PageRenderTime 60ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/com_flexicontent_v2.x/admin/models/flexicontent.php

http://flexicontent.googlecode.com/
PHP | 2010 lines | 1217 code | 229 blank | 564 comment | 217 complexity | 3db079fba34fe8fdfa7b18b443cc7866 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: flexicontent.php 1650 2013-03-11 10:27:06Z 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.model');
  21. if (FLEXI_J16GE) jimport('joomla.access.accessrules');
  22. /**
  23. * FLEXIcontent Component Model
  24. *
  25. * @package Joomla
  26. * @subpackage FLEXIcontent
  27. * @since 1.0
  28. */
  29. class FlexicontentModelFlexicontent extends JModelLegacy
  30. {
  31. /**
  32. * Constructor
  33. *
  34. * @since 1.0
  35. */
  36. function __construct()
  37. {
  38. parent::__construct();
  39. }
  40. /**
  41. * Method to get items in pending state, waiting for publication approval
  42. *
  43. * @access public
  44. * @return array
  45. */
  46. function getPending()
  47. {
  48. $user = JFactory::getUser();
  49. if (FLEXI_J16GE) {
  50. $permission = FlexicontentHelperPerm::getPerm();
  51. $allitems = $permission->DisplayAllItems;
  52. } else if (FLEXI_ACCESS) {
  53. $allitems = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'displayallitems', 'users', $user->gmid) : 1;
  54. } else {
  55. $allitems = 1;
  56. }
  57. $query = 'SELECT SQL_CALC_FOUND_ROWS c.id, c.title, c.catid, c.created, cr.name as creator, c.created_by, c.modified, c.modified_by, mr.name as modifier'
  58. . ' FROM #__content as c'
  59. . ' LEFT JOIN #__categories as cat ON c.catid=cat.id'
  60. . ' LEFT JOIN #__users AS cr ON cr.id = c.created_by'
  61. . ' LEFT JOIN #__users AS mr ON mr.id = c.modified_by'
  62. . ' WHERE state = -3'
  63. . ' AND cat.extension="'.FLEXI_CAT_EXTENSION.'" ' //AND cat.lft >= ' . $this->_db->Quote(FLEXI_LFT_CATEGORY) . ' AND cat.rgt <= ' . $this->_db->Quote(FLEXI_RGT_CATEGORY)
  64. . ($allitems ? '' : ' AND c.created_by = '.$user->id)
  65. . ' ORDER BY c.created DESC'
  66. ;
  67. $this->_db->SetQuery($query, 0, 5);
  68. $genstats = $this->_db->loadObjectList();
  69. return $genstats;
  70. }
  71. /**
  72. * Method to get items revised, having unapproved version, waiting to be reviewed and approved
  73. *
  74. * @access public
  75. * @return array
  76. */
  77. function getRevised()
  78. {
  79. $user = JFactory::getUser();
  80. if (FLEXI_J16GE) {
  81. $permission = FlexicontentHelperPerm::getPerm();
  82. $allitems = $permission->DisplayAllItems;
  83. } else if (FLEXI_ACCESS) {
  84. $allitems = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'displayallitems', 'users', $user->gmid) : 1;
  85. } else {
  86. $allitems = 1;
  87. }
  88. $query = 'SELECT SQL_CALC_FOUND_ROWS c.id, c.title, c.catid, c.created, cr.name as creator, c.created_by, c.modified, c.modified_by, mr.name as modifier, c.version, MAX(fv.version_id) '
  89. . ' FROM #__content AS c'
  90. . ' LEFT JOIN #__flexicontent_versions AS fv ON c.id=fv.item_id'
  91. . ' LEFT JOIN #__categories as cat ON c.catid=cat.id'
  92. . ' LEFT JOIN #__users AS cr ON cr.id = c.created_by'
  93. . ' LEFT JOIN #__users AS mr ON mr.id = c.modified_by'
  94. . ' WHERE c.state = -5 OR c.state = 1'
  95. . ' AND cat.extension="'.FLEXI_CAT_EXTENSION.'" ' //AND cat.lft >= ' . $this->_db->Quote(FLEXI_LFT_CATEGORY) . ' AND cat.rgt <= ' . $this->_db->Quote(FLEXI_RGT_CATEGORY)
  96. . ($allitems ? '' : ' AND c.created_by = '.$user->id)
  97. . ' GROUP BY fv.item_id '
  98. . ' HAVING c.version<>MAX(fv.version_id) '
  99. . ' ORDER BY c.modified DESC'
  100. ;
  101. $this->_db->SetQuery($query, 0, 5);
  102. $genstats = $this->_db->loadObjectList();
  103. return $genstats;
  104. }
  105. /**
  106. * Method to get items in draft state, waiting to be written (and published)
  107. *
  108. * @access public
  109. * @return array
  110. */
  111. function getDraft()
  112. {
  113. $user = JFactory::getUser();
  114. if (FLEXI_J16GE) {
  115. $permission = FlexicontentHelperPerm::getPerm();
  116. $allitems = $permission->DisplayAllItems;
  117. } else if (FLEXI_ACCESS) {
  118. $allitems = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'displayallitems', 'users', $user->gmid) : 1;
  119. } else {
  120. $allitems = 1;
  121. }
  122. $query = 'SELECT SQL_CALC_FOUND_ROWS c.id, c.title, c.catid, c.created, cr.name as creator, c.created_by, c.modified, c.modified_by, mr.name as modifier'
  123. . ' FROM #__content as c'
  124. . ' LEFT JOIN #__categories as cat ON c.catid=cat.id'
  125. . ' LEFT JOIN #__users AS cr ON cr.id = c.created_by'
  126. . ' LEFT JOIN #__users AS mr ON mr.id = c.modified_by'
  127. . ' WHERE state = -4'
  128. . ' AND cat.extension="'.FLEXI_CAT_EXTENSION.'" ' //AND cat.lft >= ' . $this->_db->Quote(FLEXI_LFT_CATEGORY) . ' AND cat.rgt <= ' . $this->_db->Quote(FLEXI_RGT_CATEGORY)
  129. . ($allitems ? '' : ' AND c.created_by = '.$user->id)
  130. . ' ORDER BY c.created DESC'
  131. ;
  132. $this->_db->SetQuery($query, 0, 5);
  133. $genstats = $this->_db->loadObjectList();
  134. return $genstats;
  135. }
  136. /**
  137. * Method to get items in progress state, (published but) waiting to be completed
  138. *
  139. * @access public
  140. * @return array
  141. */
  142. function getInprogress()
  143. {
  144. $user = JFactory::getUser();
  145. if (FLEXI_J16GE) {
  146. $permission = FlexicontentHelperPerm::getPerm();
  147. $allitems = $permission->DisplayAllItems;
  148. } else if (FLEXI_ACCESS) {
  149. $allitems = ($user->gid < 25) ? FAccess::checkComponentAccess('com_flexicontent', 'displayallitems', 'users', $user->gmid) : 1;
  150. } else {
  151. $allitems = 1;
  152. }
  153. $query = 'SELECT SQL_CALC_FOUND_ROWS c.id, c.title, c.catid, c.created, cr.name as creator, c.created_by, c.modified, c.modified_by, mr.name as modifier'
  154. . ' FROM #__content as c'
  155. . ' LEFT JOIN #__categories as cat ON c.catid=cat.id'
  156. . ' LEFT JOIN #__users AS cr ON cr.id = c.created_by'
  157. . ' LEFT JOIN #__users AS mr ON mr.id = c.modified_by'
  158. . ' WHERE c.state = -5'
  159. . ' AND cat.extension="'.FLEXI_CAT_EXTENSION.'" ' //AND cat.lft >= ' . $this->_db->Quote(FLEXI_LFT_CATEGORY) . ' AND cat.rgt <= '. $this->_db->Quote(FLEXI_RGT_CATEGORY)
  160. . ($allitems ? '' : ' AND c.created_by = '.$user->id)
  161. . ' ORDER BY c.created DESC'
  162. ;
  163. $this->_db->SetQuery($query, 0, 5);
  164. $genstats = $this->_db->loadObjectList();
  165. return $genstats;
  166. }
  167. /**
  168. * Method to check if default Flexi Menu Items exist
  169. *
  170. * @access public
  171. * @return boolean True on success
  172. */
  173. function getExistMenuItems()
  174. {
  175. static $return;
  176. if ($return !== null) return $return;
  177. $public_acclevel = !FLEXI_J16GE ? 0 : 1;
  178. $app = JFactory::getApplication();
  179. // Get 'default_menu_itemid' parameter
  180. $params = JComponentHelper::getParams('com_flexicontent');
  181. if ($params) {
  182. $menus = $app->getMenu('site', array());
  183. $_component_default_menuitem_id = $params->get('default_menu_itemid', false);
  184. $menu = $menus->getItem($_component_default_menuitem_id);
  185. } else {
  186. $_component_default_menuitem_id = '';
  187. return $return = false;
  188. }
  189. $prompt = '<br>'.JText::_('FLEXI_DEFAULT_MENU_ITEM_PROMPT');
  190. // Check menu item exists
  191. $config_saved = (bool) $params->get('flexi_cat_extension');
  192. if ( !$menu ) {
  193. if ( $config_saved ) {
  194. $app->enqueueMessage( JText::_('FLEXI_DEFAULT_MENU_ITEM_MISSING_DISABLED').$prompt, 'notice' );
  195. }
  196. return $return = false;
  197. }
  198. // Check pointing to FLEXIcontent
  199. if ( @$menu->query['option']!='com_flexicontent' ) {
  200. $app->enqueueMessage( JText::_('FLEXI_DEFAULT_MENU_ITEM_ISNON_FLEXI').$prompt, 'notice' );
  201. return $return = false;
  202. }
  203. // Check public access level
  204. if ( $menu->access!=$public_acclevel ) {
  205. $app->enqueueMessage( JText::_('FLEXI_DEFAULT_MENU_ITEM_ISNON_PUBLIC').$prompt, 'notice' );
  206. return $return = false;
  207. }
  208. // Verify that language of menu item is not empty
  209. if ( FLEXI_J16GE && $menu->language=='' ) {
  210. $query = "UPDATE #__menu SET `language`='*' WHERE id=". (int)$_component_default_menuitem_id;
  211. $this->_db->setQuery($query);
  212. $result = $this->_db->query();
  213. }
  214. // All checks passed
  215. return $return = true;
  216. }
  217. /**
  218. * Method to check if there is at least one type created
  219. *
  220. * @access public
  221. * @return boolean True on success
  222. */
  223. function getExistType() {
  224. static $return;
  225. if ($return === NULL) {
  226. $return = false;
  227. $query = 'SELECT COUNT( id )'
  228. . ' FROM #__flexicontent_types'
  229. ;
  230. $this->_db->setQuery( $query );
  231. $count = $this->_db->loadResult();
  232. if ($count > 0) {
  233. $return = true;
  234. }
  235. }
  236. return $return;
  237. }
  238. /**
  239. * Method to check if there is at least the default fields in the FLEXIcontent fields TABLE
  240. *
  241. * @access public
  242. * @return boolean True on success
  243. */
  244. function getExistFields()
  245. {
  246. static $return;
  247. if ($return === NULL) {
  248. $return = false;
  249. $query = 'SELECT COUNT( id )'
  250. . ' FROM #__flexicontent_fields'
  251. ;
  252. $this->_db->setQuery( $query );
  253. $count = $this->_db->loadResult();
  254. if ($count > 13) {
  255. $return = true;
  256. }
  257. }
  258. return $return;
  259. }
  260. /**
  261. * Method to check if there is at least the default flexicontent_fields PLUGINs
  262. *
  263. * @access public
  264. * @return boolean True on success
  265. */
  266. function getExistFieldsPlugins()
  267. {
  268. static $return;
  269. if ($return === NULL) {
  270. $return = false;
  271. $query = 'SELECT COUNT( extension_id )'
  272. . ' FROM #__extensions'
  273. . ' WHERE `type`= '.$this->_db->Quote('plugin').' AND folder = ' . $this->_db->Quote('flexicontent_fields')
  274. ;
  275. $this->_db->setQuery( $query );
  276. $count = $this->_db->loadResult();
  277. if ($count > 13) {
  278. $return = true;
  279. }
  280. }
  281. return $return;
  282. }
  283. /**
  284. * Method to check if the search plugin is installed
  285. *
  286. * @access public
  287. * @return boolean True on success
  288. */
  289. function getExistSearchPlugin()
  290. {
  291. static $return;
  292. if ($return === NULL) {
  293. $query = 'SELECT COUNT( extension_id )'
  294. . ' FROM #__extensions'
  295. . ' WHERE `type`='.$this->_db->Quote('plugin').' AND element = ' . $this->_db->Quote('flexisearch')
  296. ;
  297. $this->_db->setQuery( $query );
  298. $return = $this->_db->loadResult() ? true : false;
  299. }
  300. return $return;
  301. }
  302. /**
  303. * Method to check if the system plugin is installed
  304. *
  305. * @access public
  306. * @return boolean True on success
  307. */
  308. function getExistSystemPlugin()
  309. {
  310. static $return;
  311. if ($return === NULL) {
  312. $query = 'SELECT COUNT( extension_id )'
  313. . ' FROM #__extensions'
  314. . ' WHERE `type`='.$this->_db->Quote('plugin').' AND element = ' . $this->_db->Quote('flexisystem')
  315. ;
  316. $this->_db->setQuery( $query );
  317. $return = $this->_db->loadResult() ? true : false;
  318. }
  319. return $return;
  320. }
  321. /**
  322. * Method to check if all plugins are published
  323. *
  324. * @access public
  325. * @return boolean True on success
  326. */
  327. function getAllPluginsPublished()
  328. {
  329. static $return;
  330. if ($return === NULL) {
  331. // Make sure basic CORE fields are published
  332. $q = 'UPDATE #__flexicontent_fields SET published=1 WHERE id > 0 AND id < 7';
  333. $this->_db->setQuery( $q );
  334. $this->_db->query();
  335. $query = 'SELECT COUNT( extension_id )'
  336. . ' FROM #__extensions'
  337. . ' WHERE `type`='.$this->_db->Quote('plugin').' AND '
  338. . ' ( folder = ' . $this->_db->Quote('flexicontent_fields')
  339. //. ' OR element = ' . $this->_db->Quote('flexisearch')
  340. . ' OR element = ' . $this->_db->Quote('flexisystem')
  341. //. ' OR element = ' . $this->_db->Quote('flexiadvsearch')
  342. . ' OR element = ' . $this->_db->Quote('flexiadvroute') . ')'
  343. . ' AND enabled <> 1'
  344. ;
  345. $this->_db->setQuery( $query );
  346. $return = $this->_db->loadResult() ? false : true;
  347. }
  348. return $return;
  349. }
  350. /**
  351. * Method to check if the language column exists
  352. *
  353. * @access public
  354. * @return boolean True on success
  355. */
  356. function getExistLanguageColumn()
  357. {
  358. static $return;
  359. if ($return === NULL) {
  360. if (FLEXI_J16GE) {
  361. $columns = $this->_db->getTableColumns('#__flexicontent_items_ext');
  362. $result_lang_col = array_key_exists('language', $columns) ? true : false;
  363. $result_tgrp_col = array_key_exists('lang_parent_id', $columns) ? true : false;
  364. } else {
  365. $fields = $this->_db->getTableFields('#__flexicontent_items_ext');
  366. $result_lang_col = array_key_exists('language', $fields['#__flexicontent_items_ext']) ? true : false;
  367. $result_tgrp_col = array_key_exists('lang_parent_id', $fields['#__flexicontent_items_ext']) ? true : false;
  368. }
  369. $return = $result_lang_col && $result_tgrp_col;
  370. }
  371. return $return;
  372. }
  373. /**
  374. * Method to get if main category of items exists in both category table and in flexicontent category-items relation table
  375. *
  376. * @access public
  377. * @return boolean True on success
  378. * @since 1.5
  379. */
  380. function getItemsNoCat()
  381. {
  382. static $return;
  383. if ($return === NULL) {
  384. $db = JFactory::getDBO();
  385. $query = "SELECT i.id"
  386. ." FROM #__content AS i"
  387. ." LEFT JOIN #__flexicontent_cats_item_relations as rel ON rel.catid=i.catid AND i.id=rel.itemid "
  388. ." WHERE rel.catid IS NULL"
  389. ." LIMIT 1";
  390. $db->setQuery($query);
  391. $item_id = $db->loadResult();
  392. if ($item_id) {
  393. $query = "SELECT item_id "
  394. ." FROM #__flexicontent_items_ext as ie"
  395. ." WHERE item_id = ". $item_id;
  396. $db->setQuery($query);
  397. $item_id = $db->loadResult();
  398. }
  399. $return = $item_id ? 1 : 0;
  400. }
  401. return $return;
  402. }
  403. /**
  404. * Method to get if language of items is initialized properly
  405. *
  406. * @access public
  407. * @return boolean True on success
  408. * @since 1.5
  409. */
  410. function getItemsNoLang()
  411. {
  412. static $return;
  413. if ($return === NULL) {
  414. $enable_translation_groups = JComponentHelper::getParams( 'com_flexicontent' )->get("enable_translation_groups") && ( FLEXI_J16GE || FLEXI_FISH ) ;
  415. $db = JFactory::getDBO();
  416. /*$query = "SELECT COUNT(*) FROM #__flexicontent_items_ext as ie "
  417. . (FLEXI_J16GE ? " LEFT JOIN #__content as i ON i.id=ie.item_id " : "")
  418. . " WHERE ie.language='' " . ($enable_translation_groups ? " OR ie.lang_parent_id='0' " : "")
  419. . (FLEXI_J16GE ? " OR i.language='' OR i.language<>ie.language " : "")
  420. ;*/
  421. $query = "SELECT COUNT(*)"
  422. ." FROM #__flexicontent_items_ext as ie"
  423. ." WHERE ie.language='' " . ($enable_translation_groups ? " OR ie.lang_parent_id='0' " : "")
  424. ." LIMIT 1";
  425. $db->setQuery($query);
  426. $cnt1 = $db->loadResult();
  427. $cnt2 = 0;
  428. if (FLEXI_J16GE) {
  429. $query = "SELECT COUNT(*)"
  430. ." FROM #__content as i"
  431. ." WHERE i.language=''"
  432. ." LIMIT 1";
  433. $db->setQuery($query);
  434. $cnt2 = $db->loadResult();
  435. }
  436. $return = $cnt1 || $cnt2;
  437. }
  438. return $return;
  439. }
  440. /**
  441. * Method to get if some items do not have their no index columns up to date with the main content table (these are used for item counting)
  442. *
  443. * @access public
  444. * @return boolean True on success
  445. * @since 1.5
  446. */
  447. function getItemCountingDataOK()
  448. {
  449. static $return;
  450. if ($return === NULL) {
  451. $db = JFactory::getDBO();
  452. // Find columns cached
  453. $cache_tbl = "#__flexicontent_items_tmp";
  454. $tbls = array($cache_tbl);
  455. if (!FLEXI_J16GE) $tbl_fields = $db->getTableFields($tbls);
  456. else foreach ($tbls as $tbl) $tbl_fields[$tbl] = $db->getTableColumns($tbl);
  457. // Get the column names
  458. $tbl_fields = array_keys($tbl_fields[$cache_tbl]);
  459. $query = "SELECT COUNT(*)"
  460. . " FROM #__content AS i "
  461. . " LEFT JOIN ".$cache_tbl." AS ca ON i.id=ca.id "
  462. .(!FLEXI_J16GE ? " JOIN #__flexicontent_items_ext AS ext ON i.id = ext.item_id" : "")
  463. . " WHERE ca.id IS NULL ";
  464. foreach ($tbl_fields as $col_name) {
  465. if ($col_name == "id" || $col_name == "hits") continue;
  466. else if (!FLEXI_J16GE && $col_name == "language" )
  467. $query .= " OR ext.`language`<>ca.`language`";
  468. else
  469. $query .= " OR i.`".$col_name."`<>ca.`".$col_name."`";
  470. }
  471. $db->setQuery($query);
  472. $return = $this->_db->loadResult() ? false : true;
  473. if ($this->_db->getErrorNum()) echo $this->_db->getErrorMsg();
  474. }
  475. return $return;
  476. }
  477. /**
  478. * Method to check if the versions table is created
  479. *
  480. * @access public
  481. * @return boolean True on success
  482. */
  483. function getExistVersionsTable()
  484. {
  485. static $return;
  486. if ($return === NULL) {
  487. $query = 'SHOW TABLES LIKE ' . $this->_db->Quote('%flexicontent_versions');
  488. $this->_db->setQuery($query);
  489. $return = $this->_db->loadResult() ? true : false;
  490. }
  491. return $return;
  492. }
  493. /**
  494. * Method to check if the versions table is created
  495. *
  496. * @access public
  497. * @return boolean True on success
  498. */
  499. function getExistAuthorsTable()
  500. {
  501. static $return;
  502. if ($return === NULL) {
  503. $query = 'SHOW TABLES LIKE ' . $this->_db->Quote('%flexicontent_authors_ext');
  504. $this->_db->setQuery($query);
  505. $return = $this->_db->loadResult() ? true : false;
  506. }
  507. return $return;
  508. }
  509. /**
  510. * Method to check if the versions table is created
  511. *
  512. * @access public
  513. * @return boolean True on success
  514. */
  515. function getExistDBindexes()
  516. {
  517. static $return;
  518. if ($return === NULL) {
  519. $app = JFactory::getApplication();
  520. $dbprefix = $app->getCfg('dbprefix');
  521. $dbname = $app->getCfg('db');
  522. $query = "SELECT COUNT(1) IndexIsThere "
  523. ." FROM INFORMATION_SCHEMA.STATISTICS"
  524. ." WHERE table_schema='".$dbname."' AND table_name='".$dbprefix."flexicontent_fields_item_relations' AND index_name='value'";
  525. $this->_db->setQuery($query);
  526. $return = $this->_db->loadResult() ? true : false;
  527. }
  528. return $return;
  529. }
  530. /**
  531. * Method to check if the system plugin is installed
  532. *
  533. * @access public
  534. * @return boolean True on success
  535. */
  536. function getExistVersionsPopulated() {
  537. static $return;
  538. if ($return === NULL) {
  539. $query = 'SELECT COUNT( version )'
  540. . ' FROM #__flexicontent_items_versions'
  541. ;
  542. $this->_db->setQuery( $query );
  543. if(!$this->_db->loadResult()) {
  544. $return = true;
  545. } else {
  546. $query = 'SELECT COUNT( id )'
  547. . ' FROM #__flexicontent_versions'
  548. ;
  549. $this->_db->setQuery( $query );
  550. $return = $this->_db->loadResult() ? true : false;
  551. }
  552. }
  553. return $return;
  554. }
  555. /**
  556. * Method to check if the permissions of Phpthumb cache folder
  557. *
  558. * @access public
  559. * @return boolean True on success
  560. */
  561. function getCacheThumbChmod()
  562. {
  563. static $return;
  564. if ($return === null) {
  565. // Try to open phpThumb cache directory
  566. $phpthumbcache = JPath::clean(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'librairies'.DS.'phpthumb'.DS.'cache');
  567. $return = preg_match('/rwxr.xr.x/i', JPath::getPermissions($phpthumbcache) ) ? true : false;
  568. }
  569. return $return;
  570. }
  571. /**
  572. * Method to check if the files from beta3 still exist in the category and item view
  573. *
  574. * @access public
  575. * @return boolean True on success
  576. */
  577. function getOldBetaFiles() {
  578. static $return;
  579. if ($return!==null) return $return;
  580. jimport('joomla.filesystem.folder');
  581. $files = array (
  582. 'author.xml',
  583. 'author.php',
  584. 'myitems.xml',
  585. 'myitems.php',
  586. 'mcats.xml',
  587. 'mcats.php',
  588. 'default.xml',
  589. 'default.php',
  590. 'index.html',
  591. 'form.php',
  592. 'form.xml'
  593. );
  594. $catdir = JPath::clean(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'views'.DS.'category'.DS.'tmpl');
  595. $cattmpl = JFolder::files($catdir);
  596. $ctmpl = array_diff($cattmpl,$files);
  597. $itemdir = JPath::clean(JPATH_SITE.DS.'components'.DS.'com_flexicontent'.DS.'views'.DS.FLEXI_ITEMVIEW.DS.'tmpl');
  598. $itemtmpl = JFolder::files($itemdir);
  599. $itmpl = array_diff($itemtmpl,$files);
  600. $return = ($ctmpl || $itmpl) ? false : true;
  601. return $return;
  602. }
  603. /**
  604. * Method to check if the field positions were converted
  605. * and if not, convert them
  606. *
  607. * @access public
  608. * @return boolean True on success
  609. */
  610. function getFieldsPositions()
  611. {
  612. $query = "SELECT name, positions"
  613. . " FROM #__flexicontent_fields"
  614. . " WHERE positions <> ''"
  615. ;
  616. $this->_db->setQuery( $query );
  617. $fields = $this->_db->loadObjectList();
  618. if ($fields) {
  619. // create a temporary table to store the positions
  620. $this->_db->setQuery( "DROP TABLE IF EXISTS #__flexicontent_positions_tmp" );
  621. $this->_db->query();
  622. $query = "
  623. CREATE TABLE #__flexicontent_positions_tmp (
  624. `field` varchar(100) NOT NULL default '',
  625. `view` varchar(30) NOT NULL default '',
  626. `folder` varchar(100) NOT NULL default '',
  627. `position` varchar(255) NOT NULL default ''
  628. ) ENGINE=MyISAM DEFAULT CHARSET=utf8
  629. ";
  630. $this->_db->setQuery( $query );
  631. $this->_db->query();
  632. foreach ($fields as $field) {
  633. $field->positions = explode("\n", $field->positions);
  634. foreach ($field->positions as $pos) {
  635. $pos = explode('.', $pos);
  636. $query = 'INSERT INTO #__flexicontent_positions_tmp (`field`, `view`, `folder`, `position`) VALUES(' . $this->_db->Quote($field->name) . ',' . $this->_db->Quote($pos[1]) . ',' . $this->_db->Quote($pos[2]) . ',' . $this->_db->Quote($pos[0]) . ')';
  637. $this->_db->setQuery($query);
  638. $this->_db->query();
  639. }
  640. }
  641. $templates = flexicontent_tmpl::getTemplates();
  642. $folders = flexicontent_tmpl::getThemes();
  643. $views = array('items', 'category');
  644. foreach ($folders as $folder) {
  645. foreach ($views as $view) {
  646. $groups = @$templates->{$view}->{$folder}->positions;
  647. if ($groups) {
  648. foreach ($groups as $group) {
  649. $query = 'SELECT field'
  650. . ' FROM #__flexicontent_positions_tmp'
  651. . ' WHERE view = ' . $this->_db->Quote($view)
  652. . ' AND folder = ' . $this->_db->Quote($folder)
  653. . ' AND position = ' . $this->_db->Quote($group)
  654. ;
  655. $this->_db->setQuery( $query );
  656. $fieldstopos = FLEXI_J16GE ? $this->_db->loadColumn() : $this->_db->loadResultArray();
  657. if ($fieldstopos) {
  658. $field = implode(',', $fieldstopos);
  659. $query = 'INSERT INTO #__flexicontent_templates (`template`, `layout`, `position`, `fields`) VALUES(' . $this->_db->Quote($folder) . ',' . $this->_db->Quote($view) . ',' . $this->_db->Quote($group) . ',' . $this->_db->Quote($field) . ')';
  660. $this->_db->setQuery($query);
  661. $this->_db->query();
  662. }
  663. }
  664. }
  665. }
  666. }
  667. // delete the temporary table
  668. $query = 'DROP TABLE #__flexicontent_positions_tmp';
  669. $this->_db->setQuery( $query );
  670. $this->_db->query();
  671. // delete the old positions
  672. $query = "UPDATE #__flexicontent_fields SET positions = ''";
  673. $this->_db->setQuery( $query );
  674. $this->_db->query();
  675. // alter ordering field for releases prior to beta5
  676. $query = "ALTER TABLE #__flexicontent_cats_item_relations MODIFY `ordering` int(11) NOT NULL default '0'";
  677. $this->_db->setQuery( $query );
  678. $this->_db->query();
  679. $query = "ALTER TABLE #__flexicontent_fields_type_relations MODIFY `ordering` int(11) NOT NULL default '0'";
  680. $this->_db->setQuery( $query );
  681. $this->_db->query();
  682. }
  683. return $fields;
  684. }
  685. /**
  686. * Method to check if there are still old core fields data in the fields_items_relations table
  687. *
  688. * @access public
  689. * @return boolean True on success
  690. */
  691. function getNoOldFieldsData()
  692. {
  693. static $return;
  694. if ($return === NULL) {
  695. $query = 'SELECT COUNT( item_id )'
  696. . ' FROM #__flexicontent_fields_item_relations'
  697. . ' WHERE field_id < 13'
  698. ;
  699. $this->_db->setQuery( $query );
  700. $return = $this->_db->loadResult() ? false : true;
  701. }
  702. return $return;
  703. }
  704. /**
  705. * Method to check if there is at least one category created
  706. *
  707. * @access public
  708. * @return boolean True on success
  709. */
  710. function getExistcat()
  711. {
  712. $query = 'SELECT COUNT( id )'
  713. . ' FROM #__categories as cat'
  714. . ' WHERE cat.extension="'.FLEXI_CAT_EXTENSION.'" AND lft> ' . $this->_db->Quote(FLEXI_LFT_CATEGORY) . ' AND rgt<' . $this->_db->Quote(FLEXI_RGT_CATEGORY)
  715. ;
  716. $this->_db->setQuery( $query );
  717. $count = $this->_db->loadResult();
  718. if ($count > 0) {
  719. return true;
  720. }
  721. return false;
  722. }
  723. /**
  724. * Method to check if FLEXI_SECTION (or FLEXI_CAT_EXTENSION for J1.6+) still exists
  725. *
  726. * @access public
  727. * @return boolean True on success
  728. */
  729. function getExistsec()
  730. {
  731. if (FLEXI_CAT_EXTENSION) {
  732. $query = 'SELECT COUNT( id )'
  733. . ' FROM #__categories'
  734. . ' WHERE id = 1 AND extension=\'system\''
  735. ;
  736. $this->_db->setQuery( $query );
  737. $count = $this->_db->loadResult();
  738. if ($count > 0) {
  739. return true;
  740. } else {
  741. die("Category table corrupterd, SYSTEM root category not found");
  742. }
  743. }
  744. return false;
  745. }
  746. /**
  747. * Method to check if there is at list one menu item is created
  748. *
  749. * @access public
  750. * @return boolean True on success
  751. */
  752. function getExistmenu()
  753. {
  754. $component = JComponentHelper::getComponent('com_flexicontent');
  755. $app = JFactory::getApplication();
  756. if(FLEXI_J16GE) {
  757. $query = "SELECT COUNT(*) FROM #__menu WHERE `type`='component' AND `published`=1 AND `component_id`='{$component->id}' ";
  758. $this->_db->setQuery($query);
  759. $count = $this->_db->loadResult();
  760. } else {
  761. $menus = $app->getMenu('site', array());
  762. $items = $menus->getItems('componentid', $component->id);
  763. $count = count($items);
  764. }
  765. if ($count > 0) {
  766. return true;
  767. }
  768. return false;
  769. }
  770. /**
  771. * Method to check and add some extra FLEXIcontent specific ACL rules
  772. *
  773. * @access public
  774. * @return boolean True on success
  775. */
  776. function checkExtraAclRules()
  777. {
  778. if (FLEXI_ACCESS)
  779. {
  780. $db = $this->_db;
  781. // COMMENTED out, instead we will use field's 'submit' privilege
  782. /*$query = "SELECT count(*) FROM `#__flexiaccess_rules` WHERE acosection='com_flexicontent' AND aco='editvalue' AND axosection='fields'";
  783. $db->setQuery($query);
  784. $editvalue_rule = $db->loadResult();
  785. if (!$editvalue_rule)
  786. {
  787. $query = "INSERT INTO #__flexiaccess_rules (`acosection`, `variable`, `aco`, `axosection`, `axo`, `label`, `source`, `ordering`)"
  788. ." VALUES ('com_flexicontent', '', 'editvalue', 'fields', '', 'Edit Field Values', '', '')";
  789. $db->setQuery($query);
  790. $db->query();
  791. JFactory::getApplication()->enqueueMessage( 'Added ACL Rule: '. JText::_('FLEXI_EDIT_FIELD_VALUE'), 'message' );
  792. }*/
  793. // Delete wrong rule names
  794. $query = "DELETE FROM #__flexiaccess_rules WHERE acosection='com_flexicontent' AND aco='associateanyitem'";
  795. $db->setQuery($query);
  796. $db->query();
  797. // Check for assocanytrans : Allow users to associate translations (items) authored by any user
  798. $query = "SELECT COUNT(*) FROM `#__flexiaccess_rules` WHERE acosection='com_flexicontent' AND aco='assocanytrans'";
  799. $db->setQuery($query);
  800. $assocanytrans_rule = $db->loadResult();
  801. if (!$assocanytrans_rule)
  802. {
  803. $query = "INSERT INTO #__flexiaccess_rules (`acosection`, `variable`, `aco`, `axosection`, `axo`, `label`, `source`, `ordering`)"
  804. ." VALUES ('com_flexicontent', '', 'assocanytrans', '', '', 'Associate any translation (items)', '', '')";
  805. $db->setQuery($query);
  806. $db->query();
  807. JFactory::getApplication()->enqueueMessage( 'Added ACL Rule: '. JText::_('FLEXI_ASSOCIATE_ANY_TRANSLATION'), 'message' );
  808. }
  809. // Check for editcreationdate : Allow users to edit creation date of an item
  810. /*$query = "SELECT COUNT(*) FROM `#__flexiaccess_rules` WHERE acosection='com_flexicontent' AND aco='editcreationdate'";
  811. $db->setQuery($query);
  812. $editcreationdate_rule = $db->loadResult();
  813. if (!$editcreationdate_rule)
  814. {
  815. $query = "INSERT INTO #__flexiaccess_rules (`acosection`, `variable`, `aco`, `axosection`, `axo`, `label`, `source`, `ordering`)"
  816. ." VALUES ('com_flexicontent', '', 'editcreationdate', '', '', 'Edit creation date (items)', '', '')";
  817. $db->setQuery($query);
  818. $db->query();
  819. JFactory::getApplication()->enqueueMessage( 'Added ACL Rule: '. JText::_('FLEXI_EDIT_CREATION_DATE'), 'message' );
  820. }*/
  821. // Check for ignoreviewstate : Allow users to view unpublished, archived, trashed, scheduled, expired items in frontend content lists e.g. category view
  822. $query = "SELECT COUNT(*) FROM `#__flexiaccess_rules` WHERE acosection='com_flexicontent' AND aco='ignoreviewstate'";
  823. $db->setQuery($query);
  824. $ignoreviewstate_rule = $db->loadResult();
  825. if (!$ignoreviewstate_rule)
  826. {
  827. $query = "INSERT INTO #__flexiaccess_rules (`acosection`, `variable`, `aco`, `axosection`, `axo`, `label`, `source`, `ordering`)"
  828. ." VALUES ('com_flexicontent', '', 'ignoreviewstate', '', '', 'Ignore view state (items)', '', '')";
  829. $db->setQuery($query);
  830. $db->query();
  831. JFactory::getApplication()->enqueueMessage( 'Added ACL Rule: '. JText::_('FLEXI_IGNORE_VIEW_STATE'), 'message' );
  832. }
  833. // Check for import : Allow management of (Content) Import
  834. $query = "SELECT COUNT(*) FROM `#__flexiaccess_rules` WHERE acosection='com_flexicontent' AND aco='import'";
  835. $db->setQuery($query);
  836. $import_rule = $db->loadResult();
  837. if (!$import_rule)
  838. {
  839. $query = "INSERT INTO #__flexiaccess_rules (`acosection`, `variable`, `aco`, `axosection`, `axo`, `label`, `source`, `ordering`)"
  840. ." VALUES ('com_flexicontent', '', 'import', '', '', 'Manage (Content) Import', '', '')";
  841. $db->setQuery($query);
  842. $db->query();
  843. JFactory::getApplication()->enqueueMessage( 'Added ACL Rule: '. JText::_('FLEXI_MANAGE_CONTENT_IMPORT'), 'message' );
  844. }
  845. }
  846. }
  847. function getDiffVersions($current_versions=array(), $last_versions=array())
  848. {
  849. // check if the category was chosen to avoid adding data on static contents
  850. if (!FLEXI_CAT_EXTENSION) return array();
  851. if(!$current_versions) {
  852. $current_versions = FLEXIUtilities::getCurrentVersions();
  853. }
  854. if(!$last_versions) {
  855. $last_versions = FLEXIUtilities::getLastVersions();
  856. }
  857. $difference = $current_versions;
  858. foreach($current_versions as $key1 => $value1) {
  859. foreach($last_versions as $key2 => $value2) {
  860. if( ($value1["id"]==$value2["id"]) && ($value1["version"]==$value2["version"]) ) {
  861. unset($difference[$key1]);
  862. }
  863. }
  864. }
  865. return $difference;
  866. }
  867. function checkCurrentVersionData() {
  868. // verify that every current version is in the versions table and it's data in the flexicontent_items_versions table
  869. //$and = "";
  870. // check if the section was chosen to avoid adding data on static contents
  871. if (!FLEXI_CAT_EXTENSION) return false;
  872. return FLEXIUtilities::currentMissing();
  873. }
  874. function addCurrentVersionData($item_id = null, $clean_database = false)
  875. {
  876. // check if the section was chosen to avoid adding data on static contents
  877. if (!FLEXI_CAT_EXTENSION) return true;
  878. $db = &$this->_db;
  879. $nullDate = $db->getNullDate();
  880. // @TODO: move somewhere else
  881. $this->formatFlexiPlugins();
  882. // Clean categories cache
  883. $catscache = JFactory::getCache('com_flexicontent_cats');
  884. $catscache->clean();
  885. // Get some basic info of all items, or of the given item
  886. $query = "SELECT c.id,c.catid,c.version,c.created,c.modified,c.created_by,c.introtext,c.`fulltext`"
  887. ." FROM #__content as c"
  888. . " JOIN #__categories as cat ON c.catid=cat.id "
  889. ." WHERE cat.extension='".FLEXI_CAT_EXTENSION."'" // ."AND cat.lft >= ".$this->_db->Quote(FLEXI_LFT_CATEGORY)." AND cat.rgt <= ".$this->_db->Quote(FLEXI_RGT_CATEGORY).";";
  890. .($item_id ? " AND c.id=".$item_id : "")
  891. ;
  892. $db->setQuery($query);
  893. $rows = $db->loadObjectList('id');
  894. if (!$item_id) {
  895. // Get current version ids of ALL ITEMS not having current versions
  896. $diff_arrays = $this->getDiffVersions();
  897. } else {
  898. // Get current version id of a SPECIFIC ITEM
  899. $diff_arrays = array( FLEXIUtilities::getCurrentVersions($item_id) );
  900. }
  901. $jcorefields = flexicontent_html::getJCoreFields();
  902. $add_cats = true;
  903. $add_tags = true;
  904. // For all items not having the current version, add it
  905. foreach($diff_arrays as $item)
  906. {
  907. $item_id = @ (int)$item["id"];
  908. if( isset( $rows[$item_id] ) )
  909. {
  910. $row = & $rows[$item_id];
  911. // Get field values of the current item version
  912. $query = "SELECT f.id,fir.value,f.field_type,f.name,fir.valueorder,f.iscore "
  913. ." FROM #__flexicontent_fields_item_relations as fir"
  914. //." LEFT JOIN #__flexicontent_items_versions as iv ON iv.field_id="
  915. ." LEFT JOIN #__flexicontent_fields as f on f.id=fir.field_id "
  916. ." WHERE fir.item_id=".$row->id." AND f.iscore=0"; // old versions stored categories & tags into __flexicontent_fields_item_relations
  917. $db->setQuery($query);
  918. $fieldsvals = $db->loadObjectList();
  919. // Delete existing unversioned (current version) field values ONLY if we are asked to 'clean' the database
  920. if ($clean_database && $fieldsvals) {
  921. $query = 'DELETE FROM #__flexicontent_fields_item_relations WHERE item_id = '.$row->id;
  922. $db->setQuery($query);
  923. $db->query();
  924. }
  925. // Delete any existing versioned field values to avoid conflicts, this maybe redudant, since they should not exist,
  926. // but we do it anyway because someone may have truncated or delete records only in table 'flexicontent_versions' ...
  927. // NOTE: we do not delete data with field_id negative as these exist only in the versioning table
  928. $query = 'DELETE FROM #__flexicontent_items_versions WHERE item_id = '.$row->id .' AND version= '.$row->version.' AND field_id > 0';
  929. $db->setQuery($query);
  930. $db->query();
  931. // Add the 'maintext' field to the fields array for adding to versioning table
  932. $f = new stdClass();
  933. $f->id = 1;
  934. $f->iscore = 1;
  935. $f->valueorder = 1;
  936. $f->field_type = "maintext";
  937. $f->name = "text";
  938. $f->value = $row->introtext;
  939. if ( JString::strlen($row->fulltext) > 1 ) {
  940. $f->value .= '<hr id="system-readmore" />' . $row->fulltext;
  941. }
  942. if(substr($f->value, 0, 3)!="<p>") {
  943. $f->value = "<p>".$f->value."</p>";
  944. }
  945. $fieldsvals[] = $f;
  946. // Add the 'categories' field to the fields array for adding to versioning table
  947. $query = "SELECT catid FROM #__flexicontent_cats_item_relations WHERE itemid='".$row->id."';";
  948. $db->setQuery($query);
  949. $categories = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
  950. if(!$categories || !count($categories)) {
  951. $categories = array($catid = $row->catid);
  952. $query = "INSERT INTO #__flexicontent_cats_item_relations VALUES('$catid','".$row->id."', '0');";
  953. $db->setQuery($query);
  954. $db->query();
  955. }
  956. $f = new stdClass();
  957. $f->id = 13;
  958. $f->iscore = 1;
  959. $f->valueorder = 1;
  960. $f->version = (int)$row->version;
  961. $f->value = serialize($categories);
  962. if ($add_cats) $fieldsvals[] = $f;
  963. // Add the 'tags' field to the fields array for adding to versioning table
  964. $query = "SELECT tid FROM #__flexicontent_tags_item_relations WHERE itemid='".$row->id."';";
  965. $db->setQuery($query);
  966. $tags = FLEXI_J16GE ? $db->loadColumn() : $db->loadResultArray();
  967. $f = new stdClass();
  968. $f->id = 14;
  969. $f->iscore = 1;
  970. $f->valueorder = 1;
  971. $f->version = (int)$row->version;
  972. $f->value = serialize($tags);
  973. if ($add_tags) $fieldsvals[] = $f;
  974. // Add field values to field value versioning table
  975. foreach($fieldsvals as $fieldval) {
  976. // add the new values to the database
  977. $obj = new stdClass();
  978. $obj->field_id = $fieldval->id;
  979. $obj->item_id = $row->id;
  980. $obj->valueorder = $fieldval->valueorder;
  981. $obj->version = (int)$row->version;
  982. $obj->value = $fieldval->value;
  983. //echo "version: ".$obj->version.",fieldid : ".$obj->field_id.",value : ".$obj->value.",valueorder : ".$obj->valueorder."<br />";
  984. //echo "inserting into __flexicontent_items_versions<br />";
  985. $db->insertObject('#__flexicontent_items_versions', $obj);
  986. if( $clean_database && !$fieldval->iscore ) { // If clean_database is on we need to re-add the deleted values
  987. unset($obj->version);
  988. //echo "inserting into __flexicontent_fields_item_relations<br />";
  989. $db->insertObject('#__flexicontent_fields_item_relations', $obj);
  990. }
  991. //$searchindex .= @$fieldval->search;
  992. }
  993. // **********************************************************************************
  994. // Add basic METADATA of current item version (kept in table #__flexicontent_versions)
  995. // **********************************************************************************
  996. $v = new stdClass();
  997. $v->item_id = (int)$row->id;
  998. $v->version_id = (int)$row->version;
  999. $v->created = ($row->modified && ($row->modified != $nullDate)) ? $row->modified : $row->created;
  1000. $v->created_by = $row->created_by;
  1001. $v->comment = '';
  1002. //echo "inserting into __flexicontent_versions<br />";
  1003. $db->insertObject('#__flexicontent_versions', $v);
  1004. }
  1005. }
  1006. return true;
  1007. }
  1008. function formatFlexiPlugins()
  1009. {
  1010. $db = $this->_db;
  1011. $tbl = FLEXI_J16GE ? '#__extensions' : '#__plugins';
  1012. $idcol = FLEXI_J16GE ? 'extension_id' : 'id';
  1013. $query = 'SELECT '.$idcol.' AS id, name, element FROM '.$tbl
  1014. . ' WHERE folder =' . $db->Quote('flexicontent_fields')
  1015. . (FLEXI_J16GE ? ' AND `type`=' . $db->Quote('plugin') : '')
  1016. ;
  1017. $db->setQuery($query);
  1018. $flexiplugins = $db->loadObjectList();
  1019. $query = 'UPDATE '.$tbl.' SET name = CASE '.$idcol;
  1020. $cases = array();
  1021. $ext_ids = array();
  1022. foreach ($flexiplugins as $fp) {
  1023. if ( substr($fp->name, 0, 15) == 'FLEXIcontent - ' ) continue;
  1024. $cases[] = ' WHEN '.(int)$fp->id.' THEN '.$db->Quote('FLEXIcontent - '.$fp->name);
  1025. $ext_ids[] = $fp->id;
  1026. }
  1027. $ext_ids_list = implode(', ', $ext_ids);
  1028. $query .= implode(' ',$cases)
  1029. . ' END'
  1030. . ' WHERE '.$idcol.' IN ('.$ext_ids_list.')'
  1031. . ' AND folder =' . $db->Quote('flexicontent_fields')
  1032. . (FLEXI_J16GE ? ' AND `type`=' . $db->Quote('plugin') : '')
  1033. ;
  1034. if ( count($cases) ) {
  1035. $db->setQuery($query);
  1036. $db->query();
  1037. if ($db->getErrorNum()) echo $db->getErrorMsg();
  1038. }
  1039. /*$map = array(
  1040. 'addressint'=>'FLEXIcontent - Address International / Google Maps',
  1041. 'checkbox'=>'FLEXIcontent - Checkbox',
  1042. 'checkboximage'=>'FLEXIcontent - Checkbox Image',
  1043. 'core'=>'FLEXIcontent - Core Fields (Joomla article properties)',
  1044. 'date'=>'FLEXIcontent - Date / Publish Up-Down Dates',
  1045. 'email'=>'FLEXIcontent - Email',
  1046. 'extendedweblink'=>'FLEXIcontent - Extended Weblink',
  1047. 'fcloadmodule'=>'FLEXIcontent - Load Module / Module position',
  1048. 'fcpagenav'=>'FLEXIcontent - Navigation (Next/Previous Item)',
  1049. 'file'=>'FLEXIcontent - File (Download/View/Share/Download cart)',
  1050. 'groupmarker'=>'FLEXIcontent - Item Form Tab / Fieldset / Custom HTML',
  1051. 'image'=>'FLEXIcontent - Image or Gallery (image + details)',
  1052. 'linkslist'=>'FLEXIcontent - HTML list of URLs/Anchors/JS links',
  1053. 'minigallery'=>'FLEXIcontent - Mini-Gallery (image-only slideshow)',
  1054. 'phonenumbers'=>'FLEXIcontent - Phone Numbers',
  1055. 'radio'=>'FLEXIcontent - Radio',
  1056. 'radioimage'=>'FLEXIcontent - Radio Image',
  1057. 'relation'=>'FLEXIcontent - Relation (List of related items)',
  1058. 'relation_reverse'=>'FLEXIcontent - Relation - Reverse',
  1059. 'select'=>'FLEXIcontent - Select',
  1060. 'selectmultiple'=>'FLEXIcontent - Select Multiple',
  1061. 'sharedaudio'=>'FLEXIcontent - Shared Audio (youtube,vimeo,dailymotion,etc)',
  1062. 'sharedvideo'=>'FLEXIcontent - Shared Video (youtube,vimeo,dailymotion,etc)',
  1063. 'text'=>'FLEXIcontent - Text (number/time/etc/custom validation)',
  1064. 'textarea'=>'FLEXIcontent - Textarea',
  1065. 'textselect'=>'FLEXIcontent - TextSelect (Text with existing value selection)',
  1066. 'toolbar'=>'FLEXIcontent - Toolbar (social share/other tools)',
  1067. 'weblink'=>'FLEXIcontent - Weblink'
  1068. );
  1069. $query = 'UPDATE '.$tbl.' SET name = CASE element';
  1070. $cases = array();
  1071. $elements = array();
  1072. foreach ($flexiplugins as $fp) {
  1073. if ( empty($map[$fp->element]) ) continue;
  1074. $cases[] = ' WHEN '.$db->Quote($fp->element).' THEN '.$db->Quote($map[$fp->element]);
  1075. $elements[] = $db->Quote($fp->element);
  1076. }
  1077. $elements_list = implode(', ', $elements);
  1078. $query .= implode(' ',$cases)
  1079. . ' END'
  1080. . ' WHERE folder =' . $db->Quote('flexicontent_fields')
  1081. . (FLEXI_J16GE ? ' AND `type`='. $db->Quote('plugin') : '')
  1082. . ' AND element IN ('.$elements_list.')'
  1083. ;
  1084. if ( count($cases) ) {
  1085. $db->setQuery($query);
  1086. $db->query();
  1087. if ($db->getErrorNum()) echo $db->getErrorMsg();
  1088. }*/
  1089. }
  1090. function processLanguageFiles($code = 'en-GB', $method = '', $params = array())
  1091. {
  1092. jimport('joomla.filesystem.file');
  1093. jimport('joomla.filesystem.archive');
  1094. $prefix = $code . '.';
  1095. $suffix = '.ini';
  1096. $missing = array();
  1097. $namea = '';
  1098. $names = '';
  1099. $adminpath = JPATH_ADMINISTRATOR.DS.'language'.DS.$code.DS;
  1100. $refadminpath = JPATH_ADMINISTRATOR.DS.'language'.DS.'en-GB'.DS;
  1101. $adminfiles = array(
  1102. // component files
  1103. 'com_flexicontent',
  1104. (FLEXI_J16GE ? 'com_flexicontent.sys' : ''),
  1105. // plugin files -- flexicontent_fields
  1106. 'plg_flexicontent_fields_addressint',
  1107. 'plg_flexicontent_fields_checkbox',
  1108. 'plg_flexicontent_fields_checkboximage',
  1109. 'plg_flexicontent_fields_core',
  1110. 'plg_flexicontent_fields_date',
  1111. 'plg_flexicontent_fields_email',
  1112. 'plg_flexicontent_fields_extendedweblink',
  1113. 'plg_flexicontent_fields_fcloadmodule',
  1114. 'plg_flexicontent_fields_fcpagenav',
  1115. 'plg_flexicontent_fields_file',
  1116. 'plg_flexicontent_fields_groupmarker',
  1117. 'plg_flexicontent_fields_image',
  1118. 'plg_flexicontent_fields_linkslist',
  1119. 'plg_flexicontent_fields_minigallery',
  1120. 'plg_flexicontent_fields_phonenumbers',
  1121. 'plg_flexicontent_fields_radio',
  1122. 'plg_flexicontent_fields_radioimage',
  1123. 'plg_flexicontent_fields_relation',
  1124. 'plg_flexicontent_fields_relation_reverse',
  1125. 'plg_flexicontent_fields_select',
  1126. 'plg_flexicontent_fields_selectmultiple',
  1127. 'plg_flexicontent_fields_shareaudio',
  1128. 'plg_flexicontent_fields_sharevideo',
  1129. 'plg_flexicontent_fields_text',
  1130. 'plg_flexicontent_fields_textarea',
  1131. 'plg_flexicontent_fields_textselect',
  1132. 'plg_flexicontent_fields_toolbar',
  1133. 'plg_flexicontent_fields_weblink',
  1134. // plugin files -- finder
  1135. (FLEXI_J16GE ? 'plg_finder_flexicontent' : ''),
  1136. (FLEXI_J16GE ? 'plg_finder_flexicontent.sys' : ''),
  1137. // plugin files -- content
  1138. 'plg_content_flexibreak',
  1139. // plugin files -- flexicontent
  1140. 'plg_flexicontent_flexinotify',
  1141. // plugin files -- search
  1142. 'plg_search_flexiadvsearch',
  1143. 'plg_search_flexisearch',
  1144. // plugin files -- system
  1145. 'plg_system_flexiadvroute',
  1146. 'plg_system_flexisystem'
  1147. );
  1148. $sitepath = JPATH_SITE.DS.'language'.DS.$code.DS;
  1149. $refsitepath = JPATH_SITE.DS.'language'.DS.'en-GB'.DS;
  1150. $sitefiles = array(
  1151. // component files
  1152. 'com_flexicontent',
  1153. // module files
  1154. 'mod_flexiadvsearch',
  1155. 'mod_flexicontent',
  1156. 'mod_flexitagcloud',
  1157. 'mod_flexifilter'
  1158. );
  1159. $targetfolder = JPATH_SITE.DS.'tmp'.DS.$code."_".time();
  1160. if ($method == 'zip') {
  1161. if (count($adminfiles))
  1162. JFolder::create($targetfolder.DS.'admin', 0755);
  1163. if (count($sitefiles))
  1164. JFolder::create($targetfolder.DS.'site', 0755);
  1165. }
  1166. foreach ($adminfiles as $file) {
  1167. if (!$file) continue;
  1168. if (!JFile::exists($adminpath.$prefix.$file.$suffix)) {
  1169. $missing['admin'][] = $file;
  1170. if ($method == 'create')
  1171. JFile::copy($refadminpath.'en-GB.'.$file.$suffix, $adminpath.$prefix.$file.$suffix);
  1172. } else {
  1173. if ($method == 'zip') {
  1174. JFile::copy($adminpath.$prefix.$file.$suffix, $targetfolder.DS.'admin'.DS.$prefix.$file.$suffix);
  1175. $namea .= "\n".' <filename>'.$prefix.$file.$suffix.'</filename>';
  1176. }
  1177. }
  1178. }
  1179. foreach ($sitefiles as $file) {
  1180. if (!$file) continue;
  1181. if (!JFile::exists($sitepath.$prefix.$file.$suffix)) {
  1182. $missing['site'][] = $file;
  1183. if ($method == 'create')
  1184. JFile::copy($refsitepath.'en-GB.'.$file.$suffix, $sitepath.$prefix.$file.$suffix);
  1185. } else {
  1186. if ($method == 'zip') {
  1187. JFile::copy($sitepath.$prefix.$file.$suffix, $targetfolder.DS.'site'.DS.$prefix.$file.$suffix);
  1188. $names .= "\n".' <filename>'.$prefix.$file.$suffix.'</filename>';
  1189. }
  1190. }
  1191. }
  1192. if ($method == 'zip')
  1193. {
  1194. $mailfrom = @$params['email'] ? $params['email'] : 'emmanuel.danan@gmail.com';
  1195. $fromname = @$params['name'] ? $params['name'] : 'Emmanuel Danan';
  1196. $website = @$params['web'] ? $params['web'] : 'http://www.flexicontent.org';
  1197. // prepare the manifest of the language archive
  1198. $date = JFactory::getDate();
  1199. $xmlfile = $targetfolder.DS.'install.xml';
  1200. $xml = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  1201. <install type="language" version="1.5" client="both" method="upgrade">
  1202. <name>FLEXIcontent '.$code.'</name>
  1203. <tag>'.$code.'</tag>
  1204. <creationDate>'.(FLEXI_J16GE ? $date->format('Y-M-d', $local = true) : $date->toFormat("%Y-%m-%d")).'</creationDate>
  1205. <author>'.$fromname.'</author>
  1206. <authorEmail>'.$mailfrom.'</authorEmail>
  1207. <authorUrl>'.$website.'</authorUrl>
  1208. <copyright>(C) '.(FLEXI_J16GE ? $date->format('Y', $local = true) : $date->toFormat("%Y")).' '.$fromname.'</copyright>
  1209. <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
  1210. <description>'.$code.' language pack for FLEXIcontent</description>
  1211. <administration>
  1212. <files folder="admin">'.$namea.'
  1213. </files>
  1214. </administration>
  1215. <site>
  1216. <files folder="site">'.$names.'
  1217. </files>
  1218. </site>
  1219. </install>'
  1220. ;
  1221. // save xml manifest
  1222. JFile::write($xmlfile, $xml);
  1223. $fileslist = JFolder::files($targetfolder, '.', true, true, array('.svn', 'CVS', '.DS_Store'));
  1224. $archivename = $targetfolder.'.com_flexicontent'. (FLEXI_J16GE ? '.zip' : '.tar.gz');
  1225. // Create the archive
  1226. echo JText::_('FLEXI_SEND_LANGUAGE_CREATING_ARCHIVE')."<br>";
  1227. if (!FLEXI_J16GE) {
  1228. JArchive::create($archivename, $fileslist, 'gz', '', $targetfolder);
  1229. } else {
  1230. $app = JFactory::getApplication('administrator');
  1231. $files = array();
  1232. foreach ($fileslist as $i => $filename) {
  1233. $files[$i]=array();
  1234. $files[$i]['name'] = preg_replace("%^(\\\|/)%", "", str_replace($targetfolder, "", $filename) ); // STRIP PATH for filename inside zip
  1235. $files[$i]['data'] = implode('', file($filename)); // READ contents into string, here we use full path
  1236. $files[$i]['time'] = time();
  1237. }
  1238. $packager = JArchive::getAdapter('zip');
  1239. if (!$packager->create($archivename, $files)) {
  1240. echo JText::_('FLEXI_OPERATION_FAILED');
  1241. return false;
  1242. }
  1243. }
  1244. // Remove temporary folder structure
  1245. if (!JFolder::delete(($targetfolder)) ) {
  1246. echo JText::_('FLEXI_SEND_DELETE_TMP_FOLDER_FAILED');
  1247. }
  1248. }
  1249. // messages
  1250. if ($method == 'zip') {
  1251. return '<h3 class="lang-success">' . JText::_( 'FLEXI_SEND_LANGUAGE_ARCHIVE_SUCCESS' ) . '</span>';
  1252. }
  1253. return (count($missing) > 0) ? $missing : '<span class="fc-mssg fc-success">'. JText::sprintf( 'FLEXI_SEND_LANGUAGE_NO_MISSING', $code ) .'</span>';
  1254. }
  1255. function checkInitialPermission() {
  1256. $debug_initial_perms = JComponentHelper::getParams('com_flexicontent')->get('debug_initial_perms');
  1257. static $init_required = null;
  1258. if ( $init_required !== null ) return $init_required;
  1259. $db = JFactory::getDBO();
  1260. $component_name = 'com_flexicontent';
  1261. // DELETE old namespace (flexicontent.*) permissions of v2.0beta, we do not try to rename them ... instead we will use com_content (for some of them),
  1262. $query = $db->getQuery(true)->delete('#__assets')->where('name LIKE ' . $db->quote('flexicontent.%'));
  1263. $db->setQuery($query);
  1264. $db->query(); if ($db->getErrorNum()) echo $db->getErrorMsg();
  1265. // SET Access View Level to public (=1) for fields that do not have their Level set
  1266. $query = $db->getQuery(true)->update('#__flexicontent_fields')->set('access = 1')->where('access = 0');
  1267. $db->setQuery($query);
  1268. $db->query(); if ($db->getErrorNum()) echo $db->getErrorMsg();
  1269. // SET Access View Level to public (=1) for types that do not have their Level set
  1270. $query = $db->getQuery(true)->update('#__flexicontent_types')->set('access = 1')->where('access = 0');
  1271. $db->setQuery($query);
  1272. $db->query(); if ($db->getErrorNum()) echo $db->getErrorMsg();
  1273. // CHECK that we have the same Component Actions in assets DB table with the Actions as in component's access.xml file
  1274. $asset = JTable::getInstance('asset');
  1275. if ($comp_section = $asset->loadByName($component_name)) { // Try to load component asset, if missing it returns false
  1276. // ok, component asset not missing, proceed to cross check for deleted / added actions
  1277. $rules = new JRules($asset->rules);
  1278. $rules_data = $rules->getData();
  1279. $component_actions = JAccess::getActions($component_name, 'component');
  1280. $db_action_names = array();
  1281. foreach ($rules_data as $action_name => $data) $db_action_names[] = $action_name;
  1282. foreach ($component_actions as $action) $file_action_

Large files files are truncated, but you can click here to view the full file