public function getArticleById($id = null) { $id = $id != null ? $id : (int) $this->params->get('leading_item'); if (!$id) { return; } $db = JFactory::getDBO(); $query = $db->getQuery(true); //get k2 item $query->select('a.*'); $query->from('#__k2_items AS a'); $query->where('a.published=1'); $query->where('a.trash=0'); $query->where('a.id=' . $id); //join category $query->select('cat.alias AS category_alias'); $query->join('LEFT', '#__k2_categories AS cat ON cat.id = a.catid'); $query->where('cat.published=1'); $query->where('cat.trash=0'); $db->setQuery($query, 0, 1); $item = $db->loadObject(); if ($item->id != '') { $item->slug = $item->id . ':' . urlencode($item->alias); $item->catslug = $item->catid . ':' . urlencode($item->category_alias); $item->link = JRoute::_(K2HelperRoute::getItemRoute($item->slug, $item->catslug)); $item->emailLink = JURI::base() . K2HelperRoute::getItemRoute($item->slug, $item->catslug); $item->text = $item->introtext . $item->fulltext; if ((bool) $this->params->get('article_thumbnail') || (bool) $this->params->get('hide_leading_image')) { $thumbnail_width = (int) $this->params->get('article_thumbnail_width', 150); $thumbnail_height = (int) $this->params->get('article_thumbnail_height', 100); $item->thumbnails = self::getThumbnails($item->text, $this->params->get('article_thumbnail_mode', 'adaptiveresize'), $thumbnail_width, $thumbnail_height, $this->params->get('article_thumbnail_position') == 'inside', (bool) $this->params->get('hide_article_image')); } if ($this->params->get('article_maxchars', 400) == 0) { $item->text = $this->params->get('hide_article_image') ? modJVLatestNewsHelper::clearContentImage($item->introtext) : $item->introtext; } else { $item->text = cut_html_string($item->text, (int) $this->params->get('article_maxchars', 400)); } $dispatcher =& JDispatcher::getInstance(); $dispatcher->trigger('onContentPrepare', array('com_k2.item', &$item, &$params, 0)); return $item; } return; }
function prepare($items) { $intros = $links = array(); if (count($items)) { foreach ($items as $index => $item) { $item->slug = $item->id . ':' . $item->alias; $item->catslug = $item->catid . ':' . $item->category_alias; $item->linkcat = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catid)); $item->link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug)); $item->text = $item->introtext . $item->fulltext; $item->emailLink = JURI::base() . ContentHelperRoute::getArticleRoute($item->slug, $item->catslug); if ($index < $this->num_intro) { if ((bool) $this->params->get('intro_thumbnail')) { $thumbnail_width = (int) $this->params->get('intro_thumbnail_width', 64); $thumbnail_height = (int) $this->params->get('intro_thumbnail_height', 64); $images = json_decode($item->images); if (@$images->image_intro) { $path = $this->createPath(); $item->thumbnails = $this->createThumb($images->image_intro, $path, $thumbnail_width, $thumbnail_height, $this->params->get('intro_thumbnail')); } else { $item->thumbnails = $this->getThumbnails($item->text, $this->params->get('intro_thumbnail'), $thumbnail_width, $thumbnail_height, $this->params->get('intro_thumbnail_position') == 'inside'); } if (!$item->thumbnails) { $item->thumbnails = JURI::root() . 'modules/mod_jvlatest_news/tmpl/default/images/noImage.png'; } } else { //$images = json_decode($item->image); //$item->thumbnails = $images[0]; } if ($this->params->get('cut_intro') > 0) { $item->text = cut_html_string($this->clearContentImage($item->introtext), (int) $this->params->get('cut_intro')); } else { $item->text = $this->clearContentImage($item->introtext); } $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onPrepareContent', array(&$item, &$params, 0)); $intros[] = $item; } elseif ($this->nums_link > 0) { $links[] = $item; } } } $items = new stdClass(); $items->intros = $intros; $items->links = $links; return $items; }
} // Gestion de l'url du site $aso_page['url_site'] = htmlentities($feed->channel['link'], ENT_QUOTES, 'UTF-8'); // Ouverture du lien dans une nouvelle fenetre $aso_page['ext'] = $nouvellefenetre; //url de l'article $aso_page['url'] = htmlentities($item['link'], ENT_QUOTES, 'UTF-8'); //titre de l'article $aso_page['titre'] = html_entity_decode(htmlentities($item['title'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES); //description de la description : soit tronquée, soit en entier if (!empty($nbchar)) { //On vérifie si le texte est plus grand que le nombre de caractères spécifiés if (strlen($item['description']) > 0 && strlen($item['description']) > $nbchar) { //on découpe avec une bibliotheque qui respecte le DOM html include_once 'tools/syndication/libs/cutstring.php'; $item['description'] = cut_html_string($item['description'], $nbchar) . ' [..] <a class="lien_lire_suite" href="' . $aso_page['url'] . '" ' . ($nouvellefenetre ? 'onclick="window.open(this.href); return false;" ' : '') . 'title="lire la suite">Lire la suite</a>'; } $aso_page['description'] = html_entity_decode(htmlentities($item['description'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES); } else { $aso_page['description'] = html_entity_decode(htmlentities($item['description'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES); } //gestion de la date de publication, selon le flux, elle se trouve parsee à des endroits differents if ($item['pubdate']) { $aso_page['datestamp'] = strtotime($item['pubdate']); } elseif ($item['dc']['date']) { //en php5 on peut convertir les formats de dates exotiques plus facilement if (PHP_VERSION >= 5) { $aso_page['datestamp'] = strtotime($item['dc']['date']); } else { $aso_page['datestamp'] = parse_w3cdtf($item['dc']['date']); }