NP_PageBreak - completely (re)done!

Post your new plugins here!
User avatar
subirghosh
Posts: 408
Joined: Wed Aug 25, 2004 11:39 am
Location: Delhi, India
Contact:

Postby subirghosh » Tue Aug 02, 2005 5:51 pm

Stevie: I think I will stick to what I had said then. I am using the plugin on a multi-blog site. And the plugin works just fine. There is no sign of the bug anywhere :D
Subir Ghosh
www.newswatch.in
Rod
Posts: 133
Joined: Fri Jul 01, 2005 4:07 am

Postby Rod » Wed Aug 03, 2005 12:32 am

Suggestion : possibility to "think" layers instead of pages ??? Indeed, with a CSS DHTML TAB, it would be interesting to have this mod which create a new div instead loading a whole page.

Otherwise, great idea !
spiros
Posts: 21
Joined: Fri Jul 01, 2005 8:16 am
Contact:

DISALLOWED (PageBreak)

Postby spiros » Sat Sep 17, 2005 1:22 pm

I followed the instructions,

added <%PageBreak(links)%> in your default and detailed templates
added <%PageBreak(title)%> in the items

and I get DISALLOWED (PageBreak)

Any ideas?
Spiros Doikas
Free translation
User avatar
moraes
Nucleus Guru
Nucleus Guru
Posts: 2377
Joined: Sun Dec 23, 2001 9:42 pm
Location: Curitiba, Brazil
Contact:

Postby moraes » Sat Sep 17, 2005 2:21 pm

Hmmm. Maybe it is not working on Nucleus versions 3.2 and above? I'll make a test. Btw, which Nucleus version do you use?

moraes
spiros
Posts: 21
Joined: Fri Jul 01, 2005 8:16 am
Contact:

Postby spiros » Sun Sep 18, 2005 12:07 pm

3.22...
Spiros Doikas

Free translation
spiros
Posts: 21
Joined: Fri Jul 01, 2005 8:16 am
Contact:

Postby spiros » Fri Sep 23, 2005 5:16 pm

Has anybody managed to have it working in 3.22 please?
Spiros Doikas

Free translation
AnotherRandomUser
Posts: 7
Joined: Sat Oct 01, 2005 10:43 pm

Postby AnotherRandomUser » Sun Oct 02, 2005 1:30 am

Spiros:

I have it working (I'm using a clean install of 3.22 with about two dozen other plugins). In my templates all instances of "PageBreak" are capitalized just like so, but when I make a post I make sure to write it in as "pagebreak" (all lowercase). From what I can tell, you can have any number of pagebreaks in each item, but if even one of them has incorrect case, ALL of them will read as "Disallowed."

This is just my observation - maybe it's accurate, maybe not. ;) Try it and see what you find!

Hope this helps,

AnotherRandomUser
AnotherRandomUser
Posts: 7
Joined: Sat Oct 01, 2005 10:43 pm

Postby AnotherRandomUser » Sun Oct 02, 2005 2:30 am

As a follow-up to my previous post:

I tried installing Stevie's modified code (v0.8.1 instead of v0.8 ). With that, I get either no display or DISALLOWED errors constantly - regardless of capitalization. Also, in the vertical link list, I get either multiple entries of the same link, multiple entries of different links with the same title, or no links at all, randomly on different pages.

I have no problem and the plugin works for me just fine, as stated in my last post, if I use the original v0.8 code from the wiki. I think Stevie's code probably works, under many circumstances, but to be certain the plugin will work for you I'd recommend using the code from the wiki (at least until somebody else who knows PHP can see what's wrong with Stevie's code; I know no PHP, thus, I'm useless in this regard). ;)

Of course, by using v0.8 wiki code, you won't have all the cool features Stevie added. :( But at least you'll have custom pagebreaks!

AnotherRandomUser
heddesheimer
Posts: 13
Joined: Sat Oct 08, 2005 7:59 am

Postby heddesheimer » Tue Oct 11, 2005 3:22 pm

Hi,

I just entered a change into the plugin to fix this problem with Fancy-URLs:

Code: Select all

    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) {
                        // M.H. change: Check if Fancy URL ist turned on
                        if ($GLOBALS['CONF']['URLMode'] == 'normal')
                        {
                            echo "<a href=\"$link&amp;page=$z\">";
                        } else {
                            echo "<a href=\"$link/?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');
                    // M.H. Change: Check Fancy URL
                    if ($GLOBALS['CONF']['URLMode'] == 'normal')
                    {
                        echo "<a href=\"$link&amp;?page=".$next."\">";
                    } else {
                        echo "<a href=\"$link/?page=".$next."\">";
                    }
                    if (trim($pagetitle[$page])) {
                        echo $pagetitle[$page];
                    }
                    else {
                        echo "page ".$next;
                    }
                    echo "</a>";
                    echo " &raquo;";
                    echo $this->getOption('nextend');
                }
            }
        }
    } // doTemplateVar


