/** * @param null $url */ function save($url = null) { if (!JSession::checkToken('post')) { $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error'); $this->setRedirect(KunenaRoute::_($this->baseurl, false)); return; } $properties = $this->config->getProperties(); //Todo: fix depricated value foreach (JRequest::get('post', JREQUEST_ALLOWHTML) as $postsetting => $postvalue) { if (\Joomla\String\String::strpos($postsetting, 'cfg_') === 0) { //remove cfg_ and force lower case if (is_array($postvalue)) { $postvalue = implode(',', $postvalue); } $postname = \Joomla\String\String::strtolower(\Joomla\String\String::substr($postsetting, 4)); // No matter what got posted, we only store config parameters defined // in the config class. Anything else posted gets ignored. if (array_key_exists($postname, $properties)) { $this->config->set($postname, $postvalue); } } } $this->config->save(); $this->app->enqueueMessage(JText::_('COM_KUNENA_CONFIGSAVED')); if (empty($url)) { $this->setRedirect(KunenaRoute::_($this->kunenabaseurl, false)); return; } $this->setRedirect(KunenaRoute::_($url, false)); }
/** * Returns an array of options * * @param string $sql SQL with 'ordering' AS value and 'name field' AS text * @param integer $chop The length of the truncated headline * * @return array An array of objects formatted for JHtml list processing * * @since 11.1 */ public static function genericordering($sql, $chop = 30) { $db = Factory::getDbo(); $options = array(); $db->setQuery($sql); $items = $db->loadObjectList(); if (empty($items)) { $options[] = Html::_('select.option', 1, Text::_('JOPTION_ORDER_FIRST')); return $options; } $options[] = Html::_('select.option', 0, '0 ' . Text::_('JOPTION_ORDER_FIRST')); for ($i = 0, $n = count($items); $i < $n; $i++) { $items[$i]->text = Text::_($items[$i]->text); if (String::strlen($items[$i]->text) > $chop) { $text = String::substr($items[$i]->text, 0, $chop) . "..."; } else { $text = $items[$i]->text; } $options[] = Html::_('select.option', $items[$i]->value, $items[$i]->value . '. ' . $text); } $options[] = Html::_('select.option', $items[$i - 1]->value + 1, $items[$i - 1]->value + 1 . ' ' . Text::_('JOPTION_ORDER_LAST')); return $options; }
/** * Small helper function to get the first char of the transmitted string which is needed to create the alpha index * * @param string $value * * @return string - First character of the passed string */ private function firstCharAlphaIndex($value) { return String::substr($value, 0, 1); }
/** * Takes a long string and breaks it into natural chunks and returns an array with the chunks * - The method will attempt to break on certain html tags first, then sentence structures and finally spaces if possible * - If $string is shorter than $maxChunkLength an array with one entry is returned * * @param string $string String to chunk * @param int $maxChunkLength Maximum chunk length * * @return array */ public static function chunkHTMLString($string, $maxChunkLength) { $chunks = array(); //If the given string can fit in the first chunk then just return that if (\Joomla\String\String::strlen($string) < $maxChunkLength) { $chunks[] = $string; return $chunks; } $cutStrings = array(); $cutStrings[] = '</div>'; $cutStrings[] = '</p>'; $cutStrings[] = '</ul>'; $cutStrings[] = '</table>'; $cutStrings[] = '</a>'; $cutStrings[] = '. '; while (\Joomla\String\String::strlen($string) > $maxChunkLength) { //Look for the breakpoint that is located last in the substring that is less than max $potentialCutPoints = array(); foreach ($cutStrings as $key => $cutString) { $position = strripos(substr($string, 0, $maxChunkLength), $cutString); if ($position !== false) { $potentialCutPoints[$position] = $cutString; } } //Select the right most breakpoint if (count($potentialCutPoints)) { $selectedBreakPoint = max(array_keys($potentialCutPoints)); $selectedBreakPointString = $potentialCutPoints[$selectedBreakPoint]; $breakPoint = $selectedBreakPoint + utf8_strlen($selectedBreakPointString); //Add the chunk $chunks[] = \Joomla\String\String::substr($string, 0, $breakPoint); } else { //Unable to find a breakpoint, use wordwrap $wordWrappedString = wordwrap($string, $maxChunkLength, '|||---NENO---|||', true); $wordWrappedArray = explode('|||---NENO---|||', $wordWrappedString); $chunks[] = $wordWrappedArray[0]; $breakPoint = \Joomla\String\String::strlen($wordWrappedArray[0]) + 3; } //Reduce the string $string = \Joomla\String\String::substr($string, $breakPoint); } //Add the remainder to the last chunk $chunks[] = $string; return $chunks; }
/** * Abridges text strings over the specified character limit. The * behavior will insert an ellipsis into the text replacing a section * of variable size to ensure the string does not exceed the defined * maximum length. This method is UTF-8 safe. * * For example, it transforms "Really long title" to "Really...title". * * Note that this method does not scan for HTML tags so will potentially break them. * * @param string $text The text to abridge. * @param integer $length The maximum length of the text (default is 50). * @param integer $intro The maximum length of the intro text (default is 30). * * @return string The abridged text. * * @since 11.1 */ public static function abridge($text, $length = 50, $intro = 30) { // Abridge the item text if it is too long. if (StringString::strlen($text) > $length) { // Determine the remaining text length. $remainder = $length - ($intro + 3); // Extract the beginning and ending text sections. $beg = StringString::substr($text, 0, $intro); $end = StringString::substr($text, StringString::strlen($text) - $remainder); // Build the resulting string. $text = $beg . '...' . $end; } return $text; }
/** * Return part of a string without break words. * * <code> * $offset = 0; * $length = 25; * $content = "If you can dream it, you can do it." * * $string = new Prism\String(); * $string->substr($offset, $length); * * echo $string; * </code> * * @param integer $offset * @param integer $length * * @return self */ public function substr($offset, $length) { $pos = JString::strpos($this->content, ' ', $length); $this->content = JString::substr($this->content, $offset, $pos); return $this; }