<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -38,7 +38,7 @@
                 $placeholders = (isset($this-&gt;__placeholders) and $this-&gt;__placeholders);
 
                 Trigger::current()-&gt;filter($filtered, $model_name.&quot;_&quot;.$name.&quot;_attr&quot;, $this);
-                if (!empty($filtered))
+                if ($filtered !== false)
                     $this-&gt;$name = $filtered;
 
                 $this-&gt;belongs_to = (array) $this-&gt;belongs_to;</diff>
      <filename>includes/class/Model.php</filename>
    </modified>
    <modified>
      <diff>@@ -282,8 +282,12 @@
         public static function build_list($vals, $params = array()) {
             $return = array();
 
-            foreach ($vals as $val)
+            foreach ($vals as $val) {
+                if (is_object($val)) # Useful catch, e.g. empty SimpleXML objects.
+                    $val = &quot;&quot;;
+
                 $return[] = (isset($params[$val])) ? $val : SQL::current()-&gt;escape($val) ;
+            }
 
             return &quot;(&quot;.join(&quot;, &quot;, $return).&quot;)&quot;;
         }</diff>
      <filename>includes/class/QueryBuilder.php</filename>
    </modified>
    <modified>
      <diff>@@ -1195,6 +1195,11 @@
                                     array(&quot;&lt;![CDATA[&quot;, &quot;]]&gt;&quot;),
                                     $sane_xml);
 
+            if (!substr_count($sane_xml, &quot;xmlns:export&quot;))
+                $sane_xml = preg_replace(&quot;/xmlns:content=\&quot;([^\&quot;]+)\&quot;(\s+)/m&quot;,
+                                         &quot;xmlns:content=\&quot;\\1\&quot;\\2xmlns:excerpt=\&quot;http://wordpress.org/excerpt/1.0/\&quot;\\2&quot;,
+                                         $sane_xml);
+
             $fix_amps_count = 1;
             while ($fix_amps_count)
                 $sane_xml = preg_replace(&quot;/&lt;wp:meta_value&gt;(.+)&amp;(?!amp;)(.+)&lt;\/wp:meta_value&gt;/m&quot;,
@@ -1203,7 +1208,7 @@
 
             $xml = simplexml_load_string($sane_xml, &quot;SimpleXMLElement&quot;, LIBXML_NOCDATA);
 
-            if (!$xml or !strpos($xml-&gt;channel-&gt;generator, &quot;wordpress.org&quot;))
+            if (!$xml or !substr_count($xml-&gt;channel-&gt;generator, &quot;wordpress.org&quot;))
                 Flash::warning(__(&quot;File does not seem to be a valid WordPress export file.&quot;),
                                &quot;/admin/?action=import&quot;);
 </diff>
      <filename>includes/controller/Admin.php</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@
      *     &lt;Model&gt;
      */
     class Page extends Model {
-        public $belongs_to = array(&quot;user&quot;, &quot;parent&quot; =&gt; &quot;page&quot;);
+        public $belongs_to = array(&quot;user&quot;, &quot;parent&quot; =&gt; array(&quot;model&quot; =&gt; &quot;page&quot;));
 
         public $has_many = array(&quot;children&quot; =&gt; array(&quot;page&quot;, &quot;parent&quot;));
 </diff>
      <filename>includes/model/Page.php</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,6 @@
     class Comments extends Modules {
         public function __init() {
             $this-&gt;addAlias(&quot;metaWeblog_newPost_preQuery&quot;, &quot;metaWeblog_editPost_preQuery&quot;);
-            $this-&gt;addAlias(&quot;post_grab&quot;, &quot;posts_get&quot;);
             $this-&gt;addAlias(&quot;comment_grab&quot;, &quot;comments_get&quot;);
         }
 
@@ -619,6 +618,44 @@
             $post-&gt;has_many[] = &quot;comments&quot;;
         }
 
+        public function post_comment_count_attr($attr, $post) {
+            if (isset($this-&gt;comment_counts))
+                return fallback($this-&gt;comment_counts[$post-&gt;id], 0);
+
+            $counts = SQL::current()-&gt;select(&quot;comments&quot;,
+                                             array(&quot;COUNT(post_id) AS total&quot;, &quot;post_id&quot;),
+                                             null,
+                                             null,
+                                             null,
+                                             null,
+                                             null,
+                                             &quot;post_id&quot;);
+
+            foreach ($counts-&gt;fetchAll() as $count)
+                $this-&gt;comment_counts[$count[&quot;post_id&quot;]] = (int) $count[&quot;total&quot;];
+
+            return fallback($this-&gt;comment_counts[$post-&gt;id], 0);
+        }
+
+        public function post_latest_comment_attr($attr, $post) {
+            if (isset($this-&gt;latest_comments))
+                return fallback($this-&gt;latest_comments[$post-&gt;id], &quot;0000-00-00 00:00:00&quot;);
+
+            $times = SQL::current()-&gt;select(&quot;comments&quot;,
+                                            array(&quot;MAX(created_at) AS latest&quot;, &quot;post_id&quot;),
+                                            null,
+                                            null,
+                                            null,
+                                            null,
+                                            null,
+                                            &quot;post_id&quot;);
+
+            foreach ($times-&gt;fetchAll() as $row)
+                $this-&gt;latest_comments[$row[&quot;post_id&quot;]] = $row[&quot;latest&quot;];
+
+            return fallback($this-&gt;latest_comments[$post-&gt;id], &quot;0000-00-00 00:00:00&quot;);
+        }
+
         public function comments_get($options) {
             if (ADMIN)
                 return;
@@ -640,30 +677,6 @@
             return Comment::user_can($post);
         }
 
-        static function posts_get($options) {
-            $options[&quot;select&quot;][]  = &quot;COUNT(comments.id) AS comment_count&quot;;
-            $options[&quot;select&quot;][]  = &quot;MAX(comments.created_at) AS latest_comment&quot;;
-
-            $options[&quot;left_join&quot;][] = array(&quot;table&quot; =&gt; &quot;comments&quot;,
-                                            &quot;where&quot; =&gt; array(&quot;post_id = posts.id&quot;,
-                                                             &quot;status != 'spam'&quot;,
-                                                             &quot;status != 'denied' OR (
-                                                                  (
-                                                                      user_id != 0 AND
-                                                                      user_id = :visitor_id
-                                                                  ) OR (
-                                                                      id IN &quot;.self::visitor_comments().&quot;
-                                                                  )
-                                                              )&quot;));
-
-            $options[&quot;params&quot;][&quot;:visitor_id&quot;] = Visitor::current()-&gt;id;
-
-            $options[&quot;group&quot;][] = &quot;id&quot;;
-            $options[&quot;group&quot;][] = &quot;post_attributes.name&quot;;
-
-            return $options;
-        }
-
         public function cacher_regenerate_posts_triggers($array) {
             $array = array_merge($array, array(&quot;add_comment&quot;, &quot;update_comment&quot;, &quot;delete_comment&quot;));
             return $array;</diff>
      <filename>modules/comments/comments.php</filename>
    </modified>
    <modified>
      <diff>@@ -197,7 +197,7 @@
                                &quot;user_id&quot;=&gt; $user_id,
                                &quot;created_at&quot; =&gt; fallback($created_at, datetime()),
                                &quot;updated_at&quot; =&gt; fallback($updated_at, &quot;0000-00-00 00:00:00&quot;)));
-            $new = new self($sql-&gt;latest());;
+            $new = new self($sql-&gt;latest());
 
             Trigger::current()-&gt;call(&quot;add_comment&quot;, $new);
             return $new;</diff>
      <filename>modules/comments/model.Comment.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>7e8768b454fb3d5cf8cda1813524c80002b3584c</id>
    </parent>
  </parents>
  <author>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </author>
  <url>http://github.com/vito/chyrp/commit/ad0af46a4d2b7b5ec8a63f3ac2962de14b6a0339</url>
  <id>ad0af46a4d2b7b5ec8a63f3ac2962de14b6a0339</id>
  <committed-date>2008-11-19T19:29:37-08:00</committed-date>
  <authored-date>2008-11-19T19:29:37-08:00</authored-date>
  <message>* 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.</message>
  <tree>bf5026cc9ea2e469fa21fb24eb39639cfaf7acab</tree>
  <committer>
    <name>Alex Suraci</name>
    <email>i.am@toogeneric.com</email>
  </committer>
</commit>
