[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 # Image Gallery Plugin 3 # Russ Baldwin 4 # http://www.shoesforindustry.net 5 # For more information see the help sections at the end of this file 6 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 # Converted from my User Plugin which was based on the code by RedGuy which in 8 # turn was was inspired by a thumbnailGenerator v2.25 (21|07|2004) by 9 # michael kloepzig mischer@save-the-gummybears.org 10 # http://www.save-the-gummybears.org 11 # 12 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 13 14 15 function smarty_cms_function_ImageGallery($params, &$smarty) 16 { 17 //yu 18 $type = 'click'; // "click" or "popup" 19 $picFolder = 'uploads/images/'; //path to pics, ending with / 20 $divID = 'imagegallery'; // Set the wrapping div id to allow you to have different CSS for each gallery. 21 $sortBy = 'name'; //Sort image files by 'name' o 'date' 22 $sortByOrder = 'asc'; //Sort image files in ascending order: 'asc' or decending order: 'desc' 23 $bigPicCaption = 'name'; // either 'name', 'file', 'number' or 'none', Sets caption above big image. 24 $thumbPicCaption = 'name'; // either 'name', 'file', 'number' or 'none', Sets caption below thumbnails 25 $bigPicAltTag = 'name'; // either 'name', 'file', 'number'. Sets alt tag - compulsory 26 $bigPicTitleTag = 'name'; // either 'name', 'file', 'number' or 'none'. Sets title tag or removes it 27 $thumbPicAltTag = 'name'; // either 'name', 'file', 'number'. Sets alt tag - compulsory 28 $thumbPicTitleTag = ''; // either the default or 'name', 'file', 'number' or 'none'. Sets title tag or removes it 29 30 if(isset($params['divID'])) $divID = $params['divID']; 31 if(isset($params['type'])) $type = $params['type']; 32 if(isset($params['picFolder'])) $picFolder = $params['picFolder']; 33 if(isset($params['bigPicCaption'])) $bigPicCaption = $params['bigPicCaption']; 34 if(isset($params['thumbPicCaption'])) $thumbPicCaption = $params['thumbPicCaption']; 35 if(isset($params['bigPicAltTag'])) $bigPicAltTag = $params['bigPicAltTag']; 36 if(isset($params['bigPicTitleTag'])) $bigPicTitleTag = $params['bigPicTitleTag']; 37 if(isset($params['thumbPicAltTag'])) $thumbPicAltTag = $params['thumbPicAltTag']; 38 if(isset($params['thumbPicTitleTag'])) $thumbPicTitleTag = $params['thumbPicTitleTag']; 39 if(isset($params['sortBy'])) $sortBy = $params['sortBy']; 40 if(isset($params['sortByOrder'])) $sortByOrder = $params['sortByOrder']; 41 42 43 44 //Read Image Folder 45 $selfA = explode('/', $_SERVER["PHP_SELF"]); 46 $self = $selfA[sizeOf($selfA)-1] . '?page=' . $_GET['page']; 47 $picDir = dir($picFolder); 48 $liste = array(); 49 while($check = $picDir->read()) { 50 //if(strpos($check,'.jpg') || strpos($check,'.gif') || strpos($check,'.png')) { 51 if(strpos($check,'.jpg') || strpos($check,'.JPG') || strpos($check,'.jpeg') 52 || strpos($check,'.JPEG') || strpos($check,'.gif') || strpos($check,'.GIF') 53 || strpos($check,'.png') || strpos($check,'.PNG')) { 54 55 $cThumb = explode("_", $check); 56 if($cThumb[0] != "thumb" && $cThumb[0] != "editor") { 57 $liste[] = $check; 58 } 59 } 60 } 61 62 //Sort by date 63 if($sortBy == "date") { 64 $tmp = array(); 65 foreach($liste as $k => $v) { 66 $tmp['file'][$k] = $v; 67 $tmp['date'][$k] = filemtime($picFolder . $v); 68 } 69 70 //Sort by Order 71 ($sortByOrder == 'desc') ? array_multisort($tmp['date'], SORT_DESC, $tmp['file'], SORT_DESC) : array_multisort($tmp['date'], SORT_ASC, $tmp['file'], SORT_ASC); 72 $liste = $tmp['file']; 73 } else ($sortByOrder == 'desc') ? rsort($liste) : sort($liste); 74 75 //Output 76 $count = 1; 77 $output = ''; 78 79 if($type=="popup") { 80 $output .= generate_javascript(); 81 } 82 83 //thumbcount 84 $deci = array(); 85 for($i=1; $i<=sizeof($liste); $i++) { 86 $deci[$i] = $i; 87 while(strlen($deci[$i]) < strlen(sizeof($liste))) $deci[$i] = '0' . $deci[$i]; 88 } 89 90 //Click through gallery image = after you have clicked on an image 91 if($type == 'click' && isset($_GET['img'])) { 92 $bigPic = $picFolder . $liste[$_GET['img']]; 93 $imgSize = getImageSize($bigPic); 94 $img = (!isset($_GET['img'])) ? 1 : $_GET['img']; 95 $next = ($_GET['img'] == (sizeOf($liste)-1)) ? $self : $self . "&img=" . ($_GET['img']+1); 96 $output .= '<div id="'.$divID.'"><div class="bigPic">'. "\n"; 97 $path_parts = pathinfo($bigPic); 98 $extension='.'.$path_parts['extension']; 99 $ImageFileName = basename($bigPic); 100 $bigPicName = basename($bigPic, $extension); 101 102 // Set big pic captions 103 switch($bigPicCaption) 104 { 105 case "name": 106 $output .= '<p class="bigPicCaption">'.$bigPicName.'</p>'."\n"; 107 break; 108 case "number": 109 $output .= '<p class="bigPicCaption">'.($_GET['img']+1).'</p>'."\n"; 110 break; 111 case "file": 112 $output .= '<p class="bigPicCaption">'.$ImageFileName.'</p>'."\n"; 113 break; 114 case "none": 115 break; 116 default: 117 $output .= '<p class="bigPicCaption">'.$bigPicName.'</p>'."\n"; 118 break; 119 } 120 121 //Set Image 122 $output .= '<img src="' . $bigPic .'"'; 123 124 //title tags 125 switch($bigPicTitleTag) 126 { 127 case "name": 128 $output .=' title="'.$bigPicName.'"'; 129 break; 130 case "number": 131 $output .=' title="'.($_GET['img']+1).'"'; 132 break; 133 case "file": 134 $output .=' title="'.$ImageFileName.'"'; 135 break; 136 case "none": 137 break; 138 default: 139 $output .=' title="'.$bigPicName.'"'; 140 break; 141 } 142 143 //alt tags - compulsory 144 switch($bigPicAltTag) 145 { 146 case "name": 147 $output .=' alt="'.$bigPicName.'"'; 148 break; 149 case "number": 150 $output .=' alt="'.($_GET['img']+1).'"'; 151 break; 152 case "file": 153 $output .=' alt="'.$ImageFileName.'"'; 154 break; 155 default: 156 $output .=' alt="'.$bigPicName.'"'; 157 break; 158 } 159 160 //Close tags 161 $output .='/> <br />' . "\n"; 162 $output .= '<p class="bigPicNav">Image ' . ($_GET['img']+1) . ' of ' . sizeOf($liste) . '<br />' . "\n"; 163 $output .= ($_GET['img'] == 0) ? "" : "<a href='" . $self . "&img=" . ($_GET['img']-1) ."'> < Previous</a> | "; 164 $output .= "<a href='" . $self . "'>Index</a>"; 165 $output .= ($_GET['img'] == (sizeOf($liste)-1)) ? "" : " | <a href='" . $next . "'>Next > </a>"; 166 $output .= '</p></div></div>'."\n"; 167 168 } else { 169 170 //Else we are on thumb generation & normal page 171 $output .= '<div id="'.$divID.'">'. "\n"; 172 $i = 1; 173 foreach($liste as $key => $value) { 174 $bigPic = $picFolder . $value; 175 list($bigPicWidth, $bigPicHeight) = getImageSize($bigPic); 176 $thumbPic = $picFolder . 'thumb_' . $value; 177 $thumbSize = @getImageSize($thumbPic) or ($thumbSize[0] = 96) and ($thumbSize[1] = 96); 178 $output .= '<div class="thumb">'; 179 if($type == "click") $output .= '<a href="' . $self . '&img=' . $key . '">' . "\n"; 180 if($type == "popup") $output .= '<a href="javascript:PopupPic(\'' . $bigPic . '\',\'' . ($key+1) . '\',\'' . $bigPicWidth . '\',\''. $bigPicHeight . '\')">' . "\n"; 181 $path_parts = pathinfo($bigPic); 182 $extension='.'.$path_parts['extension']; 183 $ImageFileName = basename($bigPic); 184 $bigPicName = basename($bigPic, $extension); 185 186 //Set Image 187 $output .= '<img src="' . $thumbPic .'"'; 188 189 //title tags 190 switch($thumbPicTitleTag) 191 { 192 case "name": 193 $output .=' title="'.$bigPicName.'... click for a bigger image"'; 194 break; 195 case "number": 196 $output .=' title="'.($key+1).'... click for a bigger image"'; 197 break; 198 case "file": 199 $output .=' title="'.$ImageFileName.'... click for a bigger image"'; 200 break; 201 case "none": 202 break; 203 default: 204 $output .=' title="Click for a bigger image..."'; 205 break; 206 } 207 208 //alt tags - compulsory 209 switch($thumbPicAltTag) 210 { 211 case "name": 212 $output .=' alt="'.$bigPicName.'"'; 213 break; 214 case "number": 215 $output .=' alt="'.($key+1).'"'; 216 break; 217 case "file": 218 $output .=' alt="'.$ImageFileName.'"'; 219 break; 220 default: 221 $output .=' alt="'.$bigPicName.'"'; 222 break; 223 } 224 225 //Close tags 226 $output .='/></a> <br />' . "\n"; 227 // Set thumb captions 228 switch($thumbPicCaption) 229 { 230 case "name": 231 $output .= '<p class="thumbPicCaption">'.$bigPicName.'</p>'."\n"; 232 break; 233 case "number": 234 $output .= '<p class="thumbPicCaption">'.($key+1).'</p>'."\n"; 235 break; 236 case "file": 237 $output .= '<p class="thumbPicCaption">'.$ImageFileName.'</p>'."\n"; 238 break; 239 case "none": 240 break; 241 default: 242 $output .= '<p class="thumbPicCaption">'.$bigPicName.'</p>'."\n"; 243 break; 244 } 245 246 $output .= '</div>' . "\n"; 247 } 248 $output .= '</div>' . "\n\n"; 249 } 250 return $output; 251 } 252 253 function smarty_cms_help_function_ImageGallery() { 254 ?> 255 <h3>What does this do?</h3> 256 <p>Creates a gallery out of a folder of images (.gif, .jpg or .png). 257 You can click on a thumbnail image to view the bigger image. It can use 258 captions which are based on the image name, minus the file extension. It 259 follows web standards and uses CSS for formatting. There are classes 260 for various elements and for the surrounding 'div'. Check out the CSS below for 261 more information.</p> 262 263 <h3>How do I use it?</h3> 264 <p>Just insert the tag into your template or page like: </p> 265 <code>{ImageGallery picFolder="uploads/images/yourfolder/"}</code> 266 <p>Where picFolder is the folder where your images are stored.</p> 267 268 <h3>What parameters does it take?</h3> 269 <p>It can take quite a few parameters, but the example above is probably 270 good for most people :) </p> 271 <ol> 272 <li><strong>picFolder e.g. picFolder="uploads/images/yourfolder/"</strong><br/> 273 Is the path to the gallery (yourfolder) ending in'/'. So you can have 274 lots of directories and lots of galleries.</li> 275 276 <li><strong>type e.g. type="click" or type="popup"</strong><br/> 277 For the "popup" function to work you need to include the popup javascript into 278 the head of your template e.g. "<head></head>". The javascript is at 279 the bottom of this page! <em>The default is 'click'.</em></li> 280 281 <li><strong>divID e.g. divID ="imagegallery"</strong><br/> 282 Sets the wrapping 'div id' around your gallery so that you can have 283 different CSS for each gallery. <em>The default is 'imagegallery'.</em></li> 284 285 <li><strong>sortBy e.g. sortBy = "name" or sortBy = "date"</strong><br/> 286 Sort images by 'name' OR 'date'. <em>No default.</em></li> 287 288 <li><strong>sortByOrder e.g. sortByOrder = "asc" or sortByOrder = "desc"</strong><br/> 289 <em>No default.</em>.</li> 290 291 <li>This sets caption above the big (clicked on) image<br/> 292 <strong>bigPicCaption = "name" </strong>(filename excluding extension)<em> or </em><br/> 293 <strong>bigPicCaption = "file" </strong>(filename including extension)<em> or </em><br/> 294 <strong>bigPicCaption = "number" </strong>(a number sequence)<em> or </em><br/> 295 <strong>bigPicCaption = "none" </strong>(No caption)<br/> 296 <em>The Default is "name". </em></li> 297 298 <li>This sets the caption below the small thumbnail<br/> 299 <strong>thumbPicCaption = "name"</strong> (filename excluding extension)<em> or </em><br/> 300 <strong>thumbPicCaption = "file"</strong> (filename including extension)<em> or </em><br/> 301 <strong>thumbPicCaption = "number" </strong>(a number sequence)<em> or </em><br/> 302 <strong>thumbPicCaption = "none" </strong>(No caption)<br/> 303 <em>The Default is "name".</em></li> 304 305 <li>Sets the 'alt' tag for the big image - compulsory.<br/> 306 <strong>bigPicAltTag = "name" </strong>(filename excluding extension)<em> or </em><br/> 307 <strong>bigPicAltTag = "file" </strong>(filename including extension)<em> or </em><br/> 308 <strong>bigPicAltTag = "number" </strong>(a number sequence)<br/> 309 <em>The Default is "name".</em></li> 310 311 <li> Sets the 'title' tag for the big image. <br/> 312 <strong>bigPicTitleTag = "name" </strong>(filename excluding extension)<em> or </em><br/> 313 <strong>bigPicTitleTag = "file" </strong>(filename including extension)<em> or </em><br/> 314 <strong>bigPicTitleTag = "number" </strong>(a number sequence)<em> or </em><br/> 315 <strong>bigPicTitleTag = "none" </strong>(No title)<br/> 316 <em>The Default is "name".</em></li> 317 318 <li><strong>thumbPicAltTag</strong><br/> 319 <em>Is the same as bigPicAltTag, but for the small thumbnail images.<em></li> 320 321 <li><strong>thumbPicTitleTag *</strong><br/> 322 <em>Is the same as bigPicTitleTag but for the small thumbnail images.<br/> 323 <strong>*Except that after the options you have '... click for a bigger image' 324 or if you do not set this option then you get the default of 325 'Click for a bigger image...'</em></strong></li> 326 </ol> 327 <p>A More Complex Example</p> 328 <p>'div id' is 'cdcovers', no Caption on big images, thumbs have default caption. 329 'alt' tags for the big image are set to the name of the image file without the extension 330 and the big image 'title' tag is set to the same but with an extension. 331 The thumbs have the default 'alt' and 'title' tags. The default being the name 332 of the image file without the extension for 'alt' and 'Click for a bigger image...' for the 'title', 333 would be:</p> 334 <code>{ImageGallery picFolder="uploads/images/cdcovers/" divID="cdcovers" bigPicCaption="none" bigPicAltTag="name" bigPicTitleTag="file"}</code> 335 <br/> 336 <p>It's got lots of options but I wanted to keep it very flexible and you don't have to set them, the defaults are sensible.</p> 337 338 <br/> 339 <h4>Example CSS</h4> 340 <pre> 341 /* Image Gallery - Small Thumbnail Images */ 342 .thumb { 343 margin: 1em 1em 1.6em 0; /* Space between images */ 344 padding: 0; 345 float: left; 346 text-decoration: none; 347 line-height: normal; 348 text-align: left; 349 } 350 351 .thumb img, .thumb a img, .thumb a:link img{ /* Set link formatting*/ 352 width: 100px; /* Image width*/ 353 height: 100px; /* Image height*/ 354 display: inline; 355 padding: 12px; /* Image padding to form photo frame */ 356 /* You can set the above to 0px = no frame - but no hover indication! Adjust other widths ot text!*/ 357 margin: 0; 358 background-color: white; /*Background of photo */ 359 border-top: 1px solid #eee; /* Borders of photo frame */ 360 border-right: 2px solid #ccc; 361 border-bottom: 2px solid #ccc; 362 border-left: 1px solid #eee; 363 text-decoration: none; 364 } 365 366 .thumb a:visited img { 367 background-color: #eee; /*Background of photo on hover - sort of a light grey */ 368 } 369 370 .thumb a:hover img { 371 background-color: #dae6e4; /*Background of photo on hover - sort of light blue/green */ 372 } 373 374 .thumbPicCaption { 375 text-align: center; 376 font-size: smaller; 377 margin: 0 1px 0 0; 378 padding: 0; 379 width: 124px; /* Image width plus 2 x padding for image (photo frame) - to center text on image */ 380 /* display: none; if you do not want to display this text */ 381 } 382 383 /* Image Gallery - Big Images */ 384 .bigPic { 385 margin: 10px 0 5px 0; 386 padding: 0; 387 line-height: normal; 388 } 389 390 .bigPicCaption { /*Big Image Name - above image above .bigpicImageFileName (Without extension) */ 391 text-align: center; 392 font-weight: bold; 393 font-variant: small-caps; 394 font-weight: bold; 395 margin: 0 1px 0 0; 396 padding: 0; 397 width: 386px; /* Image width plus 2 x padding for image (photo frame) - to center text on image */ 398 /* display: none; if you do not want to display this text */ 399 } 400 401 .bigPic img{ /* Big Image settings */ 402 width: 350px; /* Width of Big Image */ 403 height: auto; 404 display: inline; 405 padding: 18px; /* Image padding to form photo frame. */ 406 /* You can set the above to 0px = no frame - but no hover indication! Adjust other widths ot text!*/ 407 margin: 0; 408 background-color: white; /* Background of photo */ 409 border-top: 1px solid #eee; /* Borders of photo frame */ 410 border-right: 2px solid #ccc; 411 border-bottom: 2px solid #ccc; 412 border-left: 1px solid #eee; 413 text-decoration: none; 414 text-align: left; 415 } 416 417 .bigPicNav { /* Big Image information: 'Image 1 of 4' and gallery navigation */ 418 margin: 0; 419 width: 386px; /* Image width plus 2 x padding for image (photo frame) - to center text on image */ 420 padding: 0; 421 color: #000; 422 font-size: smaller; 423 line-height: normal; 424 text-align: center; 425 /* display: none; if you do not want to display this text. Why? You Lose Navigation! */ 426 } 427 428 </pre> 429 <br/> 430 431 <h4>The popup javascript is now included in plugin code and will be generated automatically if you still have javascript in your template please remove it.</h4> 432 <?php 433 /* 434 <pre> 435 {literal} 436 <script type="text/javascript"> 437 <!-- 438 function PopupPic(bigPic,title,w,h) { 439 var winl = (screen.width - w) / 2; 440 var wint = (screen.height - h) / 2; 441 var smarty_hack = 'head'; 442 newWindow = window.open('',title,'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=0,scrollbars=0'); 443 newWindow.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); 444 newWindow.document.write('<html><head><title>'+title+'</title>'); 445 newWindow.document.write('<meta http-equiv="content-type" content="text/html; charset=UTF-8" />'); 446 newWindow.document.write('<style type="text/css"><!-- html, body {margin: 0px; background-color: #000;} --></style>'); 447 newWindow.document.write('</'+smarty_hack+'><body onclick="self.close()">'); 448 newWindow.document.write('<p><img src="'+bigPic+'" alt="'+title+'" /></p>'); 449 newWindow.document.write('</body></html>'); 450 newWindow.document.close(); 451 newWindow.focus(); 452 } 453 --> 454 </script> 455 {/literal} 456 </pre> 457 <br /> 458 */ 459 ?> 460 <?php 461 } 462 463 function smarty_cms_about_function_ImageGallery() { 464 ?> 465 <p>Author: <strong>Russ Baldwin</strong> (but see below.)</p> 466 <p>Website: <strong><a href="http://www.shoesforindustry.net"> www.shoesforindustry.net</a></strong></p> 467 <p>Version: <strong>0.3 Beta</strong></p> 468 <p>Date: <strong>2006-02-22</strong></p> 469 <p> 470 Change History:<br/> 471 <strong>2006-02-22 - Version 0.3 Beta</strong><br/>Fixed a bug with searching for images based on 472 lower case extensions. It now searches for both upper and lower case extensions.<br />Re-added the popup function. <em>(Redguy)</em>.<br/> 473 <strong>2006-02-21 - Version 0.2 Beta</strong><br/>Second release fixed some typos<br/> 474 <strong>2006-02-20 - Version 0.1 Beta</strong><br/>First release as a Plugin (Tag)</p> 475 <p>***************************************</p> 476 <p>This plugin (tag) is based on my original 'user-tag' which was itself 477 based upon a 'user tag' by RedGuy. This in turn was based on some code by 478 Michael Kloepzig <a href='http://save-the-gummybears.org/stg/' target='_blank'>Save-the-gummybears.org</a>. Phew...</p> 479 <p>All credit where credit is due :)</p> 480 481 <?php 482 } 483 484 function generate_javascript() { 485 global $gCms; 486 $config=$gCms->config; 487 488 static $count; 489 if ($count==0) { 490 491 $out = " 492 <script type=\"text/javascript\"> 493 <!-- 494 function PopupPic(bigPic,title,w,h) { 495 var winl = (screen.width - w) / 2; 496 var wint = (screen.height - h) / 2; 497 var smarty_hack = 'head'; 498 newWindow = window.open('',title,'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=0,scrollbars=0'); 499 newWindow.document.write('<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">'); 500 newWindow.document.write('<html><head><title>'+title+'</title><base href=\"".$config[root_url]."/\" />'); 501 newWindow.document.write('<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />'); 502 newWindow.document.write('<style type=\"text/css\"><!-- html, body {margin: 0px; background-color: #000;} --></style>'); 503 newWindow.document.write('</'+smarty_hack+'><body onclick=\"self.close()\">'); 504 newWindow.document.write('<p><img src=\"'+bigPic+'\" alt=\"'+title+'\" /></p>'); 505 newWindow.document.write('</body></html>'); 506 newWindow.document.close(); 507 newWindow.focus(); 508 } 509 --> 510 </script> 511 "; 512 } 513 514 $count++; 515 516 return $out; 517 } 518 519 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |