Exemplo n.º 1
0
 protected static function _scandirIter($dirname, $root, $protocol, $f)
 {
     $opath = implode("/", array($root, $f));
     if ($f == "..") {
         $tpath = truepath(implode("/", array($dirname, $f)), false);
     } else {
         $tpath = implode("/", array($dirname, $f));
     }
     $vpath = sprintf("%s%s", $protocol, $tpath);
     //$on_root ? preg_replace("/^\//", "", $tpath) : $tpath);
     $iter = array("filename" => htmlspecialchars(basename($f)), "path" => $vpath, "size" => 0, "mime" => null, "type" => is_dir($opath) ? "dir" : "file", "ctime" => null, "mtime" => null);
     if (($mtime = @filemtime($opath)) > 0) {
         $iter["mtime"] = date(self::DATE_FORMAT, $mtime);
     }
     if (($ctime = @filectime($opath)) > 0) {
         $iter["ctime"] = date(self::DATE_FORMAT, $ctime);
     }
     if ($iter["type"] == "file") {
         if (is_writable($opath) || is_readable($opath)) {
             if ($mime = fileMime($opath)) {
                 $iter["mime"] = $mime;
             }
             if (($size = filesize($opath)) !== false) {
                 $iter["size"] = $size;
             }
         }
     }
     return $iter;
 }
Exemplo n.º 2
0
 public static function scandir($scandir, array $opts = array())
 {
     list($dirname, $root, $protocol) = getRealPath($scandir);
     $result = array();
     $on_root = !$dirname || $dirname == "/";
     if (file_exists($root) && is_dir($root)) {
         if (($files = scandir($root)) !== false) {
             foreach ($files as $f) {
                 if ($f == "." || $f == ".." && $on_root) {
                     continue;
                 }
                 $opath = implode("/", array($root, $f));
                 if ($f == "..") {
                     $tpath = truepath(implode("/", array($dirname, $f)), false);
                 } else {
                     $tpath = implode("/", array($dirname, $f));
                 }
                 $vpath = sprintf("%s%s", $protocol, $tpath);
                 //$on_root ? preg_replace("/^\//", "", $tpath) : $tpath);
                 $iter = array("filename" => htmlspecialchars($f), "path" => $vpath, "size" => 0, "mime" => null, "type" => is_dir($opath) ? "dir" : "file", "ctime" => null, "mtime" => null);
                 if (($mtime = @filemtime($opath)) > 0) {
                     $iter["mtime"] = date(self::DATE_FORMAT, $mtime);
                 }
                 if (($ctime = @filectime($opath)) > 0) {
                     $iter["ctime"] = date(self::DATE_FORMAT, $ctime);
                 }
                 if ($iter["type"] == "file") {
                     if (is_writable($opath) || is_readable($opath)) {
                         if ($mime = fileMime($opath)) {
                             $iter["mime"] = $mime;
                         }
                         if (($size = filesize($opath)) !== false) {
                             $iter["size"] = $size;
                         }
                     }
                 }
                 $result[] = $iter;
             }
         }
     } else {
         throw new Exception("Directory does not exist");
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * 运行应用实例
  * @access public
  * @return void
  */
 public function run()
 {
     //所有请求都会请求到这里
     /*
      * 统一入口
      * */
     if (C('USE_SESSION') == true) {
         session_start();
     }
     $router = new router();
     $conf['router'] = $router();
     //这个是路由
     C($conf);
     //路由进配置
     $this->loadAppConfig();
     //覆盖hmvc配置
     C('APP_FULL_PATH', truepath(getcwd() . '/' . C('APP_PATH')) . '/');
     C('BASE_FULL_PATH', truepath(getcwd() . '/' . C('APP_BASE')) . '/');
     spl_autoload_register(array('GracePHP', 'autoload'));
     //psr-0
     includeIfExist(C('BASE_FULL_PATH') . 'Seter/I.php');
     //第一时间载入服务层
     //除controllers外,都需要检测根下有没有相对应的组件
     //===========================================================
     $router = C('router');
     $router['params'] = isset($router['params']) ? $router['params'] : [];
     $params = $router['params_'];
     //===========================================================
     $controllerfile2 = C('APP_FULL_PATH') . C('controller_folder') . 'BaseController' . C('controller_file_subfix');
     includeIfExist($controllerfile2);
     //================================================
     //标准控制器不存在,检查扩展控制器
     $controller_ext_file = $router['Controller'] . '.' . $router['Action'] . ".php";
     $controllerfile = C('APP_FULL_PATH') . C('controller_folder') . $controller_ext_file;
     includeIfExist($controllerfile);
     if (!class_exists($router['Controller'])) {
         //扩展控制器没有加载成功 加载标准控制器
         $controllerfile = C('APP_FULL_PATH') . C('controller_folder') . $router['Controller'] . C('controller_file_subfix');
         includeIfExist($controllerfile);
         //===========================================================
     }
     //判断控制器是否存在
     if (!class_exists($router['Controller'])) {
         //404
         error404();
         halt('控制器' . $router['Controller'] . '不存在');
         //交由扩展进行判断
     }
     //实例化
     $controllerClass = $router['Controller'];
     $controller = new $controllerClass();
     //确定运行的方法
     //判断扩展方法
     $act_ext = $router['ispost'] ? '_post' : '';
     $act_ext = $router['Action_ext'] != 'post' ? $act_ext : '';
     $method = 'do' . ucfirst($router['Action']) . '_' . $router['Action_ext'] . $act_ext;
     if (!method_exists($controller, $method)) {
         //扩展post没找到
         $method = 'do' . ucfirst($router['Action']) . '_' . $router['Action_ext'];
         if (!method_exists($controller, $method)) {
             //扩展方法不存在,判断主方法
             $method = 'do' . ucfirst($router['Action']);
             if (!method_exists($controller, $method)) {
                 error404();
                 //                    halt('方法'.$method.'不存在2');
             }
         }
     }
     //        $params = $router['params'];
     //        if(count($router['params']) ==1 ){
     //            $nr = current(array_values($router['params']));
     //            if(empty($nr)){
     //                $params = current(array_keys($router['params']));
     //            }
     //        }
     //=====================================
     //扩展,对mothod 进行修改
     //标准动作扩展 insert update delete select json
     //_se[post]  _cg [change]    _de [delete]    json[jsonout]   vf[view flit] 显示筛选
     call_user_func(array($controller, $method), $params);
 }
Exemplo n.º 4
0
/**
 * Thumbnail generation
 */
function generate_thumbnail(&$file, &$width, &$height, $max_width, $max_height, $cache_tag)
{
    global $config;
    $thumb_cache_tag = $cache_tag . '_' . $max_width . 'x' . $max_height;
    // the names of the existing or to-be created thumbnail- still missing dimensions
    $thumb_name = './cache/' . CACHE_THUMBS . '/' . ($config['hierarchical'] ? substr($cache_tag, 0, 1) . '/' : '') . $cache_tag;
    // did we already create this thumbnail?
    if (THUMB_CACHE_TARGET && html_image_get_cache($thumb_cache_tag, $width, $height)) {
        // get updated filename
        $file = $thumb_name . '_' . $width . 'x' . $height . '.jpg';
        return;
    }
    // thumbnail not created yet
    $scale = min($max_width / $width, $max_height / $height);
    $width = round($width * $scale);
    $height = round($height * $scale);
    // really need to scale?
    $thumb_must_scale = $config['thumbnail_level'] == TUMB_SCALE || $config['thumbnail_level'] == TUMB_REDUCE_ONLY && $scale < 1 || $config['thumbnail_level'] > 1 && $config['thumbnail_level'] < @filesize($file);
    #dump("scaling required: ".(int)$thumb_must_scale." filesize: ".@filesize($file));
    // perform actual scaling
    if ($thumb_must_scale) {
        $phpThumb = new phpThumb();
        // use of truepath was added for php 5.4 apparently- otherwise thumbnail creation would inadvertantly fail
        $phpThumb->sourceFilename = truepath($file);
        $phpThumb->w = $max_width;
        $phpThumb->h = $max_height;
        if ($config['thumbnail_quality']) {
            $phpThumb->q = $config['thumbnail_quality'];
        }
        // set cache filename
        $thumb_name .= '_' . $width . 'x' . $height . '.jpg';
        #dump("thumbname:$thumb_name");
        // check to see if file already exists in cache, and output it with no processing if it does
        if (is_writable(dirname($thumb_name)) || is_writable($thumb_name)) {
            if (@filesize($thumb_name) || $phpThumb->GenerateThumbnail() && $phpThumb->RenderOutput() && file_put_contents($thumb_name, $phpThumb->outputImageData)) {
                $file = $thumb_name;
                if (THUMB_CACHE_TARGET) {
                    html_image_put_cache($thumb_cache_tag, $width . 'x' . $height);
                }
            }
            /*
            			# emergency debugging
            			else
            			{
            				dlog("Fail: $thumb_name");
            				dlog("fs: ".@filesize($thumb_name));
            				dlog($phpThumb->GenerateThumbnail());
            				dlog($phpThumb->RenderOutput());
            				dlog($phpThumb->debugmessages);
            			}
            */
        }
        // free memory
        $phpThumb = null;
    }
}
Exemplo n.º 5
0
 private function autoload()
 {
     $system = WoniuLoader::$system;
     $autoload_helper = $system['helper_file_autoload'];
     $autoload_library = $system['library_file_autoload'];
     $autoload_models = $system['models_file_autoload'];
     foreach ($autoload_helper as $val) {
         if (is_array($val)) {
             $key = key($val);
             $val = $val[$key];
             $this->helper($key, $val);
         } else {
             $this->helper($val);
         }
     }
     foreach ($autoload_library as $key => $val) {
         if (is_array($val)) {
             $new = isset($val['new']) ? $val['new'] : true;
             $key = key($val);
             $val = $val[$key];
             $this->lib($key, $val, $new);
         } else {
             $this->lib($val);
         }
     }
     foreach ($autoload_models as $key => $val) {
         if (is_array($val)) {
             $key = key($val);
             $val = $val[$key];
             $this->model($key, $val);
         } else {
             $this->model($val);
         }
     }
     /**
      * 如果使用了自定义缓存驱动,加载相应的文件
      */
     static $included = array();
     foreach ($system['cache_drivers'] as $filepath) {
         $file = pathinfo($filepath, PATHINFO_BASENAME);
         $namex = str_replace(".php", "", $file);
         //只include选择的缓存驱动文件
         if ($namex == $system['cache_config']['storage']) {
             if (!isset($included[truepath($filepath)])) {
                 WoniuLoader::includeOnce($filepath);
             } else {
                 $included[truepath($filepath)] = 1;
             }
         }
     }
 }
Exemplo n.º 6
0
 private function queryForFile($query, $file, $hash = false, $path = true)
 {
     /* Resolve path */
     if ($path) {
         $file = truepath($file);
     }
     /* Bind path */
     $query->bindValue(':path', SQLite3::escapeString($file), SQLITE3_TEXT);
     /* Calculate and bind/save hash */
     if ($hash) {
         $hash = hash($this->config['algorithm'], $file . microtime());
         $query->bindValue(':hash', $hash, SQLITE3_TEXT);
         $this->hash = $hash;
     }
     /* Execute query */
     return $query->execute();
 }
function truepath($path)
{
    if (file_exists($path)) {
        return true;
    } else {
        if (truepath(@dirname($path))) {
            if (@mkdir($path)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
Exemplo n.º 8
0
Arquivo: index.php Projeto: azuya/Wi3
                $setupconfig["step"] = 5;
                unset($setupconfig["originalpassword"]);
                // Unset the clear and unprotected password
                unset($_SESSION["originalpassword"]);
                // Unset the clear and unprotected password
            } else {
                // Didn't work
                $step = 4;
                $message = __("Database creation was successful, but tables therein could not be created. Please try again.");
                $setupconfig["step"] = 4;
            }
        }
    }
    savesetupconfig($setupconfig);
    // If the setup continues from step 5 without doing the above processing for step 4, we still need to fetch the URL of the current wi3 installation
    $url = (strpos($_SERVER["SERVER_PROTOCOL"], "HTTPS") > 0 ? "https" : "http") . "://" . $_SERVER["HTTP_HOST"] . truepath($_SERVER["REQUEST_URI"] . "/../");
    // Ensure trailing slash at the end
    if ($url[strlen($url) - 1] != "/") {
        $url .= "/";
    }
}
// Display menu
echo "<div id='menu'>";
echo "<div " . ($step == 1 ? "class='current'" : "") . "><h1>1.</h1><h2>" . ($step > 1 ? __("language") : "") . "</h2></div>";
echo "<div " . ($step == 2 ? "class='current'" : "") . "><h1>2.</h1><h2>" . ($step > 1 ? __("folders") : "") . "</h2></div>";
echo "<div " . ($step == 3 ? "class='current'" : "") . "><h1>3.</h1><h2>" . ($step > 1 ? __("security") : "") . "</h2></div>";
echo "<div " . ($step == 4 ? "class='current'" : "") . "><h1>4.</h1><h2>" . ($step > 1 ? __("database") : "") . "</h2></div>";
echo "<div " . ($step == 5 ? "class='current'" : "") . "><h1>5.</h1><h2>" . ($step > 1 ? __("urls") : "") . "</h2></div>";
echo "</div>";
// Display appropriate screen
echo "<div id='content'>";