[PAGINATE] cntprt [PB] cntprt [/PAGINATE]

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

[PAGINATE] cntprt [PB] cntprt [/PAGINATE]

Post by jsw_nz »

As part of developing a personal project, came up with a way to 'paginate' contentparts -
allows you to create multiple page articles -- the topic has been disucussed elsewhere on boards
- in fact goes back some time.

USAGE:
place code in separate html content parts. Needs opening and closing tags:
[PAGINATE] & [/PAGINATE]

then use [PB]
to create multiple page breaks

Code Scheme:

Code: Select all

[PAGINATE] contentpart_1 [PB] contentpart_2 [PB] contentpart_3 [/PAGINATE]
Here is Backend Screenshot:
Image

Here is Frontend Screenshot:
Image

Code:

Code: Select all

<?php
define ("REWRITE_ext", ".phtml");
/* if using rewrite two additional rules need to be placed in .htaccess -
also order is important - /subdirectory example is shown here - same would apply to rules for root
RewriteBase /subdirectory
#new
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)_([0-9]+)\.phtml$ /subdirectory/index.php?id=$1,$2,$3,$4,$5,$6&p=$7
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ /subdirectory/index.php?id=$1,$2,$3,$4,$5,$6
#new
RewriteRule ^(.+)_([0-9]+)\.phtml$ /subdirectory/index.php?$1&p=$2
RewriteRule ^(.+)\.phtml$ /subdirectory/index.php?$1
*/

function show_page($pageInput) {
   global $phpwcms;
   // next line for apache servers
	$this_url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
   // for non-apache servers uncomment next line (a temporary solution - will update)
   // $this_url = FE_CURRENT_URL;
   $appendString = "_";
   $thisPageNum = 1; // default page
   if ($_GET['p']) {
      // page # is specified
      $thisPageNum = $_GET['p'];
   } // end if GET
   if(!$phpwcms["rewrite_url"]){ //  non rewrite logic
      if(intval(strpos($this_url,"&p")!=-1)){
         $url_suffix_array = explode("&p", $this_url);
         $this_url = $url_suffix_array[0];
      }
   }else{ // rewrite logic -- get core url address
         $url_left = substr($this_url, 0, strrpos($this_url, "/" ) + 1);
         $url_right =  substr(strrchr($this_url, "/"), 1);
         $url_right = str_replace(".phtml", "", $url_right);
         $url_array = explode("_", $url_right);
         $url_right = $url_array[0];
         $this_url = $url_left.$url_right;
   } // end if phpwcms["rewrite_url']
   $pageArray = explode("[PB]", $pageInput); // now parse the content
   $thisPageCount = count($pageArray);
   if(($thisPageNum > $thisPageCount) || ($thisPageNum < 1)) {
      $thisPageNum = 1;
   } // end if thisPageNum
   // format output to show which page we are looking
   // unless looking at page 1 -- display a mini-navbar for the other pages.
   // order can change - this example places navbar at top of output;
   if ($thisPageCount > 1) {
      $pageOutput = "<div><font size=\"1\"><b>page: </b> ";
      for ($i = 1; $i <= $thisPageCount; $i++) {
         if ($i == $thisPageNum) {
            $pageOutput .= "<b>$i</b>";
         }else{
            if ($i > 1) {
               if(!$phpwcms["rewrite_url"]){
                  $pageOutput .= "<a href=\"$this_url&p=$i\">$i</a>";
               }else{
                  $pageOutput .= "<a href=\"$this_url".$appendString.$i.REWRITE_ext."\">$i</a>";
               }
            }else{
               if(!$phpwcms["rewrite_url"]){
                  $pageOutput .= "<a href=\"$this_url\">$i</a>";
               }else{
                  $pageOutput .= "<a href=\"$this_url".REWRITE_ext."\">$i</a>";
               }
            }
         }
      if ($i < $thisPageCount) {
         $pageOutput .= ", ";
      }
   }
    $pageOutput .= "</font></div>\n";
     // select the proper section of content
     // NEXT LINE ADDED TO ALLOW POPUPS - ADDED 02/2007
      $cleaned_output = str_replace("\\","",$pageArray[$thisPageNum-1]);
     $pageOutput .= "<div>".$cleaned_output."</div>";
   }
   return $pageOutput;
} // end function

// sniff for tag
//UPDATED to strip out preg_replace 'unfriendly' characters

if( ! (strpos($content["all"],'[PAGINATE]')===false)) {
   $content["all"] = preg_replace('/\[PAGINATE\](.*?)\[\/PAGINATE\]/se', 'show_page("$1");', $content["all"]);
   }

// end script
?>
Name file as paginate_content.php
place in phpwcms_template/inc_script/frontend_render directory
(please note special instructions if using with rewrite = on)
beta atm - not tested in summary yet.

Just posting this as is - maybe someone will find useful.

all best
-john-
Last edited by jsw_nz on Wed 18. Apr 2007, 02:53, edited 14 times in total.
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Post by culda_a »

Yes this sound good... can you give me more details ..on how to install it?

Thanks
ImagePackging design,labels, catalogs,postcards,
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Post by culda_a »

