diff --git a/admin/class-bread-admin.php b/admin/class-bread-admin.php index 6da5317..a30eb17 100644 --- a/admin/class-bread-admin.php +++ b/admin/class-bread-admin.php @@ -52,13 +52,18 @@ class Bread_Admin var $maxSetting = 1; var $loaded_setting = 1; var $bmltEnabled_admin; - public function __construct($plugin_name, $version, $bmltEnabled_admin) + private Bread $bread; + public function __construct($plugin_name, $version, $bmltEnabled_admin, $bread) { $this->plugin_name = $plugin_name; $this->version = $version; $this->bmltEnabled_admin = $bmltEnabled_admin; + $this->bread = $bread; + } + public function get_bread_instance(): Bread + { + return $this->bread; } - /** * Register the stylesheets for the admin area. * @@ -168,14 +173,14 @@ function is_root_server_missing() global $my_admin_page; $screen = get_current_screen(); if ($screen->id == $my_admin_page) { - $root_server = Bread::getOption('root_server'); + $root_server = $this->bread->getOption('root_server'); if ($root_server == '') { echo '

Missing BMLT Server in settings for bread.

'; $url = admin_url('options-general.php?page=class-bread-admin.php'); echo "

Settings

"; echo '
'; - } else if (!Bread::temp_dir()) { - echo '

' . Bread::temp_dir() . ' temporary directory is not writable.

'; + } else if (!$this->bread->temp_dir()) { + echo '

' . $this->bread->temp_dir() . ' temporary directory is not writable.

'; $url = admin_url('options-general.php?page=class-bread-admin.php'); echo "

Settings

"; echo '
'; @@ -185,7 +190,6 @@ function is_root_server_missing() function pwsix_process_rename_settings() { - Bread::getMLOptions(Bread::getRequestedSetting()); if (isset($_POST['bmltmeetinglistsave']) && $_POST['bmltmeetinglistsave'] == 'Save Changes') { return; } @@ -198,15 +202,14 @@ function pwsix_process_rename_settings() if (! $this->current_user_can_modify()) { return; } - - Bread::renameSetting($this->loaded_setting, sanitize_text_field($_POST['setting_descr'])); + $this->bread->getMLOptions($this->bread->getRequestedSetting()); + $this->bread->renameSetting($this->loaded_setting, sanitize_text_field($_POST['setting_descr'])); } /** * Process a settings export that generates a .json file of the shop settings */ function pwsix_process_settings_export() { - Bread::getMLOptions(Bread::getRequestedSetting()); if (isset($_POST['bmltmeetinglistsave']) && $_POST['bmltmeetinglistsave'] == 'Save Changes') { return; } @@ -219,13 +222,13 @@ function pwsix_process_settings_export() if (! current_user_can('manage_bread')) { // TODO: Is this necessary? Why not let the user make a copy return; } - - $blogname = str_replace(" - ", " ", get_option('blogname').'-'.Bread::getSettingName($this->loaded_setting)); + $this->bread->getMLOptions($this->bread->getRequestedSetting()); + $blogname = str_replace(" - ", " ", get_option('blogname').'-'.$this->bread->getSettingName($this->loaded_setting)); $blogname = str_replace(" ", "-", $blogname); $date = date("m-d-Y"); $blogname = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($blogname)), '-'); $json_name = $blogname.$date.".json"; // Naming the filename will be generated. - $settings = get_option(Bread::getOptionsName()); + $settings = get_option($this->bread->getOptionsName()); foreach ($settings as $key => $value) { $value = maybe_unserialize($value); $need_options[$key] = $value; @@ -247,7 +250,7 @@ function current_user_can_modify() if (in_array('administrator', $user->roles)) { return true; } - $authors_safe = Bread::getOption('authors'); + $authors_safe = $this->bread->getOption('authors'); if (!is_array($authors_safe) || empty($authors_safe)) { return true; } @@ -268,7 +271,6 @@ function current_user_can_create() */ function pwsix_process_settings_import() { - Bread::getMLOptions(Bread::getRequestedSetting()); if (isset($_POST['bmltmeetinglistsave']) && $_POST['bmltmeetinglistsave'] == 'Save Changes') { return; } @@ -281,6 +283,7 @@ function pwsix_process_settings_import() if (! current_user_can('manage_bread')) { return; } + $this->bread->getMLOptions($this->bread->getRequestedSetting()); $file_name = $_FILES['import_file']['name']; $tmp = explode('.', $file_name); $extension = end($tmp); @@ -301,51 +304,11 @@ function pwsix_process_settings_import() } $settings = json_decode($encode_options, true); $settings['authors'] = array(wp_get_current_user()->ID); - update_option(Bread::getOptionsName(), $settings); + update_option($this->bread->getOptionsName(), $settings); setcookie('pwsix_action', "import_settings", time()+10); setcookie('current-meeting-list', $this->loaded_setting, time()+10); wp_safe_redirect(admin_url('?page=class-bread-admin.php')); } - - /** - * Process a default settings - */ - function pwsix_process_default_settings() - { - Bread::getMLOptions(Bread::getRequestedSetting()); - if (! current_user_can('manage_bread') - || (isset($_POST['bmltmeetinglistsave']) && $_POST['bmltmeetinglistsave'] == 'Save Changes' ) - ) { - return; - } elseif (isset($_REQUEST['pwsix_action']) && 'three_column_default_settings' == $_REQUEST['pwsix_action']) { - if (! wp_verify_nonce($_POST['pwsix_submit_three_column'], 'pwsix_submit_three_column')) { - die('Whoops! There was a problem with the data you posted. Please go back and try again.'); - } - $import_file = plugin_dir_path(__FILE__) . "includes/three_column_settings.json"; - } elseif (isset($_REQUEST['pwsix_action']) && 'four_column_default_settings' == $_REQUEST['pwsix_action']) { - if (! wp_verify_nonce($_POST['pwsix_submit_four_column'], 'pwsix_submit_four_column')) { - die('Whoops! There was a problem with the data you posted. Please go back and try again.'); - } - $import_file = plugin_dir_path(__FILE__) . "includes/four_column_settings.json"; - } elseif (isset($_REQUEST['pwsix_action']) && 'booklet_default_settings' == $_REQUEST['pwsix_action']) { - if (! wp_verify_nonce($_POST['pwsix_submit_booklet'], 'pwsix_submit_booklet')) { - die('Whoops! There was a problem with the data you posted. Please go back and try again.'); - } - $import_file = plugin_dir_path(__FILE__) . "includes/booklet_settings.json"; - } else { - return; - } - if (empty($import_file)) { - wp_die(__('Error importing default settings file')); - } - $encode_options = file_get_contents($import_file); - $settings = json_decode($encode_options, true); - $settings['authors'] = Bread::getOption('authors'); - update_option(Bread::getOptionsName(), $settings); - setcookie('pwsix_action', "default_settings_success", time()+10); - setcookie('current-meeting-list', $this->loaded_setting, time()+10); - wp_safe_redirect(admin_url('?page=class-bread-admin.php')); - } function my_theme_add_editor_styles() { global $my_admin_page; @@ -368,7 +331,7 @@ function filter_plugin_actions($links, $file) */ function save_admin_options() { - Bread::updateOptions(); + $this->bread->updateOptions(); } public function getLatestRootVersion() { @@ -389,13 +352,13 @@ function get($url, $cookies = array()) 'cookies' => $cookies, ); if (isset($this->options['user_agent']) - && Bread::getOption('user_agent') != 'None' + && $this->bread->getOption('user_agent') != 'None' ) { $args['headers'] = array( - 'User-Agent' => Bread::getOption('user_agent') + 'User-Agent' => $this->bread->getOption('user_agent') ); } - if (Bread::getOption('sslverify') == '1') { + if ($this->bread->getOption('sslverify') == '1') { $args['sslverify'] = false; } return wp_remote_get($url, $args); @@ -433,7 +396,6 @@ function admin_options_page() } function pwsix_process_settings_admin() { - Bread::getMLOptions(Bread::getRequestedSetting()); if (isset($_POST['bmltmeetinglistsave']) && $_POST['bmltmeetinglistsave'] == 'Save Changes') { return; } @@ -443,6 +405,7 @@ function pwsix_process_settings_admin() if (! wp_verify_nonce($_POST['pwsix_settings_admin_nonce'], 'pwsix_settings_admin_nonce')) { return; } + $this->bread->getMLOptions($this->bread->getRequestedSetting()); if (isset($_POST['delete'])) { if (!$this->current_user_can_modify()) { return; @@ -450,21 +413,21 @@ function pwsix_process_settings_admin() if ($this->loaded_setting == 1) { return; } - Bread::deleteSetting($this->loaded_setting); - Bread::getMLOptions(1); + $this->bread->deleteSetting($this->loaded_setting); + $this->bread->getMLOptions(1); $this->loaded_setting = 1; - Bread::setRequestedSetting(1); + $this->bread->setRequestedSetting(1); } elseif (isset($_POST['duplicate'])) { if (!$this->current_user_can_create()) { return; } $id = $this->maxSetting + 1; - Bread::setOptionsName(Bread::generateOptionName($id)); - Bread::setOption('authors', array()); + $this->bread->setOptionsName($this->bread->generateOptionName($id)); + $this->bread->setOption('authors', array()); $this->save_admin_options(); - Bread::renameSetting($id, 'Setting '.$id); + $this->bread->renameSetting($id, 'Setting '.$id); $this->maxSetting = $id; - Bread::getMLOptions($id); + $this->bread->getMLOptions($id); } } } diff --git a/admin/js/bmlt_meeting_list.js b/admin/js/bmlt_meeting_list.js index eebeddc..9d6ae94 100644 --- a/admin/js/bmlt_meeting_list.js +++ b/admin/js/bmlt_meeting_list.js @@ -288,6 +288,7 @@ jQuery(document).ready( $ml('#landscape').prop("checked", true); $ml('.booklet').show(); $ml('.single-page').hide(); + $ml('#half').prop('checked') && $ml('.A6').hide(); } function singlePageControlsShowHide() { $ml('.booklet').hide(); diff --git a/admin/partials/_backup_restore_setup.php b/admin/partials/_backup_restore_setup.php index 45927da..98e0fd2 100644 --- a/admin/partials/_backup_restore_setup.php +++ b/admin/partials/_backup_restore_setup.php @@ -6,38 +6,41 @@
-

Configuration Manager

+

Configuration Manager

- -

+ +

Current Meeting List

-

Meeting List ID: admin->loaded_setting?> -

+

Meeting List ID: admin->loaded_setting ?> + +

-
Configuration Name: +
Configuration Name: -

- 1) {?> -

Configuration Selection

-
- - - -
- -
+

+ bread->getSettingNames()) > 1) { ?> +

Configuration Selection

+
+ + + + +
+ +
-

+

+

- admin->loaded_setting) {?> + admin->loaded_setting) { ?>
@@ -52,7 +55,7 @@

-

+

@@ -65,11 +68,11 @@

-

+

- - - 'submit_import_file' )); ?> + + + 'submit_import_file')); ?>

Your current meeting list settings will be replaced and lost forever.

@@ -84,5 +87,5 @@

-

Generate Meeting List

-
+

Generate Meeting List

+
\ No newline at end of file diff --git a/admin/partials/_bmlt_server_setup.php b/admin/partials/_bmlt_server_setup.php index 26de019..4679e18 100644 --- a/admin/partials/_bmlt_server_setup.php +++ b/admin/partials/_bmlt_server_setup.php @@ -19,77 +19,81 @@

- +

connected) { echo $this->server_version; - echo ''; - if (Bread::getOption('sslverify') == '1') { ?> + echo ''; + if ($this->bread->getOption('sslverify') == '1') { ?>

breademptyOption('root_server')) { echo "

ERROR: Please enter a BMLT Server"; - echo ''; - if (Bread::getOption('sslverify') == '1') { ?> + echo ''; + if ($this->bread->getOption('sslverify') == '1') { ?>

-

+ +

-
ERROR: Problem Connecting to BMLT Server
-
-

- - -

- /> - -

+
ERROR: Problem Connecting to BMLT Server
bread->bmlt()->$connection_error; ?> + +

+ + +

+

+ bread->getOption('sslverify') ? 'checked' : ''; ?> /> + +

-

- - - -

-
    select_service_bodies();?>
-
- /> Recurse Service Bodies -
+

+ + + +

+
    select_service_bodies(); ?>
+
+ bread->getOption('recurse_service_bodies') == 1 ? 'checked' : '') ?> /> Recurse Service Bodies +
-

- This will be executed as part of the meeting search query. This will override any setting in the Service Body dropdowns. -
You can get help formulating a query using your sites semantic interface.

+
+

+ This will be executed as part of the meeting search query. This will override any setting in the Service Body dropdowns. +
You can get help formulating a query using your sites semantic interface. +

Custom Query(?)

- +
-
+
-

Include Extra Meetings from Another Service Body.

-

All Meetings from your BMLT Server are shown in the list.

-

The Meetings you select will be merged into your meeting list.

-

Note: Be sure to select all meetings for each group.

+

Include Extra Meetings from Another Service Body.

+

All Meetings from your BMLT Server are shown in the list.

+

The Meetings you select will be merged into your meeting list.

+

Note: Be sure to select all meetings for each group.

Include Extra Meetings(?)

Hint: Type a group name, weekday or area to narrow down your choices.

- /> Extra Meetings Enabled + bread->emptyOption('extra_meetings_enabled') && $this->bread->getOption('extra_meetings_enabled') == 1 ? 'checked' : '') ?> /> Extra Meetings Enabled
@@ -123,7 +127,7 @@
@@ -138,7 +142,7 @@
  • -   0 - 999 Hours (0 = disable cache)   +   0 - 999 Hours (0 = disable cache)  

CACHE is DELETED when you Save Changes.

diff --git a/admin/partials/_custom_section_setup.php b/admin/partials/_custom_section_setup.php index f642b22..de9e4c9 100644 --- a/admin/partials/_custom_section_setup.php +++ b/admin/partials/_custom_section_setup.php @@ -8,17 +8,17 @@
-

The Custom Content can be customized with text, graphics, tables, shortcodes, ect.

-

Default Font Size can be changed for specific text in the editor.

-

Add Media button - upload and add graphics.

-

Meeting List Shortcodes dropdown - insert variable data.

-

The Custom Content will print immediately after the meetings in the meeting list.

+

The Custom Content can be customized with text, graphics, tables, shortcodes, ect.

+

Default Font Size can be changed for specific text in the editor.

+

Add Media button - upload and add graphics.

+

Meeting List Shortcodes dropdown - insert variable data.

+

The Custom Content will print immediately after the meetings in the meeting list.

Custom Section Content(?)

-

Default Font Size:    - Line Height:

+

Default Font Size:    + Line Height:

$editor_id, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,alignjustify,link,unlink,table,undo,redo,fullscreen', 'toolbar2' => 'formatselect,fontsizeselect,fontselect,forecolor,backcolor,indent,outdent,pastetext,removeformat,charmap,code', 'toolbar3' => 'front_page_button') ); - wp_editor(stripslashes(str_replace("http://", Bread::getProtocol(), Bread::getOption('custom_section_content'))), $editor_id, $settings); + wp_editor(stripslashes(str_replace("http://", $this->bread->getProtocol(), $this->bread->getOption('custom_section_content'))), $editor_id, $settings); ?>
diff --git a/admin/partials/_front_page_setup.php b/admin/partials/_front_page_setup.php index 5455645..866ee2c 100644 --- a/admin/partials/_front_page_setup.php +++ b/admin/partials/_front_page_setup.php @@ -16,8 +16,8 @@

Front Page Content(?)

-

Default Font Size:    - Line Height:

+

Default Font Size:    + Line Height:

$editor_id, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,alignjustify,link,unlink,table,undo,redo,fullscreen', 'toolbar2' => 'formatselect,fontsizeselect,fontselect,forecolor,backcolor,indent,outdent,pastetext,removeformat,charmap,code', 'toolbar3' => 'front_page_button') ); - wp_editor(stripslashes(str_replace("http://", Bread::getProtocol(), Bread::getOption('front_page_content'))), $editor_id, $settings); + wp_editor(stripslashes(str_replace("http://", $this->bread->getProtocol(), $this->bread->getOption('front_page_content'))), $editor_id, $settings); ?>
diff --git a/admin/partials/_layout_setup.php b/admin/partials/_layout_setup.php index 5ea9fa7..ec84152 100644 --- a/admin/partials/_layout_setup.php +++ b/admin/partials/_layout_setup.php @@ -7,83 +7,84 @@
- -

Page Layout Defaults

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Meeting List SizePage LayoutOrientationPaper SizePage Height
Smaller AreasTri-FoldLandscapeLetter, A4195, 180
Medium AreaQuad-FoldLandscapeLegal, A4195, 180
Large Area, Region, MetroHalf-FoldLandscapeBooklet, A5250, 260
AnythingFull PagePortrait, LandscapeLetter, Legal, A4None
-

When a layout is clicked defaults are reset for orientation, paper size and page height.

-
+ +

Page Layout Defaults

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Meeting List SizePage LayoutOrientationPaper SizePage Height
Smaller AreasTri-FoldLandscapeLetter, A4195, 180
Medium AreaQuad-FoldLandscapeLegal, A4195, 180
Large Area, Region, MetroHalf-FoldLandscapeBooklet, A5250, 260
AnythingFull PagePortrait, LandscapeLetter, Legal, A4None
+

When a layout is clicked defaults are reset for orientation, paper size and page height.

+
+

Page Layout(?)

- type="hidden"> + type="hidden">
-
Single Page
- > - > - > -
- > - > +
Single Page
+ bread->getOption('page_fold') == 'flyer' ? 'checked' : '') ?>> + bread->getOption('page_fold') == 'tri' ? 'checked' : '') ?>> + bread->getOption('page_fold') == 'quad' ? 'checked' : '') ?>> +
+ bread->getOption('page_orientation') == 'P' ? 'checked' : '') ?>> + bread->getOption('page_orientation') == 'L' ? 'checked' : '') ?>>
-
Booklets
- > - > -
- /> +
Booklets
+ bread->getOption('page_fold') == 'half' ? 'checked' : '') ?>> + bread->getOption('page_fold') == 'full' ? 'checked' : '') ?>> +
+ bread->getOption('booklet_pages') == '1' ? 'checked' : '') ?> />
-
+
- Page Size:
- > - > - > - > - > - > - > + Page Size:
+ bread->getOption('page_size') == '5inch' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'letter' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'legal' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'ledger' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'A4' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'A5' ? 'checked' : '') ?>> + bread->getOption('page_size') == 'A6' ? 'checked' : '') ?>>
- Page Margin Top:     - Bottom:     - Left:     - Right:     + Page Margin Top:     + Bottom:     + Left:     + Right:    
@@ -94,40 +95,42 @@
-

- Describes things on the page other than the contents. Headers, footers, page numbers. -
What options you see will be dependant on the layout selected.

+
+

+ Describes things on the page other than the contents. Headers, footers, page numbers. +
What options you see will be dependant on the layout selected. +

Page Decorations(?)

- The page header is a title that goes across the entire page above the meetings.
- - - - Header Margin Top:     -
Header Text:     -
Watermark:     + The page header is a title that goes across the entire page above the meetings.
+ + + + Header Margin Top:     +
Header Text:     +
Watermark:    
- - -
- - + + +
+ +
- Page Numbers Font Size: + Page Numbers Font Size:
- Column Gap Width: + Column Gap Width:
- - Separator: /> - + + Separator: bread->getOption('column_line') == '1' ? 'checked' : '') ?> /> +
@@ -141,20 +144,20 @@
- - - - + + + +
@@ -176,13 +179,13 @@
- >Enable Protection + bread->getOption('include_protection') == '1' ? 'checked' : '') ?>>Enable Protection
- +
diff --git a/admin/partials/_meeting_list_setup.php b/admin/partials/_meeting_list_setup.php index 7fc696e..795fd98 100644 --- a/admin/partials/_meeting_list_setup.php +++ b/admin/partials/_meeting_list_setup.php @@ -15,21 +15,21 @@

Read This Section First

Getting Started

-

bread is first activated using a "Tri Fold - Landscape - Letter Size" layout. This is a "starter" meeting list that uses an Area with about 100 meetings. The starter meeting list will contain standard content for a basic meeting list that can be printed on a home computer. A basic NA logo will be added to your media libray. The starter meeting list uses a logo being hosted on https://nameetinglist.org.

+

bread is first activated using a "Tri Fold - Landscape - Letter Size" layout. This is a "starter" meeting list that uses an Area with about 100 meetings. The starter meeting list will contain standard content for a basic meeting list that can be printed on a home computer. A basic NA logo will be added to your media libray. The starter meeting list uses a logo being hosted on https://nameetinglist.org.

Step 1.

-

Click on the BMLT Server tab to the left. Change the BMLT Server and click the Save Changes button.

+

Click on the BMLT Server tab to the left. Change the BMLT Server and click the Save Changes button.

To find your BMLT Server click on the red question (?) mark.

Step 2.

-

From the Service Body 1 dropdown select your Area or Region. Then click Save Changes.

+

From the Service Body 1 dropdown select your Area or Region. Then click Save Changes.

Step 3.

-

Click Generate Meeting List. Your meeting list will open in a new tab or window.

+

Click Generate Meeting List. Your meeting list will open in a new tab or window.

Step 4.

See the "Meeting List Setup" section below for additional defaults.

Repeat steps 1, 2 and 3 after changing to new Default Settings.

What Now?

-

From here you will move forward with setting up your meeting list by exploring the Page Layout, Front Page, Custom Section, Meetings, etc tabs. There are countless ways to setup a meeting list.

-

Please allow yourself to experiment with mixing and matching different settings and content. There is a good chance you can find a way to match or at least come very close to your current meeting list.

-

When setting up the meeting list it is helpful to have some knowledge of HTML when using the editors. Very little or no knowledge of HTML is required to maintain the meeting list after the setup. If you get stuck or would like some help with the setup, read the Support section below.

+

From here you will move forward with setting up your meeting list by exploring the Page Layout, Front Page, Custom Section, Meetings, etc tabs. There are countless ways to setup a meeting list.

+

Please allow yourself to experiment with mixing and matching different settings and content. There is a good chance you can find a way to match or at least come very close to your current meeting list.

+

When setting up the meeting list it is helpful to have some knowledge of HTML when using the editors. Very little or no knowledge of HTML is required to maintain the meeting list after the setup. If you get stuck or would like some help with the setup, read the Support section below.

Meeting List Setup

@@ -41,7 +41,7 @@

Small or Medium Size Areas

-

Areas with up to about 100 meetings would benefit from using the tri-fold layout on letter sized paper. Areas larger than 100 meetings would typically use a quad fold meeting list on legal sized paper. These are just basic guidelines and are by no means set in stone. For example, an Area with over 100 meetings could use the tri-fold on letter sized paper using smaller fonts to allow the content to fit. The meeting list configuration is extremely flexible.

+

Areas with up to about 100 meetings would benefit from using the tri-fold layout on letter sized paper. Areas larger than 100 meetings would typically use a quad fold meeting list on legal sized paper. These are just basic guidelines and are by no means set in stone. For example, an Area with over 100 meetings could use the tri-fold on letter sized paper using smaller fonts to allow the content to fit. The meeting list configuration is extremely flexible.

The Custom Content section is used to add information like helplines, service meetings, meeting format legend, etc.

Large Areas, Metro Areas or Regions

Larger service bodies would benefit from using a booklet meeting list.

@@ -51,9 +51,9 @@

Multiple Meeting Lists

This tool supports multiple meeting lists per site.

-

This feature is configured from the Configuration Tab. There, each concurrent meeting list can be given a - name, and the system gives the meeting list a numberic identifier. The meeting list can then be generated using

- a link of the form http://[host]?current-meeting-list=[id]

+

This feature is configured from the Configuration Tab. There, each concurrent meeting list can be given a + name, and the system gives the meeting list a numberic identifier. The meeting list can then be generated using

+ a link of the form http://[host]?current-meeting-list=[id]

After switching to another concurrent meeting list, any changes in the admin UI impact the currently selected meeting list

If you want to give another user access to bread you can give that use the "manage_bread" capability using a custom role editor.

@@ -61,7 +61,7 @@

You can dynamically set some of the options to create a reusable template.

In order to change the meeting information you can pass a dynamic custom query using &custom_query=, ensure you are using URL encoding.

-

You can also use any combinations of [querystring_custom_*], where * is any digit. You can then override that specific value using it in querystring as &querystring_custom_1= (for instance).

+

You can also use any combinations of [querystring_custom_*], where * is any digit. You can then override that specific value using it in querystring as &querystring_custom_1= (for instance).

You can use any HTML characters, including line breaks.

Here is a video of it in action: https://bmlt.app/reusable-templates-with-bread-1-6-x/

@@ -70,15 +70,15 @@

File an issue https://github.com/bmlt-enabled/bread/issues

Debug Information
    -
  • Bread Version:
  • -
  • Wordpress Version:
  • -
  • Protocol:
  • -
  • PHP Version:
  • -
  • Server Version:
  • -
  • Temporary Directory:
  • +
  • Bread Version:
  • +
  • Wordpress Version:
  • +
  • Protocol: bread->getProtocol(); ?>
  • +
  • PHP Version:
  • +
  • Server Version:
  • +
  • Temporary Directory:

-
+
\ No newline at end of file diff --git a/admin/partials/_meetings_setup.php b/admin/partials/_meetings_setup.php index 8fca326..fd8da41 100644 --- a/admin/partials/_meetings_setup.php +++ b/admin/partials/_meetings_setup.php @@ -8,37 +8,37 @@
-

Customize the Meeting Group Header to your specification.

-

The Meeting Group Header will contain the data from Group By.

+

Customize the Meeting Group Header to your specification.

+

The Meeting Group Header will contain the data from Group By.

Meeting Group [Column] Header(?)

- > + bread->getOption('suppress_heading') == '1' ? 'checked' : '') ?>> - + + + +
Font Size: Font Size:
- +
- +
- >bread->getOption('header_uppercase') == '1' ? 'checked' : '') ?>> - >bread->getOption('header_bold') == '1' ? 'checked' : '') ?>> - >bread->getOption('cont_header_shown') == '1' ? 'checked' : '') ?>>
@@ -46,25 +46,25 @@

- +

@@ -73,7 +73,7 @@

- +

@@ -82,7 +82,7 @@

- +

@@ -91,7 +91,7 @@

- +

@@ -99,18 +99,18 @@

- - - @@ -159,8 +159,8 @@ " . Bread::getday($d, false, Bread::getOption('weekday_language')) . ""; + if ($this->bread->getOption('weekday_start') == $d || $this->bread->getOption('weekday_start') == '') { + echo ""; } else { - echo ""; + echo ""; } } ?> @@ -186,7 +186,7 @@

@@ -195,9 +195,9 @@

The Meeting Template is a powerful and flexible method for customizing meetings using - HTML markup and BMLT field names. The template is set-up once and never needs to be messed - with again. Note: When changes are made to the Default Font Size or Line Height, the template - may need to be adjusted to reflect those changes.

