BMo-Design's Mootools Javascript ScrollGallery as a Plugin for the Wordpress NextGEN Gallery. Author: Benedikt Morschheuser Author URI: http://bmo-design.de/ Version: 2.0.2 Copyright 2011-2012 by Benedikt Morschheuser (http://bmo-design.de/kontakt/) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA http://wordpress.org/about/gpl/ ################################################################# The current version used the scrollGallery2 1.10. with mobile extension ################################################################# */ // Restrictions if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); } //############################################################### define('SG2_SITEBASE_URL' , get_option('siteurl')); define('SG2_PLUGINNAME', trim(plugin_basename(dirname(__FILE__)))); define('SG2_URL', get_option('siteurl').'/wp-content/plugins/' . dirname(plugin_basename(__FILE__))); // get_bloginfo('wpurl') define('SG2_BASEPATH', WP_PLUGIN_DIR.'/'. dirname(plugin_basename(__FILE__))); //############################################################### require_once (SG2_BASEPATH . '/admin/admin.php'); class scrollGallery2 { private $sgversion = "2.0.2"; //Version private $sgJSArray = array(); public function scrollGallery2ReplaceShortcode($atts, $content = '') { //new Version, see http://codex.wordpress.org/Shortcode_API global $wpdb; //neue Version: $sgconfig = $this->get_SGConfiguration($atts); if( !is_numeric($sgconfig["galleryID"]) ) $sgconfig["galleryID"] = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $sgconfig["galleryID"]) ); if( !empty($sgconfig["galleryID"]) ) $out = $this->SGShow($sgconfig); else $out = '[Gallery not found]'; return $out.$content; } public function scrollGallery2ReplaceShortcode_thumbsSolo($atts, $content = '') { //new Version, see http://codex.wordpress.org/Shortcode_API global $wpdb; //neue Version: $sgconfig = $this->get_SGConfiguration($atts); if( !is_numeric($sgconfig["galleryID"]) ) $sgconfig["galleryID"] = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $sgconfig["galleryID"]) ); if( !empty($sgconfig["galleryID"]) ) $out = $this->SGShow($sgconfig, NULL, true, false); else $out = '[Gallery not found]'; return $out.$content; } public function scrollGallery2ReplaceShortcode_imagesSolo($atts, $content = '') { //new Version, see http://codex.wordpress.org/Shortcode_API global $wpdb; //neue Version: $sgconfig = $this->get_SGConfiguration($atts); if( !is_numeric($sgconfig["galleryID"]) ) $sgconfig["galleryID"] = $wpdb->get_var( $wpdb->prepare ("SELECT gid FROM $wpdb->nggallery WHERE name = '%s' ", $sgconfig["galleryID"]) ); if( !empty($sgconfig["galleryID"]) ) $out = $this->SGShow($sgconfig, NULL, false, true); else $out = '[Gallery not found]'; return $out.$content; } public function get_SGConfiguration($data) { //build sgconfig from parameter and options $options = get_option("SG2_Options"); //extract sub arrays in $data clickable="clickable=true,next_button=true,prev_button=true,button_opacity=100" -> clickable=array('clickable'=>true,'next_button'=>true,'prev_button'=>true, 'button_opacity'=>100) foreach( $data as $key => $value ) { if(stripos($value,',')!==false){ $dataSubarrKomma = explode(',',str_replace(" ","", $value)); $dataSubarr = array(); foreach ($dataSubarrKomma as $k => $v){ $dataSubarrGleich = explode('=', $v); $dataSubarr[$dataSubarrGleich[0]]=$dataSubarrGleich[1]; } $data[$key]=$dataSubarr; } } // $sgconfig = array(); $sgconfig["galleryID"] = (int) ( (array_key_exists("id" , $data))? $data["id"] :0 ); $sgconfig["start"] = (int) ( (array_key_exists("start" , $data))? $data["start"] : $options["SG2_start"] ); $sgconfig["area"] = (int) ( (array_key_exists("area" , $data))? $data["area"] : $options["SG2_area"] ); $sgconfig["thumbarea"] = (string) ( (array_key_exists("thumbarea" , $data))? $data["thumbarea"] : $options["SG2_thumbarea"] ); $sgconfig["imagearea"] = (string) ( (array_key_exists("imagearea" , $data))? $data["imagearea"] : $options["SG2_imagearea"] ); $sgconfig["speed"] = (string) ( (array_key_exists("speed" , $data))? $data["speed"] : $options["SG2_speed"] ); $sgconfig["clickable"] = (array) ( (array_key_exists("clickable" , $data)&&is_array($data["clickable"]))?$data["clickable"] : $options["SG2_clickable"] ); $sgconfig["thumbArrows"] = (array) ( (array_key_exists("thumbarrows" , $data)&&is_array($data["thumbarrows"]))?$data["thumbarrows"] : $options["SG2_thumbArrows"] ); $sgconfig["autoScroll"] = (bool) ( (array_key_exists("autoscroll", $data))?($data["autoscroll"] == 'false'?false:true): $options["SG2_autoScroll"] ); $sgconfig["enableSwipeMode"] = (bool) ( (array_key_exists("enableswipemode", $data))?($data["enableswipemode"] == 'false'?false:true): $options["SG2_enableSwipeMode"] ); $sgconfig["followImages"] = (bool) ( (array_key_exists("followimages", $data))?($data["followimages"] == 'false'?false:true): $options["SG2_followImages"] ); $sgconfig["useCaptions"] = (bool) ( (array_key_exists("usecaptions", $data))?($data["usecaptions"] == 'false'?false:true): $options["SG2_useCaptions"] ); $sgconfig["useDesc"] = (bool) ( (array_key_exists("usedesc", $data))?($data["usedesc"] == 'false'?false:true): $options["SG2_useDesc"] ); $sgconfig["thumbsdown"] = (bool) ( (array_key_exists("thumbsdown", $data))?($data["thumbsdown"] == 'false'?false:true): $options["SG2_thumbsdown"] ); $sgconfig["diashow"] = (bool) ( (array_key_exists("diashow", $data))?($data["diashow"] == 'false'?false:true): $options["SG2_diashow"] ); $sgconfig["diashowDelay"] = (int) ( (array_key_exists("diashowdelay" , $data))? $data["diashowdelay"] : $options["SG2_diashowDelay"] ); $sgconfig["thumbOpacity"] = (int) ( (array_key_exists("thumbopacity" , $data))? $data["thumbopacity"] : $options["SG2_thumbOpacity"] ); $sgconfig["width"] = (int) ( (array_key_exists("width" , $data))? $data["width"] : $options["SG2_width"] ); $sgconfig["height"] = (int) ( (array_key_exists("height" , $data))? $data["height"] : $options["SG2_height"] ); //$sgconfig["design"] = (string) $options["SG2_design"] ;//page should use only one design //margins $dimensions = array("px","em","%","pt"); $margins = explode(" ", trim(str_replace($dimensions,"",$options["SG2_design_margin"])));//we only work with px $marginsT = explode(" ", trim(str_replace($dimensions,"",$options["SG2_design_thumbmargin"])));//we only work with px $sgconfig["margin_top"] =$margins[0]; $sgconfig["margin_right"] =$margins[1]; $sgconfig["margin_bottom"] =$margins[2]; $sgconfig["margin_left"] =$margins[3]; #todo SG2_design_margin wird bisher nicht genutzt bei design, geht alles über max-width % $sgconfig["margin_t_top"] =$marginsT[0]; $sgconfig["margin_t_right"] =$marginsT[1]; $sgconfig["margin_t_bottom"]=$marginsT[2]; $sgconfig["margin_t_left"] =$marginsT[3]; return $sgconfig; } public function SGShow($sgconfig, $pictures = NULL, $buildThumbs = true, $buildImages = true) { global $wpdb; extract($sgconfig); // Get the pictures if ($galleryID) { $ngg_options = get_option ('ngg_options'); //NextGenGallery Options $pictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.$ngg_options[galSort] $ngg_options[galSortDir] "); $finalInformation = array(); foreach($pictures as $picture) { $getInformation = array(); $getInformation["title"] = stripslashes($picture->alttext); // $picture->alttext; $getInformation["desc"] = $picture->description; $getInformation["link"] = SG2_SITEBASE_URL . "/" . $picture->path ."/" . $picture->filename; $getInformation["img"] = SG2_SITEBASE_URL . "/" . $picture->path ."/" . $picture->filename; $getInformation["img_abs_path"] = ABSPATH . $picture->path ."/" . $picture->filename; $getInformation["thumb"] = SG2_SITEBASE_URL . "/" . $picture->path ."/thumbs/thumbs_" . $picture->filename; //metaData $serialized_data = unserialize($picture->meta_data); $getInformation["width"] = $serialized_data["width"]; $getInformation["height"] = $serialized_data["height"]; $getInformation["thumbWidth"] = $serialized_data["thumbnail"]["width"]; $getInformation["thumbHeight"] = $serialized_data["thumbnail"]["height"]; $finalInformation[] = $getInformation; } $pictures = $finalInformation; } else { $galleryID = rand();//falls pictures als parameter übergeben werden } if (empty($pictures)) return ""; //only if we have output enque the registered scripts wp_enqueue_script('mootools'); wp_enqueue_script('scrollGallery2'); wp_enqueue_script('powertools'); //JS $scriptout = 'var scrollGallery2Obj'.$galleryID.' = new scrollGallery2({scrollGalleryContainer:"scrollGallery2_'.$galleryID.'",'; if(is_numeric($start)) $scriptout .= 'start:'.$start.','; if($area) $scriptout .= 'area:'.$area.','; if(!$thumbarea||$thumbarea=="") $thumbarea="thumbarea"; $scriptout .= 'thumbarea:"'.$thumbarea.'_'.$galleryID.'",'; if(!$imagearea||$imagearea=="") $imagearea="imagearea"; $scriptout .= 'imagearea:"'.$imagearea.'_'.$galleryID.'",'; if($speed) $scriptout .= 'speed:'.$speed.','; if(!$clickable['clickable']) $scriptout .= 'clickable:false,'; if($autoScroll) $scriptout .= 'autoScroll:true,'; if($enableSwipeMode) $scriptout .= 'enableSwipeMode:true,'; if(!$followImages) $scriptout .= 'followImages:false,'; # if(...) $scriptout .= 'toElementClass:"img",';// img, standard ist li if($diashow&&$diashowDelay) $scriptout .= 'diashowDelay:'.$diashowDelay.','; if($thumbOpacity<100&&$thumbOpacity>0) $scriptout .= 'thumbOpacity:'.$thumbOpacity.','; $scriptout = substr($scriptout, 0, -1); // Remove last , $scriptout .= '}); '; $this->sgJSArray[$galleryID] = $scriptout; #save JS for later in foot //HTML $imageAreaWidth=0; $thumbAreaWidth=0; $thumbAreaHeight=0; foreach ($pictures as $picture){ if ($picture["img"]) { $imageAreaWidth+=($width+$margin_left+$margin_right); $thumbAreaWidth+=($picture["thumbWidth"]+$margin_t_left+$margin_t_right); if($thumbAreaHeight<($picture["thumbHeight"]+$margin_t_top+$margin_t_bottom)) $thumbAreaHeight=($picture["thumbHeight"]+$margin_t_top+$margin_t_bottom); } } $outT = ''; //Thumbs out if($buildThumbs==true){ $outT .= '
'; } $outI = ''; //Images out if($buildImages==true){ $outI .= '