/** * @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 validate($data) { if (empty($data) or !is_array($data)) { throw new InvalidArgumentException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_REWARDS")); } $filter = JFilterInput::getInstance(); $params = JComponentHelper::getParams("com_crowdfunding"); /** @var $params Joomla\Registry\Registry */ // Create a currency object. $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $params->get("project_currency")); // Create the object "amount". $amount = new Crowdfunding\Amount($params); $amount->setCurrency($currency); foreach ($data as $key => $item) { $item["amount"] = $amount->setValue($item["amount"])->parse(); // Filter data if (!is_numeric($item["amount"])) { $item["amount"] = 0; } $item["title"] = $filter->clean($item["title"], "string"); $item["title"] = Joomla\String\String::trim($item["title"]); $item["title"] = Joomla\String\String::substr($item["title"], 0, 128); $item["description"] = $filter->clean($item["description"], "string"); $item["description"] = Joomla\String\String::trim($item["description"]); $item["description"] = Joomla\String\String::substr($item["description"], 0, 500); $item["number"] = (int) $item["number"]; $item["delivery"] = Joomla\String\String::trim($item["delivery"]); $item["delivery"] = $filter->clean($item["delivery"], "string"); if (!empty($item["delivery"])) { $date = new JDate($item["delivery"]); $unixTime = $date->toUnix(); if ($unixTime < 0) { $item["delivery"] = ""; } } if (!$item["title"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_TITLE")); } if (!$item["description"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DESCRIPTION")); } if (!$item["amount"]) { throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_AMOUNT")); } $data[$key] = $item; } return $data; }
/** * 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); } }
/** * @param $string * @return array */ function Internal_AutoDetectURLs($string) { $search = preg_split('/(?xi) \\b ( (?: (?:https?|ftp):\\/\\/ | www\\d{0,3}\\. | mailto: | (?:[a-zA-Z0-9._-]{2,}@) ) (?: [^\\s()<>]+ | \\((?:[^\\s()<>]+|(\\(?:[^\\s()<>]+\\)))*\\) )+ (?: \\((?:[^\\s()<>]+|(\\(?:[^\\s()<>]+\\)))*\\) | [^\\s`!()\\[\\]{};:\'"\\.,<>?«»“”‘’] ) )/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE); $output = array(); foreach ($search as $index => $token) { if ($index & 1) { if (preg_match("/^(https?|ftp|mailto):/ui", $token)) { // Protocol has been provided, so just use it as-is. $url = $token; } else { // Add scheme to emails and raw domain URLs. $url = (strpos($token, '@') ? 'mailto:' : 'http://') . $token; } // Never start URL from the middle of text (except for punctuation). $invalid = preg_match('#[^\\s`!()\\[\\]{};\'"\\.,<>?«»“”‘’]$#u', $search[$index - 1]); $invalid |= !$this->IsValidURL($url, true); // We have a full, complete, and properly-formatted URL, with protocol. // Now we need to apply the $this->url_pattern template to turn it into HTML. $params = Joomla\String\String::parse_url($url); if (!$invalid && substr($url, 0, 7) == 'mailto:') { $email = Joomla\String\String::substr($url, 7); if ($this->canCloakEmail($params)) { $output[$index] = JHtml::_('email.cloak', $email, $this->IsValidEmail($email)); } else { $output[$index] = $email; } } elseif ($invalid || empty($params['host']) || !empty($params['pass'])) { $output[$index - 1] .= $token; $output[$index] = ''; } else { $params['url'] = $url; $params['link'] = $url; $params['text'] = $token; $output[$index] = $this->FillTemplate($this->url_pattern, $params); } } else { $output[$index] = $token; } } return $output; }
/** * @return string */ protected function buildWhere() { $db = JFactory::getDBO(); $querystrings = array(); foreach ($this->getSearchWords() as $searchword) { $searchword = $db->escape(Joomla\String\String::trim($searchword)); if (empty($searchword)) { continue; } $not = ''; $operator = ' OR '; if (substr($searchword, 0, 1) == '-' && strlen($searchword) > 1) { $not = 'NOT'; $operator = 'AND'; $searchword = Joomla\String\String::substr($searchword, 1); } if (!$this->getState('query.titleonly')) { $querystrings[] = "(t.message {$not} LIKE '%{$searchword}%' {$operator} m.subject {$not} LIKE '%{$searchword}%')"; } else { $querystrings[] = "(m.subject {$not} LIKE '%{$searchword}%')"; } } //User searching $username = $this->getState('query.searchuser'); if ($username) { if ($this->getState('query.exactname') == '1') { $querystrings[] = "m.name LIKE '" . $db->escape($username) . "'"; } else { $querystrings[] = "m.name LIKE '%" . $db->escape($username) . "%'"; } } $time = 0; switch ($this->getState('query.searchdate')) { case 'lastvisit': $time = KunenaFactory::GetSession()->lasttime; break; case 'all': break; case '1': case '7': case '14': case '30': case '90': case '180': case '365': $time = time() - 86400 * intval($this->getState('query.searchdate')); //24*3600 break; default: $time = time() - 86400 * 365; } if ($time) { if ($this->getState('query.beforeafter') == 'after') { $querystrings[] = "m.time > '{$time}'"; } else { $querystrings[] = "m.time <= '{$time}'"; } } $topic_id = $this->getState('query.topic_id'); if ($topic_id) { $querystrings[] = "m.id = '{$topic_id}'"; } return implode(' AND ', $querystrings); }