Browse Source

Initial commit - 2.1.5

master
Sam Black 3 years ago
commit
5650dcf4b0
Signed by: samwwwblack GPG Key ID: 0FF0223994EA47D8
  1. 339
      LICENSE.txt
  2. 303
      README.txt
  3. 1
      admin/css/admin.min.css
  4. BIN
      admin/img/bhilogo.png
  5. 10
      admin/js/admin.min.js
  6. 10
      admin/styles/shared/variables.less
  7. 94
      admin/views/codes.php
  8. 0
      admin/views/indicator-section.php
  9. 72
      admin/views/locations.php
  10. 8
      admin/views/sidebar-indicator.php
  11. 8
      admin/views/sidebar-list.php
  12. 14
      admin/views/sidebar-main.php
  13. 134
      admin/views/underscore-templates.php
  14. 151
      api/class-api.php
  15. 78
      class-business-hours-indicator.php
  16. 240
      controllers/class-admin-controller.php
  17. 379
      controllers/class-shortcode-controller.php
  18. 156
      controllers/class-widgets-controller.php
  19. 41
      core/class-abstract-options-manager.php
  20. 118
      core/class-admin.php
  21. 36
      core/class-config-manager.php
  22. 26
      core/class-language-manager.php
  23. 77
      core/class-loader.php
  24. 103
      core/class-options-manager.php
  25. 21
      core/class-registry.php
  26. 56
      core/class-settings-manager.php
  27. 61
      core/class-shortcode.php
  28. 41
      core/class-widget-options-manager.php
  29. 78
      core/class-widget.php
  30. 174
      core/linq/class-enumerable.php
  31. 35
      core/linq/class-linq-helpers.php
  32. 23
      core/models/class-checkbox-option.php
  33. 24
      core/models/class-custom-option.php
  34. 29
      core/models/class-dropdown-option.php
  35. 20
      core/models/class-option-dependency.php
  36. 41
      core/models/class-option-section.php
  37. 31
      core/models/class-option.php
  38. 25
      core/models/class-text-option.php
  39. 25
      core/templates/fields/checkbox.php
  40. 36
      core/templates/fields/dropdown.php
  41. 26
      core/templates/fields/textbox.php
  42. 89
      core/templates/start.php
  43. 17
      core/templates/widget_form.php
  44. BIN
      languages/business-hours-indicator-bg_BG.mo
  45. BIN
      languages/business-hours-indicator-cs_CZ.mo
  46. BIN
      languages/business-hours-indicator-da_DK.mo
  47. BIN
      languages/business-hours-indicator-de_DE.mo
  48. BIN
      languages/business-hours-indicator-el.mo
  49. BIN
      languages/business-hours-indicator-es_ES.mo
  50. BIN
      languages/business-hours-indicator-fr_BE.mo
  51. BIN
      languages/business-hours-indicator-fr_CA.mo
  52. BIN
      languages/business-hours-indicator-fr_FR.mo
  53. BIN
      languages/business-hours-indicator-it_IT.mo
  54. BIN
      languages/business-hours-indicator-nl_NL.mo
  55. BIN
      languages/business-hours-indicator-ru_RU.mo
  56. BIN
      languages/business-hours-indicator-sk_SK.mo
  57. BIN
      languages/business-hours-indicator-sl_SI.mo
  58. BIN
      languages/business-hours-indicator-sv_SE.mo
  59. 77
      mabel-business-hours-indicator.php
  60. 26
      models/class-ifopenclosed-vm.php
  61. 32
      models/class-indicator-vm.php
  62. 53
      models/class-list-vm.php
  63. 29
      models/class-location.php
  64. 53
      models/class-opening-hours-set.php
  65. 56
      models/class-opening-hours.php
  66. 39
      models/class-special-date.php
  67. 34
      models/class-vacation.php
  68. 140
      services/class-conversion-service.php
  69. 173
      services/class-datetime-service.php
  70. 212
      services/class-opening-hours-service.php
  71. 54
      templates/_helpers.php
  72. 12
      templates/ifopenclosed.php
  73. 25
      templates/indicator.php
  74. 44
      templates/list.php
  75. 9
      uninstall.php

339
LICENSE.txt

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

303
README.txt

