function wpp_export($export) { error_reporting(0); ob_clean(); $export = addslashes(substr(strip_tags($_GET['wpp_export']), 0, 5)); @set_time_limit(864000); if (ini_get('max_execution_time') != 864000) { @ini_set('max_execution_time', 864000); } $post_id = url_to_postid($_SERVER['REQUEST_URI']); $post = get_post($post_id); if ($post->post_status != 'publish') { return false; } if (post_password_required($post->ID)) { return false; } $product = get_product($post->ID); $out = ''; 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 = ''; } if ($thumbnail[1]) { $wpp_featured_image = '<img width="' . $thumbnail[1] . '" height="' . $thumbnail[2] . '" src="' . $thumbnail[0] . '"/>'; } $wpp_price_html = strip_tags($product->get_price_html()); $wpp_title = $post->post_title; $wpp_sku = $product->get_sku(); $wpp_permalink = $product->get_permalink(); $wpp_stock = $product->get_stock_quantity(); $wpp_rating = strip_tags($product->get_rating_html()); $wpp_categories = $product->get_categories(', '); $wpp_tags = $product->get_tags(', '); $wpp_summary = wpp_text_filter($post->post_excerpt); $wpp_description = wpp_text_filter($post->post_content); $attribute_html = "\r\n<ul>"; if ($product->enable_dimensions_display()) { $attribute_html .= $product->get_dimensions() ? '<li>' . get_option('wpp_ph_dimensions') . ': ' . $product->get_dimensions() . "\r\n</li>" : ''; } $attribute_html .= $product->get_weight() ? '<li>' . get_option('wpp_ph_weight') . ': ' . $product->get_weight() . ' ' . get_option('woocommerce_weight_unit') . "\r\n</li>" : ''; if ($product->has_attributes()) { $wpp_attributes = $product->get_attributes(); if (!empty($wpp_attributes)) { foreach ($wpp_attributes as $attribute) { if (!$attribute['is_visible']) { continue; } if ($attribute['is_taxonomy']) { $product_terms = wp_get_post_terms($post->ID, $attribute['name']); $p_terms = array(); //$attribute_name = ucwords(str_replace('attribute_','',str_replace('pa_','',$attribute['name']))); $attribute_name = wc_attribute_label($attribute['name']); foreach ($product_terms as $p_term) { $p_terms[] = $p_term->name; } $attribute_html .= '<li>' . $attribute_name . ': ' . implode(', ', $p_terms) . "\r\n</li>"; } else { $attribute_html .= '<li>' . $attribute['name'] . ': ' . $attribute['value'] . "\r\n</li>"; } } } } $attribute_html .= '</ul>'; $attribute_html = str_replace(array(' |', '|'), ',', $attribute_html); $wpp_has_variants = false; $wpp_variants = "\r\n<ul>"; $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'asc', 'post_parent' => $post->ID); $variations = get_posts($args); if (!empty($variations)) { $wpp_has_variants = true; foreach ($variations as $variation) { $vars = new WC_Product_Variation($variation->ID); $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>"; unset($vars); } $wpp_variants .= '</ul>'; $wpp_variants = str_replace(array('<li> - ', ', - '), array('<li>', ' - '), $wpp_variants); } //Post Specific Custom Tabs if ($product_meta = get_post_meta($post->ID)) { foreach ($product_meta as $meta_key => $meta_value) { if (strpos($meta_key, '_wpt_field_') !== FALSE) { $custom_tab_slug = str_replace('_wpt_field_', '', $meta_key); $custom_tab = get_posts(array('name' => $custom_tab_slug, 'posts_per_page' => 1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish')); if (trim($meta_value[0])) { $custom_tab_title_html[] = $custom_tab[0]->post_title; $custom_tab_content_html[] = wpp_text_filter($meta_value[0]); } } continue; } } //General Custom Tabs $general_custom_tab = get_posts(array('posts_per_page' => -1, 'post_type' => 'woo_product_tab', 'post_status' => 'publish')); foreach ($general_custom_tab as $tab) { if (trim($tab->post_content)) { $cfkey = '_wpt_field_' . $tab->post_name; if (get_post_meta($post->ID, $cfkey, true)) { //it's already taken } else { $custom_tab_title_html[] = $tab->post_title; $custom_tab_content_html[] = wpp_text_filter($tab->post_content); } } } $wpp_gallery = $product->get_gallery_attachment_ids(); foreach ($wpp_gallery as $wpp_img) { $wpp_gallery_images .= ' ' . wp_get_attachment_image($wpp_img, 'shop_single') . ' '; } if ($export == 'doc') { $doc_title = stripslashes($post->post_title); $wpp_description = stripslashes($wpp_description); $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('–', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8"); 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; } 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); } } $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description); $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description); preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER); if (!empty($body_array)) { for ($i = 0; $i < count($body_array); $i++) { $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]); $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description); } } $wpp_doc_urls = wpp_img_url($wpp_description); if (!empty($wpp_doc_urls)) { foreach ($wpp_doc_urls as $k => $v) { $wpp_description = str_replace($k, $v, $wpp_description); } } $doc_post_date = $post->post_date; $doc_post_date_gmt = $post->post_date_gmt; $doc_modified_date = $post->post_modified; $doc_modified_date_gmt = $post->post_modified_gmt; if (!get_option('wpp_doc_t_image')) { $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description); } $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>' : ''; $doc_t_date = get_option('wpp_doc_t_date') ? get_option('wpp_ph_prod_date') . ': ' . $doc_post_date . '<br>' : ''; $doc_t_md_date = get_option('wpp_doc_t_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $doc_modified_date : ''; require WPP_FOLDER . 'template/header/doc_head.php'; if (get_option('wpp_save_doc_template')) { require WPP_FOLDER . 'template/save_as_word_document.php'; } else { require WPP_FOLDER . 'template/save_as_word_document_oo.php'; } $doc = trim($doc); $length = strlen($doc); $file = trim(str_replace(' ', '-', trim($doc_title)), '-'); $file = $file . '.doc'; header('Content-Type: application/msword; charset=utf-8'); if (headers_sent()) { echo 'Some data has already been output, can\'t send MS Doc file'; } header('Content-Length: ' . $length); header('Content-Disposition: attachment; filename=' . $file); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public'); ini_set('zlib.output_compression', '0'); echo $doc; } elseif ($export == 'pdf') { global $wpp_html_link; $html_title = stripslashes($post->post_title); $wpp_html_link = stripslashes($post->guid); //Price Style $wpp_price = $product->get_price_html(); $wpp_price = strpos($wpp_price, '') === FALSE ? $wpp_price : str_replace('руб', 'руб', strip_tags($wpp_price)); if ($product->is_on_sale()) { $wpp_price = str_replace(array('<del>', '</del>'), array('^[font][' . get_option('wpp_ph_real_price') . ': ', '][200,200,200][14]^<br> ^[font][' . get_option('wpp_ph_curr_sale_price') . ':'), str_replace('–', ' - ', $wpp_price)) . '][15, 117, 84][14]^'; } else { $wpp_price = '^[font][' . get_option('wpp_ph_price') . ': ' . strip_tags($wpp_price) . '][15, 117, 84][14]^'; } //Limiting image sizes preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $html_body, $body_array, PREG_SET_ORDER); if (!empty($body_array)) { for ($i = 0; $i < count($body_array); $i++) { $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]); $html_body = str_replace($body_array[$i][0], $replace, $html_body); } } $html_body = preg_replace('|<noscript>.+?</noscript>|is', '', $html_body); $html_body = preg_replace("|\r|", "<br>", $html_body); $wpp_pdf_urls = wpp_img_url($html_body); if (!empty($wpp_pdf_urls)) { foreach ($wpp_pdf_urls as $k => $v) { if (strpos($k, '../') === FALSE) { $html_body = str_replace($k, $v, $html_body); } else { continue; } } } require WPP_FOLDER . 'template/header/pdf_head.php'; require WPP_FOLDER . 'template/save_as_pdf.php'; require WPP_FOLDER . 'pdf.php'; } elseif ($export == 'print') { $print_title = stripslashes($post->post_title); $wpp_description = stripslashes($wpp_description); $wpp_price = get_option('wpp_ph_price') . ': ' . html_entity_decode(str_replace('–', ' - ', $product->get_price_html()), ENT_QUOTES, "UTF-8"); 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; } if (preg_match_all('|width=[\'\\"]*(\\d+)[\'\\"]*[^\\>\\<]+height=[\'\\"]*(\\d+)[\'\\"]*|i', $wpp_description, $print_img_sizes, PREG_SET_ORDER)) { foreach ($print_img_sizes as $print_img) { $print_img_w = $print_img[1]; $print_img_h = $print_img[2]; 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; } $wpp_description = preg_replace('|width=[\'\\"]*' . $print_img[1] . '[\'\\"]*[^\\>\\<]+height=[\'\\"]*' . $print_img[2] . '[\'\\"]*|i', 'width="' . $print_img_w . '" height="' . $print_img_h . '"', $wpp_description); } } $wpp_description = preg_replace('|\\[caption[^\\]]+\\]([^\\]]*)\\[\\/caption\\]|is', '$1', $wpp_description); $wpp_description = preg_replace(array('|<embed[^>]+>[^>]*<\\/embed>|i', '|<object[^>]+>|i', '|<\\/object>|i', '|<param[^>]+>|i', '|<script[^>]+>[^>]*<\\/script>|i'), '', $wpp_description); if (get_option('wpp_pt_links')) { preg_match_all("|<a href[\\s\n\t\r]*=[\\s\n\t\r]*[\\'\"]+([^>\\'\"]+)[\\'\"]+[^><]*>([^><]+)</a>|i", $wpp_description, $links_array, PREG_SET_ORDER); if (!empty($links_array)) { for ($i = 0; $i < count($links_array); $i++) { $print_links .= '<li>' . wpp_phrase_spliter($links_array[$i][1], 50, ' ', false) . '</li>'; $wpp_description = str_replace($links_array[$i][0], '<u>' . $links_array[$i][0] . '</u> <sup>' . ($i + 1) . '</sup>', $wpp_description); } } } preg_match_all('|<img[^>]+(class[\\s\\n\\t\\r]*=[\\s\\n\\t\\r]*[\'\\"]+[^\'\\">]+[\'\\"]+)[^>]*>|i', $wpp_description, $body_array, PREG_SET_ORDER); if (!empty($body_array)) { for ($i = 0; $i < count($body_array); $i++) { $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]); $wpp_description = str_replace($body_array[$i][0], $replace, $wpp_description); } } $print_excerpt = stripslashes($post->post_excerpt); $print_post_date = $post->post_date; $print_post_date_gmt = $post->post_date_gmt; $print_modified_date = $post->post_modified; $print_modified_date_gmt = $post->post_modified_gmt; if (!get_option('wpp_pt_image')) { $wpp_description = preg_replace('|<img[^><]+>|i', '', $wpp_description); } $pt_header = get_option('wpp_pt_head_site') ? '<a href="' . get_option('siteurl') . '" target="_blank" class="wpp_header_2">' . get_option('blogname') . '</a> <br/>' : ''; $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 />' : ''; $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 />' : ''; $pt_header .= '<hr style="border:none; border-top: #DDDDDD dotted 1px;" />'; $pt_title = $print_title && get_option('wpp_pt_title') ? '<h2 style="text-align:' . get_option('wpp_save_text_align') . '">' . $print_title . '</h2><br>' : ''; $pt_links = $print_links && get_option('wpp_pt_links') ? '<strong>' . get_option('wpp_ph_links') . ':</strong> <ol type="1">' . $print_links . '</ol>' : ''; $pt_date = get_option('wpp_pt_date') ? get_option('wpp_ph_prod_date') . ': ' . $print_post_date . '<br>' : ''; $pt_md_date = get_option('wpp_pt_md') ? get_option('wpp_ph_prod_mod_date') . ': ' . $print_modified_date . '<br>' : ''; $pt_footer = get_option('wpp_pt_header') ? '<br>' . get_option('wpp_ph_exp_date') . ': ' . date("D M j G:i:s Y / O ") . ' GMT <br> ' . get_option('wpp_ph_page_exported_from') . ' ' . get_option('blogname') . ' [ <a href="' . str_replace(array('&wpp_export=print', '?wpp_export=print'), '', $_SERVER['REQUEST_URI']) . '" target="_blank">' . get_option('siteurl') . '</a> ]<hr/> Product Print by <a href="http://www.gvectors.com/?wpp" target="_blank">WooCommerce PDF & Print</a> plugin.' : ''; require WPP_FOLDER . 'template/header/print_head.php'; require WPP_FOLDER . 'template/print.php'; echo $print; } exit; }