예제 #1
0
파일: Smarty.php 프로젝트: ssdphp/ssdphp
 /**
  * render a .tpl
  */
 public function render($tpl = '')
 {
     if ($tpl == '') {
         $tpl = SsdPHP::getAction() . "/" . SsdPHP::getController();
     }
     return self::$Smarty->fetch($tpl . self::$config['tpl_suffix']);
 }
예제 #2
0
파일: Factory.php 프로젝트: ssdphp/ssdphp
 public function setTable($table = "")
 {
     if ($table == "") {
         self::$table = ucfirst(strtolower(SsdPHP::getController()));
     } else {
         self::$table = $table;
     }
     return $this;
 }
예제 #3
0
파일: systemLog.php 프로젝트: ssdphp/ssdphp
 public static function writeLog()
 {
     if (Config::get('is_write_log', true) !== true) {
         return false;
     }
     $SystemLog = new \App\Task\model\SystemLog();
     $_SESSION = !empty($_SESSION) ? $_SESSION : array();
     $model = in_array($v = strtolower(SsdPHP::getModel()), self::$_model_map) ? array_search($v, self::$_model_map) : 7;
     $logData = ['date' => date('Ymd'), 'model' => 1, 'controller' => SsdPHP::getController(), 'action' => SsdPHP::getAction(), 'session_id' => session_id(), 'session_val' => json_encode($_SESSION, JSON_UNESCAPED_UNICODE), 'custom_val' => json_encode(Response::getData(), JSON_UNESCAPED_UNICODE), 'create_time' => $_SERVER['REQUEST_TIME'], 'sql' => json_encode(Mysql::getSqlRecord())];
     $s = $SystemLog->addLog($logData);
 }
예제 #4
0
 /**
  * call event when you need.
  */
 public static function call()
 {
     if (!SsdPHP::isDebug()) {
         $ISCGI = 0 === strpos(PHP_SAPI, 'cgi') || false !== strpos(PHP_SAPI, 'fcgi') ? true : false;
         /* 冲刷(flush)所有响应的数据给客户端并结束请求。 这使得客户端结束连接后,需要大量时间运行的任务能够继续运行 */
         $ISCGI && fastcgi_finish_request();
     }
     foreach (self::$_events as $event) {
         $callback = array_shift($event);
         call_user_func_array($callback, $event);
     }
 }
예제 #5
0
파일: Route.php 프로젝트: ssdphp/ssdphp
 /**
  * 支持cli
  * author xiaohuihui <*****@*****.**>
  */
 private static function parse()
 {
     if (PHP_SAPI == 'cli') {
         $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : '/';
     }
     $REQUEST_URI = !empty($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['REQUEST_URI'];
     foreach (self::$_Routes as $pattern => $pathInfo) {
         preg_match("{$pattern}", $REQUEST_URI, $r);
         if (isset($r[0]) && !empty($r)) {
             $url = preg_replace($pattern, $pathInfo, $REQUEST_URI);
             SsdPHP::setPathInfo($url);
             break;
         }
     }
     return;
 }
예제 #6
0
파일: Factory.php 프로젝트: ssdphp/ssdphp
 public static function getInstance($adapter = 'Smarty', $config = array())
 {
     if (empty($config)) {
         $appdir = realpath(SsdPHP::getRootPath() . SsdPHP::getAppDir());
         $model = SsdPHP::getModel();
         $templates_c = $appdir . DIRECTORY_SEPARATOR . $model . DIRECTORY_SEPARATOR . "templates_c/";
         $template_dir = $appdir . DIRECTORY_SEPARATOR . $model . DIRECTORY_SEPARATOR . "templates/";
         $templates_config = $appdir . DIRECTORY_SEPARATOR . $model . DIRECTORY_SEPARATOR . "templates_config/";
         $templates_plugins = $appdir . DIRECTORY_SEPARATOR . $model . DIRECTORY_SEPARATOR . "templates_plugins/";
         $config = SConfig::get("View");
         if (!empty($config['Adaptor'])) {
             $adapter = $config['Adaptor'];
         }
         $config = array_merge($config, array('templates_c' => $templates_c, 'template_dir' => $template_dir, 'templates_config' => $templates_config, 'templates_plugins' => $templates_plugins));
     }
     $className = __NAMESPACE__ . "\\Adaptor\\{$adapter}";
     return SFactory::getInstance($className, $config);
 }
예제 #7
0
파일: Language.php 프로젝트: ssdphp/ssdphp
 /**
  * 加载资源包文件
  * @author  xiaohuihui  <*****@*****.**>
  * @param string $srcPath
  * @param string $defaultModel
  * @param string $Lang
  */
 public static function load($srcPath = "", $defaultModel = "", $Lang = "zh")
 {
     if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $langstr = $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "";
         switch (strtolower($langstr[0] . $langstr[1])) {
             case 'zh':
                 $Lang = 'zh';
                 break;
             case 'en':
                 $Lang = 'en';
                 break;
             default:
                 $Lang = 'zh';
         }
     }
     if ($srcPath == "") {
         $srcPath = SsdPHP::getRootPath() . "resources/lang/" . $Lang . "/";
     }
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($srcPath . $defaultModel));
     if (SsdPHP::isDebug() == false) {
         fileatime($srcPath);
         if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($srcPath)) {
             self::$LanguageAry = (include $tmpfile);
             return;
         }
     }
     $files = Dir::tree($srcPath, "/.php\$/");
     $Language = array();
     if ($defaultModel != "") {
         $langFile = $srcPath . $defaultModel . ".php";
         if (is_file($langFile)) {
             $Language = (include "{$langFile}");
         }
     } elseif (!empty($files)) {
         foreach ($files as $file) {
             $Language += (include "{$file}");
         }
     }
     //end if
     self::$LanguageAry = $Language;
     self::$LanguagePath = $srcPath;
     file_put_contents($tmpfile, "<?php return " . var_export($Language, true) . ";?>", LOCK_EX);
     return;
 }
예제 #8
0
파일: Config.php 프로젝트: ssdphp/ssdphp
 /**
  * 加载配置文件
  * @param $configPath 配置文件放置的目录
  * @return array|mixed
  */
 public static function load($configPath)
 {
     $tmpfile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(realpath($configPath));
     fileatime($configPath);
     if (is_file($tmpfile) && filemtime($tmpfile) >= filemtime($configPath) && !SsdPHP::isDebug()) {
         self::$config = (include $tmpfile);
         return;
     }
     $files = Dir::tree($configPath, "/.php\$/");
     $config = array();
     if (!empty($files)) {
         foreach ($files as $file) {
             $config += (include "{$file}");
         }
     }
     self::$config = $config;
     self::$configPath = $configPath;
     file_put_contents($tmpfile, "<?php return " . var_export($config, true) . ";?>", LOCK_EX);
     return;
 }
예제 #9
0
파일: Tpl.php 프로젝트: ssdphp/ssdphp
 public static function fetch($tpl = "")
 {
     if (empty($tpl)) {
         $tpl = SsdPHP::getController() . "/" . SsdPHP::getAction();
     }
     $tpl_real = self::$template_dir . "/" . $tpl . self::$config['tpl_suffix'];
     if (!is_dir(self::$compile_dir)) {
         mkdir(self::$compile_dir, 0777, true);
     }
     $compiled_file = self::$compile_dir . "/" . base64_encode($tpl) . ".%%.tpl";
     if (self::$force_compile || !is_file($compiled_file) || filemtime($tpl_real) > filemtime($compiled_file)) {
         $compiled_contents = self::_compile(file_get_contents($tpl_real));
         file_put_contents($compiled_file, $compiled_contents, LOCK_EX);
     }
     ob_start();
     include $compiled_file;
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
예제 #10
0
파일: index.php 프로젝트: ssdphp/ssdphp
 public function index()
 {
     $str = "MECARD:TEL:18883878456;URL:http://xinghuiblog.com;EMAIL:xzh_tx@163.com;NOTE:123456789;N:小谢;ORG:小村科技;TIL:php;ADR:南坪;";
     echo $str;
     //数据库操作
     //$res = MysqlFactory::getInstance()->select("ip");
     //CacheFactory::getInstance()->set("ip",50);
     //RegShutdownEvent::add('\App\Task\Email::sendEmail','*****@*****.**','xhh','test','body','\App\Task\Email::callback');
     //RegShutdownEvent::add('\App\Task\Sms::sendTextMessage','1888xxxxxxx','你的验证码是xxx','\App\Task\Sms::callback');
     /*echo Input::get("ni",0,"intval");
       Session::set('nihao',123);
       echo Session::get('nihao');*/
     // 创建日志频道
     //$a = new Db();
     //$a->test();
     /*Session::set('nihao',123);
       echo Session::get('nihao');
       $s = SFactory::getInstance('App\Home\model\Student')->Login("a","b");
       print_r($s);
       View::getInstance()->assign(array('a'=>"ni","b"=>"<br>123"))->display();*/
     echo SsdPHP::getModel();
 }
예제 #11
0
파일: upload.php 프로젝트: ssdphp/ssdphp
<?php

/*{{{LICENSE
+-----------------------------------------------------------------------+
| SsdPHP Framework                                                   |
+-----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or modify  |
| it under the terms of the GNU General Public License as published by  |
| the Free Software Foundation. You should have received a copy of the  |
| GNU General Public License along with this program.  If not, see      |
| http://www.gnu.org/licenses/.                                         |
| Copyright (C) 2015-2020. All Rights Reserved.                         |
+-----------------------------------------------------------------------+
| Supports: http://www.SsdPHP.com                                    |
+-----------------------------------------------------------------------+
}}}*/
//视图配置
use SsdPHP\SsdPHP;
return ['Upload' => ['mimes' => array(), 'exts' => array(), 'autoSub' => true, 'subName' => array('date', 'Ymd'), 'rootPath' => SsdPHP::getRootPath() . 'www/product/', 'savePath' => '', 'saveName' => array('md5_file', ''), 'saveExt' => '', 'replace' => true, 'hash' => true, 'callback' => false, 'driver' => '', 'driverConfig' => array()]];
예제 #12
0
파일: File.php 프로젝트: ssdphp/ssdphp
 private function getPath()
 {
     return !empty($this->config['save_path']) ? $this->config['save_path'] : SsdPHP::getRootPath() . 'session_tmp';
 }
예제 #13
0
파일: Error.php 프로젝트: ssdphp/ssdphp
 /**
  * 致命错误捕获
  */
 public static function fatalError()
 {
     if ($e = error_get_last()) {
         switch ($e['type']) {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_COMPILE_ERROR:
             case E_USER_ERROR:
                 if (PHP_SAPI != 'cli') {
                     ob_end_clean();
                     if (SsdPHP::isDebug()) {
                         echo "\n\t\t\t\t\t\t<table border='1' cellpadding='3' style='font-size: 75%;border: 1px solid #000000;border-collapse: collapse;'><tr bgcolor='red'><td colspan='4' style='color: white'>fatalError!</td></tr><tr style='background-color: #ccccff; font-weight: bold; color: #000000;'> <th >type</th><th >File</th><th >Line</th><th >Message</th></tr><tr style='background-color: #cccccc; color: #000000;'><td>{$e['type']}</td><td>{$e['file']}</td><td>{$e['line']}</td><td>{$e['message']}</td></tr></table><hr style='background-color: #cccccc; border: 0px; height: 1px;' />";
                     }
                 }
                 break;
         }
     }
 }
예제 #14
0
파일: Factory.php 프로젝트: ssdphp/ssdphp
 /**
  * URL组装 支持不同URL模式
  * @param string $url URL表达式,格式:'[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...'
  * @param string|array $vars 传入的参数,支持数组和字符串
  * @param string|boolean $suffix 伪静态后缀,默认为true表示获取配置值
  * @param boolean $domain 是否显示域名
  * @return string
  */
 function U($url = '', $vars = '', $suffix = true, $domain = false)
 {
     // 解析URL
     $info = parse_url($url);
     $murl = SsdPHP::getController() . "/" . SsdPHP::getAction();
     $url = !empty($info['path']) ? $info['path'] : $murl;
     if (isset($info['fragment'])) {
         // 解析锚点
         $anchor = $info['fragment'];
         if (false !== strpos($anchor, '?')) {
             // 解析参数
             list($anchor, $info['query']) = explode('?', $anchor, 2);
         }
         if (false !== strpos($anchor, '@')) {
             // 解析域名
             list($anchor, $host) = explode('@', $anchor, 2);
         }
     } elseif (false !== strpos($url, '@')) {
         // 解析域名
         list($url, $host) = explode('@', $info['path'], 2);
     }
     // 解析子域名
     if (isset($host)) {
         $domain = $host . (strpos($host, '.') ? '' : strstr($_SERVER['HTTP_HOST'], '.'));
     } elseif ($domain === true) {
         $domain = $_SERVER['HTTP_HOST'];
         if (C('APP_SUB_DOMAIN_DEPLOY')) {
             // 开启子域名部署
             $domain = $domain == 'localhost' ? 'localhost' : 'www' . strstr($_SERVER['HTTP_HOST'], '.');
             // '子域名'=>array('模块[/控制器]');
             foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) {
                 $rule = is_array($rule) ? $rule[0] : $rule;
                 if (false === strpos($key, '*') && 0 === strpos($url, $rule)) {
                     $domain = $key . strstr($domain, '.');
                     // 生成对应子域名
                     $url = substr_replace($url, '', 0, strlen($rule));
                     break;
                 }
             }
         }
     }
     // 解析参数
     if (is_string($vars)) {
         // aaa=1&bbb=2 转换成数组
         parse_str($vars, $vars);
     } elseif (!is_array($vars)) {
         $vars = array();
     }
     if (isset($info['query'])) {
         // 解析地址里面参数 合并到vars
         parse_str($info['query'], $params);
         $vars = array_merge($params, $vars);
     }
     // URL组装
     //$depr       =   C('URL_PATHINFO_DEPR');
     //$urlCase    =   C('URL_CASE_INSENSITIVE');
     $depr = SsdPHP::getSplitFlag();
     $urlCase = SConfig::get('URL_CASE_INSENSITIVE', true);
     $url = "/" . $murl . "?";
     if ($urlCase) {
         $url = strtolower($url);
     }
     if (!empty($vars)) {
         $vars = http_build_query($vars);
         $url .= $vars;
     }
     if (isset($anchor)) {
         $url .= '#' . $anchor;
     }
     if ($domain) {
         $url = ($this->is_ssl() ? 'https://' : 'http://') . $domain . $url;
     }
     return $url;
 }
