Skip to content

Commit 828d014

Browse files
committed
Parsedown loader, Basic theme update
1 parent aab7295 commit 828d014

5 files changed

Lines changed: 87 additions & 105 deletions

File tree

editor/core/scriptor.php

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Scriptor
99
/**
1010
* Application version
1111
*/
12-
const VERSION = '1.9.0';
12+
const VERSION = '1.9.2';
1313

1414
/**
1515
* @var array $config - Configuration parameter
@@ -136,6 +136,30 @@ public static function getEditor($init = true)
136136
return self::$editor;
137137
}
138138

139+
/**
140+
* Injects the Site object
141+
*
142+
* @return void
143+
*/
144+
public static function setSite($site, bool $init = false)
145+
{
146+
self::$site = new $site();
147+
if ($init) self::$site->init();
148+
}
149+
150+
/**
151+
*
152+
* @return object|null
153+
*/
154+
public static function getSite($init = true)
155+
{
156+
if (self::$site === null) {
157+
self::$site = new Site();
158+
if ($init) self::$site->init();
159+
}
160+
return self::$site;
161+
}
162+
139163
/**
140164
* Executes Hook
141165
*
@@ -218,37 +242,6 @@ public static function execHook($object, $method = '', $args = [], $type = '')
218242
return $return;
219243
}
220244

221-
/**
222-
* Injects the Site object
223-
*
224-
* @return void
225-
*/
226-
public static function setSite($site, bool $init = false, string $namespace = '')
227-
{
228-
if (!empty($namespace)) {
229-
$class = "$namespace\\$site";
230-
self::$site = new $class();
231-
} else {
232-
self::$site = new $site();
233-
}
234-
235-
if ($init) self::$site->init();
236-
}
237-
238-
/**
239-
*
240-
* @return object|null
241-
*/
242-
public static function getSite($init = true)
243-
{
244-
if (self::$site === null) {
245-
self::$site = new Site();
246-
if ($init) self::$site->init();
247-
}
248-
return self::$site;
249-
}
250-
251-
252245
/**
253246
*
254247
* @return object|null

editor/core/site.php

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace Scriptor\Core;
44

5+
use Imanager\Input;
56
use Imanager\Item;
7+
use Imanager\SectionCache;
68
use Imanager\TemplateParser;
9+
use Imanager\UrlSegments;
710
use Imanager\Util;
11+
use Scriptor\Core\Modules\Parsedown;
812

913
class Site extends Module
1014
{
@@ -93,11 +97,6 @@ class Site extends Module
9397
*/
9498
public $version;
9599

96-
/**
97-
* @var object - ParseDown instance
98-
*/
99-
public $parsedown;
100-
101100
/**
102101
* @var object - ItemManager's TemplateParser instance
103102
*/
@@ -124,11 +123,10 @@ public function init()
124123
parent::init();
125124
$this->templateParser = new TemplateParser();
126125
$this->themeUrl = $this->siteUrl.'/site/themes/'.$this->config['theme_path'];
127-
$this->input = $this->input();//imanager->input;
126+
$this->input = $this->input();
128127
$this->urlSegments = $this->urlSegments();
129-
$this->firstSegment = $this->urlSegments->get(0);
130-
$this->lastSegment = $this->urlSegments->getLast();
131-
$this->parsedown = $this->loadModule('parsedown', ['namespace' => __NAMESPACE__.'\Modules\\']);
128+
$this->firstSegment = $this->urlSegments->get(0); // Kick it out
129+
$this->lastSegment = $this->urlSegments->getLast(); // same here
132130
$this->version = Scriptor::VERSION;
133131
}
134132

@@ -164,34 +162,59 @@ public function execute() :void
164162
}
165163
}
166164

167-
public function input()
165+
public function input() : Input
168166
{
169167
return ($this->input) ?? $this->imanager->input;
170168
}
171169

172-
public function urlSegments()
170+
public function urlSegments() : UrlSegments
173171
{
174172
return ($this->urlSegments) ?? $this->input->urlSegments;
175173
}
176174

177-
public function pages()
175+
public function sectionCache() : SectionCache
176+
{
177+
return $this->imanager->sectionCache;
178+
}
179+
180+
public function pages() : Pages
178181
{
179182
return ($this->pages) ?? new Pages();
180183
}
181184

182-
public function users()
185+
public function users() : Users
183186
{
184187
return ($this->users) ?? new Users();
185188
}
186189

190+
public function parsedown() : Parsedown
191+
{
192+
if (!isset($this->parsedown)) {
193+
$this->parsedown = $this->loadModule('parsedown', ['namespace' => __NAMESPACE__.'\Modules\\']);
194+
}
195+
return $this->parsedown;
196+
}
197+
187198
/**
188-
* NOTE: "segment" is used only for compatibility reasons.
199+
* NOTE: "segments" is used only for compatibility reasons.
189200
*/
190201
public function __get($arg)
191202
{
192-
if ($arg == 'pages') return $this->pages();
193-
elseif ($arg == 'segments' || $arg == 'urlSegments') return $this->urlSegments();
194-
elseif ($arg == 'users') return $this->users();
203+
switch ($arg) {
204+
case 'pages':
205+
return $this->pages();
206+
break;
207+
case 'segments':
208+
case 'urlSegments':
209+
return $this->urlSegments();
210+
break;
211+
case 'users':
212+
return $this->users();
213+
break;
214+
case 'parsedown':
215+
return $this->parsedown();
216+
break;
217+
}
195218
}
196219