+ HTML markup and BMLT field names. The template is set-up once and never needs to be messed + with again. Note: When changes are made to the Default Font Size or Line Height, the template + may need to be adjusted to reflect those changes.

Sample templates can be found in the editor drop down menu Meeting Template.

BMLT fields can be found in the editor drop down menu Meeting Template Fields.

The Default Font Size and Line Height will be used for the meeting template.

@@ -208,9 +208,9 @@

Meeting Template(?)

- Default Font Size:    - Line Height:    - Wheelchair Icon Size:    + Default Font Size:    + Line Height:    + Wheelchair Icon Size:   

Avoid using tables which will greatly slow down the generation time. Use CSS instead to get table-like effects if need be.
$editor_id, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,alignjustify,link,unlink,table,undo,redo,fullscreen', 'toolbar2' => 'formatselect,fontsizeselect,fontselect,forecolor,backcolor,indent,outdent,pastetext,removeformat,charmap,code', 'toolbar3' => 'custom_template_button_1,custom_template_button_2') ); - wp_editor(stripslashes(Bread::getOption('meeting_template_content')), $editor_id, $settings); + wp_editor(stripslashes($this->bread->getOption('meeting_template_content')), $editor_id, $settings); ?>
@@ -239,34 +239,34 @@ @@ -282,10 +282,10 @@ connected) { echo ''; - $used_formats = Bread_Bmlt::getFormatsForSelect(false); + $used_formats = $this->bread->bmlt()->getFormatsForSelect(false); foreach ($used_formats as $format) { $selected = ''; - if ($format['id'] == Bread::getOption('used_format_1')) { + if ($format['id'] == $this->bread->getOption('used_format_1')) { $selected = 'selected="selected"'; } $id = $format['id']; @@ -310,12 +310,12 @@ - - - + + +

- bread->getOption('page_fold') == 'half' || $this->bread->getOption('page_fold') == 'full') { ?>

- +

-

>Include meetings with this format in the main list

+

bread->getOption('include_additional_list') == '1' ? 'checked' : '') ?>>Include meetings with this format in the main list

If you wish to define different contents for the additional list, use this template.
$editor_id, 'tinymce' => array('toolbar1' => 'bold,italic,underline,strikethrough,bullist,numlist,alignleft,aligncenter,alignright,alignjustify,link,unlink,table,undo,redo,fullscreen', 'toolbar2' => 'formatselect,fontsizeselect,fontselect,forecolor,backcolor,indent,outdent,pastetext,removeformat,charmap,code', 'toolbar3' => 'custom_template_button_1,custom_template_button_2') ); - wp_editor(stripslashes(Bread::getOption('additional_list_template_content')), $editor_id, $settings); + wp_editor(stripslashes($this->bread->getOption('additional_list_template_content')), $editor_id, $settings); ?>
diff --git a/admin/partials/bread-admin-display.php b/admin/partials/bread-admin-display.php index 32eb427..a8e9d15 100644 --- a/admin/partials/bread-admin-display.php +++ b/admin/partials/bread-admin-display.php @@ -14,22 +14,24 @@ class Bread_AdminDisplay { private $lang; - private $admin; + private Bread_Admin $admin; private $connected; private $server_version; + private Bread $bread; private array $unique_areas; function __construct($admin) { $this->admin = $admin; + $this->bread = $admin->get_bread_instance(); $this->refresh_status(); } private function refresh_status() { - $serverInfo = Bread_Bmlt::testRootServer(); + $serverInfo = $this->bread->bmlt()->testRootServer(); $this->connected = is_array($serverInfo) && array_key_exists("version", $serverInfo[0]) ? $serverInfo[0]["version"] : ''; if ($this->connected) { - $this->unique_areas = Bread_Bmlt::get_areas(); + $this->unique_areas = $this->bread->bmlt()->get_areas(); asort($this->unique_areas); if ($serverInfo[0]["aggregator_mode_enabled"] ?? false) { $this->server_version = "
Using Tomato Server
"; @@ -40,43 +42,46 @@ private function refresh_status() } private function select_service_bodies() { - for ($i=1; $i<=5; $i++) {?> -
  • -
  • +
  • + +
  • - unique_areas as $area) { - $area_data = explode(',', $area); - $area_name = Bread::arraySafeGet($area_data); - $area_id = Bread::arraySafeGet($area_data, 1); - $area_parent = Bread::arraySafeGet($area_data, 2); - $area_parent_name = Bread::arraySafeGet($area_data, 3); - $descr = $area_name . " (" . $area_id . ") " . $area_parent_name . " (" . $area_parent . ")"; - $selected = ''; - $sb = esc_html(Bread::getOption("service_body_$i")); - $area_selected = explode(',', $sb); - if (Bread::arraySafeGet($area_selected) != "Not Used" && $area_id == Bread::arraySafeGet($area_selected, 1)) { - $selected = 'selected = "selected"'; - } ?> - Not Used + unique_areas as $area) { + $area_data = explode(',', $area); + $area_name = $this->bread->arraySafeGet($area_data); + $area_id = $this->bread->arraySafeGet($area_data, 1); + $area_parent = $this->bread->arraySafeGet($area_data, 2); + $area_parent_name = $this->bread->arraySafeGet($area_data, 3); + $descr = $area_name . " (" . $area_id . ") " . $area_parent_name . " (" . $area_parent . ")"; + $selected = ''; + $sb = esc_html($this->bread->getOption("service_body_$i")); + $area_selected = explode(',', $sb); + if ($this->bread->arraySafeGet($area_selected) != "Not Used" && $area_id == $this->bread->arraySafeGet($area_selected, 1)) { + $selected = 'selected = "selected"'; + } ?> + lang = Bread_bmlt::get_bmlt_server_lang(); + $this->bread->getMLOptions($this->bread->getRequestedSetting()); + $this->lang = $this->bread->bmlt()->get_bmlt_server_lang(); ?>
    @@ -91,140 +96,140 @@ function admin_options_page() 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.'); } - Bread::setOption('bread_version', sanitize_text_field($_POST['bread_version'])); - Bread::setOption('front_page_content', wp_kses_post($_POST['front_page_content'])); - Bread::setOption('front_page_line_height', $_POST['front_page_line_height']); - Bread::setOption('front_page_font_size', floatval($_POST['front_page_font_size'])); - Bread::setOption('content_font_size', floatval($_POST['content_font_size'])); - Bread::setOption('suppress_heading', floatval($_POST['suppress_heading'])); - Bread::setOption('header_font_size', floatval($_POST['header_font_size'])); - Bread::setOption('header_text_color', sanitize_hex_color($_POST['header_text_color'])); - Bread::setOption('header_background_color', sanitize_hex_color($_POST['header_background_color'])); - Bread::setOption('header_uppercase', intval($_POST['header_uppercase'])); - Bread::setOption('header_bold', intval($_POST['header_bold'])); - Bread::setOption('sub_header_shown', sanitize_text_field($_POST['sub_header_shown'])); - Bread::setOption('cont_header_shown', intval($_POST['cont_header_shown'])); - Bread::setOption( + $this->bread->setOption('bread_version', sanitize_text_field($_POST['bread_version'])); + $this->bread->setOption('front_page_content', wp_kses_post($_POST['front_page_content'])); + $this->bread->setOption('front_page_line_height', $_POST['front_page_line_height']); + $this->bread->setOption('front_page_font_size', floatval($_POST['front_page_font_size'])); + $this->bread->setOption('content_font_size', floatval($_POST['content_font_size'])); + $this->bread->setOption('suppress_heading', floatval($_POST['suppress_heading'])); + $this->bread->setOption('header_font_size', floatval($_POST['header_font_size'])); + $this->bread->setOption('header_text_color', sanitize_hex_color($_POST['header_text_color'])); + $this->bread->setOption('header_background_color', sanitize_hex_color($_POST['header_background_color'])); + $this->bread->setOption('header_uppercase', intval($_POST['header_uppercase'])); + $this->bread->setOption('header_bold', intval($_POST['header_bold'])); + $this->bread->setOption('sub_header_shown', sanitize_text_field($_POST['sub_header_shown'])); + $this->bread->setOption('cont_header_shown', intval($_POST['cont_header_shown'])); + $this->bread->setOption( 'column_gap', isset($_POST['column_gap']) ? intval($_POST['column_gap']) : 5 ); - Bread::setOption('margin_right', intval($_POST['margin_right'])); - Bread::setOption('margin_left', intval($_POST['margin_left'])); - Bread::setOption('margin_bottom', intval($_POST['margin_bottom'])); - Bread::setOption('margin_top', intval($_POST['margin_top'])); - Bread::setOption('margin_header', intval($_POST['margin_header'])); - Bread::setOption( + $this->bread->setOption('margin_right', intval($_POST['margin_right'])); + $this->bread->setOption('margin_left', intval($_POST['margin_left'])); + $this->bread->setOption('margin_bottom', intval($_POST['margin_bottom'])); + $this->bread->setOption('margin_top', intval($_POST['margin_top'])); + $this->bread->setOption('margin_header', intval($_POST['margin_header'])); + $this->bread->setOption( 'margin_footer', isset($_POST['margin_footer']) ? intval($_POST['margin_footer']) : 5 ); - Bread::setOption('pageheader_fontsize', floatval($_POST['pageheader_fontsize'])); - Bread::setOption('pageheader_textcolor', sanitize_hex_color($_POST['pageheader_textcolor'])); - Bread::setOption('pageheader_backgroundcolor', sanitize_hex_color($_POST['pageheader_backgroundcolor'])); - Bread::setOption('pageheader_content', wp_kses_post($_POST['pageheader_content'])); - Bread::setOption('watermark', sanitize_text_field($_POST['watermark'])); - Bread::setOption('page_size', sanitize_text_field($_POST['page_size'])); - Bread::setOption('page_orientation', sanitize_text_field($_POST['page_orientation'])); - Bread::setOption('page_fold', sanitize_text_field($_POST['page_fold'])); - Bread::setOption( + $this->bread->setOption('pageheader_fontsize', floatval($_POST['pageheader_fontsize'])); + $this->bread->setOption('pageheader_textcolor', sanitize_hex_color($_POST['pageheader_textcolor'])); + $this->bread->setOption('pageheader_backgroundcolor', sanitize_hex_color($_POST['pageheader_backgroundcolor'])); + $this->bread->setOption('pageheader_content', wp_kses_post($_POST['pageheader_content'])); + $this->bread->setOption('watermark', sanitize_text_field($_POST['watermark'])); + $this->bread->setOption('page_size', sanitize_text_field($_POST['page_size'])); + $this->bread->setOption('page_orientation', sanitize_text_field($_POST['page_orientation'])); + $this->bread->setOption('page_fold', sanitize_text_field($_POST['page_fold'])); + $this->bread->setOption( 'booklet_pages', isset($_POST['booklet_pages']) ? boolval($_POST['booklet_pages']) : false ); - Bread::setOption('meeting_sort', sanitize_text_field($_POST['meeting_sort'])); - Bread::setOption('main_grouping', sanitize_text_field($_POST['main_grouping'])); - Bread::setOption('subgrouping', sanitize_text_field($_POST['subgrouping'])); - Bread::setOption('borough_suffix', sanitize_text_field($_POST['borough_suffix'])); - Bread::setOption('county_suffix', sanitize_text_field($_POST['county_suffix'])); - Bread::setOption('neighborhood_suffix', sanitize_text_field($_POST['neighborhood_suffix'])); - Bread::setOption('city_suffix', sanitize_text_field($_POST['city_suffix'])); - Bread::setOption('meeting_template_content', wp_kses_post($_POST['meeting_template_content'])); - Bread::setOption('additional_list_template_content', wp_kses_post($_POST['additional_list_template_content'])); - Bread::setOption( + $this->bread->setOption('meeting_sort', sanitize_text_field($_POST['meeting_sort'])); + $this->bread->setOption('main_grouping', sanitize_text_field($_POST['main_grouping'])); + $this->bread->setOption('subgrouping', sanitize_text_field($_POST['subgrouping'])); + $this->bread->setOption('borough_suffix', sanitize_text_field($_POST['borough_suffix'])); + $this->bread->setOption('county_suffix', sanitize_text_field($_POST['county_suffix'])); + $this->bread->setOption('neighborhood_suffix', sanitize_text_field($_POST['neighborhood_suffix'])); + $this->bread->setOption('city_suffix', sanitize_text_field($_POST['city_suffix'])); + $this->bread->setOption('meeting_template_content', wp_kses_post($_POST['meeting_template_content'])); + $this->bread->setOption('additional_list_template_content', wp_kses_post($_POST['additional_list_template_content'])); + $this->bread->setOption( 'column_line', isset($_POST['column_line']) ? boolval($_POST['column_line']) : 0 ); - Bread::setOption( + $this->bread->setOption( 'col_color', isset($_POST['col_color']) ? sanitize_hex_color($_POST['col_color']) : '#bfbfbf' ); - Bread::setOption('custom_section_content', wp_kses_post($_POST['custom_section_content'])); - Bread::setOption('custom_section_line_height', floatval($_POST['custom_section_line_height'])); - Bread::setOption('custom_section_font_size', floatval($_POST['custom_section_font_size'])); - Bread::setOption( + $this->bread->setOption('custom_section_content', wp_kses_post($_POST['custom_section_content'])); + $this->bread->setOption('custom_section_line_height', floatval($_POST['custom_section_line_height'])); + $this->bread->setOption('custom_section_font_size', floatval($_POST['custom_section_font_size'])); + $this->bread->setOption( 'pagenumbering_font_size', isset($_POST['pagenumbering_font_size']) ? floatval($_POST['pagenumbering_font_size']) : '9' ); - Bread::setOption('used_format_1', sanitize_text_field($_POST['used_format_1'])); - Bread::setOption('recurse_service_bodies', isset($_POST['recurse_service_bodies']) ? 1 : 0); - Bread::setOption('extra_meetings_enabled', isset($_POST['extra_meetings_enabled']) ? intval($_POST['extra_meetings_enabled']) : 0); - Bread::setOption('include_protection', boolval($_POST['include_protection'])); - Bread::setOption('weekday_language', sanitize_text_field($_POST['weekday_language'])); - Bread::setOption('additional_list_language', sanitize_text_field($_POST['additional_list_language'])); - Bread::setOption('weekday_start', sanitize_text_field($_POST['weekday_start'])); - Bread::setOption( + $this->bread->setOption('used_format_1', sanitize_text_field($_POST['used_format_1'])); + $this->bread->setOption('recurse_service_bodies', isset($_POST['recurse_service_bodies']) ? 1 : 0); + $this->bread->setOption('extra_meetings_enabled', isset($_POST['extra_meetings_enabled']) ? intval($_POST['extra_meetings_enabled']) : 0); + $this->bread->setOption('include_protection', boolval($_POST['include_protection'])); + $this->bread->setOption('weekday_language', sanitize_text_field($_POST['weekday_language'])); + $this->bread->setOption('additional_list_language', sanitize_text_field($_POST['additional_list_language'])); + $this->bread->setOption('weekday_start', sanitize_text_field($_POST['weekday_start'])); + $this->bread->setOption( 'meeting1_footer', isset($_POST['meeting1_footer']) ? sanitize_text_field($_POST['meeting1_footer']) : '' ); - Bread::setOption( + $this->bread->setOption( 'meeting2_footer', isset($_POST['meeting2_footer']) ? sanitize_text_field($_POST['meeting2_footer']) : '' ); - Bread::setOption( + $this->bread->setOption( 'nonmeeting_footer', isset($_POST['nonmeeting_footer']) ? sanitize_text_field($_POST['nonmeeting_footer']) : '' ); - Bread::setOption('include_additional_list', boolval($_POST['include_additional_list'])); - Bread::setOption('additional_list_format_key', sanitize_text_field($_POST['additional_list_format_key'])); - Bread::setOption('additional_list_sort_order', sanitize_text_field($_POST['additional_list_sort_order'])); - Bread::setOption('base_font', sanitize_text_field($_POST['base_font'])); - Bread::setOption('colorspace', sanitize_text_field($_POST['colorspace'])); - Bread::setOption('wheelchair_size', sanitize_text_field($_POST['wheelchair_size'])); - Bread::setOption('protection_password', sanitize_text_field($_POST['protection_password'])); - Bread::setOption('time_clock', sanitize_text_field($_POST['time_clock'])); - Bread::setOption('time_option', intval($_POST['time_option'])); - Bread::setOption('remove_space', boolval($_POST['remove_space'])); - Bread::setOption('content_line_height', floatval($_POST['content_line_height'])); - Bread::setOption('root_server', sanitize_url($_POST['root_server'])); - Bread::setOption('service_body_1', sanitize_text_field($_POST['service_body_1'])); - Bread::setOption('service_body_2', sanitize_text_field($_POST['service_body_2'])); - Bread::setOption('service_body_3', sanitize_text_field($_POST['service_body_3'])); - Bread::setOption('service_body_4', sanitize_text_field($_POST['service_body_4'])); - Bread::setOption('service_body_5', sanitize_text_field($_POST['service_body_5'])); - Bread::setOption('cache_time', intval($_POST['cache_time'])); - Bread::setOption('custom_query', sanitize_text_field($_POST['custom_query'])); - Bread::setOption('additional_list_custom_query', sanitize_text_field($_POST['additional_list_custom_query'])); - Bread::setOption('user_agent', isset($_POST['user_agent']) ? sanitize_text_field($_POST['user_agent']) : 'None'); - Bread::setOption('sslverify', isset($_POST['sslverify']) ? '1' : '0'); - Bread::setOption('extra_meetings', array()); + $this->bread->setOption('include_additional_list', boolval($_POST['include_additional_list'])); + $this->bread->setOption('additional_list_format_key', sanitize_text_field($_POST['additional_list_format_key'])); + $this->bread->setOption('additional_list_sort_order', sanitize_text_field($_POST['additional_list_sort_order'])); + $this->bread->setOption('base_font', sanitize_text_field($_POST['base_font'])); + $this->bread->setOption('colorspace', sanitize_text_field($_POST['colorspace'])); + $this->bread->setOption('wheelchair_size', sanitize_text_field($_POST['wheelchair_size'])); + $this->bread->setOption('protection_password', sanitize_text_field($_POST['protection_password'])); + $this->bread->setOption('time_clock', sanitize_text_field($_POST['time_clock'])); + $this->bread->setOption('time_option', intval($_POST['time_option'])); + $this->bread->setOption('remove_space', boolval($_POST['remove_space'])); + $this->bread->setOption('content_line_height', floatval($_POST['content_line_height'])); + $this->bread->setOption('root_server', sanitize_url($_POST['root_server'])); + $this->bread->setOption('service_body_1', sanitize_text_field($_POST['service_body_1'])); + $this->bread->setOption('service_body_2', sanitize_text_field($_POST['service_body_2'])); + $this->bread->setOption('service_body_3', sanitize_text_field($_POST['service_body_3'])); + $this->bread->setOption('service_body_4', sanitize_text_field($_POST['service_body_4'])); + $this->bread->setOption('service_body_5', sanitize_text_field($_POST['service_body_5'])); + $this->bread->setOption('cache_time', intval($_POST['cache_time'])); + $this->bread->setOption('custom_query', sanitize_text_field($_POST['custom_query'])); + $this->bread->setOption('additional_list_custom_query', sanitize_text_field($_POST['additional_list_custom_query'])); + $this->bread->setOption('user_agent', isset($_POST['user_agent']) ? sanitize_text_field($_POST['user_agent']) : 'None'); + $this->bread->setOption('sslverify', isset($_POST['sslverify']) ? '1' : '0'); + $this->bread->setOption('extra_meetings', array()); if (isset($_POST['extra_meetings'])) { foreach ($_POST['extra_meetings'] as $extra) { - Bread::setOption('extra_meetings', wp_kses_post($extra)); + $this->bread->setOption('extra_meetings', wp_kses_post($extra)); } } $authors = $_POST['authors_select']; - Bread::setOption('authors', array()); + $this->bread->setOption('authors', array()); foreach ($authors as $author) { - Bread::appendOption('authors', intval($author)); + $this->bread->appendOption('authors', intval($author)); } $user = wp_get_current_user(); - if (!is_array(Bread::getOption('authors'))) { - Bread::setOption('authors', array(Bread::getOption('authors'))); + if (!is_array($this->bread->getOption('authors'))) { + $this->bread->setOption('authors', array($this->bread->getOption('authors'))); } - if (!in_array($user->ID, Bread::getOption('authors'))) { - Bread::setOption('authors', $user->ID); + if (!in_array($user->ID, $this->bread->getOption('authors'))) { + $this->bread->setOption('authors', $user->ID); } if ($_POST['bmltmeetinglistpreview']) { session_start(); - $_SESSION['bread_preview_settings'] = Bread::getOptions(); - wp_redirect(home_url()."?preview-meeting-list=1"); + $_SESSION['bread_preview_settings'] = $this->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.'); @@ -233,7 +238,7 @@ function admin_options_page() } else { $this->admin->save_admin_options(); echo '

    Your changes were successfully saved!

    '; - $num = delete_transient(Bread::get_TransientKey($this->admin->loaded_setting)); + $num = delete_transient($this->bread->get_TransientKey($this->admin->loaded_setting)); if ($num > 0) { echo "

    $num Cache entries deleted

    "; } @@ -241,10 +246,10 @@ function admin_options_page() echo '
    '; } elseif (isset($_REQUEST['pwsix_action']) && $_REQUEST['pwsix_action'] == "import_settings") { echo '

    Your file was successfully imported!

    '; - $num = delete_transient(Bread::get_TransientKey($this->admin->loaded_setting)); + $num = delete_transient($this->bread->get_TransientKey($this->admin->loaded_setting)); } elseif (isset($_REQUEST['pwsix_action']) && $_REQUEST['pwsix_action'] == "default_settings_success") { echo '

    Your default settings were successfully updated!

    '; - $num = delete_transient(Bread::get_TransientKey($this->admin->loaded_setting)); + $num = delete_transient($this->bread->get_TransientKey($this->admin->loaded_setting)); } global $wpdb; $query = "SELECT COUNT(*) FROM {$wpdb->posts} WHERE guid LIKE '%default_nalogo.jpg%'"; @@ -252,7 +257,7 @@ function admin_options_page() $url = plugin_dir_url(__FILE__) . "includes/default_nalogo.jpg"; media_sideload_image($url, 0); } - Bread::fillUnsetOptions(); + $this->bread->fillUnsetOptions(); ?>
    @@ -265,7 +270,7 @@ function admin_options_page()
  • - +
    - - - - refresh_status(); ?> + + + + refresh_status(); ?>
    - +
    - +
    - +
    - +
    - +
    admin->current_user_can_modify()) {?> @@ -306,7 +311,7 @@ function admin_options_page()
    - +
    diff --git a/bread.php b/bread.php index e6878a0..609cda3 100644 --- a/bread.php +++ b/bread.php @@ -60,7 +60,7 @@ function deactivate_bread() * admin-specific hooks, and public-facing site hooks. */ require plugin_dir_path(__FILE__) . 'includes/class-bread.php'; - +require plugin_dir_path(__FILE__) . 'includes/class-bread-bmlt.php'; /** * Begins execution of the plugin. * diff --git a/includes/class-bread-bmlt.php b/includes/class-bread-bmlt.php index e61f14e..83bdac1 100644 --- a/includes/class-bread-bmlt.php +++ b/includes/class-bread-bmlt.php @@ -1,21 +1,27 @@ bread = $bread; + } + + public function get_configured_root_server_request($url, $raw = false) + { + $results = $this->bread->bmlt()->get($this->bread->getOption('root_server') . "/" . $url); if ($raw) { return $results; } return json_decode(wp_remote_retrieve_body($results), true); } - public static function get_formats_by_language(string $lang) + public function get_formats_by_language(string $lang) { - return Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetFormats&lang_enum=$lang"); + return $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetFormats&lang_enum=$lang"); } /** * Undocumented function @@ -23,17 +29,17 @@ public static function get_formats_by_language(string $lang) * @param string $url The BMLT call. * @return WP_Error | array The result of the call. */ - private static function get(string $url) : WP_Error | array + private function get(string $url): WP_Error | array { $args = array( 'timeout' => '120', ); - if (Bread::getOption('user_agent') != 'None') { + if ($this->bread->getOption('user_agent') != 'None') { $args['headers'] = array( - 'User-Agent' => Bread::getOption('user_agent') + 'User-Agent' => $this->bread->getOption('user_agent') ); } - if (Bread::getOption('sslverify') == '1') { + if ($this->bread->getOption('sslverify') == '1') { $args['sslverify'] = false; } return wp_remote_get($url, $args); @@ -43,45 +49,62 @@ private static function get(string $url) : WP_Error | array * * @return array */ - public static function get_all_meetings(): array + public function get_all_meetings(): array { - $lang = Bread_Bmlt::get_bmlt_server_lang(); - $result = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults&data_field_key=weekday_tinyint,start_time,service_body_bigint,id_bigint,meeting_name,location_text,email_contact&sort_keys=meeting_name,service_body_bigint,weekday_tinyint,start_time"); + $lang = $this->bread->bmlt()->get_bmlt_server_lang(); + $result = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults&data_field_key=weekday_tinyint,start_time,service_body_bigint,id_bigint,meeting_name,location_text,email_contact&sort_keys=meeting_name,service_body_bigint,weekday_tinyint,start_time"); - $unique_areas = Bread_Bmlt::get_areas(); + $unique_areas = $this->bread->bmlt()->get_areas(); $all_meetings = array(); foreach ($result as $value) { foreach ($unique_areas as $unique_area) { $area_data = explode(',', $unique_area); - $area_id = Bread::arraySafeGet($area_data, 1); + $area_id = $this->bread->arraySafeGet($area_data, 1); if ($area_id === $value['service_body_bigint']) { - $area_name = Bread::arraySafeGet($area_data); + $area_name = $this->bread->arraySafeGet($area_data); } } $value['start_time'] = date("g:iA", strtotime($value['start_time'])); - $all_meetings[$value['id_bigint']] = $value['meeting_name'].' - '.Bread::getday($value['weekday_tinyint'], true, $lang).' '.$value['start_time'].' in '.$area_name.' at '.$value['location_text']; + $all_meetings[$value['id_bigint']] = strip_tags($value['meeting_name'] . ' - ' . $this->bread->getday($value['weekday_tinyint'], true, $lang) . ' ' . $value['start_time'] . ' in ' . $area_name . ' at ' . $value['location_text']); } return $all_meetings; } - public static function get_fieldkeys() + public function get_fieldkeys() { - return Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetFieldKeys"); + return $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetFieldKeys"); } - private static $standard_keys = array( - "id_bigint","worldid_mixed","service_body_bigint", - "weekday_tinyint","start_time","duration_time","formats", - "lang_enum","longitude","latitude","meeting_name"."location_text", - "location_info","location_street","location_city_subsection", - "location_neighborhood","location_municipality","location_sub_province", - "location_province","location_postal_code_1","location_nation","comments","zone"); - public static function get_nonstandard_fieldkeys() + private $standard_keys = array( + "id_bigint", + "worldid_mixed", + "service_body_bigint", + "weekday_tinyint", + "start_time", + "duration_time", + "formats", + "lang_enum", + "longitude", + "latitude", + "meeting_name" . "location_text", + "location_info", + "location_street", + "location_city_subsection", + "location_neighborhood", + "location_municipality", + "location_sub_province", + "location_province", + "location_postal_code_1", + "location_nation", + "comments", + "zone" + ); + public function get_nonstandard_fieldkeys() { - $all_fks = Bread_Bmlt::get_fieldkeys(); + $all_fks = $this->bread->bmlt()->get_fieldkeys(); $ret = array(); foreach ($all_fks as $fk) { - if (!in_array($fk['key'], Bread_Bmlt::$standard_keys)) { + if (!in_array($fk['key'], $this->standard_keys)) { $ret[] = $fk; } } @@ -96,13 +119,13 @@ public static function get_nonstandard_fieldkeys() * * @return array the service bodies. */ - public static function get_areas() + public function get_areas() { - if (!empty(Bread_Bmlt::$unique_areas)) { - return Bread_Bmlt::$unique_areas; + if (!empty($this->unique_areas)) { + return $this->unique_areas; } - $result = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetServiceBodies"); - Bread_Bmlt::$unique_areas = array(); + $result = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetServiceBodies"); + $this->unique_areas = array(); foreach ($result as $value) { $parent_name = 'Parent ID'; @@ -114,26 +137,26 @@ public static function get_areas() if ($value['parent_id'] == '') { $value['parent_id'] = '0'; } - Bread_Bmlt::$unique_areas[] = $value['name'] . ',' . $value['id'] . ',' . $value['parent_id'] . ',' . $parent_name; + $this->unique_areas[] = $value['name'] . ',' . $value['id'] . ',' . $value['parent_id'] . ',' . $parent_name; } - return Bread_Bmlt::$unique_areas; + return $this->unique_areas; } /** * Gets the default language of the root server. * * @return string 2 character string ISO standard for the language. */ - public static function get_bmlt_server_lang() : string + public function get_bmlt_server_lang(): string { - if (Bread_Bmlt::$bmlt_server_lang == '') { - $result = Bread_Bmlt::testRootServer(); + if ($this->bmlt_server_lang == '') { + $result = $this->bread->bmlt()->testRootServer(); if (!($result && is_array($result) && is_array($result[0]))) { return 'en'; } - Bread_Bmlt::$bmlt_server_lang = ($result==null) ? 'en' : $result["0"]["nativeLang"]; + $this->bmlt_server_lang = ($result == null) ? 'en' : $result["0"]["nativeLang"]; } - return Bread_Bmlt::$bmlt_server_lang; + return $this->bmlt_server_lang; } /** * Check if this is a valid BMLT server. @@ -141,20 +164,20 @@ public static function get_bmlt_server_lang() : string * @param $override_root_server * @return array the results of GetServerInfo */ - public static function testRootServer(string $override_root_server = null) : array|bool + public function testRootServer(string $override_root_server = null): array|bool { if ($override_root_server == null) { - $results = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetServerInfo", true); + $results = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetServerInfo", true); } else { - $results = Bread_Bmlt::get($override_root_server."/client_interface/json/?switcher=GetServerInfo"); + $results = $this->bread->bmlt()->get($override_root_server . "/client_interface/json/?switcher=GetServerInfo"); } if ($results instanceof WP_Error) { - Bread_Bmlt::$connection_error = $results->get_error_message(); + $this->connection_error = $results->get_error_message(); return false; } $httpcode = wp_remote_retrieve_response_code($results); if ($httpcode != 200 && $httpcode != 302 && $httpcode != 304) { - Bread_Bmlt::$connection_error = "HTTP Return Code: ".$httpcode; + $this->connection_error = "HTTP Return Code: " . $httpcode; return false; } @@ -166,28 +189,28 @@ public static function testRootServer(string $override_root_server = null) : arr * @param boolean $all should we get all the formats defined in the root server, or only those used in the service body. This respects the option recurse_service_bodies but only the first service body. * @return array the formats */ - public static function getFormatsForSelect(bool $all = false): array + public function getFormatsForSelect(bool $all = false): array { if ($all) { - $results = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetFormats"); - Bread_Bmlt::sortBySubkey($results, 'key_string'); + $results = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetFormats"); + $this->bread->bmlt()->sortBySubkey($results, 'key_string'); return $results; } - $area_data = explode(',', Bread::getOption('service_body_1')); - $service_body_id = Bread::arraySafeGet($area_data, 1); - if (Bread::getOption('recurse_service_bodies') == 1) { + $area_data = explode(',', $this->bread->getOption('service_body_1')); + $service_body_id = $this->bread->arraySafeGet($area_data, 1); + if ($this->bread->getOption('recurse_service_bodies') == 1) { $services = '&recursive=1&services[]=' . $service_body_id; } else { - $services = '&services[]='.$service_body_id; + $services = '&services[]=' . $service_body_id; } if (empty($service_body_id)) { $queryUrl = "client_interface/json/?switcher=GetFormats"; } else { $queryUrl = "client_interface/json/?switcher=GetSearchResults$services&get_formats_only"; } - $results = Bread_Bmlt::get_configured_root_server_request($queryUrl); + $results = $this->bread->bmlt()->get_configured_root_server_request($queryUrl); $results = empty($service_body_id) ? $results : $results['formats']; - Bread_Bmlt::sortBySubkey($results, 'key_string'); + $this->sortBySubkey($results, 'key_string'); return $results; } /** @@ -198,7 +221,7 @@ public static function getFormatsForSelect(bool $all = false): array * @param [type] $sortType SORT_ASC (default) or SORT_DESC * @return void */ - public static function sortBySubkey(array &$array, string $subkey, int $sortType = SORT_ASC): void + public function sortBySubkey(array &$array, string $subkey, int $sortType = SORT_ASC): void { if (empty($array)) { return; @@ -213,39 +236,39 @@ public static function sortBySubkey(array &$array, string $subkey, int $sortType * * @return string Something to paste into the URL */ - public static function generateDefaultQuery(): string + public function generateDefaultQuery(): string { // addServiceBody has the side effect that // the service body option is overridden, so that it contains // only the name of the service body. - $services = Bread_Bmlt::addServiceBody('service_body_1'); - $services .= Bread_Bmlt::addServiceBody('service_body_2'); - $services .= Bread_Bmlt::addServiceBody('service_body_3'); - $services .= Bread_Bmlt::addServiceBody('service_body_4'); - $services .=Bread_Bmlt::addServiceBody('service_body_5'); + $services = $this->addServiceBody('service_body_1'); + $services .= $this->addServiceBody('service_body_2'); + $services .= $this->addServiceBody('service_body_3'); + $services .= $this->addServiceBody('service_body_4'); + $services .= $this->addServiceBody('service_body_5'); return $services; } - private static function addServiceBody($service_body_name) + private function addServiceBody($service_body_name) { - if (false === ( Bread::getOption($service_body_name) == 'Not Used' )) { - $area_data = explode(',', Bread::getOption($service_body_name)); - $area = Bread::arraySafeGet($area_data); - Bread::setOption($service_body_name, ($area == 'NOT USED' ? '' : $area)); - $service_body_id = Bread::arraySafeGet($area_data, 1); - if (Bread::getOption('recurse_service_bodies') == 1) { + if (false === ($this->bread->getOption($service_body_name) == 'Not Used')) { + $area_data = explode(',', $this->bread->getOption($service_body_name)); + $area = $this->bread->arraySafeGet($area_data); + $this->bread->setOption($service_body_name, ($area == 'NOT USED' ? '' : $area)); + $service_body_id = $this->bread->arraySafeGet($area_data, 1); + if ($this->bread->getOption('recurse_service_bodies') == 1) { return '&recursive=1&services[]=' . $service_body_id; } else { - return '&services[]='.$service_body_id; + return '&services[]=' . $service_body_id; } } } - public static function parse_field($text) + public function parse_field($text) { - if ($text!='') { + if ($text != '') { $exploded = explode("#@-@#", $text); $knt = count($exploded); if ($knt > 1) { - $text = $exploded[$knt-1]; + $text = $exploded[$knt - 1]; } } return $text; diff --git a/includes/class-bread.php b/includes/class-bread.php index 1b583f7..de74c6c 100644 --- a/includes/class-bread.php +++ b/includes/class-bread.php @@ -64,36 +64,41 @@ class Bread private $maxSetting = 1; private $requested_setting = 1; private $protocol; - private static $instance = null; private $tmp_dir; private $options = array(); private $translate = array(); - public static function temp_dir() + private $generating_meeting_list = false; + private Bread_Bmlt $bread_bmlt; + public function bmlt(): Bread_Bmlt { - return Bread::$instance->tmp_dir; + return $this->bread_bmlt; } - public static function getOption($name): mixed + public function temp_dir() { - if (!isset(Bread::$instance->options[$name])) { + return $this->tmp_dir; + } + public function getOption($name): mixed + { + if (!isset($this->options[$name])) { return ''; } - return Bread::$instance->options[$name]; + return $this->options[$name]; } - public static function emptyOption($name) + public function emptyOption($name) { - return empty(Bread::$instance->options[$name]); + return empty($this->options[$name]); } - public static function getOptionForDisplay($option, $default = '') + public function getOptionForDisplay($option, $default = '') { - return empty(Bread::$instamce->options[$option]) ? $default : esc_html(Bread::$instance->options[$option]); + return empty($this->options[$option]) ? $default : esc_html($this->options[$option]); } - public static function setOption($name, $value) + public function setOption($name, $value) { - return Bread::$instance->options[$name] = $value; + return $this->options[$name] = $value; } - public static function appendOption($name, $value) + public function appendOption($name, $value) { - return Bread::$instance->options[$name][] = $value; + return $this->options[$name][] = $value; } private static function setup_temp_dir() { @@ -126,9 +131,9 @@ private static function brute_force_cleanup($dir) } } } - public static function removeTempDir() + public function removeTempDir() { - Bread::rrmdir(Bread::temp_dir()); + Bread::rrmdir($this->temp_dir()); } private static function rrmdir($dir) { @@ -150,14 +155,13 @@ private function loadAllSettings($holder): int { if (isset($holder['bread_preview_settings'])) { $this->allSettings = array(); - $this->allSettings[0] = $holder['bread_preview_settings']; - $this->allSettings[1] = "Preview Setting"; + $this->allSettings[1] = $holder['bread_preview_settings']; } else { $this->allSettings = get_option(Bread::SETTINGS); } if ($this->allSettings === false) { $this->allSettings = array(); - $this->allSettings[1] = "Default Setting"; + $this->allSettings[1] = array(); $this->maxSetting = 1; } else { foreach ($this->allSettings as $key => $value) { @@ -168,28 +172,28 @@ private function loadAllSettings($holder): int } return isset($holder['current-meeting-list']) ? intval($holder['current-meeting-list']) : 1; } - public static function renameSetting($id, $name) + public function renameSetting($id, $name) { - Bread::$instance->allSettings[$id] = $name; - update_option(Bread::SETTINGS, Bread::$instance->allSettings); + $this->allSettings[$id] = $name; + update_option(Bread::SETTINGS, $this->allSettings); } - public static function getSettingName($id) + public function getSettingName($id) { - return Bread::$instance->allSettings[$id]; + return $this->allSettings[$id]; } - public static function getSettingNames() + public function getSettingNames() { - return Bread::$instance->allSettings; + return $this->allSettings; } - public static function deleteSetting($id) + public function deleteSetting($id) { - unset(Bread::$instance->allSettings[$id]); - update_option(Bread::SETTINGS, Bread::$instance->allSettings); + unset($this->allSettings[$id]); + update_option(Bread::SETTINGS, $this->allSettings); } private function getCurrentMeetingListHolder() { $ret = array(); - if (isset(($_REQUEST['preview-meeting-list']))) { + if (isset(($_REQUEST['preview-meeting-list'])) && !is_admin()) { session_start(); $ret['bread_preview_settings'] = $_SESSION['bread_preview_settings']; $ret['current-meeting-list'] = 1; @@ -200,24 +204,24 @@ private function getCurrentMeetingListHolder() } elseif (isset($_COOKIE['current-meeting-list'])) { $ret['current-meeting-list'] = $_COOKIE['current-meeting-list']; } + $this->generating_meeting_list = !empty($ret) && !is_admin(); return $ret; } - - - public static function generateOptionName($current_setting) + public function generatingMeetingList() { - return Bread::OPTIONS_NAME . '_' . $current_setting; + return $this->generating_meeting_list; } - public static function &getMLOptions($current_setting) + + public function generateOptionName($current_setting) { - return Bread::$instance->getMLOptionsInner($current_setting); + return Bread::OPTIONS_NAME . '_' . $current_setting; } /** * Retrieves the plugin options from the database. * * @return array */ - private function &getMLOptionsInner($current_setting) + public function &getMLOptions($current_setting) { if ($current_setting < 1) { $current_setting = is_admin() ? 1 : $this->requested_setting; @@ -250,25 +254,25 @@ private function &getMLOptionsInner($current_setting) $this->requested_setting = $current_setting; return $this->options; } - public static function getOptions() + public function getOptions() { - return Bread::$instance->options; + return $this->options; } - public static function getOptionsName() + public function getOptionsName() { - return Bread::$instance->optionsName; + return $this->optionsName; } - public static function setOptionsName($name) + public function setOptionsName($name) { - return Bread::$instance->optionsName = $name; + return $this->optionsName = $name; } - public static function getRequestedSetting() + public function getRequestedSetting() { - return Bread::$instance->requested_setting; + return $this->requested_setting; } - public static function setRequestedSetting($id) + public function setRequestedSetting($id) { - Bread::$instance->requested_setting = $id; + $this->requested_setting = $id; } /** * Define the core functionality of the plugin. @@ -287,12 +291,12 @@ public function __construct() $this->version = '2.8.0'; } $this->plugin_name = 'bread'; - Bread::$instance = $this; $this->tmp_dir = $this->setup_temp_dir(); $this->protocol = (strpos(strtolower(home_url()), "https") !== false ? "https" : "http") . "://"; $holder = $this->getCurrentMeetingListHolder(); $this->requested_setting = $this->loadAllSettings($holder); + $this->bread_bmlt = new Bread_Bmlt($this); $this->load_dependencies(); $this->set_locale(); @@ -312,13 +316,13 @@ function load_translations() $this->translate[$key] = $translate; } } - public static function getTranslateTable() + public function getTranslateTable() { - return Bread::$instance->translate; + return $this->translate; } - public static function getProtocol() + public function getProtocol() { - return Bread::$instance->protocol; + return $this->protocol; } /** * Load the required dependencies for this plugin. @@ -396,7 +400,7 @@ private function set_locale() private function define_admin_hooks() { $bmltenabled_admin = new BmltEnabled_Admin(); - $plugin_admin = new Bread_Admin($this->get_plugin_name(), $this->get_version(), $bmltenabled_admin); + $plugin_admin = new Bread_Admin($this->get_plugin_name(), $this->get_version(), $bmltenabled_admin, $this); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); @@ -410,7 +414,6 @@ private function define_admin_hooks() //add_action("admin_notices", $plugin_admin, "is_root_server_missing"); $this->loader->add_action("admin_init", $plugin_admin, "pwsix_process_settings_export"); $this->loader->add_action("admin_init", $plugin_admin, "pwsix_process_settings_import"); - $this->loader->add_action("admin_init", $plugin_admin, "pwsix_process_default_settings"); $this->loader->add_action("admin_init", $plugin_admin, "pwsix_process_settings_admin"); $this->loader->add_action("admin_init", $plugin_admin, "pwsix_process_rename_settings"); $this->loader->add_action("admin_init", $plugin_admin, "my_theme_add_editor_styles"); @@ -428,13 +431,11 @@ private function define_admin_hooks() private function define_public_hooks() { - $plugin_public = new Bread_Public($this->get_plugin_name(), $this->get_version(), $this->options); + $plugin_public = new Bread_Public($this->get_plugin_name(), $this->get_version(), $this); $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); - if (isset($this->getCurrentMeetingListHolder()['current-meeting-list']) && !is_admin()) { - $this->loader->add_action('plugins_loaded', $plugin_public, 'bmlt_meeting_list'); - } + $this->loader->add_action('plugins_loaded', $plugin_public, 'bmlt_meeting_list'); } /** @@ -491,13 +492,13 @@ public static function arraySafeGet(array $arr, string $key = "0"): string { return $arr[$key] ?? ''; } - public static function getday($day, $abbreviate = false, $language = 'en') + public function getday($day, $abbreviate = false, $language = 'en') { $key = "WEEKDAYS"; if ($abbreviate) { $key = "WKDYS"; } - return Bread::$instance->translate[$language][$key][$day]; + return $this->translate[$language][$key][$day]; } function fillUnsetOption($option, $default) { @@ -523,10 +524,10 @@ function fillUnsetArrayOption($option, $default) } } } - public static function fillUnsetOptions() + public function fillUnsetOptions() { - Bread::$instance->fillUnsetOptionsInner(); - Bread::$instance->removeDeprecated(); + $this->fillUnsetOptionsInner(); + $this->removeDeprecated(); } function removeDeprecated() { @@ -609,9 +610,9 @@ function fillUnsetOptionsInner() $this->fillUnsetStringOption('meeting1_footer', $this->options['nonmeeting_footer']); $this->fillUnsetStringOption('meeting2_footer', $this->options['nonmeeting_footer']); } - public static function upgradeSettings() + public function upgradeSettings() { - Bread::$instance->upgrade_settings(); + $this->upgrade_settings(); } function upgrade_settings() { @@ -621,7 +622,7 @@ function upgrade_settings() || $this->options['meeting_sort'] === 'weekday_city' || $this->options['meeting_sort'] === 'weekday_county' || $this->options['meeting_sort'] === 'day')) { - $this->options['weekday_language'] = Bread_Bmlt::get_bmlt_server_lang(); + $this->options['weekday_language'] = $this->bmlt()->get_bmlt_server_lang(); } if ($this->options['page_fold'] == 'half') { if ($this->options['page_size'] == 'A5') { @@ -678,7 +679,7 @@ function upgrade_settings() $this->renamed_option('asm_custom_query', 'additional_list_custom_query'); $this->renamed_option('asm_template_content', 'additional_list_template_content'); if (!isset($this->options['bread_version']) || $this->options['bread_version'] < '2.8') { - if (($this->options['page_fold'] == 'half' || $this->options['page_fold'] == 'full') && trim($this->options['last_page_content'])!=='') { + if (($this->options['page_fold'] == 'half' || $this->options['page_fold'] == 'full') && trim($this->options['last_page_content']) !== '') { $this->options['custom_section_content'] = $this->options['last_page_content']; $this->options['custom_section_font_size'] = $this->options['last_page_font_size']; $this->options['custom_section_line_height'] = $this->options['last_page_line_height']; @@ -698,9 +699,9 @@ private function renamed_option(string $old, string $new) } } } - public static function updateOptions() + public function updateOptions() { - update_option(Bread::getOptionsName(), Bread::$instance->options); + update_option(Bread::getOptionsName(), $this->options); } public static function get_TransientKey($setting) { diff --git a/public/class-bread-content-generator.php b/public/class-bread-content-generator.php index 7dfce09..2f9bf87 100644 --- a/public/class-bread-content-generator.php +++ b/public/class-bread-content-generator.php @@ -27,6 +27,7 @@ class Bread_ContentGenerator * @var array */ private array $options; + private Bread $bread; /** * The meetings in the meeting list. * @@ -79,14 +80,15 @@ class Bread_ContentGenerator * The constuctor sets things up so that we are ready to generate. * * @param Mpdf $mpdf The object that converts HTML to PDF. - * @param array $options The configuration of the meeting list. + * @param Bread $bread The configuration of the meeting list. * @param array $result_meetings The meetings to be included in the list. * @param Bread_FormatsManager $formatsManager */ - function __construct(object $mpdf, array $options, array $result_meetings, Bread_FormatsManager $formatsManager) + function __construct(Mpdf $mpdf, Bread $bread, array $result_meetings, Bread_FormatsManager $formatsManager) { $this->mpdf = $mpdf; - $this->options = $options; + $this->bread = $bread; + $this->options = $bread->getOptions(); $this->result_meetings = $this->orderByWeekdayStart($result_meetings); $this->formatsManager = $formatsManager; if (isset($_GET['time_zone'])) { @@ -118,7 +120,7 @@ function __construct(object $mpdf, array $options, array $result_meetings, Bread "[service_body_5]" => strtoupper($this->options['service_body_5']), ); - $this->shortcodes = apply_filters("Bread_Section_Shortcodes", $this->shortcodes, Bread_Bmlt::get_areas(), $formatsManager->getFormatsUsed()); + $this->shortcodes = apply_filters("Bread_Section_Shortcodes", $this->shortcodes, $this->bread->bmlt()->get_areas(), $formatsManager->getFormatsUsed()); if ($this->options['page_fold'] == 'half' || $this->options['page_fold'] == 'full') { $this->mpdf->DefHTMLFooterByName('MyFooter', '
    ' . $this->options['nonmeeting_footer'] . '
    '); $this->mpdf->DefHTMLFooterByName('_default', '
    ' . $this->options['nonmeeting_footer'] . '
    '); @@ -165,11 +167,11 @@ public function generate(int $num_columns): void $this->WriteHTML(''); } $lang = $this->options['weekday_language']; - $this->meetingEnhancer = new Bread_Meeting_Enhancer($this->options, Bread_Bmlt::get_areas()); + $this->meetingEnhancer = new Bread_Meeting_Enhancer($this->bread, $this->bread->bmlt()->get_areas()); foreach ($this->result_meetings as &$value) { $value = $this->meetingEnhancer->enhance_meeting($value, $lang, $this->formatsManager); } - $meetingslistStructure = new Bread_Meetingslist_Structure($this->options, $this->result_meetings, $lang, $this->options['include_additional_list'] == 0 ? -1 : 0); + $meetingslistStructure = new Bread_Meetingslist_Structure($this->bread, $this->result_meetings, $lang, $this->options['include_additional_list'] == 0 ? -1 : 0); $this->writeMeetings($this->options['meeting_template_content'], $meetingslistStructure); if ($this->options['page_fold'] !== 'half' && $this->options['page_fold'] !== 'full') { @@ -235,7 +237,7 @@ private function locale_month_replacement(string $data, string $case): string $locLang = 'en'; } $fmt = new IntlDateFormatter( - Bread::getTranslateTable()[$locLang]['LOCALE'], + $this->bread->getTranslateTable()[$locLang]['LOCALE'], IntlDateFormatter::FULL, IntlDateFormatter::FULL ); @@ -535,7 +537,7 @@ private function get_field(array $obj, string $field): mixed { $value = ''; if (isset($obj[$field])) { - $value = Bread_Bmlt::parse_field($obj[$field]); + $value = $this->bread->bmlt()->parse_field($obj[$field]); } return $value; } @@ -546,6 +548,9 @@ function write_additional_meetinglist() } else { $template = $this->options['meeting_template_content']; } + if (empty($this->options['additional_list_language'])) { + $this->options['additional_list_language'] = $this->options['weekday_language']; + } $additional_list_query = false; $additional_meetinglist_result = $this->result_meetings; /** @@ -562,7 +567,7 @@ function write_additional_meetinglist() if ($this->options['additional_list_format_key'] === 'ASM') { $additional_list_id = '&formats[]=' . $this->formatsManager->getFormatByKey($this->options['weekday_language'], 'ASM'); } - $services = Bread_Bmlt::generateDefaultQuery(); + $services = $this->bread->bmlt()->generateDefaultQuery(); if (!empty($this->options['additional_list_custom_query'])) { $services = $this->options['additional_list_custom_query']; } @@ -571,7 +576,7 @@ function write_additional_meetinglist() if ($this->options['additional_list_format_key'] === 'ASM') { $additional_list_query .= "&advanced_published=0"; } - $additional_meetinglist_result = Bread_Bmlt::get_configured_root_server_request($additional_list_query); + $additional_meetinglist_result = $this->bread->bmlt()->get_configured_root_server_request($additional_list_query); $this->adjust_timezone($additional_meetinglist_result, $this->target_timezone); } if ($additional_list_query || $this->options['weekday_language'] != $this->options['additional_list_language']) { @@ -579,7 +584,7 @@ function write_additional_meetinglist() $value = $this->meetingEnhancer->enhance_meeting($value, $this->options['additional_list_language'], $this->formatsManager); } } - $meetingslistStructure = new Bread_Meetingslist_Structure($this->options, $additional_meetinglist_result, $this->options['additional_list_language'], 1); + $meetingslistStructure = new Bread_Meetingslist_Structure($this->bread, $additional_meetinglist_result, $this->options['additional_list_language'], 1); $this->writeMeetings($template, $meetingslistStructure); return; } diff --git a/public/class-bread-format-manager.php b/public/class-bread-format-manager.php index 8bef612..0283eea 100644 --- a/public/class-bread-format-manager.php +++ b/public/class-bread-format-manager.php @@ -1,4 +1,5 @@ usedFormats[$lang] = $usedFormats; $this->hashedFormats[$lang] = $this->hashFormats($usedFormats); $this->defaultLang = $lang; + $this->bmlt = $bmlt; } /** * Helper functtion to create a key=>value array of formats for convenient lookup @@ -72,8 +76,8 @@ private function loadFormats(string $lang): void if (isset($this->allFormats[$lang])) { return; } - $this->allFormats[$lang] = Bread_Bmlt::get_formats_by_language($lang); - Bread_Bmlt::sortBySubkey($this->allFormats[$lang], 'key_string'); + $this->allFormats[$lang] = $this->bmlt->get_formats_by_language($lang); + $this->bmlt->sortBySubkey($this->allFormats[$lang], 'key_string'); $this->hashedFormats[$lang] = $this->hashFormats($this->allFormats[$lang]); } /** @@ -178,7 +182,7 @@ public function write_detailed_formats(string $lang, bool $isAll, string $lineHe if (empty($formats)) { return ''; } - $data = "
    -
    >
    +
    bread->getOption('time_clock') == '12' || $this->bread->getOption('time_clock') == '' ? 'checked' : '') ?>>
    -
    >
    +
    bread->getOption('time_option') == '1' || $this->bread->getOption('time_option') == '' ? 'checked' : '') ?>>
    - + bread->getOption('remove_space') == '0' || $this->bread->getOption('remove_space') == '' ? 'checked' : ''; ?>
    >
    -
    >
    +
    bread->getOption('time_clock') == '24' ? 'checked' : '') ?>>
    -
    >
    +
    bread->getOption('time_option') == '2' ? 'checked' : '') ?>>
    -
    >
    +
    bread->getOption('remove_space') == '1') ? 'checked' : ''; ?>>
    -
    >
    +
    bread->getOption('time_clock') == '24fr' ? 'checked' : '') ?>>
    -
    >
    +
    bread->getOption('time_option') == '3' ? 'checked' : '') ?>>
    "; + $data = "
    "; foreach ($formats as $format) { $data .= ""; $data .= ""; @@ -201,18 +205,18 @@ public function write_formats(string $lang, bool $isAll, string $lineHeight, str if (empty($formats)) { return ''; } - $data = "
    " . $format['key_string'] . "(" . $format['name_string'] . ") " . $format['description_string'] . "
    "; + $data = "
    "; for ($count = 0; $count < count($formats); $count++) { $data .= ''; - $data .= ""; - $data .= ""; + $data .= ""; + $data .= ""; $count++; if ($count >= count($formats)) { - $data .= ""; - $data .= ""; + $data .= ""; + $data .= ""; } else { - $data .= ""; - $data .= ""; + $data .= ""; + $data .= ""; } $data .= ""; } diff --git a/public/class-bread-meeting-enhancer.php b/public/class-bread-meeting-enhancer.php index b3f1c14..814ab85 100644 --- a/public/class-bread-meeting-enhancer.php +++ b/public/class-bread-meeting-enhancer.php @@ -1,11 +1,13 @@ options = $options; + $this->bread = $bread; + $this->options = $bread->getOptions(); $this->areas = $areas; } /** @@ -70,8 +72,8 @@ public function enhance_meeting(&$meeting_value, $lang, $formatsManager) $meeting_value['start_time'] = $start_time . $space . '-' . $space . $end_time; } - $meeting_value['day_abbr'] = Bread::getday($meeting_value['weekday_tinyint'], true, $lang); - $meeting_value['day'] = Bread::getday($meeting_value['weekday_tinyint'], false, $lang); + $meeting_value['day_abbr'] = $this->bread->getday($meeting_value['weekday_tinyint'], true, $lang); + $meeting_value['day'] = $this->bread->getday($meeting_value['weekday_tinyint'], false, $lang); $area_name = $this->get_area_name($meeting_value); $meeting_value['area_name'] = $area_name; $meeting_value['area_i'] = substr($area_name, 0, 1); @@ -91,9 +93,9 @@ private function get_area_name(array $meeting_value): string { foreach ($this->areas as $unique_area) { $area_data = explode(',', $unique_area); - $area_id = Bread::arraySafeGet($area_data, 1); + $area_id = $this->bread->arraySafeGet($area_data, 1); if ($area_id === $meeting_value['service_body_bigint']) { - return Bread::arraySafeGet($area_data); + return $this->bread->arraySafeGet($area_data); } } return ''; diff --git a/public/class-bread-meetingslist-structure.php b/public/class-bread-meetingslist-structure.php index 0117f80..d12b828 100644 --- a/public/class-bread-meetingslist-structure.php +++ b/public/class-bread-meetingslist-structure.php @@ -81,6 +81,7 @@ class Bread_Meetingslist_Structure * @return void */ private bool $suppress_heading; + private Bread $bread; /** * Calculates some options that will be used to structure the meeting list and generate headers. * @@ -137,7 +138,7 @@ private function upgradeHeaderData(string $meeting_sort) /** * Setup for structuring the meeting list * - * @param array $options The configuration of the meeting list. + * @param Bread $bread The configuration of the meeting list. * @param array $result_meetings The meetings in the meeting list. * @param string $lang The language of the meeting list * @param integer $include_additional_list Whether or not to include meetings that match the requirements of the additional list. Where @@ -145,18 +146,19 @@ private function upgradeHeaderData(string $meeting_sort) * 1 - only meetings with additional_list format * -1 - only meetings without additional_list format */ - function __construct(array $options, array $result_meetings, string $lang, int $include_additional_list) + function __construct(Bread $bread, array $result_meetings, string $lang, int $include_additional_list) { - $this->options = $options; + $this->bread = $bread; + $this->options = $bread->getOptions(); if ($include_additional_list >= 0) { $this->suppress_heading = isset($options['additional_list_suppress_heading']) ? $options['additional_list_suppress_heading'] == 1 : true; } else { - $this->suppress_heading = $options['suppress_heading'] == 1; + $this->suppress_heading = $this->options['suppress_heading'] == 1; } - $meeting_sort = $options['meeting_sort']; + $meeting_sort = $this->options['meeting_sort']; if ($include_additional_list > 0) { $this->options['suppess_heading'] = 1; - switch ($options['additional_list_sort_order']) { + switch ($this->options['additional_list_sort_order']) { case 'meeting_name': $meeting_sort = 'meeting_name'; break; @@ -169,23 +171,23 @@ function __construct(array $options, array $result_meetings, string $lang, int $ } $this->upgradeHeaderData($meeting_sort); - $header_style = "color:" . $options['header_text_color'] . ";"; - $header_style .= "background-color:" . $options['header_background_color'] . ";"; - $header_style .= "font-size:" . $options['header_font_size'] . "pt;"; - $header_style .= "line-height:" . $options['content_line_height'] . ";"; + $header_style = "color:" . $this->options['header_text_color'] . ";"; + $header_style .= "background-color:" . $this->options['header_background_color'] . ";"; + $header_style .= "font-size:" . $this->options['header_font_size'] . "pt;"; + $header_style .= "line-height:" . $this->options['content_line_height'] . ";"; $header_style .= "text-align:center;padding-top:2px;padding-bottom:3px;"; - if ($options['header_uppercase'] == 1) { + if ($this->options['header_uppercase'] == 1) { $header_style .= 'text-transform: uppercase;'; } - if ($options['header_bold'] == 0) { + if ($this->options['header_bold'] == 0) { $header_style .= 'font-weight: normal;'; } - if ($options['header_bold'] == 1) { + if ($this->options['header_bold'] == 1) { $header_style .= 'font-weight: bold;'; } $this->header_style = $header_style; - $this->cont = '(' . Bread::getTranslateTable()[$lang]['CONT'] . ')'; + $this->cont = '(' . $bread->getTranslateTable()[$lang]['CONT'] . ')'; $this->headerMeetings = $this->getHeaderMeetings($result_meetings, $include_additional_list); $this->unique_heading = $this->getUniqueHeadings($this->headerMeetings); @@ -345,7 +347,7 @@ private function getHeaderItem(array $value, array $names): string $grouping = ''; $name = $this->options[$names['name']]; if ($name == 'service_body_bigint') { - foreach (Bread_Bmlt::get_areas() as $unique_area) { + foreach ($this->bread->bmlt()->get_areas() as $unique_area) { $area_data = explode(',', $unique_area); $area_name = Bread::arraySafeGet($area_data); $area_id = Bread::arraySafeGet($area_data, 1); @@ -362,14 +364,14 @@ private function getHeaderItem(array $value, array $names): string } return '[' . str_pad($day, 2, '0', STR_PAD_LEFT) . ']' . $value['day']; } elseif (isset($value[$name])) { - $grouping = Bread_Bmlt::parse_field($value[$name]); + $grouping = $this->bread->bmlt()->parse_field($value[$name]); } $suffix = $this->options[$names['name_suffix']] ?? ''; if ($grouping == '' && !empty($name_alt) && isset($value[$name_alt]) ) { - $grouping = Bread_Bmlt::parse_field($value[$name_alt]); + $grouping = $this->bread->bmlt()->parse_field($value[$name_alt]); $suffix = $this->options[$names['name_alt_suffix']] ?? ''; } if (strlen(trim($grouping)) == 0) { diff --git a/public/class-bread-public.php b/public/class-bread-public.php index 668a758..16be4cc 100644 --- a/public/class-bread-public.php +++ b/public/class-bread-public.php @@ -48,6 +48,7 @@ class Bread_Public * @var object Does the work of translating the HTML to PDF. */ private Mpdf $mpdf; + private Bread $bread; /** * Initialize the class and set its properties. * @@ -55,10 +56,12 @@ class Bread_Public * @param string $plugin_name The name of the plugin. * @param string $version The version of this plugin. */ - public function __construct($plugin_name, $version) + public function __construct($plugin_name, $version, $bread) { $this->plugin_name = $plugin_name; $this->version = $version; + $this->bread = $bread; + $this->options = $bread->getOptions(); } /** @@ -83,7 +86,10 @@ public function enqueue_scripts() public function bmlt_meeting_list($atts = null, $content = null) { - $this->options = Bread::getMLOptions(Bread::getRequestedSetting()); + if (!$this->bread->generatingMeetingList()) { + return; + } + $this->options = $this->bread->getMLOptions($this->bread->getRequestedSetting()); $import_streams = []; ini_set('max_execution_time', 600); // tomato server can take a long time to generate a schedule, override the server setting @@ -103,7 +109,7 @@ public function bmlt_meeting_list($atts = null, $content = null) if (intval($this->options['cache_time']) > 0 && ! isset($_GET['nocache']) && ! isset($_GET['custom_query']) ) { - if (false !== ($content = get_transient(Bread::get_TransientKey(Bread::getRequestedSetting())))) { + if (false !== ($content = get_transient($this->bread->get_TransientKey($this->bread->getRequestedSetting())))) { $content = pack("H*", $content); $name = $this->get_FilePath(); header('Content-Type: application/pdf'); @@ -118,7 +124,7 @@ public function bmlt_meeting_list($atts = null, $content = null) } } $page_type_settings = $this->constuct_page_type_settings(); - Bread::UpgradeSettings(); + $this->bread->UpgradeSettings(); $default_font = $this->options['base_font'] == "freesans" ? "dejavusanscondensed" : $this->options['base_font']; $mode = 's'; $mpdf_init_options = $this->construct_init_options($default_font, $mode, $page_type_settings); @@ -151,19 +157,19 @@ public function bmlt_meeting_list($atts = null, $content = null) $sort_keys = 'weekday_tinyint,start_time,meeting_name'; $get_used_formats = '&get_used_formats'; $select_language = ''; - if ($this->options['weekday_language'] != Bread_Bmlt::get_bmlt_server_lang()) { + if ($this->options['weekday_language'] != $this->bread->bmlt()->get_bmlt_server_lang()) { $select_language = '&lang_enum=' . $this->getSingleLanguage($this->options['weekday_language']); } - $services = Bread_Bmlt::generateDefaultQuery(); + $services = $this->bread->bmlt()->generateDefaultQuery(); if (isset($_GET['custom_query'])) { $services = $_GET['custom_query']; } elseif ($this->options['custom_query'] !== '') { $services = $this->options['custom_query']; } if ($this->options['used_format_1'] == '') { - $result = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults$services&sort_keys=$sort_keys$get_used_formats$select_language"); + $result = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults$services&sort_keys=$sort_keys$get_used_formats$select_language"); } elseif ($this->options['used_format_1'] != '') { - $result = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults$services&sort_keys=$sort_keys&get_used_formats&formats[]=" . $this->options['used_format_1'] . $select_language); + $result = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults$services&sort_keys=$sort_keys&get_used_formats&formats[]=" . $this->options['used_format_1'] . $select_language); } if ($result == null) { @@ -181,7 +187,7 @@ public function bmlt_meeting_list($atts = null, $content = null) $extras .= "&meeting_ids[]=" . $value; } - $extra_result = Bread_Bmlt::get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults&sort_keys=" . $sort_keys . "" . $extras . "" . $get_used_formats . $select_language); + $extra_result = $this->bread->bmlt()->get_configured_root_server_request("client_interface/json/?switcher=GetSearchResults&sort_keys=" . $sort_keys . "" . $extras . "" . $get_used_formats . $select_language); $formatsManager = null; if ($extra_result <> null) { $result_meetings = array_merge($result['meetings'], $extra_result['meetings']); @@ -191,13 +197,13 @@ public function bmlt_meeting_list($atts = null, $content = null) } array_multisort($weekday, SORT_ASC, $start_time, SORT_ASC, $result_meetings); - $formatsManager = new Bread_FormatsManager(array_merge($result['formats'], $extra_result['formats']), $this->options['weekday_language']); + $formatsManager = new Bread_FormatsManager(array_merge($result['formats'], $extra_result['formats']), $this->options['weekday_language'], $this->bread->bmlt()); } else { - $formatsManager = new Bread_FormatsManager($result['formats'], $this->options['weekday_language']); + $formatsManager = new Bread_FormatsManager($result['formats'], $this->options['weekday_language'], $this->bread->bmlt()); $result_meetings = $result['meetings']; } } else { - $formatsManager = new Bread_FormatsManager($result['formats'], $this->options['weekday_language']); + $formatsManager = new Bread_FormatsManager($result['formats'], $this->options['weekday_language'], $this->bread->bmlt()); $result_meetings = $result['meetings']; } @@ -215,7 +221,7 @@ public function bmlt_meeting_list($atts = null, $content = null) $this->options['page_fold'] = 'quad'; $num_columns = 4; } - $generator = new Bread_ContentGenerator($this->mpdf, $this->options, $result_meetings, $formatsManager); + $generator = new Bread_ContentGenerator($this->mpdf, $this->bread, $result_meetings, $formatsManager); $generator->generate($num_columns); $this->mpdf->SetDisplayMode('fullpage', 'two'); $this->reorder_booklet_pages($mode); @@ -231,16 +237,16 @@ public function bmlt_meeting_list($atts = null, $content = null) ) { $content = $this->mpdf->Output('', 'S'); $content = bin2hex($content); - $transient_key = Bread::get_TransientKey(Bread::getRequestedSetting()); + $transient_key = $this->bread->get_TransientKey($this->bread->getRequestedSetting()); set_transient($transient_key, $content, intval($this->options['cache_time']) * HOUR_IN_SECONDS); } - $FilePath = apply_filters("Bread_Download_Name", $this->get_FilePath(), $this->options['service_body_1'], Bread::getSettingName(Bread::getRequestedSetting())); + $FilePath = apply_filters("Bread_Download_Name", $this->get_FilePath(), $this->options['service_body_1'], $this->bread->getSettingName($this->bread->getRequestedSetting())); $this->mpdf->Output($FilePath, 'I'); } foreach ($import_streams as $FilePath => $stream) { @unlink($FilePath); } - Bread::removeTempDir(); + $this->bread->removeTempDir(); exit; } private function constuct_page_type_settings() @@ -294,7 +300,7 @@ private function construct_init_options($default_font, $mode, $page_type_setting __DIR__ . '/mpdf/vendor/mpdf/mpdf/ttfonts', __DIR__ . '/fonts', ), - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'mode' => $mode, 'default_font_size' => 7, 'fontdata' => [ @@ -327,7 +333,7 @@ private function construct_init_options($default_font, $mode, $page_type_setting } else { $mpdf_init_options = [ 'mode' => $mode, - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'default_font_size' => 7, 'default_font' => $default_font, 'margin_left' => $this->options['margin_left'], @@ -372,7 +378,7 @@ private function drawLinesSeperatingColumns($mode, $format, $default_font) $mpdf_column = new mPDF( [ 'mode' => $mode, - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'format' => $format, 'default_font_size' => 7, 'default_font' => $default_font, @@ -387,7 +393,7 @@ private function drawLinesSeperatingColumns($mode, $format, $default_font) ); $mpdf_column->WriteHTML($html); - $FilePath = Bread::temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_column'); + $FilePath = $this->bread->temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_column'); $mpdf_column->Output($FilePath, 'F'); $h = \fopen($FilePath, 'rb'); $stream = new \setasign\Fpdi\PdfParser\StreamReader($h, false); @@ -399,11 +405,11 @@ private function drawLinesSeperatingColumns($mode, $format, $default_font) private function reorder_booklet_pages($mode) { if ($this->options['page_fold'] == 'half') { - $FilePath = Bread::temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_half'); + $FilePath = $this->bread->temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_half'); $this->mpdf->Output($FilePath, 'F'); $mpdfOptions = [ 'mode' => $mode, - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'default_font_size' => '', 'margin_left' => 0, 'margin_right' => 0, @@ -446,11 +452,11 @@ private function reorder_booklet_pages($mode) } $this->mpdf = $mpdftmp; } else if ($this->options['page_fold'] == 'full' && $this->options['booklet_pages']) { - $FilePath = Bread::temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_full'); + $FilePath = $this->bread->temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_full'); $this->mpdf->Output($FilePath, 'F'); $mpdfOptions = [ 'mode' => $mode, - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'default_font_size' => '', 'margin_left' => 0, 'margin_right' => 0, @@ -483,11 +489,11 @@ private function reorder_booklet_pages($mode) $mpdftmp->UseTemplate($tplIdx); $this->mpdf = $mpdftmp; } else if ($this->options['page_fold'] == 'flyer') { - $FilePath = Bread::temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_flyer'); + $FilePath = $this->bread->temp_dir() . DIRECTORY_SEPARATOR . $this->get_FilePath('_flyer'); $this->mpdf->Output($FilePath, 'F'); $mpdfOptions = [ 'mode' => $mode, - 'tempDir' => Bread::temp_dir(), + 'tempDir' => $this->bread->temp_dir(), 'default_font_size' => '', 'margin_left' => 0, 'margin_right' => 0, @@ -556,7 +562,7 @@ function get_FilePath($pos = '') if (is_multisite()) { $site = get_current_blog_id() . '_'; } - return "meetinglist_" . $site . Bread::getRequestedSetting() . $pos . '_' . strtolower(date("njYghis")) . ".pdf"; + return "meetinglist_" . $site . $this->bread->getRequestedSetting() . $pos . '_' . strtolower(date("njYghis")) . ".pdf"; } function getSingleLanguage($lang) diff --git a/tests/BreadFormatsManagerTest.php b/tests/BreadFormatsManagerTest.php index 43f2651..2cf17ca 100644 --- a/tests/BreadFormatsManagerTest.php +++ b/tests/BreadFormatsManagerTest.php @@ -1,4 +1,5 @@ getFormats($usedFormat), $lang); + return new Bread_FormatsManager($this->getFormats($usedFormat), $lang, $bmlt); } public function testGetFormatsUsed() { - $mgr = $this->getFormatMgr('berlin-formats-de', 'de'); + $bread = new Bread([]); + $bread->bmlt()->setFormatBase('german-formats'); + $mgr = $this->getFormatMgr('berlin-formats-de', 'de', $bread->bmlt()); $used = $mgr->getFormatsUsed(); assertEquals(50, count($used)); $o1 = $mgr->getFormatByKey('de', 'O1'); diff --git a/tests/BreadMeetingEnhancerTest.php b/tests/BreadMeetingEnhancerTest.php index 46f64cd..e89e2e9 100644 --- a/tests/BreadMeetingEnhancerTest.php +++ b/tests/BreadMeetingEnhancerTest.php @@ -1,4 +1,5 @@ getFormats($usedFormat), $lang); + return new Bread_FormatsManager($this->getFormats($usedFormat), $lang, $bmlt); } public function testMeetingEnhancer() { - $mgr = $this->getFormatMgr('berlin-formats-de', 'de'); + $bread = new Bread([]); + $bread->bmlt()->setFormatBase('german-formats'); + $mgr = $this->getFormatMgr('berlin-formats-de', 'de', $bread->bmlt()); $used = $mgr->getFormatsUsed(); assertEquals(50, count($used)); $o1 = $mgr->getFormatByKey('de', 'O1'); diff --git a/tests/BreadMeetinglistStructureTest.php b/tests/BreadMeetinglistStructureTest.php index f98185c..f4977a3 100644 --- a/tests/BreadMeetinglistStructureTest.php +++ b/tests/BreadMeetinglistStructureTest.php @@ -1,4 +1,5 @@ getFormats($usedFormat), $lang); + return new Bread_FormatsManager($this->getFormats($usedFormat), $lang, $bread->bmlt()); } - private function enhanceMeetings(&$meetings, $options, $formatMgr) + private function enhanceMeetings(&$meetings, Bread $bread, $formatMgr) { - $enhancer = new Bread_Meeting_Enhancer($options, array()); + $enhancer = new Bread_Meeting_Enhancer($bread, array()); foreach ($meetings as &$meeting) { $meeting = $enhancer->enhance_meeting($meeting, 'de', $formatMgr); } @@ -57,8 +58,8 @@ public function testBerlinByDayMain() 'berlin-formats-de', 'german-formats', -1, - ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'], - [[0],[0],[0],[0],[0],[0],[0]], + ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'], + [[0], [0], [0], [0], [0], [0], [0]], 'de' ); } @@ -70,8 +71,8 @@ public function testBerlinByDayAdditional() 'berlin-formats-de', 'german-formats', 1, - ['','','','','','',''], - [[0],[0],[0],[0],[0],[0],[0]], + ['', '', '', '', '', '', ''], + [[0], [0], [0], [0], [0], [0], [0]], 'de' ); } @@ -83,8 +84,8 @@ public function testBerlinByCityPlusDayMain() 'berlin-formats-de', 'german-formats', -1, - ['Berlin','Dallgow-Döberitz','Eberswalde','Potsdam','Rathenow'], - [[0],[0],[0],[0],[0]], + ['Berlin', 'Dallgow-Döberitz', 'Eberswalde', 'Potsdam', 'Rathenow'], + [[0], [0], [0], [0], [0]], 'de' ); } @@ -96,8 +97,8 @@ public function testBerlinByCityPlusDayAdditional() 'berlin-formats-de', 'german-formats', 1, - ['','','','','','',''], - [[0],[0],[0],[0],[0],[0],[0]], + ['', '', '', '', '', '', ''], + [[0], [0], [0], [0], [0], [0], [0]], 'de' ); } @@ -109,8 +110,8 @@ public function testBerlinByDayThenCityPlusDayAdditionalMain() 'berlin-formats-de', 'german-formats', -1, - ['Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag','Sonntag'], - [['Berlin',],['Berlin','Potsdam','Rathenow'],['Berlin','Dallgow-Döberitz','Eberswalde'],['Berlin','Potsdam'],['Berlin',],['Berlin','Potsdam'],['Berlin','Potsdam']], + ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag'], + [['Berlin',], ['Berlin', 'Potsdam', 'Rathenow'], ['Berlin', 'Dallgow-Döberitz', 'Eberswalde'], ['Berlin', 'Potsdam'], ['Berlin',], ['Berlin', 'Potsdam'], ['Berlin', 'Potsdam']], 'de' ); } @@ -122,21 +123,21 @@ public function testBerlinByDayThenCityPlusDayAdditional() 'berlin-formats-de', 'german-formats', 1, - ['','','','','','',''], - [[0],[0],[0],[0],[0],[0],[0]], + ['', '', '', '', '', '', ''], + [[0], [0], [0], [0], [0], [0], [0]], 'de' ); } public function doTest($config, $meetingJson, $usedFormats, $formatBase, $include, $expectedHeading, $expectedSubHeading, $lang): void { - new Bread(); $options = $this->getConfiguration($config); + $bread = new Bread($options); $meetings = $this->getMeetings($meetingJson); - $formatMgr = $this->getFormatMgr($usedFormats, $lang); - Bread_Bmlt::setFormatBase($formatBase); - $this->enhanceMeetings($meetings, $options, $formatMgr); + $bread->bmlt()->setFormatBase($formatBase); + $formatMgr = $this->getFormatMgr($usedFormats, $lang, $bread); + $this->enhanceMeetings($meetings, $bread, $formatMgr); - $bms = new Bread_Meetingslist_Structure($options, $meetings, $lang, $include); + $bms = new Bread_Meetingslist_Structure($bread, $meetings, $lang, $include); $knt = 0; $expectedHeaderStyle = $this->calculateExpectedHeadingStyle($options); while ($subs = $bms->iterateMainHeading()) { @@ -145,20 +146,20 @@ public function doTest($config, $meetingJson, $usedFormats, $formatBase, $includ $knt2 = 0; while ($meetings = $bms->iterateSubHeading($subs)) { $expected = ''; - if ($knt2++ == 0 && !empty($expectedHeading[$knt-1])) { - $expected = '
    ' . $expectedHeading[$knt-1] . "
    "; + if ($knt2++ == 0 && !empty($expectedHeading[$knt - 1])) { + $expected = '
    ' . $expectedHeading[$knt - 1] . "
    "; } $knt3 = 0; while ($meeting = $bms->iterateMeetings($meetings)) { $expectedSub = ''; if ($knt3++ == 0) { - if (!empty($subs[$knt2-1])) { - $expectedSub = "

    " . $subs[$knt2-1] . "

    "; + if (!empty($subs[$knt2 - 1])) { + $expectedSub = "

    " . $subs[$knt2 - 1] . "

    "; } } else { $expected = ''; } - assertEquals($expected.$expectedSub, $bms->calculateHeading()); + assertEquals($expected . $expectedSub, $bms->calculateHeading()); } } } diff --git a/tests/mock/class-bread-bmlt.php b/tests/mock/class-bread-bmlt.php index 9d79d8c..69feaa8 100644 --- a/tests/mock/class-bread-bmlt.php +++ b/tests/mock/class-bread-bmlt.php @@ -1,34 +1,37 @@ format_base = $format_base; } - public static function get_areas() + public function set_areas(array $areas) { - return Bread_Bmlt::$areas; + $this->areas = $areas; + } + public function get_areas() + { + return $this->areas; } public static function parse_field($text) { - if ($text!='') { + if ($text != '') { $exploded = explode("#@-@#", $text); $knt = count($exploded); if ($knt > 1) { - $text = $exploded[$knt-1]; + $text = $exploded[$knt - 1]; } } return $text; } - public static function get_formats_by_language(string $lang) + public function get_formats_by_language(string $lang) { - $json = file_get_contents('tests/formats/'.Bread_Bmlt::$format_base.'-'.$lang.".json"); + $json = file_get_contents('tests/formats/' . $this->format_base . '-' . $lang . ".json"); return json_decode($json, true); } public static function sortBySubkey(array &$array, string $subkey, int $sortType = SORT_ASC): void diff --git a/tests/mock/class-bread.php b/tests/mock/class-bread.php index 34c844a..d99d3f4 100644 --- a/tests/mock/class-bread.php +++ b/tests/mock/class-bread.php @@ -1,12 +1,22 @@ load_translations(); + $this->options = $options; + $this->bmlt1 = new Bread_Bmlt($this); + } + function bmlt() + { + return $this->bmlt1; + } + function getOptions() + { + return $this->options; } function load_translations() { @@ -17,19 +27,19 @@ function load_translations() } include 'includes/lang/' . $file; $key = substr($file, 10, -4); - Bread::$instance->translate[$key] = $translate; + $this->translate[$key] = $translate; } } - public static function getTranslateTable() + public function getTranslateTable() { - return Bread::$instance->translate; + return $this->translate; } - public static function getday($day, $abbreviate = false, $language = 'en') + public function getday($day, $abbreviate = false, $language = 'en') { $key = "WEEKDAYS"; if ($abbreviate) { $key = "WKDYS"; } - return mb_convert_encoding(Bread::$instance->translate[$language][$key][$day], 'UTF-8', mb_list_encodings()); + return $this->translate[$language][$key][$day]; } }
    ".$formats[$count]['key_string']."".$formats[$count]['name_string']."" . $formats[$count]['key_string'] . "" . $formats[$count]['name_string'] . "".$formats[$count]['key_string']."".$formats[$count]['name_string']."" . $formats[$count]['key_string'] . "" . $formats[$count]['name_string'] . "