/** * @param string$clusterIdentifier * @param bool $backupExisting * @param bool $includeTimestamp * @return array * @throws Exception */ public function generateSpriteForCluster($clusterIdentifier, $backupExisting = true, $includeTimestamp = true) { $outputFile = $this->buildFilePath($this->outputPath, array($clusterIdentifier)); $timestampOutputFile = $this->generateFileName($outputFile, $includeTimestamp); $generatedSpriteName = substr($timestampOutputFile, strrpos($timestampOutputFile, '/') + 1); ClusterTool::setCurrentCluster( $clusterIdentifier ); $lessPath = "extension/{$clusterIdentifier}/design/oscar/stylesheets/"; $icoSprite = "/ico_sprite.png"; $offsetStep = 95; $crop = $offsetStep * 2; $mobileStep = 83; $spriteConvertOptions = " -crop x{$crop}+0+0 "; $globalConvertOptions = " -append -quality 80%"; $applicationList = CacheApplicationTool::clusterApplications(); $cssList = array(); $icoList = array(); foreach( $applicationList as $application ) { $icoCss = 'ico_'.SolrSafeOperatorHelper::getAppIdentifierForIcon( $application->applicationObject->identifier ); $icoFile = StaticData::clusterFilePath( $clusterIdentifier, 'apps/'.$application->applicationObject->identifier.$icoSprite, true, true ); if ( ! file_exists( $icoFile ) ) { $icoFile = StaticData::clusterFilePath( 'default', 'apps/'.$application->applicationObject->identifier.$icoSprite, true, true ); } if ( file_exists( $icoFile ) && ! in_array( $icoCss, $cssList ) ) { $cssList[] = $icoCss; $icoList[] = $icoFile; } } if (empty($icoList)) { throw new \Exception("No icons found for cluster {$clusterIdentifier}", 0); } if ($backupExisting && file_exists($outputFile)) { rename($outputFile, $outputFile . '.bak'); } $convertBinPath = $this->convertBinPath; $cmd = 'export PATH=$PATH:' . $convertBinPath . '; convert ' . implode( $spriteConvertOptions, $icoList ) . "{$spriteConvertOptions} {$globalConvertOptions} {$outputFile}"; $cmdStatus = 0; $cmdOutput = array(); exec($cmd, $cmdOutput, $cmdStatus); if ($cmdStatus != 0) { return array( 'errorCode' => $cmdStatus, 'generateSpriteCommand' => $cmd, 'error' => implode('\n', $cmdOutput), ); } $css = " #app-catalog a.app-bar-access-app-library .poster{ background-image: none !important; } #app-catalog a .poster, #hide-app a .poster, .item-apps .batch .wrap > a .poster, .item-related-app .batch .wrap > a .poster{ background-image:url(/esibuild/static/{$clusterIdentifier}/{$generatedSpriteName}); background-repeat: no-repeat; } "; $cssMobile = " #app-catalog a.app-bar-access-app-library .poster{ background-image: none !important; } #app-catalog a .poster, #hide-app a .poster, .item-apps .batch .wrap > a .poster, .item-related-app .batch .wrap > a .poster{ background-image:url(/esibuild/static/{$clusterIdentifier}/{$generatedSpriteName}); background-repeat: no-repeat; background-size: {$mobileStep}px auto !important; } "; $offset = 0; $offsetMobile = 0; foreach( $cssList as $key => $cssStyle ) { $css .= " #app-catalog a .poster.$cssStyle, #hide-app a .poster.$cssStyle, .item-apps .batch .wrap > a .poster.$cssStyle, .item-related-app .batch .wrap > a .poster.$cssStyle{ background-position: 0 -{$offset}px !important; } "; $cssMobile .= " #app-catalog a .poster.$cssStyle, #hide-app a .poster.$cssStyle, .item-apps .batch .wrap > a .poster.$cssStyle{ background-position: 0 -{$offsetMobile}px !important; } "; $offset += $offsetStep; $offsetMobile += $mobileStep; $css .= " #app-catalog a:hover .poster.$cssStyle, #app-catalog a:active .poster.$cssStyle, #app-catalog a.active .poster.$cssStyle, #hide-app a:active .poster.$cssStyle, #hide-app a.active .poster.$cssStyle, .item-apps .batch:hover .wrap > a .poster.$cssStyle, .item-related-app .batch:hover .wrap > a .poster.$cssStyle{ background-position: 0 -{$offset}px !important; } "; $cssMobile .= " #app-catalog a:hover .poster.$cssStyle, #app-catalog a:active .poster.$cssStyle, #app-catalog a.active .poster.$cssStyle, #hide-app a:active .poster.$cssStyle, #hide-app a.active .poster.$cssStyle, .item-apps .batch:hover .wrap > a .poster.$cssStyle, .item-related-app .batch:hover .wrap > a .poster.$cssStyle{ background-position: 0 -{$offsetMobile}px !important; } "; $offset += $offsetStep; $offsetMobile += $mobileStep; } if ( ! file_exists( $lessPath ) ) { mkdir( $lessPath, 0755 ); } if ( is_dir( $lessPath ) ) { $lessFile = $lessPath."mod.icosprite.less"; file_put_contents( $lessFile, $css ); $lessFileMobile = $lessPath."mod.icosprite.mobile.less"; file_put_contents( $lessFileMobile, $cssMobile ); eZCache::clearByID( array('ezjscore-packer'), 'template-block' ); } return array( 'errorCode' => 0, 'generateSpriteCommand' => $cmd ); }
<?php /* @type $Params string[] */ $clusterIdentifier = isset( $Params['ClusterIdentifier'] ) ? $Params['ClusterIdentifier'] : ClusterTool::clusterIdentifier(); $applicationIdentifier = $Params['ApplicationIdentifier']; $staticDir = StaticData::directory(); $clusterShort = substr( $clusterIdentifier, 8 ); $filesToCheck = array( StaticData::clusterFilePath( $clusterIdentifier, 'apps/' . $applicationIdentifier . '/appstore_cover.jpg' ), StaticData::clusterFilePath( $clusterIdentifier, 'apps/' . $applicationIdentifier . '/appstore_cover.png' ), 'extension/ezoscar/design/oscar/images/' . $clusterShort . '/apps/' . $applicationIdentifier . '/appstore_cover.jpg', 'extension/ezoscar/design/oscar/images/' . $clusterShort . '/apps/' . $applicationIdentifier . '/appstore_cover.png', 'extension/ezoscar/design/oscar/images/common/apps/' . $applicationIdentifier . '/appstore_cover.jpg', 'extension/ezoscar/design/oscar/images/common/apps/' . $applicationIdentifier . '/appstore_cover.png' ); foreach ( $filesToCheck as $file ) { if ( file_exists( $file ) ) { $image = file_get_contents( $file ); $fileUtils = eZClusterFileHandler::instance( $file ); $fileUtils->storeContents( $image ); header( 'Content-Type: image/jpg' ); header( 'Content-Length: ' . $fileUtils->size() ); $fileUtils->passthrough(); eZExecution::cleanExit(); } }
<?php $parameters = $Module->OriginalParameters; $cluster = array_shift($parameters); if ($cluster == 'auto') $cluster = ClusterTool::clusterIdentifier(); $path = eZDir::path($parameters); $filePath = StaticData::clusterFilePath($cluster, $path); if ($filePath) { $fileName = basename( $filePath ); $fileExtension = strtolower( substr( strrchr( $fileName, "." ), 1 ) ); $contentType = "application/octet-stream"; switch( $fileExtension ) { case "gif": $contentType = "image/gif"; break; case "png": $contentType = "image/png"; break; case "jpg": case "jpeg": $contentType = "image/jpg"; default: break; }
/** * @param string $path * @param string $quote * @param bool $skipSlash * @return string */ public static function staticFile($path, $quote, $skipSlash) { $ini = eZINI::instance(); $imgDecHash = 0; if ( $ini->variable( 'DesignSettings', 'DynamicImageSuffix' ) == 'enabled' ) { $cluster = ClusterTool::clusterIdentifier(); $filePath = StaticData::clusterFilePath($cluster, $path); if ( ! empty( $filePath ) ) { $imgHash = sha1_file( $filePath ); $imgDecHash = hexdec( substr( $imgHash, 0, 7 ) ); } } $path = StaticData::externalUrl(ClusterTool::clusterIdentifier(), $path); $path = (!$skipSlash ? '/' : '') . ltrim($path, '/'); if ( ! empty( $imgDecHash ) ) { $path = preg_replace( '/^(.*)\.([^.]+)$/i', '$1.'.$imgDecHash.'.$2', $path ); } if (! $skipSlash ) { $serverURL = eZURI::serverShardingURL( $path ); $path = $serverURL.$path; } if ($quote == 'double') $path = sprintf('"%s"', $path); elseif ($quote == "single") $path = sprintf("'%s'", $path); return $path; }
/** * @param string $type * @return string */ private function getBanner( $type ) { // second type because new files are named with 'large' instead of big in name. if( $type == 'big' ) $type = 'large'; $appIdentifier = $this->applicationObject()->attribute('identifier'); $extensionsFallbacks = array( 'jpg', 'jpeg', 'png', ); $outputFile = null; foreach ($extensionsFallbacks as $extension) { if (!$outputFile) { $outputFile = StaticData::clusterFilePath(ClusterTool::clusterIdentifier(), "apps/{$appIdentifier}/banner_{$type}.{$extension}"); } else { break; } } if ($outputFile) return $outputFile; return null; }
/** * @return array */ public static function applicationList() { # Hotfix #23450 note-8 if ( !isset($_COOKIE['remember_me']) ) { $cookieExpiration = time() + eZINI::instance('merck.ini')->variable('TIBCOCookieSettings', 'TIBCOCookieExpiration'); $uuid = MMUsers::getCurrentUserId(); setcookie('remember_me', MMUserLogin::encryptText(json_encode($uuid)), $cookieExpiration, '/', CookieTool::getCookieDomain()); } $out = array('applicationList' => array()); $host = 'http://' . self::host(); if ( isset($_POST['application']) ) { $applicationIdList = array((int) $_POST['application']); } else { $applicationIdList = AppBarControl::instance()->applicationIds(); } foreach ( $applicationIdList as $applicationId ) { if ( !is_numeric($applicationId) ) { continue; } $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByApplication($applicationId); $application = ($applicationLocalized) ? $applicationLocalized->applicationObject() : null; if ( $applicationLocalized ) { $application = $applicationLocalized->applicationObject(); } if ( isset($application) ) { $applicationType = $application->applicationType(); $icons = array( 'icon' => array( 'path' => '', 'md5' => '', 'file' => 'ico.png', ), 'icon_hd' => array( 'path' => '', 'md5' => '', 'file' => 'ico_notext_hd.png', ), 'icon_active' => array( 'path' => '', 'md5' => '', 'file' => 'ico_notext_active.png', ), 'icon_active_hd' => array( 'path' => '', 'md5' => '', 'file' => 'ico_notext_active_hd.png' ), ); foreach($icons as $key => $iconData) { $path = sprintf('apps/%s/%s', $application->attribute('identifier'), $iconData['file']); $fullPath = StaticData::clusterFilePath(ClusterTool::clusterIdentifier(), $path); if ($fullPath) { $icons[$key]['path'] = StaticData::externalUrl(ClusterTool::clusterIdentifier(), $path); $icons[$key]['md5'] = md5_file($fullPath); } } $path = '/' . $applicationLocalized->attribute('url'); $url = $host . $path; if ( $application->isPureExternal() ) { $url = $applicationLocalized->attribute("external_url"); } $outApplicationListArray = array( 'id' => $applicationId, 'identifier' => $application->attribute('identifier'), 'name' => $applicationLocalized->attribute('name'), 'headline' => $applicationLocalized->attribute('headline'), 'type' => $applicationType->attribute('internal_type'), 'url' => $url, 'path' => $path, 'javascript' => self::getJavascript($application->attribute('identifier'), 'application')); foreach($icons as $key => $icon) { $outApplicationListArray[$key] = array( '100' => array('path' => $icon['path'], $icon['md5']), ); } $out['applicationList'][] = $outApplicationListArray; } } return $out; }
<?php /* @type $Params string[] */ $clusterIdentifier = isset( $Params['ClusterIdentifier'] ) ? $Params['ClusterIdentifier'] : ClusterTool::clusterIdentifier(); $filePath = StaticData::clusterFilePath( $clusterIdentifier, "logo_big.png" ); if ( !$filePath ) { eZDebug::writeError( 'Sprite image does not exists' ); header( 'HTTP/1.0 404 Not Found' ); } header( 'Content-Type: image/png' ); header( 'Content-Length: ' . filesize( $filePath ) ); readfile( $filePath ); eZExecution::cleanExit();
handleError(); } $publisherFolderTranslation = $publisherFolder->getTranslation(); if ($publisherFolderTranslation instanceof PublisherFolderTranslation === false) { handleError(); } if ($publisherFolderTranslation->attribute($logoType) == null) { handleError(); } //we do this only to copy the image into a proper path $filePath = $publisherFolderTranslation->getFile($logoType); $filePath = StaticData::clusterFilePath( $clusterIdentifier, "publisher_folders/{$publisherFolder->attribute('path')}/{$logoType}.png" ); header( 'Content-Type: image/png' ); header( 'Content-Length: ' . filesize( $filePath ) ); readfile( $filePath ); eZExecution::cleanExit(); function handleError() { eZDebug::writeError( 'Sprite image does not exists' ); header( 'HTTP/1.0 404 Not Found' ); eZExecution::cleanExit(); }
<?php /* @type $Params string[] */ $appIdentifier = $Params['ApplicationIdentifier']; $clusterIdentifier = isset( $Params['ClusterIdentifier'] ) ? $Params['ClusterIdentifier'] : ClusterTool::clusterIdentifier(); $varDir = eZINI::instance( 'site.ini' )->variable( 'FileSettings', 'VarDir' ); $outputFile = "{$varDir}/images/common/apps/icon/{$appIdentifier}/{$clusterIdentifier}_ico.png"; $spriteImgPath = StaticData::clusterFilePath(false, "apps/{$appIdentifier}/ico_sprite.png"); $backgroundFilePath = './extension/ezoscar/design/oscar/images/common/appicon/background.png'; $fileUtils = eZClusterFileHandler::instance($outputFile); ClusterTool::setCurrentCluster( $clusterIdentifier ); $app = CacheApplicationTool::buildLocalizedApplicationByIdentifier( $appIdentifier ); ClusterTool::resetCurrentCluster(); if ( !$app instanceof ApplicationLocalized ) { eZDebug::writeError( "Application not found: {$appIdentifier}" ); header('HTTP/1.0 404 Not Found'); eZExecution::cleanExit(); } if ( $fileUtils->fileExists( $outputFile ) ) { $appIcon = $fileUtils->fetchContents(); }