コード例 #1
0
 function detach_gallery_from_all_posts($post_id)
 {
     $gallery = FooGallery::get_by_id($post_id);
     $posts = $gallery->find_usages();
     foreach ($posts as $post) {
         delete_post_meta($post->ID, FOOGALLERY_META_POST_USAGE_CSS);
     }
 }
コード例 #2
0
 function add_images_to_sitemap($images, $post_id)
 {
     //check the content for $post_id contains a foogallery shortcode
     $post = get_post($post_id);
     //get all the foogallery shortcodes in the post
     $gallery_shortcodes = foogallery_extract_gallery_shortcodes($post->post_content);
     foreach ($gallery_shortcodes as $gallery_id => $shortcode) {
         //load each gallery
         $gallery = FooGallery::get_by_id($gallery_id);
         //add each image to the sitemap image array
         foreach ($gallery->attachments() as $attachment) {
             $image = array('src' => $attachment->url, 'title' => $attachment->caption, 'alt' => $attachment->alt);
             $images[] = $image;
         }
     }
     return $images;
 }
コード例 #3
0
 /**
  * load the gallery based on either the id or slug, passed in via arguments
  *
  * @param $args array       Arguments passed in from the shortcode
  *
  * @return bool|FooGallery  The gallery object we want to render
  */
 function find_gallery($args)
 {
     $id = intval($this->get_arg($args, 'id'), 0);
     if ($id > 0) {
         //load gallery by ID
         return FooGallery::get_by_id($id);
     } else {
         //take into account the cases where id is passed in via the 'gallery' attribute
         $gallery = $this->get_arg($args, 'gallery', 0);
         if (intval($gallery) > 0) {
             //we have an id, so load
             return FooGallery::get_by_id(intval($gallery));
         }
         //we are dealing with a slug
         return FooGallery::get_by_slug($gallery);
     }
 }
コード例 #4
0
 function ajax_get_gallery_info()
 {
     $nonce = safe_get_from_request('nonce');
     wp_verify_nonce($nonce, 'foogallery-timymce-nonce');
     $id = safe_get_from_request('foogallery_id');
     $gallery = FooGallery::get_by_id($id);
     $image_src = $gallery->featured_image_src('thumbnail', true);
     $json_array = array('id' => $id, 'name' => $gallery->name, 'count' => $gallery->image_count(), 'src' => $image_src);
     header('Content-type: application/json');
     echo json_encode($json_array);
     die;
 }
コード例 #5
0
 public function ajax_clear_gallery_thumb_cache()
 {
     if (check_admin_referer('foogallery_clear_gallery_thumb_cache', 'foogallery_clear_gallery_thumb_cache_nonce')) {
         $foogallery_id = $_POST['foogallery_id'];
         $foogallery = FooGallery::get_by_id($foogallery_id);
         ob_start();
         //loop through all images, get the full sized file
         foreach ($foogallery->attachments() as $attachment) {
             $meta_data = wp_get_attachment_metadata($attachment->ID);
             $file = $meta_data['file'];
             wpthumb_delete_cache_for_file($file);
         }
         ob_end_clean();
         echo __('The thumbnail cache has been cleared!', 'foogallery');
     }
     die;
 }
