File manager - Edit - /home/ferretapmx/public_html/controllers.zip
Back
PK ��\/N|OA A asset.php.neo_baknu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ // No direct access defined('_JEXEC') or die('Restricted access'); use Joomla\Archive\Archive; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\Helper\MediaHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Uri\Uri; require_once JPATH_ROOT . '/components/com_sppagebuilder/helpers/assets-css-parser.php'; /** * Asset Controller class * * @since 4.0.0 */ class SppagebuilderControllerAsset extends FormController { /** * Load custom icons. * * @return void * @since 4.0.0 */ public function loadCustomIcons() { $app = Factory::getApplication('site'); $input = $app->input; $model = $this->getModel(); $response = [ 'status' => true, 'data' => $model->loadCustomIcons() ]; $this->sendResponse($response, 200); } /** * Delete custom icon by id. * * @return void * @since 4.0.0 */ public function deleteCustomIcon() { $app = Factory::getApplication(); $input = $app->input; $model = $this->getModel(); $id = $input->getInt('id', 0); $response = [ 'status' => true, 'data' => $model->deleteCustomIcon($id) ]; $this->sendResponse($response, 200); } /** * Change custom icon's status. * * @return void * @since 4.0.0 */ public function changeCustomIconStatus() { $app = Factory::getApplication(); $input = $app->input; $model = $this->getModel(); $id = $input->getInt('id', 0); $status = $input->getInt('status', null); $response = [ 'status' => true, 'data' => $model->changeCustomIconStatus($id, $status) ]; $this->sendResponse($response, 200); } /** * Upload Custom Icons. * * @return void * @since 4.0.0 */ public function uploadCustomIcon() { $model = $this->getModel(); // Get file form input $input = Factory::getApplication()->input; $user = Factory::getUser(); $customIcon = $input->files->get('custom_icon', null); // Tmp path $tmp_path = Factory::getConfig()->get('tmp_path'); // Root path $rootPath = JPATH_ROOT . '/media/com_sppagebuilder/assets/iconfont/'; $rootUrl = 'media/com_sppagebuilder/assets/iconfont/'; $report = array(); if (empty($customIcon)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); echo json_encode($report); die(); } $fileDetails = \pathinfo($customIcon['name']); //check the root path if (!Folder::exists($rootPath)) { Folder::create($rootPath); } if ($customIcon['error'] == UPLOAD_ERR_OK) { $error = false; $params = ComponentHelper::getParams('com_media'); $contentLength = (int) $_SERVER['CONTENT_LENGTH']; $mediaHelper = new MediaHelper; $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size')); $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit')); // Check for the total size of post back data. if (($postMaxSize > 0 && $contentLength > $postMaxSize) || ($memoryLimit != -1 && $contentLength > $memoryLimit)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_TOTAL_SIZE_EXCEEDS'); $error = true; echo json_encode($report); die; } $uploadMaxSize = $params->get('upload_maxsize', 0) * 1024 * 1024; $uploadMaxFileSize = $mediaHelper->toBytes(ini_get('upload_max_filesize')); if (($customIcon['error'] == 1) || ($uploadMaxSize > 0 && $customIcon['size'] > $uploadMaxSize) || ($uploadMaxFileSize > 0 && $customIcon['size'] > $uploadMaxFileSize)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_LARGE'); $error = true; } if (!$error) { // get file name and file extension $package_name = File::stripExt($customIcon['name']); $name = File::stripExt($customIcon['name']); $report['name'] = $name; $ext = File::getExt($customIcon['name']); $tmp_dest = $rootPath . $customIcon['name']; $tmp_src = $customIcon['tmp_name']; $valid_icon = false; // $extract_path = $tmp_path . '/builderCustomIcon'; $zip_file = $tmp_path . '/builderCustomIcon.zip'; // Delete existing file and folder if (File::exists($zip_file)) { File::delete($zip_file); } // if (Folder::exists($extract_path)) // { // Folder::delete($extract_path); // } // Move uploaded file into asset iconfont folder. if( File::upload($tmp_src, $zip_file, false, true)) { $extract = $this->unpack($zip_file); if($extract) { $extract_path = $extract['dir']; // check and delete the zip file. if (File::exists($zip_file)) { File::delete($zip_file); } // IcoFont if (File::exists($extract_path . '/fonts/icofont.woff') && File::exists($extract_path . '/icofont.css') && File::exists($extract_path . '/icofont.min.css')) { if (Folder::exists($rootPath . '/icofont')) { Folder::delete($rootPath . '/icofont'); } Folder::create($rootPath . '/icofont', 0755); Folder::copy($extract_path . '/fonts', $rootPath . '/icofont/fonts'); File::copy($extract_path . '/icofont.css', $rootPath . '/icofont/icofont.css'); File::copy($extract_path . '/icofont.min.css', $rootPath . '/icofont/icofont.min.css'); $css = file_get_contents($rootPath . 'icofont/icofont.css'); $name = 'icofont'; $title = 'IcoFont'; $assets = SppbAssetCssParser::getClassName($css, 'icofont'); $css_path = $rootUrl . 'icofont/icofont.min.css'; $valid_icon = true; } // custom font elseif (File::exists($extract_path . '/config.json') || File::exists($extract_path . '/selection.json')) { if (File::exists($extract_path . '/selection.json')) { // Icomoon $config = json_decode(file_get_contents($extract_path . '/selection.json')); $fontFamily = isset($config->preferences->fontPref->metadata->fontFamily) ? $config->preferences->fontPref->metadata->fontFamily : ''; $prefix = isset($config->preferences->fontPref->prefix) ? $config->preferences->fontPref->prefix : ''; $font_path = 'fonts'; $font_css = 'style.css'; } else { // Fontello $config = json_decode(file_get_contents($extract_path . '/config.json')); if (File::exists($extract_path . '/font/fontello.woff') && File::exists($extract_path . '/css/fontello.css')) { $fontFamily = 'fontello'; $prefix = isset($config->css_prefix_text) ? $config->css_prefix_text : 'icon-'; $font_path = 'font'; $font_css = 'css/fontello.css'; } else { $fontFamily = isset($config->name) ? $config->name : ''; $prefix = isset($config->css_prefix_text) ? $config->css_prefix_text : ''; $font_path = 'font'; $font_css = 'css/' . $fontFamily . '.css'; } } if ($fontFamily && $prefix && Folder::exists($extract_path . '/' . $font_path) && File::exists($extract_path . '/' . $font_css)) { if (Folder::exists($rootPath . '/' . $fontFamily)) { Folder::delete($rootPath . '/' . $fontFamily); } Folder::create($rootPath . '/' . $fontFamily, 0755); Folder::create($rootPath . '/' . $fontFamily . '/css', 0755); // fontello only Folder::copy($extract_path . '/' . $font_path, $rootPath . '/' . $fontFamily . '/' . $font_path); File::copy($extract_path . '/'. $font_css, $rootPath . '/' . $fontFamily . '/' . $font_css); $css = file_get_contents($rootPath . $fontFamily . '/' . $font_css); $name = $fontFamily; $title = $fontFamily == 'icomoon' ? 'IcoMoon' : ucfirst($fontFamily); if (File::exists($extract_path . '/selection.json')) { $assets = SppbAssetCssParser::getClassName($css, rtrim($prefix, '-'), true); } else { $assets = SppbAssetCssParser::getClassName($css, rtrim($prefix, '-')); } $css_path = $rootUrl . $fontFamily . '/' . $font_css; $valid_icon = true; } else { $valid_icon = false; } } else { $valid_icon = false; } // delete if(Folder::exists($extract['extractdir'])) { Folder::delete($extract['extractdir']); } } else { $valid_icon = false; } // valid upload if ($valid_icon) { $assetData = [ 'type' => 'iconfont', 'name' => $name, 'title' => $title, 'assets' => $assets, 'css_path' => $css_path, 'created' => Factory::getDate()->toSql(), 'created_by' => Factory::getUser()->id, 'published' => 1, 'access' => 1 ]; $newIcon = $model->insertAsset($assetData); $report['data'] = $newIcon; $report['status'] = true; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_DONE'); } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FILE_NOT_SUPPORTED'); } } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); } } } echo json_encode($report); die(); } public function getIconProviders() { $model = $this->getModel(); $report = $model->getAssetProviders(); echo json_encode($report); die(); } public function loadIcons() { $input = Factory::getApplication()->input; $name = $input->json->get('name', NULL, 'STRING'); $title = $input->json->get('title', NULL, 'STRING'); $rootPath = Uri::base(true) . '/media/com_sppagebuilder/assets/iconfont/'; $report = array(); $css = $rootPath . $name . '/' . $name . '.css'; $model = $this->getModel(); $assets = $model->getIconList($name); $report['iconList'] = $assets; $report['css'] = $css; echo json_encode($report); die(); } /** * Unpacks a file and verifies it as a icofont package * Supports .gz .tar .tar.gz and .zip * * @param string $fontPackage The uploaded icon font package file * @param string $name File name. * @return boolean boolean false on failure * * @since 4.0.0 */ public static function unpack($packageFilename) { // Path to the archive $archivename = $packageFilename; // Temporary folder to extract the archive into $tmpdir = uniqid('builderCustomIcon_'); // Clean the paths to use for archive extraction $extractdir = Path::clean(dirname($packageFilename) . '/' . $tmpdir); $archivename = Path::clean($archivename); // Do the unpacking of the archive try { $archive = new Archive(array('tmp_path' => Factory::getConfig()->get('tmp_path'))); $extract = $archive->extract($archivename, $extractdir); } catch (\Exception $e) { return false; } if (!$extract) { return false; } /* * Let's set the extraction directory and package file in the result array so we can * cleanup everything properly later on. */ $retval['extractdir'] = $extractdir; $retval['packagefile'] = $archivename; /* * Try to find the correct install directory. In case the package is inside a * subdirectory detect this and set the install directory to the correct path. * * List all the items in the installation directory. If there is only one, and * it is a folder, then we will set that folder to be the installation folder. */ $dirList = array_merge((array) Folder::files($extractdir, ''), (array) Folder::folders($extractdir, '')); if (count($dirList) === 1) { if (Folder::exists($extractdir . '/' . $dirList[0])) { $extractdir = Path::clean($extractdir . '/' . $dirList[0]); } } /* * We have found the install directory so lets set it and then move on * to detecting the extension type. */ $retval['dir'] = $extractdir; return $retval; } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 4.0.0 */ private function sendResponse($response, int $statusCode = 200) : void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } } PK ��\6�Ni�B �B asset.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ // No direct access defined('_JEXEC') or die('Restricted access'); use Joomla\Archive\Archive; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Factory; use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\Helper\MediaHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Uri\Uri; require_once JPATH_ROOT . '/components/com_sppagebuilder/helpers/assets-css-parser.php'; /** * Asset Controller class * * @since 4.0.0 */ class SppagebuilderControllerAsset extends FormController { /** * Load custom icons. * * @return void * @since 4.0.0 */ public function loadCustomIcons() { $app = Factory::getApplication('site'); $input = $app->input; $model = $this->getModel(); $response = [ 'status' => true, 'data' => $model->loadCustomIcons() ]; $this->sendResponse($response, 200); } /** * Delete custom icon by id. * * @return void * @since 4.0.0 */ public function deleteCustomIcon() { $app = Factory::getApplication(); $input = $app->input; $model = $this->getModel(); $id = $input->getInt('id', 0); $response = [ 'status' => true, 'data' => $model->deleteCustomIcon($id) ]; $this->sendResponse($response, 200); } /** * Change custom icon's status. * * @return void * @since 4.0.0 */ public function changeCustomIconStatus() { $app = Factory::getApplication(); $input = $app->input; $model = $this->getModel(); $id = $input->getInt('id', 0); $status = $input->getInt('status', null); $response = [ 'status' => true, 'data' => $model->changeCustomIconStatus($id, $status) ]; $this->sendResponse($response, 200); } /** * Upload Custom Icons. * * @return void * @since 4.0.0 */ public function uploadCustomIcon() { // NEO_PATCH_662 $app = \Joomla\CMS\Factory::getApplication(); if (!$app->getIdentity()->authorise("core.manage","com_sppagebuilder")) { @http_response_code(403); @header("Content-Type: application/json"); echo json_encode(array("success"=>false,"message"=>null,"data"=>array("message"=>"You require admin access to use this application."))); $app->close(); } $model = $this->getModel(); // Get file form input $input = Factory::getApplication()->input; $user = Factory::getUser(); $customIcon = $input->files->get('custom_icon', null); // Tmp path $tmp_path = Factory::getConfig()->get('tmp_path'); // Root path $rootPath = JPATH_ROOT . '/media/com_sppagebuilder/assets/iconfont/'; $rootUrl = 'media/com_sppagebuilder/assets/iconfont/'; $report = array(); if (empty($customIcon)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); echo json_encode($report); die(); } $fileDetails = \pathinfo($customIcon['name']); //check the root path if (!Folder::exists($rootPath)) { Folder::create($rootPath); } if ($customIcon['error'] == UPLOAD_ERR_OK) { $error = false; $params = ComponentHelper::getParams('com_media'); $contentLength = (int) $_SERVER['CONTENT_LENGTH']; $mediaHelper = new MediaHelper; $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size')); $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit')); // Check for the total size of post back data. if (($postMaxSize > 0 && $contentLength > $postMaxSize) || ($memoryLimit != -1 && $contentLength > $memoryLimit)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_TOTAL_SIZE_EXCEEDS'); $error = true; echo json_encode($report); die; } $uploadMaxSize = $params->get('upload_maxsize', 0) * 1024 * 1024; $uploadMaxFileSize = $mediaHelper->toBytes(ini_get('upload_max_filesize')); if (($customIcon['error'] == 1) || ($uploadMaxSize > 0 && $customIcon['size'] > $uploadMaxSize) || ($uploadMaxFileSize > 0 && $customIcon['size'] > $uploadMaxFileSize)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_LARGE'); $error = true; } if (!$error) { // get file name and file extension $package_name = File::stripExt($customIcon['name']); $name = File::stripExt($customIcon['name']); $report['name'] = $name; $ext = File::getExt($customIcon['name']); $tmp_dest = $rootPath . $customIcon['name']; $tmp_src = $customIcon['tmp_name']; $valid_icon = false; // $extract_path = $tmp_path . '/builderCustomIcon'; $zip_file = $tmp_path . '/builderCustomIcon.zip'; // Delete existing file and folder if (File::exists($zip_file)) { File::delete($zip_file); } // if (Folder::exists($extract_path)) // { // Folder::delete($extract_path); // } // Move uploaded file into asset iconfont folder. if( File::upload($tmp_src, $zip_file, false, true)) { $extract = $this->unpack($zip_file); if($extract) { $extract_path = $extract['dir']; // check and delete the zip file. if (File::exists($zip_file)) { File::delete($zip_file); } // IcoFont if (File::exists($extract_path . '/fonts/icofont.woff') && File::exists($extract_path . '/icofont.css') && File::exists($extract_path . '/icofont.min.css')) { if (Folder::exists($rootPath . '/icofont')) { Folder::delete($rootPath . '/icofont'); } Folder::create($rootPath . '/icofont', 0755); Folder::copy($extract_path . '/fonts', $rootPath . '/icofont/fonts'); File::copy($extract_path . '/icofont.css', $rootPath . '/icofont/icofont.css'); File::copy($extract_path . '/icofont.min.css', $rootPath . '/icofont/icofont.min.css'); $css = file_get_contents($rootPath . 'icofont/icofont.css'); $name = 'icofont'; $title = 'IcoFont'; $assets = SppbAssetCssParser::getClassName($css, 'icofont'); $css_path = $rootUrl . 'icofont/icofont.min.css'; $valid_icon = true; } // custom font elseif (File::exists($extract_path . '/config.json') || File::exists($extract_path . '/selection.json')) { if (File::exists($extract_path . '/selection.json')) { // Icomoon $config = json_decode(file_get_contents($extract_path . '/selection.json')); $fontFamily = isset($config->preferences->fontPref->metadata->fontFamily) ? $config->preferences->fontPref->metadata->fontFamily : ''; $prefix = isset($config->preferences->fontPref->prefix) ? $config->preferences->fontPref->prefix : ''; $font_path = 'fonts'; $font_css = 'style.css'; } else { // Fontello $config = json_decode(file_get_contents($extract_path . '/config.json')); if (File::exists($extract_path . '/font/fontello.woff') && File::exists($extract_path . '/css/fontello.css')) { $fontFamily = 'fontello'; $prefix = isset($config->css_prefix_text) ? $config->css_prefix_text : 'icon-'; $font_path = 'font'; $font_css = 'css/fontello.css'; } else { $fontFamily = isset($config->name) ? $config->name : ''; $prefix = isset($config->css_prefix_text) ? $config->css_prefix_text : ''; $font_path = 'font'; $font_css = 'css/' . $fontFamily . '.css'; } } if ($fontFamily && $prefix && Folder::exists($extract_path . '/' . $font_path) && File::exists($extract_path . '/' . $font_css)) { if (Folder::exists($rootPath . '/' . $fontFamily)) { Folder::delete($rootPath . '/' . $fontFamily); } Folder::create($rootPath . '/' . $fontFamily, 0755); Folder::create($rootPath . '/' . $fontFamily . '/css', 0755); // fontello only Folder::copy($extract_path . '/' . $font_path, $rootPath . '/' . $fontFamily . '/' . $font_path); File::copy($extract_path . '/'. $font_css, $rootPath . '/' . $fontFamily . '/' . $font_css); $css = file_get_contents($rootPath . $fontFamily . '/' . $font_css); $name = $fontFamily; $title = $fontFamily == 'icomoon' ? 'IcoMoon' : ucfirst($fontFamily); if (File::exists($extract_path . '/selection.json')) { $assets = SppbAssetCssParser::getClassName($css, rtrim($prefix, '-'), true); } else { $assets = SppbAssetCssParser::getClassName($css, rtrim($prefix, '-')); } $css_path = $rootUrl . $fontFamily . '/' . $font_css; $valid_icon = true; } else { $valid_icon = false; } } else { $valid_icon = false; } // delete if(Folder::exists($extract['extractdir'])) { Folder::delete($extract['extractdir']); } } else { $valid_icon = false; } // valid upload if ($valid_icon) { $assetData = [ 'type' => 'iconfont', 'name' => $name, 'title' => $title, 'assets' => $assets, 'css_path' => $css_path, 'created' => Factory::getDate()->toSql(), 'created_by' => Factory::getUser()->id, 'published' => 1, 'access' => 1 ]; $newIcon = $model->insertAsset($assetData); $report['data'] = $newIcon; $report['status'] = true; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_DONE'); } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FILE_NOT_SUPPORTED'); } } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); } } } echo json_encode($report); die(); } public function getIconProviders() { $model = $this->getModel(); $report = $model->getAssetProviders(); echo json_encode($report); die(); } public function loadIcons() { $input = Factory::getApplication()->input; $name = $input->json->get('name', NULL, 'STRING'); $title = $input->json->get('title', NULL, 'STRING'); $rootPath = Uri::base(true) . '/media/com_sppagebuilder/assets/iconfont/'; $report = array(); $css = $rootPath . $name . '/' . $name . '.css'; $model = $this->getModel(); $assets = $model->getIconList($name); $report['iconList'] = $assets; $report['css'] = $css; echo json_encode($report); die(); } /** * Unpacks a file and verifies it as a icofont package * Supports .gz .tar .tar.gz and .zip * * @param string $fontPackage The uploaded icon font package file * @param string $name File name. * @return boolean boolean false on failure * * @since 4.0.0 */ public static function unpack($packageFilename) { // Path to the archive $archivename = $packageFilename; // Temporary folder to extract the archive into $tmpdir = uniqid('builderCustomIcon_'); // Clean the paths to use for archive extraction $extractdir = Path::clean(dirname($packageFilename) . '/' . $tmpdir); $archivename = Path::clean($archivename); // Do the unpacking of the archive try { $archive = new Archive(array('tmp_path' => Factory::getConfig()->get('tmp_path'))); $extract = $archive->extract($archivename, $extractdir); } catch (\Exception $e) { return false; } if (!$extract) { return false; } /* * Let's set the extraction directory and package file in the result array so we can * cleanup everything properly later on. */ $retval['extractdir'] = $extractdir; $retval['packagefile'] = $archivename; /* * Try to find the correct install directory. In case the package is inside a * subdirectory detect this and set the install directory to the correct path. * * List all the items in the installation directory. If there is only one, and * it is a folder, then we will set that folder to be the installation folder. */ $dirList = array_merge((array) Folder::files($extractdir, ''), (array) Folder::folders($extractdir, '')); if (count($dirList) === 1) { if (Folder::exists($extractdir . '/' . $dirList[0])) { $extractdir = Path::clean($extractdir . '/' . $dirList[0]); } } /* * We have found the install directory so lets set it and then move on * to detecting the extension type. */ $retval['dir'] = $extractdir; return $retval; } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 4.0.0 */ private function sendResponse($response, int $statusCode = 200) : void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } } PK ��\�ۖ�! ! saved_items_order.phpnu �[��� <?php use Joomla\CMS\Factory; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\Response\JsonResponse; use Joomla\Utilities\ArrayHelper; /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2024 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ //no direct access defined('_JEXEC') or die('Restricted access'); class SppagebuilderControllerSaved_items_order extends FormController { /** * Update Saved Items Order */ public function updateSavedItemsOrder() { $input = Factory::getApplication()->input; $pks = $input->json->get('ids', '', 'STRING'); $orders = $input->json->get('orders', '', 'STRING'); $type = $input->json->get('type', '', 'STRING'); if (empty($pks) || empty($orders) || empty($type)) { $response['message'] = 'Missing ids or orders'; $this->sendResponse($response, 400); } BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_sppagebuilder/models'); $model = $this->getModel($type, 'SppagebuilderModel'); $pks = ArrayHelper::toInteger($pks); $orders = ArrayHelper::toInteger($orders); try { $model->saveorder($pks, $orders); $this->sendResponse(true); } catch (\Exception $e) { $response['message'] = $e->getMessage(); $this->sendResponse($response, 500); } } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 5.0.0 */ private function sendResponse($response, int $statusCode = 200): void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } } PK ��\lB� color.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ // No direct access defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Response\JsonResponse; /** * Color Controller class * * @since 5.0.0 */ class SppagebuilderControllerColor extends FormController { /** * Get global colors */ public function globalColors() { $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select(['id', 'name', 'colors']) ->from($db->quoteName('#__sppagebuilder_colors')) ->where($db->quoteName('published') . ' = 1'); $db->setQuery($query); $colors = []; try { $colors = $db->loadObjectList(); } catch (\Exception $e) { return []; } if (!empty($colors)) { foreach ($colors as &$color) { $color->colors = \json_decode($color->colors); } unset($color); } $this->sendResponse($colors); } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 5.0.0 */ private function sendResponse($response, int $statusCode = 200) : void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } } PK ��\�j/��a �a page.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ //no direct access defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Http\Http; use Joomla\CMS\Table\Table; use Joomla\CMS\Language\Text; use Joomla\CMS\Filesystem\File; use Joomla\CMS\Session\Session; use Joomla\CMS\Filter\OutputFilter; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\MVC\Model\BaseDatabaseModel; use Joomla\CMS\MVC\Controller\FormController; use Joomla\Filesystem\File as FilesystemFile; class SppagebuilderControllerPage extends FormController { public function __construct($config = array()) { parent::__construct($config); if (!Session::checkToken()) { $response = [ 'status' => false, 'message' => Text::_('JLIB_ENVIRONMENT_SESSION_EXPIRED') ]; echo json_encode($response); die(); } // check have access $user = Factory::getUser(); $authorised = $user->authorise('core.edit', 'com_sppagebuilder'); if (!$authorised) { $response = [ 'status' => false, 'message' => Text::_('JERROR_ALERTNOAUTHOR') ]; echo json_encode($response); die(); } } /** * Get the page model * * @param string $name * @param string $prefix * @param array $config * @return SppagebuilderModelPage */ public function getModel($name = 'form', $prefix = '', $config = array('ignore_request' => true)) { $model = parent::getModel($name, $prefix, $config); return $model; } /** * Exit from the edit page. * * @return void * @since 4.0.0 */ public function exitExitPage() { $app = Factory::getApplication('site'); $input = $app->input; $user = Factory::getUser(); $model = $this->getModel(); $pageId = $input->get('id', 0, 'INT'); $root = Uri::base(); $root = new Uri($root); $response = ['response' => Text::_("COM_SPPAGEBUILDER_ERROR_MSG"), 'status' => false, 'code' => 500]; if (!$pageId) { $response['response'] = 'Invalid page ID!'; $response['status'] = false; $response['code'] = 404; } $table = $model->getTable(); try { if ($table->checkIn($pageId)) { $response['response'] = Uri::base() . 'index.php?option=com_sppagebuilder&view=dashboard&tmpl=component'; $response['status'] = true; $response['code'] = 200; } else { $response['response'] = 'Cannot checking out the user!'; $response['status'] = false; $response['code'] = 500; } } catch (Exception $e) { $response['response'] = $e->getMessage(); $response['status'] = false; $response['code'] = 500; } $statusCode = $response['code']; unset($response['code']); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } public function save($key = null, $urlVar = null) { $user = Factory::getUser(); $app = Factory::getApplication(); $input = $app->input; $Itemid = $input->get('Itemid', 0, 'INT'); $root = Uri::base(); $root = new Uri($root); $link = $root->getScheme() . '://' . $root->getHost(); $model = $this->getModel('Form'); $data = $this->input->post->get('jform', array(), 'array'); $task = $this->getTask(); $context = 'com_sppagebuilder.edit.page'; $recordId = $data['id']; $output = array(); //Authorized if (empty($recordId)) { $authorised = $user->authorise('core.create', 'com_sppagebuilder') || (count((array) $user->getAuthorisedCategories('com_sppagebuilder', 'core.create'))); } else { $authorised = $user->authorise('core.edit', 'com_sppagebuilder') || $user->authorise('core.edit', 'com_sppagebuilder.page.' . $recordId) || ($user->authorise('core.edit.own', 'com_sppagebuilder.page.' . $recordId) && $data['created_by'] == $user->id); } if ($authorised !== true) { $output['status'] = false; $output['message'] = Text::_('JERROR_ALERTNOAUTHOR'); echo json_encode($output); die(); } // Check for request forgeries. $output['status'] = false; $output['message'] = Text::_('JINVALID_TOKEN'); Session::checkToken() or die(json_encode($output)); $output['status'] = true; // Check for validation errors. if ($data === false) { // Get the validation messages. $errors = $model->getErrors(); $output['status'] = false; $output['message'] = ''; // Push up to three validation messages out to the user. for ($i = 0, $n = count((array) $errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $output['message'] .= $errors[$i]->getMessage(); } else { $output['message'] .= $errors[$i]; } } // Save the data in the session. $app->setUserState('com_sppagebuilder.edit.page.data', $data); // Redirect back to the edit screen. $url = $link . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $recordId . '&Itemid=' . $Itemid; $output['redirect'] = $url; echo json_encode($output); die(); } if ($itemOld = $model->getPageItem($recordId)) { if ($itemOld->extension == 'com_content' && $itemOld->extension_view == 'article' && $itemOld->view_id) { $data['catid'] = $itemOld->catid; } } // Attempt to save the data. if (!$model->save($data)) { // Save the data in the session. $app->setUserState('com_sppagebuilder.edit.page.data', $data); // Redirect back to the edit screen. $output['status'] = false; $output['message'] = Text::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()); $output['redirect'] = $link . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $recordId . '&Itemid=' . $Itemid; echo json_encode($output); die(); } // Save succeeded, check-in the row. if ($model->checkin($data['id']) === false) { // Check-in failed, go back to the row and display a notice. $output['status'] = false; $output['message'] = Text::sprintf('JLIB_APPLICATION_ERROR_CHECKIN_FAILED', $model->getError()); $output['redirect'] = $link . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $recordId . '&Itemid=' . $Itemid; echo json_encode($output); die(); } $output['status'] = true; $output['message'] = Text::_('COM_SPPAGEBUILDER_PAGE_SAVE_SUCCESS'); // Redirect the user and adjust session state based on the chosen task. switch ($task) { case 'apply': // Set the row data in the session. $this->holdEditId($context, $recordId); $app->setUserState('com_sppagebuilder.edit.page.data', null); // Convert json to readable article text $oldPage = $model->getItem($recordId); if ($oldPage->extension == 'com_content' && $oldPage->extension_view == 'article') { $model->addArticleFullText($oldPage->view_id, $oldPage->text); } // Delete generated CSS file $css_folder_path = JPATH_ROOT . '/media/com_sppagebuilder/css'; $css_file_path = $css_folder_path . '/page-' . $recordId . '.css'; if (file_exists($css_file_path)) { FilesystemFile::delete($css_file_path); } // Redirect back to the edit screen. $output['redirect'] = $link . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $recordId . '&Itemid=' . $Itemid; $output['id'] = $recordId; break; default: // Clear the row id and data in the session. $this->releaseEditId($context, $recordId); $app->setUserState('com_sppagebuilder.edit.page.data', null); // Redirect to the list screen. $output['redirect'] = $link . 'index.php?option=' . $this->option . '&view=' . $this->view_list . $this->getRedirectToListAppend(); break; } echo json_encode($output); die(); } public function getMySections() { $model = $this->getModel(); die($model->getMySections()); } public function deleteSection() { $model = $this->getModel(); $app = Factory::getApplication(); $input = $app->input; $id = $input->get('id', '', 'INT'); die($model->deleteSection($id)); } public function saveSection() { $model = $this->getModel(); $app = Factory::getApplication(); $input = $app->input; $title = htmlspecialchars($input->get('title', '', 'STRING')); $section = $input->get('section', '', 'RAW'); if ($title && $section) { $section_id = $model->saveSection($title, $section); echo $section_id; die(); } else { die('Failed'); } } public function getMyAddons() { $model = $this->getModel(); die($model->getMyAddons()); } /** * Save Addon method. * * @return void * @since 1.0.0 */ public function saveCode() { $input = Factory::getApplication()->input; $title = $input->json->get('title', '', 'STRING'); $code = $input->json->get('code', [], 'ARRAY'); $codeCategory = $input->json->get('category', '', 'STRING'); $response = [ 'status' => false, 'data' => 'Something went wrong! Please try again later.' ]; if (empty($title) || empty($code) || empty($codeCategory)) { $response['data'] = 'Information missing.'; echo json_encode($response); die(); } if (is_array($code)) { $code = json_encode($code); } $data = new stdClass; $data->title = $title; if ($codeCategory === 'section') { $data->section = $code; $table = '#__sppagebuilder_sections'; } elseif ($codeCategory === 'addon') { $data->code = $code; $table = '#__sppagebuilder_addons'; } $data->created = Factory::getDate()->toSql(); $data->created_by = Factory::getUser()->id; try { $db = Factory::getDbo(); $db->insertObject($table, $data, 'id'); $response = [ 'status' => true, 'data' => ucfirst($codeCategory) . ' saved successfully!' ]; echo json_encode($response); die(); } catch (Exception $e) { $response = [ 'status' => false, 'data' => $e->getMessage() ]; echo json_encode($response); die(); } echo json_encode($response); die(); } public function deleteAddon() { $model = $this->getModel(); $app = Factory::getApplication(); $input = $app->input; $id = $input->get('id', '', 'INT'); die($model->deleteAddon($id)); } public function myPages() { $model = $this->getModel('Page'); $model->getMyPages(); die(); } public function cancel($key = 'id') { parent::cancel($key); $return_url = Factory::getApplication()->input->get('return_page', null, 'base64'); $this->setRedirect(base64_decode($return_url)); } public function addToMenu() { $output = array(); $data = $this->input->post->get('jform', array(), 'array'); $pageId = (int) $this->input->get->get('pageId', 0, 'INT'); BaseDatabaseModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/models'); Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables'); $formModel = $this->getModel('Form'); $model = $this->getModel('Item', 'MenusModel'); //Check menu $menuId = (isset($data['menuid']) && $data['menuid']) ? $data['menuid'] : 0; $menutitle = (isset($data['menutitle']) && $data['menutitle']) ? $data['menutitle'] : ''; $menualias = (isset($data['menualias']) && $data['menualias']) ? $data['menualias'] : OutputFilter::stringURLSafe($menutitle); $menutype = (isset($data['menutype']) && $data['menutype']) ? $data['menutype'] : ''; $menuparent_id = (isset($data['menuparent_id']) && $data['menuparent_id']) ? $data['menuparent_id'] : 0; $menuordering = (isset($data['menuordering']) && $data['menuordering']) ? $data['menuordering'] : -2; $link = 'index.php?option=com_sppagebuilder&view=page&id=' . (int) $pageId; $component_id = ComponentHelper::getComponent('com_sppagebuilder')->id; $menu = $formModel->getMenuById($menuId); $home = (isset($menu->home) && $menu->home) ? $menu->home : 0; $menuData = array( 'id' => (int) $menuId, 'link' => $link, 'parent_id' => (int) $menuparent_id, 'menutype' => htmlspecialchars($menutype), 'title' => htmlspecialchars($menutitle), 'alias' => htmlspecialchars($menualias), 'type' => 'component', 'published' => 1, 'language' => '*', 'component_id' => $component_id, 'menuordering' => (int) $menuordering, 'home' => (int) $home ); $message = ($menuId) ? 'Menu successfully updated' : 'Added to a new menu'; if ($model->save($menuData)) { $menu = $formModel->getMenuByAlias($menualias); $menuId = $menu->id; $output['status'] = true; $output['alias'] = $menualias; $output['menuid'] = $menuId; $output['success'] = $message; $Itemid = $formModel->getMenuByPageId($pageId); $menuItemId = 0; if (isset($Itemid->id) && $Itemid->id) { $menuItemId = '&Itemid=' . $Itemid->id; } $root = Uri::base(); $root = new Uri($root); $output['redirect'] = Uri::base() . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $pageId . $menuItemId; } else { $output['status'] = false; $output['error'] = $model->getError(); } die(json_encode($output)); } public function getMenuParentItem() { BaseDatabaseModel::addIncludePath(JPATH_SITE . '/administrator/components/com_menus/models'); $app = Factory::getApplication(); $results = array(); $menutype = $this->input->get->get('menutype', ''); $parent_id = $this->input->get->get('parent_id', 0); if ($menutype) { $model = $this->getModel('Items', 'MenusModel', array()); $model->getState(); $model->setState('filter.menutype', $menutype); $model->setState('list.select', 'a.id, a.title, a.level'); $model->setState('list.start', '0'); $model->setState('list.limit', '0'); $results = $model->getItems(); for ($i = 0, $n = count($results); $i < $n; $i++) { $results[$i]->title = str_repeat(' - ', $results[$i]->level) . $results[$i]->title; } } echo json_encode($results); $app->close(); } public function createNewPage() { $output = array(); $app = Factory::getApplication(); $user = Factory::getUser(); $authorised = $user->authorise('core.create', 'com_sppagebuilder'); if (!$authorised) { $output['status'] = false; $output['message'] = Text::_('JERROR_ALERTNOAUTHOR'); die(json_encode($output)); } $title = trim(htmlspecialchars($this->input->post->get('title', '', 'STRING'))); $model = $this->getModel('Form'); $id = $model->createNewPage($title); $root = Uri::base(); $root = new Uri($root); $redirect = Uri::base() . 'index.php?option=com_sppagebuilder&view=form&layout=edit&tmpl=component&id=' . $id; $output['status'] = true; $output['message'] = Text::_('Page created successfully.'); $output['redirect'] = $redirect; die(json_encode($output)); } public function deletePage() { $output = array(); $app = Factory::getApplication(); $user = Factory::getUser(); $authorised = $user->authorise('core.delete', 'com_sppagebuilder'); if (!$authorised) { $output['status'] = false; $output['message'] = Text::_('JERROR_ALERTNOAUTHOR'); die(json_encode($output)); } $pageid = (int) $this->input->post->get('pageid', '', 'INT'); $model = $this->getModel('Form'); $result = $model->deletePage($pageid); if (!$result) { $output['message'] = Text::_('Unable to delete this page.'); } $output['status'] = $result; die(json_encode($output)); } private function getFields($fieldset, $xml) { // Make sure there is a valid JForm XML document. if (!($xml instanceof \SimpleXMLElement)) { return false; } /* * Get an array of <field /> elements that are underneath a <fieldset /> element * with the appropriate name attribute, and also any <field /> elements with * the appropriate fieldset attribute. To allow repeatable elements only fields * which are not descendants of other fields are selected. */ $fields = $xml->xpath('(//fieldset[@name="' . $fieldset . '"]//field | //field[@fieldset="' . $fieldset . '"])[not(ancestor::field)]'); return (array) $fields; } /** * Read the page.xml form and extract information from it for rendering * into reactJS. * * @return void * @since 4.0.0 */ public function getPageForm() { $model = $this->getModel(); $input = Factory::getApplication()->input; $id = $input->getInt('id', 0); $model->setState('page.id', $id); $data = []; $form = $model->getForm(); $formXml = $form->getXml(); $groups = $form->getFieldsets(); foreach ($groups as $name => $group) { $fields = $this->getFields($name, $formXml); foreach ($fields as $field) { if (version_compare(PHP_VERSION, '7.4.0', '>=')) { $simpleXMLObj = get_mangled_object_vars($field->attributes()); $fieldArray = (new ArrayIterator($simpleXMLObj))->current(); } else { $fieldArray = current($field->attributes()); } $fieldName = $fieldArray['name']; $fieldArray['label'] = isset($fieldArray['label']) ? Text::_($fieldArray['label']) : ''; $fieldArray['desc'] = isset($fieldArray['desc']) ? Text::_($fieldArray['desc']) : ''; $value = $form->getValue($fieldName); $fieldArray['value'] = $value; if($fieldName === 'language') { $fieldArray['options'] = $model->getLanguages(); $data[$name][] = $fieldArray; continue; } $formField = $form->getField($fieldName); $options = $formField->options; if (isset($options)) { foreach ($options as &$option) { $option->text = Text::_($option->text); } unset($option); $fieldArray['options'] = $options; } $data[$name][] = $fieldArray; } } $response = ['status' => true, 'data' => $data]; echo json_encode($response); die(); } /** * Save the page data. * * @return void * @since 4.0.0 */ public function saveData() { $input = Factory::getApplication()->input; $id = $input->get('id', 0, 'INT'); $data = $input->json->get('data', [], 'ARRAY'); if ($data['published'] === '') { $data['published'] = '0'; } $model = $this->getModel(); $response = $model->saveData($data, $id); $model->checkin($id); echo json_encode($response); die(); } /** * Get importing layout page information from JoomShaper site. * * @return void * @since 4.0.0 */ public function importLayout() { $http = new Http; $input = Factory::getApplication()->input; $params = ComponentHelper::getParams('com_sppagebuilder'); $id = $input->get('id', 0, 'INT'); $email = $params->get('joomshaper_email'); $apiKey = $params->get('joomshaper_license_key'); $response = [ 'status' => false, 'data' => 'Page not found!' ]; if (empty($id)) { $response = [ 'status' => false, 'data' => 'Invalid layout ID given!' ]; echo json_encode($response); die(); } if (empty($email) || empty($apiKey)) { $response = [ 'status' => false, 'data' => 'Invalid email and license key!' ]; echo json_encode($response); die(); } $apiURL = 'https://www.joomshaper.com/index.php?option=com_layouts&task=template.download&support=4beyond&id=' . $id . '&email=' . $email . '&api_key=' . $apiKey; $pageResponse = $http->get($apiURL); $pageData = $pageResponse->body; if ($pageResponse->code !== 200) { $response = ['status' => false, 'data' => $pageData->error->message]; } if (!empty($templatesData)) { File::write($cache_file, $templatesData); } if (!empty($pageData)) { $pageData = json_decode($pageData); $pageDataContent = $pageData->content; $content = (object) ['template' => '', 'css' => '']; if (!isset($pageDataContent->template)) { $content->template = json_encode($pageDataContent); } else { $pageDataContent->template = !\is_string($pageDataContent->template) ? json_encode($pageDataContent->template) : $pageDataContent->template; $content = $pageDataContent; } if (!empty($pageData->status)) { require_once JPATH_COMPONENT_SITE . '/builder/classes/addon.php'; $content->template = ApplicationHelper::sanitizePageText($content->template); $content->template = json_encode($content->template); $content->template = json_decode(SppagebuilderHelperSite::sanitizeImportJSON($content->template)); $response = [ 'status' => true, 'data' => $content ]; echo json_encode($response); die(); } elseif ($pageData->authorised) { $response = [ 'status' => false, 'data' => $pageData->authorised ]; echo json_encode($response); die(); } } echo json_encode($response); die(); } /** * Save page information to the database. * * @return void * @since 4.0.0 */ public function savePage() { $input = Factory::getApplication()->input; $id = $input->getInt('id', 0); $data = $input->json->get('data', [], 'ARRAY'); $response = [ 'status' => false, 'message' => 'Something went wrong! Page not saved.' ]; if (empty($id)) { $response['message'] = 'Invalid page id given!'; echo json_encode($response); die(); } if (!empty($data)) { foreach ($data as &$row) { foreach ($row['columns'] as &$column) { foreach ($column['addons'] as &$addon) { if (isset($addon['type']) && ($addon['type'] === 'sp_row' || $addon['type'] === 'inner_row')) { foreach ($addon['columns'] as &$innerColumn) { foreach ($innerColumn['addons'] as &$innerAddon) { if (isset($innerAddon['htmlContent'])) { unset($innerAddon['htmlContent']); } if (isset($innerAddon['assets'])) { unset($innerAddon['assets']); } } unset($innerAddon); } unset($innerColumn); } else { if (isset($addon['htmlContent'])) { unset($addon['htmlContent']); } if (isset($addon['assets'])) { unset($addon['assets']); } } } unset($addon); } unset($column); } unset($row); } $version = SppagebuilderHelper::getVersion(); $pageData = new stdClass; $pageData->id = $id; $pageData->content = json_encode($data); // $pageData->content = EditorUtils::cleanXSS($data); $pageData->modified = Factory::getDate()->toSql(); $pageData->modified_by = Factory::getUser()->get('id'); $pageData->version = $version; /** @var SppagebuilderModelForm */ $model = $this->getModel('Form'); $pageModel = $this->getModel(); $oldPage = $model->getItem($id); $oldPage = ApplicationHelper::preparePageData($oldPage); if ($oldPage->extension == 'com_content' && $oldPage->extension_view == 'article') { $model->addArticleFullText($oldPage->view_id, json_encode($oldPage->text)); } try { // $db = Factory::getDbo(); // $db->updateObject('#__sppagebuilder', $pageData, 'id', true); if (!$model->savePage((array) $pageData)) { $response = [ 'status' => false, 'message' => 'Error saving the page' ]; echo json_encode($response); die(); } $pageModel->checkin($id); $response = [ 'status' => true, 'message' => 'Page data saved successfully!' ]; echo json_encode($response); die(); } catch (Exception $e) { $response = [ 'status' => false, 'message' => $e->getMessage() ]; echo json_encode($response); die(); } echo json_encode($response); die(); } public function loadPagesList() { $result = []; $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('id AS value, title AS label') ->from($db->quoteName('#__sppagebuilder')) ->where($db->quoteName('extension_view') . '=' . $db->quote('page')) ->where($db->quoteName('published') . ' = 1'); $query->order($db->quoteName('ordering') . ' ASC'); $db->setQuery($query); try { $result = $db->loadObjectList(); } catch (Exception $e) { echo json_encode([]); die; } echo \json_encode($result); die; } public function loadSiteMenus() { $result = []; $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('id, title, link, menutype') ->from($db->quoteName('#__menu')) ->where($db->quoteName('id') . ' > 1') ->where($db->quoteName('published') . ' = 1') ->where($db->quoteName('client_id') . ' = 0'); $query->order($db->quoteName('lft') . ' ASC'); $db->setQuery($query); try { $result = $db->loadObjectList(); } catch (Exception $e) { echo json_encode([]); die; } if (!empty($result)) { $result = array_map(function ($item) { $obj = new \stdClass; $obj->value = $item->link . '&Itemid=' . $item->id; $obj->label = Text::_($item->title); return $obj; }, $result); } echo \json_encode($result); die; } } PK ��\K�5Bf Bf media.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ //no direct access defined('_JEXEC') or die('Restricted access'); require_once JPATH_COMPONENT . '/helpers/image.php'; use Joomla\CMS\Factory; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Language\Text; use Joomla\CMS\Filesystem\File; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\Helper\MediaHelper; use Joomla\CMS\Filter\OutputFilter; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Session\Session; class SppagebuilderControllerMedia extends FormController { public function getModel($name = 'Media', $prefix = '', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, $config); } public function __construct($config = []) { parent::__construct($config); // check have access $user = Factory::getUser(); $authorised = $user->authorise('core.admin', 'com_sppagebuilder') || $user->authorise('core.manage', 'com_sppagebuilder'); if (!$authorised) { $response = [ 'status' => false, 'message' => Text::_('JERROR_ALERTNOAUTHOR') ]; echo json_encode($response); die(); } } private function getMediaOwnerById($id) { $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('created_by') ->from($db->quoteName('#__spmedia')) ->where($db->quoteName('id') . ' = ' . $id); $db->setQuery($query); try { return $db->loadResult(); } catch (\Exception $e) { return 0; } } /** * Rename the media file * * @return void */ public function renameMedia() { $app = Factory::getApplication('site'); $input = $app->input; $id = $input->json->get('id', 0, 'INT'); $title = $input->json->get('title', '', 'STR'); $path = $input->json->get('path', '', 'STR'); $thumb = $input->json->get('thumb', '', 'STR'); $mediaType = empty($id) ? 'folder' : 'DB'; $data = new \stdClass; $data->id = $id; $data->title = $title; $data->path = $this->replacePathByTitle($path, $title); $data->thumb = $this->replacePathByTitle($thumb, $title); $data->modified_on = Factory::getDate()->toSql(); $data->modified_by = Factory::getUser()->id; $user = Factory::getUser(); $canEdit = $user->authorise('core.edit', 'com_sppagebuilder') || ($user->authorise('core.edit.own', 'com_sppagebuilder') && $user->id === $this->getMediaOwnerById($id)); if (!$canEdit) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_RENAME"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $response = ['data' => Text::_("COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_RENAME_ERROR"), 'status' => false, 'code' => 500]; try { if ($mediaType === 'DB') { $db = Factory::getDbo(); $db->updateObject('#__spmedia', $data, 'id'); } \rename(JPATH_ROOT . '/' . $path, JPATH_ROOT . '/' . $data->path); \rename(JPATH_ROOT . '/' . $thumb, JPATH_ROOT . '/' . $data->thumb); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_RENAME_SUCCESS"), 'status' => true, 'code' => 200 ]; } catch (Exception $e) { $response = [ 'data' => $e->getMessage(), 'status' => false, 'code' => 500 ]; } $code = $response['code']; unset($response['code']); $app->setHeader('status', $code, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } private function replacePathByTitle($path, $title) { $fileName = pathinfo($path, PATHINFO_FILENAME); $basename = basename($path); $newFile = str_replace($fileName, $title, $basename); return str_replace($basename, $newFile, $path); } /** * Upload media file function * * @return string * * @since 4.0.0 */ public function upload_media() { $app = Factory::getApplication('site'); $user = Factory::getUser(); $canCreate = $user->authorise('core.create', 'com_sppagebuilder'); if (!$canCreate) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_UPLOAD"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $model = $this->getModel(); $user = Factory::getUser(); $input = Factory::getApplication()->input; if (isset($_FILES['file']) && $_FILES['file']) { $file = $_FILES['file']; $dir = $input->post->get('folder', '', 'PATH'); $report = array(); $authorised = $user->authorise('core.edit', 'com_sppagebuilder') || $user->authorise('core.edit.own', 'com_sppagebuilder'); if ($authorised !== true) { $report['status'] = false; $report['output'] = Text::_('JERROR_ALERTNOAUTHOR'); echo json_encode($report); die(); } if (count((array) $file)) { if ($file['error'] == UPLOAD_ERR_OK) { $error = false; $params = ComponentHelper::getParams('com_media'); $contentLength = (int) $_SERVER['CONTENT_LENGTH']; $mediaHelper = new MediaHelper; $postMaxSize = $mediaHelper->toBytes(ini_get('post_max_size')); $memoryLimit = $mediaHelper->toBytes(ini_get('memory_limit')); // Check for the total size of post back data. if (($postMaxSize > 0 && $contentLength > $postMaxSize) || ($memoryLimit != -1 && $contentLength > $memoryLimit)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_TOTAL_SIZE_EXCEEDS'); $error = true; echo json_encode($report); die; } $uploadMaxSize = $params->get('upload_maxsize', 0) * 1024 * 1024; $uploadMaxFileSize = $mediaHelper->toBytes(ini_get('upload_max_filesize')); if (($file['error'] == 1) || ($uploadMaxSize > 0 && $file['size'] > $uploadMaxSize) || ($uploadMaxFileSize > 0 && $file['size'] > $uploadMaxFileSize)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_MEDIA_LARGE'); $error = true; } // File formats $accepted_file_formats = array( 'image' => array('jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'), 'video' => array('mp4', 'mov', 'wmv', 'avi', 'mpg', 'ogv', '3gp', '3g2'), 'audio' => array('mp3', 'm4a', 'ogg', 'wav'), 'attachment' => array('pdf', 'doc', 'docx', 'key', 'ppt', 'pptx', 'pps', 'ppsx', 'odt', 'xls', 'xlsx', 'zip', 'json'), ); // Upload if no error found if (!$error) { $date = Factory::getDate(); $file_ext = strtolower(File::getExt($file['name'])); if (self::in_array($file_ext, $accepted_file_formats)) { $media_type = self::array_search($file_ext, $accepted_file_formats); if ($media_type == 'image') { $mediaParams = ComponentHelper::getParams('com_media'); $folder_root = $mediaParams->get('file_path', 'images') . '/'; } elseif ($media_type == 'video') { $folder_root = 'media/videos/'; } elseif ($media_type == 'audio') { $folder_root = 'media/audios/'; } elseif ($media_type == 'attachment') { $folder_root = 'media/attachments/'; } elseif ($media_type == 'fonts') { $folder_root = 'media/fonts/'; } $report['type'] = $media_type; $folder = $folder_root . HTMLHelper::_('date', $date, 'Y') . '/' . HTMLHelper::_('date', $date, 'm') . '/' . HTMLHelper::_('date', $date, 'd'); if ($dir != '') { $folder = ltrim($dir, '/'); } if (!Folder::exists(JPATH_ROOT . '/' . $folder)) { Folder::create(JPATH_ROOT . '/' . $folder, 0755); } if ($media_type == 'image') { if (!Folder::exists(JPATH_ROOT . '/' . $folder . '/_spmedia_thumbs')) { Folder::create(JPATH_ROOT . '/' . $folder . '/_spmedia_thumbs', 0755); } } $name = $file['name']; $path = $file['tmp_name']; // Do no override existing file $media_file = preg_replace('#\s+#', "-", File::makeSafe(basename(strtolower($name)))); $i = 0; do { $base_name = File::stripExt($media_file) . ($i ? "$i" : ""); $ext = File::getExt($media_file); $media_name = $base_name . '.' . $ext; $i++; $dest = JPATH_ROOT . '/' . $folder . '/' . $media_name; $src = $folder . '/' . $media_name; } while (file_exists($dest)); // End Do not override if (File::upload($path, $dest, false, true)) { $media_attr = []; $thumb = ''; if ($media_type == 'image') { list($imgWidth, $imgHeight) = getimagesize($dest); if (strtolower($ext) == 'svg') { $report['src'] = Uri::root(true) . '/' . $src; } else { $image = new SppagebuilderHelperImage($dest); $media_attr['full'] = ['height' => $image->height, 'width' => $image->width]; if (($image->width > 300) || ($image->height > 225)) { $thumbDestPath = dirname($dest) . '/_spmedia_thumbs'; $created = $image->createThumb(array('300', '300'), $thumbDestPath, $base_name, $ext); if ($created == false) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FILE_NOT_SUPPORTED'); $error = true; echo json_encode($report); die; } $report['src'] = Uri::root(true) . '/' . $folder . '/_spmedia_thumbs/' . $base_name . '.' . $ext; $thumb = $folder . '/_spmedia_thumbs/' . $base_name . '.' . $ext; $humbdest = $thumbDestPath . '/' . $base_name . '.' . $ext; list($width, $height) = getimagesize($humbdest); $media_attr['thumbnail'] = ['height' => $height, 'width' => $width]; $report['thumb'] = $thumb; } else { $report['src'] = Uri::root(true) . '/' . $src; $report['thumb'] = $src; } // Create placeholder for lazy load $this->create_media_placeholder($dest, $base_name, $ext); } } $insertid = $model->insertMedia($base_name, $src, json_encode($media_attr), $thumb, $media_type); $report['media_attr'] = $media_attr; $report['status'] = true; $report['title'] = $base_name; $report['id'] = $insertid; $report['path'] = $src; $layout_path = JPATH_ROOT . '/administrator/components/com_sppagebuilder/layouts'; $format_layout = new FileLayout('media.format', $layout_path); $report['output'] = $format_layout->render(array('media' => $model->getMediaByID($insertid), 'innerHTML' => true)); } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); } } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FILE_NOT_SUPPORTED'); } } } } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); } } else { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); } echo json_encode($report); die(); } /** * @since 2020 * Create light weight image placeholder for lazy load feature */ private function create_media_placeholder($dest, $base_name, $ext) { $placeholder_folder_path = JPATH_ROOT . '/media/com_sppagebuilder/placeholder'; if (!Folder::exists($placeholder_folder_path)) { Folder::create($placeholder_folder_path, 0755); } $image = new SppagebuilderHelperImage($dest); list($srcWidth, $srcHeight) = $image->getDimension(); $width = 60; $height = $width / ($srcWidth / $srcHeight); $image->createThumb(array('60', $height), $placeholder_folder_path, $base_name, $ext, 20); } /** * @since 2020 * Delete placeholder image if exists */ private function delete_image_placeholder($file_path) { $filename = basename($file_path); $src = JPATH_ROOT . '/media/com_sppagebuilder/placeholder' . '/' . $filename; if (File::exists($src)) { File::delete($src); } } public function delete_media() { $app = Factory::getApplication('site'); $user = Factory::getUser(); $canDelete = $user->authorise('core.delete', 'com_sppagebuilder'); if (!$canDelete) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_DELETION"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $input = $app->input; $user = Factory::getUser(); $model = $this->getModel(); $data = $input->json->get('data', [], 'ARRAY'); $response = ['status' => false, 'data' => 'Something went wrong!']; if (empty($data)) { $app->setHeader('status', 500, false); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } foreach ($data as $item) { if (!$this->removeMediaItem($item, $model, $user)) { continue; } $response['data'] = 'Media item deleted!'; } $response['status'] = true; $app->setHeader('status', 200, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } /** * Remove a media item. * * @param stdClass $item The media item object. * @param object $model The media model. * @param object $user The user class object. * * @return bool * @since 4.0.0 */ private function removeMediaItem($item, $model, $user): bool { $mediaType = $item['type']; if ($mediaType === 'folder') { $path = Path::clean($item['path']); $folder = JPATH_ROOT . $path; try { $folder = BuilderMediaHelper::checkForMediaActionBoundary($folder); } catch (\Exception $e) { return false; } if (!SecurityHelper::isActionableFolder($folder)) { return false; } if (Folder::exists($folder)) { Folder::delete($folder); return true; } return false; } elseif ($mediaType === 'local') { $src = JPATH_ROOT . '/' . $item['path']; $src = Path::clean($src); try { BuilderMediaHelper::checkForMediaActionBoundary($src); } catch (\Exception $e) { return false; } if (\file_exists($src)) { $media = $model->getMediaByPath($item['path']); if (isset($media->thumb) && $media->thumb) { if (File::exists(JPATH_ROOT . '/' . $media->thumb)) { File::delete(JPATH_ROOT . '/' . $media->thumb); // Delete thumb } } // Delete placeholder too $this->delete_image_placeholder($item['path']); // Remove Path. $removeMediaByPath = $model->removeMediaByPath($item['path']); if (!File::delete($src) || !$removeMediaByPath) { return false; } return true; } return false; } elseif ($mediaType === 'local+db') { $media = $model->getMediaByID($item['id']); $src = $media->path ?? ''; $src = JPATH_ROOT . '/' . $src; $src = Path::clean($src); $authorised = $user->authorise('core.edit', 'com_sppagebuilder') || ($user->authorise('core.edit.own', 'com_sppagebuilder') && ($media->created_by === $user->id)); if (!$authorised) { return false; } try { BuilderMediaHelper::checkForMediaActionBoundary(dirname($src)); } catch (\Exception $e) { return false; } if (!$model->removeMediaByID($item['id'])) { return false; } if (!empty($media->thumb)) { $thumbSrc = $media->thumb ?? ''; $thumbSrc = JPATH_ROOT . '/' . $thumbSrc; $thumbSrc = Path::clean($thumbSrc); try { BuilderMediaHelper::checkForMediaActionBoundary(dirname($thumbSrc)); } catch (\Exception $e) { return false; } if (\file_exists($thumbSrc)) { \unlink($thumbSrc); } } // Delete placeholder too $this->delete_image_placeholder($item['path']); if (\file_exists($src)) { \unlink($src); return true; } return false; } return false; } // Delete File public function deleteMediaItem() { $model = $this->getModel(); $user = Factory::getUser(); $input = Factory::getApplication()->input; $m_type = $input->post->get('m_type', NULL, 'STRING'); if ($m_type == 'path') { $report = array(); $report['status'] = true; $path = htmlspecialchars($input->post->get('path', NULL, 'STRING')); $src = JPATH_ROOT . '/' . $path; if (File::exists($src)) { if (!File::delete($src)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_DELETE_FAILED'); echo json_encode($report); die; } } else { $report['status'] = true; } echo json_encode($report); } else { $id = $input->post->get('id', NULL, 'INT'); if (!is_numeric($id)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_DELETE_FAILED'); echo json_encode($report); die; } $media = $model->getMediaByID($id); $authorised = $user->authorise('core.edit', 'com_sppagebuilder') || ($user->authorise('core.edit.own', 'com_sppagebuilder') && ($media->created_by == $user->id)); if ($authorised !== true) { $report['status'] = false; $report['output'] = Text::_('JERROR_ALERTNOAUTHOR'); echo json_encode($report); die(); } $src = JPATH_ROOT . '/' . $media->path; $report = array(); $report['status'] = false; if (isset($media->thumb) && $media->thumb) { if (File::exists(JPATH_ROOT . '/' . $media->thumb)) { File::delete(JPATH_ROOT . '/' . $media->thumb); // Delete thumb } } if (File::exists($src)) { // Delete placeholder too $this->delete_image_placeholder($src); if (!File::delete($src)) { $report['status'] = false; $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_DELETE_FAILED'); echo json_encode($report); die; } } else { $report['status'] = true; } // Remove from database $media = $model->removeMediaByID($id); $report['status'] = true; echo json_encode($report); } die; } private static function in_array($needle, $haystack) { $it = new RecursiveIteratorIterator(new RecursiveArrayIterator($haystack)); foreach ($it as $element) { if ($element == $needle) { return true; } } return false; } private static function array_search($needle, $haystack) { foreach ($haystack as $key => $value) { $current_key = $key; if ($needle === $value or (is_array($value) && self::array_search($needle, $value) !== false)) { return $current_key; } } return false; } // Create folder public function create_folder() { $app = Factory::getApplication('site'); $user = Factory::getUser(); $canCreate = $user->authorise('core.create', 'com_sppagebuilder'); if (!$canCreate) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_CREATION"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $input = Factory::getApplication()->input; $folder = $input->post->get('folder', '', 'STRING'); $dirname = dirname($folder); $basename = OutputFilter::stringURLSafe(basename($folder)); $folder = $dirname . '/' . $basename; $report = array(); $report['status'] = false; $fullName = JPATH_ROOT . $folder; try { $fullName = BuilderMediaHelper::checkForMediaActionBoundary($fullName); } catch (\Exception $e) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'message' => $e->getMessage(), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } if (!SecurityHelper::isActionableFolder($folder)) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'message' => Text::_('COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_CREATION'), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $folderToCreate = Path::clean(JPATH_ROOT . $folder); if (!Folder::exists($folderToCreate)) { if (Folder::create($folderToCreate, 0755)) { $report['status'] = true; $folder_info['name'] = basename($folder); $folder_info['relname'] = $folder; $folder_info['fullname'] = $fullName; $report['output'] = $folder_info; } else { $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FOLDER_CREATION_FAILED'); } } else { $report['output'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FOLDER_EXISTS'); } echo json_encode($report); die; } public function delete_folder() { $app = Factory::getApplication('site'); $user = Factory::getUser(); $canDelete = $user->authorise('core.delete', 'com_sppagebuilder'); if (!$canDelete) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_DELETION"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $input = Factory::getApplication()->input; $folder = $input->post->get('folder', '', 'STRING'); $deleteItem = $input->post->get('deleteItem', '', 'STRING'); $model = $this->getModel(); $dirname = dirname($folder); $basename = OutputFilter::stringURLSafe(basename($folder)); $folder = $dirname . '/' . $basename; $cleanedFullPath = Path::clean(JPATH_ROOT . $folder); $report = array(); $report['status'] = false; if (!SecurityHelper::isActionableFolder($folder)) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'message' => Text::_('COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_FOLDER_DELETION'), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } if (!Folder::exists($cleanedFullPath)) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'message' => Text::_("COM_SPPAGEBUILDER_MEDIA_MANAGER_FOLDER_EXISTS"), 'status' => false, 'code' => 500 ]; echo new JsonResponse($response); $app->close(); } if ($deleteItem === 'multiple') { $mediaDelete = $model->removeMediaByPath(substr($folder, 1) . '/'); } else { $mediaDelete = true; } if ($mediaDelete === true) { if (Folder::delete($cleanedFullPath)) { $report['status'] = true; $folder_info['name'] = basename($folder); $folder_info['relname'] = $folder; $report['output'] = $folder_info; } else { $report['output'] = Text::_("COM_SPPAGEBUILDER_MEDIA_FOLDER_DELETE_FAILED"); } } else { $report['output'] = Text::_("COM_SPPAGEBUILDER_MEDIA_FILES_DELETE_FAILED"); } echo json_encode($report); die; } public function rename_folder() { $app = Factory::getApplication('site'); $user = Factory::getUser(); $canEdit = $user->authorise('core.edit', 'com_sppagebuilder'); if (!$canEdit) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_MEDIA_RENAME"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } $input = Factory::getApplication()->input; $model = $this->getModel(); $currentfolder = $input->post->get('currentfolder', '', 'STRING'); $newfolder = $input->post->get('newfolder', '', 'STRING'); $renameItem = $input->post->get('renameItem', '', 'STRING'); $dirname = dirname($currentfolder); $currentbasename = OutputFilter::stringURLSafe(basename($currentfolder)); $newbasename = OutputFilter::stringURLSafe(basename($newfolder)); $src = $dirname . '/' . $currentbasename; $cleanedSrc = Path::clean(JPATH_ROOT . $src); $dest = $dirname . '/' . $newbasename; $cleanedDest = Path::clean(JPATH_ROOT . $dest); if (!SecurityHelper::isActionableFolder($currentfolder) || !SecurityHelper::isActionableFolder($newfolder)) { $app->setHeader('status', 403, true); $app->sendHeaders(); $response = [ 'data' => Text::_("COM_SPPAGEBUILDER_GLOBAL_UNAUTHORIZED_FOLDER_RENAME"), 'status' => false, 'code' => 403 ]; echo new JsonResponse($response); $app->close(); } if (Folder::exists(Path::clean(JPATH_ROOT . $currentfolder))) { if ($renameItem === 'multiple') { $mediaRename = $model->editMediaPathById(substr($src, 1) . '/', substr($dest, 1) . '/'); } else { $mediaRename = true; } if ($mediaRename === true) { if (Folder::move($cleanedSrc, $cleanedDest, $path = '', $use_streams = false)) { $report['status'] = true; $folder_info['name'] = basename($dest); $folder_info['relname'] = $dest; $folder_info['fullname'] = JPATH_ROOT . $dest; $report['output'] = $folder_info; } else { $report['output'] = Text::_("COM_SPPAGEBUILDER_MEDIA_FOLDER_RENAME_FAILED"); } } else { $report['output'] = $mediaRename; //'MEDIA FILES COULD NOT BE RENAMED'; } } else { $report['output'] = Text::_("COM_SPPAGEBUILDER_MEDIA_FOLDER_NOT_FOUND"); } echo json_encode($report); die; } } PK ��\���'N N font.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ // No direct access defined('_JEXEC') or die('Restricted access'); use Joomla\CMS\Factory; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Response\JsonResponse; /** * Fonts Controller class * * @since 5.0.0 */ class SppagebuilderControllerFont extends FormController { /** * Get installed fonts. * * @return array The fonts array. * @since 5.0.0 */ public function getInstalledFonts() { $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('*') ->from($db->quoteName('#__sppagebuilder_fonts')) ->where($db->quoteName('published') . ' = 1'); $db->setQuery($query); try { $response = $db->loadObjectList(); if (isset($response)) { foreach ($response as $key => $value) { if (isset($value->data)) { $value->data = json_decode($value->data); } } } } catch (\Exception $e) { $response = []; } $this->sendResponse($response); } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 5.0.0 */ private function sendResponse($response, int $statusCode = 200): void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } } PK ��\�Sʉ� � .htaccessnu �7��m <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>PK ��\���bJ bJ ai_content.phpnu �[��� <?php /** * @package SP Page Builder * @author JoomShaper http://www.joomshaper.com * @copyright Copyright (c) 2010 - 2023 JoomShaper * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later */ use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Response\JsonResponse; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\MVC\Controller\FormController; use Joomla\CMS\Uri\Uri; use Joomla\CMS\Filesystem\Path; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Filesystem\Folder; use Joomla\CMS\Layout\FileLayout; //no direct access defined('_JEXEC') or die('Restricted access'); JLoader::register('SppagebuilderHelperImage', JPATH_ROOT . '/components/com_sppagebuilder/helpers/image.php'); class SppagebuilderControllerAi_content extends FormController { public function getModel($name = 'Media', $prefix = '', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, $config); } public function __construct($config = []) { parent::__construct($config); // check have access $user = Factory::getUser(); $authorised = $user->authorise('core.admin', 'com_sppagebuilder') || $user->authorise('core.manage', 'com_sppagebuilder'); if (!$authorised) { $response = [ 'status' => false, 'message' => Text::_('JERROR_ALERTNOAUTHOR') ]; echo json_encode($response); die(); } } /** * Get Url To Base64 Image * * @return void * @version 5.0.8 */ public function getUrlToBase64Image() { $input = Factory::getApplication()->input; $imageUrl = $input->json->get('image_uri', '', 'STRING'); if (!isset($imageUrl) || empty($imageUrl)) { $this->sendResponse([ 'status' => false, 'message' => 'Image URL is missing.' ], 400); } $base64Image = $this->imageUrlToBase64($imageUrl); $this->sendResponse([ 'status' => true, 'dataUrl' => $base64Image ], 200); } /** * Get AI generated Content * * @return void * @version 5.0.8 */ public function getAiGeneratedContent() { $cParams = ComponentHelper::getParams('com_sppagebuilder'); $input = Factory::getApplication()->input; $prompt = $input->json->get('prompt', '', 'STRING'); $type = $input->json->get('type', 'text', 'STRING'); $imageUri = $input->json->get('image_uri', '', 'STRING'); $numberOfImages = $input->json->get('number_of_images', 4, 'NUMBER'); $imageSize = $input->json->get('image_size', '512x512', 'STRING'); $maxTokens = (int) $input->json->get('max_tokens', '250', 'STRING'); // Set your OpenAI API key here $apiKey = $cParams->get('openai_api_key', ''); $model = "gpt-3.5-turbo"; if (!isset($apiKey) || empty($apiKey)) { $this->sendResponse([ 'status' => false, 'message' => Text::_('COM_SPPAGEBUILDER_AI_API_KEY_MISSING_MESSAGE') ], 400); } $endpoint = 'https://api.openai.com/v1/chat/completions'; // Request data $data = [ "model" => $model, 'max_tokens' => $maxTokens, "messages" => [ [ "role" => "user", "content" => $prompt ], ] ]; if ($type === 'image') { $endpoint = 'https://api.openai.com/v1/images/generations'; $data = [ 'prompt' => $prompt, 'size' => $imageSize, 'n' => (int) $numberOfImages, 'user' => 'username' ]; } // Create JSON payload $payload = json_encode($data); if ($type === 'variation') { if (empty($imageUri)) { $this->sendResponse([ 'status' => false, 'message' => 'Image url is Required.' ], 400); } $endpoint = 'https://api.openai.com/v1/images/variations'; if (str_starts_with($imageUri, 'http')) { $base64Image = $this->imageUrlToBase64($imageUri); $finalImageFile = $this->dataUrlToCurlFile($base64Image); } else { $finalImageFile = $this->processImageForOpenAi($imageUri); } $data = [ 'image' => $finalImageFile, 'size' => $imageSize, 'n' => (int) $numberOfImages, 'user' => 'username' ]; $payload = $data; } if ($type === 'generative_fill') { if (empty($imageUri) || empty($prompt)) { $this->sendResponse([ 'status' => false, 'message' => 'Image or Prompt is missing.' ], 400); } $endpoint = 'https://api.openai.com/v1/images/edits'; $finalMaskImage = $this->dataUrlToCurlFile($imageUri); $data = [ 'prompt' => $prompt, 'image' => $finalMaskImage, 'size' => '512x512', 'n' => 4, 'user' => 'username' ]; $payload = $data; } // Initialize cURL session $ch = curl_init(); $httpHeader = [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey ]; // Set cURL options curl_setopt($ch, CURLOPT_URL, $endpoint); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $type === 'text' || $type === 'image' ? $httpHeader : ['Authorization: Bearer ' . $apiKey]); // Execute cURL session and get the response $response = curl_exec($ch); $error = null; if ($response === false) { $error = curl_error($ch); } // Close cURL session curl_close($ch); if ($error !== null) { $this->sendResponse([ 'status' => false, 'message' => $error ], 500); } // Decode and print the response $responseArray = json_decode($response, true); if (($type !== 'text') && $responseArray && isset($responseArray['data'])) { $this->sendResponse($responseArray); } if ($type === 'text' && $responseArray && isset($responseArray['choices'][0]['message']['content'])) { $this->sendResponse($responseArray); } if ($responseArray && isset($responseArray['error']) && isset($responseArray['error']['message'])) { $message = $responseArray['error']['message']; if(strpos($message, 'maximum context length')) { $message = Text::_('COM_SPPAGEBUILDER_AI_MAXIMUM_CHARACTER_LIMIT_EXCEEDED_MESSAGE'); } $this->sendResponse([ 'status' => false, 'message' => $message, ], 400); } $this->sendResponse([ 'status' => false, 'message' => Text::_("COM_SPPAGEBUILDER_GLOBAL_SOMETHING_WENT_WRONG") ], 500); } private function processImageForOpenAi($image_uri) { $imagePath = Path::clean(JPATH_ROOT . '/' . $image_uri); // Create a temporary directory $formattedTempSquareImagePath = tempnam(sys_get_temp_dir(), time()); // $tempFile = fopen($formattedTempSquareImagePath, 'wb'); $imageMimeType = mime_content_type($imagePath); if ($imageMimeType !== 'image/png') { $isConvertSuccess = BuilderMediaHelper::changeAspectRatio('1:1', $imagePath, $formattedTempSquareImagePath, 'png'); if (!$isConvertSuccess) { $this->sendResponse([ 'status' => false, 'message' => 'Image conversion failed. Please try again.' ], 500); } $finalImageFile = $this->makeCurlFile($formattedTempSquareImagePath); } else { $finalImageFile = $this->makeCurlFile($imagePath); } return $finalImageFile; } private function makeCurlFile($file) { $mime = mime_content_type($file); $info = pathinfo($file); $name = $info['basename']; $output = new CURLFile($file, $mime, $name); return $output; } private function imageUrlToBase64($imageUrl) { // Fetch the image from the URL $imageData = @file_get_contents($imageUrl); if ($imageData === false) { $this->sendResponse([ 'status' => false, 'message' => 'Unable to fetch the image. Please try again.' ], 500); // Unable to fetch the image } // Encode the image data as Base64 $base64Data = base64_encode($imageData); if ($base64Data === false) { $this->sendResponse([ 'status' => false, 'message' => 'Failed to encode as Base64. Please try again.' ], 500); // Failed to encode as Base64 } // Create a data URL with the Base64-encoded image data $dataUrl = 'data:image/png;base64,' . $base64Data; return $dataUrl; } private function dataUrlToCurlFile($dataUrlImage) { $mimeRegex = '/^data:([^;]+);base64,([a-zA-Z0-9\/+]+=*)$/'; if (!preg_match($mimeRegex, $dataUrlImage, $matches)) { $this->sendResponse(['message' => "Invalid data URL format."], 400); } $base64Data = $matches[2]; $decodedData = base64_decode($base64Data); // Create a temporary file $tempFileName = tempnam(sys_get_temp_dir(), 'maskimage'); $tempFile = fopen($tempFileName, 'wb'); fwrite($tempFile, $decodedData); fclose($tempFile); $tempSquareImageDest = tempnam(sys_get_temp_dir(), 'square'); $isConvertSuccess = BuilderMediaHelper::changeAspectRatio('1:1', $tempFileName, $tempSquareImageDest, 'png'); if (!$isConvertSuccess) { $this->sendResponse([ 'status' => false, 'message' => 'Image conversion failed. Please try again.' ], 500); } $finalImageFile = $this->makeCurlFile($tempSquareImageDest); return $finalImageFile; } /** * Send JSON Response to the client. * * @param array $response The response array or data. * @param int $statusCode The status code of the HTTP response. * * @return void * @since 5.0.0 */ public function sendResponse($response, int $statusCode = 200): void { $app = Factory::getApplication(); $app->setHeader('status', $statusCode, true); $app->sendHeaders(); echo new JsonResponse($response); $app->close(); } /** * Upload image from url * * @return void * @version 5.0.8 */ public function uploadAiGeneratedImageFromUrl() { $model = $this->getModel('Media'); $user = Factory::getUser(); $input = Factory::getApplication()->input; $imageUrl = $input->json->get('url', '', 'STRING'); $aspectRatio = $input->json->get('aspect_ratio', '', 'STRING'); $report = []; $canCreate = $user->authorise('core.create', 'com_sppagebuilder'); if (!$canCreate) { $report['status'] = false; $report['message'] = Text::_('JERROR_ALERTNOAUTHOR'); $this->sendResponse($report, 403); } // Validate the URL if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) { $report['status'] = false; $report['message'] = Text::_('Invalid url'); $this->sendResponse($report, 400); } // Generate a unique filename $extension = 'webp'; $base_name = uniqid('ai_img_', true); $filename = $base_name . '.' . $extension; // Save the image to the server $mediaParams = ComponentHelper::getParams('com_media'); $folder_root = $mediaParams->get('file_path', 'images') . '/'; $date = Factory::getDate(); $folder = $folder_root . HTMLHelper::_('date', $date, 'Y') . '/' . HTMLHelper::_('date', $date, 'm') . '/' . HTMLHelper::_('date', $date, 'd'); if (!Folder::exists(JPATH_ROOT . '/' . $folder)) { Folder::create(JPATH_ROOT . '/' . $folder, 0755); } if (!Folder::exists(JPATH_ROOT . '/' . $folder . '/_spmedia_thumbs')) { Folder::create(JPATH_ROOT . '/' . $folder . '/_spmedia_thumbs', 0755); } $src = Path::clean($folder . '/' . $filename); $dest = Path::clean(JPATH_ROOT . '/' . $src); $isImageSaved = !empty($aspectRatio) ? $this->changeAspectRatio($aspectRatio, $imageUrl, $dest) : $this->convertImageToWebp($imageUrl, $dest); if (!$isImageSaved) { $report['status'] = false; $report['message'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_UPLOAD_FAILED'); $this->sendResponse($report, 400); } $media_attr = []; $thumb = ''; $image = new SppagebuilderHelperImage($dest); $media_attr['full'] = ['height' => $image->height, 'width' => $image->width]; if (($image->width > 300) || ($image->height > 225)) { $thumbDestPath = dirname($dest) . '/_spmedia_thumbs'; $created = $image->createThumb(array('300', '300'), $thumbDestPath, $base_name, $extension); if ($created == false) { $report['status'] = false; $report['message'] = Text::_('COM_SPPAGEBUILDER_MEDIA_MANAGER_FILE_NOT_SUPPORTED'); } $report['src'] = Uri::root(true) . '/' . $folder . '/_spmedia_thumbs/' . $base_name . '.' . $extension; $thumb = $folder . '/_spmedia_thumbs/' . $base_name . '.' . $extension; $thumb_dest = Path::clean($thumbDestPath . '/' . $base_name . '.' . $extension); list($width, $height) = getimagesize($thumb_dest); $media_attr['thumbnail'] = ['height' => $height, 'width' => $width]; $report['thumb'] = $thumb; } else { $report['src'] = Uri::root(true) . '/' . $src; $report['thumb'] = $src; } // Create placeholder for lazy load $this->createAiGeneratedMediaPlaceholder($dest, $base_name, $extension); $insert_id = $model->insertMedia($base_name, $src, json_encode($media_attr), $thumb, 'image'); $report['media_attr'] = $media_attr; $report['status'] = true; $report['title'] = $base_name; $report['id'] = $insert_id; $report['path'] = $src; $layout_path = JPATH_ROOT . '/administrator/components/com_sppagebuilder/layouts'; $format_layout = new FileLayout('media.format', $layout_path); $report['message'] = $format_layout->render(array('media' => $model->getMediaByID($insert_id), 'innerHTML' => true)); $this->sendResponse($report, 200); } /** * @since 2020 * Create light weight image placeholder for lazy load feature */ private function createAiGeneratedMediaPlaceholder($dest, $base_name, $ext) { $placeholder_folder_path = JPATH_ROOT . '/media/com_sppagebuilder/placeholder'; if (!Folder::exists($placeholder_folder_path)) { Folder::create($placeholder_folder_path, 0755); } $image = new SppagebuilderHelperImage($dest); list($srcWidth, $srcHeight) = $image->getDimension(); $width = 60; $height = $width / ($srcWidth / $srcHeight); $image->createThumb(array('60', $height), $placeholder_folder_path, $base_name, $ext, 20); } private function getImageSource($image_path) { $image_properties = @getimagesize($image_path); $image_type = $image_properties[2]; $imageSource = false; switch ($image_type) { case 1: $imageSource = @imagecreatefromgif($image_path); break; case 2: $imageSource = @imagecreatefromjpeg($image_path); break; case 3: $imageSource = @imagecreatefrompng($image_path); break; } return $imageSource; } private function convertImageToWebp($image_path, $destination) { $image = $this->getImageSource($image_path); if(!$image) { return false; } // get dimensions of image $width = imagesx($image); $height = imagesy($image); // create a canvas $canvas = imagecreatetruecolor ($width, $height); imageAlphaBlending($canvas, false); imageSaveAlpha($canvas, true); // By default, the canvas is black, so make it transparent $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127); imagefilledrectangle($canvas, 0, 0, $width - 1, $height - 1, $transparent); // copy image to canvas imagecopy($canvas, $image, 0, 0, 0, 0, $width, $height); // save canvas as a webp $is_image_saved = imagewebp($canvas, $destination, 80); // 80 is the quality parameter (0-100) // clean up memory imagedestroy($canvas); return $is_image_saved; } private function changeAspectRatio($aspect_ratio, $image_path, $destination) { $sourceImage = $this->getImageSource($image_path); if(!$sourceImage) { return false; } // Calculate the new dimensions while maintaining the aspect ratio $sourceWidth = imagesx($sourceImage); $sourceHeight = imagesy($sourceImage); $parts = explode(':', $aspect_ratio); $aspectRatio = $parts[0] / $parts[1]; // Calculate the target width and height based on the aspect ratio if ($sourceWidth / $sourceHeight > $aspectRatio) { $newWidth = round($sourceHeight * $aspectRatio); $newHeight = $sourceHeight; } else { $newWidth = $sourceWidth; $newHeight = round($sourceWidth / $aspectRatio); } // Create a new image with the desired dimensions $newImage = @imagecreatetruecolor($newWidth, $newHeight); if(!$newImage) { return false; } // Resize the source image to fit the new dimensions $isSuccess = @imagecopyresampled($newImage, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $sourceWidth, $sourceHeight); if(!$isSuccess){ return false; } // save canvas as a webp $isSuccess = @imagewebp($newImage, $destination, 80); // 80 is the quality parameter (0-100) // Clean up resources imagedestroy($sourceImage); imagedestroy($newImage); return $isSuccess; } } PK ��\/N|OA A asset.php.neo_baknu �[��� PK ��\6�Ni�B �B ZA asset.phpnu �[��� PK ��\�ۖ�! ! e� saved_items_order.phpnu �[��� PK ��\lB� ˌ color.phpnu �[��� PK ��\�j/��a �a � page.phpnu �[��� PK ��\K�5Bf Bf )� media.phpnu �[��� PK ��\���'N N �[ font.phpnu �[��� PK ��\�Sʉ� � *c .htaccessnu �7��m PK ��\���bJ bJ Pd ai_content.phpnu �[��� PK � �
| ver. 1.4 |
Github
|
.
| PHP 8.2.32 | Generation time: 0.07 |
proxy
|
phpinfo
|
Settings