This should solve the problem without further hacks for both settings.

Best Regards

Marian
w98
Posts: 1
Joined: Mon Mar 27, 2006 9:16 am

Postby w98 » Mon Mar 27, 2006 11:07 am

I use Nucleus 3.22, and have downloaded v0.4 of your plugin, and I'm unable to get it working.

I downloaded the 'leaf' skin, and in the "leaf/full" template, under "Item Body", i have the following:

Code: Select all

<div class="contentbody">
<h3><%date%>: <%title%></h3>
<%body%>
<a name="more"></a>
<br /><br />
<%more%>
<%PageBreak%>
</div>


In my articles, I've tried my breaks in MixedCase and all lowercase. If I put <%PageBreak()%> in my item, I get a DISALLOWED message. If I put <%pagebreak()%>, I don't get the error, but I also don't see the link to the next block of text nor the rest of the article I've written.

Perhaps more instructions for how exactly to modify the templates would be helpful?

Thanks
w98
User avatar
radekradek
Posts: 668
Joined: Tue Dec 30, 2003 10:48 pm
Location: Prague, Czechia
Contact:

Postby radekradek » Sat Sep 02, 2006 10:16 pm

I rewrote a bit NP_PageBreak. It now parses link/next/prev items, is able to display full article, replace pagebreaks in full view fo H2, etc. See from source code. By intention, new NP_PageBreak works only on item page, and only on MORE part of article.

Usage in item templates:

Code: Select all

<h2><%title%></h2>
<div class='itembody'>
 <%body%>
 <%more%>
</div>
<%PageBreak(next)%>
<%PageBreak(prev)%>
<%PageBreak(links)%>


Usage in article:

Code: Select all

%pagebreak(This is title for next section)%


Plugin code:

Code: Select all

<?php
/*****************************************/
/* NP_PageBreak                          */
/* ------------------------------------- */
/* by Rodrigo Moraes                     */
/* http://www.tipos.com.br               */
/*****************************************/
/* by Radek Hulan                        */
/* http://hulan.cz/contact/              */
/*****************************************/

// 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, Radek Hulan'; }
    function getURL() { return 'http://blogcms.com/'; }
    function getVersion() { return '2.0'; }
    function getDescription() { return 'NP_PageBreak can break a post in multiple pages and create navigation links between them. Use %pagebreak(Page Title)% every time you want a page break in your posts. Useful for long texts, tutorials, presentations etc. Works, by purpose, only in MORE part of item.'; }
    function supportsFeature($what) {
        switch($what) {
            case 'SqlTablePrefix':
               return 1;
               break;
            default:
               return 0;
               break;
        }
    }
 
    function install() {
        $this->createOption('navstart','Navigation links start tag','text','<div class="pagebreak"><h4>Seznam stránek článku:</h4>');
        $this->createOption('navend','Navigation links end tag','text','</div>');
        $this->createOption('titlestart','Page title start tag','text',"<h2 class='pagetitle'>");
        $this->createOption('titleend','Page title end tag','text','</h2>');
        $this->createOption('nextstart','Next page start tag','text','<div class="nextpage"><strong>Následující část:</strong> ');
        $this->createOption('nextend','Next page end tag','text','</div>');
        $this->createOption('prevstart','Prev page start tag','text','<div class="prevpage"><strong>Předchozí část:</strong> ');
        $this->createOption('prevend','Prev page end tag','text','</div>');
        $this->createOption('fullstart','Full page start tag','text','<div class="fullpage">');
        $this->createOption('fullend','Full page end tag','text','</div>');
        $this->createOption('fulldesc','Full page description','text','zobrazit bez rozdělování stránek &laquo;');
        $this->createOption('shownumbers','Show numbers before navigation links?','yesno','no');
        $this->createOption('error','Error message when trying to access a non-existent page','text',"<h2 class='pagetitle'>Požadovaná stránka neexistuje.</h2>");
    }
 
    function getEventList() { return array('PreItem','PreSkinParse'); }
   
    var $pagecount, $pagetitle, $page, $pages;
 
   function event_PreSkinParse(&$data) {
      // get the page to display, do pagebreak only on item page
        if (!isset($_GET['page']))
            $this->page = ($data['type'] == 'item') ? 1 : 0;
        else
            $this->page = ($data['type'] == 'item') ? intGetVar('page') : 0;
        // hack for wap/atom/rss - never pagebreak
        if (in_array($data['skin']->getName(),array('wap','atom','xmlrss1','xmlrss2')))
             $this->page = 0;   
   }

    function event_PreItem(&$data) {
       // init vars
        $this->pagecount = 0;
      $this->pages = array();
      $this->pagetitle = array();
       
        // full page view - replace pagebreaks for H2 and exit
        if ($this->page == 0) {
           $data['item']->more = preg_replace('/<p>\%pagebreak\((.*?)\)\%<\/p>/i', '<h2>$1</h2>', $data['item']->more);
           return;
        }
 
        // do pagebreaks
        if (preg_match('/\%pagebreak\(.*?\)\%/i', $data['item']->more)) {
              // remove pagebreaks in body
              $data['item']->body = preg_replace('/\%pagebreak\(.*?\)\%/i', '', $data['item']->body);
              // remove unnecessary P tags
              $data['item']->more = preg_replace('/<p>\%pagebreak(.*?)\%<\/p>/i', '%pagebreak$1%', $data['item']->more);
 
             // get pagebreaks
                preg_match_all('/\%pagebreak(.*?)\%/i',$data['item']->more,$tags);     
                // and get complete text to parse
                $text = $data['item']->body.$data['item']->more;

            $this->pagetitle[0] = $data['item']->title;
            $i = 0;
                foreach ($tags[0] as $tag) {
                    // get the page content
                    $tagpos = strpos($text, $tag);
                    $this->pages[$i++] = substr($text, 0, $tagpos);
                    // and the page title
               $this->pagetitle[$i] = substr($tag, 11, -2);
                    // and go back to the beginning
                    $text = substr($text, $tagpos + strlen($tag));
                }
                // this is the last page content of each item part
                $this->pages[$i] = $text;
            $this->pagecount = count($this->pages);
               
            // set current view
            $data['item']->body = '';
            if ($this->page > $this->pagecount)
               $data['item']->more = $this->getOption('error');
            elseif ($this->page > 1)
               $data['item']->more = $this->getOption('titlestart') . strip_tags($this->pagetitle[$this->page-1]) . $this->getOption('titleend') . $this->pages[$this->page-1];
            else
               $data['item']->more = $this->pages[0];
        }
    }
   
    function doTemplateVar(&$item, $type) {
        if ($this->pagecount > 1) {       
            $link = createItemLink($item->itemid);
            switch ($type) {
               case 'links':
                  // create navigation if one or more pagebreaks are found
                   echo $this->getOption('navstart'),"\n";
                   echo "<ol>\n";
                   for ($n = 0; $n < $this->pagecount; $n++) {
                       $nplus = $n + 1;
                       echo "<li>";
                       if ($this->getOption('shownumbers') == 'yes')
                           echo $nplus,". ";
                       if ($nplus != $this->page) {
                           if ((strpos($link,'?') === false) && (strpos($link,'&') === false))
                               echo "<a href=\"$link?page=$nplus\">";
                           else
                               echo "<a href=\"$link&amp;page=$nplus\">";
                       }
                       if (trim($this->pagetitle[$n]))
                           echo $this->pagetitle[$n];
                       else
                           echo "#$nplus";
                       if ($nplus != $this->page)
                           echo "</a>";
                       echo "</li>\n";
                   }
                   echo "</ol>\n";
                   // show options for full article view
                   echo $this->getOption('fullstart');
                   if ((strpos($link,'?') === false) && (strpos($link,'&') === false))
                  echo "<a href=\"$link?page=0\">";
                   else
                      echo "<a href=\"$link&amp;page=0\">";
                   echo $this->getOption('fulldesc');
                   echo "</a>";
                   // finish
                   echo $this->getOption('fullend');
                   echo $this->getOption('navend');
                   break;
                   
               case 'next':
                   $next = $this->page+1;
                   if ($next <= $this->pagecount) {
                       echo $this->getOption('nextstart');
                       if ((strpos($link,'?') === false) && (strpos($link,'&') === false))
                             echo "<a href=\"$link?page=".$next."\">";
                       else
                             echo "<a href=\"$link&amp;page=".$next."\">";
                       if (trim($this->pagetitle[$this->page]))
                           echo $this->pagetitle[$this->page];
                       echo " &raquo;";
                       echo "</a>";
                       echo $this->getOption('nextend');
                   }
                   break;

               case 'prev':
                   $prev = $this->page-1;
                   if ($prev > 0) {
                       echo $this->getOption('prevstart');
                       if ((strpos($link,'?') === false) && (strpos($link,'&') === false))
                             echo "<a href=\"$link?page=".$prev."\">";
                       else
                             echo "<a href=\"$link&amp;page=".$prev."\">";
                       echo "&laquo; ";
                       if (trim($this->pagetitle[$prev-1]))
                           echo $this->pagetitle[$prev-1];
                       echo "</a>";
                       echo $this->getOption('prevend');
                   }
                   break;
            }
        }
    }
}
?>


