/** * 首页 * * @author mrmsl <*****@*****.**> * @date 2013-04-25 21:39:23 * * @return void 无返回值 */ public function indexAction() { $blog_arr = $this->_getBlogs(); //$miniblog = $this->_getLatesttMiniblog(); $this->getViewTemplate()->assign('blog_arr', $blog_arr)->assign('web_title', sys_config('sys_base_web_index_title')); $this->_display(); }
/** * 验证帐号是否被锁定 * * @author mrmsl <*****@*****.**> * @date 2012-07-12 09:02:21 * @lastmodify 2013-01-22 11:47:43 by mrmsl * * @param array $admin_info 管理员信息 * * @return mixed true未被锁定,否则返回错误信息 */ private function _checkLock($admin_info) { if ($admin_info['lock_start_time'] && $admin_info['lock_start_time'] < APP_NOW_TIME && $admin_info['lock_end_time'] && $admin_info['lock_end_time'] > APP_NOW_TIME) { $info = L('ACCOUNT_IS_LOCKED,TO') . new_date(sys_config('sys_timezone_datetime_format'), $admin_info['lock_end_time']); $this->addLog("{$admin_info['username']}[{$admin_info['realname']}] {$info}", LOG_TYPE_ADMIN_LOGIN_INFO); return $info; } return true; }
/** * 获取文件列表 * * @author mrmsl <*****@*****.**> * @date 2012-07-17 12:46:02 * * @param string $node 节点路径 * * @return array 文件列表 */ private function _getFile($node) { $node = trim($node, '/'); $this->_denyDirectory($node); $file_arr = array(); $directory = PACKER_JS_PATH . $node . '/'; $k = 0; if (is_dir($directory)) { $date_format = sys_config('sys_timezone_datetime_format'); $d = dir($directory); while ($f = $d->read()) { if ($f == '.' || $f == '..' || substr($f, 0, 1) == '.') { continue; } $filename = $directory . '/' . $f; if (is_dir($filename)) { $file_arr[$k] = array('text' => $f, 'checked' => $f == 'pack' ? null : false, 'id' => $node . '/' . $f); $file_arr[$k]['data'] = $this->_getFile($f); $k++; } elseif (substr($f, -3) == '.js' && !in_array($f, array('app.js'))) { $desc = ''; //js文件说明 $file = new SplFileObject($filename); if (!strpos($filename, '.min.')) { $file->fgets(); $desc = trim(str_replace('*', '', $file->fgets())); //第二行为文件说明 } $file_arr[] = array('text' => $f, 'id' => $node . '/' . $f, 'leaf' => true, 'checked' => $node == 'pack' ? null : false, 'filesize' => format_size($file->getSize()), 'filemtime' => new_date($date_format, $file->getMTime()), 'desc' => $desc); } } //end while $d->close(); } //end if return $file_arr; }
/** * 底部 * * @author mrmsl <*****@*****.**> * @date 2013-05-10 13:30:10 * * @param array $info ssi信息 * * @return void 无返回值 */ private function _ssi_footer($info) { $this->getViewTemplate('build_html')->assign('footer', sys_config('sys_base_copyright')); $this->_buildHtml(WWWROOT . $info['html_name'] . C('HTML_SUFFIX'), $this->_fetch($info['_controller'], $info['_action'])); }
/** * 设置邮箱配置 * * @author mrmsl <*****@*****.**> * @date 2013-06-06 09:22:33 * * @param array $config 配置信息,默认null,通过sys_config()获取 * * @return void 无返回值 */ public function setConfig($config = null) { $config = null === $config ? sys_config() : $config; $this->Host = $config['sys_mail_smtp']; $this->Port = $config['sys_mail_smtp_port']; $this->Username = $config['sys_mail_email']; $this->Password = $config['sys_mail_password']; $this->SetFrom($config['sys_mail_email'], $config['sys_mail_from_name']); }
/** * 获取视图模板引擎实例 * * @author mrmsl <*****@*****.**> * @data 2013-04-12 15:36:13 * @lastmodify 2013-04-15 17:05:13 by mrmsl * * @param mixed $config 模板引擎配置。默认null.为build_html生成静态页时,$config = array('_caching' => true, '_force_compile' => false); * * @return object 视图模板引擎实例 */ public function getViewTemplate($config = null) { if (!$this->_view_template) { $this->_view_template = Template::getInstance(); $this->_view_template->assign(sys_config())->assign('me', $this)->assign('nav_id', strtolower(CONTROLLER_NAME)); } if (null !== $config) { //属性 if ('build_html' === $config) { //生成静态页 $config = array('_caching' => false, '_force_compile' => false); } foreach ($config as $k => $v) { $this->_view_template->{$k} = $v; } } return $this->_view_template; }
/** * * 字符串加密、解密函数,摘自{@link http://www.phpcms.cn phpcms} * * @lastmodify 2013-01-22 17:24:08 by mrmsl * * @param string $str 字符串 * @param string $encode 是否为加密,默认true,是 * @param string $key 密钥 * * @return string 经加密或解密后字符串 */ function sys_auth($str, $encode = true, $key = '') { $key = $key ? $key : sys_config('sys_security_auth_key'); $str = $encode ? $str : base64_decode($str); if ($key) { //密钥为空 $len = strlen($key); $code = ''; for ($i = 0, $n = strlen($str); $i < $n; $i++) { $k = $i % $len; $code .= $str[$i] ^ $key[$k]; } } else { $code = $str; } return $encode ? base64_encode($code) : $code; }
/** * {@inheritDoc} */ protected function _infoCallback(&$admin_info) { unset($admin_info['password']); $admin_info['lock_start_time'] = $admin_info['lock_start_time'] ? new_date(sys_config('sys_timezone_datetime_format'), $admin_info['lock_start_time']) : ''; $admin_info['lock_end_time'] = $admin_info['lock_end_time'] ? new_date(sys_config('sys_timezone_datetime_format'), $admin_info['lock_end_time']) : ''; }
/** * 写日志 * * @author liu21st <*****@*****.**> * @lastmodify 2013-01-17 09:26:44 by mrmsl * * @param string $message 日志信息。默认'',取已保存日志 * @param string $destination 写入目标。默认'',日志路径+Y/md/+文件名 * @param int $type 日志记录方式。默认'',取C('LOG_TYPE') * @param string $extra 额外信息。默认'' * * @return void 无返回值 */ public static function write($message = '', $destination = '', $type = '', $extra = '') { $log = $message ? $message : join(PHP_EOL, self::$log); if (!$log) { return; } $log .= PHP_EOL; $now = new_date(self::$date_format); $type = $type ? $type : C('LOG_TYPE'); if (!$type || self::FILE == $type) { //文件方式记录日志 if (defined('TODAY_LOG_PATH')) { $log_path = TODAY_LOG_PATH; } else { new_mkdir($log_path = LOG_PATH . new_date('Y/md/')); define('TODAY_LOG_PATH', $log_path); } if ('' === $destination) { $filename = 'php' . C('LOG_FILE_SUFFIX'); } elseif ($destination) { if (false === strpos($destination, C('LOG_FILE_SUFFIX'))) { //sql.log, slowquery.log, errorsql.log... $filename = $destination . C('LOG_FILE_SUFFIX'); } } $destination = empty($filename) ? $destination : $log_path . $filename; //检测日志文件大小,超过配置大小则备份日志文件重新生成 if (is_file($destination) && ($filesize = sys_config('sys_log_filesize')) && $filesize * 1024 <= filesize($destination)) { rename($destination, $log_path . basename($filename, C('LOG_FILE_SUFFIX')) . new_date('_His') . C('LOG_FILE_SUFFIX')); } } else { $destination = $destination ? $destination : C('LOG_DEST'); $extra = $extra ? $extra : C('LOG_EXTRA'); } if (APP_DEBUG && strpos($log, 'PHP ')) { //调试模式,输出php错误 send_http_status(HTTP_STATUS_SERVER_ERROR); if (!IS_AJAX) { echo nl2br($log); } } error_log($log, $type, $destination, $extra); }
/** * {@inheritDoc} */ protected function _infoCallback(&$cate_info) { $cate_info['add_time'] = new_date(sys_config('sys_timezone_datetime_format'), $cate_info['add_time']); }
/** * 记录事务回滚 * * @author mrmsl <*****@*****.**> * @date 2013-01-02 14:29:11 * @lastmodify 2013-01-16 15:36:32 by mrmsl * * @return void 无返回值 */ protected function _writeRollbackSql() { C(array('LOG_LEVEL' => E_APP_ROLLBACK_SQL, 'LOG_FILENAME' => 'rollbacksql')); trigger_error($rollback_sql = join(EOL_LF . '<br />', $this->_sql_arr)); return; if (sys_config('sys_log_rollback_sql') && false === strpos($this->_query_str, ' ' . $this->_parseTable(TB_LOG) . ' ')) { $last_sql = $this->_query_str; D('Log')->addLog($rollback_sql, LOG_TYPE_ROLLBACK_SQL); $this->_setLastSql($last_sql); } }
/** * 生成系统常量 * * @author mrmsl <*****@*****.**> * @date 2013-05-03 15:15:19 * * @param array $sys_config 系统信息。默认array(),取sys_config() * * @return void 无返回值 */ public function publicDefineSystemConstantsAction($sys_config = array()) { $filename = INCLUDE_PATH . 'app_config.tpl.php'; //常量模板 $tpl = file_get_contents($filename); $sys_config = $sys_config ? $sys_config : sys_config(); $content = preg_replace("#sys_config\\('(\\w+)'\\)#e", '"\'" . addslashes($sys_config["\\1"]) . "\'"', $tpl); $find = array('@@lastmodify', '@WEB_COOKIE_DOMAIN', '@WEB_SESSION_COOKIE_DOMAIN', '@WEB_ADMIN_ENTRY', '@AUTO_CREATE_COMMENT'); $replace = array(new_date(), '@domain' == ($cookie_domain = $sys_config['sys_cookie_domain']) ? 'WEB_DOMAIN_SCOPE' : "'{$cookie_domain}'", '@domain' == ($session_cookie_domain = $sys_config['sys_session_cookie_domain']) ? 'WEB_DOMAIN_SCOPE' : "'{$session_cookie_domain}'", 0 === strpos('http://', $v = $sys_config['sys_base_admin_entry']) ? "'{$v}'" : "BASE_SITE_URL . '{$v}'", '后台自动生成,请毋修改。最后更新时间: ' . new_date()); $content = str_replace($find, $replace, $content); file_put_contents(INCLUDE_PATH . 'app_config.php', $content); //写文件 if (!APP_DEBUG && is_file(RUNTIME_FILE)) { //constants.php已经包含进运行时文件。干掉 unlink(RUNTIME_FILE); } }
/** * 回复留言评论 * * @author mrmsl <*****@*****.**> * @date 2013-06-03 17:11:14 * * @return void 无返回值 */ public function replyAction() { $comment_id = Filter::int($this->_pk_field); $add_time = Filter::int('add_time'); if (!$comment_id && !$add_time) { //非法参数 $log = L('REPLY,CONTROLLER_NAME,%.,INVALID_PARAM') . "{$this->_pk_field}({$comment_id}),add_time({$add_time})"; $msg = L('INVALID_PARAM'); } elseif (!($comment_info = $this->_model->where(array($this->_pk_field => $comment_id, 'add_time' => $add_time))->find())) { //不存在 $log = L('REPLY,CONTROLLER_NAME') . ".{$this->_pk_field}({$comment_id}),add_time({$add_time})" . L('NOT_EXIST'); $msg = L('CONTROLLER_NAME,NOT_EXIST'); } elseif (COMMENT_REPLY_TYPE_ADMIN == $comment_info['admin_reply_type']) { // $msg = L('CONTROLLER_NAME_ADMIN,REPLY,%。,CAN_NOT,REPLY'); $log = L('REPLY,CONTROLLER_NAME') . '.admin_reply_type=' . COMMENT_REPLY_TYPE_ADMIN . ',' . $msg; } elseif (!($content = Filter::raw('content'))) { $log = L('REPLY,CONTROLLER_NAME') . ".{$this->_pk_field}" . L('REPLY,CONTENT,IS_EMPTY'); $msg = L('PLEASE_ENTER,REPLY,CONTENT'); } elseif ('<p>' != substr($content, 0, 3)) { $content = '<p>' . $content . '</p>'; } if (!empty($msg)) { //错误 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log; trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $msg); } $this->_model->startTrans(); $ip_info = get_ip_info(); //ip地址信息 if (is_array($ip_info)) { $province = $ip_info[0]; $city = $ip_info[1]; } else { $province = ''; $city = $ip_info; } $db = $this->_model->getDb(); $data = array('province' => $province, 'city' => $city, 'content' => $content); if (COMMENT_REPLY_TYPE_REPLIED == $comment_info['admin_reply_type']) { //已经回复 $add = false; $reply_info = $this->_model->field($this->_pk_field . ',content')->where('admin_reply_type=' . COMMENT_REPLY_TYPE_ADMIN . ' AND real_parent_id=' . $comment_id)->find(); $log = $this->_dataDiff(array('content' => $reply_info['content']), $data); $db->update($data, array('table' => TB_COMMENTS, 'where' => "{$this->_pk_field}={$reply_info[$this->_pk_field]}")); } else { $add = true; $data = $data + array('parent_id' => $comment_id, 'real_parent_id' => $comment_id, 'add_time' => time(), 'username' => sys_config('module_guestbook_comments_reply_admin_username', 'Module'), 'email' => sys_config('module_guestbook_comments_reply_admin_email', 'Module'), 'user_pic' => str_replace('@common_imgcache@', COMMON_IMGCACHE, sys_config('module_guestbook_comments_reply_admin_img', 'Module')), 'user_ip' => get_client_ip(1), 'user_homepage' => BASE_SITE_URL, 'admin_reply_type' => COMMENT_REPLY_TYPE_ADMIN, 'status' => COMMENT_STATUS_PASS, 'type' => $comment_info['type'], 'blog_id' => $comment_info['blog_id'], 'at_email' => 1, 'level' => $comment_info['level'] + 1); $reply = '@<a class="link" href="#comment-' . $comment_info['comment_id'] . '" rel="nofollow">' . $comment_info['username'] . '</a> '; $data['content'] = substr_replace($data['content'], '<p>' . $reply, 0, 3); if (false === $this->_model->getDb()->insert($data, array('table' => TB_COMMENTS))) { $this->_sqlErrorExit(L('REPLY,FAILURE')); } $insert_id = $db->getLastInsertID(); $max_reply_level = $this->getGuestbookCommentsSetting(COMMENT_TYPE_GUESTBOOK == $comment_info['type'] ? 'module_guestbook' : 'module_comments', 'max_reply_level'); if ($max_reply_level == $comment_info['level']) { //最多5层回复 $comment_info['level']--; $comment_info['node'] = substr($comment_info['node'], 0, strrpos($comment_info['node'], ',')); $node_arr = explode(',', $comment_info['node']); $parent_id = $node_arr[$max_reply_level > 2 ? $max_reply_level - 2 : 1]; //父级id取第四个 } $update = array('level' => $comment_info['level'] + 1, 'node' => $comment_info['node'] . ',' . $insert_id); if (!empty($parent_id)) { $update['parent_id'] = $parent_id; } C('_FACADE_SKIP', true); $this->_model->where($this->_pk_field . '=' . $comment_id)->save(array('admin_reply_type' => COMMENT_REPLY_TYPE_REPLIED)); //已经回复 $this->_model->where($this->_pk_field . '=' . $insert_id)->save($update); $this->_model->where(array($this->_pk_field => array('IN', $comment_info['node'])))->save(array('last_reply_time' => time())); //更新最上层最后回复时间 //干掉静态页,重新统计评论数等 $a = array($comment_id); $b = ''; $this->_beforeExec($a, $b); //处理发送有回复邮件 if ($comment_info['at_email']) { C('T_INFO.at_email', $this->_getMailCommentsInfo($comment_id, C('T_INFO.delete_blog_html'))); $this->_afterSetField('status', null, null); } $log = $content; } $this->_model->addLog(L('REPLY,GUESTBOOK_COMMENTS') . $this->_pk_field . "({$comment_id})" . $log); $this->_ajaxReturn(true, L('REPLY,SUCCESS')); }
/** * {@inheritDoc} */ protected function _infoCallback(&$cate_info) { $cate_info['add_time'] = new_date(sys_config('sys_timezone_datetime_format'), $cate_info['add_time']); $cate_info['cate_name'] = $this->_getCache($cate_info['cate_id'] . '.cate_name', 'Category'); }
/** * 初始化session * * @author mrmsl <*****@*****.**> * @date 2012-12-25 10:06:31 * * @return void 无返回值 */ private function _initSession() { $config = array('name' => sys_config('sys_session_name'), 'save_path' => sys_config('sys_session_save_path'), 'gc_maxlifetime' => sys_config('sys_session_gc_maxlifetime'), 'use_trans_sid' => sys_config('sys_session_use_trans_sid'), 'use_cookies' => sys_config('sys_session_use_cookies'), 'use_only_cookies' => sys_config('sys_session_use_only_cookies'), 'cookie_lifetime' => sys_config('sys_session_cookie_lifetime'), 'cookie_path' => sys_config('sys_session_cookie_path'), 'cookie_domain' => WEB_SESSION_COOKIE_DOMAIN, 'cookie_secure' => sys_config('sys_session_cookie_secure'), 'cookie_httponly' => sys_config('sys_session_cookie_httponly'), 'save_handler' => sys_config('sys_session_save_handler')); if (!isset($_SERVER['argv'])) { //function_exists('ob_gzhandler') ? ob_start('ob_gzhandler') : ob_start(); ob_start(); session($config); C(SESSION_ADMIN_KEY, session(SESSION_ADMIN_KEY)); //管理员信息 } }
define('WEB_JS_PATH', WWWROOT . sys_config('sys_base_js_path')); //js物理路径 define('WEB_JS_LANG_PATH', WEB_JS_PATH . 'lang/'); //js语言包物理路径 define('WEB_CSS_PATH', WWWROOT . sys_config('sys_base_css_path')); //css物理路径 define('COMMON_IMGCACHE', sys_config('sys_base_common_imgcache')); //imgcache define('ADMIN_IMGCACHE', sys_config('sys_base_admin_imgcache')); //后台imgcache define('IMGCACHE_JS', sys_config('sys_base_js_url')); //js url define('IMGCACHE_CSS', sys_config('sys_base_css_url')); //css url define('IMGCACHE_IMG', sys_config('sys_base_img_url')); //img url define('TITLE_SEPARATOR', ' ' . sys_config('sys_show_title_separator') . ' '); //标题分割符 define('BREAD_SEPARATOR', ' <span class="divider">' . sys_config('sys_show_bread_separator') . '</span> '); //面包屑分割符 //session,cookie设置 define('SESSION_PREFIX', sys_config('sys_session_prefix')); //session前缀 define('COOKIE_EXPIRE', sys_config('sys_cookie_expire')); //过期时间 define('COOKIE_DOMAIN', WEB_COOKIE_DOMAIN); //作用域 define('COOKIE_PATH', sys_config('sys_cookie_path')); //路径 define('COOKIE_PREFIX', sys_config('sys_cookie_prefix')); //前缀,避免冲突
/** * 记录错误查询 * * @author mrmsl <*****@*****.**> * @date 2013-01-02 14:25:36 * @lastmodify 2013-01-16 15:35:56 by mrmsl * * @return void 无返回值 */ protected function _writeErrorSql() { if (sys_config('sys_log_sqlerror') && !defined('DB_CONNECT_ERROR') && false === strpos($this->_query_str, ' ' . $this->_parseTable(TB_LOG) . ' ')) { $log = get_method_line(__METHOD__, __LINE__, LOG_SQL_ERROR) . $this->_query_str . PHP_EOL . $this->_error; trigger_error($log); } }