Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.34 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Show Content Only
  4. Plugin URI: https://katz.co/content-only/
  5. Description: Display only the post's content, without a theme, scripts or stylesheets.
  6. Author: Katz Web Services, Inc.
  7. Author URI: http://www.katzwebservices.com
  8. Version: 1.3.1
  9. Text Domain: show-content-only
  10. */
  11.  
  12. /*  Copyright 2014  Katz Web Services, Inc.  (email : info@katzwebdesign.com)
  13.  
  14.     This program is free software; you can redistribute it and/or modify
  15.     it under the terms of the GNU General Public License as published by
  16.     the Free Software Foundation; either version 2 of the License, or
  17.     (at your option) any later version.
  18.  
  19.     This program is distributed in the hope that it will be useful,
  20.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22.     GNU General Public License for more details.
  23.  
  24.     You should have received a copy of the GNU General Public License
  25.     along with this program; if not, write to the Free Software
  26.     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  27. */
  28.  
  29. class ShowContentOnly {
  30.  
  31.     function __construct() {
  32.         add_action( 'init', array( $this, 'languages' ) );
  33.         add_action( 'wp', array( $this, 'keyword' ) );
  34.         add_action( 'admin_menu', array( $this, 'meta_box' ) );
  35.     }
  36.  
  37.     function languages() {
  38.         load_plugin_textdomain( 'show-content-only', false, untrailingslashit( basename( dirname( __FILE__ ) ) ) . '/languages' );
  39.     }
  40.  
  41.     function keyword() {
  42.         global $post;
  43.  
  44.         if ( isset( $_GET['rand'] )) {
  45.             foreach ( get_posts ( array( 'numberposts' => 1, 'orderby' => 'rand' ) ) as $post ) {
  46.                 header('Location: ' . get_permalink ( $post->ID ));
  47.                 exit;
  48.             }
  49.            
  50.         }
  51.  
  52.         if ( isset( $_GET['content-only'] ) && is_singular() ) {
  53.             the_post();
  54.             echo '<html><head><meta name="robots" value="noindex,nofollow" />';
  55.             echo "<h1>";
  56.             the_title();
  57.             echo "</h1>";
  58.             if ( ! empty( $_GET['js'] ) ) {
  59.                 wp_print_scripts();
  60.             }
  61.             if ( ! empty( $_GET['css'] ) ) {
  62.                 wp_head();
  63.                 wp_print_styles();
  64.                 if ( function_exists( 'post_class' ) ) {
  65.                     echo '</head><body ';
  66.                     post_class();
  67.                     echo '>';
  68.                 } else {
  69.                     echo '</head><body>';
  70.                 }
  71.             } else {
  72.  
  73.             }
  74.  
  75.             if ( isset( $_GET['plain'] ) ) {
  76.                 echo $this->get_the_content();
  77.             } else {
  78.                 $this->the_content();
  79.             }
  80.  
  81.             if ( isset( $_GET['tags'] ) ) {
  82.                 the_tags( '<ul><li>', '</li><li>', '</li></ul>' );
  83.             }
  84.  
  85.             if ( isset( $_GET['categories'] ) ) {
  86.                 the_category();
  87.             }
  88.             echo '</body></html>';
  89.             die();
  90.         }
  91.     }
  92.  
  93.     function meta_box() {
  94.         $args = array(
  95.             'public' => true
  96.         );
  97.         $types = get_post_types( $args );
  98.         foreach ( $types as $type ) {
  99.         add_meta_box( 'contentonly', __( 'Show Content Only Links', 'show-content-only' ), array(
  100.                 $this,
  101.                 'links'
  102.             ), $type, 'side', 'high' );
  103.         }
  104.     }
  105.  
  106.     // Meta box content
  107.     function links() {
  108.         global $post;
  109.         if ( isset( $post->ID ) && $post->ID != 0 ) {
  110.             $p     = $post->post_type == 'page' ? 'page_id' : 'p';
  111.             $links = array(
  112.                 __('Content only', 'show-content-only') => array(
  113.                     $p             => $post->ID,
  114.                     'content-only' => true
  115.                 ),
  116.                 __('Content + Styles', 'show-content-only')           => array(
  117.                     $p             => $post->ID,
  118.                     'content-only' => true,
  119.                     'css'          => true
  120.                 ),
  121.                 __('Content + Tags', 'show-content-only')             => array(
  122.                     $p             => $post->ID,
  123.                     'content-only' => true,
  124.                     'tags'         => true
  125.                 ),
  126.                 __('Content + Categories', 'show-content-only')       => array(
  127.                     $p             => $post->ID,
  128.                     'content-only' => true,
  129.                     'categories'   => true
  130.                 ),
  131.                 __('Content, Tags & Categories', 'show-content-only') => array(
  132.                     $p             => $post->ID,
  133.                     'content-only' => true,
  134.                     'categories'   => true,
  135.                     'tags'         => true
  136.                 ),
  137.             );
  138.             if ( $links ) {
  139.                 echo '<ul>';
  140.                 foreach ( $links as $name => $link ) {
  141.                     $link = htmlentities( add_query_arg( $link, get_option( 'home' ) . '/' ) );
  142.                     echo '<li><a href="' . $link . '" class="button button-small">' . esc_html( $name ) . '</a></li>';
  143.                 }
  144.                 echo '</ul>';
  145.             }
  146.         } else {
  147.             echo '<p>' . esc_html__( 'You must publish or save this post before Show Content Only links become available.', 'show-content-only' ) . '</p>';
  148.         }
  149.     }
  150.  
  151.     /**
  152.      * Display the post content.
  153.      *
  154.      * @since 0.71
  155.      *
  156.      * @param string $more_link_text Optional. Content for when there is more text.
  157.      * @param string $stripteaser Optional. Teaser content before the more text.
  158.      * @param string $more_file Optional. Not used.
  159.      */
  160.     function the_content( $more_link_text = null, $stripteaser = 0, $more_file = '' ) {
  161.         $content = $this->get_the_content( $more_link_text, $stripteaser, $more_file );
  162.         $content = apply_filters( 'the_content', $content );
  163.         $content = str_replace( ']]>', ']]&gt;', $content );
  164.         echo $content;
  165.     }
  166.  
  167.     /**
  168.      * Retrieve the post content.
  169.      *
  170.      * @since 0.71
  171.      *
  172.      * @param string $more_link_text Optional. Content for when there is more text.
  173.      * @param string $stripteaser Optional. Teaser content before the more text.
  174.      * @param string $more_file Optional. Not used.
  175.      *
  176.      * @return string
  177.      */
  178.     function get_the_content( $more_link_text = null, $stripteaser = 0, $more_file = '' ) {
  179.         global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
  180.  
  181.         if ( null === $more_link_text ) {
  182.             $more_link_text = __( '(more...)', 'show-content-only' );
  183.         }
  184.  
  185.         $output    = '';
  186.         $hasTeaser = false;
  187.  
  188.         // If post password required and it doesn't match the cookie.
  189.         if ( post_password_required( $post ) ) {
  190.             $output = get_the_password_form();
  191.  
  192.             return $output;
  193.         }
  194.  
  195.         if ( $more_file != '' ) {
  196.             $file = $more_file;
  197.         } else {
  198.             $file = $pagenow;
  199.         } //$_SERVER['PHP_SELF'];
  200.  
  201.         if ( $page > count( $pages ) ) // if the requested page doesn't exist
  202.         {
  203.             $page = count( $pages );
  204.         } // give them the highest numbered page that DOES exist
  205.  
  206.         $content = $pages[ $page - 1 ];
  207.         if ( preg_match( '/<!--more(.*?)?-->/', $content, $matches ) ) {
  208.             $content = explode( $matches[0], $content, 2 );
  209.             if ( ! empty( $matches[1] ) && ! empty( $more_link_text ) ) {
  210.                 $more_link_text = strip_tags( wp_kses_no_null( trim( $matches[1] ) ) );
  211.             }
  212.  
  213.             $hasTeaser = true;
  214.         } else {
  215.             $content = array( $content );
  216.         }
  217.         if ( ( false !== strpos( $post->post_content, '<!--noteaser-->' ) && ( ( ! $multipage ) || ( $page == 1 ) ) ) ) {
  218.             $stripteaser = 1;
  219.         }
  220.         $teaser = $content[0];
  221.         if ( ( $more ) && ( $stripteaser ) && ( $hasTeaser ) ) {
  222.             $teaser = '';
  223.         }
  224.         $output .= $teaser;
  225.         if ( count( $content ) > 1 ) {
  226.             if ( $more ) {
  227.                 $output .= '<span id="more-' . $id . '"></span>' . $content[1];
  228.             } else {
  229.                 if ( ! empty( $more_link_text ) ) {
  230.                     $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\" rel=\"nofollow\">$more_link_text</a>", $more_link_text );
  231.                 }
  232.                 $output = force_balance_tags( $output );
  233.             }
  234.  
  235.         }
  236.         if ( $preview ) // preview fix for javascript bug with foreign languages
  237.         {
  238.             $output = preg_replace_callback( '/\%u([0-9A-F]{4})/', create_function( '$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";' ), $output );
  239.         }
  240.  
  241.         $output = do_shortcode( $output );
  242.  
  243.         return $output;
  244.     }
  245. }
  246.  
  247. new ShowContentOnly;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement