X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FFileTag.php;h=f4d04634fa78e1a5037e1b64c3660c4ee802cee8;hb=ee1954f2944f3996f4320a48b68fad7e2174da34;hp=d3baffdd4fd02106e2ba307009ed068911be1d71;hpb=c6ce9ddaa41a59496cbe5cd93ace9bc552478ccd;p=friendica.git diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index d3baffdd4f..f4d04634fa 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -8,304 +8,313 @@ namespace Friendica\Model; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Database\DBA; -use Friendica\Model\Item; /** * @brief This class handles FileTag related functions + * + * post categories and "save to file" use the same item.file table for storage. + * We will differentiate the different uses by wrapping categories in angle brackets + * and save to file categories in square brackets. + * To do this we need to escape these characters if they appear in our tag. */ class FileTag { - // post categories and "save to file" use the same item.file table for storage. - // We will differentiate the different uses by wrapping categories in angle brackets - // and save to file categories in square brackets. - // To do this we need to escape these characters if they appear in our tag. - - /** - * @brief URL encode <, >, left and right brackets - * - * @param string $s String to be URL encoded. - * - * @return string The URL encoded string. - */ - public static function encode($s) - { - return str_replace(['<', '>', '[', ']'], ['%3c', '%3e', '%5b', '%5d'], $s); - } - - /** - * @brief URL decode <, >, left and right brackets - * - * @param string $s The URL encoded string to be decoded - * - * @return string The decoded string. - */ - public static function decode($s) - { - return str_replace(['%3c', '%3e', '%5b', '%5d'], ['<', '>', '[', ']'], $s); - } - - /** - * @brief Query files for tag - * - * @param string $table The table to be queired. - * @param string $s The search term - * @param string $type Optional file type. - * - * @return string Query string. - */ - public static function fileQuery($table, $s, $type = 'file') - { - if ($type == 'file') { - $str = preg_quote('[' . str_replace('%', '%%', self::encode($s)) . ']'); - } else { - $str = preg_quote('<' . str_replace('%', '%%', self::encode($s)) . '>'); - } - - return " AND " . (($table) ? DBA::escape($table) . '.' : '') . "file regexp '" . DBA::escape($str) . "' "; - } - - /** - * @brief Get file tags from list - * - * ex. given music,video return