// // +---------------------------------------------------------------------------+ // | Stories By Topic Block (sbt v1.1) for Geeklog | // +---------------------------------------------------------------------------+ // | index.php | // +---------------------------------------------------------------------------+ // | This file contains a function which will display the stories of any | // | desired topic. Configurable variables include: order and title of | // | the topic(s), maximum number of stories under each topic, time frame, | // | maximum length for a story's title, and setting to display stories as | // | one list instead of under separate topics. | // +---------------------------------------------------------------------------+ // | Copyright (C) 2003 by DoYourDD (geek@doyourdd.com) | // +---------------------------------------------------------------------------+ // | | // | This program is free software; you can redistribute it and/or | // | modify it under the terms of the GNU General Public License | // | as published by the Free Software Foundation; either version 2 | // | of the License, or (at your option) any later version. | // | | // | This program is distributed in the hope that it will be useful, | // | but WITHOUT ANY WARRANTY; without even the implied warranty of | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | // | GNU General Public License for more details. | // | | // | You should have received a copy of the GNU General Public License | // | along with this program; if not, write to the Free Software Foundation, | // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | // | | // +---------------------------------------------------------------------------+ // // 27th May 2005 Beewee (www.beeweb.nl): // Changes: because in GL 1.3.10 and higher it's possible to change the story-ID (sid). // This affected the search for new stories. // I've changed 'sid' to 'date' on several places. function phpblock_StoriesByTopic() { global $_TABLES, $_GROUPS, $_USER; /***************************************************************************/ /* Set these configuration variables to meet your website's requirements */ /***************************************************************************/ // list each topic in the order you want it displayed with the desired title // format: $topic['topic id'] = 'Title of Topic'; $topic['1mc'] = 'Announcements'; $topic['Geeklog'] = 'Geeklog'; $topic['General'] = 'General News'; // merge all stories into just one list instead of separately titled ones $merge_topics = true; // set to true or false // title to display above the merged topics or leave blank if none desired $merge_title = ''; // maximum number of stories to display under each topic. If $merge_topics // is set to true this is the max number to display for all stories $num_stories = 10; // if you want to display stories only within a certain time interval, then // uncomment and set this variable to the desired time frame. If set to zero // or if left commented out, all stories will be displayed up to the max number // desired ($num_stories) regardless of time period. // $newstoriesinterval = 86400; // this time is in seconds (86400 = 24 hours) // maximum number of characters to display in a story's title $max_title_length = 20; /****************************************************************************/ /* Please do not modify the code below unless you know what you are doing */ /****************************************************************************/ // initialize variables $display = ''; $group_list = ''; $topic_list = ''; $perms = ''; // abort and return empty string if these variables are not set properly if (!isset($topic) OR !is_array($topic) OR (sizeof($topic) < 1) OR !isset($num_stories) OR !is_numeric($num_stories)) { return $display; } // get a listing of all groups to which the visitor belongs if (!empty($_USER['uid'])) { foreach ($_GROUPS as $grp) { $group_list .= $grp . ','; } $group_list = substr($group_list, 0, -1); } // set up the permission checker if (!empty( $_USER['uid'])) { $perms .= "(owner_id = {$_USER['uid']} AND perm_owner >= 2) OR "; $perms .= "(group_id IN ($group_list) AND perm_group >= 2) OR "; $perms .= "(perm_members >= 2) OR "; } $perms .= "(perm_anon >= 2)"; // test whether all topics should be merged if ($merge_topics) { // make a list of topics to display foreach ($topic as $topic_id => $topic_title) { // if the visitor doesn't have access to a topic then go to the next one if (!SEC_hasTopicAccess($topic_id)) { continue; } // otherwise add the topic to the allowable list to be shown else { $topic_list .= "'$topic_id'" . ','; } } // end foreach $topic_list = substr($topic_list,0,-1); // continue if there are any topics to display if (strlen($topic_list) > 0) { // pull only the stories the visitor is allowed to view $sql = "SELECT title, sid FROM {$_TABLES['stories']} WHERE "; if (isset($newstoriesinterval) AND (is_numeric($newstoriesinterval)) AND ($newstoriesinterval > 0)) { $sql .= "(date >= (NOW() - INTERVAL {$newstoriesinterval} SECOND)) AND "; } $sql .= "(date <= NOW()) AND (draft_flag = 0) AND (tid IN ($topic_list)) AND ($perms) ORDER BY date DESC LIMIT $num_stories"; // process all the stories for display $display .= displayStories($merge_title, $sql, $merge_topics, $max_title_length); } // end if // if no topics then return an empty string to Geeklog else { return $display; } } // end if // display the stories by topic instead else { foreach ($topic as $topic_id => $topic_title) { // if the visitor doesn't have access to a topic then go to the next one if (!SEC_hasTopicAccess($topic_id)) { continue; } // pull only the stories the visitor is allowed to view $sql = "SELECT title, sid FROM {$_TABLES['stories']} WHERE "; if (isset($newstoriesinterval) AND (is_numeric($newstoriesinterval)) AND ($newstoriesinterval > 0)) { $sql .= "(date >= (NOW() - INTERVAL {$newstoriesinterval} SECOND)) AND "; } $sql .= "(date <= NOW()) AND (draft_flag = 0) AND (tid='$topic_id') AND ($perms) ORDER BY date DESC LIMIT $num_stories"; // process all the stories for display $display .= displayStories($topic_title, $sql, $merge_topics, $max_title_length); } // end for } // end else // send the output to Geeklog to display return $display; } // end function phpblock_StoriesByTopic function displayStories($topic_title, $sql, $merge, $max_title_length) { global $_CONF; $result = DB_query($sql,0); $numrows = DB_numRows($result); // continue on only if there is data to process if ($numrows >= 1) { // display the topic title if one is listed if (strlen($topic_title) > 0) { $display .= '<b>' . $topic_title . '</b>'; $display .= '<br />'; } // pull each story for a particular topic for ($count = 0; $count < $numrows; $count++) { $row = DB_fetchArray($result); $story_title = $row['title']; $sid = $row['sid']; // shorten the story's title if it's too long to fit nicely in the block if (isset($max_title_length) AND is_numeric($max_title_length)) { $title_length = strlen($story_title); if ($title_length > $max_title_length) { $story_title = substr($story_title, 0, ($max_title_length - 3)); $story_title = str_replace('$', '$', $story_title) . '...'; $story_title = str_replace(' ', ' ', $story_title); } } // end if // display the title with url for each story $display .= '<a href="' . $_CONF['site_url'] . '/article.php?story=' . $sid . '">' . $story_title . '</a><br>'; } // end for // add extra line feed only if displaying multiple topics if (!$merge) { $display .= '<br>'; } } // end if return $display; } // end function displayStories