• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Prev / Next for CGBlog
PostPosted: Tue Dec 13, 2011 5:02 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Thu Mar 23, 2006 9:25 am
Posts: 1868
Location: The Netherlands
After intensive puzzling, trying, testing, re-trying, I think I made the UDT prev_next working for cgblog.

Two things I did to get it working.

First the create a UDT named prev_next (actually changed the code used with news in another topic):
\$1:
if (!function_exists('MyGetModuleInstance'))
{
        function &MyGetModuleInstance($module)
        {
                global $gCms;

                if (isset($gCms->modules[$module]) &&
                        $gCms->modules[$module]['installed'] == true &&
                        $gCms->modules[$module]['active'] == true)
                {
                        return $gCms->modules[$module]['object'];
                }
                // Fix only variable references should be returned by reference
                $tmp = FALSE;
                return $tmp;
        }
}

$gCms = cmsms();
$db = cmsms()->GetDb();    // changed this line.
$cgblog = cms_utils::get_module('CGBlog');  // changed this line.

// call from cgblog detail_template: {prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate}
$pageid = ($_REQUEST['pageid']) ? $_REQUEST['pageid'] : $params['pageid'];
$currid = ($_REQUEST['currid']) ? $_REQUEST['currid'] : $params['currid'];  // added this line for testing purposes.
$currdate = $params['currdate'];
if(!$currdate) return;

// call from cgblog detail_template: {prev_next pageid=$page_id currid=$entry->id currdate=$entry->postdate}

// For performance, added an index over two columns on ".cms_db_prefix()."module_cgblog_blog_categories

// get all CGBlog articles sorted by ascending date
$query_next = "
SELECT cgblog_id, cgblog_title
FROM ".cms_db_prefix()."module_cgblog
WHERE cgblog_date > ?
AND status = 'published'
AND (end_time >= CURRENT_DATE OR end_time IS NULL)
AND cgblog_id IN
   ((SELECT blog_id
   FROM ".cms_db_prefix()."module_cgblog_blog_categories
   WHERE category_id IN
     (SELECT category_id
     FROM ".cms_db_prefix()."module_cgblog_blog_categories
     WHERE blog_id = ".$currid.")))
ORDER BY cgblog_date
ASC LIMIT 1";

$result_next =& $db->GetRow($query_next,array($currdate));

$query_prev = "
SELECT cgblog_id, cgblog_title
FROM ".cms_db_prefix()."module_cgblog
WHERE cgblog_date < ?
AND status = 'published'
AND (end_time >= CURRENT_DATE OR end_time IS NULL)
AND cgblog_id IN
   ((SELECT blog_id
   FROM ".cms_db_prefix()."module_cgblog_blog_categories
   WHERE category_id IN
     (SELECT category_id
     FROM ".cms_db_prefix()."module_cgblog_blog_categories
     WHERE blog_id = ".$currid.")))
ORDER BY cgblog_date
DESC LIMIT 1";

// end of get all CGBlog items

$result_prev = &$db->GetRow($query_prev,array($currdate));

if($result_next['cgblog_id']) {
$aliased_title = munge_string_to_url($result_next['cgblog_title']);
$prettyurl = 'logboek/' . $result_next["cgblog_id"] .'/'.$pageid."/$aliased_title";
$next_uri = $cgblog->CreateLink('cntnt01', 'detail', $pageid, '', array('articleid' => $result_next["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$next_uri = "";
}


if($result_prev['cgblog_id']) {
$aliased_title = munge_string_to_url($result_prev['cgblog_title']);
$prettyurl = 'logboek/' . $result_prev["cgblog_id"] .'/'.$pageid."/$aliased_title";
$prev_uri = $cgblog->CreateLink('cntnt02', 'detail', $pageid, '', array('articleid' => $result_prev["cgblog_id"]) ,'', true, false, '', true, $prettyurl);
}else{
$prev_uri = "";
}

$smarty->assign('cgblog_next_url', $next_uri);
$smarty->assign('cgblog_next_text', $cgblog->lang("next"));
$smarty->assign('cgblog_prev_url', $prev_uri);
$smarty->assign('cgblog_prev_text', $cgblog->lang("prev"));


This query is quit heavy for the database because of the three nested select-statements. To reach an acceptable performance, I created an extra index over both columns on
\$1:
cms_module_cgblog_blog_categories

type of index is 'Primary'. This helped to reduce the execution time from 15sec to far less than a second.

A working example can be found at my site http://www.uisge-beatha.eu/logboek/270/76/Vijfde-in-de-clubwedstrijd.html

If one sees any improvements or suggestions, please let me know.

Gregor


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Prev / Next for CGBlog
PostPosted: Tue Dec 13, 2011 11:13 am 
Offline
Power Poster
Power Poster

Joined: Sun Apr 19, 2009 9:33 am
Posts: 1381
----------

_________________
The CMSMS Builder is a tool to help you develop and optimize CMS Made Simple >= 2.2.3 themes, it is made by a developer for developers.

I you like an automated file based work-flow this project might be for you. It is usable to kick-start a new CMSMS project or it can be applied to existing ones.


Last edited by arnoud on Tue Mar 12, 2013 5:55 pm, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Prev / Next for CGBlog
PostPosted: Tue Dec 13, 2011 11:56 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Thu Mar 23, 2006 9:25 am
Posts: 1868
Location: The Netherlands
Thanks Arnoud. Removed it. It was there ever since :)

Gregor


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Prev / Next for CGBlog
PostPosted: Wed May 09, 2012 3:10 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Fri Nov 30, 2007 9:15 am
Posts: 350
Here is my solution for adding prev/next links in the CGBlog detail pages.
You should be able to easily change this to work for the news module...

http://www.i-do-this.com/blog/72/Prev-Next-links-in-CGBlog

Greetings,
Manuel

_________________
Do you like your open source cms? Buy from the CMSMS partners || Donate
(or at least share some knowledge :D >> See some of my stuff )


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Prev / Next for CGBlog
PostPosted: Wed May 23, 2012 3:04 am 
Gregor, thanks for the update on that UDT, and Manuel, your solution is also a winner! Thanks!


Top
   
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
A2 Hosting