/com_flexicontent_v2.x/admin/models/parentclassitem.php
PHP | 4248 lines | 2613 code | 598 blank | 1037 comment | 722 complexity | 33eff71428c84317ac5d14df569ef3b9 MD5 | raw file
Possible License(s): MIT, GPL-2.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * @version 1.5 stable $Id: item.php 1244 2012-04-12 05:07:35Z ggppdk $
- * @package Joomla
- * @subpackage FLEXIcontent
- * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
- * @license GNU/GPL v2
- *
- * FLEXIcontent is a derivative work of the excellent QuickFAQ component
- * @copyright (C) 2008 Christoph Lukes
- * see www.schlu.net for more information
- *
- * FLEXIcontent is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
- // no direct access
- defined( '_JEXEC' ) or die( 'Restricted access' );
-
- jimport( 'joomla.application.component.modeladmin' );
- jimport( 'joomla.html.parameter' );
- /**
- * FLEXIcontent Component Item Model
- *
- * @package Joomla
- * @subpackage FLEXIcontent
- * @since 1.0
- */
- class ParentClassItem extends JModelAdmin
- {
- var $_name = 'ParentClassItem';
-
- /**
- * Component parameters
- *
- * @var object
- */
- var $_cparams = null;
-
- /**
- * Item data
- *
- * @var object
- */
- var $_item = null;
-
- /**
- * Item primary key
- *
- * @var int
- */
- var $_id = null;
-
- /**
- * Item current category id (used for FRONTEND only)
- *
- * @var int
- */
- var $_cid = null;
-
- /**
- * Item version of loaded data
- *
- * @var int
- */
- var $_version = null;
-
- /**
- * Associated item translations
- *
- * @var array
- */
- var $_translations = null;
-
- /**
- * Constructor
- *
- * @since 1.0
- */
- public function __construct()
- {
- parent::__construct();
-
- $app = JFactory::getApplication();
-
- // --. Get component parameters , merge (for frontend) with current menu item parameters
- $this->_cparams = clone( JComponentHelper::getParams('com_flexicontent') );
- if (!$app->isAdmin()) {
- $menu = $app->getMenu()->getActive();
- if ($menu) {
- $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);
- $this->_cparams->merge($menu_params);
- }
- }
-
- // --. Get & Set ITEM's primary key (pk) and (for frontend) the current category
- if (!$app->isAdmin()) {
- // FRONTEND, use "id" from request
- $pk = JRequest::getVar('id', 0, 'default', 'int');
- if ( !JRequest::getVar('task') )
- $curcatid = JRequest::getVar('cid', 0, $hash='default', 'int');
- else
- $curcatid = 0;
- }
- else
- {
- // BACKEND, use "cid" array from request, but check first for a POST 'id' variable
- // this is a correction for problematic name of categories AS cid in item edit form ...
- $data = JRequest::get( 'post' );
-
- // Must check if id is SET and if it is non-ZERO !
- if ( FLEXI_J16GE ? isset($data['jform']['id']) : isset($data['id']) ) {
- $pk = FLEXI_J16GE ? $data['jform']['id'] : $data['id'];
- } else {
- $cid = JRequest::getVar( 'cid', array(0), $hash='default', 'array' );
- JArrayHelper::toInteger($cid, array(0));
- $pk = $cid[0];
- }
- $curcatid = 0;
- }
- $this->setId($pk, $curcatid); // NOTE: when setting $pk to a new value the $this->_item is cleared
-
- $this->populateState();
- }
-
- /**
- * Method to set the identifier
- *
- * @access public
- * @param int item identifier
- */
- function setId($id, $currcatid=0)
- {
- // Set a new item id and wipe data
- if ($this->_id != $id) {
- $this->_item = null;
- }
- $this->_id = (int) $id;
-
- // Set current category, but verify item is assigned to this category, (SECURITY concern)
- $this->_cid = (int) $currcatid;
- if ($this->_cid) {
- $q = "SELECT catid FROM #__flexicontent_cats_item_relations WHERE itemid =". (int)$this->_id ." AND catid = ". (int)$this->_cid;
- $this->_db->setQuery($q);
- $result = $this->_db->loadResult();
- $this->_cid = $result ? $this->_cid : 0; // Clear cid, if category not assigned to the item
- }
- }
-
-
- /**
- * Method to get the identifier
- *
- * @access public
- * @return int item identifier
- */
- function getId()
- {
- return $this->_id;
- }
-
-
- /**
- * Overridden get method to get properties from the item
- *
- * @access public
- * @param string $property The name of the property
- * @param mixed $value The value of the property to set
- * @return mixed The value of the property
- * @since 1.5
- */
- function get($property, $default=null)
- {
- if ($this->_item || $this->_loadItem()) {
- if(isset($this->_item->$property)) {
- return $this->_item->$property;
- }
- }
- return $default;
- }
-
-
- /**
- * Overridden set method to pass properties on to the item
- *
- * @access public
- * @param string $property The name of the property
- * @param mixed $value The value of the property to set
- * @return boolean True on success
- * @since 1.5
- */
- function set( $property, $value=null )
- {
- if ( $this->_loadItem() ) {
- $this->_item->$property = $value;
- return true;
- } else {
- return false;
- }
- }
-
-
- /**
- * Method to get item data
- *
- * @access public
- * @return array
- * @since 1.0
- */
- function &getItem($pk=null, $check_view_access=true, $no_cache=false, $force_version=false)
- {
- $app = JFactory::getApplication();
- $cparams = $this->_cparams;
- $preview = JRequest::getVar('preview');
-
- // View access done is meant only for FRONTEND !!! ... force it to false
- if ( $app->isAdmin() ) $check_view_access = false;
-
- // Initialise and set primary if it was not given already
- $pk = !empty($pk) ? $pk : $this->_id;
- if (FLEXI_J16GE) {
- $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName().'.id');
- }
-
- // Set new item id, clearing item data, ONLY IF DIFFERENT than existing primary key
- if ($pk != $this->_id) {
- $this->setId($pk);
- }
-
- // --. Try to load existing item
- if ( $pk && $this->_loadItem($no_cache, $force_version) )
- {
- // Successfully loaded existing item, do some extra manipulation of the loaded item ...
- // Extra Steps for Frontend
- if ( !$app->isAdmin() ) {
- // Load item parameters with heritage
- $this->_loadItemParams();
- // Check item viewing access
- if ( $check_view_access ) $this->_check_viewing_access();
- }
- }
-
- // --. Failed to load existing item, or check_view_access indicates not to create a new item object
- else if ( $pk || $check_view_access===2 )
- {
- $msg = JText::sprintf('FLEXI_CONTENT_UNAVAILABLE_ITEM_NOT_FOUND', $pk);
- if (FLEXI_J16GE) throw new Exception($msg, 404); else JError::raiseError(404, $msg);
- }
-
- // --. Initialize new item, currently this succeeds always
- else
- {
- $this->_initItem();
- }
-
- // Extra Steps for Backend
- if ( $app->isAdmin() ) {
- // Set item type id for existing or new item ('typeid' of the JRequest array) ... verifying that the type exists ...
- $this->_item->type_id = $this->getTypesselected()->id;
- }
-
- return $this->_item;
- }
-
-
- /**
- * 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 (boolean) $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 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 = $user->getAuthorisedViewLevels();
- $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.*, ' // Item basic and extended data
- . $select_access // Access Columns and Access Flags for: content type, main category, item
- . ($version ? 'ver.version_id,' : '') // Versioned item viewing
- . ' c.id AS catid, i.catid as maincatid,' // Current category id and Main category id
- . ' c.published AS catpublished,' // Current category published (in J1.6+ this includes all ancestor categories)
- . ' c.title AS category_title, c.alias AS category_alias,' // Current category data
- . ' ty.name as typename, ty.alias as typealias,' // Content Type data
- . ' u.name AS author, u.usertype,' // Author data
-
- // Rating count, Rating & Score
- . ' 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)
- . ' 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,'
-
- // Publication Scheduled / Expired Flags
- . ' 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 /*|| FLEXI_J16GE*/ )
- {
- $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 /*|| FLEXI_J16GE*/) && $task=='edit' && $option=='com_flexicontent' && $editjf_translations > 0 )
- {
- // -- 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 < 2 && $translated_fields ) {
- $app->enqueueMessage("Third party Joom!Fish translations detected for current content, but editting Joom!Fish translations is disabled in global configuration", 'message' );
- $app->enqueueMessage("You can enable Joom!Fish translations editting or disable this warning in Global configuration",'message');
- } else {
- 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
- // *********************************************************
-
- // 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;
- }
- $item->typename = (string) @ $item->typename;
- $item->typealias = (string) @ $item->typealias;
- $item->rating_count = (int) @ $item->rating_count;
- $item->score = (int) @ $item->score;
-
- // 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 (boolean) $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;
- }
-
-
- //*************
- // BOF of J1.6+
- //*************
-
- /**
- * Returns a Table object, always creating it
- *
- * @param type The table type to instantiate
- * @param string A prefix for the table class name. Optional.
- * @param array Configuration array for model. Optional.
- * @return JTable A database object
- * @since 1.6
- */
- public function getTable($type = 'flexicontent_items', $prefix = '', $config = array()) {
- return JTable::getInstance($type, $prefix, $config);
- }
-
- /**
- * Method to get the row form.
- *
- * @param array $data Data for the form.
- * @param boolean $loadData True if the form is to load its own data (default case), false if not.
- * @return mixed A JForm object on success, false on failure
- * @since 1.6
- */
- public function getForm($data = array(), $loadData = true)
- {
- $app = JFactory::getApplication();
- $this->getItem();
-
- // *********************************************************
- // Prepare item data for being loaded into the form:
- // (a) Convert parameters 'images', 'urls,' 'attribs' & 'metadata' to an array
- // (b) Set property 'cid' (form field categories)
- // *********************************************************
-
- $this->_item->itemparams = FLEXI_J16GE ? new JRegistry() : new JParameter("");
-
- if ($this->_id) {
- // Convert the images
- $images = $this->_item->images;
- $registry = new JRegistry;
- $registry->loadString($images);
- $this->_item->images = $registry->toArray();
- $this->_item->itemparams->merge($registry);
-
- // Convert the urls
- $urls = $this->_item->urls;
- $registry = new JRegistry;
- $registry->loadString($urls);
- $this->_item->urls = $registry->toArray();
- $this->_item->itemparams->merge($registry);
-
- // Convert the attribs
- $attribs = $this->_item->attribs;
- $registry = new JRegistry;
- $registry->loadString($attribs);
- $this->_item->attribs = $registry->toArray();
- $this->_item->itemparams->merge($registry);
-
- // Convert the metadata
- $metadata = $this->_item->metadata;
- $registry = new JRegistry;
- $registry->loadString($metadata);
- $this->_item->metadata = $registry->toArray();
- $this->_item->itemparams->merge($registry);
- } else {
- $attribs = $metadata = '';
- $this->_item->attribs = array();
- $this->_item->metadata = array();
- $this->_item->images = array();
- $this->_item->urls = array();
- }
-
- // Set item property 'cid' (form field categories is named cid)
- $this->_item->cid = $this->_item->categories;
-
- // ****************************************************************************
- // Load item data into the form and restore the changes done above to item data
- // ****************************************************************************
- $form = $this->loadForm('com_flexicontent.item', 'item', array('control' => 'jform', 'load_data' => $loadData));
- if (empty($form)) {
- return false;
- }
- $this->_item->images = $images;
- $this->_item->urls = $urls;
- $this->_item->attribs = $attribs;
- $this->_item->metadata = $metadata;
- unset($this->_item->cid);
-
- // Determine correct permissions to check.
- $id = @$data['id'] ? $data['id'] : (int) $this->getState($this->getName().'.id');
- if ($id) {
- // Existing record. Can only edit in selected categories.
- $form->setFieldAttribute('catid', 'action', 'core.edit');
- // Existing record. Can only edit own articles in selected categories.
- $form->setFieldAttribute('catid', 'action', 'core.edit.own');
- }
- else {
- // New record. Can only create in selected categories.
- $form->setFieldAttribute('catid', 'action', 'core.create');
- }
-
- // Modify the form based on Edit State access controls.
- if ( !$this->canEditState( (object)$data ) )
- {
- $frontend_new = !$id && $app->isSite();
-
- // Disable fields for display.
- $form->setFieldAttribute('featured', 'disabled', 'true');
- $form->setFieldAttribute('ordering', 'disabled', 'true');
- $form->setFieldAttribute('publish_up', 'disabled', 'true');
- $form->setFieldAttribute('publish_down', 'disabled', 'true');
- $form->setFieldAttribute('created_by', 'disabled', 'true');
- $form->setFieldAttribute('created_by_alias', 'disabled', 'true');
- if ( !$frontend_new ) {
- // skip new items in frontend to allow override via menu (auto-publish), menu override must be check during store
- $form->setFieldAttribute('state', 'disabled', 'true'); // only for existing items, not for new to allow menu item override
- }
- //$form->setFieldAttribute('vstate', 'disabled', 'true'); // DO not -disable- will cause problems
-
- // Disable fields while saving.
- // The controller has already verified this is an article you can edit.
- $form->setFieldAttribute('featured', 'filter', 'unset');
- $form->setFieldAttribute('ordering', 'filter', 'unset');
- $form->setFieldAttribute('publish_up', 'filter', 'unset');
- $form->setFieldAttribute('publish_down', 'filter', 'unset');
- $form->setFieldAttribute('created_by', 'filter', 'unset');
- $form->setFieldAttribute('created_by_alias', 'filter', 'unset');
- if ( !$frontend_new ) {
- // skip new items in frontend to allow override via menu (auto-publish), menu override must be check during store
- $form->setFieldAttribute('state', 'filter', 'unset'); // only for existing items, not for new to allow menu item override
- }
- //$form->setFieldAttribute('vstate', 'filter', 'unset'); // DO not -filter- will cause problems
- }
-
- return $form;
- }
-
-
- /**
- * Method to get the data that should be injected in the form.
- *
- * @return mixed The data for the form.
- * @since 1.6
- */
- protected function loadFormData() {
- // Check the session for previously entered form data.
- $data = JFactory::getApplication()->getUserState('com_flexicontent.edit.'.$this->getName().'.data', array());
-
- if (empty($data)) {
- $data = $this->getItem();
- }
-
- return $data;
- }
-
-
- /**
- * Method to calculate Item Access Permissions
- *
- * @access private
- * @return void
- * @since 1.5
- */
- function getItemAccess($create_cats=array()) {
- $iparams_extra = new JRegistry;
- $user = JFactory::getUser();
- $asset = 'com_content.article.'.$this->_id;
- $permission = FlexicontentHelperPerm::getPerm(); // Global component permissions
-
- // NOTE, technically in J1.6+ a guest may edit able to edit/delete an item, so we commented out the guest check bellow,
- // this applies for creating item, but flexicontent already allows create to guests via menu item too, so no check there too
-
- // Compute CREATE access permissions.
- if ( !$this->_id ) {
-
- // Check if general create permission is missing, NOTE: THIS CAN BE SOFT DENY
- // ... so we do need to check category 'create' privilege for all categories !!
- /*if ( !$user->authorise('core.create', 'com_flexicontent') ) {
- $iparams_extra->set('access-create', false);
- return $iparams_extra; // New item, so do not calculate EDIT, DELETE and VIEW access
- }*/
-
- // Check that user can create item in at least one category ... this check is not wasted,
- // since joomla will cache it and use it later during creation of allowed Category Tree
- $canCreate = $user->authorise('core.create', 'com_flexicontent');
- if ($canCreate === NULL) {
- $allowedcats = FlexicontentHelperPerm::getAllowedCats($user, array('core.create')
- , $require_all = true, $check_published = true, $specific_catids = false, $find_first = true
- );
- $canCreate = count($allowedcats) > 0;
- }
- $iparams_extra->set('access-create', $canCreate);
- return $iparams_extra; // New item, so do not calculate EDIT, DELETE and VIEW access
- }
-
- // Not a new item retrieve item if not already done
- if ( empty($this->_item) ) {
- $this->_item = $this->getItem();
- }
-
- // Compute EDIT access permissions.
- if ( $this->_id ) {
- // first check edit permission on the item
- if ($user->authorise('core.edit', $asset)) {
- $iparams_extra->set('access-edit', true);
- }
- // no edit permission, check if edit.own is available for this item
- else if ( $user->authorise('core.edit.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
- {
- $iparams_extra->set('access-edit', true);
- }
- }
-
- // Compute EDIT STATE access permissions.
- if ( $this->_id ) {
- // first check edit.state permission on the item
- if ($user->authorise('core.edit.state', $asset)) {
- $iparams_extra->set('access-edit-state', true);
- }
- // no edit.state permission, check if edit.state.own is available for this item
- else if ( $user->authorise('core.edit.state.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
- {
- $iparams_extra->set('access-edit-state', true);
- }
- }
-
- // Compute DELETE access permissions.
- if ( $this->_id ) {
-
- // first check delete permission on the item
- if ($user->authorise('core.delete', $asset)) {
- $iparams_extra->set('access-delete', true);
- }
- // no delete permission, chekc delete.own permission if the item is owned by the user
- else if ( $user->authorise('core.delete.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
- {
- $iparams_extra->set('access-delete', true);
- }
- }
-
- // Compute VIEW access permissions.
- if ($access = $this->getState('filter.access')) {
- // The access filter has been set,
- // we already know current user can view this item or we should not check access
- $iparams_extra->set('access-view', true);
- }
- else {
- // The access filter has not been set, we will set access flag(s) if not set already
- // the layout takes some responsibility for display of limited information,
- $groups = $user->getAuthorisedViewLevels();
-
- if ( !isset($this->_item->has_item_access) ) {
- $this->_item->has_item_access = in_array($this->_item->access, $groups);
- }
- if ( !isset($this->_item->has_mcat_access) ) {
- $no_mcat_info = $this->_item->catid == 0 || !isset($this->_item->category_access) || $this->_item->category_access === null;
- $this->_item->has_mcat_access = $no_mcat_info || in_array($this->_item->category_access, $groups);
- }
- if ( !isset($this->_item->has_type_access) ) {
- $no_type_info = $this->_item->type_id == 0 || !isset($this->_item->type_access) || $this->_item->type_access === null;
- $this->_item->has_type_access = $no_type_info || in_array($this->_item->type_access, $groups);
- }
- $iparams_extra->set('access-view', $this->_item->has_item_access && $this->_item->has_mcat_access && $this->_item->has_type_access);
- }
-
- return $iparams_extra;
- }
-
-
-
- /**
- * Method to check if you can assign a (new/existing) item in the specified categories
- *
- * @param array An array of input data.
- *
- * @return boolean
- * @since 1.6
- */
- protected function itemAllowedInCats($data = array())
- {
- // Initialise variables.
- $user = JFactory::getUser();
-
- $cats = isset($data['cid']) ? $data['cid'] : array();
- if ( !empty($data['catid']) && !in_array($data['catid'], $cats) ) {
- $cats[] = $data['catid'];
- }
-
- $allow = null;
- if (count($cats)) {
- $allow = true;
- foreach ($cats as $curcatid) {
- // If the category has been passed in the data or URL check it.
- $cat_allowed = $user->authorise('core.create', 'com_content.category.'.$curcatid);
- if (!$cat_allowed) {
- return JError::raiseWarning( 500, "No access to add item to category with id ".$curcatid );
- }
- $allow &= $cat_allowed;
- }
- }
-
- if ($allow === null) {
- // no categories specified, revert to the component permissions.
- $allow = $user->authorise('core.create', 'com_flexicontent');
- }
-
- return $allow;
- }
-
- //*************
- // EOF of J1.6+
- //*************
-
- //*************
- // BOF of J1.5
- //*************
-
- /**
- * Method (for J1.5) to check if the user can add an item anywhere
- *
- * @access public
- * @return boolean True on success
- * @since 1.5
- */
- function canAdd()
- {
- $user = JFactory::getUser();
-
- if (FLEXI_ACCESS && ($user->gid < 25))
- {
- $canSubmit = FAccess::checkComponentAccess('com_content', 'submit', 'users', $user->gmid);
- $canAdd = FAccess::checkAllContentAccess('com_content','add','users',$user->gmid,'content','all');
- if (!$canSubmit && !$canAdd) return false;
- } else {
- $canAdd = $user->authorize('com_content', 'add', 'content', 'all');
- if (!$canAdd) return false;
- }
- return true;
- }
-
- /**
- * Method (for J1.5) to check if the user can edit the item
- *
- * @access public
- * @return boolean True on success
- * @since 1.5
- */
- function canEdit()
- {
- $user = JFactory::getUser();
-
- if (!$this->_loadItem() || $user->gid >= 25) {
- return true;
- } else if (FLEXI_ACCESS) {
- // This should not be used, as it bypasses individual item rights
- //$canEditAll = FAccess::checkAllContentAccess('com_content','edit','users',$user->gmid,'content','all');
- //$canEditOwnAll = FAccess::checkAllContentAccess('com_content','editown','users',$user->gmid,'content','all');
- if ($this->_item->id && $this->_item->catid)
- {
- $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $this->_item->id, $this->_item->catid);
- $canEdit = in_array('edit', $rights) /*|| $canEditAll*/;
- $canEditOwn = ( in_array('editown', $rights) /*|| $canEditOwnAll*/ ) && $this->_item->created_by ==…
Large files files are truncated, but you can click here to view the full file