diff options
author | Thomas Lange <code@nerdmind.de> | 2017-05-05 02:38:39 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2017-05-05 02:38:39 +0200 |
commit | 796ea918866c15f0d59ce178d095022edfaf096d (patch) | |
tree | ae2891847e9371921b9834f727c0bd9cd2be42f6 | |
parent | 5b3e9c5b10d08d94b05b2afc38196eded71c7781 (diff) | |
download | blog-2.1.tar.gz blog-2.1.tar.xz blog-2.1.zip |
A significant increase in the response time has been achieved, since the template parameters "$ITEM['BODY']['TEXT']" and "$ITEM['BODY']['HTML']" are now no longer strings but closures (anonymous functions). This means that the underlying logic, which parses the content or converts it into Markdown, is not executed until one of these parameters is really needed and called in the template (which maybe significantly increases the response time on a long list of items which not use one of those two parameters).v2.1
This means that within templates you now have to call these parameters in the following way (note the brackets at the end, which represent a function call):
<?=$ITEM['BODY']['TEXT']()?>
<?=$ITEM['BODY']['HTML']()?>
In the background, the anonymous functions are called and executes $Item->getBody() and $Item->getHTML() only when needed. Previously, $Item->getBody() and $Item->getHTML() were basically executed and the parsed content was passed to the template, regardless of whether these parameters are required in the template or not!
-rw-r--r-- | core/functions.php | 16 | ||||
-rw-r--r-- | core/include/page/main.php | 2 | ||||
-rw-r--r-- | core/include/post/main.php | 2 | ||||
-rw-r--r-- | core/include/user/main.php | 2 | ||||
-rw-r--r-- | template/admin/html/page/item.php | 2 | ||||
-rw-r--r-- | template/admin/html/post/item.php | 2 | ||||
-rw-r--r-- | template/admin/html/user/item.php | 2 | ||||
-rw-r--r-- | template/standard/html/feed/item_page.php | 4 | ||||
-rw-r--r-- | template/standard/html/feed/item_post.php | 4 | ||||
-rw-r--r-- | template/standard/html/home.php | 2 | ||||
-rw-r--r-- | template/standard/html/page/item.php | 2 | ||||
-rw-r--r-- | template/standard/html/page/main.php | 2 | ||||
-rw-r--r-- | template/standard/html/post/item.php | 2 | ||||
-rw-r--r-- | template/standard/html/post/main.php | 2 | ||||
-rw-r--r-- | template/standard/html/user/item.php | 2 | ||||
-rw-r--r-- | template/standard/html/user/main.php | 2 |
16 files changed, 29 insertions, 21 deletions
diff --git a/core/functions.php b/core/functions.php index 91a4006..fc97e3b 100644 --- a/core/functions.php +++ b/core/functions.php @@ -100,8 +100,12 @@ function generateItemData(Item $Item): array { ], 'BODY' => [ - 'TEXT' => $Item->getBody(), - 'HTML' => $Item->getHTML() + 'TEXT' => function() use($Item) { + return $Item->getBody(); + }, + 'HTML' => function() use($Item) { + return $Item->getHTML(); + } ], 'ATTR' => [ @@ -148,8 +152,12 @@ function generateUserItemData(User\Item $User): array { ], 'BODY' => [ - 'TEXT' => $User->getBody(), - 'HTML' => $User->getHTML() + 'TEXT' => function() use($User) { + return $User->getBody(); + }, + 'HTML' => function() use($User) { + return $User->getHTML(); + } ], 'ATTR' => [ diff --git a/core/include/page/main.php b/core/include/page/main.php index bf3e03e..01579fc 100644 --- a/core/include/page/main.php +++ b/core/include/page/main.php @@ -47,7 +47,7 @@ try { $MainTemplate->set('HTML', $PageTemplate); $MainTemplate->set('HEAD', [ 'NAME' => $page_data['ATTR']['NAME'], - 'DESC' => description($page_data['BODY']['HTML'], Application::get('PAGE.DESCRIPTION_SIZE')), + 'DESC' => description($page_data['BODY']['HTML'](), Application::get('PAGE.DESCRIPTION_SIZE')), 'PERM' => $page_data['URL'], 'OG_IMAGES' => $page_data['FILE']['LIST'] ]); diff --git a/core/include/post/main.php b/core/include/post/main.php index dc3cbdc..8cd0a49 100644 --- a/core/include/post/main.php +++ b/core/include/post/main.php @@ -47,7 +47,7 @@ try { $MainTemplate->set('HTML', $PostTemplate); $MainTemplate->set('HEAD', [ 'NAME' => $post_data['ATTR']['NAME'], - 'DESC' => description($post_data['BODY']['HTML'], Application::get('POST.DESCRIPTION_SIZE')), + 'DESC' => description($post_data['BODY']['HTML'](), Application::get('POST.DESCRIPTION_SIZE')), 'PERM' => $post_data['URL'], 'OG_IMAGES' => $post_data['FILE']['LIST'] ]); diff --git a/core/include/user/main.php b/core/include/user/main.php index 79e0ea9..ba0d07b 100644 --- a/core/include/user/main.php +++ b/core/include/user/main.php @@ -62,7 +62,7 @@ try { $MainTemplate->set('HTML', $UserTemplate); $MainTemplate->set('HEAD', [ 'NAME' => $user_data['ATTR']['FULLNAME'], - 'DESC' => description($user_data['BODY']['HTML'], Application::get('USER.DESCRIPTION_SIZE')), + 'DESC' => description($user_data['BODY']['HTML'](), Application::get('USER.DESCRIPTION_SIZE')), 'PERM' => $User->getURL(), 'OG_IMAGES' => $User->getFiles() ]); diff --git a/template/admin/html/page/item.php b/template/admin/html/page/item.php index a19afa9..599e942 100644 --- a/template/admin/html/page/item.php +++ b/template/admin/html/page/item.php @@ -7,7 +7,7 @@ </div> </header> <blockquote cite="<?=$PAGE['URL']?>"> - <p><?=excerpt($PAGE['BODY']['HTML'])?></p> + <p><?=excerpt($PAGE['BODY']['HTML']())?></p> </blockquote> <?php if($PAGE['ARGV']): ?> diff --git a/template/admin/html/post/item.php b/template/admin/html/post/item.php index 750b03d..abc2b0f 100644 --- a/template/admin/html/post/item.php +++ b/template/admin/html/post/item.php @@ -7,7 +7,7 @@ </div> </header> <blockquote cite="<?=$POST['URL']?>"> - <p><?=excerpt($POST['BODY']['HTML'])?></p> + <p><?=excerpt($POST['BODY']['HTML']())?></p> </blockquote> <?php if($POST['ARGV']): ?> diff --git a/template/admin/html/user/item.php b/template/admin/html/user/item.php index 439916e..731f6b5 100644 --- a/template/admin/html/user/item.php +++ b/template/admin/html/user/item.php @@ -6,7 +6,7 @@ </div> </header> <blockquote cite="<?=$USER['URL']?>"> - <p><?=excerpt($USER['BODY']['HTML'])?></p> + <p><?=excerpt($USER['BODY']['HTML']())?></p> </blockquote> <?php if($USER['ARGV']): ?> diff --git a/template/standard/html/feed/item_page.php b/template/standard/html/feed/item_page.php index f1a7a4d..25d7d30 100644 --- a/template/standard/html/feed/item_page.php +++ b/template/standard/html/feed/item_page.php @@ -13,10 +13,10 @@ <guid isPermaLink="false"><?=$PAGE['GUID']?></guid> <pubDate><?=parseDatetime($PAGE['ATTR']['TIME_INSERT'], '[RFC2822]')?></pubDate> <dc:creator><?=escapeHTML($USER['ATTR']['FULLNAME'])?></dc:creator> - <description><?=escapeHTML(description($PAGE['BODY']['HTML'], 400))?></description> + <description><?=escapeHTML(description($PAGE['BODY']['HTML'](), 400))?></description> <content:encoded> <![CDATA[ - <?=$PAGE['BODY']['HTML']?> + <?=$PAGE['BODY']['HTML']()?> ]]> </content:encoded> <?php foreach($PAGE['FILE']['LIST'] as $fileURL): ?> diff --git a/template/standard/html/feed/item_post.php b/template/standard/html/feed/item_post.php index d645810..7f477d6 100644 --- a/template/standard/html/feed/item_post.php +++ b/template/standard/html/feed/item_post.php @@ -13,10 +13,10 @@ <guid isPermaLink="false"><?=$POST['GUID']?></guid> <pubDate><?=parseDatetime($POST['ATTR']['TIME_INSERT'], '[RFC2822]')?></pubDate> <dc:creator><?=escapeHTML($USER['ATTR']['FULLNAME'])?></dc:creator> - <description><?=escapeHTML(description($POST['BODY']['HTML'], 400))?></description> + <description><?=escapeHTML(description($POST['BODY']['HTML'](), 400))?></description> <content:encoded> <![CDATA[ - <?=$POST['BODY']['HTML']?> + <?=$POST['BODY']['HTML']()?> ]]> </content:encoded> <?php foreach($POST['FILE']['LIST'] as $fileURL): ?> diff --git a/template/standard/html/home.php b/template/standard/html/home.php index 9909dc1..64206e9 100644 --- a/template/standard/html/home.php +++ b/template/standard/html/home.php @@ -16,4 +16,4 @@ <?php endforeach; ?> </ul> -<?=$PAGINATION['HTML']?>
\ No newline at end of file +<?=$PAGINATION['HTML']?> diff --git a/template/standard/html/page/item.php b/template/standard/html/page/item.php index d0058e7..6065354 100644 --- a/template/standard/html/page/item.php +++ b/template/standard/html/page/item.php @@ -15,6 +15,6 @@ </h2> </header> <blockquote cite="<?=$PAGE['URL']?>"> - <p><?=excerpt($PAGE['BODY']['HTML'], 600)?></p> + <p><?=excerpt($PAGE['BODY']['HTML'](), 600)?></p> </blockquote> </li>
\ No newline at end of file diff --git a/template/standard/html/page/main.php b/template/standard/html/page/main.php index 621b939..3b62571 100644 --- a/template/standard/html/page/main.php +++ b/template/standard/html/page/main.php @@ -14,7 +14,7 @@ $time = "<time datetime=\"{$PAGE['ATTR']['TIME_INSERT']}\" title=\"".parseDateti <p><?=$Language->template('page_main_heading_desc', [$user, $time])?></p> <section id="content" class="page"> - <?=$PAGE['BODY']['HTML']?> + <?=$PAGE['BODY']['HTML']()?> </section> <section id="site-navi"> diff --git a/template/standard/html/post/item.php b/template/standard/html/post/item.php index f0c12d5..19ff3f9 100644 --- a/template/standard/html/post/item.php +++ b/template/standard/html/post/item.php @@ -15,6 +15,6 @@ </h2> </header> <blockquote cite="<?=$POST['URL']?>"> - <?=$POST['BODY']['HTML']?> + <?=$POST['BODY']['HTML']()?> </blockquote> </li>
\ No newline at end of file diff --git a/template/standard/html/post/main.php b/template/standard/html/post/main.php index 5104ba9..22974dc 100644 --- a/template/standard/html/post/main.php +++ b/template/standard/html/post/main.php @@ -14,7 +14,7 @@ $time = "<time datetime=\"{$POST['ATTR']['TIME_INSERT']}\" title=\"".parseDateti <p><?=$Language->template('post_main_heading_desc', [$user, $time])?></p> <section id="content" class="post"> - <?=$POST['BODY']['HTML']?> + <?=$POST['BODY']['HTML']()?> </section> <section id="site-navi"> diff --git a/template/standard/html/user/item.php b/template/standard/html/user/item.php index 65dce5b..3a33c51 100644 --- a/template/standard/html/user/item.php +++ b/template/standard/html/user/item.php @@ -15,6 +15,6 @@ </h2> </header> <blockquote cite="<?=$USER['URL']?>"> - <?=$USER['BODY']['HTML']?> + <?=$USER['BODY']['HTML']()?> </blockquote> </li>
\ No newline at end of file diff --git a/template/standard/html/user/main.php b/template/standard/html/user/main.php index c2a5346..473b00b 100644 --- a/template/standard/html/user/main.php +++ b/template/standard/html/user/main.php @@ -11,7 +11,7 @@ <p><em><?=$Language->template('user_main_heading_desc', [escapeHTML($USER['ATTR']['USERNAME']), $COUNT['POST'], $COUNT['PAGE']])?></em></p> <section id="content" class="user"> - <?=$USER['BODY']['HTML']?> + <?=$USER['BODY']['HTML']()?> </section> <section id="site-navi"> |