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:

NP_PageBreak - completely (re)done!

Postby moraes » Fri Jun 18, 2004 9:45 pm

This is a nice feature I´ve seen in WordPress. When you place a "page break" tag (<%pagebreak%>) inside an item, it is broken in multiple pages (how many you want) with navigation links. Useful for long texts, presentations, reviews and tutorials...

Get the code and instructions here at the wiki: http://wakka.xiffy.nl/PageBreak

Somebody asked this plugin sometime ago, explaining how it could be used:
"Let's say I'm writing a review of a new gfx-card. It would be very useful to be able to split it into different sections, like benchmarks, drivers, conclusion and so on. The easiest way, from a user-point of view of course, would be to just add something like a <%pagebreak%> command where the page should end and another begin. Maybe it could even be possible to name the pages with a little title-tag, like so: <%pagebreak title="conclusion"%>."

Well, the title feature is not implemented (yet), but now you can break your items in how many parts you want by adding <%pagebreak%> where a page should end and another begin. ;-)

The plugin idea was also discussed here.
enjoy! :D
m.
Last edited by moraes on Fri Sep 10, 2004 5:32 pm, edited 1 time in total.
User avatar
radekradek
Posts: 668
Joined: Tue Dec 30, 2003 10:48 pm
Location: Prague, Czechia
Contact:

Postby radekradek » Fri Jun 18, 2004 10:27 pm

that's a very good idea moraes! :)
--= BLOG:CMS developer =--
web|LOG :: GET OPERA!
User avatar
Trent
Nucleus Guru
Nucleus Guru
Posts: 1534
Joined: Fri Oct 04, 2002 5:08 pm
Location: Alberta, Canada
Contact:

Postby Trent » Sat Jun 19, 2004 4:15 am

Wicked plugin Moraes. This works really well for a project that I was thinking of doing! Thanks!

Trent
Life Through The Eyes Of Trent Adams!
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Sat Jun 19, 2004 7:45 am

Thanks, Radek! Nice, Trent!

I´m trying to find the best way, from a user point of view, to have the title links done without much effort. The numbered links should remain as default.

The suggestion <%pagebreak title="conclusion"%> doesn´t sound good, since the first page would not have a title, and it should have when we are not there. If <%pagebreak title="conclusion"%> was also placed in the post beginning it would be strange (well, it is strange to start a post with a page break - !).

So I´m thinking about checking the first line from each part to get the title, if they have some kind of markup. Let´s say, if the first line starts with <%blabla%>, the plugin will understand that "blabla" is a title, and use it as link. If not, it will use default numbered link for that part.

Do you think this is easy enough? I´m also concerned about performance aspects...

A user-defined delimiter should be placed as an option or argument, I´m not sure what would be best. Since the pagebreak tag should be easy to use, I think a plugin option should be better (no changes on the <%pagebreak%> tag, so it would be easy to remember, and it should be, at least before a tool that adds it with a button).

m.
ehman
Posts: 19
Joined: Sat Jan 24, 2004 1:12 pm

Postby ehman » Sat Jun 19, 2004 10:39 am

Nice work, :D one suggestion though, after i played around with it a bit.

maybe its just me but it seems better to have pagebreak only work in the extended entry. That way only the detailed story can be split.

replace

Code: Select all

 $pages = explode('<%pagebreak%>', $data['item']->body);


with

Code: Select all

 $pages = explode('<%pagebreak%>', $data['item']->more);

making sure the body dosent repeat.

Code: Select all

if ($page == 1) {
$data['item']->more= $pages[$pagearray];
} else if ($page > 1){
$data['item']->body="";
$data['item']->more= $pages[$pagearray];
}


Also this way if you want to implement <%pagebreak="title of something"%> the title of the first page can just be the title of the item.
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Sun Jun 20, 2004 8:36 am

ehman wrote:maybe its just me but it seems better to have pagebreak only work in the extended entry. That way only the detailed story can be split.

I don´t see why to restrict the use of <%pagebreak%> to the extended part. Using it in the body part, you even don´t need the extended part. And you can 'extend' the extended part by using it there, spliting it in multiple pages. Some people will decide to use it in the body, others will prefer to use it in the extended part. It will depend on how the templates are built and the purpose of the split. So I´m just thinking to make it flexible.

About the title thing, I will give an example of how it could be nice. Suppose you write a CSS tutorial, named "Cascading Style Sheets Guide", and split it in 5 parts. You may want that the main title appears on each part, and plus the part subtitle. Let´s say, the first part would start with:

Cascading Style Sheets Guide
1. About the CSS2 Specification

It would be nice to have a "table of contents" on each part, which would be a list of links (using the part subtitles, if defined). Even the first part could be named, and not necessarily using the item title (the item title would be the *main* title). The part names would be, in fact, "subtitles". This is how most tutorial sites handles long texts.

So, the plugin would search each part for its title. I´m thinking to do it with a simple tag inside each part. It would still be simple to use: <%pagebreak%> breaks the item, <%title%> names each part. If you don´t use a title, that´s ok: the plugin makes numbered links. If you use, you will have a "table of contents" with the titles. Flexible, simple and cool. :wink:

This is simple to do, I suppose. Basically string manipulation. I´ll give a try this week, if nobody wants to do it first. :D
m.
ehman
Posts: 19
Joined: Sat Jan 24, 2004 1:12 pm

Postby ehman » Sun Jun 20, 2004 6:24 pm

alright that sounds really cool :D i am thinking about putting some tutoirals up on a site so i really looking forward to it.
Hiro
Posts: 419
Joined: Tue Aug 03, 2004 2:36 pm
Location: Italy
Contact:

Postby Hiro » Sat Aug 14, 2004 11:07 am

