Plugin Directory

Changeset 1108642


Ignore:
Timestamp:
03/09/2015 08:33:32 AM (11 years ago)
Author:
viktormorales
Message:

Avoiding "File already exists"

Location:
vhm-show-comments/trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • vhm-show-comments/trunk/readme.txt

    r1108186 r1108642  
    44Requires at least: 3.1
    55Tested up to: 4.1
    6 Stable tag: trunk
     6Stable tag: 1.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    24241. Activate the plugin
    25251. Go to `Settings > VHM Show Comments` for further information
     26
     27== Changelog ==
     28
     29= 1.2 =
     30*Release Date - 8th March 2015*
     31
     32* NEW: Added ORDER BY DESCENDANT/ASCENDANT/RANDOM option
     33* NEW: Spanish translation
     34
     35= 1.1 =
     36*Release Date - 8th March, 2015*
     37
     38* Some visual changes
  • vhm-show-comments/trunk/settings.php

    r1108217 r1108642  
    4747                    </tr>
    4848                    <tr valign="top">
    49                         <th scope="row"><label for="before_items"><?php _e('Before items', 'vhm-show-comments')?></label></th>
     49                        <th scope="row"><label for="order"><?php _e('Order by', 'vhm-show-comments')?></label></th>
    5050                        <td>
    51                             <input type="text" name="vhmShowCommentsSettings[before_items]" id="show_quantity" value="<?php echo (!empty($options['before_items'])) ? esc_attr($options['before_items']) : '<ol>' ; ?>" />
     51                            <select name="vhmShowCommentsSettings[order]">
     52                                <option value="DESC"<?php echo ($options['order'] == 'DESC') ? ' selected="selected"' : false ; ?>><?php _e('Descendant', 'vhm-show-comments'); ?></option>
     53                                <option value="ASC"<?php echo ($options['order'] == 'ASC') ? ' selected="selected"' : false ; ?>><?php _e('Ascendant', 'vhm-show-comments'); ?></option>
     54                                <option value="RAND"<?php echo ($options['order'] == 'RAND') ? ' selected="selected"' : false ; ?>><?php _e('Random', 'vhm-show-comments'); ?></option>
     55                            </select>
     56                            <p class="description"><?php _e('Choose how the comments should be ordered', 'vhm-show-comments'); ?></p>
     57                        </td>
     58                    </tr>
     59                    <tr valign="top">
     60                        <th scope="row"><label for="before_items"><?php _e('Before items', 'vhm-show-comments'); ?></label></th>
     61                        <td>
     62                            <input type="text" name="vhmShowCommentsSettings[before_items]" id="before_items" value="<?php echo (!empty($options['before_items'])) ? esc_attr($options['before_items']) : '<ol>' ; ?>" />
    5263                            <p class="description">
    5364                                <?php
     
    7182                            <p class="description"><?php _e('%URL% is the URL provided by the author of the comment', 'vhm-show-comments'); ?></p>
    7283                            <p class="description"><?php _e('%AUTHOR% is the name of the author of the comment', 'vhm-show-comments'); ?></p>
     84                            <p class="description"><?php _e('%POST_TITLE% is the title of the post where the user left the comment', 'vhm-show-comments'); ?></p>
     85                            <p class="description"><?php _e('%POST_URL% is the URL of the post where the user left the comment', 'vhm-show-comments'); ?></p>
    7386                        </td>
    7487                    </tr>
  • vhm-show-comments/trunk/vhm-show-comments.php

    r1108217 r1108642  
    44 * Plugin URI: http://viktormorales.com
    55 * Description: Show comments on your pages, posts, sidebar with a shortcode or PHP code
    6  * Version: 1.1
     6 * Version: 1.2
    77 * Author: Viktor H. Morales
    88 * Author URI: http://viktormorales.com
     
    101101                $new_input['show_quantity'] = absint( $input['show_quantity'] );
    102102               
     103            if( isset( $input['order'] ) )
     104                $new_input['order'] = $input['order'];
     105               
    103106            if( isset( $input['before_items'] ) )
    104107                $new_input['before_items'] = $input['before_items'];
     
    128131        public function output( $atts = false )
    129132        {
     133            global $wpdb;
     134           
    130135            // Get the shortcode/function arguments
    131136            extract( shortcode_atts( array(
    132137                'number' => ($number) ? $number : $this->options['show_quantity'],
    133138                'id' => ($id) ? $id : false,
    134                 'post_id' => ($post_id) ? $post_id : false
     139                'post_id' => ($post_id) ? $post_id : false,
     140                'order' => ($oder) ? 'DESC' : $this->options['order']
    135141            ), $atts ) );
    136142           
     
    138144            $out = $this->options['before_items'];
    139145           
     146            $sql = 'SELECT * FROM wp_comments WHERE comment_approved="1"';
    140147            if ($id)
    141148            {
    142                 $comment = get_comment($id);
    143                 $out .= str_replace(
    144                     array( "%COMMENT%", "%URL%", "%AUTHOR%" ),
    145                     array( $comment->comment_content, $comment->comment_author_url, $comment->comment_author ),
    146                     $this->options['items_template']
    147                 );
     149                $sql .= ' AND comment_ID = ' . $id;
     150                $sql .= ' LIMIT 1';
    148151            }
    149             else
     152            else 
    150153            {
    151                 $comments = get_comments('&status=approve&number=' . $number . '&post_id=' . $post_id);
    152                 if ($comments):
    153                     foreach ($comments as $comment)
    154                     {
    155                         $out .= str_replace(
    156                             array( "%COMMENT%", "%URL%", "%AUTHOR%" ),
    157                             array( $comment->comment_content, $comment->comment_author_url, $comment->comment_author ),
    158                             $this->options['items_template']
    159                         );
    160                     }
    161                 endif;
     154                if ($post_id)
     155                    $sql .= ' AND comment_post_ID = ' . $post_id;
     156                if ($order == 'ASC' || $order == 'DESC')
     157                    $sql .= ' ORDER BY comment_ID ' . $order;
     158                else
     159                    $sql .= ' ORDER BY RAND()';
     160                if ($number)
     161                    $sql .= ' LIMIT ' . $number;
    162162            }
     163           
     164            $comments = $wpdb->get_results( $sql, OBJECT );
     165            if ($comments):
     166                foreach ($comments as $comment)
     167                {
     168                    $out .= str_replace(
     169                        array( "%COMMENT%", "%URL%", "%AUTHOR%", "%POST_URL%", "%POST_TITLE%" ),
     170                        array( $comment->comment_content, $comment->comment_author_url, $comment->comment_author, get_permalink($comment->comment_post_ID), get_the_title($comment->comment_post_ID) ),
     171                        $this->options['items_template']
     172                    );
     173                }
     174            endif;
    163175           
    164176            // Print the after_items option
Note: See TracChangeset for help on using the changeset viewer.