示例#1
0
 /**
  * Update new forum
  */
 public function action_update()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Edit Topic')));
     $topic = new Model_Topic($this->request->param('id'));
     $get_all = Model_Forum::get_all();
     //get all forums to build forum parents in select
     $forum_parents = array();
     foreach ($get_all[0] as $parent) {
         $forum_parents[$parent['id']] = $parent['name'];
     }
     $this->template->content = View::factory('oc-panel/pages/forum/topic', array('topic' => $topic, 'forum_parents' => $forum_parents));
     if ($_POST) {
         $topic->title = core::post('title');
         $topic->id_forum = core::post('id_forum');
         $topic->description = core::post('description');
         if (core::post('seotitle') != $topic->seotitle) {
             $topic->seotitle = $topic->gen_seotitle(core::post('seotitle'));
         }
         if (core::post('status') == 'on') {
             $topic->status = 1;
         } else {
             $topic->status = 0;
         }
         try {
             $topic->save();
             Alert::set(Alert::SUCCESS, __('Topic is updated.'));
         } catch (Exception $e) {
             Alert::set(Alert::ERROR, $e->getMessage());
         }
         HTTP::redirect(Route::url('oc-panel', array('controller' => 'topic', 'action' => 'index')));
     }
 }
示例#2
0
 public function action_edit()
 {
     if (Auth::instance()->logged_in()) {
         $view = View::factory("topic/edit");
         $topic_id = $this->request->param('id');
         $topic = new Model_Topic();
         $view->topics = $topic->get_topic_by_id($topic_id);
         $this->template->content = $view->render();
         if ($this->request->method() === Request::POST) {
             if (!Security::check($this->request->param('id2'))) {
                 throw new Exception("Bad Token!");
             }
             $topic_title = $this->request->post('title');
             $topic_content = $this->request->post('content');
             $topic_edited = time();
             if (empty($topic_title) or empty($topic_content)) {
                 throw new Exception("Title and Content must not be empty!");
             }
             $data = array('title' => $topic_title, 'content' => $topic_content);
             $update_topic = $topic->update_topic($data, $topic_id);
             if (!$update_topic) {
                 throw new Exception("Error");
             }
             $this->redirect('topic/view/' . $topic_id);
         }
     } else {
         $this->redirect('');
     }
 }
示例#3
0
文件: Regenerate.php 项目: kstep/pnut
 public function actionDefault($params)
 {
     $topic = new Model_Topic($this->getStorage());
     $group = new Model_Group($this->getStorage());
     $topic->regenerate();
     $group->regenerate();
 }
示例#4
0
 /**
  * Edit Topic
  * 
  * @param   integer     $topic      Topic ID
  * @param   array       $changes    Changes
  * @return  bool
  */
 public function edit($topic, $changes)
 {
     $new = new Model_Topic();
     $new->assignIdentifier($topic);
     $new->fromArray($changes);
     try {
         $new->save();
     } catch (Doctrine_Exception $e) {
         return $e->getMessage();
     }
     return true;
 }
示例#5
0
 public function action_index()
 {
     $category_id = $this->request->param('id');
     if (empty($category_id)) {
         throw new Exception("Category ID must not be empty!");
     }
     $topic = new Model_Topic();
     $category = new Model_Category();
     $view = View::factory('categories/main');
     $view->topics = $topic->get_topics_by_id($category_id);
     $view->category = $category->get_name($category_id);
     $this->template->content = $view->render();
 }
示例#6
0
 public function action_forum()
 {
     $this->auto_render = FALSE;
     $info = array('title' => 'RSS Forum ' . Core::config('general.site_name'), 'pubDate' => date("r"), 'description' => __('Latest post published'), 'generator' => 'Open Classifieds');
     $items = array();
     $topics = new Model_Topic();
     if (Model_Forum::current()->loaded()) {
         $topics->where('id_forum', '=', Model_Forum::current()->id_forum);
     } else {
         $topics->where('id_forum', '!=', NULL);
     }
     //any forum
     $topics = $topics->where('status', '=', Model_Topic::STATUS_ACTIVE)->where('id_post_parent', 'IS', NULL)->order_by('created', 'desc')->limit(Core::config('advertisement.feed_elements'))->cached()->find_all();
     foreach ($topics as $topic) {
         $url = Route::url('forum-topic', array('seotitle' => $topic->seotitle, 'forum' => $topic->forum->seoname));
         $items[] = array('title' => htmlspecialchars($topic->title, ENT_QUOTES), 'link' => $url, 'pubDate' => Date::mysql2unix($topic->created), 'description' => htmlspecialchars(Text::removebbcode($topic->description), ENT_QUOTES), 'guid' => $url);
     }
     $xml = Feed::create($info, $items);
     $this->response->headers('Content-type', 'text/xml');
     $this->response->body($xml);
 }
示例#7
0
 public function action_talk()
 {
     $cid = $this->get_query('cid');
     $contest = Model_Contest::find_by_id($cid);
     $this->check_permission($contest);
     $page = $this->get_query('page', 1);
     $filter = array('cid' => $cid);
     $filter = Model_Base::clean_data($filter);
     $topic_list = Model_Topic::page($filter, $page, OJ::per_page);
     $total = Model_Topic::count($filter);
     $this->view = 'discuss/list';
     $this->template_data['contest'] = $contest;
     $this->template_data['cid'] = $cid;
     $this->template_data['topic_list'] = $topic_list;
     $this->template_data['total'] = ceil($total / OJ::per_page);
     $this->template_data['title'] = sprintf('%s - Discuss', $contest->title);
 }
