Dateigrösse: 6.12 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 = 1; // 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 private $mCorrectFaktor = 1; 26 27 public function __construct($i_perpage, $i_lastpage, $i_nextpage, $s_pagelabel, $a_params4link, $a_tmpl, $s_css, $s_csshover) 28 { 29 $this->mPerPage = $i_perpage; 30 $this->mPageLabel = $s_pagelabel; 31 $this->mGetParams = $a_params4link; 32 $this->mActPage = $this->mGetParams[$this->mPageLabel]; 33 $this->mSuchbegriff = $this->mGetParams['suchbegriff']; 34 $this->mLastPageFull= $i_lastpage; 35 $this->mLastPage = floor($i_lastpage/$this->mPerPage); 36 $this->mNextPage = $i_nextpage; 37 $this->mArrTmpl = $a_tmpl; 38 $this->mCssStyle = $s_css; 39 $this->mCssActive = $s_csshover; 40 41 if (strpos ($this->mArrTmpl[2], "##") !== FALSE) 42 { 43 $this->mArrTmpl[2] = str_replace("##", $this->mActPage+$this->mCorrectFaktor, $this->mArrTmpl[2]); 44 } 45 } 46 47 public function toHtml() 48 { 49 $first = ''; $previous = ''; $next = ''; $last = ''; $backward = ''; $forward = ''; 50 51 if ($this->mActPage > 0) 52 { 53 for ($i=$this->mNextPage; $i>0; $i--) 54 { 55 if ($this->mActPage - $i >= 0) 56 { 57 $backward .= $this->_aHtml( $this->mActPage - $i, 58 'zur Seite ' . ($this->mActPage - $i + $this->mCorrectFaktor) . '', 59 $this->mActPage - $i + $this->mCorrectFaktor, 60 'default' ); 61 } 62 } 63 64 if(($this->mActPage-1) >= (1-$this->mNextPage)) 65 { 66 $first = $this->_aHtml( 0, 67 'zur Startseite', 68 $this->mArrTmpl[0] ); 69 } else { 70 $first = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[5].'</span>'; 71 } 72 73 if(($this->mActPage-1) >= $this->mNextPage ) 74 { 75 $previous = $this->_aHtml( $this->mActPage-1-$this->mNextPage, 76 'zur vorangehenden Seite', 77 $this->mArrTmpl[1] ); 78 } else { 79 $previous = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[6].'</span>'; 80 } 81 } 82 else 83 { 84 $first = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[5].'</span>'; 85 $previous = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[6].'</span>'; 86 } 87 88 // If next, i.e. last page, is empty, hide all arrow symbols [ example: (5*4 + 4) / 20 == 1 ] 89 // ueberfluessig: if ($this->mActPage < $this->mLastPage) 90 if (($this->mActPage*$this->mPerPage + $this->mPerPage) / $this->mLastPageFull < 1) 91 { 92 for ($i=1; $i<=$this->mNextPage; $i++) 93 { 94 if ($this->mActPage+$i <= $this->mLastPage) 95 { 96 $forward .= $this->_aHtml( $this->mActPage + $i, 97 'zur Seite ' . ($this->mActPage + $i + $this->mCorrectFaktor) . '', 98 $this->mActPage + $i + $this->mCorrectFaktor, 99 'default' ); 100 } 101 } 102 103 104 if($this->mLastPageFull / $this->mPerPage > $this->mActPage+1+$this->mNextPage) 105 { 106 $next = $this->_aHtml( $this->mActPage+1+$this->mNextPage, 107 'zur nächsten Seite', 108 $this->mArrTmpl[3] ); 109 110 } else { 111 $next = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[7].'</span>'; 112 } 113 114 if($this->mLastPageFull % $this->mPerPage == 0) 115 { 116 $last = $this->_aHtml( $this->mLastPage-1, 117 'zur letzten Seite', 118 $this->mArrTmpl[4] ); 119 } else { 120 $last = $this->_aHtml( $this->mLastPage, 121 'zur letzten Seite', 122 $this->mArrTmpl[4] ); 123 } 124 } 125 else 126 { 127 $next = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[7].'</span>'; 128 $last = '<span style="'.$this->mCssStyle.'">'.$this->mArrTmpl[8].'</span>'; 129 } 130 131 if ($this->mLastPageFull <= $this->mPerPage) 132 { 133 $slider = ''; 134 } else { 135 $slider .= $first; 136 $slider .= $previous; 137 $slider .= $backward; 138 $slider .= '<span style="'.$this->mCssActive.'" title="' . $this->mActPage . '">'.$this->mArrTmpl[2].'</span>'; 139 $slider .= $forward; 140 $slider .= $next; 141 $slider .= $last; 142 } 143 144 return $slider; 145 } 146 147 private function _aHtml($actPage, $title, $link, $class='') 148 { 149 $tmpA = ''; 150 $tmpArr = array(); 151 $this->mGetParams[$this->mPageLabel] = $actPage*$this->mPerPage; 152 foreach ($this->mGetParams as $k => $v) 153 { 154 $tmpArr[] = $k .'='. $v; 155 } 156 $href = $_SERVER['PHP_SELF'] . '?' . implode('&', $tmpArr); 157 /***** implode transforms array-elements into a string ****/ 158 $tmpA .= "\n"; 159 $tmpA .= '<a href="' . $href . '" title="' . $title . '" class="' . $class . '" style="' . $this->mCssStyle . '">'; 160 $tmpA .= $link; 161 $tmpA .= '</a>' . "\n"; 162 return $tmpA; 163 } 164 } 165 166 ?>