?
Path : /home/admin/public_html/old/modules/mod_kunenalatest/ |
Current File : /home/admin/public_html/old/modules/mod_kunenalatest/helper.php |
<?php // no direct access defined('_JEXEC') or die('Restricted access'); if (file_exists(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.defines.php')) { require_once(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.defines.php'); } include_once(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.debug.php'); require_once(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.config.class.php'); global $fbConfig; $fbConfig = new CKunenaConfig(); $fbConfig->load(); require_once(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'class.kunena.php'); require_once(JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'kunena.link.class.php'); if (file_exists(KUNENA_ABSTMPLTPATH.DS.'smile.class.php')) { require_once(KUNENA_ABSTMPLTPATH.DS.'smile.class.php'); } else { require_once(KUNENA_PATH_TEMPLATE_DEFAULT .DS. 'smile.class.php'); } require_once(JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_kunena'.DS.'lib'.DS.'fx.upgrade.class.php'); if (file_exists(KUNENA_ABSTMPLTPATH.DS.'icons.php')) { include_once (KUNENA_ABSTMPLTPATH.DS.'icons.php'); } else { include_once (JPATH_SITE.DS.'components'.DS.'com_kunena'.DS.'template'.DS.'default'.DS.'icons.php'); } class modKunenaLatestHelper { function getAvatar($userid, $avatar_height) { global $fbConfig; $db = &JFactory::getDBO(); switch ($fbConfig->avatar_src) { case 'jomsocial': $user = &CFactory::getUser($userid); $msg_avatar = $user->getThumbAvatar(); break; case 'clexuspm': $msg_avatar = MyPMSTools::getAvatarLinkWithID($userid); break; case 'cb': $db->setQuery("SELECT avatar FROM #__comprofiler WHERE user_id=$userid AND avatarapproved=1"); $avatar = $db->loadResult(); if ($avatar) { $avatar = (strpos($avatar, 'gallery/') === false) ? 'tn' . $avatar : $avatar; $msg_avatar = KUNENA_JLIVEURL . "/images/comprofiler/$avatar"; } else { $msg_avatar = KUNENA_JLIVEURL . '/components/com_comprofiler/plugin/language/default_language/images/tnnophoto.jpg'; } break; default: $db->setQuery("SELECT avatar FROM #__fb_users WHERE userid = $userid"); $avatar = $db->loadResult(); $avatar = ($avatar) ? $avatar : 's_nophoto.jpg'; $msg_avatar = KUNENA_LIVEUPLOADEDPATH . "/avatars/$avatar"; } return "<span class=\"fb_avatar\"><img style=\"float: left; margin: 3px 3px 3px 3px; height: $avatar_height; width: auto\" src=\"$msg_avatar\" alt=\"\" /></span>"; } function getOnlineStatus($userid, $params) { global $fbConfig; $db = &JFactory::getDBO(); $online = $params->get('online', 'online'); $offline = $params->get('offline', 'offline'); $db->setQuery("SELECT count(userid) FROM #__session WHERE userid=$userid"); if ($db->loadResult()) { return $online; } else { return $offline; }; } function getLatestPosts($params) { global $fbConfig; $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_nolimit = $params->get('cat_nolimit' , 0); $cat_child = $params->get('cat_child', 1); $latest = $params->get('latest', 0); $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 false'; break; case 1: $sql_access = 'AND c.pub_access in (0,1)'; break; case 2: $sql_access = 'AND c.pub_access in (-1,18)'; break; case 3: $sql_access = 'AND c.pub_access in (0,1,-1,18)'; break; case 4: $sql_access = 'AND c.pub_access in (19,20,21)'; break; case 5: $sql_access = 'AND c.pub_access in (0,1,19,20,21)'; break; case 6: $sql_access = 'AND c.pub_access in (-1,18,19,20,21)'; 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)"; } } if ($cat_nolimit) { $cats = explode(',', $cat_nolimit); foreach ($cats as $i => $cat) { $cats[$i] = (int)$cat; if ($cat == 0) unset($cats[$i]); } $cat_nolimit = implode(',', $cats); if ($cat_nolimit) { if ($cat_child) $sql_cat .= " AND (c.id NOT IN ($cat_nolimit) AND c.parent NOT IN ($cat_nolimit))"; else $sql_cat .= " AND c.id NOT IN ($cat_nolimit)"; } } 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 maxid 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) ? CKunenaLink::GetProfileLink($fbConfig, $row->userid, $row->name) : $row->name; $item->date = '<span style="white-space: nowrap">' . date($date_format, $row->time) . '</span>'; $s = $item_format; $s = str_replace('%S', CKunenaLink::GetThreadPageLink($fbConfig, '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', CKunenaLink::GetThreadPageLink($fbConfig, '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', modKunenaLatestHelper::getAvatar($row->userid, $avatar_height), $s); $s = (strpos($s, '%O') === false) ? $s : str_replace('%O', modKunenaLatestHelper::getOnlineStatus($row->userid, $params), $s); $s = str_replace('title=""', '', $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', $row->name, $s); $s = str_replace('%D', date($date_format, $row->time), $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, '%O') === false) ? $s : str_replace('%O', modKunenaLatestHelper::getOnlineStatus($row->userid, $params), $s); $item->tooltip = $s; $items[] = $item; } return $items; } function getMoreLink($params) { $more_text = $params->get('more_text', 'More...'); $more_time = $params->get('more_time', 168); return CKunenaLink::GetSefHrefLink(KUNENA_LIVEURLREL.'&func=latest&do=show&sel=' . $more_time, $more_text, '', 'nofollow', 'readon'); } }