diff --git a/src/bb-di.php b/src/bb-di.php
index 06bc541cf..9e666263e 100644
--- a/src/bb-di.php
+++ b/src/bb-di.php
@@ -1,4 +1,5 @@
setDi($di);
$log_to_db = isset($di['config']['log_to_db']) && $di['config']['log_to_db'];
+
if ($log_to_db) {
$activity_service = $di['mod_service']('activity');
$writer2 = new Box_LogDb($activity_service);
+
if ($di['auth']->isAdminLoggedIn()) {
$admin = $di['loggedin_admin'];
$log->setEventItem('admin_id', $admin->id);
@@ -30,6 +38,7 @@ $di['logger'] = function () use ($di) {
$client = $di['loggedin_client'];
$log->setEventItem('client_id', $client->id);
}
+
$log->addWriter($writer2);
} else {
$logFile = $di['config']['path_logs'];
@@ -39,12 +48,14 @@ $di['logger'] = function () use ($di) {
return $log;
};
+
$di['crypt'] = function () use ($di) {
$crypt = new Box_Crypt();
$crypt->setDi($di);
return $crypt;
};
+
$di['pdo'] = function () use ($di) {
$c = $di['config']['db'];
@@ -74,6 +85,7 @@ $di['pdo'] = function () use ($di) {
return $pdo;
};
+
$di['db'] = function () use ($di) {
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'rb.php';
R::setup($di['pdo']);
@@ -93,12 +105,14 @@ $di['db'] = function () use ($di) {
return $db;
};
+
$di['pager'] = function () use ($di) {
$service = new Box_Pagination();
$service->setDi($di);
return $service;
};
+
$di['url'] = function () use ($di) {
$url = new Box_Url();
$url->setDi($di);
@@ -106,43 +120,53 @@ $di['url'] = function () use ($di) {
return $url;
};
+
$di['mod'] = $di->protect(function ($name) use ($di) {
$mod = new Box_Mod($name);
$mod->setDi($di);
return $mod;
});
+
$di['mod_service'] = $di->protect(function ($mod, $sub = '') use ($di) {
return $di['mod']($mod)->getService($sub);
});
+
$di['mod_config'] = $di->protect(function ($name) use ($di) {
return $di['mod']($name)->getConfig();
});
+
$di['events_manager'] = function () use ($di) {
$service = new Box_EventManager();
$service->setDi($di);
return $service;
};
+
$di['session'] = function () use ($di) {
$handler = new PdoSessionHandler($di['pdo']);
return new Box_Session($handler);
};
+
$di['cookie'] = function () use ($di) {
$service = new Box_Cookie();
$service->setDi($di);
return $service;
};
+
$di['request'] = function () use ($di) {
$service = new Box_Request();
$service->setDi($di);
return $service;
};
+
$di['cache'] = function () { return new FileCache(); };
+
$di['auth'] = function () use ($di) { return new Box_Authorization($di); };
+
$di['twig'] = $di->factory(function () use ($di) {
$config = $di['config'];
$options = $config['twig'];
@@ -156,10 +180,12 @@ $di['twig'] = $di->factory(function () use ($di) {
// $twig->addExtension(new Twig\Extension\OptimizerExtension());
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
$twig->addExtension(new Twig\Extension\DebugExtension());
- $twig->addExtension(new Twig\Extensions\I18nExtension());
+ $twig->addExtension(new Symfony\Bridge\Twig\Extension\TranslationExtension());
$twig->addExtension($box_extensions);
- $twig->getExtension(Twig\Extension\CoreExtension::class)->setDateFormat($config['locale_date_format']);
- $twig->getExtension(Twig\Extension\CoreExtension::class)->setTimezone($config['timezone']);
+ $twig->getExtension(Twig\Extension\CoreExtension::class)
+ ->setDateFormat($config['locale_date_format']);
+ $twig->getExtension(Twig\Extension\CoreExtension::class)
+ ->setTimezone($config['timezone']);
// add globals
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && 'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH']) {
@@ -176,6 +202,7 @@ $di['is_client_logged'] = function () use ($di) {
if (!$di['auth']->isClientLoggedIn()) {
$api_str = '/api/';
$url = $di['request']->getQuery('_url');
+
if (0 === strncasecmp($url, $api_str, strlen($api_str))) {
// Throw Exception if api request
throw new Exception('Client is not logged in');
@@ -212,6 +239,7 @@ $di['loggedin_client'] = function () use ($di) {
return $di['db']->getExistingModelById('Client', $client_id);
};
+
$di['loggedin_admin'] = function () use ($di) {
if ('cli' == php_sapi_name() || 'cgi' == substr(php_sapi_name(), 0, 3)) {
return $di['mod_service']('staff')->getCronAdmin();
@@ -244,11 +272,13 @@ $di['api'] = $di->protect(function ($role) use ($di) {
default:
throw new Exception('Unrecognized Handler type: '.$role);
}
+
$api = new Api_Handler($identity);
$api->setDi($di);
return $api;
});
+
$di['api_guest'] = function () use ($di) { return $di['api']('guest'); };
$di['api_client'] = function () use ($di) { return $di['api']('client'); };
$di['api_admin'] = function () use ($di) { return $di['api']('admin'); };
@@ -267,6 +297,7 @@ $di['validator'] = function () use ($di) {
return $validator;
};
+
$di['guzzle_client'] = function () use ($di) {
return new GuzzleHttp\Client([
'headers' => [
@@ -276,27 +307,32 @@ $di['guzzle_client'] = function () use ($di) {
'timeout' => $di['config']['guzzle']['timeout'],
]);
};
+
$di['mail'] = function () {
return new Box_Mail();
};
+
$di['extension'] = function () use ($di) {
$extension = new \Box_Extension();
$extension->setDi($di);
return $extension;
};
+
$di['updater'] = function () use ($di) {
$updater = new \Box_Update();
$updater->setDi($di);
return $updater;
};
+
$di['curl'] = function ($url) use ($di) {
$curl = new \Box_Curl($url);
$curl->setDi($di);
return $curl;
};
+
$di['zip_archive'] = function () {return new ZipArchive(); };
$di['server_package'] = function () {return new Server_Package(); };
@@ -370,11 +406,14 @@ $di['pdf'] = function () use ($di) {
$di['geoip'] = function () { return new \GeoIp2\Database\Reader(BB_PATH_LIBRARY.'/GeoLite2-Country.mmdb'); };
$di['password'] = function () { return new Box_Password(); };
+
$di['translate'] = $di->protect(function ($textDomain = '') use ($di) {
$tr = new Box_Translate();
+
if (!empty($textDomain)) {
$tr->setDomain($textDomain);
}
+
$cookieBBlang = $di['cookie']->get('BBLANG');
$locale = !empty($cookieBBlang) ? $cookieBBlang : $di['config']['locale'];
@@ -384,6 +423,7 @@ $di['translate'] = $di->protect(function ($textDomain = '') use ($di) {
return $tr;
});
+
$di['array_get'] = $di->protect(function (array $array, $key, $default = null) {
return array_key_exists($key, $array) ? $array[$key] : $default;
});
diff --git a/src/bb-library/Box/Event.php b/src/bb-library/Box/Event.php
index 6d9636c06..971197cf1 100644
--- a/src/bb-library/Box/Event.php
+++ b/src/bb-library/Box/Event.php
@@ -1,6 +1,7 @@
subject = $subject;
- $this->name = $name;
-
- $this->parameters = $parameters;
-
- $this->api_admin = $api_admin;
- $this->api_guest = $api_guest;
- }
+ /**
+ * Constructs a new sfEvent.
+ *
+ * @param mixed $subject The subject
+ * @param string $name The event name
+ * @param array $parameters An array of parameters
+ */
+ public function __construct($subject, $name, $parameters = [], $api_admin = null, $api_guest = null)
+ {
+ $this->subject = $subject;
+ $this->name = $name;
+
+ $this->parameters = $parameters;
+
+ $this->api_admin = $api_admin;
+ $this->api_guest = $api_guest;
+ }
/**
* @param Box_Di|null $di
@@ -56,133 +55,132 @@ class Box_Event implements ArrayAccess, \Box\InjectionAwareInterface
return $this->di;
}
- /**
- * Returns the subject.
- *
- * @return mixed The subject
- */
- public function getSubject()
- {
- return $this->subject;
- }
-
- public function getApiAdmin()
- {
- return $this->api_admin;
- }
-
- public function getApiGuest()
- {
- return $this->api_guest;
- }
-
- /**
- * Returns the event name.
- *
- * @return string The event name
- */
- public function getName()
- {
- return $this->name;
- }
-
- /**
- * Sets the return value for this event.
- *
- * @param mixed $value The return value
- */
- public function setReturnValue($value)
- {
- $this->value = $value;
- }
-
- /**
- * Returns the return value.
- *
- * @return mixed The return value
- */
- public function getReturnValue()
- {
- return $this->value;
- }
-
- /**
- * Sets the processed flag.
- *
- * @param Boolean $processed The processed flag value
- */
- public function setProcessed($processed)
- {
- $this->processed = (boolean) $processed;
- }
-
- /**
- * Returns whether the event has been processed by a listener or not.
- *
- * @return Boolean true if the event has been processed, false otherwise
- */
- public function isProcessed()
- {
- return $this->processed;
- }
-
- /**
- * Returns the event parameters.
- *
- * @return array The event parameters
- */
- public function getParameters()
- {
- return $this->parameters;
- }
-
- /**
- * Returns true if the parameter exists (implements the ArrayAccess interface).
- *
- * @param string $name The parameter name
- *
- * @return Boolean true if the parameter exists, false otherwise
- */
- public function offsetExists($name)
- {
- return array_key_exists($name, $this->parameters);
- }
-
- /**
- * Returns a parameter value (implements the ArrayAccess interface).
- *
- * @param string $name The parameter name
- *
- * @return mixed The parameter value
- */
- public function offsetGet($name)
- {
- if (!array_key_exists($name, $this->parameters))
+ /**
+ * Returns the subject.
+ *
+ * @return mixed The subject
+ */
+ public function getSubject()
{
- throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
+ return $this->subject;
}
- return $this->parameters[$name];
- }
+ public function getApiAdmin()
+ {
+ return $this->api_admin;
+ }
- /**
- * Sets a parameter (implements the ArrayAccess interface).
- *
- * @param string $name The parameter name
- * @param mixed $value The parameter value
- */
- public function offsetSet($name, $value)
- {
- $this->parameters[$name] = $value;
- }
+ public function getApiGuest()
+ {
+ return $this->api_guest;
+ }
- /**
- * Removes a parameter (implements the ArrayAccess interface).
- *
- * @param string $name The parameter name
- */
- public function offsetUnset($name)
- {
- unset($this->parameters[$name]);
- }
+ /**
+ * Returns the event name.
+ *
+ * @return string The event name
+ */
+ public function getName()
+ {
+ return $this->name;
+ }
+
+ /**
+ * Sets the return value for this event.
+ *
+ * @param mixed $value The return value
+ */
+ public function setReturnValue($value)
+ {
+ $this->value = $value;
+ }
+
+ /**
+ * Returns the return value.
+ *
+ * @return mixed The return value
+ */
+ public function getReturnValue()
+ {
+ return $this->value;
+ }
+
+ /**
+ * Sets the processed flag.
+ *
+ * @param bool $processed The processed flag value
+ */
+ public function setProcessed($processed)
+ {
+ $this->processed = (bool) $processed;
+ }
+
+ /**
+ * Returns whether the event has been processed by a listener or not.
+ *
+ * @return bool true if the event has been processed, false otherwise
+ */
+ public function isProcessed()
+ {
+ return $this->processed;
+ }
+
+ /**
+ * Returns the event parameters.
+ *
+ * @return array The event parameters
+ */
+ public function getParameters()
+ {
+ return $this->parameters;
+ }
+
+ /**
+ * Returns true if the parameter exists (implements the ArrayAccess interface).
+ *
+ * @param string $name The parameter name
+ *
+ * @return bool true if the parameter exists, false otherwise
+ */
+ public function offsetExists(mixed $name): bool
+ {
+ return array_key_exists($name, $this->parameters);
+ }
+
+ /**
+ * Returns a parameter value (implements the ArrayAccess interface).
+ *
+ * @param string $name The parameter name
+ *
+ * @return mixed The parameter value
+ */
+ public function offsetGet(mixed $name): mixed
+ {
+ if (!array_key_exists($name, $this->parameters)) {
+ throw new InvalidArgumentException(sprintf('The event "%s" has no "%s" parameter.', $this->name, $name));
+ }
+
+ return $this->parameters[$name];
+ }
+
+ /**
+ * Sets a parameter (implements the ArrayAccess interface).
+ *
+ * @param string $name The parameter name
+ * @param mixed $value The parameter value
+ */
+ public function offsetSet(mixed $name, $value): void
+ {
+ $this->parameters[$name] = $value;
+ }
+
+ /**
+ * Removes a parameter (implements the ArrayAccess interface).
+ *
+ * @param string $name The parameter name
+ */
+ public function offsetUnset(mixed $name): void
+ {
+ unset($this->parameters[$name]);
+ }
}
diff --git a/src/bb-library/Box/EventDispatcher.php b/src/bb-library/Box/EventDispatcher.php
index 0c69e678a..d0b63d4f9 100644
--- a/src/bb-library/Box/EventDispatcher.php
+++ b/src/bb-library/Box/EventDispatcher.php
@@ -1,6 +1,7 @@
listeners[$name]))
+ /**
+ * Connects a listener to a given event name.
+ *
+ * @param string $name An event name
+ * @param mixed $listener A PHP callable
+ */
+ public function connect($name, $listener)
{
- $this->listeners[$name] = array();
+ if (!isset($this->listeners[$name])) {
+ $this->listeners[$name] = [];
+ }
+
+ $this->listeners[$name][] = $listener;
}
- $this->listeners[$name][] = $listener;
- }
-
- /**
- * Disconnects a listener for a given event name.
- *
- * @param string $name An event name
- * @param mixed $listener A PHP callable
- *
- * @return false|null false if listener does not exist, null otherwise
- */
- public function disconnect($name, $listener)
- {
- if (!isset($this->listeners[$name]))
+ /**
+ * Disconnects a listener for a given event name.
+ *
+ * @param string $name An event name
+ * @param mixed $listener A PHP callable
+ *
+ * @return false|null false if listener does not exist, null otherwise
+ */
+ public function disconnect($name, $listener)
{
- return false;
+ if (!isset($this->listeners[$name])) {
+ return false;
+ }
+
+ foreach ($this->listeners[$name] as $i => $callable) {
+ if ($listener === $callable) {
+ unset($this->listeners[$name][$i]);
+ }
+ }
}
- foreach ($this->listeners[$name] as $i => $callable)
+ /**
+ * Disconnects all listeners for a given event name.
+ *
+ * @param string $name An event name
+ *
+ * @return false|null false if listener does not exist, null otherwise
+ */
+ public function disconnectAll($name)
{
- if ($listener === $callable)
- {
- unset($this->listeners[$name][$i]);
- }
- }
- }
+ if (!isset($this->listeners[$name])) {
+ return false;
+ }
- /**
- * Disconnects all listeners for a given event name.
- *
- * @param string $name An event name
- *
- * @return false|null false if listener does not exist, null otherwise
- */
- public function disconnectAll($name)
- {
- if (!isset($this->listeners[$name]))
- {
- return false;
+ foreach ($this->listeners[$name] as $i => $callable) {
+ unset($this->listeners[$name][$i]);
+ }
}
- foreach ($this->listeners[$name] as $i => $callable)
+ /**
+ * Notifies all listeners of a given event.
+ *
+ * @param Box_Event $event A Box_Event instance
+ *
+ * @return Box_Event The Box_Event instance
+ */
+ public function notify(Box_Event $event)
{
- unset($this->listeners[$name][$i]);
- }
- }
+ foreach ($this->getListeners($event->getName()) as $listener) {
+ call_user_func($listener, $event);
+ }
- /**
- * Notifies all listeners of a given event.
- *
- * @param Box_Event $event A Box_Event instance
- *
- * @return Box_Event The Box_Event instance
- */
- public function notify(Box_Event $event)
- {
- foreach ($this->getListeners($event->getName()) as $listener)
- {
- call_user_func($listener, $event);
+ return $event;
}
- return $event;
- }
-
- /**
- * Notifies all listeners of a given event until one returns a non null value.
- *
- * @param Box_Event $event A Box_Event instance
- *
- * @return Box_Event The Box_Event instance
- */
- public function notifyUntil(Box_Event $event)
- {
- foreach ($this->getListeners($event->getName()) as $listener)
+ /**
+ * Notifies all listeners of a given event until one returns a non null value.
+ *
+ * @param Box_Event $event A Box_Event instance
+ *
+ * @return Box_Event The Box_Event instance
+ */
+ public function notifyUntil(Box_Event $event)
{
- if (call_user_func($listener, $event))
- {
- $event->setProcessed(true);
- break;
- }
+ foreach ($this->getListeners($event->getName()) as $listener) {
+ if (call_user_func($listener, $event)) {
+ $event->setProcessed(true);
+ break;
+ }
+ }
+
+ return $event;
}
- return $event;
- }
-
- /**
- * Filters a value by calling all listeners of a given event.
- *
- * @param Box_Event $event A Box_Event instance
- * @param mixed $value The value to be filtered
- *
- * @return Box_Event The Box_Event instance
- */
- public function filter(Box_Event $event, $value)
- {
- foreach ($this->getListeners($event->getName()) as $listener)
+ /**
+ * Filters a value by calling all listeners of a given event.
+ *
+ * @param Box_Event $event A Box_Event instance
+ * @param mixed $value The value to be filtered
+ *
+ * @return Box_Event The Box_Event instance
+ */
+ public function filter(Box_Event $event, $value)
{
- $value = call_user_func_array($listener, array($event, $value));
+ foreach ($this->getListeners($event->getName()) as $listener) {
+ $value = call_user_func_array($listener, [$event, $value]);
+ }
+
+ $event->setReturnValue($value);
+
+ return $event;
}
- $event->setReturnValue($value);
-
- return $event;
- }
-
- /**
- * Returns true if the given event name has some listeners.
- *
- * @param string $name The event name
- *
- * @return Boolean true if some listeners are connected, false otherwise
- */
- public function hasListeners($name)
- {
- if (!isset($this->listeners[$name]))
+ /**
+ * Returns true if the given event name has some listeners.
+ *
+ * @param string $name The event name
+ *
+ * @return bool true if some listeners are connected, false otherwise
+ */
+ public function hasListeners($name)
{
- $this->listeners[$name] = array();
+ if (!isset($this->listeners[$name])) {
+ $this->listeners[$name] = [];
+ }
+
+ return (bool) count($this->listeners[$name]);
}
- return (boolean) count($this->listeners[$name]);
- }
-
- /**
- * Returns all listeners associated with a given event name.
- *
- * @param string $name The event name
- *
- * @return array An array of listeners
- */
- public function getListeners($name)
- {
- if (!isset($this->listeners[$name]))
+ /**
+ * Returns all listeners associated with a given event name.
+ *
+ * @param string $name The event name
+ *
+ * @return array An array of listeners
+ */
+ public function getListeners($name)
{
- return array();
- }
+ if (!isset($this->listeners[$name])) {
+ return [];
+ }
- return $this->listeners[$name];
- }
-}
\ No newline at end of file
+ return $this->listeners[$name];
+ }
+}
diff --git a/src/bb-library/Box/EventManager.php b/src/bb-library/Box/EventManager.php
index be700c9f9..b2bd856ef 100644
--- a/src/bb-library/Box/EventManager.php
+++ b/src/bb-library/Box/EventManager.php
@@ -1,6 +1,7 @@
di['logger']->debug($event. ': '. var_export($params, 1));
+ if (BB_DEBUG) {
+ $this->di['logger']->debug($event.': '.var_export($params, 1));
}
$e = new Box_Event($subject, $event, $params);
@@ -55,38 +55,39 @@ class Box_EventManager implements \Box\InjectionAwareInterface
return $e->getReturnValue();
}
-
/**
* @param Box_EventDispatcher $disp
- * @param string $event
+ * @param string $event
*/
private function _connectDatabaseHooks(&$disp, $event)
{
- $sql="SELECT id, rel_id, meta_value
+ $sql = "SELECT id, rel_id, meta_value
FROM extension_meta
WHERE extension = 'mod_hook'
AND rel_type = 'mod'
AND meta_key = 'listener'
AND meta_value = :event
";
- $list = $this->di['db']->getAll($sql, array('event'=>$event));
+ $list = $this->di['db']->getAll($sql, ['event' => $event]);
// no need to connect listeners
- if(empty($list)) {
- return ;
+ if (empty($list)) {
+ return;
}
- foreach($list as $listener) {
+ foreach ($list as $listener) {
$mod = $listener['rel_id'];
$event = $listener['meta_value'];
+
try {
$s = $this->di['mod_service']($mod);
- if(method_exists($s, $event)) {
- $disp->connect($event, array(get_class($s), $event));
+
+ if (method_exists($s, $event)) {
+ $disp->connect($event, [get_class($s), $event]);
}
- } catch(Exception $e) {
+ } catch (Exception $e) {
error_log($e->getMessage());
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/bb-library/Box/TwigExtensions.php b/src/bb-library/Box/TwigExtensions.php
index 794241b4b..04bb1880d 100644
--- a/src/bb-library/Box/TwigExtensions.php
+++ b/src/bb-library/Box/TwigExtensions.php
@@ -1,6 +1,7 @@
new Twig\TwigFilter('alink', array($this, 'twig_bb_admin_link_filter'), array('is_safe' => array('html'))),
- 'link' => new Twig\TwigFilter('link', array($this, 'twig_bb_client_link_filter'), array('is_safe' => array('html'))),
- 'gravatar' => new Twig\TwigFilter('gravatar','twig_gravatar_filter'),
- 'markdown' => new Twig\TwigFilter('markdown','twig_markdown_filter', array('needs_environment' => true, 'is_safe' => array('html'))),
- 'truncate' => new Twig\TwigFilter('truncate','twig_truncate_filter', array('needs_environment' => true)),
- 'timeago' => new Twig\TwigFilter('timeago','twig_timeago_filter'),
- 'daysleft' => new Twig\TwigFilter('daysleft','twig_daysleft_filter'),
- 'size' => new Twig\TwigFilter('size', 'twig_size_filter'),
- 'ipcountryname' => new Twig\TwigFilter('ipcountryname', array($this, 'twig_ipcountryname_filter')),
- 'number' => new Twig\TwigFilter('number', 'twig_number_filter'),
- 'period_title' => new Twig\TwigFilter('period_title', 'twig_period_title', array('needs_environment' => true, 'is_safe' => array('html'))),
- 'autolink' => new Twig\TwigFilter('autolink', 'twig_autolink_filter'),
- 'bbmd' => new Twig\TwigFilter('bbmd', 'twig_bbmd_filter', array('needs_environment' => true, 'is_safe' => array('html'))),
+ return [
+ /**
+ * 'trans' filter rewrite same filter from Symfony\Bridge\Twig\Extension\TranslationExtension
+ * for compatible with outdated php-gettext library.
+ *
+ * TODO: Use Symfony\Component\Translation\Loader\MoFileLoader and remove php-gettext hardcoded library.
+ */
+ 'trans' => new TwigFilter('trans', 'gettext'),
+ 'alink' => new TwigFilter('alink', [$this, 'twig_bb_admin_link_filter'], ['is_safe' => ['html']]),
+ 'link' => new TwigFilter('link', [$this, 'twig_bb_client_link_filter'], ['is_safe' => ['html']]),
+ 'gravatar' => new TwigFilter('gravatar', 'twig_gravatar_filter'),
+ 'markdown' => new TwigFilter('markdown', 'twig_markdown_filter', ['needs_environment' => true, 'is_safe' => ['html']]),
+ 'truncate' => new TwigFilter('truncate', 'twig_truncate_filter', ['needs_environment' => true]),
+ 'timeago' => new TwigFilter('timeago', 'twig_timeago_filter'),
+ 'daysleft' => new TwigFilter('daysleft', 'twig_daysleft_filter'),
+ 'size' => new TwigFilter('size', 'twig_size_filter'),
+ 'ipcountryname' => new TwigFilter('ipcountryname', [$this, 'twig_ipcountryname_filter']),
+ 'number' => new TwigFilter('number', 'twig_number_filter'),
+ 'period_title' => new TwigFilter('period_title', 'twig_period_title', ['needs_environment' => true, 'is_safe' => ['html']]),
+ 'autolink' => new TwigFilter('autolink', 'twig_autolink_filter'),
+ 'bbmd' => new TwigFilter('bbmd', 'twig_bbmd_filter', ['needs_environment' => true, 'is_safe' => ['html']]),
- 'bb_date' => new Twig\TwigFilter('bb_date', array($this, 'twig_bb_date')),
- 'bb_datetime' => new Twig\TwigFilter('bb_datetime', array($this, 'twig_bb_datetime')),
+ 'bb_date' => new TwigFilter('bb_date', [$this, 'twig_bb_date']),
+ 'bb_datetime' => new TwigFilter('bb_datetime', [$this, 'twig_bb_datetime']),
- 'img_tag' => new Twig\TwigFilter('img_tag', 'twig_img_tag', array('needs_environment' => false, 'is_safe' => array('html'))),
- 'script_tag' => new Twig\TwigFilter('script_tag', 'twig_script_tag', array('needs_environment' => false, 'is_safe' => array('html'))),
- 'stylesheet_tag' => new Twig\TwigFilter('stylesheet_tag', 'twig_stylesheet_tag', array('needs_environment' => false, 'is_safe' => array('html'))),
+ 'img_tag' => new TwigFilter('img_tag', 'twig_img_tag', ['needs_environment' => false, 'is_safe' => ['html']]),
+ 'script_tag' => new TwigFilter('script_tag', 'twig_script_tag', ['needs_environment' => false, 'is_safe' => ['html']]),
+ 'stylesheet_tag' => new TwigFilter('stylesheet_tag', 'twig_stylesheet_tag', ['needs_environment' => false, 'is_safe' => ['html']]),
- 'mod_asset_url' => new Twig\TwigFilter('mod_asset_url', 'twig_mod_asset_url'),
- 'asset_url' => new Twig\TwigFilter('asset_url', 'twig_asset_url', array('needs_environment' => true, 'is_safe' => array('html'))),
+ 'mod_asset_url' => new TwigFilter('mod_asset_url', 'twig_mod_asset_url'),
+ 'asset_url' => new TwigFilter('asset_url', 'twig_asset_url', ['needs_environment' => true, 'is_safe' => ['html']]),
- 'money' => new Twig\TwigFilter('money', 'twig_money', array('needs_environment' => true, 'is_safe' => array('html'))),
- 'money_without_currency' => new Twig\TwigFilter('money_without_currency','twig_money_without_currency', array('needs_environment' => true, 'is_safe' => array('html'))),
- 'money_convert' => new Twig\TwigFilter('money_convert', 'twig_money_convert', array('needs_environment' => true, 'is_safe' => array('html'))),
- 'money_convert_without_currency' => new Twig\TwigFilter('money_convert_without_currency', array('needs_environment' => true, 'is_safe' => array('html'))),
- );
+ 'money' => new TwigFilter('money', 'twig_money', ['needs_environment' => true, 'is_safe' => ['html']]),
+ 'money_without_currency' => new TwigFilter('money_without_currency', 'twig_money_without_currency', ['needs_environment' => true, 'is_safe' => ['html']]),
+ 'money_convert' => new TwigFilter('money_convert', 'twig_money_convert', ['needs_environment' => true, 'is_safe' => ['html']]),
+ 'money_convert_without_currency' => new TwigFilter('money_convert_without_currency', ['needs_environment' => true, 'is_safe' => ['html']]),
+ ];
}
/**
@@ -84,6 +95,7 @@ class Box_TwigExtensions extends Twig\Extension\AbstractExtension implements \Bo
{
$locale_date_format = $this->di['config']['locale_date_format'];
$format = is_null($format) ? $locale_date_format : $format;
+
return strftime($format, strtotime($time));
}
@@ -91,11 +103,12 @@ class Box_TwigExtensions extends Twig\Extension\AbstractExtension implements \Bo
{
$locale_date_format = $this->di['config']['locale_date_format'];
$locale_time_format = $this->di['config']['locale_time_format'];
- $format = is_null($format) ? $locale_date_format . $locale_time_format : $format;
+ $format = is_null($format) ? $locale_date_format.$locale_time_format : $format;
+
return strftime($format, strtotime($time));
}
- function twig_ipcountryname_filter($value)
+ public function twig_ipcountryname_filter($value)
{
if (empty($value)) {
return '';
@@ -103,84 +116,92 @@ class Box_TwigExtensions extends Twig\Extension\AbstractExtension implements \Bo
try {
$record = $this->di['geoip']->country($value);
+
return $record->country->name;
} catch (Exception $e) {
return '';
}
}
- function twig_bb_client_link_filter($link, $params = null)
+ public function twig_bb_client_link_filter($link, $params = null)
{
- if($this->di['url'] === null) {
+ if (null === $this->di['url']) {
return null;
}
+
return $this->di['url']->link($link, $params);
}
- function twig_bb_admin_link_filter($link, $params = null)
+ public function twig_bb_admin_link_filter($link, $params = null)
{
return $this->di['url']->adminLink($link, $params);
}
-
}
function twig_period_title(Twig\Environment $env, $period)
{
$globals = $env->getGlobals();
$api_guest = $globals['guest'];
- return $api_guest->system_period_title(array('code'=>$period));
+
+ return $api_guest->system_period_title(['code' => $period]);
}
function twig_money_convert(Twig\Environment $env, $price, $currency = null)
{
$globals = $env->getGlobals();
$api_guest = $globals['guest'];
- if(is_null($currency)) {
+ if (is_null($currency)) {
$c = $api_guest->cart_get_currency();
$currency = $c['code'];
}
- return $api_guest->currency_format(array("price" => $price, 'code'=>$currency, 'convert'=>true));
+
+ return $api_guest->currency_format(['price' => $price, 'code' => $currency, 'convert' => true]);
}
function money_convert_without_currency(Twig\Environment $env, $price, $currency = null, $without_currency = false)
{
$globals = $env->getGlobals();
$api_guest = $globals['guest'];
- if(is_null($currency)) {
+ if (is_null($currency)) {
$c = $api_guest->cart_get_currency();
$currency = $c['code'];
}
- return $api_guest->currency_format(array("price" => $price, 'code'=>$currency, 'convert'=>true, 'without_currency'=>true));
+
+ return $api_guest->currency_format(['price' => $price, 'code' => $currency, 'convert' => true, 'without_currency' => true]);
}
function twig_money(Twig\Environment $env, $price, $currency = null)
{
$globals = $env->getGlobals();
$api_guest = $globals['guest'];
- return $api_guest->currency_format(array("price" => $price, 'code'=>$currency, 'convert'=>false));
+
+ return $api_guest->currency_format(['price' => $price, 'code' => $currency, 'convert' => false]);
}
function twig_money_without_currency(Twig\Environment $env, $price, $currency = null)
{
$globals = $env->getGlobals();
$api_guest = $globals['guest'];
- return $api_guest->currency_format(array("price" => $price, 'code'=>$currency, 'convert'=>false, 'without_currency'=>true));
+
+ return $api_guest->currency_format(['price' => $price, 'code' => $currency, 'convert' => false, 'without_currency' => true]);
}
function twig_mod_asset_url($asset, $mod)
{
- return BB_URL . 'bb-modules/'.ucfirst($mod).'/assets/'.$asset;
+ return BB_URL.'bb-modules/'.ucfirst($mod).'/assets/'.$asset;
}
function twig_asset_url(Twig\Environment $env, $asset)
{
$globals = $env->getGlobals();
- return BB_URL . 'bb-themes/'.$globals['current_theme'].'/assets/'.$asset;
+
+ return BB_URL.'bb-themes/'.$globals['current_theme'].'/assets/'.$asset;
}
function twig_img_tag($path, $alt = null)
{
$alt = is_null($alt) ? pathinfo($path, PATHINFO_BASENAME) : $alt;
+
return sprintf('', htmlspecialchars($path), htmlspecialchars($alt), htmlspecialchars($alt));
}
@@ -196,25 +217,25 @@ function twig_stylesheet_tag($path, $media = 'screen')
function twig_gravatar_filter($email, $size = 20)
{
- return (new Box_Tools)->get_gravatar($email, $size);
+ return (new Box_Tools())->get_gravatar($email, $size);
}
function twig_autolink_filter($text)
{
- $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
+ $pattern = '#\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))#';
- $callback = function($matches)
- {
- $url = array_shift($matches);
- $url_parts = parse_url($url);
- if(!isset($url_parts["scheme"])) {
- $url = 'http://' . $url;
- }
+ $callback = function ($matches) {
+ $url = array_shift($matches);
+ $url_parts = parse_url($url);
- return sprintf('%s', $url, $url);
- };
+ if (!isset($url_parts['scheme'])) {
+ $url = 'http://'.$url;
+ }
- return preg_replace_callback($pattern, $callback, $text);
+ return sprintf('%s', $url, $url);
+ };
+
+ return preg_replace_callback($pattern, $callback, $text);
}
function twig_number_filter($number, $decimals = 2, $dec_point = '.', $thousands_sep = '')
@@ -225,24 +246,40 @@ function twig_number_filter($number, $decimals = 2, $dec_point = '.', $thousands
function twig_daysleft_filter($iso8601)
{
$timediff = strtotime($iso8601) - time();
- return intval($timediff/86400);
+
+ return intval($timediff / 86400);
}
function twig_timeago_filter($iso8601)
{
- $cur_tm = time(); $dif = $cur_tm-strtotime($iso8601);
- $pds = array(__('second'),__('minute'),__('hour'),__('day'),__('week'),__('month'),__('year'),__('decade'));
- $lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
- for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
+ $cur_tm = time();
+ $dif = $cur_tm - strtotime($iso8601);
+ $pds = [__('second'), __('minute'), __('hour'), __('day'), __('week'), __('month'), __('year'), __('decade')];
+ $lngh = [1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600];
+
+ for ($v = sizeof($lngh) - 1; ($v >= 0) && (($no = $dif / $lngh[$v]) <= 1); --$v) {
+ }
+
+ if ($v < 0) {
+ $v = 0;
+ }
+
+ $_tm = $cur_tm - ($dif % $lngh[$v]);
+
+ $no = floor($no);
+
+ if (1 != $no) {
+ $pds[$v] .= 's';
+ }
+ $x = sprintf('%d %s ', $no, $pds[$v]);
- $no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
return $x;
}
function twig_size_filter($value)
{
$precision = 2;
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
+ $units = ['B', 'KB', 'MB', 'GB', 'TB'];
$bytes = max($value, 0);
$pow = floor(($bytes ? log($bytes) : 0) / log(1024));
@@ -250,27 +287,30 @@ function twig_size_filter($value)
$bytes /= pow(1024, $pow);
- return round($bytes, $precision) . ' ' . $units[$pow];
+ return round($bytes, $precision).' '.$units[$pow];
}
function twig_markdown_filter(Twig\Environment $env, $value)
{
- $markdownParser = new \Michelf\MarkdownExtra;
+ $markdownParser = new \Michelf\MarkdownExtra();
// Michelf Markdown version 1.7.0 and up
$markdownParser->hard_wrap = true;
$result = $markdownParser->transform(htmlspecialchars($value, ENT_NOQUOTES));
- $result = preg_replace_callback('/(?<=href=")(.*)(?=")/', function($match) {
- if(!filter_var($match[0], FILTER_VALIDATE_URL)) {
+ $result = preg_replace_callback('/(?<=href=")(.*)(?=")/', function ($match) {
+ if (!filter_var($match[0], FILTER_VALIDATE_URL)) {
$match[0] = '#';
}
+
return $match[0];
}, $result);
+
return $result;
}
function twig_truncate_filter(Twig\Environment $env, $value, $length = 30, $preserve = false, $separator = '...')
{
- mb_internal_encoding("UTF-8");
+ mb_internal_encoding('UTF-8');
+
if (mb_strlen($value) > $length) {
if ($preserve) {
if (false !== ($breakpoint = mb_strpos($value, ' ', $length))) {
@@ -278,17 +318,18 @@ function twig_truncate_filter(Twig\Environment $env, $value, $length = 30, $pres
}
}
- return mb_substr($value, 0, $length) . $separator;
+ return mb_substr($value, 0, $length).$separator;
}
return $value;
}
/**
- * BoxBilling markdown
+ * BoxBilling markdown.
*/
function twig_bbmd_filter(Twig\Environment $env, $value)
{
$value = twig_markdown_filter($env, $value);
+
return $value;
}
diff --git a/src/bb-modules/Client/html_admin/mod_client_settings.phtml b/src/bb-modules/Client/html_admin/mod_client_settings.phtml
index 49b8b7c39..6a1372f80 100644
--- a/src/bb-modules/Client/html_admin/mod_client_settings.phtml
+++ b/src/bb-modules/Client/html_admin/mod_client_settings.phtml
@@ -1,112 +1,108 @@
{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
+
{% import "macro_functions.phtml" as mf %}
+
{% block meta_title %}Client settings{% endblock %}
+
{% set active_menu = 'system' %}
{% block breadcrumbs %}