コード例 #1
0
 public function setTemplate($mTemplate)
 {
     $aCssUrls = array();
     //Important for CSS
     if (!isset($this->aModuleSettings['css_files'])) {
         if (is_string($mTemplate)) {
             $mTemplate = new Template($mTemplate);
         }
         $oIncluder = new ResourceIncluder();
         foreach ($mTemplate->identifiersMatching('addResourceInclude', Template::$ANY_VALUE) as $oIdentifier) {
             $oIncluder->addResourceFromTemplateIdentifier($oIdentifier);
         }
         $aResources = $oIncluder->getAllIncludedResources();
         foreach ($aResources as $aResourceInfo) {
             if (!(isset($aResourceInfo['resource_type']) && $aResourceInfo['resource_type'] === ResourceIncluder::RESOURCE_TYPE_CSS)) {
                 continue;
             }
             if (isset($aResourceInfo['ie_condition'])) {
                 continue;
             }
             if (isset($aResourceInfo['media']) && !preg_match('/\\b(screen|all)\\b/', $aResourceInfo['media'])) {
                 continue;
             }
             $aCssUrls[] = $aResourceInfo['location'];
         }
         //Always include an editor.css file if found
         foreach (ResourceFinder::findAllResourceObjects(array(DIRNAME_WEB, 'css', 'editor.css')) as $oFileUrl) {
             $aCssUrls[] = $oFileUrl->getFrontendPath();
         }
     }
     $this->setSetting('contentsCss', $aCssUrls);
 }
コード例 #2
0
ファイル: ResourceIncluder.php プロジェクト: rapila/cms-base
 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;
     }
 }