Example #1
0
function get($key)
{
    global $page_admin, $main;
    if ($_SERVER['REQUEST_METHOD'] == 'GET') {
        $ret = isset($_GET[$key]) ? $_GET[$key] : null;
    } else {
        parse_str($_POST['query_string'], $output);
        $ret = isset($output[$key]) ? $output[$key] : null;
    }
    switch ($key) {
        case 'page':
            $valid_array = getdirlist(ROOT_PATH . "includes/pages/");
            array_unshift($valid_array, 'startup');
            break;
        case 'subpage':
            $valid_array = getdirlist(ROOT_PATH . "includes/pages/" . get('page') . '/', FALSE, TRUE);
            for ($key = 0; $key < count($valid_array); $key++) {
                $valid_array[$key] = basename($valid_array[$key], '.php');
                if (substr($valid_array[$key], 0, strlen(get('page')) + 1) != get('page') . '_') {
                    array_splice($valid_array, $key, 1);
                    $key--;
                } else {
                    $valid_array[$key] = substr($valid_array[$key], strlen(get('page')) + 1);
                }
            }
            array_unshift($valid_array, '');
            break;
    }
    if (isset($valid_array) && !in_array($ret, $valid_array)) {
        $ret = $valid_array[0];
    }
    return $ret;
}
Example #2
0
/**
 * @brief Get a request parameter from query string.
 * Depending the type of the key it will try to do sanitization and security
 * checking. Specifically for 'page' and 'subpage' it will check first that it exists.
 * @param string $key The key of the entry to fethch
 * @return Ambigous <string, unknown>
 */
function get($key)
{
    global $page_admin, $main;
    $ret = isset($_GET[$key]) ? $_GET[$key] : "";
    switch ($key) {
        case 'page':
            // Try to get page from path info (higher priority)
            if (!is_null(get_path_level(1))) {
                $ret = get_path_level(1);
            }
            $valid_array = getdirlist(ROOT_PATH . "includes/pages/");
            array_unshift($valid_array, 'startup');
            break;
        case 'subpage':
            // Try to get page from path info (higher priority)
            if (!is_null(get_path_level(2))) {
                $ret = get_path_level(2);
            }
            $valid_array = getdirlist(ROOT_PATH . "includes/pages/" . get('page') . '/', FALSE, TRUE);
            for ($key = 0; $key < count($valid_array); $key++) {
                $valid_array[$key] = basename($valid_array[$key], '.php');
                if (substr($valid_array[$key], 0, strlen(get('page')) + 1) != get('page') . '_') {
                    array_splice($valid_array, $key, 1);
                    $key--;
                } else {
                    $valid_array[$key] = substr($valid_array[$key], strlen(get('page')) + 1);
                }
            }
            array_unshift($valid_array, '');
            break;
        case 'node':
            $ret = intval($ret);
            break;
    }
    if (isset($valid_array) && !in_array($ret, $valid_array)) {
        $ret = $valid_array[0];
    }
    return $ret;
}
Example #3
0
 function save_import()
 {
     need_login('page');
     @set_time_limit(0);
     $timestamp = time();
     $dir = $this->getPost('dir');
     $autodel = $this->getPost('autodel') ? true : false;
     $savemode = intval($this->getPost('save_mode'));
     $album_id = intval($this->getRequest('aid'));
     if (substr($dir, 0, 1) == '/' || substr($dir, 1, 1) == ':') {
         //如果是绝对地址
         $dirpath = $dir;
     } else {
         $dirpath = ROOTDIR . $dir;
     }
     //判断扫描的文件夹是否存在
     if (!is_dir($dirpath)) {
         showError(lang('scan_dir_not_exists'));
     }
     if (!is_readable($dirpath)) {
         showError(lang('dir_cannot_read'));
     }
     //开始扫描文件夹
     $alldir = getdirlist($dirpath);
     if (!$alldir) {
         showError(lang('dir_has_no_files'));
     }
     $tmpfslib =& loader::lib('tmpfs');
     $imglib =& loader::lib('image');
     $supportType = $imglib->supportType();
     $album_num = 0;
     $photos_num = 0;
     foreach ($alldir as $dir => $files) {
         if (count($files) <= 0) {
             continue;
         }
         if ($savemode == 2) {
             $dirname = file_base($dir);
             $dirname = file_en_name($dirname) ? $dirname : date('Y-m-d', $timestamp) . '_' . rand(10, 99);
             $data = array('name' => $dirname, 'create_time' => $timestamp, 'enable_comment' => 1, 'cate_id' => 0);
             //创建相册
             $album_id = $this->mdl_album->save($data);
             $album_num++;
         }
         foreach ($files as $file) {
             $file_ext = file_ext($file);
             if (!in_array($file_ext, $supportType)) {
                 continue;
             }
             //将存储的图片读取到临时文件
             $tmpfile = time() . rand(1000, 9999) . '.' . $file_ext;
             $tmpfslib->write($tmpfile, file_get_contents($file));
             $tmpfilepath = $tmpfslib->get_path($tmpfile);
             if ($this->mdl_photo->save_upload($album_id, $tmpfilepath, file_base($file))) {
                 if ($autodel) {
                     @unlink($file);
                 }
                 $photos_num++;
             }
         }
         if ($savemode == 2) {
             $this->mdl_album->update_photos_num($album_id);
             $this->mdl_album->check_repare_cover($album_id);
         }
     }
     if ($savemode == 1) {
         $this->mdl_album->update_photos_num($album_id);
         $this->mdl_album->check_repare_cover($album_id);
     }
     $msg = lang('import_success', $album_num, $photos_num);
     $this->output->set('result_msg', $msg);
     $this->output->set('album_id', $album_id);
     //面包屑
     $crumb_nav = array();
     $crumb_nav[] = array('name' => lang('upload_photo'));
     $this->page_crumb($crumb_nav);
     $page_title = lang('upload_photo') . ' - ' . $this->setting->get_conf('site.title');
     $page_keywords = $this->setting->get_conf('site.keywords');
     $page_description = $this->setting->get_conf('site.description');
     $this->page_init($page_title, $page_keywords, $page_description);
     $this->render();
 }
