예제 #1
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;
 }
예제 #2
0
 /**
  * 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];
 }
예제 #3
0
 public function __construct($sSessionKey = null, $sModuleContents = null, $mModuleSettings = null)
 {
     parent::__construct($sSessionKey);
     $this->sModuleContents = $sModuleContents;
     if ($mModuleSettings === null || is_string($mModuleSettings)) {
         $this->aModuleSettings = Settings::getSetting('text_module', null, array());
         if ($mModuleSettings !== null) {
             $this->aModuleSettings = array_merge($this->aModuleSettings, Settings::getSetting($mModuleSettings, 'text_module', array()));
         }
     } else {
         $this->aModuleSettings = $mModuleSettings;
     }
     $this->cleanupCss();
     $this->cleanupStyles();
     $this->cleanupFormatTags();
     $this->cleanupInsertableParts();
     $this->cleanupToolbar();
     foreach ($this->aModuleSettings as $sKey => $mSetting) {
         $this->setSetting($sKey, $mSetting);
     }
     // let CKEDITOR find plugins
     $aPlugins = array();
     foreach (ResourceFinder::create()->addPath(DIRNAME_WEB, ResourceIncluder::RESOURCE_TYPE_JS, 'widget', 'ckeditor-plugins')->addDirPath()->addRecursion()->addPath('plugin.js')->returnObjects()->find() as $oPluginPath) {
         $oPluginPath = $oPluginPath->parent();
         $aPlugins[$oPluginPath->getFileName()] = $oPluginPath->getFrontendPath() . '/';
     }
     if (count($aPlugins) === 0) {
         $aPlugins = null;
     }
     $this->setSetting('additional_plugin_paths', $aPlugins);
     $this->setSetting('language', Session::language());
 }
예제 #4
0
 public function possibleRestoreFiles()
 {
     $aAllSqlFiles = ResourceFinder::create(array(DIRNAME_DATA, "sql", "/.*\\.sql\$/"))->byExpressions()->noCache()->returnObjects()->find();
     $aResult = array();
     $this->iFileSizeOfSiteDir = 0;
     foreach ($aAllSqlFiles as $oFile) {
         if (StringUtil::startsWith($oFile->getInternalPath(), 'site')) {
             $this->iFileSizeOfSiteDir += filesize(MAIN_DIR . '/' . $oFile->getInternalPath());
         }
         $aResult[$oFile->getFileName()] = $oFile->getInternalPath();
     }
     arsort($aResult);
     return $aResult;
 }
예제 #5
0
 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);
     }
 }
예제 #6
0
 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);
 }
예제 #7
0
 /**
  * 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;
 }
 public function renderFile()
 {
     $iTemplateFlags = 0;
     $oResourceFinder = ResourceFinder::create(array(DIRNAME_MODULES, $this->sModuleType, $this->sModuleName, DIRNAME_TEMPLATES))->returnObjects();
     $sFileName = "{$this->sModuleName}.{$this->sModuleType}.{$this->sResourceType}";
     $oResourceFinder->addPath($sFileName . Template::$SUFFIX);
     if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_CSS) {
         header("Content-Type: text/css;charset=utf-8");
         $oResourceFinder->all();
     } else {
         if ($this->sResourceType === ResourceIncluder::RESOURCE_TYPE_JS) {
             header("Content-Type: text/javascript;charset=utf-8");
             $iTemplateFlags = Template::ESCAPE | Template::NO_HTML_ESCAPE;
         } else {
             header("Content-Type: text/html;charset=utf-8");
         }
     }
     $oCache = new Cache('template_resource-' . $sFileName . '-' . Session::language(), 'resource');
     $oTemplate = null;
     if ($oCache->entryExists() && !$oCache->isOutdated($oResourceFinder)) {
         $oCache->sendCacheControlHeaders();
         $oTemplate = $oCache->getContentsAsVariable();
     } else {
         $oTemplate = new Template(TemplateIdentifier::constructIdentifier('contents'), null, true, false, null, $sFileName);
         $aResources = $oResourceFinder->find();
         if (!$aResources) {
             $aResources = array();
         }
         if ($aResources instanceof FileResource) {
             $aResources = array($aResources);
         }
         foreach ($aResources as $oResource) {
             $oSubTemplate = new Template($oResource, null, false, false, null, null, $iTemplateFlags);
             $oTemplate->replaceIdentifierMultiple('contents', $oSubTemplate, null, Template::LEAVE_IDENTIFIERS);
         }
         $oCache->setContents($oTemplate);
         $oCache->sendCacheControlHeaders();
     }
     print $oTemplate->render();
 }
예제 #9
0
 /**
  * Returns info schema. Either given at construction time, loaded from YAML or generated on-the-fly
  */
 public function getInfo()
 {
     if ($this->aInfo === null) {
         $sInfoFilePath = ResourceFinder::create($this->sPrefix)->mainOnly()->addPath(FILENAME_INFO)->find();
         if ($sInfoFilePath) {
             require_once BASE_DIR . '/' . DIRNAME_LIB . '/' . DIRNAME_VENDOR . '/' . "spyc/Spyc.php";
             $this->aInfo = Spyc::YAMLLoad($sInfoFilePath);
         } else {
             $this->aInfo = array();
         }
         if (!isset($this->aInfo['name'])) {
             $this->aInfo['name'] = implode(' ', explode('/', $this->sPrefix));
         }
         if (!isset($this->aInfo['dependencies'])) {
             $this->aInfo['dependencies'] = array();
         }
         if (!isset($this->aInfo['optional_dependencies'])) {
             $this->aInfo['optional_dependencies'] = array();
         }
     }
     return $this->aInfo;
 }
예제 #10
0
 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];
 }
예제 #11
0
 public function adminGetContainers()
 {
     $oTemplate = $this->oPage->getTemplate();
     foreach ($oTemplate->identifiersMatching('container', Template::$ANY_VALUE) as $oIdentifier) {
         $oInheritedFrom = null;
         $sContainerName = $oIdentifier->getValue();
         if (BooleanParser::booleanForString($oIdentifier->getParameter('inherit'))) {
             $oInheritedFrom = $this->oPage;
             $iInheritedObjectCount = 0;
             while ($iInheritedObjectCount === 0 && ($oInheritedFrom = $oInheritedFrom->getParent()) !== null) {
                 $iInheritedObjectCount = $oInheritedFrom->countObjectsForContainer($sContainerName);
             }
         }
         $sInheritedFrom = $oInheritedFrom ? $oInheritedFrom->getName() : '';
         $aTagParams = array('class' => 'template-container template-container-' . $sContainerName, 'data-container-name' => $sContainerName, 'data-container-string' => TranslationPeer::getString('container_name.' . $sContainerName, null, $sContainerName), 'data-inherited-from' => $sInheritedFrom);
         $oContainerTag = TagWriter::quickTag('ol', $aTagParams);
         $mInnerTemplate = new Template(TemplateIdentifier::constructIdentifier('content'), null, true);
         //Replace container info
         //…name
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-description'), TranslationPeer::getString('wns.page.template_container', null, null, array('container' => TranslationPeer::getString('template_container.' . $sContainerName, null, $sContainerName)), true)));
         //…additional info
         $mInnerTemplate->replaceIdentifierMultiple('content', TagWriter::quickTag('div', array('class' => 'template-container-info')));
         //…tag
         $mInnerTemplate->replaceIdentifierMultiple('content', $oContainerTag);
         //Replace actual container
         $oTemplate->replaceIdentifier($oIdentifier, $mInnerTemplate);
     }
     $bUseParsedCss = Settings::getSetting('admin', 'use_parsed_css_in_config', true);
     $oStyle = null;
     if ($bUseParsedCss) {
         $sTemplateName = $this->oPage->getTemplateNameUsed() . Template::$SUFFIX;
         $sCacheKey = 'parsed-css-' . $sTemplateName;
         $oCssCache = new Cache($sCacheKey, DIRNAME_PRELOAD);
         $sCssContents = "";
         if (!$oCssCache->entryExists() || $oCssCache->isOutdated(ResourceFinder::create(array(DIRNAME_TEMPLATES, $sTemplateName)))) {
             $oIncluder = new ResourceIncluder();
             foreach ($oTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) {
                 $oIncluder->addResourceFromTemplateIdentifier($oIdentifier);
             }
             foreach ($oIncluder->getAllIncludedResources() as $sIdentifier => $aResource) {
                 if ($aResource['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS && !isset($aResource['ie_condition']) && !isset($aResource['frontend_specific'])) {
                     if (isset($aResource['media'])) {
                         $sCssContents .= "@media {$aResource['media']} {";
                     }
                     if (isset($aResource['file_resource'])) {
                         $sCssContents .= file_get_contents($aResource['file_resource']->getFullPath());
                     } else {
                         // Absolute link, requires fopen wrappers
                         $sCssContents .= file_get_contents($aResource['location']);
                     }
                     if (isset($aResource['media'])) {
                         $sCssContents .= "}";
                     }
                 }
             }
             $oParser = new Sabberworm\CSS\Parser($sCssContents, Sabberworm\CSS\Settings::create()->withDefaultCharset(Settings::getSetting("encoding", "browser", "utf-8")));
             $oCss = $oParser->parse();
             $this->cleanupCSS($oCss);
             $sCssContents = Template::htmlEncode($oCss->render(Sabberworm\CSS\OutputFormat::createCompact()));
             $oCssCache->setContents($sCssContents);
         } else {
             $sCssContents = $oCssCache->getContentsAsString();
         }
         $oStyle = new HtmlTag('style');
         $oStyle->addParameters(array('scoped' => 'scoped'));
         $oStyle->appendChild($sCssContents);
     }
     $sTemplate = $oTemplate->render();
     $sTemplate = substr($sTemplate, strpos($sTemplate, '<body') + 5);
     $sTemplate = substr($sTemplate, strpos($sTemplate, '>') + 1);
     $sTemplate = substr($sTemplate, 0, strpos($sTemplate, '</body'));
     $oParser = new TagParser("<body>{$sTemplate}</body>");
     $oTag = $oParser->getTag();
     $this->cleanupContainerStructure($oTag);
     if ($bUseParsedCss) {
         $oTag->appendChild($oStyle);
     }
     $sResult = $oTag->__toString();
     $sResult = substr($sResult, strpos($sResult, '<body>') + 6);
     $sResult = substr($sResult, 0, strrpos($sResult, '</body>'));
     return array('html' => $sResult, 'css_parsed' => $bUseParsedCss);
 }
예제 #12
0
 private function checkStaticStrings($sCheckLanguageId = null, $sDirectory = null)
 {
     $aPaths = array();
     if ($sDirectory === null || $sDirectory === 'base') {
         $aPaths[] = array('base');
     }
     if ($sDirectory === null || $sDirectory === 'plugins') {
         foreach (ResourceFinder::create(array(DIRNAME_PLUGINS, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN))->searchMainOnly()->byExpressions()->find() as $sPlugin => $sDir) {
             $aPaths[] = explode('/', $sPlugin);
         }
     }
     if ($sDirectory === null || $sDirectory === 'site') {
         $aPaths[] = array('site');
     }
     foreach ($aPaths as $aPath) {
         $this->log(TranslationPeer::getString('wns.check.check_static_strings_title', null, null, array('path_prefix' => implode('/', $aPath))), null, 'title_main_dir');
         $aLanguagesInContextDir = array();
         $aLanguageFiles = ResourceFinder::create($aPath)->addRecursion()->addPath(DIRNAME_LANG)->addExpression("/^.+\\.ini\$/")->noCache()->returnObjects()->searchMainOnly()->find();
         foreach ($aLanguageFiles as $oLanguageFile) {
             $sLanguageId = $oLanguageFile->getFileName('.ini');
             $aLanguagesInContextDir[$sLanguageId] = true;
         }
         $aLanguagesInContextDir = array_keys($aLanguagesInContextDir);
         $aLanguageDirs = ResourceFinder::create($aPath)->addRecursion()->addPath(DIRNAME_LANG)->noCache()->returnObjects()->searchMainOnly()->find();
         foreach ($aLanguageDirs as $oDir) {
             $this->log(TranslationPeer::getString('wns.check.check_static_strings_dir', null, null, array('dir' => $oDir->getRelativePath())), null, 'title_dir');
             $aDir = explode('/', $oDir->getRelativePath());
             $aStrings = array();
             foreach ($aLanguagesInContextDir as $sLanguageId) {
                 $sFile = ResourceFinder::create($aDir)->addPath("{$sLanguageId}.ini")->searchMainOnly()->find();
                 if (!$sFile) {
                     continue;
                 }
                 $aContents = parse_ini_file($sFile);
                 foreach ($aContents as $sStringKey => $sString) {
                     if (!isset($aStrings[$sStringKey])) {
                         $aStrings[$sStringKey] = array();
                     }
                     $aStrings[$sStringKey][$sLanguageId] = $sString;
                 }
             }
             foreach ($aStrings as $sStringKey => &$aStringLanguages) {
                 foreach ($aLanguagesInContextDir as $sLanguageId) {
                     if ($sCheckLanguageId !== null && $sLanguageId !== $sCheckLanguageId) {
                         continue;
                     }
                     if (!isset($aStringLanguages[$sLanguageId])) {
                         $this->log($sStringKey, $sLanguageId, self::LOG_LEVEL_WARNING);
                     }
                 }
             }
         }
     }
     return $this->aLogMessages;
 }
    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);
    }
예제 #14
0
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 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);
 }
예제 #16
0
 /**
  * Finds files which reside inside the CMS’ main direcory. The goal of findResource is to provide a way of accessing all the desired resources from
  * the most specific location. Files in the site folder override files in the plugins folders which, in turn, override files in the base folder.
  * The return type varies depending on the given options ($bByExpressions, $bFindAll, $bReturnObjects).
  * If $bReturnObjects is false, the returned value(s) will be strings containing the files canonical full path on the file system.
  * $bReturnObjects set to true will return FileResource objects which store much more information and can be used to get to things such as the 
  * relative path, the directory the relative path was found in, or the frontend path which is used to directly render a file to the user agent.
  * If $bByExpressions and $bFindAll are set to false, only a single string/object is returned (null if not found). Otherwise, an array is returned.
  * If $bFindAll is set, the returned array is index-based; if only $bByExpressions is set, the returned array’s keys are the relative paths of the respective files.
  * @param array|string $mRelativePath relative path to search for in base, plugins or site folders. This can be an array or a string of /-separated directory/file names (or expressions if $bByExpressions is true).
  * @param int $iFlag can be one of either ResourceFinder::SEARCH_MAIN_ONLY, ResourceFinder::SEARCH_BASE_ONLY, ResourceFinder::SEARCH_SITE_ONLY, ResourceFinder::SEARCH_PLUGINS_ONLY, ResourceFinder::SEARCH_BASE_FIRST, ResourceFinder::SEARCH_SITE_FIRST, ResourceFinder::SEARCH_PLUGINS_FIRST. The *_ONLY constants are – except for SEARCH_PLUGINS_ONLY – just for convenience: since they only find files in specific directories, you might just as well do file_exists(MAIN_DIR.'my/dir').
  * @param boolean $bByExpressions If set, $mRelativePath becomes not a fixed set of names but an array of regular expressions to evaluate against possible matches. This is slow when used on large directories. There are the following values which can be used as part of the expression: ${parent_name} and ${parent_name_camelized} which do exactly what you would expect. For convenience, any array item not starting with a slash is considered to be a regular file name. This means that a slash is the only accepted delimiter. In addition to regular strings and expressions, you can also pass null for a complete wildcard, true to match all files and false for a wildcard matching only directories. Any expression item packed into an array will be optional. An empty array (as an item of $mRelativePath) will match all items recursively (should not be used in frontend-production environments).
  * @param boolean $bFindAll If set, all matching files will be returned even if they have the same relative path inside different instance prefixes. Note: when used in conjunction with $bByExpressions, the return value becomes an index-based array since there could be duplicate relative urls.
  * @param boolean $bReturnObjects If set, all returned paths become FileResource objects. This is much cheaper than calling new FileResource() on the returned value(s) because a) FileResource objects are used internally by findResource and b) the additional information maintained by FileResource was added when it was already known and does not have to be deducted.
  * @return mixed
  */
 public static function findResource($mRelativePath, $iFlag = null, $bByExpressions = false, $bFindAll = false, $bReturnObjects = false)
 {
     if ($mRelativePath instanceof ResourceFinder) {
         return $mRelativePath->find();
     }
     if (is_array($mRelativePath) && array_key_exists('flag', $mRelativePath)) {
         $iFlag = constant("ResourceFinder::" . $mRelativePath['flag']);
         unset($mRelativePath['flag']);
     }
     return ResourceFinder::create($mRelativePath, $iFlag)->byExpressions($bByExpressions)->all($bFindAll)->returnObjects($bReturnObjects)->find();
 }
예제 #17
0
 public static function groupedSchemaXml()
 {
     $aSchemas = array();
     $aSchemaFiles = ResourceFinder::create(array(DIRNAME_CONFIG))->addExpression(self::SCHEMA_FILE_PATTERN)->noCache()->all()->returnObjects()->find();
     foreach ($aSchemaFiles as $oSchemaFile) {
         $sSchemaName = self::schemaNameFromFileBasename($oSchemaFile->getFileName('.xml'));
         if (!isset($aSchemas[$sSchemaName])) {
             $aSchemas[$sSchemaName] = array();
         }
         $aSchemas[$sSchemaName][] = $oSchemaFile;
     }
     return $aSchemas;
 }
예제 #18
0
<?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;
    }
});
 private function embedVideo($sLocation)
 {
     $oTemplateLocation = ResourceFinder::create(array('modules', 'frontend', 'media_object', 'templates', 'text', 'html.tmpl'))->returnObjects()->find();
     $oVideoTempl = new Template($oTemplateLocation);
     $oVideoTempl->replaceIdentifier('src', $sLocation);
     $oVideoTempl->replaceIdentifier('width', 420);
     $oVideoTempl->replaceIdentifier('height', 250);
     return $oVideoTempl->render();
 }
예제 #20
0
파일: Module.php 프로젝트: rapila/cms-base
 /**
  * Fetches all module metadata (including module info obtained from the info.yml files) and stores it into a static field, returns it
  */
 public static function getModuleMetadataByTypeAndName($sType, $sName)
 {
     $aModuleMetadata = @self::$MODULES_METADATA_LIST[$sType][$sName];
     if ($aModuleMetadata !== null) {
         return $aModuleMetadata;
     }
     $oInfoFileFinder = ResourceFinder::create(array(DIRNAME_MODULES, $sType, $sName, self::INFO_FILE))->all();
     $oCache = new Cache("module_md_{$sType}-{$sName}", DIRNAME_PRELOAD);
     if ($oCache->entryExists() && !$oCache->isOutdated($oInfoFileFinder)) {
         $aModuleMetadata = $oCache->getContentsAsVariable();
     } else {
         //Module exists?
         $aModulePath = array(DIRNAME_MODULES, $sType, $sName);
         if (ResourceFinder::findResource($aModulePath) === null) {
             $aModuleMetadata = null;
             return null;
         }
         $aModuleMetadata = array();
         //General info
         $aModuleMetadata['path'] = $aModulePath;
         $aModuleMetadata['type'] = $sType;
         $aModuleMetadata['name'] = $sName;
         //Folders
         $aModuleMetadata['folders'] = array();
         $aFolders = ResourceFinder::findResourceObjectsByExpressions(array(DIRNAME_MODULES, $sType, $sName, ResourceFinder::ANY_NAME_OR_TYPE_PATTERN));
         foreach ($aFolders as $oFolder) {
             $aModuleMetadata['folders'][] = $oFolder->getFileName();
         }
         //Module-info
         $aModuleInfo = array();
         require_once "spyc/Spyc.php";
         foreach ($oInfoFileFinder->find() as $sPath) {
             $aModuleInfo = array_merge($aModuleInfo, Spyc::YAMLLoad($sPath));
         }
         if (!isset($aModuleInfo['enabled'])) {
             $aModuleInfo['enabled'] = true;
         }
         $aModuleMetadata['module_info'] = $aModuleInfo;
         if (!isset(self::$MODULES_METADATA_LIST[$sType])) {
             self::$MODULES_METADATA_LIST[$sType] = array();
         }
         $oCache->setContents($aModuleMetadata);
     }
     self::$MODULES_METADATA_LIST[$sType][$sName] = $aModuleMetadata;
     return $aModuleMetadata;
 }
예제 #21
0
 private static function findRapilaClass($sClassName)
 {
     $sFileName = "{$sClassName}.php";
     //Standard Classes
     $sPath = ResourceFinder::create()->addPath(DIRNAME_LIB, DIRNAME_CLASSES, $sFileName)->find();
     if ($sPath) {
         return $sPath;
     }
     //Generated Model classes
     $sPath = ResourceFinder::create()->addPath(DIRNAME_GENERATED, DIRNAME_MODEL, $sFileName)->searchMainOnly()->find();
     if ($sPath) {
         return $sPath;
     }
     $sPath = ResourceFinder::create()->addPath(DIRNAME_GENERATED, DIRNAME_MODEL, false, $sFileName)->byExpressions()->searchMainOnly()->find();
     if (($sPath = ArrayUtil::assocPeek($sPath)) !== null) {
         return $sPath;
     }
     //Model classes
     $sPath = ResourceFinder::create()->addPath(DIRNAME_LIB, DIRNAME_MODEL, $sFileName)->find();
     if ($sPath) {
         return $sPath;
     }
     $sPath = ResourceFinder::create()->addPath(DIRNAME_LIB, DIRNAME_MODEL, false, $sFileName)->byExpressions()->find();
     if (($sPath = ArrayUtil::assocPeek($sPath)) !== null) {
         return $sPath;
     }
     if (Module::isValidModuleClassNameOfAnyType($sClassName)) {
         foreach (Module::listModuleTypes() as $sModuleType) {
             $sModuleBaseClass = Module::getClassNameByTypeAndName($sModuleType);
             if (!class_exists($sModuleBaseClass)) {
                 continue;
             }
             if ($sModuleBaseClass::isValidModuleClassName($sClassName)) {
                 $sPath = ResourceFinder::create(array(DIRNAME_MODULES, $sModuleType, $sModuleBaseClass::getNameByClassName($sClassName), $sFileName))->find();
                 if ($sPath) {
                     return $sPath;
                 }
             }
         }
     }
     return null;
 }