public function showAssetPackageSizesAction()
 {
     $a = new Kwf_Util_Build_Types_Assets();
     $packages = $a->getAllPackages();
     $langs = $a->getAllLanguages();
     $exts = array('js', 'defer.js', 'css');
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         $language = $langs[0];
         foreach ($exts as $extension) {
             $cacheId = Kwf_Assets_Dispatcher::getCacheIdByPackage($p, $extension, $language);
             $cacheContents = Kwf_Assets_BuildCache::getInstance()->load($cacheId);
             echo "{$depName} ";
             $h = new Kwf_View_Helper_FileSize();
             echo "{$extension} size: " . $h->fileSize(strlen(gzencode($cacheContents['contents'], 9, FORCE_GZIP)));
             echo "\n";
         }
     }
     $d = Kwf_Assets_Package_Default::getDefaultProviderList()->findDependency('Frontend');
     foreach ($d->getFilteredUniqueDependencies('text/javascript') as $i) {
         if ($i instanceof Kwf_Assets_Dependency_File && $i->getType() == 'ext2') {
             echo "\n[WARNING] Frontend text/javascript contains ext2\n";
             echo "To improve frontend performance all ext2 dependencies should be moved to defer\n\n";
             break;
         }
     }
     exit;
 }
Example #2
0
 public function writeContent()
 {
     $fileSizeHelper = new Kwf_View_Helper_FileSize();
     $encodeTextHelper = new Kwf_View_Helper_Link();
     $vars = $this->_component->getTemplateVars();
     if ($vars['icon']) {
         $this->_pdf->Image($vars['icon']->getFilename(), $this->_pdf->getX(), $this->_pdf->getY(), 3, 3, 'PNG');
     }
     $this->_pdf->setX($this->_pdf->getX() + 4);
     if ($vars['filesize']) {
         $filesize = ' (' . $fileSizeHelper->fileSize($vars['filesize']) . ')';
     } else {
         $filesize = '';
     }
     $link = $this->_getDownloadUrl();
     $this->_pdf->Cell(0, 0, $vars['infotext'] . $filesize, '', 1, '', 0, $link);
     $this->Ln(1);
 }
 public function showFrontendAssetSizesAction()
 {
     $packages = array(Kwf_Assets_Package_Default::getInstance('Frontend'));
     $mimeTypes = array('text/javascript', 'text/javascript; defer', 'text/css', 'text/css; defer');
     foreach ($packages as $p) {
         foreach ($mimeTypes as $mimeType) {
             $sizes = array();
             echo "\n" . $p->getDependencyName() . " {$mimeType}\n";
             foreach ($p->getFilteredUniqueDependencies($mimeType) as $i) {
                 $sizes[(string) $i] = strlen(gzencode($i->getContentsPacked('en')->getFileContents(), 9, FORCE_GZIP));
             }
             arsort($sizes);
             $sumSize = array_sum($sizes);
             $topSizes = array_slice($sizes, 0, 10);
             foreach ($topSizes as $name => $size) {
                 echo "" . str_pad(number_format(round($size / $sumSize * 100, 1), 1) . '%', 5) . ' ' . str_pad(Kwf_View_Helper_FileSize::fileSize($size), 10) . " {$name}\n";
             }
         }
     }
 }
Example #4
0
 protected function _build($options)
 {
     if (!file_exists('build/assets')) {
         mkdir('build/assets');
     }
     Kwf_Assets_BuildCache::getInstance()->building = true;
     Kwf_Assets_BuildCache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->save(time(), 'assetsVersion');
     $langs = $this->_getAllLanguages();
     $packages = $this->_getAllPackages();
     $exts = array('js', 'defer.js', 'css', 'printcss');
     echo "\ncalculating dependencies...\n";
     $steps = count($packages) * count($exts);
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     $countDependencies = 0;
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($exts as $extension) {
             $progress->next(1, "{$depName} {$extension}");
             $countDependencies += count($p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]));
             $cacheId = $p->getMaxMTimeCacheId(self::$_mimeTypeByExtension[$extension]);
             if (!$cacheId) {
                 throw new Kwf_Exception("Didn't get cacheId for " . get_class($p));
             }
             $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
             Kwf_Assets_BuildCache::getInstance()->save($maxMTime, $cacheId);
             //save generated caches for clear-cache-watcher
             $fileName = 'build/assets/package-max-mtime-' . $extension;
             if (!file_exists($fileName) || strpos(file_get_contents($fileName), $cacheId . "\n") === false) {
                 file_put_contents($fileName, $cacheId . "\n", FILE_APPEND);
             }
         }
     }
     $progress->finish();
     echo "compiling assets...\n";
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $countDependencies);
     foreach ($packages as $p) {
         foreach ($exts as $extension) {
             foreach ($p->getFilteredUniqueDependencies(self::$_mimeTypeByExtension[$extension]) as $dep) {
                 $progress->next(1, "{$dep}");
                 $dep->warmupCaches();
             }
         }
     }
     $progress->finish();
     echo "generating packages...\n";
     $steps = count($packages) * count($langs) * count($exts) * 4;
     $c = new Zend_ProgressBar_Adapter_Console();
     $c->setElements(array(Zend_ProgressBar_Adapter_Console::ELEMENT_PERCENT, Zend_ProgressBar_Adapter_Console::ELEMENT_BAR, Zend_ProgressBar_Adapter_Console::ELEMENT_TEXT));
     $c->setTextWidth(50);
     $progress = new Zend_ProgressBar($c, 0, $steps);
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         foreach ($langs as $language) {
             foreach ($exts as $extension) {
                 $packageContents = $p->getPackageContents(self::$_mimeTypeByExtension[$extension], $language);
                 $maxMTime = $p->getMaxMTime(self::$_mimeTypeByExtension[$extension]);
                 $progress->next(1, "{$depName} {$extension} {$language}");
                 $progress->next(1, "{$depName} {$extension} {$language} source");
                 $this->_buildPackageContents($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} map");
                 $this->_buildPackageSourceMap($packageContents, $maxMTime, $p, $extension, $language);
                 $progress->next(1, "{$depName} {$extension} {$language} url");
                 $urls = $p->getPackageUrls(self::$_mimeTypeByExtension[$extension], $language);
                 if (Kwf_Setup::getBaseUrl()) {
                     foreach ($urls as $k => $i) {
                         $urls[$k] = substr($i, strlen(Kwf_Setup::getBaseUrl()));
                     }
                 }
                 $cacheId = $p->getPackageUrlsCacheId(self::$_mimeTypeByExtension[$extension], $language);
                 Kwf_Assets_BuildCache::getInstance()->save($urls, $cacheId);
             }
         }
     }
     Kwf_Assets_Cache::getInstance()->clean();
     Kwf_Assets_BuildCache::getInstance()->building = false;
     $exts = array('js', 'defer.js', 'css');
     foreach ($packages as $p) {
         $depName = $p->getDependencyName();
         $language = $langs[0];
         foreach ($exts as $extension) {
             $cacheId = Kwf_Assets_Dispatcher::getCacheIdByPackage($p, $extension, $language);
             $cacheContents = Kwf_Assets_BuildCache::getInstance()->load($cacheId);
             echo "{$depName} ";
             $h = new Kwf_View_Helper_FileSize();
             echo "{$extension} size: " . $h->fileSize(strlen(gzencode($cacheContents['contents'], 9, FORCE_GZIP)));
             echo "\n";
         }
     }
     $d = Kwf_Assets_Package_Default::getDefaultProviderList()->findDependency('Frontend');
     foreach ($d->getFilteredUniqueDependencies('text/javascript') as $i) {
         if ($i instanceof Kwf_Assets_Dependency_File && $i->getType() == 'ext2') {
             echo "\n[WARNING] Frontend text/javascript contains ext2\n";
             echo "To improve frontend performance all ext2 dependencies should be moved to defer\n\n";
             break;
         }
     }
 }
 public function statusAction()
 {
     $allProcesses = Kwf_Util_Process::getRunningProcesses();
     $webProcesses = Kwf_Util_Process::getRunningWebProcesses();
     foreach ($this->_commands as $requiredCmd) {
         $found = false;
         foreach ($webProcesses as $p) {
             if ($p['cmd'] == $requiredCmd['cmd']) {
                 $found = true;
                 echo "[{$p['pid']}] " . Kwf_View_Helper_FileSize::fileSize($p['memory']) . " {$p['prettyTime']} {$p['cmd']}\n";
                 foreach ($p['childPIds'] as $pid) {
                     $cp = $allProcesses[$pid];
                     echo "  [{$cp['pid']}] " . Kwf_View_Helper_FileSize::fileSize($cp['memory']) . " {$cp['prettyTime']} {$cp['cmd']}\n";
                 }
             }
         }
         if (!$found) {
             echo "NOT RUNNING: {$requiredCmd['cmd']}\n";
         }
     }
     exit;
 }
