コード例 #1
0
ファイル: Factory.php プロジェクト: ssdphp/ssdphp
 public static function getInstance($adapter = 'Local', $config = null)
 {
     if (empty($config)) {
         $config = SConfig::get('Upload');
         if (!empty($config['driver'])) {
             $adapter = $config['driver'];
         }
     }
     /* 获取配置 */
     self::$config = array_merge(self::$config, $config);
     /* 调整配置,把字符串配置参数转换为数组 */
     if (!empty(self::$config['mimes'])) {
         if (is_string(self::$config['mimes'])) {
             self::$config['mimes'] = explode(',', self::$config['mimes']);
         }
         self::$config['mimes'] = array_map('strtolower', self::$config['mimes']);
     }
     if (!empty(self::$config['exts'])) {
         if (is_string(self::$config['exts'])) {
             self::$config['exts'] = explode(',', self::$config['exts']);
         }
         self::$config['exts'] = array_map('strtolower', self::$config['exts']);
     }
     $className = __NAMESPACE__ . "\\Adaptor\\{$adapter}";
     self::$uploader = SFactory::getInstance($className, $config);
     static $Upload;
     if (!is_object($Upload)) {
         $Upload = new Factory();
     }
     return $Upload;
 }
コード例 #2
0
ファイル: Factory.php プロジェクト: ssdphp/ssdphp
 public static function getInstance($adapter = 'Email', $config = null)
 {
     if (empty($config)) {
         $config = SConfig::getField($adapter, "Main");
     }
     $className = __NAMESPACE__ . "\\Adaptor\\{$adapter}";
     return SFactory::getInstance($className, $config);
 }
コード例 #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
ファイル: Email.php プロジェクト: ssdphp/ssdphp
 /**
  * 发送邮件
  * @see RegShutdownEvent::add('Home\controller\index::taskEmail','*****@*****.**','xhh','test','body');
  * @author  xiaohuihui  <*****@*****.**>
  * @param $toEmail
  * @param $toUser
  * @param $title
  * @param $body
  */
 public static function sendEmail($toEmail, $toUser, $title, $content, $callback = null)
 {
     if (!$toEmail || !$title) {
         return;
     }
     $result = EmailFactory::getInstance()->send_mail($toEmail, $toUser, $title, $content);
     $callbackData = array('email' => $toEmail, 'status' => (int) $result, 'time' => time(), 'content' => $content, 'type' => SConfig::getField('Email', 'Main')['EmailType']);
     if (is_callable($callback)) {
         call_user_func_array($callback, array("data" => $callbackData));
     }
 }
コード例 #5
0
ファイル: file.php プロジェクト: ssdphp/ssdphp
 function jstoken()
 {
     $accessKey = Config::getField("Qiniu", "AK");
     $secretKey = Config::getField("Qiniu", "SK");
     $auth = new Auth($accessKey, $secretKey);
     // 空间名  http://developer.qiniu.com/docs/v6/api/overview/concepts.html#bucket
     $bucket = Config::getField("Qiniu", "bucket");
     // 生成上传Token
     $token = $auth->uploadToken($bucket, $key = null, 3600, array());
     $t = array("uptoken" => $token, "domain" => Config::getField("Qiniu", "domain"));
     Response::apiJsonResult($t, 1);
 }
コード例 #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
ファイル: Factory.php プロジェクト: ssdphp/ssdphp
 /**
  * 初始化缓存
  * @param string $adapter 适配器(缓存驱动类)
  * @param string $ConfKey  读取配置最顶层名
  * @return mixed
  */
 public static function getInstance($adapter = 'Redis', $ConfKey = "Redis")
 {
     if (empty($adapter)) {
         $adapter = 'Redis';
     }
     if (empty($ConfKey)) {
         $ConfKey = $adapter;
     }
     $classKey = $adapter . "_" . $ConfKey;
     if (isset(self::$CacheObj[$classKey]) && is_object(self::$CacheObj[$classKey])) {
         return self::$CacheObj[$classKey];
     }
     $class = __CLASS__;
     self::$CacheObj[$classKey] = SFactory::getInstance($class);
     //{{{设置对象缓存属性
     self::$CacheObj[$classKey]->setAdapter($adapter);
     self::$CacheObj[$classKey]->setConfKey($ConfKey);
     self::$CacheObj[$classKey]->setConfig(Config::get($ConfKey));
     //}}}
     return self::$CacheObj[$classKey];
 }
コード例 #8
0
ファイル: Factory.php プロジェクト: ssdphp/ssdphp
 public static function Start($config = null)
 {
     if (self::$isStart === false) {
         if (empty($config)) {
             $config = SConfig::get('Session');
         }
         if (!empty($config['new_cache_expire'])) {
             session_cache_expire($config['new_cache_expire']);
             $lifetime = $config['new_cache_expire'] * 60;
             //ini_set('session.gc_maxlifetime', $lifetime);
             //ini_set('session.cookie_lifetime', $lifetime);
         }
         //$path = empty($config['path']) ? '/' : $config['path'];
         //$domain = empty($config['domain']) ? '' : $config['domain'];
         //$secure = empty($config['secure']) ? false : $config['secure'];
         //$httponly = !isset($config['httponly']) ? true : $config['httponly'];
         //session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
         ini_set('session.cookie_httponly', !isset($config['httponly']) ? true : $config['httponly']);
         if (isset($config['domain'])) {
             ini_set('session.cookie_domain', $config['domain']);
         }
         if (isset($config['cache_limiter'])) {
             session_cache_limiter($config['cache_limiter']);
         }
         $sessionName = empty($config['session_name']) ? 'SSDPHPSESSID' : $config['session_name'];
         session_name($sessionName);
         if (!empty($_GET[$sessionName])) {
             session_id($_GET[$sessionName]);
         } elseif (!empty($_SERVER[$sessionName])) {
             session_id($_SERVER[$sessionName]);
         }
         //print_r($_GET);
         if (!empty($config['sessionType'])) {
             $handler = self::getInstance($config['sessionType'], $config);
             session_set_save_handler(array($handler, 'open'), array($handler, 'close'), array($handler, 'read'), array($handler, 'write'), array($handler, 'destroy'), array($handler, 'gc'));
         }
         session_start();
         self::$isStart = true;
     }
 }
コード例 #9
0
ファイル: Sms.php プロジェクト: ssdphp/ssdphp
 public static function sendTextMessage($toPhone, $Content = "", $callback = null)
 {
     //短信URL
     $SMS_SEND_ONE_URL = SConfig::getField('SMS', 'SMS_SEND_ONE_URL', "http://mb345.com:999/ws/batchSend.aspx?CorpID={\$SMS_ACCOUNT}&Pwd={\$SMS_PWD}&Mobile={\$toPhone}&Cell=&SendTime=&Content={\$Content}");
     //短信帐号
     $SMS_ACCOUNT = SConfig::getField('SMS', 'SMS_ACCOUNT');
     //短信密码
     $SMS_PWD = SConfig::getField('SMS', 'SMS_PWD');
     $SMS_CHARSET = SConfig::getField('SMS', 'SMS_CHARSET', "GBK");
     $SMS_SEND_ONE_URL = preg_replace(array('/\\{\\$SMS_ACCOUNT\\}/', '/\\{\\$SMS_PWD\\}/', '/\\{\\$toPhone\\}/', '/\\{\\$Content\\}/'), array($SMS_ACCOUNT, $SMS_PWD, $toPhone, iconv('UTF-8', $SMS_CHARSET, $Content)), $SMS_SEND_ONE_URL);
     if (SConfig::getField('SMS', 'SMS_IS_DEVELOP', false) === false) {
         $result = file_get_contents($SMS_SEND_ONE_URL);
         $result = $result >= 0 ? 1 : 0;
     } else {
         $result = 1;
         //开发模式,始终成功
     }
     $callbackData = array('phone' => $toPhone, 'status' => $result, 'time' => time(), 'content' => $Content, 'type' => SConfig::getField('SMS', 'SMS_TYPE', 1));
     if (is_callable($callback)) {
         call_user_func_array($callback, array("data" => $callbackData));
     }
     return;
 }
コード例 #10
0
ファイル: Response.php プロジェクト: ssdphp/ssdphp
 /**
  * 操作错误跳转的快捷方法
  * @access public
  * @param mixed $msg 提示信息
  * @param mixed $data 返回的数据
  * @param mixed $url 跳转的URL地址
  * @param mixed $wait 跳转等待时间
  * @return mixed
  */
 public static function error($msg = '', $data = '', $url = '', $wait = 3)
 {
     $code = 0;
     if (is_numeric($msg)) {
         $code = $msg;
         $msg = '';
     }
     $result = ['code' => $code, 'msg' => $msg, 'data' => $data, 'url' => $url ?: 'javascript:history.back(-1);', 'wait' => $wait];
     $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
     if ('html' == $type) {
         $result = \think\View::instance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
     }
     self::type($type);
     return $result;
 }
コード例 #11
0
ファイル: Input.php プロジェクト: ssdphp/ssdphp
 /**
  * 获取过滤方法
  * @return array
  */
 private static function getFilter()
 {
     if (is_null(static::$filters)) {
         // 从配置项中读取
         $filters = Config::get('default_filter');
         static::$filters = empty($filters) ? [] : (is_array($filters) ? $filters : explode(',', $filters));
     }
     return static::$filters;
 }
コード例 #12
0
ファイル: Factory.php プロジェクト: ssdphp/ssdphp
 public function __call($name, $arguments)
 {
     $name = strtolower($name);
     if (in_array($name, self::$read_array)) {
         self::getInstance('Mysql', $config = SConfig::getField("Mysql", "Slave"));
     } elseif (in_array($name, self::$write_array)) {
         self::getInstance('Mysql', $config = SConfig::getField("Mysql", "Main"));
     }
     if (self::$page !== null && is_numeric(self::$page)) {
         self::$_instance->setPage(self::$page);
     }
     if (self::$pagesize !== null && is_numeric(self::$pagesize)) {
         self::$_instance->setLimit(self::$pagesize);
     }
     if (self::$count !== null) {
         self::$_instance->setCount(self::$count);
     }
     if (self::$startTransaction !== null) {
         self::$_instance->execute('SET AUTOCOMMIT=0');
         self::$_instance->execute('BEGIN');
     }
     if (self::$commit !== null) {
         self::$_instance->execute('COMMIT');
         self::$_instance->execute('SET AUTOCOMMIT=1');
     }
     if (self::$rollBack !== null) {
         self::$_instance->execute('ROLLBACK');
         self::$_instance->execute('SET AUTOCOMMIT=1');
     }
     $count = count($arguments);
     $table = self::$prefix . self::$table;
     switch ($count) {
         case 0:
             $res = self::$_instance->{$name}($table);
             break;
         case 1:
             $res = self::$_instance->{$name}($table, $arguments[0]);
             break;
         case 2:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1]);
             break;
         case 3:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1], $arguments[2]);
             break;
         case 4:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1], $arguments[2], $arguments[3]);
             break;
         case 5:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]);
             break;
         case 6:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5]);
             break;
         case 7:
             $res = self::$_instance->{$name}($table, $arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4], $arguments[5], $arguments[6]);
             break;
     }
     return $res;
 }
コード例 #13
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;
 }
コード例 #14
0
ファイル: index.php プロジェクト: ssdphp/ssdphp
if (is_file(__DIR__ . '/../../../../vendor/autoload.php')) {
    $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) . "秒" . "-->" : "";