mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-28 04:09:56 +03:00
feature 2999: documentation of functions_search and functions_tag
git-svn-id: http://piwigo.org/svn/trunk@25658 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
037413eee8
commit
da06285d4e
7 changed files with 142 additions and 108 deletions
|
@ -342,7 +342,7 @@ SELECT DISTINCT(id)
|
||||||
* Finds a matching category id from a potential list of permalinks
|
* Finds a matching category id from a potential list of permalinks
|
||||||
*
|
*
|
||||||
* @param string[] $permalinks
|
* @param string[] $permalinks
|
||||||
* @param int $idx filled with the index in $permalinks that matches
|
* @param int &$idx filled with the index in $permalinks that matches
|
||||||
* @return int|null
|
* @return int|null
|
||||||
*/
|
*/
|
||||||
function get_cat_id_from_permalinks($permalinks, &$idx)
|
function get_cat_id_from_permalinks($permalinks, &$idx)
|
||||||
|
|
|
@ -72,9 +72,9 @@ function user_comment_check($action, $comment)
|
||||||
/**
|
/**
|
||||||
* Tries to insert a user comment and returns action to perform.
|
* Tries to insert a user comment and returns action to perform.
|
||||||
*
|
*
|
||||||
* @param array $comm
|
* @param array &$comm
|
||||||
* @param string $key secret key sent back to the browser
|
* @param string $key secret key sent back to the browser
|
||||||
* @param array $infos output array of error messages
|
* @param array &$infos output array of error messages
|
||||||
* @return string validate, moderate, reject
|
* @return string validate, moderate, reject
|
||||||
*/
|
*/
|
||||||
function insert_user_comment(&$comm, $key, &$infos)
|
function insert_user_comment(&$comm, $key, &$infos)
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
/**
|
/**
|
||||||
* Updates data of categories with filtered values
|
* Updates data of categories with filtered values
|
||||||
*
|
*
|
||||||
* @param array $cats
|
* @param array &$cats
|
||||||
*/
|
*/
|
||||||
function update_cats_with_filtered_data(&$cats)
|
function update_cats_with_filtered_data(&$cats)
|
||||||
{
|
{
|
||||||
|
|
|
@ -361,7 +361,7 @@ function news_exists($start=null, $end=null)
|
||||||
/**
|
/**
|
||||||
* Formats a news line and adds it to the array (e.g. '5 new elements')
|
* Formats a news line and adds it to the array (e.g. '5 new elements')
|
||||||
*
|
*
|
||||||
* @param array $news
|
* @param array &$news
|
||||||
* @param int $count
|
* @param int $count
|
||||||
* @param string $singular_key
|
* @param string $singular_key
|
||||||
* @param string $plural_key
|
* @param string $plural_key
|
||||||
|
|
|
@ -50,13 +50,13 @@ abstract class PluginMaintain
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $plugin_version
|
* @param string $plugin_version
|
||||||
* @param array $errors - used to return error messages
|
* @param array &$errors - used to return error messages
|
||||||
*/
|
*/
|
||||||
abstract function install($plugin_version, &$errors=array());
|
abstract function install($plugin_version, &$errors=array());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $plugin_version
|
* @param string $plugin_version
|
||||||
* @param array $errors - used to return error messages
|
* @param array &$errors - used to return error messages
|
||||||
*/
|
*/
|
||||||
abstract function activate($plugin_version, &$errors=array());
|
abstract function activate($plugin_version, &$errors=array());
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ abstract class ThemeMaintain
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $theme_version
|
* @param string $theme_version
|
||||||
* @param array $errors - used to return error messages
|
* @param array &$errors - used to return error messages
|
||||||
*/
|
*/
|
||||||
abstract function activate($theme_version, &$errors=array());
|
abstract function activate($theme_version, &$errors=array());
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ function trigger_action($event)
|
||||||
* @depracted 2.6
|
* @depracted 2.6
|
||||||
*
|
*
|
||||||
* @param string $plugin_id
|
* @param string $plugin_id
|
||||||
* @param mixed $data
|
* @param mixed &$data
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function set_plugin_data($plugin_id, &$data)
|
function set_plugin_data($plugin_id, &$data)
|
||||||
|
|
|
@ -21,12 +21,16 @@
|
||||||
// | USA. |
|
// | USA. |
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package functions\search
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns search rules stored into a serialized array in "search"
|
* Returns search rules stored into a serialized array in "search"
|
||||||
* table. Each search rules set is numericaly identified.
|
* table. Each search rules set is numericaly identified.
|
||||||
*
|
*
|
||||||
* @param int search_id
|
* @param int $search_id
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_search_array($search_id)
|
function get_search_array($search_id)
|
||||||
|
@ -47,12 +51,10 @@ SELECT rules
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the SQL clause from a search identifier
|
* Returns the SQL clause for a search.
|
||||||
|
* Transforms the array returned by get_search_array() into SQL sub-query.
|
||||||
*
|
*
|
||||||
* Search rules are stored in search table as a serialized array. This array
|
* @param array $search
|
||||||
* need to be transformed into an SQL clause to be used in queries.
|
|
||||||
*
|
|
||||||
* @param array search
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function get_sql_search_clause($search)
|
function get_sql_search_clause($search)
|
||||||
|
@ -170,12 +172,13 @@ function get_sql_search_clause($search)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the list of items corresponding to the advanced search array
|
* Returns the list of items corresponding to the advanced search array.
|
||||||
*
|
*
|
||||||
* @param array search
|
* @param array $search
|
||||||
|
* @param string $images_where optional additional restriction on images table
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_regular_search_results($search, $images_where)
|
function get_regular_search_results($search, $images_where='')
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
$forbidden = get_sql_condition_FandF(
|
$forbidden = get_sql_condition_FandF(
|
||||||
|
@ -246,34 +249,55 @@ SELECT DISTINCT(id)
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds if a char is a letter, a figure or any char of the extended ASCII table (>127).
|
||||||
|
*
|
||||||
|
* @param char $ch
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function is_word_char($ch)
|
function is_word_char($ch)
|
||||||
{
|
{
|
||||||
return ($ch>='0' && $ch<='9') || ($ch>='a' && $ch<='z') || ($ch>='A' && $ch<='Z') || ord($ch)>127;
|
return ($ch>='0' && $ch<='9') || ($ch>='a' && $ch<='z') || ($ch>='A' && $ch<='Z') || ord($ch)>127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds if a char is a special token for word start: [{<=*+
|
||||||
|
*
|
||||||
|
* @param char $ch
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function is_odd_wbreak_begin($ch)
|
function is_odd_wbreak_begin($ch)
|
||||||
{
|
{
|
||||||
return strpos('[{<=*+', $ch)===false ? false:true;
|
return strpos('[{<=*+', $ch)===false ? false:true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds if a char is a special token for word end: ]}>=*+
|
||||||
|
*
|
||||||
|
* @param char $ch
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
function is_odd_wbreak_end($ch)
|
function is_odd_wbreak_end($ch)
|
||||||
{
|
{
|
||||||
return strpos(']}>=*+', $ch)===false ? false:true;
|
return strpos(']}>=*+', $ch)===false ? false:true;
|
||||||
}
|
}
|
||||||
|
|
||||||
define('QST_QUOTED', 0x01);
|
|
||||||
define('QST_NOT', 0x02);
|
define('QST_QUOTED', 0x01);
|
||||||
define('QST_WILDCARD_BEGIN',0x04);
|
define('QST_NOT', 0x02);
|
||||||
define('QST_WILDCARD_END', 0x08);
|
define('QST_WILDCARD_BEGIN', 0x04);
|
||||||
|
define('QST_WILDCARD_END', 0x08);
|
||||||
define('QST_WILDCARD', QST_WILDCARD_BEGIN|QST_WILDCARD_END);
|
define('QST_WILDCARD', QST_WILDCARD_BEGIN|QST_WILDCARD_END);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* analyzes and splits the quick/query search query $q into tokens
|
* Analyzes and splits the quick/query search query $q into tokens.
|
||||||
* q='john bill' => 2 tokens 'john' 'bill'
|
* q='john bill' => 2 tokens 'john' 'bill'
|
||||||
* Special characters for MySql full text search (+,<,>,~) appear in the token modifiers.
|
* Special characters for MySql full text search (+,<,>,~) appear in the token modifiers.
|
||||||
* The query can contain a phrase: 'Pierre "New York"' will return 'pierre' qnd 'new york'.
|
* The query can contain a phrase: 'Pierre "New York"' will return 'pierre' qnd 'new york'.
|
||||||
|
*
|
||||||
|
* @param string $q
|
||||||
|
* @param array &$qtokens
|
||||||
|
* @param array &$qtoken_modifiers
|
||||||
*/
|
*/
|
||||||
function analyse_qsearch($q, &$qtokens, &$qtoken_modifiers)
|
function analyse_qsearch($q, &$qtokens, &$qtoken_modifiers)
|
||||||
{
|
{
|
||||||
|
@ -368,11 +392,15 @@ function analyse_qsearch($q, &$qtokens, &$qtoken_modifiers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the LIKE sql clause corresponding to the quick search query
|
* Returns the LIKE SQL clause corresponding to the quick search query
|
||||||
* that has been split into tokens
|
* that has been split into tokens.
|
||||||
* for example file LIKE '%john%' OR file LIKE '%bill%'.
|
* for example file LIKE '%john%' OR file LIKE '%bill%'.
|
||||||
|
*
|
||||||
|
* @param array $tokens
|
||||||
|
* @param array $token_modifiers
|
||||||
|
* @param string $field
|
||||||
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
function get_qsearch_like_clause($tokens, $token_modifiers, $field)
|
function get_qsearch_like_clause($tokens, $token_modifiers, $field)
|
||||||
{
|
{
|
||||||
|
@ -393,7 +421,14 @@ function get_qsearch_like_clause($tokens, $token_modifiers, $field)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
* Returns tags corresponding to the quick search query that has been split into tokens.
|
||||||
|
*
|
||||||
|
* @param array $tokens
|
||||||
|
* @param array $token_modifiers
|
||||||
|
* @param array &$token_tag_ids
|
||||||
|
* @param array &$not_tag_ids
|
||||||
|
* @param array &$all_tags
|
||||||
|
*/
|
||||||
function get_qsearch_tags($tokens, $token_modifiers, &$token_tag_ids, &$not_tag_ids, &$all_tags)
|
function get_qsearch_tags($tokens, $token_modifiers, &$token_tag_ids, &$not_tag_ids, &$all_tags)
|
||||||
{
|
{
|
||||||
$token_tag_ids = array_fill(0, count($tokens), array() );
|
$token_tag_ids = array_fill(0, count($tokens), array() );
|
||||||
|
@ -546,24 +581,27 @@ SELECT t.*, COUNT(image_id) AS counter
|
||||||
|
|
||||||
usort($all_tags, 'tag_alpha_compare');
|
usort($all_tags, 'tag_alpha_compare');
|
||||||
foreach ( $all_tags as &$tag )
|
foreach ( $all_tags as &$tag )
|
||||||
|
{
|
||||||
$tag['name'] = trigger_event('render_tag_name', $tag['name']);
|
$tag['name'] = trigger_event('render_tag_name', $tag['name']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the search results corresponding to a quick/query search.
|
* Returns the search results corresponding to a quick/query search.
|
||||||
* A quick/query search returns many items (search is not strict), but results
|
* A quick/query search returns many items (search is not strict), but results
|
||||||
* are sorted by relevance unless $super_order_by is true. Returns:
|
* are sorted by relevance unless $super_order_by is true. Returns:
|
||||||
* array (
|
* array (
|
||||||
* 'items' => array(85,68,79...)
|
* 'items' => array of matching images
|
||||||
* 'qs' => array(
|
* 'qs' => array(
|
||||||
* 'matching_tags' => array of matching tags
|
* 'matching_tags' => array of matching tags
|
||||||
* 'matching_cats' => array of matching categories
|
* 'matching_cats' => array of matching categories
|
||||||
* 'matching_cats_no_images' =>array(99) - matching categories without images
|
* 'matching_cats_no_images' =>array(99) - matching categories without images
|
||||||
* ))
|
* )
|
||||||
|
* )
|
||||||
*
|
*
|
||||||
* @param string q
|
* @param string $q
|
||||||
* @param bool super_order_by
|
* @param bool $super_order_by
|
||||||
* @param string images_where optional aditional restriction on images table
|
* @param string $images_where optional additional restriction on images table
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_quick_search_results($q, $super_order_by, $images_where='')
|
function get_quick_search_results($q, $super_order_by, $images_where='')
|
||||||
|
@ -763,10 +801,12 @@ SELECT DISTINCT(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns an array of 'items' corresponding to the search id
|
* Returns an array of 'items' corresponding to the search id.
|
||||||
|
* It can be either a quick search or a regular search.
|
||||||
*
|
*
|
||||||
* @param int search id
|
* @param int $search_id
|
||||||
* @param string images_where optional aditional restriction on images table
|
* @param bool $super_order_by
|
||||||
|
* @param string $images_where optional aditional restriction on images table
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_search_results($search_id, $super_order_by, $images_where='')
|
function get_search_results($search_id, $super_order_by, $images_where='')
|
||||||
|
@ -782,4 +822,5 @@ function get_search_results($search_id, $super_order_by, $images_where='')
|
||||||
return get_quick_search_results($search['q'], $super_order_by, $images_where);
|
return get_quick_search_results($search['q'], $super_order_by, $images_where);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -21,8 +21,16 @@
|
||||||
// | USA. |
|
// | USA. |
|
||||||
// +-----------------------------------------------------------------------+
|
// +-----------------------------------------------------------------------+
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @package functions\tag
|
||||||
|
*/
|
||||||
|
|
||||||
/** returns the number of available tags for the connected user */
|
|
||||||
|
/**
|
||||||
|
* Returns the number of available tags for the connected user.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
function get_nb_available_tags()
|
function get_nb_available_tags()
|
||||||
{
|
{
|
||||||
global $user;
|
global $user;
|
||||||
|
@ -38,14 +46,11 @@ function get_nb_available_tags()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tags available. Each return tag is represented as an array with its id,
|
* Returns all available tags for the connected user (not sorted).
|
||||||
* its name, its weight (count), its url name. Tags are not sorted.
|
* The returned list can be a subset of all existing tags due to permissions,
|
||||||
|
* also tags with no images are not returned.
|
||||||
*
|
*
|
||||||
* The returned list can be a subset of all existing tags due to
|
* @return array [id, name, counter, url_name]
|
||||||
* permissions, only if a list of forbidden categories is provided
|
|
||||||
*
|
|
||||||
* @param array forbidden categories
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
function get_available_tags()
|
function get_available_tags()
|
||||||
{
|
{
|
||||||
|
@ -53,18 +58,18 @@ function get_available_tags()
|
||||||
$query = '
|
$query = '
|
||||||
SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
FROM '.IMAGE_CATEGORY_TABLE.' ic
|
FROM '.IMAGE_CATEGORY_TABLE.' ic
|
||||||
INNER JOIN '.IMAGE_TAG_TABLE.' it ON ic.image_id=it.image_id'.get_sql_condition_FandF
|
INNER JOIN '.IMAGE_TAG_TABLE.' it
|
||||||
(
|
ON ic.image_id=it.image_id
|
||||||
array
|
'.get_sql_condition_FandF(
|
||||||
(
|
array(
|
||||||
'forbidden_categories' => 'category_id',
|
'forbidden_categories' => 'category_id',
|
||||||
'visible_categories' => 'category_id',
|
'visible_categories' => 'category_id',
|
||||||
'visible_images' => 'ic.image_id'
|
'visible_images' => 'ic.image_id'
|
||||||
),
|
),
|
||||||
'
|
' WHERE '
|
||||||
WHERE'
|
|
||||||
).'
|
).'
|
||||||
GROUP BY tag_id';
|
GROUP BY tag_id
|
||||||
|
;';
|
||||||
$tag_counters = simple_hash_from_query($query, 'tag_id', 'counter');
|
$tag_counters = simple_hash_from_query($query, 'tag_id', 'counter');
|
||||||
|
|
||||||
if ( empty($tag_counters) )
|
if ( empty($tag_counters) )
|
||||||
|
@ -76,6 +81,7 @@ SELECT tag_id, COUNT(DISTINCT(it.image_id)) AS counter
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM '.TAGS_TABLE;
|
FROM '.TAGS_TABLE;
|
||||||
$result = pwg_query($query);
|
$result = pwg_query($query);
|
||||||
|
|
||||||
$tags = array();
|
$tags = array();
|
||||||
while ($row = pwg_db_fetch_assoc($result))
|
while ($row = pwg_db_fetch_assoc($result))
|
||||||
{
|
{
|
||||||
|
@ -91,9 +97,9 @@ SELECT *
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All tags, even tags associated to no image.
|
* Returns all tags even associated to no image.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array [id, name, url_name]
|
||||||
*/
|
*/
|
||||||
function get_all_tags()
|
function get_all_tags()
|
||||||
{
|
{
|
||||||
|
@ -119,11 +125,11 @@ SELECT *
|
||||||
* level of each tag.
|
* level of each tag.
|
||||||
*
|
*
|
||||||
* The level of each tag depends on the average count of tags. This
|
* The level of each tag depends on the average count of tags. This
|
||||||
* calcylation method avoid having very different levels for tags having
|
* calculation method avoid having very different levels for tags having
|
||||||
* nearly the same count when set are small.
|
* nearly the same count when set are small.
|
||||||
*
|
*
|
||||||
* @param array tags
|
* @param array $tags at least [id, counter]
|
||||||
* @return array
|
* @return array [..., level]
|
||||||
*/
|
*/
|
||||||
function add_level_to_tags($tags)
|
function add_level_to_tags($tags)
|
||||||
{
|
{
|
||||||
|
@ -173,13 +179,14 @@ function add_level_to_tags($tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the list of image ids corresponding to given tags. AND & OR mode
|
* Return the list of image ids corresponding to given tags.
|
||||||
* supported.
|
* AND & OR mode supported.
|
||||||
*
|
*
|
||||||
* @param array tag ids
|
* @param int[] $tag_ids
|
||||||
* @param string mode
|
* @param string mode
|
||||||
* @param string extra_images_where_sql - optionally apply a sql where filter to retrieved images
|
* @param string $extra_images_where_sql - optionally apply a sql where filter to retrieved images
|
||||||
* @param string order_by - optionally overwrite default photo order
|
* @param string $order_by - optionally overwrite default photo order
|
||||||
|
* @param bool $user_permissions
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='', $order_by='', $use_permissions=true)
|
function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='', $order_by='', $use_permissions=true)
|
||||||
|
@ -190,7 +197,8 @@ function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = 'SELECT id
|
$query = '
|
||||||
|
SELECT id
|
||||||
FROM '.IMAGES_TABLE.' i ';
|
FROM '.IMAGES_TABLE.' i ';
|
||||||
|
|
||||||
if ($use_permissions)
|
if ($use_permissions)
|
||||||
|
@ -229,14 +237,14 @@ function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a list of tags corresponding to given items.
|
* Return a list of tags corresponding to given items.
|
||||||
*
|
*
|
||||||
* @param array items
|
* @param int[] $items
|
||||||
* @param array max_tags
|
* @param int $max_tags
|
||||||
* @param array excluded_tag_ids
|
* @param int[] $excluded_tag_ids
|
||||||
* @return array
|
* @return array [id, name, counter, url_name]
|
||||||
*/
|
*/
|
||||||
function get_common_tags($items, $max_tags, $excluded_tag_ids=null)
|
function get_common_tags($items, $max_tags, $excluded_tag_ids=array())
|
||||||
{
|
{
|
||||||
if (empty($items))
|
if (empty($items))
|
||||||
{
|
{
|
||||||
|
@ -256,7 +264,7 @@ SELECT t.*, count(*) AS counter
|
||||||
GROUP BY t.id
|
GROUP BY t.id
|
||||||
ORDER BY ';
|
ORDER BY ';
|
||||||
if ($max_tags>0)
|
if ($max_tags>0)
|
||||||
{
|
{ // TODO : why ORDER field is in the if ?
|
||||||
$query .= 'counter DESC
|
$query .= 'counter DESC
|
||||||
LIMIT '.$max_tags;
|
LIMIT '.$max_tags;
|
||||||
}
|
}
|
||||||
|
@ -277,45 +285,29 @@ SELECT t.*, count(*) AS counter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return a list of tags corresponding to any of ids, url_names, names
|
* Return a list of tags corresponding to any of ids, url_names or names.
|
||||||
*
|
*
|
||||||
* @param array ids
|
* @param int[] $ids
|
||||||
* @param array url_names
|
* @param string[] $url_names
|
||||||
* @param array names
|
* @param string[] $names
|
||||||
* @return array
|
* @return array [id, name, url_name]
|
||||||
*/
|
*/
|
||||||
function find_tags($ids, $url_names=array(), $names=array() )
|
function find_tags($ids=array(), $url_names=array(), $names=array() )
|
||||||
{
|
{
|
||||||
$where_clauses = array();
|
$where_clauses = array();
|
||||||
if ( !empty($ids) )
|
if (!empty($ids))
|
||||||
{
|
{
|
||||||
$where_clauses[] = 'id IN ('.implode(',', $ids).')';
|
$where_clauses[] = 'id IN ('.implode(',', $ids).')';
|
||||||
}
|
}
|
||||||
if ( !empty($url_names) )
|
if (!empty($url_names))
|
||||||
{
|
{
|
||||||
$where_clauses[] =
|
$where_clauses[] =
|
||||||
'url_name IN ('.
|
'url_name IN (\''. implode('\', \'', $url_names) .'\')';
|
||||||
implode(
|
|
||||||
',',
|
|
||||||
array_map(
|
|
||||||
create_function('$s', 'return "\'".$s."\'";'),
|
|
||||||
$url_names
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.')';
|
|
||||||
}
|
}
|
||||||
if ( !empty($names) )
|
if (!empty($names))
|
||||||
{
|
{
|
||||||
$where_clauses[] =
|
$where_clauses[] =
|
||||||
'name IN ('.
|
'name IN (\''. implode('\', \'', $names) .'\')';
|
||||||
implode(
|
|
||||||
',',
|
|
||||||
array_map(
|
|
||||||
create_function('$s', 'return "\'".$s."\'";'),
|
|
||||||
$names
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.')';
|
|
||||||
}
|
}
|
||||||
if (empty($where_clauses))
|
if (empty($where_clauses))
|
||||||
{
|
{
|
||||||
|
@ -336,4 +328,5 @@ SELECT *
|
||||||
}
|
}
|
||||||
return $tags;
|
return $tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue