Skip to content

Commit

Permalink
pkp#3242 Update Smarty API calls for Smarty 3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy-1 authored and asmecher committed Jan 5, 2018
1 parent 472cbc1 commit 956b85b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 70 deletions.
32 changes: 16 additions & 16 deletions classes/form/FormBuilderVocabulary.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function smartyFBVFormSection($params, $content, &$smarty, &$repeat) {
$class = $params['class'];

// Check if we are using the Form class and if there are any errors
$smarty->clear_assign(array('FBV_sectionErrors'));
$smarty->clearAssign(array('FBV_sectionErrors'));
if (isset($form) && !empty($form->formSectionErrors)) {
$class = $class . (empty($class) ? '' : ' ') . 'error';
$smarty->assign('FBV_sectionErrors', $form->formSectionErrors);
Expand Down Expand Up @@ -320,7 +320,7 @@ function _smartyFBVButton($params, &$smarty) {
// the type of this button. the default value is 'button' (but could be 'submit')

$buttonParams = '';
$smarty->clear_assign(array('FBV_label', 'FBV_disabled'));
$smarty->clearAssign(array('FBV_label', 'FBV_disabled'));
foreach ($params as $key => $value) {
switch ($key) {
case 'inline':
Expand Down Expand Up @@ -356,7 +356,7 @@ function _smartyFBVAutocompleteInput($params, &$smarty) {
// and make sure that the text input is not read by the Form class.
$params['id'] = $autocompleteId . '_input';

$smarty->clear_assign(array('FBV_id', 'FBV_autocompleteUrl', 'FBV_autocompleteValue'));
$smarty->clearAssign(array('FBV_id', 'FBV_autocompleteUrl', 'FBV_autocompleteValue'));
// We set this now, so that we unset the param for the text input.
$smarty->assign('FBV_autocompleteUrl', $params['autocompleteUrl']);
$smarty->assign('FBV_autocompleteValue', isset($params['autocompleteValue']) ? $params['autocompleteValue'] : null);
Expand Down Expand Up @@ -406,7 +406,7 @@ function _smartyFBVTextInput($params, &$smarty) {
$smarty->assign('FBV_isTypeURL', ($params['type'] === 'url') ? true : false);

$textInputParams = '';
$smarty->clear_assign(array('FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_label_content', 'FBV_uniqId'));
$smarty->clearAssign(array('FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_label_content', 'FBV_uniqId'));
foreach ($params as $key => $value) {
switch ($key) {
case 'label': $smarty->assign('FBV_label_content', $this->_smartyFBVSubLabel($params, $smarty)); break;
Expand Down Expand Up @@ -457,7 +457,7 @@ function _smartyFBVTextArea($params, &$smarty) {
$params['uniqId'] = uniqid();

$textAreaParams = '';
$smarty->clear_assign(array('FBV_label_content', 'FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_height', 'FBV_uniqId', 'FBV_rows', 'FBV_cols', 'FBV_rich', 'FBV_variables', 'FBV_variablesType'));
$smarty->clearAssign(array('FBV_label_content', 'FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_height', 'FBV_uniqId', 'FBV_rows', 'FBV_cols', 'FBV_rich', 'FBV_variables', 'FBV_variablesType'));
foreach ($params as $key => $value) {
switch ($key) {
case 'name':
Expand Down Expand Up @@ -512,7 +512,7 @@ function _smartyFBVColour($params, &$smarty) {
$smarty->assign('FBV_isPassword', isset($params['password']) ? true : false);

$colourParams = '';
$smarty->clear_assign(array('FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_label_content', 'FBV_uniqId', 'FBV_default'));
$smarty->clearAssign(array('FBV_disabled', 'FBV_readonly', 'FBV_multilingual', 'FBV_name', 'FBV_value', 'FBV_label_content', 'FBV_uniqId', 'FBV_default'));
foreach ($params as $key => $value) {
switch ($key) {
case 'label': $smarty->assign('FBV_label_content', $this->_smartyFBVSubLabel($params, $smarty)); break;
Expand Down Expand Up @@ -549,7 +549,7 @@ function _smartyFBVHiddenInput($params, &$smarty) {
$params['name'] = isset($params['name']) ? $params['name'] : $params['id'];

$hiddenInputParams = '';
$smarty->clear_assign(array('FBV_id', 'FBV_value'));
$smarty->clearAssign(array('FBV_id', 'FBV_value'));
foreach ($params as $key => $value) {
switch ($key) {
case 'name':
Expand Down Expand Up @@ -582,7 +582,7 @@ function _smartyFBVSelect($params, &$smarty) {

$selectParams = '';

$smarty->clear_assign(array('FBV_label', 'FBV_from', 'FBV_selected', 'FBV_label_content', 'FBV_defaultValue', 'FBV_defaultLabel', 'FBV_required', 'FBV_disabled'));
$smarty->clearAssign(array('FBV_label', 'FBV_from', 'FBV_selected', 'FBV_label_content', 'FBV_defaultValue', 'FBV_defaultLabel', 'FBV_required', 'FBV_disabled'));
foreach ($params as $key => $value) {
switch ($key) {
case 'from':
Expand Down Expand Up @@ -622,7 +622,7 @@ function _smartyFBVCheckboxGroup($params, &$smarty) {
$params['subLabelTranslate'] = isset($params['subLabelTranslate']) ? (boolean) $params['subLabelTranslate'] : true;
$checkboxParams = '';

$smarty->clear_assign(array('FBV_from', 'FBV_selected', 'FBV_label_content', 'FBV_defaultValue', 'FBV_defaultLabel', 'FBV_name'));
$smarty->clearAssign(array('FBV_from', 'FBV_selected', 'FBV_label_content', 'FBV_defaultValue', 'FBV_defaultLabel', 'FBV_name'));
foreach ($params as $key => $value) {
switch ($key) {
case 'from':
Expand Down Expand Up @@ -658,7 +658,7 @@ function _smartyFBVCheckbox($params, &$smarty) {
$params['translate'] = isset($params['translate']) ? (boolean)$params['translate'] : true;

$checkboxParams = '';
$smarty->clear_assign(array('FBV_id', 'FBV_label', 'FBV_checked', 'FBV_disabled'));
$smarty->clearAssign(array('FBV_id', 'FBV_label', 'FBV_checked', 'FBV_disabled'));
foreach ($params as $key => $value) {
switch ($key) {
case 'type': break;
Expand Down Expand Up @@ -693,7 +693,7 @@ function _smartyFBVRadioButton($params, &$smarty) {
}

$radioParams = '';
$smarty->clear_assign(array('FBV_id', 'FBV_label', 'FBV_content', 'FBV_checked', 'FBV_disabled'));
$smarty->clearAssign(array('FBV_id', 'FBV_label', 'FBV_content', 'FBV_checked', 'FBV_disabled'));
foreach ($params as $key => $value) {
switch ($key) {
case 'type': break;
Expand Down Expand Up @@ -724,7 +724,7 @@ function _smartyFBVFileInput($params, &$smarty) {
$params['name'] = isset($params['name']) ? $params['name'] : $params['id'];
$params['translate'] = isset($params['translate']) ? $params['translate'] : true;

$smarty->clear_assign(array('FBV_id', 'FBV_label_content', 'FBV_checked', 'FBV_disabled', 'FBV_submit'));
$smarty->clearAssign(array('FBV_id', 'FBV_label_content', 'FBV_checked', 'FBV_disabled', 'FBV_submit'));
foreach ($params as $key => $value) {
switch ($key) {
case 'type': break;
Expand All @@ -750,7 +750,7 @@ function _smartyFBVFileInput($params, &$smarty) {
function _smartyFBVKeywordInput($params, &$smarty) {
$params['uniqId'] = uniqid();

$smarty->clear_assign(array('FBV_id', 'FBV_label', 'FBV_label_content', 'FBV_currentKeywords', 'FBV_multilingual', 'FBV_sourceUrl', 'FBV_uniqId', 'FBV_disabled'));
$smarty->clearAssign(array('FBV_id', 'FBV_label', 'FBV_label_content', 'FBV_currentKeywords', 'FBV_multilingual', 'FBV_sourceUrl', 'FBV_uniqId', 'FBV_disabled'));
$emptyFormLocaleMap = array_fill_keys(array_keys($smarty->get_template_vars('formLocales')), array());
$smarty->assign('FBV_availableKeywords', $emptyFormLocaleMap);
foreach ($params as $key => $value) {
Expand Down Expand Up @@ -785,7 +785,7 @@ function _smartyFBVKeywordInput($params, &$smarty) {
* @param $smarty object
*/
function _smartyFBVInterestsInput($params, &$smarty) {
$smarty->clear_assign(array('FBV_id', 'FBV_label', 'FBV_label_content', 'FBV_interests'));
$smarty->clearAssign(array('FBV_id', 'FBV_label', 'FBV_label_content', 'FBV_interests'));
$params['subLabelTranslate'] = isset($params['subLabelTranslate']) ? (boolean) $params['subLabelTranslate'] : true;
foreach ($params as $key => $value) {
switch ($key) {
Expand Down Expand Up @@ -818,7 +818,7 @@ function _smartyFBVSubLabel($params, &$smarty) {
$smarty->assign('FBV_error', false);
}

$smarty->clear_assign(array('FBV_suppressId', 'FBV_label', 'FBV_required', 'FBV_uniqId', 'FBV_multilingual', 'FBV_required'));
$smarty->clearAssign(array('FBV_suppressId', 'FBV_label', 'FBV_required', 'FBV_uniqId', 'FBV_multilingual', 'FBV_required'));
foreach ($params as $key => $value) {
switch ($key) {
case 'subLabelTranslate': $smarty->assign('FBV_subLabelTranslate', $value); break;
Expand Down Expand Up @@ -899,7 +899,7 @@ function smartyFieldLabel($params, &$smarty) {
$smarty->assign('FBV_class', $params['class']);
}

$smarty->clear_assign(array('FBV_suppressId', 'FBV_label', 'FBV_required', 'FBV_disabled', 'FBV_name'));
$smarty->clearAssign(array('FBV_suppressId', 'FBV_label', 'FBV_required', 'FBV_disabled', 'FBV_name'));
foreach ($params as $key => $value) {
switch ($key) {
case 'label':
Expand Down
106 changes: 52 additions & 54 deletions classes/template/PKPTemplateManager.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import('lib.pkp.classes.template.PKPTemplateResource');

class PKPTemplateManager extends Smarty {
class PKPTemplateManager extends SmartyBC {
/** @var array of URLs to stylesheets */
private $_styleSheets = array();

Expand All @@ -61,6 +61,15 @@ class PKPTemplateManager extends Smarty {
/** @var PKPRequest */
private $_request;

/** @var string path to the active theme templates */
private $theme_template_dir;

/** @var string path to the old templates */
private $app_template_dir;

/** @var string path to the new templates */
private $core_template_dir;

/**
* Constructor.
* Initialize template engine and assign basic template variables.
Expand Down Expand Up @@ -298,68 +307,68 @@ function initialize() {
}

// Register custom functions
$this->register_modifier('translate', array('AppLocale', 'translate'));
$this->register_modifier('strip_unsafe_html', array('PKPString', 'stripUnsafeHtml'));
$this->register_modifier('String_substr', array('PKPString', 'substr'));
$this->register_modifier('dateformatPHP2JQueryDatepicker', array('PKPString', 'dateformatPHP2JQueryDatepicker'));
$this->register_modifier('to_array', array($this, 'smartyToArray'));
$this->register_modifier('compare', array($this, 'smartyCompare'));
$this->register_modifier('concat', array($this, 'smartyConcat'));
$this->register_modifier('strtotime', array($this, 'smartyStrtotime'));
$this->register_modifier('explode', array($this, 'smartyExplode'));
$this->register_modifier('assign', array($this, 'smartyAssign'));
$this->register_modifier('escape', array(&$this, 'smartyEscape'));
$this->register_function('csrf', array($this, 'smartyCSRF'));
$this->register_function('translate', array($this, 'smartyTranslate'));
$this->register_function('null_link_action', array($this, 'smartyNullLinkAction'));
$this->register_function('help', array($this, 'smartyHelp'));
$this->register_function('flush', array($this, 'smartyFlush'));
$this->register_function('call_hook', array($this, 'smartyCallHook'));
$this->register_function('html_options_translate', array($this, 'smartyHtmlOptionsTranslate'));
$this->register_block('iterate', array($this, 'smartyIterate'));
$this->register_function('page_links', array($this, 'smartyPageLinks'));
$this->register_function('page_info', array($this, 'smartyPageInfo'));
$this->register_function('pluck_files', array($this, 'smartyPluckFiles'));
$this->registerPlugin('modifier', 'translate', array('AppLocale', 'translate'));
$this->registerPlugin('modifier','strip_unsafe_html', array('PKPString', 'stripUnsafeHtml'));
$this->registerPlugin('modifier','String_substr', array('PKPString', 'substr'));
$this->registerPlugin('modifier','dateformatPHP2JQueryDatepicker', array('PKPString', 'dateformatPHP2JQueryDatepicker'));
$this->registerPlugin('modifier','to_array', array($this, 'smartyToArray'));
$this->registerPlugin('modifier','compare', array($this, 'smartyCompare'));
$this->registerPlugin('modifier','concat', array($this, 'smartyConcat'));
$this->registerPlugin('modifier','strtotime', array($this, 'smartyStrtotime'));
$this->registerPlugin('modifier','explode', array($this, 'smartyExplode'));
$this->registerPlugin('modifier','assign', array($this, 'smartyAssign'));
$this->registerPlugin('modifier','escape', array(&$this, 'smartyEscape'));
$this->registerPlugin('function','csrf', array($this, 'smartyCSRF'));
$this->registerPlugin('function', 'translate', array($this, 'smartyTranslate'));
$this->registerPlugin('function','null_link_action', array($this, 'smartyNullLinkAction'));
$this->registerPlugin('function','help', array($this, 'smartyHelp'));
$this->registerPlugin('function','flush', array($this, 'smartyFlush'));
$this->registerPlugin('function','call_hook', array($this, 'smartyCallHook'));
$this->registerPlugin('function','html_options_translate', array($this, 'smartyHtmlOptionsTranslate'));
$this->registerPlugin('block','iterate', array($this, 'smartyIterate'));
$this->registerPlugin('function','page_links', array($this, 'smartyPageLinks'));
$this->registerPlugin('function','page_info', array($this, 'smartyPageInfo'));
$this->registerPlugin('function','pluck_files', array($this, 'smartyPluckFiles'));

// Modified vocabulary for creating forms
$fbv = $this->getFBV();
$this->register_block('fbvFormSection', array($fbv, 'smartyFBVFormSection'));
$this->register_block('fbvFormArea', array($fbv, 'smartyFBVFormArea'));
$this->register_function('fbvFormButtons', array($fbv, 'smartyFBVFormButtons'));
$this->register_function('fbvElement', array($fbv, 'smartyFBVElement'));
$this->registerPlugin('block', 'fbvFormSection', array($fbv, 'smartyFBVFormSection'));
$this->registerPlugin('block', 'fbvFormArea', array($fbv, 'smartyFBVFormArea'));
$this->registerPlugin('function', 'fbvFormButtons', array($fbv, 'smartyFBVFormButtons'));
$this->registerPlugin('function', 'fbvElement', array($fbv, 'smartyFBVElement'));
$this->assign('fbvStyles', $fbv->getStyles());

$this->register_function('fieldLabel', array($fbv, 'smartyFieldLabel'));
$this->registerPlugin('function', 'fieldLabel', array($fbv, 'smartyFieldLabel'));

// register the resource name "core"
$coreResource = new PKPTemplateResource($this->core_template_dir);
$this->register_resource('core', array(
$this->registerResource('core', array(
array($coreResource, 'fetch'),
array($coreResource, 'fetchTimestamp'),
array($coreResource, 'getSecure'),
array($coreResource, 'getTrusted')
));

$appResource = new PKPTemplateResource($this->app_template_dir);
$this->register_resource('app', array(
$this->registerResource('app', array(
array($appResource, 'fetch'),
array($appResource, 'fetchTimestamp'),
array($appResource, 'getSecure'),
array($appResource, 'getTrusted')
));

$this->register_function('url', array($this, 'smartyUrl'));
$this->registerPlugin('function', 'url', array($this, 'smartyUrl'));
// ajax load into a div or any element
$this->register_function('load_url_in_el', array($this, 'smartyLoadUrlInEl'));
$this->register_function('load_url_in_div', array($this, 'smartyLoadUrlInDiv'));
$this->registerPlugin('function', 'load_url_in_el', array($this, 'smartyLoadUrlInEl'));
$this->registerPlugin('function', 'load_url_in_div', array($this, 'smartyLoadUrlInDiv'));

// load stylesheets/scripts/headers from a given context
$this->register_function('load_stylesheet', array($this, 'smartyLoadStylesheet'));
$this->register_function('load_script', array($this, 'smartyLoadScript'));
$this->register_function('load_header', array($this, 'smartyLoadHeader'));
$this->registerPlugin('function', 'load_stylesheet', array($this, 'smartyLoadStylesheet'));
$this->registerPlugin('function', 'load_script', array($this, 'smartyLoadScript'));
$this->registerPlugin('function', 'load_header', array($this, 'smartyLoadHeader'));

// load NavigationMenu Areas from context
$this->register_function('load_menu', array($this, 'smartyLoadNavigationMenuArea'));
$this->registerPlugin('function', 'load_menu', array($this, 'smartyLoadNavigationMenuArea'));

/**
* Kludge to make sure no code that tries to connect to the
Expand Down Expand Up @@ -407,16 +416,6 @@ function initialize() {
));
}

/**
* Override the Smarty {include ...} function to allow hooks to be
* called.
*/
function _smarty_include($params) {
if (!HookRegistry::call('TemplateManager::include', array($this, &$params))) {
return parent::_smarty_include($params);
}
return false;
}

/**
* Flag the page as cacheable (or not).
Expand Down Expand Up @@ -1046,7 +1045,6 @@ function smartyHtmlOptionsTranslate($params, $smarty) {
$params['values'] = array_map(array('AppLocale', 'translate'), $params['values']);
}

require_once($this->_get_plugin_filepath('function','html_options'));
return smarty_function_html_options($params, $smarty);
}

Expand All @@ -1059,11 +1057,11 @@ function smartyHtmlOptionsTranslate($params, $smarty) {
* - key: (optional) Name of variable to receive index of current item
*/
function smartyIterate($params, $content, $smarty, &$repeat) {
$iterator =& $smarty->get_template_vars($params['from']);
$iterator = $smarty->getTemplateVars($params['from']);

if (isset($params['key'])) {
if (empty($content)) $smarty->assign($params['key'], 1);
else $smarty->assign($params['key'], $smarty->get_template_vars($params['key'])+1);
else $smarty->assign($params['key'], $smarty->getTemplateVars($params['key'])+1);
}

// If the iterator is empty, we're finished.
Expand Down Expand Up @@ -1097,7 +1095,7 @@ function smartyPageInfo($params, $smarty) {
if (isset($params['itemsPerPage'])) {
$itemsPerPage = $params['itemsPerPage'];
} else {
$itemsPerPage = $smarty->get_template_vars('itemsPerPage');
$itemsPerPage = $smarty->getTemplateVars('itemsPerPage');
if (!is_numeric($itemsPerPage)) $itemsPerPage=25;
}

Expand Down Expand Up @@ -1260,7 +1258,7 @@ function smartyPageLinks($params, $smarty) {
unset($params['iterator']);
unset($params['name']);

$numPageLinks = $smarty->get_template_vars('numPageLinks');
$numPageLinks = $smarty->getTemplateVars('numPageLinks');
if (!is_numeric($numPageLinks)) $numPageLinks=10;

$page = $iterator->getPage();
Expand Down Expand Up @@ -1626,9 +1624,9 @@ function getResourcesByContext($resources, $context) {
$matches = $resources[$context];
}

$page = $this->get_template_vars('requestedPage');
$page = $this->getTemplateVars('requestedPage');
$page = empty( $page ) ? 'index' : $page;
$op = $this->get_template_vars('requestedOp');
$op = $this->getTemplateVars('requestedOp');
$op = empty( $op ) ? 'index' : $op;

$contexts = array(
Expand Down

0 comments on commit 956b85b

Please sign in to comment.