File manager - Edit - /home/jardides/www/Jardi-design/old/administrator/components/com_pagebuilderck/pro/includes/import.php
Back
<?php /** * @name Page Builder CK * @package com_pagebuilderck * @copyright Copyright (C) 2015. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @author Cedric Keiflin - https://www.template-creator.com - https://www.joomlack.fr */ // No direct access defined('_JEXEC') or die; use Pagebuilderck\CKFof; jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); class PagebuilderckParamsImport { private $_doc; private $_app; private $_input; private $import_folder_name; public function __construct() { $this->_doc = JFactory::getDocument(); $this->_app = JFactory::getApplication(); $this->_input = $this->_app->input; PagebuilderckHelper::loadCkbox(); } /** * Load the html code for the */ public function loadImportForm() { // modal popup for import ?> <div id="ckImportModal" class="" style="position:relative;display:none;"> <div style="padding: 10px;"> <div class="ckImportModalContent"> <div class="" id=""> <div class=""><h1><?php echo JText::_('CK_IMPORT'); ?></h1></div> <form id="importPage" method="post" enctype="multipart/form-data"> <div> <fieldset> <table class="table table-striped"> <tr> <td width="110" class="key"> <label for="title"> <?php echo JText::_('CK_CHOOSE_FILE_PBCK'); ?>: </label> </td> <td> <input class="inputbox" type="file" name="file" id="file" size="60" /> <input type="submit" name="submitfile" class="inputbox btn btn-primary" value="<?php echo JText::_('CK_INSTALL'); ?>" /> </td> </tr> </table> </fieldset> </div> <?php echo JHtml::_('form.token'); ?> <input type="hidden" name="task" value="pages.import" /> </form> </div> </div> </div> </div> <?php } /** * Import the file .pbck into the database */ public function importFile() { $file = $this->_input->files->get('file', '', 'array'); if (!is_array($file)) return false; $filename = JFile::makeSafe($file['name']); // check if the file exists if (JFile::getExt($filename) != 'pbck' && JFile::getExt($filename) != 'pbckz') { $msg = JText::_('CK_NOT_PBCK_FILE'); CKFof::redirect('index.php?option=com_pagebuilderck&view=pages', $msg, 'error'); return false; } //Set up the source and destination of the file $src = $file['tmp_name']; // check if the file exists if (!$src || !file_exists($src)) { $msg = JText::_('CK_FILE_NOT_EXISTS'); CKFof::redirect('index.php?option=com_pagebuilderck&view=pages', $msg, 'error'); return false; } if (Pagebuilderck\CKFile::getExt($filename) === 'pbck') { if (! $this->import_pbck_file($src) ) { return false; } } else if (Pagebuilderck\CKFile::getExt($filename) === 'pbckz') { if (! $this->import_pbckz_file($src) ) { return false; } } $msg = JText::_('CK_IMPORT_SUCCESS'); CKFof::redirect('index.php?option=com_pagebuilderck&view=pages', $msg, 'message'); return true; } public function import_pbck_file($src) { // read the file if (!$filecontent = file_get_contents($src)) { $msg = JText::_('CK_UNABLE_READ_FILE'); CKFof::redirect('index.php?option=com_pagebuilderck&view=pages', $msg, 'error'); return false; } // replace vars to allow data to be moved from another server $filecontent = str_replace("|URIROOT|", JUri::root(true), $filecontent); $filecontent = str_replace("|URIBASE|", PAGEBUILDERCK_URI_ROOT, $filecontent); $filecontent = str_replace("|PBCK_COMPONENT|", "components/com_pagebuilderck", $filecontent); $filecontent = str_replace("|PBCK_ADMIN_COMPONENT|", "administrator/components/com_pagebuilderck", $filecontent); $gabarit = json_decode($filecontent); if ($gabarit === null) { $msg = JText::_('CK_IMPORT_ERROR_IMPORT_FILE_DECODING'); CKFof::redirect('index.php?option=com_pagebuilderck&view=pages', $msg, 'message'); } $this->import_folder_name = $this->import_folder_name ? $this->import_folder_name : $gabarit->title; $gabarit->id = '0'; // set id to 0 to automatically increment value in database $gabarit->htmlcode = str_replace("|IMPORTFOLDER|", "images/" . $this->import_folder_name, $gabarit->htmlcode); $gabarit->htmlcode = stripslashes($gabarit->htmlcode); $gabarit->params = json_encode($gabarit->params); if (isset($gabarit->categories)) { $gabarit->categories = implode(',', $gabarit->categories); } $pageid = CKFof::dbStore('#__pagebuilderck_pages', $gabarit); return $pageid; } private function import_pbckz_file($src) { $dest_extracted_zip_folder = $this->extractFilesFromPbckz($src); $files = Pagebuilderck\CKFolder::files($dest_extracted_zip_folder, '.pbck'); if (count($files) > 1) { // more than one file to import found $msg = JText::_('CK_MULTIPLE_PBCKZ_FILES_FOUND'); CKFof::redirect("index.php?option=com_templateck&view=templateinfos&layout=install", $msg, 'error'); return false; } $gabaritfilename = $files[0]; $this->import_folder_name = str_replace('.pbck', '', $gabaritfilename); // import the tck3 gabarit file // $gabarit_file = array('tmp_name' => $dest_extracted_zip_folder . '/' . $import_folder_name . '.tck3'); // $gabarit_file = array('tmp_name' => $dest_extracted_zip_folder . '/' . $gabaritfilename); $gabarit_file = $dest_extracted_zip_folder . '/' . $gabaritfilename; $id = $this->import_pbck_file($gabarit_file); if ($id === false) { return false; } // create the destination folder for images if (! Pagebuilderck\CKFolder::exists( PAGEBUILDERCK_SITE_ROOT . '/images/' . $this->import_folder_name ) ) { Pagebuilderck\CKFolder::create( PAGEBUILDERCK_SITE_ROOT . '/images/' . $this->import_folder_name ); } // copy the images $exclude_files = array('pbck','css','php'); $files = Pagebuilderck\CKFolder::files($dest_extracted_zip_folder, false, true, true); foreach ($files as $file) { $filename = explode('/', $file); $filename = end($filename); if (! in_array(Pagebuilderck\CKFile::getExt($file), $exclude_files) ) { Pagebuilderck\CKFile::copy($file, PAGEBUILDERCK_SITE_ROOT . '/images/' . $this->import_folder_name . '/' . $filename); } } // remove the copy from the tmp folder Pagebuilderck\CKFolder::delete($dest_extracted_zip_folder); return $id; } private function extractFilesFromPbckz($src) { include_once PAGEBUILDERCK_PATH . '/helpers/zip.php'; // instanciate ZIP archiver $archiver = new CKArchiveZip(); // extract archive $gabarit_folder_name = JFile::stripext($src); $dest_extracted_zip_folder = PAGEBUILDERCK_SITE_ROOT . '/tmp/pagebuilderck-import'; // remove the folder if already exist JFolder::delete($dest_extracted_zip_folder); $isSuccess = $archiver->extract($src, $dest_extracted_zip_folder, $options = array()); if ($isSuccess === false) { return false; } return $dest_extracted_zip_folder; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings