Dateigrösse: 6.12 kb
1<?php/*************** PageSlider ***************/class PageSlider{ /** * Attributes */ private $mPerPage = 10; // int: elements/entries per page private $mPageLabel = 'start'; // string: key for aktuell page private $mGetParams = array(); // mix: array for get-Params private $mActPage = 1; // int: actual page private $mLastPage = 1; // int: number of last page private $mNextPage = 1; // int: number of direct links forwards/backwards from ActPage private $mArrTmpl = array('<<', '< ', '##', ' >', '>>' ); // template for links: symbols, icons, gifs... // ## = placeholder for current page private $mBlindGif = '<img src="img/img_paginate/blind.gif" alt="" border="0" width="22" height="1" />'; private $mCorrectFaktor = 1; public function __construct($i_perpage, $i_lastpage, $i_nextpage, $s_pagelabel, $a_params4link, $a_tmpl, $s_css, $s_csshover) { $this->mPerPage = $i_perpage; $this->mPageLabel = $s_pagelabel; $this->mGetParams = $a_params4link; $this->mActPage = $this->mGetParams[$this->mPageLabel]; $this->mSuchbegriff = $this->mGetParams['suchbegriff']; $this->mLastPageFull= $i_lastpage; $this->mLastPage = floor($i_lastpage/$this->mPerPage); $this->mNextPage = $i_nextpage; $this->mArrTmpl = $a_tmpl; $this->mCssStyle = $s_css; $this->mCssActive = $s_csshover; if (strpos ($this->mArrTmpl[2], "##") !== FALSE) { $this->mArrTmpl[2] = str_replace("##", $this->mActPage+$this->mCorrectFaktor, $this->mArrTmpl[2]); } } public function toHtml() { $first = ''; $previous = ''; $next = ''; $last = ''; $backward = ''; $forward = ''; if ($this->mActPage > 0) { for ($i=$this->mNextPage; $i>0; $i--) { if ($this->mActPage - $i >= 0) { $backward .= $this->_aHtml( $this->mActPage - $i, 'zur Seite ' . ($this->mActPage - $i + $this->mCorrectFaktor) . '', $this->mActPage - $i + $this->mCorrectFaktor, 'default' ); } } if(($this->mActPage-1) >= (1-$this->mNextPage)) { $first = $this->_aHtml( 0, 'zur Startseite', $this->mArrTmpl[0] ); } else { $first = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[5].'</span>'; } if(($this->mActPage-1) >= $this->mNextPage ) { $previous = $this->_aHtml( $this->mActPage-1-$this->mNextPage, 'zur vorangehenden Seite', $this->mArrTmpl[1] ); } else { $previous = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[6].'</span>'; } } else { $first = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[5].'</span>'; $previous = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[6].'</span>'; } // If next, i.e. last page, is empty, hide all arrow symbols [ example: (5*4 + 4) / 20 == 1 ] // ueberfluessig: if ($this->mActPage < $this->mLastPage) if (($this->mActPage*$this->mPerPage + $this->mPerPage) / $this->mLastPageFull < 1) { for ($i=1; $i<=$this->mNextPage; $i++) { if ($this->mActPage+$i <= $this->mLastPage) { $forward .= $this->_aHtml( $this->mActPage + $i, 'zur Seite ' . ($this->mActPage + $i + $this->mCorrectFaktor) . '', $this->mActPage + $i + $this->mCorrectFaktor, 'default' ); } } if($this->mLastPageFull / $this->mPerPage > $this->mActPage+1+$this->mNextPage) { $next = $this->_aHtml( $this->mActPage+1+$this->mNextPage, 'zur nächsten Seite', $this->mArrTmpl[3] ); } else { $next = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[7].'</span>'; } if($this->mLastPageFull % $this->mPerPage == 0) { $last = $this->_aHtml( $this->mLastPage-1, 'zur letzten Seite', $this->mArrTmpl[4] ); } else { $last = $this->_aHtml( $this->mLastPage, 'zur letzten Seite', $this->mArrTmpl[4] ); } } else { $next = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[7].'</span>'; $last = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[8].'</span>'; } if ($this->mLastPageFull <= $this->mPerPage) { $slider = ''; } else { $slider .= $first; $slider .= $previous; $slider .= $backward; $slider .= '<span style="'.$this->mCssActive.'" title="' . $this->mActPage . '">'.$this->mArrTmpl[2].'</span>'; $slider .= $forward; $slider .= $next; $slider .= $last; } return $slider; } private function _aHtml($actPage, $title, $link, $class='') { $tmpA = ''; $tmpArr = array(); $this->mGetParams[$this->mPageLabel] = $actPage*$this->mPerPage; foreach ($this->mGetParams as $k => $v) { $tmpArr[] = $k .'='. $v; } $href = $_SERVER['PHP_SELF'] . '?' . implode('&', $tmpArr); /***** implode transforms array-elements into a string ****/ $tmpA .= "\n"; $tmpA .= '<a href="' . $href . '" title="' . $title . '" class="' . $class . '" style="' . $this->mCssStyle . '">'; $tmpA .= $link; $tmpA .= '</a>' . "\n"; return $tmpA; }}?>