コード例 #6
0
        function render_import_form($galleries = false)
        {
            if (false === $galleries) {
                $galleries = $this->get_galleries();
            }
            $has_imports = get_option(self::NEXTGEN_OPTION_IMPORT_PROGRESS);
            $overall_progress = $this->get_overall_progress();
            $all_imports_completed = 100 === $overall_progress;
            $import_has_started = $this->import_in_progress();
            $importing = $import_has_started && defined('DOING_AJAX') && DOING_AJAX;
            $current_nextgen_id = get_option(self::NEXTGEN_OPTION_IMPORT_CURRENT, 0);
            ?>
			<table class="wp-list-table widefat" cellspacing="0">
				<thead>
				<tr>
					<th scope="col" id="cb" class="manage-column column-cb check-column">
						<?php 
            if (!$importing && $all_imports_completed) {
                ?>
						<label class="screen-reader-text"
						       for="cb-select-all-1"><?php 
                _e('Select All', 'foogallery');
                ?>
</label>
						<input id="cb-select-all-1" type="checkbox" <?php 
                echo $importing ? 'disabled="disabled"' : '';
                ?>
 checked="checked">
						<?php 
            }
            ?>
					</th>
					<th scope="col" class="manage-column">
						<span><?php 
            _e('NextGen Gallery', 'foogallery');
            ?>
</span>
					</th>
					<th scope="col" id="title" class="manage-column">
						<span><?php 
            printf(__('%s Name', 'foogallery'), foogallery_plugin_name());
            ?>
</span>
					</th>
					<th scope="col" id="title" class="manage-column">
						<span><?php 
            _e('Import Progress', 'foogallery');
            ?>
</span>
					</th>
				</tr>
				</thead>
				<tbody>
			<?php 
            $counter = 0;
            foreach ($galleries as $gallery) {
                $counter++;
                $progress = $this->get_import_progress($gallery->gid);
                $done = $progress->is_completed();
                $edit_link = '';
                $foogallery = false;
                if ($progress->foogallery_id > 0) {
                    $foogallery = FooGallery::get_by_id($progress->foogallery_id);
                    if ($foogallery) {
                        $edit_link = '<a href="' . admin_url('post.php?post=' . $progress->foogallery_id . '&action=edit') . '">' . $foogallery->name . '</a>';
                    } else {
                        $done = false;
                    }
                }
                ?>
				<tr class="<?php 
                echo $counter % 2 === 0 ? 'alternate' : '';
                ?>
">
					<?php 
                if (!$importing && !$done && $all_imports_completed) {
                    ?>
						<th scope="row" class="column-cb check-column">
							<input name="nextgen-id[]" type="checkbox" checked="checked" value="<?php 
                    echo $gallery->gid;
                    ?>
">
						</th>
					<?php 
                } else {
                    if ($importing && $gallery->gid == $current_nextgen_id) {
                        ?>
						<th>
							<div class="dashicons dashicons-arrow-right"></div>
						</th>
					<?php 
                    } else {
                        ?>
						<th>
						</th>
					<?php 
                    }
                }
                ?>
					<td>
						<?php 
                echo $gallery->title . ' ' . sprintf(__('(%s images)', 'foogallery'), $gallery->image_count);
                ?>
					</td>
					<td>
					<?php 
                if ($foogallery) {
                    echo $edit_link;
                } else {
                    ?>
						<input name="foogallery-name-<?php 
                    echo $gallery->gid;
                    ?>
" value="<?php 
                    echo $gallery->title;
                    ?>
">
					<?php 
                }
                ?>
					</td>
					<td class="nextgen-import-progress nextgen-import-progress-<?php 
                echo $progress->status;
                ?>
">
						<?php 
                echo $progress->message();
                ?>
					</td>
				</tr>
			<?php 
            }
            ?>
				</tbody>
			</table>
			<br/>

			<?php 
            echo '<input type="hidden" id="nextgen_import_progress" value="' . $overall_progress . '" />';
            wp_nonce_field('foogallery_nextgen_import', 'foogallery_nextgen_import');
            wp_nonce_field('foogallery_nextgen_import_refresh', 'foogallery_nextgen_import_refresh', false);
            wp_nonce_field('foogallery_nextgen_import_cancel', 'foogallery_nextgen_import_cancel', false);
            wp_nonce_field('foogallery_nextgen_import_reset', 'foogallery_nextgen_import_reset', false);
            if (!$import_has_started && !$importing) {
                ?>
				<input type="submit" class="button button-primary start_import"
				       value="<?php 
                _e('Start Import', 'foogallery');
                ?>
">
			<?php 
            } else {
                if ($import_has_started && !$importing) {
                    ?>
				<input type="submit" class="button button-primary continue_import" value="<?php 
                    _e('Resume Import', 'foogallery');
                    ?>
">
			<?php 
                } else {
                    ?>
				<input type="submit" class="button cancel_import" value="<?php 
                    _e('Stop Import', 'foogallery');
                    ?>
">
			<?php 
                }
            }
            if ($has_imports && !$importing) {
                ?>
				<input type="submit" name="foogallery_nextgen_reset" class="button reset_import" value="<?php 
                _e('Reset All Gallery Imports', 'foogallery');
                ?>
">
			<?php 
            }
            ?>
			<div id="import_spinner" style="width:20px">
				<span class="spinner"></span>
			</div>
			<?php 
            if ($importing) {
                ?>
				<div class="nextgen-import-progressbar">
					<span style="width:<?php 
                echo $overall_progress;
                ?>
%"></span>
				</div>
				<?php 
                echo intval($overall_progress);
                ?>
%
				<div style="width:20px; display: inline-block;">
					<span class="spinner shown"></span>
				</div>
			<?php 
            }
        }
コード例 #7
0
 public function ajax_create_gallery_page()
 {
     if (check_admin_referer('foogallery_create_gallery_page', 'foogallery_create_gallery_page_nonce')) {
         $foogallery_id = $_POST['foogallery_id'];
         $foogallery = FooGallery::get_by_id($foogallery_id);
         $post = array('post_content' => $foogallery->shortcode(), 'post_title' => $foogallery->name, 'post_status' => 'draft', 'post_type' => 'page');
         wp_insert_post($post);
     }
     die;
 }