Tags can now be added and removed from photos
This commit is contained in:
parent
c2d1d11123
commit
9e9a104320
3 changed files with 62 additions and 3 deletions
|
@ -36,6 +36,7 @@ use Friendica\Model\Contact;
|
|||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\BaseProfile;
|
||||
use Friendica\Network\Probe;
|
||||
|
@ -421,7 +422,7 @@ function photos_post(App $a)
|
|||
}
|
||||
|
||||
if ($item_id) {
|
||||
$item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
|
||||
$item = Item::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
|
||||
|
||||
if (DBA::isResult($item)) {
|
||||
$old_tag = $item['tag'];
|
||||
|
@ -521,10 +522,17 @@ function photos_post(App $a)
|
|||
|
||||
$profile = str_replace(',', '%2c', $profile);
|
||||
$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
|
||||
|
||||
if (!empty($item['uri-id'])) {
|
||||
Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
|
||||
}
|
||||
}
|
||||
} elseif (strpos($tag, '#') === 0) {
|
||||
$tagname = substr($tag, 1);
|
||||
$str_tags .= '#[url=' . DI::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
|
||||
if (!empty($item['uri-id'])) {
|
||||
Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ use Friendica\Content\Text\BBCode;
|
|||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Tag;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
|
@ -62,7 +63,7 @@ function update_tags($item_id, $tags){
|
|||
return;
|
||||
}
|
||||
|
||||
$item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
|
||||
$item = Item::selectFirst(['tag', 'uri-id'], ['id' => $item_id, 'uid' => local_user()]);
|
||||
if (!DBA::isResult($item)) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,6 +71,12 @@ function update_tags($item_id, $tags){
|
|||
$old_tags = explode(',', $item['tag']);
|
||||
|
||||
foreach ($tags as $new_tag) {
|
||||
if (preg_match_all('/([#@!])\[url\=([^\[\]]*)\]([^\[\]]*)\[\/url\]/ism', $new_tag, $results, PREG_SET_ORDER)) {
|
||||
foreach ($results as $tag) {
|
||||
Tag::removeByHash($item['uri-id'], $tag[1], $tag[3], $tag[2]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($old_tags as $index => $old_tag) {
|
||||
if (strcmp($old_tag, $new_tag) == 0) {
|
||||
unset($old_tags[$index]);
|
||||
|
|
|
@ -92,7 +92,7 @@ class Tag
|
|||
}
|
||||
|
||||
if (empty($cid)) {
|
||||
$fields = ['name' => substr($name, 0, 96)];
|
||||
$fields = ['name' => substr($name, 0, 96), 'url' => ''];
|
||||
|
||||
if (!empty($url) && ($url != $name)) {
|
||||
$fields['url'] = strtolower($url);
|
||||
|
@ -163,4 +163,48 @@ class Tag
|
|||
self::storeByHash($uriid, $tag[1], $tag[3], $tag[2]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tag/mention
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param integer $type
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
*/
|
||||
public static function remove(int $uriid, int $type, string $name, string $url = '')
|
||||
{
|
||||
$tag = DBA::fetchFirst("SELECT `id` FROM `tag` INNER JOIN `post-tag` ON `post-tag`.`tid` = `tag`.`id`
|
||||
WHERE `uri-id` = ? AND `type` = ? AND `name` = ? AND `url` = ?", $uriid, $type, $name, $url);
|
||||
if (!DBA::isResult($tag)) {
|
||||
return;
|
||||
}
|
||||
Logger::info('Removing tag/mention', ['uri-id' => $uriid, 'tid' => $tag['id'], 'name' => $name, 'url' => $url]);
|
||||
DBA::delete('post-tag', ['uri-id' => $uriid, 'tid' => $tag['id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove tag/mention
|
||||
*
|
||||
* @param integer $uriid
|
||||
* @param string $hash
|
||||
* @param string $name
|
||||
* @param string $url
|
||||
*/
|
||||
public static function removeByHash(int $uriid, string $hash, string $name, string $url = '')
|
||||
{
|
||||
if ($hash == self::TAG_CHARACTER[self::MENTION]) {
|
||||
$type = self::MENTION;
|
||||
} elseif ($hash == self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]) {
|
||||
$type = self::EXCLUSIVE_MENTION;
|
||||
} elseif ($hash == self::TAG_CHARACTER[self::IMPLICIT_MENTION]) {
|
||||
$type = self::IMPLICIT_MENTION;
|
||||
} elseif ($hash == self::TAG_CHARACTER[self::HASHTAG]) {
|
||||
$type = self::HASHTAG;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
self::remove($uriid, $type, $name, $url);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue