Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

search_public_collections()

Description

Performs a search for themes / public collections.
Returns a comma separated list of resource refs in each collection, used for thumbnail previews.

Parameters

ColumnTypeDefaultDescription
$search string ""
$order_by string "name"
$sort string "ASC"
$exclude_themes boolean true
$exclude_public boolean false
$include_resources boolean false
$override_group_restrict boolean false
$search_user_collections boolean false
$fetchrows integer -1

Return

array

Location

include/collections_functions.php lines 623 to 722

Definition

 
function search_public_collections($search=""$order_by="name"$sort="ASC"$exclude_themes=true$exclude_public=false$include_resources=false$override_group_restrict=false$search_user_collections=false$fetchrows=-1)
    {
    global 
$userref;
    
$sql="";
    
$keysql="";
    
# Keywords searching?
    
$keywords=split_keywords($search);  
    if (
strlen($search)==&& !is_numeric($search)) 
        {
        
# A-Z search
        
$sql="and c.name like '" escape_check($search) . "%'";
        }
    elseif (
substr($search,0,16)=="collectiontitle:")
        {
        
# A-Z specific title search
        
        
$newsearch="";
        for (
$n=0;$n<count($keywords);$n++)
            {
               if (
substr($keywords[$n],0,16)=="collectiontitle:"$newsearch.=" ".substr($keywords[$n],16);    // wildcard * - %
            
}

        
$newsearch strpos($newsearch,'*')===false '%' trim($newsearch) . '%' str_replace('*''%'trim($newsearch));
        
$sql="and c.name like '$newsearch'";
            
        }
    if (
strlen($search)>|| is_numeric($search))
        {  
        
        
$keyrefs=array();
        for (
$n=0;$n<count($keywords);$n++)
            {
            if (
substr($keywords[$n],0,16)!="collectiontitle:")
                {
                if (
substr($keywords[$n],0,16)=="collectionowner:"
                    {
                    
$keywords[$n]=substr($keywords[$n],16);
                    
$keyref=$keywords[$n];
                       
$sql.=" and (u.username rlike '$keyref' or u.fullname rlike '$keyref')";    
                    }
                elseif (
substr($keywords[$n],0,19)=="collectionownerref:"
                    {
                    
$keywords[$n]=substr($keywords[$n],19);
                    
$keyref=$keywords[$n];
                       
$sql.=" and (c.user='$keyref')";
                    } 
                else
                    {
                    if (
substr($keywords[$n],0,19)=="collectionkeywords:"$keywords[$n]=substr($keywords[$n],19);
            
# Support field specific matching - discard the field identifier as not appropriate for collection searches.
            
if (strpos($keywords[$n],":")!==false) {$keywords[$n]=substr($keywords[$n],strpos($keywords[$n],":")+1);}
                    
$keyref=resolve_keyword($keywords[$n],false);
                    if (
$keyref!==false) {$keyrefs[]=$keyref;}
                    
$keysql.="join collection_keyword k" $n " on k" $n ".collection=c.ref and (k" $n ".keyword='$keyref')";
                    }
                
//$keysql="or keyword in (" . join (",",$keyrefs) . ")";
                
}
            }
        
        global 
$search_public_collections_ref;
        if (
$search_public_collections_ref && is_numeric($search)){$spcr="or c.ref='" escape_check($search) . "'";} else {$spcr="";}    
        
//$sql.="and (c.name rlike '%$search%' or u.username rlike '%$search%' or u.fullname rlike '%$search%' $spcr )";
        
}

    if (
$exclude_themes# Include only public collections.
        
{
        
$sql.=" and (length(c.theme)=0 or c.theme is null)";
        }
    
    if ((
$exclude_public) && !$search_user_collections# Exclude public only collections (return only themes)
        
{
        
$sql.=" and length(c.theme)>0";
        }
    
    
# Restrict to parent, child and sibling groups?
    
global $public_collections_confine_group,$userref,$usergroup;
    if (
$public_collections_confine_group && !$override_group_restrict)
        {
        
# Form a list of all applicable groups
        
$groups=array($usergroup); # Start with user's own group
        
$groups=array_merge($groups,sql_array("select ref value from usergroup where parent='" escape_check($usergroup) . "'")); # Children
        
$groups=array_merge($groups,sql_array("select parent value from usergroup where ref='" escape_check($usergroup) . "'")); # Parent
        
$groups=array_merge($groups,sql_array("select ref value from usergroup where parent<>0 and parent=(select parent from usergroup where ref='" escape_check($usergroup) . "')")); # Siblings (same parent)
        
        
$sql.=" and u.usergroup in ('" join ("','",$groups) . "')";
        }
    
    if (
$search_user_collections$sql_public="(c.public=1 or c.user=$userref)";
    else 
$sql_public="c.public=1";

    
# Run the query
    
if ($include_resources)
        {    
        return 
sql_query("select distinct c.*,u.username,u.fullname, count( DISTINCT cr.resource ) count from collection c left join collection_resource cr on c.ref=cr.collection left outer join user u on c.user=u.ref left outer join collection_keyword k on c.ref=k.collection $keysql where $sql_public $sql group by c.ref order by " escape_check($order_by) . " " escape_check($sort),'',$fetchrows);
        }
    else
        {
        return 
sql_query("select distinct c.*,u.username,u.fullname from collection c left outer join user u on c.user=u.ref left outer join collection_keyword k on c.ref=k.collection $keysql where $sql_public $sql group by c.ref order by " escape_check($order_by) . " " escape_check($sort),'',$fetchrows);
        }
    }

This article was last updated 11th July 2020 22:05 Europe/London time based on the source file dated 9th July 2020 17:22 Europe/London time.