function authorizeAccess() { $mainframe = JFactory::getApplication(); $session = JFactory::getSession(); $config = DiscussHelper::getConfig(); $consumerKey = $config->get('integration_twitter_consumer_key'); $consumerSecretKey = $config->get('integration_twitter_consumer_secret_key'); if ($session->has('twitter_oauth_request_token', 'discuss')) { //$request_token = $session->get('twitter_oauth_token', 'discuss'); $session_request = JString::str_ireplace(',', "\r\n", $session->get('twitter_oauth_request_token', '', 'discuss')); $request_token = DiscussHelper::getRegistry($session_request); /* Create TwitteroAuth object with app key/secret and token key/secret from default phase */ $connection = new DiscussTwitterOAuth($consumerKey, $consumerSecretKey, $request_token->get('oauth_token', ''), $request_token->get('oauth_token_secret', '')); /* Request access tokens from twitter */ $access_token = $connection->getAccessToken($_REQUEST['oauth_verifier']); if (!empty($access_token['oauth_token']) && !empty($access_token['oauth_token_secret'])) { if ($session->has('twitter_oauth_access_token', 'discuss')) { $session->clear('twitter_oauth_access_token', 'discuss'); } $session->set('twitter_oauth_access_token', "user_id=" . $access_token["user_id"] . ",screen_name=" . $access_token["screen_name"] . ",oauth_token=" . $access_token['oauth_token'] . ",oauth_token_secret=" . $access_token['oauth_token_secret'], 'discuss'); $status = true; $msg = JText::_('COM_EASYDISCUSS_TWITTER_OAUTH_SUCCESS'); } else { $status = false; $msg = JText::_('COM_EASYDISCUSS_TWITTER_OAUTH_FAILED'); } } else { $status = false; $msg = JText::_('COM_EASYDISCUSS_TWITTER_USER_NOT_FOUND'); } echo "<script language=javascript>window.opener.discuss.login.twitter.signin(" . $status . ", '" . $msg . "'); self.close();</script>"; }
function getConfig() { static $config = null; if (is_null($config)) { $params = $this->_getParams('config'); $config = DiscussHelper::getRegistry($params); } return $config; }
public function display($tpl = null) { // Initialise variables $config = DiscussHelper::getConfig(); $id = JRequest::getInt('id'); $profile = JTable::getInstance('Profile', 'Discuss'); $profile->load($id); $userparams = DiscussHelper::getRegistry($profile->get('params')); $siteDetails = DiscussHelper::getRegistry($profile->get('site')); $avatarIntegration = $config->get('layout_avatarIntegration', 'default'); $user = JFactory::getUser($id); $isNew = $user->id == 0 ? true : false; $badges = $profile->getBadges(); $model = $this->getModel('Badges'); $history = $model->getBadgesHistory($profile->id); $params = $user->getParameters(true); // Badge id's that are assigned to the user. $badgeIds = ''; for ($i = 0; $i < count($badges); $i++) { $badgeIds .= $badges[$i]->id; if (next($badges) !== false) { $badgeIds .= ','; } $badgeUser = DiscussHelper::getTable('BadgesUsers'); $badgeUser->loadByUser($id, $badges[$i]->id); $badges[$i]->reference_id = $badgeUser->id; $badges[$i]->custom = $badgeUser->custom; } $this->assign('badgeIds', $badgeIds); $this->assignRef('badges', $badges); $this->assignRef('history', $history); $this->assignRef('config', $config); $this->assignRef('profile', $profile); $this->assignRef('user', $user); $this->assignRef('isNew', $isNew); $this->assignRef('params', $params); $this->assignRef('avatarIntegration', $avatarIntegration); $this->assignRef('userparams', $userparams); $this->assignRef('siteDetails', $siteDetails); parent::display($tpl); }
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'); }
public function apply() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $mainframe = JFactory::getApplication(); $db = DiscussHelper::getDBO(); $my = JFactory::getUser(); $acl = JFactory::getACL(); $config = DiscussHelper::getConfig(); // Create a new JUser object $user = new JUser(JRequest::getVar('id', 0, 'post', 'int')); $original_gid = $user->get('gid'); $post = JRequest::get('post'); $user->name = $post['fullname']; if (DiscussHelper::getJoomlaVersion() >= '1.6') { $jformPost = JRequest::getVar('jform', array(), 'post', 'array'); $post['params'] = $jformPost['params']; } if (!$user->bind($post)) { DiscussHelper::setMessageQueue($user->getError(), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } if (DiscussHelper::getJoomlaVersion() >= '1.6') { if ($user->get('id') == $my->get('id') && $user->get('block') == 1) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_YOURSELF'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } else { if ($user->authorise('core.admin') && $user->get('block') == 1) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_SUPERUSER'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } else { if ($user->authorise('core.admin') && !$my->authorise('core.admin')) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_EDIT_SUPERUSER'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } } } //replacing thr group name with group id so it is save correctly into the Joomla group table. $jformPost = JRequest::getVar('jform', array(), 'post', 'array'); if (!empty($jformPost['groups'])) { $user->groups = array(); foreach ($jformPost['groups'] as $groupid) { $user->groups[$groupid] = $groupid; } } } else { $objectID = $acl->get_object_id('users', $user->get('id'), 'ARO'); $groups = $acl->get_object_groups($objectID, 'ARO'); $this_group = strtolower($acl->get_group_name($groups[0], 'ARO')); if ($user->get('id') == $my->get('id') && $user->get('block') == 1) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_YOURSELF'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } else { if ($this_group == 'super administrator' && $user->get('block') == 1) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_BLOCK_SUPERUSER'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } else { if ($this_group == 'administrator' && $my->get('gid') == 24 && $user->get('block') == 1) { DiscussHelper::setMessageQueue(JText::_('WARNBLOCK'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } else { if ($this_group == 'super administrator' && $my->get('gid') != 25) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_EDIT_SUPERUSER'), DISCUSS_QUEUE_ERROR); $this->_saveError($user->id); } } } } } // Are we dealing with a new user which we need to create? $isNew = $user->get('id') < 1; if (DiscussHelper::getJoomlaVersion() <= '1.5') { // do this step only for J1.5 if (!$isNew) { // if group has been changed and where original group was a Super Admin if ($user->get('gid') != $original_gid && $original_gid == 25) { // count number of active super admins $query = 'SELECT COUNT( id )' . ' FROM #__users' . ' WHERE gid = 25' . ' AND block = 0'; $db->setQuery($query); $count = $db->loadResult(); if ($count <= 1) { DiscussHelper::setMessageQueue(JText::_('WARN_ONLY_SUPER'), DISCUSS_QUEUE_ERROR); // disallow change if only one Super Admin exists $this->setRedirect('index.php?option=com_easydiscuss&view=users'); return false; } } } } /* * Lets save the JUser object */ if (!$user->save()) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CANNOT_SAVE_THE_USER_INFORMATION'), DISCUSS_QUEUE_ERROR); return $this->execute('edit'); } // If updating self, load the new user object into the session if (DiscussHelper::getJoomlaVersion() <= '1.5') { // If updating self, load the new user object into the session if ($user->get('id') == $my->get('id')) { // Get an ACL object $acl = JFactory::getACL(); // Get the user group from the ACL $grp = $acl->getAroGroup($user->get('id')); // Mark the user as logged in $user->set('guest', 0); $user->set('aid', 1); // Fudge Authors, Editors, Publishers and Super Administrators into the special access group if ($acl->is_group_child_of($grp->name, 'Registered') || $acl->is_group_child_of($grp->name, 'Public Backend')) { $user->set('aid', 2); } // Set the usertype based on the ACL group name $user->set('usertype', $grp->name); $session = JFactory::getSession(); $session->set('user', $user); } } $post = JRequest::get('post'); if ($isNew) { // if this is a new account, we unset the id so // that profile jtable will add new record properly. unset($post['id']); } $profile = DiscussHelper::getTable('Profile'); $profile->load($user->id); $profile->bind($post); $file = JRequest::getVar('Filedata', '', 'Files', 'array'); if (!empty($file['name'])) { $newAvatar = DiscussHelper::uploadAvatar($profile, true); $profile->avatar = $newAvatar; } //save params $userparams = DiscussHelper::getRegistry(''); if (isset($post['facebook'])) { $userparams->set('facebook', $post['facebook']); } if (isset($post['show_facebook'])) { $userparams->set('show_facebook', $post['show_facebook']); } if (isset($post['twitter'])) { $userparams->set('twitter', $post['twitter']); } if (isset($post['show_twitter'])) { $userparams->set('show_twitter', $post['show_twitter']); } if (isset($post['linkedin'])) { $userparams->set('linkedin', $post['linkedin']); } if (isset($post['show_linkedin'])) { $userparams->set('show_linkedin', $post['show_linkedin']); } if (isset($post['skype'])) { $userparams->set('skype', $post['skype']); } if (isset($post['show_skype'])) { $userparams->set('show_skype', $post['show_skype']); } if (isset($post['website'])) { $userparams->set('website', $post['website']); } if (isset($post['show_website'])) { $userparams->set('show_website', $post['show_website']); } $profile->params = $userparams->toString(); // Save site details $siteDetails = DiscussHelper::getRegistry(''); if (isset($post['siteUrl'])) { $siteDetails->set('siteUrl', $post['siteUrl']); } if (isset($post['siteUsername'])) { $siteDetails->set('siteUsername', $post['siteUsername']); } if (isset($post['sitePassword'])) { $siteDetails->set('sitePassword', $post['sitePassword']); } if (isset($post['ftpUrl'])) { $siteDetails->set('ftpUrl', $post['ftpUrl']); } if (isset($post['ftpUsername'])) { $siteDetails->set('ftpUsername', $post['ftpUsername']); } if (isset($post['ftpPassword'])) { $siteDetails->set('ftpPassword', $post['ftpPassword']); } if (isset($post['optional'])) { $siteDetails->set('optional', $post['optional']); } $profile->site = $siteDetails->toString(); $profile->store(); // Update points DiscussHelper::getHelper('ranks')->assignRank($profile->id, 'points'); $app = JFactory::getApplication(); $task = $this->getTask(); $url = $task == 'apply' ? 'index.php?option=com_easydiscuss&view=user&id=' . $profile->id : 'index.php?option=com_easydiscuss&view=users'; DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_USER_INFORMATION_SAVED'), DISCUSS_QUEUE_SUCCESS); $app->redirect($url); }
/** * @package EasyDiscuss * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved. * @license GNU/GPL, see LICENSE.php * * EasyDiscuss is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Restricted access'); $profile = JTable::getInstance('Profile', 'Discuss'); $profile->load($post->user_id); $siteDetails = DiscussHelper::getRegistry($profile->get('site')); $siteUrl = $siteDetails->get('siteUrl'); $siteusername = $siteDetails->get('siteUsername'); $password = $siteDetails->get('sitePassword'); $ftpurl = $siteDetails->get('ftpUrl'); $ftpusername = $siteDetails->get('ftpUsername'); $ftppassword = $siteDetails->get('ftpPassword'); $siteinfo = $siteDetails->get('optional'); $showProfileDetails = true; if (empty($siteUrl) && empty($siteusername) && empty($password) && empty($ftpurl) && empty($ftpusername) && empty($ftppassword)) { $showProfileDetails = false; } $access = trim($system->config->get('tab_site_access')); // Nobody can view this if access is not set yet. if (!$access) { return;
/** * 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'); }
function saveProfile() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $mainframe = JFactory::getApplication(); $config = DiscussHelper::getConfig(); $post = JRequest::get('post'); array_walk($post, array($this, '_trim')); if (!$this->_validateProfileFields($post)) { $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false)); return; } $my = JFactory::getUser(); $my->name = $post['fullname']; // We check for password2 instead off password because apparently it is still autofill the form although is autocomplete="off" if (!empty($post['password2'])) { $my->password = $post['password']; $my->bind($post); } // Cheap fix: Do not allow user to override `edited` field. // Ideally, this should just be passed as ignore into the table. if (isset($post['edited'])) { unset($post['edited']); } // column mapping. $post['location'] = $post['address']; $profile = DiscussHelper::getTable('Profile'); $profile->load($my->id); $profile->bind($post); //save avatar $file = JRequest::getVar('Filedata', '', 'files', 'array'); if (!empty($file['name'])) { $newAvatar = $this->_upload($profile); // @rule: If this is the first time the user is changing their profile picture, give a different point if ($profile->avatar == 'default.png') { // @rule: Process AUP integrations DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_NEW_AVATAR, $my->id, $newAvatar); } else { // @rule: Process AUP integrations DiscussHelper::getHelper('Aup')->assign(DISCUSS_POINTS_UPDATE_AVATAR, $my->id, $newAvatar); } // @rule: Badges when they change their profile picture DiscussHelper::getHelper('History')->log('easydiscuss.new.avatar', $my->id, JText::_('COM_EASYDISCUSS_BADGES_HISTORY_UPDATED_AVATAR')); DiscussHelper::getHelper('Badges')->assign('easydiscuss.new.avatar', $my->id); DiscussHelper::getHelper('Points')->assign('easydiscuss.new.avatar', $my->id); // Reset the points $profile->updatePoints(); $profile->avatar = $newAvatar; } //save params $userparams = DiscussHelper::getRegistry(''); if (isset($post['facebook'])) { $userparams->set('facebook', $post['facebook']); } if (isset($post['show_facebook'])) { $userparams->set('show_facebook', $post['show_facebook']); } if (isset($post['twitter'])) { $userparams->set('twitter', $post['twitter']); } if (isset($post['show_twitter'])) { $userparams->set('show_twitter', $post['show_twitter']); } if (isset($post['linkedin'])) { $userparams->set('linkedin', $post['linkedin']); } if (isset($post['show_linkedin'])) { $userparams->set('show_linkedin', $post['show_linkedin']); } if (isset($post['skype'])) { $userparams->set('skype', $post['skype']); } if (isset($post['show_skype'])) { $userparams->set('show_skype', $post['show_skype']); } if (isset($post['website'])) { $userparams->set('website', $post['website']); } if (isset($post['show_website'])) { $userparams->set('show_website', $post['show_website']); } $profile->params = $userparams->toString(); // Save site details $siteDetails = DiscussHelper::getRegistry(''); if (isset($post['siteUrl'])) { $siteDetails->set('siteUrl', $post['siteUrl']); } if (isset($post['siteUsername'])) { $siteDetails->set('siteUsername', $post['siteUsername']); } if (isset($post['sitePassword'])) { $siteDetails->set('sitePassword', $post['sitePassword']); } if (isset($post['ftpUrl'])) { $siteDetails->set('ftpUrl', $post['ftpUrl']); } if (isset($post['ftpUsername'])) { $siteDetails->set('ftpUsername', $post['ftpUsername']); } if (isset($post['ftpPassword'])) { $siteDetails->set('ftpPassword', $post['ftpPassword']); } if (isset($post['optional'])) { $siteDetails->set('optional', $post['optional']); } $profile->site = $siteDetails->toString(); if ($profile->store() && $my->save(true)) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_PROFILE_SAVED'), 'info'); // @rule: Badges when they change their profile picture DiscussHelper::getHelper('History')->log('easydiscuss.update.profile', $my->id, JText::_('COM_EASYDISCUSS_BADGES_HISTORY_UPDATED_PROFILE')); DiscussHelper::getHelper('Badges')->assign('easydiscuss.update.profile', $my->id); // Only give points the first time the user edits their profile. if (!$profile->edited) { DiscussHelper::getHelper('Points')->assign('easydiscuss.update.profile', $my->id); // Reload profile again because the points might already update the user's point. $updatedProfile = DiscussHelper::getTable('Profile'); $updatedProfile->load($my->id, false, true); $updatedProfile->edited = true; $updatedProfile->store(); } } else { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_PROFILE_SAVE_ERROR'), 'error'); $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false)); return; } $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&layout=edit', false)); }
public function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); $mainframe = JFactory::getApplication(); $task = $this->getTask(); $message = ''; $type = 'success'; if (JRequest::getMethod() == 'POST') { $post = JRequest::get('post'); if (empty($post['title'])) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_CATEGORIES_INVALID_CATEGORY'), DISCUSS_QUEUE_ERROR); $url = 'index.php?option=com_easydiscuss&view=categories'; $mainframe->redirect(JRoute::_($url, false)); return; } $category = JTable::getInstance('Category', 'Discuss'); $user = JFactory::getUser(); $post['created_by'] = $user->id; $catId = JRequest::getVar('catid', ''); $isNew = empty($catId) ? true : false; $alterOrdering = true; if (!empty($catId)) { $category->load($catId); $newParentId = $post['parent_id']; if ($category->parent_id != $newParentId) { $alterOrdering = true; } else { $alterOrdering = false; } $post['id'] = $catId; } $category->bind($post); // Description might contain html codes $description = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $category->description = $description; // Bind params $params = DiscussHelper::getRegistry(''); $params->set('show_description', $post['show_description']); $params->set('maxlength', $post['maxlength']); $params->set('maxlength_size', $post['maxlength_size']); $params->set('cat_notify_custom', $post['cat_notify_custom']); $params->set('cat_email_parser', $post['cat_email_parser']); $params->set('cat_email_parser_password', $post['cat_email_parser_password']); $params->set('cat_email_parser_switch', $post['cat_email_parser_switch']); $category->params = $params->toString(); if (!$category->store($alterOrdering)) { JError::raiseError(500, $category->getError()); exit; } //save the category acl $category->deleteACL(); $category->saveACL($post); $file = JRequest::getVar('Filedata', '', 'files', 'array'); if (!empty($file['name'])) { $newAvatar = DiscussHelper::uploadCategoryAvatar($category, true); $category->avatar = $newAvatar; $category->store(); //now update the avatar. } // now we need to rerun the category ordering incase admin assign the correct category tree as a child of another category. $category->rebuildOrdering(); $message = JText::_('COM_EASYDISCUSS_CATEGORIES_SAVED_SUCCESS'); } else { $message = JText::_('COM_EASYDISCUSS_INVALID_REQUEST'); $type = 'error'; } DiscussHelper::setMessageQueue($message, $type); if ($task == 'savePublishNew') { $mainframe->redirect('index.php?option=com_easydiscuss&view=category'); $mainframe->close(); } if ($task == 'apply') { $mainframe->redirect('index.php?option=com_easydiscuss&view=category&catid=' . $category->id); $mainframe->close(); } $mainframe->redirect('index.php?option=com_easydiscuss&view=categories'); $mainframe->close(); }
public static function onContentPrepare($context = 'post', &$data = '', &$params = array(), $limitstart = 0) { $dispatcher = JDispatcher::getInstance(); $context = 'com_easydiscuss.' . $context; if (empty($params)) { $params = DiscussHelper::getRegistry(''); } self::beforeTrigger($data); if (DiscussHelper::getJoomlaVersion() >= '1.6') { $result = $dispatcher->trigger('onContentPrepare', array($context, &$data, &$params, $limitstart)); } else { $result = $dispatcher->trigger('onPrepareContent', array(&$data, &$params, $limitstart)); } self::afterTrigger($data); return $result; }
public function loadParams() { $this->_params = DiscussHelper::getRegistry($this->params); }
public function setAccess($access) { $access = DiscussHelper::getRegistry($access); $this->_access_token = $access->get('token'); return true; }
public static function getAuthentication() { $config = DiscussHelper::getConfig(); $consumerKey = $config->get('integration_twitter_consumer_key'); $consumerSecretKey = $config->get('integration_twitter_consumer_secret_key'); ob_start(); if (!empty($consumerKey) && !empty($consumerSecretKey)) { $session = JFactory::getSession(); $twitterUserId = ''; $twitterScreenName = ''; $twitterOauthToken = ''; $twitterOauthTokenSecret = ''; if ($session->has('twitter_oauth_access_token', 'discuss')) { $session_request = JString::str_ireplace(',', "\r\n", $session->get('twitter_oauth_access_token', '', 'discuss')); $access_token = DiscussHelper::getRegistry($session_request); $twitterUserId = $access_token->get('user_id', ''); $twitterScreenName = $access_token->get('screen_name', ''); $twitterOauthToken = $access_token->get('oauth_token', ''); $twitterOauthTokenSecret = $access_token->get('oauth_token_secret', ''); } //check if this is frontend or backend // $app = JFactory::getApplication(); // if ( $app->getClientId() === 1 ) { // $controller = 'c'; // }else{ // $controller = 'controller'; // } if (empty($twitterUserId) || empty($twitterOauthToken) || empty($twitterOauthTokenSecret)) { ?> <p class="small"><?php echo JText::_('COM_EASYDISCUSS_TWITTER_SIGN_IN_DESC'); ?> </p><?php ?> <p class="small"><a href="javascript:void(0)" onclick="Popup=window.open('<?php echo trim(JURI::base(), "/") . DiscussRouter::_('/index.php?option=com_easydiscuss&controller=twitter&task=requestAccess', false); ?> ','Popup','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=800,height=450,top=100'); return false;"><img src="<?php echo DISCUSS_JURIROOT; ?> /media/com_easydiscuss/images/twitter_signon.png" border="0" alt="here" /></a></p><?php } else { $screen_name = $twitterScreenName ? $twitterScreenName : $twitterUserId; ?> <p class="small"><?php echo JText::sprintf('COM_EASYDISCUSS_TWITTER_SIGNED_IN_AS', $screen_name); ?> </p><?php ?> <p class="small"><a href="javascript:void(0);" onclick="discuss.login.twitter.signout();"><?php echo JText::sprintf('COM_EASYDISCUSS_TWITTER_SIGN_OUT', $screen_name); ?> </a></p><?php } } else { ?> <div><?php echo JText::_('COM_EASYDISCUSS_TWITTER_OAUTH_INTEGRATION_INCOMPLETE'); ?> </div><?php } $html = ob_get_contents(); @ob_end_clean(); return $html; }
public function setAccess($access) { $access = DiscussHelper::getRegistry($access); $this->token = new OAuthConsumer($access->get('token'), $access->get('secret')); return $this->token; }
function unsubscribe() { $my = JFactory::getUser(); $redirectLInk = 'index.php?option=com_easydiscuss&view=profile#Subscriptions'; if ($my->id == 0) { $redirectLInk = 'index.php?option=com_easydiscuss&view=index'; } //type=site - subscription type //sid=1 - subscription id //uid=42 - user id //token=0fd690b25dd9e4d2dc47a252d025dff4 - md5 subid.subdate $data = base64_decode(JRequest::getVar('data', '')); $param = DiscussHelper::getRegistry($data); $param->type = $param->get('type', ''); $param->sid = $param->get('sid', ''); $param->uid = $param->get('uid', ''); $param->token = $param->get('token', ''); $subtable = DiscussHelper::getTable('Subscribe'); $subtable->load($param->sid); $token = md5($subtable->id . $subtable->created); $paramToken = md5($param->sid . $subtable->created); if (empty($subtable->id)) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_NOT_FOUND'), 'error'); $this->setRedirect(DiscussRouter::_($redirectLInk, false)); return false; } if ($token != $paramToken) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_UNSUBSCRIBE_FAILED'), 'error'); $this->setRedirect(DiscussRouter::_($redirectLInk, false)); return false; } if (!$subtable->delete($param->sid)) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_UNSUBSCRIBE_FAILED_ERROR_DELETING_RECORDS'), 'error'); $this->setRedirect(DiscussRouter::_($redirectLInk, false)); return false; } DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_SUBSCRIPTION_UNSUBSCRIBE_SUCCESS')); $this->setRedirect(DiscussRouter::_($redirectLInk, false)); return true; }
/** * Displays the user editing form * * @since 1.0 * @access public * @return */ public function edit($tmpl = null) { require_once DISCUSS_HELPERS . '/integrate.php'; $document = JFactory::getDocument(); $mainframe = JFactory::getApplication(); $user = JFactory::getUser(); $config = DiscussHelper::getConfig(); if (empty($user->id)) { $mainframe->enqueueMessage(JText::_('COM_EASYDISCUSS_YOU_MUST_LOGIN_FIRST'), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=index')); return false; } $this->setPathway(JText::_('COM_EASYDISCUSS_PROFILE'), DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&id=' . $user->id)); $this->setPathway(JText::_('COM_EASYDISCUSS_EDIT_PROFILE')); //load porfile info and auto save into table if user is not already exist in discuss's user table. $profile = DiscussHelper::getTable('Profile'); $profile->load($user->id); $userparams = DiscussHelper::getRegistry($profile->get('params')); $siteDetails = DiscussHelper::getRegistry($profile->get('site')); $maxSize = ini_get('upload_max_filesize'); $configMaxSize = $config->get('main_upload_maxsize', 0); if ($configMaxSize > 0) { // Backend settings is MB $configMaxSize = $configMaxSize * 1024 * 1204; // We convert to bytes because the function is accepting bytes $configMaxSize = DiscussHelper::getHelper('String')->bytesToSize($configMaxSize); } $avatar_config_path = $config->get('main_avatarpath'); $avatar_config_path = rtrim($avatar_config_path, '/'); $avatar_config_path = JString::str_ireplace('/', DIRECTORY_SEPARATOR, $avatar_config_path); $croppable = false; $allowJFBCAvatarEdit = false; if ($config->get('layout_avatarIntegration') == 'default') { $original = JPATH_ROOT . '/' . rtrim($config->get('main_avatarpath'), '/') . '/' . 'original_' . $profile->avatar; if (JFile::exists($original)) { $size = getimagesize($original); $width = $size[0]; $height = $size[1]; $configAvatarWidth = $config->get('layout_avatarwidth', 160); $configAvatarHeight = $config->get('layout_avatarheight', 160); if ($width >= $configAvatarWidth && $height >= $configAvatarHeight) { $croppable = true; } } } else { if ($config->get('layout_avatarIntegration') == 'jfbconnect') { $integrate = new DiscussIntegrate(); $hasAvatar = $integrate::jfbconnect($profile); if (!$hasAvatar) { $croppable = true; $allowJFBCAvatarEdit = true; } } } $tpl = new DiscussThemes(); $tpl->set('croppable', $croppable); $tpl->set('allowJFBCAvatarEdit', $allowJFBCAvatarEdit); $tpl->set('size', $maxSize); $tpl->set('user', $user); $tpl->set('profile', $profile); $tpl->set('config', $config); $tpl->set('configMaxSize', $configMaxSize); $tpl->set('avatarIntegration', $config->get('layout_avatarIntegration', 'default')); $tpl->set('userparams', $userparams); $tpl->set('siteDetails', $siteDetails); echo $tpl->fetch('form.user.edit.php'); }
public static function setMeta() { $config = DiscussHelper::getConfig(); $db = DiscussHelper::getDBO(); $menu = JFactory::getApplication()->getMenu(); $item = $menu->getActive(); $result = new stdClass(); $result->description = $config->get('main_description'); $result->keywords = ''; $description = ''; if (is_object($item)) { $params = $item->params; if (!$params instanceof JRegistry) { $params = DiscussHelper::getRegistry($item->params); } $description = $params->get('menu-meta_description', ''); $keywords = $params->get('menu-meta_keywords', ''); if (!empty($description)) { $result->description = $description; } if (!empty($keywords)) { $result->keywords = $keywords; } } $document = JFactory::getDocument(); if (empty($result->keywords) && empty($result->description)) { // Get joomla default description. $jConfig = DiscussHelper::getJConfig(); $joomlaDesc = $jConfig->getValue('MetaDesc'); $metaDesc = $description . ' - ' . $joomlaDesc; $document->setMetadata('description', $metaDesc); } else { if (!empty($result->keywords)) { $document->setMetadata('keywords', $result->keywords); } if (!empty($result->description)) { $document->setMetadata('description', $result->description); } } }
/** * 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(); }
public function bindParams($post) { $params = DiscussHelper::getRegistry(''); foreach ($post as $key => $value) { if (preg_match('/params\\_.*/i', $key)) { if (is_array($value)) { $total = count($value); $key = str_ireplace('[]', '', $key); for ($i = 0; $i < $total; $i++) { if (!empty($value[$i])) { // Strip off all html tags from the input since we don't want to allow them to embed html codes in the fields. $value[$i] = strip_tags($value[$i]); $params->set($key . $i, $value[$i]); } } } else { $params->set($key, $value); } } } $this->params = $params->toString('INI'); }
public function grant() { $type = JRequest::getCmd('type'); $mainframe = JFactory::getApplication(); $config = DiscussHelper::getConfig(); $key = $config->get('main_autopost_' . $type . '_id'); $secret = $config->get('main_autopost_' . $type . '_secret'); $my = JFactory::getUser(); $oauth = DiscussHelper::getTable('Oauth'); $loaded = $oauth->loadByType($type); $denied = JRequest::getVar('denied', ''); $redirect = JRoute::_('index.php?option=com_easydiscuss&view=autoposting&layout=' . $type . '&step=2', false); if (!empty($denied)) { $oauth->delete(); DiscussHelper::setMessageQueue(JText::sprintf('Denied by %1s', $type), DISCUSS_QUEUE_ERROR); $this->setRedirect($redirect); return; } if (!$loaded) { JError::raiseError(500, JText::_('COM_EASYDISCUSS_AUTOPOST_UNABLE_LOCATE_REQUEST_TOKEN')); } $request = DiscussHelper::getRegistry($oauth->request_token); $callback = rtrim(JURI::root(), '/') . '/administrator/index.php?option=com_easydiscuss&controller=autoposting&task=grant&type=' . $type; $consumer = DiscussHelper::getHelper('OAuth')->getConsumer($type, $key, $secret, $callback); $verifier = $consumer->getVerifier(); if (empty($verifier)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); JError::raiseError(500, JText::_('COM_EASYDISCUSS_AUTOPOST_INVALID_VERIFIER_CODE')); } $access = $consumer->getAccess($request->get('token'), $request->get('secret'), $verifier); if (!$access || empty($access->token) || empty($access->secret)) { // Since there is a problem with the oauth authentication, we need to delete the existing record. $oauth->delete(); DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_AUTOPOST_ERROR_RETRIEVE_ACCESS'), DISCUSS_QUEUE_ERROR); $this->setRedirect($redirect); return; } $param = DiscussHelper::getRegistry(''); $param->set('token', $access->token); $param->set('secret', $access->secret); $oauth->access_token = $param->toString(); $oauth->params = $access->params; $oauth->store(); DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_AUTOPOST_ACCOUNT_ASSOCIATED_SUCCESSFULLY'), DISCUSS_QUEUE_SUCCESS); $this->setRedirect($redirect); return; }