コード例 #1
0
ファイル: ModelHandler.php プロジェクト: liammartens/xtend
 /**
  * Loads a model
  *
  * @param string $modelName
  * @param string|boolean $ns
  * @param boolean $createInstance
  *
  * @return model|boolean
  */
 public static function load($modelName, $ns = false)
 {
     // explode it on @ -> 0 will be the directive + namespace + classname
     // >1 index will be methods
     $at_explode = explode('@', $modelName);
     $modelName = $at_explode[0];
     // remove the model name from the array
     array_splice($at_explode, 0, 1);
     // set default namespace
     if ($ns === false) {
         $ns = App::namespace();
     }
     // extract directive
     $dot_pos = strrpos($modelName, '.');
     $directive = $dot_pos === false ? false : substr($modelName, 0, $dot_pos) . '.';
     // now only contains the classname and namespace
     if ($dot_pos !== false) {
         $modelName = substr($modelName, $dot_pos + 1);
     }
     // register name should be the classname and namespace of the original load
     $registerName = $modelName;
     // extract namespace and classname
     $back_pos = strrpos($modelName, '\\');
     // namespace now contains default namespace or specified namespace
     $ns = $back_pos === false ? $ns : substr($modelName, 0, $back_pos);
     // modelName now contains the classname
     if ($back_pos !== false) {
         $modelName = substr($modelName, $back_pos + 1);
     }
     // get file path and start inclusion
     $modelPath = $directive . $modelName;
     if (self::exists($modelPath)) {
         $className = trim($ns, '\\') . '\\' . $modelName;
         FileManager::include(App::models()->file($modelPath . '.php'));
         self::$_names[] = $registerName;
         self::$_name_bindings[$registerName] = $className;
         // execute requested @ functions
         // multiple methods can be called using multiple @ symbols
         foreach ($at_explode as $method) {
             if (method_exists($className, $method)) {
                 call_user_func([$className, $method]);
             }
         }
         return true;
     }
     return false;
 }
