/components/com_jfusionplugins/phpbb3/public.php
PHP | 741 lines | 537 code | 101 blank | 103 comment | 124 complexity | c1f04e03126c40f629bb3c01c82d6970 MD5 | raw file
Possible License(s): Apache-2.0
- <?php
-
- /**
- * @package JFusion_phpBB3
- * @author JFusion development team
- * @copyright Copyright (C) 2008 JFusion. All rights reserved.
- * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
- */
- // no direct access
- defined('_JEXEC') or die('Restricted access');
-
- /**
- * JFusion Public Class for phpBB3
- * For detailed descriptions on these functions please check the model.abstractpublic.php
- * @package JFusion_phpBB3
- */
- class JFusionPublic_phpbb3 extends JFusionPublic {
-
- function getJname() {
- return 'phpbb3';
- }
-
- function getRegistrationURL() {
- return 'ucp.php?mode=register';
- }
-
- function getLostPasswordURL() {
- return 'ucp.php?mode=sendpassword';
- }
-
- function getLostUsernameURL() {
- return 'ucp.php?mode=sendpassword';
- }
-
- function getViewNewMessagesURL() {
- return 'search.php?search_id=newposts';
- }
-
- function getProfileURL($uid) {
- return 'memberlist.php?mode=viewprofile&u=' . $uid;
- }
-
- function getPrivateMessageURL() {
- return 'ucp.php?i=pm&folder=inbox';
- }
-
- function prepareText(&$text, $for = 'jfusion', $params = '', $object = '') {
- $status = array();
- if ($for == 'forum') {
- //first thing is to remove all joomla plugins
- preg_match_all('/\{(.*)\}/U', $text, $matches);
-
- //find each thread by the id
- foreach ($matches[1] AS $plugin) {
- //replace plugin with nothing
- $text = str_replace('{' . $plugin . '}', "", $text);
- }
- JFusionFunction::parseCode($text, 'bbcode');
- } elseif ($for == 'joomla' || ($for == 'activity' && $params->get('parse_text') == 'html')) {
- //remove phpbb's bbcode uids
- $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
- //encode prior to decoding as somehow it is getting added into phpBB without getting encoded
- $text = str_replace(' ', '&nbsp;', $text);
- //decode html entities
- $text = html_entity_decode($text);
-
- if (strpos($text, 'SMILIES_PATH') !== false) {
- //must convert smilies
- $db = & JFusionFactory::getDatabase($this->getJname());
- $query = "SELECT config_value FROM #__config WHERE config_name = 'smilies_path'";
- $db->setQuery($query);
- $smilie_path = $db->loadResult();
- $jfparams = & JFusionFactory::getParams($this->getJname());
- $source_url = $jfparams->get('source_url');
- $text = preg_replace('#<!-- s(.*?) --><img src="\{SMILIES_PATH\}\/(.*?)" alt="(.*?)" title="(.*?)" \/><!-- s\\1 -->#si', "<img src='{$source_url}{$smilie_path}/$2' alt='$3' />", $text);
- }
-
- //parse bbcode to html
- $options = array();
- $options['parse_smileys'] = false;
- if (!empty($params) && $params->get('character_limit', false)) {
- $status['limit_applied'] = 1;
- $options['character_limit'] = $params->get('character_limit');
- }
- JFusionFunction::parseCode($text, 'html', $options);
- } elseif ($for == 'discuss') {
- //remove phpbb's bbcode uids
- $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
- //decode html entities
- $text = html_entity_decode($text);
- } elseif ($for == 'activity' || $for == 'search') {
- $text = preg_replace("#\[(.*?):(.*?)]#si", "[$1]", $text);
- $text = html_entity_decode($text);
- if ($for == 'activity') {
- if ($params->get('parse_text') == 'plaintext') {
- $options = array();
- $options['plaintext_line_breaks'] = 'space';
- if ($params->get('character_limit')) {
- $status['limit_applied'] = 1;
- $options['character_limit'] = $params->get('character_limit');
- }
- JFusionFunction::parseCode($text, 'plaintext', $options);
- }
- } else {
- JFusionFunction::parseCode($text, 'plaintext');
- }
- }
- return $status;
- }
-
- /* * **********************************************
- * Functions For JFusion Who's Online Module
- * ********************************************* */
-
- function getOnlineUserQuery($limit, $usergroups = '') {
- $limiter = (!empty($limit)) ? "LIMIT 0,$limit" : '';
-
- $usergroup_query = '';
- if (!empty($usergroups)) {
- if (is_array($usergroups)) {
- $usergroups = implode(',', $usergroups);
- $usergroup_query .= "AND u.group_id IN ($usergroups)";
- } else {
- $usergroup_query .= "AND u.group_id = $usergroups";
- }
- }
-
- //get a unix time from 5 mintues ago
- date_default_timezone_set('UTC');
- $active = strtotime("-5 minutes", time());
-
- $query = "SELECT DISTINCT u.user_id AS userid, u.username_clean AS username, u.username AS name, u.user_email as email FROM #__users AS u INNER JOIN #__sessions AS s ON u.user_id = s.session_user_id WHERE s.session_viewonline =1 AND s.session_user_id != 1 AND s.session_time > $active $usergroup_query $limiter";
- return $query;
- }
-
- function getNumberOnlineGuests() {
- //get a unix time from 5 mintues ago
- date_default_timezone_set('UTC');
- $active = strtotime("-5 minutes", time());
-
- $db = & JFusionFactory::getDatabase($this->getJname());
- $query = "SELECT COUNT(DISTINCT(session_ip)) FROM #__sessions WHERE session_user_id = 1 AND session_time > $active";
- $db->setQuery($query);
- $result = $db->loadResult();
- return $result;
- }
-
- function getNumberOnlineMembers($usergroups = '', $total = 1) {
- //get a unix time from 5 mintues ago
- date_default_timezone_set('UTC');
- $active = strtotime("-5 minutes", time());
-
- $usergroup_query = '';
- if (!empty($usergroups) && empty($total)) {
- if (is_array($usergroups)) {
- $usergroups = implode(',', $usergroups);
- $usergroup_query .= "AND u.group_id IN ($usergroups)";
- } else {
- $usergroup_query .= "AND u.group_id = $usergroups";
- }
- }
-
- $db = & JFusionFactory::getDatabase($this->getJname());
- $query = "SELECT COUNT(DISTINCT(s.session_user_id)) FROM #__sessions AS s INNER JOIN #__users AS u ON s.session_user_id = u.user_id WHERE s.session_viewonline = 1 AND s.session_user_id != 1 AND s.session_time > $active $usergroup_query";
-
- $db->setQuery($query);
- $result = $db->loadResult();
- return $result;
- }
-
- /* * **********************************************
- * Functions For Frameless Integration
- * ********************************************* */
-
- function getBuffer(&$jfdata) {
- // Get the path
- $params = JFusionFactory::getParams($this->getJname());
- global $source_url;
- $source_url = $params->get('source_url');
- $source_path = $params->get('source_path');
-
- //get the filename
- $jfile = JRequest::getVar('jfile');
- if (!$jfile) {
- //use the default index.php
- $jfile = 'index.php';
- }
-
- //redirect for file download requests
- if ($jfile == 'file.php') {
- $url = "Location: " . $params->get('source_url') . 'download/file.php?' . $_SERVER['QUERY_STRING'];
- header($url);
- }
-
- //combine the path and filename
- if (substr($source_path, -1) == DS) {
- $index_file = $source_path . basename($jfile);
- } else {
- $index_file = $source_path . DS . basename($jfile);
- }
-
- if (!is_file($index_file)) {
- JError::raiseWarning(500, 'The path to the requested does not exist');
- $result = false;
- return $result;
- }
-
- //set the current directory to phpBB3
- chdir($source_path);
-
- /* set scope for variables required later */
- global $phpbb_root_path, $phpEx, $db, $config, $user, $auth, $cache, $template, $phpbb_hook, $module, $mode;
-
- if ($jfile == 'mcp.php') {
- //must globalize these to make sure urls are generated correctly via extra_url() in mcp.php
- global $forum_id, $topic_id, $post_id, $report_id, $user_id;
- }
-
- //see if we need to force the database to use a new connection
- if ($params->get('database_new_link', 0) && !defined('PHPBB_DB_NEW_LINK')) {
- define('PHPBB_DB_NEW_LINK', 1);
- }
-
- //define the phpBB3 hooks
- require_once(JFUSION_PLUGIN_PATH . DS . $this->getJname() . DS . 'hooks.php');
-
- // Get the output
- ob_start();
-
- //we need to hijack $_SERVER['PHP_SELF'] so that phpBB correctly utilizes it such as correctly noted the page a user is browsing
- $php_self = $_SERVER['PHP_SELF'];
- $juri = new JURI($source_url);
- $_SERVER['PHP_SELF'] = $juri->getPath() . $jfile;
-
- try {
- defined('UTF8_STRLEN') or define('UTF8_STRLEN', true);
- defined('UTF8_CORE') or define('UTF8_CORE', true);
- defined('UTF8_CASE') or define('UTF8_CASE', true);
-
- include_once($index_file);
- } catch (Exception $e) {
- $jfdata->buffer = ob_get_contents();
- ob_end_clean();
- }
-
- //restore $_SERVER['PHP_SELF']
- $_SERVER['PHP_SELF'] = $php_self;
-
- //change the current directory back to Joomla.
- chdir(JPATH_SITE);
-
- //show more smileys without the Joomla frame
- $jfmode = JRequest::getVar('mode');
- $jfform = JRequest::getVar('form');
- if ($jfmode == 'smilies' || ($jfmode == 'searchuser' && !empty($jfform) || $jfmode == 'contact')) {
- $pattern = '#<head[^>]*>(.*?)<\/head>.*?<body[^>]*>(.*)<\/body>#si';
- preg_match($pattern, $jfdata->buffer, $temp);
- $jfdata->header = $temp[1];
- $jfdata->body = $temp[2];
- $this->parseHeader($jfdata);
- $this->parseBody($jfdata);
- die('<html><head>' . $jfdata->header . '</head><body>' . $jfdata->body . '</body></html>');
- }
- }
-
- function parseBody(&$data) {
- static $regex_body, $replace_body;
-
- if (!$regex_body || !$replace_body) {
- // Define our preg arrays
- $regex_body = array();
- $replace_body = array();
-
- //fix anchors
- $regex_body[] = '#\"\#(.*?)\"#mS';
- $replace_body[] = '"' . $data->fullURL . '#$1"';
-
- //parse URLS
- $regex_body[] = '#href="\.\/(.*?)"#me';
- $replace_body[] = '$this->fixUrl("$1","' . $data->baseURL . '","' . $data->integratedURL . '")';
-
- //convert relative links from images into absolute links
- $regex_body[] = '#(src="|background="|url\(\'?)./(.*?)("|\'?\))#mS';
- $replace_body[] = '$1' . $data->integratedURL . '$2$3';
-
- //fix for form actions
- $regex_body[] = '#action="(.*?)"(.*?)>#me';
- $replace_body[] = '$this->fixAction("$1","$2","' . $data->baseURL . '")';
-
- //convert relative popup links to full url links
- $regex_body[] = '#popup\(\'\.\/(.*?)\'#mS';
- $replace_body[] = 'popup(\'' . $data->integratedURL . '$1\'';
-
- //fix for mcp links
- $jfile = JRequest::getVar('jfile');
- if ($jfile == 'mcp.php') {
- $topicid = JRequest::getInt('t');
- //fix for merge thread
- $regex_body[] = '#(&|&)to_topic_id#mS';
- $replace_body[] = '$1t=' . $topicid . '$1to_topic_id';
- $regex_body[] = '#/to_topic_id#mS';
- $replace_body[] = '/t,' . $topicid . '/to_topic_id';
- //fix for merge posts
- $regex_body[] = '#(&|&)action=merge_select#mS';
- $replace_body[] = '$1t=' . $topicid . '$1action=merge_select';
- $regex_body[] = '#/action=merge_select#mS';
- $replace_body[] = '/t,' . $topicid . '/action=merge_select';
- }
-
- //go ahead and parse any absolute links to index.php
- $regex_body[] = '#href="' . $data->integratedURL . 'index.php(.*?)"#me';
- $replace_body[] = '$this->fixUrl("index.php$1","' . $data->baseURL . '","' . $data->integratedURL . '")';
- }
- $data->body = preg_replace($regex_body, $replace_body, $data->body);
- }
-
- function fixUrl($q='', $baseURL, $integratedURL) {
- //allow for direct downloads and admincp access
- if (strstr($q, 'download/') || strstr($q, 'adm/')) {
- $url = $integratedURL . $q;
- return 'href="' . $url . '"';
- }
-
- //these are custom links that are based on modules and thus no as easy to replace as register and lost password links in the hooks.php file so we'll just parse them
- $params = & JFusionFactory::getParams($this->getJname());
- $edit_account_url = $params->get('edit_account_url');
- if (strstr($q, 'mode=reg_details') && !empty($edit_account_url)) {
- $url = $edit_account_url;
- return 'href="' . $url . '"';
- }
-
- $edit_profile_url = $params->get('edit_profile_url');
- if (!empty($edit_profile_url)) {
- if (strstr($q, 'mode=profile_info')) {
- $url = $edit_profile_url;
- return 'href="' . $url . '"';
- }
-
- static $profile_mod_id;
- if (empty($profile_mod_id)) {
- //the first item listed in the profile module is the edit profile link so must rewrite it to go to signature instead
- $db = & JFusionFactory::getDatabase($this->getJname());
- $query = "SELECT module_id FROM #__modules WHERE module_langname = 'UCP_PROFILE'";
- $db->setQuery($query);
- $profile_mod_id = $db->loadResult();
- }
- if (!empty($profile_mod_id) && strstr($q, 'i=' . $profile_mod_id)) {
- $url = 'ucp.php?i=profile&mode=signature';
- $url = JFusionFunction::routeURL($url, JRequest::getInt('Itemid'), $this->getJname());
- return 'href="' . $url . '"';
- }
- }
-
- $edit_avatar_url = $params->get('edit_avatar_url');
- if (strstr($q, 'mode=avatar') && !empty($edit_avatar_url)) {
- $url = $edit_avatar_url;
- return 'href="' . $url . '"';
- }
-
- if (substr($baseURL, -1) != '/') {
- //non-SEF mode
- $q = str_replace('?', '&', $q);
- $url = $baseURL . '&jfile=' . $q;
- } else {
- //check to see what SEF mode is selected
- $params = JFusionFactory::getParams($this->getJname());
- $sefmode = $params->get('sefmode');
- if ($sefmode == 1) {
- //extensive SEF parsing was selected
- $url = JFusionFunction::routeURL($q, JRequest::getInt('Itemid'));
- } else {
- //simple SEF mode, we can just combine both variables
- $url = $baseURL . $q;
- }
- }
- return 'href="' . $url . '"';
- }
-
- function fixRedirect($url, $baseURL) {
- //JError::raiseWarning(500, $url);
- //split up the timeout from url
- $parts = explode(';url=', $url);
- $timeout = $parts[0];
- $uri = new JURI($parts[1]);
- $jfile = $uri->getPath();
- $jfile = basename($jfile);
- $query = $uri->getQuery(false);
- $fragment = $uri->getFragment();
- if (substr($baseURL, -1) != '/') {
- //non-SEF mode
- $redirectURL = $baseURL . '&jfile=' . $jfile;
- if (!empty($query)) {
- $redirectURL .= '&' . $query;
- }
- } else {
- //check to see what SEF mode is selected
- $params = JFusionFactory::getParams($this->getJname());
- $sefmode = $params->get('sefmode');
- if ($sefmode == 1) {
- //extensive SEF parsing was selected
- $redirectURL = $jfile;
- if (!empty($query)) {
- $redirectURL .= '?' . $query;
- }
- $redirectURL = JFusionFunction::routeURL($redirectURL, JRequest::getInt('Itemid'));
- } else {
- //simple SEF mode, we can just combine both variables
- $redirectURL = $baseURL . $jfile;
- if (!empty($query)) {
- $redirectURL .= '?' . $query;
- }
- }
- }
- if (!empty($fragment)) {
- $redirectURL .= "#$fragment";
- }
- $return = '<meta http-equiv="refresh" content="' . $timeout . ';url=' . $redirectURL . '">';
- //JError::raiseWarning(500, htmlentities($return));
- return $return;
- }
-
- function fixAction($url, $extra, $baseURL) {
-
- $url = htmlspecialchars_decode($url);
- $Itemid = JRequest::getInt('Itemid');
-
- //strip any leading dots
- if (substr($url, 0, 2) == './') {
- $url = substr($url, 2);
- }
-
- if (substr($baseURL, -1) != '/') {
- //non-SEF mode
- $url_details = parse_url($url);
- $url_variables = array();
- if (!empty($url_details['query'])) {
- parse_str($url_details['query'], $url_variables);
- }
- $jfile = basename($url_details['path']);
- //set the correct action and close the form tag
- $replacement = 'action="' . $baseURL . '"' . $extra . '>';
- $replacement .= '<input type="hidden" name="jfile" value="' . $jfile . '"/>';
- $replacement .= '<input type="hidden" name="Itemid" value="' . $Itemid . '"/>';
- $replacement .= '<input type="hidden" name="option" value="com_jfusion"/>';
- } else {
- //check to see what SEF mode is selected
- $params = JFusionFactory::getParams($this->getJname());
- $sefmode = $params->get('sefmode');
- if ($sefmode == 1) {
- //extensive SEF parsing was selected
- $url = JFusionFunction::routeURL($url, $Itemid);
- $replacement = 'action="' . $url . '"' . $extra . '>';
- return $replacement;
- } else {
- //simple SEF mode
- $url_details = parse_url($url);
- $url_variables = array();
- if (!empty($url_details['query'])) {
- parse_str($url_details['query'], $url_variables);
- }
- $jfile = basename($url_details['path']);
- $replacement = 'action="' . $baseURL . $jfile . '"' . $extra . '>';
- }
- }
- unset($url_variables['option'], $url_variables['jfile'], $url_variables['Itemid']);
-
- //add any other variables
- if (is_array($url_variables)) {
- foreach ($url_variables as $key => $value) {
- $replacement .= '<input type="hidden" name="' . $key . '" value="' . $value . '"/>';
- }
- }
- return $replacement;
- }
-
- function parseHeader(&$data) {
- static $regex_header, $replace_header;
-
- if (!$regex_header || !$replace_header) {
- // Define our preg arrays
- $regex_header = array();
- $replace_header = array();
-
- //convert relative links into absolute links
- $regex_header[] = '#(href="|src=")./(.*?")#mS';
- $replace_header[] = '$1' . $data->integratedURL . '$2';
-
- //fix for URL redirects
- $regex_header[] = '#<meta http-equiv="refresh" content="(.*?)"(.*?)>#me';
- $replace_header[] = '$this->fixRedirect("$1","' . $data->baseURL . '")';
-
- //fix pm popup URL to be absolute for some phpBB templates
- $regex_header[] = "#var url = '\.\/(.*?)';#mS";
- $replace_header[] = "var url = '{$data->integratedURL}$1';";
-
- //convert relative popup links to full url links
- $regex_header[] = '#popup\(\'\.\/(.*?)\'#mS';
- $replace_header[] = 'popup(\'' . $data->integratedURL . '$1\'';
- }
- $data->header = preg_replace($regex_header, $replace_header, $data->header);
- }
-
- function parseRoute(&$vars) {
- foreach ($vars as $k => $v) {
- //must undo Joomla's parsing that changes dashes to colons so that PM browsing works correctly
- if ($k == 'f') {
- $vars[$k] = str_replace(':', '-', $v);
- } elseif ($k == 'redirect') {
- $vars[$k] = base64_decode($v);
- }
- }
- }
-
- function buildRoute(&$segments) {
- if (is_array($segments)) {
- foreach ($segments as $k => $v) {
- if (strstr($v, 'redirect,./')) {
- //need to encode the redirect to prevent issues with SEF
- $url = substr($v, 9);
- $segments[$k] = 'redirect,' . base64_encode($url);
- }
- }
- }
- }
-
- function getPathway() {
- $mainframe = &JFactory::getApplication('site');
- $db =& JFusionFactory::getDatabase($this->getJname());
- $pathway = array();
-
- $forum_id = JRequest::getInt('f');
- if (!empty($forum_id)) {
- //get the forum's info
- $query = "SELECT forum_name, parent_id, left_id, right_id, forum_parents FROM #__forums WHERE forum_id = $forum_id";
- $db->setQuery($query);
- $forum_info = $db->loadObject();
-
- //get forum parents
- $query = "SELECT forum_id, forum_name FROM #__forums WHERE left_id < {$forum_info->left_id} AND right_id > {$forum_info->right_id} ORDER BY left_id ASC";
- $db->setQuery($query);
- $forum_parents = $db->loadObjectList();
-
- if (!empty($forum_parents)) {
- foreach ($forum_parents as $k => $data) {
- $crumb = new stdClass();
- $crumb->title = $data->forum_name;
- $crumb->url = "viewforum.php?f={$data->forum_id}";
- $pathway[] = $crumb;
- }
- }
-
- $crumb = new stdClass();
- $crumb->title = $forum_info->forum_name;
- $crumb->url = "viewforum.php?f=" . $forum_id;
- $pathway[] = $crumb;
- }
-
- $topic_id = JRequest::getInt('t');
- if (!empty($topic_id)) {
- $query = "SELECT topic_title FROM #__topics WHERE topic_id = $topic_id";
- $db->setQuery($query);
- $topic_title = $db->loadObject();
-
- $crumb = new stdClass();
- $crumb->title = $topic_title->topic_title;
- $crumb->url = "viewtopic.php?f=$forum_id&t=$topic_id";
- $pathway[] = $crumb;
- }
-
- return $pathway;
- }
-
- function getAvatar($puser_id) {
- if ($puser_id) {
-
- $dbparams = JFusionFactory::getParams($this->getJname());
- $db = JFusionFactory::getDatabase($this->getJname());
-
- $db->setQuery('SELECT user_avatar, user_avatar_type FROM #__users WHERE user_id=' . $puser_id);
- $db->query();
- $result = $db->loadObject();
-
- if (!empty($result)) {
- if ($result->user_avatar_type == 1) {
- // AVATAR_UPLOAD
- $url = $dbparams->get('source_url') . 'download/file.php?avatar=' . $result->user_avatar;
- } else if ($result->user_avatar_type == 3) {
- // AVATAR_GALLERY
- $db->setQuery("SELECT config_value FROM #__config WHERE config_name='avatar_gallery_path'");
- $db->query();
- $path = $db->loadResult();
- if (!empty($path)) {
- $url = $dbparams->get('source_url') . $path . '/' . $result->user_avatar;
- } else {
- $url = '';
- }
- } else if ($result->user_avatar_type == 2) {
- // AVATAR REMOTE URL
- $url = $result->user_avatar;
- } else {
- $url = '';
- }
- return $url;
- }
- }
- return 0;
- }
-
- function getPrivateMessageCounts($puser_id) {
-
- if ($puser_id) {
-
- // read pm counts
- $db = JFusionFactory::getDatabase($this->getJname());
-
- // read unread count
- $db->setQuery('SELECT COUNT(msg_id)
- FROM #__privmsgs_to
- WHERE pm_unread = 1
- AND folder_id <> -2
- AND user_id = ' . $puser_id);
- $unreadCount = $db->loadResult();
-
- // read total pm count
- $db->setQuery('SELECT COUNT(msg_id)
- FROM #__privmsgs_to
- WHERE folder_id NOT IN (-1, -2)
- AND user_id = ' . $puser_id);
- $totalCount = $db->loadResult();
-
- return array('unread' => $unreadCount, 'total' => $totalCount);
- }
- return array('unread' => 0, 'total' => 0);
- }
-
- function getActivityQuery($usedforums, $result_order, $result_limit) {
- //filter forums based on user permissions
- $forum = & JFusionFactory::getForum($this->getJname());
- $forumids = $forum->filterForumList($usedforums);
- if (empty($forumids)) {
- $forumids = array(0);
- }
- $where = ' WHERE a.forum_id IN (' . implode(',', $forumids) . ') AND a.topic_approved = 1 AND b.post_approved = 1';
- $end = $result_order . " LIMIT 0," . $result_limit;
-
- $numargs = func_num_args();
- if ($numargs > 3) {
- $db = & JFusionFactory::getDatabase($this->getJname());
- $filters = func_get_args();
- $i = 3;
- for ($i = 3; $i < $numargs; $i++) {
- if ($filters[$i][0] == 'userid') {
- $where.= ' HAVING userid = ' . $db->Quote($filters[$i][1]);
- }
- }
- }
-
- $query = array(
- //LAT with first post info
- LAT . '0' => "SELECT a.topic_id AS threadid, a.topic_first_post_id AS postid, a.topic_first_poster_name AS name, CASE WHEN b.poster_id = 1 AND a.topic_first_poster_name != '' THEN a.topic_first_poster_name ELSE c.username_clean END as username, a.topic_poster AS userid, CASE WHEN b.poster_id = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, a.topic_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_first_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_last_post_time $end",
- //LAT with latest post info
- LAT . '1' => "SELECT a.topic_id AS threadid, a.topic_last_post_id AS postid, a.topic_last_poster_name AS name, CASE WHEN b.poster_id = 1 AND a.topic_last_poster_name != '' THEN a.topic_last_poster_name ELSE c.username_clean END as username, a.topic_last_poster_id AS userid, CASE WHEN a.topic_last_poster_id = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, a.topic_last_post_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_last_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_last_post_time $end",
- //LCT
- LCT => "SELECT a.topic_id AS threadid, a.topic_first_post_id AS postid, a.topic_first_poster_name AS name, CASE WHEN a.topic_poster = 1 AND a.topic_first_poster_name != '' THEN a.topic_first_poster_name ELSE c.username_clean END as username, a.topic_poster AS userid, CASE WHEN a.topic_poster = 1 THEN 1 ELSE 0 END AS guest, a.topic_title AS subject, b.post_text AS body, a.topic_time AS dateline, a.forum_id as forum_specific_id, a.topic_last_post_time as last_post_dateline FROM `#__topics` as a INNER JOIN `#__posts` as b ON a.topic_first_post_id = b.post_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY a.topic_time $end",
- //LCP
- LCP => "SELECT b.topic_id AS threadid, b.post_id AS postid, CASE WHEN b.poster_id = 1 AND b.post_username!='' THEN b.post_username ELSE c.username END AS name, CASE WHEN b.poster_id = 1 AND b.post_username != '' THEN b.post_username ELSE c.username_clean END as username, b.poster_id AS userid, CASE WHEN b.poster_id = 1 THEN 1 ELSE 0 END AS guest, b.post_subject AS subject, b.post_text AS body, b.post_time AS dateline, b.post_time as last_post_dateline, b.forum_id as forum_specific_id FROM `#__topics` as a INNER JOIN `#__posts` AS b ON a.topic_id = b.topic_id INNER JOIN `#__users` AS c ON b.poster_id = c.user_id $where ORDER BY b.post_time $end");
-
- return $query;
- }
-
- /* * **********************************************
- * For JFusion Search Plugin
- * ********************************************* */
-
- function getSearchQueryColumns() {
- $columns = new stdClass();
- $columns->title = "p.post_subject";
- $columns->text = "p.post_text";
- return $columns;
- }
-
- function getSearchQuery(&$pluginParam) {
- //need to return threadid, postid, title, text, created, section
- $query = 'SELECT p.topic_id, p.post_id, p.forum_id, CASE WHEN p.post_subject = "" THEN CONCAT("Re: ",t.topic_title) ELSE p.post_subject END AS title, p.post_text AS text,
- FROM_UNIXTIME(p.post_time, "%Y-%m-%d %h:%i:%s") AS created,
- CONCAT_WS( "/", f.forum_name, t.topic_title ) AS section,
- t.topic_views AS hits
- FROM #__posts AS p
- INNER JOIN #__topics AS t ON t.topic_id = p.topic_id
- INNER JOIN #__forums AS f on f.forum_id = p.forum_id';
- return $query;
- }
- function getSearchCriteria(&$where, &$pluginParam, $ordering) {
- $where.= " AND p.post_approved = 1";
- $forum = & JFusionFactory::getForum($this->getJname());
- if ($pluginParam->get('forum_mode', 0)) {
- $selected_ids = $pluginParam->get('selected_forums', array());
- $forumids = $forum->filterForumList($selected_ids);
- } else {
- $db = & JFusionFactory::getDatabase($this->getJname());
- //no forums were selected so pull them all then filter
- $query = "SELECT forum_id FROM #__forums WHERE forum_type = 1 ORDER BY left_id";
- $db->setQuery($query);
- $forumids = $db->loadResultArray();
- $forumids = $forum->filterForumList($forumids);
- }
- if (empty($forumids)) {
- $forumids = array(0);
- }
- //determine how to sort the results which is required for accurate results when a limit is placed
- switch ($ordering) {
- case 'oldest':
- $sort = 'p.post_time ASC';
- break;
- case 'category':
- $sort = 'section ASC';
- break;
- case 'popular':
- $sort = 't.topic_views DESC, p.post_time DESC';
- case 'alpha':
- $sort = 'title ASC';
- break;
- case 'newest':
- default:
- $sort = 'p.post_time DESC';
- break;
- }
- $where.= " AND p.forum_id IN (" . implode(',', $forumids) . ") ORDER BY $sort";
- }
-
- function filterSearchResults(&$results, &$pluginParam) {
-
- }
-
- function getSearchResultLink($post) {
- $forum = JFusionFactory::getForum($this->getJname());
- return $forum->getPostURL($post->topic_id, $post->post_id);
- }
-
- }
-