Plugin Directory

Changeset 1331850


Ignore:
Timestamp:
01/20/2016 05:05:46 AM (10 years ago)
Author:
faaiq
Message:

faaiq, now secure form sql injectinos

Location:
custom-post-order-category/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • custom-post-order-category/trunk/readme.txt

    r969387 r1331850  
    7070Premium Features -  Now arrage your posts in Ascending/ Descending order in just one click.
    7171
     72= 1.5.6 =
     73Now more secure from hackers , Please backup your database before upgrade, it can delete your all orders, download pluging in seperated directory and replace only plugin file.
     74
    7275== Arbitrary section 1 ==
  • custom-post-order-category/trunk/wp-customcategorypostorder.php

    r969387 r1331850  
    88Plugin Name: Custom Category Post Order
    99Description: Arrange Post through drag n drop interface of selected category and post type.
    10 Author: Faaiq Ahmed, Technical Architect PHP, faaiqsj@gmail.com
     10Author: Faaiq Ahmed, Technical Architect PHP, nfaaiq@gmail.com
    1111Version: 1.5.5
    1212*/
     
    6060        $role = $_POST['role'];
    6161        if(isset($_POST) and $role != "") {
    62                
    63                 update_option( "ccpo_order_manager", $role );
    64                 print "Role Updated";
     62            update_option( "ccpo_order_manager", $role );
     63            print "Role Updated";
    6564         
    6665        }
    6766        $role = get_option( 'ccpo_order_manager', 'administrator' );
    68     $roles = $wp_roles->get_names();
     67        $roles = $wp_roles->get_names();
    6968        $select  = "";
    7069        foreach($roles as $key=> $label) {
     
    7776        }
    7877       
    79         print '<div class="wrap">
    80     <h2>Who Can Arrange Post</h2>
    81     <form method="post">';
    82     wp_nonce_field('update-options');
     78    print '<div class="wrap">
     79        <h2>Who Can Arrange Post</h2>
     80        <form method="post">';
     81        wp_nonce_field('update-options');
    8382   
    8483    print '<table class="form-table">
     
    148147    if($category != '' ) {
    149148       
    150      $sql = "select * from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category' order by weight";
     149     $sql = $wpdb->prepare("select * from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '%d' order by weight",$category);
    151150     $order_result = $wpdb->get_results($sql);
    152151       
    153152        for($k = 0 ;$k < count($order_result); ++$k) {
    154                 $order_result_incl[$order_result[$k]->post_id] = $order_result[$k]->incl;
     153            $order_result_incl[$order_result[$k]->post_id] = $order_result[$k]->incl;
    155154        }
    156155       
     
    187186       
    188187    }
    189    
     188
    190189    $checked = get_option( "ccpo_category_ordering_".$category );
    191190            ?>
     
    230229        $html .= '<ul id="sortable" class="sortableul">';
    231230
     231       
    232232        for($i = 0; $i < count( $order_result); ++$i) {
    233233            $post_id = $order_result[$i]->post_id;
     234           
    234235            $post = $temp_order[$post_id];
    235236           
    236237            unset($temp_order[$post_id]);   
    237              $total = $this->check_order_table($post->ID,$category);
    238                 $od = $order_result_incl[$post->ID];
     238
     239            $total = $this->check_order_table($post->ID,$category);
     240           
     241            $od = $order_result_incl[$post->ID];
     242
    239243            if($od == 1) {
    240244                $edit = '<small><a href="javascript:void(0);" onclick="rempst('.$post->ID.',\''.$category.'\')">Remove</a></small>';
     
    242246                $edit = '<small><a href="javascript:void(0);" onclick="rempst('.$post->ID.',\''.$category.'\')">Add</a></small>';
    243247            }
     248
    244249            if($checked == "checked") {
    245                  if($total >0 ) {
     250                 if($total > 0 ) {
    246251                        $html .= '<li class="sortable" id="'.$post->ID.'" rel="'.$post->ID.'" post_title="'.$post->post_title.'">';
    247252                        $html .= '<div id="post" class="drag_post">'.$post->post_title.'<div class="ar_link" id="id_'.$post->ID.'">'.$edit.'</div></div>';
     
    254259        }
    255260       
     261
     262
    256263        foreach($temp_order as $temp_order_id => $temp_order_post) {
    257264            $post_id = $temp_order_id;
     
    365372     $category = $_POST['category'];
    366373     $post_id = $_POST['post_id'];
    367      
    368      $incl = $wpdb->get_var("select incl from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category' and post_id = '$post_id'");
     374
     375     $incl = $wpdb->get_var($wpdb->prepare( "select incl from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category' and post_id = '%d'",$post_id));
     376
    369377     $new_incl = ($incl == 1) ? 0 : 1;
    370      $wpdb->query("update ".$wpdb->prefix."ccpo_post_order_rel set incl = '$new_incl' where category_id = '$category' and post_id = '$post_id'");
     378     $wpdb->query($wpdb->prepare( "update ".$wpdb->prefix."ccpo_post_order_rel set incl = '%d' where category_id = '%d' and post_id = '%d'",$new_incl,$category,$post_id));
    371379     
    372380      if($new_incl == 1) {
     
    386394function check_order_table($post,$cat) {
    387395     global $wpdb; // this is how you get access to the database
    388      $total = $wpdb->get_var("select count(*) as total from   ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$cat' and post_id = '$post'");
     396     $total = $wpdb->get_var($wpdb->prepare( "select count(*) as total from   " . $wpdb->prefix . "ccpo_post_order_rel where category_id = '%d' and post_id = '%d'",$cat, $post));
    389397     return $total;
    390398}
     
    407415    $category = $_POST['category'];
    408416    //$wpdb->query("delete from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category'");
    409    
    410     $total = $wpdb->get_var("select count(*) as total from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category'");
     417
     418    $total = $wpdb->get_var($wpdb->prepare( "select count(*) as total from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '%d'",$category));
    411419   
    412420    if($total == 0) { //executes when there is not date for selected category
     
    416424        }
    417425        $sql = "insert into ".$wpdb->prefix."ccpo_post_order_rel (category_id,post_id,weight)  values ".implode(",",$value);
     426
    418427        $wpdb->query($sql);
    419428    }else {
     
    421430        foreach($order as $post_id) {
    422431            ++$weight;
    423                 $sql = "update ".$wpdb->prefix."ccpo_post_order_rel set weight='$weight' where post_id = '$post_id' and category_id = '$category'";
    424                 $wpdb->query($sql);
    425         }
    426        
    427         $results = $wpdb->get_results("select * from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$category' order by weight");
     432
     433                //$sql = "update ".$wpdb->prefix."ccpo_post_order_rel set weight='$weight' where post_id = '$post_id' and category_id = '$category'";
     434                $wpdb->query($wpdb->prepare( "update ".$wpdb->prefix."ccpo_post_order_rel set weight='%d' where post_id = '%d' and category_id = '%d'",$weight, $post_id, $category)); 
     435        }
     436       
     437        $results = $wpdb->get_results($wpdb->prepare("select * from ".$wpdb->prefix."ccpo_post_order_rel where category_id = '%d' order by weight",$category));
    428438       
    429439        foreach($results as $index => $result_row) {
     
    439449                $id = $row->id;
    440450               
    441                 $exists = $wpdb->get_var("select count(*) as total from ".$wpdb->prefix."ccpo_post_order_rel  where post_id = '$post_id' and category_id = '$category'");
     451                $exists = $wpdb->get_var($wpdb->prepare("select count(*) as total from ".$wpdb->prefix."ccpo_post_order_rel  where post_id = '%d' and category_id = '%d'",$post_id, $category));
    442452
    443453                if($exists > 0) {
    444                     $sql = "update ".$wpdb->prefix."ccpo_post_order_rel set post_id = '$post_id',incl = '$incl' where id = '$id'";
     454                    $sql = $wpdb->prepare("update ".$wpdb->prefix."ccpo_post_order_rel set post_id = '%d',incl = '%d' where id = '%d'",$post_id,$incl,$id);
    445455                    $wpdb->query($sql);
    446456                }else {
    447                     $sql = "insert into ".$wpdb->prefix."ccpo_post_order_rel set category_id = '$category' ,post_id = '$post_id', incl = '0'";
     457                    $sql = $wpdb->prepare("insert into ".$wpdb->prefix."ccpo_post_order_rel set category_id = '%d' ,post_id = '%d', incl = '0'",$category,$post_id);
    448458                    $wpdb->query($sql);
    449459                }
     
    531541        foreach($cats as $key => $cat) {
    532542                $cat_id = $cat->term_id;
    533                 $total = $wpdb->get_var("select count(*) as total from  ".$wpdb->prefix."ccpo_post_order_rel where category_id = '$cat_id' and post_id = '$post_id'");
     543                $total = $wpdb->get_var($wpdb->prepare("select count(*) as total from  ".$wpdb->prefix."ccpo_post_order_rel where category_id = '%d' and post_id = '%d'",$cat_id,$post_id));
    534544                if($total == 0) {
    535                         $sql = "insert into ".$wpdb->prefix."ccpo_post_order_rel (category_id,post_id) values ('$cat_id','$post_id')";
     545                        $sql = $wpdb->prepare("insert into ".$wpdb->prefix."ccpo_post_order_rel (category_id,post_id) values ('%d','%d')",$cat_id,$post_id);
    536546                        $wpdb->query($sql);
    537547                }
Note: See TracChangeset for help on using the changeset viewer.