Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

get_theme_image()

Description

Returns an array of resource references that can be used as theme category images.

Parameters

ColumnTypeDefaultDescription
$themes array array Array of collections
$collection integer "" ID of collection
$smart boolean false Flag for smart featured collections

Return

array|boolean

Location

include/collections_functions.php lines 1929 to 2030

Definition

 
function get_theme_image($themes=array(), $collection=""$smart=false)
    {
    global 
$theme_images_number;
    global 
$theme_category_levels;
    global 
$usergroup$userref;
    global 
$userpermissions;
    
# Resources that have been specifically chosen using the option on the collection comments page will be returned first based on order by.
    
    # have this hook return an empty array if a plugin needs to return a false value from function
    
$images_override=hook('get_theme_image_override','', array($themes$collection$smart));
    
    if (
$images_override!==false && is_array($images_override))
        {
        
$images=$images_override;
        }
    else 
        {
        if (
$smart)
            {
            
$nodestring '';
            foreach(
$themes as $node)
                {
                
$nodestring .= NODE_TOKEN_PREFIX $node['ref'];
                }
                
            if(
$nodestring=='')
                {
                return 
false;
                }
                
            
// As we are using nodes just do a simple search so that permissions are honoured
            
$images do_search($nodestring,'','hit_count',0,-1,'desc',false,0,false,false,'',true,false,true);
            return 
is_array($images) ? array_column($images"ref") : array();
            }
        else
        {
            
$sqlfilter_custom="";
            
$sqlselect="SELECT r.ref, cr.use_as_theme_thumbnail, theme2, r.hit_count FROM collection c "
                            
."JOIN collection_resource cr on cr.collection=c.ref "
                            
."JOIN resource r on r.ref=cr.resource and r.archive=0 and r.ref>0 and r.has_image=1 ";
            
            
// Add custom access joins if necessary
            
if (!checkperm("v"))
                {
                
$sqlselect.= " LEFT OUTER JOIN resource_custom_access rca2 " 
                                        
."ON r.ref=rca2.resource "
                                        
."AND rca2.user='$userref' "
                                        
."AND (rca2.user_expires IS null or rca2.user_expires>now()) "
                                        
."AND rca2.access<>2 "
                            
." LEFT OUTER JOIN resource_custom_access rca "
                                        
."ON r.ref=rca.resource "
                                        
."AND rca.usergroup='$usergroup' "
                                        
."AND rca.access<>2 ";

                
# Check both the resource access, but if confidential is returned, also look at the joined user-specific or group-specific custom access for rows.
                
$sqlfilter_custom.=" AND (     r.access<>'2' " 
                                  
."       OR (r.access=2 AND ( (rca.access IS NOT null AND rca.access<>2) OR (rca2.access IS NOT null AND rca2.access<>2) ) ) )";

                }

            
// Build filter, attaching custom access filtering, if any     
            
$sqlfilter=" WHERE c.public=1 and c.theme='" escape_check($themes[0]) . "' "
                       
.$sqlfilter_custom;

            
// Attach filter to principal select           
            
$sqlselect.=$sqlfilter;

            
$orderby  =" ORDER BY ti.use_as_theme_thumbnail desc";
            
            
$orderby_theme='';
            for (
$n=2;$n<=count($themes)+1;$n++)
                {
                if (isset(
$themes[$n-1]))
                    {
                    
$sqlselect.=" AND theme".$n."='" escape_check($themes[$n-1]) . "' ";
                    } 
                else
                    {
                    if (
$n<=$theme_category_levels)
                        {
                        
# Resources in sub categories can be used but should be below those in the current category
                        
$orderby_theme=" ORDER BY theme".$n;
                        }
                    }
                } 

            if(
$collection != "")
                {
                
$sqlselect.=" and c.ref = '" escape_check($collection) .  "'";
                }
                
            
$orderby.=",ti.hit_count desc,ti.ref desc";
            }
    
        
$sql "SELECT ti.ref value from (" $sqlselect $orderby_theme ") ti "
               
.$orderby " limit " escape_check($theme_images_number);
               
        
$images=sql_array($sql,"themeimage");
        }
    if (
count($images)>0) {return $images;}
    return 
false;
    }

This article was last updated 22nd October 2020 11:35 Europe/London time based on the source file dated 2nd October 2020 15:40 Europe/London time.