Ejemplo n.º 1
0
 function widget($args, $instance)
 {
     global $wpdb;
     // outputs the content of the widget
     extract($args);
     $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
     $gallery_options = $instance['gallery_options'];
     $number = isset($instance['number']) ? $instance['number'] : 5;
     $selection = isset($instance['selection']) ? $instance['selection'] : 'latest';
     $fg = new FancyGallery();
     //get options
     $options = $wpdb->get_results("SELECT options FROM {$fg->gallery_table_name} WHERE ID='{$gallery_options}'");
     $options = $fg->check_options_availability(unserialize($options[0]->options));
     //include necessary scripts
     FancyGallery::$add_script = true;
     switch ($options['gallery']) {
         case 'prettyphoto':
             FancyGallery::$add_pp_script = true;
             break;
         case 'fancybox':
             FancyGallery::$add_fb_script = true;
             break;
         case 'inline':
             FancyGallery::$add_inline_script = true;
             break;
     }
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     if ($selection == 'latest') {
         $album_files = $wpdb->get_results("SELECT * FROM {$fg->images_table_name} ORDER BY ID DESC LIMIT {$number}");
     } else {
         if ($selection == 'random') {
             $album_files = $wpdb->get_results("SELECT * FROM {$fg->images_table_name} ORDER BY ID");
             shuffle($album_files);
         }
     }
     //html output
     $output = '';
     $output .= '<div id="fancygallery-media-widget-' . $selection . '" class="fg-panel">';
     $output .= '<div title="Media Widget">';
     for ($i = 0; $i < $number; ++$i) {
         $album_file = $album_files[$i];
         if ($album_file) {
             $output .= $fg->get_media_link($album_file->file, $album_file->thumbnail, $options['thumbnail_width'], $options['thumbnail_height'], $options['thumbnail_zc'], $album_file->title, $album_file->description);
         }
     }
     $output .= "</div></div>";
     $options = $fg->check_options_availability($options);
     $output .= $fg->get_js_code($options, 'fancygallery-media-widget-' . $selection . '', '');
     echo $output;
     echo $after_widget;
 }
        public function add_fancyGallery_dir($atts)
        {
            self::$add_script = true;
            extract(shortcode_atts(array('gallery_dir' => '', 'album_dir' => '', 'columns' => 0, 'gallery_options' => ''), $atts));
            //get albums
            $albums = array();
            //get albums from gallery
            if (empty($album_dir)) {
                //check if gallery directory exists
                if (!is_dir(FG_DIR . '/' . $gallery_dir)) {
                    return '<p class="fg-error">' . sprintf(__('The gallery directory "%s" does not exist!', 'radykal'), $gallery_dir) . '</p>';
                } else {
                    //read gallery dir
                    $gallery_directory_entries = scandir(FG_DIR . '/' . $gallery_dir);
                    //get all albums dir from gallery dir
                    $album_directories = glob(FG_DIR . '/' . $gallery_dir . '/*', GLOB_ONLYDIR);
                    //loop through all albums dirs
                    foreach ($album_directories as $album_directory) {
                        if (is_dir($album_directory)) {
                            $images = $this->_scan_album_dir($album_directory);
                            $albums[basename($album_directory)] = $images;
                        }
                    }
                }
            } else {
                //check if album directory exists
                if (!is_dir(FG_DIR . '/' . $gallery_dir . '/' . $album_dir)) {
                    return '<p class="fg-error">' . sprintf(__('The gallery "%s" or album directory "%s" does not exist!', 'radykal'), $gallery_dir, $album_dir) . '</p>';
                } else {
                    $images = $this->_scan_album_dir(FG_DIR . '/' . $gallery_dir . '/' . $album_dir);
                    $albums[$album_dir] = $images;
                }
            }
            //get options for gallery
            if (get_option('fg_general_options_name')) {
                $options_id = get_option('fg_general_options_name');
                $options = $this->wpdb->get_results("SELECT options FROM {$this->gallery_table_name} WHERE ID='{$options_id}'");
            } else {
                $options = $this->wpdb->get_results("SELECT options FROM {$this->gallery_table_name} WHERE title='{$gallery_options}'");
            }
            $options = unserialize($options[0]->options);
            //check if options is an array, fallback
            if (!is_array($options)) {
                $options = $this->default_options;
            }
            //check if columns value is set via an attribute
            if ($columns > 0) {
                $options['columns'] = $columns;
            }
            //add necessary scripts
            switch ($options['gallery']) {
                case 'prettyphoto':
                    self::$add_pp_script = true;
                    break;
                case 'fancybox':
                    self::$add_fb_script = true;
                    break;
                case 'inline':
                    self::$add_inline_script = true;
                    break;
            }
            //custom thumbnail size for thumbnails selection
            if ($options['album_selection'] == 'thumbnails') {
                if ($options['thumbnail_selection_layout'] == 'default') {
                    $thumbnails_selection_width = $options['thumbnail_selection_width'];
                    $thumbnails_selection_height = $options['thumbnail_selection_height'];
                } else {
                    if ($options['thumbnail_selection_layout'] == 'polaroid') {
                        $thumbnails_selection_width = 151;
                        $thumbnails_selection_height = 151;
                    }
                }
            }
            $selector = $gallery_dir;
            if (!empty($album_dir)) {
                $selector .= '-' . basename($album_dir);
            }
            $selector = sanitize_title($selector);
            //html output
            ob_start();
            ?>
<div id="<?php 
            echo $selector;
            ?>
" class="fg-panel" >
				<?php 
            foreach ($albums as $key => $value) {
                $album_thumbnail = '';
                if ($options['album_selection'] == 'thumbnails') {
                    $album_thumbnail = plugins_url('/admin/timthumb.php', __FILE__) . '?src=' . urlencode($albums[$key][0]) . '&w=' . $thumbnails_selection_width . '&h=' . $thumbnails_selection_height . '&zc=1&q=100';
                }
                ?>
				<div title="<?php 
                echo $key;
                ?>
" data-thumbnail="<?php 
                echo $album_thumbnail;
                ?>
"><?php 
                foreach ($albums[$key] as $album_file) {
                    echo $this->get_media_link($album_file, $album_file, $options['thumbnail_width'], $options['thumbnail_height'], $options['thumbnail_zc'], preg_replace("/\\.[^.\\s]{3,4}\$/", "", basename($album_file)), '');
                }
                ?>
</div><?php 
            }
            ?>
</div>
			<?php 
            //js output
            $options = $this->check_options_availability($options);
            echo $this->get_js_code($options, $selector, '');
            $output_gallery = ob_get_contents();
            ob_end_clean();
            return $output_gallery;
        }