Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
<button class="btn" type="button" id="upbutton" title="<?php echo JText::_('COM_MEDIA_DIRECTORY_UP') ?>"><?php echo JText::_('COM_MEDIA_UP') ?></button>
</div>
</div>
<?php if ($input->getCmd('tiny') != 1):?>
<div class="pull-right">
<button class="btn btn-primary" type="button" onclick="<?php if ($this->state->get('field.id')):?>window.parent.jInsertFieldValue(document.getElementById('f_url').value,'<?php echo $this->state->get('field.id');?>');<?php else:?>ImageManager.onok();<?php endif;?>window.parent.jModalClose();"><?php echo JText::_('COM_MEDIA_INSERT') ?></button>
<button class="btn" type="button" onclick="window.parent.jModalClose();"><?php echo JText::_('JCANCEL') ?></button>
</div>
<?php endif;?>
</div>
</div>

Expand Down
33 changes: 33 additions & 0 deletions media/editors/tinymce/plugins/joomlaarticle/plugin.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
tinymce.PluginManager.add("joomlaarticle", function(editor, url) {
editor.addButton("joomlaarticle", {
text: 'J Article',
title: "Joomla Insert Article",
icon: "newdocument",
onclick: function() {
if (imgLink) {
editor.windowManager.open({
title : "Joomla Select Article",
url : 'index.php?option=com_content&amp;view=articles&amp;layout=modal&amp;tmpl=component&amp;' + toc + '=1',
width : 900,
height : 600,
buttons: [{
text : "Close",
onclick: "close"
}]
})
}
}
})
});

function jSelectArticle(id, title, catid, object, link, lang)
{
var hreflang = '';
if (lang !== '')
{
var hreflang = ' hreflang = \"' + lang + '\"';
}
var tag = '<a' + hreflang + ' href=\"' + link + '\">' + title + '</a>';
tinymce.activeEditor.insertContent(tag);
tinymce.activeEditor.windowManager.close();
}
27 changes: 27 additions & 0 deletions media/editors/tinymce/plugins/joomlaimage/plugin.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tinymce.PluginManager.add("joomlaimage", function(editor, url) {
editor.addButton("joomlaimage", {
text: 'J Image',
title: "Joomla Insert Image",
icon: "image",
onclick: function() {
if (imgLink) {
editor.windowManager.open({
title : "Change or upload image",
url : imgLink + editor.getContainer().id,
width : 900,
height : 600,
buttons: [{
text : "Insert",
onclick: function () {
var url = editor.windowManager.getWindows()[0];
editor.insertContent("<img src=\"" + url.getContentWindow().document.getElementById("f_url").value + "\" alt=\"\" />"), url.close()
}
}, {
text : "Close",
onclick: "close"
}]
})
}
}
})
});
25 changes: 25 additions & 0 deletions media/editors/tinymce/plugins/joomlamore/plugin.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tinymce.PluginManager.add("joomlamore", function(editor) {
editor.addCommand("mceJoomlaMore", function() {
var myRe = /<hr\s*(id="system-readmore")/gi,
tiny_text = editor.getContent(),
is_set = myRe.exec(tiny_text);

if (is_set != null) {
alert(hrExists);
}
else
{
editor.insertContent("<hr id=\"system-readmore\" />");
}
}), editor.addButton("joomlamore", {
text: 'J Read More',
title: "Joomla Read More",
icon: 'pagebreak',
cmd: "mceJoomlaMore"
}), editor.addMenuItem("joomlamore", {
text: "Joomla Read More",
icon: "pagebreak",
cmd: "mceJoomlaMore",
context: "insert"
})
});
25 changes: 25 additions & 0 deletions media/editors/tinymce/plugins/joomlapager/plugin.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tinymce.PluginManager.add("joomlapager", function(editor, url) {
editor.addButton("joomlapager", {
text: "J Page Break",
title: "Joomla Page Break",
icon: "copy",
onclick: function () {
editor.windowManager.open({
title : 'Page Break',
body : [{
type : 'textbox',
name : 'title',
label: 'Title:'
},
{
type : 'textbox',
name : 'id',
label: 'Alternative:'
}],
onsubmit: function (e) {
editor.insertContent('<hr class="system-pagebreak" title="' + e.data.title + '" alt="' + e.data.id + '" />');
}
});
}
})
});
116 changes: 108 additions & 8 deletions plugins/editors/tinymce/tinymce.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public function onInit()
$toolbar2_add = array();
$toolbar3_add = array();
$toolbar4_add = array();
$toolbar5_add = array();
$elements = array();
$plugins = array(
'autolink',
Expand Down Expand Up @@ -602,15 +603,22 @@ public function onInit()
$toolbar4_add[] = $custom_button;
}

$toolbar5_add[] = 'joomlamore';
$toolbar5_add[] = 'joomlaimage';
$toolbar5_add[] = 'joomlapager';
$toolbar5_add[] = 'joomlaarticle';
$toolbar5_add[] = '| code';

// Prepare config variables
$plugins = implode(',', $plugins);
$plugins = implode(' ', $plugins);
$elements = implode(',', $elements);

// Prepare config variables
$toolbar1 = implode(' ', $toolbar1_add);
$toolbar2 = implode(' ', $toolbar2_add);
$toolbar3 = implode(' ', $toolbar3_add);
$toolbar4 = implode(' ', $toolbar4_add);
$toolbar5 = implode(' ', $toolbar5_add);

// See if mobileVersion is activated
$mobileVersion = $this->params->get('mobile', 0);
Expand All @@ -619,6 +627,21 @@ public function onInit()
JUri::root() . $this->_basePath .
"/tinymce.min.js\"></script>\n";

// User check for images ACL
$asset = $this->app->scope;
$user = JFactory::getUser();

if ( $user->authorise('core.edit', $this->app->scope)
|| $user->authorise('core.create', $this->app->scope)
|| (count($user->getAuthorisedCategories($this->app->scope, 'core.create')) > 0)
|| (count($user->getAuthorisedCategories($this->app->scope, 'core.edit')) > 0))
{
$author = $user->id;
$link = JUri::root(true) .
'index.php?option=com_media&amp;view=images&amp;tmpl=component&amp;asset=' .
$asset . '&amp;author=' . $author . '&amp;tiny=1&amp;e_name=';
}

/**
* Shrink the buttons if not on a mobile or if mobile view is off.
* If mobile view is on force into simple mode and enlarge the buttons
Expand All @@ -637,6 +660,11 @@ public function onInit()
$mode = 0;
}

// We need a string for the alert of read more
$lang = JFactory::getLanguage();
$lang->load('plg_editors-xtd_readmore', JPATH_ADMINISTRATOR, $lang->getTag(), true);
$alertText = JText::_('PLG_READMORE_ALREADY_EXISTS');

switch ($mode)
{
case 0: /* Simple mode*/
Expand All @@ -653,7 +681,8 @@ public function onInit()
theme : \"$theme\",
schema: \"html5\",
menubar: false,
toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist\",
toolbar1: \"bold italics underline strikethrough | undo redo | bullist numlist | $toolbar5\",
plugins : \"code, joomlamore, joomlaimage, joomlaarticle, joomlapager\",
// Cleanup/Output
inline_styles : true,
gecko_spellcheck : true,
Expand All @@ -667,6 +696,9 @@ public function onInit()
$content_css
document_base_url : \"" . JUri::root() . "\"
});
var hrExists = \"" . $alertText . "\",
imgLink = \"$link\",
toc = \"" . JSession::getFormToken() . "\";
</script>";
break;

Expand Down Expand Up @@ -696,10 +728,11 @@ public function onInit()
$smallButtons
invalid_elements : \"$invalid_elements\",
// Plugins
plugins : \"table link image code hr charmap autolink lists importcss\",
plugins : \"table link image code hr charmap autolink lists importcss code joomlamore joomlaimage joomlaarticle joomlapager\",
// Toolbar
toolbar1: \"$toolbar1\",
toolbar2: \"$toolbar2\",
toolbar3: \"$toolbar5\",
removed_menuitems: \"newdocument\",
// URL
relative_urls : $relative_urls,
Expand All @@ -714,6 +747,9 @@ public function onInit()
width : \"$html_width\",

});
var hrExists = \"" . $alertText . "\",
imgLink = \"$link\",
toc = \"" . JSession::getFormToken() . "\";
</script>";
break;

