Example #1
0
 public static function make($inputData = array())
 {
     $loadData = self::get();
     // print_r($loadData);die();
     $url = $loadData['data']['file'];
     $sourcePath = '';
     if (!is_dir(ROOT_PATH . 'uploads/tmp/update/')) {
         Dir::create(ROOT_PATH . 'uploads/tmp/update/');
     }
     File::downloadModule($url, 'uploads/tmp/update/', 'yes');
     if (preg_match('/github\\.com/i', $url)) {
         $sourcePath = ROOT_PATH . 'uploads/tmp/update/noblessecms-master/';
     } else {
         $sourcePath = ROOT_PATH . 'uploads/tmp/update/noblessecms/';
     }
     $descPath = ROOT_PATH . 'uploads/tmp/test/';
     if (is_dir($sourcePath)) {
         unlink($sourcePath . '.htaccess');
         unlink($sourcePath . 'config.php');
         unlink($sourcePath . 'autoload.php');
         unlink($sourcePath . 'routes.php');
         unlink($sourcePath . 'README.md');
         if (file_exists($sourcePath . 'install/update.sql')) {
             Database::import($sourcePath . 'install/db.sql');
             Database::import($sourcePath . 'install/update.sql');
         }
         Dir::remove($sourcePath . 'install');
         Dir::remove($sourcePath . 'contents');
         Dir::remove($sourcePath . 'application/caches');
     }
     // File::fullCopy($sourcePath,ROOT_PATH.'uploads/tmp/test/');
     File::fullCopy($sourcePath, ROOT_PATH);
     Dir::remove($sourcePath);
     // Dir::remove($descPath);
 }
Example #2
0
 public function __construct()
 {
     //smarty配置
     if (!is_null(self::$smarty)) {
         return;
     }
     $smarty = new Smarty();
     $smarty->template_dir = ROOT_PATH . APP_PATH . '/' . MODULE . APP_TPL_PATH . '/' . CONTROLLER . '/';
     //模板目录
     $smarty->compile_dir = APP_TEMP_PATH . '/Compile/' . MODULE . '/';
     //模板编译目录
     $smarty->cache_dir = APP_TEMP_PATH . '/Cache/' . MODULE . '/';
     //模板缓存目录
     if (!file_exists($smarty->cache_dir)) {
         Dir::create($smarty->cache_dir);
     }
     $smarty->left_delimiter = C('LEFT_DELIMITER');
     //左边界符号
     $smarty->right_delimiter = C('RIGHT_DELIMITER');
     //右边界符
     $smarty->caching = C('CACHE_ON');
     //缓存开启
     $smarty->cache_lifetime = C('CACHE_TIME');
     //缓存时间
     // $smarty->allow_php_templates = true;
     self::$smarty = $smarty;
 }
Example #3
0
 public function run()
 {
     $this->content = file_get_contents($this->view->tplFile);
     //获得模板内容
     $this->loadParseTags();
     //加载标签库  及解析标签
     $this->replaceGlobalFunc();
     //解析全局函数{U:'index'}
     $this->compile();
     //解析全局内容
     $this->parseTokey();
     //解析POST令牌Token
     $this->replaceConst();
     //将所有常量替换   如把__APP__进行替换
     $this->replaceLiteral();
     //将Literal内容替换
     $this->content = '<?php if(!defined("HDPHP_PATH"))exit;C("SHOW_NOTICE",FALSE);?>' . $this->content;
     if (!is_dir(APP_COMPILE_PATH)) {
         Dir::create(APP_COMPILE_PATH);
         copy(HDPHP_TPL_PATH . 'index.html', APP_COMPILE_PATH . 'index.html');
     }
     //创建编译目录
     is_dir(dirname($this->view->compileFile)) or Dir::create(dirname($this->view->compileFile));
     file_put_contents($this->view->compileFile, $this->content);
     //创建安全文件
     $safeFile = dirname($this->view->compileFile) . "/index.html";
     is_file($safeFile) or Dir::safeFile(dirname($safeFile));
 }
Example #4
0
 public function dir($dir)
 {
     $this->dir = $dir;
     if (!Dir::create($this->dir) || !is_writable($this->dir)) {
         throw new Exception("缓存目录创建失败或目录不可写");
     }
     return $this;
 }
