diff --git a/info.xml b/info.xml index 4b243dd..0b4e38e 100644 --- a/info.xml +++ b/info.xml @@ -34,7 +34,7 @@ menu-xml@1.0.0 - smarty-v2@1.0.1 + smarty-v2@1.0.3 CRM_Outlook365_Upgrader diff --git a/mixin/smarty-v2@1.0.1.mixin.php b/mixin/smarty-v2@1.0.1.mixin.php deleted file mode 100644 index 5972dbd..0000000 --- a/mixin/smarty-v2@1.0.1.mixin.php +++ /dev/null @@ -1,51 +0,0 @@ -getPath('templates'); - if (!file_exists($dir)) { - return; - } - - $register = function() use ($dir) { - // This implementation has a theoretical edge-case bug on older versions of CiviCRM where a template could - // be registered more than once. - CRM_Core_Smarty::singleton()->addTemplateDir($dir); - }; - - // Let's figure out what environment we're in -- so that we know the best way to call $register(). - - if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) { - // Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`. - if ($mixInfo->isActive()) { - $register(); - } - return; - } - - if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { - // New Install, Standard Loader: The extension has just been enabled, and we're now setting it up. - // System has already booted. New templates may be needed for upcoming installation steps. - $register(); - return; - } - - // Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online. - \Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($mixInfo, $register) { - if ($mixInfo->isActive()) { - $register(); - } - }); - -}; diff --git a/mixin/smarty-v2@1.0.3.mixin.php b/mixin/smarty-v2@1.0.3.mixin.php new file mode 100644 index 0000000..f8718c8 --- /dev/null +++ b/mixin/smarty-v2@1.0.3.mixin.php @@ -0,0 +1,78 @@ +getPath('templates'); + if (!file_exists($dir)) { + return; + } + + $register = function($newDirs) { + $smarty = CRM_Core_Smarty::singleton(); + $v2 = isset($smarty->_version) && version_compare($smarty->_version, 3, '<'); + $templateDirs = (array) ($v2 ? $smarty->template_dir : $smarty->getTemplateDir()); + $templateDirs = array_merge($newDirs, $templateDirs); + $templateDirs = array_unique(array_map(function($v) { + $v = str_replace(DIRECTORY_SEPARATOR, '/', $v); + $v = rtrim($v, '/') . '/'; + return $v; + }, $templateDirs)); + if ($v2) { + $smarty->template_dir = $templateDirs; + } + else { + $smarty->setTemplateDir($templateDirs); + } + }; + + // Let's figure out what environment we're in -- so that we know the best way to call $register(). + + if (!empty($GLOBALS['_CIVIX_MIXIN_POLYFILL'])) { + // Polyfill Loader (v<=5.45): We're already in the middle of firing `hook_config`. + if ($mixInfo->isActive()) { + $register([$dir]); + } + return; + } + + if (CRM_Extension_System::singleton()->getManager()->extensionIsBeingInstalledOrEnabled($mixInfo->longName)) { + // New Install, Standard Loader: The extension has just been enabled, and we're now setting it up. + // System has already booted. New templates may be needed for upcoming installation steps. + $register([$dir]); + return; + } + + // Typical Pageview, Standard Loader: Defer the actual registration for a moment -- to ensure that Smarty is online. + // We need to bundle-up all dirs -- Smarty 3/4/5 is inefficient with processing repeated calls to `getTemplateDir()`+`setTemplateDir()` + if (!isset(Civi::$statics[__FILE__]['event'])) { + Civi::$statics[__FILE__]['event'] = 'civi.smarty-v2.addPaths.' . md5(__FILE__); + Civi::dispatcher()->addListener('hook_civicrm_config', function() use ($register) { + $dirs = []; + $event = \Civi\Core\Event\GenericHookEvent::create(['dirs' => &$dirs]); + Civi::dispatcher()->dispatch(Civi::$statics[__FILE__]['event'], $event); + $register($dirs); + }); + } + + Civi::dispatcher()->addListener(Civi::$statics[__FILE__]['event'], function($event) use ($mixInfo, $dir) { + if ($mixInfo->isActive()) { + array_unshift($event->dirs, $dir); + } + }); + +};