/** * @param KunenaBBCode $bbcode * @param $action * @param $name * @param $default * @param $params * @param $content * @return bool|string */ function DoCode($bbcode, $action, $name, $default, $params, $content) { if ($action == BBCODE_CHECK) { return true; } $type = isset($params["type"]) ? $params["type"] : "php"; if ($type == 'js') { $type = 'javascript'; } elseif ($type == 'html') { $type = 'html4strict'; } $highlight = KunenaFactory::getConfig()->highlightcode && empty($bbcode->parent->forceMinimal); if ($highlight && !class_exists('GeSHi')) { $paths = array(JPATH_ROOT . '/plugins/content/geshiall/geshi/geshi.php', JPATH_ROOT . '/plugins/content/geshi/geshi/geshi.php'); foreach ($paths as $path) { if (!class_exists('GeSHi') && file_exists($path)) { require_once $path; } } } if ($highlight && class_exists('GeSHi')) { $geshi = new GeSHi($bbcode->UnHTMLEncode($content), $type); $geshi->enable_keyword_links(false); $code = $geshi->parse_code(); } else { $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $code = '<pre xml:' . $type . '>' . $content . '</pre>'; } return '<div class="highlight">' . $code . '</div>'; }
/** * @param KunenaBBCode $bbcode * @param $action * @param $name * @param $default * @param $params * @param $content * @return bool|string */ function DoImage($bbcode, $action, $name, $default, $params, $content) { if ($action == BBCODE_CHECK) { return true; } $fileurl = $bbcode->UnHTMLEncode(trim(strip_tags($content))); $filename = basename($fileurl); // Display tag in activity streams etc.. if (!empty($bbcode->parent->forceMinimal)) { return "<a href=\"" . $bbcode->HTMLEncode($fileurl) . "\" rel=\"nofollow\" target=\"_blank\">" . $bbcode->HTMLEncode($filename) . '</a>'; } // Legacy attachments support. if (isset($bbcode->parent->attachments) && strpos($fileurl, '/media/kunena/attachments/legacy/images/')) { // Remove attachment from the attachments list and show it if it exists. /** @var array|KunenaAttachment[] $attachments */ $attachments =& $bbcode->parent->attachments; foreach ($attachments as $id => $attachment) { if ($attachment->getFilename() == $filename && $attachment->folder == 'media/kunena/attachments/legacy/images') { unset($attachments[$id]); return $this->renderAttachment($attachment, $bbcode); } } } $config = KunenaFactory::getConfig(); $layout = KunenaLayout::factory('BBCode/Image')->set('title', JText::_('COM_KUNENA_FILEATTACH'))->set('url', null)->set('filename', null)->set('size', isset($params['size']) ? $params['size'] : 0)->set('canLink', $bbcode->autolink_disable == 0); if (JFactory::getUser()->id == 0 && $config->showimgforguest == 0) { // Hide between content from non registered users. return (string) $layout->set('title', JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEIMG'))->setLayout('unauthorised'); } // Obey image security settings. if ($config->bbcode_img_secure != 'image') { if ($bbcode->autolink_disable == 0 && !preg_match("/\\.(?:gif|jpeg|jpg|jpe|png)\$/ui", $fileurl)) { // If the image has not legal extension, return it as link or text. if ($config->bbcode_img_secure == 'link') { if (!preg_match('`^(/|https?://)`', $fileurl)) { $fileurl = 'http://' . $fileurl; } // TODO: call URL layout instead.. return "<a href=\"" . $bbcode->HTMLEncode($fileurl) . "\" rel=\"nofollow\" target=\"_blank\">" . $bbcode->HTMLEncode($fileurl) . '</a>'; } else { return $bbcode->HTMLEncode($fileurl); } } } return (string) $layout->set('url', $fileurl); }