NP_PageBreak - completely (re)done!

Post your new plugins here!
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Mon Jan 10, 2005 12:25 am

roel wrote:@Moraes, did you see Gen's Bug Report on this plugin?

ok, it is solved! :-D

m.
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Wed Apr 06, 2005 7:29 pm

I am back with this plugin finally after ages, and I seem to be doing something pretty dumb here. The result I am getting on display is

Code: Select all

DISALLOWED (PageBreak)
.

My short template is:

Code: Select all

<DIV CLASS="powerintro"><B><%title%></B></DIV>
<DIV CLASS="powerintro"><%body%></DIV>
<%morelink%><%PageBreak(links)%><BR>

My detailed template is:

Code: Select all

<DIV class="itemhead"><%title%></DIV>
<DIV class="itembody">
<B>Date:</B> <%BetterDate(posted,F j)%>,
<%date(%Y)%> <BR>
<B>By:</B> <%CustomField(Byline)%> <BR>
<B>Source:</B> <%CustomField(Publication)%></DIV><BR>
<DIV class="itembody">
<%more%>
<%PageBreak(links)%>
<BR><BR>
<B>&copy;</B><%CustomField(Publication)%></DIV>

And I am using the breaks in the "Extended" part of the item. The "Body" part is just a teaser. e.g.

Code: Select all

<%PageBreak(The Myntdu-Leshka dam)%>


What might I be doing wroing here?
Subir Ghosh
www.newswatch.in
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Thu Apr 07, 2005 5:44 pm

SOS pls. 8O
Subir Ghosh

www.newswatch.in
User avatar
roel
Nucleus Guru
Nucleus Guru
Posts: 4469
Joined: Tue Apr 16, 2002 12:41 am
Location: Rotterdam, The Netherlands
Contact:

Postby roel » Thu Apr 07, 2005 9:23 pm

What happens when you use <%pagebreak%> (all letters lower case) instead of <%PageBreak%> ?
Is your question not solved yet?
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Thu Apr 07, 2005 9:45 pm

Aaaah Roel, the DISALLOWED bit seems to have been a case of upper/lower case. In fact, I had been careful in using PageBreak since that was how the plugin had been named.

But then, the DISALLOWED bit is gone, but now there is a problem of display. Nothing appears after the first pagebreak. i.e. there is no second page.

I guess this has something to do with the body/extended part that I had raised ages back. More of it in the next post.
Subir Ghosh

www.newswatch.in
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Thu Apr 07, 2005 9:50 pm

moraes wrote:@Subir, the aimed flexibility with body/extended parts will be solved before version 1.0 (I hope ;-)).


I believe the problem persists. Let me just outline in brief what I have done.
(i) Installed Rodrigo's plugin. :D No changes in the plugin settings at all.
(ii) The template codes are just what I had mentioned three posts previous. Of course there is also the link to extended entry in the Short template.
(iii) Teaser pasted in Body part. Whole story pasted in Extended part. <%pagebreak(name of title)%> used where I want the first page break.

What happens is this:
(i) The short display is fine, link too works fine.. into the main story.
(ii) However, in the main story only that portion appears which is before the pagebreak. Nothing after. I.e. there is no link to a subsequent page.
Subir Ghosh

www.newswatch.in
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Thu Apr 07, 2005 10:12 pm

Perhaps it would be a better idea to tell what is it that I am to convert.

It is this page: http://www.northeastvigil.com/issues/da ... ntents.htm and further. This is the contents page. Each link opens into an article -- most of which (not all) run into multiple pages.

It is a simple HTML section which I want to Nuke.
Subir Ghosh

www.newswatch.in
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

updated to include previous and paginate

Postby stevie » Mon Jun 06, 2005 4:36 am

Here are a few modifications I added to include: <%PageBreak(prev)%> and <%PageBreak(paginate)%> with some new control fields. Hope you enjoy...

See it in use at: http://www.allintune.com/

Code: Select all


<?php
/*****************************************/
/* NP_PageBreak                          */
/* ------------------------------------- */
/* by Rodrigo Moraes                     */
/* http://www.tipos.com.br               */
/*****************************************/
// Feedback is welcome here: http://nucleuscms.org/forum/viewtopic.php?t=3995
//
// 06/05/2005 - Previous and Paginate added by Steve Ackerman [steve@gonetpro.com]
//
 
class NP_PageBreak extends NucleusPlugin {
    function getName() { return 'Page Break'; }
    function getAuthor() { return 'Rodrigo Moraes'; }
    function getURL() { return 'http://www.tipos.com.br'; }
    function getVersion() { return '0.8.1'; }
    function getDescription() {
        return 'NP_PageBreak can break a post in multiple pages and create navigation links between them. Use &lt;%pagebreak(Page Title)%&gt; every time you want a page break in your posts. Useful for long texts, tutorials, presentations etc.'; }
    function supportsFeature($what) {
        switch($what) {
            case 'SqlTablePrefix': return 1;
            default: return 0;
        }
    }
 
    function install() {
        $this->createOption('navstart','Navigation links start tag','text','<div class="pagebreak">');
        $this->createOption('navend','Navigation links end tag','text','</div>');
        $this->createOption('titlestart','Page title start tag','text','<strong>');
        $this->createOption('titleend','Page title end tag','text','</strong>');
        $this->createOption('pagestart','Paginate start tag','text','<div class="paginate">');
        $this->createOption('pageend','Paginate end tag','text','</div>');
        $this->createOption('prevtext','Previous item','text','&lt;&lt; Prev Page');
        $this->createOption('prevstart','Previous page start tag','text','<div class="prevpage">');
        $this->createOption('prevend','Previous page end tag','text','</div>');
        $this->createOption('nexttext','Next item','text','Next Page &gt;&gt;');
        $this->createOption('nextstart','Next page start tag','text','<div class="nextpage">');
        $this->createOption('nextend','Next page end tag','text','</div>');
        $this->createOption('shownumbers','Show numbers before navigation links?','yesno','yes');
        $this->createOption('error','Error message when trying to access a non-existent page','text','This page doesn\'t exist. Use the navigation links to find what you want.');
    }
 
    function getEventList() { return array('PreItem'); }
 
