Пример #1
0
 public function make($dir)
 {
     $moduleName = 'Default';
     if (strpos($dir, 'modules/') !== false) {
         $tmp = explode('modules/', $dir);
         $moduleName = ucfirst(str_replace('/controllers/', '', $tmp[1]));
     }
     $list = XF_File::fileAll($dir);
     if (!is_array($list)) {
         return;
     }
     foreach ($list as $l) {
         if (strpos($l, 'Controller.php') !== false) {
             @(require_once $dir . $l);
             $classname = $cname = str_replace('.php', '', $l);
             if ($moduleName != 'Default') {
                 $classname = $moduleName . '_' . $classname;
             }
             if (class_exists($classname) && strpos($classname, 'Abstract') === false) {
                 $this->_map[$classname] = array();
                 $ref = new ReflectionClass(new $classname());
                 $methods = $ref->getMethods(ReflectionMethod::IS_PUBLIC);
                 if (is_array($methods) && count($methods) > 0) {
                     foreach ($methods as $m) {
                         if (strpos($m->name, 'Action') !== false && $m->name != 'doAction' && $m->name != 'hasAction') {
                             $this->_map[$classname][] = strtolower($moduleName . '.' . str_replace('Controller', '', $cname) . '.' . str_replace('Action', '', $m->name));
                         }
                     }
                 }
             }
         }
     }
 }
Пример #2
0
    $saveFile = APPLICATION_PATH . '/../static/cacheimg/2818/' . $_GET['file'];
    $location = 'http://static.souchela.com/cacheimg/2818/' . $_GET['file'];
}
if ($_GET['type'] == '19812x') {
    $width = 198;
    $height = 120;
    $saveFile = APPLICATION_PATH . '/../static/cacheimg/19812/' . $_GET['file'];
    $location = 'http://static.souchela.com/cacheimg/19812/' . $_GET['file'];
}
if ($_GET['type'] == 'gray19812x') {
    $width = 198;
    $height = 120;
    $saveFile = APPLICATION_PATH . '/../static/cacheimg/gray19812/' . $_GET['file'];
    $location = 'http://static.souchela.com/cacheimg/gray19812/' . $_GET['file'];
}
if (is_file($saveFile)) {
    header('Location:' . $location);
    exit;
}
$thumb = PhpThumbFactory::create($file);
$thumb->adaptiveResize($width, $height);
//创建目录
$path = pathinfo($saveFile);
XF_File::mkdirs($path['dirname']);
//保存图片
if (strpos($_GET['type'], 'gray') === false) {
    $thumb->save($saveFile);
} else {
    $thumb->saveGray($saveFile);
}
header('Location:' . $location);
Пример #3
0
 /**
  * 缓存数据库字段信息
  * @access	private
  * @return	array 字段列表
  */
 private function _makeCacheTableFields()
 {
     $cache_key = md5($this->_db_name . $this->_table_name);
     $cache = XF_Cache_SECache::getInstance();
     if (!is_dir(TEMP_PATH . '/Cache/')) {
         XF_File::mkdirs(TEMP_PATH . '/Cache/');
     }
     $cache->setCacheSaveFile(TEMP_PATH . '/Cache/DatabaseField');
     $content = $cache->read($cache_key);
     if ($content !== XF_CACHE_EMPTY) {
         return $content;
     }
     //缓存字段
     $tmp = $this->getTableSelect()->getFields();
     $cache->setCacheTime(60 * 24 * 30)->add($cache_key, $tmp);
     return $tmp;
 }
Пример #4
0
 /**
  * 写入日志
  * @access public
  * @param string $message 内容
  * @return void
  */
 public static function log($message)
 {
     if (!is_scalar($message) && $message == '') {
         return;
     }
     $file = TEMP_PATH . '/Logs/' . date('Y-m-d') . '.log';
     XF_File::write($file, '[' . date('H:i:s') . '] ' . $message, 'a+');
 }
Пример #5
0
 /**
  * 渲染模板
  * @access public
  * @param string $template_file Action模板文件
  * @param string $cache_sign 缓存标识
  * @param XF_View_Layout_Abstract $layout 
  * @return string
  */
 public function render($template_file = null, $cache_sign = '', XF_View_Layout_Abstract $layout = null)
 {
     $this->getTemplateStartLocation();
     $request = XF_Controller_Request_Http::getInstance();
     $appName = $request->getModule();
     $controllerName = $request->getController();
     $actionName = $request->getAction();
     //如果没有设置模板,则自动获取当前Action名称相关的模板
     if ($template_file == null) {
         $template_file = $this->_template_folder . '/' . $controllerName . '/' . $actionName . '.php';
     }
     if (!is_file($template_file)) {
         throw new XF_View_Exception('Action template not found');
     }
     $content = $this->obGetContents($template_file);
     XF_Controller_Plugin_Manage::getInstance()->postRender($content);
     //是否需要缓存?
     if ($this->_cache_time > 0) {
         $layout_tag = '';
         if ($layout != null) {
             $layout_tag = '<!--Layout:' . get_class($layout) . ',' . $layout->getCacheTime() . ',' . (int) $layout->getCacheType() . '-->';
         }
         $_content = $content . $layout_tag . $this->_makeCacheHeadTitleAndHeadMeta();
         //写入缓存
         if ($this->_cache_instance instanceof XF_Cache_SECache) {
             XF_File::mkdirs(TEMP_PATH . '/Cache');
             $this->_cache_instance->setCacheSaveFile(TEMP_PATH . '/Cache/ActionViewCache');
         }
         $this->_cache_instance->setCacheTime($this->_cache_time);
         $this->_cache_instance->add($cache_sign, $_content);
     }
     //是否启用布局
     if ($layout != null) {
         $layout->assign('$layoutContent', $content);
         $content = $layout->render();
     }
     return $content;
 }
