public static function getJsPath($params) { $files = isset($params['file']) ? trim($params['file']) : ''; $scope = isset($params['scope']) ? trim($params['scope']) : 'global'; //'module' or 'global' $contextpath = C('env.contextpath', '/'); $filedir = $contextpath . 'misc/js/'; $version = defined('STATIC_VERSION') ? STATIC_VERSION : ''; if ('global' != $scope) { $filedir = $contextpath . SimPHP::$gConfig['modroot'] . '/' . current_module() . '/js/'; } return $filedir . $files . (strrpos($files, '?') === FALSE ? '?' : '&') . $version; }
function filter_rewrite_module_lower(&$values) { $default = current_module(); if (cmd_switch('rewrite_module')) { $values['rewrite_module'] = cmd_switch('rewrite_module'); $values['rewrite_module_lower'] = strtolower($module); } else { $module = user_module_path("Select a module to override", $default); list($codepool, $company, $module) = explode("/", $module); $values['rewrite_module'] = $module; $values['rewrite_module_lower'] = strtolower($module); } }
/** * 'add_js' tpl func */ public static function add_js($params, $tpl = NULL) { $files = isset($params['file']) ? trim($params['file']) : ''; $scope = isset($params['scope']) ? trim($params['scope']) : 'global'; //'module' or 'global' $mod = isset($params['mod']) ? trim($params['mod']) : ''; //when scope='module', indicating module name $pos = isset($params['pos']) ? trim($params['pos']) : 'foot'; //'head' or 'foot' or 'current' $ismin = isset($params['ismin']) ? intval($params['ismin']) : 0; //whether min zip $disable = isset($params['disable']) ? intval($params['disable']) : 0; //whether disable it $ver = isset($params['ver']) ? trim($params['ver']) : 'rand'; //whether with version controlling, optional value: 'rand','none','','VERSION' if ($disable) { return ''; } $content = ''; $version = defined('STATIC_VERSION') && $ver == 'rand' ? STATIC_VERSION : $ver; if ('' != $files) { $contextpath = C('env.contextpath', '/'); $filedir = $contextpath . 'misc/js/'; if ('global' != $scope) { $mod = empty($mod) ? current_module() : $mod; $filedir = $contextpath . SimPHP::$gConfig['modroot'] . '/' . $mod . '/js/'; } if (!isset($GLOBALS['_JSPATHS'])) { $GLOBALS['_JSPATHS'] = array('head' => array(), 'foot' => array()); } $filesarr = explode(',', $files); foreach ($filesarr as $filename) { $filepath = $filedir . $filename; if (preg_match("!^(http|https):\\/\\/!i", $filename) || preg_match("!^\\/\\/!", $filename)) { $filepath = $filename; } elseif (0 === strpos($filename, '/')) { // absolute path $filepath = $contextpath . substr($filename, 1); } if ($ver && $ver != '0' && $ver != 'none') { $filepath .= (strrpos($filepath, '?') === FALSE ? '?' : '&') . 'ver=' . $version; } $html = "<script type=\"text/javascript\" src=\"{$filepath}\"></script>"; if ('current' == $pos) { $content .= $html; } else { $GLOBALS['_JSPATHS'][$pos][] = $html; } } } return $content; }
if (!empty($split[1])) { $split[1] = trim($split[1], "/"); $args = explode('/', $split[1]); } $_GET = array_merge($_POST, $_GET); $_POST = array_merge($_POST, $_GET); $db = new Database(); registerModules(); //run the init hook, nothing should be returned exec_hook('init'); $status = 0; ob_start(); //get the routing from each module, check them against the current path $paths = exec_hook('routes'); foreach ($paths as $module_name => $module) { current_module($module_name); if (array_key_exists($path, $module)) { $callback = $module[$path]; $access = true; if (isset($callback['access_callback']) && function_exists($callback['access_callback'])) { $access = call_user_func_array($callback['access_callback'], $args); } if ($access) { if (isset($callback['callback']) && function_exists($callback['callback'])) { $returned = call_user_func_array($callback['callback'], $args); print $returned; } else { $status = 500; elog('either callback is not set or is invalid', 'error', 'bootstrap'); } } else {
function engagement_process_users() { $template = new Template(); $template->add_js('js/process_users.engagement.js', current_module()); $template->c('<h1>Processing Users</h1>'); $template->c('<div class="well"><pre id="log"</pre></div>'); //$page->get_posts(false); //redirect(get_url('/'), 301, true); return $template->render(); }
/** * Dispatch request to Controller * */ public function dispatch(Request $request = NULL, Response $response = NULL) { $request = isset($request) ? $request : new Request(); $response = isset($response) ? $response : new Response(); // Import common module $flag = import('common/*'); // Adjust $_GET['q'] $request->adjust_q(); // Call possible hooks if (method_exists('Common_Controller', 'on_shutdown')) { register_shutdown_function(array('Common_Controller', 'on_shutdown'), $request, $response); } if (method_exists('Common_Controller', 'on_dispatch_before')) { Common_Controller::on_dispatch_before($request, $response); } $module = ''; $action = ''; $q = $request->q(); if ('' == $q) { $q = 'default' . $this->qsep . 'index'; } $qarr = explode($this->qsep, $q); if (count($qarr) > 0) { $module = strtolower($qarr[0]); $action = isset($qarr[1]) ? strtolower($qarr[1]) : 'index'; $moddir = $this->modRootDir() . $module; if (is_dir($moddir)) { $ctlname = ucfirst($module) . '_Controller'; $modfile = $moddir . '/' . $ctlname . '.php'; if (file_exists($modfile)) { // import all class under "$this->modroot/$module/*" import($module, $this->modroot); current_module($module); //save current module // find controller action and dispatch $ctrl = new $ctlname(); $menu = $ctrl->menu(); //hook menu if (count($menu)) { foreach ($menu as $key => $val) { if (self::qMatchPattern($key, $q)) { $action = $val; break; } } } // dispatch if ('' != $action && $ctrl->action_exists($action)) { // hook init $ctrl->init($action, $request, $response); // dispatch action $ctrl->{$action}($request, $response); // tigger dispatch after hook if (method_exists('Common_Controller', 'on_dispatch_after')) { Common_Controller::on_dispatch_after($request, $response); } exit; } } } } throw new NotFoundException(); }