Skip to content

Commit

Permalink
Merge pull request #203 from PrestaSafe/fix-tinymce-api-key
Browse files Browse the repository at this point in the history
Fix api key for tinymce
  • Loading branch information
PrestaSafe authored Feb 2, 2024
2 parents baf862f + 9277aac commit d6fda1c
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 44 deletions.
3 changes: 3 additions & 0 deletions _dev/src/components/FieldRepeater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const removeTinyNotifications = () => {
})
}, 300)
}
let tinymce_api_key = ref(window.security_app.tinymce_api_key)
</script>

<template>
Expand All @@ -79,6 +81,7 @@ const removeTinyNotifications = () => {
<div class="pb-4"> {{ f.label }} </div>
<Editor
v-model="f.value"
:api-key="tinymce_api_key"
@init="removeTinyNotifications()"
:init="{
height: 500,
Expand Down
6 changes: 3 additions & 3 deletions classes/PrettyBlockCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ protected function filterVars()
* Filter file and replace vars
*
* @param $files
* $files = [
* '$/modules/your_module/views/css/vars.scss'
* ];
* $files = [
* '$/modules/your_module/views/css/vars.scss'
* ];
*
* @return string
*/
Expand Down
46 changes: 23 additions & 23 deletions classes/PrettyBlocksMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function addTemplateField()
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'prettyblocks` ADD `template` longtext DEFAULT NULL AFTER `config`;';
$sql[] = 'ALTER TABLE `' . _DB_PREFIX_ . 'prettyblocks` ADD `default_params` longtext DEFAULT NULL AFTER `config`;';
foreach ($sql as $query) {
$res &= \Db::getInstance()->execute($query);
$res &= Db::getInstance()->execute($query);
}

return $res;
Expand All @@ -29,12 +29,12 @@ public static function migrateConfig()
&& !self::columnExists('prettyblocks', 'default_params')) {
self::addTemplateField();
}
$langs = \Language::getLanguages();
$langs = Language::getLanguages();
$res = true;
$fields = [];
foreach ($langs as $lang) {
$lang_id = $lang['id_lang'];
$blocks = (new \PrestaShopCollection('PrettyBlocksModel', $lang_id))->getAll();
$blocks = (new PrestaShopCollection('PrettyBlocksModel', $lang_id))->getAll();
// get old config
foreach ($blocks as $model) {
$block = $model->mergeStateWithFields();
Expand Down Expand Up @@ -108,10 +108,10 @@ public static function migrateLangTable()
ADD COLUMN id_lang int(11) DEFAULT NULL,
ADD COLUMN state longtext DEFAULT NULL;
';
\Db::getInstance()->execute($sql);
Db::getInstance()->execute($sql);
}

$blocks_lang = \Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'prettyblocks_lang');
$blocks_lang = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'prettyblocks_lang');
foreach ($blocks_lang as $block) {
$existingBlock = new PrettyBlocksModel($block['id_prettyblocks']);
$newBlocks = new PrettyBlocksModel();
Expand All @@ -133,7 +133,7 @@ public static function migrateLangTable()
}

$sql = 'DROP TABLE IF EXISTS ' . _DB_PREFIX_ . 'prettyblocks_lang';
\Db::getInstance()->execute($sql);
Db::getInstance()->execute($sql);

return true;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public static function migrateSettings()

// get settings fields:

$settings_on_hooks = \HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settings_on_hooks = HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$res = [];

foreach ($settings_on_hooks as $key => $field) {
Expand Down Expand Up @@ -320,14 +320,14 @@ private static function _formatSettingsField($name, $type, $params, $context, $b
private static function _getDefaultParams($block)
{
$id_prettyblocks = (int) $block['id_prettyblocks'];
$key = \Tools::strtoupper($id_prettyblocks . '_default_params');
$key = Tools::strtoupper($id_prettyblocks . '_default_params');
// welcome = prettyblocks:views/templates/blocks/welcome.tpl
$options = [
'container' => true,
'load_ajax' => false,
'bg_color' => '',
];
$defaultParams = \Configuration::get($key);
$defaultParams = Configuration::get($key);
if (!$defaultParams) {
return $options;
}
Expand All @@ -345,10 +345,10 @@ private static function _getDefaultParams($block)
private static function _getTemplateSelected($block)
{
$id_prettyblocks = (int) $block['id_prettyblocks'];
$key = \Tools::strtoupper($id_prettyblocks . '_template');
$key = Tools::strtoupper($id_prettyblocks . '_template');
// welcome = prettyblocks:views/templates/blocks/welcome.tpl
$default_tpl = (isset($block['templates']['default'])) ? 'default' : 'welcome';
$currentTemplate = \Configuration::get($key, null, null, (int) $block['id_shop']);
$currentTemplate = Configuration::get($key, null, null, (int) $block['id_shop']);
if ($currentTemplate !== false && isset($block['templates'][$currentTemplate])) {
return $currentTemplate;
}
Expand All @@ -358,41 +358,41 @@ private static function _getTemplateSelected($block)

private static function _formatFieldConfigFront($field, $value, $block, $context = 'front')
{
\FieldFormatter::setSuffix('_config');
FieldFormatter::setSuffix('_config');

switch ($value['type']) {
case 'editor':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'text':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'textarea':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'color':
return \FieldFormatter::formatFieldText($field, $value, $block, $context);
return FieldFormatter::formatFieldText($field, $value, $block, $context);
break;
case 'radio':
return \FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
return FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
break;
case 'checkbox':
return \FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
return FieldFormatter::formatFieldBoxes($field, $value, $block, $context);
break;
case 'fileupload':
return \FieldFormatter::formatFieldUpload($field, $value, $block, $context);
return FieldFormatter::formatFieldUpload($field, $value, $block, $context);
break;
case 'upload':
return \FieldFormatter::formatFieldUpload($field, $value, $block, $context);
return FieldFormatter::formatFieldUpload($field, $value, $block, $context);
break;
case 'selector':
return \FieldFormatter::formatFieldSelector($field, $value, $block, $context);
return FieldFormatter::formatFieldSelector($field, $value, $block, $context);
break;
case 'select':
return \FieldFormatter::formatFieldSelect($field, $value, $block, $context);
return FieldFormatter::formatFieldSelect($field, $value, $block, $context);
break;
case 'radio_group':
return \FieldFormatter::formatFieldRadioGroup($field, $value, $block, $context);
return FieldFormatter::formatFieldRadioGroup($field, $value, $block, $context);
break;
default:
return '';
Expand Down
12 changes: 6 additions & 6 deletions classes/PrettyBlocksModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function setDefaultParams($params)
public function getDefaultParams()
{
$data = json_encode([], true);
if (\Validate::isJson($this->default_params)) {
if (Validate::isJson($this->default_params)) {
$data = $this->default_params;
}

Expand Down Expand Up @@ -508,13 +508,13 @@ public static function getShopById($id)
*/
public static function updateThemeSettings($stateRequest)
{
$context = \Context::getContext();
$context = Context::getContext();

$id_shop = (isset($stateRequest['context']['id_shop'])) ? (int) $stateRequest['context']['id_shop'] : $context->shop->id;
$id_lang = (isset($stateRequest['context']['id_lang'])) ? (int) $stateRequest['context']['id_shop'] : $context->language->id;
$shop = self::getShopById($id_shop);

$profile = \PrettyBlocksSettingsModel::getProfileByTheme($shop['theme_name'], $id_shop);
$profile = PrettyBlocksSettingsModel::getProfileByTheme($shop['theme_name'], $id_shop);

$res = [];
foreach ($stateRequest as $tabs) {
Expand Down Expand Up @@ -921,10 +921,10 @@ public function add($auto_date = true, $null_values = false)
*/
public static function getThemeSettings($with_tabs = true, $context = 'front', $id_shop = null)
{
$context = \Context::getContext();
$context = Context::getContext();
$id_shop = ($id_shop !== null) ? (int) $id_shop : $context->shop->id;
$theme_settings = \HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settingsDB = \PrettyBlocksSettingsModel::getSettings($context->shop->theme_name, $id_shop);
$theme_settings = HelperBuilder::hookToArray('ActionRegisterThemeSettings');
$settingsDB = PrettyBlocksSettingsModel::getSettings($context->shop->theme_name, $id_shop);
$res = [];
$no_tabs = [];
foreach ($theme_settings as $key => $settings) {
Expand Down
8 changes: 4 additions & 4 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function displayAjaxDeleteAllBlocks()
$zone_name = pSQL(Tools::getValue('zone'));
$id_lang = (int) Tools::getValue('ctx_id_lang');
$id_shop = (int) Tools::getValue('ctx_id_shop');
$success = \PrettyBlocksModel::deleteBlocksFromZone($zone_name, $id_lang, $id_shop);
$success = PrettyBlocksModel::deleteBlocksFromZone($zone_name, $id_lang, $id_shop);
$message = $this->translator->trans('An error has occured during this process', [], 'Modules.Prettyblocks.Admin');
if ($success) {
$message = $this->translator->trans('Blocks deleted with success', [], 'Modules.Prettyblocks.Admin');
Expand All @@ -138,7 +138,7 @@ public function displayAjaxCopyZone()
$id_shop = (int) Tools::getValue('ctx_id_shop');
$zone_name = pSQL(Tools::getValue('zone'));
$zone_name_to_paste = pSQL(Tools::getValue('zone_name_to_paste'));
$success = \PrettyBlocksModel::copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_shop);
$success = PrettyBlocksModel::copyZone($zone_name, $zone_name_to_paste, $id_lang, $id_shop);
$message = $this->translator->trans('An error has occured during this process', [], 'Modules.Prettyblocks.Admin');
if ($success) {
$message = $this->translator->trans('Zone dupplicated with success', [], 'Modules.Prettyblocks.Admin');
Expand All @@ -160,7 +160,7 @@ public function displayAjaxinsertBlock()
$zone_name = pSQL(Tools::getValue('zone_name'));
$id_lang = (int) Tools::getValue('ctx_id_lang');
$id_shop = (int) Tools::getValue('ctx_id_shop');
$state = \PrettyBlocksModel::registerBlockToZone($zone_name, $code, $id_lang, $id_shop);
$state = PrettyBlocksModel::registerBlockToZone($zone_name, $code, $id_lang, $id_shop);

exit(json_encode([
'state' => $state,
Expand Down Expand Up @@ -487,7 +487,7 @@ public function displayAjaxupdateTitleComponent()
$id_prettyblocks = (int) Tools::getValue('id_prettyblocks');
$element = Tools::getValue('element');

$model = new \PrettyBlocksModel($id_prettyblocks, $id_lang, $id_shop);
$model = new PrettyBlocksModel($id_prettyblocks, $id_lang, $id_shop);
$model->mergeStateWithFields();
if (Tools::getIsset('index')) {
// save state
Expand Down
22 changes: 20 additions & 2 deletions prettyblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ class PrettyBlocks extends Module implements WidgetInterface
'displayHeader',
'actionDispatcher',
'actionFrontControllerSetVariables',
'ActionRegisterThemeSettings',
];

public function __construct()
{
$this->name = 'prettyblocks';
$this->tab = 'administration';
$this->version = '3.0.6';
$this->version = '3.0.7';
$this->author = 'PrestaSafe';
$this->need_instance = 1;
$this->js_path = $this->_path . 'views/js/';
Expand Down Expand Up @@ -207,7 +208,7 @@ public function getWidgetVariables($hookName = null, array $configuration = [])

public function hookdisplayHeader($params)
{
if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'iframe') || \Tools::getValue('prettyblocks') === '1') {
if ((isset($_SERVER['HTTP_SEC_FETCH_DEST']) && $_SERVER['HTTP_SEC_FETCH_DEST'] == 'iframe') || Tools::getValue('prettyblocks') === '1') {
$this->context->controller->registerJavascript(
'prettyblocks',
'modules/' . $this->name . '/views/js/build.js',
Expand Down Expand Up @@ -320,4 +321,21 @@ public static function renderZone($params)

return $context->smarty->fetch('module:prettyblocks/views/templates/front/zone.tpl');
}

/**
* Hook for adding theme settings
* quick fix for adding tinyMCE api key.
*/
public function hookActionRegisterThemeSettings()
{
return [
'tinymce_api_key' => [
'type' => 'text', // type of field
'label' => $this->l('TinyMCE api key'), // label to display
'description' => $this->l('Add your TinyMCE api key (free) https://www.tiny.cloud/pricing/'), // description to display
'tab' => 'Settings',
'default' => 'no-api-key', // default value (Boolean)
],
];
}
}
1 change: 1 addition & 0 deletions src/Controller/AdminThemeManagerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public function indexAction()
'ajax_token' => \Configuration::getGlobalValue('_PRETTYBLOCKS_TOKEN_'),
'prettyblocks_version' => $module->version,
'available_language_ids' => $available_language_ids,
'tinymce_api_key' => \TplSettings::getSettings('tinymce_api_key') ?? 'no-api-key',
],
'css_build' => $css,
'js_build' => $js,
Expand Down
2 changes: 1 addition & 1 deletion upgrade/upgrade-2.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
*/
function upgrade_module_2_0_0($module)
{
return \PrettyBlocksMigrate::migrateConfig();
return PrettyBlocksMigrate::migrateConfig();
}
6 changes: 3 additions & 3 deletions upgrade/upgrade-3.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
function upgrade_module_3_0_0($module)
{
if (!\PrettyBlocksMigrate::tableExists('prettyblocks_settings')) {
if (!PrettyBlocksMigrate::tableExists('prettyblocks_settings')) {
$module->makeSettingsTable();
}
\PrettyBlocksMigrate::migrateLangTable();
\PrettyBlocksMigrate::migrateSettings();
PrettyBlocksMigrate::migrateLangTable();
PrettyBlocksMigrate::migrateSettings();
$module->registerHook('displayHeader');

return true;
Expand Down
4 changes: 2 additions & 2 deletions upgrade/upgrade-3.0.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/
function upgrade_module_3_0_2($module)
{
\Configuration::deleteByName('_PRETTYBLOCKS_TOKEN_');
\Configuration::updateGlobalValue('_PRETTYBLOCKS_TOKEN_', \Tools::passwdGen(25));
Configuration::deleteByName('_PRETTYBLOCKS_TOKEN_');
Configuration::updateGlobalValue('_PRETTYBLOCKS_TOKEN_', Tools::passwdGen(25));

return true;
}
37 changes: 37 additions & 0 deletions upgrade/upgrade-3.0.7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (c) Since 2020 PrestaSafe and contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaSafe <[email protected]>
* @copyright Since 2020 PrestaSafe and contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaSafe
*/
if (!defined('_PS_VERSION_')) {
exit;
}

/**
* @param prettyblocks $module
*
* @return bool|string
*
* @throws PrestaShopDatabaseException
* @throws PrestaShopException
*/
function upgrade_module_3_0_7($module)
{
$module->registerHook('ActionRegisterThemeSettings');

return true;
}

0 comments on commit d6fda1c

Please sign in to comment.