Plugin Directory

Changeset 766128


Ignore:
Timestamp:
09/03/2013 07:09:07 AM (12 years ago)
Author:
laki_patel
Message:

Fix security issues

Location:
indianic-testimonial/trunk
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • indianic-testimonial/trunk/testimonial.php

    r632107 r766128  
    3131    add_action('wp_ajax_iNIC_testimonial_save', array($this, 'iNIC_testimonial_save'));
    3232    add_action('wp_ajax_iNIC_testimonial_save_setting', array($this, 'iNIC_testimonial_save_setting'));
    33     add_action('wp_ajax_iNIC_testimonial_delete', array($this, 'iNIC_testimonial_delete'));
    3433    add_action('wp_ajax_iNIC_testimonial_save_widget', array($this, 'iNIC_testimonial_save_widget'));
    3534    add_action('wp_ajax_iNIC_testimonial_delete_widget', array($this, 'iNIC_testimonial_delete_widget'));
     
    4241      add_action('admin_head', array($this, 'include_js'));
    4342    }
    44 
    45     require_once 'paginate.class.php';
    4643  }
    4744
     
    127124      }
    128125
    129       $_no_of_testimonial = $_template_data['no_of_testimonial'] ? $_template_data['no_of_testimonial'] : false;
    130       if ($_no_of_testimonial) {
    131         $_testimonial_result = $this->wpdb->get_results("SELECT * FROM {$this->wpdb->prefix}inic_testimonial WHERE (id NOT IN(" . implode(",", $_current_featured_testimonial_id) . ")){$filter_by} ORDER BY {$_template_data['ord_by']} LIMIT {$_no_of_testimonial}");
    132       } else {
     126      $_no_of_testimonial = $_template_data['no_of_testimonial'] ? " LIMIT {$_template_data['no_of_testimonial']}" : false;
     127      $_testimonial_result = $this->wpdb->get_results("SELECT * FROM {$this->wpdb->prefix}inic_testimonial WHERE (id NOT IN(" . implode(",", $_current_featured_testimonial_id) . ")){$filter_by} ORDER BY {$_template_data['ord_by']}{$_no_of_testimonial}");
     128      if (!$_no_of_testimonial || $_template_data['list_per_page']) {
     129
     130        $_record_per_page = $_template_data['list_per_page'] ? $_template_data['list_per_page'] : 20;
     131        $_array_chunk = array_chunk($_testimonial_result, $_record_per_page);
     132        $_total_pages = count($_array_chunk);
    133133        $_current_page = (isset($_GET[$this->blog_page_pagination_key]) && $_GET[$this->blog_page_pagination_key] > 0) ? $_GET[$this->blog_page_pagination_key] : 1;
    134         $testimonials = new iNICpagination($_current_page, "SELECT * FROM {$this->wpdb->prefix}inic_testimonial WHERE (id NOT IN(" . implode(",", $_current_featured_testimonial_id) . ")){$filter_by} ORDER BY {$_template_data['ord_by']}");
    135         $testimonials->link_prefix = "{$_SERVER['REDIRECT_URL']}?{$this->blog_page_pagination_key}=";
    136         $testimonials->results_per_page = $_template_data['list_per_page'] ? $_template_data['list_per_page'] : 1000;
    137         $_pagination = $testimonials->paginate();
    138 
    139         $_testimonial_result = array();
    140 
    141         if ($testimonials->total_results) {
    142           while ($_row = mysql_fetch_object($testimonials->resource())) {
    143             $_testimonial_result[] = $_row;
    144           }
    145         }
    146       }
     134        $_current_page = $_total_pages < $_current_page ? $_total_pages : $_current_page;
     135
     136        $_testimonial_result = isset($_array_chunk[$_current_page - 1]) && $_array_chunk[$_current_page - 1] ? $_array_chunk[$_current_page - 1] : $_array_chunk[0];
     137        $_pagination = "";
     138       
     139        if ($_total_pages > 1) {
     140          $_pagination .= "<div class='testimonial_pagination'>";
     141         
     142          if($_current_page > 1) {
     143            $_pagination .= "<a href=\"?".build_query(array_merge($_REQUEST, array($this->blog_page_pagination_key => 1)))."\" title=\"Go to the first page\" class=\"first-page\">&laquo;</a> ";
     144            $_pagination .= "<a href=\"?".build_query(array_merge($_REQUEST, array($this->blog_page_pagination_key => ($_current_page - 1))))."\" title=\"Go to the previous page\" class=\"prev-page\">&lsaquo;</a> ";
     145          }
     146         
     147          for ($i = 1; $i <= $_total_pages; ++$i) {
     148            $_url_prefix = build_query(array_merge($_REQUEST, array($this->blog_page_pagination_key => $i)));
     149            $_is_active = $_current_page == $i ? ' class="current-page"' : '';
     150            $_pagination .= "<a href=\"?{$_url_prefix}\"{$_is_active}>{$i}</a> ";
     151          }
     152         
     153          if($_current_page < $_total_pages) {
     154            $_pagination .= "<a href=\"?".build_query(array_merge($_REQUEST, array($this->blog_page_pagination_key => ($_current_page + 1))))."\" title=\"Go to the next page\" class=\"next-page\">&rsaquo;</a> ";
     155            $_pagination .= "<a href=\"?".build_query(array_merge($_REQUEST, array($this->blog_page_pagination_key => $_total_pages)))."\" title=\"Go to the last page\" class=\"last-page\">&raquo;</a> ";
     156          }
     157         
     158          $_pagination .= "</div>";
     159        }
     160
     161      }
     162
    147163      if ($_testimonial_result) {
    148164        $i = 0;
     
    207223      $data['error'] = mysql_error();
    208224    } else {
    209       if($this->wpdb->insert_id) {
     225      if ($this->wpdb->insert_id) {
    210226        $data['form_reset'] = true;
    211227      }
     
    325341  }
    326342
    327   public function iNIC_testimonial_delete() {
    328     if (isset($_POST['id']) && $_POST['id']) {
    329       $this->wpdb->query("DELETE FROM {$this->wpdb->prefix}inic_testimonial WHERE id='{$_POST['id']}'");
    330       if (mysql_error()) {
    331         $data['error'] = mysql_error();
    332       } else {
    333         $data['success'] = "The testimonial has been delete successfully.";
    334       }
    335       echo json_encode($data);
    336     }
    337     die();
    338   }
    339 
    340343  public function testimonial_register_menu() {
    341344    add_menu_page('Testimonial', 'Testimonial', 'administrator', "inic_testimonial_view", array($this, 'testimonial_view'), $this->pluginUrl . "icon.png");
     
    345348    add_submenu_page("inic_testimonial_view", "Widget Template", "Widget Template", 'administrator', "inic_testimonial_widget_template", array($this, 'inic_testimonial_widget_template'));
    346349    add_submenu_page("inic_testimonial_view", "Settings", "Settings", 'administrator', "inic_testimonial_settings", array($this, 'testimonial_settings'));
     350   
     351    require_once "{$this->pluginPath}/listing_data_table.php";
     352    $this->tbl = new listing_data_table();
    347353  }
    348354
     
    524530require_once 'widget.php';
    525531add_action('widgets_init', create_function('', 'register_widget( "iNIC_TestimonialWidget" );'));
     532
     533
     534if (!function_exists('array_chunk')) {
     535
     536  function array_chunk($input, $size, $preserve_keys = false) {
     537    @reset($input);
     538
     539    $i = $j = 0;
     540
     541    while (@list( $key, $value ) = @each($input)) {
     542      if (!( isset($chunks[$i]) )) {
     543        $chunks[$i] = array();
     544      }
     545
     546      if (count($chunks[$i]) < $size) {
     547        if ($preserve_keys) {
     548          $chunks[$i][$key] = $value;
     549          $j++;
     550        } else {
     551          $chunks[$i][] = $value;
     552        }
     553      } else {
     554        $i++;
     555
     556        if ($preserve_keys) {
     557          $chunks[$i][$key] = $value;
     558          $j++;
     559        } else {
     560          $j = 0;
     561          $chunks[$i][$j] = $value;
     562        }
     563      }
     564    }
     565
     566    return $chunks;
     567  }
     568
     569}
  • indianic-testimonial/trunk/view.php

    r563885 r766128  
    11<?php
    2 $_current_page = (isset($_GET['p']) && $_GET['p'] > 0) ? $_GET['p'] : 1;
    32
    4 if(isset($_GET['s']) && $_GET['s']) {
    5   $_s = trim($_GET['s']);
    6   $_where = " WHERE (project_name LIKE '%{$_s}%' || client_name LIKE '%{$_s}%' || city LIKE '%{$_s}%' || state LIKE '%{$_s}%' || country LIKE '%{$_s}%')";
    7 } else {
    8   $_s = $_where = "";
     3if (isset($_GET['id']) && $_GET['id'] && isset($_GET['action']) && $_GET['action'] == 'delete') {
     4  $this->wpdb->query("DELETE FROM {$this->wpdb->prefix}inic_testimonial WHERE id={$_GET['id']}");
     5  if ($this->wpdb->rows_affected) {
     6    $_data['updated'] = "The testimonial has been deleted successfully.";
     7  }
    98}
    10 $_ord_by = get_option("inic_testimonial_list_ord_by") ? " ORDER BY ".get_option("inic_testimonial_list_ord_by") : "";
    11 $testimonials = new iNICpagination($_current_page, "SELECT * FROM {$this->wpdb->prefix}inic_testimonial{$_where}{$_ord_by}");
    12 $testimonials->link_prefix = "admin.php?page=inic_testimonial_view&p=";
    13 $testimonials->results_per_page = get_option("inic_testimonial_admin_list_per_page");
    14 $_pagination = $testimonials->paginate();
     9   
     10$_ord_by = get_option("inic_testimonial_list_ord_by") ? " ORDER BY " . get_option("inic_testimonial_list_ord_by") : "";
     11$_result_per_page = get_option("inic_testimonial_admin_list_per_page");
    1512?>
    1613
    1714<div class="wrap">
    1815  <div id="icon-edit" class="icon32 icon32-posts-post"><br></div>
    19   <h2>View Testimonials</h2>
     16  <h2>View Testimonials test</h2>
    2017
    21   <div id="message" class="updated below-h2" style="display:none;"><p></p></div>
     18  <?php
     19  if(isset($_data) && is_array($_data)) {
     20    foreach($_data as $_message_type => $_message) {
     21      echo '<div id="message" class="'.$_message_type.' below-h2"><p>'.$_message.'</p></div>';
     22    }
     23  }
     24  ?>
    2225
    23   <div class="tablenav top">
    24     <form class="alignleft actions" method="GET" action="">
    25       <input type="hidden" name="page" value="inic_testimonial_view">
    26       <input type="text" id="post-search-input" name="s" value="<?php echo $_s; ?>">
    27       <input type="submit" name="" id="search-submit" class="button" value="Search Testimonial">
    28     </form>
     26  <div class="col-wrap">
     27    <div class="form-wrap">
     28      <?php
     29      if($_result_per_page > 0) {
     30        $this->tbl->row_per_page = $_result_per_page;
     31      }
     32      $this->tbl->set_mysql_query("SELECT * FROM {$this->wpdb->prefix}inic_testimonial{$_ord_by}");
     33      $this->tbl->set_mysql_search_query("SELECT * FROM {$this->wpdb->prefix}inic_testimonial WHERE project_name LIKE '%{#S}%' || client_name LIKE '%{#S}%' || city LIKE '%{#S}%' || state LIKE '%{#S}%' || country LIKE '%{#S}%'{$_ord_by}");
    2934
    30     <div class="tablenav-pages"><span class="displaying-num"><?php echo $testimonials->total_results; ?> items</span>
    31       <span class="pagination-links">
    32         <?php echo $_pagination; ?>
     35      $this->tbl->add_col('project_name', "Project Name", true);
     36      $this->tbl->display_col_function(function($item, $column_name) {
     37                $item['is_featured'] = $item['is_featured'] ? "<br /><code style=\"color:#C00;\"> Featured </code>" : "";
     38                return "<a href=\"{$item['project_url']}\" target=\"blank\">{$item['project_name']}</a><br /><i>[ {$item['tags']} ]{$item['is_featured']}</i>";
     39              });
     40
     41      $this->tbl->add_col('client_name', "Client Name", true);
     42      $this->tbl->display_col_function(function($item, $column_name) {
     43                $item['city'] = $item['city'] ? "<br /><i>[ City: {$item['city']} ]</i>" : "";
     44                $item['state'] = $item['state'] ? "<br /><i>[ State: {$item['state']} ]</i>" : "";
     45                $item['country'] = $item['country'] ? "<br /><i>[ Country: {$item['country']} ]</i>" : "";
     46                return "{$item['client_name']}{$item['city']}{$item['state']}{$item['country']}";
     47              });
     48
     49      $this->tbl->add_col_action('Edit', array('id' => false, 'url' => '?page=inic_testimonial_add'));
     50      $this->tbl->add_col_action('Delete', array('action' => 'delete', 'id' => false));
     51
     52      $this->tbl->add_col('description', "Description");
     53
     54      $this->tbl->add_col('video_url', "Video URL");
     55
     56      $this->tbl->add_col('thumb_img_url', "Thumb Image");
     57      $this->tbl->display_col_function(function($item, $column_name) {
     58                return $item['thumb_img_url'] ? "<a href=\"{$item['large_img_url']}\" target=\"_blank\"><img src=\"{$item['thumb_img_url']}\" width=\"100\" height=\"100\" /></a>" : "";
     59              });
     60
     61
     62      $this->tbl->rander();
     63      ?>
     64
    3365    </div>
    34 
    3566  </div>
    3667
    37   <table class="wp-list-table widefat fixed testimonials" cellspacing="0">
    38     <thead>
    39       <tr>
    40         <th>Project Name</th>
    41         <th>Client Name</th>
    42         <th>Description</th>
    43         <th>Video URL</th>
    44         <th width="100">Thumb Image</th>
    45       </tr>
    46     </thead>
    4768
    48     <tbody>
    49       <?php
    50       if ($testimonials->total_results) {
    51         while ($_row = mysql_fetch_assoc($testimonials->resource())) {
    52          
    53           $_row['city'] = $_row['city'] ? "<br /><i>[ City: {$_row['city']} ]</i>" : "";
    54           $_row['state'] = $_row['state'] ? "<br /><i>[ State: {$_row['state']} ]</i>" : "";
    55           $_row['country'] = $_row['country'] ? "<br /><i>[ Country: {$_row['country']} ]</i>" : "";
    56           //$_is_featured = $_row['is_featured'] ? ' class="featured"' : '';
    57          
    58           $_thumb_img = $_row['thumb_img_url'] ? "<a href=\"{$_row['large_img_url']}\" target=\"_blank\"><img src=\"{$_row['thumb_img_url']}\" width=\"100\" height=\"100\" /></a>" : false;
    59          
    60           $_row['is_featured'] = $_row['is_featured'] ? "<br /><code style=\"color:#C00;\"> Featured </code>" : "";
    61           echo "<tr>
    62                     <td><a href=\"{$_row['project_url']}\" target=\"blank\">{$_row['project_name']}</a><br /><i>[ {$_row['tags']} ]{$_row['is_featured']}</i></td>
    63                     <td>
    64                       {$_row['client_name']}{$_row['city']}{$_row['state']}{$_row['country']}
    65                       <div class=\"row-actions\">
    66                         <span class=\"edit\"><a href=\"admin.php?page=inic_testimonial_add&id={$_row['id']}\" title=\"Edit this item\">Edit</a> | </span>
    67                         <span class=\"trash\"><a class=\"submitdelete\" title=\"Delete this item\" href=\"javascript:void(0)\" rel=\"{$_row['id']}\">Delete</a></span>
    68                       </div>
    69                     </td>
    70                     <td>{$_row['description']}</td>
    71                     <td>{$_row['video_url']}</td>
    72                     <td>{$_thumb_img}</td>
    73                   </tr>";
    74         }
    75       } else {
    76         echo '<tr><td colspan="5">No Testimonial Found.</td></tr>';
    77       }
    78       ?>
    79     </tbody>
    80   </table>
    8169</div>
    82 
    83 <style>
    84   tr:nth-child(even) td {background-color: #fff;}
    85 </style>
    86 
    87 <script>
    88   jQuery(document).ready(function(){
    89     jQuery("table.testimonials tr td span.trash a").click(function(e){
    90      
    91       var _this = jQuery(this);
    92      
    93       var r = confirm("Are you sure want to delete this item?");
    94       if(r == true) {
    95        
    96         jQuery.post(ajaxurl, {action:"iNIC_testimonial_delete", id:jQuery(this).attr('rel')}, function(data){
    97          
    98           if(data.error) {
    99             jQuery("#message").show().addClass("error").removeClass('updated').find('p').html(data.error);
    100           } else if(data.success) {
    101             jQuery("#message").removeClass('error')
    102             jQuery("#message").show().addClass('updated').find('p').html(data.success);
    103             _this.closest("tr").remove();
    104           }
    105         }, 'json')
    106       }
    107       e.preventDefault();
    108     });
    109   });
    110 </script>
Note: See TracChangeset for help on using the changeset viewer.