generate_rewrite_rule($wp_rewrite->permalink_structure.'print'); array_splice($rewrite_rules2, 1); $r_rule = array_shift(array_keys($rewrite_rules2)); $r_rule = str_replace('/trackback', '',$r_rule); $r_link = array_shift(array_values($rewrite_rules2)); $r_link = str_replace('tb=1', 'print=1', $r_link); $print_rules = array($r_rule => $r_link, '(.+)/printpage/?$' => 'index.php?pagename='.$wp_rewrite->preg_index(1).'&print=1'); $wp_rewrite->rules = $print_rules + $wp_rewrite->rules; } ### Function: Print Public Variables add_filter('query_vars', 'print_variables'); function print_variables($public_query_vars) { $public_query_vars[] = 'print'; return $public_query_vars; } ### Function: Display Print Link function print_link($text_post = 'Print This Post', $text_page = 'Print This Page') { global $id; $using_permalink = get_settings('permalink_structure'); $permalink = get_permalink(); if(!empty($using_permalink)) { if(is_page()) { echo ''.$text_page.''; } else { echo ''.$text_post.''; } } else { echo ''.$text_post.''; } } ### Function: Display Print Image Link function print_link_image() { global $id; $using_permalink = get_settings('permalink_structure'); $permalink = get_permalink(); if(file_exists(ABSPATH.'/wp-content/plugins/print/images/print.gif')) { $print_image = 'Print This Post/Page'; } else { $print_image = 'Print'; } if(!empty($using_permalink)) { if(is_page()) { echo ''.$print_image.''; } else { echo ''.$print_image.''; } } else { echo ''.$print_image.''; } } ### Function: Print Content function print_content($display = true) { global $links_text, $link_number, $pages, $multipage, $numpages, $post; $max_url_char = 80; if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) { $content = get_the_password_form(); } else { if($multipage) { for($page = 0; $page < $numpages; $page++) { $content .= $pages[$page]; } } else { $content = $pages[0]; } $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); if(!print_can('images')) { $content = remove_image($content); } if(print_can('links')) { preg_match_all('/(.+?)<\/a>/', $content, $matches); for ($i=0; $i < count($matches[0]); $i++) { $link_match = $matches[0][$i]; $link_number++; $link_url = $matches[2][$i]; $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url; $link_text = $matches[4][$i]; $content = str_replace($link_match, '['.$link_number."] ".$link_text.'', $content); if(strlen($link_url) > $max_url_char) { $link_url = substr($link_url, 0, $max_url_char).'
'.substr($link_url, $max_url_char, strlen($link_url)); } if(preg_match('//',$link_text)) { $links_text .= '
['.$link_number.'] '.__('Image').': '.$link_url.''; } else { $links_text .= '
['.$link_number.'] '.$link_text.': '.$link_url.''; } } } } if($display) { echo $content; } else { return $content; } } ### Function: Print Categories function print_categories($before = '', $after = '') { $temp_cat = strip_tags(get_the_category_list(',' , $parents)); $temp_cat = explode(', ', $temp_cat); $temp_cat = implode($after.', '.$before, $temp_cat); echo $before.$temp_cat.$after; } ### Function: Print Comments Content function print_comments_content($display = true) { global $links_text, $link_number; $max_url_char = 100; $content = get_comment_text(); $content = apply_filters('comment_text', $content); if(!print_can('images')) { $content = remove_image($content); } if(print_can('links')) { preg_match_all('/(.+?)<\/a>/', $content, $matches); for ($i=0; $i < count($matches[0]); $i++) { $link_match = $matches[0][$i]; $link_number++; $link_url = $matches[2][$i]; $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url; $link_text = $matches[4][$i]; $content = str_replace($link_match, '['.$link_number."] ".$link_text.'', $content); if(strlen($link_url) > $max_url_char) { $link_url = substr($link_url, 0, $max_url_char).'
'.substr($link_url, $max_url_char, strlen($link_url)); } if(preg_match('//',$link_text)) { $links_text .= '
['.$link_number.'] '.__('Image').': '.$link_url.''; } else { $links_text .= '
['.$link_number.'] '.$link_text.': '.$link_url.''; } } } if($display) { echo $content; } else { return $content; } } ### Function: Print Comments function print_comments_number() { global $post; $comment_text = ''; $comment_status = $post->comment_status; if($comment_status == 'open') { $num_comments = get_comments_number(); if($num_comments == 0) { $comment_text = __('No Comments'); } elseif($num_comments == 1) { $comment_text = __('1 Comment'); } else { $comment_text = __($num_comments.' Comments'); } } else { $comment_text = __('Comments Disabled'); } if(!empty($post->post_password) && stripslashes($_COOKIE['wp-postpass_'.COOKIEHASH]) != $post->post_password) { _e('Comments Hidden'); } else { echo $comment_text; } } ### Function: Print Links function print_links($text_links = 'URLs in this post:') { global $links_text; if(!empty($links_text)) { echo $text_links.$links_text; } } ### Function: Load WP-Print add_action('template_redirect', 'wp_print'); function wp_print() { if(intval(get_query_var('print')) == 1) { include(ABSPATH.'wp-content/plugins/print/wp-print.php'); exit; } } ### Function: Add Print Comments Template function print_template_comments($file = '') { $file = ABSPATH.'wp-content/plugins/print/wp-print-comments.php'; return $file; } ### Function: Print Page Title function print_pagetitle($print_pagetitle) { return '» Print'.$print_pagetitle; } ### Function: Can Print? function print_can($type) { $print_options = get_settings('print_options'); return intval($print_options[$type]); } ### Function: Remove Image From Text function remove_image($content) { $content= preg_replace('//', '',$content); return $content; } ### Function: Print Options add_action('activate_print/print.php', 'print_init'); function print_init() { // Add Options $print_options = array(); $print_options['comments'] = 0; $print_options['links'] = 1; $print_options['images'] = 1; add_option('print_options', $print_options, 'Print Options'); } ?>