/wpsc-admin/media.php

  1. <?php 
  2.  
  3. add_action( 'admin_enqueue_scripts', '_wpsc_action_enqueue_media_scripts' ); 
  4. add_action( 'admin_enqueue_scripts', '_wpsc_action_enqueue_media_styles' ); 
  5. add_action( 'admin_footer', '_wpsc_action_print_media_templates' ); 
  6.  
  7. function _wpsc_action_enqueue_media_scripts() { 
  8. $current_screen = get_current_screen(); 
  9.  
  10. if ( in_array( $current_screen->id, array( 'wpsc-product-variations-iframe', 'wpsc-product' ) ) ) { 
  11. $post = get_post(); 
  12. if ( ! $post ) 
  13. $id = absint( $_REQUEST['product_id'] ); 
  14. else 
  15. $id = $post->ID; 
  16.  
  17. $gallery = _wpsc_get_product_gallery_json( $id ); 
  18. wp_enqueue_script( 'wpsc-media', WPSC_URL . '/wpsc-admin/js/media.js', array( 'media-editor', 'wp-e-commerce-admin', 'jquery-ui-sortable', 'post' ), WPSC_VERSION ); 
  19. wp_localize_script( 'wpsc-media', 'WPSC_Media', array( 
  20. 'l10n' => array( 
  21. 'productMediaTitle' => __( 'Add Images to Product Gallery', 'wpsc' ),  
  22. 'saveGallery' => __( 'Set Product Images', 'wpsc' ),  
  23. ),  
  24. 'gallery' => $gallery,  
  25. 'updateGalleryNonce' => wp_create_nonce( 'wpsc_ajax_update_gallery_' . $id ),  
  26. 'getGalleryNonce' => wp_create_nonce( 'wpsc_ajax_get_gallery_' . $id ) 
  27. ) ); 
  28.  
  29. function _wpsc_action_enqueue_media_styles() { 
  30. $current_screen = get_current_screen(); 
  31.  
  32. if ( 'wpsc-product' == $current_screen->id ) 
  33. wp_enqueue_style( 'wpsc-media', WPSC_URL . '/wpsc-admin/css/media.css', array( 'media-views' ), WPSC_VERSION ); 
  34.  
  35. function _wpsc_action_print_media_templates() { 
  36. ?> 
  37. <script type="text/html" id="tmpl-wpsc-featured-image"> 
  38. <div class="wpsc-media-featured-image"> 
  39. <span class="title"><?php _e( 'Featured image', 'wpsc' ); ?></span> 
  40. <a class="edit-selection" href="#"><?php _ex( 'Edit', 'edit featured image', 'wpsc' ); ?></a> 
  41. </div> 
  42. <div class="wpsc-selection-view"></div> 
  43. </script> 
  44. <?php 
  45.  
  46. function _wpsc_ajax_verify_get_variation_gallery() { 
  47. return _wpsc_ajax_verify_nonce( 'get_variation_gallery_' . absint( $_REQUEST['id'] ) ); 
  48.  
  49. function _wpsc_ajax_get_variation_gallery() { 
  50. $id = absint( $_REQUEST['id'] ); 
  51.  
  52. $gallery = _wpsc_get_product_gallery_json( $id ); 
  53.  
  54. return array( 
  55. 'models' => $gallery,  
  56. 'featuredId' => wpsc_the_product_thumbnail_id( $id ) 
  57. ); 
  58.  
  59. function _wpsc_ajax_verify_save_product_gallery() { 
  60. return _wpsc_ajax_verify_nonce( 'update_gallery_' . absint( $_REQUEST['postId'] ) ); 
  61.  
  62. function _wpsc_ajax_verify_get_product_gallery() { 
  63. return _wpsc_ajax_verify_nonce( 'get_gallery_' . absint( $_REQUEST['postId'] ) ); 
  64.  
  65. function _wpsc_ajax_save_product_gallery() { 
  66. $id = absint( $_REQUEST['postId'] ); 
  67. $items = array_map( 'absint', $_REQUEST['items'] ); 
  68. $thumb = get_post_thumbnail_id( $id ); 
  69.  
  70. // always make sure the thumbnail is included 
  71. if ( $thumb && ! in_array( $thumb, $items ) ) 
  72. $items[] = $thumb; 
  73.  
  74. $result = wpsc_set_product_gallery( $id, $items ); 
  75.  
  76. return _wpsc_get_product_gallery_json( $id ); 
  77.  
  78. function _wpsc_ajax_get_product_gallery() { 
  79. $id = absint( $_REQUEST['postId'] ); 
  80. return _wpsc_get_product_gallery_json( $id ); 
  81.  
  82. function _wpsc_get_product_gallery_json( $id ) { 
  83. $attachments = wpsc_get_product_gallery( $id ); 
  84. return array_map( 'wp_prepare_attachment_for_js', $attachments ); 
.