Process url generator function

@param  array   $params
@param  \Smarty $smarty
@return string  no text is returned.
161377
public function generateUrlFunction($params, &$smarty)
    {
        // the path to process
        $current = $this->getParam($params, 'current', false);
        $path  = $this->getParam($params, 'path', null);
        // Do not invoke index.php in URL (get a static file in web space
        $file = $this->getParam($params, 'file', null);
        $routeId = $this->getParam($params, 'route_id', null);
        // select default router
        if ($this->getRequest()->fromAdmin()) {
            $defaultRouter = 'admin';
        } elseif ($this->getRequest()->fromFront()) {
            $defaultRouter = 'front';
        } else {
            $defaultRouter = null;
        }

        $routerId = $this->getParam($params, 'router', $defaultRouter);

        $baseUrl = $this->getParam($params, 'base_url', null);

        if ($current) {
            $path = $this->getRequest()->getPathInfo();
            unset($params["current"]); // Delete the current param, so it isn't included in the url

            // build the query variables
            $params = array_merge(
                $this->getRequest()->query->all(),
                $params
            );
        }

        if ($routeId !== null && $routerId !== null) {
            $routerId = 'router.' . $routerId;

            // test if the router exists
            if (!$this->container->has($routerId)) {
                throw new \InvalidArgumentException(
                    'The router "' . $routerId . '" not found.'
                );
            }
            // get url by router and id
            /** @var Router $router */
            $router = $this->container->get($routerId);

            $url = $router->generate(
                $routeId,
                $this->getArgsFromParam($params, ['route_id', 'router', 'base_url']),
                Router::ABSOLUTE_URL
            );
        } else {
            if ($file !== null) {
                $path = $file;
                $mode = URL::PATH_TO_FILE;
            } elseif ($path !== null) {
                $mode = URL::WITH_INDEX_PAGE;
            } else {
                throw new \InvalidArgumentException(
                    "Please specify either 'path', 'file' or router and route_id on parameters in {url} function."
                );
            }

            $excludeParams = $this->resolvePath($params, $path, $smarty);

            $url = URL::getInstance()->absoluteUrl(
                $path,
                $this->getArgsFromParam($params, array_merge(['noamp', 'path', 'file', 'target', 'base_url'], $excludeParams)),
                $mode,
                $baseUrl
            );

            $request = $this->getRequest();
            $requestedLangCodeOrLocale = $params["lang"];
            $view = $request->attributes->get('_view', null);
            $viewId = $view === null ? null : $request->query->get($view . '_id', null);

            if (null !== $requestedLangCodeOrLocale) {
                if (strlen($requestedLangCodeOrLocale) > 2) {
                    $lang = LangQuery::create()->findOneByLocale($requestedLangCodeOrLocale);
                } else {
                    $lang = LangQuery::create()->findOneByCode($requestedLangCodeOrLocale);
                }

                if (ConfigQuery::isMultiDomainActivated()) {
                    $urlRewrite = RewritingUrlQuery::create()
                        ->filterByView($view)
                        ->filterByViewId($viewId)
                        ->filterByViewLocale($lang->getLocale())
                        ->findOneByRedirected(null)
                    ;

                    $path = '';
                    if (null != $urlRewrite) {
                        $path = "/".$urlRewrite->getUrl();
                    }
                    $url = rtrim($lang->getUrl(), "/").$request->getBaseUrl().$path;
                }

            }
        }
        return $this->applyNoAmpAndTarget($params, $url);
    }
412240
private function generateCacheKey($key, $params)
    {
        // If our parameters is an array
        // we need to do some work to it.
        if (is_array($params)) {
            // Sort array and maintain index
            asort($params);

            // Convert array to a query string
            $params = http_build_query($params);
        }

        return $key.'|'.$params;
    }
35449
public function generate($name, $params = []) {
		$url = '';
		$path = $this->generatePath($name, $params);

		if ($path) {
			if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])
				&& $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'
			) {
				$scheme = 'https';
			} else {
				$scheme = 'http';
			}
			$url = $scheme . '://' . $_SERVER['HTTP_HOST'] . $path;
		}

		return $url;
	}
176200
public function generateYiic($source,$params)
	{
		$content=file_get_contents($source);
		$yiic=realpath(dirname(__FILE__).'/../../yiic.php');
		$yiic=$this->getRelativePath($yiic,$this->_rootPath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'yiic.php');
		$yiic=str_replace('\\','\\\\',$yiic);
		return preg_replace('/\$yiic\s*=(.*?);/',"\$yiic=$yiic;",$content);
	}
1183238
static function fetch($template, $data = array(), $smarty = NULL)
	{
//		if($template[0] == '/')
//			$template = 'xfile:'.$template;

//		PhpConsole\Handler::getInstance()->debug($template, 'tpl');
//		PhpConsole\Handler::getInstance()->debug($data, 'tpldata');

		if(!$smarty)
			$smarty = self::factory();

		$data = array_merge(bors_template::page_data(), $data);
		$smarty->auto_literal = popval($data, 'smarty_auto_literal', $smarty->auto_literal);
		$smarty->assign($data);
		$trace = debug_backtrace();

		$caller_path = NULL;
		$wo_xfile_prefix = str_replace('xfile:', '', $template);

		for($i=1, $stop=count($trace); $i<$stop; $i++)
		{
			if(!empty($trace[$i]['file']))
				$php_file_dir = dirname(@$trace[$i]['file']).'/';
			else
				$php_file_dir = '/unknown/';

			if(file_exists($php_file_dir.$wo_xfile_prefix))
			{
				$caller_path = $php_file_dir;
				break;
			}
		}

		$dirname = dirname($wo_xfile_prefix);
		if($dirname == '.' && ($object = @$data['this']))
			$dirname = dirname($object->real_class_file());

		if(!preg_match("!^\w+:!", $dirname))
			$dirname = "xfile:$dirname";
		if(!($dir_names = $smarty->getTemplateVars('template_dirnames')))
			$dir_names = array();
		array_unshift($dir_names, $dirname);
		array_unshift($dir_names, $caller_path);

		$smarty->assign("template_dirnames", $dir_names);

		$smarty->assign('me', bors()->user());
		$smarty->assign("main_uri", empty($GLOBALS['main_uri']) ? NULL : $GLOBALS['main_uri']);

		// Снести в пользу render_page(), наверное.
		if(!$smarty->templateExists($template))
			$template = self::find_template($template, @$data['this']);

		if(config('debug.execute_trace'))
			bors_debug::execute_trace("smarty3->fetch()");

		$smarty->error_reporting = E_ALL & ~E_NOTICE;
		$result = $smarty->fetch($template);
		$dir_names = $smarty->getTemplateVars('template_dirnames');
		array_shift($dir_names);
		array_shift($dir_names);

		$smarty->assign("template_dirnames", $dir_names);
		return $result;
	}
83065
public function productDataAccess($params, &$smarty)
    {
        $productId = $this->getRequest()->get('product_id');

        if ($productId !== null) {
            return $this->dataAccessWithI18n(
                "Product",
                $params,
                ProductQuery::create()->filterByPrimaryKey($productId)
            );
        }

        return '';
    }
782540
public function folderDataAccess($params, &$smarty)
    {
        $folderId = $this->getRequest()->get('folder_id');

        if ($folderId === null) {
            $contentId = $this->getRequest()->get('content_id');

            if ($contentId !== null) {
                if (null !== $content = ContentQuery::create()->findPk($contentId)) {
                    $folderId = $content->getDefaultFolderId();
                }
            }
        }

        if ($folderId !== null) {
            return $this->dataAccessWithI18n(
                "Folder",
                $params,
                FolderQuery::create()->filterByPrimaryKey($folderId)
            );
        }

        return '';
    }
1102528
protected static function pluginUrl($params)
    {
        $result = '';
        if (!empty($params['route'])) {
            $route = $params['route'];
            unset($params['route']);
            $result = Url::toRoute($route, $params);
        } elseif (!empty($params['url'])) {
            $url = $params['url'];
            unset($params['url']);
            $result = Url::toRoute($url, $params);
        } else {
            $msg = __METHOD__ . ": text plugin '{{%url}}' must have 'route' or 'url' parameter."
                 . " Real params is " . var_export($params, true);
            Yii::error($msg);
        }
        return $result;
    }
400794
public static function query(array $params = null, $useGet = false)
    {
        if ($useGet)
        {
            if (null === $params)
            {
                $params = $_GET;
            }
            else
            {
                $params = Arr::merge($_GET, $params);
            }
        }

        if (empty($params))
        {
            return '';
        }

        $query = http_build_query($params, '', '&');
        return ($query === '') ? '' : ('?' . $query);
    }
