Example #1
0
 /**
  * 构造函数
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!function_exists('sqlite_open')) {
         spError('PHP环境未安装Sqlite函数库!');
     }
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'sqlite_popen' : 'sqlite_open';
     if (!($this->conn = $linkfunction($dbConfig['host'], 0666, $sqliteerror))) {
         spError('数据库链接错误/无法找到数据库 : ' . $sqliteerror);
     }
 }
Example #2
0
File: sae.php Project: daolei/grw
 /**
  * 构造函数
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (TRUE == SP_DEBUG) {
         sae_set_display_errors(TRUE);
     }
     $this->conn = new SaeMysql();
     if ($this->conn->errno()) {
         spError("数据库链接错误 : " . $this->conn->error());
     }
     $this->conn->setCharset("UTF8");
 }
Example #3
0
 /**
  * 显示模板
  * @param tplname 模板名称
  */
 public function display($tplname)
 {
     if (file_exists(realpath($this->template_dir) . '/' . $tplname)) {
         $tplpath = realpath($this->template_dir) . '/' . $tplname;
     } elseif (file_exists($tplname)) {
         $tplpath = $tplname;
     } else {
         spError("speedy引擎:无法找到模板 " . $tplname);
     }
     extract($this->_vars);
     if (TRUE == $this->enable_gzip) {
         global $__speedy_compression_level;
         $__speedy_compression_level = $this->compression_level;
         ob_start('speedy_ob_gzip');
     }
     include $tplpath;
 }
Example #4
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!function_exists('oci_connect')) {
         spError('PHP环境未安装ORACLE函数库!');
     }
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'oci_pconnect' : 'oci_connect';
     if (!($this->conn = $linkfunction($dbConfig['login'], $dbConfig['password'], $dbConfig['host'], 'AL32UTF8'))) {
         $e = oci_error();
         spError('数据库链接错误 : ' . strip_tags($e['message']));
     }
 }
Example #5
0
 public function __construct()
 {
     if (!function_exists('xcache_set')) {
         spError('PHP环境未安装Xcache函数库!');
     }
 }
Example #6
0
/**
 * spCore
 *
 * SpeedPHP应用框架的系统执行程序
 */
// 定义系统路径
if (!defined('SP_PATH')) {
    define('SP_PATH', dirname(__FILE__) . '/SpeedPHP');
}
if (!defined('APP_PATH')) {
    define('APP_PATH', dirname(__FILE__) . '/app');
}
// 载入核心函数库
require SP_PATH . "/spFunctions.php";
if (substr(PHP_VERSION, 0, 1) != '5') {
    spError("SpeedPHP框架环境要求PHP5!");
}
// 载入配置文件
$GLOBALS['G_SP'] = spConfigReady(require SP_PATH . "/spConfig.php", $spConfig);
// 根据配置文件进行一些全局变量的定义
if ('debug' == $GLOBALS['G_SP']['mode']) {
    define("SP_DEBUG", TRUE);
    // 当前正在调试模式下
} else {
    define("SP_DEBUG", FALSE);
    // 当前正在部署模式下
}
// 如果是调试模式,打开警告输出
if (SP_DEBUG) {
    if (substr(PHP_VERSION, 0, 3) == "5.3") {
        error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
Example #7
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!function_exists('mssql_connect')) {
         spError('PHP环境未安装MSSQL函数库!');
     }
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'mssql_pconnect' : 'mssql_connect';
     $this->conn = $linkfunction($dbConfig['host'], $dbConfig['login'], $dbConfig['password']) or spError("数据库链接错误 : " . mssql_get_last_message());
     mssql_select_db($dbConfig['database'], $this->conn) or spError("无法找到数据库,请确认数据库名称正确!");
 }
Example #8
0
/**
 * spCore
 *
 * SpeedPHP应用框架的系统执行程序
 */
// 定义系统路径
if (!defined('SP_PATH')) {
    define('SP_PATH', dirname(__FILE__));
}
if (!defined('APP_PATH')) {
    define('APP_PATH', dirname(dirname(__FILE__)));
}
// 载入核心函数库
require SP_PATH . '/spFunctions.php';
if (substr(PHP_VERSION, 0, 1) != '5') {
    spError('SpeedPHP框架环境要求PHP5!');
}
// 载入配置文件
$GLOBALS['G_SP'] = spConfigReady(require SP_PATH . '/spConfig.php', $spConfig);
// 设置错误处理函数
//set_error_handler('spErrorHandler');
@set_magic_quotes_runtime(0);
// 载入核心MVC架构文件
import($GLOBALS['G_SP']['sp_core_path'] . '/spController.php', FALSE, TRUE);
import($GLOBALS['G_SP']['sp_core_path'] . '/spModel.php', FALSE, TRUE);
import($GLOBALS['G_SP']['sp_core_path'] . '/spView.php', FALSE, TRUE);
// 当在二级目录中使用SpeedPHP框架时,自动获取当前访问的文件名
if ('' == $GLOBALS['G_SP']['url']['url_path_base']) {
    if (basename($_SERVER['SCRIPT_NAME']) === basename($_SERVER['SCRIPT_FILENAME'])) {
        $GLOBALS['G_SP']['url']['url_path_base'] = $_SERVER['SCRIPT_NAME'];
    } elseif (basename($_SERVER['PHP_SELF']) === basename($_SERVER['SCRIPT_FILENAME'])) {
Example #9
0
 function error($message, $tplname)
 {
     spError($message . $tplname);
 }
Example #10
0
/**
 * spErrorHandler 系统错误提示函数
 * @param errno    出错类型
 * @param errstr    错误信息
 * @param errfile    出错的文件
 * @param errline    出错语句行号
 */
function spErrorHandler($errno, $errstr, $errfile, $errline)
{
    if (E_ERROR == $errno || E_PARSE == $errno) {
        spError($errstr);
    }
}
Example #11
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'mysql_pconnect' : 'mysql_connect';
     $this->conn = $linkfunction($dbConfig['host'] . ":" . $dbConfig['port'], $dbConfig['login'], $dbConfig['password']) or spError("数据库链接错误 : " . mysql_error());
     mysql_select_db($dbConfig['database'], $this->conn) or spError("无法找到数据库,请确认数据库名称正确!");
     $this->exec("SET NAMES UTF8");
 }
Example #12
0
 private function getTableInfo($table)
 {
     mysql_select_db($this->database, $this->conn) or spError("无法链接数据库或者没有" . $this->database . "数据库访问权限。");
     $sql = "select * from `{$this->database}`.`{$table}` WHERE 1";
     $rs = $this->getArray($sql);
     //获取crate sql
     if (is_array($rs)) {
         $filed = $val = '';
         //处理字段
         foreach ($rs[0] as $k => $v) {
             $filed .= '`' . $k . '` ,';
         }
         $filed = substr($filed, 0, -1);
         //去掉多余的逗号
         foreach ($rs as $d) {
             $vas = '';
             foreach ($d as $va) {
                 if (is_numeric($va)) {
                     $vas .= $va . ',';
                 } else {
                     $vas .= "'" . addslashes($va) . "',";
                 }
             }
             $vas = substr($vas, 0, -1);
             $val .= '(' . $vas . "),{$this->ln}";
         }
         $sql = "{$this->ln}{$this->ln}INSERT INTO `{$table}` ";
         $sql .= "( {$filed} ) VALUES {$this->ln} {$val}";
         $sql = substr($sql, 0, -2) . ';';
         return $sql . $this->ln . $this->ln;
     } else {
         return $this->ln . $this->ln;
     }
 }
Example #13
0
 /**
  * 构造函数
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!function_exists('oci_connect')) {
         spError('PHP环境未安装ORACLE函数库!');
     }
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'oci_pconnect' : 'oci_connect';
     if (!($this->conn = $linkfunction($dbConfig['login'], $dbConfig['password'], $dbConfig['host'], 'AL32UTF8'))) {
         $e = oci_error();
         spError('数据库链接错误 : ' . strip_tags($e['message']));
     }
     $this->exec('ALTER SESSION SET NLS_DATE_FORMAT = \'yyyy-mm-dd hh24:mi:ss\'');
 }
Example #14
0
 public function forumline($user_id)
 {
     if ($this->forum_open) {
         $num_per_page = 4;
         $args = array("page" => 2);
         $uc_id = $this->spArgs('ucid');
         if ($user_id) {
             $conditions['user_id'] = $user_id;
             $args['uid'] = $user_id;
             if (!$uc_id) {
                 $ptx_user = spClass("ptx_user");
                 $user = $ptx_user->getuser_byid($user_id);
                 $uc_id = $user['uc_id'];
             }
         }
         if (!$uc_id || !is_numeric($uc_id)) {
             spError(T('no_bbs_account_bind'));
             return;
         }
         $args['ucid'] = $uc_id;
         $conditions['authorid'] = $uc_id;
         $next_time = $this->spArgs("next_time");
         $this->need_static = false;
         if ($next_time) {
             $now = $next_time;
         } else {
             $now = time();
             $this->need_static = $this->page == 1 ? true : false;
         }
         $forum_post = spClass('forum_post');
         $conditions['lt_time'] = $now;
         $last_post = $forum_post->find_one($conditions, " forum_post.dateline DESC ", " forum_post.pid,forum_post.dateline ");
         $last_time = $last_post['dateline'];
         $last_post_month = (int) date('m', $last_time);
         $last_post_month_days = (int) date('t', $last_time);
         $last_post_year = (int) date('Y', $last_time);
         $this_month_time_first = time(0, 0, 0, $last_post_month, 1, $last_post_year);
         $this_month_time_last = time(24, 59, 59, $last_post_month, $last_post_month_days, $last_post_year);
         $conditions['gt_time'] = $this_month_time_first;
         $conditions['lt_time'] = $this_month_time_last;
         $this_month_last_post = $forum_post->find_one($conditions, " forum_post.dateline DESC ", " forum_post.pid,forum_post.dateline ");
         $posts = $forum_post->search($conditions, $this->page, $num_per_page, NULL, " forum_post.dateline DESC ");
         if (array_length($posts) == $num_per_page) {
             $next_search_time = $posts[$num_per_page - 1]['dateline'];
             //$this->resetPage = true;
         } else {
             $next_search_time = $this_month_time_first;
             $this->resetPage = true;
         }
         if ($this_month_last_post['pid'] == $posts[0]['pid']) {
             $this->timeline_date = $last_post_year . '年' . $last_post_month . '月';
         }
         $forum_attachment = spClass('forum_attachment');
         foreach ($posts as $key => $post) {
             $posts[$key]['images'] = $forum_attachment->search_attach_images($post['pid']);
             $post['message'] = messageclean($post['message']);
             $post['message'] = tpl_modifier_bbcode2html($post['message']);
             $posts[$key]['message'] = $post['message'];
         }
         $args['next_time'] = $next_search_time;
         $this->nextpage_url = spUrl($this->current_controller, $this->current_action, $args);
         $this->forumlineView($posts, 'post');
         //$this->set_user_banner($user_id);
         $this->output("user/forumline");
     }
 }
Example #15
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!class_exists("PDO")) {
         spError('PHP环境未安装PDO函数库!');
     }
     try {
         $this->conn = new PDO($dbConfig['host'], $dbConfig['login'], $dbConfig['password']);
     } catch (PDOException $e) {
         echo '数据库链接错误/无法找到数据库 :  ' . $e->getMessage();
     }
 }
Example #16
0
/**
 * spClass  类实例化函数  自动载入类定义文件,实例化并返回对象句柄
 * 
 * @param class_name    类名称
 * @param args   类初始化时使用的参数,数组形式
 * @param sdir 载入类定义文件的路径,可以是目录+文件名的方式,也可以单独是目录。sdir的值将传入import()进行载入
 * @param force_inst 是否强制重新实例化对象
 */
function spClass($class_name, $args = null, $sdir = null, $force_inst = FALSE)
{
    // 检查类名称是否正确,以保证类定义文件载入的安全性
    if (preg_match('/[^a-z0-9\\-_.]/i', $class_name)) {
        spError($class_name . "类名称错误,请检查。");
    }
    // 检查是否该类已经实例化,直接返回已实例对象,避免再次实例化
    if (TRUE != $force_inst) {
        if (isset($GLOBALS['G_SP']["inst_class"][$class_name])) {
            return $GLOBALS['G_SP']["inst_class"][$class_name];
        }
    }
    // 如果$sdir不能读取,则测试是否仅路径
    if (null != $sdir && !import($sdir) && !import($sdir . '/' . $class_name . '.php')) {
        return FALSE;
    }
    $has_define = FALSE;
    // 检查类定义是否存在
    if (class_exists($class_name, false) || interface_exists($class_name, false)) {
        $has_define = TRUE;
    } else {
        if (TRUE == import($class_name . '.php')) {
            $has_define = TRUE;
        }
    }
    if (FALSE != $has_define) {
        $argString = '';
        $comma = '';
        if (null != $args) {
            for ($i = 0; $i < count($args); $i++) {
                $argString .= $comma . "\$args[{$i}]";
                $comma = ', ';
            }
        }
        eval("\$GLOBALS['G_SP']['inst_class'][\$class_name]= new \$class_name({$argString});");
        return $GLOBALS['G_SP']["inst_class"][$class_name];
    }
    spError($class_name . "类定义不存在,请检查。");
}
Example #17
0
 /** 
  * 按规则验证数据
  * 
  * @param values    验证值
  */
 private function checkrules($values)
 {
     $this->checkvalues = $values;
     foreach ($this->verifier["rules"] as $rkey => $rval) {
         $inputval = isset($values[$rkey]) ? $values[$rkey] : '';
         foreach ($rval as $rule => $rightval) {
             if (method_exists($this, $rule)) {
                 if (TRUE == $this->{$rule}($inputval, $rightval)) {
                     continue;
                 }
             } elseif (null != $this->add_rules && isset($this->add_rules[$rule])) {
                 if (function_exists($this->add_rules[$rule])) {
                     if (TRUE == $this->add_rules[$rule]($inputval, $rightval, $values)) {
                         continue;
                     }
                 } elseif (is_array($this->add_rules[$rule])) {
                     if (TRUE == spClass($this->add_rules[$rule][0])->{$this->add_rules[$rule][1]}($inputval, $rightval, $values)) {
                         continue;
                     }
                 }
             } else {
                 spError("未知规则!");
             }
             $this->messages[$rkey][] = isset($this->verifier["messages"][$rkey][$rule]) ? $this->verifier["messages"][$rkey][$rule] : "{$rule}";
         }
     }
     // 返回FALSE则通过验证,返回数组则未能通过验证,返回的是提示信息。
     return null == $this->messages ? FALSE : $this->messages;
 }
Example #18
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!function_exists('mysqli_connect')) {
         spError('PHP环境未安装MySQLi函数库!');
     }
     $linkfunction = TRUE == $dbConfig['persistent'] ? 'mysqli_pconnect' : 'mysqli_connect';
     $this->conn = $linkfunction($dbConfig['host'], $dbConfig['login'], $dbConfig['password'], $dbConfig['database'], $dbConfig['port']);
     if (mysqli_connect_errno()) {
         spError('数据库链接错误/无法找到数据库 : ' . mysqli_connect_error());
     }
     $this->exec("SET NAMES UTF8");
 }
Example #19
0
 /**
  * 魔术函数,实现对控制器扩展类的自动加载
  */
 public function __call($name, $args)
 {
     if (in_array($name, $GLOBALS['G_SP']["auto_load_controller"])) {
         return spClass($name)->__input($args);
     } elseif (!method_exists($this, $name)) {
         spError("方法 {$name}未定义!<br />请检查是否控制器类(" . get_class($this) . ")与数据模型类重名?");
     }
 }
Example #20
0
 /**
  * 构造函数
  *
  * @param dbConfig  数据库配置
  */
 public function __construct($dbConfig)
 {
     if (!class_exists("PDO")) {
         spError('PHP环境未安装PDO函数库!');
     }
     try {
         $this->conn = new PDO($dbConfig['host'], $dbConfig['login'], $dbConfig['password'], array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
     } catch (PDOException $e) {
         spError('数据库链接错误/无法找到数据库 :  ' . $e->getMessage());
     }
 }
Example #21
0
 *							// 将使得 http://www.example.com/search.html 转向控制器main/动作serach执行
 *							// 特例 '@' => 'main@no' 如果映射是@,将使得符合以下条件的网址转向到 控制器main/动作no执行:
 *							// 1. 在map中无法找到其他映射,2. 网址第一个参数并非控制器名称。			
 *			),
 *			'args' => array( // 网址映射附加的隐藏参数,如果针对某个网址映射设置了隐藏参数,则在网址中仅会存在参数值,而参数名称被隐藏。
 *						 	 // 比如 'search' => array('q','page'), 那么生成的网址将会是:
 *							 // http://www.example.com/search-thekey-2.html
 *							 // 配合map映射'search' => 'main@search',这个网址将会执行 控制器main/动作serach,
 *							 // 而参数q将等于thekey,参数page将等于2
 *			),
 *		),
 * ),
 *
 */
if (SP_VERSION < 2.5) {
    spError('spUrlRewrite扩展要求SpeedPHP框架版本2.5以上。');
}
class spUrlRewrite
{
    var $params = array('suffix' => '.html', 'sep' => '-', 'map' => array(), 'args' => array());
    /**
     * 构造函数,处理配置
     */
    public function __construct()
    {
        $params = spExt('spUrlRewrite');
        if (is_array($params)) {
            $this->params = array_merge($this->params, $params);
        }
    }
    /**
Example #22
0
 /**
  * 生成单个静态页面
  * 
  * @param spurl spUrl的参数
  * @param alias_url 生成HTML文件的名称,如果不设置alias_url,将使用年月日生成目录及随机数为文件名的形式生成HTML文件。
  * @param update_mode    更新模式,默认2为同时更新列表及文件
  * 0是仅更新列表
  * 1是仅更新文件
  */
 public function make($spurl, $alias_url = null, $update_mode = 2)
 {
     if (1 == spAccess('r', 'sp_html_making')) {
         $this->spurls[] = array($spurl, $alias_url);
         return;
     }
     @(list($controller, $action, $args, $anchor) = $spurl);
     if ($url_item = spHtml::getUrl($controller, $action, $args, $anchor, TRUE)) {
         @(list($baseuri, $realfile) = $url_item);
         $update_mode = 1;
     } else {
         $file_root_name = '' == $GLOBALS['G_SP']['html']['file_root_name'] ? '' : $GLOBALS['G_SP']['html']['file_root_name'] . '/';
         if (null == $alias_url) {
             $filedir = $file_root_name . date('Y/n/d') . '/';
             $filename = substr(time(), 3, 10) . substr(mt_rand(100000, substr(time(), 3, 10)), 4) . ".html";
         } else {
             $filedir = $file_root_name . dirname($alias_url) . '/';
             $filename = basename($alias_url);
         }
         $baseuri = rtrim(dirname($GLOBALS['G_SP']['url']["url_path_base"]), '/\\') . "/" . $filedir . $filename;
         $realfile = APP_PATH . "/" . $filedir . $filename;
     }
     if (0 == $update_mode or 2 == $update_mode) {
         spHtml::setUrl($spurl, $baseuri, $realfile);
     }
     if (1 == $update_mode or 2 == $update_mode) {
         $remoteurl = 'http://' . $_SERVER["SERVER_NAME"] . ':' . $_SERVER['SERVER_PORT'] . '/' . ltrim(spUrl($controller, $action, $args, $anchor, TRUE), '/\\');
         $cachedata = file_get_contents($remoteurl);
         if (FALSE === $cachedata) {
             $cachedata = $this->curl_get_file_contents($remoteurl);
             if (FALSE === $cachedata) {
                 spError("无法从网络获取页面数据,请检查:<br />1. spUrl生成地址是否正确!<a href='{$remoteurl}' target='_blank'>点击这里测试</a>。<br />2. 设置php.ini的allow_url_fopen为On。<br />3. 检查是否防火墙阻止了APACHE/PHP访问网络。<br />4. 建议安装CURL函数库。");
             }
         }
         __mkdirs(dirname($realfile));
         file_put_contents($realfile, $cachedata);
     }
 }