Example #1
0
 /**
  * Adds a CSS file to be loaded upon clientside rendering. Leave the localpath empty for remote files
  * @param \SimpleXMLElement The XML root
  * @param string The (full)path to the local CSS file.
  * @param string The (full)path to the remote file
  * @param string The media type, defaults to CSS_MEDIA_SCREEN
  * @param string The reltype, defaults to CSS_REL_DEFAULT
  * @param int \System\Web\BasePage\Page\InclusionLocation location for placement
  */
 public function addCSSFile(\SimpleXMLElement $xml, $localFile, $remoteFile, $media = \System\Web\BasePage\Page\BasePage::CSS_MEDIA_SCREEN, $rel = \System\Web\BasePage\Page\BasePage::CSS_REL_DEFAULT, $location = \System\Web\BasePage\Page\InclusionLocation::LOCATION_HEAD)
 {
     if (!isset($xml->cssfiles)) {
         $xml->addChild('cssfiles');
     }
     $cssFiles = $xml->cssfiles;
     $cssFile = $cssFiles->addChild('cssfile');
     $cssFile->addChild('media', $media);
     $cssFile->addChild('rel', $rel);
     if ($localFile) {
         $file = new \System\IO\File($localFile);
         if ('.' . $file->getExtension() == self::CSS_EXTENSION && MINIFY_ENABLE && mb_strpos($file->getFilename(), self::CSS_MIN_EXTENSION) === false) {
             $localMinFile = $file->getPath() . basename($file->getFilename(), self::CSS_EXTENSION) . self::CSS_MIN_EXTENSION;
             if (!file_exists($localMinFile)) {
                 $file = \System\IO\File::writeContents($localMinFile, \System\Web\Minify\CSS\Minify::minify($file->getContents()));
             } else {
                 $file = new \System\IO\File($localMinFile);
             }
             $remoteFile = str_ireplace(self::CSS_EXTENSION, self::CSS_MIN_EXTENSION, $remoteFile);
         }
         $cssFile->addChild('filesize', $file->getFileSizeInBytes());
     }
     $cssFile->addChild('name', $remoteFile);
     $cssFile->addChild('location', $location);
 }
Example #2
0
 /**
  * Gets all the files in the current directory, with exclusion of
  * .svn, .htaccess, .htpasswd etc.
  * Does not iterate to deeper levels.
  * @param \System\Collection\Vector extensions to include in the search.
  * @return \System\Collection\Vector A Vector with File objects.
  */
 public final function getFiles(\System\Collection\Vector $extensions = null)
 {
     $list = new \System\Collection\Vector();
     //list all the files
     $handle = opendir($this->path);
     while (($file = readdir($handle)) !== false) {
         //get the full path
         $filePath = self::getPath($this->path . self::getSeparator() . $file);
         //no current or upper folders should be considered and the target should exist.
         if ($file != '.' && $file != '..' && mb_substr($file, 0, 1) != '.' && file_exists($filePath) && !is_dir($filePath)) {
             $file = new \System\IO\File($filePath);
             if ($extensions != null) {
                 if ($extensions->contains($file->getExtension())) {
                     $list[] = $file;
                 }
             } else {
                 $list[] = $file;
             }
         }
     }
     closedir($handle);
     return $list;
 }