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' ORDER BY id ASC 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 if (!defined('C_ASSET_JQUERY')) 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'); // A bug in the JomSocial 1.6 pre-release is throwing a hard php error when this include is enabled // for now I have moved it straight into post.php - the only place the userpoints classes // are being used. We might want to change that back for future releases. // include_once(KUNENA_ROOT_PATH .DS. 'components/com_community/libraries/userpoints.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 == "aup") { // integration AlphaUserPoints $db =& JFactory::getDBO(); $query = "SELECT id FROM #__menu WHERE `link`='index.php?option=com_alphauserpoints&view=account' AND `type`='component' AND `published`='1'"; $db->setQuery( $query ); $AUP_itemid = $db->loadResult(); define("KUNENA_AUP_ITEMID", (int)$AUP_itemid); define("KUNENA_AUP_ITEMID_SUFFIX", "&Itemid=" . KUNENA_AUP_ITEMID); $profilelink = 'index.php?option=com_alphauserpoints&view=account&userid='; define("KUNENA_PROFILE_LINK_SUFFIX", "index.php?option=com_alphauserpoints&view=account&Itemid=" . KUNENA_AUP_ITEMID . "&userid="); } 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 . 'index.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 reCountUserPosts() { $kunena_db = &JFactory::getDBO(); // Reset category counts as next query ignores users which have written no messages $kunena_db->setQuery("UPDATE #__fb_users SET posts=0"); $kunena_db->query(); check_dberror("Unable to reset category post counts."); // Update user post count (ignore unpublished categories and hidden messages) $kunena_db->setQuery("INSERT INTO #__fb_users (userid, posts)" ." SELECT m.userid, COUNT(m.userid) " ." FROM #__fb_messages AS m" ." INNER JOIN #__fb_users AS u ON u.userid = m.userid" ." WHERE m.hold=0 and m.catid IN (SELECT id FROM #__fb_categories WHERE published=1)" ." GROUP BY m.userid" ." ON DUPLICATE KEY UPDATE posts=VALUES(posts)"); $kunena_db->query(); check_dberror("Unable to update user posts."); } function reCountBoardsRecursion(&$array, $current) { foreach ($array[$current]->children as $child) { if (!$array[$child]->published) continue; if (!empty($array[$child]->children)) CKunenaTools::reCountBoardsRecursion($array, $child); $array[$current]->numTopics += $array[$child]->numTopics; $array[$current]->numPosts += $array[$child]->numPosts; if (isset($array[$current]->id) && $array[$child]->id_last_msg > $array[$current]->id_last_msg) { $array[$current]->id_last_msg = $array[$child]->id_last_msg; $array[$current]->time_last_msg = $array[$child]->time_last_msg; } } } function reCountBoards() { $kunena_db = &JFactory::getDBO(); include_once (KUNENA_PATH_LIB .DS. 'kunena.db.iterator.class.php'); // Reset category counts as next query ignores empty categories $kunena_db->setQuery("UPDATE #__fb_categories SET numTopics=0, numPosts=0"); $kunena_db->query(); check_dberror("Unable to reset category post counts."); // Update category post count $kunena_db->setQuery("INSERT INTO #__fb_categories (id, numTopics, numPosts, id_last_msg, time_last_msg)" ." SELECT c.id, SUM( m.parent=0 ), SUM( m.parent>0 ), MAX( m.id ), MAX( m.time )" ." FROM #__fb_messages as m" ." INNER JOIN #__fb_categories AS c ON c.id=m.catid" ." WHERE m.catid>0 AND m.hold=0" ." GROUP BY catid " ." ON DUPLICATE KEY UPDATE numTopics=VALUES(numTopics), numPosts=VALUES(numPosts), id_last_msg=VALUES(id_last_msg), time_last_msg=VALUES(time_last_msg)"); $kunena_db->query(); check_dberror("Unable to update categories post count."); // Load categories to be counted $kunena_db->setQuery("SELECT id, parent, published, numTopics, numPosts, id_last_msg, time_last_msg FROM #__fb_categories"); $cats = $kunena_db->loadObjectList('id'); check_dberror("Unable to load categories."); foreach ($cats as $c) { if (isset($cats[$c->parent])) $cats[$c->parent]->children[] = $c->id; else $cats[0]->children[] = $c->id; } CKunenaTools::reCountBoardsRecursion($cats, 0); // now back to db foreach ($cats as $c) { if (!isset($c->id)) continue; $kunena_db->setQuery("UPDATE #__fb_categories SET" ." numTopics=" . intval($c->numTopics) .", numPosts=" . intval($c->numPosts) .", id_last_msg=" . intval($c->id_last_msg) .", time_last_msg=" . intval($c->time_last_msg) ." WHERE id=" . intval($c->id)); $kunena_db->query(); check_dberror("Unable to update categories."); } } 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"); return $kunena_db->getAffectedRows(); } 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(); $backUrl = $app->getUserState ( "com_kunena.ActionBulk" ); $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 getEMailToList($catid, $thread, $subscriptions = false, $moderators = false, $admins = false, $excludeList = '0') { $catid = intval ( $catid ); $thread = intval ( $thread ); if ( $catid == '0' || $thread == '0' ) return array(); // Make sure that category exists and fetch access info $kunena_db = &JFactory::getDBO (); $query = "SELECT pub_access, pub_recurse, admin_access, admin_recurse FROM #__fb_categories WHERE id={$catid}"; $kunena_db->setQuery ($query); $access = $kunena_db->loadObject (); check_dberror ( "Unable to load category access rights." ); if (!$access) return array(); $arogroups = ''; if ($subscriptions) { // Get all allowed Joomla groups to make sure that subscription is valid $kunena_acl = &JFactory::getACL (); $public = array (); $admin = array (); if ($access->pub_access > 0) { if ($access->pub_recurse) { $public = $kunena_acl->get_group_children ( $access->pub_access, 'ARO', 'RECURSE' ); } $public [] = $access->pub_access; } if ($access->pub_access > 0 && $access->admin_access > 0) { if ($access->admin_recurse) { $admin = $kunena_acl->get_group_children ( $access->admin_access, 'ARO', 'RECURSE' ); } $admin [] = $access->admin_access; } $arogroups = implode ( ',', array_unique ( array_merge ( $public, $admin ) ) ); if ($arogroups) $arogroups = "u.gid IN ({$arogroups})"; } $querysel = "SELECT u.id, u.name, u.username, u.email, IF( s.thread IS NOT NULL, 1, 0 ) AS subscription, IF( c.moderated=1 AND p.moderator=1 AND ( m.catid IS NULL OR m.catid={$catid}), 1, 0 ) AS moderator, IF( u.gid IN (24, 25), 1, 0 ) AS admin FROM #__users AS u LEFT JOIN #__fb_users AS p ON u.id=p.userid LEFT JOIN #__fb_categories AS c ON c.id={$catid} LEFT JOIN #__fb_moderation AS m ON u.id=m.userid AND m.catid=c.id LEFT JOIN #__fb_subscriptions AS s ON u.id=s.userid AND s.thread={$thread}"; $where = array (); if ($subscriptions) $where [] = " ( s.thread IS NOT NULL " . ($arogroups ? " AND {$arogroups}" : '') . " ) "; if ($moderators) $where [] = " ( c.moderated=1 AND p.moderator=1 AND ( m.catid IS NULL OR m.catid={$catid} ) ) "; if ($admins) $where [] = " ( u.gid IN (24, 25) ) "; $subsList = array (); if (count ($where)) { $where = " AND (" . implode ( ' OR ', $where ) . ")"; $query = $querysel . " WHERE u.block=0 AND u.id NOT IN ($excludeList) $where GROUP BY u.id"; $kunena_db->setQuery ( $query ); $subsList = $kunena_db->loadObjectList (); check_dberror ( "Unable to load email list." ); } return $subsList; } function isModOrAdmin($id = 0) { $kunena_my = &JFactory::getUser(); // echo '