From b26c38825451b51842d13933bce7abb167ebc3d0 Mon Sep 17 00:00:00 2001
From: otrok7 <50595291+otrok7@users.noreply.github.com>
Date: Sat, 16 Nov 2024 23:40:02 +0100
Subject: [PATCH] first working preview button
---
admin/partials/_backup_restore_setup.php | 1 +
admin/partials/bread-admin-display.php | 12 ++++-
includes/class-bread.php | 64 ++++++++++++++++--------
public/class-bread-public.php | 1 +
4 files changed, 55 insertions(+), 23 deletions(-)
diff --git a/admin/partials/_backup_restore_setup.php b/admin/partials/_backup_restore_setup.php
index 52caec8..5823df8 100644
--- a/admin/partials/_backup_restore_setup.php
+++ b/admin/partials/_backup_restore_setup.php
@@ -84,4 +84,5 @@
+
Generate Meeting List
diff --git a/admin/partials/bread-admin-display.php b/admin/partials/bread-admin-display.php
index 52dee1e..57d6e97 100644
--- a/admin/partials/bread-admin-display.php
+++ b/admin/partials/bread-admin-display.php
@@ -84,7 +84,10 @@ function admin_options_page()
if (!isset($_POST['bmltmeetinglistsave'])) {
$_POST['bmltmeetinglistsave'] = false;
}
- if ($_POST['bmltmeetinglistsave']) {
+ if (!isset($_POST['bmltmeetinglistpreview'])) {
+ $_POST['bmltmeetinglistpreview'] = false;
+ }
+ if ($_POST['bmltmeetinglistsave'] || $_POST['bmltmeetinglistpreview']) {
if (!wp_verify_nonce($_POST['_wpnonce'], 'bmltmeetinglistupdate-options')) {
die('Whoops! There was a problem with the data you posted. Please go back and try again.');
}
@@ -218,6 +221,12 @@ function admin_options_page()
if (!in_array($user->ID, Bread::getOption('authors'))) {
Bread::setOption('authors', $user->ID);
}
+ if ($_POST['bmltmeetinglistpreview']) {
+ session_start();
+ $_SESSION['bread_preview_settings'] = Bread::getOptions();
+ wp_redirect(home_url()."?preview-meeting-list=1");
+ exit();
+ }
set_transient('admin_notice', 'Please put down your weapon. You have 20 seconds to comply.');
if (!$this->admin->current_user_can_modify()) {
echo 'You do not have permission to save this configuation!
';
@@ -290,6 +299,7 @@ function admin_options_page()
admin->current_user_can_modify()) {?>
+
Generate Meeting List
Save Changes before Generate Meeting List.
diff --git a/includes/class-bread.php b/includes/class-bread.php
index 1c70862..cdac30c 100644
--- a/includes/class-bread.php
+++ b/includes/class-bread.php
@@ -146,9 +146,15 @@ private static function rrmdir($dir)
@rmdir($dir);
}
}
- private function loadAllSettings()
+ private function loadAllSettings($holder): int
{
- $this->allSettings = get_option(Bread::SETTINGS);
+ if (isset($holder['bread_preview_settings'])) {
+ $this->allSettings = array();
+ $this->allSettings[0] = $holder['bread_preview_settings'];
+ $this->allSettings[1] = "Preview Setting";
+ } else {
+ $this->allSettings = get_option(Bread::SETTINGS);
+ }
if ($this->allSettings === false) {
$this->allSettings = array();
$this->allSettings[1] = "Default Setting";
@@ -160,6 +166,7 @@ private function loadAllSettings()
}
}
}
+ return isset($holder['current-meeting-list']) ? intval($holder['current-meeting-list']) : 1;
}
public static function renameSetting($id, $name)
{
@@ -182,9 +189,15 @@ public static function deleteSetting($id)
private function getCurrentMeetingListHolder()
{
$ret = array();
+ if (isset(($_REQUEST['preview-meeting-list']))) {
+ session_start();
+ $ret['bread_preview_settings'] = $_SESSION['bread_preview_settings'];
+ $ret['current-meeting-list'] = 1;
+ // TODO check that the value is equal to some security option we've set, otherwise reject.
+ }
if (isset($_REQUEST['current-meeting-list'])) {
$ret['current-meeting-list'] = $_REQUEST['current-meeting-list'];
- } else if (isset($_COOKIE['current-meeting-list'])) {
+ } elseif (isset($_COOKIE['current-meeting-list'])) {
$ret['current-meeting-list'] = $_COOKIE['current-meeting-list'];
}
return $ret;
@@ -209,30 +222,38 @@ private function &getMLOptionsInner($current_setting)
if ($current_setting < 1) {
$current_setting = is_admin() ? 1 : $this->requested_setting;
}
-
- if ($current_setting != 1) {
- $this->optionsName = $this->generateOptionName($current_setting);
+ if (is_array($this->allSettings[$current_setting])) {
+ $this->options = $this->allSettings[$current_setting];
} else {
- $this->optionsName = Bread::OPTIONS_NAME;
- }
- //Don't forget to set up the default options
- if (!$theOptions = get_option($this->optionsName)) {
if ($current_setting != 1) {
- unset($this->allSettings[$current_setting]);
- update_option(Bread::SETTINGS, $this->allSettings);
- die('Undefined setting: ' . $current_setting);
+ $this->optionsName = $this->generateOptionName($current_setting);
+ } else {
+ $this->optionsName = Bread::OPTIONS_NAME;
+ }
+ //Don't forget to set up the default options
+ if (!$theOptions = get_option($this->optionsName)) {
+ if ($current_setting != 1) {
+ unset($this->allSettings[$current_setting]);
+ update_option(Bread::SETTINGS, $this->allSettings);
+ die('Undefined setting: ' . $current_setting);
+ }
+ $import_file = plugin_dir_path(__FILE__) . "includes/three_column_settings.json";
+ $encode_options = file_get_contents($import_file);
+ $theOptions = json_decode($encode_options, true);
+ update_option($this->optionsName, $theOptions);
}
- $import_file = plugin_dir_path(__FILE__) . "includes/three_column_settings.json";
- $encode_options = file_get_contents($import_file);
- $theOptions = json_decode($encode_options, true);
- update_option($this->optionsName, $theOptions);
+ $this->options = $theOptions;
+ $this->fillUnsetOptions();
+ $this->upgrade_settings();
}
- $this->options = $theOptions;
- $this->fillUnsetOptions();
- $this->upgrade_settings();
+
$this->requested_setting = $current_setting;
return $this->options;
}
+ public static function getOptions()
+ {
+ return Bread::$instance->options;
+ }
public static function getOptionsName()
{
return Bread::$instance->optionsName;
@@ -270,10 +291,9 @@ public function __construct()
$this->tmp_dir = $this->setup_temp_dir();
$this->protocol = (strpos(strtolower(home_url()), "https") !== false ? "https" : "http") . "://";
- $this->loadAllSettings();
$holder = $this->getCurrentMeetingListHolder();
+ $this->requested_setting = $this->loadAllSettings($holder);
- $this->requested_setting = isset($holder['current-meeting-list']) ? intval($holder['current-meeting-list']) : 1;
$this->load_dependencies();
$this->set_locale();
$this->load_translations();
diff --git a/public/class-bread-public.php b/public/class-bread-public.php
index ebc0471..668a758 100644
--- a/public/class-bread-public.php
+++ b/public/class-bread-public.php
@@ -245,6 +245,7 @@ public function bmlt_meeting_list($atts = null, $content = null)
}
private function constuct_page_type_settings()
{
+ $page_type_settings = array();
// TODO: The page number is always 5 from botton...this should be adjustable
if ($this->options['page_fold'] == 'half') {
if ($this->options['page_size'] == 'letter') {