Last active
August 29, 2015 14:27
-
-
Save sajhd/89fd61d6b2dc05d2c39c to your computer and use it in GitHub Desktop.
auto-gallery.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| To be included at the top of every page that has the gallery. | |
| <?php | |
| class gallery { | |
| public $imagePath = null; | |
| public $thumbsPath = null; | |
| function __construct( $imagePath, $thumbsPath, $rel, $alt) { | |
| $this->imagePath = $imagePath; | |
| $this->thumbsPath = $thumbsPath; | |
| $this->rel = $rel; | |
| $this->alt = $alt; | |
| } | |
| function getExtension($str) { | |
| $i = strrpos($str,"."); | |
| if (!$i) { return ""; } | |
| $l = strlen($str) - $i; | |
| $ext = substr($str,$i+1,$l); | |
| return $ext; | |
| } | |
| function getFirstChar($string){ | |
| return $string[0]; | |
| } | |
| function toHtml($showOrder) { | |
| if(file_exists($this->imagePath)){ | |
| $directory = opendir($this->imagePath); | |
| while($item = readdir($directory)){ | |
| $extension = $this->getExtension($item); | |
| $firstChar = $this->getFirstChar($item); | |
| if(($item != ".") && ($item != "..") && ($firstChar != ".")){ | |
| if (($extension == "jpg") || ($extension == "jpeg") || ($extension == "png") || ($extension == "gif")|| ($extension == "JPG")){ | |
| $files[] = $item; | |
| } | |
| } | |
| } | |
| if(isset($files)){ | |
| sort($files); | |
| $altStart = 1; | |
| $count = 1; | |
| $titleCount = "1"; | |
| foreach($files as $a){ | |
| ?> | |
| <?php | |
| if ($showOrder) : ?> | |
| <div style="float: left; width: 50%;"> | |
| <?php echo $altStart . " - " . $this->alt[$altStart] . "<br />"; | |
| endif; | |
| ?> | |
| <a href="<?php echo $this->imagePath.$a; ?>" data-fancybox-group="<?php echo $this->rel; ?>" class="fancybox" title="<?php echo $this->alt[$altStart];?>"><?php if(file_exists($this->thumbsPath.$a)){?><img src="<?php echo $this->thumbsPath.$a; ?>" alt="<?php echo $this->alt[$altStart++];?>" /><?php }?></a> | |
| <?php | |
| if ($showOrder) : ?> | |
| </div><?php | |
| endif; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Fancybox | |
| $(".fancybox").fancybox({ | |
| 'transitionIn' : 'fade', | |
| 'transitionOut' : 'fade', | |
| 'speedIn' : 600, | |
| 'speedOut' : 200, | |
| 'overlayShow' : true | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $alt = array( | |
| 1 => $pagekw, | |
| 2 => $pagekw, | |
| 3 => $pagekw, | |
| 4 => $pagekw | |
| ); | |
| $showOrder = false; | |
| $gallery = new gallery("images/$subpage/", "images/$subpage/thumbs/", "Gallery", $alt); | |
| $gallery->toHtml($showOrder); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment