Exemple #1
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;
 }
Exemple #2
0
 /**
  * Gets the media item file in the correct format and passes it through PHP
  *
  * @param array $item
  * @param string $format
  * @return bool
  */
 protected function displayFormat(array $item, $format)
 {
     if ($format == 'thumb') {
         $file = $item['path_fs'] . '/' . $item['thumbnail'];
     } else {
         if ($item['type'] == 'image') {
             /**
              * Get either full or medium sized image, however no large than
              * the specified max width.
              */
             $imgPath = $item['path_fs'] . '/' . $item['filename'];
             if (is_file($imgPath)) {
                 list($imgWidth) = getimagesize($imgPath);
                 $maxWidth = $this->_config->get('media/max_image_width');
                 if ($format == 'medium') {
                     // Display the medium size image no wider than the themes content
                     try {
                         $contentWidth = $this->_theme->getDetail('contentWidth');
                     } catch (Theme_DetailNoExist $e) {
                         $contentWidth = 500;
                     }
                     if ($contentWidth < $maxWidth) {
                         $maxWidth = $contentWidth;
                     }
                 }
                 // Resize and add watermark if needed
                 $wmPath = $this->_zula->getDir('uploads') . '/media/wm.png';
                 if ($imgWidth <= $maxWidth && !is_file($wmPath)) {
                     $file = $imgPath;
                 } else {
                     $file = $this->_zula->getDir('tmp') . "/media/max{$maxWidth}-" . pathinfo($item['filename'], PATHINFO_BASENAME);
                     if (!is_file($file)) {
                         $image = new Image($imgPath);
                         $image->resize($maxWidth, null, false);
                         if (is_file($wmPath)) {
                             $image->watermark($wmPath, $this->_config->get('media/wm_position'));
                         }
                         $image->save($file);
                     }
                 }
             }
         } else {
             if ($format == 'stream' && $item['type'] == 'audio' || $item['type'] == 'video') {
                 $file = $item['path_fs'] . '/' . $item['filename'];
             }
         }
     }
     if (isset($file) && is_file($file)) {
         zula_readfile($file);
         return false;
     } else {
         if ($format == 'thumb') {
             zula_readfile(zula_get_icon('misc/missing_' . $item['type'], null, false));
             return false;
         } else {
             if ($item['type'] == 'image') {
                 // Display default icon
                 zula_readfile(zula_get_icon('misc/no_file', null, false));
                 return false;
             } else {
                 throw new Module_ControllerNoExist();
             }
         }
     }
 }
Exemple #3
0
    $module = preg_replace('#[^A-Z0-9_\\-]+#i', '', substr($assetPath, 0, $slashPos));
    $path = substr($assetPath, $slashPos + 1);
    if ($path !== false) {
        /**
         * Build both the path and real path to the asset, comparing that to what was
         * provided. Basically a similar functionaility to openbase_dir I guess.
         */
        $assetDir = Module::getDirectory() . '/' . $module . '/assets';
        $assetPath = $assetDir . '/' . $path;
        if (strpos(realpath($assetPath), realpath($assetDir)) === 0 && is_readable($assetPath)) {
            // Set all of the headers needed and output the file
            switch (pathinfo($assetPath, PATHINFO_EXTENSION)) {
                case 'js':
                    $mime = 'text/javascript; charset=utf-8';
                    break;
                case 'css':
                    $mime = 'text/css; charset=utf-8';
                    break;
                default:
                    $mime = zula_get_file_mime($assetPath);
                    if ($mime === false) {
                        $mime = 'text/plain';
                    }
            }
            return (bool) zula_readfile($assetPath, $mime);
        }
    }
}
// Will only ever occur if something goes wrong up there.
header('HTTP/1.1 404 Not Found', true, 404);
return false;