public
Description: The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.
Homepage: http://chyrp.net/
Clone URL: git://github.com/vito/chyrp.git
Click here to lend your support to: chyrp and make a donation at www.pledgie.com !
More SQL interfacing touch-ups.
vito (author)
Tue Sep 02 14:28:18 -0700 2008
commit  303cba317d4ec3af39c8b45a66a761da0369bb4b
tree    1d2503685eb52649d4f290dfb7bbeed3a8d88afd
parent  af7fc7e2ca49b0d56dfb023d164259831e87d0c4
...
191
192
193
194
 
195
196
197
...
199
200
201
 
202
203
204
205
206
207
208
 
 
209
210
211
212
213
 
 
 
214
215
216
217
 
 
 
218
219
220
221
222
223
224
225
 
 
 
226
227
228
...
191
192
193
 
194
195
196
197
...
199
200
201
202
203
204
205
206
207
 
 
208
209
210
211
212
 
 
213
214
215
216
217
 
 
218
219
220
221
222
223
224
225
226
 
 
227
228
229
230
231
232
0
@@ -191,7 +191,7 @@
0
 
0
     public static function build_conditions($conds, &$params, $tables = null) {
0
       foreach ($conds as $key => $val) {
0
-        if (is_numeric($key)) # Full expression
0
+        if (is_int($key)) # Full expression
0
           $cond = $val;
0
         else { # Key => Val expression
0
           if (is_string($val) and $val[0] == ":")
0
@@ -199,30 +199,34 @@
0
           else {
0
             if (substr($key, -4) == " not") { # Negation
0
               $key = substr($key, 0, -4);
0
+              $param = str_replace(array("(", ")"), "_", $key);
0
               if (is_array($val))
0
                 $cond = $key." NOT IN ".self::build_in($val);
0
               elseif ($val === null)
0
                 $cond = $key." IS NOT NULL";
0
               else {
0
-                $cond = $key." != :".$key;
0
-                $params[":".$key] = $val;
0
+                $cond = $key." != :".$param;
0
+                $params[":".$param] = $val;
0
               }
0
             } elseif (substr($key, -5) == " like") { # LIKE
0
               $key = substr($key, 0, -5);
0
-              $cond = $key." LIKE :".$key;
0
-              $params[":".$key] = $val;
0
+              $param = str_replace(array("(", ")"), "_", $key);
0
+              $cond = $key." LIKE :".$param;
0
+              $params[":".$param] = $val;
0
             } elseif (substr($key, -9) == " not like") { # NOT LIKE
0
               $key = substr($key, 0, -9);
0
-              $cond = $key." NOT LIKE :".$key;
0
-              $params[":".$key] = $val;
0
+              $param = str_replace(array("(", ")"), "_", $key);
0
+              $cond = $key." NOT LIKE :".$param;
0
+              $params[":".$param] = $val;
0
             } else { # Equation
0
               if (is_array($val))
0
                 $cond = $key." IN ".self::build_in($val);
0
               elseif ($val === null)
0
                 $cond = $key." IS NULL";
0
               else {
0
-                $cond = $key." = :".$key;
0
-                $params[":".$key] = $val;
0
+                $param = str_replace(array("(", ")"), "_", $key);
0
+                $cond = $key." = :".$param;
0
+                $params[":".$param] = $val;
0
               }
0
             }
0
           }
...
1106
1107
1108
1109
1110
1111
1112
 
 
 
1113
1114
1115
...
1106
1107
1108
 
 
 
 
1109
1110
1111
1112
1113
1114
0
@@ -1106,10 +1106,9 @@
0
     foreach ($matches as $match) {
0
       list($test, $equals,) = explode(":", $match);
0
 
0
-      if (in_array($test, $times)) {
0
-        $where[] = strtoupper($test)."(created_at) = :created_".$test;
0
-        $params[":created_".$test] = $equals;
0
-      } elseif ($test == "author") {
0
+      if (in_array($test, $times))
0
+        $where[strtoupper($test)."(created_at)"] = $equals;
0
+      elseif ($test == "author") {
0
         $user = new User(null, array("where" => array("login" => $equals)));
0
         $where["user_id"] = $user->id;
0
       } elseif ($test == "group") {
...
748
749
750
751
752
753
754
 
 
 
755
756
757
...
748
749
750
 
 
 
 
751
752
753
754
755
756
0
@@ -748,10 +748,9 @@
0
       preg_match_all("/\(([^\)]+)\)/", Config::current()->post_url, $matches);
0
       $params = array();
0
       foreach ($matches[1] as $attr)
0
-        if (in_array($attr, $times)) {
0
-          $where[] = strtoupper($attr)."(created_at) = :created_".$attr;
0
-          $params[':created_'.$attr] = $get[$attr];
0
-        } elseif ($attr == "author") {
0
+        if (in_array($attr, $times))
0
+          $where[strtoupper($attr)."(created_at)"] = $get[$attr];
0
+        elseif ($attr == "author") {
0
           $user = new User(array("where" => array("login" => $get['author'])));
0
           $where["user_id"] = $user->id;
0
         } elseif ($attr == "feathers")
...
446
447
448
449
450
 
451
452
453
 
454
455
 
456
457
458
459
460
 
 
461
462
463
464
465
466
467
 
468
469
470
...
492
493
494
495
496
497
498
499
 
 
500
501
502
...
446
447
448
 
 
449
450
451
 
452
453
 
454
455
 
 
 
 
456
457
458
459
460
461
462
 
 
463
464
465
466
...
488
489
490
 
 
 
 
 
491
492
493
494
495
0
@@ -446,25 +446,21 @@
0
       if (!in_array(XML_RPC_FEATHER, Config::current()->enabled_feathers))
0
         throw new Exception(_f("The %s feather is not enabled.", array(XML_RPC_FEATHER)));
0
 
0
-      $where = array('feather = :feather');
0
-      $params = array(':feather' => XML_RPC_FEATHER);
0
+      $where = array('feather' => XML_RPC_FEATHER);
0
 
0
       if ($user->group()->can('view_own_draft', 'view_draft'))
0
-        $where[] = 'status IN ( "public", "draft" )';
0
+        $where['status'] = array('public', 'draft');
0
       else
0
-        $where[] = 'status = "public"';
0
+        $where['status'] = 'public';
0
 
0
-      if (!$user->group()->can('view_draft', 'edit_draft', 'edit_post', 'delete_draft', 'delete_post')) {
0
-        $where[] = 'user_id = :user_id';
0
-        $params[':user_id'] = $user->id;
0
-      }
0
+      if (!$user->group()->can('view_draft', 'edit_draft', 'edit_post', 'delete_draft', 'delete_post'))
0
+        $where['user_id'] = $user->id;
0
 
0
       return Post::find(
0
         array(
0
           'where'  => $where,
0
           'order'  => 'created_at DESC, id DESC',
0
-          'limit'  => $limit,
0
-          'params' => $params),
0
+          'limit'  => $limit),
0
         array('filter' => false));
0
     }
0
 
0
@@ -492,11 +488,8 @@
0
         null,
0
         array(
0
           'where' => array(
0
-            'login = :login',
0
-            'password = :password'),
0
-          'params' => array(
0
-            ':login' => $login,
0
-            ':password' => md5($password))));
0
+            'login' => $login,
0
+            'password' => md5($password))));
0
 
0
       if ($user->no_results)
0
         throw new Exception(__("Login incorrect."));
...
60
61
62
63
 
64
65
66
 
 
 
67
68
69
...
74
75
76
77
 
 
78
79
80
...
101
102
103
104
105
 
106
107
108
...
60
61
62
 
63
64
 
 
65
66
67
68
69
70
...
75
76
77
 
78
79
80
81
82
...
103
104
105
 
 
106
107
108
109
0
@@ -60,10 +60,11 @@
0
                                            "MONTH(created_at) AS month",
0
                                            "created_at AS created_at",
0
                                            "COUNT(id) AS posts"),
0
-                                     array("YEAR(created_at) = :year"),
0
+                                     array("YEAR(created_at)" => $_GET['year']),
0
                                      "created_at DESC, id DESC",
0
-                                     array(":year" => $_GET['year']),
0
-                                     null, null,
0
+                                     array(),
0
+                                     null,
0
+                                     null,
0
                                      array("YEAR(created_at)", "MONTH(created_at)"));
0
         else
0
           $timestamps = $sql->select("posts",
0
@@ -74,7 +75,8 @@
0
                                      null,
0
                                      "created_at DESC, id DESC",
0
                                      array(),
0
-                                     null, null,
0
+                                     null,
0
+                                     null,
0
                                      array("YEAR(created_at)", "MONTH(created_at)"));
0
 
0
         $archives = array();
0
@@ -101,8 +103,7 @@
0
                                                                "month" => strftime("%B", $timestamp),
0
                                                                "day" => strftime("%e", $timestamp),
0
                                                                "timestamp" => $timestamp,
0
-                                                               "depth" => $depth)
0
-                                      ));
0
+                                                               "depth" => $depth)));
0
       }
0
       break;
0
     case "login":

Comments