Пример #1
0
function register($tag, $func)
{
    $tags =& \ui\global_var('shortcode_tags', array());
    $tags[] = $tag;
    \ui\global_var('shortcode_tags_regx', join('|', array_map('preg_quote', $tags)), 1);
    \ui\register_hook('shortcode_tag_' . $tag, $func);
}
Пример #2
0
 function load($locale = false)
 {
     global $_LANG_POT;
     if ($locale == false) {
         if (isset($_REQUEST['lang'])) {
             $locale = substr($_REQUEST['lang'], 0, 2);
         } elseif (isset($_SESSION['lang_code'])) {
             $locale = $_SESSION['lang_code'];
         } elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
             $langs = array();
             // break up string into pieces (languages and q factors)
             preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\\s*(;\\s*q\\s*=\\s*(1|0\\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse);
             if (count($lang_parse[1])) {
                 // create a list like "en" => 0.8
                 $langs = array_combine($lang_parse[1], $lang_parse[4]);
                 // set default to 1 for any without q factor
                 foreach ($langs as $lang => &$val) {
                     if ($val === '') {
                         $val = 1;
                     }
                     $val = (double) $val;
                 }
                 // sort list based on value
                 arsort($langs, SORT_NUMERIC);
             }
             // Check them all, until we find a match
             foreach ($langs as $locale => $priority) {
                 // Turn en-gb into en
                 $locale = strtolower(substr($locale, 0, 2));
                 // Check its in the array. If so, break the loop, we have one!
                 if (file_exists(\ui\global_var('app_dir') . 'lang/' . $locale . '.php')) {
                     break;
                 }
             }
         }
     }
     $_LANG_POT = array();
     $locale = preg_replace('[^a-z]', '', strtolower($locale));
     if (!file_exists(\ui\global_var('app_dir') . 'lang/' . $locale . '.php')) {
         $locale = \ui\config('lang');
     } else {
         $_SESSION['lang_code'] = $locale;
     }
     include 'lang/' . $locale . '.php';
     $_LANG_POT['lang_code'] = $locale;
     if (\ui\config('lang_write')) {
         \ui\register_hook('exit', '\\ui\\lang\\write');
     }
 }
Пример #3
0
/**
 * Starts a cached block. Nested cache blocks are allowed.
 * If cache is not found, boolean TRUE is returned.
 * If cache is found boolean FALSE, or the cached data is returned depending upon $return
 * @example if(\ui\cache\start()===TRUE){ [... expensive work...] \ui\cache\stop();}
 * @param $id string|bool If absent/false, then id is generated automatically using make_id()
 * @param $return bool wether to return cached data and not echo it, or echo it.
 */
function start($id = false, $timeout = false, $return = false)
{
    if ($id === false) {
        $id = make_id();
    }
    if (isset($_GET['nocache']) && $_GET['nocache'] == \ui\config('nocache_code')) {
        global $ui_cache_ignores, $ui_cache_ids;
        $ui_cache_ids[] = $ui_cache_ignores[] = $id;
        return TRUE;
    }
    if (($data = exists($id, $timeout, true)) !== false) {
        if ($return) {
            return $data;
        }
        echo $data;
        return FALSE;
    }
    ob_start();
    global $ui_cache_ids;
    $ui_cache_ids[] = $id;
    \ui\register_hook('content_end', '\\ui\\cache\\silent_stop');
    return TRUE;
}
Пример #4
0
        load($container);
    }
    if ($key !== false && $create_if_not && !isset($data[$container][$key])) {
        $data[$container][$key] = $default;
    }
    if ($key !== false && isset($data[$container][$key])) {
        return $data[$container][$key];
    }
    if ($key === false) {
        return $data[$container];
    }
    return $default;
}
function &set($container, $key, $val, $update = false)
{
    $data =& data();
    if (!isset($data[$container])) {
        load($container);
    }
    if ($key !== false) {
        $data[$container][$key] = $val;
    } else {
        $data[$container][] = $val;
    }
    if ($update) {
        update($container);
    }
    return $data[$container];
}
\ui\register_hook('exit', '\\ui\\data\\update');