Kunena BBCode Parser
- Details
- Kategorie: Kunena
- Zuletzt aktualisiert: Sonntag, 10. Januar 2021 21:56
- Zugriffe: 2572
Kunena BBCode Parser Modifications (type: Core Hack)
i found some unlucky solutions in the BBCode Parser, so I modified the Code a bit :).
you may find it useful or not :) - all solutions are hacks of the standard kunena BBCode Core
link img-attachments
ever wanted to add a link to an attached image?
after using this little hack you can add a link to attachments see the attachment demo
for the linked attachments you must edit:
1. yourtemplate/assets/js/upload.main-min.js
function insertInMessage(attachid, filename, button) edit the 2nd line:
$('#editor').insertAtCaret(' [attachment=' + attachid]' + filename + '[/attachment]'); to
$('#editor').insertAtCaret(' [attachment=' + attachid + ' link=self]' + filename + '[/attachment]');
important: always check if your template loads the normal.js or the -min.js version.
you can simply rename normal js files to -min, this makes just a few more kb, or minifiy your new JS online.
2. libraries/kunena/bbcode/bbcode.php
add the link key to public $default_tag_rules = array( 'attachment' => array(...
'allow' => array('_default' => '/^\d$/', 'link' => '/^\s?|[\w\d.:-@&?/]$/'),
public function DoAttachment edit the last line
return $this->renderAttachment($attachment, $bbcode); to
return $this->renderAttachment($attachment, $bbcode, $params);
replace the complete protected function renderAttachment with or add marked lines
protected function renderAttachment(KunenaAttachment $attachment, $bbcode, $params, $displayImage = true) {
// Display nothing in subscription mails
if (!empty($bbcode->context))
{
return '';
}
$alink = (isset($params['link']) && $params['link'] == 'self') ? $bbcode->autolink_disable == 1 : $bbcode->autolink_disable == 0;
$layout = KunenaLayout::factory('BBCode/Attachment')
->set('attachment', $attachment)
->set('canLink', $alink);
$config = KunenaConfig::getInstance();
$bbcode->parent->inline_attachments[$attachment->id] = $attachment;
if (!$attachment->exists() || !$attachment->getPath()) {
return (string) $layout->setLayout('deleted');
}
elseif (!$attachment->isAuthorised() && !$config->showimgforguest && $attachment->id != '0') {
return;
}
elseif (!$attachment->isAuthorised()) {
return (string) $layout->setLayout('unauthorised');
}
if ($displayImage && $attachment->isImage()) {
$layout->setLayout('image');
}
if (isset($params['link']) && $params['link'] != 'self' && $params['link'] != '') {
$d = substr(explode('/',JURI::base())[2],5);
$inturl = explode($d,$params['link']);
$aurl = (count($inturl) == 2) ? $inturl[1] : $inturl[0];
if (stripos($aurl,'ndex.php') == 1 || stripos($aurl,'ndex.php') == 2)
$aurl = JRoute::_(ltrim($aurl,'/'));
elseif (strpos($aurl, 'http') !== 0)
$aurl = 'http://'.$aurl;
if ($bbcode->IsValidURL($aurl, false, true)) {
$strlayout = (string)$layout;
$part1 = explode('<a href',$strlayout);
$part2 = explode('<img src=',$strlayout);
$strlayout = $part1[0].'<a href="'.$aurl.'" target="_blank" title="'.$aurl.'"><img src='.$part2[1];
return $strlayout;
}
}
return (string) $layout;
}
you may test the results of the modified core just in the forum