Esempio n. 1
0
 public function render()
 {
     $imageResults = $this->getImages();
     $gallery = $this->getGallery();
     $ids = array();
     foreach ($imageResults as $image) {
         $ids[] = $image->imageId;
     }
     $args = array('post_type' => 'attachment', 'posts_per_page' => -1, 'include' => $ids);
     $atts = get_posts($args);
     foreach ($atts as $att) {
         $this->images[$att->ID] = $att->guid;
     }
     if ($gallery->shuffle == 'T') {
         shuffle($imageResults);
     }
     $bgCaption = $this->toRGB($gallery->hoverColor);
     $html = "";
     if (strlen($gallery->style) || $gallery->borderSize || $gallery->backgroundColor || $gallery->borderRadius || $gallery->shadowSize) {
         $html .= "<style>\n";
         if ($gallery->borderSize) {
             $html .= "#ftg-{$this->id} .tile .tile-inner { border: " . $gallery->borderSize . "px solid " . $gallery->borderColor . "; }\n";
         }
         if ($gallery->backgroundColor) {
             $html .= "#ftg-{$this->id} .tile .tile-inner { background-color: " . $gallery->backgroundColor . "; }\n";
         }
         if ($gallery->borderRadius) {
             $html .= "#ftg-{$this->id} .tile .tile-inner { border-radius: " . $gallery->borderRadius . "px; }\n";
         }
         if ($gallery->shadowSize) {
             $html .= "#ftg-{$this->id} .tile .tile-inner { box-shadow: " . $gallery->shadowColor . " 0px 0px " . $gallery->shadowSize . "px; }\n";
         }
         $html .= "#ftg-{$this->id} .tile .caption { background-color: #{$gallery->hoverColor}; }\n";
         $html .= "#ftg-{$this->id} .tile .caption { background-color: rgba({$bgCaption['0']}, {$bgCaption['1']}, {$bgCaption['2']}, " . $gallery->hoverOpacity / 100 . "); }\n";
         if (strlen($gallery->style)) {
             $html .= $gallery->style;
         }
         $html .= "</style>\n";
     }
     $html .= "<div class='final-tiles-gallery' id='ftg-{$this->id}' style='width:{$gallery->width}'>\n";
     if (strlen($gallery->filters)) {
         $filters = explode("|", $gallery->filters);
         $html .= "<div class='ftg-filters'>\n";
         $html .= "\t<a href='#'>All</a>\n";
         foreach ($filters as $filter) {
             $html .= "\t<a href='#set-" . FinalTilesGallery::slugify($filter) . "'>{$filter}</a>\n";
         }
         $html .= "</div>\n";
     }
     $html .= "<div class='ftg-items'>\n";
     foreach ($imageResults as $image) {
         $rel = $gallery->lightbox == "prettyphoto" ? "prettyPhoto[ftg-{$this->id}]" : "ftg-{$this->id}";
         $html .= "<div class='tile " . FinalTilesGallery::getFilters($image->filters) . "'>\n";
         $html .= "<a " . ($gallery->lightbox == "lightbox2" ? "data-lightbox='gallery'" : "") . " rel='{$rel}' " . ($image->blank == "T" ? "target='_blank' " : " ") . " class='tile-inner " . ($image->zoom == "T" ? "zoom" : "") . "' " . $this->getLink($image) . ">\n";
         $html .= "<img class='item' src='{$image->imagePath}' />\n";
         if (!empty($image->description)) {
             $html .= "<div class='caption'><p>{$image->description}</p></div>\n";
         }
         $html .= "</a>\n";
         $html .= "</div>\n";
     }
     $html .= "</div>\n";
     $html .= "</div>\n";
     $html .= "<script type='text/javascript'>\n";
     $html .= "\tjQuery('#ftg-{$this->id}').finalTilesGallery({\n";
     $html .= "\t\tminTileWidth: {$gallery->minTileWidth},\n";
     if (strlen($gallery->script)) {
         $html .= "\t\tonComplete: function () { " . stripslashes($gallery->script) . "},\n";
     }
     $html .= "\t\tmargin: {$gallery->margin},\n";
     $html .= "\t\tgridCellSize: {$gallery->gridCellSize},\n";
     $html .= "\t\thoverEffectDuration: {$gallery->hoverEffectDuration},\n";
     $html .= "\t\thoverEffect: '{$gallery->hoverEffect}',\n";
     $html .= "\t\thoverEasing: '{$gallery->hoverEasing}',\n";
     $html .= "\t\tenableTwitter: " . ($gallery->enableTwitter == "T" ? "true" : "false") . ",\n";
     $html .= "\t\tenableFacebook: " . ($gallery->enableFacebook == "T" ? "true" : "false") . ",\n";
     $html .= "\t\tenablePinterest: " . ($gallery->enablePinterest == "T" ? "true" : "false") . ",\n";
     $html .= "\t\tenableGplus: " . ($gallery->enableGplus == "T" ? "true" : "false") . ",\n";
     $html .= "\t\tallowEnlargement: " . ($gallery->enlargeImages == "T" ? "true" : "false") . ",\n";
     $html .= "\t\tscrollEffect: '" . $gallery->scrollEffect . "'\n";
     $html .= "\t});\n";
     $html .= "\tjQuery(function () {\n";
     switch ($gallery->lightbox) {
         default:
             break;
         case 'magnific':
             $html .= "\t\tjQuery('#ftg-{$this->id} .tile a.zoom').magnificPopup({type:'image', zoom: { enabled: true, duration: 300, easing: 'ease-in-out' }});\n";
             break;
         case 'prettyphoto':
             $html .= "\t\tjQuery('#ftg-{$this->id} .tile a.zoom').prettyPhoto({social_tools:''});\n";
             break;
         case 'colorbox':
             $html .= "\t\tjQuery('#ftg-{$this->id} .tile a.zoom').colorbox({rel: 'gallery'});\n";
             break;
         case 'fancybox':
             $html .= "\t\tjQuery('#ftg-{$this->id} .tile a.zoom').fancybox({});\n";
             break;
         case 'swipebox':
             $html .= "\t\tjQuery('#ftg-{$this->id} .tile a.zoom').swipebox({});\n";
             break;
     }
     $html .= "\t\tvar preload = jQuery('#ftg-{$this->id} .tile a.zoom');\n";
     $html .= "\t\tvar _idx = 0;\n";
     $html .= "\t\tvar _img = new Image();\n";
     $html .= "\t\t_img.onload=function () { if(++_idx < preload.length) this.src = preload.eq(_idx).attr('href'); };\n";
     $html .= "\t\t_img.src = preload.eq(_idx).attr('href');\n";
     $html .= "\n";
     $html .= "\n";
     $html .= "\t});\n";
     $html .= "</script>";
     if (!empty($_GET["debug"])) {
         return $html;
     }
     return str_replace(array("\n", "\t"), "", $html);
 }
 public function create_gallery($galleryId)
 {
     require_once 'lib/gallery-class.php';
     global $FinalTilesGallery;
     if (class_exists('FinalTilesGallery')) {
         $FinalTilesGallery = new FinalTilesGallery($galleryId, $this->FinalTilesdb);
         $settings = $FinalTilesGallery->getGallery();
         switch ($settings->lightbox) {
             default:
             case "magnific":
                 wp_enqueue_style('magnific_stylesheet');
                 wp_enqueue_script('magnific_script');
                 break;
             case "prettyphoto":
                 wp_enqueue_style('prettyphoto_stylesheet');
                 wp_enqueue_script('prettyphoto_script');
                 break;
             case "fancybox":
                 wp_enqueue_style('fancybox_stylesheet');
                 wp_enqueue_script('fancybox_script');
                 break;
             case "colorbox":
                 wp_enqueue_style('colorbox_stylesheet');
                 wp_enqueue_script('colorbox_script');
                 break;
             case "swipebox":
                 wp_enqueue_style('swipebox_stylesheet');
                 wp_enqueue_script('swipebox_script');
                 break;
             case "lightbox2":
                 wp_enqueue_style('lightbox2_stylesheet');
                 wp_enqueue_script('lightbox2_script');
                 break;
         }
         return $FinalTilesGallery->render();
     } else {
         return "Gallery not found.";
     }
 }