예제 #15
0
파일: index.php 프로젝트: ssdphp/ssdphp
    $rootpath = __DIR__ . '/../../../../';
    require $rootpath . 'vendor/autoload.php';
} elseif ($autoload = realpath(__DIR__ . "/../vendor/autoload.php")) {
    require $autoload;
}
if (!class_exists('\\SsdPHP\\SsdPHP')) {
    require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . "SsdPHP" . DIRECTORY_SEPARATOR . "SsdPHP.php";
}
use SsdPHP\Core\RegShutdownEvent, SsdPHP\Core\Route, SsdPHP\Core\Error, SsdPHP\Core\Config, SsdPHP\Core\Language, SsdPHP\SsdPHP;
use SsdPHP\Pulgins\Session\Factory as Session;
SsdPHP::setRootPath($rootpath);
if (($r = SsdPHP::Bootstrap(function () {
    date_default_timezone_set('PRC');
    RegShutdownEvent::register();
    SsdPHP::setAppDir("App");
    SsdPHP::setDebug(true);
    Error::$CONSOLE = SsdPHP::isDebug();
    Config::load(SsdPHP::getRootPath() . DIRECTORY_SEPARATOR . 'config');
    Route::set(Config::getField('ROUTE', 'home', array()));
    Language::load();
    Session::Start($config = Config::get('SessionApiUser'));
})->Run()) === false) {
    header('HTTP/1.1 404 Not Found');
    header('Status: 404 Not Found');
    echo "404 error";
} else {
    echo $r;
}
$end = microtime(true);
echo SsdPHP::isDebug() ? "<!--" . "SsdPHP" . "Framwork runtime=" . ($end - $start) . "秒" . "-->" : "";