Пример #1
0
 /**
  * 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));
 }
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
 /**
  * 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();
 }
Пример #4
0
 private function findEntry($entry_id)
 {
     $raw = \ForumEntry::getConstraints($entry_id);
     if ($raw === false) {
         $this->notFound();
     }
     $entry = $this->convertEntry($raw);
     $children = \ForumEntry::getEntries($entry_id, \ForumEntry::WITHOUT_CHILDS, '', 'ASC', 0, false);
     if (isset($children['list'][$entry_id])) {
         unset($children['list'][$entry_id]);
     }
     $entry['children'] = array();
     foreach (array_values($children['list']) as $childentry) {
         $entry['children'][] = $this->convertEntry($childentry);
     }
     return $entry;
 }
Пример #5
0
 /**
  * move the passed topic to the passed area
  *
  * @param type $topic_id the topic to move
  * @param type $destination the area_id where the topic is moved to
  *
  * @return void
  */
 function move($topic_id, $destination)
 {
     // #TODO: Zusammenfassen in eine Transaktion!!!
     $constraints = ForumEntry::getConstraints($topic_id);
     // move the affected entries "outside" the tree
     $stmt = DBManager::get()->prepare("UPDATE forum_entries\n            SET lft = lft * -1, rgt = (rgt * -1)\n            WHERE seminar_id = ? AND lft >= ? AND rgt <= ?");
     $stmt->execute(array($constraints['seminar_id'], $constraints['lft'], $constraints['rgt']));
     // update the lft and rgt values of the parent to reflect the "deletion"
     $diff = $constraints['rgt'] - $constraints['lft'] + 1;
     $stmt = DBManager::get()->prepare("UPDATE forum_entries SET lft = lft - {$diff}\n            WHERE lft > ? AND seminar_id = ?");
     $stmt->execute(array($constraints['rgt'], $constraints['seminar_id']));
     $stmt = DBManager::get()->prepare("UPDATE forum_entries SET rgt = rgt - {$diff}\n            WHERE rgt > ? AND seminar_id = ?");
     $stmt->execute(array($constraints['rgt'], $constraints['seminar_id']));
     // make some space by updating the lft and rgt values of the target node
     $constraints_destination = ForumEntry::getConstraints($destination);
     $size = $constraints['rgt'] - $constraints['lft'] + 1;
     DBManager::get()->exec("UPDATE forum_entries SET lft = lft + {$size}\n            WHERE lft > " . $constraints_destination['rgt'] . " AND seminar_id = '" . $constraints_destination['seminar_id'] . "'");
     DBManager::get()->exec("UPDATE forum_entries SET rgt = rgt + {$size}\n            WHERE rgt >= " . $constraints_destination['rgt'] . " AND seminar_id = '" . $constraints_destination['seminar_id'] . "'");
     //move the entries from "outside" the tree to the target node
     $constraints_destination = ForumEntry::getConstraints($destination);
     // update the depth to reflect the new position in the tree
     // determine if we need to add, subtract or even do nothing to/from the depth
     $depth_mod = $constraints_destination['depth'] - $constraints['depth'] + 1;
     DBManager::get()->exec("UPDATE forum_entries\n            SET depth = depth + (" . $depth_mod . ")\n            WHERE seminar_id = '" . $constraints_destination['seminar_id'] . "'\n                AND lft < 0");
     // move the tree to its destination
     $diff = $constraints_destination['rgt'] - ($constraints['rgt'] - $constraints['lft']) - 1 - $constraints['lft'];
     DBManager::get()->exec("UPDATe forum_entries\n            SET lft = (lft * -1) + {$diff}, rgt = (rgt * -1) + {$diff}\n            WHERE seminar_id = '" . $constraints_destination['seminar_id'] . "'\n                AND lft < 0");
 }
Пример #6
0
 /**
  * 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));
     }
 }
Пример #7
0
 /**
  * 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));
     }
 }
Пример #8
0
echo $post['topic_id'];
?>
" <?php 
echo $edit_posting == $post['topic_id'] ? '' : 'style="display: none;"';
?>
>
                <input type="text" name="name" value="<?php 
echo htmlReady($post['name_raw']);
?>
" data-reset="<?php 
echo htmlReady($post['name_raw']);
?>
" style="width: 100%">
            </span>
            <? else : ?>
                <? $parent_topic = ForumEntry::getConstraints(ForumEntry::getParentTopicId($post['topic_id'])) ?>

                <? if($constraint['closed']) : ?>
                <?php 
echo Icon::create('lock-locked', 'info', ['title' => _('Dieses Thema wurde geschlossen. Sie können daher nicht auf diesen Beitrag antworten.')])->asImg(16);
?>
                <? endif ?>

                <span data-edit-topic="<?php 
echo $post['topic_id'];
?>
">
                    <span name="name" value="<?php 
echo htmlReady($parent_topic['name']);
?>
"></span>