Advertisement
Guest User

thecartpress1.9.1.1

a guest
May 11th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.62 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: TheCartPress
  4. Plugin URI: http://thecartpress.com
  5. Description: TheCartPress (Multi language support)
  6. Version: 1.1.9.1
  7. Author: TheCartPress team
  8. Author URI: http://thecartpress.com
  9. License: GPL
  10. Parent: thecartpress
  11. */
  12.  
  13. /**
  14. * This file is part of TheCartPress.
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29.  
  30. define( 'TCP_FOLDER' , dirname( __FILE__ ) . '/' );
  31. define( 'TCP_ADMIN_FOLDER' , TCP_FOLDER . 'admin/' );
  32. define( 'TCP_CLASSES_FOLDER' , TCP_FOLDER . 'classes/' );
  33. define( 'TCP_TEMPLATES_FOLDER' , TCP_FOLDER . 'templates/' );
  34. define( 'TCP_DAOS_FOLDER' , TCP_FOLDER . 'daos/' );
  35. define( 'TCP_WIDGETS_FOLDER' , TCP_FOLDER . 'widgets/' );
  36. define( 'TCP_METABOXES_FOLDER' , TCP_FOLDER . 'metaboxes/' );
  37. define( 'TCP_SHORTCODES_FOLDER' , TCP_FOLDER . 'shortcodes/' );
  38. define( 'TCP_PLUGINS_FOLDER' , TCP_FOLDER . 'plugins/' );
  39. define( 'TCP_CHECKOUT_FOLDER' , TCP_FOLDER . 'checkout/' );
  40. define( 'TCP_CUSTOM_POST_TYPE_FOLDER' , TCP_FOLDER . 'customposttypes/' );
  41. define( 'TCP_THEMES_TEMPLATES_FOLDER' , TCP_FOLDER . 'themes-templates/' );
  42. define( 'TCP_ADMIN_PATH' , 'admin.php?page=' . plugin_basename( TCP_FOLDER ) . '/admin/' );
  43.  
  44. class TheCartPress {
  45.  
  46. public $settings = array();
  47. private $saleable_post_types = array();
  48.  
  49. function wp_head() { //Shopping Cart actions
  50. if ( isset( $_REQUEST['tcp_add_to_shopping_cart'] ) ) {
  51. unset( $_REQUEST['tcp_add_to_shopping_cart'] );
  52. if ( ! isset( $_REQUEST['tcp_post_id'] ) ) return;
  53. $shoppingCart = TheCartPress::getShoppingCart();
  54. do_action( 'tcp_before_add_shopping_cart', $_REQUEST['tcp_post_id'] );
  55. for( $i = 0; $i < count( $_REQUEST['tcp_post_id'] ); $i++ ) {
  56. $count = isset( $_REQUEST['tcp_count'][$i] ) ? (int)$_REQUEST['tcp_count'][$i] : 0;
  57. if ( $count > 0 ) {
  58. $post_id = isset( $_REQUEST['tcp_post_id'][$i] ) ? $_REQUEST['tcp_post_id'][$i] : 0;
  59. $post_id = tcp_get_default_id( $post_id, get_post_type( $post_id ) );
  60. $tcp_option_id = isset( $_REQUEST['tcp_option_id'][$i] ) ? $_REQUEST['tcp_option_id'][$i] : 0;
  61. if ( $tcp_option_id > 0 ) {
  62. $option_ids = explode( '-', $tcp_option_id);
  63. if ( count( $option_ids ) == 2 ) {
  64. $option_1_id = $option_ids[0];
  65. $price_1 = tcp_get_the_price( $option_1_id );
  66. $weight_1 = tcp_get_the_weight( $option_1_id );
  67. $option_2_id = $option_ids[1];
  68. $price_2 = tcp_get_the_price( $option_2_id );
  69. $weight_2 = tcp_get_the_weight( $option_2_id );
  70. } else {
  71. $option_1_id = $tcp_option_id;
  72. $price_1 = tcp_get_the_price( $option_1_id );
  73. $weight_1 = tcp_get_the_weight( $option_1_id );
  74. $option_2_id = '0';
  75. $price_2 = 0;
  76. $weight_2 = 0;
  77. }
  78. } else {
  79. $option_1_id = isset( $_REQUEST['tcp_option_1_id'][$i] ) ? $_REQUEST['tcp_option_1_id'][$i] : 0;
  80. if ( $option_1_id > 0 ) {
  81. $price_1 = tcp_get_the_price( $option_1_id );
  82. $weight_1 = tcp_get_the_weight( $option_1_id );
  83. $option_2_id = isset( $_REQUEST['tcp_option_2_id'][$i] ) ? $_REQUEST['tcp_option_2_id'][$i] : 0;
  84. if ( $option_2_id > 0 ) {
  85. $price_2 = tcp_get_the_price( $option_2_id );
  86. $weight_2 = tcp_get_the_weight( $option_2_id );
  87. } else {
  88. $price_2 = 0;
  89. $weight_2 = 0;
  90. }
  91. } else {
  92. $price_1 = 0;
  93. $weight_1 = 0;
  94. $option_2_id = 0;
  95. $price_2 = 0;
  96. $weight_2 = 0;
  97. }
  98. }
  99. $unit_price = tcp_get_the_price( $post_id );
  100. $unit_price += $price_1 + $price_2;
  101. $unit_price = apply_filters( 'tcp_price_to_add_to_shoppingcart', $unit_price, $post_id );
  102. if ( $weight_2 > 0 ) $unit_weight = $weight_2;
  103. elseif ( $weight_1 > 0 ) $unit_weight = $weight_1;
  104. else $unit_weight = tcp_get_the_weight( $post_id );
  105. ////$unit_weight = tcp_get_the_weight( $post_id ) + $weight_1 + $weight_2;
  106. $args = compact( 'i', 'post_id', 'count', 'unit_price', 'unit_weight' );
  107. $args = apply_filters( 'tcp_add_item_shopping_cart', $args );
  108. extract( $args );
  109. $shoppingCart->add( $post_id, $option_1_id, $option_2_id, $count, $unit_price, $unit_weight );
  110. }
  111. }
  112. do_action( 'tcp_add_shopping_cart', $_REQUEST['tcp_post_id'] );
  113. } elseif ( isset( $_REQUEST['tcp_delete_shopping_cart'] ) ) {
  114. do_action( 'tcp_before_delete_shopping_cart' );
  115. TheCartPress::removeShoppingCart();
  116. do_action( 'tcp_delete_shopping_cart' );
  117. } elseif ( isset( $_REQUEST['tcp_delete_item_shopping_cart'] ) ) {
  118. $post_id = isset( $_REQUEST['tcp_post_id'] ) ? $_REQUEST['tcp_post_id'] : 0;
  119. do_action( 'tcp_before_delete_item_shopping_cart', $post_id );
  120. if ( $post_id > 0 ) {
  121. $option_1_id = isset( $_REQUEST['tcp_option_1_id'] ) ? $_REQUEST['tcp_option_1_id'] : 0;
  122. $option_2_id = isset( $_REQUEST['tcp_option_2_id'] ) ? $_REQUEST['tcp_option_2_id'] : 0;
  123. $shoppingCart = TheCartPress::getShoppingCart();
  124. $shoppingCart->delete( $post_id, $option_1_id, $option_2_id );
  125. do_action( 'tcp_delete_item_shopping_cart', $post_id );
  126. }
  127. } elseif ( isset( $_REQUEST['tcp_modify_item_shopping_cart'] ) ) {
  128. $post_id = $_REQUEST['tcp_post_id'] ? $_REQUEST['tcp_post_id'] : 0;
  129. do_action( 'tcp_before_modify_shopping_cart', $post_id );
  130. if ( $post_id > 0 ) {
  131. $option_1_id = isset( $_REQUEST['tcp_option_1_id'] ) ? $_REQUEST['tcp_option_1_id'] : 0;
  132. $option_2_id = isset( $_REQUEST['tcp_option_2_id'] ) ? $_REQUEST['tcp_option_2_id'] : 0;
  133. $count = isset( $_REQUEST['tcp_count'] ) ? (int)$_REQUEST['tcp_count'] : 0;
  134. $shoppingCart = TheCartPress::getShoppingCart();
  135. $shoppingCart->modify( $post_id, $option_1_id, $option_2_id, $count );
  136. do_action( 'tcp_modify_shopping_cart', $post_id );
  137. }
  138. }
  139. }
  140.  
  141. function annotate_last_visited() {
  142. if ( is_single() && ! is_page() ) {
  143. global $post;
  144. if ( tcp_is_saleable_post_type( $post->post_type ) ) {
  145. do_action( 'tcp_visited_product', $post );
  146. $shoppingCart = TheCartPress::getShoppingCart();
  147. $shoppingCart->addVisitedPost( $post->ID );
  148. }
  149. }
  150. }
  151.  
  152. static function getShoppingCart() {
  153. if ( ! session_id() ) session_start();
  154. global $tcp_shoppingCart;
  155. if ( $tcp_shoppingCart ) return $tcp_shoppingCart;
  156.  
  157. if ( isset( $_SESSION['tcp_session'] ) ) {
  158. if ( is_string( $_SESSION['tcp_session'] ) ) $tcp_shoppingCart = unserialize( $_SESSION['tcp_session'] );
  159. else $tcp_shoppingCart = $_SESSION['tcp_session'];
  160. }
  161. if ( ! $tcp_shoppingCart ) {
  162. $tcp_shoppingCart = new ShoppingCart();
  163. $_SESSION['tcp_session'] = serialize( $tcp_shoppingCart );
  164. }
  165. return $tcp_shoppingCart;
  166. }
  167.  
  168. static function removeShoppingCart() {
  169. $shoppingCart = TheCartPress::getShoppingCart();
  170. if ( $shoppingCart ) $shoppingCart->deleteAll();
  171. }
  172.  
  173. static function saveShoppingCart() {
  174. global $tcp_shoppingCart;
  175. $_SESSION['tcp_session'] = serialize( $tcp_shoppingCart );
  176. }
  177.  
  178. /**
  179. * Returns the value of the setting indexed by $setting_name
  180. * @param string $setting_name
  181. * @param mixed $default_value
  182. * @return the setting indexed by $setting_name, if not value found, $default_value will be returned
  183. * @since 1.1.6
  184. */
  185. public function get_setting( $setting_name, $default_value = false ) {
  186. $value = isset( $this->settings[$setting_name] ) ? $this->settings[$setting_name ] : $default_value;
  187. if ( strlen( $value ) == 0 && $default_value ) $value = $default_value;
  188. $value = apply_filters( 'tcp_get_setting', $value, $setting_name, $default_value );
  189. return $value;
  190. }
  191.  
  192. /**
  193. * Checks the plugin
  194. */
  195. function admin_notices() {
  196. $warnings = array();
  197. $page_id = get_option( 'tcp_shopping_cart_page_id' );
  198. if ( ! $page_id || ! get_page( $page_id ) )
  199. $warnings[] = __( 'The <strong>Shopping Cart page</strong> has been deleted.', 'tcp' );
  200. $page_id = get_option( 'tcp_checkout_page_id' );
  201. if ( ! $page_id || ! get_page( $page_id ) )
  202. $warnings[] = __( 'The <strong>Checkout page</strong> has been deleted.', 'tcp' );
  203. $page_id = get_option( 'tcp_checkout_page_id' );
  204. //if ( ! $page_id || ! get_page( $page_id ) )
  205. // $warnings[] = __( 'The <strong>Catalog page</strong> has been deleted.', 'tcp' );
  206. $warnings = apply_filters( 'tcp_check_the_plugin', $warnings );
  207. if ( count( $warnings ) > 0 ) :
  208. $checking_path = TCP_ADMIN_PATH . 'Checking.php'; ?>
  209. <div id="message_checking_error" class="error"><p>
  210. <?php _e( 'Notice:', 'tcp' ); ?><br />
  211. <?php foreach( $warnings as $warning ) : ?>
  212. <?php echo $warning; ?><br/>
  213. <?php endforeach; ?></p>
  214. <p><?php printf( __( 'Visit the <a href="%s">Checking page</a> to fix those warnings.', 'tcp' ), $checking_path ); ?></p>
  215. </div>
  216. <?php endif;
  217. }
  218.  
  219. function request( $query ) {
  220. if ( is_admin() || ( is_array( $query ) && count( $query ) == 0 ) ) return $query;
  221. $wp_query = new WP_Query();
  222. $wp_query->parse_query( $query );
  223. if ( $wp_query->is_category() || $wp_query->is_tag() ) return $query;
  224.  
  225. $apply_filters = false;
  226. $apply_filters_for_saleables = false;
  227. //if ( $wp_query->is_front_page() || $wp_query->is_home() || isset( $wp_query->tax_query ) || $wp_query->is_archive() ) {
  228. if ( $wp_query->is_front_page() || $wp_query->is_home() ) {
  229. global $thecartpress;
  230. $activate_frontpage = $thecartpress->get_setting( 'activate_frontpage' );
  231. if ( ! $activate_frontpage ) return $query;
  232. $apply_filters = true;
  233. $taxonomy_term = $thecartpress->get_setting( 'taxonomy_term', '' );
  234. if ( strlen( $taxonomy_term ) > 0 ) {
  235. $taxonomy_term = explode( ':', $taxonomy_term );
  236. $query[$taxonomy_term[0]] = $taxonomy_term[1];
  237. }
  238. }
  239. if ( isset( $wp_query->tax_query ) ) {
  240. foreach ( $wp_query->tax_query->queries as $tax_query ) { //@See Query.php: 1530
  241. if ( tcp_is_saleable_taxonomy( $tax_query['taxonomy'] ) ) {
  242. $apply_filters = true;
  243. $apply_filters_for_saleables = true;
  244. break;
  245. }
  246. }
  247. }
  248. if ( $wp_query->is_archive() && isset( $wp_query->query_vars['post_type'] ) && tcp_is_saleable_post_type( $wp_query->query_vars['post_type'] ) ) {
  249. $apply_filters = true;
  250. $apply_filters_for_saleables = true;
  251. }
  252. //}
  253. if ( $apply_filters_for_saleables || ( $apply_filters && isset( $wp_query->query_vars['post_type'] ) && tcp_is_saleable_post_type( $wp_query->query_vars['post_type'] ) ) ) {
  254. $query['meta_query'][] = array(
  255. 'key' => 'tcp_is_visible',
  256. 'value' => 1,
  257. 'type' => 'NUMERIC',
  258. 'compare' => '='
  259. );
  260. $query = apply_filters( 'tcp_apply_filters_for_saleables', $query, $wp_query );
  261. }
  262. $filter = new TCPFilterNavigation();
  263. if ( $apply_filters && $apply_filters_for_saleables ) {
  264. //if ( isset( $wp_query->query_vars['post_type'] ) && tcp_is_saleable_post_type( $wp_query->query_vars['post_type'] ) ) {
  265. $query['posts_per_page'] = (int)$this->get_setting( 'products_per_page', 10 );
  266. if ( $filter->is_filter_by_layered() ) {
  267. $layered = $filter->get_layered();
  268. foreach( $layered as $tax => $layers ) {
  269. $query[$tax] = '';
  270. foreach( $layers as $layer ) {
  271. $query[$tax] .= $layer . ',';
  272. }
  273. }
  274. }
  275. if ( $filter->is_filter_by_price_range() ) {
  276. $query['meta_query'][] = array(
  277. 'key' => 'tcp_price',
  278. 'value' => array( $filter->get_min_price(), $filter->get_max_price() ),
  279. 'type' => 'NUMERIC',
  280. 'compare' => 'BETWEEN'
  281. );
  282. }
  283. //}
  284. }
  285. if ( isset( $wp_query->tax_query ) || $wp_query->is_archive() ) {
  286. if ( $filter->get_order_type() == 'price' ) {
  287. $query['orderby'] = 'meta_value_num';
  288. $query['meta_key'] = 'tcp_price';
  289. } elseif ( $filter->get_order_type() == 'order' ) {
  290. $query['orderby'] = 'meta_value_num';
  291. $query['meta_key'] = 'tcp_order';
  292. } else {
  293. $query['orderby'] = $filter->get_order_type();
  294. }
  295. $query['order'] = $filter->get_order_desc();
  296. }
  297. $query['order'] = $filter->get_order_desc();
  298. $query = apply_filters( 'tcp_sort_main_loop', $query, $filter->get_order_type(), $filter->get_order_desc() );
  299. return $query;
  300. }
  301.  
  302. function get_pagenum_link( $result ) {
  303. if ( isset( $_REQUEST['tcp_order_by'] ) ) {
  304. $order_type = isset( $_REQUEST['tcp_order_type'] ) ? $_REQUEST['tcp_order_type'] : 'order';
  305. $order_desc = isset( $_REQUEST['tcp_order_desc'] ) ? $_REQUEST['tcp_order_desc'] : 'asc';
  306. $result = add_query_arg( 'tcp_order_type', $order_type, $result );
  307. $result = add_query_arg( 'tcp_order_desc', $order_desc, $result );
  308. }
  309. return $result;
  310. }
  311.  
  312. function posts_request( $input ) {
  313. /*echo '<br>SELECT: ', $input;
  314. /*global $wpdb;
  315. $res = $wpdb->get_results( $input );
  316. echo '<br>RES=', count( $res ), '<br>';*/
  317. return $input;
  318. }
  319.  
  320. function loginFormBottom( $content ) {
  321. return '<p class="login-lostpassword"><a href="'. wp_lostpassword_url( get_permalink() ) . '" title="' . __( 'Lost Password', 'tcp' ) . '">' . __( 'Lost Password', 'tcp' ) . '</a></p>';
  322. }
  323.  
  324. function shortCodeBuyButton( $atts ) {
  325. extract( shortcode_atts( array( 'post_id' => 0 ), $atts ) );
  326. return tcp_get_the_buy_button( $post_id );
  327. }
  328.  
  329. function shortCodePrice( $atts ) {
  330. extract( shortcode_atts( array( 'post_id' => 0 ), $atts ) );
  331. return tcp_get_the_price_label( $post_id );
  332. }
  333.  
  334. /**
  335. * Runs when a user is registered (or created) before email
  336. */
  337. function user_register( $user_id ) {
  338. $user = new WP_User( $user_id );
  339. $user->set_role( 'customer' );
  340. }
  341.  
  342. function wp_dashboard_setup() {
  343. $disable_ecommerce = $this->get_setting( 'disable_ecommerce' );
  344. if ( ! $disable_ecommerce ) {
  345. require_once( TCP_WIDGETS_FOLDER . 'OrdersSummaryDashboard.class.php' );
  346. require_once( TCP_WIDGETS_FOLDER . 'SalesChartDashboard.class.php' );
  347. }
  348. global $wp_meta_boxes;
  349. $normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
  350. $tcp_orders_resume = array( 'tcp_orders_resume' => $normal_dashboard['tcp_orders_resume']);
  351. unset( $normal_dashboard['tcp_orders_resume'] );
  352. $sorted_dashboard = array_merge( $tcp_orders_resume, $normal_dashboard);
  353. $wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
  354. }
  355.  
  356. function widgets_init() {
  357. require_once( TCP_WIDGETS_FOLDER . 'manage_widgets.php' );
  358. }
  359.  
  360. function get_base() {
  361. $base = TCP_ADMIN_FOLDER . 'OrdersListTable.php';
  362. return $base;
  363. }
  364.  
  365. function get_base_tools() {
  366. $base = TCP_ADMIN_FOLDER . 'ShortCodeGenerator.php';
  367. return $base;
  368. }
  369.  
  370. function admin_menu() {
  371. $base = $this->get_base();
  372. $disable_ecommerce = $this->get_setting( 'disable_ecommerce' );
  373. if ( ! $disable_ecommerce ) {
  374. add_menu_page( '', 'theCartPress', 'tcp_read_orders', $base, '', plugins_url( '/images/tcp.png', __FILE__ ), 40 );
  375. add_submenu_page( $base, __( 'Orders', 'tcp' ), __( 'Orders', 'tcp' ), 'tcp_read_orders', $base );
  376. add_submenu_page( $base, __( 'First time setup', 'tcp' ), __( 'First time setup', 'tcp' ), 'tcp_edit_settings', TCP_ADMIN_FOLDER . 'FirstTimeSetUp.php' );
  377. add_submenu_page( $base, __( 'Taxes', 'tcp' ), __( 'Taxes', 'tcp' ), 'tcp_edit_taxes', TCP_ADMIN_FOLDER . 'TaxesList.php' );
  378. //add_submenu_page( $base, __( 'Taxes Rates', 'tcp' ), __( 'Taxes Rates', 'tcp' ), 'tcp_edit_taxes', TCP_ADMIN_FOLDER . 'TaxesRates.php' );
  379. add_submenu_page( $base, __( 'Payment methods', 'tcp' ), __( 'Payment methods', 'tcp' ), 'tcp_edit_plugins', TCP_ADMIN_FOLDER . 'PluginsList.php' );
  380. add_submenu_page( $base, __( 'Shipping methods', 'tcp' ), __( 'Shipping methods', 'tcp' ), 'tcp_edit_plugins', TCP_ADMIN_FOLDER . 'PluginsListShipping.php' );
  381. add_submenu_page( $base, __( 'Notices, eMails', 'tcp' ), __( 'Notices, eMails', 'tcp' ), 'tcp_edit_orders', 'edit.php?post_type=tcp_template' );
  382. add_submenu_page( $base, __( 'Addresses', 'tcp' ), __( 'Addresses', 'tcp' ), 'tcp_edit_addresses', TCP_ADMIN_FOLDER . 'AddressesList.php' );
  383. $hide_downloadable_menu = $this->get_setting( 'hide_downloadable_menu' );
  384. if ( ! $hide_downloadable_menu ) add_submenu_page( $base, __( 'My Downloads', 'tcp' ), __( 'My Downloads', 'tcp' ), 'tcp_downloadable_products', TCP_ADMIN_FOLDER . 'DownloadableList.php' );
  385. //registered pages
  386. add_submenu_page( 'tcpm', __( 'Order', 'tcp' ), __( 'Order', 'tcp' ), 'tcp_edit_orders', TCP_ADMIN_FOLDER . 'OrderEdit.php' );
  387. add_submenu_page( 'tcpm', __( 'list of Assigned products', 'tcp' ), __( 'list of Assigned products', 'tcp' ), 'tcp_edit_product', TCP_ADMIN_FOLDER . 'AssignedProductsList.php' );
  388. add_submenu_page( 'tcpm', __( 'list of Assigned categories', 'tcp' ), __( 'list of Assigned categories', 'tcp' ), 'tcp_edit_product', TCP_ADMIN_FOLDER . 'AssignedCategoriesList.php' );
  389. add_submenu_page( 'tcpm', __( 'Plugin editor', 'tcp' ), __( 'Plugin editor', 'tcp' ), 'tcp_edit_plugins', TCP_ADMIN_FOLDER . 'PluginEdit.php' );
  390. add_submenu_page( 'tcpm', __( 'Address editor', 'tcp' ), __( 'Address editor', 'tcp' ), 'tcp_edit_addresses', TCP_ADMIN_FOLDER . 'AddressEdit.php' );
  391. add_submenu_page( 'tcpm', __( 'Upload files', 'tcp' ), __( 'Upload files', 'tcp' ), 'tcp_edit_product', TCP_ADMIN_FOLDER . 'UploadFiles.php' );
  392. add_submenu_page( 'tcpm', __( 'Files', 'tcp' ), __( 'Files', 'tcp' ), 'tcp_edit_product', TCP_ADMIN_FOLDER . 'FilesList.php' );
  393. add_submenu_page( 'tcpm', __( 'Downloadable products', 'tcp' ), __( 'Downloadable products', 'tcp' ), 'tcp_downloadable_products', TCP_ADMIN_FOLDER . 'VirtualProductDownloader.php' );
  394. add_submenu_page( 'tcpm', __( 'TheCartPress checking', 'tcp' ), __( 'TheCartPress checking', 'tcp' ), 'tcp_edit_products', TCP_ADMIN_FOLDER . 'Checking.php' );
  395. }
  396. $base = $this->get_base_tools();
  397. add_menu_page( '', __( 'TCP tools', 'tcp' ), 'tcp_edit_products', $base, '', plugins_url( '/images/tcp.png', __FILE__ ), 41 );
  398. add_submenu_page( $base, __( 'Shortcodes Generator', 'tcp' ), __( 'Shortcodes', 'tcp' ), 'tcp_shortcode_generator', $base );
  399. if ( ! $disable_ecommerce ) {
  400. add_submenu_page( $base, __( 'Related Categories', 'tcp' ), __( 'Related Categories', 'tcp' ), 'tcp_edit_products', TCP_ADMIN_FOLDER . 'RelatedCats.php' );
  401. add_submenu_page( $base, __( 'Checkout Editor', 'tcp' ), __( 'Checkout Editor', 'tcp' ), 'tcp_checkout_editor', TCP_CHECKOUT_FOLDER . 'CheckoutEditor.php' );
  402. add_submenu_page( $base, __( 'Update Prices', 'tcp' ), __( 'Update Prices', 'tcp' ), 'tcp_update_price', TCP_ADMIN_FOLDER . 'PriceUpdate.php' );
  403. }
  404. add_submenu_page( $base, __( 'Manage post types', 'tcp' ), __( 'Manage post types', 'tcp' ), 'manage_options', TCP_ADMIN_FOLDER . 'PostTypeList.php' );
  405. add_submenu_page( $base, __( 'Manage taxonomies', 'tcp' ), __( 'Manage taxonomies', 'tcp' ), 'manage_options', TCP_ADMIN_FOLDER . 'TaxonomyList.php' );
  406. add_submenu_page( $base, __( 'Admin Bar Config', 'tcp' ), __( 'Admin Bar Config', 'tcp' ), 'tcp_edit_products', TCP_ADMIN_FOLDER . 'AdminBarConfig.php' );
  407. //register pages
  408. add_submenu_page( 'tcp', __( 'Post Type Editor', 'tcp' ), __( 'Post Type Editor', 'tcp' ), 'manage_options', TCP_ADMIN_FOLDER . 'PostTypeEdit.php' );
  409. add_submenu_page( 'tcp', __( 'Taxonomy Editor', 'tcp' ), __( 'Taxonomy Editor', 'tcp' ), 'manage_options', TCP_ADMIN_FOLDER . 'TaxonomyEdit.php' );
  410. //add_submenu_page( 'tcpm', __( 'Print Order', 'tcp' ), __( 'Print Order', 'tcp' ), 'tcp_edit_orders', TCP_ADMIN_FOLDER . 'PrintOrder.php' );
  411. }
  412.  
  413. function the_content( $content ) {
  414. if ( is_single() ) {
  415. global $post;
  416. if ( ! tcp_is_saleable_post_type( $post->post_type ) ) return $content;
  417. $see_buy_button_in_content = $this->get_setting( 'see_buy_button_in_content', true );
  418. $align_buy_button_in_content= $this->get_setting( 'align_buy_button_in_content', 'north' );
  419. $see_price_in_content = $this->get_setting( 'see_price_in_content' );
  420. if ( ! function_exists( 'has_post_thumbnail' ) ) $see_image_in_content = false;
  421. else $see_image_in_content = $this->get_setting( 'see_image_in_content' );
  422. $html = '';
  423. if ( $see_buy_button_in_content ) {
  424. $html = tcp_the_buy_button( $post->ID, false );
  425. } elseif ( $see_price_in_content ) {
  426. $html = '<p id="tcp_price_post-' . $post->ID . '">' . tcp_get_the_price_label( $post->ID ) . '</p>';
  427. }
  428. if ( $see_image_in_content ) {
  429. $image_align = $this->get_setting( 'image_align_content', '' );
  430. $args = array(
  431. 'size' => $this->get_setting( 'image_size_content', 'thumbnail' ),
  432. 'align' => $image_align,
  433. 'link' => $this->get_setting( 'image_link_content', 'permalink' ),
  434. );
  435. $image = tcp_get_the_thumbnail_with_permalink( $post->ID, $args, false );
  436. $image = apply_filters( 'tcp_get_image_in_content', $image, $post->ID, $args );
  437. $thumbnail_post = get_post( $thumbnail_id );
  438. if ( ! empty( $thumbnail_post->post_excerpt ) ) {
  439. $width = $image_attributes[1];
  440. $image = '[caption id="attachment_' . $thumbnail_id . '" align="' . $image_align . ' tcp_featured_single_caption" width="' . $width . '" caption="' . $thumbnail_post->post_excerpt . '"]' . $image . '[/caption]';
  441. }
  442. $content = $image . $content;
  443. }
  444. $html = apply_filters( 'tcp_filter_content', $html, $post->ID );
  445. if ( $align_buy_button_in_content == 'north' ) {
  446. return $html . do_shortcode( $content );
  447. } else {
  448. return do_shortcode( $content ) . $html;
  449. }
  450. }
  451. return $content;
  452. }
  453.  
  454. function the_excerpt( $content ) {
  455. if ( ! is_single() ) {
  456. global $post;
  457. if ( ! tcp_is_saleable_post_type( $post->post_type ) ) return $content;
  458. $use_default_loop = $this->get_setting( 'use_default_loop', 'only_settings' );
  459. if ( $use_default_loop != 'none' ) return $content;
  460. $see_buy_button_in_excerpt = $this->get_setting( 'see_buy_button_in_excerpt' );
  461. $align_buy_button_in_excerpt= $this->get_setting( 'align_buy_button_in_excerpt', 'north' );
  462. $see_price_in_excerpt = $this->get_setting( 'see_price_in_excerpt', true );
  463. if ( ! function_exists( 'has_post_thumbnail' ) )
  464. $see_image_in_excerpt = false;
  465. else
  466. $see_image_in_excerpt = $this->get_setting( 'see_image_in_excerpt' );
  467. $html = '';
  468. if ( $see_buy_button_in_excerpt ) {
  469. $html .= tcp_the_buy_button( $post->ID, false );
  470. } elseif ( $see_price_in_excerpt ) {
  471. $html .= '<p id="tcp_price_post-' . $post->ID . '">' . tcp_get_the_price_label( $post->ID ) . '</p>';
  472. }
  473. if ( $see_image_in_excerpt && has_post_thumbnail( $post->ID ) ) {
  474. $image_size = $this->get_setting( 'image_size_excerpt', 'thumbnail' );
  475. $image_align = $this->get_setting( 'image_align_excerpt', '' );
  476. $image_link = $this->get_setting( 'image_link_excerpt', '' );
  477. $thumbnail_id = get_post_thumbnail_id( $post->ID );
  478. $attr = array( 'class' => $image_align . ' size-' . $image_size . ' wp-image-' . $thumbnail_id . ' tcp_single_img_featured tcp_thumbnail_' . $post->ID );
  479. //$image_attributes = array{0 => url, 1 => width, 2 => height};
  480. $image_attributes = wp_get_attachment_image_src( $thumbnail_id, $image_size );
  481. if ( strlen( $image_link ) > 0 ) {
  482. if ( $image_link == 'file' ) {
  483. $href = $image_attributes[0];
  484. } else {
  485. $href = get_permalink( $thumbnail_id );
  486. }
  487. $image = '<a href="' . $href . '">' . get_the_post_thumbnail( $post->ID, $image_size, $attr ) . '</a>';
  488. } else {
  489. $image = get_the_post_thumbnail( $post->ID, $image_size, $attr );
  490. }
  491. $thumbnail_post = get_post( $thumbnail_id );
  492. $image = apply_filters( 'tcp_get_image_in_excerpt', $image, $post->ID );
  493. if ( ! empty( $thumbnail_post->post_excerpt ) ) {
  494. //$image_attributes = array{0 => url, 1 => width, 2 => height};
  495. $image_attributes = wp_get_attachment_image_src( $thumbnail_id, $image_size );
  496. $width = $image_attributes[1];
  497. $image = '[caption id="attachment_' . $thumbnail_id . '" align="' . $image_align . ' tcp_featured_single_caption" width="' . $width . '" caption="' . $thumbnail_post->post_excerpt . '"]' . $image . '[/caption]';
  498. }
  499. $content = $image . $content;//$html .= $image;
  500. }
  501. $html = apply_filters( 'tcp_filter_excerpt', $html, $post->ID );
  502. if ( $align_buy_button_in_excerpt == 'north' )
  503. return do_shortcode( $html . $content );
  504. else
  505. return do_shortcode( $content . $html );
  506. }
  507. return $content;
  508. }
  509.  
  510. function tcp_checkout_steps_save() {
  511. $steps = $_REQUEST['list'];
  512. $steps = explode( ',', $steps );
  513. require_once( TCP_CHECKOUT_FOLDER .'TCPCheckoutManager.class.php' );
  514. TCPCheckoutManager::update_steps( $steps );
  515. }
  516.  
  517. function loading_default_checkout_boxes() {
  518. if ( is_admin() ) {
  519. add_action( 'wp_ajax_tcp_checkout_steps_save', array( &$this, 'tcp_checkout_steps_save' ) );
  520. }
  521. tcp_register_checkout_box( 'thecartpress/checkout/TCPBillingExBox.class.php', 'TCPBillingExBox' );
  522. tcp_register_checkout_box( 'thecartpress/checkout/TCPBillingBox.class.php', 'TCPBillingBox' );
  523. tcp_register_checkout_box( 'thecartpress/checkout/TCPShippingBox.class.php', 'TCPShippingBox' );
  524. tcp_register_checkout_box( 'thecartpress/checkout/TCPShippingMethodsBox.class.php', 'TCPShippingMethodsBox' );
  525. tcp_register_checkout_box( 'thecartpress/checkout/TCPPaymentMethodsBox.class.php', 'TCPPaymentMethodsBox' );
  526. tcp_register_checkout_box( 'thecartpress/checkout/TCPCartBox.class.php', 'TCPCartBox' );
  527. tcp_register_checkout_box( 'thecartpress/checkout/TCPNoticeBox.class.php', 'TCPNoticeBox' );
  528. tcp_register_checkout_box( 'thecartpress/checkout/TCPSigninBox.class.php', 'TCPSigninBox' );
  529. }
  530.  
  531. function loading_default_checkout_plugins() {
  532. //shipping methods
  533. require_once( TCP_PLUGINS_FOLDER .'FreeTrans.class.php' );
  534. tcp_register_shipping_plugin( 'FreeTrans' );
  535. require_once( TCP_PLUGINS_FOLDER .'FlatRate.class.php' );
  536. tcp_register_shipping_plugin( 'FlatRateShipping' );
  537. require_once( TCP_PLUGINS_FOLDER .'ShippingCost.class.php' );
  538. tcp_register_shipping_plugin( 'ShippingCost' );
  539. require_once( TCP_PLUGINS_FOLDER .'LocalPickUp.class.php' );
  540. tcp_register_shipping_plugin( 'TCPLocalPickUp' );
  541. //payment methods
  542. require_once( TCP_PLUGINS_FOLDER .'PayPal/TCPPayPal.php' );
  543. tcp_register_payment_plugin( 'TCPPayPal' );
  544. require_once( TCP_PLUGINS_FOLDER .'Remboursement.class.php' );
  545. tcp_register_payment_plugin( 'TCPRemboursement' );
  546. require_once( TCP_PLUGINS_FOLDER .'NoCostPayment.class.php' );
  547. tcp_register_payment_plugin( 'NoCostPayment' );
  548. require_once( TCP_PLUGINS_FOLDER .'Transference.class.php' );
  549. tcp_register_payment_plugin( 'Transference' );
  550. require_once( TCP_PLUGINS_FOLDER .'CardOffLine/CardOffLine.class.php' );
  551. tcp_register_payment_plugin( 'TCPCardOffLine' );
  552. require_once( TCP_PLUGINS_FOLDER .'authorize.net/TCPAuthorizeNet.class.php' );
  553. tcp_register_payment_plugin( 'TCPAuthorizeNet' );
  554. }
  555.  
  556. function activate_plugin() {
  557. unset( $_SESSION['tcp_session'] );
  558. update_option( 'tcp_rewrite_rules', true );
  559. global $wp_version;
  560. if ( version_compare( $wp_version, '3.0', '<' ) ) {
  561. exit( __( 'TheCartPress requires WordPress version 3.0 or newer.', 'tcp' ) );
  562. }
  563. require_once( TCP_CLASSES_FOLDER . 'Roles.class.php' );
  564. require_once( TCP_DAOS_FOLDER . 'manage_daos.php' );
  565. //Page Shopping Cart
  566. $shopping_cart_page_id = get_option( 'tcp_shopping_cart_page_id' );
  567. if ( ! $shopping_cart_page_id || ! get_page( $shopping_cart_page_id ) ) {
  568. $shopping_cart_page_id = TheCartPress::createShoppingCartPage();
  569. } else {
  570. wp_publish_post( (int)$shopping_cart_page_id );
  571. }
  572. //Page Checkout
  573. $page_id = get_option( 'tcp_checkout_page_id' );
  574. if ( ! $page_id || ! get_page( $page_id ) ) {
  575. TheCartPress::createCheckoutPage( $shopping_cart_page_id );
  576. } else {
  577. wp_publish_post( (int)$page_id );
  578. }
  579. //Page Catalogue
  580. $page_id = get_option( 'tcp_catalogue_page_id' );
  581. if ( ! $page_id || ! get_page( $page_id ) ) {
  582. TheCartPress::createCataloguePage();
  583. } else {
  584. wp_publish_post( (int)$page_id );
  585. }
  586. ProductCustomPostType::create_default_custom_post_type_and_taxonomies();
  587. //initial shipping and payment method
  588. add_option( 'tcp_plugins_data_shi_FreeTrans', array(
  589. array(
  590. 'title' => __( 'Free transport', 'tcp' ),
  591. 'active' => true,
  592. 'for_downloadable' => true,
  593. 'all_countries' => 'yes',
  594. 'countries' => array(),
  595. 'new_status' => 'PENDING',
  596. 'minimun' => 0,
  597. ),
  598. )
  599. );
  600. add_option( 'tcp_plugins_data_pay_Remboursement', array(
  601. array(
  602. 'title' => __( 'Cash on delivery', 'tcp' ),
  603. 'active' => true,
  604. 'for_downloadable' => false,
  605. 'all_countries' => 'yes',
  606. 'countries' => array(),
  607. 'new_status' => 'PROCESSING',
  608. 'notice' => 'Cash on delivery! (5%)',
  609. 'percentage' => 5,
  610. ),
  611. )
  612. );
  613. if ( ! get_option( 'tcp_shortcodes_data' ) )
  614. add_option( 'tcp_shortcodes_data', array( array(
  615. 'id' => 'all_products',
  616. 'title' => '',
  617. 'desc' => 'List of all products',
  618. 'post_type' => 'tcp_product',
  619. 'use_taxonomy' => false,
  620. 'taxonomy' => 'tcp_product_category',
  621. 'included' => array(),
  622. 'term' => '', //'tables',
  623. 'pagination' => true,
  624. 'loop' => '',
  625. 'columns' => 2,
  626. 'see_title' => true,
  627. 'see_image' => false,
  628. 'image_size' => 'thumbnail',
  629. 'see_content' => false,
  630. 'see_excerpt' => true,
  631. 'see_author' => false,
  632. 'see_meta_data' => false,
  633. 'see_meta_utilities' => false,
  634. 'see_price' => false,
  635. 'see_buy_button' => false,
  636. 'see_first_custom_area' => false,
  637. 'see_second_custom_area'=> false,
  638. 'see_third_custom_area' => false,
  639. ) ) );
  640. if ( ! get_option( 'tcp_settings' ) ) {
  641. $this->settings = array(
  642. 'legal_notice' => __( 'Checkout notice', 'tcp' ),
  643. 'stock_management' => false,
  644. 'disable_shopping_cart' => false,
  645. 'disable_ecommerce' => false,
  646. 'user_registration' => false,
  647. 'see_buy_button_in_content' => true,
  648. 'see_buy_button_in_excerpt' => false,
  649. 'see_price_in_content' => false,
  650. 'see_price_in_excerpt' => true,
  651. 'downloadable_path' => WP_PLUGIN_DIR . '/thecartpress/uploads',
  652. 'load_default_buy_button_style' => true,
  653. 'load_default_shopping_cart_checkout_style' => true,
  654. 'load_default_loop_style' => true,
  655. 'responsive_featured_thumbnails' => true,
  656. 'search_engine_activated' => true,
  657. 'emails' => get_option('admin_email'),
  658. 'currency' => 'EUR',
  659. 'decimal_point' => '.',
  660. 'thousands_separator' => ',',
  661. 'unit_weight' => 'gr',
  662. 'hide_visibles' => false,//hide_invisibles!!
  663. );
  664. add_option( 'tcp_settings', $this->settings );
  665. }
  666. TheCartPress::createExampleData();
  667. //feed: http://<site>/?feed=tcp-products
  668. //add_feed( 'tcp-products', array( $this, 'create_products_feed' ) );
  669. /* global $wp_rewrite;
  670. add_action( 'generate_rewrite_rules', array( $this, 'rewrite_rules_feed' ) );
  671. $wp_rewrite->flush_rules();*/
  672. }
  673.  
  674. static function createShoppingCartPage() {
  675. $post = array(
  676. 'comment_status' => 'closed',
  677. 'post_content' => '[tcp_shopping_cart]',
  678. 'post_status' => 'publish',
  679. 'post_title' => __( 'Shopping cart', 'tcp' ),
  680. 'post_type' => 'page',
  681. );
  682. $shopping_cart_page_id = wp_insert_post( $post );
  683. update_option( 'tcp_shopping_cart_page_id', $shopping_cart_page_id );
  684. return $shopping_cart_page_id;
  685. }
  686.  
  687. static function createCheckoutPage( $shopping_cart_page_id = 0 ) {
  688. $post = array(
  689. 'comment_status' => 'closed',
  690. 'post_content' => '[tcp_checkout]',
  691. 'post_status' => 'publish',
  692. 'post_title' => __( 'Checkout', 'tcp' ),
  693. 'post_type' => 'page',
  694. 'post_parent' => $shopping_cart_page_id,
  695. );
  696. $checkout_page_id = wp_insert_post( $post );
  697. update_option( 'tcp_checkout_page_id', $checkout_page_id );
  698. return $checkout_page_id;
  699. }
  700.  
  701. static function createCataloguePage() {
  702. $post = array(
  703. 'comment_status' => 'closed',
  704. 'post_content' => '[tcp_list id="all_products"]',
  705. 'post_status' => 'publish',
  706. 'post_title' => __( 'Catalogue', 'tcp' ),
  707. 'post_type' => 'page',
  708. );
  709. $catalogue_page_id = wp_insert_post( $post );
  710. update_option( 'tcp_catalogue_page_id', $catalogue_page_id );
  711. return $catalogue_page_id;
  712. }
  713.  
  714. static function createExampleData() {
  715. $products = wp_count_posts( 'tcp_product' );
  716. if ( $products->publish + $products->draft == 0 ) {
  717. $args = array(
  718. 'cat_name' => __( 'Category One', 'tcp' ),
  719. 'category_description' => __( 'Category One for Product One', 'tcp' ),
  720. 'taxonomy' => 'tcp_product_category',
  721. );
  722. $post = array(
  723. 'post_content' => 'Product One content, where you can read the best features of the Product One.',
  724. 'post_status' => 'publish',
  725. 'post_title' => __( 'Product One','tcp' ),
  726. 'post_type' => 'tcp_product',
  727. );
  728. $post_id = wp_insert_post( $post );
  729. add_post_meta( $post_id, 'tcp_tax_id', 0 );
  730. add_post_meta( $post_id, 'tcp_is_visible', true );
  731. add_post_meta( $post_id, 'tcp_is_downloadable', false );
  732. add_post_meta( $post_id, 'tcp_type', 'SIMPLE' );
  733. add_post_meta( $post_id, 'tcp_hide_buy_button', false );
  734. add_post_meta( $post_id, 'tcp_price', 100 );
  735. add_post_meta( $post_id, 'tcp_weight', 12 );
  736. add_post_meta( $post_id, 'tcp_order', 10 );
  737. add_post_meta( $post_id, 'tcp_sku', 'SKU_ONE' );
  738. add_post_meta( $post_id, 'tcp_stock', -1 ); //No stock
  739. $category_id = wp_insert_category( $args );
  740. $category_id = term_exists( 'Category One', 'tcp_product_category' );
  741. if ( ! $category_id ) $category_id = wp_insert_term( 'Category One', 'tcp_product_category', $args );
  742. wp_set_object_terms( $post_id, (int)$category_id->term_id, 'tcp_product_category' );
  743. }
  744. }
  745.  
  746. function deactivate_plugin() {
  747. $id = get_option( 'tcp_shopping_cart_page_id' );
  748. wp_delete_post( $id );
  749. $id = get_option( 'tcp_checkout_page_id' );
  750. wp_delete_post( $id );
  751. $id = get_option( 'tcp_catalogue_page_id' );
  752. wp_delete_post( $id );
  753. remove_role( 'customer' );
  754. remove_role( 'merchant' );
  755. }
  756.  
  757. function admin_init() { //default notices
  758. tcp_add_template_class( 'tcp_checkout_email', __( 'This notice will be added in the email to the customer when the Checkout process ends', 'tcp' ) );
  759. tcp_add_template_class( 'tcp_checkout_notice', __( 'This notice will be showed in the Checkout Notice Box into the checkout process', 'tcp' ) );
  760. tcp_add_template_class( 'tcp_checkout_end', __( 'This notice will be showed if the checkout process ends right', 'tcp' ) );
  761. tcp_add_template_class( 'tcp_checkout_end_ko', __( 'This notice will be showed if the checkout process ends wrong: Declined payments, etc.', 'tcp' ) );
  762. tcp_add_template_class( 'tcp_shopping_cart_empty', __( 'This notice will be showed at the Shopping Cart or Checkout page, if the Shopping Cart is empty', 'tcp' ) );
  763. tcp_add_template_class( 'tcp_checkout_order_cart', __( 'This notice will be showed at the Checkout Resume Cart', 'tcp' ) );
  764. }
  765.  
  766. function load_settings() {
  767. $this->settings = get_option( 'tcp_settings' );
  768. }
  769.  
  770. function init() {
  771. if ( ! session_id() ) session_start();
  772. if ( function_exists( 'load_plugin_textdomain' ) ) load_plugin_textdomain( 'tcp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  773. wp_register_script( 'tcp_scripts', plugins_url( 'thecartpress/js/tcp_admin_scripts.js' ) );
  774. if ( is_admin() ) {
  775. wp_enqueue_script( 'jquery-ui-core' );
  776. wp_enqueue_script( 'jquery-ui-sortable' );
  777. wp_enqueue_script( 'tcp_scripts' );
  778. wp_enqueue_style( 'tcp_dashboard_style', plugins_url( 'thecartpress/css/tcp_dashboard.css' ) );
  779. } else {
  780. wp_enqueue_script( 'jquery' );
  781. }
  782. $this->load_custom_post_types_and_custom_taxonomies();
  783. $disable_ecommerce = $this->get_setting( 'disable_ecommerce' );
  784. if ( ! $disable_ecommerce ) {
  785. if ( $this->get_setting( 'load_default_buy_button_style', true ) ) wp_enqueue_style( 'tcp_buy_button_style', plugins_url( 'thecartpress/css/tcp_buy_button.css' ) );
  786. if ( $this->get_setting( 'load_default_shopping_cart_checkout_style', true ) ) wp_enqueue_style( 'tcp_shopping_cart_checkout_style', plugins_url( 'thecartpress/css/tcp_shopping_cart_checkout.css' ) );
  787. if ( $this->get_setting( 'load_default_loop_style', true ) ) wp_enqueue_style( 'tcp_loop_style', plugins_url( 'thecartpress/css/tcp_loop.css' ) );
  788. if ( $this->get_setting( 'responsive_featured_thumbnails', true ) ) wp_enqueue_style( 'tcp_responsive_style', plugins_url( 'thecartpress/css/tcp_responsive.css' ) );
  789. new TemplateCustomPostType();
  790. $this->loading_default_checkout_boxes();
  791. $this->loading_default_checkout_plugins();
  792. //feed: http://<site>/?feed=tcp-products
  793. global $wp_rewrite;
  794. add_action( 'generate_rewrite_rules', array( $this, 'rewrite_rules_feed' ) );
  795. $wp_rewrite->flush_rules();
  796. }
  797. $version = (int)get_option( 'tcp_version' );
  798. if ( $version < 110 ) {
  799. global $wpdb;
  800. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_orders WHERE field = \'transaction_id\'';
  801. $row = $wpdb->get_row( $sql );
  802. if ( ! $row ) {
  803. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders ADD COLUMN `transaction_id` VARCHAR(250) NOT NULL AFTER `payment_amount`;';
  804. $wpdb->query( $sql );
  805. }
  806. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_addresses WHERE field = \'custom_id\'';
  807. if ( ! $wpdb->get_row( $sql ) ) {
  808. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_addresses ADD COLUMN `custom_id` bigint(250) unsigned NOT NULL AFTER `customer_id`;';
  809. $wpdb->query( $sql );
  810. }
  811. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_addresses WHERE field = \'tax_id_number\'';
  812. if ( ! $wpdb->get_row( $sql ) ) {
  813. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_addresses ADD COLUMN `tax_id_number` bigint(250) unsigned NOT NULL AFTER `company`;';
  814. $wpdb->query( $sql );
  815. }
  816. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_addresses WHERE field = \'company_id\'';
  817. if ( ! $wpdb->get_row( $sql ) ) {
  818. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_addresses ADD COLUMN `company_id` bigint(250) unsigned NOT NULL AFTER `tax_id_number`;';
  819. $wpdb->query( $sql );
  820. }
  821. //
  822. //TODO Deprecated 1.2
  823. //
  824. }
  825. if ( $version < 112 ) {
  826. global $wpdb;
  827. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders MODIFY COLUMN `shipping_postcode` CHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
  828. $wpdb->query( $sql );
  829. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders MODIFY COLUMN `billing_postcode` CHAR(10) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
  830. $wpdb->query( $sql );
  831. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_rel_entities WHERE field = \'units\'';
  832. if ( $wpdb->get_row( $sql ) ) {
  833. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_rel_entities DROP COLUMN `units`;';
  834. $wpdb->query( $sql );
  835. }
  836. $sql = 'SHOW COLUMNS FROM ' . $wpdb->prefix . 'tcp_rel_entities WHERE field = \'meta_value\'';
  837. if ( ! $wpdb->get_row( $sql ) ) {
  838. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_rel_entities ADD COLUMN `meta_value` longtext NOT NULL AFTER `list_order`;';
  839. $wpdb->query( $sql );
  840. }
  841. require_once( TCP_DAOS_FOLDER . 'OrdersMeta.class.php' );
  842. OrdersMeta::createTable();
  843. //
  844. //TODO Deprecated 1.2
  845. //
  846. }
  847. if ( $version < 113 ) {
  848. $administrator = get_role( 'administrator' );
  849. if ( $administrator ) $administrator->add_cap( 'tcp_edit_wish_list' );
  850. $merchant = get_role( 'merchant' );
  851. if ( $merchant ) $merchant->add_cap( 'tcp_edit_wish_list' );
  852. $customer = get_role( 'customer' );
  853. if ( $customer ) $customer->add_cap( 'tcp_edit_wish_list' );
  854. $this->settings['use_default_loop'] = 'only_settings';
  855. update_option( 'tcp_settings', $this->settings );
  856. //
  857. //TODO Deprecated 1.2
  858. //
  859. }
  860. if ( $version < 117 ) {
  861. require_once( TCP_DAOS_FOLDER . 'OrdersDetailsMeta.class.php' );
  862. OrdersDetailsMeta::createTable();
  863. $new_post_types = array();
  864. $post_types = tcp_get_custom_post_types();
  865. foreach( $post_types as $id => $post_type ) {
  866. if ( isset( $post_type['name_id'] ) ) {
  867. $id = $post_type['name_id'];
  868. unset( $post_type['name_id'] );
  869. }
  870. $new_post_types[$id] = $post_type;
  871. }
  872. tcp_set_custom_post_types($new_post_types);
  873.  
  874. $new_taxonomies = array();
  875. $taxonomies = tcp_get_custom_taxonomies();
  876. foreach( $taxonomies as $id => $taxonomy ) {
  877. if ( isset( $taxonomy['name_id'] ) ) {
  878. $id = $taxonomy['name_id'];
  879. unset( $taxonomy['name_id'] );
  880. }
  881. $new_taxonomies[$id] = $taxonomy;
  882. }
  883. tcp_set_custom_taxonomies( $new_taxonomies );
  884.  
  885. $post_type_defs = tcp_get_custom_post_types();
  886. if ( isset( $post_type_defs[TCP_PRODUCT_POST_TYPE] ) ) {
  887. $rewrite = $this->get_setting( 'product_rewrite', '' );
  888. if ( strlen( $rewrite ) > 0 ) $post_type_defs[TCP_PRODUCT_POST_TYPE]['rewrite'] = $rewrite;
  889. }
  890. tcp_set_custom_post_types( $post_type_defs );
  891.  
  892. $taxonomy_defs = tcp_get_custom_taxonomies();
  893. if ( isset( $taxonomy_defs[TCP_PRODUCT_CATEGORY] ) ) {
  894. $rewrite = $this->get_setting( 'category_rewrite', '' );
  895. if ( strlen( $rewrite ) > 0 ) $taxonomy_defs[TCP_PRODUCT_CATEGORY]['rewrite'] = array( 'slug' => $rewrite );
  896. }
  897. if ( isset( $taxonomy_defs[TCP_PRODUCT_TAG] ) ) {
  898. $rewrite = $this->get_setting( 'tag_rewrite', '' );
  899. if ( strlen( $rewrite ) > 0 ) $taxonomy_defs[TCP_PRODUCT_TAG]['rewrite'] = array( 'slug' => $rewrite );
  900. }
  901. if ( isset( $taxonomy_defs[TCP_SUPPLIER_TAG] ) ) {
  902. $rewrite = $this->get_setting( 'supplier_rewrite', '' );
  903. if ( strlen( $rewrite ) > 0 ) $taxonomy_defs[TCP_SUPPLIER_TAG]['rewrite'] = array( 'slug' => $rewrite );
  904. }
  905. tcp_set_custom_taxonomies( $taxonomy_defs );
  906. update_option( 'tcp_version', 117 );
  907. //
  908. //TODO Deprecated 1.2
  909. //
  910. }
  911. if ( $version < 118 ) {
  912. global $wpdb;
  913. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders_details MODIFY COLUMN `name` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
  914. $wpdb->query( $sql );
  915. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders_details MODIFY COLUMN `option_1_name` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
  916. $wpdb->query( $sql );
  917. $sql = 'ALTER TABLE ' . $wpdb->prefix . 'tcp_orders_details MODIFY COLUMN `option_2_name` CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;';
  918. $wpdb->query( $sql );
  919. $taxonomies = tcp_get_custom_taxonomies();
  920. if ( is_array( $taxonomies ) && count( $taxonomies ) > 0 ) {
  921. $save = false;
  922. foreach( $taxonomies as $id => $taxonomy ) {
  923. if ( is_array( $taxonomy['rewrite'] ) ) {
  924. $taxonomies[$id]['rewrite'] = $taxonomy['rewrite']['slug'];
  925. $save = true;
  926. }
  927. }
  928. if ( $save ) tcp_set_custom_taxonomies( $taxonomies );
  929. }
  930. require_once( TCP_DAOS_FOLDER . 'OrdersCostsMeta.class.php' );
  931. OrdersCostsMeta::createTable();
  932. update_option( 'tcp_version', 118 ); //TODO
  933. }
  934. update_option( 'tcp_version', 119 );
  935. }
  936.  
  937. function after_setup_theme() {
  938. if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' );
  939. }
  940.  
  941. /**
  942. * Allows to generate the xml for search engine
  943. */
  944. function create_products_feed() {
  945. require_once( TCP_CLASSES_FOLDER . 'FeedForSearchEngine.class.php' );
  946. $feedForSearchEngine = new FeedForSearchEngine();
  947. $feedForSearchEngine->generateXML();
  948. }
  949.  
  950. function rewrite_rules_feed( $wp_rewrite ) {
  951. $new_rules = array(
  952. 'feed/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index( 1 )
  953. );
  954. $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
  955. }
  956.  
  957. function load_custom_post_types_and_custom_taxonomies() {
  958. $post_types = tcp_get_custom_post_types();
  959. if ( is_array( $post_types ) && count( $post_types ) > 0 ) {
  960. foreach( $post_types as $id => $post_type ) {
  961. if ( $post_type['activate'] ) {
  962. $register = array (
  963. 'labels' => $post_type,
  964. 'public' => isset( $post_type['public'] ) ? $post_type['public'] : true,
  965. 'show_ui' => isset( $post_type['show_ui'] ) ? $post_type['show_ui'] : true,
  966. 'show_in_menu' => isset( $post_type['show_in_menu'] ) ? $post_type['show_in_menu'] : true,
  967. 'can_export' => isset( $post_type['can_export'] ) ? $post_type['can_export'] : true,
  968. 'show_in_nav_menus' => isset( $post_type['show_in_nav_menus'] ) ? $post_type['show_in_nav_menus'] : true,
  969. '_builtin' => false,
  970. '_edit_link' => 'post.php?post=%d',
  971. 'capability_type' => 'post',
  972. 'hierarchical' => false,
  973. 'query_var' => isset( $post_type['query_var'] ) ? $post_type['query_var'] : true,
  974. 'supports' => isset( $post_type['supports'] ) ? $post_type['supports'] : array(),
  975. //'taxonomies' => tcp_get_custom_taxonomies( $id ),
  976. 'rewrite' => strlen( $post_type['rewrite'] ) > 0 ? array( 'slug' => $post_type['rewrite'] ) : false,
  977. 'has_archive' => strlen( $post_type['has_archive'] ) > 0 ? $post_type['has_archive'] : false,
  978. );
  979. register_post_type( $id, $register );
  980. $is_saleable = isset( $post_type['is_saleable'] ) ? $post_type['is_saleable'] : false;
  981. if ( $is_saleable ) {
  982. $this->register_saleable_post_type( $id );
  983. //if ( $register['has_archive'] ) ProductCustomPostType::register_post_type_archives( $id, $register['has_archive'] );
  984. global $productcustomposttype;
  985. add_filter( 'manage_edit-' . $id . '_columns', array( &$productcustomposttype, 'custom_columns_definition' ) );
  986. add_filter( 'manage_edit-' . $id . '_sortable_columns', array( &$productcustomposttype, 'sortable_columns' ) );
  987. add_filter( 'request', array( &$productcustomposttype, 'price_column_orderby' ) );
  988. }
  989. }
  990. }
  991. }
  992. $taxonomies = tcp_get_custom_taxonomies();
  993. if ( is_array( $taxonomies ) && count( $taxonomies ) > 0 ) {
  994. foreach( $taxonomies as $id => $taxonomy ) {
  995. if ( $taxonomy['activate'] ) {
  996. $register = array (
  997. 'labels' => $taxonomy,
  998. 'hierarchical' => $taxonomy['hierarchical'],
  999. 'query_var' => $id,
  1000. //'rewrite' => is_array( $taxonomy['rewrite'] ) && isset( $taxonomy['rewrite']['slug'] ) ? $taxonomy['rewrite']['slug'] : false,
  1001. 'rewrite' => strlen( $taxonomy['rewrite'] ) > 0 ? array( 'slug' => $taxonomy['rewrite'] ) : false,
  1002. );
  1003. $post_types = $taxonomy['post_type'];
  1004. if ( ! is_array( $post_types ) ) $post_types = array( $post_types );
  1005. foreach( $post_types as $post_type ) {
  1006. register_taxonomy( $id, $post_type, $register );
  1007. }
  1008. }
  1009. }
  1010. }
  1011. if ( get_option( 'tcp_rewrite_rules' ) ) {
  1012. global $wp_rewrite;
  1013. $wp_rewrite->flush_rules();
  1014. update_option( 'tcp_rewrite_rules', false );
  1015. }
  1016. }
  1017.  
  1018. /**
  1019. * Register a post type as saleable
  1020. * @since 1.1.6
  1021. */
  1022. function register_saleable_post_type( $saleable_post_type ) {
  1023. $this->saleable_post_types[] = $saleable_post_type;
  1024. }
  1025.  
  1026. function tcp_get_saleable_post_types( $saleable_post_types ) {
  1027. return array_merge( $saleable_post_types, $this->saleable_post_types );
  1028. }
  1029.  
  1030. //if a non visible product is displayed, its link will go to the parent
  1031. function post_type_link( $post_link, $post, $leavename, $sample ) {
  1032. if ( ! tcp_is_visible( $post->ID ) ) {
  1033. $parent_id = tcp_get_the_parent( $post->ID );
  1034. if ( $parent_id > 0 ) return get_permalink( $parent_id );
  1035. }
  1036. return $post_link;
  1037. }
  1038.  
  1039. function shutdown() {
  1040. TheCartPress::saveShoppingCart();
  1041. }
  1042.  
  1043. function __construct() {
  1044. $this->load_settings();
  1045. require_once( TCP_TEMPLATES_FOLDER . 'tcp_template.php' );
  1046. require_once( TCP_TEMPLATES_FOLDER . 'tcp_general_template.php' );
  1047. require_once( TCP_TEMPLATES_FOLDER . 'tcp_buybutton_template.php' );
  1048. require_once( TCP_TEMPLATES_FOLDER . 'tcp_calendar_template.php' );
  1049. require_once( TCP_TEMPLATES_FOLDER . 'tcp_template_template.php' );
  1050. require_once( TCP_TEMPLATES_FOLDER . 'tcp_custom_taxonomies.php' );
  1051. require_once( TCP_TEMPLATES_FOLDER . 'tcp_states_template.php' );
  1052. require_once( TCP_TEMPLATES_FOLDER . 'tcp_ordersmeta_template.php' );
  1053. require_once( TCP_CLASSES_FOLDER . 'ShoppingCart.class.php' );
  1054. require_once( TCP_CLASSES_FOLDER . 'TCP_Plugin.class.php' );
  1055. require_once( TCP_CHECKOUT_FOLDER . 'tcp_checkout_template.php' );
  1056. add_action( 'init', array( $this, 'init' ), 9 );
  1057. add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ), 11 );
  1058. $disable_ecommerce = $this->get_setting( 'disable_ecommerce' );
  1059. if ( ! $disable_ecommerce ) {
  1060. add_action( 'user_register', array( $this, 'user_register' ) );
  1061. if ( is_admin() ) {
  1062. register_activation_hook( __FILE__, array( $this, 'activate_plugin' ) );
  1063. register_deactivation_hook( __FILE__, array( $this, 'deactivate_plugin' ) );
  1064. add_action( 'admin_init', array( $this, 'admin_init' ) );
  1065. add_action( 'admin_notices', array( $this, 'admin_notices' ) ); //to check the plugin
  1066. add_action( 'wp_dashboard_setup', array( $this, 'wp_dashboard_setup' ) );
  1067. require_once( TCP_METABOXES_FOLDER . 'ProductCustomFieldsMetabox.class.php' );
  1068. require_once( TCP_METABOXES_FOLDER . 'RelationsMetabox.class.php' );
  1069. require_once( TCP_METABOXES_FOLDER . 'PostMetabox.class.php' );
  1070. require_once( TCP_METABOXES_FOLDER . 'TemplateMetabox.class.php' );
  1071. } else {
  1072. add_filter( 'the_content', array( $this, 'the_content' ) );
  1073. add_filter( 'the_excerpt', array( $this, 'the_excerpt' ) );
  1074. add_action( 'wp_head', array( $this, 'wp_head' ) );
  1075. add_action( 'wp_footer', array( $this, 'annotate_last_visited' ) );
  1076. add_filter( 'request', array( $this, 'request' ) );
  1077. add_filter( 'posts_request', array( $this, 'posts_request' ) );
  1078. add_filter( 'post_type_link', array( $this, 'post_type_link' ), 10, 4 );
  1079. add_filter( 'get_pagenum_link', array( $this, 'get_pagenum_link' ) );
  1080. add_filter( 'login_form_bottom', array( $this, 'loginFormBottom' ) );
  1081. add_shortcode( 'tcp_buy_button', array( $this, 'shortCodeBuyButton' ) );
  1082. add_shortcode( 'tcp_price', array( $this, 'shortCodePrice' ) );
  1083. require_once( TCP_SHORTCODES_FOLDER . 'ShoppingCartPage.class.php' );
  1084. require_once( TCP_CHECKOUT_FOLDER . 'ActiveCheckout.class.php' );
  1085. }
  1086. add_filter( 'tcp_get_saleable_post_types', array( $this, 'tcp_get_saleable_post_types' ) );
  1087. }
  1088. if ( is_admin() ) {
  1089. add_action( 'admin_menu', array( $this, 'admin_menu' ) );
  1090. require_once( TCP_ADMIN_FOLDER . 'Settings.class.php' );
  1091. } else {
  1092. require_once( TCP_SHORTCODES_FOLDER . 'Shortcode.class.php' );
  1093. add_action( 'shutdown', array( $this, 'shutdown' ) );
  1094. }
  1095. add_action( 'widgets_init', array( $this, 'widgets_init' ) );
  1096. }
  1097. }
  1098.  
  1099. $thecartpress = new TheCartPress();
  1100. $tcp_shoppingCart = false;
  1101.  
  1102. require_once( TCP_CUSTOM_POST_TYPE_FOLDER . 'ProductCustomPostType.class.php' );
  1103. require_once( TCP_CUSTOM_POST_TYPE_FOLDER . 'TemplateCustomPostType.class.php' );
  1104.  
  1105. require_once( TCP_CLASSES_FOLDER . 'CustomFields.class.php' );
  1106. require_once( TCP_CLASSES_FOLDER . 'WPPluginsAdminPanel.class.php' );
  1107. require_once( TCP_CLASSES_FOLDER . 'WishList.class.php' );
  1108. require_once( TCP_CLASSES_FOLDER . 'StockManagement.class.php' );
  1109. require_once( TCP_CLASSES_FOLDER . 'DownloadableProducts.class.php' );
  1110. require_once( TCP_CLASSES_FOLDER . 'FilterNavigation.class.php' );
  1111. require_once( TCP_CLASSES_FOLDER . 'GroupedProducts.class.php' );
  1112. require_once( TCP_CLASSES_FOLDER . 'UIImprovements.class.php' );
  1113. require_once( TCP_CLASSES_FOLDER . 'CustomTemplates.class.php' );
  1114. require_once( TCP_CLASSES_FOLDER . 'JPlayer.class.php' );
  1115. require_once( TCP_CLASSES_FOLDER . 'TopSellers.class.php' );
  1116. require_once( TCP_CLASSES_FOLDER . 'CountrySelection.class.php' );
  1117. require_once( TCP_CLASSES_FOLDER . 'BuyButton.class.php' );
  1118.  
  1119. require_once( TCP_ADMIN_FOLDER . 'LoopsSettings.class.php' );
  1120.  
  1121. //add_action( 'all', create_function( '', 'echo \'<!-- TODO: \', current_filter(), \' -->\';' ) );
  1122. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement