4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: V@no on May 19, 2003, 07:37:17 PM

Title: Universal Paging Class
Post by: V@no on May 19, 2003, 07:37:17 PM
Topic has moved here (http://www.4homepages.de/forum/index.php?topic=6926.0)

Please dont use the code below!
It wasn't deleted just for your references.
Quote
This is replacement for the default /includes/paging.php that works exactly the same but could be used for anything, not only for images. (If u are not gonna do your own changes in 4images code, then probably dont bother reading "How To Use" section ;))


1. Backup original /includes/paging.php
2. Create new /includes/paging.php file with this code (replace the original)
Code: [Select]
<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: paging.php                                           *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.7                                                  *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (Lizenz.txt) f&#8319;r weitere Informationen.                 *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (Licence.txt) for further information.                              *
 *                                                                        *
 *************************************************************************/
if (!defined('ROOT_PATH')) {
  die("Security violation");
}
if (
class_exists(Paging)) return;

class 
Paging {
  var $page,$offset,$perpage,$num_rows_all,$link_args;
  var $first,$last,$total_pages,$config,$desc,$next,$back,$extra;

  function Paging($page 1$perpage 0$num_rows_all 0$link_args ""$text ""$extra ""$page_text ""$style "") {
    global $lang$config;

//-------- Config ------------
//Change $this->alt to 1 if u want display number of pages not more then u set in the settings, no metter on witch page u are.
//by default if u have 20 pages, for example, and in the settings set to show only 10, it will actualy show u 20 pages when u go to 10th page.
$this->alt 1;
//------- End Config ---------

    $this->style = ($style) ? $style "paging";
    $this->extra = ($extra) ? "#".$extra "";
    $this->page_text = ($page_text) ? $page_text "page";
    $this->desc = ($text) ? $text $lang['paging_stats'];

    $this->page $page;
    $this->perpage $perpage;
    $this->num_rows_all $num_rows_all;

    if (!isset($this->page) || !intval($this->page)) {
      $this->page 1;
    }
    if (!$this->num_rows_all) {
      $this->total_pages 0;
    }
    elseif ($this->num_rows_all <= $this->perpage) {
      $this->total_pages 1;
    }
    elseif ($this->num_rows_all $this->perpage == 0) {
      $this->total_pages $this->num_rows_all $this->perpage;
    }
    else {
      $this->total_pages ceil($this->num_rows_all $this->perpage);
    }
    if ($this->page $this->total_pages) {
      $this->page 1;
    }
    if (!$this->num_rows_all) {
      $this->first 0;
    }
    else {
      $this->first $this->perpage $this->page $this->perpage 1;
    }
    if (!$this->num_rows_all) {
      $this->last 0;
    }
    elseif ($this->page == $this->total_pages) {
      $this->last $this->num_rows_all;
    }
    else {
      $this->last $this->perpage $this->page;
    }

    $this->offset $this->perpage $this->page $this->perpage;

    $link_args ereg_replace("&".$this->page_text."=[0-9]*"""$link_args);
    $link_args ereg_replace($this->page_text."=[0-9]*&"""$link_args);
    $this->link_args basename($link_args);
    $this->link_args .= preg_match("/\?/",$this->link_args) ? "&amp;" "?";

    $this->paging_next $lang['paging_next'];
    $this->paging_back $lang['paging_previous'];
    $this->paging_lastpage $lang['paging_lastpage'];
    $this->paging_firstpage $lang['paging_firstpage'];
    $this->range $config['paging_range'];
  }

  function get_paging() {
    $html "";
    if ($this->total_pages 1) {
      $page_back $this->page 1;
      $page_next $this->page 1;

if ($this->alt) {
      if ($page_back 0) {
        $html .= "<a href=\"".$this->link_args.$this->page_text."=1".$this->extra."\" class=\"".$this->style."\">".$this->paging_firstpage."</a>&nbsp;&nbsp;";
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_back.$this->extra."\" class=\"".$this->style."\">".$this->paging_back."</a>&nbsp;&nbsp;";
      }
      $page_num2 ceil($this->range 2);
      $page_num3 $this->range;
      $page_left 1;
      if (($this->page $page_num2) > 0) {
       $html .= "<a href=\"".$this->link_args.$this->page_text."=".(($this->page $this->range $page_num2) ? $page_num2 : (($this->page <= ($this->total_pages $page_num2)) ? $this->page $this->range $this->total_pages $this->range $page_num2 1)).$this->extra."\" class=\"".$this->style."\">...</a>&nbsp;&nbsp;";
}
      for ($page_num 1$page_num <= $this->total_pages$page_num++){
       if ($page_num3) {
       if ($page_left) {
       if (($page_num >= $this->page - ($this->range $page_num2)) || ($page_num $this->total_pages $this->range && $this->page $this->total_pages $this->range )) {
          if ($this->page == $page_num) {
           $page_left--;
           $page_num2--;
           $page_num3--;
            $html .= "[<b class=\"".$this->style."on\">".$page_num."</b>]&nbsp;&nbsp;";
          }
          else {
           $page_num2--;
           $page_num3--;
            $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_num.$this->extra."\" class=\"".$this->style."\">".$page_num."</a>&nbsp;&nbsp;";
          }
        }
      }else{
      if ($page_num <= $this->page + ($this->range $page_num2)) {

          if ($this->page == $page_num) {
            $html .= "[<b class=\"".$this->style."on\">".$page_num."</b>]&nbsp;&nbsp;";
          }
          else {
           $page_num2--;
           $page_num3--;
            $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_num.$this->extra."\" class=\"".$this->style."\">".$page_num."</a>&nbsp;&nbsp;";
          }
        }
}
}
}
$page_num2 ceil($this->range 2);
      if (($this->page $page_num2) <= $this->total_pages) {
       $html .= "<a href=\"".$this->link_args.$this->page_text."=".(($this->page $page_num2 <= $this->total_pages $this->range) ? (($this->page $page_num2) ? $this->range $page_num2 $this->page $this->range) : $this->total_pages $page_num2 1).$this->extra."\" class=\"".$this->style."\">...</a>&nbsp;&nbsp;";
}
      if ($page_next <= $this->total_pages) {
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_next.$this->extra."\" class=\"".$this->style."\">".$this->paging_next."</a>&nbsp;&nbsp;";
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$this->total_pages.$this->extra."\" class=\"".$this->style."\">".$this->paging_lastpage."</a>";
      }
}else{
      if ($page_back 0) {
        $html .= "<a href=\"".$this->link_args.$this->page_text."=1".$this->extra."\" class=\"".$this->style."\">".$this->paging_firstpage."</a>&nbsp;&nbsp;";
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_back.$this->extra."\" class=\"".$this->style."\">".$this->paging_back."</a>&nbsp;&nbsp;";
      }
  for ($page_num 1$page_num <= $this->total_pages$page_num++) {
        if ($page_num >= ($this->page $this->range) && $page_num <= ($this->page $this->range)) {
          if ($this->page == $page_num) {
            $html .= "<b class=\"".$this->style."on\">".$page_num."</b>&nbsp;&nbsp;";
          }else{
            $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_num.$this->extra."\" class=\"".$this->style."\">".$page_num."</a>&nbsp;&nbsp;";
          }
        }
      }
      if ($page_next <= $this->total_pages) {
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$page_next.$this->extra."\" class=\"".$this->style."\">".$this->paging_next."</a>&nbsp;&nbsp;";
        $html .= "<a href=\"".$this->link_args.$this->page_text."=".$this->total_pages.$this->extra."\" class=\"".$this->style."\">".$this->paging_lastpage."</a>";
      }
      }



    }
    return $html;
  }

  function get_offset() {
    return $this->offset;
  }

  function get_paging_stats() {
    global $site_template;
    $search_array = array(
      "/".$site_template->start."total_cat_images".$site_template->end."/iU",
      "/".$site_template->start."total_pages".$site_template->end."/iU",
      "/".$site_template->start."first_page".$site_template->end."/iU",
      "/".$site_template->start."last_page".$site_template->end."/iU"
    );
    $replace_array = array(
      $this->num_rows_all,
      $this->total_pages,
      $this->first,
      $this->last
    
);
    $this->desc preg_replace($search_array$replace_array$this->desc);
    return $this->desc;
  }
//end of class
?>

I added alternative way to show number of pictures (reference (http://4homepages.de/forum/viewtopic.php?t=2323))
for that u'll need just change $this->alt = 1; inside the file.


How To Use:
I'll try explain by an example ;):
Code: [Select]
  $cat_num_all = 10;
  $cat_perpage = 4;
  $cat_page = 2;
  $link_arg = $site_sess->url(ROOT_PATH."categories.php");
  $text = "Found {total_cat_images} categories(s) on {total_pages} page(s) .Displayed: category {first_page} to {last_page}.";
  $page_text = "cat_page";
  $extra = "categories";
  include(ROOT_PATH.'includes/paging.php');
  $getpaging = new Paging($cat_page, $cat_perpage, $cat_num_all, $link_arg, $text, $page_text, $extra);
  $offset = $getpaging->get_offset();
  $site_template->register_vars(array(
    "cat_paging" => $getpaging->get_paging(),
    "cat_paging_stats" => $getpaging->get_paging_stats()
  ));
this is not working example, so dont bother trying it ;)

if u are familuar a little bit with 4images code, then u might see, that all this is almost the same as the default, exept three new variables that being send to Paging class:
$getpaging = new Paging($cat_page, $cat_perpage, $cat_num_all, $link_arg, $text, $page_text, $extra, $style);
if u leave those variables empty (or just wont add them to the code), paging will use the default settings.

In $text variable u can specify text that u'd like to show in the templates by {cat_paging_stats}
U can use the same {..} tags as in $lang['paging_stats'] in your /lang/<yourlanguage>/main.php

In $page_text u can specify name of "page" for the link address. In this example it will change current page when in the address add cat_page=XX . If u leave it empty it will generate links to the pages by using page=XX. This is neccery if u want use more then one paging at the same page, for example if u want add paging for list of categories and still have paging for images.

$extra needs only if u want after open "next" page it "jumps" to the part of page, name of witch matching with $extra. $extra will be added into "pages" link as #$extra.
in this example the link would be:
categories.php?cat_page=XX#categories

$style set style of paging displayed. If not set, will use class="paging"
Title: Universal Paging Class
Post by: toto1 on May 20, 2003, 09:23:25 AM
very good mod thk veno :D
Title: Universal Paging Class
Post by: Apollo13 on May 29, 2003, 10:44:32 AM
very nice and good 2 use 4 a guestbook and so on...
Title: questions
Post by: mantra on May 30, 2003, 04:11:53 AM
Hi V@no ,

I want to use your paging class in my news

this my code news
Code: [Select]
$sql = "SELECT * FROM ".NEWS_TABLE." ORDER BY id DESC ";
   $result = $site_db->query($sql);
   $num_rows = $site_db->get_numrows($result);
   $archive_row = array();

   while ($row = $site_db->fetch_array($result)) {
    $archive_row[] = $row;
}
   $site_db->free_result($result);


if (!$num_rows) {
     $news = "&nbsp;&nbsp;&nbsp;<b>NO MASAGE YET</b>";  
  }
  else {
  $news = "";
$bgcounter = 0;

   for ($i = 0; $i < $num_rows; $i++) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
         
         $site_template->register_vars(array(
 "id" => ($archive_row[$i]['id']),
"totalpage"=>$totalMsg,
"text" => convertBBCode($archive_row[$i]['text']),
"title" => ($archive_row[$i]['title']),
"date" => ($archive_row[$i]['date']),
"row_bg_number" => $row_bg_number));

          $news .= $site_template->parse_template("cpnews_detail");
   }

  }
  $site_template->register_vars("news", $news);
  unset($news);


My question is  how to add paging feature in my news with your paging class
Title: Universal Paging Class
Post by: effemmess on June 18, 2003, 02:01:34 AM
Hi v@no,

I have problems with the paging.php...
I want different colors (styles) for different pagings - for example black text for category-paging and yellow text for news-archiv-paging.
My knowledge with php-classes isn´t good enough to mod the sourcecode.  :(  Can you help me?
My paging.php. is like yours.
pagingstuff from index.php:
Code: [Select]
 if ($newstype == "latestnewsall") {
    include(ROOT_PATH.'includes/paging.php');
    $perpage = $show_news_articles;
    $link_arg = $site_sess->url(ROOT_PATH."index.php?newstype=latestnewsall");
    $getpaging = new Paging($page, $perpage, $num_rows, $link_arg);
    $offset = $getpaging->get_offset();

    $site_template->register_vars(array(
      "paging" => $getpaging->get_paging(),
      "paging_stats" => $getpaging->get_paging_stats()
    ));

my archive.html:
Code: [Select]
                                 <td align="left"  class="head1" width="50%"><img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" />Newsarchiv</td>
                                  <td align="right" class="head1" width="50%">{paging}<img src="{template_url}/images/spacer.gif" alt="" width="4" height="4" /></td>


As a non functioning example here my testsite:http://www.miss-magdeburg.de
thanks
Title: Universal Paging Class
Post by: V@no on June 22, 2003, 08:31:58 PM
Quote from: effemmess
I want different colors (styles) for different pagings - for example black text for category-paging and yellow text for news-archiv-paging.

ok, I just added support different style classes.
for example in categories.php u can use it like this:
Quote
$getpaging = new Paging($page, $perpage, $num_rows_all, $link_arg, "", "", "", "head1");
it will display paging with head1 style class (u'll need set all needed styles in your .css file.)
Title: Universal Paging Class
Post by: effemmess on June 22, 2003, 11:52:56 PM
Quote from: V@no
Quote from: effemmess
I want different colors (styles) for different pagings - for example black text for category-paging and yellow text for news-archiv-paging.

ok, I just added support different style classes.


thanks v@no! It works perfect and now the paging looks so much better... :D

best greets
effemmess
Title: Universal Paging Class
Post by: cigarette on June 24, 2003, 10:07:10 AM
OK, I HOPE this is the mod I'm looking for :)

What I'm trying to do is change the Last Page and Next Page links on categories.php to graphical links instead of text links. To see what I mean, check out my details.php page:

http://photo.vandalized.org/details.php?image_id=44

I'd like to to be able to use the same setup on my categories.php pages. What would need to be changed in paging.php to allow for this?
Title: Re: Universal Paging Class
Post by: ashfaq on January 10, 2009, 09:55:55 AM
I wanna show paging on my index page just for new added images, plz help how can i do this ?
Title: Re: Universal Paging Class
Post by: mawenzi on January 10, 2009, 03:25:54 PM
@ashfaq

... I think there are two modifications for your request ...
... one you can find somewhere here (http://www.4homepages.de/forum/index.php?board=11.0) ...
... and another one you can finde here (http://klick.kl.funpic.de/files.php?page=2) ...
Title: Re: Universal Paging Class
Post by: ashfaq on January 10, 2009, 03:56:05 PM
Thanks mawenzi you are really a good helper but at this site: klick.kl.funpic.de i am unable to find 4images mods ?