Пример #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
 /**
  * Edits the content of a blubber. Sends a message of the change to the author, if the editing user is not
  * the author of the blubber, to inform him/her about the change.
  * If the content is empty the blubber is going to be deleted, because we don't want empty
  * blubber in the system.
  *
  * @put /blubber/posting/:blubber_id
  * @put /blubber/comment/:blubber_id
  *
  * @param string $blubber_id
  *
  * @param string content  new content for the blubber
  */
 public function editBlubberPosting($blubber_id)
 {
     if (!strlen(trim($this->data['content']))) {
         $this->error(400, 'No content provided');
     }
     $blubber = new \BlubberPosting($blubber_id);
     $this->requireWriteAccessTo($blubber);
     if ($this->requestedRouteMatches('/posting/') xor $blubber->isThread()) {
         $this->notFound();
     }
     $old_content = $blubber['description'];
     \BlubberPosting::$mention_posting_id = $blubber->getId();
     \StudipTransformFormat::addStudipMarkup("mention1", '@\\"[^\\n\\"]*\\"', "", "\\BlubberPosting::mention");
     \StudipTransformFormat::addStudipMarkup("mention2", '@[^\\s]*[\\d\\w_]+', "", "\\BlubberPosting::mention");
     $content = \transformBeforeSave($this->data['content']);
     $blubber['name'] = $blubber['description'] = $content;
     $blubber->store();
     if ($blubber['user_id'] !== $GLOBALS['user']->id) {
         $this->sendEditMail($blubber, sprintf(_("%s hat als Moderator gerade Ihren Beitrag im Blubberforum editiert.\n\nDie alte Version des Beitrags lautete:\n\n%s\n\nDie neue lautet:\n\n%s\n"), get_fullname(), $old_content, $blubber['description']), _("Änderungen an Ihrem Posting."));
     }
     $this->status(204);
 }
Пример #4
0
 /**
  * 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."));
     }
 }
Пример #5
0
/**
 * Apply StudipTransformFormat rules to marked-up text.
 *
 * @param  string $text  Marked-up text.
 * @return string        HTML code computed by applying markup-rules.
 */
function transformBeforeSave($text)
{
    $markup = new StudipTransformFormat();
    return $markup->format($text);
}
Пример #6
0
/**
* Write a new/edited wiki page to database
*
* @param    string  keyword WikiPage name
* @param    string  version WikiPage version
* @param    string  body    WikiPage text
* @param    string  user_id Internal user id of editor
* @param    string  range_id    Internal id of seminar/einrichtung
*
**/
function submitWikiPage($keyword, $version, $body, $user_id, $range_id) {

    releasePageLocks($keyword, $user_id); // kill lock that was set when starting to edit
    // write changes to db, show new page
    $latestVersion=getWikiPage($keyword,false);
    if ($latestVersion) {
        $date=time();
        $lastchange = $date - $latestVersion['chdate'];
    }

    StudipTransformFormat::addStudipMarkup('wiki-comments', '(\[comment\])', null, function(){return sprintf('[comment=%s]', get_fullname());});

    //TODO: Die $message Texte klingen fürchterlich. Halbsätze, Denglisch usw...
    if ($latestVersion && ($latestVersion['body'] == $body)) {
        $message = MessageBox::info(_('Keine Änderung vorgenommen.'));
        PageLayout::postMessage($message);
    } else if ($latestVersion && ($version !== null) && ($lastchange < 30*60) && ($user_id == $latestVersion['user_id'])) {
        // if same author changes again within 30 minutes, no new verison is created
        NotificationCenter::postNotification('WikiPageWillUpdate', array($range_id, $keyword));

        // apply replace-before-save transformations
        $body = transformBeforeSave($body);

        $query = "UPDATE wiki
                  SET body = ?, chdate = UNIX_TIMESTAMP()
                  WHERE keyword = ? AND range_id = ? AND version = ?";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($body, $keyword, $range_id, $version));

        NotificationCenter::postNotification('WikiPageDidUpdate', array($range_id, $keyword));
    } else {
        if ($version === null) {
            $version=0;
        } else {
            $version=$latestVersion['version']+1;
        }

        NotificationCenter::postNotification('WikiPageWillCreate', array($range_id, $keyword));

        // apply replace-before-save transformations
        $body = transformBeforeSave($body);

        $query = "INSERT INTO wiki (range_id, user_id, keyword, body, chdate, version)
                  VALUES (?, ?, ?, ?, UNIX_TIMESTAMP(), ?)";
        $statement = DBManager::get()->prepare($query);
        $statement->execute(array($range_id, $user_id, $keyword, $body, $version));

        NotificationCenter::postNotification('WikiPageDidCreate', array($range_id, $keyword));
    }
    StudipTransformFormat::removeStudipMarkup('wiki-comments');
    refreshBacklinks($keyword, $body);
}