PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/3.7.5 RC 2/wpsc-admin/display-debug.page.php

https://github.com/evadne/wp-e-commerce
PHP | 365 lines | 283 code | 57 blank | 25 comment | 34 complexity | 1df385674035124bd1401d50f71e7e83 MD5 | raw file
  1. <?php
  2. /**
  3. * WP eCommerce Debug page and functions
  4. *
  5. * This is debugging and unsafe updating code to debug or fix specific problems on some sites that is either not safe to run automatically or not usually needed
  6. * It is unwise to use anything on this page unless you know exactly what it will do and why you need to run it.
  7. *
  8. * @package wp-e-commerce
  9. * @since 3.7
  10. */
  11. function wpsc_debug_page() {
  12. global $wpdb;
  13. $fixpage = get_option('siteurl').'/wp-admin/admin.php?page=wpsc-sales-logs&amp;subpage=upgrade-purchase-logs';
  14. ?>
  15. <div class="wrap">
  16. <h2>Debugging Page</h2>
  17. <p>
  18. This is debugging and unsafe updating code to debug or fix specific problems on some sites that is either not safe to run automatically or not usually needed<br />
  19. It is unwise to use anything on this page unless you know exactly what it will do and why you need to run it.
  20. </p>
  21. <h4>Action List</h4>
  22. <ul>
  23. <li>
  24. <a href='?page=wpsc-debug&amp;wpsc_debug_action=download_links'>Update Download Links</a>
  25. </li>
  26. <li>
  27. <a href='?page=wpsc-debug&amp;wpsc_debug_action=images_reupload'>Image reassociate</a>
  28. </li>
  29. <li>
  30. <a href='?page=wpsc-debug&amp;wpsc_debug_action=product_url_names'>Clean Duplicate Product URL names</a>
  31. </li>
  32. <li>
  33. <a href='?page=wpsc-debug&amp;wpsc_debug_action=redo_product_url_names'>Redo Product URL names</a>
  34. </li>
  35. <li>
  36. <a href='?page=wpsc-debug&amp;wpsc_debug_action=test_copying_themes'>Copy Themes to New Theme Directory</a>
  37. </li>
  38. <li>
  39. <a href='?page=wpsc-debug&amp;wpsc_debug_action=resize_thumbnails'>Resize all Thumbnails and Clean Empty Image Records</a>
  40. </li>
  41. <li>
  42. <a href='?page=wpsc-debug&amp;wpsc_debug_action=filters'>Display filters</a>
  43. </li>
  44. <li>
  45. <a href='?page=wpsc-debug&amp;wpsc_debug_action=phpinfo'>Display phpinfo</a>
  46. </li>
  47. <li>
  48. <a href='<?php echo $fixpage; ?>'>Fix Purchaselogs</a>
  49. </li>
  50. </ul>
  51. <?php
  52. if (defined('WPSC_ADD_DEBUG_PAGE') && (constant('WPSC_ADD_DEBUG_PAGE') == true)) {
  53. ?>
  54. <h4>Development Code List</h4>
  55. <p> And this code is probably useless for anything other than working out how to write better code to do the same thing, unless you want to do that, leave it alone</p>
  56. <ul>
  57. <!-- <li>
  58. <a href='?page=wpsc-debug&amp;wpsc_debug_action=test_making_product_url_names'>Test Making Product URL Names</a>
  59. </li>-->
  60. <li>
  61. <a href='?page=wpsc-debug&amp;wpsc_debug_action=test_variation_grid'>Test Variation Grid</a>
  62. </li>
  63. <li>
  64. <a href='?page=wpsc-debug&amp;wpsc_debug_action=wp_get_object_terms'>Test wp_get_object_terms</a>
  65. </li>
  66. <li>
  67. <a href='?page=wpsc-debug&amp;wpsc_debug_action=create_also_bought_list'>Create also bought list</a>
  68. </li>
  69. <li>
  70. <a href='?page=wpsc-debug&amp;wpsc_debug_action=paypal_test'>Paypal Test</a>
  71. </li>
  72. </ul>
  73. <?php
  74. }
  75. ?>
  76. <pre style='font-family:\"Lucida Grande\",Verdana,Arial,\"Bitstream Vera Sans\",sans-serif; font-size:8px;'><?php
  77. switch($_GET['wpsc_debug_action']) {
  78. case 'download_links':
  79. wpsc_group_and_update_download_links();
  80. break;
  81. case 'product_url_names':
  82. wpsc_clean_product_url_names();
  83. break;
  84. case 'redo_product_url_names':
  85. wpsc_redo_product_url_names();
  86. break;
  87. case 'test_copying_themes':
  88. wpsc_test_copying_themes();
  89. break;
  90. case 'test_making_product_url_names':
  91. wpsc_test_making_product_url_names();
  92. break;
  93. case 'resize_thumbnails':
  94. wpsc_mass_resize_thumbnails_and_clean_images();
  95. break;
  96. case 'images_reupload':
  97. wpsc_update_image_records(true);
  98. break;
  99. case 'filters':
  100. global $wp_filter, $merged_filters;
  101. print_r($wp_filter);
  102. break;
  103. case 'phpinfo':
  104. echo "</pre>";
  105. phpinfo();
  106. echo "<pre style='font-family:\"Lucida Grande\",Verdana,Arial,\"Bitstream Vera Sans\",sans-serif; font-size:8px;'>";
  107. break;
  108. case 'wp_get_object_terms':
  109. global $wp_taxonomies;
  110. //register_taxonomy('product_tag', 'product');
  111. //print_r($wp_taxonomies);
  112. $tags = wp_get_object_terms(108, 'product_tag', array('fields' => 'names'));
  113. // wp_set_object_terms(103, $tags, 'product_tag');
  114. print_r($tags);
  115. break;
  116. case 'create_also_bought_list':
  117. // wpsc_populate_also_bought_list();
  118. break;
  119. case 'paypal_test':
  120. // wpsc_populate_also_bought_list();
  121. $fields = "cmd=_notify-validate&mc_gross=0.10&invoice=7121255557327&protection_eligibility=Ineligible&address_status=unconfirmed&item_number1=105&payer_id=LCFQDE4F5F6U8&tax=0.00&address_street=2+Offa+RdBedford&payment_date=14%3A56%3A02+Oct+14%2C+2009+PDT&payment_status=Completed&charset=windows-1252&mc_tax1=0.00&address_zip=&mc_shipping=0.00&mc_handling=0.00&first_name=Thomas&mc_fee=0.10&address_country_code=NZ&address_name=test+test&notify_version=2.8&custom=&payer_status=verified&business=dan%40instinct.co.nz&address_country=New+Zealand&num_cart_items=1&mc_handling1=0.00&address_city=Bedfordshire&verify_sign=AGu.hbwMxRXoqDiyy-IJNOnULnvNAKaQoywaGolyEFLHTSZiM-w0YWH4&payer_email=thomas.howard%40gmail.com&mc_shipping1=0.00&tax1=0.00&txn_id=5014962043916743K&payment_type=instant&last_name=Howard&address_state=&item_name1=m%27a%2Fn.d%2Fe%22l%24%7Ct%2Fe%28s%7Et%29%3A%3B+%C3%85%C3%84%C3%96&receiver_email=dan%40instinct.co.nz&payment_fee=&quantity1=1&receiver_id=LENKCHY6CU2VY&txn_type=cart&mc!
  122. _gross_1=0.10&mc_currency=NZD&residence_country=NZ&transaction_subject=Shopping+Cart&payment_gross=";
  123. $ch=curl_init();
  124. curl_setopt($ch, CURLOPT_URL, get_option('paypal_multiple_url'));
  125. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  126. curl_setopt($ch, CURLOPT_NOPROGRESS, 1);
  127. curl_setopt($ch, CURLOPT_VERBOSE, 1);
  128. curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
  129. curl_setopt($ch, CURLOPT_POST, 1);
  130. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  131. curl_setopt($ch, CURLOPT_TIMEOUT, 120);
  132. curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  133. // curl_setopt($ch, CURLOPT_REFERER, $referrer);
  134. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  135. $buffer = curl_exec($ch);
  136. curl_close($ch);
  137. echo $buffer;
  138. break;
  139. case 'test_variation_grid':
  140. $variations_processor = new nzshpcrt_variations;
  141. $product_data['id'] = 106;
  142. $output = $variations_processor->variations_grid_view($product_data['id']);
  143. echo "</pre>";
  144. echo $output;
  145. echo "<pre style='font-family:\"Lucida Grande\",Verdana,Arial,\"Bitstream Vera Sans\",sans-serif; font-size:8px;'>";
  146. break;
  147. }
  148. ?></pre>
  149. </div>
  150. <?php
  151. }
  152. function wpsc_test_copying_themes() {
  153. $old_theme_path = WPSC_FILE_PATH . "/themes/";
  154. $new_theme_path = WPSC_THEMES_PATH;
  155. $new_dir = @opendir($new_theme_path);
  156. $num = 0;
  157. $file_names = array();
  158. while(($file = @readdir($new_dir)) !== false) {
  159. if(is_dir($new_theme_path.$file) && ($file != "..") && ($file != ".")){
  160. $file_names[] = $file;
  161. }
  162. }
  163. if(count($file_names) < 1) {
  164. $old_dir = @opendir($old_theme_path);
  165. while(($file = @readdir($old_dir)) !== false) {
  166. if(is_dir($old_theme_path.$file) && ($file != "..") && ($file != ".")){
  167. $success = wpsc_recursive_copy($old_theme_path.$file, $new_theme_path.$file);
  168. echo "old_file:".$old_theme_path.$file."<br />";
  169. echo "new_file:".$new_theme_path.$file."<br />";
  170. echo "<pre>".print_r($success,true)."</pre>";
  171. }
  172. }
  173. }
  174. }
  175. function wpsc_group_and_update_download_links() {
  176. global $wpdb;
  177. $unique_file_names = $wpdb->get_col("SELECT DISTINCT `filename` FROM `".WPSC_TABLE_PRODUCT_FILES."`");
  178. foreach((array)$unique_file_names as $filename) {
  179. echo "$filename \n";
  180. $file_id_list = array();
  181. $file_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_FILES."` WHERE `filename` IN ('$filename')", ARRAY_A);
  182. foreach($file_data as $file_row) {
  183. $file_id_list[] = $file_row['id'];
  184. }
  185. $product_data = $wpdb->get_row("SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `file` IN ('".implode("', '", $file_id_list)."') AND `active` IN('1') ORDER BY `id` DESC LIMIT 1 ",ARRAY_A);
  186. $product_id = $product_data['id'];
  187. if($product_id > 0) {
  188. if($wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_FILES."` SET `product_id` = '{$product_id}' WHERE `id` IN ('".implode("', '", $file_id_list)."')")) {
  189. if($wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `product_id` = '{$product_id}' WHERE `fileid` IN ('".implode("', '", $file_id_list)."')")) {
  190. echo "$filename done \n";
  191. }
  192. }
  193. }
  194. }
  195. }
  196. /**
  197. * wpsc_clean_product_url_names, cleans dupicates
  198. */
  199. function wpsc_clean_product_url_names() {
  200. global $wpdb;
  201. $duplicated_meta_data = $wpdb->get_col("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN('url_name') GROUP BY `meta_value` HAVING COUNT(`meta_value`) > 1 ");
  202. $product_data = $wpdb->get_results("SELECT DISTINCT `products`.* FROM `".WPSC_TABLE_PRODUCTMETA."` AS `meta` LEFT JOIN `".WPSC_TABLE_PRODUCT_LIST."` AS `products` ON `meta`.`product_id` = `products`.`id` WHERE `meta`.`meta_key` IN('url_name') AND `meta`.`meta_value` IN('".implode("', '", $duplicated_meta_data)."') AND `products`.`active` = '1' ORDER BY `meta`.`meta_value` DESC", ARRAY_A);
  203. foreach((array)$product_data as $product_row) {
  204. if($product_row['name'] != '') {
  205. $tidied_name = strtolower(trim(stripslashes($product_row['name'])));
  206. $url_name = sanitize_title($tidied_name);
  207. $similar_names = $wpdb->get_row("SELECT COUNT(*) AS `count`, MAX(REPLACE(`meta_value`, '$url_name', '')) AS `max_number` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN ('url_name') AND `meta_value` REGEXP '^($url_name){1}[[:digit:]]*$' ",ARRAY_A);
  208. $extension_number = '';
  209. if($similar_names['count'] > 0) {
  210. $extension_number = (int)$similar_names['max_number']+1;
  211. }
  212. $url_name .= $extension_number;
  213. echo "{$product_row['name']} => {$url_name}\n\r";
  214. update_product_meta($product_row['id'], 'url_name', $url_name);
  215. }
  216. }
  217. }
  218. /**
  219. * wpsc_redo_product_url_names, deletes all product URL names, then remakes then
  220. */
  221. function wpsc_redo_product_url_names() {
  222. global $wpdb;
  223. $product_data = $wpdb->get_results("SELECT DISTINCT `products`.* FROM `".WPSC_TABLE_PRODUCTMETA."` AS `meta` LEFT JOIN `".WPSC_TABLE_PRODUCT_LIST."` AS `products` ON `meta`.`product_id` = `products`.`id` WHERE `products`.`active` = '1' ORDER BY `meta`.`meta_value` DESC", ARRAY_A);
  224. foreach((array)$product_data as $product_row) {
  225. $product_id = $product_row['id'];
  226. $post_data = $product_row;
  227. if($post_data['name'] != '') {
  228. $existing_name = get_product_meta($product_id, 'url_name');
  229. $tidied_name = strtolower(trim(stripslashes($post_data['name'])));
  230. $url_name = sanitize_title($tidied_name);
  231. $similar_names = (array)$wpdb->get_col("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `product_id` NOT IN('{$product_id}}') AND `meta_key` IN ('url_name') AND `meta_value` REGEXP '^(".$wpdb->escape(preg_quote($url_name))."){1}[[:digit:]]*$' ");
  232. echo "<strong>Product {$product_id}:</strong> {$product_row['name']}\n";
  233. echo "Current Name: {$existing_name}\n";
  234. echo "Originally Proposed Name: {$url_name}\n";
  235. if(array_search($url_name, $similar_names) !== false) {
  236. $i = 0;
  237. do {
  238. $i++;
  239. echo "Proposed Name No.$i: ".($url_name.$i)."\n";
  240. } while(array_search(($url_name.$i), $similar_names) !== false);
  241. $url_name .= $i;
  242. }
  243. echo "Accepted Name: {$url_name}\n";
  244. if($existing_name != $url_name) {
  245. update_product_meta($product_id, 'url_name', $url_name);
  246. }
  247. echo "\n";
  248. }
  249. }
  250. }
  251. function wpsc_recreate_product_url_names() {
  252. global $wpdb;
  253. $product_data = $wpdb->get_results("SELECT `id`, `name` FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `active` IN ('1')", ARRAY_A);
  254. //echo "<pre>".print_r($product_data,true)."</pre>";
  255. echo "<pre>";
  256. foreach($product_data as $product_row) {
  257. $product_id = $product_row['id'];
  258. $tidied_name = trim($product_row['name']);
  259. $tidied_name = strtolower($tidied_name);
  260. $url_name = sanitize_title($tidied_name);
  261. echo "<strong>Product {$product_id}:</strong> {$product_row['name']}\n";
  262. echo "Originally Proposed Name: {$url_name}\n";
  263. $similar_names = (array)$wpdb->get_col("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `product_id` NOT IN('{$product_id}}') AND `meta_key` IN ('url_name') AND `meta_value` REGEXP '^(".$wpdb->escape(preg_quote($url_name))."){1}[[:digit:]]*$' ");
  264. if(array_search($url_name, $similar_names) !== false) {
  265. // If it is, try to add a number to the end, if that is taken, try the next highest number...
  266. $i = 0;
  267. do {
  268. $i++;
  269. if($i > 100) {
  270. break;
  271. }
  272. echo "Proposed Name No.$i: ".($url_name.$i)."\n";
  273. } while(array_search(($url_name.$i), $similar_names) !== false);
  274. // Concatenate the first number found that wasn't taken
  275. $url_name .= $i;
  276. }
  277. echo "Accepted Name: {$url_name}\n";
  278. $existing_name = get_product_meta($product_id, 'url_name', true);
  279. if(is_array($existing_name )) {
  280. $existing_name = array_pop($existing_name);
  281. }
  282. if($existing_name != $url_name) {
  283. update_product_meta($product_id, 'url_name', $url_name);
  284. }
  285. echo "\n\n\n";
  286. }
  287. }
  288. function wpsc_mass_resize_thumbnails_and_clean_images(){
  289. global $wpdb;
  290. $height = get_option('product_image_height');
  291. $width = get_option('product_image_width');
  292. $product_data = $wpdb->get_results("SELECT `product`.`id`, `product`.`image` AS `image_id`, `images`.`image` AS `file` FROM `".WPSC_TABLE_PRODUCT_LIST."` AS `product` INNER JOIN `".WPSC_TABLE_PRODUCT_IMAGES."` AS `images` ON `product`.`image` = `images`.`id` WHERE `product`.`image` > 0 ",ARRAY_A);
  293. //print_r($product_data);
  294. foreach((array)$product_data as $product) {
  295. $image_input = WPSC_IMAGE_DIR . $product['file'];
  296. $image_output = WPSC_THUMBNAIL_DIR . $product['file'];
  297. if(($product['file'] != '') and file_exists($image_input)) {
  298. image_processing($image_input, $image_output, $width, $height);
  299. update_product_meta($product['id'], 'thumbnail_width', $width);
  300. update_product_meta($product['id'], 'thumbnail_height', $height);
  301. } else {
  302. $wpdb->query("DELETE FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `id` IN('{$product['image_id']}') LIMIT 1");
  303. $wpdb->query("UPDATE `".WPSC_TABLE_PRODUCT_LIST."` SET `image` = NULL WHERE `id` = '".$product['id']."' LIMIT 1");
  304. }
  305. }
  306. $wpdb->query("DELETE FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` IN('0')");
  307. }
  308. ?>