widget/sitemap: order pages hierarchically and alphabetically
[minimedit.git] / article.inc.php
index 336511e87069e59174a80c73d84898562dabe431..a6a4ef800e9504f7440a5d34b42d774606c2fe96 100644 (file)
@@ -82,7 +82,27 @@ class ArchiveArticle
        }
        function teaser()
        {
-               if (preg_match('{<p>(.*?)</p>}s', $this->story, $bodyp)) {
+               if (preg_match('{
+                       <meta \s+ name="description" [^>]* content="([^">]*)"
+               }x', $this->preface, $meta)) {
+                       # prefer specific page description if found (assume before title)
+                       #TODO: strip from body contents
+                       return $meta[1];
+               }
+
+               if (preg_match('{
+                       </h2> (?: \s+ | <p\sclass="nav\b.*?</p> | <div[^>]*> )* <p> \s* (.*?) </p>
+               }sx', $this->raw, $bodyp, PREG_OFFSET_CAPTURE)) {
+                       # fallback paragraph contents following the page header
+                       if ($bodyp[1][1] < 256) {
+                               return $bodyp[1][0];
+                       }
+               }
+
+               # starting paragraph for documents without title (assumed simple/partial)
+               if (strpos($this->raw, '<h2') === FALSE and preg_match('{
+                       \A <p> \s* (.*?) </p>
+               }sx', $this->raw, $bodyp)) {
                        return $bodyp[1];
                }
        }