Screenshots:
Image
--= BLOG:CMS developer =--
web|LOG :: GET OPERA!
User avatar
matt_t_hat
Posts: 1123
Joined: Sun Aug 21, 2005 4:45 pm
Location: UK
Contact:

Formal request

Postby matt_t_hat » Sun Sep 03, 2006 1:36 pm

I am formaly requesting that this dishonerable ego driven posting be stricken from the record.
User avatar
radekradek
Posts: 668
Joined: Tue Dec 30, 2003 10:48 pm
Location: Prague, Czechia
Contact:

Re: Formal request

Postby radekradek » Sun Sep 03, 2006 2:50 pm

matt_t_hat wrote:I am formaly requesting that this dishonerable ego driven posting be stricken from the record.


Are you stupid or what? What is you problem? I contribute and work, you damage. For fun?

I know there are plenty of stupid teenagers on the internet, but you must be their "king" :-) You are a very sad fuck.. I pity you.
--= BLOG:CMS developer =--

web|LOG :: GET OPERA!
User avatar
matt_t_hat
Posts: 1123
Joined: Sun Aug 21, 2005 4:45 pm
Location: UK
Contact:

Postby matt_t_hat » Thu Feb 01, 2007 1:35 pm

Ignoring branch-boy for a moment it seems the original (and better trusted version) has something that I hesitate to call a bug but is a clash between that and NP_fancier_URL2 it seems (although I am unsure) that the two are not playing nicely.
User avatar
matt_t_hat
Posts: 1123
Joined: Sun Aug 21, 2005 4:45 pm
Location: UK
Contact:

Postby matt_t_hat » Thu Feb 01, 2007 2:28 pm

Because I am better then smeg-in-the-head I have not sat arround b'ching but have found a solution to the clash. It reques the addition of just 4 new characters.

These are added to the .htaccess file

change [L] to [QSA,L]

Job done.
User avatar
Francesca
Posts: 129
Joined: Wed Feb 11, 2004 4:03 pm
Location: Italy

Postby Francesca » Sat Mar 31, 2007 3:42 pm

Great plugin!
I just installed the radekradek version on Nucleus 3.24 and it seems to work fine.
I need help with the pagination style because I'd like to have only numbers (1 - 2 - 3).
So I used %pagebreak()% to splitt the item but the link for part no 1 in the pagination shows the item title, not just #1.

any suggestion?

I've read about using <%PageBreak(paginate)%> instead of <%PageBreak(links)%> in the item template, but it gives blank space.

Thank you.
User avatar
Francesca
Posts: 129
Joined: Wed Feb 11, 2004 4:03 pm
Location: Italy

Postby Francesca » Thu Apr 12, 2007 4:36 pm

Solved.
User avatar
Leng
Nucleus Guru
Nucleus Guru
Posts: 2827
Joined: Sun Sep 19, 2004 2:34 am
Location: Australia
Contact:

Postby Leng » Sat Apr 14, 2007 10:52 am

Francesca wrote:Solved.

Would you be able to post your solutions for other users? It may help those who have a similar problem.
Image
deborahlau.com | To-Do List
Questions? See the FAQ, read the docs, or browse our plugins!!
User avatar
Francesca
Posts: 129
Joined: Wed Feb 11, 2004 4:03 pm
Location: Italy

Postby Francesca » Sun Apr 15, 2007 6:34 pm

Yes, it's just that - since I got no answers - I was afraid it was a kinda stupid question :lol: maybe solved in some past post

sorry

anyway, I replaced

Code: Select all

if (trim($this->pagetitle[$n]))
echo $this->pagetitle[$n];


with:

Code: Select all

 if (trim($this->pagetitle[$n]))
echo "#1";


at lines 132-133
sluggo
Posts: 14
Joined: Wed Jun 04, 2008 2:20 am

Postby sluggo » Mon Jul 28, 2008 7:33 pm

radekradek wrote:I rewrote a bit NP_PageBreak.

Code: Select all

        $this->createOption('navstart','Navigation links start tag','text','<div class="pagebreak"><h4>Seznam stránek článku:</h4>');
        $this->createOption('navend','Navigation links end tag','text','</div>');
        $this->createOption('titlestart','Page title start tag','text',"<h2 class='pagetitle'>");
        $this->createOption('titleend','Page title end tag','text','</h2>');
        $this->createOption('nextstart','Next page start tag','text','<div class="nextpage"><strong>Následující část:</strong> ');
        $this->createOption('nextend','Next page end tag','text','</div>');
        $this->createOption('prevstart','Prev page start tag','text','<div class="prevpage"><strong>Předchozí část:</strong> ');
        $this->createOption('prevend','Prev page end tag','text','</div>');
        $this->createOption('fullstart','Full page start tag','text','<div class="fullpage">');
        $this->createOption('fullend','Full page end tag','text','</div>');
        $this->createOption('fulldesc','Full page description','text','zobrazit bez rozdělování stránek &laquo;');
        $this->createOption('shownumbers','Show numbers before navigation links?','yesno','no');
        $this->createOption('error','Error message when trying to access a non-existent page','text',"<h2 class='pagetitle'>Požadovaná stránka neexistuje.</h2>");


Can someone please assist with the Czech-to-English translation?

Also:

Code: Select all

    function getEventList() { return array('PreItem','PreSkinParse'); }
   
           var $pagecount, $pagetitle, $page, $pages;

None of the class functions reference these vars. Should this line be removed?


Return to “Plugin Development”