function topic() { $tpl = array('id' => 0, 'title' => '', 'url' => 'http://www.v2ex.com/t/188087', 'content' => '', 'content_rendered' => '', 'replies' => 0, 'created' => 0, 'last_modified' => 0, 'last_touched' => 1430627831, 'member' => array('id' => 0, 'username' => '', 'tagline' => '', 'avatar_mini' => '', 'avatar_normal' => '', 'avatar_large' => ''), 'node' => array('id' => 1, 'name' => 'create', 'title' => '分享创造', 'title_alternative' => 'Create', 'url' => 'http://www.v2ex.com/go/create', 'topics' => 3800, 'avatar_mini' => '//cdn.v2ex.co/navatar/70ef/df2e/17_mini.png?m=1430065455', 'avatar_normal' => '//cdn.v2ex.co/navatar/70ef/df2e/17_normal.png?m=1430065455', 'avatar_large' => '//cdn.v2ex.co/navatar/70ef/df2e/17_large.png?m=1430065455')); $gets = array('order' => 'question_id desc', 'pagesize' => 20); $gets['page'] = empty($_GET['page']) ? 1 : intval($_GET['page']); $_user = table('aws_users'); $_user->primary = 'uid'; if (!empty($_GET['category'])) { $gets['category_id'] = intval($_GET['category']); } if (!empty($_GET['username'])) { $user = $_user->get($_GET['username'], 'user_name'); $gets['published_uid'] = $user['uid']; } $pager = null; $list = table('aws_question')->gets($gets, $pager); $_uids = array(); $_categorys = array(); foreach ($list as $li) { $_uids[$li['published_uid']] = true; $_categorys[$li['category_id']] = true; } if (!empty($_uids)) { $users = $_user->getMap(['in' => array('uid', implode(',', array_keys($_uids)))]); } else { $users = array(); } if (!empty($_uids)) { $categorys = table('aws_category')->getMap(['in' => array('id', implode(',', array_keys($_categorys)))]); } else { $categorys = array(); } $result = array(); foreach ($list as $li) { Swoole\Filter::safe($li['question_content']); $tpl['id'] = $li['question_id']; $tpl['title'] = $li['question_content']; $tpl['content'] = $li['question_detail']; $tpl['created'] = $li['add_time']; $tpl['last_modified'] = $li['update_time']; $tpl['replies'] = $li['answer_count']; //用户信息 $uid = $li['published_uid']; $tpl['member']['id'] = $uid; $tpl['member']['username'] = $users[$uid]['user_name']; $_category_id = $li['category_id']; $tpl['node']['id'] = $_category_id; $tpl['node']['title_alternative'] = $tpl['node']['title'] = $tpl['node']['name'] = $categorys[$_category_id]['title']; $tpl['node']['name'] = $categorys[$_category_id]['title']; if (empty($users[$uid]['avatar_file'])) { $tpl['member']['avatar_mini'] = self::NO_AVATAR . 'avatar-min-img.jpg'; $tpl['member']['avatar_normal'] = self::NO_AVATAR . 'avatar-mid-img.jpg'; $tpl['member']['avatar_large'] = self::NO_AVATAR . 'avatar-max-img.jpg'; } else { $tpl['member']['avatar_mini'] = self::AVATAR_URL . $users[$uid]['avatar_file']; $tpl['member']['avatar_normal'] = self::AVATAR_URL . str_replace('_min.', '_mid.', $users[$uid]['avatar_file']); $tpl['member']['avatar_large'] = self::AVATAR_URL . str_replace('_min.', '_max.', $users[$uid]['avatar_file']); } $tpl['content_rendered'] = self::parseMarkdown($li['question_detail']); $result[] = $tpl; } echo json_encode($result); }
function write() { $_m = model('UserLogs'); $_l = model('UserLogCat'); if ($_POST) { //如果没得到id,说明提交的是添加操作 if (empty($_POST['title'])) { return Swoole\JS::js_back('标题不能为空!'); } Swoole\Filter::safe($_POST['content']); $_POST['content'] = Swoole\Filter::remove_xss($_POST['content']); Swoole\Filter::addslash($_POST['content']); $blog['title'] = $_POST['title']; $blog['content'] = $_POST['content']; $blog['c_id'] = (int) $_POST['c_id']; if (isset($_POST['act']) and $_POST['act'] == 'draft') { $blog['dir'] = 1; } else { $blog['dir'] = 0; } if (!empty($_POST['id'])) { //如果得到id,说明提交的是修改的操作 $id = (int) $_POST['id']; $det = $_m->get($id)->get(); if ($det['uid'] != $this->uid) { exit('access deny!not your blog!'); } $_m->set($id, $blog); if (isset($_POST['autosave'])) { return 1; } else { return Swoole\JS::js_back('修改成功', -2); } } else { $blog['uid'] = $this->uid; $bid = $_m->put($blog); $_l->set($blog['c_id'], array('num' => '`num`+1')); if (isset($_POST['autosave'])) { return $bid; } else { return Swoole\JS::js_back('添加成功'); } } } else { require_once WEBPATH . '/swoole_plugin/fckeditor/Swoole.plugin.php'; $cat = $_l->getMap(array('uid' => $this->uid), 'name'); if (empty($cat)) { $cat = array(); } if (!empty($_GET['id'])) { $id = $_GET['id']; $det = $_m->get($id)->get(); Swoole\Filter::deslash($det['content']); $form = Swoole\Form::select('c_id', $cat, $det['c_id']); $this->swoole->tpl->assign('det', $det); $editor = editor("content", $det['content'], 480, false, false, array('empty' => '请选择日志分类')); } else { $form = Swoole\Form::select('c_id', $cat, '', false, array('empty' => '请选择日志分类')); $editor = editor("content", '', 480, false); } $this->swoole->tpl->assign('form', $form); $this->swoole->tpl->assign('editor', $editor); $this->swoole->tpl->display(); } }