Advertisement
Guest User

decoded

a guest
Feb 7th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.63 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author Advanced Web Core - www.Awcore.com
  5.  */
  6.  
  7. final class Awcore{
  8.  
  9.     const NEWS_RSS = 'http://system.awcore.com/mujaz_rss';
  10.  
  11.     protected $license_key = null;
  12.  
  13.     protected $initialized = false;
  14.     protected $sessionState = Awcore::SESSION_STATE_UNINITIALIZED;
  15.  
  16.     const SESSION_STATE_UNAVAILABLE = -1;
  17.     const SESSION_STATE_UNINITIALIZED = 0;
  18.     const SESSION_STATE_INITIALIZED = 1;
  19.     const SESSION_STATE_EXTERNAL = 2;
  20.  
  21.     protected $config = null;
  22.  
  23.     protected $translation = array();
  24.    
  25.     protected $html = array();
  26.     protected $ad = array();
  27.     protected $css = array();
  28.     protected $js = array();
  29.  
  30.     function __construct() {
  31.         Awcore::protect();
  32.         if(include (dirname(__FILE__).'/version.php')){
  33.             $this->version = $version;
  34.         }        
  35.         $config_file = dirname(__FILE__).'/config.inc.php';
  36.         if(file_exists($config_file)){
  37.             if (include ($config_file)) {
  38.                 $this->license_key = $license_key;
  39.                 if($db_class = $this->loadClass('NotORM','db')){
  40.                     try {
  41.                         $connect = new PDO($db_info['dsn'], $db_info['user'], $db_info['pass']);
  42.                     } catch (Exception $e) {
  43.                         exit($e->getMessage());
  44.                     }                    
  45.                     $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  46.                     $connect->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
  47.                     $structure = new NotORM_Structure_Convention(
  48.                         $primary = "id",
  49.                         $foreign = "%s_id",
  50.                         $table = "%ss",
  51.                         $prefix = $db_info['prefix']
  52.                     );
  53.                     $this->db = new NotORM($connect,$structure,new NotORM_Cache_Include(CACHE_PATH.'db.php'));  
  54.                 }
  55.                 unset($license_key,$db_info);
  56.             }            
  57.         }else{
  58.             exit(header("Location: setup"));
  59.         }
  60.     }  
  61.  
  62.  
  63.     public static function protect() {
  64.         if (isset ($_SERVER['QUERY_STRING']) && strpos(urldecode($_SERVER['QUERY_STRING']), chr(0)) !== false) die();
  65.         if (@ ini_get('register_globals') && isset ($_REQUEST)) {
  66.             while (list($key, $value)= each($_REQUEST)) {
  67.                 $GLOBALS[$key] = null;
  68.                 unset ($GLOBALS[$key]);
  69.             }
  70.         }
  71.         $targets= array ('PHP_SELF', 'HTTP_USER_AGENT', 'HTTP_REFERER', 'QUERY_STRING');
  72.         foreach ($targets as $target) {
  73.             $_SERVER[$target] = isset ($_SERVER[$target]) ? htmlspecialchars($_SERVER[$target], ENT_QUOTES) : null;
  74.         }
  75.         if (get_magic_quotes_gpc()) {
  76.             $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
  77.             while (list($key, $val) = each($process)) {
  78.                 foreach ($val as $k => $v) {
  79.                     unset($process[$key][$k]);
  80.                     if (is_array($v)) {
  81.                         $process[$key][stripslashes($k)] = $v;
  82.                         $process[] = &$process[$key][stripslashes($k)];
  83.                     } else {
  84.                         $process[$key][stripslashes($k)] = stripslashes($v);
  85.                     }
  86.                 }
  87.             }
  88.             unset($process);
  89.         }        
  90.     }
  91.  
  92.     public function start($_smarty = true,$_manager = false,$_utility = true,$_session = true) {
  93.         if (!$this->initialized) {
  94.  
  95.             if($this->loadClass('cache','tools')){
  96.                 $this->cache = new cache(array(
  97.                     'cacheDir' => CACHE_PATH,
  98.                     'lifeTime' => 90
  99.                 ));
  100.             }            
  101.            
  102.             $this->getConfig();
  103.            
  104.             if($_manager == true){
  105.                 $this->checkLicense();
  106.             }
  107.            
  108.             if($_session){
  109.                 $this->session_start();
  110.             }
  111.  
  112.             if ($auth_class = $this->loadClass('auth','auth')) {
  113.                 $this->auth = new $auth_class ($this);    
  114.             }
  115.             if ($tools_class = $this->loadClass('tools','tools')) {
  116.                 $this->tools = new $tools_class ($this->config);
  117.             }
  118.    
  119.             if($_utility){
  120.                 if ($news_class = $this->loadClass('news','news')) {
  121.                     $this->news = new $news_class ($this);
  122.                 }
  123.                 if ($videos_class = $this->loadClass('videos','videos')) {
  124.                     $this->videos = new $videos_class ($this);
  125.                 }                              
  126.                 if ($ads_class = $this->loadClass('ads','tools')) {
  127.                     $this->ads = new $ads_class ($this);
  128.                    
  129.                     $this->ad(160,600,'اعلان الجانب واحد','right');
  130.                     $this->ad(160,600,'اعلان الجانب اتنين','left');                    
  131.                    
  132.                 }                                
  133.             }          
  134.             if($_smarty){
  135.                 if ($this->loadClass('smarty','smarty') && $this->smarty = new smarty()) {
  136.                     $this->smarty->template_dir = $this->getOption('base_path') . 'themes/'.$this->getOption('theme');
  137.                     $this->smarty->compile_dir  = $this->getOption('cache_path');
  138.                     $this->smarty->plugins_dir  = array(
  139.                         $this->getOption('base_path') . 'core/smarty/plugins',
  140.                     );
  141.                    
  142.                     if(!$_manager){                            
  143.                        
  144.                         $this->css = array_merge($this->css,(array) unserialize($this->getOption('css')));
  145.                         $this->js = array_merge($this->js,(array) unserialize($this->getOption('js')));
  146.  
  147.                         if($this->tools->referer('facebook') && $this->getOption('facebook_auth',0)){
  148.                             $this->js('facebook.js');
  149.                         }
  150.                        
  151.                         if($this->auth->logged()){
  152.                             $this->js('notification.js');
  153.                         }
  154.                        
  155.                         if(!$links = $this->cache->get('links')){
  156.                             $links = array(
  157.                                 'header' => $this->db->links('position',1)->order('`sort` ASC'),
  158.                                 'footer' => $this->db->links('position',2)->order('`sort` ASC')->fetchPairs('cat_id','title'),
  159.                             );
  160.                             $this->cache->save($links,'links');                          
  161.                         }
  162.                        
  163.                         $this->smarty->assign( 'links' , $links );                        
  164.  
  165.                         if($polls_class = $this->loadClass('polls','tools')){
  166.                             $poll = new $polls_class($this);
  167.                             $this->smarty->assign( 'poll' , $poll->display() );
  168.                         }
  169.                    
  170.                     }
  171.                                                      
  172.                     $this->smarty->assign( 'config' , $this->config );
  173.                     $this->smarty->assign( 'user' , $this->auth->data() );
  174.                     $this->smarty->assign( 'tools' , $this->tools );
  175.                                            
  176.                     if($_utility){
  177.                         $this->smarty->assign( 'bar' , $this->news->bar() );
  178.                         $this->smarty->assign( 'cats' , $this->news->catgories_tree() );
  179.                     }
  180.                    
  181.                     $this->smarty->assign( 'version' , $this->getVersion() );
  182.                 }                
  183.             }
  184.             $this->initialized= true;
  185.         }
  186.     }
  187.  
  188.  
  189.     final private function checkLicense($reload = false){
  190.  
  191.     $host =  $this->get_host();
  192.     $key = $this->getLicenseKey();
  193.    
  194.     if(empty($host)){
  195.         return false;
  196.     }
  197.    
  198.     $file = $this->getOption('cache_path').md5($host).'.file.google.tpl.php';
  199.  
  200.         if(!file_exists($file)){
  201.             $this->createLicense($file,$key,$host);
  202.         }else{
  203.    
  204.             $last_fetch = filemtime($file);
  205.             $check_time = ($reload) ? 5 : 7200;
  206.  
  207.             if((time() - $last_fetch) > $check_time){
  208.                 if(!$this->createLicense($file,$key,$host)){
  209.                     exit('حدث خطأ فى تصريحات مجلدات الملفات المؤقتة');
  210.                 }
  211.             }
  212.             if($reload){
  213.                 return true;
  214.             }
  215.         }
  216.  
  217.         if(file_exists($file)){
  218.             include ($file);
  219.             $x = $google_search;
  220.         }else{
  221.             $x = false;
  222.         }
  223.  
  224.         if(!$x){
  225.             $this->checkLicense(true);
  226.            
  227.             if($html = $this->loadUrl('http://system.awcore.com/license/index.html')){
  228.                 exit($html);
  229.             }else{
  230.                 exit('لا يمكن العمل الا فى وجود اتصال بالانترنت');
  231.             }
  232.  
  233.         }
  234.  
  235.     }
  236.  
  237.     function createLicense($file,$key,$host){
  238.        
  239.         if(!$this->prepareDir(dirname($file))){
  240.             exit('مجلد الكاش يجب ان يكون قابل للكتابة');
  241.         }
  242.        
  243.         if($response = $this->loadUrl("http://system.awcore.com/mujaz_license?host={$host}&key={$key}&i=".uniqid())){
  244.             $this->updateOption('license_info',$response);
  245.             $response = (array) unserialize($response);
  246.  
  247.             if($response['response']){
  248.                 if(in_array($host,(array) $response['domains'])){
  249.                     if($response['expire'] > time()){
  250.                         $auth = 'true';
  251.                     }else{
  252.                         $auth = 'false';
  253.                     }
  254.                 }else{
  255.                     $auth = 'false';
  256.                 }
  257.             }else{
  258.                 $auth = 'false';
  259.             }
  260.         }else{
  261.             $auth = 'false';
  262.         }
  263.  
  264.         $fp = fopen($file,'w');
  265.             $written = fwrite($fp,html_entity_decode("&lt;?php \$google_search = $auth; ?&gt;"));
  266.         fclose($fp);
  267.        
  268.         return $written;     
  269.     }
  270.  
  271.  
  272.     final function get_host() {
  273.         if ($host = $_SERVER['HTTP_X_FORWARDED_HOST'])
  274.         {
  275.             $elements = explode(',', $host);
  276.    
  277.             $host = trim(end($elements));
  278.         }
  279.         else
  280.         {
  281.             if (!$host = $_SERVER['HTTP_HOST'])
  282.             {
  283.                 if (!$host = $_SERVER['SERVER_NAME'])
  284.                 {
  285.                     $host = !empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '';
  286.                 }
  287.             }
  288.         }
  289.    
  290.         $host = preg_replace('/:\d+$/', '', $host);
  291.        
  292.         preg_match("/^(http:\/\/)?([^\/]+)/i",$host, $matches);
  293.         preg_match("/[^\.\/]+\.[^\.\/]+$/", $matches[2], $matches);
  294.    
  295.         return $matches[0];
  296.     }
  297.  
  298.     private function prepareDir($directory) {
  299.         $chmod = 0755;
  300.         if (!is_dir($directory)) {
  301.             $old = umask(0000);
  302.             mkdir($directory, $chmod);
  303.             umask($old);
  304.         } elseif (!$this->testPermissions($directory, $chmod)) {
  305.             return false;
  306.         }
  307.         return true;
  308.     }
  309.  
  310.     private function testPermissions($dir, $chmod) {
  311.  
  312.         if (is_writable($dir)) return true;
  313.         if (!is_dir($dir)) {
  314.  
  315.             trigger_error('المجلد '.$dir.' غير موجود',E_USER_WARNING);
  316.             return false;
  317.         }
  318.         if (function_exists('posix_getuid')) {
  319.  
  320.             if (fileowner($dir) === posix_getuid()) {
  321.  
  322.                 $chmod = $chmod | 0700;
  323.                 if (chmod($dir, $chmod)) return true;
  324.             } elseif (filegroup($dir) === posix_getgid()) {
  325.                 $chmod = $chmod | 0070;
  326.             } else {
  327.  
  328.                 $chmod = $chmod | 0777;
  329.             }
  330.             trigger_error('المجلد '.$dir.' غير قابل للكتابة, '.'من فضلك اعطه التصريح ' . decoct($chmod),E_USER_WARNING);
  331.         } else {
  332.  
  333.             trigger_error('المجلد '.$dir.' غير قابل للكتابة, '.'من فضلك قم بتغيير التصاريح',E_USER_WARNING);
  334.         }
  335.         return false;
  336.     }
  337.  
  338.     public function getVersion(){    
  339.         return $this->version;
  340.     }
  341.    
  342.     public function getLicenseKey(){    
  343.         return $this->license_key;
  344.     }
  345.  
  346.     public function getOption($key, $default = null){
  347.             if (is_string($key) && !empty($key)) {
  348.                 if (is_array($this->config) && !empty($this->config) && array_key_exists($key, $this->config)) {
  349.                     $option = ($this->config[$key] !== '') ? $this->config[$key] : $default;
  350.                 }
  351.             }        
  352.         return $option;
  353.     }
  354.  
  355.     public function updateOption($key, $value){      
  356.         return $this->db->options('name' , $key)->update(array('value' => $value));
  357.     }
  358.  
  359.     public function getConfig() {
  360.         if (!$this->initialized || !is_array($this->config) || empty ($this->config)) {
  361.             if (!isset ($this->config['base_url']))
  362.                 $this->config['base_url']= BASE_URL;
  363.             if (!isset ($this->config['base_path']))
  364.                 $this->config['base_path']= BASE_PATH;
  365.             if (!isset ($this->config['cache_path']))
  366.                 $this->config['cache_path']= CACHE_PATH;
  367.             if (!isset ($this->config['url_scheme']))
  368.                 $this->config['url_scheme']= URL_SCHEME;
  369.             if (!isset ($this->config['http_host']))
  370.                 $this->config['http_host']= HTTP_HOST;
  371.             if (!isset ($this->config['site_url']))
  372.                 $this->config['site_url']= SITE_URL;
  373.             if (!isset ($this->config['https_port']))
  374.                 $this->config['https_port']= isset($GLOBALS['https_port']) ? $GLOBALS['https_port'] : 443;
  375.            
  376.             if(!$config = $this->cache->get('options')){
  377.                 foreach ($this->db->options()->fetchPairs('name','value') as $name => $value) {
  378.                     $config[$name] = $this->plaintext($value);
  379.                 }  
  380.                 $this->cache->save($config,'options');        
  381.             }
  382.            
  383.             if(is_array($config)){
  384.                 $this->config = array_merge($this->config, $config);
  385.             }
  386.            
  387.       }
  388.         return $this->config;
  389.     }
  390.  
  391.  
  392.     function loadClass($className,$packageName = '',$constructor = ''){
  393.       if (empty($constructor)){
  394.         $constructor=$className;
  395.       }
  396.       if(!is_callable(array($className,$constructor))){
  397.           $pkg = dirname(__FILE__)."/{$packageName}/";
  398.             if (is_dir($pkg)){
  399.               $class = $pkg.strtolower($className).".class.php";
  400.               if(file_exists($class)){
  401.                 include_once($class);
  402.               }else{
  403.                 die("مجمع الاكواد <b>$className</b> غير موجود فى المجموعة الكودية <b>$packageName</b>");
  404.               }
  405.             }else{
  406.               die("المجموعة الكودية <b>$packageName</b> غير موجودة");
  407.             }
  408.         }
  409.         return $className;
  410.     }
  411.  
  412.     function loadUrl($url,$expected_result = ''){
  413.        
  414.           $url = trim($url);  
  415.        
  416.           Awcore::loadClass('url','dom');  
  417.           $url = get_final_url(html_entity_decode($url));
  418.          
  419.           $timeout = 30;
  420.           $userAgent = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091030 Gentoo Firefox/3.5.4';        
  421.        
  422.           $ch = curl_init();
  423.           curl_setopt($ch,CURLOPT_URL,$url);
  424.           curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  425.           curl_setopt($ch,CURLOPT_USERAGENT, $userAgent);
  426.           curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  427.          
  428.           if (!ini_get('open_basedir') && ini_get('safe_mode' == 'Off')){
  429.             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  430.           }
  431.          
  432.           switch ($expected_result){
  433.             case 'html':
  434.                 curl_setopt($ch, CURLOPT_HEADER, 1);
  435.             break;  
  436.                      
  437.             case 'images':
  438.                 curl_setopt($ch, CURLOPT_HEADER, 0);
  439.                 curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);            
  440.             break;
  441.           }          
  442.          
  443.          $data = curl_exec($ch);
  444.        
  445.          if($expected_result == 'html'){
  446.             $offset = strpos($data, "\r\n\r\n");
  447.             $header = substr($data, 0, $offset);
  448.             $data = substr($data, $offset + 4);
  449.        
  450.             $encoding = false;
  451.            
  452.             if(preg_match('/^Content-Type:\s+([^;]+)(?:;\s*charset=(.*))?/im', $header, $match)){
  453.                 if(isset($match[2])){
  454.                     $encoding = strtolower(trim($match[2]));
  455.                 }else{
  456.                     if(preg_match('/charset=([^"]+)/i', $data, $match)){
  457.                         if(isset($match[1])){
  458.                             $encoding = strtolower(trim($match[1]));
  459.                         }
  460.                     }
  461.                 }
  462.             }
  463.  
  464.             if($encoding && $encoding <> 'utf-8'){
  465.                 if (function_exists('iconv')) {
  466.                     $data = iconv($encoding, 'utf-8', $data);
  467.                 } elseif (function_exists('mb_convert_encoding')) {
  468.                     $data = mb_convert_encoding($data, 'utf-8', $encoding);
  469.                 } elseif (function_exists('recode_string')) {
  470.                     $data = recode_string($encoding . '..utf-8', $data);
  471.                 }                    
  472.             }            
  473.    
  474.         }          
  475.  
  476.         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  477.         curl_close($ch);
  478.       return ($httpCode == 200) ? $data : $httpCode;       
  479.     }
  480.  
  481.     function loadlang($file){
  482.         if(include_once(dirname(__FILE__)."/language/{$file}.php")){
  483.                 $this->translation = array_merge($this->translation,(array)$lang);
  484.         }
  485.     }
  486.  
  487.     protected function session_start() {
  488.         if (!in_array($this->getSessionState(), array(Awcore::SESSION_STATE_INITIALIZED, Awcore::SESSION_STATE_EXTERNAL, Awcore::SESSION_STATE_UNAVAILABLE), true)) {
  489.            
  490.             if($this->getOption('db_session')){
  491.                 if ($shClass = $this->loadClass('sessions','auth')) {
  492.                     if ($sh= new $shClass($this->db)) {
  493.                         $sh->lifetime($this->getOption('session_gc_maxlifetime'));
  494.                         session_set_save_handler(
  495.                             array (& $sh, 'open'),
  496.                             array (& $sh, 'close'),
  497.                             array (& $sh, 'read'),
  498.                             array (& $sh, 'write'),
  499.                             array (& $sh, 'destroy'),
  500.                             array (& $sh, 'gc')
  501.                         );
  502.                     }
  503.                 }                
  504.             }
  505.            
  506.             $cookieDomain= $this->getOption('session_cookie_domain','');
  507.             $cookiePath= $this->getOption('session_cookie_path','/');
  508.             $cookieSecure= (boolean) $this->getOption('session_cookie_secure',false);
  509.             $cookieLifetime= (integer) $this->getOption('session_cookie_lifetime',0);
  510.             $gcMaxlifetime = (integer) $this->getOption('session_gc_maxlifetime',$cookieLifetime);
  511.            
  512.                 if ($gcMaxlifetime > 0) {
  513.                     ini_set('session.gc_maxlifetime', $gcMaxlifetime);
  514.                 }
  515.             $site_sessionname= $this->getOption('session_name', null);
  516.                 if (!empty($site_sessionname)){
  517.                     session_name($site_sessionname);
  518.                 }
  519.             session_set_cookie_params($cookieLifetime, $cookiePath, $cookieDomain, $cookieSecure);
  520.             session_start();
  521.             $this->sessionState = Awcore::SESSION_STATE_INITIALIZED;
  522.             $cookieExpiration= 0;
  523.             if (isset ($_SESSION['Awcore.session.cookie.lifetime'])) {
  524.                 $sessionCookieLifetime= (integer) $_SESSION['Awcore.session.cookie.lifetime'];
  525.                 if ($sessionCookieLifetime !== $cookieLifetime) {
  526.                     if ($sessionCookieLifetime) {
  527.                         $cookieExpiration= time() + $sessionCookieLifetime;
  528.                     }
  529.                     setcookie(session_name(), session_id(), $cookieExpiration, $cookiePath, $cookieDomain, $cookieSecure);
  530.                 }
  531.             }
  532.         }
  533.     }
  534.  
  535.     public function getSessionState() {
  536.  
  537.         if ($this->sessionState !== Awcore::SESSION_STATE_INITIALIZED) {
  538.             if (headers_sent()) {
  539.                 $this->sessionState = Awcore::SESSION_STATE_UNAVAILABLE;
  540.             }elseif (isset($_SESSION)) {
  541.                 $this->sessionState = Awcore::SESSION_STATE_EXTERNAL;
  542.             }
  543.         }
  544.         return $this->sessionState;
  545.     }
  546.  
  547.     function translate($str, $tokens = array()) {
  548.         $explode = explode(':',$str);
  549.         if (array_key_exists($explode[0],(array) $this->translation)){
  550.             $str = $this->translation[$explode[0]];
  551.         }
  552.         if (is_array($str)){
  553.             $str = $str[$explode[1]];      
  554.         }
  555.         if (is_array($tokens) && sizeof($tokens) > 0){
  556.             $str = vsprintf($str, $tokens);
  557.         }
  558.         return $str;
  559.     }
  560.  
  561.     function photo_list($id,$prefix = 'N'){
  562.         return $this->db->upload_imgs('prefix',"{$prefix}:{$id}")->fetchPairs('id','img_file');
  563.     }
  564.  
  565.     function delete_photo($id){
  566.         $path = $this->getOption('base_path').'dynamic/uploads/images/';
  567.         if(is_int($id)){
  568.             $row = $this->db->upload_imgs('id',$id);
  569.             $file = $path.$row->fetchSingle('img_file');
  570.                 if(file_exists($file)){
  571.                     if(unlink($file)){
  572.                         $row->delete();
  573.                     }            
  574.                 }            
  575.         }else{
  576.             $file = $path.$id;
  577.             if(file_exists($file)){
  578.                 unlink($file);            
  579.             }            
  580.         }
  581.  
  582.     }
  583.  
  584.     function plaintext($str,$quotes = true){
  585.         return ($quotes) ? htmlspecialchars($str,ENT_NOQUOTES,"UTF-8") : htmlspecialchars($str,ENT_QUOTES,"UTF-8");
  586.     }
  587.  
  588.     function safehtml($str,$options = array()){
  589.         $this->loadClass('load','purifier');              
  590.  
  591.         $config = HTMLPurifier_Config::createDefault();
  592.  
  593.         $config->set('Cache.SerializerPath', $this->getOption('cache_path'));
  594.  
  595.         $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', true);
  596.         $config->set('AutoFormat.RemoveEmpty.RemoveNbsp.Exceptions', 'iframe');
  597.         $config->set('AutoFormat.AutoParagraph', true);
  598.        
  599.         $config->set('HTML.SafeIframe', true);
  600.         $config->set('URI.SafeIframeRegexp', '%^http://(www.youtube.com/embed/|player.vimeo.com/video/|www.dailymotion.com/embed/video/)%');
  601.        
  602.         $config->set('Filter.YouTube', true);
  603.         $config->set('HTML.SafeObject', true);
  604.         $config->set('HTML.SafeEmbed', true);
  605.  
  606.         if(is_array($options['ForbiddenElements']) && count($options['ForbiddenElements'])){
  607.             $config->set('HTML.ForbiddenElements', $options['ForbiddenElements']);
  608.         }
  609.  
  610.         $filter = new HTMLPurifier($config);
  611.                            
  612.         return $filter->purify($str);      
  613.     }
  614.  
  615.     function cron($key,$duration){
  616.         $now = time();
  617.         $last = (int) $this->getOption($key);
  618.  
  619.         if(($now - $last) > $duration){
  620.             $this->updateOption($key,$now);
  621.             $this->cache->remove('options');
  622.             return true;
  623.         }  
  624.        
  625.         return false;  
  626.     }
  627.  
  628.     public function ad($width,$height,$info,$key = false){
  629.         if($key){
  630.             return $this->ad[$key] = $this->ads->draw($width,$height,$info);
  631.         }else{
  632.             return $this->ad[] = $this->ads->draw($width,$height,$info);
  633.         }
  634.        
  635.     }
  636.    
  637.     public function html($code,$place = 'header'){
  638.         return $this->html[$place][] = $code;
  639.     }
  640.  
  641.     public function css(){
  642.         foreach(func_get_args() as $file){
  643.             $this->css[] = $file;
  644.         }
  645.     }
  646.  
  647.     public function js(){
  648.         foreach(func_get_args() as $file){
  649.             $this->js[] = $file;
  650.         }
  651.     }
  652.        
  653.     final function display($tpl_file = null,$title = 'غير مسمى',$options = array()){
  654.         $css_files = $css_rules = $js_files = array();
  655.         foreach ($this->css as $css_item) {
  656.             if(strpos($css_item, ":") !== false){
  657.                $css_rules[] = $css_item;
  658.             }else{
  659.                $css_files[] = $this->getOption('base_url').'/static/css/'.$css_item;
  660.             }
  661.         }
  662.        
  663.         $this->smarty->assign('css', array('files' => $css_files,'rules' => $css_rules));
  664.        
  665.         foreach ($this->js as $js_item) {
  666.             $js_files[] = $this->getOption('base_url').'/static/js/'.$js_item;
  667.         }
  668.        
  669.         $this->smarty->assign('js', $js_files );
  670.  
  671.         $this->smarty->assign('html', $this->html );
  672.        
  673.         $this->smarty->assign('ad', $this->ad );
  674.  
  675.         $this->smarty->assign('tpl_file',$tpl_file);
  676.        
  677.         if(is_array($title)){
  678.             $title = array_reverse($title);
  679.             $title = implode(' | ',$title);
  680.         }
  681.        
  682.         $this->smarty->assign('title',$title);
  683.  
  684.             $page = array_merge(array(
  685.                 'description' => null,
  686.                 'keywords' => null,
  687.                 'noindex' => false,
  688.                 'og_image' => false
  689.             ),$options);
  690.        
  691.         $this->smarty->assign('page',$page);
  692.         $this->smarty->display($this->smarty->structure_tpl);
  693.         unset($this->db);
  694.         #echo gen_time();
  695.    }    
  696.    
  697. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement