/** * Logic to copy the fields * * @access public * @return void * @since 1.5 */ function copy() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); // Get model, user, ids of copied fields $model = $this->getModel('fields'); $user = JFactory::getUser(); $cid = JRequest::getVar('cid', array(0), 'default', 'array'); $task = JRequest::getVar('task', 'copy'); // calculate access if (FLEXI_J16GE) { $is_authorised = $user->authorise('flexicontent.copyfields', 'com_flexicontent'); } else { // With / Without FLEXI_ACCESS there is no global privilege, so we will check publish (edit state) privilege bellow (for backend users it will be always true) $is_authorised = true; } // check access if (!$is_authorised) { JError::raiseWarning(403, JText::_('FLEXI_ALERTNOTAUTH')); $this->setRedirect('index.php?option=com_flexicontent&view=fields'); return; } // Remove core fields $core_cid = array(); $non_core_cid = array(); // Copying of core fields is not allowed foreach ($cid as $id) { if ($id < 15) { $core_cid[] = $id; } else { $non_core_cid[] = $id; } } // Remove uneditable fields $auth_cid = array(); $non_auth_cid = array(); // Cannot copy fields you cannot edit foreach ($non_core_cid as $id) { $asset = 'com_flexicontent.field.' . $id; if (FLEXI_J16GE) { $is_authorised = $user->authorise('flexicontent.editfield', $asset); } else { if (FLEXI_ACCESS && $user->gid < 25) { $is_authorised = FAccess::checkAllContentAccess('com_content', 'edit', 'users', $user->gmid, 'field', $id); } else { // Only admin or super admin can copy fields $is_authorised = $user->gid >= 24; } } if ($is_authorised) { $auth_cid[] = $id; } else { $non_auth_cid[] = $id; } } // Try to copy fields $ids_map = $model->copy($auth_cid, $task == 'copy_wvalues'); if (!$ids_map) { $msg = JText::_('FLEXI_FIELDS_COPY_FAILED'); JError::raiseWarning(500, $model->getError()); } else { $msg = ''; if (count($ids_map)) { $msg .= JText::sprintf('FLEXI_FIELDS_COPY_SUCCESS', count($ids_map)) . ' '; } if (count($auth_cid) - count($ids_map)) { //$msg .= JText::sprintf('FLEXI_FIELDS_SKIPPED_DURING_COPY', count($auth_cid)-count($ids_map)) . ' '; } if (count($core_cid)) { $msg .= JText::sprintf('FLEXI_FIELDS_CORE_FIELDS_NOT_COPIED', count($core_cid)) . ' '; } if (count($non_auth_cid)) { $msg .= JText::sprintf('FLEXI_FIELDS_UNEDITABLE_FIELDS_NOT_COPIED', count($non_auth_cid)) . ' '; } $cache = JFactory::getCache('com_flexicontent'); $cache->clean(); } $mainframe = JFactory::getApplication(); $option = JRequest::getVar('option'); $filter_type = $mainframe->getUserStateFromRequest($option . '.fields.filter_type', 'filter_type', '', 'int'); if ($filter_type) { $mainframe->setUserState($option . '.fields.filter_type', ''); $msg .= ' ' . JText::_('FLEXI_TYPE_FILTER_CLEARED_TO_VIEW_NEW_FIELDS'); } $this->setRedirect('index.php?option=com_flexicontent&view=fields', $msg); }
$row_css = ''; for ($icnt = 0; $icnt < $padcount; $icnt++) { $padspacer .= " |_ "; } } } if (FLEXI_J16GE) { $rights = FlexicontentHelperPerm::checkAllItemAccess($user->id, 'field', $row->id); $canEdit = in_array('editfield', $rights); $canPublish = in_array('publishfield', $rights); $canDelete = in_array('deletefield', $rights); } else { if (FLEXI_ACCESS) { $canEdit = $user->gid == 25 ? 1 : FAccess::checkAllContentAccess('com_content', 'edit', 'users', $user->gmid, 'field', $row->id); $canPublish = $user->gid == 25 ? 1 : FAccess::checkAllContentAccess('com_content', 'publish', 'users', $user->gmid, 'field', $row->id); $canDelete = $user->gid == 25 ? 1 : FAccess::checkAllContentAccess('com_content', 'delete', 'users', $user->gmid, 'field', $row->id); } else { $canEdit = $user->gid >= 24; $canPublish = $user->gid >= 24; $canDelete = $user->gid >= 24; } } $link = 'index.php?option=com_flexicontent&' . $fields_task . 'edit&cid[]=' . $row->id; if ($row->id < 7) { // First 6 core field are not unpublishable $published = JHTML::image('administrator/components/com_flexicontent/assets/images/tick_f2.png', JText::_('FLEXI_NOT_AVAILABLE')); } else { if (!$canPublish && $row->published) { // No privilige published $published = JHTML::image('administrator/components/com_flexicontent/assets/images/tick_f2.png', JText::_('FLEXI_NOT_AVAILABLE')); } else {
/** * Method to get types list when performing an edit action or e.g. checking 'create' ACCESS for the types * * @return array * @since 1.5 */ function getTypeslist($type_ids = false, $check_perms = false) { if (!empty($type_ids) && is_array($type_ids)) { foreach ($type_ids as $i => $type_id) { $type_ids[$i] = (int) $type_id; } $type_ids_list = implode(',', $type_ids); } $query = 'SELECT * ' . ' FROM #__flexicontent_types' . ' WHERE published = 1 ' . (@$type_ids_list ? ' AND id IN (' . $type_ids_list . ' ) ' : '') . ' ORDER BY name ASC'; $this->_db->setQuery($query); $types = $this->_db->loadObjectList('id'); if ($check_perms) { $user = JFactory::getUser(); $_types = array(); foreach ($types as $type) { if (FLEXI_J16GE) { $allowed = !$type->itemscreatable || $user->authorise('core.create', 'com_flexicontent.type.' . $type->id); } else { if (FLEXI_ACCESS && $user->gid < 25) { $allowed = !$type->itemscreatable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'type', $type->id); } else { $allowed = 1; } } if ($allowed) { $_types[] = $type; } } $types = $_types; } return $types; }
function display($tpl = null) { echo '<div id="flexicontent">'; echo '<link rel="stylesheet" href="' . JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css" />'; if (FLEXI_J30GE) { $fc_css = JURI::base() . 'components/com_flexicontent/assets/css/j3x.css'; } else { if (FLEXI_J16GE) { $fc_css = JURI::base() . 'components/com_flexicontent/assets/css/j25.css'; } else { $fc_css = JURI::base() . 'components/com_flexicontent/assets/css/j15.css'; } } echo '<link rel="stylesheet" href="' . $fc_css . '" />'; $user = JFactory::getUser(); $db = JFactory::getDBO(); $query = 'SELECT id, name, itemscreatable' . ' FROM #__flexicontent_types' . ' WHERE published = 1' . ' ORDER BY name ASC'; $db->setQuery($query); $types = $db->loadObjectList(); $types = is_array($types) ? $types : array(); echo '<label class="flexi_label">' . JText::_('FLEXI_SELECT_TYPE') . ':</label><br/><br/>'; $ctrl_task = FLEXI_J16GE ? 'items.add' : 'add'; $icon = "components/com_flexicontent/assets/images/layout_add.png"; foreach ($types as $type) { if (FLEXI_J16GE) { $allowed = !$type->itemscreatable || $user->authorise('core.create', 'com_flexicontent.type.' . $type->id); } else { if (FLEXI_ACCESS && $user->gid < 25) { $allowed = !$type->itemscreatable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'type', $type->id); } else { $allowed = 1; } } if (!$allowed && $type->itemscreatable == 1) { continue; } $link = "index.php?option=com_flexicontent&controller=items&task=" . $ctrl_task . "&typeid=" . $type->id . "&" . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . "=1"; if (!$allowed && $type->itemscreatable == 2) { ?> <span class="fc_button"> <img style="margin-bottom:-3px;" src="<?php echo $icon; ?> " width="16" height="16" border="0" alt="<?php echo $type->name; ?> " /> <?php echo $type->name; ?> </span> <?php } else { ?> <a class="fc_button" href="<?php echo $link; ?> " target="_parent"> <img style="margin-bottom:-3px;" src="<?php echo $icon; ?> " width="16" height="16" border="0" alt="<?php echo $type->name; ?> " /> <?php echo $type->name; ?> </a> <?php } } $link = "index.php?option=com_flexicontent&controller=items&task=" . $ctrl_task . "&" . (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) . "=1"; $_name = JText::_("FLEXI_ANY") . ' ... ' . JText::_("FLEXI_TYPE"); ?> <div class="fcclear"></div> <br/> <a class="fc_button fcsimple" href="<?php echo $link; ?> " target="_parent"> <img style="margin-bottom:-3px;" src="<?php echo $icon; ?> " width="16" height="16" border="0" alt="<?php echo $_name; ?> " /> <?php echo $_name; ?> </a> </div> <?php }
/** * Method to build the list for types when performing an edit action * * @return array * @since 1.5 */ static function buildtypesselect($types, $name, $selected, $top, $class = 'class="inputbox"', $tagid='', $check_perms=false) { $user = JFactory::getUser(); $typelist = array(); if($top) $typelist[] = JHTML::_( 'select.option', '', JText::_( 'FLEXI_SELECT_TYPE' ) ); foreach ($types as $type) { $allowed = 1; if ($check_perms) { if (FLEXI_J16GE) $allowed = ! $type->itemscreatable || $user->authorise('core.create', 'com_flexicontent.type.' . $type->id); else if (FLEXI_ACCESS && $user->gid < 25) $allowed = ! $type->itemscreatable || FAccess::checkAllContentAccess('com_content','submit','users', $user->gmid, 'type', $type->id); else $allowed = 1; } if ( !$allowed && $type->itemscreatable == 1 ) continue; if ( !$allowed && $type->itemscreatable == 2 ) $typelist[] = JHTML::_( 'select.option', $type->id, $type->name, 'value', 'text', $disabled = true ); else $typelist[] = JHTML::_( 'select.option', $type->id, $type->name); } return JHTML::_('select.genericlist', $typelist, $name, $class, 'value', 'text', $selected, $tagid ); }
static function getUserPerms($user_id = null) { // handle jcomments integration if (JPluginHelper::isEnabled('system', 'jcomments')) { $Comments_Enabled = 1; $destpath = JPATH_SITE . DS . 'components' . DS . 'com_jcomments' . DS . 'plugins'; $dest = $destpath . DS . 'com_flexicontent.plugin.php'; $source = JPATH_SITE . DS . 'components' . DS . 'com_flexicontent' . DS . 'librairies' . DS . 'jcomments' . DS . 'com_flexicontent.plugin.php'; jimport('joomla.filesystem.file'); if (!JFile::exists($dest)) { if (!JFolder::exists($destpath)) { if (!JFolder::create($destpath)) { JError::raiseWarning(100, JText::_('FLEXIcontent: Unable to create jComments plugin folder')); } } if (!JFile::copy($source, $dest)) { JError::raiseWarning(100, JText::_('FLEXIcontent: Unable to copy jComments plugin')); } else { $mainframe->enqueueMessage(JText::_('Copied FLEXIcontent jComments plugin')); } } } else { $Comments_Enabled = 0; } // Find permissions for given user id $user = $user_id ? JFactory::getUser($user_id) : JFactory::getUser(); // no user id given, use current user) $permission = new stdClass(); // !!! This is the Super User Privelege of GLOBAL Configuration (==> (for J2.5) core.admin ACTION allowed on ROOT ASSET: 'root.1') $permission->SuperAdmin = $user->gid > 24; //!!! ALLOWs USERS to change component's CONFIGURATION (==> (for J2.5) core.admin ACTION allowed on COMPONENT ASSET: e.g. 'com_flexicontent') $permission->CanConfig = $permission->SuperAdmin; // No FLEXI ACCESS .. if (!FLEXI_ACCESS) { $permission->CanManage = $user->gid >= 23; // At least J1.5 Manager $permission->CanAdd = $user->authorize('com_content', 'add', 'content', 'all'); // ($user->gid >= 19); // At least J1.5 Author $permission->CanEdit = $user->authorize('com_content', 'edit', 'content', 'all'); // ($user->gid >= 20); // At least J1.5 Editor $permission->CanEditOwn = $user->authorize('com_content', 'edit', 'content', 'own'); // ($user->gid >= 20); // At least J1.5 Editor $permission->CanPublish = $user->authorize('com_content', 'publish', 'content', 'all'); // ($user->gid >= 21); // At least J1.5 Publisher $permission->CanPublishOwn = $user->authorize('com_content', 'publish', 'content', 'own'); // ($user->gid >= 21); // At least J1.5 Publisher $permission->CanDelete = $user->gid >= 23; // At least J1.5 Manager $permission->CanDeleteOwn = $user->gid >= 23; // At least J1.5 Manager $permission->CanChangeCat = 1; // J1.5 lacks this $permission->CanChangeSecCat = 1; // J1.5 lacks this $permission->CanChangeFeatCat = 1; // J1.5 lacks this $permission->CanRights = $user->gid >= 23; // At least J1.5 Manager $permission->CanAccLvl = $user->gid >= 20; // At least J1.5 Editor // ITEMS: component controlled permissions $permission->DisplayAllItems = $user->gid >= 23; // At least J1.5 Manager $permission->CanCopy = $user->gid >= 23; // At least J1.5 Manager $permission->CanOrder = $user->gid >= 23; // At least J1.5 Manager $permission->CanParams = $user->gid >= 19; // At least J1.5 Author $permission->CanVersion = $user->gid >= 19; // At least J1.5 Author $permission->AssocAnyTrans = $user->gid >= 19; // At least J1.5 Author //$permission->EditCreationDate = ($user->gid >= 23); // At least J1.5 Manager $permission->IgnoreViewState = $user->gid >= 20; // At least J1.5 Editor $permission->RequestApproval = $user->gid >= 20; // At least J1.5 Editor // CATEGORIES: management tab and usage $permission->CanCats = $user->gid >= 23; // At least J1.5 Manager $permission->ViewAllCats = 1; $permission->ViewTree = 1; $permission->MultiCat = $user->gid >= 19; // At least J1.5 Author $permission->CanAddCats = $user->gid >= 23; // At least J1.5 Manager // TAGS: management tab and usage $permission->CanTags = $user->gid >= 23; // At least J1.5 Manager $permission->CanUseTags = $user->gid >= 19; // At least J1.5 Author $permission->CanNewTags = $user->gid >= 19; // At least J1.5 Author // VARIOUS management TABS: types, archives, statistics, templates, tags $permission->CanTypes = $user->gid >= 23; // At least J1.5 Manager $permission->CanArchives = $user->gid >= 23; // At least J1.5 Manager $permission->CanTemplates = $user->gid >= 23; // At least J1.5 Manager $permission->CanStats = $user->gid >= 23; // At least J1.5 Manager $permission->CanImport = $user->gid >= 23; // At least J1.5 Manager // FIELDS: management tab $permission->CanFields = $user->gid >= 23; // At least J1.5 Manager $permission->CanCopyFields = $user->gid >= 24; // At least J1.5 Administrator $permission->CanOrderFields = $user->gid >= 24; // At least J1.5 Administrator $permission->CanAddField = $user->gid >= 24; // At least J1.5 Administrator $permission->CanEditField = $user->gid >= 24; // At least J1.5 Administrator $permission->CanDeleteField = $user->gid >= 24; // At least J1.5 Administrator $permission->CanPublishField = $user->gid >= 24; // At least J1.5 Administrator // FILES: management tab $permission->CanFiles = $user->gid >= 19; // At least J1.5 Author $permission->CanUpload = $user->gid >= 19; // At least J1.5 Author $permission->CanViewAllFiles = $user->gid >= 23; // At least J1.5 Manager // AUTHORS: management tab $permission->CanAuthors = $user->gid >= 24; // At least J1.5 Administrator $permission->CanGroups = 0; //FLEXI_J16GE ? $permission->CanAuthors : 0; // SEARCH INDEX: management tab $permission->CanIndex = $user->gid >= 23; // At least J1.5 Manager // OTHER components permissions $permission->CanPlugins = $user->gid >= 24; // At least J1.5 Administrator $permission->CanComments = $user->gid >= 23; // At least J1.5 Manager $permission->CanComments = $permission->CanComments && $Comments_Enabled; // Global parameter to force always displaying of categories as tree if (JComponentHelper::getParams('com_flexicontent')->get('cats_always_astree', 1)) { $permission->ViewTree = 1; } return $permission; } //!!! ALLOWs USERS in JOOMLA BACKEND : (not used in J1.5) // (a) to view the FLEXIcontent menu item in Components Menu and // (b) to access the FLEXIcontent component screens (whatever they are allowed to see by individual FLEXIcontent area permissions) // NOTE: the initially installed permissions allows all areas to be managed for J2.5 and none (except for items) for J1.5 $permission->CanManage = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'manage', 'users', $user->gmid) : 1; // ITEMS/CATEGORIES: category-inherited permissions, (NOTE: these are the global settings, so:) // *** 1. the action permissions of individual items are checked seperately per item // *** 2. the view permission is checked via the access level of each item $permission->CanAdd = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'submit', 'users', $user->gmid) || FAccess::checkAllContentAccess('com_content', 'add', 'users', $user->gmid, 'content', 'all') : 1; $permission->CanEdit = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'edit', 'users', $user->gmid) : 1; $permission->CanEditOwn = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'editown', 'users', $user->gmid) : 1; $permission->CanPublish = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'publish', 'users', $user->gmid) : 1; $permission->CanPublishOwn = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'publishown', 'users', $user->gmid) : 1; $permission->CanDelete = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'delete', 'users', $user->gmid) : 1; $permission->CanDeleteOwn = $user->gid < 25 ? FAccess::checkComponentAccess('com_content', 'deleteown', 'users', $user->gmid) : 1; $permission->CanChangeCat = 1; $permission->CanChangeSecCat = 1; $permission->CanChangeFeatCat = 1; // Permission for changing the ACL rules of items and categories that user can edit // Given to users that FLEXIaccess configuration $permission->CanRights = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexiaccess', 'manage', 'users', $user->gmid) : 1; // Permission for changing the access level of items and categories that user can edit // (a) In J1.5 with FLEXIaccess, this is given to those that can edit the FLEXIaccess configuration // (b) In J1.5 without FLEXIaccess, this is given to users being at least an Editor // (c) In J2.5, this is the FLEXIcontent component ACTION 'accesslevel' $permission->CanAccLvl = $permission->CanRights; // ITEMS: component controlled permissions $permission->DisplayAllItems = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'displayallitems', 'users', $user->gmid) : 1; // (backend) List all items (otherwise only items that can be edited) $permission->CanCopy = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'copyitems', 'users', $user->gmid) : 1; // (backend) Item Copy Task $permission->CanOrder = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'order', 'users', $user->gmid) : 1; // (backend) Reorder items inside the category $permission->CanParams = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'paramsitems', 'users', $user->gmid) : 1; // (backend) Edit item parameters like meta data and template parameters $permission->CanVersion = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'versioning', 'users', $user->gmid) : 1; // (backend) Use item versioning $permission->AssocAnyTrans = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'assocanytrans', 'users', $user->gmid) : 1; // (item edit form) associate any translation //$permission->EditCreationDate = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'editcreationdate', 'users', $user->gmid) : 1; // (item edit form) edit creation date (frontend) $permission->IgnoreViewState = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'ignoreviewstate', 'users', $user->gmid) : 1; // (Frontend Content Lists) ignore view state $permission->RequestApproval = $user->gid >= 20; // At least J1.5 Editor // CATEGORIES: management tab and usage $permission->CanCats = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'categories', 'users', $user->gmid) : 1; // (backend) Allow management of Categories $permission->ViewAllCats = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'usercats', 'users', $user->gmid) : 1; // (e.g. item edit form) view the categories which user cannot assign to items $permission->ViewTree = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'cattree', 'users', $user->gmid) : 1; // (e.g. item edit form) view categories as tree instead of flat list $permission->MultiCat = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'multicat', 'users', $user->gmid) : 1; // (e.g. item edit form) allow user to assign each item to multiple categories $permission->CanAddCats = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'addcats', 'users', $user->gmid) : 1; // add new Categories // TAGS: management tab and usage $permission->CanTags = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'tags', 'users', $user->gmid) : 1; // (backend) Allow management of Item Types $permission->CanUseTags = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'usetags', 'users', $user->gmid) : 1; // edit already assigned Tags of items $permission->CanNewTags = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'newtags', 'users', $user->gmid) : 1; // add new Tags to items // VARIOUS management TABS: types, archives, statistics, templates, tags $permission->CanTypes = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'types', 'users', $user->gmid) : 1; // (backend) Allow management of Item Types $permission->CanArchives = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'archives', 'users', $user->gmid) : 1; // (backend) Allow management of Archives $permission->CanTemplates = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'templates', 'users', $user->gmid) : 1; // (backend) Allow management of Templates $permission->CanStats = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'stats', 'users', $user->gmid) : 1; // (backend) Allow management of Statistics $permission->CanImport = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'import', 'users', $user->gmid) : 1; // (backend) Allow management of (Content) Import // FIELDS: management tab $permission->CanFields = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'fields', 'users', $user->gmid) : 1; // (backend) Allow management of Fields $permission->CanCopyFields = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'copyfields', 'users', $user->gmid) : 1; // (backend) Field Copy Task $permission->CanOrderFields = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'orderfields', 'users', $user->gmid) : 1; // (backend) Reorder fields inside each item type $permission->CanAddField = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'createfield', 'users', $user->gmid) : 1; // (backend) Create fields $permission->CanEditField = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'editfield', 'users', $user->gmid) : 1; // (backend) Edit fields $permission->CanDeleteField = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'deletefield', 'users', $user->gmid) : 1; // (backend) Delete fields $permission->CanPublishField = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'publishfield', 'users', $user->gmid) : 1; // (backend) Publish fields // FILES: management tab $permission->CanFiles = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'files', 'users', $user->gmid) : 1; $permission->CanUpload = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'uploadfiles', 'users', $user->gmid) : 1; // allow user to upload Files $permission->CanViewAllFiles = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'viewallfiles', 'users', $user->gmid) : 1; // allow user to view all Files // AUTHORS: management tab $permission->CanAuthors = $user->gid < 25 ? FAccess::checkComponentAccess('com_users', 'manage', 'users', $user->gmid) : 1; $permission->CanGroups = 0; //FLEXI_J16GE ? $permission->CanAuthors : 0; // SEARCH INDEX: management tab $permission->CanIndex = $permission->CanFields && ($permission->CanAddField || $permission->CanEditField); // OTHER components permissions $permission->CanPlugins = $user->gid < 25 ? FAccess::checkComponentAccess('com_plugins', 'manage', 'users', $user->gmid) : 1; $permission->CanComments = $user->gid < 25 ? FAccess::checkComponentAccess('com_jcomments', 'manage', 'users', $user->gmid) : 1; $permission->CanComments = $permission->CanComments && $Comments_Enabled; // Global parameter to force always displaying of categories as tree if (JComponentHelper::getParams('com_flexicontent')->get('cats_always_astree', 1)) { $permission->ViewTree = 1; } return $permission; }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit( 'Invalid Token' ); // Initialize variables $app = JFactory::getApplication(); $db = JFactory::getDBO(); $user = JFactory::getUser(); $menu = $app->getMenu()->getActive(); $config = JFactory::getConfig(); $session = JFactory::getSession(); $task = JRequest::getVar('task'); $model = $this->getModel(FLEXI_ITEMVIEW); $isnew = !$model->getId(); $ctrl_task = FLEXI_J16GE ? 'task=items.' : 'controller=items&task='; $fc_params = JComponentHelper::getParams( 'com_flexicontent' ); $dolog = $fc_params->get('print_logging_info'); // Get the COMPONENT only parameters $comp_params = JComponentHelper::getComponent('com_flexicontent')->params; $params = FLEXI_J16GE ? clone ($comp_params) : new JParameter( $comp_params ); // clone( JComponentHelper::getParams('com_flexicontent') ); // Merge the type parameters $tparams = $model->getTypeparams(); $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams); $params->merge($tparams); // Merge the menu parameters if ($menu) { $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params); $params->merge($menu_params); } // Get needed parameters $submit_redirect_url_fe = $params->get('submit_redirect_url_fe', ''); $allowunauthorize = $params->get('allowunauthorize', 0); // ********************* // Get data from request // ********************* if (FLEXI_J16GE) { // Retrieve form data these are subject to basic filtering $data = JRequest::getVar('jform', array(), 'post', 'array'); // Core Fields and and item Parameters $custom = JRequest::getVar('custom', array(), 'post', 'array'); // Custom Fields $jfdata = JRequest::getVar('jfdata', array(), 'post', 'array'); // Joomfish Data if ( ! @ $data['rules'] ) $data['rules'] = array(); } else { // Retrieve form data these are subject to basic filtering $data = JRequest::get( 'post' ); // Core & Custom Fields and item Parameters } // Set data id into model in case not already set ? $model->setId((int) $data['id']); // ************************************* // ENFORCE can change category ACL perms // ************************************* $perms = FlexicontentHelperPerm::getPerm(); // Per content type change category permissions if (FLEXI_J16GE) { $current_type_id = ($isnew || !$model->get('type_id')) ? $data['type_id'] : $model->get('type_id'); // GET current (existing/old) item TYPE ID $CanChangeFeatCat = $user->authorise('flexicontent.change.cat.feat', 'com_flexicontent.type.' . $current_type_id); $CanChangeSecCat = $user->authorise('flexicontent.change.cat.sec', 'com_flexicontent.type.' . $current_type_id); $CanChangeCat = $user->authorise('flexicontent.change.cat', 'com_flexicontent.type.' . $current_type_id); } else { $CanChangeFeatCat = 1; $CanChangeSecCat = 1; $CanChangeCat = 1; } $featured_cats_parent = $params->get('featured_cats_parent', 0); $featured_cats = array(); $enable_featured_cid_selector = $perms->MultiCat && $CanChangeFeatCat; $enable_cid_selector = $perms->MultiCat && $CanChangeSecCat; $enable_catid_selector = ($isnew && !$tparams->get('catid_default')) || (!$isnew && !$model->get('catid')) || $CanChangeCat; // Enforce maintaining featured categories $featured_cats_parent = $params->get('featured_cats_parent', 0); $featured_cats = array(); if ( $featured_cats_parent && !$enable_featured_cid_selector ) { $featured_tree = flexicontent_cats::getCategoriesTree($published_only=1, $parent_id=$featured_cats_parent, $depth_limit=0); $featured_cid = array(); if (!$isnew) { foreach($model->get('categories') as $item_cat) if (isset($featured_tree[$item_cat])) $featured_cid[] = $item_cat; } $data['featured_cid'] = $featured_cid; } // Enforce maintaining secondary categories if (!$enable_cid_selector) { if ($isnew) { $data['cid'] = $tparams->get('cid_default'); } else if ( isset($featured_cid) ) { $featured_cid_arr = array_flip($featured_cid); $sec_cid = array(); foreach($model->get('cats') as $item_cat) if (!isset($featured_cid_arr[$item_cat])) $sec_cid[] = $item_cat; $data['cid'] = $sec_cid; } else { $data['cid'] = $model->get('cats'); } } if (!$enable_catid_selector) { if ($isnew && $tparams->get('catid_default')) $data['catid'] = $tparams->get('catid_default'); else if ($model->get('catid')) $data['catid'] = $model->get('catid'); } // ************************** // Basic Form data validation // ************************** if (FLEXI_J16GE) { // *** MANUALLY CHECK CAPTCHA *** $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) $is_submitop = ((int) $data['id']) == 0; $display_captcha = $use_captcha >= 2 || ( $use_captcha == 1 && $user->guest ); $display_captcha = $display_captcha && ( $is_submitop || $captcha_formop); // for submit operation we do not need to check 'captcha_formop' ... if ($display_captcha) { // Try to force the use of recaptcha plugin JFactory::getConfig()->set('captcha', 'recaptcha'); if ( $app->getCfg('captcha') == 'recaptcha' && JPluginHelper::isEnabled('captcha', 'recaptcha') ) { JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onCheckAnswer', JRequest::getString('recaptcha_response_field')); if (!$result[0]) { $errmsg = JText::_('FLEXI_CAPTCHA_FAILED'); $errmsg .= ' '.JText::_('FLEXI_MUST_REFILL_SOME_FIELDS'); echo "<script>alert('".$errmsg."');"; echo "window.history.back();"; echo "</script>"; jexit(); } } } // Validate Form data for core fields and for parameters $form = $model->getForm(); // Do not pass any data we only want the form object in order to validate the data and not create a filled-in form $post = $model->validate($form, $data); // Check for validation error if (!$post) { // Get the validation messages. $errors = $form->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) $app->enqueueMessage($errors[$i]->getMessage(), 'notice'); else $app->enqueueMessage($errors[$i], 'notice'); } // Save the jform data in the session. $app->setUserState($form->option.'.edit.'.$form->context.'.data', $data); // Save the custom fields data in the session. $app->setUserState($form->option.'.edit.'.$form->context.'.custom', $custom); // Redirect back to the registration form. $this->setRedirect( $_SERVER['HTTP_REFERER'] ); return false; //die('error'); } /*if (!$post) { //JError::raiseWarning( 500, "Error while validating data: " . $model->getError() ); echo "Error while validating data: " . $model->getError(); echo '<span class="fc_return_msg">'.JText::sprintf('FLEXI_CLICK_HERE_TO_RETURN', '"JavaScript:window.history.back();"').'</span>'; jexit(); }*/ // Some values need to be assigned after validation $post['attribs'] = @$data['attribs']; // Workaround for item's template parameters being clear by validation since they are not present in item.xml $post['custom'] = & $custom; // Assign array of custom field values, they are in the 'custom' form array instead of jform $post['jfdata'] = & $jfdata; // Assign array of Joomfish field values, they are in the 'jfdata' form array instead of jform // Assign template parameters of the select ilayout as an sub-array (the DB model will handle the merging of parameters) $ilayout = @ $data['attribs']['ilayout']; // normal not be set if frontend template editing is not shown if( $ilayout && !empty($data['layouts'][$ilayout]) ) $post['attribs']['layouts'] = $data['layouts']; //echo "<pre>"; print_r($post['attribs']); exit; } else { $post = $data; // Some values need to be assigned after validation $post['text'] = JRequest::getVar( 'text', '', 'post', 'string', JREQUEST_ALLOWRAW ); // Workaround for allowing raw text field // Assign template parameters of the select ilayout as an sub-array (the DB model will handle the merging of parameters) $ilayout = @ $post['params']['ilayout']; // normal not be set if frontend template editing is not shown if( $ilayout && !empty($post['layouts'][$ilayout]) ) $post['params']['layouts'] = $post['layouts']; //echo "<pre>"; print_r($post['params']); exit; } // USEFULL FOR DEBUGING for J2.5 (do not remove commented code) //$diff_arr = array_diff_assoc ( $data, $post); //echo "<pre>"; print_r($diff_arr); jexit(); // ******************************************************************************** // PERFORM ACCESS CHECKS, NOTE: we need to check access again, despite having // checked them on edit form load, because user may have tampered with the form ... // ******************************************************************************** $type_id = (int) @ $post['type_id']; // Typecast to int, (already done for J2.5 via validating) if ( !$isnew && $model->get('type_id') == $type_id ) { // Existing item with Type not being ALTERED, content type can be maintained regardless of privilege $canCreateType = true; } else { // New item or existing item with Type is being ALTERED, check privilege to create items of this type $canCreateType = $model->canCreateType( array($type_id), true, $types ); } // **************************************************************** // Calculate user's privileges on current content item // ... canPublish IS RECALCULATED after saving, maybe comment out ? // **************************************************************** if (!$isnew) { if (FLEXI_J16GE) { $asset = 'com_content.article.' . $model->get('id'); $canPublish = $user->authorise('core.edit.state', $asset) || ($user->authorise('core.edit.state.own', $asset) && $model->get('created_by') == $user->get('id')); $canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id')); // ALTERNATIVE 1 //$canEdit = $model->getItemAccess()->get('access-edit'); // includes privileges edit and edit-own // ALTERNATIVE 2 //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id')); //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ; } else if ($user->gid >= 25) { $canPublish = true; $canEdit = true; } else if (FLEXI_ACCESS) { $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid')); $canPublish = in_array('publish', $rights) || (in_array('publishown', $rights) && $model->get('created_by') == $user->get('id')) ; $canEdit = in_array('edit', $rights) || (in_array('editown', $rights) && $model->get('created_by') == $user->get('id')) ; } else { $canPublish = $user->authorize('com_content', 'publish', 'content', 'all'); $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || ($user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id')); //$canPublish = ($user->gid >= 21); // At least J1.5 Publisher //$canEdit = ($user->gid >= 20); // At least J1.5 Editor } if ( !$canEdit ) { // No edit privilege, check if item is editable till logoff if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $canEdit = isset($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')]; } } } else { if (FLEXI_J16GE) { $canAdd = $model->getItemAccess()->get('access-create'); // includes check of creating in at least one category $not_authorised = !$canAdd; $canPublish = $user->authorise('core.edit.state', 'com_flexicontent') || $user->authorise('core.edit.state.own', 'com_flexicontent'); } else if ($user->gid >= 25) { $canAdd = 1; } else if (FLEXI_ACCESS) { $canAdd = FAccess::checkUserElementsAccess($user->gmid, 'submit'); $canAdd = @$canAdd['content'] || @$canAdd['category']; $canPublishAll = FAccess::checkAllContentAccess('com_content','publish','users',$user->gmid,'content','all'); $canPublishOwnAll = FAccess::checkAllContentAccess('com_content','publishown','users',$user->gmid,'content','all'); $canPublish = ($user->gid < 25) ? $canPublishAll || $canPublishOwnAll : 1; } else { $canAdd = $user->authorize('com_content', 'add', 'content', 'all'); //$canAdd = ($user->gid >= 19); // At least J1.5 Author $not_authorised = ! $canAdd; $canPublish = ($user->gid >= 21); } if ( $allowunauthorize ) { $canAdd = true; $canCreateType = true; } } // ... we use some strings from administrator part // 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); // Check for new content if ( ($isnew && !$canAdd) || (!$isnew && !$canEdit)) { $msg = JText::_( 'FLEXI_ALERTNOTAUTH' ); if (FLEXI_J16GE) throw new Exception($msg, 403); else JError::raiseError(403, $msg); } if ( !$canCreateType ) { $msg = isset($types[$type_id]) ? JText::sprintf( 'FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', JText::_($types[$type_id]->name) ) : ' Content Type '.$type_id.' was not found OR is not published'; if (FLEXI_J16GE) throw new Exception($msg, 403); else JError::raiseError(403, $msg); return; } // Get "BEFORE SAVE" categories for information mail $before_cats = array(); if ( !$isnew ) { $query = 'SELECT DISTINCT c.id, c.title FROM #__categories AS c' . ' JOIN #__flexicontent_cats_item_relations AS rel ON rel.catid = c.id' . ' WHERE rel.itemid = '.(int) $model->get('id'); $db->setQuery( $query ); $before_cats = $db->loadObjectList('id'); $before_maincat = $model->get('catid'); $original_item = $model->getItem($post['id'], $check_view_access=false, $no_cache=true, $force_version=0); } // **************************************** // Try to store the form data into the item // **************************************** if ( ! $model->store($post) ) { // Set error message about saving failed, and also the reason (=model's error message) $msg = JText::_( 'FLEXI_ERROR_STORING_ITEM' ); JError::raiseWarning( 500, $msg .": " . $model->getError() ); // Since an error occured, check if (a) the item is new and (b) was not created if ($isnew && !$model->get('id')) { $msg = ''; $link = 'index.php?option=com_flexicontent&'.$ctrl_task.'add&id=0&typeid='.$type_id.'&'. (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) .'=1'; $this->setRedirect($link, $msg); } else { $msg = ''; $link = 'index.php?option=com_flexicontent&'.$ctrl_task.'edit&id='.$model->get('id').'&'. (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) .'=1'; $this->setRedirect($link, $msg); } // Saving has failed check-in and return, (above redirection will be used) $model->checkin(); return; } // ************************************************** // Check in model and get item id in case of new item // ************************************************** $model->checkin(); $post['id'] = $isnew ? (int) $model->get('id') : $post['id']; // Get items marked as newly submitted $newly_submitted = $session->get('newly_submitted', array(), 'flexicontent'); if ($isnew) { // Mark item as newly submitted, to allow to a proper "THANKS" message after final save & close operation (since user may have clicked add instead of add & close) $newly_submitted[$model->get('id')] = 1; $session->set('newly_submitted', $newly_submitted, 'flexicontent'); } $newly_submitted_item = @ $newly_submitted[$model->get('id')]; // *********************************************************************************************************** // Get newly saved -latest- version (store task gets latest) of the item, and also calculate publish privelege // *********************************************************************************************************** $item = $model->getItem($post['id'], $check_view_access=false, $no_cache=true, $force_version=-1); $canPublish = $model->canEditState( $item, $check_cat_perm=true ); // ******************************************************************************************** // Use session to detect multiple item saves to avoid sending notification EMAIL multiple times // ******************************************************************************************** $is_first_save = true; if ($session->has('saved_fcitems', 'flexicontent')) { $saved_fcitems = $session->get('saved_fcitems', array(), 'flexicontent'); $is_first_save = $isnew ? true : !isset($saved_fcitems[$model->get('id')]); } // Add item to saved items of the corresponding session array $saved_fcitems[$model->get('id')] = $timestamp = time(); // Current time as seconds since Unix epoc; $session->set('saved_fcitems', $saved_fcitems, 'flexicontent'); // ******************************************** // Get categories added / removed from the item // ******************************************** $query = 'SELECT DISTINCT c.id, c.title FROM #__categories AS c' . ' JOIN #__flexicontent_cats_item_relations AS rel ON rel.catid = c.id' . ' WHERE rel.itemid = '.(int) $model->get('id'); $db->setQuery( $query ); $after_cats = $db->loadObjectList('id'); if ( !$isnew ) { $cats_added_ids = array_diff(array_keys($after_cats), array_keys($before_cats)); foreach($cats_added_ids as $cats_added_id) { $cats_added_titles[] = $after_cats[$cats_added_id]->title; } $cats_removed_ids = array_diff(array_keys($before_cats), array_keys($after_cats)); foreach($cats_removed_ids as $cats_removed_id) { $cats_removed_titles[] = $before_cats[$cats_removed_id]->title; } $cats_altered = count($cats_added_ids) + count($cats_removed_ids); $after_maincat = $model->get('catid'); } // ******************************************************************************************************************* // We need to get emails to notify, from Global/item's Content Type parameters -AND- from item's categories parameters // ******************************************************************************************************************* $notify_emails = array(); if ( $is_first_save || $cats_altered || $params->get('nf_enable_debug',0) ) { // Get needed flags regarding the saved items $approve_version = 2; $pending_approval_state = -3; $draft_state = -4; $current_version = FLEXIUtilities::getCurrentVersions($item->id, true); // Get current item version $last_version = FLEXIUtilities::getLastVersions($item->id, true); // Get last version (=latest one saved, highest version id), // $post variables vstate & state may have been (a) tampered in the form, and/or (b) altered by save procedure so better not use them $needs_version_reviewal = !$isnew && ($last_version > $current_version) && !$canPublish; $needs_publication_approval = $isnew && ($item->state == $pending_approval_state) && !$canPublish; $draft_from_non_publisher = $item->state==$draft_state && !$canPublish; if ($draft_from_non_publisher) { // Suppress notifications for draft-state items (new or existing ones), for these each author will publication approval manually via a button $nConf = false; } else { // Get notifications configuration and select appropriate emails for current saving case $nConf = $model->getNotificationsConf($params); //echo "<pre>"; print_r($nConf); "</pre>"; } if ($nConf) { $states_notify_new = $params->get('states_notify_new', array(1,0,(FLEXI_J16GE ? 2:-1),-3,-4,-5)); if ( empty($states_notify_new) ) $states_notify_new = array(); else if ( ! is_array($states_notify_new) ) $states_notify_new = !FLEXI_J16GE ? array($states_notify_new) : explode("|", $states_notify_new); $states_notify_existing = $params->get('states_notify_existing', array(1,0,(FLEXI_J16GE ? 2:-1),-3,-4,-5)); if ( empty($states_notify_existing) ) $states_notify_existing = array(); else if ( ! is_array($states_notify_existing) ) $states_notify_existing = !FLEXI_J16GE ? array($states_notify_existing) : explode("|", $states_notify_existing); $n_state_ok = in_array($item->state, $states_notify_new); $e_state_ok = in_array($item->state, $states_notify_existing); if ($needs_publication_approval) $notify_emails = $nConf->emails->notify_new_pending; else if ($isnew && $n_state_ok) $notify_emails = $nConf->emails->notify_new; else if ($isnew) $notify_emails = array(); else if ($needs_version_reviewal) $notify_emails = $nConf->emails->notify_existing_reviewal; else if (!$isnew && $e_state_ok) $notify_emails = $nConf->emails->notify_existing; else if (!$isnew) $notify_emails = array(); if ($needs_publication_approval) $notify_text = $params->get('text_notify_new_pending'); else if ($isnew) $notify_text = $params->get('text_notify_new'); else if ($needs_version_reviewal) $notify_text = $params->get('text_notify_existing_reviewal'); else if (!$isnew) $notify_text = $params->get('text_notify_existing'); //print_r($notify_emails); jexit(); } } // ********************************************************************************************************************* // If there are emails to notify for current saving case, then send the notifications emails, but // ********************************************************************************************************************* if ( !empty($notify_emails) && count($notify_emails) ) { $notify_vars = new stdClass(); $notify_vars->needs_version_reviewal = $needs_version_reviewal; $notify_vars->needs_publication_approval = $needs_publication_approval; $notify_vars->isnew = $isnew; $notify_vars->notify_emails = $notify_emails; $notify_vars->notify_text = $notify_text; $notify_vars->before_cats = $before_cats; $notify_vars->after_cats = $after_cats; $notify_vars->original_item = @ $original_item; $model->sendNotificationEmails($notify_vars, $params, $manual_approval_request=0); } // *************************************************** // CLEAN THE CACHE so that our changes appear realtime // *************************************************** if (FLEXI_J16GE) { $cache = FLEXIUtilities::getCache($group='', 0); $cache->clean('com_flexicontent_items'); $cache->clean('com_flexicontent_filters'); $cache = FLEXIUtilities::getCache($group='', 1); $cache->clean('com_flexicontent_items'); $cache->clean('com_flexicontent_filters'); } else { $itemcache = JFactory::getCache('com_flexicontent_items'); $itemcache->clean(); $filtercache = JFactory::getCache('com_flexicontent_filters'); $filtercache->clean(); } // **************************************************************************************************************************** // Recalculate EDIT PRIVILEGE of new item. Reason for needing to do this is because we can have create permission in a category // and thus being able to set this category as item's main category, but then have no edit/editown permission for this category // **************************************************************************************************************************** if (FLEXI_J16GE) { $asset = 'com_content.article.' . $model->get('id'); $canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id')); // ALTERNATIVE 1 //$canEdit = $model->getItemAccess()->get('access-edit'); // includes privileges edit and edit-own // ALTERNATIVE 2 //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id')); //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ; } else if (FLEXI_ACCESS && $user->gid < 25) { $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid')); $canEdit = in_array('edit', $rights) || (in_array('editown', $rights) && $model->get('created_by') == $user->get('id')) ; } else { // This is meaningful when executed in frontend, since all backend users (managers and above) can edit items $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || ($user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id')); } // ******************************************************************************************************* // Check if user can not edit item further (due to changed main category, without edit/editown permission) // ******************************************************************************************************* if (!$canEdit) { if ($task=='apply') { // APPLY TASK: Temporarily set item to be editable till closing it $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $rendered_uneditable[$model->get('id')] = 1; $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } else if ( $newly_submitted_item ) { // NEW ITEM: Do not use editable till logoff behaviour // ALSO: Clear editable FLAG set in the case that 'apply' button was used during new item creation if ( !$params->get('items_session_editable', 0) ) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); if ( isset($rendered_uneditable[$model->get('id')]) ) { unset( $rendered_uneditable[$model->get('id')] ); $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); } } } else { // EXISTING ITEM: (if enabled) Use the editable till logoff behaviour if ( $params->get('items_session_editable', 0) ) { // Set notice for existing item being editable till logoff JError::raiseNotice( 403, JText::_( 'FLEXI_CANNOT_EDIT_AFTER_LOGOFF' ) ); // Allow item to be editable till logoff $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $rendered_uneditable[$model->get('id')] = 1; $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } } // Set notice about saving an item that cannot be changed further if ( !$canEdit ) { $app->enqueueMessage(JText::_( 'FLEXI_CANNOT_MAKE_FURTHER_CHANGES_TO_CONTENT' ), 'message' ); } } // **************************************************************** // Check for new Content Item is being closed, and clear some flags // **************************************************************** if ($task!='apply' && $newly_submitted_item ) { // Clear item from being marked as newly submitted unset($newly_submitted[$model->get('id')]); $session->set('newly_submitted', $newly_submitted, 'flexicontent'); // The 'apply' task may set 'editable till logoff' FLAG ... // CLEAR IT, since NEW content this is meant to be used temporarily if ( !$params->get('items_session_editable', 0) ) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); if ( isset($rendered_uneditable[$model->get('id')]) ) { unset( $rendered_uneditable[$model->get('id')] ); $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); } } } // **************************************** // Saving is done, decide where to redirect // **************************************** // REDIRECT CASE FOR APPLYING: Save and reload the item edit form if ($task=='apply') { $msg = JText::_( 'FLEXI_ITEM_SAVED' ); // Create the URL global $globalcats; $Itemid = JRequest::getInt('Itemid', 0); // maintain current menu item if this was given $item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $globalcats[$item->catid]->slug, $Itemid)); $link = $item_url .(strstr($item_url, '?') ? '&' : '?').'task=edit' ; // Important pass referer back to avoid making the form itself the referer // but also check that referer URL is 'safe' (allowed) , e.g. not an offsite URL, otherwise set referer to HOME page $referer = JRequest::getString('referer', JURI::base(), 'post'); if ( ! flexicontent_html::is_safe_url($referer) ) $referer = JURI::base(); $return = '&return='.base64_encode( $referer ); $link .= $return; } // REDIRECT CASES FOR SAVING else { // REDIRECT CASE: Return to a custom page after creating a new item (e.g. a thanks page) if ( $newly_submitted_item && $submit_redirect_url_fe ) { $link = $submit_redirect_url_fe; $msg = JText::_( 'FLEXI_ITEM_SAVED' ); } // REDIRECT CASE: Save and preview the latest version else if ($task=='save_a_preview') { $msg = JText::_( 'FLEXI_ITEM_SAVED' ); $link = JRoute::_(FlexicontentHelperRoute::getItemRoute($model->_item->id.':'.$model->_item->alias, $model->_item->catid, 0, $model->_item).'&preview=1', false); } // REDIRECT CASE: Return to the form 's referer (previous page) after item saving else { $msg = $newly_submitted_item ? JText::_( 'FLEXI_THANKS_SUBMISSION' ) : JText::_( 'FLEXI_ITEM_SAVED' ); // Check that referer URL is 'safe' (allowed) , e.g. not an offsite URL, otherwise for returning to HOME page $link = JRequest::getString('referer', JURI::base(), 'post'); if ( ! flexicontent_html::is_safe_url($link) ) { if ( $dolog ) JFactory::getApplication()->enqueueMessage( 'refused redirection to possible unsafe URL: '.$link, 'notice' ); $link = JURI::base(); } } } $this->setRedirect($link, $msg); }
/** * 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(); $session = JFactory::getSession(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $option = JRequest::getVar('option'); $nullDate = $db->getNullDate(); // Get the COMPONENT only parameters $params = clone JComponentHelper::getParams('com_flexicontent'); if (!FLEXI_J16GE) { jimport('joomla.html.pane'); $pane = JPane::getInstance('sliders'); $editor = JFactory::getEditor(); } // Some flags $enable_translation_groups = $params->get("enable_translation_groups") && (FLEXI_J16GE || FLEXI_FISH); $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'); $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable'); // Load custom behaviours: form validation, popup tooltips //JHTML::_('behavior.formvalidation'); JHTML::_('behavior.tooltip'); // Add css to document $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontentbackend.css'); if (FLEXI_J30GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j3x.css'); } else { if (FLEXI_J16GE) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j25.css'); } else { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/j15.css'); } } // Add js function to overload the joomla submitform $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/admin.js'); $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/validate.js'); // Add js function for custom code used by FLEXIcontent item form $document->addScript(JURI::root() . 'components/com_flexicontent/assets/js/itemscreen.js'); // *********************** // Get data from the model // *********************** if ($print_logging_info) { $start_microtime = microtime(true); } $model = $this->getModel(); $item = $this->get('Item'); if (FLEXI_J16GE) { $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'); } if (FLEXI_FISH || FLEXI_J16GE) { $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 JRequest::setVar('unique_tmp_itemid', $cid ? $cid : date('_Y_m_d_h_i_s_', time()) . uniqid(true)); // Get number of subscribers $subscribers = $model->getSubscribersCount(); // ****************** // Version Panel data // ****************** // Get / calculate some version related variables $versioncount = $model->getVersionCount(); $versionsperpage = $params->get('versionsperpage', 10); $pagecount = (int) ceil($versioncount / $versionsperpage); // Data need by version panel: (a) current version page, (b) currently active version $current_page = 1; $k = 1; $allversions = $model->getVersionList(); foreach ($allversions as $v) { if ($k > 1 && ($k - 1) % $versionsperpage == 0) { $current_page++; } if ($v->nr == $item->version) { break; } $k++; } // Finally fetch the version data for versions in current page $versions = $model->getVersionList(($current_page - 1) * $versionsperpage, $versionsperpage); // ***************** // Type related data // ***************** // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Get and merge type parameters $tparams = $this->get('Typeparams'); $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($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, $typesselected); if (!$perms['canparams']) { $document->addStyleDeclaration((FLEXI_J16GE ? '#details-options' : '#det-pane') . '{display:none;}'); } // ****************** // Create the toolbar // ****************** $toolbar = JToolBar::getInstance('toolbar'); // SET toolbar title if ($cid) { JToolBarHelper::title(JText::_('FLEXI_EDIT_ITEM'), 'itemedit'); // Editing existing item } else { JToolBarHelper::title(JText::_('FLEXI_NEW_ITEM'), 'itemadd'); // Creating new item } // Add a preview button for LATEST version of the item 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 $isAdmin = JFactory::getApplication()->isAdmin(); if ($isAdmin && FLEXI_J16GE) { JFactory::$application = JApplication::getInstance('site'); } // Create the URL $item_url = JRoute::_(FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . $autologin); // 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) { if (FLEXI_J16GE) { $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'); } else { $item_url = JURI::root(true) . '/' . $item_url; } } $previewlink = $item_url . (strstr($item_url, '?') ? '&' : '?') . 'preview=1'; //$previewlink = str_replace('&', '&', $previewlink); //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin; if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) { $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('Preview') . '</a>', 'preview'); } else { // Add a preview button for (currently) LOADED version of the item $previewlink_loaded_ver = $previewlink . '&version=' . $item->version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_loaded_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</a>', 'preview'); // Add a preview button for currently ACTIVE version of the item $previewlink_active_ver = $previewlink . '&version=' . $item->current_version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_active_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</a>', 'preview'); // Add a preview button for currently LATEST version of the item $previewlink_last_ver = $previewlink; //'&version='.$item->last_version; $toolbar->appendButton('Custom', '<a class="preview btn btn-small" href="' . $previewlink_last_ver . '" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-32-preview"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</a>', 'preview'); } JToolBarHelper::spacer(); JToolBarHelper::divider(); JToolBarHelper::spacer(); } // Common Buttons if (FLEXI_J16GE) { JToolBarHelper::apply('items.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'); } else { JToolBarHelper::apply(); if (!$isnew || $item->version) { JToolBarHelper::save(); } if (!$isnew || $item->version) { JToolBarHelper::custom('saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false); } JToolBarHelper::cancel(); } // Check if saving an item that translates an original content in site's default language $is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($item->language, 0, 2); $modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id != $item->id; // ***************************************************************************** // Get (CORE & CUSTOM) fields and their VERSIONED values and then // (a) Apply Content Type Customization to CORE fields (label, description, etc) // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField' // ***************************************************************************** if ($print_logging_info) { $start_microtime = microtime(true); } $fields = $this->get('Extrafields'); 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); } 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 (FLEXI_J16GE) { $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); } else { if (FLEXI_ACCESS && $user->gid < 25) { $is_editable = !$field->valueseditable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'field', $field->id); } else { $is_editable = 1; } } if (!$is_editable) { $field->html = '<div class="fc-mssg fc-warning">' . JText::_('FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>'; } else { if ($modify_untraslatable_values && $field->untranslatable) { $field->html = '<div class="fc-mssg fc-note">' . JText::_('FLEXI_FIELD_VALUE_IS_UNTRANSLATABLE') . '</div>'; } else { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item)); } } } // c. Create main text field, via calling the display function of the textarea field (will also check for tabs) if ($field->field_type == 'maintext') { if (isset($item->item_translations)) { $shortcode = substr($item->language, 0, 2); foreach ($item->item_translations as $lang_id => $t) { if ($shortcode == $t->shortcode) { continue; } $field->name = array('jfdata', $t->shortcode, 'text'); $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8'); FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); $t->fields->text->tab_labels = $field->tab_labels; $t->fields->text->html = $field->html; unset($field->tab_labels); unset($field->html); } } $field->name = 'text'; // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data $field->value[0] = $item->text; // do not decode special characters this was handled during saving ! // Render the field's (form) HTML FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); } } if ($print_logging_info) { $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // ************************* // Get tags used by the item // ************************* $usedtagsIds = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) $usedtags = $model->getUsedtagsData($usedtagsIds); // ******************************* // Get categories used by the item // ******************************* if ($isnew) { // Case for preselected main category for new items $maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0); if (!$maincat) { $maincat = $app->getUserStateFromRequest($option . '.items.filter_cats', 'filter_cats', '', 'int'); } if ($maincat) { $selectedcats = array($maincat); $item->catid = $maincat; } else { $selectedcats = array(); } if ($tparams->get('cid_default')) { $selectedcats = $tparams->get('cid_default'); } if ($tparams->get('catid_default')) { $item->catid = $tparams->get('catid_default'); } } else { // NOTE: This will normally return the already set versioned value of categories ($item->categories) $selectedcats = $this->get('Catsselected'); } //$selectedcats = $isnew ? array() : $fields['categories']->value; //echo "<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 granular access list if (!FLEXI_J16GE) { if (FLEXI_ACCESS) { if (isset($user->level)) { $lists['access'] = FAccess::TabGmaccess($item, 'item', 1, 0, 0, 1, 0, 1, 0, 1, 1); } else { $lists['access'] = JText::_('Your profile has been changed, please logout to access to the permissions'); } } else { $lists['access'] = JHTML::_('list.accesslevel', $item); // created but not used in J1.5 backend form } } // build state list $_arc_ = FLEXI_J16GE ? 2 : -1; $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4; $special_privelege_stategrp = $item->state == $_arc_ || $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 == $_arc_ || $perms['canarchive']) { $state[] = JHTML::_('select.option', $_arc_, 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 = FLEXI_J16GE ? 'jform[state]' : 'state'; $elementid = FLEXI_J16GE ? 'jform_state' : '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-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['featured'] .= ' ' . JText::_($option_label) . '</label>'; } $i++; } } // *** EOF: J1.5 SPECIFIC SELECT LISTS // build version approval list $fieldname = FLEXI_J16GE ? 'jform[vstate]' : 'vstate'; $elementid = FLEXI_J16GE ? 'jform_vstate' : '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-label="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['vstate'] .= ' ' . 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 = FLEXI_J16GE ? 'jform[notify]' : 'notify'; $elementid = FLEXI_J16GE ? 'jform_notify' : '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-label="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" element_group_id="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />'; if (!$prettycheckable_added) { $lists['notify'] .= ' ' . $lbltxt . '</label>'; } } } // Retrieve author configuration $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id); if ($authorparams = $db->loadResult()) { $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams); } // 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) . '"]; max_cat_overlimit_msg_fc = "' . JText::_('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); $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 = FLEXI_J16GE ? 'jform[featured_cid][]' : '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); } 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); } else { $cid_tree =& $categories; } // 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) . '"]; max_cat_overlimit_msg_fc = "' . JText::_('FLEXI_TOO_MANY_ITEM_CATEGORIES', true) . '"; '); $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 = FLEXI_J16GE ? 'jform[cid][]' : '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()); } 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 = FLEXI_J16GE ? 'jform[catid]' : '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); } else { $catid_tree =& $categories; } $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); } else { if (!$isnew && $item->catid) { $lists['catid'] = $globalcats[$item->catid]->title; } } //buid types selectlist $class = 'required use_select2_lib'; $attribs = 'class="' . $class . '"'; $fieldname = FLEXI_J16GE ? 'jform[type_id]' : 'type_id'; $elementid = FLEXI_J16GE ? 'jform_type_id' : '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 $language_fieldname = FLEXI_J16GE ? 'jform[language]' : 'language'; if (FLEXI_FISH || FLEXI_J16GE) { $lists['languages'] = flexicontent_html::buildlanguageslist($language_fieldname, '', $item->language, 3, $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 (!FLEXI_J16GE) { // Create the form parameters object if (FLEXI_ACCESS) { $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item2.xml'); } else { $formparams = new JParameter('', JPATH_COMPONENT . DS . 'models' . DS . 'item.xml'); } // Details Group $active = intval($item->created_by) ? intval($item->created_by) : $user->get('id'); if (!FLEXI_ACCESS) { $formparams->set('access', $item->access); } $formparams->set('created_by', $active); $formparams->set('created_by_alias', $item->created_by_alias); $formparams->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S')); $formparams->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S')); if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) { $formparams->set('publish_down', JText::_('FLEXI_NEVER')); } else { $formparams->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S')); } // Advanced Group $formparams->loadINI($item->attribs); //echo "<pre>"; print_r($formparams->_xml['themes']->_children[0]); echo "<pre>"; print_r($formparams->_xml['themes']->param[0]); exit; foreach ($formparams->_xml['themes']->_children as $i => $child) { if (isset($child->_attributes['enableparam']) && !$params->get($child->_attributes['enableparam'])) { unset($formparams->_xml['themes']->_children[$i]); unset($formparams->_xml['themes']->param[$i]); } } // Metadata Group $formparams->set('description', $item->metadesc); $formparams->set('keywords', $item->metakey); $formparams->loadINI($item->metadata); } else { if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) { $form->setValue('publish_down', null, 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(); } else { if (!is_array($allowed_tmpls)) { $allowed_tmpls = !FLEXI_J16GE ? array($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); } } // ****************************** // 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('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); 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; } }
function save_import() { // Check for request forgeries //JRequest::checkToken() or jexit( 'Invalid Token' ); //mara $arr_countries = array('AL' => 'Albania', 'AM' => 'Armenia' , 'ARG' =>'Argentina' , 'AU' => 'Australia' , 'AUT' => 'Austria' , 'AZ' =>'Azerbaidjan' , 'BEL' => 'Belgium' , 'BGD' => 'Bangladesh' , 'BLG' => 'Bulgaria' , 'BLR' => 'Belarus' , 'BOS' => 'Bosnia-Herzegovina' , 'BRA' => 'Brazil' , 'CAN' => 'Canada' , 'CB' => 'Cuba' , 'CHE' => 'Switzerland' , 'CHI' => 'China' , 'CHL' => 'Chile' , 'CS' => 'Czech Republic' , 'DEU' => 'Germany' , 'DNK' => 'Denmark' , 'EGP' => 'Egypt' , 'EST' => 'Estonia' , 'FIN' => 'Finland' , 'FRA' => 'France' , 'GBR' => 'Great Britain' , 'GBRUSA' => 'Great Britain' , 'GEO' => 'Georgia' , 'GR' => 'Greece' , 'HK' => 'Hong Kong' , 'HOR' => 'Croatia' , 'HUN' => 'Hungary' , 'IDZ' => 'Indonesia' , 'IND' => 'India' , 'IOR' => 'Jordan' , 'IRA' => 'Iran' , 'IRL' => 'Ireland' , 'ISL' => 'Iceland' , 'ISR' => 'Israel' , 'ITA' => 'Italy' , 'JPN' => 'Japan' , 'KAZ' => 'Kazakhstan' , 'KGZ' => 'Kyrgyzstan' , 'KIP' => 'Cyprus' , 'LAT' => 'Latvia' , 'LIT' => 'Lithuania' , 'LUX' => 'Luxembourg' , 'MAK' => 'Macedonia' , 'ME' => 'Montenegro' , 'MEK' => 'Mexico' , 'MLT' => 'Malta' , 'MOL' => 'Moldavia' , 'MON' => 'Monaco' , 'NID' => 'Netherlands' , 'NOR' => 'Norway' , 'PAK' => 'Pakistan' , 'POL' => 'Poland' , 'PORT' => 'Portugal' , 'PR' => 'Puerto Rico' , 'PS' => 'Palestinian Territory' , 'RS' => 'Serbia' , 'RUM' => 'Romania' , 'RUS' => 'Russian Federation' , 'SA' => 'Saudi Arabia' , 'SCH' => 'Serbia' , 'SGP' => 'Singapore' , 'SHE' => 'Switzerland' , 'SKO' => 'South Korea' , 'SLO' => 'Slovenia' , 'SLR' => 'Slovak Republic' , 'SM' => 'San Marino' , 'SPN' => 'Spain' , 'SWE' => 'Sweden' , 'SYR' => 'Syria' , 'TA' => 'Thailand' , 'TUR' => 'Turkey' , 'UAR' => 'South Africa' , 'UGS' => 'Serbia' , 'UKR' => 'Ukraine' , 'unk' => 'Unknown' , 'USA' => 'United States' , 'USAFRA' => 'United States' , 'Uzb' => 'Uzbekistan' , 'VTN' => 'Vietnam'); mysql_connect('localhost', 'root', 'staSPE8e'); mysql_select_db('vidal'); mysql_query("SET NAMES utf8"); $query = "SELECT pa.ATCCode,m.LatName,n.NozologyCode,Document.DocumentID," ."Document.RusName,Document.EngName,Document.CompiledComposition,Document.PhInfluence,Document.PhKinetics," ."Document.Dosage,Document.OverDosage,Document.Interaction,Document.Lactation,Document.SideEffects," ."Document.StorageCondition,Document.Indication,Document.ContraIndication,Document.SpecialInstruction " . "FROM Document" ." LEFT JOIN Document_IndicNozology as n ON Document.DocumentID = n.DocumentID" ." LEFT JOIN Molecule_Document as md ON md.DocumentID = Document.DocumentID" ." LEFT JOIN Molecule as m ON m.MoleculeID = md.MoleculeID" ." LEFT JOIN Product_Document as pd ON pd.DocumentID = Document.DocumentID" ." LEFT JOIN Product_ATC as pa ON pd.ProductID = pa.ProductID" ." GROUP BY Document.DocumentID"; $result = mysql_query($query) or die(mysql_error()); while($all = mysql_fetch_array($result)){ // Initialize variables $app = JFactory::getApplication(); $db = JFactory::getDBO(); $user = JFactory::getUser(); $menu = $app->getMenu()->getActive(); $config = JFactory::getConfig(); $session = JFactory::getSession(); $task = JRequest::getVar('task'); $model = $this->getModel(FLEXI_ITEMVIEW); $isnew = !$model->getId(); $ctrl_task = FLEXI_J16GE ? 'task=items.' : 'controller=items&task='; $fc_params = JComponentHelper::getParams( 'com_flexicontent' ); $dolog = $fc_params->get('print_logging_info'); // Get the COMPONENT only parameters $comp_params = JComponentHelper::getComponent('com_flexicontent')->params; $params = FLEXI_J16GE ? clone ($comp_params) : new JParameter( $comp_params ); // clone( JComponentHelper::getParams('com_flexicontent') ); // Merge the type parameters $tparams = $model->getTypeparams(); $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams); $params->merge($tparams); // Merge the menu parameters if ($menu) { $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params); $params->merge($menu_params); } // Get needed parameters $submit_redirect_url_fe = $params->get('submit_redirect_url_fe', ''); $allowunauthorize = $params->get('allowunauthorize', 0); $data = array(); $data['title'] = $all['RusName']; //content $data['text'] = $all['CompiledComposition'].$all['PhInfluence'].$all['PhKinetics'].$all['Dosage'].$all['OverDosage'].$all['Interaction'].$all['Lactation'].$all['SideEffects'].$all['StorageCondition'].$all['Indication'].$all['ContraIndication'].$all['SpecialInstruction']; $data['state'] = 1; $data['catid'] = 45; $data['type_id'] = 2; $data['id'] = 0; //insert into content //flexicontent_fields_item_relations //15 field RusName EngName //19 field Zabolev $zab = ''; if($all['NozologyCode']){ $tmp = $all['NozologyCode']; $zab_cif = substr($tmp,1,2); $alpha = substr($tmp,0,1); switch($alpha){ case 'A' : $zab = 'A00–B99'; break; case 'B' : $zab = 'A00–B99';break; case 'C' : $zab = 'C00–D48';break; case 'D' : $zab = $zab_cif <= 48 ? 'C00–D48' : 'D50–D89';break; case 'E' : $zab = 'E00–E90';break; case 'F' : $zab = 'F00–F99';break; case 'G' : $zab = 'G00–G99';break; case 'H' : $zab = $zab_cif <= 59 ? 'H00–H59' : 'H60–H95';break; case 'I' : $zab = 'I00–I99';break; case 'J' : $zab = 'J00–J99';break; case 'K' : $zab = 'K00–K93';break; case 'L' : $zab = 'L00–L99';break; case 'M' : $zab = 'M00–M99';break; case 'N' : $zab = 'N00–N99';break; case 'O' : $zab = 'O00–O99';break; case 'P' : $zab = 'P00–P96'; break; case 'R' : $zab = 'R00–R99'; break; case 'S' : $zab = 'S00–T98'; break; case 'V' : $zab = 'V01–Y98';break; case 'Z' : $zab = 'Z00–Z99';break; case 'U' : $zab = 'U00–U99'; break; default: $zab = ''; } } $custom = array(); $custom['zabolevanie'] = $zab; $custom['field24'] = $all['ATCCode']; /*$custom['field24_1'] = ''; $custom['field24_2'] = ''; $custom['field24_3'] = ''; $custom['field24_4'] = ''; $custom['field24_5'] = '';*/ $custom['preparat'][0] = addslashes($all['RusName']); $custom['preparat'][1] = addslashes($all['EngName']); $custom['field22'][0] = addslashes($all['LatName']); $query = "SELECT p.DateOfCloseRegistration, p.RegistrationNumber, p.Composition, p.ZipInfo, " ." c.LocalName, c.CountryCode " . "FROM Product as p" ." JOIN Product_Company as pc ON pc.ProductID = p.ProductID" ." JOIN Company as c ON c.CompanyID = pc.CompanyID" ." JOIN Product_Document d ON d.ProductID = p.ProductID" ." WHERE d.DocumentID = ".$all['DocumentID']; $result1 = mysql_query($query) or die(mysql_error()); $field_pr = array(); $z = 0; while($proizv = mysql_fetch_array($result1)){ if(isset($arr_countries[$proizv['CountryCode']])){ $custom['field21'][0]['country'][$z] = addslashes($arr_countries[$proizv['CountryCode']]); $custom['field21'][0]['naimen'][$z] = addslashes($proizv['LocalName']);//."<br />".$proizv['Composition']); $custom['field21'][0]['vypusk'][$z] = addslashes($proizv['ZipInfo']); $custom['field21'][0]['reg'][$z] = addslashes($proizv['RegistrationNumber']); $custom['field21'][0]['date'][$z] = addslashes($proizv['DateOfCloseRegistration']); } $z++; } // ********************* // Get data from request // ********************* if (FLEXI_J16GE) { // Retrieve form data these are subject to basic filtering // $data = JRequest::getVar('jform', array(), 'post', 'array'); // Core Fields and and item Parameters // $custom = JRequest::getVar('custom', array(), 'post', 'array'); // Custom Fields $jfdata = JRequest::getVar('jfdata', array(), 'post', 'array'); // Joomfish Data if ( ! @ $data['rules'] ) $data['rules'] = array(); } else { // Retrieve form data these are subject to basic filtering $data = JRequest::get( 'post' ); // Core & Custom Fields and item Parameters } // Set data id into model in case not already set ? $model->setId((int) $data['id']); // ************************************* // ENFORCE can change category ACL perms // ************************************* $perms = FlexicontentHelperPerm::getPerm(); // Per content type change category permissions if (FLEXI_J16GE) { $current_type_id = ($isnew || !$model->get('type_id')) ? $data['type_id'] : $model->get('type_id'); // GET current (existing/old) item TYPE ID $CanChangeFeatCat = $user->authorise('flexicontent.change.cat.feat', 'com_flexicontent.type.' . $current_type_id); $CanChangeSecCat = $user->authorise('flexicontent.change.cat.sec', 'com_flexicontent.type.' . $current_type_id); $CanChangeCat = $user->authorise('flexicontent.change.cat', 'com_flexicontent.type.' . $current_type_id); } else { $CanChangeFeatCat = 1; $CanChangeSecCat = 1; $CanChangeCat = 1; } $featured_cats_parent = $params->get('featured_cats_parent', 0); $featured_cats = array(); $enable_featured_cid_selector = $perms->MultiCat && $CanChangeFeatCat; $enable_cid_selector = $perms->MultiCat && $CanChangeSecCat; $enable_catid_selector = ($isnew && !$tparams->get('catid_default')) || (!$isnew && !$model->get('catid')) || $CanChangeCat; // Enforce maintaining featured categories $featured_cats_parent = $params->get('featured_cats_parent', 0); $featured_cats = array(); if ( $featured_cats_parent && !$enable_featured_cid_selector ) { $featured_tree = flexicontent_cats::getCategoriesTree($published_only=1, $parent_id=$featured_cats_parent, $depth_limit=0); $featured_cid = array(); if (!$isnew) { foreach($model->get('categories') as $item_cat) if (isset($featured_tree[$item_cat])) $featured_cid[] = $item_cat; } $data['featured_cid'] = $featured_cid; } // Enforce maintaining secondary categories if (!$enable_cid_selector) { if ($isnew) { $data['cid'] = $tparams->get('cid_default'); } else if ( isset($featured_cid) ) { $featured_cid_arr = array_flip($featured_cid); $sec_cid = array(); foreach($model->get('cats') as $item_cat) if (!isset($featured_cid_arr[$item_cat])) $sec_cid[] = $item_cat; $data['cid'] = $sec_cid; } else { $data['cid'] = $model->get('cats'); } } if (!$enable_catid_selector) { if ($isnew && $tparams->get('catid_default')) $data['catid'] = $tparams->get('catid_default'); else if ($model->get('catid')) $data['catid'] = $model->get('catid'); } // ************************** // Basic Form data validation // ************************** if (FLEXI_J16GE) { // *** MANUALLY CHECK CAPTCHA *** $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) $is_submitop = ((int) $data['id']) == 0; $display_captcha = $use_captcha >= 2 || ( $use_captcha == 1 && $user->guest ); $display_captcha = $display_captcha && ( $is_submitop || $captcha_formop); // for submit operation we do not need to check 'captcha_formop' ... if ($display_captcha) { // Try to force the use of recaptcha plugin JFactory::getConfig()->set('captcha', 'recaptcha'); if ( $app->getCfg('captcha') == 'recaptcha' && JPluginHelper::isEnabled('captcha', 'recaptcha') ) { JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $result = $dispatcher->trigger('onCheckAnswer', JRequest::getString('recaptcha_response_field')); if (!$result[0]) { $errmsg = JText::_('FLEXI_CAPTCHA_FAILED'); $errmsg .= ' '.JText::_('FLEXI_MUST_REFILL_SOME_FIELDS'); echo "<script>alert('".$errmsg."');"; echo "window.history.back();"; echo "</script>"; jexit(); } } } // Validate Form data for core fields and for parameters $form = $model->getForm(); // Do not pass any data we only want the form object in order to validate the data and not create a filled-in form $post = $model->validate($form, $data); // Check for validation error if (!$post) { // Get the validation messages. $errors = $form->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) $app->enqueueMessage($errors[$i]->getMessage(), 'notice'); else $app->enqueueMessage($errors[$i], 'notice'); } // Save the jform data in the session. $app->setUserState($form->option.'.edit.'.$form->context.'.data', $data); // Save the custom fields data in the session. $app->setUserState($form->option.'.edit.'.$form->context.'.custom', $custom); // Redirect back to the registration form. $this->setRedirect( $_SERVER['HTTP_REFERER'] ); return false; //die('error'); } /*if (!$post) { //JError::raiseWarning( 500, "Error while validating data: " . $model->getError() ); echo "Error while validating data: " . $model->getError(); echo '<span class="fc_return_msg">'.JText::sprintf('FLEXI_CLICK_HERE_TO_RETURN', '"JavaScript:window.history.back();"').'</span>'; jexit(); }*/ // Some values need to be assigned after validation $post['attribs'] = @$data['attribs']; // Workaround for item's template parameters being clear by validation since they are not present in item.xml $post['custom'] = & $custom; // Assign array of custom field values, they are in the 'custom' form array instead of jform $post['jfdata'] = & $jfdata; // Assign array of Joomfish field values, they are in the 'jfdata' form array instead of jform // Assign template parameters of the select ilayout as an sub-array (the DB model will handle the merging of parameters) $ilayout = @ $data['attribs']['ilayout']; // normal not be set if frontend template editing is not shown if( $ilayout && !empty($data['layouts'][$ilayout]) ) $post['attribs']['layouts'] = $data['layouts']; //echo "<pre>"; print_r($post['attribs']); exit; } else { $post = $data; // Some values need to be assigned after validation $post['text'] = JRequest::getVar( 'text', '', 'post', 'string', JREQUEST_ALLOWRAW ); // Workaround for allowing raw text field // Assign template parameters of the select ilayout as an sub-array (the DB model will handle the merging of parameters) $ilayout = @ $post['params']['ilayout']; // normal not be set if frontend template editing is not shown if( $ilayout && !empty($post['layouts'][$ilayout]) ) $post['params']['layouts'] = $post['layouts']; //echo "<pre>"; print_r($post['params']); exit; } // USEFULL FOR DEBUGING for J2.5 (do not remove commented code) //$diff_arr = array_diff_assoc ( $data, $post); //echo "<pre>"; print_r($diff_arr); jexit(); // ******************************************************************************** // PERFORM ACCESS CHECKS, NOTE: we need to check access again, despite having // checked them on edit form load, because user may have tampered with the form ... // ******************************************************************************** $type_id = (int) @ $post['type_id']; // Typecast to int, (already done for J2.5 via validating) if ( !$isnew && $model->get('type_id') == $type_id ) { // Existing item with Type not being ALTERED, content type can be maintained regardless of privilege $canCreateType = true; } else { // New item or existing item with Type is being ALTERED, check privilege to create items of this type $canCreateType = $model->canCreateType( array($type_id), true, $types ); } // **************************************************************** // Calculate user's privileges on current content item // ... canPublish IS RECALCULATED after saving, maybe comment out ? // **************************************************************** if (!$isnew) { if (FLEXI_J16GE) { $asset = 'com_content.article.' . $model->get('id'); $canPublish = $user->authorise('core.edit.state', $asset) || ($user->authorise('core.edit.state.own', $asset) && $model->get('created_by') == $user->get('id')); $canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id')); // ALTERNATIVE 1 //$canEdit = $model->getItemAccess()->get('access-edit'); // includes privileges edit and edit-own // ALTERNATIVE 2 //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id')); //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ; } else if ($user->gid >= 25) { $canPublish = true; $canEdit = true; } else if (FLEXI_ACCESS) { $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid')); $canPublish = in_array('publish', $rights) || (in_array('publishown', $rights) && $model->get('created_by') == $user->get('id')) ; $canEdit = in_array('edit', $rights) || (in_array('editown', $rights) && $model->get('created_by') == $user->get('id')) ; } else { $canPublish = $user->authorize('com_content', 'publish', 'content', 'all'); $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || ($user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id')); //$canPublish = ($user->gid >= 21); // At least J1.5 Publisher //$canEdit = ($user->gid >= 20); // At least J1.5 Editor } if ( !$canEdit ) { // No edit privilege, check if item is editable till logoff if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $canEdit = isset($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')]; } } } else { if (FLEXI_J16GE) { $canAdd = $model->getItemAccess()->get('access-create'); // includes check of creating in at least one category $not_authorised = !$canAdd; $canPublish = $user->authorise('core.edit.state', 'com_flexicontent') || $user->authorise('core.edit.state.own', 'com_flexicontent'); } else if ($user->gid >= 25) { $canAdd = 1; } else if (FLEXI_ACCESS) { $canAdd = FAccess::checkUserElementsAccess($user->gmid, 'submit'); $canAdd = @$canAdd['content'] || @$canAdd['category']; $canPublishAll = FAccess::checkAllContentAccess('com_content','publish','users',$user->gmid,'content','all'); $canPublishOwnAll = FAccess::checkAllContentAccess('com_content','publishown','users',$user->gmid,'content','all'); $canPublish = ($user->gid < 25) ? $canPublishAll || $canPublishOwnAll : 1; } else { $canAdd = $user->authorize('com_content', 'add', 'content', 'all'); //$canAdd = ($user->gid >= 19); // At least J1.5 Author $not_authorised = ! $canAdd; $canPublish = ($user->gid >= 21); } if ( $allowunauthorize ) { $canAdd = true; $canCreateType = true; } } // ... we use some strings from administrator part // 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); // Check for new content if ( ($isnew && !$canAdd) || (!$isnew && !$canEdit)) { $msg = JText::_( 'FLEXI_ALERTNOTAUTH' ); if (FLEXI_J16GE) throw new Exception($msg, 403); else JError::raiseError(403, $msg); } if ( !$canCreateType ) { $msg = isset($types[$type_id]) ? JText::sprintf( 'FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', JText::_($types[$type_id]->name) ) : ' Content Type '.$type_id.' was not found OR is not published'; if (FLEXI_J16GE) throw new Exception($msg, 403); else JError::raiseError(403, $msg); return; } // Get "BEFORE SAVE" categories for information mail $before_cats = array(); if ( !$isnew ) { $query = 'SELECT DISTINCT c.id, c.title FROM #__categories AS c' . ' JOIN #__flexicontent_cats_item_relations AS rel ON rel.catid = c.id' . ' WHERE rel.itemid = '.(int) $model->get('id'); $db->setQuery( $query ); $before_cats = $db->loadObjectList('id'); $before_maincat = $model->get('catid'); $original_item = $model->getItem($post['id'], $check_view_access=false, $no_cache=true, $force_version=0); } // **************************************** // Try to store the form data into the item // **************************************** if ( ! $model->store($post) ) { // Set error message about saving failed, and also the reason (=model's error message) $msg = JText::_( 'FLEXI_ERROR_STORING_ITEM' ); JError::raiseWarning( 500, $msg .": " . $model->getError() ); // Since an error occured, check if (a) the item is new and (b) was not created if ($isnew && !$model->get('id')) { $msg = ''; $link = 'index.php?option=com_flexicontent&'.$ctrl_task.'add&id=0&typeid='.$type_id.'&'. (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) .'=1'; $this->setRedirect($link, $msg); } else { $msg = ''; $link = 'index.php?option=com_flexicontent&'.$ctrl_task.'edit&id='.$model->get('id').'&'. (FLEXI_J30GE ? JSession::getFormToken() : JUtility::getToken()) .'=1'; $this->setRedirect($link, $msg); } // Saving has failed check-in and return, (above redirection will be used) $model->checkin(); return; } // ************************************************** // Check in model and get item id in case of new item // ************************************************** $model->checkin(); $post['id'] = $isnew ? (int) $model->get('id') : $post['id']; // Get items marked as newly submitted $newly_submitted = $session->get('newly_submitted', array(), 'flexicontent'); if ($isnew) { // Mark item as newly submitted, to allow to a proper "THANKS" message after final save & close operation (since user may have clicked add instead of add & close) $newly_submitted[$model->get('id')] = 1; $session->set('newly_submitted', $newly_submitted, 'flexicontent'); } $newly_submitted_item = @ $newly_submitted[$model->get('id')]; // *********************************************************************************************************** // Get newly saved -latest- version (store task gets latest) of the item, and also calculate publish privelege // *********************************************************************************************************** $item = $model->getItem($post['id'], $check_view_access=false, $no_cache=true, $force_version=-1); $canPublish = $model->canEditState( $item, $check_cat_perm=true ); // ******************************************************************************************** // Use session to detect multiple item saves to avoid sending notification EMAIL multiple times // ******************************************************************************************** $is_first_save = true; if ($session->has('saved_fcitems', 'flexicontent')) { $saved_fcitems = $session->get('saved_fcitems', array(), 'flexicontent'); $is_first_save = $isnew ? true : !isset($saved_fcitems[$model->get('id')]); } // Add item to saved items of the corresponding session array $saved_fcitems[$model->get('id')] = $timestamp = time(); // Current time as seconds since Unix epoc; $session->set('saved_fcitems', $saved_fcitems, 'flexicontent'); // ******************************************** // Get categories added / removed from the item // ******************************************** $query = 'SELECT DISTINCT c.id, c.title FROM #__categories AS c' . ' JOIN #__flexicontent_cats_item_relations AS rel ON rel.catid = c.id' . ' WHERE rel.itemid = '.(int) $model->get('id'); $db->setQuery( $query ); $after_cats = $db->loadObjectList('id'); if ( !$isnew ) { $cats_added_ids = array_diff(array_keys($after_cats), array_keys($before_cats)); foreach($cats_added_ids as $cats_added_id) { $cats_added_titles[] = $after_cats[$cats_added_id]->title; } $cats_removed_ids = array_diff(array_keys($before_cats), array_keys($after_cats)); foreach($cats_removed_ids as $cats_removed_id) { $cats_removed_titles[] = $before_cats[$cats_removed_id]->title; } $cats_altered = count($cats_added_ids) + count($cats_removed_ids); $after_maincat = $model->get('catid'); } // ******************************************************************************************************************* // We need to get emails to notify, from Global/item's Content Type parameters -AND- from item's categories parameters // ******************************************************************************************************************* $notify_emails = array(); if ( $is_first_save || $cats_altered || $params->get('nf_enable_debug',0) ) { // Get needed flags regarding the saved items $approve_version = 2; $pending_approval_state = -3; $draft_state = -4; $current_version = FLEXIUtilities::getCurrentVersions($item->id, true); // Get current item version $last_version = FLEXIUtilities::getLastVersions($item->id, true); // Get last version (=latest one saved, highest version id), // $post variables vstate & state may have been (a) tampered in the form, and/or (b) altered by save procedure so better not use them $needs_version_reviewal = !$isnew && ($last_version > $current_version) && !$canPublish; $needs_publication_approval = $isnew && ($item->state == $pending_approval_state) && !$canPublish; $draft_from_non_publisher = $item->state==$draft_state && !$canPublish; if ($draft_from_non_publisher) { // Suppress notifications for draft-state items (new or existing ones), for these each author will publication approval manually via a button $nConf = false; } else { // Get notifications configuration and select appropriate emails for current saving case $nConf = $model->getNotificationsConf($params); //echo "<pre>"; print_r($nConf); "</pre>"; } if ($nConf) { $states_notify_new = $params->get('states_notify_new', array(1,0,(FLEXI_J16GE ? 2:-1),-3,-4,-5)); if ( empty($states_notify_new) ) $states_notify_new = array(); else if ( ! is_array($states_notify_new) ) $states_notify_new = !FLEXI_J16GE ? array($states_notify_new) : explode("|", $states_notify_new); $states_notify_existing = $params->get('states_notify_existing', array(1,0,(FLEXI_J16GE ? 2:-1),-3,-4,-5)); if ( empty($states_notify_existing) ) $states_notify_existing = array(); else if ( ! is_array($states_notify_existing) ) $states_notify_existing = !FLEXI_J16GE ? array($states_notify_existing) : explode("|", $states_notify_existing); $n_state_ok = in_array($item->state, $states_notify_new); $e_state_ok = in_array($item->state, $states_notify_existing); if ($needs_publication_approval) $notify_emails = $nConf->emails->notify_new_pending; else if ($isnew && $n_state_ok) $notify_emails = $nConf->emails->notify_new; else if ($isnew) $notify_emails = array(); else if ($needs_version_reviewal) $notify_emails = $nConf->emails->notify_existing_reviewal; else if (!$isnew && $e_state_ok) $notify_emails = $nConf->emails->notify_existing; else if (!$isnew) $notify_emails = array(); if ($needs_publication_approval) $notify_text = $params->get('text_notify_new_pending'); else if ($isnew) $notify_text = $params->get('text_notify_new'); else if ($needs_version_reviewal) $notify_text = $params->get('text_notify_existing_reviewal'); else if (!$isnew) $notify_text = $params->get('text_notify_existing'); //print_r($notify_emails); jexit(); } } // ********************************************************************************************************************* // If there are emails to notify for current saving case, then send the notifications emails, but // ********************************************************************************************************************* if ( !empty($notify_emails) && count($notify_emails) ) { $notify_vars = new stdClass(); $notify_vars->needs_version_reviewal = $needs_version_reviewal; $notify_vars->needs_publication_approval = $needs_publication_approval; $notify_vars->isnew = $isnew; $notify_vars->notify_emails = $notify_emails; $notify_vars->notify_text = $notify_text; $notify_vars->before_cats = $before_cats; $notify_vars->after_cats = $after_cats; $notify_vars->original_item = @ $original_item; $model->sendNotificationEmails($notify_vars, $params, $manual_approval_request=0); } // *************************************************** // CLEAN THE CACHE so that our changes appear realtime // *************************************************** if (FLEXI_J16GE) { $cache = FLEXIUtilities::getCache($group='', 0); $cache->clean('com_flexicontent_items'); $cache->clean('com_flexicontent_filters'); $cache = FLEXIUtilities::getCache($group='', 1); $cache->clean('com_flexicontent_items'); $cache->clean('com_flexicontent_filters'); } else { $itemcache = JFactory::getCache('com_flexicontent_items'); $itemcache->clean(); $filtercache = JFactory::getCache('com_flexicontent_filters'); $filtercache->clean(); } // **************************************************************************************************************************** // Recalculate EDIT PRIVILEGE of new item. Reason for needing to do this is because we can have create permission in a category // and thus being able to set this category as item's main category, but then have no edit/editown permission for this category // **************************************************************************************************************************** if (FLEXI_J16GE) { $asset = 'com_content.article.' . $model->get('id'); $canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id')); // ALTERNATIVE 1 //$canEdit = $model->getItemAccess()->get('access-edit'); // includes privileges edit and edit-own // ALTERNATIVE 2 //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id')); //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ; } else if (FLEXI_ACCESS && $user->gid < 25) { $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid')); $canEdit = in_array('edit', $rights) || (in_array('editown', $rights) && $model->get('created_by') == $user->get('id')) ; } else { // This is meaningful when executed in frontend, since all backend users (managers and above) can edit items $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || ($user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id')); } // ******************************************************************************************************* // Check if user can not edit item further (due to changed main category, without edit/editown permission) // ******************************************************************************************************* if (!$canEdit) { if ($task=='apply') { // APPLY TASK: Temporarily set item to be editable till closing it $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $rendered_uneditable[$model->get('id')] = 1; $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } else if ( $newly_submitted_item ) { // NEW ITEM: Do not use editable till logoff behaviour // ALSO: Clear editable FLAG set in the case that 'apply' button was used during new item creation if ( !$params->get('items_session_editable', 0) ) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); if ( isset($rendered_uneditable[$model->get('id')]) ) { unset( $rendered_uneditable[$model->get('id')] ); $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); } } } else { // EXISTING ITEM: (if enabled) Use the editable till logoff behaviour if ( $params->get('items_session_editable', 0) ) { // Set notice for existing item being editable till logoff JError::raiseNotice( 403, JText::_( 'FLEXI_CANNOT_EDIT_AFTER_LOGOFF' ) ); // Allow item to be editable till logoff $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); $rendered_uneditable[$model->get('id')] = 1; $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } } // Set notice about saving an item that cannot be changed further if ( !$canEdit ) { $app->enqueueMessage(JText::_( 'FLEXI_CANNOT_MAKE_FURTHER_CHANGES_TO_CONTENT' ), 'message' ); } } // **************************************************************** // Check for new Content Item is being closed, and clear some flags // **************************************************************** if ($task!='apply' && $newly_submitted_item ) { // Clear item from being marked as newly submitted unset($newly_submitted[$model->get('id')]); $session->set('newly_submitted', $newly_submitted, 'flexicontent'); // The 'apply' task may set 'editable till logoff' FLAG ... // CLEAR IT, since NEW content this is meant to be used temporarily if ( !$params->get('items_session_editable', 0) ) { $rendered_uneditable = $session->get('rendered_uneditable', array(),'flexicontent'); if ( isset($rendered_uneditable[$model->get('id')]) ) { unset( $rendered_uneditable[$model->get('id')] ); $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); } } } } //$this->setRedirect($link, $msg); }
/** * 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(); // Get the COMPONENT only parameters, then merge the menu parameters $comp_params = JComponentHelper::getComponent('com_flexicontent')->params; $params = FLEXI_J16GE ? clone $comp_params : new JParameter($comp_params); // clone( JComponentHelper::getParams('com_flexicontent') ); if ($menu) { $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params); $params->merge($menu_params); } // Some flags $enable_translation_groups = $params->get("enable_translation_groups") && (FLEXI_J16GE || FLEXI_FISH); $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'); // Load custom behaviours: form validation, popup tooltips //JHTML::_('behavior.formvalidation'); 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(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css'); } if (!FLEXI_J16GE) { $document->addStyleSheet($this->baseurl . '/administrator/templates/khepri/css/general.css'); } //$document->addCustomTag('<!--[if IE]><style type="text/css">.floattext{zoom:1;}, * html #flexicontent dd { height: 1%; }</style><![endif]-->'); // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend) $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexi_shared.css'); // NOTE: this is imported by main Frontend CSS file if (FLEXI_J30GE) { $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css'); } else { if (FLEXI_J16GE) { $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css'); } else { $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j15.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 and create 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! 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'); if (!$new_typeid) { $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true); if ($types && count($types) == 1) { $new_typeid = $types[0]->id; } JRequest::setVar('typeid', $new_typeid); $canCreateType = true; } $item = $this->get('Item'); if (FLEXI_J16GE) { $form = $this->get('Form'); } if ($print_logging_info) { $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // ********************************************************************************************************* // Get language stuff, and also load Template-Specific language file to override or add new language strings // ********************************************************************************************************* if ($enable_translation_groups) { $langAssocs = $this->get('LangAssocs'); } if (FLEXI_FISH || FLEXI_J16GE) { $langs = FLEXIUtilities::getLanguages('code'); } if (FLEXI_FISH || FLEXI_J16GE) { FLEXIUtilities::loadTemplateLanguageFile($item->parameters->get('ilayout', 'default')); } // **************************************************************************************** // CHECK EDIT / CREATE PERMISSIONS (this is duplicate since it also done at the controller) // **************************************************************************************** // new item and ownership variables $isnew = !$item->id; $isOwner = $item->created_by == $user->get('id'); // create and set (into HTTP request) a unique item id for plugins that needed it JRequest::setVar('unique_tmp_itemid', $item->id ? $item->id : date('_Y_m_d_h_i_s_', time()) . uniqid(true)); // 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 if (FLEXI_J16GE) { $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); // Force using recaptcha if ($display_captcha) { // Try to force the use of recaptcha plugin JFactory::getConfig()->set('captcha', 'recaptcha'); if (!$app->getCfg('captcha')) { $captcha_errmsg = '-- Please select <b>CAPTCHA Type</b> at global Joomla parameters'; } else { if ($app->getCfg('captcha') != 'recaptcha') { $captcha_errmsg = '-- Captcha Type: <b>' . $app->getCfg('captcha') . '</b> not supported'; } else { if (!JPluginHelper::isEnabled('captcha', 'recaptcha')) { $captcha_errmsg = '-- Please enable & configure the Joomla <b>ReCaptcha Plugin</b>'; } else { $captcha_errmsg = ''; JPluginHelper::importPlugin('captcha'); $dispatcher->trigger('onInit', 'dynamic_recaptcha_1'); $field_description = JText::_('FLEXI_CAPTCHA_ENTER_CODE_DESC'); $label_tooltip = 'class="hasTip flexi_label" title="' . '::' . htmlspecialchars($field_description, ENT_COMPAT, 'UTF-8') . '"'; $captcha_field = ' <label id="recaptcha_response_field-lbl" for="recaptcha_response_field" ' . $label_tooltip . ' > ' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . ' </label> <div class="container_fcfield container_fcfield_name_captcha"> <div id="dynamic_recaptcha_1"></div> </div> '; } } } } } // User Group / Author parameters $db->setQuery('SELECT author_basicparams FROM #__flexicontent_authors_ext WHERE user_id = ' . $user->id); $authorparams = $db->loadResult(); $authorparams = FLEXI_J16GE ? new JRegistry($authorparams) : new JParameter($authorparams); $max_auth_limit = $authorparams->get('max_auth_limit', 0); // maximum number of content items the user can create 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(); if (FLEXI_J16GE) { $canEdit = $model->getItemAccess()->get('access-edit'); // includes privileges edit and edit-own // ALTERNATIVE 1 //$asset = 'com_content.article.' . $model->get('id'); //$canEdit = $user->authorise('core.edit', $asset) || ($user->authorise('core.edit.own', $asset) && $model->get('created_by') == $user->get('id')); // ALTERNATIVE 2 //$rights = FlexicontentHelperPerm::checkAllItemAccess($user->get('id'), 'item', $model->get('id')); //$canEdit = in_array('edit', $rights) || (in_array('edit.own', $rights) && $model->get('created_by') == $user->get('id')) ; } else { if ($user->gid >= 25) { $canEdit = true; } else { if (FLEXI_ACCESS) { $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $model->get('id'), $model->get('catid')); $canEdit = in_array('edit', $rights) || in_array('editown', $rights) && $model->get('created_by') == $user->get('id'); } else { $canEdit = $user->authorize('com_content', 'edit', 'content', 'all') || $user->authorize('com_content', 'edit', 'content', 'own') && $model->get('created_by') == $user->get('id'); //$canEdit = ($user->gid >= 20); // At least J1.5 Editor } } } if (!$canEdit) { // No edit privilege, check if item is editable till logoff if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $canEdit = isset($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')]; } } 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 if (FLEXI_J16GE) { $canAdd = $model->getItemAccess()->get('access-create'); // includes check of creating in at least one category $not_authorised = !$canAdd; } else { if ($user->gid >= 25) { $not_authorised = 0; } else { if (FLEXI_ACCESS) { $canAdd = FAccess::checkUserElementsAccess($user->gmid, 'submit'); $not_authorised = !(@$canAdd['content'] || @$canAdd['category']); } else { $canAdd = $user->authorize('com_content', 'add', 'content', 'all'); //$canAdd = ($user->gid >= 19); // At least J1.5 Author $not_authorised = !$canAdd; } } } // Check if Content Type can be created by current user if (empty($canCreateType)) { if ($new_typeid) { $canCreateType = $model->canCreateType(array($new_typeid)); // Can create given Content Type } else { $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 more variables to push into the FORM view // ********************************************* // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Create the type parameters $tparams = $this->get('Typeparams'); $tparams = FLEXI_J16GE ? new JRegistry($tparams) : new JParameter($tparams); // Merge item parameters, or type/menu parameters for new item if ($isnew) { if ($new_typeid) { $params->merge($tparams); } // Apply type configuration if it type is set if ($menu) { $params->merge($menu_params); } // Apply menu configuration if it menu is set, to override type configuration } else { $params = $item->parameters; } // Check if saving an item that translates an original content in site's default language $is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($item->language, 0, 2); $modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id != $item->id; // ***************************************************************************** // Get (CORE & CUSTOM) fields and their VERSIONED values and then // (a) Apply Content Type Customization to CORE fields (label, description, etc) // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField' // ***************************************************************************** if ($print_logging_info) { $start_microtime = microtime(true); } $fields = $this->get('Extrafields'); 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); } 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 (FLEXI_J16GE) { $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); } else { if (FLEXI_ACCESS && $user->gid < 25) { $is_editable = !$field->valueseditable || FAccess::checkAllContentAccess('com_content', 'submit', 'users', $user->gmid, 'field', $field->id); } else { $is_editable = 1; } } if (!$is_editable) { $field->html = '<div class="fc-mssg fc-warning">' . JText::_('FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>'; } else { if ($modify_untraslatable_values && $field->untranslatable) { $field->html = '<div class="fc-mssg fc-note">' . JText::_('FLEXI_FIELD_VALUE_IS_UNTRANSLATABLE') . '</div>'; } else { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item)); } } } // c. Create main text field, via calling the display function of the textarea field (will also check for tabs) if ($field->field_type == 'maintext') { if (isset($item->item_translations)) { $shortcode = substr($item->language, 0, 2); foreach ($item->item_translations as $lang_id => $t) { if ($shortcode == $t->shortcode) { continue; } $field->name = array('jfdata', $t->shortcode, 'text'); $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8'); FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); $t->fields->text->tab_labels = $field->tab_labels; $t->fields->text->html = $field->html; unset($field->tab_labels); unset($field->html); } } $field->name = 'text'; // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data $field->value[0] = $item->text; // do not decode special characters this was handled during saving ! // Render the field's (form) HTML FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); } } if ($print_logging_info) { $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Tags used by the item $usedtagsids = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) //$usedtagsIds = $isnew ? array() : $fields['tags']->value; $usedtagsdata = $model->getUsedtagsData($usedtagsids); //echo "<br/>usedtagsIds: "; print_r($usedtagsids); //echo "<br/>usedtags (data): "; print_r($usedtagsdata); // Compatibility for old overriden templates ... if (!FLEXI_J16GE) { $tags = $this->get('Alltags'); $usedtags = $this->get('UsedtagsIds'); } // Load permissions (used by form template) $perms = $this->_getItemPerms($item, $typesselected); // Get the edit lists $lists = $this->_buildEditLists($perms, $params, $authorparams, $typesselected, $tparams); // Get number of subscribers $subscribers = $this->get('SubscribersCount'); // Get menu overridden categories/main category fields $menuCats = $this->_getMenuCats($item, $perms, $params); // Create submit configuration (for new items) into the session $submitConf = $this->_createSubmitConf($item, $perms, $params); // Create placement configuration for CORE properties $placementConf = $this->_createPlacementConf($fields, $params, $item); // Item language related vars if (FLEXI_FISH || FLEXI_J16GE) { $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 = FLEXI_J16GE ? $menu->params : new JParameter($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 if (FLEXI_J16GE) { // Not available in J1.5 // 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); if (FLEXI_J16GE) { // most core field are created via calling methods of the form (J2.5) $this->assignRef('form', $form); } if ($enable_translation_groups) { $this->assignRef('lang_assocs', $langAssocs); } if (FLEXI_FISH || FLEXI_J16GE) { $this->assignRef('langs', $langs); } $this->assignRef('params', $params); $this->assignRef('lists', $lists); $this->assignRef('subscribers', $subscribers); $this->assignRef('editor', $editor); $this->assignRef('user', $user); if (!FLEXI_J16GE) { // compatibility old templates $this->assignRef('tags', $tags); $this->assignRef('usedtags', $usedtags); } $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); // ************************************************************************************** // Load a different template file for parameters depending on whether we use FLEXI_ACCESS // ************************************************************************************** if (!FLEXI_J16GE) { if (FLEXI_ACCESS) { $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item2.xml'); } else { $formparams = new JParameter('', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'item.xml'); } } // **************************************************************** // SET INTO THE FORM, parameter values for various parameter groups // **************************************************************** if (!FLEXI_J16GE) { // Permissions (Access) Group if (!FLEXI_ACCESS) { $formparams->set('access', $item->access); } // Set: (Publication) Details Group $created_by = intval($item->created_by) ? intval($item->created_by) : $user->get('id'); $formparams->set('created_by', $created_by); $formparams->set('created_by_alias', $item->created_by_alias); $formparams->set('created', JHTML::_('date', $item->created, '%Y-%m-%d %H:%M:%S')); $formparams->set('publish_up', JHTML::_('date', $item->publish_up, '%Y-%m-%d %H:%M:%S')); if (JHTML::_('date', $item->publish_down, '%Y') <= 1969 || $item->publish_down == $nullDate || empty($item->publish_down)) { $formparams->set('publish_down', JText::_('FLEXI_NEVER')); } else { $formparams->set('publish_down', JHTML::_('date', $item->publish_down, '%Y-%m-%d %H:%M:%S')); } // Set: Attributes (parameters) Group, (these are retrieved from the item table column 'attribs') // (also contains templates parameters, but we will use these individual for every template ... see below) $formparams->loadINI($item->attribs); //echo "<pre>"; print_r($formparams->_xml['themes']->_children[0]); echo "<pre>"; print_r($formparams->_xml['themes']->param[0]); exit; foreach ($formparams->_xml['themes']->_children as $i => $child) { if (isset($child->_attributes['enableparam']) && !$params->get($child->_attributes['enableparam'])) { unset($formparams->_xml['themes']->_children[$i]); unset($formparams->_xml['themes']->param[$i]); } } // Set: Metadata (parameters) Group // NOTE: (2 params from 2 item table columns, and then multiple params from item table column 'metadata') $formparams->set('description', $item->metadesc); $formparams->set('keywords', $item->metakey); if (!empty($item->metadata)) { $formparams->loadINI($item->metadata->toString()); } // Now create the sliders object, // And also push the Form Parameters object into the template (Template Parameters object is seperate) jimport('joomla.html.pane'); $pane = JPane::getInstance('Sliders'); //$tabs_pane = JPane::getInstance('Tabs'); $this->assignRef('pane', $pane); //$this->assignRef('tabs_pane' , $tabs_pane); $this->assignRef('formparams', $formparams); } else { 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(); } else { if (!is_array($allowed_tmpls)) { $allowed_tmpls = !FLEXI_J16GE ? array($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); 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; } }