Plugin Directory

Changeset 2170794

Timestamp:
10/09/2019 07:20:20 PM (5 years ago)
Author:
ajku99
Message:

0.2 version released

Location:
new-page-comments
Files:
25 added
6 edited

Legend:

Unmodified
Added
Removed
  • new-page-comments/trunk/assets/cmnt.css

    r2146074 r2170794  
    1919    vertical-align: middle;
    2020    margin-right: 10px;
     21
    2122}
    2223
  • new-page-comments/trunk/changelog.txt

    r2146074 r2170794  
    11== Changelog ==
     2
     3
     4
     5
     6
     7
    28= 0.1 =
    39* Initial version
  • new-page-comments/trunk/include/comment-load-template.php

    r2146074 r2170794  
    66$post_slug=$post->post_name;
    77$post_id = $post->ID;
     8
    89$commentCount = get_comments_number($post_id);
    9 $commentCountText = $commentCount." COMMENTS";
     10$commentCountText = $commentCount." ";
    1011 if($commentCount==0 || $commentCount==1){
    11     $commentCountText = $commentCount." COMMENT";
     12    $commentCountText = $commentCount." ";
    1213 }
    1314 $postName = $post->post_name;
    1415?><div class="npcmnt-wrap" id="npc-comments">
    1516    <?php
    16     if(NPCMNT_ADMIN::get_options_data('need_read_comment')=='true'){ ?>
    17     <a class='load-comment' href='<?php echo home_url('/comments/'.$postName); ?>' data-postid='<?php echo $post_id; ?>'><span>READ <?php echo $commentCountText; ?> </span></a>
    18 <?php } ?>
    19     <a class='load-comment' href='<?php echo home_url('/comments/'.$postName); ?>' data-postid='<?php echo $post_id; ?>'><span"><?php echo esc_html__(NPCMNT_ADMIN::get_options_data('comment-btn-txt'), 'new-page-comments'); ?></span></a>
    20 </div>
     17    if( $settings['comment-load-type']== 'new_page' ){
     18        $slug = sanitize_title(NPCMNT_ADMIN::get_options_data('slug'));
     19        if(NPCMNT_ADMIN::get_options_data('need_read_comment')=='true'){
     20            ?>
     21        <a class='load-comment' href='<?php echo esc_url(home_url('/'.$slug.'/'.$postName)); ?>' data-postid='<?php echo esc_attr($post_id); ?>'><span> <?php echo esc_html__('READ', 'new-page-comments')." ".esc_html($commentCountText); ?> </span></a>
     22    <?php } ?>
     23        <a class='load-comment' href='<?php echo esc_url(home_url('/'.$slug.'/'.$postName)); ?>' data-postid='<?php echo esc_attr($post_id); ?>'><span"><?php echo esc_html__(NPCMNT_ADMIN::get_options_data('comment-btn-txt'), 'new-page-comments'); ?></span></a>
     24    <?php
     25    }else{
     26        echo "<span class='npc-lazy-load-comment'>
     27                <span class='load-comment' data-postid='".esc_attr( $post_id )."'>".esc_html__('Show', 'new-page-comments')." ".$commentCountText." </span>
     28            </span>";
     29    }
     30    ?>
     31  </div><?php
  • new-page-comments/trunk/include/settings.php

    r2146074 r2170794  
    1313            add_action('admin_menu', array( $this, 'settings_pages') );
    1414            add_action( 'admin_init', array( $this, 'register_newpagecomment') );
     15
     16
     17
     18
    1519        }
    1620    }
    1721
    18     public static function get_options_data($setting_name=null){
     22    public  function admin_script_option_page($hook){
     23        if($hook != 'settings_page_new-page-comment') {
     24            return ;
     25        }
     26        wp_enqueue_style( 'npc_admin_script', NPCMNT_URL.'assets/admin-main.css', array(), NPC_VERSION, 'all' );
     27        wp_enqueue_script( 'npc_admin_script', NPCMNT_URL.'assets/admin-main.js', array('jquery'), NPC_VERSION, true );
     28    }
     29
     30    public static function get_options_data($setting_name=null, $single=false){
    1931        $defaultValues = array(
     32
    2033                        'comment-btn-txt'=> 'Post a comment',
    2134                        'slug' => 'comments',
    22                         'need_read_comment'=> 'true'
     35                        'need_read_comment'=> 'true'
    2336                        );
    2437        $options = get_option( 'new-page-comment-opt' );
     
    2740            return $options[$setting_name];
    2841        }
    29         return '';
     42        if($single){
     43            return $options;
     44        }else{
     45            return '';
     46        }
    3047    }
    3148    function add_action_links($links){
     
    4259            'manage_options', 'new-page-comment', array($this, 'settings_page') );
    4360    }
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
    4494
    4595    function settings_page(){
     
    4797            return ;
    4898        }
    49         $this->options = get_option( 'new-page-comment-opt' );
     99        $this->options = self::get_options_data(null, true);//get_option( 'new-page-comment-opt' );
     100        $tab = $this->npc_get_tab('general', array('general','help'));
    50101        ?>
    51         <div class="wrap">
    52             <h2><?php echo esc_html__("New page comments", 'new-page-comments'); ?><hr></h2>
     102        <div class="npc-main-wrapper wrap">
     103            <h2><?php echo esc_html__("New page comments", 'new-page-comments'); ?></h2>
     104            <br/>
     105            <div class="nav-tab-wrapper npc-main-wrapper">
     106                <?php
     107                echo '<a href="' . esc_url($this->npc_admin_link('general')) . '" class="nav-tab ' . esc_attr( $tab == 'general' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-dashboard"></span> ' . esc_html__('General', 'new-page-comments') . '</a>';
     108                echo '<a href="' . esc_url($this->npc_admin_link('help')) . '" class="nav-tab ' . esc_attr( $tab == 'help' ? 'nav-tab-active' : '') . '"><span class="dashicons dashicons-editor-help"></span> ' . esc_html__('Help','npc-for-wp') . '</a>';
     109                ?>
     110            </div>
    53111            <form method="post" action="options.php">
     112
    54113                <?php
    55114                settings_fields( 'new-page-comment-group' );
     115
    56116                do_settings_sections( 'new-page-comment-page' );
     117
     118
     119
     120
    57121                submit_button(); ?>
     122
    58123            </form>
    59124            </div>
     
    69134                }
    70135            }
    71             var operation = perform_Checkbox
    72136        </script>
    73137            <?php
     
    86150            'new-page-comment-page' // Page
    87151        ); 
     152
     153
     154
     155
     156
     157
     158
     159
    88160
    89161        add_settings_field(
     
    119191    {
    120192        $new_input = array();
     193
     194
     195
    121196        if( isset( $input['comment-btn-txt'] ) )
    122197            $new_input['comment-btn-txt'] = sanitize_text_field( $input['comment-btn-txt'] );
    123198
    124199        if( isset( $input['slug'] ) )
    125             $new_input['slug'] = sanitize_text_field( $input['slug'] );
     200            $new_input['slug'] = sanitize_t( $input['slug'] );
    126201
    127202        if( isset( $input['need_read_comment'] ) )
     
    136211    public function print_section_info()
    137212    {
    138         print esc_html__('Enter your settings below:','new-page-comments');
    139     }
    140 
     213        print esc_html__('','new-page-comments');
     214    }
     215
     216    /**
     217     * Get the settings option array and print one of its values
     218     */
     219    public function cmnt_lazy_load_callback()
     220    {
     221        if(!isset( $this->options['comment-load-type'] ) ){
     222            $this->options['comment-load-type'] = 'new_page';
     223        }
     224        printf(
     225            '<label><input type="radio" id="comment-lazy-load-switch" name="new-page-comment-opt[comment-load-type]" value="lazy_load" %s />%s</label>',
     226            isset( $this->options['comment-load-type'] ) && $this->options['comment-load-type']=='lazy_load'? "checked" : '',
     227            esc_html__('Load comment via Ajax on same page','new-page-comments')
     228        );
     229
     230        printf(
     231            '<label><input type="radio" id="comment-new-page-switch" name="new-page-comment-opt[comment-load-type]" value="new_page" %s />%s</label>',
     232            isset( $this->options['comment-load-type'] ) && $this->options['comment-load-type']=='new_page'? "checked" : '',
     233            esc_html__('Load comment on new page','new-page-comments')
     234        );
     235    }
     236    /**
     237     * Get the settings option array and print one of its values
     238     */
     239    public function cmnt_new_page_load_callback()
     240    {
     241       
     242    }
    141243    /**
    142244     * Get the settings option array and print one of its values
     
    157259        printf(
    158260            '<input type="text" id="slug" name="new-page-comment-opt[slug]" value="%s" />',
    159             isset( $this->options['slug'] ) ? esc_attr( $this->options['slug']) : esc_html__('comments','new-page-comments')
     261            isset( $this->options['slug'] ) ? esc_attr( $this->options['slug']) : esc_comments')
    160262        );
    161263    }
     
    169271        echo "<input type='hidden' id='need_read_comment' name='new-page-comment-opt[need_read_comment]' value='". (isset( $this->options['need_read_comment'] )? 'true': 'false') ."'>";
    170272    }
     273
     274
     275
     276
     277
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
    171355}
    172356$npc_cmnt_admin = new NPCMNT_ADMIN();
  • new-page-comments/trunk/new-page-comments.php

    r2146074 r2170794  
    55 Author: easetousers
    66 Author URI: http://easetousers.com
    7  Version: 0.1
     7 Version: 0.
    88 Donate link: https://paypal.me/Ajeet260/25
    99 License: GPL2+
     
    1515}
    1616
    17 define( 'NPC_VERSION', '0.1' );
     17define( 'NPC_VERSION', '0.' );
    1818
    1919define( 'NPCMNT__FILE__', __FILE__ );
     
    2525add_action("plugins_loaded", 'npc_load_init');
    2626function npc_load_init(){
     27
    2728    $obj = new NPC_class();
    2829    $obj->init();
    2930}
    30 class NPC_class{
    31     public function init(){
    32         add_filter('comments_template', array($this, 'new_page_load_comment_section'), 999);
    33         add_action( 'wp_enqueue_scripts', array($this, 'load_script_style') );
    34         require_once NPCMNT_PATH . "include/settings.php";
    35 
    36 
    37         add_action( 'init',  array($this, 'new_page_load_prefix_movie_rewrite_rule'), 30) ;
    38         add_filter( 'query_vars',  array($this, 'new_page_load_prefix_register_query_var'), 20, 1);
    39         add_filter( 'template_include', array($this, 'new_page_load_prefix_url_rewrite_templates'), 1, 1);
    40     }
    41 
    42     public function new_page_load_comment_section($file){
    43         update_option('npc_load_comment', $file);
    44         $file = NPCMNT_PATH . 'include/comment-load-template.php';
    45          return $file;
    46     }
    47 
    48 
    49     function load_script_style() {
    50         if ( (is_singular() || get_query_var( 'npte' )=='load_comments' ) && comments_open() && get_option( 'thread_comments' ) ) {
    51             wp_enqueue_style( 'npcmnt-comment', NPCMNT_URL . '/assets/cmnt.css', array(), '1.1', 'all');
    52         }
    53     }
    54 
    55     function new_page_load_prefix_movie_rewrite_rule() {
    56         $slug = NPCMNT_ADMIN::get_options_data('slug');
    57         add_rewrite_rule( '^'.$slug.'\/([^/]+)\/?$', 'index.php?cp_slug=$matches[1]&npte=load_comments', 'top' );
    58         flush_rewrite_rules( false );
    59     }
    60 
    61 
    62     function new_page_load_prefix_register_query_var( $vars ) {
    63         $vars[] = 'cp_slug';
    64         $vars[] = 'npte';
    65         return $vars;
    66     }
    67 
    68 
    69     function new_page_load_prefix_url_rewrite_templates($template){
    70         if ( get_query_var( 'npte' )=='load_comments' ) {
    71             add_action('parse_query', array($this, 'comment_parse_query'));
    72         //remove_action('wp_head', 'saswp_data_generator');
    73             $template = NPCMNT_PATH . '/include/new-page-comment-template.php';
    74         }
    75         return $template;
    76     }
    77 
    78     function comment_parse_query($query){
    79         if(is_main_query()){
    80             $commentPost = get_query_var( 'cp_slug' );
    81             $query->post_name = $commentPost;
    82             $query->post_type = 'any';
    83             $query->is_single = true;
    84         }
    85     }
    86 
    87 }
  • new-page-comments/trunk/readme.txt

    r2152911 r2170794  
    55Requires at least: 3.0
    66Tested up to: 5.2.2
    7 Stable tag: 0.1
     7Stable tag: 0.
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.