    function event_PreItem(&$data,$page=1) {
        global $pagecount, $pagetitle, $page;
 
        $pagecount = 0;
        if (!getVar('page')) {
            $page = 1;
        }
        else {
            $page=getVar('page');
        }
 
        $z = 0;
        $parts=array('body','more');
        foreach ($parts as $part) {
 
            if (preg_match('/\<%pagebreak\(.*?\)%\>/', $data['item']->$part)) {
 
                preg_match_all('/\<%pagebreak\(.*?\)%\>/',$data['item']->$part,$tags);     
                $text = $data['item']->$part;
                foreach ($tags[0] as $tag) {
 
                    // let's get the page content...
                    $tagpos = strpos($text, $tag);
                    $pages[$z] = substr($text, 0, $tagpos);
 
                    // ... and now the page title
                    $end = strpos(substr($tag, 0), ')%>');
                    if ($pages[0]) {
                        $pagetitle[$z+1] = substr($tag, 12, $end-12);
                    }
                    else {
                        $pagetitle[$z] = substr($tag, 12, $end-12);
                    }
 
                    // finally, let's forget used data and go back to the beginning
                    $tagend = $tagpos + strlen($tag);
                    $text = substr($text, $tagend, strlen($text)-$tagend);
                    $z++;
                } // foreach ($tags[0] as $tag)
 
                // this is the last page content of each item part
                $pages[$z] = substr($text, 0, strlen($text));
                $z++;
                if (!$pages[0]) {
                    $pagearray = $page;
                }
 
                else {
                    $pagearray = $page - 1;
                    $pagetitle[0] = $data['item']->title;
                }
               
                // check if page exists
                if (!$pages[$pagearray]) {
                    $data['item']->$part = $this->getOption('error');
                }
                else {
                                        // full mode = show all parts
                                        if (getVar('mode') == 'full') {
                                                $data['item']->$part = '';
                                                $n = 0;
                                                foreach($pages as $pagepart) {
                                                        if (!$pages[0]) {
                                                                if ($z == 1) {
                                                                        echo $this->getOption('titlestart');
                                                                        echo $pagetitle[$n];
                                                                        echo $this->getOption('titleend');
                                                                        echo $pagepart;
                                                                $n++;
                                                                }
                                                                $z = 1;
                                                        }
                                                        else {
                                                                if ($n != 0) {
                                                                        echo $this->getOption('titlestart');
                                                                        echo $pagetitle[$n];
                                                                        echo $this->getOption('titleend');
                                                                }
                                                                echo $pagepart;
                                                                $n++;
                                                        }
                                                }
                                        } // end of full mode
                                        else {
 
                                                if ($pages[0] && $page == 1 || !$pagetitle[$page-1]) {
                                                        $data['item']->$part = '';
                                                }
                                                else {
                                                        $data['item']->$part = $this->getOption('titlestart') . strip_tags($pagetitle[$page-1]) . $this->getOption('titleend');
                                                }
                                                if ($pages[0]) {
                                                        $data['item']->$part .= $pages[$pagearray];
                                                }
                                                else {
                                                        $strip_br = explode("\r", $pages[$pagearray], 2);
                                                        $data['item']->$part .= $strip_br[1];
                                                }
                                        }
                }
                $pagecount = count($pagetitle);
                        //} // if (getVar('mode') != 'full')
            } // if (preg_match
        } // foreach ($parts as $part)
    } // event_PreItem
   
    function doTemplateVar(&$item) {
        global $pagecount, $pagetitle, $page;
 
        if ($pagecount > 1) {       
            $params = func_get_args();
            $link = createItemLink($item->itemid);
 
            if ($params[1] == 'links') {
 
            // create navigation if one or more pagebreaks are found
                echo $this->getOption('navstart'),"\n";
                echo "<ul>\n";
                for ($n = 0; $n < $pagecount; $n++) {
                    $z = $n + 1;
                    echo "<li>";
                    if ($this->getOption('shownumbers') == 'yes') {
                        echo $z,". ";
                    }
                    if ($z != $page) {
                        echo "<a href=\"$link&amp;page=$z\">";
                    }
                    if (trim($pagetitle[$n])) {
                        echo $pagetitle[$n];
                    }
                    else {
                        echo "page $z";
                    }
                    if ($z != $page) {
                        echo "</a>";
                    }
                    echo "</li>\n";
                }
                echo "</ul>\n";
                echo $this->getOption('navend');
            }
 
            if ($params[1] == 'next') {
                $next = $page+1;
                if ($next <= $pagecount) {
                    echo $this->getOption('nextstart');
                    echo "<a href=\"$link&amp;page=".$next."\">";
                    if (trim($pagetitle[$page])) {
                        echo $pagetitle[$page];
                    }
                    else {
                       echo $this->getOption('nexttext');
                    }
                    echo "</a>";
                    echo $this->getOption('nextend');
                }
            }
 
            if ($params[1] == 'prev') {
                $prev = $page-1;
                if (($prev <= $pagecount) && ($prev >= 1)) {
                    echo $this->getOption('prevstart');
                    echo "<a href=\"$link&amp;page=".$prev."\">";
                    if (trim($pagetitle[$page])) {
                        echo $pagetitle[$page];
                    }
                    else {
                        echo $this->getOption('prevtext');
                    }
                    echo "</a>";
                    echo $this->getOption('prevend');
                }
            }
 
            if ($params[1] == 'paginate') {
            
            // create navigation if one or more pagebreaks are found
               $next = $page+1;
               $prev = $page-1;
               echo $this->getOption('pagestart');
               if( $page == 1 ) {
                  echo $this->getOption('prevtext');
                  echo "&nbsp;&nbsp;&nbsp;";
                  
               } elseif( $page >= 2 ) {
                  echo "<a href=\"$link&amp;page=".$prev."\">";
                  echo $this->getOption('prevtext');
                  echo "</a>";
                  echo "&nbsp;&nbsp;&nbsp;";
               }
               for ($n = 0; $n < $pagecount; $n++) {
                  $z = $n + 1;
                  
                  if ($z != $page) {
                     echo "<a href=\"$link&amp;page=$z\">$z</a>";
                  } else {
                     echo "$z";
                  }
                  echo "&nbsp;&nbsp;&nbsp;";
               }
               if ($next <= $pagecount) {
                  echo "<a href=\"$link&amp;page=".$next."\">";
                  echo $this->getOption('nexttext');
                  echo "</a>";
               } else {
                  echo $this->getOption('nexttext');
               }
               echo $this->getOption('pageend');
            }
        }
    } // doTemplateVar
} // class
?>

User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Re: updated to include previous and paginate

Postby subirghosh » Mon Jun 06, 2005 10:48 am

stevie wrote:Here are a few modifications I added to include: <%PageBreak(prev)%> and <%PageBreak(paginate)%> with some new control fields. Hope you enjoy...


Stevie: the output certainly does look what I would like it to be. Could you throw some light on the usage commands? Would be grateful.

Thanks.

Subir
Subir Ghosh

www.newswatch.in
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

Usage

Postby stevie » Mon Jun 06, 2005 4:06 pm

Certainly,

I simply extended the functionality of this plugin... The design made it really simple...

<%pagebreak()%> and <%pagebreak(title)%> are used exactly as before...

<%PageBreak(links)%> and <%PageBreak(next)%> also work exactly as they did... no changes to them at all.

<%PageBreak(prev)%> is used exactly as you would use <%PageBreak(next)%> only it allows you to move in the opposite direction.

<%PageBreak(paginate)%> is used in much the same way you would use <%PageBreak(links)%> except that it will display horizontally, with a 'pagination style' look.

The additional options just extend what was already in place to customize the look of these new functions...

The only modifications made were located in the install() function and at the end of the file... The if ($params[1] == 'prev') {} and if ($params[1] == 'paginate') {} blocks of code were added...

Steve
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Tue Jun 07, 2005 3:19 am

Thanks Steve. I believe the Pagebreak functionality should be a part of the core code.
Subir Ghosh

www.newswatch.in
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

Postby stevie » Tue Jun 07, 2005 3:47 am

I definitely agree... The app would be useless to me without it...

S
Hiro
Posts: 419
Joined: Tue Aug 03, 2004 2:36 pm
Location: Italy
Contact:

Postby Hiro » Thu Jun 09, 2005 11:47 am

Rodrigo, it isn't yet clear to me if the plugin has some capability to show, beside the title of the article, also the number of what the current page is (eg. "itemtitle title - part 2"). Maybe there is some hidden tag?
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

PageBreak and blog or otherblog...

Postby stevie » Sat Jun 11, 2005 11:46 am

PageBreak and blog or otherblog...

Has anyone got this to work?

It seems Pagebreak takes the pagecount from blog and otherblog when used together. I have otherblog in my skin displaying linked titles and PageBreak in my article template. Even though there are only 2 pages in the article, it shows as 9 in the PageBreak list. The 2 pages link fine but the rest show the PageBreak error...

I took out my paginate addition and tried to rename the $page variables to see if that would help but it didn't do a thing...

Any ideas on how to resolve this?

Steve
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

Discovered the problem...

Postby stevie » Mon Jun 13, 2005 6:08 pm

