/** * Common code for all actions: set default layout and page title. * * @param type $action * @param type $args */ function before_filter(&$action, &$args) { $this->validate_args($args, array('option', 'option')); parent::before_filter($action, $args); // set correct encoding if this is an ajax-call if (Request::isAjax()) { header('Content-Type: text/html; charset=Windows-1252'); } $this->flash = Trails_Flash::instance(); // set default layout $layout = $GLOBALS['template_factory']->open('layouts/base'); $this->set_layout($layout); // Set help keyword for Stud.IP's user-documentation and page title PageLayout::setHelpKeyword('Basis.Forum'); PageLayout::setTitle($_SESSION['SessSemName']['header_line'] . ' - ' . _('Forum')); $this->AVAILABLE_DESIGNS = array('web20', 'studip'); if ($GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] && $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] != '/') { $this->picturepath = $GLOBALS['CANONICAL_RELATIVE_PATH_STUDIP'] . '/' . $this->dispatcher->trails_root . '/img'; } else { $this->picturepath = '/' . $this->dispatcher->trails_root . '/img'; } // we want to display the dates in german setlocale(LC_TIME, 'de_DE@euro', 'de_DE', 'de', 'ge'); // the default for displaying timestamps $this->time_format_string = "%a %d. %B %Y, %H:%M"; $this->time_format_string_short = "%d.%m.%Y, %H:%M"; $this->template_factory = new Flexi_TemplateFactory(dirname(__FILE__) . '/../templates'); //$this->check_token(); ForumVisit::setVisit($this->getId()); if (Request::int('page')) { ForumHelpers::setPage(Request::int('page')); } $this->seminar_id = $this->getId(); }
function add_action($category_id) { ForumPerm::check('add_area', $this->getId()); $new_id = md5(uniqid(rand())); if (Request::isXhr()) { $name = studip_utf8decode(Request::get('name', _('Kein Titel'))); $content = studip_utf8decode(Request::get('content')); } else { $name = Request::get('name', _('Kein Titel')); $content = Request::get('content'); } ForumEntry::insert(array('topic_id' => $new_id, 'seminar_id' => $this->getId(), 'user_id' => $GLOBALS['user']->id, 'name' => $name, 'content' => $content, 'author' => get_fullname($GLOBALS['user']->id), 'author_host' => getenv('REMOTE_ADDR')), $this->getId()); ForumCat::addArea($category_id, $new_id); if (Request::isXhr()) { $this->set_layout(null); $this->entry = array_pop(ForumEntry::parseEntries(array(ForumEntry::getEntry($new_id)))); $this->visitdate = ForumVisit::getLastVisit($this->getId()); } else { $this->redirect(PluginEngine::getLink('coreforum/index/index/')); } }
function getIconNavigation($course_id, $last_visit, $user_id = null) { if (!$this->isActivated($course_id)) { return; } $this->setupAutoload(); if ($GLOBALS['perm']->have_studip_perm('user', $course_id)) { $num_entries = ForumVisit::getCount($course_id, ForumVisit::getVisit($course_id)); $text = ForumHelpers::getVisitText($num_entries, $course_id); } else { $num_entries = 0; $text = 'Forum'; } $navigation = new Navigation('forum', PluginEngine::getURL($this, array(), 'index/enter_seminar')); $navigation->setBadgeNumber($num_entries); if ($num_entries > 0) { $navigation->setImage(Icon::create('forum+new', 'attention', ["title" => $text])); } else { $navigation->setImage(Icon::create('forum', 'inactive', ["title" => $text])); } return $navigation; }
<img src="<?php echo $picturepath; ?> /anfasser_48.png" class="handle js" id="tutorMoveArea"> <? endif ?> <a href="<?php echo PluginEngine::getLink('coreforum/index/index/' . $jump_to_topic_id . '#' . $jump_to_topic_id); ?> "> <? if ($entry['chdate'] >= $visitdate && $entry['user_id'] != $GLOBALS['user']->id): ?> <?php echo Icon::create('forum+new', 'attention', ['title' => _('Dieser Eintrag ist neu!')])->asImg(16, ["id" => 'tutorNotificationIcon', "style" => 'margin-bottom: 15px;']); ?> <? else : ?> <? $num_postings = ForumVisit::getCount($entry['topic_id'], $visitdate) ?> <? $text = ForumHelpers::getVisitText($num_postings, $entry['topic_id'], $constraint['depth']) ?> <? if ($num_postings > 0) : ?> <?php echo Icon::create('forum', 'attention', ['title' => $text])->asImg(16, ["id" => 'tutorNotificationIcon', "style" => 'margin-bottom: 15px;']); ?> <? else : ?> <?php echo Icon::create('forum', 'info', ['title' => $text])->asImg(16, ["id" => 'tutorNotificationIcon', "style" => 'margin-bottom: 15px;']); ?> <? endif ?> <? endif ?> </a> </td> <td class="areaentry"> <div style="position: relative;<?php
/** * get a list of postings of a special type * * @param string $type one of 'area', 'list', 'postings', 'latest', 'favorites', 'dump', 'flat' * @param string $parent_id the are to fetch from * @return array array('list' => ..., 'count' => ...); */ static function getList($type, $parent_id) { $start = (ForumHelpers::getPage() - 1) * ForumEntry::POSTINGS_PER_PAGE; switch ($type) { case 'area': $list = ForumEntry::getEntries($parent_id, ForumEntry::WITHOUT_CHILDS, '', 'DESC', 0, 1000); $postings = $list['list']; $postings = ForumEntry::getLastPostings($postings); return array('list' => $postings, 'count' => $list['count']); break; case 'list': $constraint = ForumEntry::getConstraints($parent_id); // purpose of the following query is to retrieve the threads // for an area ordered by the mkdate of their latest posting $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS\n fe.*, IF(ou.topic_id IS NOT NULL, 'fav', NULL) as fav\n FROM forum_entries AS fe\n LEFT JOIN forum_favorites as ou ON (ou.topic_id = fe.topic_id AND ou.user_id = :user_id)\n WHERE fe.seminar_id = :seminar_id AND fe.lft > :left\n AND fe.rgt < :right AND fe.depth = 2\n ORDER BY sticky DESC, latest_chdate DESC\n LIMIT {$start}, " . ForumEntry::POSTINGS_PER_PAGE); $stmt->bindParam(':seminar_id', $constraint['seminar_id']); $stmt->bindParam(':left', $constraint['lft'], PDO::PARAM_INT); $stmt->bindParam(':right', $constraint['rgt'], PDO::PARAM_INT); $stmt->bindParam(':user_id', $GLOBALS['user']->id); $stmt->execute(); $postings = $stmt->fetchAll(PDO::FETCH_ASSOC); $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn(); $postings = ForumEntry::parseEntries($postings); $postings = ForumEntry::getLastPostings($postings); return array('list' => $postings, 'count' => $count); break; case 'postings': return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'ASC', $start); break; case 'newest': $constraint = ForumEntry::getConstraints($parent_id); // get postings $stmt = DBManager::get()->prepare("SELECT forum_entries.*, IF(ou.topic_id IS NOT NULL, 'fav', NULL) as fav\n FROM forum_entries\n LEFT JOIN forum_favorites as ou ON (ou.topic_id = forum_entries.topic_id AND ou.user_id = :user_id)\n WHERE seminar_id = :seminar_id AND lft > :left\n AND rgt < :right AND (mkdate >= :mkdate OR chdate >= :mkdate)\n ORDER BY mkdate ASC\n LIMIT {$start}, " . ForumEntry::POSTINGS_PER_PAGE); $stmt->bindParam(':seminar_id', $constraint['seminar_id']); $stmt->bindParam(':left', $constraint['lft']); $stmt->bindParam(':right', $constraint['rgt']); $stmt->bindParam(':mkdate', ForumVisit::getLastVisit($constraint['seminar_id'])); $stmt->bindParam(':user_id', $GLOBALS['user']->id); $stmt->execute(); $postings = $stmt->fetchAll(PDO::FETCH_ASSOC); $postings = ForumEntry::parseEntries($postings); // var_dump($postings); // count found postings $stmt_count = DBManager::get()->prepare("SELECT COUNT(*)\n FROM forum_entries\n WHERE seminar_id = :seminar_id AND lft > :left\n AND rgt < :right AND mkdate >= :mkdate\n ORDER BY mkdate ASC"); $stmt_count->bindParam(':seminar_id', $constraint['seminar_id']); $stmt_count->bindParam(':left', $constraint['lft']); $stmt_count->bindParam(':right', $constraint['rgt']); $stmt_count->bindParam(':mkdate', ForumVisit::getLastVisit($constraint['seminar_id'])); $stmt_count->execute(); // return results return array('list' => $postings, 'count' => $stmt_count->fetchColumn()); break; case 'latest': return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'DESC', $start); break; case 'favorites': $add = "AND ou.topic_id IS NOT NULL"; return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, $add, 'DESC', $start); break; case 'dump': return ForumEntry::getEntries($parent_id, ForumEntry::WITH_CHILDS, '', 'ASC', 0, false); break; case 'flat': $constraint = ForumEntry::getConstraints($parent_id); $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM forum_entries\n WHERE lft > ? AND rgt < ? AND seminar_id = ? AND depth = ?\n ORDER BY name ASC"); $stmt->execute(array($constraint['lft'], $constraint['rgt'], $constraint['seminar_id'], $constraint['depth'] + 1)); $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn(); $posting_list = array(); // speed up things a bit by leaving out the formatReady fields foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $data) { $posting_list[$data['topic_id']] = array('author' => $data['author'], 'topic_id' => $data['topic_id'], 'name_raw' => $data['name'], 'content_raw' => ForumEntry::killEdit($data['content']), 'content_short' => $desc_short, 'chdate' => $data['chdate'], 'mkdate' => $data['mkdate'], 'user_id' => $data['user_id'], 'raw_title' => $data['name'], 'raw_description' => ForumEntry::killEdit($data['content']), 'fav' => $data['fav'] == 'fav', 'depth' => $data['depth'], 'seminar_id' => $data['seminar_id']); } return array('list' => $posting_list, 'count' => $count); break; case 'depth_to_large': $constraint = ForumEntry::getConstraints($parent_id); $stmt = DBManager::get()->prepare("SELECT SQL_CALC_FOUND_ROWS * FROM forum_entries\n WHERE lft > ? AND rgt < ? AND seminar_id = ? AND depth > 3\n ORDER BY name ASC"); $stmt->execute(array($constraint['lft'], $constraint['rgt'], $constraint['seminar_id'])); $count = DBManager::get()->query("SELECT FOUND_ROWS()")->fetchColumn(); return array('list' => $stmt->fetchAll(PDO::FETCH_ASSOC), 'count' => $count); break; } }
/** * show search results * * @param int $page show entries on submitted page */ function search_action($page = null) { ForumPerm::check('search', $this->getId()); $nav = Navigation::getItem('course/forum2'); $nav->setImage(Icon::create('forum', 'info')); Navigation::activateItem('course/forum2/index'); // set page to which we shall jump if ($page) { ForumHelpers::setPage($page); } $this->section = 'search'; $this->topic_id = $this->getId(); $this->show_full_path = true; // parse filter-options foreach (array('search_title', 'search_content', 'search_author') as $option) { $this->options[$option] = Request::option($option); } $this->searchfor = Request::get('searchfor'); if (strlen($this->searchfor) < 3) { $this->flash['messages'] = array('error' => _('Ihr Suchbegriff muss mindestens 3 Zeichen lang sein und darf nur Buchstaben und Zahlen enthalten!')); } else { // get search-results $list = ForumEntry::getSearchResults($this->getId(), $this->searchfor, $this->options); $this->postings = $list['list']; $this->number_of_entries = $list['count']; $this->highlight = $list['highlight']; if (empty($this->postings)) { $this->flash['messages'] = array('info' => _('Es wurden keine Beiträge gefunden, die zu Ihren Suchkriterien passen!')); } } // set default layout $layout = $GLOBALS['template_factory']->open('layouts/base'); $this->set_layout($layout); // exploit the visitdate for this view $this->visitdate = ForumVisit::getLastVisit($this->getId()); $this->render_action('index'); }