示例#8
0
 public function action_search($search = NULL)
 {
     //template header
     $this->template->title = __('Forum Search');
     $this->template->styles = array('css/forum.css' => 'screen');
     $this->template->bind('content', $content);
     $topics = new Model_Topic();
     $topics->where('status', '=', Model_Post::STATUS_ACTIVE)->where('id_forum', 'IS NOT', NULL)->where_open()->where('title', 'like', '%' . $search . '%')->or_where('description', 'like', '%' . $search . '%')->where_close();
     $pagination = Pagination::factory(array('view' => 'pagination', 'total_items' => $topics->count_all(), 'items_per_page' => self::$items_per_page))->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
     $pagination->title($this->template->title);
     $topics = $topics->order_by('created', 'desc')->limit($pagination->items_per_page)->offset($pagination->offset)->find_all();
     $pagination = $pagination->render();
     $this->template->content = View::factory('pages/forum/search', array('topics' => $topics, 'pagination' => $pagination));
 }
示例#9
0
 public function action_new()
 {
     $this->check_login();
     /* @var Model_User $cu */
     $cu = $this->get_current_user();
     if ($cu->submit < 1) {
         throw new Exception_Page(__('common.submit_before_topic'));
     }
     if ($this->request->is_post()) {
         $topic = new Model_Topic();
         $topic->title = $this->get_post('title');
         $topic->author_id = $cu->user_id;
         $topic->cid = intval($this->get_post('cid'));
         $topic->pid = intval($this->get_post('pid'));
         $topic->save();
         $reply = new Model_Reply();
         $reply->topic_id = $topic->tid;
         $reply->content = $this->get_raw_post('content');
         $reply->author_id = $cu->user_id;
         $reply->save();
         $this->redirect("/discuss/topic/{$topic->tid}");
     }
     $this->view = 'discuss/edit';
     $this->template_data['title'] = __('discuss.edit.new_topic');
 }
示例#10
0
 public function action_view()
 {
     $user_id = $this->request->param('id');
     if (empty($user_id)) {
         throw new Exception("User ID Must not be empty!");
     }
     $user = new Model_User();
     $view = View::factory('profile/view');
     $topic = new Model_Topic();
     $reply = new Model_Reply();
     $view->replies = $reply->get_replies_by_user_id($user_id);
     $view->topics = $topic->get_topics_by_user_id($user_id);
     $view->user = $user->where('id', '=', $user_id)->find();
     $this->template->content = $view->render();
 }
示例#11
0
文件: Article.php 项目: kstep/pnut
 public function isInTopic(Model_Topic $topic)
 {
     return $this->topic == $topic->getId();
 }
示例#12
0
文件: Topic.php 项目: kstep/pnut
 public function actionReorder($params)
 {
     $view = $this->ajaxView();
     $view->state = 'failed';
     if ($params['id'] && $params['targid']) {
         $otopic = new Model_Topic($this->getStorage(), $params['id']);
         $ttopic = new Model_Topic($this->getStorage(), $params['targid']);
         $view->id = $otopic->getId();
         $view->target_id = $ttopic->getId();
         $view->parent_id = $otopic->parent;
         if ($otopic->isLoaded() && $ttopic->isLoaded()) {
             $this->canPerform($otopic, 'edit');
             $view->state = 'reordered';
             $view->place = $params['place'];
             switch ($params['place']) {
                 case 'before':
                     $method = 'insertBefore';
                     break;
                 case 'after':
                     $method = 'insertAfter';
                     break;
                 default:
                     if ($otopic->isBefore($ttopic)) {
                         $method = 'insertAfter';
                         $view->place = 'after';
                     } else {
                         $method = 'insertBefore';
                         $view->place = 'before';
                     }
             }
             try {
                 $otopic->{$method}($ttopic);
             } catch (Exception $e) {
                 $view->state = 'failed';
                 $view->error = $e->getMessage();
             }
         } else {
             $view->error = 'Topic(s) not found.';
         }
     } else {
         $view->error = 'Topic IDs are not set.';
     }
     return $view;
 }
示例#13
0
文件: Article.php 项目: kstep/pnut
 public function actionMove($params)
 {
     $view = $this->ajaxView('article');
     $view->state = "failed";
     if ($params["id"] && $params["targid"]) {
         $article = new Model_Article($this->getStorage(), $params["id"]);
         $topic = new Model_Topic($this->getStorage(), $params["targid"]);
         $view->id = $article->getId();
         $view->topic_id = $topic->getId();
         if ($view->id && $view->topic_id) {
             if ($article->topic != $topic->getId()) {
                 $this->canPerform($article, "edit");
                 $this->canPerform($topic, "edit");
                 $view->state = "moved";
                 $article->topic = $topic->getId();
                 try {
                     $article->save();
                 } catch (Exception $e) {
                     $view->state = "failed";
                     $view->error = $e->getMessage();
                 }
             } else {
                 $view->state = "notmoved";
             }
         } else {
             $view->error = "Article or topic not found.";
         }
     } else {
         $view->error = "Article or topic ID is not set.";
     }
     return $view;
 }