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 = '