Restaurant Reservations - Version 1.0.1

Version Description

(2014-05-08) = * Replace dashicons caret with CSS-only caret in booking form

Download this release

Release Info

Developer NateWr
Plugin Icon 128x128 Restaurant Reservations
Version 1.0.1
Comparing to
See all releases

Version 1.0.1

Files changed (92) hide show
  1. GPL.txt +280 -0
  2. assets/css/admin.css +91 -0
  3. assets/css/booking-form.css +73 -0
  4. assets/js/admin.js +22 -0
  5. assets/js/booking-form.js +201 -0
  6. docs/index.html +169 -0
  7. docs/style.css +31 -0
  8. includes/Booking.class.php +421 -0
  9. includes/CustomPostTypes.class.php +231 -0
  10. includes/Notification.Email.class.php +187 -0
  11. includes/Notification.class.php +106 -0
  12. includes/Notifications.class.php +187 -0
  13. includes/Settings.class.php +540 -0
  14. includes/WP_List_Table.BookingsTable.class.php +650 -0
  15. includes/WP_Widget.BookingFormWidget.class.php +87 -0
  16. includes/template-functions.php +283 -0
  17. lib/simple-admin-pages/README.md +379 -0
  18. lib/simple-admin-pages/classes/AdminPage.Submenu.class.php +38 -0
  19. lib/simple-admin-pages/classes/AdminPage.Themes.class.php +15 -0
  20. lib/simple-admin-pages/classes/AdminPage.class.php +215 -0
  21. lib/simple-admin-pages/classes/AdminPageSection.class.php +132 -0
  22. lib/simple-admin-pages/classes/AdminPageSetting.Editor.class.php +44 -0
  23. lib/simple-admin-pages/classes/AdminPageSetting.HTML.class.php +33 -0
  24. lib/simple-admin-pages/classes/AdminPageSetting.OpeningHours.class.php +167 -0
  25. lib/simple-admin-pages/classes/AdminPageSetting.Scheduler.class.php +596 -0
  26. lib/simple-admin-pages/classes/AdminPageSetting.Select.class.php +60 -0
  27. lib/simple-admin-pages/classes/AdminPageSetting.SelectPost.class.php +61 -0
  28. lib/simple-admin-pages/classes/AdminPageSetting.SelectTaxonomy.class.php +66 -0
  29. lib/simple-admin-pages/classes/AdminPageSetting.Text.class.php +35 -0
  30. lib/simple-admin-pages/classes/AdminPageSetting.Textarea.class.php +56 -0
  31. lib/simple-admin-pages/classes/AdminPageSetting.Toggle.class.php +43 -0
  32. lib/simple-admin-pages/classes/AdminPageSetting.class.php +225 -0
  33. lib/simple-admin-pages/classes/Library.class.php +406 -0
  34. lib/simple-admin-pages/css/admin.css +225 -0
  35. lib/simple-admin-pages/js/admin.js +340 -0
  36. lib/simple-admin-pages/lib/pickadate/legacy.js +10 -0
  37. lib/simple-admin-pages/lib/pickadate/picker.date.js +5 -0
  38. lib/simple-admin-pages/lib/pickadate/picker.js +7 -0
  39. lib/simple-admin-pages/lib/pickadate/picker.time.js +5 -0
  40. lib/simple-admin-pages/lib/pickadate/themes/default.css +4 -0
  41. lib/simple-admin-pages/lib/pickadate/themes/default.date.css +1 -0
  42. lib/simple-admin-pages/lib/pickadate/themes/default.time.css +1 -0
  43. lib/simple-admin-pages/lib/pickadate/themes/rtl.css +3 -0
  44. lib/simple-admin-pages/lib/pickadate/translations/ar.js +1 -0
  45. lib/simple-admin-pages/lib/pickadate/translations/bg_BG.js +1 -0
  46. lib/simple-admin-pages/lib/pickadate/translations/bs_BA.js +1 -0
  47. lib/simple-admin-pages/lib/pickadate/translations/ca_ES.js +1 -0
  48. lib/simple-admin-pages/lib/pickadate/translations/cs_CZ.js +1 -0
  49. lib/simple-admin-pages/lib/pickadate/translations/da_DK.js +1 -0
  50. lib/simple-admin-pages/lib/pickadate/translations/de_DE.js +1 -0
  51. lib/simple-admin-pages/lib/pickadate/translations/el_GR.js +1 -0
  52. lib/simple-admin-pages/lib/pickadate/translations/es_ES.js +1 -0
  53. lib/simple-admin-pages/lib/pickadate/translations/et_EE.js +1 -0
  54. lib/simple-admin-pages/lib/pickadate/translations/eu_ES.js +1 -0
  55. lib/simple-admin-pages/lib/pickadate/translations/fi_FI.js +1 -0
  56. lib/simple-admin-pages/lib/pickadate/translations/fr_FR.js +1 -0
  57. lib/simple-admin-pages/lib/pickadate/translations/gl_ES.js +1 -0
  58. lib/simple-admin-pages/lib/pickadate/translations/he_IL.js +1 -0
  59. lib/simple-admin-pages/lib/pickadate/translations/hr_HR.js +1 -0
  60. lib/simple-admin-pages/lib/pickadate/translations/hu_HU.js +1 -0
  61. lib/simple-admin-pages/lib/pickadate/translations/id_ID.js +1 -0
  62. lib/simple-admin-pages/lib/pickadate/translations/is_IS.js +1 -0
  63. lib/simple-admin-pages/lib/pickadate/translations/it_IT.js +1 -0
  64. lib/simple-admin-pages/lib/pickadate/translations/ja_JP.js +1 -0
  65. lib/simple-admin-pages/lib/pickadate/translations/ko_KR.js +1 -0
  66. lib/simple-admin-pages/lib/pickadate/translations/nl_NL.js +1 -0
  67. lib/simple-admin-pages/lib/pickadate/translations/no_NO.js +1 -0
  68. lib/simple-admin-pages/lib/pickadate/translations/pl_PL.js +1 -0
  69. lib/simple-admin-pages/lib/pickadate/translations/pt_BR.js +1 -0
  70. lib/simple-admin-pages/lib/pickadate/translations/pt_PT.js +1 -0
  71. lib/simple-admin-pages/lib/pickadate/translations/ro_RO.js +1 -0
  72. lib/simple-admin-pages/lib/pickadate/translations/ru_RU.js +1 -0
  73. lib/simple-admin-pages/lib/pickadate/translations/sk_SK.js +1 -0
  74. lib/simple-admin-pages/lib/pickadate/translations/sl_SI.js +1 -0
  75. lib/simple-admin-pages/lib/pickadate/translations/sv_SE.js +1 -0
  76. lib/simple-admin-pages/lib/pickadate/translations/th_TH.js +1 -0
  77. lib/simple-admin-pages/lib/pickadate/translations/tr_TR.js +1 -0
  78. lib/simple-admin-pages/lib/pickadate/translations/uk_UA.js +1 -0
  79. lib/simple-admin-pages/lib/pickadate/translations/zh_CN.js +1 -0
  80. lib/simple-admin-pages/lib/pickadate/translations/zh_TW.js +1 -0
  81. lib/simple-admin-pages/simple-admin-pages.php +57 -0
  82. readme.txt +61 -0
  83. restaurant-reservations.php +334 -0
  84. screenshot-1.PNG +0 -0
  85. screenshot-2.PNG +0 -0
  86. screenshot-3.PNG +0 -0
  87. screenshot-4.PNG +0 -0
  88. screenshot-5.PNG +0 -0
  89. screenshot-6.PNG +0 -0
  90. screenshot-7.PNG +0 -0
  91. screenshot-8.PNG +0 -0
  92. screenshot-9.PNG +0 -0
GPL.txt ADDED
@@ -0,0 +1,280 @@
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
6
+
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+ Preamble
11
+
12
+ The licenses for most software are designed to take away your
13
+ freedom to share and change it. By contrast, the GNU General Public
14
+ License is intended to guarantee your freedom to share and change free
15
+ software--to make sure the software is free for all its users. This
16
+ General Public License applies to most of the Free Software
17
+ Foundation's software and to any other program whose authors commit to
18
+ using it. (Some other Free Software Foundation software is covered by
19
+ the GNU Library General Public License instead.) You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ this service if you wish), that you receive source code or can get it
26
+ if you want it, that you can change the software or use pieces of it
27
+ in new free programs; and that you know you can do these things.
28
+
29
+ To protect your rights, we need to make restrictions that forbid
30
+ anyone to deny you these rights or to ask you to surrender the rights.
31
+ These restrictions translate to certain responsibilities for you if you
32
+ distribute copies of the software, or if you modify it.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must give the recipients all the rights that
36
+ you have. You must make sure that they, too, receive or can get the
37
+ source code. And you must show them these terms so they know their
38
+ rights.
39
+
40
+ We protect your rights with two steps: (1) copyright the software, and
41
+ (2) offer you this license which gives you legal permission to copy,
42
+ distribute and/or modify the software.
43
+
44
+ Also, for each author's protection and ours, we want to make certain
45
+ that everyone understands that there is no warranty for this free
46
+ software. If the software is modified by someone else and passed on, we
47
+ want its recipients to know that what they have is not the original, so
48
+ that any problems introduced by others will not reflect on the original
49
+ authors' reputations.
50
+
51
+ Finally, any free program is threatened constantly by software
52
+ patents. We wish to avoid the danger that redistributors of a free
53
+ program will individually obtain patent licenses, in effect making the
54
+ program proprietary. To prevent this, we have made it clear that any
55
+ patent must be licensed for everyone's free use or not licensed at all.
56
+
57
+ The precise terms and conditions for copying, distribution and
58
+ modification follow.
59
+
60
+ GNU GENERAL PUBLIC LICENSE
61
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
62
+
63
+ 0. This License applies to any program or other work which contains
64
+ a notice placed by the copyright holder saying it may be distributed
65
+ under the terms of this General Public License. The "Program", below,
66
+ refers to any such program or work, and a "work based on the Program"
67
+ means either the Program or any derivative work under copyright law:
68
+ that is to say, a work containing the Program or a portion of it,
69
+ either verbatim or with modifications and/or translated into another
70
+ language. (Hereinafter, translation is included without limitation in
71
+ the term "modification".) Each licensee is addressed as "you".
72
+
73
+ Activities other than copying, distribution and modification are not
74
+ covered by this License; they are outside its scope. The act of
75
+ running the Program is not restricted, and the output from the Program
76
+ is covered only if its contents constitute a work based on the
77
+ Program (independent of having been made by running the Program).
78
+ Whether that is true depends on what the Program does.
79
+
80
+ 1. You may copy and distribute verbatim copies of the Program's
81
+ source code as you receive it, in any medium, provided that you
82
+ conspicuously and appropriately publish on each copy an appropriate
83
+ copyright notice and disclaimer of warranty; keep intact all the
84
+ notices that refer to this License and to the absence of any warranty;
85
+ and give any other recipients of the Program a copy of this License
86
+ along with the Program.
87
+
88
+ You may charge a fee for the physical act of transferring a copy, and
89
+ you may at your option offer warranty protection in exchange for a fee.
90
+
91
+ 2. You may modify your copy or copies of the Program or any portion
92
+ of it, thus forming a work based on the Program, and copy and
93
+ distribute such modifications or work under the terms of Section 1
94
+ above, provided that you also meet all of these conditions:
95
+
96
+ a) You must cause the modified files to carry prominent notices
97
+ stating that you changed the files and the date of any change.
98
+
99
+ b) You must cause any work that you distribute or publish, that in
100
+ whole or in part contains or is derived from the Program or any
101
+ part thereof, to be licensed as a whole at no charge to all third
102
+ parties under the terms of this License.
103
+
104
+ c) If the modified program normally reads commands interactively
105
+ when run, you must cause it, when started running for such
106
+ interactive use in the most ordinary way, to print or display an
107
+ announcement including an appropriate copyright notice and a
108
+ notice that there is no warranty (or else, saying that you provide
109
+ a warranty) and that users may redistribute the program under
110
+ these conditions, and telling the user how to view a copy of this
111
+ License. (Exception: if the Program itself is interactive but
112
+ does not normally print such an announcement, your work based on
113
+ the Program is not required to print an announcement.)
114
+
115
+ These requirements apply to the modified work as a whole. If
116
+ identifiable sections of that work are not derived from the Program,
117
+ and can be reasonably considered independent and separate works in
118
+ themselves, then this License, and its terms, do not apply to those
119
+ sections when you distribute them as separate works. But when you
120
+ distribute the same sections as part of a whole which is a work based
121
+ on the Program, the distribution of the whole must be on the terms of
122
+ this License, whose permissions for other licensees extend to the
123
+ entire whole, and thus to each and every part regardless of who wrote it.
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
assets/css/admin.css ADDED
@@ -0,0 +1,91 @@
1
+ /* CSS Stylesheet for the admin interface for Restaurant Reservations */
2
+
3
+ .clearfix:before,
4
+ .clearfix:after { /* thanks bootstrap */
5
+ content: " ";
6
+ display: table;
7
+ }
8
+
9
+ .clearfix:after {
10
+ clear: both;
11
+ }
12
+
13
+ /* Bookings Table */
14
+ #rtb-bookings-table .subsubsub {
15
+ float: right;
16
+ }
17
+
18
+ #rtb-bookings-table .subsubsub .trash a {
19
+ color: #a00;
20
+ }
21
+
22
+ #rtb-bookings-table .subsubsub .trash a:hover {
23
+ color: red;
24
+ }
25
+
26
+ #rtb-filters {
27
+ float: left;
28
+ }
29
+
30
+ #rtb-filters .subsubsub {
31
+ margin-bottom: 0.5em;
32
+ float: none;
33
+ }
34
+
35
+ #rtb-filters .date-filters {
36
+ clear: both;
37
+ padding: 1em;
38
+ margin: 1em 0 2em;
39
+ background: #fff;
40
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
41
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
42
+ }
43
+
44
+ #rtb-filters .date-filters .datepicker {
45
+ max-width: 10em;
46
+ }
47
+
48
+ #rtb-filters .current {
49
+ font-weight: 600;
50
+ color: #000;
51
+ }
52
+
53
+ #rtb-bookings-table .column-message .rtb-message-data,
54
+ #rtb-bookings-table .message-row {
55
+ display: none;
56
+ }
57
+
58
+ #rtb-bookings-table tr.closed {
59
+ opacity: 0.7;
60
+ filter: opacity(alpha=70);
61
+ }
62
+ #rtb-bookings-table tr.closed:hover {
63
+ opacity: 1;
64
+ filter: opacity(alpha=100);
65
+ }
66
+
67
+ #rtb-bookings-table tr.pending .check-column,
68
+ #rtb-bookings-table tr.pending.message-row td {
69
+ border-left: 4px solid #dd3d36;
70
+ }
71
+
72
+ @media screen and (max-width: 782px) {
73
+
74
+ #rtb-bookings-table .fixed .column-date {
75
+ display: table-cell;
76
+ }
77
+ }
78
+
79
+ /* Settings Pages (most of this is handled by the Simple Admin Pages library) */
80
+ .rtb-template-tags-box {
81
+ margin-top: 0.5em;
82
+ padding: 1em;
83
+ border-left: 4px solid #2ea2cc;
84
+ background: #fff;
85
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
86
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
87
+ }
88
+ .rtb-template-tags-box strong {
89
+ min-width: 8em;
90
+ display: inline-block;
91
+ }
assets/css/booking-form.css ADDED
@@ -0,0 +1,73 @@
1
+ /* Frontend CSS Stylesheet for Restaurant Reservations */
2
+
3
+ .rtb-booking-form fieldset {
4
+ padding-bottom: 1em;
5
+ margin-bottom: 1em;
6
+ }
7
+ .rtb-booking-form legend {
8
+ padding: 0 0.5em;
9
+ }
10
+ .rtb-booking-form fieldset>div {
11
+ margin-top: 1em;
12
+ }
13
+ .rtb-booking-form label {
14
+ display: block;
15
+ }
16
+ .rtb-booking-form input {
17
+ width: 100%;
18
+ max-width: 15em;
19
+ }
20
+ .rtb-booking-form textarea {
21
+ width: 100%;
22
+ max-width: 30em;
23
+ }
24
+ .rtb-booking-form .add-message {
25
+ margin-top: 1em;
26
+ }
27
+ .rtb-booking-form .message {
28
+ position: absolute;
29
+ top: -9999px;
30
+ left: -9999px;
31
+ }
32
+ .rtb-booking-form .message-open {
33
+ position: relative;
34
+ top: auto;
35
+ left: auto;
36
+ }
37
+ .rtb-booking-form .message textarea {
38
+ min-height: 6em;
39
+ }
40
+ .rtb-booking-form .rtb-error {
41
+ font-size: 0.85em;
42
+ padding: 0.25em;
43
+ background: #f50;
44
+ color: #fff;
45
+ }
46
+ .rtb-booking-form .rtb-error:before {
47
+ content: ' ';
48
+ border-top: 4px solid;
49
+ border-right: 4px solid transparent;
50
+ border-left: 4px solid transparent;
51
+ width: 0;
52
+ height: 0;
53
+ display: inline-block;
54
+ margin: 0.25em 0.5em;
55
+ }
56
+
57
+ /* Compatibility styles for pickadate on common themes */
58
+ #rtb-date_root .picker__button--clear,
59
+ #rtb-date_root .picker__button--today {
60
+ /* don't adopt the theme's button text color */
61
+ color: #000;
62
+ }
63
+ #rtb-date_root .picker__nav--next,
64
+ #rtb-date_root .picker__nav--prev {
65
+ /* next/prev calendar arrows button areas sometimes don't cover the arrows */
66
+ min-height: 2em;
67
+ }
68
+ #rtb-time_root .picker__list,
69
+ #rtb-time_root .picker__list li {
70
+ /* override some theme's list styles */
71
+ list-style: none;
72
+ margin: 0 0 0 1px;
73
+ }
assets/js/admin.js ADDED
@@ -0,0 +1,22 @@
1
+ /* Javascript for Restaurant Reservations admin */
2
+ jQuery(document).ready(function ($) {
3
+
4
+ // Show or hide a booking message in the bookings table
5
+ $( '#rtb-bookings-table .column-message a' ).click( function () {
6
+ var message_id = $(this).data( 'id' );
7
+ if ( $(this).parent().parent().siblings( '#' + message_id ).length ) {
8
+ $( '#' + $(this).data( 'id' ) ).fadeOut( function() {
9
+ $(this).remove();
10
+ });
11
+ $(this).children( '.dashicons' ).removeClass( 'dashicons-welcome-comments' ).addClass( 'dashicons-testimonial' );
12
+ } else {
13
+ var row = $(this).closest( 'tr' );
14
+ row.after( '<tr class="' + row.attr( 'class' ) + ' message-row" id="' + message_id + '"><td colspan="' + row.children( 'th, td' ).length + '">' + $(this).siblings( '.rtb-message-data' ).html() + '</td></tr>' );
15
+ $( '#' + message_id ).fadeIn();
16
+ $(this).children( '.dashicons' ).removeClass( 'dashicons-testimonial' ).addClass( 'dashicons-welcome-comments' );
17
+ }
18
+
19
+ return false;
20
+ });
21
+
22
+ });
assets/js/booking-form.js ADDED
@@ -0,0 +1,201 @@
1
+ /* Javascript for Restaurant Reservations booking form */
2
+ jQuery(document).ready(function ($) {
3
+
4
+ /**
5
+ * Scroll to the first error message on the booking form
6
+ */
7
+ if ( $( '.rtb-booking-form .rtb-error' ).length ) {
8
+ $('html, body').animate({
9
+ scrollTop: $( '.rtb-booking-form .rtb-error' ).first().offset().top + -40
10
+ }, 500);
11
+ }
12
+
13
+ /**
14
+ * Show the message field on the booking form
15
+ */
16
+ $( '.rtb-booking-form .add-message a' ).click( function() {
17
+ $(this).hide();
18
+ $(this).parent().siblings( '.message' ).addClass( 'message-open' );
19
+
20
+ return false;
21
+ });
22
+
23
+ /**
24
+ * Enable datepickers on load
25
+ */
26
+ if ( typeof rtb_pickadate !== 'undefined' ) {
27
+
28
+ // Declare datepicker
29
+ var $date_input = $( '#rtb-date' ).pickadate({
30
+ format: rtb_pickadate.date_format,
31
+ min: true,
32
+ container: 'body',
33
+ });
34
+
35
+ // Declare timepicker
36
+ var $time_input = $( '#rtb-time' ).pickatime({
37
+ format: rtb_pickadate.time_format,
38
+ });
39
+
40
+ var datepicker = $date_input.pickadate( 'picker' );
41
+ var timepicker = $time_input.pickatime( 'picker' );
42
+
43
+ if ( typeof datepicker == 'undefined' ) {
44
+ return;
45
+ }
46
+
47
+ // Pass conditional configuration parameters
48
+ if ( rtb_pickadate.disable_dates.length ) {
49
+ datepicker.set( 'disable', rtb_pickadate.disable_dates );
50
+ }
51
+
52
+ // Update timepicker on pageload and whenever the datepicker is closed
53
+ rtb_update_timepicker_range();
54
+ datepicker.on( {
55
+ close: function() {
56
+ rtb_update_timepicker_range();
57
+ }
58
+ });
59
+ }
60
+
61
+ // Update the timepicker's range based on the currently selected date
62
+ function rtb_update_timepicker_range() {
63
+
64
+ // Reset enabled/disabled rules on this timepicker
65
+ timepicker.set( 'enable', false );
66
+ timepicker.set( 'disable', false );
67
+
68
+ var selected_date = new Date( datepicker.get() );
69
+ var selected_date_year = selected_date.getFullYear();
70
+ var selected_date_month = selected_date.getMonth();
71
+ var selected_date_date = selected_date.getDate();
72
+
73
+ // Declaring the first element true inverts the timepicker settings. All
74
+ // times subsequently declared are valid. Any time that doesn't fall
75
+ // within those declarations is invalid.
76
+ // See: http://amsul.ca/pickadate.js/time.htm#disable-times-all
77
+ var valid_times = [ { from: [0, 0], to: [24, 0] } ];
78
+
79
+ // Check if this date is an exception to the rules
80
+ if ( typeof rtb_pickadate.schedule_closed != 'undefined' ) {
81
+
82
+ var excp_date = [];
83
+ var excp_start_date = [];
84
+ var excp_start_time = [];
85
+ var excp_end_date = [];
86
+ var excp_end_time = [];
87
+ for ( var closed_key in rtb_pickadate.schedule_closed ) {
88
+
89
+ excp_date = new Date( rtb_pickadate.schedule_closed[closed_key].date );
90
+ if ( excp_date.getFullYear() == selected_date_year &&
91
+ excp_date.getMonth() == selected_date_month &&
92
+ excp_date.getDate() == selected_date_date
93
+ ) {
94
+
95
+ // Closed all day
96
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time == 'undefined' ) {
97
+ timepicker.set( 'disable', [ true ] );
98
+
99
+ return;
100
+ }
101
+
102
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time.start !== 'undefined' ) {
103
+ excp_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.start );
104
+ excp_start_time = [ excp_start_date.getHours(), excp_start_date.getMinutes() ];
105
+ } else {
106
+ excp_start_time = [ 0, 0 ]; // Start of the day
107
+ }
108
+
109
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time.end !== 'undefined' ) {
110
+ excp_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.end );
111
+ excp_end_time = [ excp_end_date.getHours(), excp_end_date.getMinutes() ];
112
+ } else {
113
+ excp_end_time = [ 24, 0 ]; // End of the day
114
+ }
115
+
116
+ valid_times.push( { from: excp_start_time, to: excp_end_time, inverted: true } );
117
+ }
118
+ }
119
+
120
+ excp_date = excp_start_date = excp_start_time = excp_end_date = excp_end_time = null;
121
+
122
+ // Exit early if this date is an exception
123
+ if ( valid_times.length > 1 ) {
124
+ timepicker.set( 'disable', valid_times );
125
+
126
+ return;
127
+ }
128
+ }
129
+
130
+ // Get any rules which apply to this weekday
131
+ if ( typeof rtb_pickadate.schedule_open != 'undefined' ) {
132
+
133
+ var selected_date_weekday = selected_date.getDay();
134
+
135
+ var weekdays = {
136
+ sunday: 0,
137
+ monday: 1,
138
+ tuesday: 2,
139
+ wednesday: 3,
140
+ thursday: 4,
141
+ friday: 5,
142
+ saturday: 6,
143
+ };
144
+
145
+ var rule_start_date = [];
146
+ var rule_start_time = [];
147
+ var rule_end_date = [];
148
+ var rule_end_time = [];
149
+ for ( var open_key in rtb_pickadate.schedule_open ) {
150
+
151
+ if ( typeof rtb_pickadate.schedule_open[open_key].weekdays !== 'undefined' ) {
152
+ for ( var weekdays_key in rtb_pickadate.schedule_open[open_key].weekdays ) {
153
+ if ( weekdays[weekdays_key] == selected_date_weekday ) {
154
+
155
+ // Closed all day
156
+ if ( typeof rtb_pickadate.schedule_open[open_key].time == 'undefined' ) {
157
+ timepicker.set( 'disable', [ true ] );
158
+
159
+ return;
160
+ }
161
+
162
+ if ( typeof rtb_pickadate.schedule_open[open_key].time.start !== 'undefined' ) {
163
+ rule_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.start );
164
+ rule_start_time = [ rule_start_date.getHours(), rule_start_date.getMinutes() ];
165
+ } else {
166
+ rule_start_time = [ 0, 0 ]; // Start of the day
167
+ }
168
+
169
+ if ( typeof rtb_pickadate.schedule_open[open_key].time.end !== 'undefined' ) {
170
+ rule_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.end );
171
+ rule_end_time = [ rule_end_date.getHours(), rule_end_date.getMinutes() ];
172
+ } else {
173
+ rule_end_time = [ 24, 0 ]; // End of the day
174
+ }
175
+
176
+ valid_times.push( { from: rule_start_time, to: rule_end_time, inverted: true } );
177
+
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ rule_start_date = rule_start_time = rule_end_date = rule_end_time = null;
184
+
185
+ // Pass any valid times located
186
+ if ( valid_times.length > 1 ) {
187
+ timepicker.set( 'disable', valid_times );
188
+
189
+ return;
190
+ }
191
+
192
+ }
193
+
194
+ // Set it to always open if no rules have been defined
195
+ timepicker.set( 'enable', true );
196
+ timepicker.set( 'disable', false );
197
+
198
+ return;
199
+ }
200
+
201
+ });
docs/index.html ADDED
@@ -0,0 +1,169 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en-US">
3
+ <head>
4
+
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Restaurant Reservations | How to install and use this plugin</title>
8
+ <link rel="profile" href="http://gmpg.org/xfn/11">
9
+ <meta name="robots" content="noindex,nofollow">
10
+ <link rel="stylesheet" href="style.css" type="text/css" media="all" />
11
+
12
+ </head>
13
+
14
+ <body>
15
+
16
+ <div id="toc">
17
+ <ul>
18
+ <li>
19
+ <a href="#install">Installation</a>
20
+ </li>
21
+ <li>
22
+ <a href="#setup">Quick Setup</a>
23
+ </li>
24
+ <li>
25
+ <a href="#manage_bookings">Manage bookings</a>
26
+ </li>
27
+ <li>
28
+ <a href="#schedule">Set the booking schedule</a>
29
+ </li>
30
+ <li>
31
+ <a href="#settings">The settings page</a>
32
+ </li>
33
+ <li>
34
+ <a href="#extend">Extend this plugin</a>
35
+ </li>
36
+ </ul>
37
+ </div>
38
+
39
+ <div id="content">
40
+
41
+ <h1>Guide to the Restaurant Reservations plugin for WordPress</h1>
42
+ <p>This guide will help you install and configure the plugin for your site.</p>
43
+ <p>Further support for this plugin can be found at <a href="http://themeofthecrop.com/?utm_source=Plugin&utm_medium=Plugin%20Help%20Documentation&utm_campaign=Restaurant%20Reservations">themeofthecrop.com</a>.</p>
44
+
45
+ <a name="install"></a>
46
+ <h2>Installation</h2>
47
+ <p>The following steps describe how to upload the Restaurant Reservations plugin to an
48
+ existing WordPress installation. If you have not yet installed WordPress, consult the
49
+ <a href="http://codex.wordpress.org/Installing_WordPress">WordPress
50
+ documentation</a> for more information.</p>
51
+ <ol>
52
+ <li>
53
+ Unpack the restaurant-reservations.zip file. It should create a folder
54
+ named <code>/restaurant-reservations/</code>.
55
+ </li>
56
+ <li>
57
+ Upload the <code>/restaurant-reservations/</code> folder to your
58
+ WordPress plugin directory at <code>/wp-content/plugins/</code>.
59
+ </li>
60
+ <li>
61
+ Go to your WordPress admin dashboard at yoursite.com/wp-admin and
62
+ click the <strong>Plugins</strong> item in the menu on the left.
63
+ </li>
64
+ <li>
65
+ Find <strong>Restaurant Reservations</strong> in the list of Plugins
66
+ and click the <strong>Activate</strong> link below the plugin name.
67
+ </li>
68
+ </ol>
69
+ <p>The plugin is now active. Next you'll need to get it setup.</p>
70
+
71
+ <a name="setup"></a>
72
+ <h2>Quick Setup</h2>
73
+ <p>To get this plugin working as quickly as possible, all you need to do is
74
+ display the booking form. There are three ways to do this:</p>
75
+ <ol>
76
+ <li>
77
+ Automatically add the booking form to any page on your website. Go
78
+ to the <strong>Booking > Settings</strong> page in your admin
79
+ dashboard. Select one of your pages in the dropdown list for
80
+ <strong>Booking Page</strong>. The booking form will automatically
81
+ be added to that page.
82
+ </li>
83
+ <li>
84
+ Add the Booking Form widget. Go to <strong>Appearance > Widgets</strong>
85
+ and find the Booking Form widget. Add that to any sidebar to display
86
+ your booking form.
87
+ </li>
88
+ <li>
89
+ Use the <code>[booking-form]</code> shortcode to add your booking
90
+ form to any page or post on your website. Simply paste
91
+ <code>[booking-form]</code> into the content of any page or post.
92
+ </li>
93
+ </ol>
94
+ <p>Once you've done that, your users can submit their bookings. The next
95
+ section will describe how to view, confirm and reject them in your
96
+ admin panel.</p>
97
+
98
+ <a name="manage_bookings"></a>
99
+ <h2>Manage Bookings</h2>
100
+ <p>To view, confirm and reject bookings, go to the <strong>Bookings</strong>
101
+ page in your admin panel. This will show you all of your bookings with
102
+ the current status on the right.</p>
103
+ <p>On this page you can filter bookings by date, filter bookings by status
104
+ and change a booking's status. <em>Tip: you can combine filters, so that you
105
+ are viewing just Pending bookings for Today</em>.</p>
106
+ <p>When a new booking is made,
107
+ it is set to Pending. You can then either set the status to Confirmed
108
+ or Closed. The user will then receive an email letting them know that
109
+ their booking was confirmed or rejected.</p>
110
+ <p>To change the status of any booking, click the checkbox to the left of
111
+ the booking. From the <strong>Bulk Actions</strong> dropdown list,
112
+ select the appropriate action (ie - Set to Confirmed) and click
113
+ <strong>Apply</strong>.</p>
114
+ <p><em>Remember, a user will receive an email notification, so only change
115
+ the status when you're ready.</em> At the moment, a notification is sent
116
+ to the user when they make a booking request and when that request is
117
+ changed from pending to confirmed or pending to closed.</p>
118
+
119
+ <a name="schedule"></a>
120
+ <h2>Set the booking schedule</h2>
121
+ <p>You probably only want to accept bookings when you're open. You may only
122
+ accept bookings during certain opening hours. You can define scheduling
123
+ rules to limit when people can submit booking requests.</p>
124
+ <p>To do this, go to the <strong>Bookings > Settings</strong> page in the
125
+ admin dashboard. On this page, click the <strong>Booking Schedule</strong>
126
+ tab.</p>
127
+ <p>Under <strong>Schedule</strong>, click the <strong>Add new scheduling
128
+ rule</strong> button. Set the weekdays and opening hours.</p>
129
+ <p>These rules are <em>complimentary</em>. That means if you have two rules
130
+ which occur at different times on the same day, bookings will be
131
+ accepted during both times. This allows you to set morning and evening
132
+ hours, for example.</p>
133
+ <p>There are three other settings on this page.</p>
134
+ <p><strong>Exceptions</strong> allows you to specify custom scheduling rules
135
+ on certain dates. This will help you indicate if you're closed on
136
+ a holiday or have special opening hours one day.</p>
137
+ <p><strong>Early Bookings</strong> and <strong>Late Bookings</strong> allow
138
+ you to set limits on how early or late people can make bookings. If you
139
+ don't want to recieve a booking for 4:45pm at 4:40pm, set the
140
+ <strong>Late Bookings</strong> setting to something more appropriate.</p>
141
+
142
+ <a name="settings"></a>
143
+ <h2>The settings page</h2>
144
+ <p>In addition to the <a href="#schedule">Booking Schedule</a>, there are
145
+ two other settings tabs. These settings allow you to customize
146
+ messages when people submit a booking, notification emails sent out
147
+ when bookings are confirmed or rejected, and more.</p>
148
+ <p>If you want to receive an admin notification email when a new booking
149
+ request is made, make sure to check the box next to <strong>Admin
150
+ Notification</strong> under the Notificaitons tab.</p>
151
+
152
+ <a name="extend"></a>
153
+ <h2>Extend this plugin</h2>
154
+ <p>This plugin has been designed from the ground up to be extensible and
155
+ customizable. There are dozens of hooks to allow you to customize the
156
+ functionality and output. These include hooks to completely replace the
157
+ booking form's HTML output, add new settings, add new booking form
158
+ information, and add your own notifications.</p>
159
+ <p>If you have any questions, please
160
+ <a href="http://themeofthecrop.com/about/support/?utm_source=Plugin&utm_medium=Plugin%20Help%20Documentation&utm_campaign=Restaurant%20Reservations">contact me</a>.</p>
161
+ <p>This plugin is available on
162
+ <a href="https://github.com/NateWr/restaurant-reservations">GitHub</a>
163
+ if you would like to contribute pull requests.</p>
164
+
165
+ </div>
166
+
167
+ </body>
168
+
169
+ </html>
docs/style.css ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Documentation Markup
3
+ **********************/
4
+ body {
5
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
6
+ background-color: #eee;
7
+ margin: 0;
8
+ }
9
+ li {
10
+ padding-bottom: 5px;
11
+ }
12
+ #toc {
13
+ position: absolute;
14
+ width: 250px;
15
+ }
16
+ #content {
17
+ padding: 20px;
18
+ margin-left: 300px;
19
+ background-color: #fff;
20
+ box-shadow: 0 0 5px #000;
21
+ }
22
+ #toc>ul>li {
23
+ padding-bottom: 10px;
24
+ padding-top: 10px;
25
+ }
26
+ code {
27
+ font-family: Courier, monospace;
28
+ padding: 2px 5px;
29
+ background-color: #eee;
30
+ border-radius: 2px;
31
+ }
includes/Booking.class.php ADDED
@@ -0,0 +1,421 @@
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbBooking' ) ) {
5
+ /**
6
+ * Class to handle a booking for Restaurant Table Bookings
7
+ *
8
+ * @since 0.0.1
9
+ */
10
+ class rtbBooking {
11
+
12
+ /**
13
+ * Whether or not this request has been processed. Used to prevent
14
+ * duplicate forms on one page from processing a booking form more than
15
+ * once.
16
+ * @since 0.0.1
17
+ */
18
+ public $request_processed = false;
19
+
20
+ /**
21
+ * Whether or not this request was successfully saved to the database.
22
+ * @since 0.0.1
23
+ */
24
+ public $request_inserted = false;
25
+
26
+ public function __construct() {}
27
+
28
+ /**
29
+ * Load the booking information from a WP_Post object or an ID
30
+ *
31
+ * @uses load_wp_post()
32
+ * @since 0.0.1
33
+ */
34
+ public function load_post( $post ) {
35
+
36
+ if ( is_int( $post ) || is_string( $post ) ) {
37
+ $post = get_post( $post );
38
+ }
39
+
40
+ if ( get_class( $post ) == 'WP_Post' && $post->post_type == RTB_BOOKING_POST_TYPE ) {
41
+ $this->load_wp_post( $post );
42
+ return true;
43
+ } else {
44
+ return false;
45
+ }
46
+
47
+ }
48
+
49
+ /**
50
+ * Load data from WP post object and retrieve metadata
51
+ *
52
+ * @uses load_post_metadata()
53
+ * @since 0.0.1
54
+ */
55
+ public function load_wp_post( $post ) {
56
+
57
+ // Store post for access to other data if needed by extensions
58
+ $this->post = $post;
59
+
60
+ $this->ID = $post->ID;
61
+ $this->name = $post->post_title;
62
+ $this->date = $this->format_date( $post->post_date );
63
+ $this->message = apply_filters( 'the_content', $post->post_content );
64
+ $this->post_status = $post->post_status;
65
+
66
+ $this->load_post_metadata();
67
+
68
+ do_action( 'rtb_booking_load_post_data', $this, $post );
69
+ }
70
+
71
+ /**
72
+ * Store metadata for post
73
+ * @since 0.0.1
74
+ */
75
+ public function load_post_metadata() {
76
+
77
+ $meta_defaults = array(
78
+ 'party' => '',
79
+ 'email' => '',
80
+ 'phone' => '',
81
+ 'date_submission' => '',
82
+ );
83
+
84
+ $meta_defaults = apply_filters( 'rtb_booking_metadata_defaults', $meta_defaults );
85
+
86
+ if ( is_array( $meta = get_post_meta( $this->ID, 'rtb', true ) ) ) {
87
+ $meta = array_merge( $meta_defaults, get_post_meta( $this->ID, 'rtb', true ) );
88
+ } else {
89
+ $meta = $meta_defaults;
90
+ }
91
+
92
+ $this->party = $meta['party'];
93
+ $this->email = $meta['email'];
94
+ $this->phone = $meta['phone'];
95
+ $this->date_submission = $meta['date_submission'];
96
+ }
97
+
98
+ /**
99
+ * Format date
100
+ * @since 0.0.1
101
+ */
102
+ public function format_date( $date ) {
103
+ $date = mysql2date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $date);
104
+ return apply_filters( 'get_the_date', $date );
105
+ }
106
+
107
+ /**
108
+ * Insert a new booking submission into the database
109
+ *
110
+ * Validates the data, adds it to the database and executes notifications
111
+ * @since 0.0.1
112
+ */
113
+ public function insert_booking() {
114
+
115
+ // Check if this request has already been processed. If multiple forms
116
+ // exist on the same page, this prevents a single submission from
117
+ // being added twice.
118
+ if ( $this->request_processed === true ) {
119
+ return true;
120
+ }
121
+
122
+ $this->request_processed = true;
123
+
124
+ $this->validate_submission();
125
+ if ( $this->is_valid_submission() === false ) {
126
+ return false;
127
+ }
128
+
129
+ if ( $this->insert_post_data() === false ) {
130
+ return false;
131
+ } else {
132
+ $this->request_inserted = true;
133
+ }
134
+
135
+ do_action( 'rtb_insert_booking', $this );
136
+
137
+ return true;
138
+ }
139
+
140
+ /**
141
+ * Validate submission data. Expects to find data in $_POST.
142
+ * @since 0.0.1
143
+ */
144
+ public function validate_submission() {
145
+
146
+ $this->validation_errors = array();
147
+
148
+ // Date
149
+ $date = empty( $_POST['rtb-date'] ) ? false : $_POST['rtb-date'];
150
+ if ( $date === false ) {
151
+ $this->validation_errors[] = array(
152
+ 'field' => 'date',
153
+ 'error_msg' => 'Booking request missing date',
154
+ 'message' => __( 'Please enter the date you would like to book.', RTB_TEXTDOMAIN ),
155
+ );
156
+
157
+ } else {
158
+ try {
159
+ $date = new DateTime( $_POST['rtb-date'] );
160
+ } catch ( Exception $e ) {
161
+ $this->validation_errors[] = array(
162
+ 'field' => 'date',
163
+ 'error_msg' => $e->getMessage(),
164
+ 'message' => __( 'The date you entered is not valid. Please select from one of the dates in the calendar.', RTB_TEXTDOMAIN ),
165
+ );
166
+ }
167
+ }
168
+
169
+ // Time
170
+ $time = empty( $_POST['rtb-time'] ) ? false : $_POST['rtb-time'];
171
+ if ( $time === false ) {
172
+ $this->validation_errors[] = array(
173
+ 'field' => 'time',
174
+ 'error_msg' => 'Booking request missing time',
175
+ 'message' => __( 'Please enter the time you would like to book.', RTB_TEXTDOMAIN ),
176
+ );
177
+
178
+ } else {
179
+ try {
180
+ $time = new DateTime( $_POST['rtb-time'] );
181
+ } catch ( Exception $e ) {
182
+ $this->validation_errors[] = array(
183
+ 'field' => 'time',
184
+ 'error_msg' => $e->getMessage(),
185
+ 'message' => __( 'The time you entered is not valid. Please select from one of the times provided.', RTB_TEXTDOMAIN ),
186
+ );
187
+ }
188
+ }
189
+
190
+ // Check against valid open dates/times
191
+ if ( is_object( $time ) && is_object( $date ) ) {
192
+
193
+ global $rtb_controller;
194
+
195
+ $request = new DateTime( $date->format( 'Y-m-d' ) . ' ' . $time->format( 'H:i:s' ) );
196
+
197
+ $early_bookings = $rtb_controller->settings->get_setting( 'early-bookings' );
198
+ if ( !empty( $early_bookings ) ) {
199
+ $early_bookings_seconds = $early_bookings * 24 * 60 * 60; // Advanced bookings allowance in seconds
200
+ if ( $request->format( 'U' ) > ( current_time( 'timestamp' ) + $early_bookings_seconds ) ) {
201
+ $this->validation_errors[] = array(
202
+ 'field' => 'time',
203
+ 'error_msg' => 'Booking request too far in the future',
204
+ 'message' => sprintf( __( 'Sorry, bookings can not be made more than %s days in advance.', RTB_TEXTDOMAIN ), $early_bookings ),
205
+ );
206
+ }
207
+ }
208
+
209
+ $late_bookings = $rtb_controller->settings->get_setting( 'late-bookings' );
210
+ if ( empty( $late_bookings ) ) {
211
+ if ( $request->format( 'U' ) < current_time( 'timestamp' ) ) {
212
+ $this->validation_errors[] = array(
213
+ 'field' => 'time',
214
+ 'error_msg' => 'Booking request in the past',
215
+ 'message' => __( 'Sorry, bookings can not be made in the past.', RTB_TEXTDOMAIN ),
216
+ );
217
+ }
218
+
219
+ } else {
220
+ $late_bookings_seconds = $late_bookings * 60; // Late bookings allowance in seconds
221
+ if ( $request->format( 'U' ) < ( current_time( 'timestamp' ) + $late_bookings_seconds ) ) {
222
+ $this->validation_errors[] = array(
223
+ 'field' => 'time',
224
+ 'error_msg' => 'Booking request made too close to the reserved time',
225
+ 'message' => sprintf( __( 'Sorry, bookings must be made more than %s minutes in advance.', RTB_TEXTDOMAIN ), $late_bookings ),
226
+ );
227
+ }
228
+ }
229
+
230
+ // Check against scheduling exception rules
231
+ $exceptions = $rtb_controller->settings->get_setting( 'schedule-closed' );
232
+ if ( empty( $this->validation_errors ) && !empty( $exceptions ) ) {
233
+ $exception_is_active = false;
234
+ $datetime_is_valid = false;
235
+ foreach( $exceptions as $exception ) {
236
+ $excp_date = new DateTime( $exception['date'] );
237
+ if ( $excp_date->format( 'Y-m-d' ) == $request->format( 'Y-m-d' ) ) {
238
+ $exception_is_active = true;
239
+
240
+ // Closed all day
241
+ if ( empty( $exception['time'] ) ) {
242
+ continue;
243
+ }
244
+
245
+ $excp_start_time = empty( $exception['time']['start'] ) ? $request : new DateTime( $exception['date'] . ' ' . $exception['time']['start'] );
246
+ $excp_end_time = empty( $exception['time']['end'] ) ? $request : new DateTime( $exception['date'] . ' ' . $exception['time']['end'] );
247
+
248
+ if ( $request->format( 'U' ) >= $excp_start_time->format( 'U' ) && $request->format( 'U' ) <= $excp_end_time->format( 'U' ) ) {
249
+ $datetime_is_valid = true;
250
+ break;
251
+ }
252
+ }
253
+ }
254
+
255
+ if ( $exception_is_active && !$datetime_is_valid ) {
256
+ $this->validation_errors[] = array(
257
+ 'field' => 'date',
258
+ 'error_msg' => 'Booking request made on invalid date or time in an exception rule',
259
+ 'message' => __( 'Sorry, no bookings are being accepted then.', RTB_TEXTDOMAIN ),
260
+ );
261
+ }
262
+ }
263
+
264
+ // Check against weekly scheduling rules
265
+ $rules = $rtb_controller->settings->get_setting( 'schedule-open' );
266
+ if ( empty( $exception_is_active ) && empty( $this->validation_errors ) && !empty( $rules ) ) {
267
+ $request_weekday = strtolower( $request->format( 'l' ) );
268
+ $time_is_valid = null;
269
+ $day_is_valid = null;
270
+ foreach( $rules as $rule ) {
271
+
272
+ if ( !empty( $rule['weekdays'][ $request_weekday ] ) ) {
273
+ $day_is_valid = true;
274
+
275
+ if ( empty( $rule['time'] ) ) {
276
+ $time_is_valid = true; // Days with no time values are open all day
277
+ break;
278
+ }
279
+
280
+ $too_early = true;
281
+ $too_late = true;
282
+
283
+ // Too early
284
+ if ( !empty( $rule['time']['start'] ) ) {
285
+ $rule_start_time = new DateTime( $request->format( 'Y-m-d' ) . ' ' . $rule['time']['start'] );
286
+ if ( $rule_start_time->format( 'U' ) <= $request->format( 'U' ) ) {
287
+ $too_early = false;
288
+ }
289
+ }
290
+
291
+ // Too late
292
+ if ( !empty( $rule['time']['end'] ) ) {
293
+ $rule_end_time = new DateTime( $request->format( 'Y-m-d' ) . ' ' . $rule['time']['end'] );
294
+ if ( $rule_end_time->format( 'U' ) >= $request->format( 'U' ) ) {
295
+ $too_late = false;
296
+ }
297
+ }
298
+
299
+ // Valid time found
300
+ if ( $too_early === false && $too_late === false) {
301
+ $time_is_valid = true;
302
+ break;
303
+ }
304
+ }
305
+ }
306
+
307
+ if ( !$day_is_valid ) {
308
+ $this->validation_errors[] = array(
309
+ 'field' => 'date',
310
+ 'error_msg' => 'Booking request made on an invalid date',
311
+ 'message' => __( 'Sorry, no bookings are being accepted on that date.', RTB_TEXTDOMAIN ),
312
+ );
313
+ } elseif ( !$time_is_valid ) {
314
+ $this->validation_errors[] = array(
315
+ 'field' => 'time',
316
+ 'error_msg' => 'Booking request made at an invalid time',
317
+ 'message' => __( 'Sorry, no bookings are being accepted at that time.', RTB_TEXTDOMAIN ),
318
+ );
319
+ }
320
+ }
321
+
322
+ // Accept the date if it has passed validation
323
+ if ( empty( $this->validation_errors ) ) {
324
+ $this->date = $request->format( 'Y-m-d H:i:s' );
325
+ }
326
+ }
327
+
328
+ // Save requested date/time values in case they need to be
329
+ // printed in the form again
330
+ $this->request_date = empty( $_POST['rtb-date'] ) ? '' : $_POST['rtb-date'];
331
+ $this->request_time = empty( $_POST['rtb-time'] ) ? '' : $_POST['rtb-time'];
332
+
333
+ // Name
334
+ $this->name = empty( $_POST['rtb-name'] ) ? '' : wp_strip_all_tags( sanitize_text_field( $_POST['rtb-name'] ), true ); // @todo should I limit length?
335
+ if ( empty( $this->name ) ) {
336
+ $this->validation_errors[] = array(
337
+ 'field' => 'name',
338
+ 'post_variable' => $this->name,
339
+ 'message' => __( 'Please enter a name for this booking.', RTB_TEXTDOMAIN ),
340
+ );
341
+ }
342
+
343
+ // Party
344
+ $this->party = empty( $_POST['rtb-party'] ) ? '' : sanitize_text_field( $_POST['rtb-party'] );
345
+ if ( empty( $this->party ) ) {
346
+ $this->validation_errors[] = array(
347
+ 'field' => 'party',
348
+ 'post_variable' => $this->party,
349
+ 'message' => __( 'Please let us know how many people will be in your party.', RTB_TEXTDOMAIN ),
350
+ );
351
+ }
352
+
353
+ // Email/Phone
354
+ $this->email = empty( $_POST['rtb-email'] ) ? '' : sanitize_text_field( $_POST['rtb-email'] ); // @todo email validation? send notification back to form on bad email address.
355
+ if ( empty( $this->email ) ) {
356
+ $this->validation_errors[] = array(
357
+ 'field' => 'email',
358
+ 'post_variable' => $this->email,
359
+ 'message' => __( 'Please enter an email address so we can confirm your booking.', RTB_TEXTDOMAIN ),
360
+ );
361
+ }
362
+
363
+ // Phone/Message
364
+ $this->phone = empty( $_POST['rtb-phone'] ) ? '' : sanitize_text_field( $_POST['rtb-phone'] );
365
+ $this->message = empty( $_POST['rtb-message'] ) ? '' : sanitize_text_field( $_POST['rtb-message'] );
366
+
367
+ do_action( 'rtb_validate_booking_submission', $this );
368
+
369
+ }
370
+
371
+ /**
372
+ * Check if submission is valid
373
+ * @since 0.0.1
374
+ */
375
+ public function is_valid_submission() {
376
+ if ( !count( $this->validation_errors ) ) {
377
+ return true;
378
+ }
379
+ return false;
380
+ }
381
+
382
+ /**
383
+ * Insert post data for a new booking.
384
+ * @since 0.0.1
385
+ */
386
+ public function insert_post_data() {
387
+
388
+ $args = array(
389
+ 'post_type' => RTB_BOOKING_POST_TYPE,
390
+ 'post_title' => $this->name,
391
+ 'post_content' => $this->message,
392
+ 'post_date' => $this->date,
393
+ 'post_status' => 'pending',
394
+ );
395
+
396
+ $args = apply_filters( 'rtb_insert_booking_data', $args, $this );
397
+
398
+ $id = wp_insert_post( $args );
399
+
400
+ if ( is_wp_error( $id ) || $id === false ) {
401
+ $this->insert_post_error = $id;
402
+ return false;
403
+ } else {
404
+ $this->ID = $id;
405
+ }
406
+
407
+ $meta = array(
408
+ 'party' => $this->party,
409
+ 'email' => $this->email,
410
+ 'phone' => $this->phone,
411
+ 'date_submission' => current_time( 'timestamp' ),
412
+ );
413
+
414
+ $meta = apply_filters( 'rtb_insert_booking_metadata', $meta, $this );
415
+
416
+ return update_post_meta( $this->ID, 'rtb', $meta );
417
+
418
+ }
419
+
420
+ }
421
+ } // endif;
includes/CustomPostTypes.class.php ADDED
@@ -0,0 +1,231 @@
1
+ <?php
2
+ /**
3
+ * Class to handle all custom post type definitions for Restaurant Reservations
4
+ */
5
+
6
+ if ( !defined( 'ABSPATH' ) )
7
+ exit;
8
+
9
+ if ( !class_exists( 'rtbCustomPostTypes' ) ) {
10
+ class rtbCustomPostTypes {
11
+
12
+ // Array of valid post statuses
13
+ // @sa set_booking_statuses()
14
+ public $booking_statuses = array();
15
+
16
+ // Cached select fields for booking stasuses
17
+ public $status_select_html = array();
18
+
19
+ public function __construct() {
20
+
21
+ // Call when plugin is initialized on every page load
22
+ add_action( 'init', array( $this, 'load_cpts' ) );
23
+
24
+ // Set up $booking_statuses array and register new post statuses
25
+ add_action( 'init', array( $this, 'set_booking_statuses' ) );
26
+
27
+ }
28
+
29
+ /**
30
+ * Initialize custom post types
31
+ * @since 0.1
32
+ */
33
+ public function load_cpts() {
34
+
35
+ // Define the booking custom post type
36
+ $args = array(
37
+ 'labels' => array(
38
+ 'name' => __( 'Bookings', RTB_TEXTDOMAIN ),
39
+ 'singular_name' => __( 'Booking', RTB_TEXTDOMAIN ),
40
+ 'menu_name' => __( 'Bookings', RTB_TEXTDOMAIN ),
41
+ 'name_admin_bar' => __( 'Bookings', RTB_TEXTDOMAIN ),
42
+ 'add_new' => __( 'Add New', RTB_TEXTDOMAIN ),
43
+ 'add_new_item' => __( 'Add New Booking', RTB_TEXTDOMAIN ),
44
+ 'edit_item' => __( 'Edit Booking', RTB_TEXTDOMAIN ),
45
+ 'new_item' => __( 'New Booking', RTB_TEXTDOMAIN ),
46
+ 'view_item' => __( 'View Booking', RTB_TEXTDOMAIN ),
47
+ 'search_items' => __( 'Search Bookings', RTB_TEXTDOMAIN ),
48
+ 'not_found' => __( 'No bookings found', RTB_TEXTDOMAIN ),
49
+ 'not_found_in_trash' => __( 'No bookings found in trash', RTB_TEXTDOMAIN ),
50
+ 'all_items' => __( 'All Bookings', RTB_TEXTDOMAIN ),
51
+ ),
52
+ 'menu_icon' => 'dashicons-calendar',
53
+ 'public' => false,
54
+ 'supports' => array(
55
+ 'title',
56
+ 'revisions'
57
+ )
58
+ );
59
+
60
+ // Create filter so addons can modify the arguments
61
+ $args = apply_filters( 'rtb_booking_args', $args );
62
+
63
+ // Add an action so addons can hook in before the post type is registered
64
+ do_action( 'rtb_booking_pre_register' );
65
+
66
+ // Register the post type
67
+ register_post_type( RTB_BOOKING_POST_TYPE, $args );
68
+
69
+ // Add an action so addons can hook in after the post type is registered
70
+ do_action( 'rtb_booking_post_register' );
71
+ }
72
+
73
+ /**
74
+ * Set an array of valid booking statuses and register any custom statuses
75
+ * @since 0.0.1
76
+ */
77
+ public function set_booking_statuses() {
78
+
79
+ $this->booking_statuses['pending'] = array(
80
+ 'label' => _x( 'Pending', 'Booking status when it is pending review', RTB_TEXTDOMAIN ),
81
+ 'default' => true, // Whether or not this status is part of WP Core
82
+ 'user_selectable' => true, // Whether or not a user can set a booking to this status
83
+ );
84
+
85
+ $this->booking_statuses['confirmed'] = array (
86
+ 'label' => _x( 'Confirmed', 'Booking status for a confirmed booking', RTB_TEXTDOMAIN ),
87
+ 'default' => false, // Whether or not this status is part of WP Core
88
+ 'user_selectable' => true, // Whether or not a user can set a booking to this status
89
+ 'public' => false,
90
+ 'exclude_from_search' => true,
91
+ 'show_in_admin_all_list' => true,
92
+ 'show_in_admin_status_list' => true,
93
+ 'label_count' => _n_noop( 'Confirmed <span class="count">(%s)</span>', 'Confirmed <span class="count">(%s)</span>', RTB_TEXTDOMAIN ),
94
+ );
95
+
96
+ $this->booking_statuses['closed'] = array(
97
+ 'label' => _x( 'Closed', 'Booking status for a closed booking', RTB_TEXTDOMAIN ),
98
+ 'default' => false, // Whether or not this status is part of WP Core
99
+ 'user_selectable' => true, // Whether or not a user can set a booking to this status
100
+ 'public' => false,
101
+ 'exclude_from_search' => true,
102
+ 'show_in_admin_all_list' => true,
103
+ 'show_in_admin_status_list' => true,
104
+ 'label_count' => _n_noop( 'Closed <span class="count">(%s)</span>', 'Closed <span class="count">(%s)</span>', RTB_TEXTDOMAIN )
105
+ );
106
+
107
+ // Let addons hook in to add/edit/remove post statuses
108
+ $this->booking_statuses = apply_filters( 'rtb_post_statuses_args', $this->booking_statuses );
109
+
110
+ // Register the custom post statuses
111
+ foreach ( $this->booking_statuses as $status => $args ) {
112
+ if ( $args['default'] === false ) {
113
+ register_post_status( $status, $args );
114
+ }
115
+ }
116
+
117
+ }
118
+
119
+ /**
120
+ * Print an HTML element to select a booking status
121
+ * @since 0.0.1
122
+ * @note This is no longer used in the bookings table, but it could be
123
+ * useful in the future, so leave it in for now (0.0.1) until the plugin is
124
+ * more fleshed out.
125
+ */
126
+ public function print_booking_status_select( $current = false ) {
127
+
128
+ if ( $current === false ) {
129
+ $current = 'none';
130
+ }
131
+
132
+ // Output stored select field if available
133
+ if ( !empty( $this->status_select_html[$current] ) ) {
134
+ return $this->status_select_html[$current];
135
+ }
136
+
137
+ ob_start();
138
+ ?>
139
+
140
+ <select name="rtb-select-status">
141
+ <?php foreach ( $this->booking_statuses as $status => $args ) : ?>
142
+ <?php if ( $args['user_selectable'] === true ) : ?>
143
+ <option value="<?php echo esc_attr( $status ); ?>"<?php echo $status == $current ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $args['label'] ); ?></option>
144
+ <?php endif; ?>
145
+ <?php endforeach; ?>
146
+ </select>
147
+
148
+ <?php
149
+ $output = ob_get_clean();
150
+
151
+ // Store output so we don't need to loop for every row
152
+ $this->status_select_html[$current] = $output;
153
+
154
+ return $output;
155
+
156
+ }
157
+
158
+ /**
159
+ * Delete a booking request (or send to trash)
160
+ *
161
+ * @since 0.0.1
162
+ */
163
+ public function delete_booking( $id ) {
164
+
165
+ if ( !current_user_can( 'manage_bookings' ) ) {
166
+ return;
167
+ }
168
+
169
+ // If we're already looking at trashed posts, delete it for good.
170
+ // Otherwise, just send it to trash.
171
+ if ( !empty( $_GET['status'] ) && $_GET['status'] == 'trash' ) {
172
+ $screen = get_current_screen();
173
+ if ( $screen->base == 'toplevel_page_rtb-bookings' ) {
174
+ $result = wp_delete_post( $id, true );
175
+ }
176
+ } else {
177
+ $result = wp_trash_post( $id );
178
+ }
179
+
180
+ if ( $result === false ) {
181
+ return false;
182
+ } else {
183
+ return true;
184
+ }
185
+ }
186
+
187
+ /**
188
+ * Update a booking status.
189
+ * @since 0.0.1
190
+ */
191
+ function update_booking_status( $id, $status ) {
192
+
193
+ if ( !current_user_can( 'manage_bookings' ) ) {
194
+ return;
195
+ }
196
+
197
+ if ( !$this->is_valid_booking_status( $status ) ) {
198
+ return false;
199
+ }
200
+
201
+ $booking = get_post( $id );
202
+
203
+ if ( is_wp_error( $booking ) || !is_object( $booking ) ) {
204
+ return false;
205
+ }
206
+
207
+ if ( $booking->post_status === $status ) {
208
+ return null;
209
+ }
210
+
211
+ $result = wp_update_post(
212
+ array(
213
+ 'ID' => $id,
214
+ 'post_status' => $status,
215
+ 'edit_date' => current_time( 'mysql' ),
216
+ )
217
+ );
218
+
219
+ return $result ? true : false;
220
+ }
221
+
222
+ /**
223
+ * Check if status is valid for bookings
224
+ * @since 0.0.1
225
+ */
226
+ public function is_valid_booking_status( $status ) {
227
+ return isset( $this->booking_statuses[$status] ) ? true : false;
228
+ }
229
+
230
+ }
231
+ } // endif;
includes/Notification.Email.class.php ADDED
@@ -0,0 +1,187 @@
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbNotificationEmail' ) ) {
5
+ /**
6
+ * Class to handle an email notification for Restaurant Reservations
7
+ *
8
+ * This class extends rtbNotification and must implement the following methods:
9
+ * prepare_notification() - set up and validate data
10
+ * send_notification()
11
+ *
12
+ * @since 0.0.1
13
+ */
14
+ class rtbNotificationEmail extends rtbNotification {
15
+
16
+ /**
17
+ * Recipient email
18
+ * @since 0.0.1
19
+ */
20
+ public $to_email;
21
+
22
+ /**
23
+ * From email
24
+ * @since 0.0.1
25
+ */
26
+ public $from_email;
27
+
28
+ /**
29
+ * From name
30
+ * @since 0.0.1
31
+ */
32
+ public $from_name;
33
+
34
+ /**
35
+ * Email subject
36
+ * @since 0.0.1
37
+ */
38
+ public $subject;
39
+
40
+ /**
41
+ * Email message body
42
+ * @since 0.0.1
43
+ */
44
+ public $message;
45
+
46
+ /**
47
+ * Email headers
48
+ * @since 0.0.1
49
+ */
50
+ public $headers;
51
+
52
+ /**
53
+ * Prepare and validate notification data
54
+ *
55
+ * @return boolean if the data is valid and ready for transport
56
+ * @since 0.0.1
57
+ */
58
+ public function prepare_notification() {
59
+
60
+ $this->set_to_email();
61
+ $this->set_from_email();
62
+ $this->set_subject();
63
+ $this->set_headers();
64
+ $this->set_message();
65
+
66
+ // Return false if we're missing any of the required information
67
+ if ( empty( $this->to_email) ||
68
+ empty( $this->from_email) ||
69
+ empty( $this->from_name) ||
70
+ empty( $this->subject) ||
71
+ empty( $this->headers) ||
72
+ empty( $this->message) ) {
73
+ return false;
74
+ }
75
+
76
+ return true;
77
+ }
78
+
79
+ /**
80
+ * Set to email
81
+ * @since 0.0.1
82
+ */
83
+ public function set_to_email() {
84
+
85
+ if ( $this->target == 'user' ) {
86
+ $this->to_email = empty( $this->booking->email ) ? null : $this->booking->email;
87
+
88
+ } else {
89
+ global $rtb_controller;
90
+ $this->to_email = $rtb_controller->settings->get_setting( 'admin-email-address' );
91
+ }
92
+
93
+ }
94
+
95
+ /**
96
+ * Set from email
97
+ * @since 0.0.1
98
+ */
99
+ public function set_from_email() {
100
+
101
+ global $rtb_controller;
102
+
103
+ $this->from_email = $rtb_controller->settings->get_setting( 'reply-to-address' );
104
+ $this->from_name = $rtb_controller->settings->get_setting( 'reply-to-name' );
105
+
106
+ }
107
+
108
+ /**
109
+ * Set email subject
110
+ * @since 0.0.1
111
+ */
112
+ public function set_subject() {
113
+
114
+ global $rtb_controller;
115
+
116
+ if( $this->event == 'new_submission' ) {
117
+ if ( $this->target == 'admin' ) {
118
+ $this->subject = $rtb_controller->settings->get_setting( 'subject-booking-admin' );
119
+ } elseif ( $this->target == 'user' ) {
120
+ $this->subject = $rtb_controller->settings->get_setting( 'subject-booking-user' );
121
+ }
122
+
123
+ } elseif ( $this->event == 'pending_to_confirmed' ) {
124
+ $this->subject = $rtb_controller->settings->get_setting( 'subject-confirmed-user' );
125
+
126
+ } elseif ( $this->event == 'pending_to_closed' ) {
127
+ $this->subject = $rtb_controller->settings->get_setting( 'subject-rejected-user' );
128
+ }
129
+
130
+ }
131
+
132
+ /**
133
+ * Set email headers
134
+ * @since 0.0.1
135
+ */
136
+ public function set_headers( $headers = null ) {
137
+
138
+ $headers = "From: " . stripslashes_deep( html_entity_decode( $this->from_name, ENT_COMPAT, 'UTF-8' ) ) . " <" . $this->from_email . ">\r\n";
139
+ $headers .= "Reply-To: ". $this->from_email . "\r\n";
140
+ $headers .= "Content-Type: text/html; charset=utf-8\r\n";
141
+ $this->headers = apply_filters( 'rtb_notification_email_headers', $headers, $this );
142
+
143
+ }
144
+
145
+ /**
146
+ * Set email message body
147
+ * @since 0.0.1
148
+ */
149
+ public function set_message() {
150
+
151
+ $settings = get_option( 'rtb-settings' );
152
+
153
+ if ( $this->event == 'new_submission' ) {
154
+ if ( $this->target == 'user' ) {
155
+ $template = 'template-booking-user';
156
+ } elseif ( $this->target == 'admin' ) {
157
+ $template = 'template-booking-admin';
158
+ }
159
+
160
+ } elseif ( $this->event == 'pending_to_confirmed' ) {
161
+ if ( $this->target == 'user' ) {
162
+ $template = 'template-confirmed-user';
163
+ }
164
+
165
+ } elseif ( $this->event == 'pending_to_closed' ) {
166
+ if ( $this->target == 'user' ) {
167
+ $template = 'template-rejected-user';
168
+ }
169
+ }
170
+
171
+ if ( !isset( $template ) ) {
172
+ $this->message = '';
173
+ } else {
174
+ $this->message = wpautop( $this->process_template( $this->get_template( $template ) ) );
175
+ }
176
+
177
+ }
178
+
179
+ /**
180
+ * Send notification
181
+ * @since 0.0.1
182
+ */
183
+ public function send_notification() {
184
+ wp_mail( $this->to_email, $this->subject, $this->message, $this->headers );
185
+ }
186
+ }
187
+ } // endif;
includes/Notification.class.php ADDED
@@ -0,0 +1,106 @@
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbNotification' ) ) {
5
+ /**
6
+ * Base class to handle a notification for Restaurant Reservations
7
+ *
8
+ * This class sets up the notification content and sends it when run by
9
+ * rtbNotifications. This class should be extended for each type of
10
+ * notification. So, there would be a rtbNotificationEmail class or a
11
+ * rtbNotificationSMS class.
12
+ *
13
+ * @since 0.0.1
14
+ */
15
+ abstract class rtbNotification {
16
+
17
+ /**
18
+ * Event which should trigger this notification
19
+ * @since 0.0.1
20
+ */
21
+ public $event;
22
+
23
+ /**
24
+ * Target of the notification (who/what will receive it)
25
+ * @since 0.0.1
26
+ */
27
+ public $target;
28
+
29
+ /**
30
+ * Define the notification essentials
31
+ * @since 0.0.1
32
+ */
33
+ public function __construct( $event, $target ) {
34
+
35
+ $this->event = $event;
36
+ $this->target = $target;
37
+
38
+ }
39
+
40
+ /**
41
+ * Set booking data passed from rtbNotifications
42
+ *
43
+ * @var object $booking
44
+ * @since 0.0.1
45
+ */
46
+ public function set_booking( $booking ) {
47
+ $this->booking = $booking;
48
+ }
49
+
50
+ /**
51
+ * Prepare and validate notification data
52
+ *
53
+ * @return boolean if the data is valid and ready for transport
54
+ * @since 0.0.1
55
+ */
56
+ abstract public function prepare_notification();
57
+
58
+ /**
59
+ * Retrieve a notification template
60
+ * @since 0.0.1
61
+ */
62
+ public function get_template( $type ) {
63
+
64
+ global $rtb_controller;
65
+
66
+ $template = $rtb_controller->settings->get_setting( $type );
67
+
68
+ if ( $template === null ) {
69
+ return '';
70
+ } else {
71
+ return $template;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Process a template and insert booking details
77
+ * @since 0.0.1
78
+ */
79
+ public function process_template( $message ) {
80
+
81
+ $template_tags = array(
82
+ '{user_name}' => $this->booking->name,
83
+ '{party}' => $this->booking->party,
84
+ '{date}' => $this->booking->date,
85
+ '{bookings_link}' => '<a href="' . admin_url( 'admin.php?page=rtb-bookings&status=pending' ) . '">' . __( 'View pending bookings', RTB_TEXTDOMAIN ) . '</a>',
86
+ '{confirm_link}' => '<a href="' . admin_url( 'admin.php?page=rtb-bookings&rtb-quicklink=confirm&booking=' . esc_attr( $this->booking->ID ) ) . '">' . __( 'Confirm this booking', RTB_TEXTDOMAIN ) . '</a>',
87
+ '{close_link}' => '<a href="' . admin_url( 'admin.php?page=rtb-bookings&rtb-quicklink=close&booking=' . esc_attr( $this->booking->ID ) ) . '">' . __( 'Reject this booking', RTB_TEXTDOMAIN ) . '</a>',
88
+ '{site_name}' => get_bloginfo( 'name' ),
89
+ '{site_link}' => '<a href="' . home_url( '/' ) . '">' . get_bloginfo( 'name' ) . '</a>',
90
+ '{current_time}' => date( get_option( 'date_format' ), current_time( 'timestamp' ) ) . ' ' . date( get_option( 'time_format' ), current_time( 'timestamp' ) ),
91
+ );
92
+
93
+ $template_tags = apply_filters( 'rtb_notification_template_tags', $template_tags, $this );
94
+
95
+ return str_replace( array_keys( $template_tags ), array_values( $template_tags ), $message );
96
+
97
+ }
98
+
99
+ /**
100
+ * Send notification
101
+ * @since 0.0.1
102
+ */
103
+ abstract public function send_notification();
104
+
105
+ }
106
+ } // endif;
includes/Notifications.class.php ADDED
@@ -0,0 +1,187 @@