/** * @param $txt * @param int $len * * @return mixed|string|void */ public static function parseText($txt, $len = 0) { if (!$txt) { return; } if ($len && Joomla\String\String::strlen($txt) > $len) { $txt = Joomla\String\String::substr($txt, 0, $len) . ' ...'; } $txt = self::escape($txt); $txt = preg_replace('/(\\S{30})/u', '\\1​', $txt); $txt = self::prepareContent($txt, 'title'); return $txt; }
public function onAfterPost($message) { if (Joomla\String\String::strlen($message->message) > $this->params->get('activity_points_limit', 0)) { $this->assignPoints('thread.new'); } if (Joomla\String\String::strlen($message->message) > $this->params->get('activity_badge_limit', 0)) { $this->assignBadge('thread.new', JText::_('PLG_KUNENA_EASYSOCIAL_BADGE_NEW_TITLE')); } $stream = FD::stream(); $tmpl = $stream->getTemplate(); $tmpl->setActor($message->userid, SOCIAL_TYPE_USER); $tmpl->setContext($message->thread, 'kunena'); $tmpl->setVerb('create'); $tmpl->setAccess('core.view'); $stream->add($tmpl); }
/** * Upload file by passing it by HTML input * * @param array $fileInput The file object returned by JInput * @param string $destination The path of destination of file uploaded * @param string $type The type of file uploaded: attachment or avatar * * @return object */ public function upload($fileInput, $destination, $type = 'attachment') { $file = new stdClass(); $file->ext = JFile::getExt($fileInput['name']); $file->size = $fileInput['size']; $file->tmp_name = $fileInput['tmp_name']; $file->error = $fileInput['error']; $file->destination = $destination . '.' . $file->ext; $file->success = false; $file->isAvatar = false; if ($type != 'attachment') { $file->isAvatar = true; } if (!is_uploaded_file($file->tmp_name)) { $exception = $this->checkUpload($fileInput); if ($exception) { throw $exception; } } elseif ($file->error != 0) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_NOT_UPLOADED'), 500); } // Check if file extension matches any allowed extensions (case insensitive) foreach ($this->validExtensions as $ext) { $extension = Joomla\String\String::substr($file->tmp_name, -Joomla\String\String::strlen($ext)); if (Joomla\String\String::strtolower($extension) == Joomla\String\String::strtolower($ext)) { // File must contain one letter before extension $name = Joomla\String\String::substr($file->tmp_name, 0, -Joomla\String\String::strlen($ext)); $extension = Joomla\String\String::substr($extension, 1); if (!$name) { throw new RuntimeException(JText::sprintf('COM_KUNENA_UPLOAD_ERROR_EXTENSION_FILE', implode(', ', $this->validExtensions)), 400); } } } if (!$this->checkFileSize($file->size, true)) { if ($file->isAvatar) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_AVATAR_EXCEED_LIMIT_IN_CONFIGURATION'), 500); } else { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_FILE_EXCEED_LIMIT_IN_CONFIGURATION'), 500); } } if (!KunenaFile::copy($file->tmp_name, $file->destination)) { throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_FILE_RIGHT_MEDIA_DIR'), 500); } unlink($file->tmp_name); KunenaPath::setPermissions($file->destination); $file->success = true; return $file; }
/** * @param $description */ public function setDescription($description) { if ($this->inLayout) { throw new LogicException(sprintf('HMVC template should not call %s::%s()', __CLASS__, __FUNCTION__)); } if (!$this->state->get('embedded')) { // TODO: allow translations/overrides $lang = JFactory::getLanguage(); $length = Joomla\String\String::strlen($lang->getName()); $length = 137 - $length; if (Joomla\String\String::strlen($description) > $length) { $description = Joomla\String\String::substr($description, 0, $length) . '...'; } $this->document->setMetadata('description', $description); } }
/** * @return array */ public function getSearchWords() { // Accept individual words and quoted strings $splitPattern = '/[\\s,]*\'([^\']+)\'[\\s,]*|[\\s,]*"([^"]+)"[\\s,]*|[\\s,]+/u'; $searchwords = preg_split($splitPattern, $this->getState('searchwords'), 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $result = array(); foreach ($searchwords as $word) { // Do not accept one letter strings if (Joomla\String\String::strlen($word) > 1) { $result[] = $word; } } return $result; }