Advertisement
jwkite

MultiGallery NextGen NivoSlider

Nov 29th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.51 KB | None | 0 0
  1. <?php
  2.  
  3. Class NGG_NivoSlider_Widget extends WP_Widget {
  4.  
  5.     public function __construct() {
  6.         $widget_ops = array(
  7.                 'classname' => 'ngg-nivoslider',
  8.                 'description' => 'Allows you to pick a gallery from the \'NextGen Gallery\' plugin to use as a Nivo Slider.' );
  9.  
  10.         parent::WP_Widget( 'nextgen-nivoslider', 'NextGEN NivoSlider', $widget_ops );
  11.     }
  12.  
  13.     public function widget( $args, $instance ) {
  14.         // Enqueue scripts if being loaded as Widget
  15.         if( is_active_widget( false, false, $this->id_base) ) {
  16.             wp_enqueue_script( 'jquery' );
  17.             wp_enqueue_script( 'jquery-nivo-slider' );
  18.             wp_enqueue_script( 'jquery-shuffle' );
  19.         }
  20.  
  21.         global $wpdb;
  22.         extract( $args );
  23.  
  24.         // Plugin Settings
  25.         $s = array(
  26.                 'title' => apply_filters( 'widget_title', (isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : "") ),
  27.                 'htmlID' => $this->get_val( $instance, 'html_id', 'slider' ),
  28.                 'width' => $this->get_val_numeric( $instance, 'width' ),
  29.                 'height' => $this->get_val_numeric( $instance, 'height' ),
  30.                 'resizeWidth' => $this->get_val_numeric( $instance, 'resizewidth' ),
  31.                 'resizeHeight' => $this->get_val_numeric( $instance, 'resizeheight' ),
  32.                 'resizeBGColor' => $this->get_val( $instance, 'resizebg' ),
  33.                 'resize' => $this->get_val( $instance, 'resize' ),
  34.                 'order' => $this->get_val( $instance, 'order', 'asc', false ),
  35.                 'tags' => $this->get_val( $instance, 'tags' ),
  36.                 'shuffle' => $this->get_val( $instance, 'shuffle' ),
  37.                 'limit' => $this->get_val_numeric( $instance, 'max_pictures' ),
  38.                 'center' => $this->get_val( $instance, 'center' ),
  39.                 'gallery' => $this->get_val( $instance, 'gallery' ),
  40.                 'shortCode' => $this->get_val( $instance, 'shortcode' ),
  41.                 'caption' => $this->get_val( $instance, 'caption' ),
  42.                 'htmlCaption' => $this->get_val( $instance, 'htmlcaption', '' ),
  43.                 'theme' => get_option( 'ngg_nivoslider_theme', 'default' ),
  44.                 'thumbsWidth' => $this->get_val_numeric( $instance, 'thumbswidth' ),
  45.                 'thumbsHeight' => $this->get_val_numeric( $instance, 'thumbsheight' ),
  46.                 'thumbsContainerHeight' => $this->get_val_numeric( $instance, 'thumbscontainerheight' ),
  47.                 'thumbsGap' => $this->get_val_numeric( $instance, 'thumbsgap' ),
  48.                 'showGalleryTitle' => $this->get_val( $instance, 'showgallerytitle' ),
  49.                 'showGalleryDesc' => $this->get_val( $instance, 'showgallerydesc' ),
  50.         );
  51.  
  52.         // Nivo Slider Settings
  53.         $ns = array(
  54.                 'effect' => $this->get_val( $instance, 'effect' ),
  55.                 'slices' => $this->get_val( $instance, 'slices' ),
  56.                 'boxCols' => $this->get_val( $instance, 'boxcols' ),
  57.                 'boxRows' => $this->get_val( $instance, 'boxrows' ),
  58.                 'animSpeed' => $this->get_val( $instance, 'animspeed' ),
  59.                 'pauseTime' => $this->get_val( $instance, 'pausetime' ),
  60.                 'startSlide' => $this->get_val( $instance, 'startslide' ),
  61.                 'directionNav' => $this->get_val( $instance, 'directionnav' ),
  62.                 'controlNav' => $this->get_val( $instance, 'controlnav' ),
  63.                 'controlNavThumbs' => $this->get_val( $instance, 'controlnavthumbs' ),
  64.                 'pauseOnHover' => $this->get_val( $instance, 'pauseonhover' ),
  65.                 'keyboardNav' => $this->get_val( $instance, 'keyboardnav' ),
  66.                 'manualAdvance' => $this->get_val( $instance, 'manualadvance' ),
  67.                 'prevText' => $this->get_val( $instance, 'prevtext' ),
  68.                 'nextText' => $this->get_val( $instance, 'nexttext' ),
  69.                 'randomStart' => $this->get_val( $instance, "randomstart" ),
  70.                 'captionOpacity' => $this->get_val( $instance, 'captionopacity' ),
  71.                 'beforeChange' => $this->get_val( $instance, 'beforechange', '', false ),
  72.                 'afterChange' => $this->get_val( $instance, 'afterchange', '', false ),
  73.                 'slideshowEnd' => $this->get_val( $instance, 'slideshowend', '', false ),
  74.                 'lastSlide' => $this->get_val( $instance, 'lastslide', '', false ),
  75.                 'afterLoad' => $this->get_val( $instance, 'afterload', '', false )
  76.         );
  77.  
  78.         // Declare some variables for readability
  79.         $width = $s['width'];
  80.         $height = $s['height'];
  81.         $htmlID = $s['htmlID'];
  82.  
  83.         // SQL defaults
  84.         $sqlOrder = '';
  85.         $sqlWhere = ' WHERE exclude = 0';
  86.         $sqlLimit = '';
  87.  
  88.         // Set SQL order
  89.         switch ( $s['order'] ) {
  90.             case 'random':
  91.                 $sqlOrder = 'RAND()';
  92.                 break;
  93.             case 'sortorder':
  94.                 $sqlOrder = 'sortorder ASC';
  95.                 break;
  96.             case 'desc':
  97.                 $sqlOrder = 'galleryid DESC';
  98.                 break;
  99.             case 'asc':
  100.             default:
  101.                 $sqlOrder = 'galleryid ASC';
  102.         }
  103.  
  104. // Select multiple galleries from NGG
  105. // Added by JWK 29 Nov 2013
  106.         $galleryraw = (explode(',',$s['gallery']));
  107.  
  108.         $g = array_map(trim,$galleryraw);
  109.            
  110.  
  111.         if ( $g[0]!='') {
  112.             $sqlWhere .= ' AND galleryid = ';
  113.             $x = count($g);
  114.             $i = 1;
  115.             foreach ($g as $gident) {
  116.                 $sqlWhere .= $gident;
  117.                 if ($i < $x) {
  118.                     $sqlWhere .= ' OR galleryid = ';
  119.                 }
  120.                 $i++;
  121.             }
  122.  
  123. // End addition by JWK
  124.  
  125.         // Set limit defaults only if tags are not being used
  126.         $numLimit = -1;
  127.         if ( is_numeric( $s['limit'] ) ) {
  128.             $numLimit = (int) $s['limit'];
  129.             if ( $s['tags'] == '' ) {
  130.                 $sqlLimit = ' LIMIT 0, ' . $s['limit'];
  131.             }
  132.         }
  133.  
  134.         $results = $wpdb
  135.                 ->get_results(
  136.                         "SELECT * FROM $wpdb->nggpictures" . $sqlWhere . " ORDER BY " . $sqlOrder . $sqlLimit );
  137.         $pSize = 0;
  138.         if ( is_array( $results ) ) {
  139.             // Filter by tag if entered
  140.             if ( $s['tags'] != '' ) {
  141.                 $taggedImages = nggTags::find_images_for_tags( $s['tags'] );
  142.  
  143.                 if ( $taggedImages ) {
  144.                     $taggedImageIDs = array();
  145.                     foreach ( $taggedImages as $image ) {
  146.                         $taggedImageIDs[ ] = $image->pid;
  147.                     }
  148.  
  149.                     if ( sizeof( $taggedImageIDs ) > 0 ) {
  150.  
  151.                         $filteredResults = array();
  152.                         $taggedCount = 0;
  153.                         foreach ( $results as $result ) {
  154.                             if ( $numLimit != -1 && $taggedCount >= $numLimit ) {
  155.                                 break;
  156.                             } else {
  157.                                 if ( in_array( $result->pid, $taggedImageIDs ) ) {
  158.                                     $filteredResults[ ] = $result;
  159.                                     $taggedCount += 1;
  160.                                 }
  161.                             }
  162.                         }
  163.  
  164.                         $results = $filteredResults;
  165.                     }
  166.  
  167.                 } else {
  168.                     $results = array();
  169.                 }
  170.             }
  171.  
  172.             $pSize = count( $results );
  173.         }
  174.  
  175.         $output = '';
  176.         if ( $pSize > 0 ) {
  177.             $hasControlNav = ( $ns['controlNav'] == '' || $ns['controlNav'] == 'true' );
  178.             $hasThumbs = ( $ns['controlNavThumbs'] );
  179.             $hasCenter = ( $s['center'] == '1' && $width != '' );
  180.  
  181.             if ( $width != '' || $height != '' ) {
  182.                 $width_css = '';
  183.                 $height_css = '';
  184.  
  185.                 if ( $width != '' ) {
  186.                     $width_css = "width: " . $width . "px !important;";
  187.                 }
  188.  
  189.                 if ( $height != '' ) {
  190.                     $height_css = "height: " . $height . "px !important;";
  191.                 }
  192.                 $output .= "\n<style type=\"text/css\">";
  193.  
  194.                 if ( $width_css != '' || $height_css != '' ) {
  195.                     $output .= "\n  ." . $htmlID . "-wrapper { " . $width_css . $height_css . " }";
  196.                 }
  197.                 $output .= "\n</style>";
  198.             }
  199.  
  200.             $containerClass = '';
  201.             if ( $hasCenter ) {
  202.                 $containerClass = ' nivoSlider-center';
  203.             }
  204.             if ( $hasControlNav ) {
  205.                 if ( $hasThumbs ) {
  206.                     $containerClass .= ' nivoSlider-controlNavImages';
  207.                 } else {
  208.                     $containerClass .= ' nivoSlider-controlNavText';
  209.                 }
  210.             }
  211.  
  212.             // Add theme class and title/desc if applicable
  213.             $output .= "\n<div class=\"" . $htmlID . "-wrapper " . $containerClass . " theme-" . $s['theme'] . "\">";
  214.  
  215.             // Add Custom Title
  216.             if ( $s['title'] != '' ) {
  217.                 $output .= "\n<h3>" . $s['title'] . "</h3>";
  218.             }
  219.  
  220.             // Add Gallery title/Description
  221.             $addInfo = false;
  222.             if ( $s['showGalleryDesc'] || $s['showGalleryTitle'] ) {
  223.                 $addInfo = true;
  224.                 $output .= '#REPLACETHIS#';
  225.             }
  226.  
  227.             // Add slider div
  228.             $output .= "\n  <div id=\"" . $htmlID . "\" class=\"nivoSlider\">";
  229.             $imageAltText = null;
  230.             $imageDescription = null;
  231.  
  232.             foreach ( $results as $result ) {
  233.                 $gallery = $wpdb
  234.                         ->get_row( "SELECT * FROM $wpdb->nggallery WHERE gid = '" . $result->galleryid . "'" );
  235.                 foreach ( $gallery as $key => $value ) {
  236.                     $result->$key = $value;
  237.                 }
  238.  
  239.                 $image = new nggImage( $result );
  240.                 $imageAltText = trim( $image->alttext );
  241.                 $imageDescription = trim( $image->description );
  242.  
  243.                 $output .= "\n    ";
  244.  
  245.                 // Check if alt is URL
  246.                 $use_url = false;
  247.  
  248.                 if ( $imageAltText != ''
  249.                         && preg_match( '%\A/|\Ahttp://|\Aftp://|\Amailto:%', $imageAltText ) ) {
  250.                     $use_url = true;
  251.                     $output .= "<a href=\"" . esc_attr( $imageAltText ) . "\" target=\"_blank\">";
  252.                 } elseif ( $imageDescription != ''
  253.                         && preg_match( '%\A/|\Ahttp://|\Aftp://|\Amailto:%', $imageDescription ) ) {
  254.                     $use_url = true;
  255.                     $output .= "<a href=\"" . esc_attr( $imageDescription ) . "\" target=\"_blank\">";
  256.                 }
  257.  
  258.                 //
  259.                 if ( $addInfo ) {
  260.                     $replaceString = '<div class="nivoSlider-galleryInfo">';
  261.                     if ( $s['showGalleryTitle'] ) {
  262.                         $replaceString .= '<h3>' . trim( $gallery->title ) . '</h3>';
  263.                     }
  264.                     if ( $s['showGalleryDesc'] ) {
  265.                         $replaceString .= '<p>' . trim( $gallery->galdesc ) . '</p>';
  266.                     }
  267.                     $replaceString .= '</div>';
  268.                     $output = str_replace( '#REPLACETHIS#', $replaceString, $output );
  269.                 }
  270.  
  271.  
  272.                 // Add a caption containing the image alttext and/or description
  273.                 $imageTitle = '';
  274.  
  275.                 if ( $s['caption'] != '' ) {
  276.                     if ( $s['caption'] == 'both' ) {
  277.                         if ( $imageAltText <> '' || $imageDescription <> '' ) {
  278.                             $imageTitle = ' title="';
  279.                             if ( $imageAltText <> '' ) {
  280.                                 $imageTitle .= $imageAltText;
  281.                                 if ( $imageDescription <> '') {
  282.                                     $imageTitle .= ' - ';
  283.                                 }
  284.                             }
  285.                             $imageTitle .= $imageDescription . '"';
  286.                         }
  287.                     } elseif ( $s['caption'] == 'alttext' ) {
  288.                         $imageTitle = ' title="' . $imageAltText . '"';
  289.                     } elseif ( $s['caption'] == 'description' ) {
  290.                         $imageTitle = ' title="' . $imageDescription . '"';
  291.                     } elseif ( $s['caption'] == 'html' ) {
  292.                         $imageTitle = ' title="#htmlcaption"';
  293.                     }
  294.                 }
  295.  
  296.                 $output .= '<img src="';
  297.  
  298.                 // Resizing functions here
  299.                 // TimThumb takes option 0-3
  300.                 if ( $s['resize'] != '0' && (($s['resize'] >= 1) && ($s['resize'] <= 4)) ) {
  301.                     //print_r($image);
  302.                     $output .= plugins_url( 'includes/timthumb.php', dirname( __FILE__ ) ) . '?zc=' . ($s['resize'] - 1)
  303.                             . '&cc=' . $s['resizeBGColor'] . '&src=' . $image->imageURL;
  304.                     if ( $s['resizeHeight'] != '' || $s['resizeWidth'] != '' ) {
  305.                         if ( $s['resizeHeight'] ) {
  306.                             $output .= '&h=' . $s['resizeHeight'];
  307.                         }
  308.                         if ( $s['resizeWidth'] ) {
  309.                             $output .= '&w=' . $s['resizeWidth'];
  310.                         }
  311.  
  312.                     } else {
  313.                         if ( $height ) {
  314.                             $output .= '&h=' . $height;
  315.                         }
  316.                         if ( $width ) {
  317.                             $output .= '&w=' . $width;
  318.                         }
  319.                     }
  320.  
  321.                 } else {
  322.                     $output .= $image->imageURL;
  323.                 }
  324.  
  325.                 $output .= '"' . $imageTitle;
  326.  
  327.                 // Add data-thumb attribute for thumbnail navigation as per NivoSlider v3.0+
  328.                 if ( $hasThumbs ) {
  329.                     $output .= ' data-thumb="' . $image->thumbURL . '"/>';
  330.                 } else {
  331.                     $output .= "/>";
  332.                 }
  333.  
  334.                 if ( $use_url != '' ) {
  335.                     $output .= "</a>";
  336.                 }
  337.             }
  338.             $output .= "\n  </div>";
  339.             $output .= "\n</div>";
  340.             if ( $s['htmlCaption'] ) {
  341.                 $output .= "\n<div id=\"htmlcaption\" class=\"nivo-html-caption\">" . html_entity_decode($s['htmlCaption']) . "</div>";
  342.             }
  343.         }
  344.  
  345.         // Nivo arguments
  346.         $javascriptArgs = array();
  347.  
  348.         // Modifications if only 1 picture
  349.         if ( $pSize <= 1 ) {
  350.             $ns['startSlide'] = '0';
  351.             $ns['directionNav'] = 'false';
  352.             $ns['controlNav'] = 'false';
  353.             $ns['keyboardNav'] = 'false';
  354.             $ns['pauseOnHover'] = 'false';
  355.             $ns['manualAdvance'] = 'false';
  356.             $ns['beforeChange'] = '';
  357.             $ns['afterChange'] = '';
  358.             $ns['slideshowEnd'] = '';
  359.             $ns['lastSlide'] = '';
  360.             $ns['afterLoad'] = '';
  361.         }
  362.  
  363.         // Load NivoSettings as Javascript arguments
  364.         foreach ( $ns as $key => $value ) {
  365.             if ($value != '') {
  366.                 if ( in_array($key,Array('beforeChange', 'afterChange', 'slideshowEnd', 'lastSlide', 'afterLoad')) || is_numeric($value) || is_bool($value) || $value == 'false' || $value == 'true' ) {
  367.                     $javascriptArgs[ ] = $key . ": " . $value;
  368.                 } else {
  369.                     $javascriptArgs[ ] = $key . ": '" . $value . "'";
  370.                 }
  371.             }
  372.         }
  373.  
  374.         // Add javascript
  375.         $output .= "\n<script type=\"text/javascript\">";
  376.         $output .= "\n  jQuery(document).ready(function() {";
  377.  
  378.         // Shuffle results locally so even if page is cached the order will be different each time
  379.         if ( $s['order'] == 'random' && $s['shuffle'] == 'true' ) {
  380.             $output .= "\n    jQuery('div#" . $htmlID . "').jj_ngg_shuffle();";
  381.         }
  382. /*
  383.         // TODO Touch support
  384.         $output .= "
  385.         if(jQuery.support.touch){
  386.             jQuery('a.nivo-nextNav').css('visibility', 'hidden !important');
  387.             jQuery('a.nivo-prevNav').css('visibility', 'hidden !important');
  388.  
  389.             jQuery('div#" . $htmlID . "').bind( 'swipeleft', function( e ) {
  390.                 jQuery('a.nivo-nextNav').trigger('click');
  391.                 e.stopImmediatePropagation();
  392.                 return false; } );
  393.  
  394.             jQuery('div#" . $htmlID . "').bind( 'swiperight', function( e ) {
  395.                 jQuery('a.nivo-prevNav').trigger('click');
  396.                 e.stopImmediatePropagation();
  397.                 return false; } );
  398.         }\n";
  399. */
  400.         // Nivo Javascript arguments
  401.         $output .= "\n    jQuery('div#" . $htmlID . "').nivoSlider(";
  402.  
  403.         if ( count( $javascriptArgs ) > 0 ) {
  404.             $output .= "{\n      " . implode( ",\n      ", $javascriptArgs ) . "\n    }";
  405.         }
  406.         $output .= ");";
  407.  
  408.         if ( $hasControlNav && $hasThumbs ) {
  409.             // Make thumbnails visisble
  410.             $output .= "\n    jQuery('div.nivo-controlNav').css('visibility', 'visible');";
  411.         }
  412.  
  413.         $output .= "\n  });";
  414.         $output .= "\n</script>\n";
  415.  
  416.         echo $output;
  417.     }
  418.  
  419.     private function get_val( $instance, $key, $default = '', $escape = true ) {
  420.         $val = '';
  421.  
  422.         if ( isset( $instance[ $key ] ) ) {
  423.             $val = trim( $instance[ $key ] );
  424.         }
  425.  
  426.  
  427.         if ( $val == '' ) {
  428.             $val = $default;
  429.         }
  430.  
  431.         if ( $escape ) {
  432.             $val = esc_attr( $val );
  433.         }
  434.  
  435.         return $val;
  436.     }
  437.  
  438.     private function get_val_numeric( $instance, $key, $default = '', $escape = true ) {
  439.         $val = $this->get_val( $instance, $key, $default, false );
  440.  
  441.         if ( !is_numeric( $val ) ) {
  442.             return '';
  443.         }
  444.  
  445.         return $val;
  446.     }
  447.  
  448.     public function update( $new_instance, $old_instance ) {
  449.         $new_instance[ 'title' ] = esc_attr( $new_instance[ 'title' ] );
  450.         return $new_instance;
  451.     }
  452.  
  453.     private function create_radio($id, $setting, $title, $description = false, $options = array("default", "true", "false")) {
  454.         $output = '';
  455.         $output .= "<p>\n";
  456.         $output .= "<label><strong>" . $title . ":</strong></label><br />\n";
  457.         if ($description) { $output .= "<small>" . $description . "</small><br />\n"; }
  458.  
  459.         foreach ($options as $type) {
  460.             $output .= '<input type="radio" ';
  461.             $output .= 'id="' . $this->get_field_id( $id ) . '-' . $type . '" ';
  462.             $output .= 'name="' . $this->get_field_name( $id ) . '" ';
  463.             $output .= 'value="' . $type . '"';
  464.             $output .= 'style="vertical-align: middle;"';
  465.             if ( ($type == 'default' && $setting == '') || $setting == $type ) {
  466.                 $output .= ' checked="checked"';
  467.             }
  468.             $output .= "/>\n";
  469.             // Label
  470.             $output .= '<label for="' . $this->get_field_id( $id ) . '-' . $type . '" style="vertical-align: middle;"> ' . ucfirst($type) . "</label>\n";
  471.  
  472.         }
  473.         $output .= "</p>\n";
  474.         echo $output;
  475.     }
  476.  
  477.     private function create_field($id, $setting, $title, $description = false, $class = 'widefat') {
  478.         $output = '';
  479.         $output .= "<p>\n";
  480.         $output .= '<label for="'. $this->get_field_id( $id ) . '"><strong>' . $title . ":</strong></label><br />\n";
  481.         if ($description) { $output .= "<small>" . $description . "</small><br />\n"; }
  482.         $output .= '<input type="text" ';
  483.         $output .= 'id="' . $this->get_field_id( $id ) . '" ';
  484.         $output .= 'name="' . $this->get_field_name( $id ) . '" ';
  485.         $output .= 'value="' . $setting . '" ';
  486.         $output .= 'class="' . $class . '"';
  487.         $output .= "/>\n</p>\n";
  488.         echo $output;
  489.     }
  490.  
  491.     private function create_select($id, $setting, $title, $description = false, $options) {
  492.         $output = '';
  493.         $output .= "<p>\n";
  494.         $output .= '<label for="' . $this->get_field_id( $id ) . '"><strong>' . $title . ":</strong></label><br />\n";
  495.         if ($description) { $output .= "<small>" . $description . "</small><br />\n"; }
  496.         $output .= '<select id="' . $this->get_field_id( $id ) . '" ';
  497.         $output .= 'name="' . $this->get_field_name( $id ) . '" ';
  498.         $output .= "class=\"widefat\">\n";
  499.         foreach ($options as $key => $value) {
  500.             $output .= '<option value="' . $key . '"';
  501.             if ($setting == $key) { $output .= ' selected="selected"'; }
  502.             $output .= '>' . $value . "</option>\n";
  503.         }
  504.         $output .= "</select>\n</p>\n";
  505.         echo $output;
  506.     }
  507.  
  508.     private function create_checkbox($id, $setting, $title) {
  509.         $output = '';
  510.         $output .= "<p>\n";
  511.         $output .= '<input type="checkbox" ';
  512.         $output .= 'id="' . $this->get_field_id( $id ) . '" ';
  513.         $output .= 'style="vertical-align: middle;" ';
  514.         $output .= 'name="' . $this->get_field_name( $id ) . '" ';
  515.         $output .= 'value="' . $id . '"';
  516.         if ($setting) { $output .= ' checked="checked"'; }
  517.         $output .= "/>\n";
  518.  
  519.         $output .= '<label for="'. $this->get_field_id( $id ) . '" ';
  520.         $output .= 'style="vertical-align: middle;">';
  521.         $output .= '<strong>' . $title . "</strong></label><br />\n";
  522.         $output .= "</p>\n";
  523.         echo $output;
  524.     }
  525.  
  526.     public function form( $instance ) {
  527.         global $wpdb;
  528.         $instance = wp_parse_args(
  529.                 (array) $instance,
  530.                 array(
  531.                         'title' => '',
  532.                         'html_id' => 'slider',
  533.                         'width' => '',
  534.                         'height' => '',
  535.                         'resizewidth' => '',
  536.                         'resizeheight' => '',
  537.                         'resizebg' => '',
  538.                         'resize' => '',
  539.                         'order' => 'random',
  540.                         'tags' => '',
  541.                         'shuffle' => 'false',
  542.                         'max_pictures' => '',
  543.                         'center' => '',
  544.                         'gallery' => '',
  545.                         'caption' => '',
  546.                         'htmlcaption' => '',
  547.                         'theme' => '',
  548.                         'showgallerytitle' => '',
  549.                         'showgallerydesc' => '',
  550.                         // nivo settings
  551.                         'effect' => '',
  552.                         'slices' => '',
  553.                         'boxcols' => '',
  554.                         'boxrows' => '',
  555.                         'animspeed' => '',
  556.                         'pausetime' => '',
  557.                         'startslide' => '',
  558.                         'directionnav' => '',
  559.                         'controlnav' => '',
  560.                         'controlnavthumbs' => '',
  561.                         'thumbswidth' => '',
  562.                         'thumbsheight' => '',
  563.                         'thumbscontainerheight' => '',
  564.                         'thumbsgap' => '',
  565.                         'controlnavthumbsfromrel' => '',
  566.                         'controlnavthumbssearch' => '',
  567.                         'controlnavthumbsreplace' => '',
  568.                         'keyboardnav' => '',
  569.                         'pauseonhover' => '',
  570.                         'manualadvance' => '',
  571.                         'captionopacity' => '',
  572.                         'beforechange' => '',
  573.                         'afterchange' => '',
  574.                         'slideshowend' => '',
  575.                         'lastslide' => '',
  576.                         'afterload' => '' ) );
  577.  
  578.         $order_values = array(
  579.                 'random' => 'Random',
  580.                 'asc' => 'Latest First',
  581.                 'desc' => 'Oldest First',
  582.                 'sortorder' => 'NextGen Sortorder' );
  583.         $galleries = $wpdb->get_results( "SELECT * FROM $wpdb->nggallery ORDER BY name ASC" );
  584.  
  585.         // Start HTML Page
  586.         $this->create_field('title', $instance['title'], 'Widget title'); ?>
  587.         <p>
  588.             <label><strong>Select a gallery to use:</strong></label><br />
  589.  
  590.             <?php
  591. //  Moved from pulldown to comma delimited list JWK 29 Nov 2013
  592.  
  593.         /*  if ( is_array( $galleries ) && count( $galleries ) > 0 ) {
  594.  
  595.                 echo '<select id="';
  596.                 echo $this->get_field_id( 'gallery' ) . '" name="';
  597.                 echo $this ->get_field_name( 'gallery' );
  598.                 echo '" class="widefat">';
  599.                 echo '<option value="">All images</option>';
  600.  
  601.                 $gallery_selected = '';
  602.  
  603.                 foreach ( $galleries as $gallery ) {
  604.                     if ( $gallery->gid == $instance[ 'gallery' ] ) {
  605.                         $gallery_selected = " selected=\"selected\"";
  606.                     } else {
  607.                         $gallery_selected = "";
  608.                     }
  609.                     echo "<option value=\"" . $gallery->gid . "\"" . $gallery_selected . ">" . $gallery->name . "</option>";
  610.                 }
  611.  
  612.                 echo '</select>';
  613.             } else {
  614.                 echo 'No galleries found';
  615.             }
  616.         */?>
  617.         </p>
  618.         <p>
  619.             <label for="<?php echo $this->get_field_id( 'order' ); ?>"><strong>Order:</strong></label><br />
  620.             <select id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' );?>" class="widefat">
  621.             <?php
  622.                 $order_selected = '';
  623.                 foreach ( $order_values as $key => $value ) {
  624.                     if ( $key == $instance[ 'order' ] ) {
  625.                         $order_selected = " selected=\"selected\"";
  626.                     } else {
  627.                         $order_selected = "";
  628.                     }
  629.                     echo "<option value=\"" . $key . "\"" . $order_selected . ">" . $value . "</option>";
  630.                 }
  631.             ?>
  632.             </select>
  633.         </p>
  634.         <?php
  635. //Moved from pulldown to comma delimited by JWK 29 Nov 2013
  636.         $this->create_field('gallery', $instance['gallery'], 'Display Gallery', '(Gallery ID as a comma seperated list)');
  637.         $this->create_field('tags', $instance['tags'], 'Only display images tagged as', '(Comma seperated list)');
  638.         $this->create_radio('shuffle', $instance['shuffle'], 'Shuffle', '(Only for random order)', array("true", "false"));
  639.         $this->create_field('max_pictures', $instance['max_pictures'], 'Max pictures', '(Leave blank for all)');
  640.         $this->create_field('html_id', $instance['html_id'], 'HTML id');
  641.         $this->create_field('width', $instance['width'], 'Width', '(Leave blank for auto)');
  642.         $this->create_field('height', $instance['height'], 'Height', '(Leave blank for auto)');
  643.         $this->create_select('caption', $instance['caption'], 'Caption', false,
  644.                 array( '0' => 'Disabled',
  645.                         'alttext' => 'Alt text',
  646.                         'description' => 'Description',
  647.                         'both' => 'Both (Alt text - Description)',
  648.                         'html' => 'Use a HTML caption'));
  649.         $this->create_field('htmlcaption', $instance['htmlcaption'], 'HTML Caption', '(HTML formatted caption that will display on every image)');
  650.         $this->create_select('resize', $instance['resize'], 'Resize', '(Resize images using TimThumb v2)',
  651.                 array( '0' => 'Disabled',
  652.                         '1' => 'Resize to fit (no cropping)',
  653.                         '2' => 'Crop and resize to best fit the dimensions',
  654.                         '3' => 'Resize proportionally and add borders',
  655.                         '4' => 'Resize proportionally with no gaps'));
  656.         $this->create_field('resizebg', $instance['resizebg'], 'Resize BG Color', '(Color in HEX format - eg. #rrggbb. Leave blank for white)');
  657.         $this->create_field('resizewidth', $instance['resizewidth'], 'Resize width', '(Leave blank for auto)');
  658.         $this->create_field('resizeheight', $instance['resizeheight'], 'Resize height', '(Leave blank for auto)');
  659.         $this->create_checkbox('center', $instance['center'], 'Center content');
  660.         ?>
  661.  
  662.         <div class="javascript_settings" style="display: none; border: 1px solid #cccccc; background-color: #f0f0f0;">
  663.             <div style="padding: 10px;">
  664.                 <p><a href="http://nivo.dev7studios.com/#usage" target="jj_nextgen_jquery">Visit Nivo configuration page</a></p>
  665.                 <p>Leave blank to use defaults.</p>
  666.                 <?php
  667.                 $this->create_field('effect', $instance['effect'], 'Effects', '(comma seperated sets or leave blank for random)');
  668.                 $this->create_field('slices', $instance['slices'], 'Slices');
  669.                 $this->create_field('boxcols', $instance['boxcols'], 'Box Columns');
  670.                 $this->create_field('boxrows', $instance['boxrows'], 'Box Rows');
  671.                 $this->create_field('animspeed', $instance['animspeed'], 'Animation speed');
  672.                 $this->create_field('pausetime', $instance['pausetime'], 'Pause time');
  673.                 $this->create_field('startslide', $instance['startslide'], 'Start slide');
  674.                 $this->create_radio('directionnav', $instance['directionnav'], 'Direction Navigation');
  675.                 $this->create_radio('controlnav', $instance['controlnav'], 'Control Navigation');
  676.                 $this->create_radio('controlnavthumbs', $instance['controlnavthumbs'], 'Thumbnail Navigation');
  677.                 $this->create_field('thumbswidth', $instance['thumbswidth'], 'Thumbnail width');
  678.                 $this->create_field('thumbsheight', $instance['thumbsheight'], 'Thumbnail height');
  679.                 $this->create_field('thumbscontainerheight', $instance['thumbscontainerheight'], 'Thumbnail container height', '(eg, image rows x thumb height)');
  680.                 $this->create_field('thumbsgap', $instance['thumbsgap'], 'Thumbnail gap');
  681.                 $this->create_radio('keyboardnav', $instance['keyboardnav'], 'Keyboard navigation');
  682.                 $this->create_radio('pauseonhover', $instance['pauseonhover'], 'Pause on hover');
  683.                 $this->create_radio('manualadvance', $instance['manualadvance'], 'Manual advance');
  684.                 $this->create_field('captionopacity', $instance['captionopacity'], 'Caption opacity');
  685.                 $this->create_field('beforechange', $instance['beforechange'], 'Before change');
  686.                 $this->create_field('afterchange', $instance['afterchange'], 'After change');
  687.                 $this->create_field('slideshowend', $instance['slideshowend'], 'Slideshow end');
  688.                 $this->create_field('lastslide', $instance['lastslide'], 'Last slide');
  689.                 $this->create_field('afterload', $instance['afterload'], 'After load');
  690.                 ?>
  691.             </div>
  692.         </div>
  693.         <p><a href="#" onclick="jQuery(this).parent().prev('div.javascript_settings').toggle();return false;">Nivo Slider Settings</a></p>
  694.         <?php
  695.     }
  696. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement