Ejemplo n.º 1
0
 /**
  * Отобразить карточку темы
  *
  * @param string $alias - url темы
  * @throws CHttpException
  *
  * @return void
  */
 public function actionShow($alias = null)
 {
     $topic = ForumTopic::model()->findByAttributes(array('alias' => $alias));
     if ($topic === null) {
         throw new CHttpException(404, Yii::t('ForumModule.forum', 'Page was not found!'));
     }
     if (($data = Yii::app()->getRequest()->getPost('ForumMessage')) !== null) {
         $model = new ForumMessage();
         $model->setAttributes($data);
         $model->topic_id = $topic->id;
         $model->user_id = Yii::app()->user->id;
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, 'Сообщение добавлено');
             $this->redirect(Yii::app()->createUrl($this->getRoute(), array('alias' => $topic->alias)));
         }
     }
     $this->render('show', array('topic' => $topic));
 }
 function SendCommentsSubscriptions(ReviewItem $review_item, ForumMessage $message)
 {
     # get all subscriptions for this item
     if (AuthenticationManager::GetUser()->IsSignedIn() and $review_item->GetId()) {
         $s_person = $this->GetSettings()->GetTable('User');
         $s_sub = $this->GetSettings()->GetTable('EmailSubscription');
         # join to item's table to get the title, regardless of message title
         $s_sql = '';
         switch ($review_item->GetType()) {
             case ContentType::STOOLBALL_MATCH:
                 $matches = $this->GetSettings()->GetTable('Match');
                 $s_sql = "SELECT {$matches}.match_title AS title, {$s_person}.email\n\t\t\t\t\tFROM ({$s_person} INNER JOIN {$s_sub} ON {$s_person}.user_id = {$s_sub}.user_id AND {$s_sub}.item_type = " . ContentType::STOOLBALL_MATCH . ")\n\t\t\t\t\tINNER JOIN {$matches} ON {$s_sub}.item_id = {$matches}.match_id AND {$s_sub}.item_type = " . ContentType::STOOLBALL_MATCH . "\n\t\t\t\t\tWHERE {$s_sub}.item_id = " . Sql::ProtectNumeric($review_item->GetId()) . " AND {$s_person}.user_id <> " . Sql::ProtectNumeric(AuthenticationManager::GetUser()->GetId());
                 break;
         }
         if ($s_sql) {
             # if there's at least one person, build email
             require_once 'Zend/Mail.php';
             $email = new Zend_Mail('UTF-8');
             if ($this->GetEmailAddresses($s_sql, $email)) {
                 $o_filter = new BadLanguageFilter();
                 $s_title = $o_filter->Filter($this->s_review_item_title);
                 unset($o_filter);
                 $s_title = StringFormatter::PlainText($s_title);
                 # send the email
                 $email->addTo($this->GetSettings()->GetSubscriptionEmailTo());
                 $email->setFrom($this->GetSettings()->GetSubscriptionEmailFrom(), $this->GetSettings()->GetSubscriptionEmailFrom());
                 $email->setSubject("Email alert: '" . $s_title . "'");
                 $email->setBodyText($this->GetHeader() . trim(AuthenticationManager::GetUser()->GetName()) . ' has just commented on a page at ' . $this->GetSettings()->GetSiteName() . ' for which you subscribed to an email alert.' . "\n\n" . "The page is called '" . $s_title . "' - here's an excerpt of the new comments:\n\n" . $message->GetExcerpt() . "\n\n" . 'View the new comments at' . "\n" . $review_item->GetNavigateUrl() . '#message' . $message->GetId() . $this->GetFooter());
                 try {
                     $email->send();
                 } catch (Zend_Mail_Transport_Exception $e) {
                     # Do nothing - email not that important so, if it fails, fail silently rather than raising a fatal error
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Возвращает модель по указанному идентификатору
  * Если модель не будет найдена - возникнет HTTP-исключение.
  *
  * @param integer идентификатор нужной модели
  * @return ForumMessage $model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ForumMessage::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('ForumModule.forum', 'Page was not found!'));
     }
     return $model;
 }
Ejemplo n.º 4
0
 public function getTopics($limit = -1)
 {
     $criteria = new CDbCriteria();
     $criteria->select = "`t`.*";
     $criteria->compare('forum_id', $this->id);
     $criteria->join = 'LEFT JOIN ' . ForumMessage::model()->tableName() . ' AS `fm` ON `fm`.topic_id=`t`.id';
     $criteria->order = '`fm`.topic_id DESC';
     $criteria->group = '`t`.id';
     $criteria->limit = $limit;
     return new CActiveDataProvider('ForumTopic', array('criteria' => $criteria));
     //return ForumTopic::model()->findAll($criteria);
 }
Ejemplo n.º 5
0
 /**
  *	delete - Delete this message and its followups.
  *
  *	@return	int	The count of deleted messages.
  */
 function delete()
 {
     $msg_id = $this->getID();
     if (!$msg_id) {
         $this->setError(_('Invalid Message ID'));
         return 0;
     }
     if (!$this->Forum->userIsAdmin()) {
         $this->setPermissionDeniedError();
         return false;
     }
     /*$perm =& $this->Forum->Group->getPermission( session_get_user() );
     
     		if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {
     			$this->setPermissionDeniedError();
     			return false;
     		}*/
     $sql = "SELECT msg_id FROM forum \n\t\t\tWHERE is_followup_to='{$msg_id}' \n\t\t\tAND group_forum_id='" . $this->Forum->getID() . "'";
     $result = db_query($sql);
     $rows = db_numrows($result);
     $count = 1;
     for ($i = 0; $i < $rows; $i++) {
         $msg = new ForumMessage($this->Forum, db_result($result, $i, 'msg_id'));
         $count += $msg->delete();
     }
     $sql = "DELETE FROM forum \n\t\t\tWHERE msg_id='{$msg_id}' \n\t\t\tAND group_forum_id='" . $this->Forum->getID() . "'";
     $toss = db_query($sql);
     $sql = "DELETE FROM forum_attachment where msg_id='{$msg_id}'";
     $res = db_query($res);
     return $count;
 }
Ejemplo n.º 6
0
 public function getLastMessage()
 {
     return ForumMessage::model()->findByAttributes(array('topic_id' => $this->id), array('order' => 'id DESC', 'limit' => '1'));
 }
Ejemplo n.º 7
0
<?php

$this->breadcrumbs = [Yii::t('ForumModule.forum', 'Forums') => ['/forum/forumBackend/index'], Yii::t('ForumModule.forum', 'Topics') => ['/forum/messageBackend/index'], Yii::t('ForumModule.forum', 'Manage')];
$this->pageTitle = Yii::t('ForumModule.forum', 'Messages - manage');
$this->menu = Yii::app()->getModule('forum')->getNavigation();
?>
<div class="page-header">
    <h1>
        <?php 
echo Yii::t('ForumModule.forum', 'Messages');
?>
        <small><?php 
echo Yii::t('ForumModule.forum', 'manage');
?>
</small>
    </h1>
</div>

<p><?php 
echo Yii::t('ForumModule.forum', 'This section describes forum management');
?>
</p>

<?php 
$this->widget('yupe\\widgets\\CustomGridView', ['id' => 'forum-message-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => [['name' => 'id', 'htmlOptions' => ['style' => 'width:20px'], 'type' => 'raw', 'value' => 'CHtml::link($data->id, ["/forum/forumBackend/update", "id" => $data->id])', 'filter' => CHtml::activeTextField($model, 'id', ['class' => 'form-control', 'style' => 'width:20px'])], ['name' => 'topic_id', 'value' => '$data->getTopicTitle()', 'filter' => CHtml::activeDropDownList($model, 'topic_id', ForumTopic::model()->getFormattedList(), ['empty' => '', 'class' => 'form-control'])], ['name' => 'user_id', 'value' => '$data->getUserNickname()', 'filter' => CHtml::activeDropDownList($model, 'user_id', ForumMessage::model()->getUserList(), ['empty' => '', 'class' => 'form-control'])], ['name' => 'message', 'type' => 'ntext'], ['name' => 'date', 'htmlOptions' => ['style' => 'width:150px'], 'filter' => false], ['class' => 'bootstrap.widgets.TbButtonColumn']]]);
Ejemplo n.º 8
0
<?php

$this->breadcrumbs = array(Yii::t('ForumModule.forum', 'Forums') => array('/forum/forumBackend/index'), Yii::t('ForumModule.forum', 'Topics') => array('/forum/messageBackend/index'), Yii::t('ForumModule.forum', 'Manage'));
$this->pageTitle = Yii::t('ForumModule.forum', 'Messages - manage');
$this->menu = Yii::app()->getModule('forum')->getNavigation();
?>
    <div class="page-header">
        <h1>
            <?php 
echo Yii::t('ForumModule.forum', 'Messages');
?>
            <small><?php 
echo Yii::t('ForumModule.forum', 'manage');
?>
</small>
        </h1>
    </div>

    <p><?php 
echo Yii::t('ForumModule.forum', 'This section describes forum management');
?>
</p>

<?php 
$this->widget('yupe\\widgets\\CustomGridView', array('id' => 'forum-message-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array(array('name' => 'id', 'htmlOptions' => array('style' => 'width:20px'), 'type' => 'raw', 'value' => 'CHtml::link($data->id, array("/forum/forumBackend/update", "id" => $data->id))'), array('name' => 'topic_id', 'value' => '$data->getTopicTitle()', 'filter' => CHtml::activeDropDownList($model, 'topic_id', ForumTopic::model()->getFormattedList(), array('encode' => false, 'empty' => ''))), array('name' => 'user_id', 'value' => '$data->getUserNickname()', 'filter' => CHtml::activeDropDownList($model, 'user_id', ForumMessage::model()->getUserList(), array('encode' => false, 'empty' => ''))), array('name' => 'message', 'type' => 'ntext'), 'date', array('class' => 'bootstrap.widgets.TbButtonColumn'))));
Ejemplo n.º 9
0
 public function getTopics($limit = -1)
 {
     $criteria = new CDbCriteria();
     $criteria->compare('forum_id', $this->id);
     $criteria->join = 'LEFT JOIN ' . ForumMessage::model()->tableName() . ' AS fm ON fm.topic_id=t.id';
     $criteria->order = 'fm.topic_id DESC';
     $criteria->group = 't.id';
     $criteria->limit = $limit;
     return ForumTopic::model()->findAll($criteria);
 }
Ejemplo n.º 10
0
 /**
  * Insert data into the forum db
  *
  * @return - true or false
  */
 function addMessage()
 {
     //
     //	get user_id
     //
     $user_id = $this->getUserId();
     if ($user_id) {
         //
         //	Set up this user's session before posting
         //
         session_set_new($user_id);
     }
     //DBG( "AddMessage 1\n");
     $Forum =& $this->getForum();
     if (!$Forum || !is_object($Forum)) {
         $this->setError("Could Not Get Forum");
         return false;
     } elseif ($Forum->isError()) {
         $this->setError("Forum Error: " . $Forum->getErrorMessage());
         return false;
     }
     if (!$user_id && !$Forum->AllowAnonymous()) {
         $this->setError("Could Not Match Sender Email Address to User and Forum Does Not Allow Anonymous Posts");
         return false;
     }
     //DBG( "AddMessage 2\n");
     //
     //	Create a blank forum message
     //
     $ForumMessage = new ForumMessage($Forum);
     if (!$ForumMessage || !is_object($Forum)) {
         $this->setError("Could Not Get Forum Message");
         return false;
     } elseif ($ForumMessage->isError()) {
         $this->setError("ForumMessage Error: " . $ForumMessage->getErrorMessage());
         return false;
     }
     //DBG( "AddMessage 3\n");
     if ($this->Message != "") {
         if (!$ForumMessage->create($this->Subject, $this->Message, $this->ThreadId, $this->Parent)) {
             //DBG( "AddMessage 4.".$ForumMessage->getErrorMessage()."\n");
             $this->setError("ForumMessage Create Error: " . $ForumMessage->getErrorMessage());
             return false;
         } else {
             //DBG( "AddMessage 5.".$ForumMessage->getErrorMessage()."\n");
             return true;
         }
     } else {
         return true;
     }
 }
 /**
  * Saves a comment on an item
  *
  * @param ReviewItem $item_to_comment_on
  * @param string $s_body
  * @return ForumMessage
  */
 public function SaveComment(ReviewItem $item_to_comment_on, $s_body)
 {
     $user = AuthenticationManager::GetUser();
     # create new message
     $o_message = new ForumMessage($this->GetSettings(), $user);
     $o_message->SetBody($s_body);
     $o_message->SetReviewItem($item_to_comment_on);
     # add new message to db, either as reply or as new topic
     /* @var $o_result MySQLRawData */
     # Create table aliases
     $s_message = $this->o_settings->GetTable('ForumMessage');
     $s_reg = $this->o_settings->GetTable('User');
     $s_ip = isset($_SERVER['REMOTE_ADDR']) ? $this->SqlString($_SERVER['REMOTE_ADDR']) : 'NULL';
     $s_sql = 'INSERT INTO ' . $s_message . ' SET ' . 'user_id = ' . Sql::ProtectNumeric(AuthenticationManager::GetUser()->GetId()) . ', ' . 'date_added = ' . gmdate('U') . ', ' . 'date_changed = ' . gmdate('U') . ', ' . "message = " . $this->SqlHtmlString($o_message->GetBody()) . ", " . 'ip = ' . $s_ip . ', ' . 'sort_override = 0, ' . 'item_id = ' . Sql::ProtectNumeric($item_to_comment_on->GetId()) . ', ' . "item_type = " . Sql::ProtectNumeric($item_to_comment_on->GetType());
     $this->Lock(array($s_message, $s_reg));
     $o_result = $this->GetDataConnection()->query($s_sql);
     if ($this->GetDataConnection()->isError()) {
         die('Failed to create message.');
     }
     $o_message->SetId($this->GetDataConnection()->insertID());
     # increment personal message count
     $user_id = Sql::ProtectNumeric(AuthenticationManager::GetUser()->GetId());
     $s_sql = "UPDATE nsa_user SET total_messages = (SELECT COUNT(id) FROM nsa_forum_message WHERE user_id = {$user_id}) WHERE user_id = {$user_id}";
     $o_result = $this->GetDataConnection()->query($s_sql);
     if ($this->GetDataConnection()->isError()) {
         die('Failed to update your message count.');
     }
     # release db
     $this->Unlock();
     return $o_message;
 }
Ejemplo n.º 12
0
 /**
  *	create - use this function to create a new entry in the database.
  *
  *	@param	string	The name of the forum.
  *	@param	string	The description of the forum.
  *	@param	int	Pass (1) if it should be public (0) for private.
  *	@param	string	The email address to send all new posts to.
  *	@param	int	Pass (1) if a welcome message should be created (0) for no welcome message.
  *	@param	int	Pass (1) if we should allow non-logged-in users to post (0) for mandatory login.
  *	@param	int Pass (0) if the messages that are posted in the forum should go to moderation before available. 0-> no moderation 1-> moderation for anonymous and non-project members 2-> moderation for everyone
  *	@return	boolean	success.
  */
 function create($forum_name, $description, $is_public = 1, $send_all_posts_to = '', $create_default_message = 1, $allow_anonymous = 1, $moderation_level = 0)
 {
     if (strlen($forum_name) < 3) {
         $this->setError(_('Forum Name Must Be At Least 3 Characters'));
         return false;
     }
     if (strlen($description) < 10) {
         $this->setError(_('Forum Description Must Be At Least 10 Characters'));
         return false;
     }
     if (eregi('[^_\\.0-9a-z-]', $forum_name)) {
         $this->setError(_('Illegal Characters in Forum Name'));
         return false;
     }
     if ($send_all_posts_to) {
         $invalid_mails = validate_emails($send_all_posts_to);
         if (count($invalid_mails) > 0) {
             $this->setInvalidEmailError();
             return false;
         }
     }
     $project_name = $this->Group->getUnixName();
     $result_list_samename = db_query('SELECT 1 FROM mail_group_list WHERE list_name = \'' . $project_name . '-' . $forum_name . '\' AND group_id=' . $this->Group->getID() . '');
     if (db_numrows($result_list_samename) > 0) {
         $this->setError(_('Mailing List Exists with same name'));
         return false;
     }
     // This is a hack to allow non-site-wide-admins to post
     // news.  The news/submit.php checks for proper permissions.
     // This needs to be revisited.
     global $sys_news_group;
     if ($this->Group->getID() == $sys_news_group) {
         // Future check will be added.
     } else {
         // Current permissions check.
         $perm =& $this->Group->getPermission(session_get_user());
         if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {
             $this->setPermissionDeniedError();
             return false;
         }
     }
     $sql = "INSERT INTO forum_group_list (group_id,forum_name,is_public,description,send_all_posts_to,allow_anonymous,moderation_level)\n\t\t\tVALUES ('" . $this->Group->getId() . "',\n\t\t\t'" . strtolower($forum_name) . "',\n\t\t\t'{$is_public}',\n\t\t\t'" . htmlspecialchars($description) . "',\n\t\t\t'{$send_all_posts_to}',\n\t\t\t'{$allow_anonymous}','{$moderation_level}')";
     db_begin();
     $result = db_query($sql);
     if (!$result) {
         db_rollback();
         $this->setError(_('Error Adding Forum') . db_error());
         return false;
     }
     $this->group_forum_id = db_insertid($result, 'forum_group_list', 'group_forum_id');
     $this->fetchData($this->group_forum_id);
     if ($create_default_message) {
         $fm = new ForumMessage($this);
         if (!$fm->create("Welcome to " . $forum_name, "Welcome to " . $forum_name)) {
             $this->setError($fm->getErrorMessage());
             return false;
         }
     }
     db_commit();
     return true;
 }