function edit_action($area_id) { ForumPerm::check('edit_area', $this->getId(), $area_id); if (Request::isAjax()) { ForumEntry::update($area_id, studip_utf8decode(Request::get('name')), studip_utf8decode(Request::get('content'))); $this->render_json(array('content' => ForumEntry::killFormat(ForumEntry::killEdit(studip_utf8decode(Request::get('content')))))); } else { ForumEntry::update($area_id, Request::get('name'), Request::get('content')); $this->flash['messages'] = array('success' => _('Die Änderungen am Bereich wurden gespeichert.')); $this->redirect(PluginEngine::getLink('coreforum/index/index')); } }
/** * 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)); }
/** * Create/Update the linked posting for the passed issue_id * * @param string $seminar_id * @param string $issue_id issue id to link to * @param string $title (new) title of the posting * @param string $content (new) content of the posting */ static function setThreadForIssue($seminar_id, $issue_id, $title, $content) { if ($topic_id = self::getThreadIdForIssue($issue_id)) { // update ForumEntry::update($topic_id, $title ?: _('Ohne Titel'), $content); } else { // create // make sure the forum is set up properly ForumEntry::checkRootEntry($seminar_id); $topic_id = md5(uniqid(rand())); ForumEntry::insert(array('topic_id' => $topic_id, 'seminar_id' => $seminar_id, 'user_id' => $GLOBALS['user']->id, 'name' => $title ?: _('Ohne Titel'), 'content' => $content, 'author' => get_fullname($GLOBALS['user']->id), 'author_host' => getenv('REMOTE_ADDR')), $seminar_id); $stmt = DBManager::get()->prepare("INSERT INTO forum_entries_issues\n (issue_id, topic_id) VALUES (?, ?)"); $stmt->execute(array($issue_id, $topic_id)); } }
/** * return number of new entries since last visit up to 3 month ago * * @param string $seminar_id the seminar_id for the entries * @param string $visitdate count all entries newer than this timestamp * * @return int the number of entries */ static function getCount($parent_id, $visitdate) { if ($visitdate < time() - ForumVisit::LAST_VISIT_MAX) { $visitdate = time() - ForumVisit::LAST_VISIT_MAX; } $constraints = ForumEntry::getConstraints($parent_id); $stmt = DBManager::get()->prepare("SELECT COUNT(*) FROM forum_entries\n WHERE lft >= :lft AND rgt <= :rgt AND user_id != :user_id\n AND seminar_id = :seminar_id\n AND topic_id != seminar_id\n AND chdate > :lastvisit"); $stmt->bindParam(':user_id', $GLOBALS['user']->id); $stmt->bindParam(':lft', $constraints['lft']); $stmt->bindParam(':rgt', $constraints['rgt']); $stmt->bindParam(':seminar_id', $constraints['seminar_id']); $stmt->bindParam(':lastvisit', $visitdate); $stmt->execute(); return $stmt->fetchColumn(); }
/** * 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(); }
private function createEntry($parent_id, $course_id, $subject, $content, $anonymous) { $topic_id = self::generateID(); $data = array('topic_id' => $topic_id, 'seminar_id' => $course_id, 'user_id' => $GLOBALS['user']->id, 'name' => $subject, 'content' => $content, 'author' => $GLOBALS['user']->getFullName(), 'author_host' => $_SERVER['REMOTE_ADDR'], 'anonymous' => (int) $anonymous); \ForumEntry::insert($data, $parent_id); return $topic_id; }
/** * Create a pdf of all postings belonging to the passed seminar located * under the passed topic_id. The PDF is dispatched automatically. * * BEWARE: This function never returns, it dies after the PDF has been * (succesfully or not) dispatched. * * @param string $seminar_id * @param string $parent_id */ static function createPdf($seminar_id, $parent_id = null) { $seminar_name = get_object_name($seminar_id, 'sem'); $data = ForumEntry::getList('dump', $parent_id ?: $seminar_id); $first_page = true; $document = new ExportPDF(); $document->SetTitle(_('Forum')); $document->setHeaderTitle(sprintf(_("Forum \"%s\""), $seminar_name['name'])); $document->addPage(); foreach ($data['list'] as $entry) { if (Config::get()->FORUM_ANONYMOUS_POSTINGS && $entry['anonymous']) { $author = _('anonym'); } else { $author = $entry['author']; } if ($entry['depth'] == 1) { if (!$first_page) { $document->addPage(); } $first_page = false; $document->addContent('++++**' . _('Bereich') . ': ' . $entry['name_raw'] . '**++++' . "\n"); $document->addContent($entry['content_raw']); $document->addContent("\n\n"); } else { if ($entry['depth'] == 2) { $document->addContent('++**' . _('Thema') . ': ' . $entry['name_raw'] . '**++' . "\n"); $document->addContent('%%' . sprintf(_('erstellt von %s am %s'), $author, strftime('%A %d. %B %Y, %H:%M', (int) $entry['mkdate'])) . '%%' . "\n"); $document->addContent($entry['content_raw']); $document->addContent("\n\n"); } else { if ($entry['depth'] == 3) { $document->addContent('**' . $entry['name_raw'] . '**' . "\n"); $document->addContent('%%' . sprintf(_('erstellt von %s am %s'), $author, strftime('%A %d. %B %Y, %H:%M', (int) $entry['mkdate'])) . '%%' . "\n"); $document->addContent($entry['content_raw']); $document->addContent("\n--\n"); } } } } $document->dispatch($seminar_name['name'] . " - Forum"); die; }
<br> <? if (trim($constraint['content'])) : ?> <div class="posting"> <div class="postbody"> <div class="content"><?php echo formatReady(ForumEntry::killEdit($constraint['content'])); ?> </div> </div> </div> <? endif ?> <? if (!empty($list)) foreach ($list as $category_id => $entries) : ?> <table class="default forum" data-category-id="<?php echo $category_id; ?> "> <colgroup> <col> <col> <col> <col> </colgroup> <thead> <tr> <th colspan="2"><?php echo _('Thema'); ?>
?> > <a href="<?php echo PluginEngine::getLink('coreforum/index/index/' . $jump_to_topic_id . '#' . $jump_to_topic_id); ?> "> <span class="areaname"><?php echo htmlReady($entry['name_raw']); ?> </span> </a> <div class="areacontent" data-content="<?php echo htmlReady($entry['content_raw']); ?> "> <? $description = ForumEntry::killFormat(ForumEntry::killEdit($entry['content_raw'])) ?> <?php echo htmlReady(substr($description, 0, 150)); echo strlen($description) > 150 ? '…' : ''; ?> </div> </span> <? if (ForumPerm::has('edit_area', $seminar_id) && Request::get('edit_area') == $entry['topic_id']) : ?> <span style="text-align: center;"> <div style="width: 90%"> <?php echo $this->render_partial('area/_edit_area_form', compact('entry')); ?> </div>
public static function isClosed($topic_id) { foreach (ForumEntry::getPathToPosting($topic_id) as $entry) { if ($entry['closed']) { return true; } } return false; }
echo _('Letzte Beiträge'); ?> </a> <? elseif ($section == 'favorites') : ?> <a href="<?php echo PluginEngine::getURL('coreforum/index/favorites'); ?> "> <?php echo _('Gemerkte Beiträge'); ?> </a> <? else: ?> <? $first = true ?> <? foreach (ForumEntry::getPathToPosting($topic_id) as $path_part) : ?> <? if (!$first) : ?> >> <? endif ?> <a href="<?php echo PluginEngine::getLink('coreforum/index/index/' . $path_part['id']); ?> "> <?php echo htmlReady(ForumEntry::killFormat($path_part['name'])); ?> </a> <? $first = false ?> <? endforeach ?> <? endif ?> </span> </div>
/** * Unsubscribe from the passed topic * * @param string $topic_id */ function remove_abo_action($topic_id) { ForumPerm::check('abo', $this->getId(), $topic_id); ForumAbo::delete($topic_id); if (Request::isXhr()) { $this->constraint = ForumEntry::getConstraints($topic_id); $this->render_template('index/_abo_link'); } else { $this->flash['messages'] = array('success' => _('Abonnement aufgehoben.')); $this->redirect(PluginEngine::getLink('coreforum/index/index/' . $topic_id)); } }
/** * check if the passed topic_id belongs to the passed seminar_id. * Throws an AccessDenied denied exception if this is not the case * * @param type $seminar_id id of the seminar, the category should belong to * @param type $topic_id the id of the topic to check */ static function checkTopicId($seminar_id, $topic_id) { $data = ForumEntry::getConstraints($topic_id); if ($data['seminar_id'] != $seminar_id) { throw new AccessDeniedException(sprintf(_('Forum: Sie haben keine Berechtigung auf den Eintrag mit der ID %s zuzugreifen!'), $topic_id)); } }
/** * move the submitted topics[] to the passed destination * * @param string $destination id of seminar to move topics to */ function move_action($destination) { // check if destination is a category_id. if yes, use seminar_id instead if (ForumCat::get($destination)) { $category_id = $destination; $destination = $this->getId(); } ForumPerm::check('admin', $this->getId(), $destination); foreach (Request::getArray('topics') as $topic_id) { // make sure every passed topic_id is checked against the current seminar ForumPerm::check('admin', $this->getId(), $topic_id); // if the source is an area and the target a category, just move this area to the category $entry = ForumEntry::getEntry($topic_id); if ($entry['depth'] == 1 && $category_id) { ForumCat::removeArea($topic_id); ForumCat::addArea($category_id, $topic_id); } else { // first step: move the whole topic with all childs ForumEntry::move($topic_id, $destination); // if the current topic id is an area, remove it from any categories ForumCat::removeArea($topic_id); // second step: move all to deep childs a level up (depth > 3) $data = ForumEntry::getList('depth_to_large', $topic_id); foreach ($data['list'] as $entry) { $path = ForumEntry::getPathToPosting($entry['topic_id']); array_shift($path); // Category array_shift($path); // Area $thread = array_shift($path); // Thread ForumEntry::move($entry['topic_id'], $thread['id']); } // add entry to passed category when moving to the top if ($category_id) { ForumCat::addArea($category_id, $topic_id); } } } $this->render_nothing(); }
function getDump($seminar_id) { $this->setupAutoload(); return ForumEntry::getDump($seminar_id); }
?> </span> </a> <? endif ?> </dt> <dd> <?php echo ForumHelpers::translate_perm($GLOBALS['perm']->get_studip_perm($constraint['seminar_id'], $post['user_id'])); ?> </dd> <? if ($post['user_id']) : ?> <dd> Beiträge: <?php echo ForumEntry::countUserEntries($post['user_id']); ?> <br> <?php echo _('Erhaltene "Gefällt mir!":'); ?> <?php echo ForumLike::receivedForUser($post['user_id']); ?> </dd> <? endif ?> <? endif; ?> <dd> <? if (!$post['user_id']) : ?> <?php echo _('von Stud.IP erstellt');