From 0cfe771a18b56e440de44963fefbaa82a0910038 Mon Sep 17 00:00:00 2001 From: Frank Morgner <morgnerf@ub.uni-leipzig.de> Date: Tue, 14 Jun 2016 12:30:59 +0200 Subject: [PATCH] refs #5395: * implemented resolver logic to process URIs linked from records * implemented specific resolver logic for EBL URLs * removed resolver logic introduced with refs #6554 * configured resolver for URNs --- local/config/vufind/config.ini | 36 +++- local/config/vufind/permissions.ini | 6 + local/dev/config/vufind/config.ini.sample | 22 +++ module/finc/config/module.config.php | 10 +- module/finc/src/finc/Controller/EblTrait.php | 66 +++++++ .../src/finc/Controller/RecordController.php | 12 ++ .../finc/RecordDriver/SolrMarcFincTrait.php | 22 --- module/finc/src/finc/Rewrite/EblRewrite.php | 186 ++++++++++++++++++ module/finc/src/finc/Rewrite/Factory.php | 65 ++++++ .../finc/src/finc/Rewrite/PluginFactory.php | 50 +++++ .../src/finc/View/Helper/Root/Factory.php | 5 +- .../finc/src/finc/View/Helper/Root/Record.php | 144 +++++++++++++- .../finc/templates/RecordTab/serviceebl.phtml | 12 ++ 13 files changed, 602 insertions(+), 34 deletions(-) create mode 100644 module/finc/src/finc/Controller/EblTrait.php create mode 100644 module/finc/src/finc/Rewrite/EblRewrite.php create mode 100644 module/finc/src/finc/Rewrite/Factory.php create mode 100644 module/finc/src/finc/Rewrite/PluginFactory.php create mode 100644 themes/finc/templates/RecordTab/serviceebl.phtml diff --git a/local/config/vufind/config.ini b/local/config/vufind/config.ini index d497c9ec102..2f47460da98 100644 --- a/local/config/vufind/config.ini +++ b/local/config/vufind/config.ini @@ -1518,11 +1518,37 @@ localMarcFieldOfLibraryMapping[] = "bas:985" ; Email subject ;subject_acquisition = "Ihr Auftrag: %s, %s" -; This section allows to set resolver for certain content types for Marc field 856 -; set in subfield $2 (refs #6554 and http://www.loc.gov/marc/bibliographic/bd856.html) -[Additional_Resolver] -urn = "http://nbn-resolving.de/%s" -doi = "https://dx.doi.org/%s" +; Section to configure Ebook Central service - EBL Choice service provided by +; ProQuest http://www.proquest.com +; Please note: Service if only available with configuration of [LinksRewrite] +; section. Use equal defined pattern below for ebl[pattern] and ebl[method] = +; resolveEblLink to call specific link resolver of EBL with authentication and +; persmision logic. +;[Ebl] +;pattern = "namespace of uri" +;secret_key = "secret key provided by supplier" + +; Section of rewriting of urls of marc field $856 using regular expression or +; through injection of self-declared method. Rewrite options here are not really +; fit to resolve by bare linkresolver logic or openurl processing. +[LinksRewrite] +; Start to declare a own group which can have following keys. +; identifier[pattern] is necessary to switch on rewrite und sort out the right links. +; regular expression are allowed +; identifier[search] is the string to replaced +; identifier[replace] is the replacing phrase +; identifier[method] calls an alternative method with the link as parameter. +; The method is expected in View\Helper\Root\Record.php +; Examples: +; ebl[pattern] = leip.eblib.com +; ebl[method] = resolveEblLink +; naxos[pattern] = www.ln.naxosmusiclibrary.com +; naxos[search] = www.ln.naxosmusiclibrary.com +; naxos[replace] = ubl-leipzig.naxosmusiclibrary.com +nbn[pattern] = "^urn:nbn:" +nbn[search] = "urn:nbn:" +nbn[replace] = "http://nbn-resolving.de/urn:nbn:" + ; ***************** ; * EOF finc ; ***************** diff --git a/local/config/vufind/permissions.ini b/local/config/vufind/permissions.ini index 0f5db3cc277..d4089b21ef3 100644 --- a/local/config/vufind/permissions.ini +++ b/local/config/vufind/permissions.ini @@ -67,6 +67,12 @@ ; access.StaffViewTab - Controls access to the staff view tab in record mode ; access.SummonExtendedResults - Controls visibility of protected Summon results +; Configuration for permitting EBL/Schweitzer link resolving +;[default.EBL] +;role = loggedin +;catUserType = UBL:eblAccessGranted +;permission = access.EblLink + ; Configuration for permitting PDA form action ;[default.PDA] ;role = loggedin diff --git a/local/dev/config/vufind/config.ini.sample b/local/dev/config/vufind/config.ini.sample index 5e81cf6b0a9..6e3f2e1b87a 100644 --- a/local/dev/config/vufind/config.ini.sample +++ b/local/dev/config/vufind/config.ini.sample @@ -62,3 +62,25 @@ replace_other_urls = true [Content] coversize[result-list] = false showStyleBasedIcons = true + +[Ebl] +pattern = "leip.eblib.com" +secret_key = "SecretKey" + +[LinksRewrite] +; Personalized rewriting of Open Urls. +; Start to declare a own group which can have following keys. +; identifier[pattern] is necessary to switch on rewrite und sort out the right links. +; regular expression are allowed +; identifier[search] is the string to replaced +; identifier[replace] is the replacing phrase +; identifier[method] calls an alternative method with the link as parameter. +; The method has to be written in the IndexDriver.php +schweitzer[pattern] = leip.eblib.com +schweitzer[method] = resolveEblLink +; naxos[pattern] = www.ln.naxosmusiclibrary.com +; naxos[search] = www.ln.naxosmusiclibrary.com +; naxos[replace] = ubl-leipzig.naxosmusiclibrary.com +; nbn[pattern] = "^urn:nbn:" +; nbn[search] = urn:nbn: +; nbn[replace] = nbn-resolving.de/urn:nbn: diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 7942efa7990..347d56772e4 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -9,7 +9,8 @@ $config = [ 'VuFind\BranchesReader' => 'finc\Service\Factory::getBranchesReader', 'VuFind\ILSConnection' => 'finc\Service\Factory::getILSConnection', 'VuFind\ILSHoldLogic' => 'finc\Service\Factory::getILSHoldLogic', - ], + 'finc\Rewrite' => 'finc\Rewrite\Factory' + ] ], 'controllers' => [ 'factories' => [ @@ -43,13 +44,13 @@ $config = [ 'solrmarcfincpda' => 'finc\RecordDriver\Factory::getSolrMarcFincPDA', 'solrmarcremote' => 'finc\RecordDriver\Factory::getSolrMarcRemote', 'solrmarcremotefinc' => 'finc\RecordDriver\Factory::getSolrMarcRemoteFinc', - 'solrai' => 'finc\RecordDriver\Factory::getSolrAI', + 'solrai' => 'finc\RecordDriver\Factory::getSolrAI' ], ], 'recordtab' => [ 'invokables' => [ 'staffviewai' => 'finc\RecordTab\StaffViewAI', - 'acquisitionpda' => 'finc\RecordTab\AcquisitionPDA', + 'acquisitionpda' => 'finc\RecordTab\AcquisitionPDA' ], ], 'resolver_driver' => [ @@ -136,7 +137,8 @@ $recordRoutes = [ // Define static routes -- Controller/Action strings $staticRoutes = [ - 'MyResearch/Acquisition', 'dds/Home', 'dds/Email' + 'MyResearch/Acquisition', 'dds/Home', 'dds/Email', + 'Record/EblLink' ]; $routeGenerator = new \VuFind\Route\RouteGenerator($nonTabRecordActions); diff --git a/module/finc/src/finc/Controller/EblTrait.php b/module/finc/src/finc/Controller/EblTrait.php new file mode 100644 index 00000000000..c150515e29c --- /dev/null +++ b/module/finc/src/finc/Controller/EblTrait.php @@ -0,0 +1,66 @@ +<?php +/** + * Ebl Trait + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * Copyright (C) Leipzig University Library 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category Vufind + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace finc\Controller; + +/** + * Ebl Trait + * + * @category VuFind + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ + +trait EblTrait +{ + + /** + * Link action to manage rewrite with authorization and permission treatment. + * Redirect directly to external EBL service after successful login. + * + * @return mixed + * @access public + */ + public function eblLinkAction() + { + $link = $tag = $this->params()->fromQuery('link'); + //$id = $tag = $this->params()->fromQuery('id'); + + // Force login: + if (!($user = $this->getUser())) { + return $this->forceLogin(); + } + $rewrite = $this->getRewrite(); + $link = $rewrite->resolveLink($link, $user); + return $this->redirect()->toUrl($link); + } +} \ No newline at end of file diff --git a/module/finc/src/finc/Controller/RecordController.php b/module/finc/src/finc/Controller/RecordController.php index dc3d491669b..d4c74b9047c 100644 --- a/module/finc/src/finc/Controller/RecordController.php +++ b/module/finc/src/finc/Controller/RecordController.php @@ -42,6 +42,7 @@ use VuFind\Exception\Mail as MailException; */ class RecordController extends \VuFind\Controller\RecordController { + use EblTrait; use PdaTrait; use EmailHoldTrait; @@ -73,4 +74,15 @@ class RecordController extends \VuFind\Controller\RecordController throw new MailException('Missing email profile: ' + $profile); } } + + /** + * Returns rewrite object + * + * @return object + */ + protected function getRewrite() + { + return $this->getServiceLocator()->get('finc\Rewrite'); + } + } diff --git a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php index 3541bb96c14..9c7ed391ba8 100644 --- a/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php +++ b/module/finc/src/finc/RecordDriver/SolrMarcFincTrait.php @@ -148,28 +148,6 @@ trait SolrMarcFincTrait $desc = $address; } - // this only applies to field 856 (rf. #6554) - // first check if $address is not a valid URL, then check - // do we have the indicator 7 and the subfield $2 exist - // which indicates the access method? - if ($field == '856' - && !filter_var($address, FILTER_VALIDATE_URL) - && $url->getIndicator('1') == '7' - && $url->getSubfield('2') - ) { - // handle the value of $address according to content - // of subfield $2 - if (isset($this->mainConfig->Additional_Resolver - ->{$url->getSubfield('2')->getData()}) - ) { - // reformat $address according to config setting - $address = sprintf( - $this->mainConfig->Additional_Resolver - ->{$url->getSubfield('2')->getData()}, - $address); - } - } - // If url doesn't exist as key so far write to return variable. if (!in_array(['url' => $address, 'desc' => $desc], $retVal)) { $retVal[] = ['url' => $address, 'desc' => $desc]; diff --git a/module/finc/src/finc/Rewrite/EblRewrite.php b/module/finc/src/finc/Rewrite/EblRewrite.php new file mode 100644 index 00000000000..26a5ecaf73f --- /dev/null +++ b/module/finc/src/finc/Rewrite/EblRewrite.php @@ -0,0 +1,186 @@ +<?php +/** + * Ebl/ Schweitzer Rewrite service for VuFind. + * + * PHP version 5.3 + * + * Copyright (C) Leipzig University Library 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Rewrite + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +namespace finc\Rewrite; + +use ZfcRbac\Service\AuthorizationServiceAwareTrait/*,*/ + /*ZfcRbac\Service\AuthorizationServiceAwareInterface*/ + ; + +/** + * Ebl/ Schweitzer Rewrite service for VuFind. + * + * @category VuFind2 + * @package Rewrite + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://www.vufind.org Main Page + */ +class EblRewrite /*implements AuthorizationServiceAwareInterface*/ +{ + use AuthorizationServiceAwareTrait; + + /** + * Config object + * + * @var object $config + * @access private + */ + private $config; + + /** + * Timestamp + * + * @var null/int $time + * @access private + */ + private $time = null; + + /** + * User identifier as hashed value + * + * @var null/string $user_id + * @access private + */ + private $userid = null; + + /** + * Constructor + * + * @param $config + * @access public + * + */ + public function __construct($config) + { + $this->config = $config; + } + + /** + * Resolve link for EBL + * + * @param string $link Link as url. + * @param object $user User object + * + * @return string $link Link as url. + * @access public + * @throws Exception No user object exists + */ + public function resolveLink($link, $user) + { + $this->accessPermission = 'access.EblLink'; + + if (!isset($user->username) && strlen($user->username) > 0) { + throw new Exception('No user object exists'); + } + $auth = $this->getAuthorizationService(); + if (!$auth) { + throw new Exception('Authorization service missing'); + } + + // Logged in user with no permission get resolver link for view of already + // purchased e-books by institution + // @link https://intern.finc.info/issues/1813#note-8 + $statusUser = ''; // Default value 'intern' equal to keep value blank + if (!$auth->isGranted($this->accessPermission)) { + $params['patrontype'] = 'extern'; + $statusUser = 'extern'; + } + $params['userid'] = $this->getHashedUser($user->username); + $params['tstamp'] = $this->getTimeStamp(); + $params['id'] = $this->getEblIdentifier( + $params['userid'], + $params['tstamp'], + $statusUser + ); + $query = http_build_query($params); + return $link . '&' . $query; + } + + /** + * Get EBL identifier + * + * @param string $userid Hashed user identifier + * @param int $timestamp Current timestamp of interaction + * @param string $statususer Status of user internally|externally + * + * @return string + * @access private + * @throws Exception There is no secret key defined in configuration + */ + private function getEblIdentifier($userid, $timestamp, $statususer) + { + return sha1($userid . $timestamp . $this->getSecretKey() . $statususer); + } + + /** + * Get hashed user + * + * @param string $userid User identifier + * + * @return string + * @access private + * @throws Exception There is no secret key defined in configuration + */ + private function getHashedUser($userid) + { + return ($this->userid == null) + ? hash('sha384', $userid) : $this->userid; + } + + /** + * Get secret key of provider Schweitzer + * + * @return string + * @access private + * @throws Exception There is no secret key defined in configuration + */ + private function getSecretKey() + { + if (isset($this->config->Ebl->secret_key) + && strlen($this->config->Ebl->secret_key) > 0 + ) { + return $this->config->Ebl->secret_key; + } + throw new Exception('There is no secret key defined in configuration.'); + } + + /** + * Get one timestamp per processing + * + * @return int|null + * @access private + */ + private function getTimeStamp() + { + return ($this->time == null) ? time() : $this->time; + } + + +} \ No newline at end of file diff --git a/module/finc/src/finc/Rewrite/Factory.php b/module/finc/src/finc/Rewrite/Factory.php new file mode 100644 index 00000000000..6d982117e9e --- /dev/null +++ b/module/finc/src/finc/Rewrite/Factory.php @@ -0,0 +1,65 @@ +<?php +/** + * Factory for instantiating Rewrite objects + * + * PHP version 5.3 + * + * Copyright (C) Leipzig University Library 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package Rewrite + * @author Demian Katz <demian.katz@villanova.edu> + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + */ +namespace finc\Rewrite; + +use Zend\ServiceManager\ServiceLocatorInterface; + +/** + * Factory for instantiating Rewrite objects + * + * @category VuFind + * @package Rewrite + * @author Demian Katz <demian.katz@villanova.edu> + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development Wiki + * + * @codeCoverageIgnore + */ +class Factory implements \Zend\ServiceManager\FactoryInterface +{ + /** + * Create service + * + * @param ServiceLocatorInterface $sm Service manager + * + * @return mixed + */ + public function createService(ServiceLocatorInterface $sm) + { + // Load configurations: + $config = $sm->get('VuFind\Config')->get('config'); + $eblHandler = new EblRewrite($config); + $eblHandler->setAuthorizationService( + $sm->get('ZfcRbac\Service\AuthorizationService') + ); + return $eblHandler; + } + +} diff --git a/module/finc/src/finc/Rewrite/PluginFactory.php b/module/finc/src/finc/Rewrite/PluginFactory.php new file mode 100644 index 00000000000..67068ca5fb0 --- /dev/null +++ b/module/finc/src/finc/Rewrite/PluginFactory.php @@ -0,0 +1,50 @@ +<?php +/** + * Rewrite plugin factory + * + * PHP version 5 + * + * Copyright (C) Leipzig University Library 2016. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind + * @package Rewrite + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:related_records_modules Wiki + */ +namespace finc\Rewrite; + +/** + * Rewrite plugin factory + * + * @category VuFind + * @package Rewrite + * @author Frank Morgner <morgnerf@ub.uni-leipzig.de> + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:plugins:related_records_modules Wiki + */ +class PluginFactory extends \VuFind\ServiceManager\AbstractPluginFactory +{ + /** + * Constructor + */ + public function __construct() + { + $this->defaultNamespace = 'finc\Rewrite'; + } +} \ No newline at end of file diff --git a/module/finc/src/finc/View/Helper/Root/Factory.php b/module/finc/src/finc/View/Helper/Root/Factory.php index 876ea8a60dd..92a619d3705 100644 --- a/module/finc/src/finc/View/Helper/Root/Factory.php +++ b/module/finc/src/finc/View/Helper/Root/Factory.php @@ -51,7 +51,10 @@ class Factory public static function getRecord(ServiceManager $sm) { return new Record( - $sm->getServiceLocator()->get('VuFind\Config')->get('config') + $sm->getServiceLocator()->get('VuFind\Config')->get('config'), + $sm->get('url'), + $sm->getServiceLocator()->get('VuFind\AuthManager'), + $sm->getServiceLocator()->get('finc\Rewrite') ); } diff --git a/module/finc/src/finc/View/Helper/Root/Record.php b/module/finc/src/finc/View/Helper/Root/Record.php index 6ba42e60547..9b351576a34 100644 --- a/module/finc/src/finc/View/Helper/Root/Record.php +++ b/module/finc/src/finc/View/Helper/Root/Record.php @@ -26,7 +26,7 @@ * @link https://vufind.org/wiki/development Wiki */ namespace finc\View\Helper\Root; -use Zend\View\Exception\RuntimeException, Zend\View\Helper\AbstractHelper; +use Zend\View\Helper\Url, finc\Rewrite; /** * Record driver view helper @@ -46,14 +46,42 @@ class Record extends \VuFind\View\Helper\Root\Record */ protected $config; + /** + * Authentication manager + * + * @var \VuFind\Auth\Manager + */ + protected $manager; + + /** + * URL helper + * + * @var Url + */ + protected $url; + + /** + * Rewriter + * + * @var \finc\Rewrite + */ + protected $rewrite; + /** * Constructor * * @param \Zend\Config\Config $config VuFind configuration + * @param \Zend\View\Helper\Url $helper URL helper */ - public function __construct($config = null) + public function __construct($config = null, + Url $helper, + \VuFind\Auth\Manager $manager, + $rewrite) { parent::__construct($config); + $this->url = $helper; + $this->manager = $manager; + $this->rewrite = $rewrite; } /** @@ -128,6 +156,20 @@ class Record extends \VuFind\View\Helper\Root\Record return $link; } + /** + * Get all the links associated with this record. Returns an array of + * associative arrays each containing 'desc' and 'url' keys. + * + * @param bool $openUrlActive Is there an active OpenURL on the page? + * + * @return array + */ + public function getLinkDetails($openUrlActive = false) + { + $links = parent::getLinkDetails($openUrlActive); + return $this->rewriteLinks($links); + } + /** * Remove author dates from author string (used for using author names as search * term). @@ -150,4 +192,102 @@ class Record extends \VuFind\View\Helper\Root\Record } return $author; } + + /** + * Rewrite links if defined + * + * @param array $links List with links schema [url] and [desc] for description. + * + * @access protected + * @return array $links Return processed links. + */ + protected function rewriteLinks($links = []) + { + // if configuration empty return unprocessed + if (!isset($this->config->LinksRewrite) + || count($this->config->LinksRewrite) == 0 + ) { + return $links; + } + + // if links list empty return unprocessed + if (count($links) == 0) { + return $links; + } + + foreach ($links as &$link) { + $link['url'] = $this->rewriteLink($link['url']); + } + + return $links; + } + + /** + * Rewrite link + * + * @param string $link Link to rewrite + * + * @access protected + * @return string $link Return processed link. + */ + protected function rewriteLink($link) + { + $rewrite = $this->config->LinksRewrite->toArray(); + foreach ($rewrite as $r) { + // is pattern set so try rewrite url + if (isset($r['pattern'])) { + + // is search and replace set so try to rewrite url + if (isset($r['search']) && isset($r['replace'])) { + // check if pattern exists. if at least one match than continue + if (0 != preg_match('/' . $r['pattern'] . '/i', trim($link))) { + // prepare search pattern + // should be free of conflicting meta characters + $pattern = str_replace(array('.'), array('\.'), $r['search']); + $pattern = '/(' . $pattern . ')/i'; + // replace it only one time + $link = preg_replace($pattern, trim($r['replace']), trim($link), 1, $count); + // add http if needed + // @todo make it https compatible + if (!preg_match('/^(http:\/\/)/', $link)) { + $link = 'http://' . $link; + } + } + } + // is method set so call alternatively method proceed link + if (isset($r['method']) && method_exists($this, $r['method'])) { + /* && $count > 0) { @todo fix */ + if (0 != preg_match('/' . $r['pattern'] . '/i', trim($link))) { + $link = $this->$r['method']($link); + } + } // end if isset method + + } // end if isset pattern + + } // end foreach + return $link; + } + + /** + * Resolve Rewrite/Schweitzer Url + * + * @param string $link Link to rewrite + * + * @access protected + * @return string $link Return processed link. + */ + protected function resolveEblLink($link) + { + if (false === ($user = $this->manager->isLoggedIn())) { + $id = $this->driver->getUniqueId(); + return $this->url->__invoke( + 'record-ebllink', [], ['query' => ['link' => $link, 'id' => $id]] + ); + } + $url = $this->rewrite->resolveLink($link, $user); + return $url; + } + + + } \ No newline at end of file diff --git a/themes/finc/templates/RecordTab/serviceebl.phtml b/themes/finc/templates/RecordTab/serviceebl.phtml new file mode 100644 index 00000000000..90d0ffed4d1 --- /dev/null +++ b/themes/finc/templates/RecordTab/serviceebl.phtml @@ -0,0 +1,12 @@ +<? +// Set page title. +$this->headTitle($this->translate('EBL') . ': ' . $this->driver->getBreadcrumb()); + +// Get EBL url +$link = $this->tab->getLinkEBL(); + +?> + <h4>EBL</h4> +<? foreach ($link as $href): ?> + <a href="<?= $href['url'] ?>"><?= $href['desc'] ?></a> +<? endforeach; ?> \ No newline at end of file -- GitLab