can you please help me on this? im trying to figure out fireboard module to work with kuneba... im just changing the main compnent's direction (com_kunena to com_kunena)
i cannot make it to work... it says
Code:
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
require_once (JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'sources'.DS.'fb_config.class.php');
global $fbConfig;
$fbConfig = new fb_config();
$fbConfig->load();
require_once (JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'class.fireboard.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'sources'.DS.'fb_link.class.php');
require_once (JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'template'.DS.'default'.DS.'smile.class.php');
class modFBLatestHelper {
function getAvatar($userid, $avatar_height) {
$jspath = JPATH_BASE.DS.'components'.DS.'com_community';
include_once($jspath.DS.'libraries'.DS.'core.php');
// Get CUser object
$user =& CFactory::getUser($userid);
$avatarUrl = $user->getThumbAvatar();
$link = CRoute::_('index.php?option=com_community&view=profile&userid='.$userid);
$avatar = "<a href=\"$link\"><img class=\"hasTip\" style=\"border:1px solid #cccccc; float: left; margin: 3px 3px 3px 3px; padding:2px; height: $avatar_height;\" src=\"$avatarUrl\" alt=\"$user->name\" title=\"$user->name\" /></a>";
return $avatar;
}
function getLatestPosts($params) {
global $fbConfig, $row, $avatar_height;
$db = &JFactory::getDBO();
$user = &JFactory::getUser();
$posts = $params->get('posts', 10);
$show_pub = $params->get('show_pub', 1);
$show_reg = $params->get('show_reg', 0);
$show_spe = $params->get('show_spe', 0);
$cat_limit = $params->get('cat_limit' , 0);
$cat_child = $params->get('cat_child', 1);
$latest = $params->get('latest', 0);
$more_text = $params->get('more_text', 'More...');
$more_time = $params->get('more_time', 168);
$unread = $params->get('unread', 1);
$unread_text = $params->get('unread_text', '!');
$subject = $params->get('subject', 40);
$message = $params->get('message', 200);
$name_link = $params->get('name_link', 1);
$item_format = $params->get('item_format', '%R %S<br /><small>%N %D</small>');
$tooltip_format = $params->get('tooltip_format', '%F > %L');
$date_format = $params->get('date_format', 'j.n.Y G:i');
$avatar_height = $params->get('avatar_height', '48px');
//new indicator
if ($user->id != 0) {
$db->setQuery("SELECT * FROM #__fb_sessions WHERE userid = {$user->id}");
$session = $db->loadObjectList();
if ($session) {
$lasttime = $session[0]->lasttime;
$readtopics = $session[0]->readtopics;
} else {
$lasttime = time() - 1314000; // 1 year
$readtopics = '';
}
} else {
$lasttime = 0;
$readtopics = '';
}
// new indicator
if ($readtopics) // user have session
$sql_new = ", (m.time > $lasttime AND m.thread NOT IN ($readtopics)) AS unread";
elseif ($lasttime) // user don't have session
$sql_new = ", (m.time > $lasttime) AS unread";
else // no user
$sql_new = ", 0 AS unread";
// access levels
$i = $show_pub + 2 * $show_reg + 4 * $show_spe;
switch ($i) {
case 0: $sql_access = 'AND c.pub_access == 999999'; break;
case 1: $sql_access = 'AND c.pub_access = 0'; break;
case 2: $sql_access = 'AND c.pub_access < 0'; break;
case 3: $sql_access = 'AND c.pub_access <= 0'; break;
case 4: $sql_access = 'AND c.pub_access > 0'; break;
case 5: $sql_access = 'AND c.pub_access >= 0'; break;
case 6: $sql_access = 'AND c.pub_access != 0'; break;
default: $sql_access = '';
}
// categories
$sql_cat = '';
if ($cat_limit) {
$cats = explode(',', $cat_limit);
foreach ($cats as $i => $cat) {
$cats[$i] = (int)$cat;
if ($cat == -1)
$cats[$i] = $params->get('catid', 0);
if ($cat == 0)
unset($cats[$i]);
}
$cat_limit = implode(',', $cats);
if ($cat_limit) {
if ($cat_child)
$sql_cat = "AND (c.id IN ($cat_limit) OR c.parent IN ($cat_limit))";
else
$sql_cat = "AND c.id IN ($cat_limit)";
}
}
switch ($latest) {
case 0: // Show all posts from a thread
$query = "
SELECT l.id, l.time, l.thread, n.hits, count(m.id) AS `count`, l.subject, l.userid, l.name, l.catid, l.catname, l.unread, t.message
FROM
(SELECT m.time, m.thread, m.id, m.catid, m.userid, m.name, m.subject, c.name AS catname $sql_new
FROM #__fb_messages AS m
JOIN #__fb_categories AS c ON m.catid = c.id
WHERE c.published = 1 AND m.hold = 0 AND m.moved = 0 $sql_access $sql_cat ORDER BY m.id DESC LIMIT $posts) AS l
JOIN #__fb_messages AS m ON l.thread = m.thread
JOIN #__fb_messages AS n ON l.thread = n.id
JOIN #__fb_messages_text AS t ON l.id = t.mesid
WHERE l.time >= m.time AND m.hold = 0 AND m.moved = 0 GROUP BY l.id ORDER BY l.id DESC";
break;
case 1: // Show only first post from a thread
$query = "
SELECT m.id, m.time, m.thread, m.hits, 1 AS `count`, m.subject, m.userid, m.name, m.catid, c.name AS catname, t.message $sql_new
FROM #__fb_messages AS m
JOIN #__fb_categories AS c ON m.catid = c.id
JOIN #__fb_messages_text AS t ON m.id = t.mesid
WHERE c.published = 1 AND m.hold = 0 AND m.moved = 0 AND m.parent = 0 $sql_access $sql_cat ORDER BY m.id DESC LIMIT $posts";
break;
case 2: // Show only last post from a thread
$query = "
SELECT q.maxid AS id, m.time, m.thread, n.hits, q.countid AS `count`, m.subject, m.userid, m.name, m.catid, q.catname, t.message $sql_new
FROM
(SELECT max(m.id) AS maxid, count(m.id) AS countid, c.name AS catname
FROM #__fb_messages AS m
JOIN #__fb_categories as c ON m.catid = c.id
WHERE c.published = 1 AND m.hold = 0 AND m.moved = 0 $sql_access $sql_cat
GROUP BY m.thread ORDER BY max(m.id) DESC LIMIT $posts) AS q
JOIN #__fb_messages AS m ON q.maxid = m.id
JOIN #__fb_messages AS n ON m.thread = n.id
JOIN #__fb_messages_text AS t ON q.maxid = t.mesid
";
break;
}
$db->setQuery($query);
$rows = $db->loadObjectList();
if (!count($rows)) return;
$items = array();
foreach ($rows as $row) {
$item = '';
$item->subject = (stripslashes($row->subject)) ? stripslashes($row->subject) : 'No subject';
$item->subject_short = (JString::strlen($item->subject) > $subject) ? JString::substr($item->subject, 0, $subject - 4) . '...' : $item->subject;
$item->message = str_replace('"', '', smile::purify($row->message));
$item->message_short = (JString::strlen($item->message) > $message) ? JString::substr($item->message, 0, $message - 4) . '...' : $item->message;
//$item->postname = ($name_link > 0 && $row->userid > 0) ? fb_link::GetProfileLink($row->userid, $row->name) : $row->name;
$item->postname = ($name_link > 0 && $row->userid > 0) ? '<a href="'.JRoute::_('index.php?option=com_community&view=profile&userid='.$row->userid.'&Itemid=8').'">'.$row->name.'</a>' : $row->name;
$item->date = '<span style="white-space: nowrap">' . date($date_format, FBTools::fbGetInternalTime($row->time)) . '</span>';
$item->more = fb_link::GetShowLatestThreadsLink($more_time, $more_text, $rel='nofollow');
$s = $item_format;
$s = str_replace('%S', fb_link::GetThreadPageLink('view', $row->catid, $row->thread, ceil($row->count / $fbConfig->messages_per_page), $fbConfig->messages_per_page, $item->subject_short, $row->id), $s);
$s = str_replace('%L', fb_link::GetThreadPageLink('view', $row->catid, $row->thread, ceil($row->count / $fbConfig->messages_per_page), $fbConfig->messages_per_page, $item->subject, $row->id), $s);
$s = str_replace('%M', $item->message_short, $s);
$s = str_replace('%T', $item->message, $s);
$s = str_replace('%N', $item->postname, $s);
$s = str_replace('%D', $item->date, $s);
$s = str_replace('%F', $row->catname, $s);
$s = str_replace('%H', $row->hits, $s);
$s = str_replace('%C', $row->count - 1, $s);
$s = str_replace('%R', ($row->unread) ? $unread_text : '', $s);
$s = (strpos($s, '%A') === false) ? $s : str_replace('%A', modFBLatestHelper::getAvatar($row->userid, $avatar_height), $s);
$item->title = $s;
$s = $tooltip_format;
$s = str_replace('%S', $item->subject_short, $s);
$s = str_replace('%L', $item->subject, $s);
$s = str_replace('%M', $item->message_short, $s);
$s = str_replace('%T', $item->message, $s);
$s = str_replace('%N', $item->postname, $s);
$s = str_replace('%D', $item->date, $s);
$s = str_replace('%F', $row->catname, $s);
$s = str_replace('%H', $row->hits, $s);
$s = str_replace('%C', $row->count - 1, $s);
$s = str_replace('%R', ($row->unread) ? $unread_text : '', $s);
$item->tooltip = $s;
$items[] = $item;
}
return $items;
}
}