/** * @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); }
/** * @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 = trim(strip_tags($content)); // Display tag in activity streams etc.. if (!empty($bbcode->parent->forceMinimal)) { return "<a href=\"" . $fileurl . "\" rel=\"nofollow\" target=\"_blank\">" . basename($fileurl) . '</a>'; } $config = KunenaFactory::getConfig(); if (JFactory::getUser()->id == 0 && $config->showimgforguest == 0) { // Hide between content from non registered users return '<b>' . JText::_('COM_KUNENA_SHOWIMGFORGUEST_HIDEIMG') . '</b>'; } 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 $fileurl = $bbcode->HTMLEncode($fileurl); if ($config->bbcode_img_secure == 'link') { if (!preg_match('`^(/|https?://)`', $fileurl)) { $fileurl = 'http://' . $fileurl; } return "<a href=\"" . $fileurl . "\" rel=\"nofollow\" target=\"_blank\">" . $fileurl . '</a>'; } else { return $fileurl; } } } // Legacy attachments support (mostly used to remove image from attachments list), but also fixes broken links if (isset($bbcode->parent->attachments) && strpos($fileurl, '/media/kunena/attachments/legacy/images/')) { // Make sure that filename does not contain path or URL $filename = basename($fileurl); // Remove attachment from the attachments list and show it if it exists /** @var array|KunenaForumMessageAttachment[] $attachments */ $attachments =& $bbcode->parent->attachments; $attachment = null; foreach ($attachments as $att) { if ($att->filename == $filename && $att->folder == 'media/kunena/attachments/legacy/images') { $attachment = $att; unset($attachments[$att->id]); $bbcode->parent->inline_attachments[$attachment->id] = $attachment; return "<div class=\"kmsgimage\">{$attachment->getImageLink()}</div>"; } } // No match -- assume that we have normal img tag } // Make sure we add image size if specified $width = $params['size'] ? ' width="' . (int) $params['size'] . '"' : ''; $fileurl = $bbcode->HTMLEncode($fileurl); // Need to check if we are nested inside a URL code if ($bbcode->autolink_disable == 0 && $config->lightbox) { return '<div class="kmsgimage"><a href="' . $fileurl . '" title="" rel="lightbox[gallery]"><img src="' . $fileurl . '"' . $width . ' style="max-height:' . $config->imageheight . 'px;" alt="" /></a></div>'; } return '<div class="kmsgimage"><img src="' . $fileurl . '"' . $width . ' style="max-height:' . $config->imageheight . 'px;" alt="" /></div>'; }
function stripBBCode($txt, $len=0) { if (!$txt) return; $bbcode = KunenaBBCode::getInstance(); $bbcode->SetLimit($len); $bbcode->SetPlainMode(true); $bbcode->SetDetectURLs(true); $bbcode->SetURLPattern('<a href="{$url/h}" target="_blank" rel="nofollow">{$text/h}</a>'); $bbcode->SetURLTarget('_blank'); $txt = strip_tags($bbcode->Parse($txt)); $txt = self::prepareContent ( $txt ); return $txt; }