797662
private function buildQueryString(array $params)
    {
        $flattened = [];
        foreach ($params as $key => $value) {
            $flattened[] = $key . '=' . $value;
        }
        $queryString = implode('&', $flattened);

        return $queryString;
    }
1272616
public function get($smartCollectionId, array $params = array())
    {
        $endpoint = '/admin/smart_collections/'.$smartCollectionId.'.json';
        $response = $this->request($endpoint, 'GET', $params);
        return $this->createObject(SmartCollection::class, $response['smart_collection']);
    }
731625
public static function generateSign(array $params): string
    {
        $privateKey = self::$instance->private_key;

        if (is_null($privateKey)) {
            throw new InvalidConfigException('Missing Alipay Config -- [private_key]');
        }

        if (Str::endsWith($privateKey, '.pem')) {
            $privateKey = openssl_pkey_get_private($privateKey);
        } else {
            $privateKey = "-----BEGIN RSA PRIVATE KEY-----\n".
                wordwrap($privateKey, 64, "\n", true).
                "\n-----END RSA PRIVATE KEY-----";
        }

        openssl_sign(self::getSignContent($params), $sign, $privateKey, OPENSSL_ALGO_SHA256);

        $sign = base64_encode($sign);

        Log::debug('Alipay Generate Sign', [$params, $sign]);

        return $sign;
    }
70799
public function createUrl($params=array())
    {
        return Yii::app()->createUrl($this->route, CMap::mergeArray($params, $this->evaluateParams($this->params)));
    }
180141
public static function makeUrl(array $params): string
    {
        $href = [];

        foreach ($params as $key => $value) {
            $href[] = static::makeParam($key, (string)$value);
        }

        return '?' . implode('&', $href);
    }
988201
public static function queryString($params, $parent = null, $callback = 'rawurlencode', $ignoreNonValues = true)
    {
        $params = self::flattenRequestVars($params, $parent);
        $ret = [];
        foreach ($params as $pair) {
            list($name, $value) = $pair;
            if (!$value && $ignoreNonValues) {
                continue;
            }
            if ($callback) {
                $value = call_user_func($callback, $value);
            }
            $ret[] = sprintf('%s=%s', $name, $value);
        }
        return implode('&', $ret);
    }
512252
public static function load(Smarty $smarty, $type)
    {
        // try smarty's cache
        if (isset($smarty->_cache['resource_handlers'][$type])) {
            return $smarty->_cache['resource_handlers'][$type];
        }

        // try registered resource
        if (isset($smarty->registered_resources[$type])) {
            return $smarty->_cache['resource_handlers'][$type] =
                $smarty->registered_resources[$type] instanceof Smarty_Resource ? $smarty->registered_resources[$type] :
                    new Smarty_Internal_Resource_Registered();
        }

        // try sysplugins dir
        if (isset(self::$sysplugins[$type])) {
            $_resource_class = 'Smarty_Internal_Resource_' . ucfirst($type);
            return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
        }

        // try plugins dir
        $_resource_class = 'Smarty_Resource_' . ucfirst($type);
        if ($smarty->loadPlugin($_resource_class)) {
            if (class_exists($_resource_class, false)) {
                return $smarty->_cache['resource_handlers'][$type] = new $_resource_class();
            } else {
                $smarty->registerResource($type,
                                          array("smarty_resource_{$type}_source", "smarty_resource_{$type}_timestamp",
                                                "smarty_resource_{$type}_secure", "smarty_resource_{$type}_trusted"));
                // give it another try, now that the resource is registered properly
                return self::load($smarty, $type);
            }
        }

        // try streams
        $_known_stream = stream_get_wrappers();
        if (in_array($type, $_known_stream)) {
            // is known stream
            if (is_object($smarty->security_policy)) {
                $smarty->security_policy->isTrustedStream($type);
            }
            return $smarty->_cache['resource_handlers'][$type] = new Smarty_Internal_Resource_Stream();
        }

        // TODO: try default_(template|config)_handler

        // give up
        throw new SmartyException("Unknown resource type '{$type}'");
    }
1356878
public function form_fieldset($params, $content, $smarty, &$repeat) {
        //$content is null when repeat is true and has block content when repeat is false
        if ($repeat) {
            $attributes = isset($params['attrs']) ? $params['attrs'] : array();
            $legend = isset($params['legend']) ? $params['legend'] : null;
            return Form::fieldset_open($attributes, $legend);
        } else {
            return $content . Form::fieldset_close();
        }
    }