Exemple #1
0
 public function addVariables()
 {
     foreach (array_reverse($this->_render->getSite()->getModules()) as $moduleName) {
         foreach (array_reverse($this->_render->getSite()->getThemes()) as $theme) {
             $file = new CM_File($this->_render->getThemeDir(true, $theme, $moduleName) . 'variables.less');
             if ($file->exists()) {
                 $this->add($file->read());
             }
         }
     }
 }
Exemple #2
0
 public function generateFavicon()
 {
     $faviconConfigList = $this->_getFaviconConfigList();
     $this->_getStreamOutput()->writeln('Generating favicons');
     $themeDirStructList = Functional\map(CM_Site_Abstract::getAll(), function (CM_Site_Abstract $site) {
         $render = new CM_Frontend_Render(new CM_Frontend_Environment($site));
         return ['render' => $render, 'themeDir' => new CM_File($render->getThemeDir(true))];
     });
     $themeDirStructList = Functional\unique($themeDirStructList, function (array $themeDirStruct) {
         /** @var CM_File $themeDir */
         $themeDir = $themeDirStruct['themeDir'];
         return $themeDir->getPath();
     });
     //filter site aliases
     foreach ($themeDirStructList as $themeDirStruct) {
         /** @var CM_Frontend_Render $render */
         $render = $themeDirStruct['render'];
         /** @var CM_File $themeDir */
         $themeDir = $themeDirStruct['themeDir'];
         $svgFile = $themeDir->joinPath('resource', 'img', self::FAVICON_SVG_FILENAME);
         if ($svgFile->exists()) {
             foreach ($faviconConfigList as $outputFilename => $config) {
                 $backgroundWidth = (int) $config['width'];
                 $backgroundHeight = (int) $config['height'];
                 $backgroundColor = false === $config['transparent'] ? $render->getLessVariable(self::FAVICON_BACKGROUND_LESS_VARIABLE) : 'transparent';
                 $background = new Imagick();
                 $background->newPseudoImage($backgroundWidth, $backgroundHeight, 'canvas:' . $backgroundColor);
                 $backgroundImage = new CM_Image_Image($background);
                 $iconSize = (int) (min($backgroundWidth, $backgroundHeight) * (double) $config['iconSize']);
                 $iconImage = CM_Image_Image::createFromSVGWithSize($svgFile->read(), $iconSize, $iconSize);
                 $backgroundImage->compositeImage($iconImage, ($backgroundWidth - $iconSize) / 2, ($backgroundHeight - $iconSize) / 2);
                 $backgroundImage->setFormat(CM_Image_Image::FORMAT_PNG);
                 $targetFile = $themeDir->joinPath('resource', 'img', 'meta', $outputFilename);
                 $targetFile->ensureParentDirectory();
                 $targetFile->write($backgroundImage->getBlob());
                 $this->_getStreamOutput()->writeln('Generated ' . $targetFile->getPath());
             }
         }
     }
 }