Beispiel #1
0
 function show()
 {
     module_conf('db_installer', 'create_table_post_callbacks', ['^b_bets_(?P<shard>[0-9]{4}_[0-9]{2}_[0-9]{2})$' => function ($table, $struct, $db, $m) {
         // From b_bets_2014_01_01 Will produce 140101000000000
         $auto_inc = substr(str_replace('_', '', $m['shard']), 2) . '000000000';
         return $db->query('ALTER TABLE ' . $table . ' AUTO_INCREMENT = ' . $auto_inc);
     }, '^b_contracts_(?P<shard>[0-9]{4}_[0-9]{2})$' => function ($table, $struct, $db, $m) {
         // From b_contracts_2014_01 Will produce 14010000000
         $auto_inc = substr(str_replace('_', '', $m['shard']), 2) . '0000000';
         return $db->query('ALTER TABLE ' . $table . ' AUTO_INCREMENT = ' . $auto_inc);
     }]);
     db()->query('DROP TABLE IF EXISTS b_bets_2020_01_01');
     db()->query('SELECT * FROM b_bets_2020_01_01');
     db()->query('DROP TABLE IF EXISTS b_contracts_2020_01');
     db()->query('SELECT * FROM b_contracts_2020_01');
 }
Beispiel #2
0
 public function test_bug_04()
 {
     conf('unit_test_conf_item1', '5');
     $this->assertEquals('5', conf('unit_test_conf_item1'));
     conf('unit_test_conf_item2', '6');
     $this->assertEquals('6', conf('unit_test_conf_item2'));
     module_conf('main', 'unit_var1', '4');
     $this->assertEquals('4', module_conf('main', 'unit_var1'));
     module_conf('main', 'unit_var2', '5');
     $this->assertEquals('5', module_conf('main', 'unit_var2'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item1 eq "5" and conf.unit_test_conf_item2 eq "6")} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item1 eq 5 and conf.unit_test_conf_item2 eq 6)} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item1 eq 1 or conf.unit_test_conf_item2 eq 6)} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item1 ne 1 or conf.unit_test_conf_item2 ne 1)} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item2 eq "6" and module_conf.main.unit_var2 eq "5")} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item2 eq 6 and module_conf.main.unit_var2 eq 5)} ok {/if}'));
 }
Beispiel #3
0
 function _get_cache($cache_name = '')
 {
     // Reference to the categories array
     $cache_file = INCLUDE_PATH . 'core_cache/cache_' . $cache_name . '.php';
     if (!file_exists($cache_file)) {
         return false;
     }
     // Delete expired cache files
     $last_modified = filemtime($cache_file);
     $TTL = 86400;
     $cache_ttl = module_conf('cache', 'FILES_TTL');
     if (!empty($cache_ttl)) {
         $TTL = intval($cache_ttl);
     }
     if ($last_modified < time() - $TTL) {
         return false;
     }
     // Get data from file
     return eval('return ' . substr(file_get_contents($cache_file), 7, -4) . ';');
 }
Beispiel #4
0
 /**
  */
 function _hook_settings(&$selected = [])
 {
     $selected['site_maintenance'] = conf('site_maintenance') ?: 0;
     $selected['main[USE_SYSTEM_CACHE]'] = module_conf('main', 'USE_SYSTEM_CACHE') || defined('USE_CACHE') && USE_CACHE ?: 0;
     // TODO: unify and simplify
     $selected['cache[DRIVER]'] = module_conf('cache', 'DRIVER') ?: 'memcache';
     $selected['main[ALLOW_DEBUG_PROFILING]'] = main()->ALLOW_DEBUG_PROFILING;
     $selected['DEBUG_CONSOLE_POPUP'] = conf('DEBUG_CONSOLE_POPUP');
     return [['yes_no_box', 'site_maintenance', ['tip' => '']], ['yes_no_box', 'main[USE_SYSTEM_CACHE]', ['desc' => 'use_cache']], ['select_box', 'cache[DRIVER]', $this->cache_drivers, ['desc' => 'cache_driver']], ['select_box', 'css_framework', $this->css_frameworks, ['show_text' => 1]], ['yes_no_box', 'main[ALLOW_DEBUG_PROFILING]', ['desc' => 'Use built-in code profiling (for DEBUG_MODE)']], ['yes_no_box', 'DEBUG_CONSOLE_POPUP', ['desc' => 'Debug console as popup window (for DEBUG_MODE)']]];
 }
Beispiel #5
0
 public function test_5()
 {
     module_conf('test', ['key1' => 'val1', 'key2::sub1' => 'val21', 'key2::sub2' => 'val22', 'key2::sub3::ss1' => 'val231', 'key2::sub3::ss2' => 'val232', 'key2::sub4::ss1::sss1' => 'val2411', 'key2::sub4::ss1::sss2' => 'val2412']);
     $_conf_should_be = ['test' => ['key1' => 'val1', 'key2' => ['sub1' => 'val21', 'sub2' => 'val22', 'sub3' => ['ss1' => 'val231', 'ss2' => 'val232'], 'sub4' => ['ss1' => ['sss1' => 'val2411', 'sss2' => 'val2412']]]]];
     $this->assertEquals($GLOBALS['PROJECT_CONF'], $_conf_should_be);
 }
Beispiel #6
0
<?php

// Fast throw output cache page
return function () {
    $MODULE_CONF = module_conf('output_cache');
    if (!conf('language')) {
        conf('language', 'en');
    }
    // Do not use cache for members
    if (!empty($_COOKIE['member_id'])) {
        return false;
    }
    if (isset($_GET['no_cache']) || isset($_GET['refresh_cache'])) {
        return false;
    }
    // Special for the 'share on facebook' feature
    if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'facebookexternalhit')) {
        return false;
    }
    $w = $MODULE_CONF['WHITE_LIST_PATTERN'];
    if (!empty($w)) {
        if (is_array($w)) {
            if (defined('SITE_DEFAULT_PAGE')) {
                @parse_str(substr(SITE_DEFAULT_PAGE, 3), $_tmp);
            }
            $_object = $_GET['object'] ? $_GET['object'] : $_tmp['object'];
            $_action = $_GET['action'] ? $_GET['action'] : 'show';
            if (!isset($w[$_object])) {
                $NO_NEED_TO_CACHE = true;
            } elseif (!empty($w[$_object]) && !in_array($_action, (array) $w[$_object])) {
                $NO_NEED_TO_CACHE = true;
Beispiel #7
0
 // Try to get tip id
 $TIP_ID = substr($_REQUEST['id'], strlen('help_'));
 if (empty($TIP_ID) && !main()->USE_SYSTEM_CACHE) {
     return false;
 }
 if (main()->USE_SYSTEM_CACHE && empty($tip_info)) {
     clearstatcache();
     $locale_specific = '___' . (DEFAULT_LANG != 'DEFAULT_LANG' ? DEFAULT_LANG : 'en');
     $cache_file = INCLUDE_PATH . 'core_cache/cache_tips' . $locale_specific . '.php';
     if (!file_exists($cache_file)) {
         return false;
     }
     // Delete expired cache files
     $last_modified = filemtime($cache_file);
     $TTL = 86400;
     $cache_ttl = module_conf('cache', 'FILES_TTL');
     if (!empty($cache_ttl)) {
         $TTL = intval($cache_ttl);
     }
     if ($last_modified < time() - $TTL) {
         return false;
     }
     // Get data from file
     $tips_array = eval('return ' . substr(file_get_contents($cache_file), 7, -4) . ';');
     $tip_info = $tips_array[$TIP_ID];
 }
 main()->NO_GRAPHICS = true;
 // Display data
 if (empty($tip_info)) {
     $body = 'No info';
 } else {
Beispiel #8
0
 /**
  * Url rewriting engine init and apply if rewrite is enabled
  */
 function _do_rewrite()
 {
     $this->PROFILING && ($this->_timing[] = [microtime(true), __CLASS__, __FUNCTION__, $this->trace_string(), func_get_args()]);
     if ($this->is_console() || MAIN_TYPE_ADMIN || !module_conf('tpl', 'REWRITE_MODE')) {
         return false;
     }
     $this->events->fire('main.before_rewrite');
     $host = $_SERVER['HTTP_HOST'];
     $request_uri = $_SERVER['REQUEST_URI'];
     // Override by WEB_PATH
     if (defined('WEB_PATH') && !$this->web_path_was_not_defined) {
         $w = parse_url(WEB_PATH);
         $w_host = $w['host'];
         $w_port = $w['port'];
         $w_path = $w['path'];
         $host = $w_host . (strlen($w_port) > 1 ? ':' . $w_port : '') . (strlen($w_path) > 1 ? $w_path : '');
         if ($w_path != '/' && substr($request_uri, 0, strlen($w_path)) == $w_path) {
             $request_uri = substr($request_uri, strlen($w_path));
             $request_uri = '/' . ltrim($request_uri, '/');
         }
     }
     if (isset($_GET['host']) && !empty($_GET['host'])) {
         $host = $_GET['host'];
     }
     list($u, ) = explode('?', trim($request_uri, '/'));
     $u_arr = explode('/', preg_replace('/\\.htm.*/', '', $u));
     $orig_object = $_GET['object'];
     $orig_action = $_GET['action'];
     unset($_GET['object']);
     unset($_GET['action']);
     $class_rewrite = $this->_class('rewrite');
     $arr = $class_rewrite->REWRITE_PATTERNS['yf']->_parse($host, $u_arr, $_GET, '', $class_rewrite);
     foreach ((array) $arr as $k => $v) {
         if ($k != '%redirect_url%') {
             $_GET[$k] = $v;
         }
     }
     foreach ((array) $_GET as $k => $v) {
         if ($v == '') {
             unset($_GET[$k]);
         }
     }
     if (!isset($_GET['action'])) {
         $_GET['action'] = 'show';
     }
     if (!$this->is_console() && !isset($_SESSION['utm_source'])) {
         $utm_source = $_GET['utm_source'] ?: ($_POST['utm_source'] ?: $_COOKIE['utm_source']);
         if (!$utm_source && $_SERVER['HTTP_REFERER']) {
             $cur_domain = trim($_SERVER['HTTP_HOST']);
             $ref_domain = trim(parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST));
             if ($ref_domain && $ref_domain != $cur_domain) {
                 $utm_source = $ref_domain;
             }
         }
         if ($utm_source) {
             $_SESSION['utm_source'] = trim(preg_replace('~[^a-z0-9\\.\\/_@-]~ims', '', substr(strtolower($utm_source), 0, 255)));
         }
     }
     $_SERVER['QUERY_STRING'] = http_build_query((array) $_GET);
     $this->events->fire('main.after_rewrite');
 }
Beispiel #9
0
 /**
  * Replace standard patterns
  */
 function _replace_std_patterns($string, $name = '', array &$replace, $params = [])
 {
     $_this = $this;
     $tpl = tpl();
     $patterns = ['/\\{const\\(\\s*["\']{0,1}([a-z_][a-z0-9_]+?)["\']{0,1}\\s*\\)\\}/i' => function ($m) {
         return defined($m[1]) ? constant($m[1]) : '';
     }, '/\\{conf\\(\\s*["\']{0,1}([a-z_][a-z0-9_:]+?)["\']{0,1}\\s*\\)\\}/i' => function ($m) {
         return conf($m[1]);
     }, '/\\{module_conf\\(\\s*["\']{0,1}([a-z_@][a-z0-9_:]+?)["\']{0,1}\\s*,\\s*["\']{0,1}([a-z_][a-z0-9_:]+?)["\']{0,1}\\s*\\)\\}/i' => function ($m) {
         return module_conf($m[1], $m[2]);
     }, '/\\{(t|translate|i18n)\\(\\s*["\']{0,1}(.*?)["\']{0,1}\\s*\\)\\}/ims' => function ($m) use($replace, $name, $tpl) {
         return $tpl->_i18n_wrapper($m[2], $replace);
     }, '/\\{cleanup\\(\\s*\\)\\}(.*?)\\{\\/cleanup\\}/ims' => function ($m) {
         return trim(str_replace(["\r", "\n", "\t"], '', stripslashes($m[1])));
     }, '/\\{(tip|itip)\\(\\s*["\']{0,1}(?P<raw>[^"\'\\)\\}]*)["\']{0,1}\\s*\\)\\}/ims' => function ($m) use($replace, $name) {
         return _class_safe('graphics')->tip(['raw' => $m['raw'], 'replace' => $replace, 'tpl_name' => $name]);
     }, '/\\{(e|user_error)\\(\\s*["\']{0,1}([\\w\\-\\.]+)["\']{0,1}\\s*\\)\\}/ims' => function ($m) {
         return common()->_show_error_inline($m[2]);
     }, '/\\{ad\\(\\s*["\']{0,1}([^"\'\\)\\}]*)["\']{0,1}\\s*\\)\\}/ims' => function ($m) {
         return module_safe('advertising')->_show(['ad' => $m[1]]);
     }, '/\\{url\\(\\s*["\']{0,1}([^"\'\\)\\}]*)["\']{0,1}\\s*\\)\\}/ims' => function ($m) use($tpl) {
         return $tpl->_url_wrapper($m[1]);
     }, '/\\{form_row\\(\\s*["\']{0,1}[\\s\\t]*([a-z0-9\\-_]+)[\\s\\t]*["\']{0,1}([\\s\\t]*,[\\s\\t]*["\']{1}([^"\']*)["\']{1})?([\\s\\t]*,' . '[\\s\\t]*["\']{1}([^"\']*)["\']{1})?([\\s\\t]*,[\\s\\t]*["\']{1}([^"\']*)["\']{1})?\\s*\\)\\}/ims' => function ($m) use($replace, $name) {
         return _class('form2')->tpl_row($m[1], $replace, $m[3], $m[5], $m[7]);
     }, '/\\{([a-z0-9\\-\\_]+)\\|([a-z0-9\\-\\_\\|]+)\\}/ims' => function ($m) use($replace, $name, $tpl) {
         return $tpl->_process_var_filters($replace[$m[1]], $m[2]);
     }, '/\\{([a-z0-9\\-\\_]+)\\.([a-z0-9\\-\\_]+)\\|([a-z0-9\\-\\_\\|]+)\\}/ims' => function ($m) use($replace, $name, $tpl) {
         $val = $replace[$m[1]][$m[2]];
         return $tpl->_process_var_filters($val ?: $class_prop, $m[3]);
     }];
     // Evaluate custom PHP code pattern. Examples: {eval_code(print_r(_class('forum')))}
     if ($tpl->ALLOW_EVAL_PHP_CODE) {
         $patterns['/(\\{eval_code\\()([^\\}]+?)(\\)\\})/i'] = function ($m) {
             return eval('return ' . $m[2] . ' ;');
         };
     }
     // Custom patterns support (intended to be used inside modules/plugins)
     foreach ((array) $tpl->_custom_patterns_funcs as $pattern => $func) {
         $patterns[$pattern] = function ($m) use($replace, $name, $_this, $func) {
             return $func($m, $replace, $name, $_this);
         };
     }
     if (DEBUG_MODE) {
         // Evaluate custom PHP code pattern special for the DEBUG_MODE. Examples: {_debug_get_replace()}
         $patterns['/(\\{_debug_get_replace\\(\\)\\})/i'] = function ($m) use($replace, $name) {
             return is_array($replace) ? '<pre>' . print_r(array_keys($replace), 1) . '</pre>' : '';
         };
         // Evaluate custom PHP code pattern special for the DEBUG_MODE. Examples: {_debug_stpl_vars()}
         $patterns['/(\\{_debug_get_vars\\(\\)\\})/i'] = function ($m) use($string, $tpl) {
             return $tpl->_debug_get_vars($string);
         };
     }
     foreach ((array) $patterns as $pattern => $callback) {
         $string = preg_replace_callback($pattern, $callback, $string);
     }
     return $string;
 }
Beispiel #10
0
 public function test_if_conf_complex()
 {
     module_conf('main', 'unit_var2', '5');
     conf('unit_test_conf_item2', '6');
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item2 eq "6" and module_conf.main.unit_var2 eq "5")} ok {/if}'));
     $this->assertEquals(' ok ', self::_tpl('{if(conf.unit_test_conf_item2 eq 6 and module_conf.main.unit_var2 eq 5)} ok {/if}'));
 }
Beispiel #11
0
        $dir = 'share/fast_init/';
        $suffix = '.php';
        $pattern = $dir . $f_name . $suffix;
        $globs = ['project_app_plugins' => APP_PATH . 'plugins/*/' . $pattern, 'project_app' => APP_PATH . $pattern, 'yf_plugins' => YF_PATH . 'plugins/*/' . $pattern, 'yf_main' => YF_PATH . $pattern];
        foreach ($globs as $gname => $glob) {
            foreach (glob($glob) as $path) {
                $func = (include $path);
                return $func();
            }
        }
        return false;
    };
} else {
    $fast_init_call = $CONF['fast_init_call'];
}
// try
if ($fname) {
    $done = $fast_init_call($fname);
}
// log
if ($done) {
    if (module_conf('main', 'LOG_EXEC')) {
        $fast_init_call('log_exec');
    }
    if (DEBUG_MODE && !main()->_no_fast_init_debug) {
        $body .= '<hr>DEBUG INFO:' . PHP_EOL;
        $body .= '<br />exec time: <b>' . round(microtime(true) - main()->_time_start, 5) . '</b> sec';
        echo $body;
    }
    exit;
}