/** * 析构函数 */ public function __destruct() { global $lang; view::assign('class', sharePHP::get_class()); view::assign('action', sharePHP::get_method()); view::display(); }
/** * 运行框架 * @param $application_dir 应用程序路径 */ public static function run($application_dir) { if (!$application_dir) { echo_('please defined your application dir...', true); } if (!file_exists($application_dir)) { echo_('directory ' . $application_dir . ' is not exists, place check...', true); } self::$application_dir = $application_dir; self::action(); }
/** * 文件哈希 */ public function sha1() { $file = $this->file('file'); if (intval($file['size']) <= 0) { return; } $tmp = sharePHP::get_application_dir() . 'tmp/'; $extension = substr($file['name'], strrpos($file['name'], '.') + 1); filesystem::mkdir($tmp); $filename = $tmp . '1.' . $extension; move_uploaded_file($file['tmp_name'], $filename); $result = sha1_file($filename); filesystem::rm($tmp); view::assign('result', $result); }
/** * 构造函数 */ public function __construct() { if (sharePHP::get_mode() === 2) { $get = fliter($_SERVER['REQUEST_URI']); $class = sharePHP::get_class(); $method = sharePHP::get_method(); $i = strpos(fliter($_SERVER['REQUEST_URI']), $class . '/' . $method); $get = explode('/', substr($get, $i + strlen($class . '/' . $method) + 1)); $flag = null; foreach ($get as $k => $g) { if ($flag === null) { $GLOBALS['_GET'][$g] = ''; $flag = fliter($g); } else { $GLOBALS['_GET'][$flag] = fliter($g); $flag = null; } } } }
<?php require dirname(__FILE__) . '/config.php'; //初始化数据库 $db_type = DB_TYPE; $database = 'share' . $db_type; model::init_db(new $database(DB_HOST, DB_USER, DB_PASS, DB_PRE, DB_NAME, DB_PORT, CHARSET)); //检查系统是否已经安装 if (!model::get_db()->can_use()) { redirect('install'); } //定义默认的类和方法 sharePHP::set_class(DEFAULT_CLASS); sharePHP::set_method(DEFAULT_METHOD); //定义框架运行模式 sharePHP::set_mode(MODE); //定义base_url sharePHP::set_base_url(BASE_URL); //设置皮肤 view::set_skin(SKIN); //运行sherePHP框架 sharePHP::run(DOCUMENT_ROOT);
/** * 导入网站图标 */ public static function load_short_icon() { echo '<link rel="shortcut icon" href="' . sharePHP::get_base_url() . 'skin/' . self::$skin . '/images/favicon.ico?' . filesystem::mtime(sharePHP::get_application_dir() . '/skin/' . self::$skin . '/images/favicon.ico') . '"/>'; }
/** * 生成管理菜单 */ public function menu($fliter_class = array(), $fliter_method = array()) { $dir = sharePHP::get_application_dir() . 'controller/'; chdir($dir); $list = glob('*.php'); foreach ($list as $file) { if (in_array(str_replace('.php', '', $file), $fliter_class, true)) { continue; } $str = explode('/**', file_get_contents($dir . '/' . $file)); $class = trim(str_replace('*', '', substr($str[1], 0, strrpos($str[1], '*/')))); foreach ($str as $s) { $s = explode('*', $s); foreach ($s as $ss) { $ss = str_replace('<?php', '', $ss); if (!trim($ss)) { continue; } if (strpos($ss, '@') <= 0 && strpos($ss, 'function') <= 0 && strpos($ss, '<p>') <= 0 && strpos($ss, '<br>') <= 0) { continue; } $index = stripos($ss, '){'); if ($index > 0) { $p1 = strpos($ss, '/'); $p2 = strpos($ss, 'p'); $ss = substr($ss, $p1 + 1, -$p2); $function = substr($ss, 0, $index); } if (strpos($function, 'private') > 0 || strpos($function, 'protected') > 0 || strpos($function, '__construct') > 0 || strpos($function, '__destruct') > 0) { continue; } $function = str_replace('public ', '', substr($ss, 0, $index)); $function = str_replace('function ', '', $function); $function = str_replace('()', '', $function); $filename = trim(substr($file, 0, -4)); $function = $filename . '.' . str_replace('/', '', trim($function)); if (in_array($function, $fliter_method, true)) { continue; } $menu[trim($class) . '#' . trim($filename)][trim($function)] = trim($s[1]); } } } view::assign('menu', $menu); return $menu; }