/** * _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; }
/** * _createAlias * * @param string $title Params * * @return string */ private function _createAlias($title) { $alias = TextUtil::convertUrlSafe($title); $custom_translit = self::$_params->get('custom_translit'); if (!empty($custom_translit)) { $alias = FeedTextHelper::transliterate($alias, $custom_translit); } // Fix for trailing alias dashes $length = strlen($alias); if (strrpos($alias, '-') == $length - 1) { $alias = substr($alias, 0, $length - 1); } // Fix for long titles and htmlentities $alias = substr($alias, 0, 255); return $alias; }
/** * url * * @param object &$article Param * * @return string */ public function url(&$article) { JLoader::register('JTableCategory', JPATH_PLATFORM . '/joomla/database/table/category.php'); $cats = plgAutotweetBase::getContentCategories($article->catid); $cat_ids = $cats[0]; $catNames = $cats[1]; $catAlias = $cats[2]; // Use main category for article url $cat_slug = $article->catid . ':' . 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); $routeHelp = RouteHelp::getInstance(); $url = $routeHelp->getAbsoluteUrl($url); return $url; }
/** * 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); }
/** * getImageName * * @param string $title Params * @param string $alt Params * @param string $src Params * @param string $name_type Params * @param string $image_details Params * @param bool $add_ext Params * * @return string */ public static function getImageName($title, $alt, $src, $name_type, $image_details, $add_ext = 1) { preg_match('#[/?&]([^/?&]*)(\\.jpg|\\.jpeg|\\.gif|\\.png)#i', $src, $matches); $ext = isset($matches[2]) ? trim(strtolower($matches[2])) : ''; if (!$ext and !empty($image_details)) { switch ($image_details['mime']) { case 'image/pjpeg': case 'image/jpeg': case 'image/jpg': $ext = '.jpg'; break; case 'image/x-png': case 'image/png': $ext = '.png'; break; case 'image/gif': $ext = '.gif'; break; case 'image/bmp': $ext = '.bmp'; break; } } switch ($name_type) { case 0: list($name) = $title ? self::splitText($title, 50, 'char', false) : self::splitText($alt, 50, 'char', false); break; case 1: if (isset($matches[1])) { $name = $matches[1]; } break; case 2: $name = md5($src); break; case 3: jexit('Image name error'); break; } $name_type++; if (empty($name)) { $name = self::getImageName($title, $alt, $src, $name_type, $image_details, 0); } $name = JFile::makeSafe(TextUtil::convertUrlSafe($name)); return $add_ext ? $name . $ext : $name; }