private static function _renderRow($row, $options = null) { $id = TIP::toHtml($row['id']); $description = TIP::toHtml($row['description']); $src = TIP::toHtml($row['thumbnail']); $width = (int) $row['thumbnail_width']; $height = (int) $row['thumbnail_height']; $attrs = 'href="' . $id . '"'; empty($description) || ($attrs .= ' title="' . $description . '"'); isset($options['class']) && ($attrs .= ' class="' . $options['class'] . '"'); if (isset($options['max-width']) && $width > $options['max-width']) { $options['max-width'] = $width; } if (isset($options['max-height']) && $height > $options['max-height']) { $options['max-height'] = $height; } return "<a {$attrs}><img src=\"{$src}\" width=\"{$width}\" height=\"{$height}\" alt=\"{$description}\" /></a>\n"; }
/** * The "main" function * * The starting point of the TIP system. This must be called somewhere from * your index.php. */ public function go() { // Configure the locale $locale_module = $this->shared_modules['locale']; if (TIP::setLocaleId(TIP::getOption($locale_module, 'locale'))) { date_default_timezone_set(TIP::getOption($locale_module, 'timezone')); } // Executes the action if ($this->_request['module'] && $this->_request['action']) { if (is_null($module =& TIP_Type::getInstance($this->_request['module'], false))) { TIP::notifyError('module'); } else { if (isset($this->_request['id'])) { // Now the module is loaded: force id type casting $id_type = $module->getProperty('id_type'); isset($id_type) || ($id_type = 'integer'); settype($this->_request['id'], $id_type); $this->keys['ID'] = $this->_request['id']; } if (is_null($module->callAction($this->_request['action']))) { TIP::notifyError(is_null(TIP::getUserId()) ? 'reserved' : 'denied'); } } } elseif ($this->_request['module']) { TIP::notifyError('noaction'); } elseif ($this->_request['action']) { TIP::notifyError('nomodule'); } elseif (TIP_AHAH) { // AHAH request without module/action specified: perform a test $this->content = "<pre>\n" . TIP::toHtml(print_r($_SERVER, true)) . "\n</pre>\n"; } if (TIP_AHAH) { // AHAH request: output the page and return header('Content-Type: application/xml'); echo $this->content; return; } // Generates the page: body must be called before the head because // some head tags can be modified by body templates $body = $this->tagRun($this->body_template); echo str_replace('{locale}', TIP::getLocaleId('-'), $this->incipit); $this->run($this->head_template); echo $body . $this->explicit; $this->_session_started && HTTP_Session2::pause(); }
/** * Get a partial content of a wiki field * * $params must be a string in the form "field_id[,len[,wordlen]]", where * id is the id of a wiki field, len is the number of characters to be * echoed and wordlen is the maximum length of a single word. * len defaults to 100 while wordlen defaults to 25. */ protected function tagPartialWiki($params) { @(list($field_id, $max, $max_word) = explode(',', $params)); if (empty($field_id) || is_null($value = $this->getField($field_id))) { TIP::error("no valid field found ({$params})"); return null; } $fields =& $this->data->getFields(); if (!array_key_exists($field_id, $fields)) { // Field not found $this->data: it is probably a joined field $rules = null; } else { $field =& $fields[$field_id]; // Get the wiki rules if (array_key_exists('widget_args', $field)) { $rules = explode(',', $field['widget_args']); } elseif (array_key_exists('wiki_rules', $field)) { // DEPRECATED: now use "widget_args" instead of "wiki_rules" option $rules = explode(',', $field['wiki_rules']); } else { $rules = null; } } $max > 0 || ($max = 100); $max_word > 0 || ($max_word = 25); $text = TIP_Renderer::getWiki($rules)->transform($value, 'Plain'); // Ellipsize the words too big $text_len = -1; // Do not consider the first space delimiter $token_list = array(); $token = strtok($text, " \n\t"); while ($text_len < $max && $token !== false) { $token_len = mb_strlen($token); if ($token_len > $max_word) { $token = mb_substr($token, 0, $max_word - 3) . '...'; $token_len = $max_word; } $text_len += $token_len + 1; $token_list[] = $token; $token = strtok(" \n\t"); } $text_len > 0 || ($text_len = 0); $text = implode(' ', $token_list); $text_len < $max || ($text = mb_substr($text, 0, $max - 3) . '...'); return TIP::toHtml($text); }
/** * Build a relative action URI * * $params is a string in the form "action[,id[,param1=value1,param2=value2,...]]" * The module name can be overriden specifying it as module=... */ protected function tagActionUri($params) { return TIP::toHtml(TIP::buildActionUriFromTag($params, $this->id)); }
/** * Convert to HTML a value * * Converts the $value content in HTML safe manner, according to its type. * * @param mixed $value The value to convert * @return string The converted value */ public static function toHtml($value) { if (is_bool($value)) { return $value ? 'true' : 'false'; } elseif (is_numeric($value)) { return (string) $value; } elseif (is_string($value)) { return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); } elseif (is_array($value)) { // Canonicalize the name return TIP::toHtml(implode(',', $value)); } return ''; }
function renderEntry($node, $level, $type) { $this->_name_stack[$level] = $node['title']; $name = implode($this->_glue, $this->_name_stack); $is_container = array_key_exists('sub', $node); // Array rendering if ($is_container && $this->_array_mode & 1 || !$is_container && $this->_array_mode & 2) { $this->_rows[$node['id']] = $name; } // Check for maximum level $is_deep = isset($this->_levels) && $level >= $this->_levels; $is_active = $type != HTML_MENU_ENTRY_INACTIVE; if ($is_deep && $level > $this->_levels + 1 || $is_deep && $level > $this->_levels && !$is_active && !end($this->_html[$level - 1]['active'])) { return; } // Verify if the current/active row is a container if ($is_active) { $this->_is_current_container = $is_container; } // Generate the XHTML content $content = $node['title']; $indent = str_repeat(' ', $level); isset($node['ITEMS']) && ($content .= ' (' . $node['ITEMS'] . ')'); $content = htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); isset($node['COUNT']) && ($content = ' <var>' . $node['COUNT'] . ' </var>' . $content); $is_active && ($content = '<strong>' . $content . '</strong>'); if ($is_container) { // <em> for containers $content = '<em>' . $content . '</em>'; $is_deep && !$is_active && ($content = '<a href="' . TIP::toHtml($node['url']) . '">' . $content . '</a>'); } else { // Compute the tooltip, if defined isset($node['ITEMS']) && ($content .= ' (' . $node['ITEMS'] . ')'); if (array_key_exists('tooltip', $node)) { $tooltip = '" title="' . htmlspecialchars($node['tooltip'], ENT_QUOTES, 'UTF-8'); } else { $tooltip = ''; } // Use <span> for normal entries $content = '<a href="' . TIP::toHtml($node['url']) . $tooltip . '"><span>' . $content . '</span></a>'; } $content = "\n{$indent} <li>{$content}"; // Close previous <li> for non-starting entries isset($this->_html[$level]) && ($content = '</li>' . $content); if (isset($this->_html[$level])) { $this->_html[$level]['active'][] = $is_active; $this->_html[$level]['content'] .= $content; } else { $this->_html[$level] = array('active' => array($is_active), 'content' => $content); } }
/** * Get the privilege description * * Expands to the specified privilege description, in the current locale. * In $params you must specify the privilege as 'module_id,privilege', * where privilege must be manager|admin|trusted|untrusted|none. */ protected function tagPrivilegeDescription($params) { global $cfg; list($module, $privilege) = explode(',', $params); $prefixes = array_reverse($cfg[$module]['type']); isset($cfg[$module]['locale_prefix']) && array_unshift($prefixes, $cfg[$module]['locale_prefix']); foreach ($prefixes as $prefix) { $description = TIP::getLocale($privilege, $prefix); if (!empty($description)) { return TIP::toHtml($description); } } TIP::warning("localized privilege description not found ({$params})"); return null; }