getNullDate();
// Get the COMPONENT only parameters
$params = clone( JComponentHelper::getParams('com_flexicontent') );
// Some flags
$enable_translation_groups = $params->get("enable_translation_groups");
$print_logging_info = $params->get('print_logging_info');
if ( $print_logging_info ) global $fc_run_times;
// *****************
// Load JS/CSS files
// *****************
// Add css to document
$document->addStyleSheet(JURI::base(true).'/components/com_flexicontent/assets/css/flexicontentbackend.css');
FLEXI_J30GE ?
$document->addStyleSheet(JURI::base(true).'/components/com_flexicontent/assets/css/j3x.css') :
$document->addStyleSheet(JURI::base(true).'/components/com_flexicontent/assets/css/j25.css') ;
// Add JS frameworks
flexicontent_html::loadFramework('select2');
$prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable');
flexicontent_html::loadFramework('flexi-lib');
// Add js function to overload the joomla submitform validation
JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden
$document->addScript(JURI::root(true).'/components/com_flexicontent/assets/js/admin.js');
$document->addScript(JURI::root(true).'/components/com_flexicontent/assets/js/validate.js');
// Add js function for custom code used by FLEXIcontent item form
$document->addScript(JURI::root(true).'/components/com_flexicontent/assets/js/itemscreen.js');
// ***********************
// Get data from the model
// ***********************
if ( $print_logging_info ) $start_microtime = microtime(true);
$model = $this->getModel();
$item = $model->getItem();
$form = $this->get('Form');
if ( $print_logging_info ) $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
// ***************************
// Get Associated Translations
// ***************************
if ($enable_translation_groups) $langAssocs = $this->get( 'LangAssocs' );
$langs = FLEXIUtilities::getLanguages('code');
// Get item id and new flag
$cid = $model->getId();
$isnew = ! $cid;
// Create and set a unique item id for plugins that needed it
if ($cid) {
$unique_tmp_itemid = $cid;
} else {
$unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid');
$unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true);
}
//print_r($unique_tmp_itemid);
JRequest::setVar( 'unique_tmp_itemid', $unique_tmp_itemid );
// Get number of subscribers
$subscribers = $model->getSubscribersCount();
// ******************
// Version Panel data
// ******************
// Get / calculate some version related variables
$versioncount = $model->getVersionCount();
$versionsperpage = $params->get('versionsperpage', 10);
$pagecount = (int) ceil( $versioncount / $versionsperpage );
// Data need by version panel: (a) current version page, (b) currently active version
$current_page = 1; $k=1;
$allversions = $model->getVersionList();
foreach($allversions as $v)
{
if ( $k > 1 && (($k-1) % $versionsperpage) == 0 )
$current_page++;
if ( $v->nr == $item->version ) break;
$k++;
}
// Finally fetch the version data for versions in current page
$versions = $model->getVersionList( ($current_page-1)*$versionsperpage, $versionsperpage );
// *****************
// Type related data
// *****************
// Get available types and the currently selected/requested type
$types = $model->getTypeslist();
$typesselected = $model->getTypesselected();
// Get and merge type parameters
$tparams = $this->get( 'Typeparams' );
$tparams = new JRegistry($tparams);
$params->merge($tparams); // Apply type configuration if it type is set
// Get user allowed permissions on the item ... to be used by the form rendering
// Also hide parameters panel if user can not edit parameters
$perms = $this->_getItemPerms($item);
if (!$perms['canparams']) $document->addStyleDeclaration( '#details-options {display:none;}' );
// ******************
// Create the toolbar
// ******************
$toolbar = JToolBar::getInstance('toolbar');
$tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
// SET toolbar title
if ( $cid )
{
JToolBarHelper::title( JText::_( 'FLEXI_EDIT_ITEM' ), 'itemedit' ); // Editing existing item
} else {
JToolBarHelper::title( JText::_( 'FLEXI_NEW_ITEM' ), 'itemadd' ); // Creating new item
}
// Add a preview button for LATEST version of the item
$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef');
if ( $cid )
{
// Domain URL and autologin vars
$server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
$autologin = ''; //$params->get('autoflogin', 1) ? '&fcu='.$user->username . '&fcp='.$user->password : '';
// Check if we are in the backend, in the back end we need to set the application to the site app instead
// we do not remove 'isAdmin' check so that we can copy later without change, e.g. to a plugin
$isAdmin = JFactory::getApplication()->isAdmin();
if ( $isAdmin && !defined('SH404SEF_IS_RUNNING') ) JFactory::$application = JApplication::getInstance('site');
// Create the URL
$item_url = FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug);
$item_url = defined('SH404SEF_IS_RUNNING') ?
Sh404sefHelperGeneral::getSefFromNonSef($item_url, $fullyQualified = true, $xhtml = false, $ssl = null) :
JRoute::_($item_url);
// Check if we are in the backend again
// In backend we need to remove administrator from URL as it is added even though we've set the application to the site app
if( $isAdmin && !defined('SH404SEF_IS_RUNNING') ) {
$admin_folder = str_replace(JURI::root(true),'',JURI::base(true));
$item_url = str_replace($admin_folder.'/', '/', $item_url);
// Restore application
JFactory::$application = JApplication::getInstance('administrator');
}
$previewlink = /*$server .*/ $item_url. (strstr($item_url, '?') ? '&' : '?') .'preview=1' . $autologin;
//$previewlink = str_replace('&', '&', $previewlink);
//$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin;
if ( !$params->get('use_versioning', 1) || ($item->version == $item->current_version && $item->version == $item->last_version) )
{
$toolbar->appendButton( 'Custom', '', 'preview' );
} else {
// Add a preview button for (currently) LOADED version of the item
$previewlink_loaded_ver = $previewlink .'&version='.$item->version;
$toolbar->appendButton( 'Custom', '', 'preview' );
// Add a preview button for currently ACTIVE version of the item
$previewlink_active_ver = $previewlink .'&version='.$item->current_version;
$toolbar->appendButton( 'Custom', '', 'preview' );
// Add a preview button for currently LATEST version of the item
$previewlink_last_ver = $previewlink; //'&version='.$item->last_version;
$toolbar->appendButton( 'Custom', '', 'preview' );
}
JToolBarHelper::spacer();
JToolBarHelper::divider();
JToolBarHelper::spacer();
}
// Common Buttons
// Applying new item type is a special case that has not loaded custom fieds yet
JToolBarHelper::apply($item->type_id ? 'items.apply' : 'items.apply_type', !$isnew ? 'FLEXI_APPLY' : ($typesselected->id ? 'FLEXI_ADD' : 'FLEXI_APPLY_TYPE' ), false);
if (!$isnew || $item->version) flexicontent_html::addToolBarButton(
'FLEXI_FAST_APPLY', $btn_name='apply_ajax', $full_js="Joomla.submitbutton('items.apply_ajax')", $msg_alert='', $msg_confirm='',
$btn_task='items.apply_ajax', $extra_js='', $btn_list=false, $btn_menu=true, $btn_confirm=false, $btn_class="btn-info".$tip_class, $btn_icon="icon-loop",
'data-placement="bottom" title="Fast saving, without reloading the form.
Note: new files will not be uploaded, - in such a case please use \'Apply\'"');
if (!$isnew || $item->version) JToolBarHelper::save('items.save');
if (!$isnew || $item->version) JToolBarHelper::custom( 'items.saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false );
JToolBarHelper::cancel('items.cancel');
// Check if saving an item that translates an original content in site's default language
$is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0,2) == substr($item->language, 0,2);
$modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id!=$item->id;
// *****************************************************************************
// Get (CORE & CUSTOM) fields and their VERSIONED values and then
// (a) Apply Content Type Customization to CORE fields (label, description, etc)
// (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField'
// *****************************************************************************
if ( $print_logging_info ) $start_microtime = microtime(true);
$fields = $this->get( 'Extrafields' );
$item->fields = & $fields;
if ( $print_logging_info ) $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
if ( $print_logging_info ) $start_microtime = microtime(true);
$jcustom = $app->getUserState('com_flexicontent.edit.item.custom'); //print_r($jcustom);
foreach ($fields as $field)
{
// a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description
// NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations
if ($field->iscore) {
FlexicontentFields::loadFieldConfig($field, $item);
}
// b. Create field 's editing HTML (the form field)
// NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow)
if (!$field->iscore)
{
$is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
if ( !$is_editable ) {
$field->html = '
';
} else {
if ( isset($jcustom[$field->name]) ) {
$field->value = array();
foreach ($jcustom[$field->name] as $i => $_val) {
$field->value[$i] = is_array($_val) ? serialize($_val) : $_val;
}
}
FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array( &$field, &$item ));
}
}
// c. Create main text field, via calling the display function of the textarea field (will also check for tabs)
if ($field->field_type == 'maintext')
{
if ( isset($item->item_translations) ) {
$shortcode = substr($item->language ,0,2);
foreach ($item->item_translations as $lang_id => $t) {
if ($shortcode == $t->shortcode) continue;
$field->name = array('jfdata',$t->shortcode,'text');
$field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8');
FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item) );
$t->fields->text->tab_labels = $field->tab_labels;
$t->fields->text->html = $field->html;
unset( $field->tab_labels );
unset( $field->html );
}
}
$field->name = 'text';
// NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data
$field->value[0] = $item->text; // do not decode special characters this was handled during saving !
// Render the field's (form) HTML
FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item) );
}
}
if ( $print_logging_info ) $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
// *************************
// Get tags used by the item
// *************************
$usedtagsIds = $this->get( 'UsedtagsIds' ); // NOTE: This will normally return the already set versioned value of tags ($item->tags)
$usedtags = $model->getUsedtagsData($usedtagsIds);
// *******************************
// Get categories used by the item
// *******************************
if ($isnew) {
// Case for preselected main category for new items
$maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0);
if (!$maincat) {
$maincat = $app->getUserStateFromRequest( $option.'.items.filter_cats', 'filter_cats', '', 'int' );
}
if ($maincat) {
$selectedcats = array($maincat);
$item->catid = $maincat;
} else {
$selectedcats = array();
}
if ( $tparams->get('cid_default') ) {
$selectedcats = $tparams->get('cid_default');
}
if ( $tparams->get('catid_default') ) {
$item->catid = $tparams->get('catid_default');
}
} else {
// NOTE: This will normally return the already set versioned value of categories ($item->categories)
$selectedcats = $this->get( 'Catsselected' );
}
//$selectedcats = $isnew ? array() : $fields['categories']->value;
//echo " row->tags: "; print_r($item->tags);
//echo " usedtagsIds: "; print_r($usedtagsIds);
//echo " usedtags (data): "; print_r($usedtags);
//echo " row->categories: "; print_r($item->categories);
//echo " selectedcats: "; print_r($selectedcats);
// *********************************************************************************************
// Build select lists for the form field. Only few of them are used in J1.6+, since we will use:
// (a) form XML file to declare them and then (b) getInput() method form field to create them
// *********************************************************************************************
// First clean form data, we do this after creating the description field which may contain HTML
JFilterOutput::objectHTMLSafe( $item, ENT_QUOTES );
$lists = array();
// build state list
$non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state==-3 || $item->state==-4 ;
$special_privelege_stategrp = ($item->state==2 || $perms['canarchive']) || ($item->state==-2 || $perms['candelete']) ;
$state = array();
// Using