Ejemplo n.º 1
0
 /**
  * Delete child forums & topics
  */
 public function dispose()
 {
     // Drop subjects
     $subjects = Forum::find('all', ['conditions' => ['forum_id = ?', $this->id]]);
     foreach ($subjects as $sbj) {
         $sbj->delete();
     }
     // Drop themes
     $themes = ForumTheme::find('all', ['conditions' => ['forum_id = ?', $this->id]]);
     foreach ($themes as $thm) {
         $thm->delete();
     }
 }
Ejemplo n.º 2
0
 /**
  * @param Request $request
  * @param $matches
  * @return mixed
  */
 public function new_topic(Request $request, $matches)
 {
     if ($access = $this->authenticated_only()) {
         return $access;
     }
     $subject = $matches->get('id');
     $subject = \Forum::find($subject);
     if (!$subject || !$subject->forum_id) {
         return $this->error404($request);
     }
     if ($request->isMethod('post') && $this->user->can('write_forum')) {
         $data = ['description' => trim($request->get('edit')), 'title' => trim($request->get('title')), 'author_id' => $this->user->id, 'forum_id' => $subject->id];
         $this->view->assign('data', $data);
         $errors = [];
         if (strlen($data['title']) < 3) {
             $errors[] = $this->lang->translate('forum.topic.title_len');
         }
         if (strlen($data['description']) < 3) {
             $errors[] = $this->lang->translate('forum.topic.body_len');
         }
         if (count($errors)) {
             $this->view->assign('errors', $errors);
         } else {
             $topic = new \ForumTheme($data);
             if ($topic->save()) {
                 /** @var Ping $ping */
                 $ping = NCService::load('SocialMedia.Ping');
                 return static::redirect_response($this->map->reverse('topic', ['id' => $topic->id]));
             } else {
                 $this->view->assign('errors', [$this->lang->translate('forum.topic.new_failed')]);
             }
         }
     }
     return $this->view->render('forum/create.twig', ['title' => $this->lang->translate('forum.topic.new'), 'subject' => $subject->to_array()]);
 }
Ejemplo n.º 3
0
 public function search()
 {
     fallback($_GET['query'], "");
     $config = Config::current();
     if ($config->clean_urls and substr_count($_SERVER['REQUEST_URI'], "?") and !substr_count($_SERVER['REQUEST_URI'], "%2F")) {
         # Searches with / and clean URLs = server 404
         redirect("search/" . urlencode($_GET['query']) . "/");
     }
     if (empty($_GET['query'])) {
         return Flash::warning(__("Please enter a search term."));
     }
     list($where, $params) = keywords($_GET['query'], "name LIKE :query OR url LIKE :query", "forums");
     $forums = Forum::find(array("placeholders" => true, "where" => $where, "params" => $params));
     list($where, $params) = keywords($_GET['query'], "title LIKE :query OR description LIKE :query OR url LIKE :query", "topics");
     $topics = Topic::find(array("placeholders" => true, "where" => $where, "params" => $params));
     list($where, $params) = keywords($_GET['query'], "body LIKE :query", "messages");
     $messages = Message::find(array("placeholders" => true, "where" => $where, "params" => $params));
     $this->display("discuss/search", array("forums" => new Paginator($forums, 25, "forums_page"), "topics" => new Paginator($topics, 25, "topics_pave"), "messages" => new Paginator($messages, 25, "messages_page"), "search" => $_GET['query']), fix(_f("Search results for \"%s\"", $_GET['query'])));
 }
Ejemplo n.º 4
0
 /**
  * Compte le nombre de topic dans le forum
  *
  */
 public function getTopicCount($forumId)
 {
     $forum = Forum::find($forumId);
     return Topic::where('forum_id', '=', $forum->id)->count();
 }