Expand All @@ -740,12 +776,12 @@ public function onInit()
$smallButtons
invalid_elements : \"$invalid_elements\",
// Plugins
plugins : \"$plugins\",
plugins : \"$plugins, code joomlamore joomlaimage joomlaarticle joomlapager\",
// Toolbar
toolbar1: \"$toolbar1\",
toolbar2: \"$toolbar2\",
toolbar3: \"$toolbar3\",
toolbar4: \"$toolbar4\",
toolbar4: \"$toolbar4 | $toolbar5\",
removed_menuitems: \"newdocument\",
// URL
relative_urls : $relative_urls,
Expand Down Expand Up @@ -778,6 +814,9 @@ public function onInit()
width : \"$html_width\",

});
var hrExists = \"" . $alertText . "\",
imgLink = \"$link\",
toc = \"" . JSession::getFormToken() . "\";
</script>";
break;
}
Expand Down Expand Up @@ -859,7 +898,7 @@ function jInsertEditorText( text, editor )
*
* @return string
*/
public function onDisplay($name, $content, $width, $height, $col, $row, $buttons = true, $id = null, $asset = null, $author = null)
public function onDisplay($name, $content, $width, $height, $col, $row, $buttons = false, $id = null, $asset = null, $author = null)
{
if (empty($id))
{
Expand Down Expand Up @@ -890,7 +929,6 @@ public function onDisplay($name, $content, $width, $height, $col, $row, $buttons
$editor = '<div class="editor">';
$editor .= JLayoutHelper::render('joomla.tinymce.textarea', $textarea);
$editor .= $this->_displayButtons($id, $buttons, $asset, $author);
$editor .= $this->_toogleButton($id);
$editor .= '</div>';

return $editor;
Expand Down Expand Up @@ -932,12 +970,74 @@ private function _displayButtons($name, $buttons, $asset, $author)
{
$buttons = $this->_subject->getButtons($name, $buttons, $asset, $author);

$return .= JLayoutHelper::render('joomla.editors.buttons', $buttons);
foreach ($buttons as $button)
{
$but[] = get_object_vars($button);
}

// Load the lang strings for the buttons
$lang = JFactory::getLanguage();
$lang->load('plg_editors-xtd_article', JPATH_ADMINISTRATOR, $lang->getTag(), true);
$lang->load('plg_editors-xtd_image', JPATH_ADMINISTRATOR, $lang->getTag(), true);
$lang->load('plg_editors-xtd_pagebreak', JPATH_ADMINISTRATOR, $lang->getTag(), true);
$lang->load('plg_editors-xtd_readmore', JPATH_ADMINISTRATOR, $lang->getTag(), true);
$trArticle = JText::_('PLG_ARTICLE_BUTTON_ARTICLE');
$trBreak = JText::_('PLG_EDITORSXTD_PAGEBREAK_BUTTON_PAGEBREAK');
$trImage = JText::_('PLG_IMAGE_BUTTON_IMAGE');
$trMore = JText::_('PLG_READMORE_BUTTON_READMORE');

foreach ($but as $butt)
{
if (in_array($butt['text'], array($trArticle, $trBreak, $trImage, $trMore)))
{
$but = $this->removeElementWithValue($but, "text", $butt['text']);
}
else
{
$butt2 = new JObject;
$butt2->modal = $butt['modal'];
$butt2->class = $butt['class'];
$butt2->link = $butt['link'];
$butt2->text = $butt['text'];
$butt2->name = $butt['name'];
if (isset($butt['options']))
{
$butt2->options = $butt['options'];
}
$nbutt[] = $butt2;
}
}

if ((isset($nbutt) && is_array($nbutt)) || (isset($nbutt) && (is_bool($nbutt) && $nbutt)))
{
$return .= JLayoutHelper::render('joomla.editors.buttons', $nbutt);
}
}

return $return;
}

/**
* Array helper funtion to remove specific arrays by key-value
*
* @param array $array the parent array
* @param string $key the key
* @param string $value the value
*
* @return array
*/
private function removeElementWithValue($array, $key, $value)
{
foreach ($array as $subKey => $subArray)
{
if ($subArray[$key] == $value)
{
unset($array[$subKey]);
}
}
return $array;
}

/**
* Get the toggle editor button
*
Expand Down