PageRenderTime 66ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/com_flexicontent_v2.x/admin/models/parentclassitem.php

http://flexicontent.googlecode.com/
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

  1. <?php
  2. /**
  3. * @version 1.5 stable $Id: item.php 1244 2012-04-12 05:07:35Z ggppdk $
  4. * @package Joomla
  5. * @subpackage FLEXIcontent
  6. * @copyright (C) 2009 Emmanuel Danan - www.vistamedia.fr
  7. * @license GNU/GPL v2
  8. *
  9. * FLEXIcontent is a derivative work of the excellent QuickFAQ component
  10. * @copyright (C) 2008 Christoph Lukes
  11. * see www.schlu.net for more information
  12. *
  13. * FLEXIcontent is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. // no direct access
  19. defined( '_JEXEC' ) or die( 'Restricted access' );
  20. jimport( 'joomla.application.component.modeladmin' );
  21. jimport( 'joomla.html.parameter' );
  22. /**
  23. * FLEXIcontent Component Item Model
  24. *
  25. * @package Joomla
  26. * @subpackage FLEXIcontent
  27. * @since 1.0
  28. */
  29. class ParentClassItem extends JModelAdmin
  30. {
  31. var $_name = 'ParentClassItem';
  32. /**
  33. * Component parameters
  34. *
  35. * @var object
  36. */
  37. var $_cparams = null;
  38. /**
  39. * Item data
  40. *
  41. * @var object
  42. */
  43. var $_item = null;
  44. /**
  45. * Item primary key
  46. *
  47. * @var int
  48. */
  49. var $_id = null;
  50. /**
  51. * Item current category id (used for FRONTEND only)
  52. *
  53. * @var int
  54. */
  55. var $_cid = null;
  56. /**
  57. * Item version of loaded data
  58. *
  59. * @var int
  60. */
  61. var $_version = null;
  62. /**
  63. * Associated item translations
  64. *
  65. * @var array
  66. */
  67. var $_translations = null;
  68. /**
  69. * Constructor
  70. *
  71. * @since 1.0
  72. */
  73. public function __construct()
  74. {
  75. parent::__construct();
  76. $app = JFactory::getApplication();
  77. // --. Get component parameters , merge (for frontend) with current menu item parameters
  78. $this->_cparams = clone( JComponentHelper::getParams('com_flexicontent') );
  79. if (!$app->isAdmin()) {
  80. $menu = $app->getMenu()->getActive();
  81. if ($menu) {
  82. $menu_params = FLEXI_J16GE ? $menu->params : new JParameter($menu->params);
  83. $this->_cparams->merge($menu_params);
  84. }
  85. }
  86. // --. Get & Set ITEM's primary key (pk) and (for frontend) the current category
  87. if (!$app->isAdmin()) {
  88. // FRONTEND, use "id" from request
  89. $pk = JRequest::getVar('id', 0, 'default', 'int');
  90. if ( !JRequest::getVar('task') )
  91. $curcatid = JRequest::getVar('cid', 0, $hash='default', 'int');
  92. else
  93. $curcatid = 0;
  94. }
  95. else
  96. {
  97. // BACKEND, use "cid" array from request, but check first for a POST 'id' variable
  98. // this is a correction for problematic name of categories AS cid in item edit form ...
  99. $data = JRequest::get( 'post' );
  100. // Must check if id is SET and if it is non-ZERO !
  101. if ( FLEXI_J16GE ? isset($data['jform']['id']) : isset($data['id']) ) {
  102. $pk = FLEXI_J16GE ? $data['jform']['id'] : $data['id'];
  103. } else {
  104. $cid = JRequest::getVar( 'cid', array(0), $hash='default', 'array' );
  105. JArrayHelper::toInteger($cid, array(0));
  106. $pk = $cid[0];
  107. }
  108. $curcatid = 0;
  109. }
  110. $this->setId($pk, $curcatid); // NOTE: when setting $pk to a new value the $this->_item is cleared
  111. $this->populateState();
  112. }
  113. /**
  114. * Method to set the identifier
  115. *
  116. * @access public
  117. * @param int item identifier
  118. */
  119. function setId($id, $currcatid=0)
  120. {
  121. // Set a new item id and wipe data
  122. if ($this->_id != $id) {
  123. $this->_item = null;
  124. }
  125. $this->_id = (int) $id;
  126. // Set current category, but verify item is assigned to this category, (SECURITY concern)
  127. $this->_cid = (int) $currcatid;
  128. if ($this->_cid) {
  129. $q = "SELECT catid FROM #__flexicontent_cats_item_relations WHERE itemid =". (int)$this->_id ." AND catid = ". (int)$this->_cid;
  130. $this->_db->setQuery($q);
  131. $result = $this->_db->loadResult();
  132. $this->_cid = $result ? $this->_cid : 0; // Clear cid, if category not assigned to the item
  133. }
  134. }
  135. /**
  136. * Method to get the identifier
  137. *
  138. * @access public
  139. * @return int item identifier
  140. */
  141. function getId()
  142. {
  143. return $this->_id;
  144. }
  145. /**
  146. * Overridden get method to get properties from the item
  147. *
  148. * @access public
  149. * @param string $property The name of the property
  150. * @param mixed $value The value of the property to set
  151. * @return mixed The value of the property
  152. * @since 1.5
  153. */
  154. function get($property, $default=null)
  155. {
  156. if ($this->_item || $this->_loadItem()) {
  157. if(isset($this->_item->$property)) {
  158. return $this->_item->$property;
  159. }
  160. }
  161. return $default;
  162. }
  163. /**
  164. * Overridden set method to pass properties on to the item
  165. *
  166. * @access public
  167. * @param string $property The name of the property
  168. * @param mixed $value The value of the property to set
  169. * @return boolean True on success
  170. * @since 1.5
  171. */
  172. function set( $property, $value=null )
  173. {
  174. if ( $this->_loadItem() ) {
  175. $this->_item->$property = $value;
  176. return true;
  177. } else {
  178. return false;
  179. }
  180. }
  181. /**
  182. * Method to get item data
  183. *
  184. * @access public
  185. * @return array
  186. * @since 1.0
  187. */
  188. function &getItem($pk=null, $check_view_access=true, $no_cache=false, $force_version=false)
  189. {
  190. $app = JFactory::getApplication();
  191. $cparams = $this->_cparams;
  192. $preview = JRequest::getVar('preview');
  193. // View access done is meant only for FRONTEND !!! ... force it to false
  194. if ( $app->isAdmin() ) $check_view_access = false;
  195. // Initialise and set primary if it was not given already
  196. $pk = !empty($pk) ? $pk : $this->_id;
  197. if (FLEXI_J16GE) {
  198. $pk = !empty($pk) ? $pk : (int) $this->getState($this->getName().'.id');
  199. }
  200. // Set new item id, clearing item data, ONLY IF DIFFERENT than existing primary key
  201. if ($pk != $this->_id) {
  202. $this->setId($pk);
  203. }
  204. // --. Try to load existing item
  205. if ( $pk && $this->_loadItem($no_cache, $force_version) )
  206. {
  207. // Successfully loaded existing item, do some extra manipulation of the loaded item ...
  208. // Extra Steps for Frontend
  209. if ( !$app->isAdmin() ) {
  210. // Load item parameters with heritage
  211. $this->_loadItemParams();
  212. // Check item viewing access
  213. if ( $check_view_access ) $this->_check_viewing_access();
  214. }
  215. }
  216. // --. Failed to load existing item, or check_view_access indicates not to create a new item object
  217. else if ( $pk || $check_view_access===2 )
  218. {
  219. $msg = JText::sprintf('FLEXI_CONTENT_UNAVAILABLE_ITEM_NOT_FOUND', $pk);
  220. if (FLEXI_J16GE) throw new Exception($msg, 404); else JError::raiseError(404, $msg);
  221. }
  222. // --. Initialize new item, currently this succeeds always
  223. else
  224. {
  225. $this->_initItem();
  226. }
  227. // Extra Steps for Backend
  228. if ( $app->isAdmin() ) {
  229. // Set item type id for existing or new item ('typeid' of the JRequest array) ... verifying that the type exists ...
  230. $this->_item->type_id = $this->getTypesselected()->id;
  231. }
  232. return $this->_item;
  233. }
  234. /**
  235. * Method to load item data
  236. *
  237. * @access private
  238. * @return boolean True on success
  239. * @since 1.0
  240. */
  241. function _loadItem( $no_cache=false, $force_version=false )
  242. {
  243. if(!$this->_id) return false; // Only try to load existing item
  244. // Cache items retrieved, we can retrieve multiple items, for this purpose
  245. // (a) temporarily set JRequest variable -version- to specify loaded version (set to zero to use latest )
  246. // (b1) use member function function setId($id, $currcatid=0) to change primary key and then call getItem()
  247. // (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
  248. static $items = array();
  249. if ( $no_cache ) {
  250. // Clear item to make sure it is reloaded
  251. $this->_item = null;
  252. }
  253. else if ( isset($items[$this->_id]) ) {
  254. $this->_item = & $items[$this->_id];
  255. return (boolean) $this->_item;
  256. }
  257. static $unapproved_version_notice;
  258. $db = $this->_db;
  259. $app = JFactory::getApplication();
  260. $user = JFactory::getUser();
  261. $cparams = $this->_cparams;
  262. $task = JRequest::getVar('task', false);
  263. $layout = JRequest::getVar('layout', false);
  264. $view = JRequest::getVar('view', false);
  265. $option = JRequest::getVar('option', false);
  266. $use_versioning = $cparams->get('use_versioning', 1);
  267. $allow_current_version = true;
  268. $editjf_translations = $cparams->get('editjf_translations', 0);
  269. // *********************************************************************************************************
  270. // Retrieve item if not already retrieved, null indicates cleared item data, e.g. because of changed item id
  271. // *********************************************************************************************************
  272. if ( $this->_item === null ) {
  273. //*****************************************************
  274. // DECIDE VERSION and GENERATE VERSION RELATED MESSAGES
  275. //*****************************************************
  276. // Variables controlling the version loading logic
  277. $loadcurrent = JRequest::getVar('loadcurrent', false, 'request', 'boolean'); // loadcurrent request flag, ignored if version specified
  278. $preview = JRequest::getVar('preview', false, 'request', 'boolean'); // preview request flag for viewing unapproved version in frontend
  279. $version = JRequest::getVar('version', 0, 'request', 'int' ); // the item version to load
  280. // -- Decide the version to load: (a) the one specified by request or (b) the current one or (c) the latest one
  281. $current_version = FLEXIUtilities::getCurrentVersions($this->_id, true, $force=true); // Get current item version
  282. $last_version = FLEXIUtilities::getLastVersions($this->_id, true, $force=true); // Get last version (=latest one saved, highest version id),
  283. // NOTE: Setting version to zero indicates to load the current version from the normal tables and not the versioning table
  284. if ( !$use_versioning ) {
  285. // Force version to zero (load current version), when not using versioning mode
  286. $version = 0;
  287. } else if ($force_version !== false) {
  288. $version = $force_version==-1 ? $last_version : $force_version;
  289. } else if ($version == 0) {
  290. // version request variable was NOT SET ... We need to decide to load current (version zero) or latest
  291. if ( $app->isAdmin() || ($task=='edit' && $option=='com_flexicontent') ) {
  292. // Catch cases (a) when we enable versioning mode after an item has been saved in unversioning mode, (b) loadcurrent flag is set
  293. // in these case we will load CURRENT version instead of the default for the item edit form which is the LATEST (for backend/fontend)
  294. $version = ($current_version >= $last_version || $loadcurrent) ? 0 : $last_version;
  295. } else {
  296. // In frontend item display the current version must be shown unless preview flag is set
  297. $version = !$preview ? 0 : $last_version;
  298. }
  299. } else if ($version == $current_version) {
  300. // Current version number given, the data from the versioning table should be the same as the data from normal tables
  301. // we do not force $version to ZERO to allow testing the field data of current version from the versioning table
  302. if (!$allow_current_version) $version = 0; // Force zero to retrieve unversioned data
  303. }
  304. // Check if not loading the current version while we are in edit form, and raise a notice to inform the user
  305. if ($version && $version != $current_version && $task=='edit' && $option=='com_flexicontent' && !$unapproved_version_notice) {
  306. $unapproved_version_notice = 1;
  307. if (!$app->isAdmin()) {
  308. JError::raiseNotice(10, JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE') );
  309. } else {
  310. JError::raiseNotice(10,
  311. JText::_('FLEXI_LOADING_UNAPPROVED_VERSION_NOTICE') . ' :: ' .
  312. JText::sprintf('FLEXI_LOADED_VERSION_INFO_NOTICE', $version, $current_version)
  313. );
  314. }
  315. }
  316. try
  317. {
  318. if ( $app->isAdmin() )
  319. {
  320. // **********************
  321. // Item Retrieval BACKEND
  322. // **********************
  323. $item = $this->getTable('flexicontent_items', '');
  324. $result = $item->load($this->_id); // try loading existing item data
  325. if ($result===false) return false;
  326. }
  327. else
  328. {
  329. // ***********************
  330. // Item Retrieval FRONTEND
  331. // ***********************
  332. // Tables needed to be joined for calculating access
  333. $joinaccess = '';
  334. // Extra access columns for main category and content type (item access will be added as 'access')
  335. $select_access = 'mc.access as category_access, ty.access as type_access';
  336. // Access Flags for: content type, main category, item
  337. if (FLEXI_J16GE) {
  338. $aid_arr = $user->getAuthorisedViewLevels();
  339. $aid_list = implode(",", $aid_arr);
  340. $select_access .= ', CASE WHEN ty.access IN (0,'.$aid_list.') THEN 1 ELSE 0 END AS has_type_access';
  341. $select_access .= ', CASE WHEN mc.access IN (0,'.$aid_list.') THEN 1 ELSE 0 END AS has_mcat_access';
  342. $select_access .= ', CASE WHEN i.access IN (0,'.$aid_list.') THEN 1 ELSE 0 END AS has_item_access';
  343. } else {
  344. $aid = (int) $user->get('aid');
  345. if (FLEXI_ACCESS) {
  346. $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gt ON ty.id = gt.axo AND gt.aco = "read" AND gt.axosection = "type"';
  347. $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gc ON mc.id = gc.axo AND gc.aco = "read" AND gc.axosection = "category"';
  348. $joinaccess .= ' LEFT JOIN #__flexiaccess_acl AS gi ON i.id = gi.axo AND gi.aco = "read" AND gi.axosection = "item"';
  349. $select_access .= ', CASE WHEN (gt.aro IN ( '.$user->gmid.' ) OR ty.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_type_access';
  350. $select_access .= ', CASE WHEN (gc.aro IN ( '.$user->gmid.' ) OR mc.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_mcat_access';
  351. $select_access .= ', CASE WHEN (gi.aro IN ( '.$user->gmid.' ) OR i.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_item_access';
  352. } else {
  353. $select_access .= ', CASE WHEN (ty.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_type_access';
  354. $select_access .= ', CASE WHEN (mc.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_mcat_access';
  355. $select_access .= ', CASE WHEN ( i.access <= '. (int) $aid . ') THEN 1 ELSE 0 END AS has_item_access';
  356. }
  357. $select_access .= ', ';
  358. }
  359. // SQL date strings, current date and null date
  360. $nowDate = $db->Quote( FLEXI_J16GE ? JFactory::getDate()->toSql() : JFactory::getDate()->toMySQL() );
  361. $nullDate = $db->Quote($db->getNullDate());
  362. // Decide to limit to CURRENT CATEGORY
  363. $limit_to_cid = $this->_cid ? ' AND rel.catid = '. (int) $this->_cid : ' AND rel.catid = i.catid';
  364. if (FLEXI_J16GE)
  365. {
  366. // Initialize query
  367. $query = $db->getQuery(true);
  368. $query->select('i.*, ie.*'); // Item basic and extended data
  369. $query->select($select_access); // Access Columns and Access Flags for: content type, main category, item
  370. if ($version) $query->select('ver.version_id'); // Versioned item viewing
  371. $query->select('c.id AS catid, i.catid as maincatid'); // Current category id and Main category id
  372. $query->select(
  373. 'c.title AS category_title, c.alias AS category_alias, c.lft,c.rgt'); // Current category data
  374. $query->select('ty.name AS typename, ty.alias as typealias'); // Content Type data, and author data
  375. $query->select('u.name AS author'); // Author data
  376. // Rating count, Rating & Score
  377. $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');
  378. // Item and Current Category slugs (for URL)
  379. $query->select('CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug');
  380. $query->select('CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug');
  381. // Publication Scheduled / Expired Flags
  382. $query->select('CASE WHEN i.publish_up = '.$nullDate.' OR i.publish_up <= '.$nowDate.' THEN 0 ELSE 1 END as publication_scheduled');
  383. $query->select('CASE WHEN i.publish_down = '.$nullDate.' OR i.publish_down >= '.$nowDate.' THEN 0 ELSE 1 END as publication_expired' );
  384. // From content table, and extended item table, content type table, user table, rating table, categories relation table
  385. $query->from('#__content AS i');
  386. $query->join('LEFT', '#__flexicontent_items_ext AS ie ON ie.item_id = i.id');
  387. $query->join('LEFT', '#__flexicontent_types AS ty ON ie.type_id = ty.id');
  388. $query->join('LEFT', '#__users AS u on u.id = i.created_by');
  389. $query->join('LEFT', '#__content_rating AS v ON i.id = v.content_id');
  390. $query->join('LEFT', '#__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . $limit_to_cid);
  391. // Join twice on category table, once for current category and once for item's main category
  392. $query->join('LEFT', '#__categories AS c on c.id = rel.catid'); // All item's categories
  393. $query->join('LEFT', '#__categories AS mc on mc.id = i.catid'); // Item's main category
  394. // HANDLE J1.6+ ancestor category being unpublished, when badcats.id is not null,
  395. // then the item is inside in an unpublished ancestor category, thus inaccessible
  396. $query->select('CASE WHEN badcats.id is null THEN 1 ELSE 0 END AS ancestor_cats_published');
  397. $subquery = ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ';
  398. $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt ';
  399. $subquery .= 'WHERE parent.extension = ' . $db->Quote('com_content');
  400. $subquery .= ' AND parent.published <= 0 GROUP BY cat.id)';
  401. $query->join('LEFT', $subquery . ' AS badcats ON badcats.id = c.id');
  402. if ($version) {
  403. // 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
  404. $query->join('LEFT', '#__flexicontent_versions AS ver ON ver.item_id = i.id AND ver.version_id = '. $db->Quote($version) );
  405. }
  406. // Join on contact table, to get contact data of author
  407. //$query = 'SHOW TABLES LIKE "' . JFactory::getApplication()->getCfg('dbprefix') . 'contact_details"';
  408. //$db->setQuery($query);
  409. //$contact_details_tbl_exists = (boolean) count($db->loadObjectList());
  410. //if ( $contact_details_tbl_exists) {
  411. // $query->select('contact.id as contactid' ) ;
  412. // $query->join('LEFT','#__contact_details AS contact on contact.user_id = i.created_by');
  413. //}
  414. // Join over the categories to get parent category titles
  415. //$query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias');
  416. //$query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id');
  417. $query->where('i.id = ' . (int) $this->_id);
  418. //echo $db->replacePrefix($query);
  419. }
  420. else
  421. {
  422. // 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
  423. $version_join = $version ? ' LEFT JOIN #__flexicontent_versions AS ver ON ver.item_id = i.id AND ver.version_id = '. $db->Quote($version) : '';
  424. $where = $this->_buildItemWhere();
  425. $query = 'SELECT i.*, ie.*, ' // Item basic and extended data
  426. . $select_access // Access Columns and Access Flags for: content type, main category, item
  427. . ($version ? 'ver.version_id,' : '') // Versioned item viewing
  428. . ' c.id AS catid, i.catid as maincatid,' // Current category id and Main category id
  429. . ' c.published AS catpublished,' // Current category published (in J1.6+ this includes all ancestor categories)
  430. . ' c.title AS category_title, c.alias AS category_alias,' // Current category data
  431. . ' ty.name as typename, ty.alias as typealias,' // Content Type data
  432. . ' u.name AS author, u.usertype,' // Author data
  433. // Rating count, Rating & Score
  434. . ' v.rating_count as rating_count, ROUND( v.rating_sum / v.rating_count ) AS rating, ((v.rating_sum / v.rating_count)*20) as score,'
  435. // Item and Current Category slugs (for URL)
  436. . ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as slug,'
  437. . ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as categoryslug,'
  438. // Publication Scheduled / Expired Flags
  439. . ' CASE WHEN i.publish_up = '.$nullDate.' OR i.publish_up <= '.$nowDate.' THEN 0 ELSE 1 END as publication_scheduled,'
  440. . ' CASE WHEN i.publish_down = '.$nullDate.' OR i.publish_down >= '.$nowDate.' THEN 0 ELSE 1 END as publication_expired'
  441. . ' FROM #__content AS i'
  442. . ' LEFT JOIN #__flexicontent_items_ext AS ie ON ie.item_id = i.id'
  443. . ' LEFT JOIN #__flexicontent_types AS ty ON ie.type_id = ty.id'
  444. . ' LEFT JOIN #__flexicontent_cats_item_relations AS rel ON rel.itemid = i.id' . $limit_to_cid
  445. . ' LEFT JOIN #__categories AS c ON c.id = rel.catid'
  446. . ' LEFT JOIN #__categories AS mc ON mc.id = i.catid'
  447. . ' LEFT JOIN #__users AS u ON u.id = i.created_by'
  448. . ' LEFT JOIN #__content_rating AS v ON i.id = v.content_id'
  449. . $joinaccess
  450. . $version_join
  451. . $where
  452. ;
  453. }
  454. $db->setQuery($query);
  455. // Try to execute query directly and load the data as an object
  456. if ( FLEXI_FISH && $task=='edit' && $option=='com_flexicontent' && in_array( $app->getCfg('dbtype') , array('mysqli','mysql') ) ) {
  457. $data = flexicontent_db::directQuery($query);
  458. $data = @ $data[0];
  459. //$data = $db->loadObject(null, false); // do not, translate, this is the JoomFish overridden method of Database extended Class
  460. } else {
  461. $data = $db->loadObject();
  462. }
  463. // Check for SQL error
  464. if ( $db->getErrorNum() ) {
  465. if (FLEXI_J16GE) throw new Exception($db->getErrorMsg(), 500); else JError::raiseError(500, $db->getErrorMsg());
  466. }
  467. //print_r($data); exit;
  468. if(!$data) return false; // item not found, return
  469. if ($version && !$data->version_id) {
  470. JError::raiseNotice(10, JText::sprintf('NOTICE: Requested item version %d was not found', $version) );
  471. }
  472. $item = & $data;
  473. }
  474. // -- Create the description field called 'text' by appending introtext + readmore + fulltext
  475. $item->text = $item->introtext;
  476. $item->text .= JString::strlen( trim($item->fulltext) ) ? '<hr id="system-readmore" />' . $item->fulltext : "";
  477. //echo "<br/>Current version (Frontend Active): " . $item->version;
  478. //echo "<br/>Version to load: ".$version;
  479. //echo "<br/><b> *** db title:</b> ".$item->title;
  480. //echo "<br/><b> *** db text:</b> ".$item->text;
  481. //echo "<pre>*** item data: "; print_r($item); echo "</pre>"; exit;
  482. // Set number of loaded version, IMPORTANT: zero means load unversioned data
  483. JRequest::setVar( 'version', $version );
  484. // *************************************************************************************************
  485. // -- Retrieve all active site languages, and create empty item translation objects for each of them
  486. // *************************************************************************************************
  487. $nn_content_tbl = FLEXI_J16GE ? 'falang_content' : 'jf_content';
  488. if ( FLEXI_FISH /*|| FLEXI_J16GE*/ )
  489. {
  490. $site_languages = FLEXIUtilities::getlanguageslist();
  491. $item_translations = new stdClass();
  492. foreach($site_languages as $lang_id => $lang_data)
  493. {
  494. if ( !$lang_id && $item->language!='*' ) continue;
  495. $lang_data->fields = new stdClass();
  496. $item_translations->{$lang_id} = $lang_data;
  497. }
  498. }
  499. // **********************************
  500. // Retrieve and prepare JoomFish data
  501. // **********************************
  502. if ( (FLEXI_FISH /*|| FLEXI_J16GE*/) && $task=='edit' && $option=='com_flexicontent' && $editjf_translations > 0 )
  503. {
  504. // -- Try to retrieve all joomfish data for the current item
  505. $query = "SELECT jfc.language_id, jfc.reference_field, jfc.value, jfc.published "
  506. ." FROM #__".$nn_content_tbl." as jfc "
  507. ." WHERE jfc.reference_table='content' AND jfc.reference_id = {$this->_id} ";
  508. $db->setQuery($query);
  509. $translated_fields = $db->loadObjectList();
  510. if ( $editjf_translations < 2 && $translated_fields ) {
  511. $app->enqueueMessage("Third party Joom!Fish translations detected for current content, but editting Joom!Fish translations is disabled in global configuration", 'message' );
  512. $app->enqueueMessage("You can enable Joom!Fish translations editting or disable this warning in Global configuration",'message');
  513. } else {
  514. if ($db->getErrorNum()) JFactory::getApplication()->enqueueMessage(__FUNCTION__.'(): SQL QUERY ERROR:<br/>'.nl2br($db->getErrorMsg()),'error');
  515. // -- Parse translation data according to their language
  516. if ( $translated_fields )
  517. {
  518. // Add retrieved translated item properties
  519. foreach ($translated_fields as $field_data)
  520. {
  521. $item_translations ->{$field_data->language_id} ->fields ->{$field_data->reference_field} = new stdClass();
  522. $item_translations ->{$field_data->language_id} ->fields ->{$field_data->reference_field}->value = $field_data->value;
  523. $found_languages[$field_data->language_id] = $item_translations->{$field_data->language_id}->name;
  524. }
  525. //echo "<br/>Joom!Fish translations found for: " . implode(",", $found_languages);
  526. }
  527. foreach ($item_translations as $lang_id => $translation_data)
  528. {
  529. // Default title can be somewhat long, trim it to first word, so that it is more suitable for tabs
  530. list($translation_data->name) = explode(' ', trim($translation_data->name));
  531. // Create text field value for all languages
  532. $translation_data->fields->text = new stdClass();
  533. $translation_data->fields->text->value = @ $translation_data->fields->introtext->value;
  534. if ( JString::strlen( trim(@$translation_data->fields->fulltext->value) ) ) {
  535. $translation_data->fields->text->value .= '<hr id="system-readmore" />' . @ $translation_data->fields->fulltext->value;
  536. }
  537. }
  538. $item->item_translations = & $item_translations;
  539. }
  540. }
  541. //echo "<pre>"; print_r($item->item_translations); exit;
  542. // *****************************************************
  543. // Overwrite item fields with the requested VERSION data
  544. // *****************************************************
  545. $item->current_version = $current_version;
  546. $item->last_version = $last_version;
  547. if ($use_versioning && $version)
  548. {
  549. // Overcome possible group concat limitation
  550. $query="SET SESSION group_concat_max_len = 9999999";
  551. $db->setQuery($query);
  552. $db->query();
  553. $query = "SELECT f.id, f.name, f.field_type, GROUP_CONCAT(iv.value SEPARATOR ',') as value, count(f.id) as valuecount, iv.field_id"
  554. ." FROM #__flexicontent_items_versions as iv "
  555. ." LEFT JOIN #__flexicontent_fields as f on f.id=iv.field_id"
  556. ." WHERE iv.version='".$version."' AND (f.iscore=1 OR iv.field_id=-1 OR iv.field_id=-2) AND iv.item_id='".$this->_id."'"
  557. ." GROUP BY f.id";
  558. $db->setQuery($query);
  559. $fields = $db->loadObjectList();
  560. $fields = $fields ? $fields : array();
  561. //echo "<br/>Overwritting fields with version: $version";
  562. foreach($fields as $f) {
  563. //echo "<br/><b>{$f->field_id} : ". $f->name."</b> : "; print_r($f->value);
  564. // Use versioned data, by overwriting the item data
  565. $fieldname = $f->name;
  566. if ($f->field_type=='hits' || $f->field_type=='state' || $f->field_type=='voting') {
  567. // skip fields that should not have been versioned: hits, state, voting
  568. continue;
  569. } else if ($f->field_type=='version') {
  570. // set version variable to indicate the loaded version
  571. $item->version = $version;
  572. } else if( $fieldname=='categories'|| $fieldname=='tags' ) {
  573. // categories and tags must have been serialized but some earlier versions did not do it,
  574. // we will check before unserializing them, otherwise they were concatenated to a single string and use explode ...
  575. $item->$fieldname = ($array = @unserialize($f->value)) ? $array : explode(",", $f->value);
  576. } else if ($f->field_id==-1) {
  577. if ( FLEXI_FISH ) {
  578. $jfdata = unserialize($f->value);
  579. $item_lang = substr($item->language ,0,2);
  580. foreach ($item_translations as $lang_id => $translation_data) {
  581. //echo "<br/>Adding values for: ".$translation_data->shortcode;
  582. if ( empty($jfdata[$translation_data->shortcode]) ) continue;
  583. foreach ($jfdata[$translation_data->shortcode] as $fieldname => $fieldvalue)
  584. {
  585. //echo "<br/>".$translation_data->shortcode.": $fieldname => $fieldvalue";
  586. if ($translation_data->shortcode != $item_lang) {
  587. $translation_data->fields->$fieldname = new stdClass();
  588. $translation_data->fields->$fieldname->value = $fieldvalue;
  589. } else {
  590. $item->$fieldname = $fieldvalue;
  591. }
  592. }
  593. }
  594. }
  595. } else if ($f->field_id==-2) {
  596. // Other item properties that were versioned, such as alias, catid, meta params, attribs
  597. $item_data = unserialize($f->value);
  598. //$item->bind($item_data);
  599. foreach ($item_data as $k => $v) $item->$k = $v;
  600. } else if ($fieldname) {
  601. // Other fields (maybe serialized or not but we do not unserialized them, this is responsibility of the field itself)
  602. $item->$fieldname = $f->value;
  603. }
  604. }
  605. // The text field is stored in the db as to seperate fields: introtext & fulltext
  606. // So we search for the {readmore} tag and split up the text field accordingly.
  607. $pattern = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#i';
  608. $tagPos = preg_match($pattern, $item->text);
  609. if ($tagPos == 0) {
  610. $item->introtext = $item->text;
  611. $item->fulltext = '';
  612. } else {
  613. list($item->introtext, $item->fulltext) = preg_split($pattern, $item->text, 2);
  614. $item->fulltext = JString::strlen( trim($item->fulltext) ) ? $item->fulltext : '';
  615. }
  616. }
  617. // -- Retrieve tags field value (if not using versioning)
  618. if ( $use_versioning && $version ) {
  619. // Check version value was found
  620. if ( !isset($item->tags) || !is_array($item->tags) )
  621. $item->tags = array();
  622. } else {
  623. // Retrieve unversioned value
  624. $query = 'SELECT DISTINCT tid FROM #__flexicontent_tags_item_relations WHERE itemid = ' . (int)$this->_id;
  625. $db->setQuery($query);
  626. $item->tags = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
  627. }
  628. // -- Retrieve categories field value (if not using versioning)
  629. if ( $use_versioning && $version ) {
  630. // Check version value was found, and is valid (above code should have produced an array)
  631. if ( !isset($item->categories) || !is_array($item->categories) )
  632. $item->categories = array();
  633. } else {
  634. $query = 'SELECT DISTINCT catid FROM #__flexicontent_cats_item_relations WHERE itemid = ' . (int)$this->_id;
  635. $db->setQuery($query);
  636. $item->categories = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
  637. }
  638. // Make sure catid is in categories array
  639. if ( !in_array($item->catid, $item->categories) ) $item->categories[] = $item->catid;
  640. // 'cats' is an alias of categories
  641. $item->cats = & $item->categories;
  642. // *********************************************************
  643. // Retrieve item properties not defined in the model's CLASS
  644. // *********************************************************
  645. // Category access is retrieved here for J1.6+, for J1.5 we use FLEXIaccess
  646. if (FLEXI_J16GE) {
  647. // Get category access for the item's main category, used later to determine viewing of the item
  648. $query = 'SELECT access FROM #__categories WHERE id = '. (int) $item->catid;
  649. $db->setQuery($query);
  650. $item->category_access = $db->loadResult();
  651. }
  652. // Typecast some properties in case LEFT JOIN returned nulls
  653. if ( !isset($item->type_access) ) {
  654. $public_acclevel = !FLEXI_J16GE ? 0 : 1;
  655. $item->type_access = $public_acclevel;
  656. }
  657. $item->typename = (string) @ $item->typename;
  658. $item->typealias = (string) @ $item->typealias;
  659. $item->rating_count = (int) @ $item->rating_count;
  660. $item->score = (int) @ $item->score;
  661. // Retrieve Creator NAME and email (used to display the gravatar)
  662. $query = 'SELECT name, email FROM #__users WHERE id = '. (int) $item->created_by;
  663. $db->setQuery($query);
  664. $creator_data = $db->loadObject();
  665. $item->creator = $creator_data ? $creator_data->name : '';
  666. $item->creatoremail = $creator_data ? $creator_data->email : '';
  667. // Retrieve Modifier NAME
  668. if ($item->created_by == $item->modified_by) {
  669. $item->modifier = $item->creator;
  670. } else {
  671. $query = 'SELECT name, email FROM #__users WHERE id = '. (int) $item->modified_by;
  672. $db->setQuery($query);
  673. $modifier_data = $db->loadObject();
  674. $item->modifier = $modifier_data ? $modifier_data->name : '';
  675. $item->modifieremail = $modifier_data ? $modifier_data->email : '';
  676. }
  677. // Clear modified Date, if it is an invalid "null" date
  678. if ($item->modified == $db->getNulldate()) {
  679. $item->modified = null;
  680. }
  681. // ********************************************************
  682. // Assign to the item data member variable and cache it too
  683. // ********************************************************
  684. $this->_item = & $item;
  685. $items[$this->_id] = & $this->_item;
  686. // ******************************************************************************************************
  687. // Detect if current version doesnot exist in version table and add it !!! e.g. after enabling versioning
  688. // ******************************************************************************************************
  689. if ( $use_versioning && $current_version > $last_version ) {
  690. require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_flexicontent'.DS.'models'.DS.'flexicontent.php');
  691. $fleximodel = new FlexicontentModelFlexicontent();
  692. $fleximodel->addCurrentVersionData($item->id);
  693. }
  694. // return true if item was loaded successfully
  695. return (boolean) $this->_item;
  696. }
  697. catch (JException $e)
  698. {
  699. if ($e->getCode() == 404) {
  700. // Need to go thru the error handler to allow Redirect to work.
  701. $msg = $e->getMessage();
  702. if (FLEXI_J16GE) throw new Exception($msg, 404); else JError::raiseError(404, $msg);
  703. }
  704. else {
  705. $this->setError($e);
  706. $this->_item = false;
  707. }
  708. }
  709. } else {
  710. $items[$this->_id] = & $this->_item;
  711. }
  712. /*$session = JFactory::getSession();
  713. $postdata = $session->get('item_edit_postdata', array(), 'flexicontent');
  714. if (count($postdata)) {
  715. $session->set('item_edit_postdata', null, 'flexicontent');
  716. // ...
  717. }*/
  718. return true;
  719. }
  720. //*************
  721. // BOF of J1.6+
  722. //*************
  723. /**
  724. * Returns a Table object, always creating it
  725. *
  726. * @param type The table type to instantiate
  727. * @param string A prefix for the table class name. Optional.
  728. * @param array Configuration array for model. Optional.
  729. * @return JTable A database object
  730. * @since 1.6
  731. */
  732. public function getTable($type = 'flexicontent_items', $prefix = '', $config = array()) {
  733. return JTable::getInstance($type, $prefix, $config);
  734. }
  735. /**
  736. * Method to get the row form.
  737. *
  738. * @param array $data Data for the form.
  739. * @param boolean $loadData True if the form is to load its own data (default case), false if not.
  740. * @return mixed A JForm object on success, false on failure
  741. * @since 1.6
  742. */
  743. public function getForm($data = array(), $loadData = true)
  744. {
  745. $app = JFactory::getApplication();
  746. $this->getItem();
  747. // *********************************************************
  748. // Prepare item data for being loaded into the form:
  749. // (a) Convert parameters 'images', 'urls,' 'attribs' & 'metadata' to an array
  750. // (b) Set property 'cid' (form field categories)
  751. // *********************************************************
  752. $this->_item->itemparams = FLEXI_J16GE ? new JRegistry() : new JParameter("");
  753. if ($this->_id) {
  754. // Convert the images
  755. $images = $this->_item->images;
  756. $registry = new JRegistry;
  757. $registry->loadString($images);
  758. $this->_item->images = $registry->toArray();
  759. $this->_item->itemparams->merge($registry);
  760. // Convert the urls
  761. $urls = $this->_item->urls;
  762. $registry = new JRegistry;
  763. $registry->loadString($urls);
  764. $this->_item->urls = $registry->toArray();
  765. $this->_item->itemparams->merge($registry);
  766. // Convert the attribs
  767. $attribs = $this->_item->attribs;
  768. $registry = new JRegistry;
  769. $registry->loadString($attribs);
  770. $this->_item->attribs = $registry->toArray();
  771. $this->_item->itemparams->merge($registry);
  772. // Convert the metadata
  773. $metadata = $this->_item->metadata;
  774. $registry = new JRegistry;
  775. $registry->loadString($metadata);
  776. $this->_item->metadata = $registry->toArray();
  777. $this->_item->itemparams->merge($registry);
  778. } else {
  779. $attribs = $metadata = '';
  780. $this->_item->attribs = array();
  781. $this->_item->metadata = array();
  782. $this->_item->images = array();
  783. $this->_item->urls = array();
  784. }
  785. // Set item property 'cid' (form field categories is named cid)
  786. $this->_item->cid = $this->_item->categories;
  787. // ****************************************************************************
  788. // Load item data into the form and restore the changes done above to item data
  789. // ****************************************************************************
  790. $form = $this->loadForm('com_flexicontent.item', 'item', array('control' => 'jform', 'load_data' => $loadData));
  791. if (empty($form)) {
  792. return false;
  793. }
  794. $this->_item->images = $images;
  795. $this->_item->urls = $urls;
  796. $this->_item->attribs = $attribs;
  797. $this->_item->metadata = $metadata;
  798. unset($this->_item->cid);
  799. // Determine correct permissions to check.
  800. $id = @$data['id'] ? $data['id'] : (int) $this->getState($this->getName().'.id');
  801. if ($id) {
  802. // Existing record. Can only edit in selected categories.
  803. $form->setFieldAttribute('catid', 'action', 'core.edit');
  804. // Existing record. Can only edit own articles in selected categories.
  805. $form->setFieldAttribute('catid', 'action', 'core.edit.own');
  806. }
  807. else {
  808. // New record. Can only create in selected categories.
  809. $form->setFieldAttribute('catid', 'action', 'core.create');
  810. }
  811. // Modify the form based on Edit State access controls.
  812. if ( !$this->canEditState( (object)$data ) )
  813. {
  814. $frontend_new = !$id && $app->isSite();
  815. // Disable fields for display.
  816. $form->setFieldAttribute('featured', 'disabled', 'true');
  817. $form->setFieldAttribute('ordering', 'disabled', 'true');
  818. $form->setFieldAttribute('publish_up', 'disabled', 'true');
  819. $form->setFieldAttribute('publish_down', 'disabled', 'true');
  820. $form->setFieldAttribute('created_by', 'disabled', 'true');
  821. $form->setFieldAttribute('created_by_alias', 'disabled', 'true');
  822. if ( !$frontend_new ) {
  823. // skip new items in frontend to allow override via menu (auto-publish), menu override must be check during store
  824. $form->setFieldAttribute('state', 'disabled', 'true'); // only for existing items, not for new to allow menu item override
  825. }
  826. //$form->setFieldAttribute('vstate', 'disabled', 'true'); // DO not -disable- will cause problems
  827. // Disable fields while saving.
  828. // The controller has already verified this is an article you can edit.
  829. $form->setFieldAttribute('featured', 'filter', 'unset');
  830. $form->setFieldAttribute('ordering', 'filter', 'unset');
  831. $form->setFieldAttribute('publish_up', 'filter', 'unset');
  832. $form->setFieldAttribute('publish_down', 'filter', 'unset');
  833. $form->setFieldAttribute('created_by', 'filter', 'unset');
  834. $form->setFieldAttribute('created_by_alias', 'filter', 'unset');
  835. if ( !$frontend_new ) {
  836. // skip new items in frontend to allow override via menu (auto-publish), menu override must be check during store
  837. $form->setFieldAttribute('state', 'filter', 'unset'); // only for existing items, not for new to allow menu item override
  838. }
  839. //$form->setFieldAttribute('vstate', 'filter', 'unset'); // DO not -filter- will cause problems
  840. }
  841. return $form;
  842. }
  843. /**
  844. * Method to get the data that should be injected in the form.
  845. *
  846. * @return mixed The data for the form.
  847. * @since 1.6
  848. */
  849. protected function loadFormData() {
  850. // Check the session for previously entered form data.
  851. $data = JFactory::getApplication()->getUserState('com_flexicontent.edit.'.$this->getName().'.data', array());
  852. if (empty($data)) {
  853. $data = $this->getItem();
  854. }
  855. return $data;
  856. }
  857. /**
  858. * Method to calculate Item Access Permissions
  859. *
  860. * @access private
  861. * @return void
  862. * @since 1.5
  863. */
  864. function getItemAccess($create_cats=array()) {
  865. $iparams_extra = new JRegistry;
  866. $user = JFactory::getUser();
  867. $asset = 'com_content.article.'.$this->_id;
  868. $permission = FlexicontentHelperPerm::getPerm(); // Global component permissions
  869. // NOTE, technically in J1.6+ a guest may edit able to edit/delete an item, so we commented out the guest check bellow,
  870. // this applies for creating item, but flexicontent already allows create to guests via menu item too, so no check there too
  871. // Compute CREATE access permissions.
  872. if ( !$this->_id ) {
  873. // Check if general create permission is missing, NOTE: THIS CAN BE SOFT DENY
  874. // ... so we do need to check category 'create' privilege for all categories !!
  875. /*if ( !$user->authorise('core.create', 'com_flexicontent') ) {
  876. $iparams_extra->set('access-create', false);
  877. return $iparams_extra; // New item, so do not calculate EDIT, DELETE and VIEW access
  878. }*/
  879. // Check that user can create item in at least one category ... this check is not wasted,
  880. // since joomla will cache it and use it later during creation of allowed Category Tree
  881. $canCreate = $user->authorise('core.create', 'com_flexicontent');
  882. if ($canCreate === NULL) {
  883. $allowedcats = FlexicontentHelperPerm::getAllowedCats($user, array('core.create')
  884. , $require_all = true, $check_published = true, $specific_catids = false, $find_first = true
  885. );
  886. $canCreate = count($allowedcats) > 0;
  887. }
  888. $iparams_extra->set('access-create', $canCreate);
  889. return $iparams_extra; // New item, so do not calculate EDIT, DELETE and VIEW access
  890. }
  891. // Not a new item retrieve item if not already done
  892. if ( empty($this->_item) ) {
  893. $this->_item = $this->getItem();
  894. }
  895. // Compute EDIT access permissions.
  896. if ( $this->_id ) {
  897. // first check edit permission on the item
  898. if ($user->authorise('core.edit', $asset)) {
  899. $iparams_extra->set('access-edit', true);
  900. }
  901. // no edit permission, check if edit.own is available for this item
  902. else if ( $user->authorise('core.edit.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
  903. {
  904. $iparams_extra->set('access-edit', true);
  905. }
  906. }
  907. // Compute EDIT STATE access permissions.
  908. if ( $this->_id ) {
  909. // first check edit.state permission on the item
  910. if ($user->authorise('core.edit.state', $asset)) {
  911. $iparams_extra->set('access-edit-state', true);
  912. }
  913. // no edit.state permission, check if edit.state.own is available for this item
  914. else if ( $user->authorise('core.edit.state.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
  915. {
  916. $iparams_extra->set('access-edit-state', true);
  917. }
  918. }
  919. // Compute DELETE access permissions.
  920. if ( $this->_id ) {
  921. // first check delete permission on the item
  922. if ($user->authorise('core.delete', $asset)) {
  923. $iparams_extra->set('access-delete', true);
  924. }
  925. // no delete permission, chekc delete.own permission if the item is owned by the user
  926. else if ( $user->authorise('core.delete.own', $asset) && $user->get('id') == $this->_item->created_by /* && !$user->get('guest') */ )
  927. {
  928. $iparams_extra->set('access-delete', true);
  929. }
  930. }
  931. // Compute VIEW access permissions.
  932. if ($access = $this->getState('filter.access')) {
  933. // The access filter has been set,
  934. // we already know current user can view this item or we should not check access
  935. $iparams_extra->set('access-view', true);
  936. }
  937. else {
  938. // The access filter has not been set, we will set access flag(s) if not set already
  939. // the layout takes some responsibility for display of limited information,
  940. $groups = $user->getAuthorisedViewLevels();
  941. if ( !isset($this->_item->has_item_access) ) {
  942. $this->_item->has_item_access = in_array($this->_item->access, $groups);
  943. }
  944. if ( !isset($this->_item->has_mcat_access) ) {
  945. $no_mcat_info = $this->_item->catid == 0 || !isset($this->_item->category_access) || $this->_item->category_access === null;
  946. $this->_item->has_mcat_access = $no_mcat_info || in_array($this->_item->category_access, $groups);
  947. }
  948. if ( !isset($this->_item->has_type_access) ) {
  949. $no_type_info = $this->_item->type_id == 0 || !isset($this->_item->type_access) || $this->_item->type_access === null;
  950. $this->_item->has_type_access = $no_type_info || in_array($this->_item->type_access, $groups);
  951. }
  952. $iparams_extra->set('access-view', $this->_item->has_item_access && $this->_item->has_mcat_access && $this->_item->has_type_access);
  953. }
  954. return $iparams_extra;
  955. }
  956. /**
  957. * Method to check if you can assign a (new/existing) item in the specified categories
  958. *
  959. * @param array An array of input data.
  960. *
  961. * @return boolean
  962. * @since 1.6
  963. */
  964. protected function itemAllowedInCats($data = array())
  965. {
  966. // Initialise variables.
  967. $user = JFactory::getUser();
  968. $cats = isset($data['cid']) ? $data['cid'] : array();
  969. if ( !empty($data['catid']) && !in_array($data['catid'], $cats) ) {
  970. $cats[] = $data['catid'];
  971. }
  972. $allow = null;
  973. if (count($cats)) {
  974. $allow = true;
  975. foreach ($cats as $curcatid) {
  976. // If the category has been passed in the data or URL check it.
  977. $cat_allowed = $user->authorise('core.create', 'com_content.category.'.$curcatid);
  978. if (!$cat_allowed) {
  979. return JError::raiseWarning( 500, "No access to add item to category with id ".$curcatid );
  980. }
  981. $allow &= $cat_allowed;
  982. }
  983. }
  984. if ($allow === null) {
  985. // no categories specified, revert to the component permissions.
  986. $allow = $user->authorise('core.create', 'com_flexicontent');
  987. }
  988. return $allow;
  989. }
  990. //*************
  991. // EOF of J1.6+
  992. //*************
  993. //*************
  994. // BOF of J1.5
  995. //*************
  996. /**
  997. * Method (for J1.5) to check if the user can add an item anywhere
  998. *
  999. * @access public
  1000. * @return boolean True on success
  1001. * @since 1.5
  1002. */
  1003. function canAdd()
  1004. {
  1005. $user = JFactory::getUser();
  1006. if (FLEXI_ACCESS && ($user->gid < 25))
  1007. {
  1008. $canSubmit = FAccess::checkComponentAccess('com_content', 'submit', 'users', $user->gmid);
  1009. $canAdd = FAccess::checkAllContentAccess('com_content','add','users',$user->gmid,'content','all');
  1010. if (!$canSubmit && !$canAdd) return false;
  1011. } else {
  1012. $canAdd = $user->authorize('com_content', 'add', 'content', 'all');
  1013. if (!$canAdd) return false;
  1014. }
  1015. return true;
  1016. }
  1017. /**
  1018. * Method (for J1.5) to check if the user can edit the item
  1019. *
  1020. * @access public
  1021. * @return boolean True on success
  1022. * @since 1.5
  1023. */
  1024. function canEdit()
  1025. {
  1026. $user = JFactory::getUser();
  1027. if (!$this->_loadItem() || $user->gid >= 25) {
  1028. return true;
  1029. } else if (FLEXI_ACCESS) {
  1030. // This should not be used, as it bypasses individual item rights
  1031. //$canEditAll = FAccess::checkAllContentAccess('com_content','edit','users',$user->gmid,'content','all');
  1032. //$canEditOwnAll = FAccess::checkAllContentAccess('com_content','editown','users',$user->gmid,'content','all');
  1033. if ($this->_item->id && $this->_item->catid)
  1034. {
  1035. $rights = FAccess::checkAllItemAccess('com_content', 'users', $user->gmid, $this->_item->id, $this->_item->catid);
  1036. $canEdit = in_array('edit', $rights) /*|| $canEditAll*/;
  1037. $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