Dateigrösse: 5.39 kb
1 <?php 2 3 /************** 4 * PageSlider * 5 **************/ 6 7 class PageSlider 8 { 9 /** 10 * Attributes 11 */ 12 private $mPerPage = 10; // int: elements/entries per page 13 private $mPageLabel = 'start'; // string: key for aktuell page 14 private $mGetParams = array(); // mix: array for get-Params 15 private $mActPage = 1; // int: actual page 16 private $mLastPage = 1; // int: number of last page 17 private $mNextPage = 3; // int: number of direct links forwards/backwards from ActPage 18 private $mArrTmpl = array('<<', 19 '< ', 20 '##', 21 ' >', 22 '>>' ); // template for links: symbols, icons, gifs... 23 // ## = placeholder for current page 24 private $mBlindGif = '<img src="img/img_paginate/blind.gif" alt="" border="0" width="22" height="1" />'; 25 26 public function __construct($i_perpage, $i_lastpage, $i_nextpage, $s_pagelabel, $a_params4link, $a_tmpl, $s_css, $s_csshover) 27 { 28 $this->mPerPage = $i_perpage; 29 $this->mPageLabel = $s_pagelabel; 30 $this->mGetParams = $a_params4link; 31 $this->mActPage = $this->mGetParams[$this->mPageLabel]; 32 $this->mSuchbegriff = $this->mGetParams['suchbegriff']; 33 $this->mLastPageFull= $i_lastpage; 34 $this->mLastPage = floor($i_lastpage/$this->mPerPage); 35 $this->mNextPage = $i_nextpage; 36 $this->mArrTmpl = $a_tmpl; 37 $this->mCssStyle = $s_css; 38 $this->mCssActive = $s_csshover; 39 40 if (strpos ($this->mArrTmpl[2], "##") !== FALSE) 41 { 42 $this->mArrTmpl[2] = str_replace("##", $this->mActPage+1, $this->mArrTmpl[2]); 43 } 44 } 45 46 public function toHtml() 47 { 48 $first = ''; $previous = ''; $next = ''; $last = ''; $backward = ''; $forward = ''; 49 50 if ($this->mActPage > 0) 51 { 52 for ($i=$this->mNextPage; $i>0; $i--) 53 { 54 if ($this->mActPage-$i >= 1) 55 { 56 $backward .= $this->_aHtml( ($this->mActPage - $i), 57 'zur Seite ' . ($this->mActPage - $i), 58 ($this->mActPage - $i) ); 59 } 60 } 61 62 $first = $this->_aHtml( 0, 63 'zur ersten Seite', 64 $this->mArrTmpl[0] ); 65 $previous = $this->_aHtml( $this->mActPage-1, 66 'zur vorangehenden Seite', 67 $this->mArrTmpl[1] ); 68 } 69 else 70 { 71 $first = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[5].'</span>'; 72 $previous = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[6].'</span>'; 73 } 74 75 // If next, i.e. last page, is empty, hide all arrow symbols [ example: (5*4 + 4) / 20 == 1 ] 76 // ueberfluessig: if ($this->mActPage < $this->mLastPage) 77 if (($this->mActPage*$this->mPerPage + $this->mPerPage) / $this->mLastPageFull < 1) 78 { 79 for ($i=1; $i<=$this->mNextPage; $i++) 80 { 81 if ($this->mActPage+$i <= $this->mLastPage) 82 { 83 $forward .= $this->_aHtml( ($this->mActPage + $i), 84 'zur Seite ' . ($this->mActPage + $i), 85 ($this->mActPage + $i) ); 86 } 87 } 88 89 $next = $this->_aHtml( $this->mActPage+1, 90 'zur nächsten Seite', 91 $this->mArrTmpl[3] ); 92 93 if($this->mLastPageFull % $this->mPerPage == 0) 94 { 95 $last = $this->_aHtml( $this->mLastPage-1, 96 'zur letzten Seite', 97 $this->mArrTmpl[4] ); 98 } else { 99 $last = $this->_aHtml( $this->mLastPage, 100 'zur letzten Seite', 101 $this->mArrTmpl[4] ); 102 } 103 } 104 else 105 { 106 $next = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[7].'</span>'; 107 $last = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[8].'</span>'; 108 } 109 110 if ($this->mLastPageFull <= $this->mPerPage) 111 { 112 $slider = ''; 113 } else { 114 $slider .= $first; 115 $slider .= $previous; 116 $slider .= $backward; 117 $slider .= '<span style="'.$this->mCssActive.'">'.$this->mArrTmpl[2].'</span>'; 118 $slider .= $forward; 119 $slider .= $next; 120 $slider .= $last; 121 } 122 123 return $slider; 124 } 125 126 private function _aHtml($actPage, $title, $link, $class='default') 127 { 128 $tmpA = ''; 129 $tmpArr = array(); 130 $this->mGetParams[$this->mPageLabel] = $actPage*$this->mPerPage; 131 foreach ($this->mGetParams as $k => $v) 132 { 133 $tmpArr[] = $k .'='. $v; 134 } 135 $href = $_SERVER['PHP_SELF'] . '?' . implode('&', $tmpArr); 136 /***** implode transforms array-elements into a string ****/ 137 $tmpA .= "\n" . '<a href="' . $href . '" title="' . $title . '" style="' . $this->mCssStyle . '">'; 138 $tmpA .= $link; 139 $tmpA .= "</a>" . "\n"; 140 return $tmpA; 141 } 142 } 143 144 ?>