Example #5
0
 /**
  * 设置SESSION存储路径
  * @param type $path
  */
 static function setSavePath($path)
 {
     self::start();
     if (!is_dir($path)) {
         Dir::create($path);
     }
     session_save_path($path);
 }
Example #6
0
 private function setSavePath($path)
 {
     $path = $path ? $path : C('UPLOAD_PATH') . '/content/' . date('Y/m/d');
     if (!is_dir($path)) {
         Dir::create($path);
     }
     return trim($path, '/');
 }
Example #7
0
 public static function save($cacheName, $text)
 {
     $cacheName = Sanitize::variable($cacheName, ".-");
     $filename = "/" . ltrim($cacheName, "/") . '.html';
     // Make sure the directory exists
     Dir::create(APP_PATH . self::$cacheDirectory . dirname($filename));
     // Write the new file
     return File::write(APP_PATH . self::$cacheDirectory . $filename, $text);
 }
Example #8
0
 /**
  * 储存内容
  * @param string $fileName 文件名
  * @param string $content 数据
  */
 public function save($fileName, $content)
 {
     $dir = dirname($fileName);
     Dir::create($dir);
     if (file_put_contents($fileName, $content) === false) {
         halt("创建文件{$fileName}失败");
     }
     $this->contents[$fileName] = $content;
     return true;
 }
Example #9
0
 public static function create($filePath = '', $fileData = '', $writeMode = 'w')
 {
     $path = dirname($filePath);
     if (!is_dir($path)) {
         Dir::create($path);
     }
     $fp = fopen($filePath, $writeMode);
     fwrite($fp, $fileData);
     fclose($fp);
 }
Example #10
0
 public function sendMessage($sdata, $data)
 {
     $res = $this->add($sdata);
     //添加到发件人表
     if ($res) {
         $data['mid'] = $res;
         $fields = "";
         $values = "";
         foreach ($data as $k => $v) {
             $fields .= '`' . $this->_safe_str($k) . '`,';
             $values .= "'" . $this->_safe_str($v) . "',";
         }
         $fields = trim($fields, ',');
         $values = trim($values, ',');
         $sql = "INSERT INTO " . C('DB_PREFIX') . $this->rectable . " (" . $fields . ") VALUES (" . $values . ")";
         $result = $this->exe($sql);
         if ($result) {
             $path = APP_CACHE_PATH . '/DataBase_id';
             $Dir = new Dir();
             if (!is_dir($path)) {
                 $file = $Dir->create($path) ? $path . '/' . $this->table . '.txt' : NULL;
                 $recfile = $Dir->create($path) ? $path . '/' . C('DB_PREFIX') . $this->rectable . '.txt' : NULL;
             } else {
                 $file = $path . '/' . $this->table . '.txt';
                 $recfile = $path . '/' . C('DB_PREFIX') . $this->rectable . '.txt';
             }
             if (!is_null($file) || !is_null($recfile)) {
                 if (file_put_contents($file, $res) || file_put_contents($recfile, $result)) {
                     return true;
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         }
     }
 }
Example #11
0
 /**
  * 根据模板文件生成编译文件
  *
  * @param $file
  *
  * @return string
  */
 public function compile($file)
 {
     $file = $this->template($file);
     $compileFile = ROOT_PATH . '/storage/view/' . preg_replace('/[^\\w]/', '_', $file) . '_' . substr(md5($file), 0, 5) . '.php';
     $status = c('app.debug') || !is_file($compileFile) || filemtime($file) > filemtime($compileFile);
     if ($status) {
         Dir::create(dirname($compileFile));
         //执行文件编译
         $compile = new Compile($this);
         $content = $compile->run($file);
         file_put_contents($compileFile, $content);
     }
     return $compileFile;
 }
Example #12
0
 public static function write($filepath, $text, $overwrite = true)
 {
     // Check if the file already exists, and react accordingly
     if (self::exists($filepath) && $overwrite == false) {
         return false;
     }
     // Make sure the directories leading to the file exist
     $pos = strrpos($filepath, "/");
     $fileDirectory = substr($filepath, 0, $pos);
     if (!is_dir($fileDirectory)) {
         Dir::create($fileDirectory);
     }
     // Write the content to the file
     return (bool) file_put_contents($filepath, $text);
 }
Example #13
0
 public function run()
 {
     $this->content = file_get_contents($this->view->tplFile); //获得模板内容
     $this->loadParseTags(); //加载标签库  及解析标签
     $this->replaceGlobalFunc(); //解析全局函数{U:'index'}
     $this->compile(); //解析全局内容
     $this->parseTokey(); //解析POST令牌Token
     $this->replaceConst(); //将所有常量替换   如把__APP__进行替换
     $this->content = '<?php if(!defined("HDPHP_PATH"))exit;C("SHOW_WARNING",false);?>' . $this->content;
     if (!is_dir(COMPILE_PATH)) {
         Dir::create(COMPILE_PATH);
         copy(HDPHP_TPL_PATH . 'index.html', COMPILE_PATH . 'index.html');
     }
     file_put_contents($this->view->compileFile, $this->content);
 }
Example #14
0
 public function addLever($data)
 {
     $res = $this->add($data);
     if ($res) {
         $path = APP_CACHE_PATH . '/DataBase_id';
         $dir = new Dir();
         if (!is_dir($path)) {
             $dir->create($path);
         }
         if (file_put_contents($path . '/' . $this->table . '.txt', $res)) {
             return true;
         } else {
             return false;
         }
     }
 }
Example #15
0
 public function addCate($data)
 {
     $res = $this->add($data);
     if ($res) {
         $path = APP_CACHE_PATH . '/DataBase_id';
         if (!is_dir($path)) {
             Dir::create($path);
         }
         $file = $path . '/' . $this->table . '.txt';
         if (file_put_contents($file, $res)) {
             return true;
         } else {
             return false;
         }
     }
 }
Example #16
0
 public static function get($inputData = array())
 {
     $path = $inputData['path'];
     $postid = $inputData['postid'];
     $result = '';
     if (!is_dir(ROOT_PATH . $path . $postid)) {
         Dir::create(ROOT_PATH . $path . $postid);
     }
     $fileName = $postid . '_' . $inputData['width'] . 'x' . $inputData['height'] . '.jpg';
     $filePath = $path . $postid . '/' . $fileName;
     if (!file_exists(ROOT_PATH . $filePath)) {
         $result = self::make($inputData);
     } else {
         $result = $filePath;
     }
     return $result;
 }
Example #17
0
    /**
     * 写入日志内容
     * @access public
     * @param string $message       日志内容
     * @param int $type             处理方式
     * @param string $destination   日志文件
     * @param null $extraHeaders
     * @return void
     */
    static public function write($message, $type = 3, $destination = NULL, $extraHeaders = NULL)
    {
        if (DEBUG || !C("LOG_SAVE"))
            return;
        Dir::create(LOG_PATH);
        if (is_null($destination)) {
            $destination = LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . ".log";
        }
        if ($type == 3) {
            if (is_file($destination) && filesize($destination) > C("LOG_SIZE")) {
                //日志文件超过大小时的处理
                $num = count(glob(LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . "-*")); //当日共有几个文件
                rename($destination, substr($destination, 0, -4) . "-" . $num . ".log");
            }
        }
        error_log($message."\n", $type, $destination, $extraHeaders = null);

    }
Example #18
0
 /**
  * Template factory
  *
  *  <code>
  *      $template = Template::factory('templates_path');
  *  </code>
  *
  * @param string|Fenom\ProviderInterface $source path to templates or custom provider
  * @param string $compile_dir path to compiled files
  * @param int|array $options
  * @throws InvalidArgumentException
  * @return Fenom
  */
 public static function factory($source, $compile_dir = '/tmp', $options = 0)
 {
     // Create fenom cache directory if its not exists
     !Dir::exists(CACHE_PATH . '/fenom/') and Dir::create(CACHE_PATH . '/fenom/');
     // Create Unique Cache ID for Theme
     $theme_config_file = THEMES_PATH . '/' . Config::get('system.theme') . '/' . Config::get('system.theme') . '.yml';
     $theme_cache_id = md5('theme' . ROOT_DIR . $theme_config_file . filemtime($theme_config_file));
     // Set current them options
     if (Cache::driver()->contains($theme_cache_id)) {
         Config::set('theme', Cache::driver()->fetch($theme_cache_id));
     } else {
         $theme_config = Yaml::parseFile($theme_config_file);
         Config::set('theme', $theme_config);
         Cache::driver()->save($theme_cache_id, $theme_config);
     }
     $compile_dir = CACHE_PATH . '/fenom/';
     $options = Config::get('system.fenom');
     $fenom = parent::factory($source, $compile_dir, $options);
     $fenom->assign('config', Config::getConfig());
     return $fenom;
 }
Example #19
0
 public function addUser($data)
 {
     $res = $this->add($data);
     if ($res) {
         $path = APP_CACHE_PATH . '/DataBase_id';
         $Dir = new Dir();
         if (!is_dir($path)) {
             $file = $Dir->create($path) ? $path . '/' . $this->table . '.txt' : NULL;
         } else {
             $file = $path . '/' . $this->table . '.txt';
         }
         if (!is_null($file)) {
             if (file_put_contents($file, $res)) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
 }
Example #20
0
 public static function get($queryStr = '', $timeLive = 15, $addPath = '')
 {
     // die(self::$enable);
     if (self::$enable == 'no' || !isset($queryStr[1])) {
         return false;
     }
     if (isset($addPath[1])) {
         $fullPath = CACHES_PATH . 'dbcache/' . $addPath;
         if (!is_dir($fullPath)) {
             Dir::create($fullPath);
         }
     }
     $queryStr = md5($queryStr);
     // Cache::setPath(CACHES_PATH.'dbcache/');
     if (!($loadData = Cache::loadKey('dbcache/' . $addPath . '/' . $queryStr, $timeLive))) {
         return false;
     }
     // Cache::setPath(CACHES_PATH);
     // self::$enable='no';
     // $loadData=json_decode($loadData,true);
     $loadData = unserialize($loadData);
     // $loadData=unserialize(base64_decode($loadData));
     return $loadData;
 }
Example #21
0
 public function run()
 {
     $this->content = file_get_contents($this->view->tplFile);
     $this->loadParseTags();
     $this->replaceGlobalFunc();
     $this->compile();
     $this->parseTokey();
     $this->replaceConst();
     $this->content = '<?php if(!defined("HDPHP_PATH"))exit;C("SHOW_WARNING",false);?>' . $this->content;
     if (!is_dir(COMPILE_PATH)) {
         Dir::create(COMPILE_PATH);
         copy(HDPHP_TPL_PATH . 'index.html', COMPILE_PATH . 'index.html');
     }
     file_put_contents($this->view->compileFile, $this->content);
 }
    public function add()
    {
        if (IS_POST) {
            $data = $_POST;
            $data['has_adminlist'] = isset($_POST['has_adminlist']) ? 1 : 0;
            //有后台
            $data['has_outurl'] = isset($_POST['has_outurl']) ? 1 : 0;
            //前台访问
            $data['config'] = isset($_POST['config']) ? 1 : 0;
            //有配置文件
            //-------------------检查必要信息
            $this->db->validate = array(array('name', 'nonull', '插件标识不能为空!', 2, 3), array('name', 'regexp:/^[a-zA-Z][a-zA-Z0-9_]+$/i', '插件标识只支持英文、数字', 2, 3), array('name', 'addonUniqueCheck', '该插件已经存在!', 2, 3), array('title', 'nonull', '插件名称不能为空!', 2, 3), array('version', 'nonull', '插件版本不能为空!', 2, 3), array('author', 'nonull', '插件作者不能为空!', 2, 3), array('description', 'nonull', '插件描述不能为空!', 2, 3));
            if (!$this->db->validate($data)) {
                $this->error($this->db->error);
            }
            $data['name'] = ucfirst($data['name']);
            $addonDir = APP_ADDON_PATH . $data['name'] . '/';
            //插件目录
            //验证安装目录
            if (!is_writable(APP_ADDON_PATH)) {
                $this->error(APP_ADDON_PATH . ' 不可写');
            }
            is_dir($addonDir) or dir::create($addonDir);
            //创建插件目录
            //-------------------创建配置文件
            if ($data['config']) {
                copy(HDPHP_PATH . 'Lib/Tpl/configAddon.php', $addonDir . 'config.php');
            }
            //-----------------控制器
            if ($data['has_adminlist'] || $data['has_outurl']) {
                //创建控制器目录
                is_dir($addonDir . 'Controller') or Dir::create($addonDir . 'Controller');
            }
            if ($data['has_adminlist']) {
                $controller = <<<str
<?php
/**
 * {$data['name']} 插件
 * @author 后盾向军 <*****@*****.**>
 */

class AdminController extends AddonController {

    public function index() {
        \$this->display();
    }
}
str;
                file_put_contents($addonDir . 'Controller/AdminController.class.php', $controller);
            }
            //创建前台访问控制器
            if ($data['has_outurl']) {
                $controller = <<<str
<?php
/**
 * {$data['name']} 插件
 * @author 后盾向军 <*****@*****.**>
 */

class IndexController extends AddonController {

    public function index() {
        \$this->display();
    }
}
str;
                file_put_contents($addonDir . 'Controller/IndexController.class.php', $controller);
            }
            $addonData = <<<str
<?php
/**
 * {$data['name']} 插件
 * @author 后盾向军 <*****@*****.**>
 */
class {$data['name']}Addon extends Addon
{

    //插件信息
    public \$info = array(
        'name' => '{$data['name']}',
        'title' => '{$data['title']}',
        'description' => '{$data['description']}',
        'status' => 1,
        'author' => '{$data['author']}',
        'version' => '{$data['version']}',
        'has_adminlist' => {$data['has_adminlist']},
    );

    //安装
    public function install()
    {
        return true;
    }

    //卸载
    public function uninstall()
    {
        return true;
    }
str;
            if (isset($data['hooks'])) {
                foreach ($data['hooks'] as $hook) {
                    $addonData .= "\n    //实现的{$hook}钩子方法\n    public function {$hook}(\$param){\n    }\n";
                }
            }
            $addonData .= '}';
            file_put_contents($addonDir . $data['name'] . 'Addon.class.php', $addonData);
            //创建View视图文件
            if ($data['has_adminlist']) {
                Dir::create($addonDir . 'View/Admin');
                copy(MODULE_PATH . 'Data/View/addonAdmin.php', $addonDir . 'View/Admin/index.php');
            }
            if ($data['has_outurl']) {
                Dir::create($addonDir . 'View/Index');
                copy(MODULE_PATH . 'Data/View/addonIndex.php', $addonDir . 'View/Index/index.php');
            }
            $this->display('success.php');
        } else {
            $this->assign('hooks', K('Hooks')->all());
            $this->display();
        }
    }
Example #23
0
 /**
  * 验证目录
  * @param string $path 目录
  * @return bool
  */
 private function checkDir($path)
 {
     return Dir::create($path) && is_writeable($path) ? true : false;
 }
 /**
  * Backup admin
  */
 public static function main()
 {
     $backups_path = ROOT . DS . 'backups';
     // Create backup
     // -------------------------------------
     if (Request::post('create_backup')) {
         if (Security::check(Request::post('csrf'))) {
             @set_time_limit(0);
             @ini_set("memory_limit", "512M");
             $zip = Zip::factory();
             // Add storage folder
             $zip->readDir(STORAGE . DS, false);
             // Add public folder
             $zip->readDir(ROOT . DS . 'public' . DS, false);
             // Add plugins folder
             $zip->readDir(PLUGINS . DS, false, null, array(PLUGINS . DS . 'box'));
             if ($zip->archive($backups_path . DS . Date::format(time(), "Y-m-d-H-i-s") . '.zip')) {
                 Notification::set('success', __('Backup was created', 'backup'));
             } else {
                 Notification::set('error', __('Backup was not created', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Delete backup
     // -------------------------------------
     if (Request::get('id') == 'backup' && Request::get('delete_file')) {
         if (Security::check(Request::get('token'))) {
             if (File::delete($backups_path . DS . Request::get('delete_file'))) {
                 Notification::set('success', __('Backup was deleted', 'backup'));
             } else {
                 Notification::set('error', __('Backup was not deleted', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Download backup
     // -------------------------------------
     if (Request::get('download')) {
         if (Security::check(Request::get('token'))) {
             File::download($backups_path . DS . Request::get('download'));
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Restore backup
     // -------------------------------------
     if (Request::get('restore')) {
         if (Security::check(Request::get('token'))) {
             $tmp_dir = ROOT . DS . 'tmp' . DS . uniqid('backup_');
             if (Dir::create($tmp_dir)) {
                 $file_locations = Zip::factory()->extract($backups_path . DS . Request::get('restore'), $tmp_dir);
                 if (!empty($file_locations)) {
                     Dir::copy($tmp_dir, ROOT . DS);
                     Notification::set('success', __('Backup was restored', 'backup'));
                 } else {
                     Notification::set('error', __('Unzip error', 'backup'));
                 }
             } else {
                 Notification::set('error', __('Backup was not restored', 'backup'));
             }
             Request::redirect(Option::get('siteurl') . '/admin/index.php?id=backup');
         } else {
             die('Request was denied because it contained an invalid security token. Please refresh the page and try again.');
         }
     }
     // Display view
     View::factory('box/backup/views/backend/index')->assign('backups_list', File::scan($backups_path, '.zip'))->display();
 }
Example #25
0
 /**
  * Get Cache Driver
  *
  * @access public
  * @return object
  */
 public static function getCacheDriver()
 {
     $driver_name = Config::get('system.cache.driver');
     if (!$driver_name || $driver_name == 'auto') {
         if (extension_loaded('apc')) {
             $driver_name = 'apc';
         } elseif (extension_loaded('wincache')) {
             $driver_name = 'wincache';
         } elseif (extension_loaded('xcache')) {
             $driver_name = 'xcache';
         }
     } else {
         $driver_name = 'file';
     }
     switch ($driver_name) {
         case 'apc':
             $driver = new \Doctrine\Common\Cache\ApcCache();
             break;
         case 'wincache':
             $driver = new \Doctrine\Common\Cache\WinCacheCache();
             break;
         case 'xcache':
             $driver = new \Doctrine\Common\Cache\XcacheCache();
             break;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect(Config::get('system.cache.memcache.server', 'localhost'), Config::get('system.cache.memcache.port', 11211));
             $driver = new \Doctrine\Common\Cache\MemcacheCache();
             $driver->setMemcache($memcache);
             break;
         case 'redis':
             $redis = new \Redis();
             $redis->connect(Config::get('system.cache.redis.server', 'localhost'), Config::get('system.cache.redis.port', 6379));
             $driver = new \Doctrine\Common\Cache\RedisCache();
             $driver->setRedis($redis);
             break;
         default:
             // Create doctrine cache directory if its not exists
             !Dir::exists($cache_directory = CACHE_PATH . '/doctrine/') and Dir::create($cache_directory);
             $driver = new \Doctrine\Common\Cache\FilesystemCache($cache_directory);
             break;
     }
     return $driver;
 }
Example #26
0
 /**
  * Download $remote_path directory recursive as $local_path.
  * 
  * @throws
  * @param string $remote_path
  * @param string $local_path
  * @return vector<string>
  */
 public function getDir($remote_path, $local_path)
 {
     $entries = $this->ls($remote_path);
     Dir::create($local_path, 0, true);
     foreach ($entries as $path => $info) {
         if ($info['type'] === 'f') {
             $this->get($path, $local_path . '/' . $info['name']);
         } else {
             if ($info['type'] === 'l') {
                 if (FSEntry::isLink($local_path . '/' . $info['name'], false)) {
                     File::remove($local_path . '/' . $info['name']);
                 }
                 print "link: " . $info['link'] . " - " . $local_path . '/' . $info['name'] . "\n";
                 FSEntry::link($info['link'], $local_path . '/' . $info['name'], false);
             } else {
                 if ($info['type'] === 'd') {
                     $this->getDir($path, $local_path . '/' . $info['name']);
                 }
             }
         }
     }
 }
function dir_create($dir)
{
    return Dir::create($dir);
}
Example #28
0
 /**
  * Writes a string to a file.
  *
  * @param  string  $filename   The path of the file.
  * @param  string  $content    The content that should be written.
  * @param  boolean $createFile Should the file be created if it doesn't exists?
  * @param  boolean $append     Should the content be appended if the file already exists?
  * @param  integer $chmod      Mode that should be applied on the file.
  * @return boolean
  */
 public static function setContent($filename, $content, $create_file = true, $append = false, $chmod = 0666)
 {
     // Redefine vars
     $filename = (string) $filename;
     $content = (string) $content;
     $create_file = (bool) $create_file;
     $append = (bool) $append;
     // File may not be created, but it doesn't exist either
     if (!$create_file && File::exists($filename)) {
         throw new RuntimeException(vsprintf("%s(): The file '{$filename}' doesn't exist", array(__METHOD__)));
     }
     // Create directory recursively if needed
     Dir::create(dirname($filename));
     // Create file & open for writing
     $handler = $append ? @fopen($filename, 'a') : @fopen($filename, 'w');
     // Something went wrong
     if ($handler === false) {
         throw new RuntimeException(vsprintf("%s(): The file '{$filename}' could not be created. Check if PHP has enough permissions.", array(__METHOD__)));
     }
     // Store error reporting level
     $level = error_reporting();
     // Disable errors
     error_reporting(0);
     // Write to file
     $write = fwrite($handler, $content);
     // Validate write
     if ($write === false) {
         throw new RuntimeException(vsprintf("%s(): The file '{$filename}' could not be created. Check if PHP has enough permissions.", array(__METHOD__)));
     }
     // Close the file
     fclose($handler);
     // Chmod file
     chmod($filename, $chmod);
     // Restore error reporting level
     error_reporting($level);
     // Return
     return true;
 }
Example #29
0
 public function save($file, $quality = 90)
 {
     // Allow Transparency
     imagesavealpha($this->resource, true);
     // If the save file is valid
     if (!IsSanitized::filepath($file)) {
         Alert::error("Image Path", "The image path is invalid.", 7);
         return false;
     }
     $saveInfo = pathinfo($file);
     if (!isset($saveInfo['basename']) or !isset($saveInfo['dirname']) or !isset($saveInfo['extension'])) {
         Alert::error("Image Path", "The image path is not functioning properly.", 6);
         return false;
     }
     // Make sure the directory exists
     if (!Dir::create($saveInfo['dirname'])) {
         Alert::error("Image Directory", "The image directory cannot be created. Please check permissions.", 4);
         return false;
     }
     // Save the file
     switch ($saveInfo['extension']) {
         case "jpg":
         case "jpeg":
             return imagejpeg($this->resource, $file, $quality);
         case "png":
             return imagepng($this->resource, $file);
         case "gif":
             return imagegif($this->resource, $file);
     }
     return false;
 }
Example #30
0
define('VIEWS', ROOT . '/views');
// Morfy paths
define('ROOTBASE', rtrim(str_replace(array($backend), array(''), dirname(__FILE__)), '\\/'));
define('LIBRARIES', ROOTBASE . '/libraries');
define('STORAGE', ROOTBASE . '/storage');
define('PAGES', ROOTBASE . '/storage/pages');
define('BLOCKS', ROOTBASE . '/storage/blocks');
define('SITE', ROOTBASE . '/config/site.yml');
define('THEMES', ROOTBASE . '/themes');
define('PLUGINS', ROOTBASE . '/plugins');
// new folders
define('BACKUPS', ROOTBASE . '/backups');
define('PUBLICFOLDER', ROOTBASE . '/public');
define('MEDIA', PUBLICFOLDER . '/media');
define('UPLOADS', PUBLICFOLDER . '/uploads');
// Morfy panel class/routes
include_once API . '/Morfy.panel.php';
include_once API . '/Morfy.routes.php';
// check if exist this folders
if (!Dir::exists(MEDIA)) {
    Dir::create(MEDIA);
}
if (!Dir::exists(UPLOADS)) {
    Dir::create(UPLOADS);
}
if (!Dir::exists(BACKUPS)) {
    Dir::create(BACKUPS);
}
?>