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 !
* Fixed model object overloading trigger check glitch.
* Added a fix for empty SimpleXML objects as a result of empty strings.
* Added another preprocessing fix for WordPress' ass-backwards export
  format.
* Fixed wordpress export generator validity check.
* Comments module no longer uses left joins, in favor of cached dynamic
  attribute fetching.
vito (author)
Wed Nov 19 19:29:37 -0800 2008
commit  ad0af46a4d2b7b5ec8a63f3ac2962de14b6a0339
tree    bf5026cc9ea2e469fa21fb24eb39639cfaf7acab
parent  7e8768b454fb3d5cf8cda1813524c80002b3584c
...
38
39
40
41
 
42
43
44
...
38
39
40
 
41
42
43
44
0
@@ -38,7 +38,7 @@
0
                 $placeholders = (isset($this->__placeholders) and $this->__placeholders);
0
 
0
                 Trigger::current()->filter($filtered, $model_name."_".$name."_attr", $this);
0
-                if (!empty($filtered))
0
+                if ($filtered !== false)
0
                     $this->$name = $filtered;
0
 
0
                 $this->belongs_to = (array) $this->belongs_to;
...
282
283
284
285
 
 
 
 
286
 
287
288
289
...
282
283
284
 
285
286
287
288
289
290
291
292
293
0
@@ -282,8 +282,12 @@
0
         public static function build_list($vals, $params = array()) {
0
             $return = array();
0
 
0
-            foreach ($vals as $val)
0
+            foreach ($vals as $val) {
0
+                if (is_object($val)) # Useful catch, e.g. empty SimpleXML objects.
0
+                    $val = "";
0
+
0
                 $return[] = (isset($params[$val])) ? $val : SQL::current()->escape($val) ;
0
+            }
0
 
0
             return "(".join(", ", $return).")";
0
         }
...
1195
1196
1197
 
 
 
 
 
1198
1199
1200
...
1203
1204
1205
1206
 
1207
1208
1209
...
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
...
1208
1209
1210
 
1211
1212
1213
1214
0
@@ -1195,6 +1195,11 @@
0
                                     array("<![CDATA[", "]]>"),
0
                                     $sane_xml);
0
 
0
+            if (!substr_count($sane_xml, "xmlns:export"))
0
+                $sane_xml = preg_replace("/xmlns:content=\"([^\"]+)\"(\s+)/m",
0
+                                         "xmlns:content=\"\\1\"\\2xmlns:excerpt=\"http://wordpress.org/excerpt/1.0/\"\\2",
0
+                                         $sane_xml);
0
+
0
             $fix_amps_count = 1;
0
             while ($fix_amps_count)
0
                 $sane_xml = preg_replace("/<wp:meta_value>(.+)&(?!amp;)(.+)<\/wp:meta_value>/m",
0
@@ -1203,7 +1208,7 @@
0
 
0
             $xml = simplexml_load_string($sane_xml, "SimpleXMLElement", LIBXML_NOCDATA);
0
 
0
-            if (!$xml or !strpos($xml->channel->generator, "wordpress.org"))
0
+            if (!$xml or !substr_count($xml->channel->generator, "wordpress.org"))
0
                 Flash::warning(__("File does not seem to be a valid WordPress export file."),
0
                                "/admin/?action=import");
0
 
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@
0
      *     <Model>
0
      */
0
     class Page extends Model {
0
-        public $belongs_to = array("user", "parent" => "page");
0
+        public $belongs_to = array("user", "parent" => array("model" => "page"));
0
 
0
         public $has_many = array("children" => array("page", "parent"));
0
 
...
5
6
7
8
9
10
11
...
619
620
621
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
622
623
624
...
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
...
5
6
7
 
8
9
10
...
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
...
677
678
679
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
681
682
0
@@ -5,7 +5,6 @@
0
     class Comments extends Modules {
0
         public function __init() {
0
             $this->addAlias("metaWeblog_newPost_preQuery", "metaWeblog_editPost_preQuery");
0
-            $this->addAlias("post_grab", "posts_get");
0
             $this->addAlias("comment_grab", "comments_get");
0
         }
0
 
0
@@ -619,6 +618,44 @@
0
             $post->has_many[] = "comments";
0
         }
0
 
0
+        public function post_comment_count_attr($attr, $post) {
0
+            if (isset($this->comment_counts))
0
+                return fallback($this->comment_counts[$post->id], 0);
0
+
0
+            $counts = SQL::current()->select("comments",
0
+                                             array("COUNT(post_id) AS total", "post_id"),
0
+                                             null,
0
+                                             null,
0
+                                             null,
0
+                                             null,
0
+                                             null,
0
+                                             "post_id");
0
+
0
+            foreach ($counts->fetchAll() as $count)
0
+                $this->comment_counts[$count["post_id"]] = (int) $count["total"];
0
+
0
+            return fallback($this->comment_counts[$post->id], 0);
0
+        }
0
+
0
+        public function post_latest_comment_attr($attr, $post) {
0
+            if (isset($this->latest_comments))
0
+                return fallback($this->latest_comments[$post->id], "0000-00-00 00:00:00");
0
+
0
+            $times = SQL::current()->select("comments",
0
+                                            array("MAX(created_at) AS latest", "post_id"),
0
+                                            null,
0
+                                            null,
0
+                                            null,
0
+                                            null,
0
+                                            null,
0
+                                            "post_id");
0
+
0
+            foreach ($times->fetchAll() as $row)
0
+                $this->latest_comments[$row["post_id"]] = $row["latest"];
0
+
0
+            return fallback($this->latest_comments[$post->id], "0000-00-00 00:00:00");
0
+        }
0
+
0
         public function comments_get($options) {
0
             if (ADMIN)
0
                 return;
0
@@ -640,30 +677,6 @@
0
             return Comment::user_can($post);
0
         }
0
 
0
-        static function posts_get($options) {
0
-            $options["select"][]  = "COUNT(comments.id) AS comment_count";
0
-            $options["select"][]  = "MAX(comments.created_at) AS latest_comment";
0
-
0
-            $options["left_join"][] = array("table" => "comments",
0
-                                            "where" => array("post_id = posts.id",
0
-                                                             "status != 'spam'",
0
-                                                             "status != 'denied' OR (
0
-                                                                  (
0
-                                                                      user_id != 0 AND
0
-                                                                      user_id = :visitor_id
0
-                                                                  ) OR (
0
-                                                                      id IN ".self::visitor_comments()."
0
-                                                                  )
0
-                                                              )"));
0
-
0
-            $options["params"][":visitor_id"] = Visitor::current()->id;
0
-
0
-            $options["group"][] = "id";
0
-            $options["group"][] = "post_attributes.name";
0
-
0
-            return $options;
0
-        }
0
-
0
         public function cacher_regenerate_posts_triggers($array) {
0
             $array = array_merge($array, array("add_comment", "update_comment", "delete_comment"));
0
             return $array;
...
197
198
199
200
 
201
202
203
...
197
198
199
 
200
201
202
203
0
@@ -197,7 +197,7 @@
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
+            $new = new self($sql->latest());
0
 
0
             Trigger::current()->call("add_comment", $new);
0
             return $new;

Comments