head: include canonical location in og:url
[minimedit.git] / article.inc.php
index da1836890a7c096dfc77b48d18da2705ce791326..dd3d5b2996d777fafe929c593dd666b5c97a5033 100644 (file)
@@ -22,7 +22,7 @@ class ArchiveArticle
        function __construct($path)
        {
                $this->page = preg_replace('{^\.(?:/|$)}', '', $path);
-               $this->link = preg_replace('{(?:/index)?\.html$}', '', $this->page);
+               $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->page);
                $this->raw($this->page);
        }
 
@@ -50,6 +50,30 @@ class ArchiveArticle
                return $this->$col = $this->$col();  # run method and cache
        }
 
+       function handler()
+       {
+               $path = $this->link;
+               $this->path = '';
+               $this->restricted = FALSE;
+               while (TRUE) {
+                       if (file_exists("$path/.private")) {
+                               $this->restricted = $path;
+                       }
+
+                       if (file_exists("$path/index.php")) {
+                               return $path;
+                       }
+
+                       $up = strrpos($path, '/');
+                       $this->path = substr($path, $up) . $this->path;
+                       $path = substr($path, 0, $up);
+                       if ($up === FALSE) {
+                               break;
+                       }
+               }
+               return;
+       }
+
        function safetitle()
        {
                return trim($this->meta['og:title'] ?? strip_tags($this->title));
@@ -86,7 +110,7 @@ class ArchiveArticle
        function story()
        {
                if ( preg_match('{
-                       \n (?: < (?: p | figure [^>]* ) >\s* )+ (<img\ [^>]*>) | \n <hr\ />
+                       (?: < (?: p | figure [^>]* ) >\s* )+ (<img\ [^>]*>) | \n <hr\ />
                }x', $this->body, $img, PREG_OFFSET_CAPTURE) ) {
                        # strip part after matching divider (image)
                        if (isset($img[1])) {
@@ -108,7 +132,7 @@ class ArchiveArticle
                        </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) {
+                       if ($bodyp[1][1] < 512) {
                                return $bodyp[1][0];
                        }
                }