public function afterStoreCallback() { if (!$this->material['host_id'] && $this->material['user_id'] !== $GLOBALS['user']->id) { PersonalNotifications::add($this->material['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/details/" . $this->material->getId() . "#review_" . $this->getId()), $this->isNew() ? sprintf(_("%s hat ein Review zu '%s' geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']) : sprintf(_("%s hat ein Review zu '%s' verändert."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id']), $this->material['name']), "review_" . $this->getId(), Icon::create("support", "clickable")); } //only push if the comment is from this server and the material-server is different if ($this->material['host_id'] && !$this['host_id'] && $this->isDirty()) { $remote = new LernmarktplatzHost($this->material['host_id']); $myHost = LernmarktplatzHost::thisOne(); $data = array(); $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']); $data['data'] = $this->toArray(); $data['data']['foreign_review_id'] = $data['data']['review_id']; unset($data['data']['review_id']); unset($data['data']['id']); unset($data['data']['user_id']); unset($data['data']['host_id']); $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD"))); if ($user_description_datafield) { $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId())); } $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null); if (!$remote->isMe()) { $remote->pushDataToEndpoint("add_review/" . $this->material['foreign_material_id'], $data); } } }
public function afterStoreCallback() { if ($this->isDirty()) { //add notification to writer of review if (!$this->review['host_id'] && $this->review['user_id'] !== $this['user_id']) { PersonalNotifications::add($this->review['user_id'], URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat einen Kommentar zu Ihrem Review geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable")); } //add notification to all users of this servers who discussed this review but are neither the new //commentor nor the writer of the review $statement = DBManager::get()->prepare("\n SELECT user_id\n FROM lernmarktplatz_comments\n WHERE review_id = :review_id\n AND host_id IS NULL\n GROUP BY user_id\n "); $statement->execute(array('review_id' => $this->review->getId())); foreach ($statement->fetchAll(PDO::FETCH_COLUMN, 0) as $user_id) { if (!in_array($user_id, array($this->review['user_id'], $this['user_id']))) { PersonalNotifications::add($user_id, URLHelper::getURL("plugins.php/lernmarktplatz/market/discussion/" . $this['review_id'] . "#comment_" . $this->getId()), sprintf(_("%s hat auch einen Kommentar geschrieben."), $this['host_id'] ? LernmarktplatzUser::find($this['user_id'])->name : get_fullname($this['user_id'])), "comment_" . $this->getId(), Icon::create("support", "clickable")); } } //only push if the comment is from this server and the material-server is different if (!$this['host_id']) { $myHost = LernmarktplatzHost::thisOne(); $data = array(); $data['host'] = array('name' => $myHost['name'], 'url' => $myHost['url'], 'public_key' => $myHost['public_key']); $data['data'] = $this->toArray(); $data['data']['foreign_comment_id'] = $data['data']['comment_id']; unset($data['data']['comment_id']); unset($data['data']['id']); unset($data['data']['user_id']); unset($data['data']['host_id']); $user_description_datafield = DataField::find(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD")) ?: DataField::findOneBySQL("name = ?", array(get_config("LERNMARKTPLATZ_USER_DESCRIPTION_DATAFIELD"))); if ($user_description_datafield) { $datafield_entry = DatafieldEntryModel::findOneBySQL("range_id = ? AND datafield_id = ?", array($this['user_id'], $user_description_datafield->getId())); } $data['user'] = array('user_id' => $this['user_id'], 'name' => get_fullname($this['user_id']), 'avatar' => Avatar::getAvatar($this['user_id'])->getURL(Avatar::NORMAL), 'description' => $datafield_entry ? $datafield_entry['content'] : null); $statement = DBManager::get()->prepare("\n SELECT host_id\n FROM lernmarktplatz_comments\n WHERE review_id = :review_id\n AND host_id IS NOT NULL\n GROUP BY host_id\n "); $statement->execute(array('review_id' => $this->review->getId())); $hosts = $statement->fetchAll(PDO::FETCH_COLUMN, 0); if ($this->review['host_id'] && !in_array($this->review['host_id'], $hosts)) { $hosts[] = $this->review['host_id']; } if ($this->review->material['host_id'] && !in_array($this->review->material['host_id'], $hosts)) { $hosts[] = $this->review->material['host_id']; } foreach ($hosts as $host_id) { $remote = new LernmarktplatzHost($host_id); if (!$remote->isMe()) { $review_id = $this->review['foreign_review_id'] ?: $this->review->getId(); if ($this->review['foreign_review_id']) { if ($this->review->host_id === $remote->getId()) { $host_hash = null; } else { $host_hash = md5($this->review->host['public_key']); } } else { $host_hash = md5($myHost['public_key']); } $remote->pushDataToEndpoint("add_comment/" . $review_id . "/" . $host_hash, $data); } } } } }
/** * Stores the general settings of a user. */ public function store_action() { $this->check_ticket(); $language = Request::get('forced_language'); if (array_key_exists($language, $GLOBALS['INSTALLED_LANGUAGES'])) { $this->user->preferred_language = $_SESSION['_language'] = $language; $this->user->store(); } $this->config->store('PERSONAL_STARTPAGE', Request::int('personal_startpage')); $this->config->store('ACCESSKEY_ENABLE', Request::int('accesskey_enable')); $this->config->store('SHOWSEM_ENABLE', Request::int('showsem_enable')); $this->config->store('SKIPLINKS_ENABLE', Request::int('skiplinks_enable')); $this->config->store('TOUR_AUTOSTART_DISABLE', Request::int('tour_autostart_disable')); if (Request::int('personal_notifications_activated')) { PersonalNotifications::activate(); } else { PersonalNotifications::deactivate(); } if (Request::int('personal_notifications_audio_activated')) { PersonalNotifications::activateAudioFeedback(); } else { PersonalNotifications::deactivateAudioFeedback(); } $this->reportSuccess(_('Die Einstellungen wurden gespeichert.')); $this->redirect('settings/general'); }
public function execute($last_result, $parameters = array()) { $db = DBManager::get(); $dd_func = function ($d) { delete_document($d); }; //abgelaufenen News löschen $deleted_news = StudipNews::DoGarbageCollect(); //messages aufräumen $to_delete = $db->query("SELECT message_id, count( message_id ) AS gesamt, count(IF (deleted =0, NULL , 1) ) AS geloescht\n FROM message_user GROUP BY message_id HAVING gesamt = geloescht")->fetchAll(PDO::FETCH_COLUMN, 0); if (count($to_delete)) { $db->exec("DELETE FROM message_user WHERE message_id IN(" . $db->quote($to_delete) . ")"); $db->exec("DELETE FROM message WHERE message_id IN(" . $db->quote($to_delete) . ")"); $to_delete_attach = $db->query("SELECT dokument_id FROM dokumente WHERE range_id IN(" . $db->quote($to_delete) . ")")->fetchAll(PDO::FETCH_COLUMN, 0); array_walk($to_delete_attach, $dd_func); } //Attachments von nicht versendeten Messages aufräumen $to_delete_attach = $db->query("SELECT dokument_id FROM dokumente WHERE range_id = 'provisional' AND chdate < UNIX_TIMESTAMP(DATE_ADD(NOW(),INTERVAL -2 HOUR))")->fetchAll(PDO::FETCH_COLUMN, 0); array_walk($to_delete_attach, $dd_func); if ($parameters['verbose']) { printf(_("Gelöschte Ankündigungen: %u") . "\n", (int) $deleted_news); printf(_("Gelöschte Nachrichten: %u") . "\n", count($to_delete)); printf(_("Gelöschte Dateianhänge: %u") . "\n", count($to_delete_attach)); } PersonalNotifications::doGarbageCollect(); // Remove old plugin assets PluginAsset::deleteBySQL('chdate < ?', array(time() - PluginAsset::CACHE_DURATION)); }
/** * Set the posting denoted by the passed topic_id as liked for the * currently logged in user * * @param string $topic_id */ static function like($topic_id) { $stmt = DBManager::get()->prepare("REPLACE INTO\n forum_likes (topic_id, user_id)\n VALUES (?, ?)"); $stmt->execute(array($topic_id, $GLOBALS['user']->id)); // get posting owner $data = ForumEntry::getConstraints($topic_id); // notify owner of posting about the like setTempLanguage($data['user_id']); $notification = get_fullname($GLOBALS['user']->id) . _(' gefällt einer deiner Forenbeiträge!'); restoreLanguage(); PersonalNotifications::add($data['user_id'], PluginEngine::getURL('coreforum/index/index/' . $topic_id . '?highlight_topic=' . $topic_id . '#' . $topic_id), $notification, $topic_id, Icon::create('forum', 'clickable')->asImagePath(40)); }
<label> <input type="checkbox" name="personal_notifications_activated" aria-describedby="personal_notifications_activated_description" value="1" <? if (PersonalNotifications::isActivated($user->user_id)) echo 'checked'; ?>> <?php echo _('Benachrichtigungen über Javascript'); ?> <?php echo tooltipIcon(_('Hiermit wird in der Kopfzeile dargestellt, wenn es Benachrichtigungen für ' . 'Sie gibt. Die Benachrichtigungen werden auch angezeigt, wenn Sie nicht die ' . 'Seite neuladen.')); ?> </label> <label> <input type="checkbox" name="personal_notifications_audio_activated" aria-describedby="personal_notifications_audio_activated_description" value="1" <? if (PersonalNotifications::isAudioActivated($user->user_id)) echo 'checked'; ?>> <?php echo _('Audio-Feedback zu Benachrichtigungen'); ?> <?php echo tooltipIcon(_('Wenn eine neue Benachrichtigung für Sie reinkommt, ' . 'werden Sie mittels eines kleinen Plopps darüber in Kenntnis gesetzt ' . '- auch wenn Sie gerade einen anderen Browsertab anschauen. Der Plopp ist ' . 'nur zu hören, wenn Sie die Benachrichtigungen über Javascript aktiviert haben.')); ?> </label> </fieldset> <footer> <?php echo \Studip\Button::create(_("Speichern")); ?> </footer> </form>
?> "> <?php echo count($notifications); ?> </div> <div class="list below" id="notification_list"> <ul> <? foreach ($notifications as $notification) : ?> <?php echo $notification->getLiElement(); ?> <? endforeach ?> </ul> </div> <? if (PersonalNotifications::isAudioActivated()) : ?> <audio id="audio_notification" preload="none"> <source src="<?php echo Assets::url('sounds/blubb.ogg'); ?> " type="audio/ogg"> <source src="<?php echo Assets::url('sounds/blubb.mp3'); ?> " type="audio/mpeg"> </audio> <? endif ?> </li> <? endif ?> <? if (isset($search_semester_nr)) : ?> <li>
/** * send out the notification messages for the passed topic. The contents * and a link directly to the topic are added to the messages. * * @param string $topic_id */ static function notify($topic_id) { // send message to all abo-users $db = DBManager::get(); $messaging = new ForumBulkMail(); // $messaging = new Messaging(); // get all parent topic-ids, to find out which users to notify $path = ForumEntry::getPathToPosting($topic_id); // fetch all users to notify, exlcude current user $stmt = $db->prepare("SELECT DISTINCT user_id\n FROM forum_abo_users\n WHERE topic_id IN (:topic_ids)\n AND user_id != :user_id"); $stmt->bindParam(':topic_ids', array_keys($path), StudipPDO::PARAM_ARRAY); $stmt->bindParam(':user_id', $GLOBALS['user']->id); $stmt->execute(); // get details for topic $topic = ForumEntry::getConstraints($topic_id); $template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../views'); $template = $template_factory->open('index/_mail_notification'); // notify users while ($data = $stmt->fetch(PDO::FETCH_ASSOC)) { $user_id = $data['user_id']; // create subject and content setTempLanguage(get_userid($user_id)); // check if user wants an email for all or selected messages only $force_email = false; if ($messaging->user_wants_email($user_id)) { $force_email = true; } $parent_id = ForumEntry::getParentTopicId($topic['topic_id']); setTempLanguage($data['user_id']); $notification = sprintf(_("%s hat einen Beitrag geschrieben"), $topic['anonymous'] ? _('Anonym') : $topic['author']); restoreLanguage(); PersonalNotifications::add($user_id, UrlHelper::getUrl('plugins.php/coreforum/index/index/' . $topic['topic_id'] . '#' . $topic['topic_id'], array('cid' => $topic['seminar_id']), true), $notification, "forumposting_" . $topic['topic_id'], Icon::create('forum', 'clickable')->asImagePath(40)); if ($force_email) { $title = implode(' >> ', ForumEntry::getFlatPathToPosting($topic_id)); $subject = addslashes(_('[Forum]') . ' ' . ($title ?: _('Neuer Beitrag'))); $htmlMessage = $template->render(compact('user_id', 'topic', 'path')); $textMessage = trim(kill_format($htmlMessage)); $userWantsHtml = UserConfig::get($user_id)->getValue('MAIL_AS_HTML'); StudipMail::sendMessage(User::find($user_id)->email, $subject, addslashes($textMessage), $userWantsHtml ? $htmlMessage : null); } restoreLanguage(); } $messaging->bulkSend(); }
/** * * @param $message * @param $rec_uname * @param $user_id * @param $time * @param $tmp_message_id * @param $set_deleted * @param $signature * @param $subject * @param $force_email * @param $priority */ function insert_message($message, $rec_uname, $user_id = '', $time = '', $tmp_message_id = '', $set_deleted = '', $signature = '', $subject = '', $force_email = '', $priority = 'normal', $tags = null) { global $user; $my_messaging_settings = UserConfig::get($user->id)->MESSAGING_SETTINGS; // wenn kein subject uebergeben $subject = $subject ?: _('Ohne Betreff'); $email_request = $this->send_as_email ?: $my_messaging_settings['send_as_email']; // wenn keine zeit uebergeben $time = $time ?: time(); // wenn keine id uebergeben $tmp_message_id = $tmp_message_id ?: md5(uniqid('321losgehtes', true)); // wenn keine user_id uebergeben $user_id = $user_id ?: $user->id; # send message now if ($user_id != '____%system%____') { // real-user message $snd_user_id = $user_id; $set_deleted = $set_deleted ?: $my_messaging_settings['save_snd'] != '1'; // don't save sms in outbox } else { // system-message $set_deleted = '1'; // system-signatur $snd_user_id = '____%system%____'; setTempLanguage(); $message .= $this->sig_string; $message .= _('Diese Nachricht wurde automatisch vom Stud.IP-System generiert. Sie können darauf nicht antworten.'); restoreLanguage(); } // Setzen der Message-ID als Range_ID für angehängte Dateien if (isset($this->provisonal_attachment_id) && $GLOBALS['ENABLE_EMAIL_ATTACHMENTS']) { $query = "UPDATE dokumente SET range_id = ?, description = '' WHERE dokument_id = ?"; $statement = DBManager::get()->prepare($query); foreach (get_message_attachments($this->provisonal_attachment_id, true) as $attachment) { $statement->execute(array($tmp_message_id, $attachment['dokument_id'])); } } // insert message $query = "INSERT INTO message (message_id, autor_id, subject, message, priority, mkdate)\n VALUES (?, ?, ?, ?, ?, UNIX_TIMESTAMP())"; $statement = DBManager::get()->prepare($query); $statement->execute(array($tmp_message_id, $snd_user_id, $subject, $message, $priority)); // insert snd $insert_tags = DBManager::get()->prepare("\n INSERT IGNORE INTO message_tags\n SET message_id = :message_id,\n user_id = :user_id,\n tag = :tag,\n chdate = UNIX_TIMESTAMP(),\n mkdate = UNIX_TIMESTAMP()\n "); $query = "INSERT INTO message_user (message_id, user_id, snd_rec, deleted, mkdate)\n VALUES (?, ?, 'snd', ?, UNIX_TIMESTAMP())"; $statement = DBManager::get()->prepare($query); $statement->execute(array($tmp_message_id, $snd_user_id, $set_deleted ? 1 : 0)); if ($tags) { is_array($tags) || ($tags = explode(" ", (string) $tags)); foreach ($tags as $tag) { $insert_tags->execute(array('message_id' => $tmp_message_id, 'user_id' => $snd_user_id, 'tag' => strtolower($tag))); } } // heben wir kein array bekommen, machen wir einfach eins ... if (!is_array($rec_uname)) { $rec_uname = array($rec_uname); } // wir bastelen ein neues array, das die user_id statt des user_name enthaelt $rec_id = array(); foreach ($rec_uname as $one) { $rec_id[] = User::findByUsername($one)->user_id; } $rec_id = array_filter($rec_id); // wir gehen das eben erstellt array durch und schauen, ob irgendwer was weiterleiten moechte. // diese user_id schreiben wir in ein tempraeres array foreach ($rec_id as $one) { $tmp_forward_id = User::find($this->get_forward_id($one))->user_id; if ($tmp_forward_id) { $rec_id[] = $tmp_forward_id; } } // wir mergen die eben erstellten arrays und entfernen doppelte eintraege $rec_id = array_unique($rec_id); // hier gehen wir alle empfaenger durch, schreiben das in die db und schicken eine mail $query = "INSERT INTO message_user (message_id, user_id, snd_rec, mkdate)\n VALUES (?, ?, 'rec', UNIX_TIMESTAMP())"; $insert = DBManager::get()->prepare($query); $snd_name = $user_id != '____%system%____' ? User::find($user_id)->getFullName() . ' (' . User::find($user_id)->username . ')' : 'Stud.IP-System'; foreach ($rec_id as $one) { $insert->execute(array($tmp_message_id, $one)); if ($GLOBALS['MESSAGING_FORWARD_AS_EMAIL']) { // mail to original receiver $mailstatus_original = $this->user_wants_email($one); if ($mailstatus_original == 2 || $mailstatus_original == 3 && $email_request == 1 || $force_email) { $this->sendingEmail($one, $snd_user_id, $message, $subject, $tmp_message_id); } } if ($tags) { foreach ($tags as $tag) { $insert_tags->execute(array('message_id' => $tmp_message_id, 'user_id' => $one, 'tag' => strtolower($tag))); } } } // Obtain all users that should receive a notification $user_ids = $rec_id; if (is_object($GLOBALS['user'])) { $user_ids = array_diff($user_ids, array($GLOBALS['user']->id)); } // Create notifications PersonalNotifications::add($user_ids, URLHelper::getUrl("dispatch.php/messages/read/{$tmp_message_id}", array('cid' => null)), sprintf(_('Sie haben eine Nachricht von %s erhalten!'), $snd_name), 'message_' . $tmp_message_id, Icon::create('mail', 'clickable')->asImagePath(80)); return sizeof($rec_id); }
public function markAsRead($user_id) { PersonalNotifications::markAsReadByHTML('message_' . $this->getId(), $user_id); return $this->markAs($user_id, 1); }
echo $GLOBALS['ABSOLUTE_URI_STUDIP']; ?> "; STUDIP.ASSETS_URL = "<?php echo $GLOBALS['ASSETS_URL']; ?> "; STUDIP.STUDIP_SHORT_NAME = "<?php echo Config::get()->STUDIP_SHORT_NAME; ?> "; String.locale = "<?php echo htmlReady(strtr($_SESSION['_language'], '_', '-')); ?> "; <? if (is_object($GLOBALS['perm']) && $GLOBALS['perm']->have_perm('autor') && PersonalNotifications::isActivated()) : ?> STUDIP.jsupdate_enable = true; <? endif ?> STUDIP.URLHelper.parameters = <?php echo json_encode(studip_utf8encode(URLHelper::getLinkParams())); ?> ; </script> <?php // needs to be included in lib/include/html_head.inc.php as well include 'app/views/WysiwygHtmlHead.php'; ?> </head> <body id="<?php echo $body_id ? $body_id : PageLayout::getBodyElementId();
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.")); } }
/** * 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.")); } }
/** * Lets the user reshare the posting. If user_id is not given, the current * user does the reshare. * @param string|null $user_id : md5 user_id of the resharing user. * @param int $external_user : is the user an external user? * @return boolean : true if reshare was successful, else false */ public function reshare($user_id = null, $external_user = 0) { if ($this['context_type'] !== "public") { return false; } $user_id or $user_id = $GLOBALS['user']->id; $share = DBManager::get()->prepare("INSERT IGNORE INTO blubber_reshares " . "SET topic_id = :topic_id, " . "user_id = :user_id, " . "external_contact = :external_contact, " . "chdate = UNIX_TIMESTAMP() " . ""); $success = $share->execute(array('topic_id' => $this['root_id'], 'user_id' => $user_id, 'external_contact' => $external_user)); if ($success) { $thread = $this->isThread() ? $this : BlubberPosting::find($this['root_id']); $thread['chdate'] = time(); $thread->store(); if (!$thread['external_contact']) { $url = URLHelper::getURL("plugins.php/blubber/streams/thread/" . $thread->getId(), array('cid' => $thread['context_type'] === "course" ? $thread['Seminar_id'] : null, 'reshared' => 1), true); PersonalNotifications::add($thread['user_id'], $url, sprintf(_("%s hat Ihren Blubber weitergesagt"), get_fullname()), "posting_" . $thread->getId(), Avatar::getAvatar($GLOBALS['user']->id)->getURL(Avatar::MEDIUM)); } } return $success; }
/** * SystemPlugins may call UpdateInformation::setInformation to set information * to be sent via ajax to the main request. Core-functionality-data should be * collected and set here. * @return array: array(array('js_function' => $data), ...) */ protected function coreInformation() { $data = array(); if (PersonalNotifications::isActivated()) { $notifications = PersonalNotifications::getMyNotifications(); if ($notifications && count($notifications)) { $ret = array(); foreach ($notifications as $notification) { $info = $notification->toArray(); $info['html'] = $notification->getLiElement(); $ret[] = $info; } $data['PersonalNotifications.newNotifications'] = $ret; } else { $data['PersonalNotifications.newNotifications'] = array(); } } $page_info = Request::getArray("page_info"); if (stripos(Request::get("page"), "dispatch.php/messages") !== false) { $messages = Message::findNew($GLOBALS["user"]->id, $page_info['Messages']['received'], $page_info['Messages']['since'], $page_info['Messages']['tag']); $template_factory = $this->get_template_factory(); foreach ($messages as $message) { $data['Messages.newMessages']['messages'][$message->getId()] = $template_factory->open("messages/_message_row.php")->render(compact("message") + array('controller' => $this)); } } if (count($page_info['Questionnaire']['questionnaire_ids']) > 0) { foreach ($page_info['Questionnaire']['questionnaire_ids'] as $questionnaire_id) { $questionnaire = new Questionnaire($questionnaire_id); if ($questionnaire->latestAnswerTimestamp() > $page_info['Questionnaire']['last_update']) { $template = $this->get_template_factory()->open("questionnaire/evaluate"); $template->set_layout(null); $template->set_attribute("questionnaire", $questionnaire); $data['Questionnaire.updateQuestionnaireResults'][$questionnaire->getId()] = array('html' => $template->render()); } } } return $data; }
public function answer_action($questionnaire_id) { $this->questionnaire = new Questionnaire($questionnaire_id); if (!$this->questionnaire->isViewable()) { throw new AccessDeniedException("Der Fragebogen ist nicht einsehbar."); } if (Request::isPost()) { $answered_before = $this->questionnaire->isAnswered(); foreach ($this->questionnaire->questions as $question) { $answer = $question->createAnswer(); if (!$answer['question_id']) { $answer['question_id'] = $question->getId(); } $answer['user_id'] = $GLOBALS['user']->id; if (!$answer['answerdata']) { $answer['answerdata'] = array(); } if ($this->questionnaire['anonymous']) { $answer['user_id'] = null; $answer['chdate'] = 1; $answer['mkdate'] = 1; } $answer->store(); } if ($this->questionnaire['anonymous']) { $anonymous_answer = new QuestionnaireAnonymousAnswer(); $anonymous_answer['questionnaire_id'] = $this->questionnaire->getId(); $anonymous_answer['user_id'] = $GLOBALS['user']->id; $anonymous_answer->store(); } if (!$answered_before && !$this->questionnaire['anonymous'] && $this->questionnaire['user_id'] !== $GLOBALS['user']->id) { $url = URLHelper::getURL("dispatch.php/questionnaire/evaluate/" . $this->questionnaire->getId(), array(), true); foreach ($this->questionnaire->assignments as $assignment) { if ($assignment['range_type'] === "course") { $url = URLHelper::getURL("dispatch.php/course/overview#" . $this->questionnaire->getId(), array('cid' => $assignment['range_id'], 'contentbox_type' => "vote", 'contentbox_open' => $this->questionnaire->getId())); } elseif ($assignment['range_type'] === "profile") { $url = URLHelper::getURL("dispatch.php/profile#" . $this->questionnaire->getId(), array('contentbox_type' => "vote", 'contentbox_open' => $this->questionnaire->getId()), true); } elseif ($assignment['range_type'] === "start") { $url = URLHelper::getURL("dispatch.php/start#" . $this->questionnaire->getId(), array('contentbox_type' => "vote", 'contentbox_open' => $this->questionnaire->getId()), true); } break; } PersonalNotifications::add($this->questionnaire['user_id'], $url, sprintf(_("%s hat an der Befragung '%s' teilgenommen."), get_fullname(), $this->questionnaire['title']), "questionnaire_" . $this->questionnaire->getId(), Assets::image_path("icons/blue/vote.svg")); } if (Request::isAjax()) { $this->response->add_header("X-Dialog-Close", "1"); $this->response->add_header("X-Dialog-Execute", "STUDIP.Questionnaire.updateWidgetQuestionnaire"); $this->render_template("questionnaire/evaluate"); } elseif (Request::get("range_type") === "user") { PageLayout::postMessage(MessageBox::success(_("Danke für die Teilnahme!"))); $this->redirect("profile?username="******"range_id"))); } elseif (Request::get("range_type") === "course") { PageLayout::postMessage(MessageBox::success(_("Danke für die Teilnahme!"))); $this->redirect("course/overview?cid=" . Request::option("range_id")); } elseif (Request::get("range_id") === "start") { PageLayout::postMessage(MessageBox::success(_("Danke für die Teilnahme!"))); $this->redirect("start"); } else { PageLayout::postMessage(MessageBox::success(_("Danke für die Teilnahme!"))); if ($GLOBALS['perm']->have_perm("autor")) { $this->redirect("questionnaire/overview"); } else { $this->redirect("questionnaire/thank_you"); } } } $this->range_type = Request::get("range_type"); $this->range_id = Request::get("range_id"); PageLayout::setTitle(sprintf(_("Fragebogen beantworten: %s"), $this->questionnaire->title)); }
public function save_review_action($plugin_id) { if (!Request::isPost()) { throw new Exception("Wrong method, use POST."); } $this->marketplugin = MarketPlugin::find($plugin_id); if (!$this->marketplugin) { throw new Exception("Unknown plugin."); } $reviews = MarketReview::findBySQL("plugin_id = ? AND user_id = ?", array($plugin_id, $GLOBALS['user']->id)); if (count($reviews)) { $this->review = $reviews[0]; } else { $this->review = new MarketReview(); $this->review['plugin_id'] = $plugin_id; $this->review['user_id'] = $GLOBALS['user']->id; } $data = Request::getArray("data"); $this->review['review'] = trim($data['review']) ?: null; if ($data['rating'] <= 5 && $data['rating'] >= 0) { $this->review['rating'] = $data['rating']; } else { throw new Exception("Rating is not in accepted range."); } $this->review->store(); PersonalNotifications::add($this->marketplugin['user_id'], PluginEngine::getURL($this->plugin, array(), "presenting/details/" . $plugin_id), sprintf(_("Ihr Plugin %s wurde von %s bewertet."), $this->marketplugin['name'], get_fullname($GLOBALS['user']->id)), null, Assets::image_path("icons/blue/star.svg")); PageLayout::postMessage(MessageBox::success(_("Review/Bewertung wurde gespeichert."))); $this->redirect('presenting/details/' . $plugin_id); }
/** * Checks if a given user should hear audio plopp for new personal notification. * Either the Stud.IP or the user could deactivate personal notification or * audio feedback. If neither is the case, this function returns true. * @param string|null $user_id : ID of special user the notification should belong to or (default:) null for current user * @return boolean : true if activated else false */ public static function isAudioActivated($user_id = null) { if (!PersonalNotifications::isGloballyActivated()) { return false; } if (!$user_id) { $user_id = $GLOBALS['user']->id; } return UserConfig::get($user_id)->getValue("PERSONAL_NOTIFICATIONS_AUDIO_DEACTIVATED") ? false : true; }