Ejemplo n.º 1
0
        ?>
">
					<?php 
        echo $infoimage;
        ?>
				</span>
			</div>
			<?php 
    }
    ?>
		</div>
	</fieldset>
<?php 
    $captured['tags'] = ob_get_clean();
}
if (!isset($all_tab_fields['lang']) && $captured['lang'] || flexicontent_db::useAssociations() && $this->params->get('uselang_fe', 1) == 1) {
    ob_start();
    // language
    ?>
	<fieldset class="basicfields_set" id="fcform_language_container">
		<legend>
			<?php 
    echo !isset($all_tab_fields['lang']) ? JText::_('FLEXI_LANGUAGE') : JText::_('FLEXI_LANGUAGE') . ' ' . JText::_('FLEXI_ASSOCIATIONS');
    ?>
		</legend>
		
		<?php 
    if (!isset($all_tab_fields['lang'])) {
        echo $captured['lang'];
        unset($captured['lang']);
    }
Ejemplo n.º 2
0
foreach ($this->tmpls as $tmpl) {
	$layouts[] = $tmpl->name;
}
$layouts = implode("','", $layouts);

$this->document->addScriptDeclaration("
	window.addEvent('domready', function() {
		activatePanel('blog');
	});
	");
dump($this->row);
*/
?>

<?php 
$useAssocs = flexicontent_db::useAssociations();
// Load JS tabber lib
$this->document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/tabber-minimized.js', FLEXI_VERSION);
$this->document->addStyleSheetVersion(JURI::root(true) . '/components/com_flexicontent/assets/css/tabber.css', FLEXI_VERSION);
$this->document->addScriptDeclaration(' document.write(\'<style type="text/css">.fctabber{display:none;}<\\/style>\'); ');
// temporarily hide the tabbers until javascript runs
$js = "\n\tjQuery(document).ready(function(){\n\t\tfc_bindFormDependencies('#flexicontent', 0, '');\n\t});\n";
?>

<style>
.current:after{
	clear: both;
	content: "";
	display: block;
}
</style>
Ejemplo n.º 3
0
$end_text = '<div class="icon-arrow-up-2" title="' . JText::_('FLEXI_HIDE') . '" style="cursor: pointer;" onclick="fc_toggle_box_via_btn(\\\'mainChooseColBox\\\', document.getElementById(\\\'fc_mainChooseColBox_btn\\\'), \\\'btn-primary\\\');"></div>';
flexicontent_html::jscode_to_showhide_table('mainChooseColBox', 'adminListTableFCitems', $start_text, $end_text);
global $globalcats;
$cparams = JComponentHelper::getParams('com_flexicontent');
$limit = $this->pagination->limit;
$ctrl = 'items.';
$items_task = 'task=items.';
$cats_task = 'task=category.';
$db = JFactory::getDBO();
$config = JFactory::getConfig();
$nullDate = $db->getNullDate();
$user = JFactory::getUser();
//$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef') && $config->get('sef');
$_sh404sef = defined('SH404SEF_IS_RUNNING') && $config->get('sef');
$isAdmin = JFactory::getApplication()->isAdmin();
$enable_translation_groups = flexicontent_db::useAssociations();
//$cparams->get("enable_translation_groups");
$autologin = '';
//$cparams->get('autoflogin', 1) ? '&amp;fcu='.$user->username . '&amp;fcp='.$user->password : '';
$list_total_cols = 18;
if ($enable_translation_groups) {
    $list_total_cols++;
}
$list_total_cols += count($this->extra_fields);
$image_flag_path = "../media/mod_languages/images/";
$attribs_preview = ' class="fc-man-icon-s ' . $tip_class . '" title="' . flexicontent_html::getToolTip('FLEXI_PREVIEW', 'FLEXI_DISPLAY_ENTRY_IN_FRONTEND_DESC', 1, 1) . '" ';
$image_preview = JHTML::image('components/com_flexicontent/assets/images/' . 'monitor_go.png', JText::_('FLEXI_PREVIEW'), $attribs_preview);
$attribs_editlayout = ' class="fc-man-icon-s" title="' . flexicontent_html::getToolTip('FLEXI_EDIT_LAYOUT', null, 1, 1) . '" ';
$image_editlayout = JHTML::image('components/com_flexicontent/assets/images/' . 'layout_edit.png', JText::_('FLEXI_EDIT_LAYOUT'), $attribs_editlayout);
$ordering_draggable = $cparams->get('draggable_reordering', 1);
if ($this->ordering) {
Ejemplo n.º 4
0
    /**
     * Creates the item submit form
     *
     * @since 1.0
     */
    function _displayForm($tpl)
    {
        jimport('joomla.html.parameter');
        // ... we use some strings from administrator part
        // load english language file for 'com_content' component then override with current language file
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true);
        // load english language file for 'com_flexicontent' component then override with current language file
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true);
        JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true);
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $uri = JFactory::getURI();
        $nullDate = $db->getNullDate();
        $menu = $app->getMenu()->getActive();
        // We do not have item parameters yet, but we need to do some work before creating the item
        // Get the COMPONENT only parameter
        $params = new JRegistry();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $params->merge($cparams);
        // Merge the active menu parameters
        if ($menu) {
            $params->merge($menu->params);
        }
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$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
        // *****************
        FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools');
        flexicontent_html::loadFramework('jQuery');
        flexicontent_html::loadFramework('select2');
        flexicontent_html::loadFramework('flexi-lib');
        // Load custom behaviours: form validation, popup tooltips
        JHTML::_('behavior.formvalidation');
        // load default validation JS to make sure it is overriden
        JHTML::_('behavior.tooltip');
        if (FLEXI_J30GE) {
            JHtml::_('bootstrap.tooltip');
        }
        //JHTML::_('script', 'joomla.javascript.js', 'includes/js/');
        // Add css files to the document <head> section (also load CSS joomla template override)
        $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css');
        if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) {
            $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css');
        }
        // Fields common CSS
        $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexi_form_fields.css');
        // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend)
        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 function to overload the joomla submitform
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js');
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js');
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js');
        // *********************************************************
        // Get item data and create item form (that loads item data)
        // *********************************************************
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        $model = $this->getModel();
        // ** WE NEED TO get OR decide the Content Type, before we call the getItem
        // ** We rely on typeid Request variable to decide type for new items so make sure this is set,
        // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it!
        // Try type from session
        $jdata = $app->getUserState('com_flexicontent.edit.item.data');
        //print_r($jdata);
        if (!empty($jdata['type_id'])) {
            JRequest::setVar('typeid', (int) $jdata['type_id']);
            // This also forces zero if value not set
        } else {
            if ($menu && isset($menu->query['typeid'])) {
                JRequest::setVar('typeid', (int) $menu->query['typeid']);
                // This also forces zero if value not set
            }
        }
        $new_typeid = JRequest::getVar('typeid', 0, '', 'int');
        // Verify type is allowed to the user
        if (!$new_typeid) {
            $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true, $_published = true);
            if ($types && count($types) == 1) {
                $new_typeid = $types[0]->id;
            }
            JRequest::setVar('typeid', $new_typeid);
            $canCreateType = true;
        }
        // FORCE model to load versioned data (URL specified version or latest version (last saved))
        $version = JRequest::getVar('version', 0, 'request', 'int');
        // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form)
        $item = $model->getItem(null, $check_view_access = false, $no_cache = true, $force_version = $version != 0 ? $version : -1);
        // -1 version means latest
        // Replace component/menu 'params' with thee merged component/category/type/item/menu ETC ... parameters
        $params =& $item->parameters;
        if ($print_logging_info) {
            $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
        // Load permissions (used by form template)
        $perms = $this->_getItemPerms($item);
        // Create submit configuration (for new items) into the session, this is needed before creating the item form
        $submitConf = $this->_createSubmitConf($item, $perms);
        // Most core field are created via calling methods of the form (J2.5)
        $form = $this->get('Form');
        // is new item and ownership Flags
        $isnew = !$item->id;
        $isOwner = $item->created_by == $user->get('id');
        // Get available types and the currently selected/requested type
        $types = $model->getTypeslist();
        $typesselected = $model->getTypesselected();
        // Get type parameters, these are needed besides the 'merged' item parameters, e.g. to get Type's default layout
        $tparams = $this->get('Typeparams');
        $tparams = new JRegistry($tparams);
        // *********************************************************************************************************
        // Get language stuff, and also load Template-Specific language file to override or add new language strings
        // *********************************************************************************************************
        if ($enable_translation_groups) {
            $langAssocs = $params->get('uselang_fe') == 1 ? $this->get('LangAssocs') : false;
        }
        $langs = FLEXIUtilities::getLanguages('code');
        FLEXIUtilities::loadTemplateLanguageFile($params->get('ilayout', 'default'));
        // *************************************
        // Create captcha field via custom logic
        // *************************************
        // create and set (into HTTP request) a unique item id for plugins that needed it
        if ($item->id) {
            $unique_tmp_itemid = $item->id;
        } 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);
        // Component / Menu Item parameters
        $allowunauthorize = $params->get('allowunauthorize', 0);
        // allow unauthorised user to submit new content
        $unauthorized_page = $params->get('unauthorized_page', '');
        // page URL for unauthorized users (via global configuration)
        $notauth_itemid = $params->get('notauthurl', '');
        // menu itemid (to redirect) when user is not authorized to create content
        // Create captcha field or messages
        // Maybe some code can be removed by using Joomla's built-in form element (in XML file), instead of calling the captcha plugin ourselves
        $use_captcha = $params->get('use_captcha', 1);
        // 1 for guests, 2 for any user
        $captcha_formop = $params->get('captcha_formop', 0);
        // 0 for submit, 1 for submit/edit (aka always)
        $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest;
        $display_captcha = $display_captcha && ($isnew || $captcha_formop);
        // Trigger the configured captcha plugin
        if ($display_captcha) {
            // Get configured captcha plugin
            $c_plugin = $params->get('captcha', $app->getCfg('captcha'));
            // TODO add param to override default
            if ($c_plugin) {
                $c_name = 'captcha_response_field';
                $c_id = $c_plugin == 'recaptcha' ? 'dynamic_recaptcha_1' : 'fc_dynamic_captcha';
                $c_class = ' required';
                $c_namespace = 'fc_item_form';
                // Try to load the configured captcha plugin, (check if disabled or uninstalled), Joomla will enqueue an error message if needed
                $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => $c_namespace));
                if ($captcha_obj) {
                    $captcha_field = $captcha_obj->display($c_name, $c_id, $c_class);
                    $label_class = 'flexi_label';
                    $label_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip';
                    $label_tooltip = flexicontent_html::getToolTip(null, 'FLEXI_CAPTCHA_ENTER_CODE_DESC', 1, 1);
                    $captcha_field = '
						<label id="' . $c_name . '-lbl" for="' . $c_name . '" class="' . $label_class . '" title="' . $label_tooltip . '" >
						' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . '
						</label>
						<div id="container_fcfield_' . $c_plugin . '" class="container_fcfield container_fcfield_name_' . $c_plugin . '">
							<div class="fcfieldval_container valuebox fcfieldval_container_' . $c_plugin . '">
							' . $captcha_field . '
							</div>
						</div>';
                }
            }
        }
        // *******************************
        // CHECK EDIT / CREATE PERMISSIONS
        // *******************************
        // User Group / Author parameters
        $authorparams = flexicontent_db::getUserConfig($user->id);
        $max_auth_limit = intval($authorparams->get('max_auth_limit', 0));
        // maximum number of content items the user can create
        $hasTmpEdit = false;
        $hasCoupon = false;
        // Check session
        if ($session->has('rendered_uneditable', 'flexicontent')) {
            $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
            $hasTmpEdit = !empty($rendered_uneditable[$model->get('id')]);
            $hasCoupon = !empty($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')] == 2;
            // editable via coupon
        }
        if (!$isnew) {
            // EDIT action
            // Finally check if item is currently being checked-out (currently being edited)
            if ($model->isCheckedOut($user->get('id'))) {
                $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title'));
                $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg);
            }
            //Checkout the item
            $model->checkout();
            // Get edit access, this includes privileges edit and edit-own and the temporary EDIT flag ('rendered_uneditable')
            $canEdit = $model->getItemAccess()->get('access-edit');
            // If no edit privilege, check if edit COUPON was provided
            if (!$canEdit) {
                $edittok = JRequest::getCmd('edittok', false);
                if ($edittok) {
                    $query = 'SHOW TABLES LIKE "' . $app->getCfg('dbprefix') . 'flexicontent_edit_coupons"';
                    $db->setQuery($query);
                    $tbl_exists = (bool) count($db->loadObjectList());
                    if ($tbl_exists) {
                        $query = 'SELECT * FROM #__flexicontent_edit_coupons ' . ' WHERE token = ' . $db->Quote($edittok) . ' AND id = ' . $model->get('id');
                        $db->setQuery($query);
                        $tokdata = $db->loadObject();
                        if ($tokdata) {
                            $hasCoupon = true;
                            $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent');
                            $rendered_uneditable[$model->get('id')] = 2;
                            // 2: indicates, that has edit via EDIT Coupon
                            $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent');
                            $canEdit = 1;
                        } else {
                            JError::raiseNotice(403, JText::_('EDIT_TOKEN_IS_INVALID') . ' : ' . $edittok);
                        }
                    }
                }
            }
            // Edit check finished, throw error if needed
            if (!$canEdit) {
                if ($user->guest) {
                    $uri = JFactory::getURI();
                    $return = $uri->toString();
                    $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid));
                    // a special url parameter, used by some SEF code
                    $com_users = FLEXI_J16GE ? 'com_users' : 'com_user';
                    $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login');
                    $return = strtr(base64_encode($return), '+/=', '-_,');
                    $url .= '&return=' . $return;
                    //$url .= '&return='.urlencode(base64_encode($return));
                    $url .= '&fcreturn=' . base64_encode($fcreturn);
                    JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url));
                    $app->redirect($url);
                } else {
                    if ($unauthorized_page) {
                        //  unauthorized page via global configuration
                        JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK'));
                        $app->redirect($unauthorized_page);
                    } else {
                        // user isn't authorize to edit this content
                        $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK');
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        } else {
            // CREATE action
            // Get create access, this includes check of creating in at least one category, and type's "create items"
            $canAdd = $model->getItemAccess()->get('access-create');
            $not_authorised = !$canAdd;
            // Check if Content Type can be created by current user
            if (empty($canCreateType)) {
                if ($new_typeid) {
                    // not needed, already done be model when type_id is set, check and remove
                    $canCreateType = $model->canCreateType(array($new_typeid));
                    // Can create given Content Type
                } else {
                    // needed not done be model yet
                    $canCreateType = $model->canCreateType();
                    // Can create at least one Content Type
                }
            }
            $not_authorised = $not_authorised || !$canCreateType;
            // Allow item submission by unauthorized users, ... even guests ...
            if ($allowunauthorize == 2) {
                $allowunauthorize = !$user->guest;
            }
            if ($not_authorised && !$allowunauthorize) {
                if (!$canCreateType) {
                    $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY');
                    $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name);
                } else {
                    $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE');
                }
            } else {
                if ($max_auth_limit) {
                    $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id);
                    $authored_count = $db->loadResult();
                    $content_is_limited = $authored_count >= $max_auth_limit;
                    $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : '';
                }
            }
            if ($not_authorised && !$allowunauthorize || @$content_is_limited) {
                // User isn't authorize to add ANY content
                if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) {
                    // a. custom unauthorized submission page via menu item
                    $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : '';
                    $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false);
                    JError::raiseNotice(403, $msg);
                    $app->redirect($notauthurl);
                } else {
                    if ($unauthorized_page) {
                        // b. General unauthorized page via global configuration
                        JError::raiseNotice(403, $msg);
                        $app->redirect($unauthorized_page);
                    } else {
                        // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page
                        if (FLEXI_J16GE) {
                            throw new Exception($msg, 403);
                        } else {
                            JError::raiseError(403, $msg);
                        }
                    }
                }
            }
        }
        // *****************************************************************************
        // 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'
        // *****************************************************************************
        // Check if saving an item that translates an original content in site's default language
        $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2);
        $is_content_default_lang = $site_default == 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;
        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) {
                if (isset($jcustom[$field->name])) {
                    $field->value = array();
                    foreach ($jcustom[$field->name] as $i => $_val) {
                        $field->value[$i] = $_val;
                    }
                }
                $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                if ($is_editable) {
                    FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    if ($field->untranslatable) {
                        $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . $field->html;
                    }
                } else {
                    if ($field->valueseditable == 1) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                    } else {
                        if ($field->valueseditable == 2) {
                            FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                            $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display;
                        } else {
                            if ($field->valueseditable == 3) {
                                FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                                $field->html = $field->display;
                            } else {
                                if ($field->valueseditable == 4) {
                                    $field->html = '';
                                    $field->formhidden = 4;
                                }
                            }
                        }
                    }
                }
            }
            // 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;
        }
        // Tags used by the item
        $usedtagsids = $this->get('UsedtagsIds');
        // NOTE: This will normally return the already set versioned value of tags ($item->tags)
        $usedtagsdata = $model->getUsedtagsData($usedtagsids);
        // Get the edit lists
        $lists = $this->_buildEditLists($perms, $params, $authorparams);
        // Get number of subscribers
        $subscribers = $this->get('SubscribersCount');
        // Get menu overridden categories/main category fields
        $menuCats = $this->_getMenuCats($item, $perms);
        // Create placement configuration for CORE properties
        $placementConf = $this->_createPlacementConf($item, $fields);
        // Item language related vars
        $languages = FLEXIUtilities::getLanguages();
        $itemlang = new stdClass();
        $itemlang->shortcode = substr($item->language, 0, 2);
        $itemlang->name = $languages->{$item->language}->name;
        $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />';
        //Load the JEditor object
        $editor = JFactory::getEditor();
        // **********************************************************
        // Calculate a (browser window) page title and a page heading
        // **********************************************************
        // Verify menu item points to current FLEXIcontent object
        if ($menu) {
            $menu_matches = false;
            $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view'];
            $menu_matches = $view_ok;
            //$menu_params = $menu->params;  // Get active menu item parameters
        } else {
            $menu_matches = false;
        }
        // MENU ITEM matched, use its page heading (but use menu title if the former is not set)
        if ($menu_matches) {
            $default_heading = FLEXI_J16GE ? $menu->title : $menu->name;
            // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->def('page_heading', $params->get('page_title', $default_heading));
            $params->def('page_title', $params->get('page_heading', $default_heading));
            $params->def('show_page_heading', $params->get('show_page_title', 0));
            $params->def('show_page_title', $params->get('show_page_heading', 0));
        } else {
            // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ...
            $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW');
            // Decide to show page heading (=J1.5 page title), there is no need for this in item view
            $show_default_heading = 0;
            // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template)
            $params->set('page_title', $default_heading);
            $params->set('page_heading', $default_heading);
            $params->set('show_page_heading', $show_default_heading);
            $params->set('show_page_title', $show_default_heading);
        }
        // ************************************************************
        // Create the document title, by from page title and other data
        // ************************************************************
        // Use the page heading as document title, (already calculated above via 'appropriate' logic ...)
        $doc_title = $params->get('page_title');
        // Check and prepend or append site name
        // Add Site Name to page title
        if ($app->getCfg('sitename_pagetitles', 0) == 1) {
            $doc_title = $app->getCfg('sitename') . " - " . $doc_title;
        } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) {
            $doc_title = $doc_title . " - " . $app->getCfg('sitename');
        }
        // Finally, set document title
        $document->setTitle($doc_title);
        // Add title to pathway
        $pathway = $app->getPathWay();
        $pathway->addItem($doc_title, '');
        // Get pageclass suffix
        $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
        // Ensure the row data is safe html
        // @TODO: check if this is really required as it conflicts with the escape function in the tmpl
        //JFilterOutput::objectHTMLSafe( $item );
        $this->assign('action', $uri->toString());
        $this->assignRef('item', $item);
        $this->assignRef('form', $form);
        // most core field are created via calling methods of the form (J2.5)
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        $this->assignRef('langs', $langs);
        $this->assignRef('params', $params);
        $this->assignRef('lists', $lists);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('editor', $editor);
        $this->assignRef('user', $user);
        $this->assignRef('usedtagsdata', $usedtagsdata);
        $this->assignRef('fields', $fields);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('perms', $perms);
        $this->assignRef('document', $document);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('menuCats', $menuCats);
        $this->assignRef('submitConf', $submitConf);
        $this->assignRef('placementConf', $placementConf);
        $this->assignRef('itemlang', $itemlang);
        $this->assignRef('pageclass_sfx', $pageclass_sfx);
        $this->assign('captcha_errmsg', @$captcha_errmsg);
        $this->assign('captcha_field', @$captcha_field);
        // ****************************************************************
        // SET INTO THE FORM, parameter values for various parameter groups
        // ****************************************************************
        if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) {
            $item->publish_down = JText::_('FLEXI_NEVER');
        }
        // ****************************
        // Handle Template related work
        // ****************************
        // (a) Get the templates structures used to create form fields for template parameters
        $themes = flexicontent_tmpl::getTemplates();
        $tmpls_all = $themes->items;
        // (b) Get Content Type allowed templates
        $allowed_tmpls = $tparams->get('allowed_ilayouts');
        $type_default_layout = $tparams->get('ilayout', 'default');
        if (empty($allowed_tmpls)) {
            $allowed_tmpls = array();
        }
        if (!is_array($allowed_tmpls)) {
            $allowed_tmpls = explode("|", $allowed_tmpls);
        }
        // (c) Add default layout, unless all templates allowed (=array is empty)
        if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) {
            $allowed_tmpls[] = $type_default_layout;
        }
        // (d) Create array of template data according to the allowed templates for current content type
        if (count($allowed_tmpls)) {
            foreach ($tmpls_all as $tmpl) {
                if (in_array($tmpl->name, $allowed_tmpls)) {
                    $tmpls[] = $tmpl;
                }
            }
        } else {
            $tmpls = $tmpls_all;
        }
        // (e) Apply Template Parameters values into the form fields structures
        foreach ($tmpls as $tmpl) {
            if (FLEXI_J16GE) {
                $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
                $jform->load($tmpl->params);
                $tmpl->params = $jform;
                foreach ($tmpl->params->getGroup('attribs') as $field) {
                    $fieldname = $field->__get('fieldname');
                    $value = $item->itemparams->get($fieldname);
                    if (strlen($value)) {
                        $tmpl->params->setValue($fieldname, 'attribs', $value);
                    }
                }
            } else {
                $tmpl->params->loadINI($item->attribs);
            }
        }
        $this->assignRef('tmpls', $tmpls);
        // Clear custom form data from session
        $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false);
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        parent::display($tpl);
        if ($print_logging_info) {
            $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
    }
 /**
  * Method to save language associations
  *
  * @return  boolean True if successful
  */
 static function saveAssociations(&$item, &$data, $context)
 {
     $assoc = flexicontent_db::useAssociations();
     if (!$assoc) {
         return true;
     }
     // **********************************
     // Prepare / check associations array
     // **********************************
     // Unset empty associations from associations array, to avoid save them in the associations table
     $associations = isset($data['associations']) ? $data['associations'] : array();
     foreach ($associations as $tag => $id) {
         if (empty($id)) {
             unset($associations[$tag]);
         }
     }
     // Raise notice that associations should be empty if language of current item is '*' (ALL)
     $all_language = $item->language == '*';
     if ($all_language && !empty($associations)) {
         JError::raiseNotice(403, JText::_('FLEXI_ERROR_ALL_LANGUAGE_ASSOCIATED'));
     }
     // Make sure that current item id, is the association id of the language of the current item
     $associations[$item->language] = $item->id;
     // Make sure associations ids are integers
     JArrayHelper::toInteger($associations);
     // ***********************
     // Delete old associations
     // ***********************
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->delete('#__associations')->where($db->quoteName('context') . ' = ' . $db->quote($context . '.item'))->where($db->quoteName('id') . ' IN (' . implode(',', $associations) . ')');
     $db->setQuery($query);
     $db->execute();
     if ($error = $db->getErrorMsg()) {
         $this->setError($error);
         return false;
     }
     // ********************
     // Add new associations
     // ********************
     // Only add language associations if item language is not '*' (ALL)
     if ($all_language || !count($associations)) {
         return true;
     }
     $key = md5(json_encode($associations));
     $query->clear()->insert('#__associations');
     foreach ($associations as $id) {
         $query->values($id . ',' . $db->quote($context . '.item') . ',' . $db->quote($key));
     }
     $db->setQuery($query);
     $db->execute();
     if ($error = $db->getErrorMsg()) {
         $this->setError($error);
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
    /**
     * Creates the item page
     *
     * @since 1.0
     */
    function display($tpl = null)
    {
        // ********************************
        // Initialize variables, flags, etc
        // ********************************
        global $globalcats;
        $categories = $globalcats;
        $app = JFactory::getApplication();
        $dispatcher = JDispatcher::getInstance();
        $document = JFactory::getDocument();
        $config = JFactory::getConfig();
        $session = JFactory::getSession();
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $option = JRequest::getVar('option');
        $nullDate = $db->getNullDate();
        // Get the COMPONENT only parameters
        // Get component parameters
        $params = new JRegistry();
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $params->merge($cparams);
        $params = clone JComponentHelper::getParams('com_flexicontent');
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$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->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VERSION);
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VERSION);
        // Fields common CSS
        $document->addStyleSheetVersion(JURI::root(true) . '/components/com_flexicontent/assets/css/flexi_form_fields.css', FLEXI_VERSION);
        // 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->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VERSION);
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VERSION);
        // Add js function for custom code used by FLEXIcontent item form
        $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/itemscreen.js', FLEXI_VERSION);
        // ***********************
        // 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);
        // Create display of average rating
        $ratings = $model->getRatingDisplay();
        // *****************
        // 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
        }
        // **************
        // 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="".$tip_class, $btn_icon="icon-loop",
        		'data-placement="bottom" title="Fast saving, without reloading the form. <br/><br/>Note: new files will not be uploaded, <br/>- 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');
        // ***********************
        // Add a preview button(s)
        // ***********************
        //$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef') && $config->get('sef');
        $_sh404sef = defined('SH404SEF_IS_RUNNING') && $config->get('sef');
        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 && !$_sh404sef) {
                JFactory::$application = JApplication::getInstance('site');
            }
            // Create the URL
            $item_url = FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . ($item->language != '*' ? '&lang=' . substr($item->language, 0, 2) : '');
            $item_url = $_sh404sef ? 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 && !$_sh404sef) {
                $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 = $item_url . (strstr($item_url, '?') ? '&amp;' : '?') . 'preview=1' . $autologin;
            //$previewlink     = str_replace('&amp;', '&', $previewlink);
            //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin;
            // PREVIEW for latest version
            if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) {
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small btn-info spaced-btn" onClick="window.open(\'' . $previewlink . '\');"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('Preview') . '</button>', 'preview');
            } else {
                // Add a preview button for (currently) LOADED version of the item
                $previewlink_loaded_ver = $previewlink . '&version=' . $item->version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_loaded_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</button>', 'preview');
                // Add a preview button for currently ACTIVE version of the item
                $previewlink_active_ver = $previewlink . '&version=' . $item->current_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_active_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</button>', 'preview');
                // Add a preview button for currently LATEST version of the item
                $previewlink_last_ver = $previewlink;
                //'&version='.$item->last_version;
                $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_last_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</button>', 'preview');
            }
            JToolBarHelper::spacer();
            JToolBarHelper::divider();
            JToolBarHelper::spacer();
        }
        // ************************
        // Add modal layout editing
        // ************************
        if ($perms['cantemplates']) {
            JToolBarHelper::divider();
            if (!$isnew || $item->version) {
                flexicontent_html::addToolBarButton('FLEXI_EDIT_LAYOUT', $btn_name = 'apply_ajax', $full_js = "var url = jQuery(this).attr('data-href'); fc_showDialog(url, 'fc_modal_popup_container'); return false;", $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-pencil", 'data-placement="bottom" data-href="index.php?option=com_flexicontent&amp;view=template&amp;type=items&amp;tmpl=component&amp;ismodal=1&amp;folder=' . $item->itemparams->get('ilayout', $tparams->get('ilayout', 'default')) . '" title="Edit the display layout of this item. <br/><br/>Note: this layout maybe assigned to content types or other items, thus changing it will effect them too"');
            }
        }
        // Check if saving an item that translates an original content in site's default language
        $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2);
        $is_content_default_lang = $site_default == substr($item->language, 0, 2);
        // *****************************************************************************
        // 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) {
                if (isset($jcustom[$field->name])) {
                    $field->value = array();
                    foreach ($jcustom[$field->name] as $i => $_val) {
                        $field->value[$i] = $_val;
                    }
                }
                $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id);
                if ($is_editable) {
                    FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item));
                    if ($field->untranslatable) {
                        $field->html = (!isset($field->html) ? '<div class="fc-mssg-inline fc-warning" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_PLEASE_PUBLISH_THIS_PLUGIN') . '</div><div class="clear"></div>' : '') . '<div class="alert alert-info fc-small fc-iblock" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . (isset($field->html) ? '<div class="clear"></div>' . $field->html : '');
                    }
                } else {
                    if ($field->valueseditable == 1) {
                        $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>';
                    } else {
                        if ($field->valueseditable == 2) {
                            FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                            $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display;
                        } else {
                            if ($field->valueseditable == 3) {
                                FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item));
                                $field->html = $field->display;
                            } else {
                                if ($field->valueseditable == 4) {
                                    $field->html = '';
                                    $field->formhidden = 4;
                                }
                            }
                        }
                    }
                }
            }
            // 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 "<br/>row->tags: "; print_r($item->tags);
        //echo "<br/>usedtagsIds: "; print_r($usedtagsIds);
        //echo "<br/>usedtags (data): "; print_r($usedtags);
        //echo "<br/>row->categories: "; print_r($item->categories);
        //echo "<br/>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 <select> groups
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_PUBLISHERS_WORKFLOW_STATES'));
        }
        $state[] = JHTML::_('select.option', 1, JText::_('FLEXI_PUBLISHED'));
        $state[] = JHTML::_('select.option', 0, JText::_('FLEXI_UNPUBLISHED'));
        $state[] = JHTML::_('select.option', -5, JText::_('FLEXI_IN_PROGRESS'));
        // States reserved for workflow
        if ($non_publishers_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_NON_PUBLISHERS_WORKFLOW_STATES'));
        }
        if ($item->state == -3 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -3, JText::_('FLEXI_PENDING'));
        }
        if ($item->state == -4 || $perms['isSuperAdmin']) {
            $state[] = JHTML::_('select.option', -4, JText::_('FLEXI_TO_WRITE'));
        }
        // Special access states
        if ($special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
            $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_SPECIAL_ACTION_STATES'));
        }
        if ($item->state == 2 || $perms['canarchive']) {
            $state[] = JHTML::_('select.option', 2, JText::_('FLEXI_ARCHIVED'));
        }
        if ($item->state == -2 || $perms['candelete']) {
            $state[] = JHTML::_('select.option', -2, JText::_('FLEXI_TRASHED'));
        }
        // Close last <select> group
        if ($non_publishers_stategrp || $special_privelege_stategrp) {
            $state[] = JHTML::_('select.optgroup', '');
        }
        $fieldname = 'jform[state]';
        $elementid = 'jform_state';
        $class = 'use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $lists['state'] = JHTML::_('select.genericlist', $state, $fieldname, $attribs, 'value', 'text', $item->state, $elementid);
        if (!FLEXI_J16GE) {
            $lists['state'] = str_replace('<optgroup label="">', '</optgroup>', $lists['state']);
        }
        // *** BOF: J2.5 SPECIFIC SELECT LISTS
        if (FLEXI_J16GE) {
            // build featured flag
            $fieldname = 'jform[featured]';
            $elementid = 'jform_featured';
            /*
            $options = array();
            $options[] = JHTML::_('select.option',  0, JText::_( 'FLEXI_NO' ) );
            $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_YES' ) );
            $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
            $lists['featured'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', $item->featured, $elementid);
            */
            $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
            $attribs = ' class="' . $classes . '" ';
            $i = 1;
            $options = array(0 => JText::_('FLEXI_NO'), 1 => JText::_('FLEXI_YES'));
            $lists['featured'] = '';
            foreach ($options as $option_id => $option_label) {
                $checked = $option_id == $item->featured ? ' checked="checked"' : '';
                $elementid_no = $elementid . '_' . $i;
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
                if (!$prettycheckable_added) {
                    $lists['featured'] .= '&nbsp;' . JText::_($option_label) . '</label>';
                }
                $i++;
            }
        }
        // *** EOF: J1.5 SPECIFIC SELECT LISTS
        // build version approval list
        $fieldname = 'jform[vstate]';
        $elementid = 'jform_vstate';
        /*
        $options = array();
        $options[] = JHTML::_('select.option',  1, JText::_( 'FLEXI_NO' ) );
        $options[] = JHTML::_('select.option',  2, JText::_( 'FLEXI_YES' ) );
        $attribs = FLEXI_J16GE ? ' style ="float:left!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
        $lists['vstate'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', 2, $elementid);
        */
        $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
        $attribs = ' class="' . $classes . '" ';
        $i = 1;
        $options = array(1 => JText::_('FLEXI_NO'), 2 => JText::_('FLEXI_YES'));
        $lists['vstate'] = '';
        foreach ($options as $option_id => $option_label) {
            $checked = $option_id == 2 ? ' checked="checked"' : '';
            $elementid_no = $elementid . '_' . $i;
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">';
            }
            $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"';
            $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />';
            if (!$prettycheckable_added) {
                $lists['vstate'] .= '&nbsp;' . JText::_($option_label) . '</label>';
            }
            $i++;
        }
        // build field for notifying subscribers
        if (!$subscribers) {
            $lists['notify'] = !$isnew ? JText::_('FLEXI_NO_SUBSCRIBERS_EXIST') : '';
        } else {
            // b. Check if notification emails to subscribers , were already sent during current session
            $subscribers_notified = $session->get('subscribers_notified', array(), 'flexicontent');
            if (!empty($subscribers_notified[$item->id])) {
                $lists['notify'] = JText::_('FLEXI_SUBSCRIBERS_ALREADY_NOTIFIED');
            } else {
                // build favs notify field
                $fieldname = 'jform[notify]';
                $elementid = 'jform_notify';
                /*
                $attribs = FLEXI_J16GE ? ' style ="float:none!important;" '  :  '';   // this is not right for J1.5' style ="float:left!important;" ';
                $lists['notify'] = '<input type="checkbox" name="jform[notify]" id="jform_notify" '.$attribs.' /> '. $lbltxt;
                */
                $classes = !$prettycheckable_added ? '' : ' use_prettycheckable ';
                $attribs = ' class="' . $classes . '" ';
                $lbltxt = $subscribers . ' ' . JText::_($subscribers > 1 ? 'FLEXI_SUBSCRIBERS' : 'FLEXI_SUBSCRIBER');
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '<label class="fccheckradio_lbl" for="' . $elementid . '">';
                }
                $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"';
                $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />';
                if (!$prettycheckable_added) {
                    $lists['notify'] .= '&nbsp;' . $lbltxt . '</label>';
                }
            }
        }
        // Retrieve author configuration
        $authorparams = flexicontent_db::getUserConfig($user->id);
        // Get author's maximum allowed categories per item and set js limitation
        $max_cat_assign = intval($authorparams->get('max_cat_assign', 0));
        $document->addScriptDeclaration('
			max_cat_assign_fc = ' . $max_cat_assign . ';
			existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
		');
        JText::script('FLEXI_TOO_MANY_ITEM_CATEGORIES', true);
        // Creating categorories tree for item assignment, we use the 'create' privelege
        $actions_allowed = array('core.create');
        // Featured categories form field
        $featured_cats_parent = $params->get('featured_cats_parent', 0);
        $featured_cats = array();
        $enable_featured_cid_selector = $perms['multicat'] && $perms['canchange_featcat'];
        if ($featured_cats_parent) {
            $featured_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $featured_cats_parent, $depth_limit = 0);
            $disabled_cats = $params->get('featured_cats_parent_disable', 1) ? array($featured_cats_parent) : array();
            $featured_sel = array();
            foreach ($selectedcats as $item_cat) {
                if (isset($featured_tree[$item_cat])) {
                    $featured_sel[] = $item_cat;
                }
            }
            $class = "use_select2_lib select2_list_selected";
            $attribs = 'class="' . $class . '" multiple="multiple" size="8"';
            $attribs .= $enable_featured_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = 'jform[featured_cid][]';
            $lists['featured_cid'] = ($enable_featured_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($featured_tree, $fieldname, $featured_sel, 3, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            // Do not display, if not configured or not allowed to the user
            $lists['featured_cid'] = false;
        }
        // Multi-category form field, for user allowed to use multiple categories
        $lists['cid'] = '';
        $enable_cid_selector = $perms['multicat'] && $perms['canchange_seccat'];
        if (1) {
            if ($tparams->get('cid_allowed_parent')) {
                $cid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('cid_allowed_parent'), $depth_limit = 0);
                $disabled_cats = $tparams->get('cid_allowed_parent_disable', 1) ? array($tparams->get('cid_allowed_parent')) : array();
            } else {
                $cid_tree =& $categories;
                $disabled_cats = array();
            }
            // Get author's maximum allowed categories per item and set js limitation
            $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0));
            $document->addScriptDeclaration('
				max_cat_assign_fc = ' . $max_cat_assign . ';
				existing_cats_fc  = ["' . implode('","', $selectedcats) . '"];
			');
            $class = "mcat use_select2_lib select2_list_selected";
            $class .= $max_cat_assign ? " validate-fccats" : " validate";
            $attribs = 'class="' . $class . '" multiple="multiple" size="20"';
            $attribs .= $enable_cid_selector ? '' : ' disabled="disabled"';
            $fieldname = 'jform[cid][]';
            $skip_subtrees = $featured_cats_parent ? array($featured_cats_parent) : array();
            $lists['cid'] = ($enable_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($cid_tree, $fieldname, $selectedcats, false, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees, $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            if (count($selectedcats) > 1) {
                foreach ($selectedcats as $catid) {
                    $cat_titles[$catid] = $globalcats[$catid]->title;
                }
                $lists['cid'] .= implode(', ', $cat_titles);
            } else {
                $lists['cid'] = false;
            }
        }
        // Main category form field
        $class = 'scat use_select2_lib';
        if ($perms['multicat']) {
            $class .= ' validate-catid';
        } else {
            $class .= ' required';
        }
        $attribs = 'class="' . $class . '"';
        $fieldname = 'jform[catid]';
        $enable_catid_selector = $isnew && !$tparams->get('catid_default') || !$isnew && empty($item->catid) || $perms['canchange_cat'];
        if ($tparams->get('catid_allowed_parent')) {
            $catid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('catid_allowed_parent'), $depth_limit = 0);
            $disabled_cats = $tparams->get('catid_allowed_parent_disable', 1) ? array($tparams->get('catid_allowed_parent')) : array();
        } else {
            $catid_tree =& $categories;
            $disabled_cats = array();
        }
        $lists['catid'] = false;
        if (!empty($catid_tree)) {
            $disabled = $enable_catid_selector ? '' : ' disabled="disabled"';
            $attribs .= $disabled;
            $lists['catid'] = ($enable_catid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($catid_tree, $fieldname, $item->catid, 2, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats);
        } else {
            if (!$isnew && $item->catid) {
                $lists['catid'] = $globalcats[$item->catid]->title;
            }
        }
        //buid types selectlist
        $class = 'required use_select2_lib';
        $attribs = 'class="' . $class . '"';
        $fieldname = 'jform[type_id]';
        $elementid = 'jform_type_id';
        $lists['type'] = flexicontent_html::buildtypesselect($types, $fieldname, $typesselected->id, 1, $attribs, $elementid, $check_perms = true);
        //build languages list
        $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null);
        $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs);
        if (!$isnew && $allowed_langs) {
            $allowed_langs[] = $item->language;
        }
        // We will not use the default getInput() function of J1.6+ since we want to create a radio selection field with flags
        // we could also create a new class and override getInput() method but maybe this is an overkill, we may do it in the future
        $lists['languages'] = flexicontent_html::buildlanguageslist('jform[language]', 'class="use_select2_lib"', $item->language, 2, $allowed_langs);
        // Label for current item state: published, unpublished, archived etc
        switch ($item->state) {
            case 0:
                $published = JText::_('FLEXI_UNPUBLISHED');
                break;
            case 1:
                $published = JText::_('FLEXI_PUBLISHED');
                break;
            case -1:
                $published = JText::_('FLEXI_ARCHIVED');
                break;
            case -3:
                $published = JText::_('FLEXI_PENDING');
                break;
            case -5:
                $published = JText::_('FLEXI_IN_PROGRESS');
                break;
            case -4:
            default:
                $published = JText::_('FLEXI_TO_WRITE');
                break;
        }
        // **************************************************************
        // Handle Item Parameters Creation and Load their values for J1.5
        // In J1.6+ we declare them in the item form XML file
        // **************************************************************
        if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) {
            $form->setValue('publish_down', null, '');
            // Setting to text will break form date element
        }
        // ****************************
        // Handle Template related work
        // ****************************
        // (a) Get the templates structures used to create form fields for template parameters
        $themes = flexicontent_tmpl::getTemplates();
        $tmpls_all = $themes->items;
        // (b) Get Content Type allowed templates
        $allowed_tmpls = $tparams->get('allowed_ilayouts');
        $type_default_layout = $tparams->get('ilayout', 'default');
        if (empty($allowed_tmpls)) {
            $allowed_tmpls = array();
        } else {
            if (!is_array($allowed_tmpls)) {
                $allowed_tmpls = explode("|", $allowed_tmpls);
            }
        }
        // (c) Add default layout, unless all templates allowed (=array is empty)
        if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) {
            $allowed_tmpls[] = $type_default_layout;
        }
        // (d) Create array of template data according to the allowed templates for current content type
        if (count($allowed_tmpls)) {
            foreach ($tmpls_all as $tmpl) {
                if (in_array($tmpl->name, $allowed_tmpls)) {
                    $tmpls[] = $tmpl;
                }
            }
        } else {
            $tmpls = $tmpls_all;
        }
        // (e) Apply Template Parameters values into the form fields structures
        foreach ($tmpls as $tmpl) {
            $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true));
            $jform->load($tmpl->params);
            $tmpl->params = $jform;
            foreach ($tmpl->params->getGroup('attribs') as $field) {
                $fieldname = $field->__get('fieldname');
                $value = $item->itemparams->get($fieldname);
                if (strlen($value)) {
                    $tmpl->params->setValue($fieldname, 'attribs', $value);
                }
            }
        }
        // ******************************
        // Assign data to VIEW's template
        // ******************************
        $this->assignRef('document', $document);
        $this->assignRef('lists', $lists);
        $this->assignRef('row', $item);
        if (FLEXI_J16GE) {
            $this->assignRef('form', $form);
        } else {
            $this->assignRef('editor', $editor);
            $this->assignRef('pane', $pane);
            $this->assignRef('formparams', $formparams);
        }
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        if (FLEXI_FISH || FLEXI_J16GE) {
            $this->assignRef('langs', $langs);
        }
        $this->assignRef('typesselected', $typesselected);
        $this->assignRef('published', $published);
        $this->assignRef('nullDate', $nullDate);
        $this->assignRef('subscribers', $subscribers);
        $this->assignRef('fields', $fields);
        $this->assignRef('versions', $versions);
        $this->assignRef('ratings', $ratings);
        $this->assignRef('pagecount', $pagecount);
        $this->assignRef('params', $params);
        $this->assignRef('tparams', $tparams);
        $this->assignRef('tmpls', $tmpls);
        $this->assignRef('usedtags', $usedtags);
        $this->assignRef('perms', $perms);
        $this->assignRef('current_page', $current_page);
        // Clear custom form data from session
        $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false);
        $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false);
        if ($print_logging_info) {
            $start_microtime = microtime(true);
        }
        parent::display($tpl);
        if ($print_logging_info) {
            $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10;
        }
    }
