Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Added in SmartyPlugins
Browse files Browse the repository at this point in the history
  • Loading branch information
silentworks committed Jul 10, 2013
1 parent 1e07fcb commit fab13d9
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
24 changes: 24 additions & 0 deletions SmartyPlugins/function.baseUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.baseUrl.php
* Type: function
* Name: baseUrl
* Purpose: outputs url for a function with the defined name method
* -------------------------------------------------------------
*/
function smarty_function_baseUrl($params, $template)
{
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
$appName = isset($params['appname']) ? $params['appname'] : 'default';

$req = \Slim\Slim::getInstance($appName)->request();
$uri = $req->getUrl();

if ($withUri) {
$uri .= $req->getRootUri();
}

return $uri;
}
25 changes: 25 additions & 0 deletions SmartyPlugins/function.siteUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.siteUrl.php
* Type: function
* Name: siteUrl
* Purpose: outputs url for a function with the defined name method
* -------------------------------------------------------------
*/
function smarty_function_siteUrl($params, $template)
{
$withUri = isset($params['withUri']) ? $params['withUri'] : true;
$appName = isset($params['appname']) ? $params['appname'] : 'default';
$url = isset($params['url']) ? $params['url'] : '';

$req = \Slim\Slim::getInstance($appName)->request();
$uri = $req->getUrl();

if ($withUri) {
$uri .= $req->getRootUri();
}

return $uri . '/' . ltrim($url, '/');
}
30 changes: 30 additions & 0 deletions SmartyPlugins/function.urlFor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.urlFor.php
* Type: function
* Name: urlFor
* Purpose: outputs url for a function with the defined name method
* -------------------------------------------------------------
*/
function smarty_function_urlFor($params, $template)
{
$name = isset($params['name']) ? $params['name'] : '';
$appName = isset($params['appname']) ? $params['appname'] : 'default';

$url = \Slim\Slim::getInstance($appName)->urlFor($name);

if (isset($params['options']))
{
$options = explode('|', $params['options']);
foreach ($options as $option) {
list($key, $value) = explode('.', $option);
$opts[$key] = $value;
}

$url = \Slim\Slim::getInstance($appName)->urlFor($name, $opts);
}

return $url;
}

0 comments on commit fab13d9

Please sign in to comment.