@ -0,0 +1,303 @@
=== Business Hours Indicator ===
Contributors: maartenbelmans, studiowombat
Donate link: https://www.paypal.me/maartenbelmans
Tags: business hours, opening times, opening hours, open indication, currently open, business hours overview, indicator, closed, open times, closing times
Requires at least: 3.7
Tested up to: 4.9.4
Stable tag: 2.1.5
Requires PHP: 5.4.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Display opening hours and if you're currently open/closed, with countdown to next opening. Show or hide content only when open/closed & a lot more!
== Description ==
* Highly customizable shortcodes to display your opening times in any format
* Shortcodes to indicate if you are currently open or closed.
* Alternate message when you're almost opening or closing.
* Shortcodes to display something only when you are open or closed
* Easily style everything
* 4 widgets (does the same as the shortcodes)
* Supports Vacations
* Supports 'special dates' with different opening times (e.g: holidays)
* Supports countdown until your next opening/closing time
* Supports multiple locations
* Developer API (more info below)
* Translated in NL, GR, EN, DE, ES, IT, FR, BG, SE, SK, SL
* beautiful & user-friendly settings screens for you, or your client, to work in
Check out a complete list of features below.
= Quick links =
* [&raquo; Examples](http://demo.studiowombat.com/bhi-demos/)
* [&raquo; Documentation](https://studiowombat.com/knowledge-base/)
* [&raquo; Pro Version](https://studiowombat.com/plugin/business-hours-indicator/)
= Requirements =
* PHP 5.4 or higher
* WordPress 3.7 or higher
= General features =
* Shortcode to display business hours
* Widget to display business hours
* Shortcode to display if you're currently open/closed
* Widget to display if you're currently open/closed
* Shortcode to display content only when you're open
* Shortcode to display content only when you're closed
* Choose your prefered time zone
* Display times in 12 or 24 hour format
* Enter multiple locations for more businesses (up to 3 in the free version)
* Include special hours such as holidays
* Include vacation hours
* Highlight the current day
* Frontend translated in: NL, GR, EN, DE, ES, IT, FR, BG, SE, SK, SL
= Displaying opening times =
* Show the opening hours in a table
* Show the opening hours inline
* Consolidate the output: group days with the same opening hours
* Show/hide holiday hours
* Show/hide vacation hours
* Highlight the current day
= Currently open/closed Indication =
* Edit the "we're currently open" message
* Edit the "we're currently closed" message
* Include the current time in the output
* Include the current day in the output
* Add an opening/closing soon warning like "hurry, we're closing in 35 minutes"
= Developer API =
Use the plugin anywhere in WordPress by using the following calls:
* `MBHILITE()->is_open('location name')` returns true if the location is currently open. False otherwise.
* `MBHILITE()->is_closed('location name')` returns true if the location is currently closed. False otherwise.
* `MBHILITE()->get_opening_hours('location name')` returns an array of objects containing the location's opening hours.
* `MBHILITE()->get_specials('location name')` returns an array of objects containing the location's special opening hours.
* `MBHILITE()->get_vacations('location name')` returns an array of objects containing the location's vacations.
More documentation coming soon.
= PRO FEATURES =
* Supports caching
* SEO features
* Enter unlimited multiple locations for more businesses
* Multiple time slots/day for when you close at noon
* Woocommerce support: disable orders + hide "add to cart" buttons when you are closed.
* 'Message builder' allows you to add dynamic codes to build any message you like. A few examples:
* Today is March 8, we're open from 9AM to 5PM.
* It's 7:12PM, we're closed. We open again on Thursday, in 7 hours and 45 minutes.
* Hurry, we're closing in 13 minutes!
* ..And much more!
* Only show today's opening times
* Set how many minutes or hours in advance to show "opening/closing soon" message.
* Customize output with line breaks & separators
* Premium support
* Receive updates & bugfixes
* Show abbreviated days in outputs
* More flexibility
* Priority feauture requests
* And more..!
Find out more about the [pro version here](https://studiowombat.com/plugin/business-hours-indicator/)
== Installation ==
Installing the Business Hours Indicator plugin is very easy:
1. Install from the WordPress Dashboard > Plugin page
2. Or manually download the plugin and extract to wp-content/plugins/
3. Activate the plugin
4. Go to Wordpress Dashboard > Settings > Business Hours Indicator
5. Enter your location, daily opening hours, and fiddle with more settings if you want
6. Use the shortcode `[mbhi location="my location"]` to display the output on pages or posts
7. Or use the PHP code `do_shortcode('[mbhi location="my location"]')` to display the output anywhere in your theme
== Frequently Asked Questions ==
= Does these shortcodes need extra options? =
Yes, at least 1. You should give it a 'location' attribute. If you don't, the first location is used.
= How can I style the business hours overview? =
The code exposes enough CSS classes to give you many styling options. You can
find all classes [here](https://studiowombat.com/knowledge-base/styling-the-output/).
== Screenshots ==
1. Various examples of what this plugin can do.
2. Settings screen.
3. Enter opening times for a location.
4. Example of how it could look like on the frontend.
== Changelog ==
= version 2.1.5 =
* Fix: fixed a bug when deleting one or more holidays within the same month.
= version 2.1.4 =
* CSS changes in the backend to support plugins that override WordPress' default style.
= version 2.1.3 =
* Added: added Slovenian language.
= version 2.1.2 =
* Added: added Canadian French and Belgian French language.
= version 2.1.1 =
* Added: Czech language.
* Fix: bugfix in conversion service.
= version 2.1.0 =
* Fix: fixed a bug with is_open and holidays.
= version 2.0.9 =
* Fix: fixed a bug with is_open.
= version 2.0.8 =
* Update: Lists with vacations and specials are now ordered by ascending date.
* Update: Added Danish translations.
= version 2.0.7 =
* Update: added Russian translations.
* Fix: fixed a bug with the indicator and vacations.
= version 2.0.6 =
* New feature: added widget to display content only when closed.
* New feature: added widget to display content only when open.
* Changes: minor style changes.
* Testing: verified the plugin on WP 4.7.5
= version 2.0.5 =
* New feature: easily accessible API for developers.
* New feature: select quartes of an hour.
* Testing: verified the plugin on WP 4.7.4
= version 2.0.4 =
* Fix: if a vacation was today, it wasn't denoted as the current day.
= version 2.0.3 =
* Fix notice: wrap loops to check for arrays.
= version 2.0.2 =
* Fix admin screen bug with dependency fields.
= version 2.0.1 =
* Fixed a bug where some translations weren't working
* Fixed a bug where a vacation was displayed even though the setting was set to false.
* AFTER UPGRADING, PLEASE CHECK IF YOUR WIDGETS ARE STILL INTACT.
= version 2.0.0 =
* Rewritten the core of the plugin to implement features faster.
* Fixed a few edge-case bugs.
* AFTER UPGRADING, PLEASE CHECK IF YOUR WIDGETS ARE STILL INTACT.
= Version 1.8.8 =
* Added Slovak language to translations
* Verified WP 4.7.1 compatibility
= Version 1.8.7 =
* Getting rid of closure in favor of normal function. This disables warnings for some versions of WP.
= Version 1.8.6 =
* Finally added 2 widgets to display (a) your business hours and (b) indication of being currently open/closed.
* UI changes.
= Version 1.8.5 =
* Fixed php warning 'invalid foreach'.
= Version 1.8.4 =
* Added Bulgarian language (special thanks to D. Stoykow)
= Version 1.8.3 =
* Addition upon 1.8.2
= Version 1.8.2 =
* Fixed an issue with PHP 5.3/5.4 versions.
= Version 1.8.1 =
* Fixed an issue where some WooCommerce websites had a faulty system status.
= Version 1.8.0 =
* Bugfixes
* Rewritten frontend
* Updated languages
* Added Swedish language
= Version 1.7.4 =
* Bugfix: when you aren't open for a few days, the frontend gave a silent error.
= Version 1.7.3 =
* Small bugfix in admin javascript where users weren't able to add multiple locations without refreshing the page.
= version 1.7.2 =
* Proper support for the shortcodes in widgets.
* Remove array literals to support php version 5.3.
* Update documentation.
* Fix bug with ifopen/ifclosed shortcodes for multiple locations.
= version 1.7.1 =
* Fixed a bug where do_shortcode() doesn't show content.
= version 1.7 =
* Added a help tab with shortcodes info.
* shortcodes can now override dashboard settings via attributes.
* Added various new functionality for displaying opening hours.
= Version 1.6 =
* Bugfix where holidays couldn't be denoted as 'closed'.
= Version 1.5.1 =
* Bugfix between Woocommerce and this plugin.
= Version 1.5 =
* Added more CSS classes for your styling needs.
* Ability to print a consolidated (= shortened) opening hours table.
* Reorganized and added some settings.
= Version 1.4 =
* Small bugfixes
= Version 1.3 =
* Added [mbhi_ifclosed] shortcode
* Added [mbhi_ifopen] shortcode
= Version 1.2 =
MAJOR CHANGE &mdash; You'll have to re-enter your settings!
* Added locations
* Added vacation/holiday exception
* Changed settings screen
* Added more settings
* Added a new shortcode to display a location's business hours table
= Version 1.1 =
* Code enhancements
* Approximation: include a different sentence when your business is almost opening/closing.
= Version 1.0 =
* Initial version

1
admin/css/admin.min.css

File diff suppressed because one or more lines are too long

BIN
admin/img/bhilogo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

10
admin/js/admin.min.js

@ -0,0 +1,10 @@
jQuery(document).ready(function(){new Core.Admin.Main(jQuery(document.body))});
var Core;!function(t){!function(e){var i=function(){function e(e){var i=t.Admin.Helpers.Context.getSlug();this.parent=e,this.form=this.parent.find("#"+i+"-form"),this.settingsKey=t.Admin.Helpers.Context.getSettingsKey(),this.currentTab=this.parent.find(".mabel-nav-tab-active").data("tab"),this.sidebars=this.parent.find(".mabel-sidebar"),this.mainSidebar=this.sidebars.filter('[data-sidebar-for="main"]'),this.initTabs(),this.initDependencies(),this.toggleSidebars(),this.initAjax(),this.initEvents()}return e.prototype.initEvents=function(){var e=this,i=window.tb_remove;window.tb_remove=function(){i(),t.Admin.Dispatcher.publish("modal:closed"),e.saveSettings()},t.Admin.Dispatcher.subscribe("settings:save",function(){e.saveSettings()})},e.prototype.initAjax=function(){var t=this;this.form.find('select, input[type="text"], textarea, input[type=checkbox]').not(".skip-save").on("change",function(){t.saveSettings()})},e.prototype.saveSettings=function(){var e=this;this.parent.find(".all-settings-saved").hide(),this.parent.find(".saving-settings").show();var i=this.form.serialize();jQuery.post("options.php",i).done(function(){e.parent.find(".all-settings-saved").show(),e.parent.find(".saving-settings").hide(),t.Admin.Dispatcher.publish("settings:saved",i)})},e.prototype.initDependencies=function(){var t=this;this.parent.find('[name*="'+this.settingsKey+'"]').each(function(e,i){var n=jQuery(i),s=n.data("dependency");if(s){var a=t.parent.find('[name="'+t.settingsKey+"["+s.element_id+']"]').not(".skip-dependency");a&&(a.on("change",function(){var t=a.val(),e=!1;if(a.is(":checkbox")){var i=a.is(":checked");t==s.value&&i&&(e=!0)}else t==s.value&&(e=!0);e?n.closest("tr").show():n.closest("tr").hide()}),a.trigger("change"))}})},e.prototype.initTabs=function(){var e=this,i=this.parent.find(".mabel-nav-tab-wrapper a"),n=this.parent.find(".mabel-tab");i.on("click",function(s){s.preventDefault();var a=jQuery(s.currentTarget),r=a.data("tab");i.removeClass("mabel-nav-tab-active"),a.addClass("mabel-nav-tab-active"),n.hide(),e.parent.find(".tab-"+r).show(),t.Admin.Dispatcher.publish("tab:changed",r),e.currentTab=r,e.toggleSidebars()})},e.prototype.toggleSidebars=function(){this.sidebars.hide();var t=this.sidebars.filter('[data-sidebar-for="'+this.currentTab+'"]');t.length&&!t.is(":empty")?t.show():this.mainSidebar.show()},e}();e.Main=i}(t.Admin||(t.Admin={}))}(Core||(Core={}));
var Core;!function(i){!function(i){var t=function(){function i(){}return i.subscribe=function(i,t){this.hOP.call(this.topics,i)||(this.topics[i]=[]);var o=this.topics[i].push(t)-1;return{remove:function(){delete this.topics[i][o]}}},i.publish=function(i,t){this.hOP.call(this.topics,i)&&this.topics[i].forEach(function(i){i(void 0!=t?t:{})})},i.topics=[],i.hOP=[].hasOwnProperty,i}();i.Dispatcher=t}(i.Admin||(i.Admin={}))}(Core||(Core={}));
var Core;!function(t){!function(t){!function(t){var n=function(){function t(){}return t.getSlug=function(){return jQuery("[data-context]").data("slug")},t.getSettingsKey=function(){return jQuery("[data-context]").data("settings-key")},t.getAdminAjaxUrl=function(){return jQuery("[data-context]").data("admin-ajax-url")},t}();t.Context=n}(t.Helpers||(t.Helpers={}))}(t.Admin||(t.Admin={}))}(Core||(Core={}));
var BHIAdmin;!function(e){var n=function(){function n(n){this.home=n;var r=(new e.AjaxHelper(n),new e.TemplateHelper(n)),i=new e.LocationHelper(n,r);new e.HoursHelper(n,r,i),new e.EventHelper(n,i)}return n}();e.Main=n}(BHIAdmin||(BHIAdmin={})),jQuery(document).ready(function(){new BHIAdmin.Main(jQuery(document.body))});
var BHIAdmin;!function(t){var i=function(){function t(t){var i=this;this.parent=t,this.url=Core.Admin.Helpers.Context.getAdminAjaxUrl(),this.exampleIndicator=this.parent.find(".example-indicator"),this.exampleList=this.parent.find(".example-list"),this.updateExamples(),Core.Admin.Dispatcher.subscribe("settings:saved",function(){i.updateExamples()})}return t.prototype.updateExamples=function(){var t=this;this.exampleList.html('<div class="t-c">Updating...</div>'),this.exampleIndicator.html('<div class="t-c">Updating...</div>'),jQuery.post(this.url,{action:"mb-bhi-update-indicator"},function(i){t.exampleIndicator.html(i)}),jQuery.post(this.url,{action:"mb-bhi-update-list"},function(i){t.exampleList.html(i)})},t}();t.AjaxHelper=i}(BHIAdmin||(BHIAdmin={}));
var BHIAdmin;!function(i){var n=function(){function i(i,n){this.home=i,this.locationHelper=n,this.initEvents()}return i.prototype.initEvents=function(){var i=this;Core.Admin.Dispatcher.subscribe("/locations/changed",function(n){i.home.find('input[name="mb-bhi-settings[locations]"]').val(JSON.stringify(n)),Core.Admin.Dispatcher.publish("settings:save")}),Core.Admin.Dispatcher.subscribe("modal:closed",function(){i.locationHelper.setCurrentLocation(null)})},i}();i.EventHelper=n}(BHIAdmin||(BHIAdmin={}));
var BHIAdmin;!function(t){var e=function(){function t(t,e,o){this.home=t,this.locationDisplay=t.find(".loc-display"),this.templateHelper=e,this.locationHelper=o,this.openHours(),this.addHours(),this.openHolidays(),this.addHoliday(),this.deleteHoliday(),this.openVacations(),this.addVacation(),this.deleteVacation()}return t.prototype.openHours=function(){var t=this;this.locationDisplay.on("click",".btn-open-edit-hours",function(e){e.preventDefault();var o=jQuery(this),a=t.locationHelper.getLocationByName(o.data("loc"));a&&a.Days&&(t.templateHelper.drawTemplate("businesshours",a.Days),t.locationHelper.setCurrentLocation(a),window.tb_show("Edit Holidays for "+a.Name,"#TB_inline?height=550&amp;width=600&amp;inlineId=add-hours"))})},t.prototype.addHours=function(){var t=this;this.home.find(".btn-edit-hours").on("click",function(e){e.preventDefault();var o=[];jQuery(".add-hours-table tr").each(function(e,a){var i=jQuery(a),n=i.data("day"),r={Day:n,Hours:[]};r.Hours=t.validateAndAdd(i),o.push(r)}),t.locationHelper.getCurrentLocation().Days=o,Core.Admin.Dispatcher.publish("/locations/changed",t.locationHelper.getLocations()),window.tb_remove()})},t.prototype.openHolidays=function(){var t=this;this.locationDisplay.on("click",".btn-open-edit-specials",function(e){e.preventDefault();var o=t.locationHelper.getLocationByName(jQuery(this).data("loc"));o&&(t.templateHelper.drawTemplate("showholiday",o.Holidays),t.templateHelper.drawTemplate("addholiday",{}),t.locationHelper.setCurrentLocation(o),window.tb_show("Edit holidays for "+o.Name,"#TB_inline?height=550&amp;width=500&amp;inlineId=add-specials"))})},t.prototype.addHoliday=function(){var t=this;this.home.find(".add-specials-table").on("click",".btn-add-special",function(e){e.preventDefault();var o=jQuery(this).closest("tr"),a={Day:o.find(".date select[name=day]").val(),Month:o.find(".date select[name=month]").val(),Hours:[]};a.Hours=t.validateAndAdd(o);var i=t.locationHelper.getCurrentLocation();i.Holidays.push(a),t.templateHelper.drawTemplate("showholiday",i.Holidays),Core.Admin.Dispatcher.publish("/locations/changed",t.locationHelper.getLocations())})},t.prototype.deleteHoliday=function(){var t=this;this.home.find(".sd-display").on("click",".btn-delete",function(e){e.preventDefault();var o=jQuery(this),a=o.closest("tr");a.hide("fast",function(){a.remove();var e=t.locationHelper.getCurrentLocation(),i=o.data("holiday").split(",");e.Holidays=_.filter(e.Holidays,function(t){return t.Day!==i[0]||t.Month!==i[1]}),Core.Admin.Dispatcher.publish("/locations/changed",t.locationHelper.getLocations())})})},t.prototype.openVacations=function(){var t=this;this.locationDisplay.on("click",".btn-open-edit-vacation",function(e){e.preventDefault();var o=jQuery(this),a=t.locationHelper.getLocationByName(o.data("loc"));a&&(t.templateHelper.drawTemplate("showvacations",a.Vacations),t.templateHelper.drawTemplate("addvacation",{}),t.locationHelper.setCurrentLocation(a),window.tb_show("Edit vacations for "+a.Name,"#TB_inline?height=550&amp;width=500&amp;inlineId=add-vacation"))})},t.prototype.addVacation=function(){var t=this;this.home.find(".add-vacation-table").on("click",".btn-add-vacation",function(e){e.preventDefault();var o=jQuery(this).closest("tr"),a=t.locationHelper.getCurrentLocation();a.Vacations.push({FromDay:o.find("select[name=from-day]").val(),ToDay:o.find("select[name=to-day]").val(),From:o.find("select[name=from]").val(),To:o.find("select[name=to]").val()}),t.templateHelper.drawTemplate("showvacations",a.Vacations),Core.Admin.Dispatcher.publish("/locations/changed",t.locationHelper.getLocations())})},t.prototype.deleteVacation=function(){var t=this;this.home.find(".vac-display").on("click",".btn-delete",function(e){e.preventDefault();var o=jQuery(this).closest("tr");o.hide("fast",function(){o.remove(),t.locationHelper.getCurrentLocation().Vacations.splice(jQuery(".vac-display").find(".close").index(jQuery(this)),1),Core.Admin.Dispatcher.publish("/locations/changed",t.locationHelper.getLocations())})})},t.prototype.validateAndAdd=function(t){var e=[],o=this,a=!1;return t.find(".hours > div").each(function(t,i){var n=jQuery(i),r=n.find("select[name=From]").val(),l=n.find("select[name=To]").val(),s=n.find("select[name=ToIndication]").val(),d=n.find("select[name=FromIndication]").val(),c=o.to24(r,d),p=o.to24(l,s);_.every(e,function(t){var e=o.to24(t.From,t.FromIndication),a=o.to24(t.To,t.ToIndication);return e>=a&&(a+=24),e<c&&e<p&&a<c&&a<p||e>c&&e>p&&a>c&&a>p})?e.push({From:r,To:l,ToIndication:s,FromIndication:d}):a=!0}),a&&alert("One or more combinations weren't correct. They were not added to your time table"),e},t.prototype.to24=function(t,e){return t=t.split(":"),t[0]=parseInt(t[0]),t[1]=parseInt(t[1]),"PM"==e&&t[0]<12&&(t[0]=t[0]+12),"AM"==e&&12==t[0]&&(t[0]=24),parseFloat(t[0]+"."+t[1])},t}();t.HoursHelper=e}(BHIAdmin||(BHIAdmin={}));
var BHIAdmin;!function(t){var o=function(){function t(t,o){if(this.home=t,this.templateHelper=o,this.locationDisplay=t.find(".loc-display"),this.locations=jQuery.parseJSON(this.home.find('input[name="mb-bhi-settings[locations]"]').val())||[],this.emptylocation=jQuery.parseJSON(this.home.find(".locations-wrapper").attr("data-empty-object")),!this.emptylocation)throw"Empty location object not found.";this.init()}return t.prototype.init=function(){this.openLocationDialog(),this.addLocation(),this.deleteLocation(),this.templateHelper.drawTemplate("location",this.locations)},t.prototype.openLocationDialog=function(){var t=this;this.home.find(".btn-open-lpopup").on("click",function(o){o.preventDefault(),t.locations.length>=mabel_ajax.clamp?alert("To add more locations, please upgrade to the PRO version."):window.tb_show("Add a new location","#TB_inline?width=500&height=350&inlineId=add-location")})},t.prototype.addLocation=function(){var t=this;this.home.find(".btn-add-loc").click(function(o){if(o.preventDefault(),t.locations.length>=mabel_ajax.clamp)alert("To add more locations, please upgrade to the PRO version.");else{var e=jQuery.extend(!0,{},t.emptylocation),n=jQuery.trim(t.home.find("input[name=loc-name]").val());n&&(e.Name=t.escapeHtml(n),t.locations.push(e),t.templateHelper.drawTemplate("location",t.locations),Core.Admin.Dispatcher.publish("/locations/changed",t.getLocations()),window.tb_remove())}})},t.prototype.getLocations=function(){return this.locations},t.prototype.getLocationByName=function(t){return _.findWhere(this.locations,{Name:t})},t.prototype.setCurrentLocation=function(t){this.openLocation=t},t.prototype.getCurrentLocation=function(){return this.openLocation},t.prototype.deleteLocation=function(){var t=this;this.locationDisplay.on("click",".btn-delete",function(o){if(o.preventDefault(),confirm("Are you sure you want to do delete this entry?")){var e=jQuery(this),n=e.closest(".sd-entry");n.slideUp("fast",function(){n.remove(),t.locations=_.filter(t.locations,function(t){return t.Name!==e.data("loc")}),Core.Admin.Dispatcher.publish("/locations/changed",t.getLocations()),Core.Admin.Dispatcher.publish("settings:save")})}})},t.prototype.escapeHtml=function(t){var o={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;","/":"&frasl;"};return String(t).replace(/[&<>"'\/]/g,function(t){return o[t]})},t}();t.LocationHelper=o}(BHIAdmin||(BHIAdmin={}));
var BHIAdmin;!function(t){var e=function(){function t(t){this.home=t,this.config=[{id:"location",templateScriptId:"tplLocation",templateView:"loc-display"},{id:"businesshours",templateScriptId:"tplBusinessHours",subtemplates:[{name:"renderHours",templateScriptId:"tplHourSelect"},{name:"renderIndication",templateScriptId:"tplHourIndication"}],templateView:"add-hours-table"},{id:"showholiday",templateScriptId:"tplShowHoliday",templateView:"sd-display"},{id:"addholiday",templateView:"add-specials-table",templateScriptId:"tplAddHoliday",subtemplates:[{name:"renderHours",templateScriptId:"tplHourSelect"},{name:"renderIndication",templateScriptId:"tplHourIndication"}]},{id:"showvacations",templateScriptId:"tplShowVacations",templateView:"vac-display"},{id:"addvacation",templateScriptId:"tplAddVacation",templateView:"add-vacation-table"}],this.init()}return t.prototype.init=function(){var t=this;_.each(this.config,function(e){e.template=_.template(t.home.find("#"+e.templateScriptId).html()),e.subtemplates&&(e.subtemplateCache=[],_.each(e.subtemplates,function(a){e.subtemplateCache.push({name:a.name,template:_.template(t.home.find("#"+a.templateScriptId).html())})}))})},t.prototype.drawTemplate=function(t,e){var a=_.findWhere(this.config,{id:t});if(a){var i={model:e,templateEngine:function(t,e){return _.findWhere(a.subtemplateCache,{name:t}).template(e)}};this.home.find("."+a.templateView).html(a.template(i))}},t}();t.TemplateHelper=e}(BHIAdmin||(BHIAdmin={}));

10
admin/styles/shared/variables.less

@ -0,0 +1,10 @@
// Brand colors
@primary-color: #334094;
// Other colors
@gray: #888;
@lightgray: #d4d9d7;
@lightestgray: #f3f3f3;
@red: #FF5555;
@border-radius: 2px;

94
admin/views/codes.php

@ -0,0 +1,94 @@
<table class="form-table">
<tr>
<th>Indicator shortcode</th>
<td>
<code>
[mbhi location="your location name"]
</code>
<div class="p-t-2">
<span class="extra-info">
Use this shortcode to display the open/closed indicator anywhere in your posts or on your pages.
</span>
</div>
</td>
</tr>
<tr>
<th>Indicator shortcode for themes</th>
<td>
<code>
&lt;?php
echo do_shortcode('[mbhi location="your location name"]');
?&gt;
</code>
<div class="p-t-2">
<span class="extra-info">
This code allows you to use the indicator directly in your theme.
</span>
</div>
</td>
</tr>
<tr>
<th>Business hours shortcode</th>
<td>
<code>
[mbhi_hours location="your location name"]
</code>
<div class="p-t-2">
<span class="extra-info">
Use this shortcode to display your opening hours anywhere in your posts or on your pages.
</span>
</div>
</td>
</tr>
<tr>
<th>Business hours shortcode for themes</th>
<td>
<code>
&lt;?php
echo do_shortcode('[mbhi_hours location="your location name"]');
?&gt;
</code>
<div class="p-t-2">
<span class="extra-info">
This code allows you to show your opening times directly in your theme.
</span>
</div>
</td>
</tr>
<tr>
<th>'if open' shortcode</th>
<td>
<code>
[mbhi_ifopen location="your location name"]
Your content...
[/mbhi_ifopen]
</code>
<div class="p-t-2">
<span class="extra-info">
Use this shortcode to display something only when your business is currently open.
</span>
</div>
</td>
</tr>
<tr>
<th>'if closed' shortcode</th>
<td>
<code>
[mbhi_ifclosed location="your location name"]
Your content...
[/mbhi_ifclosed]
</code>
<div class="p-t-2">
<span class="extra-info">
Use this shortcode to display something only when your business is currently closed.
</span>
</div>
</td>
</tr>
<tr>
<th></th>
<td>
<a href="https://businesshourplugin.maartenbelmans.com/docs/free-documentation/usage/all-shortcodes/" target="_blank">Read the documentation</a> to find out all available options for shortcodes.
</td>
</tr>
</table>

0
admin/views/indicator-section.php

72
admin/views/locations.php

@ -0,0 +1,72 @@
<?php
if(!defined('ABSPATH')){die;}
?>
<div class="locations-wrapper" data-empty-object='{"Name":"","Days":[{"Day":"Monday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Tuesday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Wednesday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Thursday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Friday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Saturday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]},{"Day":"Sunday","Hours":[{"From":"0","To":"0","ToIndication":"PM","FromIndication":"AM"}]}],"Holidays":[],"Vacations":[]}'>
<input type="hidden" name="mb-bhi-settings[locations]" value='<?php echo json_encode($data['locations'],JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT );?>' />
<div id="add-location" style="display:none;">
<p>
The location name should be unique.
</p>
<table class="form-table">
<tr>
<th scope="row">Name</th>
<td>
<input type="text" name="loc-name" maxlength="50" class="skip-save" />
</td>
</tr>
<tr>
<th scope="row" colspan="2">
<a href="#" class="btn-add-loc mabel-btn">Add</a>
</th>
</tr>
</table>
</div>
<div id="add-hours" style="display:none;">
<p>When you're closed on a certain day, just leave the hours blank.<br/>Remember: 12PM is midday, 12AM is midnight.</p>
<table class="form-table table-hours">
<tbody class="add-hours-table">
</tbody>
</table>
<div class="modal-button-row">
<a href="#" class="btn-edit-hours mabel-btn">Done</a>
</div>
</div>
<div id="add-specials" style="display:none;">
<p>When you're closed on a certain day, just leave the hours blank.<br/>Remember: 12PM is midday, 12AM is midnight.</p>
<div class="sd-display-wrapper">
<table class="form-table sd-display"></table>
</div>
<hr/>
<table class="form-table add-specials-table">
</table>
<div class="modal-button-row">
<a href="javascript:tb_remove();" class="btn-edit-specials mabel-btn">Done</a>
</div>
</div>
<div id="add-vacation" style="display:none;">
<p>Denote when you're on vacation.</p>
<div class="sd-display-wrapper">
<table class="form-table vac-display"></table>
</div>
<hr/>
<table class="form-table add-vacation-table"></table>
<div class="modal-button-row">
<a href="javascript:tb_remove();" class="btn-edit-vacation mabel-btn">Done</a>
</div>
</div>
<div class="loc-display"></div>
</div>
<div class="p-t-3">
<a href="#" class="mabel-btn btn-open-lpopup">Add location</a>
</div>

8
admin/views/sidebar-indicator.php

@ -0,0 +1,8 @@
<div class="panel">
<h3 class="t-u t-c"><?php _e('Example',\MABEL_BHI_LITE\Core\Config_Manager::$slug) ?></h3>
<div class="p-t-3 example example-indicator">
<div class="t-c">
Fetching...
</div>
</div>
</div>

8
admin/views/sidebar-list.php

@ -0,0 +1,8 @@
<div class="panel">
<h3 class="t-u t-c"><?php _e('Example',\MABEL_BHI_LITE\Core\Config_Manager::$slug) ?></h3>
<div class="p-t-3 example example-list">
<div class="t-c">
Fetching...
</div>
</div>
</div>

14
admin/views/sidebar-main.php

@ -0,0 +1,14 @@
<div class="mabel-t-center">
<img src="<?php echo \MABEL_BHI_LITE\Core\Config_Manager::$url; ?>admin/img/bhilogo.png" style="opacity: 0.85;" class="u-max-200-width"/>
</div>
<div class="p-t-2">
<div>
<a class="mabel-btn mabel-btn-block" target="_blank" href="https://businesshourplugin.maartenbelmans.com/documentation/">Documentation</a>
</div>
<div class="p-t-2">
<a class="mabel-btn mabel-btn-block" target="_blank" href="https://businesshourplugin.maartenbelmans.com/#features">Want More? Check Pro Features</a>
</div>
<div class="p-t-2">
<a class="mabel-btn mabel-btn-block" target="_blank" href="http://eepurl.com/cgQWVP">News about discounts? Sign Up</a>
</div>
</div>

134
admin/views/underscore-templates.php

@ -0,0 +1,134 @@
<script type="text/underscore-tpl" id="tplLocation">
<% if(!model.length){ %>
<span style="padding-top:0;" class="extra-info">You have to add atleast one location before you can proceed.</span>
<%} else _.each(model, function(location){ %>
<div class="sd-entry" data-loc="<%=location.Name %>">
     <span><%= location.Name %></span>
<a href="#" data-loc="<%=location.Name %>" class="btn btn-delete"></a>
<a href="#" data-loc="<%=location.Name %>" class="primary btn-open-edit-vacation">Vacation</a>
<a href="#" data-loc="<%=location.Name %>" class="primary btn-open-edit-specials">Holidays</a>
<a href="#" data-loc="<%=location.Name %>" class="primary btn-open-edit-hours">Edit hours</a>
    </div>
<% }); %>
</script>
<script id="tplBusinessHours" type="text/underscore-tpl">
<% _.each(model, function(day){ %>
<tr data-day="<%= day.Day %>">
<th class="day"><%= day.Day %></th>
<td class="hours">
<% _.each(day.Hours, function(hour,idx){%>
<div>
<%= templateEngine('renderHours',{selected:hour.From, name:'From'}) %>
<%= templateEngine('renderIndication',{selected:hour.FromIndication, name:'FromIndication'}) %>
<%= templateEngine('renderHours',{selected:hour.To, name:'To'}) %>
<%= templateEngine('renderIndication',{selected:hour.ToIndication, name:'ToIndication'}) %>
</div>
<% }); %>
</td>
</tr>
<% }); %>
</script>
<script id="tplHourSelect" type="text/underscore-tpl">
<select name="<%= name %>">
<option value="0"></option>
<% for(i=1;i<=12;i++){ %>
<option value="<%= i %>:00" <% if(i+':00'==selected){ %> selected <% } %> ><%= i %>:00</option>
<option value="<%= i %>:15" <% if(i+':15'==selected){ %> selected <% } %> ><%= i %>:15</option>
<option value="<%= i %>:30" <% if(i+':30'==selected){ %> selected <% } %> ><%= i %>:30</option>
<option value="<%= i %>:45" <% if(i+':45'==selected){ %> selected <% } %> ><%= i %>:45</option>
<% } %>
<select>
</script>
<script id="tplHourIndication" type="text/underscore-tpl">
<select name="<%= name %>">
<option valeu="AM" <% if(selected == 'AM'){ %> selected <%}%>>AM</option>
<option valeu="PM" <% if(selected == 'PM'){ %> selected <%}%>>PM</option>
</select>
</script>
<script id="tplAddHoliday" type="text/underscore-tpl">
<tr>
<td class="date">
<select name="month">
<% _.each(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],function(m){ %>
<option value="<%= m %>"><%= m %></option>
<% }); %>
</select>
<select name="day">
<% for(i=1;i<=31;i++){ %>
<option value="<%= i %>"><%= i %></option>
<% } %>
<select>
</td>
<td class="hours">
<div>
<%= templateEngine('renderHours',{selected:undefined, name:'From'}) %>
<%= templateEngine('renderIndication',{selected:"AM", name:'FromIndication'}) %>
<%= templateEngine('renderHours',{selected:undefined, name:'To'}) %>
<%= templateEngine('renderIndication',{selected:'PM', name:'ToIndication'}) %>
</div>
</td>
<td><a href="#" class="mabel-btn btn-add-special">+</a></td>
</tr>
</script>
<script id="tplShowHoliday" type="text/underscore-tpl">
<% _.each(model,function(holiday){ %>
<tr>
<th><%= holiday.Month %> <%= holiday.Day %></th>
<td>
<% if(holiday.Hours.length === 1 && (holiday.Hours[0].From == 0 || holiday.Hours[0].To == 0)){ %>
Closed
<% }else{
_.each(holiday.Hours,function(hour){ %>
<% if(hour.From!=0 && hour.To!=0){ %>
<%= hour.From %><%=hour.FromIndication%> &mdash; <%= hour.To %><%= hour.ToIndication%><br/>
<% } %>
<% });} %>
</td>
<td><a data-holiday="<%=holiday.Day%>,<%=holiday.Month%>" href="#" class="btn-delete"></a></td>
</tr>
<% }); %>
</script>
<script id="tplAddVacation" type="text/underscore-tpl">
<tr>
<td>
From
<select name="from">
<% _.each(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],function(m){ %>
<option value="<%= m %>"><%= m %></option>
<% }); %>
</select>
<select name="from-day">
<% for(i=1;i<=31;i++){ %>
<option value="<%= i %>"><%= i %></option>
<% } %>
<select>
</td>
<td>
To
<select name="to">
<% _.each(['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],function(m){ %>
<option value="<%= m %>"><%= m %></option>
<% }); %>
</select>
<select name="to-day">
<% for(i=1;i<=31;i++){ %>
<option value="<%= i %>"><%= i %></option>
<% } %>
<select>
</td>
<td><a href="#" class="mabel-btn btn-add-vacation">+</a></td>
</tr>
</script>
<script id="tplShowVacations" type="text/underscore-tpl">
<% _.each(model,function(vaca){ %>
<tr>
<td class="from">
<span class="fromday"><%= vaca.FromDay %></span> <span class="from"><%= vaca.From %></span>
</td>
<td class="to">
<span class="today"><%= vaca.ToDay %></span> <span class="to"><%= vaca.To %></span>
</td>
<td><a href="#" class="btn btn-delete"></a></td>
</tr>
<% }); %>
</script>

151
api/class-api.php

@ -0,0 +1,151 @@
<?php
namespace MABEL_BHI_LITE\API
{
if(!defined('ABSPATH')) exit;
use Exception;
use MABEL_BHI_LITE\Core\Linq\Enumerable;
use MABEL_BHI_LITE\Core\Settings_Manager;
use MABEL_BHI_LITE\Models\Opening_Hours_Set;
use MABEL_BHI_LITE\Models\Special_Date;
use MABEL_BHI_LITE\Models\Vacation;
use MABEL_BHI_LITE\Services\Conversion_Service;
use MABEL_BHI_LITE\Services\Opening_Hours_Service;
/**
* Class Api Easily accessible functions to be used by theme/plugin developers.
*/
class API
{
/**
* @var array location_name => Location. Location cache.
*/
private $location_cache = array();
private static $instance = null;
public static function instance()
{
if (self::$instance === null)
self::$instance = new API();
return self::$instance;
}
public function get_specials($location_name)
{
if(empty($location_name) ||!is_string($location_name))
throw new Exception("Invalid location name.");
$location = $this->get_location($location_name);
if($location === null)
throw new Exception("No location found with name '".$location_name."'");
return Enumerable::from($location->specials)->select(function($x){
/** @var Special_Date $x */
$hours = Enumerable::from($x->opening_hours)->select(function($y){
return (object) array(
'start' => $y->start,
'end' => $y->end
);
})->toArray();
return (object) array(
'date' => $x->date,
'hours' => $hours,
'is_closed' => $x->is_closed()
);
})->toArray();
}
public function get_vacations($location_name)
{
if(empty($location_name) ||!is_string($location_name))
throw new Exception("Invalid location name.");
$location = $this->get_location($location_name);
if($location === null)
throw new Exception("No location found with name '".$location_name."'");
return Enumerable::from($location->vacations)->select(function($x){
/** @var Vacation $x */
return (object) array(
'from' => $x->from,
'to' => $x->to
);
})->toArray();
}
/**
* @param $location_name string location name
* @return array
*/
public function get_opening_hours($location_name)
{
if(empty($location_name) ||!is_string($location_name))
throw new Exception("Invalid location name.");
$location = $this->get_location($location_name);
if($location === null)
throw new Exception("No location found with name '".$location_name."'");
return Enumerable::from($location->opening_hours)->select(function($x){
/** @var Opening_Hours_Set $x */
$hours = Enumerable::from($x->opening_hours)->select(function($y){
return (object) array(
'start' => $y->start,
'end' => $y->end
);
})->toArray();
return (object) array(
'day' => $x->day_name,
'hours' => $hours,
'is_closed' => $x->is_closed()
);
})->toArray();
}
/**
* @param $location_name string location name
* @return bool
*/
public function is_open($location_name)
{
if(empty($location_name) ||!is_string($location_name))
throw new Exception("Invalid location name.");
$location = $this->get_location($location_name);
if($location === null)
throw new Exception("No location found with name '".$location_name."'");
return Opening_Hours_Service::instance()->is_open($location);
}
public function is_closed($location_name)
{
$is_open = $this->is_open($location_name);
return !$is_open;
}
#region Private helpers
private function get_location($name)
{
if(array_key_exists($name,$this->location_cache))
return $this->location_cache[$name];
$location = Conversion_Service::convert_to_location(
Settings_Manager::get_setting('locations'),
$name
);
$this->location_cache[$name] = $location;
return $location;
}
#endregion
}
}

78
class-business-hours-indicator.php

@ -0,0 +1,78 @@
<?php
namespace MABEL_BHI_LITE
{
if(!defined('ABSPATH')){die;}
use MABEL_BHI_LITE\Controllers\Admin_Controller;
use MABEL_BHI_LITE\Controllers\Shortcode_Controller;
use MABEL_BHI_LITE\Controllers\Widgets_Controller;
use MABEL_BHI_LITE\Core\Config_Manager;
use MABEL_BHI_LITE\Core\Language_Manager;
use MABEL_BHI_LITE\Core\Registry;
use MABEL_BHI_LITE\Core\Settings_Manager;
class Business_Hours_Indicator
{
/**
* @var Language_Manager language manager.
*/
protected $language_manager;
/**
* Business_Hours_Indicator constructor.
*
* @param $dir string
* @param $url string
* @param $slug string
* @param $version string
*/
public function __construct($dir, $url, $plugin_base, $name, $version)
{
// Init meta info.
Config_Manager::init($dir, $url, $plugin_base, $version, MABEL_BHI_LITE_SETTINGS, $name);
}
public function run()
{
// Init translations.
$this->language_manager = new Language_Manager();
// Init settings with defaults.
Settings_Manager::init(array(
'openline'=> "We're open",
'closedline'=> "Sorry, we're closed",
'closedsoonline'=> "Closing in {x} minutes",
'opensoonline'=> "Opening in {x} minutes",
'includetime' => false,
'includeday' =>false,
'timezone'=>get_option('timezone_string'),
'format'=>'12',
'approximation'=>false,
'warning'=>45,
'warningclosing'=>45,
'tabledisplaymode'=>'normal',
'output'=> 'table',
'includespecialdates' => false,
'includevacations' => false
));
// Kick off admin page.
new Admin_Controller();
// Register shortcodes
new Shortcode_Controller();
// Widgets
new Widgets_Controller();
// Kick off!
Registry::get_loader()->run();
}
}
}

240
controllers/class-admin-controller.php

@ -0,0 +1,240 @@
<?php
namespace MABEL_BHI_LITE\Controllers
{
use MABEL_BHI_LITE\Core\Admin;
use DateTimeZone;
use MABEL_BHI_LITE\Core\Config_Manager;
use MABEL_BHI_LITE\Core\Models\Option_Dependency;
use MABEL_BHI_LITE\Core\Options_Manager;
use MABEL_BHI_LITE\Core\Settings_Manager;
if(!defined('ABSPATH')){die;}
class Admin_Controller extends Admin
{
private $slug;
public function __construct()
{
parent::__construct(new Options_Manager());
$this->slug = Config_Manager::$slug;
$this->add_script_dependencies(array('underscore'));
$this->add_script_variable('clamp', 3);
$this->init_admin_page();
$this->add_ajax_function('mb-bhi-update-indicator',$this,'update_indicator',false,true);
$this->add_ajax_function('mb-bhi-update-list',$this,'update_list',false, true);
}
public function update_list()
{
echo do_shortcode('[mbhi_hours]');
wp_die();
}
public function update_indicator()
{
echo do_shortcode('[mbhi]');
wp_die();
}
private function init_admin_page()
{
$this->options_manager->add_section('general', __('General',$this->slug), 'admin-tools', true);
$this->options_manager->add_section('hours', __('Hours',$this->slug), 'clock');
$this->options_manager->add_section('indicator', __('Indicator',$this->slug), 'arrow-down-alt');
$this->options_manager->add_section('table', __('Table',$this->slug), 'editor-table');
$this->options_manager->add_section('codes', __('Codes',$this->slug),'editor-code');
$timezones = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
$locations = Settings_Manager::get_setting('locations');
$this->options_manager->add_dropdown_option(
'general',
'timezone',
__('Time zone',$this->slug),
array_combine($timezones,$timezones),
Settings_Manager::get_setting('timezone')
);
$this->options_manager->add_dropdown_option(
'general',
'format',
__('Time format',$this->slug),
array(12 => __('12-hour format',$this->slug), 24 => __('24-hour format',$this->slug)),
Settings_Manager::get_setting('format')
);
$this->options_manager->add_custom_option(
'hours',
__('Locations',$this->slug),
'admin/views/locations.php',
array('locations' => json_decode($locations))
);
$this->options_manager->add_text_option(
'indicator',
'openline',
__('Now open message',$this->slug),
Settings_Manager::get_translated_setting('openline'),
null,
__('HTML is allowed.',$this->slug)
);
$this->options_manager->add_text_option(
'indicator',
'closedline',
__('Now closed message', $this->slug),
Settings_Manager::get_translated_setting('closedline'),
null,
__('HTML is allowed.',$this->slug)
);
$this->options_manager->add_checkbox_option(
'indicator',
'includetime',
__('Include time', $this->slug),
__('Include the current time in the output.', $this->slug),
Settings_Manager::get_setting('includetime')
);
$this->options_manager->add_checkbox_option(
'indicator',
'includeday',
__('Include day', $this->slug),
__('Include the current day in the output.'),
Settings_Manager::get_setting('includeday')
);
$this->options_manager->add_checkbox_option(
'indicator',
'approximation',
__('Opening/closing soon warning', $this->slug),
__('When it\'s near opening or closing time, show a different message.', $this->slug),
Settings_Manager::get_setting('approximation')
);
$this->options_manager->add_text_option(
'indicator',
'opensoonline',
__('Opening soon message',$this->slug),
Settings_Manager::get_translated_setting('opensoonline'),
null,
__('HTML is allowed. Use {x} to denote minutes.',$this->slug),
new Option_Dependency('approximation','true')
);
$this->options_manager->add_text_option(
'indicator',
'closedsoonline',
__('Closing soon message', $this->slug),
Settings_Manager::get_translated_setting('closedsoonline'),
null,
__('HTML is allowed. Use {x} to denote minutes.',$this->slug),
new Option_Dependency('approximation','true')
);
$this->options_manager->add_dropdown_option(
'indicator',
'warning',
__('Opening soon warning', $this->slug),
array(15 => 15, 30 => 30, 45 => 45),
Settings_Manager::get_setting('warning'),
null,
new Option_Dependency('approximation', 'true'),
__("Show 'opening soon' warning ", $this->slug),
__('minutes in advance.', $this->slug)
);
$this->options_manager->add_dropdown_option(
'indicator',
'warningclosing',
__('Closing soon warning', $this->slug),
array(15 => 15, 30 => 30, 45 => 45),
Settings_Manager::get_setting('warningclosing'),
null,
new Option_Dependency('approximation', 'true'),
__("Show 'closing soon' warning ", $this->slug),
__('minutes in advance.', $this->slug)
);
$this->options_manager->add_dropdown_option(
'table',
'tabledisplaymode',
__('Display mode', $this->slug),
array( 0 => __('Normal', $this->slug) , 1 => __('Consolidated', $this->slug) ),
Settings_Manager::get_setting('tabledisplaymode')
);
$this->options_manager->add_dropdown_option(
'table',
'output',
__('Output', $this->slug),
array( 1 => __('Table',$this->slug) , 2 => __('Inline',$this->slug) ),
Settings_Manager::get_setting('output')
);
$this->options_manager->add_checkbox_option(
'table',
'includespecialdates',
__('Include holidays', $this->slug),
__('Add holidays to the hours table.', $this->slug),
Settings_Manager::get_setting('includespecialdates')
);
$this->options_manager->add_checkbox_option(
'table',
'includevacations',
__('Include vacations', $this->slug),
__('Add vacations to the hours table.', $this->slug),
Settings_Manager::get_setting('includevacations')
);
$this->loader->add_action(Config_Manager::$slug . '-add-section-content-codes',$this,'codes_content');
$this->loader->add_action(Config_Manager::$slug . '-add-content', $this , 'underscore_templates');
$this->loader->add_action(Config_Manager::$slug . '-render-sidebar', $this,'render_main_sidebar');
$this->loader->add_action(Config_Manager::$slug . '-render-sidebar-indicator', $this,'render_indicator_sidebar');
$this->loader->add_action(Config_Manager::$slug . '-render-sidebar-table', $this,'render_list_sidebar');
}
public function render_list_sidebar()
{
include Config_Manager::$dir . 'admin/views/sidebar-list.php';
}
public function render_indicator_sidebar()
{
include Config_Manager::$dir . 'admin/views/sidebar-indicator.php';
}
public function render_main_sidebar()
{
include Config_Manager::$dir . 'admin/views/sidebar-main.php';
}
public function indicator_section()
{
include Config_Manager::$dir . 'admin/views/indicator-section.php';
}
public function underscore_templates()
{
include Config_Manager::$dir . 'admin/views/underscore-templates.php';
}
public function codes_content()
{
include Config_Manager::$dir . 'admin/views/codes.php';
}
}
}

379
controllers/class-shortcode-controller.php

@ -0,0 +1,379 @@
<?php
namespace MABEL_BHI_LITE\Controllers
{
use MABEL_BHI_LITE\Core\Config_Manager;
use MABEL_BHI_LITE\Core\Linq\Enumerable;
use MABEL_BHI_LITE\Core\Settings_Manager;
use MABEL_BHI_LITE\Core\Shortcode;
use MABEL_BHI_LITE\Models\IfOpenClosed_VM;
use MABEL_BHI_LITE\Models\Indicator_VM;
use MABEL_BHI_LITE\Models\List_VM;
use MABEL_BHI_LITE\Models\List_VM_Entry;
use MABEL_BHI_LITE\Models\Location;
use MABEL_BHI_LITE\Models\Opening_Hours_Set;
use MABEL_BHI_LITE\Services\Conversion_Service;
use MABEL_BHI_LITE\Services\DateTime_Service;
use MABEL_BHI_LITE\Services\Opening_Hours_Service;
if(!defined('ABSPATH')){die;}
class Shortcode_Controller
{
private $slug;
private static $format_12 = 'g:i A';
private static $format_24 = 'G:i';
public function __construct()
{
$this->slug = Config_Manager::$slug;
$this->init_hours_list_shortcode();
$this->init_isopenclosed_shortcodes();
$this->init_indicator_shortcode();
}
#region Indicator Shortcode
private function init_indicator_shortcode()
{
new Shortcode(
'mbhi',
'indicator.php',
array($this,'create_indicator_model'),
array(
'location' => null,
'includetime' => Settings_Manager::get_setting('includetime'),
'includeday' => Settings_Manager::get_setting('includeday'),
'format' => Settings_Manager::get_setting('format'),
'approximation' => Settings_Manager::get_setting('approximation'),
'openingsoonmessagetime' => (int)Settings_Manager::get_setting('warning') * 60,
'closingsoonmessagetime' => (int)Settings_Manager::get_setting('warningclosing') * 60,
'openmessage' => Settings_Manager::get_translated_setting('openline'),
'closedmessage' => Settings_Manager::get_translated_setting('closedline'),
'openingsoonmessage' => Settings_Manager::get_translated_setting('opensoonline'),
'closingsoonmessage' => Settings_Manager::get_translated_setting('closedsoonline'),
)
);
}
public function create_indicator_model($attributes)
{
$model = new Indicator_VM();
$model->slug = $this->slug;
$location = Conversion_Service::convert_to_location(Settings_Manager::get_setting('locations'),$attributes['location']);
if($location == null){
$model->show_location_error = true;