Ejemplo n.º 7
0
 /**
  * Method to determine if J3.1+ associations should be used
  *
  * @return  boolean True if using J3 associations; false otherwise.
  */
 public function useAssociations()
 {
     return flexicontent_db::useAssociations();
 }
Ejemplo n.º 8
0
    function display($tpl = null)
    {
        // ***********
        // Batch tasks
        // ***********
        $app = JFactory::getApplication();
        $jinput = $app->input;
        $task = $jinput->get('task', '', 'cmd');
        $cid = $jinput->get('cid', array(), 'array');
        if ($task == 'copy') {
            $behaviour = $jinput->get('copy_behaviour', 'copy/move', 'string');
            $this->setLayout('copy');
            $this->_displayCopyMove($tpl, $cid, $behaviour);
            return;
        }
        // ********************
        // Initialise variables
        // ********************
        global $globalcats;
        $option = $jinput->get('option', '', 'cmd');
        $view = $jinput->get('view', '', 'cmd');
        $cparams = JComponentHelper::getParams('com_flexicontent');
        $user = JFactory::getUser();
        $db = JFactory::getDBO();
        $document = JFactory::getDocument();
        $session = JFactory::getSession();
        $bind_limit = $jinput->get('bind_limit', 1000, 'int');
        // Some flags
        $enable_translation_groups = flexicontent_db::useAssociations();
        //$cparams->get("enable_translation_groups");
        $print_logging_info = $cparams->get('print_logging_info');
        // Get model
        $model = $this->getModel();
        // ***********
        // Get filters
        // ***********
        $count_filters = 0;
        // File id filtering
        $fileid_to_itemids = $session->get('fileid_to_itemids', array(), 'flexicontent');
        $filter_fileid = $model->getState('filter_fileid');
        if ($filter_fileid) {
            $count_filters++;
        }
        // Order type, order, order direction
        $filter_order_type = $model->getState('filter_order_type');
        $filter_order = $model->getState('filter_order');
        $filter_order_Dir = $model->getState('filter_order_Dir');
        // Category filtering
        $filter_cats = $model->getState('filter_cats');
        $filter_subcats = $model->getState('filter_subcats');
        $filter_catsinstate = $model->getState('filter_catsinstate');
        if ($filter_cats) {
            $count_filters++;
        }
        if ($filter_subcats != 1) {
            $count_filters++;
        }
        if ($filter_catsinstate != 1) {
            $count_filters++;
        }
        // Other filters
        $filter_tag = $model->getState('filter_tag');
        $filter_lang = $model->getState('filter_lang');
        $filter_type = $model->getState('filter_type');
        $filter_author = $model->getState('filter_author');
        $filter_state = $model->getState('filter_state');
        $filter_access = $model->getState('filter_access');
        // Support for using 'ALL', 'ORPHAN' fake states, by clearing other values
        if (is_array($filter_state) && in_array('ALL', $filter_state)) {
            $filter_state = array('ALL');
        }
        if (is_array($filter_state) && in_array('ORPHAN', $filter_state)) {
            $filter_state = array('ORPHAN');
        }
        // Count active filters
        if ($filter_tag) {
            $count_filters++;
        }
        if ($filter_lang) {
            $count_filters++;
        }
        if ($filter_type) {
            $count_filters++;
        }
        if ($filter_author) {
            $count_filters++;
        }
        if ($filter_state) {
            $count_filters++;
        }
        if ($filter_access) {
            $count_filters++;
        }
        // Date filters
        $date = $model->getState('date');
        $startdate = $model->getState('startdate');
        $enddate = $model->getState('enddate');
        $startdate = $db->escape(trim(JString::strtolower($startdate)));
        $enddate = $db->escape(trim(JString::strtolower($enddate)));
        if ($startdate) {
            $count_filters++;
        }
        if ($enddate) {
            $count_filters++;
        }
        // Item ID filter
        $filter_id = $model->getState('filter_id');
        if ($filter_id) {
            $count_filters++;
        }
        // Text search
        $scope = $model->getState('scope');
        $search = $model->getState('search');
        $search = $db->escape(trim(JString::strtolower($search)));
        // **************************
        // Add css and js to document
        // **************************
        flexicontent_html::loadFramework('select2');
        JHTML::_('behavior.calendar');
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VERSION);
        $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VERSION);
        $js = "jQuery(document).ready(function(){";
        if ($filter_cats) {
            $js .= "jQuery('.col_cats').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_type) {
            $js .= "jQuery('.col_type').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_author) {
            $js .= "jQuery('.col_authors').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_state) {
            $js .= "jQuery('.col_state').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_lang) {
            $js .= "jQuery('.col_lang').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_access) {
            $js .= "jQuery('.col_access').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_tag) {
            $js .= "jQuery('.col_tag').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($filter_id) {
            $js .= "jQuery('.col_id').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        if ($startdate || $enddate) {
            if ($date == 1) {
                $js .= "jQuery('.col_created').each(function(){ jQuery(this).addClass('yellow'); });";
            } else {
                if ($date == 2) {
                    $js .= "jQuery('.col_revised').each(function(){ jQuery(this).addClass('yellow'); });";
                }
            }
        }
        if (strlen($search)) {
            $js .= "jQuery('.col_title').each(function(){ jQuery(this).addClass('yellow'); });";
        }
        // *****************************
        // Get user's global permissions
        // *****************************
        $perms = FlexicontentHelperPerm::getPerm();
        $CanEdit = $perms->CanEdit;
        $CanPublish = $perms->CanPublish;
        $CanDelete = $perms->CanDelete;
        $CanEditOwn = $perms->CanEditOwn;
        $CanPublishOwn = $perms->CanPublishOwn;
        $CanDeleteOwn = $perms->CanDeleteOwn;
        $hasEdit = $CanEdit || $CanEditOwn;
        $hasPublish = $CanPublish || $CanPublishOwn;
        $hasDelete = $CanDelete || $CanDeleteOwn;
        $CanCats = $perms->CanCats;
        $CanAccLvl = $perms->CanAccLvl;
        $CanOrder = $perms->CanOrder;
        $CanCopy = $perms->CanCopy;
        $CanArchives = $perms->CanArchives;
        // Check if user can create in at least one published category
        require_once "components/com_flexicontent/models/item.php";
        $itemmodel = new FlexicontentModelItem();
        $CanAdd = $itemmodel->getItemAccess()->get('access-create');
        // *****************************
        // Get user's global permissions
        // *****************************
        $perms = FlexicontentHelperPerm::getPerm();
        // ************************
        // Create Submenu & Toolbar
        // ************************
        // Create Submenu (and also check access to current view)
        FLEXISubmenu('notvariable');
        // Create document/toolbar titles
        $doc_title = JText::_('FLEXI_ITEMS');
        $site_title = $document->getTitle();
        JToolBarHelper::title($doc_title, 'items');
        $document->setTitle($doc_title . ' - ' . $site_title);
        $toolbar = JToolBar::getInstance('toolbar');
        // Implementation of multiple-item state selector
        $add_divider = false;
        if ($hasPublish) {
            $btn_task = '';
            $ctrl_task = '&task=items.selectstate';
            $popup_load_url = JURI::base() . 'index.php?option=com_flexicontent' . $ctrl_task . '&format=raw';
            if (FLEXI_J30GE || !FLEXI_J16GE) {
                // Layout of Popup button broken in J3.1, add in J1.5 it generates duplicate HTML tag id (... just for validation), so add manually
                $js .= "\n\t\t\t\t\tjQuery('#toolbar-publish a.toolbar, #toolbar-publish button')\n\t\t\t\t\t\t.attr('onclick', 'javascript:;')\n\t\t\t\t\t\t.attr('href', '" . $popup_load_url . "')\n\t\t\t\t\t\t.attr('rel', '{handler: \\'iframe\\', size: {x: 800, y: 240}, onClose: function() {}}');\n\t\t\t\t";
                //JToolBarHelper::publishList( $btn_task );
                JToolBarHelper::custom($btn_task, 'publish.png', 'publish_f2.png', 'FLEXI_CHANGE_STATE', false);
                JHtml::_('behavior.modal', '#toolbar-publish a.toolbar, #toolbar-publish button');
            } else {
                $toolbar->appendButton('Popup', 'publish', JText::_('FLEXI_CHANGE_STATE'), str_replace('&', '&amp;', $popup_load_url), 800, 240);
            }
            $add_divider = true;
        }
        if ($hasDelete) {
            if ($filter_state && in_array('T', $filter_state)) {
                //$btn_msg = JText::_('FLEXI_ARE_YOU_SURE');
                //$btn_task = 'items.remove';
                //JToolBarHelper::deleteList($btn_msg, $btn_task);
                $msg_alert = JText::sprintf('FLEXI_SELECT_LIST_ITEMS_TO', JText::_('FLEXI_DELETE'));
                $msg_confirm = JText::_('FLEXI_ARE_YOU_SURE');
                $btn_task = 'items.remove';
                $extra_js = "";
                flexicontent_html::addToolBarButton('FLEXI_DELETE', 'delete', '', $msg_alert, $msg_confirm, $btn_task, $extra_js, $btn_list = true, $btn_menu = true, $btn_confirm = true, $btn_class = "btn-warning");
            } else {
                $msg_alert = JText::sprintf('FLEXI_SELECT_LIST_ITEMS_TO', JText::_('FLEXI_TRASH'));
                $msg_confirm = JText::_('FLEXI_TRASH_CONFIRM') . ' ' . JText::_('FLEXI_NOTES') . ': ' . JText::_('FLEXI_DELETE_PERMANENTLY');
                $btn_task = 'items.changestate';
                $extra_js = "document.adminForm.newstate.value='T';";
                flexicontent_html::addToolBarButton('FLEXI_TRASH', 'trash', '', $msg_alert, $msg_confirm, $btn_task, $extra_js, $btn_list = true, $btn_menu = true, $btn_confirm = true, $btn_class = "");
            }
            $add_divider = true;
        }
        if ($CanArchives && (!$filter_state || !in_array('A', $filter_state))) {
            $msg_alert = JText::sprintf('FLEXI_SELECT_LIST_ITEMS_TO', JText::_('FLEXI_ARCHIVE'));
            $msg_confirm = JText::_('FLEXI_ARCHIVE_CONFIRM');
            $btn_task = 'items.changestate';
            $extra_js = "document.adminForm.newstate.value='A';";
            flexicontent_html::addToolBarButton('FLEXI_ARCHIVE', 'archive', $full_js = '', $msg_alert, $msg_confirm, $btn_task, $extra_js, $btn_list = true, $btn_menu = true, $btn_confirm = true);
            $add_divider = true;
        }
        if ($CanArchives && $filter_state && in_array('A', $filter_state) || $hasDelete && $filter_state && in_array('T', $filter_state)) {
            $msg_alert = JText::sprintf('FLEXI_SELECT_LIST_ITEMS_TO', JText::_('FLEXI_RESTORE'));
            $msg_confirm = JText::_('FLEXI_RESTORE_CONFIRM');
            $btn_task = 'items.changestate';
            $extra_js = "document.adminForm.newstate.value='P';";
            flexicontent_html::addToolBarButton('FLEXI_RESTORE', 'restore', $full_js = '', $msg_alert, $msg_confirm, $btn_task, $extra_js, $btn_list = true, $btn_menu = true, $btn_confirm = true);
        }
        if ($add_divider) {
            JToolBarHelper::divider();
        }
        $add_divider = false;
        if ($CanAdd) {
            $btn_task = '';
            $popup_load_url = JURI::base() . 'index.php?option=com_flexicontent&view=types&format=raw';
            if (FLEXI_J30GE || !FLEXI_J16GE) {
                // Layout of Popup button broken in J3.1, add in J1.5 it generates duplicate HTML tag id (... just for validation), so add manually
                $js .= "\n\t\t\t\t\tjQuery('#toolbar-new a.toolbar, #toolbar-new button')\n\t\t\t\t\t\t.attr('onclick', 'javascript:;')\n\t\t\t\t\t\t.attr('href', '" . $popup_load_url . "')\n\t\t\t\t\t\t.attr('rel', '{handler: \\'iframe\\', size: {x: 800, y: 240}, onClose: function() {}}');\n\t\t\t\t";
                //JToolBarHelper::addNew( $btn_task );
                JToolBarHelper::custom($btn_task, 'new.png', 'new_f2.png', 'FLEXI_NEW', false);
                JHtml::_('behavior.modal', '#toolbar-new a.toolbar, #toolbar-new button');
            } else {
                $toolbar->appendButton('Popup', 'new', JText::_('FLEXI_NEW'), str_replace('&', '&amp;', $popup_load_url), 800, 240);
            }
            $add_divider = true;
        }
        if ($hasEdit) {
            $btn_task = 'items.edit';
            JToolBarHelper::editList($btn_task);
            $add_divider = true;
        }
        if ($add_divider) {
            JToolBarHelper::divider();
        }
        $add_divider = false;
        if ($CanAdd && $CanCopy) {
            $btn_task = 'items.copy';
            JToolBarHelper::custom($btn_task, 'copy.png', 'copy_f2.png', 'FLEXI_BATCH');
            if ($enable_translation_groups) {
                JToolBarHelper::custom('translate', 'translate', 'translate', 'FLEXI_TRANSLATE');
            }
            $add_divider = true;
        }
        $btn_task = 'items.checkin';
        JToolbarHelper::checkin($btn_task);
        if ($add_divider) {
            JToolBarHelper::divider();
            JToolBarHelper::spacer();
        }
        if ($perms->CanConfig) {
            $session = JFactory::getSession();
            $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent');
            $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940;
            $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent');
            $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550;
            JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration');
        }
        $js .= "});";
        $document->addScriptDeclaration($js);
        // ***********************
        // Get data from the model
        // ***********************
        $badcatitems = (int) $model->getUnboundedItems($limit = 10000000, $count_only = true, $checkNoExtData = false, $checkInvalidCat = true);
        $unassociated = (int) $model->getUnboundedItems($limit = 10000000, $count_only = true, $checkNoExtData = true, $checkInvalidCat = false);
        $rows = $this->get('Data');
        $pagination = $this->get('Pagination');
        $types = $this->get('Typeslist');
        $authors = $this->get('Authorslist');
        // these depend on data rows and must be called after getting data
        $extraCols = $this->get('ExtraCols');
        $customFilts = $this->get('CustomFilts');
        foreach ($customFilts as $filter) {
            if (count($filter->value)) {
                $count_filters++;
            }
        }
        $itemCats = $this->get('ItemCats');
        $itemTags = $this->get('ItemTags');
        if ($enable_translation_groups) {
            $langAssocs = $this->get('LangAssocs');
        }
        $langs = FLEXIUtilities::getLanguages('code');
        $categories = $globalcats ? $globalcats : array();
        $limit = $pagination->limit;
        $inline_ss_max = 500;
        $drag_reorder_max = 150;
        if ($limit > $drag_reorder_max) {
            $cparams->set('draggable_reordering', 0);
        }
        // ******************************************
        // Add usability notices if these are enabled
        // ******************************************
        if ($cparams->get('show_usability_messages', 1) && !$unassociated && !$badcatitems) {
            $notice_iss_disabled = $app->getUserStateFromRequest($option . '.items.notice_iss_disabled', 'notice_iss_disabled', 0, 'int');
            if (!$notice_iss_disabled && $limit > $inline_ss_max) {
                $app->setUserState($option . '.items.notice_iss_disabled', 1);
                $app->enqueueMessage(JText::sprintf('FLEXI_INLINE_ITEM_STATE_SELECTOR_DISABLED', $inline_ss_max), 'notice');
                $show_turn_off_notice = 1;
            }
            $notice_drag_reorder_disabled = $app->getUserStateFromRequest($option . '.items.notice_drag_reorder_disabled', 'notice_drag_reorder_disabled', 0, 'int');
            if (!$notice_drag_reorder_disabled && $limit > $drag_reorder_max) {
                $app->setUserState($option . '.items.notice_drag_reorder_disabled', 1);
                $app->enqueueMessage(JText::sprintf('FLEXI_DRAG_REORDER_DISABLED', $drag_reorder_max), 'notice');
                $show_turn_off_notice = 1;
            }
            $notice_add_custom_columns = $app->getUserStateFromRequest($option . '.items.notice_add_custom_columns', 'notice_add_custom_columns', 0, 'int');
            if (!$notice_add_custom_columns) {
                $app->setUserState($option . '.items.notice_add_custom_columns', 1);
                $app->enqueueMessage(JText::_('FLEXI_YOU_MAY_CONFIGURE_CUSTOM_COLUMNS_GLOBAL_AND_PER_TYPE'), 'message');
                $show_turn_off_notice = 1;
            }
            if (!empty($show_turn_off_notice)) {
                $app->enqueueMessage(JText::_('FLEXI_USABILITY_MESSAGES_TURN_OFF'), 'message');
            }
        }
        // *******************
        // Create Filters HTML
        // *******************
        // filter publication state
        $states = array();
        //$states[] = JHTML::_('select.option',  '', '-'/*JText::_( 'FLEXI_SELECT_STATE' )*/ );
        $states[] = JHTML::_('select.optgroup', JText::_('FLEXI_SINGLE_STATUS'));
        $states[] = JHTML::_('select.option', 'P', JText::_('FLEXI_PUBLISHED'));
        $states[] = JHTML::_('select.option', 'U', JText::_('FLEXI_UNPUBLISHED'));
        $states[] = JHTML::_('select.option', 'PE', JText::_('FLEXI_PENDING'));
        $states[] = JHTML::_('select.option', 'OQ', JText::_('FLEXI_TO_WRITE'));
        $states[] = JHTML::_('select.option', 'IP', JText::_('FLEXI_IN_PROGRESS'));
        $states[] = JHTML::_('select.option', 'RV', JText::_('FLEXI_REVISED_VER'));
        $states[] = JHTML::_('select.option', 'A', JText::_('FLEXI_ARCHIVED'));
        $states[] = JHTML::_('select.option', 'T', JText::_('FLEXI_TRASHED'));
        $states[] = JHTML::_('select.optgroup', '');
        $states[] = JHTML::_('select.optgroup', JText::_('FLEXI_STATUS_GROUPS'));
        $states[] = JHTML::_('select.option', 'ALL', JText::_('FLEXI_GRP_ALL') . ' ' . JText::_('FLEXI_STATE_S'));
        $states[] = JHTML::_('select.option', 'ALL_P', JText::_('FLEXI_GRP_PUBLISHED') . ' ' . JText::_('FLEXI_STATE_S'));
        $states[] = JHTML::_('select.option', 'ALL_U', JText::_('FLEXI_GRP_UNPUBLISHED') . ' ' . JText::_('FLEXI_STATE_S'));
        $states[] = JHTML::_('select.option', 'ORPHAN', JText::_('FLEXI_GRP_ORPHAN'));
        $states[] = JHTML::_('select.optgroup', '');
        $lists['filter_state'] = ($filter_state || 1 ? '<label class="label">' . JText::_('FLEXI_STATE') . '</label>' : '') . JHTML::_('select.genericlist', $states, 'filter_state[]', 'class="use_select2_lib fcfilter_be" multiple="multiple" size="3" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_state);
        //JHTML::_('grid.state', $filter_state );
        // build filter state group
        if ($hasDelete || $CanArchives) {
            //$stategroups[''] = JText::_( 'FLEXI_GRP_NORMAL' ) .' '. JText::_( 'FLEXI_STATE_S' );
            //$stategroups['published'] = JText::_( 'FLEXI_GRP_PUBLISHED' ) .' '. JText::_( 'FLEXI_STATE_S' );
            //$stategroups['unpublished'] = JText::_( 'FLEXI_GRP_UNPUBLISHED' ) .' '. JText::_( 'FLEXI_STATE_S' );
            /*if ($hasDelete)
            		$stategroups['trashed']  = JText::_( 'FLEXI_GRP_TRASHED' );*/
            /*if ($CanArchives)
            		$stategroups['archived'] = JText::_( 'FLEXI_GRP_ARCHIVED' );*/
            //$stategroups['orphan']      = JText::_( 'FLEXI_GRP_ORPHAN' );
            //$stategroups['all']      = JText::_( 'FLEXI_GRP_ALL' );
            /*$_stategroups = array();
            		foreach ($stategroups as $i => $v) {
            			$_stategroups[] = JHTML::_('select.option', $i, $v);
            		}
            		$lists['filter_stategrp'] = JHTML::_('select.radiolist', $_stategroups, 'filter_stategrp', 'size="1" class="inputbox" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_stategrp );*/
            /*$lists['filter_stategrp'] = '';
            		foreach ($stategroups as $i => $v) {
            			$checked = $filter_stategrp == $i ? ' checked="checked" ' : '';
            			$lists['filter_stategrp'] .= '<input type="radio" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" class="inputbox" '.$checked.' value="'.$i.'" id="filter_stategrp'.$i.'" name="filter_stategrp" />';
            			$lists['filter_stategrp'] .= '<label class="" id="filter_stategrp'.$i.'-lbl" for="filter_stategrp'.$i.'">'.$v.'</label>';
            		}*/
        }
        // build the include subcats boolean list
        // build the include non-published cats boolean list
        if ($filter_order_type && $filter_cats && ($filter_order == 'i.ordering' || $filter_order == 'catsordering')) {
            $ordering_tip = '<img src="components/com_flexicontent/assets/images/comment.png" class="hasTooltip" title="' . JText::_('FLEXI_SUBCATEGORIES_NOT_INCLUDED_DURING_CATORDER_DESC', true) . '" />';
            $lists['filter_subcats'] = '
			<span class="fc-mssg-inline fc-note">
				' . JText::_('FLEXI_SUBCATEGORIES_NOT_INCLUDED_DURING_CATORDER') . ' &nbsp;
				' . $ordering_tip . '
			</span>';
        } else {
            //$lists['filter_subcats'] = JHTML::_('select.booleanlist',  'filter_subcats', 'class="inputbox" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', $filter_subcats );
            $subcats = array();
            $subcats[] = JHTML::_('select.option', 0, JText::_('FLEXI_NO'));
            $subcats[] = JHTML::_('select.option', 1, JText::_('FLEXI_YES'));
            $lists['filter_subcats'] = JHTML::_('select.genericlist', $subcats, 'filter_subcats', 'size="1" class="use_select2_lib ' . ($filter_subcats != 1 ? '' : ' fc_skip_highlight') . '" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_subcats, 'filter_subcats');
        }
        $lists['filter_subcats'] = ($filter_subcats || 1 ? '<label class="label">' . JText::_('FLEXI_SUBCATEGORIES') . '</label>' : '') . $lists['filter_subcats'];
        // build the include non-published cats boolean list
        $catsinstate[1] = JText::_('FLEXI_PUBLISHED');
        $catsinstate[0] = JText::_('FLEXI_UNPUBLISHED');
        $catsinstate[99] = JText::_('FLEXI_ANY');
        $catsinstate[2] = JText::_('FLEXI_ARCHIVED_STATE');
        $catsinstate[-2] = JText::_('FLEXI_TRASHED_STATE');
        $_catsinstate = array();
        foreach ($catsinstate as $i => $v) {
            $_catsinstate[] = JHTML::_('select.option', $i, $v);
        }
        $lists['filter_catsinstate'] = ($filter_catsinstate || 1 ? '<label class="label">' . JText::_('FLEXI_LIST_ITEMS_IN_CATS') . '</label>' : '') . JHTML::_('select.genericlist', $_catsinstate, 'filter_catsinstate', 'size="1" class="use_select2_lib' . ($filter_catsinstate != 1 ? '' : ' fc_skip_highlight') . '" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_catsinstate, 'filter_catsinstate');
        //$lists['filter_catsinstate'] = JHTML::_('select.radiolist', $_catsinstate, 'filter_catsinstate', 'size="1" class="inputbox" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_catsinstate );
        /*$lists['filter_catsinstate']  = '';
        		foreach ($catsinstate as $i => $v) {
        			$checked = $filter_catsinstate == $i ? ' checked="checked" ' : '';
        			$lists['filter_catsinstate'] .= '<input type="radio" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" class="inputbox" '.$checked.' value="'.$i.'" id="filter_catsinstate'.$i.'" name="filter_catsinstate" />';
        			$lists['filter_catsinstate'] .= '<label class="" id="filter_catsinstate'.$i.'-lbl" for="filter_catsinstate'.$i.'">'.$v.'</label>';
        		}*/
        // build the order type boolean list
        $order_types = array();
        $order_types[] = JHTML::_('select.option', '0', 'FLEXI_ORDER_JOOMLA');
        $order_types[] = JHTML::_('select.option', '1', 'FLEXI_ORDER_FLEXICONTENT');
        //$lists['filter_order_type'] = JHTML::_('select.radiolist', $order_types, 'filter_order_type', 'size="1" class="inputbox" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_order_type );
        $lists['filter_order_type'] = JHTML::_('select.genericlist', $order_types, 'filter_order_type', 'size="1" class="use_select2_lib fc_skip_highlight" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_order_type, 'filter_order_type', $translate = true);
        // build the categories select list for filter
        $lists['filter_cats'] = ($filter_cats || 1 ? '<label class="label">' . JText::_('FLEXI_CATEGORY') . '</label>' : '') . flexicontent_cats::buildcatselect($categories, 'filter_cats', $filter_cats, '-', 'class="use_select2_lib" size="1" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', $check_published = false, $check_perms = false);
        //build type select list
        $lists['filter_type'] = ($filter_type || 1 ? '<label class="label">' . JText::_('FLEXI_TYPE') . '</label>' : '') . flexicontent_html::buildtypesselect($types, 'filter_type[]', $filter_type, 0, 'class="use_select2_lib fcfilter_be" multiple="multiple" size="3" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'filter_type');
        //build authors select list
        $lists['filter_author'] = ($filter_author || 1 ? '<label class="label">' . JText::_('FLEXI_AUTHOR') . '</label>' : '') . flexicontent_html::buildauthorsselect($authors, 'filter_author[]', $filter_author, 0, 'class="use_select2_lib fcfilter_be" multiple="multiple" size="3" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"');
        if ($badcatitems) {
            $lists['default_cat'] = flexicontent_cats::buildcatselect($categories, 'default_cat', '', 2, 'class="use_select2_lib"', false, false);
        }
        //search filter
        $scopes = array();
        $scopes[1] = JText::_('FLEXI_TITLE');
        $scopes[2] = JText::_('FLEXI_INTROTEXT');
        $scopes[4] = JText::_('FLEXI_INDEXED_CONTENT');
        $_scopes = array();
        foreach ($scopes as $i => $v) {
            $_scopes[] = JHTML::_('select.option', $i, $v);
        }
        //$lists['scope'] = JHTML::_('select.radiolist', $_scopes, 'scope', 'size="1" class="inputbox"', 'value', 'text', $scope );
        $lists['scope'] = JHTML::_('select.genericlist', $_scopes, 'scope', 'size="1" class="use_select2_lib fc_skip_highlight" onchange="jQuery(\'#search\').attr(\'placeholder\', jQuery(this).find(\'option:selected\').text());" title="' . JText::_('FLEXI_SEARCH_TEXT_INSIDE') . '"', 'value', 'text', $scope, 'scope');
        /*$lists['scope']  = '';
        		foreach ($scopes as $i => $v) {
        			$checked = $scope == $i ? ' checked="checked" ' : '';
        			$lists['scope'] .= '<input type="radio" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" class="inputbox" '.$checked.' value="'.$i.'" id="scope'.$i.'" name="scope" />';
        			$lists['scope'] .= '<label class="" id="scope'.$i.'-lbl" for="scope'.$i.'">'.$v.'</label>';
        		}*/
        // build item dates option list
        $dates[1] = JText::_('FLEXI_CREATED');
        $dates[2] = JText::_('FLEXI_REVISED');
        $_dates = array();
        foreach ($dates as $i => $v) {
            $_dates[] = JHTML::_('select.option', $i, $v);
        }
        //$lists['date'] = JHTML::_('select.radiolist', $_dates, 'date', 'size="1" class="inputbox"', 'value', 'text', $date );
        $lists['date'] = '<label class="label">' . JText::_('FLEXI_DATE') . '</label>' . JHTML::_('select.genericlist', $_dates, 'date', 'size="1" class="use_select2_lib fc_skip_highlight"', 'value', 'text', $date, 'date');
        /*$lists['date']  = '';
        		foreach ($dates as $i => $v) {
        			$checked = $date == $i ? ' checked="checked" ' : '';
        			$lists['date'] .= '<input type="radio" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" class="inputbox" '.$checked.' value="'.$i.'" id="date'.$i.'" name="date" />';
        			$lists['date'] .= '<label class="" id="date'.$i.'-lbl" for="date'.$i.'">'.$v.'</label>';
        		}*/
        $lists['startdate'] = JHTML::_('calendar', $startdate, 'startdate', 'startdate', '%Y-%m-%d', array('class' => 'inputbox', 'size' => '8', 'maxlength' => '19', 'style' => 'width:auto', 'placeholder' => JText::_('FLEXI_FROM')));
        $lists['enddate'] = JHTML::_('calendar', $enddate, 'enddate', 'enddate', '%Y-%m-%d', array('class' => 'inputbox', 'size' => '8', 'maxlength' => '19', 'style' => 'width:auto', 'placeholder' => JText::_('FLEXI_TO')));
        // search filter
        $bind_limits = array();
        $bind_limits[] = JHTML::_('select.option', 250, '250 ' . JText::_('FLEXI_ITEMS'));
        $bind_limits[] = JHTML::_('select.option', 500, '500 ' . JText::_('FLEXI_ITEMS'));
        $bind_limits[] = JHTML::_('select.option', 750, '750 ' . JText::_('FLEXI_ITEMS'));
        $bind_limits[] = JHTML::_('select.option', 1000, '1000 ' . JText::_('FLEXI_ITEMS'));
        $bind_limits[] = JHTML::_('select.option', 1500, '1500 ' . JText::_('FLEXI_ITEMS'));
        $bind_limits[] = JHTML::_('select.option', 2000, '2000 ' . JText::_('FLEXI_ITEMS'));
        $lists['bind_limits'] = JHTML::_('select.genericlist', $bind_limits, 'bind_limit', 'size="1" class="use_select2_lib"', 'value', 'text', $bind_limit, 'bind_limit');
        // search filter
        $lists['search'] = $search;
        // search id
        $lists['filter_id'] = $filter_id;
        // table ordering
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['order'] = $filter_order;
        // filter ordering
        if (!$filter_order_type) {
            $ordering = $lists['order'] == 'i.ordering';
        } else {
            $ordering = $lists['order'] == 'catsordering';
        }
        //build tags filter
        $lists['filter_tag'] = ($filter_tag || 1 ? '<label class="label">' . JText::_('FLEXI_TAG') . '</label>' : '') . flexicontent_html::buildtagsselect('filter_tag[]', 'class="use_select2_lib fcfilter_be" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" multiple="multiple" size="3" ', $filter_tag, 0);
        //build languages filter
        $lists['filter_lang'] = ($filter_lang || 1 ? '<label class="label">' . JText::_('FLEXI_LANGUAGE') . '</label>' : '') . flexicontent_html::buildlanguageslist('filter_lang[]', 'class="use_select2_lib fcfilter_be" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" multiple="multiple" size="3" ', $filter_lang, 1);
        // build access level filter
        $access_levels = JHtml::_('access.assetgroups');
        /*if ( $cparams->get('iman_viewable_items', 1) )  // only viewable items is enabled, skip the non available levels to avoid user confusion
        		{
        			$_aid_arr = array_flip(JAccess::getAuthorisedViewLevels($user->id));
        			$_levels = array();
        			foreach($access_levels as $i => $level)
        			{
        				if ( isset($_aid_arr[$level->value]) )
        					$_levels[] = $level;
        				//else $access_levels[$i]->disable = 1;
        			}
        			$access_levels = $_levels;
        		}*/
        // Above code is maybe problematic (e.g. in multi-sites), need to test more
        //array_unshift($access_levels, JHtml::_('select.option', '', '-'/*'JOPTION_SELECT_ACCESS'*/) );
        $fieldname = 'filter_access[]';
        // make multivalue
        $elementid = 'filter_access';
        $attribs = 'class="use_select2_lib fcfilter_be" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()" multiple="multiple"';
        $lists['filter_access'] = ($filter_access || 1 ? '<label class="label">' . JText::_('FLEXI_ACCESS') . '</label>' : '') . JHTML::_('select.genericlist', $access_levels, $fieldname, $attribs, 'value', 'text', $filter_access, $elementid, $translate = true);
        // filter by item usage a specific file
        if ($fileid_to_itemids && count($fileid_to_itemids)) {
            $files_data = $model->getFileData(array_keys($fileid_to_itemids));
            $file_options = array();
            $file_options[] = JHTML::_('select.option', '', '-');
            foreach ($files_data as $_file) {
                $file_options[] = JHTML::_('select.option', $_file->id, $_file->altname);
            }
            flexicontent_html::loadFramework('select2');
            $lists['filter_fileid'] = ($filter_fileid || 1 ? '<label class="label">' . JText::_('FLEXI_ITEMS_USING') . ' ' . JText::_('FLEXI_FILE') . '</label>' : '') . JHTML::_('select.genericlist', $file_options, 'filter_fileid', 'size="1" class="use_select2_lib' . ($filter_fileid ? '' : ' fc_skip_highlight') . '" onchange="document.adminForm.limitstart.value=0; Joomla.submitform()"', 'value', 'text', $filter_fileid);
        }
        //assign data to template
        $this->assignRef('CanTemplates', $perms->CanTemplates);
        $this->assignRef('count_filters', $count_filters);
        //$this->assignRef('filter_stategrp', $filter_stategrp);
        $this->assignRef('filter_catsinstate', $filter_catsinstate);
        $this->assignRef('db', $db);
        $this->assignRef('lists', $lists);
        $this->assignRef('rows', $rows);
        $this->assignRef('itemCats', $itemCats);
        $this->assignRef('itemTags', $itemTags);
        $this->assignRef('extra_fields', $extraCols);
        $this->assignRef('custom_filts', $customFilts);
        if ($enable_translation_groups) {
            $this->assignRef('lang_assocs', $langAssocs);
        }
        $this->assignRef('langs', $langs);
        $this->assignRef('cid', $cid);
        $this->assignRef('pagination', $pagination);
        $this->assignRef('ordering', $ordering);
        $this->assignRef('CanOrder', $CanOrder);
        $this->assignRef('CanCats', $CanCats);
        $this->assignRef('CanAccLvl', $CanAccLvl);
        $this->assignRef('unassociated', $unassociated);
        $this->assignRef('badcatitems', $badcatitems);
        // filters
        $this->assignRef('filter_id', $filter_id);
        $this->assignRef('filter_state', $filter_state);
        $this->assignRef('filter_author', $filter_author);
        $this->assignRef('filter_type', $filter_type);
        $this->assignRef('filter_cats', $filter_cats);
        $this->assignRef('filter_subcats', $filter_subcats);
        $this->assignRef('filter_catsinstate', $filter_catsinstate);
        $this->assignRef('filter_order_type', $filter_order_type);
        $this->assignRef('filter_order', $filter_order);
        $this->assignRef('filter_lang', $filter_lang);
        $this->assignRef('filter_access', $filter_access);
        $this->assignRef('filter_tag', $filter_tag);
        $this->assignRef('filter_fileid', $filter_fileid);
        $this->assignRef('inline_ss_max', $inline_ss_max);
        $this->assignRef('scope', $scope);
        $this->assignRef('search', $search);
        $this->assignRef('date', $date);
        $this->assignRef('startdate', $startdate);
        $this->assignRef('enddate', $enddate);
        $this->assignRef('option', $option);
        $this->assignRef('view', $view);
        $print_logging_info = $cparams->get('print_logging_info');
        if ($print_logging_info) {
            global $fc_run_times;
            $start_microtime = microtime(true);
        }
        $this->sidebar = FLEXI_J30GE ? JHtmlSidebar::render() : null;
        parent::display($tpl);
        if ($print_logging_info) {
            @($fc_run_times['template_render'] += round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10);
        }
    }
Ejemplo n.º 9
0
 /**
  * Method to copy items
  *
  * @access	public
  * @return	boolean	True on success
  * @since	1.5
  */
 function copyitems($cid, $keeptags = 1, $prefix, $suffix, $copynr = 1, $lang = null, $state = null, $method = 1, $maincat = null, $seccats = null, $type_id = null, $access = null)
 {
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $dbprefix = $app->getCfg('dbprefix');
     $use_versioning = $this->cparams->get('use_versioning', 1);
     require_once "components/com_flexicontent/models/item.php";
     // ************************************************************************
     // Try to find Falang/Joomfish, to import translation data, if so requested
     // ************************************************************************
     $_FALANG = false;
     $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'falang_content"');
     $_FALANG = (bool) count($this->_db->loadObjectList());
     // Try to find old joomfish tables (with current DB prefix)
     $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'jf_content"');
     $_FISH = (bool) count($this->_db->loadObjectList());
     // Try to find old joomfish tables (with J1.5 jos prefix)
     if (!$_FISH) {
         $this->_db->setQuery('SHOW TABLES LIKE "jos_jf_content"');
         if (count($this->_db->loadObjectList())) {
             $_FISH = true;
             $dbprefix = 'jos_';
         }
     }
     // Detect version of joomfish tables
     $_FISH22GE = false;
     if ($_FISH) {
         $this->_db->setQuery('SHOW TABLES LIKE "' . $dbprefix . 'jf_languages_ext"');
         $_FISH22GE = (bool) count($this->_db->loadObjectList());
     }
     $_NEW_LANG_TBL = FLEXI_J16GE || $_FISH22GE;
     // Get if translation is to be performed, 1: FLEXI_DUPLICATEORIGINAL,  2: FLEXI_USE_JF_DATA,  3: FLEXI_AUTO_TRANSLATION,  4: FLEXI_FIRST_JF_THEN_AUTO
     if ($method == 99) {
         $translate_method = $jinput->get('translate_method', 1, 'int');
     } else {
         $translate_method = 0;
     }
     // If translation method import the translator class
     if ($translate_method == 3 || $translate_method == 4) {
         require_once JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'translator.php';
     }
     // If translation method load description field to allow some parsing according to parameters
     if ($translate_method == 3 || $translate_method == 4) {
         $this->_db->setQuery('SELECT id FROM #__flexicontent_fields WHERE name = "text" ');
         $desc_field_id = $this->_db->loadResult();
         $desc_field = JTable::getInstance('flexicontent_fields', '');
         $desc_field->load($desc_field_id);
     }
     // ************************************************************
     // Loop through the items, copying, moving, or translating them
     // ************************************************************
     foreach ($cid as $itemid) {
         for ($nr = 0; $nr < $copynr; $nr++) {
             // (a) Get existing item
             $item = JTable::getInstance('flexicontent_items', '');
             $item->load($itemid);
             // Some shortcuts
             $sourceid = (int) $item->id;
             $curversion = (int) $item->version;
             // (b) We create copy so that the original data are always available
             $row = clone $item;
             // (c) Force creation & assigning of new records by cleaning the primary keys
             $row->id = null;
             // force creation of new record in _content DB table
             $row->item_id = null;
             // force creation of new record in _flexicontent_ext DB table
             $row->asset_id = null;
             // force creation of new record in _assets DB table
             // (d) Start altering the properties of the cloned item
             $row->title = ($prefix ? $prefix . ' ' : '') . $item->title . ($suffix ? ' ' . $suffix : '');
             $row->hits = 0;
             if (!$translate_method) {
                 // cleared featured flag if not translating
                 $row->featured = 0;
             }
             $row->version = 1;
             $datenow = JFactory::getDate();
             $row->created = $datenow->toSql();
             $row->publish_up = $datenow->toSql();
             $row->modified = $nullDate = $this->_db->getNullDate();
             $lang_from = substr($row->language, 0, 2);
             $row->language = $lang ? $lang : $row->language;
             $lang_to = substr($row->language, 0, 2);
             $row->state = strlen($state) ? $state : $row->state;
             // keep original if: null, ''
             $row->type_id = $type_id ? $type_id : $row->type_id;
             // keep original if: null, zero, ''
             $row->access = $access ? $access : $row->access;
             // keep original if: null, zero, ''
             $doauto['title'] = $doauto['introtext'] = $doauto['fulltext'] = $doauto['metakey'] = $doauto['metadesc'] = true;
             // In case JF data is missing
             if ($translate_method == 2 || $translate_method == 4) {
                 // a. Try to get joomfish/falang translation from the item
                 $jfitemfields = false;
                 if ($_FALANG) {
                     $query = "SELECT c.* FROM `#__falang_content` AS c " . " LEFT JOIN #__languages AS lg ON c.language_id=lg.lang_id" . " WHERE c.reference_table = 'content' AND lg.lang_code='" . $row->language . "' AND c.reference_id = " . $sourceid;
                     $this->_db->setQuery($query);
                     $jfitemfields = $this->_db->loadObjectList();
                 }
                 if (!$jfitemfields && $_FISH) {
                     $query = "SELECT c.* FROM `" . $dbprefix . "jf_content` AS c " . " LEFT JOIN #__languages AS lg ON c.language_id=" . ($_NEW_LANG_TBL ? "lg.lang_id" : "lg.id") . " WHERE c.reference_table = 'content' AND " . ($_NEW_LANG_TBL ? "lg.lang_code" : "lg.code") . "='" . $row->language . "' AND c.reference_id = " . $sourceid;
                     $this->_db->setQuery($query);
                     $jfitemfields = $this->_db->loadObjectList();
                 }
                 // b. if joomfish translation found set for the new item
                 if ($jfitemfields) {
                     $jfitemdata = new stdClass();
                     foreach ($jfitemfields as $jfitemfield) {
                         $jfitemdata->{$jfitemfield->reference_field} = $jfitemfield->value;
                     }
                     if (isset($jfitemdata->title) && mb_strlen($jfitemdata->title) > 0) {
                         $row->title = $jfitemdata->title;
                         $doauto['title'] = false;
                     }
                     if (isset($jfitemdata->alias) && mb_strlen($jfitemdata->alias) > 0) {
                         $row->alias = $jfitemdata->alias;
                     }
                     if (isset($jfitemdata->introtext) && mb_strlen(strip_tags($jfitemdata->introtext)) > 0) {
                         $row->introtext = $jfitemdata->introtext;
                         $doauto['introtext'] = false;
                     }
                     if (isset($jfitemdata->fulltext) && mb_strlen(strip_tags($jfitemdata->fulltext)) > 0) {
                         $row->fulltext = $jfitemdata->fulltext;
                         $doauto['fulltext'] = false;
                     }
                     if (isset($jfitemdata->metakey) && mb_strlen($jfitemdata->metakey) > 0) {
                         $row->metakey = $jfitemdata->metakey;
                         $doauto['metakey'] = false;
                     }
                     if (isset($jfitemdata->metadesc) && mb_strlen($jfitemdata->metadesc) > 0) {
                         $row->metadesc = $jfitemdata->metadesc;
                         $doauto['metadesc'] = false;
                     }
                 }
             }
             // Try to do automatic translation from the item, if autotranslate is SET and --NOT found-- or --NOT using-- JoomFish Data
             if ($translate_method == 3 || $translate_method == 4) {
                 // Translate fulltext item property, using the function for which handles custom fields TYPES: text, textarea, ETC
                 if ($doauto['fulltext']) {
                     $desc_field->value = $row->fulltext;
                     $fields = array(&$desc_field);
                     $this->translateFieldValues($fields, $row, $lang_from, $lang_to);
                     $row->fulltext = $desc_field->value;
                 }
                 // TRANSLATE basic item properties (if not already imported via Joomfish)
                 $translatables = array('title', 'introtext', 'metakey', 'metadesc');
                 $fieldnames_arr = array();
                 $fieldvalues_arr = array();
                 foreach ($translatables as $translatable) {
                     if (!$doauto[$translatable]) {
                         continue;
                     }
                     $fieldnames_arr[] = $translatable;
                     $translatable_obj = new stdClass();
                     $translatable_obj->originalValue = $row->{$translatable};
                     $translatable_obj->noTranslate = false;
                     $fieldvalues_arr[] = $translatable_obj;
                 }
                 if (count($fieldvalues_arr)) {
                     $result = autoTranslator::translateItem($fieldnames_arr, $fieldvalues_arr, $lang_from, $lang_to);
                     if (intval($result)) {
                         $n = 0;
                         foreach ($fieldnames_arr as $fieldname) {
                             $row->{$fieldname} = $fieldvalues_arr[$n]->translationValue;
                             $n++;
                         }
                     }
                 }
             }
             //print_r($row->fulltext); exit;
             // Create a new item in the content fc_items_ext table
             $row->store();
             // Not doing a translation, we start a new language group for the new item
             if ($translate_method == 0) {
                 $row->lang_parent_id = 0;
                 //$row->id;
                 $row->store();
             }
             // ***********************************************************
             // Copy custom fields, translating the fields if so configured
             // ***********************************************************
             $doTranslation = $translate_method == 3 || $translate_method == 4;
             $query = 'SELECT fir.*, f.* ' . ' FROM #__flexicontent_fields_item_relations as fir' . ' LEFT JOIN #__flexicontent_fields as f ON f.id=fir.field_id' . ' WHERE item_id = ' . $sourceid;
             $this->_db->setQuery($query);
             $fields = $this->_db->loadObjectList();
             //echo "<pre>"; print_r($fields); exit;
             if ($doTranslation) {
                 $this->translateFieldValues($fields, $row, $lang_from, $lang_to);
             }
             //foreach ($fields as $field)  if ($field->field_type!='text' && $field->field_type!='textarea') { print_r($field->value); echo "<br><br>"; }
             foreach ($fields as $field) {
                 if (strlen($field->value)) {
                     $query = 'INSERT INTO #__flexicontent_fields_item_relations (`field_id`, `item_id`, `valueorder`, `suborder`, `value`)' . ' VALUES(' . $field->field_id . ', ' . $row->id . ', ' . $field->valueorder . ', ' . $field->suborder . ', ' . $this->_db->Quote($field->value) . ')';
                     $this->_db->setQuery($query);
                     $this->_db->execute();
                 }
             }
             if ($use_versioning) {
                 $v = new stdClass();
                 $v->item_id = (int) $item->id;
                 $v->version_id = 1;
                 $v->created = $item->created;
                 $v->created_by = $item->created_by;
                 //$v->comment		= 'copy version.';
                 $this->_db->insertObject('#__flexicontent_versions', $v);
             }
             // get the items versions
             $query = 'SELECT *' . ' FROM #__flexicontent_items_versions' . ' WHERE item_id = ' . $sourceid . ' AND version = ' . $curversion;
             $this->_db->setQuery($query);
             $curversions = $this->_db->loadObjectList();
             foreach ($curversions as $cv) {
                 $query = 'INSERT INTO #__flexicontent_items_versions (`version`, `field_id`, `item_id`, `valueorder`, `suborder`, `value`)' . ' VALUES(1 ,' . $cv->field_id . ', ' . $row->id . ', ' . $cv->valueorder . ', ' . $cv->suborder . ', ' . $this->_db->Quote($cv->value) . ')';
                 $this->_db->setQuery($query);
                 $this->_db->execute();
             }
             // get the item categories
             $query = 'SELECT catid' . ' FROM #__flexicontent_cats_item_relations' . ' WHERE itemid = ' . $sourceid;
             $this->_db->setQuery($query);
             $cats = $this->_db->loadColumn();
             foreach ($cats as $cat) {
                 $query = 'INSERT INTO #__flexicontent_cats_item_relations (`catid`, `itemid`)' . ' VALUES(' . $cat . ',' . $row->id . ')';
                 $this->_db->setQuery($query);
                 $this->_db->execute();
             }
             if ($keeptags) {
                 // get the item tags
                 $query = 'SELECT tid' . ' FROM #__flexicontent_tags_item_relations' . ' WHERE itemid = ' . $sourceid;
                 $this->_db->setQuery($query);
                 $tags = $this->_db->loadColumn();
                 foreach ($tags as $tag) {
                     $query = 'INSERT INTO #__flexicontent_tags_item_relations (`tid`, `itemid`)' . ' VALUES(' . $tag . ',' . $row->id . ')';
                     $this->_db->setQuery($query);
                     $this->_db->execute();
                 }
             }
             if ($method == 3) {
                 $this->moveitem($row->id, $maincat, $seccats);
             } else {
                 if ($method == 99 && ($maincat || $seccats)) {
                     $row->catid = $maincat ? $maincat : $row->catid;
                     $this->moveitem($row->id, $row->catid, $seccats);
                 }
             }
             // Load item model and save it once, e.g. updating Joomla featured FLAG data
             //$itemmodel = new FlexicontentModelItem();
             //$itemmodel->getItem($row->id);
             //$itemmodel->store((array)$row);
             // If new item is a tranlation, load the language associations of item
             // that was copied, and save the associations, adding the new item to them
             if ($method == 99 && $item->language != '*' && $row->language != '*' && flexicontent_db::useAssociations()) {
                 $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id);
                 // associations of item that was copied
                 $_data = array();
                 foreach ($associations as $tag => $association) {
                     $_data['associations'][$tag] = (int) $association->id;
                 }
                 $_data['associations'][$row->language] = $row->id;
                 // Add new item itself
                 $_data['associations'][$item->language] = $item->id;
                 // unneeded, done by saving ...
                 $context = 'com_content';
                 flexicontent_db::saveAssociations($row, $_data, $context);
                 // Save associations, adding the new item
                 //$app->enqueueMessage( print_r($_data, true), 'message' );
             }
         }
     }
     return true;
 }
 static function getPropertySupport($field_type, $iscore, $spname = null)
 {
     static $fi = null;
     if ($fi === null) {
         $fi = FlexicontentFields::getPropertySupport_BuiltIn();
     }
     static $cparams = null;
     if ($cparams === null) {
         $cparams = JComponentHelper::getParams('com_flexicontent');
     }
     static $support_ft = array();
     if (isset($support_ft[$field_type])) {
         return !$spname ? $support_ft[$field_type] : $support_ft[$field_type]->{$spname};
     }
     // Existing fields with field type
     if ($field_type) {
         // Make sure that the Joomla plugin that implements the type of current flexi field, has been imported
         //JPluginHelper::importPlugin('flexicontent_fields', $field_type);
         FLEXIUtilities::call_FC_Field_Func($iscore ? 'core' : $field_type, null, null);
         // Get Methods implemented by the field
         $classname = 'plgFlexicontent_fields' . ($iscore ? 'core' : $field_type);
         $classmethods = get_class_methods($classname);
         // SEARCH/FILTER related properties
         $supportsearch = $iscore ? in_array($field_type, $fi->core_search) : in_array('onIndexSearch', $classmethods);
         $supportfilter = $iscore ? in_array($field_type, $fi->core_filters) : in_array('onDisplayFilter', $classmethods);
         $supportadvsearch = $iscore ? in_array($field_type, $fi->core_advsearch) : in_array('onIndexAdvSearch', $classmethods);
         $supportadvfilter = $iscore ? in_array($field_type, $fi->core_advfilters) : in_array('onAdvSearchDisplayFilter', $classmethods);
         // ITEM FORM related properties
         $supportuntranslatable = !$iscore || $field_type == 'maintext';
         $supportvalueseditable = !$iscore || $field_type == 'maintext';
         $supportformhidden = !$iscore || $field_type == 'maintext';
         $supportedithelp = !$iscore || $field_type == 'maintext';
         // New fields without field type
     } else {
         // SEARCH/FILTER related properties
         $supportsearch = false;
         $supportfilter = false;
         $supportadvsearch = false;
         $supportadvfilter = false;
         // ITEM FORM related properties
         $supportuntranslatable = !$iscore;
         $supportvalueseditable = !$iscore;
         $supportformhidden = !$iscore;
         $supportedithelp = !$iscore;
     }
     // This property is usable only when Translation Groups are enabled
     $supportuntranslatable = $supportuntranslatable && flexicontent_db::useAssociations();
     //$cparams->get('enable_translation_groups');
     $support_ft[$field_type] = new stdClass();
     $support_ft[$field_type]->supportsearch = $supportsearch;
     $support_ft[$field_type]->supportfilter = $supportfilter;
     $support_ft[$field_type]->supportadvsearch = $supportadvsearch;
     $support_ft[$field_type]->supportadvfilter = $supportadvfilter;
     $support_ft[$field_type]->supportuntranslatable = $supportuntranslatable;
     $support_ft[$field_type]->supportvalueseditable = $supportvalueseditable;
     $support_ft[$field_type]->supportformhidden = $supportformhidden;
     $support_ft[$field_type]->supportedithelp = $supportedithelp;
     return !$spname ? $support_ft[$field_type] : $support_ft[$field_type]->{$spname};
 }
Ejemplo n.º 11
0
 /**
  * Method to get if language of items is initialized properly
  * 
  * @access	public
  * @return	boolean	True on success
  * @since 1.5
  */
 function getItemsNoLang()
 {
     static $return;
     if ($return !== NULL) {
         return $return;
     }
     $return = false;
     $cparams = JComponentHelper::getParams('com_flexicontent');
     $enable_translation_groups = flexicontent_db::useAssociations();
     //$cparams->get("enable_translation_groups");
     // Check for emtpy language in flexicontent EXT table
     $query = "SELECT COUNT(*)" . " FROM #__flexicontent_items_ext as ie" . " WHERE ie.language='' " . " LIMIT 1";
     $this->_db->setQuery($query);
     $cnt = $this->_db->loadResult();
     if ($cnt) {
         return $return = true;
     }
     $query = "SELECT COUNT(*)" . " FROM #__content as i" . " WHERE i.language=''" . " LIMIT 1";
     $this->_db->setQuery($query);
     $cnt = $this->_db->loadResult();
     if ($cnt) {
         return $return = true;
     }
     $query = "SELECT COUNT(*)" . " FROM #__content as i" . " JOIN #__flexicontent_items_ext as ie ON i.id=ie.item_id " . " WHERE i.language<>ie.language" . " LIMIT 1";
     $this->_db->setQuery($query);
     $cnt = $this->_db->loadResult();
     if ($cnt) {
         return $return = true;
     }
     // Check for not yet transfered language associations
     $query = "SELECT COUNT(*)" . " FROM #__flexicontent_items_ext as ie" . " WHERE ie.lang_parent_id <> 0" . " LIMIT 1";
     $this->_db->setQuery($query);
     $cnt = $this->_db->loadResult();
     if ($cnt) {
         return $return = true;
     }
     return $return;
 }