예제 #1
0
 /**
  * Pre-Markup rule. Recognizes mentions in blubber as @username or @"Firstname lastname"
  * and turns them into usual studip-links. The mentioned person is notified by
  * sending a message to him/her as a side-effect.
  * @param StudipTransformFormat $markup
  * @param array $matches
  * @return string
  */
 public static function mention($markup, $matches)
 {
     $mention = $matches[1];
     $posting = new BlubberPosting(self::$mention_posting_id);
     $username = stripslashes(substr($mention, 1));
     if ($username[0] !== '"') {
         $user = BlubberUser::findByUsername($username);
         if (!$user) {
             $user = BlubberExternalContact::findByEmail($username);
         }
     } else {
         $name = substr($username, 1, strlen($username) - 2);
         $statement = DBManager::get()->prepare("SELECT user_id FROM auth_user_md5 WHERE CONCAT(Vorname, ' ', Nachname) = :name " . "");
         $statement->execute(array('name' => $name));
         $user_id = $statement->fetch(PDO::FETCH_COLUMN, 0);
         if ($user_id) {
             $user = new BlubberUser($user_id);
         } else {
             $statement = DBManager::get()->prepare("SELECT external_contact_id FROM blubber_external_contact WHERE name = ? " . "");
             $statement->execute(array($name));
             $user_id = $statement->fetch(PDO::FETCH_COLUMN, 0);
             $user = BlubberExternalContact::find($user_id);
         }
     }
     if ($user && !$posting->isNew() && $user->getId() && $user->getId() !== $GLOBALS['user']->id) {
         $user->mention($posting);
         $statement = DBManager::get()->prepare("INSERT IGNORE INTO blubber_mentions " . "SET user_id = :user_id, " . "topic_id = :topic_id, " . "external_contact = :extern, " . "mkdate = UNIX_TIMESTAMP() " . "");
         $statement->execute(array('user_id' => $user->getId(), 'topic_id' => $posting['root_id'], 'extern' => is_a($user, "BlubberExternalContact") ? 1 : 0));
         return '[' . $user->getName() . ']' . $user->getURL() . ' ';
     } else {
         return $markup->quote($matches[0]);
     }
 }
예제 #2
0
 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."));
     }
 }
예제 #3
0
파일: streams.php 프로젝트: ratbird/hope
 /**
  * Writes a comment on a thread and outputs the metadata of new comment as json.
  * @throws AccessDeniedException
  */
 public function comment_action()
 {
     if (!Request::isPost()) {
         throw new Exception("GET not supported");
     }
     $context = Request::option("context");
     $thread = new BlubberPosting(Request::option("thread"));
     if ($thread['context_type'] === "course" && $GLOBALS['SessSemName']['class'] === "sem") {
         $seminar = new Seminar($context);
         if ($seminar->write_level > 0 && !$GLOBALS['perm']->have_studip_perm("autor", $context)) {
             throw new AccessDeniedException();
         }
     }
     BlubberPosting::$course_hashes = $thread['context_type'] === "course" ? $thread['Seminar_id'] : false;
     if (!$thread->isNew() && $thread['Seminar_id'] === $context) {
         $output = array();
         $posting = new BlubberPosting();
         $posting['context_type'] = $thread['context_type'];
         $posting['seminar_id'] = $thread['Seminar_id'];
         $posting['root_id'] = $posting['parent_id'] = $thread->getId();
         $posting['name'] = "Re: " . $thread['name'];
         if ($GLOBALS['user']->id !== "nobody") {
             $posting['user_id'] = $GLOBALS['user']->id;
         } 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;
             } else {
                 throw new AccessDeniedException("No permission to write posting.");
             }
         }
         $posting['author_host'] = $_SERVER['REMOTE_ADDR'];
         $posting['description'] = studip_utf8decode(Request::get("content"));
         $posting->store();
         BlubberPosting::$mention_posting_id = $posting->getId();
         StudipTransformFormat::addStudipMarkup("mention1", '@\\"[^\\n\\"]*\\"', null, "BlubberPosting::mention");
         StudipTransformFormat::addStudipMarkup("mention2", '@[^\\s]*[\\d\\w_]+', null, "BlubberPosting::mention");
         $content = transformBeforeSave(studip_utf8decode(Request::get("content")));
         $posting['description'] = $content;
         $posting->store();
         $factory = new Flexi_TemplateFactory($this->plugin->getPluginPath() . "/views/streams");
         $template = $factory->open("comment.php");
         $template->set_attribute('posting', $posting);
         $template->set_attribute('course_id', $thread['Seminar_id']);
         $output['content'] = $template->render($template->render());
         $output['mkdate'] = time();
         $output['posting_id'] = $posting->getId();
         //Notifications:
         $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);
         foreach ($user_ids as $user_id) {
             setTempLanguage($user_id);
             $avatar = Visibility::verify('picture', $GLOBALS['user']->id, $user_id) ? Avatar::getAvatar($GLOBALS['user']->id) : Avatar::getNobody();
             PersonalNotifications::add($user_id, PluginEngine::getURL($this->plugin, array('cid' => $thread['context_type'] === "course" ? $thread['Seminar_id'] : null), "streams/thread/" . $thread->getId()), sprintf(_("%s hat einen Kommentar geschrieben"), get_fullname()), "posting_" . $posting->getId(), $avatar->getURL(Avatar::MEDIUM));
             restoreLanguage();
         }
         $this->render_json($output);
     } else {
         $this->render_json(array('error' => "Konnte thread nicht zuordnen."));
     }
 }