public static
renderArticle
(mixed $id, mixed $format = 'html', mixed $default = '', mixed $changeLang = 0)
public static function renderArticle($id, $format = 'html', $default = '', $changeLang = 0)
{
$o = '';
if ((int) $id > 0) {
$db = Factory::getDBO();
$query = $db->getQuery(true);
//$query = 'SELECT a.introtext, a.fulltext FROM #__content AS a WHERE id = ' . (int)$id;
$query = $db->getQuery(true)->select('a.introtext, a.fulltext')->from($db->quoteName('#__content', 'a'))->where([$db->quoteName('a.id') . ' = ' . (int) $id]);
/*if (Associations::isEnabled())
{
$subQuery = $db->getQuery(true)
->select('COUNT(' . $db->quoteName('asso1.id') . ') > 1')
->from($db->quoteName('#__associations', 'asso1'))
->join('INNER', $db->quoteName('#__associations', 'asso2'), $db->quoteName('asso1.key') . ' = ' . $db->quoteName('asso2.key'))
->where(
[
$db->quoteName('asso1.id') . ' = ' . $db->quoteName('a.id'),
$db->quoteName('asso1.context') . ' = ' . $db->quote('com_content.item'),
]
);
$query->select('(' . $subQuery . ') AS ' . $db->quoteName('association'));
}*/
$db->setQuery((string) $query);
$a = $db->loadObject();
// Associated article by language - lang, assoc
if (Associations::isEnabled()) {
$itemAssociations = array();
if ($id != null) {
$associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $id);
$lang = Factory::getLanguage();
$language = $lang->getTag();
if (isset($language) && $language != '*' && $language != '') {
foreach ($associations as $tag => $association) {
if ($language == $tag && isset($association->id)) {
$query = $db->getQuery(true)->select('a.introtext, a.fulltext')->from($db->quoteName('#__content', 'a'))->where([$db->quoteName('a.id') . ' = ' . (int) $association->id]);
$db->setQuery((string) $query);
$a = $db->loadObject();
}
}
}
}
}
$o = $a->introtext . $a->fulltext;
// Disable emailclock for PDF | MAIL
if ($format == 'pdf' || $format == 'mail') {
$o = '{emailcloak=off}' . $o;
}
$o = HTMLHelper::_('content.prepare', $o);
if ($changeLang == 1) {
PluginHelper::importPlugin('system');
PluginHelper::importPlugin('plgSystemMultilanguagesck');
Factory::getApplication()->triggerEvent('onChangeText', array(&$o));
}
if ($format == 'pdf' || $format == 'text') {
// Remove Javascript for PDF
$o = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $o);
// Remove mailto - problematic for TCPDF
$o = preg_replace("~<a\\s+href=[\\'|\"]mailto:(.*?)[\\'|\"].*?>.*?</a>~", "\$1", $o);
}
if ($format == 'text') {
$o = PhocacartText::filterValue($o, 'text');
}
}
// If no text is set by article and there is default value
if ($o == '' && $default != '') {
return $default;
}
return $o;
}