__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
/**
* @package SP Page Builder
* @author JoomShaper http://www.joomshaper.com
* @copyright Copyright (c) 2010 - 2025 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\Plugin\PluginHelper;
/**
* Trait for managing addons API endpoints.
*/
trait AddonsTrait
{
public function addons()
{
$method = $this->getInputMethod();
$this->checkNotAllowedMethods(['POST', 'DELETE'], $method);
switch ($method)
{
case 'GET':
$this->getAddonList();
break;
case 'PATCH':
$this->toggleAddonStatus();
break;
case 'PUT':
$this->changeFavoriteState();
break;
}
}
private function getAddonByName(string $name)
{
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('*')->from($db->quoteName('#__sppagebuilder_addonlist'))
->where($db->quoteName('name') . ' = ' . $db->quote($name));
$db->setQuery($query);
return $db->loadObject();
}
private function updateOrCreate($data)
{
$db = Factory::getDbo();
if (!empty($data->id))
{
$db->updateObject('#__sppagebuilder_addonlist', $data, 'id', true);
}
else
{
$db->insertObject('#__sppagebuilder_addonlist', $data, 'id');
$data->id = $db->insertid();
}
return $data;
}
public function toggleAddonStatus()
{
$addonName = $this->getInput('addon_name', '', 'STRING');
if (empty($addonName))
{
$this->sendResponse(['message' => 'Missing addon name'], 400);
}
$status = 0;
$addon = $this->getAddonByName($addonName);
$data = (object) [
'name' => $addonName,
'ordering' => 0
];
if (!empty($addon))
{
$status = $addon->status ? 0 : 1;
$data->id = $addon->id;
}
$data->status = $status;
$this->updateOrCreate($data);
$response = (object) [
'addon_name' => $addonName,
'status' => $status
];
$this->sendResponse($response);
}
public function getAddonList()
{
if (!class_exists('SpAddonsConfig'))
{
require_once JPATH_ROOT . '/components/com_sppagebuilder/builder/classes/base.php';
require_once JPATH_ROOT . '/components/com_sppagebuilder/builder/classes/config.php';
}
SpPgaeBuilderBase::loadAddons();
$addons = SpAddonsConfig::$addons;
$type = $this->getInput('type', null, 'STRING');
$flattenList = new stdClass;
$parsedAddons = [];
$globalSettings = SpPgaeBuilderBase::addonOptions();
$globalDefaults = [];
$globalSettingsGroups = ['style', 'advanced', 'interaction'];
foreach ($globalSettingsGroups as $groupName)
{
$globalDefaults = array_merge($globalDefaults, EditorUtils::extractSettingsDefaultValues($globalSettings[$groupName]));
}
$databaseAddons = $this->getAddonListFromDatabase();
$parsedAddons['Favourite'] = [];
foreach ($addons as $addon)
{
$hasContext = isset($addon['context']) && stripos($addon['context'], 'easystore') === 0;
// If we are not in the easystore pages, then skip the single & collection addons.
if ($hasContext && !in_array($type, ['single', 'storefront', 'collection']))
{
$contextArray = explode('.', $addon['context'], 2);
if (!empty($contextArray[1]) && in_array($contextArray[1], ['single', 'collection']))
{
continue;
}
}
// In the storefront page, we don't need the single & collection addons.
if ($hasContext && $type === 'storefront')
{
$contextArray = explode('.', $addon['context'], 2);
if (!empty($contextArray[1]) && in_array($contextArray[1], ['single', 'collection']))
{
continue;
}
}
// In the collection page, we don't need the single addons.
if ($hasContext && $type === 'collection')
{
$contextArray = explode('.', $addon['context'], 2);
if (!empty($contextArray[1]) && $contextArray[1] === 'single')
{
continue;
}
}
$category = $addon['category'] ?? 'General';
$addon['default'] = [];
if (!isset($parsedAddons[$category]))
{
$parsedAddons[$category] = [];
}
$addonName = preg_replace('/^sp_/i', '', $addon['addon_name']);
$className = ApplicationHelper::generateSiteClassName($addonName);
$flattenAddon = $addon;
$addonStructure = AddonsHelper::modernizeAddonStructure($flattenAddon);
$addonDefaults = EditorUtils::extractSettingsDefaultValues($addonStructure['settings']);
$addonStructure['default'] = array_merge($globalDefaults, $addonDefaults);
$addonStructure['desc'] = $addonStructure['desc'] ?? '';
PluginHelper::importPlugin('system');
Factory::getApplication()->triggerEvent('onBeforeAddonConfigure', [$addonName, &$addonStructure]);
$flattenList->$addonName = $addonStructure;
$addonObject = (object) [
'type' => $addonStructure['type'],
'name' => $addonName,
'title' => $addonStructure['title'],
'description' => $addonStructure['desc'],
'category' => $addonStructure['category'] ?? 'General',
'icon' => $addonStructure['icon'],
'default' => $addonStructure['default'],
'visibility' => true,
'js_template' => method_exists($className, 'getTemplate'),
'status' => $databaseAddons[$addonName]->status ?? 1,
'is_favorite' => $databaseAddons[$addonName]->is_favorite ?? 0,
'pro' => $addonStructure['pro'] ?? false
];
if ($addonObject->is_favorite)
{
if (!isset($parsedAddons['Favourite']))
{
$parsedAddons['Favourite'] = [];
}
$parsedAddons['Favourite'][] = $addonObject;
}
$parsedAddons[$category][] = $addonObject;
}
if (isset($parsedAddons['Dynamic Content']))
{
$structureGroup = $parsedAddons['Dynamic Content'];
unset($parsedAddons['Dynamic Content']);
$parsedAddons = array_merge(['Dynamic Content' => $structureGroup], $parsedAddons);
}
if (isset($parsedAddons['Structure']))
{
$structureGroup = $parsedAddons['Structure'];
unset($parsedAddons['Structure']);
$parsedAddons = array_merge(['Structure' => $structureGroup], $parsedAddons);
}
$favoriteGroup = $parsedAddons['Favourite'];
if (!empty($favoriteGroup))
{
$parsedAddons = array_merge(['Favourite' => $favoriteGroup], $parsedAddons);
}
foreach ($parsedAddons as $category => $_)
{
if (in_array($category, ['Structure', 'Dynamic Content']))
{
continue;
}
usort($parsedAddons[$category], function ($first, $second)
{
return strcmp(strtolower($first->title), strtolower($second->title));
});
}
$keyOrders = ['row', 'columns', 'div'];
if (isset($parsedAddons['Structure']))
{
usort($parsedAddons['Structure'], function ($first, $second) use ($keyOrders)
{
return array_search($first->name, $keyOrders) - array_search($second->name, $keyOrders);
});
}
$response = (object) [
'addons' => $flattenList,
'groups' => $parsedAddons,
'globals' => $globalSettings
];
$this->sendResponse($response);
}
private function getAddonListFromDatabase()
{
$db = Factory::getDbo();
$query = $db->getQuery(true);
$query->select('*')->from($db->quoteName('#__sppagebuilder_addonlist'));
$db->setQuery($query);
return $db->loadObjectList('name') ?? [];
}
private function changeFavoriteState()
{
$addonName = $this->getInput('addon_name', '', 'STRING');
$favoriteState = $this->getInput('state', null, 'INT');
if (empty($addonName))
{
$this->sendResponse(['message' => 'Missing addon name'], 400);
}
if (\is_null($favoriteState))
{
$this->sendResponse(['message' => 'Missing favorite state'], 400);
}
$addon = $this->getAddonByName($addonName);
$data = (object) [
'name' => $addonName,
'ordering' => 0,
'is_favorite' => $favoriteState,
'status' => 1
];
if (!empty($addon))
{
$data = $addon;
$data->is_favorite = $favoriteState;
}
$this->updateOrCreate($data);
$response = (object) [
'addon_name' => $addonName,
'state' => $favoriteState
];
$this->sendResponse($response);
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| AddToMenuTrait.php | File | 2.69 KB | 0664 |
|
| AddonsTrait.php | File | 7.77 KB | 0664 |
|
| AiContentTrait.php | File | 10 KB | 0664 |
|
| AiContentUploadTrait.php | File | 8.14 KB | 0664 |
|
| AllFontsTrait.php | File | 1.32 KB | 0664 |
|
| AppConfig.php | File | 5.33 KB | 0664 |
|
| ApplicationSettingsTrait.php | File | 16.47 KB | 0664 |
|
| BulkExportTrait.php | File | 16.66 KB | 0664 |
|
| BulkImportTrait.php | File | 18.55 KB | 0664 |
|
| CommonTrait.php | File | 4.56 KB | 0664 |
|
| ExportTrait.php | File | 11.07 KB | 0664 |
|
| FontsTrait.php | File | 12.45 KB | 0664 |
|
| GlobalColorsTrait.php | File | 3.37 KB | 0664 |
|
| IconProvidersTrait.php | File | 928 B | 0664 |
|
| IconsListTrait.php | File | 1.39 KB | 0664 |
|
| IconsTrait.php | File | 14.71 KB | 0664 |
|
| ImageShapesTrait.php | File | 5.56 KB | 0664 |
|
| ImportTrait.php | File | 16.82 KB | 0664 |
|
| IntegrationTrait.php | File | 4.64 KB | 0664 |
|
| LanguageTrait.php | File | 6.6 KB | 0664 |
|
| LayoutImportTrait.php | File | 2.89 KB | 0664 |
|
| Media.php | File | 17.78 KB | 0664 |
|
| MediaFolderTrait.php | File | 9.5 KB | 0664 |
|
| MenuByPageIdTrait.php | File | 952 B | 0664 |
|
| MenuListTrait.php | File | 791 B | 0664 |
|
| PageContentById.php | File | 1.22 KB | 0664 |
|
| PageDuplicateTrait.php | File | 1.35 KB | 0664 |
|
| PageOrderTrait.php | File | 1.16 KB | 0664 |
|
| PageTemplateTrait.php | File | 3.1 KB | 0664 |
|
| PageTrait.php | File | 9.74 KB | 0664 |
|
| ParentItemsTrait.php | File | 1.01 KB | 0664 |
|
| PluginsTrait.php | File | 2.93 KB | 0664 |
|
| PopupTemplateTrait.php | File | 2.34 KB | 0664 |
|
| ProductPageContentById.php | File | 2 KB | 0664 |
|
| PurgeCssTrait.php | File | 810 B | 0664 |
|
| SaveIgTokenTrait.php | File | 2.01 KB | 0664 |
|
| SavedAddonsOrderTrait.php | File | 1.19 KB | 0664 |
|
| SavedAddonsTrait.php | File | 4.06 KB | 0664 |
|
| SavedPresetsTrait.php | File | 3.17 KB | 0664 |
|
| SavedSectionsOrderTrait.php | File | 1.21 KB | 0664 |
|
| SavedSectionsTrait.php | File | 4.12 KB | 0664 |
|
| SectionLibraryTrait.php | File | 2.84 KB | 0664 |
|
| SettingsTrait.php | File | 1.07 KB | 0664 |
|
| UploadFontTrait.php | File | 5.48 KB | 0664 |
|