/** * @see BatchAttributeValueDataAnalyzer::analyzeByValue() */ protected function analyzeByValue($value) { if ($this->type == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME) { $compareValue = TextUtil::strToLowerWithDefaultEncoding($value); } else { $compareValue = $value; } if ($value != null && !in_array($compareValue, $this->acceptableValues)) { $this->messageCountData[static::INVALID]++; } }
public static function resolveAccountRelationLabel($type, $relationIdentifier) { assert('in_array($type, array("Singular", "SingularLowerCase"))'); assert('in_array($relationIdentifier, array("primary", "secondary"))'); switch ($type) { case 'Singular': return static::getSingularAccountRelationLabel($relationIdentifier); case 'SingularLowerCase': $string = static::getSingularAccountRelationLabel($relationIdentifier); return TextUtil::strToLowerWithDefaultEncoding($string); } }
/** * @param RedBean_OODBBean $rowBean */ public function analyzeByRow(RedBean_OODBBean $rowBean) { if ($this->mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME) { $compareValue = TextUtil::strToLowerWithDefaultEncoding($rowBean->{$this->columnName}); } else { $compareValue = $rowBean->{$this->columnName}; } if ($rowBean->{$this->columnName} != null && !in_array($compareValue, $this->getAcceptableValues())) { $label = Zurmo::t('ImportModule', 'Is an invalid user value. This value will be skipped during import.'); $this->analysisMessages[] = $label; } }
protected function setupMeta () { $numResults = number_format ($this->totalResults); $this->meta['subLogoText'] = ($this->searchType != 'search') ? CLUtil::getLabelForType ($this->searchType) . ' for sale' : TextUtil::getRandomPhrase (); $this->meta['h1'] = $this->searchOptions->displaySearchStr . (empty ($this->q) && $this->searchType != 'wtb' ? ' for sale on craigslist' : ''); $this->meta['h2-addon'] = '<a id="showCityDialogLink2" href="javascript: void (null)">search more cities</a>'; if (! empty ($this->q)) { $this->meta['h2'] = $numResults . " search results for \"{$this->searchOptions->displaySearchStr}\" from " . count ($this->searchOptions->cities) . ' craigslist cities'; } else { $this->meta['h2'] = $numResults . " results in " . CLUtil::getLabelForType ($this->searchOptions->type) . " from " . count ($this->searchOptions->cities) . ' craigslist cities'; } $this->meta['title'] = ($this->searchType != 'wtb') ? $this->searchOptions->displaySearchStr . ' for sale on craigslist' : 'WTB listings for ' . $this->searchOptions->displaySearchStr . ' on craigslist'; $this->meta['description'] = ($this->searchType != 'wtb') ? "$numResults search results from " . count ($this->searchOptions->cities) . " craigslist cities." : "$numResults WTB listings from " . count ($this->searchOptions->cities) . ' craigslist cities.'; $this->meta['description'] .= " Craig's Little Buddy helps you search craigslist. Search multiple cities, sort listings. Results updated constantly."; $this->meta['keywords'] = ($this->searchType != 'wtb') ? $this->searchOptions->displaySearchStr . ', for sale, craigslist, classifieds, classified ad' : $this->searchOptions->displaySearchStr . ', wtb, craigslist, classifieds, classified ads, want to buy'; if (empty ($this->q) && $this->searchOptions->type == 'search') { $this->meta['h2'] = $numResults . " search results from " . count ($this->searchOptions->cities) . ' craigslist cities'; $this->meta['h1'] = 'For Sale on Craigslist'; $this->meta['title'] = 'For Sale on Craigslist'; $this->meta['description'] = 'Classified listings on craigslist.'; $this->meta['keywords'] = 'search, for sale, craigslist, classifieds, classified ads'; } }
/** * sendMessage. * * @param string $message Params * @param object $data Params * * @return boolean */ public function sendMessage($message, $data) { $title = $data->title; $text = $data->fulltext; $url = $data->url; $image_url = $data->image_url; $media_mode = $this->getMediaMode(); $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'sendLinkedinMessage', $message); $result = null; $content = array(); // Post message and/or media switch ($media_mode) { case 'attachment': $post_attach = true; $post_msg = false; break; case 'both': $post_msg = true; $post_attach = true; break; case 'message': default: $post_msg = true; $post_attach = false; } // Media: do also not post when text and image are empty if ($post_attach && !empty($title) && !empty($url)) { // Prepare content $content['title'] = TextUtil::truncString($title, self::MAX_CHARS_TITLE); $content['submitted-url'] = $url; $content['submitted-image-url'] = $image_url; // Strlen shorter than JString::strlen for UTF-8 - 2 char languages E.g. Hebrew $text = TextUtil::truncString($text, self::MAX_CHARS_DESC); $content['description'] = $text; } // Message if ($post_msg) { $content['comment'] = $title; } // Default for visibility $private = false; try { $api = $this->getApiInstance(); $response = $api->companyShare($this->get('company_id'), 'new', $content, $private); $result = $this->_processResponse($response); } catch (Exception $e) { $result = array(false, $e->getMessage()); } return $result; }
public function validateModuleLabels($attribute, $params) { $data = $this->{$attribute}; foreach (Yii::app()->languageHelper->getActiveLanguagesData() as $language => $notUsed) { if (empty($data[$language])) { $this->addError($attribute . '[' . $language . ']', Zurmo::t('Core', 'Label must not be empty.')); } if ($data[$language] != TextUtil::strToLowerWithDefaultEncoding($data[$language])) { $this->addError($attribute . '[' . $language . ']', Zurmo::t('ZurmoModule', 'Label must be all lowercase.')); } if (!preg_match('/^[\\p{L}A-Za-z0-9_ ]+$/u', $data[$language])) { $this->addError($attribute . '[' . $language . ']', Zurmo::t('ZurmoModule', 'Label must not contain any special characters.')); } } }
public function testTextWithUrlToTextWithLink() { $textWithUrl = "Do you know the guys who made http://www.zurmo.com. They are awsome."; $textWithLink = TextUtil::textWithUrlToTextWithLink($textWithUrl); $this->assertEquals('Do you know the guys who made <a href="http://www.zurmo.com">www.zurmo.com</a>. They are awsome.', $textWithLink); $textWithUrl = "Do you know the guys who made https://www.zurmo.com. They are awsome."; $textWithLink = TextUtil::textWithUrlToTextWithLink($textWithUrl); $this->assertEquals('Do you know the guys who made <a href="https://www.zurmo.com">www.zurmo.com</a>. They are awsome.', $textWithLink); $textWithUrl = "Do you know the guys who made www.zurmo.com. They are awsome."; $textWithLink = TextUtil::textWithUrlToTextWithLink($textWithUrl); $this->assertEquals('Do you know the guys who made <a href="http://www.zurmo.com">www.zurmo.com</a>. They are awsome.', $textWithLink); $textWithUrl = "Please, send an email to jonny@zurmo.com"; $textWithLink = TextUtil::textWithUrlToTextWithLink($textWithUrl); $this->assertEquals('Please, send an email to <a href="mailto:jonny@zurmo.com">jonny@zurmo.com</a>', $textWithLink); }
/** * sendMessage. * * @param string $message Params * @param object $data Params * * @return boolean */ public function sendMessage($message, $data) { $title = $data->title; // Strlen shorter than JString::strlen for UTF-8 - 2 char languages E.g. Hebrew $text = TextUtil::truncString($data->fulltext, self::MAX_CHARS_TEXT); $url = $data->url; $image_url = $data->image_url; $media_mode = $this->getMediaMode(); $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'sendLinkedinMessage', $message); $result = null; // Post message and/or media switch ($media_mode) { case 'attachment': $post_attach = true; $post_msg = false; break; case 'both': $post_msg = true; $post_attach = true; case 'message': default: $post_msg = true; $post_attach = false; } try { $api = $this->getApiInstance(); if (empty($text)) { $text = JFactory::getConfig()->get('MetaDesc'); } if (empty($text)) { $text = JFactory::getConfig()->get('sitename'); } if (empty($text)) { $text = $title; } if ($post_attach) { $response = $api->createPost($this->get('group_id'), $title, $text, $url); } else { $response = $api->createPost($this->get('group_id'), $title, $text, $url, $image_url); } $result = $this->_processResponse($response); } catch (Exception $e) { $result = array(false, $e->getMessage()); } return $result; }
/** * sendMessage * * @param string $message Param * @param string $data Param * * @return bool */ public function sendMessage($message, $data) { $sender_mail = $this->get('mail_sender_email'); $sender_name = $this->get('mail_sender_name'); $recipient_mail = $this->get('mail_recipient_email'); $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'sendMailMessage', $message); $result = null; $this->mailer->isHtml(true); $this->mailer->SetFrom($sender_mail, $sender_name); $this->mailer->AddAddress($recipient_mail); $this->mailer->Subject = TextUtil::truncString($data->title, self::MAX_CHARS_SUBJECT); $this->mailer->Body = $this->renderPost($this->channel->id, 'mailchannel', $message, $data); if (!$this->mailer->Send()) { $result = array(false, 'error sending mail'); } else { $result = array(true, 'successfully sent'); } return $result; }
public function testStrToLowerWithDefaultEncoding() { $string = "Mary Had A Little Lamb and She LOVED It So."; $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string); $this->assertEquals('mary had a little lamb and she loved it so.', $lowercaseString); // Confirm that string will stay same, if we call this function on lowercase string. $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString); $this->assertEquals('mary had a little lamb and she loved it so.', $lowercaseString); $string = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"; $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string); $this->assertEquals('τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', $lowercaseString); $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString); $this->assertEquals('τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', $lowercaseString); $string = "ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮÂÀÁÄÃÊÈÉËÎÍÌÏÔÕÒÓÖÛÙÚÜÇ"; $correctLowercase = "ąćęłńóśźżabcdefghijklmnoprstuwyzqxvёйцукенгшщзхъфывапролджэячсмитьбюâàáäãêèéëîíìïôõòóöûùúüç"; $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string); $this->assertEquals($correctLowercase, $lowercaseString); $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString); $this->assertEquals($correctLowercase, $lowercaseString); }
/** * import * * @param object &$feed Params * * @return void */ public function import(&$feed) { if (isset($feed->params)) { $feed->xtform = EForm::paramsToRegistry($feed); } $import_frequency = $feed->xtform->get('import_frequency', self::ALWAYS_EXPRESSION); if ($import_frequency != self::ALWAYS_EXPRESSION) { $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel'); $key = 'feed-' . $feed->id; $lastexec = $automators->lastRun($key); if ($lastexec->toUnix() < JFactory::getDate()->toUnix()) { $lastexec = 'now'; } $next = TextUtil::nextScheduledDate($import_frequency, $lastexec); $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, "Feed import: lastRunCheck {$lastexec} ({$key}, 0, {$next})"); if (!$automators->lastRunCheck($key, 0, $next)) { $logger->log(JLog::INFO, "Feed import: lastRunCheck skipped!"); return; } } $result = new StdClass(); $result->added_items = 0; $simplePie = $this->_createSimplePie($feed); if ($simplePie->get_type() & SIMPLEPIE_TYPE_NONE) { throw new Exception(JText::sprintf('COM_AUTOTWEET_FEED_UNABLE_TO_PROCESS', $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')')); } elseif ($simplePie->error) { throw new Exception("SimplePie error (ID={$feed->id}): " . $simplePie->error . ' for ' . $feed->xtform->get('title') . ' (' . $feed->xtform->get('feed') . ')'); } $title = $simplePie->get_title(); $c = (int) $feed->xtform->get('import_limit'); $items = $simplePie->get_items(0, $c); $result->title = $title; $result->items = $items; $simplePie->__destruct(); unset($items, $simplePie); // End SimplePie processing return $result; }
* * @author Prieco S.A. <*****@*****.**> * @copyright Copyright (C) 2007 - 2015 Prieco, S.A. All rights reserved. * @license http://http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL * @link http://www.extly.com http://support.extly.com */ // No direct access defined('_JEXEC') or die('Restricted access'); F0FModel::getTmpInstance('Plugins', 'AutoTweetModel'); $result = array(); if ($count = count($this->items)) { foreach ($this->items as $item) { $native_object = json_decode($item->native_object); $has_error = isset($native_object->error) && $native_object->error; $description = htmlentities($item->description, ENT_COMPAT, 'UTF-8'); $description = TextUtil::truncString($description, AutotweetDefaultView::MAX_CHARS_TITLE_SHORT_SCREEN, true); $elem = array('id' => $item->id, 'title' => $description, 'start' => JHtml::_('date', $item->publish_up, DateTime::RFC3339), 'className' => $item->published ? $has_error ? 'req-error' : 'req-success' : ($has_error ? 'req-warning' : 'req-info')); /* if (!empty($item->url)) { $elem['url'] = TextUtil::renderUrl($item->url); } */ $elem['url'] = 'index.php?option=com_autotweet&view=composer&req-id=' . $item->id; if (!empty($item->image_url)) { $elem['image_url'] = TextUtil::renderUrl($item->image_url); } $result[] = $elem; } } echo json_encode($result);
/** * sampleAutoTweetNGIntegration * * @param int $productId Param * @param array &$data Param * * Example of how to save AutoTweetNG Request * Copy-paste into your extension, and customize freely * * @return void */ private static function sampleAutoTweetNGIntegration($productId, &$data) { // If product is not published, nothing else to do if (!$data['published']) { return; } $typeinfo = 99; $native_object = json_encode($data); // Product Url $viewProductUrl = EshopRoute::getProductRoute($productId, EshopHelper::getProductCategory($productId)); // Image Url $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->clear(); $query->select('image')->from('#__eshop_productimages')->where('product_id = ' . intval($productId))->order('ordering'); $db->setQuery($query); $product_image = $db->loadResult(); $image_url = null; if ($product_image && JFile::exists(JPATH_ROOT . '/media/com_eshop/products/' . $product_image)) { $image_url = 'media/com_eshop/products/' . $product_image; } $langmgmt_default_language = EParameter::getComponentParam(CAUTOTWEETNG, 'langmgmt_default_language'); if ($langmgmt_default_language) { $key = 'product_name_' . $langmgmt_default_language; if (array_key_exists($key, $data)) { $title = $data[$key]; } $key = 'product_desc_' . $langmgmt_default_language; if (array_key_exists($key, $data)) { $description = TextUtil::cleanText($data[$key]); } } if (empty($title)) { $title = $data['product_name']; } if (empty($description)) { $description = TextUtil::cleanText($data['product_desc']); } if (empty($title)) { return; } // Saving Advanced Attributes $autotweet_advanced = $data['autotweet_advanced_attrs']; $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($autotweet_advanced); AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $productId); // AutotweetAPI $id = self::insertRequest($productId, 'autotweetpost', JFactory::getDate()->toSql(), $title, $typeinfo, $viewProductUrl, $image_url, $native_object, $advanced_attrs); // Adding more information to the request $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel'); $request = $requestsModel->getItem($id); $request = (array) $request; $request['xtform']->set('title', $title); $request['xtform']->set('fulltext', $description); $request['xtform']->set('author', JFactory::getUser()->username); $requestsModel->save($request); }
public static function getModelLabelByTypeAndLanguage($type, $language = null) { assert('in_array($type, array("Singular", "SingularLowerCase", "Plural", "PluralLowerCase"))'); if ($type == 'Singular') { return static::getLabel($language); } if ($type == 'SingularLowerCase') { return TextUtil::strToLowerWithDefaultEncoding(static::getLabel($language)); } if ($type == 'Plural') { return static::getPluralLabel($language); } if ($type == 'PluralLowerCase') { return TextUtil::strToLowerWithDefaultEncoding(static::getPluralLabel($language)); } }
/** * sendMessage. * * @param string $message Params * @param object $data Params * * @return boolean */ public function sendMessage($message, $data) { $title = $data->title; $text = $data->fulltext; $url = $data->url; $image_url = $data->image_url; $media_mode = $this->getMediaMode(); $logger = AutotweetLogger::getInstance(); $logger->log(JLog::INFO, 'LiOAuth2ChannelHelper sendMessage', $message); $result = null; $content = array(); // Post message and/or media switch ($media_mode) { case 'attachment': $post_attach = true; $post_msg = false; break; case 'both': $post_msg = true; $post_attach = true; break; case 'message': default: $post_msg = true; $post_attach = false; } if (!empty($title)) { $title = TextUtil::truncString($title, self::MAX_CHARS_TITLE); $content['title'] = $title; } if (!empty($text)) { $text = TextUtil::truncString($text, self::MAX_CHARS_TEXT); $content['description'] = $text; } if (!empty($url)) { $content['submitted-url'] = $url; } if ($post_attach && !empty($image_url)) { $content['submitted-image-url'] = $image_url; } // Message if ($post_msg) { $content['comment'] = $message; } // Default for visibility $private = false; try { $response = $this->getApiInstance()->share2('new', $content, $private); $result = $this->processResponse($response); } catch (Exception $e) { $result = array(false, $e->getMessage()); } return $result; }
public static function resolveArrayToLowerCase($array) { return unserialize(TextUtil::strToLowerWithDefaultEncoding(serialize($array))); }
<div class="text"> <?php echo TextUtil::getRandomPhrase(); ?> </div>
/** @inheritdoc */ public static function calculateValue($modifierName, $modifierParams, $value, $params = array()) { switch ($modifierName) { case 'tag': return '{{' . $value . '}}'; break; case "lowercase": $value = strtolower($value); break; case "uppercase": $value = strtoupper($value); break; case "trim": $value = trim($value); break; case "length": $value = strlen($value); break; case "wordcount": //$value = str_word_count($value, 0, '/[\p{C}\p{S}\p{Z}]+/'); // does not work with utf-8 $value = str_replace("", '', $value); // soft hyphen encoded in UTF-8 $value = preg_match_all('~[\\p{L}\'\\-]+~u', $value); break; case "htmlentities": $value = htmlentities($value); break; case "zero": if ($value == '') { $value = 0; } break; case "shortener": $wordCount = Util::lavnn('words', $modifierParams, 0); $charCount = Util::lavnn('chars', $modifierParams, 0); $value = TextUtil::shorten($value, $wordCount, $charCount); break; case "split": $delimiter = Util::lavnn('delimiter', $modifierParams, ''); $value = explode(Processor::glueDecoder($delimiter), $value); break; case "if": if (!self::applyIf($modifierParams, $value, $params)) { return ''; } break; case "ifempty": $default = Util::lavnn('default', $modifierParams, ''); $fallback = Util::lavnn('fallback', $modifierParams, ''); if ($value != '') { return $value; } elseif ($fallback != '') { // @TODO fallback is now on top level of $params. make it findable in the tree return Util::lavnn($fallback, $params, $default); } else { return $default; } break; case "ifnotempty": if (is_null($value) || $value == '') { return ''; } break; case 'replace': $default = Util::lavnn('default', $modifierParams, ''); $fallback = Util::lavnn('fallback', $modifierParams, ''); $value = $fallback == '' ? $default : Util::lavnn($fallback, $params, $default); break; case "dbsafe": $value = TextUtil::dbsafe($value); break; case "jssafe": $value = TextUtil::jssafe($value); break; case "htmlsafe": $value = TextUtil::htmlsafe($value); break; case "urlencode": $value = urlencode($value); break; case "fixfloat": $value = floatval($value); break; case "fixint": $value = intval($value); break; case "fixbool": $value = (bool) $value; break; case 'rsstime': $value = date('D, d M Y H:i:s O', strtotime($value)); break; case 'dbdate': // Convert date from current locale format to DB-suitable format if ($value != '') { $value = DateTimeUtil::DateTimeToDB($value, Util::lavnn('time', $modifierParams, 'now')); } break; case 'date': // Convert database-formatted datetime into user favourite locale, without time if ($value != '') { $utcDate = date_create_from_format('Y-m-d H:i:s', $value); if (!$utcDate) { $value = date($_SESSION['formats']['date_php'], strtotime($value)); } else { $offset = Util::lavnn('timezoneOffset', $_SESSION, 0); $localDate = $utcDate->modify("+{$offset} minutes"); // fixing the timezone offset can change the date $value = $localDate->format($_SESSION['formats']['date_php']); } } break; case 'time': // Convert database-formatted datetime into user favourite locale, without date if ($value != '') { $utcDate = date_create_from_format('Y-m-d H:i:s', $value); if (!$utcDate) { $value = date($_SESSION['formats']['time_php'], strtotime($value)); } else { $offset = Util::lavnn('timezoneOffset', $_SESSION, 0); $localDate = $utcDate->modify("+{$offset} minutes"); $value = $localDate->format($_SESSION['formats']['time_php']); } } break; case 'datetime': // Convert database-formatted datetime into user current locale, using time if ($value != '') { $utcDate = date_create_from_format('Y-m-d H:i:s', $value); if (!$utcDate) { $value = date($_SESSION['formats']['datetime_php'], strtotime($value)); } else { $offset = Util::lavnn('timezoneOffset', $_SESSION, 0); $localDate = $utcDate->modify("+{$offset} minutes"); $value = $localDate->format($_SESSION['formats']['datetime_php']); } } break; case 'timestamp': if ($value != '') { $value = strtotime($value); } break; case "fixurl": $value = $value == '' ? '#' : (substr($value, 0, 4) != 'http' ? 'http://' : '') . $value; break; case "nohtml": $value = strip_tags($value); break; case "htmlcomment": $value = "<!--{$value}-->"; break; case "dump": $value = print_r($value, 1); break; case 'unserialize': $value = $value == '' ? array() : json_decode($value, true); break; case 'loremipsum': $loremIpsum = array("Donec ullamcorper nulla non metus auctor fringilla.", "Vestibulum id ligula porta felis euismod semper.", "Praesent commodo cursus magna, vel scelerisque nisl consectetur.", "Fusce dapibus, tellus ac cursus commodo."); $value = $value == '' ? join(' ', $loremIpsum) : $value; break; case 'gravatar': $size = Util::lavnn('size', $modifierParams, 50); $email = md5(strtolower(trim($value))); $value = "http://www.gravatar.com/avatar/{$email}?s=" . $size; break; default: $value = parent::calculateValue($modifierName, $modifierParams, $value, $params); break; } return $value; }
/** * postArticle * * @param object $article The item object. * * @return boolean */ protected function postArticle($article) { $cats = $this->getContentCategories($article->catid); $catIds = $cats[0]; $isIncluded = $this->isCategoryIncluded($catIds); $isExcluded = $this->isCategoryExcluded($catIds); if (!$isIncluded || $isExcluded) { return true; } if (!$this->enabledAccessLevel($article->access)) { return true; } $catAlias = $cats[2]; // Use main category for article url $cat_slug = $catIds[0] . ':' . TextUtil::convertUrlSafe($catAlias[0]); $id_slug = $article->id . ':' . TextUtil::convertUrlSafe($article->alias); // Create internal url for Joomla core content article JLoader::import('components.com_content.helpers.route', JPATH_ROOT); $url = ContentHelperRoute::getArticleRoute($id_slug, $cat_slug); // Get the first image from the text $fulltext = $article->introtext . ' ' . $article->fulltext; $images = null; if (isset($article->images)) { $images = json_decode($article->images); } if ($images && isset($images->image_intro) && !empty($images->image_intro)) { $image_url = $images->image_intro; } elseif ($images && isset($images->image_fulltext) && !empty($images->image_fulltext)) { $image_url = $images->image_fulltext; } else { $image_url = $this->getImageFromText($fulltext); } $native_object = json_encode($article); $this->content_language = $article->language; $this->postStatusMessage($article->id, $article->publish_up, $article->title, self::TYPE_ARTICLE, $url, $image_url, $native_object); }
/** * _getTagsToStrip * * @return array */ private function _getTagsToStrip() { $s = self::$_params->get('strip_list'); $w = ''; if (strpos($s, '+') === 0) { $s = FeedTextHelper::str_replace_first('+', '', $s); $w = '+'; } $ts = TextUtil::listToArray($s); $ht = array(); foreach ($ts as $k => $t) { if (JString::strpos($t, '=')) { $ht[] = $t; unset($ts[$k]); } } list($tags, $hook_tag) = array($w . implode(',', $ts), $w . implode(',', $ht)); if ($tags) { if (strpos($tags, '+') !== false) { $tags = str_replace('+', '', $tags); } else { $tags = str_replace(' ', '', $tags); $tags = '*-' . str_replace(',', ' -', $tags); } } self::$_tags = $tags; self::$_hook_tag = $hook_tag; return array($tags, $hook_tag); }
/** * _getImgFilename * * @param string $filename Params * @param int $type Params * * @return string */ private function _getImgFilename($filename, $type) { $filename = basename($filename); // Use Image Title/Alt if ($type == 0) { $ext = pathinfo($filename, PATHINFO_EXTENSION); if (!empty($this->title)) { $filename = $this->title; } elseif (!empty($this->alt)) { $filename = $this->alt; } else { return $filename; } $filename = TextUtil::convertUrlSafe($filename); return $filename . '.' . $ext; } // Use Original Filename if ($type == 1) { return $filename; } // Use md5 hash if ($type == 2) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $filename = md5($filename); return $filename . '.' . $ext; } return $filename; }
echo EHtmlGrid::lockedWithIcons($checkedout); ?> <a href="<?php echo $link; ?> "> <?php $description = TextUtil::truncString($item->description, AutotweetDefaultView::MAX_CHARS_TITLE_SCREEN, true); echo htmlentities($description, ENT_COMPAT, 'UTF-8'); ?> </a> <?php if (!empty($item->url)) { echo ' <a href="' . TextUtil::renderUrl($item->url) . '" target="_blank"><i class="xticon xticon-globe"></i></a>'; } if (!empty($item->image_url)) { echo ' <a href="' . TextUtil::renderUrl($item->image_url) . '" target="_blank"><i class="xticon xticon-image"></i></a>'; } ?> </td> <td><?php echo AutoTweetModelPlugins::getSimpleName($item->plugin); ?> </td> <td><?php if ($has_error) { $alert_message = htmlentities($alert_message, ENT_COMPAT, 'UTF-8'); echo '<div rel="tooltip" data-original-title="' . $alert_message . '">'; echo EHtmlGrid::publishedWithIcons($item, $i, $this->perms->editstate); echo ' <a class="xticon xticon-thumbs-down"></a>';
/** * _saveEnclosure * * @param string $name Params * @param string $type Params * @param string $src Params * * @return void */ public function _saveEnclosure($name, $type, $src) { if ($type == 'images') { $savepath = $this->_params->get('save_enc_image_as_img', 1) ? $this->_params->get('img_savepath') : $this->_params->get('savepath') . $type . '/'; if (!JFolder::exists($savepath)) { JFolder::create($savepath); } $file_path = $savepath . $name; } else { $savepath = $this->_params->get('savepath') . $type . '/'; if (!JFolder::exists($savepath)) { JFolder::create($savepath); } $file_path = $savepath . $name; } if (!file_exists($file_path)) { if (!($contents = TextUtil::getUrl(TextUtil::encode_url($src), $this->_params->get('scrape_type'), $type, $file_path))) { // Enclosure Not Saved'); return false; } else { // Enclosure Saved'); } } else { // Enclosure Already Saved'); } return true; }
/** * Override to convert url to link * @return The element's content. */ protected function renderControlNonEditable() { return TextUtil::textWithUrlToTextWithLink($this->model->{$this->attribute}); }
/** * queueMessage * * @param string $articleid Param * @param string $source_plugin Param * @param string $publish_up Param * @param string $description Param * @param string $typeinfo Param * @param string $url Param * @param string $image_url Param * @param object &$native_object Param * @param string &$advanced_attrs Param * @param string &$params Param * @param string $content_language Param * * @return mixed - false, or id of request */ public static function insertRequest($articleid, $source_plugin, $publish_up, $description, $typeinfo = 0, $url = '', $image_url = '', &$native_object = null, &$advanced_attrs = null, &$params = null, $content_language = null) { $logger = AutotweetLogger::getInstance(); // Check if message is already queued (it makes no sense to queue message more than once when modfied) // if message is already queued, correct the publish date $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel'); $requestsModel->set('ref_id', $articleid); $requestsModel->set('plugin', $source_plugin); $requestsModel->set('typeinfo', $typeinfo); $row = $requestsModel->getFirstItem(); $id = $row->id; // Avoid databse warnings when desc is longer then expected if (!empty($description)) { $description = TextUtil::cleanText($description); $description = JString::substr($description, 0, SharingHelper::MAX_CHARS_TITLE); } $routeHelp = RouteHelp::getInstance(); if ($content_language) { $routeHelp->setContentLanguage($content_language); } if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_post_url')) { $url = 'index.php'; } $url = $routeHelp->getAbsoluteUrl($url); if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_image_url')) { $image_url = null; } if (empty($image_url)) { // Default image: used in media mode when no image is available $image_url = EParameter::getComponentParam(CAUTOTWEETNG, 'default_image', ''); } if (!empty($image_url)) { $image_url = $routeHelp->getAbsoluteUrl($image_url, true); } $row->reset(); if ($id) { $row->load($id); } // If there's no date, it means now if (empty($publish_up)) { $publish_up = JFactory::getDate()->toSql(); } $request = array('id' => $id, 'ref_id' => $articleid, 'plugin' => $source_plugin, 'publish_up' => $publish_up, 'description' => $description, 'typeinfo' => $typeinfo, 'url' => $url, 'image_url' => $image_url, 'native_object' => $native_object, 'params' => $params, 'published' => 0); $logger->log(JLog::INFO, 'Enqueued request', $request); // Saving the request $queued = $row->save($request); if (!$queued) { $logger->log(JLog::ERROR, 'queueMessage: error storing message to database message queue, article id = ' . $articleid . ', error message = ' . $row->getError()); } else { $logger->log(JLog::INFO, 'queueMessage: message stored/updated to database message queue, article id = ' . $articleid); } if (!$id) { $id = $row->id; } if ($advanced_attrs && isset($advanced_attrs->attr_id)) { $row = F0FModel::getTmpInstance('Advancedattrs', 'AutoTweetModel')->getTable(); $row->reset(); $row->load($advanced_attrs->attr_id); $attr = array('id' => $advanced_attrs->attr_id, 'request_id' => $id); // Updating attr $result = $row->save($attr); if (!$result) { $logger->log(JLog::ERROR, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id . ', error message = ' . $row->getError()); } else { $logger->log(JLog::INFO, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id); } } $app = JFactory::getApplication(); if ($app->isAdmin() && JFactory::getConfig()->get('show_req_notification', true)) { $msg = VersionHelper::getFlavourName() . ': ' . JText::sprintf('COM_AUTOTWEET_REQUEST_ENQUEUED_MSG', $id); $app->enqueueMessage($msg); } return $queued ? $id : false; }
/** * Check whether the specified value corresponds to a valid username of a user model. * @param AnalyzerSupportedDataProvider $dataProvider * @param string $columnName */ protected function resolveForTypeUsername(AnalyzerSupportedDataProvider $dataProvider, $columnName) { assert('is_string($columnName)'); $usernameValues = UserValueTypeSanitizerUtil::getUsernames(); $usernameValues = ArrayUtil::resolveArrayToLowerCase($usernameValues); $data = $dataProvider->getCountDataByGroupByColumnName($columnName); $count = 0; foreach ($data as $valueCountData) { if ($valueCountData[$columnName] == null) { continue; } if (!in_array(TextUtil::strToLowerWithDefaultEncoding($valueCountData[$columnName]), $usernameValues)) { $count++; } } if ($count > 0) { $label = '{count} username(s) specified were not found. '; $label .= 'These values will not be used during the import.'; $this->addMessage(Zurmo::t('ImportModule', $label, array('{count}' => $count))); } }
/** * @dataProvider dataProviderSanitize */ public function testSanitize($string, $expected) { $this->assertEquals($expected, TextUtil::sanitize($string)); }
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL * @link http://www.extly.com http://support.extly.com */ // No direct access defined('_JEXEC') or die('Restricted access'); $input = $this->input; $message = $input->getString('message'); $image_url = $input->getString('image_url'); $url = $input->getString('url'); $org_url = $input->getString('org_url'); $sitename = JFactory::getConfig()->get('sitename'); $url = RouteHelp::getInstance()->getRoot(); ?> <p> <?php echo TextUtil::autoLink($message); ?> </p> <?php if (!empty($image_url)) { ?> <p> <a href="<?php echo $org_url; ?> "> <img src="<?php echo $image_url; ?> "> </a>
/** * Given a value, resolve that the value is a valid custom field data value. If the value does not exist yet, * check the import instructions data to determine how to handle the missing value. * * Example of importInstructionsData * array('DropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('neverPresent', 'notPresent'))) * * @param string $modelClassName * @param string $attributeName * @param mixed $value * @param array $mappingRuleData * @param array $importInstructionsData */ public static function sanitizeValueWithInstructions($modelClassName, $attributeName, $value, $mappingRuleData, $importInstructionsData) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); assert('$mappingRuleData == null'); if (!isset($importInstructionsData["DropDown"][DropDownSanitizerUtil::ADD_MISSING_VALUE])) { $importInstructionsData["DropDown"][DropDownSanitizerUtil::ADD_MISSING_VALUE] = array(); } if ($value == null) { return $value; } $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $attributeName); $dropDownValues = unserialize($customFieldData->serializedData); $lowerCaseDropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues); $generateMissingPickListError = false; //does the value already exist in the custom field data if (in_array(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseDropDownValues)) { $keyToUse = array_search(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseDropDownValues); $resolvedValueToUse = $dropDownValues[$keyToUse]; } else { //if the value does not already exist, then check the instructions data. $lowerCaseValuesToAdd = ArrayUtil::resolveArrayToLowerCase($importInstructionsData['DropDown'][DropDownSanitizerUtil::ADD_MISSING_VALUE]); if (in_array(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseValuesToAdd)) { $keyToAddAndUse = array_search(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseValuesToAdd); $resolvedValueToUse = $importInstructionsData['DropDown'][DropDownSanitizerUtil::ADD_MISSING_VALUE][$keyToAddAndUse]; $unserializedData = unserialize($customFieldData->serializedData); $unserializedData[] = $resolvedValueToUse; $customFieldData->serializedData = serialize($unserializedData); $saved = $customFieldData->save(); assert('$saved'); } elseif (isset($importInstructionsData['DropDown'][DropDownSanitizerUtil::MAP_MISSING_VALUES])) { $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($importInstructionsData['DropDown'][DropDownSanitizerUtil::MAP_MISSING_VALUES]); if (isset($lowerCaseMissingValuesToMap[TextUtil::strToLowerWithDefaultEncoding($value)])) { $keyToUse = array_search($lowerCaseMissingValuesToMap[TextUtil::strToLowerWithDefaultEncoding($value)], $lowerCaseDropDownValues); if ($keyToUse === false) { $message = 'Pick list value specified is missing from existing pick list, has a specified mapping value' . ', but the mapping value is not a valid value.'; throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', $message)); } else { $resolvedValueToUse = $dropDownValues[$keyToUse]; } } else { $generateMissingPickListError = true; } } else { $generateMissingPickListError = true; } if ($generateMissingPickListError) { $message = 'Pick list value specified is missing from existing pick list and no valid instructions' . ' were provided on how to resolve this.'; throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', $message)); } } $customField = new OwnedCustomField(); $customField->value = $resolvedValueToUse; $customField->data = $customFieldData; return $customField; }
public static function getModuleLabelByTypeAndLanguage($type, $language = null) { assert('in_array($type, array("Singular", "SingularLowerCase", "Plural", "PluralLowerCase"))'); assert('$language == null || is_string($language)'); if ($language == null) { $language = Yii::app()->language; } $label = self::getCustomModuleLabelByTypeAndLanguage($type, $language); if ($label != null) { return $label; } switch ($type) { case 'Singular': return static::getSingularModuleLabel($language); case 'SingularLowerCase': $string = static::getSingularModuleLabel($language); return TextUtil::strToLowerWithDefaultEncoding($string); case 'Plural': return static::getPluralModuleLabel($language); case 'PluralLowerCase': $string = static::getPluralModuleLabel($language); return TextUtil::strToLowerWithDefaultEncoding($string); } }