wpp_export

The WooCommerce PDF & Print wpp export function.

Description

wpp_export( $export ); 

Parameters (1)

0. $export
The export.

Usage

  1. if ( !function_exists( 'wpp_export' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-pdf-print/functions.php'; 
  3.  
  4. // The export. 
  5. $export = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wpp_export($export); 
  9.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function wpp_export( $export ) { 
  2.  
  3. error_reporting(0); 
  4. ob_clean(); 
  5. $export = addslashes(substr(strip_tags($_GET[ 'wpp_export' ]), 0, 5)); 
  6. @set_time_limit (864000); 
  7. if(ini_get('max_execution_time')!=864000)@ini_set('max_execution_time', 864000); 
  8.  
  9. $post_id = url_to_postid( $_SERVER['REQUEST_URI'] ); 
  10. $post = get_post( $post_id );  
  11. if( $post->post_status != 'publish' ) return false; 
  12. if( post_password_required($post->ID)) return false; 
  13. $product = get_product( $post->ID ); 
  14. $out = ''; 
  15. if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID) ) { $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'shop_single' ); $wpp_featured_image = ($thumbnail[0]) ? $thumbnail[0] : $thumbnail[0]; } else{ $wpp_featured_image = ''; } 
  16. if( $thumbnail[1] ) $wpp_featured_image = '<img width="'.$thumbnail[1].'" height="'.$thumbnail[2].'" src="'.$thumbnail[0].'"/>'; 
  17.  
  18. $wpp_price_html = strip_tags($product->get_price_html()); 
  19. $wpp_title = $post->post_title; 
  20. $wpp_sku = $product->get_sku(); 
  21. $wpp_permalink = $product->get_permalink(); 
  22. $wpp_stock = $product->get_stock_quantity(); 
  23. $wpp_rating = strip_tags($product->get_rating_html()); 
  24. $wpp_categories = $product->get_categories(', '); 
  25. $wpp_tags = $product->get_tags(', '); 
  26. $wpp_summary = wpp_text_filter( $post->post_excerpt ); 
  27. $wpp_description = wpp_text_filter( $post->post_content ); 
  28.  
  29. $attribute_html = "\r\n<ul>"; 
  30. if($product->enable_dimensions_display()) {  
  31. $attribute_html .= (($product->get_dimensions()) ? '<li>'.get_option( 'wpp_ph_dimensions' ).': '.$product->get_dimensions()."\r\n</li>" : '');  
  32. $attribute_html .= (($product->get_weight()) ? '<li>'.get_option( 'wpp_ph_weight' ).': '.$product->get_weight().' '.get_option('woocommerce_weight_unit')."\r\n</li>" : ''); 
  33. if( $product->has_attributes() ) {  
  34. $wpp_attributes = $product->get_attributes();  
  35. if(!empty($wpp_attributes)) { 
  36. foreach( $wpp_attributes as $attribute) { 
  37. if( !$attribute['is_visible'] ) continue; 
  38. if( $attribute['is_taxonomy'] ) { 
  39. $product_terms = wp_get_post_terms( $post->ID, $attribute['name'] ); $p_terms = array(); 
  40. //$attribute_name = ucwords(str_replace('attribute_', '', str_replace('pa_', '', $attribute['name']))); 
  41. $attribute_name = wc_attribute_label( $attribute['name'] ); 
  42. foreach($product_terms as $p_term) { 
  43. $p_terms[] = $p_term->name; 
  44. $attribute_html .= '<li>'.$attribute_name.': '.implode(', ', $p_terms)."\r\n</li>"; 
  45. else{ 
  46. $attribute_html .= '<li>'.$attribute['name'].': '.$attribute['value']."\r\n</li>"; 
  47. $attribute_html .= '</ul>'; 
  48. $attribute_html = str_replace(array(' |', '|'), ', ', $attribute_html); 
  49. $wpp_has_variants = false; 
  50. $wpp_variants = "\r\n<ul>"; 
  51. $args = array( 'post_type' => 'product_variation', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID); 
  52. $variations = get_posts( $args );  
  53. if(!empty($variations)) { 
  54. $wpp_has_variants = true; 
  55. foreach ( $variations as $variation ) { 
  56. $vars = new WC_Product_Variation($variation->ID); 
  57. $wpp_variants .= '<li>'. str_replace($vars->get_sku(), '', html_entity_decode(strip_tags(wpp_text_filter(str_replace( '–', ' - ', $vars->get_formatted_name())) ), ENT_QUOTES, "UTF-8") ) ."\r\n</li>"; 
  58. unset($vars); 
  59. $wpp_variants .= '</ul>'; 
  60. $wpp_variants = str_replace(array('<li> - ', ', - '), array('<li>', ' - '), $wpp_variants); 
  61.  
  62. //Post Specific Custom Tabs  
  63. if( $product_meta = get_post_meta( $post->ID ) ) { 
  64. foreach( $product_meta as $meta_key => $meta_value ) { 
  65. if( strpos($meta_key, '_wpt_field_') !== FALSE ) { 
  66. $custom_tab_slug = str_replace('_wpt_field_', '', $meta_key); 
  67. $custom_tab = get_posts(array( 'name' => $custom_tab_slug, 'posts_per_page' => 1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish' )); 
  68. if(trim($meta_value[0])) { 
  69. $custom_tab_title_html[] = $custom_tab[0]->post_title; 
  70. $custom_tab_content_html[] = wpp_text_filter($meta_value[0]); 
  71. continue; 
  72.  
  73. //General Custom Tabs  
  74. $general_custom_tab = get_posts(array( 'posts_per_page' => -1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish' )); 
  75. foreach( $general_custom_tab as $tab ) { 
  76. if(trim( $tab->post_content )) { 
  77. $cfkey = '_wpt_field_' . $tab->post_name; 
  78. if( get_post_meta( $post->ID, $cfkey, true ) ) { 
  79. //it's already taken 
  80. else{ 
  81. $custom_tab_title_html[] = $tab->post_title; 
  82. $custom_tab_content_html[] = wpp_text_filter($tab->post_content); 
  83.  
  84. $wpp_gallery = $product->get_gallery_attachment_ids(); 
  85. foreach( $wpp_gallery as $wpp_img ) { 
  86. $wpp_gallery_images .= ' '.wp_get_attachment_image( $wpp_img, 'shop_single' ) . ' '; 
  87.  
  88.  
  89.  
  90. if( $export == 'doc' ) { 
  91.  
  92. $doc_title = stripslashes( $post->post_title ); 
  93. $wpp_description = stripslashes( $wpp_description ); 
  94. $wpp_price = get_option( 'wpp_ph_price' ) . ': ' . html_entity_decode(str_replace( '–', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8"); 
  95. if( get_option('wpp_save_doc_img_max_width') ) { $wpp_max_image_width = get_option('wpp_save_doc_img_max_width'); } else{ $wpp_max_image_width = 500; } 
  96. if( preg_match_all('|width=[\'\"]*(\d+)[\'\"]*[^\>\<]+height=[\'\"]*(\d+)[\'\"]*|i', $wpp_description, $doc_img_sizes, PREG_SET_ORDER ) ) { foreach( $doc_img_sizes as $doc_img ) { $doc_img_w = $doc_img[1]; $doc_img_h = $doc_img[2]; if( (int)$wpp_max_image_width < (int)$doc_img_w ) { $doc_img_h = $doc_img_h * ( $wpp_max_image_width / $doc_img_w ); $doc_img_w = $wpp_max_image_width; } $wpp_description = preg_replace('|width=[\'\"]*'.$doc_img[1].'[\'\"]*[^\>\<]+height=[\'\"]*'.$doc_img[2].'[\'\"]*|i', 'width="'.$doc_img_w.'" height="'.$doc_img_h.'"', $wpp_description );}} 
  97. $wpp_description = preg_replace('|\[caption[^\]]+\]([^\]]*)\[\/caption\]|is', '$1', $wpp_description); 
  98. $wpp_description = preg_replace( array('|<embed[^>]+>[^>]*<\/embed>|i', '|<object[^>]+>|i', '|<\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\/script>|i'), '', $wpp_description ); 
  99. preg_match_all('|<img[^>]+(class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+[^\'\">]+[\'\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER); 
  100. if( !empty($body_array) ) { 
  101. for ($i=0; $i < count($body_array); $i++) { 
  102. $replace = preg_replace( '|(.+)class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+align([^\s\t\r\n\'\">]+)[^\'\">]*[\'\"]+(.+)|i', '</span><![if !vml]> $1 align = \'$2\' $3 <![endif]><span style=\'font-size:10.5pt;color:#666666;\'>', $body_array [$i][0] ); 
  103. $wpp_description = str_replace( $body_array [$i][0], $replace , $wpp_description); 
  104. $wpp_doc_urls = wpp_img_url( $wpp_description ); 
  105. if(!empty($wpp_doc_urls)) { foreach( $wpp_doc_urls as $k => $v ) { $wpp_description = str_replace( $k, $v, $wpp_description ); }} 
  106. $doc_post_date = $post->post_date; 
  107. $doc_post_date_gmt = $post->post_date_gmt; 
  108. $doc_modified_date = $post->post_modified; 
  109. $doc_modified_date_gmt = $post->post_modified_gmt; 
  110. if(!get_option('wpp_doc_t_image')) { $wpp_description = preg_replace( '|<img[^><]+>|i', '', $wpp_description ); } 
  111. $doc_t_title = (($doc_title && get_option('wpp_doc_t_title'))? '<h2 style="color:#000000;text-align:'.get_option('wpp_save_text_align').'">'.$doc_title.'</h2><br>' :''); 
  112. $doc_t_date = ((get_option('wpp_doc_t_date'))? get_option( 'wpp_ph_prod_date' ) . ': '.$doc_post_date.'<br>':''); 
  113. $doc_t_md_date = ((get_option('wpp_doc_t_md'))? get_option( 'wpp_ph_prod_mod_date' ) . ': '.$doc_modified_date:''); 
  114. require( WPP_FOLDER . 'template/header/doc_head.php' ); 
  115. if( get_option('wpp_save_doc_template') ) { 
  116. require( WPP_FOLDER . 'template/save_as_word_document.php' ); 
  117. else{ 
  118. require( WPP_FOLDER . 'template/save_as_word_document_oo.php' ); 
  119. $doc = trim($doc); 
  120. $length = strlen( $doc ); 
  121. $file = trim( str_replace( ' ', '-' , trim($doc_title) ), '-' ); 
  122. $file = $file.'.doc'; 
  123. header ('Content-Type: application/msword; charset=utf-8' ); 
  124. if(headers_sent()) echo ('Some data has already been output, can\'t send MS Doc file'); 
  125. header('Content-Length: '.$length ); 
  126. header ('Content-Disposition: attachment; filename='.$file ); 
  127. header('Cache-Control: private, max-age=0, must-revalidate'); 
  128. header('Pragma: public'); 
  129. ini_set('zlib.output_compression', '0'); 
  130. echo $doc; 
  131.  
  132. elseif( $export == 'pdf' ) { 
  133.  
  134. global $wpp_html_link; 
  135. $html_title = stripslashes( $post->post_title ); 
  136. $wpp_html_link = stripslashes( $post->guid ); 
  137.  
  138. //Price Style 
  139. $wpp_price = $product->get_price_html(); 
  140. $wpp_price = ( strpos( $wpp_price, '' ) === FALSE ) ? $wpp_price : str_replace('руб', '***', strip_tags($wpp_price)); 
  141. if( $product->is_on_sale() ) {  
  142. $wpp_price = str_replace(array('<del>', '</del>'), array('^[font][' . get_option( 'wpp_ph_real_price' ) . ': ', '][200, 200, 200][14]^<br> 
  143. ^[font]['.get_option( 'wpp_ph_curr_sale_price' ).':'), str_replace( '–', ' - ', $wpp_price)).'][15, 117, 84][14]^'; 
  144. } else{  
  145. $wpp_price = '^[font]['.get_option( 'wpp_ph_price' ).': ' . strip_tags( $wpp_price ).'][15, 117, 84][14]^';  
  146.  
  147. //Limiting image sizes 
  148. preg_match_all('|<img[^>]+(class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+[^\'\">]+[\'\"]+)[^>]*>|i', $html_body, $body_array, PREG_SET_ORDER); 
  149. if( !empty($body_array) ) { 
  150. for ($i=0; $i < count($body_array); $i++) { 
  151. $replace = preg_replace( '|(.+)class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+align([^\s\t\r\n\'\">]+)[^\'\">]*[\'\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array [$i][0] ); 
  152. $html_body = str_replace( $body_array [$i][0], $replace , $html_body); 
  153. $html_body = preg_replace('|<noscript>.+?</noscript>|is', '', $html_body); 
  154. $html_body = preg_replace( "|\r|", "<br>" , $html_body); 
  155. $wpp_pdf_urls = wpp_img_url( $html_body ); 
  156. if(!empty($wpp_pdf_urls)) { 
  157. foreach( $wpp_pdf_urls as $k => $v ) { 
  158. if( strpos( $k, '../' ) === FALSE ) { 
  159. $html_body = str_replace( $k, $v, $html_body ); 
  160. else{ 
  161. continue; 
  162. require( WPP_FOLDER . 'template/header/pdf_head.php' ); 
  163. require( WPP_FOLDER . 'template/save_as_pdf.php' ); 
  164. require( WPP_FOLDER . 'pdf.php' ); 
  165. elseif( $export == 'print' ) { 
  166.  
  167. $print_title = stripslashes( $post->post_title ); 
  168. $wpp_description = stripslashes( $wpp_description ); 
  169. $wpp_price = get_option( 'wpp_ph_price' ) . ': ' . html_entity_decode(str_replace( '–', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8"); 
  170. if( get_option('wpp_save_print_img_max_width') ) { $wpp_max_image_width = get_option('wpp_save_print_img_max_width'); } else{ $wpp_max_image_width = 500; } 
  171. if( preg_match_all('|width=[\'\"]*(\d+)[\'\"]*[^\>\<]+height=[\'\"]*(\d+)[\'\"]*|i', $wpp_description, $print_img_sizes, PREG_SET_ORDER ) ) { 
  172. foreach( $print_img_sizes as $print_img ) { 
  173. $print_img_w = $print_img[1]; $print_img_h = $print_img[2]; 
  174. if( (int)$wpp_max_image_width < (int)$print_img_w ) { $print_img_h = $print_img_h * ( $wpp_max_image_width / $print_img_w ); $print_img_w = $wpp_max_image_width; } 
  175. $wpp_description = preg_replace('|width=[\'\"]*'.$print_img[1].'[\'\"]*[^\>\<]+height=[\'\"]*'.$print_img[2].'[\'\"]*|i', 'width="'.$print_img_w.'" height="'.$print_img_h.'"', $wpp_description ); 
  176. $wpp_description = preg_replace('|\[caption[^\]]+\]([^\]]*)\[\/caption\]|is', '$1', $wpp_description); 
  177. $wpp_description = preg_replace( array('|<embed[^>]+>[^>]*<\/embed>|i', '|<object[^>]+>|i', '|<\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\/script>|i'), '', $wpp_description ); 
  178. if(get_option('wpp_pt_links')) { 
  179. preg_match_all("|<a href[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+([^>\'\"]+)[\'\"]+[^><]*>([^><]+)</a>|i", $wpp_description, $links_array, PREG_SET_ORDER); 
  180. if( !empty($links_array) ) { 
  181. for ($i=0; $i < count($links_array); $i++) { 
  182. $print_links .= '<li>'.wpp_phrase_spliter( $links_array[$i][1], 50, ' ', false ).'</li>'; 
  183. $wpp_description = str_replace( $links_array[$i][0], '<u>'.$links_array[$i][0].'</u> <sup>'.($i+1).'</sup>', $wpp_description); 
  184. preg_match_all('|<img[^>]+(class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+[^\'\">]+[\'\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER); 
  185. if( !empty($body_array) ) { 
  186. for ($i=0; $i < count($body_array); $i++) { 
  187. $replace = preg_replace( '|(.+)class[\s\n\t\r]*=[\s\n\t\r]*[\'\"]+align([^\s\t\r\n\'\">]+)[^\'\">]*[\'\"]+(.+)|i', '$1 align = "$2" style="padding:5px" $3', $body_array[$i][0] ); 
  188. $wpp_description = str_replace( $body_array[$i][0], $replace , $wpp_description); 
  189. $print_excerpt = stripslashes( $post->post_excerpt ); 
  190. $print_post_date = $post->post_date; 
  191. $print_post_date_gmt = $post->post_date_gmt; 
  192. $print_modified_date = $post->post_modified; 
  193. $print_modified_date_gmt = $post->post_modified_gmt; 
  194. if(!get_option('wpp_pt_image')) { 
  195. $wpp_description = preg_replace( '|<img[^><]+>|i', '', $wpp_description ); 
  196. $pt_header = (get_option('wpp_pt_head_site'))? '<a href="'.get_option('siteurl').'" target="_blank" class="wpp_header_2">'.get_option('blogname').'</a> <br/>': ''; 
  197. $pt_header .= (get_option('wpp_pt_head_url'))? '<a href="'.get_permalink($post->ID).'" target="_blank" class="wpp_header_3">'.get_permalink($post->ID).'</a> <br />': ''; 
  198. $pt_header .= (get_option('wpp_pt_head_date'))? get_option('wpp_ph_exp_date') . ': '. date("D M j G:i:s Y / O ") .' GMT<br />': ''; 
  199. $pt_header .= '<hr style="border:none; border-top: #DDDDDD dotted 1px;" />'; 
  200. $pt_title =  
  201. (($print_title && get_option('wpp_pt_title'))? '<h2 style="text-align:'.get_option('wpp_save_text_align').'">'.$print_title.'</h2><br>' :''); 
  202. $pt_links =  
  203. (($print_links && get_option('wpp_pt_links'))?'<strong>'.get_option( 'wpp_ph_links' ).':</strong> <ol type="1">'.$print_links.'</ol>':''); 
  204. $pt_date =  
  205. ((get_option('wpp_pt_date'))? get_option( 'wpp_ph_prod_date' ) .': '.$print_post_date.'<br>':''); 
  206. $pt_md_date =  
  207. ((get_option('wpp_pt_md'))? get_option( 'wpp_ph_prod_mod_date' ) .': '.$print_modified_date.'<br>':''); 
  208. $pt_footer = ((get_option('wpp_pt_header'))?'<br>'.get_option('wpp_ph_exp_date').': '. date("D M j G:i:s Y / O ") .' GMT 
  209. <br> '.get_option( 'wpp_ph_page_exported_from' ).' '.get_option('blogname').'  
  210. [ <a href="'.(str_replace( array('&wpp_export=print', '?wpp_export=print'), '', $_SERVER['REQUEST_URI'] )).'" target="_blank">'.get_option('siteurl').'</a> ]<hr/> 
  211. Product Print by <a href="http://www.gvectors.com/?wpp" target="_blank">WooCommerce PDF & Print</a> plugin.':''); 
  212. require( WPP_FOLDER . 'template/header/print_head.php' ); 
  213. require( WPP_FOLDER . 'template/print.php' ); 
  214. echo $print;  
  215. exit;