Updated FP-specific Smarty plugin "Admin" to v4 OOP style. Replaced obsolete get_template_vars() calls with getTemplateVars().

This commit is contained in:
azett 2022-01-29 15:20:42 +01:00
parent e7a64816d6
commit 25c1618042
9 changed files with 58 additions and 77 deletions

View File

@ -80,8 +80,8 @@ function main() {
if ($retval > 0) { // if has REDIRECT option
// clear postdata by a redirect
sess_add("success_{$panel}", $smarty->get_template_vars('success'));
$smarty->get_template_vars('success');
sess_add("success_{$panel}", $smarty->getTemplateVars('success'));
$smarty->getTemplateVars('success');
$to_action = $retval > 1 ? ('&action=' . $action) : '';
$with_mod = isset($_GET ['mod']) ? ('&mod=' . $_GET ['mod']) : '';
@ -176,7 +176,7 @@ if (isset($_GET ['mod'])) {
$smarty->display(ABS_PATH . ADMIN_DIR . 'admin-inline.tpl');
break;
case 'ajax':
echo $smarty->get_template_vars('success');
echo $smarty->getTemplateVars('success');
}
} else {
$smarty->display('admin.tpl');

View File

@ -20,7 +20,7 @@
// ---------------------------------------------------------------------
function smarty_function_flag_classes($params, &$smarty) {
$flags = entry_flags_get();
($active_flags = array_intersect($smarty->get_template_vars('categories'), $flags));
($active_flags = array_intersect($smarty->getTemplateVars('categories'), $flags));
return implode(' ', $active_flags);
}

View File

@ -35,6 +35,7 @@
<p>
<label for="content">{$panelstrings.content}</label>
</p>
{* FIXME AZI: Smarty compiler error "unknown tag 'toolbar'". How did this ever work? Should that be better {include file='plugin:bbcode/toolbar'}? *}
{toolbar}
<p>
<textarea name="content" class="{$class}"

View File

@ -177,7 +177,7 @@ function smarty_block_draft($params, $content, &$smarty, &$repeat) {
'version' => '',
'id' => ''
));
$arr = & $smarty->get_template_vars('draft_list');
$arr = & $smarty->getTemplateVars('draft_list');
$id = $subject = null;
if ($arr) {

View File

@ -101,8 +101,8 @@ function smarty_block_static($params, $content, &$smarty, &$repeat) {
'id' => ''
));
if ($arr = $smarty->get_template_vars('static_page')) {
$smarty->assign('id', $smarty->get_template_vars('static_id'));
if ($arr = $smarty->getTemplateVars('static_page')) {
$smarty->assign('id', $smarty->getTemplateVars('static_id'));
if (THEME_LEGACY_MODE)
theme_entry_filters($arr);
$smarty->assign($arr);
@ -119,7 +119,7 @@ function smarty_block_static($params, $content, &$smarty, &$repeat) {
return $content;
}
$list = $smarty->get_template_vars('statics');
$list = $smarty->getTemplateVars('statics');
if (isset($list [$pointer])) {
// foreach ($entry as $k => $val)

View File

@ -1,58 +1,39 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: resource.admin.php
* Type: admin tpls
* Name: admin
* Purpose: convenient way to call stored tpls in ADMIN_DIR
* -------------------------------------------------------------
/**
* Resoure plugin that conveniently allows to include templates from the admin templates folder.
*
* @author FlatPress
* @see https://www.smarty.net/docs/en/plugins.resources.tpl
*/
class Smarty_Resource_Admin extends Smarty_Resource_Custom {
/**
*
* {@inheritdoc}
* @see Smarty_Resource_Custom::fetch()
*/
protected function fetch($name, &$source, &$mtime) {
$filePath = $this->getFilePath($name);
function smarty_resource_admin_parsename($tpl_name) {
if ($source = io_load_file($filePath)) {
$mtime = filemtime($filePath);
} else {
$source = null;
$mtime = null;
}
}
private function getFilePath($templateName) {
$path = null;
$tpl_name;
$panel = strtok($tpl_name, '/');
if ($action = strtok('/'))
$panel = strtok($templateName, '/');
if ($action = strtok('/')) {
$path = ABS_PATH . ADMIN_DIR . "panels/$panel/admin.$panel.$action.tpl";
if (!$action || !file_exists($path))
}
if (!$action || !file_exists($path)) {
$path = ABS_PATH . ADMIN_DIR . "panels/$panel/admin.$panel.tpl";
}
return $path;
}
function smarty_resource_admin_source($tpl_name, &$tpl_source, &$smarty)
{
$fname = smarty_resource_admin_parsename($tpl_name);
if ($tpl_source = io_load_file($fname)) {
return true;
} else {
return false;
}
}
function smarty_resource_admin_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
{
$fname = smarty_resource_admin_parsename($tpl_name);
if (file_exists($fname)) {
$tpl_timestamp = filemtime($fname);
return true;
} else {
return false;
}
}
function smarty_resource_admin_secure($tpl_name, &$smarty)
{
return true;
}
function smarty_resource_admin_trusted($tpl_name, &$smarty)
{
}
?>

View File

@ -135,9 +135,9 @@ class admin_entry_commentcenter extends AdminPanelAction {
function _redirect($cmd, $cmdval = 1, $nosuccess = false) {
global $panel;
$smarty = &$this->smarty;
sess_add("success_{$panel}", $smarty->get_template_vars('success'));
sess_add("success_{$panel}", $smarty->getTemplateVars('success'));
$action_url = $smarty->get_template_vars('action_url');
$action_url = $smarty->getTemplateVars('action_url');
$url = admin_filter_command($action_url, $cmd, $cmdval);
$url = html_entity_decode($url);
$url = substr($url, strlen(BLOG_BASEURL));

View File

@ -2,7 +2,6 @@
/**
* This file integrates the plugin into the entry editor.
*/
if (!class_exists('plugin_commentcenter')) {
die('Don\'t try to hack us.');
}
@ -21,8 +20,8 @@ function plugin_commentcenter_editor() {
$entry = $_REQUEST ['entry'];
$plugin = &$GLOBALS ['plugin_commentcenter'];
$plang = &$lang ['admin'] ['entry'] ['commentcenter'];
$arr=$smarty->get_template_vars('post');
$panel_url=$smarty->get_template_vars('panel_url');
$arr = $smarty->getTemplateVars('post');
$panel_url = $smarty->getTemplateVars('panel_url');
$plugin->loadPolicies();
$do = $plugin->behavoirFromPolicies($entry, @$arr ['categories']);

View File

@ -66,7 +66,7 @@ class footnotes_class {
function plugin_footnotes_filter($text) {
global $smarty;
$footnotes_obj = new footnotes_class($id = $smarty->get_template_vars('id'));
$footnotes_obj = new footnotes_class($id = $smarty->getTemplateVars('id'));
// *STRONG* emphasis
$text = preg_replace('|(?<!\S)\*(?=\S) (?! \*) (.+?) (?<=\S) \*(?!>\w)|xs', '<strong>$1</strong>', $text);