function getInput() { $doc = JFactory::getDocument(); $db = JFactory::getDBO(); // Get field configuration if (FLEXI_J16GE) { $node =& $this->element; $attributes = get_object_vars($node->attributes()); $attributes = $attributes['@attributes']; } else { $attributes =& $node->_attributes; } // Get values $values = FLEXI_J16GE ? $this->value : $value; if (empty($values)) { $values = array(); } else { if (!is_array($values)) { $values = !FLEXI_J16GE ? array($values) : explode("|", $values); } } // Field name and HTML tag id $fieldname = FLEXI_J16GE ? $this->name : $control_name . '[' . $name . ']'; $element_id = FLEXI_J16GE ? $this->id : $control_name . $name; // Create options $langs = array(); // Add 'use global' (no value option) if (@$attributes['use_global']) { $langs[] = JHTML::_('select.option', '', JText::_('FLEXI_USE_GLOBAL')); } // Add 'please select' (no value option) if (@$attributes['please_select']) { $langs[] = JHTML::_('select.option', '', JText::_('FLEXI_PLEASE_SELECT')); } $languages = FLEXIUtilities::getlanguageslist(); foreach ($languages as $lang) { $langs[] = JHTML::_('select.option', $lang->code, $lang->name); } // Create HTML tag parameters $attribs = ' style="float:left;" '; if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') { $attribs .= ' multiple="multiple" '; $attribs .= @$attributes['size'] ? ' size="' . @$attributes['size'] . '" ' : ' size="6" '; $fieldname .= !FLEXI_J16GE ? "[]" : ""; // NOTE: this added automatically in J2.5 $maximize_link = "<a style='display:inline-block;" . (FLEXI_J16GE ? 'float:left; margin: 6px 0px 0px 18px;' : 'margin:0px 0px 6px 12px') . "' href='javascript:;' onclick='{$element_id} = document.getElementById(\"{$element_id}\"); if ({$element_id}.size<16) { {$element_id}_oldsize={$element_id}.size; {$element_id}.size=16;} else { {$element_id}.size={$element_id}_oldsize; } ' >Maximize/Minimize</a>"; } else { $attribs .= 'class="inputbox"'; $maximize_link = ''; } if ($onchange = @$attributes['onchange']) { $attribs .= ' onchange="' . $onchange . '"'; } // Render the field's HTML $html = JHTML::_('select.genericlist', $langs, $fieldname, $attribs, 'value', 'text', $values, $element_id); return $html . $maximize_link; }
function getInput() { $doc = JFactory::getDocument(); $db = JFactory::getDBO(); // Get field configuration $node =& $this->element; $attributes = get_object_vars($node->attributes()); $attributes = $attributes['@attributes']; // Get values $values = $this->value; if (empty($values)) { $values = array(); } else { if (!is_array($values)) { $values = explode("|", $values); } } // Field name and HTML tag id $fieldname = $this->name; $element_id = $this->id; // Create options $langs = array(); // Add 'use global' (no value option) if (@$attributes['use_global']) { $langs[] = JHTML::_('select.option', '', JText::_('FLEXI_USE_GLOBAL')); } // Add 'please select' (no value option) if (@$attributes['please_select']) { $langs[] = JHTML::_('select.option', '', JText::_('FLEXI_PLEASE_SELECT')); } foreach ($node->children() as $option) { $val = $option->attributes()->value; $text = JText::_(FLEXI_J30GE ? $option->__toString() : $option->data()); $langs[] = JHTML::_('select.option', $val, $text); } $languages = FLEXIUtilities::getlanguageslist(); foreach ($languages as $lang) { $langs[] = JHTML::_('select.option', $lang->code, $lang->name); } // Create HTML tag parameters $attribs = ''; $classes = 'use_select2_lib'; if (@$attributes['multiple'] == 'multiple' || @$attributes['multiple'] == 'true') { $attribs .= ' multiple="multiple" '; $attribs .= @$attributes['size'] ? ' size="' . @$attributes['size'] . '" ' : ' size="6" '; } if ($onchange = @$attributes['onchange']) { $attribs .= ' onchange="' . $onchange . '"'; } $attribs .= ' class="' . $classes . '" '; // Render the field's HTML return JHTML::_('select.genericlist', $langs, $fieldname, $attribs, 'value', 'text', $values, $element_id); }
/** * Method to build an array of languages hashed by id or by language code * * @return object * @since 1.5 */ static function getLanguages($hash = 'code', $published_only = false) { static $langs = array(); static $languages; if (isset($langs[$hash])) { return $langs[$hash]; } if (!$languages) { $languages = FLEXIUtilities::getlanguageslist($published_only); } $langs[$hash] = new stdClass(); foreach ($languages as $language) { $langs[$hash]->{$language->{$hash}} = $language; } return $langs[$hash]; }
/** * Method to load item data * * @access private * @return boolean True on success * @since 1.0 */ function _loadItem($no_cache = false, $force_version = false) { if (!$this->_id) { return false; } // Only try to load existing item // Cache items retrieved, we can retrieve multiple items, for this purpose // (a) temporarily set JRequest variable -version- to specify loaded version (set to zero to use latest ) // (b1) use member function function setId($id, $currcatid=0) to change primary key and then call getItem() // (b2) or call getItem($pk, $check_view_access=true) passing the item id and maybe also disabling read access checkings, to avoid unwanted messages/errors static $items = array(); if ($no_cache) { // Clear item to make sure it is reloaded $this->_item = null; } else { if (isset($items[$this->_id])) { $this->_item =& $items[$this->_id]; return (bool) $this->_item; } } static $unapproved_version_notice; $db = $this->_db; $app = JFactory::getApplication(); $user = JFactory::getUser(); $cparams = $this->_cparams; $task = JRequest::getVar('task', false); $layout = JRequest::getVar('layout', false); $view = JRequest::getVar('view', false); $option = JRequest::getVar('option', false); $use_versioning = $cparams->get('use_versioning', 1); $allow_current_version = true; $editjf_translations = $cparams->get('editjf_translations', 0); // ********************************************************************************************************* // Retrieve item if not already retrieved, null indicates cleared item data, e.g. because of changed item id // ********************************************************************************************************* if ($this->_item === null) { //***************************************************** // DECIDE VERSION and GENERATE VERSION RELATED MESSAGES //***************************************************** // Variables controlling the version loading logic $loadcurrent = JRequest::getVar('loadcurrent', false, 'request', 'boolean'); // loadcurrent request flag, ignored if version specified $preview = JRequest::getVar('preview', false, 'request', 'boolean'); // preview request flag for viewing latest (and possibly unapproved) version in frontend $version = JRequest::getVar('version', 0, 'request', 'int'); // the item version to load // -- Decide the version to load: (a) the one specified by request or (b) the current one or (c) the latest one $current_version = FLEXIUtilities::getCurrentVersions($this->_id, true, $force = true); // Get current item version $last_version = FLEXIUtilities::getLastVersions($this->_id, true, $force = true); // Get last version (=latest one saved, highest version id), // NOTE: Setting version to zero indicates to load the current version from the normal tables and not the versioning table if (!$use_versioning) { // Force version to zero (load current version), when not using versioning mode $version = 0; } else { if ($force_version !== false) { $version = $force_version == -1 ? $last_version : $force_version; } else { if ($version == 0) { // version request variable was NOT SET ... We need to decide to load current (version zero) or latest if ($app->isAdmin() || $task == 'edit' && $option == 'com_flexicontent') { // Catch cases (a) when we enable versioning mode after an item has been saved in unversioning mode, (b) loadcurrent flag is set // in these case we will load CURRENT version instead of the default for the item edit form which is the LATEST (for backend/fontend) $version = $current_version >= $last_version || $loadcurrent ? 0 : $last_version; } else { // In frontend item display the current version must be shown unless preview flag is set $version = !$preview ? 0 : $last_version; } } else { if ($version == $current_version) { // Current version number given, the data from the versioning table should be the same as the data from normal tables // we do not force $version to ZERO to allow testing the field data of current version from the versioning table if (!$allow_current_version) { $version = 0; } // Force zero to retrieve unversioned data } } } } // Check if not loading the current version while we are in edit form, and raise a notice to inform the user if ($version && $version != $current_version && $task == 'edit' && $option == 'com_flexicontent' && !$unapproved_version_notice) { $unapproved_version_notice = 1; if (!$app->isAdmin()) { JError::raiseNotice(10, JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE')); } else { JError::raiseNotice(10, JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE') . ' :: ' . JText::sprintf('FLEXI_LOADED_VERSION_INFO_NOTICE', $version, $current_version)); } } try { if ($app->isAdmin()) { // ********************** // Item Retrieval BACKEND // ********************** $item = $this->getTable('flexicontent_items', ''); $result = $item->load($this->_id); // try loading existing item data if ($result === false) { return false; } } else { // *********************** // Item Retrieval FRONTEND // *********************** // Tables needed to be joined for calculating access $joinaccess = ''; // Extra access columns for main category and content type (item access will be added as 'access') $select_access = 'mc.access as category_access, ty.access as type_access'; // Access Flags for: content type, main category, item if (FLEXI_J16GE) { $aid_arr = JAccess::getAuthorisedViewLevels($user->id); $aid_list = implode(",", $aid_arr); $select_access .= ', CASE WHEN ty.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_type_access'; $select_access .= ', CASE WHEN mc.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_mcat_access'; $select_access .= ', CASE WHEN i.access IN (0,' . $aid_list . ') THEN 1 ELSE 0 END AS has_item_access'; } else { $aid = (int) $user->get('aid'); if (FLEXI_ACCESS) { $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gt ON ty.id = gt.axo AND gt.aco = "read" AND gt.axosection = "type"'; $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gc ON mc.id = gc.axo AND gc.aco = "read" AND gc.axosection = "category"'; $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gi ON i.id = gi.axo AND gi.aco = "read" AND gi.axosection = "item"'; $select_access .= ', CASE WHEN (gt.aro IN ( ' . $user->gmid . ' ) OR ty.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_type_access'; $select_access .= ', CASE WHEN (gc.aro IN ( ' . $user->gmid . ' ) OR mc.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_mcat_access'; $select_access .= ', CASE WHEN (gi.aro IN ( ' . $user->gmid . ' ) OR i.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_item_access'; } else { $select_access .= ', CASE WHEN (ty.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_type_access'; $select_access .= ', CASE WHEN (mc.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_mcat_access'; $select_access .= ', CASE WHEN ( i.access <= ' . (int) $aid . ') THEN 1 ELSE 0 END AS has_item_access'; } $select_access .= ', '; } // SQL date strings, current date and null date $nowDate = $db->Quote(FLEXI_J16GE ? JFactory::getDate()->toSql() : JFactory::getDate()->toMySQL()); $nullDate = $db->Quote($db->getNullDate()); // Decide to limit to CURRENT CATEGORY $limit_to_cid = $this->_cid ? ' AND rel.catid = ' . (int) $this->_cid : ' AND rel.catid = i.catid'; if (FLEXI_J16GE) { // Initialize query $query = $db->getQuery(true); $query->select('i.*, ie.*'); // Item basic and extended data $query->select($select_access); // Access Columns and Access Flags for: content type, main category, item if ($version) { $query->select('ver.version_id'); } // Versioned item viewing $query->select('c.id AS catid, i.catid as maincatid'); // Current category id and Main category id $query->select('c.title AS category_title, c.alias AS category_alias, c.lft,c.rgt'); // Current category data $query->select('ty.name AS typename, ty.alias as typealias'); // Content Type data, and author data $query->select('u.name AS author'); // Author data // Rating count, Rating & Score $query->select('v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score'); // Item and Current Category slugs (for URL) $query->select('CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug'); $query->select('CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug'); // Publication Scheduled / Expired Flags $query->select('CASE WHEN i.publish_up = ' . $nullDate . ' OR i.publish_up <= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_scheduled'); $query->select('CASE WHEN i.publish_down = ' . $nullDate . ' OR i.publish_down >= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_expired'); // From content table, and extended item table, content type table, user table, rating table, categories relation table $query->from('#__content AS i'); $query->join('LEFT', '#__flexicontent_items_ext AS ie ON ie.item_id = i.id'); $query->join('LEFT', '#__flexicontent_types AS ty ON ie.type_id = ty.id'); $query->join('LEFT', '#__users AS u on u.id = i.created_by'); $query->join('LEFT', '#__content_rating AS v ON i.id = v.content_id'); $query->join('LEFT', '#__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . $limit_to_cid); // Join twice on category table, once for current category and once for item's main category $query->join('LEFT', '#__categories AS c on c.id = rel.catid'); // All item's categories $query->join('LEFT', '#__categories AS mc on mc.id = i.catid'); // Item's main category // HANDLE J1.6+ ancestor category being unpublished, when badcats.id is not null, // then the item is inside in an unpublished ancestor category, thus inaccessible /*$query->select('CASE WHEN badcats.id is null THEN 1 ELSE 0 END AS ancestor_cats_published'); $subquery = ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent '; $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt '; $subquery .= 'WHERE parent.extension = ' . $db->Quote('com_content'); $subquery .= ' AND parent.published <= 0 GROUP BY cat.id)'; $query->join('LEFT', $subquery . ' AS badcats ON badcats.id = c.id');*/ if ($version) { // NOTE: version_id is used by field helper file to load the specified version, the reason for left join here is to verify that the version exists $query->join('LEFT', '#__flexicontent_versions AS ver ON ver.item_id = i.id AND ver.version_id = ' . $db->Quote($version)); } // Join on contact table, to get contact data of author //$query = 'SHOW TABLES LIKE "' . JFactory::getApplication()->getCfg('dbprefix') . 'contact_details"'; //$db->setQuery($query); //$contact_details_tbl_exists = (boolean) count($db->loadObjectList()); //if ( $contact_details_tbl_exists) { // $query->select('contact.id as contactid' ) ; // $query->join('LEFT','#__contact_details AS contact on contact.user_id = i.created_by'); //} // Join over the categories to get parent category titles //$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); //$query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); $query->where('i.id = ' . (int) $this->_id); //echo $db->replacePrefix($query); } else { // NOTE: version_id is used by field helper file to load the specified version, the reason for left join here is to verify that the version exists $version_join = $version ? ' LEFT JOIN #__flexicontent_versions AS ver ON ver.item_id = i.id AND ver.version_id = ' . $db->Quote($version) : ''; $where = $this->_buildItemWhere(); $query = 'SELECT i.*, ie.*, ' . $select_access . ($version ? 'ver.version_id,' : '') . ' c.id AS catid, i.catid as maincatid,' . ' c.published AS catpublished,' . ' c.title AS category_title, c.alias AS category_alias,' . ' ty.name as typename, ty.alias as typealias,' . ' u.name AS author, u.usertype,' . ' v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score,' . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug,' . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug,' . ' CASE WHEN i.publish_up = ' . $nullDate . ' OR i.publish_up <= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_scheduled,' . ' CASE WHEN i.publish_down = ' . $nullDate . ' OR i.publish_down >= ' . $nowDate . ' THEN 0 ELSE 1 END as publication_expired' . ' FROM #__content AS i' . ' LEFT JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id' . ' LEFT JOIN #__flexicontent_types AS ty ON ie.type_id = ty.id' . ' LEFT JOIN #__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . $limit_to_cid . ' LEFT JOIN #__categories AS c ON c.id = rel.catid' . ' LEFT JOIN #__categories AS mc ON mc.id = i.catid' . ' LEFT JOIN #__users AS u ON u.id = i.created_by' . ' LEFT JOIN #__content_rating AS v ON i.id = v.content_id' . $joinaccess . $version_join . $where; } $db->setQuery($query); // Try to execute query directly and load the data as an object if (FLEXI_FISH && $task == 'edit' && $option == 'com_flexicontent' && in_array($app->getCfg('dbtype'), array('mysqli', 'mysql'))) { $data = flexicontent_db::directQuery($query); $data = @$data[0]; //$data = $db->loadObject(null, false); // do not, translate, this is the JoomFish overridden method of Database extended Class } else { $data = $db->loadObject(); } // Check for SQL error if ($db->getErrorNum()) { if (FLEXI_J16GE) { throw new Exception($db->getErrorMsg(), 500); } else { JError::raiseError(500, $db->getErrorMsg()); } } //print_r($data); exit; if (!$data) { return false; } // item not found, return if ($version && !$data->version_id) { JError::raiseNotice(10, JText::sprintf('NOTICE: Requested item version %d was not found', $version)); } $item =& $data; } // -- Create the description field called 'text' by appending introtext + readmore + fulltext $item->text = $item->introtext; $item->text .= JString::strlen(trim($item->fulltext)) ? '<hr id="system-readmore" />' . $item->fulltext : ""; //echo "<br/>Current version (Frontend Active): " . $item->version; //echo "<br/>Version to load: ".$version; //echo "<br/><b> *** db title:</b> ".$item->title; //echo "<br/><b> *** db text:</b> ".$item->text; //echo "<pre>*** item data: "; print_r($item); echo "</pre>"; exit; // Set number of loaded version, IMPORTANT: zero means load unversioned data JRequest::setVar('version', $version); // ************************************************************************************************* // -- Retrieve all active site languages, and create empty item translation objects for each of them // ************************************************************************************************* $nn_content_tbl = FLEXI_J16GE ? 'falang_content' : 'jf_content'; if (FLEXI_FISH) { $site_languages = FLEXIUtilities::getlanguageslist(); $item_translations = new stdClass(); foreach ($site_languages as $lang_id => $lang_data) { if (!$lang_id && $item->language != '*') { continue; } $lang_data->fields = new stdClass(); $item_translations->{$lang_id} = $lang_data; } } // ********************************** // Retrieve and prepare JoomFish data // ********************************** if (FLEXI_FISH && $task == 'edit' && $option == 'com_flexicontent') { // -- Try to retrieve all joomfish data for the current item $query = "SELECT jfc.language_id, jfc.reference_field, jfc.value, jfc.published " . " FROM #__" . $nn_content_tbl . " as jfc " . " WHERE jfc.reference_table='content' AND jfc.reference_id = {$this->_id} "; $db->setQuery($query); $translated_fields = $db->loadObjectList(); if ($editjf_translations == 0 && $translated_fields) { // 1:disable without warning about found translations $app->enqueueMessage("3rd party Joom!Fish/Falang translations detected for current item." . " You can either enable editing them or disable this message in FLEXIcontent component configuration", 'message'); } else { if ($editjf_translations == 2) { if ($db->getErrorNum()) { JFactory::getApplication()->enqueueMessage(__FUNCTION__ . '(): SQL QUERY ERROR:<br/>' . nl2br($db->getErrorMsg()), 'error'); } // -- Parse translation data according to their language if ($translated_fields) { // Add retrieved translated item properties foreach ($translated_fields as $field_data) { $item_translations->{$field_data->language_id}->fields->{$field_data->reference_field} = new stdClass(); $item_translations->{$field_data->language_id}->fields->{$field_data->reference_field}->value = $field_data->value; $found_languages[$field_data->language_id] = $item_translations->{$field_data->language_id}->name; } //echo "<br/>Joom!Fish translations found for: " . implode(",", $found_languages); } foreach ($item_translations as $lang_id => $translation_data) { // Default title can be somewhat long, trim it to first word, so that it is more suitable for tabs list($translation_data->name) = explode(' ', trim($translation_data->name)); // Create text field value for all languages $translation_data->fields->text = new stdClass(); $translation_data->fields->text->value = @$translation_data->fields->introtext->value; if (JString::strlen(trim(@$translation_data->fields->fulltext->value))) { $translation_data->fields->text->value .= '<hr id="system-readmore" />' . @$translation_data->fields->fulltext->value; } } $item->item_translations =& $item_translations; } } } //echo "<pre>"; print_r($item->item_translations); exit; // ***************************************************** // Overwrite item fields with the requested VERSION data // ***************************************************** $item->current_version = $current_version; $item->last_version = $last_version; if ($use_versioning && $version) { // Overcome possible group concat limitation $query = "SET SESSION group_concat_max_len = 9999999"; $db->setQuery($query); $db->query(); $query = "SELECT f.id, f.name, f.field_type, GROUP_CONCAT(iv.value SEPARATOR ',') as value, count(f.id) as valuecount, iv.field_id" . " FROM #__flexicontent_items_versions as iv " . " LEFT JOIN #__flexicontent_fields as f on f.id=iv.field_id" . " WHERE iv.version='" . $version . "' AND (f.iscore=1 OR iv.field_id=-1 OR iv.field_id=-2) AND iv.item_id='" . $this->_id . "'" . " GROUP BY f.id"; $db->setQuery($query); $fields = $db->loadObjectList(); $fields = $fields ? $fields : array(); //echo "<br/>Overwritting fields with version: $version"; foreach ($fields as $f) { //echo "<br/><b>{$f->field_id} : ". $f->name."</b> : "; print_r($f->value); // Use versioned data, by overwriting the item data $fieldname = $f->name; if ($f->field_type == 'hits' || $f->field_type == 'state' || $f->field_type == 'voting') { // skip fields that should not have been versioned: hits, state, voting continue; } else { if ($f->field_type == 'version') { // set version variable to indicate the loaded version $item->version = $version; } else { if ($fieldname == 'categories' || $fieldname == 'tags') { // categories and tags must have been serialized but some earlier versions did not do it, // we will check before unserializing them, otherwise they were concatenated to a single string and use explode ... $item->{$fieldname} = ($array = @unserialize($f->value)) ? $array : explode(",", $f->value); } else { if ($f->field_id == -1) { if (FLEXI_FISH) { $jfdata = unserialize($f->value); $item_lang = substr($item->language, 0, 2); foreach ($item_translations as $lang_id => $translation_data) { //echo "<br/>Adding values for: ".$translation_data->shortcode; if (empty($jfdata[$translation_data->shortcode])) { continue; } foreach ($jfdata[$translation_data->shortcode] as $fieldname => $fieldvalue) { //echo "<br/>".$translation_data->shortcode.": $fieldname => $fieldvalue"; if ($translation_data->shortcode != $item_lang) { $translation_data->fields->{$fieldname} = new stdClass(); $translation_data->fields->{$fieldname}->value = $fieldvalue; } else { $item->{$fieldname} = $fieldvalue; } } } } } else { if ($f->field_id == -2) { // Other item properties that were versioned, such as alias, catid, meta params, attribs $item_data = unserialize($f->value); //$item->bind($item_data); foreach ($item_data as $k => $v) { $item->{$k} = $v; } } else { if ($fieldname) { // Other fields (maybe serialized or not but we do not unserialized them, this is responsibility of the field itself) $item->{$fieldname} = $f->value; } } } } } } } // The text field is stored in the db as to seperate fields: introtext & fulltext // So we search for the {readmore} tag and split up the text field accordingly. $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; $tagPos = preg_match($pattern, $item->text); if ($tagPos == 0) { $item->introtext = $item->text; $item->fulltext = ''; } else { list($item->introtext, $item->fulltext) = preg_split($pattern, $item->text, 2); $item->fulltext = JString::strlen(trim($item->fulltext)) ? $item->fulltext : ''; } } // -- Retrieve tags field value (if not using versioning) if ($use_versioning && $version) { // Check version value was found if (!isset($item->tags) || !is_array($item->tags)) { $item->tags = array(); } } else { // Retrieve unversioned value $query = 'SELECT DISTINCT tid FROM #__flexicontent_tags_item_relations WHERE itemid = ' . (int) $this->_id; $db->setQuery($query); $item->tags = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray(); } // -- Retrieve categories field value (if not using versioning) if ($use_versioning && $version) { // Check version value was found, and is valid (above code should have produced an array) if (!isset($item->categories) || !is_array($item->categories)) { $item->categories = array(); } } else { $query = 'SELECT DISTINCT catid FROM #__flexicontent_cats_item_relations WHERE itemid = ' . (int) $this->_id; $db->setQuery($query); $item->categories = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray(); } // Make sure catid is in categories array if (!in_array($item->catid, $item->categories)) { $item->categories[] = $item->catid; } // 'cats' is an alias of categories $item->cats =& $item->categories; // ********************************************************* // Retrieve item properties not defined in the model's CLASS // ********************************************************* if (FLEXI_J16GE) { $query = 'SELECT title FROM #__viewlevels WHERE id = ' . (int) $item->access; } else { $query = 'SELECT name FROM #__groups WHERE id = ' . (int) $item->access; } $db->setQuery($query); $item->access_level = $db->loadResult(); // Category access is retrieved here for J1.6+, for J1.5 we use FLEXIaccess if (FLEXI_J16GE) { // Get category access for the item's main category, used later to determine viewing of the item $query = 'SELECT access FROM #__categories WHERE id = ' . (int) $item->catid; $db->setQuery($query); $item->category_access = $db->loadResult(); } // Typecast some properties in case LEFT JOIN returned nulls if (!isset($item->type_access)) { $public_acclevel = !FLEXI_J16GE ? 0 : 1; $item->type_access = $public_acclevel; } if (!isset($item->rating_count)) { // Get category access for the item's main category, used later to determine viewing of the item $query = 'SELECT ' . ' v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score' . ' FROM #__content_rating AS v WHERE v.content_id = ' . (int) $item->id; $db->setQuery($query); $rating_data = $db->loadObject(); $item->rating_count = !$rating_data ? 0 : $rating_data->rating_count; $item->rating = !$rating_data ? 0 : $rating_data->rating_count; $item->score = !$rating_data ? 0 : $rating_data->score; } $item->typename = (string) @$item->typename; $item->typealias = (string) @$item->typealias; // Retrieve Creator NAME and email (used to display the gravatar) $query = 'SELECT name, email FROM #__users WHERE id = ' . (int) $item->created_by; $db->setQuery($query); $creator_data = $db->loadObject(); $item->creator = $creator_data ? $creator_data->name : ''; $item->creatoremail = $creator_data ? $creator_data->email : ''; // Retrieve Modifier NAME if ($item->created_by == $item->modified_by) { $item->modifier = $item->creator; } else { $query = 'SELECT name, email FROM #__users WHERE id = ' . (int) $item->modified_by; $db->setQuery($query); $modifier_data = $db->loadObject(); $item->modifier = $modifier_data ? $modifier_data->name : ''; $item->modifieremail = $modifier_data ? $modifier_data->email : ''; } // Clear modified Date, if it is an invalid "null" date if ($item->modified == $db->getNulldate()) { $item->modified = null; } // ******************************************************** // Assign to the item data member variable and cache it too // ******************************************************** $this->_item =& $item; $items[$this->_id] =& $this->_item; // ****************************************************************************************************** // Detect if current version doesnot exist in version table and add it !!! e.g. after enabling versioning // ****************************************************************************************************** if ($use_versioning && $current_version > $last_version) { require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_flexicontent' . DS . 'models' . DS . 'flexicontent.php'; $fleximodel = new FlexicontentModelFlexicontent(); $fleximodel->addCurrentVersionData($item->id); } // return true if item was loaded successfully return (bool) $this->_item; } catch (JException $e) { if ($e->getCode() == 404) { // Need to go thru the error handler to allow Redirect to work. $msg = $e->getMessage(); if (FLEXI_J16GE) { throw new Exception($msg, 404); } else { JError::raiseError(404, $msg); } } else { $this->setError($e); $this->_item = false; } } } else { $items[$this->_id] =& $this->_item; } /*$session = JFactory::getSession(); $postdata = $session->get('item_edit_postdata', array(), 'flexicontent'); if (count($postdata)) { $session->set('item_edit_postdata', null, 'flexicontent'); // ... }*/ return true; }