197220
public static function getPageUrl($item, $pages)

site/themes/basic/_ext.php

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,23 @@
1515
require_once __DIR__ . '/vendor/autoload.php';
1616

1717
// BasicTheme extends default Site class
18-
Scriptor::setSite('BasicTheme', true, 'Themes\Basic');
18+
Scriptor::setSite('Themes\Basic\BasicTheme', true);
1919
$site = Scriptor::getSite();
2020

2121
// Crete router instance
2222
$router = new BasicRouter($site);
2323

2424
/*
25-
* SuperCache
26-
* Check if there's a cached version of that page.
25+
* ~ SuperCache
26+
*
27+
* Looks to determine if there is a cached version of the page,
28+
* and if so, retrieves it, outputs it, and interrupts further
29+
* script execution.
30+
*
31+
* NOTE: The user actions are still performed if they have been
32+
* executed, e.g. contact form has been sent, subscriber form
33+
* has been sent, tags, etc.
34+
*
2735
*/
2836
if ($output = $site->imanager->sectionCache->get(
2937
md5($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']),
@@ -38,49 +46,4 @@
3846

3947

4048
// Execute
41-
$router->execute();
42-
43-
/*
44-
UPDATE SCRIPTOR V. 1.4.16 > 1.4.17
45-
46-
// New pages will get a new "menu_title" field after the update, but the pages
47-
// that are already created will have to be overwritten manually.
48-
//
49-
// If you have other custom page fields, fill in the array with their field names:
50-
51-
$YOUR_FIELD_NAMES = [
52-
'slug',
53-
'parent',
54-
'pagetype',
55-
'menu_title',
56-
'content',
57-
'template',
58-
'images'
59-
];
60-
61-
$pages = $imanager->getCategory('name=Pages');
62-
63-
// Create new field 'menu_title' of type 'text'
64-
65-
$newField = new \Imanager\Field($pages->id);
66-
67-
$newField->set('type', 'text')
68-
->set('name', 'menu_title')
69-
->set('label', 'Enter menu title')
70-
->save();
71-
72-
// Adjust the field positions
73-
74-
foreach($YOUR_FIELD_NAMES as $key => $name) {
75-
$field = $pages->getField("name=$name");
76-
$field->set('position', ++$key);
77-
$field->save();
78-
}
79-
80-
echo count($YOUR_FIELD_NAMES).' fields have been updated.';
81-
82-
exit; */
83-
84-
//include __DIR__.'/_configs.php';
85-
//include __DIR__.'/_functions.php';
86-
//checkActions();
49+
$router->execute();

site/themes/basic/lib/Basic.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class BasicTheme extends Site
3131
*/
3232
public function init()
3333
{
34-
ob_start();
3534
parent::init();
3635
$this->config['theme'] = Scriptor::load(__DIR__.'/../_configs.php');
3736
$this->tpls = Scriptor::load(__DIR__.'/_tpls.php');
@@ -253,7 +252,7 @@ private function renderArticlesContent(array $articles = []) :string
253252
$info = '';
254253
if($article->images[0]->title) {
255254
$info = $this->templateParser->render($this->tpls['art_list_image_caption'], [
256-
'TEXT' => $this->parsedown->text($article->images[0]->title)
255+
'TEXT' => $this->parsedown()->text($article->images[0]->title)
257256
]);
258257
}
259258

@@ -265,13 +264,13 @@ private function renderArticlesContent(array $articles = []) :string
265264
]);
266265
}
267266

268-
$this->parsedown->setSafeMode(true);
267+
$this->parsedown()->setSafeMode(true);
269268

270269
if (mb_strlen($article->content) > $this->getTCP('summary_character_len')) {
271-
$content = $this->parsedown->text(mb_substr(htmlspecialchars_decode($article->content), 0,
270+
$content = $this->parsedown()->text(mb_substr(htmlspecialchars_decode($article->content), 0,
272271
$this->getTCP('summary_character_len')).' ...');
273272
} else {
274-
$content = $this->parsedown->text(htmlspecialchars_decode($article->content));
273+
$content = $this->parsedown()->text(htmlspecialchars_decode($article->content));
275274
}
276275

277276
$list .= $this->templateParser->render($this->tpls['article_row'], [
@@ -325,7 +324,7 @@ private function renderHero() :string
325324
$imageUrl = $this->getBasePath().$this->page->images[0]->resize(1200, 0);
326325
$hero = $this->templateParser->render($this->tpls['hero'], [
327326
'SRC' => $imageUrl,
328-
'INFO' => $this->parsedown->text($this->page->images[0]->title)
327+
'INFO' => $this->parsedown()->text($this->page->images[0]->title)
329328
]);
330329
}
331330
return $hero;
@@ -767,7 +766,10 @@ public function getFormatedPageDate(int $datestamp) :string
767766
public function cache() :string
768767
{
769768
$output = ob_get_clean();
770-
if ($this->page && in_array($this->page->template, $this->getTCP('cacheable_templates'))) {
769+
if ($this->page &&
770+
$this->getTCP('markup_cache_time') &&
771+
in_array($this->page->template, $this->getTCP('cacheable_templates')))
772+
{
771773
$this->imanager->sectionCache->save($output);
772774
}
773775
return $output;

site/themes/basic/template.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$tplName = $site->sanitizer->templateName($site->page->template);
44
$tplFile = __DIR__."/$tplName.php";
55

6+
ob_start();
67
if(file_exists($tplFile)) {
78
include $tplFile;
89
} else {

0 commit comments

Comments
 (0)