Пример #6
0
 /**
  * 将文件上传到指定的位置
  * @param array $options 参数数组 <br/>
  * inputName 上传控件名称<br/>
  * maxSize 最大允许上传大小[单位:kb]<br/>
  * folder 保存的目录, 从项目根目录开始<br/>
  * extension  允许上传的文件类型
  */
 public static function upload(array $options)
 {
     //HTML上传控件名称
     $fileName = isset($options['inputName']) ? $options['inputName'] : 'upload_input';
     //允许上传大小
     $maxlimit = isset($options['maxSize']) ? $options['maxSize'] * 1024 * 1024 : 8 * 1024 * 1024;
     //8M
     //保存目录
     $folder = isset($options['folder']) ? $options['folder'] : null;
     //保存的文件名
     $saveFileName = isset($options['saveFileName']) ? $options['saveFileName'] : null;
     //允许上传的文件类型
     $extensionArray = isset($options['extension']) ? $options['extension'] : array('jpg', 'jpeg', 'gif', 'png', 'bmp');
     $return['status'] = 'error';
     if (isset($_FILES[$fileName]) && is_uploaded_file($_FILES[$fileName]['tmp_name'])) {
         $file = $_FILES[$fileName];
         $name = $file['name'];
         $temp_name = $file['tmp_name'];
         $size = $file['size'];
         //限制文件上传大小
         if ($size > $maxlimit) {
             $return['error_type'] = 'size';
             $return['error_message'] = 'size: ' . ceil($size / 100000) . '/' . ceil($maxlimit / 100000);
         } else {
             $extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
             if (in_array(strtolower($extension), $extensionArray)) {
                 if ($extension == 'jpeg') {
                     $extension = 'jpg';
                 }
                 $newFileName = '';
                 if ($saveFileName == null) {
                     $newFileName = md5(time() . '_' . mt_rand(1000, 9999)) . '.' . $extension;
                 } else {
                     $newFileName = $saveFileName . '.' . $extension;
                 }
                 $md5 = md5_file($temp_name);
                 //创建将要保存的目录
                 XF_File::mkdirs($folder);
                 //上传图片
                 if (move_uploaded_file($temp_name, $folder . '/' . $newFileName)) {
                     $path = str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath($folder)) . '/';
                     $folder = realpath($folder . '/');
                     $return['status'] = 'success';
                     $return['fileDir'] = realpath($folder . '/');
                     $return['folder'] = str_replace('\\', '/', $path);
                     $return['filePath'] = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('\\', '/', $path);
                     $return['file'] = 'http://' . $_SERVER['HTTP_HOST'] . str_replace('\\', '/', $path) . $newFileName;
                     $return['file2'] = realpath(realpath($folder) . '/' . $newFileName);
                     $return['fileName'] = $newFileName;
                     $return['fileExtension'] = $extension;
                     $return['fileSize'] = $size;
                     $return['md5'] = $md5;
                     if (in_array(strtolower($extension), $extensionArray)) {
                         $r = getimagesize($folder . '/' . $newFileName);
                         $return['fileWidth'] = $r[0];
                         $return['fileHeight'] = $r[1];
                     }
                 }
             } else {
                 $return['error_type'] = 'type';
                 $return['fileExtension'] = $extension;
                 $return['error_message'] = '文件格式只能是:' . implode(',', $extensionArray);
             }
         }
     } else {
         $return['error_message'] = 'To upload control name does not exist.';
     }
     return $return;
 }
Пример #7
0
 /**
  * 渲染布局模板文件
  * @access public
  * @return string
  */
 public function render()
 {
     $content = isset($this->_data['$layoutContent']) ? $this->_data['$layoutContent'] : '';
     //布局模板起始路径
     $layoutTemplatePath = APPLICATION_PATH . '/layouts/scripts/';
     if (!is_file($layoutTemplatePath . $this->_tpl)) {
         return $content;
     }
     //检测缓存
     if ($this->_cache_time > 0) {
         $request = XF_Controller_Request_Http::getInstance();
         $file = TEMP_PATH . '/Cache/LayoutScripts/';
         $pathinfo = pathinfo($this->_tpl);
         //检测布局缓存类型,定位正确的路径
         if ($this->_cache_is_private) {
             $file .= 'Private/' . $request->getModule() . '/' . $request->getController() . '/' . $request->getAction() . '/' . $pathinfo['basename'];
         } else {
             $file .= 'Public/' . $pathinfo['basename'];
         }
         XF_File::mkdirs(pathinfo($file, PATHINFO_DIRNAME));
         if (is_file($file)) {
             //布局缓存是否过期
             if (time() > filemtime($file) + $this->_cache_time * 60) {
                 //缓存失效时执行用户的初始化操作init()
                 $this->_init();
                 XF_File::del($file);
                 $this->_flag = false;
                 $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
                 XF_File::write($file, $content);
             }
             $this->_flag = true;
             return $this->_getObContent($file);
         } else {
             $this->_init();
             $this->_flag = false;
             $content = $this->_getObContent($layoutTemplatePath . $this->_tpl);
             XF_File::write($file, $content);
             $this->_flag = true;
             return $this->_getObContent($file);
         }
     } else {
         //不采用缓存时获取最终输出的HTML内容
         $this->_init();
         $this->_flag = true;
         return $this->_getObContent($layoutTemplatePath . $this->_tpl);
     }
     return $content;
 }