fg_settings_default() ); } if ( ! isset( $fg_options['engine'] ) ) { $fg_options['engine'] = 'lightbox2'; update_option( 'FolderGallery', $fg_options ); } if ( 'lightview' == $fg_options['engine'] ) { if ( ! is_dir( plugin_dir_path( __FILE__ ) . 'lightview' ) ) { $fg_options['engine'] = 'lightbox2'; update_option( 'FolderGallery', $fg_options ); } } if ( ! isset( $fg_options['thumbnails'] ) ) { // 1.1 update $fg_options['thumbnails'] = 'all'; update_option( 'FolderGallery', $fg_options ); } if ( ! isset( $fg_options['fb_title'] ) ) { // 1.2 update $fg_options['fb_title'] = 'float'; update_option( 'FolderGallery', $fg_options ); } if ( ! isset( $fg_options['fb_speed'] ) ) { // 1.3 update $fg_options['subtitle'] = 'default'; $fg_options['fb_speed'] = 0; update_option( 'FolderGallery', $fg_options ); } } function fg_styles(){ $fg_options = get_option( 'FolderGallery' ); wp_enqueue_style( 'fg-style', plugins_url( '/css/style.css', __FILE__ ) ); switch ( $fg_options['engine'] ) { case 'lightbox2' : wp_enqueue_style( 'fg-lightbox-style', plugins_url( '/css/lightbox.css', __FILE__ ) ); break; case 'fancybox2' : wp_enqueue_style( 'fancybox-style', plugins_url( '/fancybox/source/jquery.fancybox.css', __FILE__ ) ); break; case 'lightview' : wp_enqueue_style( 'lightview-style', plugins_url( '/lightview/css/lightview/lightview.css', __FILE__ ) ); break; case 'none' : // do nothing for now break; } } function fg_scripts(){ static $firstcall = 1; $fg_options = get_option( 'FolderGallery' ); switch ( $fg_options['engine'] ) { case 'lightbox2' : wp_enqueue_script( 'fg-lightbox-script', plugins_url( '/js/fg-lightbox.js', __FILE__ ), array( 'jquery' ) ); if ( $firstcall ) { wp_localize_script( 'fg-lightbox-script', 'FGtrans', array( 'labelImage' => __( 'Image', 'foldergallery' ), 'labelOf' => __( 'of', 'foldergallery' ), ) ); $firstcall = 0; } break; case 'fancybox2' : wp_enqueue_script( 'fancybox-script', plugins_url( '/fancybox/source/jquery.fancybox.pack.js', __FILE__ ), array( 'jquery' ) ); wp_enqueue_script( 'fg-fancybox-script', plugins_url( '/js/fg-fancybox.js', __FILE__ ), array( 'jquery' ) ); if ( $firstcall ) { wp_localize_script( 'fg-fancybox-script', 'FancyBoxGalleryOptions', array( 'title' => $fg_options['fb_title'], 'speed' => $fg_options['fb_speed'], ) ); $firstcall = 0; } break; case 'lightview' : global $is_IE; if ( $is_IE ) { wp_enqueue_script( 'excanvas', plugins_url( '/lightview/js/excanvas/excanvas.js', __FILE__ ), array( 'jquery' ) ); } wp_enqueue_script( 'lightview_spinners', plugins_url( '/lightview/js/spinners/spinners.min.js', __FILE__ ), array( 'jquery' ) ); wp_enqueue_script( 'lightview-script', plugins_url( '/lightview/js/lightview/lightview.js', __FILE__ ) ); break; case 'none' : // Do nothing for now break; } } /* --------- Folder Gallery Main Functions --------- */ function save_thumbnail( $path, $savepath, $th_width, $th_height ) { // Save thumbnail $image = wp_get_image_editor( $path ); if ( ! is_wp_error( $image ) ) { if ( 0 == $th_height ) { // 0 height => auto $size = $image->get_size(); $width = $size['width']; $height = $size['height']; $th_height = floor( $height * ( $th_width / $width ) ); } $image->resize( $th_width, $th_height, true ); $image->save( $savepath ); } } function file_array( $directory ) { // List all JPG & PNG files in $directory $files = array(); if( $handle = opendir( $directory ) ) { while ( false !== ( $file = readdir( $handle ) ) ) { $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) ); if ( 'jpg' == $ext || 'png' == $ext ) { $files[] = $file; } } closedir( $handle ); } sort( $files ); return $files; } function filename_without_extension ( $filename ) { $info = pathinfo($filename); return basename($filename,'.'.$info['extension']); } function fg_gallery( $atts ) { // Generate gallery $fg_options = get_option( 'FolderGallery' ); extract( shortcode_atts( array( 'folder' => 'wp-content/uploads/', 'title' => 'My Gallery', 'width' => $fg_options['thumbnails_width'], 'height' => $fg_options['thumbnails_height'], 'columns' => $fg_options['columns'], 'margin' => $fg_options['margin'], 'padding' => $fg_options['padding'], 'border' => $fg_options['border'], 'thumbnails' => $fg_options['thumbnails'], 'options' => $fg_options['lw_options'], 'subtitle'=> $fg_options['subtitle'], ), $atts ) ); $folder = rtrim( $folder, '/' ); // Remove trailing / from path if ( !is_dir( $folder ) ) { return '

' . __( 'Folder Gallery Error:', 'foldergallery' ) . ' ' . sprintf( __( 'Unable to find the directory %s.', 'foldergallery' ), $folder ) . '

'; } $pictures = $this->file_array( $folder ); $NoP = count( $pictures ); if ( 0 == $NoP ) { return '

' . __( 'Folder Gallery Error:', 'foldergallery' ) . ' ' . sprintf( __( 'No picture available inside %s.', 'foldergallery' ), $folder ) . '

'; } $cache_folder = $folder . '/cache_' . $width . 'x' . $height; if ( ! is_dir( $cache_folder ) ) { @mkdir( $cache_folder, 0777 ); } if ( ! is_dir( $cache_folder ) ) { return '

' . __( 'Folder Gallery Error:', 'foldergallery' ) . ' ' . sprintf( __( 'Unable to create the thumbnails directory inside %s.', 'foldergallery' ), $folder ) . ' ' . __( 'Verify that this directory is writable (chmod 777).', 'foldergallery' ) . '

'; } $imgstyle = "margin:0px {$margin}px {$margin}px 0px;"; $imgstyle .= "padding:{$padding}px;"; $imgstyle .= "border-width:{$border}px;"; //if ( 'all' != $thumbnails ) $columns = 0; // Moved below $this->fg_scripts(); $lightbox_id = uniqid(); //md5( $folder . ); $gallery_code = '\n"; if ( 'all' == $thumbnails ) $gallery_code .= '
'; return $gallery_code; } /* --------- Folder Gallery Settings --------- */ function fg_menu() { add_options_page( 'Folder Gallery Settings', 'Folder Gallery', 'manage_options', 'folder-gallery', array( $this, 'fg_settings' ) ); } function fg_settings_init() { register_setting( 'FolderGallery', 'FolderGallery', array( $this, 'fg_settings_validate' ) ); } function fg_plugin_action_links( $links ) { // Add a link to this plugin's settings page $settings_link = '' . __('Settings') . ''; array_unshift( $links, $settings_link ); return $links; } function fg_settings_validate( $input ) { $input['columns'] = intval( $input['columns'] ); $input['thumbnails_width'] = intval( $input['thumbnails_width'] ); if ( 0 == $input['thumbnails_width'] ) $input['thumbnails_width'] = 150; $input['thumbnails_height'] = intval( $input['thumbnails_height'] ); $input['border'] = intval( $input['border'] ); $input['padding'] = intval( $input['padding'] ); $input['margin'] = intval( $input['margin'] ); if ( ! in_array( $input['thumbnails'], array( 'all','none','single' ) ) ) $input['thumbnails'] = 'all'; if ( ! in_array( $input['fb_title'], array( 'inside','outside','float','over','null' ) ) ) $input['fb_title'] = 'all'; if ( ! in_array( $input['subtitle'], array( 'default','none','filename','filenamewithoutextension' ) ) ) $input['subtitle'] = 'default'; $input['fb_speed'] = intval( $input['fb_speed'] ); return $input; } function fg_settings_default() { $defaults = array( 'engine' => 'lightbox2', 'border' => 1, 'padding' => 2, 'margin' => 5, 'columns' => 0, 'thumbnails_width' => 160, 'thumbnails_height' => 0, 'lw_options' => '', 'thumbnails' => 'all', 'subtitle' => 'default', 'fb_title' => 'float', 'fb_speed' => 0, ); return $defaults; } function fg_option_field( $field, $label, $extra = 'px' ) { $fg_options = get_option( 'FolderGallery' ); echo '' . "\n"; echo '\n"; echo ' ' . $extra . "\n"; echo "\n"; } function fg_settings() { $fg_options = get_option( 'FolderGallery' ); echo '
' . "\n"; screen_icon(); echo '

' . __( 'Folder Gallery Settings', 'foldergallery' ) . "

\n"; echo '
' . "\n"; settings_fields( 'FolderGallery' ); echo "\n" . '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '\n\n"; echo '' . "\n"; echo '' . "\n"; echo '\n\n"; $this->fg_option_field( 'columns', __( 'Columns', 'foldergallery' ), __( '(0 = auto)', 'foldergallery' ) ); $this->fg_option_field( 'thumbnails_width', __( 'Thumbnails Width', 'foldergallery' ) ); $this->fg_option_field( 'thumbnails_height', __( 'Thumbnails Height', 'foldergallery' ), ' px ' . __( '(0 = auto)', 'foldergallery' ) ); $this->fg_option_field( 'border', __( 'Picture Border', 'foldergallery' ) ); $this->fg_option_field( 'padding', __( 'Padding', 'foldergallery' ) ); $this->fg_option_field( 'margin', __( 'Margin', 'foldergallery' ) ); // Subtitle echo '' . "\n"; echo '' . "\n"; echo '\n\n"; // Lightview if ( 'lightview' == $fg_options['engine'] ) { echo '' . "\n"; echo '' . "\n"; echo '\n"; echo "\n"; } else { echo ''; } // Fancybox 2 options if ( 'fancybox2' == $fg_options['engine'] ) { echo '' . "\n"; echo '' . "\n"; echo '\n\n"; $this->fg_option_field( 'fb_speed', __( 'Autoplay Speed', 'foldergallery' ), ' seconds ' . __( '(0 = off)', 'foldergallery' ) ); } else { echo ''; echo ''; } echo "
\n"; switch ( $fg_options['engine'] ) { case 'lightbox2' : echo '

Lightbox is completely free to use. '; echo 'If you are using Lightbox on a commercial project and feeling generous, consider a donation. '; echo 'All donations are sincerely appreciated. Thanks!

'; break; case 'fancybox2' : echo '

Fancybox 2 is licensed under Creative Commons Attribution-NonCommercial 3.0 license. '; echo 'You are free to use fancyBox for your personal or non-profit website projects.
'; echo 'See http://fancyapps.com/fancybox for details.

'; break; case 'lightview' : echo '

Lightview is licensed under the terms of the Lightview License. '; echo 'You are free to use it on non-commercial websites. Licenses are available for commercial use.

'; break; } echo "
\n"; echo "
\n"; echo "
\n"; echo '

' . __( 'Lightview default options, comma-separated.', 'foldergallery' ); echo " E.g., controls: { slider: false }, skin: 'mac'. "; echo __( 'For details, see:', 'foldergallery' ); echo ' http://projects.nickstakenburg.com/lightview.

' . "\n"; echo "
\n"; echo "
\n"; submit_button(); echo "
\n"; } } //End Of Class ?>