page: text/plain request triggers api mode
[minimedit.git] / article.inc.php
index 36639f2a222129d13cf632629a4ce5e7e6c88a95..1dbda25e0dc1b3c70186114979605e71a8a9acfa 100644 (file)
@@ -4,12 +4,13 @@ class ArchiveArticle
        public $raw, $title, $body; # file contents
        public $meta = [];  # head metadata properties
        public $place = []; # template variables replaced in render()
+       public $api = FALSE; # requested programming interface
 
        function __construct($path)
        {
-               $this->page = preg_replace('{^\.(?:/|$)}', '', $path);
-               $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->page);
-               $this->raw($this->page);
+               $this->file = preg_replace('{^\.(?:/|$)}', '', $path);
+               $this->link = preg_replace('{(?:(?:/|^)index)?\.html$}', '', $this->file);
+               $this->raw($this->file);
        }
 
        function raw($page)
@@ -71,7 +72,7 @@ class ArchiveArticle
                if (empty($this->handler)) {
                        return;
                }
-               $User = NULL;
+               $this->api = TRUE;
                $Page = $this;
                $res = include "./{$this->handler}/index.php";
                return $res;
@@ -94,7 +95,7 @@ class ArchiveArticle
 
        function last()
        {
-               return filemtime($this->page);
+               return filemtime($this->file);
        }
        function lastiso()
        {
@@ -103,7 +104,7 @@ class ArchiveArticle
 
        function dateparts()
        {
-               preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->page, $ymd);
+               preg_match('< / (\d{4}) [/-] (\d{2}) (?:- (\d{2}) )? - >x', $this->file, $ymd);
                array_shift($ymd);
                return $ymd;
        }
@@ -165,8 +166,9 @@ class ArchiveArticle
                        return ltrim($this->image, '/');
                }
                return preg_replace(
-                       ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/'], ["thumb/$size", ''],
-                       $this->image
+                       ['{^(?:/thumb/[^/]*)?}', '/\.groot(?=\.\w+$)/', '/(?:\.jpg)?$/'],
+                       [      "thumb/$size",    '',                         '.jpg'    ],
+                       $this->image, 1
                );
        }