Rodrigo, I finally got it working, with changing all body instances (array's too) with more...
Now I have to figure how to do for getting also the footnotes going automatically with the splitted page (they do have anchors right now) without pasting each right before any pagebreak.
User avatar
gRegor
Posts: 738
Joined: Tue May 14, 2002 3:17 am
Location: Bellingham, WA
Contact:

Postby gRegor » Sat Aug 14, 2004 1:07 pm

I like the idea of this plugin a lot.. I'm sure I can find a use for it sometime down the road.

Would it be too hard to implement another tag, like <%pagetitle(this is the section title)%> ?
— gRegor
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

DISALLOWED (PageBreak)

Postby subirghosh » Sun Sep 05, 2004 8:48 pm

I have done the following in this order:

(i) Downloaded the code
(ii) Installed it (withoutout hitches).
(iii) Updated the subscriptions
(iv) Put <%PageBreak%> in the /full and /short templates just after the <%body%> tag
(v) Put <%PageBreak%> in the story where I wanted the pagebreaks.

The desired effect is not happenning and instead I am getting the error message: DISALLOWED (PageBreak).

I guess we get this error message if we put the code in the wrong place in the skin, and not template? Or when there is a uppercase/lowercase problem?

:?:
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Sun Sep 05, 2004 10:52 pm

I'm not sure how this plugin is working. This was a beta release and I've never finished it. :(

Does anybody have it working?
m.
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Oh :O

Postby subirghosh » Mon Sep 06, 2004 4:14 pm

8O oh really?

No wonder then perhaps why it is not working :lol:

Oh Moraes, when can you make it work? :twisted:
Hiro
Posts: 419
Joined: Tue Aug 03, 2004 2:36 pm
Location: Italy
Contact:

Postby Hiro » Mon Sep 06, 2004 5:55 pm

Mine is finally working (Rodrigo, if u did cared about my replies, you were aware of it).
Check out in the plugin whether you have "pagebreak" or "nextpage".
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Mon Sep 06, 2004 6:10 pm

Hiro wrote:Rodrigo, if u did cared about my replies, you were aware of it.

I do care, I just reply too quickly sometimes. :lol:
Can you share the code you are using and some info to get it working with us? Please? ;-)

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

Please!

Postby subirghosh » Tue Sep 07, 2004 4:05 am

Yes Hiro, please do share :lol: :D
Hiro
Posts: 419
Joined: Tue Aug 03, 2004 2:36 pm
Location: Italy
Contact:

Postby Hiro » Tue Sep 07, 2004 9:45 am

code? I said, I just changed "nextpage" with "pagebreak" in the plugin itself, that's all. Maybe you are using the version with "nextpage" inside, instead of "pagebreak" (Rodrigo, pliz check our previous exchanges about).
I'm using <%pagebreak%> in the templates after the extended body.
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Still sumtin wrong

Postby subirghosh » Tue Sep 07, 2004 3:22 pm

I made the modifications indicated in the original plugin code and made it as follows:

<?php
/*****************************************/
/* NP_PageBreak */
/* ------------------------------------- */
/* by Rodrigo Moraes */
/* http://www.tipos.com.br */
/*****************************************/
// History
// 0.1b - Initial release: basic functionallity is done.
// TODO: FancyURL compatibility, page number check, next/previous links and some cosmetic improvements.
// Nice idea: give each page a title to be used as link (good for tutorials, chapters...).
// Feedback is welcome here: http://nucleuscms.org/forum/viewtopic.php?t=3995

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.1b'; }
function getDescription() {
return 'Allows multiple pages posts (how many extended texts you want). It breaks a post as defined by you and creates navigation links. Use &lt;%pagebreak%&gt; every time you want a page break in your post. Useful for long texts, tutorials, presentations etc.'; }

function supportsFeature($what) {
switch($what) {
case 'SqlTablePrefix':
return 1;
default:
return 0;
}
}

function getEventList() { return array('PreItem'); }

function event_PreItem(&$data,$page=1) {
global $pagecount;

$page=getVar('page');

$parts=array('body','more');
foreach ($parts as $part) {

// body part
if ($part=='body') {
if (preg_match('<%pagebreak%>', $data['item']->body)) {
$data['item']->body = stripslashes($data['item']->body);
// Count number of pages
$pages = explode('<%pagebreak%>', $data['item']->body);
$pagecount = count($pages);
// Check current page number and set the first page if no one
if (!$page || $page > $pagecount) {
$page = 1;
}
$pagearray = $page - 1;
// Show the current body part
$data['item']->body = $pages[$pagearray];
}
}
// end of body part
// more part (MY ADDITON)
if ($part=='more') {
if (preg_match('<%pagebreak%>', $data['item']->more)) {
$data['item']->more = stripslashes($data['item']->more);
// Count number of pages
$pages = explode('<%pagebreak%>', $data['item']->more);
$pagecount = count($pages);
// Check current page number and set the first page if no one
if (!$page || $page > $pagecount) {
$page = 1;
}
$pagearray = $page - 1;
// Show the current body part
$data['item']->body = $pages[$pagearray];
}
}
// end of more part
// Note: extended part page break is not implemented in the beta version.
// To do it, duplicate the body part code and replace 'body' by 'more'
}

} // event_PreItem
function doTemplateVar(&$item) {
global $pagecount;
$itemid = $item->itemid;

// Check if there is more than one page
if ($pagecount > 1) {
$n = 1;
while ($n <= $pagecount) {
// Must use this for smart link & FancyURLs: $itemlink = createItemLink($itemid);
echo "<a href=\"index.php?itemid=$itemid&page=$n\">page $n</a> | ";
$n++;
}
}
} // doTemplateVar
} // class
?>


My code in the xyz/full template Item Body is:
<DIV class="headline"><%title%></DIV>
<DIV class="creditbody">
<B>Date:</B> <%BetterDate(posted,F j)%>,
<%date(%Y)%> <B>By:</B> <%CustomField(Byline)%> <B>Source:</B> <%CustomField(Source)%></DIV><BR>
<DIV class="itembody">
<%body%>
<%pagebreak%>
<BR><BR>
&copy; <I><%CustomField(Source)%></I>
</DIV>


And I am putting the <%pagebreak%> in the item wherever I wanted the break. The results look much better now... the page breaks are there. But there is a different problem now.

The story is starting with the extended portion both on the MainPage as well as the ItemPage. It is disregarding whetever is there in the Body portion in the Item. I have the first para of the story in the Body section. And the subsequent text in the Extended section.

