Skip to content

Instantly share code, notes, and snippets.

@BruceGitHub
Last active June 27, 2017 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BruceGitHub/df5e1305dd69bfe88be58c6099f7f64a to your computer and use it in GitHub Desktop.
Save BruceGitHub/df5e1305dd69bfe88be58c6099f7f64a to your computer and use it in GitHub Desktop.
Personalizzare il componente content con gli override - Seconda parte (refactor)
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
JHtml::_('behavior.formvalidator');
JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', 'select', null, array('disable_search_threshold' => 0 ));
$this->configFieldsets = array('editorConfig');
$this->hiddenFieldsets = array('basic-limited');
$this->ignore_fieldsets = array('jmetadata', 'item_associations');
// Create shortcut to parameters.
$params = $this->state->get('params');
$app = JFactory::getApplication();
$input = $app->input;
$assoc = JLanguageAssociations::isEnabled();
// This checks if the config options have ever been saved. If they haven't they will fall back to the original settings.
$params = json_decode($params);
$editoroptions = isset($params->show_publishing_options);
if (!$editoroptions)
{
$params->show_publishing_options = '1';
$params->show_article_options = '1';
$params->show_urls_images_backend = '0';
$params->show_urls_images_frontend = '0';
}
// Check if the article uses configuration settings besides global. If so, use them.
if (isset($this->item->attribs['show_publishing_options']) && $this->item->attribs['show_publishing_options'] != '')
{
$params->show_publishing_options = $this->item->attribs['show_publishing_options'];
}
if (isset($this->item->attribs['show_article_options']) && $this->item->attribs['show_article_options'] != '')
{
$params->show_article_options = $this->item->attribs['show_article_options'];
}
if (isset($this->item->attribs['show_urls_images_frontend']) && $this->item->attribs['show_urls_images_frontend'] != '')
{
$params->show_urls_images_frontend = $this->item->attribs['show_urls_images_frontend'];
}
if (isset($this->item->attribs['show_urls_images_backend']) && $this->item->attribs['show_urls_images_backend'] != '')
{
$params->show_urls_images_backend = $this->item->attribs['show_urls_images_backend'];
}
JFactory::getDocument()->addScriptDeclaration('
Joomla.submitbutton = function(task)
{
if (task == "article.cancel" || document.formvalidator.isValid(document.getElementById("item-form")))
{
jQuery("#permissions-sliders select").attr("disabled", "disabled");
'
//. $this->form->getField('articletext')->save()
. '
Joomla.submitform(task, document.getElementById("item-form"));
if (task !== "article.apply")
{
window.parent.jQuery("#articleEdit' . (int) $this->item->id . 'Modal").modal("hide");
}
}
};
');
// echo '<pre>';
// print_r($this->form);
// print_r($this->form->getValue('articletext'));
// die('stop');
JFactory::getDocument()->addScriptDeclaration('
jQuery(document).ready(function(){
jQuery(\'#jform_catid\').find(\'option:selected\').removeAttr(\'selected\');
jQuery("select[name=\'jform[catid]\']").find("option[value=\'20\']").attr("selected",true);
function ReloadAllVideo(){
jQuery("#list_of_video").empty();
var myKeyYoutube = "chiave youtube";
var myChannelID = "chiave canale";
jQuery.ajax({
cache: false,
data: jQuery.extend({
key: myKeyYoutube,
channelId: myChannelID,
part: \'snippet,id\',
order: \'date\',
type:\'video\'
}, {maxResults:30,pageToken:jQuery("#pageToken").val()}),
dataType: \'jsonp\',
type: \'GET\',
timeout: 5000,
url: \'https://www.googleapis.com/youtube/v3/search\'
})
.done(function(data) {
//alert(myMaxResult);
if (typeof data.prevPageToken === "undefined") {jQuery("#pageTokenPrev").hide();}else{jQuery("#pageTokenPrev").show();}
if (typeof data.nextPageToken === "undefined") {jQuery("#pageTokenNext").hide();}else{jQuery("#pageTokenNext").show();}
jQuery("#pageTokenNext").val(data.nextPageToken);
jQuery("#pageTokenPrev").val(data.prevPageToken);
var $ul = jQuery("#list_of_video");
jQuery.each(data.items, function(idx, item){
var url = item.snippet.thumbnails.default.url;
var currValue = "' . strip_tags($this->form->getValue('articletext')) .'";
var cssClass ="";
if (currValue == item.id.videoId) {
cssClass="selectVideo";
}
else {
cssClass="";
}
$ul.append("<div data-target=\'"+ item.snippet.title + "\' id=\'"+item.id.videoId+"\' style=\'float:left;height:90px;margin-bottom:1px;margin-right:8px;\' class=\'" + cssClass + " list-group-item list-group-item-info\' >"
+ "<img height=\'90\' width=\'90\' src=\'"+ url + "\' />"
//+ item.snippet.title
+ "</div>");
});
});
}
ReloadAllVideo();
jQuery("#pageTokenNext").on( "click", function( event ) {
jQuery("#pageToken").val(jQuery("#pageTokenNext").val());
ReloadAllVideo();
});
jQuery("#pageTokenPrev").on( "click", function( event ) {
jQuery("#pageToken").val(jQuery("#pageTokenPrev").val());
ReloadAllVideo();
});
});
');
JFactory::getDocument()->addScriptDeclaration('
jQuery(function() {
jQuery(\'#list_of_video\').on(\'click\', \'div\', function() {
jQuery(\'#list_of_video div\').removeClass(\'selectVideo\');
jQuery(this).addClass(\'selectVideo\');
var data = jQuery(this).attr(\'data-target\');
jQuery(\'#jform_title\').val(data);
jQuery(\'#jform_alias\').val(\'\');
//{youtube}QJIVbnqk7SE|600|450|0{/youtube}
jQuery(\'#jform_articletext\').html(\'{youtube}\'+ this.id + \'|600|450|0{/youtube}\');
});
});
');
// In case of modal
$isModal = $input->get('layout') == 'modal' ? true : false;
$layout = $isModal ? 'modal' : 'editvideo';
$tmpl = $isModal || $input->get('tmpl', '', 'cmd') === 'component' ? '&tmpl=component' : '';
?>
<h1> > Gestione inserimento video </h1>
<form action="<?php echo JRoute::_('index.php?option=com_content&layout=' . $layout . $tmpl . '&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">
<?php echo JLayoutHelper::render('joomla.edit.title_alias', $this); ?>
<div class="form-horizontal">
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_CONTENT_ARTICLE_CONTENT')); ?>
<div class="row-fluid">
<div class="span12" >
<h2>Elenco video (Clicca su un video per caricarlo) </h2>
<div id="block_list_of_video" style="width:100%;overflow:scroll">
<ul class="list-group" id="list_of_video">
</ul>
</div>
<input type="hidden" id="pageToken" value="">
<div>
<button type="button" id="pageTokenPrev" value="" >Prev</button>
<button type="button" id="pageTokenNext" value="" >Next</button>
</div>
</div>
<div class="span9" style="margin-top:40px;">
<fieldset class="adminform">
<?php
//echo $this->form->getInput('articletext');
// print_r($this->form->getInput('articletext'));
// die('stop');
?>
<textarea
name="jform[articletext]"
id="jform_articletext"
cols=""
rows=""
style="visibility: hidden; width: 100%; height: 500px;"
class="mce_editable"></textarea>
</fieldset>
</div>
<div class="span3">
<?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php // Do not show the images and links options if the edit form is configured not to. ?>
<?php
$params->show_urls_images_backend = 0;
if ($params->show_urls_images_backend == 1) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'images', JText::_('COM_CONTENT_FIELDSET_URLS_AND_IMAGES')); ?>
<div class="row-fluid form-horizontal-desktop">
<div class="span6">
<?php echo $this->form->renderField('images'); ?>
<?php foreach ($this->form->getGroup('images') as $field) : ?>
<?php echo $field->renderField(); ?>
<?php endforeach; ?>
</div>
<div class="span6">
<?php foreach ($this->form->getGroup('urls') as $field) : ?>
<?php echo $field->renderField(); ?>
<?php endforeach; ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php $this->show_options = $params->show_article_options; ?>
<?php $this->show_options = 0; ?>
<?php echo JLayoutHelper::render('joomla.edit.params', $this); ?>
<?php // Do not show the publishing options if the edit form is configured not to. ?>
<?php
$params->show_publishing_options = 0;
if ($params->show_publishing_options == 1) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'publishing', JText::_('COM_CONTENT_FIELDSET_PUBLISHING')); ?>
<div class="row-fluid form-horizontal-desktop">
<div class="span6">
<?php echo JLayoutHelper::render('joomla.edit.publishingdata', $this); ?>
</div>
<div class="span6">
<?php echo JLayoutHelper::render('joomla.edit.metadata', $this); ?>
</div>
</div>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php
//if ( ! $isModal && $assoc) :
if (false) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'associations', JText::_('JGLOBAL_FIELDSET_ASSOCIATIONS')); ?>
<?php echo $this->loadTemplate('associations'); ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php elseif ($isModal && $assoc) : ?>
<div class="hidden"><?php echo $this->loadTemplate('associations'); ?></div>
<?php endif; ?>
<?php
//$this->canDo->get('core.admin')
if (false) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'editor', JText::_('COM_CONTENT_SLIDER_EDITOR_CONFIG')); ?>
<?php echo $this->form->renderFieldset('editorConfig'); ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php
//$this->canDo->get('core.admin')
if (false) : ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'permissions', JText::_('COM_CONTENT_FIELDSET_RULES')); ?>
<?php echo $this->form->getInput('rules'); ?>
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php endif; ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="return" value="<?php echo $input->getCmd('return'); ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment