-
- if ($saved != $filetags_updated) {
- PConfig::set($uid, 'system', 'filetags', $filetags_updated);
- }
-
- return true;
- } elseif (strlen($file_new)) {
- PConfig::set($uid, 'system', 'filetags', $file_new);
- }
-
- return true;
- }
-
- /**
- * @brief Add tag to file
- *
- * @param int $uid Unique identity.
- * @param int $item_id Item identity.
- * @param string $file File tag.
- *
- * @return boolean A value indicating success or failure.
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public static function saveFile($uid, $item_id, $file)
- {
- if (!intval($uid)) {
- return false;
- }
-
- $item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
- if (DBA::isResult($item)) {
- if (!stristr($item['file'], '[' . self::encode($file) . ']')) {
- $fields = ['file' => $item['file'] . '[' . self::encode($file) . ']'];
- Item::update($fields, ['id' => $item_id]);
- }
-
- $saved = PConfig::get($uid, 'system', 'filetags');
-
- if (!strlen($saved) || !stristr($saved, '[' . self::encode($file) . ']')) {
- PConfig::set($uid, 'system', 'filetags', $saved . '[' . self::encode($file) . ']');
- }
-
- info(L10n::t('Item filed'));
- }
-
- return true;
- }
-
- /**
- * @brief Remove tag from file
- *
- * @param int $uid Unique identity.
- * @param int $item_id Item identity.
- * @param string $file File tag.
- * @param boolean $cat Optional value indicating the term type (i.e. Category or File)
- *
- * @return boolean A value indicating success or failure.
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- public static function unsaveFile($uid, $item_id, $file, $cat = false)
- {
- if (!intval($uid)) {
- return false;
- }
-
- if ($cat == true) {
- $pattern = '<' . self::encode($file) . '>';
- $termtype = Term::CATEGORY;
- } else {
- $pattern = '[' . self::encode($file) . ']';
- $termtype = Term::FILE;
- }
-
- $item = Item::selectFirst(['file'], ['id' => $item_id, 'uid' => $uid]);
-
- if (!DBA::isResult($item)) {
- return false;
- }
-
- $fields = ['file' => str_replace($pattern, '', $item['file'])];
-
- Item::update($fields, ['id' => $item_id]);
-
- $r = q("SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d",
- DBA::escape($file),
- intval(Term::OBJECT_TYPE_POST),
- intval($termtype),
- intval($uid)
- );
-
- if (!DBA::isResult($r)) {
- $saved = PConfig::get($uid, 'system', 'filetags');
- PConfig::set($uid, 'system', 'filetags', str_replace($pattern, '', $saved));