Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //You'll also need to include this library: http://undesigned.org.za/2007/10/22/amazon-s3-php-class
- //Show New Field in Admin
- add_action('foxyshop_admin_product_details','my_custom_file_download_link');
- function my_custom_file_download_link($post_id) {
- include "S3.php";
- define('S3_ACCESS_KEY_ID','xxxxxxxxxxxxx');
- define('S3_SECRET_ACCESS_KEY','xxxxxxxxxxxxxx');
- define('S3_URL','s3.amazonaws.com');
- define('S3_BUCKET','bucket_name');
- $_download_link = get_post_meta($post_id,'_download_link',1);
- $s3 = new S3(S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY);
- ?>
- <div style="clear:both;"></div>
- <div class="foxyshop_field_control">
- <?php
- //Get List of Assets From S3 Bucket
- $file_list = array();
- $s3 = new S3(S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY);
- if (($contents = $s3->getBucket(S3_BUCKET)) !== false) {
- foreach ($contents as $fileinfo) {
- $file_list[] = $fileinfo['name'];
- }
- }
- ?>
- <select name="_download_link" id="_download_link" style="max-width: 256px; margin-top: 6px;">
- <option value="">- - Selected File - -</option>
- <?php
- asort($file_list);
- foreach($file_list as $filename) {
- echo '<option value="'.$filename.'"' . ($_download_link == $filename ? ' selected="selected"' : "") . '>'.$filename.'</option>' . "\n";
- }
- ?>
- </select>
- </div>
- <div style="clear:both"></div>
- <?php
- }
- //Save New Field
- add_action('foxyshop_save_product','my_custom_file_download_link_save');
- function my_custom_file_download_link_save($post_id) {
- global $post_id, $wpdb;
- foxyshop_save_meta_data('_download_link', $_POST['_download_link']);
- //Sync with Self Hosted Script
- $table_prefix = "Foxy"; //UPDATE HERE IF YOU USED SOMETHING OTHER THAN "Foxy"
- //Get Values
- $product_code = $post_id;
- $product_name = get_the_title($post_id);
- $price = get_post_meta($post_id,'_price',1);
- $file_name = $_POST['_download_link'];
- $file_location = $_POST['_download_link'];
- // Check if the product already exists.
- $product_result = $wpdb->get_row("SELECT `product_id`, `product_code`, `file_location` FROM `" . $table_prefix . "Product` WHERE `product_code` = '$product_code';");
- // Edit existing.
- if ($product_result) {
- $query = "
- UPDATE `" . $table_prefix . "Product` SET
- product_name = '".mysql_real_escape_string($product_name)."',
- product_code = '".mysql_real_escape_string($product_code)."',
- price = '".mysql_real_escape_string($price)."',
- file_name = '".mysql_real_escape_string($file_name)."',
- file_location = '".mysql_real_escape_string($file_location)."'
- WHERE `product_code` = '$product_code';
- ";
- $wpdb->query($query);
- $output = "<div class=\"productRow\">» Updated <em>$product_name</em> ($product_code)</div>\n";
- // Add
- } else {
- // Add as new.
- $query = "
- INSERT INTO `" . $table_prefix . "Product` SET
- product_code = '".mysql_real_escape_string($product_code)."',
- product_name = '".mysql_real_escape_string($product_name)."',
- price = '".mysql_real_escape_string($price)."',
- file_name = '".mysql_real_escape_string($file_name)."',
- file_location = '".mysql_real_escape_string($file_location)."'
- ";
- $wpdb->query($query);
- $output = "<div class=\"productRow\">» Added <em>$product_name</em> ($product_code)</div>\n";
- }
- return $post_id;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement