Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
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"
}
}
121 changes: 108 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions interface/plugins/function.css_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ function smarty_function_css_link($params, $template)
$root = dirname($_SERVER['DOCUMENT_ROOT']);
$filename = FALSE;
if ( is_dir("$root/common") ) {
$filename = "$root/${base_filename}";
$filename = "$root/{$base_filename}";
} elseif ( is_dir("$root/../babel/common") ) {
$filename = "$root/../babel/${base_filename}";
$filename = "$root/../babel/{$base_filename}";
}
$modtime = ( $filename === FALSE ) ? time() : filemtime($filename);
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"${params['href']}?_=${modtime}\" />";
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$params['href']}?_={$modtime}\" />";
}
?>
6 changes: 3 additions & 3 deletions interface/plugins/function.js_link.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function smarty_function_js_link($params, $template)
$root = dirname($_SERVER['DOCUMENT_ROOT']);
$filename = FALSE;
if ( is_dir("$root/common") ) {
$filename = "$root/${base_filename}";
$filename = "$root/{$base_filename}";
} elseif ( is_dir("$root/../babel/common") ) {
$filename = "$root/../babel/${base_filename}";
$filename = "$root/../babel/{$base_filename}";
}
$modtime = ( $filename === FALSE ) ? time() : filemtime($filename);
return "<script type=\"text/javascript\" src=\"${params['href']}?_=${modtime}\"></script>";
return "<script type=\"text/javascript\" src=\"{$params['href']}?_={$modtime}\"></script>";

}
?>
6 changes: 3 additions & 3 deletions interface/themes/firebird/Search/advanced.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<hathi-alert-banner></hathi-alert-banner>
<main class="main-container" id="main">
<hathi-advanced-search-form
data-prop-language-data="{$languageList|@json_encode|escape}"
data-prop-format-data='{$formatList|@json_encode|escape}'
data-prop-location-data='{$locationsList|@json_encode|escape}'
data-prop-language-data="{$languageList|json_encode|escape}"
data-prop-format-data='{$formatList|json_encode|escape}'
data-prop-location-data='{$locationsList|json_encode|escape}'
></hathi-advanced-search-form>
</main>

Expand Down
9 changes: 3 additions & 6 deletions interface/themes/firebird/Search/list-list.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
{/if}

<article class="record d-flex gap-3 p-3 mb-3 mt-3 shadow-sm">
{* {$ld.handle|@var_dump}
{$record.title|@var_dump} *}
<div class="cover d-none d-md-block" data-hdl="{$ld.handle}">
{if $ld.handle}
<img loading="lazy" class="bookCover border p-1 flex-grow-0 flex-shrink-0" aria-hidden="true" alt="" src="{$unicorn_root}/cgi/imgsrv/cover?id={$ld.handle};width=250" />
Expand Down Expand Up @@ -68,8 +66,7 @@
</dl>
</div>
{assign var="dfields" value=$ru->displayable_ht_fields($record.marc)}
{* {$dfields|@var_dump} *}
{if false && $dfields|@count gt 1}
{if false && $dfields|count gt 1}
<p class="fs-7 text-secondary mb-1">
Use the Catalog Record to view multiple volumes
</p>
Expand All @@ -78,7 +75,7 @@
<div class="resource-access-container">
<div class="list-group list-group-horizontal-sm align-items-center">
<a href="{$ss->asRecordURL($record.id)}" class="list-group-item list-group-item-action w-sm-50" aria-describedby="maintitle-{$i}"><i class="fa-solid fa-circle-info" aria-hidden="true"></i></i>Catalog Record<i aria-hidden="true" class="visited-link fa-solid fa-check-double"></i></a>
{if $dfields|@count eq 1 && isset($ld) && is_array($ld)}
{if $dfields|count eq 1 && isset($ld) && is_array($ld)}
{if ( $ld.is_resource_sharing ) }
<a data-activated-role="true" href="{$handle_prefix}{$ld.handle}" referrerpolicy="unsafe-url" class="list-group-item list-group-item-action list-group-item w-sm-50" aria-describedby="maintitle-{$i}"><i aria-hidden="true" class="fa-solid fa-lock-open"></i>Registered Access<i aria-hidden="true" class="visited-link fa-solid fa-check-double"></i></a>
{elseif ( $ld.role_name !== 'resourceSharing' && ! $ld.is_fullview && ( $ld.has_activated_role ) ) }
Expand All @@ -90,7 +87,7 @@
{else}
<a href="{$handle_prefix}{$ld.handle}" referrerpolicy="unsafe-url" class="list-group-item list-group-item-action list-group-item w-sm-50" aria-describedby="maintitle-{$i}"><i aria-hidden="true" class="fa-solid fa-lock"></i>Limited (search only)<i aria-hidden="true" class="visited-link fa-solid fa-check-double"></i></a>
{/if}
{elseif $dfields|@count gt 1}
{elseif $dfields|count gt 1}
<a href="{$ss->asRecordURL($record.id)}#viewability" class="list-group-item list-group-item-action w-sm-50" aria-describedby="maintitle-{$i}"><i class="fa-solid fa-layer-group" aria-hidden="true"></i></i>Multiple Items<i aria-hidden="true" class="visited-link fa-solid fa-check-double"></i></a>
{/if}
</div>
Expand Down
4 changes: 2 additions & 2 deletions interface/themes/firebird/Search/list.sidebar.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
{/foreach}
</div>
<div class="mt-3">
{if $counts.$cluster|@count gt 6}
{if $counts.$cluster|count gt 6}
<button type="button" class="btn btn-sm btn-outline-dark" data-action="expand-filter" aria-expanded="false">
Show
<span class="not-expanded">all {$counts.$cluster|@count} </span>
<span class="not-expanded">all {$counts.$cluster|count} </span>
<span class="is-expanded">fewer </span>
{$facetConfig.$cluster} Filters
</button>
Expand Down
2 changes: 1 addition & 1 deletion static/api/templates/volumes/oclchtml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>{$doc.titles[0]} (OCLC {', '|implode:$doc.oclcs })</title>
<title>{$doc.titles[0]} (OCLC {$doc.oclcs|join:', '})</title>
Copy link
Member

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.

</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion static/api/volumes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# require_once 'Apache/Solr/Service.php';
require_once 'vendor/autoload.php';
use Smarty\Smarty;
require_once 'sys/SolrConnection.php';
require_once 'services/Record/RecordUtils.php';
require_once 'sys/Normalize.php';
Expand Down Expand Up @@ -629,4 +630,3 @@ function lccnnormalize($val) {




58 changes: 53 additions & 5 deletions sys/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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']);
Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down
Loading