From 96402e306a4ea448f64df0f36346c05dcf221ab8 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 May 2019 17:12:19 -0400 Subject: [PATCH] Fix formatting of Model\FileTag - Normalize indent style - Remove extraneous new lines after ifs/foreachs --- src/Model/FileTag.php | 435 ++++++++++++++++++++---------------------- 1 file changed, 209 insertions(+), 226 deletions(-) diff --git a/src/Model/FileTag.php b/src/Model/FileTag.php index 2ad864c9c4..a5824f5347 100644 --- a/src/Model/FileTag.php +++ b/src/Model/FileTag.php @@ -11,127 +11,122 @@ use Friendica\Database\DBA; /** * @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 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 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)) . '>'); + } - /** - * @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) . "' "; + } - return " AND " . (($table) ? DBA::escape($table) . '.' : '') . "file regexp '" . DBA::escape($str) . "' "; - } + /** + * @brief Get file tags from list + * + * ex. given music,video return