Thursday, October 1, 2009

MC Fixing the front page issue with differing number of front page stories

The problem with this was that the index.php file did only a single search, an then as the information recovered here worked it's way through the other files, my added code split it up between the two categories.

The problem with this is that if all eight latest stories are only News, then no Opinion stories show up on the front page. To solve this, I had to establish two separate searches, which started off being split by category.

Fortunately, the GET[category] code already existed to do this, so it was possible to adapt this code to create a search of only one category. The difficulty was how, but fortunately, after chaining a hundred monkeys to a hundred computers, I lucked out on a way of doing this without major changes.

Emphisis should be placed on the fact that this hasn't been fully tested yet; my local copy only has four stories at the moment, so I am unsure how it will effect multiple copies.

Anyway, here are the changes.

index.php


For the code


// 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;

}


// 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;


Alter to


// 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();

}

}elseif(!isset($_REQUEST['category'])){

$catnameopinion = opinion;

if(isset($catnameopinion)){

$thecatopinion = get_cached_category_data('category_safe_name', sanitize($catnameopinion, 1));

$thecatopinion = $thecatopinion->category_name;

if (!$thecatopinion)

{

$main_smarty->assign('tpl_center', '404error');

$main_smarty->display($the_template . '/pligg.tpl');

die();

}

}

}


// start a new search

$search=new Search();

$search2=new Search();


// check for some get/post

if(isset($_REQUEST['from'])){

$search->newerthan = sanitize($_REQUEST['from'], 3);

$search2->newerthan = sanitize($_REQUEST['from'], 3);

}

unset($_REQUEST['search']);

unset($_POST['search']);

unset($_GET['search']);

if(isset($_REQUEST['search'])){$search->searchTerm = sanitize($_REQUEST['search'], 3);

$search2->searchTerm = sanitize($_REQUEST['search'], 3);}

if(isset($_REQUEST['search'])){$search->filterToStatus = "all";

$search2->filterToStatus = "all";}

if(!isset($_REQUEST['search'])){$search->orderBy = "link_published_date DESC";

$search2->orderBy = "link_published_date DESC";}

if(isset($_REQUEST['tag'])){$search->searchTerm = sanitize($_REQUEST['search'], 3); $search->isTag = true;

$search2->searchTerm = sanitize($_REQUEST['search'], 3); $search2->isTag = true;}

if(isset($thecat)){

$search->category = $thecat;

}

if(isset($thecatopinion)){

$search2->category = $thecatopinion;

}


// figure out what "page" of the results we're on

$search->offset = (get_current_page()-1)*$page_size;

$search2->offset = (get_current_page()-1)*$page_size;


// pagesize set in the admin panel

$search->pagesize = $page_size;

$search2->pagesize = $page_size;


// since this is index, we only want to view "published" stories

$search->filterToStatus = "published";

$search2->filterToStatus = "published";


// this is for the tabs on the top that filter

if(isset($_GET['part'])){$search->setmek = $db->escape($_GET['part']);

$search2->setmek = $db->escape($_GET['part']);}

$search->do_setmek();

$search2->do_setmek();


// do the search

$search->doSearch();

$search2->doSearch();


$linksum_count = $search->countsql;

$linksum_sql = $search->sql;

$linksum_count_opinion = $search2->countsql;

$linksum_sql_opinion = $search2->sql;


And for


// misc smarty

if(isset($from_text)){$main_smarty->assign('from_text', $from_text);}

if(isset($search->setmek)){$main_smarty->assign('setmeka', $search->setmek);}else{$main_smarty->assign('setmeka', '');}


to


// 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', '');}




libs/link_summery.php


at the top of the page, add


if($ls_debug == true){echo '
' . sanitize($rows,3) . '
';}

$links = $db->get_col($linksum_sql);

$the_results = $links;

$links_opinion = $db->get_col($linksum_sql_opinion);

$the_results_opinion = $links_opinion;


And at the bottom of the page, for


if ($links) {

foreach($links as $link_id) {

$link->id=$link_id;

$link->read();

$link_summary_output .= $link->print_summary('summary', true);

$news_link_summary_output .= $link-> print_news_summary('summary', true);

$opinion_link_summary_output .= $link-> print_opinion_summary('summary', true);

}

}


alter to


if ($links || $links_opinion) {

foreach($links as $link_id) {

$link->id=$link_id;

$link->read();

$link_summary_output .= $link->print_summary('summary', true);

$news_link_summary_output .= $link-> print_news_summary('summary', true);

}

foreach($links_opinion as $link_id) {

$link->id=$link_id;

$link->read();

$opinion_link_summary_output .= $link-> print_opinion_summary('summary', true);

}

}

No comments:

Post a Comment