getTemplate()); define('KUNENA_JTEMPLATEURL', KUNENA_JLIVEURL. "templates/".$app->getTemplate()); global $kunena_my; require_once (KUNENA_PATH_LIB .DS. "kunena.config.class.php"); $document =& JFactory::getDocument(); $fbConfig =& CKunenaConfig::getInstance(); $kunena_db = &JFactory::getDBO(); $kunena_my = &JFactory::getUser(); /** *@desc Getting the correct Itemids, for components required */ $Itemid = JRequest::getInt('Itemid', 0, 'REQUEST'); //check if we have all the itemid sets. if so, then no need for DB call if (!defined("KUNENA_COMPONENT_ITEMID")) { $kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_kunena' AND published='1'"); $Itemid = $kunena_db->loadResult(); if ($Itemid < 1) { $Itemid = 0; } define("KUNENA_COMPONENT_ITEMID", (int)$Itemid); define("KUNENA_COMPONENT_ITEMID_SUFFIX", "&Itemid=" . KUNENA_COMPONENT_ITEMID); //JomSocial if ($fbConfig->pm_component == 'jomsocial' || $fbConfig->fb_profile == 'jomsocial' || $fbConfig->avatar_src == 'jomsocial') { // Only proceed if jomSocial is really installed if ( file_exists( KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/core.php' ) ) { $kunena_db->setQuery("SELECT id FROM #__menu WHERE link LIKE 'index.php?option=com_community%' AND published='1' LIMIT 1"); $JOMSOCIAL_Itemid = $kunena_db->loadResult(); check_dberror('Unable to load jomSocial item id'); define("KUNENA_JOMSOCIAL_ITEMID", (int)$JOMSOCIAL_Itemid); define("KUNENA_JOMSOCIAL_ITEMID_SUFFIX", "&Itemid=" . KUNENA_JOMSOCIAL_ITEMID); // Prevent JomSocial from loading their jquery library - we got one loaded already define( 'C_ASSET_JQUERY', 1 ); include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/core.php'); include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/messaging.php'); //PM popup requires JomSocial css to be loaded from selected template $config =& CFactory::getConfig(); $document->addStyleSheet(KUNENA_JLIVEURL.'components/com_community/assets/window.css'); $document->addStyleSheet(KUNENA_JLIVEURL.'components/com_community/templates/'.$config->get('template').'/css/style.css'); } else { // JomSocial not present reset config settings to avoid problems $fbConfig->pm_component = $fbConfig->pm_component == 'jomsocial' ? 'none' : $fbConfig->pm_component; $fbConfig->fb_profile = $fbConfig->fb_profile == 'jomsocial' ? 'kunena' : $fbConfig->fb_profile; $fbConfig->avatar_src = $fbConfig->avatar_src == 'jomsocial' ? 'kunena' : $fbConfig->avatar_src; // Do not save new config - thats a task for the backend // This is just a catch all in case it is not present } } //Community Builder 1.2 integration if ($fbConfig->pm_component == 'cb' || $fbConfig->fb_profile == 'cb' || $fbConfig->avatar_src == 'cb') { // Get Community Builder compability require_once (KUNENA_PATH_LIB .DS. "kunena.communitybuilder.php"); global $kunenaProfile; $kunenaProfile =& CkunenaCBProfile::getInstance(); } //Clexus PM if ($fbConfig->pm_component == 'clexuspm' || $fbConfig->fb_profile == 'clexuspm') { $kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_mypms' AND published='1'"); $CPM_Itemid = $kunena_db->loadResult(); check_dberror('Unable to load Clexus item id'); define("KUNENA_CPM_ITEMID", (int)$CPM_Itemid); define("KUNENA_CPM_ITEMID_SUFFIX", "&Itemid=" . KUNENA_CPM_ITEMID); } // UddeIM if ($fbConfig->pm_component == 'uddeim') { $kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_uddeim' AND published='1'"); $UIM_itemid = $kunena_db->loadResult(); check_dberror('Unable to load uddeim item id'); define("KUNENA_UIM_ITEMID", (int)$UIM_itemid); define("KUNENA_UIM_ITEMID_SUFFIX", "&Itemid=" . KUNENA_UIM_ITEMID); } // MISSUS if ($fbConfig->pm_component == 'missus') { $kunena_db->setQuery("SELECT id FROM #__menu WHERE link='index.php?option=com_missus' AND published='1'"); $MISSUS_itemid = $kunena_db->loadResult(); check_dberror('Unable to load missus item id'); define("KUNENA_MISSUS_ITEMID", (int)$MISSUS_itemid); define("KUNENA_MISSUS_ITEMID_SUFFIX", "&Itemid=" . KUNENA_MISSUS_ITEMID); } // PROFILE LINK if ($fbConfig->fb_profile == "jomsocial") { $profilelink = 'index.php?option=com_community&view=profile&userid='; define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_community&view=profile&Itemid=" . KUNENA_JOMSOCIAL_ITEMID . "&userid="); } else if ($fbConfig->fb_profile == "cb") { $profilelink = 'index.php?option=com_comprofiler&task=userProfile&user='; define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_comprofiler&task=userProfile" . KUNENA_CB_ITEMID_SUFFIX . "&user="); } else if ($fbConfig->fb_profile == "clexuspm") { $profilelink = 'index.php?option=com_mypms&task=showprofile&user='; define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_mypms&task=showprofile&Itemid=" . KUNENA_CPM_ITEMID . "&user="); } else { $profilelink = 'index.php?option=com_kunena&func=fbprofile&userid='; define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_kunena&func=fbprofile&Itemid=" . KUNENA_COMPONENT_ITEMID . "&userid="); } } /* _\|/_ (o o) +----oOO-{_}-OOo--------------------------------+ | Now we have the components Itemids everywhere | | Please use these constants where ever needed | +----------------------------------------------*/ // Kunena live url define('KUNENA_LIVEURL', KUNENA_JLIVEURL . 'index.php?option=com_kunena' . KUNENA_COMPONENT_ITEMID_SUFFIX); define('KUNENA_CLEANLIVEURL', KUNENA_JLIVEURL . 'index2.php?option=com_kunena&no_html=1' . KUNENA_COMPONENT_ITEMID_SUFFIX); define('KUNENA_LIVEURLREL', 'index.php?option=com_kunena' . KUNENA_COMPONENT_ITEMID_SUFFIX); // Kunena souces absolute path define('KUNENA_DIRECTURL', KUNENA_JLIVEURL . 'components/com_kunena/'); // Kunena direct url define('KUNENA_URLSOURCESPATH', KUNENA_DIRECTURL . 'lib/'); if (!defined("KUNENA_JCSSURL")) { $kunena_db->setQuery("SELECT template FROM #__templates_menu WHERE client_id='0'"); $current_stylesheet = $kunena_db->loadResult(); define('KUNENA_JCSSURL', KUNENA_JLIVEURL . 'templates/' . $current_stylesheet . '/css/template_css.css'); } // Kunena uploaded files directory define('KUNENA_LIVEUPLOADEDPATH', KUNENA_JLIVEURL . 'images/fbfiles'); // now continue with other paths $fb_user_template = JRequest::getString('fb_user_template', '', 'COOKIE'); $fb_user_img_template = JRequest::getString('fb_user_img_template', '', 'COOKIE'); // don't allow directory travelling $fb_user_template = strtr($fb_user_template, '\\/', ''); $fb_user_img_template = strtr($fb_user_template, '\\/', ''); if (strlen($fb_user_template) > 0 && file_exists(KUNENA_PATH_TEMPLATE .DS. $fb_user_template)) { $fb_cur_template = $fb_user_template; } else if (file_exists(KUNENA_PATH_TEMPLATE .DS. $fbConfig->template)) { $fb_cur_template = $fbConfig->template; } else { $fb_cur_template = 'default_ex'; } if (strlen($fb_user_img_template) > 0 && file_exists(KUNENA_PATH_TEMPLATE .DS. $fb_user_template .DS. 'images')) { $fb_cur_img_template = $fb_user_img_template; } else if (file_exists(KUNENA_PATH_TEMPLATE .DS. $fbConfig->templateimagepath .DS. 'images')) { $fb_cur_img_template = $fbConfig->templateimagepath; } else { $fb_cur_img_template = 'default_ex'; } // only for preview module - maybe used later by users to change template define('KUNENA_ABSTMPLTPATH', KUNENA_PATH_TEMPLATE .DS. $fb_cur_template); define('KUNENA_ABSTMPLTMAINIMGPATH', KUNENA_PATH_TEMPLATE .DS. $fb_cur_img_template); // IMAGES ABSOLUTE PATH if (is_dir(KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. KUNENA_LANGUAGE) .DS) { define('KUNENA_ABSIMAGESPATH', KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. KUNENA_LANGUAGE .DS); } else { define('KUNENA_ABSIMAGESPATH', KUNENA_ABSTMPLTMAINIMGPATH .DS. 'images' .DS. 'english' .DS); } // absolute images path define('KUNENA_ABSICONSPATH', KUNENA_ABSIMAGESPATH . 'icons/'); // absolute icons path define('KUNENA_ABSEMOTIONSPATH', KUNENA_ABSIMAGESPATH . 'emoticons/'); // absolute emoticons path define('KUNENA_ABSGRAPHPATH', KUNENA_ABSIMAGESPATH . 'graph/'); // absolute graph path define('KUNENA_ABSRANKSPATH', KUNENA_ABSIMAGESPATH . 'ranks/'); // absolute ranks path define('KUNENA_ABSCATIMAGESPATH', KUNENA_PATH_UPLOADED .DS. $fbConfig->catimagepath); // Kunena category images absolute path define('KUNENA_TMPLTURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/"); define('KUNENA_TMPLTMAINIMGURL', KUNENA_DIRECTURL . "template/{$fb_cur_img_template}/"); // IMAGES URL PATH define('KUNENA_TMPLTCSSURL', KUNENA_TMPLTURL . 'kunena.forum.css'); if (is_dir(KUNENA_ABSTMPLTMAINIMGPATH . '/images/' . KUNENA_LANGUAGE)) { define('KUNENA_URLIMAGESPATH', KUNENA_TMPLTMAINIMGURL . 'images/' .KUNENA_LANGUAGE. '/'); } else { define('KUNENA_URLIMAGESPATH', KUNENA_TMPLTMAINIMGURL . 'images/english/'); } // url images path define('KUNENA_URLICONSPATH', KUNENA_URLIMAGESPATH . 'icons/'); // url icons path define('KUNENA_URLEMOTIONSPATH', KUNENA_URLIMAGESPATH . 'emoticons/'); // url emoticons path define('KUNENA_URLGRAPHPATH', KUNENA_URLIMAGESPATH . 'graph/'); // url graph path define('KUNENA_URLRANKSPATH', KUNENA_URLIMAGESPATH . 'ranks/'); // url ranks path define('KUNENA_URLCATIMAGES', KUNENA_LIVEUPLOADEDPATH ."/{$fbConfig->catimagepath}/"); // Kunena category images direct url if (file_exists(KUNENA_ABSTMPLTPATH .DS. 'js' .DS. 'jquery-1.3.2.min.js')) { define('KUNENA_JQURL', KUNENA_DIRECTURL . 'template/' . $fb_cur_template . '/js/jquery-1.3.2.min.js'); } else { define('KUNENA_JQURL', KUNENA_DIRECTURL . 'template/default/js/jquery-1.3.2.min.js'); } if (file_exists(KUNENA_ABSTMPLTPATH .DS. 'js' .DS. 'kunenaforum.js')) { define('KUNENA_COREJSPATH', '/components/com_kunena/template/' . $fb_cur_template . '/js/kunenaforum.js'); define('KUNENA_COREJSURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/js/kunenaforum.js"); } else { define('KUNENA_COREJSPATH', '/components/com_kunena/template/default/js/kunenaforum.js'); define('KUNENA_COREJSURL', KUNENA_DIRECTURL . 'template/default/js/kunenaforum.js'); } function KUNENA_fmodReplace($x, $y) { //function provided for older PHP versions which do not have an fmod function yet $i = floor($x / $y); // r = x - i * y return $x - $i * $y; } function KUNENA_check_image_type(&$type) { switch ($type) { case 'jpeg': case 'pjpeg': case 'jpg': case 'JPEG': case 'PJPEG': case 'JPG': return '.jpg'; break; case 'gif': case 'GIF': return '.gif'; break; case 'png': case 'PNG': return '.png'; break; } return false; } function getFBGroupName($id) { $kunena_db = &JFactory::getDBO(); $gr = ''; $kunena_db->setQuery("SELECT id, title FROM #__fb_groups AS g, #__fb_users as u WHERE u.group_id=g.id and u.userid='{$id}'"); $gr = $kunena_db->loadObject(); if ($gr == NULL) { $gr = new stdClass(); $gr->id = 0; $gr->title = _VIEW_VISITOR; } return $gr; } class CKunenaTools { var $id = null; /* function fbGetCurrentTime () { // tells current FB internal representing time $fbConfig =& CKunenaConfig::getInstance(); return time() + ($fbConfig->board_ofset * 3600); } */ function fbGetInternalTime ($time=null) { // tells internal FB representing time from UTC $time $fbConfig =& CKunenaConfig::getInstance(); // Prevent zeroes if($time===0) { return 0; } if($time===null) { $time = time(); } return $time + ($fbConfig->board_ofset * 3600); } function fbGetShowTime ($time=null, $space='FB') { // converts internal (FB)|UTC representing time to display time // could consider user properties (zones) for future $kunena_db = &JFactory::getDBO(); $fbConfig =& CKunenaConfig::getInstance(); // Prevent zeroes if($time===0) { return 0; } if($time===null) { $time = CKunenaTools::fbGetInternalTime(); $space = 'FB'; } if($space=='UTC') { return $time + ($fbConfig->board_ofset * 3600); } return $time; } function whoisID($id) { $kunena_db = &JFactory::getDBO(); $id = intval($kunena_db->getEscaped($id)); $kunena_db->setQuery("SELECT username, id FROM #__users WHERE id='{$id}'"); return $kunena_db->loadResult(); } function reCountBoards() { $kunena_db = &JFactory::getDBO(); include_once (KUNENA_PATH_LIB .DS. 'kunena.db.iterator.class.php'); //reset all stats to 0 $kunena_db->setQuery("UPDATE `#__fb_categories` SET `id_last_msg`='0',`time_last_msg`='0',`numTopics`='0',`numPosts`='0'"); $kunena_db->query(); check_dberror("Unable to update categories."); $kunena_db->setQuery("SELECT id, time, parent, catid FROM #__fb_messages WHERE hold='0' AND moved='0' ORDER BY id ASC"); $messages_iter = new fb_DB_Iterator($kunena_db); check_dberror("Unable to load messages."); $kunena_db->setQuery("SELECT id, parent, numTopics, numPosts,id_last_msg, time_last_msg FROM #__fb_categories ORDER BY id ASC"); $cats = $kunena_db->loadObjectList(); check_dberror("Unable to load messages."); foreach ($cats as $c) { $ctg[$c->id] = $c; } $i=0; while ($messages_iter->loadNextObject($l)) { $i++; $cat_l = $l->catid; while ($cat_l) { if ($l->parent == 0) { $ctg[$cat_l]->numTopics++; } else { $ctg[$cat_l]->numPosts++; } $ctg[$cat_l]->id_last_msg = $l->id; $ctg[$cat_l]->time_last_msg = $l->time; $cat_l = $ctg[$cat_l]->parent; } } // now back to db foreach ($ctg as $cc) { $kunena_db->setQuery( "UPDATE `#__fb_categories` SET `time_last_msg`='" . $cc->time_last_msg . "',`id_last_msg`='" . $cc->id_last_msg . "',`numTopics`='" . $cc->numTopics . "',`numPosts`='" . $cc->numPosts . "' WHERE (`id`='" . $cc->id . "') "); $kunena_db->query(); echo $kunena_db->getErrorMsg(); } $messages_iter->Free(); } function updateNameInfo() { $kunena_db = &JFactory::getDBO(); $fbConfig =& CKunenaConfig::getInstance(); $fb_queryName = $fbConfig->username ? "username" : "name"; $query = "UPDATE #__fb_messages AS m, #__users AS u SET m.name = u.$fb_queryName WHERE m.userid = u.id"; $kunena_db->setQuery($query); $kunena_db->query(); check_dberror ("Unable to update user name information"); } function modifyCategoryStats($msg_id, $msg_parent, $msg_time, $msg_cat) { $kunena_db = &JFactory::getDBO(); $kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories ORDER BY id ASC"); $cats = $kunena_db->loadObjectList(); check_dberror("Unable to load categories."); foreach ($cats as $c) { $ctg[$c->id] = $c; } while ($msg_cat) { // traverse parental from orig msg_cat if ($msg_parent == 0) { $ctg[$msg_cat]->numTopics++; } else { $ctg[$msg_cat]->numPosts++; } $ctg[$msg_cat]->id_last_msg = $msg_id; $ctg[$msg_cat]->time_last_msg = $msg_time; // store to db (only changed) $kunena_db->setQuery( "UPDATE `#__fb_categories`" ." SET `time_last_msg`='" . $ctg[$msg_cat]->time_last_msg . "'" .",`id_last_msg`='" . $ctg[$msg_cat]->id_last_msg . "'" .",`numTopics`='" . $ctg[$msg_cat]->numTopics . "'" .",`numPosts`='" . $ctg[$msg_cat]->numPosts . "'" ." WHERE (`id`='" . $ctg[$msg_cat]->id . "') "); $kunena_db->query(); echo $kunena_db->getErrorMsg(); // parent $msg_cat = $ctg[$msg_cat]->parent; } return; } function decreaseCategoryStats($msg_id, $msg_cat) { //topic : 1 , message = 0 $kunena_db = &JFactory::getDBO(); $kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories ORDER BY id ASC"); $cats = $kunena_db->loadObjectList(); check_dberror("Unable to load categories."); foreach ($cats as $c) { $ctg[$c->id] = $c; } $kunena_db->setQuery("SELECT id FROM #__fb_messages WHERE id='{$msg_id}' OR thread='{$msg_id}'"); $msg_ids = $kunena_db->loadResultArray(); check_dberror("Unable to load messages."); $cntTopics = 0; $cntPosts = 0; if (count($msg_ids) > 0) { foreach ($msg_ids as $msg) { if ($msg == $msg_id) { $cntTopics = 1; } else { $cntPosts++; } } } while ($msg_cat) { unset($lastMsgInCat); $kunena_db->setQuery("SELECT id, time FROM #__fb_messages WHERE catid='{$msg_cat}' AND (thread!='{$msg_id}' AND id!='{$msg_id}') ORDER BY time DESC LIMIT 1;"); $lastMsgInCat = $kunena_db->loadObject(); check_dberror("Unable to load messages."); $ctg[$msg_cat]->numTopics = (int) ($ctg[$msg_cat]->numTopics - $cntTopics); $ctg[$msg_cat]->numPosts = (int) ($ctg[$msg_cat]->numPosts - $cntPosts); $ctg[$msg_cat]->id_last_msg = $lastMsgInCat->id; $ctg[$msg_cat]->time_last_msg = $lastMsgInCat->time; $msg_cat = $ctg[$msg_cat]->parent; } // now back to db foreach ($ctg as $cc) { $kunena_db->setQuery("UPDATE `#__fb_categories` SET `time_last_msg`='" . $cc->time_last_msg . "',`id_last_msg`='" . $cc->id_last_msg . "',`numTopics`='" . $cc->numTopics . "',`numPosts`='" . $cc->numPosts . "' WHERE `id`='" . $cc->id . "' "); $kunena_db->query(); check_dberror("Unable to update categories."); } return; } function showBulkActionCats($disabled = 1) { $kunena_db = &JFactory::getDBO(); $options = array (); $options[] = JHTML::_('select.option', '0', " "); $lists['parent'] = KUNENA_GetAvailableForums(0, "", $options, $disabled); echo $lists['parent']; } function fbDeletePosts($isMod, $return) { $app =& JFactory::getApplication(); $kunena_my = &JFactory::getUser(); $kunena_db = &JFactory::getDBO(); if (!CKunenaTools::isModOrAdmin() && !$isMod) { $app->redirect($return, _POST_NOT_MODERATOR); } $items = fbGetArrayInts("fbDelete"); $dellattach = 1; // start iterating here foreach ($items as $id => $value) { $kunena_db->setQuery("SELECT id, catid, parent, thread, subject, userid FROM #__fb_messages WHERE id='{$id}'"); if (!$kunena_db->query()) { return -2; } $mes = $kunena_db->loadObject(); $thread = $mes->thread; if ($mes->parent == 0) { // this is the forum topic; if removed, all children must be removed as well. $children = array (); $userids = array (); $kunena_db->setQuery("SELECT userid, id, catid FROM #__fb_messages WHERE thread='{$id}' OR id='{$id}'"); foreach ($kunena_db->loadObjectList() as $line) { $children[] = $line->id; if ($line->userid > 0) { $userids[] = $line->userid; } } $children = implode(',', $children); } else { //this is not the forum topic, so delete it and promote the direct children one level up in the hierarchy $kunena_db->setQuery('UPDATE #__fb_messages SET parent=\'' . $mes->parent . '\' WHERE parent=\'' . $id . '\''); if (!$kunena_db->query()) { return -1; } $children = $id; $userids = $mes->userid > 0 ? $mes->userid : ''; } //Delete the post (and it's children when it's the first post) $kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $id . ' OR thread=' . $id); if (!$kunena_db->query()) { return -2; } // now update stats CKunenaTools::decreaseCategoryStats($id, $mes->catid); //Delete message text(s) $kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid IN (' . $children . ')'); if (!$kunena_db->query()) { return -3; } //Update user post stats if (count($userids) > 0) { $userids = implode(',', $userids); $kunena_db->setQuery('UPDATE #__fb_users SET posts=posts-1 WHERE userid IN (' . $userids . ')'); if (!$kunena_db->query()) { return -4; } } //Delete (possible) ghost post $kunena_db->setQuery("SELECT mesid FROM #__fb_messages_text WHERE message='catid={$mes->catid}&id={$id}'"); $int_ghost_id = $kunena_db->loadResult(); if ($int_ghost_id > 0) { $kunena_db->setQuery('DELETE FROM #__fb_messages WHERE id=' . $int_ghost_id); $kunena_db->query(); $kunena_db->setQuery('DELETE FROM #__fb_messages_text WHERE mesid=' . $int_ghost_id); $kunena_db->query(); } //Delete attachments if ($dellattach) { $kunena_db->setQuery("SELECT filelocation FROM #__fb_attachments WHERE mesid IN ({$children})"); $fileList = $kunena_db->loadObjectList(); check_dberror("Unable to load attachments."); if (count($fileList) > 0) { foreach ($fileList as $fl) { unlink ($fl->filelocation); } $kunena_db->setQuery('DELETE FROM #__fb_attachments WHERE mesid IN (' . $children . ')'); $kunena_db->query(); } } } //end foreach CKunenaTools::reCountBoards(); $app->redirect($return, _KUNENA_BULKMSG_DELETED); } function isModOrAdmin($id = 0) { $kunena_my = &JFactory::getUser(); // echo '