/** * 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); }
private function &_widgetTextArea(&$field, $args) { HTML_QuickForm::registerElementType('wikiarea', 'HTML/QuickForm/wikiarea.php', 'HTML_QuickForm_wikiarea'); $id = $field['id']; $element =& $this->_addElement('wikiarea', $id, array('class' => 'expand')); if (!empty($args)) { $rules = explode(',', $args); } elseif (array_key_exists('wiki_rules', $field)) { // DEPRECATED use of "wiki_rules" option instead of "widget_args" $rules = explode(',', $field['wiki_rules']); } else { $rules = null; } $element->setWiki(TIP_Renderer::getWiki($rules)); $element->setCols($this->text_cols); $element->setRows($this->text_rows); return $element; }