Ejemplo n.º 5
0
 public function saveBiography($character)
 {
     $question_ids = Input::get('ids');
     $replies = Input::get('replies');
     if ($character) {
         foreach ($question_ids as $index => $q) {
             $response = CharacterQuestionnaire::firstOrNew(['character_id' => $character->id, 'questionnaire_id' => $q]);
             $response->response = $replies[$index];
             $response->save();
         }
         if (Input::hasFile('backstory')) {
             $file = Input::file('backstory');
             $fileName = preg_replace("([^\\w\\d\\-_~,;:\\[\\]\\(\\).])", '', $character->name . "Backstory." . $file->getClientOriginalExtension());
             $file->move(public_path() . '/content/backstories/', $fileName);
             $character->backstory_file = $fileName;
             $character->save();
         }
         if ($character->active || $character->in_review) {
             //Find the relevant forum post and bump it (or create it if it doesn't exist)
             $post = ForumPost::where('body', "[[questionnaire/{$character->id}]]")->first();
             if ($post) {
                 $topic = $post->topic;
                 $topic->postReply($character->owner->id, "Questionnaire responses updated. (Automatic system post)");
             } else {
                 //42 = Character Backgrounds
                 $topic = Forum::find(42)->post("Character Biography for " . $character->name, "[[questionnaire/{$character->id}]]");
                 $topic->markAsRead(Auth::user());
             }
             return Redirect::to("/forums/topic/" . $topic->id);
         } else {
             return Redirect::to("/dashboard/characters");
         }
     } else {
         return Response::json(["success" => false, "message" => "Character could not be found."]);
     }
 }
Ejemplo n.º 6
0
 /**
  * Crée un nouveau topic dans le forum désiré
  *
  * @param $slug Slug du forum dans lequel sera le topic
  * @param $id Id du forum dans lequel sera le topic
  */
 public function newTopic($slug, $id)
 {
     $user = Auth::user();
     $forum = Forum::find($id);
     $category = $forum->getCategory();
     $parsedContent = null;
     // L'utilisateur possède le droit de crée un topic ici
     if ($category->getPermission()->start_topic != true) {
         return Redirect::route('forum_index')->with('message', 'You can\'t start a new topic here');
     }
     // Prévisualisation du post
     if (Request::getMethod() == 'POST' && Input::get('preview') == true) {
         $code = new Decoda\Decoda(Input::get('content'));
         $code->defaults();
         $parsedContent = $code->parse();
     }
     if (Request::getMethod() == 'POST' && Input::get('post') == true) {
         // Crée le topic
         $topic = new Topic();
         $topic->name = Input::get('title');
         $topic->slug = Str::slug(Input::get('title'));
         $topic->state = 'open';
         $topic->first_post_user_id = $topic->last_post_user_id = $user->id;
         $topic->first_post_user_username = $topic->last_post_user_username = $user->username;
         $topic->views = 0;
         $topic->pinned = false;
         $topic->forum_id = $forum->id;
         $v = Validator::make($topic->toArray(), $topic->rules);
         if ($v->passes()) {
             $topic->save();
             $post = new Post();
             $post->content = Input::get('content');
             $post->user_id = $user->id;
             $post->topic_id = $topic->id;
             $v = Validator::make($post->toArray(), $post->rules);
             if ($v->passes()) {
                 $post->save();
                 $topic->num_post = 1;
                 $topic->save();
                 $forum->num_topic = $forum->getTopicCount($forum->id);
                 $forum->num_post = $forum->getPostCount($forum->id);
                 $forum->last_topic_id = $topic->id;
                 $forum->last_topic_name = $topic->name;
                 $forum->last_topic_slug = $topic->slug;
                 $forum->last_post_user_id = $user->id;
                 $forum->last_post_user_username = $user->username;
                 $forum->save();
                 return Redirect::route('forum_topic', array('slug' => $topic->slug, 'id' => $topic->id));
             } else {
                 // Impoossible de save le premier post donc delete le topic
                 $topic->delete();
             }
         } else {
             Session::put('message', 'An error has occurred with this topic. Try again.');
         }
     }
     return View::make('forum.new_topic', array('forum' => $forum, 'category' => $category, 'parsedContent' => $parsedContent, 'title' => Input::get('title'), 'content' => Input::get('content')));
 }
Ejemplo n.º 7
0
 public function admin_delete_forum($admin)
 {
     if (!isset($_GET['id'])) {
         error(__("Error"), __("No forum ID specified.", "discuss"));
     }
     $forum = new Forum($_GET['id']);
     if ($forum->no_results) {
         error(__("Error"), __("Invalid forum ID specified.", "discuss"));
     }
     if (!$forum->deletable()) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this forum.", "discuss"));
     }
     $admin->display("delete_forum", array("forum" => $forum, "forums" => Forum::find(array("where" => array("id not" => $forum->id)))), _f("Delete Forum &#8220;%s&#8221;", array(fix($forum->name)), "discuss"));
 }
Ejemplo n.º 8
0
 public function edit_topic(Request $request, $matches)
 {
     $title = $this->lang->translate('forum.create');
     // Get page for updating
     $id = intval($matches->get('id', $request->get('id')));
     // Parent topic
     $topics = \Forum::as_array(\Forum::find('all', ['conditions' => ['forum_id = 0 AND id <> ?', $id]]));
     if ($id > 0) {
         $forum = \Forum::find_by_id($id);
         $title = $this->lang->translate('forum.editing', $forum->title);
     } else {
         $forum = ['title' => $this->lang->translate('page.name'), 'forum_id' => null];
     }
     // Create or update page
     if ($request->isMethod('post')) {
         if ($forum instanceof \Forum) {
             $forum->title = $request->get('title');
             $forum->forum_id = $request->get('forum');
             $forum->author_id = $this->user->id;
         } else {
             $forum = new \Forum(['title' => $request->get('title'), 'forum_id' => $request->get('forum'), 'author_id' => $this->user->id]);
         }
         // Updating instance
         $forum->save();
         $forum = $forum->to_array();
         return static::json_response(['success' => true, 'message' => $this->lang->translate('form.saved')]);
     }
     return $this->view->render('forum/create.twig', ['forum' => $forum, 'title' => $title, 'topics' => $topics]);
 }
Ejemplo n.º 9
0
 function postTopic()
 {
     if (!Auth::check()) {
         return Redirect::to("/forums");
     }
     $topic_id = Input::get("topic_id");
     if (isset($topic_id)) {
         //Edit logic
         $topic = ForumTopic::find(Input::get("topic_id"));
         $post = $topic->firstPost;
         $user = Auth::user();
         if (!$user->canAccessTopic($topic_id)) {
             return "Access denied.";
         }
         if ($post->posted_by == $user->id || $user->isStoryteller()) {
             $body = ForumPost::replaceSpecialTerms(Input::get("body"));
             $post->body = $body;
             $post->save();
             $topic->title = Input::get("title");
             $topic->save();
             //Save an edit record
             $posted_by = Input::get("post-as");
             $poster = User::find($posted_by);
             if (!$poster) {
                 $poster = Auth::user();
             }
             $edit = new ForumEdit();
             $edit->post_id = $post->id;
             $edit->user_id = $poster->id;
             $edit->save();
             ForumTopicAddedUser::where('topic_id', $topic_id)->delete();
             $addedUsersRaw = Input::get("added-users");
             if (strlen(trim($addedUsersRaw)) > 0) {
                 $addedUsers = explode(",", $addedUsersRaw);
                 foreach ($addedUsers as $au) {
                     $new_au = new ForumTopicAddedUser();
                     $new_au->topic_id = $topic->id;
                     $new_au->user_id = $au;
                     $new_au->save();
                 }
             }
             return Redirect::to('/forums/topic/' . $post->topic->id);
         } else {
             return "Post does not belong to user";
         }
     } else {
         $user = Auth::user();
         $forum_id = Input::get("forum_id");
         $title = Input::get("title");
         $body = Input::get("body");
         if (!$user->canAccessForum($forum_id)) {
             return "Access denied.";
         }
         if ($forum_id == null || $title == null || $body == null) {
             //Validate.
             return "failed.";
         } else {
             $forum = Forum::find($forum_id);
             $permission = PermissionDefinition::find($forum->topic_permission);
             if (!$forum->topic_permission || Auth::user()->hasPermission($permission->name) || Auth::user()->isStoryteller()) {
                 $posted_by = Input::get("post-as");
                 $body = ForumPost::replaceSpecialTerms($body);
                 $topic = $forum->post($title, $body, User::find($posted_by));
                 $addedUsersRaw = Input::get("added-users");
                 if (strlen(trim($addedUsersRaw)) > 0) {
                     $addedUsers = explode(",", $addedUsersRaw);
                     foreach ($addedUsers as $au) {
                         $new_au = new ForumTopicAddedUser();
                         $new_au->topic_id = $topic->id;
                         $new_au->user_id = $au;
                         $new_au->save();
                     }
                 }
                 //Check for @mentions.
                 $this->alertMentions($posted_by, $body, $topic);
                 if ($topic) {
                     return Redirect::to('/forums/topic/' . $topic->id);
                 } else {
                     return "No access.";
                 }
             } else {
                 return 'No write permission';
             }
         }
     }
 }