The previous version of the code only seemed to work on my local machine. I am unsure why, but this new code has been checked and confirmed on several machines, and hence should be the final version.
In index.php replace/add the code with
// find the name of the current category
if(isset($_REQUEST['category'])){
$thecat = get_cached_category_data('category_safe_name', sanitize($_REQUEST['category'], 1));
$thecat = $thecat->category_name;
if (!$thecat)
{
$main_smarty->assign('tpl_center', '404error');
$main_smarty->display($the_template . '/pligg.tpl');
die();
}
}
// start a new search
$search=new Search();
// check for some get/post
if(isset($_REQUEST['from'])){
$search->newerthan = sanitize($_REQUEST['from'], 3);
}
unset($_REQUEST['search']);
unset($_POST['search']);
unset($_GET['search']);
if(isset($_REQUEST['search'])){$search->searchTerm = sanitize($_REQUEST['search'], 3);}
if(isset($_REQUEST['search'])){$search->filterToStatus = "all";}
if(!isset($_REQUEST['search'])){$search->orderBy = "link_published_date DESC";}
if(isset($_REQUEST['tag'])){$search->searchTerm = sanitize($_REQUEST['search'], 3); $search->isTag = true;}
if(isset($thecat)){
$search->category = $thecat;
} else {
$thecat = News; // Search with only opinion
$search->category = $thecat;
}
// figure out what "page" of the results we're on
$search->offset = (get_current_page()-1)*$page_size;
// pagesize set in the admin panel
$search->pagesize = $page_size;
// since this is index, we only want to view "published" stories
$search->filterToStatus = "published";
// this is for the tabs on the top that filter
if(isset($_GET['part'])){$search->setmek = $db->escape($_GET['part']);}
$search->do_setmek();
// do the search
$search->doSearch();
$linksum_count = $search->countsql;
$linksum_sql = $search->sql;
$search2=new Search();
if(isset($_REQUEST['from'])){
$search2->newerthan = sanitize($_REQUEST['from'], 3);
}
if(isset($_REQUEST['search'])){$search2->searchTerm = sanitize($_REQUEST['search'], 3);}
if(isset($_REQUEST['search'])){$search2->filterToStatus = "all";}
if(!isset($_REQUEST['search'])){$search2->orderBy = "link_published_date DESC";}
if(isset($_REQUEST['tag'])){$search2->searchTerm = sanitize($_REQUEST['search'], 3); $search->isTag = true;}
if(!isset($_REQUEST['category'])){ // Activates when on the index page and no category select has been activated
$catnameopinion = Opinion; // Search with only opinion
}
if(isset($catnameopinion)){
$search2->category = $catnameopinion;
}
// figure out what "page" of the results we're on
$search2->offset = (get_current_page()-1)*$page_size;
// pagesize set in the admin panel
$search2->pagesize = $page_size;
// since this is index, we only want to view "published" stories
$search2->filterToStatus = "published";
// this is for the tabs on the top that filter
if(isset($_GET['part'])){$search2->setmek = $db->escape($_GET['part']);}
$search2->do_setmek();
// do the search
$search2->doSearch();
$linksum_count_coltwo = $search2->countsql;
$linksum_sql_coltwo = $search2->sql;
// misc smarty
if(isset($from_text)){$main_smarty->assign('from_text', $from_text);}
if(isset($search->setmek)){
$main_smarty->assign('setmeka', $search->setmek);
$main_smarty->assign('setmeka', $search2->setmek);
}else{
$main_smarty->assign('setmeka', '');
}
$fetch_link_summary = true; // this feed information back to libs/link_summary.php
$fetch_news_link_summary = true; // this feed information back to libs/link_summary.php for news
$fetch_opinion_link_summary = true; // this feed information back to libs/link_summary.php for opinion
include('./libs/link_summary.php'); // this is the code that show the links / stories
$main_smarty->assign('link_pagination', do_pages($rows, $page_size, "published", true));
In libs/link_summary.php, replace the code with;
if ($new_search) {
// used on the search page
$rows = $new_search['count'];
$new_search = $new_search['rows'];
$the_results = $new_search;
} else {
// used in the index and upcoming pages
$ls_debug = false;
if($ls_debug == true){
echo '--' . sanitize($linksum_count,3) . '--
';
echo '--' . sanitize($linksum_count_coltwo,3) . '--
';
}
if($linksum_count == "SELECT count(*) FROM " . table_links . " WHERE link_status='published' "){
if($ls_debug == true){echo 'p';}
$rows = $cached_totals['published'];
} elseif ($linksum_count == "SELECT count(*) FROM " . table_links . " WHERE link_status='queued' ") {
if($ls_debug == true){echo 'u';}
$rows = $cached_totals['queued'];
} else {
if($ls_debug == true){
echo 'r';}
$rows = $db->get_var($linksum_count);
$rows_opinion = $db->get_var($linksum_count_coltwo);
}
if($ls_debug == true){echo '
' . sanitize($rows,3) . '
';}
$links = $db->get_col($linksum_sql);
$the_results = $links;
$links_opinion = $db->get_col($linksum_sql_coltwo); // Brings in second search data from index.php
$the_results_opinion = $links_opinion; // Brings in second search data from index.php
}
if($the_results_opinion){
// find out if the logged in user voted / reported each of
// the stories that the search found and cache the results
require_once(mnminclude.'votes.php');
// DB 03/02/09
// $vote = new Vote;
// $vote->type='links';
// $vote->user=$current_user->user_id;
// $vote->link=$the_results;
// $results = $vote->user_list_all_votes();
/////
$vote = '';
$results_opinion = ''; // we don't actually need the results
// we're just calling this to cache the results
// so when we foreach the links we don't have to
// run 1 extra query for each story to determine
// current user votes
// setup the link cache
$sql = "SELECT " . table_links . ".* FROM " . table_links . " WHERE ";
$sql_saved = "SELECT * FROM " . table_saved_links . " WHERE saved_user_id=" . $current_user->user_id . " AND ";
$ids_opinion = array();
foreach($the_results_opinion as $opinion_link_id) {
// first make sure we don't already have it cached
if(!isset($cached_links[$opinion_link_id])){
$ids_opinion[] = $opinion_link_id;
}
if(!isset($cached_saved_links[$opinion_link_id])){
$saved_ids[] = $opinion_link_id;
}
}
// if count = 0 then all the links are already cached
// so don't touch the db
// if count > 0 then there is at least 1 link to get
// so get the SQL and add results to the cache
if ( count ( $ids_opinion ) ) {
$sql .= 'link_id IN ('.implode(',',$ids_opinion).')';
foreach ( $db->get_results($sql) as $row ) {
$cached_links[$row->opinion_link_id] = $row;
if(!isset($link_authors[$row->link_author])){
$link_authors[$row->link_author] = $row->link_author;
}
}
}
// get all authors at once from the users table
$sql = 'SELECT * FROM ' . table_users . ' WHERE ';
if ( count ( $link_authors ) ) {
$sql .= 'user_id IN (' . implode(',', $link_authors) . ')';
foreach ( $db->get_results($sql) as $user ) {
$cached_users[$user->user_id] = $user;
}
}
// user saved _links
if ( count ( $saved_ids ) ) {
$sql_saved .= 'saved_link_id IN ('.implode(',',$ids_opinion).')';
$results_opinion = $db->get_results($sql_saved);
if($results){
foreach($results_opinion as $row){
$sl[$row->saved_link_id] = 1;
}
}
foreach($the_results_opinion as $opinion_link_id) {
if(isset($sl[$opinion_link_id])){
$cached_saved_links[$opinion_link_id] = 1;
} else {
$cached_saved_links[$opinion_link_id] = 0;
}
}
}
// end link cache setup
}
global $display_grouplinks;
if(!isset($link_summary_output)){$link_summary_output = '';}
if ($new_search) {
foreach($new_search as $link_id) {
$link->id=$link_id;
$link->read();
if( $display_grouplinks ) $link->link_group_id = 0;
$link_summary_output .= $link->print_summary('summary', true); // standard function call
$news_link_summary_output .= $link-> print_news_summary('summary', true); // news only function call
}
} else {
if ($links) {
foreach($links as $link_id) {
$link->id=$link_id;
$link->read();
$link_summary_output .= $link->print_summary('summary', true); // standard function call
$news_link_summary_output .= $link-> print_news_summary('summary', true); // news only function call
}
}
}
if ($new_search) {
foreach($new_search as $opinion_link_id) { //function to apply second search function
$link_opinion->id_opinion=$opinion_link_id;
$link_opinion->read_opinion();
if( $display_grouplinks ) $link->link_group_id = 0;
$opinion_link_summary_output .= $link_opinion-> print_opinion_summary('summary', true); // opinion only function call
}
} else {
if ($links_opinion) {
foreach($links_opinion as $opinion_link_id) { //function to apply second search function
$link_opinion->id_opinion=$opinion_link_id;
$link_opinion->read_opinion();
$opinion_link_summary_output .= $link_opinion-> print_opinion_summary('summary', true); // opinion only function call
}
}
}
if(isset($fetch_link_summary) && $fetch_link_summary == true){ // standard feedback from index.php
$main_smarty->assign('link_summary_output', $link_summary_output);
} else {
echo $link_summary_output;
}
if(isset($fetch_news_link_summary) && $fetch_news_link_summary == true){ // news feedback from index.php
$main_smarty->assign('news_link_summary_output', $news_link_summary_output);
} else {
echo $news_link_summary_output;
}
if(isset($fetch_opinion_link_summary) && $fetch_opinion_link_summary == true){ // opinion feedback from index.php
$main_smarty->assign('opinion_link_summary_output', $opinion_link_summary_output);
} else {
echo $opinion_link_summary_output;
}
In libs/link.php, add the following code;
function read_opinion($usecache = TRUE) {
global $db, $current_user, $cached_links;
$id_opinion = $this->id_opinion;
$this->rating = 0;
if(!is_numeric($id_opinion)){return false;}
// check to see if the link is cached
// if it is, use it
// if not, get from mysql and save to cache
if (isset($cached_links[$id_opinion]) && $usecache == TRUE) {
$link_opinion = $cached_links[$id_opinion];
} else {
$link_opinion = $db->get_row("SELECT " . table_links . ".* FROM " . table_links . " WHERE link_id = $id_opinion");
$cached_links[$id_opinion] = $link_opinion;
}
if($link_opinion) {
$this->author=$link_opinion->link_author;
$this->userid=$link_opinion->link_author;
$this->status=$link_opinion->link_status;
$this->votes=$link_opinion->link_votes;
$this->reports=$link_opinion->link_reports;
$this->comments=$link_opinion->link_comments;
$this->randkey=$link_opinion->link_randkey;
$this->category=$link_opinion->link_category;
$this->url= $link_opinion->link_url;
$this->url= str_replace('&', '&', $link_opinion->link_url);
$this->url_title=$link_opinion->link_url_title;
$this->url_description=$link_opinion->link_url_description;
$this->title=$link_opinion->link_title;
$this->title_url=$link_opinion->link_title_url;
$this->tags=$link_opinion->link_tags;
$this->content=$link_opinion->link_content;
// DB 01/08/09
$this->date=strtotime($link_opinion->link_date);
// $date=$link_opinion->link_date;
// $this->date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
$this->published_date=strtotime($link_opinion->link_published_date);
// $date=$link_opinion->link_published_date;
// $this->published_date=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
$this->modified=strtotime($link_opinion->link_modified);
// $date=$link_opinion->link_modified;
// $this->modified=$db->get_var("SELECT UNIX_TIMESTAMP('$date')");
/////
$this->fullread = $this->read = true;
$this->link_summary = $link_opinion->link_summary;
$this->link_field1=$link_opinion->link_field1;
$this->link_field2=$link_opinion->link_field2;
$this->link_field3=$link_opinion->link_field3;
$this->link_field4=$link_opinion->link_field4;
$this->link_field5=$link_opinion->link_field5;
$this->link_field6=$link_opinion->link_field6;
$this->link_field7=$link_opinion->link_field7;
$this->link_field8=$link_opinion->link_field8;
$this->link_field9=$link_opinion->link_field9;
$this->link_field10=$link_opinion->link_field10;
$this->link_field11=$link_opinion->link_field11;
$this->link_field12=$link_opinion->link_field12;
$this->link_field13=$link_opinion->link_field13;
$this->link_field14=$link_opinion->link_field14;
$this->link_field15=$link_opinion->link_field15;
$this->link_group_id=$link_opinion->link_group_id;
return true;
}
$this->fullread = $this->read = false;
return false;
}