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 refactoring.
vito (author)
Mon Sep 01 20:47:05 -0700 2008
commit  91c8953ce1899035f5c572aa74ea6d4af54510a3
tree    7f42f66386346dab559ff742a3db858d8a1a635f
parent  e32209c7141f2f645a35b6d7c1504aa021090540
...
82
83
84
85
86
 
87
88
89
...
82
83
84
 
 
85
86
87
88
0
@@ -82,8 +82,7 @@
0
      */
0
     static function add($name, $permissions) {
0
       $sql = SQL::current();
0
-      $sql->insert("groups", array("name" => ":name", "permissions" => ":permissions"),
0
-                             array(":name"  => $name,   ":permissions"  => YAML::dump($permissions)));
0
+      $sql->insert("groups", array("name" => $name, "permissions" => YAML::dump($permissions)));
0
 
0
       $group = new self($sql->latest());
0
 
...
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
94
...
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
71
72
73
74
75
76
77
78
79
80
0
@@ -65,30 +65,16 @@
0
       $sql = SQL::current();
0
       $visitor = Visitor::current();
0
       $sql->insert("pages",
0
-                   array(
0
-                       "title" => ":title",
0
-                       "body" => ":body",
0
-                       "user_id" => ":user_id",
0
-                       "parent_id" => ":parent_id",
0
-                       "show_in_list" => ":show_in_list",
0
-                       "list_order" => ":list_order",
0
-                       "clean" => ":clean",
0
-                       "url" => ":url",
0
-                       "created_at" => ":created_at",
0
-                       "updated_at" => ":updated_at"
0
-                   ),
0
-                   array(
0
-                       ":title" => $title,
0
-                       ":body" => $body,
0
-                       ":user_id" => fallback($user_id, $visitor->id),
0
-                       ":parent_id" => $parent_id,
0
-                       ":show_in_list" => $show_in_list,
0
-                       ":list_order" => $list_order,
0
-                       ":clean" => $clean,
0
-                       ":url" => $url,
0
-                       ":created_at" => fallback($created_at, datetime()),
0
-                       ":updated_at" => fallback($updated_at, "0000-00-00 00:00:00")
0
-                   ));
0
+                   array("title" => $title,
0
+                         "body" => $body,
0
+                         "user_id" => fallback($user_id, $visitor->id),
0
+                         "parent_id" => $parent_id,
0
+                         "show_in_list" => $show_in_list,
0
+                         "list_order" => $list_order,
0
+                         "clean" => $clean,
0
+                         "url" => $url,
0
+                         "created_at" => fallback($created_at, datetime()),
0
+                         "updated_at" => fallback($updated_at, "0000-00-00 00:00:00")));
0
 
0
       $page = new self($sql->latest());
0
 
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
 
 
 
 
 
 
 
 
 
183
184
185
...
547
548
549
550
 
551
552
 
553
554
 
555
556
 
557
558
559
560
 
561
562
563
...
162
163
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
166
167
168
169
170
171
172
173
174
175
176
...
538
539
540
 
541
542
 
543
544
 
545
546
 
547
548
 
 
 
549
550
551
552
0
@@ -162,24 +162,15 @@
0
       $sql = SQL::current();
0
       $visitor = Visitor::current();
0
       $sql->insert("posts",
0
-                   array("xml" => ":xml",
0
-                         "feather" => ":feather",
0
-                         "user_id" => ":user_id",
0
-                         "pinned" => ":pinned",
0
-                         "status" => ":status",
0
-                         "clean" => ":clean",
0
-                         "url" => ":url",
0
-                         "created_at" => ":created_at",
0
-                         "updated_at" => ":updated_at"),
0
-                   array(":xml" => $xml->asXML(),
0
-                         ":feather" => $feather,
0
-                         ":user_id" => $user,
0
-                         ":pinned" => (int) $pinned,
0
-                         ":status" => $status,
0
-                         ":clean" => $clean,
0
-                         ":url" => $url,
0
-                         ":created_at" => $created_at,
0
-                         ":updated_at" => $updated_at));
0
+                   array("xml" => $xml->asXML(),
0
+                         "feather" => $feather,
0
+                         "user_id" => $user,
0
+                         "pinned" => (int) $pinned,
0
+                         "status" => $status,
0
+                         "clean" => $clean,
0
+                         "url" => $url,
0
+                         "created_at" => $created_at,
0
+                         "updated_at" => $updated_at));
0
       $id = $sql->latest();
0
 
0
       if (empty($clean) or empty($url))
0
@@ -547,17 +538,15 @@
0
       if ($this->no_results)
0
         return false;
0
 
0
-      $where = array("(created_at > :created_at OR id > :id)");
0
+      $where = array("created_at > :created_at OR id > :id");
0
 
0
-      $statuses = array("public");
0
+      $where["status"] = array("public");
0
       if ($this->status == "draft")
0
-        $statuses[] = "draft";
0
+        $where["status"][] = "draft";
0
       if (logged_in())
0
-        $statuses[] = "registered_only";
0
+        $where["status"][] = "registered_only";
0
       if (Visitor::current()->group()->can("view_private"))
0
-        $statuses[] = "private";
0
-
0
-      $where[] = "status IN ('".implode("', '", $statuses)."')";
0
+        $where["status"][] = "private";
0
 
0
       return new self(null, array("where" => $where,
0
                                   "order" => "created_at ASC, id ASC",
...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
 
 
 
 
 
 
87
88
89
...
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
73
74
75
76
77
78
79
0
@@ -67,23 +67,13 @@
0
       $config = Config::current();
0
       $sql = SQL::current();
0
       $sql->insert("users",
0
-                   array(
0
-                       "login" => ":login",
0
-                       "password" => ":password",
0
-                       "email" => ":email",
0
-                       "full_name" => ":full_name",
0
-                       "website" => ":website",
0
-                       "group_id" => ":group_id",
0
-                       "joined_at" => ":joined_at"),
0
-                   array(
0
-                       ":login" => strip_tags($login),
0
-                       ":password" => md5($password),
0
-                       ":email" => strip_tags($email),
0
-                       ":full_name" => strip_tags($full_name),
0
-                       ":website" => strip_tags($website),
0
-                       ":group_id" => ($group_id) ? intval($group_id) : $config->default_group,
0
-                       ":joined_at" => fallback($joined_at, datetime())
0
-                  ));
0
+                   array("login" => strip_tags($login),
0
+                         "password" => md5($password),
0
+                         "email" => strip_tags($email),
0
+                         "full_name" => strip_tags($full_name),
0
+                         "website" => strip_tags($website),
0
+                         "group_id" => ($group_id) ? intval($group_id) : $config->default_group,
0
+                         "joined_at" => fallback($joined_at, datetime())));
0
 
0
       $user = new self($sql->latest());
0
 
...
265
266
267
268
269
270
 
271
272
273
...
278
279
280
281
282
283
 
284
285
286
...
265
266
267
 
 
 
268
269
270
271
...
276
277
278
 
 
 
279
280
281
282
0
@@ -265,9 +265,7 @@
0
                            "delete_group" => "Delete Groups");
0
 
0
       foreach ($permissions as $permission => $name)
0
-        $sql->replace("permissions",
0
-                      array("id" => ":permission", "name" => ":name"),
0
-                      array(":permission" => $permission, ":name" => $name));
0
+        $sql->replace("permissions", array("id" => $permission, "name" => $name));
0
 
0
       $groups = array("admin" => YAML::dump(array_keys($permissions)),
0
                       "member" => YAML::dump(array("view_site")),
0
@@ -278,9 +276,7 @@
0
       # Insert the default groups (see above)
0
       $group_id = array();
0
       foreach($groups as $name => $permissions) {
0
-        $sql->replace("groups",
0
-                      array("name" => ":name", "permissions" => ":permissions"),
0
-                      array(":name" => ucfirst($name), ":permissions" => $permissions));
0
+        $sql->replace("groups", array("name" => ucfirst($name), "permissions" => $permissions));
0
 
0
         $group_id[$name] = $sql->latest();
0
       }
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
 
 
 
 
 
 
 
 
 
 
 
 
197
198
199
...
169
170
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
0
@@ -169,31 +169,18 @@
0
 
0
       $sql = SQL::current();
0
       $sql->insert("comments",
0
-                   array("body" => ":body",
0
-                         "author" => ":author",
0
-                         "author_url" => ":author_url",
0
-                         "author_email" => ":author_email",
0
-                         "author_ip" => ":author_ip",
0
-                         "author_agent" => ":author_agent",
0
-                         "status" => ":status",
0
-                         "signature" => ":signature",
0
-                         "post_id" => ":post_id",
0
-                         "user_id" => ":user_id",
0
-                         "created_at" => ":created_at",
0
-                         "updated_at" => ":updated_at"),
0
-                   array(":body" => $body,
0
-                         ":author" => strip_tags($author),
0
-                         ":author_url" => strip_tags($url),
0
-                         ":author_email" => strip_tags($email),
0
-                         ":author_ip" => $ip,
0
-                         ":author_agent" => $agent,
0
-                         ":status" => $status,
0
-                         ":signature" => $signature,
0
-                         ":post_id" => $post->id,
0
-                         ":user_id"=> $user_id,
0
-                         ":created_at" => fallback($created_at, datetime()),
0
-                         ":updated_at" => fallback($updated_at, "0000-00-00 00:00:00")
0
-                   ));
0
+                   array("body" => $body,
0
+                         "author" => strip_tags($author),
0
+                         "author_url" => strip_tags($url),
0
+                         "author_email" => strip_tags($email),
0
+                         "author_ip" => $ip,
0
+                         "author_agent" => $agent,
0
+                         "status" => $status,
0
+                         "signature" => $signature,
0
+                         "post_id" => $post->id,
0
+                         "user_id"=> $user_id,
0
+                         "created_at" => fallback($created_at, datetime()),
0
+                         "updated_at" => fallback($updated_at, "0000-00-00 00:00:00")));
0
       $new = new self($sql->latest());;
0
 
0
       Trigger::current()->call("add_comment", $new);
...
94
95
96
97
98
99
100
101
 
102
103
104
...
120
121
122
123
124
125
126
127
 
128
129
130
...
226
227
228
229
230
 
 
 
 
231
232
 
233
234
235
...
277
278
279
280
281
282
 
283
284
285
...
369
370
371
372
373
374
375
376
377
 
 
 
378
379
380
...
389
390
391
392
393
394
395
396
397
 
 
 
398
399
400
...
426
427
428
429
430
431
432
433
 
434
435
436
...
94
95
96
 
 
 
 
 
97
98
99
100
...
116
117
118
 
 
 
 
 
119
120
121
122
...
218
219
220
 
 
221
222
223
224
225
 
226
227
228
229
...
271
272
273
 
 
 
274
275
276
277
...
361
362
363
 
 
 
 
 
 
364
365
366
367
368
369
...
378
379
380
 
 
 
 
 
 
381
382
383
384
385
386
...
412
413
414
 
 
 
 
 
415
416
417
418
0
@@ -94,11 +94,7 @@
0
       $tags_cleaned_string = "{{".implode("}},{{", $tags_cleaned)."}}";
0
 
0
       $sql = SQL::current();
0
-      $sql->insert("tags", array("tags" => ":tags", "clean" => ":clean", "post_id" => ":post_id"), array(
0
-                       ":tags"    => $tags_string,
0
-                       ":clean"   => $tags_cleaned_string,
0
-                       ":post_id" => $post->id
0
-                   ));
0
+      $sql->insert("tags", array("tags" => $tags_string, "clean" => $tags_cleaned_string, "post_id" => $post->id));
0
     }
0
 
0
     public function update_post($post) {
0
@@ -120,11 +116,7 @@
0
       if (empty($tags_string) and empty($tags_cleaned_string))
0
         $sql->delete("tags", array("post_id" => $post->id));
0
       else
0
-        $sql->insert("tags", array("tags" => ":tags", "clean" => ":clean", "post_id" => ":post_id"), array(
0
-                         ":tags"    => $tags_string,
0
-                         ":clean"   => $tags_cleaned_string,
0
-                         ":post_id" => $post->id
0
-                     ));
0
+        $sql->insert("tags", array("tags" => $tags_string, "clean" => $tags_cleaned_string, "post_id" => $post->id));
0
     }
0
 
0
     public function delete_post($post) {
0
@@ -226,10 +218,12 @@
0
                          "tags.*",
0
                          array(Post::$private, Post::$enabled_feathers),
0
                          null,
0
-                         array(":tag" => "%{{".$_GET['name']."}}%"),
0
-                         null, null, null,
0
+                         array(),
0
+                         null,
0
+                         null,
0
+                         null,
0
                          array(array("table" => "tags",
0
-                                     "where" => array("post_id = posts.id", "clean LIKE :tag"))))->fetchAll() as $tag) {
0
+                                     "where" => array("post_id = posts.id", array("clean like" => "%{{".$_GET['name']."}}%"))))->fetchAll() as $tag) {
0
         if ($tag["id"] == null)
0
           continue;
0
 
0
@@ -277,9 +271,7 @@
0
       $clean = array();
0
       foreach($sql->select("tags",
0
                          "*",
0
-                         "clean LIKE :tag",
0
-                         null,
0
-                         array(":tag" => "%{{".$_POST['clean']."}}%"))->fetchAll() as $tag) {
0
+                         array("clean like" => "%{{".$_POST['clean']."}}%"))->fetchAll() as $tag) {
0
         $names = str_replace("{{".$_POST['clean']."}}", "{{".$_POST['name']."}}", $tag["tags"]);
0
         $clean = str_replace("{{".$_POST['clean']."}}", "{{".sanitize($_POST['name'])."}}", $tag["clean"]);
0
         $sql->update("tags",
0
@@ -369,12 +361,9 @@
0
 
0
       if (!empty($tags) and !empty($cleaned))
0
         SQL::current()->insert("tags",
0
-                               array("tags"     => ":tags",
0
-                                     "clean"    => ":clean",
0
-                                     "post_id"  => ":post_id"),
0
-                               array(":tags"    => rtrim($tags, ","),
0
-                                     ":clean"   => rtrim($cleaned, ","),
0
-                                     ":post_id" => $post->id));
0
+                               array("tags" => rtrim($tags, ","),
0
+                                     "clean" => rtrim($cleaned, ","),
0
+                                     "post_id" => $post->id));
0
     }
0
 
0
     public function import_wordpress_post($item, $post) {
0
@@ -389,12 +378,9 @@
0
 
0
       if (!empty($tags) and !empty($cleaned))
0
         SQL::current()->insert("tags",
0
-                               array("tags"     => ":tags",
0
-                                     "clean"    => ":clean",
0
-                                     "post_id"  => ":post_id"),
0
-                               array(":tags"    => rtrim($tags, ","),
0
-                                     ":clean"   => rtrim($cleaned, ","),
0
-                                     ":post_id" => $post->id));
0
+                               array("tags" => rtrim($tags, ","),
0
+                                     "clean" => rtrim($cleaned, ","),
0
+                                     "post_id" => $post->id));
0
     }
0
 
0
     public function import_movabletype_post($array, $post, $link) {
0
@@ -426,11 +412,7 @@
0
       $clean_string = "{{".implode("}},{{", array_values($tags))."}}";
0
 
0
       $sql = SQL::current();
0
-      $sql->insert("tags", array("tags" => ":tags", "clean" => ":clean", "post_id" => ":post_id"), array(
0
-                       ":tags"    => $dirty_string,
0
-                       ":clean"   => $clean_string,
0
-                       ":post_id" => $post->id
0
-                   ));
0
+      $sql->insert("tags", array("tags" => $dirty_string, "clean" => $clean_string, "post_id" => $post->id));
0
     }
0
 
0
     public function metaWeblog_getPost($struct, $post) {
...
33
34
35
36
37
38
39
40
41
 
 
 
42
43
44
...
33
34
35
 
 
 
 
 
 
36
37
38
39
40
41
0
@@ -33,12 +33,9 @@
0
     foreach ($tags as $post => $tag)
0
       echo _f("Inserting tags for post #%s...", array($post), "tags").
0
            test(SQL::current()->insert("tags",
0
-                                       array("tags" => ":tags",
0
-                                             "clean" => ":clean",
0
-                                             "post_id" => ":post_id"),
0
-                                       array(":tags" => implode(",", $tag["normal"]),
0
-                                             ":clean" => implode(",", $tag["clean"]),
0
-                                             ":post_id" => $post)));
0
+                                       array("tags" => implode(",", $tag["normal"]),
0
+                                             "clean" => implode(",", $tag["clean"]),
0
+                                             "post_id" => $post)));
0
   }
0
 
0
   update_tags_structure();
...
352
353
354
355
356
357
358
359
360
 
 
 
361
362
363
...
399
400
401
402
403
404
405
 
 
406
407
408
...
474
475
476
477
478
479
480
 
 
481
482
483
...
352
353
354
 
 
 
 
 
 
355
356
357
358
359
360
...
396
397
398
 
 
 
 
399
400
401
402
403
...
469
470
471
 
 
 
 
472
473
474
475
476
0
@@ -352,12 +352,9 @@
0
     foreach($groups as $name => $values)
0
       echo _f("Restoring group \"%s\"...", array($name)).
0
            test(SQL::current()->insert("groups",
0
-                                       array("id" => ":id",
0
-                                             "name" => ":name",
0
-                                             "permissions" => ":permissions"),
0
-                                       array(":id" => $values["id"],
0
-                                             ":name" => $name,
0
-                                             ":permissions" => $values["permissions"])));
0
+                                       array("id" => $values["id"],
0
+                                             "name" => $name,
0
+                                             "permissions" => $values["permissions"])));
0
   }
0
 
0
   function add_permissions_table() {
0
@@ -399,10 +396,8 @@
0
     foreach ($permissions as $id => $name)
0
       echo _f("Inserting permission \"%s\"...", array($name)).
0
            test(SQL::current()->insert("permissions",
0
-                                       array("id" => ":id",
0
-                                             "name" => ":name"),
0
-                                       array(":id" => $id,
0
-                                             ":name" => $name)));
0
+                                       array("id" => $id,
0
+                                             "name" => $name)));
0
   }
0
 
0
   function add_sessions_table() {
0
@@ -474,10 +469,8 @@
0
       $name = isset($permissions[$id]) ? $permissions[$id] : camelize($id, true);
0
       echo _f("Restoring permission \"%s\"...", array($name)).
0
            test(SQL::current()->insert("permissions",
0
-                                       array("id" => ":id",
0
-                                             "name" => ":name"),
0
-                                       array(":id" => $id,
0
-                                             ":name" => $name)));
0
+                                       array("id" => $id,
0
+                                             "name" => $name)));
0
     }
0
 
0
   }

Comments