'.$autotag['parm2'].''; $content = str_replace($autotag['tagstr'],$filelink,$content); return $content; } } /** * This will put an option for forum admin in the command and control block on moderation.php * */ function plugin_cclabel_forum() { global $_CONF; if (SEC_hasRights('forum.edit')) { return array('Forum',$_CONF['site_admin_url'] . "/plugins/forum/index.php",$_CONF['site_url'] . '/forum/images/forum.gif'); } } /** * returns the administrative option for this plugin * */ function plugin_getadminoption_forum() { global $_TABLES, $_CONF; if (SEC_hasRights('forum.edit')) { $numtopics = DB_getITEM($_TABLES['gf_topic'],"count(*)"); return array('Forum', $_CONF['site_admin_url'] . '/plugins/forum/index.php', $numtopics); } } /** * Returns the user menuitem option for this plugin * Only one menu item can be returned. */ function plugin_getuseroption_forum() { global $_CONF, $_TABLES, $LANG_GF00; $regrequired = DB_getITEM($_TABLES['gf_settings'], "registrationrequired"); if (!$regrequired || SEC_hasRights('forum.user')) { return array($LANG_GF00['useradminmenu'], $_CONF['site_url'] . '/forum/gf_userprefs.php', 0); } } function plugin_user_create_forum ($uid) { global $_TABLES; DB_query ("INSERT INTO {$_TABLES['gf_userinfo']} (uid) VALUES ('{$uid}')"); } /** * Called if admin deletes a user - Removes any moderator and Watch Records for user */ function plugin_user_delete_forum ($uid) { global $_TABLES; $username = DB_getItem($_TABLES['users'], "username", "uid=$uid"); DB_query("DELETE FROM {$_TABLES['gf_moderators']} WHERE mod_username='$username'"); DB_query("DELETE FROM {$_TABLES['gf_watch']} WHERE uid ='$uid'"); DB_query("DELETE FROM {$_TABLES['gf_userinfo']} WHERE uid ='$uid'"); DB_query("DELETE FROM {$_TABLES['gf_userprefs']} WHERE uid ='$uid'"); DB_query("DELETE FROM {$_TABLES['gf_log']} WHERE uid ='$uid'"); DB_query("UPDATE {$_TABLES['gf_topic']} SET uid = 1 WHERE uid = '$uid'"); } function plugin_profileextrassave_forum() { global $_USER, $HTTP_POST_VARS, $_TABLES; require_once ($_CONF['path_html'] . 'forum/include/gf_format.php'); $uid = $_USER['uid']; if ($uid > 1) { $location = gf_preparefordb($HTTP_POST_VARS['forum_location'],'html'); $aim = gf_preparefordb($HTTP_POST_VARS['forum_aim'],'html'); $icq = gf_preparefordb($HTTP_POST_VARS['forum_icq'],'html'); $yim = gf_preparefordb($HTTP_POST_VARS['forum_yim'],'html'); $msnm = gf_preparefordb($HTTP_POST_VARS['forum_msnm'],'html'); $interests = gf_preparefordb($HTTP_POST_VARS['forum_interests'],'html'); $occupation = gf_preparefordb($HTTP_POST_VARS['forum_occupation'],'html'); DB_save ($_TABLES['gf_userinfo'], "uid,location,aim,yim,icq,msnm,interests,occupation", "'$uid','$location','$aim','$yim','$icq','$msnm','$interests','$occupation'"); } } function plugin_profilevariablesedit_forum($uid, &$template) { global $_TABLES, $LANG_GF04; $result = DB_query ("SELECT uid,location,aim,yim,icq,yim,msnm,interests,occupation FROM {$_TABLES['gf_userinfo']} WHERE uid = $uid"); $A = DB_fetchArray ($result); $template->set_var('forum_location', $A['location']); $template->set_var('forum_aim', $A['aim']); $template->set_var('forum_icq', $A['icq']); $template->set_var('forum_yim', $A['yim']); $template->set_var('forum_msnm', $A['msnm']); $template->set_var('forum_interests', $A['interests']); $template->set_var('forum_occupation', $A['occupation']); $template->set_var ('lang_forum', $LANG_GF04['label_forum']); $template->set_var ('lang_location', $LANG_GF04['label_location']); $template->set_var ('lang_aim', $LANG_GF04['label_aim']); $template->set_var ('lang_icq', $LANG_GF04['label_icq']); $template->set_var ('lang_yim', $LANG_GF04['label_yim']); $template->set_var ('lang_msnm', $LANG_GF04['label_msnm']); $template->set_var ('lang_interests', $LANG_GF04['label_interests']); $template->set_var ('lang_occupation', $LANG_GF04['label_occupation']); } function plugin_profilevariablesdisplay_forum ($uid, &$template) { global $_TABLES, $_CONF, $LANG_GF02,$LANG_GF04; $postlimit="10"; // How many posts you want displayed $query = DB_query ("SELECT id,date,forum,subject FROM {$_TABLES['gf_topic']} WHERE uid = {$uid} ORDER BY date DESC LIMIT 100"); $numposts = 0; while (list($postid,$date,$forum_id,$subject) = DB_fetchArray($query)) { $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='$forum_id'"); $forum_name = DB_getItem($_TABLES['gf_forums'],'forum_name',"forum_id='$forum_id'"); $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'"); if (SEC_inGroup($groupname) OR $grp_id == 2) { $numposts++; $postdate = COM_getUserDateTimeFormat ($date); $template->set_var ('row_number', $numposts . '.'); $template->set_var ('story_begin_href', ''); $template->set_var ('story_title', $subject); $template->set_var ('story_end_href', ''); $template->set_var ('story_date', $postdate[0]); $template->parse ('forum_post_row', 'strow', true); if ($numposts >= $postlimit) { break; } } } if ($numposts == 0) { $template->set_var ('forum_post_row', '' .$LANG_GF02['msg155']. ''); } $count = DB_count ($_TABLES['gf_topic'], 'uid', $uid); $template->set_var ('forum_lang_number_posts', $LANG_GF02['msg156']); $template->set_var ('forum_number_posts', $count); $template->set_var ('forum_start_block_last10posts', COM_startBlock ( $LANG_GF02['msg158'] . DB_getItem ($_TABLES['users'], 'username', "uid = $uid"))); $template->set_var ('forum_headline_last10posts', $LANG_GF02['msg157']); /* Display Instant Messaging Handles */ $result = DB_query ("SELECT uid,location,aim,yim,icq,yim,msnm,interests,occupation FROM {$_TABLES['gf_userinfo']} WHERE uid = $uid"); $A = DB_fetchArray ($result); $template->set_var('forum_location', $A['location']); $template->set_var('forum_aim', $A['aim']); $template->set_var('forum_icq', $A['icq']); $template->set_var('forum_yim', $A['yim']); $template->set_var('forum_msnm', $A['msnm']); $template->set_var('forum_interests', $A['interests']); $template->set_var('forum_occupation', $A['occupation']); $template->set_var ('lang_forum', $LANG_GF04['label_forum']); $template->set_var ('lang_location', $LANG_GF04['label_location']); $template->set_var ('lang_aim', $LANG_GF04['label_aim']); $template->set_var ('lang_icq', $LANG_GF04['label_icq']); $template->set_var ('lang_yim', $LANG_GF04['label_yim']); $template->set_var ('lang_msnm', $LANG_GF04['label_msnm']); $template->set_var ('lang_interests', $LANG_GF04['label_interests']); $template->set_var ('lang_occupation', $LANG_GF04['label_occupation']); } /** * shows the statistics for the book review plugin on stats.php. * If $showsitestats is 1 then we are to only print the overall stats in the 'site statistics box' * otherwise we show the detailed stats for the photo album * * @showsitestate int Flag to let us know which stats to get */ function plugin_showstats_forum($showsitestats) { global $_CONF, $_TABLES, $LANG_GF00,$LANG_GF01; $stat_templates = new Template($_CONF['path_layout'] . 'stats'); $stat_templates->set_file(array('itemstats'=>'itemstatistics.thtml', 'statrow'=>'singlestat.thtml')); $retval=''; if ($showsitestats == 1) { // This shows in the summary box $total_pages = DB_count($_TABLES['gf_topic']); // Total number of Forum Posts $summary_label = $LANG_GF00['statslabel']; // Label to display $retval = ""; $retval .= ""; $retval .= "
$summary_label" . $total_pages . "  
"; } else { $result = DB_query("SELECT forum,subject,views,id FROM {$_TABLES['gf_topic']} where PID='0' ORDER BY views desc"); $nrows = DB_numRows($result); $retval .= COM_startBlock($LANG_GF00['statsheading1']); if ($nrows > 0) { $stat_templates->set_var('item_label',$LANG_GF01['TOPICSUBJECT']); $stat_templates->set_var('stat_name',$LANG_GF01['VIEWS']); $displaycount = 0; for ($i = 0; $i < $nrows && $i < 10; $i++) { list ($forum,$subject, $views,$id) = DB_fetchARRAY($result); $forum_id = DB_getItem($_TABLES['gf_topic'],'forum',"id='$id'"); $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='$forum_id'"); $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'"); if (SEC_inGroup($groupname) OR $grp_id == 2) { $url = $_CONF['site_url']. "/forum/viewtopic.php?forum=$forum&showtopic=$id"; $stat_templates->set_var('item_url', $url); $stat_templates->set_var('item_text', $subject); $stat_templates->set_var('item_stat', $views); $stat_templates->parse('stat_row','statrow',true); $displaycount++; if ($displaycount > 10) { break; } } } $stat_templates->parse('output','itemstats'); $retval .= $stat_templates->finish($stat_templates->get_var('output')); } else { $retval .= $LANG_GF00['statsheading3']; } $retval .= COM_endBlock(); $stat_templates = new Template($_CONF['path_layout'] . 'stats'); $stat_templates->set_file(array('itemstats'=>'itemstatistics.thtml', 'statrow'=>'singlestat.thtml')); $result = DB_query("SELECT forum,subject,replies,id FROM {$_TABLES['gf_topic']} where PID='0' ORDER BY replies desc"); $nrows = DB_numRows($result); $retval .= COM_startBlock($LANG_GF00['statsheading2']); if ($nrows > 0) { $stat_templates->set_var('item_label',$LANG_GF01['TOPICSUBJECT']); $stat_templates->set_var('stat_name',$LANG_GF01['REPLIES']); $displaycount=0; for ($i = 0; $i < $nrows; $i++) { list ($forum,$subject, $replies,$id) = DB_fetchARRAY($result); $forum_id = DB_getItem($_TABLES['gf_topic'],'forum',"id='$id'"); $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='$forum_id'"); $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'"); if (SEC_inGroup($groupname) OR $grp_id == 2) { $url = $_CONF['site_url']. "/forum/viewtopic.php?forum=$forum&showtopic=$id"; $stat_templates->set_var('item_url', $url); $stat_templates->set_var('item_text', $subject); $stat_templates->set_var('item_stat', $replies); $stat_templates->parse('stat_row','statrow',true); $displaycount++; if ($displaycount > 10) { break; } } } $stat_templates->parse('output','itemstats'); $retval .= $stat_templates->finish($stat_templates->get_var('output')); } else { $retval .= $LANG_GF00['statsheading3']; } $retval .= COM_endBlock(); } return $retval; } /** * Geeklog is asking us to provide any new items that show up in the type drop-down * on search.php. Let's let users search the Filelistings in the Filemgmt Plugin * */ function plugin_searchtypes_forum() { global $LANG_GF00; $tmp['forum'] = $LANG_GF00['searchlabel']; return $tmp; } /** * this searches for files matching the user query and returns an array of * for the header and table rows back to search.php where it will be formated and * printed * * @query string Keywords user is looking for * @datestart date/time Start date to get results for * @dateend date/time End date to get results for * @topic string The topic they were searching in * @type string Type of items they are searching * @author string Get all results by this author * */ function plugin_dopluginsearch_forum($query, $datestart, $dateend, $topic, $type, $author) { global $LANG_GF00, $LANG_GF01, $_TABLES, $_CONF; if (empty($type)) { $type = 'all'; } // Bail if we aren't supppose to do our search if ($type <> 'all' AND $type <> 'forum') { $plugin_results = new Plugin(); $plugin_results->plugin_name = $LANG_GF00['plugin_name']; $plugin_results->searchlabel = $LANG_GF00['searchlabel']; return $plugin_results; } $query = addslashes($query); // Build search SQL $sql = "SELECT id,name,forum,date,subject,comment,views,uid FROM {$_TABLES['gf_topic']} WHERE"; $sql .= "((comment like '%$query%' OR comment like '$query%' OR comment like '%$query') "; $sql .= "OR (name like '%$query%' OR name like '$query%' OR name like '%$query') "; $sql .= "OR (subject like '%$query%' OR subject like '$query%' OR subject like '%$query'))"; if (!empty($datestart) && !empty($dateend)) { $delim = substr($datestart, 4, 1); $DS = explode($delim,$datestart); $DE = explode($delim,$dateend); $startdate = mktime(0,0,0,$DS[1],$DS[2],$DS[0]); if ($datestart == $dateend) { $enddate = mktime(0,0,0,$DE[1],$DE[2],$DE[0]) + 86500; } else { $enddate = mktime(0,0,0,$DE[1],$DE[2],$DE[0]) + 3600; } $sql .= "AND date BETWEEN '$startdate' AND '$enddate' "; } if (!empty($author)) { $sql .= "AND (uid = '$author') "; } $sql .= "ORDER BY date desc"; // Perform search $result = DB_query($sql); // OK, now return coma delmited string of table header labels // Need to use language variables require_once($_CONF['path_system'] . 'classes/plugin.class.php'); $plugin_results = new Plugin(); $plugin_results->plugin_name = 'forum'; if (!empty($author)) { $username = DB_getItem($_TABLES['users'],"username","uid = {$author}"); $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],$LANG_GF01['FOR'] . ' ' . $username); } else { $plugin_results->searchlabel = sprintf($LANG_GF00['searchresults'],""); } $plugin_results->addSearchHeading($LANG_GF01['FORUM']); $plugin_results->addSearchHeading($LANG_GF01['SUBJECT']); $plugin_results->addSearchHeading($LANG_GF01['DATE']); $plugin_results->addSearchHeading($LANG_GF01['VIEWS'] ); $totalsearched = DB_numRows($result); $searchcount=0; // NOTE if any of your data items need to be links then add them here! // make sure data elements are in an array and in the same order as your // headings above! for ($i = 1; $i <= $totalsearched; $i++) { $A = DB_fetchArray($result); $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='{$A['forum']}'"); $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'"); if (SEC_inGroup($groupname) OR $grp_id == 2) { $searchcount++; $thetime = COM_getUserDateTimeFormat($A['day']); $forumname = DB_getItem($_TABLES['gf_forums'],"forum_name","forum_id='{$A['forum']}'"); $subject = wordwrap($A['subject'],40,"
"); $date = strftime('%b %d %Y @ %I:%M %p', $A['date']); $url = $_CONF['site_url']. "/forum/viewtopic.php?forum={$A['forum']}&showtopic={$A['id']}"; $row = array($forumname, "$subject",$date,$A['views']); $plugin_results->addSearchResult($row); } } $plugin_results->num_searchresults = $searchcount; $plugin_results->num_itemssearched = DB_count($_TABLES['gf_topic']); return $plugin_results; } /** * Removes the datastructures for this plugin from the Geeklog database * This may get called by the install routine to undue anything created during the install. * Added check to see that plugin is first disabled. */ function plugin_uninstall_forum($installCheck='') { global $_TABLES, $LANG_GF00; $pi_name='forum'; $FEATURES = array ('forum.edit', 'forum.user'); $TABLES = array ('gf_topic','gf_categories','gf_forums','gf_settings','gf_watch','gf_moderators','gf_banned_ip', 'gf_log', 'gf_userprefs','gf_userinfo'); // Check and see if plugin is still enabled - if so display warning and exit if ($installCheck != '' && DB_getItem($_TABLES['plugins'],'pi_enabled', 'pi_name = "' .$pi_name. '"')) { COM_errorLog("Plugin is installed and enabled. Disable first if you want to de-install it",1); $display .= COM_startBlock($LANG_GF00['warning']); $display .= $LANG_GF00['enabled']; $display .= COM_endBlock(); echo $display; exit; } // Ok to proceed and delete plugin - Unregister the plugin with Geeklog COM_errorLog('Attempting to unregister the Forum plugin from Geeklog',1); DB_query("DELETE FROM {$_TABLES['plugins']} WHERE pi_name = 'forum'",1); // Drop tables foreach($TABLES as $table) { $t = $_TABLES["$table"]; COM_errorLog("Removing Table $t",1); DB_query("DROP TABLE $t",1); } // Remove Admin Security for this plugin $grp_id = DB_getItem($_TABLES['vars'], 'value', "name = '{$pi_name}_admin'"); COM_errorLog("Removing $pi_name Admin Group", 1); DB_query("DELETE FROM {$_TABLES['groups']} WHERE grp_id = $grp_id",1); DB_query("DELETE FROM {$_TABLES['vars']} WHERE name = '{$pi_name}_admin'"); COM_errorLog("Removing root users from admin of $pi_name"); DB_query("DELETE FROM {$_TABLES['group_assignments']} WHERE ug_main_grp_id = $grp_id",1); // Remove all the associated features - access rights. The feature ID's were stored in the vars table during install. foreach ($FEATURES as $feature) { COM_errorLog("Removing $feature feature and rights to it",1); $feat_id = DB_getItem($_TABLES['features'], 'ft_id', "ft_name = '$feature'"); COM_errorLog("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $feat_id"); DB_query("DELETE FROM {$_TABLES['access']} WHERE acc_ft_id = $feat_id",1); DB_query("DELETE FROM {$_TABLES['features']} WHERE ft_id = $feat_id",1); } COM_errorLog("Removing Forum - Block Definition ", 1); DB_query("DELETE FROM {$_TABLES['blocks']} WHERE phpblockfn = 'phpblock_forum_newposts'",1); DB_query("DELETE FROM {$_TABLES['blocks']} WHERE phpblockfn = 'phpblock_forum_newposts2'",1); COM_errorLog('...success',1); return true; } // ------- GENERAL FORUM FUNCTIONS -------- function forum_chkUsercanPost() { global $_CONF,$registerpost,$LANG_GF00, $LANG_GF01, $LANG_GF02, $_TABLES, $_USER; //Check is anonymous users can post if($registerpost && $_USER['uid'] < 2){ $url = $_CONF['site_url']. '/users.php?mode=new'; $display .= COM_startBlock($LANG_GF00['access_denied']); $display .= '
' .$LANG_GF01['loginreqpost']. '

