This commit is contained in:
2024-12-31 11:07:09 +01:00
parent df7915205d
commit e089172b15
1916 changed files with 165422 additions and 271 deletions

View File

@ -0,0 +1,148 @@
<?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace ACF\Previewer;
defined('_JEXEC') or die;
class Countdown extends Field
{
/**
* The field framework widget name.
*
* @var string
*/
protected $field = 'Countdown';
/**
* The theme used.
*
* @var string
*/
private $theme;
public function __construct($data = [], $payload = [])
{
parent::__construct($data, $payload);
// Set theme
$this->theme = $this->getTheme();
}
/**
* Render the field.
*
* @return string
*/
public function onSetup()
{
$this->payload = [
// Field values
'countdown_type' => 'evergreen',
'timezone' => 'server',
'dynamic_days' => '1',
'dynamic_hours' => '12',
'dynamic_minutes' => '59',
'dynamic_seconds' => '59',
// Countdown End Action
'finish_text' => $this->fieldParams->get('finish_text', ''),
'redirect_url' => $this->fieldParams->get('redirect_url', ''),
'countdown_action' => 'restart',
// Preset
'theme' => $this->theme,
'format' => $this->fieldParams->get('format', ''),
// Unit Display
'days' => $this->fieldParams->get('days') === '1',
'days_label' => $this->fieldParams->get('days_label'),
'hours' => $this->fieldParams->get('hours') === '1',
'hours_label' => $this->fieldParams->get('hours_label'),
'minutes' => $this->fieldParams->get('minutes') === '1',
'minutes_label' => $this->fieldParams->get('minutes_label'),
'seconds' => $this->fieldParams->get('seconds') === '1',
'seconds_label' => $this->fieldParams->get('seconds_label'),
'separator' => $this->fieldParams->get('separator') === '1',
'double_zeroes_format' => $this->fieldParams->get('double_zeroes_format') === '1',
// Unit Item
'item_size' => $this->fieldParams->get('item_size_responsive.item_size'),
'item_padding' => $this->fieldParams->get('item_padding_control.item_padding'),
'gap' => $this->fieldParams->get('item_gap.gap'),
'item_border_style' => $this->fieldParams->get('border.style'),
'item_border_width' => $this->fieldParams->get('border.width'),
'item_border_color' => $this->fieldParams->get('border.color'),
'item_background_color' => $this->fieldParams->get('item_background_color'),
'item_border_radius' => $this->fieldParams->get('item_border_radius_control.item_border_radius'),
// Unit Digits Container
'digits_wrapper_min_width' => $this->fieldParams->get('digits_wrapper_custom_width') === '1' ? $this->fieldParams->get('digits_wrapper_min_width') : null,
'digits_wrapper_padding' => $this->fieldParams->get('digits_wrapper_padding_control.digits_wrapper_padding'),
'digits_wrapper_border_radius' => $this->fieldParams->get('digits_wrapper_border_radius_control.digits_wrapper_border_radius'),
'digits_wrapper_background_color' => $this->fieldParams->get('digits_wrapper_background_color'),
// Unit Digit
'digits_font_size' => $this->fieldParams->get('digits_font_size_control.digits_font_size'),
'digits_font_weight' => $this->fieldParams->get('digits_font_weight'),
'digit_min_width' => $this->fieldParams->get('digits_custom_width') === '1' ? $this->fieldParams->get('digits_min_width') : null,
'digits_padding' => $this->fieldParams->get('digits_padding_control.digits_padding'),
'digit_border_radius' => $this->fieldParams->get('digits_border_radius_control.digits_border_radius'),
'digits_gap' => $this->fieldParams->get('digits_gap_control.digits_gap'),
'digit_background_color' => $this->fieldParams->get('digit_background_color'),
'digit_text_color' => $this->fieldParams->get('digit_text_color'),
// Unit Label
'label_font_size' => $this->fieldParams->get('label_font_size_control.label_font_size'),
'label_font_weight' => $this->fieldParams->get('label_font_weight'),
'unit_label_margin_top' => $this->fieldParams->get('unit_label_margin_top'),
'unit_label_text_color' => $this->fieldParams->get('unit_label_text_color'),
];
$this->widget = new \NRFramework\Widgets\Countdown(json_decode(json_encode($this->payload), true));
}
/**
* Return all assets used by this field.
*
* @return void
*/
public function getAssets()
{
$exclude_breakpoints = [];
// If we are not viewing the fullscreen previewer,
// then get the widget's Custom CSS of the desktop
// due to the IFrame having small width and triggering the tablet/mobile CSS breakpoints
if (!$this->data->get('fullscreen'))
{
$exclude_breakpoints = ['tablet', 'mobile'];
}
return [
'css' => \NRFramework\Widgets\Countdown::getCSS($this->theme),
'js' => \NRFramework\Widgets\Countdown::getJS(),
'custom_css' => $this->widget->getWidgetCSS($exclude_breakpoints)
];
}
/**
* Get the theme.
*
* @return string
*/
private function getTheme()
{
$preset_source = $this->fieldParams->get('preset_source', 'preset');
$preset = $this->fieldParams->get('preset', '1');
// Determine theme
return $preset_source === 'custom' ? 'custom' : ($preset === '8' ? 'oneline' : 'default');
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace ACF\Previewer;
defined('_JEXEC') or die;
class FAQ extends Field
{
/**
* The field framework widget name.
*
* @var string
*/
protected $field = 'FAQ';
/**
* Render the field.
*
* @return string
*/
public function onSetup()
{
$value = [
[
'question' => 'Who should use EngageBox?',
'answer' => 'EngageBox is the most powerful popup engine in the Joomla! market used by marketing agencies, bloggers, eCommerce websites, and all small businesses. If you want to grow your email list, improve your website conversions, and reduce cart abandonment, then you need EngageBox.'
],
[
'question' => 'What\'s required to use EngageBox?',
'answer' => 'EngageBox can be used in both Joomla 3 and Joomla 4. In detail, you will need an up-to-date version of Joomla 3.8.0 or higher, PHP 7.0.0 or higher, and MySQL 5 or higher.'
],
[
'question' => 'Do I need coding skills to use EngageBox?',
'answer' => 'Absolutely not! You can create and customize beautiful popups without any coding knowledge. We made it extremely user-friendly, so you can build a high-converting popup without hiring a developer.'
],
[
'question' => 'What type of conversions can I expect?',
'answer' => 'It will make a significant difference. Game-changing! Our average user sees over 500% increase in sales, customers base and growth in general.'
],
[
'question' => 'What if a visitor has a pop-up adblocker enabled?',
'answer' => 'Will still work! EngageBox produces popups in a way which can\'t be blocked by the browsers pop-up blocking feature or 3rd party extensions such as AdBlock or uBlock.'
],
];
$this->payload = [
'value' => $value,
'css_class' => ' template_' . $this->fieldParams->get('template'),
'columns' => (int) $this->fieldParams->get('columns', 1),
'item_gap' => $this->fieldParams->get('item_gap_control.item_gap', 20),
'column_gap' => $this->fieldParams->get('column_gap_control.column_gap', 20),
'item_background_color' => $this->fieldParams->get('background_color'),
'item_border_radius' => $this->fieldParams->get('border_radius_control.item_border_radius'),
'item_padding' => $this->fieldParams->get('padding_control.item_padding'),
'question_font_size' => $this->fieldParams->get('question_font_size_control.question_font_size'),
'question_text_color' => $this->fieldParams->get('question_text_color'),
'answer_font_size' => $this->fieldParams->get('answer_font_size_control.answer_font_size'),
'answer_text_color' => $this->fieldParams->get('answer_text_color'),
'generate_faq' => $this->fieldParams->get('generate_faq', '0') === '1',
'keep_one_question_open' => $this->fieldParams->get('keep_one_question_open', '0') === '1',
'separator' => $this->fieldParams->get('separator', '0') === '1',
'separator_color' => $this->fieldParams->get('separator_color'),
'initial_state' => $this->fieldParams->get('initial_state', 'first-open')
];
$show_toggle_icon = $this->fieldParams->get('show_toggle_icon', '1') === '1';
$this->payload['show_toggle_icon'] = $show_toggle_icon;
if ($show_toggle_icon)
{
$this->payload['icon'] = $this->fieldParams->get('icon', 'arrow');
$this->payload['icon_position'] = $this->fieldParams->get('icon_position', 'right');
}
$this->widget = new \NRFramework\Widgets\FAQ(json_decode(json_encode($this->payload), true));
}
/**
* Adds some extra CSS to the previewer's body.
*
* @return string
*/
protected function getFieldPreviewerCSS()
{
if ((int) $this->fieldParams->get('template') !== 4)
{
return;
}
return '
body {
background: #EBEBEB !important;
padding: 20px !important;
}
';
}
}

View File

@ -0,0 +1,235 @@
<?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link http://www.tassos.gr
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace ACF\Previewer;
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
use Joomla\CMS\Uri\Uri;
class Field
{
/**
* The field framework widget name.
*
* @var string
*/
protected $field = '';
/**
* Field Editor Form Data.
*
* @var array
*/
protected $data = [];
/**
* Field Params.
*
* @var object
*/
protected $fieldParams = [];
/**
* The field payload used to render the field.
*
* @var array
*/
protected $payload;
/**
* The Framework Widget.
*
* @var Widget
*/
protected $widget = null;
public function __construct($data = [], $payload = [])
{
$this->data = new Registry($data);
$fieldParams = isset($data['fieldparams']) ? $data['fieldparams'] : [];
$this->fieldParams = new Registry($fieldParams);
if ($payload)
{
$this->payload = $payload;
}
}
/**
* Saves the field's JSON data for previewer to render it.
*
* @return void
*/
protected function saveJSON()
{
// Get path to file
$file = implode(DIRECTORY_SEPARATOR, [\ACF\Helpers\Previewer::getJsonDirectory(), $this->data->get('type') . '.json']);
// Save JSON file
file_put_contents($file, $this->getHTML());
}
/**
* Setup the field.
*
* @return string
*/
public function setup()
{
if (method_exists($this, 'onSetup'))
{
$this->onSetup();
}
$this->saveJSON();
}
/**
* Render the field.
*
* @return string
*/
public function render()
{
return $this->widget->render();
}
/**
* Field HTML output.
*
* @return string
*/
private function getHTML()
{
return '<html><head>' . $this->getHead() . '</head><body>' . $this->render() . '</body></html>';
}
/**
* Returns the head of the preview HTML.
*
* @return string
*/
private function getHead()
{
if (!$assets = $this->getAssets())
{
return;
}
// Add Reset CSS
$head = '<style>' . $this->getResetCSS() . '</style>';
// Add Custom CSS
if (isset($assets['custom_css']) && !empty($assets['custom_css']))
{
$head .= '<style>' . $assets['custom_css'] . '</style>';
}
$base_url = Uri::root();
// Add CSS
if (isset($assets['css']) && is_array($assets['css']) && count($assets['css']))
{
foreach ($assets['css'] as $css)
{
$css = str_replace('plg_system_nrframework/', 'plg_system_nrframework/css/', $css);
$link = $base_url . 'media/' . $css;
$head .= '<link href="' . $link . '" rel="stylesheet" />';
}
}
// Add Core JS
$head .= '<script src="' . $base_url . 'media/system/js/core.js"></script>';
// Add JS
if (isset($assets['js']) && is_array($assets['js']) && count($assets['js']))
{
foreach ($assets['js'] as $js)
{
$js = str_replace('plg_system_nrframework/', 'plg_system_nrframework/js/', $js);
$link = $base_url . 'media/' . $js;
$head .= '<script src="' . $link . '"></script>';
}
}
return $head;
}
/**
* Returns the field reset CSS.
*
* @return string
*/
private function getResetCSS()
{
$reset_css = '
body {
border: 0 !important;
background: #fff !important;
padding: 0 !important;
margin: 0 !important;
overflow-x: hidden !important;
font-family: Arial;
font-size: 16px;
}
';
return $reset_css . $this->getFieldPreviewerCSS();
}
/**
* Adds some extra CSS to the previewer's body.
*
* @return string
*/
protected function getFieldPreviewerCSS()
{
}
/**
* The CSS/JS assets that are required for the field to run.
*
* @return void
*/
public function getAssets()
{
return [
'css' => $this->getFieldCSS(),
'js' => $this->getFieldJS(),
'custom_css' => $this->widget->getOption('css_vars') . $this->widget->getOption('custom_css')
];
}
/**
* Returns the field CSS files.
*
* @return array
*/
private function getFieldCSS()
{
return $this->widget && method_exists($this->widget, 'getCSS') ? $this->widget->getCSS() : [];
}
/**
* Returns the field JS files.
*
* @return array
*/
private function getFieldJS()
{
return $this->widget && method_exists($this->widget, 'getJS') ? $this->widget->getJS() : [];
}
}