File manager - Edit - /home/jardides/www/Jardi-design/old/administrator/components/com_templateck/models/template.php
Back
<?php /** * @name Template Creator CK 3 * @package com_templateck * @copyright Copyright (C) 2013. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr */ // No direct access. defined('_JEXEC') or die; jimport('joomla.application.component.modelform'); jimport('joomla.application.component.modeladmin'); jimport('joomla.event.dispatcher'); jimport('joomla.filesystem.folder'); /** * Templateck model. */ class TemplateckModelTemplate extends JModelAdmin { var $_item = null; /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('com_templateck'); // Load state from the request userState on edit or from the passed variable on default if ($app->input->get('layout', '', 'cmd') == 'edit') { $id = JFactory::getApplication()->getUserState('com_templateck.edit.template.id'); } else { $id = $app->input->get('id', 0, 'int'); JFactory::getApplication()->setUserState('com_templateck.edit.template.id', $id); } $this->setState('template.id', $id); // Load the parameters. // $params = $app->getParams(); // $this->setState('params', $params); } /** * Method to get an ojbect. * * @param integer The id of the object to get. * * @return mixed Object on success, false on failure. */ public function &getData($id = null) { $app = JFactory::getApplication(); if ($this->_item === null) { $this->_item = false; if (empty($id)) { $id = $app->input->get('id', '', 'int'); } // Get a level row instance. $table = $this->getTable(); // Attempt to load the row. if ($table->load($id)) { // Check published state. if ($published = $this->getState('filter.published')) { if ($table->state != $published) { return $this->_item; } } // Convert the JTable to a clean JObject. $properties = $table->getProperties(1); $this->_item = JArrayHelper::toObject($properties, 'JObject'); } elseif ($error = $table->getError()) { $this->setError($error); } } $this->_item->layouts = $this->getLayouts($id); return $this->_item; } public function getLayouts($id) { $l = $this->initLayouts(); if (! $id) return $l; $db = JFactory::getDBO(); $query = 'SELECT id,type,htmlcode FROM #__templateck_layouts WHERE template_id=' . (int) $id; $db->setQuery($query); $layouts = $db->loadObjectList(); foreach($layouts as $layout) { $l[$layout->type] = new stdClass(); $l[$layout->type]->id = $layout->id; $l[$layout->type]->htmlcode = $layout->htmlcode; } return $l; } private function initLayouts() { $l = array(); $types = array('error404'); foreach ($types as $type) { $l[$type] = new stdClass(); $l[$type]->id = 0; $l[$type]->htmlcode = ''; } return $l; } public function getTable($type = 'Template', $prefix = 'TemplateckTable', $config = array()) { $this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables'); return JTable::getInstance($type, $prefix, $config); } /** * Method to check in an item. * * @param integer The id of the row to check out. * @return boolean True on success, false on failure. * @since 1.6 */ public function checkin($id = null) { // Get the id. $id = (!empty($id)) ? $id : (int) $this->getState('template.id'); if ($id) { // Initialise the table $table = $this->getTable(); // Attempt to check the row in. if (method_exists($table, 'checkin')) { if (!$table->checkin($id)) { $this->setError($table->getError()); return false; } } } return true; } /** * Method to check out an item for editing. * * @param integer The id of the row to check out. * @return boolean True on success, false on failure. * @since 1.6 */ public function checkout($id = null) { // Get the user id. $id = (!empty($id)) ? $id : (int) $this->getState('template.id'); if ($id) { // Initialise the table $table = $this->getTable(); // Get the current user object. $user = JFactory::getUser(); // Attempt to check the row out. if (method_exists($table, 'checkout')) { if (!$table->checkout($user->get('id'), $id)) { $this->setError($table->getError()); return false; } } } return true; } /** * Method to get the profile form. * * The base form is loaded from XML * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_templateck.template', 'template', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } return $form; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { $data = $this->getData(); return $data; } /** * Method to save the form data. * * @param array The form data. * @return mixed The user id on success, false on failure. * @since 1.6 */ public function save($data) { $app = JFactory::getApplication(); $id = (!empty($data['id'])) ? $data['id'] : (int) $this->getState('template.id'); $user = JFactory::getUser(); // $data['htmlcode'] = JRequest::getVar('htmlcode', '', 'post', 'string', JREQUEST_ALLOWRAW); $data['htmlcode'] = $app->input->get('htmlcode', '', 'raw'); $htmlcode_responsive = $app->input->get('htmlcode_responsive', '', 'raw'); if ($htmlcode_responsive) $data['htmlcode_responsive'] = $htmlcode_responsive; $modules = $app->input->get('modules', '', 'string'); if ($modules) $data['modules'] = $modules; $data['widgets'] = $app->input->get('widgets', '', 'raw'); if ($id) { //Check the user can edit this item $authorised = $user->authorise('core.edit', 'template.' . $id); } else { //Check the user can create new items in this section $authorised = $user->authorise('core.create', 'com_templateck'); } if ($authorised !== true) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); return false; } $table = $this->getTable(); $table->load($data['id']); // make a backup before save $this->makeBackup(); if ($table->name !== $data['name']) { $this->changeTemplateName($table->name, $data['name']); } if ($table->save($data) === true) { return $table->id; } else { return false; } } public function changeTemplateName($oldname, $newname) { $path = JPATH_ROOT . '/components/com_templateck/projects/'; if (! JFolder::exists($path . $oldname)) { return; } $movefolder = JFolder::move($path . $oldname, $path . $newname); if ($movefolder !== true) { JFactory::getApplication()->enqueueMessage(JText::_('CK_UNABLE_TO_RENAME_FOLDER') . ' : ' . $newname, 'warning'); } } public function delete(&$pks) { $path = JPATH_ROOT . '/components/com_templateck/projects/'; $table = $this->getTable(); foreach ($pks as $i => $pk) { $table->load((int)$pk); if (JFolder::exists($path . $table->name)) { JFolder::delete($path . $table->name); } } parent::delete($pks); } private function makeBackup() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $path = JPATH_ROOT . '/administrator/components/com_templateck/backup'; $item = $this->getData(); $exportfiletext = json_encode($item); // create the folder if (! JFolder::exists($path . '/' . $item->id . '_bak/')) { JFolder::create($path . '/' . $item->id . '_bak/'); } // check if we have more than 5 existing backups, delete the old one $existingBackups = JFolder::files($path . '/' . $item->id . '_bak/', '^backup_' . $item->id); if (count($existingBackups) > 5) { // $this->deleteOldestBackup($path . '/' . $item->id . '_bak/'); natsort($existingBackups); $oldest = $existingBackups[0]; Jfile::delete($path . '/' . $item->id . '_bak/' . $oldest); } $exportfiledest = $path . '/' . $item->id . '_bak/backup_' . $item->id . '_' . date("d-m-Y-G-i-s") . '.tck3'; JFile::write($exportfiledest, $exportfiletext); } // private function deleteOldestBackup($path) { // $files = JFolder::files($path, '^backup_' . $item->id); // // natsort($files); // // $oldest = $files[0]; // Jfile::delete($path . $oldest); // } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings