Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.90 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package gantry
  4. * @subpackage core
  5. * @version 4.1.26 October 9, 2014
  6. * @author RocketTheme http://www.rockettheme.com
  7. * @copyright Copyright (C) 2007 - 2014 RocketTheme, LLC
  8. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9. *
  10. * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
  11. *
  12. */
  13.  
  14. // No direct access.
  15. defined('_JEXEC') or die;
  16.  
  17. jimport('joomla.application.component.modeladmin');
  18.  
  19.  
  20. if (version_compare(JVERSION, '3.0', '<')) {
  21. abstract class GantryModelTemplateIntermediate extends JModelAdmin
  22. {
  23. protected function prepareTable(&$table)
  24. {
  25. $this->gPrepareTable($table);
  26. }
  27. abstract protected function gPrepareTable($table);
  28. }
  29. } else {
  30. abstract class GantryModelTemplateIntermediate extends JModelAdmin
  31. {
  32. protected function prepareTable($table)
  33. {
  34. $this->gPrepareTable($table);
  35. }
  36.  
  37. abstract protected function gPrepareTable($table);
  38. }
  39. }
  40.  
  41. /**
  42. * Template style model.
  43. *
  44. * @package Joomla.Administrator
  45. * @subpackage com_templates
  46. * @since 1.6
  47. */
  48. class GantryModelTemplate extends GantryModelTemplateIntermediate
  49. {
  50. /**
  51. * @var string The help screen key for the module.
  52. * @since 1.6
  53. */
  54. protected $helpKey = 'JHELP_EXTENSIONS_TEMPLATE_MANAGER_STYLES_EDIT';
  55.  
  56. /**
  57. * @var string The help screen base URL for the module.
  58. * @since 1.6
  59. */
  60. protected $helpURL;
  61.  
  62. /**
  63. * Item cache.
  64. */
  65. private $_cache = array();
  66.  
  67. private $_formCache = array();
  68.  
  69. /**
  70. * Method to auto-populate the model state.
  71. *
  72. * Note. Calling getState in this method will result in recursion.
  73. *
  74. * @since 1.6
  75. */
  76. protected function populateState()
  77. {
  78. $app = JFactory::getApplication('administrator');
  79.  
  80. // Load the User state.
  81. $pk = (int)$app->input->getInt('id');
  82. $this->setState('template.id', $pk);
  83.  
  84. // Load the parameters.
  85. $params = JComponentHelper::getParams('com_gantry');
  86. $this->setState('params', $params);
  87. }
  88.  
  89. /**
  90. * Method to get the record form.
  91. *
  92. * @param array $data An optional array of data for the form to interogate.
  93. * @param boolean $loadData True if the form is to load its own data (default case), false if not.
  94. *
  95. * @return JForm A JForm object on success, false on failure
  96. * @since 1.6
  97. */
  98. public function getForm($data = array(), $loadData = true)
  99. {
  100. // Initialise variables.
  101. $app = JFactory::getApplication();
  102.  
  103. // The folder and element vars are passed when saving the form.
  104. if (empty($data)) {
  105. $item = $this->getItem();
  106. $clientId = $item->client_id;
  107. $template = $item->template;
  108. } else {
  109. $clientId = JArrayHelper::getValue($data, 'client_id');
  110. $template = JArrayHelper::getValue($data, 'template');
  111. }
  112.  
  113. // These variables are used to add data from the plugin XML files.
  114. $this->setState('item.client_id', $clientId);
  115. $this->setState('item.template', $template);
  116.  
  117. // Get the form.
  118. $form = $this->loadForm('com_gantry.template', 'template', array(
  119. 'control' => 'jform', 'load_data' => $loadData
  120. ));
  121. if (empty($form)) {
  122. return false;
  123. }
  124.  
  125. // Modify the form based on access controls.
  126. if (!$this->canEditState((object)$data)) {
  127. // Disable fields for display.
  128. $form->setFieldAttribute('home', 'disabled', 'true');
  129.  
  130. // Disable fields while saving.
  131. // The controller has already verified this is a record you can edit.
  132. $form->setFieldAttribute('home', 'filter', 'unset');
  133. }
  134.  
  135. return $form;
  136. }
  137.  
  138. protected function canEditState($record)
  139. {
  140. $user = JFactory::getUser();
  141. return $user->authorise('core.edit.state', 'com_templates');
  142. }
  143.  
  144. public function getGantryForm()
  145. {
  146. gantry_import('core.config.gantryform');
  147. gantry_import('core.config.gantryformnaminghelper');
  148.  
  149. $pk = (!empty($pk)) ? $pk : (int)$this->getState('template.id');
  150. $item = $this->getItem($pk);
  151. $item->params['current_id'] = $pk;
  152. if (!isset($this->_formCache[$pk])) {
  153. $naming_helper = GantryFormNamingHelper::getInstance();
  154. $form = GantryForm::getInstance($naming_helper, 'template-options', 'template-options', array(), true, "//form");
  155. $form->bind($item->params);
  156. $this->_formCache[$pk] = $form;
  157. }
  158. return $this->_formCache[$pk];
  159. }
  160.  
  161.  
  162. public function checkForGantryUpdate()
  163. {
  164. try {
  165. gantry_import('core.gantryupdates');
  166. $gantry_updates = GantryUpdates::getInstance();
  167.  
  168. $last_updated = $gantry_updates->getLastUpdated();
  169. $diff = time() - $last_updated;
  170. if ($diff > (60 * 60 * 24)) {
  171. jimport('joomla.updater.updater');
  172. // check for update
  173. $updater = JUpdater::getInstance();
  174. $results = @$updater->findUpdates($gantry_updates->getGantryExtensionId());
  175. $gantry_updates->setLastChecked(time());
  176. }
  177. } catch (Exception $e) {
  178. if (!($e->getCode() == 0 && $e->getMessage() == 'No HTTP response received.'))
  179. {
  180. throw $e;
  181. }
  182. }
  183. }
  184.  
  185. /**
  186. * Method to get the data that should be injected in the form.
  187. *
  188. * @return mixed The data for the form.
  189. * @since 1.6
  190. */
  191. protected function loadFormData()
  192. {
  193. // Check the session for previously entered form data.
  194. $data = JFactory::getApplication()->getUserState('com_templates.edit.style.data', array());
  195.  
  196. if (empty($data)) {
  197. $data = $this->getItem();
  198. }
  199.  
  200. return $data;
  201. }
  202.  
  203. /**
  204. * Method to get a single record.
  205. *
  206. * @param integer The id of the primary key.
  207. *
  208. * @return mixed Object on success, false on failure.
  209. */
  210. public function getItem($pk = null)
  211. {
  212. // Initialise variables.
  213. $pk = (!empty($pk)) ? $pk : (int)$this->getState('template.id');
  214.  
  215. if (!isset($this->_cache[$pk])) {
  216. $false = false;
  217.  
  218. // Get a row instance.
  219. $table = $this->getTable();
  220.  
  221. // Attempt to load the row.
  222. $return = $table->load($pk);
  223.  
  224. // Check for a table object error.
  225. if ($return === false && $table->getError()) {
  226. $this->setError($table->getError());
  227. return $false;
  228. }
  229.  
  230. // Convert to the JObject before adding other data.
  231. $table_props = $table->getProperties(1);
  232. $this->_cache[$pk] = JArrayHelper::toObject($table_props, 'JObject');
  233.  
  234. // Convert the params field to an array.
  235. $registry = new JRegistry;
  236. $registry->loadString($table->params);
  237.  
  238. $item_params = $registry->toArray();
  239. if (array_key_exists('master', $item_params) && $item_params['master'] != 'true') {
  240. $master_params = $this->getItem((int)$item_params['master'])->params;
  241. if (count($master_params) <= 1)
  242. {
  243. $default_params = $this->getDefaultTemplateParams($table->template);
  244. $master_params = $this->array_join($master_params, $default_params);
  245. }
  246. $item_params = $this->array_join($master_params, $item_params);
  247. }
  248. if(@ini_get('magic_quotes_gpc')=='1'){
  249. $item_params = self::_stripSlashesRecursive($item_params);
  250. }
  251.  
  252. $this->_cache[$pk]->params = $item_params;
  253. }
  254.  
  255. return $this->_cache[$pk];
  256. }
  257.  
  258. protected function getDefaultTemplateParams($template_name)
  259. {
  260. // xpath for names //form//field|//form//fields[@default]|//form//fields[@value]
  261. // xpath for parents ancestor::fields[@name][not(@ignore-group)]/@name|ancestor::set[@name]/@name
  262. $xml = JFactory::getXML(JPATH_SITE . '/templates/' . $template_name . '/template-options.xml');
  263.  
  264. $params = $xml->xpath('//form//field|//form//fields[@default]|//form//fields[@value]');
  265. $defaults = array();
  266. foreach ($params as $param) {
  267. $attrs = $param->xpath('ancestor::fields[@name][not(@ignore-group)]/@name|ancestor::set[@name]/@name');
  268. $groups = array_map('strval', $attrs ? $attrs : array());
  269. $groups[] = (string)$param['name'];
  270. array_walk($groups, create_function('&$value,$key', '$value = \'[\\\'\'.$value.\'\\\']\';'));
  271. //array_walk($groups, create_function('&$item,$k', '$item = "[\'" . $item . "\']");'));
  272. $def_array_eval = '$defaults' . implode('', $groups) . ' = (string)$param[\'default\'];';
  273. if ($param['default']) @eval($def_array_eval);
  274. }
  275. //$defaults = $this->arrayToObject($defaults);
  276. return $defaults;
  277. }
  278.  
  279. public function getOverride($pk = null)
  280. {
  281. $pk = (!empty($pk)) ? $pk : (int)$this->getState('template.id');
  282. $params = $this->getItem($pk)->params;
  283. if (array_key_exists('master', $params) && $params['master'] != 'true') {
  284. return true;
  285. }
  286. return false;
  287. }
  288.  
  289. public function getBaseData($pk = null)
  290. {
  291. $pk = (!empty($pk)) ? $pk : (int)$this->getState('template.id');
  292. $params = $this->getItem($pk)->params;
  293. if ($params->get('master') != 'true') {
  294. $params = $this->getItem($params->get('master'));
  295. }
  296. return $params;
  297. }
  298.  
  299. /**
  300. * Returns a reference to the a Table object, always creating it.
  301. *
  302. * @param type The table type to instantiate
  303. * @param string A prefix for the table class name. Optional.
  304. * @param array Configuration array for model. Optional.
  305. *
  306. * @return JTable A database object
  307. */
  308. public function getTable($type = 'Style', $prefix = 'TemplatesTable', $config = array())
  309. {
  310. JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_templates/tables');
  311. return JTable::getInstance($type, $prefix, $config);
  312. }
  313.  
  314. /**
  315. * Prepare and sanitise the table prior to saving.
  316. */
  317. protected function gPrepareTable($table)
  318. {
  319. $table;
  320. }
  321.  
  322. /**
  323. * @param object A form object.
  324. * @param mixed The data expected for the form.
  325. *
  326. * @throws Exception if there is an error in the form event.
  327. * @since 1.6
  328. */
  329. protected function preprocessForm(JForm $form, $data, $group = 'content')
  330. {
  331. // Initialise variables.
  332. $clientId = $this->getState('item.client_id');
  333. $template = $this->getState('item.template');
  334. $lang = JFactory::getLanguage();
  335. $client = JApplicationHelper::getClientInfo($clientId);
  336. if (!$form->loadFile('template_' . $client->name, true)) {
  337. throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
  338. }
  339.  
  340. jimport('joomla.filesystem.file');
  341. jimport('joomla.filesystem.folder');
  342.  
  343. $formFile = JPath::clean($client->path . '/templates/' . $template . '/templateDetails.xml');
  344.  
  345. // Load the core and/or local language file(s).
  346. $lang->load('tpl_' . $template, $client->path, null, false, false) || $lang->load('tpl_' . $template, $client->path . '/templates/' . $template, null, false, false) || $lang->load('tpl_' . $template, $client->path, $lang->getDefault(), false, false) || $lang->load('tpl_' . $template, $client->path . '/templates/' . $template, $lang->getDefault(), false, false);
  347.  
  348. if (file_exists($formFile)) {
  349. // Get the template form.
  350. if (!$form->loadFile($formFile, false, '//config')) {
  351. throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
  352. }
  353. }
  354.  
  355. // Disable home field if it is default style
  356.  
  357. if ((is_array($data) && array_key_exists('home', $data)) || ((is_object($data) && $data->home))) {
  358. $form->setFieldAttribute('home', 'readonly', 'true');
  359. }
  360.  
  361. // Attempt to load the xml file.
  362. if (!$xml = simplexml_load_file($formFile)) {
  363. throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
  364. }
  365.  
  366. // Get the help data from the XML file if present.
  367. $help = $xml->xpath('/extension/help');
  368. if (!empty($help)) {
  369. $helpKey = trim((string)$help[0]['key']);
  370. $helpURL = trim((string)$help[0]['url']);
  371.  
  372. $this->helpKey = $helpKey ? $helpKey : $this->helpKey;
  373. $this->helpURL = $helpURL ? $helpURL : $this->helpURL;
  374. }
  375.  
  376. // Trigger the default form events.
  377. parent::preprocessForm($form, $data, $group);
  378. }
  379.  
  380. /**
  381. * Method to save the form data.
  382. *
  383. * @param array The form data.
  384. *
  385. * @return boolean True on success.
  386. */
  387. public function save($data)
  388. {
  389. require_once(JPATH_LIBRARIES . "/gantry/gantry.php");
  390.  
  391. // Initialise variables;
  392. $dispatcher = JDispatcher::getInstance();
  393. $table = $this->getTable();
  394. $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState('template.id');
  395. $isNew = true;
  396.  
  397. // Include the extension plugins for the save events.
  398. JPluginHelper::importPlugin('extension');
  399.  
  400. // Load the row if saving an existing record.
  401. if ($pk > 0) {
  402. $table->load($pk);
  403. $isNew = false;
  404. }
  405.  
  406. if (!array_key_exists('home', $data)) {
  407. $data['home'] = 0;
  408. }
  409.  
  410. // see if its a override and set params to only different data
  411. if (array_key_exists('master', $data['params']) && $data['params']['master'] != 'true') {
  412. $master_params = $this->getItem($data['params']['master'])->params;
  413. $data['params'] = $this->array_diff($data['params'], $master_params);
  414. }
  415.  
  416. if(@ini_get('magic_quotes_gpc')=='1'){
  417. $data['params'] = self::_stripSlashesRecursive($data['params']);
  418. }
  419.  
  420. // Bind the data.
  421. if (!$table->bind($data)) {
  422. $this->setError($table->getError());
  423. return false;
  424. }
  425.  
  426. // Prepare the row for saving
  427. $this->prepareTable($table);
  428.  
  429. // Check the data.
  430. if (!$table->check()) {
  431. $this->setError($table->getError());
  432. return false;
  433. }
  434.  
  435. // Trigger the onExtensionBeforeSave event.
  436. $result = $dispatcher->trigger('onExtensionBeforeSave', array('com_templates.style', &$table, $isNew));
  437. if (in_array(false, $result, true)) {
  438. $this->setError($table->getError());
  439. return false;
  440. }
  441.  
  442. // Store the data.
  443. if (!$table->store()) {
  444. $this->setError($table->getError());
  445. return false;
  446. }
  447.  
  448. $user = JFactory::getUser();
  449. if ($user->authorise('core.edit', 'com_menus') && $table->client_id == 0) {
  450. $n = 0;
  451. $db = JFactory::getDbo();
  452. $user = JFactory::getUser();
  453.  
  454. if (empty($data['assigned']) || $data['assigned'] !== false) {
  455. if (!empty($data['assigned'])) {
  456. JArrayHelper::toInteger($data['assigned']);
  457.  
  458. // Update the mapping for menu items that this style IS assigned to.
  459. $query = $db->getQuery(true);
  460. $query->update('#__menu');
  461. $query->set('template_style_id=' . (int)$table->id);
  462. $query->where('id IN (' . implode(',', $data['assigned']) . ')');
  463. $query->where('template_style_id!=' . (int)$table->id);
  464. $query->where('checked_out in (0,' . (int)$user->id . ')');
  465. $db->setQuery($query);
  466. $db->query();
  467. $n += $db->getAffectedRows();
  468. }
  469.  
  470. // Remove style mappings for menu items this style is NOT assigned to.
  471. // If unassigned then all existing maps will be removed.
  472. $query = $db->getQuery(true);
  473. $query->update('#__menu');
  474. $query->set('template_style_id=0');
  475. if (!empty($data['assigned'])) {
  476. $query->where('id NOT IN (' . implode(',', $data['assigned']) . ')');
  477. }
  478.  
  479. $query->where('template_style_id=' . (int)$table->id);
  480. $query->where('checked_out in (0,' . (int)$user->id . ')');
  481. $db->setQuery($query);
  482. $db->query();
  483.  
  484. $n += $db->getAffectedRows();
  485. if ($n > 0) {
  486. $app = JFactory::getApplication();
  487. $app->enQueueMessage(JText::plural('COM_TEMPLATES_MENU_CHANGED', $n));
  488. }
  489. }
  490. }
  491.  
  492. // Clean the cache.
  493. $cache = JFactory::getCache();
  494. $cache->clean('com_templates');
  495. $gcache = GantryCache::getCache(GantryCache::GROUP_NAME);
  496. $gcache->getCacheLib()->getDriver()->getCache()->cache->_options['cachebase'] = JPATH_ROOT.'/cache';
  497. $gcache->clearGroupCache();
  498. $gacache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME);
  499. $gacache->clearGroupCache();
  500. gantry_admin_setup();
  501.  
  502. // Trigger the onExtensionAfterSave event.
  503. $dispatcher->trigger('onExtensionAfterSave', array('com_templates.style', &$table, $isNew));
  504.  
  505. $this->setState('template.id', $table->id);
  506.  
  507. return true;
  508. }
  509.  
  510. /**
  511. * Get the necessary data to load an item help screen.
  512. *
  513. * @return object An object with key, url, and local properties for loading the item help screen.
  514. * @since 1.6
  515. */
  516. public function getHelp()
  517. {
  518. return (object)array('key' => $this->helpKey, 'url' => $this->helpURL);
  519. }
  520.  
  521. /**
  522. * Method to get a form object.
  523. *
  524. * @param string $name The name of the form.
  525. * @param string $source The form source. Can be XML string if file flag is set to false.
  526. * @param array $options Optional array of options for the form creation.
  527. * @param boolean $clear Optional argument to force load a new form.
  528. * @param string $xpath An optional xpath to search for the fields.
  529. *
  530. * @return mixed JForm object on success, False on error.
  531. */
  532. protected function loadForm($name, $source = null, $options = array(), $clear = false, $xpath = false)
  533. {
  534. // Handle the optional arguments.
  535. $options['control'] = JArrayHelper::getValue($options, 'control', false);
  536.  
  537. // Create a signature hash.
  538. $hash = md5($source . serialize($options));
  539.  
  540. // Check if we can use a previously loaded form.
  541. if (isset($this->_forms[$hash]) && !$clear) {
  542. return $this->_forms[$hash];
  543. }
  544.  
  545. // Get the form.
  546. JForm::addFormPath(JPATH_COMPONENT . '/models/forms');
  547. JForm::addFieldPath(JPATH_COMPONENT . '/models/fields');
  548.  
  549. try {
  550. $form = JForm::getInstance($name, $source, $options, false, $xpath);
  551.  
  552. if (isset($options['load_data']) && $options['load_data']) {
  553. // Get the data for the form.
  554. $data = $this->loadFormData();
  555. } else {
  556. $data = array();
  557. }
  558.  
  559. // Allow for additional modification of the form, and events to be triggered.
  560. // We pass the data because plugins may require it.
  561. $this->preprocessForm($form, $data);
  562.  
  563. // Load the data into the form after the plugins have operated.
  564. $form->bind($data);
  565.  
  566. } catch (Exception $e) {
  567. $this->setError($e->getMessage());
  568. return false;
  569. }
  570.  
  571. // Store the form for later.
  572. $this->_forms[$hash] = $form;
  573.  
  574. return $form;
  575. }
  576.  
  577.  
  578. protected function array_join()
  579. {
  580. // Get array arguments
  581. $arrays = func_get_args();
  582.  
  583. // Define the original array
  584. $original = array_shift($arrays);
  585.  
  586. // Loop through arrays
  587. foreach ($arrays as $array) {
  588. // Loop through array key/value pairs
  589. foreach ($array as $key => $value) {
  590. // Value is an array
  591. if (is_array($value)) {
  592. // Traverse the array; replace or add result to original array
  593. @$original[$key] = $this->array_join($original[$key], $array[$key]);
  594. } // Value is not an array
  595. else {
  596. // Replace or add current value to original array
  597. @$original[$key] = $value;
  598. }
  599. }
  600. }
  601.  
  602. // Return the joined array
  603. return $original;
  604. }
  605.  
  606. protected function array_diff($aArray1, $aArray2)
  607. {
  608. $aReturn = array();
  609.  
  610. foreach ($aArray1 as $mKey => $mValue) {
  611. if (array_key_exists($mKey, $aArray2)) {
  612. if (is_array($mValue)) {
  613. $aRecursiveDiff = $this->array_diff($mValue, $aArray2[$mKey]);
  614. if (count($aRecursiveDiff)) {
  615. $aReturn[$mKey] = $aRecursiveDiff;
  616. }
  617. } else {
  618. if ($mValue != $aArray2[$mKey]) {
  619. $aReturn[$mKey] = $mValue;
  620. }
  621. }
  622. } else {
  623. $aReturn[$mKey] = $mValue;
  624. }
  625. }
  626.  
  627. return $aReturn;
  628. }
  629.  
  630. /**
  631. * Method to duplicate styles.
  632. *
  633. * @param array An array of primary key IDs.
  634. *
  635. * @return boolean True if successful.
  636. * @throws Exception
  637. */
  638. public function duplicate(&$pks)
  639. {
  640. // Initialise variables.
  641. $user = JFactory::getUser();
  642. $db = $this->getDbo();
  643.  
  644. // Access checks.
  645. if (!$user->authorise('core.create', 'com_templates')) {
  646. throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
  647. }
  648.  
  649. $table = $this->getTable();
  650.  
  651. foreach ($pks as $pk) {
  652. if ($table->load($pk, true)) {
  653. // Reset the id to create a new record.
  654. $table->id = 0;
  655.  
  656. // Reset the home (don't want dupes of that field).
  657. $table->home = 0;
  658.  
  659. // Alter the title.
  660. $m = null;
  661. if (preg_match('#\((\d+)\)$#', $table->title, $m)) {
  662. $table->title = preg_replace('#\(\d+\)$#', '(' . ($m[1] + 1) . ')', $table->title);
  663. } else {
  664. $table->title .= ' (2)';
  665. }
  666.  
  667. if ($this->isGantryTemplate($table)) {
  668. $template_params = new JRegistry();
  669. $template_params->loadString($table->params);
  670. if ($template_params->get('master') == 'true') {
  671. $base_params = $template_params->toArray();
  672. $template_params->set('master', $pk);
  673. $copy_params = $template_params->toArray();
  674. $copy_params = $this->array_diff($copy_params, $base_params);
  675. $template_params = new JRegistry();
  676. $template_params->loadArray($copy_params);
  677. }
  678. $table->params = $template_params->toString();
  679. }
  680.  
  681. if (!$table->check() || !$table->store()) {
  682. throw new Exception($table->getError());
  683. }
  684. } else {
  685. throw new Exception($table->getError());
  686. }
  687. }
  688.  
  689. $cache = JFactory::getCache();
  690. $cache->clean('com_templates');
  691. $cache->clean('_system');
  692.  
  693. return true;
  694. }
  695.  
  696. /**
  697. * Method to delete rows.
  698. *
  699. * @param array An array of item ids.
  700. *
  701. * @return boolean Returns true on success, false on failure.
  702. */
  703. public function delete(&$pks)
  704. {
  705. // Initialise variables.
  706. $pks = (array)$pks;
  707. $user = JFactory::getUser();
  708. $table = $this->getTable();
  709. $language = JFactory::getLanguage();
  710. $language->load('com_gantry');
  711.  
  712. // Iterate the items to delete each one.
  713. foreach ($pks as $i => $pk) {
  714. if ($table->load($pk)) {
  715. // Access checks.
  716. if (!$user->authorise('core.delete', 'com_templates')) {
  717. throw new Exception(JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
  718. }
  719.  
  720. if ($this->isGantryTemplate($table)) {
  721. $template_params = new JRegistry();
  722. $template_params->loadString($table->params);
  723. if ($template_params->get('master') == 'true') {
  724. $this->setError(JText::_('Cannot delete a Gantry Template Master Style'));
  725. return false;
  726. }
  727. }
  728. if (!$table->delete($pk)) {
  729. $this->setError($table->getError());
  730. return false;
  731. }
  732. } else {
  733. $this->setError($table->getError());
  734. return false;
  735. }
  736. }
  737.  
  738. $cache = JFactory::getCache();
  739. $cache->clean('com_templates');
  740. $cache->clean('_system');
  741.  
  742. return true;
  743. }
  744.  
  745. /**
  746. * Check if template is based on gantry
  747. *
  748. * @param string $id
  749. *
  750. * @return boolean
  751. */
  752. private function isGantryTemplate($table)
  753. {
  754. $template = $table->template;
  755. return file_exists(JPATH_SITE . '/' . 'templates' . '/' . $template . '/' . 'lib' . '/' . 'gantry' . '/' . 'gantry.php');
  756. }
  757.  
  758. /**
  759. *
  760. * @param $value
  761. *
  762. * @return array|string
  763. */
  764. protected static function _stripSlashesRecursive($value)
  765. {
  766. $value = is_array($value) ? array_map(array( 'GantryModelTemplate', '_stripSlashesRecursive'), $value) : stripslashes($value);
  767. return $value;
  768. }
  769.  
  770. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement