コード例 #1
0
ファイル: forum.php プロジェクト: noackorama/blubberforum
 public function comment_action()
 {
     $context = Request::option("context");
     $thread = new ForumPosting(Request::option("thread"));
     if ($thread['context_type'] === "course") {
         $seminar = new Seminar($context);
         if ($seminar->write_level > 0 && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
             throw new AccessDeniedException("Kein Zugriff");
         }
     }
     ForumPosting::$course_hashes = $thread['context_type'] === "course" ? $thread['Seminar_id'] : false;
     if (Request::option("thread") && $thread['Seminar_id'] === $context) {
         $output = array();
         $posting = new ForumPosting();
         ForumPosting::$mention_thread_id = $thread->getId();
         StudipTransformFormat::addStudipMarkup("mention1", '@\\"[^\\n\\"]*\\"', "", "ForumPosting::mention");
         StudipTransformFormat::addStudipMarkup("mention2", '@[^\\s]*[\\d\\w_]+', "", "ForumPosting::mention");
         $content = transformBeforeSave(studip_utf8decode(Request::get("content")));
         //mentions einbauen:
         $content = preg_replace("/(@\"[^\n\"]*\")/e", "ForumPosting::mention('\\1', '" . $thread->getId() . "')", $content);
         $content = preg_replace("/(@[^\\s]+)/e", "ForumPosting::mention('\\1', '" . $thread->getId() . "')", $content);
         $posting['description'] = $content;
         $posting['context_type'] = $thread['context_type'];
         $posting['seminar_id'] = $thread['Seminar_id'];
         $posting['root_id'] = $posting['parent_id'] = Request::option("thread");
         $posting['name'] = "Re: " . $thread['name'];
         if ($GLOBALS['user']->id !== "nobody") {
             $posting['user_id'] = $GLOBALS['user']->id;
             $posting['author'] = get_fullname();
         } else {
             if (Request::get("anonymous_security") === $_SESSION['blubber_anonymous_security']) {
                 $contact_user = BlubberExternalContact::findByEmail(Request::get("anonymous_email"));
                 $_SESSION['anonymous_email'] = Request::get("anonymous_email");
                 $_SESSION['anonymous_name'] = $contact_user['name'] = Request::get("anonymous_name");
                 $contact_user->store();
                 $posting['user_id'] = $contact_user->getId();
                 $posting['external_contact'] = 1;
                 $posting['author'] = Request::get("anonymous_name");
             } else {
                 throw new AccessDeniedException("No permission to write posting.");
             }
         }
         $posting['author_host'] = $_SERVER['REMOTE_ADDR'];
         if ($posting->store()) {
             $factory = new Flexi_TemplateFactory($this->plugin->getPluginPath() . "/views/forum");
             $template = $factory->open("comment.php");
             $template->set_attribute('posting', $posting);
             $template->set_attribute('course_id', $thread['Seminar_id']);
             $output['content'] = studip_utf8encode($template->render($template->render()));
             $output['mkdate'] = time();
             $output['posting_id'] = $posting->getId();
             //Notifications:
             if (class_exists("PersonalNotifications")) {
                 $user_ids = array();
                 if ($thread['user_id'] && $thread['user_id'] !== $GLOBALS['user']->id) {
                     $user_ids[] = $thread['user_id'];
                 }
                 foreach ((array) $thread->getChildren() as $comment) {
                     if ($comment['user_id'] && $comment['user_id'] !== $GLOBALS['user']->id && !$comment['external_contact']) {
                         $user_ids[] = $comment['user_id'];
                     }
                 }
                 $user_ids = array_unique($user_ids);
                 PersonalNotifications::add($user_ids, PluginEngine::getURL($this->plugin, array('cid' => $thread['context_type'] === "course" ? $thread['Seminar_id'] : null), "forum/thread/" . $thread->getId()), get_fullname() . " hat einen Kommentar geschrieben", "posting_" . $posting->getId(), Avatar::getAvatar($GLOBALS['user']->id)->getURL(Avatar::MEDIUM));
             }
         }
         $this->render_json($output);
     } else {
         $this->render_json(array('error' => "Konnte thread nicht zuordnen."));
     }
 }