'; $display .= ''; $display .= COM_endBlock(); $display .= COM_siteFooter(); echo $display; exit; } // Check if IP of user has been banned $sqlresult = DB_query ("select * from {$_TABLES['gf_banned_ip']} where host_ip like '$ip'"); $banned = DB_fetchArray ($sqlresult); while($row = $banned){ echo COM_startBlock($LANG_GF00['access_denied']); echo ($LANG_GF02['msg14']); printf ($LANG_GF02['msg15'],$_CONF['site_mail']); echo COM_endBlock(); echo COM_siteFooter(true); exit(); } } function forum_chkUsercanAccess($secure=false) { global $_CONF, $LANG_GF01, $LANG_GF02, $registrationrequired, $_USER; if ($registrationrequired && $_USER['uid'] < 2) { echo '
'; printf($LANG_GF01['loginreqview'], '', ''); echo '
'; echo COM_siteFooter(); exit; } elseif($secure AND empty($_USER['uid'])) { echo '
'; BlockMessage($LANG_GF01['ACCESSERROR'],$LANG_GF02['msg83'],false); echo COM_siteFooter(); exit; } } function forum_xchsmilies($message) { $search = array(":D", ":)", ":(", "8O", ":?", "B)", ":lol:", ":x", ":P" ,":oops:", ":o",":cry:", ":evil:", ":twisted:", ":roll:", ";)", ":!:", ":question:", ":idea:", ":arrow:", ":|", ":mrgreen:",":mrt:",":love:",":cat:"); $replace = array( "Big Grin", "Smile", "Frown", "Eek!", "Confused", "Cool", "Laughing Out Loud", "Angry", "Razz", "Oops!", "Surprised!", "Cry", "Evil", "Twisted Evil", "Rolling Eyes", "Wink", "Exclaimation", "Question", "Idea", "Arrow", "Neutral", "Mr. Green"); $message = str_replace($search, $replace, $message); return $message; } function forum_statusMessage($message='',$url,$prompt,$post=false,$forum='') { global $_CONF,$_TABLES,$_USER,$LANG_GF02,$msgauto; include($_CONF['path_html'] . 'forum/include/config.php'); $imgset = $_CONF['layout_url'] .'/forum/image_set'; if ($prompt=="") { $prompt = $LANG_GF02['msg140']; } $statusmsg_header = new Template($_CONF['path_layout'] . 'forum/layout'); $statusmsg_header->set_file (array ('forum_statusmsg_header'=>'forum_statusmsg_header.thtml')); $statusmsg_header->set_var ('imgset', $imgset); $statusmsg_header->set_var ('heading', $LANG_GF02['StatusHeading']); $statusmsg_header->parse ('output', 'forum_statusmsg_header'); echo $statusmsg_header->finish($statusmsg_header->get_var('output')); echo $message; echo "

