Advertisement
Guest User

cartpressnew

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