static function getOriginalContentItemids($_items, $ids = null) { if (empty($ids) && empty($_items)) { return array(); } if (is_array($_items)) { $items =& $_items; } else { $items = array(&$_items); } if (empty($ids)) { $ids = array(); foreach ($items as $item) { $ids[] = $item->id; } } // Get associated translations $db = JFactory::getDBO(); $query = 'SELECT a.id as id, k.id as original_id' . ' FROM #__associations AS a' . ' JOIN #__associations AS k ON a.`key`=k.`key`' . ' JOIN #__content AS i ON i.id = k.id AND i.language = ' . $db->Quote(flexicontent_html::getSiteDefaultLang()) . ' WHERE a.id IN (' . implode(',', $ids) . ') AND a.context = "com_content.item"'; $db->setQuery($query); $assoc_keys = $db->loadObjectList('id'); if (!empty($items)) { foreach ($items as $item) { $item->lang_parent_id = isset($assoc_keys[$item->id]) ? $assoc_keys[$item->id]->original_id : $item->id; } } else { return $assoc_keys; } }
/** * Method to create the language datas * * @access public * @return boolean True on success * @since 1.5 */ function createLangColumn() { // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); $db = JFactory::getDBO(); $nullDate = $db->getNullDate(); // Add language column $columns = $db->getTableColumns('#__flexicontent_items_ext'); $language_col = array_key_exists('language', $columns) ? true : false; if (!$language_col) { $query = "ALTER TABLE #__flexicontent_items_ext ADD `language` VARCHAR( 11 ) NOT NULL DEFAULT '' AFTER `type_id`"; $db->setQuery($query); $result_lang_col = $db->query(); if (!$result_lang_col) { echo "Cannot add language column<br>"; } } else { $result_lang_col = true; } // Add translation group column $lang_parent_id_col = array_key_exists('lang_parent_id', $columns) ? true : false; if (!$lang_parent_id_col) { $query = "ALTER TABLE #__flexicontent_items_ext ADD `lang_parent_id` INT NOT NULL DEFAULT 0 AFTER `language`"; $db->setQuery($query); $result_tgrp_col = $db->query(); if (!$result_tgrp_col) { echo "Cannot add translation group column<br>"; } } else { $result_tgrp_col = true; } // Add default language for items that do not have one, and add translation group to items that do not have one set $model = $this->getModel('flexicontent'); if ($model->getItemsNoLang()) { // 1. copy language from __flexicontent_items_ext table into __content $this->syncItemsLang(); // 2. then for those that are still empty, add site default language to the language field if empty $lang = flexicontent_html::getSiteDefaultLang(); $result_items_default_lang = $this->setItemsDefaultLang($lang); if (!$result_items_default_lang) { echo "Cannot set default language or set default translation group<br>"; } } else { $result_items_default_lang = true; } $query = "\n\t\t\tINSERT INTO `#__associations` (`id`, `context`, `key`)\n\t\t\t\tSELECT DISTINCT ie.item_id, 'com_content.item', ie.lang_parent_id\n\t\t\t\tFROM `#__flexicontent_items_ext` AS ie\n\t\t\t\tJOIN `#__flexicontent_items_ext` AS j ON ie.lang_parent_id = j.lang_parent_id AND ie.item_id<>j.item_id\n\t\t\t\tWHERE ie.lang_parent_id <> 0\n\t\t\tON DUPLICATE KEY UPDATE id=id"; $db->setQuery($query); try { $convert_assocs = $db->query(); $query = "UPDATE `#__flexicontent_items_ext` SET lang_parent_id = 0"; $db->setQuery($query); $clear_assocs = $db->query(); } catch (Exception $e) { echo "Cannot convert FLEXIcontent associations to Joomla associations<br>"; JError::raiseWarning(500, $e->getMessage()); $convert_assocs = $clear_assocs = false; } if (!$result_lang_col || !$result_tgrp_col || !$result_items_default_lang || !$convert_assocs || !$clear_assocs) { echo '<span class="install-notok"></span>'; jexit(); } else { echo '<span class="install-ok"></span>'; } }
/** * Method to save field values of the item in field versioning DB table or in ..._fields_item_relations DB table * * @access public * @return boolean True on success * @since 1.0 */ function saveFields($isnew, &$item, &$data, &$files) { $app = JFactory::getApplication(); $user = JFactory::getUser(); $dispatcher = JDispatcher::getInstance(); $cparams = $this->_cparams; $use_versioning = $cparams->get('use_versioning', 1); $print_logging_info = $cparams->get('print_logging_info'); $last_version = FLEXIUtilities::getLastVersions($item->id, true); $mval_query = true; if ($print_logging_info) { global $fc_run_times; } if ($print_logging_info) { $start_microtime = microtime(true); } //********************************* // Checks for untranslatable fields //********************************* // CASE 1. Check if saving an item that translates an original content in site's default language // ... Decide whether to retrieve field values of untranslatable fields from the original content item $enable_translation_groups = $cparams->get('enable_translation_groups'); $is_content_default_lang = substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($item->language, 0, 2); $get_untraslatable_values = $enable_translation_groups && !$is_content_default_lang && $item->lang_parent_id && $item->lang_parent_id != $item->id; // CASE 2. Check if saving an original content item (item's language is site default language) // ... Get item ids of translating items if ($is_content_default_lang && $this->_id) { $query = 'SELECT ie.item_id' . ' FROM #__flexicontent_items_ext as ie' . ' WHERE ie.lang_parent_id = ' . (int) $this->_id . ' AND ie.item_id <> ' . (int) $this->_id; // DO NOT include the item itself in associated translations !! $this->_db->setQuery($query); $assoc_item_ids = FLEXI_J16GE ? $this->_db->loadColumn() : $this->_db->loadResultArray(); } if (empty($assoc_item_ids)) { $assoc_item_ids = array(); } // *************************************************************************************************************************** // Get item's fields ... and their values (for untranslatable fields the field values from original content item are retrieved // *************************************************************************************************************************** $fields = $this->getExtrafields($force = true, $get_untraslatable_values ? $item->lang_parent_id : 0); // ****************************************************************************************************************** // Loop through Fields triggering onBeforeSaveField Event handlers, this was seperated from the rest of the process // to give chance to ALL fields to check their DATA and cancel item saving process before saving any new field values // ****************************************************************************************************************** $searchindex = array(); //$qindex = array(); if ($fields) { foreach ($fields as $field) { // Set vstate property into the field object to allow this to be changed be the before saving field event handler $field->item_vstate = $data['vstate']; 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; } } // FORM HIDDEN FIELDS (FRONTEND/BACKEND) AND (ACL) UNEDITABLE FIELDS: maintain their DB value ... if ($app->isSite() && ($field->formhidden == 1 || $field->formhidden == 3 || $field->parameters->get('frontend_hidden')) || $app->isAdmin() && ($field->formhidden == 2 || $field->formhidden == 3 || $field->parameters->get('backend_hidden')) || !$is_editable) { $postdata[$field->name] = $field->value; // UNTRANSLATABLE (CUSTOM) FIELDS: maintain their DB value ... } else { if ($get_untraslatable_values && $field->untranslatable) { $postdata[$field->name] = $field->value; // CORE FIELDS: if not set maintain their DB value ... } else { if ($field->iscore) { $postdata[$field->name] = @$data[$field->name]; if (is_array($postdata[$field->name]) && !count($postdata[$field->name]) || !is_array($postdata[$field->name]) && !strlen(trim($postdata[$field->name]))) { $postdata[$field->name] = $field->value; } // OTHER CUSTOM FIELDS (not hidden and not untranslatable) } else { $postdata[$field->name] = !FLEXI_J16GE ? @$data[$field->name] : @$data['custom'][$field->name]; } } } // Unserialize values already serialized values, e.g. (a) if current values used are from DB or (b) are being imported from CSV file if (!is_array($postdata[$field->name])) { $postdata[$field->name] = strlen($postdata[$field->name]) ? array($postdata[$field->name]) : array(); } //echo "<b>{$field->field_type}</b>: <br/> <pre>".print_r($postdata[$field->name], true)."</pre>\n"; foreach ($postdata[$field->name] as $i => $postdata_val) { if (@unserialize($postdata_val) !== false || $postdata_val === 'b:0;') { $postdata[$field->name][$i] = unserialize($postdata_val); } } // Trigger plugin Event 'onBeforeSaveField' $fieldname = $field->iscore ? 'core' : $field->field_type; $result = FLEXIUtilities::call_FC_Field_Func($fieldname, 'onBeforeSaveField', array(&$field, &$postdata[$field->name], &$files[$field->name], &$item)); //$qindex[$field->name] = NULL; //$result = FLEXIUtilities::call_FC_Field_Func($fieldname, 'onBeforeSaveField', array( &$field, &$postdata[$field->name], &$files[$field->name], &$item, &$qindex[$field->name] )); if ($result === false) { // Field requested to abort item saving $this->setError(JText::sprintf('FLEXI_FIELD_VALUE_IS_INVALID', $field->label)); return 'abort'; } // Get vstate property from the field object back to the data array $data['vstate'] = $field->item_vstate; } //echo "<pre>"; print_r($postdata); echo "</pre>"; exit; } if ($print_logging_info) { @($fc_run_times['fields_value_preparation'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } // **************************************************************************************************************************** // Loop through Fields triggering onIndexAdvSearch, onIndexSearch Event handlers, this was seperated from the before save field // event, so that we will update search indexes only if the above has not canceled saving OR has not canceled version approval // **************************************************************************************************************************** if ($print_logging_info) { $start_microtime = microtime(true); } if ($fields) { $ai_query_vals = array(); foreach ($fields as $field) { $fieldname = $field->iscore ? 'core' : $field->field_type; if ($data['vstate'] == 2 || $isnew) { // Trigger plugin Event 'onIndexAdvSearch' to update field-item pair records in advanced search index FLEXIUtilities::call_FC_Field_Func($fieldname, 'onIndexAdvSearch', array(&$field, &$postdata[$field->name], &$item)); if (isset($field->ai_query_vals)) { foreach ($field->ai_query_vals as $query_val) { $ai_query_vals[] = $query_val; } } //echo $field->name .":".implode(",", @$field->ai_query_vals ? $field->ai_query_vals : array() )."<br/>"; // Trigger plugin Event 'onIndexSearch' to update item 's (basic) search index record FLEXIUtilities::call_FC_Field_Func($fieldname, 'onIndexSearch', array(&$field, &$postdata[$field->name], &$item)); if (strlen(@$field->search[$item->id])) { $searchindex[] = $field->search[$item->id]; } //echo $field->name .":".@$field->search[$item->id]."<br/>"; } } } // Remove item's old advanced search index entries $query = "DELETE FROM #__flexicontent_advsearch_index WHERE item_id=" . $item->id; $this->_db->setQuery($query); $this->_db->query(); // Store item's advanced search index entries if (!empty($ai_query_vals)) { $query = "INSERT INTO #__flexicontent_advsearch_index " . " (field_id,item_id,extraid,search_index,value_id) VALUES " . implode(",", $ai_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } // Assigned created basic search index into item object $item->search_index = implode(' | ', $searchindex); // Check if vstate was set to 1 (no approve new version) while versioning is disabled if (!$use_versioning && $data['vstate'] != 2) { $data['vstate'] = 2; $app->enqueueMessage('vstate cannot be set to 1 (=no approve new version) when versioning is disabled', 'notice'); } if ($print_logging_info) { @($fc_run_times['fields_value_indexing'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } if ($print_logging_info) { $start_microtime = microtime(true); } // ************************************************************************** // IF new version is approved, remove old version values from the field table // ************************************************************************** if ($data['vstate'] == 2) { //echo "delete __flexicontent_fields_item_relations, item_id: " .$item->id; $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id = ' . $item->id; $this->_db->setQuery($query); $this->_db->query(); $query = 'DELETE FROM #__flexicontent_items_versions WHERE item_id=' . $item->id . ' AND version=' . ((int) $last_version + 1); $this->_db->setQuery($query); $this->_db->query(); $untranslatable_fields = array(); if ($fields) { foreach ($fields as $field) { if ($field->iscore) { continue; } if (count($assoc_item_ids) && $field->untranslatable) { // Delete field values in all translating items, if current field is untranslatable and current item version is approved // NOTE: item itself is not include in associated translations, no need to check for it and skip itit if (!$mval_query) { $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id IN (' . implode(',', $assoc_item_ids) . ') AND field_id=' . $field->id; $this->_db->setQuery($query); $this->_db->query(); } else { $untranslatable_fields[] = $field->id; } } } } if (count($untranslatable_fields)) { $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id IN (' . implode(',', $assoc_item_ids) . ') AND field_id IN (' . implode(',', $untranslatable_fields) . ')'; $this->_db->setQuery($query); $this->_db->query(); } } // ******************************************* // Loop through Fields saving the field values // ******************************************* if ($fields) { // Do not save if versioning disabled or item has no type (version 0) $record_versioned_data = $use_versioning && $item->version; $ver_query_vals = array(); $rel_query_vals = array(); foreach ($fields as $field) { // -- Add the new values to the database $postvalues = $this->formatToArray($postdata[$field->name]); //$qindex_values = $qindex[$field->name]; $i = 1; foreach ($postvalues as $postvalue) { // Create field obj for DB insertion $obj = new stdClass(); $obj->field_id = $field->id; $obj->item_id = $item->id; $obj->valueorder = $i; $obj->version = (int) $last_version + 1; // Serialize the properties of the value, normally this is redudant, since the field must have had serialized the parameters of each value already $obj->value = is_array($postvalue) ? serialize($postvalue) : $postvalue; //$obj->qindex01 = isset($qindex_values['qindex01']) ? $qindex_values['qindex01'] : NULL; //$obj->qindex02 = isset($qindex_values['qindex02']) ? $qindex_values['qindex02'] : NULL; //$obj->qindex03 = isset($qindex_values['qindex03']) ? $qindex_values['qindex03'] : NULL; // -- a. Add versioning values, but do not version the 'hits' or 'state' or 'voting' fields if ($record_versioned_data && $field->field_type != 'hits' && $field->field_type != 'state' && $field->field_type != 'voting') { // Insert only if value non-empty if (isset($obj->value) && JString::strlen(trim($obj->value))) { if (!$mval_query) { $this->_db->insertObject('#__flexicontent_items_versions', $obj); } else { $ver_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->version . "," . $this->_db->Quote($obj->value) . ")"; } } } //echo $field->field_type." - ".$field->name." - ".JString::strlen(trim($obj->value))." ".$field->iscore."<br/>"; // -- b. If item is new OR version is approved, AND field is not core (aka stored in the content table or in special table), then add field value to field values table if (($isnew || $data['vstate'] == 2) && !$field->iscore) { // UNSET version it it used only verion data table, and insert only if value non-empty unset($obj->version); if (isset($obj->value) && JString::strlen(trim($obj->value))) { if (!$mval_query) { $this->_db->insertObject('#__flexicontent_fields_item_relations', $obj); } else { $rel_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $this->_db->Quote($obj->value) . ")"; } // Save field value in all translating items, if current field is untranslatable // NOTE: item itself is not include in associated translations, no need to check for it and skip it if (count($assoc_item_ids) && $field->untranslatable) { foreach ($assoc_item_ids as $t_item_id) { $obj->item_id = $t_item_id; if (!$mval_query) { $this->_db->insertObject('#__flexicontent_fields_item_relations', $obj); } else { $rel_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $this->_db->Quote($obj->value) . ")"; } } } } } $i++; } } // ********************************************* // Insert values in item fields versioning table // ********************************************* if (count($ver_query_vals)) { $query = "INSERT INTO #__flexicontent_items_versions " . " (field_id,item_id,valueorder,version,value" . ") VALUES " . "\n" . implode(",\n", $ver_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } // ******************************************* // Insert values in item fields relation table // ******************************************* if (count($rel_query_vals)) { $query = "INSERT INTO #__flexicontent_fields_item_relations " . " (field_id,item_id,valueorder,value" . ") VALUES " . "\n" . implode(",\n", $rel_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } // ************************************************************** // Save other versioned item data into the field versioning table // ************************************************************** // a. Save a version of item properties that do not have a corresponding CORE Field if ($record_versioned_data) { $obj = new stdClass(); $obj->field_id = -2; // ID of Fake Field used to contain item properties not having a corresponding CORE field $obj->item_id = $item->id; $obj->valueorder = 1; $obj->version = (int) $last_version + 1; $item_data = array(); $iproperties = array('alias', 'catid', 'metadesc', 'metakey', 'metadata', 'attribs'); if (FLEXI_J16GE) { $j16ge_iproperties = array('urls', 'images'); $iproperties = array_merge($iproperties, $j16ge_iproperties); } foreach ($iproperties as $iproperty) { $item_data[$iproperty] = $item->{$iproperty}; } $obj->value = serialize($item_data); $this->_db->insertObject('#__flexicontent_items_versions', $obj); } // b. Finally save a version of the posted JoomFish translated data for J1.5, if such data are editted inside the item edit form if (FLEXI_FISH && !empty($data['jfdata']) && $record_versioned_data) { $obj = new stdClass(); $obj->field_id = -1; // ID of Fake Field used to contain the Joomfish translated item data $obj->item_id = $item->id; $obj->valueorder = 1; $obj->version = (int) $last_version + 1; $item_lang = substr($item->language, 0, 2); $data['jfdata'][$item_lang]['alias'] = $item->alias; $data['jfdata'][$item_lang]['metadesc'] = $item->metadesc; $data['jfdata'][$item_lang]['metakey'] = $item->metakey; $obj->value = serialize($data['jfdata']); $this->_db->insertObject('#__flexicontent_items_versions', $obj); } } if ($print_logging_info) { @($fc_run_times['fields_value_saving'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } // ****************************** // Trigger onAfterSaveField Event // ****************************** if ($fields) { if ($print_logging_info) { $start_microtime = microtime(true); } foreach ($fields as $field) { $fieldname = $field->iscore ? 'core' : $field->field_type; $result = FLEXIUtilities::call_FC_Field_Func($fieldname, 'onAfterSaveField', array(&$field, &$postdata[$field->name], &$files[$field->name], &$item)); // *** $result is ignored } if ($print_logging_info) { @($fc_run_times['onAfterSaveField_event'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } } return true; }
/** * Method to import Joomla! com_content datas and structure * this is UNUSED in J2.5+, it may be used in the future * * @return boolean true on success * @since 1.5 */ function import() { jimport('joomla.utilities.simplexml'); // Deprecated J2.5, removed J3.x // Get the site default language $lang = flexicontent_html::getSiteDefaultLang(); if (!FLEXI_J16GE) { // Get all Joomla sections $query = 'SELECT * FROM #__sections'; $this->_db->setQuery($query); $sections = $this->_db->loadObjectList(); } $logs = new stdClass(); if (!FLEXI_J16GE) { $logs->sec = 0; } $logs->cat = 0; $logs->art = 0; //$logs->err = new stdClass(); // Create the new category for the flexicontent items $topcat = JTable::getInstance('flexicontent_categories', ''); $topcat->parent_id = 1; $topcat->level = 0; $topcat->extension = "com_content"; $topcat->title = 'FLEXIcontent'; $topcat->alias = 'flexicontent'; $topcat->lft = null; $topcat->rgt = null; $topcat->level = 0; $topcat->published = 1; $topcat->access = 1; $topcat->language = "*"; $topcat->setLocation(0, 'last-child'); $topcat->check(); $topcat->store(); $topcat->rebuildPath($topcat->id); // Get the category default parameters in a string $xml = new JSimpleXML(); $xml->loadFile(JPATH_COMPONENT . DS . 'models' . DS . 'category.xml'); $catparams = new JRegistry(); foreach ($xml->document->params as $paramGroup) { foreach ($paramGroup->param as $param) { if (!$param->attributes('name')) { continue; } // FIX for empty name e.g. seperator fields $catparams->set($param->attributes('name'), $param->attributes('default')); } } $catparams_str = $catparams->toString(); // Loop through the top category object and create cat -> subcat -> items -> fields $k = 0; if ($topcat->id) { // Get the sub-categories of the root category that belong to com_content $query = "SELECT * FROM #__categories as c WHERE c.extension='com_content' "; $this->_db->setQuery($query); $categories = $this->_db->loadObjectList(); /*//get children $children = array(); foreach ($categories as $child) { $parent = $child->parent_id; $list = @$children[$parent] ? $children[$parent] : array(); array_push($list, $child); $children[$parent] = $list; } $categories = $children; //unset($children); */ $map_old_new = array(); $map_old_new[1] = $topcat->id; // Loop throught the categories of the created section foreach ($categories as $category) { $subcat = JTable::getInstance('flexicontent_categories', ''); $subcat->load($category->id); $subcat->id = 0; $subcat->lft = null; $subcat->rgt = null; $subcat->level = null; $subcat->parent_id = isset($map_old_new[$category->parent_id]) ? $map_old_new[$category->parent_id] : $topcat->id; $subcat->setLocation($subcat->parent_id, 'last-child'); $subcat->params = $category->params; $k++; $subcat->check(); if ($subcat->store()) { $logs->cat++; } else { $logs->err->{$k}->type = JText::_('FLEXI_IMPORT_CATEGORY') . ' id'; $logs->err->{$k}->id = $category->id; $logs->err->{$k}->title = $category->title; } $subcat->rebuildPath($subcat->id); $map_old_new[$category->id] = $subcat->id; // Get the articles of the created category $query = 'SELECT * FROM #__content WHERE catid = ' . $category->id; $this->_db->setQuery($query); $articles = $this->_db->loadObjectList(); // Loop throught the articles of the created category foreach ($articles as $article) { $item = JTable::getInstance('content'); $item->load($article->id); $item->id = 0; $item->catid = $subcat->id; $k++; $item->check(); if ($item->store()) { $logs->art++; } else { $logs->err->{$k}->type = JText::_('FLEXI_IMPORT_ARTICLE') . ' id'; $logs->err->{$k}->id = $article->id; $logs->err->{$k}->title = $article->title; } } // end articles loop } // end categories loop } // end if foreach ($categories as $category) { $subcat = JTable::getInstance('flexicontent_categories', ''); $subcat->load($map_old_new[$category->id]); $subcat->lft = null; $subcat->rgt = null; $subcat->level = null; $subcat->parent_id = isset($map_old_new[$category->parent_id]) ? $map_old_new[$category->parent_id] : $topcat->id; $subcat->setLocation($subcat->parent_id, 'last-child'); $subcat->check(); $subcat->store(); } unset($map_old_new); // Save the created top category as the flexi_top_category for the component $this->cparams->set('flexi_top_category', $topcat->id); $cparams_str = $this->cparams->toString(); $flexi = JComponentHelper::getComponent('com_flexicontent'); $query = 'UPDATE ' . (FLEXI_J16GE ? '#__extensions' : '#__components') . ' SET params = ' . $this->_db->Quote($cparams_str) . ' WHERE ' . (FLEXI_J16GE ? 'extension_id' : 'id') . '=' . $flexi->id; $this->_db->setQuery($query); $this->_db->execute(); return $logs; }
/** * Method to import Joomla! com_content datas and structure * this is UNUSED in J2.5+, it may be used in the future * * @return boolean true on success * @since 1.5 */ function import() { jimport('joomla.utilities.simplexml'); // Deprecated J2.5, removed J3.x // Get the site default language $lang = flexicontent_html::getSiteDefaultLang(); if (!FLEXI_J16GE) { // Get all Joomla sections $query = 'SELECT * FROM #__sections'; $this->_db->setQuery($query); $sections = $this->_db->loadObjectList(); } $logs = new stdClass(); if (!FLEXI_J16GE) { $logs->sec = 0; } $logs->cat = 0; $logs->art = 0; //$logs->err = new stdClass(); // Create the new section for flexicontent items $flexisection = JTable::getInstance('section'); $flexisection->title = 'FLEXIcontent'; $flexisection->alias = 'flexicontent'; $flexisection->published = 1; $flexisection->ordering = $flexisection->getNextOrder(); $flexisection->access = 0; $flexisection->scope = 'content'; $flexisection->check(); $flexisection->store(); // Get the category default parameters in a string $xml = new JSimpleXML(); $xml->loadFile(JPATH_COMPONENT . DS . 'models' . DS . 'category.xml'); $catparams = FLEXI_J16GE ? new JRegistry() : new JParameter(""); foreach ($xml->document->params as $paramGroup) { foreach ($paramGroup->param as $param) { if (!$param->attributes('name')) { continue; } // FIX for empty name e.g. seperator fields $catparams->set($param->attributes('name'), $param->attributes('default')); } } $catparams_str = $catparams->toString(); // Loop through the section object and create cat -> subcat -> items -> fields $k = 0; foreach ($sections as $section) { // Create a category for every imported section, to contain all categories of the section $cat = JTable::getInstance('flexicontent_categories', ''); $cat->parent_id = 0; $cat->title = $section->title; $cat->name = $section->name; $cat->alias = $section->alias; $cat->image = $section->image; $cat->section = $flexisection->id; $cat->image_position = $section->image_position; $cat->description = $section->description; $cat->published = $section->published; $cat->ordering = $section->ordering; $cat->access = $section->access; $cat->params = $catparams_str; $k++; $cat->check(); if ($cat->store()) { $logs->sec++; } else { $logs->err->{$k}->type = JText::_('FLEXI_IMPORT_SECTION') . ' id'; $logs->err->{$k}->id = $section->id; $logs->err->{$k}->title = $section->title; } // Get the categories of each imported section $query = "SELECT * FROM #__categories WHERE section = " . $section->id; $this->_db->setQuery($query); $categories = $this->_db->loadObjectList(); // Loop throught the categories of the created section foreach ($categories as $category) { $subcat = JTable::getInstance('flexicontent_categories', ''); $subcat->load($category->id); $subcat->id = 0; $subcat->parent_id = $cat->id; $subcat->section = $flexisection->id; $subcat->params = $catparams_str; $k++; $subcat->check(); if ($subcat->store()) { $logs->cat++; } else { $logs->err->{$k}->type = JText::_('FLEXI_IMPORT_CATEGORY') . ' id'; $logs->err->{$k}->id = $category->id; $logs->err->{$k}->title = $category->title; } // Get the articles of the created category $query = 'SELECT * FROM #__content WHERE catid = ' . $category->id; $this->_db->setQuery($query); $articles = $this->_db->loadObjectList(); // Loop throught the articles of the created category foreach ($articles as $article) { $item = JTable::getInstance('content'); $item->load($article->id); $item->id = 0; $item->sectionid = $flexisection->id; $item->catid = $subcat->id; $k++; $item->check(); if ($item->store()) { $logs->art++; } else { $logs->err->{$k}->type = JText::_('FLEXI_IMPORT_ARTICLE') . ' id'; $logs->err->{$k}->id = $article->id; $logs->err->{$k}->title = $article->title; } } // end articles loop } // end categories loop } // end sections loop // Save the created section as flexi_section for the component $fparams = JComponentHelper::getParams('com_flexicontent'); $fparams->set('flexi_section', $flexisection->id); $fparams_str = $fparams->toString(); $flexi = JComponentHelper::getComponent('com_flexicontent'); $query = 'UPDATE ' . (FLEXI_J16GE ? '#__extensions' : '#__components') . ' SET params = ' . $this->_db->Quote($fparams_str) . ' WHERE ' . (FLEXI_J16GE ? 'extension_id' : 'id') . '=' . $flexi->id; $this->_db->setQuery($query); $this->_db->query(); return $logs; }
/** * Build the where clause * * @access private * @return string */ function _buildContentWhere() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $option = JRequest::getVar('option'); $langparent_item = $app->getUserStateFromRequest($option . '.itemelement.langparent_item', 'langparent_item', 0, 'int'); $type_id = $app->getUserStateFromRequest($option . '.itemelement.type_id', 'type_id', 0, 'int'); $created_by = $app->getUserStateFromRequest($option . '.itemelement.created_by', 'created_by', 0, 'int'); if ($langparent_item) { $user_fullname = JFactory::getUser($created_by)->name; $this->_db->setQuery('SELECT name FROM #__flexicontent_types WHERE id = ' . $type_id); $type_name = $this->_db->loadResult(); $msg = sprintf("Selecting ORIGINAL Content item for a translating item of Content Type: \"%s\" and User: \"%s\"", $type_name, $user_fullname); $jAp = JFactory::getApplication(); $jAp->enqueueMessage($msg, 'message'); } $filter_state = $app->getUserStateFromRequest($option . '.itemelement.filter_state', 'filter_state', '', 'word'); $filter_cats = $app->getUserStateFromRequest($option . '.itemelement.filter_cats', 'filter_cats', '', 'int'); $filter_type = $app->getUserStateFromRequest($option . '.itemelement.filter_type', 'filter_type', '', 'int'); if (FLEXI_FISH || FLEXI_J16GE) { if ($langparent_item) { $filter_lang = flexicontent_html::getSiteDefaultLang(); } else { $filter_lang = $app->getUserStateFromRequest($option . '.itemelement.filter_lang', 'filter_lang', '', 'cmd'); } } $search = $app->getUserStateFromRequest($option . '.itemelement.search', 'search', '', 'string'); $search = trim(JString::strtolower($search)); $where = array(); $where[] = ' i.state != -2'; // Exclude trashed if (!FLEXI_J16GE) { $where[] = ' sectionid = ' . FLEXI_SECTION; } if ($filter_state) { if ($filter_state == 'P') { $where[] = 'i.state = 1'; } else { if ($filter_state == 'U') { $where[] = 'i.state = 0'; } else { if ($filter_state == 'PE') { $where[] = 'i.state = -3'; } else { if ($filter_state == 'OQ') { $where[] = 'i.state = -4'; } else { if ($filter_state == 'IP') { $where[] = 'i.state = -5'; } else { if ($filter_state == 'A') { $where[] = 'i.state = ' . (FLEXI_J16GE ? 2 : -1); } } } } } } } if ($filter_cats) { $where[] = 'rel.catid = ' . $filter_cats; } if ($langparent_item && $type_id) { $where[] = 'ie.type_id = ' . $type_id; } else { if ($filter_type) { $where[] = 'ie.type_id = ' . $filter_type; } } if (FLEXI_FISH || FLEXI_J16GE) { if ($filter_lang) { $where[] = 'ie.language = ' . $this->_db->Quote($filter_lang); } } if ($search) { $search_escaped = FLEXI_J16GE ? $this->_db->escape($search, true) : $this->_db->getEscaped($search, true); $where[] = ' LOWER(i.title) LIKE ' . $this->_db->Quote('%' . $search_escaped . '%', false); } /*if (FLEXI_J16GE) { $isAdmin = JAccess::check($user->id, 'core.admin', 'root.1'); } else { $isAdmin = $user->gid >= 24; }*/ if (FLEXI_J16GE) { $assocanytrans = $user->authorise('flexicontent.assocanytrans', 'com_flexicontent'); } else { if (FLEXI_ACCESS) { $assocanytrans = $user->gid < 25 ? FAccess::checkComponentAccess('com_flexicontent', 'assocanytrans', 'users', $user->gmid) : 1; } else { $assocanytrans = $user->gid >= 24; } } // is at least admin if (!$assocanytrans) { if ($langparent_item && $created_by) { $where[] = ' i.created_by=' . $created_by; } } $where = count($where) ? ' WHERE ' . implode(' AND ', $where) : ''; return $where; }
/** * Method to get information of site languages * * @return object * @since 1.5 */ static function getlanguageslist($published_only=false, $add_all = true) { $app = JFactory::getApplication(); $db = JFactory::getDBO(); static $pub_languages = null; static $all_languages = null; if ( $published_only ) { if ($pub_languages) return $pub_languages; else $pub_languages = false; } if ( !$published_only ) { if ($all_languages) return $all_languages; else $all_languages = false; } // ****************** // Retrieve languages // ****************** if (FLEXI_J16GE) { // Use J1.6+ language info $query = 'SELECT DISTINCT lc.lang_id as id, lc.image as image_prefix, lc.lang_code as code, lc.title_native, ' . ' CASE WHEN CHAR_LENGTH(lc.title_native) THEN CONCAT(lc.title, " (", lc.title_native, ")") ELSE lc.title END as name ' .' FROM #__languages as lc ' .' WHERE 1 '.($published_only ? ' AND lc.published=1' : '') . ' ORDER BY lc.ordering ASC ' ; } else if (FLEXI_FISH) { // Use joomfish languages table $query = 'SELECT l.* ' . ( FLEXI_FISH_22GE ? ', lext.* ' : '' ) . ( FLEXI_FISH_22GE ? ', l.lang_id as id ' : ', l.id ' ) . ( FLEXI_FISH_22GE ? ', l.lang_code as code, l.sef as shortcode' : ', l.code, l.shortcode' ) . ( FLEXI_FISH_22GE ? ', CASE WHEN CHAR_LENGTH(l.title_native) THEN CONCAT(l.title, " (", l.title_native, ")") ELSE l.title END as name ' : ', l.name ' ) . ' FROM #__languages as l' . ( FLEXI_FISH_22GE ? ' LEFT JOIN #__jf_languages_ext as lext ON l.lang_id=lext.lang_id ' : '') . ' WHERE '. (FLEXI_FISH_22GE ? ' l.published=1 ' : ' l.active=1 ') . ' ORDER BY '. (FLEXI_FISH_22GE ? ' lext.ordering ASC ' : ' l.ordering ASC ') ; } else { //echo "<pre>"; debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); echo "</pre>"; //JError::raiseNotice(500, 'getlanguageslist(): Notice no joomfish installed'); //return array(); } if ( !empty($query) ) { $db->setQuery($query); $languages = $db->loadObjectList('id'); //echo "<pre>"; print_r($languages); echo "</pre>"; exit; if ($db->getErrorNum()) JFactory::getApplication()->enqueueMessage(__FUNCTION__.'(): SQL QUERY ERROR:<br/>'.nl2br($db->getErrorMsg()),'error'); } // ********************* // Calculate image paths // ********************* if (FLEXI_J16GE) { // FLEXI_J16GE, use J1.6+ images $imgpath = $app->isAdmin() ? '../images/':'images/'; $mediapath = $app->isAdmin() ? '../media/mod_languages/images/' : 'media/mod_languages/images/'; } else { // Use joomfish images $imgpath = $app->isAdmin() ? '../images/':'images/'; $mediapath = $app->isAdmin() ? '../components/com_joomfish/images/flags/' : 'components/com_joomfish/images/flags/'; } // ************************ // Prepare language objects // ************************ $_languages = array(); // J1.6+ add 'ALL' also add 'ALL' if no languages found, since this is default for J1.6+ if (FLEXI_J16GE && $add_all) { $lang_all = new stdClass(); $lang_all->code = '*'; $lang_all->name = JText::_('FLEXI_ALL'); $lang_all->shortcode = '*'; $lang_all->id = 0; $_languages = array( 0 => $lang_all); } // J1.5 add default site language if no languages found, e.g. no Joom!Fish installed if (!FLEXI_J16GE && empty($languages)) { $lang_default = new stdClass(); $lang_default->code = flexicontent_html::getSiteDefaultLang(); $lang_default->name = $lang_default->code; $lang_default->shortcode = strpos($lang_default->code,'-') ? substr($lang_default->code, 0, strpos($lang_default->code,'-')) : $lang_default->code; $lang_default->id = 0; $_languages = array( 0 => $lang_default); } // Check if no languages found and return if ( empty($languages) ) return $_languages; if (FLEXI_J16GE) // FLEXI_J16GE, based on J1.6+ language data and images { foreach ($languages as $lang) { // Calculate/Fix languages data $lang->shortcode = strpos($lang->code,'-') ? substr($lang->code, 0, strpos($lang->code,'-')) : $lang->code; //$lang->id = $lang->extension_id; $image_prefix = $lang->image_prefix ? $lang->image_prefix : $lang->shortcode; // $lang->image, holds a custom image path $lang->imgsrc = @$lang->image ? $imgpath . $lang->image : $mediapath . $image_prefix . '.gif'; $_languages[$lang->id] = $lang; } // Also prepend '*' (ALL) language to language array //echo "<pre>"; print_r($languages); echo "</pre>"; exit; // Select language -ALL- if none selected //$selected = $selected ? $selected : '*'; // WRONG behavior commented out } else if (FLEXI_FISH_22GE) // JoomFish v2.2+ { require_once(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_joomfish'.DS.'helpers'.DS.'extensionHelper.php' ); foreach ($languages as $lang) { // Get image path via helper function $_imgsrc = JoomfishExtensionHelper::getLanguageImageSource($lang); $lang->imgsrc = JURI::root(true).($_imgsrc[0]!='/' ? '/' : '').$_imgsrc; $_languages[$lang->id] = $lang; } } else // JoomFish until v2.1 { foreach ($languages as $lang) { // $lang->image, holds a custom image path $lang->imgsrc = @$lang->image ? $imgpath . $lang->image : $mediapath . $lang->shortcode . '.gif'; $_languages[$lang->id] = $lang; } } $languages = $_languages; if ( $published_only ) { $pub_languages = $_languages; } else { $all_languages = $_languages; } return $_languages; }
/** * Creates the Filemanagerview * * @since 1.0 */ function display($tpl = null) { // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); flexicontent_html::loadJQuery(); flexicontent_html::loadFramework('select2'); JHTML::_('behavior.tooltip'); // Load the form validation behavior JHTML::_('behavior.formvalidation'); //initialise variables $app = JFactory::getApplication(); $option = JRequest::getVar('option'); $document = JFactory::getDocument(); $db = JFactory::getDBO(); $user = JFactory::getUser(); $params = JComponentHelper::getParams('com_flexicontent'); //$authorparams = flexicontent_db::getUserConfig($user->id); $langs = FLEXIUtilities::getLanguages('code'); $fieldid = JRequest::getVar('field', null, 'request', 'int'); $client = $app->isAdmin() ? '../' : ''; //get vars $filter_order = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_order', 'filter_order', 'f.filename', 'cmd'); $filter_order_Dir = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_order_Dir', 'filter_order_Dir', '', 'word'); $filter = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter', 'filter', 1, 'int'); $filter_lang = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_lang', 'filter_lang', '', 'string'); $filter_uploader = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_uploader', 'filter_uploader', 0, 'int'); $filter_url = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_url', 'filter_url', '', 'word'); $filter_secure = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_secure', 'filter_secure', '', 'word'); $filter_ext = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.filter_ext', 'filter_ext', '', 'alnum'); $search = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.search', 'search', '', 'string'); $filter_item = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.item_id', 'item_id', '', 'int'); $u_item_id = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.u_item_id', 'u_item_id', 0, 'string'); $autoselect = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.autoselect', 'autoselect', 0, 'int'); $autoassign = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.autoassign', 'autoassign', 0, 'int'); $folder_mode = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.folder_mode', 'folder_mode', 0, 'int'); $folder_param = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.folder_param', 'folder_param', 'dir', 'string'); $append_item = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.append_item', 'append_item', 1, 'int'); $append_field = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.append_field', 'append_field', 1, 'int'); $targetid = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.targetid', 'targetid', '', 'string'); $thumb_w = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.thumb_w', 'thumb_w', 120, 'int'); $thumb_h = $app->getUserStateFromRequest($option . '.fileselement' . $fieldid . '.thumb_h', 'thumb_h', 90, 'int'); $search = FLEXI_J16GE ? $db->escape(trim(JString::strtolower($search))) : $db->getEscaped(trim(JString::strtolower($search))); $newfileid = JRequest::getInt('newfileid'); $newfilename = base64_decode(JRequest::getVar('newfilename', '')); $delfilename = base64_decode(JRequest::getVar('delfilename', '')); //add css and submenu to document if ($app->isSite()) { $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexicontent.css'); $document->addStyleSheet(JURI::base() . 'components/com_flexicontent/assets/css/flexi_shared.css'); // NOTE: this is imported by main Frontend CSS file } else { $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'); } } $document->addStyleSheet(JURI::root() . 'administrator/templates/system/css/system.css'); // include backend CSS template CSS file , access to backend folder may not be allowed but ... if ($app->isSite()) { $template = !FLEXI_J16GE ? 'khepri' : (FLEXI_J30GE ? 'hathor' : 'bluestork'); $document->addStyleSheet(JURI::root() . 'administrator/templates/' . $template . (FLEXI_J16GE ? '/css/template.css' : '/css/general.css')); } //a trick to avoid loosing general style in modal window $css = 'body, td, th { font-size: 11px; } a.striketext { text-decoration: line-through; color:red; font-style:italic; } '; $document->addStyleDeclaration($css); // Get User's Global Permissions $perms = FlexicontentHelperPerm::getPerm(); // *********************** // Get data from the model // *********************** $model = $this->getModel(); if (!$folder_mode) { $rows = $this->get('Data'); $img_folder = ''; } else { $rows = $model->getFilesFromPath($u_item_id, $fieldid, $append_item, $append_field, $folder_param); $img_folder = $model->getFieldFolderPath($u_item_id, $fieldid, $append_item, $append_field, $folder_param); $img_path = str_replace('\\', '/', $img_folder . DS . $newfilename); $thumb = JURI::root() . 'components/com_flexicontent/librairies/phpthumb/phpThumb.php?src=' . $img_path . '&w=' . $thumb_w . '&h=' . $thumb_h; } $upload_path_var = 'fc_upload_path_' . $fieldid . '_' . $u_item_id; $app->setUserState($upload_path_var, $img_folder); //echo $upload_path_var . "<br>"; //echo $app->getUserState( $upload_path_var, 'noset' ); $pagination = $this->get('Pagination'); //$users = $this->get('Users'); // Get item using at least one file (-of- the currently listed files) /*$items_single = $model->getItemsSingleprop( array('file','minigallery') ); $items_multi = $model->getItemsMultiprop ( $field_props=array('image'=>'originalname'), $value_props=array('image'=>'filename') ); $items = array(); foreach ($items_single as $item_id => $_item) $items[$item_id] = $_item; foreach ($items_multi as $item_id => $_item) $items[$item_id] = $_item; ksort($items);*/ $fname = $model->getFieldName($fieldid); $files_selected = $model->getItemFiles($u_item_id); $formfieldname = FLEXI_J16GE ? 'custom[' . $fname . '][]' : $fname . '[]'; //add js to document if ($folder_mode) { $js = "\n\t\t\t\n\t\t\twindow.addEvent('domready', function() {\n\n\t\t function closest (obj, el) {\n\t\t var find = obj.getElement(el);\n\t\t var self = obj;\n\t\t \n\t\t while (self && !find) {\n\t\t self = self.getParent();\n\t\t find = self ? self.getElement(el) : null;\n\t\t }\n\t\t return find;\n\t\t }\n\n\t\t\t\tvar delfilename = '" . $delfilename . "';\n\t\t\t\tvar remove_existing_files_from_list = 0;\n\t\t\t\tvar remove_new_files_from_list = 0;\n\t\t\t\toriginal_objs = \$(window.parent.document.body).getElement('#container_fcfield_" . $fieldid . "').getElements('.originalname');\n\t\t\t\texisting_objs = \$(window.parent.document.body).getElement('#container_fcfield_" . $fieldid . "').getElements('.existingname');\n\t\t\t\t\n\t\t\t\tvar imgobjs = Array();\n\t\t\t\tfor(i=0,n=original_objs.length; i<n; i++) {\n\t\t\t\t\tif (original_objs[i].value) imgobjs.push(original_objs[i].value);\n\t\t\t\t\tif ( delfilename!='' && original_objs[i].value == delfilename)\n\t\t\t\t\t{\n\t\t\t\t\t\twindow.parent.deleteField" . $fieldid . "( original_objs[i].getParent() );\n\t\t\t\t\t\tremove_existing_files_from_list = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tfor(i=0,n=existing_objs.length; i<n; i++) {\n\t\t\t\t\tif ( existing_objs[i].value) imgobjs.push(existing_objs[i].value);\n\t\t\t\t\tif ( delfilename!='' && existing_objs[i].value == delfilename)\n\t\t\t\t\t{\n\t\t\t\t\t\twindow.parent.deleteField" . $fieldid . "(\n\t\t\t\t\t\t\t(MooTools.version>='1.2.4') ? existing_objs[i].getParent('.img_value_props') : closest (existing_objs[i] , '.img_value_props')\n\t\t\t\t\t\t);\n\t\t\t\t\t\tremove_new_files_from_list = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif ( remove_existing_files_from_list || remove_new_files_from_list ) {\n\t\t\t\t\tmssg = '" . JText::_('FLEXI_DELETE_FILE_IN_LIST_WINDOW_MUST_CLOSE') . "';\n\t\t\t\t\tmssg = mssg + '\\n' + (remove_existing_files_from_list ? '" . JText::_('FLEXI_EXISTING_FILE_REMOVED_SAVE_RECOMMENEDED', true) . "' : '');\n\t\t\t\t\talert( mssg );\n\t\t\t\t\t(MooTools.version>='1.2.4') ? window.parent.SqueezeBox.close() : window.parent.document.getElementById('sbox-window').close();\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tfor(i=0,n=imgobjs.length; i<n; i++) {\n\t\t\t\t\tvar rows = \$(document.body).getElements('a[rel='+ imgobjs[i] +']');\n\t\t\t\t\trows.addClass('striketext');\n\t\t\t\t\t\n\t\t\t\t\t//if( (typeof rows) != 'undefined' && rows != null) {\n\t\t\t\t\t\t//alert(rows[0]);\n\t\t\t\t\t\t//row.className = 'striketext';\n\t\t\t\t\t//}\n\t\t\t\t}\n\t\t\t\t" . ($autoassign && $newfilename ? "window.parent.qmAssignFile" . $fieldid . "('" . $targetid . "', '" . $newfilename . "', '" . $thumb . "');" : "") . "\n\t\t\t});\n\t\t\t"; } else { $js = "\n\t\t\tfunction qffileselementadd(obj, id, file) {\n\t\t\t\tvar result = window.parent.qfSelectFile" . $fieldid . "(id, file);\n\t\t\t\tif ((typeof result) != 'undefined' && result == 'cancel') return;\n\t\t\t\tobj.className = 'striketext';\n\t\t\t\tdocument.adminForm.file.value=id;\n\t\t\t}\n\t\t\twindow.addEvent('domready', function() {\n\t\t\t\tfileobjs = window.parent.document.getElementsByName('{$formfieldname}');\n\t\t\t\tfor(i=0,n=fileobjs.length; i<n; i++) {\n\t\t\t\t\trow = document.getElementById('file'+fileobjs[i].value);\n\t\t\t\t\tif( (typeof row) != 'undefined' && row != null) {\n\t\t\t\t\t\trow.className = 'striketext';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t" . ($autoselect && $newfileid ? "qffileselementadd( document.getElementById('file" . $newfileid . "'), '" . $newfileid . "', '" . $newfilename . "');" : "") . "\n\t\t\t});\n\t\t\t"; } $document->addScriptDeclaration($js); if ($autoselect && $newfileid) { $app->enqueueMessage(JText::_('FLEXI_UPLOADED_FILE_WAS_SELECTED'), 'message'); } /***************** ** BUILD LISTS ** *****************/ $lists = array(); // ** FILE UPLOAD FORM ** // Build languages list //$allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed',null); //$allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs); $display_file_lang_as = $params->get('display_file_lang_as', 3); $allowed_langs = null; if (FLEXI_FISH || FLEXI_J16GE) { $lists['file-lang'] = flexicontent_html::buildlanguageslist('file-lang', '', '*', $display_file_lang_as, $allowed_langs, $published_only = false); } else { $lists['file-lang'] = flexicontent_html::getSiteDefaultLang() . '<input type="hidden" name="file-lang" value="' . flexicontent_html::getSiteDefaultLang() . '" />'; } /************* ** FILTERS ** *************/ // language filter $lists['language'] = flexicontent_html::buildlanguageslist('filter_lang', 'class="use_select2_lib" onchange="submitform();" size="1" ', $filter_lang, 2); // search $lists['search'] = $search; //search filter $filters = array(); $filters[] = JHTML::_('select.option', '1', JText::_('FLEXI_FILENAME')); $filters[] = JHTML::_('select.option', '2', JText::_('FLEXI_FILE_TITLE')); $lists['filter'] = JHTML::_('select.genericlist', $filters, 'filter', 'size="1" class="use_select2_lib"', 'value', 'text', $filter); //build url/file filterlist $url = array(); $url[] = JHTML::_('select.option', '', '- ' . JText::_('FLEXI_ALL_FILES') . ' -'); $url[] = JHTML::_('select.option', 'F', JText::_('FLEXI_FILE')); $url[] = JHTML::_('select.option', 'U', JText::_('FLEXI_URL')); $lists['url'] = JHTML::_('select.genericlist', $url, 'filter_url', 'class="use_select2_lib" size="1" onchange="submitform( );"', 'value', 'text', $filter_url); //item lists /*$items_list = array(); $items_list[] = JHTML::_('select.option', '', '- '. JText::_( 'FLEXI_FILTER_BY_ITEM' ) .' -' ); foreach($items as $item) { $items_list[] = JHTML::_('select.option', $item->id, JText::_( $item->title ) . ' (#' . $item->id . ')' ); } $lists['item_id'] = JHTML::_('select.genericlist', $items_list, 'item_id', 'size="1" class="use_select2_lib" onchange="submitform( );"', 'value', 'text', $filter_item );*/ $lists['item_id'] = '<input type="text" name="item_id" size="1" class="inputbox" onchange="submitform( );" value="' . $filter_item . '" />'; //build secure/media filterlist $secure = array(); $secure[] = JHTML::_('select.option', '', '- ' . JText::_('FLEXI_ALL_DIRECTORIES') . ' -'); $secure[] = JHTML::_('select.option', 'S', JText::_('FLEXI_SECURE_DIR')); $secure[] = JHTML::_('select.option', 'M', JText::_('FLEXI_MEDIA_DIR')); $lists['secure'] = JHTML::_('select.genericlist', $secure, 'filter_secure', 'class="use_select2_lib" size="1" onchange="submitform( );"', 'value', 'text', $filter_secure); //build ext filterlist $lists['ext'] = flexicontent_html::buildfilesextlist('filter_ext', 'class="use_select2_lib" size="1" onchange="submitform( );"', $filter_ext); //build uploader filterlist $lists['uploader'] = flexicontent_html::builduploaderlist('filter_uploader', 'class="use_select2_lib" size="1" onchange="submitform( );"', $filter_uploader); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // removed files $filelist = JRequest::getString('files'); $file = JRequest::getInt('file'); $filelist = explode(',', $filelist); $files = array(); foreach ($filelist as $fileid) { if ($fileid && $fileid != $file) { $files[] = (int) $fileid; } } $files = implode(',', $files); if (strlen($files) > 0) { $files .= ','; } $files .= $file; //assign data to template $this->assignRef('params', $params); $this->assignRef('client', $client); //Load pane behavior if (!FLEXI_J16GE) { jimport('joomla.html.pane'); $pane = JPane::getInstance('Tabs'); $this->assignRef('pane', $pane); } $this->assignRef('lists', $lists); $this->assignRef('rows', $rows); $this->assignRef('folder_mode', $folder_mode); $this->assignRef('img_folder', $img_folder); $this->assignRef('thumb_w', $thumb_w); $this->assignRef('thumb_h', $thumb_h); $this->assignRef('pagination', $pagination); $this->assignRef('files', $files); $this->assignRef('fieldid', $fieldid); $this->assignRef('u_item_id', $u_item_id); $this->assignRef('targetid', $targetid); $this->assignRef('CanFiles', $perms->CanFiles); $this->assignRef('CanUpload', $perms->CanUpload); $this->assignRef('CanViewAllFiles', $perms->CanViewAllFiles); $this->assignRef('files_selected', $files_selected); $this->assignRef('langs', $langs); parent::display($tpl); }
function display($tpl = null) { $mainframe = JFactory::getApplication(); //initialise variables $user = JFactory::getUser(); $db = JFactory::getDBO(); $document = JFactory::getDocument(); $option = JRequest::getCmd('option'); $context = 'com_flexicontent'; $task = JRequest::getVar('task', ''); $cid = JRequest::getVar('cid', array()); $cparams = JComponentHelper::getParams('com_flexicontent'); $this->setLayout('import'); //initialise variables $user = JFactory::getUser(); $document = JFactory::getDocument(); $context = 'com_flexicontent'; $has_zlib = version_compare(PHP_VERSION, '5.4.0', '>='); FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); 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'); } } // Get filter vars $filter_order = $mainframe->getUserStateFromRequest($context . '.import.filter_order', 'filter_order', '', 'cmd'); $filter_order_Dir = $mainframe->getUserStateFromRequest($context . '.import.filter_order_Dir', 'filter_order_Dir', '', 'word'); // Get session information $session = JFactory::getSession(); $conf = $session->get('csvimport_config', "", 'flexicontent'); $conf = unserialize($conf ? $has_zlib ? zlib_decode(base64_decode($conf)) : base64_decode($conf) : ""); $lineno = $session->get('csvimport_lineno', 999999, 'flexicontent'); $session->set('csvimport_parse_log', null, 'flexicontent'); // Get User's Global Permissions $perms = FlexicontentHelperPerm::getPerm(); // Create Submenu (and also check access to current view) FLEXISubmenu('CanImport'); // Create document/toolbar titles $doc_title = JText::_('FLEXI_IMPORT'); $site_title = $document->getTitle(); JToolBarHelper::title($doc_title, 'import'); $document->setTitle($doc_title . ' - ' . $site_title); // Create the toolbar $toolbar = JToolBar::getInstance('toolbar'); if (!empty($conf)) { if ($task != 'processcsv') { $ctrl_task = FLEXI_J16GE ? 'import.processcsv' : 'processcsv'; $import_btn_title = empty($lineno) ? 'FLEXI_IMPORT_START_TASK' : 'FLEXI_IMPORT_CONTINUE_TASK'; JToolBarHelper::custom($ctrl_task, 'save.png', 'save.png', $import_btn_title, $list_check = false); } $ctrl_task = FLEXI_J16GE ? 'import.clearcsv' : 'clearcsv'; JToolBarHelper::custom($ctrl_task, 'cancel.png', 'cancel.png', 'FLEXI_IMPORT_CLEAR_TASK', $list_check = false); } else { $ctrl_task = FLEXI_J16GE ? 'import.initcsv' : 'initcsv'; JToolBarHelper::custom($ctrl_task, 'import.png', 'import.png', 'FLEXI_IMPORT_PREPARE_TASK', $list_check = false); $ctrl_task = FLEXI_J16GE ? 'import.testcsv' : 'testcsv'; JToolBarHelper::custom($ctrl_task, 'test.png', 'test.png', 'FLEXI_IMPORT_TEST_FILE_FORMAT', $list_check = false); } //JToolBarHelper::Back(); if ($perms->CanConfig) { JToolBarHelper::divider(); JToolBarHelper::spacer(); $session = JFactory::getSession(); $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent'); $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940; $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent'); $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550; JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration'); } if (!empty($conf) && $task == 'processcsv') { $this->assignRef('conf', $conf); parent::display('process'); return; } // Get types $query = 'SELECT id, name' . ' FROM #__flexicontent_types' . ' WHERE published = 1' . ' ORDER BY name ASC'; $db->setQuery($query); $types = $db->loadObjectList('id'); // Get Languages $languages = FLEXI_FISH || FLEXI_J16GE ? FLEXIUtilities::getLanguages('code') : array(); // Get categories global $globalcats; $categories = $globalcats; if (!empty($conf)) { $this->assignRef('conf', $conf); $this->assignRef('cparams', $cparams); $this->assignRef('types', $types); $this->assignRef('languages', $languages); $this->assignRef('categories', $globalcats); parent::display('list'); return; } // ****************** // Create form fields // ****************** $lists['type_id'] = flexicontent_html::buildtypesselect($types, 'type_id', '', true, 'class="fcfield_selectval" size="1"', 'type_id'); $actions_allowed = array('core.create'); // Creating categorories tree for item assignment, we use the 'create' privelege // build the secondary categories select list $class = "fcfield_selectmulval"; $attribs = 'multiple="multiple" size="10" class="' . $class . '"'; $fieldname = FLEXI_J16GE ? 'seccats[]' : 'seccats[]'; $lists['seccats'] = flexicontent_cats::buildcatselect($categories, $fieldname, '', false, $attribs, false, true, $actions_allowed, $require_all = true); // build the main category select list $attribs = 'class="fcfield_selectval"'; $fieldname = FLEXI_J16GE ? 'maincat' : 'maincat'; $lists['maincat'] = flexicontent_cats::buildcatselect($categories, $fieldname, '', 2, $attribs, false, true, $actions_allowed); /* // build the main category select list $lists['maincat'] = flexicontent_cats::buildcatselect($categories, 'maincat', '', 0, 'class="inputbox" size="10"', false, false); // build the secondary categories select list $lists['seccats'] = flexicontent_cats::buildcatselect($categories, 'seccats[]', '', 0, 'class="inputbox" multiple="multiple" size="10"', false, false); */ //build languages list // 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); } $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null); $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs); // 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 if (FLEXI_FISH || FLEXI_J16GE) { $default_lang = $cparams->get('import_lang', '*'); $lists['languages'] = flexicontent_html::buildlanguageslist('language', '', $default_lang, 6, $allowed_langs, $published_only = true); } else { $default_lang = flexicontent_html::getSiteDefaultLang(); $_langs[] = JHTML::_('select.option', $default_lang, JText::_('Default') . ' (' . flexicontent_html::getSiteDefaultLang() . ')'); $lists['languages'] = JHTML::_('select.radiolist', $_langs, 'language', $class = '', 'value', 'text', $default_lang); } $default_state = $cparams->get('import_state', 1); $lists['states'] = flexicontent_html::buildstateslist('state', '', $default_state, 2); // Ignore warnings because component may not be installed $warnHandlers = JERROR::getErrorHandling(E_WARNING); JERROR::setErrorHandling(E_WARNING, 'ignore'); if (FLEXI_J30GE) { // J3.0+ adds an warning about component not installed, commented out ... till time ... $fleximport_comp_enabled = false; //JComponentHelper::isEnabled('com_fleximport'); } else { $fleximport_comp = JComponentHelper::getComponent('com_fleximport', true); $fleximport_comp_enabled = $fleximport_comp && $fleximport_comp->enabled; } // Reset the warning handler(s) foreach ($warnHandlers as $mode) { JERROR::setErrorHandling(E_WARNING, $mode); } if ($fleximport_comp_enabled) { $fleximport = JText::sprintf('FLEXI_FLEXIMPORT_INSTALLED', JText::_('FLEXI_FLEXIMPORT_INFOS')); } else { $fleximport = JText::sprintf('FLEXI_FLEXIMPORT_NOT_INSTALLED', JText::_('FLEXI_FLEXIMPORT_INFOS')); } // ******************************************************************************** // Get field names (from the header line (row 0), and remove it form the data array // ******************************************************************************** $file_field_types_list = '"image","file"'; $q = 'SELECT id, name, label, field_type FROM #__flexicontent_fields AS fi' . ' WHERE fi.field_type IN (' . $file_field_types_list . ')'; $db->setQuery($q); $file_fields = $db->loadObjectList('name'); //assign data to template $this->assignRef('lists', $lists); $this->assignRef('cid', $cid); $this->assignRef('user', $user); $this->assignRef('fleximport', $fleximport); $this->assignRef('cparams', $cparams); $this->assignRef('file_fields', $file_fields); parent::display($tpl); }
/** * Method to create the language datas * * @access public * @return boolean True on success * @since 1.5 */ function createLangColumn() { // Check for request forgeries JRequest::checkToken('request') or jexit('Invalid Token'); $db = JFactory::getDBO(); $nullDate = $db->getNullDate(); // Add language column if (!FLEXI_J16GE) { $fields = $db->getTableFields(array('#__flexicontent_items_ext')); $columns = $fields['#__flexicontent_items_ext']; } else { $columns = $db->getTableColumns('#__flexicontent_items_ext'); } $language_col = array_key_exists('language', $columns) ? true : false; if (!$language_col) { $query = "ALTER TABLE #__flexicontent_items_ext ADD `language` VARCHAR( 11 ) NOT NULL DEFAULT '' AFTER `type_id`"; $db->setQuery($query); $result_lang_col = $db->query(); if (!$result_lang_col) { echo "Cannot add language column<br>"; } } else { $result_lang_col = true; } // Add translation group column $lang_parent_id_col = array_key_exists('lang_parent_id', $columns) ? true : false; if (!$lang_parent_id_col) { $query = "ALTER TABLE #__flexicontent_items_ext ADD `lang_parent_id` INT NOT NULL DEFAULT 0 AFTER `language`"; $db->setQuery($query); $result_tgrp_col = $db->query(); if (!$result_tgrp_col) { echo "Cannot add translation group column<br>"; } } else { $result_tgrp_col = true; } // Add default language for items that do not have one, and add translation group to items that do not have one set $model = $this->getModel('flexicontent'); if ($model->getItemsNoLang()) { // Add site default language to the language field if empty $lang = flexicontent_html::getSiteDefaultLang(); $result_items_default_lang = $this->setItemsDefaultLang($lang); if (!$result_items_default_lang) { echo "Cannot set default language or set default translation group<br>"; } } else { $result_items_default_lang = true; } if (!$result_lang_col || !$result_tgrp_col || !$result_items_default_lang) { echo '<span class="install-notok"></span>'; jexit(); } else { echo '<span class="install-ok"></span>'; } }
/** * Creates the Filemanagerview * * @since 1.0 */ function display($tpl = null) { flexicontent_html::loadJQuery(); flexicontent_html::loadFramework('select2'); JHTML::_('behavior.tooltip'); // Load the form validation behavior JHTML::_('behavior.formvalidation'); //initialise variables $app = JFactory::getApplication(); $option = JRequest::getVar('option'); $document = JFactory::getDocument(); $db = JFactory::getDBO(); $user = JFactory::getUser(); $params = JComponentHelper::getParams('com_flexicontent'); //$authorparams = flexicontent_db::getUserConfig($user->id); $langs = FLEXIUtilities::getLanguages('code'); //get vars $filter_order = $app->getUserStateFromRequest($option . '.filemanager.filter_order', 'filter_order', 'f.filename', 'cmd'); $filter_order_Dir = $app->getUserStateFromRequest($option . '.filemanager.filter_order_Dir', 'filter_order_Dir', '', 'word'); $filter = $app->getUserStateFromRequest($option . '.filemanager.filter', 'filter', 1, 'int'); $filter_lang = $app->getUserStateFromRequest($option . '.filemanager.filter_lang', 'filter_lang', '', 'string'); $filter_uploader = $app->getUserStateFromRequest($option . '.filemanager.filter_uploader', 'filter_uploader', 0, 'int'); $filter_url = $app->getUserStateFromRequest($option . '.filemanager.filter_url', 'filter_url', '', 'word'); $filter_secure = $app->getUserStateFromRequest($option . '.filemanager.filter_secure', 'filter_secure', '', 'word'); $filter_ext = $app->getUserStateFromRequest($option . '.filemanager.filter_ext', 'filter_ext', '', 'alnum'); $search = $app->getUserStateFromRequest($option . '.filemanager.search', 'search', '', 'string'); $filter_item = $app->getUserStateFromRequest($option . '.filemanager.item_id', 'item_id', 0, 'int'); $folder_mode = 0; $search = FLEXI_J16GE ? $db->escape(trim(JString::strtolower($search))) : $db->getEscaped(trim(JString::strtolower($search))); //add css and submenu 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'); } } // Get User's Global Permissions $perms = FlexicontentHelperPerm::getPerm(); // ************************** // Create Submenu and toolbar // ************************** FLEXISubmenu('CanFiles'); // Create document/toolbar titles $doc_title = JText::_('FLEXI_FILEMANAGER'); $site_title = $document->getTitle(); JToolBarHelper::title($doc_title, 'files'); $document->setTitle($doc_title . ' - ' . $site_title); // Create the toolbar if (FLEXI_J16GE) { JToolBarHelper::deleteList('Are you sure?', 'filemanager.remove'); } else { JToolBarHelper::deleteList(); } if ($perms->CanConfig) { JToolBarHelper::divider(); JToolBarHelper::spacer(); $session = JFactory::getSession(); $fc_screen_width = (int) $session->get('fc_screen_width', 0, 'flexicontent'); $_width = $fc_screen_width && $fc_screen_width - 84 > 940 ? $fc_screen_width - 84 > 1400 ? 1400 : $fc_screen_width - 84 : 940; $fc_screen_height = (int) $session->get('fc_screen_height', 0, 'flexicontent'); $_height = $fc_screen_height && $fc_screen_height - 128 > 550 ? $fc_screen_height - 128 > 1000 ? 1000 : $fc_screen_height - 128 : 550; JToolBarHelper::preferences('com_flexicontent', $_height, $_width, 'Configuration'); } // *********************** // Get data from the model // *********************** $model = $this->getModel(); if (!$folder_mode) { $rows = $this->get('Data'); } else { // TODO MORE ... } $pagination = $this->get('Pagination'); //$users = $this->get('Users'); // Get item using at least one file (-of- the currently listed files) /*$items_single = $model->getItemsSingleprop( array('file','minigallery') ); $items_multi = $model->getItemsMultiprop ( $field_props=array('image'=>'originalname'), $value_props=array('image'=>'filename') ); $items = array(); foreach ($items_single as $item_id => $_item) $items[$item_id] = $_item; foreach ($items_multi as $item_id => $_item) $items[$item_id] = $_item; ksort($items);*/ $assigned_fields_labels = array('image' => 'image/gallery', 'file' => 'file', 'minigallery' => 'minigallery'); $assigned_fields_icons = array('image' => 'picture_link', 'file' => 'page_link', 'minigallery' => 'film_link'); /***************** ** BUILD LISTS ** *****************/ $lists = array(); // ** FILE UPLOAD FORM ** // Build languages list //$allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed',null); //$allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs); $display_file_lang_as = $params->get('display_file_lang_as', 3); $allowed_langs = null; if (FLEXI_FISH || FLEXI_J16GE) { $lists['file-lang'] = flexicontent_html::buildlanguageslist('file-lang', '', '*', $display_file_lang_as, $allowed_langs, $published_only = false); } else { $lists['file-lang'] = flexicontent_html::getSiteDefaultLang() . '<input type="hidden" name="file-lang" value="' . flexicontent_html::getSiteDefaultLang() . '" />'; } /************* ** FILTERS ** *************/ // language filter $lists['language'] = flexicontent_html::buildlanguageslist('filter_lang', 'class="use_select2_lib" onchange="submitform();" size="1" ', $filter_lang, 2); // search $lists['search'] = $search; //search filter $filters = array(); $filters[] = JHTML::_('select.option', '1', JText::_('FLEXI_FILENAME')); $filters[] = JHTML::_('select.option', '2', JText::_('FLEXI_FILE_TITLE')); $lists['filter'] = JHTML::_('select.genericlist', $filters, 'filter', 'size="1" class="use_select2_lib"', 'value', 'text', $filter); //build url/file filterlist $url = array(); $url[] = JHTML::_('select.option', '', '- ' . JText::_('FLEXI_ALL_FILES') . ' -'); $url[] = JHTML::_('select.option', 'F', JText::_('FLEXI_FILE')); $url[] = JHTML::_('select.option', 'U', JText::_('FLEXI_URL')); $lists['url'] = JHTML::_('select.genericlist', $url, 'filter_url', 'class="use_select2_lib" size="1" onchange="submitform( );"', 'value', 'text', $filter_url); //item lists /*$items_list = array(); $items_list[] = JHTML::_('select.option', '', '- '. JText::_( 'FLEXI_FILTER_BY_ITEM' ) .' -' ); foreach($items as $item) { $items_list[] = JHTML::_('select.option', $item->id, JText::_( $item->title ) . ' (#' . $item->id . ')' ); } $lists['item_id'] = JHTML::_('select.genericlist', $items_list, 'item_id', 'size="1" class="use_select2_lib" onchange="submitform( );"', 'value', 'text', $filter_item );*/ $lists['item_id'] = '<input type="text" name="item_id" size="1" class="inputbox" onchange="submitform( );" value="' . $filter_item . '" />'; //build secure/media filterlist $secure = array(); $secure[] = JHTML::_('select.option', '', '- ' . JText::_('FLEXI_ALL_DIRECTORIES') . ' -'); $secure[] = JHTML::_('select.option', 'S', JText::_('FLEXI_SECURE_DIR')); $secure[] = JHTML::_('select.option', 'M', JText::_('FLEXI_MEDIA_DIR')); $lists['secure'] = JHTML::_('select.genericlist', $secure, 'filter_secure', 'class="use_select2_lib" size="1" onchange="submitform( );"', 'value', 'text', $filter_secure); //build ext filterlist $lists['ext'] = flexicontent_html::buildfilesextlist('filter_ext', 'class="use_select2_lib" size="1" onchange="submitform( );"', $filter_ext); //build uploader filterlist $lists['uploader'] = flexicontent_html::builduploaderlist('filter_uploader', 'class="use_select2_lib" size="1" onchange="submitform( );"', $filter_uploader); // table ordering $lists['order_Dir'] = $filter_order_Dir; $lists['order'] = $filter_order; // uploadstuff if ($params->get('enable_flash', 1) && !FLEXI_J30GE) { JHTML::_('behavior.uploader', 'file-upload', array('onAllComplete' => 'function(){ window.location.reload(); }')); } jimport('joomla.client.helper'); $ftp = !JClientHelper::hasCredentials('ftp'); //assign data to template $this->assignRef('params', $params); $this->assign('require_ftp', $ftp); //Load pane behavior if (!FLEXI_J16GE) { jimport('joomla.html.pane'); $pane = JPane::getInstance('Tabs'); $this->assignRef('pane', $pane); } $this->assignRef('lists', $lists); $this->assignRef('rows', $rows); $this->assignRef('pagination', $pagination); $this->assignRef('CanFiles', $perms->CanFiles); $this->assignRef('CanUpload', $perms->CanUpload); $this->assignRef('CanViewAllFiles', $perms->CanViewAllFiles); $this->assignRef('assigned_fields_labels', $assigned_fields_labels); $this->assignRef('assigned_fields_icons', $assigned_fields_icons); $this->assignRef('langs', $langs); parent::display($tpl); }
<div class="fcclear"></div> <?php $label_tooltip = 'class="hasTip flexi_label" title="' . '::' . htmlspecialchars(JText::_('FLEXI_ORIGINAL_CONTENT_ITEM_DESC'), ENT_COMPAT, 'UTF-8') . '"'; ?> <label id="jform_lang_parent_id-lbl" for="jform_lang_parent_id" <?php echo $label_tooltip; ?> > <?php echo JText::_('FLEXI_ORIGINAL_CONTENT_ITEM'); ?> </label> <div class="container_fcfield container_fcfield_name_originalitem"> <?php if ($this->row->id && (substr(flexicontent_html::getSiteDefaultLang(), 0, 2) == substr($this->row->language, 0, 2) || $this->row->language == '*')) { ?> <br/><small><?php echo JText::_($this->row->language == '*' ? 'FLEXI_ORIGINAL_CONTENT_ALL_LANGS' : 'FLEXI_ORIGINAL_TRANSLATION_CONTENT'); ?> </small> <input type="hidden" name="jform[lang_parent_id]" id="jform_lang_parent_id" value="<?php echo $this->row->id; ?> " /> <?php } else { ?> <?php if (1) { // currently selecting associated item, is always allowed in backend
/** * 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; } }
/** * Creates the item page * * @since 1.0 */ function display($tpl = null) { // ******************************** // Initialize variables, flags, etc // ******************************** global $globalcats; $categories = $globalcats; $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $document = JFactory::getDocument(); $config = JFactory::getConfig(); $session = JFactory::getSession(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $option = JRequest::getVar('option'); $nullDate = $db->getNullDate(); // Get the COMPONENT only parameters // Get component parameters $params = new JRegistry(); $cparams = JComponentHelper::getParams('com_flexicontent'); $params->merge($cparams); $params = clone JComponentHelper::getParams('com_flexicontent'); // Some flags $enable_translation_groups = flexicontent_db::useAssociations(); //$params->get("enable_translation_groups"); $print_logging_info = $params->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; } // ***************** // Load JS/CSS files // ***************** // Add css to document $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontentbackend.css', FLEXI_VERSION); $document->addStyleSheetVersion(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css', FLEXI_VERSION); // Fields common CSS $document->addStyleSheetVersion(JURI::root(true) . '/components/com_flexicontent/assets/css/flexi_form_fields.css', FLEXI_VERSION); // Add JS frameworks flexicontent_html::loadFramework('select2'); $prettycheckable_added = flexicontent_html::loadFramework('prettyCheckable'); flexicontent_html::loadFramework('flexi-lib'); // Add js function to overload the joomla submitform validation JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/admin.js', FLEXI_VERSION); $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/validate.js', FLEXI_VERSION); // Add js function for custom code used by FLEXIcontent item form $document->addScriptVersion(JURI::root(true) . '/components/com_flexicontent/assets/js/itemscreen.js', FLEXI_VERSION); // *********************** // Get data from the model // *********************** if ($print_logging_info) { $start_microtime = microtime(true); } $model = $this->getModel(); $item = $model->getItem(); $form = $this->get('Form'); if ($print_logging_info) { $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // *************************** // Get Associated Translations // *************************** if ($enable_translation_groups) { $langAssocs = $this->get('LangAssocs'); } $langs = FLEXIUtilities::getLanguages('code'); // Get item id and new flag $cid = $model->getId(); $isnew = !$cid; // Create and set a unique item id for plugins that needed it if ($cid) { $unique_tmp_itemid = $cid; } else { $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid'); $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true); } //print_r($unique_tmp_itemid); JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid); // Get number of subscribers $subscribers = $model->getSubscribersCount(); // ****************** // Version Panel data // ****************** // Get / calculate some version related variables $versioncount = $model->getVersionCount(); $versionsperpage = $params->get('versionsperpage', 10); $pagecount = (int) ceil($versioncount / $versionsperpage); // Data need by version panel: (a) current version page, (b) currently active version $current_page = 1; $k = 1; $allversions = $model->getVersionList(); foreach ($allversions as $v) { if ($k > 1 && ($k - 1) % $versionsperpage == 0) { $current_page++; } if ($v->nr == $item->version) { break; } $k++; } // Finally fetch the version data for versions in current page $versions = $model->getVersionList(($current_page - 1) * $versionsperpage, $versionsperpage); // Create display of average rating $ratings = $model->getRatingDisplay(); // ***************** // Type related data // ***************** // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Get and merge type parameters $tparams = $this->get('Typeparams'); $tparams = new JRegistry($tparams); $params->merge($tparams); // Apply type configuration if it type is set // Get user allowed permissions on the item ... to be used by the form rendering // Also hide parameters panel if user can not edit parameters $perms = $this->_getItemPerms($item); if (!$perms['canparams']) { $document->addStyleDeclaration('#details-options {display:none;}'); } // ****************** // Create the toolbar // ****************** $toolbar = JToolBar::getInstance('toolbar'); $tip_class = FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; // SET toolbar title if ($cid) { JToolBarHelper::title(JText::_('FLEXI_EDIT_ITEM'), 'itemedit'); // Editing existing item } else { JToolBarHelper::title(JText::_('FLEXI_NEW_ITEM'), 'itemadd'); // Creating new item } // ************** // Common Buttons // ************** // Applying new item type is a special case that has not loaded custom fieds yet JToolBarHelper::apply($item->type_id ? 'items.apply' : 'items.apply_type', !$isnew ? 'FLEXI_APPLY' : ($typesselected->id ? 'FLEXI_ADD' : 'FLEXI_APPLY_TYPE'), false); /*if (!$isnew || $item->version) flexicontent_html::addToolBarButton( 'FLEXI_FAST_APPLY', $btn_name='apply_ajax', $full_js="Joomla.submitbutton('items.apply_ajax')", $msg_alert='', $msg_confirm='', $btn_task='items.apply_ajax', $extra_js='', $btn_list=false, $btn_menu=true, $btn_confirm=false, $btn_class="".$tip_class, $btn_icon="icon-loop", 'data-placement="bottom" title="Fast saving, without reloading the form. <br/><br/>Note: new files will not be uploaded, <br/>- in such a case please use \'Apply\'"');*/ if (!$isnew || $item->version) { JToolBarHelper::save('items.save'); } if (!$isnew || $item->version) { JToolBarHelper::custom('items.saveandnew', 'savenew.png', 'savenew.png', 'FLEXI_SAVE_AND_NEW', false); } JToolBarHelper::cancel('items.cancel'); // *********************** // Add a preview button(s) // *********************** //$_sh404sef = JPluginHelper::isEnabled('system', 'sh404sef') && $config->get('sef'); $_sh404sef = defined('SH404SEF_IS_RUNNING') && $config->get('sef'); if ($cid) { // Domain URL and autologin vars $server = JURI::getInstance()->toString(array('scheme', 'host', 'port')); $autologin = ''; //$params->get('autoflogin', 1) ? '&fcu='.$user->username . '&fcp='.$user->password : ''; // Check if we are in the backend, in the back end we need to set the application to the site app instead // we do not remove 'isAdmin' check so that we can copy later without change, e.g. to a plugin $isAdmin = JFactory::getApplication()->isAdmin(); if ($isAdmin && !$_sh404sef) { JFactory::$application = JApplication::getInstance('site'); } // Create the URL $item_url = FlexicontentHelperRoute::getItemRoute($item->id . ':' . $item->alias, $categories[$item->catid]->slug) . ($item->language != '*' ? '&lang=' . substr($item->language, 0, 2) : ''); $item_url = $_sh404sef ? Sh404sefHelperGeneral::getSefFromNonSef($item_url, $fullyQualified = true, $xhtml = false, $ssl = null) : JRoute::_($item_url); // Check if we are in the backend again // In backend we need to remove administrator from URL as it is added even though we've set the application to the site app if ($isAdmin && !$_sh404sef) { $admin_folder = str_replace(JURI::root(true), '', JURI::base(true)); $item_url = str_replace($admin_folder . '/', '/', $item_url); // Restore application JFactory::$application = JApplication::getInstance('administrator'); } $previewlink = $item_url . (strstr($item_url, '?') ? '&' : '?') . 'preview=1' . $autologin; //$previewlink = str_replace('&', '&', $previewlink); //$previewlink = JRoute::_(JURI::root() . FlexicontentHelperRoute::getItemRoute($item->id.':'.$item->alias, $categories[$item->catid]->slug)) .$autologin; // PREVIEW for latest version if (!$params->get('use_versioning', 1) || $item->version == $item->current_version && $item->version == $item->last_version) { $toolbar->appendButton('Custom', '<button class="preview btn btn-small btn-info spaced-btn" onClick="window.open(\'' . $previewlink . '\');"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('Preview') . '</button>', 'preview'); } else { // Add a preview button for (currently) LOADED version of the item $previewlink_loaded_ver = $previewlink . '&version=' . $item->version; $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_loaded_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FORM_LOADED_VERSION') . ' [' . $item->version . ']</button>', 'preview'); // Add a preview button for currently ACTIVE version of the item $previewlink_active_ver = $previewlink . '&version=' . $item->current_version; $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_active_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_FRONTEND_ACTIVE_VERSION') . ' [' . $item->current_version . ']</button>', 'preview'); // Add a preview button for currently LATEST version of the item $previewlink_last_ver = $previewlink; //'&version='.$item->last_version; $toolbar->appendButton('Custom', '<button class="preview btn btn-small" onClick="window.open(\'' . $previewlink_last_ver . '\');" target="_blank"><span title="' . JText::_('Preview') . '" class="icon-screen"></span>' . JText::_('FLEXI_PREVIEW_LATEST_SAVED_VERSION') . ' [' . $item->last_version . ']</button>', 'preview'); } JToolBarHelper::spacer(); JToolBarHelper::divider(); JToolBarHelper::spacer(); } // ************************ // Add modal layout editing // ************************ if ($perms['cantemplates']) { JToolBarHelper::divider(); if (!$isnew || $item->version) { flexicontent_html::addToolBarButton('FLEXI_EDIT_LAYOUT', $btn_name = 'apply_ajax', $full_js = "var url = jQuery(this).attr('data-href'); fc_showDialog(url, 'fc_modal_popup_container'); return false;", $msg_alert = '', $msg_confirm = '', $btn_task = 'items.apply_ajax', $extra_js = '', $btn_list = false, $btn_menu = true, $btn_confirm = false, $btn_class = "btn-info" . $tip_class, $btn_icon = "icon-pencil", 'data-placement="bottom" data-href="index.php?option=com_flexicontent&view=template&type=items&tmpl=component&ismodal=1&folder=' . $item->itemparams->get('ilayout', $tparams->get('ilayout', 'default')) . '" title="Edit the display layout of this item. <br/><br/>Note: this layout maybe assigned to content types or other items, thus changing it will effect them too"'); } } // Check if saving an item that translates an original content in site's default language $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2); $is_content_default_lang = $site_default == substr($item->language, 0, 2); // ***************************************************************************** // Get (CORE & CUSTOM) fields and their VERSIONED values and then // (a) Apply Content Type Customization to CORE fields (label, description, etc) // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField' // ***************************************************************************** if ($print_logging_info) { $start_microtime = microtime(true); } $fields = $this->get('Extrafields'); $item->fields =& $fields; if ($print_logging_info) { $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } if ($print_logging_info) { $start_microtime = microtime(true); } $jcustom = $app->getUserState('com_flexicontent.edit.item.custom'); //print_r($jcustom); foreach ($fields as $field) { // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations if ($field->iscore) { FlexicontentFields::loadFieldConfig($field, $item); } // b. Create field 's editing HTML (the form field) // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow) if (!$field->iscore) { if (isset($jcustom[$field->name])) { $field->value = array(); foreach ($jcustom[$field->name] as $i => $_val) { $field->value[$i] = $_val; } } $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); if ($is_editable) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item)); if ($field->untranslatable) { $field->html = (!isset($field->html) ? '<div class="fc-mssg-inline fc-warning" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_PLEASE_PUBLISH_THIS_PLUGIN') . '</div><div class="clear"></div>' : '') . '<div class="alert alert-info fc-small fc-iblock" style="margin:0 4px 6px 4px; max-width: unset;">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . (isset($field->html) ? '<div class="clear"></div>' . $field->html : ''); } } else { if ($field->valueseditable == 1) { $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>'; } else { if ($field->valueseditable == 2) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display; } else { if ($field->valueseditable == 3) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = $field->display; } else { if ($field->valueseditable == 4) { $field->html = ''; $field->formhidden = 4; } } } } } } // c. Create main text field, via calling the display function of the textarea field (will also check for tabs) if ($field->field_type == 'maintext') { if (isset($item->item_translations)) { $shortcode = substr($item->language, 0, 2); foreach ($item->item_translations as $lang_id => $t) { if ($shortcode == $t->shortcode) { continue; } $field->name = array('jfdata', $t->shortcode, 'text'); $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8'); FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); $t->fields->text->tab_labels = $field->tab_labels; $t->fields->text->html = $field->html; unset($field->tab_labels); unset($field->html); } } $field->name = 'text'; // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data $field->value[0] = $item->text; // do not decode special characters this was handled during saving ! // Render the field's (form) HTML FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); } } if ($print_logging_info) { $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // ************************* // Get tags used by the item // ************************* $usedtagsIds = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) $usedtags = $model->getUsedtagsData($usedtagsIds); // ******************************* // Get categories used by the item // ******************************* if ($isnew) { // Case for preselected main category for new items $maincat = $item->catid ? $item->catid : JRequest::getInt('maincat', 0); if (!$maincat) { $maincat = $app->getUserStateFromRequest($option . '.items.filter_cats', 'filter_cats', '', 'int'); } if ($maincat) { $selectedcats = array($maincat); $item->catid = $maincat; } else { $selectedcats = array(); } if ($tparams->get('cid_default')) { $selectedcats = $tparams->get('cid_default'); } if ($tparams->get('catid_default')) { $item->catid = $tparams->get('catid_default'); } } else { // NOTE: This will normally return the already set versioned value of categories ($item->categories) $selectedcats = $this->get('Catsselected'); } //$selectedcats = $isnew ? array() : $fields['categories']->value; //echo "<br/>row->tags: "; print_r($item->tags); //echo "<br/>usedtagsIds: "; print_r($usedtagsIds); //echo "<br/>usedtags (data): "; print_r($usedtags); //echo "<br/>row->categories: "; print_r($item->categories); //echo "<br/>selectedcats: "; print_r($selectedcats); // ********************************************************************************************* // Build select lists for the form field. Only few of them are used in J1.6+, since we will use: // (a) form XML file to declare them and then (b) getInput() method form field to create them // ********************************************************************************************* // First clean form data, we do this after creating the description field which may contain HTML JFilterOutput::objectHTMLSafe($item, ENT_QUOTES); $lists = array(); // build state list $non_publishers_stategrp = $perms['isSuperAdmin'] || $item->state == -3 || $item->state == -4; $special_privelege_stategrp = $item->state == 2 || $perms['canarchive'] || ($item->state == -2 || $perms['candelete']); $state = array(); // Using <select> groups if ($non_publishers_stategrp || $special_privelege_stategrp) { $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_PUBLISHERS_WORKFLOW_STATES')); } $state[] = JHTML::_('select.option', 1, JText::_('FLEXI_PUBLISHED')); $state[] = JHTML::_('select.option', 0, JText::_('FLEXI_UNPUBLISHED')); $state[] = JHTML::_('select.option', -5, JText::_('FLEXI_IN_PROGRESS')); // States reserved for workflow if ($non_publishers_stategrp) { $state[] = JHTML::_('select.optgroup', ''); $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_NON_PUBLISHERS_WORKFLOW_STATES')); } if ($item->state == -3 || $perms['isSuperAdmin']) { $state[] = JHTML::_('select.option', -3, JText::_('FLEXI_PENDING')); } if ($item->state == -4 || $perms['isSuperAdmin']) { $state[] = JHTML::_('select.option', -4, JText::_('FLEXI_TO_WRITE')); } // Special access states if ($special_privelege_stategrp) { $state[] = JHTML::_('select.optgroup', ''); $state[] = JHTML::_('select.optgroup', JText::_('FLEXI_SPECIAL_ACTION_STATES')); } if ($item->state == 2 || $perms['canarchive']) { $state[] = JHTML::_('select.option', 2, JText::_('FLEXI_ARCHIVED')); } if ($item->state == -2 || $perms['candelete']) { $state[] = JHTML::_('select.option', -2, JText::_('FLEXI_TRASHED')); } // Close last <select> group if ($non_publishers_stategrp || $special_privelege_stategrp) { $state[] = JHTML::_('select.optgroup', ''); } $fieldname = 'jform[state]'; $elementid = 'jform_state'; $class = 'use_select2_lib'; $attribs = 'class="' . $class . '"'; $lists['state'] = JHTML::_('select.genericlist', $state, $fieldname, $attribs, 'value', 'text', $item->state, $elementid); if (!FLEXI_J16GE) { $lists['state'] = str_replace('<optgroup label="">', '</optgroup>', $lists['state']); } // *** BOF: J2.5 SPECIFIC SELECT LISTS if (FLEXI_J16GE) { // build featured flag $fieldname = 'jform[featured]'; $elementid = 'jform_featured'; /* $options = array(); $options[] = JHTML::_('select.option', 0, JText::_( 'FLEXI_NO' ) ); $options[] = JHTML::_('select.option', 1, JText::_( 'FLEXI_YES' ) ); $attribs = FLEXI_J16GE ? ' style ="float:none!important;" ' : ''; // this is not right for J1.5' style ="float:left!important;" '; $lists['featured'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', $item->featured, $elementid); */ $classes = !$prettycheckable_added ? '' : ' use_prettycheckable '; $attribs = ' class="' . $classes . '" '; $i = 1; $options = array(0 => JText::_('FLEXI_NO'), 1 => JText::_('FLEXI_YES')); $lists['featured'] = ''; foreach ($options as $option_id => $option_label) { $checked = $option_id == $item->featured ? ' checked="checked"' : ''; $elementid_no = $elementid . '_' . $i; if (!$prettycheckable_added) { $lists['featured'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">'; } $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['featured'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['featured'] .= ' ' . JText::_($option_label) . '</label>'; } $i++; } } // *** EOF: J1.5 SPECIFIC SELECT LISTS // build version approval list $fieldname = 'jform[vstate]'; $elementid = 'jform_vstate'; /* $options = array(); $options[] = JHTML::_('select.option', 1, JText::_( 'FLEXI_NO' ) ); $options[] = JHTML::_('select.option', 2, JText::_( 'FLEXI_YES' ) ); $attribs = FLEXI_J16GE ? ' style ="float:left!important;" ' : ''; // this is not right for J1.5' style ="float:left!important;" '; $lists['vstate'] = JHTML::_('select.radiolist', $options, $fieldname, $attribs, 'value', 'text', 2, $elementid); */ $classes = !$prettycheckable_added ? '' : ' use_prettycheckable '; $attribs = ' class="' . $classes . '" '; $i = 1; $options = array(1 => JText::_('FLEXI_NO'), 2 => JText::_('FLEXI_YES')); $lists['vstate'] = ''; foreach ($options as $option_id => $option_label) { $checked = $option_id == 2 ? ' checked="checked"' : ''; $elementid_no = $elementid . '_' . $i; if (!$prettycheckable_added) { $lists['vstate'] .= '<label class="fccheckradio_lbl" for="' . $elementid_no . '">'; } $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . JText::_($option_label) . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['vstate'] .= ' <input type="radio" id="' . $elementid_no . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="' . $option_id . '" ' . $checked . $extra_params . ' />'; if (!$prettycheckable_added) { $lists['vstate'] .= ' ' . JText::_($option_label) . '</label>'; } $i++; } // build field for notifying subscribers if (!$subscribers) { $lists['notify'] = !$isnew ? JText::_('FLEXI_NO_SUBSCRIBERS_EXIST') : ''; } else { // b. Check if notification emails to subscribers , were already sent during current session $subscribers_notified = $session->get('subscribers_notified', array(), 'flexicontent'); if (!empty($subscribers_notified[$item->id])) { $lists['notify'] = JText::_('FLEXI_SUBSCRIBERS_ALREADY_NOTIFIED'); } else { // build favs notify field $fieldname = 'jform[notify]'; $elementid = 'jform_notify'; /* $attribs = FLEXI_J16GE ? ' style ="float:none!important;" ' : ''; // this is not right for J1.5' style ="float:left!important;" '; $lists['notify'] = '<input type="checkbox" name="jform[notify]" id="jform_notify" '.$attribs.' /> '. $lbltxt; */ $classes = !$prettycheckable_added ? '' : ' use_prettycheckable '; $attribs = ' class="' . $classes . '" '; $lbltxt = $subscribers . ' ' . JText::_($subscribers > 1 ? 'FLEXI_SUBSCRIBERS' : 'FLEXI_SUBSCRIBER'); if (!$prettycheckable_added) { $lists['notify'] .= '<label class="fccheckradio_lbl" for="' . $elementid . '">'; } $extra_params = !$prettycheckable_added ? '' : ' data-labeltext="' . $lbltxt . '" data-labelPosition="right" data-customClass="fcradiocheck"'; $lists['notify'] = ' <input type="checkbox" id="' . $elementid . '" data-element-grpid="' . $elementid . '" name="' . $fieldname . '" ' . $attribs . ' value="1" ' . $extra_params . ' checked="checked" />'; if (!$prettycheckable_added) { $lists['notify'] .= ' ' . $lbltxt . '</label>'; } } } // Retrieve author configuration $authorparams = flexicontent_db::getUserConfig($user->id); // Get author's maximum allowed categories per item and set js limitation $max_cat_assign = intval($authorparams->get('max_cat_assign', 0)); $document->addScriptDeclaration(' max_cat_assign_fc = ' . $max_cat_assign . '; existing_cats_fc = ["' . implode('","', $selectedcats) . '"]; '); JText::script('FLEXI_TOO_MANY_ITEM_CATEGORIES', true); // Creating categorories tree for item assignment, we use the 'create' privelege $actions_allowed = array('core.create'); // Featured categories form field $featured_cats_parent = $params->get('featured_cats_parent', 0); $featured_cats = array(); $enable_featured_cid_selector = $perms['multicat'] && $perms['canchange_featcat']; if ($featured_cats_parent) { $featured_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $featured_cats_parent, $depth_limit = 0); $disabled_cats = $params->get('featured_cats_parent_disable', 1) ? array($featured_cats_parent) : array(); $featured_sel = array(); foreach ($selectedcats as $item_cat) { if (isset($featured_tree[$item_cat])) { $featured_sel[] = $item_cat; } } $class = "use_select2_lib select2_list_selected"; $attribs = 'class="' . $class . '" multiple="multiple" size="8"'; $attribs .= $enable_featured_cid_selector ? '' : ' disabled="disabled"'; $fieldname = 'jform[featured_cid][]'; $lists['featured_cid'] = ($enable_featured_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($featured_tree, $fieldname, $featured_sel, 3, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats); } else { // Do not display, if not configured or not allowed to the user $lists['featured_cid'] = false; } // Multi-category form field, for user allowed to use multiple categories $lists['cid'] = ''; $enable_cid_selector = $perms['multicat'] && $perms['canchange_seccat']; if (1) { if ($tparams->get('cid_allowed_parent')) { $cid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('cid_allowed_parent'), $depth_limit = 0); $disabled_cats = $tparams->get('cid_allowed_parent_disable', 1) ? array($tparams->get('cid_allowed_parent')) : array(); } else { $cid_tree =& $categories; $disabled_cats = array(); } // Get author's maximum allowed categories per item and set js limitation $max_cat_assign = !$authorparams ? 0 : intval($authorparams->get('max_cat_assign', 0)); $document->addScriptDeclaration(' max_cat_assign_fc = ' . $max_cat_assign . '; existing_cats_fc = ["' . implode('","', $selectedcats) . '"]; '); $class = "mcat use_select2_lib select2_list_selected"; $class .= $max_cat_assign ? " validate-fccats" : " validate"; $attribs = 'class="' . $class . '" multiple="multiple" size="20"'; $attribs .= $enable_cid_selector ? '' : ' disabled="disabled"'; $fieldname = 'jform[cid][]'; $skip_subtrees = $featured_cats_parent ? array($featured_cats_parent) : array(); $lists['cid'] = ($enable_cid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($cid_tree, $fieldname, $selectedcats, false, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees, $disable_subtrees = array(), $custom_options = array(), $disabled_cats); } else { if (count($selectedcats) > 1) { foreach ($selectedcats as $catid) { $cat_titles[$catid] = $globalcats[$catid]->title; } $lists['cid'] .= implode(', ', $cat_titles); } else { $lists['cid'] = false; } } // Main category form field $class = 'scat use_select2_lib'; if ($perms['multicat']) { $class .= ' validate-catid'; } else { $class .= ' required'; } $attribs = 'class="' . $class . '"'; $fieldname = 'jform[catid]'; $enable_catid_selector = $isnew && !$tparams->get('catid_default') || !$isnew && empty($item->catid) || $perms['canchange_cat']; if ($tparams->get('catid_allowed_parent')) { $catid_tree = flexicontent_cats::getCategoriesTree($published_only = 1, $parent_id = $tparams->get('catid_allowed_parent'), $depth_limit = 0); $disabled_cats = $tparams->get('catid_allowed_parent_disable', 1) ? array($tparams->get('catid_allowed_parent')) : array(); } else { $catid_tree =& $categories; $disabled_cats = array(); } $lists['catid'] = false; if (!empty($catid_tree)) { $disabled = $enable_catid_selector ? '' : ' disabled="disabled"'; $attribs .= $disabled; $lists['catid'] = ($enable_catid_selector ? '' : '<label class="label" style="float:none; margin:0 6px 0 0 !important;">locked</label>') . flexicontent_cats::buildcatselect($catid_tree, $fieldname, $item->catid, 2, $attribs, true, true, $actions_allowed, $require_all = true, $skip_subtrees = array(), $disable_subtrees = array(), $custom_options = array(), $disabled_cats); } else { if (!$isnew && $item->catid) { $lists['catid'] = $globalcats[$item->catid]->title; } } //buid types selectlist $class = 'required use_select2_lib'; $attribs = 'class="' . $class . '"'; $fieldname = 'jform[type_id]'; $elementid = 'jform_type_id'; $lists['type'] = flexicontent_html::buildtypesselect($types, $fieldname, $typesselected->id, 1, $attribs, $elementid, $check_perms = true); //build languages list $allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed', null); $allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs); if (!$isnew && $allowed_langs) { $allowed_langs[] = $item->language; } // We will not use the default getInput() function of J1.6+ since we want to create a radio selection field with flags // we could also create a new class and override getInput() method but maybe this is an overkill, we may do it in the future $lists['languages'] = flexicontent_html::buildlanguageslist('jform[language]', 'class="use_select2_lib"', $item->language, 2, $allowed_langs); // Label for current item state: published, unpublished, archived etc switch ($item->state) { case 0: $published = JText::_('FLEXI_UNPUBLISHED'); break; case 1: $published = JText::_('FLEXI_PUBLISHED'); break; case -1: $published = JText::_('FLEXI_ARCHIVED'); break; case -3: $published = JText::_('FLEXI_PENDING'); break; case -5: $published = JText::_('FLEXI_IN_PROGRESS'); break; case -4: default: $published = JText::_('FLEXI_TO_WRITE'); break; } // ************************************************************** // Handle Item Parameters Creation and Load their values for J1.5 // In J1.6+ we declare them in the item form XML file // ************************************************************** if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $db->getNullDate() || empty($item->publish_down)) { $form->setValue('publish_down', null, ''); // Setting to text will break form date element } // **************************** // Handle Template related work // **************************** // (a) Get the templates structures used to create form fields for template parameters $themes = flexicontent_tmpl::getTemplates(); $tmpls_all = $themes->items; // (b) Get Content Type allowed templates $allowed_tmpls = $tparams->get('allowed_ilayouts'); $type_default_layout = $tparams->get('ilayout', 'default'); if (empty($allowed_tmpls)) { $allowed_tmpls = array(); } else { if (!is_array($allowed_tmpls)) { $allowed_tmpls = explode("|", $allowed_tmpls); } } // (c) Add default layout, unless all templates allowed (=array is empty) if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) { $allowed_tmpls[] = $type_default_layout; } // (d) Create array of template data according to the allowed templates for current content type if (count($allowed_tmpls)) { foreach ($tmpls_all as $tmpl) { if (in_array($tmpl->name, $allowed_tmpls)) { $tmpls[] = $tmpl; } } } else { $tmpls = $tmpls_all; } // (e) Apply Template Parameters values into the form fields structures foreach ($tmpls as $tmpl) { $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true)); $jform->load($tmpl->params); $tmpl->params = $jform; foreach ($tmpl->params->getGroup('attribs') as $field) { $fieldname = $field->__get('fieldname'); $value = $item->itemparams->get($fieldname); if (strlen($value)) { $tmpl->params->setValue($fieldname, 'attribs', $value); } } } // ****************************** // Assign data to VIEW's template // ****************************** $this->assignRef('document', $document); $this->assignRef('lists', $lists); $this->assignRef('row', $item); if (FLEXI_J16GE) { $this->assignRef('form', $form); } else { $this->assignRef('editor', $editor); $this->assignRef('pane', $pane); $this->assignRef('formparams', $formparams); } if ($enable_translation_groups) { $this->assignRef('lang_assocs', $langAssocs); } if (FLEXI_FISH || FLEXI_J16GE) { $this->assignRef('langs', $langs); } $this->assignRef('typesselected', $typesselected); $this->assignRef('published', $published); $this->assignRef('nullDate', $nullDate); $this->assignRef('subscribers', $subscribers); $this->assignRef('fields', $fields); $this->assignRef('versions', $versions); $this->assignRef('ratings', $ratings); $this->assignRef('pagecount', $pagecount); $this->assignRef('params', $params); $this->assignRef('tparams', $tparams); $this->assignRef('tmpls', $tmpls); $this->assignRef('usedtags', $usedtags); $this->assignRef('perms', $perms); $this->assignRef('current_page', $current_page); // Clear custom form data from session $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false); $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false); $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false); if ($print_logging_info) { $start_microtime = microtime(true); } parent::display($tpl); if ($print_logging_info) { $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } }
/** * Method to save field values of the item in field versioning DB table or in ..._fields_item_relations DB table * * @access public * @return boolean True on success * @since 1.0 */ function saveFields($isnew, &$item, &$data, &$files, &$old_item = null, &$core_data_via_events = null) { if (!$old_item) { $old_item =& $item; } $app = JFactory::getApplication(); $user = JFactory::getUser(); $dispatcher = JDispatcher::getInstance(); $cparams = $this->_cparams; $use_versioning = $cparams->get('use_versioning', 1); $print_logging_info = $cparams->get('print_logging_info'); $last_version = (int) FLEXIUtilities::getLastVersions($item->id, true); $mval_query = true; if ($print_logging_info) { global $fc_run_times; } if ($print_logging_info) { $start_microtime = microtime(true); } // ******************************** // Checks for untranslatable fields // ******************************** // CASE 1. Check if saving an item that translates an original content in site's default language // ... Decide whether to retrieve field values of untranslatable fields from the original content item $enable_translation_groups = flexicontent_db::useAssociations(); //$cparams->get('enable_translation_groups'); $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2); $is_content_default_lang = $site_default == substr($item->language, 0, 2); $get_untraslatable_values = $enable_translation_groups && !$is_content_default_lang; if ($enable_translation_groups) { $langAssocs = $this->getLangAssocs(); //} //if ($enable_translation_groups /*&& $is_content_default_lang*/) //{ // ... Get item ids of the associated items, so that we save into the untranslatable fields $_langAssocs = $langAssocs; unset($_langAssocs[$this->_id]); $assoc_item_ids = array_keys($_langAssocs); } if (empty($assoc_item_ids)) { $assoc_item_ids = array(); } // *************************************************************************************************************************** // Get item's fields ... and their values (for untranslatable fields the field values from original content item are retrieved // *************************************************************************************************************************** $original_content_id = 0; if ($get_untraslatable_values) { foreach ($langAssocs as $content_id => $_assoc) { if ($site_default == substr($_assoc->language, 0, 2)) { $original_content_id = $content_id; break; } } } //JFactory::getApplication()->enqueueMessage(__FUNCTION__.'(): '.$original_content_id.' '.print_r($assoc_item_ids, true),'message'); $fields = $this->getExtrafields($force = true, $original_content_id, $old_item); // ****************************************************************************************************************** // Loop through Fields triggering onBeforeSaveField Event handlers, this was seperated from the rest of the process // to give chance to ALL fields to check their DATA and cancel item saving process before saving any new field values // ****************************************************************************************************************** $searchindex = array(); //$qindex = array(); $core_data_via_events = array(); // Extra validation for some core fields via onBeforeSaveField if ($fields) { $core_via_post = array('title' => 1, 'text' => 1); foreach ($fields as $field) { // Set vstate property into the field object to allow this to be changed be the before saving field event handler $field->item_vstate = $data['vstate']; $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); $maintain_dbval = false; // FORM HIDDEN FIELDS (FRONTEND/BACKEND) AND (ACL) UNEDITABLE FIELDS: maintain their DB value ... if ($app->isSite() && ($field->formhidden == 1 || $field->formhidden == 3 || $field->parameters->get('frontend_hidden')) || $app->isAdmin() && ($field->formhidden == 2 || $field->formhidden == 3 || $field->parameters->get('backend_hidden')) || !$is_editable) { $postdata[$field->name] = $field->value; $maintain_dbval = true; // UNTRANSLATABLE (CUSTOM) FIELDS: maintain their DB value ... /*} else if ( $get_untraslatable_values && $field->untranslatable ) { $postdata[$field->name] = $field->value; $maintain_dbval = true;*/ } else { if ($field->iscore) { // (posted) CORE FIELDS: if not set maintain their DB value ... if (isset($core_via_post[$field->name])) { if (isset($data[$field->name])) { $postdata[$field->name] = $data[$field->name]; } else { $postdata[$field->name] = $field->value; $maintain_dbval = true; } // (not posted) CORE FIELDS: get current value } else { // Get value from the updated item instead of old data $postdata[$field->name] = $this->getCoreFieldValue($field, 0); } // OTHER CUSTOM FIELDS (not hidden and not untranslatable) } else { $postdata[$field->name] = @$data['custom'][$field->name]; } } // Unserialize values already serialized values, e.g. (a) if current values used are from DB or (b) are being imported from CSV file if (!is_array($postdata[$field->name])) { $postdata[$field->name] = strlen($postdata[$field->name]) ? array($postdata[$field->name]) : array(); } foreach ($postdata[$field->name] as $i => $postdata_val) { if (@unserialize($postdata_val) !== false || $postdata_val === 'b:0;') { $postdata[$field->name][$i] = unserialize($postdata_val); } } // Trigger plugin Event 'onBeforeSaveField' if (!$field->iscore || isset($core_via_post[$field->name])) { $field_type = $field->iscore ? 'core' : $field->field_type; $result = FLEXIUtilities::call_FC_Field_Func($field_type, 'onBeforeSaveField', array(&$field, &$postdata[$field->name], &$files[$field->name], &$item)); if ($result === false) { // Field requested to abort item saving $this->setError(JText::sprintf('FLEXI_FIELD_VALUE_IS_INVALID', $field->label)); return 'abort'; } // For CORE field get the modified data, which will be used for storing in DB (these will be re-bind later) if (isset($core_via_post[$field->name])) { $core_data_via_events[$field->name] = isset($postdata[$field->name][0]) ? $postdata[$field->name][0] : ''; // The validation may have skipped it !! } } else { // Currently other CORE fields, these are skipped we will not call onBeforeSaveField() on them, neither rebind them } //$qindex[$field->name] = NULL; //$result = FLEXIUtilities::call_FC_Field_Func($field_type, 'onBeforeSaveField', array( &$field, &$postdata[$field->name], &$files[$field->name], &$item, &$qindex[$field->name] )); //if ($result===false) { ... } // Get vstate property from the field object back to the data array ... in case it was modified, since some field may decide to prevent approval ! $data['vstate'] = $field->item_vstate; } //echo "<pre>"; print_r($postdata); echo "</pre>"; exit; } if ($print_logging_info) { @($fc_run_times['fields_value_preparation'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } // ********************** // Empty per field TABLES // ********************** $filterables = FlexicontentFields::getSearchFields('id', $indexer = 'advanced', null, null, $_load_params = true, 0, $search_type = 'filter'); $filterables = array_keys($filterables); $filterables = array_flip($filterables); $tbl_prefix = $app->getCfg('dbprefix') . 'flexicontent_advsearch_index_field_'; $query = "SELECT TABLE_NAME\n\t\t\tFROM INFORMATION_SCHEMA.TABLES\n\t\t\tWHERE TABLE_NAME LIKE '" . $tbl_prefix . "%'\n\t\t\t"; $this->_db->setQuery($query); $tbl_names = $this->_db->loadColumn(); foreach ($tbl_names as $tbl_name) { $_field_id = str_replace($tbl_prefix, '', $tbl_name); // Drop the table of no longer filterable field if (!isset($filterables[$_field_id])) { $this->_db->setQuery('DROP TABLE IF EXISTS ' . $tbl_name); } else { // Remove item's old advanced search index entries $query = "DELETE FROM " . $tbl_name . " WHERE item_id=" . $item->id; $this->_db->setQuery($query); $this->_db->query(); } } // VERIFY all search tables exist $tbl_names_flipped = array_flip($tbl_names); foreach ($filterables as $_field_id => $_ignored) { $tbl_name = $app->getCfg('dbprefix') . 'flexicontent_advsearch_index_field_' . $_field_id; if (isset($tbl_names_flipped[$tbl_name])) { continue; } $query = ' CREATE TABLE IF NOT EXISTS `' . $tbl_name . '` ( `sid` int(11) NOT NULL auto_increment, `field_id` int(11) NOT NULL, `item_id` int(11) NOT NULL, `extraid` int(11) NOT NULL, `search_index` longtext NOT NULL, `value_id` varchar(255) NULL, PRIMARY KEY (`field_id`,`item_id`,`extraid`), KEY `sid` (`sid`), KEY `field_id` (`field_id`), KEY `item_id` (`item_id`), FULLTEXT `search_index` (`search_index`), KEY `value_id` (`value_id`) ) ENGINE=MyISAM CHARACTER SET `utf8` COLLATE `utf8_general_ci` '; $this->_db->setQuery($query); $this->_db->query(); } // **************************************************************************************************************************** // Loop through Fields triggering onIndexAdvSearch, onIndexSearch Event handlers, this was seperated from the before save field // event, so that we will update search indexes only if the above has not canceled saving OR has not canceled version approval // **************************************************************************************************************************** if ($print_logging_info) { $start_microtime = microtime(true); } $ai_query_vals = array(); $ai_query_vals_f = array(); if ($fields) { foreach ($fields as $field) { $field_type = $field->iscore ? 'core' : $field->field_type; if ($data['vstate'] == 2 || $isnew) { // Trigger plugin Event 'onIndexAdvSearch' to update field-item pair records in advanced search index FLEXIUtilities::call_FC_Field_Func($field_type, 'onIndexAdvSearch', array(&$field, &$postdata[$field->name], &$item)); if (isset($field->ai_query_vals)) { foreach ($field->ai_query_vals as $query_val) { $ai_query_vals[] = $query_val; } if (isset($filterables[$field->id])) { // Current for advanced index only foreach ($field->ai_query_vals as $query_val) { $ai_query_vals_f[$field->id][] = $query_val; } } } //echo $field->name .":".implode(",", @$field->ai_query_vals ? $field->ai_query_vals : array() )."<br/>"; // Trigger plugin Event 'onIndexSearch' to update item 's (basic) search index record FLEXIUtilities::call_FC_Field_Func($field_type, 'onIndexSearch', array(&$field, &$postdata[$field->name], &$item)); if (strlen(@$field->search[$item->id])) { $searchindex[] = $field->search[$item->id]; } //echo $field->name .":".@$field->search[$item->id]."<br/>"; } } } // Remove item's old advanced search index entries $query = "DELETE FROM #__flexicontent_advsearch_index WHERE item_id=" . $item->id; $this->_db->setQuery($query); $this->_db->query(); // Store item's advanced search index entries $queries = array(); if (count($ai_query_vals)) { $queries[] = "INSERT INTO #__flexicontent_advsearch_index " . " (field_id,item_id,extraid,search_index,value_id) VALUES " . implode(",", $ai_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } foreach ($ai_query_vals_f as $_field_id => $_query_vals) { // Current for advanced index only $queries[] = "INSERT INTO #__flexicontent_advsearch_index_field_" . $_field_id . " (field_id,item_id,extraid,search_index,value_id) VALUES " . implode(",", $_query_vals); } foreach ($queries as $query) { $this->_db->setQuery($query); $this->_db->query(); } // Assigned created basic search index into item object $search_prefix = $cparams->get('add_search_prefix') ? 'vvv' : ''; // SEARCH WORD Prefix $item->search_index = implode(' | ', $searchindex); if ($search_prefix && $item->search_index) { $item->search_index = preg_replace('/(\\b[^\\s]+\\b)/', $search_prefix . '$0', trim($item->search_index)); } // Check if vstate was set to 1 (no approve new version) while versioning is disabled if (!$use_versioning && $data['vstate'] != 2) { $data['vstate'] = 2; $app->enqueueMessage('vstate cannot be set to 1 (=no approve new version) when versioning is disabled', 'notice'); } if ($print_logging_info) { @($fc_run_times['fields_value_indexing'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } if ($print_logging_info) { $start_microtime = microtime(true); } // ************************************************************************** // IF new version is approved, remove old version values from the field table // ************************************************************************** if ($data['vstate'] == 2) { //echo "delete __flexicontent_fields_item_relations, item_id: " .$item->id; $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id = ' . $item->id; $this->_db->setQuery($query); $this->_db->query(); $query = 'DELETE FROM #__flexicontent_items_versions WHERE item_id=' . $item->id . ' AND version=' . ((int) $last_version + 1); $this->_db->setQuery($query); $this->_db->query(); $untranslatable_fields = array(); if ($fields) { foreach ($fields as $field) { if ($field->iscore) { continue; } if (count($assoc_item_ids) && $field->untranslatable) { // Delete field values in all translating items, if current field is untranslatable and current item version is approved // NOTE: item itself is not include in associated translations, no need to check for it and skip itit if (!$mval_query) { $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id IN (' . implode(',', $assoc_item_ids) . ') AND field_id=' . $field->id; $this->_db->setQuery($query); $this->_db->query(); } else { $untranslatable_fields[] = $field->id; } } } } if (count($untranslatable_fields)) { $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id IN (' . implode(',', $assoc_item_ids) . ') AND field_id IN (' . implode(',', $untranslatable_fields) . ')'; $this->_db->setQuery($query); $this->_db->query(); } } // ******************************************* // Loop through Fields saving the field values // ******************************************* if ($fields) { // Do not save if versioning disabled or item has no type (version 0) $record_versioned_data = $use_versioning && $item->version; $ver_query_vals = array(); $rel_query_vals = array(); foreach ($fields as $field) { // -- Add the new values to the database $postvalues = $this->formatToArray($postdata[$field->name]); //$qindex_values = $qindex[$field->name]; $i = 1; foreach ($postvalues as $postvalue) { // Create field obj for DB insertion $obj = new stdClass(); $obj->field_id = $field->id; $obj->item_id = $item->id; $obj->valueorder = $i; $obj->suborder = 1; $obj->version = (int) $last_version + 1; $use_ingroup = $field->parameters->get('use_ingroup', 0); // Serialize the properties of the value, normally this is redudant, since the field must have had serialized the parameters of each value already if (!empty($field->use_suborder) && is_array($postvalue)) { $obj->value = null; } else { $obj->value = is_array($postvalue) ? serialize($postvalue) : $postvalue; } //$obj->qindex01 = isset($qindex_values['qindex01']) ? $qindex_values['qindex01'] : NULL; //$obj->qindex02 = isset($qindex_values['qindex02']) ? $qindex_values['qindex02'] : NULL; //$obj->qindex03 = isset($qindex_values['qindex03']) ? $qindex_values['qindex03'] : NULL; // -- a. Add versioning values, but do not version the 'hits' or 'state' or 'voting' fields if ($record_versioned_data && $field->field_type != 'hits' && $field->field_type != 'state' && $field->field_type != 'voting') { // Insert only if value non-empty if (!empty($field->use_suborder) && is_array($postvalue)) { $obj->suborder = 1; foreach ($postvalue as $v) { $obj->value = $v; if (!$mval_query) { $this->_db->insertObject('#__flexicontent_items_versions', $obj); } else { $ver_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->suborder . "," . $obj->version . "," . $this->_db->Quote($obj->value) . ")"; } $obj->suborder++; } unset($v); } else { if (isset($obj->value) && ($use_ingroup || strlen(trim($obj->value)))) { if (!$mval_query) { $this->_db->insertObject('#__flexicontent_items_versions', $obj); } else { $ver_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->suborder . "," . $obj->version . "," . $this->_db->Quote($obj->value) . ")"; } } } } //echo $field->field_type." - ".$field->name." - ".strlen(trim($obj->value))." ".$field->iscore."<br/>"; // -- b. If item is new OR version is approved, AND field is not core (aka stored in the content table or in special table), then add field value to field values table if (($isnew || $data['vstate'] == 2) && !$field->iscore) { // UNSET version it it used only verion data table, and insert only if value non-empty unset($obj->version); if (!empty($field->use_suborder) && is_array($postvalue)) { $obj->suborder = 1; foreach ($postvalue as $v) { $obj->value = $v; if (!$mval_query) { $this->_db->insertObject('#__flexicontent_fields_item_relations', $obj); } else { $rel_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->suborder . "," . $this->_db->Quote($obj->value) . ")"; } $obj->suborder++; } unset($v); } else { if (isset($obj->value) && ($use_ingroup || strlen(trim($obj->value)))) { if (!$mval_query) { $this->_db->insertObject('#__flexicontent_fields_item_relations', $obj); } else { $rel_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->suborder . "," . $this->_db->Quote($obj->value) . ")"; } // Save field value in all translating items, if current field is untranslatable // NOTE: item itself is not include in associated translations, no need to check for it and skip it if (count($assoc_item_ids) && $field->untranslatable) { foreach ($assoc_item_ids as $t_item_id) { //echo "setting Untranslatable value for item_id: ".$t_item_id ." field_id: ".$field->id."<br/>"; $obj->item_id = $t_item_id; if (!$mval_query) { $this->_db->insertObject('#__flexicontent_fields_item_relations', $obj); } else { $rel_query_vals[] = "(" . $obj->field_id . "," . $obj->item_id . "," . $obj->valueorder . "," . $obj->suborder . "," . $this->_db->Quote($obj->value) . ")"; } } } } } } $i++; } } // ********************************************* // Insert values in item fields versioning table // ********************************************* if (count($ver_query_vals)) { $query = "INSERT INTO #__flexicontent_items_versions " . " (field_id,item_id,valueorder,suborder,version,value" . ") VALUES " . "\n" . implode(",\n", $ver_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } // ******************************************* // Insert values in item fields relation table // ******************************************* if (count($rel_query_vals)) { $query = "INSERT INTO #__flexicontent_fields_item_relations " . " (field_id,item_id,valueorder,suborder,value" . ") VALUES " . "\n" . implode(",\n", $rel_query_vals); $this->_db->setQuery($query); $this->_db->query(); if ($this->_db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($this->_db->getErrorMsg()), 'error'); } } // ************************************************************** // Save other versioned item data into the field versioning table // ************************************************************** // a. Save a version of item properties that do not have a corresponding CORE Field if ($record_versioned_data) { $obj = new stdClass(); $obj->field_id = -2; // ID of Fake Field used to contain item properties not having a corresponding CORE field $obj->item_id = $item->id; $obj->valueorder = 1; $obj->suborder = 1; $obj->version = (int) $last_version + 1; $item_data = array(); $iproperties = array('alias', 'catid', 'metadesc', 'metakey', 'metadata', 'attribs', 'urls', 'images'); foreach ($iproperties as $iproperty) { $item_data[$iproperty] = $item->{$iproperty}; } $obj->value = serialize($item_data); $this->_db->insertObject('#__flexicontent_items_versions', $obj); } // b. Finally save a version of the posted JoomFish translated data for J1.5, if such data are editted inside the item edit form /*if ( FLEXI_FISH && !empty($data['jfdata']) && $record_versioned_data ) { $obj = new stdClass(); $obj->field_id = -1; // ID of Fake Field used to contain the Joomfish translated item data $obj->item_id = $item->id; $obj->valueorder = 1; $obj->suborder = 1; $obj->version = (int)$last_version+1; $item_lang = substr($item->language ,0,2); $data['jfdata'][$item_lang]['title'] = $item->title; $data['jfdata'][$item_lang]['alias'] = $item->alias; $data['jfdata'][$item_lang]['text'] = $item->text; $data['jfdata'][$item_lang]['metadesc'] = $item->metadesc; $data['jfdata'][$item_lang]['metakey'] = $item->metakey; $obj->value = serialize($data['jfdata']); $this->_db->insertObject('#__flexicontent_items_versions', $obj); }*/ } if ($print_logging_info) { @($fc_run_times['fields_value_saving'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } // ****************************** // Trigger onAfterSaveField Event // ****************************** if ($fields) { if ($print_logging_info) { $start_microtime = microtime(true); } foreach ($fields as $field) { $field_type = $field->iscore ? 'core' : $field->field_type; $result = FLEXIUtilities::call_FC_Field_Func($field_type, 'onAfterSaveField', array(&$field, &$postdata[$field->name], &$files[$field->name], &$item)); // *** $result is ignored } if ($print_logging_info) { @($fc_run_times['onAfterSaveField_event'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10); } } return true; }
/** * Creates the item submit form * * @since 1.0 */ function _displayForm($tpl) { jimport('joomla.html.parameter'); // ... we use some strings from administrator part // load english language file for 'com_content' component then override with current language file JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR, null, true); // load english language file for 'com_flexicontent' component then override with current language file JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, 'en-GB', true); JFactory::getLanguage()->load('com_flexicontent', JPATH_ADMINISTRATOR, null, true); // ******************************** // Initialize variables, flags, etc // ******************************** $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $document = JFactory::getDocument(); $session = JFactory::getSession(); $user = JFactory::getUser(); $db = JFactory::getDBO(); $uri = JFactory::getURI(); $nullDate = $db->getNullDate(); $menu = $app->getMenu()->getActive(); // We do not have item parameters yet, but we need to do some work before creating the item // Get the COMPONENT only parameter $params = new JRegistry(); $cparams = JComponentHelper::getParams('com_flexicontent'); $params->merge($cparams); // Merge the active menu parameters if ($menu) { $params->merge($menu->params); } // Some flags $enable_translation_groups = flexicontent_db::useAssociations(); //$params->get("enable_translation_groups"); $print_logging_info = $params->get('print_logging_info'); if ($print_logging_info) { global $fc_run_times; } // ***************** // Load JS/CSS files // ***************** FLEXI_J30GE ? JHtml::_('behavior.framework', true) : JHTML::_('behavior.mootools'); flexicontent_html::loadFramework('jQuery'); flexicontent_html::loadFramework('select2'); flexicontent_html::loadFramework('flexi-lib'); // Load custom behaviours: form validation, popup tooltips JHTML::_('behavior.formvalidation'); // load default validation JS to make sure it is overriden JHTML::_('behavior.tooltip'); if (FLEXI_J30GE) { JHtml::_('bootstrap.tooltip'); } //JHTML::_('script', 'joomla.javascript.js', 'includes/js/'); // Add css files to the document <head> section (also load CSS joomla template override) $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/flexicontent.css'); if (file_exists(JPATH_SITE . DS . 'templates' . DS . $app->getTemplate() . DS . 'css' . DS . 'flexicontent.css')) { $document->addStyleSheet($this->baseurl . '/templates/' . $app->getTemplate() . '/css/flexicontent.css'); } // Fields common CSS $document->addStyleSheet($this->baseurl . '/components/com_flexicontent/assets/css/flexi_form_fields.css'); // Load backend / frontend shared and Joomla version specific CSS (different for frontend / backend) FLEXI_J30GE ? $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j3x.css') : $document->addStyleSheet(JURI::base(true) . '/components/com_flexicontent/assets/css/j25.css'); // Add js function to overload the joomla submitform $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/admin.js'); $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/validate.js'); // Add js function for custom code used by FLEXIcontent item form $document->addScript(JURI::base(true) . '/components/com_flexicontent/assets/js/itemscreen.js'); // ********************************************************* // Get item data and create item form (that loads item data) // ********************************************************* if ($print_logging_info) { $start_microtime = microtime(true); } $model = $this->getModel(); // ** WE NEED TO get OR decide the Content Type, before we call the getItem // ** We rely on typeid Request variable to decide type for new items so make sure this is set, // ZERO means allow user to select type, but if user is only allowed a single type, then autoselect it! // Try type from session $jdata = $app->getUserState('com_flexicontent.edit.item.data'); //print_r($jdata); if (!empty($jdata['type_id'])) { JRequest::setVar('typeid', (int) $jdata['type_id']); // This also forces zero if value not set } else { if ($menu && isset($menu->query['typeid'])) { JRequest::setVar('typeid', (int) $menu->query['typeid']); // This also forces zero if value not set } } $new_typeid = JRequest::getVar('typeid', 0, '', 'int'); // Verify type is allowed to the user if (!$new_typeid) { $types = $model->getTypeslist($type_ids_arr = false, $check_perms = true, $_published = true); if ($types && count($types) == 1) { $new_typeid = $types[0]->id; } JRequest::setVar('typeid', $new_typeid); $canCreateType = true; } // FORCE model to load versioned data (URL specified version or latest version (last saved)) $version = JRequest::getVar('version', 0, 'request', 'int'); // Load specific item version (non-zero), 0 version: is unversioned data, -1 version: is latest version (=default for edit form) $item = $model->getItem(null, $check_view_access = false, $no_cache = true, $force_version = $version != 0 ? $version : -1); // -1 version means latest // Replace component/menu 'params' with thee merged component/category/type/item/menu ETC ... parameters $params =& $item->parameters; if ($print_logging_info) { $fc_run_times['get_item_data'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Load permissions (used by form template) $perms = $this->_getItemPerms($item); // Create submit configuration (for new items) into the session, this is needed before creating the item form $submitConf = $this->_createSubmitConf($item, $perms); // Most core field are created via calling methods of the form (J2.5) $form = $this->get('Form'); // is new item and ownership Flags $isnew = !$item->id; $isOwner = $item->created_by == $user->get('id'); // Get available types and the currently selected/requested type $types = $model->getTypeslist(); $typesselected = $model->getTypesselected(); // Get type parameters, these are needed besides the 'merged' item parameters, e.g. to get Type's default layout $tparams = $this->get('Typeparams'); $tparams = new JRegistry($tparams); // ********************************************************************************************************* // Get language stuff, and also load Template-Specific language file to override or add new language strings // ********************************************************************************************************* if ($enable_translation_groups) { $langAssocs = $params->get('uselang_fe') == 1 ? $this->get('LangAssocs') : false; } $langs = FLEXIUtilities::getLanguages('code'); FLEXIUtilities::loadTemplateLanguageFile($params->get('ilayout', 'default')); // ************************************* // Create captcha field via custom logic // ************************************* // create and set (into HTTP request) a unique item id for plugins that needed it if ($item->id) { $unique_tmp_itemid = $item->id; } else { $unique_tmp_itemid = $app->getUserState('com_flexicontent.edit.item.unique_tmp_itemid'); $unique_tmp_itemid = $unique_tmp_itemid ? $unique_tmp_itemid : date('_Y_m_d_h_i_s_', time()) . uniqid(true); } //print_r($unique_tmp_itemid); JRequest::setVar('unique_tmp_itemid', $unique_tmp_itemid); // Component / Menu Item parameters $allowunauthorize = $params->get('allowunauthorize', 0); // allow unauthorised user to submit new content $unauthorized_page = $params->get('unauthorized_page', ''); // page URL for unauthorized users (via global configuration) $notauth_itemid = $params->get('notauthurl', ''); // menu itemid (to redirect) when user is not authorized to create content // Create captcha field or messages // Maybe some code can be removed by using Joomla's built-in form element (in XML file), instead of calling the captcha plugin ourselves $use_captcha = $params->get('use_captcha', 1); // 1 for guests, 2 for any user $captcha_formop = $params->get('captcha_formop', 0); // 0 for submit, 1 for submit/edit (aka always) $display_captcha = $use_captcha >= 2 || $use_captcha == 1 && $user->guest; $display_captcha = $display_captcha && ($isnew || $captcha_formop); // Trigger the configured captcha plugin if ($display_captcha) { // Get configured captcha plugin $c_plugin = $params->get('captcha', $app->getCfg('captcha')); // TODO add param to override default if ($c_plugin) { $c_name = 'captcha_response_field'; $c_id = $c_plugin == 'recaptcha' ? 'dynamic_recaptcha_1' : 'fc_dynamic_captcha'; $c_class = ' required'; $c_namespace = 'fc_item_form'; // Try to load the configured captcha plugin, (check if disabled or uninstalled), Joomla will enqueue an error message if needed $captcha_obj = JCaptcha::getInstance($c_plugin, array('namespace' => $c_namespace)); if ($captcha_obj) { $captcha_field = $captcha_obj->display($c_name, $c_id, $c_class); $label_class = 'flexi_label'; $label_class .= FLEXI_J30GE ? ' hasTooltip' : ' hasTip'; $label_tooltip = flexicontent_html::getToolTip(null, 'FLEXI_CAPTCHA_ENTER_CODE_DESC', 1, 1); $captcha_field = ' <label id="' . $c_name . '-lbl" for="' . $c_name . '" class="' . $label_class . '" title="' . $label_tooltip . '" > ' . JText::_('FLEXI_CAPTCHA_ENTER_CODE') . ' </label> <div id="container_fcfield_' . $c_plugin . '" class="container_fcfield container_fcfield_name_' . $c_plugin . '"> <div class="fcfieldval_container valuebox fcfieldval_container_' . $c_plugin . '"> ' . $captcha_field . ' </div> </div>'; } } } // ******************************* // CHECK EDIT / CREATE PERMISSIONS // ******************************* // User Group / Author parameters $authorparams = flexicontent_db::getUserConfig($user->id); $max_auth_limit = intval($authorparams->get('max_auth_limit', 0)); // maximum number of content items the user can create $hasTmpEdit = false; $hasCoupon = false; // Check session if ($session->has('rendered_uneditable', 'flexicontent')) { $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $hasTmpEdit = !empty($rendered_uneditable[$model->get('id')]); $hasCoupon = !empty($rendered_uneditable[$model->get('id')]) && $rendered_uneditable[$model->get('id')] == 2; // editable via coupon } if (!$isnew) { // EDIT action // Finally check if item is currently being checked-out (currently being edited) if ($model->isCheckedOut($user->get('id'))) { $msg = JText::sprintf('FLEXI_DESCBEINGEDITTED', $model->get('title')); $app->redirect(JRoute::_('index.php?view=' . FLEXI_ITEMVIEW . '&cid=' . $model->get('catid') . '&id=' . $model->get('id'), false), $msg); } //Checkout the item $model->checkout(); // Get edit access, this includes privileges edit and edit-own and the temporary EDIT flag ('rendered_uneditable') $canEdit = $model->getItemAccess()->get('access-edit'); // If no edit privilege, check if edit COUPON was provided if (!$canEdit) { $edittok = JRequest::getCmd('edittok', false); if ($edittok) { $query = 'SHOW TABLES LIKE "' . $app->getCfg('dbprefix') . 'flexicontent_edit_coupons"'; $db->setQuery($query); $tbl_exists = (bool) count($db->loadObjectList()); if ($tbl_exists) { $query = 'SELECT * FROM #__flexicontent_edit_coupons ' . ' WHERE token = ' . $db->Quote($edittok) . ' AND id = ' . $model->get('id'); $db->setQuery($query); $tokdata = $db->loadObject(); if ($tokdata) { $hasCoupon = true; $rendered_uneditable = $session->get('rendered_uneditable', array(), 'flexicontent'); $rendered_uneditable[$model->get('id')] = 2; // 2: indicates, that has edit via EDIT Coupon $session->set('rendered_uneditable', $rendered_uneditable, 'flexicontent'); $canEdit = 1; } else { JError::raiseNotice(403, JText::_('EDIT_TOKEN_IS_INVALID') . ' : ' . $edittok); } } } } // Edit check finished, throw error if needed if (!$canEdit) { if ($user->guest) { $uri = JFactory::getURI(); $return = $uri->toString(); $fcreturn = serialize(array('id' => @$this->_item->id, 'cid' => $cid)); // a special url parameter, used by some SEF code $com_users = FLEXI_J16GE ? 'com_users' : 'com_user'; $url = $params->get('login_page', 'index.php?option=' . $com_users . '&view=login'); $return = strtr(base64_encode($return), '+/=', '-_,'); $url .= '&return=' . $return; //$url .= '&return='.urlencode(base64_encode($return)); $url .= '&fcreturn=' . base64_encode($fcreturn); JError::raiseWarning(403, JText::sprintf("FLEXI_LOGIN_TO_ACCESS", $url)); $app->redirect($url); } else { if ($unauthorized_page) { // unauthorized page via global configuration JError::raiseNotice(403, JText::_('FLEXI_ALERTNOTAUTH_TASK')); $app->redirect($unauthorized_page); } else { // user isn't authorize to edit this content $msg = JText::_('FLEXI_ALERTNOTAUTH_TASK'); if (FLEXI_J16GE) { throw new Exception($msg, 403); } else { JError::raiseError(403, $msg); } } } } } else { // CREATE action // Get create access, this includes check of creating in at least one category, and type's "create items" $canAdd = $model->getItemAccess()->get('access-create'); $not_authorised = !$canAdd; // Check if Content Type can be created by current user if (empty($canCreateType)) { if ($new_typeid) { // not needed, already done be model when type_id is set, check and remove $canCreateType = $model->canCreateType(array($new_typeid)); // Can create given Content Type } else { // needed not done be model yet $canCreateType = $model->canCreateType(); // Can create at least one Content Type } } $not_authorised = $not_authorised || !$canCreateType; // Allow item submission by unauthorized users, ... even guests ... if ($allowunauthorize == 2) { $allowunauthorize = !$user->guest; } if ($not_authorised && !$allowunauthorize) { if (!$canCreateType) { $type_name = isset($types[$new_typeid]) ? '"' . JText::_($types[$new_typeid]->name) . '"' : JText::_('FLEXI_ANY'); $msg = JText::sprintf('FLEXI_NO_ACCESS_CREATE_CONTENT_OF_TYPE', $type_name); } else { $msg = JText::_('FLEXI_ALERTNOTAUTH_CREATE'); } } else { if ($max_auth_limit) { $db->setQuery('SELECT COUNT(id) FROM #__content WHERE created_by = ' . $user->id); $authored_count = $db->loadResult(); $content_is_limited = $authored_count >= $max_auth_limit; $msg = $content_is_limited ? JText::sprintf('FLEXI_ALERTNOTAUTH_CREATE_MORE', $max_auth_limit) : ''; } } if ($not_authorised && !$allowunauthorize || @$content_is_limited) { // User isn't authorize to add ANY content if ($notauth_menu = $app->getMenu()->getItem($notauth_itemid)) { // a. custom unauthorized submission page via menu item $internal_link_vars = @$notauth_menu->component ? '&Itemid=' . $notauth_itemid . '&option=' . $notauth_menu->component : ''; $notauthurl = JRoute::_($notauth_menu->link . $internal_link_vars, false); JError::raiseNotice(403, $msg); $app->redirect($notauthurl); } else { if ($unauthorized_page) { // b. General unauthorized page via global configuration JError::raiseNotice(403, $msg); $app->redirect($unauthorized_page); } else { // c. Finally fallback to raising a 403 Exception/Error that will redirect to site's default 403 unauthorized page if (FLEXI_J16GE) { throw new Exception($msg, 403); } else { JError::raiseError(403, $msg); } } } } } // ***************************************************************************** // Get (CORE & CUSTOM) fields and their VERSIONED values and then // (a) Apply Content Type Customization to CORE fields (label, description, etc) // (b) Create the edit html of the CUSTOM fields by triggering 'onDisplayField' // ***************************************************************************** // Check if saving an item that translates an original content in site's default language $site_default = substr(flexicontent_html::getSiteDefaultLang(), 0, 2); $is_content_default_lang = $site_default == substr($item->language, 0, 2); //$modify_untraslatable_values = $enable_translation_groups && !$is_content_default_lang; // && $item->lang_parent_id && $item->lang_parent_id!=$item->id; if ($print_logging_info) { $start_microtime = microtime(true); } $fields = $this->get('Extrafields'); $item->fields =& $fields; if ($print_logging_info) { $fc_run_times['get_field_vals'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } if ($print_logging_info) { $start_microtime = microtime(true); } $jcustom = $app->getUserState('com_flexicontent.edit.item.custom'); //print_r($jcustom); foreach ($fields as $field) { // a. Apply CONTENT TYPE customizations to CORE FIELDS, e.g a type specific label & description // NOTE: the field parameters are already created so there is not need to call this for CUSTOM fields, which do not have CONTENT TYPE customizations if ($field->iscore) { FlexicontentFields::loadFieldConfig($field, $item); } // b. Create field 's editing HTML (the form field) // NOTE: this is DONE only for CUSTOM fields, since form field html is created by the form for all CORE fields, EXCEPTION is the 'text' field (see bellow) if (!$field->iscore) { if (isset($jcustom[$field->name])) { $field->value = array(); foreach ($jcustom[$field->name] as $i => $_val) { $field->value[$i] = $_val; } } $is_editable = !$field->valueseditable || $user->authorise('flexicontent.editfieldvalues', 'com_flexicontent.field.' . $field->id); if ($is_editable) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayField', array(&$field, &$item)); if ($field->untranslatable) { $field->html = '<div class="alert alert-info fc-small fc-iblock">' . JText::_('FLEXI_FIELD_VALUE_IS_NON_TRANSLATABLE') . '</div>' . "\n" . $field->html; } } else { if ($field->valueseditable == 1) { $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>'; } else { if ($field->valueseditable == 2) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = '<div class="fc-mssg fc-note">' . JText::_($field->parameters->get('no_acc_msg_form') ? $field->parameters->get('no_acc_msg_form') : 'FLEXI_NO_ACCESS_LEVEL_TO_EDIT_FIELD') . '</div>' . "\n" . $field->display; } else { if ($field->valueseditable == 3) { FLEXIUtilities::call_FC_Field_Func($field->field_type, 'onDisplayFieldValue', array(&$field, $item)); $field->html = $field->display; } else { if ($field->valueseditable == 4) { $field->html = ''; $field->formhidden = 4; } } } } } } // c. Create main text field, via calling the display function of the textarea field (will also check for tabs) if ($field->field_type == 'maintext') { if (isset($item->item_translations)) { $shortcode = substr($item->language, 0, 2); foreach ($item->item_translations as $lang_id => $t) { if ($shortcode == $t->shortcode) { continue; } $field->name = array('jfdata', $t->shortcode, 'text'); $field->value[0] = html_entity_decode($t->fields->text->value, ENT_QUOTES, 'UTF-8'); FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); $t->fields->text->tab_labels = $field->tab_labels; $t->fields->text->html = $field->html; unset($field->tab_labels); unset($field->html); } } $field->name = 'text'; // NOTE: We use the text created by the model and not the text retrieved by the CORE plugin code, which maybe overwritten with JoomFish/Falang data $field->value[0] = $item->text; // do not decode special characters this was handled during saving ! // Render the field's (form) HTML FLEXIUtilities::call_FC_Field_Func('textarea', 'onDisplayField', array(&$field, &$item)); } } if ($print_logging_info) { $fc_run_times['render_field_html'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } // Tags used by the item $usedtagsids = $this->get('UsedtagsIds'); // NOTE: This will normally return the already set versioned value of tags ($item->tags) $usedtagsdata = $model->getUsedtagsData($usedtagsids); // Get the edit lists $lists = $this->_buildEditLists($perms, $params, $authorparams); // Get number of subscribers $subscribers = $this->get('SubscribersCount'); // Get menu overridden categories/main category fields $menuCats = $this->_getMenuCats($item, $perms); // Create placement configuration for CORE properties $placementConf = $this->_createPlacementConf($item, $fields); // Item language related vars $languages = FLEXIUtilities::getLanguages(); $itemlang = new stdClass(); $itemlang->shortcode = substr($item->language, 0, 2); $itemlang->name = $languages->{$item->language}->name; $itemlang->image = '<img src="' . @$languages->{$item->language}->imgsrc . '" alt="' . $languages->{$item->language}->name . '" />'; //Load the JEditor object $editor = JFactory::getEditor(); // ********************************************************** // Calculate a (browser window) page title and a page heading // ********************************************************** // Verify menu item points to current FLEXIcontent object if ($menu) { $menu_matches = false; $view_ok = FLEXI_ITEMVIEW == @$menu->query['view'] || 'article' == @$menu->query['view']; $menu_matches = $view_ok; //$menu_params = $menu->params; // Get active menu item parameters } else { $menu_matches = false; } // MENU ITEM matched, use its page heading (but use menu title if the former is not set) if ($menu_matches) { $default_heading = FLEXI_J16GE ? $menu->title : $menu->name; // Cross set (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template) $params->def('page_heading', $params->get('page_title', $default_heading)); $params->def('page_title', $params->get('page_heading', $default_heading)); $params->def('show_page_heading', $params->get('show_page_title', 0)); $params->def('show_page_title', $params->get('show_page_heading', 0)); } else { // Calculate default page heading (=called page title in J1.5), which in turn will be document title below !! ... $default_heading = !$isnew ? JText::_('FLEXI_EDIT') : JText::_('FLEXI_NEW'); // Decide to show page heading (=J1.5 page title), there is no need for this in item view $show_default_heading = 0; // Set both (show_) page_heading / page_title for compatibility of J2.5+ with J1.5 template (and for J1.5 with J2.5 template) $params->set('page_title', $default_heading); $params->set('page_heading', $default_heading); $params->set('show_page_heading', $show_default_heading); $params->set('show_page_title', $show_default_heading); } // ************************************************************ // Create the document title, by from page title and other data // ************************************************************ // Use the page heading as document title, (already calculated above via 'appropriate' logic ...) $doc_title = $params->get('page_title'); // Check and prepend or append site name // Add Site Name to page title if ($app->getCfg('sitename_pagetitles', 0) == 1) { $doc_title = $app->getCfg('sitename') . " - " . $doc_title; } elseif ($app->getCfg('sitename_pagetitles', 0) == 2) { $doc_title = $doc_title . " - " . $app->getCfg('sitename'); } // Finally, set document title $document->setTitle($doc_title); // Add title to pathway $pathway = $app->getPathWay(); $pathway->addItem($doc_title, ''); // Get pageclass suffix $pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx')); // Ensure the row data is safe html // @TODO: check if this is really required as it conflicts with the escape function in the tmpl //JFilterOutput::objectHTMLSafe( $item ); $this->assign('action', $uri->toString()); $this->assignRef('item', $item); $this->assignRef('form', $form); // most core field are created via calling methods of the form (J2.5) if ($enable_translation_groups) { $this->assignRef('lang_assocs', $langAssocs); } $this->assignRef('langs', $langs); $this->assignRef('params', $params); $this->assignRef('lists', $lists); $this->assignRef('subscribers', $subscribers); $this->assignRef('editor', $editor); $this->assignRef('user', $user); $this->assignRef('usedtagsdata', $usedtagsdata); $this->assignRef('fields', $fields); $this->assignRef('tparams', $tparams); $this->assignRef('perms', $perms); $this->assignRef('document', $document); $this->assignRef('nullDate', $nullDate); $this->assignRef('menuCats', $menuCats); $this->assignRef('submitConf', $submitConf); $this->assignRef('placementConf', $placementConf); $this->assignRef('itemlang', $itemlang); $this->assignRef('pageclass_sfx', $pageclass_sfx); $this->assign('captcha_errmsg', @$captcha_errmsg); $this->assign('captcha_field', @$captcha_field); // **************************************************************** // SET INTO THE FORM, parameter values for various parameter groups // **************************************************************** if (JHTML::_('date', $item->publish_down, 'Y') <= 1969 || $item->publish_down == $nullDate) { $item->publish_down = JText::_('FLEXI_NEVER'); } // **************************** // Handle Template related work // **************************** // (a) Get the templates structures used to create form fields for template parameters $themes = flexicontent_tmpl::getTemplates(); $tmpls_all = $themes->items; // (b) Get Content Type allowed templates $allowed_tmpls = $tparams->get('allowed_ilayouts'); $type_default_layout = $tparams->get('ilayout', 'default'); if (empty($allowed_tmpls)) { $allowed_tmpls = array(); } if (!is_array($allowed_tmpls)) { $allowed_tmpls = explode("|", $allowed_tmpls); } // (c) Add default layout, unless all templates allowed (=array is empty) if (count($allowed_tmpls) && !in_array($type_default_layout, $allowed_tmpls)) { $allowed_tmpls[] = $type_default_layout; } // (d) Create array of template data according to the allowed templates for current content type if (count($allowed_tmpls)) { foreach ($tmpls_all as $tmpl) { if (in_array($tmpl->name, $allowed_tmpls)) { $tmpls[] = $tmpl; } } } else { $tmpls = $tmpls_all; } // (e) Apply Template Parameters values into the form fields structures foreach ($tmpls as $tmpl) { if (FLEXI_J16GE) { $jform = new JForm('com_flexicontent.template.item', array('control' => 'jform', 'load_data' => true)); $jform->load($tmpl->params); $tmpl->params = $jform; foreach ($tmpl->params->getGroup('attribs') as $field) { $fieldname = $field->__get('fieldname'); $value = $item->itemparams->get($fieldname); if (strlen($value)) { $tmpl->params->setValue($fieldname, 'attribs', $value); } } } else { $tmpl->params->loadINI($item->attribs); } } $this->assignRef('tmpls', $tmpls); // Clear custom form data from session $app->setUserState($form->option . '.edit.' . $form->context . '.custom', false); $app->setUserState($form->option . '.edit.' . $form->context . '.jfdata', false); $app->setUserState($form->option . '.edit.' . $form->context . '.unique_tmp_itemid', false); if ($print_logging_info) { $start_microtime = microtime(true); } parent::display($tpl); if ($print_logging_info) { $fc_run_times['form_rendering'] = round(1000000 * 10 * (microtime(true) - $start_microtime)) / 10; } }
<?php if ( $this->params->get('enable_translation_groups') ) : ?> <div class="fcclear"></div> <?php if(FLEXI_J30GE){ $label_tooltip = 'class="hasTooltip flexi_label" title="'.JHtml::tooltipText(trim(JText::_('FLEXI_ORIGINAL_CONTENT_ITEM'), ':'), htmlspecialchars(JText::_( 'FLEXI_ORIGINAL_CONTENT_ITEM_DESC' ), ENT_COMPAT, 'UTF-8'), 0).'"'; }else{ $label_tooltip = 'class="hasTip flexi_label" title="'.'::'.htmlspecialchars(JText::_( 'FLEXI_ORIGINAL_CONTENT_ITEM_DESC' ), ENT_COMPAT, 'UTF-8').'"'; } ?> <label id="jform_lang_parent_id-lbl" for="jform_lang_parent_id" <?php echo $label_tooltip; ?> > <?php echo JText::_( 'FLEXI_ORIGINAL_CONTENT_ITEM' );?> </label> <div class="container_fcfield container_fcfield_name_originalitem"> <?php if ( !$isnew && (substr(flexicontent_html::getSiteDefaultLang(), 0,2) == substr($this->item->language, 0,2) || $this->item->language=='*') ) : ?> <br/><?php echo JText::_( $this->item->language=='*' ? 'FLEXI_ORIGINAL_CONTENT_ALL_LANGS' : 'FLEXI_ORIGINAL_TRANSLATION_CONTENT' );?> <input type="hidden" name="jform[lang_parent_id]" id="jform_lang_parent_id" value="<?php echo $this->item->id; ?>" /> <?php else : ?> <?php if ( in_array( 'mod_item_lang', $allowlangmods_fe) || $isnew || $this->item->id==$this->item->lang_parent_id) { $app = JFactory::getApplication(); $option = JRequest::getVar('option'); $app->setUserState( $option.'.itemelement.langparent_item', 1 ); $app->setUserState( $option.'.itemelement.type_id', $typeid); $app->setUserState( $option.'.itemelement.created_by', $this->item->created_by); //echo '<small>'.JText::_( 'FLEXI_ORIGINAL_CONTENT_IGNORED_IF_DEFAULT_LANG' ).'</small><br/>'; echo $this->form->getInput('lang_parent_id'); ?> <span class="editlinktip <?php echo FLEXI_J30GE?'hasTooltip':'hasTip'; ?>" style="display:inline-block;" title="<?php echo FLEXI_J30GE?JHtml::tooltipText(trim(JText::_('FLEXI_NOTES'), ':'), htmlspecialchars(JText::_( 'FLEXI_ORIGINAL_CONTENT_IGNORED_IF_DEFAULT_LANG' ), ENT_COMPAT, 'UTF-8'), 0):htmlspecialchars(JText::_( 'FLEXI_NOTES' ), ENT_COMPAT, 'UTF-8').'::'.htmlspecialchars(JText::_( 'FLEXI_ORIGINAL_CONTENT_IGNORED_IF_DEFAULT_LANG' ), ENT_COMPAT, 'UTF-8'); ?>"> <?php echo $infoimage; ?>
function display($tpl = null) { //initialise variables $app = JFactory::getApplication(); $document = JFactory::getDocument(); $user = JFactory::getUser(); //$authorparams = flexicontent_db::getUserConfig($user->id); //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'); } } //create the toolbar JToolBarHelper::title(JText::_('FLEXI_EDIT_FILE'), 'fileedit'); if (FLEXI_J16GE) { JToolBarHelper::apply('filemanager.apply'); JToolBarHelper::save('filemanager.save'); JToolBarHelper::cancel('filemanager.cancel'); } else { JToolBarHelper::apply(); JToolBarHelper::save(); JToolBarHelper::cancel(); } //Get data from the model $model = $this->getModel(); if (FLEXI_J16GE) { $form = $this->get('Form'); } $row = $this->get('File'); // fail if checked out not by 'me' if ($row->id) { if ($model->isCheckedOut($user->get('id'))) { JError::raiseWarning('SOME_ERROR_CODE', $row->name . ' ' . JText::_('FLEXI_EDITED_BY_ANOTHER_ADMIN')); $app->redirect('index.php?option=com_flexicontent&view=filemanager'); } } //build access level list if (FLEXI_J16GE) { $lists['access'] = JHTML::_('access.assetgrouplist', 'access', $row->access); } else { if (FLEXI_ACCESS) { $lists['access'] = FAccess::TabGmaccess($row, 'field', 1, 0, 0, 0, 0, 0, 0, 0, 0); } else { $lists['access'] = JHTML::_('list.accesslevel', $row); } } // Build languages list //$allowed_langs = !$authorparams ? null : $authorparams->get('langs_allowed',null); //$allowed_langs = !$allowed_langs ? null : FLEXIUtilities::paramToArray($allowed_langs); $allowed_langs = null; if (FLEXI_FISH || FLEXI_J16GE) { $lists['language'] = flexicontent_html::buildlanguageslist('language', '', $row->language, 3, $allowed_langs, $published_only = false); } else { $lists['language'] = flexicontent_html::getSiteDefaultLang() . '<input type="hidden" name="language" value="' . flexicontent_html::getSiteDefaultLang() . '" />'; } //clean data JFilterOutput::objectHTMLSafe($row, ENT_QUOTES); //assign data to template if (FLEXI_J16GE) { $this->assignRef('form', $form); } $this->assignRef('row', $row); $this->assignRef('lists', $lists); $this->assignRef('document', $document); parent::display($tpl); }
/** * 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; } }