Example #1
0
File: log.php Project: cruide/wasp
 /**
  * Запись лога в файл
  * 
  */
 public function write()
 {
     $_tmp = '';
     if (!is_dir(LOGS_DIR)) {
         wasp_mkdir(LOGS_DIR, 0775, true);
     }
     if (!empty($this->_logs)) {
         foreach ($this->_logs as $key => $val) {
             $_tmp .= "[{$val['time']}] {$val['msg']}\n";
         }
         if (is_file(LOGS_DIR . DIR_SEP . 'app_log')) {
             if (filesize(LOGS_DIR . DIR_SEP . 'app_log') >= 614400) {
                 $logfile_out = LOGS_DIR . DIR_SEP . 'app-' . date('Ymd');
                 $j = 1;
                 while (true) {
                     if (!is_file($logfile_out . "-{$j}.log.gz")) {
                         $logfile_out .= "-{$j}.log.gz";
                         break;
                     }
                     $j++;
                 }
                 gz_file_pack(LOGS_DIR . DIR_SEP . 'app_log', $logfile_out);
                 @unlink(LOGS_DIR . DIR_SEP . 'app_log');
             }
             $_tmp .= file_get_contents(LOGS_DIR . DIR_SEP . 'app_log');
             file_put_contents(LOGS_DIR . DIR_SEP . 'app_log', $_tmp);
         } else {
             @file_put_contents(LOGS_DIR . DIR_SEP . 'app_log', $_tmp);
         }
         $this->_logs = [];
     }
 }
Example #2
0
 public function __construct()
 {
     $this->config = cfg('config');
     $this->session = session();
     $this->input = input();
     $this->cookie = cookie();
     $this->layout = theme();
     $this->router = router();
     $this->ui = new Ui();
     $this->ui->enableSecurity('Wasp_Smarty_Security');
     $this->ui->setTemplateDir($this->layout->getThemePath() . DIR_SEP . 'views' . DIR_SEP);
     $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . theme()->getThemeName() . DIR_SEP . 'views';
     if (!is_dir($temp_dir)) {
         wasp_mkdir($temp_dir);
     }
     $this->ui->setCompileDir($temp_dir . DIR_SEP);
     //        $this->ui->setCacheDir('');
 }
Example #3
0
 public function display($content)
 {
     if (!$this->render) {
         if (!headers_sent() && array_count($this->_headers) > 0) {
             foreach ($this->_headers as $key => $val) {
                 header($val);
             }
         }
         http_cache_off();
         if (!Cookie::isSaved()) {
             cookie()->save();
         }
         if (wasp_strlen($content) > 102400) {
             @ini_set('zlib.output_compression', 1);
         }
         echo $this->getDebugInfo($content);
         return;
     }
     $templater = new \Smarty();
     $templater->enableSecurity('Wasp_Smarty_Security');
     $templater->setTemplateDir($this->getThemePath() . DIR_SEP);
     $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . $this->getThemeName();
     if (!is_dir($temp_dir)) {
         wasp_mkdir($temp_dir);
     }
     $templater->setCompileDir($temp_dir . DIR_SEP);
     if (array_count($this->_assigns) > 0) {
         foreach ($this->_assigns as $key => $val) {
             $templater->assign($key, $val);
         }
     }
     $templater->assign('content', $content);
     if (function_exists('memory_get_peak_usage')) {
         $templater->assign('max_mem_use', get_mem_use(true));
     } else {
         $templater->assign('max_mem_use', '-//-');
     }
     $out = $templater->fetch($this->_layout);
     if (!headers_sent() && array_count($this->_headers) > 0) {
         foreach ($this->_headers as $key => $val) {
             header($val);
         }
     }
     if (!Cookie::isSaved()) {
         cookie()->save();
     }
     if (wasp_strlen($out) > 102400) {
         ini_set('zlib.output_compression', 1);
     }
     unset($templater);
     memory_clear();
     /**
      * Add CSS
      */
     if (array_count($this->_css_list) > 0) {
         $_ = "\n\t\t<!-- DYNAMIC CSS -->\n";
         foreach ($this->_css_list as $key => $val) {
             if (preg_match('/^http/is', $val)) {
                 $_ .= "\t\t<link href=\"{$val}\" rel=\"stylesheet\" type=\"text/css\" />\n";
             } else {
                 $url = $this->getThemeUrl() . '/css/' . $val;
                 $_ .= "\t\t<link href=\"{$url}\" rel=\"stylesheet\" type=\"text/css\" />\n";
             }
         }
         $out = preg_replace('#\\<\\/head\\>#is', $_ . "</head>\n", $out);
         unset($_, $key, $val, $url);
     }
     /**
      * Add JS
      */
     if (array_count($this->_js_list) > 0) {
         $info = "\n\t\t<!-- :position DYNAMIC JS -->\n";
         foreach ($this->_js_list as $pos => $item) {
             $_ = str_replace(':position', wasp_strtoupper($pos), "\n\t\t<!-- :position DYNAMIC JS -->\n");
             if (array_count($item) > 0) {
                 foreach ($item as $key => $val) {
                     if (preg_match('/^http/is', $val)) {
                         $_ .= "\t\t<script type=\"text/javascript\" src=\"{$val}\"></script>\n";
                     } else {
                         $url = $this->getThemeUrl() . '/js/' . $val;
                         $_ .= "\t\t<script type=\"text/javascript\" src=\"{$url}\"></script>\n";
                     }
                 }
                 $out = preg_replace("#\\<\\/{$pos}\\>#is", $_ . "</{$pos}>\n", $out);
                 unset($_, $key, $val, $url);
             }
         }
         unset($pos, $item);
     }
     echo $this->getDebugInfo($out);
 }
Example #4
0
 protected function _prepare()
 {
     $this->settings = cfg('phpmailer');
     if (!class_exists('\\PHPMailer')) {
         wasp_error('Class `PHPMailer` not found...');
     }
     $mails_path = APP_DIR . DIR_SEP . 'mails';
     $this->phpmail = new \PHPMailer();
     $this->ui = new \Smarty();
     $this->ui->enableSecurity('Wasp_Smarty_Security');
     $this->ui->setTemplateDir($mails_path . DIR_SEP);
     $temp_dir = TEMP_DIR . DIR_SEP . 'smarty' . DIR_SEP . theme()->getThemeName() . DIR_SEP . 'mails';
     if (!is_dir($temp_dir)) {
         wasp_mkdir($temp_dir);
     }
     $this->ui->setCompileDir($temp_dir . DIR_SEP);
     if (!empty($this->settings->email_from)) {
         $this->phpmail->SetFrom($this->settings->email_from, isset($this->settings->from_name) ? $this->settings->from_name : '');
     }
     if (!empty($this->settings->replyto)) {
         $this->phpmail->AddReplyTo($this->settings->replyto);
     }
     if (!empty($this->settings->host)) {
         $this->phpmail->Host = $this->settings->host;
     }
     if (!empty($this->settings->port)) {
         $this->phpmail->Port = $this->settings->port;
     }
     if (!empty($this->settings->username)) {
         $this->phpmail->Username = $this->settings->username;
         if (!empty($this->settings->password)) {
             $this->phpmail->Password = $this->settings->password;
             $this->phpmail->SMTPAuth = true;
         }
     }
     if (!empty($this->settings->authtype)) {
         $this->phpmail->AuthType = $this->settings->authtype;
     }
     if (!empty($this->settings->type)) {
         switch ($this->settings->type) {
             case 'sendmail':
                 if (isset($this->settings->sendmail)) {
                     $this->phpmail->Sendmail = (string) $this->settings->sendmail;
                 }
                 $this->phpmail->IsSendmail();
                 break;
             case 'smtp':
                 $this->phpmail->IsSMTP();
                 break;
             case 'qmail':
                 $this->phpmail->IsQmail();
                 break;
             default:
                 $this->phpmail->IsMail();
         }
     } else {
         $this->phpmail->IsMail();
     }
     $this->phpmail->XMailer = FRAMEWORK;
     $this->phpmail->CharSet = 'utf-8';
 }
Example #5
0
if (is_dir(APP_DIR) && is_file(APP_DIR . DIR_SEP . 'functions.php')) {
    require APP_DIR . DIR_SEP . 'functions.php';
}
require_once CORE_PATH . DIR_SEP . 'vendor' . DIR_SEP . 'autoload.php';
spl_autoload_register('wasp_autoloader');
if (!headers_sent()) {
    header('X-Based-On: ' . FRAMEWORK);
}
if (!is_dir(CONTENT_DIR)) {
    wasp_mkdir(CONTENT_DIR);
}
if (!is_dir(TEMP_DIR)) {
    wasp_mkdir(TEMP_DIR);
}
if (!is_dir(LOGS_DIR)) {
    wasp_mkdir(LOGS_DIR);
}
$DisabledFunctions = get_disabled_functions();
if (!in_array('ini_set', $DisabledFunctions)) {
    $php_cfg = cfg('config')->php;
    if ($php_cfg->count() > 0) {
        foreach ($php_cfg->toArray() as $key => $val) {
            $key = str_replace('__', '.', $key);
            @ini_set($key, $val);
        }
        unset($key, $val);
    }
    unset($php_cfg);
}
unset($DisabledFunctions);
require CORE_PATH . DIR_SEP . 'smarty_security.php';