Example #1
0
/**
 * Function combines multiple actor thumbnail queries into single SQL query
 */
function get_actor_thumbnails_batched(&$actors)
{
    if (!count($actors)) {
        return;
    }
    $ids = "'" . join("','", array_map('addslashes', array_extract($actors, 'id'))) . "'";
    $SQL = 'SELECT actorid, name, imgurl, UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(checked) AS cacheage
                 FROM ' . TBL_ACTORS . ' WHERE actorid IN (' . $ids . ')';
    $result = runSQL($SQL);
    $result = array_associate($result, 'actorid');
    // loop over actors from full-text field
    foreach ($actors as $idx => $actor) {
        // check for actor thumbnail
        $batch_result = $result[$actor['id']];
        if ($batch_result) {
            $actors[$idx]['imgurl'] = get_actor_image_from_cache($batch_result, $actor['name'], $actor['id']);
        } else {
            $actors[$idx]['imgurl'] = getActorThumbnail($actor['name'], $actor['id'], false);
        }
    }
}
Example #2
0
/** 
 * Genres
 */
function setup_getGenres()
{
    $SELECT = 'SELECT id, name
                 FROM ' . TBL_GENRES . '
             ORDER BY name';
    $result = runSQL($SELECT);
    return array_associate($result, 'id', 'name');
}
Example #3
0
/** 
 * Studios
 */
function setup_getStudios()
{
    $SELECT = 'SELECT id, name
                 FROM ' . TBL_STUDIOS . '
             ORDER BY name';
    $result = runSQL($SELECT);
    return array_associate($result, 'id', 'name');
}
Example #4
0
/**
 * List of owners names/ids with valid permissions for use in edit/index/search templates
 *
 * @author  <*****@*****.**>
 * @author  Chinamann <*****@*****.**>
 * @param   string  $prefix         Predefined additional Array entries
 * @param   string  $permission     Honor permissions for selectbox
 * @return  string                  Array with keys=ownernames and values=ownerids
 */
function out_owners($prefix = null, $permission = false, $keyIsId = false)
{
    global $config;
    // all permissions available if admin
    if (check_permission(PERM_ADMIN)) {
        $permission = false;
    }
    // hide guest if he/she can't login
    $WHERES = $config['denyguest'] ? " AND B.id != " . $config['guestid'] : '';
    // select user ids- if permissions are required and no all access given, this is done against xrefs
    if ($permission && !check_permission($permission)) {
        // xref permissions
        // TODO use cached permission table instead
        $SELECT = 'SELECT DISTINCT(B.name) AS name, B.id
                     FROM ' . TBL_PERMISSIONS . ' A, ' . TBL_USERS . ' B
                    WHERE A.to_uid = B.id
                          AND A.from_uid = ' . get_current_user_id() . '
                          AND (A.permissions & ' . $permission . ') = ' . $permission . $WHERES . '
                    ORDER BY name';
    } else {
        // all users +/- guest
        $SELECT = 'SELECT B.id, B.name
                     FROM ' . TBL_USERS . ' B
                    WHERE 1=1 ' . $WHERES . '
                    ORDER BY B.name';
    }
    $result = runSQL($SELECT);
    $key = $keyIsId ? 'id' : 'name';
    // build associative array
    $owners = is_array($prefix) ? $prefix : array();
    $owners = $owners + array_unique(array_associate($result, $key, 'name'));
    return $owners;
}
Example #5
0
/**
 * Load config options from config.inc.php and database and
 * setup sane defaults.
 * Return configuration in global $config array variable
 *
 * @todo    Add security check if install.php is still available
 * @param   boolean force reload of configuration data
 */
function load_config($force_reload = false)
{
    global $config, $lang, $smarty;
    // configuration cached and not outdated?
    if (!$force_reload && !$config['recompile'] && session_get('config') && session_get('config_userid') === $_COOKIE['VDBuserid'] && session_get('config_timestamp') == filemtime(CONFIG_FILE)) {
        // load from cache
        $config = session_get('config');
    } else {
        // check MySQL extension and cache directories
        verify_installation();
        // remember modification time
        session_set('config_timestamp', filemtime(CONFIG_FILE));
        // get config options from the database
        $SELECT = 'SELECT opt,value
                     FROM ' . TBL_CONFIG;
        $result = runSQL($SELECT);
        $config = array_merge($config, array_associate($result, 'opt', 'value'));
        // check if database matches the current version
        if ($config['dbversion'] < DB_REQUIRED) {
            // run installer
            redirect('install.php?action=upgrade');
        }
        // get user config options from the database
        // does not use get_current_user_id() to allow fallback to login page after loading config
        if (is_numeric($user_id = $_COOKIE['VDBuserid'])) {
            // store user id in session to identify reload point for config
            session_set('config_userid', $user_id);
            $SQL = 'SELECT opt, value
                         FROM ' . TBL_USERCONFIG . '
                        WHERE user_id = ' . $user_id;
            $result = runSQL($SQL);
            $config = array_merge($config, array_associate($result, 'opt', 'value'));
        }
        // set some defaults
        if (empty($config['language'])) {
            $config['language'] = 'en';
        }
        if (empty($config['template'])) {
            $config['template'] = 'modern::compact';
        }
        if (empty($config['filterdefault'])) {
            $config['filterdefault'] = 'unseen';
        }
        //      if ($config['IMDBage'] < 1) $config['IMDBage']          = 60*60*24*5;
        if ($config['castcolumns'] < 1) {
            $config['castcolumns'] = 4;
        }
        if ($config['listcolumns'] < 1) {
            $config['listcolumns'] = 1;
        }
        if ($config['thumbAge'] < 1) {
            $config['thumbAge'] = 60 * 60 * 24 * 7 * 3;
        }
        if ($config['shownew'] < 1) {
            $config['shownew'] = 12;
        }
        // prepare som options for later use
        $config['languages'] = explode('::', $config['languageflags']);
        // prepare template/style
        $tpl = explode('::', $config['template']);
        $config['style'] = 'templates/' . $tpl[0] . '/' . $tpl[1] . '.css';
        $config['templatedir'] = 'templates/' . $tpl[0] . '/';
        /*
                // multiple style files - use template name as base (e.g. elegant_grey.css)
                if (!file_exists($config['style']))
                {
                    // this should be an array
                    $config['style']    = array('templates/'.$tpl[0].'/'.$tpl[0].'.css',
                                                'templates/'.$tpl[0].'/'.$tpl[0].'_'.$tpl[1].'.css');
                }
        */
        // check if selected template is valid
        if (!file_exists($config['style'])) {
            $config['template'] = 'elegant::grey';
            $config['templatedir'] = 'templates/elegant/';
            $config['style'] = 'templates/elegant/grey.css';
        }
        // smarty cacheid for multiuser mode
        $config['cacheid'] = $tpl[0];
        // get installed engines meta information
        if (empty($config['engines'])) {
            require_once './engines/engines.php';
            $config['engines'] = engineMeta();
            // translate config options of type engine xyz into config[engine]
            foreach ($config['engines'] as $engine => $meta) {
                // convert the db engine options into associative array of engine enabled status
                if ($config['engine' . $engine]) {
                    $config['engine'][$engine] = $config['engine' . $engine];
                    // add meta-engine if enabled
                    engine_setup_meta($engine, $meta);
                }
            }
        }
        /*
                // added proxy support for $_ENV
                $proxy = $config['proxy_host'];
                if (empty($proxy))
                {
                    $env = array_change_key_case($_ENV);
                    $proxy = $env['http_proxy'];
                }
                if (!empty($proxy))
                {
                    $uri = parse_url($proxy);
                    $config['proxy_host'] = ($uri['scheme']) ? $uri['host'] : $uri['path'];
                    $config['proxy_port'] = ($uri['port']) ? $uri['port'] : 8080;
                }
        */
        // store loaded configuration
        session_set('config', $config);
    }
    // setup smarty
    $smarty->template_dir = array($config['templatedir'], 'templates/modern');
    $smarty->assign('template', $config['templatedir']);
    // initialize languages
    $lang = array();
    // load english language as default
    require './language/en.php';
    // override it with local language if nessesary:
    if ($config['language'] != 'en') {
        $languages = explode('_', $config['language']);
        $file = '';
        foreach ($languages as $language) {
            if ($file) {
                $file .= '_';
            }
            $file .= $language;
            @(include './language/' . $file . '.php');
            // convert languages to utf-8 encoding
            if ($lang['encoding'] != 'utf-8') {
                $lang = iconv_array($lang['encoding'], 'utf-8', $lang);
                $lang['encoding'] = 'utf-8';
            }
        }
    }
    // set connection character set and collation
    #   db_set_encoding();
}