/** * Compiles URL addressing current script of current application. * * @param array|false $parameters set of parameters to pass in query, false * to drop all current parameters (e.g. on creating GET form), * provide special parameter '*' in array to start fresh set of parameters * @param mixed $selector first of multiple optional selectors to include * @return string URL of addressed script including optional parameters */ public function selfURL($parameters = array(), $selector = null) { $selectors = func_get_args(); $selectors = array_slice($selectors, 1); if (!count($selectors)) { $selectors = application::current()->selectors; } /* * merge current script's input parameters with provided one */ if ($parameters === false) { $parameters = array(); } else { // find all non-persistent input parameters of current script $currentVolatileParameters = array(); if (!array_key_exists('*', $parameters)) { $get = input::source(input::SOURCE_ACTUAL_GET); foreach ($get->listNames() as $name) { if (data::isKeyword($name) && !input::isPersistent($name)) { $currentVolatileParameters[$name] = $get->getValue($name); } } } unset($parameters['*']); // merge volatile input with given parameters, but drop all those // finally set NULL (to support removal per $parameters) $parameters = array_filter(array_merge($currentVolatileParameters, $parameters), function ($item) { return $item !== null; }); } /* * utilize scriptURL() for referring to current script */ array_unshift($selectors, $parameters); array_unshift($selectors, $this->script); return call_user_func_array(array(&$this, 'scriptURL'), $selectors); }
public static final function getScopeParameter(&$domain, &$path) { // process focus selection $focus = config::get('session.focus', 'application'); switch ($focus) { case 'domain': // valid for whole current domain $domain = $_SERVER['HTTP_HOST']; $path = '/'; break; case 'txf': // valid for all applications in current installation, only $domain = $_SERVER['HTTP_HOST']; $path = '/' . txf::getContext()->prefixPathname; break; case 'application': // valid for current application, only $domain = $_SERVER['HTTP_HOST']; $path = '/' . application::current()->prefixPathname; break; default: // option is explicitly providing domain and path to focus if (strpos($focus, '%') !== false) { $focus = strtr($focus, array('%H' => $_SERVER['HTTP_HOST'], '%T' => '/' . txf::getContext()->prefixPathname, '%A' => '/' . application::current()->prefixPathname)); } $temp = explode('/', $focus); $domain = array_shift($temp); $path = '/' . implode('/', $temp); } }
public static function redirectTo($url) { if (func_num_args() > 1) { $url = call_user_func_array(array(__NAMESPACE__ . '\\context', 'scriptURL'), func_get_args()); } if (url::isRelative($url)) { $url = application::current()->relativePrefix($url); } header('Location: ' . $url); view::callDisableOutput(); exit; }
/** * Converts current set of items into multi-dimensional array containing * subordinated navigators' items as ordinary arrays as well. * * Additionally this method tries to detect active/selected items and * threads of navigator. * * @return array set items with subordinated items resolved to arrays */ protected function qualifyThread($depth = 1, &$selected) { $out = array('level' => intval($depth), 'items' => array()); foreach ($this->items as $name => $item) { if (@$item['label'] || $item['asset']) { // process attached sub navigator if (@$item['sub'] instanceof navigator) { // resolve that one's items $subselected = false; $item['sub'] = $item['sub']->qualifyThread($depth + 1, $subselected); // if resolving detected selected sub-item ... if ($subselected && !$selected) { // ... transfer related mark to caller $selected = true; // ... mark containing navigator as active one $out['active'] = 'active'; } } else { $item['sub'] = array('items' => array()); } // apply auto-detection of selected item if enabled and on haven't selected item before if (!$selected) { $detected = $this->detectSelected($item); if ($detected) { // current item is selected, thus mark if ($detected === true) { $item['selected'] = 'selected'; } else { $item['active'] = 'active'; } // and tell any containing navigator about having found selected item $selected = $detected; } } $item['action'] = application::current()->normalizeUrl($item['action']); $out['items'][$name] = $item; } } return $out; }
/** * Simplifies retrieval of compiled URLs to a selected script of current * application. * * In opposition to selfURL() $parameters must be array of parameters to * integrate into generated link for never being merged with existing input. * * @param string $scriptName name of script to refer to * @param array $parameters set of parameters to include in reference * @param string $selector one of several selectors to include in reference * @return string URL referring to selected script */ public static function scriptURL($scriptName, $parameters = array(), $selector = null) { $args = func_get_args(); return call_user_func_array(array(application::current(), 'scriptURL'), $args); }
/** * Renders HTML code of form. * * @return string generated HTML code */ public function getCode() { $method = $this->usePost ? 'post' : 'get'; $action = is_null($this->processorUrl) ? application::current()->selfUrl($this->usePost ? array() : false) : $this->processorUrl; $mime = $this->maxFileSize > 0 ? ' enctype="multipart/form-data"' : ''; $size = $this->maxFileSize > 0 ? '<input type="hidden" name="MAX_FILE_SIZE" value="' . $this->maxFileSize . "\"/>\n\t" : ''; $name = html::idname($this->name); $idName = $this->idName(); $idValue = $this->idValue(); $labelClass = 'without-labels'; // compile code of form's rows $template = self::getRowTemplate(); $rows = array_filter($this->rows, function ($row) { return !!count($row); }); if ($this->sortingOrder) { data::rearrangeArray($rows, $this->sortingOrder, true); } $rows = array_map(function ($row) use($template, &$labelClass) { if (@$row['label']) { $labelClass = 'with-labels'; } $label = view::wrapNotEmpty(@$row['label'], '', ''); $code = view::wrapNotEmpty(@$row['htmlCode'], '', ''); $hint = view::wrapNotEmpty(@$row['hint'], '<span class="hint">', "</span>\n"); $error = view::wrapNotEmpty(@$row['error'], '<span class="error">', "</span>\n"); $mandatory = @$row['mandatory'] ? config::get('html.form.mandatory', '<span class="mandatory">*</span>') : ''; if (trim($label) !== '') { $label = sprintf(config::get('html.form.label', '%s%s:'), $label, $mandatory); } return sprintf($template, trim('form-row-name-' . @$row['name'] . ' ' . @$row['class']), $label, $code, $error, $hint); }, $rows); // embed compiled rows in form's custom content $code = str_replace('%%%%ROWS_STACK%%%%', implode('', $rows), $this->code); $hidden = $this->enableXsrfMode ? "<input type=\"hidden\" name=\"{$idName}\" value=\"{$idValue}\"/>" : ''; foreach ($this->hidden as $key => $value) { if (is_array($value)) { foreach ($value as $subName => $subValue) { $hidden .= '<input type="hidden" name="' . html::inAttribute($key) . '[' . html::inAttribute($subName) . ']" value="' . html::inAttribute($subValue) . '"/>'; } } else { if ($value !== null) { $hidden .= '<input type="hidden" name="' . html::inAttribute($key) . '" value="' . html::inAttribute($value) . '"/>'; } } } $class = ' class="' . html::inAttribute(trim($this->class . ' ' . $labelClass)) . '"'; return <<<EOT <form action="{$action}" method="{$method}"{$mime} id="{$name}"{$class}> \t{$size}{$hidden} {$code} </form> EOT; }
public static function qualifyString($in, $values = null) { if (is_array($values)) { $cb = function ($matches) use($values) { $chunks = explode('::', $matches[1]); return array_key_exists($chunks[0], $values) ? $values[trim($chunks[0])] : $matches[1]; }; } else { $cb = function ($matches) use($values) { $chunks = explode('::', $matches[1]); switch (strtolower(trim($chunks[0]))) { case 'appdir': return application::current()->pathname; case 'appurl': return application::current()->scriptURL($chunks[1]); case 'date': return date($chunks[1], count($chunks) > 2 ? intval($chunks[2]) : time()); default: return ''; } }; } return preg_replace_callback('/\\{\\{([^}]+)\\}\\}/', $cb, $in); }