/** * 文件哈希 */ 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); }
/** * 自动导入 * @param $class 类名(如果是导入model则是m + model名,例:madmin::list()) */ function __autoload($class) { if (strpos($class, 'controller') > 0) { $autoload = sharePHP::get_application_dir() . '/controller/' . str_replace('controller', '', $class) . '.php'; } else { $autoload = sharePHP::get_application_dir() . '/model/' . substr($class, 1) . '.php'; if (!file_exists($autoload)) { $autoload = SHARE_ROOT . 'class/' . $class . '.php'; } } load_file($autoload); //分页类特殊处理 if ($class === 'page') { page::set_rewrite(MODE === 2); } }
/** * 导入网站图标 */ 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; }