/**
 * @param array $params
 * SSL default behaviour:
 * Decided by current page.
 * Set parameter __ssl to true or false to override default ssl behaviour.
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_public_url($params = array(), &$smarty)
{
    $path = '';
    if (!empty($params['path'])) {
        $path = $params['path'];
        unset($params['path']);
    }
    if (!empty($params['__ssl'])) {
        $ssl = $params['__ssl'];
        unset($params['__ssl']);
    } else {
        $ssl = \Skully\App\Helpers\UrlHelper::isSecure();
    }
    $arguments = array();
    foreach ($params as $key => $val) {
        $arguments[$key] = $val;
    }
    /** @var \Skully\ApplicationInterface $app */
    $app = $smarty->getRegisteredObject('app');
    if (strpos($path, "http://") !== 0 && strpos($path, "https://") !== 0) {
        $path = $app->getTheme()->getPublicBaseUrl($ssl) . $path;
    }
    if (!empty($arguments)) {
        $argumentsStr = http_build_query($arguments);
        return $path . '?' . $argumentsStr;
    } else {
        return $path;
    }
}
Example #2
0
/**
 * @param array $params
 * @param Smarty $smarty
 * @return mixed
 */
function smarty_function_lang($params = array(), &$smarty)
{
    $value = $params['value'];
    unset($params['value']);
    $arguments = array();
    foreach ($params as $key => $val) {
        $arguments[$key] = $val;
    }
    /** @var \Skully\ApplicationInterface $app */
    $app = $smarty->getRegisteredObject('app');
    return $app->getTranslator()->translate($value, $arguments);
}
Example #3
0
/**
 * @param array $params
 * @param Smarty $smarty
 * @return mixed
 * Url function
 * $params:
 * - path: url string
 * - pass other items as array items.
 * SSL default behaviour:
 * NULL (won't attempt to change http:// into https:// or vice versa).
 * Set parameter __ssl to true or false to override default ssl behaviour.
 */
function smarty_function_url($params = array(), &$smarty)
{
    $path = '';
    if (!empty($params['path'])) {
        $path = $params['path'];
        unset($params['path']);
    }
    if (isset($params['__ssl'])) {
        $ssl = $params['__ssl'];
        unset($params['__ssl']);
    } else {
        $ssl = null;
    }
    /** @var \Skully\ApplicationInterface $app */
    $app = $smarty->getRegisteredObject('app');
    return $app->getRouter()->getUrl($path, $params, $ssl);
}
/**
 * @param array $params
 * SSL default behaviour:
 * Decided by current page.
 * Set parameter __ssl to true or false to override default ssl behaviour.
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_theme_url($params = array(), &$smarty)
{
    $path = '';
    if (!empty($params['path'])) {
        $path = $params['path'];
        unset($params['path']);
    }
    if (!empty($params['__ssl'])) {
        $ssl = $params['__ssl'];
        unset($params['__ssl']);
    } else {
        $ssl = \Skully\App\Helpers\UrlHelper::isSecure();
    }
    $arguments = array();
    foreach ($params as $key => $val) {
        $arguments[$key] = $val;
    }
    /** @var \Skully\ApplicationInterface $app */
    $app = $smarty->getRegisteredObject('app');
    return $app->getTheme()->getUrl($path, $arguments, false, $ssl);
}
Example #5
0
 /**
  * @param $name
  * @return object
  */
 public function getRegisteredObject($name)
 {
     return $this->smarty->getRegisteredObject($name);
 }