"; if ($msgauto == "0") { echo sprintf($LANG_GF02['msg139'],$prompt,$url); echo "

"; } else { echo ''; if ($post) { $forumindex = 'index.php?forum=' . $forum; echo sprintf($LANG_GF02['msg162'],$forumindex,$url); } else { echo sprintf($LANG_GF02['msg141'],$url); } echo "

"; } $statusmsg_footer = new Template($_CONF['path_layout'] . 'forum/layout'); $statusmsg_footer->set_file (array ('forum_statusmsg_footer'=>'forum_statusmsg_footer.thtml')); $statusmsg_footer->set_var ('imgset', $imgset); $statusmsg_footer->parse ('output', 'forum_statusmsg_footer'); echo $statusmsg_footer->finish ($statusmsg_footer->get_var('output')); return; } /* Function to create a new forum * * @param string $name Forum name * @param string $category Category id to add the forum * @param string $dscp Optional Category Description * @param string $order Optional Display order * @param string $order Optional Group ID if a private group * @return string Returns the Forum ID for the new forum if successful */ function forum_addForum($name,$category,$dscp="",$order="",$grp_id="") { global $_TABLES, $_USER; DB_query("INSERT INTO {$_TABLES['gf_forums']} (forum_order,forum_name,forum_dscp,forum_cat,grp_id) VALUES ('$order','$name','$dscp','$category','$grp_id')"); $forumid = DB_insertId(); $modquery = DB_query("SELECT * FROM {$_TABLES['gf_moderators']} WHERE mod_username='{$_USER['username']}' AND mod_forum='$forumid'"); if (DB_numrows($modquery) < 1){ DB_query("INSERT INTO {$_TABLES['gf_moderators']} (mod_username,mod_forum,mod_delete,mod_ban,mod_edit,mod_move,mod_stick) VALUES ('$_USER[username]', '$forumid','1','1','1','1','1')"); } return $forumid; } /* Function to delete a forum * * @param string $id Forum id to delete * @return boolean Returns true */ function forum_deleteForum($id) { global $_TABLES; DB_query("DELETE FROM {$_TABLES['gf_forums']} WHERE forum_id='$id'"); DB_query("DELETE FROM {$_TABLES['gf_topic']} WHERE forum='$id'"); DB_query("DELETE FROM {$_TABLES['gf_moderators']} WHERE mod_forum='$id'"); DB_query("DELETE FROM {$_TABLES['gf_watch']} WHERE forum_id ='$id'"); return true; } function phpblock_forum_newposts() { global $_CONF, $_USER, $_TABLES, $LANG_GF01, $LANG_GF02, $mode, $order, $PHP_SELF; $post_limit="5"; // How many posts you want displayed $subject_limit="18"; // The length of characters of the subject you want displayed $latestTopicPost = true; // Set True if only want to show the latest post for a topic $img_dir = $_CONF['layout_url'] . "/forum/image_set"; /* End of User configureable settings */ $pi_name = 'forum'; // Plugin name if (DB_getItem($_TABLES['plugins'],'pi_enabled', 'pi_name = "' .$pi_name. '"')) { if ($mode == "forumblock") { if (($order == "new") OR ($order == "")) { $view_modemsg = sprintf($LANG_GF02['msg74'],$post_limit); if ($latestTopicPost) { $orderby = "lastupdated"; } else { $orderby = "date"; } } elseif ($order == "views") { $view_modemsg = sprintf($LANG_GF02['msg75'],$post_limit); $orderby = "views"; } elseif ($order == "posts") { $view_modemsg = sprintf($LANG_GF02['msg76'],$post_limit); $orderby = "replies"; } } else { $view_modemsg = sprintf($LANG_GF02['msg74'],$post_limit); if ($latestTopicPost) { $orderby = "lastupdated"; } else { $orderby = "date"; } } $block_header = new Template($_CONF['path_layout'] . 'forum/layout'); $block_header->set_file (array ('block_header'=>'block_header.thtml')); $block_header->set_var ('phpself', $PHP_SELF); $block_header->set_var ('layout_url', $_CONF['layout_url']); $block_header->set_var ('LANG_ORDERBY', $LANG_GF01['ORDERBY']); $block_header->set_var ('LANG_NEW', $LANG_GF01['NEW']); $block_header->set_var ('LANG_VIEWS', $LANG_GF01['VIEWS']); $block_header->set_var ('LANG_POSTS', $LANG_GF01['POSTS']); $block_header->set_var ('view_modemsg', $view_modemsg); $block_header->parse ('output', 'block_header'); $retval = $block_header->finish($block_header->get_var('output')); // Select SQL to either show the latest posts even if they are for the same topic // Or show only the lastest post for each of the last updated topics if ($latestTopicPost) { $result = DB_query("SELECT id,forum,name,date,subject,replies,views,uid,pid FROM {$_TABLES['gf_topic']} WHERE PID=0 ORDER BY $orderby DESC"); } else { $result = DB_query("SELECT id,forum,name,date,subject,replies,views,uid,pid FROM {$_TABLES['gf_topic']} ORDER BY $orderby DESC"); } $nrows = DB_numrows($result); $onetwo = 1; $displaycount = 0; for ($i =1; $i <= $nrows; $i++) { $A = DB_fetchArray($result); $forum_id = DB_getItem($_TABLES['gf_topic'],'forum',"id='{$A['id']}'"); $grp_id = DB_getItem($_TABLES['gf_forums'],'grp_id',"forum_id='$forum_id'"); $groupname = DB_getItem($_TABLES['groups'],'grp_name',"grp_id='$grp_id'"); if (SEC_inGroup($groupname) OR $grp_id == 2) { $displaycount++; $fullsubject = $A["subject"]; if (strlen ($A["subject"]) > $subject_limit) { $A["subject"] = substr("$A[subject]", 0, $subject_limit); $A["subject"] .= ".."; $profilelink = ""; } if ($A['replies'] > 0 AND $latestTopicPost) { $lastreplySQL = DB_query("Select uid,name,date from {$_TABLES['gf_topic']} WHERE PID={$A['id']} ORDER BY date DESC LIMIT 1"); list ($uid,$postername,$postdate) = DB_fetchArray($lastreplySQL); } else { $postername = $A['name']; $postdate = $A['date']; $uid = $A['uid']; } if ($uid > 1) { $profilelink = ""; } $block_displayline = new Template($_CONF['path_layout'] . 'forum/layout'); $block_displayline->set_file (array ('block_displayline'=>'block_displayline.thtml')); $block_displayline->set_var ('site_url', $_CONF['site_url']); $block_displayline->set_var ('css_id', $onetwo); $block_displayline->set_var ('img_dir', $img_dir); $block_displayline->set_var ('forum_id', $A['forum']); $block_displayline->set_var ('topic_id', $A['id']); $block_displayline->set_var ('topic_subject', $A['subject']); $block_displayline->set_var ('fullsubject', $fullsubject); $block_displayline->set_var ('topic_id', $A['id']); $block_displayline->set_var ('profilelink', $profilelink); $block_displayline->set_var ('user_name', $postername); $block_displayline->set_var ('LANG_BY', $LANG_GF01['BY']); $block_displayline->set_var ('LANG_ON', $LANG_GF01['ON']); $block_displayline->set_var ('LANG_VIEWS', $LANG_GF01['VIEWS']); $block_displayline->set_var ('LANG_REPLIES', $LANG_GF01['REPLIES']); $block_displayline->set_var ('views', $A['views']); $block_displayline->set_var ('replies', $A['replies']); $block_displayline->set_var ('date', strftime('%m/%d/%y %H:%M %p', $postdate)); $block_displayline->parse ('output', 'block_displayline'); $retval .= $block_displayline->finish($block_displayline->get_var('output')); if ($onetwo == 1) { $onetwo = 2; } else { $onetwo = 1; } if ($displaycount >= $post_limit) { break; } } } return $retval; } else { return ""; } } /** * Display latest forum posts in the center block. * * @param where int where the block will be displayed (0..2) * @param page int page number * @param topic string topic ID * @return string HTML for the center blcok (can be empty) */ function plugin_centerblock_forum ($where = 1, $page = 1, $topic = '') { global $_CONF, $_USER, $_TABLES, $LANG_GF01; global $LANG_GF02, $mode, $order, $PHP_SELF; require_once ($_CONF['path_html'] . 'forum/include/config.php'); $post_limit = 10; // How many posts you want displayed $subject_limit = 30; // The length of the subject you want displayed $UserDateTimePref = false; $img_dir = $_CONF['layout_url'] . '/forum/image_set'; $retval = ''; // Retrieve Centerblock Settings $query = DB_query ("SELECT cb_enable, cb_homepage, cb_where FROM {$_TABLES['gf_settings']}"); list ($cb_enable,$cb_homepage,$cb_where) = DB_fetchArray ($query); // If enabled only for homepage and this is not page 1 or a topic page, // then set disable flag if ($cb_homepage == 1 AND ($page > 1 OR !empty ($topic))) { $cb_enable = 0; } elseif ($cb_homepage == 0 and $page > 1) { $cb_where = 1; // Top of Page } // Check if there are no featured articles in this topic // and if so then place it at the top of the page if (!empty ($topic)) { $wheresql = "WHERE tid='$topic' AND featured > 0"; } else { $wheresql = 'WHERE featured = 1'; } $query = DB_query ("SELECT count(*) as count FROM {$_TABLES['stories']} $wheresql"); $result = DB_fetchArray ($query); if ($result['count'] == 0 and $cb_where == 2) { $cb_where = 1; } if ($cb_enable AND ($cb_where == $where)) { $retval .= COM_startBlock ($LANG_GF02['msg170']); $block_header = new Template ($_CONF['path_layout'] . 'forum/layout'); $block_header->set_file (array ('block_header'=>'centerblock_header.thtml')); $block_header->set_var ('phpself', $PHP_SELF); $block_header->set_var ('site_url', $_CONF['site_url']); $block_header->set_var ('layout_url', $_CONF['layout_url']); $block_header->set_var ('LANG_FORUM', $LANG_GF01['FORUM']); $block_header->set_var ('LANG_TOPIC', $LANG_GF01['TOPIC']); $block_header->set_var ('LANG_LASTPOST', $LANG_GF01['LASTPOST']); $block_header->parse ('output', 'block_header'); $retval .= $block_header->finish ($block_header->get_var ('output')); $result = DB_query ("SELECT id,forum,name,lastupdated,subject,uid,pid,replies,views FROM {$_TABLES['gf_topic']} WHERE pid=0 ORDER BY lastupdated DESC"); $nrows = DB_numrows ($result); $onetwo = 1; $displaycount = 0; $block_displayline = new Template ($_CONF['path_layout'] . 'forum/layout'); $block_displayline->set_file (array ('block_displayline' => 'centerblock_displayline.thtml')); $block_displayline->set_var ('site_url', $_CONF['site_url']); $block_displayline->set_var ('LANG_lastpost', $LANG_GF02['msg160']); $cache_in_group = array (); for ($i = 0; $i < $nrows; $i++) { $A = DB_fetchArray ($result); $fresult = DB_query ("SELECT grp_id, forum_name FROM {$_TABLES['gf_forums']} WHERE forum_id='{$A['forum']}'"); list ($grp_id, $forum_name) = DB_fetchArray ($fresult); if ($grp_id != 2) { if (empty ($cache_in_group[$grp_id])) { $groupname = DB_getItem ($_TABLES['groups'], 'grp_name', "grp_id='$grp_id'"); $cache_in_group[$grp_id] = SEC_inGroup ($groupname); } } if (($grp_id == 2) || $cache_in_group[$grp_id]) { $displaycount++; $fullsubject = $A['subject']; if(strlen ($A['subject']) > $subject_limit) { $A['subject'] = substr ($A['subject'], 0, $subject_limit); $A['subject'] .= '...'; } $query2 = DB_query ("SELECT max(id) as lastid FROM {$_TABLES['gf_topic']} WHERE pid= {$A['id']}"); list ($lastid) = DB_fetchArray ($query2); if (empty ($lastid) OR $lastid < 1) { $lastid = $A['id']; } if ($UserDateTimePref) { $lastdate = COM_getUserDateTimeFormat ($A['lastupdated']); $lastdate = $lastdate[0]; } else { $lastdate = strftime ('%m/%d/%y %H:%M', $A['lastupdated']); } $block_displayline->set_var ('css_id', $onetwo); $block_displayline->set_var ('img_dir', $img_dir); $block_displayline->set_var ('forum_id', $A['forum']); $block_displayline->set_var ('forum_name', $forum_name); $block_displayline->set_var ('topic_id', $A['id']); $block_displayline->set_var ('topic_subject', $A['subject']); $block_displayline->set_var ('fullsubject', $fullsubject); $block_displayline->set_var ('views', $A['views']); $block_displayline->set_var ('replies', $A['replies']); $block_displayline->set_var ('date',$lastdate ); $block_displayline->parse ('output', 'block_displayline'); $retval .= $block_displayline->finish ($block_displayline->get_var ('output')); if ($onetwo == 1) { $onetwo = 2; } else { $onetwo = 1; } if ($displaycount >= $post_limit) { break; } } } $block_header = new Template ($_CONF['path_layout'] . 'forum/layout'); $block_header->set_file (array ('block_header' => 'centerblock_footer.thtml')); $block_header->parse ('output', 'block_header'); $retval .= $block_header->finish ($block_header->get_var ('output')); $retval .= COM_endBlock(); } return $retval; } ?>