or is there a way to do this automaticly and to say after 1000 characters to create automatic a second page?
ImagePackging design,labels, catalogs,postcards,
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Hi jsw_nz, nice one :D
Campeones del mundo!
Vegetables!
volkman
Posts: 179
Joined: Wed 13. Jul 2005, 12:52
Location: Hamburg, Germany

Post by volkman »

@ jsw_nz
wow, thats a good one, thx a lot!!

@culda_a (installation)
read the posting, its all in there


volkman
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Hi jsw_nz, I don't understand well the usage with rewrite_mode.

I've putted this new rules in my .htaccess

Code: Select all

RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)_([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6&p=$7
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6
I have deleted the /subdirectory/ because my installation is in the root dir, but seems it doesn't work :?
Campeones del mundo!
Vegetables!
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Sustia,

Well, while developing the rewrite code i did notice that the order of the arguments does make a wee difference - your post looks correct - other than having excluded the 'non-numeric' rules for aliased page requests. For the sake of arguement - I installed a copy of my install into the root of my localhost - and it works, at least in this environment. Here is the order I had in root level .htaccess:

Code: Select all

RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)_([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6&p=$7
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6
RewriteRule ^(.+)_([0-9]+)\.phtml$ index.php?$1&p=$2
RewriteRule ^(.+)\.phtml$ index.php?$1
I have yet to test this in an actual online setting - i have been tasked atm - so wont be able to get to this until the weekend. I do admit the rewrite issue is a bit fuzzy. Might be other issues at stake here. Perhaps others in the community (hello DeXXus) - might offer additional advice - hope this helps - and as mentioned - the code as it is - is beta - so any improvements are welcome. Planning to include a nav bar icon scheme - like teaser reptag - at some stage.

All the best,
-john- :D
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Hi jsw_nz, now it works perfectly, thaaaanks a lot :D
Campeones del mundo!
Vegetables!
tinoo
Posts: 311
Joined: Thu 16. Jun 2005, 11:16
Location: Zürich, Switzerland
Contact:

Post by tinoo »

V-E-R-Y nice one, John. Thanks! I started already thinking about where i can use this enhancement a.s.a.p.... :wink:
Greetz, tinoo
User avatar
Oliver Georgi
Site Admin
Posts: 9892
Joined: Fri 3. Oct 2003, 22:22
Contact:

Post by Oliver Georgi »

The concept behind is very nice - but the solution sub-optimal. A pagination setting is coming for structures and articles - then you can decide to have pagination for article lists and/or for articles based on the content parts too.

Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
sustia
Posts: 651
Joined: Fri 2. Apr 2004, 22:29
Location: Lecce (Italy)
Contact:

Post by sustia »

Oliver Georgi wrote:The concept behind is very nice - but the solution sub-optimal. A pagination setting is coming for structures and articles - then you can decide to have pagination for article lists and/or for articles based on the content parts too.

Oliver
:D
Campeones del mundo!
Vegetables!
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi Oliver,

"A pagination setting is coming for structures and articles"
Sounds excellent

This advice, coming from the master himself, is well recieved !

All the best - the community is behind you :D
kubens
Posts: 168
Joined: Sat 6. Nov 2004, 15:29
Location: Duesseldorf near Cologne ;-)

Post by kubens »

Normally I would also say that it make no sense to paginate one article, but of course sometimes it is necessary or the most elegant solution to solve either a problem or a customer request ;-) I solved a similar issue with custom blocks. This gaves you the ability to structure your articel in separate logical parts.

Details
Preise

Both links belongs to the same article, but pending of the parameter 'show' the template controls which custom block should rendered.

Br
Wolfgang
culda_a
Posts: 521
Joined: Tue 28. Feb 2006, 01:39
Contact:

Post by culda_a »

I have folow the instruction I I have use the paginate to paginate a images content part ...but is not working...in frontend it shows me like this:

[PAGINATE]

the content of the images (the images that i put in)

[PB]

the content of the images (the images that i put in)


[/PAGINATE]

any ideea why?

I have paginate_content.php
place in phpwcms_template/inc_script/frontend_render directory

do I have to do other changes?
ImagePackging design,labels, catalogs,postcards,
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi culda_a,

As mentioned this approach is beta, until OliG provides a core method.
You are absolutely right - tried your code and got the same issue...

From what I am learning (still a student) preg_replace is a string method,
so if it encounters \n or other types of markup that OliG's code generates, it fails to return a pattern.
The workaround i created is to strip out such:

UPDATED
- See OliG's post later in this thread:

Code: Select all

if( ! (strpos($content["all"],'[PAGINATE]')===false)) {
	$content["all"] = preg_replace('/\[PAGINATE\](.*?)\[\/PAGINATE\]/se', 'show_page("$1");', $content["all"]);
}
This is working on my localhost...
although page source is a wee bit harder to read
(ps - will add some \n's to the parsing function at some stage)
:D

I updated the code (see above)
cheers,
-john-

BTW: I understand your interest in this -- wanting to create
multiple paginated image galleries - now possible
- just tested now -
thats way cool

:D
Last edited by jsw_nz on Sat 12. Aug 2006, 09:22, edited 4 times in total.
Post Reply