Skip to content

Instantly share code, notes, and snippets.

@damianoporta
Created April 10, 2015 16:38
Show Gist options
  • Save damianoporta/6dadf350fa745c28530b to your computer and use it in GitHub Desktop.
Save damianoporta/6dadf350fa745c28530b to your computer and use it in GitHub Desktop.
<?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