Example #4
0
 /**
  * Refreshes the internal list of Extensions
  *
  * @param string $dir Extension directory
  */
 function refreshList($dir)
 {
     $moduledirs = getdirlist($dir);
     for ($m = 0; $m < count($moduledirs); $m++) {
         $path = $moduledirs[$m];
         if (file_exists($dir . $path . "/extension.php") && file_exists($dir . $path . "/extension.xml")) {
             if (!$this->getIdByPath($path)) {
                 $extConfig = new \framework\Config($dir . $path . "/extension.xml");
                 $extApiVersion = explode('.', (string) $extConfig->getVar("extension/api"));
                 if ($extApiVersion[0] != EXTENSION_VERSION_MAJOR) {
                     sLog()->error('Extension: API Version mismatch. Expected v' . EXTENSION_VERSION_MAJOR . '.x, Extension has v' . $extApiVersion[0] . '.x!');
                     return false;
                 }
                 require_once $dir . $path . "/extension.php";
                 $namespace = (string) $extConfig->getVar("extension/namespace");
                 $classname = $namespace . "\\" . (string) $extConfig->getVar("extension/class");
                 $code = strtolower(preg_replace("/[^A-Za-z0-9]/", "_", $classname));
                 try {
                     $extension = new $classname();
                 } catch (Exception $e) {
                     return;
                 }
                 $info = $extension->getInfo();
                 if ($this->getIdByCode($code) == NULL) {
                     $this->add($code, $path, $info["NAME"], $info["DEVELOPERNAME"], $info["VERSION"], $info["DESCRIPTION"], $info["URL"], $info["TYPE"]);
                 }
             }
         }
     }
     // Remove orphaned extensions from database
     $currentExtensions = $this->getList(0, false, true);
     foreach ($currentExtensions as $currentExtensionItem) {
         if (!$currentExtensionItem['INSTALLED'] && !in_array($currentExtensionItem['PATH'], $moduledirs)) {
             $currExtension = new Extension($currentExtensionItem['CODE']);
             $currExtension->uninstall();
             $extMgr = new ExtensionMgr();
             $extMgr->remove($currentExtensionItem['CODE']);
         }
     }
 }
Example #5
0
function getdirectorysize($root)
{
    $root = getRealpath($root);
    $size = 0;
    $fileList = getfilelist($root);
    foreach ($fileList as $file) {
        $size += filesize($root . "/" . $file);
    }
    $dirList = getdirlist($root);
    foreach ($dirList as $dir) {
        $size += getdirectorysize($root . "/" . $dir);
    }
    return $size;
}