Esempio n. 1
0
    /**
     * Compilation of Layout Designer code
     * System method used by platform developers
     */
    public function compileAction()
    {
        if (!$this->_config->get('development')) {
            die('Use development mode');
        }
        $s = '';
        $totalSize = 0;
        foreach (self::$_scripts as $filePath) {
            $s .= file_get_contents('.' . $filePath) . "\n";
            $totalSize += filesize('.' . $filePath);
        }
        $time = microtime(true);
        file_put_contents('.' . $this->_config->get('compiled_js'), Code_Js_Minify::minify($s));
        echo '
			Compilation time: ' . number_format(microtime(true) - $time, 5) . ' sec<br>
			Files compiled: ' . sizeof(self::$_scripts) . ' <br>
			Total size: ' . Utils::formatFileSize($totalSize) . '<br>
			Compiled File size: ' . Utils::formatFileSize(filesize('.' . $this->_config->get('compiled_js'))) . ' <br>
		';
        exit;
    }
Esempio n. 2
0
 /**
  * Dev. method. Compile JavaScript sources
  */
 public function compileAction()
 {
     $sources = array('/js/app/system/medialib/Category.js', '/js/app/system/medialib/Panel.js', '/js/app/system/medialib/Models.js', '/js/app/system/medialib/FileUploadWindow.js', '/js/app/system/medialib/ImageSizeWindow.js', '/js/app/system/medialib/SelectMediaItemWindow.js', '/js/app/system/medialib/ItemField.js', '/js/app/system/medialib/EditWindow.js', '/js/app/system/medialib/CropWindow.js');
     if (!$this->_configMain->get('development')) {
         die('Use development mode');
     }
     $s = '';
     $totalSize = 0;
     foreach ($sources as $filePath) {
         $s .= file_get_contents('.' . $filePath) . "\n";
         $totalSize += filesize('.' . $filePath);
     }
     $time = microtime(true);
     file_put_contents('./js/app/system/Medialib.js', Code_Js_Minify::minify($s));
     echo '
   			Compilation time: ' . number_format(microtime(true) - $time, 5) . ' sec<br>
   			Files compiled: ' . sizeof($sources) . ' <br>
   			Total size: ' . Utils::formatFileSize($totalSize) . '<br>
   			Compiled File size: ' . Utils::formatFileSize(filesize('./js/app/system/Medialib.js')) . ' <br>
   		';
     exit;
 }
Esempio n. 3
0
 /**
  * Compile JS files cache
  * @param array $files - file paths relative to the document root directory
  * @param boolean $minify - minify scripts
  * @return string  - cached file path
  */
 protected function _compileJsFiles($files, $minify)
 {
     $validHash = $this->_getFileHash(Utils::fetchCol('file', $files));
     $cacheFile = Utils::createCachePath(self::$_jsCachePath, $validHash . '.js');
     $cachedUrl = str_replace(self::$_jsCachePath, self::$_jsCacheUrl, $cacheFile);
     if (file_exists($cacheFile)) {
         return $cachedUrl;
     }
     $str = '';
     foreach ($files as $file) {
         $str .= "\n";
         $fileName = $file['file'];
         $paramsPos = strpos($fileName, '?', true);
         if ($paramsPos !== false) {
             $fileName = substr($fileName, 0, $paramsPos);
         }
         $content = file_get_contents(self::$_docRoot . '/' . $fileName);
         if ($minify && !$file['minified']) {
             $str .= Code_Js_Minify::minify($content);
         } else {
             $str .= $content;
         }
     }
     file_put_contents($cacheFile, $str);
     return $cachedUrl;
 }
Esempio n. 4
0
    /**
     * Dev. method. Compile JavaScript sources
     */
    public function compileAction()
    {
        $sources = array('/js/app/system/orm/panel.js', '/js/app/system/orm/dataGrid.js', '/js/app/system/orm/objectWindow.js', '/js/app/system/orm/fieldWindow.js', '/js/app/system/orm/indexWindow.js', '/js/app/system/orm/restoreBackupWindow.js', '/js/app/system/orm/dictionaryWindow.js', '/js/app/system/orm/objectsMapWindow.js', '/js/app/system/orm/dataViewWindow.js', '/js/app/system/orm/objectField.js', '/js/app/system/orm/connections.js', '/js/app/system/orm/logWindow.js', '/js/app/system/orm/import.js', '/js/app/system/orm/taskStatusWindow.js');
        if (!$this->_configMain->get('development')) {
            die('Use development mode');
        }
        $s = '';
        $totalSize = 0;
        foreach ($sources as $filePath) {
            $s .= file_get_contents('.' . $filePath) . "\n";
            $totalSize += filesize('.' . $filePath);
        }
        $time = microtime(true);
        file_put_contents('./js/app/system/ORM.js', Code_Js_Minify::minify($s));
        echo '
			Compilation time: ' . number_format(microtime(true) - $time, 5) . ' sec<br>
			Files compiled: ' . sizeof($sources) . ' <br>
			Total size: ' . Utils::formatFileSize($totalSize) . '<br>
			Compiled File size: ' . Utils::formatFileSize(filesize('./js/app/system/ORM.js')) . ' <br>
		';
        exit;
    }
Esempio n. 5
0
 /**
  * Gel list of JS files to include
  * (load and render designer project)
  * @param string $cacheKey
  * @param Designer_Project $project
  * @param boolean $selfInclude
  * @param array $replace
  * @return array
  */
 public static function getProjectIncludes($cacheKey, Designer_Project $project, $selfInclude = true, $replace = array())
 {
     $applicationConfig = Registry::get('main', 'config');
     $designerConfig = Config::factory(Config::File_Array, $applicationConfig->get('configs') . 'designer.php');
     $projectConfig = $project->getConfig();
     $includes = array();
     // include langs
     if (isset($projectConfig['langs']) && !empty($projectConfig['langs'])) {
         $language = Lang::getDefaultDictionary();
         $lansPath = $designerConfig->get('langs_path');
         $langsUrl = $designerConfig->get('langs_url');
         foreach ($projectConfig['langs'] as $k => $file) {
             $file = $language . '/' . $file . '.js';
             if (file_exists($lansPath . $file)) {
                 $includes[] = $langsUrl . $file . '?' . filemtime($lansPath . $file);
             }
         }
     }
     if (isset($projectConfig['files']) && !empty($projectConfig['files'])) {
         foreach ($projectConfig['files'] as $file) {
             $ext = File::getExt($file);
             if ($ext === '.js' || $ext === '.css') {
                 $includes[] = $designerConfig->get('js_url') . $file;
             } else {
                 $projectFile = $designerConfig->get('configs') . $file;
                 $subProject = Designer_Factory::loadProject($designerConfig, $projectFile);
                 $projectKey = self::getProjectCacheKey($projectFile);
                 $files = self::getProjectIncludes($projectKey, $subProject, true, $replace);
                 unset($subProject);
                 if (!empty($files)) {
                     $includes = array_merge($includes, $files);
                 }
             }
         }
     }
     Ext_Code::setRunNamespace($projectConfig['runnamespace']);
     Ext_Code::setNamespace($projectConfig['namespace']);
     if ($selfInclude) {
         $layoutCacheFile = Utils::createCachePath($applicationConfig->get('jsCacheSysPath'), $cacheKey . '.js');
         /**
          * @todo remove slow operation
          */
         if (!file_exists($layoutCacheFile)) {
             file_put_contents($layoutCacheFile, Code_Js_Minify::minify($project->getCode($replace)));
         }
         $includes[] = str_replace('./', '/', $layoutCacheFile);
     }
     /*
      * Project actions
      */
     $actionFile = $project->getActionsFile();
     /**
      * @todo slow operation
      */
     $mTime = 0;
     if (file_exists('.' . $actionFile)) {
         $mTime = filemtime('.' . $actionFile);
     }
     $includes[] = $actionFile . '?' . $mTime;
     return $includes;
 }