Created
April 10, 2015 16:38
-
-
Save damianoporta/6dadf350fa745c28530b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace UserTags\View\Helper; | |
use Cake\View\Helper; | |
use Cake\View\View; | |
use UserTags\Traits\TagTrait; | |
/** | |
* Tag helper | |
*/ | |
class TagHelper extends Helper | |
{ | |
use TagTrait; | |
public $helpers = ['Url']; | |
/** | |
* Default configuration. | |
* | |
* @var array | |
*/ | |
protected $_defaultConfig = []; | |
public function url($url, $full = true, $user = null) | |
{ | |
// Se l'utente non è stato impostato restituisco l'url senza tagging | |
if (!is_numeric($user)) { | |
return $this->Url->build($url, $full); | |
} | |
if (is_string($url)) { | |
$urlInfo = parse_url($url); | |
if (!empty($urlInfo['query'])) { | |
parse_str($urlInfo['query'], $params); | |
} else { | |
$params = []; | |
} | |
$params['user'] = $this->encrypt($user); | |
$urlInfo['query'] = http_build_query($params); | |
$url = $urlInfo['path'] .'?'. $urlInfo['query']; | |
} | |
if (is_array($url)) { | |
$url['user'] = $this->encrypt($user); | |
} | |
return $this->Url->build($url, $full); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment