예제 #1
0
 /**
  * Rebuild the image
  *
  * @access public
  * @return void
  * @author Nicolas Juen
  */
 public static function a_thumbnail_rebuild()
 {
     // Get the nonce
     $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : '';
     // Get the thumbnails
     $thumbnails = isset($_POST['thumbnails']) ? $_POST['thumbnails'] : null;
     // Check the nonce
     if (!wp_verify_nonce($nonce, 'regen')) {
         SIS_Admin_Main::display_json(array('error' => __('Trying to cheat ?', 'simple-image-sizes')));
     }
     // Get the id
     $id = isset($_POST['id']) ? $_POST['id'] : 0;
     SIS_Admin_Main::display_json(SIS_Admin_Main::thumbnail_rebuild($id, $thumbnails));
 }
예제 #2
0
파일: media.php 프로젝트: asha23/folio
 /**
  * Regenerate the thumbnails ajax action
  *
  * @return array
  *
  * @param void
  *
  * @author Nicolas Juen
  */
 public static function a_thumbnails_rebuild()
 {
     /**
      * @var $wpdb wpdb
      */
     global $wpdb;
     // Get the nonce
     $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : '';
     $offset = isset($_POST['offset']) ? absint($_POST['offset']) : 0;
     $post_types = isset($_POST['post_types']) ? $_POST['post_types'] : 'any';
     $thumbnails = isset($_POST['thumbnails']) ? $_POST['thumbnails'] : null;
     // Check the nonce
     if (!wp_verify_nonce($nonce, 'regen')) {
         SIS_Admin_Main::display_json(array('error' => __('Trying to cheat ?', 'simple-image-sizes')));
     }
     if ('any' !== $post_types) {
         foreach ($_POST['post_types'] as $key => $type) {
             if (!post_type_exists($type)) {
                 unset($_POST['post_types'][$key]);
             }
         }
         if (empty($_POST['post_types'])) {
             SIS_Admin_Main::display_json();
         }
         // Get image medias
         $whichmimetype = wp_post_mime_type_where('image', $wpdb->posts);
         // Get all parent from post type
         $attachment = $wpdb->get_var($wpdb->prepare("SELECT ID\n\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\tWHERE 1 = 1\n\t\t\t\tAND post_type = 'attachment'\n\t\t\t\t{$whichmimetype}\n\t\t\t\tAND post_parent IN (\n\t\t\t\t\tSELECT DISTINCT ID \n\t\t\t\t\tFROM {$wpdb->posts} \n\t\t\t\t\tWHERE post_type IN ('" . implode("', '", $_POST['post_types']) . "')\n\t\t\t\t)\n\t\t\t\tLIMIT %d,1 \n\t\t\t", $offset));
     } else {
         $attachment = get_posts(array('post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 1, 'post_status' => 'any', 'output' => 'object', 'offset' => $offset));
         $attachment = !empty($attachment) ? $attachment[0]->ID : 0;
     }
     if (empty($attachment)) {
         return array('message' => __('Regeneration ended', 'simple-image-sizes'));
     }
     SIS_Admin_Main::display_json(SIS_Admin_Main::thumbnail_rebuild($attachment, $thumbnails));
 }