public function build($args, $useall = true, $noamp = false)
{
$named_args = $this->named_args;
// Direct call prints a PHP notice
$named_args_combined = array_flip(array_merge($named_args['required'], $named_args['optional']));
$args_defined = array_intersect_key($args, $named_args_combined);
$args = Plugins::filter('rewrite_args', $args, $this->name);
// Replace defined arguments with their value
$searches = array();
$replacements = array();
foreach ($named_args as $keys) {
foreach ($keys as $key) {
if (!empty($args[$key])) {
$searches[] = '/{\\$' . $key . '}/';
$replacements[] = str_replace('%2F', '%252F', urlencode($args[$key]));
}
}
}
// Remove undefined arguments
$searches[] = '/\\([^\\(\\)]*\\$+[^\\(\\)]*\\)/';
$replacements[] = '';
// Remove parens left from defined optional arguments
$searches[] = '/\\(|\\)/';
$replacements[] = '';
$return_url = preg_replace($searches, $replacements, $this->build_str);
// Append any remaining args as query string arguments
if ($useall) {
$args = array_diff_key($args, $named_args_combined);
$query_seperator = $noamp ? '&' : '&';
$return_url .= count($args) == 0 ? '' : '?' . http_build_query($args, '', $query_seperator);
}
return $return_url;
}