/** * 详请 * * @author mrmsl <*****@*****.**> * @date 2013-02-21 13:47:40 * @lastmodify 2013-04-26 23:13:01 * * @return void 无返回值 */ public function detailAction() { $blog_id = Filter::int('id', 'get'); $date = Filter::int('date', 'get'); if (!$blog_id || !$date) { //非法参数 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . "date=({$date}),id=({$blog_id})"; trigger_error($log); $this->_showMessage('error' . $blog_id . $date, null, 404); } if ($blog_info = $this->_model->find($blog_id)) { if (date('Ymd', $blog_info['add_time']) != $date) { //日期与id不匹配 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . "date=({$date}),id=({$blog_id})"; trigger_error($log); $this->_showMessage('error' . $blog_id . ',' . $date, null, 404); } $filename = str_replace(BASE_SITE_URL, WWWROOT, $blog_info['link_url']); new_mkdir(dirname($filename)); $o = $this->getViewTemplate('build_html')->assign('blog_info', $blog_info)->assign(array('web_title' => L('MINIBLOG,DETAIL') . TITLE_SEPARATOR . L('MINIBLOG'), 'comments_html' => $this->_getBlogComments($blog_id))); $content = $o->fetch(CONTROLLER_NAME, 'detail', $blog_id); //file_put_contents($filename, $content); echo $content; } else { //微博不存在 $this->_showMessage(L('MINIBLOG,NOT_EXIST'), null, 404); } }
/** * 禁止路径 * * @author mrmsl <*****@*****.**> * @date 2012-07-10 15:40:01 * * @param string $path 待检测路径 * * @return void 无返回值 */ private function _denyDirectory($path) { if (false !== strpos($path, '..')) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path; trigger_error($log, E_USER_ERROR); send_http_status(HTTP_STATUS_SERVER_ERROR); $this->_ajaxReturn(true, L('LIST_DIRECTORY_FORBIDDEN') . PACKER_JS_PATH . $path); } }
/** * 列表 * * @author mrmsl <*****@*****.**> * @date 2013-06-07 11:09:51 * * @return void 无返回值 */ public function listAction() { $sort = Filter::string('sort', 'get', $this->_pk_field); //排序字段 if (!in_array($sort, $this->_getDbFields())) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('QUERY,CONTROLLER_NAME,%。,ORDER,COLUMN') . $sort . L('NOT_EXIST'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('SERVER_ERROR')); } $order = !empty($_GET['dir']) ? Filter::string('dir', 'get') : Filter::string('order', 'get'); //排序 $order = toggle_order($order); $keyword = Filter::string('keyword', 'get'); //关键字 $date_start = Filter::string('date_start', 'get'); //开始时间 $date_end = Filter::string('date_end', 'get'); //结束时间 $template_id = Filter::int('template_id', 'get'); // $column = Filter::string('column', 'get'); //搜索字段 $where = array(); if ('' !== $keyword && in_array($column, array('subject', 'content', 'email'))) { $where[$column] = $this->_buildMatchQuery($column, $keyword, Filter::string('match_mode', 'get')); } if ($date_start && ($date_start = strtotime($date_start))) { $where['add_time'][] = array('EGT', $date_start); } if ($date_end && ($date_end = strtotime($date_end))) { $where['add_time'][] = array('ELT', $date_end); } if (isset($where['add_time']) && count($where['add_time']) == 1) { $where['add_time'] = $where['add_time'][0]; } if ($template_id) { $where['template_id'] = $template_id; } $total = $this->_model->where($where)->count(); if ($total === false) { //查询出错 $this->_sqlErrorExit(L('QUERY,CONTROLLER_NAME') . L('TOTAL_NUM,ERROR')); } elseif ($total == 0) { //无记录 $this->_ajaxReturn(true, '', null, $total); } $page_info = Filter::page($total); $data = $this->_model->where($where)->limit($page_info['limit'])->order('' . $sort . ' ' . $order)->select(); $data === false && $this->_sqlErrorExit(L('QUERY,CONTROLLER_NAME') . L('LIST,ERROR')); //出错 $templates = $this->cache(false, 'Mail'); foreach ($data as &$v) { $v['template_name'] = isset($templates[$id = $v['template_id']]) ? $templates[$id]['template_name'] : ''; } $this->_ajaxReturn(true, '', $data, $total); }
/** * 入口 * * @author mrmsl <*****@*****.**> * @date 2012-09-27 17:26:23 * @lastmodify 2013-01-22 11:02:32 by mrmsl * * @return void 无返回值 */ public function indexAction() { $module = Filter::get('module', 'get'); //模块 $error = ''; if (!APP_DEBUG) { //非调试模式 if (!REFERER_PAGER) { $error = L('REFERER_PAGER,IS_EMPTY'); } elseif (strpos(REFERER_PAGER, WEB_SITE_URL) === false) { $error = L('REFERER_PAGER') . '(' . REFERER_PAGER . ')' . L('IS_EMPTY'); } } if (!$error) { if (!$module) { $error = 'module' . L('IS_EMPTY'); } elseif (!in_array($module, $this->_verifycode_module)) { $error = 'module not in (' . join(',', $this->_verifycode_module) . ')'; } else { $verifycode_setting = get_verifycode_setting($module); //验证码设置 //未开启验证码 if (!$verifycode_setting['enable']) { $default_setting = get_verifycode_setting('sys', 'enable'); //默认设置 $error = L('NOT_HAS,TURN_ON') . "(module:{$verifycode_setting['enable']}|sys:{$default_setting})"; } } } if ($error) { //有错误 $log = get_method_line(__METHOD__, __LINE__, LOG_VERIFYCODE_ERROR) . L('VERIFY_CODE') . "({$module})" . $error; trigger_error($log); $exit = true; } elseif (!check_verifycode_limit($module, 'refresh')) { //刷新次数限制 $exit = true; } if (!empty($exit)) { header('Content-type: image/png'); readfile(IMGCACHE_PATH . 'common/images/verifycode_error.png'); exit; } $width = $verifycode_setting['width']; //宽 $height = $verifycode_setting['height']; //高 $length = $verifycode_setting['length']; //字母长 $type = $verifycode_setting['type']; //类型 $img = new Verifycode(); $img->buildVerifyImage($verifycode_setting['length'], $verifycode_setting['type'], $verifycode_setting['width'], $verifycode_setting['height']); }
/** * swsi * * @author mrmsl <*****@*****.**> * @date 2013-05-18 09:50:30 * * @param string $tpl_name s * * @return void 无返回值 */ protected function _checkTplName($tpl_name) { $arr = explode('/', $tpl_name); if (2 != count($arr)) { return false; } elseif (false !== strpos($tpl_name, '..')) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('TRY,USE,RELATIVE,PATH') . $tpl_name; trigger_error($log, E_USER_ERROR); return L('TPL_NAME,CAN_NOT,USE,RELATIVE,PATH'); } elseif (!is_file(FRONT_THEME_PATH . $tpl_name . C('TEMPLATE_SUFFIX'))) { return L('TEMPLATE,NOT_EXIST'); } return true; }
/** * ueditor上传图片操作 * * @author mrmsl <*****@*****.**> * @date 2013-07-12 22:22:13 * * @return void 无返回值 */ public function ueditorUploadImageAction() { $config = array('_upload_dir' => UPLOAD_PATH); $upload = new Image_Upload(); $date = date('Ymd/'); $result = $upload->execute('upfile', UPLOAD_PATH . $date); if (isset($result['errstr'])) { //出错 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . var_export($result, true); trigger_error($log); $result = array('state' => $result['errstr']); } else { $result = array('state' => 'SUCCESS', 'originalName' => $result['name'], 'name' => $result['filename'], 'url' => $date . $result['filename'], 'size' => $result['size'], 'type' => $result['type']); } exit(json_encode($result)); }
/** * 详请 * * @author mrmsl <*****@*****.**> * @date 2013-02-21 15:26:00 * @lastmodify 2013-04-23 14:32:00 by mrmsl * * @return void 无返回值 */ public function detailAction() { $blog_id = Filter::int('id', 'get'); $date = Filter::int('date', 'get'); if (!$blog_id || !$date) { //非法参数 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . "date=({$date}),id=({$blog_id})"; trigger_error($log); $this->_showMessage('error' . $blog_id . $date, null, 404); } if ($blog_info = $this->_model->find($blog_id)) { if (date('Ymd', $blog_info['add_time']) != $date) { //日期与id不匹配 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . "date=({$date}),id=({$blog_id})"; trigger_error($log); $this->_showMessage('error' . $blog_id . ',' . $date, null, 404); } if (!$blog_info['is_issue'] || $blog_info['is_delete']) { //未发布或已删除 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . "is_delete=({$blog_info['is_delete']}),is_issue=({$blog_info['is_issue']})"; trigger_error($log); $this->_showMessage('error' . $blog_info['is_issue'] . ',' . $blog_info['is_delete'], null, 404); } $filename = str_replace(BASE_SITE_URL, WWWROOT, $blog_info['link_url']); new_mkdir(dirname($filename)); $o = $this->getViewTemplate('build_html')->assign($this->_getNextAndPrevBlog($blog_id))->assign('blog_info', $blog_info)->assign(array('web_title' => $blog_info['title'] . TITLE_SEPARATOR . $this->nav($blog_info['cate_id'], 'cate_name', 'Category', TITLE_SEPARATOR) . TITLE_SEPARATOR . L('CN_WANGWEN'), 'seo_keywords' => $blog_info['seo_keyword'], 'seo_description' => $blog_info['seo_description'], 'tags' => $this->tags($blog_info['seo_keyword']), 'relative_blog' => $this->_getRelativeBlog($blog_id, $blog_info['seo_keyword']), 'comments_html' => $this->_getBlogComments($blog_id))); $content = $o->fetch(CONTROLLER_NAME, 'detail', $blog_id); //file_put_contents($filename, $content); echo $content; } else { //博客不存在 $this->_showMessage(L('BLOG,NOT_EXIST'), null, 404); } }
/** * ajax异步获取博客,微博元数据,包括点击量,评论数等 * * @author mrmsl <*****@*****.**> * @date 2013-05-02 16:21:34 * @lastmodify 2013-05-03 08:41:05 by mrmsl * * @return void 无返回值 */ public function metaInfoAction() { /*foreach (array(TB_BLOG, TB_MINIBLOG) as $table) { foreach($this->_model->table($table)->select() as $v) { $sql = sprintf('UPDATE %s SET hits=%d,comments=%d,diggs=%d WHERE blog_id=%d', $table, rand(1, 1000), rand(1, 50), rand(1, 20), $v['blog_id']); $this->_model->execute($sql); } }*/ $this->_updateHits(); //统计点击 $blog = Filter::string('blog'); $miniblog = Filter::string('miniblog'); if (!$blog && !$miniblog) { //空数据 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('INVALID_PARAM'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false); } $blog = 0 === strpos($blog, ',') ? substr($blog, 1) : $blog; $miniblog = 0 === strpos($miniblog, ',') ? substr($miniblog, 1) : $miniblog; $field_arr = 'blog_id,add_time'; $field = 'blog_id,add_time,hits,comments,diggs'; $miniblog_data = $this->_getPairsData($field_arr, $miniblog, $field, 'blog_id', TB_MINIBLOG); $blog_data = $this->_getPairsData($field_arr, $blog, $field, 'blog_id', TB_BLOG); $this->_ajaxReturn(array('blog' => $blog_data, 'miniblog' => $miniblog_data, 'success' => true)); }
/** * 验证自动创建数据是否成功 * * @author mrmsl <*****@*****.**> * @lastmodify 2013-01-22 11:25:30 by mrmsl * * @param string $method 自动验证数据方法。默认create * * @return string|true true验证成功,返回true,否则返回错误信息 */ public function checkCreate($method = 'create') { if ('POST' != REQUEST_METHOD && !__GET) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM); $log .= L(empty($this->data[$this->getPk()]) ? 'ADD' : 'EDIT') . L('CONTROLLER_NAME,FAILURE,%: ,DATA_TYPE_INVALID'); trigger_error($log, E_USER_ERROR); return L('DATA_TYPE_INVALID'); } $result = true; if (!$this->{$method}()) { $error = $this->getError(); $error = is_array($error) ? join(PHP_EOL, $error) : $error; $log = get_method_line(__METHOD__, __LINE__, LOG_VALIDATE_FORM_ERROR); $log .= L('VALIDATE') . L(empty($this->data[$this->getPk()]) ? 'ADD' : 'EDIT') . L('CONTROLLER_NAME,FAILURE') . ': ' . $error; trigger_error($log); $result = nl2br($error); } return $result; }
/** * 添加或编辑 * * @author mrmsl <*****@*****.**> * @data 2013-06-21 11:05:10 * * @return void 无返回值 */ public function addAction() { $check = $this->_model->checkCreate(); //自动创建数据 $check !== true && $this->_ajaxReturn(false, $check); //未通过验证 $pk_field = $this->_pk_field; //主键 $pk_value = $this->_model->{$pk_field}; //id $data = $this->_model->getProperty('_data'); //数据,$model->data 在save()或add()后被重置为array() $diff_key = 'module_name,var_name,var_value_zh_cn,var_value_en,sort_order,memo,to_js'; //比较差异字段 $msg = L($pk_value ? 'EDIT' : 'ADD'); //添加或编辑 $log_msg = $msg . L('LANGUAGE_ITEM,FAILURE'); //错误日志 $error_msg = $msg . L('FAILURE'); //错误提示信息 if (!($module_info = $this->cache($module_id = $this->_model->module_id, 'LanguageModules'))) { //语言包模块不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,LANGUAGE_MODULE,%module_id({$module_id}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } $data['module_name'] = $module_info['module_name']; //语言包模块名 if ($pk_value) { //编辑 if (!($item_info = $this->cache($pk_value))) { //语言项不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,CONTROLLER_NAME,%{$pk_field}({$pk_value}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } if ($this->_model->save() === false) { //更新出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME') . "{$item_info[$this->_name_column]}({$pk_value})" . L('FAILURE'), $error_msg); } $module_info = $this->cache($item_info['module_id'], 'LanguageModules'); $item_info['module_name'] = $module_info['module_name']; //语言包模块名 $diff = $this->_dataDiff($item_info, $data, $diff_key); //差异 $this->_model->addLog($msg . L('CONTROLLER_NAME') . "{$item_info[$this->_name_column]}({$pk_value})." . $diff . L('SUCCESS')); $this->createAction(); C(array('T_MODULE_ID' => array($data['module_id'], $item_info['module_id']))); $this->R('LanguageModules/buildAction', array('all')); $this->_ajaxReturn(true, $msg . L('SUCCESS')); } else { $diff = $this->_dataDiff($data, false, $diff_key); //数据 if ($this->_model->add() === false) { //插入出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME') . $diff . L('FAILURE'), $error_msg); } $this->_model->addLog($msg . L('CONTROLLER_NAME') . $diff . L('SUCCESS')); $this->createAction(); C(array('T_MODULE_ID' => array($data['module_id']))); $this->R('LanguageModules/buildAction', array('all')); $this->_ajaxReturn(true, $msg . L('SUCCESS')); } }
/** * 记录加载css,js时间 * * @author mrmsl <*****@*****.**> * @date 2012-09-06 17:15:16 * @lastmodify 2013-01-21 16:52:19 by mrmsl * * @return object this */ public function logLoadTimeAction() { if (!$this->_admin_info) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CONTROLLER_NAME_ADMIN,IS_EMPTY'); trigger_error($log, E_USER_ERROR); return $this; } $load_css_time = Filter::float('load_css_time'); //加载css样式时间 $load_ext_time = Filter::float('load_ext_time'); //加载extjs.js时间 $load_js_time = Filter::float('load_js_time'); //加载其它js时间 $app_launch_time = Filter::float('app_launch_time'); //创建应用程序时间 $total_time = $load_css_time + $load_ext_time + $load_js_time + $app_launch_time; $app_launch_time = $app_launch_time ? ', app_launch_time => ' . $app_launch_time : ''; //管理中心才会有 $log = get_method_line(__METHOD__, __LINE__, LOG_LOAD_SCRIPT_TIME) . "total_time => {$total_time}{$app_launch_time}, load_ext_time => {$load_ext_time}, load_css_time => {$load_css_time}, load_js_time => {$load_js_time}"; trigger_error($log, E_USER_ERROR); return $this; }
/** * 检测目录是否存在 * * @author mrmsl <*****@*****.**> * @date 2012-09-06 14:23:23 * @lastmodify 2013-01-31 14:23:05 by mrmsl * * @param string $path 路径 * @param string $name 路径提示名称。默认'' * @param string $relative_path 相对路径。默认WWWROOT,网站根目录 * @param bool $must_end_with true必须以'/'结尾。默认true * @param bool $allow_start_with true允许以'/'开头。默认false * @param bool $allow_dot true允许../或./出现。默认false * * @return mixed true路径存在,否则返回相应提示信息 */ function validate_dir($path, $name = '', $relative_path = 'WWWROOT', $must_end_with = true, $allow_start_with = false, $allow_dot = false) { if ('null' == $relative_path) { //只是对路径 / 判断 if (DS == $path) { // /,直接返回true return true; } $relative_path = null; } else { $relative_path = defined($relative_path) ? constant($relative_path) : WWWROOT; } $name = 0 === strpos($name, '{%') ? L(substr($name, 2, -1)) : $name; $path = false === strpos($path, '\\') ? $path : str_replace('\\', DS, $path); if ($must_end_with && DS != substr($path, -1)) { return $name . sprintf(L('MUST,END_WITH'), DS); } if (!$allow_start_with && 0 === strpos($path, DS)) { return $name . sprintf(L('CAN_NOT,START_WITH'), DS); } if (!$allow_dot && false !== strpos($path, '.' . DS)) { $error = $name . L('CAN_NOT,USE,RELATIVE,PATH'); $log = get_method_line(__METHOD__, __LINE__, LOG_NORMAL_ERROR) . $error; trigger_error($log, E_USER_ERROR); return $error; } return null === $relative_path || is_dir($relative_path . $path) ? true : $name . $path . L('NOT_EXIST'); }
/** * 博客列表 * * @author mrmsl <*****@*****.**> * @date 2013-04-18 11:50:55 * * @return void 无返回值 */ public function indexAction() { $cate_name = Filter::string('name', 'get'); if ('tag' == Filter::get('flag', 'get')) { //标签 $this->_fetchBlog($cate_name); return; } $cate_arr = $this->cache(); if (!$cate_arr) { $this->_showMessage('no arr', null, 404); } if ('' === $cate_name) { //category.shtml $this->_fetchBlog(array('cate_id' => 0, 'cate_name' => L('CN_WANGWEN'), 'link_url' => BASE_SITE_URL . 'category' . C('HTML_SUFFIX'))); return; } foreach ($cate_arr as $v) { if ($v['en_name'] == $cate_name) { $cate_info = $v; break; } } if (!isset($cate_info)) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $cate_name . ' ' . L('NOT_EXIST'); trigger_error($log); $this->_showMessage($cate_name . ' ' . L('NOT_EXIST'), null, 404); } $this->_fetchBlog($cate_info); }
/** * 添加或保存 * * @author mrmsl <*****@*****.**> * @date 2013-06-06 16:03:15 * * @return void 无返回值 */ public function addAction() { $check = $this->_model->checkCreate(); //自动创建数据 $check !== true && $this->_ajaxReturn(false, $check); //未通过验证 $pk_field = $this->_pk_field; //主键 $pk_value = $this->_model->{$pk_field}; //主键值 $data = $this->_model->getProperty('_data'); //数据,$model->data 在save()或add()后被重置为array() $diff_key = 'template_name,subject,sort_order,memo,content'; //比较差异字段 $msg = L($pk_value ? 'EDIT' : 'ADD'); //添加或编辑 $log_msg = $msg . L('CONTROLLER_NAME,FAILURE'); //错误日志 $error_msg = $msg . L('FAILURE'); //错误提示信息 if ($pk_value) { //编辑 if (!($info = $this->cache($pk_value))) { //不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,CONTROLLER_NAME,%{$pk_field}({$pk_value}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } if (false === $this->_model->save()) { //更新出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME') . "{$info['template_name']}({$pk_value})" . L('FAILURE'), $error_msg); } $diff = $this->_dataDiff($info, $data, $diff_key); //差异 $this->_model->addLog($msg . L('CONTROLLER_NAME') . "{$info['template_name']}({$pk_value})." . $diff . L('SUCCESS')); $this->cache(null, null, null)->_ajaxReturn(true, $msg . L('SUCCESS')); } else { $data = $this->_dataDiff($data, false, $diff_key); //数据 if ($this->_model->add() === false) { //插入出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME') . $data . L('FAILURE'), $error_msg); } $this->_model->addLog($msg . L('CONTROLLER_NAME') . $data . L('SUCCESS')); $this->cache(null, null, null)->_ajaxReturn(true, $msg . L('SUCCESS')); } }
/** * 检测用户名,包括禁用用户名 * * @author mrmsl <*****@*****.**> * @date 2013-05-23 15:00:32 * * @param string $username 用户名 * * @return mixed true验证否则,如果未输入,返回提示信息,如果禁用,返回禁用信息,否则返回false */ protected function _checkUsername($username) { if ($username === '') { //如果未输入,提示输入 return false; } if ($disabled_username = $this->_module->getGuestbookCommentsSetting($module = C('T_VERIFYCODE_MODULE'), 'disabled_username')) { $separator = false === strpos($disabled_username, PHP_EOL) ? PHP_EOL : PHP_EOL; //公司64位\n,家里32位\r\n,奇了怪了 if (in_array(strtolower($username), explode($separator, strtolower($disabled_username)))) { $error = L('DISABLED,' . C('T_MODULE') . ',USERNAME') . $username; $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $module . $error; trigger_error($log); C('T_REDIRECT', true); return $error; } } return true; }
/** * 查看某一条留言评论 * * @author mrmsl <*****@*****.**> * @date 2013-06-01 11:00:03 * * @return void 无返回值 */ public function viewAction() { $comment_id = Filter::int($this->_pk_field, 'get'); $add_time = Filter::int('add_time', 'get'); $field = '*,INET_NTOA(user_ip) AS user_ip'; if (!$comment_id && !$add_time) { //非法参数 $log = L('CN_CHAKAN,CONTROLLER_NAME,%.,INVALID_PARAM') . "{$this->_pk_field}({$comment_id}),add_time({$add_time})"; $msg = L('INVALID_PARAM'); } elseif (!($comment_info = $this->_model->field($field)->where(array($this->_pk_field => $comment_id, 'add_time' => $add_time))->select())) { //不存在 $log = L('CN_CHAKAN,CONTROLLER_NAME') . ".{$this->_pk_field}({$comment_id}),add_time({$add_time})" . L('NOT_EXIST'); $msg = L('CONTROLLER_NAME,NOT_EXIST'); } if (!empty($msg)) { //错误 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log; trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $msg); } $store = array($this->_pk_field => $comment_id, 'add_time' => $add_time, 'content' => ''); $info = $comment_info[0]; if (COMMENT_REPLY_TYPE_REPLIED == $info['admin_reply_type']) { // $reply_content = $this->_model->where('admin_reply_type=' . COMMENT_REPLY_TYPE_ADMIN . ' AND real_parent_id=' . $info[$this->_pk_field])->getField('content'); $store['content'] = $reply_content; } if ($parent_id = $info['parent_id']) { $node_arr = explode(',', $info['node']); $comment_info = $this->_model->field($field)->where("type={$info['type']} AND (node LIKE '{$node_arr[0]},%' OR {$this->_pk_field} = {$node_arr[0]}) AND comment_id<={$comment_id}")->select(); } $this->_ajaxReturn(true, $store, Tree::array2tree($comment_info, $this->_pk_field)); }
/** * 生成语言包 * * @author mrmsl <*****@*****.**> * @data 2013-06-21 16:03:22 * * @return void 无返回值 */ public function buildAction() { if ($t_module_id = C('T_MODULE_ID')) { //$this->R() $module_id = $t_module_id; } else { $module_id = Filter::string($this->_pk_field); } if (!$module_id && null === $t_module_id) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('BUILD,LANGUAGE_ITEM,CACHE,FAILURE')); } $module_id = 'all' == $module_id ? $this->_exclude_delete_id : map_int($module_id, true); if ($intersect = array_intersect($this->_exclude_delete_id, $module_id)) { //是否包含1,2,3 foreach ($intersect as $v) { $module_id = array_merge($module_id, $this->_getChildrenIds($v, false, true)); } } $module_id = array_unique($module_id); $modules = $this->cache(); $error = ''; $log = ''; foreach ($module_id as $k => $v) { //验证语言模块 if (isset($modules[$v])) { $item = $modules[$v]; $log .= ",{$item['module_name']}({$item[$this->_pk_field]})"; } else { unset($module_id[$k]); $error .= ',id(' . $v . ')'; } } if (!$module_id && null === $t_module_id) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('BUILD,LANGUAGE_ITEM,CACHE,FAILURE')); } $data = $this->_getBuildData($module_id); foreach ($data['php_data'] as $key => $content) { F($key, $content, LANG_PATH); } $this->_buildScriptItems($data['js_data']); if ($error) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $error . L('NOT_EXIST'); trigger_error($log); } if (null === $t_module_id) { $this->_model->addLog(L('BUILD,LANGUAGE_ITEM,CACHE') . $log . L('SUCCESS')); $this->_ajaxReturn(true, L('BUILD,SUCCESS')); } }
/** * 移动所属分类 * * @author mrmsl <*****@*****.**> * @date 2013-03-31 19:27:28 * * @return void 无返回值 */ function moveAction() { $field = 'cate_id'; //定段 $cate_id = Filter::int($field); //所属分类id $msg = L('MOVE'); //提示 $log_msg = $msg . L('CONTROLLER_NAME_BLOG,FAILURE'); //错误日志 $error_msg = $msg . L('FAILURE'); //错误提示信息 if ($cate_id) { //分类id $cate_info = $this->cache($cate_id, 'Category'); if (!$cate_info) { //分类不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,BELONG_TO_CATEGORY,%{$field}({$cate_id}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } $cate_name = $cate_info['cate_name']; } else { //非法参数 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%: {$field},IS_EMPTY"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } $this->_setField($field, $cate_id, $msg, L('TO') . $cate_name); }
/** * 记录事务回滚 * * @author mrmsl <*****@*****.**> * @date 2013-01-02 14:29:11 * @lastmodify 2013-01-16 15:36:32 by mrmsl * * @return void 无返回值 */ protected function _writeRollbackSql() { $log = get_method_line(__METHOD__, __LINE__, LOG_ROLLBACK_SQL) . join(PHP_EOL, $this->_sql_arr); trigger_error($log); }
/** * 清除缓存 * * @author mrmsl <*****@*****.**> * @date 2013-05-17 09:01:33 * * @return void 无返回值 */ public function clearCacheAction() { $cate_id = Filter::string($pk_field = $this->_pk_field); $cate_id = map_int($cate_id, true); $cate_arr = $this->cache(); if ($cate_id) { $error = ''; $log = ''; $template = $this->getViewTemplate(); $name_column = $this->_name_column; $cache_path = $template->_cache_path . CONTROLLER_NAME . DS; foreach ($cate_id as $v) { if (isset($cate_arr[$v])) { foreach (glob($cache_path . "index{$v}-*") as $filename) { unlink($filename); } $log .= ",{$cate_arr[$v][$name_column]}({$v})"; } else { $error .= ',' . $v; } } if ($error) { $log_error = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CONTROLLER_NAME') . $error . L('NOT_EXIST'); trigger_error($log_error); } if ($log) { $this->_model->addLog(L('CLEAR,CONTROLLER_NAME_CATEGORY,CACHE') . substr($log, 1) . L('SUCCESS')); $this->_ajaxReturn(true, L('CLEAR,SUCCESS')); } else { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('CLEAR,CONTROLLER_NAME_CATEGORY,CACHE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME') . $error . L('NOT_EXIST'); trigger_error($log, E_USER_ERROR); } } if (empty($error)) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("CLEAR,CONTROLLER_NAME_CATEGORY,CACHE,FAILURE,%<br />,INVALID_PARAM,%:,CONTROLLER_NAME,%{$this->_pk_field},IS_EMPTY"); trigger_error($log, E_USER_ERROR); } $this->_ajaxReturn(false, L('CLEAR,FAILURE')); }
/** * 保存值 * * @author mrmsl <*****@*****.**> * @date 2012-08-29 13:47:39 * @lastmodify 2013-01-22 10:30:42 by mrmsl * * @return void 无返回值 */ public function publicSaveValueAction() { $error = L('SAVE,FAILURE'); //保存失败错误 $menu_id = Filter::int('_menu_id'); //菜单id $menu = $this->cache(0, 'Menu'); //菜单数据 if (!isset($menu[$menu_id])) { //菜单不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("SAVE,CONTROLLER_NAME_FIELD,VALUE,FAILURE,%:(,MENU,%menu_id={$menu_id}}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error); } $menu_info = $menu[$menu_id]; //菜单信息 $controller = $menu_info['controller']; //控制器 $action = $menu_info['action']; //操作方法 $this->_checkAdminPriv($controller, $action); //权限判断 by mashanlin on 2012-08-30 11:06:25 $menu = $this->nav($menu_id, 'menu_name', 'Menu'); //菜单名 $info = L('CONTROLLER_NAME_FIELD,VALUE') . "({$menu})"; //信息 if (empty($_POST)) { //非法数据 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('SAVE') . $info . L('FAILURE,%:,INVALID,DATA'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error); } /*$field_arr = $this->_model->alias('f') ->field('f.input_name,f.field_id,f.field_name,input_value,f.validate_rule,f.auto_operation') ->join(TB_MENU . ' AS m ON f.menu_id=m.menu_id') ->where("m.menu_id={$menu_id} AND f.is_enable=1") ->index($this->_pk_field)->select();*/ //走缓存 by mrmsl on 2012-09-05 14:05:14 $field_arr = array_filter($this->cache(), create_function('$v', 'return $v["menu_id"] == ' . $menu_id . ' && $v["is_enable"];')); if (empty($field_arr)) { //查询出错或表单域为空 if ($field_arr === false) { //查询出错 $this->_sqlErrorExit(L('GET') . $menu . L('CONTROLLER_NAME_FIELD,FAILURE'), $error); } else { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('SAVE') . $info . L('FAILURE,%:,CONTROLLER_NAME_FIELD,IS_EMPTY'); trigger_error($log, E_USER_ERROR); } $this->_ajaxReturn(false, $error); } $this->_model->saveValueCheckCreate($field_arr); //设置自动验证 $checked = $this->_model->checkCreate('_validateSaveValue'); //执行自动验证 $checked !== true && $this->_ajaxReturn(false, $checked); //未通过验证 $this->_model->autoOperation($_POST, Model::MODEL_BOTH); //自动填充 by mrmsl on 2012-09-07 13:07:57 $log = ''; //管理日志 $pk_field = $this->_pk_field; //主键 foreach ($field_arr as $field_id => $item) { $input_name = $item['input_name']; if (isset($_POST[$input_name])) { $old_value = $item['input_value']; //原值 $new_value = $_POST[$input_name]; //新值 if ($old_value != $new_value) { //值不相等 $this->_model->save(array($pk_field => $field_id, 'input_value' => $new_value)); //更新 $log .= ", {$input_name}: {$old_value} => {$new_value}"; //管理日志 } } } $this->cache(null, null, null); //重新生成缓存 //回调 by mrmsl on 2012-09-22 15:34:53 method_exists($this, $callback = '_saveValueCallback' . ucfirst($controller)) && $this->{$callback}($menu_info); $this->_model->addLog(L('SAVE') . $info . L('SUCCESS') . ($log ? $log : '')); $this->_ajaxReturn(true, L('SAVE,SUCCESS')); }
/** * 添加或保存 * * @author mrmsl <*****@*****.**> * @lastmodify 2013-01-22 10:59:48 by mrmsl * * @return void 无返回值 */ public function addAction() { $check = $this->_model->startTrans()->checkCreate(); //自动创建数据 $check !== true && $this->_ajaxReturn(false, $check); //未通过验证 $pk_field = $this->_pk_field; //主键 $pk_value = $this->_model->{$pk_field}; //角色id $this->_model->_priv_id = map_int($this->_model->_priv_id, true); //菜单权限 $priv_id = $this->_model->_priv_id; $data = $this->_model->getProperty('_data'); //数据,$model->data 在save()或add()后被重置为array() $diff_key = $this->_name_column . ',memo,sort_order'; //比较差异字段 $cache_data = $this->cache(); if ($pk_value) { //编辑 if ($pk_value == ADMIN_ROLE_ID && $this->_admin_info[$pk_field] != ADMIN_ROLE_ID) { //不可编辑指定角色。增加当前角色id判断 by mrmsl on 2012-07-05 08:50:27 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('TRY,EDIT,CONTROLLER_NAME_ROLE') . "{$pk_field}: {$pk_value}"; trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('EDIT,FAILURE')); } if (!isset($cache_data[$pk_value])) { //角色不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L("EDIT,CONTROLLER_NAME_ROLE,FAILURE,%: ,INVALID_PARAM,%:,CONTROLLER_NAME_ROLE,%{$pk_field}({$pk_value}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('EDIT,FAILURE')); } $role_info = $cache_data[$pk_value]; if ($this->_model->save() === false) { //更新出错 $this->_sqlErrorExit(L('EDIT,CONTROLLER_NAME_ROLE') . "{$role_info[$this->_name_column]}({$pk_value})" . L('FAILURE'), L('EDIT,FAILURE')); } $diff_priv = $this->diffRolePriv(array_keys($role_info['priv']), $priv_id); $diff = $this->_dataDiff($role_info, $data, $diff_key) . ($diff_priv['msg'] ? 'priv => ' . $diff_priv['msg'] : ''); //差异 //权限有变更 $diff_priv['msg'] && $this->_model->setRolePriv($pk_value, $priv_id); //管理员操作日志 $this->_model->addLog(L('EDIT,CONTROLLER_NAME_ROLE') . "{$role_info[$this->_name_column]}({$pk_value})." . $diff . L('SUCCESS')); $this->cache(null, null, null)->_ajaxReturn(true, L('EDIT,SUCCESS')); } else { $priv = $this->_getRolePriv($priv_id); $insert_data = "{$this->_name_column} => {$data[$this->_name_column]}, sort_order => " . (isset($data['sort_order']) ? $data['sort_order'] : -1) . " memo => {$data['memo']}" . ($priv['msg'] ? 'priv => ' . $priv['msg'] : ''); //数据 if (($insert_id = $this->_model->add()) === false) { //插入出错 $this->_sqlErrorExit(L('ADD,CONTROLLER_NAME_ROLE') . $insert_data . L('FAILURE'), L('ADD,FAILURE')); } //权限 $priv_id && $this->_model->setRolePriv($insert_id, $priv_id); $this->_model->addLog(L('ADD,CONTROLLER_NAME_ROLE') . $insert_data . L('SUCCESS')); $this->cache(null, null, null)->_ajaxReturn(true, L('ADD,SUCCESS')); } }
/** * 自动填充处理 * * @author liu21st <*****@*****.**> * @lastmodify 2013-01-21 14:50:11 by mrmsl * * @param array $data 整个表单数据 * @param int $type 类型 * * @return array $data 处理后数据 */ public function autoOperation(&$data, $type) { if ($this->_auto) { //自动填充 foreach ($this->_auto as $auto) { //填充因子定义格式 array('field','填充内容','填充条件','附加规则',[额外参数]) thinkphp //填充因子定义格式 array('field','填充内容','附加规则','填充条件',[额外参数]) yablog by mrmsl on 2013-09-27 11:18:15 $auto[3] = empty($auto[3]) ? self::MODEL_INSERT : $auto[3]; //默认为新增的时候自动填充 if ($type == $auto[3] || self::MODEL_BOTH == $auto[3]) { switch ($auto[2]) { //附加规则 case 'function': //使用函数进行填充 字段的值作为参数 //使用函数进行填充 字段的值作为参数 case 'callback': //使用回调方法 $args = array(); if (isset($auto[4])) { //附加参数 $args = is_array($auto[4]) ? $auto[4] : explode('|', $auto[4]); $index = array_search('data', $args, true); //传整个_POST数组 if (false !== $index) { $args[$index] = __GET ? $_GET : $_POST; } } isset($data[$auto[0]]) && array_unshift($args, $data[$auto[0]]); if ('function' == $auto[2]) { //是否为允许的回调函数 by mrmsl on 2012-09-07 14:47:27 if (false === strpos(ALLOW_AUTO_OPERATION_FUNCTION, ',' . $auto[1] . ',')) { $log = get_method_line(__METHOD__, __LINE__, LOG_NORMAL_ERROR); $log .= L('TRY,USE,AUTO_OPERATION,FUNCTION') . ': ' . $auto[1]; trigger_error($log, E_USER_ERROR); } else { $data[$auto[0]] = call_user_func_array($auto[1], $args); } } else { $data[$auto[0]] = call_user_func_array(array(&$this, $auto[1]), $args); } break; case 'field': //用其它字段的值进行填充 $data[$auto[0]] = $data[$auto[1]]; break; case 'string': default: //默认作为字符串填充 $data[$auto[0]] = $auto[1]; } if (false === $data[$auto[0]]) { unset($data[$auto[0]]); } } } //end switch } //end if return $data; }
/** * 根据两字段组合值获取数据,如id及add_time匹配才能获取到数据,而不仅仅根据id * * @author mrmsl <*****@*****.**> * @date 2013-06-14 16:22:53 * * @param string|array $field_arr 组合字段,通常为array('id','add_time') * @param string $data 组合信息,默认null=$_POST['data'],格式:id1|add_time1,id2|add_time2,... * @param string $field 选取字段,默认* * @param string $table ,默认null * * @return array 数据 */ protected function _getPairsData($field_arr, $data = null, $field = '*', $pk_field = null, $table = null) { $data = null === $data ? Filter::string('data') : $data; $return_arr = array(); if (!$data) { return $return_arr; } $data = explode(',', $data); foreach ($data as $k => $v) { $v_arr = explode('|', $v); if (isset($v_arr[0], $v_arr[1]) && ($column_1 = intval($v_arr[0])) && ($column_2 = intval($v_arr[1]))) { $return_arr[$column_1] = $column_2; } } if (!$return_arr) { $error = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('INVALID_PARAM') . var_export($data, true); trigger_error($error, E_USER_ERROR); return $return_arr; } $column_1_arr = array_keys($return_arr); $column_2_arr = array_values($return_arr); $pk_field = $pk_field ? $pk_field : $this->_pk_field; $field_arr = is_array($field_arr) ? $field_arr : explode(',', $field_arr); $table && $this->_model->table($table); $data = $this->_model->where(array($field_arr[0] => array('IN', $column_1_arr), $field_arr[1] => array('IN', $column_2_arr)))->field($field)->index($pk_field)->select(); $un_match = count($data) == count($return_arr) ? '' : 'data count not match.'; foreach ($data as $k => $v) { if ($return_arr[$k] != $v[$field_arr[1]]) { //id与时间不匹配 $un_match .= ",{$k}({$return_arr[$k]}) => {$k}({$v[$field_arr[1]]})[correct]"; unset($data[$k]); } } if ($un_match) { $error = get_method_line(__METHOD__, __LINE__, LOG_NORMAL_ERROR) . L('PAIRS_DATA_UN_MATCH') . $un_match; trigger_error($error, E_USER_ERROR); } return $data; }
/** * 移动所属角色 * * @author mrmsl <*****@*****.**> * @date 2012-12-28 10:55:23 * @lastmodify 2013-01-21 15:47:04 by mrmsl * * @return void 无返回值 */ function moveAction() { $field = 'role_id'; //定段 $role_id = Filter::int($field); //所属角色id $msg = L('MOVE'); //提示 $log_msg = $msg . L('CONTROLLER_NAME_ADMIN,FAILURE'); //错误日志 $error_msg = $msg . L('FAILURE'); //错误提示信息 if ($role_id) { //角色id $role_info = $this->cache($role_id, 'Role'); if (!$role_info) { //角色不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,ROLE,%{$field}({$role_id}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } $role_name = $role_info['role_name']; } else { //非法参数 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%: {$field},IS_EMPTY"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } $this->_setField($field, $role_id, $msg, L('TO') . $role_name); }
/** * 生成 * * @author mrmsl <*****@*****.**> * @date 2013-05-14 11:30:05 * * @return void 无返回值 */ public function buildAction() { $html_id = map_int(Filter::string($this->_pk_field), true); if (!$html_id) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . L('PRIMARY_KEY,DATA,IS_EMPTY'); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, L('BUILD,STATIC_PAGE,FAILURE')); } $caches = $this->cache(); $error = ''; $log = ''; foreach ($html_id as $k => $v) { if (isset($caches[$v])) { $item = $caches[$v]; $error .= $this->_build($item); $log .= ",{$item['tpl_name']}({$item[$this->_pk_field]})"; } else { unset($html_id[$k]); $error .= ',id(' . $v . ')'; } } $html_id && C('T_HTML_ID', $html_id); $log && C('T_LOG', $log); if ($error) { $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $error . L('NOT_EXIST'); trigger_error($log); } $this->_successAction(); }
/** * 添加或保存 * * @author mrmsl <*****@*****.**> * @date 2012-12-26 15:57:19 * @lastmodify 2013-01-21 15:45:31 by mrmsl * * @return void 无返回值 */ public function addAction() { $check = $this->_model->checkCreate(); //自动创建数据 $check !== true && $this->_ajaxReturn(false, $check); //未通过验证 $pk_field = $this->_pk_field; //主键 $pk_value = $this->_model->{$pk_field}; //微博id $data = $this->_model->getProperty('_data'); //数据,$model->data 在save()或add()后被重置为array() $diff_key = 'content'; //比较差异字段 $msg = L($pk_value ? 'EDIT' : 'ADD'); //添加或编辑 $log_msg = $msg . L('CONTROLLER_NAME_MINIBLOG,FAILURE'); //错误日志 $error_msg = $msg . L('FAILURE'); //错误提示信息 if ($pk_value) { //编辑 if (!($blog_info = $this->_model->find($pk_value))) { //编辑微博不存在 $log = get_method_line(__METHOD__, __LINE__, LOG_INVALID_PARAM) . $log_msg . ': ' . L("INVALID_PARAM,%:,CONTROLLER_NAME_MINIBLOG,%{$pk_field}({$pk_value}),NOT_EXIST"); trigger_error($log, E_USER_ERROR); $this->_ajaxReturn(false, $error_msg); } if (false === $this->_model->save()) { //更新出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME_MINIBLOG') . "{$blog['title']}({$pk_value})" . L('FAILURE'), $error_msg); } $diff = $this->_dataDiff($blog_info, $data, $diff_key); //差异 C('HTML_BUILD_INFO', array(array('link_url' => $blog_info['link_url']))); $this->_deleteBlogHtml(null); $this->_model->addLog($msg . L('CONTROLLER_NAME_MINIBLOG') . "{$blog_info['content']}({$pk_value})." . $diff . L('SUCCESS')); $this->_ajaxReturn(true, $msg . L('SUCCESS')); } else { $data = $this->_dataDiff($data, false, $diff_key); //数据 if (false === ($insert_id = $this->_model->add())) { //插入出错 $this->_sqlErrorExit($msg . L('CONTROLLER_NAME_MINIBLOG') . $data . L('FAILURE'), $error_msg); } $this->_model->addLog($msg . L('CONTROLLER_NAME_MINIBLOG') . $data . L('SUCCESS')); $this->_ajaxReturn(true, $msg . L('SUCCESS')); } }