first commit

This commit is contained in:
Ryan Ariana
2024-05-06 11:04:37 +07:00
commit aee061ddba
7322 changed files with 2918816 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeBannerBuilder extends UCAdminNoticeBuilderAbstract{
const THEME_DARK = 'dark';
const THEME_LIGHT = 'light';
private $theme = self::THEME_LIGHT;
private $linkUrl;
private $linkTarget;
private $imageUrl;
/**
* set the notice theme
*/
public function theme($theme){
$this->theme = $theme;
return $this;
}
/**
* set the notice link URL
*/
public function link($url, $target = ''){
$this->linkUrl = $url;
$this->linkTarget = $target;
return $this;
}
/**
* set the notice image URL
*/
public function image($url){
$this->imageUrl = $url;
return $this;
}
/**
* get the notice html
*/
public function build(){
$class = implode(' ', array(
'notice',
'uc-admin-notice',
'uc-admin-notice--banner',
'uc-admin-notice--theme-' . $this->theme,
'uc-admin-notice--' . $this->getId(),
));
$html = '<div class="' . esc_attr($class) . '">';
$html .= '<a class="uc-notice-link" href="' . esc_url($this->linkUrl) . '" target="' . esc_attr($this->linkTarget) . '" >';
$html .= $this->getImageHtml();
$html .= '</a>';
$html .= $this->getDebugHtml();
$html .= $this->getDismissHtml();
$html .= '</div>';
return $html;
}
/**
* get the image html
*/
private function getImageHtml(){
if(empty($this->imageUrl))
return '';
return '<img class="uc-notice-image" src="' . esc_attr($this->imageUrl) . '" alt="" />';
}
}

View File

@@ -0,0 +1,172 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeBuilder extends UCAdminNoticeBuilderAbstract{
const COLOR_INFO = 'info';
const COLOR_WARNING = 'warning';
const COLOR_ERROR = 'error';
const COLOR_DOUBLY = 'doubly';
const ACTION_VARIANT_PRIMARY = 'primary';
const ACTION_VARIANT_SECONDARY = 'secondary';
private $color = self::COLOR_INFO;
private $heading;
private $content;
private $actions = array();
/**
* set the notice color
*/
public function color($color){
$this->color = $color;
return $this;
}
/**
* set the notice heading
*/
public function withHeading($heading){
$this->heading = $heading;
return $this;
}
/**
* set the notice content
*/
public function withContent($content){
$this->content = $content;
return $this;
}
/**
* add the notice action
*/
public function addAction($action){
$this->actions[] = $action;
return $this;
}
/**
* add the link action
*/
public function withLinkAction($text, $url, $variant = self::ACTION_VARIANT_PRIMARY, $target = ''){
$action = '<a class="button button-' . $variant . '" href="' . esc_url($url) . '" target="' . esc_attr($target) . '">' . $text . '</a>';
return $this->addAction($action);
}
/**
* add the dismiss action
*/
public function withDismissAction($text, $variant = self::ACTION_VARIANT_SECONDARY){
$ajaxUrl = $this->getDismissAjaxUrl();
$action = '<a class="button button-' . $variant . '" href="#" data-action="dismiss" data-ajax-url="' . esc_attr($ajaxUrl) . '">' . $text . '</a>';
return $this->addAction($action);
}
/**
* add the postpone action
*/
public function withPostponeAction($text, $duration, $variant = self::ACTION_VARIANT_SECONDARY){
$ajaxUrl = $this->getPostponeAjaxUrl($duration);
$action = '<a class="button button-' . $variant . '" href="#" data-action="postpone" data-ajax-url="' . esc_attr($ajaxUrl) . '">' . $text . '</a>';
return $this->addAction($action);
}
/**
* get the notice html
*/
public function build(){
$class = implode(' ', array(
'notice',
'notice-' . $this->color,
'uc-admin-notice',
'uc-admin-notice--' . $this->getId(),
));
$html = '<div class="' . esc_attr($class) . '">';
$html .= '<div class="uc-notice-wrapper">';
$html .= $this->getLogoHtml();
$html .= '<div class="uc-notice-container">';
$html .= $this->getHeadingHtml();
$html .= $this->getContentHtml();
$html .= $this->getActionsHtml();
$html .= $this->getDebugHtml();
$html .= '</div>';
$html .= '</div>';
$html .= $this->getDismissHtml();
$html .= '</div>';
return $html;
}
/**
* get the logo html
*/
private function getLogoHtml(){
$logoUrl = GlobalsUC::$urlPluginImages . 'logo-circle.svg';
return '<img class="uc-notice-logo" src="' . esc_attr($logoUrl) . '" alt="Logo" width="40" height="40" />';
}
/**
* get the heading html
*/
private function getHeadingHtml(){
if(empty($this->heading))
return '';
return '<h3 class="uc-notice-heading">' . $this->heading . '</h3>';
}
/**
* get the content html
*/
private function getContentHtml(){
if(empty($this->content))
return '';
return '<p class="uc-notice-content">' . $this->content . '</p>';
}
/**
* get actions html
*/
private function getActionsHtml(){
if(empty($this->actions))
return '';
return '<div class="uc-notice-actions">' . implode('', $this->actions) . '</div>';
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
abstract class UCAdminNoticeBuilderAbstract{
private $id;
private $dismissible = false;
private $debug;
/**
* get the notice html
*/
abstract public function build();
/**
* create a new builder instance
*/
public function __construct($id){
$this->id = $id;
}
/**
* set the notice as dismissible
*/
public function dismissible(){
$this->dismissible = true;
return $this;
}
/**
* set the notice debug data
*/
public function debug($data){
$this->debug = $data;
return $this;
}
/**
* get the notice identifier
*/
protected function getId(){
return $this->id;
}
/**
* get the dismiss html
*/
protected function getDismissHtml(){
if($this->dismissible === false)
return '';
$ajaxUrl = $this->getDismissAjaxUrl();
$text = __('Dismiss', 'unlimited-elements-for-elementor');
$title = __('Dismiss Notice', 'unlimited-elements-for-elementor');
return '<a class="uc-notice-dismiss" href="#" data-action="dismiss" title="' . esc_attr($title) . '" data-ajax-url="' . esc_attr($ajaxUrl) . '">' . $text . '</a>';
}
/**
* get the debug html
*/
protected function getDebugHtml(){
if(empty($this->debug))
return '';
return '<p class="uc-notice-debug"><b>DEBUG:</b> ' . $this->debug . '</p>';
}
/**
* get the dismiss ajax url
*/
protected function getDismissAjaxUrl(){
$ajaxUrl = HelperUC::getUrlAjax('dismiss_notice');
$ajaxUrl = UniteFunctionsUC::addUrlParams($ajaxUrl, array('id' => $this->id));
return $ajaxUrl;
}
/**
* get the postpone ajax url (duration in hours)
*/
protected function getPostponeAjaxUrl($duration){
$ajaxUrl = HelperUC::getUrlAjax('postpone_notice');
$ajaxUrl = UniteFunctionsUC::addUrlParams($ajaxUrl, array('id' => $this->id, 'duration' => $duration));
return $ajaxUrl;
}
}

View File

@@ -0,0 +1,19 @@
<?php
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
$path = dirname(__FILE__) . '/';
require_once $path . 'builders/builder_abstract.class.php';
require_once $path . 'builders/builder.class.php';
require_once $path . 'builders/banner_builder.class.php';
require_once $path . 'notices/notice_abstract.class.php';
require_once $path . 'notices/banner.class.php';
require_once $path . 'notices/simple_example.class.php';
require_once $path . 'notices/doubly.class.php';
require_once $path . 'notices/rating.class.php';
require_once $path . 'manager.class.php';
require_once $path . 'options.class.php';
require_once $path . 'notices.class.php';

View File

@@ -0,0 +1,69 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticesManager{
private static $notices = array();
/**
* get all notices
*/
public static function getNotices(){
return self::$notices;
}
/**
* add a notice instance
*/
public static function addNotice($notice){
self::$notices[$notice->getId()] = $notice;
}
/**
* mark the notice as dismissed
*/
public static function dismissNotice($id){
$notice = self::getNotice($id);
if($notice === null)
return;
$notice->dismiss();
}
/**
* postpone the notice for the given duration (in hours)
*/
public static function postponeNotice($id, $duration){
$notice = self::getNotice($id);
if($notice === null)
return;
$notice->postpone($duration);
}
/**
* get the notice by identifier
*/
private static function getNotice($id){
if(empty(self::$notices[$id]))
return null;
return self::$notices[$id];
}
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
abstract class UCAdminNotices{
const NOTICES_DISPLAY_LIMIT = 2;
private static $initialized = false;
/**
* init
*/
public static function init($notices){
$shouldInitialize = self::shouldInitialize();
if($shouldInitialize === false)
return;
self::initializeOptions();
self::registerNotices($notices);
self::registerHooks();
self::checkDismissAction();
self::$initialized = true;
}
/**
* display notices
*/
public static function displayNotices(){
$notices = UCAdminNoticesManager::getNotices();
$displayedCount = 0;
foreach($notices as $notice){
$isDebug = $notice->isDebug();
if($isDebug === true){
$noticeHtml = $notice->getHtml();
echo $noticeHtml;
continue;
}
if($displayedCount >= self::NOTICES_DISPLAY_LIMIT)
return;
$isDisplayable = $notice->shouldDisplay();
if($isDisplayable === false)
continue;
$displayedCount++;
$noticeHtml = $notice->getHtml();
echo $noticeHtml;
}
}
/**
* enqueue assets
*/
public static function enqueueAssets(){
HelperUC::addStyleAbsoluteUrl(GlobalsUC::$url_provider . 'assets/admin_notices.css', 'uc_admin_notices');
HelperUC::addScriptAbsoluteUrl(GlobalsUC::$url_provider . 'assets/admin_notices.js', 'uc_admin_notices');
}
/**
* check if notices need to be initialized
*/
private static function shouldInitialize(){
if(self::$initialized === true)
return false;
if(GlobalsUC::$is_admin === false)
return false;
if(current_user_can('administrator') === false)
return false;
return true;
}
/**
* initialize options
*/
private static function initializeOptions(){
// Set plugin installation time
$installTime = UCAdminNoticesOptions::getOption('install_time');
if(empty($installTime))
UCAdminNoticesOptions::setOption('install_time', time());
}
/**
* check for dismiss action
*/
private static function checkDismissAction(){
$id = UniteFunctionsUC::getPostGetVariable('uc_dismiss_notice', '', UniteFunctionsUC::SANITIZE_KEY);
if(empty($id))
return;
UCAdminNoticesManager::dismissNotice($id);
}
/**
* register notices
*/
private static function registerNotices($notices){
foreach($notices as $notice){
UCAdminNoticesManager::addNotice($notice);
}
}
/**
* register hooks
*/
private static function registerHooks(){
UniteProviderFunctionsUC::addFilter('admin_notices', array(self::class, 'displayNotices'), 10, 3);
UniteProviderFunctionsUC::addAction('admin_enqueue_scripts', array(self::class, 'enqueueAssets'));
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeBanner extends UCAdminNoticeAbstract{
/**
* get the notice identifier
*/
public function getId(){
return 'black_friday_23a';
}
/**
* get the notice html
*/
public function getHtml(){
$linkUrl = 'https://unlimited-elements.com/pricing/';
$linkTarget = '_blank';
//$imageUrl = GlobalsUC::$urlPluginImages . 'bannerimage.jpg';
$imageUrl = 'http://via.placeholder.com/1360x110';
$builder = $this->createBannerBuilder();
$builder->dismissible();
$builder->theme(UCAdminNoticeBannerBuilder::THEME_DARK);
$builder->link($linkUrl, $linkTarget);
$builder->image($imageUrl);
$html = $builder->build();
return $html;
}
/**
* initialize the notice
*/
protected function init(){
$this->freeOnly();
$this->setLocation(self::LOCATION_EVERYWHERE);
$this->setDuration(720); // 30 days in hours
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeDoubly extends UCAdminNoticeAbstract{
/**
* get the notice identifier
*/
public function getId(){
return 'doubly';
}
/**
* get the notice html
*/
public function getHtml(){
$heading = __('Live Copy Paste from Unlimited Elements', 'unlimited-elements-for-elementor');
$content = __('Did you know that now you can copy fully designed sections from Unlimited Elements to your website for FREE? <br /> If you want to try then install our new plugin called Doubly.', 'unlimited-elements-for-elementor');
$installText = __('Install Doubly Now', 'unlimited-elements-for-elementor');
$installUrl = UniteFunctionsWPUC::getInstallPluginLink('doubly');
$installUrl = UniteFunctionsUC::addUrlParams($installUrl, array('uc_dismiss_notice' => $this->getId()));
$builder = $this->createBuilder();
$builder->dismissible();
$builder->color(UCAdminNoticeBuilder::COLOR_DOUBLY);
$builder->withHeading($heading);
$builder->withContent($content);
$builder->withLinkAction($installText, $installUrl);
$html = $builder->build();
return $html;
}
/**
* initialize the notice
*/
protected function init(){
$this->setDuration(48); // 2 days in hours
}
/**
* check if the notice condition is allowed
*/
protected function isConditionAllowed(){
// check if the Doubly plugin is installed
if(defined('DOUBLY_INC'))
return false;
return true;
}
}

View File

@@ -0,0 +1,367 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
abstract class UCAdminNoticeAbstract{
const LOCATION_EVERYWHERE = 'everywhere';
const LOCATION_DASHBOARD = 'dashboard';
const LOCATION_PLUGIN = 'plugin';
private $location = self::LOCATION_EVERYWHERE;
private $start = 0;
private $duration = 0;
private $freeOnly = false;
/**
* get the notice identifier
*/
abstract public function getId();
/**
* get the notice html
*/
abstract public function getHtml();
/**
* create a new notice instance
*/
public function __construct(){
$this->init();
}
/**
* check if the notice is in the debug mode
*/
public function isDebug(){
if(GlobalsUnlimitedElements::$debugAdminNotices === true)
return true;
return false;
}
/**
* check if the notice should be displayed
*/
public function shouldDisplay(){
$isDebug = $this->isDebug();
if($isDebug === true)
return true;
$isDismissed = $this->isDismissed();
if($isDismissed === true)
return false;
$isFreeAllowed = $this->isFreeAllowed();
if($isFreeAllowed === false)
return false;
$isLocationAllowed = $this->isLocationAllowed();
if($isLocationAllowed === false)
return false;
$isConditionAllowed = $this->isConditionAllowed();
if($isConditionAllowed === false)
return false;
$isScheduled = $this->isScheduled();
if($isScheduled === true)
return false;
return true;
}
/**
* mark the notice as dismissed
*/
public function dismiss(){
$this->setOption('dismissed', true);
}
/**
* postpone the notice for the given duration (in hours)
*/
public function postpone($duration){
$this->setOption('start_time', time() + $duration * 3600);
$this->deleteOption('finish_time');
}
/**
* initialize the notice
*/
protected function init(){
//
}
/**
* create a new builder instance
*/
protected function createBuilder(){
$id = $this->getId();
$builder = new UCAdminNoticeBuilder($id);
$builder = $this->initBuilder($builder);
return $builder;
}
/**
* create a new banner builder instance
*/
protected function createBannerBuilder(){
$id = $this->getId();
$builder = new UCAdminNoticeBannerBuilder($id);
$builder = $this->initBuilder($builder);
return $builder;
}
/**
* check if the notice condition is allowed
*/
protected function isConditionAllowed(){
return true;
}
/**
* enable the notice free only mode - show only in the free version
*/
protected function freeOnly(){
$this->freeOnly = true;
}
/**
* set the notice display location
*/
protected function setLocation($location){
$this->location = $location;
}
/**
* set the notice start offset in hours from the plugin installation
*/
protected function setStart($start){
$this->start = $start;
}
/**
* set the notice duration offset in hours from the first display
*/
protected function setDuration($duration){
$this->duration = $duration;
}
/**
* initialize the builder instance
*/
private function initBuilder($builder){
$isDebug = $this->isDebug();
if($isDebug === true){
$debugData = $this->getDebugData();
$builder->debug($debugData);
}
return $builder;
}
/**
* get the debug data of the notice
*/
private function getDebugData(){
$isFreeAllowed = $this->isFreeAllowed();
$id = $this->getId();
if($isFreeAllowed === false)
return "Notice <b>{$id}</b> hidden - free only";
$isDismissed = $this->isDismissed();
if($isDismissed === true)
return "Notice <b>{$id}</b> hidden - dismissed";
$isLocationAllowed = $this->isLocationAllowed();
if($isLocationAllowed === false)
return "Notice <b>{$id}</b> hidden - incorrect location";
$isConditionAllowed = $this->isConditionAllowed();
if($isConditionAllowed === false)
return "Notice <b>{$id}</b> hidden - false condition";
$dateFormat = 'j F Y H:i:s';
$currentTime = time();
$startTime = $this->getStartTime();
if($currentTime < $startTime)
return "Notice <b>{$id}</b> hidden - scheduled (will be visible on " . date($dateFormat, $startTime) . ")";
$finishTime = $this->getFinishTime();
if($currentTime <= $finishTime)
return "Notice <b>{$id}</b> visible (will be hidden on ". date($dateFormat, $finishTime). ")";
return "Notice <b>{$id}</b> hidden - permanently";
}
/**
* check if the notice is dismissed
*/
private function isDismissed(){
$isDismissed = $this->getOption('dismissed', false);
$isDismissed = UniteFunctionsUC::strToBool($isDismissed);
return $isDismissed;
}
/**
* check if the notice is allowed for the free version
*/
private function isFreeAllowed(){
if($this->freeOnly === true && GlobalsUC::$isProVersion === true)
return false;
return true;
}
/**
* check if the notice location is allowed
*/
private function isLocationAllowed(){
switch($this->location){
case self::LOCATION_EVERYWHERE:
return true;
break;
case self::LOCATION_DASHBOARD:
$current_screen = get_current_screen();
if($current_screen->id === 'dashboard')
return true;
break;
case self::LOCATION_PLUGIN:
$page = UniteFunctionsUC::getGetVar('page', '', UniteFunctionsUC::SANITIZE_KEY);
if($page === GlobalsUnlimitedElements::PLUGIN_NAME)
return true;
break;
}
return false;
}
/**
* check if the notice is scheduled
*/
private function isScheduled(){
$currentTime = time();
$startTime = $this->getStartTime();
$finishTime = $this->getFinishTime();
if($currentTime >= $startTime && $currentTime <= $finishTime)
return false;
return true;
}
/**
* get the notice start time
*/
private function getStartTime(){
$installTime = intval(UCAdminNoticesOptions::getOption('install_time'));
$startTime = $this->getOption('start_time');
if(empty($startTime))
$startTime = $installTime + $this->start * 3600;
return $startTime;
}
/**
* get the notice finish time
*/
private function getFinishTime(){
$currentTime = time();
$startTime = $this->getStartTime();
if($currentTime >= $startTime){
$finishTime = $this->getOption('finish_time');
if(empty($finishTime)){
$finishTime = $currentTime + $this->duration * 3600;
$this->setOption('finish_time', $finishTime);
}
return $finishTime;
}
return 0;
}
/**
* get the notice option value
*/
private function getOption($key, $fallback = null){
$value = UCAdminNoticesOptions::getNoticeOption($this->getId(), $key, $fallback);
return $value;
}
/**
* set the notice option value
*/
private function setOption($key, $value){
UCAdminNoticesOptions::setNoticeOption($this->getId(), $key, $value);
}
/**
* delete the notice option value
*/
private function deleteOption($key){
UCAdminNoticesOptions::deleteNoticeOption($this->getId(), $key);
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeRating extends UCAdminNoticeAbstract{
/**
* get the notice identifier
*/
public function getId(){
return 'rating';
}
/**
* get the notice html
*/
public function getHtml(){
$heading = __('Could you please do us a BIG favor?', 'unlimited-elements-for-elementor');
$content = __('Leave a 5-start rating on WordPress. Help us spread the word and boost our motivation.', 'unlimited-elements-for-elementor');
$rateText = __('Ok, you deserve it', 'unlimited-elements-for-elementor');
$rateUrl = GlobalsUC::URL_RATE;
$rateVariant = UCAdminNoticeBuilder::ACTION_VARIANT_PRIMARY;
$rateTarget = '_blank';
$postponeText = __('Nope, maybe later', 'unlimited-elements-for-elementor');
$postponeDuration = 168; // 7 days in hours
$dismissText = __('I already did', 'unlimited-elements-for-elementor');
$builder = $this->createBuilder();
$builder->dismissible();
$builder->withHeading($heading);
$builder->withContent($content);
$builder->withLinkAction($rateText, $rateUrl, $rateVariant, $rateTarget);
$builder->withPostponeAction($postponeText, $postponeDuration);
$builder->withDismissAction($dismissText);
$html = $builder->build();
return $html;
}
/**
* initialize the notice
*/
protected function init(){
$this->setStart(240); // 10 days in hours
$this->setDuration(240); // 10 days in hours
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticeSimpleExample extends UCAdminNoticeAbstract{
/**
* get the notice identifier
*/
public function getId(){
return 'simple-example';
}
/**
* get the notice html
*/
public function getHtml(){
$heading = __('Example of a simple notice', 'unlimited-elements-for-elementor');
$content = __('Here is the content of a simple notice.', 'unlimited-elements-for-elementor');
$linkText = __('Link Text', 'unlimited-elements-for-elementor');
$linkUrl = 'https://google.com';
$linkVariant = UCAdminNoticeBuilder::ACTION_VARIANT_PRIMARY;
$linkTarget = '_blank';
$builder = $this->createBuilder();
$builder->dismissible();
$builder->withHeading($heading);
$builder->withContent($content);
$builder->withLinkAction($linkText, $linkUrl, $linkVariant, $linkTarget);
$html = $builder->build();
return $html;
}
/**
* initialize the notice
*/
protected function init(){
$this->setLocation(self::LOCATION_PLUGIN);
$this->setDuration(8760); // 365 days in hours
}
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* @package Unlimited Elements
* @author UniteCMS http://unitecms.net
* @copyright Copyright (c) 2016 UniteCMS
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later
*/
defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UCAdminNoticesOptions{
const OPTIONS_KEY = 'unlimited_elements_notices';
private static $optionsCache = array();
/**
* get the option value
*/
public static function getOption($key, $fallback = null){
$options = self::getOptions();
$value = UniteFunctionsUC::getVal($options['options'], $key, $fallback);
return $value;
}
/**
* set the option value
*/
public static function setOption($key, $value){
$options = self::getOptions();
$options['options'][$key] = $value;
self::setOptions($options);
}
/**
* get the notice all options
*/
public static function getNoticeOptions($id){
$options = self::getOptions();
$noticeOptions = UniteFunctionsUC::getVal($options['notices'], $id, array());
return $noticeOptions;
}
/**
* get the notice option value
*/
public static function getNoticeOption($id, $key, $fallback = null){
$options = self::getOptions();
$noticeOptions = self::getNoticeOptions($id);
$value = UniteFunctionsUC::getVal($noticeOptions, $key, $fallback);
return $value;
}
/**
* set the notice option value
*/
public static function setNoticeOption($id, $key, $value){
$options = self::getOptions();
$noticeOptions = self::getNoticeOptions($id);
$noticeOptions[$key] = $value;
$options['notices'][$id] = $noticeOptions;
self::setOptions($options);
}
/**
* delete the notice option value
*/
public static function deleteNoticeOption($id, $key){
$options = self::getOptions();
$noticeOptions = self::getNoticeOptions($id);
unset($noticeOptions[$key]);
$options['notices'][$id] = $noticeOptions;
self::setOptions($options);
}
/**
* get all options
*/
private static function getOptions(){
if(empty(self::$optionsCache)){
self::$optionsCache = get_option(self::OPTIONS_KEY, array(
'options' => array(),
'notices' => array(),
));
}
return self::$optionsCache;
}
/**
* set all options
*/
private static function setOptions($options){
self::$optionsCache = $options;
update_option(self::OPTIONS_KEY, $options);
}
}