/** * Converts a UID to a Username, with no link * * @param int $userId * @return string */ public function username($userId) { try { $user = $this->_ugmanager->getUser($userId); return zula_htmlspecialchars($user['username']); } catch (Ugmanager_UserNoExist $e) { return t('Unknown User', I18n::_DTD); } }
/** * hook: 'cntrlr_error_output' * Provides 'Wiki like' functionaility for the Page module * * @param int $statusCode * @param string $output * @return string */ public function hookCntrlrErrorOutput($statusCode, $output) { if ($statusCode == 404 && Module::exists('page') && !Module::isDisabled('page') && $this->_acl->checkMulti(array('page_manage', 'aliases_add'), ACL::_MULTI_ALL)) { $alias = $this->_router->getRequestPath(); if (trim($alias)) { $msgStr = t('This page can be <a href="%1$s">created</a> with an alias of <strong>"%2$s"</strong>, simply <a href="%1$s">add this page</a> now.', _PROJECT_ID . '-page'); $output .= '<h3>' . t('Create this Page', _PROJECT_ID . '-page') . '</h3>'; $output .= sprintf('<p>' . $msgStr . '</p>', $this->_router->makeUrl('page', 'config', 'add', null, array('qe' => 'true', 'alias' => base64_encode($alias))), zula_htmlspecialchars($alias)); } } return $output; }
/** * Handles the storing of all event messages. If within CLI mode * then the event message will be displayed directly to stdout. * * @param string $type * @param string $msg * @return bool */ protected function handle($type, $msg) { $zulaMode = $this->_zula->getMode(); if ($zulaMode == 'normal') { $this->_log->message('(' . $type . ') ' . $msg, Log::L_EVENT); $_SESSION['event_feedback'][$type][] = zula_htmlspecialchars($msg); } else { if ($zulaMode == 'cli') { fwrite($type == 'error' ? STDERR : STDOUT, ":: ({$type}) {$msg}\n"); } } return true; }
/** * Builds up a string request path to be used * * @param string $separator * @param string $type * @param bool $noBase * @return string */ public function make($separator = '&', $type = null, $noBase = false) { $data = array(); foreach ($this->parsed as $key => $val) { if ($key == 'arguments' || $key == 'siteType' && $val == $this->_router->getDefaultSiteType()) { continue; } else { if ($key != 'siteType' && $val == null) { $val = 'index'; } } $data[$key] = $val; } $arguments = $this->parsed['arguments']; $argString = ''; if (empty($arguments)) { // No need to keep empty parts on while (end($data) == 'index') { array_pop($data); } } else { foreach ($arguments as $key => $val) { $argString .= '/' . $key . '/' . $val; } } $requestPath = trim(implode('/', $data), '/') . $argString; # hook event: router_make_url $tmpRp = Hooks::notifyAll('router_make_url', $requestPath); if (is_array($tmpRp)) { $requestPath = trim(end($tmpRp), '/'); } $requestPath = zula_htmlspecialchars($requestPath); // Create the correct URL based upon router type if (!$type) { $type = $this->_router->getType(); } unset($this->queryStringArgs['url']); if ($type == 'standard') { // Add in the 'url' query string needed, force it to be first index if ($requestPath) { $this->queryStringArgs = array_merge(array('url' => $requestPath), $this->queryStringArgs); } if ($this->_input->has('get', 'ns')) { $this->queryStringArgs['ns'] = ''; } $url = $noBase ? 'index.php' : _BASE_DIR . 'index.php'; } else { $url = $noBase ? $requestPath : _BASE_DIR . $requestPath; } if (!empty($this->queryStringArgs)) { $url .= '?' . str_replace('%2F', '/', http_build_query($this->queryStringArgs, null, $separator)); } return $this->fragment ? $url . '#' . $this->fragment : $url; }
/** * Main method for parsing the text * * @param bool $break * @return string */ public function parse($break = false) { $text = preg_replace_callback('#([A-Z][A-Z0-9+.\\-]+://|www\\.)[A-Z0-9][A-Z0-9.\\-]+\\.[A-Z0-9.\\-]+(:\\d+)?(/([^\\s\\r\\n]+)?)?#im', array($this, 'urlReplace'), zula_htmlspecialchars($this->breakText($break))); return zula_nls2p($text); }
/** * Provides the Zula Framework with Language Support for View Files * It searches the view file via reg-ex to find all tags that in the format * of {L_[Phrase]} and fills a new array which each of the new tags and langauge string * It also updates the text domain to the current module, if we have one set. * then resets it back afterwards * * @param string $content * @return array */ protected function languageTags($content) { if (!empty($this->module)) { // Bind the text domain and set the domain to use $domain = _PROJECT_ID . '-' . $this->module; $this->_i18n->bindTextDomain($domain, $this->_zula->getDir('locale')); $this->_i18n->textDomain($domain); } // Gather all languages tags preg_match_all('#{L_\\[(.*?)\\](?=})#', $content, $tags); if (!empty($tags[0])) { $languageTags = array(); foreach ($tags[0] as $key => $tag) { $tag = trim($tag, '{} '); // The following t() is allowed, as the actual string is pulled straight from the view file $value = zula_htmlspecialchars(t($tags[1][$key])); $languageTags[$tag] = $value; } // Restore the text domain back $this->_i18n->textDomain(I18n::_DTD); return $languageTags; } else { return array(); } }
/** * Builds 'input' elements of type checkbox * * @param string name * @param string $default * @param array $options * @return string */ public function checkbox($name, $default = null, array $options = array()) { $optionCount = count($options); $format = '<input type="checkbox" id="%1$s" name="%2$s[]" %3$s value="%4$s"> <label class="horizontal" for="%1$s">%5$s</label>'; $output = ''; $i = 1; foreach ($options as $key => $val) { $checked = in_array($val, (array) $default) ? 'checked="checked"' : ''; $val == is_bool($val) ? zula_bool2str($val) : zula_htmlspecialchars($val); $output .= sprintf($format, uniqid('html_'), $this->makeNameAttr($name), $checked, $val, zula_htmlspecialchars($key)); if ($i++ != $optionCount) { $output .= '<br>'; } } return $output; }
/** * Adds a new HTML tag into the 'head' of the HTML theme view * file. Extra Head elements are added through the {HEAD} tag. * * @param string $type * @param array $attrs Attributes for the tag * @param string $content * @return bool */ public function addHead($type, $attrs = array(), $content = null, $prepend = false) { if ($type == 'js' || $type == 'javascript') { $attrs['type'] = 'text/javascript'; $type = 'script'; } else { if ($type == 'css') { $attrs['type'] = 'text/css'; $attrs['rel'] = 'StyleSheet'; if (!isset($attrs['media'])) { $attrs['media'] = 'screen'; } $type = 'link'; } } // Build all of the attributes required $attrStr = ''; foreach ((array) $attrs as $attr => $val) { $attrStr .= $attr . '="' . zula_htmlspecialchars($val) . '" '; } $attrStr = rtrim($attrStr); switch ($type) { case 'script': $str = '<script ' . $attrStr . '>' . $content . '</script>'; break; case 'style': $str = '<style type="text/css" ' . $attrStr . '>' . $content . '</style>'; break; case 'meta': case 'link': $str = sprintf('<%1$s %2$s>', $type, $attrStr); break; default: trigger_error('Theme::addHead() provided type "' . $type . '" is unknown', E_USER_NOTICE); return false; } return $this->assignHtml(array('HEAD' => $str . "\r\n"), false, $prepend); }
/** * Builds the list items (<li>) elements for a menu category * with the provided items, recursively if need be. * * @param array $items * @return string */ protected function buildItems(array $items) { $requestPath = $this->_router->getRequestPath(); $rawRequestPath = $this->_router->getRawRequestPath(); $list = '<ul class="menu-category">' . "\n\t"; foreach ($items as $item) { $item['url'] = ltrim($item['url'], '/'); $class = 'menu-' . $item['id']; if ($item['url'] == $rawRequestPath || $item['url'] == $requestPath) { $class .= ' menu-current'; } // Create the correct URL for the menu item to use if ($item['url'] == 'admin') { $item['url'] = $this->_router->makeUrl('', '', '', 'admin'); } else { if ($item['url'] == false) { $item['url'] = $this->_router->makeUrl('', '', '', 'main'); } else { if (strpos($item['url'], 'www.') === 0) { $item['url'] = 'http://' . $item['url']; } else { if (!zula_url_has_scheme($item['url'])) { if ($item['url'][0] == '#') { $item['url'] = $this->_router->getCurrentUrl() . $item['url']; } else { if (strpos($item['url'], '/')) { $item['url'] = $this->_router->makeUrl($item['url']); } else { $item['url'] = $this->_router->makeUrl($item['url'], null, null, 'main'); } } } } } } // Gather children and append the list item $children = empty($item['children']) ? '' : $this->buildItems($item['children']); $list .= sprintf('<li class="%1$s"><a href="%2$s" title="%3$s">%4$s</a>%5$s</li>' . "\n", $class, $item['url'], zula_htmlspecialchars($item['attr_title'] ? $item['attr_title'] : $item['name']), zula_htmlspecialchars($item['name']), $children); } return $list . '</ul>'; }