Ejemplo n.º 1
0
 public function display($tpl = null)
 {
     // @rule: Test for user access if on 1.6 and above
     if (DiscussHelper::getJoomlaVersion() >= '1.6') {
         if (!JFactory::getUser()->authorise('discuss.manage.post_types', 'com_easydiscuss')) {
             JFactory::getApplication()->redirect('index.php', JText::_('JERROR_ALERTNOAUTHOR'), 'error');
             JFactory::getApplication()->close();
         }
     }
     // Initialise variables
     $document = JFactory::getDocument();
     $user = JFactory::getUser();
     $mainframe = JFactory::getApplication();
     // REMOVE THIS COMMENT LATER: Don't ever use $this->getModel because it will conflict with K2
     $model = DiscussHelper::getModel('Post_Types', true);
     $postTypes = $model->getTypes();
     $pagination = $this->get('Pagination');
     $filter_state = $mainframe->getUserStateFromRequest('com_easydiscuss.post_types.filter_state', 'filter_state', '*', 'word');
     $order = $mainframe->getUserStateFromRequest('com_easydiscuss.post_types.filter_order', 'filter_order', 'id', 'cmd');
     $orderDirection = $mainframe->getUserStateFromRequest('com_easydiscuss.post_types.filter_order_Dir', 'filter_order_Dir', '', 'word');
     $browse = JRequest::getInt('browse', 0);
     $browseFunction = JRequest::getVar('browseFunction', '');
     $search = $mainframe->getUserStateFromRequest('com_easydiscuss.post_types.search', 'search', '', 'string');
     $search = trim(JString::strtolower($search));
     $this->assign('browseFunction', $browseFunction);
     $this->assign('browse', $browse);
     $this->assign('search', $search);
     $this->assign('postTypes', $postTypes);
     $this->assign('state', $this->getFilterState($filter_state));
     $this->assign('order', $order);
     $this->assign('orderDirection', $orderDirection);
     $this->assign('pagination', $pagination);
     parent::display($tpl);
 }
Ejemplo n.º 2
0
 public function save()
 {
     JRequest::checkToken('request') or jexit('Invalid Token');
     $mainframe = JFactory::getApplication();
     $post = JRequest::get('post');
     $ids = isset($post['id']) ? $post['id'] : '';
     $starts = isset($post['start']) ? $post['start'] : '';
     $ends = isset($post['end']) ? $post['end'] : '';
     $titles = isset($post['title']) ? $post['title'] : '';
     $removal = isset($post['itemRemove']) ? $post['itemRemove'] : '';
     $model = DiscussHelper::getModel('Ranks', true);
     if (!empty($removal)) {
         $rids = explode(',', $removal);
         $model->removeRanks($rids);
     }
     if (!empty($ids)) {
         if (count($ids) > 0) {
             for ($i = 0; $i < count($ids); $i++) {
                 $data = array();
                 $data['id'] = $ids[$i];
                 $data['start'] = $starts[$i];
                 $data['end'] = $ends[$i];
                 $data['title'] = $titles[$i];
                 $ranks = DiscussHelper::getTable('Ranks');
                 $ranks->bind($data);
                 $ranks->store();
             }
         }
         //end if
     }
     //end if
     $message = JText::_('COM_EASYDISCUSS_RANKING_SUCCESSFULLY_UPDATED');
     DiscussHelper::setMessageQueue($message, DISCUSS_QUEUE_SUCCESS);
     $mainframe->redirect('index.php?option=com_easydiscuss&view=ranks');
 }
Ejemplo n.º 3
0
 /**
  * Displays the user's points achievement history
  *
  * @since	2.0
  * @access	public
  */
 public function history($tmpl = null)
 {
     $app = JFactory::getApplication();
     $id = JRequest::getInt('id');
     if (!$id) {
         DiscussHelper::setMessageQueue(JText::_('Unable to locate the id of the user.'), DISCUSS_QUEUE_ERROR);
         $app->redirect('index.php?option=com_easydiscuss');
         $app->close();
     }
     $model = DiscussHelper::getModel('Points', true);
     $history = $model->getPointsHistory($id);
     foreach ($history as $item) {
         $date = DiscussDateHelper::dateWithOffSet($item->created);
         $item->created = $date->toFormat('%A, %b %e %Y');
         $points = DiscussHelper::getHelper('Points')->getPoints($item->command);
         if ($points) {
             if ($points[0]->rule_limit < 0) {
                 $item->class = 'badge-important';
                 $item->points = $points[0]->rule_limit;
             } else {
                 $item->class = 'badge-info';
                 $item->points = '+' . $points[0]->rule_limit;
             }
         } else {
             $item->class = 'badge-info';
             $item->points = '+';
         }
     }
     $theme = new DiscussThemes();
     $theme->set('history', $history);
     echo $theme->fetch('points.history.php');
 }
Ejemplo n.º 4
0
 public function parseEmails()
 {
     require_once DISCUSS_CLASSES . '/mailbox.php';
     $config = DiscussHelper::getConfig();
     // Default email parser
     $mailer = new DiscussMailer();
     $state = $mailer->connect($config->get('main_email_parser_username'), $config->get('main_email_parser_password'));
     if ($state) {
         self::processEmails($mailer);
     }
     // Category email parser
     $model = DiscussHelper::getModel('Categories', true);
     $cats = $model->getAllCategories();
     if (is_array($cats)) {
         foreach ($cats as $cat) {
             $category = DiscussHelper::getTable('Category');
             $category->load($cat->id);
             $enable = explode(',', $category->getParam('cat_email_parser_switch'));
             if ($enable[0]) {
                 $catMail = explode(',', $category->getParam('cat_email_parser'));
                 $catPass = explode(',', $category->getParam('cat_email_parser_password'));
                 $mailer = new DiscussMailer();
                 $state = $mailer->connect($catMail[0], $catPass[0]);
                 if ($state) {
                     self::processEmails($mailer, $category);
                 }
             }
         }
     }
     return true;
 }
Ejemplo n.º 5
0
    protected function getInput()
    {
        $model = DiscussHelper::getModel('Categories', true);
        $categories = $model->getAllCategories();
        $multiple = $this->element['multipleitems'];
        if (!is_array($this->value)) {
            $this->value = array($this->value);
        }
        ob_start();
        ?>
		<select name="<?php 
        echo $this->name;
        echo $multiple ? '[]' : '';
        ?>
" id="<?php 
        echo $this->name;
        ?>
"<?php 
        echo $multiple == 'true' ? ' multiple="multiple"' : '';
        ?>
>
			<?php 
        if ($categories) {
            ?>
	
				<?php 
            foreach ($categories as $category) {
                ?>
				<option value="<?php 
                echo $category->id;
                ?>
"<?php 
                echo in_array($category->id, $this->value) ? ' selected="selected"' : '';
                ?>
><?php 
                echo JText::_($category->title);
                ?>
</option>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
		</select>
		<?php 
        $html = ob_get_contents();
        ob_end_clean();
        return $html;
    }
Ejemplo n.º 6
0
 public static function getTagCloud($params)
 {
     $mainframe = JFactory::getApplication();
     $order = $params->get('order', 'postcount');
     $sort = $params->get('sort', 'desc');
     $count = (int) trim($params->get('count', 0));
     $shuffeTags = $params->get('shuffleTags', TRUE);
     $pMinSize = $params->get('minsize', '10');
     $pMaxSize = $params->get('maxsize', '30');
     // 		if( !class_exists( 'EasyDiscussModelTags' ) )
     // 		{
     // 			jimport( 'joomla.application.component.model' );
     // 			JLoader::import( 'tags' , DISCUSS_MODELS );
     // 		}
     // 		$model		= JModel::getInstance( 'Tags' , 'EasyDiscussModel' );
     $model = DiscussHelper::getModel('Tags');
     $tagCloud = $model->getTagCloud($count, $order, $sort);
     $extraInfo = array();
     if ($shuffeTags) {
         shuffle($tagCloud);
     }
     foreach ($tagCloud as $item) {
         $extraInfo[] = $item->post_count;
     }
     $min_size = $pMinSize;
     $max_size = $pMaxSize;
     //$tags = tag_info();
     $minimum_count = 0;
     $maximum_count = 0;
     if (!empty($extraInfo)) {
         $minimum_count = min($extraInfo);
         $maximum_count = max($extraInfo);
     }
     $spread = $maximum_count - $minimum_count;
     if ($spread == 0) {
         $spread = 1;
     }
     $cloud_html = '';
     $cloud_tags = array();
     //foreach ($tags as $tag => $count)
     for ($i = 0; $i < count($tagCloud); $i++) {
         $row =& $tagCloud[$i];
         $size = $min_size + ($row->post_count - $minimum_count) * ($max_size - $min_size) / $spread;
         $row->fontsize = $size;
     }
     return $tagCloud;
 }
Ejemplo n.º 7
0
 function display($tpl = null)
 {
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     if (!$config->get('main_favorite')) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_FEATURE_IS_DISABLED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss', false));
         $app->close();
     }
     DiscussHelper::setPageTitle(JText::_('COM_EASYDISCUSS_FAVOURITES_TITLE'));
     // @task: Add view
     $this->logView();
     DiscussHelper::setMeta();
     $postModel = DiscussHelper::getModel('Posts');
     $posts = $postModel->getData(true, 'latest', null, 'favourites');
     $posts = DiscussHelper::formatPost($posts);
     $theme = new DiscussThemes();
     $theme->set('posts', $posts);
     echo $theme->fetch('favourites.php');
 }
Ejemplo n.º 8
0
									</a>
									<?php 
                }
                ?>
								<?php 
            } else {
                ?>
									<?php 
                echo $post->reply->poster_name;
                ?>
								<?php 
            }
            ?>

								<?php 
            $lastReply = DiscussHelper::getModel('Posts')->getLastReply($post->id);
            ?>
								<a class="ml-5" href="<?php 
            echo DiscussRouter::getPostRoute($post->id) . '#' . JText::_('MOD_EASYDISCUSS_REPLY_PERMALINK') . '-' . $lastReply->id;
            ?>
