Skip to content

Commit

Permalink
first working preview button
Browse files Browse the repository at this point in the history
  • Loading branch information
otrok7 committed Nov 16, 2024
1 parent 67aa8e9 commit b26c388
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 23 deletions.
1 change: 1 addition & 0 deletions admin/partials/_backup_restore_setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@
</div>
</div>
<br class="clear">
<p style="display: inline; margin-top:.5em;margin-bottom:1.0em;margin-left:.2em;"><a target="_blank" class="button-primary" href="<?php echo home_url();?>/?current-meeting-list=<?php echo $this->admin->loaded_setting;?>">Generate Meeting List</a></p>
</div>
12 changes: 11 additions & 1 deletion admin/partials/bread-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down Expand Up @@ -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 '<div class="updated"><p style="color: #F00;">You do not have permission to save this configuation!</p>';
Expand Down Expand Up @@ -290,6 +299,7 @@ function admin_options_page()
</div>
<?php if ($this->admin->current_user_can_modify()) {?>
<input type="submit" value="Save Changes" id="bmltmeetinglistsave1" name="bmltmeetinglistsave" class="button-primary" />
<input type="submit" value="Preview" id="bmltmeetinglistpreview" name="bmltmeetinglistpreview" class="button-primary" formtarget="_blank" />
<p style="display: inline; margin-top:.5em;margin-bottom:1.0em;margin-left:.2em;"><a target="_blank" class="button-primary" href="<?php echo home_url();?>/?current-meeting-list=' . $this->admin->loaded_setting . '">Generate Meeting List</a></p>
<div style="display:inline;"><i>&nbsp;&nbsp;Save Changes before Generate Meeting List.</i></div>
<br class="clear">
Expand Down
64 changes: 42 additions & 22 deletions includes/class-bread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions public/class-bread-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit b26c388

Please sign in to comment.