Exemple #1
0
 /**
  * 
  * @param mixed $file
  * @param string $folder
  * @param string $extension Opcional
  * @param string $folder_theme Path to folder themes
  * @return string or array of files
  */
 public static function file($file, $folder, $extension = null)
 {
     $parser = new Parser();
     $folder = Filter::systemPath($folder);
     $file = Filter::systemPath($file);
     if (!$parser->file()->exists($folder)) {
         throw new Error("Directory \"{$folder}\" not found.");
     }
     if (!$file && $folder) {
         return self::fileAll($folder);
     }
     $no_extension = false;
     if (!$extension) {
         $no_extension = self::fileNoExtension($file, $folder);
     }
     if ($no_extension) {
         return $no_extension;
     }
     $parser = new Parser();
     Filter::file($file, $extension);
     if (is_string($file)) {
         $namefill = $folder . DIRECTORY_SEPARATOR . $file;
         if (!$parser->file()->exists($namefill)) {
             throw new Error("File \"{$namefill}\" not found.");
         }
         return $namefill;
     }
     if (!is_array($file)) {
         throw new Error("File invalid.");
     }
     $i = 0;
     foreach ($file as $val) {
         $namefill = $folder . DIRECTORY_SEPARATOR . $val;
         if (!$parser->file()->exists($namefill)) {
             throw new Error("File \"{$namefill}\" not found.");
         }
         $file[$i] = $namefill;
         $i++;
     }
     if ($i == count($file)) {
         return $file;
     }
 }
Exemple #2
0
 public static function fileContent($url)
 {
     $ext = new Extensions();
     $header_http = new ResponseHttpFoundation();
     $file = Tmpfile::getThemeConfig('themes_folder') . DIRECTORY_SEPARATOR . $url;
     $file = Filter::systemPath($file);
     $path = Filter::realpath($file);
     if (!$path) {
         $header_http->setContent("<html><body><center><h1>Ops! file not exists :(</h1></center></body></html>");
         $header_http->setStatusCode(ResponseHttpFoundation::HTTP_NOT_FOUND);
         $header_http->headers->set('Content-Type', "text/html");
         $header_http->send();
         return false;
     }
     //Defined Content-type of file
     $ctype = $ext->ctype("." . $ext->check($path, true));
     $header_http->setContent(file_get_contents($path));
     $header_http->setStatusCode(ResponseHttpFoundation::HTTP_OK);
     $header_http->headers->set('Content-Type', $ctype);
     $header_http->send();
 }
Exemple #3
0
    public function loadThemes($folder)
    {
        $f_origin = $folder;
        $folder = Filter::realPath($folder);
        if (!$folder) {
            throw new ErrorRuntime("Folder \"{$f_origin}\", not exists. It's important to save Themes.");
        }
        $parser = new Parser();
        $DS = DIRECTORY_SEPARATOR;
        if (!$parser->file()->exists(Filter::systemPath($folder . "/" . $this->getMainConfig()))) {
            echo <<<DOC
            No found {$folder}{$DS}{$this->getMainConfig()}
            Please, create one file of
            configuration to themes, something as config.yml:
            <pre>
            themes:
                "light": true
                "dark":
                "one-style":
            
DOC;
            exit;
        }
        if (!$parser->file()->exists(Filter::systemPath($this->getFolderTmpTheme()))) {
            echo <<<DOC
            <pre>
            Please, follow steps:
            
                1 - Create a folder in "public/theme"
                2 - Create a file in "public/theme/index.php", containing:
            
                    < ?php
                    require_once __DIR__.'/../../vendor/autoload.php';
                    use Glance\\Response;
                    Response::listenMessage();
            
                3 - Create a file in "public/theme/.htaccess", containing:
            
                    
                    RewriteEngine On
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d
                    RewriteRule ^(.*)\$ index.php?get=\$1 [L]
                    
            </pre>
DOC;
            exit;
        }
        $themes = $parser->loadYAML(Filter::systemPath($folder . "/" . $this->getMainConfig()));
        $ftheme = NULL;
        foreach ($themes['themes'] as $theme => $value) {
            if (!$parser->file()->exists(Filter::systemPath($folder . "/" . $theme))) {
                throw new ErrorRuntime("Folder of the THEME: \"{$theme}\", not exists.");
            } else {
                if (!$ftheme) {
                    $ftheme = $theme;
                }
                if ($value and !$this->activated) {
                    $this->activated = $theme;
                }
            }
        }
        if ($ftheme and !$this->activated) {
            $this->activated = $ftheme;
        }
    }