Exemplo n.º 1
0
 /**
  * Generating view file.
  *
  * @param $file
  * @param null $data
  * @throws Aries_Exception
  */
 public function __construct($file, $data = null, $is_markdown)
 {
     //Set path to the view file
     if ($is_markdown) {
         $file_location = VIEWS_DIR . $file . '.md';
     } else {
         $file_location = VIEWS_DIR . $file . '.' . $this->view_extension;
     }
     $this->path = realpath($file_location);
     //Check if file is exist
     if (!is_file($this->path)) {
         throw new Aries_Exception($file_location . ' didn\'t exist');
     }
     //Extracting data to content
     $content = '';
     ob_start();
     //Get language file.
     include_once $this->language_folder . $_SESSION[Config::$lang_session] . '.' . $this->language_ext;
     //Sent data to view
     $data[$this->base_url] = Config::getConfig(Config::$base);
     $data[$this->current_year] = Controller::getCurrentYear();
     extract($data);
     extract($lang);
     if ($is_markdown) {
         echo $this->parseMarkdown($this->path);
     } else {
         require_once $this->path;
     }
     $content .= ob_get_clean();
     //Extracting the data to template
     ob_start();
     //Process auto combine and autoload
     $filename_css = '../public/caches/css.css';
     $filename_js = '../public/caches/js.js';
     if (Config::getConfig(Config::$cache) == 'true' && file_exists($filename_css) && file_exists($filename_js)) {
         //Do Nothing
     } else {
         //Process auto combine and autoload for CSS
         if (Config::getPlugins(Config::$combineCss) == 'true' && Config::isAutoloadExist(Config::$autoload_css)) {
             Controller::combineCss();
             $t[$this->css] = '<link href="' . Config::getConfig(Config::$base) . $this->caches_folder . $this->combined_css_filename . '" type="text/css" rel="stylesheet"/>';
         } else {
             if (Config::isAutoloadExist(Config::$autoload_css)) {
                 $t[$this->css] = Controller::cssBuilder();
             } else {
                 $t[$this->css] = '';
             }
         }
         //Process auto combine and autoload for JS
         if (Config::getPlugins(Config::$combineJs) == 'true' && Config::isAutoloadExist(Config::$autoload_js)) {
             Controller::combineJs();
             $t[$this->js] = '<script src="' . Config::getConfig(Config::$base) . $this->caches_folder . $this->combined_js_filename . '" type="text/javascript"></script>';
         } else {
             if (Config::isAutoloadExist(Config::$autoload_js)) {
                 $t[$this->js] = Controller::jsBuilder();
             } else {
                 $t[$this->js] = '';
             }
         }
     }
     //Insert content into template
     $t[$this->content] = $content;
     //Inject variable into template
     extract($data);
     extract($lang);
     extract($t);
     //Load template
     require_once realpath(VIEWS_DIR . DIRECTORY_SEPARATOR . $this->template_name . '.' . $this->template_ext);
     $text = ob_get_clean();
     //Compressing html page before send it to browser
     if (Config::getPlugins(Config::$htmlCompress) == 'true') {
         $this->result = Controller::htmlCompressor($text);
     } else {
         $this->result = $text;
     }
 }
Exemplo n.º 2
0
define('MODELS_DIR', realpath(__DIR__ . '/app/models') . DIRECTORY_SEPARATOR);
define('VIEWS_DIR', realpath(__DIR__ . '/app/views') . DIRECTORY_SEPARATOR);
define('LANGUAGES_DIR', realpath(__DIR__ . '/app/languages') . DIRECTORY_SEPARATOR);
define('LIB_DIR', realpath(__DIR__ . '/lib') . DIRECTORY_SEPARATOR);
define('CSS_DIR', __DIR__ . '/public/css' . DIRECTORY_SEPARATOR);
define('IMG_DIR', Config::getConfig('base') . 'public/img/');
define('JS_DIR', __DIR__ . '/public/js' . DIRECTORY_SEPARATOR);
define('LESS_DIR', realpath(__DIR__ . '/public/less') . DIRECTORY_SEPARATOR);
//Set current language
if (!isset($_SESSION[Config::$lang_session])) {
    $_SESSION[Config::$lang_session] = Config::getConfig(Config::$lang);
}
//Running the router
$router = new \lib\Router();
//Compiling dynamic stylesheet
if (Config::getPlugins('css') == 'lessCSS') {
    $lessFile = glob('public/less/*.less');
    if (sizeof($lessFile) > 0) {
        $less = new lessc();
        foreach ($lessFile as $value) {
            $filenames = explode('/', $value);
            $filename = $filenames[2];
            $less->checkedCompile($value, strstr($value, '/', true) . '/css/' . substr($filename, 0, strpos($filename, '.')) . '.css');
        }
    }
}
//Call caches header
if (Config::getConfig(Config::$cache) == 'true') {
    $router->headerCache();
}
AR_Config::initialize(function ($cfg) {