コード例 #2
0
ファイル: PostsController.php プロジェクト: rainbow88/hummel
 public function __construct()
 {
     parent::__construct();
     $system_cms = $this->load_config('version');
     require_once SYS_ROOT . 'libraries/cache_file.class.php';
     $this->cache = new cache_file();
     App::$namespace = $this->namespace = trim($this->router->directory, '/');
     App::$controller = $this->controller = $this->router->class;
     App::$action = $this->action = $this->router->method;
     App::$plugin = APP_DIR;
     $this->_init();
     $this->load->model('category');
     $this->cats = $this->get_category();
     $this->cats_dir = $this->get_category_dir();
     $this->content = Controller::model('content');
     $this->content->table_name = $this->content->prefix . 'content_' . $this->siteid;
     //var_dump(strstr($_SERVER['HTTP_HOST'],$_SERVER['SERVER_NAME']));
     if (strstr($_SERVER['HTTP_HOST'], $_SERVER['SERVER_NAME'])) {
         $siteUrl = $this->get_server_name() . $this->get_base_url();
         $sitepath = $this->get_base_url();
         define('PROXY_PATH', '');
     } else {
         $siteUrl = $_SERVER['HTTP_HOST'] . '/' . $_SERVER['HTTP_REFERER'] . '/';
         define('PROXY_PATH', 'http://' . $_SERVER['HTTP_HOST'] . '/' . $_SERVER['HTTP_REFERER']);
         $sitePath = 'http://' . $siteUrl;
         foreach ($this->cats as $k => $value) {
             $this->cats[$k]['url'] = PROXY_PATH . $value['url'];
         }
     }
     //定义网站常量
     define('IS_POST', $this->post('submit'));
     define('SITE_PATH', $sitePath);
     define('SITE_URL', $siteUrl);
     define('CMS_CMS', $system_cms['cms']);
     define('CMS_NAME', $system_cms['name']);
     define('CMS_COM', $system_cms['company']);
     define('CMS_VERSION', $system_cms['version']);
     define('CMS_UPDATE', $system_cms['update']);
     define('SITE_THEME', "." . $this->get_theme_url());
     define('ADMIN_THEME', SITE_PATH . basename(VIEW_DIR) . '/admin/');
     define('EXT_PATH', SITE_PATH . EXTENSION_PATH . '/');
     define('LANG_PATH', SITE_PATH . EXTENSION_PATH . '/language/' . SYS_LANGUAGE . '/');
     //echo '=============='.SITE_THEME;exit;
     //echo SITE_PATH;
     //禁止访问
     $ips = $this->cache->get('ip');
     $uip = $this->input->ip_address();
     if ($uip && $ips && is_array($ips)) {
         if (isset($ips[$uip]) && (empty($ips[$uip]['endtime']) || $ips[$uip]['endtime'] - $ips[$uip]['addtime'] >= 0)) {
             $this->adminMsg(lang('a-aip-6'));
         }
         foreach ($ips as $ip => $t) {
             if (empty($ip) || strpos($ip, '*') === false) {
                 continue;
             }
             if (preg_match('/^' . str_replace(array('*', '.'), array('[0-9]+', '\\.'), $ip) . '$/', $uip)) {
                 $this->adminMsg(lang('a-aip-6'));
             }
         }
         unset($ips, $ip);
     }
     $this->template = $this->view = new View();
     //载入会员系统缓存
     if (!$this->site['SYS_MEMBER'] && is_dir(CONTROLLER_DIR . 'member')) {
         $this->member = Controller::model('member');
         $this->membergroup = $this->cache->get('membergroup');
         $this->membermodel = $this->cache->get('model_member');
         $this->memberconfig = $this->cache->get('member');
         if ($this->memberconfig['uc_use'] == 1 && $this->namespace != 'admin') {
             include EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'config.inc.php';
             include EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'uc_client' . DIRECTORY_SEPARATOR . 'client.php';
         }
         $this->memberinfo = $this->getMember();
         $this->view->assign(array('memberinfo' => $this->memberinfo, 'membergroup' => $this->membergroup, 'membermodel' => $this->membermodel, 'memberconfig' => $this->memberconfig));
     }
     define('IS_ADMIN', $this->session->userdata('user_id'));
     $this->view->assign($this->site);
     $this->view->assign(array('s' => $this->namespace, 'c' => $this->controller, 'a' => $this->action, 'cats' => $this->cats, 'param' => $this->getParam(), 'sites' => App::get_site(), 'siteid' => $this->siteid, 'is_admin' => IS_ADMIN));
     //加载系统函数库和自定义函数库
     require EXTENSION_DIR . 'function.php';
     require EXTENSION_DIR . 'custom.php';
     date_default_timezone_set(SYS_TIME_ZONE);
     $this->load->library('user_agent');
 }
コード例 #3
0
ファイル: Common.php プロジェクト: kennyhonghui/zhuoxi
 public function __construct()
 {
     parent::__construct();
     if (!file_exists(APP_ROOT . './cache/install.lock')) {
         $this->redirect(url('install/'));
     }
     $system_cms = $this->load_config('version');
     require_once SYS_ROOT . 'libraries/cache_file.class.php';
     $this->cache = new cache_file();
     App::$namespace = $this->namespace = trim($this->router->directory, '/');
     App::$controller = $this->controller = $this->router->class;
     App::$action = $this->action = $this->router->method;
     App::$plugin = APP_DIR;
     $this->_init();
     $this->load->model('category');
     $this->cats = $this->get_category();
     $this->cats_dir = $this->get_category_dir();
     $this->content = Controller::model('content');
     $this->content->table_name = $this->content->prefix . 'content_' . $this->siteid;
     //定义网站常量
     define('IS_POST', $this->post('submit'));
     define('SITE_PATH', $this->get_base_url());
     define('SITE_URL', $this->get_server_name() . $this->get_base_url());
     define('CMS_CMS', $system_cms['cms']);
     define('CMS_NAME', $system_cms['name']);
     define('CMS_COM', $system_cms['company']);
     define('CMS_VERSION', $system_cms['version']);
     define('CMS_UPDATE', $system_cms['update']);
     define('SITE_THEME', $this->get_theme_url());
     define('ADMIN_THEME', SITE_PATH . basename(VIEW_DIR) . '/admin/');
     define('EXT_PATH', SITE_PATH . EXTENSION_PATH . '/');
     define('LANG_PATH', SITE_PATH . EXTENSION_PATH . '/language/' . SYS_LANGUAGE . '/');
     //禁止访问
     $ips = $this->cache->get('ip');
     $uip = $this->input->ip_address();
     if ($uip && $ips && is_array($ips)) {
         if (isset($ips[$uip]) && (empty($ips[$uip]['endtime']) || $ips[$uip]['endtime'] - $ips[$uip]['addtime'] >= 0)) {
             $this->adminMsg(lang('a-aip-6'));
         }
         foreach ($ips as $ip => $t) {
             if (empty($ip) || strpos($ip, '*') === false) {
                 continue;
             }
             if (preg_match('/^' . str_replace(array('*', '.'), array('[0-9]+', '\\.'), $ip) . '$/', $uip)) {
                 $this->adminMsg(lang('a-aip-6'));
             }
         }
         unset($ips, $ip);
     }
     $this->template = $this->view = new View();
     //载入会员系统缓存
     if (!$this->site['SYS_MEMBER'] && is_dir(CONTROLLER_DIR . 'member')) {
         $this->member = Controller::model('member');
         $this->membergroup = $this->cache->get('membergroup');
         $this->membermodel = $this->cache->get('model_member');
         $this->memberconfig = $this->cache->get('member');
         if ($this->memberconfig['uc_use'] == 1 && $this->namespace != 'admin') {
             include EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'config.inc.php';
             include EXTENSION_DIR . 'ucenter' . DIRECTORY_SEPARATOR . 'uc_client' . DIRECTORY_SEPARATOR . 'client.php';
         }
         $this->memberinfo = $this->getMember();
         $this->view->assign(array('memberinfo' => $this->memberinfo, 'membergroup' => $this->membergroup, 'membermodel' => $this->membermodel, 'memberconfig' => $this->memberconfig));
     }
     define('IS_ADMIN', $this->session->userdata('user_id'));
     $this->view->assign($this->site);
     $this->view->assign(array('s' => $this->namespace, 'c' => $this->controller, 'a' => $this->action, 'cats' => $this->cats, 'param' => $this->getParam(), 'sites' => App::get_site(), 'siteid' => $this->siteid, 'is_admin' => IS_ADMIN));
     //加载系统函数库和自定义函数库
     require EXTENSION_DIR . 'function.php';
     require EXTENSION_DIR . 'custom.php';
     date_default_timezone_set(SYS_TIME_ZONE);
     //
     if (!get_cookie('sb') && $this->db->query("SHOW TABLES LIKE '" . $this->db->dbprefix . "sb'")->row_array()) {
         $data = $this->db->limit(5)->order_by('id desc')->get('sb')->result_array();
         if ($data) {
             set_cookie('sb', 1, 600);
             $delete = array();
             foreach ($data as $t) {
                 $value = string2array($t['value']);
                 if ($t['type'] == 'content_add') {
                     // 文章推送到baidping
                     if (function_exists('curl_init')) {
                         $url = 'http://ping.baidu.com/ping/RPC2';
                         $xml = "\n                            <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n                            <methodCall>\n                                <methodName>weblogUpdates.extendedPing</methodName>\n                                <params>\n                                    <param>\n                                        <value><string>" . $data['title'] . "</string></value>\n                                    </param>\n                                    <param>\n                                        <value><string>" . SITE_URL . "</string></value>\n                                    </param>\n                                    <param>\n                                        <value><string>" . $data['url'] . "</string></value>\n                                    </param>\n                                    <param>\n                                        <value><string></string></value>\n                                    </param>\n                                </params>\n                            </methodCall>";
                         $ch = curl_init();
                         $head = array("POST " . $url . " HTTP/1.0", "Content-type: text/xml;charset=\"utf-8\"", "Accept: text/xml", "Content-length: " . strlen($xml));
                         curl_setopt($ch, CURLOPT_URL, $url);
                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                         curl_setopt($ch, CURLOPT_POST, 1);
                         curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
                         curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
                         $res = curl_exec($ch);
                         curl_close($ch);
                         if (strpos($res, "<int>0</int>")) {
                             $delete[] = $t['id'];
                         }
                     }
                 }
                 if ($delete) {
                     $this->db->where_in('id', $delete)->delete('sb');
                 }
             }
         }
     }
 }
