PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/wp-e-commerce/wpsc-admin/includes/display-items-functions.php

https://github.com/AaronFernandes/aquestionof
PHP | 1302 lines | 1062 code | 163 blank | 77 comment | 173 complexity | 8f5f69641574f2b3f5194cc9f137648e MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * WPSC Product form generation functions
  4. *
  5. * @package wp-e-commerce
  6. * @since 3.7
  7. */
  8. global $wpsc_product_defaults;
  9. $wpsc_product_defaults = array(
  10. 'id' => '0',
  11. 'name' => '',
  12. 'description' => '',
  13. 'additional_description' => '',
  14. 'price' => '0.00',
  15. 'weight' => '0',
  16. 'weight_unit' => 'pound',
  17. 'pnp' => '0.00',
  18. 'international_pnp' => '0.00',
  19. 'file' => '0',
  20. 'image' => '',
  21. 'category' => '0',
  22. 'brand' => '0',
  23. 'quantity_limited' => '0',
  24. 'quantity' => '0',
  25. 'special' => '0',
  26. 'special_price' => 0.00,
  27. 'display_frontpage' => '0',
  28. 'notax' => '0',
  29. 'publish' => '1',
  30. 'active' => '1',
  31. 'donation' => '0',
  32. 'no_shipping' => '0',
  33. 'thumbnail_image' => '',
  34. 'thumbnail_state' => '1',
  35. 'meta' =>
  36. array(
  37. 'external_link' => NULL,
  38. 'external_link_text' => NULL,
  39. 'external_link_target' => NULL,
  40. 'merchant_notes' => NULL,
  41. 'sku' => NULL,
  42. 'engrave' => '0',
  43. 'can_have_uploaded_image' => '0',
  44. 'table_rate_price' =>
  45. array(
  46. 'quantity' =>
  47. array(
  48. 0 => '',
  49. ),
  50. 'table_price' =>
  51. array(
  52. 0 => '',
  53. ),
  54. ),
  55. ),
  56. );
  57. add_action( 'admin_head', 'wpsc_css_header' );
  58. function wpsc_redirect_variation_update( $location, $post_id ) {
  59. global $post;
  60. if ( $post->post_parent > 0 && 'wpsc-product' == $post->post_type )
  61. wp_redirect( admin_url( 'post.php?post='.$post->post_parent.'&action=edit' ) );
  62. else
  63. return $location;
  64. }
  65. add_filter( 'redirect_post_location', 'wpsc_redirect_variation_update', 10, 2 );
  66. function wpsc_css_header() {
  67. global $post_type;
  68. ?>
  69. <style type="text/css">
  70. <?php if ( isset( $_GET['post_type'] ) && ( 'wpsc-product' == $_GET['post_type'] ) || ( !empty( $post_type ) && 'wpsc-product' == $post_type ) ) : ?>
  71. #icon-edit { background:transparent url('<?php echo WPSC_CORE_IMAGES_URL.'/icon32.png';?>') no-repeat; }
  72. <?php endif; ?>
  73. </style>
  74. <?php
  75. }
  76. function wpsc_price_control_forms() {
  77. global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
  78. $product_data = get_post_custom( $post->ID );
  79. $product_data['meta'] = maybe_unserialize( $product_data );
  80. foreach ( $product_data['meta'] as $meta_key => $meta_value )
  81. $product_data['meta'][$meta_key] = $meta_value[0];
  82. $product_meta = array();
  83. if ( !empty( $product_data["_wpsc_product_metadata"] ) )
  84. $product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
  85. if ( isset( $product_data['meta']['_wpsc_currency'] ) )
  86. $product_alt_currency = maybe_unserialize( $product_data['meta']['_wpsc_currency'] );
  87. if ( !isset( $product_data['meta']['_wpsc_table_rate_price'] ) ) {
  88. $product_data['meta']['_wpsc_table_rate_price'] = $wpsc_product_defaults['meta']['table_rate_price'];
  89. }
  90. if ( isset( $product_meta['_wpsc_table_rate_price'] ) ) {
  91. $product_meta['table_rate_price']['state'] = 1;
  92. $product_meta['table_rate_price'] += $product_meta['_wpsc_table_rate_price'];
  93. $product_data['meta']['_wpsc_table_rate_price'] = $product_meta['_wpsc_table_rate_price'];
  94. }
  95. if ( !isset( $product_data['meta']['_wpsc_is_donation'] ) )
  96. $product_data['meta']['_wpsc_is_donation'] = $wpsc_product_defaults['donation'];
  97. if ( !isset( $product_meta['table_rate_price']['state'] ) )
  98. $product_meta['table_rate_price']['state'] = null;
  99. if ( !isset( $product_meta['table_rate_price']['quantity'] ) )
  100. $product_meta['table_rate_price']['quantity'] = $wpsc_product_defaults['meta']['table_rate_price']['quantity'][0];
  101. if ( !isset( $product_data['meta']['_wpsc_price'] ) )
  102. $product_data['meta']['_wpsc_price'] = $wpsc_product_defaults['price'];
  103. if ( !isset( $product_data['special'] ) )
  104. $product_data['special'] = $wpsc_product_defaults['special'];
  105. if ( !isset( $product_data['meta']['_wpsc_special_price'] ) )
  106. $product_data['meta']['_wpsc_special_price'] = $wpsc_product_defaults['special_price'];
  107. $currency_data = $wpdb->get_results( "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` ORDER BY `country` ASC", ARRAY_A );
  108. ?>
  109. <input type="hidden" id="parent_post" name="parent_post" value="<?php echo $post->post_parent; ?>" />
  110. <?php /* Lots of tedious work is avoided with this little line. */ ?>
  111. <input type="hidden" id="product_id" name="product_id" value="<?php echo $post->ID; ?>" />
  112. <?php /* Check product if a product has variations (Wording doesn't make sense. If Variations box is closed, you don't go there, and it's not necessarily "below") */ ?>
  113. <?php if ( wpsc_product_has_children( $post->ID ) ) : ?>
  114. <?php $price = wpsc_product_variation_price_available( $post->ID ); ?>
  115. <p><?php _e( 'This Product has variations, to edit the price please use the <a href="#variation_control">Variation Controls</a> below.' , 'wpsc' ); ?></p>
  116. <p><?php printf( __( 'Price: %s and above.' , 'wpsc' ) , $price ); ?></p>
  117. <?php else: ?>
  118. <div class='wpsc_floatleft' style="width:85px;">
  119. <label><?php _e( 'Price', 'wpsc' ); ?>:</label><br />
  120. <input type='text' class='text' size='10' name='meta[_wpsc_price]' value='<?php echo ( isset($product_data['meta']['_wpsc_price']) ) ? number_format( (float)$product_data['meta']['_wpsc_price'], 2, '.', '' ) : '0.00'; ?>' />
  121. </div>
  122. <div class='wpsc_floatleft' style='display:<?php if ( ( $product_data['special'] == 1 ) ? 'block' : 'none'
  123. ); ?>; width:85px; margin-left:30px;'>
  124. <label for='add_form_special'><?php _e( 'Sale Price', 'wpsc' ); ?>:</label>
  125. <div id='add_special'>
  126. <input type='text' size='10' value='<?php echo ( isset($product_data['meta']['_wpsc_special_price']) ) ? number_format( (float)$product_data['meta']['_wpsc_special_price'], 2, '.', '' ) : '0.00' ; ?>' name='meta[_wpsc_special_price]' />
  127. </div>
  128. </div>
  129. <br style="clear:both" />
  130. <br style="clear:both" />
  131. <a href='#' class='wpsc_add_new_currency'><?php _e( '+ New Currency', 'wpsc' ); ?></a>
  132. <br />
  133. <!-- add new currency layer -->
  134. <div class='new_layer'>
  135. <label for='newCurrency[]'><?php _e( 'Currency type', 'wpsc' ); ?>:</label><br />
  136. <select name='newCurrency[]' class='newCurrency' style='width:42%'>
  137. <?php
  138. foreach ( (array)$currency_data as $currency ) {?>
  139. <option value='<?php echo $currency['id']; ?>' >
  140. <?php echo htmlspecialchars( $currency['country'] ); ?> (<?php echo $currency['currency']; ?>)
  141. </option> <?php
  142. } ?>
  143. </select>
  144. <?php _e( 'Price', 'wpsc' ); ?> :
  145. <input type='text' class='text' size='8' name='newCurrPrice[]' value='0.00' style='display:inline' />
  146. <a href='' class='wpsc_delete_currency_layer'><img src='<?php echo WPSC_CORE_IMAGES_URL; ?>/cross.png' /></a>
  147. </div> <!-- close new_layer -->
  148. <?php
  149. if ( isset( $product_alt_currency ) && is_array( $product_alt_currency ) ) :
  150. $i = 0;
  151. foreach ( $product_alt_currency as $iso => $alt_price ) {
  152. $i++; ?>
  153. <div class='wpsc_additional_currency'>
  154. <label for='newCurrency[]'><?php _e( 'Currency type', 'wpsc' ); ?>:</label><br />
  155. <select name='newCurrency[]' class='newCurrency' style='width:42%'> <?php
  156. foreach ( $currency_data as $currency ) {
  157. if ( $iso == $currency['isocode'] )
  158. $selected = "selected='selected'";
  159. else
  160. $selected = ""; ?>
  161. <option value='<?php echo $currency['id']; ?>' <?php echo $selected; ?> >
  162. <?php echo htmlspecialchars( $currency['country'] ); ?> (<?php echo $currency['currency']; ?>)
  163. </option> <?php
  164. } ?>
  165. </select>
  166. <?php _e( 'Price:', 'wpsc' ); ?> <input type='text' class='text' size='8' name='newCurrPrice[]' value='<?php echo $alt_price; ?>' style=' display:inline' />
  167. <a href='' class='wpsc_delete_currency_layer' rel='<?php echo $iso; ?>'><img src='<?php echo WPSC_CORE_IMAGES_URL; ?>/cross.png' /></a></div>
  168. <?php }
  169. endif;
  170. echo "<br style='clear:both' />
  171. <br/><input id='add_form_donation' type='checkbox' name='meta[_wpsc_is_donation]' value='yes' " . ( isset($product_data['meta']['_wpsc_is_donation']) && ( $product_data['meta']['_wpsc_is_donation'] == 1 ) ? 'checked="checked"' : '' ) . " />&nbsp;<label for='add_form_donation'>" . __( 'This is a donation, checking this box populates the donations widget.', 'wpsc' ) . "</label>";
  172. ?>
  173. <br /><br /> <input type='checkbox' value='1' name='table_rate_price[state]' id='table_rate_price' <?php echo ( ( isset($product_meta['table_rate_price']['state']) && (bool)$product_meta['table_rate_price']['state'] == true ) ? 'checked=\'checked\'' : '' ); ?> />
  174. <label for='table_rate_price'><?php _e( 'Table Rate Price', 'wpsc' ); ?></label>
  175. <div id='table_rate'>
  176. <a class='add_level' style='cursor:pointer;'><?php _e( '+ Add level', 'wpsc' ); ?></a><br />
  177. <br style='clear:both' />
  178. <table>
  179. <tr>
  180. <th><?php _e( 'Quantity In Cart', 'wpsc' ); ?></th>
  181. <th colspan='2'><?php _e( 'Discounted Price', 'wpsc' ); ?></th>
  182. </tr>
  183. <?php
  184. if ( count( $product_meta['table_rate_price']['quantity'] ) > 0 ) {
  185. foreach ( (array)$product_meta['table_rate_price']['quantity'] as $key => $quantity ) {
  186. if ( $quantity != '' ) {
  187. $table_price = number_format( $product_meta['table_rate_price']['table_price'][$key], 2, '.', '' );
  188. ?>
  189. <tr>
  190. <td>
  191. <input type="text" size="5" value="<?php echo $quantity; ?>" name="table_rate_price[quantity][]"/><span class='description'><?php _e( 'and above', 'wpsc' ); ?></span>
  192. </td>
  193. <td>
  194. <input type="text" size="10" value="<?php echo $table_price; ?>" name="table_rate_price[table_price][]" />
  195. </td>
  196. <td><img src="<?php echo WPSC_CORE_IMAGES_URL; ?>/cross.png" class="remove_line" /></td>
  197. </tr>
  198. <?php
  199. }
  200. }
  201. }
  202. ?>
  203. <tr>
  204. <td><input type="text" size="5" value="<?php echo $quantity; ?>" name="table_rate_price[quantity][]"/><span class='description'><?php _e( 'and above', 'wpsc' ); ?></span> </td>
  205. <td><input type='text' size='10' value='' name='table_rate_price[table_price][]'/></td>
  206. </tr>
  207. </table>
  208. </div>
  209. <?php endif; ?>
  210. <?php
  211. }
  212. function wpsc_stock_control_forms() {
  213. global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
  214. $product_data = get_post_custom( $post->ID );
  215. $product_data['meta'] = maybe_unserialize( $product_data );
  216. foreach ( $product_data['meta'] as $meta_key => $meta_value )
  217. $product_data['meta'][$meta_key] = $meta_value[0];
  218. $product_meta = array();
  219. if ( !empty( $product_data["_wpsc_product_metadata"] ) )
  220. $product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
  221. if ( !isset( $product_meta['unpublish_when_none_left'] ) )
  222. $product_meta['unpublish_when_none_left'] = ''; ?>
  223. <label for="wpsc_sku"><abbr title="<?php _e( 'Stock Keeping Unit', 'wpsc' ); ?>"><?php _e( 'SKU:', 'wpsc' ); ?></abbr></label>
  224. <?php
  225. if ( !isset( $product_data['meta']['_wpsc_sku'] ) )
  226. $product_data['meta']['_wpsc_sku'] = $wpsc_product_defaults['meta']['sku']; ?><br />
  227. <input size='32' type='text' class='text' id="wpsc_sku" name='meta[_wpsc_sku]' value='<?php echo htmlentities( stripslashes( $product_data['meta']['_wpsc_sku'] ), ENT_QUOTES, 'UTF-8' ); ?>' />
  228. <br style="clear:both" />
  229. <?php
  230. if ( !isset( $product_data['meta']['_wpsc_stock'] ) )
  231. $product_data['meta']['_wpsc_stock'] = ''; ?>
  232. <br /><input class='limited_stock_checkbox' id='add_form_quantity_limited' type='checkbox' value='yes' <?php if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) echo 'checked="checked"'; else echo ''; ?> name='meta[_wpsc_limited_stock]' />
  233. <label for='add_form_quantity_limited' class='small'><?php _e( 'I have limited stock for this Product', 'wpsc' ); ?></label>
  234. <?php
  235. if ( $post->ID > 0 ) {
  236. if ( is_numeric( $product_data['meta']['_wpsc_stock'] ) ) {?>
  237. <div class='edit_stock' style='display: block;'> <?php
  238. } else { ?>
  239. <div class='edit_stock' style='display: none;'><?php
  240. } ?>
  241. <?php if ( wpsc_product_has_children( $post->ID ) ) : ?>
  242. <?php $stock = wpsc_variations_stock_remaining( $post->ID ); ?>
  243. <p><?php _e( 'This Product has variations, to edit the quantity please use the Variation Controls below.' , 'wpsc' ); ?></p>
  244. <p><?php printf( _n( "%s variant item in stock.", "%s variant items in stock.", $stock, 'wpsc' ), $stock ); ?></p>
  245. <?php else: ?>
  246. <label for="stock_limit_quantity"><?php _e( 'Quantity:', 'wpsc' ); ?></label>
  247. <input type='text' id="stock_limit_quantity" name='meta[_wpsc_stock]' size='3' value='<?php echo $product_data['meta']['_wpsc_stock']; ?>' class='stock_limit_quantity' />
  248. <?php
  249. $remaining_quantity = wpsc_get_remaining_quantity( $post->ID );
  250. $reserved_quantity = $product_data['meta']['_wpsc_stock'] - $remaining_quantity;
  251. if($reserved_quantity): ?>
  252. <p><em>
  253. <?php
  254. printf(_n('%s of them is reserved for pending or recently completed orders.', '%s of them are reserved for pending or recently completed orders.', $reserved_quantity, 'wpsc'), $reserved_quantity);
  255. ?>
  256. </em></p>
  257. <?php endif; ?>
  258. <?php endif; ?>
  259. <div class='unpublish_when_none_left'>
  260. <input type='checkbox' id="inform_when_oos" name='meta[_wpsc_product_metadata][unpublish_when_none_left]' class='inform_when_oos'<?php if ( $product_meta['unpublish_when_none_left'] == 1 ) echo ' checked="checked"'; ?> />
  261. <label for="inform_when_oos"><?php _e( 'Notify site owner and unpublish this Product if stock runs out', 'wpsc' ); ?></label>
  262. </div>
  263. <p><em><?php _e( 'If stock runs out, this Product will not be available on the shop unless you untick this box or add more stock.', 'wpsc' ); ?></em></p>
  264. </div> <?php
  265. } else { ?>
  266. <div style='display: none;' class='edit_stock'>
  267. <?php _e( 'Stock Qty', 'wpsc' ); ?><input type='text' name='meta[_wpsc_stock]' value='0' size='10' />
  268. <div style='font-size:9px; padding:5px;'>
  269. <input type='checkbox' class='inform_when_oos' name='meta[_wpsc_product_metadata][unpublish_when_none_left]' /> <?php _e( 'If this Product runs out of stock set status to Unpublished & email site owner', 'wpsc' ); ?>
  270. </div>
  271. </div><?php
  272. }
  273. ?>
  274. <?php
  275. }
  276. function wpsc_product_taxes_forms() {
  277. global $post, $wpdb, $wpsc_product_defaults;
  278. $product_data = get_post_custom( $post->ID );
  279. $product_data['meta'] = $product_meta = array();
  280. if ( !empty( $product_data['_wpsc_product_metadata'] ) )
  281. $product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
  282. if ( !isset( $product_data['meta']['_wpsc_custom_tax'] ) )
  283. $product_data['meta']['_wpsc_custom_tax'] = '';
  284. $custom_tax = $product_data['meta']['_wpsc_custom_tax'];
  285. if ( !isset( $product_meta['custom_tax'] ) ) {
  286. $product_meta['custom_tax'] = 0.00;
  287. }
  288. //Add New WPEC-Taxes Bands Here
  289. $wpec_taxes_controller = new wpec_taxes_controller();
  290. //display tax bands
  291. $band_select_settings = array(
  292. 'id' => 'wpec_taxes_band',
  293. 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_band]',
  294. 'label' => __( 'Custom Tax Band', 'wpsc' )
  295. );
  296. $wpec_taxes_band = '';
  297. if ( isset( $product_meta['wpec_taxes_band'] ) ) {
  298. $band = $wpec_taxes_controller->wpec_taxes->wpec_taxes_get_band_from_index( $product_meta['wpec_taxes_band'] );
  299. $wpec_taxes_band = array( 'index'=>$band['index'], 'name'=>$band['name'] );
  300. }
  301. $taxable_checkbox_settings = array(
  302. 'type' => 'checkbox',
  303. 'id' => 'wpec_taxes_taxable',
  304. 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable]',
  305. 'label' => __( 'This product is not taxable.', 'wpsc' )
  306. );
  307. if ( isset( $product_meta['wpec_taxes_taxable'] ) && 'on' == $product_meta['wpec_taxes_taxable'] ) {
  308. $taxable_checkbox_settings['checked'] = 'checked';
  309. }
  310. //add taxable amount only for exclusive tax
  311. if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ) {
  312. $taxable_amount_input_settings = array(
  313. 'id' => 'wpec_taxes_taxable_amount',
  314. 'name' => 'meta[_wpsc_product_metadata][wpec_taxes_taxable_amount]',
  315. 'label' => __( 'Taxable Amount', 'wpsc' )
  316. );
  317. if ( isset( $product_meta['wpec_taxes_taxable_amount'] ) ) {
  318. $taxable_amount_input_settings['value'] = $product_meta['wpec_taxes_taxable_amount'];
  319. }
  320. }// if
  321. ?>
  322. <p><?php echo $wpec_taxes_controller->wpec_taxes_display_tax_bands( $band_select_settings, $wpec_taxes_band ); ?></p>
  323. <p>
  324. <?php if ( !$wpec_taxes_controller->wpec_taxes_isincluded() ): ?>
  325. <?php echo $wpec_taxes_controller->wpec_taxes_build_input( $taxable_amount_input_settings );?>
  326. <?php endif;?>
  327. </p>
  328. <p><?php echo $wpec_taxes_controller->wpec_taxes_build_input( $taxable_checkbox_settings ); ?></p>
  329. <?php
  330. }
  331. function wpsc_product_variation_forms() {
  332. global $post, $wpdb, $wp_query, $variations_processor, $wpsc_product_defaults;
  333. $db_version = get_option( 'db_version' );
  334. $product_data = get_post_custom( $post->ID );
  335. $product_data['meta'] = maybe_unserialize( $product_data );
  336. foreach ( $product_data['meta'] as $meta_key => $meta_value )
  337. $product_data['meta'][$meta_key] = $meta_value[0];
  338. $product_meta = array();
  339. if ( !empty( $product_data["_wpsc_product_metadata"] ) )
  340. $product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
  341. $siteurl = get_option( 'siteurl' );
  342. $output = '';
  343. // Get variation data from WP Terms
  344. $product_term_data = wp_get_object_terms( $post->ID, 'wpsc-variation' );
  345. if ( !empty( $product_term_data ) ) {
  346. foreach ( $product_term_data as $product_term )
  347. $product_terms[] = $product_term->term_id;
  348. } else {
  349. $product_terms = array();
  350. }
  351. ?>
  352. <?php if ( empty( $post->post_title ) ) : ?>
  353. <p><?php _e( 'You must first save this Product as a Draft before adding variations', 'wpsc' ); ?></p>
  354. <?php else : ?>
  355. <div id="product_variations">
  356. <div class="variation_checkboxes">
  357. <?php
  358. // Get the terms from variations
  359. $variation_sets = get_terms( 'wpsc-variation', array (
  360. 'hide_empty' => 0,
  361. 'parent' => 0
  362. ) );
  363. // Loop through each variation set
  364. foreach ( (array)$variation_sets as $variation_set ) :
  365. $set_checked_state = '';
  366. // If this Product includes this variation, check it
  367. if ( in_array( $variation_set->term_id, $product_terms ) )
  368. $set_checked_state = "checked='checked'"; ?>
  369. <div class="variation_set">
  370. <label class='set_label'>
  371. <input type="checkbox" <?php echo $set_checked_state; ?> name="variations[<?php echo $variation_set->term_id; ?>]" value="1">
  372. <?php echo $variation_set->name; ?>
  373. </label>
  374. <?php
  375. $variations = get_terms( 'wpsc-variation', array (
  376. 'hide_empty' => 0,
  377. 'parent' => $variation_set->term_id
  378. ) );
  379. // Loop through the variations
  380. foreach ( (array)$variations as $variation ) :
  381. $checked_state = '';
  382. if ( in_array( $variation->term_id, $product_terms ) )
  383. $checked_state = "checked='checked'";
  384. ?>
  385. <div class="variation">
  386. <label>
  387. <input type="checkbox" <?php echo $checked_state; ?> name="edit_var_val[<?php echo $variation_set->term_id; ?>][<?php echo $variation->term_id; ?>]" value="1">
  388. <?php echo $variation->name; ?>
  389. </label>
  390. </div>
  391. <?php endforeach; ?>
  392. </div>
  393. <?php endforeach; ?>
  394. </div>
  395. <a class="preview button update_variations_action" href='#'><?php _e( 'Update Variations &rarr;', 'wpsc' ); ?></a>
  396. </div>
  397. <?php
  398. $parent_product = $post->ID;
  399. $query = array(
  400. 'post_type' => 'wpsc-product',
  401. 'orderby' => 'menu_order post_title',
  402. 'post_parent' => $parent_product,
  403. 'post_status' => 'publish, inherit',
  404. 'order' => "ASC"
  405. );
  406. $args = array(
  407. 'post_type' => 'attachment',
  408. 'numberposts' => 1,
  409. 'post_status' => null,
  410. 'post_parent' => $parent_product,
  411. 'orderby' => 'menu_order',
  412. 'order' => 'ASC'
  413. );
  414. $image_data = (array)get_posts( $args );
  415. $parent_product_data['image'] = array_shift( $image_data );
  416. $wp_query = new WP_Query( $query );
  417. if ( !isset( $parent_product_data ) )
  418. $parent_product_data = null;
  419. ?>
  420. <p><a name='variation_control'>&nbsp;</a><?php _e( 'Check or uncheck variation boxes and then click Update Variations to add or remove variations.', 'wpsc' ) ?></p>
  421. <table class="widefat page" id='wpsc_product_list' cellspacing="0">
  422. <thead>
  423. <tr>
  424. <?php print_column_headers( 'wpsc-product_variants' ); ?>
  425. </tr>
  426. </thead>
  427. <tfoot>
  428. <tr>
  429. <?php print_column_headers( 'wpsc-product_variants', false ); ?>
  430. </tr>
  431. </tfoot>
  432. <tbody>
  433. <?php
  434. wpsc_admin_product_listing( $parent_product_data );
  435. ?>
  436. <?php
  437. if ( count( $wp_query->posts ) < 1 ) :
  438. ?>
  439. <tr>
  440. <td colspan="8">
  441. <?php _e( 'You have no Variations added.', 'wpsc' ); ?>
  442. </td>
  443. </tr>
  444. <?php endif; ?>
  445. </tbody>
  446. </table>
  447. <?php
  448. endif;
  449. }
  450. function wpsc_product_shipping_forms() {
  451. global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
  452. $product_data = get_post_custom( $post->ID );
  453. $product_data['meta'] = maybe_unserialize( $product_data );
  454. foreach ( $product_data['meta'] as $meta_key => $meta_value )
  455. $product_data['meta'][$meta_key] = $meta_value[0];
  456. $product_meta = array();
  457. if ( !empty( $product_data["_wpsc_product_metadata"] ) )
  458. $product_meta = maybe_unserialize( $product_data["_wpsc_product_metadata"][0] );
  459. $product_data['transformed'] = array();
  460. if ( !isset( $product_meta['weight'] ) )
  461. $product_meta['weight'] = "";
  462. if( !isset( $product_meta['weight_unit'] ) )
  463. $product_meta['weight_unit'] = '';
  464. $product_data['transformed']['weight'] = wpsc_convert_weight( $product_meta['weight'], "pound", $product_meta['weight_unit']);
  465. // Fix wp_debug notices
  466. if(!isset($product_meta['dimensions'])){
  467. $product_meta['dimensions'] = array(
  468. 'height' => 0,
  469. 'width' => 0,
  470. 'length' => 0
  471. );
  472. }
  473. if( !isset($product_meta['display_weight_as']) )
  474. $product_meta['display_weight_as'] = '';
  475. if( !isset( $product_meta['dimensions']['height_unit'] ) )
  476. $product_meta['dimensions']['height_unit'] = '';
  477. if( !isset( $product_meta['dimensions']['width_unit'] ) )
  478. $product_meta['dimensions']['width_unit'] = '';
  479. if( !isset( $product_meta['dimensions']['length_unit'] ) )
  480. $product_meta['dimensions']['length_unit'] = '';
  481. if( !isset( $product_meta['shipping'] ) ){
  482. $product_meta['shipping']['local'] = '';
  483. $product_meta['shipping']['international'] = '';
  484. }
  485. if( !isset( $product_meta['no_shipping'] ) )
  486. $product_meta['no_shipping'] = '';
  487. ?>
  488. <table>
  489. <!--USPS shipping changes-->
  490. <tr>
  491. <td>
  492. <?php _e( 'Weight', 'wpsc' ); ?>
  493. </td>
  494. <td>
  495. <input type='text' size='5' name='meta[_wpsc_product_metadata][weight]' value='<?php echo $product_data['transformed']['weight']; ?>' />
  496. <select name='meta[_wpsc_product_metadata][weight_unit]'>
  497. <option value='pound' <?php echo ( ( $product_meta['display_weight_as'] == 'pound' ) ? 'selected="selected"' : '' ); ?> ><?php _e( 'Pounds', 'wpsc' ); ?></option>
  498. <option value='ounce' <?php echo ( ( preg_match( "/o(u)?nce/", $product_meta['display_weight_as'] ) ) ? 'selected="selected"' : '' ); ?> ><?php _e( 'Ounces', 'wpsc' ); ?></option>
  499. <option value='gram' <?php echo ( ( $product_meta['display_weight_as'] == 'gram' ) ? 'selected="selected"' : '' ); ?> ><?php _e( 'Grams', 'wpsc' ); ?></option>
  500. <option value='kilogram' <?php echo ( ( $product_meta['display_weight_as'] == 'kilogram' || $product_meta['display_weight_as'] == 'kilograms' ) ? 'selected="selected"' : '' ); ?> ><?php _e( 'Kilograms', 'wpsc' ); ?></option>
  501. </select>
  502. </td>
  503. </tr>
  504. <!--dimension-->
  505. <tr>
  506. <td>
  507. <?php _e( 'Height', 'wpsc' ); ?>
  508. </td>
  509. <td>
  510. <input type='text' size='5' name='meta[_wpsc_product_metadata][dimensions][height]' value= '<?php echo $product_meta['dimensions']['height'] ; ?>'>
  511. <select name='meta[_wpsc_product_metadata][dimensions][height_unit]'>
  512. <option value='in' <?php echo ( ( $product_meta['dimensions']['height_unit'] == 'in' ) ? 'selected' : '' ); ?> ><?php _e( 'inches', 'wpsc' ); ?></option>
  513. <option value='cm' <?php echo ( ( $product_meta['dimensions']['height_unit'] == 'cm' ) ? 'selected' : '' ); ?> ><?php _e( 'cm', 'wpsc' ); ?></option>
  514. <option value='meter' <?php echo ( ( $product_meta['dimensions']['height_unit'] == 'meter' ) ? 'selected' : '' ); ?> ><?php _e( 'meter', 'wpsc' ); ?></option>
  515. </select>
  516. </td>
  517. </tr>
  518. <tr>
  519. <td>
  520. <?php _e( 'Width', 'wpsc' ); ?>
  521. </td>
  522. <td>
  523. <input type='text' size='5' name='meta[_wpsc_product_metadata][dimensions][width]' value='<?php echo $product_meta['dimensions']['width']; ?> '>
  524. <select name='meta[_wpsc_product_metadata][dimensions][width_unit]'>
  525. <option value='in' <?php echo( ( $product_meta['dimensions']['width_unit'] == 'in' ) ? 'selected' : '' ); ?> ><?php _e( 'inches', 'wpsc' ); ?></option>
  526. <option value='cm' <?php echo ( ( $product_meta['dimensions']['width_unit'] == 'cm' ) ? 'selected' : '' ); ?> ><?php _e( 'cm', 'wpsc' ); ?></option>
  527. <option value='meter' <?php echo ( ( $product_meta['dimensions']['width_unit'] == 'meter' ) ? 'selected' : '' ); ?> ><?php _e( 'meter', 'wpsc' ); ?></option>
  528. </select>
  529. </td>
  530. </tr>
  531. <tr>
  532. <td>
  533. <?php _e( 'Length', 'wpsc' ); ?>
  534. </td>
  535. <td>
  536. <input type='text' size='5' name='meta[_wpsc_product_metadata][dimensions][length]' value='<?php echo $product_meta['dimensions']['length']; ?>'>
  537. <select name='meta[_wpsc_product_metadata][dimensions][length_unit]'>
  538. <option value='in' <?php echo( ( $product_meta['dimensions']['length_unit'] == 'in' ) ? 'selected' : '' ); ?> ><?php _e( 'inches', 'wpsc' ); ?></option>
  539. <option value='cm' <?php echo( ( $product_meta['dimensions']['length_unit'] == 'cm' ) ? 'selected' : '' ); ?> ><?php _e( 'cm', 'wpsc' ); ?></option>
  540. <option value='meter' <?php echo ( ( $product_meta['dimensions']['length_unit'] == 'meter' ) ? 'selected' : '' ); ?> ><?php _e( 'meter', 'wpsc' ); ?></option>
  541. </select>
  542. </td>
  543. </tr>
  544. <!--//dimension-->
  545. <!--USPS shipping changes ends-->
  546. <tr>
  547. <td colspan='2'>
  548. <strong><?php _e( 'Flat Rate Settings', 'wpsc' ); ?></strong>
  549. </td>
  550. </tr>
  551. <tr>
  552. <td>
  553. <?php _e( 'Local Shipping Fee', 'wpsc' ); ?>
  554. </td>
  555. <td>
  556. <input type='text' size='10' name='meta[_wpsc_product_metadata][shipping][local]' value='<?php echo number_format( (float)$product_meta['shipping']['local'], 2, '.', '' ); ?>' />
  557. </td>
  558. </tr>
  559. <tr>
  560. <td>
  561. <?php _e( 'International Shipping Fee', 'wpsc' ); ?>
  562. </td>
  563. <td>
  564. <input type='text' size='10' name='meta[_wpsc_product_metadata][shipping][international]' value='<?php echo number_format( (float)$product_meta['shipping']['international'], 2, '.', '' ); ?>' />
  565. </td>
  566. </tr>
  567. <tr>
  568. <td>
  569. <br />
  570. <input id='add_form_no_shipping' type='checkbox' name='meta[_wpsc_product_metadata][no_shipping]' value='1' <?php echo ( ( $product_meta['no_shipping'] == 1 ) ? 'checked="checked"' : '' ); ?> />&nbsp;<label for='add_form_no_shipping'><?php _e( 'Disregard Shipping for this Product', 'wpsc' ); ?></label>
  571. </td>
  572. </tr>
  573. </table>
  574. <?php
  575. }
  576. function wpsc_product_advanced_forms() {
  577. global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
  578. $product_data = get_post_custom( $post->ID );
  579. $product_data['meta'] = $product_meta = array();
  580. if ( !empty( $product_data['_wpsc_product_metadata'] ) )
  581. $product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
  582. $custom_fields = $wpdb->get_results( "
  583. SELECT
  584. `meta_id`, `meta_key`, `meta_value`
  585. FROM
  586. `{$wpdb->postmeta}`
  587. WHERE
  588. `post_id` = {$post->ID}
  589. AND
  590. `meta_key` NOT LIKE '\_%'
  591. ORDER BY
  592. LOWER(meta_key)", ARRAY_A
  593. );
  594. if( !isset( $product_meta['engraved'] ) )
  595. $product_meta['engraved'] = '';
  596. if( !isset( $product_meta['can_have_uploaded_image'] ) )
  597. $product_meta['can_have_uploaded_image'] = '';
  598. ?>
  599. <table>
  600. <tr>
  601. <td colspan='2' class='itemfirstcol'>
  602. <strong><?php _e( 'Custom Meta', 'wpsc' ); ?>:</strong><br />
  603. <a href='#' class='add_more_meta' onclick="return add_more_meta(this)"> + <?php _e( 'Add Custom Meta', 'wpsc' );?> </a><br /><br />
  604. <?php
  605. foreach ( (array)$custom_fields as $custom_field ) {
  606. $i = $custom_field['meta_id'];
  607. ?>
  608. <div class='product_custom_meta' id='custom_meta_<?php echo $i; ?>'>
  609. <?php _e( 'Name', 'wpsc' ); ?>
  610. <input type='text' class='text' value='<?php echo $custom_field['meta_key']; ?>' name='custom_meta[<?php echo $i; ?>][name]' id='custom_meta_name_<?php echo $i; ?>'>
  611. <?php _e( 'Value', 'wpsc' ); ?>
  612. <textarea class='text' name='custom_meta[<?php echo $i; ?>][value]' id='custom_meta_value_<?php echo $i; ?>'><?php echo $custom_field['meta_value']; ?></textarea>
  613. <a href='#' class='remove_meta' onclick='return remove_meta(this, <?php echo $i; ?>)'><?php _e( 'Delete', 'wpsc' ); ?></a>
  614. <br />
  615. </div>
  616. <?php
  617. }
  618. ?>
  619. <div class='product_custom_meta'>
  620. <?php _e( 'Name', 'wpsc' ); ?>: <br />
  621. <input type='text' name='new_custom_meta[name][]' value='' class='text'/><br />
  622. <?php _e( 'Description', 'wpsc' ); ?>: <br />
  623. <textarea name='new_custom_meta[value][]' cols='40' rows='10' class='text' ></textarea>
  624. <br />
  625. </div>
  626. </td>
  627. </tr>
  628. <tr>
  629. <td class='itemfirstcol' colspan='2'><br /> <strong><?php _e( 'Merchant Notes:', 'wpsc' ); ?></strong><br />
  630. <textarea cols='40' rows='3' name='meta[_wpsc_product_metadata][merchant_notes]' id='merchant_notes'><?php
  631. if ( isset( $product_meta['merchant_notes'] ) )
  632. echo stripslashes( trim( $product_meta['merchant_notes'] ) );
  633. ?></textarea>
  634. <small><?php _e( 'These notes are only available here.', 'wpsc' ); ?></small>
  635. </td>
  636. </tr>
  637. <tr>
  638. <td class='itemfirstcol' colspan='2'><br />
  639. <strong><?php _e( 'Personalisation Options', 'wpsc' ); ?>:</strong><br />
  640. <input type='hidden' name='meta[_wpsc_product_metadata][engraved]' value='0' />
  641. <input type='checkbox' name='meta[_wpsc_product_metadata][engraved]' <?php echo ( ( $product_meta['engraved'] == true ) ? 'checked="checked"' : '' ); ?> id='add_engrave_text' />
  642. <label for='add_engrave_text'><?php _e( 'Users can personalize this Product by leaving a message on single product page', 'wpsc' ); ?></label>
  643. <br />
  644. </td>
  645. </tr>
  646. <tr>
  647. <td class='itemfirstcol' colspan='2'>
  648. <input type='hidden' name='meta[_wpsc_product_metadata][can_have_uploaded_image]' value='0' />
  649. <input type='checkbox' name='meta[_wpsc_product_metadata][can_have_uploaded_image]' <?php echo ( $product_meta['can_have_uploaded_image'] == true ) ? 'checked="checked"' : ''; ?> id='can_have_uploaded_image' />
  650. <label for='can_have_uploaded_image'> <?php _e( 'Users can upload images on single product page to purchase logs.', 'wpsc' ); ?> </label>
  651. <br />
  652. </td>
  653. </tr>
  654. <?php
  655. if ( get_option( 'payment_gateway' ) == 'google' ) {
  656. ?>
  657. <tr>
  658. <td class='itemfirstcol' colspan='2'>
  659. <input type='checkbox' <?php echo $product_meta['google_prohibited']; ?> name='meta[_wpsc_product_metadata][google_prohibited]' id='add_google_prohibited' /> <label for='add_google_prohibited'>
  660. <?php _e( 'Prohibited <a href="http://checkout.google.com/support/sell/bin/answer.py?answer=75724">by Google?</a>', 'wpsc' ); ?>
  661. </label><br />
  662. </td>
  663. </tr>
  664. <?php
  665. }
  666. ob_start();
  667. do_action( 'wpsc_add_advanced_options', $post->ID );
  668. ob_get_contents();
  669. ob_end_clean();
  670. ?>
  671. <tr>
  672. <td class='itemfirstcol' colspan='2'><br />
  673. <strong><?php _e( 'Enable Comments', 'wpsc' ); ?>:</strong><br />
  674. <select name='meta[_wpsc_product_metadata][enable_comments]'>
  675. <option value='' <?php echo ( ( isset( $product_meta['enable_comments'] ) && $product_meta['enable_comments'] == '' ) ? 'selected' : '' ); ?> ><?php _e( 'Use Default', 'wpsc' ); ?></option>
  676. <option value='1' <?php echo ( ( isset( $product_meta['enable_comments'] ) && $product_meta['enable_comments'] == '1' ) ? 'selected' : '' ); ?> ><?php _e( 'Yes', 'wpsc' ); ?></option>
  677. <option value='0' <?php echo ( ( isset( $product_meta['enable_comments'] ) && $product_meta['enable_comments'] == '0' ) ? 'selected' : '' ); ?> ><?php _e( 'No', 'wpsc' ); ?></option>
  678. </select>
  679. <br/><?php _e( 'Allow users to comment on this Product.', 'wpsc' ); ?>
  680. </td>
  681. </tr>
  682. </table>
  683. <?php
  684. }
  685. function wpsc_product_external_link_forms() {
  686. global $post, $wpdb, $variations_processor, $wpsc_product_defaults;
  687. $product_data = get_post_custom( $post->ID );
  688. $product_data['meta'] = $product_meta = array();
  689. if ( !empty( $product_data['_wpsc_product_metadata'] ) )
  690. $product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
  691. // Get External Link Values
  692. $external_link_value = isset( $product_meta['external_link'] ) ? $product_meta['external_link'] : '';
  693. $external_link_text_value = isset( $product_meta['external_link_text'] ) ? $product_meta['external_link_text'] : '';
  694. $external_link_target_value = isset( $product_meta['external_link_target'] ) ? $product_meta['external_link_target'] : '';
  695. $external_link_target_value_selected[$external_link_target_value] = ' selected="selected"';
  696. if ( !isset( $external_link_target_value_selected['_self'] ) ) $external_link_target_value_selected['_self'] = '';
  697. if ( !isset( $external_link_target_value_selected['_blank'] ) ) $external_link_target_value_selected['_blank'] = '';
  698. ?>
  699. <p><?php _e( 'If this product is for sale on another website enter the link here. For instance if your product is an MP3 file for sale on iTunes you could put the link here. This option overrides the buy now and add to cart links and takes you to the site linked here. You can also customise the Buy Now text and choose to open the link in a new window.', 'wpsc' ); ?>
  700. <table class="form-table" style="width: 100%;" cellspacing="2" cellpadding="5">
  701. <tbody>
  702. <tr class="form-field">
  703. <th valign="top" scope="row"><label for="external_link"><?php _e( 'External Link', 'wpsc' ); ?></label></th>
  704. <td><input type="text" name="meta[_wpsc_product_metadata][external_link]" id="external_link" value="<?php esc_attr_e( $external_link_value ); ?>" size="50" style="width: 95%"></td>
  705. </tr>
  706. <tr class="form-field">
  707. <th valign="top" scope="row"><label for="external_link_text"><?php _e( 'External Link Text', 'wpsc' ); ?></label></th>
  708. <td><input type="text" name="meta[_wpsc_product_metadata][external_link_text]" id="external_link_text" value="<?php esc_attr_e( $external_link_text_value ); ?>" size="50" style="width: 95%"></td>
  709. </tr>
  710. <tr class="form-field">
  711. <th valign="top" scope="row"><label for="external_link_target"><?php _e( 'External Link Target', 'wpsc' ); ?></label></th>
  712. <td>
  713. <select id="external_link_target" name="meta[_wpsc_product_metadata][external_link_target]">
  714. <option value=""><?php _ex( 'Default (set by theme)', 'External product link target', 'wpsc' ); ?></option>
  715. <option value="_self" <?php echo $external_link_target_value_selected['_self'] ; ?>><?php _e( 'Open link in the same window', 'wpsc' ); ?></option>
  716. <option value="_blank" <?php echo $external_link_target_value_selected['_blank'] ; ?>><?php _e( 'Open link in a new window', 'wpsc' ); ?></option>
  717. </select>
  718. </td>
  719. </tr>
  720. </tbody>
  721. </table>
  722. <?php
  723. }
  724. function wpsc_product_image_forms() {
  725. global $post;
  726. edit_multiple_image_gallery( $post );
  727. ?>
  728. <p><strong <?php if ( isset( $display ) ) echo $display; ?>><a href="media-upload.php?parent_page=wpsc-edit-products&post_id=<?php echo $post->ID; ?>&type=image&tab=gallery&TB_iframe=1&width=640&height=566" class="thickbox" title="Manage Your Product Images"><?php _e( 'Manage Product Images', 'wpsc' ); ?></a></strong></p>
  729. <?php
  730. }
  731. function wpsc_additional_desc() {
  732. global $post;
  733. ?>
  734. <textarea name='additional_description' id='additional_description' cols='40' rows='5' ><?php echo stripslashes( $post->post_excerpt ); ?></textarea>
  735. <?php
  736. }
  737. function wpsc_product_download_forms() {
  738. global $post, $wpdb, $wpsc_product_defaults;
  739. $product_data = get_post_custom( $post->ID );
  740. $output = '';
  741. $product_data['meta'] = $product_meta = array();
  742. if ( !empty( $product_data['_wpsc_product_metadata'] ) )
  743. $product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
  744. $upload_max = wpsc_get_max_upload_size();
  745. ?>
  746. <?php echo wpsc_select_product_file( $post->ID ); ?>
  747. <h4><?php _e( 'Upload New File', 'wpsc' ); ?>:</h4>
  748. <input type='file' name='file' value='' /><br /><?php _e( 'Max Upload Size', 'wpsc' ); ?>:<span><?php echo $upload_max; ?></span><br /><br />
  749. <h4><a href="admin.php?wpsc_admin_action=product_files_existing&product_id=<?php echo $post->ID; ?>" class="thickbox" title="<?php printf( __( 'Select all downloadable files for %s', 'wpsc' ), $post->post_title ); ?>"><?php _e( 'Select from existing files', 'wpsc' ); ?></a></h4>
  750. <?php
  751. if ( function_exists( "make_mp3_preview" ) || function_exists( "wpsc_media_player" ) ) {
  752. ?>
  753. <br />
  754. <h4><?php _e( "Select an MP3 file to upload as a preview", 'wpsc' ) ?></h4>
  755. <input type='file' name='preview_file' value='' /><br />
  756. <h4><?php _e( "Your preview for this product:", 'wpsc' ) ?></h4>
  757. <?php
  758. $args = array(
  759. 'post_type' => 'wpsc-preview-file',
  760. 'post_parent' => $post->ID,
  761. 'numberposts' => -1,
  762. 'post_status' => 'all'
  763. );
  764. $preview_files = (array)get_posts( $args );
  765. foreach ($preview_files as $preview)
  766. echo $preview->post_title . '<br />';
  767. ?>
  768. <br />
  769. <?php
  770. }
  771. $output = apply_filters( 'wpsc_downloads_metabox', $output );
  772. }
  773. function wpsc_product_label_forms() {
  774. _deprecated_function( __FUNCTION__, '3.8' );
  775. return false;
  776. }
  777. /**
  778. * Adding function to change text for media buttons
  779. */
  780. function change_context( $context ) {
  781. global $current_screen;
  782. if ( $current_screen->id != 'wpsc-product' )
  783. return $context;
  784. return __( 'Upload Image%s', 'wpsc' );
  785. }
  786. function change_link( $link ) {
  787. global $post_ID, $current_screen;
  788. if ( $current_screen->id != 'wpsc-product' )
  789. return $link;
  790. $uploading_iframe_ID = $post_ID;
  791. $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
  792. return $media_upload_iframe_src . "&amp;type=image&parent_page=wpsc-edit-products";
  793. }
  794. function wpsc_form_multipart_encoding() {
  795. echo ' enctype="multipart/form-data"';
  796. }
  797. add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
  798. add_filter( 'media_buttons_context', 'change_context' );
  799. add_filter( 'image_upload_iframe_src', "change_link" );
  800. /*
  801. * Modifications to Media Gallery
  802. */
  803. if ( ( isset( $_REQUEST['parent_page'] ) && ( $_REQUEST['parent_page'] == 'wpsc-edit-products' ) ) ) {
  804. add_filter( 'media_upload_tabs', 'wpsc_media_upload_tab_gallery', 12 );
  805. add_filter( 'attachment_fields_to_save', 'wpsc_save_attachment_fields', 9, 2 );
  806. add_filter( 'media_upload_form_url', 'wpsc_media_upload_url', 9, 1 );
  807. add_action( 'admin_head', 'wpsc_gallery_css_mods' );
  808. }
  809. add_filter( 'gettext', 'wpsc_filter_delete_text', 12 , 3 );
  810. add_filter( 'attachment_fields_to_edit', 'wpsc_attachment_fields', 11, 2 );
  811. add_filter( 'gettext', 'wpsc_filter_feature_image_text', 12, 3 );
  812. add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
  813. if ( isset( $_REQUEST["save"] ) && isset( $_REQUEST["attachments"] ) && is_array( $_REQUEST["attachments"] ) ) {
  814. //wpsc_regenerate_thumbnails();
  815. }
  816. /*
  817. * This filter overrides string with context translations
  818. *
  819. * @param $translation The current translation
  820. * @param $text The text being translated
  821. * @param $context The domain for the translation
  822. * @param $domain The domain for the translation
  823. * @return string The translated / filtered text.
  824. */
  825. function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
  826. if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
  827. $translations = &get_translations_for_domain( $domain );
  828. return $translations->translate( 'Variation set', 'wpsc' );
  829. //this will never happen, this is here only for gettex to pick up the translation
  830. return __( 'Variation set', 'wpsc' );
  831. }
  832. return $translation;
  833. }
  834. /*
  835. * This filter translates string before it is displayed
  836. * specifically for the words 'Use as featured image' with 'Use as Product Thumbnail' when the user is selecting a Product Thumbnail
  837. * using media gallery.
  838. *
  839. * @param $translation The current translation
  840. * @param $text The text being translated
  841. * @param $domain The domain for the translation
  842. * @return string The translated / filtered text.
  843. */
  844. function wpsc_filter_feature_image_text( $translation, $text, $domain ) {
  845. if ( 'Use as featured image' == $text && isset( $_REQUEST['post_id'] ) ) {
  846. $post = get_post( $_REQUEST['post_id'] );
  847. if ( $post->post_type != 'wpsc-product' ) return $translation;
  848. $translations = &get_translations_for_domain( $domain );
  849. return $translations->translate( 'Use as Product Thumbnail', 'wpsc' );
  850. //this will never happen, this is here only for gettex to pick up the translation
  851. return __( 'Use as Product Thumbnail', 'wpsc' );
  852. }
  853. if ( 'The name is how it appears on your site.' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ){
  854. $translations = &get_translations_for_domain( $domain );
  855. return $translations->translate( 'The name is how it appears on your site. <br><div class="error"><strong>Please read this carefully before starting to work with variations:</strong><br />Variations in WP e-Commerce are divided into sets. For example set <strong>Color</strong> could have variations <strong>Red, Green,</strong> and <strong>Blue</strong>. To create a variation set simply enter the <strong>name</strong> and push Enter key on your keyboard or click <strong>Add New Variation/Set</strong> button in the bottom of this page. Then you will be able to select it from <strong>Variation set</strong> drop-down menu and add some variations to it. To add a new variation set just select <strong>None</strong> in <strong>Variation set</strong> drop-down menu.</div>', 'wpsc' );
  856. //this will never happen, this is here only for gettex to pick up the translation
  857. return __( 'The name is how it appears on your site. <br><div class="error"><strong>Please read this carefully before starting to work with variations:</strong><br />Variations in WP e-Commerce are divided into sets. For example set <strong>Color</strong> could have variations <strong>Red, Green,</strong> and <strong>Blue</strong>. To create a set simply enter <strong>Name</strong> and push Enter key on your keyboard or click <strong>Add New Variation/Set</strong> button in the bottom of this page. Now you can select the variation set that you\'ve just created from <strong>Variation set</strong> drop-down menu and add some variations to it.</div>', 'wpsc' );
  858. }
  859. return $translation;
  860. }
  861. function wpsc_attachment_fields( $form_fields, $post ) {
  862. $out = '';
  863. if(isset($_GET["post_id"]))
  864. $parent_post = get_post( absint($_GET["post_id"]) );
  865. else
  866. $parent_post = get_post( $post->post_parent );
  867. if ( $parent_post->post_type == "wpsc-product" ) {
  868. //Unfortunate hack, as I'm not sure why the From Computer tab doesn't process filters the same way the Gallery does
  869. echo '
  870. <script type="text/javascript">
  871. jQuery(function(){
  872. jQuery("a.wp-post-thumbnail").each(function(){
  873. var product_image = jQuery(this).text();
  874. if (product_image == "' . __('Use as featured image') . '") {
  875. jQuery(this).text("' . __('Use as Product Thumbnail', 'wpsc') . '");
  876. }
  877. });
  878. var trash = jQuery("#media-upload a.del-link").text();
  879. if (trash == "Delete") {
  880. jQuery("#media-upload a.del-link").text("Trash");
  881. }
  882. });
  883. </script>';
  884. $size_names = array( 'small-product-thumbnail' => __( 'Default Product Thumbnail Size', 'wpsc' ), 'medium-single-product' => __( 'Single Product Image Size', 'wpsc' ), 'full' => __( 'Full Size', 'wpsc' ) );
  885. $check = get_post_meta( $post->ID, '_wpsc_selected_image_size', true );
  886. if ( !$check )
  887. $check = 'medium-single-product';
  888. // regenerate size metadata in case it's missing
  889. if ( ! image_get_intermediate_size( $post->ID, $check ) ) {
  890. $metadata = wp_get_attachment_metadata( $post->ID );
  891. $file = get_attached_file( $post->ID );
  892. $metadata = array_merge( wp_generate_attachment_metadata( $post->ID, $file ), $metadata );
  893. wp_update_attachment_metadata( $post->ID, $metadata );
  894. }
  895. //This loop attaches the custom thumbnail/single image sizes to this page
  896. foreach ( $size_names as $size => $name ) {
  897. $downsize = image_downsize( $post->ID, $size );
  898. // is this size selectable?
  899. $enabled = ( $downsize[3] || 'full' == $size );
  900. $css_id = "image-size-{$size}-{$post->ID}";
  901. // if this size is the default but that's not available, don't select it
  902. $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}' " . checked( $size, $check, false ) . " />";
  903. $html .= "<label for='{$css_id}'>$name</label>";
  904. // only show the dimensions if that choice is available
  905. if ( $enabled )
  906. $html .= " <label for='{$css_id}' class='help'>" . sprintf( __( "(%d&nbsp;&times;&nbsp;%d)", 'wpsc' ), $downsize[1], $downsize[2] ). "</label>";
  907. $html .= '</div>';
  908. $out .= $html;
  909. }
  910. unset( $form_fields['post_excerpt'], $form_fields['image_url'], $form_fields['post_content'], $form_fields['post_title'], $form_fields['url'], $form_fields['align'], $form_fields['image_alt']['helps'], $form_fields["image-size"] );
  911. $form_fields['image_alt']['helps'] = __( 'Alt text for the product image, e.g. &#8220;Rockstar T-Shirt&#8221;', 'wpsc' );
  912. $form_fields["image-size"] = array(
  913. 'label' => __( 'Single Product Page Thumbnail:', 'wpsc' ),
  914. 'input' => 'html',
  915. 'html' => $out,
  916. 'helps' => "<span style='text-align:left; clear:both; display:block; padding-top:3px;'>" . __( 'This is the Thumbnail size that will be displayed on the Single Product page. You can change the default sizes under your store settings', 'wpsc' ) . "</span>"
  917. );
  918. //This is for the custom thumbnail size.
  919. $custom_thumb_size_w = get_post_meta( $post->ID, "_wpsc_custom_thumb_w", true );
  920. $custom_thumb_size_h = get_post_meta( $post->ID, "_wpsc_custom_thumb_h", true );
  921. $custom_thumb_html = "
  922. <input style='width:50px; text-align:center' type='text' name='attachments[{$post->ID}][wpsc_custom_thumb_w]' value='{$custom_thumb_size_w}' /> X <input style='width:50px; text-align:center' type='text' name='attachments[{$post->ID}][wpsc_custom_thumb_h]' value='{$custom_thumb_size_h}' />
  923. ";
  924. $form_fields["wpsc_custom_thumb"] = array(
  925. "label" => __( "Products Page Thumbnail Size:", 'wpsc' ),
  926. "input" => "html", // this is default if "input" is omitted
  927. "helps" => "<span style='text-align:left; clear:both; display:block; padding-top:3px;'>" . __( 'Custom thumbnail size for this image on the main Product Page', 'wpsc') . "</span>",
  928. "html" => $custom_thumb_html
  929. );
  930. }
  931. return $form_fields;
  932. }
  933. function wpsc_save_attachment_fields( $post, $attachment ) {
  934. if ( isset ( $attachment['wpsc_custom_thumb_w'] ) )
  935. update_post_meta( $post['ID'], '_wpsc_custom_thumb_w', $attachment['wpsc_custom_thumb_w'] );
  936. if ( isset ( $attachment['wpsc_custom_thumb_h'] ) )
  937. update_post_meta( $post['ID'], '_wpsc_custom_thumb_h', $attachment['wpsc_custom_thumb_h'] );
  938. if ( isset ( $attachment['image-size'] ) )
  939. update_post_meta( $post['ID'], '_wpsc_selected_image_size', $attachment['image-size'] );
  940. return $post;
  941. }
  942. function wpsc_media_upload_url( $form_action_url ) {
  943. $form_action_url = esc_url( add_query_arg( array( 'parent_page'=>'wpsc-edit-products' ) ) );
  944. return $form_action_url;
  945. }
  946. function wpsc_gallery_css_mods() {
  947. print '<style type="text/css">
  948. #gallery-settings *{
  949. display:none;
  950. }
  951. a.wp-post-thumbnail {
  952. color:green;
  953. }
  954. #media-upload a.del-link {
  955. color:red;
  956. }
  957. #media-upload a.wp-post-thumbnail {
  958. margin-left:0px;
  959. }
  960. td.savesend input.button {
  961. display:none;
  962. }
  963. </style>';
  964. print '
  965. <script type="text/javascript">
  966. jQuery(function(){
  967. jQuery("td.A1B1").each(function(){
  968. var target = jQuery(this).next();
  969. jQuery("p > input.button", this).appendTo(target);
  970. });
  971. jQuery("a.wp-post-thumbnail").each(function(){
  972. var product_image = jQuery(this).text();
  973. if (product_image == "' . __('Use as featured image') . '") {
  974. jQuery(this).text("' . __('Use as Product Thumbnail', 'wpsc') . '");
  975. }
  976. });
  977. });
  978. </script>';
  979. }
  980. function wpsc_media_upload_tab_gallery( $tabs ) {
  981. unset( $tabs['gallery'] );
  982. $tabs['gallery'] = __( 'Product Image Gallery', 'wpsc' );
  983. return $tabs;
  984. }
  985. function wpsc_filter_delete_text( $translation, $text, $domain ) {
  986. if ( 'Delete' == $text && isset( $_REQUEST['post_id'] ) && isset( $_REQUEST["paren…

Large files files are truncated, but you can click here to view the full file