keys types to convert to single types # Extensions types define('EXTENSION_TYPE_PLUGIN', 1); define('EXTENSION_TYPE_THEME', 2); define('EXTENSION_TYPE_MODULE', 3); /** * Get the available container instance. * @param string|null $abstract * @param array $parameters * @return mixed|\Application */ function bff($abstract = null, array $parameters = []) { if (is_null($abstract)) { return bff::i(); } return bff::i()->make($abstract, $parameters); } /** * File customization * @param string $filePath full file path * @param bool $customAllow allow customized file version: /custom/file * @return string customized file path */ function modification(string $filePath, bool $customAllow = true): string { # Custom static $customDir; if (!isset($customDir)) { $customDir = PATH_BASE . 'custom' . DIRECTORY_SEPARATOR; if (!is_dir($customDir)) { $customDir = false; } } if ($customAllow && $customDir !== false) { # Custom $file = $customDir . substr($filePath, strlen(PATH_BASE)); if (is_file($file)) { $filePath = $file; } elseif (mb_stripos($filePath, $customDir) === 0) { # Original $filePath = PATH_BASE . substr($filePath, strlen($customDir)); } } return $filePath; } /** * Localize message * @param string $context message context * @param string $message message text * @param array|string|bool $params message parameters, language key (string), true - all languages, false - no translate return params as array * @param string|bool|null $language language key, null - current language, true - all languages, false - no translate return params as array * @param array $opts additional settings * @return string * @example _t('context', 'Date: [date]', array('date'=>date('Y.m.d'))); => Date 2001.01.01 */ function _t(string $context, string $message, $params = [], $language = null, array $opts = []) { return bff('locale')->translate($context, $message, $params, $language, $opts); } /** * Localize admin message * @param string $context message context * @param string $message message text * @param array|string|bool $params message parameters, language key (string), true - all languages * @param string|bool|null $language language key, null - current language, true - all languages * @param array $opts additional settings * @return string * @example _ta('context', 'Date: [date]', array('date'=>date('Y.m.d'))); => Date 2001.01.01 */ function _ta(string $context, string $message, $params = [], $language = null, array $opts = []) { return _t('@' . $context, $message, $params, $language, $opts); } /** * Localize message + escape * @param string $context message context * @param string $message message text * @param array|string|bool $params message parameters, language key (string), true - all languages * @param string|bool|null $language language key, null - current language, true - all languages * @param array $opts additional settings * @return string */ function _te(string $context, string $message, $params = [], $language = null, array $opts = []) { return htmlspecialchars(_t($context, $message, $params, $language, $opts), ENT_QUOTES, 'UTF-8'); } /** * Localize message + escape to use in javascript context * @param string $context message context * @param string $message message text * @param array|string|bool $params message parameters, language key (string), true - all languages * @param string|bool|null $language language key, null - current language, true - all languages * @param array $opts additional settings * @return string */ function _tejs(string $context, string $message, $params = [], $language = null, array $opts = []) { return strtr(_t($context, $message, $params, $language, $opts), [ '\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', ' '<\/' ]); }