コード例 #4
0
ファイル: Wow.php プロジェクト: liammartens/xtend
 /**
  * Starts a view compilation
  *
  * @param string $file
  * @param string|boolean $layout_dir
  * @param string|boolean $modules_dir
  *
  * @return string
  */
 public static function view($file, $layout_dir = false, $modules_dir = false)
 {
     //file hash
     $file_hash = hash('sha256', $file);
     //get file name 'name'
     $file_name = substr($file, strrpos($file, "/") + 1);
     $file_name = substr($file_name, 0, strpos($file_name, "."));
     //get view content
     $view_c = $file->read();
     //get view flags
     $version = self::_version($view_c);
     $layout = self::_layout($view_c);
     $layout_path = false;
     $flag = self::_flag($view_c);
     //check for layout existance -> if it doesnt exist, ignore the layout, thus set it to false
     if ($layout !== false) {
         $layout_path = $layout_dir === false ? App::layouts()->file($layout . '.wow.php', 2) : $layout_dir->file($layout . '.wow.php', 2);
         if (!$layout_path->exists()) {
             $layout = false;
             $layout_path = false;
         }
     }
     //get last compiled version of this view file -> sorting works descending thus most recent versions are first
     $is_new_version = true;
     $one_found = false;
     $compiled_views = App::viewOutput()->files();
     rsort($compiled_views);
     //check for the current version in the array
     foreach ($compiled_views as $cv) {
         $sl_pos = strrpos($cv, '/');
         $pos = strpos($cv, '.v');
         //get version number
         $v_num = floatval(trim(substr($cv, $pos + 2), '.php'));
         //get actual view name -> hash("sha256") of the view path
         $v_hash = substr($cv, $sl_pos + 1, $pos - $sl_pos - 1);
         //check for hash compliance
         if ($v_hash == $file_hash) {
             $one_found = true;
             if ($v_num >= $version) {
                 $is_new_version = false;
                 break;
             }
         }
     }
     //get whether the view has changed (either the view itself or the layout)
     $has_changed = self::changed($file, $view_c, $layout_path);
     //check whether view needs to be compiled
     $compile_view = false;
     if ($flag !== false) {
         //set to lowercase
         $flag = strtolower($flag);
         //check flag option
         if ($flag == 'always' || $flag != 'never' && !$one_found || $flag == 'version' && $is_new_version || $flag == 'change' && $has_changed || $flag == 'change+version' && $has_changed && $is_new_version) {
             $compile_view = true;
         }
     } else {
         $compile_view = true;
     }
     //view has to be compiled
     if ($compile_view) {
         $compiled_string = '';
         if ($layout !== false) {
             //compile using a layout
             $layout_parts = self::layout($layout_path->read(), $modules_dir);
             foreach ($layout_parts as $part) {
                 //check for section request
                 $section_match = [];
                 $is_section = preg_match(self::$_rx_section_name, $part, $section_match);
                 if ($is_section == 1) {
                     $section_name = $section_match[1];
                     //got the section name, now take the section content out of the view content
                     $rx = sprintf(self::$_rx_section_extract, $section_name, $section_name);
                     $rx_matches = [];
                     preg_match($rx, $view_c, $rx_matches);
                     if (isset($rx_matches[1]) && $rx_matches[1] != '') {
                         $compiled_string .= self::compile($rx_matches[1], $modules_dir);
                     } elseif (isset($rx_matches[2])) {
                         $compiled_string .= self::compile($rx_matches[2], $modules_dir);
                     }
                 } else {
                     $compiled_string .= $part;
                 }
             }
         } else {
             $compiled_string = self::compile($file->read(), $modules_dir);
         }
         //add namespace to compiled_string
         $compiled_string = "<?php namespace " . App::namespace() . "; ?>" . $compiled_string;
         //write view output
         App::viewOutput()->file("{$file_hash}.v{$version}.php", 2)->write($compiled_string);
         //update meta file
         self::update($file);
     }
     //return compiled view filename
     return App::viewOutput()->file("{$file_hash}.v{$version}.php", 2);
 }