/**
  * Return the default title of the avatar.
  * @return string the default title
  */
 function getDefaultTitle()
 {
     return BlubberExternalContact::find($this->user_id)->name;
 }
Example #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."));
     }
 }
 /**
  * Returns an object of the author of this posting. This object may be BlubberUser
  * or BlubberExternalContact or any other object that implemenst the 
  * BlubberContact-interface (see there).
  * @return \BlubberContact
  */
 public function getUser()
 {
     if ($this['external_contact']) {
         $statement = DBManager::get()->prepare("SELECT * FROM blubber_external_contact WHERE external_contact_id = ? " . "");
         $statement->execute(array($this['user_id']));
         $data = $statement->fetch(PDO::FETCH_ASSOC);
         if (class_exists($data['contact_type'])) {
             $user = new $data['contact_type']();
             if (is_a($user, "BlubberContact")) {
                 $user->setData($data);
                 return $user;
             }
         }
         $user = new BlubberExternalContact();
         $user->setData($data);
         return $user;
     } else {
         return new BlubberUser($this['user_id']);
     }
 }
Example #4
0
 /**
  * Current user is going to follow (add as buddy) the given user, who could
  * also be an external contact.
  */
 public function follow_user_action()
 {
     if (!$GLOBALS['perm']->have_perm("autor")) {
         throw new AccessDeniedException();
     }
     if (Request::get("external_contact")) {
         $user = BlubberExternalContact::find(Request::option("user_id"));
     } else {
         $user = new BlubberUser(Request::option("user_id"));
     }
     if (!$user->isNew()) {
         if (is_a($user, "BlubberExternalContact")) {
             $statement = DBManager::get()->prepare("INSERT IGNORE INTO blubber_follower " . "SET studip_user_id = :user_id, " . "external_contact_id = :contact_id, " . "left_follows_right = '1' " . "");
             $success = $statement->execute(array('user_id' => $GLOBALS['user']->id, 'contact_id' => $user->getId()));
             if ($success) {
                 NotificationCenter::postNotification('BlubberExternalContactDidAdd', $user);
             }
         } else {
             Contact::import(array('owner_id' => User::findCurrent()->id, 'user_id' => $user->id))->store();
         }
     }
     $this->render_json(array('success' => 1, 'message' => (string) MessageBox::success(_("Kontakt hinzugefĆ¼gt"))));
 }
Example #5
0
 /**
  * Returns all known users that have been sharing this thread.
  * @return array of \BlubberContact
  */
 public function getSharingUsers()
 {
     if ($this['context_type'] !== "public") {
         return array();
     }
     $get_shares = DBManager::get()->prepare("SELECT * FROM blubber_reshares WHERE topic_id = ? " . "");
     $get_shares->execute(array($this['root_id']));
     $shares = $get_shares->fetchAll(PDO::FETCH_ASSOC);
     $users = array();
     foreach ($shares as $share) {
         $users[] = $share['external_contact'] ? BlubberExternalContact::find($share['user_id']) : BlubberUser::find($share['user_id']);
     }
     return $users;
 }