-
Notifications
You must be signed in to change notification settings - Fork 0
Ett 1328 smarty4to5 migration #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,13 @@ | ||
| { | ||
| "name": "hathitrust/catalog", | ||
| "description": "HathiTrust Catalog application", | ||
| "require": { | ||
| "geoip2/geoip2": "2.13.*", | ||
| "pear/pear-core-minimal": "1.10.*", | ||
| "pear/file_marc": "1.4.*", | ||
| "pear/http_request2": "2.7.*", | ||
| "pear/pager": "2.5.*", | ||
| "phpunit/phpunit": "9.6.*", | ||
| "smarty/smarty": "4.5.5" | ||
| "smarty/smarty": "^5.0" | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,9 @@ | |
| * | ||
| */ | ||
|
|
||
| # Smarty 4.5.5 uses classmap autoload with bare Smarty class | ||
| require_once 'vendor/autoload.php'; | ||
|
|
||
| # use Smarty\Smarty; | ||
| use Smarty\Smarty; | ||
|
|
||
| # Smarty Extension class | ||
| class UInterface extends Smarty | ||
|
|
@@ -33,6 +32,7 @@ function __construct() | |
| $local = $configArray['Site']['local']; | ||
| $theme = $configArray['Site']['theme']; | ||
|
|
||
| # set a single directory where the config file are stored. | ||
| $this->setTemplateDir("$local/interface/themes/$theme"); | ||
|
|
||
| # Set up the space for compiled files | ||
|
|
@@ -44,21 +44,34 @@ function __construct() | |
| chmod($comp, 0777); | ||
| } | ||
|
|
||
| // set another path to store compiled templates | ||
| $this->setCompileDir($comp); | ||
|
|
||
| // set another path to store caches of templates to speed up the loading of templates | ||
| $this->setCacheDir("$local/interface/cache"); | ||
| # Add custom plugin directory | ||
| $this->addPluginsDir("$local/interface/plugins"); | ||
| # Register legacy plugin files from the custom directory | ||
| $this->registerLegacyPlugins("$local/interface/plugins"); | ||
| $this->setCaching(Smarty::CACHING_OFF); | ||
| $this->setDebugging(false); | ||
| $this->setCompileCheck(Smarty::COMPILECHECK_ON); | ||
|
|
||
|
|
||
| unset($local); | ||
|
|
||
| // Register custom functions (Smarty 3 method) | ||
| // Register custom functions | ||
| // These are used in the templates as {translate text="Back to Record"} to output the translated text | ||
| // registerPlugin documentation: https://www.smarty.net/docs/en/api.register.plugin.tpl | ||
| $this->registerPlugin('function', 'translate', 'translate'); | ||
| $this->registerPlugin('function', 'char', 'char'); | ||
|
|
||
| // Register PHP functions that used to be invoked via Smarty's @modifier syntax. | ||
| // These are used in the templates as {$var|json_encode="value"} to output the JSON-encoded value of $var, | ||
| // or {$array|count} to output the count of items in $array. | ||
| // modifier are used to transform the output of a variable, so they are registered as 'modifier' plugins. | ||
| $this->registerPlugin('modifier', 'json_encode', 'json_encode'); | ||
| $this->registerPlugin('modifier', 'count', 'count'); | ||
|
|
||
|
|
||
| $this->assign('site', $configArray['Site']); | ||
| $this->assign('path', $configArray['Site']['path']); | ||
| $this->assign('url', $configArray['Site']['url']); | ||
|
|
@@ -105,6 +118,41 @@ function setPageTitle($title) | |
| { | ||
| $this->assign('pageTitle', $title); | ||
| } | ||
|
|
||
| /** | ||
| * Registers legacy plugins from a specified directory. | ||
| * | ||
| * This method looks for PHP files in the given directory that match the naming convention | ||
| * for Smarty plugins (function.{name}.php or modifier.{name}.php). It then includes these files | ||
| * and registers the corresponding functions as Smarty plugins. | ||
| * | ||
| * Smarty 5 requires to register each plugin or load an extension instead of pointing it at a directory. | ||
| * | ||
| * | ||
| * @param string $directory The directory to search for legacy plugin files. | ||
| */ | ||
|
|
||
| private function registerLegacyPlugins(string $directory): void | ||
| { | ||
| if (!is_dir($directory)) { | ||
| return; | ||
| } | ||
|
|
||
| foreach (glob(rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*.php') as $file) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth specifically enumerating what we're actually using rather than using the glob here, especially as it's not terribly likely to change in the future |
||
| require_once $file; | ||
| $basename = basename($file); | ||
| if (!preg_match('/^(function|modifier)\\.([^\\.]+)\\.php$/', $basename, $matches)) { | ||
| continue; | ||
| } | ||
| $type = $matches[1]; | ||
| $name = $matches[2]; | ||
| $callback = 'smarty_' . $type . '_' . $name; | ||
| if (!function_exists($callback)) { | ||
| continue; | ||
| } | ||
| $this->registerPlugin($type, $name, $callback); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function translate($params) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line gives a complaint about empty array if nothing matches (i.e. $doc.titles is empty). Not a new issue but probably worth fixing.