Example #6
0
 public function getTemplateVars($values, $namePostfix = '', $idPrefix = '')
 {
     $name = $this->getFieldName();
     $value = isset($values[$name]) ? $values[$name] : null;
     $ret = parent::getTemplateVars($values, $namePostfix, $idPrefix);
     $fileSizeLimit = $this->getFileSizeLimit();
     $name = htmlspecialchars($name);
     $ret['id'] = $idPrefix . str_replace(array('[', ']'), array('_', '_'), $name . $namePostfix);
     $ret['html'] = "<div class=\"kwfFormFieldFileInnerImg\">\n";
     if ($value) {
         $ret['html'] .= "<input type=\"hidden\" name=\"{$name}_upload_id{$namePostfix}\" " . " value=\"{$value['uploadId']}_{$value['hashKey']}\" />";
         if ($value['image']) {
             //todo: width und height von image
             $ret['html'] .= " <img src=\"/kwf/media/upload/preview?uploadId={$value['uploadId']}&hashKey={$value['hashKey']}&amp;size=frontend\" alt=\"\" width=\"100\" height=\"100\" />";
         }
     }
     $ret['html'] .= '</div>';
     $ret['html'] .= "<div class=\"kwfFormFieldFileInnerContent\">\n";
     $ret['html'] .= '<div class="kwfFormFieldFieldDropText">' . $this->getDropText() . '</div>';
     $ret['html'] .= "<div class=\"imagePath kwfFormFieldFileUploadWrapper\">\n";
     $ret['html'] .= "<input class=\"fileSelector\" type=\"file\" id=\"{$ret['id']}\" name=\"{$name}{$namePostfix}\" " . " data-file-size-limit=\"{$fileSizeLimit}\" " . " style=\"width: {$this->getWidth()}px\" onchange=\"document.getElementById(this.id+'_underlayText').value = this.value;\" />";
     $ret['html'] .= '<div class="underlayFileSelector">';
     $ret['html'] .= '<input type="text" id="' . $ret['id'] . '_underlayText" class="kwfFormFieldFileUnderlayText" style="width: ' . $this->getWidth() . 'px;" />';
     $ret['html'] .= ' <a href="#" class="kwfFormFieldFileUploadButton" onclick="return false;">' . $this->getFrontendButtonText() . '</a>';
     $ret['html'] .= '</div>';
     $ret['html'] .= '</div>';
     if ($value) {
         $ret['html'] .= "<div class=\"imageTitle\">\n";
         $ret['html'] .= '' . $value['filename'] . '.' . $value['extension'];
         $helper = new Kwf_View_Helper_FileSize();
         $ret['html'] .= ' (' . $helper->fileSize($value['fileSize']) . ')';
         $ret['html'] .= '</div>';
         $ret['html'] .= '<div class="deleteImage"><button class="deleteImage" type="submit" name="' . $name . '_del' . $namePostfix . '" value="1">' . trlKwf("Delete") . '</button></div>';
         $uploadId = $value['uploadId'];
         $hashKey = '_' . $value['hashKey'];
     } else {
         $uploadId = '0';
         $hashKey = '';
     }
     $ret['html'] .= "<input type=\"hidden\" class=\"kwfUploadIdField\" name=\"{$name}_upload_id{$namePostfix}\" " . " value=\"{$uploadId}{$hashKey}\" />";
     $ret['html'] .= '</div>';
     return $ret;
 }