" title="<?php 
            echo JText::_('MOD_EASYDISCUSS_VIEW_LAST_REPLY');
            ?>
"><?php 
            echo JText::_('MOD_EASYDISCUSS_VIEW_LAST_REPLY');
            ?>
</a>

							<?php 
        }
        ?>
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
$path = JPATH_ROOT . '/components/com_easydiscuss/helpers/helper.php';
jimport('joomla.filesystem.file');
if (!JFile::exists($path)) {
    return;
}
require_once $path;
// require_once (dirname(__FILE__) . '/helper.php');
DiscussHelper::loadStylesheet("module", "mod_easydiscuss_your_discussions");
$my = JFactory::getUser();
$config = DiscussHelper::getConfig();
$profile = DiscussHelper::getTable('Profile');
$profile->load($my->id);
$postsModel = DiscussHelper::getModel('Posts');
$count = $params->get('count', 5);
$posts = array();
$posts = $postsModel->getPostsBy('user', $profile->id, 'latest', '0', '', '', $count);
$posts = DiscussHelper::formatPost($posts);
if (!empty($posts)) {
    $posts = Discusshelper::getPostStatusAndTypes($posts);
    // foreach( $posts as $post )
    // {
    // 	// Translate post status from integer to string
    // 	switch( $post->post_status )
    // 	{
    // 		case '0':
    // 			$post->post_status = '';
    // 			break;
    // 		case '1':
Ejemplo n.º 10
0
 /**
  * Processes ajax request when a user likes an item.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function like()
 {
     $my = JFactory::getUser();
     $ajax = DiscussHelper::getHelper('ajax');
     $config = DiscussHelper::getConfig();
     // Get the post.
     $postId = JRequest::getInt('postid');
     $post = DiscussHelper::getTable('Post');
     $post->load($postId);
     // Determine if the likes are enabled or not.
     if ($post->isReply() && !$config->get('main_likes_replies') || $post->isQuestion() && !$config->get('main_likes_discussions')) {
         return $ajax->reject();
     }
     // Do not allow non logged in users to like an item.
     if (!$my->id) {
         return $ajax->reject();
     }
     // Determine if the current user request is to like the post item or unlike.
     $isLike = !$post->isLikedBy($my->id);
     if ($isLike) {
         DiscussHelper::getHelper('Likes')->addLikes($post->id, 'post', $my->id);
     } else {
         // If this is an unlike request, we need to remove it.
         DiscussHelper::getHelper('Likes')->removeLikes($post->id, $my->id);
     }
     // Get the main question if this is a reply.
     if ($post->isReply()) {
         $question = DiscussHelper::getTable('Post');
         $question->load($post->parent_id);
     } else {
         $question = $post;
     }
     // Add JomSocial activity item if the post for the main discussion item if it has been liked.
     if ($post->published && $isLike) {
         // EasySocial instegrations
         DiscussHelper::getHelper('EasySocial')->notify('new.likes', $post, $question);
         DiscussHelper::getHelper('jomsocial')->addActivityLikes($post, $question);
         DiscussHelper::getHelper('easysocial')->likesStream($post, $question);
     }
     // Add a badge record for the user when they like a discussion
     // The record should only be added when the user liked another user's post.
     if ($post->isQuestion() && $isLike && $my->id != $post->user_id) {
         // Add logging for user.
         DiscussHelper::getHelper('History')->log('easydiscuss.like.discussion', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_DISCUSSION', $question->title), $post->id);
         DiscussHelper::getHelper('Badges')->assign('easydiscuss.like.discussion', $my->id);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.like.discussion', $my->id);
         // Assign badge for EasySocial
         DiscussHelper::getHelper('EasySocial')->assignBadge('like.question', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_DISCUSSION', $question->title));
     }
     // Add a badge record for the user when they like a discussion
     // The record should only be added when the user liked another user's post.
     if ($post->isReply() && $isLike && $my->id != $post->user_id) {
         // Add logging for user.
         DiscussHelper::getHelper('History')->log('easydiscuss.like.reply', $my->id, JText::sprintf('COM_EASYDISCUSS_BADGES_HISTORY_LIKE_REPLY', $post->title), $post->id);
         DiscussHelper::getHelper('Badges')->assign('easydiscuss.like.reply', $my->id);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.like.reply', $my->id);
     }
     // Remove history when a user unlikes a discussion.
     if ($post->isQuestion() && !$isLike && $my->id != $post->user_id) {
         // Remove unlike
         DiscussHelper::getHelper('History')->removeLog('easydiscuss.like.discussion', $my->id, $post->id);
         DiscussHelper::getHelper('Badges')->assign('easydiscuss.unlike.discussion', $my->id);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.unlike.discussion', $my->id);
     }
     // Remove history when a user unlikes a reply.
     if ($post->isReply() && !$isLike && $my->id != $post->user_id) {
         // Remove unlike
         DiscussHelper::getHelper('History')->removeLog('easydiscuss.like.reply', $my->id, $post->id);
         DiscussHelper::getHelper('Badges')->assign('easydiscuss.unlike.reply', $my->id);
         DiscussHelper::getHelper('Points')->assign('easydiscuss.unlike.reply', $my->id);
     }
     // Add notifications to the post owner.
     if ($post->user_id != $my->id) {
         $notification = DiscussHelper::getTable('Notifications');
         $text = $post->isQuestion() ? 'COM_EASYDISCUSS_LIKE_DISCUSSION_NOTIFICATION_TITLE' : 'COM_EASYDISCUSS_LIKE_REPLY_NOTIFICATION_TITLE';
         $title = $question->title;
         $likeType = $post->isQuestion() ? DISCUSS_NOTIFICATIONS_LIKES_DISCUSSION : DISCUSS_NOTIFICATIONS_LIKES_REPLIES;
         $notification->bind(array('title' => JText::sprintf($text, $title), 'cid' => $question->id, 'type' => $likeType, 'target' => $post->user_id, 'author' => $my->id, 'permalink' => 'index.php?option=com_easydiscuss&view=post&id=' . $question->id));
         $notification->store();
     }
     // Only send notification email if the post owner is a registered user.
     // And, it would not send email if the user that is liking on his own item.
     if ($post->user_id && $my->id != $post->user_id && $isLike && $config->get('notify_owner_like')) {
         // Send email to post / reply author that someone liked their post.
         $notify = DiscussHelper::getNotification();
         $profile = DiscussHelper::getTable('Profile');
         $profile->load($my->id);
         $emailSubject = JText::sprintf('COM_EASYDISCUSS_USER_LIKED_YOUR_POST', $profile->getName());
         $emailTemplate = 'email.like.post.php';
         $emailData = array();
         $emailData['authorName'] = $profile->getName();
         $emailData['authorAvatar'] = $profile->getAvatar();
         $emailData['replyContent'] = $post->content;
         $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $question->id, false, true);
         $recipient = JFactory::getUser($post->user_id);
         $notify->addQueue($recipient->email, $emailSubject, '', $emailTemplate, $emailData);
     }
     // Get the like's text.
     $likeText = DiscussHelper::getHelper('Likes')->getLikesHTML($post->id, $my->id, 'post');
     if (!$likeText) {
         $likeText = JText::_('COM_EASYDISCUSS_BE_THE_FIRST_TO_LIKE');
     }
     $count = DiscussHelper::getModel('Likes')->getTotalLikes($postId);
     $ajax->resolve($likeText, $count);
     return $ajax->send();
 }
Ejemplo n.º 11
0
 function removeBadges($userId)
 {
     $model = DiscussHelper::getModel('Badges');
     $state = $model->removeBadges($userId);
     if ($state == false) {
         JError::raiseError(500, $db->stderr());
     }
 }
Ejemplo n.º 12
0
require_once $path;
// Load theme css here.
DiscussHelper::loadStylesheet("module", "mod_easydiscuss_navigation");
DiscussHelper::loadHeaders();
// Load component's language file.
JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT);
JFactory::getLanguage()->load('mod_easydiscuss_navigation', JPATH_ROOT);
$my = JFactory::getUser();
// We need to detect if the user is browsing a particular category
$active = '';
$view = JRequest::getVar('view');
$layout = JRequest::getVar('layout');
$option = JRequest::getVar('option');
$id = JRequest::getInt('category_id');
if ($option == 'com_easydiscuss' && $view == 'post') {
    $postId = JRequest::getInt('id', 0);
    // update user's post read flag
    if (!empty($my->id) && !empty($postId)) {
        $profile = DiscussHelper::getTable('Profile');
        $profile->load($my->id);
        $profile->read($postId);
    }
}
$model = DiscussHelper::getModel('Categories');
$categories = $model->getCategoryTree();
$notificationModel = DiscussHelper::getModel('Notification');
$totalNotifications = $notificationModel->getTotalNotifications($my->id);
if ($option == 'com_easydiscuss' && $view == 'categories' && $layout == 'listings' && $id) {
    $active = $id;
}
require JModuleHelper::getLayoutPath('mod_easydiscuss_navigation');
Ejemplo n.º 13
0
 /**
  * Merges the current discussion into an existing discussion
  *
  * @since   1.0
  * @access  public
  * @param   string
  * @return
  */
 public function mergeForm($id)
 {
     $ajax = new Disjax();
     $model = DiscussHelper::getModel('Posts');
     $posts = $model->getDiscussions(array('limit' => DISCUSS_NO_LIMIT, 'exclude' => array($id)));
     $theme = new DiscussThemes();
     $theme->set('posts', $posts);
     $theme->set('current', $id);
     $content = $theme->fetch('ajax.post.merge.php', array('dialog' => true));
     $options = new stdClass();
     $options->content = $content;
     $options->title = JText::_('COM_EASYDISCUSS_MERGE_POST_TITLE');
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $buttons[] = $button;
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_MERGE');
     $button->form = '#frmMergePost';
     $button->className = 'btn-primary';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $ajax->dialog($options);
     $ajax->send();
 }
Ejemplo n.º 14
0
 * See COPYRIGHT.php for copyright notices and details.
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
$my = JFactory::getUser();
$stringHelper = DiscussHelper::getHelper('String');
$system = new stdClass();
$system->config = DiscussHelper::getConfig();
$system->my = JFactory::getUser();
$system->profile = DiscussHelper::getTable('Profile');
$system->profile->load($system->my->id);
// $profileModel 	= DiscussHelper::getTable( 'Profile' );
// $profile 		= $profileModel->load( $my->id );
if (!empty($my->id)) {
    $notificationModel = DiscussHelper::getModel('Notification');
    $conversationModel = DiscussHelper::getModel('Conversation');
    if (!empty($notificationModel)) {
        $notifications = $notificationModel->getTotalNotifications($my->id);
    }
    if (!empty($conversationModel)) {
        $totalMessages = $conversationModel->getCount($my->id, array('filter' => 'unread'));
    }
}
?>

<script type="text/javascript">
EasyDiscuss
.require()
.script( 'toolbar' )
.done(function($){
Ejemplo n.º 15
0
 /**
  * Displays the user's profile.
  *
  * @since	2.0
  * @access	public
  */
 function display($tmpl = null)
 {
     $doc = JFactory::getDocument();
     $app = JFactory::getApplication();
     $id = JRequest::getInt('id', null);
     $my = JFactory::getUser($id);
     $config = DiscussHelper::getConfig();
     // Custom parameters.
     $sort = JRequest::getString('sort', 'latest');
     $filteractive = JRequest::getString('filter', 'allposts');
     $viewType = JRequest::getString('viewtype', 'questions');
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     // If profile is invalid, throw an error.
     if (!$profile->id) {
         // Show login form.
         $theme = new DiscussThemes();
         $theme->set('redirect', DiscussRouter::_('index.php?option=com_easydiscuss&view=profile', false));
         echo $theme->fetch('login.form.php');
         return;
     }
     $params = DiscussHelper::getRegistry($profile->params);
     $fields = array('facebook', 'linkedin', 'twitter', 'website');
     foreach ($fields as $site) {
         if ($params->get($site, '') != '') {
             if ($site == 'facebook' || $site == 'linkedin' || $site == 'twitter') {
                 $name = $params->get($site);
                 $url = 'www.' . $site . '.com/' . $name;
                 $params->set($site, DiscussUrlHelper::clean($url));
             }
             if ($site == 'website') {
                 $url = $params->get($site);
                 $params->set($site, DiscussUrlHelper::clean($url));
             }
         }
     }
     // Set the title for the page.
     DiscussHelper::setPageTitle(JText::sprintf('COM_EASYDISCUSS_PROFILE_PAGE_TITLE', $profile->getName()));
     // Set the pathway
     $this->setPathway(JText::_($profile->getName()));
     $postsModel = DiscussHelper::getModel('Posts');
     $tagsModel = DiscussHelper::getModel('Tags');
     $posts = array();
     $replies = array();
     $tagCloud = array();
     $badges = array();
     $unresolved = array();
     $pagination = null;
     $filterArr = array();
     $filterArr['viewtype'] = $viewType;
     $filterArr['id'] = $profile->id;
     switch ($viewType) {
         case 'replies':
             $replies = $postsModel->getRepliesFromUser($profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $replies = DiscussHelper::formatPost($replies);
             break;
         case 'unresolved':
             $unresolved = $postsModel->getUnresolvedFromUser($profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $unresolved = DiscussHelper::formatPost($unresolved);
             break;
         case 'questions':
         default:
             $posts = $postsModel->getPostsBy('user', $profile->id);
             $pagination = $postsModel->getPagination();
             $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
             $posts = DiscussHelper::formatPost($posts);
             break;
     }
     // Get user badges
     $badges = $profile->getBadges();
     // @rule: Clear up any notifications that are visible for the user.
     $notifications = DiscussHelper::getModel('Notification');
     $notifications->markRead($profile->id, false, array(DISCUSS_NOTIFICATIONS_PROFILE, DISCUSS_NOTIFICATIONS_BADGE));
     $tpl = new DiscussThemes();
     // EasyBlog integrations
     $easyblogExists = $this->easyblogExists();
     $blogCount = 0;
     if ($easyblogExists && $config->get('integrations_easyblog_profile')) {
         $blogModel = EasyBlogHelper::getModel('Blog');
         $blogCount = $blogModel->getBlogPostsCount($profile->id, false);
     }
     $komentoExists = $this->komentoExists();
     $commentCount = 0;
     if ($komentoExists && $config->get('integrations_komento_profile')) {
         $commentsModel = Komento::getModel('comments');
         $commentCount = $commentsModel->getTotalComment($profile->id);
     }
     $posts = Discusshelper::getPostStatusAndTypes($posts);
     $favPosts = $postsModel->getData('true', 'latest', 'null', 'favourites');
     $favPosts = DiscussHelper::formatPost($favPosts);
     $tpl->set('sort', $sort);
     $tpl->set('filter', $filteractive);
     $tpl->set('tagCloud', $tagCloud);
     $tpl->set('paginationType', DISCUSS_USERQUESTIONS_TYPE);
     $tpl->set('parent_id', $profile->id);
     $tpl->set('pagination', $pagination);
     $tpl->set('posts', $posts);
     $tpl->set('badges', $badges);
     $tpl->set('favPosts', $favPosts);
     $tpl->set('profile', $profile);
     $tpl->set('replies', $replies);
     $tpl->set('unresolved', $unresolved);
     $tpl->set('params', $params);
     $tpl->set('viewType', $viewType);
     $tpl->set('easyblogExists', $easyblogExists);
     $tpl->set('komentoExists', $komentoExists);
     $tpl->set('blogCount', $blogCount);
     $tpl->set('commentCount', $commentCount);
     $filterArr = array();
     $filterArr['filter'] = $filteractive;
     $filterArr['id'] = $profile->id;
     $filterArr['sort'] = $sort;
     $filterArr['viewtype'] = $viewType;
     $tpl->set('filterArr', $filterArr);
     $tpl->set('page', 'profile');
     echo $tpl->fetch('profile.php');
 }
Ejemplo n.º 16
0
 public function getFields()
 {
     // select top 20 tags.
     $tagmodel = DiscussHelper::getModel('Tags');
     $tags = $tagmodel->getTagCloud('', 'post_count', 'DESC');
     $theme = new DiscussThemes();
     $theme->set('tags', $tags);
     $theme->set('composer', $this);
     $theme->set('post', $this->post);
     $theme->set('parent', $this->parent);
     $theme->set('isDiscussion', $this->isDiscussion);
     $theme->set('renderMode', $this->renderMode);
     return $theme->fetch('form.tabs.php');
 }
Ejemplo n.º 17
0
 public function tab()
 {
     // always reset the limitstart.
     JRequest::setVar('limitstart', 0);
     $type = JRequest::getVar('type');
     $profileId = JRequest::getVar('id');
     $ajax = DiscussHelper::getHelper('ajax');
     $model = DiscussHelper::getModel('Posts');
     $tagsModel = DiscussHelper::getModel('Tags');
     $config = DiscussHelper::getConfig();
     $template = new DiscussThemes();
     $html = '';
     $pagination = null;
     switch ($type) {
         case 'tags':
             $tags = $tagsModel->getTagCloud('', '', '', $profileId);
             $template->set('tags', $tags);
             $html = $template->fetch('profile.tags.php');
             break;
         case 'questions':
             $posts = $model->getPostsBy('user', $profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $template->set('posts', $posts);
             $html = $template->fetch('profile.questions.php');
             break;
         case 'unresolved':
             $posts = $model->getUnresolvedFromUser($profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.unresolved.php');
             break;
         case 'favourites':
             if (!$config->get('main_favorite')) {
                 return false;
             }
             $posts = $model->getData(true, 'latest', null, 'favourites', '', null, 'all', $profileId);
             $posts = DiscussHelper::formatPost($posts);
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.favourites.php');
             break;
         case 'replies':
             $posts = $model->getRepliesFromUser($profileId);
             $posts = DiscussHelper::formatPost($posts);
             $pagination = $model->getPagination();
             $posts = Discusshelper::getPostStatusAndTypes($posts);
             $template->set('posts', $posts);
             $html = $template->fetch('profile.replies.php');
             break;
         case 'tabEasyBlog':
             $helperFile = JPATH_ROOT . '/components/com_easyblog/helpers/helper.php';
             if (!JFile::exists($helperFile)) {
                 $html = JText::_('COM_EASYDISCUSS_EASYBLOG_DOES_NOT_EXIST');
             } else {
                 require_once $helperFile;
                 require_once JPATH_ROOT . '/components/com_easyblog/router.php';
                 $blogModel = EasyBlogHelper::getModel('Blog');
                 $blogs = $blogModel->getBlogsBy('blogger', $profileId);
                 $blogs = EasyBlogHelper::formatBlog($blogs);
                 $ebConfig = EasyBlogHelper::getConfig();
                 $user = JFactory::getUser($profileId);
                 $template->set('user', $user);
                 $template->set('ebConfig', $ebConfig);
                 $template->set('blogs', $blogs);
                 // Load EasyBlog's language file
                 JFactory::getLanguage()->load('com_easyblog', JPATH_ROOT);
                 $html = $template->fetch('profile.blogs.php');
             }
             break;
         case 'tabKomento':
             $helperFile = JPATH_ROOT . '/components/com_komento/helpers/helper.php';
             if (!JFile::exists($helperFile)) {
                 $html = JText::_('COM_EASYDISCUSS_KOMENTO_DOES_NOT_EXIST');
             } else {
                 require_once $helperFile;
                 $commentsModel = Komento::getModel('comments');
                 $commentHelper = Komento::getHelper('comment');
                 $options = array('sort' => 'latest', 'userid' => $profileId, 'threaded' => 0);
                 $comments = $commentsModel->getComments('all', 'all', $options);
                 foreach ($comments as &$comment) {
                     $comment = $commentHelper->process($comment);
                 }
                 $feedUrl = Komento::getHelper('router')->getFeedUrl('all', 'all', $profileId);
                 JFactory::getLanguage()->load('com_komento', JPATH_ROOT);
                 $template->set('feedUrl', $feedUrl);
                 $template->set('comments', $comments);
                 $html = $template->fetch('profile.comments.php');
             }
             break;
         case 'subscriptions':
             $subModel = DiscussHelper::getModel('subscribe');
             $rows = $subModel->getSubscriptions();
             $subs = array();
             if ($rows) {
                 foreach ($rows as $row) {
                     $obj = new stdClass();
                     $obj->id = $row->id;
                     $obj->type = $row->type;
                     $obj->unsublink = Discusshelper::getUnsubscribeLink($row, false);
                     switch ($row->type) {
                         case 'site':
                             $obj->title = '';
                             $obj->link = '';
                             break;
                         case 'post':
                             $post = DiscussHelper::getTable('Post');
                             $post->load($row->cid);
                             $obj->title = $post->title;
                             $obj->link = DiscussRouter::_('index.php?option=com_easydiscuss&view=post&id=' . $post->id);
                             break;
                         case 'category':
                             $category = DiscussHelper::getTable('Category');
                             $category->load($row->cid);
                             $obj->title = $category->title;
                             $obj->link = DiscussRouter::getCategoryRoute($category->id);
                             break;
                         case 'user':
                             $profile = DiscussHelper::getTable('Profile');
                             $profile->load($row->cid);
                             $obj->title = $profile->getName();
                             $obj->link = $profile->getLink();
                             break;
                         default:
                             unset($obj);
                             break;
                     }
                     if (!empty($obj)) {
                         $obj->title = DiscussStringHelper::escape($obj->title);
                         $subs[$row->type][] = $obj;
                         unset($obj);
                     }
                 }
             }
             $template->set('subscriptions', $subs);
             $html = $template->fetch('profile.subscriptions.php');
             break;
         default:
             break;
     }
     if ($pagination) {
         $filterArr = array();
         $filterArr['viewtype'] = $type;
         $filterArr['id'] = $profileId;
         $pagination = $pagination->getPagesLinks('profile', $filterArr, true);
     }
     $ajax->success($html, $pagination);
     $ajax->send();
 }
Ejemplo n.º 18
0
 public function getNewCount($filter = '', $category = '', $tagId = '', $featuredOnly = 'all')
 {
     $db = DiscussHelper::getDBO();
     $my = JFactory::getUser();
     $queryExclude = '';
     $excludeCats = array();
     // get all private categories id
     $excludeCats = DiscussHelper::getPrivateCategories();
     if (!empty($excludeCats)) {
         $queryExclude .= ' AND a.`category_id` NOT IN (' . implode(',', $excludeCats) . ')';
     }
     $query = 'SELECT COUNT(a.`id`) FROM `#__discuss_posts` AS a';
     if (!empty($tagId)) {
         $query .= ' INNER JOIN `#__discuss_posts_tags` as c';
         $query .= '	ON a.`id` = c.`post_id`';
         $query .= '	AND c.`tag_id` = ' . $db->Quote($tagId);
     }
     $query .= ' WHERE a.`parent_id` = ' . $db->Quote('0');
     $query .= ' AND a.`published`=' . $db->Quote('1');
     if ($featuredOnly === true) {
         $query .= ' AND a.`featured`=' . $db->Quote('1');
     } else {
         if ($featuredOnly === false) {
             $query .= ' AND a.`featured`=' . $db->Quote('0');
         }
     }
     $config = DiscussHelper::getConfig();
     $query .= ' AND DATEDIFF( ' . $db->Quote(DiscussHelper::getDate()->toMySQL()) . ', a.`created`) <= ' . $db->Quote($config->get('layout_daystostaynew'));
     if ($category) {
         $model = DiscussHelper::getModel('Categories');
         $childs = $model->getChildIds($category);
         $childs[] = $category;
         $query .= ' AND a.`category_id` IN (' . implode(',', $childs) . ')';
     }
     // $query	.= ' AND b.`id` IS NULL';
     $query .= $queryExclude;
     $db->setQuery($query);
     return $db->loadResult();
 }
Ejemplo n.º 19
0
 /**
  * Notify the user when a new conversation is started or replied.
  *
  * @since	3.0
  * @access	public
  * @param	DiscussConversationMessage	The message object that is formatted
  *
  */
 public function notify(DiscussConversationMessage $message)
 {
     $author = DiscussHelper::getTable('Profile');
     $author->load($message->created_by);
     $model = DiscussHelper::getModel('Conversation');
     $result = $model->getParticipants($this->id, $message->created_by);
     $recipient = DiscussHelper::getTable('Profile');
     $recipient->load($result[0]);
     $emailData = array();
     $emailData['conversationLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=conversation&layout=read&id=' . $this->id, false, true);
     $emailData['authorName'] = $author->getName();
     $emailData['authorAvatar'] = $author->getAvatar();
     $emailData['content'] = $message->message;
     $subject = JText::sprintf('COM_EASYDISCUSS_CONVERSATION_EMAIL_SUBJECT', $author->getName());
     $notification = DiscussHelper::getNotification();
     $notification->addQueue($recipient->user->email, $subject, '', 'email.conversation.reply.php', $emailData);
 }
Ejemplo n.º 20
0
 /**
  * Filters discussion based on a given filter
  *
  * @since	3.2
  * @access	public
  * @param	string
  * @return	
  */
 public function filter()
 {
     $filterType = JRequest::getVar('filter');
     $sort = JRequest::getVar('sort', 'latest');
     $categoryId = JRequest::getVar('id', '0');
     if (!$categoryId) {
         $categoryId = array();
     } else {
         $categoryId = explode(',', $categoryId);
     }
     $view = JRequest::getVar('view', 'index');
     $ajax = DiscussHelper::getHelper('ajax');
     JRequest::setVar('filter', $filterType);
     $postModel = DiscussHelper::getModel('Posts');
     $registry = DiscussHelper::getRegistry();
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Get normal discussion posts.
     $options = array('sort' => $sort, 'category' => $categoryId, 'filter' => $filterType, 'limit' => $limit, 'featured' => false);
     $posts = $postModel->getDiscussions($options);
     //$posts		= $postModel->getData( false , $sort , null , $filterType , $categoryId, null, '');
     $posts = DiscussHelper::formatPost($posts);
     $pagination = '';
     $pagination = $postModel->getPagination(0, $sort, $filterType, $categoryId, false);
     $filtering = array('category_id' => $categoryId, 'filter' => $filterType, 'sort' => $sort);
     $pagination = $pagination->getPagesLinks($view, $filtering, true);
     $html = '';
     $empty = '';
     if (count($posts) > 0) {
         $template = new DiscussThemes();
         $badgesTable = DiscussHelper::getTable('Profile');
         $onlineUsers = Discusshelper::getModel('Users')->getOnlineUsers();
         foreach ($posts as $post) {
             $badgesTable->load($post->user->id);
             $post->badges = $badgesTable->getBadges();
             // Translate post status from integer to string
             switch ($post->post_status) {
                 case '0':
                     $post->post_status_class = '';
                     $post->post_status = '';
                     break;
                 case '1':
                     $post->post_status_class = '-on-hold';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ON_HOLD');
                     break;
                 case '2':
                     $post->post_status_class = '-accept';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ACCEPTED');
                     break;
                 case '3':
                     $post->post_status_class = '-working-on';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_WORKING_ON');
                     break;
                 case '4':
                     $post->post_status_class = '-reject';
                     $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_REJECT');
                     break;
                 default:
                     $post->post_status_class = '';
                     $post->post_status = '';
                     break;
             }
             $alias = $post->post_type;
             $modelPostTypes = DiscussHelper::getModel('Post_types');
             // Get each post's post status title
             $title = $modelPostTypes->getTitle($alias);
             $post->post_type = $title;
             // Get each post's post status suffix
             $suffix = $modelPostTypes->getSuffix($alias);
             $post->suffix = $suffix;
             $template->set('post', $post);
             $html .= $template->fetch('frontpage.post.php');
         }
     } else {
         $template = new DiscussThemes();
         $html .= $template->fetch('frontpage.empty.php');
     }
     // This post is already favourite
     $ajax->resolve($html, $pagination);
     $ajax->send();
 }
Ejemplo n.º 21
0
 public function readNotification($targetId, $notificationType)
 {
     if (!$this->exists) {
         return false;
     }
     // Get group members emails
     if (!class_exists('EasyDiscussModelNotification')) {
         jimport('joomla.application.component.model');
         JLoader::import('notification', JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easydiscuss' . DIRECTORY_SEPARATOR . 'models');
     }
     // @rule: Get current logged in user.
     $my = JFactory::getUser();
     // @rule: Clear up any notifications that are visible for the user.
     $notifications = DiscussHelper::getModel('Notification');
     $notifications->markRead($my->id, $targetId, $notificationType);
 }
Ejemplo n.º 22
0
 /**
  * Displays a list of recent discussions from a particular category.
  *
  * @since	3.0
  * @access	public
  */
 public function listings()
 {
     // Initialise variables
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $registry = DiscussHelper::getRegistry();
     $categoryId = JRequest::getInt('category_id', 0);
     // Try to detect if there's any category id being set in the menu parameter.
     $activeMenu = $app->getMenu()->getActive();
     if ($activeMenu) {
         // Load menu params to the registry.
         $registry->loadString($activeMenu->params);
         // Set the active category id if exists.
         $categoryId = $registry->get('category_id') ? $registry->get('category_id') : $categoryId;
     }
     // Get the current logged in user's access.
     $acl = DiscussHelper::getHelper('ACL');
     // Todo: Perhaps we should fix the confused naming of filter and sort to type and sort
     $activeFilter = JRequest::getString('filter', $registry->get('filter'));
     $sort = JRequest::getString('sort', $registry->get('sort'));
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Get the active category id if there is any
     $activeCategory = DiscussHelper::getTable('Category');
     $activeCategory->load($categoryId);
     DiscussHelper::setPageTitle($activeCategory->title);
     // Add breadcrumbs for active category.
     if ($activeCategory->id != 0) {
         // Test if user is really allowed to access this category.
         if (!$activeCategory->canAccess()) {
             $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index', false), JText::_('COM_EASYDISCUSS_SYSTEM_INSUFFICIENT_PERMISSIONS'));
             $app->close();
             return;
         }
         // Add pathway for category here.
         DiscussHelper::getHelper('Pathway')->setCategoryPathway($activeCategory);
     }
     // Add view to this page.
     $this->logView();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     $doc = JFactory::getDocument();
     $doc->setMetadata('description', strip_tags($activeCategory->getDescription()));
     // Add rss feed into headers
     DiscussHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easydiscuss&view=index');
     // Get list of categories on the site.
     $catModel = $this->getModel('Categories');
     // Pagination is by default disabled.
     $pagination = false;
     if ($categoryId) {
         $category = DiscussHelper::getTable('Category');
         $category->load($categoryId);
         $categories[] = $category;
     } else {
         $categories = $catModel->getCategories($categoryId);
         if (count($categories) > 1) {
             $ids = array();
             foreach ($categories as $row) {
                 $ids[] = $row->id;
             }
             // iniCounts should only called in index page.
             $category = DiscussHelper::getTable('Category');
             $category->initCounts($ids, true);
         }
     }
     // Get the model.
     $postModel = DiscussHelper::getModel('Posts');
     $authorIds = array();
     $topicIds = array();
     for ($i = 0; $i < count($categories); $i++) {
         $category =& $categories[$i];
         // building category childs lickage.
         $category->childs = null;
         $nestedLinks = '';
         // In category page
         if ($config->get('layout_show_all_subcategories', '1')) {
             // By default show all the subcategories of the selected category
             DiscussHelper::buildNestedCategories($category->id, $category, false, true);
         } else {
             // Show one level of subcategories of the selected category only
             $category->childs = $catModel->getChildCategories($category->id);
         }
         DiscussHelper::accessNestedCategories($category, $nestedLinks, '0', '', 'listlink', ', ');
         $category->nestedLink = $nestedLinks;
         // Get featured posts from this particular category.
         $featured = $postModel->getDiscussions(array('pagination' => false, 'sort' => $sort, 'filter' => $activeFilter, 'category' => $category->id, 'limit' => $config->get('layout_featuredpost_limit', $limit), 'featured' => true));
         // Get normal discussion posts.
         $posts = $postModel->getDiscussions(array('sort' => $sort, 'filter' => $activeFilter, 'category' => $category->id, 'limit' => $limit, 'featured' => false));
         $tmpPostsArr = array_merge($featured, $posts);
         if (count($tmpPostsArr) > 0) {
             foreach ($tmpPostsArr as $tmpArr) {
                 $authorIds[] = $tmpArr->user_id;
                 $topicIds[] = $tmpArr->id;
             }
         }
         if ($categoryId) {
             $pagination = $postModel->getPagination(0, 'latest', '', $categoryId, false);
         }
         // Set these items into the category object.
         $category->featured = $featured;
         $category->posts = $posts;
         // Set active filter for the category
         $category->activeFilter = $activeFilter;
         $category->activeSort = $sort;
     }
     $lastReplyUser = $postModel->setLastReplyBatch($topicIds);
     $authorIds = array_merge($lastReplyUser, $authorIds);
     // load all author object 1st.
     $authorIds = array_unique($authorIds);
     $profile = DiscussHelper::getTable('Profile');
     $profile->init($authorIds);
     $postLoader = DiscussHelper::getTable('Posts');
     $postLoader->loadBatch($topicIds);
     $postTagsModel = DiscussHelper::getModel('PostsTags');
     $postTagsModel->setPostTagsBatch($topicIds);
     // perform data formating here.
     for ($i = 0; $i < count($categories); $i++) {
         $category =& $categories[$i];
         // perform data formating here.
         if ($category->featured) {
             $category->featured = DiscussHelper::formatPost($category->featured, false, true);
         }
         if ($category->posts) {
             $category->posts = DiscussHelper::formatPost($category->posts, false, true);
         }
     }
     // Let's render the layout now.
     $theme = new DiscussThemes();
     $theme->set('activeFilter', $activeFilter);
     $theme->set('activeSort', $sort);
     $theme->set('categories', $categories);
     $theme->set('pagination', $pagination);
     echo $theme->fetch('frontpage.php');
 }
Ejemplo n.º 23
0
 public function display($tpl = null)
 {
     // Initialise variables
     $doc = JFactory::getDocument();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     $app = JFactory::getApplication();
     $registry = DiscussHelper::getRegistry();
     $categoryId = JRequest::getInt('category_id', 0);
     // Perform redirection if there is a category_id in the index view.
     if (!empty($categoryId)) {
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories&layout=listings&category_id=' . $categoryId, false));
         $app->close();
     }
     // Try to detect if there's any category id being set in the menu parameter.
     $activeMenu = $app->getMenu()->getActive();
     if ($activeMenu && !$categoryId) {
         // Load menu params to the registry.
         $registry->loadString($activeMenu->params);
         if ($registry->get('category_id')) {
             $categoryId = $registry->get('category_id');
         }
     }
     // Get the current logged in user's access.
     $acl = DiscussHelper::getHelper('ACL');
     // Todo: Perhaps we should fix the confused naming of filter and sort to type and sort
     $filter = JRequest::getString('filter', $registry->get('filter'));
     $sort = JRequest::getString('sort', $registry->get('sort'));
     // Get the pagination limit
     $limit = $registry->get('limit');
     $limit = $limit == '-2' ? DiscussHelper::getListLimit() : $limit;
     $limit = $limit == '-1' ? DiscussHelper::getJConfig()->get('list_limit') : $limit;
     // Add view to this page.
     $this->logView();
     // set page title.
     DiscussHelper::setPageTitle();
     // Set the meta of the page.
     DiscussHelper::setMeta();
     // Add rss feed into headers
     DiscussHelper::getHelper('Feeds')->addHeaders('index.php?option=com_easydiscuss&view=index');
     // Get list of categories on the site.
     $catModel = $this->getModel('Categories');
     // Pagination is by default disabled.
     $pagination = false;
     // Get the model.
     $postModel = DiscussHelper::getModel('Posts');
     // Get a list of accessible categories
     $cats = $this->getAccessibleCategories($categoryId);
     // Get featured posts from this particular category.
     $featured = array();
     if ($config->get('layout_featuredpost_frontpage')) {
         $options = array('pagination' => false, 'category' => $cats, 'sort' => $sort, 'filter' => $filter, 'limit' => $config->get('layout_featuredpost_limit', $limit), 'featured' => true);
         $featured = $postModel->getDiscussions($options);
         if (is_null($featured)) {
             $featured = array();
         }
     }
     // Get normal discussion posts.
     $options = array('sort' => $sort, 'category' => $cats, 'filter' => $filter, 'limit' => $limit, 'featured' => false);
     $posts = $postModel->getDiscussions($options);
     if (is_null($posts)) {
         $posts = array();
     }
     $authorIds = array();
     $topicIds = array();
     $tmpPostsArr = array_merge($featured, $posts);
     if (count($tmpPostsArr) > 0) {
         foreach ($tmpPostsArr as $tmpArr) {
             $authorIds[] = $tmpArr->user_id;
             $topicIds[] = $tmpArr->id;
         }
     }
     $pagination = $postModel->getPagination(0, 'latest', '', $cats, false);
     $postLoader = EDC::getTable('Posts');
     $postLoader->loadBatch($topicIds);
     $postTagsModel = EDC::getModel('PostsTags');
     $postTagsModel->setPostTagsBatch($topicIds);
     $model = EDC::getModel('Posts');
     $lastReplyUser = $model->setLastReplyBatch($topicIds);
     // Reduce SQL queries by pre-loading all author object.
     $authorIds = array_merge($lastReplyUser, $authorIds);
     $authorIds = array_unique($authorIds);
     // Initialize the list of user's so we run lesser sql queries.
     $profile = EDC::getTable('Profile');
     $profile->init($authorIds);
     // Format featured entries.
     $featured = EDC::formatPost($featured, false, true);
     // Format normal entries
     $posts = EDC::formatPost($posts, false, true);
     // Get unread count
     $unreadCount = $model->getUnreadCount($cats, false);
     // Get unresolved count
     // Change the "all" to TRUE or FALSE to include/exclude featured post count
     $unresolvedCount = $model->getUnresolvedCount('', $cats, '', 'all');
     // Get resolved count
     $resolvedCount = $model->getTotalResolved();
     // Get unanswered count
     $unansweredCount = EDC::getUnansweredCount($cats, true);
     // Get assigned post count that isn't answered yet.
     $assignedCount = 0;
     if (EDC::isSiteAdmin() || EDC::isModerator()) {
         $assignedModel = EDC::getModel('Assigned');
         $assignedCount = $assignedModel->getTotalUnresolved();
     }
     $activeFilter = $config->get('layout_frontpage_sorting');
     // Let's render the layout now.
     $theme = new DiscussThemes();
     $theme->set('assignedCount', $assignedCount);
     $theme->set('activeFilter', $activeFilter);
     $theme->set('activeSort', $sort);
     $theme->set('categories', $categoryId);
     $theme->set('unreadCount', $unreadCount);
     $theme->set('unansweredCount', $unansweredCount);
     $theme->set('resolvedCount', $resolvedCount);
     $theme->set('unresolvedCount', $unresolvedCount);
     $theme->set('posts', $posts);
     $theme->set('featured', $featured);
     $theme->set('pagination', $pagination);
     echo $theme->fetch('frontpage.index.php');
 }
Ejemplo n.º 24
0
 /**
  * Marks a message as unread
  *
  * @since	3.0
  * @access	public
  */
 public function unread()
 {
     JRequest::checkToken('request', 'get') or jexit('Invalid Token');
     $id = JRequest::getInt('id');
     $app = JFactory::getApplication();
     // Test for valid recipients.
     if (!$id) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_MESSAGING_INVALID_ID'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation', false));
         $app->close();
     }
     // Only registered users are allowed to use conversation.
     $my = JFactory::getUser();
     if (!$my->id) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation', false));
         $app->close();
     }
     // Retrieve model.
     $model = DiscussHelper::getModel('Conversation');
     // Test if user has access
     if (!$model->hasAccess($id, $my->id)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NOT_ALLOWED'), DISCUSS_QUEUE_ERROR);
         $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation', false));
         $app->close();
     }
     // Mark the conversation as unread.
     $model->markAsUnread($id, $my->id);
     DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CONVERSATION_MARKED_AS_UNREAD'), DISCUSS_QUEUE_SUCCESS);
     $app->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=conversation', false));
     $app->close();
 }
Ejemplo n.º 25
0
 /**
  * Processes user subscription.
  *
  * @since	3.0
  * @access	public
  * @param	null
  */
 public function subscribe()
 {
     JRequest::checkToken('request') or jexit('Invalid Token');
     $app = JFactory::getApplication();
     $my = JFactory::getUser();
     $config = DiscussHelper::getConfig();
     // Get variables from post.
     $type = JRequest::getVar('type', null);
     $name = JRequest::getVar('subscribe_name', '');
     $email = JRequest::getVar('subscribe_email', '');
     $interval = JRequest::getVar('subscription_interval', '');
     $cid = JRequest::getInt('cid', 0);
     $redirect = JRequest::getVar('redirect', '');
     if (empty($redirect)) {
         $redirect = DiscussRouter::_('index.php?option=com_easydiscuss', false);
         if ($type == 'category' && $cid) {
             $redirect = DiscussRouter::getCategoryRoute($cid, false);
         }
     } else {
         $redirect = base64_decode($url);
     }
     // Apply filtering on the name.
     $filter = JFilterInput::getInstance();
     $name = $filter->clean($name, 'STRING');
     $email = JString::trim($email);
     $name = JString::trim($name);
     if (!JMailHelper::isEmailAddress($email)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_INVALID_EMAIL'), 'error');
         $app->redirect($redirect);
         $app->close();
     }
     // Check for empty email
     if (empty($email)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_EMAIL_IS_EMPTY'), 'error');
         $app->redirect($redirect);
         $app->close();
     }
     // Check for empty name
     if (empty($name)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NAME_IS_EMPTY'), 'error');
         $app->redirect($redirect);
         $app->close();
     }
     $model = DiscussHelper::getModel('Subscribe');
     $subscription = $model->isSiteSubscribed($type, $email, $cid);
     $data = array();
     $data['type'] = $type;
     $data['userid'] = $my->id;
     $data['email'] = $email;
     $data['cid'] = $cid;
     $data['member'] = $my->id ? '1' : '0';
     $data['name'] = $my->id ? $my->name : $name;
     $data['interval'] = $interval;
     if ($subscription) {
         // Perhaps the user tried to change the subscription interval.
         if ($subscription->interval == $interval) {
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_UPDATED_SUCCESSFULLY'), 'success');
             $app->redirect($redirect);
             return $app->close();
         }
         // User changed their subscription interval.
         if (!$model->updateSiteSubscription($subscription->id, $data)) {
             //if($model->updateSiteSubscription($subRecord['id'], $subscription_info))
             DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_FAILED'), 'error');
             $app->redirect($redirect);
             return $app->close();
         }
         // If the user already has an existing subscription, just let them know that their subscription is already updated.
         $intervalMessage = JText::_('COM_EASYDISCUSS_SUBSCRIPTION_INTERVAL_' . strtoupper($interval));
         DiscussHelper::setMessageQueue(JText::sprintf('COM_EASYDISCUSS_SUBSCRIPTION_UPDATED', $intervalMessage), 'success');
         $app->redirect($redirect);
         return $app->close();
     }
     // Only new records are added here.
     if (!$model->addSubscription($data)) {
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_FAILED'), 'error');
         $app->redirect($redirect);
         return $app->close();
     }
     DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_UPDATED_SUCCESSFULLY'), 'success');
     $app->redirect($redirect);
     return $app->close();
 }
Ejemplo n.º 26
0
 /**
  * Displays a list of voters on the site.
  *
  * @since	3.0
  */
 public function showVoters($id)
 {
     // Allow users to see who voted on the discussion
     $ajax = new Disjax();
     $config = DiscussHelper::getConfig();
     $my = JFactory::getUser();
     // If main_allowguestview_whovoted is lock
     if (!$config->get('main_allowguestview_whovoted') && !$my->id) {
         $ajax->reject(JText::_('COM_EASYDISCUSS_NOT_ALLOWED_HERE'));
         return $ajax->send();
     }
     $voteModel = DiscussHelper::getModel('Votes');
     $voters = $voteModel->getVoters($id);
     $guests = 0;
     $users = array();
     if ($voters) {
         foreach ($voters as $voter) {
             if (!$voter->user_id) {
                 $guests += 1;
             } else {
                 $profile = DiscussHelper::getTable('Profile');
                 $users[] = $profile->load($voter->user_id);
             }
         }
     }
     $options = new stdClass();
     $options->title = JText::_('COM_EASYDISCUSS_VIEWING_VOTERS_TITLE');
     $theme = new DiscussThemes();
     $theme->set('users', $users);
     $theme->set('guests', $guests);
     $content = $theme->fetch('voters.php', array('dialog' => true));
     $options->content = $content;
     $buttons = array();
     $button = new stdClass();
     $button->title = JText::_('COM_EASYDISCUSS_BUTTON_CLOSE');
     $button->action = 'disjax.closedlg();';
     $buttons[] = $button;
     $options->buttons = $buttons;
     $ajax->dialog($options);
     return $ajax->send();
 }
Ejemplo n.º 27
0
 public static function getPostStatusAndTypes($posts = null)
 {
     if (empty($posts)) {
         return;
     }
     $badgesTable = DiscussHelper::getTable('Profile');
     foreach ($posts as $post) {
         $badgesTable->load($post->user->id);
         $post->badges = $badgesTable->getBadges();
         // Translate post status from integer to string
         switch ($post->post_status) {
             case '0':
                 $post->post_status_class = '';
                 $post->post_status = '';
                 break;
             case '1':
                 $post->post_status_class = '-on-hold';
                 $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ON_HOLD');
                 break;
             case '2':
                 $post->post_status_class = '-accept';
                 $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_ACCEPTED');
                 break;
             case '3':
                 $post->post_status_class = '-working-on';
                 $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_WORKING_ON');
                 break;
             case '4':
                 $post->post_status_class = '-reject';
                 $post->post_status = JText::_('COM_EASYDISCUSS_POST_STATUS_REJECT');
                 break;
             default:
                 $post->post_status_class = '';
                 $post->post_status = '';
                 break;
         }
         $alias = $post->post_type;
         $modelPostTypes = DiscussHelper::getModel('Post_types');
         // Get each post's post status title
         $title = $modelPostTypes->getTitle($alias);
         $post->post_type = $title;
         // Get each post's post status suffix
         $suffix = $modelPostTypes->getSuffix($alias);
         $post->suffix = $suffix;
     }
     return $posts;
 }
Ejemplo n.º 28
0
 /**
  * update posts
  */
 public function submit()
 {
     if (JRequest::getMethod() == 'POST') {
         JRequest::checkToken('request') or jexit('Invalid Token');
         $user = JFactory::getUser();
         // get all forms value
         $post = JRequest::get('post');
         // get id if available
         $id = JRequest::getInt('id', 0);
         // get post parent id
         $parent = JRequest::getInt('parent_id', 0);
         // the source where page come from
         $source = JRequest::getVar('source', 'posts');
         // Get raw content from request as we may need to respect the html codes.
         $content = JRequest::getVar('dc_reply_content', '', 'post', 'none', JREQUEST_ALLOWRAW);
         // Ensure that the posted content is respecting the correct values.
         $post['dc_reply_content'] = $content;
         // get config
         $config = DiscussHelper::getConfig();
         $post['alias'] = empty($post['alias']) ? DiscussHelper::getAlias($post['title'], 'post', $id) : DiscussHelper::getAlias($post['alias'], 'post', $id);
         //clear tags if editing a post.
         $previousTags = array();
         if (!empty($id)) {
             $postsTagsModel = $this->getModel('PostsTags');
             $tmppreviousTags = $postsTagsModel->getPostTags($id);
             if (!empty($tmppreviousTags)) {
                 foreach ($tmppreviousTags as $previoustag) {
                     $previousTags[] = $previoustag->id;
                 }
             }
             $postsTagsModel->deletePostTag($id);
         }
         // bind the table
         $postTable = JTable::getInstance('posts', 'Discuss');
         $postTable->load($id);
         //get previous post status before binding.
         $prevPostStatus = $postTable->published;
         $postTable->bind($post, true);
         // hold last inserted ID in DB
         $lastId = null;
         // @rule: Bind parameters
         $postTable->bindParams($post);
         if ($config->get('main_private_post') && isset($post['private'])) {
             $postTable->private = $post['private'];
         }
         // @trigger: onBeforeSave
         $isNew = (bool) $postTable->id;
         DiscussEventsHelper::importPlugin('content');
         DiscussEventsHelper::onContentBeforeSave('post', $post, $isNew);
         if (!$postTable->store()) {
             JError::raiseError(500, $postTable->getError());
         }
         //Clear off previous records before storing
         $ruleModel = DiscussHelper::getModel('CustomFields');
         $ruleModel->deleteCustomFieldsValue($postTable->id, 'update');
         // Process custom fields.
         $fieldIds = JRequest::getVar('customFields');
         if (!empty($fieldIds)) {
             foreach ($fieldIds as $fieldId) {
                 $fields = JRequest::getVar('customFieldValue_' . $fieldId);
                 if (!empty($fields)) {
                     // Cater for custom fields select list
                     // To detect if there is no value selected for the select list custom fields
                     if (in_array('defaultList', $fields)) {
                         $tempKey = array_search('defaultList', $fields);
                         $fields[$tempKey] = '';
                     }
                 }
                 $postTable->bindCustomFields($fields, $fieldId);
             }
         }
         // @trigger: onAfterSave
         DiscussEventsHelper::onContentAfterSave('post', $post, $isNew);
         // The category_id for the replies should change too
         $postTable->moveChilds($postTable->id, $postTable->category_id);
         $lastId = $postTable->id;
         // Bind file attachments
         $postTable->bindAttachments();
         $message = JText::_('COM_EASYDISCUSS_POST_SAVED');
         $date = DiscussHelper::getDate();
         //@task: Save tags
         $tags = JRequest::getVar('tags', '', 'POST');
         if (!empty($tags)) {
             $tagModel = $this->getModel('Tags');
             foreach ($tags as $tag) {
                 if (!empty($tag)) {
                     $tagTable = JTable::getInstance('Tags', 'Discuss');
                     //@task: Only add tags if it doesn't exist.
                     if (!$tagTable->exists($tag)) {
                         $tagInfo['title'] = JString::trim($tag);
                         $tagInfo['alias'] = DiscussHelper::getAlias($tag, 'tag');
                         $tagInfo['created'] = $date->toMySQL();
                         $tagInfo['published'] = 1;
                         $tagInfo['user_id'] = $user->id;
                         $tagTable->bind($tagInfo);
                         $tagTable->store();
                     } else {
                         $tagTable->load($tag, true);
                     }
                     $postTagInfo = array();
                     //@task: Store in the post tag
                     $postTagTable = JTable::getInstance('PostsTags', 'Discuss');
                     $postTagInfo['post_id'] = $postTable->id;
                     $postTagInfo['tag_id'] = $tagTable->id;
                     $postTagTable->bind($postTagInfo);
                     $postTagTable->store();
                 }
             }
         }
         $isNew = empty($id) ? true : false;
         if (($isNew || $prevPostStatus == DISCUSS_ID_PENDING) && $postTable->published == DISCUSS_ID_PUBLISHED) {
             $owner = $isNew ? $user->id : $postTable->user_id;
             DiscussHelper::sendNotification($postTable, $parent, $isNew, $owner, $prevPostStatus);
             // auto subscription
             if ($config->get('main_autopostsubscription') && $config->get('main_postsubscription') && $postTable->user_type != 'twitter' && !empty($postTable->parent_id)) {
                 // process only if this is a reply
                 //automatically subscribe this user into this reply
                 $replier = JFactory::getUser($postTable->user_id);
                 $subscription_info = array();
                 $subscription_info['type'] = 'post';
                 $subscription_info['userid'] = !empty($postTable->user_id) ? $postTable->user_id : '0';
                 $subscription_info['email'] = !empty($postTable->user_id) ? $replier->email : $postTable->poster_email;
                 $subscription_info['cid'] = $postTable->parent_id;
                 $subscription_info['member'] = !empty($postTable->user_id) ? '1' : '0';
                 $subscription_info['name'] = !empty($postTable->user_id) ? $replier->name : $postTable->poster_name;
                 $subscription_info['interval'] = 'instant';
                 //get frontend subscribe table
                 $susbcribeModel = DiscussHelper::getModel('Subscribe');
                 $sid = '';
                 if ($subscription_info['userid'] == 0) {
                     $sid = $susbcribeModel->isPostSubscribedEmail($subscription_info);
                     if (empty($sid)) {
                         $susbcribeModel->addSubscription($subscription_info);
                     }
                 } else {
                     $sid = $susbcribeModel->isPostSubscribedUser($subscription_info);
                     if (empty($sid['id'])) {
                         //add new subscription.
                         $susbcribeModel->addSubscription($subscription_info);
                     }
                 }
             }
             // only if the post is a discussion
             if ($config->get('integration_pingomatic') && empty($postTable->parent_id)) {
                 $pingo = DiscussHelper::getHelper('Pingomatic');
                 $urls = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $postTable->id, true, true);
                 $pingo->ping($postTable->title, $urls);
             }
         }
         $pid = '';
         if (!empty($parent)) {
             $pid = '&pid=' . $parent;
         }
         $task = $this->getTask();
         switch ($task) {
             case 'apply':
                 $redirect = 'index.php?option=com_easydiscuss&view=post&id=' . $postTable->id;
                 break;
             case 'save':
                 $redirect = 'index.php?option=com_easydiscuss&view=posts';
                 break;
             case 'savePublishNew':
             default:
                 $redirect = 'index.php?option=com_easydiscuss&view=post';
                 break;
         }
         DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_DISCUSSION_SAVED'), DISCUSS_QUEUE_SUCCESS);
         $this->setRedirect($redirect);
     }
 }
Ejemplo n.º 29
0
 public function getMyFavCount()
 {
     $model = DiscussHelper::getModel('Favourites');
     $result = $model->getFavouritesCount($this->id);
     return $result;
 }
Ejemplo n.º 30
0
 private function getReplies($category, $post, $sort, $answer)
 {
     $config = DiscussHelper::getConfig();
     $postsModel = DiscussHelper::getModel('Posts');
     $my = JFactory::getUser();
     // Get a list of replies for this discussion
     $replies = array();
     $hasMoreReplies = false;
     $totalReplies = 0;
     $readMoreURI = '';
     if ($category->canViewReplies()) {
         $repliesLimit = $config->get('layout_replies_list_limit');
         $totalReplies = $postsModel->getTotalReplies($post->id);
         $hasMoreReplies = false;
         $limitstart = null;
         $limit = null;
         if ($repliesLimit && !JRequest::getBool('viewallreplies')) {
             $limit = $repliesLimit;
             $hasMoreReplies = $totalReplies - $repliesLimit > 0;
         }
         $replies = $postsModel->getReplies($post->id, $sort, $limitstart, $limit);
         if (count($replies) > 0) {
             $repliesIds = array();
             $authorIds = array();
             foreach ($replies as $reply) {
                 $repliesIds[] = $reply->id;
                 $authorIds[] = $reply->user_id;
             }
             if ($answer) {
                 if (is_array($answer)) {
                     $answer = $answer[0];
                 }
                 $repliesIds[] = $answer->id;
                 $authorIds[] = $answer->user_id;
             }
             $post->loadBatch($repliesIds);
             $post->setAttachmentsData('replies', $repliesIds);
             // here we include the discussion id into the array as well.
             $repliesIds[] = $post->id;
             $authorIds[] = $post->user_id;
             $post->setLikeAuthorsBatch($repliesIds);
             DiscussHelper::getHelper('Post')->setIsLikedBatch($repliesIds);
             $post->setPollQuestionsBatch($repliesIds);
             $post->setPollsBatch($repliesIds);
             $post->setLikedByBatch($repliesIds, $my->id);
             $post->setVoterBatch($repliesIds);
             $post->setHasVotedBatch($repliesIds);
             $post->setTotalCommentsBatch($repliesIds);
             $commentLimit = $config->get('main_comment_pagination') ? $config->get('main_comment_pagination_count') : null;
             $post->setCommentsBatch($repliesIds, $commentLimit);
             // Reduce SQL queries by pre-loading all author object.
             $authorIds = array_unique($authorIds);
             $profile = DiscussHelper::getTable('Profile');
             $profile->init($authorIds);
         }
         $readMoreURI = JURI::getInstance()->toString();
         $delimiteter = JString::strpos($readMoreURI, '&') ? '&' : '?';
         $readMoreURI = $hasMoreReplies ? $readMoreURI . $delimiteter . 'viewallreplies=1' : $readMoreURI;
         // Format the reply items.
         $replies = DiscussHelper::formatReplies($replies, $category);
     }
     $data = new stdClass();
     $data->replies = $replies;
     $data->total = $totalReplies;
     $data->more = $hasMoreReplies;
     $data->readmore = $readMoreURI;
     return $data;
 }