/** * Loads all the static strings from either the cache or the ini files. Note that ini files in modules are not verified for outdatedness, so if they were updated, just clear all the caches or hard reload a page * This method should not be called directly from outsite TranslationPeer except for testing and debugging purposes */ public static function getStaticStrings($sLanguageId) { if (!isset(self::$STATIC_STRINGS[$sLanguageId])) { $oCache = new Cache($sLanguageId, DIRNAME_LANG); $aLanguageFiles = ResourceFinder::create()->addPath(DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find(); if ($oCache->entryExists() && !$oCache->isOutdated($aLanguageFiles)) { self::$STATIC_STRINGS[$sLanguageId] = $oCache->getContentsAsVariable(); } else { self::$STATIC_STRINGS[$sLanguageId] = array(); //Get default strings foreach ($aLanguageFiles as $sLanguageFile) { self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile)); } //Get strings for modules foreach (ResourceFinder::create()->addExpression(DIRNAME_MODULES, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN, DIRNAME_LANG, "{$sLanguageId}.ini")->all()->baseFirst()->find() as $sLanguageFile) { self::$STATIC_STRINGS[$sLanguageId] = array_merge(self::$STATIC_STRINGS[$sLanguageId], parse_ini_file($sLanguageFile)); } //Fix string encoding foreach (self::$STATIC_STRINGS[$sLanguageId] as $sStringKey => $sValue) { self::$STATIC_STRINGS[$sLanguageId][$sStringKey] = StringUtil::encodeForDbFromFile($sValue); } $oCache->setContents(self::$STATIC_STRINGS[$sLanguageId]); } } return self::$STATIC_STRINGS[$sLanguageId]; }
/** * loadToDbFromYamlFile() * description: * - reading yaml config file with params 'modelName', 'inserts', 'insert_pattern' * - and processing the data by passing it to a propel modelName::insertRow() method passing a array assoc of fieldnames and values * - works only already installed db, handled by propel * - see details in the data/install/'table_name.insert.yml' files and install_notes.txt * @param string $sFileName table_name or optionally fullfilename.yml * @param string $sFileDir optional path to directory (like '/dirname'), defaults to MAIN_DIR/DIRNAME_DATA/install * @return void */ public static function loadToDbFromYamlFile($sFileName, $sFileDir = null) { if ($sFileDir === null) { $sFileDir = ResourceFinder::findResource(array(DIRNAME_DATA, 'install')); } $sFileName = count(explode('.', $sFileName)) == 1 ? $sFileName . '.insert.yml' : $sFileName; $aFileContent = self::loadYamlFile($sFileName, $sFileDir); if (!isset($aFileContent['model_name'])) { throw new Exception('Error in InstallUtil: insertIntoDbFromConfigFile() expects file with param "model_name" set!'); } if (!isset($aFileContent['insert_pattern'])) { throw new Exception('Error in InstallUtil: insertIntoDbFromConfigFile() expects file with array "insert_pattern" set!'); } $aArrayOfValues = array(); foreach ($aFileContent['inserts'] as $sKey => $aData) { $i = 1; foreach ($aFileContent['insert_pattern'] as $sIndex => $sColumnName) { if ($sIndex == 'key' && $i === 1) { $aArrayOfValues[$sColumnName] = $sKey; } else { $aArrayOfValues[$sColumnName] = isset($aData[$sColumnName]) ? $aData[$sColumnName] : false; // optional boolean handling } $i++; } call_user_func(array($aFileContent['model_name'] . 'Peer', "insertRow"), $aArrayOfValues); } }
/** send() * Description: * • This method is called when NewsletterMailer is instanciated * • All newsletter, sender and recipient info are ready * * @return boolean has_invalid email addresses */ public function send() { // Get newsletter email main template and template body and css by template name $oEmailTemplate = new Template('main', array(DIRNAME_TEMPLATES, 'newsletter')); $oEmailTemplate->replaceIdentifier('newsletter_template_css', new Template("{$this->oNewsletter->getTemplateName()}.css", array(DIRNAME_TEMPLATES, 'newsletter'))); // Parse links differently in text RichtextUtil::$USE_ABSOLUTE_LINKS = LinkUtil::isSSL(); $oEMailContent = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($this->oNewsletter->getNewsletterBody())); RichtextUtil::$USE_ABSOLUTE_LINKS = null; // Replace add surrounding (body.tmpl) before content if exists. Template needs to contain a newsletter_content identifier if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME, "{$this->oNewsletter->getTemplateName()}.body.tmpl")) !== null) { $oEmailTemplate->replaceIdentifier('newsletter_content', new Template("{$this->oNewsletter->getTemplateName()}.body", array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME)), null, Template::LEAVE_IDENTIFIERS); } $oEmailTemplate->replaceIdentifier('newsletter_content', $oEMailContent, null, Template::LEAVE_IDENTIFIERS); $oEmailTemplate->replaceIdentifier('subject', $this->oNewsletter->getSubject()); $oEmailTemplate->replaceIdentifier('language', $this->oNewsletter->getLanguageId()); $oEmailTemplate->replaceIdentifier('newsletter_link', LinkUtil::absoluteLink($this->oNewsletter->getDisplayLink())); $oEmailTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate(null, $this->oNewsletter->getLanguageId())); $oEmailTemplate->replaceIdentifier('newsletter_timestamp', time()); // Process templates with each recipient, depending on whether recipient is object and object of Subscriber or string foreach ($this->aRecipients as $mRecipient) { $this->sendNewsletter($mRecipient, clone $oEmailTemplate); } return count($this->aInvalidEmails) === 0; }
public function allDocumentsByCategories() { $aResult = array(); // find files in media dirs - large files that cannot be uploaded with http $aCustomFiles = array(); $aMediaDirs = ResourceFinder::create()->addExpression('web', '/^(media|flash)$/')->addRecursion()->noCache()->returnObjects()->find(); foreach ($aMediaDirs as $oFileResource) { if ($oFileResource->isFile()) { $aCustomFiles[$oFileResource->getRelativePath()] = $oFileResource->getInstancePrefix() . $oFileResource->getRelativePath(); } } if (count($aCustomFiles) > 0) { $sCustomFiles = TranslationPeer::getString('wns.documents.custom_files'); $aResult[$sCustomFiles] = array_flip($aCustomFiles); } // find files in database ordered by category foreach (DocumentCategoryQuery::create()->filterByIsExternallyManaged(false)->orderByName()->find() as $oCategory) { $aDocuments = DocumentQuery::create()->useDocumentCategoryQuery()->filterByIsExternallyManaged(false)->endUse()->orderByDocumentCategoryId()->orderByName()->select(array('Id', 'Name'))->find(); foreach ($aDocuments as $aDocument) { $aResult[$oCategory->getName()][$aDocument['Id']] = $aDocument['Name']; } } $sWithoutCategory = TranslationPeer::getString('wns.documents.select_without_title'); foreach (self::getDocumentsWithoutCategoryId() as $iId => $sName) { $aResult[$sWithoutCategory][$iId] = $sName; } return $aResult; }
public function possibleTemplates() { $aResult = array(); foreach (ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, AdminModule::getType(), AdminModule::getNameByClassName('DashboardAdminModule'), DIRNAME_TEMPLATES, 'layouts', '/^[\\w_\\d-]+\\.tmpl$/')) as $oResource) { $aResult[] = $oResource->getFileName('.tmpl'); } return $aResult; }
public function __construct($aRequestPath) { parent::__construct($aRequestPath); // if(!Session::getSession()->isAuthenticated() || !Session::getSession()->getUser()->getIsBackendLoginEnabled()) { // throw new Exception("Not allowed"); // } array_unshift($aRequestPath, DIRNAME_WEB, ResourceIncluder::RESOURCE_TYPE_CSS); $this->oFile = ResourceFinder::findResourceObject($aRequestPath); }
public static function suite() { $oResult = new PHPUnit_Framework_TestSuite("ResourceFinder test suite"); foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) { if (StringUtil::endsWith($sFileName, "Tests.php") && (StringUtil::startsWith($sFileName, "ResourceFinder") || StringUtil::startsWith($sFileName, "FileResource") || StringUtil::startsWith($sFileName, "ResourceIncluder"))) { $oResult->addTestFile($sFilePath); } } return $oResult; }
public static function suite() { $oResult = new PHPUnit_Framework_TestSuite("Complete test suite"); foreach (ResourceFinder::getFolderContents(dirname(__FILE__)) as $sFileName => $sFilePath) { if (StringUtil::endsWith($sFileName, ".php") && StringUtil::startsWith($sFileName, "Test") && !StringUtil::startsWith($sFileName, "TestUtil") && $sFilePath !== __FILE__) { require_once $sFilePath; $oResult->addTest(call_user_func(array(substr($sFileName, 0, -strlen('.php')), "suite"))); } } return $oResult; }
public static function includeResources($oResourceIncluder = null) { if ($oResourceIncluder === null) { $oResourceIncluder = ResourceIncluder::defaultIncluder(); } $oResourceIncluder->startDependencies(); self::includeWidgetResources(true, $oResourceIncluder); $oCkEditor = ResourceFinder::findResourceObject(array('web', 'js', 'widget', 'ckeditor')); $oResourceIncluder->addCustomJs('CKEDITOR_BASEPATH = "' . $oCkEditor->getFrontendPath() . '/";'); $oResourceIncluder->addResource('widget/ckeditor/ckeditor.js'); }
public function getDisplayOptions() { $aResult = array(); foreach (ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, FrontendModule::getType(), FrontendModule::getNameByClassName('LoginFrontendModule'), DIRNAME_TEMPLATES, '/^[\\w_\\d-]+\\.tmpl$/')) as $oResource) { $sFileName = $oResource->getFileName('.tmpl'); if (strpos($sFileName, '_action_') !== false) { continue; } $aResult[$sFileName] = StringUtil::makeReadableName($sFileName); } return $aResult; }
public function renderFile() { $oTemplate = new Template("{$this->sModuleName}.{$this->sModuleType}.{$this->sResourceType}", array(DIRNAME_MODULES, $this->sModuleType, $this->sModuleName, DIRNAME_TEMPLATES)); $sContents = $oTemplate->render(); $sModuleClass = Module::getClassNameByTypeAndName($this->sModuleType, $this->sModuleName); if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_CSS && $sModuleClass::USE_NAMESPACED_CSS) { $oFile = ResourceFinder::findResourceObject(array(DIRNAME_MODULES, $this->sModuleType, $this->sModuleName, DIRNAME_TEMPLATES, "{$this->sModuleName}.{$this->sModuleType}.{$this->sResourceType}.tmpl")); NamespacedPreviewCssFileModule::processCSSContent($sContents, $oFile); } else { header("Content-Type: text/css;charset=" . Settings::getSetting('encoding', 'browser', 'utf-8')); print $sContents; } }
public function clearCaches() { $sPath = str_replace(array('${module}', '${key}'), '*', $this->file_name); $aPath = explode('/', $sPath); foreach ($aPath as &$sPathItem) { if (strpos($sPathItem, '*') !== false) { $sPathItem = '/^' . str_replace('\\*', '.+', preg_quote($sPathItem, '/')) . '$/'; } } $oFinder = ResourceFinder::create($aPath)->byExpressions()->searchMainOnly()->noCache(); foreach ($oFinder->find() as $sCachesFile) { unlink($sCachesFile); } }
public function setConnectionCharset($sAdapter, $sCharset, PDOConnection $oConnection = null) { if ($oConnection === null) { $oConnection = Propel::getConnection(); } $sCharset = self::convertEncodingNameToSql($sCharset); if (StringUtil::startsWith($sAdapter, 'mysql')) { $sAdapter = 'mysql'; } $sFile = ResourceFinder::create(array('data', 'sql', 'charset', "{$sAdapter}.dump"))->find(); if ($sFile === null) { return; } $sCharsetCode = file_get_contents($sFile); $sCharsetCode = str_replace('{{charset}}', $sCharset, $sCharsetCode); $oConnection->exec($sCharsetCode); }
public function renderFile() { $sCacheString = 'preview_' . $this->oDocumentType->getId() . '_' . $this->iSize; $oCache = new Cache($sCacheString, DIRNAME_IMAGES); LinkUtil::sendCacheControlHeaders($this->oDocumentType, $oCache); if ($oCache->entryExists() && !$oCache->isOlderThan($this->oDocumentType)) { header("Content-Type: " . self::MIME_TYPE); $oCache->passContents(true); exit; } $sFileName = "{$this->oDocumentType->getDocumentKind()}.png"; $sFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), ResourceIncluder::RESOURCE_TYPE_ICON, $sFileName)); if ($sFilePath === null) { $sFileName = 'default.png'; } $sFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), ResourceIncluder::RESOURCE_TYPE_ICON, $sFileName)); if ($sFilePath === null) { throw new Exception("Error in DocumentTypePreviewFileModule->renderFile: type has unknown kind: {$this->oDocumentType->getDocumentKind()}"); } $sFontFilePath = ResourceFinder::findResource(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), 'PTS55F.ttf')); $oImage = Image::imageFromPath($sFilePath); if (Image::supportsText()) { $sText = strtoupper($this->oDocumentType->getExtension()); $fFontSize = 72.0; $aSize = Image::textSize($sFontFilePath, $sText, $fFontSize); $iDesiredWidth = 300; $iDesiredHeight = 145; $fWidthRatio = $iDesiredWidth / $aSize[0]; $fHeightRatio = $iDesiredHeight / $aSize[1]; $fRatio = min($fWidthRatio, $fHeightRatio); $fFontSize *= $fRatio; $iDesiredPositionX = 107 - 7 * $fRatio; $iDesiredPositionY = 338; $iStartPositionX = $iDesiredPositionX + ($iDesiredWidth - $aSize[0] * $fRatio) / 2; $iStartPositionY = $iDesiredPositionY + $aSize[1] * $fRatio + ($iDesiredHeight - $aSize[1] * $fRatio) / 2; $oImage->addText($sFontFilePath, $sText, 1, $fFontSize, 150, 150, 150, $iStartPositionX, $iStartPositionY); } if ($this->iSize < 512) { $oImage->setSize($this->iSize, $this->iSize, Image::STRETCH); } $oImage->setFileType('png'); $oImage->render(true, null, $oCache); exit; }
/** * if possible, reads the file php_error.php in the site/lib directory and outputs it as an error message. * This is called from the handleError and handleException methods if the error was not output directly to screen (like in the test environment) and could not be recovered from. If the file does not exist, it will output the text "An Error occured, exiting" */ public static function displayErrorMessage($aError, $bMayPrintDetailedMessage = false) { while (ob_get_level() > 0) { ob_end_clean(); } $sErrorFilePath = ResourceFinder::create(DIRNAME_LIB . '/php_error.php')->noCache()->find(); header('HTTP/1.0 500 Internal Server Error'); header('Expires: 0'); if (!$sErrorFilePath || !file_exists($sErrorFilePath)) { header('Content-Type: text/plain;charset=utf-8'); $sMessage = $aError['message']; if (!$bMayPrintDetailedMessage) { $sMessage = "An Error occured, exiting"; } die($sMessage); } header('Content-Type: text/html;charset=utf-8'); include $sErrorFilePath; exit; }
/** * renderFile() * @return string xhtml output */ public function renderFile() { $oOutput = new XHTMLOutput(XHTMLOutput::SETTING_HTML_4_TRANSITIONAL, true, null, $this->oNewsletter->getLanguageId()); $oOutput->render(); $oNewsletterTemplate = new Template('main_display', array(DIRNAME_TEMPLATES, 'newsletter'), false, true); $oNewsletterTemplate->replaceIdentifier('newsletter_template_css', new Template("{$this->oNewsletter->getTemplateName()}.css", array(DIRNAME_TEMPLATES, 'newsletter'))); $oNewsletterContent = RichtextUtil::parseStorageForFrontendOutput(stream_get_contents($this->oNewsletter->getNewsletterBody())); if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME, "{$this->oNewsletter->getTemplateName()}.body.tmpl")) !== null) { $oNewsletterTemplate->replaceIdentifier('newsletter_content', new Template("{$this->oNewsletter->getTemplateName()}.body", array(DIRNAME_TEMPLATES, NewsletterDetailWidgetModule::NEWSLETTER_DIRNAME)), null, Template::LEAVE_IDENTIFIERS); } $oNewsletterTemplate->replaceIdentifier('newsletter_content', $oNewsletterContent, null, Template::LEAVE_IDENTIFIERS); $oNewsletterTemplate->replaceIdentifier('language', $this->oNewsletter->getLanguageId()); if ($this->oMailing !== null) { $oNewsletterTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate($this->oMailing->getDateSent(null)->getTimestamp(), $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('newsletter_timestamp', $this->oMailing->getDateSent(null)->getTimestamp()); } else { $oNewsletterTemplate->replaceIdentifier('newsletter_date', LocaleUtil::localizeDate($this->oNewsletter->getCreatedAt(null)->getTimestamp(), $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('newsletter_timestamp', $this->oNewsletter->getCreatedAt(null)->getTimestamp()); } $oNewsletterTemplate->replaceIdentifier('recipient', TranslationPeer::getString('wns.newsletter.recipient', $this->oNewsletter->getLanguageId())); $oNewsletterTemplate->replaceIdentifier('subject', $this->oNewsletter->getSubject()); $oNewsletterTemplate->render(); }
<?php /** * @package test */ require_once 'base/lib/inc.php'; Cache::clearAllCaches(); spl_autoload_register(function ($sClassName) { $sFileName = "{$sClassName}.php"; $sPath = ResourceFinder::create()->addPath(DIRNAME_LIB, 'tests', $sFileName)->find(); if ($sPath !== null) { require $sPath; return true; } });
public function getMatchingCustomTemplates($aPostfix = array(self::CONTENT_TEMPLATE_SUFFIX, self::CSS_TEMPLATE_SUFFIX)) { $aMatchingTemplates = array(); $aTemplateList = ResourceFinder::findResourcesByExpressions(array(DIRNAME_TEMPLATES, self::NEWSLETTER_DIRNAME, '/.+.content.tmpl/')); foreach ($aTemplateList as $sTemplateShortPath => $sTemplatePath) { $sTemplateName = substr($sTemplateShortPath, 0, -strlen(self::CONTENT_TEMPLATE_SUFFIX . '.tmpl')); $sTemplateName = substr($sTemplateName, strlen(DIRNAME_TEMPLATES . '/' . self::NEWSLETTER_DIRNAME . '/')); if (ResourceFinder::findResource(array(DIRNAME_TEMPLATES, self::NEWSLETTER_DIRNAME, "{$sTemplateName}.css.tmpl")) !== null) { $aMatchingTemplates[$sTemplateName] = $sTemplateName; } } return $aMatchingTemplates; }
public static function getInstance($sFile = null) { if ($sFile === null) { $sFile = "config"; } $sCacheKey = self::createCacheKey($sFile); $sFileName = "{$sFile}.yml"; if (!isset(self::$INSTANCES[$sCacheKey])) { $oCache = new Cache($sCacheKey, DIRNAME_CONFIG, CachingStrategyFile::create()); $oFinder = ResourceFinder::create(array(DIRNAME_CONFIG))->addOptionalPath(ErrorHandler::getEnvironment())->addPath($sFileName)->byExpressions()->searchBaseFirst()->all(); if ($oCache->entryExists() && !$oCache->isOutdated($oFinder)) { self::$INSTANCES[$sCacheKey] = $oCache->getContentsAsVariable(); } else { self::$INSTANCES[$sCacheKey] = new Settings($oFinder, $sFile); $oCache->setContents(self::$INSTANCES[$sCacheKey]); } } return self::$INSTANCES[$sCacheKey]; }
public static function getAvailableResource($sModuleName, $sModuleType, $sResourceType, $aParameters) { if ($aParameters === null) { $aParameters = array(); } $sFileModule = str_replace('template_', "{$sModuleType}_", self::getNameByClassName(get_class())); $sFileName = "{$sModuleName}.{$sModuleType}.{$sResourceType}.tmpl"; if (ResourceFinder::findResource(array(DIRNAME_MODULES, $sModuleType, $sModuleName, DIRNAME_TEMPLATES, "{$sFileName}")) === null) { return null; } return LinkUtil::link(array($sFileModule, $sResourceType, $sModuleName), 'FileManager', $aParameters); }
public static function listTemplates($mDirName = DIRNAME_TEMPLATES, $bListSubdirs = false, $bFlag = null) { $aResult = array(); if (!is_array($mDirName)) { $mDirName = explode("/", $mDirName); } $aDirectories = ResourceFinder::findResource($mDirName, $bFlag, false, true); foreach ($aDirectories as $sDirectory) { if ($iTemplatesDir = opendir($sDirectory)) { while (false !== ($sFileName = readdir($iTemplatesDir))) { if (strpos($sFileName, ".tmpl") === strlen($sFileName) - strlen(".tmpl") && is_file("{$sDirectory}/{$sFileName}")) { $aResult[] = substr($sFileName, 0, strlen($sFileName) - strlen(".tmpl")); } else { if (is_dir($sDirectory . "/" . $sFileName) && strpos($sFileName, ".") !== 0 && $bListSubdirs) { $aDirName = $mDirName; $aDirName[] = $sFileName; $aSubItems = self::listTemplates($aDirName, true); foreach ($aSubItems as $sSubItem) { $aResult[] = "{$sFileName}/{$sSubItem}"; } } } } closedir($iTemplatesDir); } } return array_unique($aResult); }
private static function getPluginPaths($bReverseOrder = false) { if (self::$PLUGINS === null) { self::$PLUGINS = array_map(function ($oPart) { return MAIN_DIR . '/' . $oPart->getPrefix(); }, PluginPart::allPlugins()); } if ($bReverseOrder === true) { return array_reverse(self::$PLUGINS); } return self::$PLUGINS; }
public function listTemplateSets() { $aResult = array(); foreach (ResourceFinder::create(array(DIRNAME_MODULES, self::getType(), $this->getModuleName(), DIRNAME_TEMPLATES))->addDirPath()->returnObjects()->find() as $oSet) { $aResult[$oSet->getFileName()] = TranslationPeer::getString('journal.template_set_' . $oSet->getFileName(), null, StringUtil::makeReadableName($oSet->getFileName())); } return array('options' => $aResult, 'current' => $this->sTemplateSet); }
public function addResource($mLocation, $sResourceType = null, $sIdentifier = null, $aExtraInfo = null, $iPriority = self::PRIORITY_NORMAL, $sIeCondition = null, $bIncludeAll = false, $bEndsDependencyList = false) { //Not allowed if ($bIncludeAll && $sIdentifier !== null) { $sIdentifier = null; } $sResourcePrefix = self::RESOURCE_PREFIX_EXTERNAL; $mFileResource = null; $sFinalLocation = null; if ($mLocation instanceof FileResource) { //FileResource given (internal) $mFileResource = $mLocation; } else { if (is_array($mLocation)) { //Array given, relative -> convert to FileResource (internal) if ($bIncludeAll) { $mFileResource = ResourceFinder::findAllResourceObjects($mLocation); } else { $mFileResource = ResourceFinder::findResourceObject($mLocation); } } else { if ($mLocation instanceof NavigationItem) { $sFinalLocation = LinkUtil::link($mLocation->getLink(), 'FrontendManager'); $sResourcePrefix = self::RESOURCE_PREFIX_INTERNAL; if ($sResourceType === null) { $sResourceType = self::RESOURCE_TYPE_LINK; } } else { if (!is_string($mLocation)) { //Unknown input type given -> throw Exception throw new Exception("Eror in ResourceIncluder->addResource(): given location {$mLocation} is in unknown format"); } else { if (preg_match('/\\w+\\:/', $mLocation) !== 0 || StringUtil::startsWith($mLocation, '//')) { //Absolute URL given with protocol -> set Location directly (external) $sFinalLocation = $mLocation; } else { if (StringUtil::startsWith($mLocation, '/')) { //Absolute location given -> check if it’s a path or a URL if (file_exists($mLocation)) { //Path given -> convert to FileResource (internal) $mFileResource = new FileResource($mLocation); } else { //URL given, set Location directly (external) $sFinalLocation = $mLocation; } } else { //Relative location can be given with resource type, and without resource type (which will then be determined by extension) $aLocation = explode('/', $mLocation); if ($sResourceType === null) { $sResourceType = $this->findResourceTypeForLocation($aLocation[count($aLocation) - 1]); } array_unshift($aLocation, DIRNAME_WEB, $sResourceType); if ($bIncludeAll) { $mFileResource = ResourceFinder::findAllResourceObjects($aLocation); } else { $mFileResource = ResourceFinder::findResourceObject($aLocation); } } } } } } } if ($sFinalLocation === null && $mFileResource === null && !$bIncludeAll) { if (is_array($mLocation)) { $mLocation = implode('/', $mLocation); } throw new Exception("Error in ResourceIncluder->addResource(): Specified internal file {$mLocation} could not be found."); } if (!is_array($mFileResource)) { $mFileResource = array($mFileResource); } if ($aExtraInfo === null) { $aExtraInfo = array(); } foreach ($mFileResource as $oFileResource) { $aExtraInfoForResource = $aExtraInfo; if ($sFinalLocation === null) { $sFinalLocation = $oFileResource->getFrontendPath(); $sResourcePrefix = self::RESOURCE_PREFIX_INTERNAL; } if ($sResourceType === null) { $sResourceType = $this->findResourceTypeForLocation($sFinalLocation); } if ($sIdentifier === null) { $sIdentifier = $sResourcePrefix . $sFinalLocation; } if (StringUtil::startsWith($sFinalLocation, '/') && !StringUtil::startsWith($sFinalLocation, '//')) { // This will actually only convert to an absolute URL if linking/always_link_absolutely is true // or linking/ssl_in_absolute_links requests a different protocol than currently employed $sFinalLocation = LinkUtil::absoluteLink($sFinalLocation, null, 'default', true); } $aExtraInfoForResource['location'] = $sFinalLocation; if (!isset($aExtraInfoForResource['resource_type'])) { $aExtraInfoForResource['resource_type'] = $sResourceType; } if (!isset($aExtraInfoForResource['template'])) { $aExtraInfoForResource['template'] = $sResourceType; } if ($sIeCondition !== null && !isset($aExtraInfoForResource['ie_condition'])) { $aExtraInfoForResource['ie_condition'] = $sIeCondition; } if (!isset($aExtraInfoForResource['dependees'])) { $aExtraInfoForResource['dependees'] = array(); } if ($oFileResource instanceof FileResource && !isset($aExtraInfoForResource['file_resource'])) { $aExtraInfoForResource['file_resource'] = $oFileResource; } if ($bEndsDependencyList) { $this->endDependencyList($sIdentifier); } if (($iPrevResoucePriority = $this->containsResource($sIdentifier)) !== false) { $aExtraInfoForResource = array_merge($this->aIncludedResources[$iPrevResoucePriority][$sIdentifier], $aExtraInfoForResource); $aExtraInfoForResource['dependees'] = array_merge($this->aIncludedResources[$iPrevResoucePriority][$sIdentifier]['dependees'], $aExtraInfoForResource['dependees']); unset($this->aIncludedResources[$iPrevResoucePriority][$sIdentifier]); } //Include resource $this->aIncludedResources[$iPriority][$sIdentifier] = $aExtraInfoForResource; //move down all dependent resources that already exist if (isset($aExtraInfoForResource['dependees'])) { $this->moveDependees($aExtraInfoForResource['dependees'], $sIdentifier); } //Add dependency $this->registerAsDependency($sIdentifier); $sFinalLocation = null; $sIdentifier = null; } }
private function fileInfo($sPath, $sFullPath) { // create result array $aInfo = array(); // TODO remove slash append code when base class is able to do it itself $aInfo["path"] = str_replace(rawurlencode('/'), '/', rawurlencode($sPath)); $aInfo["path"] = is_dir($sFullPath) ? $this->_slashify($aInfo["path"]) : $aInfo["path"]; $aInfo["props"] = array(); // no special beautified displayname here ... $aInfo["props"][] = $this->mkprop("displayname", rawurlencode(basename($sPath))); // creation and modification time $aInfo["props"][] = $this->mkprop("creationdate", filectime($sFullPath)); $aInfo["props"][] = $this->mkprop("getlastmodified", filemtime($sFullPath)); // type and size (caller already made sure that path exists) if (is_dir($sFullPath)) { // directory (WebDAV collection) $aInfo["props"][] = $this->mkprop("resourcetype", "collection"); $aInfo["props"][] = $this->mkprop("getcontenttype", "application/x-directory"); } else { // plain file (WebDAV resource) $aInfo["props"][] = $this->mkprop("resourcetype", ""); if (is_readable($sFullPath)) { $aInfo["props"][] = $this->mkprop("getcontenttype", ResourceFinder::mimeTypeOfFile($sFullPath)); } else { $aInfo["props"][] = $this->mkprop("getcontenttype", "application/x-non-readable"); } $aInfo["props"][] = $this->mkprop("getcontentlength", filesize($sFullPath)); } return $aInfo; }
public function testCSSRewriteWhenUsingSSL() { Settings::addOverride('domain_holder', 'domain', '2.example.com'); Settings::addOverride('linking', 'prefer_configured_domain', true); Settings::addOverride('linking', 'always_link_absolutely', false); Settings::addOverride('linking', 'ssl_in_absolute_links', true); $this->oIncluder->addResource('ResourceIncluderConsolidationTests.css'); $oFile = ResourceFinder::create()->returnObjects()->addPath('web', 'css', 'ResourceIncluderConsolidationTests.css')->find(); $this->oIncluder->getIncludes(true, true)->render(); $sContents = self::$CACHED_INCLUDE->getContentsAsString(); $this->assertSame(<<<EOT @import url("https://2.example.com/plugins/test_only/web/css/fineprint.css") print; @import url("chrome://communicator/skin/"); @import url("//example.com/skin/"); @import "http://example.com/skin1/"; @import 'http://example.com/skin2/'; @import url('https://2.example.com/plugins/test_only/web/landscape.css') screen and (orientation:landscape); @font-face { \tfont-family: "WebFont"; \tsrc: local('test'), url("https://2.example.com/plugins/test_only/web/fonts/WebFont.woff") format('woff') \t url('https://2.example.com/plugins/test_only/web/css/fonts:media/WebFont.eot'); } html { \tbackground-image: url('https://2.example.com/plugins/test_only/web/images/test.png'); } EOT , $sContents); }
public function testNoRecursivePathItemByExpression() { $aConfigPaths = ResourceFinder::findAllResourcesByExpressions(array(DIRNAME_WEB, 'css', array(null), '/^.+\\.custom\\.css$/'), ResourceFinder::SEARCH_BASE_ONLY); $this->assertSame(array(), $aConfigPaths); }
function find_files($sType) { global $iResourceFinderFlags; return array_merge(ResourceFinder::create($iResourceFinderFlags)->addPath(DIRNAME_WEB)->addRecursion()->addExpression('/^.+\\.' . $sType . '$/')->noCache()->all()->find(), ResourceFinder::create($iResourceFinderFlags)->addOptionalPath(DIRNAME_MODULES, '/^(widget|admin)$/', false)->addPath(DIRNAME_TEMPLATES)->addRecursion()->addExpression('/\\.' . $sType . '\\.tmpl$/')->noCache()->all()->find()); }
public static function listModuleTypes() { if (self::$MODULE_TYPE_LIST === null) { $aPaths = ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN)); self::$MODULE_TYPE_LIST = array(); foreach ($aPaths as $oPath) { self::$MODULE_TYPE_LIST[] = $oPath->getFileName(); } } return self::$MODULE_TYPE_LIST; }
public static function allParts() { $oCache = new Cache("system_parts", DIRNAME_CONFIG, CachingStrategyFile::create()); if ($oCache->entryExists()) { return $oCache->getContentsAsVariable(); } $oBasePart = new BasePart(); $oSitePart = new SitePart(); $aParts = array(DIRNAME_BASE => $oBasePart); // Get all plugins foreach (ResourceFinder::pluginFinder()->returnObjects()->find() as $oPath) { $oPluginPart = SystemPart::getPart($oPath->getRelativePath()); // Plugins depend on base implicitly $oPluginPart->dependOn($oBasePart); // Site depends on plugins implicitly $oSitePart->dependOn($oPluginPart); $aParts[$oPath->getRelativePath()] = $oPluginPart; } $oSitePart->dependOn($oBasePart); $aParts[DIRNAME_SITE] = $oSitePart; // Add dependencies from info foreach ($aParts as $oPart) { $aInfo = $oPart->getInfo(); foreach ($aInfo['dependencies'] as $sDependencyPrefix => $sVersion) { if (isset($aParts[$sDependencyPrefix])) { $oPart->dependOn($aParts[$sDependencyPrefix]); } else { throw new Exception("Dependency of {$oPart->getPrefix()} on {$sDependencyPrefix} can not be satisfied"); } } foreach ($aInfo['optional_dependencies'] as $sDependencyPrefix => $sVersion) { if (isset($aParts[$sDependencyPrefix])) { $oPart->dependOn($aParts[$sDependencyPrefix]); } } } // Order list by dependencies $aParts = self::orderedParts($aParts); // Cache ordered list $oCache->setContents($aParts); return $aParts; }