And if I paste the entire story in the Body itself, then it shows everything in the Main Page till the first pagebreak that is indicated.

Ideally, the look and feel should be like this: The MainPage using the short template should show the first para only with the LinkToExtendedEntry. And the first pagebreak should be applicable only when it is so indicated in the Extended section.
Hiro
Posts: 419
Joined: Tue Aug 03, 2004 2:36 pm
Location: Italy
Contact:

Postby Hiro » Tue Sep 07, 2004 3:44 pm

uhu
I solved using the body as a short teaser, and using the extended body as the real article. For the behavior you wish to achieve, I guess there's need of some plugin to extend/break both the body and the extended part; but IMO I cannot see any utility for such a effect. In this case, I guess it might be rather much more useful some plugin for kind of "top news" posting.

here is the code I modified for my needs (*only extended body*), and it works:

Code: Select all

<?php
/*****************************************/
/* NP_PageBreak                          */
/* ------------------------------------- */
/* by Rodrigo Moraes                     */
/* http://www.tipos.com.br               */
/*****************************************/
//    History
//    0.1b - Initial release: basic functionallity is done.
//    TODO: FancyURL compatibility, page number check, next/previous links and some cosmetic improvements.
//    Nice idea: give each page a title to be used as link (good for tutorials, chapters...).
//    Feedback is welcome here: http://nucleuscms.org/forum/viewtopic.php?t=3995

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.1b'; }
    function getDescription() {
        return 'Allows multiple pages posts (how many extended texts you want). It breaks a post as defined by you and creates navigation links. Use &lt;%pagebreak%&gt; every time you want a page break in your post. Useful for long texts, tutorials, presentations etc.'; }
       
    function getEventList() { return array('PreItem'); }
   
    function event_PreItem(&$data,$page=1) {
        global $pagecount;



        $page=getVar('page');
       
        $parts=array('more');
        foreach ($parts as $part) {


            // more part
            if ($part=='more') {
                if (preg_match('<%pagebreak%>', $data['item']->more)) {
                    $data['item']->more = stripslashes($data['item']->more);
                    // Count number of pages
                    $pages = explode('<%pagebreak%>', $data['item']->more);
                    $pagecount = count($pages);
                    // Check current page number and set the first page if no one
                    if (!$page || $page > $pagecount) {
                        $page = 1;
                    }
                    $pagearray = $page - 1;
                    // Show the current more part
                    $data['item']->more = $pages[$pagearray];
                }
            }
            // end of more part
           
            // Note: extended part page break is not implemented in the beta version.
            // To do it, duplicate the more part code and replace 'more' by 'more'
        }
   
    } // event_PreItem
    function doTemplateVar(&$item) {
        global $pagecount;
        $itemid = $item->itemid;
       
        // Check if there is more than one page
        if ($pagecount > 1) {
            $n = 1;
            while ($n <= $pagecount) {
                // Must use this for smart link & FancyURLs: $itemlink = createItemLink($itemid);
                echo "<a href=\"index.php?itemid=$itemid&page=$n\">$n</a>&nbsp;&nbsp;";
                $n++;
            }
        }
    } // doTemplateVar
} // class
?>
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Tue Sep 07, 2004 5:17 pm

Thank you very much, Hiro.
I'm glad to see it is working. The pagetitle option is a must have for this plugin (each piece can have it's own subtitle), and I hope when I have my computer back I can help develop this. :-)

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

To quite an extent

Postby subirghosh » Tue Sep 07, 2004 6:00 pm

Yes Hiro, I follow what you are doing. But there are a couple of more areas that need to be worked on. Can I do some thinking aloud?

Moraes had initially suggested putting <%pagebreak%> aftter <%body%> in both the short and full templates. This will cause a problem if you don't use pagination uniformly throughout. This is because that would be applying the tag to the Body element of all stories.

So the <%pagebreak%> tag must be in the full template only i.e. apply it only to the Extended section. What Hiro did was to make it work by using the body as a teaser. One can make it work that way, but again... the logic will have to apply all stories.

Perhaps Moraes when you get your comp back, you can release the final and perfect version :lol: :D

Return to “Plugin Development”