Well its seems that when you use NP_PageBreak within your post and you use blog or otherblog within your skin, NP_PageBreak will take the pagecount from the largest article listed including blog, otherblog and the current article.

An example: The current article might contain 3 pages, the leftnav consists of the last 15 articles displaying only the title. Average articles contain 3-5 pagebreaks. I have 1 article listed that contains 9 pagebreaks. NP_PageBreak shows the current article as having 9 pages but when you visit pages 4-9, the page error shows "This page doesn't exist. Use the navigation links to find what you are looking for."

I haven't tried but I imagine it will perform the same with other pluging like NP_TopRated.php, NP_MostViewed.php, etc.

For some reason NP_PageBreak is not counting the current item... At least that is what I have found so far...

S
sircambridge
Posts: 277
Joined: Thu Jun 02, 2005 7:39 pm
Contact:

Postby sircambridge » Fri Jun 17, 2005 1:34 am

BUG (maybe?)

there is a mysterious extra </div> that appears at the end of the navigation list, but it ONLY occurs on the last page?

here is an example of the 2nd page which works :
http://www.sircambridge.net/nucleus/?itemid=34&page=2

and the third page that has an extra </div>
http://www.sircambridge.net/nucleus/?itemid=34&page=3

ive been playing with the code and I dont see where it is coming from..

EDIT : nevermind, its fixed, i was just being dumb, sorry :)
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Re: Usage

Postby subirghosh » Mon Jun 20, 2005 5:06 pm

stevie wrote:<%PageBreak(paginate)%> is used in much the same way you would use <%PageBreak(links)%> except that it will display horizontally, with a 'pagination style' look.

Sorry for the belated reaction, Steve, I hadn't been able to try it out. And now that I have, well... :D So many problems in my life seem to have just vanished.

Great one, this Paginate thing.
Subir Ghosh

www.newswatch.in
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

yes it is nice...

Postby stevie » Tue Jun 21, 2005 7:14 am

yes it is nice... but when you use this plugin, there is a serious limitation that needs to be addressed. Anytime you show more than a single article on a page, the plugin uses the page count from article with the most pagebreaks so using otherblog or something like that for a navigation is out of the question. I haven't found a way to get past this yet.

Take a look at www.allintune.com, Go to any article listed... This is a prime example of the bug in action...

Steve
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Re: yes it is nice...

Postby subirghosh » Tue Jun 21, 2005 7:59 am

Well, Steve. My site is still under construction; so I can't find all the bugs as yet.


stevie wrote: Anytime you show more than a single article on a page, the plugin uses the page count from article with the most pagebreaks


Lol. Yes, all your articles SHOW nice pages. And when you go to the ninth page we get the error message "This page doesn't exist. Use the navigation links to find what you are looking for." You might have to tinker around with the templates I guess. Because I did some trial and error and came up with the solution I want. Right, minus the problem you mentioned.

My short template on the index page remains the same: <%body%><%morelink%> etc and all that. In the Item template I just have "<%more%><%PageBreak(paginate)%>".

And in the Item itself, I have the first para as the teaser in Body.. and the actual story in the Extended Body part. And it works fine MINUS the bug. I can circumvent the problem but a couple will remain:

(i) If you use <%body%><%more%><%PageBreak(paginate)%>, then the first para will appear with ALL the pages. So, this is a question of usage only and can be avoided.
(ii) If you put <%pagelinks%> in the short template of the index page, then the bug you mentioned will appear. It will show the maximum number of pages etc.
Subir Ghosh

www.newswatch.in
stevie
Posts: 9
Joined: Mon Sep 06, 2004 8:56 am

Postby stevie » Tue Jun 21, 2005 8:07 am

It is actually pulling in the pagecount from the largest item listed on my left nav using otherblog within my skin. Basically the plugin is counting the pages from the wrong item and I have not found a way to get around this yet...

Steve

Return to “Plugin Development”