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 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 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;
     }
 }
Example #4
0
 public function testFindMainSelfEqual()
 {
     $oMain = ResourceFinder::findResourceObject(array('lib', 'tests', 'ResourceFinderTests.php'));
     $this->assertEquals(new FileResource($oMain->getFullPath()), $oMain);
 }
Example #5
0
 /**
  * @param string $sTemplateName template name
  * @param string|array $mPath template dir path
  * @param boolean $bTemplateIsTextOnly template is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
  * @param boolean $bDirectOutput template will output directly to stream? only one the main template should have set this to true
  * @param string $sTargetEncoding target encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
  * @param string $sRootTemplateName root template name, used internally when including subtemplates, default=null
  * @param int $iDefaultFlags default flags, will be ORed to the flags you provide when calling {@link replaceIdentifier()} and {@link replaceIdentifierMultiple()}
  */
 public function __construct($sTemplateName, $mPath = null, $bTemplateIsTextOnly = false, $bDirectOutput = false, $sTargetEncoding = null, $sRootTemplateName = null, $iDefaultFlags = 0)
 {
     if ($sTargetEncoding === null) {
         $sTargetEncoding = Settings::getSetting("encoding", "browser", "utf-8");
     }
     if ($mPath === "db") {
         $this->sEncoding = Settings::getSetting("encoding", "db", "utf-8");
     } else {
         if ($mPath === "browser") {
             $this->sEncoding = Settings::getSetting("encoding", "browser", "utf-8");
         }
     }
     if ($mPath === null || $mPath === "db" || $mPath === "browser") {
         $mPath = DIRNAME_TEMPLATES;
     }
     $sTemplateText = "";
     $this->aTemplateContents = array();
     $oCache = null;
     $bCacheIsCurrent = false;
     if ($bTemplateIsTextOnly) {
         $sTemplateText = $sTemplateName;
         $sTemplateName = $sRootTemplateName;
     } else {
         if ($sTemplateName instanceof FileResource) {
             $oPath = $sTemplateName;
             $aPath = explode('/', $oPath->getRelativePath());
             $sTemplateName = $oPath->getFileName(self::$SUFFIX);
         } else {
             $aPath = ResourceFinder::parsePathArguments(null, $mPath, $sTemplateName . self::$SUFFIX);
             $oPath = ResourceFinder::findResourceObject($aPath);
         }
         if ($oPath === null) {
             throw new Exception("Error in Template construct: Template file " . implode("/", $aPath + array($sTemplateName . self::$SUFFIX)) . " does not exist");
         }
         if (Settings::getSetting('general', 'template_caching', false)) {
             $oCache = new Cache($oPath->getFullPath() . "_" . LocaleUtil::getLocaleId() . "_" . $sTargetEncoding . "_" . $sRootTemplateName, DIRNAME_TEMPLATES);
             $bCacheIsCurrent = $oCache->entryExists() && !$oCache->isOutdated($oPath->getFullPath());
         }
         if (!$bCacheIsCurrent) {
             $sTemplateText = file_get_contents($oPath->getFullPath());
         }
         $mPath = $aPath;
         array_pop($mPath);
     }
     if ($sRootTemplateName === null && !$bTemplateIsTextOnly) {
         $sRootTemplateName = $sTemplateName;
     }
     if ($sRootTemplateName === null) {
         $sRootTemplateName = '';
     }
     $this->sTemplateName = $sRootTemplateName;
     if (StringUtil::startsWith($sTemplateName, 'e_mail_') || StringUtil::startsWith($sTemplateName, 'email_')) {
         $iDefaultFlags |= self::NO_HTML_ESCAPE;
     } else {
         if (StringUtil::endsWith($sTemplateName, '.js') || StringUtil::endsWith($sTemplateName, '.css')) {
             $iDefaultFlags |= self::NO_HTML_ESCAPE | self::ESCAPE;
         } else {
             if (StringUtil::endsWith($this->sTemplateName, '.js') || StringUtil::endsWith($this->sTemplateName, '.css')) {
                 //I’m not a js template but my parent is
                 $iDefaultFlags &= ~(self::NO_HTML_ESCAPE | self::ESCAPE);
             }
         }
     }
     $this->mPath = $mPath;
     $this->oSpecialTemplateIdentifierActions = new SpecialTemplateIdentifierActions($this);
     $this->iDefaultFlags = $iDefaultFlags;
     if ($bCacheIsCurrent) {
         $this->aTemplateContents = $oCache->getContentsAsVariable();
         foreach ($this->aTemplateContents as &$mContent) {
             if ($mContent instanceof TemplatePart) {
                 $mContent->setTemplate($this);
             }
         }
     } else {
         if (is_array($sTemplateText)) {
             $this->aTemplateContents = $sTemplateText;
         } else {
             $sTemplateText = StringUtil::encode($sTemplateText, $this->sEncoding, $sTargetEncoding);
             $this->aTemplateContents = self::templateContentsFromText($sTemplateText, $this);
             $this->replaceConditionals(true);
             $this->renderDirectOutput();
         }
         $this->replaceSpecialIdentifiersOnStart();
         if ($oCache !== null) {
             $oCache->setContents($this->aTemplateContents);
         }
     }
     $this->sEncoding = $sTargetEncoding;
     $this->bDirectOutput = $bDirectOutput;
     $this->replaceConditionals(true);
     $this->renderDirectOutput();
 }
Example #6
0
 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;
     }
 }
Example #7
0
 private function cleanupCss()
 {
     $aCssUrls = array();
     if (isset($this->aModuleSettings['css_files'])) {
         if (!is_array($this->aModuleSettings['css_files'])) {
             $this->aModuleSettings['css_files'] = array($this->aModuleSettings['css_files']);
         }
         foreach ($this->aModuleSettings['css_files'] as $sCssFile) {
             $oFileUrl = ResourceFinder::findResourceObject(array(DIRNAME_WEB, 'css', "{$sCssFile}.css"));
             if ($oFileUrl !== null) {
                 $aCssUrls[] = $oFileUrl->getFrontendPath();
             }
         }
     }
     unset($this->aModuleSettings['css_files']);
     $this->setSetting('contentsCss', $aCssUrls);
 }