Пример #1
0
 /**
  * Constructor
  * Makes sure the cache directory is set
  *
  * @return object
  */
 public function __construct()
 {
     $this->cacheDir = $this->_zula->getDir('tmp') . '/cache';
     if (!is_dir($this->cacheDir)) {
         zula_make_dir($this->cacheDir);
     }
     if (!zula_is_writable($this->cacheDir)) {
         throw new Cache_Exception($this->cacheDir . ' is not writable');
     }
 }
Пример #2
0
 /**
  * Compress all the needed JS files for TinyMCE into one,
  * and will return it back for TinyMCE to execute.
  *
  * The results of this are cached if all data matches up.
  *
  * @return string
  */
 public function gzipSection()
 {
     $jsFile = 'tinymce-' . zula_hash(implode('|', $this->_input->getAll('get')), null, 'md5') . '.js';
     // Build path and check if the cached version exists
     $jsFilePath = $this->_zula->getDir('tmp') . '/js/' . $jsFile;
     if (!file_exists($jsFilePath)) {
         if (!is_dir(dirname($jsFilePath))) {
             zula_make_dir(dirname($jsFilePath));
         }
         try {
             $tinyMcePath = $this->_zula->getDir('js') . '/tinymce';
             $tinyMceLang = $this->_input->get('languages');
             $theme = $this->_input->get('themes');
             // Array of all files that need to be merged together
             $neededFiles = array('/langs/' . $tinyMceLang . '.js', '/themes/' . $theme . '/editor_template.js', '/themes/' . $theme . '/langs/' . $tinyMceLang . '.js');
             // Plugins
             foreach (explode(',', $this->_input->get('plugins')) as $plugin) {
                 $neededFiles[] = '/plugins/' . $plugin . '/editor_plugin.js';
                 $neededFiles[] = '/plugins/' . $plugin . '/langs/' . $tinyMceLang . '.js';
             }
             $content = '';
             foreach ($neededFiles as $file) {
                 $path = $tinyMcePath . $file;
                 if (file_exists($path)) {
                     $content .= file_get_contents($path);
                 }
             }
             if ($this->_input->get('core') == true) {
                 $content = file_get_contents($tinyMcePath . '/tiny_mce.js') . ' tinyMCE_GZ.start(); ' . $content . ' tinyMCE_GZ.end();';
             }
             // Store the file so it can be used later on
             file_put_contents($jsFilePath, $content);
         } catch (Input_KeyNoExist $e) {
             trigger_error('compressor requires languags, themes, plugins and core input values', E_USER_ERROR);
         }
     }
     zula_readfile($jsFilePath, 'text/javascript');
     return false;
 }
Пример #3
0
 /**
  * Constructor
  * Calls the parent constructor to register the methods
  *
  * Also gathers the version file to get latest versions
  *
  * @return object
  */
 public function __construct()
 {
     parent::__construct($this);
     $verFile = $this->_zula->getDir('tmp') . '/sysinfo/versions';
     if (file_exists($verFile) && is_readable($verFile) && filemtime($verFile) + 60 * 60 * 8 > time()) {
         $this->versions = @unserialize(file_get_contents($verFile));
     } else {
         // Attempt to re-read the versions
         if (ini_get('allow_url_fopen')) {
             $stream = stream_context_create(array('http' => array('method' => 'GET', 'header' => 'X-TangoCMS-Version: ' . _PROJECT_VERSION . "\r\n" . 'X-TangoCMS-USI: ' . zula_hash($_SERVER['HTTP_HOST']) . "\r\n", 'timeout' => 6)));
             foreach (array('stable', 'unstable') as $type) {
                 $tmpVer = @file_get_contents('http://releases.tangocms.org/latest/' . $type, false, $stream);
                 if (isset($http_response_header[0]) && strpos($http_response_header[0], '200') !== false) {
                     $this->versions[$type] = trim($tmpVer);
                 }
             }
             if (zula_make_dir($this->_zula->getDir('tmp') . '/sysinfo')) {
                 file_put_contents($verFile, serialize($this->versions));
             }
         } else {
             $this->_log->message('Sysinfo unable to get latest TangoCMS versions, allow_url_fopen disabled', Log::L_NOTICE);
         }
     }
 }
Пример #4
0
 /**
  * Makes the correct directory for the files to be uploaded
  * to, a category can be provided as a token to replace.
  *
  * @param string $category
  * @return string|bool
  */
 protected function makeDirectory($category = null)
 {
     $uploadDir = str_replace('{CATEGORY}', $category, $this->uploader->uploadDir);
     if ($this->uploader->subDir === true) {
         if (!$this->uploader->subDirName) {
             $this->uploader->subDirectoryName(pathinfo(zula_make_unique_dir($uploadDir), PATHINFO_BASENAME));
         }
         $uploadDir .= '/' . $this->uploader->subDirName;
     }
     return zula_make_dir($uploadDir) && is_writable($uploadDir) ? $uploadDir : false;
 }
Пример #5
0
 /**
  * Updates the path to a named directory that can be used. If the path
  * does not exist, it shall attemp to create the directory (only if the
  * 3rd argument is set to bool true)
  *
  * @param string $name
  * @param string $dir
  * @param bool $createDir
  * @return object
  */
 public function setDir($name, $dir, $createDir = false)
 {
     if ($createDir && zula_make_dir($dir) === false) {
         throw new Zula_Exception('failed to create directory "' . $dir . '"');
     }
     $this->directories[$name] = $dir;
     unset($this->htmlDirs[$name]);
     return $this;
 }
Пример #6
0
/**
 * Makes a directory name that is unique in the specified directory, by
 * default this directory will be created.
 *
 * bool false will be returned if the directory can not be created
 *
 * @param string $dir
 * @param bool $create
 * @return string|bool
 */
function zula_make_unique_dir($dir, $create = true)
{
    $chars = '1234567890ABCDEFGHIJKLMNOPQRSUTVWXYZabcdefghijklmnopqrstuvwxyz';
    do {
        $dirname = '';
        for ($i = 0; $i <= 9; $i++) {
            $dirname .= substr($chars, rand(0, 62), 1);
        }
        $path = $dir . '/' . $dirname;
    } while (is_dir($path));
    if ($create) {
        return zula_make_dir($path) ? $dirname : false;
    }
    return $dirname;
}
Пример #7
0
 /**
  * Saves the RSS feed back to a file;
  *
  * @return bool
  */
 public function save()
 {
     if ($this->isRemote) {
         throw new Rss_RemoteFeed();
     } else {
         if (!is_dir($this->rssDir)) {
             zula_make_dir($this->rssDir);
         }
     }
     if ($this->feed->save($this->rssDir . '/' . $this->name . '.xml')) {
         Hooks::notifyAll('rss_feed_save', $this->name);
         $this->_log->message('Saved RSS feed "' . $this->name . '"', Log::L_DEBUG);
         return true;
     }
     $this->_log->message('Unable to save RSS feed "' . $this->name . '"', Log::L_WARNING);
     return false;
 }
Пример #8
0
    /**
     * Returns the themes view output as a string. If a layout object has been
     * loaded, then all required controllers for said layout will be loaded into
     * the correct sector.
     *
     * @return string
     */
    public function output()
    {
        if (!empty($this->loadedJsFiles)) {
            // Setup some vars to be used (as JS can not get at the Zula Framework)
            $this->addHead('js', array(), 'var zula_dir_base = "' . _BASE_DIR . '";
								 var zula_dir_assets = "' . $this->_zula->getDir('assets', true) . '";
								 var zula_dir_js = "' . $this->_zula->getDir('js', true) . '";
								 var zula_dir_cur_theme = "' . $this->_zula->getDir('themes', true) . '/' . $this->getDetail('name') . '";
								 var zula_dir_icon = zula_dir_cur_theme+"/icons";
								 var zula_theme_style = "' . $this->getDetail('style') . '";', true);
        }
        if ($this->jsAggregation) {
            // Add in all needed JavaScript files, those under 'merging' will be aggregated.
            foreach (array('system', 'merging', 'standalone') as $type) {
                if (empty($this->loadedJsFiles[$type])) {
                    continue;
                    # No JS files of this type.
                } else {
                    if ($type == 'system' || $type == 'standalone') {
                        foreach ($this->loadedJsFiles[$type] as $file) {
                            $this->addHead('js', array('src' => $file));
                        }
                    } else {
                        /**
                         * Merge all 'merging' JS files into 1, help reduce HTTP requests
                         */
                        $tmpJsFile = 'js/' . zula_hash(implode('', $this->loadedJsFiles[$type]), null, 'md5') . '.js';
                        $tmpJsPath = $this->_zula->getDir('tmp') . '/' . $tmpJsFile;
                        // Check if the aggregated file exists, if so - see if we need to expire it
                        $hasFile = false;
                        if (is_dir(dirname($tmpJsPath))) {
                            if (file_exists($tmpJsPath)) {
                                $hasFile = true;
                                $lastModified = filemtime($tmpJsPath);
                                foreach ($this->loadedJsFiles[$type] as $file) {
                                    if (filemtime($file) > $lastModified) {
                                        unlink($tmpJsPath);
                                        $hasFile = false;
                                        break;
                                    }
                                }
                            }
                        } else {
                            zula_make_dir(dirname($tmpJsPath));
                        }
                        if ($hasFile === false) {
                            // Create the new aggregation file
                            $content = null;
                            foreach ($this->loadedJsFiles[$type] as $file) {
                                $content .= file_get_contents($file);
                            }
                            file_put_contents($tmpJsPath, $content);
                        }
                        $this->addHead('js', array('src' => $this->_zula->getDir('tmp', true) . '/' . $tmpJsFile));
                    }
                }
            }
        }
        if (!$this->isAssigned('HEAD')) {
            $this->assign(array('HEAD' => ''));
        }
        return $this->getOutput();
    }
Пример #9
0
 /**
  * Takes the provided destination and checks that it does not exist first
  * if so, remove it - and check that directory is writable
  *
  * @param string $destination
  * @return string
  */
 protected function prepareDestination($destination)
 {
     if ($destination == false) {
         $destination = $this->dirname . '/' . $this->filename;
         switch ($this->mime) {
             case 'image/jpeg':
             case 'image/jpg':
                 $destination .= '.jpg';
                 break;
             case '':
             case 'image/png':
                 $destination .= '.png';
                 break;
             case 'image/gif':
                 $destination .= '.gif';
                 break;
             default:
                 $destination .= '.' . $this->extension;
         }
     }
     $directory = dirname($destination);
     if (file_exists($destination)) {
         if (!@unlink($destination)) {
             throw new Image_SaveFailed($destination . ' already exists and could not be removed');
         }
     } else {
         if (!zula_make_dir($directory)) {
             throw new Image_SaveFailed($directory . ' directory could not be created');
         }
     }
     if (!zula_is_writable($directory)) {
         throw new Image_SaveFailed($directory . ' is not writable');
     }
     return $destination;
 }