Restaurant Reservations - Version 2.0.0

Version Description

(2019-10-28) = - This is a big update with many new features, corrections, revised admin styling, etc., so please take caution and test before updating on a live site (or wait a few days before updating in case some minor corrective updates need to be put out) - The Options pages have a brand new and easy-to-use design, to go hand in hand with the many, many new options! - Added in two brand new responsive reservation form layouts - Added in a new styling options section that lets you customize the colors, fonts, borders etc. of all elements of your restaurant booking form - Added in a new "view bookings" shortcode and page - Added in the ability to automatically confirm reservations when less than X reservations or seats are taken during a time block - Added in the ability to specify a dining block length - Added in a "Max Reservations" number for a particular timeslot, so that it's not possible to book within a timeslot once that number has been reached - Added in an option for guests to be checked in as they arrive - Added in a walkthrough on installation to help you get going as quickly as possible - Added in defaults for several options - Updated the styling of certain default features to be consistent with new features - Other styling and ease-of-use changes - Updated the order, layout and descriptions of several options - Updated the upgrade-to-premium process to be much quicker and easier - Corrected issue causing the email template designer to not load properly in the customizer - Corrected internal settings version numbering that was causing an issue with the Business Profile plugin settings - Removed files from the plugin that were not being used/not needed

Download this release

Release Info

Developer Rustaurius
Plugin Icon 128x128 Restaurant Reservations
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.9.0 to 2.0.0

Files changed (74) hide show
  1. assets/css/admin-rtb-welcome-screen.css +367 -0
  2. assets/css/admin.css +2538 -716
  3. assets/css/booking-form.css +28 -5
  4. assets/css/columns.css +120 -0
  5. assets/css/contemporary.css +158 -0
  6. assets/css/editor.css +582 -0
  7. assets/css/spectrum.css +507 -0
  8. assets/img/dash-asset-badge.png +0 -0
  9. assets/img/dash-asset-checkmark.png +0 -0
  10. assets/img/dash-asset-key.png +0 -0
  11. assets/img/dash-asset-stars.png +0 -0
  12. assets/img/ewd-support-icon-documentation.png +0 -0
  13. assets/img/ewd-support-icon-faqs.png +0 -0
  14. assets/img/ewd-support-icon-forum.png +0 -0
  15. assets/img/ewd-support-icon-youtube.png +0 -0
  16. assets/img/fivestartextlogo.png +0 -0
  17. assets/img/fivestartextlogowithstar.png +0 -0
  18. assets/img/options-asset-lock.png +0 -0
  19. assets/img/options-asset-star.png +0 -0
  20. assets/js/admin-rtb-welcome-screen.js +63 -0
  21. assets/js/admin-settings.js +42 -0
  22. assets/js/admin.js +1041 -830
  23. assets/js/booking-form.js +177 -111
  24. assets/js/columns.js +17 -0
  25. assets/js/contemporary.js +26 -0
  26. assets/js/customizer-control.js +52 -0
  27. assets/js/customizer-control.min.js +2 -0
  28. assets/js/editor.js +1236 -0
  29. assets/js/mailchimp-admin.js +2 -0
  30. assets/js/mailchimp-subscribe.js +2 -0
  31. assets/js/spectrum.js +2317 -0
  32. includes/Addons.class.php +2 -2
  33. includes/AdminBookings.class.php +28 -0
  34. includes/Ajax.class.php +272 -0
  35. includes/Booking.class.php +130 -1
  36. includes/Compatibility.class.php +8 -8
  37. includes/Cron.class.php +234 -0
  38. includes/CustomFields.class.php +192 -0
  39. includes/CustomPostTypes.class.php +51 -1
  40. includes/Dashboard.class.php +415 -0
  41. includes/Editor.class.php +845 -0
  42. includes/EmailTemplates.class.php +75 -0
  43. includes/Export.CSV.class.php +263 -0
  44. includes/Export.PDF.class.php +307 -0
  45. includes/Export.class.php +129 -0
  46. includes/ExportHandler.class.php +302 -0
  47. includes/Field.Controller.class.php +784 -0
  48. includes/Field.class.php +597 -0
  49. includes/Import.class.php +279 -0
  50. includes/InstallationWalkthrough.class.php +391 -0
  51. includes/MailChimp.class.php +535 -0
  52. includes/MailChimpRequest.class.php +142 -0
  53. includes/Notification.Email.class.php +17 -1
  54. includes/Permissions.class.php +61 -0
  55. includes/Query.class.php +5 -1
  56. includes/Settings.class.php +902 -135
  57. includes/class-designer.php +287 -0
  58. includes/custom_fields_pointers.php +99 -0
  59. includes/integrations/business-profile.php +178 -0
  60. includes/load-customizer.php +711 -0
  61. includes/load-notifications.php +51 -0
  62. includes/template-functions.php +235 -1
  63. lib/mpdf/CHANGELOG.txt +3110 -0
  64. lib/mpdf/CREDITS.txt +92 -0
  65. lib/mpdf/LICENSE.txt +340 -0
  66. lib/mpdf/README.txt +130 -0
  67. lib/mpdf/classes/barcode.php +1972 -0
  68. lib/mpdf/classes/bmp.php +248 -0
  69. lib/mpdf/classes/cssmgr.php +1721 -0
  70. lib/mpdf/classes/desktop.ini +4 -0
  71. lib/mpdf/classes/directw.php +412 -0
  72. lib/mpdf/classes/gif.php +700 -0
  73. lib/mpdf/classes/grad.php +724 -0
  74. lib/mpdf/classes/indic.php +776 -0
assets/css/admin-rtb-welcome-screen.css ADDED
@@ -0,0 +1,367 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .rtb-hidden {
2
+ display: none;
3
+ }
4
+ .rtb-welcome-clear {
5
+ clear: both;
6
+ }
7
+
8
+ .rtb-welcome-screen-header h1 {
9
+ padding: 48px 0 16px 0;
10
+ margin: 0;
11
+ }
12
+ .rtb-welcome-screen-header p {
13
+ margin-bottom: 32px;
14
+ font-size: 15px;
15
+ }
16
+ .rtb-welcome-screen h2 {
17
+ background: #1b335f;
18
+ color: #fff;
19
+ padding: 18px;
20
+ margin: 0;
21
+ z-index: 2;
22
+ position: relative;
23
+ float: left;
24
+ width: calc(100% - 36px);
25
+ border-top: 1px solid #42639F;
26
+ }
27
+ .rtb-welcome-screen h2:hover {
28
+ background: #365388;
29
+ }
30
+
31
+ .rtb-welcome-screen-box .rtb-welcome-screen-box-content {
32
+ display: none;
33
+ }
34
+
35
+ .rtb-welcome-screen-box.rtb-welcome-screen-open .rtb-welcome-screen-box-content {
36
+ display: block;
37
+ }
38
+
39
+ .rtb-welcome-screen-box {
40
+ padding: 0px;
41
+ max-width: 800px;
42
+ margin: 0 auto;
43
+ }
44
+
45
+ .rtb-welcome-screen-header,
46
+ .rtb-welcome-screen-skip-container {
47
+ max-width: 800px;
48
+ margin: 0 auto;
49
+ }
50
+
51
+ .rtb-welcome-screen-header {
52
+ text-align: center;
53
+ }
54
+
55
+ .rtb-welcome-screen-box h2 {
56
+ cursor: pointer;
57
+ }
58
+
59
+ .rtb-welcome-screen-box-content {
60
+ position: relative;
61
+ float: left;
62
+ background: #fff;
63
+ width: 90%;
64
+ margin: 0 auto 16px;
65
+ box-shadow: 0 1px 12px #ddd;
66
+ display: block;
67
+ padding: 18px 5%;
68
+ }
69
+
70
+ .rtb-welcome-screen-add-reservations-page-button,
71
+ .rtb-welcome-screen-save-schedule-open-button,
72
+ .rtb-welcome-screen-save-options-button {
73
+ position: relative;
74
+ float: left;
75
+ cursor: pointer;
76
+ padding: 4px 8px;
77
+ border: 2px solid #1b335f;
78
+ color: #fff;
79
+ border-radius: 2px;
80
+ background: #1b335f;
81
+ width: auto;
82
+ text-align: center;
83
+ margin-top: 12px;
84
+ }
85
+ .rtb-welcome-screen-add-reservations-page-button:hover,
86
+ .rtb-welcome-screen-save-schedule-open-button:hover,
87
+ .rtb-welcome-screen-save-options-button:hover {
88
+ border-color: #365388;
89
+ background: #365388;
90
+ }
91
+
92
+ .rtb-welcome-screen-next-button,
93
+ .rtb-welcome-screen-previous-button,
94
+ .rtb-welcome-screen-finish-button a {
95
+ position: relative;
96
+ float: right;
97
+ cursor: pointer;
98
+ padding: 4px 8px;
99
+ border: 2px solid #1b335f;
100
+ color: #1b335f;
101
+ border-radius: 2px;
102
+ background: transparent;
103
+ width: auto;
104
+ text-align: center;
105
+ margin-top: 32px;
106
+ text-decoration: none;
107
+ }
108
+ .rtb-welcome-screen-next-button:hover,
109
+ .rtb-welcome-screen-previous-button:hover,
110
+ .rtb-welcome-screen-finish-button a:hover {
111
+ color: #fff;
112
+ background: #1b335f;
113
+ text-decoration: none;
114
+ }
115
+ .rtb-welcome-screen-next-button-not-top-margin {
116
+ margin-top: 12px;
117
+ }
118
+ .rtb-welcome-screen-previous-button {
119
+ float: left;
120
+ }
121
+
122
+ .rtb-welcome-screen-skip-button {
123
+ position: relative;
124
+ float: right;
125
+ cursor: pointer;
126
+ padding: 4px 8px;
127
+ border: 2px solid #ccc;
128
+ color: #999;
129
+ border-radius: 2px;
130
+ background: transparent;
131
+ width: auto;
132
+ text-align: center;
133
+ margin-top: 12px;
134
+ }
135
+ .rtb-welcome-screen-skip-button:hover {
136
+ border-color: #aaa;
137
+ color: #fff;
138
+ background: #aaa;
139
+ }
140
+
141
+ .rtb-welcome-screen-box-content label {
142
+ width: 160px;
143
+ position: relative;
144
+ float: left;
145
+ font-weight: bold;
146
+ }
147
+ .rtb-welcome-screen-option {
148
+ margin: 7px 0;
149
+ }
150
+ .rtb-welcome-screen-option label {
151
+ width: 100px;
152
+ float: left;
153
+ font-weight: normal;
154
+ }
155
+ .rtb-welcome-screen-option label.rtb-admin-switch {
156
+ width: 40px
157
+ }
158
+
159
+ .rtb-welcome-screen-box-content input {
160
+ margin: 0;
161
+ }
162
+ .rtb-welcome-screen-box-content-divs {
163
+ margin-bottom: 8px;
164
+ }
165
+
166
+
167
+ .rtb-welcome-screen-show-created-sections {
168
+ display: none;
169
+ }
170
+
171
+ .rtb-welcome-screen-show-created-sections-name {
172
+ position: relative;
173
+ float: left;
174
+ width: 40%;
175
+ width: calc(40% - 2px);
176
+ padding: 9px 5%;
177
+ border-left: 1px solid #ccc;
178
+ border-right: 1px solid #ccc;
179
+ font-size: 15px;
180
+ font-weight: bold;
181
+ border-top: 1px solid #ccc;
182
+ border-bottom: 1px solid #ccc;
183
+ }
184
+ .rtb-welcome-screen-show-created-sections-description {
185
+ position: relative;
186
+ float: right;
187
+ width: 40%;
188
+ width: calc(40% - 1px);
189
+ border-right: 1px solid #ccc;
190
+ padding: 9px 5%;
191
+ font-size: 15px;
192
+ font-weight: bold;
193
+ border-top: 1px solid #ccc;
194
+ border-bottom: 1px solid #ccc;
195
+ }
196
+ .rtb-welcome-screen-section-name {
197
+ position: relative;
198
+ float: left;
199
+ width: 40%;
200
+ width: calc(40% - 2px);
201
+ padding: 7px 5%;
202
+ height: 18px;
203
+ overflow: hidden;
204
+ border-left: 1px solid #ccc;
205
+ border-right: 1px solid #ccc;
206
+ border-bottom: 1px solid #ccc;
207
+ }
208
+ .rtb-welcome-screen-section-description {
209
+ position: relative;
210
+ float: right;
211
+ width: 40%;
212
+ width: calc(40% - 1px);
213
+ padding: 7px 5%;
214
+ height: 18px;
215
+ overflow: hidden;
216
+ border-right: 1px solid #ccc;
217
+ border-bottom: 1px solid #ccc;
218
+ }
219
+
220
+
221
+ .rtb-welcome-screen-show-created-menu_items {
222
+ display: none;
223
+ }
224
+
225
+ .rtb-welcome-screen-show-created-menu_items-image {
226
+ position: relative;
227
+ float: left;
228
+ width: 20%;
229
+ width: calc(20% - 2px);
230
+ padding: 9px 2.5%;
231
+ border-left: 1px solid #ccc;
232
+ border-right: 1px solid #ccc;
233
+ font-size: 15px;
234
+ font-weight: bold;
235
+ border-top: 1px solid #ccc;
236
+ border-bottom: 1px solid #ccc;
237
+ }
238
+ .rtb-welcome-screen-show-created-menu_items-name {
239
+ position: relative;
240
+ float: left;
241
+ width: 20%;
242
+ width: calc(20% - 1px);
243
+ border-right: 1px solid #ccc;
244
+ padding: 9px 2.5%;
245
+ font-size: 15px;
246
+ font-weight: bold;
247
+ border-top: 1px solid #ccc;
248
+ border-bottom: 1px solid #ccc;
249
+ }
250
+ .rtb-welcome-screen-show-created-menu_items-description {
251
+ position: relative;
252
+ float: left;
253
+ width: 20%;
254
+ width: calc(20% - 1px);
255
+ border-right: 1px solid #ccc;
256
+ padding: 9px 2.5%;
257
+ font-size: 15px;
258
+ font-weight: bold;
259
+ border-top: 1px solid #ccc;
260
+ border-bottom: 1px solid #ccc;
261
+ }
262
+ .rtb-welcome-screen-show-created-menu_items-price {
263
+ position: relative;
264
+ float: left;
265
+ width: 20%;
266
+ width: calc(20% - 1px);
267
+ border-right: 1px solid #ccc;
268
+ padding: 9px 2.5%;
269
+ font-size: 15px;
270
+ font-weight: bold;
271
+ border-top: 1px solid #ccc;
272
+ border-bottom: 1px solid #ccc;
273
+ }
274
+ .rtb-welcome-screen-menu_item-image {
275
+ position: relative;
276
+ float: left;
277
+ width: 20%;
278
+ width: calc(20% - 2px);
279
+ padding: 7px 2.5%;
280
+ height: 100px;
281
+ overflow: hidden;
282
+ border-left: 1px solid #ccc;
283
+ border-right: 1px solid #ccc;
284
+ border-bottom: 1px solid #ccc;
285
+ }
286
+ .rtb-welcome-screen-menu_item-image img {
287
+ width: auto;
288
+ height: auto;
289
+ max-width: 100%;
290
+ max-height: 100%;
291
+ }
292
+ .rtb-welcome-screen-menu_item-name {
293
+ position: relative;
294
+ float: left;
295
+ width: 20%;
296
+ width: calc(20% - 1px);
297
+ padding: 7px 2.5%;
298
+ height: 100px;
299
+ overflow: hidden;
300
+ border-right: 1px solid #ccc;
301
+ border-bottom: 1px solid #ccc;
302
+ }
303
+ .rtb-welcome-screen-menu_item-description {
304
+ position: relative;
305
+ float: left;
306
+ width: 20%;
307
+ width: calc(20% - 1px);
308
+ padding: 7px 2.5%;
309
+ height: 100px;
310
+ overflow: hidden;
311
+ border-right: 1px solid #ccc;
312
+ border-bottom: 1px solid #ccc;
313
+ }
314
+ .rtb-welcome-screen-menu_item-price {
315
+ position: relative;
316
+ float: left;
317
+ width: 20%;
318
+ width: calc(20% - 1px);
319
+ padding: 7px 2.5%;
320
+ height: 100px;
321
+ overflow: hidden;
322
+ border-right: 1px solid #ccc;
323
+ border-bottom: 1px solid #ccc;
324
+ }
325
+
326
+ .rtb-welcome-screen-add-create_menu-sections h3 {
327
+ padding-bottom: 0;
328
+ margin-bottom: 0;
329
+ }
330
+
331
+ .rtb-save-message {
332
+ clear: both;
333
+ position: relative;
334
+ float: left;
335
+ width: 100%;
336
+ margin: 16px 0;
337
+ }
338
+ .rtb-save-message-inside {
339
+ position: relative;
340
+ float: left;
341
+ padding: 8px 12px;
342
+ background: #eee;
343
+ }
344
+
345
+ .rtb-welcome-screen-image-preview-container {
346
+ float: left;
347
+ width: calc(100% - 160px);
348
+ margin-bottom: 10px;
349
+ }
350
+ .rtb-welcome-screen-image-preview img {
351
+ width: 180px;
352
+ height: auto;
353
+ }
354
+
355
+ /*scheduler*/
356
+ .rtb-welcome-screen-box-content .sap-scheduler label {
357
+ width: auto;
358
+ float: none;
359
+ text-align: center;
360
+ font-weight: normal;
361
+ }
362
+ .rtb-welcome-screen-box-content .sap-scheduler .sap-scheduler-time-input label {
363
+ text-align: left;
364
+ }
365
+ .rtb-welcome-screen-box-content .sap-scheduler input[type="checkbox"] {
366
+ margin: 6px 4px 7px 0;
367
+ }
assets/css/admin.css CHANGED
@@ -1,716 +1,2538 @@
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 Admin List Table */
14
- #rtb-bookings-table .rtb-primary-controls {
15
- margin-top: 2em;
16
- }
17
-
18
- #rtb-bookings-table .subsubsub {
19
- float: none;
20
- margin: 0.5em 0 1em;
21
- text-align: left;
22
- }
23
-
24
- #rtb-bookings-table .subsubsub .trash a {
25
- color: #a00;
26
- }
27
-
28
- #rtb-bookings-table .subsubsub .trash a:hover {
29
- color: red;
30
- }
31
-
32
- #rtb-filters {
33
- position: relative;
34
- }
35
-
36
- #rtb-filters .date-filters {
37
- position: absolute;
38
- top: -9999px;
39
- left: -9999px;
40
- display: inline-block;
41
- padding: 1em;
42
- background: #fff;
43
- -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
44
- box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
45
- }
46
-
47
- #rtb-filters.date-filters-visible .date-filters {
48
- position: relative;
49
- top: auto;
50
- left: 0;
51
- }
52
-
53
- #rtb-filters .date-filters .datepicker {
54
- max-width: 10em;
55
- }
56
-
57
- #rtb-filters .date-filter-range {
58
- padding: 0.25em;
59
- }
60
-
61
- #rtb-date-filter-link {
62
- position: relative;
63
- }
64
-
65
- #rtb-date-filter-link .dashicons {
66
- line-height: 1.5;
67
- }
68
-
69
- #rtb-filters .date-filter-range + #rtb-date-filter-link {
70
- margin-left: 0.5em;
71
- }
72
-
73
- #rtb-date-filter-link .rtb-date-filter-label {
74
- position: absolute;
75
- top: -9999px;
76
- left: -9999px;
77
- }
78
-
79
- #rtb-filters.date-filters-visible #rtb-date-filter-link {
80
- color: #777;
81
- }
82
-
83
- #rtb-filters.date-filters-visible #rtb-date-filter-link:before {
84
- content: '';
85
- position: absolute;
86
- top: 60%;
87
- left: 50%;
88
- margin-left: -1em;
89
- width: 0;
90
- height: 0;
91
- border: 1em solid transparent;
92
- border-bottom: 1em solid #fff;
93
- }
94
-
95
- #rtb-filters .current {
96
- font-weight: 600;
97
- color: #000;
98
- }
99
-
100
- #rtb-bookings-table .tablenav .actions .button {
101
- margin-top: 1px;
102
- margin-bottom: 1px;
103
- }
104
-
105
- #rtb-bookings-table .tablenav .actions .button .dashicons {
106
- line-height: 28px;
107
- }
108
-
109
- #rtb-bookings-table .rtb-notice,
110
- #rtb-bookings-table .rtb-top-actions-wrapper,
111
- #rtb-bookings-table .rtb-table-header-controls {
112
- margin: 1em 0;
113
- }
114
-
115
- #rtb-bookings-table .rtb-table-header-controls {
116
- margin-bottom: 0;
117
- }
118
-
119
- #rtb-bookings-table .rtb-notice {
120
- padding: 1em;
121
- background: #2ea2cc;
122
- color: #fff;
123
- }
124
-
125
- #rtb-bookings-table .rtb-table-header-controls {
126
- position: relative;
127
- top: 1px;
128
- overflow: hidden;
129
- margin-bottom: 0.5em;
130
- }
131
-
132
- #rtb-bookings-table select[name="action"],
133
- #rtb-bookings-table select[name="action2"],
134
- #rtb-bookings-table .rtb-location-switch select {
135
- max-width: 120px;
136
- }
137
-
138
- #rtb-bookings-table .rtb-table-header-controls .bulkactions {
139
- float: left;
140
- }
141
-
142
- #rtb-bookings-table .rtb-locations {
143
- display: none;
144
- margin: 0;
145
- width: 9999px;
146
- }
147
-
148
- #rtb-bookings-table .rtb-locations li {
149
- display: inline-block;
150
- margin: 0;
151
- line-height: 38px;
152
- position: relative;
153
- }
154
-
155
- #rtb-bookings-table .rtb-locations a {
156
- display: block;
157
- padding: 0 1em;
158
- font-weight: 700;
159
- color: #777;
160
- text-decoration: none;
161
- }
162
-
163
- #rtb-bookings-table .rtb-locations .current a {
164
- background: #fff;
165
- color: #333;
166
- border: 1px solid #ddd;
167
- border-bottom: 0;
168
- }
169
-
170
- #rtb-bookings-table .rtb-location-switch {
171
- float: left;
172
- }
173
-
174
- #rtb-bookings-table .rtb-locations-button {
175
- margin-bottom: 0;
176
- }
177
-
178
- #rtb-bookings-table tr.closed {
179
- opacity: 0.6;
180
- filter: opacity(alpha=60);
181
- }
182
- #rtb-bookings-table tr.closed:hover {
183
- opacity: 1;
184
- filter: opacity(alpha=100);
185
- }
186
-
187
- #rtb-bookings-table tr.pending .check-column {
188
- border-left: 4px solid #dd3d36;
189
- }
190
-
191
- #rtb-bookings-table tr.pending .check-column input[type=checkbox] {
192
- margin-left: 4px;
193
- }
194
-
195
- #rtb-bookings-table th#date {
196
- width: auto;
197
- }
198
-
199
- #rtb-bookings-table th#party {
200
- width: 3em;
201
- }
202
-
203
- #rtb-bookings-table th#details {
204
- width: 4em;
205
- }
206
-
207
- #rtb-bookings-table td .actions {
208
- line-height: 1.5em;
209
- opacity: 0;
210
- -webkit-transition: opacity 0.3s 0;
211
- -moz-transition: opacity 0.3s 0;
212
- transition: opacity 0.3s 0;
213
- }
214
-
215
- #rtb-bookings-table tr:hover td .actions {
216
- opacity: 1;
217
- }
218
-
219
- #rtb-bookings-table .column-date .actions .trash,
220
- #rtb-bookings-table .actions [data-action="delete"] {
221
- color: #a00;
222
- }
223
-
224
- #rtb-bookings-table .column-date .actions .trash:hover,
225
- #rtb-bookings-table .actions [data-action="delete"]:hover {
226
- color: red;
227
- }
228
-
229
- #rtb-bookings-table .column-date .status {
230
- width: 0;
231
- height: 0;
232
- overflow: hidden;
233
- line-height: 28px;
234
- opacity: 0;
235
- -webkit-transition: opacity 0.6s 0;
236
- -moz-transition: opacity 0.6s 0;
237
- transition: opacity 0.6s 0;
238
- }
239
-
240
- #rtb-bookings-table .column-date .status .spinner {
241
- visibility: visible;
242
- display: inline-block;
243
- float: left;
244
- margin: 4px 4px 0 0;
245
- vertical-align: middle;
246
- }
247
-
248
- #rtb-bookings-table .column-date.loading .actions {
249
- display: none;
250
- }
251
-
252
- #rtb-bookings-table .column-date.loading .status {
253
- width: auto;
254
- height: auto;
255
- overflow: visible;
256
- opacity: 0.5;
257
- }
258
-
259
- #rtb-bookings-table tr ul {
260
- margin: 0;
261
- }
262
-
263
- #rtb-bookings-table .consent {
264
- margin-top: 0.5em;
265
- }
266
-
267
- .rtb-details-data {
268
- display: none;
269
- }
270
-
271
- .rtb-details-data .details {
272
- margin: 0;
273
- }
274
-
275
- .rtb-details-data .details > li {
276
- margin-top: 2em;
277
- }
278
-
279
- .rtb-details-data .details > li:first-child {
280
- margin-top: 0;
281
- }
282
-
283
- .rtb-details-data .details .label {
284
- font-weight: 900;
285
- }
286
-
287
- #rtb-details-modal .rtb-details-data {
288
- display: block;
289
- }
290
-
291
- @media screen and (min-width: 783px) {
292
-
293
- #rtb-bookings-table .rtb-locations li {
294
- line-height: 32px;
295
- }
296
- }
297
-
298
- @media screen and (min-width: 930px) {
299
-
300
- #rtb-bookings-table .rtb-primary-controls {
301
- margin-top: 0;
302
- }
303
-
304
- #rtb-bookings-table .rtb-views {
305
- float: right;
306
- width: 50%;
307
- }
308
-
309
- #rtb-bookings-table .rtb-views .subsubsub {
310
- text-align: right;
311
- }
312
-
313
- #rtb-filters {
314
- float: left;
315
- width: 50%;
316
- }
317
-
318
- #rtb-filters .date-filters {
319
- margin-right: 2em;
320
- }
321
-
322
- #rtb-bookings-table .rtb-locations {
323
- display: block;
324
- }
325
-
326
- #rtb-bookings-table .rtb-table-header-controls {
327
- margin-bottom: 0;
328
- }
329
-
330
- #rtb-bookings-table .rtb-location-switch {
331
- position: absolute;
332
- top: 0;
333
- right: 0;
334
- background: #eee;
335
- padding-left: 1em;
336
- }
337
- }
338
-
339
- @media screen and (max-width: 782px) {
340
-
341
- /* Prevent date column from being hidden in WP versions < 4.3 */
342
- #rtb-bookings-table .fixed .column-date {
343
- display: table-cell;
344
- }
345
-
346
- /* Always display details data in mobile views */
347
- #rtb-bookings-table .column-details .rtb-details-data {
348
- display: block;
349
- }
350
-
351
- #rtb-bookings-table .column-details .rtb-show-details {
352
- display: none;
353
- }
354
- }
355
-
356
- /* Add/edit bookings modal */
357
- .rtb-admin-modal {
358
- position: fixed;
359
- top: 0;
360
- left: 0;
361
- width: 100%;
362
- height: 100%;
363
- background: rgba(0, 0, 0, 0.8);
364
- z-index: 9999;
365
- overflow-y: auto;
366
- cursor: pointer;
367
- visibility: hidden;
368
- opacity: 0;
369
- -webkit-transition: opacity 0.3s 0, visibility 0 0.3s;
370
- -moz-transition: opacity 0.3s 0, visibility 0 0.3s;
371
- transition: opacity 0.3s 0, visibility 0 0.3s;
372
- }
373
-
374
- .rtb-admin-modal.is-visible {
375
- visibility: visible;
376
- opacity: 1;
377
- -webkit-transition: opacity 0.3s 0, visibility 0 0;
378
- -moz-transition: opacity 0.3s 0, visibility 0 0;
379
- transition: opacity 0.3s 0, visibility 0 0;
380
- }
381
-
382
- .rtb-admin-modal.is-visible .rtb-container {
383
- -webkit-transform: translateY(0);
384
- -moz-transform: translateY(0);
385
- -ms-transform: translateY(0);
386
- -o-transform: translateY(0);
387
- transform: translateY(0);
388
- }
389
-
390
- .rtb-admin-modal .rtb-container {
391
- position: relative;
392
- width: 90%;
393
- max-width: 20em;
394
- padding: 2em;
395
- background: #FFF;
396
- margin: 3em auto 4em;
397
- cursor: auto;
398
- border-radius: 0.25em;
399
- -webkit-transform: translateY(-30px);
400
- -moz-transform: translateY(-30px);
401
- -ms-transform: translateY(-30px);
402
- -o-transform: translateY(-30px);
403
- transform: translateY(-30px);
404
- -webkit-transition-property: -webkit-transform;
405
- -moz-transition-property: -moz-transform;
406
- transition-property: transform;
407
- -webkit-transition-duration: 0.3s;
408
- -moz-transition-duration: 0.3s;
409
- transition-duration: 0.3s;
410
- }
411
-
412
- .rtb-admin-modal fieldset {
413
- padding: 0;
414
- }
415
-
416
- .rtb-admin-modal fieldset > div {
417
- margin-top: 1em;
418
- }
419
-
420
- .rtb-admin-modal legend {
421
- font-size: 1.5em;
422
- margin: 0 0 0.83em;
423
- font-weight: 400;
424
- padding: 0;
425
- }
426
-
427
- .rtb-admin-modal label {
428
- color: #777;
429
- font-style: italic;
430
- display: block;
431
- }
432
-
433
- .rtb-admin-modal .button {
434
- margin-top: 1em;
435
- margin-right: 0.5em;
436
- }
437
-
438
- .rtb-admin-modal button,
439
- .rtb-admin-modal .button {
440
- opacity: 1;
441
- transition: opacity .25s ease-in-out;
442
- -moz-transition: opacity .25s ease-in-out;
443
- -webkit-transition: opacity .25s ease-in-out;
444
- }
445
-
446
- .rtb-admin-modal button:disabled,
447
- .rtb-admin-modal .button:disabled {
448
- opacity: 0.5;
449
- transition: opacity .25s ease-in-out;
450
- -moz-transition: opacity .25s ease-in-out;
451
- -webkit-transition: opacity .25s ease-in-out;
452
- }
453
-
454
- .rtb-admin-modal .button-link {
455
- display: inline-block;
456
- margin-top: 1em;
457
- line-height: 26px;
458
- }
459
-
460
- .rtb-admin-modal .action-status {
461
- display: inline-block;
462
- float: right;
463
- margin-top: 1em;
464
- opacity: 0;
465
- transition: opacity .25s ease-in-out;
466
- -moz-transition: opacity .25s ease-in-out;
467
- -webkit-transition: opacity .25s ease-in-out;
468
- }
469
-
470
- .rtb-admin-modal .action-status.is-visible {
471
- opacity: 1;
472
- }
473
-
474
- .rtb-admin-modal .action-status > span {
475
- display: none;
476
- background-position: 4px;
477
- margin: 0;
478
- height: 28px;
479
- width: 28px;
480
- line-height: 28px;
481
- font-size: 28px;
482
- }
483
-
484
- .rtb-admin-modal .action-status > .spinner {
485
- visibility: visible;
486
- display: block;
487
- }
488
-
489
- .rtb-admin-modal .action-status > .success {
490
- color: #7ad03a;
491
- }
492
-
493
- .rtb-admin-modal .action-status > .error {
494
- color: #dd3d36;
495
- }
496
-
497
- #rtb-booking-form .rtb-error {
498
- background: #dd3d36;
499
- }
500
-
501
- #rtb-booking-form .rtb-error a {
502
- color: #fff;
503
- }
504
-
505
- .rtb-admin-modal input[type="text"],
506
- .rtb-admin-modal input[type="email"],
507
- .rtb-admin-modal input[type="tel"],
508
- .rtb-admin-modal textarea {
509
- max-width: 100%;
510
- width: 100%;
511
- }
512
-
513
- #rtb-email-modal .rtb-email-to {
514
- font-weight: 700;
515
- color: #777;
516
- }
517
-
518
- #rtb-email-modal textarea {
519
- min-height: 12em;
520
- }
521
-
522
- #rtb-delete-modal #rtb-delete-status {
523
- display: none;
524
- margin-top: 2em;
525
- margin-bottom: 1em;
526
- }
527
-
528
- #rtb-delete-modal #rtb-delete-status.is-visible {
529
- display: block;
530
- }
531
-
532
- #rtb-delete-modal .rtb-delete-status-total {
533
- position: relative;
534
- display: block;
535
- width: 100%;
536
- height: 16px;
537
- border: 1px solid #0085ba;
538
- }
539
-
540
- #rtb-delete-modal .rtb-delete-status-progress {
541
- position: absolute;
542
- display: block;
543
- width: 0;
544
- height: 100%;
545
- background: #0085ba;
546
- transition: width 0.2s;
547
- }
548
-
549
- #rtb-delete-modal #rtb-delete-status-deleted {
550
- margin-top: 0.5em;
551
- text-align: right;
552
- }
553
-
554
- #rtb-delete-modal #rtb-cancel-delete-modal {
555
- padding-left: 1em;
556
- padding-right: 1em;
557
- }
558
-
559
- .rtb-description {
560
- margin: 0.5em 0;
561
- color: #777;
562
- max-height: 0;
563
- overflow: hidden;
564
- -webkit-transition: max-height 0.5s 0;
565
- -moz-transition: max-height 0.5s 0;
566
- transition: max-height 0.5s 0;
567
- }
568
-
569
- .rtb-description.is-visible {
570
- max-height: 20em;
571
- }
572
-
573
- .rtb-column-form ul {
574
- margin: 0;
575
- }
576
-
577
- .rtb-column-form label {
578
- font-style: normal;
579
- padding: 2px 0;
580
- }
581
-
582
- .rtb-column-form fieldset {
583
- margin-bottom: 2em;
584
- }
585
-
586
- .rtb-column-form .action-status {
587
- margin-top: 0;
588
- }
589
-
590
- #rtb-error-modal .rtb-error-msg {
591
- margin-bottom: 1em;
592
- }
593
-
594
- .rtb-ban-form .intro {
595
- margin-top: 0;
596
- font-weight: bold;
597
- }
598
-
599
- .rtb-ban-form .intro span {
600
- color: #a55;
601
- }
602
-
603
- .rtb-ban-form .button-primary {
604
- display: block;
605
- width: 100%;
606
- margin-top: 2em;
607
- margin-bottom: 2em;
608
- }
609
-
610
- /* Hide the outer scrollbar when the modal is open */
611
- .rtb-hide-body-scroll {
612
- overflow: hidden !important;
613
- }
614
-
615
- /* Settings Pages (most of this is handled by the Simple Admin Pages library) */
616
- .rtb-template-tags-box {
617
- margin-top: 0.5em;
618
- padding: 1em;
619
- border-left: 4px solid #2ea2cc;
620
- background: #fff;
621
- -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
622
- box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
623
- }
624
- .rtb-template-tags-box strong {
625
- min-width: 8em;
626
- display: inline-block;
627
- }
628
-
629
- /* Addons Page */
630
- .rtb-addons {
631
- margin-top: 2em;
632
- }
633
-
634
- .rtb-addons .addon {
635
- display: inline-block;
636
- margin-bottom: 20px;
637
- padding: 20px;
638
- background: #fff;
639
- min-height: 150px;
640
- border-radius: 3px;
641
- max-width: 40em;
642
- margin-right: 20px;
643
- vertical-align: top;
644
- }
645
-
646
- .rtb-addons img {
647
- float: left;
648
- width: 150px;
649
- height: 150px;
650
- margin-right: 20px;
651
- }
652
-
653
- .rtb-addons .action {
654
- margin-top: 2em;
655
- }
656
-
657
- .rtb-addons .action .button {
658
- margin-right: 0.5em;
659
- }
660
-
661
- .rtb-addons .soon,
662
- .rtb-addons .installed {
663
- line-height: 28px;
664
- display: inline-block;
665
- padding: 0 0.75em;
666
- border-radius: 3px;
667
- box-shadow: 0 1px 0 #ccc;
668
- }
669
-
670
- .rtb-addons .soon {
671
- background: #F0F05E;
672
- }
673
-
674
- .rtb-addons .installed {
675
- background: #81F05E;
676
- }
677
-
678
- .rtb-addons .rtb-by {
679
- display: inline-block;
680
- font-style: italic;
681
- line-height: 28px;
682
- color: #777;
683
- }
684
-
685
- .rtb-addons .rtb-by a {
686
- margin-left: 0.25em;
687
- font-style: normal;
688
- }
689
-
690
- @media screen and (max-width: 600px) {
691
-
692
- .rtb-addons .addon {
693
- text-align: center;
694
- }
695
-
696
- .rtb-addons img {
697
- float: none;
698
- margin: 0;
699
- }
700
- }
701
-
702
-
703
- /* License page */
704
- .rtb-license-setting .status {
705
- display: inline-block;
706
- padding: 4px;
707
- color: #fff;
708
- }
709
-
710
- .rtb-license-setting .status.valid {
711
- background: #069106;
712
- }
713
-
714
- .rtb-license-setting .status.inactive {
715
- background: #BE0A0A;
716
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 Admin List Table */
14
+ #rtb-bookings-table .rtb-primary-controls {
15
+ margin-top: 2em;
16
+ }
17
+
18
+ #rtb-bookings-table .subsubsub {
19
+ float: none;
20
+ margin: 0.5em 0 1em;
21
+ text-align: left;
22
+ }
23
+
24
+ #rtb-bookings-table .subsubsub .trash a {
25
+ color: #a00;
26
+ }
27
+
28
+ #rtb-bookings-table .subsubsub .trash a:hover {
29
+ color: red;
30
+ }
31
+
32
+ #rtb-filters {
33
+ position: relative;
34
+ }
35
+
36
+ #rtb-filters .date-filters {
37
+ position: absolute;
38
+ top: -9999px;
39
+ left: -9999px;
40
+ display: inline-block;
41
+ padding: 1em;
42
+ background: #fff;
43
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
44
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
45
+ }
46
+
47
+ #rtb-filters.date-filters-visible .date-filters {
48
+ position: relative;
49
+ top: auto;
50
+ left: 0;
51
+ }
52
+
53
+ #rtb-filters .date-filters .datepicker {
54
+ max-width: 10em;
55
+ }
56
+
57
+ #rtb-filters .date-filter-range {
58
+ padding: 0.25em;
59
+ }
60
+
61
+ #rtb-date-filter-link {
62
+ position: relative;
63
+ }
64
+
65
+ #rtb-date-filter-link .dashicons {
66
+ line-height: 1.5;
67
+ }
68
+
69
+ #rtb-filters .date-filter-range + #rtb-date-filter-link {
70
+ margin-left: 0.5em;
71
+ }
72
+
73
+ #rtb-date-filter-link .rtb-date-filter-label {
74
+ position: absolute;
75
+ top: -9999px;
76
+ left: -9999px;
77
+ }
78
+
79
+ #rtb-filters.date-filters-visible #rtb-date-filter-link {
80
+ color: #777;
81
+ }
82
+
83
+ #rtb-filters.date-filters-visible #rtb-date-filter-link:before {
84
+ content: '';
85
+ position: absolute;
86
+ top: 60%;
87
+ left: 50%;
88
+ margin-left: -1em;
89
+ width: 0;
90
+ height: 0;
91
+ border: 1em solid transparent;
92
+ border-bottom: 1em solid #fff;
93
+ }
94
+
95
+ #rtb-filters .current {
96
+ font-weight: 600;
97
+ color: #000;
98
+ }
99
+
100
+ #rtb-bookings-table .tablenav .actions .button {
101
+ margin-top: 1px;
102
+ margin-bottom: 1px;
103
+ }
104
+
105
+ #rtb-bookings-table .tablenav .actions .button .dashicons {
106
+ line-height: 28px;
107
+ }
108
+
109
+ #rtb-bookings-table .rtb-notice,
110
+ #rtb-bookings-table .rtb-top-actions-wrapper,
111
+ #rtb-bookings-table .rtb-table-header-controls {
112
+ margin: 1em 0;
113
+ }
114
+
115
+ #rtb-bookings-table .rtb-table-header-controls {
116
+ margin-bottom: 0;
117
+ }
118
+
119
+ #rtb-bookings-table .rtb-notice {
120
+ padding: 1em;
121
+ background: #2ea2cc;
122
+ color: #fff;
123
+ }
124
+
125
+ #rtb-bookings-table .rtb-table-header-controls {
126
+ position: relative;
127
+ top: 1px;
128
+ overflow: hidden;
129
+ margin-bottom: 0.5em;
130
+ }
131
+
132
+ #rtb-bookings-table select[name="action"],
133
+ #rtb-bookings-table select[name="action2"],
134
+ #rtb-bookings-table .rtb-location-switch select {
135
+ max-width: 120px;
136
+ }
137
+
138
+ #rtb-bookings-table .rtb-table-header-controls .bulkactions {
139
+ float: left;
140
+ }
141
+
142
+ #rtb-bookings-table .rtb-locations {
143
+ display: none;
144
+ margin: 0;
145
+ width: 9999px;
146
+ }
147
+
148
+ #rtb-bookings-table .rtb-locations li {
149
+ display: inline-block;
150
+ margin: 0;
151
+ line-height: 38px;
152
+ position: relative;
153
+ }
154
+
155
+ #rtb-bookings-table .rtb-locations a {
156
+ display: block;
157
+ padding: 0 1em;
158
+ font-weight: 700;
159
+ color: #777;
160
+ text-decoration: none;
161
+ }
162
+
163
+ #rtb-bookings-table .rtb-locations .current a {
164
+ background: #fff;
165
+ color: #333;
166
+ border: 1px solid #ddd;
167
+ border-bottom: 0;
168
+ }
169
+
170
+ #rtb-bookings-table .rtb-location-switch {
171
+ float: left;
172
+ }
173
+
174
+ #rtb-bookings-table .rtb-locations-button {
175
+ margin-bottom: 0;
176
+ }
177
+
178
+ #rtb-bookings-table tr.closed {
179
+ opacity: 0.6;
180
+ filter: opacity(alpha=60);
181
+ }
182
+ #rtb-bookings-table tr.closed:hover {
183
+ opacity: 1;
184
+ filter: opacity(alpha=100);
185
+ }
186
+
187
+ #rtb-bookings-table tr.pending .check-column {
188
+ border-left: 4px solid #dd3d36;
189
+ }
190
+
191
+ #rtb-bookings-table .striped>tbody>tr.pending:nth-of-type(odd) {
192
+ background-color: rgba(255,0,0,0.35);
193
+ }
194
+ #rtb-bookings-table .striped>tbody>tr.pending:nth-of-type(even) {
195
+ background-color: rgba(255,0,0,0.25);
196
+ }
197
+
198
+ #rtb-bookings-table tr.pending .check-column input[type=checkbox] {
199
+ margin-left: 4px;
200
+ }
201
+
202
+ #rtb-bookings-table .striped>tbody>tr.confirmed:nth-of-type(odd) {
203
+ background-color: rgba(46,162,204,0.35);
204
+ }
205
+ #rtb-bookings-table .striped>tbody>tr.confirmed:nth-of-type(even) {
206
+ background-color: rgba(46,162,204,0.25);
207
+ }
208
+
209
+ #rtb-bookings-table th#date {
210
+ width: auto;
211
+ }
212
+
213
+ #rtb-bookings-table th#party {
214
+ width: 3em;
215
+ }
216
+
217
+ #rtb-bookings-table th#details {
218
+ width: 4em;
219
+ }
220
+
221
+ #rtb-bookings-table td .actions {
222
+ line-height: 1.5em;
223
+ opacity: 0;
224
+ -webkit-transition: opacity 0.3s 0;
225
+ -moz-transition: opacity 0.3s 0;
226
+ transition: opacity 0.3s 0;
227
+ }
228
+
229
+ #rtb-bookings-table tr:hover td .actions {
230
+ opacity: 1;
231
+ }
232
+
233
+ #rtb-bookings-table .column-date .actions .trash,
234
+ #rtb-bookings-table .actions [data-action="delete"] {
235
+ color: #a00;
236
+ }
237
+
238
+ #rtb-bookings-table .column-date .actions .trash:hover,
239
+ #rtb-bookings-table .actions [data-action="delete"]:hover {
240
+ color: red;
241
+ }
242
+
243
+ #rtb-bookings-table .column-date .status {
244
+ width: 0;
245
+ height: 0;
246
+ overflow: hidden;
247
+ line-height: 28px;
248
+ opacity: 0;
249
+ -webkit-transition: opacity 0.6s 0;
250
+ -moz-transition: opacity 0.6s 0;
251
+ transition: opacity 0.6s 0;
252
+ }
253
+
254
+ #rtb-bookings-table .column-date .status .spinner {
255
+ visibility: visible;
256
+ display: inline-block;
257
+ float: left;
258
+ margin: 4px 4px 0 0;
259
+ vertical-align: middle;
260
+ }
261
+
262
+ #rtb-bookings-table .column-date.loading .actions {
263
+ display: none;
264
+ }
265
+
266
+ #rtb-bookings-table .column-date.loading .status {
267
+ width: auto;
268
+ height: auto;
269
+ overflow: visible;
270
+ opacity: 0.5;
271
+ }
272
+
273
+ #rtb-bookings-table tr ul {
274
+ margin: 0;
275
+ }
276
+
277
+ #rtb-bookings-table .consent {
278
+ margin-top: 0.5em;
279
+ }
280
+
281
+ .rtb-details-data {
282
+ display: none;
283
+ }
284
+
285
+ .rtb-details-data .details {
286
+ margin: 0;
287
+ }
288
+
289
+ .rtb-details-data .details > li {
290
+ margin-top: 2em;
291
+ }
292
+
293
+ .rtb-details-data .details > li:first-child {
294
+ margin-top: 0;
295
+ }
296
+
297
+ .rtb-details-data .details .label {
298
+ font-weight: 900;
299
+ }
300
+
301
+ #rtb-details-modal .rtb-details-data {
302
+ display: block;
303
+ }
304
+
305
+ @media screen and (min-width: 783px) {
306
+
307
+ #rtb-bookings-table .rtb-locations li {
308
+ line-height: 32px;
309
+ }
310
+ }
311
+
312
+ @media screen and (min-width: 930px) {
313
+
314
+ #rtb-bookings-table .rtb-primary-controls {
315
+ margin-top: 0;
316
+ }
317
+
318
+ #rtb-bookings-table .rtb-views {
319
+ float: right;
320
+ width: 50%;
321
+ }
322
+
323
+ #rtb-bookings-table .rtb-views .subsubsub {
324
+ text-align: right;
325
+ }
326
+
327
+ #rtb-filters {
328
+ float: left;
329
+ width: 50%;
330
+ }
331
+
332
+ #rtb-filters .date-filters {
333
+ margin-right: 2em;
334
+ }
335
+
336
+ #rtb-bookings-table .rtb-locations {
337
+ display: block;
338
+ }
339
+
340
+ #rtb-bookings-table .rtb-table-header-controls {
341
+ margin-bottom: 0;
342
+ }
343
+
344
+ #rtb-bookings-table .rtb-location-switch {
345
+ position: absolute;
346
+ top: 0;
347
+ right: 0;
348
+ background: #eee;
349
+ padding-left: 1em;
350
+ }
351
+ }
352
+
353
+ @media screen and (max-width: 782px) {
354
+
355
+ /* Prevent date column from being hidden in WP versions < 4.3 */
356
+ #rtb-bookings-table .fixed .column-date {
357
+ display: table-cell;
358
+ }
359
+
360
+ /* Always display details data in mobile views */
361
+ #rtb-bookings-table .column-details .rtb-details-data {
362
+ display: block;
363
+ }
364
+
365
+ #rtb-bookings-table .column-details .rtb-show-details {
366
+ display: none;
367
+ }
368
+ }
369
+
370
+ /* Add/edit bookings modal */
371
+ .rtb-admin-modal {
372
+ position: fixed;
373
+ top: 0;
374
+ left: 0;
375
+ width: 100%;
376
+ height: 100%;
377
+ background: rgba(0, 0, 0, 0.8);
378
+ z-index: 9999;
379
+ overflow-y: auto;
380
+ cursor: pointer;
381
+ visibility: hidden;
382
+ opacity: 0;
383
+ -webkit-transition: opacity 0.3s 0, visibility 0 0.3s;
384
+ -moz-transition: opacity 0.3s 0, visibility 0 0.3s;
385
+ transition: opacity 0.3s 0, visibility 0 0.3s;
386
+ }
387
+
388
+ .rtb-admin-modal.is-visible {
389
+ visibility: visible;
390
+ opacity: 1;
391
+ -webkit-transition: opacity 0.3s 0, visibility 0 0;
392
+ -moz-transition: opacity 0.3s 0, visibility 0 0;
393
+ transition: opacity 0.3s 0, visibility 0 0;
394
+ }
395
+
396
+ .rtb-admin-modal.is-visible .rtb-container {
397
+ -webkit-transform: translateY(0);
398
+ -moz-transform: translateY(0);
399
+ -ms-transform: translateY(0);
400
+ -o-transform: translateY(0);
401
+ transform: translateY(0);
402
+ }
403
+
404
+ .rtb-admin-modal .rtb-container {
405
+ position: relative;
406
+ width: 90%;
407
+ max-width: 20em;
408
+ padding: 2em;
409
+ background: #FFF;
410
+ margin: 3em auto 4em;
411
+ cursor: auto;
412
+ border-radius: 0.25em;
413
+ -webkit-transform: translateY(-30px);
414
+ -moz-transform: translateY(-30px);
415
+ -ms-transform: translateY(-30px);
416
+ -o-transform: translateY(-30px);
417
+ transform: translateY(-30px);
418
+ -webkit-transition-property: -webkit-transform;
419
+ -moz-transition-property: -moz-transform;
420
+ transition-property: transform;
421
+ -webkit-transition-duration: 0.3s;
422
+ -moz-transition-duration: 0.3s;
423
+ transition-duration: 0.3s;
424
+ }
425
+
426
+ .rtb-admin-modal fieldset {
427
+ padding: 0;
428
+ }
429
+
430
+ .rtb-admin-modal fieldset > div {
431
+ margin-top: 1em;
432
+ }
433
+
434
+ .rtb-admin-modal legend {
435
+ font-size: 1.5em;
436
+ margin: 0 0 0.83em;
437
+ font-weight: 400;
438
+ padding: 0;
439
+ }
440
+
441
+ .rtb-admin-modal label {
442
+ color: #777;
443
+ font-style: italic;
444
+ display: block;
445
+ }
446
+
447
+ .rtb-admin-modal .button {
448
+ margin-top: 1em;
449
+ margin-right: 0.5em;
450
+ }
451
+
452
+ .rtb-admin-modal button,
453
+ .rtb-admin-modal .button {
454
+ opacity: 1;
455
+ transition: opacity .25s ease-in-out;
456
+ -moz-transition: opacity .25s ease-in-out;
457
+ -webkit-transition: opacity .25s ease-in-out;
458
+ }
459
+
460
+ .rtb-admin-modal button:disabled,
461
+ .rtb-admin-modal .button:disabled {
462
+ opacity: 0.5;
463
+ transition: opacity .25s ease-in-out;
464
+ -moz-transition: opacity .25s ease-in-out;
465
+ -webkit-transition: opacity .25s ease-in-out;
466
+ }
467
+
468
+ .rtb-admin-modal .button-link {
469
+ display: inline-block;
470
+ margin-top: 1em;
471
+ line-height: 26px;
472
+ }
473
+
474
+ .rtb-admin-modal .action-status {
475
+ display: inline-block;
476
+ float: right;
477
+ margin-top: 1em;
478
+ opacity: 0;
479
+ transition: opacity .25s ease-in-out;
480
+ -moz-transition: opacity .25s ease-in-out;
481
+ -webkit-transition: opacity .25s ease-in-out;
482
+ }
483
+
484
+ .rtb-admin-modal .action-status.is-visible {
485
+ opacity: 1;
486
+ }
487
+
488
+ .rtb-admin-modal .action-status > span {
489
+ display: none;
490
+ background-position: 4px;
491
+ margin: 0;
492
+ height: 28px;
493
+ width: 28px;
494
+ line-height: 28px;
495
+ font-size: 28px;
496
+ }
497
+
498
+ .rtb-admin-modal .action-status > .spinner {
499
+ visibility: visible;
500
+ display: block;
501
+ }
502
+
503
+ .rtb-admin-modal .action-status > .success {
504
+ color: #7ad03a;
505
+ }
506
+
507
+ .rtb-admin-modal .action-status > .error {
508
+ color: #dd3d36;
509
+ }
510
+
511
+ #rtb-booking-form .rtb-error {
512
+ background: #dd3d36;
513
+ }
514
+
515
+ #rtb-booking-form .rtb-error a {
516
+ color: #fff;
517
+ }
518
+
519
+ .rtb-admin-modal input[type="text"],
520
+ .rtb-admin-modal input[type="email"],
521
+ .rtb-admin-modal input[type="tel"],
522
+ .rtb-admin-modal textarea {
523
+ max-width: 100%;
524
+ width: 100%;
525
+ }
526
+
527
+ #rtb-email-modal .rtb-email-to {
528
+ font-weight: 700;
529
+ color: #777;
530
+ }
531
+
532
+ #rtb-email-modal textarea {
533
+ min-height: 12em;
534
+ }
535
+
536
+ #rtb-delete-modal #rtb-delete-status {
537
+ display: none;
538
+ margin-top: 2em;
539
+ margin-bottom: 1em;
540
+ }
541
+
542
+ #rtb-delete-modal #rtb-delete-status.is-visible {
543
+ display: block;
544
+ }
545
+
546
+ #rtb-delete-modal .rtb-delete-status-total {
547
+ position: relative;
548
+ display: block;
549
+ width: 100%;
550
+ height: 16px;
551
+ border: 1px solid #0085ba;
552
+ }
553
+
554
+ #rtb-delete-modal .rtb-delete-status-progress {
555
+ position: absolute;
556
+ display: block;
557
+ width: 0;
558
+ height: 100%;
559
+ background: #0085ba;
560
+ transition: width 0.2s;
561
+ }
562
+
563
+ #rtb-delete-modal #rtb-delete-status-deleted {
564
+ margin-top: 0.5em;
565
+ text-align: right;
566
+ }
567
+
568
+ #rtb-delete-modal #rtb-cancel-delete-modal {
569
+ padding-left: 1em;
570
+ padding-right: 1em;
571
+ }
572
+
573
+ .rtb-description {
574
+ margin: 0.5em 0;
575
+ color: #777;
576
+ max-height: 0;
577
+ overflow: hidden;
578
+ -webkit-transition: max-height 0.5s 0;
579
+ -moz-transition: max-height 0.5s 0;
580
+ transition: max-height 0.5s 0;
581
+ }
582
+
583
+ .rtb-description.is-visible {
584
+ max-height: 20em;
585
+ }
586
+
587
+ .rtb-column-form ul {
588
+ margin: 0;
589
+ }
590
+
591
+ .rtb-column-form label {
592
+ font-style: normal;
593
+ padding: 2px 0;
594
+ }
595
+
596
+ .rtb-column-form fieldset {
597
+ margin-bottom: 2em;
598
+ }
599
+
600
+ .rtb-column-form .action-status {
601
+ margin-top: 0;
602
+ }
603
+
604
+ #rtb-error-modal .rtb-error-msg {
605
+ margin-bottom: 1em;
606
+ }
607
+
608
+ .rtb-ban-form .intro {
609
+ margin-top: 0;
610
+ font-weight: bold;
611
+ }
612
+
613
+ .rtb-ban-form .intro span {
614
+ color: #a55;
615
+ }
616
+
617
+ .rtb-ban-form .button-primary {
618
+ display: block;
619
+ width: 100%;
620
+ margin-top: 2em;
621
+ margin-bottom: 2em;
622
+ }
623
+
624
+ /* Hide the outer scrollbar when the modal is open */
625
+ .rtb-hide-body-scroll {
626
+ overflow: hidden !important;
627
+ }
628
+
629
+ /* Settings Pages (most of this is handled by the Simple Admin Pages library) */
630
+ .rtb-template-tags-box {
631
+ margin-top: 0.5em;
632
+ padding: 1em;
633
+ border-left: 4px solid #2ea2cc;
634
+ background: #fff;
635
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
636
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
637
+ }
638
+ .rtb-template-tags-box strong {
639
+ min-width: 8em;
640
+ display: inline-block;
641
+ }
642
+
643
+ /* Addons Page */
644
+ .rtb-addons {
645
+ margin-top: 2em;
646
+ }
647
+
648
+ .rtb-addons .addon {
649
+ display: inline-block;
650
+ margin-bottom: 20px;
651
+ padding: 20px;
652
+ background: #fff;
653
+ min-height: 150px;
654
+ border-radius: 3px;
655
+ max-width: 40em;
656
+ margin-right: 20px;
657
+ vertical-align: top;
658
+ }
659
+
660
+ .rtb-addons img {
661
+ float: left;
662
+ width: 150px;
663
+ height: 150px;
664
+ margin-right: 20px;
665
+ }
666
+
667
+ .rtb-addons .action {
668
+ margin-top: 2em;
669
+ }
670
+
671
+ .rtb-addons .action .button {
672
+ margin-right: 0.5em;
673
+ }
674
+
675
+ .rtb-addons .soon,
676
+ .rtb-addons .installed {
677
+ line-height: 28px;
678
+ display: inline-block;
679
+ padding: 0 0.75em;
680
+ border-radius: 3px;
681
+ box-shadow: 0 1px 0 #ccc;
682
+ }
683
+
684
+ .rtb-addons .soon {
685
+ background: #F0F05E;
686
+ }
687
+
688
+ .rtb-addons .installed {
689
+ background: #81F05E;
690
+ }
691
+
692
+ .rtb-addons .rtb-by {
693
+ display: inline-block;
694
+ font-style: italic;
695
+ line-height: 28px;
696
+ color: #777;
697
+ }
698
+
699
+ .rtb-addons .rtb-by a {
700
+ margin-left: 0.25em;
701
+ font-style: normal;
702
+ }
703
+
704
+ @media screen and (max-width: 600px) {
705
+
706
+ .rtb-addons .addon {
707
+ text-align: center;
708
+ }
709
+
710
+ .rtb-addons img {
711
+ float: none;
712
+ margin: 0;
713
+ }
714
+ }
715
+
716
+
717
+ /* License page */
718
+ .rtb-license-setting .status {
719
+ display: inline-block;
720
+ padding: 4px;
721
+ color: #fff;
722
+ }
723
+
724
+ .rtb-license-setting .status.valid {
725
+ background: #069106;
726
+ }
727
+
728
+ .rtb-license-setting .status.inactive {
729
+ background: #BE0A0A;
730
+ }
731
+
732
+
733
+
734
+
735
+ /*** UPGRADE BANNER ***/
736
+ .rtb-temp-upgrade-banner {
737
+ position: relative;
738
+ float: left;
739
+ clear: both;
740
+ margin-left: -20px;
741
+ width: calc(100% + 20px);
742
+ padding-top: 22px;
743
+ height: 42px;
744
+ text-transform: uppercase;
745
+ text-align: center;
746
+ text-decoration: none;
747
+ color: #fff;
748
+ background: #365388;
749
+ }
750
+ .rtb-temp-upgrade-banner:hover {
751
+ color: #eee;
752
+ }
753
+
754
+
755
+
756
+ /*
757
+ ==============================================
758
+ NEW DASHBOARD
759
+ ==============================================
760
+ */
761
+
762
+
763
+ /*** WRAP ***/
764
+
765
+ .bookings_page_rtb-dashboard #wpcontent {
766
+ padding-left: 0;
767
+ }
768
+ .bookings_page_rtb-dashboard .wrap {
769
+ margin: 10px 0 0;
770
+ }
771
+
772
+ .rtb-import-export-container {
773
+ position: relative;
774
+ float: left;
775
+ margin-left: 32px;
776
+ width: calc(100% - 32px);
777
+ }
778
+
779
+
780
+ /*** BANNER ***/
781
+
782
+ .rtb-dashboard-new-upgrade-banner {
783
+ position: relative;
784
+ float: left;
785
+ width: 100%;
786
+ height: 256px;
787
+ background: url(../img/rtb-dashboard-banner.png) center no-repeat #1b0f49;
788
+ }
789
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-icon {
790
+ position: absolute;
791
+ height: 112px;
792
+ width: 112px;
793
+ left: 172px;
794
+ top: 72px;
795
+ background: url(../img/rtb-icon.png) no-repeat;
796
+ background-size: 112px 112px;
797
+ }
798
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-buttons {
799
+ position: absolute;
800
+ height: 112px;
801
+ width: 192px;
802
+ right: 128px;
803
+ top: 84px;
804
+ }
805
+ .rtb-dashboard-new-upgrade-button {
806
+ position: relative;
807
+ float: right;
808
+ width: 188px;
809
+ border: 2px solid #7CA3BF;
810
+ background-color: #7CA3BF;
811
+ color: #fff;
812
+ padding: 6px 0;
813
+ font-size: 12px;
814
+ text-decoration: none;
815
+ text-align: center;
816
+ margin-bottom: 20px;
817
+ font-weight: bold;
818
+ border-radius: 2px;
819
+ }
820
+ .rtb-dashboard-new-upgrade-button:hover {
821
+ background-color: #91B5CE;
822
+ border-color: #91B5CE;
823
+ color: #fff;
824
+ }
825
+ .rtb-dashboard-new-upgrade-button.rtb-dashboard-new-trial-button {
826
+ background-color: transparent;
827
+ color: #7CA3BF;
828
+ font-size: 11px;
829
+ cursor: pointer;
830
+ width: 192px;
831
+ }
832
+ .rtb-dashboard-new-upgrade-button.rtb-dashboard-new-trial-button:hover {
833
+ background-color: #7CA3BF;
834
+ border-color: #7CA3BF;
835
+ color: #fff;
836
+ }
837
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-text {
838
+ position: absolute;
839
+ width: calc(100% - 680px);
840
+ height: 112px;
841
+ top: 76px;
842
+ left: 320px;
843
+ color: #fff;
844
+ }
845
+ .rtb-dashboard-banner-title {
846
+ position: relative;
847
+ float: left;
848
+ width: 100%;
849
+ font-size: 29px;
850
+ line-height: 32px;
851
+ font-weight: bold;
852
+ }
853
+ .rtb-dashboard-banner-brief {
854
+ position: relative;
855
+ float: left;
856
+ width: 100%;
857
+ margin-top: 14px;
858
+ font-size: 14px;
859
+ }
860
+
861
+ @media screen and (min-width: 1700px) {
862
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-icon {
863
+ left: 272px;
864
+ }
865
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-buttons {
866
+ right: 228px;
867
+ }
868
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-text {
869
+ width: calc(100% - 880px);
870
+ left: 420px;
871
+ }
872
+ }
873
+ @media screen and (max-width: 1200px) {
874
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-icon {
875
+ left: 54px;
876
+ }
877
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-buttons {
878
+ right: 32px;
879
+ }
880
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-text {
881
+ width: calc(100% - 466px);
882
+ left: 202px;
883
+ }
884
+ }
885
+ @media screen and (max-width: 800px) {
886
+ .rtb-dashboard-new-upgrade-banner {
887
+ height: 512px;
888
+ height: 300px;
889
+ }
890
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-icon {
891
+ left: calc(50% - 56px);
892
+ top: 48px;
893
+ display: none;
894
+ }
895
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-text {
896
+ width: 80%;
897
+ left: 10%;
898
+ top: 208px;
899
+ height: 160px;
900
+ text-align: center;
901
+ height: 140px;
902
+ top: 42px;
903
+ }
904
+ .rtb-dashboard-banner-brief {
905
+ display: none;
906
+ }
907
+ .rtb-dashboard-new-upgrade-banner .rtb-dashboard-banner-buttons {
908
+ right: calc(50% - 96px);
909
+ top: 368px;
910
+ top: 172px;
911
+ }
912
+ }
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+ /*** MENU ***/
921
+
922
+ .rtb-admin-header-menu {
923
+ background-color: #1b335f;
924
+ margin-bottom: 16px;
925
+ position: relative;
926
+ float: left;
927
+ width: 100%;
928
+ }
929
+ body.bookings_page_rtb-settings .rtb-admin-header-menu,
930
+ body.bookings_page_cffrtb-editor .rtb-admin-header-menu,
931
+ body.toplevel_page_rtb-bookings .rtb-admin-header-menu {
932
+ margin-left: -20px;
933
+ width: calc(100% + 20px);
934
+ }
935
+ .rtb-admin-header-menu .nav-tab-wrapper, .wrap .rtb-admin-header-menu h2.nav-tab-wrapper {
936
+ border-bottom: 0 !important;
937
+ margin: 0;
938
+ padding-top: 0;
939
+ padding-bottom: 0;
940
+ line-height: inherit;
941
+ }
942
+ .rtb-admin-header-menu .nav-tab {
943
+ border: none;
944
+ margin-left: 0;
945
+ padding: 12px 48px;
946
+ font-size: 12px;
947
+ text-transform: uppercase;
948
+ background: #1b335f;
949
+ color: #fff;
950
+ border-right: 1px solid #42639F;
951
+ }
952
+
953
+ .rtb-admin-header-menu .nav-tab:hover {
954
+ background: #365388;
955
+ }
956
+ .rtb-admin-header-menu .nav-tab-active {
957
+ background: #365388;
958
+ color: #fff;
959
+ }
960
+ .rtb-admin-header-menu .nav-tab-active:hover {
961
+ background: #365388;
962
+ color: #fff;
963
+ }
964
+ .rtb-admin-header-menu .nav-tab#rtb-dash-mobile-menu-open {
965
+ display: none;
966
+ }
967
+
968
+ @media screen and (max-width: 1440px) {
969
+ .rtb-admin-header-menu .nav-tab {
970
+ padding: 12px 32px;
971
+ }
972
+ }
973
+ @media screen and (max-width: 1150px) {
974
+ .rtb-admin-header-menu .nav-tab {
975
+ padding: 12px 18px;
976
+ }
977
+ }
978
+ @media screen and (max-width: 800px) {
979
+ .rtb-admin-header-menu .nav-tab {
980
+ padding: 12px 0;
981
+ margin: 0;
982
+ width: 100%;
983
+ clear: both;
984
+ text-align: center;
985
+ border-right: none;
986
+ border-bottom: 1px solid #42639F;
987
+ }
988
+ .rtb-admin-header-menu .nav-tab:last-of-type {
989
+ border-bottom: none;
990
+ }
991
+ .rtb-admin-header-menu .nav-tab {
992
+ display: none;
993
+ }
994
+ .rtb-admin-header-menu .nav-tab#rtb-dash-mobile-menu-open {
995
+ display: block;
996
+ }
997
+ #rtb-dash-mobile-menu-up-caret {
998
+ display: none;
999
+ }
1000
+ #rtb-dash-mobile-menu-down-caret {
1001
+ display: inline;
1002
+ }
1003
+ }
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+ /*** CONTENT ***/
1014
+
1015
+ #rtb-dashboard-content-area {
1016
+ position: relative;
1017
+ float: left;
1018
+ width: calc(100% - 162px);
1019
+ margin: 32px 20px 32px 142px;
1020
+ }
1021
+ #rtb-dashboard-content-left {
1022
+ position: relative;
1023
+ float: left;
1024
+ width: 74%;
1025
+ }
1026
+ #rtb-dashboard-content-right {
1027
+ position: relative;
1028
+ float: right;
1029
+ width: 24%;
1030
+ }
1031
+
1032
+ .rtb-dashboard-new-widget-box {
1033
+ position: relative;
1034
+ float: left;
1035
+ background: #fff;
1036
+ box-shadow: -2px 2px 6px #ccc;
1037
+ margin-bottom: 16px;
1038
+ }
1039
+ .rtb-dashboard-new-widget-box.ewd-widget-box-full {
1040
+ width: 100%;
1041
+ }
1042
+ .rtb-dashboard-new-widget-box.ewd-widget-box-two-thirds {
1043
+ width: 66%;
1044
+ }
1045
+ .rtb-dashboard-new-widget-box.ewd-widget-box-one-third {
1046
+ width: 32%;
1047
+ margin-left: 2%;
1048
+ }
1049
+ .rtb-dashboard-new-widget-box-top, .rtb-dashboard-new-widget-box-bottom {
1050
+ position: relative;
1051
+ float: left;
1052
+ width: calc(100% - 32px);
1053
+ padding: 8px 16px;
1054
+ color: #777;
1055
+ }
1056
+ .rtb-dashboard-new-widget-box-top {
1057
+ padding: 12px 16px;
1058
+ font-weight: bold;
1059
+ color: #444;
1060
+ }
1061
+ .rtb-dashboard-new-widget-box-bottom {
1062
+ border-top: 1px solid #e2e2e2;
1063
+ }
1064
+
1065
+ .rtb-dashboard-key-widget {
1066
+ position: relative;
1067
+ float: left;
1068
+ width: calc(100% - 144px);
1069
+ min-height: 30px;
1070
+ margin: 24px 24px 8px;
1071
+ padding: 0 0 0 96px;
1072
+ background-image: url(../img/dash-asset-key.png);
1073
+ background-position: left top;
1074
+ background-size: 64px 30px;
1075
+ background-repeat: no-repeat;
1076
+ }
1077
+ .rtb-dashboard-key-widget-input {
1078
+ position: relative;
1079
+ float: left;
1080
+ width: calc(65% - 2px);
1081
+ height: 30px;
1082
+ padding: 4px 8px !important;
1083
+ background: none;
1084
+ border: 1px solid #e2e2e2 !important;
1085
+ margin: 0 !important;
1086
+ }
1087
+ .rtb-dashboard-key-widget-input::placeholder {
1088
+ color: #bbb;
1089
+ }
1090
+ .rtb-dashboard-key-widget-submit {
1091
+ position: relative;
1092
+ float: left;
1093
+ width: 35%;
1094
+ height: 30px;
1095
+ font-size: 14px;
1096
+ background: #f2b52f;
1097
+ color: #fff;
1098
+ border: none;
1099
+ cursor: pointer;
1100
+ margin: 0 !important;
1101
+ }
1102
+ .rtb-dashboard-key-widget-submit:hover {
1103
+ background: #F2BD49;
1104
+ }
1105
+ .rtb-dashboard-key-widget-text {
1106
+ position: relative;
1107
+ float: left;
1108
+ width: 100%;
1109
+ margin-top: 7px;
1110
+ font-size: 11px;
1111
+ color: #888;
1112
+ font-style: italic;
1113
+ font-weight: normal;
1114
+ }
1115
+ .rtb-dashboard-key-widget-text a {
1116
+ color: #7CA3BF;
1117
+ text-decoration: none;
1118
+ font-weight: bold;
1119
+ }
1120
+ .rtb-dashboard-key-widget-text a:hover {
1121
+ color: #91B5CE;
1122
+ text-decoration: none;
1123
+ }
1124
+
1125
+ #rtb-dashboard-support-widget-box .rtb-dashboard-new-widget-box-top {
1126
+ cursor: pointer;
1127
+ }
1128
+ #rtb-dash-mobile-support-down-caret {
1129
+ display: none;
1130
+ float: right;
1131
+ }
1132
+ #rtb-dash-mobile-support-up-caret {
1133
+ display: inline;
1134
+ float: right;
1135
+ }
1136
+ .rtb-dashboard-support-widgets {
1137
+ position: relative;
1138
+ float: left;
1139
+ width: 90%;
1140
+ padding: 14px 5%;
1141
+ }
1142
+ .rtb-dashboard-support-widgets li {
1143
+ position: relative;
1144
+ float: left;
1145
+ width: 18.25%;
1146
+ margin-right: 9%;
1147
+ }
1148
+ .rtb-dashboard-support-widgets li:last-of-type {
1149
+ margin-right: 0;
1150
+ }
1151
+ .rtb-dashboard-support-widgets li a {
1152
+ position: relative;
1153
+ float: left;
1154
+ width: 100%;
1155
+ text-align: center;
1156
+ color: #444;
1157
+ text-decoration: none;
1158
+ font-weight: bold;
1159
+ }
1160
+ .rtb-dashboard-support-widgets li a:hover {
1161
+ color: #1b335f;
1162
+ }
1163
+ .rtb-dashboard-support-widgets li img {
1164
+ position: relative;
1165
+ float: left;
1166
+ width: 80%;
1167
+ height: auto;
1168
+ border: none;
1169
+ padding: 0 10% 12px;
1170
+ }
1171
+ .rtb-dashboard-support-widgets li .rtb-dashboard-support-widgets-text {
1172
+ position: relative;
1173
+ float: left;
1174
+ width: 100%;
1175
+ margin-top: 2px;
1176
+ }
1177
+
1178
+ #rtb-dashboard-optional-table .rtb-dashboard-new-widget-box-top {
1179
+ cursor: pointer;
1180
+ }
1181
+ #rtb-dash-optional-table-down-caret {
1182
+ display: none;
1183
+ float: right;
1184
+ }
1185
+ #rtb-dash-optional-table-up-caret {
1186
+ display: inline;
1187
+ float: right;
1188
+ }
1189
+
1190
+ .rtb-dashboard-testimonials {
1191
+ position: relative;
1192
+ float: left;
1193
+ width: 100%;
1194
+ }
1195
+ .rtb-dashboard-testimonials li {
1196
+ position: relative;
1197
+ float: left;
1198
+ width: 100%;
1199
+ text-align: center;
1200
+ }
1201
+ .rtb-dashboard-testimonials li img {
1202
+ position: relative;
1203
+ float: left;
1204
+ width: 140px;
1205
+ height: auto;
1206
+ margin-top: 8px;
1207
+ margin-left: calc(50% - 70px);
1208
+ }
1209
+ .rtb-dashboard-testimonials li .rtb-dashboard-testimonial-title {
1210
+ position: relative;
1211
+ float: left;
1212
+ width: 100%;
1213
+ margin: 28px 0 20px;
1214
+ font-size: 30px;
1215
+ line-height: 30px;
1216
+ font-weight: bold;
1217
+ }
1218
+ .rtb-dashboard-testimonials li .rtb-dashboard-testimonial-author {
1219
+ position: relative;
1220
+ float: left;
1221
+ width: 100%;
1222
+ font-size: 16px;
1223
+ }
1224
+ .rtb-dashboard-testimonials li .rtb-dashboard-testimonial-text {
1225
+ position: relative;
1226
+ float: left;
1227
+ width: 80%;
1228
+ margin: 24px 10% 0;
1229
+ font-size: 12px;
1230
+ }
1231
+ .rtb-dashboard-testimonials li .rtb-dashboard-testimonial-text a {
1232
+ color: #7CA3BF;
1233
+ text-decoration: none;
1234
+ font-weight: bold;
1235
+ }
1236
+ .rtb-dashboard-testimonials li .rtb-dashboard-testimonial-text a:hover {
1237
+ color: #91B5CE;
1238
+ }
1239
+
1240
+ .rtb-dashboard-review-ask {
1241
+ position: relative;
1242
+ float: left;
1243
+ width: calc(100% - 32px);
1244
+ padding: 16px 16px 12px;
1245
+ text-align: center;
1246
+ }
1247
+ .rtb-dashboard-review-ask img {
1248
+ position: relative;
1249
+ float: left;
1250
+ width: 110px;
1251
+ height: auto;
1252
+ margin-left: calc(50% - 55px);
1253
+ }
1254
+ .rtb-dashboard-review-ask-text {
1255
+ position: relative;
1256
+ float: left;
1257
+ width: 100%;
1258
+ margin: 24px 0;
1259
+ }
1260
+ .rtb-dashboard-review-ask-button {
1261
+ clear: both;
1262
+ position: relative;
1263
+ float: left;
1264
+ width: calc(100% - 2px);
1265
+ border: 1px solid #888;
1266
+ background-color: transparent;
1267
+ color: #888;
1268
+ padding: 6px 0;
1269
+ font-size: 12px;
1270
+ text-decoration: none;
1271
+ text-align: center;
1272
+ font-weight: bold;
1273
+ border-radius: 2px;
1274
+ }
1275
+ .rtb-dashboard-review-ask-button:hover {
1276
+ background-color: #888;
1277
+ border-color: #888;
1278
+ color: #fff;
1279
+ }
1280
+ .rtb-dashboard-review-ask-dismiss {
1281
+ position: relative;
1282
+ float: left;
1283
+ background: transparent;
1284
+ border: none;
1285
+ margin: 16px 0 0 0;
1286
+ padding: 0;
1287
+ width: 100%;
1288
+ text-align: center;
1289
+ color: #999;
1290
+ font-size: 11px;
1291
+ text-transform: uppercase;
1292
+ cursor: pointer;
1293
+ }
1294
+ .rtb-dashboard-review-ask-dismiss:hover {
1295
+ color: #555;
1296
+ }
1297
+
1298
+ .rtb-dashboard-guarantee {
1299
+ position: relative;
1300
+ float: left;
1301
+ width: calc(100% - 208px);
1302
+ min-height: 127px;
1303
+ margin: 20px 24px;
1304
+ padding: 0 0 0 160px;
1305
+ background-image: url(../img/dash-asset-badge.png);
1306
+ background-position: left top;
1307
+ background-size: 128px 127px;
1308
+ background-repeat: no-repeat;
1309
+ color: #777;
1310
+ }
1311
+ .rtb-dashboard-guarantee-title, .rtb-dashboard-guarantee-text {
1312
+ position: relative;
1313
+ float: left;
1314
+ width: 100%;
1315
+ margin-top: 16px;
1316
+ }
1317
+ .rtb-dashboard-guarantee-title {
1318
+ font-size: 24px;
1319
+ line-height: 24px;
1320
+ }
1321
+ .rtb-dashboard-guarantee-text {
1322
+ font-size: 12px;
1323
+ font-weight: normal;
1324
+ }
1325
+
1326
+ .rtb-dashboard-get-premium-widget-trial-time {
1327
+ position: relative;
1328
+ float: left;
1329
+ width: 100%;
1330
+ margin-top: 6px;
1331
+ background: #1b335f;
1332
+ }
1333
+ .rtb-dashboard-get-premium-widget-trial-days, .rtb-dashboard-get-premium-widget-trial-hours {
1334
+ position: relative;
1335
+ float: left;
1336
+ text-align: center;
1337
+ color: #fff;
1338
+ font-size: 43px;
1339
+ line-height: 35px;
1340
+ padding: 24px 0 8px;
1341
+ font-weight: bold;
1342
+ }
1343
+ .rtb-dashboard-get-premium-widget-trial-days span, .rtb-dashboard-get-premium-widget-trial-hours span {
1344
+ position: relative;
1345
+ float: left;
1346
+ width: 100%;
1347
+ font-size: 14px;
1348
+ font-weight: normal;
1349
+ }
1350
+ .rtb-dashboard-get-premium-widget-trial-days {
1351
+ width: calc(50% - 7px);
1352
+ border-right: 7px solid #fff;
1353
+ }
1354
+ .rtb-dashboard-get-premium-widget-trial-hours {
1355
+ width: 50%;
1356
+ }
1357
+ .rtb-dashboard-get-premium-widget-trial-time-left {
1358
+ position: relative;
1359
+ float: left;
1360
+ width: 100%;
1361
+ margin: 28px 0 24px;
1362
+ color: #1b335f;
1363
+ font-size: 24px;
1364
+ text-align: center;
1365
+ font-weight: bold;
1366
+ }
1367
+ .rtb-dashboard-get-premium-widget-features-title {
1368
+ position: relative;
1369
+ float: left;
1370
+ width: calc(100% - 16px);
1371
+ padding: 8px 8px 10px;
1372
+ color: #7CA3BF;
1373
+ font-size: 18px;
1374
+ line-height: 1.5;
1375
+ font-weight: bold;
1376
+ }
1377
+ .rtb-dashboard-get-premium-widget-features {
1378
+ position: relative;
1379
+ float: left;
1380
+ width: calc(100% - 16px);
1381
+ padding: 0 8px;
1382
+ -webkit-margin-after: 0;
1383
+ }
1384
+ .rtb-dashboard-get-premium-widget-features li {
1385
+ clear: both;
1386
+ position: relative;
1387
+ float: left;
1388
+ width: calc(100% - 36px);
1389
+ margin-bottom: 8px;
1390
+ padding-left: 36px;
1391
+ background-image: url(../img/dash-asset-checkmark.png);
1392
+ background-position: left top;
1393
+ background-size: 20px;
1394
+ background-repeat: no-repeat;
1395
+ font-style: italic;
1396
+ }
1397
+ .rtb-dashboard-get-premium-widget-features li:last-of-type {
1398
+ background-image: none;
1399
+ }
1400
+ .rtb-dashboard-get-premium-widget-button {
1401
+ clear: both;
1402
+ position: relative;
1403
+ float: left;
1404
+ width: calc(100% - 20px);
1405
+ margin: 16px 8px 10px;
1406
+ border: 2px solid #7CA3BF;
1407
+ background-color: #7CA3BF;
1408
+ color: #fff;
1409
+ padding: 6px 0;
1410
+ font-size: 12px;
1411
+ text-decoration: none;
1412
+ text-align: center;
1413
+ font-weight: bold;
1414
+ border-radius: 2px;
1415
+ }
1416
+ .rtb-dashboard-get-premium-widget-button:hover {
1417
+ background-color: #91B5CE;
1418
+ border-color: #91B5CE;
1419
+ color: #fff;
1420
+ }
1421
+ .rtb-dashboard-get-premium-widget-button.rtb-dashboard-new-trial-button {
1422
+ background-color: transparent;
1423
+ color: #7CA3BF;
1424
+ font-size: 11px;
1425
+ cursor: pointer;
1426
+ width: calc(100% - 16px);
1427
+ margin: 0 8px 16px;
1428
+ }
1429
+ .rtb-dashboard-get-premium-widget-button.rtb-dashboard-new-trial-button:hover {
1430
+ background-color: #7CA3BF;
1431
+ border-color: #7CA3BF;
1432
+ color: #fff;
1433
+ }
1434
+
1435
+ .rtb-dashboard-other-plugins {
1436
+ position: relative;
1437
+ float: left;
1438
+ width: 100%;
1439
+ }
1440
+ .rtb-dashboard-other-plugins li {
1441
+ position: relative;
1442
+ float: left;
1443
+ width: 100%;
1444
+ margin-bottom: 24px;
1445
+ }
1446
+ .rtb-dashboard-other-plugins li:last-of-type {
1447
+ margin-bottom: 12px;
1448
+ }
1449
+ .rtb-dashboard-other-plugins li img {
1450
+ position: relative;
1451
+ float: left;
1452
+ width: 64px;
1453
+ height: auto;
1454
+ margin-right: 16px;
1455
+ border: none;
1456
+ }
1457
+ .rtb-dashboard-other-plugins li .rtb-dashboard-other-plugins-text {
1458
+ position: relative;
1459
+ float: left;
1460
+ width: calc(100% - 80px);
1461
+ }
1462
+ .rtb-dashboard-other-plugins li .rtb-dashboard-other-plugins-title {
1463
+ position: relative;
1464
+ float: left;
1465
+ width: 100%;
1466
+ font-size: 16px;
1467
+ color: #444;
1468
+ font-weight: bold;
1469
+ }
1470
+ .rtb-dashboard-other-plugins li .rtb-dashboard-other-plugins-blurb {
1471
+ position: relative;
1472
+ float: left;
1473
+ width: 100%;
1474
+ font-size: 11px;
1475
+ margin-top: 8px;
1476
+ }
1477
+
1478
+ @media screen and (min-width: 1441px) {
1479
+ #rtb-dashboard-content-area {
1480
+ width: calc(100% - 194px);
1481
+ margin: 32px 20px 32px 174px;
1482
+ }
1483
+ }
1484
+ @media screen and (max-width: 1150px) {
1485
+ #rtb-dashboard-content-area {
1486
+ width: calc(100% - 40px);
1487
+ margin: 16px 20px 32px;
1488
+ }
1489
+ }
1490
+ @media screen and (max-width: 1000px) {
1491
+ .rtb-dashboard-key-widget-submit {
1492
+ font-size: 12px;
1493
+ }
1494
+ }
1495
+ @media screen and (max-width: 800px) {
1496
+ #rtb-dashboard-content-left, #rtb-dashboard-content-right {
1497
+ float: left;
1498
+ width: 100%;
1499
+ }
1500
+ .rtb-dashboard-new-widget-box.ewd-widget-box-two-thirds, .rtb-dashboard-new-widget-box.ewd-widget-box-one-third {
1501
+ width: 100%;
1502
+ margin-left: 0;
1503
+ }
1504
+
1505
+ .rtb-dashboard-key-widget {
1506
+ width: calc(100% - 48px);
1507
+ margin: 16px 24px 8px;
1508
+ padding: 54px 0 0 0;
1509
+ background-image: url(../img/dash-asset-key.png);
1510
+ background-size: 64px 30px;
1511
+ background-position: center top;
1512
+ background-repeat: no-repeat;
1513
+ }
1514
+ .rtb-dashboard-key-widget-input {
1515
+ width: 100%;
1516
+ }
1517
+ .rtb-dashboard-key-widget-submit {
1518
+ width: 100%;
1519
+ margin: 8px 0 0 0 !important;
1520
+ font-size: 14px;
1521
+ }
1522
+ .rtb-dashboard-key-widget-text {
1523
+ margin-top: 16px;
1524
+ text-align: center;
1525
+ }
1526
+
1527
+ .rtb-dashboard-support-widgets {
1528
+ width: 90%;
1529
+ padding: 0 5%;
1530
+ }
1531
+ .rtb-dashboard-support-widgets li {
1532
+ width: 100%;
1533
+ margin: 0 0 12px 0;
1534
+ padding-bottom: 12px;
1535
+ border-bottom: 1px solid #ddd;
1536
+ }
1537
+ .rtb-dashboard-support-widgets li:last-of-type {
1538
+ border-bottom: none;
1539
+ margin-bottom: 0;
1540
+ }
1541
+ .rtb-dashboard-support-widgets li a {
1542
+ text-align: left;
1543
+ color: #444;
1544
+ }
1545
+ .rtb-dashboard-support-widgets li a:hover {
1546
+ color: #1b335f;
1547
+ }
1548
+ .rtb-dashboard-support-widgets li img {
1549
+ width: 32px;
1550
+ height: 32px;
1551
+ padding: 0 24px 0 16px;
1552
+ }
1553
+ .rtb-dashboard-support-widgets li .rtb-dashboard-support-widgets-text {
1554
+ width: calc(100% - 72px);
1555
+ margin-top: 7px;
1556
+ text-transform: uppercase;
1557
+ font-size: 11px;
1558
+ }
1559
+ #rtb-dashboard-support-widget-box .rtb-dashboard-new-widget-box-bottom {
1560
+ border-top: none;
1561
+ }
1562
+
1563
+ #rtb-dashboard-get-premium-widget-box {
1564
+ display: none;
1565
+ }
1566
+ }
1567
+
1568
+ @media screen and (max-width: 568px) {
1569
+ #rtb-dashboard-guarantee-widget-box {
1570
+ background: #1b335f;
1571
+ }
1572
+ .rtb-dashboard-guarantee {
1573
+ width: calc(100% - 48px);
1574
+ padding: 0;
1575
+ height: 199px;
1576
+ background-image: url(../img/dash-asset-badge.png);
1577
+ background-size: 200px 199px;
1578
+ background-position: center top;
1579
+ background-repeat: no-repeat;
1580
+ }
1581
+ .rtb-dashboard-guarantee-title, .rtb-dashboard-guarantee-text {
1582
+ display: none;
1583
+ }
1584
+ }
1585
+
1586
+
1587
+
1588
+ /*** FOOTER ***/
1589
+
1590
+ #rtb-dashboard-new-footer-one {
1591
+ position: relative;
1592
+ float: left;
1593
+ width: 100%;
1594
+ background: #fff;
1595
+ color: #777;
1596
+ }
1597
+ .rtb-dashboard-new-footer-one-inside {
1598
+ position: relative;
1599
+ float: left;
1600
+ width: 80%;
1601
+ margin: 0 10%;
1602
+ }
1603
+ .rtb-dashboard-new-footer-one-left {
1604
+ position: relative;
1605
+ float: left;
1606
+ width: calc(100% - 224px);
1607
+ margin-bottom: 32px;
1608
+ }
1609
+ .rtb-dashboard-new-footer-one-title {
1610
+ position: relative;
1611
+ float: left;
1612
+ width: 100%;
1613
+ margin-top: 56px;
1614
+ font-size: 24px;
1615
+ font-weight: bold;
1616
+ }
1617
+ .rtb-dashboard-new-footer-one-benefits {
1618
+ position: relative;
1619
+ float: left;
1620
+ width: 100%;
1621
+ margin-top: 32px;
1622
+ }
1623
+ .rtb-dashboard-new-footer-one-benefits li {
1624
+ position: relative;
1625
+ float: left;
1626
+ width: calc(33.333333% - 36px);
1627
+ margin-bottom: 11px;
1628
+ padding-left: 36px;
1629
+ background-image: url(../img/dash-asset-checkmark.png);
1630
+ background-position: left top;
1631
+ background-size: 20px;
1632
+ background-repeat: no-repeat;
1633
+ font-style: italic;
1634
+ }
1635
+
1636
+ .rtb-dashboard-new-footer-one-buttons {
1637
+ position: relative;
1638
+ float: right;
1639
+ width: 192px;
1640
+ margin-top: 112px;
1641
+ }
1642
+
1643
+ #rtb-dashboard-new-footer-two {
1644
+ position: relative;
1645
+ float: left;
1646
+ width: 100%;
1647
+ background: #1b335f;
1648
+ color: #D3DFF5;
1649
+ }
1650
+ .rtb-dashboard-new-footer-two-inside {
1651
+ position: relative;
1652
+ float: left;
1653
+ width: 90%;
1654
+ margin: 48px 5%;
1655
+ }
1656
+ .rtb-dashboard-new-footer-two-icon {
1657
+ position: relative;
1658
+ float: left;
1659
+ width: 200px;
1660
+ height: auto;
1661
+ margin-right: 40px;
1662
+ }
1663
+ .rtb-dashboard-new-footer-two-blurb {
1664
+ position: relative;
1665
+ float: left;
1666
+ width: 300px;
1667
+ line-height: 1.7;
1668
+ font-size: 12px;
1669
+ }
1670
+ .rtb-dashboard-new-footer-two-menu {
1671
+ position: relative;
1672
+ float: right;
1673
+ width: 150px;
1674
+ -webkit-margin-after: 0;
1675
+ -webkit-margin-before: 0;
1676
+ }
1677
+ .rtb-dashboard-new-footer-two-menu li {
1678
+ clear: both;
1679
+ position: relative;
1680
+ float: right;
1681
+ width: 100%;
1682
+ font-weight: bold;
1683
+ margin-bottom: 4px;
1684
+ color: #fff;
1685
+ font-size: 13px;
1686
+ }
1687
+ .rtb-dashboard-new-footer-two-menu li:first-of-type {
1688
+ margin-bottom: 9px;
1689
+ }
1690
+ .rtb-dashboard-new-footer-two-menu li:last-of-type {
1691
+ margin-bottom: 0;
1692
+ }
1693
+ .rtb-dashboard-new-footer-two-menu li a {
1694
+ font-weight: normal;
1695
+ color: #D3DFF5;
1696
+ text-decoration: none;
1697
+ font-size: 12px;
1698
+ }
1699
+ .rtb-dashboard-new-footer-two-menu li a:hover {
1700
+ color: #fff;
1701
+ }
1702
+
1703
+ @media screen and (max-width: 1100px) {
1704
+ .rtb-dashboard-new-footer-one-left {
1705
+ width: 100%;
1706
+ margin-bottom: 0;
1707
+ }
1708
+ .rtb-dashboard-new-footer-one-title {
1709
+ margin-top: 56px;
1710
+ font-size: 24px;
1711
+ line-height: 28px;
1712
+ text-align: center;
1713
+ }
1714
+ .rtb-dashboard-new-footer-one-benefits li {
1715
+ width: calc(50% - 36px);
1716
+ }
1717
+ .rtb-dashboard-new-footer-one-buttons {
1718
+ float: left;
1719
+ width: 100%;
1720
+ margin-top: 32px;
1721
+ margin-bottom: 24px;
1722
+ }
1723
+ .rtb-dashboard-new-footer-one-buttons .rtb-dashboard-new-upgrade-button {
1724
+ float: left;
1725
+ margin-left: calc(50% - 96px);
1726
+ }
1727
+
1728
+ .rtb-dashboard-new-footer-two-icon {
1729
+ clear: both;
1730
+ float: left;
1731
+ margin: 0 0 16px calc(50% - 55px);
1732
+ }
1733
+ .rtb-dashboard-new-footer-two-blurb {
1734
+ display: none;
1735
+ }
1736
+ .rtb-dashboard-new-footer-two-menu {
1737
+ float: left;
1738
+ width: 100%;
1739
+ margin-top: 32px;
1740
+ }
1741
+ .rtb-dashboard-new-footer-two-menu li {
1742
+ float: left;
1743
+ text-align: center;
1744
+ margin-bottom: 4px;
1745
+ font-size: 17px;
1746
+ }
1747
+ .rtb-dashboard-new-footer-two-menu li:first-of-type {
1748
+ margin-bottom: 9px;
1749
+ }
1750
+ .rtb-dashboard-new-footer-two-menu li:last-of-type {
1751
+ margin-bottom: 0;
1752
+ }
1753
+ .rtb-dashboard-new-footer-two-menu li a {
1754
+ font-size: 16px;
1755
+ }
1756
+ }
1757
+ @media screen and (max-width: 568px) {
1758
+ .rtb-dashboard-new-footer-one-benefits li {
1759
+ clear: both;
1760
+ width: calc(100% - 36px);
1761
+ }
1762
+ }
1763
+
1764
+
1765
+
1766
+
1767
+
1768
+
1769
+
1770
+
1771
+ /************************/
1772
+ /***** OPTIONS PAGE *****/
1773
+ /************************/
1774
+
1775
+ /* Side Menu */
1776
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper {
1777
+ position: relative;
1778
+ float: left;
1779
+ border: none;
1780
+ width: 180px;
1781
+ box-shadow: -1px 1px 8px #ccc;
1782
+ overflow: hidden;
1783
+ padding-top: 0;
1784
+ margin-top: 20px;
1785
+ }
1786
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper a {
1787
+ clear: both;
1788
+ display: block;
1789
+ position: relative;
1790
+ float: left;
1791
+ background-color: #e2e2e2;
1792
+ border: none;
1793
+ border-bottom: 1px solid #f1f1f1;
1794
+ color: #555;
1795
+ font-weight: bold;
1796
+ padding-left: 20px;
1797
+ width: calc(100% - 20px);
1798
+ text-align: left;
1799
+ margin: 0;
1800
+ height: 34px;
1801
+ line-height: 34px;
1802
+ font-size: 13px;
1803
+ }
1804
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper a:last-of-type {
1805
+ border-bottom: none;
1806
+ }
1807
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper a.nav-tab-active {
1808
+ box-shadow: none;
1809
+ background-color: #fff !important;
1810
+ color: #1b335f;
1811
+ border-left: 4px solid #1b335f;
1812
+ }
1813
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper a:hover {
1814
+ color: #29324e;
1815
+ background-color: rgba(199,199,199, 0.5);
1816
+ box-shadow: none;
1817
+ border-left: 4px solid #29324e;
1818
+ }
1819
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper a.nav-tab-active:hover {
1820
+ color: #1b335f;
1821
+ background-color: #fff;
1822
+ border-left: 4px solid #1b335f;
1823
+ }
1824
+
1825
+ /* Right side */
1826
+ .bookings_page_rtb-settings .wrap form {
1827
+ display: block;
1828
+ position: relative;
1829
+ float: left;
1830
+ width: calc(100% - 276px);
1831
+ padding: 32px 48px;
1832
+ z-index: 999;
1833
+ background:#fff;
1834
+ margin: 20px 0 0 !important;
1835
+ min-height: 400px;
1836
+ border: none;
1837
+ }
1838
+
1839
+ .bookings_page_rtb-settings .wrap form h2:first-of-type {
1840
+ font-size: 18px;
1841
+ color: #1b335f;
1842
+ margin: 0 0 32px !important;
1843
+ }
1844
+
1845
+ .bookings_page_rtb-settings .wrap form h2:nth-of-type(1n+2) {
1846
+ position: relative;
1847
+ float: left;
1848
+ background: #1b335f;
1849
+ margin: 8px 0 0;
1850
+ font-size: 15px;
1851
+ font-weight: bold;
1852
+ color: #fff;
1853
+ padding: 12px 2%;
1854
+ width: 96%;
1855
+ text-transform: uppercase;
1856
+ z-index: 2;
1857
+ }
1858
+ .bookings_page_rtb-settings .wrap form .form-table {
1859
+ width: 90%;
1860
+ margin: 0 auto 16px;
1861
+ box-shadow: 0 1px 12px #ddd;
1862
+ display: block;
1863
+ padding: 11px 5%;
1864
+ }
1865
+
1866
+ .bookings_page_rtb-settings .wrap form p.description {
1867
+ display: none;
1868
+ }
1869
+ .bookings_page_rtb-settings .wrap form .form-table p.description {
1870
+ display: block;
1871
+ }
1872
+ .bookings_page_rtb-settings .wrap form .form-table p.description.disabled {
1873
+ color: #b5b5b5;
1874
+ }
1875
+
1876
+
1877
+ .rtb-premium-options-table-overlay + table th,
1878
+ .rtb-premium-options-table-overlay + table td {
1879
+ color: #b5b5b5;
1880
+ }
1881
+
1882
+
1883
+
1884
+
1885
+
1886
+ /************************
1887
+ TOGGLE SWITCHES
1888
+ ************************/
1889
+ .rtb-admin-hide-radios {
1890
+ display: none;
1891
+ }
1892
+
1893
+ /* The switch - the box around the slider */
1894
+ .rtb-admin-switch {
1895
+ position: relative;
1896
+ display: inline-block;
1897
+ width: 40px;
1898
+ height: 22px;
1899
+ }
1900
+
1901
+ /* Hide default HTML checkbox */
1902
+ .rtb-admin-switch input {display:none;}
1903
+
1904
+ /* The slider */
1905
+ .rtb-admin-switch-slider {
1906
+ position: absolute;
1907
+ cursor: pointer;
1908
+ top: 0;
1909
+ left: 0;
1910
+ right: 0;
1911
+ bottom: 0;
1912
+ background-color: #ccc;
1913
+ -webkit-transition: .4s;
1914
+ transition: .4s;
1915
+ }
1916
+
1917
+ .rtb-admin-switch-slider:before {
1918
+ position: absolute;
1919
+ content: "";
1920
+ height: 14px;
1921
+ width: 14px;
1922
+ left: 4px;
1923
+ bottom: 4px;
1924
+ background-color: white;
1925
+ -webkit-transition: .4s;
1926
+ transition: .4s;
1927
+ }
1928
+
1929
+ input:checked + .rtb-admin-switch-slider {
1930
+ background-color: #1b335f;
1931
+ }
1932
+
1933
+ input:focus + .rtb-admin-switch-slider {
1934
+ box-shadow: 0 0 1px #1b335f;
1935
+ }
1936
+
1937
+ input:checked + .rtb-admin-switch-slider:before {
1938
+ -webkit-transform: translateX(18px);
1939
+ -ms-transform: translateX(18px);
1940
+ transform: translateX(18px);
1941
+ }
1942
+
1943
+ /* Rounded sliders */
1944
+ .rtb-admin-switch-slider.round {
1945
+ border-radius: 34px;
1946
+ }
1947
+
1948
+ .rtb-admin-switch-slider.round:before {
1949
+ border-radius: 50%;
1950
+ }
1951
+
1952
+
1953
+ /* RADIO BUTTON AND CHECKBOX */
1954
+ .bookings_page_rtb-settings .wrap form .form-table fieldset label {
1955
+ line-height: 1.4em;
1956
+ margin: .25em 0 .5em;
1957
+ display: inline-block;
1958
+ font-size: 14px;
1959
+ }
1960
+
1961
+ .rtb-admin-input-container input, .rtb-admin-input-container input:disabled {
1962
+ position: absolute;
1963
+ opacity: 0;
1964
+ }
1965
+ .rtb-admin-radio-button {
1966
+ position: relative;
1967
+ float: left;
1968
+ height: 14px;
1969
+ width: 14px;
1970
+ top: 1px;
1971
+ margin-right: 12px;
1972
+ background-color: #fff;
1973
+ border: 2px solid #aaa;
1974
+ border-radius: 50%;
1975
+ }
1976
+ .rtb-admin-input-container:hover input ~ .rtb-admin-radio-button {
1977
+ background-color: #E6FFFB;
1978
+ border-color: #1b335f;
1979
+ }
1980
+ .rtb-admin-input-container input:checked ~ .rtb-admin-radio-button {
1981
+ border-color: #1b335f;
1982
+ background-color: #fff;
1983
+ }
1984
+ .rtb-admin-radio-button:after {
1985
+ content: "";
1986
+ position: absolute;
1987
+ display: none;
1988
+ }
1989
+ .rtb-admin-input-container input:checked ~ .rtb-admin-radio-button:after {
1990
+ display: block;
1991
+ }
1992
+ .rtb-admin-input-container .rtb-admin-radio-button:after {
1993
+ top: 3px;
1994
+ left: 3px;
1995
+ width: 8px;
1996
+ height: 8px;
1997
+ border-radius: 50%;
1998
+ background: #1b335f;
1999
+ }
2000
+
2001
+ .rtb-admin-checkbox {
2002
+ position: relative;
2003
+ float: left;
2004
+ height: 14px;
2005
+ width: 14px;
2006
+ top: 1px;
2007
+ margin-right: 12px;
2008
+ background-color: #fff;
2009
+ border: 2px solid #aaa;
2010
+ }
2011
+ .rtb-admin-input-container:hover input ~ .rtb-admin-checkbox {
2012
+ background-color: #E6FFFB;
2013
+ border-color: #1b335f;
2014
+ }
2015
+ .rtb-admin-input-container input:checked ~ .rtb-admin-checkbox {
2016
+ border-color: #1b335f;
2017
+ background-color: #fff;
2018
+ }
2019
+ .rtb-admin-checkbox:after {
2020
+ content: "";
2021
+ position: absolute;
2022
+ display: none;
2023
+ }
2024
+ .rtb-admin-input-container input:checked ~ .rtb-admin-checkbox:after {
2025
+ display: block;
2026
+ }
2027
+ .rtb-admin-input-container .rtb-admin-checkbox:after {
2028
+ left: 4px;
2029
+ top: 1px;
2030
+ width: 4px;
2031
+ height: 8px;
2032
+ border: solid #1b335f;
2033
+ border-width: 0 2px 2px 0;
2034
+ -webkit-transform: rotate(45deg);
2035
+ -ms-transform: rotate(45deg);
2036
+ transform: rotate(45deg);
2037
+ }
2038
+
2039
+ /* Textbox and Text Area and Select boxes */
2040
+ .bookings_page_rtb-settings .wrap form .form-table input[type=text],
2041
+ .bookings_page_rtb-settings .wrap form .form-table input[type=search],
2042
+ .bookings_page_rtb-settings .wrap form .form-table input[type=tel],
2043
+ .bookings_page_rtb-settings .wrap form .form-table input[type=url],
2044
+ .bookings_page_rtb-settings .wrap form .form-table input[type=week],
2045
+ .bookings_page_rtb-settings .wrap form .form-table input[type=password],
2046
+ .bookings_page_rtb-settings .wrap form .form-table input[type=color],
2047
+ .bookings_page_rtb-settings .wrap form .form-table input[type=email],
2048
+ .bookings_page_rtb-settings .wrap form .form-table input[type=number],
2049
+ .bookings_page_rtb-settings .wrap form .form-table textarea,
2050
+ .bookings_page_rtb-settings .wrap form .form-table select {
2051
+ border: 2px solid #ccc;
2052
+ border-radius: 5px;
2053
+ box-shadow: none;
2054
+ }
2055
+ .bookings_page_rtb-settings .wrap form .form-table select,
2056
+ .bookings_page_rtb-settings .wrap form .form-table textarea {
2057
+ width: auto !important;
2058
+ min-width: 50%;
2059
+ max-width: 100% !important;
2060
+ }
2061
+ #rtb-dining-block-length_count,
2062
+ #rtb-dining-block-length_unit {
2063
+ min-width: 0;
2064
+ }
2065
+
2066
+ .bookings_page_rtb-settings .wrap form .form-table textarea {
2067
+ min-width: 300px;
2068
+ min-height: 200px;
2069
+ }
2070
+ .bookings_page_rtb-settings .wrap form .form-table .wp-editor-wrap textarea {
2071
+ border: none;
2072
+ border-radius: 0;
2073
+ min-width: 0;
2074
+ max-width: 100%;
2075
+ min-height: 0;
2076
+ }
2077
+
2078
+
2079
+ /**************************
2080
+ OTHER OPTION PAGE STYLING
2081
+ **************************/
2082
+
2083
+ /*LOCK PREMIUM CONTENT*/
2084
+ .rtb-premium-options-table {
2085
+ position: relative;
2086
+ min-height: 240px;
2087
+ }
2088
+ .rtb-premium-options-table.Yes {
2089
+ min-height: 0;
2090
+ }
2091
+ .rtb-premium-options-table-overlay {
2092
+ position: absolute;
2093
+ top: 0;
2094
+ left: 0;
2095
+ width: 1000px;
2096
+ height: 500px;
2097
+ background: rgba(0,0,0,.45);
2098
+ z-index: 2;
2099
+ }
2100
+ .section-disabled {
2101
+ position: absolute;
2102
+ margin-top: 16px;
2103
+ width: 200px;
2104
+ height: 200px;
2105
+ padding: 16px;
2106
+ background: #fff;
2107
+ left: calc(50% - 116px);
2108
+ }
2109
+ .section-disabled img {
2110
+ position: relative;
2111
+ float: left;
2112
+ width: 40px;
2113
+ height: auto;
2114
+ margin: 16px 80px 24px;
2115
+ }
2116
+ .section-disabled p {
2117
+ margin: 16px 0;
2118
+ text-align: center;
2119
+ color: #888;
2120
+ }
2121
+ .section-disabled .rtb-dashboard-get-premium-widget-button {
2122
+ clear: both;
2123
+ position: relative;
2124
+ float: left;
2125
+ width: calc(100% - 20px);
2126
+ margin: 16px 8px;
2127
+ border: 2px solid #7CA3BF;
2128
+ background-color: #7CA3BF;
2129
+ color: #fff;
2130
+ padding: 6px 0;
2131
+ font-size: 12px;
2132
+ text-decoration: none;
2133
+ text-align: center;
2134
+ font-weight: bold;
2135
+ border-radius: 2px;
2136
+ }
2137
+ .section-disabled .rtb-dashboard-get-premium-widget-button:hover {
2138
+ background-color: #91B5CE;
2139
+ border-color: #91B5CE;
2140
+ color: #fff;
2141
+ }
2142
+
2143
+
2144
+ /*************
2145
+ RESPONSIVE
2146
+ *************/
2147
+ @media screen and (max-width: 1099px) {
2148
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper {
2149
+ clear: both;
2150
+ width: 100%;
2151
+ }
2152
+ .bookings_page_rtb-settings .wrap form {
2153
+ clear: both;
2154
+ width: calc(100% - 96px);
2155
+ }
2156
+ }
2157
+ @media screen and (max-width: 782px) {
2158
+ .bookings_page_rtb-settings .wrap h2.nav-tab-wrapper {
2159
+ margin: 0 0 20px 0;
2160
+ }
2161
+ .bookings_page_rtb-settings .wrap form {
2162
+ width: calc(100% - 96px);
2163
+ }
2164
+ .rtb-admin-section-heading {
2165
+ text-align: center;
2166
+ }
2167
+ .bookings_page_rtb-settings .wrap form .form-table,
2168
+ .ufaq-styling-set .form-table {
2169
+ box-shadow: none;
2170
+ }
2171
+ .bookings_page_rtb-settings .wrap form .form-table,
2172
+ .ufaq-styling-set .form-table,
2173
+ .bookings_page_rtb-settings .wrap form .form-table tbody,
2174
+ .bookings_page_rtb-settings .wrap form .form-table tr,
2175
+ .bookings_page_rtb-settings .wrap form .form-table th,
2176
+ .bookings_page_rtb-settings .wrap form .form-table td {
2177
+ clear: both;
2178
+ float: left;
2179
+ width: 100%;
2180
+ }
2181
+ .bookings_page_rtb-settings .wrap form .form-table {
2182
+ padding: 11px 0;
2183
+ }
2184
+ .bookings_page_rtb-settings .wrap form .form-table th {
2185
+ padding: 20px 5% 8px;
2186
+ width: 90%;
2187
+ height: auto;
2188
+ margin: 0;
2189
+ background-image: url(../images/options-asset-info.png);
2190
+ background-position: 95% 20px;
2191
+ background-size: 18px 18px;
2192
+ background-repeat: no-repeat;
2193
+ cursor: pointer;
2194
+ }
2195
+ .bookings_page_rtb-settings .wrap form .form-table td {
2196
+ padding-top: 4px;
2197
+ }
2198
+ .bookings_page_rtb-settings .wrap form .form-table td fieldset {
2199
+ position: relative;
2200
+ }
2201
+ .bookings_page_rtb-settings .wrap form .form-table td label {
2202
+ position: relative;
2203
+ clear: both;
2204
+ float: left;
2205
+ width: 90%;
2206
+ margin-left: 5% !important;
2207
+ }
2208
+ .bookings_page_rtb-settings .wrap form .form-table td label.rtb-admin-switch {
2209
+ position: absolute;
2210
+ width: 40px;
2211
+ top: -35px;
2212
+ right: 5%;
2213
+ }
2214
+ .bookings_page_rtb-settings .wrap form .form-table td p {
2215
+ display: none;
2216
+ position: relative;
2217
+ float: left;
2218
+ width: 90%;
2219
+ padding: 10px 5% 24px;
2220
+ background: #f3f3f3;
2221
+ border-bottom: 1px solid #ccc;
2222
+ font-size: 13px;
2223
+ }
2224
+ .bookings_page_rtb-settings .wrap form .form-table td input[type="button"] {
2225
+ display: block;
2226
+ margin: 10px auto 4px;
2227
+ }
2228
+ .rtb-admin-styling-section .ewd-admin-labelling-section label {
2229
+ width: 95%;
2230
+ margin: 0 2.5% 8px;
2231
+ }
2232
+ .rtb-admin-input-container {
2233
+ width: calc(100% - 16px);
2234
+ padding-left: 16px;
2235
+ }
2236
+
2237
+ .rtb-admin-styling-section {
2238
+ box-shadow: none;
2239
+ }
2240
+ .rtb-admin-styling-subsection, .rtb-admin-styling-subsection:first-of-type {
2241
+ width: 100%;
2242
+ padding-right: 0;
2243
+ padding-left: 0;
2244
+ }
2245
+ .rtb-admin-styling-subsection-label {
2246
+ width: 90%;
2247
+ padding: 0 5% 8px;
2248
+ }
2249
+ .ewdOptionHasInfo .rtb-admin-styling-subsection-label {
2250
+ padding: 0 calc(5% + 38px) 8px 5%;
2251
+ width: calc(90% - 38px);
2252
+ background-image: url(../images/options-asset-info.png);
2253
+ background-position: 95% 0;
2254
+ background-size: 18px 18px;
2255
+ background-repeat: no-repeat;
2256
+ }
2257
+ .rtb-admin-styling-subsection:first-of-type .rtb-admin-styling-subsection-label {
2258
+ padding: 20px 5% 8px;
2259
+ }
2260
+ .ewdOptionHasInfo:first-of-type .rtb-admin-styling-subsection-label {
2261
+ padding: 20px calc(5% + 38px) 8px 5%;
2262
+ background-image: url(../images/options-asset-info.png);
2263
+ background-position: 950% 20px;
2264
+ background-size: 18px 18px;
2265
+ background-repeat: no-repeat;
2266
+ }
2267
+ .rtb-admin-styling-subsection-content {
2268
+ width: 100%;
2269
+ padding: 0 ;
2270
+ }
2271
+ .rtb-admin-styling-subsection-content-each {
2272
+ margin-bottom: 10px;
2273
+ padding-bottom: 10px;
2274
+ border-bottom: 1px solid #ddd;
2275
+ }
2276
+ .rtb-admin-styling-subsection-content-each:last-of-type {
2277
+ border-bottom: none;
2278
+ }
2279
+ .rtb-admin-styling-subsection-content-label, .rtb-admin-styling-subsection-content-right {
2280
+ width: calc(90% - 16px);
2281
+ padding: 0 0 0 calc(5% + 16px);
2282
+ }
2283
+ .rtb-admin-styling-subsection-content-label {
2284
+ padding-top: 10px;
2285
+ padding-bottom: 15px;
2286
+ }
2287
+ .rtb-admin-styling-subsection-content label {
2288
+ width: 90%;
2289
+ margin-left: 5% !important;
2290
+ }
2291
+ .rtb-admin-styling-subsection p {
2292
+ display: none;
2293
+ position: relative;
2294
+ float: left;
2295
+ width: 90%;
2296
+ padding: 10px 5% 24px;
2297
+ background: #f3f3f3;
2298
+ border-bottom: 1px solid #ccc;
2299
+ font-size: 13px;
2300
+ }
2301
+ .rtb-admin-styling-section .ewd-admin-labelling-section label p {
2302
+ display: block;
2303
+ padding: 10px 0 0;
2304
+ background: transparent;
2305
+ border-bottom: none;
2306
+ }
2307
+ .rtb-admin-styling-text-input {
2308
+ width: 100%;
2309
+ }
2310
+ .rtb-admin-styling-subsection input[type="button"] {
2311
+ display: block;
2312
+ margin: 10px auto 0;
2313
+ }
2314
+
2315
+ }
2316
+
2317
+
2318
+ /****************************
2319
+ * RTB EXPORT STYLING
2320
+ ****************************/
2321
+
2322
+ .ebfrtb-options-form h2 {
2323
+ margin: 0;
2324
+ }
2325
+
2326
+ .ebfrtb-options-form .hidden-label {
2327
+ position: absolute;
2328
+ top: -9999px;
2329
+ }
2330
+
2331
+ .ebfrtb-options-form fieldset > div {
2332
+ margin: 2em 0;
2333
+ }
2334
+
2335
+ .ebfrtb-options-form .date-range .selector {
2336
+ border: 1px solid #ddd;
2337
+ border-radius: 4px;
2338
+ }
2339
+
2340
+ .ebfrtb-options-form .date-range .selector ul {
2341
+ margin: 0;
2342
+ text-align: center;
2343
+ }
2344
+
2345
+ .ebfrtb-options-form .date-range .selector li {
2346
+ display: inline-block;
2347
+ padding: 0.5em 1em;
2348
+ margin: 0;
2349
+ }
2350
+
2351
+ .ebfrtb-options-form .date-range .selector a {
2352
+ text-decoration: none;
2353
+ }
2354
+
2355
+ .ebfrtb-options-form .date-range .selector .current {
2356
+ font-weight: 600;
2357
+ color: #666;
2358
+ }
2359
+
2360
+ .ebfrtb-options-form .date-range .selector > div {
2361
+ display: none;
2362
+ padding: 1em;
2363
+ background: #ddd;
2364
+ font-style: italic;
2365
+ color: #777;
2366
+ }
2367
+
2368
+ .ebfrtb-options-form .date-range .selector .dates:before,
2369
+ .ebfrtb-options-form .date-range .selector .dates:after {
2370
+ content: ' ';
2371
+ display: table;
2372
+ }
2373
+ .ebfrtb-options-form .date-range .selector .dates:after {
2374
+ clear: both;
2375
+ }
2376
+
2377
+ .ebfrtb-options-form .date-range .selector .dates > div {
2378
+ width: 48%;
2379
+ float: left;
2380
+ }
2381
+
2382
+ .ebfrtb-options-form .date-range .selector .dates > .date-end {
2383
+ float: right;
2384
+ }
2385
+
2386
+ .ebfrtb-options-form .date-range .selector .dates input[type="text"] {
2387
+ background: #fff;
2388
+ cursor: pointer;
2389
+ }
2390
+
2391
+ .ebfrtb-options-form .date-range .selector input {
2392
+ -webkit-box-shadow: none;
2393
+ box-shadow: none;
2394
+ border: 1px solid #ccc;
2395
+ }
2396
+
2397
+ .ebfrtb-options-form .status label {
2398
+ margin-bottom: 0.5em;
2399
+ }
2400
+
2401
+ .ebfrtb-options-form a.settings {
2402
+ float: right;
2403
+ line-height: 28px;
2404
+ margin-top: 1em;
2405
+ }
2406
+
2407
+ /* Admin styles for MailChimp for Restaurants Reservations */
2408
+
2409
+ /* Api Key */
2410
+ .mcfrtb-status {
2411
+ padding: 3px 5px;
2412
+ color: #fff;
2413
+ font-weight: bold;
2414
+ text-transform: uppercase;
2415
+ font-size: 14px;
2416
+ }
2417
+ .mcfrtb-status-connected {
2418
+ background: #51ca51;
2419
+ }
2420
+ .mcfrtb-status-error {
2421
+ background: #ff3d3d;
2422
+ }
2423
+
2424
+ /* Subscribe list and merge fields */
2425
+ .mcfrtb_loading {
2426
+ opacity: 0;
2427
+ }
2428
+ .mcfrtb_loading span {
2429
+ display: inline-block;
2430
+ float: none;
2431
+ vertical-align: middle;
2432
+ opacity: 0.7;
2433
+ }
2434
+
2435
+ .mcfrtb_loading .spinner {
2436
+ visibility: visible;
2437
+ }
2438
+
2439
+ #mcfrtb-merge-controls .error,
2440
+ .mcfrtb-list-select .error {
2441
+ padding: 5px;
2442
+ background: #ff3d3d;
2443
+ color: #fff;
2444
+ margin: 2em 0;
2445
+ }
2446
+ #mcfrtb-merge-controls.active {
2447
+ margin-top: 2em;
2448
+ background: #fff;
2449
+ border: 1px solid #ccc;
2450
+ padding: 1em;
2451
+ }
2452
+ #mcfrtb-merge-controls table {
2453
+ margin-bottom: 2em;
2454
+ }
2455
+ #mcfrtb-merge-controls th {
2456
+ padding: 0 0 1em;
2457
+ }
2458
+ #mcfrtb-merge-controls td {
2459
+ padding: 2px 5px 2px 0;
2460
+ position: relative;
2461
+ }
2462
+ #mcfrtb-merge-controls .merge-duplicate-warning {
2463
+ position: absolute;
2464
+ left: -25px;
2465
+ top: 50%;
2466
+ margin-top: -10px;
2467
+ color: #ff3d3d;
2468
+ }
2469
+
2470
+ /* Collapsed view for small screens */
2471
+ @media screen and (max-width: 782px) {
2472
+
2473
+ .mcfrtb-status,
2474
+ .mcfrtb_loading,
2475
+ #mcfrtb-merge-controls {
2476
+ display: inline-block;
2477
+ margin: 0.5em 2px;
2478
+ }
2479
+
2480
+ .bookings_page_rtb-settings .description,
2481
+ .bookings_page_rtb-settings .form-table th {
2482
+ margin-left: 2px;
2483
+ }
2484
+
2485
+ #mcfrtb-merge-controls th, #mcfrtb-merge-controls td {
2486
+ display: table-cell;
2487
+ }
2488
+
2489
+ }
2490
+
2491
+
2492
+ /******************************************************************
2493
+ NEW STYLING FOR ADD/DELETE AREAS LIKE CUSTOM FIELDS
2494
+ ******************************************************************/
2495
+ .sap-infinite-table table th {
2496
+ padding: 0 10px !important;
2497
+ }
2498
+ .rtb-new-admin-add-button {
2499
+ position: relative;
2500
+ float: left;
2501
+ width: calc(100% - 4px);
2502
+ border: 2px dotted #bbb;
2503
+ text-align: center;
2504
+ padding: 12px 0;
2505
+ color: #999;
2506
+ }
2507
+ .rtb-new-admin-add-button:hover {
2508
+ background: #f5f5f5;
2509
+ color: #888;
2510
+ }
2511
+ .sap-infinite-table-row-delete,
2512
+ .rtb-custom-fields-add-nutrional-information {
2513
+ cursor: pointer;
2514
+ color: #1b335f;
2515
+ }
2516
+ .sap-infinite-table-row-delete:hover,
2517
+ .rtb-custom-fields-add-nutrional-information:hover {
2518
+ color: #4366A6;
2519
+ }
2520
+
2521
+
2522
+
2523
+ /*********************************/
2524
+ /*** MENU SECTIONS EDIT SCREEN ***/
2525
+ /*********************************/
2526
+
2527
+ .rtb-edit-menu-section-image-preview {
2528
+ max-width: 200px;
2529
+ }
2530
+
2531
+
2532
+
2533
+ /*********************************/
2534
+ /*** TEMPORARY ***/
2535
+ /*********************************/
2536
+ ul.rtb-dashboard-new-footer-two-menu:first-of-type {
2537
+ display: none;
2538
+ }
assets/css/booking-form.css CHANGED
@@ -1,5 +1,8 @@
1
  /* Frontend CSS Stylesheet for Restaurant Reservations */
2
 
 
 
 
3
  .rtb-booking-form fieldset {
4
  padding-bottom: 1em;
5
  margin-bottom: 1em;
@@ -34,14 +37,13 @@
34
  margin-top: 1em;
35
  }
36
  .rtb-booking-form .message {
37
- position: absolute;
38
- top: -9999px;
39
- left: -9999px;
40
- }
41
- .rtb-booking-form .message-open {
42
  position: relative;
43
  top: auto;
44
  left: auto;
 
 
 
 
45
  }
46
  .rtb-booking-form .message textarea {
47
  min-height: 6em;
@@ -83,3 +85,24 @@
83
  list-style: none;
84
  margin: 0 0 0 1px;
85
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  /* Frontend CSS Stylesheet for Restaurant Reservations */
2
 
3
+ .rtb-hidden {
4
+ display: none;
5
+ }
6
  .rtb-booking-form fieldset {
7
  padding-bottom: 1em;
8
  margin-bottom: 1em;
37
  margin-top: 1em;
38
  }
39
  .rtb-booking-form .message {
 
 
 
 
 
40
  position: relative;
41
  top: auto;
42
  left: auto;
43
+ display: none;
44
+ }
45
+ .rtb-booking-form .message-open {
46
+ display: block;
47
  }
48
  .rtb-booking-form .message textarea {
49
  min-height: 6em;
85
  list-style: none;
86
  margin: 0 0 0 1px;
87
  }
88
+
89
+
90
+ /* ARRIVAL LIGHTBOX */
91
+ .rtb-view-bookings-form-confirmation-div {
92
+ position: fixed;
93
+ top: 100px;
94
+ z-index: 1000000;
95
+ margin: 0 auto;
96
+ background: #fff;
97
+ width: 100%;
98
+ max-width: 1080px;
99
+ }
100
+ .rtb-view-bookings-form-confirmation-background-div {
101
+ position: fixed;
102
+ top: 0;
103
+ left: 0;
104
+ width: 100%;
105
+ height: 100%;
106
+ z-index: 999999;
107
+ background: rgba(0,0,0,0.5);
108
+ }
assets/css/columns.css ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .rtb-booking-form,
2
+ .rtb-booking-form form {
3
+ position: relative;
4
+ float: left;
5
+ width: 100%;
6
+ }
7
+ .rtb-booking-form fieldset {
8
+ border: 0 solid #ccc;
9
+ margin: 0;
10
+ padding: 0;
11
+ margin-inline-start: 0;
12
+ padding-inline-start: 0;
13
+ position: relative;
14
+ float: left;
15
+ margin-top: 32px;
16
+ }
17
+ .rtb-booking-form fieldset.reservation {
18
+ width: 45%;
19
+ margin-right: 5%;
20
+ }
21
+ .rtb-booking-form fieldset.contact {
22
+ width: 50%;
23
+ }
24
+ @media screen and (max-width: 768px) {
25
+ .rtb-booking-form fieldset.reservation {
26
+ width: 100%;
27
+ margin-right: 0;
28
+ margin-bottom: 28px;
29
+ }
30
+ .rtb-booking-form fieldset.contact {
31
+ width: 100%;
32
+ }
33
+ }
34
+
35
+ .rtb-booking-form fieldset legend {
36
+ padding: 0;
37
+ }
38
+
39
+ .rtb-booking-form fieldset>div {
40
+ margin-top: 2em;
41
+ }
42
+
43
+ .rtb-booking-form fieldset label {
44
+ width: 100%;
45
+ background: #f1f1f1;
46
+ padding: 3px;
47
+ text-align: center;
48
+ color: #666;
49
+ font-weight: bold;
50
+ }
51
+
52
+ .rtb-booking-form fieldset.optin {
53
+ clear: both;
54
+ position: relative;
55
+ float: left;
56
+ width: 100%;
57
+ }
58
+ .rtb-booking-form fieldset.optin label {
59
+ position: relative;
60
+ float: right;
61
+ width: auto;
62
+ background: transparent;
63
+ padding: 0;
64
+ text-align: center;
65
+ color: inherit;
66
+ font-weight: normal;
67
+ }
68
+
69
+ .rtb-booking-form form select,
70
+ .rtb-booking-form form textarea,
71
+ .rtb-booking-form form input {
72
+ border: 1px solid #ddd;
73
+ border-top-color: #f1f1f1;
74
+ border-radius: 0;
75
+ background-color: white;
76
+ color: #777;
77
+ padding: 12px 21px;
78
+ max-width: 100%;
79
+ }
80
+ .rtb-booking-form form select,
81
+ .rtb-booking-form form input {
82
+ height: 48px;
83
+ }
84
+ .rtb-booking-form form input::webkit-input-placeholder,
85
+ .rtb-booking-form form input:ms--input-placeholder,
86
+ .rtb-booking-form form input::placeholder {
87
+ color: #aaa;
88
+ }
89
+
90
+ .rtb-booking-form form fieldset .add-message {
91
+ clear: both;
92
+ position: relative;
93
+ float: right;
94
+ margin-top: 16px;
95
+ }
96
+ .rtb-booking-form .add-message a {
97
+ box-shadow: none;
98
+ padding: 6px 12px;
99
+ border: 1px solid #ddd;
100
+ background: white;
101
+ color: #888;
102
+ }
103
+ .rtb-booking-form .add-message a:hover {
104
+ background: #aaa;
105
+ border-color: #aaa;
106
+ color: white;
107
+ }
108
+
109
+ .rtb-booking-form button {
110
+ float: left;
111
+ margin-top: 24px;
112
+ cursor: pointer;
113
+ display: block;
114
+ align-items: stretch;
115
+ }
116
+
117
+ .rtb-booking-form fieldset.optin input[type="checkbox"] {
118
+ vertical-align: top;
119
+ margin-top: -10px;
120
+ }
assets/css/contemporary.css ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .rtb-booking-form fieldset {
2
+ border: 0 solid #ccc;
3
+ margin: 0;
4
+ padding: 0;
5
+ margin-inline-start: 0;
6
+ padding-inline-start: 0;
7
+ }
8
+ .rtb-booking-form fieldset legend {
9
+ padding: 0;
10
+ }
11
+
12
+ .rtb-booking-form form select,
13
+ .rtb-booking-form form textarea,
14
+ .rtb-booking-form form input {
15
+ border: 1px solid #ccc;
16
+ border-radius: 0;
17
+ background-color: white;
18
+ color: #777;
19
+ padding: 12px 21px;
20
+ max-width: 100%;
21
+ }
22
+ .rtb-booking-form form select,
23
+ .rtb-booking-form form input {
24
+ height: 48px;
25
+ }
26
+ .rtb-booking-form form input::webkit-input-placeholder,
27
+ .rtb-booking-form form input:ms--input-placeholder,
28
+ .rtb-booking-form form input::placeholder {
29
+ color: #aaa;
30
+ }
31
+
32
+
33
+ .rtb-booking-form fieldset.reservation {
34
+ margin-bottom: 80px;
35
+ }
36
+ .rtb-booking-form fieldset.reservation label {
37
+ margin-left: 21px;
38
+ color: #666;
39
+ font-weight: bold;
40
+ }
41
+ .rtb-booking-form fieldset.reservation .rtb-text {
42
+ position: relative;
43
+ float: left;
44
+ display: block;
45
+ width: 300px;
46
+ }
47
+ .rtb-booking-form fieldset.reservation .rtb-text.time {
48
+ left: -1px;
49
+ }
50
+ .rtb-booking-form fieldset.reservation .rtb-select {
51
+ position: relative;
52
+ float: left;
53
+ display: block;
54
+ width: 300px;
55
+ left: -2px;
56
+ }
57
+
58
+ .rtb-booking-form form fieldset.reservation select,
59
+ .rtb-booking-form form fieldset.reservation textarea,
60
+ .rtb-booking-form form fieldset.reservation input {
61
+ width: 300px;
62
+ }
63
+
64
+ .rtb-booking-form form fieldset.reservation input,
65
+ .rtb-booking-form form fieldset.reservation select {
66
+ background-color: white;
67
+ margin: 7px 0 0 0;
68
+ -webkit-box-sizing: border-box;
69
+ -moz-box-sizing: border-box;
70
+ box-sizing: border-box;
71
+ -webkit-appearance: none;
72
+ -moz-appearance: none;
73
+ background-image:
74
+ linear-gradient(45deg, transparent 50%, gray 50%),
75
+ linear-gradient(135deg, gray 50%, transparent 50%),
76
+ linear-gradient(to right, #ccc, #ccc);
77
+ background-position:
78
+ calc(100% - 20px) 22px,
79
+ calc(100% - 15px) 22px,
80
+ calc(100% - 40px) 10px;
81
+ background-size:
82
+ 5px 5px,
83
+ 5px 5px,
84
+ 1px 28px;
85
+ background-repeat: no-repeat;
86
+ }
87
+ .rtb-booking-form form fieldset.reservation select:focus {
88
+ background-image:
89
+ linear-gradient(45deg, gray 50%, transparent 50%),
90
+ linear-gradient(135deg, transparent 50%, gray 50%),
91
+ linear-gradient(to right, #ccc, #ccc);
92
+ background-position:
93
+ calc(100% - 15px) 22px,
94
+ calc(100% - 20px) 22px,
95
+ calc(100% - 40px) 10px;
96
+ background-size:
97
+ 5px 5px,
98
+ 5px 5px,
99
+ 1px 28px;
100
+ background-repeat: no-repeat;
101
+ outline: 0;
102
+ }
103
+ .rtb-booking-form form fieldset.reservation select:-moz-focusring {
104
+ color: transparent;
105
+ text-shadow: 0 0 0 #000;
106
+ }
107
+
108
+
109
+ .rtb-booking-form fieldset.contact {
110
+ margin-bottom: 60px;
111
+ }
112
+ .rtb-booking-form fieldset.contact label {
113
+ margin-left: 21px;
114
+ color: #666;
115
+ font-weight: bold;
116
+ }
117
+ .rtb-booking-form fieldset.contact .rtb-text {
118
+ position: relative;
119
+ float: left;
120
+ display: block;
121
+ width: 300px;
122
+ }
123
+ .rtb-booking-form fieldset.contact .rtb-text.email {
124
+ left: -1px;
125
+ }
126
+ .rtb-booking-form fieldset.contact .rtb-text.phone {
127
+ left: -2px;
128
+ }
129
+
130
+ .rtb-booking-form form fieldset.contact select,
131
+ .rtb-booking-form form fieldset.contact textarea,
132
+ .rtb-booking-form form fieldset.contact input {
133
+ width: 300px;
134
+ }
135
+
136
+ .rtb-booking-form form fieldset .add-message {
137
+ clear: both;
138
+ position: relative;
139
+ float: left;
140
+ margin-top: 32px;
141
+ }
142
+ .rtb-booking-form .add-message a {
143
+ box-shadow: none;
144
+ padding: 6px 12px;
145
+ border: 2px solid #777;
146
+ background: white;
147
+ color: #777;
148
+ }
149
+ .rtb-booking-form .add-message a:hover {
150
+ background: #777;
151
+ color: white;
152
+ }
153
+
154
+ .rtb-booking-form form fieldset .rtb-textarea {
155
+ clear: both;
156
+ position: relative;
157
+ float: left;
158
+ }
assets/css/editor.css ADDED
@@ -0,0 +1,582 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @keyframes cffrtbrotate {
2
+ 0% {
3
+ transform: rotateZ(-360deg);
4
+ -webkit-transform: rotateZ(-360deg);
5
+ -moz-transform: rotateZ(-360deg);
6
+ -o-transform: rotateZ(-360deg);
7
+ }
8
+ 100% {
9
+ transform: rotateZ(0deg);
10
+ -webkit-transform: rotateZ(0deg);
11
+ -moz-transform: rotateZ(0deg);
12
+ -o-transform: rotateZ(0deg);
13
+ }
14
+ }
15
+ @-webkit-keyframes cffrtbrotate {
16
+ 0% {
17
+ transform: rotateZ(-360deg);
18
+ -webkit-transform: rotateZ(-360deg);
19
+ -moz-transform: rotateZ(-360deg);
20
+ -o-transform: rotateZ(-360deg);
21
+ }
22
+ 100% {
23
+ transform: rotateZ(0deg);
24
+ -webkit-transform: rotateZ(0deg);
25
+ -moz-transform: rotateZ(0deg);
26
+ -o-transform: rotateZ(0deg);
27
+ }
28
+ }
29
+ @-moz-keyframes cffrtbrotate {
30
+ 0% {
31
+ transform: rotateZ(-360deg);
32
+ -webkit-transform: rotateZ(-360deg);
33
+ -moz-transform: rotateZ(-360deg);
34
+ -o-transform: rotateZ(-360deg);
35
+ }
36
+ 100% {
37
+ transform: rotateZ(0deg);
38
+ -webkit-transform: rotateZ(0deg);
39
+ -moz-transform: rotateZ(0deg);
40
+ -o-transform: rotateZ(0deg);
41
+ }
42
+ }
43
+ @-o-keyframes cffrtbrotate {
44
+ 0% {
45
+ transform: rotateZ(-360deg);
46
+ -webkit-transform: rotateZ(-360deg);
47
+ -moz-transform: rotateZ(-360deg);
48
+ -o-transform: rotateZ(-360deg);
49
+ }
50
+ 100% {
51
+ transform: rotateZ(0deg);
52
+ -webkit-transform: rotateZ(0deg);
53
+ -moz-transform: rotateZ(0deg);
54
+ -o-transform: rotateZ(0deg);
55
+ }
56
+ }
57
+ #cffrtb-editor .load-spinner:after,
58
+ #cffrtb-field-editor-form .load-spinner:after {
59
+ display: block;
60
+ position: relative;
61
+ width: 20px;
62
+ height: 20px;
63
+ -webkit-animation: cffrtbrotate 0.6s linear infinite;
64
+ -moz-animation: cffrtbrotate 0.6s linear infinite;
65
+ -ms-animation: cffrtbrotate 0.6s linear infinite;
66
+ -o-animation: cffrtbrotate 0.6s linear infinite;
67
+ animation: cffrtbrotate 0.6s linear infinite;
68
+ border-radius: 100%;
69
+ border-top: 1px solid #777;
70
+ border-bottom: 1px solid #D1DDE2;
71
+ border-left: 1px solid #777;
72
+ border-right: 1px solid #D1DDE2;
73
+ content: '';
74
+ opacity: 0.5;
75
+ }
76
+ #cffrtb-editor {
77
+ margin-top: 2em;
78
+ }
79
+ .cffrtb-list {
80
+ margin: 0;
81
+ padding: 0;
82
+ /* Ensure there is space to drop a field into an empty fieldset */
83
+ }
84
+ .cffrtb-list .title {
85
+ position: relative;
86
+ padding: 1em;
87
+ min-height: 1.4em;
88
+ background: #D1DDE2;
89
+ border: 1px solid #82878c;
90
+ margin-bottom: 30px;
91
+ overflow: hidden;
92
+ cursor: pointer;
93
+ cursor: hand;
94
+ opacity: 1;
95
+ -webkit-transition: opacity 0.3s ease-in-out;
96
+ -moz-transition: opacity 0.3s ease-in-out;
97
+ -ms-transition: opacity 0.3s ease-in-out;
98
+ -o-transition: opacity 0.3s ease-in-out;
99
+ transition: opacity 0.3s ease-in-out;
100
+ }
101
+ .cffrtb-list .title .view .controls .load-spinner {
102
+ float: left;
103
+ margin: 1em;
104
+ }
105
+ .cffrtb-list .title .edit {
106
+ position: absolute;
107
+ overflow: hidden;
108
+ background: #fff;
109
+ width: 0;
110
+ top: 0;
111
+ left: 0;
112
+ -webkit-transition: width 0.3s ease-in-out;
113
+ -moz-transition: width 0.3s ease-in-out;
114
+ -ms-transition: width 0.3s ease-in-out;
115
+ -o-transition: width 0.3s ease-in-out;
116
+ transition: width 0.3s ease-in-out;
117
+ }
118
+ .cffrtb-list .title .edit input {
119
+ box-shadow: none;
120
+ margin: 1em;
121
+ padding: 0;
122
+ font-size: 13px;
123
+ line-height: 1.4em;
124
+ border: none;
125
+ border-bottom: 1px solid #aaa;
126
+ }
127
+ .cffrtb-list .title .edit .controls {
128
+ opacity: 0;
129
+ -webkit-transition: opacity 0.6s ease-in-out;
130
+ -moz-transition: opacity 0.6s ease-in-out;
131
+ -ms-transition: opacity 0.6s ease-in-out;
132
+ -o-transition: opacity 0.6s ease-in-out;
133
+ transition: opacity 0.6s ease-in-out;
134
+ }
135
+ .cffrtb-list .title .controls,
136
+ .cffrtb-list .title .status {
137
+ position: absolute;
138
+ top: 0;
139
+ right: 0;
140
+ display: none;
141
+ }
142
+ .cffrtb-list .title .controls {
143
+ display: block;
144
+ }
145
+ .cffrtb-list .title .controls a {
146
+ display: block;
147
+ float: left;
148
+ padding: 1em;
149
+ margin-left: 1px;
150
+ text-decoration: none;
151
+ background: #0073aa;
152
+ color: #fff;
153
+ transition: none;
154
+ }
155
+ .cffrtb-list .title .controls a:hover,
156
+ .cffrtb-list .title .controls a:active,
157
+ .cffrtb-list .title .controls a:focus {
158
+ background: #00b9eb;
159
+ box-shadow: none;
160
+ }
161
+ .cffrtb-list .title .controls a:active {
162
+ background: #fff;
163
+ color: #0073aa;
164
+ }
165
+ .cffrtb-list .title .controls a.save {
166
+ background: #fff;
167
+ color: #0073aa;
168
+ }
169
+ .cffrtb-list .title .controls a.save:active,
170
+ .cffrtb-list .title .controls a.save:focus {
171
+ color: #00b9eb;
172
+ }
173
+ .cffrtb-list .title .status {
174
+ padding: 1em;
175
+ }
176
+ .cffrtb-list .title .status span {
177
+ display: block;
178
+ text-decoration: none;
179
+ color: #777;
180
+ }
181
+ .cffrtb-list .title.editing {
182
+ border-color: #fff;
183
+ border-radius: 4px;
184
+ box-shadow: 0 0 3px rgba(0, 0, 0, 0.2);
185
+ }
186
+ .cffrtb-list .title.editing .edit {
187
+ width: 100%;
188
+ }
189
+ .cffrtb-list .title.editing .edit .controls {
190
+ opacity: 1;
191
+ }
192
+ .cffrtb-list .title.saving .controls {
193
+ display: none;
194
+ }
195
+ .cffrtb-list .title.saving .status {
196
+ display: block;
197
+ }
198
+ .cffrtb-list .fieldset > .title {
199
+ background: #d54e21;
200
+ border: none;
201
+ color: #fff;
202
+ }
203
+ .cffrtb-list .fieldset > .title .view .controls a {
204
+ background: #933617;
205
+ }
206
+ .cffrtb-list .fieldset > .title .view .controls a:hover,
207
+ .cffrtb-list .fieldset > .title .view .controls a:focus {
208
+ background: #e67f5d;
209
+ }
210
+ .cffrtb-list .fieldset > .title .view .controls a:active {
211
+ background: #fff;
212
+ color: #d54e21;
213
+ }
214
+ .cffrtb-list .cffrtb-list-placeholder {
215
+ height: 1.4em;
216
+ padding: 1em;
217
+ margin-bottom: 30px;
218
+ border: 1px dashed #D1DDE2;
219
+ background: #fff;
220
+ }
221
+ .cffrtb-list .fields {
222
+ min-height: 3.4em;
223
+ }
224
+ #cffrtb-editor .add-field {
225
+ display: block;
226
+ line-height: 1.4em;
227
+ text-align: center;
228
+ text-decoration: none;
229
+ padding: 1em;
230
+ background: #fff;
231
+ border: 1px dashed #b2c6ce;
232
+ opacity: 0.7;
233
+ }
234
+ #cffrtb-editor .add-field:hover,
235
+ #cffrtb-editor .add-field:focus {
236
+ color: #fff;
237
+ background: #0073aa;
238
+ opacity: 1;
239
+ border-color: transparent;
240
+ }
241
+ #cffrtb-editor .add-field:active {
242
+ background: #00b9eb;
243
+ }
244
+ #cffrtb-disabled h3 {
245
+ border-bottom: 1px solid #ddd;
246
+ padding-bottom: 0.5em;
247
+ color: #777;
248
+ }
249
+ #cffrtb-disabled .field,
250
+ #cffrtb-disabled .fieldset {
251
+ min-width: 20em;
252
+ max-width: 20em;
253
+ opacity: 0.7;
254
+ display: inline-block;
255
+ margin-right: 1em;
256
+ }
257
+ #cffrtb-disabled .field:hover,
258
+ #cffrtb-disabled .fieldset:hover,
259
+ #cffrtb-disabled .field:focus,
260
+ #cffrtb-disabled .fieldset:focus {
261
+ opacity: 1;
262
+ }
263
+ #cffrtb-disabled .field .title,
264
+ #cffrtb-disabled .fieldset .title {
265
+ border-color: #aaadb1;
266
+ background: #ecedee;
267
+ }
268
+ #cffrtb-disabled .field .controls a,
269
+ #cffrtb-disabled .fieldset .controls a {
270
+ background: #82878c;
271
+ }
272
+ #cffrtb-disabled .field .controls a:hover,
273
+ #cffrtb-disabled .fieldset .controls a:hover,
274
+ #cffrtb-disabled .field .controls a:active,
275
+ #cffrtb-disabled .fieldset .controls a:active,
276
+ #cffrtb-disabled .field .controls a:focus,
277
+ #cffrtb-disabled .fieldset .controls a:focus {
278
+ background: #aaadb1;
279
+ }
280
+ #cffrtb-disabled .field .controls a:active,
281
+ #cffrtb-disabled .fieldset .controls a:active {
282
+ color: #82878c;
283
+ }
284
+ #cffrtb-disabled .fieldset .title {
285
+ color: #444;
286
+ }
287
+ #cffrtb-disabled .fieldset .title .view .controls a {
288
+ background: #82878c;
289
+ }
290
+ #cffrtb-disabled .fieldset .title .view .controls a:hover,
291
+ #cffrtb-disabled .fieldset .title .view .controls a:active,
292
+ #cffrtb-disabled .fieldset .title .view .controls a:focus {
293
+ background: #aaadb1;
294
+ }
295
+ #cffrtb-disabled .fieldset .title .view .controls a:active {
296
+ color: #82878c;
297
+ }
298
+ #cffrtb-disabled .reset {
299
+ opacity: 0;
300
+ display: hidden;
301
+ -webkit-transition: opacity 0.3s ease-in-out;
302
+ -moz-transition: opacity 0.3s ease-in-out;
303
+ -ms-transition: opacity 0.3s ease-in-out;
304
+ -o-transition: opacity 0.3s ease-in-out;
305
+ transition: opacity 0.3s ease-in-out;
306
+ }
307
+ #cffrtb-disabled .is-visible {
308
+ display: block;
309
+ opacity: 1;
310
+ }
311
+ #cffrtb-disabled .learn-more {
312
+ line-height: 26px;
313
+ margin-left: 1em;
314
+ }
315
+ #cffrtb-disabled .description {
316
+ margin: 1em 0;
317
+ max-width: 20em;
318
+ }
319
+ #cffrtb-disabled .no-disabled-fields {
320
+ margin-bottom: 30px;
321
+ padding-bottom: 30px;
322
+ }
323
+ #cffrtb-disabled .learn-more-details {
324
+ max-height: 0;
325
+ overflow: hidden;
326
+ -webkit-transition: max-height 0.5s ease-in-out;
327
+ -moz-transition: max-height 0.5s ease-in-out;
328
+ -ms-transition: max-height 0.5s ease-in-out;
329
+ -o-transition: max-height 0.5s ease-in-out;
330
+ transition: max-height 0.5s ease-in-out;
331
+ }
332
+ #cffrtb-disabled .learn-more-details.is-visible {
333
+ max-height: 15em;
334
+ }
335
+ .rtb-admin-modal {
336
+ position: fixed;
337
+ top: 0;
338
+ left: 0;
339
+ width: 100%;
340
+ height: 100%;
341
+ background: rgba(0, 0, 0, 0.8);
342
+ z-index: 3;
343
+ overflow-y: auto;
344
+ cursor: pointer;
345
+ visibility: hidden;
346
+ opacity: 0;
347
+ -webkit-transition: opacity 0.3s 0, visibility 0 0.3s;
348
+ -moz-transition: opacity 0.3s 0, visibility 0 0.3s;
349
+ transition: opacity 0.3s 0, visibility 0 0.3s;
350
+ }
351
+ .rtb-admin-modal.is-visible {
352
+ visibility: visible;
353
+ opacity: 1;
354
+ -webkit-transition: opacity 0.3s 0, visibility 0 0;
355
+ -moz-transition: opacity 0.3s 0, visibility 0 0;
356
+ transition: opacity 0.3s 0, visibility 0 0;
357
+ }
358
+ .rtb-admin-modal.is-visible .rtb-container {
359
+ -webkit-transform: translateY(0);
360
+ -moz-transform: translateY(0);
361
+ -ms-transform: translateY(0);
362
+ -o-transform: translateY(0);
363
+ transform: translateY(0);
364
+ }
365
+ .rtb-admin-modal .rtb-container {
366
+ position: relative;
367
+ width: 90%;
368
+ max-width: 20em;
369
+ padding: 2em;
370
+ background: #FFF;
371
+ margin: 3em auto 4em;
372
+ cursor: auto;
373
+ border-radius: 0.25em;
374
+ -webkit-transform: translateY(-30px);
375
+ -moz-transform: translateY(-30px);
376
+ -ms-transform: translateY(-30px);
377
+ -o-transform: translateY(-30px);
378
+ transform: translateY(-30px);
379
+ -webkit-transition-property: -webkit-transform;
380
+ -moz-transition-property: -moz-transform;
381
+ transition-property: transform;
382
+ -webkit-transition-duration: 0.3s;
383
+ -moz-transition-duration: 0.3s;
384
+ transition-duration: 0.3s;
385
+ }
386
+ /* Hide the outer scrollbar when the modal is open */
387
+ .rtb-hide-body-scroll {
388
+ overflow: hidden !important;
389
+ }
390
+ #cffrtb-field-editor h2 {
391
+ margin: 0;
392
+ }
393
+ #cffrtb-field-editor a {
394
+ text-decoration: none;
395
+ }
396
+ #cffrtb-field-editor label {
397
+ color: #777;
398
+ font-style: italic;
399
+ }
400
+ #cffrtb-field-editor .type {
401
+ margin: 2em 0 0;
402
+ }
403
+ #cffrtb-field-editor .type label {
404
+ display: block;
405
+ }
406
+ #cffrtb-field-editor .type .selector {
407
+ background: #ddd;
408
+ border: 1px solid #ddd;
409
+ border-radius: 4px;
410
+ }
411
+ #cffrtb-field-editor .type ul {
412
+ text-align: center;
413
+ }
414
+ #cffrtb-field-editor .types {
415
+ margin: 0;
416
+ background: #fff;
417
+ border-top-left-radius: 4px;
418
+ border-top-right-radius: 4px;
419
+ }
420
+ #cffrtb-field-editor .types li {
421
+ display: inline-block;
422
+ margin: 0;
423
+ }
424
+ #cffrtb-field-editor .types li a {
425
+ display: block;
426
+ padding: 0.5em 1em;
427
+ }
428
+ #cffrtb-field-editor .types li a.current {
429
+ font-weight: 600;
430
+ color: #666;
431
+ position: relative;
432
+ }
433
+ #cffrtb-field-editor .types li a.current:after {
434
+ content: ' ';
435
+ position: absolute;
436
+ left: 50%;
437
+ margin-left: -6px;
438
+ width: 0;
439
+ height: 0;
440
+ border-left: 6px solid transparent;
441
+ border-right: 6px solid transparent;
442
+ border-bottom: 6px solid #ddd;
443
+ }
444
+ #cffrtb-field-editor .subtypes {
445
+ display: none;
446
+ margin: 0;
447
+ }
448
+ #cffrtb-field-editor .subtypes.current {
449
+ display: block;
450
+ }
451
+ #cffrtb-field-editor .subtypes li {
452
+ margin: 0;
453
+ display: inline-block;
454
+ }
455
+ #cffrtb-field-editor .subtypes li a {
456
+ display: block;
457
+ padding: 0.5em 1em;
458
+ }
459
+ #cffrtb-field-editor .subtypes li a.current {
460
+ font-weight: 600;
461
+ color: #666;
462
+ }
463
+ #cffrtb-field-editor .settings {
464
+ margin-top: 2em;
465
+ }
466
+ #cffrtb-field-editor .settings .item {
467
+ margin: 0 0 2em;
468
+ }
469
+ #cffrtb-field-editor .settings label,
470
+ #cffrtb-field-editor .settings input {
471
+ display: block;
472
+ }
473
+ #cffrtb-field-editor .settings input {
474
+ width: 100%;
475
+ }
476
+ #cffrtb-field-editor .settings-panel {
477
+ height: auto;
478
+ overflow: hidden;
479
+ max-height: 0;
480
+ -webkit-transition: max-height 0.6s ease-in-out;
481
+ -moz-transition: max-height 0.6s ease-in-out;
482
+ -ms-transition: max-height 0.6s ease-in-out;
483
+ -o-transition: max-height 0.6s ease-in-out;
484
+ transition: max-height 0.6s ease-in-out;
485
+ }
486
+ #cffrtb-field-editor .settings-panel.current {
487
+ overflow: visible;
488
+ max-height: 40em;
489
+ }
490
+ #cffrtb-field-editor .settings-panel.options .add {
491
+ position: relative;
492
+ }
493
+ #cffrtb-field-editor .settings-panel.options .add a {
494
+ position: absolute;
495
+ top: 0;
496
+ right: 0;
497
+ padding: 4px;
498
+ }
499
+ #cffrtb-field-editor .settings-panel.options .add input {
500
+ padding-right: 4em;
501
+ }
502
+ #cffrtb-field-editor .settings-panel.options .options {
503
+ margin: 1em 0 0;
504
+ max-height: 325px;
505
+ }
506
+ #cffrtb-field-editor .settings-panel.options .options.scroll {
507
+ overflow-y: scroll;
508
+ }
509
+ #cffrtb-field-editor .settings-panel.options .options li {
510
+ margin: 0.5em 0 0;
511
+ padding: 0.25em 0.5em;
512
+ height: 1.4em;
513
+ background: #eee;
514
+ border: 1px solid #ddd;
515
+ border-radius: 4px;
516
+ cursor: pointer;
517
+ cursor: hand;
518
+ }
519
+ #cffrtb-field-editor .settings-panel.options .options li.cffrtb-editor-options-placeholder {
520
+ background: #fff;
521
+ border: 1px dashed #aaa;
522
+ }
523
+ #cffrtb-field-editor .settings-panel.options .options a {
524
+ display: inline-block;
525
+ color: #a00;
526
+ }
527
+ #cffrtb-field-editor .settings-panel.options .options a:hover,
528
+ #cffrtb-field-editor .settings-panel.options .options a:focus {
529
+ color: red;
530
+ }
531
+ #cffrtb-field-editor .required {
532
+ padding: 1em 0;
533
+ }
534
+ #cffrtb-field-editor .actions {
535
+ padding: 1em 0 0;
536
+ }
537
+ #cffrtb-field-editor .actions .save {
538
+ vertical-align: top;
539
+ }
540
+ #cffrtb-field-editor .actions .save.fieldset {
541
+ background: #d54e21;
542
+ color: #fff;
543
+ box-shadow: inset 0 1px 0 #e67f5d, 0 1px 0 rgba(0, 0, 0, 0.08);
544
+ border-color: #933617;
545
+ text-shadow: none;
546
+ }
547
+ #cffrtb-field-editor .actions .status {
548
+ display: none;
549
+ padding: 4px;
550
+ height: 14px;
551
+ }
552
+ #cffrtb-field-editor .actions.working .status {
553
+ display: inline-block;
554
+ }
555
+ #cffrtb-field-editor > .fieldset .type,
556
+ #cffrtb-field-editor > .fieldset .settings-panel,
557
+ #cffrtb-field-editor > .fieldset .required {
558
+ display: none;
559
+ }
560
+ #cffrtb-field-editor-option .fieldset.button {
561
+ background: #d54e21;
562
+ color: #fff;
563
+ box-shadow: inset 0 1px 0 #e67f5d, 0 1px 0 rgba(0, 0, 0, 0.08);
564
+ border-color: #933617;
565
+ margin-top: 2em;
566
+ }
567
+ #cffrtb-field-editor-option .option p {
568
+ margin-bottom: 0;
569
+ }
570
+ #rtb-error-modal .rtb-error-msg {
571
+ margin-bottom: 1em;
572
+ }
573
+ @media (min-width: 767px) {
574
+ .cffrtb-lft {
575
+ width: 30em;
576
+ float: left;
577
+ }
578
+ .cffrtb-rgt {
579
+ margin-left: 33em;
580
+ max-width: 100%;
581
+ }
582
+ }
assets/css/spectrum.css ADDED
@@ -0,0 +1,507 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /***
2
+ Spectrum Colorpicker v1.7.1
3
+ https://github.com/bgrins/spectrum
4
+ Author: Brian Grinstead
5
+ License: MIT
6
+ ***/
7
+
8
+ .sp-container {
9
+ position:absolute;
10
+ top:0;
11
+ left:0;
12
+ display:inline-block;
13
+ *display: inline;
14
+ *zoom: 1;
15
+ /* https://github.com/bgrins/spectrum/issues/40 */
16
+ z-index: 9999994;
17
+ overflow: hidden;
18
+ }
19
+ .sp-container.sp-flat {
20
+ position: relative;
21
+ }
22
+
23
+ /* Fix for * { box-sizing: border-box; } */
24
+ .sp-container,
25
+ .sp-container * {
26
+ -webkit-box-sizing: content-box;
27
+ -moz-box-sizing: content-box;
28
+ box-sizing: content-box;
29
+ }
30
+
31
+ /* http://ansciath.tumblr.com/post/7347495869/css-aspect-ratio */
32
+ .sp-top {
33
+ position:relative;
34
+ width: 100%;
35
+ display:inline-block;
36
+ }
37
+ .sp-top-inner {
38
+ position:absolute;
39
+ top:0;
40
+ left:0;
41
+ bottom:0;
42
+ right:0;
43
+ }
44
+ .sp-color {
45
+ position: absolute;
46
+ top:0;
47
+ left:0;
48
+ bottom:0;
49
+ right:20%;
50
+ }
51
+ .sp-hue {
52
+ position: absolute;
53
+ top:0;
54
+ right:0;
55
+ bottom:0;
56
+ left:84%;
57
+ height: 100%;
58
+ }
59
+
60
+ .sp-clear-enabled .sp-hue {
61
+ top:33px;
62
+ height: 77.5%;
63
+ }
64
+
65
+ .sp-fill {
66
+ padding-top: 80%;
67
+ }
68
+ .sp-sat, .sp-val {
69
+ position: absolute;
70
+ top:0;
71
+ left:0;
72
+ right:0;
73
+ bottom:0;
74
+ }
75
+
76
+ .sp-alpha-enabled .sp-top {
77
+ margin-bottom: 18px;
78
+ }
79
+ .sp-alpha-enabled .sp-alpha {
80
+ display: block;
81
+ }
82
+ .sp-alpha-handle {
83
+ position:absolute;
84
+ top:-4px;
85
+ bottom: -4px;
86
+ width: 6px;
87
+ left: 50%;
88
+ cursor: pointer;
89
+ border: 1px solid black;
90
+ background: white;
91
+ opacity: .8;
92
+ }
93
+ .sp-alpha {
94
+ display: none;
95
+ position: absolute;
96
+ bottom: -14px;
97
+ right: 0;
98
+ left: 0;
99
+ height: 8px;
100
+ }
101
+ .sp-alpha-inner {
102
+ border: solid 1px #333;
103
+ }
104
+
105
+ .sp-clear {
106
+ display: none;
107
+ }
108
+
109
+ .sp-clear.sp-clear-display {
110
+ background-position: center;
111
+ }
112
+
113
+ .sp-clear-enabled .sp-clear {
114
+ display: block;
115
+ position:absolute;
116
+ top:0px;
117
+ right:0;
118
+ bottom:0;
119
+ left:84%;
120
+ height: 28px;
121
+ }
122
+
123
+ /* Don't allow text selection */
124
+ .sp-container, .sp-replacer, .sp-preview, .sp-dragger, .sp-slider, .sp-alpha, .sp-clear, .sp-alpha-handle, .sp-container.sp-dragging .sp-input, .sp-container button {
125
+ -webkit-user-select:none;
126
+ -moz-user-select: -moz-none;
127
+ -o-user-select:none;
128
+ user-select: none;
129
+ }
130
+
131
+ .sp-container.sp-input-disabled .sp-input-container {
132
+ display: none;
133
+ }
134
+ .sp-container.sp-buttons-disabled .sp-button-container {
135
+ display: none;
136
+ }
137
+ .sp-container.sp-palette-buttons-disabled .sp-palette-button-container {
138
+ display: none;
139
+ }
140
+ .sp-palette-only .sp-picker-container {
141
+ display: none;
142
+ }
143
+ .sp-palette-disabled .sp-palette-container {
144
+ display: none;
145
+ }
146
+
147
+ .sp-initial-disabled .sp-initial {
148
+ display: none;
149
+ }
150
+
151
+
152
+ /* Gradients for hue, saturation and value instead of images. Not pretty... but it works */
153
+ .sp-sat {
154
+ background-image: -webkit-gradient(linear, 0 0, 100% 0, from(#FFF), to(rgba(204, 154, 129, 0)));
155
+ background-image: -webkit-linear-gradient(left, #FFF, rgba(204, 154, 129, 0));
156
+ background-image: -moz-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
157
+ background-image: -o-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
158
+ background-image: -ms-linear-gradient(left, #fff, rgba(204, 154, 129, 0));
159
+ background-image: linear-gradient(to right, #fff, rgba(204, 154, 129, 0));
160
+ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr=#FFFFFFFF, endColorstr=#00CC9A81)";
161
+ filter : progid:DXImageTransform.Microsoft.gradient(GradientType = 1, startColorstr='#FFFFFFFF', endColorstr='#00CC9A81');
162
+ }
163
+ .sp-val {
164
+ background-image: -webkit-gradient(linear, 0 100%, 0 0, from(#000000), to(rgba(204, 154, 129, 0)));
165
+ background-image: -webkit-linear-gradient(bottom, #000000, rgba(204, 154, 129, 0));
166
+ background-image: -moz-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
167
+ background-image: -o-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
168
+ background-image: -ms-linear-gradient(bottom, #000, rgba(204, 154, 129, 0));
169
+ background-image: linear-gradient(to top, #000, rgba(204, 154, 129, 0));
170
+ -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00CC9A81, endColorstr=#FF000000)";
171
+ filter : progid:DXImageTransform.Microsoft.gradient(startColorstr='#00CC9A81', endColorstr='#FF000000');
172
+ }
173
+
174
+ .sp-hue {
175
+ background: -moz-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
176
+ background: -ms-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
177
+ background: -o-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
178
+ background: -webkit-gradient(linear, left top, left bottom, from(#ff0000), color-stop(0.17, #ffff00), color-stop(0.33, #00ff00), color-stop(0.5, #00ffff), color-stop(0.67, #0000ff), color-stop(0.83, #ff00ff), to(#ff0000));
179
+ background: -webkit-linear-gradient(top, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
180
+ background: linear-gradient(to bottom, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
181
+ }
182
+
183
+ /* IE filters do not support multiple color stops.
184
+ Generate 6 divs, line them up, and do two color gradients for each.
185
+ Yes, really.
186
+ */
187
+ .sp-1 {
188
+ height:17%;
189
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0000', endColorstr='#ffff00');
190
+ }
191
+ .sp-2 {
192
+ height:16%;
193
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffff00', endColorstr='#00ff00');
194
+ }
195
+ .sp-3 {
196
+ height:17%;
197
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ff00', endColorstr='#00ffff');
198
+ }
199
+ .sp-4 {
200
+ height:17%;
201
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#00ffff', endColorstr='#0000ff');
202
+ }
203
+ .sp-5 {
204
+ height:16%;
205
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0000ff', endColorstr='#ff00ff');
206
+ }
207
+ .sp-6 {
208
+ height:17%;
209
+ filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff00ff', endColorstr='#ff0000');
210
+ }
211
+
212
+ .sp-hidden {
213
+ display: none !important;
214
+ }
215
+
216
+ /* Clearfix hack */
217
+ .sp-cf:before, .sp-cf:after { content: ""; display: table; }
218
+ .sp-cf:after { clear: both; }
219
+ .sp-cf { *zoom: 1; }
220
+
221
+ /* Mobile devices, make hue slider bigger so it is easier to slide */
222
+ @media (max-device-width: 480px) {
223
+ .sp-color { right: 40%; }
224
+ .sp-hue { left: 63%; }
225
+ .sp-fill { padding-top: 60%; }
226
+ }
227
+ .sp-dragger {
228
+ border-radius: 5px;
229
+ height: 5px;
230
+ width: 5px;
231
+ border: 1px solid #fff;
232
+ background: #000;
233
+ cursor: pointer;
234
+ position:absolute;
235
+ top:0;
236
+ left: 0;
237
+ }
238
+ .sp-slider {
239
+ position: absolute;
240
+ top:0;
241
+ cursor:pointer;
242
+ height: 3px;
243
+ left: -1px;
244
+ right: -1px;
245
+ border: 1px solid #000;
246
+ background: white;
247
+ opacity: .8;
248
+ }
249
+
250
+ /*
251
+ Theme authors:
252
+ Here are the basic themeable display options (colors, fonts, global widths).
253
+ See http://bgrins.github.io/spectrum/themes/ for instructions.
254
+ */
255
+
256
+ .sp-container {
257
+ border-radius: 0;
258
+ background-color: #ECECEC;
259
+ border: solid 1px #f0c49B;
260
+ padding: 0;
261
+ }
262
+ .sp-container, .sp-container button, .sp-container input, .sp-color, .sp-hue, .sp-clear {
263
+ font: normal 12px "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
264
+ -webkit-box-sizing: border-box;
265
+ -moz-box-sizing: border-box;
266
+ -ms-box-sizing: border-box;
267
+ box-sizing: border-box;
268
+ }
269
+ .sp-top {
270
+ margin-bottom: 3px;
271
+ }
272
+ .sp-color, .sp-hue, .sp-clear {
273
+ border: solid 1px #666;
274
+ }
275
+
276
+ /* Input */
277
+ .sp-input-container {
278
+ float:right;
279
+ width: 100px;
280
+ margin-bottom: 4px;
281
+ }
282
+ .sp-initial-disabled .sp-input-container {
283
+ width: 100%;
284
+ }
285
+ .sp-input {
286
+ font-size: 12px !important;
287
+ border: 1px inset;
288
+ padding: 4px 5px;
289
+ margin: 0;
290
+ width: 100%;
291
+ background:transparent;
292
+ border-radius: 3px;
293
+ color: #222;
294
+ }
295
+ .sp-input:focus {
296
+ border: 1px solid orange;
297
+ }
298
+ .sp-input.sp-validation-error {
299
+ border: 1px solid red;
300
+ background: #fdd;
301
+ }
302
+ .sp-picker-container , .sp-palette-container {
303
+ float:left;
304
+ position: relative;
305
+ padding: 10px;
306
+ padding-bottom: 300px;
307
+ margin-bottom: -290px;
308
+ }
309
+ .sp-picker-container {
310
+ width: 172px;
311
+ border-left: solid 1px #fff;
312
+ }
313
+
314
+ /* Palettes */
315
+ .sp-palette-container {
316
+ border-right: solid 1px #ccc;
317
+ }
318
+
319
+ .sp-palette-only .sp-palette-container {
320
+ border: 0;
321
+ }
322
+
323
+ .sp-palette .sp-thumb-el {
324
+ display: block;
325
+ position:relative;
326
+ float:left;
327
+ width: 24px;
328
+ height: 15px;
329
+ margin: 3px;
330
+ cursor: pointer;
331
+ border:solid 2px transparent;
332
+ }
333
+ .sp-palette .sp-thumb-el:hover, .sp-palette .sp-thumb-el.sp-thumb-active {
334
+ border-color: orange;
335
+ }
336
+ .sp-thumb-el {
337
+ position:relative;
338
+ }
339
+
340
+ /* Initial */
341
+ .sp-initial {
342
+ float: left;
343
+ border: solid 1px #333;
344
+ }
345
+ .sp-initial span {
346
+ width: 30px;
347
+ height: 25px;
348
+ border:none;
349
+ display:block;
350
+ float:left;
351
+ margin:0;
352
+ }
353
+
354
+ .sp-initial .sp-clear-display {
355
+ background-position: center;
356
+ }
357
+
358
+ /* Buttons */
359
+ .sp-palette-button-container,
360
+ .sp-button-container {
361
+ float: right;
362
+ }
363
+
364
+ /* Replacer (the little preview div that shows up instead of the <input>) */
365
+ .sp-replacer {
366
+ margin:0;
367
+ overflow:hidden;
368
+ cursor:pointer;
369
+ padding: 4px;
370
+ display:inline-block;
371
+ *zoom: 1;
372
+ *display: inline;
373
+ border: solid 1px #91765d;
374
+ background: #eee;
375
+ color: #333;
376
+ vertical-align: middle;
377
+ }
378
+ .sp-replacer:hover, .sp-replacer.sp-active {
379
+ border-color: #F0C49B;
380
+ color: #111;
381
+ }
382
+ .sp-replacer.sp-disabled {
383
+ cursor:default;
384
+ border-color: silver;
385
+ color: silver;
386
+ }
387
+ .sp-dd {
388
+ padding: 2px 0;
389
+ height: 16px;
390
+ line-height: 16px;
391
+ float:left;
392
+ font-size:10px;
393
+ }
394
+ .sp-preview {
395
+ position:relative;
396
+ width:25px;
397
+ height: 20px;
398
+ border: solid 1px #222;
399
+ margin-right: 5px;
400
+ float:left;
401
+ z-index: 0;
402
+ }
403
+
404
+ .sp-palette {
405
+ *width: 220px;
406
+ max-width: 220px;
407
+ }
408
+ .sp-palette .sp-thumb-el {
409
+ width:16px;
410
+ height: 16px;
411
+ margin:2px 1px;
412
+ border: solid 1px #d0d0d0;
413
+ }
414
+
415
+ .sp-container {
416
+ padding-bottom:0;
417
+ }
418
+
419
+
420
+ /* Buttons: http://hellohappy.org/css3-buttons/ */
421
+ .sp-container button {
422
+ background-color: #eeeeee;
423
+ background-image: -webkit-linear-gradient(top, #eeeeee, #cccccc);
424
+ background-image: -moz-linear-gradient(top, #eeeeee, #cccccc);
425
+ background-image: -ms-linear-gradient(top, #eeeeee, #cccccc);
426
+ background-image: -o-linear-gradient(top, #eeeeee, #cccccc);
427
+ background-image: linear-gradient(to bottom, #eeeeee, #cccccc);
428
+ border: 1px solid #ccc;
429
+ border-bottom: 1px solid #bbb;
430
+ border-radius: 3px;
431
+ color: #333;
432
+ font-size: 14px;
433
+ line-height: 1;
434
+ padding: 5px 4px;
435
+ text-align: center;
436
+ text-shadow: 0 1px 0 #eee;
437
+ vertical-align: middle;
438
+ }
439
+ .sp-container button:hover {
440
+ background-color: #dddddd;
441
+ background-image: -webkit-linear-gradient(top, #dddddd, #bbbbbb);
442
+ background-image: -moz-linear-gradient(top, #dddddd, #bbbbbb);
443
+ background-image: -ms-linear-gradient(top, #dddddd, #bbbbbb);
444
+ background-image: -o-linear-gradient(top, #dddddd, #bbbbbb);
445
+ background-image: linear-gradient(to bottom, #dddddd, #bbbbbb);
446
+ border: 1px solid #bbb;
447
+ border-bottom: 1px solid #999;
448
+ cursor: pointer;
449
+ text-shadow: 0 1px 0 #ddd;
450
+ }
451
+ .sp-container button:active {
452
+ border: 1px solid #aaa;
453
+ border-bottom: 1px solid #888;
454
+ -webkit-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
455
+ -moz-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
456
+ -ms-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
457
+ -o-box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
458
+ box-shadow: inset 0 0 5px 2px #aaaaaa, 0 1px 0 0 #eeeeee;
459
+ }
460
+ .sp-cancel {
461
+ font-size: 11px;
462
+ color: #d93f3f !important;
463
+ margin:0;
464
+ padding:2px;
465
+ margin-right: 5px;
466
+ vertical-align: middle;
467
+ text-decoration:none;
468
+
469
+ }
470
+ .sp-cancel:hover {
471
+ color: #d93f3f !important;
472
+ text-decoration: underline;
473
+ }
474
+
475
+
476
+ .sp-palette span:hover, .sp-palette span.sp-thumb-active {
477
+ border-color: #000;
478
+ }
479
+
480
+ .sp-preview, .sp-alpha, .sp-thumb-el {
481
+ position:relative;
482
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAIAAADZF8uwAAAAGUlEQVQYV2M4gwH+YwCGIasIUwhT25BVBADtzYNYrHvv4gAAAABJRU5ErkJggg==);
483
+ }
484
+ .sp-preview-inner, .sp-alpha-inner, .sp-thumb-inner {
485
+ display:block;
486
+ position:absolute;
487
+ top:0;left:0;bottom:0;right:0;
488
+ }
489
+
490
+ .sp-palette .sp-thumb-inner {
491
+ background-position: 50% 50%;
492
+ background-repeat: no-repeat;
493
+ }
494
+
495
+ .sp-palette .sp-thumb-light.sp-thumb-active .sp-thumb-inner {
496
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAIVJREFUeNpiYBhsgJFMffxAXABlN5JruT4Q3wfi/0DsT64h8UD8HmpIPCWG/KemIfOJCUB+Aoacx6EGBZyHBqI+WsDCwuQ9mhxeg2A210Ntfo8klk9sOMijaURm7yc1UP2RNCMbKE9ODK1HM6iegYLkfx8pligC9lCD7KmRof0ZhjQACDAAceovrtpVBRkAAAAASUVORK5CYII=);
497
+ }
498
+
499
+ .sp-palette .sp-thumb-dark.sp-thumb-active .sp-thumb-inner {
500
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAadEVYdFNvZnR3YXJlAFBhaW50Lk5FVCB2My41LjEwMPRyoQAAAMdJREFUOE+tkgsNwzAMRMugEAahEAahEAZhEAqlEAZhEAohEAYh81X2dIm8fKpEspLGvudPOsUYpxE2BIJCroJmEW9qJ+MKaBFhEMNabSy9oIcIPwrB+afvAUFoK4H0tMaQ3XtlrggDhOVVMuT4E5MMG0FBbCEYzjYT7OxLEvIHQLY2zWwQ3D+9luyOQTfKDiFD3iUIfPk8VqrKjgAiSfGFPecrg6HN6m/iBcwiDAo7WiBeawa+Kwh7tZoSCGLMqwlSAzVDhoK+6vH4G0P5wdkAAAAASUVORK5CYII=);
501
+ }
502
+
503
+ .sp-clear-display {
504
+ background-repeat:no-repeat;
505
+ background-position: center;
506
+ background-image: url(data:image/gif;base64,R0lGODlhFAAUAPcAAAAAAJmZmZ2dnZ6enqKioqOjo6SkpKWlpaampqenp6ioqKmpqaqqqqurq/Hx8fLy8vT09PX19ff39/j4+Pn5+fr6+vv7+wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAAAUABQAAAihAP9FoPCvoMGDBy08+EdhQAIJCCMybCDAAYUEARBAlFiQQoMABQhKUJBxY0SPICEYHBnggEmDKAuoPMjS5cGYMxHW3IiT478JJA8M/CjTZ0GgLRekNGpwAsYABHIypcAgQMsITDtWJYBR6NSqMico9cqR6tKfY7GeBCuVwlipDNmefAtTrkSzB1RaIAoXodsABiZAEFB06gIBWC1mLVgBa0AAOw==);
507
+ }
assets/img/dash-asset-badge.png ADDED
Binary file
assets/img/dash-asset-checkmark.png ADDED
Binary file
assets/img/dash-asset-key.png ADDED
Binary file
assets/img/dash-asset-stars.png ADDED
Binary file
assets/img/ewd-support-icon-documentation.png ADDED
Binary file
assets/img/ewd-support-icon-faqs.png ADDED
Binary file
assets/img/ewd-support-icon-forum.png ADDED
Binary file
assets/img/ewd-support-icon-youtube.png ADDED
Binary file
assets/img/fivestartextlogo.png ADDED
Binary file
assets/img/fivestartextlogowithstar.png ADDED
Binary file
assets/img/options-asset-lock.png ADDED
Binary file
assets/img/options-asset-star.png ADDED
Binary file
assets/js/admin-rtb-welcome-screen.js ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery('.rtb-welcome-screen-box h2').on('click', function() {
3
+ var section = jQuery(this).parent().data('screen');
4
+ rtb_toggle_section(section);
5
+ });
6
+
7
+ jQuery('.rtb-welcome-screen-next-button').on('click', function() {
8
+ var section = jQuery(this).data('nextaction');
9
+ rtb_toggle_section(section);
10
+ });
11
+
12
+ jQuery('.rtb-welcome-screen-previous-button').on('click', function() {
13
+ var section = jQuery(this).data('previousaction');
14
+ rtb_toggle_section(section);
15
+ });
16
+
17
+ jQuery('.rtb-welcome-screen-add-reservations-page-button').on('click', function() {
18
+ var reservations_page_title = jQuery('.rtb-welcome-screen-add-reservations-page-name input').val();
19
+
20
+ var data = 'reservations_page_title=' + reservations_page_title + '&action=rtb_welcome_add_menu_page';
21
+ jQuery.post(ajaxurl, data, function(response) {});
22
+
23
+ var section = jQuery(this).data('nextaction');
24
+ rtb_toggle_section(section);
25
+ });
26
+
27
+ jQuery('.rtb-welcome-screen-save-schedule-open-button').on('click', function() {
28
+
29
+ var schedule_open = [];
30
+
31
+ jQuery('.sap-scheduler-rule').each(function() {
32
+ var weekdays ={};
33
+
34
+ jQuery(this).find('.sap-scheduler-weekdays input[type="checkbox"]').each(function() {
35
+ if ( jQuery(this).is(':checked') ) { weekdays[jQuery(this).data('day')] = "1" ; }
36
+ });
37
+
38
+ var start = jQuery(this).find('.sap-scheduler-time-input .start input').first().val();
39
+ var end = jQuery(this).find('.sap-scheduler-time-input .end input').first().val();
40
+
41
+ schedule_open.push({'weekdays': weekdays, 'time': {'start': start, 'end': end }});
42
+ });
43
+
44
+ var data = 'schedule_open=' + JSON.stringify(schedule_open) + '&action=rtb_welcome_set_schedule';
45
+ jQuery.post(ajaxurl, data, function(response) {});
46
+ });
47
+
48
+ jQuery('.rtb-welcome-screen-save-options-button').on('click', function() {
49
+ var party_size_min = jQuery('select[name="min-party-size"]').val();
50
+ var party_size = jQuery('select[name="party-size"]').val();
51
+ var early_bookings = jQuery('select[name="early-bookings"]').val();
52
+ var late_bookings = jQuery('select[name="late-bookings"]').val();
53
+ var time_interval = jQuery('select[name="time-interval"]').val();
54
+
55
+ var data = 'party_size_min=' + party_size_min + '&party_size=' + party_size + '&early_bookings=' + early_bookings + '&late_bookings=' + late_bookings + '&time_interval=' + time_interval + '&action=rtb_welcome_set_options';
56
+ jQuery.post(ajaxurl, data, function(response) {});
57
+ });
58
+ });
59
+
60
+ function rtb_toggle_section(page) {
61
+ jQuery('.rtb-welcome-screen-box').removeClass('rtb-welcome-screen-open');
62
+ jQuery('.rtb-welcome-screen-' + page).addClass('rtb-welcome-screen-open');
63
+ }
assets/js/admin-settings.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function() {
2
+ jQuery('.rtb-spectrum').spectrum({
3
+ showInput: true,
4
+ showInitial: true,
5
+ preferredFormat: "hex",
6
+ allowEmpty: true
7
+ });
8
+
9
+ jQuery('.rtb-spectrum').css('display', 'inline');
10
+
11
+ jQuery('.rtb-spectrum').on('change', function() {
12
+ if (jQuery(this).val() != "") {
13
+ jQuery(this).css('background', jQuery(this).val());
14
+ var rgb = RTB_hexToRgb(jQuery(this).val());
15
+ var Brightness = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
16
+ if (Brightness < 100) {jQuery(this).css('color', '#ffffff');}
17
+ else {jQuery(this).css('color', '#000000');}
18
+ }
19
+ else {
20
+ jQuery(this).css('background', 'none');
21
+ }
22
+ });
23
+
24
+ jQuery('.rtb-spectrum').each(function() {
25
+ if (jQuery(this).val() != "") {
26
+ jQuery(this).css('background', jQuery(this).val());
27
+ var rgb = RTB_hexToRgb(jQuery(this).val());
28
+ var Brightness = (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
29
+ if (Brightness < 100) {jQuery(this).css('color', '#ffffff');}
30
+ else {jQuery(this).css('color', '#000000');}
31
+ }
32
+ });
33
+ });
34
+
35
+ function RTB_hexToRgb(hex) {
36
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
37
+ return result ? {
38
+ r: parseInt(result[1], 16),
39
+ g: parseInt(result[2], 16),
40
+ b: parseInt(result[3], 16)
41
+ } : null;
42
+ }
assets/js/admin.js CHANGED
@@ -1,830 +1,1041 @@
1
- /* Javascript for Restaurant Reservations admin */
2
- jQuery(document).ready(function ($) {
3
-
4
- // Show/hide date filter in bookings list
5
- $( '#rtb-date-filter-link' ).click( function() {
6
- $( '#rtb-filters' ).toggleClass( 'date-filters-visible' );
7
- });
8
-
9
- // Add date picker to date filter in admin
10
- $( '#start-date, #end-date' ).each( function() {
11
- var input = $(this);
12
-
13
- input.pickadate({
14
- format: rtb_pickadate.date_format,
15
- formatSubmit: 'yyyy/mm/dd',
16
- hiddenName: true,
17
-
18
- onStart: function() {
19
- if ( input.val() !== '' ) {
20
- var date = new Date( input.val() );
21
- if ( Object.prototype.toString.call( date ) === "[object Date]" ) {
22
- this.set( 'select', date );
23
- }
24
- }
25
- }
26
- });
27
- });
28
-
29
- // Show or hide extra booking details in the bookings table
30
- $( '.rtb-show-details' ).click( function (e) {
31
- e.preventDefault();
32
- rtb_toggle_details_modal( true, $(this).siblings( '.rtb-details-data' ).html() );
33
- });
34
-
35
- // Register clicks on action links
36
- $( '#rtb-bookings-table tr .actions' ).click( function(e) {
37
-
38
- e.stopPropagation();
39
-
40
- var target = $(e.target);
41
- var action = target.data( 'action' );
42
-
43
- if ( !action ) {
44
- return;
45
- }
46
-
47
- var cell = target.parent().parent();
48
-
49
- if ( target.data( 'action' ) == 'edit' ) {
50
- rtb_booking_loading_spinner( true, cell );
51
- rtb_get_booking( target.data( 'id' ), cell );
52
-
53
- } else if ( target.data( 'action' ) == 'trash' ) {
54
- rtb_booking_loading_spinner( true, cell );
55
- rtb_trash_booking( target.data( 'id' ), cell );
56
-
57
- } else if ( target.data( 'action' ) == 'email') {
58
- rtb_toggle_email_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'name' ) );
59
-
60
- } else if ( target.data( 'action' ) == 'ban') {
61
- rtb_toggle_ban_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'ip' ) );
62
-
63
- } else if ( target.data( 'action' ) == 'delete') {
64
- rtb_toggle_delete_modal( true, target.data( 'id'), target.data( 'email' ) );
65
- }
66
-
67
- e.preventDefault();
68
- });
69
-
70
- // Show booking form modal
71
- $( '.add-booking' ).click( function( e ) {
72
- e.preventDefault();
73
- rtb_toggle_booking_form_modal( true );
74
- });
75
-
76
- // Show column configuration modal
77
- $( '.rtb-columns-button' ).click( function( e ) {
78
- e.preventDefault();
79
- rtb_toggle_column_modal( true );
80
- });
81
-
82
- /**
83
- * Show/hide loading spinner when edit/delete link clicked
84
- */
85
- function rtb_booking_loading_spinner( loading, cell ) {
86
- if ( loading ) {
87
- cell.addClass( 'loading' );
88
- } else {
89
- cell.removeClass( 'loading' );
90
- }
91
- }
92
-
93
- /**
94
- * Modals for the admin page
95
- */
96
- var rtb_booking_modal = $( '#rtb-booking-modal' ),
97
- rtb_booking_modal_fields = rtb_booking_modal.find( '#rtb-booking-form-fields' ),
98
- rtb_booking_modal_submit = rtb_booking_modal.find( 'button' ),
99
- rtb_booking_modal_cancel = rtb_booking_modal.find( '#rtb-cancel-booking-modal' ),
100
- rtb_booking_modal_action_status = rtb_booking_modal.find( '.action-status' ),
101
- rtb_email_modal = $( '#rtb-email-modal' ),
102
- rtb_email_modal_submit = rtb_email_modal.find( 'button' ),
103
- rtb_email_modal_cancel = rtb_email_modal.find( '#rtb-cancel-email-modal' ),
104
- rtb_email_modal_action_status = rtb_email_modal.find( '.action-status' ),
105
- rtb_column_modal = $( '#rtb-column-modal' ),
106
- rtb_column_modal_submit = rtb_column_modal.find( 'button' ),
107
- rtb_column_modal_cancel = rtb_column_modal.find( '#rtb-cancel-column-modal' ),
108
- rtb_column_modal_action_status = rtb_column_modal.find( '.action-status' ),
109
- rtb_details_modal = $( '#rtb-details-modal' ),
110
- rtb_details_modal_close = rtb_details_modal.find( '#rtb-close-details-modal' ),
111
- rtb_details_modal_cancel = rtb_details_modal.find( '#rtb-cancel-details-modal' ),
112
- rtb_booking_modal_error = $( '#rtb-error-modal' ),
113
- rtb_booking_modal_error_msg = rtb_booking_modal_error.find( '.rtb-error-msg' ),
114
- rtb_ban_modal = $( '#rtb-ban-modal' ),
115
- rtb_ban_modal_submit_email = rtb_ban_modal.find( '#rtb-ban-modal-email-btn' ),
116
- rtb_ban_modal_submit_ip = rtb_ban_modal.find( '#rtb-ban-modal-ip-btn' ),
117
- rtb_ban_modal_cancel = rtb_ban_modal.find( '#rtb-cancel-ban-modal' ),
118
- rtb_ban_modal_action_status = rtb_ban_modal.find( '.action-status' ),
119
- rtb_delete_modal = $( '#rtb-delete-modal' ),
120
- rtb_delete_modal_submit_btn = rtb_delete_modal.find( '#rtb-delete-modal-btn' ),
121
- rtb_delete_modal_cancel = rtb_delete_modal.find( '#rtb-cancel-delete-modal' ),
122
- rtb_delete_modal_action_status = rtb_delete_modal.find( '.action-status' ),
123
- rtb_delete_modal_status = rtb_delete_modal.find( '#rtb-delete-status' ),
124
- rtb_delete_modal_progress = rtb_delete_modal_status.find( '#rtb-delete-status-progress' ),
125
- rtb_delete_modal_deleted = rtb_delete_modal_status.find( '#rtb-delete-status-deleted' );
126
-
127
- /**
128
- * Show or hide the booking form modal
129
- */
130
- function rtb_toggle_booking_form_modal( show, fields, booking ) {
131
-
132
- if ( show ) {
133
- rtb_booking_modal.scrollTop( 0 ).addClass( 'is-visible' );
134
-
135
- if ( typeof fields !== 'undefined' ) {
136
- rtb_booking_modal_fields.html( fields );
137
- rtb_init_booking_form_modal_fields();
138
- }
139
-
140
- if ( typeof booking == 'undefined' ) {
141
- rtb_booking_modal_fields.find( '#rtb-post-status' ).val( 'confirmed' );
142
- rtb_booking_modal_submit.html( rtb_admin.strings.add_booking );
143
- } else {
144
- rtb_booking_modal_submit.html( rtb_admin.strings.edit_booking );
145
- rtb_booking_modal.find( 'input[name=ID]' ).val( booking.ID );
146
- }
147
-
148
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
149
-
150
- } else {
151
- rtb_booking_modal.removeClass( 'is-visible' );
152
- rtb_booking_modal.find( '.rtb-error' ).remove();
153
- rtb_booking_modal.find( '.notifications-description' ).removeClass( 'is-visible' );
154
- rtb_booking_modal_action_status.removeClass( 'is-visible' );
155
- rtb_reset_booking_form_modal_fields();
156
- rtb_booking_modal_submit.removeData( 'id' );
157
- rtb_booking_modal_submit.prop( 'disabled', false );
158
- rtb_booking_modal_cancel.prop( 'disabled', false );
159
- rtb_booking_modal.find( 'input[name=ID]' ).val( '' );
160
-
161
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
162
- }
163
- }
164
-
165
- /**
166
- * Show or hide the booking form error modal
167
- */
168
- function rtb_toggle_booking_form_error_modal( show, msg ) {
169
-
170
- if ( show ) {
171
- rtb_booking_modal_error_msg.html( msg );
172
- rtb_booking_modal_error.addClass( 'is-visible' );
173
-
174
- } else {
175
- rtb_booking_modal_error.removeClass( 'is-visible' );
176
- }
177
- }
178
-
179
- /**
180
- * Show or hide the email form modal
181
- */
182
- function rtb_toggle_email_modal( show, id, email, name ) {
183
-
184
- if ( show ) {
185
- rtb_email_modal.scrollTop( 0 ).addClass( 'is-visible' );
186
- rtb_email_modal.find( 'input[name=ID]' ).val( id );
187
- rtb_email_modal.find( 'input[name=email]' ).val( email );
188
- rtb_email_modal.find( 'input[name=name]' ).val( name );
189
- rtb_email_modal.find( '.rtb-email-to' ).html( name + ' &lt;' + email + '&gt;' );
190
-
191
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
192
-
193
- } else {
194
- rtb_email_modal.removeClass( 'is-visible' );
195
- rtb_email_modal.find( '.rtb-email-to' ).html( '' );
196
- rtb_email_modal.find( 'textarea, input[type="hidden"], input[type="text"]' ).val( '' );
197
- rtb_email_modal_submit.prop( 'disabled', false );
198
- rtb_email_modal_cancel.prop( 'disabled', false );
199
-
200
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
201
- }
202
- }
203
-
204
- /**
205
- * Show or hide the column configuration modal
206
- */
207
- function rtb_toggle_column_modal( show ) {
208
-
209
- if ( show ) {
210
- rtb_column_modal.scrollTop( 0 ).addClass( 'is-visible' );
211
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
212
-
213
- } else {
214
- rtb_column_modal.removeClass( 'is-visible' );
215
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
216
- }
217
- }
218
-
219
- /**
220
- * Show or hide the booking details modal
221
- */
222
- function rtb_toggle_details_modal( show, content ) {
223
-
224
- if ( show ) {
225
- rtb_details_modal.addClass( 'is-visible' ).scrollTop( 0 )
226
- .find( '.rtb-details-data' ).html( content );
227
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
228
- rtb_details_modal.find( '.actions' ).click( function(e) {
229
- var target = $( e.target );
230
- rtb_toggle_details_modal( false );
231
- if ( target.data( 'action' ) == 'email') {
232
- rtb_toggle_email_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'name' ) );
233
- } else if ( target.data( 'action' ) == 'ban') {
234
- rtb_toggle_ban_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'ip' ) );
235
- } else if ( target.data( 'action' ) == 'delete') {
236
- rtb_toggle_delete_modal( true, target.data( 'id'), target.data( 'email' ) );
237
- }
238
- });
239
-
240
- } else {
241
- rtb_details_modal.removeClass( 'is-visible' );
242
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
243
- setTimeout( function() {
244
- rtb_details_modal.find( '.rtb-details-data' ).empty();
245
- }, 300 );
246
- }
247
- }
248
-
249
- /**
250
- * Show or hide the ban ip/email form modal
251
- */
252
- function rtb_toggle_ban_modal( show, id, email, ip ) {
253
-
254
- if ( show ) {
255
- rtb_ban_modal.scrollTop( 0 ).addClass( 'is-visible' );
256
- rtb_ban_modal.find( '#rtb-ban-modal-email' ).text( email );
257
- rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text( ip );
258
- if ( rtb_admin.banned_emails.indexOf( email ) > -1 ) {
259
- rtb_ban_modal_submit_email.prop( 'disabled', true );
260
- }
261
- if ( rtb_admin.banned_ips.indexOf( ip ) > -1 ) {
262
- rtb_ban_modal_submit_ip.prop( 'disabled', true );
263
- }
264
-
265
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
266
-
267
- } else {
268
- rtb_ban_modal.removeClass( 'is-visible' );
269
- rtb_ban_modal.find( '#rtb-ban-modal-email' ).text( '' );
270
- rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text( '' );
271
- rtb_ban_modal_submit_email.prop( 'disabled', false );
272
- rtb_ban_modal_submit_ip.prop( 'disabled', false );
273
- rtb_ban_modal_cancel.prop( 'disabled', false );
274
-
275
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
276
- }
277
- }
278
-
279
- /**
280
- * Show or hide the delete customer form modal
281
- */
282
- function rtb_toggle_delete_modal( show, id, email ) {
283
-
284
- if ( show ) {
285
- rtb_delete_modal.scrollTop( 0 ).addClass( 'is-visible' );
286
- rtb_delete_modal.find( '#rtb-delete-modal-email' ).text( email );
287
- $( 'body' ).addClass( 'rtb-hide-body-scroll' );
288
-
289
- } else {
290
- rtb_delete_modal.removeClass( 'is-visible' );
291
- rtb_delete_modal.find( '#rtb-ban-modal-email' ).text( '' );
292
- $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
293
- }
294
- }
295
-
296
- /**
297
- * Initialize form field events
298
- */
299
- function rtb_init_booking_form_modal_fields() {
300
-
301
- // Run init on the form
302
- rtb_booking_form.init();
303
-
304
- // Show full description for notifications toggle
305
- rtb_booking_modal_fields.find( '.rtb-description-prompt' ).click( function() {
306
- $(this).parent().siblings( '.rtb-description' ).addClass( 'is-visible' );
307
- });
308
- }
309
-
310
- /**
311
- * Reset booking form fields
312
- */
313
- function rtb_reset_booking_form_modal_fields() {
314
- rtb_booking_modal_fields.find( 'input,select, textarea' ).not( 'input[type="checkbox"],input[type="radio"]' ).val( '' );
315
- rtb_booking_modal_fields.find( 'input[name=rtb-notifications]' ).removeAttr( 'checked' );
316
- }
317
-
318
- /**
319
- * Retrieve booking from the database
320
- */
321
- function rtb_get_booking( id, cell ) {
322
-
323
- var params = {};
324
-
325
- params.action = 'rtb-admin-booking-modal';
326
- params.nonce = rtb_admin.nonce;
327
- params.booking = {
328
- 'ID': id
329
- };
330
-
331
- var data = $.param( params );
332
-
333
- var jqhxr = $.get( ajaxurl, data, function( r ) {
334
-
335
- if ( r.success ) {
336
- rtb_toggle_booking_form_modal( true, r.data.fields, r.data.booking );
337
-
338
- } else {
339
-
340
- if ( typeof r.data.error == 'undefined' ) {
341
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
342
- } else {
343
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
344
- }
345
- }
346
-
347
- rtb_booking_loading_spinner( false, cell );
348
- });
349
- }
350
-
351
- /**
352
- * Trash booking
353
- */
354
- function rtb_trash_booking( id, cell ) {
355
-
356
- var params = {};
357
-
358
- params.action = 'rtb-admin-trash-booking';
359
- params.nonce = rtb_admin.nonce;
360
- params.booking = id;
361
-
362
- var data = $.param( params );
363
-
364
- var jqhxr = $.post( ajaxurl, data, function( r ) {
365
-
366
- if ( r.success ) {
367
-
368
- cell.parent().fadeOut( 500, function() {
369
- $(this).remove();
370
- });
371
-
372
- var trash_count_el = $( '#rtb-bookings-table .subsubsub .trash .count' );
373
- var trash_count = parseInt( trash_count_el.html().match(/\d+/), 10 ) + 1;
374
- trash_count_el.html( '(' + trash_count + ')' );
375
-
376
- } else {
377
-
378
- if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
379
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
380
- } else {
381
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
382
- }
383
- }
384
-
385
- rtb_booking_loading_spinner( false, cell );
386
- });
387
-
388
- }
389
-
390
- /**
391
- * Show the appropriate result status icon
392
- */
393
- function rtb_show_action_status( el, status ) {
394
-
395
- el.find( 'span' ).hide();
396
-
397
- if ( status === true ) {
398
- el.find( '.success' ).show();
399
- } else if ( status === false ) {
400
- el.find( '.error' ).show();
401
- } else {
402
- el.find( '.spinner' ).show();
403
- }
404
- }
405
-
406
- // Reset the forms on load
407
- // This fixes a strange bug in Firefox where disabled buttons would
408
- // persist after the page refreshed. I'm guessing its a cache issue
409
- // but this will just reset everything again
410
- rtb_toggle_booking_form_modal( false );
411
- rtb_toggle_email_modal( false );
412
- rtb_toggle_column_modal( false );
413
-
414
- // Close booking form modal when background or cancel button is clicked
415
- rtb_booking_modal.click( function(e) {
416
- if ( $(e.target).is( rtb_booking_modal ) ) {
417
- rtb_toggle_booking_form_modal( false );
418
- }
419
-
420
- if ( $(e.target).is( rtb_booking_modal_cancel ) && rtb_booking_modal_cancel.prop( 'disabled' ) === false ) {
421
- rtb_toggle_booking_form_modal( false );
422
- }
423
- });
424
-
425
- // Close email modal when background or cancel button is clicked
426
- rtb_email_modal.click( function(e) {
427
- if ( $(e.target).is( rtb_email_modal ) ) {
428
- rtb_toggle_email_modal( false );
429
- }
430
-
431
- if ( $(e.target).is( rtb_email_modal_cancel ) && rtb_email_modal_cancel.prop( 'disabled' ) === false ) {
432
- rtb_toggle_email_modal( false );
433
- }
434
- });
435
-
436
- // Close column modal when background or cancel button is clicked
437
- rtb_column_modal.click( function(e) {
438
- if ( $(e.target).is( rtb_column_modal ) ) {
439
- rtb_toggle_column_modal( false );
440
- }
441
-
442
- if ( $(e.target).is( rtb_column_modal_cancel ) && rtb_column_modal_cancel.prop( 'disabled' ) !== true ) {
443
- rtb_toggle_column_modal( false );
444
- }
445
- });
446
-
447
- // Close details modal when background or cancel button is clicked
448
- rtb_details_modal.click( function(e) {
449
- if ( $(e.target).is( rtb_details_modal ) ) {
450
- rtb_toggle_details_modal( false );
451
- }
452
-
453
- if ( $(e.target).is( rtb_details_modal_cancel ) ) {
454
- rtb_toggle_details_modal( false );
455
- }
456
- });
457
-
458
- // Close booking form error modal when background or cancel button is clicked
459
- rtb_booking_modal_error.click( function(e) {
460
- if ( $(e.target).is( rtb_booking_modal_error ) || $(e.target).is( rtb_booking_modal_error.find( 'a.button' ) ) ) {
461
- rtb_toggle_booking_form_error_modal( false );
462
- }
463
- });
464
-
465
- // Close ban modal when background or cancel button is clicked
466
- rtb_ban_modal.click( function(e) {
467
- if ( $(e.target).is( rtb_ban_modal ) ) {
468
- rtb_toggle_ban_modal( false );
469
- }
470
-
471
- if ( $(e.target).is( rtb_ban_modal_cancel ) && rtb_ban_modal_cancel.prop( 'disabled' ) !== true ) {
472
- rtb_toggle_ban_modal( false );
473
- }
474
- });
475
-
476
- // Close delete modal when background or cancel button is clicked
477
- rtb_delete_modal.click( function(e) {
478
- if ( $(e.target).is( rtb_delete_modal ) ) {
479
- rtb_toggle_delete_modal( false );
480
- }
481
-
482
- if ( $(e.target).is( rtb_delete_modal_cancel ) && rtb_delete_modal_cancel.prop( 'disabled' ) !== true ) {
483
- rtb_toggle_delete_modal( false );
484
- }
485
- });
486
-
487
- // Close modals when ESC is keyed
488
- $(document).keyup( function(e) {
489
- if ( e.which == '27' ) {
490
- rtb_toggle_booking_form_modal( false );
491
- rtb_toggle_email_modal( false );
492
- rtb_toggle_column_modal( false );
493
- rtb_toggle_details_modal( false );
494
- rtb_toggle_booking_form_error_modal( false );
495
- rtb_toggle_ban_modal( false );
496
- rtb_toggle_delete_modal( false );
497
- }
498
- });
499
-
500
- // Submit booking form modal
501
- rtb_booking_modal_submit.click( function(e) {
502
-
503
- e.preventDefault();
504
- e.stopPropagation();
505
-
506
- if ( $(this).prop( 'disabled' ) === true ) {
507
- return;
508
- }
509
-
510
- // Loading
511
- rtb_booking_modal_submit.prop( 'disabled', true );
512
- rtb_booking_modal_cancel.prop( 'disabled', true );
513
- rtb_booking_modal_action_status.addClass( 'is-visible' );
514
- rtb_show_action_status( rtb_booking_modal_action_status, 'loading' );
515
-
516
- var params = {};
517
-
518
- params.action = 'rtb-admin-booking-modal';
519
- params.nonce = rtb_admin.nonce;
520
- params.booking = rtb_booking_modal.find( 'form' ).serializeArray();
521
-
522
- var data = $.param( params );
523
-
524
- var jqhxr = $.post( ajaxurl, data, function( r ) {
525
-
526
- if ( r.success ) {
527
-
528
- // Refresh the page so that the new details are visible
529
- window.location.reload();
530
-
531
- } else {
532
-
533
- // Validation failed
534
- if ( r.data.error == 'invalid_booking_data' ) {
535
-
536
- // Replace form fields with HTML returned
537
- rtb_booking_modal_fields.html( r.data.fields );
538
- rtb_init_booking_form_modal_fields();
539
-
540
- // Logged out
541
- } else if ( r.data.error == 'loggedout' ) {
542
- rtb_booking_modal_fields.after( '<div class="rtb-error">' + r.data.msg + '</div>' );
543
-
544
- // Unspecified error
545
- } else {
546
- rtb_booking_modal_fields.after( '<div class="rtb-error">' + rtb_admin.strings.error_unspecified + '</div>' );
547
- }
548
-
549
- rtb_booking_modal_cancel.prop( 'disabled', false );
550
- rtb_booking_modal_submit.prop( 'disabled', false );
551
- }
552
-
553
- rtb_show_action_status( rtb_booking_modal_action_status, r.success );
554
-
555
- // Hide result status icon after a few seconds
556
- setTimeout( function() {
557
- rtb_booking_modal.find( '.action-status' ).removeClass( 'is-visible' );
558
- }, 4000 );
559
- });
560
- });
561
-
562
- // Submit email form modal
563
- rtb_email_modal_submit.click( function(e) {
564
-
565
- e.preventDefault();
566
- e.stopPropagation();
567
-
568
- if ( $(this).prop( 'disabled' ) === true ) {
569
- return;
570
- }
571
-
572
- // Loading
573
- rtb_email_modal_submit.prop( 'disabled', true );
574
- rtb_email_modal_cancel.prop( 'disabled', true );
575
- rtb_email_modal_action_status.addClass( 'is-visible' );
576
- rtb_show_action_status( rtb_email_modal_action_status, 'loading' );
577
-
578
- var params = {};
579
-
580
- params.action = 'rtb-admin-email-modal';
581
- params.nonce = rtb_admin.nonce;
582
- params.email = rtb_email_modal.find( 'form' ).serializeArray();
583
-
584
- var data = $.param( params );
585
-
586
- var jqhxr = $.post( ajaxurl, data, function( r ) {
587
-
588
- if ( r.success ) {
589
-
590
- rtb_show_action_status( rtb_email_modal_action_status, r.success );
591
-
592
- // Hide result status icon after a few seconds
593
- setTimeout( function() {
594
- rtb_email_modal.find( '.action-status' ).removeClass( 'is-visible' );
595
- rtb_toggle_email_modal( false );
596
- }, 1000 );
597
-
598
- } else {
599
-
600
- if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
601
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
602
- } else {
603
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
604
- }
605
-
606
- rtb_email_modal_cancel.prop( 'disabled', false );
607
- rtb_email_modal_submit.prop( 'disabled', false );
608
-
609
- rtb_show_action_status( rtb_email_modal_action_status, false );
610
-
611
- // Hide result status icon after a few seconds
612
- setTimeout( function() {
613
- rtb_email_modal.find( '.action-status' ).removeClass( 'is-visible' );
614
- }, 4000 );
615
- }
616
- });
617
- });
618
-
619
- // Submit column configuration modal
620
- rtb_column_modal_submit.click( function(e) {
621
-
622
- e.preventDefault();
623
- e.stopPropagation();
624
-
625
- if ( $(this).prop( 'disabled' ) === true ) {
626
- return;
627
- }
628
-
629
- // Loading
630
- rtb_column_modal_submit.prop( 'disabled', true );
631
- rtb_column_modal_cancel.prop( 'disabled', true );
632
- rtb_column_modal_action_status.addClass( 'is-visible' );
633
- rtb_show_action_status( rtb_column_modal_action_status, 'loading' );
634
-
635
- var params = {};
636
-
637
- params.action = 'rtb-admin-column-modal';
638
- params.nonce = rtb_admin.nonce;
639
-
640
- params.columns = [];
641
- rtb_column_modal.find( 'input[name="rtb-columns-config"]:checked' ).each( function() {
642
- params.columns.push( $(this).val() );
643
- });
644
-
645
- var data = $.param( params );
646
-
647
- var jqhxr = $.post( ajaxurl, data, function( r ) {
648
-
649
- if ( r.success ) {
650
-
651
- // Refresh the page so that the new details are visible
652
- window.location.reload();
653
-
654
- } else {
655
-
656
- if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
657
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
658
- } else {
659
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
660
- }
661
-
662
- rtb_column_modal_cancel.prop( 'disabled', false );
663
- rtb_column_modal_submit.prop( 'disabled', false );
664
- }
665
-
666
- rtb_show_action_status( rtb_column_modal_action_status, r.success );
667
-
668
- // Hide result status icon after a few seconds
669
- setTimeout( function() {
670
- rtb_column_modal.find( '.action-status' ).removeClass( 'is-visible' );
671
- }, 4000 );
672
- });
673
- });
674
-
675
- // Shared function for banning emails and IPs
676
- function rtb_ban_modal_submit( e, type ) {
677
-
678
- e.preventDefault();
679
- e.stopPropagation();
680
-
681
- if ( $(this).prop( 'disabled' ) === true ) {
682
- return;
683
- }
684
-
685
- // Loading
686
- if ( type === 'email' ) {
687
- rtb_ban_modal_submit_email.prop( 'disabled', true );
688
- } else if ( type === 'ip' ) {
689
- rtb_ban_modal_submit_ip.prop( 'disabled', true );
690
- }
691
- rtb_ban_modal_cancel.prop( 'disabled', true );
692
- rtb_ban_modal_action_status.addClass( 'is-visible' );
693
- rtb_show_action_status( rtb_ban_modal_action_status, 'loading' );
694
-
695
- var params = {};
696
-
697
- params.action = 'rtb-admin-ban-modal';
698
- params.nonce = rtb_admin.nonce;
699
- if ( type === 'email' ) {
700
- params.email = rtb_ban_modal.find( '#rtb-ban-modal-email' ).text();
701
- } else if ( type === 'ip' ) {
702
- params.ip = rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text();
703
- }
704
-
705
- var data = $.param( params );
706
-
707
- var jqhxr = $.post( ajaxurl, data, function( r ) {
708
-
709
- if ( r.success ) {
710
-
711
- if ( type === 'email' ) {
712
- rtb_admin.banned_emails.push( params.email );
713
- } else if ( type === 'ip' ) {
714
- rtb_admin.banned_ips.push( params.ip );
715
- }
716
-
717
- rtb_show_action_status( rtb_ban_modal_action_status, r.success );
718
-
719
- // Hide result status icon after a few seconds
720
- setTimeout( function() {
721
- rtb_ban_modal.find( '.action-status' ).removeClass( 'is-visible' );
722
- }, 1000 );
723
-
724
- } else {
725
-
726
- if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
727
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
728
- } else {
729
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
730
- }
731
-
732
- rtb_ban_modal_cancel.prop( 'disabled', false );
733
- if ( type === 'email' ) {
734
- rtb_ban_modal_submit_email.prop( 'disabled', false );
735
- } else if ( type === 'ip' ) {
736
- rtb_ban_modal_submit_ip.prop( 'disabled', false );
737
- }
738
-
739
- rtb_show_action_status( rtb_ban_modal_action_status, false );
740
-
741
- // Hide result status icon after a few seconds
742
- setTimeout( function() {
743
- rtb_ban_modal.find( '.action-status' ).removeClass( 'is-visible' );
744
- }, 4000 );
745
- }
746
- });
747
- }
748
-
749
- // Submit ban email form modal
750
- rtb_ban_modal_submit_email.click( function(e) {
751
- rtb_ban_modal_submit( e, 'email' );
752
- });
753
-
754
- // Submit ban ip form modal
755
- rtb_ban_modal_submit_ip.click( function(e) {
756
- rtb_ban_modal_submit( e, 'ip' );
757
- });
758
-
759
- // Delete customers by email
760
- function rtb_delete_modal_submit( e ) {
761
-
762
- e.preventDefault();
763
- e.stopPropagation();
764
-
765
- // Loading
766
- rtb_delete_modal_submit_btn.prop( 'disabled', true );
767
- rtb_delete_modal_cancel.prop( 'disabled', true );
768
- rtb_delete_modal_action_status.addClass( 'is-visible' );
769
- rtb_delete_modal_status.addClass('is-visible');
770
- rtb_show_action_status( rtb_delete_modal_action_status, 'loading' );
771
-
772
- function delete_page( params ) {
773
-
774
- var jqhxr = $.post( ajaxurl, $.param( params ), function( r ) {
775
-
776
- if ( r.success ) {
777
-
778
- processed = processed + r.data.processed;
779
- deleted = deleted + r.data.deleted;
780
- var percent = Math.ceil( ( processed / r.data.total ) * 100 );
781
- rtb_delete_modal_progress.css( 'width', percent + '%' );
782
- rtb_delete_modal_deleted.text( deleted + ' bookings deleted' );
783
-
784
- if ( processed < r.data.total ) {
785
- params.page++;
786
- delete_page( params );
787
- } else {
788
- rtb_delete_modal_cancel.click(function(e) {
789
- window.location.reload();
790
- });
791
- rtb_delete_modal_deleted.text( 'Finished! ' + deleted + ' bookings deleted' );
792
- rtb_delete_modal_cancel.prop( 'disabled', false );
793
- rtb_delete_modal_submit_btn.css('display', 'none');
794
- rtb_delete_modal_action_status.removeClass( 'is-visible' );
795
- rtb_show_action_status( rtb_delete_modal_action_status, false );
796
- }
797
-
798
- } else {
799
-
800
- if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
801
- rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
802
- } else {
803
- rtb_toggle_booking_form_error_modal( true, r.data.msg );
804
- }
805
-
806
- rtb_delete_modal_submit_btn.prop( 'disabled', false );
807
- rtb_delete_modal_cancel.prop( 'disabled', false );
808
- rtb_delete_modal_action_status.removeClass( 'is-visible' );
809
- rtb_delete_modal_status.removeClass( 'is-visible' );
810
- rtb_show_action_status( rtb_delete_modal_action_status, false );
811
- }
812
- });
813
- }
814
-
815
- var processed = 0;
816
- var deleted = 0;
817
- delete_page({
818
- action: 'rtb-admin-delete-modal',
819
- nonce: rtb_admin.nonce,
820
- email: rtb_delete_modal.find( '#rtb-delete-modal-email' ).text(),
821
- page: 1,
822
- });
823
- }
824
-
825
- // Submit ban email form modal
826
- rtb_delete_modal_submit_btn.click( function(e) {
827
- rtb_delete_modal_submit( e );
828
- });
829
-
830
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Javascript for Restaurant Reservations admin */
2
+ jQuery(document).ready(function ($) {
3
+
4
+ // Show/hide date filter in bookings list
5
+ $( '#rtb-date-filter-link' ).click( function() {
6
+ $( '#rtb-filters' ).toggleClass( 'date-filters-visible' );
7
+ });
8
+
9
+ // Add date picker to date filter in admin
10
+ $( '#start-date, #end-date' ).each( function() {
11
+ var input = $(this);
12
+
13
+ input.pickadate({
14
+ format: rtb_pickadate.date_format,
15
+ formatSubmit: 'yyyy/mm/dd',
16
+ hiddenName: true,
17
+
18
+ onStart: function() {
19
+ if ( input.val() !== '' ) {
20
+ var date = new Date( input.val() );
21
+ if ( Object.prototype.toString.call( date ) === "[object Date]" ) {
22
+ this.set( 'select', date );
23
+ }
24
+ }
25
+ }
26
+ });
27
+ });
28
+
29
+ // Show or hide extra booking details in the bookings table
30
+ $( '.rtb-show-details' ).click( function (e) {
31
+ e.preventDefault();
32
+ rtb_toggle_details_modal( true, $(this).siblings( '.rtb-details-data' ).html() );
33
+ });
34
+
35
+ // Register clicks on action links
36
+ $( '#rtb-bookings-table tr .actions' ).click( function(e) {
37
+
38
+ e.stopPropagation();
39
+
40
+ var target = $(e.target);
41
+ var action = target.data( 'action' );
42
+
43
+ if ( !action ) {
44
+ return;
45
+ }
46
+
47
+ var cell = target.parent().parent();
48
+
49
+ if ( target.data( 'action' ) == 'edit' ) {
50
+ rtb_booking_loading_spinner( true, cell );
51
+ rtb_get_booking( target.data( 'id' ), cell );
52
+
53
+ } else if ( target.data( 'action' ) == 'trash' ) {
54
+ rtb_booking_loading_spinner( true, cell );
55
+ rtb_trash_booking( target.data( 'id' ), cell );
56
+
57
+ } else if ( target.data( 'action' ) == 'email') {
58
+ rtb_toggle_email_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'name' ) );
59
+
60
+ } else if ( target.data( 'action' ) == 'ban') {
61
+ rtb_toggle_ban_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'ip' ) );
62
+
63
+ } else if ( target.data( 'action' ) == 'delete') {
64
+ rtb_toggle_delete_modal( true, target.data( 'id'), target.data( 'email' ) );
65
+ }
66
+
67
+ e.preventDefault();
68
+ });
69
+
70
+ // Show booking form modal
71
+ $( '.add-booking' ).click( function( e ) {
72
+ e.preventDefault();
73
+ rtb_toggle_booking_form_modal( true );
74
+ });
75
+
76
+ // Show column configuration modal
77
+ $( '.rtb-columns-button' ).click( function( e ) {
78
+ e.preventDefault();
79
+ rtb_toggle_column_modal( true );
80
+ });
81
+
82
+ /**
83
+ * Show/hide loading spinner when edit/delete link clicked
84
+ */
85
+ function rtb_booking_loading_spinner( loading, cell ) {
86
+ if ( loading ) {
87
+ cell.addClass( 'loading' );
88
+ } else {
89
+ cell.removeClass( 'loading' );
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Modals for the admin page
95
+ */
96
+ var rtb_booking_modal = $( '#rtb-booking-modal' ),
97
+ rtb_booking_modal_fields = rtb_booking_modal.find( '#rtb-booking-form-fields' ),
98
+ rtb_booking_modal_submit = rtb_booking_modal.find( 'button' ),
99
+ rtb_booking_modal_cancel = rtb_booking_modal.find( '#rtb-cancel-booking-modal' ),
100
+ rtb_booking_modal_action_status = rtb_booking_modal.find( '.action-status' ),
101
+ rtb_email_modal = $( '#rtb-email-modal' ),
102
+ rtb_email_modal_submit = rtb_email_modal.find( 'button' ),
103
+ rtb_email_modal_cancel = rtb_email_modal.find( '#rtb-cancel-email-modal' ),
104
+ rtb_email_modal_action_status = rtb_email_modal.find( '.action-status' ),
105
+ rtb_column_modal = $( '#rtb-column-modal' ),
106
+ rtb_column_modal_submit = rtb_column_modal.find( 'button' ),
107
+ rtb_column_modal_cancel = rtb_column_modal.find( '#rtb-cancel-column-modal' ),
108
+ rtb_column_modal_action_status = rtb_column_modal.find( '.action-status' ),
109
+ rtb_details_modal = $( '#rtb-details-modal' ),
110
+ rtb_details_modal_close = rtb_details_modal.find( '#rtb-close-details-modal' ),
111
+ rtb_details_modal_cancel = rtb_details_modal.find( '#rtb-cancel-details-modal' ),
112
+ rtb_booking_modal_error = $( '#rtb-error-modal' ),
113
+ rtb_booking_modal_error_msg = rtb_booking_modal_error.find( '.rtb-error-msg' ),
114
+ rtb_ban_modal = $( '#rtb-ban-modal' ),
115
+ rtb_ban_modal_submit_email = rtb_ban_modal.find( '#rtb-ban-modal-email-btn' ),
116
+ rtb_ban_modal_submit_ip = rtb_ban_modal.find( '#rtb-ban-modal-ip-btn' ),
117
+ rtb_ban_modal_cancel = rtb_ban_modal.find( '#rtb-cancel-ban-modal' ),
118
+ rtb_ban_modal_action_status = rtb_ban_modal.find( '.action-status' ),
119
+ rtb_delete_modal = $( '#rtb-delete-modal' ),
120
+ rtb_delete_modal_submit_btn = rtb_delete_modal.find( '#rtb-delete-modal-btn' ),
121
+ rtb_delete_modal_cancel = rtb_delete_modal.find( '#rtb-cancel-delete-modal' ),
122
+ rtb_delete_modal_action_status = rtb_delete_modal.find( '.action-status' ),
123
+ rtb_delete_modal_status = rtb_delete_modal.find( '#rtb-delete-status' ),
124
+ rtb_delete_modal_progress = rtb_delete_modal_status.find( '#rtb-delete-status-progress' ),
125
+ rtb_delete_modal_deleted = rtb_delete_modal_status.find( '#rtb-delete-status-deleted' );
126
+
127
+ /**
128
+ * Show or hide the booking form modal
129
+ */
130
+ function rtb_toggle_booking_form_modal( show, fields, booking ) {
131
+
132
+ if ( show ) {
133
+ rtb_booking_modal.scrollTop( 0 ).addClass( 'is-visible' );
134
+
135
+ if ( typeof fields !== 'undefined' ) {
136
+ rtb_booking_modal_fields.html( fields );
137
+ rtb_init_booking_form_modal_fields();
138
+ }
139
+
140
+ if ( typeof booking == 'undefined' ) {
141
+ rtb_booking_modal_fields.find( '#rtb-post-status' ).val( 'confirmed' );
142
+ rtb_booking_modal_submit.html( rtb_admin.strings.add_booking );
143
+ } else {
144
+ rtb_booking_modal_submit.html( rtb_admin.strings.edit_booking );
145
+ rtb_booking_modal.find( 'input[name=ID]' ).val( booking.ID );
146
+ }
147
+
148
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
149
+
150
+ } else {
151
+ rtb_booking_modal.removeClass( 'is-visible' );
152
+ rtb_booking_modal.find( '.rtb-error' ).remove();
153
+ rtb_booking_modal.find( '.notifications-description' ).removeClass( 'is-visible' );
154
+ rtb_booking_modal_action_status.removeClass( 'is-visible' );
155
+ rtb_reset_booking_form_modal_fields();
156
+ rtb_booking_modal_submit.removeData( 'id' );
157
+ rtb_booking_modal_submit.prop( 'disabled', false );
158
+ rtb_booking_modal_cancel.prop( 'disabled', false );
159
+ rtb_booking_modal.find( 'input[name=ID]' ).val( '' );
160
+
161
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
162
+ }
163
+ }
164
+
165
+ /**
166
+ * Show or hide the booking form error modal
167
+ */
168
+ function rtb_toggle_booking_form_error_modal( show, msg ) {
169
+
170
+ if ( show ) {
171
+ rtb_booking_modal_error_msg.html( msg );
172
+ rtb_booking_modal_error.addClass( 'is-visible' );
173
+
174
+ } else {
175
+ rtb_booking_modal_error.removeClass( 'is-visible' );
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Show or hide the email form modal
181
+ */
182
+ function rtb_toggle_email_modal( show, id, email, name ) {
183
+
184
+ if ( show ) {
185
+ rtb_email_modal.scrollTop( 0 ).addClass( 'is-visible' );
186
+ rtb_email_modal.find( 'input[name=ID]' ).val( id );
187
+ rtb_email_modal.find( 'input[name=email]' ).val( email );
188
+ rtb_email_modal.find( 'input[name=name]' ).val( name );
189
+ rtb_email_modal.find( '.rtb-email-to' ).html( name + ' &lt;' + email + '&gt;' );
190
+
191
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
192
+
193
+ } else {
194
+ rtb_email_modal.removeClass( 'is-visible' );
195
+ rtb_email_modal.find( '.rtb-email-to' ).html( '' );
196
+ rtb_email_modal.find( 'textarea, input[type="hidden"], input[type="text"]' ).val( '' );
197
+ rtb_email_modal_submit.prop( 'disabled', false );
198
+ rtb_email_modal_cancel.prop( 'disabled', false );
199
+
200
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Show or hide the column configuration modal
206
+ */
207
+ function rtb_toggle_column_modal( show ) {
208
+
209
+ if ( show ) {
210
+ rtb_column_modal.scrollTop( 0 ).addClass( 'is-visible' );
211
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
212
+
213
+ } else {
214
+ rtb_column_modal.removeClass( 'is-visible' );
215
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Show or hide the booking details modal
221
+ */
222
+ function rtb_toggle_details_modal( show, content ) {
223
+
224
+ if ( show ) {
225
+ rtb_details_modal.addClass( 'is-visible' ).scrollTop( 0 )
226
+ .find( '.rtb-details-data' ).html( content );
227
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
228
+ rtb_details_modal.find( '.actions' ).click( function(e) {
229
+ var target = $( e.target );
230
+ rtb_toggle_details_modal( false );
231
+ if ( target.data( 'action' ) == 'email') {
232
+ rtb_toggle_email_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'name' ) );
233
+ } else if ( target.data( 'action' ) == 'ban') {
234
+ rtb_toggle_ban_modal( true, target.data( 'id'), target.data( 'email' ), target.data( 'ip' ) );
235
+ } else if ( target.data( 'action' ) == 'delete') {
236
+ rtb_toggle_delete_modal( true, target.data( 'id'), target.data( 'email' ) );
237
+ }
238
+ });
239
+
240
+ } else {
241
+ rtb_details_modal.removeClass( 'is-visible' );
242
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
243
+ setTimeout( function() {
244
+ rtb_details_modal.find( '.rtb-details-data' ).empty();
245
+ }, 300 );
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Show or hide the ban ip/email form modal
251
+ */
252
+ function rtb_toggle_ban_modal( show, id, email, ip ) {
253
+
254
+ if ( show ) {
255
+ rtb_ban_modal.scrollTop( 0 ).addClass( 'is-visible' );
256
+ rtb_ban_modal.find( '#rtb-ban-modal-email' ).text( email );
257
+ rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text( ip );
258
+ if ( rtb_admin.banned_emails.indexOf( email ) > -1 ) {
259
+ rtb_ban_modal_submit_email.prop( 'disabled', true );
260
+ }
261
+ if ( rtb_admin.banned_ips.indexOf( ip ) > -1 ) {
262
+ rtb_ban_modal_submit_ip.prop( 'disabled', true );
263
+ }
264
+
265
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
266
+
267
+ } else {
268
+ rtb_ban_modal.removeClass( 'is-visible' );
269
+ rtb_ban_modal.find( '#rtb-ban-modal-email' ).text( '' );
270
+ rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text( '' );
271
+ rtb_ban_modal_submit_email.prop( 'disabled', false );
272
+ rtb_ban_modal_submit_ip.prop( 'disabled', false );
273
+ rtb_ban_modal_cancel.prop( 'disabled', false );
274
+
275
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
276
+ }
277
+ }
278
+
279
+ /**
280
+ * Show or hide the delete customer form modal
281
+ */
282
+ function rtb_toggle_delete_modal( show, id, email ) {
283
+
284
+ if ( show ) {
285
+ rtb_delete_modal.scrollTop( 0 ).addClass( 'is-visible' );
286
+ rtb_delete_modal.find( '#rtb-delete-modal-email' ).text( email );
287
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
288
+
289
+ } else {
290
+ rtb_delete_modal.removeClass( 'is-visible' );
291
+ rtb_delete_modal.find( '#rtb-ban-modal-email' ).text( '' );
292
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Initialize form field events
298
+ */
299
+ function rtb_init_booking_form_modal_fields() {
300
+
301
+ // Run init on the form
302
+ rtb_booking_form.init();
303
+
304
+ // Show full description for notifications toggle
305
+ rtb_booking_modal_fields.find( '.rtb-description-prompt' ).click( function() {
306
+ $(this).parent().siblings( '.rtb-description' ).addClass( 'is-visible' );
307
+ });
308
+ }
309
+
310
+ /**
311
+ * Reset booking form fields
312
+ */
313
+ function rtb_reset_booking_form_modal_fields() {
314
+ rtb_booking_modal_fields.find( 'input,select, textarea' ).not( 'input[type="checkbox"],input[type="radio"]' ).val( '' );
315
+ rtb_booking_modal_fields.find( 'input[name=rtb-notifications]' ).removeAttr( 'checked' );
316
+ }
317
+
318
+ /**
319
+ * Retrieve booking from the database
320
+ */
321
+ function rtb_get_booking( id, cell ) {
322
+
323
+ var params = {};
324
+
325
+ params.action = 'rtb-admin-booking-modal';
326
+ params.nonce = rtb_admin.nonce;
327
+ params.booking = {
328
+ 'ID': id
329
+ };
330
+
331
+ var data = $.param( params );
332
+
333
+ var jqhxr = $.get( ajaxurl, data, function( r ) {
334
+
335
+ if ( r.success ) {
336
+ rtb_toggle_booking_form_modal( true, r.data.fields, r.data.booking );
337
+
338
+ } else {
339
+
340
+ if ( typeof r.data.error == 'undefined' ) {
341
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
342
+ } else {
343
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
344
+ }
345
+ }
346
+
347
+ rtb_booking_loading_spinner( false, cell );
348
+ });
349
+ }
350
+
351
+ /**
352
+ * Trash booking
353
+ */
354
+ function rtb_trash_booking( id, cell ) {
355
+
356
+ var params = {};
357
+
358
+ params.action = 'rtb-admin-trash-booking';
359
+ params.nonce = rtb_admin.nonce;
360
+ params.booking = id;
361
+
362
+ var data = $.param( params );
363
+
364
+ var jqhxr = $.post( ajaxurl, data, function( r ) {
365
+
366
+ if ( r.success ) {
367
+
368
+ cell.parent().fadeOut( 500, function() {
369
+ $(this).remove();
370
+ });
371
+
372
+ var trash_count_el = $( '#rtb-bookings-table .subsubsub .trash .count' );
373
+ var trash_count = parseInt( trash_count_el.html().match(/\d+/), 10 ) + 1;
374
+ trash_count_el.html( '(' + trash_count + ')' );
375
+
376
+ } else {
377
+
378
+ if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
379
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
380
+ } else {
381
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
382
+ }
383
+ }
384
+
385
+ rtb_booking_loading_spinner( false, cell );
386
+ });
387
+
388
+ }
389
+
390
+ /**
391
+ * Show the appropriate result status icon
392
+ */
393
+ function rtb_show_action_status( el, status ) {
394
+
395
+ el.find( 'span' ).hide();
396
+
397
+ if ( status === true ) {
398
+ el.find( '.success' ).show();
399
+ } else if ( status === false ) {
400
+ el.find( '.error' ).show();
401
+ } else {
402
+ el.find( '.spinner' ).show();
403
+ }
404
+ }
405
+
406
+ // Reset the forms on load
407
+ // This fixes a strange bug in Firefox where disabled buttons would
408
+ // persist after the page refreshed. I'm guessing its a cache issue
409
+ // but this will just reset everything again
410
+ rtb_toggle_booking_form_modal( false );
411
+ rtb_toggle_email_modal( false );
412
+ rtb_toggle_column_modal( false );
413
+
414
+ // Close booking form modal when background or cancel button is clicked
415
+ rtb_booking_modal.click( function(e) {
416
+ if ( $(e.target).is( rtb_booking_modal ) ) {
417
+ rtb_toggle_booking_form_modal( false );
418
+ }
419
+
420
+ if ( $(e.target).is( rtb_booking_modal_cancel ) && rtb_booking_modal_cancel.prop( 'disabled' ) === false ) {
421
+ rtb_toggle_booking_form_modal( false );
422
+ }
423
+ });
424
+
425
+ // Close email modal when background or cancel button is clicked
426
+ rtb_email_modal.click( function(e) {
427
+ if ( $(e.target).is( rtb_email_modal ) ) {
428
+ rtb_toggle_email_modal( false );
429
+ }
430
+
431
+ if ( $(e.target).is( rtb_email_modal_cancel ) && rtb_email_modal_cancel.prop( 'disabled' ) === false ) {
432
+ rtb_toggle_email_modal( false );
433
+ }
434
+ });
435
+
436
+ // Close column modal when background or cancel button is clicked
437
+ rtb_column_modal.click( function(e) {
438
+ if ( $(e.target).is( rtb_column_modal ) ) {
439
+ rtb_toggle_column_modal( false );
440
+ }
441
+
442
+ if ( $(e.target).is( rtb_column_modal_cancel ) && rtb_column_modal_cancel.prop( 'disabled' ) !== true ) {
443
+ rtb_toggle_column_modal( false );
444
+ }
445
+ });
446
+
447
+ // Close details modal when background or cancel button is clicked
448
+ rtb_details_modal.click( function(e) {
449
+ if ( $(e.target).is( rtb_details_modal ) ) {
450
+ rtb_toggle_details_modal( false );
451
+ }
452
+
453
+ if ( $(e.target).is( rtb_details_modal_cancel ) ) {
454
+ rtb_toggle_details_modal( false );
455
+ }
456
+ });
457
+
458
+ // Close booking form error modal when background or cancel button is clicked
459
+ rtb_booking_modal_error.click( function(e) {
460
+ if ( $(e.target).is( rtb_booking_modal_error ) || $(e.target).is( rtb_booking_modal_error.find( 'a.button' ) ) ) {
461
+ rtb_toggle_booking_form_error_modal( false );
462
+ }
463
+ });
464
+
465
+ // Close ban modal when background or cancel button is clicked
466
+ rtb_ban_modal.click( function(e) {
467
+ if ( $(e.target).is( rtb_ban_modal ) ) {
468
+ rtb_toggle_ban_modal( false );
469
+ }
470
+
471
+ if ( $(e.target).is( rtb_ban_modal_cancel ) && rtb_ban_modal_cancel.prop( 'disabled' ) !== true ) {
472
+ rtb_toggle_ban_modal( false );
473
+ }
474
+ });
475
+
476
+ // Close delete modal when background or cancel button is clicked
477
+ rtb_delete_modal.click( function(e) {
478
+ if ( $(e.target).is( rtb_delete_modal ) ) {
479
+ rtb_toggle_delete_modal( false );
480
+ }
481
+
482
+ if ( $(e.target).is( rtb_delete_modal_cancel ) && rtb_delete_modal_cancel.prop( 'disabled' ) !== true ) {
483
+ rtb_toggle_delete_modal( false );
484
+ }
485
+ });
486
+
487
+ // Close modals when ESC is keyed
488
+ $(document).keyup( function(e) {
489
+ if ( e.which == '27' ) {
490
+ rtb_toggle_booking_form_modal( false );
491
+ rtb_toggle_email_modal( false );
492
+ rtb_toggle_column_modal( false );
493
+ rtb_toggle_details_modal( false );
494
+ rtb_toggle_booking_form_error_modal( false );
495
+ rtb_toggle_ban_modal( false );
496
+ rtb_toggle_delete_modal( false );
497
+ }
498
+ });
499
+
500
+ // Submit booking form modal
501
+ rtb_booking_modal_submit.click( function(e) {
502
+
503
+ e.preventDefault();
504
+ e.stopPropagation();
505
+
506
+ if ( $(this).prop( 'disabled' ) === true ) {
507
+ return;
508
+ }
509
+
510
+ // Loading
511
+ rtb_booking_modal_submit.prop( 'disabled', true );
512
+ rtb_booking_modal_cancel.prop( 'disabled', true );
513
+ rtb_booking_modal_action_status.addClass( 'is-visible' );
514
+ rtb_show_action_status( rtb_booking_modal_action_status, 'loading' );
515
+
516
+ var params = {};
517
+
518
+ params.action = 'rtb-admin-booking-modal';
519
+ params.nonce = rtb_admin.nonce;
520
+ params.booking = rtb_booking_modal.find( 'form' ).serializeArray();
521
+
522
+ var data = $.param( params );
523
+
524
+ var jqhxr = $.post( ajaxurl, data, function( r ) {
525
+
526
+ if ( r.success ) {
527
+
528
+ // Refresh the page so that the new details are visible
529
+ window.location.reload();
530
+
531
+ } else {
532
+
533
+ // Validation failed
534
+ if ( r.data.error == 'invalid_booking_data' ) {
535
+
536
+ // Replace form fields with HTML returned
537
+ rtb_booking_modal_fields.html( r.data.fields );
538
+ rtb_init_booking_form_modal_fields();
539
+
540
+ // Logged out
541
+ } else if ( r.data.error == 'loggedout' ) {
542
+ rtb_booking_modal_fields.after( '<div class="rtb-error">' + r.data.msg + '</div>' );
543
+
544
+ // Unspecified error
545
+ } else {
546
+ rtb_booking_modal_fields.after( '<div class="rtb-error">' + rtb_admin.strings.error_unspecified + '</div>' );
547
+ }
548
+
549
+ rtb_booking_modal_cancel.prop( 'disabled', false );
550
+ rtb_booking_modal_submit.prop( 'disabled', false );
551
+ }
552
+
553
+ rtb_show_action_status( rtb_booking_modal_action_status, r.success );
554
+
555
+ // Hide result status icon after a few seconds
556
+ setTimeout( function() {
557
+ rtb_booking_modal.find( '.action-status' ).removeClass( 'is-visible' );
558
+ }, 4000 );
559
+ });
560
+ });
561
+
562
+ // Submit email form modal
563
+ rtb_email_modal_submit.click( function(e) {
564
+
565
+ e.preventDefault();
566
+ e.stopPropagation();
567
+
568
+ if ( $(this).prop( 'disabled' ) === true ) {
569
+ return;
570
+ }
571
+
572
+ // Loading
573
+ rtb_email_modal_submit.prop( 'disabled', true );
574
+ rtb_email_modal_cancel.prop( 'disabled', true );
575
+ rtb_email_modal_action_status.addClass( 'is-visible' );
576
+ rtb_show_action_status( rtb_email_modal_action_status, 'loading' );
577
+
578
+ var params = {};
579
+
580
+ params.action = 'rtb-admin-email-modal';
581
+ params.nonce = rtb_admin.nonce;
582
+ params.email = rtb_email_modal.find( 'form' ).serializeArray();
583
+
584
+ var data = $.param( params );
585
+
586
+ var jqhxr = $.post( ajaxurl, data, function( r ) {
587
+
588
+ if ( r.success ) {
589
+
590
+ rtb_show_action_status( rtb_email_modal_action_status, r.success );
591
+
592
+ // Hide result status icon after a few seconds
593
+ setTimeout( function() {
594
+ rtb_email_modal.find( '.action-status' ).removeClass( 'is-visible' );
595
+ rtb_toggle_email_modal( false );
596
+ }, 1000 );
597
+
598
+ } else {
599
+
600
+ if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
601
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
602
+ } else {
603
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
604
+ }
605
+
606
+ rtb_email_modal_cancel.prop( 'disabled', false );
607
+ rtb_email_modal_submit.prop( 'disabled', false );
608
+
609
+ rtb_show_action_status( rtb_email_modal_action_status, false );
610
+
611
+ // Hide result status icon after a few seconds
612
+ setTimeout( function() {
613
+ rtb_email_modal.find( '.action-status' ).removeClass( 'is-visible' );
614
+ }, 4000 );
615
+ }
616
+ });
617
+ });
618
+
619
+ // Submit column configuration modal
620
+ rtb_column_modal_submit.click( function(e) {
621
+
622
+ e.preventDefault();
623
+ e.stopPropagation();
624
+
625
+ if ( $(this).prop( 'disabled' ) === true ) {
626
+ return;
627
+ }
628
+
629
+ // Loading
630
+ rtb_column_modal_submit.prop( 'disabled', true );
631
+ rtb_column_modal_cancel.prop( 'disabled', true );
632
+ rtb_column_modal_action_status.addClass( 'is-visible' );
633
+ rtb_show_action_status( rtb_column_modal_action_status, 'loading' );
634
+
635
+ var params = {};
636
+
637
+ params.action = 'rtb-admin-column-modal';
638
+ params.nonce = rtb_admin.nonce;
639
+
640
+ params.columns = [];
641
+ rtb_column_modal.find( 'input[name="rtb-columns-config"]:checked' ).each( function() {
642
+ params.columns.push( $(this).val() );
643
+ });
644
+
645
+ var data = $.param( params );
646
+
647
+ var jqhxr = $.post( ajaxurl, data, function( r ) {
648
+
649
+ if ( r.success ) {
650
+
651
+ // Refresh the page so that the new details are visible
652
+ window.location.reload();
653
+
654
+ } else {
655
+
656
+ if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
657
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
658
+ } else {
659
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
660
+ }
661
+
662
+ rtb_column_modal_cancel.prop( 'disabled', false );
663
+ rtb_column_modal_submit.prop( 'disabled', false );
664
+ }
665
+
666
+ rtb_show_action_status( rtb_column_modal_action_status, r.success );
667
+
668
+ // Hide result status icon after a few seconds
669
+ setTimeout( function() {
670
+ rtb_column_modal.find( '.action-status' ).removeClass( 'is-visible' );
671
+ }, 4000 );
672
+ });
673
+ });
674
+
675
+ // Shared function for banning emails and IPs
676
+ function rtb_ban_modal_submit( e, type ) {
677
+
678
+ e.preventDefault();
679
+ e.stopPropagation();
680
+
681
+ if ( $(this).prop( 'disabled' ) === true ) {
682
+ return;
683
+ }
684
+
685
+ // Loading
686
+ if ( type === 'email' ) {
687
+ rtb_ban_modal_submit_email.prop( 'disabled', true );
688
+ } else if ( type === 'ip' ) {
689
+ rtb_ban_modal_submit_ip.prop( 'disabled', true );
690
+ }
691
+ rtb_ban_modal_cancel.prop( 'disabled', true );
692
+ rtb_ban_modal_action_status.addClass( 'is-visible' );
693
+ rtb_show_action_status( rtb_ban_modal_action_status, 'loading' );
694
+
695
+ var params = {};
696
+
697
+ params.action = 'rtb-admin-ban-modal';
698
+ params.nonce = rtb_admin.nonce;
699
+ if ( type === 'email' ) {
700
+ params.email = rtb_ban_modal.find( '#rtb-ban-modal-email' ).text();
701
+ } else if ( type === 'ip' ) {
702
+ params.ip = rtb_ban_modal.find( '#rtb-ban-modal-ip' ).text();
703
+ }
704
+
705
+ var data = $.param( params );
706
+
707
+ var jqhxr = $.post( ajaxurl, data, function( r ) {
708
+
709
+ if ( r.success ) {
710
+
711
+ if ( type === 'email' ) {
712
+ rtb_admin.banned_emails.push( params.email );
713
+ } else if ( type === 'ip' ) {
714
+ rtb_admin.banned_ips.push( params.ip );
715
+ }
716
+
717
+ rtb_show_action_status( rtb_ban_modal_action_status, r.success );
718
+
719
+ // Hide result status icon after a few seconds
720
+ setTimeout( function() {
721
+ rtb_ban_modal.find( '.action-status' ).removeClass( 'is-visible' );
722
+ }, 1000 );
723
+
724
+ } else {
725
+
726
+ if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
727
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
728
+ } else {
729
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
730
+ }
731
+
732
+ rtb_ban_modal_cancel.prop( 'disabled', false );
733
+ if ( type === 'email' ) {
734
+ rtb_ban_modal_submit_email.prop( 'disabled', false );
735
+ } else if ( type === 'ip' ) {
736
+ rtb_ban_modal_submit_ip.prop( 'disabled', false );
737
+ }
738
+
739
+ rtb_show_action_status( rtb_ban_modal_action_status, false );
740
+
741
+ // Hide result status icon after a few seconds
742
+ setTimeout( function() {
743
+ rtb_ban_modal.find( '.action-status' ).removeClass( 'is-visible' );
744
+ }, 4000 );
745
+ }
746
+ });
747
+ }
748
+
749
+ // Submit ban email form modal
750
+ rtb_ban_modal_submit_email.click( function(e) {
751
+ rtb_ban_modal_submit( e, 'email' );
752
+ });
753
+
754
+ // Submit ban ip form modal
755
+ rtb_ban_modal_submit_ip.click( function(e) {
756
+ rtb_ban_modal_submit( e, 'ip' );
757
+ });
758
+
759
+ // Delete customers by email
760
+ function rtb_delete_modal_submit( e ) {
761
+
762
+ e.preventDefault();
763
+ e.stopPropagation();
764
+
765
+ // Loading
766
+ rtb_delete_modal_submit_btn.prop( 'disabled', true );
767
+ rtb_delete_modal_cancel.prop( 'disabled', true );
768
+ rtb_delete_modal_action_status.addClass( 'is-visible' );
769
+ rtb_delete_modal_status.addClass('is-visible');
770
+ rtb_show_action_status( rtb_delete_modal_action_status, 'loading' );
771
+
772
+ function delete_page( params ) {
773
+
774
+ var jqhxr = $.post( ajaxurl, $.param( params ), function( r ) {
775
+
776
+ if ( r.success ) {
777
+
778
+ processed = processed + r.data.processed;
779
+ deleted = deleted + r.data.deleted;
780
+ var percent = Math.ceil( ( processed / r.data.total ) * 100 );
781
+ rtb_delete_modal_progress.css( 'width', percent + '%' );
782
+ rtb_delete_modal_deleted.text( deleted + ' bookings deleted' );
783
+
784
+ if ( processed < r.data.total ) {
785
+ params.page++;
786
+ delete_page( params );
787
+ } else {
788
+ rtb_delete_modal_cancel.click(function(e) {
789
+ window.location.reload();
790
+ });
791
+ rtb_delete_modal_deleted.text( 'Finished! ' + deleted + ' bookings deleted' );
792
+ rtb_delete_modal_cancel.prop( 'disabled', false );
793
+ rtb_delete_modal_submit_btn.css('display', 'none');
794
+ rtb_delete_modal_action_status.removeClass( 'is-visible' );
795
+ rtb_show_action_status( rtb_delete_modal_action_status, false );
796
+ }
797
+
798
+ } else {
799
+
800
+ if ( typeof r.data == 'undefined' || typeof r.data.error == 'undefined' ) {
801
+ rtb_toggle_booking_form_error_modal( true, rtb_admin.strings.error_unspecified );
802
+ } else {
803
+ rtb_toggle_booking_form_error_modal( true, r.data.msg );
804
+ }
805
+
806
+ rtb_delete_modal_submit_btn.prop( 'disabled', false );
807
+ rtb_delete_modal_cancel.prop( 'disabled', false );
808
+ rtb_delete_modal_action_status.removeClass( 'is-visible' );
809
+ rtb_delete_modal_status.removeClass( 'is-visible' );
810
+ rtb_show_action_status( rtb_delete_modal_action_status, false );
811
+ }
812
+ });
813
+ }
814
+
815
+ var processed = 0;
816
+ var deleted = 0;
817
+ delete_page({
818
+ action: 'rtb-admin-delete-modal',
819
+ nonce: rtb_admin.nonce,
820
+ email: rtb_delete_modal.find( '#rtb-delete-modal-email' ).text(),
821
+ page: 1,
822
+ });
823
+ }
824
+
825
+ // Submit ban email form modal
826
+ rtb_delete_modal_submit_btn.click( function(e) {
827
+ rtb_delete_modal_submit( e );
828
+ });
829
+
830
+ });
831
+
832
+
833
+ /* Javascript for Export Bookings for Restaurant Reservations admin */
834
+ jQuery(document).ready(function ($) {
835
+
836
+ /**
837
+ * Modal to generate an export
838
+ */
839
+ var ebfrtb_export_modal = $( '#ebfrtb-options-modal' );
840
+ var ebfrtb_export_modal_form = ebfrtb_export_modal.find( 'form' );
841
+ var ebfrtb_export_modal_date_range = ebfrtb_export_modal_form.find( '.date-range' );
842
+ var ebfrtb_export_modal_submit = ebfrtb_export_modal_form.find( 'button' );
843
+ var ebfrtb_export_modal_cancel = ebfrtb_export_modal_form.find( '#ebfrtb-cancel-export-modal' );
844
+
845
+ /**
846
+ * Show or hide the booking form modal
847
+ */
848
+ function ebfrtb_toggle_export_modal( show ) {
849
+
850
+ if ( show ) {
851
+ ebfrtb_export_modal.scrollTop( 0 ).addClass( 'is-visible' );
852
+ } else {
853
+ ebfrtb_export_modal.removeClass( 'is-visible' );
854
+ ebfrtb_export_modal_form.find( 'select option:selected' ).attr( 'selected', false );
855
+ ebfrtb_export_modal_date_range.find( '.selector .options a' ).first().trigger( 'click' );
856
+ ebfrtb_export_modal_form.find( '.status input' ).each( function() {
857
+ if ( $(this).val() === 'confirmed' ) {
858
+ $(this).attr( 'checked', true );
859
+ } else {
860
+ $(this).attr( 'checked', false );
861
+ }
862
+ });
863
+
864
+ if ( ebfrtb_picker_start_date && ebfrtb_picker_end_date ) {
865
+ ebfrtb_picker_start_date.pickadate( 'picker' ).clear();
866
+ ebfrtb_picker_end_date.pickadate( 'picker' ).clear();
867
+ }
868
+ }
869
+ }
870
+
871
+ // Show export modal
872
+ $( '.ebfrtb-export-button').click( function(e) {
873
+
874
+ e.stopPropagation();
875
+ e.preventDefault();
876
+
877
+ ebfrtb_toggle_export_modal( true );
878
+ });
879
+
880
+ // Close export modal when background or cancel button is clicked
881
+ ebfrtb_export_modal.click( function(e) {
882
+
883
+ if ( $(e.target).is( ebfrtb_export_modal ) ) {
884
+ ebfrtb_toggle_export_modal( false );
885
+ }
886
+
887
+ if ( $(e.target).is( ebfrtb_export_modal_cancel ) && ebfrtb_export_modal_cancel ) {
888
+ ebfrtb_toggle_export_modal( false );
889
+ }
890
+ });
891
+
892
+ // Close export modal when ESC is keyed
893
+ $( document ).keyup( function(e) {
894
+ if ( e.which == '27' ) {
895
+ ebfrtb_toggle_export_modal( false );
896
+ }
897
+ });
898
+
899
+ // Select a date option
900
+ ebfrtb_export_modal_date_range.find( '.selector .options' ).click( function(e) {
901
+
902
+ var target = $( e.target );
903
+
904
+ if ( target.hasClass( 'current' ) || !target.data( 'type' ) ) {
905
+ return;
906
+ }
907
+
908
+ // Set the hidden field value
909
+ ebfrtb_export_modal_date_range.find( 'input[name="date_range"]' ).val( target.data( 'type' ) );
910
+
911
+ // Reset date input fields
912
+ if ( ebfrtb_picker_start_date && ebfrtb_picker_end_date ) {
913
+ ebfrtb_picker_start_date.pickadate( 'picker' ).clear();
914
+ ebfrtb_picker_end_date.pickadate( 'picker' ).clear();
915
+ }
916
+
917
+ // Show selection details
918
+ ebfrtb_export_modal_date_range.find( '.selector > div' ).slideUp();
919
+ ebfrtb_export_modal_date_range.find( '.' + target.data( 'type' ) ).slideDown();
920
+
921
+ // Update current selection
922
+ ebfrtb_export_modal_date_range.find( '.options a' ).removeClass( 'current' );
923
+ target.addClass( 'current' );
924
+ })
925
+
926
+ // Select the first date option on page load
927
+ .find( 'a' ).first().trigger( 'click' );
928
+
929
+ // Load the date pickers
930
+ var ebfrtb_picker_start_date;
931
+ var ebfrtb_picker_end_date;
932
+ if ( typeof rtb_pickadate !== 'undefined' ) {
933
+
934
+ var settings = {
935
+ format: rtb_pickadate.date_format,
936
+ formatSubmit: 'yyyy-mm-dd',
937
+ hiddenName: true,
938
+ container: 'body'
939
+ };
940
+
941
+ ebfrtb_picker_start_date = $( '#ebfrtb-start-date' ).pickadate( settings );
942
+ ebfrtb_picker_end_date = $( '#ebfrtb-end-date' ).pickadate( settings );
943
+ }
944
+
945
+ // Load export
946
+ ebfrtb_export_modal_submit.click( function(e) {
947
+
948
+ e.stopPropagation();
949
+ e.preventDefault();
950
+
951
+ if ( $(this).prop( 'disabled' ) === true ) {
952
+ return;
953
+ }
954
+
955
+ var url = rtb_admin.export_url;
956
+ var statuses = [];
957
+ var form = ebfrtb_export_modal_form.serializeArray();
958
+ for( var i in form ) {
959
+
960
+ if ( form[i].name == 'status' ) {
961
+ statuses.push( form[i].value );
962
+ } else {
963
+ url += '&' + form[i].name + '=' + form[i].value;
964
+ }
965
+ }
966
+ url += '&status=' + statuses.join();
967
+
968
+ window.open( encodeURI( url ) );
969
+ });
970
+
971
+ });
972
+
973
+
974
+ /*NEW DASHBOARD MOBILE MENU AND WIDGET TOGGLING*/
975
+ jQuery(document).ready(function($){
976
+ $('#rtb-dash-mobile-menu-open').click(function(){
977
+ $('.rtb-admin-header-menu .nav-tab:nth-of-type(1n+2)').toggle();
978
+ $('#rtb-dash-mobile-menu-up-caret').toggle();
979
+ $('#rtb-dash-mobile-menu-down-caret').toggle();
980
+ return false;
981
+ });
982
+ $(function(){
983
+ $(window).resize(function(){
984
+ if($(window).width() > 800){
985
+ $('.rtb-admin-header-menu .nav-tab:nth-of-type(1n+2)').show();
986
+ }
987
+ else{
988
+ $('.rtb-admin-header-menu .nav-tab:nth-of-type(1n+2)').hide();
989
+ $('#rtb-dash-mobile-menu-up-caret').hide();
990
+ $('#rtb-dash-mobile-menu-down-caret').show();
991
+ }
992
+ }).resize();
993
+ });
994
+ $('#rtb-dashboard-support-widget-box .rtb-dashboard-new-widget-box-top').click(function(){
995
+ $('#rtb-dashboard-support-widget-box .rtb-dashboard-new-widget-box-bottom').toggle();
996
+ $('#rtb-dash-mobile-support-up-caret').toggle();
997
+ $('#rtb-dash-mobile-support-down-caret').toggle();
998
+ });
999
+ $('#rtb-dashboard-optional-table .rtb-dashboard-new-widget-box-top').click(function(){
1000
+ $('#rtb-dashboard-optional-table .rtb-dashboard-new-widget-box-bottom').toggle();
1001
+ $('#rtb-dash-optional-table-up-caret').toggle();
1002
+ $('#rtb-dash-optional-table-down-caret').toggle();
1003
+ });
1004
+ });
1005
+
1006
+ /*LOCK BOXES*/
1007
+ jQuery(document).ready(function($){
1008
+ $(function(){
1009
+ $(window).resize(function(){
1010
+ $('.rtb-premium-options-table-overlay').each(function(){
1011
+ var eachProTableOverlay = $(this);
1012
+ var associatedTable = eachProTableOverlay.next();
1013
+ var tableWidth = associatedTable.outerWidth(true);
1014
+ associatedTable.css('min-height', '240px');
1015
+ var tableHeight = associatedTable.outerHeight();
1016
+ var tablePosition = associatedTable.position();
1017
+ var tableLeft = tablePosition.left;
1018
+ var tableTop = tablePosition.top;
1019
+ eachProTableOverlay.css('width', tableWidth+'px');
1020
+ eachProTableOverlay.css('height', tableHeight+'px');
1021
+ eachProTableOverlay.css('left', tableLeft+'px');
1022
+ eachProTableOverlay.css('top', tableTop+'px');
1023
+ });
1024
+ }).resize();
1025
+ });
1026
+ });
1027
+
1028
+ //OPTIONS PAGE YES/NO TOGGLE SWITCHES
1029
+ jQuery(document).ready(function($){
1030
+ $('.rtb-admin-option-toggle').on('change', function() {
1031
+ var Input_Name = $(this).data('inputname'); console.log(Input_Name);
1032
+ if ($(this).is(':checked')) {
1033
+ $('input[name="' + Input_Name + '"][value="1"]').prop('checked', true).trigger('change');
1034
+ $('input[name="' + Input_Name + '"][value=""]').prop('checked', false);
1035
+ }
1036
+ else {
1037
+ $('input[name="' + Input_Name + '"][value="1"]').prop('checked', false).trigger('change');
1038
+ $('input[name="' + Input_Name + '"][value=""]').prop('checked', true);
1039
+ }
1040
+ });
1041
+ });
assets/js/booking-form.js CHANGED
@@ -89,6 +89,7 @@ jQuery(document).ready(function ($) {
89
  if ( Object.prototype.toString.call( time ) === "[object Date]" ) {
90
  this.set( 'select', time );
91
  }
 
92
  }
93
  }
94
  });
@@ -181,8 +182,8 @@ jQuery(document).ready(function ($) {
181
 
182
  var selected_date = new Date( rtb_booking_form.datepicker.get( 'select', 'yyyy/mm/dd' ) ),
183
  selected_date_year = selected_date.getFullYear(),
184
- selected_date_month = selected_date.getMonth(),
185
- selected_date_date = selected_date.getDate(),
186
  current_date = new Date();
187
 
188
  // Declaring the first element true inverts the timepicker settings. All
@@ -191,129 +192,147 @@ jQuery(document).ready(function ($) {
191
  // See: http://amsul.ca/pickadate.js/time/#disable-times-all
192
  var valid_times = [ rtb_booking_form.get_outer_time_range() ];
193
 
194
- // Check if this date is an exception to the rules
195
- if ( typeof rtb_pickadate.schedule_closed !== 'undefined' ) {
196
-
197
- var excp_date = [];
198
- var excp_start_date = [];
199
- var excp_start_time = [];
200
- var excp_end_date = [];
201
- var excp_end_time = [];
202
- for ( var closed_key in rtb_pickadate.schedule_closed ) {
203
-
204
- excp_date = new Date( rtb_pickadate.schedule_closed[closed_key].date );
205
- if ( excp_date.getFullYear() == selected_date_year &&
206
- excp_date.getMonth() == selected_date_month &&
207
- excp_date.getDate() == selected_date_date
208
- ) {
209
-
210
- // Closed all day
211
- if ( typeof rtb_pickadate.schedule_closed[closed_key].time == 'undefined' ) {
212
- rtb_booking_form.timepicker.set( 'disable', [ true ] );
213
 
214
- return;
215
- }
216
 
217
- if ( typeof rtb_pickadate.schedule_closed[closed_key].time.start !== 'undefined' ) {
218
- excp_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.start );
219
- excp_start_time = [ excp_start_date.getHours(), excp_start_date.getMinutes() ];
220
- } else {
221
- excp_start_time = [ 0, 0 ]; // Start of the day
222
- }
223
 
224
- if ( typeof rtb_pickadate.schedule_closed[closed_key].time.end !== 'undefined' ) {
225
- excp_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.end );
226
- excp_end_time = [ excp_end_date.getHours(), excp_end_date.getMinutes() ];
227
- } else {
228
- excp_end_time = [ 24, 0 ]; // End of the day
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  }
230
-
231
- excp_start_time = rtb_booking_form.get_earliest_time( excp_start_time, selected_date, current_date );
232
-
233
- valid_times.push( { from: excp_start_time, to: excp_end_time, inverted: true } );
 
 
 
 
 
234
  }
235
  }
236
-
237
- excp_date = excp_start_date = excp_start_time = excp_end_date = excp_end_time = null;
238
-
239
- // Exit early if this date is an exception
240
- if ( valid_times.length > 1 ) {
241
- rtb_booking_form.timepicker.set( 'disable', valid_times );
242
-
243
- return;
244
- }
245
- }
246
-
247
- // Get any rules which apply to this weekday
248
- if ( typeof rtb_pickadate.schedule_open != 'undefined' ) {
249
-
250
- var selected_date_weekday = selected_date.getDay();
251
-
252
- var weekdays = {
253
- sunday: 0,
254
- monday: 1,
255
- tuesday: 2,
256
- wednesday: 3,
257
- thursday: 4,
258
- friday: 5,
259
- saturday: 6,
260
- };
261
-
262
- var rule_start_date = [];
263
- var rule_start_time = [];
264
- var rule_end_date = [];
265
- var rule_end_time = [];
266
- for ( var open_key in rtb_pickadate.schedule_open ) {
267
-
268
- if ( typeof rtb_pickadate.schedule_open[open_key].weekdays !== 'undefined' ) {
269
- for ( var weekdays_key in rtb_pickadate.schedule_open[open_key].weekdays ) {
270
- if ( weekdays[weekdays_key] == selected_date_weekday ) {
271
-
272
- // Closed all day
273
- if ( typeof rtb_pickadate.schedule_open[open_key].time == 'undefined' ) {
274
- rtb_booking_form.timepicker.set( 'disable', [ true ] );
275
-
276
- return;
 
 
 
 
 
 
 
 
 
 
277
  }
278
-
279
- if ( typeof rtb_pickadate.schedule_open[open_key].time.start !== 'undefined' ) {
280
- rule_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.start );
281
- rule_start_time = [ rule_start_date.getHours(), rule_start_date.getMinutes() ];
282
- } else {
283
- rule_start_time = [ 0, 0 ]; // Start of the day
284
- }
285
-
286
- if ( typeof rtb_pickadate.schedule_open[open_key].time.end !== 'undefined' ) {
287
- rule_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.end );
288
- rule_end_time = rtb_booking_form.get_latest_viable_time( rule_end_date.getHours(), rule_end_date.getMinutes() );
289
- } else {
290
- rule_end_time = [ 24, 0 ]; // End of the day
291
- }
292
-
293
- rule_start_time = rtb_booking_form.get_earliest_time( rule_start_time, selected_date, current_date );
294
-
295
- valid_times.push( { from: rule_start_time, to: rule_end_time, inverted: true } );
296
-
297
  }
298
  }
299
  }
 
 
 
 
 
 
 
 
 
 
300
  }
301
 
302
- rule_start_date = rule_start_time = rule_end_date = rule_end_time = null;
303
-
304
- // Pass any valid times located
305
- if ( valid_times.length > 1 ) {
306
- rtb_booking_form.timepicker.set( 'disable', valid_times );
307
-
308
- return;
309
- }
310
-
311
  }
312
 
313
- // Set it to always open if no rules have been defined
314
- rtb_booking_form.timepicker.set( 'enable', true );
315
- rtb_booking_form.timepicker.set( 'disable', false );
316
-
317
  return;
318
  };
319
 
@@ -400,3 +419,50 @@ jQuery(document).ready(function ($) {
400
 
401
  rtb_booking_form.init();
402
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  if ( Object.prototype.toString.call( time ) === "[object Date]" ) {
90
  this.set( 'select', time );
91
  }
92
+
93
  }
94
  }
95
  });
182
 
183
  var selected_date = new Date( rtb_booking_form.datepicker.get( 'select', 'yyyy/mm/dd' ) ),
184
  selected_date_year = selected_date.getFullYear(),
185
+ selected_date_month = ('0' + (selected_date.getMonth()+1)).slice(-2),
186
+ selected_date_date = ('0' + selected_date.getDate()).slice(-2),
187
  current_date = new Date();
188
 
189
  // Declaring the first element true inverts the timepicker settings. All
192
  // See: http://amsul.ca/pickadate.js/time/#disable-times-all
193
  var valid_times = [ rtb_booking_form.get_outer_time_range() ];
194
 
195
+ if ( rtb_pickadate.enable_max_reservations ) {
196
+
197
+ var data = 'year=' + selected_date_year + '&month=' + selected_date_month + '&day=' + selected_date_date + '&action=rtb_get_available_time_slots';
198
+ jQuery.post( ajaxurl, data, function( response ) {
199
+ if ( ! response ) {
200
+ rtb_booking_form.timepicker.set( 'disable', true );
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
+ return;
203
+ }
204
 
205
+ var additional_valid_times = jQuery.parseJSON( response );
206
+ var all_valid_times = valid_times.concat( additional_valid_times );
207
+ rtb_booking_form.timepicker.set( 'disable', all_valid_times );
208
+ });
209
+ }
 
210
 
211
+ else {
212
+ // Check if this date is an exception to the rules
213
+ if ( typeof rtb_pickadate.schedule_closed !== 'undefined' ) {
214
+
215
+ var excp_date = [];
216
+ var excp_start_date = [];
217
+ var excp_start_time = [];
218
+ var excp_end_date = [];
219
+ var excp_end_time = [];
220
+ for ( var closed_key in rtb_pickadate.schedule_closed ) {
221
+
222
+ excp_date = new Date( rtb_pickadate.schedule_closed[closed_key].date );
223
+ if ( excp_date.getFullYear() == selected_date_year &&
224
+ excp_date.getMonth() == selected_date_month &&
225
+ excp_date.getDate() == selected_date_date
226
+ ) {
227
+
228
+ // Closed all day
229
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time == 'undefined' ) {
230
+ rtb_booking_form.timepicker.set( 'disable', [ true ] );
231
+
232
+ return;
233
+ }
234
+
235
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time.start !== 'undefined' ) {
236
+ excp_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.start );
237
+ excp_start_time = [ excp_start_date.getHours(), excp_start_date.getMinutes() ];
238
+ } else {
239
+ excp_start_time = [ 0, 0 ]; // Start of the day
240
+ }
241
+
242
+ if ( typeof rtb_pickadate.schedule_closed[closed_key].time.end !== 'undefined' ) {
243
+ excp_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_closed[closed_key].time.end );
244
+ excp_end_time = [ excp_end_date.getHours(), excp_end_date.getMinutes() ];
245
+ } else {
246
+ excp_end_time = [ 24, 0 ]; // End of the day
247
+ }
248
+
249
+ excp_start_time = rtb_booking_form.get_earliest_time( excp_start_time, selected_date, current_date );
250
+
251
+ valid_times.push( { from: excp_start_time, to: excp_end_time, inverted: true } );
252
  }
253
+ }
254
+
255
+ excp_date = excp_start_date = excp_start_time = excp_end_date = excp_end_time = null;
256
+
257
+ // Exit early if this date is an exception
258
+ if ( valid_times.length > 1 ) {
259
+ rtb_booking_form.timepicker.set( 'disable', valid_times );
260
+
261
+ return;
262
  }
263
  }
264
+
265
+ // Get any rules which apply to this weekday
266
+ if ( typeof rtb_pickadate.schedule_open != 'undefined' ) {
267
+
268
+ var selected_date_weekday = selected_date.getDay();
269
+
270
+ var weekdays = {
271
+ sunday: 0,
272
+ monday: 1,
273
+ tuesday: 2,
274
+ wednesday: 3,
275
+ thursday: 4,
276
+ friday: 5,
277
+ saturday: 6,
278
+ };
279
+
280
+ var rule_start_date = [];
281
+ var rule_start_time = [];
282
+ var rule_end_date = [];
283
+ var rule_end_time = [];
284
+ for ( var open_key in rtb_pickadate.schedule_open ) {
285
+
286
+ if ( typeof rtb_pickadate.schedule_open[open_key].weekdays !== 'undefined' ) {
287
+ for ( var weekdays_key in rtb_pickadate.schedule_open[open_key].weekdays ) {
288
+ if ( weekdays[weekdays_key] == selected_date_weekday ) {
289
+
290
+ // Closed all day
291
+ if ( typeof rtb_pickadate.schedule_open[open_key].time == 'undefined' ) {
292
+ rtb_booking_form.timepicker.set( 'disable', [ true ] );
293
+
294
+ return;
295
+ }
296
+
297
+ if ( typeof rtb_pickadate.schedule_open[open_key].time.start !== 'undefined' ) {
298
+ rule_start_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.start );
299
+ rule_start_time = [ rule_start_date.getHours(), rule_start_date.getMinutes() ];
300
+ } else {
301
+ rule_start_time = [ 0, 0 ]; // Start of the day
302
+ }
303
+
304
+ if ( typeof rtb_pickadate.schedule_open[open_key].time.end !== 'undefined' ) {
305
+ rule_end_date = new Date( '1 January 2000 ' + rtb_pickadate.schedule_open[open_key].time.end );
306
+ rule_end_time = rtb_booking_form.get_latest_viable_time( rule_end_date.getHours(), rule_end_date.getMinutes() );
307
+ } else {
308
+ rule_end_time = [ 24, 0 ]; // End of the day
309
+ }
310
+
311
+ rule_start_time = rtb_booking_form.get_earliest_time( rule_start_time, selected_date, current_date );
312
+
313
+ valid_times.push( { from: rule_start_time, to: rule_end_time, inverted: true } );
314
+
315
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  }
317
  }
318
  }
319
+
320
+ rule_start_date = rule_start_time = rule_end_date = rule_end_time = null;
321
+
322
+ // Pass any valid times located
323
+ if ( valid_times.length > 1 ) {
324
+ rtb_booking_form.timepicker.set( 'disable', valid_times );
325
+
326
+ return;
327
+ }
328
+
329
  }
330
 
331
+ // Set it to always open if no rules have been defined
332
+ rtb_booking_form.timepicker.set( 'enable', true );
333
+ rtb_booking_form.timepicker.set( 'disable', false );
 
 
 
 
 
 
334
  }
335
 
 
 
 
 
336
  return;
337
  };
338
 
419
 
420
  rtb_booking_form.init();
421
  });
422
+
423
+ // Functions for the 'View Bookings' shortcode
424
+ jQuery(document).ready(function ($) {
425
+ jQuery('.rtb-view-bookings-form-date-selector').on('change', function() {
426
+ window.location.href = replaceUrlParam(window.location.href, 'date', jQuery(this).val());
427
+ });
428
+
429
+ jQuery('.rtb-edit-view-booking').on('click', function() {
430
+ jQuery('.rtb-view-bookings-form-confirmation-div, .rtb-view-bookings-form-confirmation-background-div').removeClass('rtb-hidden');
431
+
432
+ jQuery('.rtb-view-bookings-form-confirmation-div').data('bookingid', jQuery(this).data('bookingid'));
433
+
434
+ jQuery(this).prop('checked', false);
435
+ });
436
+
437
+ jQuery('.rtb-view-bookings-form-confirmation-accept').on('click', function() {
438
+ var booking_id = jQuery('.rtb-view-bookings-form-confirmation-div').data('bookingid');
439
+
440
+ var data = 'booking_id=' + booking_id + '&action=rtb_set_reservation_arrived';
441
+ jQuery.post(ajaxurl, data, function(response) {
442
+
443
+ if (response.success) {window.location.href = window.location.href}
444
+ else {jQuery('.rtb-view-bookings-form-confirmation-div').html(response.data.msg);}
445
+ });
446
+ });
447
+
448
+ jQuery('.rtb-view-bookings-form-confirmation-decline').on('click', function() {
449
+ jQuery('.rtb-view-bookings-form-confirmation-div, .rtb-view-bookings-form-confirmation-background-div').addClass('rtb-hidden');
450
+ });
451
+
452
+ jQuery('.rtb-view-bookings-form-confirmation-background-div').on('click', function() {
453
+ jQuery('.rtb-view-bookings-form-confirmation-div, .rtb-view-bookings-form-confirmation-background-div').addClass('rtb-hidden');
454
+ });
455
+ });
456
+
457
+ function replaceUrlParam(url, paramName, paramValue)
458
+ {
459
+ if (paramValue == null) {
460
+ paramValue = '';
461
+ }
462
+ var pattern = new RegExp('\\b('+paramName+'=).*?(&|#|$)');
463
+ if (url.search(pattern)>=0) {
464
+ return url.replace(pattern,'$1' + paramValue + '$2');
465
+ }
466
+ url = url.replace(/[?#]$/,'');
467
+ return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue;
468
+ }
assets/js/columns.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($){
2
+ $(function(){
3
+ $(window).resize(function(){
4
+ $('.rtb-booking-form form button').each(function(){
5
+ var thisButton = $(this);
6
+ var buttonHalfWidthBig = ( thisButton.width() / 2 ) + 56;
7
+ var buttonHalfWidthSmall = ( thisButton.width() / 2 ) + 28;
8
+ if( $(window).width() > 768 ){
9
+ thisButton.css('margin-left', 'calc(50% - '+buttonHalfWidthBig+'px');
10
+ }
11
+ else{
12
+ thisButton.css('margin-left', 'calc(50% - '+buttonHalfWidthSmall+'px');
13
+ }
14
+ });
15
+ }).resize();
16
+ });
17
+ });
assets/js/contemporary.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($){
2
+ $(function(){
3
+ $(window).resize(function(){
4
+ $('.rtb-booking-form form').each(function(){
5
+ var thisForm = $(this);
6
+ var formWidth = thisForm.width();
7
+ if(formWidth < 900){
8
+ thisForm.find('fieldset.reservation .rtb-select').css('left', '0');
9
+ thisForm.find('fieldset.contact .rtb-text.phone').css('left', '0');
10
+ }
11
+ if(formWidth < 600){
12
+ thisForm.find('fieldset.reservation .rtb-text.time').css('left', '0');
13
+ thisForm.find('fieldset.contact .rtb-text.email').css('left', '0');
14
+ }
15
+ if(formWidth > 599){
16
+ thisForm.find('fieldset.reservation .rtb-text.time').css('left', '-1px');
17
+ thisForm.find('fieldset.contact .rtb-text.email').css('left', '-1px');
18
+ }
19
+ if(formWidth > 899){
20
+ thisForm.find('fieldset.reservation .rtb-select').css('left', '-2px');
21
+ thisForm.find('fieldset.contact .rtb-text.phone').css('left', '-2px');
22
+ }
23
+ });
24
+ }).resize();
25
+ });
26
+ });
assets/js/customizer-control.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global wp, jQuery */
2
+
3
+ /**
4
+ * Initialize the customizer controls
5
+ *
6
+ * @since 0.1
7
+ */
8
+ (function( api, $ ) {
9
+
10
+ api.etfrtb = api.etfrtb || {};
11
+
12
+ /**
13
+ * Update a URI query string parameter
14
+ *
15
+ * @see http://stackoverflow.com/a/6021027
16
+ * @param string uri The original URI
17
+ * @param string key The parameter key to add/update
18
+ * @param string value The value to insert
19
+ * @since 0.1
20
+ */
21
+ api.etfrtb.updateQueryStringParam = function( uri, key, value ) {
22
+ var re = new RegExp( "([?&])" + key + "=.*?(&|$)", "i" ),
23
+ separator = uri.indexOf( '?' ) !== -1 ? "&" : "?";
24
+
25
+ key = encodeURIComponent( key );
26
+ value = encodeURIComponent( value );
27
+
28
+ if ( uri.match( re ) ) {
29
+ return uri.replace( re, '$1' + key + "=" + value + '$2' );
30
+ } else {
31
+ return uri + separator + key + "=" + value;
32
+ }
33
+ };
34
+
35
+ api.bind( 'ready', function() {
36
+ api.section.each( function( section ) {
37
+ section.expanded.bind( function( expanded ) {
38
+ if ( expanded && section.id !== 'etfrtb_style' ) {
39
+ api.etfrtb.load_email( section.id );
40
+ }
41
+ } );
42
+ } );
43
+ } );
44
+
45
+ api.etfrtb.load_email = function( email ) {
46
+ var email_type = email.replace( 'etfrtb-content-', '' ),
47
+ url = api.etfrtb.updateQueryStringParam( api.previewer.previewUrl.get(), 'etfrtb_designer_email', email_type );
48
+
49
+ api.previewer.previewUrl.set( url );
50
+ };
51
+
52
+ }( wp.customize, jQuery ) );
assets/js/customizer-control.min.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ /*! email-templates-for-rtb 2017-05-05 */
2
+ !function(a,b){a.etfrtb=a.etfrtb||{},a.etfrtb.updateQueryStringParam=function(a,b,c){var d=new RegExp("([?&])"+b+"=.*?(&|$)","i"),e=a.indexOf("?")!==-1?"&":"?";return b=encodeURIComponent(b),c=encodeURIComponent(c),a.match(d)?a.replace(d,"$1"+b+"="+c+"$2"):a+e+b+"="+c},a.bind("ready",function(){a.section.each(function(b){b.expanded.bind(function(c){c&&"etfrtb_style"!==b.id&&a.etfrtb.load_email(b.id)})})}),a.etfrtb.load_email=function(b){var c=b.replace("etfrtb-content-",""),d=a.etfrtb.updateQueryStringParam(a.previewer.previewUrl.get(),"etfrtb_designer_email",c);a.previewer.previewUrl.set(d)}}(wp.customize,jQuery);
assets/js/editor.js ADDED
@@ -0,0 +1,1236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom fields editor for Custom Fields for Restaurant Reservations
3
+ */
4
+ var cffrtb_editor = cffrtb_editor || {};
5
+
6
+ /**
7
+ * Initialize the editor object after jQuery has loaded
8
+ */
9
+ jQuery(document).ready(function ($) {
10
+
11
+ /**
12
+ * jQuery reference for editor panel
13
+ */
14
+ cffrtb_editor.el = $( '#cffrtb-editor' );
15
+
16
+ /**
17
+ * Show the error modal
18
+ */
19
+ cffrtb_editor.show_error = function( msg ) {
20
+
21
+ var rtb_error_modal = $( '#rtb-error-modal ' );
22
+
23
+ rtb_error_modal.find( '.rtb-error-msg' ).html( msg );
24
+ rtb_error_modal.addClass( 'is-visible' );
25
+
26
+ $(document).keyup( function(e) {
27
+ if ( e.which == '27' ) {
28
+ cffrtb_editor.hide_error( rtb_error_modal );
29
+ }
30
+ });
31
+
32
+ rtb_error_modal.click( function(e) {
33
+ if ( $(e.target).is( rtb_error_modal ) || $(e.target).is( rtb_error_modal.find( 'a.button' ) ) ) {
34
+
35
+ e.stopPropagation();
36
+ e.preventDefault();
37
+
38
+ cffrtb_editor.hide_error( rtb_error_modal );
39
+ }
40
+ });
41
+ };
42
+
43
+ /**
44
+ * Hide the error modal
45
+ */
46
+ cffrtb_editor.hide_error = function( el ) {
47
+ el.removeClass( 'is-visible' );
48
+ el.off();
49
+ };
50
+
51
+ });
52
+
53
+ /**
54
+ * Initialize the field editor after jQuery has loaded
55
+ */
56
+ jQuery(document).ready(function ($) {
57
+
58
+ /**
59
+ * Manage the field editor
60
+ */
61
+ cffrtb_editor.editor = {
62
+
63
+ el: $( '#cffrtb-field-editor' ),
64
+
65
+ option_el: $( '#cffrtb-field-editor-option' ),
66
+
67
+ init: function() {
68
+
69
+ // Store common form references
70
+ this.form = {
71
+ el: this.el.find( '#cffrtb-field-editor-form' ),
72
+ id: this.el.find( 'input[name="id"]' ),
73
+ type: this.el.find( 'input[name="type"]' ),
74
+ subtype: this.el.find( 'input[name="subtype"]' ),
75
+ };
76
+
77
+ // Show field editor option modal
78
+ $( '.add-field' ).click( function(e) {
79
+ e.stopPropagation();
80
+ e.preventDefault();
81
+
82
+ cffrtb_editor.editor.show_option();
83
+ });
84
+
85
+ // Register click events on options modal
86
+ this.option_el.click( function(e) {
87
+ e.stopPropagation();
88
+ e.preventDefault();
89
+
90
+ var target = $( e.target );
91
+
92
+ if ( target.hasClass( 'field' ) ) {
93
+ cffrtb_editor.editor.hide_option();
94
+ cffrtb_editor.editor.show_editor();
95
+
96
+ } else if ( target.hasClass( 'fieldset' ) ) {
97
+ cffrtb_editor.editor.hide_option();
98
+ cffrtb_editor.editor.show_editor( 'fieldset' );
99
+
100
+ } else if ( target.is( cffrtb_editor.editor.option_el ) ) {
101
+ cffrtb_editor.editor.hide_option();
102
+ }
103
+ });
104
+
105
+ // Close field editor modal when background is clicked
106
+ this.el.click( function(e) {
107
+ if ( $( e.target ).is( cffrtb_editor.editor.el ) ) {
108
+ cffrtb_editor.editor.hide_editor();
109
+ }
110
+ });
111
+
112
+ // Close field editor modal when ESC is keyed
113
+ $(document).keyup( function(e) {
114
+ if ( e.which == '27' ) {
115
+ cffrtb_editor.editor.hide_editor();
116
+ }
117
+ });
118
+
119
+ // Form actions
120
+ this.form.el.find( '> .actions' ).on( 'click', function(e) {
121
+
122
+ e.stopPropagation();
123
+ e.preventDefault();
124
+
125
+ var target = $( e.target );
126
+
127
+ // Exit early if the actions are disabled
128
+ if ( typeof target.attr( 'disabled' ) !== 'undefined' ) {
129
+ return;
130
+ }
131
+
132
+ // Save field
133
+ if ( target.hasClass( 'save' ) ) {
134
+ cffrtb_editor.editor.save_field();
135
+
136
+ // Cancel and close editor
137
+ } else if ( target.hasClass( 'cancel' ) ) {
138
+ cffrtb_editor.editor.hide_editor();
139
+ }
140
+ });
141
+
142
+ // Field type selections
143
+ this.form.el.find( '.type .selector' ).on( 'click', function(e) {
144
+
145
+ var target = $( e.target );
146
+
147
+ if ( target.get(0).tagName != 'A' ) {
148
+ return;
149
+ }
150
+
151
+ var level = target.parent().parent();
152
+
153
+ if ( target.parent().parent().hasClass( 'types' ) ) {
154
+ cffrtb_editor.editor.set_type( target.data( 'type' ), target );
155
+
156
+ } else {
157
+ cffrtb_editor.editor.set_subtype( target.data( 'subtype' ), target );
158
+ }
159
+
160
+ });
161
+
162
+ // Add an option
163
+ this.el.find( '.settings-panel.options .add a' ).on( 'click', function(e) {
164
+ e.stopPropagation();
165
+ e.preventDefault();
166
+ cffrtb_editor.editor.add_option();
167
+ });
168
+
169
+ // Add an option with ENTER key
170
+ this.get_add_option_el().keyup( function(e) {
171
+ if ( e.which == '13' ) {
172
+ e.stopPropagation();
173
+ e.preventDefault();
174
+
175
+ cffrtb_editor.editor.add_option();
176
+ }
177
+ });
178
+
179
+ // Remove an option
180
+ this.get_options_list_el().on( 'click', function(e) {
181
+ e.stopPropagation();
182
+ e.preventDefault();
183
+
184
+ var target = $( e.target );
185
+
186
+ if( target.is( 'a, a .dashicons' ) ) {
187
+ cffrtb_editor.editor.remove_option( target.closest( 'li' ) );
188
+ }
189
+ });
190
+
191
+ // Make the option list sortable
192
+ this.get_options_list_el().sortable({
193
+ placeholder: 'cffrtb-editor-options-placeholder',
194
+ delay: 250
195
+ });
196
+
197
+ },
198
+
199
+ /**
200
+ * Get the add option input element
201
+ */
202
+ get_add_option_el: function() {
203
+
204
+ if ( typeof this.form.add_option == 'undefined' ) {
205
+ this.form.add_option = this.el.find( '.settings-panel.options .add input' );
206
+ }
207
+
208
+ return this.form.add_option;
209
+ },
210
+
211
+ /**
212
+ * Get the options list element
213
+ */
214
+ get_options_list_el: function() {
215
+
216
+ if ( typeof this.form.options_list == 'undefined' ) {
217
+ this.form.options_list = this.el.find( '.settings-panel.options .options' );
218
+ }
219
+
220
+ return this.form.options_list;
221
+ },
222
+
223
+ /**
224
+ * Update the editor values with a new field object
225
+ */
226
+ update_editor_values: function( field ) {
227
+
228
+ this.form.id.val( field.ID );
229
+ this.set_type( field.type );
230
+ this.set_subtype( field.subtype );
231
+ this.form.el.find( 'input[name="title"]' ).val( field.title );
232
+
233
+ if ( field.required ) {
234
+ this.form.el.find( '.required input' ).attr( 'checked', 'checked' );
235
+ }
236
+
237
+ if ( field.options && Object.keys( field.options ).length ) {
238
+ var options = '';
239
+ for( var i in field.options ) {
240
+ if ( field.options[i].disabled ) {
241
+ continue;
242
+ }
243
+ options += '<li data-id="' + field.options[i].id + '"><a href="#"><span class="dashicons dashicons-dismiss"></span></a> <span class="value">' + field.options[i].value + '</span></li>';
244
+ }
245
+ this.form.el.find( '.settings-panel.options .options' ).html( options );
246
+ }
247
+
248
+ this.el.trigger( 'cffrtb_update_editor_values', field );
249
+ },
250
+
251
+ /**
252
+ * Show the field/fieldset type selection before opening the editor
253
+ */
254
+ show_option: function() {
255
+
256
+ this.option_el.addClass( 'is-visible' );
257
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
258
+
259
+ },
260
+
261
+ /**
262
+ * Hide the field/fieldset type selection
263
+ */
264
+ hide_option: function() {
265
+
266
+ this.option_el.removeClass( 'is-visible' );
267
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
268
+
269
+ },
270
+
271
+ /**
272
+ * Show the editor
273
+ */
274
+ show_editor: function( mode ) {
275
+
276
+ if ( mode === 'edit' ) {
277
+ this.form.el.find( '> .title > h2' ).html( cffrtb_editor.strings.editor_edit_field );
278
+ this.form.el.find( '.actions a.save' ).html( cffrtb_editor.strings.editor_save_field );
279
+ } else if ( mode == 'fieldset' ) {
280
+ this.form.el.find( '> .title > h2' ).html( cffrtb_editor.strings.editor_add_fieldset );
281
+ this.form.el.find( '.actions a.save' ).addClass( 'fieldset' ).html( cffrtb_editor.strings.editor_save_fieldset );
282
+ this.form.el.addClass( mode );
283
+ this.form.type.val( 'fieldset' );
284
+ this.form.subtype.val( 'fieldset' );
285
+ } else {
286
+ this.form.el.find( '> .title > h2' ).html( cffrtb_editor.strings.editor_add_field );
287
+ this.form.el.find( '.actions a.save' ).html( cffrtb_editor.strings.editor_add_field );
288
+ }
289
+
290
+ this.el.addClass( 'is-visible' );
291
+ $( 'body' ).addClass( 'rtb-hide-body-scroll' );
292
+ },
293
+
294
+ /**
295
+ * Hide the editor
296
+ */
297
+ hide_editor: function() {
298
+ this.el.removeClass( 'is-visible' );
299
+ this.option_el.removeClass( 'is-hidden' );
300
+ this.form.el.addClass( 'is-hidden' );
301
+ this.form.el.removeClass( 'fieldset' );
302
+ this.form.el.find( '.actions a.save' ).removeClass( 'fieldset' );
303
+ $( 'body' ).removeClass( 'rtb-hide-body-scroll' );
304
+ this.form.el.find( 'input, select, textarea' ).not( 'input[type="checkbox"]' ).val( '' );
305
+ this.form.el.find( 'input[type="checkbox"]' ).removeAttr( 'checked' );
306
+ this.get_options_list_el().empty();
307
+ this.set_type( cffrtb_editor.default_type );
308
+ this.set_subtype( cffrtb_editor.default_subtype );
309
+ },
310
+
311
+ /**
312
+ * Set the type and select the new subtype
313
+ */
314
+ set_type: function( type, el ) {
315
+
316
+ if ( type == this.form.type.val() ) {
317
+ return;
318
+ }
319
+
320
+ // Set the value
321
+ this.form.type.val( type );
322
+
323
+ // Remove the `current` class from the selection
324
+ this.el.find( '.type .types a' ).removeClass( 'current' );
325
+
326
+ // Add the `current` class to this selection
327
+ if ( typeof el == 'undefined' ) {
328
+ el = this.el.find( '.type .types .' + type );
329
+ }
330
+ el.addClass( 'current' );
331
+
332
+ // Show the settings if they exist
333
+ this.el.find( '.settings-panel' ).each( function() {
334
+ if ( $(this).hasClass( type ) ) {
335
+ $(this).addClass( 'current' );
336
+ } else {
337
+ $(this).removeClass( 'current' );
338
+ }
339
+ });
340
+
341
+ // Show the subtype list
342
+ this.el.find( '.type .subtypes' ).each( function() {
343
+ if ( $(this).hasClass( type ) ) {
344
+ $(this).addClass( 'current' );
345
+ } else {
346
+ $(this).removeClass( 'current' );
347
+ }
348
+ });
349
+
350
+ // Trigger a click on the first subtype for this type
351
+ this.el.find( '.subtypes.' + type + ' li' ).first().find( 'a' ).trigger( 'click' );
352
+ },
353
+
354
+ /**
355
+ * Select a subtype
356
+ */
357
+ set_subtype: function( subtype, el ) {
358
+
359
+ if ( subtype == this.form.subtype.val() ) {
360
+ return;
361
+ }
362
+
363
+ // Set the value
364
+ this.form.subtype.val( subtype );
365
+
366
+ // Remove the `current` class from the selection
367
+ this.el.find( '.type .subtypes a' ).removeClass( 'current' );
368
+
369
+ // Apply the `current` class to the right subtype
370
+ if ( typeof el == 'undefined' ) {
371
+ el = this.el.find( '.type .subtypes .' + subtype );
372
+ }
373
+ el.addClass( 'current' );
374
+
375
+ },
376
+
377
+ /**
378
+ * Add an option to the list
379
+ */
380
+ add_option: function() {
381
+ var list = this.get_options_list_el();
382
+ var option = this.get_add_option_el();
383
+
384
+ this.get_options_list_el().append( '<li><a href="#"><span class="dashicons dashicons-dismiss"></span></a> <span class="value">' + this.get_add_option_el().val() + '</span></li>' );
385
+ this.get_add_option_el().val( '' );
386
+
387
+ // Scroll the options list if they have more than 10
388
+ if ( this.get_options_list_el().find( 'li' ).length > 10 ) {
389
+ this.get_options_list_el().addClass( 'scroll' );
390
+ }
391
+ },
392
+
393
+ /**
394
+ * Remove an option from the list
395
+ */
396
+ remove_option: function( el ) {
397
+
398
+ el.fadeOut( '200', function() {
399
+ $(this).remove();
400
+
401
+ // Remove scrollbar if the options list is less than 10 options
402
+ if ( cffrtb_editor.editor.get_options_list_el().find( 'li' ).length <= 10 ) {
403
+ cffrtb_editor.editor.get_options_list_el().removeClass( 'scroll' );
404
+ }
405
+ });
406
+ },
407
+
408
+ /**
409
+ * Disable actions
410
+ */
411
+ disable_actions: function() {
412
+ this.form.el.find( '.actions' ).addClass( 'working' ).find( '.save, .cancel' ).attr( 'disabled', 'disabled' );
413
+ },
414
+
415
+ /**
416
+ * Enable actions
417
+ */
418
+ enable_actions: function() {
419
+ this.form.el.find( '.actions' ).removeClass( 'working' ).find( '.save, .cancel' ).removeAttr( 'disabled' );
420
+ },
421
+
422
+ /**
423
+ * Load field
424
+ */
425
+ load_field: function( item_slug ) {
426
+
427
+ // Don't trigger if we're already saving
428
+ if ( cffrtb_editor.list.get_title_el( item_slug ).hasClass( 'saving' ) ) {
429
+ return;
430
+ }
431
+
432
+ var id = cffrtb_editor.list.items[item_slug].el.data( 'id' );
433
+ if ( typeof id == 'undefined' ) {
434
+ return;
435
+ }
436
+
437
+ cffrtb_editor.list.disable_sorting();
438
+ cffrtb_editor.list.get_title_el( item_slug ).addClass( 'saving' );
439
+ cffrtb_editor.list.get_title_el( item_slug ).find( '.view .controls' ).prepend( '<span class="load-spinner"></span>' );
440
+
441
+ var params = {};
442
+
443
+ params.action = 'cffrtb-load-field';
444
+ params.nonce = cffrtb_editor.ajax_nonce;
445
+ params.ID = id;
446
+
447
+ var data = $.param( params );
448
+
449
+ $.post( ajaxurl, data, function( r ) {
450
+
451
+ if ( r.success ) {
452
+ cffrtb_editor.editor.update_editor_values( r.data.field );
453
+ cffrtb_editor.editor.show_editor( 'edit' );
454
+
455
+ } else {
456
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
457
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
458
+ } else {
459
+ cffrtb_editor.show_error( r.data.msg );
460
+ }
461
+ }
462
+
463
+ // Reset status
464
+ cffrtb_editor.list.enable_sorting();
465
+ cffrtb_editor.list.get_title_el( item_slug ).removeClass( 'saving' );
466
+ cffrtb_editor.list.get_title_el( item_slug ).find( '.view .controls .load-spinner' ).fadeOut( 400, function() { $(this).remove(); });
467
+ });
468
+
469
+ },
470
+
471
+ /**
472
+ * Save a field
473
+ */
474
+ save_field: function() {
475
+
476
+ this.disable_actions();
477
+
478
+ var params = {};
479
+
480
+ params.action = 'cffrtb-save-field';
481
+ params.nonce = cffrtb_editor.ajax_nonce;
482
+ params.request = 'save_field';
483
+ params.field = {
484
+ ID: this.form.id.val(),
485
+ type: this.form.type.val(),
486
+ subtype: this.form.subtype.val(),
487
+ title: this.form.el.find( 'input[name="title"]' ).val(),
488
+ };
489
+
490
+ if ( this.form.el.find( 'input[name="required"]' ).is( ':checked' ) ) {
491
+ params.field.required = 1;
492
+ } else {
493
+ params.field.required = 0;
494
+ }
495
+
496
+ if ( params.field.type == 'options' ) {
497
+ params.field.options = {};
498
+ this.get_options_list_el().find( 'li' ).each( function(i) {
499
+
500
+ var id = $(this).data( 'id' );
501
+ if ( typeof id == 'undefined' ) {
502
+ id = 'new-' + Math.random().toString(36).substring(7);
503
+ }
504
+
505
+ params.field.options[i] = {
506
+ id: id,
507
+ value: $(this).find( '.value' ).html(),
508
+ order: i
509
+ };
510
+ });
511
+ }
512
+
513
+ // Perform some basic validation checks here
514
+ var errors = this.validate_field( params.field );
515
+ if ( typeof errors !== 'undefined' ) {
516
+ cffrtb_editor.show_error( errors );
517
+ this.enable_actions();
518
+
519
+ return;
520
+ }
521
+
522
+ var data = $.param( params );
523
+
524
+ $.post( ajaxurl, data, function( r ) {
525
+
526
+ if ( r.success ) {
527
+ cffrtb_editor.editor.hide_editor();
528
+ cffrtb_editor.list.add_item( r.data.field, r.data.ID, r.data.is_new_field, r.data.type );
529
+
530
+ } else {
531
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
532
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
533
+ } else {
534
+ console.log( r.data );
535
+ cffrtb_editor.show_error( r.data.msg );
536
+ }
537
+ }
538
+
539
+ cffrtb_editor.editor.enable_actions();
540
+ });
541
+ },
542
+
543
+ /**
544
+ * Some quick validation on the field data before sending it off
545
+ */
546
+ validate_field: function( field ) {
547
+
548
+ if ( field.title.length === 0 || !field.title.trim() ) {
549
+ return cffrtb_editor.strings.field_missing_title;
550
+ }
551
+
552
+ if ( field.type == 'options' && field.options.length === 0 ) {
553
+ return cffrtb_editor.strings.field_missing_options;
554
+ }
555
+ }
556
+ };
557
+
558
+ /**
559
+ * Initialize the editor
560
+ */
561
+ cffrtb_editor.editor.init();
562
+
563
+ });
564
+
565
+ /**
566
+ * Initialize the fields list object after jQuery has loaded
567
+ */
568
+ jQuery(document).ready(function ($) {
569
+
570
+ /**
571
+ * Manage the list of fields
572
+ */
573
+ cffrtb_editor.list = {
574
+
575
+ // list element
576
+ el: cffrtb_editor.el.find( '#cffrtb-list' ),
577
+
578
+ // fieldsets and fields.
579
+ // just storing jQuery references to prevent duplicate lookups
580
+ items: {},
581
+
582
+ // flag to disable events during view->edit transition
583
+ in_transition: false,
584
+
585
+ // disabled fields list
586
+ disabled_el: cffrtb_editor.el.find( '#cffrtb-disabled' ),
587
+
588
+ init: function() {
589
+
590
+ // Store jQuery references to prevent duplicate lookups
591
+ this.el.find( '.fieldset, .field' ).each( function() {
592
+ cffrtb_editor.list.items[ $(this).data( 'slug' ) ] = {
593
+ el: $(this)
594
+ };
595
+ });
596
+
597
+ // Clear pre-existing listeners
598
+ this.el.off( 'click keyup' );
599
+
600
+ // Register click listeners
601
+ this.el.on( 'click', function( e ) {
602
+
603
+ e.stopPropagation();
604
+ e.preventDefault();
605
+
606
+ var target = $( e.target );
607
+
608
+ // Any click outside one of the field titles
609
+ if ( !target.hasClass( 'title' ) && !target.parents().hasClass( 'title' ) ) {
610
+ cffrtb_editor.list.save_all();
611
+ return;
612
+ }
613
+
614
+ var item_slug = target.parents( '.fieldset, .field' ).first().data( 'slug' );
615
+
616
+ // Open options panel
617
+ if ( cffrtb_editor.list.is_target( target, 'options' ) ) {
618
+ cffrtb_editor.list.save_all();
619
+ cffrtb_editor.editor.load_field( item_slug );
620
+
621
+ // Delete field
622
+ } else if ( cffrtb_editor.list.is_target( target, 'delete' ) ) {
623
+ cffrtb_editor.list.save_all();
624
+ cffrtb_editor.list.delete_item( item_slug );
625
+
626
+ // Open label editing panel
627
+ } else if ( !cffrtb_editor.list.is_editing( item_slug ) ) {
628
+ cffrtb_editor.list.show_edit( item_slug );
629
+
630
+ // Save label
631
+ } else if ( cffrtb_editor.list.is_target( target, 'save' ) ) {
632
+ cffrtb_editor.list.save_label( item_slug );
633
+
634
+ // Give focus to input when editing panel is active
635
+ } else if ( target.hasClass( 'edit' ) ) {
636
+ cffrtb_editor.list.set_focus( item_slug );
637
+ }
638
+
639
+ });
640
+
641
+ // Save label with ENTER key
642
+ this.el.keyup( function(e) {
643
+
644
+ if ( !cffrtb_editor.list.in_transition && e.which == '13' ) {
645
+
646
+ var target = $( e.target );
647
+
648
+ if ( target.is( 'input:focus' ) ) {
649
+
650
+ e.stopPropagation();
651
+ e.preventDefault();
652
+
653
+ cffrtb_editor.list.save_label( target.parents( '.fieldset, .field' ).first().data( 'slug' ) );
654
+ }
655
+ }
656
+ });
657
+
658
+ // Make the list sortable
659
+ this.el.sortable({
660
+ placeholder: 'cffrtb-list-placeholder',
661
+ delay: 250,
662
+ update: this.sorting_complete
663
+ });
664
+ this.el.find( '.fieldset ul' ).sortable({
665
+ placeholder: 'cffrtb-list-placeholder',
666
+ connectWith: '#cffrtb-list .fieldset ul',
667
+ delay: 250,
668
+ update: this.sorting_complete
669
+ });
670
+
671
+ // Clear pre-existing listeners
672
+ this.disabled_el.off( 'click' );
673
+
674
+ // Register click events on disabled fields
675
+ this.disabled_el.on( 'click', function(e) {
676
+
677
+ e.stopPropagation();
678
+ e.preventDefault();
679
+
680
+ var target = $( e.target );
681
+
682
+ // Restore field
683
+ if ( cffrtb_editor.list.is_target( target, 'enable' ) ) {
684
+ cffrtb_editor.list.enable_item( target.parents( '.fieldset, .field' ).first() );
685
+
686
+ // Open learn more text
687
+ } else if ( cffrtb_editor.list.is_target( target, 'learn-more' ) ) {
688
+ cffrtb_editor.list.disabled_el.find( '.reset .description' ).addClass( 'is-visible' );
689
+
690
+ // Revert to default
691
+ } else if ( cffrtb_editor.list.is_target( target, 'reset-all' ) ) {
692
+ cffrtb_editor.list.reset_all();
693
+ }
694
+ });
695
+
696
+ },
697
+
698
+ /**
699
+ * Is the field being edited?
700
+ */
701
+ is_editing: function( item_slug ) {
702
+ return this.get_title_el( item_slug ).hasClass( 'editing' );
703
+ },
704
+
705
+ /**
706
+ * Is the click target opening the field options?
707
+ */
708
+ is_target: function( target, match ) {
709
+ return target.hasClass( match ) || target.parents().hasClass( match );
710
+ },
711
+
712
+ /**
713
+ * Get the title element for an item
714
+ */
715
+ get_title_el: function( item_slug ) {
716
+
717
+ if ( typeof this.items[item_slug].title == 'undefined' ) {
718
+ this.items[item_slug].title = this.items[item_slug].el.find( '> .title' );
719
+ }
720
+
721
+ return this.items[item_slug].title;
722
+ },
723
+
724
+ /**
725
+ * Get the edit element for an item
726
+ */
727
+ get_edit_el: function( item_slug ) {
728
+
729
+ if ( typeof this.items[item_slug].title == 'undefined' ) {
730
+ this.items[item_slug].edit = this.items[item_slug].el.find( '> .title .edit' );
731
+ }
732
+
733
+ return this.items[item_slug].edit;
734
+ },
735
+
736
+ /**
737
+ * Get the value of the input field
738
+ */
739
+ get_input: function( item_slug ) {
740
+ return this.get_input_el( item_slug ).val();
741
+ },
742
+
743
+ /**
744
+ * Get the input element of a field
745
+ */
746
+ get_input_el: function( item_slug ) {
747
+
748
+ if ( typeof this.items[item_slug].input == 'undefined' ) {
749
+ this.items[item_slug].input = this.items[item_slug].el.find( '> .title .edit input' );
750
+ }
751
+
752
+ return this.items[item_slug].input;
753
+ },
754
+
755
+ /**
756
+ * Get the fieldset slug an item is attached to
757
+ */
758
+ get_fieldset: function( item_slug ) {
759
+
760
+ if ( this.items[item_slug].el.hasClass( 'fieldset' ) ) {
761
+ return item_slug;
762
+ } else {
763
+ return this.items[item_slug].el.parents( '.fieldset' ).first().data( 'slug' );
764
+ }
765
+ },
766
+
767
+ /**
768
+ * Update the value of the label in the view
769
+ */
770
+ update_view: function( item_slug ) {
771
+
772
+ if ( typeof this.items[item_slug].view_value == 'undefined' ) {
773
+ this.items[item_slug].view_value = this.items[item_slug].el.find( '> .title .view .value' );
774
+ }
775
+
776
+ this.items[item_slug].view_value.html( this.get_input( item_slug ) );
777
+ },
778
+
779
+ /**
780
+ * Open an item's edit mode
781
+ */
782
+ show_edit: function( item_slug ) {
783
+
784
+ // Save and close any other labels being edited
785
+ this.save_all();
786
+
787
+ // Set transition flag and timer
788
+ this.in_transition = true;
789
+ setTimeout( this.clear_transition_flag, 600 );
790
+
791
+ // Open edit mode for this item
792
+ this.enable_tabbing( item_slug );
793
+ this.get_title_el( item_slug ).addClass( 'editing' );
794
+ this.set_focus( item_slug );
795
+ },
796
+
797
+ /**
798
+ * Focus and select the input field
799
+ */
800
+ set_focus: function( item_slug ) {
801
+ this.get_input_el( item_slug ).focus().select();
802
+ },
803
+
804
+ /**
805
+ * Clear the transition flag used when opening the editing panel
806
+ */
807
+ clear_transition_flag: function() {
808
+ cffrtb_editor.list.in_transition = false;
809
+ },
810
+
811
+ /**
812
+ * Return an item to view mode
813
+ */
814
+ show_view: function( item_slug ) {
815
+ this.get_title_el( item_slug ).removeClass( 'editing' );
816
+ this.disable_tabbing( item_slug );
817
+ this.set_focus( item_slug );
818
+ },
819
+
820
+ /**
821
+ * Disable tabbing through a hidden edit interface
822
+ */
823
+ disable_tabbing: function( item_slug ) {
824
+ this.get_title_el( item_slug ).find( '> .edit input, > .edit .save' ).attr( 'tabindex', '-1' );
825
+ },
826
+
827
+ /**
828
+ * Enable tabbing through a hidden edit interface
829
+ */
830
+ enable_tabbing: function( item_slug ) {
831
+ this.get_title_el( item_slug ).find( '> .edit input, > .edit .save' ).removeAttr( 'tabindex' );
832
+ },
833
+
834
+ /**
835
+ * Disable drag and drop sorting
836
+ */
837
+ disable_sorting: function() {
838
+ this.el.sortable( 'option', 'disabled', true );
839
+ this.el.find( '.fieldset ul' ).sortable( 'option', 'disabled', true );
840
+ },
841
+
842
+ /**
843
+ * Enable drag and drop sorting
844
+ */
845
+ enable_sorting: function() {
846
+ this.el.sortable( 'option', 'disabled', false );
847
+ this.el.find( '.fieldset ul' ).sortable( 'option', 'disabled', false );
848
+ },
849
+
850
+ /**
851
+ * Save and close any fields being edited
852
+ */
853
+ save_all: function() {
854
+ this.el.find( '.title.editing' ).each( function() {
855
+ cffrtb_editor.list.save_label( $(this ).parent().data( 'slug' ) );
856
+ });
857
+ },
858
+
859
+ /**
860
+ * Save an item's label
861
+ */
862
+ save_label: function( item_slug ) {
863
+
864
+ // Don't trigger if we're already saving
865
+ if ( this.get_title_el( item_slug ).hasClass( 'saving' ) ) {
866
+ return;
867
+ }
868
+
869
+ // Indicate status
870
+ this.get_title_el( item_slug ).addClass( 'saving' );
871
+ this.get_input_el( item_slug ).attr( 'disabled', 'disabled' );
872
+
873
+ var params = {};
874
+
875
+ params.action = 'cffrtb-save-field';
876
+ params.nonce = cffrtb_editor.ajax_nonce;
877
+ params.request = 'save_label';
878
+ params.field = {
879
+ slug: item_slug,
880
+ title: this.get_input( item_slug ),
881
+ fieldset: this.get_fieldset( item_slug )
882
+ };
883
+
884
+ if( this.items[item_slug].el.data( 'id' ) ) {
885
+ params.field.ID = this.items[item_slug].el.data( 'id' );
886
+ }
887
+
888
+ var data = $.param( params );
889
+
890
+ $.post( ajaxurl, data, function( r ) {
891
+
892
+ if ( r.success ) {
893
+ cffrtb_editor.list.update_view( item_slug );
894
+ cffrtb_editor.list.show_view( item_slug );
895
+
896
+ } else {
897
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
898
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
899
+ } else {
900
+ console.log( r.data );
901
+ cffrtb_editor.show_error( r.data.msg );
902
+ }
903
+ }
904
+
905
+ // Reset status
906
+ cffrtb_editor.list.get_title_el( item_slug ).removeClass( 'saving' );
907
+ cffrtb_editor.list.get_input_el( item_slug ).removeAttr( 'disabled' );
908
+ });
909
+ },
910
+
911
+ /**
912
+ * Sorting complete
913
+ */
914
+ sorting_complete: function( event, ui ) {
915
+ cffrtb_editor.list.save_sort( $( ui.item.context ) );
916
+ },
917
+
918
+ /**
919
+ * Save the sort order after it's been changed
920
+ */
921
+ save_sort: function( target ) {
922
+
923
+ if ( cffrtb_editor.el.hasClass( 'saving-order' ) ) {
924
+ return;
925
+ }
926
+
927
+ // Indicate status
928
+ cffrtb_editor.list.disable_sorting();
929
+ cffrtb_editor.el.addClass( 'saving-order' );
930
+ target.find( '> .title .view .controls' ).prepend( '<span class="load-spinner"></span>' );
931
+
932
+ var params = {};
933
+
934
+ params.action = 'cffrtb-save-order';
935
+ params.nonce = cffrtb_editor.ajax_nonce;
936
+ params.order = [];
937
+
938
+ var i = 0;
939
+ cffrtb_editor.list.el.find( '> li' ).each( function() {
940
+ params.order.push( cffrtb_editor.list.get_item_order_obj( $(this), i ) );
941
+ i++;
942
+
943
+ $(this).find( '> ul > li' ).each( function() {
944
+ params.order.push( cffrtb_editor.list.get_item_order_obj( $(this), i ) );
945
+ i++;
946
+ });
947
+ });
948
+
949
+ var data = $.param( params );
950
+
951
+ $.post( ajaxurl, data, function( r ) {
952
+
953
+ if ( r.success ) {
954
+
955
+ } else {
956
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
957
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
958
+ } else {
959
+ console.log( r.data );
960
+ cffrtb_editor.show_error( r.data.msg );
961
+ }
962
+ }
963
+
964
+ // Reset status
965
+ cffrtb_editor.el.removeClass( 'saving-order' );
966
+ target.find( '> .title .view .controls .load-spinner' ).fadeOut( 400, function() { $(this).remove(); });
967
+ cffrtb_editor.list.enable_sorting();
968
+ });
969
+ },
970
+
971
+ /**
972
+ * Get an object with an elements order and slug/id data
973
+ */
974
+ get_item_order_obj: function( el, i ) {
975
+
976
+ var item = {};
977
+
978
+ if ( el.data( 'slug' ) ) {
979
+ item.slug = el.data( 'slug' );
980
+ }
981
+
982
+ if ( el.data( 'id' ) ) {
983
+ item.ID = el.data( 'id' );
984
+ }
985
+
986
+ item.fieldset = cffrtb_editor.list.get_fieldset( item.slug );
987
+
988
+ item.order = i;
989
+
990
+ return item;
991
+ },
992
+
993
+ /**
994
+ * Add an item
995
+ *
996
+ * Expects to receive an HTML string for the new <li> element
997
+ */
998
+ add_item: function( html, ID, is_new_field, type ) {
999
+
1000
+ if ( is_new_field ) {
1001
+ if ( type == 'fieldset' ) {
1002
+ this.el.find( '> .fieldset' ).last().after( html );
1003
+ } else {
1004
+ this.el.find( '> .fieldset' ).last().find( '> .fields' ).append( html );
1005
+ }
1006
+ } else {
1007
+ this.el.find( '.fieldset, .field' ).each( function() {
1008
+ if ( $(this).data( 'id' ) == ID ) {
1009
+ $(this).html( html ).hide().fadeIn();
1010
+ }
1011
+ });
1012
+ }
1013
+
1014
+ this.init();
1015
+ this.save_sort( this.el.find( '.fieldset, .field' ).last() );
1016
+ },
1017
+
1018
+ /**
1019
+ * Delete or disable an item from the list of fields
1020
+ */
1021
+ delete_item: function( item_slug ) {
1022
+
1023
+ if ( cffrtb_editor.el.hasClass( 'deleting' ) ) {
1024
+ return;
1025
+ }
1026
+
1027
+ var item_el = this.items[item_slug].el;
1028
+ var is_fieldset = item_el.hasClass( 'fieldset' );
1029
+
1030
+ // Indicate status
1031
+ cffrtb_editor.list.disable_sorting();
1032
+ cffrtb_editor.el.addClass( 'deleting' );
1033
+ item_el.find( '> .title .view .controls' ).prepend( '<span class="load-spinner"></span>' );
1034
+
1035
+ // Can't remove a fieldset with fields
1036
+ if ( is_fieldset && item_el.find( '.field' ).length ) {
1037
+ cffrtb_editor.show_error( cffrtb_editor.strings.fieldset_not_empty );
1038
+ item_el.find( '> .title .view .controls .load-spinner' ).fadeOut( 400, function() { $(this).remove(); });
1039
+ cffrtb_editor.el.removeClass( 'deleting' );
1040
+ cffrtb_editor.list.enable_sorting();
1041
+ return;
1042
+ }
1043
+
1044
+ var id = item_el.data( 'id' );
1045
+
1046
+ var params = {};
1047
+
1048
+ params.action = 'cffrtb-delete-field';
1049
+ params.nonce = cffrtb_editor.ajax_nonce;
1050
+
1051
+ if ( id ) {
1052
+ params.ID = id;
1053
+ } else {
1054
+ params.slug = item_slug;
1055
+ params.fieldset = this.get_fieldset( item_slug );
1056
+ }
1057
+
1058
+ var data = $.param( params );
1059
+
1060
+ $.post( ajaxurl, data, function( r ) {
1061
+
1062
+ if ( r.success ) {
1063
+
1064
+ item_el.fadeOut( 400, function() { $(this).remove(); });
1065
+
1066
+ if ( typeof r.data !== 'undefined' && typeof r.data.field !== 'undefined' ) {
1067
+
1068
+ if ( !cffrtb_editor.list.disabled_el.find( '.fields' ).length ) {
1069
+ cffrtb_editor.list.disabled_el.find( '.no-disabled-fields' ).remove();
1070
+ cffrtb_editor.list.disabled_el.find( '.reset' ).before( '<ul class="fields"></ul>' );
1071
+ }
1072
+
1073
+ cffrtb_editor.list.disabled_el.find( '.fields' ).append( r.data.field );
1074
+
1075
+ cffrtb_editor.list.disabled_el.find( '.reset' ).addClass( 'is-visible' );
1076
+ }
1077
+
1078
+ } else {
1079
+
1080
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
1081
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
1082
+ } else {
1083
+ console.log( r.data );
1084
+ cffrtb_editor.show_error( r.data.msg );
1085
+ }
1086
+
1087
+ item_el.find( '> .title .view .controls .load-spinner' ).fadeOut( 400, function() { $(this).remove(); });
1088
+ }
1089
+
1090
+ // Reset status
1091
+ cffrtb_editor.el.removeClass( 'deleting' );
1092
+ cffrtb_editor.list.enable_sorting();
1093
+ });
1094
+ },
1095
+
1096
+ /**
1097
+ * Enable a field that has been disabled
1098
+ */
1099
+ enable_item: function( field ) {
1100
+
1101
+ if ( field.hasClass( 'enabling' ) ) {
1102
+ return;
1103
+ }
1104
+
1105
+ // Indicate status
1106
+ field.addClass( 'enabling' );
1107
+ field.find( '> .title .view .controls' ).prepend( '<span class="load-spinner"></span>' );
1108
+
1109
+ var params = {};
1110
+
1111
+ params.action = 'cffrtb-enable-field';
1112
+ params.nonce = cffrtb_editor.ajax_nonce;
1113
+
1114
+ params.slug = field.data( 'slug' );
1115
+
1116
+ if ( field.hasClass( 'fieldset' ) ) {
1117
+ params.type = 'fieldset';
1118
+ } else {
1119
+ params.type = 'field';
1120
+ }
1121
+
1122
+ var data = $.param( params );
1123
+
1124
+ $.post( ajaxurl, data, function( r ) {
1125
+
1126
+ if ( r.success ) {
1127
+ cffrtb_editor.list.add_item( r.data.field, 0, true );
1128
+ field.fadeOut( 400, function() { $(this).remove(); });
1129
+
1130
+ } else {
1131
+
1132
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
1133
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
1134
+ } else {
1135
+ console.log( r.data );
1136
+ cffrtb_editor.show_error( r.data.msg );
1137
+ }
1138
+
1139
+ field.find( '> .title .view .controls .load-spinner' ).fadeOut( 400, function() { $(this).remove(); });
1140
+ field.removeClass( 'enabling' );
1141
+ }
1142
+
1143
+ cffrtb_editor.list.enable_sorting();
1144
+ });
1145
+ },
1146
+
1147
+ /**
1148
+ * Reset all modifications and custom fields created by the
1149
+ * plugin
1150
+ */
1151
+ reset_all: function() {
1152
+
1153
+ this.disabled_el.find( '.reset-all' ).attr( 'disabled', 'disabled' );
1154
+
1155
+ if ( !window.confirm( cffrtb_editor.strings.confirm_reset_all ) ) {
1156
+ this.disabled_el.find( '.reset-all' ).removeAttr( 'disabled' );
1157
+ return;
1158
+ }
1159
+
1160
+ var params = {};
1161
+
1162
+ params.action = 'cffrtb-reset-all';
1163
+ params.nonce = cffrtb_editor.ajax_nonce;
1164
+
1165
+ var data = $.param( params );
1166
+
1167
+ $.post( ajaxurl, data, function( r ) {
1168
+
1169
+ if ( r.success ) {
1170
+
1171
+ // Refresh the page so that the new details are visible
1172
+ window.location.reload();
1173
+
1174
+ } else {
1175
+
1176
+ if ( typeof r.data === 'undefined' || typeof r.data.error === 'undefined' ) {
1177
+ cffrtb_editor.show_error( cffrtb_editor.strings.unknown_error );
1178
+ } else {
1179
+ console.log( r.data );
1180
+ cffrtb_editor.show_error( r.data.msg );
1181
+ }
1182
+
1183
+ cffrtb_editor.list.disabled_el.find( '.reset-all' ).removeAttr( 'disabled' );
1184
+ }
1185
+ });
1186
+ }
1187
+ };
1188
+
1189
+ /**
1190
+ * Initialize the list
1191
+ */
1192
+ cffrtb_editor.list.init();
1193
+
1194
+ });
1195
+
1196
+ /**
1197
+ * Display the pointer admin help tips
1198
+ */
1199
+ jQuery(document).ready(function ($) {
1200
+
1201
+ if ( typeof cffrtb_editor.pointers == 'undefined' || !cffrtb_editor.pointers.length ) {
1202
+ return;
1203
+ }
1204
+
1205
+ function cffrtb_pointer_show( pointers ) {
1206
+
1207
+ var pointer = pointers.splice( 0, 1 )[0];
1208
+ var options = $.extend( pointer.options, {
1209
+ close: function() {
1210
+ $.post( ajaxurl, {
1211
+ pointer: pointer.id,
1212
+ action: 'dismiss-wp-pointer'
1213
+ }, function() {
1214
+ if ( pointers.length ) {
1215
+ cffrtb_pointer_show( pointers );
1216
+ }
1217
+ });
1218
+ }
1219
+ });
1220
+
1221
+ var target = $( pointer.target );
1222
+
1223
+ if ( !target ) {
1224
+ return;
1225
+ }
1226
+
1227
+ target.first().pointer( options ).pointer( 'open' );
1228
+
1229
+ $( 'html, body' ).animate({
1230
+ scrollTop: target.offset().top - 100
1231
+ }, 500);
1232
+ }
1233
+
1234
+ cffrtb_pointer_show( cffrtb_editor.pointers );
1235
+
1236
+ });
assets/js/mailchimp-admin.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ /*! mailchimp-for-rtb 2018-10-05 */
2
+ jQuery(document).ready(function(a){function b(){var b=a(".mcfrtb_loading");b.animate({opacity:1},500,function(){});var d={action:"mcfrtb-get-lists",nonce:rtb_admin_mc.ajax_nonce},e=a.param(d);a.post(ajaxurl,e,function(d){if(d.success){"undefined"==typeof d.data&&(console.log("no data returned from ajax request"),console.log(d)),b.stop(),b.css("opacity","0");var e=a("#mcfrtb-merge-controls").data("input-name")+"[list]";a(".mcfrtb-list-select").append('<select name="'+e+'" id="'+e+'"><option></option></select>');var f=a(".mcfrtb-list-select select");for(var g in d.data.lists){var h=a("<option></option>"),i=d.data.lists[g];h.attr("value",i.id).text(i.name),f.append(h)}a(f).change(function(b){c(a("option:selected",this).val())}),null!==rtb_admin_mc.lists&&"undefined"!=typeof rtb_admin_mc.lists.list&&""!==rtb_admin_mc.lists.list&&f.find("option[value="+rtb_admin_mc.lists.list+"]").attr("selected","selected").trigger("change")}else"undefined"==typeof d.data||"undefined"==typeof d.data.msg?a(".mcfrtb-list-select").html('<span class="error">'+rtb_admin_mc.strings.api_unknown_error+"</span>"):a(".mcfrtb-list-select").html('<span class="error">'+d.data.msg+"</span>"),b.animate({opacity:0},500,function(){})})}function c(b){var c=a(".mcfrtb_loading"),e=a("#mcfrtb-merge-controls");if(c.animate({opacity:1},500,function(){}),e.empty(),e.data("list-id",b),e.removeClass("active"),""===b)return void c.animate({opacity:0},500,function(){});var f={list:b,action:"mcfrtb-load-merge-fields",nonce:rtb_admin_mc.ajax_nonce},g=a.param(f);a.post(ajaxurl,g,function(f){if(f.success){if("undefined"==typeof f.data&&(console.log("no data returned from ajax request"),console.log(f)),f.data.list_id!=e.data("list-id"))return;if(e.empty(),"undefined"!=typeof rtb_admin_mc.merge_fields){var g=e.data("input-name")+"[fields]",h=a("<select><option></option></select>");for(var i in f.data.merge_fields){var j=a("<option></option>"),k=f.data.merge_fields[i];j.attr("value",k.tag).text(k.name),h.append(j)}e.hide(),e.append("<table></table>");var l=e.find("table");l.append("<tr><th>"+rtb_admin_mc.strings.merge_booking_data+"</th><th>"+rtb_admin_mc.strings.merge_list_field+"</th></tr>"),l.append("<tr><td>"+rtb_admin_mc.strings.merge_email_label+'</td><td><span class="description">'+rtb_admin_mc.strings.merge_email_description+"</span></td></tr>");for(var m in rtb_admin_mc.merge_fields)l.append('<tr><td><label for="mcfrtb-'+m+'">'+rtb_admin_mc.merge_fields[m]+'</label></td><td><select name="'+g+"["+m+']" id="mcfrtb-'+m+'">'+h.html()+"</select></td></tr>"),null!==rtb_admin_mc.lists&&b===rtb_admin_mc.lists.list&&"undefined"!=typeof rtb_admin_mc.lists.fields[m]&&""!==rtb_admin_mc.lists.fields[m]&&l.find("#mcfrtb-"+m+" option[value="+rtb_admin_mc.lists.fields[m]+"]").attr("selected","selected");e.find("select").change(function(){d(a(this),a("option:selected",this).val(),e)}),e.append('<p class="description">'+rtb_admin_mc.strings.merge_description+"</p>"),e.addClass("active"),e.fadeIn()}}else"undefined"==typeof f.data||"undefined"==typeof f.data.msg?e.html('<p class="error">'+rtb_admin_mc.strings.api_unknown_error+"</p>"):e.html('<p class="error">'+f.data.msg+"</p>");c.animate({opacity:0},500,function(){})})}function d(b,c,d){if(""!==c){var e=0,f=[];if(a("select option:selected",d).each(function(){a(this).val()===c&&(f.push(a(this)),e++)}),e>1){b.find("option[value="+c+"]").prop("selected","");for(var g in f)f[g].parent().after('<span class="merge-duplicate-warning dashicons dashicons-lock"></span>');a(".merge-duplicate-warning").fadeOut(2e3,function(){a(this).remove()})}}}a(".mcfrtb-list-select").length&&b()});
assets/js/mailchimp-subscribe.js ADDED
@@ -0,0 +1,2 @@
 
 
1
+ /*! mailchimp-for-rtb 2018-10-05 */
2
+ jQuery(document).ready(function(a){var b={action:"mcfrtb-subscribe",booking:rtb_subscribe_mc.booking,nonce:rtb_subscribe_mc.ajax_nonce},c=a.param(b);a.post(rtb_subscribe_mc.ajax_url,c,function(b){a(".rtb-booking-form").trigger("mcfrtb_subscribe_result",b)})});
assets/js/spectrum.js ADDED
@@ -0,0 +1,2317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Spectrum Colorpicker v1.7.1
2
+ // https://github.com/bgrins/spectrum
3
+ // Author: Brian Grinstead
4
+ // License: MIT
5
+
6
+ (function (factory) {
7
+ "use strict";
8
+
9
+ if (typeof define === 'function' && define.amd) { // AMD
10
+ define(['jquery'], factory);
11
+ }
12
+ else if (typeof exports == "object" && typeof module == "object") { // CommonJS
13
+ module.exports = factory;
14
+ }
15
+ else { // Browser
16
+ factory(jQuery);
17
+ }
18
+ })(function($, undefined) {
19
+ "use strict";
20
+
21
+ var defaultOpts = {
22
+
23
+ // Callbacks
24
+ beforeShow: noop,
25
+ move: noop,
26
+ change: noop,
27
+ show: noop,
28
+ hide: noop,
29
+
30
+ // Options
31
+ color: false,
32
+ flat: false,
33
+ showInput: false,
34
+ allowEmpty: false,
35
+ showButtons: true,
36
+ clickoutFiresChange: true,
37
+ showInitial: false,
38
+ showPalette: false,
39
+ showPaletteOnly: false,
40
+ hideAfterPaletteSelect: false,
41
+ togglePaletteOnly: false,
42
+ showSelectionPalette: true,
43
+ localStorageKey: false,
44
+ appendTo: "body",
45
+ maxSelectionSize: 7,
46
+ cancelText: "cancel",
47
+ chooseText: "choose",
48
+ togglePaletteMoreText: "more",
49
+ togglePaletteLessText: "less",
50
+ clearText: "Clear Color Selection",
51
+ noColorSelectedText: "No Color Selected",
52
+ preferredFormat: false,
53
+ className: "", // Deprecated - use containerClassName and replacerClassName instead.
54
+ containerClassName: "",
55
+ replacerClassName: "",
56
+ showAlpha: false,
57
+ theme: "sp-light",
58
+ palette: [["#ffffff", "#000000", "#ff0000", "#ff8000", "#ffff00", "#008000", "#0000ff", "#4b0082", "#9400d3"]],
59
+ selectionPalette: [],
60
+ disabled: false,
61
+ offset: null
62
+ },
63
+ spectrums = [],
64
+ IE = !!/msie/i.exec( window.navigator.userAgent ),
65
+ rgbaSupport = (function() {
66
+ function contains( str, substr ) {
67
+ return !!~('' + str).indexOf(substr);
68
+ }
69
+
70
+ var elem = document.createElement('div');
71
+ var style = elem.style;
72
+ style.cssText = 'background-color:rgba(0,0,0,.5)';
73
+ return contains(style.backgroundColor, 'rgba') || contains(style.backgroundColor, 'hsla');
74
+ })(),
75
+ replaceInput = [
76
+ "<div class='sp-replacer'>",
77
+ "<div class='sp-preview'><div class='sp-preview-inner'></div></div>",
78
+ "<div class='sp-dd'>&#9660;</div>",
79
+ "</div>"
80
+ ].join(''),
81
+ markup = (function () {
82
+
83
+ // IE does not support gradients with multiple stops, so we need to simulate
84
+ // that for the rainbow slider with 8 divs that each have a single gradient
85
+ var gradientFix = "";
86
+ if (IE) {
87
+ for (var i = 1; i <= 6; i++) {
88
+ gradientFix += "<div class='sp-" + i + "'></div>";
89
+ }
90
+ }
91
+
92
+ return [
93
+ "<div class='sp-container sp-hidden'>",
94
+ "<div class='sp-palette-container'>",
95
+ "<div class='sp-palette sp-thumb sp-cf'></div>",
96
+ "<div class='sp-palette-button-container sp-cf'>",
97
+ "<button type='button' class='sp-palette-toggle'></button>",
98
+ "</div>",
99
+ "</div>",
100
+ "<div class='sp-picker-container'>",
101
+ "<div class='sp-top sp-cf'>",
102
+ "<div class='sp-fill'></div>",
103
+ "<div class='sp-top-inner'>",
104
+ "<div class='sp-color'>",
105
+ "<div class='sp-sat'>",
106
+ "<div class='sp-val'>",
107
+ "<div class='sp-dragger'></div>",
108
+ "</div>",
109
+ "</div>",
110
+ "</div>",
111
+ "<div class='sp-clear sp-clear-display'>",
112
+ "</div>",
113
+ "<div class='sp-hue'>",
114
+ "<div class='sp-slider'></div>",
115
+ gradientFix,
116
+ "</div>",
117
+ "</div>",
118
+ "<div class='sp-alpha'><div class='sp-alpha-inner'><div class='sp-alpha-handle'></div></div></div>",
119
+ "</div>",
120
+ "<div class='sp-input-container sp-cf'>",
121
+ "<input class='sp-input' type='text' spellcheck='false' />",
122
+ "</div>",
123
+ "<div class='sp-initial sp-thumb sp-cf'></div>",
124
+ "<div class='sp-button-container sp-cf'>",
125
+ "<a class='sp-cancel' href='#'></a>",
126
+ "<button type='button' class='sp-choose'></button>",
127
+ "</div>",
128
+ "</div>",
129
+ "</div>"
130
+ ].join("");
131
+ })();
132
+
133
+ function paletteTemplate (p, color, className, opts) {
134
+ var html = [];
135
+ for (var i = 0; i < p.length; i++) {
136
+ var current = p[i];
137
+ if(current) {
138
+ var tiny = tinycolor(current);
139
+ var c = tiny.toHsl().l < 0.5 ? "sp-thumb-el sp-thumb-dark" : "sp-thumb-el sp-thumb-light";
140
+ c += (tinycolor.equals(color, current)) ? " sp-thumb-active" : "";
141
+ var formattedString = tiny.toString(opts.preferredFormat || "rgb");
142
+ var swatchStyle = rgbaSupport ? ("background-color:" + tiny.toRgbString()) : "filter:" + tiny.toFilter();
143
+ html.push('<span title="' + formattedString + '" data-color="' + tiny.toRgbString() + '" class="' + c + '"><span class="sp-thumb-inner" style="' + swatchStyle + ';" /></span>');
144
+ } else {
145
+ var cls = 'sp-clear-display';
146
+ html.push($('<div />')
147
+ .append($('<span data-color="" style="background-color:transparent;" class="' + cls + '"></span>')
148
+ .attr('title', opts.noColorSelectedText)
149
+ )
150
+ .html()
151
+ );
152
+ }
153
+ }
154
+ return "<div class='sp-cf " + className + "'>" + html.join('') + "</div>";
155
+ }
156
+
157
+ function hideAll() {
158
+ for (var i = 0; i < spectrums.length; i++) {
159
+ if (spectrums[i]) {
160
+ spectrums[i].hide();
161
+ }
162
+ }
163
+ }
164
+
165
+ function instanceOptions(o, callbackContext) {
166
+ var opts = $.extend({}, defaultOpts, o);
167
+ opts.callbacks = {
168
+ 'move': bind(opts.move, callbackContext),
169
+ 'change': bind(opts.change, callbackContext),
170
+ 'show': bind(opts.show, callbackContext),
171
+ 'hide': bind(opts.hide, callbackContext),
172
+ 'beforeShow': bind(opts.beforeShow, callbackContext)
173
+ };
174
+
175
+ return opts;
176
+ }
177
+
178
+ function spectrum(element, o) {
179
+
180
+ var opts = instanceOptions(o, element),
181
+ flat = opts.flat,
182
+ showSelectionPalette = opts.showSelectionPalette,
183
+ localStorageKey = opts.localStorageKey,
184
+ theme = opts.theme,
185
+ callbacks = opts.callbacks,
186
+ resize = throttle(reflow, 10),
187
+ visible = false,
188
+ isDragging = false,
189
+ dragWidth = 0,
190
+ dragHeight = 0,
191
+ dragHelperHeight = 0,
192
+ slideHeight = 0,
193
+ slideWidth = 0,
194
+ alphaWidth = 0,
195
+ alphaSlideHelperWidth = 0,
196
+ slideHelperHeight = 0,
197
+ currentHue = 0,
198
+ currentSaturation = 0,
199
+ currentValue = 0,
200
+ currentAlpha = 1,
201
+ palette = [],
202
+ paletteArray = [],
203
+ paletteLookup = {},
204
+ selectionPalette = opts.selectionPalette.slice(0),
205
+ maxSelectionSize = opts.maxSelectionSize,
206
+ draggingClass = "sp-dragging",
207
+ shiftMovementDirection = null;
208
+
209
+ var doc = element.ownerDocument,
210
+ body = doc.body,
211
+ boundElement = $(element),
212
+ disabled = false,
213
+ container = $(markup, doc).addClass(theme),
214
+ pickerContainer = container.find(".sp-picker-container"),
215
+ dragger = container.find(".sp-color"),
216
+ dragHelper = container.find(".sp-dragger"),
217
+ slider = container.find(".sp-hue"),
218
+ slideHelper = container.find(".sp-slider"),
219
+ alphaSliderInner = container.find(".sp-alpha-inner"),
220
+ alphaSlider = container.find(".sp-alpha"),
221
+ alphaSlideHelper = container.find(".sp-alpha-handle"),
222
+ textInput = container.find(".sp-input"),
223
+ paletteContainer = container.find(".sp-palette"),
224
+ initialColorContainer = container.find(".sp-initial"),
225
+ cancelButton = container.find(".sp-cancel"),
226
+ clearButton = container.find(".sp-clear"),
227
+ chooseButton = container.find(".sp-choose"),
228
+ toggleButton = container.find(".sp-palette-toggle"),
229
+ isInput = boundElement.is("input"),
230
+ isInputTypeColor = isInput && boundElement.attr("type") === "color" && inputTypeColorSupport(),
231
+ shouldReplace = isInput && !flat,
232
+ replacer = (shouldReplace) ? $(replaceInput).addClass(theme).addClass(opts.className).addClass(opts.replacerClassName) : $([]),
233
+ offsetElement = (shouldReplace) ? replacer : boundElement,
234
+ previewElement = replacer.find(".sp-preview-inner"),
235
+ initialColor = opts.color || (isInput && boundElement.val()),
236
+ colorOnShow = false,
237
+ preferredFormat = opts.preferredFormat,
238
+ currentPreferredFormat = preferredFormat,
239
+ clickoutFiresChange = !opts.showButtons || opts.clickoutFiresChange,
240
+ isEmpty = !initialColor,
241
+ allowEmpty = opts.allowEmpty && !isInputTypeColor;
242
+
243
+ function applyOptions() {
244
+
245
+ if (opts.showPaletteOnly) {
246
+ opts.showPalette = true;
247
+ }
248
+
249
+ toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
250
+
251
+ if (opts.palette) {
252
+ palette = opts.palette.slice(0);
253
+ paletteArray = $.isArray(palette[0]) ? palette : [palette];
254
+ paletteLookup = {};
255
+ for (var i = 0; i < paletteArray.length; i++) {
256
+ for (var j = 0; j < paletteArray[i].length; j++) {
257
+ var rgb = tinycolor(paletteArray[i][j]).toRgbString();
258
+ paletteLookup[rgb] = true;
259
+ }
260
+ }
261
+ }
262
+
263
+ container.toggleClass("sp-flat", flat);
264
+ container.toggleClass("sp-input-disabled", !opts.showInput);
265
+ container.toggleClass("sp-alpha-enabled", opts.showAlpha);
266
+ container.toggleClass("sp-clear-enabled", allowEmpty);
267
+ container.toggleClass("sp-buttons-disabled", !opts.showButtons);
268
+ container.toggleClass("sp-palette-buttons-disabled", !opts.togglePaletteOnly);
269
+ container.toggleClass("sp-palette-disabled", !opts.showPalette);
270
+ container.toggleClass("sp-palette-only", opts.showPaletteOnly);
271
+ container.toggleClass("sp-initial-disabled", !opts.showInitial);
272
+ container.addClass(opts.className).addClass(opts.containerClassName);
273
+
274
+ reflow();
275
+ }
276
+
277
+ function initialize() {
278
+
279
+ if (IE) {
280
+ container.find("*:not(input)").attr("unselectable", "on");
281
+ }
282
+
283
+ applyOptions();
284
+
285
+ if (shouldReplace) {
286
+ boundElement.after(replacer).hide();
287
+ }
288
+
289
+ if (!allowEmpty) {
290
+ clearButton.hide();
291
+ }
292
+
293
+ if (flat) {
294
+ boundElement.after(container).hide();
295
+ }
296
+ else {
297
+
298
+ var appendTo = opts.appendTo === "parent" ? boundElement.parent() : $(opts.appendTo);
299
+ if (appendTo.length !== 1) {
300
+ appendTo = $("body");
301
+ }
302
+
303
+ appendTo.append(container);
304
+ }
305
+
306
+ updateSelectionPaletteFromStorage();
307
+
308
+ offsetElement.bind("click.spectrum touchstart.spectrum", function (e) {
309
+ if (!disabled) {
310
+ toggle();
311
+ }
312
+
313
+ e.stopPropagation();
314
+
315
+ if (!$(e.target).is("input")) {
316
+ e.preventDefault();
317
+ }
318
+ });
319
+
320
+ if(boundElement.is(":disabled") || (opts.disabled === true)) {
321
+ disable();
322
+ }
323
+
324
+ // Prevent clicks from bubbling up to document. This would cause it to be hidden.
325
+ container.click(stopPropagation);
326
+
327
+ // Handle user typed input
328
+ textInput.change(setFromTextInput);
329
+ textInput.bind("paste", function () {
330
+ setTimeout(setFromTextInput, 1);
331
+ });
332
+ textInput.keydown(function (e) { if (e.keyCode == 13) { setFromTextInput(); } });
333
+
334
+ cancelButton.text(opts.cancelText);
335
+ cancelButton.bind("click.spectrum", function (e) {
336
+ e.stopPropagation();
337
+ e.preventDefault();
338
+ revert();
339
+ hide();
340
+ });
341
+
342
+ clearButton.attr("title", opts.clearText);
343
+ clearButton.bind("click.spectrum", function (e) {
344
+ e.stopPropagation();
345
+ e.preventDefault();
346
+ isEmpty = true;
347
+ move();
348
+
349
+ if(flat) {
350
+ //for the flat style, this is a change event
351
+ updateOriginalInput(true);
352
+ }
353
+ });
354
+
355
+ chooseButton.text(opts.chooseText);
356
+ chooseButton.bind("click.spectrum", function (e) {
357
+ e.stopPropagation();
358
+ e.preventDefault();
359
+
360
+ if (IE && textInput.is(":focus")) {
361
+ textInput.trigger('change');
362
+ }
363
+
364
+ if (isValid()) {
365
+ updateOriginalInput(true);
366
+ hide();
367
+ }
368
+ });
369
+
370
+ toggleButton.text(opts.showPaletteOnly ? opts.togglePaletteMoreText : opts.togglePaletteLessText);
371
+ toggleButton.bind("click.spectrum", function (e) {
372
+ e.stopPropagation();
373
+ e.preventDefault();
374
+
375
+ opts.showPaletteOnly = !opts.showPaletteOnly;
376
+
377
+ // To make sure the Picker area is drawn on the right, next to the
378
+ // Palette area (and not below the palette), first move the Palette
379
+ // to the left to make space for the picker, plus 5px extra.
380
+ // The 'applyOptions' function puts the whole container back into place
381
+ // and takes care of the button-text and the sp-palette-only CSS class.
382
+ if (!opts.showPaletteOnly && !flat) {
383
+ container.css('left', '-=' + (pickerContainer.outerWidth(true) + 5));
384
+ }
385
+ applyOptions();
386
+ });
387
+
388
+ draggable(alphaSlider, function (dragX, dragY, e) {
389
+ currentAlpha = (dragX / alphaWidth);
390
+ isEmpty = false;
391
+ if (e.shiftKey) {
392
+ currentAlpha = Math.round(currentAlpha * 10) / 10;
393
+ }
394
+
395
+ move();
396
+ }, dragStart, dragStop);
397
+
398
+ draggable(slider, function (dragX, dragY) {
399
+ currentHue = parseFloat(dragY / slideHeight);
400
+ isEmpty = false;
401
+ if (!opts.showAlpha) {
402
+ currentAlpha = 1;
403
+ }
404
+ move();
405
+ }, dragStart, dragStop);
406
+
407
+ draggable(dragger, function (dragX, dragY, e) {
408
+
409
+ // shift+drag should snap the movement to either the x or y axis.
410
+ if (!e.shiftKey) {
411
+ shiftMovementDirection = null;
412
+ }
413
+ else if (!shiftMovementDirection) {
414
+ var oldDragX = currentSaturation * dragWidth;
415
+ var oldDragY = dragHeight - (currentValue * dragHeight);
416
+ var furtherFromX = Math.abs(dragX - oldDragX) > Math.abs(dragY - oldDragY);
417
+
418
+ shiftMovementDirection = furtherFromX ? "x" : "y";
419
+ }
420
+
421
+ var setSaturation = !shiftMovementDirection || shiftMovementDirection === "x";
422
+ var setValue = !shiftMovementDirection || shiftMovementDirection === "y";
423
+
424
+ if (setSaturation) {
425
+ currentSaturation = parseFloat(dragX / dragWidth);
426
+ }
427
+ if (setValue) {
428
+ currentValue = parseFloat((dragHeight - dragY) / dragHeight);
429
+ }
430
+
431
+ isEmpty = false;
432
+ if (!opts.showAlpha) {
433
+ currentAlpha = 1;
434
+ }
435
+
436
+ move();
437
+
438
+ }, dragStart, dragStop);
439
+
440
+ if (!!initialColor) {
441
+ set(initialColor);
442
+
443
+ // In case color was black - update the preview UI and set the format
444
+ // since the set function will not run (default color is black).
445
+ updateUI();
446
+ currentPreferredFormat = preferredFormat || tinycolor(initialColor).format;
447
+
448
+ addColorToSelectionPalette(initialColor);
449
+ }
450
+ else {
451
+ updateUI();
452
+ }
453
+
454
+ if (flat) {
455
+ show();
456
+ }
457
+
458
+ function paletteElementClick(e) {
459
+ if (e.data && e.data.ignore) {
460
+ set($(e.target).closest(".sp-thumb-el").data("color"));
461
+ move();
462
+ }
463
+ else {
464
+ set($(e.target).closest(".sp-thumb-el").data("color"));
465
+ move();
466
+ updateOriginalInput(true);
467
+ if (opts.hideAfterPaletteSelect) {
468
+ hide();
469
+ }
470
+ }
471
+
472
+ return false;
473
+ }
474
+
475
+ var paletteEvent = IE ? "mousedown.spectrum" : "click.spectrum touchstart.spectrum";
476
+ paletteContainer.delegate(".sp-thumb-el", paletteEvent, paletteElementClick);
477
+ initialColorContainer.delegate(".sp-thumb-el:nth-child(1)", paletteEvent, { ignore: true }, paletteElementClick);
478
+ }
479
+
480
+ function updateSelectionPaletteFromStorage() {
481
+
482
+ if (localStorageKey && window.localStorage) {
483
+
484
+ // Migrate old palettes over to new format. May want to remove this eventually.
485
+ try {
486
+ var oldPalette = window.localStorage[localStorageKey].split(",#");
487
+ if (oldPalette.length > 1) {
488
+ delete window.localStorage[localStorageKey];
489
+ $.each(oldPalette, function(i, c) {
490
+ addColorToSelectionPalette(c);
491
+ });
492
+ }
493
+ }
494
+ catch(e) { }
495
+
496
+ try {
497
+ selectionPalette = window.localStorage[localStorageKey].split(";");
498
+ }
499
+ catch (e) { }
500
+ }
501
+ }
502
+
503
+ function addColorToSelectionPalette(color) {
504
+ if (showSelectionPalette) {
505
+ var rgb = tinycolor(color).toRgbString();
506
+ if (!paletteLookup[rgb] && $.inArray(rgb, selectionPalette) === -1) {
507
+ selectionPalette.push(rgb);
508
+ while(selectionPalette.length > maxSelectionSize) {
509
+ selectionPalette.shift();
510
+ }
511
+ }
512
+
513
+ if (localStorageKey && window.localStorage) {
514
+ try {
515
+ window.localStorage[localStorageKey] = selectionPalette.join(";");
516
+ }
517
+ catch(e) { }
518
+ }
519
+ }
520
+ }
521
+
522
+ function getUniqueSelectionPalette() {
523
+ var unique = [];
524
+ if (opts.showPalette) {
525
+ for (var i = 0; i < selectionPalette.length; i++) {
526
+ var rgb = tinycolor(selectionPalette[i]).toRgbString();
527
+
528
+ if (!paletteLookup[rgb]) {
529
+ unique.push(selectionPalette[i]);
530
+ }
531
+ }
532
+ }
533
+
534
+ return unique.reverse().slice(0, opts.maxSelectionSize);
535
+ }
536
+
537
+ function drawPalette() {
538
+
539
+ var currentColor = get();
540
+
541
+ var html = $.map(paletteArray, function (palette, i) {
542
+ return paletteTemplate(palette, currentColor, "sp-palette-row sp-palette-row-" + i, opts);
543
+ });
544
+
545
+ updateSelectionPaletteFromStorage();
546
+
547
+ if (selectionPalette) {
548
+ html.push(paletteTemplate(getUniqueSelectionPalette(), currentColor, "sp-palette-row sp-palette-row-selection", opts));
549
+ }
550
+
551
+ paletteContainer.html(html.join(""));
552
+ }
553
+
554
+ function drawInitial() {
555
+ if (opts.showInitial) {
556
+ var initial = colorOnShow;
557
+ var current = get();
558
+ initialColorContainer.html(paletteTemplate([initial, current], current, "sp-palette-row-initial", opts));
559
+ }
560
+ }
561
+
562
+ function dragStart() {
563
+ if (dragHeight <= 0 || dragWidth <= 0 || slideHeight <= 0) {
564
+ reflow();
565
+ }
566
+ isDragging = true;
567
+ container.addClass(draggingClass);
568
+ shiftMovementDirection = null;
569
+ boundElement.trigger('dragstart.spectrum', [ get() ]);
570
+ }
571
+
572
+ function dragStop() {
573
+ isDragging = false;
574
+ container.removeClass(draggingClass);
575
+ boundElement.trigger('dragstop.spectrum', [ get() ]);
576
+ }
577
+
578
+ function setFromTextInput() {
579
+
580
+ var value = textInput.val();
581
+
582
+ if ((value === null || value === "") && allowEmpty) {
583
+ set(null);
584
+ updateOriginalInput(true);
585
+ }
586
+ else {
587
+ var tiny = tinycolor(value);
588
+ if (tiny.isValid()) {
589
+ set(tiny);
590
+ updateOriginalInput(true);
591
+ }
592
+ else {
593
+ textInput.addClass("sp-validation-error");
594
+ }
595
+ }
596
+ }
597
+
598
+ function toggle() {
599
+ if (visible) {
600
+ hide();
601
+ }
602
+ else {
603
+ show();
604
+ }
605
+ }
606
+
607
+ function show() {
608
+ var event = $.Event('beforeShow.spectrum');
609
+
610
+ if (visible) {
611
+ reflow();
612
+ return;
613
+ }
614
+
615
+ boundElement.trigger(event, [ get() ]);
616
+
617
+ if (callbacks.beforeShow(get()) === false || event.isDefaultPrevented()) {
618
+ return;
619
+ }
620
+
621
+ hideAll();
622
+ visible = true;
623
+
624
+ $(doc).bind("keydown.spectrum", onkeydown);
625
+ $(doc).bind("click.spectrum", clickout);
626
+ $(window).bind("resize.spectrum", resize);
627
+ replacer.addClass("sp-active");
628
+ container.removeClass("sp-hidden");
629
+
630
+ reflow();
631
+ updateUI();
632
+
633
+ colorOnShow = get();
634
+
635
+ drawInitial();
636
+ callbacks.show(colorOnShow);
637
+ boundElement.trigger('show.spectrum', [ colorOnShow ]);
638
+ }
639
+
640
+ function onkeydown(e) {
641
+ // Close on ESC
642
+ if (e.keyCode === 27) {
643
+ hide();
644
+ }
645
+ }
646
+
647
+ function clickout(e) {
648
+ // Return on right click.
649
+ if (e.button == 2) { return; }
650
+
651
+ // If a drag event was happening during the mouseup, don't hide
652
+ // on click.
653
+ if (isDragging) { return; }
654
+
655
+ if (clickoutFiresChange) {
656
+ updateOriginalInput(true);
657
+ }
658
+ else {
659
+ revert();
660
+ }
661
+ hide();
662
+ }
663
+
664
+ function hide() {
665
+ // Return if hiding is unnecessary
666
+ if (!visible || flat) { return; }
667
+ visible = false;
668
+
669
+ $(doc).unbind("keydown.spectrum", onkeydown);
670
+ $(doc).unbind("click.spectrum", clickout);
671
+ $(window).unbind("resize.spectrum", resize);
672
+
673
+ replacer.removeClass("sp-active");
674
+ container.addClass("sp-hidden");
675
+
676
+ callbacks.hide(get());
677
+ boundElement.trigger('hide.spectrum', [ get() ]);
678
+ }
679
+
680
+ function revert() {
681
+ set(colorOnShow, true);
682
+ }
683
+
684
+ function set(color, ignoreFormatChange) {
685
+ if (tinycolor.equals(color, get())) {
686
+ // Update UI just in case a validation error needs
687
+ // to be cleared.
688
+ updateUI();
689
+ return;
690
+ }
691
+
692
+ var newColor, newHsv;
693
+ if (!color && allowEmpty) {
694
+ isEmpty = true;
695
+ } else {
696
+ isEmpty = false;
697
+ newColor = tinycolor(color);
698
+ newHsv = newColor.toHsv();
699
+
700
+ currentHue = (newHsv.h % 360) / 360;
701
+ currentSaturation = newHsv.s;
702
+ currentValue = newHsv.v;
703
+ currentAlpha = newHsv.a;
704
+ }
705
+ updateUI();
706
+
707
+ if (newColor && newColor.isValid() && !ignoreFormatChange) {
708
+ currentPreferredFormat = preferredFormat || newColor.getFormat();
709
+ }
710
+ }
711
+
712
+ function get(opts) {
713
+ opts = opts || { };
714
+
715
+ if (allowEmpty && isEmpty) {
716
+ return null;
717
+ }
718
+
719
+ return tinycolor.fromRatio({
720
+ h: currentHue,
721
+ s: currentSaturation,
722
+ v: currentValue,
723
+ a: Math.round(currentAlpha * 100) / 100
724
+ }, { format: opts.format || currentPreferredFormat });
725
+ }
726
+
727
+ function isValid() {
728
+ return !textInput.hasClass("sp-validation-error");
729
+ }
730
+
731
+ function move() {
732
+ updateUI();
733
+
734
+ callbacks.move(get());
735
+ boundElement.trigger('move.spectrum', [ get() ]);
736
+ }
737
+
738
+ function updateUI() {
739
+
740
+ textInput.removeClass("sp-validation-error");
741
+
742
+ updateHelperLocations();
743
+
744
+ // Update dragger background color (gradients take care of saturation and value).
745
+ var flatColor = tinycolor.fromRatio({ h: currentHue, s: 1, v: 1 });
746
+ dragger.css("background-color", flatColor.toHexString());
747
+
748
+ // Get a format that alpha will be included in (hex and names ignore alpha)
749
+ var format = currentPreferredFormat;
750
+ if (currentAlpha < 1 && !(currentAlpha === 0 && format === "name")) {
751
+ if (format === "hex" || format === "hex3" || format === "hex6" || format === "name") {
752
+ format = "rgb";
753
+ }
754
+ }
755
+
756
+ var realColor = get({ format: format }),
757
+ displayColor = '';
758
+
759
+ //reset background info for preview element
760
+ previewElement.removeClass("sp-clear-display");
761
+ previewElement.css('background-color', 'transparent');
762
+
763
+ if (!realColor && allowEmpty) {
764
+ // Update the replaced elements background with icon indicating no color selection
765
+ previewElement.addClass("sp-clear-display");
766
+ }
767
+ else {
768
+ var realHex = realColor.toHexString(),
769
+ realRgb = realColor.toRgbString();
770
+
771
+ // Update the replaced elements background color (with actual selected color)
772
+ if (rgbaSupport || realColor.alpha === 1) {
773
+ previewElement.css("background-color", realRgb);
774
+ }
775
+ else {
776
+ previewElement.css("background-color", "transparent");
777
+ previewElement.css("filter", realColor.toFilter());
778
+ }
779
+
780
+ if (opts.showAlpha) {
781
+ var rgb = realColor.toRgb();
782
+ rgb.a = 0;
783
+ var realAlpha = tinycolor(rgb).toRgbString();
784
+ var gradient = "linear-gradient(left, " + realAlpha + ", " + realHex + ")";
785
+
786
+ if (IE) {
787
+ alphaSliderInner.css("filter", tinycolor(realAlpha).toFilter({ gradientType: 1 }, realHex));
788
+ }
789
+ else {
790
+ alphaSliderInner.css("background", "-webkit-" + gradient);
791
+ alphaSliderInner.css("background", "-moz-" + gradient);
792
+ alphaSliderInner.css("background", "-ms-" + gradient);
793
+ // Use current syntax gradient on unprefixed property.
794
+ alphaSliderInner.css("background",
795
+ "linear-gradient(to right, " + realAlpha + ", " + realHex + ")");
796
+ }
797
+ }
798
+
799
+ displayColor = realColor.toString(format);
800
+ }
801
+
802
+ // Update the text entry input as it changes happen
803
+ if (opts.showInput) {
804
+ textInput.val(displayColor);
805
+ }
806
+
807
+ if (opts.showPalette) {
808
+ drawPalette();
809
+ }
810
+
811
+ drawInitial();
812
+ }
813
+
814
+ function updateHelperLocations() {
815
+ var s = currentSaturation;
816
+ var v = currentValue;
817
+
818
+ if(allowEmpty && isEmpty) {
819
+ //if selected color is empty, hide the helpers
820
+ alphaSlideHelper.hide();
821
+ slideHelper.hide();
822
+ dragHelper.hide();
823
+ }
824
+ else {
825
+ //make sure helpers are visible
826
+ alphaSlideHelper.show();
827
+ slideHelper.show();
828
+ dragHelper.show();
829
+
830
+ // Where to show the little circle in that displays your current selected color
831
+ var dragX = s * dragWidth;
832
+ var dragY = dragHeight - (v * dragHeight);
833
+ dragX = Math.max(
834
+ -dragHelperHeight,
835
+ Math.min(dragWidth - dragHelperHeight, dragX - dragHelperHeight)
836
+ );
837
+ dragY = Math.max(
838
+ -dragHelperHeight,
839
+ Math.min(dragHeight - dragHelperHeight, dragY - dragHelperHeight)
840
+ );
841
+ dragHelper.css({
842
+ "top": dragY + "px",
843
+ "left": dragX + "px"
844
+ });
845
+
846
+ var alphaX = currentAlpha * alphaWidth;
847
+ alphaSlideHelper.css({
848
+ "left": (alphaX - (alphaSlideHelperWidth / 2)) + "px"
849
+ });
850
+
851
+ // Where to show the bar that displays your current selected hue
852
+ var slideY = (currentHue) * slideHeight;
853
+ slideHelper.css({
854
+ "top": (slideY - slideHelperHeight) + "px"
855
+ });
856
+ }
857
+ }
858
+
859
+ function updateOriginalInput(fireCallback) {
860
+ var color = get(),
861
+ displayColor = '',
862
+ hasChanged = !tinycolor.equals(color, colorOnShow);
863
+
864
+ if (color) {
865
+ displayColor = color.toString(currentPreferredFormat);
866
+ // Update the selection palette with the current color
867
+ addColorToSelectionPalette(color);
868
+ }
869
+
870
+ if (isInput) {
871
+ boundElement.val(displayColor);
872
+ }
873
+
874
+ if (fireCallback && hasChanged) {
875
+ callbacks.change(color);
876
+ boundElement.trigger('change', [ color ]);
877
+ }
878
+ }
879
+
880
+ function reflow() {
881
+ dragWidth = dragger.width();
882
+ dragHeight = dragger.height();
883
+ dragHelperHeight = dragHelper.height();
884
+ slideWidth = slider.width();
885
+ slideHeight = slider.height();
886
+ slideHelperHeight = slideHelper.height();
887
+ alphaWidth = alphaSlider.width();
888
+ alphaSlideHelperWidth = alphaSlideHelper.width();
889
+
890
+ if (!flat) {
891
+ container.css("position", "absolute");
892
+ if (opts.offset) {
893
+ container.offset(opts.offset);
894
+ } else {
895
+ container.offset(getOffset(container, offsetElement));
896
+ }
897
+ }
898
+
899
+ updateHelperLocations();
900
+
901
+ if (opts.showPalette) {
902
+ drawPalette();
903
+ }
904
+
905
+ boundElement.trigger('reflow.spectrum');
906
+ }
907
+
908
+ function destroy() {
909
+ boundElement.show();
910
+ offsetElement.unbind("click.spectrum touchstart.spectrum");
911
+ container.remove();
912
+ replacer.remove();
913
+ spectrums[spect.id] = null;
914
+ }
915
+
916
+ function option(optionName, optionValue) {
917
+ if (optionName === undefined) {
918
+ return $.extend({}, opts);
919
+ }
920
+ if (optionValue === undefined) {
921
+ return opts[optionName];
922
+ }
923
+
924
+ opts[optionName] = optionValue;
925
+ applyOptions();
926
+ }
927
+
928
+ function enable() {
929
+ disabled = false;
930
+ boundElement.attr("disabled", false);
931
+ offsetElement.removeClass("sp-disabled");
932
+ }
933
+
934
+ function disable() {
935
+ hide();
936
+ disabled = true;
937
+ boundElement.attr("disabled", true);
938
+ offsetElement.addClass("sp-disabled");
939
+ }
940
+
941
+ function setOffset(coord) {
942
+ opts.offset = coord;
943
+ reflow();
944
+ }
945
+
946
+ initialize();
947
+
948
+ var spect = {
949
+ show: show,
950
+ hide: hide,
951
+ toggle: toggle,
952
+ reflow: reflow,
953
+ option: option,
954
+ enable: enable,
955
+ disable: disable,
956
+ offset: setOffset,
957
+ set: function (c) {
958
+ set(c);
959
+ updateOriginalInput();
960
+ },
961
+ get: get,
962
+ destroy: destroy,
963
+ container: container
964
+ };
965
+
966
+ spect.id = spectrums.push(spect) - 1;
967
+
968
+ return spect;
969
+ }
970
+
971
+ /**
972
+ * checkOffset - get the offset below/above and left/right element depending on screen position
973
+ * Thanks https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.datepicker.js
974
+ */
975
+ function getOffset(picker, input) {
976
+ var extraY = 0;
977
+ var dpWidth = picker.outerWidth();
978
+ var dpHeight = picker.outerHeight();
979
+ var inputHeight = input.outerHeight();
980
+ var doc = picker[0].ownerDocument;
981
+ var docElem = doc.documentElement;
982
+ var viewWidth = docElem.clientWidth + $(doc).scrollLeft();
983
+ var viewHeight = docElem.clientHeight + $(doc).scrollTop();
984
+ var offset = input.offset();
985
+ offset.top += inputHeight;
986
+
987
+ offset.left -=
988
+ Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
989
+ Math.abs(offset.left + dpWidth - viewWidth) : 0);
990
+
991
+ offset.top -=
992
+ Math.min(offset.top, ((offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
993
+ Math.abs(dpHeight + inputHeight - extraY) : extraY));
994
+
995
+ return offset;
996
+ }
997
+
998
+ /**
999
+ * noop - do nothing
1000
+ */
1001
+ function noop() {
1002
+
1003
+ }
1004
+
1005
+ /**
1006
+ * stopPropagation - makes the code only doing this a little easier to read in line
1007
+ */
1008
+ function stopPropagation(e) {
1009
+ e.stopPropagation();
1010
+ }
1011
+
1012
+ /**
1013
+ * Create a function bound to a given object
1014
+ * Thanks to underscore.js
1015
+ */
1016
+ function bind(func, obj) {
1017
+ var slice = Array.prototype.slice;
1018
+ var args = slice.call(arguments, 2);
1019
+ return function () {
1020
+ return func.apply(obj, args.concat(slice.call(arguments)));
1021
+ };
1022
+ }
1023
+
1024
+ /**
1025
+ * Lightweight drag helper. Handles containment within the element, so that
1026
+ * when dragging, the x is within [0,element.width] and y is within [0,element.height]
1027
+ */
1028
+ function draggable(element, onmove, onstart, onstop) {
1029
+ onmove = onmove || function () { };
1030
+ onstart = onstart || function () { };
1031
+ onstop = onstop || function () { };
1032
+ var doc = document;
1033
+ var dragging = false;
1034
+ var offset = {};
1035
+ var maxHeight = 0;
1036
+ var maxWidth = 0;
1037
+ var hasTouch = ('ontouchstart' in window);
1038
+
1039
+ var duringDragEvents = {};
1040
+ duringDragEvents["selectstart"] = prevent;
1041
+ duringDragEvents["dragstart"] = prevent;
1042
+ duringDragEvents["touchmove mousemove"] = move;
1043
+ duringDragEvents["touchend mouseup"] = stop;
1044
+
1045
+ function prevent(e) {
1046
+ if (e.stopPropagation) {
1047
+ e.stopPropagation();
1048
+ }
1049
+ if (e.preventDefault) {
1050
+ e.preventDefault();
1051
+ }
1052
+ e.returnValue = false;
1053
+ }
1054
+
1055
+ function move(e) {
1056
+ if (dragging) {
1057
+ // Mouseup happened outside of window
1058
+ if (IE && doc.documentMode < 9 && !e.button) {
1059
+ return stop();
1060
+ }
1061
+
1062
+ var t0 = e.originalEvent && e.originalEvent.touches && e.originalEvent.touches[0];
1063
+ var pageX = t0 && t0.pageX || e.pageX;
1064
+ var pageY = t0 && t0.pageY || e.pageY;
1065
+
1066
+ var dragX = Math.max(0, Math.min(pageX - offset.left, maxWidth));
1067
+ var dragY = Math.max(0, Math.min(pageY - offset.top, maxHeight));
1068
+
1069
+ if (hasTouch) {
1070
+ // Stop scrolling in iOS
1071
+ prevent(e);
1072
+ }
1073
+
1074
+ onmove.apply(element, [dragX, dragY, e]);
1075
+ }
1076
+ }
1077
+
1078
+ function start(e) {
1079
+ var rightclick = (e.which) ? (e.which == 3) : (e.button == 2);
1080
+
1081
+ if (!rightclick && !dragging) {
1082
+ if (onstart.apply(element, arguments) !== false) {
1083
+ dragging = true;
1084
+ maxHeight = $(element).height();
1085
+ maxWidth = $(element).width();
1086
+ offset = $(element).offset();
1087
+
1088
+ $(doc).bind(duringDragEvents);
1089
+ $(doc.body).addClass("sp-dragging");
1090
+
1091
+ move(e);
1092
+
1093
+ prevent(e);
1094
+ }
1095
+ }
1096
+ }
1097
+
1098
+ function stop() {
1099
+ if (dragging) {
1100
+ $(doc).unbind(duringDragEvents);
1101
+ $(doc.body).removeClass("sp-dragging");
1102
+
1103
+ // Wait a tick before notifying observers to allow the click event
1104
+ // to fire in Chrome.
1105
+ setTimeout(function() {
1106
+ onstop.apply(element, arguments);
1107
+ }, 0);
1108
+ }
1109
+ dragging = false;
1110
+ }
1111
+
1112
+ $(element).bind("touchstart mousedown", start);
1113
+ }
1114
+
1115
+ function throttle(func, wait, debounce) {
1116
+ var timeout;
1117
+ return function () {
1118
+ var context = this, args = arguments;
1119
+ var throttler = function () {
1120
+ timeout = null;
1121
+ func.apply(context, args);
1122
+ };
1123
+ if (debounce) clearTimeout(timeout);
1124
+ if (debounce || !timeout) timeout = setTimeout(throttler, wait);
1125
+ };
1126
+ }
1127
+
1128
+ function inputTypeColorSupport() {
1129
+ return $.fn.spectrum.inputTypeColorSupport();
1130
+ }
1131
+
1132
+ /**
1133
+ * Define a jQuery plugin
1134
+ */
1135
+ var dataID = "spectrum.id";
1136
+ $.fn.spectrum = function (opts, extra) {
1137
+
1138
+ if (typeof opts == "string") {
1139
+
1140
+ var returnValue = this;
1141
+ var args = Array.prototype.slice.call( arguments, 1 );
1142
+
1143
+ this.each(function () {
1144
+ var spect = spectrums[$(this).data(dataID)];
1145
+ if (spect) {
1146
+ var method = spect[opts];
1147
+ if (!method) {
1148
+ throw new Error( "Spectrum: no such method: '" + opts + "'" );
1149
+ }
1150
+
1151
+ if (opts == "get") {
1152
+ returnValue = spect.get();
1153
+ }
1154
+ else if (opts == "container") {
1155
+ returnValue = spect.container;
1156
+ }
1157
+ else if (opts == "option") {
1158
+ returnValue = spect.option.apply(spect, args);
1159
+ }
1160
+ else if (opts == "destroy") {
1161
+ spect.destroy();
1162
+ $(this).removeData(dataID);
1163
+ }
1164
+ else {
1165
+ method.apply(spect, args);
1166
+ }
1167
+ }
1168
+ });
1169
+
1170
+ return returnValue;
1171
+ }
1172
+
1173
+ // Initializing a new instance of spectrum
1174
+ return this.spectrum("destroy").each(function () {
1175
+ var options = $.extend({}, opts, $(this).data());
1176
+ var spect = spectrum(this, options);
1177
+ $(this).data(dataID, spect.id);
1178
+ });
1179
+ };
1180
+
1181
+ $.fn.spectrum.load = true;
1182
+ $.fn.spectrum.loadOpts = {};
1183
+ $.fn.spectrum.draggable = draggable;
1184
+ $.fn.spectrum.defaults = defaultOpts;
1185
+ $.fn.spectrum.inputTypeColorSupport = function inputTypeColorSupport() {
1186
+ if (typeof inputTypeColorSupport._cachedResult === "undefined") {
1187
+ var colorInput = $("<input type='color'/>")[0]; // if color element is supported, value will default to not null
1188
+ inputTypeColorSupport._cachedResult = colorInput.type === "color" && colorInput.value !== "";
1189
+ }
1190
+ return inputTypeColorSupport._cachedResult;
1191
+ };
1192
+
1193
+ $.spectrum = { };
1194
+ $.spectrum.localization = { };
1195
+ $.spectrum.palettes = { };
1196
+
1197
+ $.fn.spectrum.processNativeColorInputs = function () {
1198
+ var colorInputs = $("input[type=color]");
1199
+ if (colorInputs.length && !inputTypeColorSupport()) {
1200
+ colorInputs.spectrum({
1201
+ preferredFormat: "hex6"
1202
+ });
1203
+ }
1204
+ };
1205
+
1206
+ // TinyColor v1.1.2
1207
+ // https://github.com/bgrins/TinyColor
1208
+ // Brian Grinstead, MIT License
1209
+
1210
+ (function() {
1211
+
1212
+ var trimLeft = /^[\s,#]+/,
1213
+ trimRight = /\s+$/,
1214
+ tinyCounter = 0,
1215
+ math = Math,
1216
+ mathRound = math.round,
1217
+ mathMin = math.min,
1218
+ mathMax = math.max,
1219
+ mathRandom = math.random;
1220
+
1221
+ var tinycolor = function(color, opts) {
1222
+
1223
+ color = (color) ? color : '';
1224
+ opts = opts || { };
1225
+
1226
+ // If input is already a tinycolor, return itself
1227
+ if (color instanceof tinycolor) {
1228
+ return color;
1229
+ }
1230
+ // If we are called as a function, call using new instead
1231
+ if (!(this instanceof tinycolor)) {
1232
+ return new tinycolor(color, opts);
1233
+ }
1234
+
1235
+ var rgb = inputToRGB(color);
1236
+ this._originalInput = color,
1237
+ this._r = rgb.r,
1238
+ this._g = rgb.g,
1239
+ this._b = rgb.b,
1240
+ this._a = rgb.a,
1241
+ this._roundA = mathRound(100*this._a) / 100,
1242
+ this._format = opts.format || rgb.format;
1243
+ this._gradientType = opts.gradientType;
1244
+
1245
+ // Don't let the range of [0,255] come back in [0,1].
1246
+ // Potentially lose a little bit of precision here, but will fix issues where
1247
+ // .5 gets interpreted as half of the total, instead of half of 1
1248
+ // If it was supposed to be 128, this was already taken care of by `inputToRgb`
1249
+ if (this._r < 1) { this._r = mathRound(this._r); }
1250
+ if (this._g < 1) { this._g = mathRound(this._g); }
1251
+ if (this._b < 1) { this._b = mathRound(this._b); }
1252
+
1253
+ this._ok = rgb.ok;
1254
+ this._tc_id = tinyCounter++;
1255
+ };
1256
+
1257
+ tinycolor.prototype = {
1258
+ isDark: function() {
1259
+ return this.getBrightness() < 128;
1260
+ },
1261
+ isLight: function() {
1262
+ return !this.isDark();
1263
+ },
1264
+ isValid: function() {
1265
+ return this._ok;
1266
+ },
1267
+ getOriginalInput: function() {
1268
+ return this._originalInput;
1269
+ },
1270
+ getFormat: function() {
1271
+ return this._format;
1272
+ },
1273
+ getAlpha: function() {
1274
+ return this._a;
1275
+ },
1276
+ getBrightness: function() {
1277
+ var rgb = this.toRgb();
1278
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
1279
+ },
1280
+ setAlpha: function(value) {
1281
+ this._a = boundAlpha(value);
1282
+ this._roundA = mathRound(100*this._a) / 100;
1283
+ return this;
1284
+ },
1285
+ toHsv: function() {
1286
+ var hsv = rgbToHsv(this._r, this._g, this._b);
1287
+ return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
1288
+ },
1289
+ toHsvString: function() {
1290
+ var hsv = rgbToHsv(this._r, this._g, this._b);
1291
+ var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
1292
+ return (this._a == 1) ?
1293
+ "hsv(" + h + ", " + s + "%, " + v + "%)" :
1294
+ "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
1295
+ },
1296
+ toHsl: function() {
1297
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1298
+ return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
1299
+ },
1300
+ toHslString: function() {
1301
+ var hsl = rgbToHsl(this._r, this._g, this._b);
1302
+ var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
1303
+ return (this._a == 1) ?
1304
+ "hsl(" + h + ", " + s + "%, " + l + "%)" :
1305
+ "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
1306
+ },
1307
+ toHex: function(allow3Char) {
1308
+ return rgbToHex(this._r, this._g, this._b, allow3Char);
1309
+ },
1310
+ toHexString: function(allow3Char) {
1311
+ return '#' + this.toHex(allow3Char);
1312
+ },
1313
+ toHex8: function() {
1314
+ return rgbaToHex(this._r, this._g, this._b, this._a);
1315
+ },
1316
+ toHex8String: function() {
1317
+ return '#' + this.toHex8();
1318
+ },
1319
+ toRgb: function() {
1320
+ return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
1321
+ },
1322
+ toRgbString: function() {
1323
+ return (this._a == 1) ?
1324
+ "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
1325
+ "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
1326
+ },
1327
+ toPercentageRgb: function() {
1328
+ return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
1329
+ },
1330
+ toPercentageRgbString: function() {
1331
+ return (this._a == 1) ?
1332
+ "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
1333
+ "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
1334
+ },
1335
+ toName: function() {
1336
+ if (this._a === 0) {
1337
+ return "transparent";
1338
+ }
1339
+
1340
+ if (this._a < 1) {
1341
+ return false;
1342
+ }
1343
+
1344
+ return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
1345
+ },
1346
+ toFilter: function(secondColor) {
1347
+ var hex8String = '#' + rgbaToHex(this._r, this._g, this._b, this._a);
1348
+ var secondHex8String = hex8String;
1349
+ var gradientType = this._gradientType ? "GradientType = 1, " : "";
1350
+
1351
+ if (secondColor) {
1352
+ var s = tinycolor(secondColor);
1353
+ secondHex8String = s.toHex8String();
1354
+ }
1355
+
1356
+ return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
1357
+ },
1358
+ toString: function(format) {
1359
+ var formatSet = !!format;
1360
+ format = format || this._format;
1361
+
1362
+ var formattedString = false;
1363
+ var hasAlpha = this._a < 1 && this._a >= 0;
1364
+ var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "name");
1365
+
1366
+ if (needsAlphaFormat) {
1367
+ // Special case for "transparent", all other non-alpha formats
1368
+ // will return rgba when there is transparency.
1369
+ if (format === "name" && this._a === 0) {
1370
+ return this.toName();
1371
+ }
1372
+ return this.toRgbString();
1373
+ }
1374
+ if (format === "rgb") {
1375
+ formattedString = this.toRgbString();
1376
+ }
1377
+ if (format === "prgb") {
1378
+ formattedString = this.toPercentageRgbString();
1379
+ }
1380
+ if (format === "hex" || format === "hex6") {
1381
+ formattedString = this.toHexString();
1382
+ }
1383
+ if (format === "hex3") {
1384
+ formattedString = this.toHexString(true);
1385
+ }
1386
+ if (format === "hex8") {
1387
+ formattedString = this.toHex8String();
1388
+ }
1389
+ if (format === "name") {
1390
+ formattedString = this.toName();
1391
+ }
1392
+ if (format === "hsl") {
1393
+ formattedString = this.toHslString();
1394
+ }
1395
+ if (format === "hsv") {
1396
+ formattedString = this.toHsvString();
1397
+ }
1398
+
1399
+ return formattedString || this.toHexString();
1400
+ },
1401
+
1402
+ _applyModification: function(fn, args) {
1403
+ var color = fn.apply(null, [this].concat([].slice.call(args)));
1404
+ this._r = color._r;
1405
+ this._g = color._g;
1406
+ this._b = color._b;
1407
+ this.setAlpha(color._a);
1408
+ return this;
1409
+ },
1410
+ lighten: function() {
1411
+ return this._applyModification(lighten, arguments);
1412
+ },
1413
+ brighten: function() {
1414
+ return this._applyModification(brighten, arguments);
1415
+ },
1416
+ darken: function() {
1417
+ return this._applyModification(darken, arguments);
1418
+ },
1419
+ desaturate: function() {
1420
+ return this._applyModification(desaturate, arguments);
1421
+ },
1422
+ saturate: function() {
1423
+ return this._applyModification(saturate, arguments);
1424
+ },
1425
+ greyscale: function() {
1426
+ return this._applyModification(greyscale, arguments);
1427
+ },
1428
+ spin: function() {
1429
+ return this._applyModification(spin, arguments);
1430
+ },
1431
+
1432
+ _applyCombination: function(fn, args) {
1433
+ return fn.apply(null, [this].concat([].slice.call(args)));
1434
+ },
1435
+ analogous: function() {
1436
+ return this._applyCombination(analogous, arguments);
1437
+ },
1438
+ complement: function() {
1439
+ return this._applyCombination(complement, arguments);
1440
+ },
1441
+ monochromatic: function() {
1442
+ return this._applyCombination(monochromatic, arguments);
1443
+ },
1444
+ splitcomplement: function() {
1445
+ return this._applyCombination(splitcomplement, arguments);
1446
+ },
1447
+ triad: function() {
1448
+ return this._applyCombination(triad, arguments);
1449
+ },
1450
+ tetrad: function() {
1451
+ return this._applyCombination(tetrad, arguments);
1452
+ }
1453
+ };
1454
+
1455
+ // If input is an object, force 1 into "1.0" to handle ratios properly
1456
+ // String input requires "1.0" as input, so 1 will be treated as 1
1457
+ tinycolor.fromRatio = function(color, opts) {
1458
+ if (typeof color == "object") {
1459
+ var newColor = {};
1460
+ for (var i in color) {
1461
+ if (color.hasOwnProperty(i)) {
1462
+ if (i === "a") {
1463
+ newColor[i] = color[i];
1464
+ }
1465
+ else {
1466
+ newColor[i] = convertToPercentage(color[i]);
1467
+ }
1468
+ }
1469
+ }
1470
+ color = newColor;
1471
+ }
1472
+
1473
+ return tinycolor(color, opts);
1474
+ };
1475
+
1476
+ // Given a string or object, convert that input to RGB
1477
+ // Possible string inputs:
1478
+ //
1479
+ // "red"
1480
+ // "#f00" or "f00"
1481
+ // "#ff0000" or "ff0000"
1482
+ // "#ff000000" or "ff000000"
1483
+ // "rgb 255 0 0" or "rgb (255, 0, 0)"
1484
+ // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
1485
+ // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
1486
+ // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
1487
+ // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
1488
+ // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
1489
+ // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
1490
+ //
1491
+ function inputToRGB(color) {
1492
+
1493
+ var rgb = { r: 0, g: 0, b: 0 };
1494
+ var a = 1;
1495
+ var ok = false;
1496
+ var format = false;
1497
+
1498
+ if (typeof color == "string") {
1499
+ color = stringInputToObject(color);
1500
+ }
1501
+
1502
+ if (typeof color == "object") {
1503
+ if (color.hasOwnProperty("r") && color.hasOwnProperty("g") && color.hasOwnProperty("b")) {
1504
+ rgb = rgbToRgb(color.r, color.g, color.b);
1505
+ ok = true;
1506
+ format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
1507
+ }
1508
+ else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("v")) {
1509
+ color.s = convertToPercentage(color.s);
1510
+ color.v = convertToPercentage(color.v);
1511
+ rgb = hsvToRgb(color.h, color.s, color.v);
1512
+ ok = true;
1513
+ format = "hsv";
1514
+ }
1515
+ else if (color.hasOwnProperty("h") && color.hasOwnProperty("s") && color.hasOwnProperty("l")) {
1516
+ color.s = convertToPercentage(color.s);
1517
+ color.l = convertToPercentage(color.l);
1518
+ rgb = hslToRgb(color.h, color.s, color.l);
1519
+ ok = true;
1520
+ format = "hsl";
1521
+ }
1522
+
1523
+ if (color.hasOwnProperty("a")) {
1524
+ a = color.a;
1525
+ }
1526
+ }
1527
+
1528
+ a = boundAlpha(a);
1529
+
1530
+ return {
1531
+ ok: ok,
1532
+ format: color.format || format,
1533
+ r: mathMin(255, mathMax(rgb.r, 0)),
1534
+ g: mathMin(255, mathMax(rgb.g, 0)),
1535
+ b: mathMin(255, mathMax(rgb.b, 0)),
1536
+ a: a
1537
+ };
1538
+ }
1539
+
1540
+
1541
+ // Conversion Functions
1542
+ // --------------------
1543
+
1544
+ // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
1545
+ // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
1546
+
1547
+ // `rgbToRgb`
1548
+ // Handle bounds / percentage checking to conform to CSS color spec
1549
+ // <http://www.w3.org/TR/css3-color/>
1550
+ // *Assumes:* r, g, b in [0, 255] or [0, 1]
1551
+ // *Returns:* { r, g, b } in [0, 255]
1552
+ function rgbToRgb(r, g, b){
1553
+ return {
1554
+ r: bound01(r, 255) * 255,
1555
+ g: bound01(g, 255) * 255,
1556
+ b: bound01(b, 255) * 255
1557
+ };
1558
+ }
1559
+
1560
+ // `rgbToHsl`
1561
+ // Converts an RGB color value to HSL.
1562
+ // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
1563
+ // *Returns:* { h, s, l } in [0,1]
1564
+ function rgbToHsl(r, g, b) {
1565
+
1566
+ r = bound01(r, 255);
1567
+ g = bound01(g, 255);
1568
+ b = bound01(b, 255);
1569
+
1570
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
1571
+ var h, s, l = (max + min) / 2;
1572
+
1573
+ if(max == min) {
1574
+ h = s = 0; // achromatic
1575
+ }
1576
+ else {
1577
+ var d = max - min;
1578
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1579
+ switch(max) {
1580
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1581
+ case g: h = (b - r) / d + 2; break;
1582
+ case b: h = (r - g) / d + 4; break;
1583
+ }
1584
+
1585
+ h /= 6;
1586
+ }
1587
+
1588
+ return { h: h, s: s, l: l };
1589
+ }
1590
+
1591
+ // `hslToRgb`
1592
+ // Converts an HSL color value to RGB.
1593
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
1594
+ // *Returns:* { r, g, b } in the set [0, 255]
1595
+ function hslToRgb(h, s, l) {
1596
+ var r, g, b;
1597
+
1598
+ h = bound01(h, 360);
1599
+ s = bound01(s, 100);
1600
+ l = bound01(l, 100);
1601
+
1602
+ function hue2rgb(p, q, t) {
1603
+ if(t < 0) t += 1;
1604
+ if(t > 1) t -= 1;
1605
+ if(t < 1/6) return p + (q - p) * 6 * t;
1606
+ if(t < 1/2) return q;
1607
+ if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
1608
+ return p;
1609
+ }
1610
+
1611
+ if(s === 0) {
1612
+ r = g = b = l; // achromatic
1613
+ }
1614
+ else {
1615
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
1616
+ var p = 2 * l - q;
1617
+ r = hue2rgb(p, q, h + 1/3);
1618
+ g = hue2rgb(p, q, h);
1619
+ b = hue2rgb(p, q, h - 1/3);
1620
+ }
1621
+
1622
+ return { r: r * 255, g: g * 255, b: b * 255 };
1623
+ }
1624
+
1625
+ // `rgbToHsv`
1626
+ // Converts an RGB color value to HSV
1627
+ // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
1628
+ // *Returns:* { h, s, v } in [0,1]
1629
+ function rgbToHsv(r, g, b) {
1630
+
1631
+ r = bound01(r, 255);
1632
+ g = bound01(g, 255);
1633
+ b = bound01(b, 255);
1634
+
1635
+ var max = mathMax(r, g, b), min = mathMin(r, g, b);
1636
+ var h, s, v = max;
1637
+
1638
+ var d = max - min;
1639
+ s = max === 0 ? 0 : d / max;
1640
+
1641
+ if(max == min) {
1642
+ h = 0; // achromatic
1643
+ }
1644
+ else {
1645
+ switch(max) {
1646
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
1647
+ case g: h = (b - r) / d + 2; break;
1648
+ case b: h = (r - g) / d + 4; break;
1649
+ }
1650
+ h /= 6;
1651
+ }
1652
+ return { h: h, s: s, v: v };
1653
+ }
1654
+
1655
+ // `hsvToRgb`
1656
+ // Converts an HSV color value to RGB.
1657
+ // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
1658
+ // *Returns:* { r, g, b } in the set [0, 255]
1659
+ function hsvToRgb(h, s, v) {
1660
+
1661
+ h = bound01(h, 360) * 6;
1662
+ s = bound01(s, 100);
1663
+ v = bound01(v, 100);
1664
+
1665
+ var i = math.floor(h),
1666
+ f = h - i,
1667
+ p = v * (1 - s),
1668
+ q = v * (1 - f * s),
1669
+ t = v * (1 - (1 - f) * s),
1670
+ mod = i % 6,
1671
+ r = [v, q, p, p, t, v][mod],
1672
+ g = [t, v, v, q, p, p][mod],
1673
+ b = [p, p, t, v, v, q][mod];
1674
+
1675
+ return { r: r * 255, g: g * 255, b: b * 255 };
1676
+ }
1677
+
1678
+ // `rgbToHex`
1679
+ // Converts an RGB color to hex
1680
+ // Assumes r, g, and b are contained in the set [0, 255]
1681
+ // Returns a 3 or 6 character hex
1682
+ function rgbToHex(r, g, b, allow3Char) {
1683
+
1684
+ var hex = [
1685
+ pad2(mathRound(r).toString(16)),
1686
+ pad2(mathRound(g).toString(16)),
1687
+ pad2(mathRound(b).toString(16))
1688
+ ];
1689
+
1690
+ // Return a 3 character hex if possible
1691
+ if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
1692
+ return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
1693
+ }
1694
+
1695
+ return hex.join("");
1696
+ }
1697
+ // `rgbaToHex`
1698
+ // Converts an RGBA color plus alpha transparency to hex
1699
+ // Assumes r, g, b and a are contained in the set [0, 255]
1700
+ // Returns an 8 character hex
1701
+ function rgbaToHex(r, g, b, a) {
1702
+
1703
+ var hex = [
1704
+ pad2(convertDecimalToHex(a)),
1705
+ pad2(mathRound(r).toString(16)),
1706
+ pad2(mathRound(g).toString(16)),
1707
+ pad2(mathRound(b).toString(16))
1708
+ ];
1709
+
1710
+ return hex.join("");
1711
+ }
1712
+
1713
+ // `equals`
1714
+ // Can be called with any tinycolor input
1715
+ tinycolor.equals = function (color1, color2) {
1716
+ if (!color1 || !color2) { return false; }
1717
+ return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
1718
+ };
1719
+ tinycolor.random = function() {
1720
+ return tinycolor.fromRatio({
1721
+ r: mathRandom(),
1722
+ g: mathRandom(),
1723
+ b: mathRandom()
1724
+ });
1725
+ };
1726
+
1727
+
1728
+ // Modification Functions
1729
+ // ----------------------
1730
+ // Thanks to less.js for some of the basics here
1731
+ // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
1732
+
1733
+ function desaturate(color, amount) {
1734
+ amount = (amount === 0) ? 0 : (amount || 10);
1735
+ var hsl = tinycolor(color).toHsl();
1736
+ hsl.s -= amount / 100;
1737
+ hsl.s = clamp01(hsl.s);
1738
+ return tinycolor(hsl);
1739
+ }
1740
+
1741
+ function saturate(color, amount) {
1742
+ amount = (amount === 0) ? 0 : (amount || 10);
1743
+ var hsl = tinycolor(color).toHsl();
1744
+ hsl.s += amount / 100;
1745
+ hsl.s = clamp01(hsl.s);
1746
+ return tinycolor(hsl);
1747
+ }
1748
+
1749
+ function greyscale(color) {
1750
+ return tinycolor(color).desaturate(100);
1751
+ }
1752
+
1753
+ function lighten (color, amount) {
1754
+ amount = (amount === 0) ? 0 : (amount || 10);
1755
+ var hsl = tinycolor(color).toHsl();
1756
+ hsl.l += amount / 100;
1757
+ hsl.l = clamp01(hsl.l);
1758
+ return tinycolor(hsl);
1759
+ }
1760
+
1761
+ function brighten(color, amount) {
1762
+ amount = (amount === 0) ? 0 : (amount || 10);
1763
+ var rgb = tinycolor(color).toRgb();
1764
+ rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
1765
+ rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
1766
+ rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
1767
+ return tinycolor(rgb);
1768
+ }
1769
+
1770
+ function darken (color, amount) {
1771
+ amount = (amount === 0) ? 0 : (amount || 10);
1772
+ var hsl = tinycolor(color).toHsl();
1773
+ hsl.l -= amount / 100;
1774
+ hsl.l = clamp01(hsl.l);
1775
+ return tinycolor(hsl);
1776
+ }
1777
+
1778
+ // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
1779
+ // Values outside of this range will be wrapped into this range.
1780
+ function spin(color, amount) {
1781
+ var hsl = tinycolor(color).toHsl();
1782
+ var hue = (mathRound(hsl.h) + amount) % 360;
1783
+ hsl.h = hue < 0 ? 360 + hue : hue;
1784
+ return tinycolor(hsl);
1785
+ }
1786
+
1787
+ // Combination Functions
1788
+ // ---------------------
1789
+ // Thanks to jQuery xColor for some of the ideas behind these
1790
+ // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
1791
+
1792
+ function complement(color) {
1793
+ var hsl = tinycolor(color).toHsl();
1794
+ hsl.h = (hsl.h + 180) % 360;
1795
+ return tinycolor(hsl);
1796
+ }
1797
+
1798
+ function triad(color) {
1799
+ var hsl = tinycolor(color).toHsl();
1800
+ var h = hsl.h;
1801
+ return [
1802
+ tinycolor(color),
1803
+ tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
1804
+ tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
1805
+ ];
1806
+ }
1807
+
1808
+ function tetrad(color) {
1809
+ var hsl = tinycolor(color).toHsl();
1810
+ var h = hsl.h;
1811
+ return [
1812
+ tinycolor(color),
1813
+ tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
1814
+ tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
1815
+ tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
1816
+ ];
1817
+ }
1818
+
1819
+ function splitcomplement(color) {
1820
+ var hsl = tinycolor(color).toHsl();
1821
+ var h = hsl.h;
1822
+ return [
1823
+ tinycolor(color),
1824
+ tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
1825
+ tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
1826
+ ];
1827
+ }
1828
+
1829
+ function analogous(color, results, slices) {
1830
+ results = results || 6;
1831
+ slices = slices || 30;
1832
+
1833
+ var hsl = tinycolor(color).toHsl();
1834
+ var part = 360 / slices;
1835
+ var ret = [tinycolor(color)];
1836
+
1837
+ for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
1838
+ hsl.h = (hsl.h + part) % 360;
1839
+ ret.push(tinycolor(hsl));
1840
+ }
1841
+ return ret;
1842
+ }
1843
+
1844
+ function monochromatic(color, results) {
1845
+ results = results || 6;
1846
+ var hsv = tinycolor(color).toHsv();
1847
+ var h = hsv.h, s = hsv.s, v = hsv.v;
1848
+ var ret = [];
1849
+ var modification = 1 / results;
1850
+
1851
+ while (results--) {
1852
+ ret.push(tinycolor({ h: h, s: s, v: v}));
1853
+ v = (v + modification) % 1;
1854
+ }
1855
+
1856
+ return ret;
1857
+ }
1858
+
1859
+ // Utility Functions
1860
+ // ---------------------
1861
+
1862
+ tinycolor.mix = function(color1, color2, amount) {
1863
+ amount = (amount === 0) ? 0 : (amount || 50);
1864
+
1865
+ var rgb1 = tinycolor(color1).toRgb();
1866
+ var rgb2 = tinycolor(color2).toRgb();
1867
+
1868
+ var p = amount / 100;
1869
+ var w = p * 2 - 1;
1870
+ var a = rgb2.a - rgb1.a;
1871
+
1872
+ var w1;
1873
+
1874
+ if (w * a == -1) {
1875
+ w1 = w;
1876
+ } else {
1877
+ w1 = (w + a) / (1 + w * a);
1878
+ }
1879
+
1880
+ w1 = (w1 + 1) / 2;
1881
+
1882
+ var w2 = 1 - w1;
1883
+
1884
+ var rgba = {
1885
+ r: rgb2.r * w1 + rgb1.r * w2,
1886
+ g: rgb2.g * w1 + rgb1.g * w2,
1887
+ b: rgb2.b * w1 + rgb1.b * w2,
1888
+ a: rgb2.a * p + rgb1.a * (1 - p)
1889
+ };
1890
+
1891
+ return tinycolor(rgba);
1892
+ };
1893
+
1894
+
1895
+ // Readability Functions
1896
+ // ---------------------
1897
+ // <http://www.w3.org/TR/AERT#color-contrast>
1898
+
1899
+ // `readability`
1900
+ // Analyze the 2 colors and returns an object with the following properties:
1901
+ // `brightness`: difference in brightness between the two colors
1902
+ // `color`: difference in color/hue between the two colors
1903
+ tinycolor.readability = function(color1, color2) {
1904
+ var c1 = tinycolor(color1);
1905
+ var c2 = tinycolor(color2);
1906
+ var rgb1 = c1.toRgb();
1907
+ var rgb2 = c2.toRgb();
1908
+ var brightnessA = c1.getBrightness();
1909
+ var brightnessB = c2.getBrightness();
1910
+ var colorDiff = (
1911
+ Math.max(rgb1.r, rgb2.r) - Math.min(rgb1.r, rgb2.r) +
1912
+ Math.max(rgb1.g, rgb2.g) - Math.min(rgb1.g, rgb2.g) +
1913
+ Math.max(rgb1.b, rgb2.b) - Math.min(rgb1.b, rgb2.b)
1914
+ );
1915
+
1916
+ return {
1917
+ brightness: Math.abs(brightnessA - brightnessB),
1918
+ color: colorDiff
1919
+ };
1920
+ };
1921
+
1922
+ // `readable`
1923
+ // http://www.w3.org/TR/AERT#color-contrast
1924
+ // Ensure that foreground and background color combinations provide sufficient contrast.
1925
+ // *Example*
1926
+ // tinycolor.isReadable("#000", "#111") => false
1927
+ tinycolor.isReadable = function(color1, color2) {
1928
+ var readability = tinycolor.readability(color1, color2);
1929
+ return readability.brightness > 125 && readability.color > 500;
1930
+ };
1931
+
1932
+ // `mostReadable`
1933
+ // Given a base color and a list of possible foreground or background
1934
+ // colors for that base, returns the most readable color.
1935
+ // *Example*
1936
+ // tinycolor.mostReadable("#123", ["#fff", "#000"]) => "#000"
1937
+ tinycolor.mostReadable = function(baseColor, colorList) {
1938
+ var bestColor = null;
1939
+ var bestScore = 0;
1940
+ var bestIsReadable = false;
1941
+ for (var i=0; i < colorList.length; i++) {
1942
+
1943
+ // We normalize both around the "acceptable" breaking point,
1944
+ // but rank brightness constrast higher than hue.
1945
+
1946
+ var readability = tinycolor.readability(baseColor, colorList[i]);
1947
+ var readable = readability.brightness > 125 && readability.color > 500;
1948
+ var score = 3 * (readability.brightness / 125) + (readability.color / 500);
1949
+
1950
+ if ((readable && ! bestIsReadable) ||
1951
+ (readable && bestIsReadable && score > bestScore) ||
1952
+ ((! readable) && (! bestIsReadable) && score > bestScore)) {
1953
+ bestIsReadable = readable;
1954
+ bestScore = score;
1955
+ bestColor = tinycolor(colorList[i]);
1956
+ }
1957
+ }
1958
+ return bestColor;
1959
+ };
1960
+
1961
+
1962
+ // Big List of Colors
1963
+ // ------------------
1964
+ // <http://www.w3.org/TR/css3-color/#svg-color>
1965
+ var names = tinycolor.names = {
1966
+ aliceblue: "f0f8ff",
1967
+ antiquewhite: "faebd7",
1968
+ aqua: "0ff",
1969
+ aquamarine: "7fffd4",
1970
+ azure: "f0ffff",
1971
+ beige: "f5f5dc",
1972
+ bisque: "ffe4c4",
1973
+ black: "000",
1974
+ blanchedalmond: "ffebcd",
1975
+ blue: "00f",
1976
+ blueviolet: "8a2be2",
1977
+ brown: "a52a2a",
1978
+ burlywood: "deb887",
1979
+ burntsienna: "ea7e5d",
1980
+ cadetblue: "5f9ea0",
1981
+ chartreuse: "7fff00",
1982
+ chocolate: "d2691e",
1983
+ coral: "ff7f50",
1984
+ cornflowerblue: "6495ed",
1985
+ cornsilk: "fff8dc",
1986
+ crimson: "dc143c",
1987
+ cyan: "0ff",
1988
+ darkblue: "00008b",
1989
+ darkcyan: "008b8b",
1990
+ darkgoldenrod: "b8860b",
1991
+ darkgray: "a9a9a9",
1992
+ darkgreen: "006400",
1993
+ darkgrey: "a9a9a9",
1994
+ darkkhaki: "bdb76b",
1995
+ darkmagenta: "8b008b",
1996
+ darkolivegreen: "556b2f",
1997
+ darkorange: "ff8c00",
1998
+ darkorchid: "9932cc",
1999
+ darkred: "8b0000",
2000
+ darksalmon: "e9967a",
2001
+ darkseagreen: "8fbc8f",
2002
+ darkslateblue: "483d8b",
2003
+ darkslategray: "2f4f4f",
2004
+ darkslategrey: "2f4f4f",
2005
+ darkturquoise: "00ced1",
2006
+ darkviolet: "9400d3",
2007
+ deeppink: "ff1493",
2008
+ deepskyblue: "00bfff",
2009
+ dimgray: "696969",
2010
+ dimgrey: "696969",
2011
+ dodgerblue: "1e90ff",
2012
+ firebrick: "b22222",
2013
+ floralwhite: "fffaf0",
2014
+ forestgreen: "228b22",
2015
+ fuchsia: "f0f",
2016
+ gainsboro: "dcdcdc",
2017
+ ghostwhite: "f8f8ff",
2018
+ gold: "ffd700",
2019
+ goldenrod: "daa520",
2020
+ gray: "808080",
2021
+ green: "008000",
2022
+ greenyellow: "adff2f",
2023
+ grey: "808080",
2024
+ honeydew: "f0fff0",
2025
+ hotpink: "ff69b4",
2026
+ indianred: "cd5c5c",
2027
+ indigo: "4b0082",
2028
+ ivory: "fffff0",
2029
+ khaki: "f0e68c",
2030
+ lavender: "e6e6fa",
2031
+ lavenderblush: "fff0f5",
2032
+ lawngreen: "7cfc00",
2033
+ lemonchiffon: "fffacd",
2034
+ lightblue: "add8e6",
2035
+ lightcoral: "f08080",
2036
+ lightcyan: "e0ffff",
2037
+ lightgoldenrodyellow: "fafad2",
2038
+ lightgray: "d3d3d3",
2039
+ lightgreen: "90ee90",
2040
+ lightgrey: "d3d3d3",
2041
+ lightpink: "ffb6c1",
2042
+ lightsalmon: "ffa07a",
2043
+ lightseagreen: "20b2aa",
2044
+ lightskyblue: "87cefa",
2045
+ lightslategray: "789",
2046
+ lightslategrey: "789",
2047
+ lightsteelblue: "b0c4de",
2048
+ lightyellow: "ffffe0",
2049
+ lime: "0f0",
2050
+ limegreen: "32cd32",
2051
+ linen: "faf0e6",
2052
+ magenta: "f0f",
2053
+ maroon: "800000",
2054
+ mediumaquamarine: "66cdaa",
2055
+ mediumblue: "0000cd",
2056
+ mediumorchid: "ba55d3",
2057
+ mediumpurple: "9370db",
2058
+ mediumseagreen: "3cb371",
2059
+ mediumslateblue: "7b68ee",
2060
+ mediumspringgreen: "00fa9a",
2061
+ mediumturquoise: "48d1cc",
2062
+ mediumvioletred: "c71585",
2063
+ midnightblue: "191970",
2064
+ mintcream: "f5fffa",
2065
+ mistyrose: "ffe4e1",
2066
+ moccasin: "ffe4b5",
2067
+ navajowhite: "ffdead",
2068
+ navy: "000080",
2069
+ oldlace: "fdf5e6",
2070
+ olive: "808000",
2071
+ olivedrab: "6b8e23",
2072
+ orange: "ffa500",
2073
+ orangered: "ff4500",
2074
+ orchid: "da70d6",
2075
+ palegoldenrod: "eee8aa",
2076
+ palegreen: "98fb98",
2077
+ paleturquoise: "afeeee",
2078
+ palevioletred: "db7093",
2079
+ papayawhip: "ffefd5",
2080
+ peachpuff: "ffdab9",
2081
+ peru: "cd853f",
2082
+ pink: "ffc0cb",
2083
+ plum: "dda0dd",
2084
+ powderblue: "b0e0e6",
2085
+ purple: "800080",
2086
+ rebeccapurple: "663399",
2087
+ red: "f00",
2088
+ rosybrown: "bc8f8f",
2089
+ royalblue: "4169e1",
2090
+ saddlebrown: "8b4513",
2091
+ salmon: "fa8072",
2092
+ sandybrown: "f4a460",
2093
+ seagreen: "2e8b57",
2094
+ seashell: "fff5ee",
2095
+ sienna: "a0522d",
2096
+ silver: "c0c0c0",
2097
+ skyblue: "87ceeb",
2098
+ slateblue: "6a5acd",
2099
+ slategray: "708090",
2100
+ slategrey: "708090",
2101
+ snow: "fffafa",
2102
+ springgreen: "00ff7f",
2103
+ steelblue: "4682b4",
2104
+ tan: "d2b48c",
2105
+ teal: "008080",
2106
+ thistle: "d8bfd8",
2107
+ tomato: "ff6347",
2108
+ turquoise: "40e0d0",
2109
+ violet: "ee82ee",
2110
+ wheat: "f5deb3",
2111
+ white: "fff",
2112
+ whitesmoke: "f5f5f5",
2113
+ yellow: "ff0",
2114
+ yellowgreen: "9acd32"
2115
+ };
2116
+
2117
+ // Make it easy to access colors via `hexNames[hex]`
2118
+ var hexNames = tinycolor.hexNames = flip(names);
2119
+
2120
+
2121
+ // Utilities
2122
+ // ---------
2123
+
2124
+ // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
2125
+ function flip(o) {
2126
+ var flipped = { };
2127
+ for (var i in o) {
2128
+ if (o.hasOwnProperty(i)) {
2129
+ flipped[o[i]] = i;
2130
+ }
2131
+ }
2132
+ return flipped;
2133
+ }
2134
+
2135
+ // Return a valid alpha value [0,1] with all invalid values being set to 1
2136
+ function boundAlpha(a) {
2137
+ a = parseFloat(a);
2138
+
2139
+ if (isNaN(a) || a < 0 || a > 1) {
2140
+ a = 1;
2141
+ }
2142
+
2143
+ return a;
2144
+ }
2145
+
2146
+ // Take input from [0, n] and return it as [0, 1]
2147
+ function bound01(n, max) {
2148
+ if (isOnePointZero(n)) { n = "100%"; }
2149
+
2150
+ var processPercent = isPercentage(n);
2151
+ n = mathMin(max, mathMax(0, parseFloat(n)));
2152
+
2153
+ // Automatically convert percentage into number
2154
+ if (processPercent) {
2155
+ n = parseInt(n * max, 10) / 100;
2156
+ }
2157
+
2158
+ // Handle floating point rounding errors
2159
+ if ((math.abs(n - max) < 0.000001)) {
2160
+ return 1;
2161
+ }
2162
+
2163
+ // Convert into [0, 1] range if it isn't already
2164
+ return (n % max) / parseFloat(max);
2165
+ }
2166
+
2167
+ // Force a number between 0 and 1
2168
+ function clamp01(val) {
2169
+ return mathMin(1, mathMax(0, val));
2170
+ }
2171
+
2172
+ // Parse a base-16 hex value into a base-10 integer
2173
+ function parseIntFromHex(val) {
2174
+ return parseInt(val, 16);
2175
+ }
2176
+
2177
+ // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
2178
+ // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
2179
+ function isOnePointZero(n) {
2180
+ return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
2181
+ }
2182
+
2183
+ // Check to see if string passed in is a percentage
2184
+ function isPercentage(n) {
2185
+ return typeof n === "string" && n.indexOf('%') != -1;
2186
+ }
2187
+
2188
+ // Force a hex value to have 2 characters
2189
+ function pad2(c) {
2190
+ return c.length == 1 ? '0' + c : '' + c;
2191
+ }
2192
+
2193
+ // Replace a decimal with it's percentage value
2194
+ function convertToPercentage(n) {
2195
+ if (n <= 1) {
2196
+ n = (n * 100) + "%";
2197
+ }
2198
+
2199
+ return n;
2200
+ }
2201
+
2202
+ // Converts a decimal to a hex value
2203
+ function convertDecimalToHex(d) {
2204
+ return Math.round(parseFloat(d) * 255).toString(16);
2205
+ }
2206
+ // Converts a hex value to a decimal
2207
+ function convertHexToDecimal(h) {
2208
+ return (parseIntFromHex(h) / 255);
2209
+ }
2210
+
2211
+ var matchers = (function() {
2212
+
2213
+ // <http://www.w3.org/TR/css3-values/#integers>
2214
+ var CSS_INTEGER = "[-\\+]?\\d+%?";
2215
+
2216
+ // <http://www.w3.org/TR/css3-values/#number-value>
2217
+ var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
2218
+
2219
+ // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
2220
+ var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
2221
+
2222
+ // Actual matching.
2223
+ // Parentheses and commas are optional, but not required.
2224
+ // Whitespace can take the place of commas or opening paren
2225
+ var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
2226
+ var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
2227
+
2228
+ return {
2229
+ rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
2230
+ rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
2231
+ hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
2232
+ hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
2233
+ hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
2234
+ hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
2235
+ hex3: /^([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
2236
+ hex6: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
2237
+ hex8: /^([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
2238
+ };
2239
+ })();
2240
+
2241
+ // `stringInputToObject`
2242
+ // Permissive string parsing. Take in a number of formats, and output an object
2243
+ // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
2244
+ function stringInputToObject(color) {
2245
+
2246
+ color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
2247
+ var named = false;
2248
+ if (names[color]) {
2249
+ color = names[color];
2250
+ named = true;
2251
+ }
2252
+ else if (color == 'transparent') {
2253
+ return { r: 0, g: 0, b: 0, a: 0, format: "name" };
2254
+ }
2255
+
2256
+ // Try to match string input using regular expressions.
2257
+ // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
2258
+ // Just return an object and let the conversion functions handle that.
2259
+ // This way the result will be the same whether the tinycolor is initialized with string or object.
2260
+ var match;
2261
+ if ((match = matchers.rgb.exec(color))) {
2262
+ return { r: match[1], g: match[2], b: match[3] };
2263
+ }
2264
+ if ((match = matchers.rgba.exec(color))) {
2265
+ return { r: match[1], g: match[2], b: match[3], a: match[4] };
2266
+ }
2267
+ if ((match = matchers.hsl.exec(color))) {
2268
+ return { h: match[1], s: match[2], l: match[3] };
2269
+ }
2270
+ if ((match = matchers.hsla.exec(color))) {
2271
+ return { h: match[1], s: match[2], l: match[3], a: match[4] };
2272
+ }
2273
+ if ((match = matchers.hsv.exec(color))) {
2274
+ return { h: match[1], s: match[2], v: match[3] };
2275
+ }
2276
+ if ((match = matchers.hsva.exec(color))) {
2277
+ return { h: match[1], s: match[2], v: match[3], a: match[4] };
2278
+ }
2279
+ if ((match = matchers.hex8.exec(color))) {
2280
+ return {
2281
+ a: convertHexToDecimal(match[1]),
2282
+ r: parseIntFromHex(match[2]),
2283
+ g: parseIntFromHex(match[3]),
2284
+ b: parseIntFromHex(match[4]),
2285
+ format: named ? "name" : "hex8"
2286
+ };
2287
+ }
2288
+ if ((match = matchers.hex6.exec(color))) {
2289
+ return {
2290
+ r: parseIntFromHex(match[1]),
2291
+ g: parseIntFromHex(match[2]),
2292
+ b: parseIntFromHex(match[3]),
2293
+ format: named ? "name" : "hex"
2294
+ };
2295
+ }
2296
+ if ((match = matchers.hex3.exec(color))) {
2297
+ return {
2298
+ r: parseIntFromHex(match[1] + '' + match[1]),
2299
+ g: parseIntFromHex(match[2] + '' + match[2]),
2300
+ b: parseIntFromHex(match[3] + '' + match[3]),
2301
+ format: named ? "name" : "hex"
2302
+ };
2303
+ }
2304
+
2305
+ return false;
2306
+ }
2307
+
2308
+ window.tinycolor = tinycolor;
2309
+ })();
2310
+
2311
+ $(function () {
2312
+ if ($.fn.spectrum.load) {
2313
+ $.fn.spectrum.processNativeColorInputs();
2314
+ }
2315
+ });
2316
+
2317
+ });
includes/Addons.class.php CHANGED
@@ -111,7 +111,7 @@ class rtbAddons {
111
  </div>
112
  </div>
113
  </div>
114
- </div>
115
  <h2>Recommended Themes</h2>
116
  <p>The following restaurant themes integrate beautifully with Restaurant Reservations, providing a clean, stylized booking form that matches your site's design.</p>
117
  <div class="rtb-addons">
@@ -324,7 +324,7 @@ class rtbAddons {
324
  </div>
325
  </div>
326
  </div>
327
- </div>
328
  <?php do_action( 'rtb_addons_post' ); ?>
329
  </div>
330
 
111
  </div>
112
  </div>
113
  </div>
114
+ </div><?php /*
115
  <h2>Recommended Themes</h2>
116
  <p>The following restaurant themes integrate beautifully with Restaurant Reservations, providing a clean, stylized booking form that matches your site's design.</p>
117
  <div class="rtb-addons">
324
  </div>
325
  </div>
326
  </div>
327
+ </div>*/ ?>
328
  <?php do_action( 'rtb_addons_post' ); ?>
329
  </div>
330
 
includes/AdminBookings.class.php CHANGED
@@ -43,6 +43,9 @@ class rtbAdminBookings {
43
  add_action( 'wp_ajax_nopriv_rtb-admin-delete-modal' , array( $this , 'nopriv_ajax' ) );
44
  add_action( 'wp_ajax_rtb-admin-delete-modal', array( $this, 'delete_modal_ajax' ) );
45
 
 
 
 
46
  // Validate post status and notification fields
47
  add_action( 'rtb_validate_booking_submission', array( $this, 'validate_admin_fields' ) );
48
 
@@ -841,6 +844,31 @@ class rtbAdminBookings {
841
  );
842
  }
843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  /**
845
  * Validate post status and notification fields
846
  * @since 1.3
43
  add_action( 'wp_ajax_nopriv_rtb-admin-delete-modal' , array( $this , 'nopriv_ajax' ) );
44
  add_action( 'wp_ajax_rtb-admin-delete-modal', array( $this, 'delete_modal_ajax' ) );
45
 
46
+ add_action( 'wp_ajax_nopriv_rtb_set_reservation_arrived' , array( $this , 'nopriv_ajax' ) );
47
+ add_action( 'wp_ajax_rtb_set_reservation_arrived', array( $this, 'set_booking_arrived' ) );
48
+
49
  // Validate post status and notification fields
50
  add_action( 'rtb_validate_booking_submission', array( $this, 'validate_admin_fields' ) );
51
 
844
  );
845
  }
846
 
847
+ /**
848
+ * Register a party as having arrived
849
+ * @since 2.0.0
850
+ */
851
+ public function set_booking_arrived() {
852
+ $booking_id = isset($_POST['booking_id']) ? $_POST['booking_id'] : 0;
853
+
854
+ $booking_id = wp_update_post(array(
855
+ 'ID' => $booking_id,
856
+ 'post_status' => 'arrived'
857
+ ) );
858
+
859
+ if ( $booking_id ) {
860
+ wp_send_json_success();
861
+ }
862
+ else {
863
+ wp_send_json_error(
864
+ array(
865
+ 'error' => 'loggedout',
866
+ 'msg' => sprintf( __( 'You have been logged out. Please %slogin again%s.', 'restaurant-reservations' ), '<a href="' . wp_login_url( ) . '">', '</a>' ),
867
+ )
868
+ );
869
+ }
870
+ }
871
+
872
  /**
873
  * Validate post status and notification fields
874
  * @since 1.3
includes/Ajax.class.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbAJAX' ) ) {
5
+ /**
6
+ * Class to handle AJAX date interactions for Restaurant Reservations
7
+ *
8
+ * @since 2.0.0
9
+ */
10
+ class rtbAJAX {
11
+
12
+ /**
13
+ * The year of the booking date we're getting timeslots for
14
+ * @since 2.0.0
15
+ */
16
+ public $year;
17
+
18
+ /**
19
+ * The month of the booking date we're getting timeslots for
20
+ * @since 2.0.0
21
+ */
22
+ public $month;
23
+
24
+ /**
25
+ * The day of the booking date we're getting timeslots for
26
+ * @since 2.0.0
27
+ */
28
+ public $day;
29
+
30
+ public function __construct() {
31
+
32
+ add_action( 'wp_ajax_nopriv_rtb_get_available_time_slots', array( $this, 'get_time_slots' ) );
33
+ }
34
+
35
+ /**
36
+ * Load the plugin's default settings
37
+ * @since 2.0.0
38
+ */
39
+ public function get_time_slots() {
40
+ global $rtb_controller;
41
+
42
+ $max_reservations_setting = $rtb_controller->settings->get_setting( 'rtb-max-tables-count' );
43
+ $max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
44
+
45
+ $this->year = sanitize_text_field( $_POST['year'] );
46
+ $this->month = sanitize_text_field( $_POST['month'] );
47
+ $this->day = sanitize_text_field( $_POST['day'] );
48
+
49
+ $dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
50
+ $dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
51
+ $dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
52
+
53
+ // Get opening/closing times for this particular day
54
+ $hours = $this->get_opening_hours();
55
+
56
+ // If the restaurant is closed that day, return false
57
+ if ( ! $hours ) { echo $hours; die(); }
58
+
59
+ $args = array(
60
+ 'post_count' => -1,
61
+ 'date_range' => 'dates',
62
+ 'start_date' => $this->year . '-' . $this->month . '-' . $this->day,
63
+ 'end_date' => $this->year . '-' . $this->month . '-' . $this->day
64
+ );
65
+
66
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
67
+ $query = new rtbQuery( $args );
68
+ $query->prepare_args();
69
+
70
+ // Get all current booking times in seconds from UNIX
71
+ $times = array();
72
+ foreach ( $query->get_bookings() as $booking ) {
73
+ $times[] = strtotime( $booking->date );
74
+ }
75
+
76
+ sort( $times );
77
+
78
+ // Go through all current booking times and figure out when we're at or above the max
79
+ $blocked = false;
80
+ $blocked_times = array();
81
+ $current_times = array();
82
+ if ($max_reservations != 'undefined' and $max_reservations != 0) {
83
+ foreach ( $times as $time ) {
84
+ $current_times[] = $time;
85
+
86
+ while ( sizeOf( $current_times ) > 0 and reset( $current_times ) < $time - $dining_block_seconds ) { array_shift( $current_times ); }
87
+
88
+ if ( $blocked and sizeOf( $current_times ) < $max_reservations ) {
89
+ $blocked = false;
90
+ $blocked_times[] = $time + $dining_block_seconds;
91
+ }
92
+
93
+ // Check if we're at or above the maximum number of reservations
94
+ if ( sizeOf( $current_times ) >= $max_reservations ) {
95
+ $blocked = true;
96
+ $blocked_times[] = $time - $dining_block_seconds;
97
+ }
98
+ }
99
+ }
100
+
101
+ if ( $blocked ) { $blocked_times[] = end( $current_times ) + $dining_block_seconds; }
102
+
103
+ $combined_times = array_merge( $blocked_times, $hours );
104
+ sort( $combined_times );
105
+
106
+ //Go through all of times to determine when the restaurant is open and not blocked
107
+ $open = false;
108
+ $blocked = false;
109
+ $valid_times = array();
110
+ foreach ( $combined_times as $time ) {
111
+ if ( in_array( $time, $blocked_times ) ) {
112
+ if ( ! $blocked ) {
113
+ $blocked = true;
114
+ if ( $open ) {
115
+ $valid_times[] = (object) array( 'from' => $this->format_pickadate_time( $open_time ), 'to' => $this->format_pickadate_time( $time ), 'inverted' => true );
116
+ }
117
+ }
118
+ else {
119
+ $blocked = false;
120
+ if ( $open ) { $open_time = $time; }
121
+ }
122
+ }
123
+ else {
124
+ if ( ! $open ) {
125
+ $open = true;
126
+ if ( ! $blocked ) { $open_time = $time; }
127
+ }
128
+ else {
129
+ $open = false;
130
+ if ( ! $blocked ) { $valid_times[] = (object) array( 'from' => $this->format_pickadate_time( $open_time ), 'to' => $this->format_pickadate_time( $time ), 'inverted' => true ); }
131
+ }
132
+ }
133
+ }
134
+
135
+ echo json_encode( $valid_times );
136
+
137
+ die();
138
+ }
139
+
140
+ public function get_opening_hours() {
141
+ global $rtb_controller;
142
+
143
+ $schedule_closed = $rtb_controller->settings->get_setting( 'schedule-closed' );
144
+
145
+ $valid_times = array();
146
+
147
+ // Check if this date is an exception to the rules
148
+ if ( $schedule_closed !== 'undefined' ) {
149
+
150
+ foreach ( $schedule_closed as $closing ) {
151
+ $time = strtotime( $closing['date'] );
152
+
153
+ if ( date( 'Y', $time ) == $this->year &&
154
+ date( 'm', $time ) == $this->month &&
155
+ date( 'd', $time ) == $this->day
156
+ ) {
157
+
158
+ // Closed all day
159
+ if ( $closing['time'] == 'undefined' ) {
160
+ return false;
161
+ }
162
+
163
+ if ( $closing['time']['start'] !== 'undefined' ) {
164
+ $open_time = strtotime( $closing['date'] . ' ' . $closing['time']['start'] );
165
+ } else {
166
+ $open_time = strtotime( $closing['date'] ); // Start of the day
167
+ }
168
+
169
+ if ( $closing['time']['end'] !== 'undefined' ) {
170
+ $close_time = strtotime( $closing['date'] . ' ' . $closing['time']['end'] );
171
+ } else {
172
+ $close_time = strtotime( $closing['date'] . ' 23:59:59' ); // End of the day
173
+ }
174
+
175
+ $open_time = $this->get_earliest_time( $open_time );
176
+
177
+ if ( $open_time < $close_time ) {
178
+ $valid_times[] = $open_time;
179
+ $valid_times[] = $close_time;
180
+ }
181
+ else {
182
+ return false;
183
+ }
184
+ }
185
+ }
186
+
187
+ // Exit early if this date is an exception
188
+ if ( isset( $open_time ) ) {
189
+ return $valid_times;
190
+ }
191
+ }
192
+
193
+ $schedule_open = $rtb_controller->settings->get_setting( 'schedule-open' );
194
+
195
+ // Get any rules which apply to this weekday
196
+ if ( $schedule_open != 'undefined' ) {
197
+
198
+ $day_of_week = strtolower( date( 'l', strtotime( $this->year . '-' . $this->month . '-' . $this->day . ' 1:00:00' ) ) );
199
+
200
+ foreach ( $schedule_open as $opening ) {
201
+
202
+ if ( $opening['weekdays'] !== 'undefined' ) {
203
+ foreach ( $opening['weekdays'] as $weekday => $value ) {
204
+ if ( $weekday == $day_of_week ) {
205
+
206
+ // Closed all day
207
+ if ( $opening->time == 'undefined' ) {
208
+ return false;
209
+ }
210
+
211
+ if ( $opening['time']['start'] !== 'undefined' ) {
212
+ $open_time = strtotime( $this->year . '-' . $this->month . '-' . $this->day . ' ' . $opening['time']['start'] );
213
+ } else {
214
+ $open_time = strtotime( $this->year . '-' . $this->month . '-' . $this->day );
215
+ }
216
+
217
+ if ( $opening['time']['end'] !== 'undefined' ) {
218
+ $close_time = strtotime( $this->year . '-' . $this->month . '-' . $this->day . ' ' . $opening['time']['end'] );
219
+ } else {
220
+ $close_time = strtotime( $this->year . '-' . $this->month . '-' . $this->day . ' 23:59:59' ); // End of the day
221
+ }
222
+
223
+ $open_time = $this->get_earliest_time( $open_time );
224
+
225
+ if ( $open_time < $close_time ) {
226
+ $valid_times[] = $open_time;
227
+ $valid_times[] = $close_time;
228
+ }
229
+ else {
230
+ return false;
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ // Pass any valid times located
238
+ if ( sizeOf( $valid_times ) >= 1 ) {
239
+ return $valid_times;
240
+ }
241
+ }
242
+
243
+ return false;
244
+ }
245
+
246
+ public function get_earliest_time( $open_time ) {
247
+ global $rtb_controller;
248
+
249
+ // Only make adjustments for current day selections
250
+ if ( date( 'y-m-d', strtotime( $this->year . '-' . $this->month . '-' . $this->day ) ) !== date( 'y-m-d' ) ) {
251
+ return $open_time;
252
+ }
253
+
254
+ $late_bookings = ( is_admin() && current_user_can( 'manage_bookings' ) ) ? '' : $rtb_controller->settings->get_setting( 'late-bookings' );
255
+
256
+ $open_time = time() > $open_time ? time() : $open_time;
257
+
258
+ if ( $late_bookings === 'number' && $late_bookings % 1 === 0 ) {
259
+ if ( time() + $late_bookings * 60 > $open_time ) {
260
+ $open_time = time() + $late_bookings;
261
+ }
262
+ }
263
+
264
+ return $open_time;
265
+ }
266
+
267
+ public function format_pickadate_time( $time ) {
268
+ return array( date( 'G', $time ), date( 'i', $time ) );
269
+ }
270
+ }
271
+
272
+ }
includes/Booking.class.php CHANGED
@@ -82,6 +82,7 @@ class rtbBooking {
82
  'logs' => array(),
83
  'ip' => '',
84
  'consent_acquired' => '',
 
85
  );
86
 
87
  $meta_defaults = apply_filters( 'rtb_booking_metadata_defaults', $meta_defaults );
@@ -457,12 +458,22 @@ class rtbBooking {
457
  // Message
458
  $this->message = empty( $_POST['rtb-message'] ) ? '' : nl2br( wp_kses_post( stripslashes_deep( $_POST['rtb-message'] ) ) );
459
 
460
- // Post Status (define a default post status is none passed)
461
  if ( !empty( $_POST['rtb-post-status'] ) && array_key_exists( $_POST['rtb-post-status'], $rtb_controller->cpts->booking_statuses ) ) {
462
  $this->post_status = sanitize_text_field( stripslashes_deep( $_POST['rtb-post-status'] ) );
 
 
463
  } else {
464
  $this->post_status = 'pending';
465
  }
 
 
 
 
 
 
 
 
466
 
467
  // Consent
468
  $require_consent = $rtb_controller->settings->get_setting( 'require-consent' );
@@ -613,6 +624,116 @@ class rtbBooking {
613
  return true;
614
  }
615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
616
  /**
617
  * Add a log entry to the booking
618
  *
@@ -696,6 +817,14 @@ class rtbBooking {
696
  $meta['logs'] = $this->logs;
697
  }
698
 
 
 
 
 
 
 
 
 
699
  $meta = apply_filters( 'rtb_insert_booking_metadata', $meta, $this );
700
 
701
  return update_post_meta( $this->ID, 'rtb', $meta );
82
  'logs' => array(),
83
  'ip' => '',
84
  'consent_acquired' => '',
85
+ 'reminder_sent' => false,
86
  );
87
 
88
  $meta_defaults = apply_filters( 'rtb_booking_metadata_defaults', $meta_defaults );
458
  // Message
459
  $this->message = empty( $_POST['rtb-message'] ) ? '' : nl2br( wp_kses_post( stripslashes_deep( $_POST['rtb-message'] ) ) );
460
 
461
+ // Post Status (define a default post status if none passed)
462
  if ( !empty( $_POST['rtb-post-status'] ) && array_key_exists( $_POST['rtb-post-status'], $rtb_controller->cpts->booking_statuses ) ) {
463
  $this->post_status = sanitize_text_field( stripslashes_deep( $_POST['rtb-post-status'] ) );
464
+ } elseif ( $this->party < $rtb_controller->settings->get_setting( 'auto-confirm-max-party-size' ) ) {
465
+ $this->post_status = 'confirmed';
466
  } else {
467
  $this->post_status = 'pending';
468
  }
469
+
470
+ // Check if the post status should be changed to confirmed, based on the maximum number of reservations and/or seats for auto-confirmation
471
+ if ( $rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' ) ) {
472
+ $this->post_status = $this->under_max_confirm_reservations() ? 'confirmed' : $this->post_status;
473
+ }
474
+ if ( $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' ) ) {
475
+ $this->post_status = $this->under_max_confirm_seats() ? 'confirmed' : $this->post_status;
476
+ }
477
 
478
  // Consent
479
  $require_consent = $rtb_controller->settings->get_setting( 'require-consent' );
624
  return true;
625
  }
626
 
627
+ /**
628
+ * Check whether the number of reservations occurring at the same time is below the threshold
629
+ * where reservations get automatically confirmed
630
+ *
631
+ * @since 2.0.0
632
+ */
633
+ public function under_max_confirm_reservations() {
634
+ global $rtb_controller;
635
+
636
+ $max_reservations_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-reservations' );
637
+ $max_reservations = substr( $max_reservations_setting, 0, strpos( $max_reservations_setting, '_' ) );
638
+
639
+ if ($max_reservations == 'undefined' or $max_reservations == 0) { return; }
640
+
641
+ $dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
642
+ $dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
643
+ $dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
644
+
645
+ $after_time = strtotime($this->date) - $dining_block_seconds;
646
+ $before_time = strtotime($this->date) + $dining_block_seconds;
647
+
648
+ $args = array(
649
+ 'post_count' => -1,
650
+ 'date_query' => array(
651
+ 'before' => date( 'c', $before_time ),
652
+ 'after' => date( 'c', $after_time )
653
+ )
654
+ );
655
+
656
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
657
+ $query = new rtbQuery( $args );
658
+
659
+ $times = array();
660
+ foreach ( $query->get_bookings() as $booking ) {
661
+ $times[] = strtotime( $booking->date );
662
+ }
663
+
664
+ sort( $times );
665
+
666
+ $auto_confirm = true;
667
+ $current_times = array();
668
+ foreach ( $times as $time ) {
669
+ $current_times[] = $time;
670
+
671
+ if ( reset( $current_times ) < $time - $dining_block_seconds ) { array_shift( $current_times ); }
672
+
673
+ // Check if we've reached 1 below the max confirmation number, since adding the current booking will put us at the threshold
674
+ if ( sizeOf( $current_times ) + 1 >= $max_reservations ) { $auto_confirm = false; break; }
675
+ }
676
+
677
+ return $auto_confirm;
678
+ }
679
+
680
+ /**
681
+ * Check whether the number of seats occurring at the same time is below the threshold
682
+ * where reservations get automatically confirmed
683
+ *
684
+ * @since 2.0.0
685
+ */
686
+ public function under_max_confirm_seats() {
687
+ global $rtb_controller;
688
+
689
+ $max_seats_setting = $rtb_controller->settings->get_setting( 'auto-confirm-max-seats' );
690
+ $max_seats = substr( $max_seats_setting, 0, strpos( $max_seats_setting, '_' ) );
691
+
692
+ if ($max_seats == 'undefined' or $max_seats == 0) { return; }
693
+
694
+ $dining_block_setting = $rtb_controller->settings->get_setting( 'rtb-dining-block-length' );
695
+ $dining_block = substr( $dining_block_setting, 0, strpos( $dining_block_setting, '_' ) );
696
+ $dining_block_seconds = ( $dining_block * 60 - 1 ); // Take 1 second off, to avoid bookings that start or end exactly at the beginning of a booking block
697
+
698
+ $after_time = strtotime($this->date) - $dining_block_seconds;
699
+ $before_time = strtotime($this->date) + $dining_block_seconds;
700
+
701
+ $args = array(
702
+ 'post_count' => -1,
703
+ 'date_query' => array(
704
+ 'before' => date( 'c', $before_time ),
705
+ 'after' => date( 'c', $after_time )
706
+ )
707
+ );
708
+
709
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
710
+ $query = new rtbQuery( $args );
711
+
712
+ $times = array();
713
+ foreach ( $query->get_bookings() as $booking ) {
714
+ $booking_time = strtotime( $booking->date );
715
+ if ( isset( $times[$booking_time] ) ) { $times[$booking_time] += $booking->party; }
716
+ else { $times[$booking_time] = $booking->party; }
717
+ }
718
+
719
+ ksort( $times );
720
+
721
+ $auto_confirm = true;
722
+ $current_seats = array();
723
+ foreach ( $times as $time => $seats ) {
724
+ $current_seats[$time] = $seats;
725
+
726
+ reset( $current_seats );
727
+
728
+ if ( key ( $current_seats ) < $time - $dining_block_seconds ) { array_shift( $current_seats ); }
729
+
730
+ // Check if adding the current party puts us at or above the max confirmation number
731
+ if ( array_sum( $current_seats ) + $this->party >= $max_seats ) { $auto_confirm = false; break; }
732
+ }
733
+
734
+ return $auto_confirm;
735
+ }
736
+
737
  /**
738
  * Add a log entry to the booking
739
  *
817
  $meta['logs'] = $this->logs;
818
  }
819
 
820
+ if ( !empty( $this->reminder_sent ) ) {
821
+ $meta['reminder_sent'] = $this->reminder_sent;
822
+ }
823
+
824
+ if ( !empty( $this->late_arrival_sent ) ) {
825
+ $meta['late_arrival_sent'] = $this->late_arrival_sent;
826
+ }
827
+
828
  $meta = apply_filters( 'rtb_insert_booking_metadata', $meta, $this );
829
 
830
  return update_post_meta( $this->ID, 'rtb', $meta );
includes/Compatibility.class.php CHANGED
@@ -26,8 +26,8 @@ class rtbCompatibility {
26
  // Run a filter deprecrated in 1.4.3
27
  add_filter( 'rtb_bookings_table_views_date_range', array( $this, 'rtn_bookings_table_views_schedule' ) );
28
 
29
- // Make sure custom fields don't completely disappear in 1.5
30
- add_action( 'admin_init', array( $this, 'maybe_bridge_cffrtb_to_1_5' ) );
31
 
32
  }
33
 
@@ -65,9 +65,9 @@ class rtbCompatibility {
65
  * Check whether or not we need to run some compatibiilty code for older
66
  * versions of the Custom Fields addon.
67
  *
68
- * @since 0.1
69
  */
70
- public function maybe_bridge_cffrtb_to_1_5() {
71
  if ( !function_exists( 'cffrtbInit' ) || !function_exists( 'get_plugin_data' ) ) {
72
  return;
73
  }
@@ -78,7 +78,7 @@ class rtbCompatibility {
78
  }
79
 
80
  add_filter( 'rtb_bookings_table_column_details', array( $this, 'add_cffrtb_fields_to_details' ), 11, 2 );
81
- }
82
 
83
  /**
84
  * Add custom fields output to details column
@@ -92,9 +92,9 @@ class rtbCompatibility {
92
  * But this will at least ensure that the data doesn't disappear and users
93
  * can then update to get the full functionality.
94
  *
95
- * @since 1.5
96
  */
97
- public function add_cffrtb_fields_to_details( $details, $booking ) {
98
 
99
  if ( !isset( $booking->custom_fields ) ) {
100
  return $details;
@@ -109,7 +109,7 @@ class rtbCompatibility {
109
  }
110
 
111
  return $details;
112
- }
113
  }
114
  } // endif
115
 
26
  // Run a filter deprecrated in 1.4.3
27
  add_filter( 'rtb_bookings_table_views_date_range', array( $this, 'rtn_bookings_table_views_schedule' ) );
28
 
29
+ // Make sure custom fields don't completely disappear in 1.5, should no longer be needed
30
+ //add_action( 'admin_init', array( $this, 'maybe_bridge_cffrtb_to_1_5' ) );
31
 
32
  }
33
 
65
  * Check whether or not we need to run some compatibiilty code for older
66
  * versions of the Custom Fields addon.
67
  *
68
+ * @since 0.1 // THIS FUNCTION SHOULD NO LONGER BE NECESSARY AFTER MERGING CODE BASES
69
  */
70
+ /*public function maybe_bridge_cffrtb_to_1_5() {
71
  if ( !function_exists( 'cffrtbInit' ) || !function_exists( 'get_plugin_data' ) ) {
72
  return;
73
  }
78
  }
79
 
80
  add_filter( 'rtb_bookings_table_column_details', array( $this, 'add_cffrtb_fields_to_details' ), 11, 2 );
81
+ }*/
82
 
83
  /**
84
  * Add custom fields output to details column
92
  * But this will at least ensure that the data doesn't disappear and users
93
  * can then update to get the full functionality.
94
  *
95
+ * @since 1.5 // THIS FUNCTION SHOULD NO LONGER BE NECESSARY AFTER MERGING CODE BASES
96
  */
97
+ /*public function add_cffrtb_fields_to_details( $details, $booking ) {
98
 
99
  if ( !isset( $booking->custom_fields ) ) {
100
  return $details;
109
  }
110
 
111
  return $details;
112
+ }*/
113
  }
114
  } // endif
115
 
includes/Cron.class.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbCron' ) ) {
5
+ /**
6
+ * This class handles scheduling of cron jobs for different notifications
7
+ * such as reservation reminders or when customers are late for their reservations
8
+ *
9
+ * @since 2.0.0
10
+ */
11
+ class rtbCron {
12
+
13
+ /**
14
+ * Adds the necessary filter and action calls
15
+ * @since 2.0.0
16
+ */
17
+ public function __construct() {
18
+ add_filter( 'cron_schedules', array($this, 'add_cron_interval') );
19
+
20
+ add_action( 'rtb_cron_jobs', array($this, 'handle_late_arrivals_task') );
21
+ add_action( 'rtb_cron_jobs', array($this, 'handle_reminder_task') );
22
+
23
+ add_action('admin_init', array($this, 'handle_reminder_task') );
24
+ }
25
+
26
+ /**
27
+ * Adds in 2, 5, 15, and 30 minute cron intervals
28
+ *
29
+ * @var array $schedules
30
+ * @since 2.0.0
31
+ */
32
+ public function add_cron_interval( $schedules ) {
33
+ $schedules['ten_minutes'] = array(
34
+ 'interval' => 600,
35
+ 'display' => esc_html__( 'Every Ten Minutes' )
36
+ );
37
+
38
+ return $schedules;
39
+ }
40
+
41
+ /**
42
+ * Creates a scheduled action called by wp_cron every 10 minutes
43
+ * The class hooks into those calls for reminders and late arrivals
44
+ *
45
+ * @since 2.0.0
46
+ */
47
+ public function schedule_events() {
48
+ if (! wp_next_scheduled ( 'rtb_cron_jobs' )) {
49
+ wp_schedule_event( time(), 'ten_minutes', 'rtb_cron_jobs' );
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Clears the rtb_cron_job hook so that it's no longer called after the plugin is deactivated
55
+ *
56
+ * @since 2.0.0
57
+ */
58
+ public function unschedule_events() {
59
+ wp_clear_scheduled_hook( 'rtb_cron_jobs' );
60
+ }
61
+
62
+ /**
63
+ * Handles the late arrival event when called by wp_scheduler
64
+ *
65
+ * @since 2.0.0
66
+ */
67
+ public function handle_late_arrivals_task() {
68
+ global $rtb_controller;
69
+
70
+ if ( ! $rtb_controller->settings->get_setting( 'time-reminder-user' ) ) { return; }
71
+
72
+ $bookings = $this->get_late_arrival_posts();
73
+
74
+ foreach ($bookings as $booking) {
75
+ $booking_data = get_post_meta( $booking->ID, 'rtb', true );
76
+
77
+ $notifications_sent = (isset($booking_data['late_arrival_sent']) ? $booking_data['late_arrival_sent'] : false );
78
+
79
+ if ( ! $notifications_sent ) {
80
+ $notification = new rtbNotificationEmail( 'late_user', 'user' );
81
+
82
+ $notification->set_booking($booking);
83
+
84
+ $notification->prepare_notification();
85
+
86
+ do_action( 'rtb_send_notification_before', $notification );
87
+ $sent = $notification->send_notification();
88
+ do_action( 'rtb_send_notification_after', $notification );
89
+
90
+ if ( $sent ) {
91
+ $booking->late_arrival_sent = true;
92
+ $booking->insert_post_meta();
93
+ }
94
+ }
95
+ }
96
+
97
+ wp_reset_postdata();
98
+ }
99
+
100
+ /**
101
+ * Handles the notification reminders event when called by wp_scheduler
102
+ *
103
+ * @since 2.0.0
104
+ */
105
+ public function handle_reminder_task() {
106
+ global $rtb_controller;
107
+
108
+ if ( ! $rtb_controller->settings->get_setting( 'time-reminder-user' ) ) { return; }
109
+
110
+ $bookings = $this->get_reminder_posts();
111
+
112
+ foreach ($bookings as $booking) {
113
+ $booking_data = get_post_meta( $booking->ID, 'rtb', true );
114
+
115
+ $notifications_sent = (isset($booking_data['reminder_sent']) ? $booking_data['reminder_sent'] : false );
116
+
117
+ if ( ! $notifications_sent ) {
118
+ $notification = new rtbNotificationEmail( 'reminder', 'user' );
119
+
120
+ $notification->set_booking($booking);
121
+
122
+ $notification->prepare_notification();
123
+
124
+ do_action( 'rtb_send_notification_before', $notification );
125
+ $sent = $notification->send_notification();
126
+ do_action( 'rtb_send_notification_after', $notification );
127
+
128
+ if ( $sent ) {
129
+ $booking->reminder_sent = true;
130
+ $booking->insert_post_meta();
131
+ }
132
+ }
133
+ }
134
+
135
+ wp_reset_postdata();
136
+ }
137
+
138
+ /**
139
+ * Gets the bookings that might need reminders sent to them
140
+ *
141
+ * @since 2.0.0
142
+ */
143
+ public function get_late_arrival_posts() {
144
+ global $rtb_controller;
145
+
146
+ $late_arrival_time = $rtb_controller->settings->get_setting( 'time-late-user' );
147
+ $count = substr( $late_arrival_time, 0, strpos( $late_arrival_time, "_" ) );
148
+ $unit = substr( $late_arrival_time, strpos( $late_arrival_time, "_" ) + 1 );
149
+
150
+ $time_interval = $this->get_time_interval( $count, $unit );
151
+
152
+ $after_datetime = new DateTime( '@' . ( time() - ( $time_interval + 3600 ) ) );
153
+ $before_datetime = new DateTime( '@' . ( time() - $time_interval ) );
154
+
155
+
156
+ $args = array(
157
+ 'post_status' => 'confirmed,',
158
+ 'posts_per_page' => -1,
159
+ 'date_query' => array(
160
+ 'before' => $before_datetime->format( 'c' ),
161
+ 'after' => $after_datetime->format( 'c' ),
162
+ 'column' => 'post_date_gmt'
163
+ )
164
+ );
165
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
166
+ $query = new rtbQuery( $args );
167
+
168
+ $query->prepare_args();
169
+
170
+ return $query->get_bookings();
171
+ }
172
+
173
+ /**
174
+ * Gets the bookings that might need reminders sent to them
175
+ *
176
+ * @since 2.0.0
177
+ */
178
+ public function get_reminder_posts() {
179
+ global $rtb_controller;
180
+
181
+ $reminder_time = $rtb_controller->settings->get_setting( 'time-reminder-user' );
182
+ $count = substr( $reminder_time, 0, strpos( $reminder_time, "_" ) );
183
+ $unit = substr( $reminder_time, strpos( $reminder_time, "_" ) + 1 );
184
+
185
+ $time_interval = $this->get_time_interval( $count, $unit );
186
+
187
+ $after_datetime = new DateTime( '@' . ( time() - max( $time_interval, 6*3600 ) ) );
188
+ $before_datetime = new DateTime( '@' . ( time() + $time_interval ) );
189
+
190
+ $args = array(
191
+ 'post_status' => 'confirmed,',
192
+ 'post_count' => -1,
193
+ 'date_query' => array(
194
+ 'before' => $before_datetime->format( 'c' ),
195
+ 'after' => $after_datetime->format( 'c' ),
196
+ 'column' => 'post_date_gmt'
197
+ )
198
+ );
199
+
200
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
201
+ $query = new rtbQuery( $args );
202
+
203
+ $query->prepare_args();
204
+
205
+ return $query->get_bookings();
206
+ }
207
+
208
+ /**
209
+ * Converts a time unit and interval into its value in seconds
210
+ *
211
+ * @since 2.0.0
212
+ */
213
+ public function get_time_interval( $count, $unit ) {
214
+ switch ($unit) {
215
+ case 'days':
216
+ $multiplier = 24*3600;
217
+ break;
218
+ case 'hours':
219
+ $multiplier = 3600;
220
+ break;
221
+ case 'minutes':
222
+ $multiplier = 60;
223
+ break;
224
+
225
+ default:
226
+ $multiplier = 1;
227
+ break;
228
+ }
229
+
230
+ return $count * $multiplier;
231
+ }
232
+
233
+ }
234
+ } // endif;
includes/CustomFields.class.php ADDED
@@ -0,0 +1,192 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * A class that handles the main custom field functions
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) )
6
+ exit;
7
+
8
+ if ( !class_exists( 'rtbCustomFields' ) ) {
9
+ class rtbCustomFields {
10
+
11
+ /**
12
+ * Option name for storing modified default fields
13
+ *
14
+ * @since 0.1
15
+ */
16
+ public $modified_option_key;
17
+
18
+ /**
19
+ * Common string tacked onto the end of error messages
20
+ *
21
+ * @since 0.1
22
+ */
23
+ public $common_error_msg;
24
+
25
+ /**
26
+ * Initialize the plugin and register hooks
27
+ *
28
+ * @since 0.1
29
+ */
30
+ public function __construct() {
31
+
32
+ // Option key where information about default fields that have
33
+ // been modified and disabled is stored in the database
34
+ $this->modified_option_key = apply_filters( 'cffrtb_modified_fields_option_key', 'cffrtb_modified_fields' );
35
+
36
+ // Common string tacked onto the end of error messages
37
+ $this->common_error_msg = sprintf( _x( 'Please try again. If the problem persists, you may need to refresh the page. If that does not solve the problem, please %scontact support%s for help.', 'A common phrase added to the end of error messages', 'custom-fields-for-rtb' ), '<a href="http://fivestarplugins.com/contact-us/">', '</a>' );
38
+
39
+ // Validate user input for custom fields
40
+ add_action( 'rtb_validate_booking_submission', array( $this, 'validate_custom_fields_input' ) );
41
+
42
+ // Filter required phone setting when phone field is disabled
43
+ add_filter( 'rtb-setting-require-phone', array( $this, 'never_require_phone' ) );
44
+
45
+ // Insert/load custom field input with booking metadata
46
+ add_filter( 'rtb_insert_booking_metadata', array( $this, 'insert_booking_metadata' ), 10, 2 );
47
+ add_action( 'rtb_booking_load_post_data', array( $this, 'load_booking_meta_data' ), 10, 2 );
48
+
49
+ // Print custom fields in notification template tags
50
+ add_filter( 'rtb_notification_template_tags', array( $this, 'add_notification_template_tags' ), 10, 2 );
51
+ add_filter( 'rtb_notification_template_tag_descriptions', array( $this, 'add_notification_template_tag_descriptions' ) );
52
+
53
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
54
+ }
55
+
56
+ public function enqueue_scripts() {
57
+ $currentScreen = get_current_screen();
58
+ if ( $currentScreen->id == 'bookings_page_cffrtb-editor' ) {
59
+ wp_enqueue_style( 'rtb-admin', RTB_PLUGIN_URL . '/assets/css/admin.css', array(), '2.0.0' );
60
+ wp_enqueue_script( 'rtb-admin-js', RTB_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), '2.0.0', true );
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Validate user input for custom fields
66
+ *
67
+ * @since 0.1
68
+ */
69
+ public function validate_custom_fields_input( $booking ) {
70
+
71
+ $fields = rtb_get_custom_fields();
72
+
73
+ if ( !count( $fields ) ) {
74
+ return;
75
+ }
76
+
77
+ foreach( $fields as $field ) {
78
+ $validation = $field->validate_input( $booking );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Add custom fields to metadata when a booking is saved
84
+ *
85
+ * @since 0.1
86
+ */
87
+ public function insert_booking_metadata( $meta, $booking ) {
88
+
89
+ if ( empty( $booking->custom_fields ) ) {
90
+ return $meta;
91
+ }
92
+
93
+ if ( !is_array( $meta ) ) {
94
+ $meta = array();
95
+ }
96
+
97
+ if ( !isset( $meta['custom_fields'] ) ) {
98
+ $meta['custom_fields'] = array();
99
+ }
100
+
101
+ $meta['custom_fields'] = $booking->custom_fields;
102
+
103
+ return $meta;
104
+ }
105
+
106
+ /**
107
+ * Add custom fields to metadata when booking is loaded
108
+ *
109
+ * @since 0.1
110
+ */
111
+ public function load_booking_meta_data( $booking, $post ) {
112
+
113
+ $meta = get_post_meta( $booking->ID, 'rtb', true );
114
+
115
+ if ( empty( $meta['custom_fields'] ) ) {
116
+ return;
117
+ }
118
+
119
+ $booking->custom_fields = $meta['custom_fields'];
120
+ }
121
+
122
+ /**
123
+ * Add custom fields as notification template tags
124
+ *
125
+ * @since 0.1
126
+ */
127
+ public function add_notification_template_tags( $tags, $notification ) {
128
+
129
+ $fields = rtb_get_custom_fields();
130
+
131
+ $cf = isset( $notification->booking->custom_fields ) ? $notification->booking->custom_fields : array();
132
+ $checkbox_icon = apply_filters( 'cffrtb_checkbox_icon_notification', '', $notification );
133
+
134
+ foreach( $fields as $field ) {
135
+
136
+ if ( $field->type == 'fieldset' ) {
137
+ continue;
138
+ }
139
+
140
+ if ( isset( $cf[ $field->slug ] ) ) {
141
+ $display_val = apply_filters( 'cffrtb_display_value_notification', $this->fields->get_display_value( $cf[ $field->slug ], $field, $checkbox_icon ), $cf[ $field->slug ], $field, $notification );
142
+ } else {
143
+ $display_val = '';
144
+ }
145
+ $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = $display_val;
146
+ }
147
+
148
+ return $tags;
149
+ }
150
+
151
+ /**
152
+ * Add custom field notification template tag descriptions
153
+ *
154
+ * @since 0.1
155
+ */
156
+ public function add_notification_template_tag_descriptions( $tags ) {
157
+
158
+ $fields = rtb_get_custom_fields();
159
+
160
+ foreach( $fields as $field ) {
161
+
162
+ if ( $field->type == 'fieldset' ) {
163
+ continue;
164
+ }
165
+
166
+ $tags[ '{cf-' . esc_attr( $field->slug ) . '}' ] = esc_html( $field->title );
167
+ }
168
+
169
+ return $tags;
170
+ }
171
+
172
+ /**
173
+ * Override the required phone setting when the phone field has been
174
+ * disabled.
175
+ *
176
+ * @param string $value The value of the setting
177
+ * @since 1.2.3
178
+ */
179
+ public function never_require_phone( $value ) {
180
+ global $rtb_controller;
181
+
182
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
183
+
184
+ if ( $modified && isset( $modified['phone'] ) && !empty( $modified['phone']['disabled'] ) ) {
185
+ return '';
186
+ }
187
+
188
+ return $value;
189
+ }
190
+
191
+ }
192
+ } // endif;
includes/CustomPostTypes.class.php CHANGED
@@ -23,6 +23,7 @@ class rtbCustomPostTypes {
23
 
24
  // Set up $booking_statuses array and register new post statuses
25
  add_action( 'init', array( $this, 'set_booking_statuses' ) );
 
26
 
27
  // Display the count of pending bookings
28
  add_action( 'admin_footer', array( $this, 'show_pending_count' ) );
@@ -39,6 +40,7 @@ class rtbCustomPostTypes {
39
  * @since 0.1
40
  */
41
  public function load_cpts() {
 
42
 
43
  // Define the booking custom post type
44
  $args = array(
@@ -77,7 +79,31 @@ class rtbCustomPostTypes {
77
  // Add an action so addons can hook in after the post type is registered
78
  do_action( 'rtb_booking_post_register' );
79
 
80
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  }
82
 
83
  /**
@@ -126,6 +152,30 @@ class rtbCustomPostTypes {
126
 
127
  }
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  /**
130
  * Print an HTML element to select a booking status
131
  * @since 0.0.1
23
 
24
  // Set up $booking_statuses array and register new post statuses
25
  add_action( 'init', array( $this, 'set_booking_statuses' ) );
26
+ add_filter( 'rtb_post_statuses_args' , array( $this, 'add_arrived_status' ) );
27
 
28
  // Display the count of pending bookings
29
  add_action( 'admin_footer', array( $this, 'show_pending_count' ) );
40
  * @since 0.1
41
  */
42
  public function load_cpts() {
43
+ global $rtb_controller;
44
 
45
  // Define the booking custom post type
46
  $args = array(
79
  // Add an action so addons can hook in after the post type is registered
80
  do_action( 'rtb_booking_post_register' );
81
 
82
+ if ( $rtb_controller->permissions->check_permission( 'custom_fields' ) ) {
83
+ // Define the field custom post type
84
+ $args = array(
85
+ 'labels' => array(
86
+ 'name' => __( 'Field', 'custom-fields-for-rtb' ),
87
+ 'singular_name' => __( 'Field', 'custom-fields-for-rtb' ),
88
+ 'menu_name' => __( 'Fields', 'custom-fields-for-rtb' ),
89
+ 'name_admin_bar' => __( 'Fields', 'custom-fields-for-rtb' ),
90
+ 'add_new' => __( 'Add Field', 'custom-fields-for-rtb' ),
91
+ 'add_new_item' => __( 'Add New Field', 'custom-fields-for-rtb' ),
92
+ 'edit_item' => __( 'Edit Field', 'custom-fields-for-rtb' ),
93
+ 'new_item' => __( 'New Field', 'custom-fields-for-rtb' ),
94
+ 'view_item' => __( 'View Field', 'custom-fields-for-rtb' ),
95
+ 'search_items' => __( 'Search Fields', 'custom-fields-for-rtb' ),
96
+ 'not_found' => __( 'No fields found', 'custom-fields-for-rtb' ),
97
+ 'not_found_in_trash' => __( 'No fields found in trash', 'custom-fields-for-rtb' ),
98
+ 'all_items' => __( 'All Fields', 'custom-fields-for-rtb' ),
99
+ ),
100
+ 'public' => false
101
+ );
102
+
103
+ $args = apply_filters( 'cffrtb_field_post_type_args', $args );
104
+
105
+ register_post_type( 'cffrtb_field', $args );
106
+ }
107
  }
108
 
109
  /**
152
 
153
  }
154
 
155
+ /**
156
+ * @since 2.0.0
157
+ * Adds in an "Arrived" status if the option to check guests in on arrival
158
+ * has been toggled on.
159
+ */
160
+ public function add_arrived_status( $booking_statuses = array() ) {
161
+ global $rtb_controller;
162
+
163
+ if ( $rtb_controller->settings->get_setting( 'view-bookings-arrivals' ) ) {
164
+ $booking_statuses['arrived'] = array(
165
+ 'label' => _x( 'Arrived', 'The guests have arrived for their reservation', 'restaurant-reservations' ),
166
+ 'default' => false, // Whether or not this status is part of WP Core
167
+ 'user_selectable' => true, // Whether or not a user can set a booking to this status
168
+ 'public' => false,
169
+ 'exclude_from_search' => true,
170
+ 'show_in_admin_all_list' => true,
171
+ 'show_in_admin_status_list' => true,
172
+ 'label_count' => _n_noop( 'Arrived <span class="count">(%s)</span>', 'Arrived <span class="count">(%s)</span>', 'restaurant-reservations' )
173
+ );
174
+ }
175
+
176
+ return $booking_statuses;
177
+ }
178
+
179
  /**
180
  * Print an HTML element to select a booking status
181
  * @since 0.0.1
includes/Dashboard.class.php ADDED
@@ -0,0 +1,415 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbDashboard' ) ) {
5
+ /**
6
+ * Class to handle plugin dashboard
7
+ *
8
+ * @since 2.0.0
9
+ */
10
+ class rtbDashboard {
11
+
12
+ public $message;
13
+ public $status = true;
14
+
15
+ public function __construct() {
16
+ add_action( 'admin_menu', array( $this, 'add_dashboard_to_menu' ), 99 );
17
+ if ( isset($_POST['RTB_Upgrade_To_Full']) ) { add_action( 'init', array( $this, 'check_upgrade_code' ) ); }
18
+ if ( get_option( 'RTB_Trial_Happening' ) == 'Yes' ) {
19
+ add_action('admin_init', array( $this, 'check_trial_status' ) );
20
+ }
21
+
22
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
23
+ }
24
+
25
+ public function add_dashboard_to_menu() {
26
+ global $menu, $submenu;
27
+
28
+ add_submenu_page(
29
+ 'rtb-bookings',
30
+ 'Dashboard',
31
+ 'Dashboard',
32
+ 'manage_options',
33
+ 'rtb-dashboard',
34
+ array($this, 'display_dashboard_screen')
35
+ );
36
+
37
+ // Create a new sub-menu in the order that we want
38
+ $new_submenu = array();
39
+ $menu_item_count = 3;
40
+ foreach ( $submenu['rtb-bookings'] as $key => $sub_item ) {
41
+ if ( $sub_item[0] == 'Dashboard' ) { $new_submenu[0] = $sub_item; }
42
+ elseif ( $sub_item[0] == 'Bookings' ) { $new_submenu[1] = $sub_item; }
43
+ elseif ( $sub_item[0] == 'Settings' ) { $new_submenu[2] = $sub_item; }
44
+ else {
45
+ $new_submenu[$menu_item_count] = $sub_item;
46
+ $menu_item_count++;
47
+ }
48
+ }
49
+ ksort($new_submenu);
50
+
51
+ $submenu['rtb-bookings'] = $new_submenu;
52
+
53
+ if ( isset( $dashboard_key ) ) {
54
+ $submenu['rtb-bookings'][0] = $submenu['rtb-bookings'][$dashboard_key];
55
+ unset($submenu['rtb-bookings'][$dashboard_key]);
56
+ }
57
+ }
58
+
59
+ // Enqueues the admin script so that our hacky sub-menu opening function can run
60
+ public function enqueue_scripts() {
61
+ $currentScreen = get_current_screen();
62
+ if ( $currentScreen->id == 'bookings_page_rtb-dashboard' ) {
63
+ wp_enqueue_style( 'rtb-admin', RTB_PLUGIN_URL . '/assets/css/admin.css', array(), '2.0.0' );
64
+ wp_enqueue_script( 'rtb-admin-js', RTB_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), '2.0.0', true );
65
+ }
66
+ }
67
+
68
+ public function check_upgrade_code() {
69
+ global $rtb_controller;
70
+
71
+ $key = trim($_POST['Key']);
72
+
73
+ if ($key == "FSP Trial" and !get_option("RTB_Trial_Happening")) {
74
+ $this->message = __("Trial successfully started!", 'restaurant-reservations');
75
+
76
+ update_option("RTB_Trial_Expiry_Time", time() + (7*24*60*60));
77
+ update_option("RTB_Trial_Happening", "Yes");
78
+
79
+ update_option( "rtb-pre-permission-level", get_option( 'rtb-permission-level' ) );
80
+ update_option( "rtb-permission-level", 2 );
81
+ $rtb_controller->permissions->update_permissions();
82
+
83
+ $Admin_Email = get_option('admin_email');
84
+
85
+ $opts = array('http'=>array('method'=>"GET"));
86
+ $context = stream_context_create($opts);
87
+ $Response = file_get_contents("http://www.fivestarplugins.com/key-check/Register_Trial.php?Plugin=RTB&Admin_Email=" . $Admin_Email . "&Site=" . get_bloginfo('wpurl'), false, $context);
88
+ }
89
+ elseif ($key == "FSP Trial") {
90
+ $this->status = false;
91
+ $this->message = __('Trial has already been used.', 'restaurant-reservations');
92
+ }
93
+ elseif (strlen($key) < 18 or strlen($key) > 22) {
94
+ $this->status = false;
95
+ $this->message = __('Invalid License Key', 'restaurant-reservations');
96
+ }
97
+ elseif ($key != "FSP Trial") {
98
+ $opts = array('http'=>array('method'=>"GET"));
99
+ $context = stream_context_create($opts);
100
+ $Response = unserialize(file_get_contents("http://www.fivestarplugins.com/key-check/FSP_RTB_KeyCheck.php?Key=" . $key . "&Site=" . get_bloginfo('wpurl'), false, $context));
101
+
102
+ if ($Response['Message_Type'] == "Error") {
103
+ $this->status = false;
104
+ $this->message = $Response['Message'];
105
+ }
106
+ else {
107
+ $this->message = $Response['Message'];
108
+ update_option("RTB_Trial_Happening", "No");
109
+ delete_option("RTB_Trial_Expiry_Time");
110
+
111
+ update_option( "rtb-permission-level", 2 );
112
+ $rtb_controller->permissions->update_permissions();
113
+ }
114
+ }
115
+
116
+ add_action( 'admin_notices', array( $this, 'display_notice' ) );
117
+ }
118
+
119
+ public function check_trial_status() {
120
+ global $rtb_controller;
121
+
122
+ if ( get_option("RTB_Trial_Happening") == "Yes" and get_option( 'RTB_Trial_Expiry_Time' ) < time() ) {
123
+ update_option( 'RTB_Trial_Happening', 'No');
124
+ update_option( 'rtb-permission-level', get_option( 'rtb-pre-permission-level' ) );
125
+
126
+ $rtb_controller->permissions->update_permissions();
127
+ }
128
+ }
129
+
130
+ public function display_dashboard_screen() {
131
+ global $rtb_controller;
132
+
133
+ $permission = $rtb_controller->permissions->check_permission( 'styling' );
134
+
135
+ ?>
136
+ <div id="rtb-dashboard-content-area">
137
+
138
+ <div id="rtb-dashboard-content-left">
139
+
140
+ <?php if ( ! $permission or get_option("RTB_Trial_Happening") == "Yes") { ?>
141
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-full">
142
+ <div class="rtb-dashboard-new-widget-box-top">
143
+ <form method="post" action="admin.php?page=rtb-dashboard" class="rtb-dashboard-key-widget">
144
+ <input class="rtb-dashboard-key-widget-input" name="Key" type="text" placeholder="<?php _e('Enter License Key Here', 'restaurant-reservations'); ?>">
145
+ <input class="rtb-dashboard-key-widget-submit" name="RTB_Upgrade_To_Full" type="submit" value="<?php _e('UNLOCK PREMIUM', 'restaurant-reservations'); ?>">
146
+ <div class="rtb-dashboard-key-widget-text">Don't have a key? <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">Upgrade Now</a> to unlock all premium features.</div>
147
+ </form>
148
+ </div>
149
+ </div>
150
+ <?php } ?>
151
+
152
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-full" id="rtb-dashboard-support-widget-box">
153
+ <div class="rtb-dashboard-new-widget-box-top">Get Support<span id="rtb-dash-mobile-support-down-caret">&nbsp;&nbsp;&#9660;</span><span id="rtb-dash-mobile-support-up-caret">&nbsp;&nbsp;&#9650;</span></div>
154
+ <div class="rtb-dashboard-new-widget-box-bottom">
155
+ <ul class="rtb-dashboard-support-widgets">
156
+ <li>
157
+ <a href="https://www.youtube.com/channel/UCZPuaoetCJB1vZOmpnMxJNw/featured" target="_blank">
158
+ <img src="<?php echo plugins_url( '../assets/img/ewd-support-icon-youtube.png', __FILE__ ); ?>">
159
+ <div class="rtb-dashboard-support-widgets-text">YouTube Tutorials</div>
160
+ </a>
161
+ </li>
162
+ <li>
163
+ <a href="https://wordpress.org/plugins/restaurant-reservations/#faq" target="_blank">
164
+ <img src="<?php echo plugins_url( '../assets/img/ewd-support-icon-faqs.png', __FILE__ ); ?>">
165
+ <div class="rtb-dashboard-support-widgets-text">Plugin FAQs</div>
166
+ </a>
167
+ </li>
168
+ <li>
169
+ <a href="https://wordpress.org/support/plugin/restaurant-reservations" target="_blank">
170
+ <img src="<?php echo plugins_url( '../assets/img/ewd-support-icon-forum.png', __FILE__ ); ?>">
171
+ <div class="rtb-dashboard-support-widgets-text">Support Forum</div>
172
+ </a>
173
+ </li>
174
+ <li>
175
+ <a href="https://www.fivestarplugins.com/support-center/?Plugin=RTB" target="_blank">
176
+ <img src="<?php echo plugins_url( '../assets/img/ewd-support-icon-documentation.png', __FILE__ ); ?>">
177
+ <div class="rtb-dashboard-support-widgets-text">Documentation</div>
178
+ </a>
179
+ </li>
180
+ </ul>
181
+ </div>
182
+ </div>
183
+
184
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-full" id="rtb-dashboard-optional-table">
185
+ <div class="rtb-dashboard-new-widget-box-top">Bookings Summary<span id="rtb-dash-optional-table-down-caret">&nbsp;&nbsp;&#9660;</span><span id="rtb-dash-optional-table-up-caret">&nbsp;&nbsp;&#9650;</span></div>
186
+ <div class="rtb-dashboard-new-widget-box-bottom">
187
+ <table class='rtb-overview-table wp-list-table widefat fixed striped posts'>
188
+ <thead>
189
+ <tr>
190
+ <th><?php _e("Date", 'restaurant-reservations'); ?></th>
191
+ <th><?php _e("Party", 'restaurant-reservations'); ?></th>
192
+ <th><?php _e("Name", 'restaurant-reservations'); ?></th>
193
+ <th><?php _e("Status", 'restaurant-reservations'); ?></th>
194
+ </tr>
195
+ </thead>
196
+ <tbody>
197
+ <?php
198
+ require_once( RTB_PLUGIN_DIR . '/includes/Query.class.php' );
199
+ $query = new rtbQuery( array() );
200
+ $query->prepare_args();
201
+
202
+ $bookings = $query->get_bookings();
203
+
204
+ if (sizeOf($bookings) == 0) {echo "<tr><td colspan='4'>" . __("No bookings to display yet. Create a booking for it to be displayed here.", 'restaurant-reservations') . "</td></tr>";}
205
+ else {
206
+ foreach ($bookings as $booking) {
207
+ ?>
208
+
209
+ <tr>
210
+ <td><?php echo $booking->date; ?></td>
211
+ <td><?php echo $booking->party; ?></td>
212
+ <td><?php echo $booking->name; ?></td>
213
+ <td><?php echo $booking->post_status; ?></td>
214
+ </tr>
215
+ <?php }
216
+ }
217
+ ?>
218
+ </tbody>
219
+ </table>
220
+ </div>
221
+ </div>
222
+
223
+ <?php /*<div class="rtb-dashboard-new-widget-box <?php echo ( ($hideReview != 'Yes' and $Ask_Review_Date < time()) ? 'ewd-widget-box-two-thirds' : 'ewd-widget-box-full' ); ?>">
224
+ <div class="rtb-dashboard-new-widget-box-top">What People Are Saying</div>
225
+ <div class="rtb-dashboard-new-widget-box-bottom">
226
+ <ul class="rtb-dashboard-testimonials">
227
+ <?php $randomTestimonial = rand(0,2);
228
+ if($randomTestimonial == 0){ ?>
229
+ <li id="rtb-dashboard-testimonial-one">
230
+ <img src="<?php echo plugins_url( '../assets/img/dash-asset-stars.png', __FILE__ ); ?>">
231
+ <div class="rtb-dashboard-testimonial-title">"Awesome. Just Awesome."</div>
232
+ <div class="rtb-dashboard-testimonial-author">- @shizart</div>
233
+ <div class="rtb-dashboard-testimonial-text">Thanks for this very well-made plugin. This works so well out of the box, I barely had to do ANYTHING to create an amazing FAQ accordion display... <a href="https://wordpress.org/support/topic/awesome-just-awesome-11/" target="_blank">read more</a></div>
234
+ </li>
235
+ <?php }
236
+ if($randomTestimonial == 1){ ?>
237
+ <li id="rtb-dashboard-testimonial-two">
238
+ <img src="<?php echo plugins_url( '../assets/img/dash-asset-stars.png', __FILE__ ); ?>">
239
+ <div class="rtb-dashboard-testimonial-title">"Absolutely perfect with great support"</div>
240
+ <div class="rtb-dashboard-testimonial-author">- @isaac85</div>
241
+ <div class="rtb-dashboard-testimonial-text">I tried several different FAQ plugins and this is by far the prettiest and easiest to use... <a href="https://wordpress.org/support/topic/absolutely-perfect-with-great-support/" target="_blank">read more</a></div>
242
+ </li>
243
+ <?php }
244
+ if($randomTestimonial == 2){ ?>
245
+ <li id="rtb-dashboard-testimonial-three">
246
+ <img src="<?php echo plugins_url( '../assets/img/dash-asset-stars.png', __FILE__ ); ?>">
247
+ <div class="rtb-dashboard-testimonial-title">"Perfect FAQ Plugin"</div>
248
+ <div class="rtb-dashboard-testimonial-author">- @muti-wp</div>
249
+ <div class="rtb-dashboard-testimonial-text">Works great! Easy to configure and to use. Thanks! <a href="https://wordpress.org/support/topic/perfect-faq-plugin/" target="_blank">read more</a></div>
250
+ </li>
251
+ <?php } ?>
252
+ </ul>
253
+ </div>
254
+ </div> */ ?>
255
+
256
+ <?php /* if($hideReview != 'Yes' and $Ask_Review_Date < time()){ ?>
257
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-one-third">
258
+ <div class="rtb-dashboard-new-widget-box-top">Leave a review</div>
259
+ <div class="rtb-dashboard-new-widget-box-bottom">
260
+ <div class="rtb-dashboard-review-ask">
261
+ <img src="<?php echo plugins_url( '../assets/img/dash-asset-stars.png', __FILE__ ); ?>">
262
+ <div class="rtb-dashboard-review-ask-text">If you enjoy this plugin and have a minute, please consider leaving a 5-star review. Thank you!</div>
263
+ <a href="https://wordpress.org/plugins/ultimate-faqs/#reviews" class="rtb-dashboard-review-ask-button">LEAVE A REVIEW</a>
264
+ <form action="admin.php?page=EWD-UFAQ-Options" method="post">
265
+ <input type="hidden" name="hide_ufaq_review_box_hidden" value="Yes">
266
+ <input type="submit" name="hide_ufaq_review_box_submit" class="rtb-dashboard-review-ask-dismiss" value="I've already left a review">
267
+ </form>
268
+ </div>
269
+ </div>
270
+ </div>
271
+ <?php } */ ?>
272
+
273
+ <?php if ( ! $permission or get_option("RTB_Trial_Happening") == "Yes" ) { ?>
274
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-full" id="rtb-dashboard-guarantee-widget-box">
275
+ <div class="rtb-dashboard-new-widget-box-top">
276
+ <div class="rtb-dashboard-guarantee">
277
+ <div class="rtb-dashboard-guarantee-title">14-Day 100% Money-Back Guarantee</div>
278
+ <div class="rtb-dashboard-guarantee-text">If you're not 100% satisfied with the premium version of our plugin - no problem. You have 14 days to receive a FULL REFUND. We're certain you won't need it, though.</div>
279
+ </div>
280
+ </div>
281
+ </div>
282
+ <?php } ?>
283
+
284
+ </div> <!-- left -->
285
+
286
+ <div id="rtb-dashboard-content-right">
287
+
288
+ <?php if ( ! $permission or get_option("RTB_Trial_Happening") == "Yes" ) { ?>
289
+ <div class="rtb-dashboard-new-widget-box ewd-widget-box-full" id="rtb-dashboard-get-premium-widget-box">
290
+ <div class="rtb-dashboard-new-widget-box-top">Get Premium</div>
291
+ <?php if(get_option("RTB_Trial_Happening") == "Yes"){
292
+ $trialExpireTime = get_option("RTB_Trial_Expiry_Time");
293
+ $currentTime = time();
294
+ $trialTimeLeft = $trialExpireTime - $currentTime;
295
+ $trialTimeLeftDays = ( date("d", $trialTimeLeft) ) - 1;
296
+ $trialTimeLeftHours = date("H", $trialTimeLeft);
297
+ ?>
298
+ <div class="rtb-dashboard-new-widget-box-bottom">
299
+ <div class="rtb-dashboard-get-premium-widget-trial-time">
300
+ <div class="rtb-dashboard-get-premium-widget-trial-days"><?php echo $trialTimeLeftDays; ?><span>days</span></div>
301
+ <div class="rtb-dashboard-get-premium-widget-trial-hours"><?php echo $trialTimeLeftHours; ?><span>hours</span></div>
302
+ </div>
303
+ <div class="rtb-dashboard-get-premium-widget-trial-time-left">LEFT IN TRIAL</div>
304
+ </div>
305
+ <?php } ?>
306
+ <div class="rtb-dashboard-new-widget-box-bottom">
307
+ <div class="rtb-dashboard-get-premium-widget-features-title"<?php echo ( get_option("RTB_Trial_Happening") == "Yes" ? "style='padding-top: 20px;'" : ""); ?>>GET FULL ACCESS WITH OUR PREMIUM VERSION AND GET:</div>
308
+ <ul class="rtb-dashboard-get-premium-widget-features">
309
+ <li>Multiple Layouts</li>
310
+ <li>Custom Fields</li>
311
+ <li>MailChimp Integration</li>
312
+ <li>Advanced Styling Options</li>
313
+ <li>+ More</li>
314
+ </ul>
315
+ <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" class="rtb-dashboard-get-premium-widget-button" target="_blank">UPGRADE NOW</a>
316
+ <?php if (!get_option("RTB_Trial_Happening")) { ?>
317
+ <form method="post" action="admin.php?page=rtb-dashboard">
318
+ <input name="Key" type="hidden" value='FSP Trial'>
319
+ <input name="RTB_Upgrade_To_Full" type="hidden" value='RTB_Upgrade_To_Full'>
320
+ <button class="rtb-dashboard-get-premium-widget-button rtb-dashboard-new-trial-button">GET FREE 7-DAY TRIAL</button>
321
+ </form>
322
+ <?php } ?>
323
+ </div>
324
+ </div>
325
+ <?php } ?>
326
+
327
+ <!-- <div class="rtb-dashboard-new-widget-box ewd-widget-box-full">
328
+ <div class="rtb-dashboard-new-widget-box-top">Other Plugins by Etoile</div>
329
+ <div class="rtb-dashboard-new-widget-box-bottom">
330
+ <ul class="rtb-dashboard-other-plugins">
331
+ <li>
332
+ <a href="https://wordpress.org/plugins/ultimate-product-catalogue/" target="_blank"><img src="<?php echo plugins_url( '../images/ewd-upcp-icon.png', __FILE__ ); ?>"></a>
333
+ <div class="rtb-dashboard-other-plugins-text">
334
+ <div class="rtb-dashboard-other-plugins-title">Product Catalog</div>
335
+ <div class="rtb-dashboard-other-plugins-blurb">Enables you to display your business's products in a clean and efficient manner.</div>
336
+ </div>
337
+ </li>
338
+ <li>
339
+ <a href="https://wordpress.org/plugins/ultimate-reviews/" target="_blank"><img src="<?php echo plugins_url( '../images/ewd-urp-icon.png', __FILE__ ); ?>"></a>
340
+ <div class="rtb-dashboard-other-plugins-text">
341
+ <div class="rtb-dashboard-other-plugins-title">Ultimate Reviews</div>
342
+ <div class="rtb-dashboard-other-plugins-blurb">Let visitors submit reviews and display them right in the tabbed page layout!</div>
343
+ </div>
344
+ </li>
345
+ </ul>
346
+ </div>
347
+ </div> -->
348
+
349
+ </div> <!-- right -->
350
+
351
+ </div> <!-- rtb-dashboard-content-area -->
352
+
353
+ <?php if ( ! $permission or get_option("RTB_Trial_Happening") == "Yes" ) { ?>
354
+ <div id="rtb-dashboard-new-footer-one">
355
+ <div class="rtb-dashboard-new-footer-one-inside">
356
+ <div class="rtb-dashboard-new-footer-one-left">
357
+ <div class="rtb-dashboard-new-footer-one-title">What's Included in Our Premium Version?</div>
358
+ <ul class="rtb-dashboard-new-footer-one-benefits">
359
+ <li>Multiple Form Layouts</li>
360
+ <li>Custom Form Fields</li>
361
+ <li>Advanced Email Designer</li>
362
+ <li>MailChimp Integration</li>
363
+ <li>Set Table and Seat Restrictions</li>
364
+ <li>Automatic Booking Confirmation</li>
365
+ <li>Bookings Page for Staff</li>
366
+ <li>Export Bookings</li>
367
+ <li>Advanced Styling Options</li>
368
+ </ul>
369
+ </div>
370
+ <div class="rtb-dashboard-new-footer-one-buttons">
371
+ <a class="rtb-dashboard-new-upgrade-button" href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">UPGRADE NOW</a>
372
+ </div>
373
+ </div>
374
+ </div> <!-- rtb-dashboard-new-footer-one -->
375
+ <?php } ?>
376
+ <div id="rtb-dashboard-new-footer-two">
377
+ <div class="rtb-dashboard-new-footer-two-inside">
378
+ <img src="<?php echo plugins_url( '../assets/img/fivestartextlogowithstar.png', __FILE__ ); ?>" class="rtb-dashboard-new-footer-two-icon">
379
+ <div class="rtb-dashboard-new-footer-two-blurb">
380
+ At Five Star Plugins, we build powerful, easy-to-use WordPress plugins with a focus on the restaurant, hospitality and business industries. With a modern, responsive look and a highly-customizable feature set, Five Star Plugins can be used as out-of-the-box solutions and can also be adapted to your specific requirements.
381
+ </div>
382
+ <ul class="rtb-dashboard-new-footer-two-menu">
383
+ <li>SOCIAL</li>
384
+ <li><a href="https://www.facebook.com/EtoileWebDesign/" target="_blank">Facebook</a></li>
385
+ <li><a href="https://twitter.com/EtoileWebDesign" target="_blank">Twitter</a></li>
386
+ <li><a href="https://www.fivestarplugins.com/blog/" target="_blank">Blog</a></li>
387
+ </ul>
388
+ <ul class="rtb-dashboard-new-footer-two-menu">
389
+ <li>SUPPORT</li>
390
+ <li><a href="https://www.youtube.com/channel/UCZPuaoetCJB1vZOmpnMxJNw/featured" target="_blank">YouTube Tutorials</a></li>
391
+ <li><a href="https://wordpress.org/support/plugin/restaurant-reservations" target="_blank">Forums</a></li>
392
+ <li><a href="https://www.fivestarplugins.com/support-center/?Plugin=RTB" target="_blank">Documentation</a></li>
393
+ <li><a href="https://wordpress.org/plugins/restaurant-reservations/#faq" target="_blank">FAQs</a></li>
394
+ </ul>
395
+ </div>
396
+ </div> <!-- rtb-dashboard-new-footer-two -->
397
+
398
+ <?php }
399
+
400
+ public function get_term_from_array($terms, $term_id) {
401
+ foreach ($terms as $term) {if ($term->term_id == $term_id) {return $term;}}
402
+
403
+ return array();
404
+ }
405
+
406
+ public function display_notice() {
407
+ if ( $this->status ) {
408
+ echo "<div class='updated'><p>" . $this->message . "</p></div>";
409
+ }
410
+ else {
411
+ echo "<div class='error'><p>" . $this->message . "</p></div>";
412
+ }
413
+ }
414
+ }
415
+ } // endif
includes/Editor.class.php ADDED
@@ -0,0 +1,845 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'cffrtbEditor' ) ) {
5
+ /**
6
+ * Class which builds the form editor for Custom Fields for Restaurant
7
+ * Reservations
8
+ *
9
+ * @since 0.1
10
+ */
11
+ class cffrtbEditor {
12
+
13
+ /**
14
+ * Hook suffix for the page
15
+ *
16
+ * @since 0.1
17
+ */
18
+ public $hook_suffix;
19
+
20
+ public function __construct() {
21
+
22
+ // Add the admin menu
23
+ add_action( 'admin_menu', array( $this, 'add_menu_page' ), 20 );
24
+
25
+ // Handle ajax requests
26
+ add_action( 'wp_ajax_nopriv_cffrtb-save-field' , array( $this , 'ajax_nopriv' ) );
27
+ add_action( 'wp_ajax_cffrtb-save-field', array( $this, 'ajax_save_field' ) );
28
+ add_action( 'wp_ajax_nopriv_cffrtb-save-order' , array( $this , 'ajax_nopriv' ) );
29
+ add_action( 'wp_ajax_cffrtb-save-order', array( $this, 'ajax_save_order' ) );
30
+ add_action( 'wp_ajax_nopriv_cffrtb-load-field' , array( $this , 'ajax_nopriv' ) );
31
+ add_action( 'wp_ajax_cffrtb-load-field', array( $this, 'ajax_load_field' ) );
32
+ add_action( 'wp_ajax_nopriv_cffrtb-delete-field' , array( $this , 'ajax_nopriv' ) );
33
+ add_action( 'wp_ajax_cffrtb-delete-field', array( $this, 'ajax_delete_field' ) );
34
+ add_action( 'wp_ajax_nopriv_cffrtb-enable-field' , array( $this , 'ajax_nopriv' ) );
35
+ add_action( 'wp_ajax_cffrtb-enable-field', array( $this, 'ajax_enable_field' ) );
36
+ add_action( 'wp_ajax_nopriv_cffrtb-reset-all' , array( $this , 'ajax_nopriv' ) );
37
+ add_action( 'wp_ajax_cffrtb-reset-all', array( $this, 'ajax_reset_all' ) );
38
+
39
+ // Load "pointers" (help tooltips on initial load)
40
+ require_once( RTB_PLUGIN_DIR . '/includes/custom_fields_pointers.php' );
41
+ }
42
+
43
+ /**
44
+ * Add the booking form editor page to the admin menu
45
+ *
46
+ * @since 0.1
47
+ */
48
+ public function add_menu_page() {
49
+ $this->hook_suffix = add_submenu_page(
50
+ 'rtb-bookings',
51
+ _x( 'Custom Fields', 'Title of the Custom Fields editor page', 'restaurant-reservations' ),
52
+ _x( 'Custom Fields', 'Title of Custom Fields editor link in the admin menu', 'restaurant-reservations' ),
53
+ 'manage_options',
54
+ 'cffrtb-editor',
55
+ array( $this, 'display_editor_page' )
56
+ );
57
+
58
+ // Print the error modal and enqueue assets
59
+ add_action( 'load-' . $this->hook_suffix, array( $this, 'enqueue_admin_assets' ) );
60
+ add_action( 'admin_footer-' . $this->hook_suffix, array( $this, 'print_modals' ) );
61
+ }
62
+
63
+ /**
64
+ * Enqueue assets on the editor page
65
+ *
66
+ * @since 0.1
67
+ */
68
+ public function enqueue_admin_assets() {
69
+ global $rtb_controller;
70
+
71
+ if ( ! $rtb_controller->permissions->check_permission( 'custom_fields' ) ) { return; }
72
+
73
+ // Retrieve pointers (admin tooltips)
74
+ $pointers = apply_filters( 'cffrtb_pointers', array() );
75
+
76
+ // Determine editor dependencies
77
+ $editor_css_deps = array( 'rtb-booking-form' );
78
+ $editor_js_deps = array( 'jquery-ui-sortable', 'rtb-booking-form' );
79
+ if ( !empty( $pointers ) ) {
80
+ $editor_css_deps[] = 'wp-pointer';
81
+ $editor_js_deps[] = 'wp-pointer';
82
+ }
83
+
84
+ // Booking form assets
85
+ $rtb_controller->register_assets();
86
+ rtb_enqueue_assets();
87
+
88
+ // Editor assets
89
+ wp_enqueue_style( 'cffrtb-editor', RTB_PLUGIN_URL . '/assets/css/editor.css', $editor_css_deps, false );
90
+ wp_enqueue_script( 'cffrtb-editor', RTB_PLUGIN_URL . '/assets/js/editor.js', $editor_js_deps, false, true );
91
+
92
+ // Pass the fields array to the script
93
+ $field_controller = $rtb_controller->fields;
94
+ $field_controller->get_valid_field_types();
95
+ wp_localize_script(
96
+ 'cffrtb-editor',
97
+ 'cffrtb_editor',
98
+ array(
99
+ 'ajax_nonce' => wp_create_nonce( 'cffrtb-editor' ),
100
+ 'default_type' => key( $field_controller->valid_field_types ),
101
+ 'default_subtype' => key( $field_controller->valid_field_types[ key( $field_controller->valid_field_types ) ]['subtypes'] ),
102
+ 'pointers' => $pointers,
103
+ 'strings' => array(
104
+ 'save' => __( 'Save', 'restaurant-reservations' ),
105
+ 'editor_add_field' => __( 'Add Field', 'restaurant-reservations' ),
106
+ 'editor_edit_field' => __( 'Edit Field', 'restaurant-reservations' ),
107
+ 'editor_save_field' => __( 'Save Field', 'restaurant-reservations' ),
108
+ 'editor_add_fieldset' => __( 'Add Fieldset', 'restaurant-reservations' ),
109
+ 'editor_save_fieldset' => __( 'Save Fieldset', 'restaurant-reservations' ),
110
+ 'field_missing_title' => __( 'Please enter a label for this field.', 'restaurant-reservations' ),
111
+ 'field_missing_options' => __( 'To add an Option field you must add at least one option below.', 'restaurant-reservations' ),
112
+ 'fieldset_not_empty' => __( 'This fieldset can not be deleted until all of its attached fields are removed or assigned to another fieldset.', 'restaurant-reservations' ),
113
+ 'confirm_reset_all' => __( 'Are you sure you want to reset the booking form? All of your changes and custom fields will be removed. This action can not be undone.', 'restaurant-reservations' ),
114
+ 'unknown_error' => __( 'An unspecified error occurred. Please try again. If the problem persists, try logging out and logging back in.', 'restaurant-reservations' ),
115
+ ),
116
+ )
117
+ );
118
+ }
119
+
120
+ /**
121
+ * Display the booking form editor page
122
+ *
123
+ * @since 0.1
124
+ */
125
+ public function display_editor_page() {
126
+ global $rtb_controller;
127
+
128
+ $custom_fields_permission = $rtb_controller->permissions->check_permission( 'custom_fields' )
129
+
130
+ ?>
131
+
132
+ <div class="wrap">
133
+ <h2>
134
+ <?php _e( 'Custom Fields Editor', 'restaurant-reservations' ); ?>
135
+ <a href="#" class="add-new-h2 add-field">Add New</a>
136
+ </h2>
137
+ <?php if ( $custom_fields_permission ) { ?>
138
+ <div id="cffrtb-editor">
139
+ <?php $this->print_booking_form_fields(); ?>
140
+ </div>
141
+ <?php } else { ?>
142
+ <div class='rtb-premium-locked'>
143
+ <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">Upgrade</a> to the premium version to use this feature
144
+ </div>
145
+ <?php } ?>
146
+ </div>
147
+
148
+ <?php
149
+ }
150
+
151
+ /**
152
+ * Print the booking form fields for editing
153
+ *
154
+ * @since 0.0.1
155
+ */
156
+ public function print_booking_form_fields() {
157
+ global $rtb_controller;
158
+
159
+ // Retrieve the form fields
160
+ $fields = $rtb_controller->settings->get_booking_form_fields();
161
+
162
+ // Retrieve system fields with limited editing abilities
163
+ $field_controller = $rtb_controller->fields;
164
+ $field_controller->get_system_fields();
165
+ ?>
166
+
167
+ <div class="cffrtb-lft">
168
+
169
+ <ul id="cffrtb-list" class="cffrtb-list">
170
+
171
+ <?php
172
+ foreach( $fields as $fieldset => $contents ) {
173
+ echo $this->print_field( $fieldset, $contents, 'fieldset' );
174
+ }
175
+ ?>
176
+
177
+ </ul>
178
+
179
+ <a href="#" class="add-field">
180
+ <span class="dashicons dashicons-plus-alt"></span>
181
+ <?php _e( 'Add New', 'restaurant-reservations' ); ?>
182
+ </a>
183
+
184
+ </div>
185
+ <div class="cffrtb-rgt">
186
+
187
+ <div id="cffrtb-disabled" class="cffrtb-list">
188
+ <h3><?php _e( 'Disabled Fields', 'restaurant-reservations' ); ?></h3>
189
+
190
+ <?php
191
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
192
+ if ( $modified ) :
193
+
194
+ $list = '';
195
+ foreach( $modified as $slug => $field ) {
196
+
197
+ if ( !empty( $field['disabled'] ) ) {
198
+
199
+ $default_field = $slug == $field['fieldset'] ? $field_controller->default_fields[ $slug ] : $field_controller->get_nested_field( $slug, $field_controller->default_fields );
200
+ if ( empty( $default_field ) || !is_array( $default_field ) ) {
201
+ continue;
202
+ }
203
+
204
+ $type = $slug == $field['fieldset'] ? 'fieldset' : 'field';
205
+
206
+ $list .= $this->print_field( $slug, array_merge( $default_field, $field ), $type );
207
+ }
208
+ }
209
+
210
+ if ( !empty( $list ) ) :
211
+ ?>
212
+
213
+ <ul class="fields">
214
+ <?php echo $list; ?>
215
+ </ul>
216
+
217
+ <?php else : ?>
218
+
219
+ <p class="description no-disabled-fields"><?php _e( 'You have not disabled any default fields yet.', 'restaurant-reservations' ); ?></p>
220
+
221
+ <?php
222
+ endif;
223
+ endif;
224
+ ?>
225
+
226
+ <div class="reset<?php echo !empty( $modified ) ? ' is-visible' : ''; ?>">
227
+ <a href="#" class="button reset-all">
228
+ <?php _e( 'Revert to default', 'restaurant-reservations' ); ?>
229
+ </a>
230
+ <a href="#" class="learn-more">
231
+ <?php _e( 'Learn more', 'restaurant-reservations' ); ?>
232
+ </a>
233
+ <p class="description learn-more-details">
234
+ <?php _e( 'All of your changes and custom fields will be discarded if you revert to default. This is not advised unless you want to remove all of your changes and restore the default booking form.', 'restaurant-reservations' ); ?>
235
+ </p>
236
+ </div>
237
+ </div>
238
+
239
+ </div>
240
+
241
+ <?php
242
+ }
243
+
244
+ /**
245
+ * Print a single field in the fields list
246
+ *
247
+ * @since 0.1
248
+ */
249
+ public function print_field( $slug, $field, $type = 'field' ) {
250
+ global $rtb_controller;
251
+
252
+ $field_controller = $rtb_controller->fields;
253
+ if ( empty( $field_controller->system_fields ) ) {
254
+ $field_controller->get_system_fields();
255
+ }
256
+
257
+ $title = '';
258
+ if ( $type == 'fieldset' && !empty( $field['legend'] ) ) {
259
+ $title = $field['legend'];
260
+ } elseif ( !empty( $field['title'] ) ) {
261
+ $title = $field['title'];
262
+ }
263
+
264
+ ob_start();
265
+ ?>
266
+
267
+ <li class="<?php echo $type; echo !empty( $field['disabled'] ) ? ' disabled' : ''; ?>" data-slug="<?php echo esc_attr( $slug ); ?>"<?php echo empty( $field['ID'] ) ? '' : ' data-id="' . (int) $field['ID'] . '"'; ?>>
268
+
269
+ <div class="title">
270
+ <div class="view">
271
+ <span class="value">
272
+ <?php echo esc_html( $title ); ?>
273
+ </span>
274
+
275
+ <div class="controls">
276
+ <?php if ( empty( $field['disabled'] ) ) : ?>
277
+ <a href="#" class="label" title="<?php _e( 'Edit title', 'restaurant-reservations' ); ?>">
278
+ <span class="dashicons dashicons-edit"></span>
279
+ </a>
280
+ <?php endif; ?>
281
+ <?php if ( !empty( $field['disabled'] ) ) : ?>
282
+ <a href="#" class="enable" title="<?php _e( 'Enable field', 'restaurant-reservations' ); ?>">
283
+ <span class="dashicons dashicons-visibility"></span>
284
+ </a>
285
+ <?php elseif ( ( $type == 'field' && !in_array( $slug, $field_controller->system_fields ) ) || ( $type == 'fieldset' && !in_array( $slug, $field_controller->system_fieldsets ) ) ) : ?>
286
+ <?php if ( $type == 'field' && !empty( $field['ID'] ) ) : ?>
287
+ <a href="#" class="options" title="<?php _e( 'Edit field', 'restaurant-reservations' ); ?>">
288
+ <span class="dashicons dashicons-admin-tools"></span>
289
+ </a>
290
+ <?php endif; ?>
291
+ <a href="#" class="delete" title="<?php _e( 'Delete field', 'restaurant-reservations' ); ?>">
292
+ <span class="dashicons dashicons-no"></span>
293
+ </a>
294
+ <?php endif; ?>
295
+ </div>
296
+ </div>
297
+
298
+ <?php if ( empty( $field['disabled'] ) ) : ?>
299
+ <div class="edit">
300
+ <input type="text" name="title" value="<?php echo esc_html( $title ); ?>" tabindex="-1">
301
+
302
+ <div class="controls">
303
+ <a href="#" class="save" tabindex="-1">
304
+ <?php _e( 'Save', 'restaurant-reservations' ); ?>
305
+ </a>
306
+ </div>
307
+
308
+ <div class="status">
309
+ <span class="load-spinner"></span>
310
+ </div>
311
+ </div>
312
+ <?php endif; ?>
313
+
314
+ </div>
315
+
316
+ <?php if ( $type == 'fieldset' && empty( $field['disabled'] ) && empty( $field['exclude_fields'] ) ) : ?>
317
+ <ul class="fields">
318
+ <?php
319
+ if( !empty( $field['fields'] ) ) :
320
+ foreach( $field['fields'] as $field_slug => $sub_field ) :
321
+ echo $this->print_field( $field_slug, $sub_field );
322
+ endforeach;
323
+ endif;
324
+ ?>
325
+ </ul>
326
+ <?php endif; ?>
327
+ </li>
328
+ <?php
329
+
330
+ return ob_get_clean();
331
+ }
332
+
333
+ /**
334
+ * Print a label field for the editing form
335
+ *
336
+ * @since 0.1
337
+ */
338
+ public function print_label_input( $slug, $label ) {
339
+ ?>
340
+
341
+ <div class="label">
342
+ <label for="<?php echo esc_attr( $slug ); ?>_label">
343
+ <?php _e( 'Label', 'restaurant-reservations' ); ?>
344
+ </label>
345
+ <input type="text" name="label" id="<?php echo esc_attr( $slug ); ?>_label" value="<?php echo esc_attr( $label ); ?>">
346
+ </div>
347
+
348
+ <?php
349
+ }
350
+
351
+ /**
352
+ * Print the error modal in the footer. This re-uses the error modal
353
+ * markup and styling from Restaurant Reservations
354
+ *
355
+ * @since 0.1
356
+ */
357
+ public function print_modals() {
358
+ global $rtb_controller;
359
+
360
+ $field_controller = $rtb_controller->fields;
361
+ $field_controller->get_valid_field_types();
362
+
363
+ $default_type = key( $field_controller->valid_field_types );
364
+ $default_subtype = key( $field_controller->valid_field_types[ $default_type ]['subtypes'] );
365
+ ?>
366
+ <div id="cffrtb-field-editor" class="rtb-admin-modal">
367
+
368
+ <form id="cffrtb-field-editor-form" class="rtb-container">
369
+ <input type="hidden" name="id" value="">
370
+ <input type="hidden" name="type" value="<?php echo esc_attr( $default_type ); ?>">
371
+ <input type="hidden" name="subtype" value="<?php echo esc_attr( $default_type ); ?>">
372
+
373
+ <div class="title">
374
+ <h2><?php _e( 'Add Field', 'restaurant-reservations' ); ?></h2>
375
+ </div>
376
+
377
+ <div class="type">
378
+ <label>
379
+ <?php _e( 'Field Type', 'restaurant-reservations' ); ?>
380
+ </label>
381
+
382
+ <div class="selector">
383
+ <ul class="types">
384
+ <?php foreach( $field_controller->valid_field_types as $slug => $type ) : ?>
385
+ <li>
386
+ <a href="#" class="<?php echo esc_attr( $slug ); if ( $default_type == $slug ) : ?> current<?php endif; ?>" data-type="<?php echo esc_attr( $slug ); ?>">
387
+ <?php echo $type['title']; ?>
388
+ </a>
389
+ </li>
390
+ <?php endforeach; ?>
391
+ </ul>
392
+
393
+ <?php foreach( $field_controller->valid_field_types as $slug => $type ) : ?>
394
+ <ul class="subtypes <?php echo $slug; if ( $default_type == $slug ) : ?> current<?php endif; ?>">
395
+ <?php foreach( $type['subtypes'] as $sub_slug => $subtype ) : ?>
396
+ <li>
397
+ <a href="#" class="<?php echo esc_attr( $sub_slug ); if ( $default_type == $sub_slug ) : ?> current<?php endif; ?>" data-subtype="<?php echo esc_attr( $sub_slug ); ?>">
398
+ <?php echo $subtype['title']; ?>
399
+ </a>
400
+ </li>
401
+ <?php endforeach; ?>
402
+ </ul>
403
+ <?php endforeach; ?>
404
+ </div>
405
+ </div>
406
+ <div class="settings">
407
+
408
+ <div class="item">
409
+ <label for="title">
410
+ <?php _e( 'Label', 'restaurant-reservations' ); ?>
411
+ </label>
412
+ <input type="text" name="title" id="title">
413
+ </div>
414
+
415
+ <div class="settings-panel options">
416
+ <div class="item">
417
+ <label for="options-options">
418
+ <?php _e( 'Options', 'restaurant-reservations' ); ?>
419
+ </label>
420
+ <div class="add">
421
+ <input type="text" name="options" id="options-options">
422
+ <a href="#">
423
+ <span class="dashicons dashicons-plus-alt"></span>
424
+ <?php _e( 'Add', 'restaurant-reservations' ); ?>
425
+ </a>
426
+ </div>
427
+ <ul class="options">
428
+ </ul>
429
+ </div>
430
+ </div>
431
+
432
+ <?php do_action( 'cffrtb_field_editor_settings_panel' ); ?>
433
+
434
+ </div>
435
+
436
+ <div class="required">
437
+ <label>
438
+ <input type="checkbox" name="required" value="1">
439
+ <?php _e( 'Required', 'restaurant-reservations' ); ?>
440
+ </label>
441
+ </div>
442
+
443
+ <div class="actions">
444
+ <a href="#" class="button-primary save">
445
+ <?php _e( 'Add Field', 'restaurant-reservations' ); ?>
446
+ </a>
447
+ <a href="#" class="button cancel">
448
+ <?php _e( 'Cancel', 'restaurant-reservations' ); ?>
449
+ </a>
450
+ <div class="status">
451
+ <span class="load-spinner"></span>
452
+ </div>
453
+ </div>
454
+ </form>
455
+ </div>
456
+
457
+ <div id="cffrtb-field-editor-option" class="rtb-admin-modal">
458
+ <div class="rtb-container">
459
+ <div class="option">
460
+ <a href="#" class="field button-primary">
461
+ <?php _e( 'Add Field', 'restaurant-reservations' ); ?>
462
+ </a>
463
+ <p class="description">
464
+ <?php _e( 'Fields prompt the user to enter information or select from options.' ); ?>
465
+ </p>
466
+ </div>
467
+ <div class="option">
468
+ <a href="#" class="fieldset button">
469
+ <?php _e( 'Add Fieldset', 'restaurant-reservations' ); ?>
470
+ </a>
471
+ <p class="description">
472
+ <?php _e( 'Fieldsets group other fields under a common label.' ); ?>
473
+ </p>
474
+ </div>
475
+ </div>
476
+ </div>
477
+
478
+ <div id="rtb-error-modal" class="rtb-admin-modal">
479
+ <div class="rtb-error rtb-container"">
480
+ <div class="rtb-error-msg"></div>
481
+ <a href="#" class="button"><?php _e( 'Close', 'restaurant-reservations' ); ?></a>
482
+ </div>
483
+ </div>
484
+ <?php
485
+ }
486
+
487
+ /**
488
+ * Handle ajax requests from logged out users
489
+ *
490
+ * @since 0.1
491
+ */
492
+ public function ajax_nopriv() {
493
+
494
+ wp_send_json_error(
495
+ array(
496
+ 'error' => 'loggedout',
497
+ 'msg' => sprintf( __( 'You have been logged out. Please %slogin again%s.', 'restaurant-reservations' ), '<a href="' . wp_login_url( admin_url( 'admin.php?page=cffrtb-editor' ) ) . '">', '</a>' ),
498
+ )
499
+ );
500
+ }
501
+
502
+ /**
503
+ * Handle ajax request to save a field
504
+ *
505
+ * @since 0.1
506
+ */
507
+ public function ajax_save_field() {
508
+ global $rtb_controller;
509
+
510
+ // Authenticate request
511
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
512
+ $this->nopriv_ajax();
513
+ }
514
+
515
+ // Missing data
516
+ if ( empty( $_POST['field'] ) ) {
517
+ wp_send_json_error(
518
+ array(
519
+ 'error' => 'no_field_data',
520
+ 'msg' => __( 'No field data was received with your request.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
521
+ )
522
+ );
523
+ }
524
+
525
+ // Missing request specification
526
+ if ( empty( $_POST['request'] ) ) {
527
+ wp_send_json_error(
528
+ array(
529
+ 'error' => 'no_request',
530
+ 'msg' => __( 'Internal data that was supposed to be passed with your request was not received.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
531
+ )
532
+ );
533
+ }
534
+
535
+ $field = new cffrtbField( $_POST['field'] );
536
+
537
+ // Just the label
538
+ if ( $_POST['request'] == 'save_label' ) {
539
+ $this->send_ajax_response( $field->save_label() );
540
+
541
+ // The whole field
542
+ } elseif ( $_POST['request'] == 'save_field' ) {
543
+ $this->send_ajax_response( $field->save_field() );
544
+ }
545
+
546
+ wp_send_json_error(
547
+ array(
548
+ 'error' => 'unknown',
549
+ 'msg' => __( 'An unknown error has occurred.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
550
+ )
551
+ );
552
+ }
553
+
554
+ /**
555
+ * Handle ajax request to save the order of fields and fieldsets
556
+ *
557
+ * @since 0.1
558
+ */
559
+ public function ajax_save_order() {
560
+ global $rtb_controller;
561
+
562
+ // Authenticate request
563
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
564
+ $this->nopriv_ajax();
565
+ }
566
+
567
+ // Missing data
568
+ if ( empty( $_POST['order'] ) ) {
569
+ wp_send_json_error(
570
+ array(
571
+ 'error' => 'no_fields_data',
572
+ 'msg' => __( 'No fields data was received with your request.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
573
+ )
574
+ );
575
+ }
576
+
577
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
578
+ $orig_modified = $modified;
579
+
580
+ $custom_fields_error = array();
581
+ $has_custom_fields = false;
582
+ foreach( $_POST['order'] as $field ) {
583
+
584
+ if ( !isset( $field['order'] ) || empty( $field['fieldset'] ) ) {
585
+ continue; // @todo this indicates some kind of data error, though
586
+ }
587
+
588
+ // Default fields
589
+ if ( empty( $field['ID'] ) ) {
590
+
591
+ if ( empty( $modified[ $field['slug'] ] ) ) {
592
+ $modified[ $field['slug'] ] = array();
593
+ }
594
+
595
+ // Skip if the order isn't changing
596
+ if ( isset( $modified[ $field['slug'] ]['order'] ) && $modified[ $field['slug'] ]['order'] == $field['order'] && isset( $modified[ $field['slug'] ]['fieldset'] ) && $modified[ $field['slug'] ]['fieldset'] == $field['fieldset'] ) {
597
+ continue;
598
+ }
599
+
600
+ $modified[ $field['slug'] ]['order'] = (int) $field['order'];
601
+ $modified[ $field['slug'] ]['fieldset'] = sanitize_key( $field['fieldset'] );
602
+
603
+ // Custom fields
604
+ } else {
605
+
606
+ $custom_field = new cffrtbField( $field );
607
+ $result = $custom_field->save_field();
608
+
609
+ if ( !$result[0] ) {
610
+ array_push( $custom_fields_error, $result[1] );
611
+ }
612
+
613
+ $has_custom_fields = true;
614
+ }
615
+ }
616
+
617
+ update_option( $rtb_controller->custom_fields->modified_option_key, $modified );
618
+
619
+ if ( !$has_custom_fields || ( $has_custom_fields && empty( $custom_fields_error ) ) ) {
620
+ wp_send_json_success();
621
+
622
+ } else {
623
+ wp_send_json_error(
624
+ array(
625
+ 'error' => 'save_order_failed',
626
+ 'msg' => __( 'An error occurred while saving the new field order. Please try again.', 'restaurant-reservations' ),
627
+ 'fields' => $_POST['order'],
628
+ 'custom_fields_error' => $custom_fields_error,
629
+ )
630
+ );
631
+ }
632
+
633
+ wp_send_json_error(
634
+ array(
635
+ 'error' => 'unknown',
636
+ 'msg' => __( 'An unknown error has occurred.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
637
+ )
638
+ );
639
+ }
640
+
641
+ /**
642
+ * Handle ajax request to load a field
643
+ *
644
+ * @since 0.1
645
+ */
646
+ public function ajax_load_field() {
647
+ global $rtb_controller;
648
+
649
+ // Authenticate request
650
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
651
+ $this->nopriv_ajax();
652
+ }
653
+
654
+ // Missing data
655
+ if ( empty( $_POST['ID'] ) ) {
656
+ wp_send_json_error(
657
+ array(
658
+ 'error' => 'no_id',
659
+ 'msg' => __( 'The requested field could not be loaded because no ID was received with your request.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
660
+ )
661
+ );
662
+ }
663
+
664
+ $field = new cffrtbField( array( 'ID' => (int) $_POST['ID'] ) );
665
+
666
+ wp_send_json_success(
667
+ array(
668
+ 'field' => $field,
669
+ )
670
+ );
671
+ }
672
+
673
+ /**
674
+ * Handle ajax request to delete or disable a field
675
+ *
676
+ * @since 0.1
677
+ */
678
+ public function ajax_delete_field() {
679
+ global $rtb_controller;
680
+
681
+ // Authenticate request
682
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
683
+ $this->nopriv_ajax();
684
+ }
685
+
686
+ // Missing data
687
+ if ( empty( $_POST['ID'] ) && ( empty( $_POST['slug'] ) || empty( $_POST['fieldset'] ) ) ) {
688
+ wp_send_json_error(
689
+ array(
690
+ 'error' => 'no_id',
691
+ 'msg' => __( 'The requested field could not be deleted because no ID or slug was received with your request.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
692
+ )
693
+ );
694
+ }
695
+
696
+ if ( !empty( $_POST['ID'] ) ) {
697
+ $post = wp_delete_post( (int) $_POST['ID'] );
698
+
699
+ if ( !$post ) {
700
+ wp_send_json_error(
701
+ array(
702
+ 'error' => 'delete_field_failed',
703
+ 'msg' => __( 'An error occurred while deleting this field.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
704
+ )
705
+ );
706
+ }
707
+
708
+ wp_send_json_success();
709
+
710
+ } else {
711
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
712
+ $slug = sanitize_key( $_POST['slug'] );
713
+ $fieldset = sanitize_key( $_POST['fieldset'] );
714
+ $modified[ $slug ]['disabled'] = 1;
715
+ $modified[ $slug ]['fieldset'] = $fieldset;
716
+ update_option( $rtb_controller->custom_fields->modified_option_key, $modified );
717
+
718
+ global $rtb_controller;
719
+ $fields = $rtb_controller->settings->get_booking_form_fields();
720
+ $field = $slug == $fieldset ? $rtb_controller->fields->default_fields[ $slug ] : $rtb_controller->fields->get_nested_field( $slug, $rtb_controller->fields->default_fields );
721
+ $field['disabled'] = 1;
722
+
723
+ $type = $slug == $fieldset ? 'fieldset' : 'field';
724
+
725
+ wp_send_json_success(
726
+ array(
727
+ 'field' => $this->print_field( $slug, $field, $type ),
728
+ )
729
+ );
730
+ }
731
+ }
732
+
733
+ /**
734
+ * Handle an ajax request to enable a field that has been disabled
735
+ *
736
+ * @since 0.1
737
+ */
738
+ public function ajax_enable_field() {
739
+ global $rtb_controller;
740
+
741
+ // Authenticate request
742
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
743
+ $this->nopriv_ajax();
744
+ }
745
+
746
+ // Missing data
747
+ if ( empty( $_POST['slug'] ) ) {
748
+ wp_send_json_error(
749
+ array(
750
+ 'error' => 'no_id',
751
+ 'msg' => __( 'The requested field could not be enabled because no identifying slug was received with your request.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
752
+ )
753
+ );
754
+ }
755
+
756
+ $slug = sanitize_key( $_POST['slug'] );
757
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
758
+
759
+ if ( empty( $modified ) || !is_array( $modified ) || !array_key_exists( $slug, $modified ) ) {
760
+ wp_send_json_error(
761
+ array(
762
+ 'error' => 'field_not_found',
763
+ 'msg' => __( 'The requested field could not be enabled because it did not appear to be disabled.', 'restaurant-reservations' ) . ' ' . $rtb_controller->custom_fields->common_error_msg
764
+ )
765
+ );
766
+ }
767
+
768
+ if ( isset( $modified[ $slug ]['disabled'] ) ) {
769
+ unset( $modified[ $slug ]['disabled'] );
770
+ update_option( $rtb_controller->custom_fields->modified_option_key, $modified );
771
+ }
772
+
773
+ global $rtb_controller;
774
+ $fields = $rtb_controller->settings->get_booking_form_fields();
775
+ $field = $_POST['type'] == 'fieldset' ? $rtb_controller->fields->default_fields[ $slug ] : $rtb_controller->fields->get_nested_field( $slug, $fields );
776
+
777
+ $type = $_POST['type'] == 'fieldset' ? 'fieldset' : 'field';
778
+
779
+ if ( $type == 'fieldset' ) {
780
+ $field['exclude_fields'] = true;
781
+ }
782
+
783
+ wp_send_json_success(
784
+ array(
785
+ 'field' => $this->print_field( $slug, $field, $type )
786
+ )
787
+ );
788
+ }
789
+
790
+ /**
791
+ * Handle an ajax request to reset all changes and delete custom
792
+ * fields
793
+ *
794
+ * @since 0.1
795
+ */
796
+ public function ajax_reset_all() {
797
+ global $rtb_controller;
798
+
799
+ // Authenticate request
800
+ if ( !check_ajax_referer( 'cffrtb-editor', 'nonce' ) || !current_user_can( 'manage_options' ) ) {
801
+ $this->nopriv_ajax();
802
+ }
803
+
804
+ // Delete modifications to default fields
805
+ delete_option( $rtb_controller->custom_fields->modified_option_key );
806
+
807
+ // Delete all custom posts
808
+ $posts = new WP_Query(
809
+ array(
810
+ 'post_type' => 'cffrtb_field',
811
+ 'posts_per_page' => 1000, // Very large upper limit
812
+ )
813
+ );
814
+
815
+ while( $posts->have_posts() ) {
816
+ $posts->the_post();
817
+ wp_delete_post( get_the_ID() );
818
+ }
819
+
820
+ wp_send_json_success();
821
+ }
822
+
823
+ /**
824
+ * Send an ajax response
825
+ *
826
+ * This is a generic response sender which will search for an error
827
+ * in the response and make the appropriate wp_send_json_*() call.
828
+ *
829
+ * @since 0.1
830
+ */
831
+ public function send_ajax_response( $response = array() ) {
832
+
833
+ $response[1] = empty( $response[1] ) ? '' : $response[1];
834
+
835
+ if ( !empty( $response[0] ) ) {
836
+ wp_send_json_success( $response[1] );
837
+
838
+ } else {
839
+ wp_send_json_error( $response[1] );
840
+ }
841
+
842
+ }
843
+
844
+ }
845
+ } // endif;
includes/EmailTemplates.class.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * A class to handle email templates for restaurant reservations
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) )
6
+ exit;
7
+
8
+ if ( !class_exists( 'rtbEmailTemplates' ) ) {
9
+ class rtbEmailTemplates {
10
+
11
+ /**
12
+ * Available templates
13
+ *
14
+ * @param array $template_options
15
+ * @since 0.1
16
+ */
17
+ public $template_options;
18
+
19
+
20
+ /**
21
+ * Initialize the plugin and register hooks
22
+ *
23
+ * @since 0.1.0
24
+ */
25
+ public function __construct() {
26
+
27
+ require_once( RTB_PLUGIN_DIR . '/includes/class-designer.php' );
28
+ require_once( RTB_PLUGIN_DIR . '/includes/load-notifications.php' );
29
+ require_once( RTB_PLUGIN_DIR . '/includes/integrations/business-profile.php' );
30
+
31
+ $this->load_template_options();
32
+
33
+ add_image_size( 'etfrtb_logo', 200, 200 );
34
+ }
35
+
36
+ /**
37
+ * Load the template options into the controller instance so that they're
38
+ * available from the customizer and the designer class
39
+ *
40
+ * @since 0.1
41
+ */
42
+ public function load_template_options() {
43
+
44
+ $template_options = array(
45
+ 'conversations.php' => array(
46
+ 'title' => __( 'Conversations', 'restaurant-reservations' ),
47
+ 'description' => __( 'A clean, simple email template for talking to directly to your customer.', 'restaurant-reservations' ),
48
+ ),
49
+ 'impressions.php' => array(
50
+ 'title' => __( 'Impressions', 'restaurant-reservations' ),
51
+ 'description' => __( 'A small email template that is great for making a quick impression.', 'restaurant-reservations' ),
52
+ ),
53
+ 'statement.php' => array(
54
+ 'title' => __( 'Statement', 'restaurant-reservations' ),
55
+ 'description' => __( 'A plain template for delivering a direct message.', 'restaurant-reservations' ),
56
+ ),
57
+ 'stationary.php' => array(
58
+ 'title' => __( 'Stationary', 'restaurant-reservations' ),
59
+ 'description' => __( 'An elegant template for sending a message with an air of sophistication.', 'restaurant-reservations' ),
60
+ ),
61
+ );
62
+
63
+ $this->template_options = apply_filters( 'etfrtb_template_options', $template_options );
64
+ }
65
+
66
+ }
67
+
68
+ } // End if
69
+
70
+ /**
71
+ * Load the customizer early enough to initialize it in "blank slate" mode.
72
+ *
73
+ * @since 0.1
74
+ */
75
+ require_once( RTB_PLUGIN_DIR . '/includes/load-customizer.php' );
includes/Export.CSV.class.php ADDED
@@ -0,0 +1,263 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'ebfrtbExportCSV' ) ) {
5
+ /**
6
+ * Handle CSV exports
7
+ *
8
+ * PHP's fputcsv() function is used to stream a
9
+ * CSV file to the browser.
10
+ *
11
+ * @since 0.2
12
+ */
13
+ class ebfrtbExportCSV extends ebfrtbExport {
14
+
15
+ /**
16
+ * Arguments for the query used to fetch
17
+ * bookings for this export
18
+ *
19
+ * @since 0.1
20
+ */
21
+ public $query_args;
22
+
23
+ /**
24
+ * Insantiate the CSV export
25
+ *
26
+ * @since 0.1
27
+ */
28
+ public function __construct( $bookings, $args = array() ) {
29
+
30
+ $this->bookings = $bookings;
31
+
32
+ // Date range
33
+ if ( !empty( $args['query_args'] ) ) {
34
+ $this->query_args = $args['query_args'];
35
+ }
36
+
37
+ // Locations
38
+ global $rtb_controller;
39
+ if ( !empty( $rtb_controller->locations ) && !empty( $rtb_controller->locations->post_type ) ) {
40
+ add_filter( 'ebfrtb_export_csv_booking_headers', array( $this, 'add_location_header' ) );
41
+ add_filter( 'ebfrtb_export_csv_booking', array( $this, 'add_location' ), 10, 2 );
42
+ }
43
+
44
+ // Privacy consent
45
+ $require_consent = $rtb_controller->settings->get_setting( 'require-consent' );
46
+ if ( !empty( $require_consent ) ) {
47
+ add_filter( 'ebfrtb_export_csv_booking_headers', array( $this, 'add_privacy_header' ) );
48
+ add_filter( 'ebfrtb_export_csv_booking', array( $this, 'add_privacy' ), 10, 2 );
49
+ }
50
+
51
+ add_filter( 'ebfrtb_export_csv_booking_headers', array( $this, 'add_custom_fields_header' ) );
52
+ add_filter( 'ebfrtb_export_csv_booking', array( $this, 'add_custom_fields' ), 10, 2 );
53
+ }
54
+
55
+ /**
56
+ * Compile an array for the CSV file
57
+ *
58
+ * @since 0.1
59
+ */
60
+ public function export() {
61
+
62
+ global $rtb_controller;
63
+ $date_format = $rtb_controller->settings->get_setting( 'ebfrtb-csv-date-format' );
64
+
65
+ // Compile bookings arrayarray headers
66
+ $arr = apply_filters( 'ebfrtb_export_csv_booking_headers', array(
67
+ array(
68
+ 'ID' => __( 'Booking ID', 'restaurant-reservations' ),
69
+ 'date' => __( 'Date', 'restaurant-reservations' ),
70
+ 'name' => __( 'Name', 'restaurant-reservations' ),
71
+ 'party' => __( 'Party', 'restaurant-reservations' ),
72
+ 'email' => __( 'Email', 'restaurant-reservations' ),
73
+ 'phone' => __( 'Phone', 'restaurant-reservations' ),
74
+ 'message' => __( 'Message', 'restaurant-reservations' ),
75
+ 'date_submission' => __( 'Date the request was made', 'restaurant-reservations' ),
76
+ 'status' => __( 'Booking Status', 'restaurant-reservations' ),
77
+ )
78
+ ) );
79
+
80
+ // Compile bookings array
81
+ foreach( $this->bookings as $booking ) {
82
+ $arr[] = apply_filters( 'ebfrtb_export_csv_booking', array(
83
+ 'ID' => $booking->ID,
84
+ 'date' => date_i18n( $date_format, strtotime( $booking->date ) ),
85
+ 'name' => $booking->name,
86
+ 'party' => $booking->party,
87
+ 'email' => $booking->email,
88
+ 'phone' => $booking->phone,
89
+ 'message' => str_replace( array( "\r\n", "\n", "\r", '<br />', '<br>', '<br/>' ), ' ', $booking->message ),
90
+ 'date_submission' => date_i18n( $date_format, $booking->date_submission ),
91
+ 'status' => $booking->post_status,
92
+ ), $booking );
93
+ }
94
+
95
+ $this->export = apply_filters( 'ebfrtb_export_csv_bookings', $arr );
96
+
97
+ return $this->export;
98
+ }
99
+
100
+ /**
101
+ * Deliver the CSV file to the browser
102
+ *
103
+ * @since 0.1
104
+ */
105
+ public function deliver() {
106
+
107
+ // Generate the export if it's not been done yet
108
+ if ( empty( $this->export ) ) {
109
+ $this->export();
110
+ }
111
+
112
+ $filename = apply_filters( 'ebfrtb_export_csv_filename', sanitize_file_name( $this->get_date_phrase() ) . '.csv' );
113
+ $delimiter = apply_filters( 'ebfrtb_export_csv_delimiter', ',' );
114
+
115
+ header( 'Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0' );
116
+ header( 'Content-Description: File Transfer' );
117
+ header( 'Content-type: text/csv' );
118
+ header( 'Content-Disposition: attachment; filename=' . $filename );
119
+ header( 'Expires: 0' );
120
+ header( 'Pragma: no-cache' );
121
+
122
+ $output = @fopen( 'php://output', 'w' );
123
+
124
+ foreach( $this->export as $booking ) {
125
+ fputcsv( $output, $booking, $delimiter );
126
+ }
127
+
128
+ fclose( $output );
129
+
130
+ exit();
131
+ }
132
+
133
+ /**
134
+ * Add a location header if locations are active
135
+ *
136
+ * @param array $headers Key/value of spreadsheet header rows id/label
137
+ * @since 1.1
138
+ */
139
+ public function add_location_header( $headers ) {
140
+
141
+ $headers[0] = array_merge(
142
+ array( 'location' => __( 'Location', 'restaurant-reservations' ) ),
143
+ $headers[0]
144
+ );
145
+
146
+ return $headers;
147
+ }
148
+
149
+ /**
150
+ * Add location data from a booking to the array for conversion to csv
151
+ *
152
+ * @param array $arr Assoc array of booking data compiled for conversion to
153
+ * csv
154
+ * @param rtbBooking $booking Original booking object
155
+ * @since 1.1
156
+ */
157
+ public function add_location( $arr, $booking ) {
158
+
159
+ $location = '';
160
+ if ( !empty( $booking->location ) ) {
161
+ $term = get_term( $booking->location );
162
+ if ( is_a( $term, 'WP_Term' ) ) {
163
+ $location = $term->name;
164
+ }
165
+ }
166
+
167
+ $arr = array_merge(
168
+ array( 'location' => $location ),
169
+ $arr
170
+ );
171
+
172
+ return $arr;
173
+ }
174
+
175
+ /**
176
+ * Add a header for the privacy consent if it's active
177
+ *
178
+ * @param array $headers Key/value of spreadsheet header rows id/label
179
+ * @since 1.1.1
180
+ */
181
+ public function add_privacy_header( $headers ) {
182
+
183
+ $headers[0] = array_merge(
184
+ $headers[0],
185
+ array( 'consent_acquired' => __( 'Data Privacy Consent', 'restaurant-reservations' ) )
186
+ );
187
+
188
+ return $headers;
189
+ }
190
+
191
+ /**
192
+ * Add privacy consent collection status to the array for conversion to csv
193
+ *
194
+ * @param array $arr Assoc array of booking data compiled for conversion to
195
+ * csv
196
+ * @param rtbBooking $booking Original booking object
197
+ * @since 1.1
198
+ */
199
+ public function add_privacy( $arr, $booking ) {
200
+
201
+ $consent_acquired = !empty( $booking->consent_acquired ) ? __( 'Yes', 'restaurant-reservations' ) : __( 'No', 'restaurant-reservations' );
202
+ $arr = array_merge(
203
+ $arr,
204
+ array( 'consent_acquired' => $consent_acquired )
205
+ );
206
+
207
+ return $arr;
208
+ }
209
+
210
+ /**
211
+ * Add custom fields to CSV headers
212
+ *
213
+ * @param array $headers Key/value of spreadsheet header rows id/label
214
+ * @since 2.0
215
+ */
216
+ public function add_custom_fields_header( $headers ) {
217
+
218
+ $fields = rtb_get_custom_fields();
219
+
220
+ foreach( $fields as $field ) {
221
+
222
+ if ( $field->type == 'fieldset' ) {
223
+ continue;
224
+ }
225
+
226
+ $headers[0][ 'cf-' . $field->slug ] = $field->title;
227
+ }
228
+
229
+ return $headers;
230
+ }
231
+
232
+ /**
233
+ * Add custom fields to CSV data row
234
+ *
235
+ * @param array $row Assoc array of booking data compiled for conversion to
236
+ * csv
237
+ * @param rtbBooking $booking Original booking object
238
+ * @since 2.0
239
+ */
240
+ public function cffrtb_ebfrtb_add_csv_row( $row, $booking ) {
241
+ global $rtb_controller;
242
+
243
+ $fields = rtb_get_custom_fields();
244
+
245
+ $cf = isset( $booking->custom_fields ) ? $booking->custom_fields : array();
246
+
247
+ foreach( $fields as $field ) {
248
+
249
+ if ( $field->type == 'fieldset' ) {
250
+ continue;
251
+ }
252
+
253
+ $val = isset( $cf[ $field->slug ] ) ? $cf[ $field->slug ] : '';
254
+ $display_val = apply_filters( 'cffrtb_display_value_csv', $rtb_controller->fields->get_display_value( $val, $field, '', false ), $val, $field, $booking );
255
+
256
+ $row[ 'cf-' . $field->slug ] = $display_val;
257
+ }
258
+
259
+ return $row;
260
+ }
261
+
262
+ }
263
+ } // endif
includes/Export.PDF.class.php ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'ebfrtbExportPDF' ) ) {
5
+ /**
6
+ * Handle PDF exports
7
+ *
8
+ * mPDF or TCPDF is used to render the PDFs.
9
+ *
10
+ * mPDF has better HTML/CSS support, but may not
11
+ * be compatible with all servers.
12
+ *
13
+ * http://www.mpdf1.com/
14
+ *
15
+ * TCPDF should have better server compatiblity,
16
+ * so it is a fallback in case the main renderer
17
+ * is not compatible.
18
+ *
19
+ * http://www.tcpdf.org/
20
+ *
21
+ * @since 1.4.1
22
+ */
23
+ class ebfrtbExportPDF extends ebfrtbExport {
24
+
25
+ /**
26
+ * PDF Rendering Library
27
+ *
28
+ * @since 0.1
29
+ */
30
+ public $lib;
31
+
32
+ /**
33
+ * Paper size to use
34
+ *
35
+ * @since 0.1
36
+ */
37
+ public $paper_size;
38
+
39
+ /**
40
+ * Arguments for the query used to fetch
41
+ * bookings for this export
42
+ *
43
+ * @since 0.1
44
+ */
45
+ public $query_args;
46
+
47
+ /**
48
+ * Insantiate the PDF export
49
+ *
50
+ * @since 0.1
51
+ */
52
+ public function __construct( $bookings, $args = array() ) {
53
+
54
+ $this->bookings = $bookings;
55
+
56
+ global $rtb_controller;
57
+ $this->lib = !empty( $args['pdf-lib'] ) ? sanitize_key( $args['pdf-lib'] ) : $rtb_controller->settings->get_setting( 'ebfrtb-pdf-lib' );
58
+
59
+ // Get paper size
60
+ $this->paper_size = !empty( $args['paper-size'] ) ? sanitize_key( $args['paper-size'] ) : $rtb_controller->settings->get_setting( 'ebfrtb-paper-size' );
61
+
62
+ // Query arguments
63
+ if ( !empty( $args['query_args'] ) ) {
64
+ $this->query_args = $args['query_args'];
65
+ }
66
+
67
+ //Add custom field hooks
68
+ add_filter( 'ebfrtb_mpdf_after_details', array($this, 'add_custom_fields_to_mpdf' ) );
69
+ add_filter( 'ebfrtb_tcpdf_after_details', array($this, 'add_custom_fields_to_tcpdf' ) );
70
+ }
71
+
72
+ /**
73
+ * Set document information
74
+ *
75
+ * Sets document meta data like title, creator, etc. Both
76
+ * TCPDF and mPDF use the same methods for this.
77
+ *
78
+ * @since 0.1
79
+ */
80
+ public function set_doc_info( $pdf ) {
81
+
82
+ $pdf->SetCreator( get_bloginfo( 'sitename' ) );
83
+ $pdf->SetAuthor( get_bloginfo( 'sitename' ) );
84
+ $pdf->SetTitle( sprintf( _x( 'Bookings at %s', 'Title of PDF documents', 'restaurant-reservations' ), get_bloginfo( 'sitename' ) ) );
85
+ $pdf->SetSubject( $this->get_date_phrase() );
86
+
87
+ return $pdf;
88
+ }
89
+
90
+ /**
91
+ * Compile the PDF file
92
+ *
93
+ * This routes to the appropriate export method
94
+ * depending on the PDF library being used.
95
+ *
96
+ * @since 0.1
97
+ */
98
+ public function export() {
99
+
100
+ if ( $this->lib === 'tcpdf' ) {
101
+ $this->export_tcpdf();
102
+
103
+ } elseif ( $this->lib === 'mpdf' ) {
104
+ $this->export_mpdf();
105
+
106
+ } else {
107
+ do_action( 'ebcfrtb_pdf_export_' . $this->lib, $this );
108
+ }
109
+
110
+ return $this->export;
111
+ }
112
+
113
+ /**
114
+ * Deliver the PDF to the browser
115
+ *
116
+ * @since 0.1
117
+ */
118
+ public function deliver() {
119
+
120
+ // Generate the export if it's not been done yet
121
+ if ( empty( $this->export ) ) {
122
+ $this->export();
123
+ }
124
+
125
+ $filename = apply_filters( 'ebfrtb_export_pdf_filename', sanitize_file_name( $this->get_date_phrase() ) . '.pdf' );
126
+
127
+ // Clean any stray errors, warnings or notices that may have been
128
+ // printed to the buffer
129
+ ob_get_clean();
130
+
131
+ if ( $this->lib === 'tcpdf' || $this->lib === 'mpdf' ) {
132
+ $this->export->Output( $filename, 'I');
133
+
134
+ } else {
135
+ do_action( 'ebcfrtb_pdf_deliver_' . $this->lib, $this );
136
+ }
137
+
138
+ // Just in case we forget...
139
+ wp_die( __( 'An unexpected error occurred and your export request could not be fulfilled.', 'restaurant-reservations' ) );
140
+ }
141
+
142
+ /**
143
+ * Compile PDF file with TCPDF library
144
+ *
145
+ * @since 0.1
146
+ */
147
+ public function export_tcpdf() {
148
+
149
+ // Load TCPDF library
150
+ require_once( RTB_PLUGIN_DIR . '/lib/tcpdf/config/tcpdf_config.php' );
151
+ require_once( RTB_PLUGIN_DIR . '/lib/tcpdf/tcpdf.php' );
152
+
153
+ // TCPDF uses a different identifier for U.S. Letter format
154
+ if ( $this->paper_size === 'LETTER' ) {
155
+ $this->paper_size = 'ANSI_A';
156
+ }
157
+
158
+ $tcpdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $this->paper_size, true, 'UTF-8', false);
159
+ $tcpdf = $this->set_doc_info( $tcpdf );
160
+
161
+ // set default header data
162
+ $header_title = get_bloginfo( 'sitename' );
163
+ if ( !empty( $this->query_args['location'] ) ) {
164
+ $term = get_term( $this->query_args['location'] );
165
+ if ( is_a( $term, 'WP_Term' ) ) {
166
+ $header_title = $term->name;
167
+ }
168
+ }
169
+ $tcpdf->SetHeaderData('', '', $header_title, $this->get_date_phrase(), array( 117, 117, 117 ), array( 117, 117, 117 ) );
170
+ $tcpdf->setFooterData(array(0,64,0), array(0,64,128));
171
+
172
+ // set header and footer fonts
173
+ $tcpdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
174
+ $tcpdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
175
+
176
+ // set margins
177
+ $tcpdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
178
+ $tcpdf->SetHeaderMargin(PDF_MARGIN_HEADER);
179
+ $tcpdf->SetFooterMargin(PDF_MARGIN_FOOTER);
180
+
181
+ // set auto page breaks
182
+ $tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
183
+
184
+ // set image scale factor
185
+ $tcpdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
186
+
187
+ // Subset fonts for smaller doc sizes
188
+ $tcpdf->setFontSubsetting(true);
189
+
190
+ // Add a page
191
+ $tcpdf->AddPage();
192
+ $tcpdf->SetCellPadding(0);
193
+
194
+ // Generate the bookings HTML
195
+ ob_start();
196
+ $this->include_template( 'tcpdf.php' );
197
+ $html = ob_get_clean();
198
+
199
+ // Print HTML
200
+ $tcpdf->writeHTML($html, false, true, false, false, '');
201
+
202
+ $this->export = $tcpdf;
203
+
204
+ return $this->export;
205
+ }
206
+
207
+ /**
208
+ * Add custom fields to TCPDF output
209
+ *
210
+ * @since 2.0
211
+ */
212
+ public function add_custom_fields_to_tcpdf( $booking ) {
213
+ global $rtb_controller;
214
+
215
+ $fields = rtb_get_custom_fields();
216
+ $cf = isset( $booking->custom_fields ) ? $booking->custom_fields : array();
217
+
218
+ foreach( $fields as $field ) {
219
+
220
+ if ( $field->type == 'fieldset' || !isset( $cf[ $field->slug ] ) ) {
221
+ continue;
222
+ }
223
+
224
+ $val = $cf[ $field->slug ];
225
+ $display_val = apply_filters( 'cffrtb_display_value_tcpdf', $rtb_controller->fields->get_display_value( $val, $field, '', true ), $val, $field, $booking );
226
+
227
+ ?>
228
+
229
+ <div class="custom-field <?php echo esc_attr( $field->type . ' ' . $field->slug ); ?>">
230
+ <?php echo esc_html( $field->title ) . esc_html_x( ': ', 'Appears after field label in TCPDF exports', 'custom-fields-for-rtb' ); ?>
231
+ <?php echo $display_val ?>
232
+ </div>
233
+
234
+ <?php
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Compile PDF file with mPDF library
240
+ *
241
+ * @since 0.1
242
+ */
243
+ public function export_mpdf() {
244
+
245
+ if ( !extension_loaded( 'mbstring' ) ) {
246
+ $rtb_settings_link = '<a href="' . admin_url( 'admin.php?page=rtb-settings&tab=rtb-export' ) . '">' . _x( 'export settings', 'Name of a link to the Export tab on the settings page', 'restaurant-reservations' ) . '</a>';
247
+ wp_die( sprintf( __( 'Your server has not loaded the mbstring PHP extension, or has disabled the mbregex PHP extension. mPDF requires both to output a PDF file. Please contact your website host and ask them to enable these PHP extensions. Or switch to the TCPDF library, which has fewer server requirements. You can change the PDF Renderer in the %s.', 'restaurant-reservations' ), $rtb_settings_link ) );
248
+ }
249
+
250
+ // Load mPDF library
251
+ require_once( RTB_PLUGIN_DIR . '/lib/mpdf/mpdf.php' );
252
+
253
+ $mpdf = new mPDF( '', $this->paper_size, '', '', 15, 15, 25 );
254
+ $mpdf = $this->set_doc_info( $mpdf );
255
+
256
+ // Support languages automatically
257
+ $mpdf->autoScriptToLang = true;
258
+ $mpdf->baseScript = 1;
259
+ $mpdf->autoVietnamese = true;
260
+ $mpdf->autoArabic = true;
261
+ $mpdf->autoLangToFont = true;
262
+
263
+ // Generate the bookings HTML
264
+ ob_start();
265
+ $this->include_template( 'mpdf.php' );
266
+ $html = ob_get_clean();
267
+
268
+ $mpdf->WriteHTML($html);
269
+
270
+ $this->export = $mpdf;
271
+
272
+ return $this->export;
273
+ }
274
+
275
+ /**
276
+ * Add custom fields to mPDF output
277
+ *
278
+ * @since 2.0
279
+ */
280
+ public function add_custom_fields_to_mpdf( $booking ) {
281
+ global $rtb_controller;
282
+
283
+ $fields = rtb_get_custom_fields();
284
+ $cf = isset( $booking->custom_fields ) ? $booking->custom_fields : array();
285
+
286
+ foreach( $fields as $field ) {
287
+
288
+ if ( $field->type == 'fieldset' || !isset( $cf[ $field->slug ] ) ) {
289
+ continue;
290
+ }
291
+
292
+ $val = $cf[ $field->slug ];
293
+ $display_val = apply_filters( 'cffrtb_display_value_mpdf', $rtb_controller->fields->get_display_value( $val, $field, '', true ), $val, $field, $booking );
294
+
295
+ ?>
296
+
297
+ <p class="custom-field <?php echo esc_attr( $field->type . ' ' . $field->slug ); ?>">
298
+ <span class="label"><?php echo esc_html( $field->title ) . esc_html_x( ': ', 'Appears after field label in mPDF exports', 'custom-fields-for-rtb' ); ?></span>
299
+ <?php echo $display_val ?>
300
+ </p>
301
+
302
+ <?php
303
+ }
304
+ }
305
+
306
+ }
307
+ } // endif
includes/Export.class.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'ebfrtbExport' ) ) {
5
+ /**
6
+ * Base class to handle exports
7
+ *
8
+ * @since 1.4.1
9
+ */
10
+ abstract class ebfrtbExport {
11
+
12
+ /**
13
+ * Bookings
14
+ *
15
+ * @since 0.1
16
+ */
17
+ public $bookings;
18
+
19
+ /**
20
+ * Export
21
+ *
22
+ * A fully-rendered export ready for delivery
23
+ *
24
+ * @since 0.1
25
+ */
26
+ public $export;
27
+
28
+ /**
29
+ * Instantiate the export
30
+ *
31
+ * @since 0.1
32
+ */
33
+ abstract function __construct( $bookings, $args = array() );
34
+
35
+ /**
36
+ * Render the export file
37
+ *
38
+ * The export should be constructed and compiled here,
39
+ * then stored in $export for retrieval and returned.
40
+ *
41
+ * @since 0.1
42
+ */
43
+ abstract function export();
44
+
45
+ /**
46
+ * Deliver the export file by printing it to the buffer
47
+ *
48
+ * @since 0.1
49
+ */
50
+ abstract function deliver();
51
+
52
+ /**
53
+ * Locate a template file
54
+ *
55
+ * @since 0.1
56
+ */
57
+ public function locate_template( $file ) {
58
+
59
+ $template_dirs = apply_filters(
60
+ 'ebfrtb_template_directories',
61
+ array(
62
+ get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'ebfrtb-templates', // Child theme
63
+ get_template_directory() . DIRECTORY_SEPARATOR . 'ebfrtb-templates', // Parent theme
64
+ RTB_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'templates', // Plugin dir
65
+ )
66
+ );
67
+
68
+ foreach( $template_dirs as $dir ) {
69
+ if ( file_exists( $dir . DIRECTORY_SEPARATOR . $file ) ) {
70
+ return $dir . DIRECTORY_SEPARATOR . $file;
71
+ }
72
+ }
73
+
74
+ return false;
75
+ }
76
+
77
+ /**
78
+ * Include a template file
79
+ *
80
+ * @since 0.1
81
+ */
82
+ public function include_template( $file ) {
83
+
84
+ $template = $this->locate_template( $file );
85
+
86
+ if ( empty( $template ) ) {
87
+ return;
88
+ }
89
+
90
+ global $rtb_controller;
91
+ $bookings = $this->bookings;
92
+ include( $template );
93
+ }
94
+
95
+ /**
96
+ * Generate a string representing the date range
97
+ * for this export (if it exists )
98
+ *
99
+ * @since 0.1
100
+ */
101
+ public function get_date_phrase() {
102
+
103
+ if ( empty( $this->query_args['date_range'] ) ) {
104
+ return '';
105
+ }
106
+
107
+ if ( $this->query_args['date_range'] === 'today' || $this->query_args['date_range'] === 'upcoming' ) {
108
+ $date = date( get_option( 'date_format' ) );
109
+
110
+ if ( $this->query_args['date_range'] === 'today' ) {
111
+ return sprintf( _x( 'Bookings for %s', 'Subject for some export documents', 'restaurant-reservations' ), $date );
112
+ } else {
113
+ return sprintf( _x( "Bookings from %s", 'Subject for some export documents', 'restaurant-reservations' ), $date );
114
+ }
115
+ }
116
+
117
+ if ( !empty( $this->query_args['start_date'] ) || !empty( $this->query_args['end_date'] ) ) {
118
+ $any_date = _x( '*', 'No date limit in a date range, eg 2014-* would mean any date from 2014 or after', 'restaurant-reservations' );
119
+ $start_date = empty( $this->query_args['start_date'] ) ? $any_date : mysql2date( get_option( 'date_format' ), $this->query_args['start_date'] . ' 00:00:00' );
120
+ $end_date = empty( $this->query_args['end_date'] ) ? $any_date : mysql2date( get_option( 'date_format' ), $this->query_args['end_date'] . ' 00:00:00' );
121
+
122
+ return sprintf( $start_date . _x( ' - ', 'Separator between two dates in a date range to be used in exports', 'restaurant-reservations' ) . $end_date );
123
+ }
124
+
125
+ return '';
126
+ }
127
+
128
+ }
129
+ } // endif
includes/ExportHandler.class.php ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) )
3
+ exit;
4
+
5
+ if ( !class_exists( 'rtbExportHandler' ) ) {
6
+ class rtbExportHandler {
7
+
8
+ /**
9
+ * Registered exports
10
+ *
11
+ * @since 0.1
12
+ */
13
+ public $export_types;
14
+
15
+
16
+ /**
17
+ * Initialize the class and register hooks
18
+ */
19
+ public function __construct() {
20
+
21
+ // Admin notices
22
+ add_action( 'admin_notices', array( $this, 'make_mpdf_dir_writable' ) );
23
+
24
+ // Register available exports
25
+ add_action( 'admin_init', array( $this, 'register_exports' ) );
26
+
27
+ // Load an export file
28
+ add_action( 'admin_init', array( $this, 'load_export' ) );
29
+
30
+ // Load bookings page and assets
31
+ add_action( 'rtb_bookings_table_actions', array( $this, 'print_button' ) );
32
+ add_action( 'admin_footer-toplevel_page_rtb-bookings', array( $this, 'print_export_options_modal' ), 9 );
33
+
34
+ }
35
+
36
+ /**
37
+ * Add an admin notice if the font directory for mpdf is not
38
+ * writeable
39
+ *
40
+ * @since 0.1
41
+ */
42
+ public function make_mpdf_dir_writable() {
43
+
44
+ global $rtb_controller;
45
+ if ( empty( $rtb_controller ) or ! $rtb_controller->permissions->check_permission( 'export' ) ) {
46
+ return;
47
+ }
48
+
49
+ // Only trigger a warning when using the mpdf library
50
+ if ( $rtb_controller->settings->get_setting( 'ebfrtb-pdf-lib' ) !== 'mpdf' ) {
51
+ return;
52
+ }
53
+
54
+
55
+ // No warning needed if the directory is writable
56
+ if ( wp_is_writable( RTB_PLUGIN_DIR . '/lib/mpdf/ttfontdata/' ) ) {
57
+ return;
58
+ }
59
+
60
+
61
+ $rtb_settings_link = '<a href="' . admin_url( 'admin.php?page=rtb-settings&tab=rtb-export' ) . '">' . _x( 'export settings', 'Name of a link to the Export tab on the settings page', 'restaurant-reservations' ) . '</a>';
62
+ ?>
63
+
64
+ <div class="error">
65
+ <p>
66
+ <?php printf( __( 'Warning from Export Bookings for Restaurant Reservations: The server is not able to write to the font directory for the mPDF generator. Your PDF exports may not work properly until you change the file permissions for the directory /wp-content/plugins/export-for-rtb/lib/mpdf/ttfontdata/. Your web host can help you change the file permissions to be compatible. Or you can switch to the TCPDF renderer in the %s.', 'restaurant-reservations' ), $rtb_settings_link ); ?>
67
+ </p>
68
+ </div>
69
+
70
+ <?php
71
+ }
72
+
73
+ /**
74
+ * Register supported exports
75
+ *
76
+ * @since 0.1
77
+ */
78
+ public function register_exports() {
79
+
80
+ // Load the export classes
81
+ require_once( RTB_PLUGIN_DIR . '/includes/Export.class.php' );
82
+ require_once( RTB_PLUGIN_DIR . '/includes/Export.PDF.class.php' );
83
+ require_once( RTB_PLUGIN_DIR . '/includes/Export.CSV.class.php' );
84
+
85
+ // Array of export types and the class which should be used
86
+ // to generate them. All classes should extend ebfrtbExport
87
+ // @todo Excel
88
+ $this->export_types = apply_filters(
89
+ 'ebfrtb_export_types',
90
+ array(
91
+ 'pdf' => array(
92
+ 'label' => __( 'PDF', 'restaurant-reservations' ),
93
+ 'class' => 'ebfrtbExportPDF',
94
+ ),
95
+ 'csv' => array(
96
+ 'label' => __( 'Excel/CSV', 'restaurant-reservations' ),
97
+ 'class' => 'ebfrtbExportCSV',
98
+ ),
99
+ )
100
+ );
101
+
102
+ }
103
+
104
+ /**
105
+ * Load the requested export
106
+ *
107
+ * @since 0.1
108
+ */
109
+ public function load_export() {
110
+ global $rtb_controller;
111
+
112
+ if (! $rtb_controller->permissions->check_permission( 'export' ) ) { return; }
113
+
114
+ if ( !isset( $_GET['action'] ) || $_GET['action'] !== 'ebfrtb-export' ) {
115
+ return;
116
+ }
117
+
118
+ if ( !current_user_can( 'manage_bookings' ) ) {
119
+ wp_die( __( 'You do not have the required permissions to export bookings.', 'restaurant-reservations' ) );
120
+ }
121
+
122
+ if ( isset( $_GET['type'] ) && !empty( $this->export_types[ $_GET['type'] ] ) ) {
123
+ $export_class = $this->export_types[ $_GET['type'] ]['class'];
124
+ }
125
+
126
+ if ( !isset( $export_class ) || !class_exists( $export_class ) ) {
127
+ wp_die( __( 'Unable to create export to match your request.', 'restaurant-reservations' ) );
128
+ }
129
+
130
+ // Prepare query args
131
+ $query = new rtbQuery( array(), 'export' );
132
+ $query->parse_request_args();
133
+ $query->prepare_args();
134
+ $query->args['posts_per_page'] = -1;
135
+
136
+ // Show an error if they forgot to enter dates
137
+ if ( isset( $query->args['date_range'] ) && $query->args['date_range'] == 'dates' && !isset( $query->args['start_date'] ) && empty( $query->args['end_date'] ) ) {
138
+ wp_die( __( "You selected a date range but didn't enter a start or end date. Please return and enter a start or end date.", 'restaurant-reservations' ) );
139
+ }
140
+
141
+ // Retrieve bookings
142
+ $bookings = $query->get_bookings();
143
+
144
+ if ( empty( $bookings ) ) {
145
+ wp_die( __( 'There are no bookings which match your export request.', 'restaurant-reservations' ) );
146
+ }
147
+
148
+ $export = new $export_class( $bookings, array( 'query_args' => $query->args ) );
149
+ $export->deliver(); // calls wp_die()
150
+ }
151
+
152
+ /**
153
+ * Print the export button above and below the table
154
+ *
155
+ * @since 0.1.0
156
+ */
157
+ public function print_button( $pos ) {
158
+ global $rtb_controller;
159
+
160
+ if (! $rtb_controller->permissions->check_permission( 'export' ) ) { return; }
161
+
162
+ ?>
163
+
164
+ <div class="alignleft actions ebfrtb-actions">
165
+ <a href="#" class="button ebfrtb-export-button">
166
+ <span class="dashicons dashicons-media-spreadsheet"></span>
167
+ <?php esc_html_e( 'Export Bookings', 'restaurant-reservations' ); ?>
168
+ </a>
169
+ </div>
170
+
171
+ <?php
172
+ }
173
+
174
+ /**
175
+ * Print the export options modal in the footer
176
+ * of the bookings page
177
+ *
178
+ * @since 0.1
179
+ */
180
+ public function print_export_options_modal() {
181
+
182
+ global $rtb_controller;
183
+
184
+ if (! $rtb_controller->permissions->check_permission( 'export' ) ) { return; }
185
+ ?>
186
+
187
+ <!-- Export bookings options modal -->
188
+ <div id="ebfrtb-options-modal" class="rtb-admin-modal">
189
+ <div class="ebfrtb-options-form rtb-container">
190
+ <form>
191
+
192
+ <div class="title">
193
+ <h2>
194
+ <?php esc_html_e( 'Export Bookings', 'restaurant-reservations' ); ?>
195
+ </h2>
196
+ </div>
197
+
198
+ <fieldset>
199
+ <div class="type">
200
+ <label for="type" class="hidden-label">
201
+ <?php esc_html_e( 'Type', 'restaurant-reservations' ); ?>
202
+ </label>
203
+ <select name="type">
204
+ <?php foreach( $this->export_types as $type => $export ) : ?>
205
+ <option value="<?php echo esc_attr( $type ); ?>"><?php echo $export['label']; ?></option>
206
+ <?php endforeach; ?>
207
+ </select>
208
+ </div>
209
+
210
+ <?php if ( !empty( $rtb_controller->locations ) && !empty( $rtb_controller->locations->post_type ) ) : ?>
211
+ <div class="location">
212
+ <label for="location" class="hidden-label">
213
+ <?php esc_html_e( 'Location', 'restaurant-reservations' ); ?>
214
+ </label>
215
+ <select name="location">
216
+ <option value=""><?php esc_html_e( 'All locations', 'restaurant-reservations' ); ?></option>
217
+ <?php
218
+ $locations = $rtb_controller->locations->get_location_options();
219
+ foreach( $locations as $id => $name ) :
220
+ ?>
221
+ <option value="<?php echo absint( $id ); ?>"><?php echo esc_attr( $name ); ?></option>
222
+ <?php
223
+ endforeach;
224
+ ?>
225
+ </select>
226
+ </div>
227
+ <?php endif; ?>
228
+
229
+ <div class="date-range">
230
+ <input type="hidden" name="date_range">
231
+ <label for="date-range" class="hidden-label">
232
+ <?php esc_html_e( 'Date Range', 'restaurant-reservations' ); ?>
233
+ </label>
234
+ <div class="selector">
235
+ <ul class="options">
236
+ <li>
237
+ <a href="#" data-type="today">
238
+ <?php esc_html_e( 'Today', 'restaurant-reservations' ); ?>
239
+ </a>
240
+ </li>
241
+ <li>
242
+ <a href="#" data-type="upcoming">
243
+ <?php esc_html_e( 'Upcoming', 'restaurant-reservations' ); ?>
244
+ </a>
245
+ </li>
246
+ <li>
247
+ <a href="#" data-type="dates">
248
+ <?php esc_html_e( 'Date Range', 'restaurant-reservations' ); ?>
249
+ </a>
250
+ </li>
251
+ </ul>
252
+ <div class="today">
253
+ <?php esc_html_e( "Today's bookings", 'restaurant-reservations' ); ?>
254
+ </div>
255
+ <div class="upcoming">
256
+ <?php esc_html_e( 'All upcoming bookings', 'restaurant-reservations' ); ?>
257
+ </div>
258
+ <div class="dates">
259
+ <div class="date-start">
260
+ <label for="ebfrtb-start-date">
261
+ <?php esc_html_e( 'Start', 'restaurant-reservations' ); ?>
262
+ </label>
263
+ <input type="text" name="start_date" id="ebfrtb-start-date">
264
+ </div>
265
+ <div class="date-end">
266
+ <label for="ebfrtb-end-date">
267
+ <?php esc_html_e( 'End', 'restaurant-reservations' ); ?>
268
+ </label>
269
+ <input type="text" name="end_date" id="ebfrtb-end-date">
270
+ </div>
271
+ </div>
272
+ </div>
273
+ </div>
274
+
275
+ <div class="status">
276
+ <?php foreach( $rtb_controller->cpts->booking_statuses as $key => $status ) : ?>
277
+ <label>
278
+ <input type="checkbox" name="status" value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, 'confirmed' ); ?>>
279
+ <?php echo $status['label']; ?>
280
+ </label>
281
+ <?php endforeach; ?>
282
+ </div>
283
+
284
+ </fieldset>
285
+ <button type="submit" class="button button-primary">
286
+ <?php esc_html_e( 'Export', 'restaurant-reservations' ); ?>
287
+ </button>
288
+ <a href="#" class="button" id="ebfrtb-cancel-export-modal">
289
+ <?php esc_html_e( 'Cancel', 'restaurant-reservations' ); ?>
290
+ </a>
291
+ <a href="<?php echo admin_url( 'admin.php?page=rtb-settings&tab=rtb-export' ); ?>" class="settings">
292
+ <?php esc_html_e( 'Settings', 'restaurant-reservations' ); ?>
293
+ </a>
294
+ </form>
295
+ </div>
296
+ </div>
297
+
298
+ <?php
299
+ }
300
+
301
+ }
302
+ } // endif;
includes/Field.Controller.class.php ADDED
@@ -0,0 +1,784 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbFieldController' ) ) {
5
+ /**
6
+ * Controller class to generate, store and retrieve custom fields.
7
+ *
8
+ * @since 0.1
9
+ */
10
+ class rtbFieldController {
11
+
12
+ /**
13
+ * System fields
14
+ *
15
+ * @since 0.1
16
+ */
17
+ public $system_fields;
18
+
19
+ /**
20
+ * Default fields
21
+ *
22
+ * @var array
23
+ * @since 0.1
24
+ */
25
+ public $default_fields;
26
+
27
+ /**
28
+ * Valid field types
29
+ *
30
+ * @since 0.1
31
+ */
32
+ public $valid_field_types;
33
+
34
+
35
+ /**
36
+ * Markup for a checkbox icon used to display results
37
+ *
38
+ * @param string checkbox_icon
39
+ * @since 0.1
40
+ */
41
+ public $checkbox_icon;
42
+
43
+ /**
44
+ * Go!
45
+ *
46
+ * @since 0.1
47
+ */
48
+ public function __construct() {
49
+
50
+ // Store default fields
51
+ add_filter( 'rtb_booking_form_fields', array( $this, 'get_default_fields' ), 1, 2 );
52
+
53
+ // Modify fields based on modified options array
54
+ add_filter( 'rtb_booking_form_fields', array( $this, 'modify_form_fields' ), 20, 2 );
55
+
56
+ // Modify bookings table columns
57
+ add_filter( 'rtb_bookings_table_columns', array( $this, 'modify_bookings_columns' ) );
58
+ add_filter( 'rtb_bookings_all_table_columns', array( $this, 'modify_all_bookings_columns' ) );
59
+ add_filter( 'rtb_bookings_table_column', array( $this, 'add_custom_column_value' ), 10, 3 );
60
+ }
61
+
62
+ /**
63
+ * Store the default form fields before anyone has hooked in to
64
+ * change them
65
+ *
66
+ * @since 0.1
67
+ */
68
+ public function get_default_fields( $fields, $request ) {
69
+
70
+ $this->default_fields = $fields;
71
+
72
+ return $fields;
73
+ }
74
+
75
+ /**
76
+ * Retrieve a field from the fields array
77
+ *
78
+ * @since 0.1
79
+ */
80
+ public function get_nested_field( $slug, $fields ) {
81
+
82
+ foreach( $fields as $fieldset_slug => $fieldset ) {
83
+ if ( array_key_exists( $slug, $fieldset['fields'] ) ) {
84
+ return $fieldset['fields'][ $slug ];
85
+ }
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Get a field by it's slug when passed an array of field objects
91
+ *
92
+ * @since 0.1
93
+ */
94
+ public function get_field_in_array( $slug, $fields ) {
95
+
96
+ foreach( $fields as $field ) {
97
+ if ( $field->slug === $slug ) {
98
+ return $field;
99
+ }
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Get system fields and fieldsets
105
+ *
106
+ * @note these fields should have limited options for editing
107
+ * because they play a critical role in the plugin or are
108
+ * managed elsewhere.
109
+ * @since 0.1
110
+ */
111
+ public function get_system_fields() {
112
+
113
+ $this->system_fields = apply_filters(
114
+ 'cffrtb_system_fields',
115
+ array(
116
+ 'location',
117
+ 'date',
118
+ 'time',
119
+ 'party',
120
+ 'name',
121
+ 'email',
122
+ )
123
+ );
124
+
125
+ $this->system_fieldsets = apply_filters(
126
+ 'cffrtb_system_fieldsets',
127
+ array(
128
+ 'reservation',
129
+ )
130
+ );
131
+ }
132
+
133
+ /**
134
+ * Default values for a field object
135
+ *
136
+ * @since 0.1
137
+ */
138
+ public function get_default_field_values() {
139
+
140
+ if ( !empty( $this->default_values ) ) {
141
+ return $this->default_values;
142
+ }
143
+
144
+ $defaults = array(
145
+ 'type' => 'text',
146
+ 'subtype' => 'text',
147
+ 'label' => __( 'Field', 'custom-fields-for-rtb' ),
148
+ 'slug' => null,
149
+ 'required' => false,
150
+ );
151
+
152
+ $this->default_values = apply_filters( 'cffrtb_default_field_values', $defaults );
153
+
154
+ return $this->default_values;
155
+ }
156
+
157
+ /**
158
+ * Get valid field types
159
+ *
160
+ * @since 0.1
161
+ */
162
+ public function get_valid_field_types() {
163
+
164
+ if( !empty( $this->valid_field_types ) ) {
165
+ return $this->valid_field_types;
166
+ }
167
+
168
+ $field_types = array(
169
+ 'text' => array(
170
+ 'title' => __( 'Text', 'custom-fields-for-rtb' ),
171
+ 'subtypes' => array(
172
+ 'text' => array(
173
+ 'title' => __( 'Small', 'custom-fields-for-rtb' ),
174
+ 'callback' => 'rtb_print_form_text_field',
175
+ ),
176
+ 'textarea' => array(
177
+ 'title' => __( 'Large', 'custom-fields-for-rtb' ),
178
+ 'callback' => 'rtb_print_form_textarea_field',
179
+ ),
180
+ )
181
+ ),
182
+ 'options' => array(
183
+ 'title' => __( 'Options', 'custom-fields-for-rtb' ),
184
+ 'subtypes' => array(
185
+ 'select' => array(
186
+ 'title' => __( 'Dropdown', 'custom-fields-for-rtb' ),
187
+ 'callback' => 'rtb_print_form_select_field',
188
+ ),
189
+ 'checkbox' => array(
190
+ 'title' => __( 'Checkbox', 'custom-fields-for-rtb' ),
191
+ 'callback' => 'rtb_print_form_checkbox_field',
192
+ ),
193
+ 'radio' => array(
194
+ 'title' => __( 'Radio', 'custom-fields-for-rtb' ),
195
+ 'callback' => 'rtb_print_form_radio_field',
196
+ ),
197
+ ),
198
+ ),
199
+ 'confirm' => array(
200
+ 'title' => __( 'Confirm', 'custom-fields-for-rtb' ),
201
+ 'subtypes' => array(
202
+ 'confirm' => array(
203
+ 'title' => __( 'Confirm', 'custom-fields-for-rtb' ),
204
+ 'callback' => 'rtb_print_form_confirm_field',
205
+ ),
206
+ )
207
+ )
208
+ );
209
+
210
+ $this->valid_field_types = apply_filters( 'cffrtb_valid_field_types', $field_types );
211
+
212
+ return $this->valid_field_types;
213
+ }
214
+
215
+ /**
216
+ * Get the callback function for a field type
217
+ *
218
+ * @since 0.1
219
+ */
220
+ public function get_callback_function( $type, $subtype ) {
221
+
222
+ $types = $this->get_valid_field_types();
223
+
224
+ // Safe fallback
225
+ if ( empty( $types[ $type ] ) || empty( $types[ $type ]['subtypes'][ $subtype ] ) ) {
226
+ return 'rtb_print_form_text_field';
227
+ }
228
+
229
+ return $this->valid_field_types[ $type ]['subtypes'][ $subtype ]['callback'];
230
+ }
231
+
232
+ /**
233
+ * Modify fields based on modified options array
234
+ *
235
+ * @todo this does not handle disabled fields or fieldsets yet
236
+ * @since 0.1
237
+ */
238
+ public function modify_form_fields( $fields, $request ) {
239
+ global $rtb_controller;
240
+
241
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
242
+
243
+ // Strip out a location field when it has been saved to the modified option,
244
+ // but the multi-locations feature is no longer enabled.
245
+ if ( !empty( $modified['location'] ) && !$rtb_controller->locations->post_type ) {
246
+ unset( $modified['location'] );
247
+ }
248
+
249
+ $fields_query = new WP_Query( array( 'post_type' => 'cffrtb_field', 'post_status' => 'publish', 'posts_per_page' => 1000 ) );
250
+
251
+ if ( empty( $modified ) && !$fields_query->have_posts() ) {
252
+ wp_reset_query();
253
+ return $fields;
254
+ }
255
+
256
+ // Add custom fields
257
+ global $post;
258
+ while( $fields_query->have_posts() ) {
259
+ $fields_query->the_post();
260
+
261
+ $meta = get_post_meta( get_the_ID(), 'cffrtb', true );
262
+
263
+ if ( $meta['type'] == 'fieldset' ) {
264
+
265
+ $pre_existing_fields = !empty( $fields[ $post->post_name ] ) && !empty( $fields[ $post->post_name ]['fields'] ) ? $fields[ $post->post_name ]['fields'] : array();
266
+
267
+ $fields[ $post->post_name ] = array(
268
+ 'legend' => get_the_title(),
269
+ 'order' => $post->menu_order,
270
+ 'fields' => $pre_existing_fields,
271
+ 'ID' => get_the_ID(),
272
+ );
273
+
274
+ continue;
275
+
276
+ }
277
+
278
+ if ( empty( $meta['fieldset'] ) ) {
279
+ end( $fields );
280
+ $meta['fieldset'] = key( $fields );
281
+ reset( $fields );
282
+ }
283
+
284
+ if ( empty( $fields[ $meta['fieldset'] ] ) ) {
285
+ $fields[ $meta['fieldset'] ] = array( 'fields' => array() );
286
+ }
287
+
288
+ $fields[ $meta['fieldset'] ]['fields'][ $post->post_name ] = array(
289
+ 'title' => get_the_title(),
290
+ 'request_input' => rtb_get_request_input( $post->post_name, $request ),
291
+ 'callback' => $this->get_callback_function( $meta['type'], $meta['subtype'] ),
292
+ 'required' => !empty( $meta['required'] ),
293
+ 'order' => $post->menu_order,
294
+ 'ID' => get_the_ID(),
295
+ );
296
+
297
+ if ( !empty( $meta['options'] ) ) {
298
+ $fields[ $meta['fieldset'] ]['fields'][ $post->post_name ]['callback_args'] = array(
299
+ 'options' => $this->format_option_field_values( $meta['options'] ),
300
+ );
301
+ }
302
+ }
303
+
304
+ // Disable default fields
305
+ if ( !empty( $modified ) ) {
306
+ $orphans = array();
307
+ $disabled = array();
308
+ foreach( $modified as $slug => $item ) {
309
+
310
+ if ( empty( $item['fieldset'] ) ) {
311
+ continue;
312
+ }
313
+
314
+ if ( !empty( $item['disabled'] ) ) {
315
+
316
+ // Disable a fieldset and store any orphaned fields
317
+ if ( $item['fieldset'] == $slug ) {
318
+ if ( isset( $fields[ $slug ] ) ) {
319
+ $orphans = array_merge( $orphans, $fields[ $slug ]['fields'] );
320
+ unset( $fields[ $slug ] );
321
+ }
322
+
323
+ // Find and disable a field
324
+ } else {
325
+ foreach( $fields as $fieldset_slug => $fieldset ) {
326
+ if ( array_key_exists( $slug, $fieldset['fields'] ) ) {
327
+ unset( $fields[ $fieldset_slug ]['fields'][ $slug ] );
328
+ $disabled[] = $slug;
329
+ break;
330
+ }
331
+ }
332
+ }
333
+
334
+ $disabled[] = $slug;
335
+ }
336
+ }
337
+
338
+ // Add any orphan'd fields into an extra fieldset so they can be
339
+ // moved
340
+ if ( count( $orphans ) ) {
341
+ $fields['cffrtb-extra-fields'] = array(
342
+ 'fields' => $orphans
343
+ );
344
+ }
345
+
346
+ // Remove disabled fields from the $modified array so we're
347
+ // no longer messing with them
348
+ foreach( $disabled as $slug ) {
349
+ unset( $modified[$slug] );
350
+ }
351
+
352
+ // Move default fields
353
+ foreach( $modified as $slug => $item ) {
354
+
355
+ if ( empty( $item['fieldset'] ) || $item['fieldset'] == $slug ) {
356
+ continue;
357
+ }
358
+
359
+ // Field exists in fieldset - doesn't need to be moved
360
+ if ( !empty( $fields[ $item['fieldset'] ] ) && !empty( $fields[ $item['fieldset'] ]['fields'][ $slug ] ) ) {
361
+ continue;
362
+
363
+ // Field needs to be moved
364
+ } else {
365
+
366
+ if ( empty( $fields[ $item['fieldset'] ] ) ) {
367
+ $fields[ $item['fieldset'] ] = array(
368
+ 'fields' => array()
369
+ );
370
+ }
371
+
372
+ // Find, copy and then remove the existing field
373
+ foreach( $fields as $fieldset_slug => $fieldset ) {
374
+ if ( array_key_exists( $slug, $fieldset['fields'] ) ) {
375
+ $fields[ $item['fieldset'] ]['fields'][ $slug ] = $fieldset['fields'][ $slug ];
376
+ unset( $fields[ $fieldset_slug ]['fields'][ $slug ] );
377
+ break;
378
+ }
379
+ }
380
+ }
381
+ }
382
+
383
+ // Modify default titles for fields and fieldsets and add order
384
+ foreach( $modified as $slug => $field ) {
385
+
386
+ if ( empty( $field['fieldset'] ) ) {
387
+ continue; // @todo this suggests an error in the data
388
+ }
389
+
390
+ // Fieldset
391
+ if ( $slug == $field['fieldset'] ) {
392
+
393
+ if ( !empty( $field['title'] ) ) {
394
+ $fields[ $slug ]['legend'] = $field['title'];
395
+ }
396
+
397
+ if ( array_key_exists( 'order', $field ) ) {
398
+ $fields[ $slug ]['order'] = $field['order'];
399
+ }
400
+
401
+ // Field
402
+ } else {
403
+
404
+ if ( !empty( $field['title'] ) ) {
405
+ $fields[ $field['fieldset'] ]['fields'][ $slug ]['title'] = $field['title'];
406
+ }
407
+
408
+ if ( array_key_exists( 'order', $field ) ) {
409
+ $fields[ $field['fieldset'] ]['fields'][ $slug ]['order'] = $field['order'];
410
+ }
411
+ }
412
+ }
413
+ }
414
+
415
+ // Remove the extra fieldset if it has been created but is no
416
+ // longer used
417
+ if ( isset( $fields['cffrtb-extra-fields'] ) && empty( $fields['cffrtb-extra=fields']['fields'] ) ) {
418
+ unset( $fields['cffrtb-extra-fields'] );
419
+ }
420
+
421
+ // Sort the fieldsets and fields by order
422
+ $first = reset( $fields );
423
+ if ( isset( $first['order'] ) ) {
424
+ uasort( $fields, array( $this, 'sort_by_order' ) );
425
+ foreach( $fields as $slug => $fieldset ) {
426
+
427
+ // Sort fields in fieldset
428
+ if ( isset( $fields[ $slug ]['fields'] ) ) {
429
+ uasort( $fields[ $slug ]['fields'], array( $this, 'sort_by_order' ) );
430
+
431
+ // Pass an empty array of fields in the fieldset to reduce
432
+ // chance of unwanted PHP notices in 3rd party code
433
+ } else {
434
+ $fields[ $slug ]['fields'] = array();
435
+ }
436
+ }
437
+ }
438
+
439
+ wp_reset_query();
440
+
441
+ return $fields;
442
+ }
443
+
444
+ /**
445
+ * Sort an associative array by the value's order parameter
446
+ *
447
+ * @usedby self::modify_form_fields()
448
+ * @since 0.1
449
+ */
450
+ public function sort_by_order( $a, $b ) {
451
+
452
+ if ( empty( $a['order'] ) ) {
453
+ $a['order'] = 0;
454
+ }
455
+
456
+ if ( empty( $b['order'] ) ) {
457
+ // This prevents it from changing the sort order of fields
458
+ // or fieldsets that have an identical order number. It
459
+ // could interfere with other ordering routines, but it
460
+ // should only really be an issue with rare third-party
461
+ // manipulations of the $fields array, which define or load
462
+ // order values in unexpected ways.
463
+ $b['order'] = $a['order']++;
464
+ }
465
+
466
+ return $a['order'] - $b['order'];
467
+ }
468
+
469
+ /**
470
+ * Format option field values in order to pass them to a select field
471
+ * callback. Should be assoc array of key/value pairs
472
+ *
473
+ * @since 0.1
474
+ */
475
+ public function format_option_field_values( $options ) {
476
+
477
+ // Don't show disabled options
478
+ $options = array_filter( $options, array( $this, 'filter_active_option' ) );
479
+
480
+ $formatted = array();
481
+ foreach( $options as $key => $option ) {
482
+
483
+ // Store key for fields that were generated before the change in
484
+ // version 1.1, when the key represented the field id
485
+ if ( !isset( $option['id'] ) ) {
486
+ $option['id'] = $key;
487
+ }
488
+
489
+ $formatted[ $option['id'] ] = $option['value'];
490
+ }
491
+
492
+ return $formatted;
493
+ }
494
+
495
+ /**
496
+ * Filter an option based on its disabled state. To be used in `array_filter`
497
+ *
498
+ * @since 0.1
499
+ */
500
+ public function filter_active_option( $option ) {
501
+ return empty( $option['disabled'] );
502
+ }
503
+
504
+ /**
505
+ * Convert a custom field value to its display value
506
+ *
507
+ * @since 0.1
508
+ */
509
+ public function get_display_value( $val, $field, $checkbox_icon = '', $use_html = true ) {
510
+
511
+ $display_val = '';
512
+
513
+ // Checkboxes
514
+ if ( $field->type == 'options' && is_array( $val ) ) {
515
+ $display_vals = array();
516
+ foreach( $val as $val_i ) {
517
+ if ( isset( $field->options[ $val_i ] ) ) {
518
+ $display_vals[] = esc_html( $this->get_option_val_by_id( $val_i, $field->options ) );
519
+ }
520
+ }
521
+
522
+ if ( $use_html ) {
523
+ $display_val = '<ul><li>' . $checkbox_icon . join( '</li><li>' . $checkbox_icon, $display_vals ) . '</li></ul>';
524
+ } else {
525
+ $display_val = join( esc_html_x( ', ', 'separator between two selected options', 'custom-fields-for-rtb' ), $display_vals );
526
+ }
527
+
528
+ // Select/radio fields
529
+ } elseif ( $field->type == 'options' ) {
530
+ $display_val = esc_html( $this->get_option_val_by_id( $val, $field->options ) );
531
+
532
+ // Confirmation checkboxes
533
+ } elseif ( $field->type == 'confirm' ) {
534
+ $display_val = apply_filters( 'cffrtb_confirm_checkmark', sprintf( __( '%s Checked', 'custom-fields-for-rtb' ), $checkbox_icon ), $val, $field );
535
+
536
+ // Text fields
537
+ } else {
538
+ $display_val = esc_html( $val );
539
+ }
540
+
541
+ return $display_val;
542
+ }
543
+
544
+ /**
545
+ * Retrieve a booking's custom field values in a sorted array ready to be
546
+ * displayed in markup
547
+ *
548
+ * @since 0.1
549
+ */
550
+ public function get_booking_fields_display_array( $booking ) {
551
+ global $rtb_controller;
552
+
553
+ if ( !isset( $booking->custom_fields ) ) {
554
+ return array();
555
+ }
556
+
557
+ $fields = rtb_get_custom_fields();
558
+
559
+ $checkbox_icon = $this->get_checkbox_icon();
560
+
561
+ $return = array();
562
+ foreach( $booking->custom_fields as $slug => $val ) {
563
+ $field = $rtb_controller->fields->get_field_in_array( $slug, $fields );
564
+ $return[] = $this->get_booking_field_display_array( $field, $slug, $val, $checkbox_icon, $booking );
565
+ }
566
+
567
+ uasort( $return, array( $this, 'sort_by_order' ) );
568
+
569
+ return $return;
570
+ }
571
+
572
+ /**
573
+ * Retrieve a custom field's value
574
+ *
575
+ * @since 1.5
576
+ */
577
+ public function get_booking_field_display_array( $field, $slug, $val, $checkbox_icon, $booking ) {
578
+
579
+ // If the field is no longer available, let's try to fall
580
+ // back to something kind of meaningful
581
+ if ( empty( $field ) ) {
582
+ $title = $slug;
583
+ $display_val = $val;
584
+ $classes = array( $slug );
585
+ $order = 9999; // after everything else!
586
+
587
+ // Otherwise let's get good display values
588
+ } else {
589
+ $title = $field->title;
590
+ $display_val = apply_filters( 'cffrtb_display_value_admin_list', $this->get_display_value( $val, $field, $checkbox_icon ), $val, $field, $booking );
591
+ $classes = array($slug, $field->type, $field->subtype );
592
+ $order = $field->order;
593
+ }
594
+
595
+ return array(
596
+ 'title' => $title,
597
+ 'display_val' => $display_val,
598
+ 'classes' => $classes,
599
+ 'order' => $order,
600
+ );
601
+ }
602
+
603
+ /**
604
+ * Retrieve an option value from array by its id
605
+ *
606
+ * @since 1.1
607
+ */
608
+ public function get_option_val_by_id( $id, $options ) {
609
+
610
+ foreach( $options as $key => $option ) {
611
+
612
+ // Store key for fields that were generated before the change in
613
+ // version 1.1, when the key represented the field id
614
+ if ( !isset( $option['id'] ) ) {
615
+ $option['id'] = $key;
616
+ }
617
+
618
+ if ( $option['id'] == $id ) {
619
+ return $option['value'];
620
+ }
621
+ }
622
+
623
+ return '';
624
+ }
625
+
626
+ /**
627
+ * Add custom fields to the array of all possible bookings columns
628
+ *
629
+ * @since 1.2
630
+ */
631
+ public function modify_all_bookings_columns( $columns ) {
632
+
633
+ $fields_query = new WP_Query( array( 'post_type' => 'cffrtb_field', 'post_status' => 'publish', 'posts_per_page' => 1000 ) );
634
+
635
+ if ( !$fields_query->have_posts() ) {
636
+ wp_reset_query();
637
+ return $columns;
638
+ }
639
+
640
+ global $post;
641
+ while( $fields_query->have_posts() ) {
642
+ $fields_query->the_post();
643
+
644
+ if ( isset( $columns[ $post->post_name ] ) ) {
645
+ continue;
646
+ }
647
+
648
+ $meta = get_post_meta( get_the_ID(), 'cffrtb', true );
649
+ if ( $meta['type'] == 'fieldset' ) {
650
+ continue;
651
+ }
652
+
653
+ $columns[ $post->post_name ] = $post->post_title;
654
+ }
655
+
656
+ wp_reset_query();
657
+
658
+ return $columns;
659
+ }
660
+
661
+ /**
662
+ * Add columns for custom fields that have been enabled
663
+ *
664
+ * @since 1.2
665
+ */
666
+ public function modify_bookings_columns( $columns ) {
667
+ global $rtb_controller;
668
+
669
+ // Change names of default columns if they've been edited
670
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
671
+ if ( !empty( $modified ) ) {
672
+ foreach( $modified as $field_key => $field ) {
673
+ if ( isset( $columns[$field_key] ) && !empty( $field['title'] ) ) {
674
+ $columns[$field_key] = $field['title'];
675
+ }
676
+ }
677
+ }
678
+
679
+ global $rtb_controller;
680
+ $visible_columns = $rtb_controller->settings->get_setting( 'bookings-table-columns' );
681
+ if ( empty( $visible_columns ) ) {
682
+ return $columns;
683
+ }
684
+
685
+ $fields_query = new WP_Query( array( 'post_type' => 'cffrtb_field', 'post_status' => 'publish', 'posts_per_page' => 1000 ) );
686
+
687
+ if ( !$fields_query->have_posts() ) {
688
+ wp_reset_query();
689
+ return $columns;
690
+ }
691
+
692
+ global $post;
693
+ while( $fields_query->have_posts() ) {
694
+ $fields_query->the_post();
695
+
696
+ if ( !in_array( $post->post_name, $visible_columns ) ) {
697
+ continue;
698
+ }
699
+
700
+ $columns[ $post->post_name ] = $post->post_title;
701
+ }
702
+
703
+ wp_reset_query();
704
+
705
+ // Keep the details column last
706
+ // Only exists in rtb v1.5+
707
+ if ( isset( $columns['details'] ) ) {
708
+ $details = $columns['details'];
709
+ unset( $columns['details'] );
710
+ $columns['details'] = $details;
711
+ }
712
+
713
+
714
+ return $columns;
715
+ }
716
+
717
+ /**
718
+ * Print custom fields in a custom column in the bookings list table
719
+ *
720
+ * @since 0.1
721
+ */
722
+ public function add_custom_column_value( $value, $booking, $column_name ) {
723
+ global $rtb_controller;
724
+
725
+ if ( empty( $booking->custom_fields ) || !isset( $booking->custom_fields[$column_name] ) ) {
726
+ return $value;
727
+ }
728
+
729
+ $fields = rtb_get_custom_fields();
730
+ $field = $rtb_controller->fields->get_field_in_array( $column_name, $fields );
731
+ $checkbox_icon = $this->get_checkbox_icon();
732
+ $field_data = $this->get_booking_field_display_array( $field, $field->slug, $booking->custom_fields[$column_name], $checkbox_icon, $booking );
733
+
734
+ return $value . $field_data['display_val'];
735
+ }
736
+
737
+ /**
738
+ * Add custom fields output to details column
739
+ *
740
+ * @since 1.5
741
+ */
742
+ public function add_fields_to_details_panel( $details, $booking ) {
743
+ global $rtb_controller;
744
+
745
+ if ( !isset( $booking->custom_fields ) || empty( $booking->custom_fields ) ) {
746
+ return $details;
747
+ }
748
+
749
+ global $rtb_controller;
750
+ $visible_columns = $rtb_controller->settings->get_setting( 'bookings-table-columns' );
751
+ if ( !is_array( $visible_columns ) ) {
752
+ return $details;
753
+ }
754
+
755
+ $fields = rtb_get_custom_fields();
756
+ foreach( $booking->custom_fields as $slug => $val ) {
757
+
758
+ // Skip fields with their own columns
759
+ if ( in_array( $slug, $visible_columns ) ) {
760
+ continue;
761
+ }
762
+
763
+ $field = $rtb_controller->fields->get_field_in_array( $slug, $fields );
764
+ $checkbox_icon = $this->get_checkbox_icon();
765
+ $field_data = $this->get_booking_field_display_array( $field, $field->slug, $booking->custom_fields[$slug], $checkbox_icon, $booking );
766
+ $details[] = array(
767
+ 'label' => $field_data['title'],
768
+ 'value' => $field_data['display_val'],
769
+ );
770
+ }
771
+
772
+ return $details;
773
+ }
774
+
775
+ /**
776
+ * Retrieve checkbox icon markup
777
+ *
778
+ * @since 1.5
779
+ */
780
+ public function get_checkbox_icon() {
781
+ return is_string( $this->checkbox_icon ) ? $this->checkbox_icon : apply_filters( 'cffrtb_checkbox_icon', '<span class="dashicons dashicons-yes"></span> ' );
782
+ }
783
+ }
784
+ } // endif
includes/Field.class.php ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'cffrtbField' ) ) {
5
+ /**
6
+ * Field class to add, edit, save, update, validate and process a
7
+ * custom field added to the booking form.
8
+ *
9
+ * @since 0.1
10
+ */
11
+ class cffrtbField {
12
+
13
+ /**
14
+ * ID
15
+ *
16
+ * @since 0.1
17
+ */
18
+ public $ID;
19
+
20
+ /**
21
+ * Type
22
+ *
23
+ * eg - text, options, confirm
24
+ *
25
+ * @since 0.1
26
+ */
27
+ public $type;
28
+
29
+ /**
30
+ * Subtype
31
+ *
32
+ * eg - text/textarea, select/checkbox/radio, confirm
33
+ *
34
+ * @since 0.1
35
+ */
36
+ public $subtype;
37
+
38
+ /**
39
+ * Label
40
+ *
41
+ * @since 0.1
42
+ */
43
+ public $title;
44
+
45
+ /**
46
+ * Slug
47
+ *
48
+ * @since 0.1
49
+ */
50
+ public $slug;
51
+
52
+ /**
53
+ * Required
54
+ *
55
+ * @since 0.1
56
+ */
57
+ public $required;
58
+
59
+ /**
60
+ * Fieldset
61
+ *
62
+ * @since 0.1
63
+ */
64
+ public $fieldset;
65
+
66
+ /**
67
+ * Order of the field in its fieldset
68
+ *
69
+ * @since 0.1
70
+ */
71
+ public $order;
72
+
73
+ /**
74
+ * Options (used in some field types)
75
+ *
76
+ * @since 0.1
77
+ */
78
+ public $options;
79
+
80
+ /**
81
+ * Post status
82
+ *
83
+ * @since 0.1
84
+ */
85
+ public $status;
86
+
87
+ /**
88
+ * Get it started
89
+ *
90
+ * @since 0.1
91
+ */
92
+ public function __construct( $args = array() ) {
93
+
94
+ // Load from the db if an ID is passed
95
+ if ( !empty( $args['ID'] ) ) {
96
+ $args = array_merge( $this->load_from_db( $args['ID'] ), $args );
97
+ }
98
+
99
+ // Set up the field object
100
+ $this->setup_field( $args );
101
+
102
+ }
103
+
104
+ /**
105
+ * Load an object based on the arguments passed
106
+ *
107
+ * @since 0.1
108
+ */
109
+ public function load_from_db( $id ) {
110
+
111
+ $post = get_post( $id, 'ARRAY_A' );
112
+
113
+ $post['title'] = $post['post_title'];
114
+ $post['slug'] = $post['post_name'];
115
+ $post['order'] = $post['menu_order'];
116
+ $post['status'] = $post['post_status'];
117
+
118
+ $post_meta = get_post_meta( $id, 'cffrtb', true );
119
+
120
+ if( !empty( $post_meta['type'] ) ) { $post['type'] = $post_meta['type']; }
121
+ if( !empty( $post_meta['subtype'] ) ) { $post['subtype'] = $post_meta['subtype']; }
122
+ if( !empty( $post_meta['required'] ) ) { $post['required'] = $post_meta['required']; }
123
+ if( !empty( $post_meta['fieldset'] ) ) { $post['fieldset'] = $post_meta['fieldset']; }
124
+ if( !empty( $post_meta['options'] ) ) { $post['options'] = $post_meta['options']; }
125
+
126
+ return $post;
127
+ }
128
+
129
+ /**
130
+ * Set up a new field object
131
+ *
132
+ * @since 0.1
133
+ */
134
+ public function setup_field( $args ) {
135
+ global $rtb_controller;
136
+
137
+ // Use defaults for missing args
138
+ $args = array_merge( $rtb_controller->fields->get_default_field_values(), $args );
139
+
140
+ // Set up the object
141
+ $this->ID = empty( $args['ID'] ) ? null : (int) $args['ID'];
142
+ $this->type = empty( $args['type'] ) ? $this->get_valid_type( '' ) : $this->get_valid_type( $args['type'] );
143
+ $this->subtype = empty( $args['subtype'] ) ? $this->get_valid_subtype( '' ) : $this->get_valid_subtype( $args['subtype'] );
144
+ $this->title = empty( $args['title'] ) ? null : sanitize_text_field( $args['title'] );
145
+ $this->slug = empty( $args['slug'] ) ? null : sanitize_key( $args['slug'] );
146
+ $this->required = empty( $args['required'] ) ? false : (bool) $args['required'];
147
+ $this->fieldset = empty( $args['fieldset'] ) ? null : sanitize_key( $args['fieldset'] );
148
+ $this->order = empty( $args['order'] ) ? null : (int) $args['order'];
149
+ $this->options = empty( $args['options'] ) ? null : $this->get_valid_options( $args['options'] );
150
+ $this->status = empty( $args['status'] ) ? 'publish' : sanitize_key( $args['status'] );
151
+
152
+ do_action( 'cffrtb_setup_field_object', $this, $args );
153
+ }
154
+
155
+ /**
156
+ * Check if type is valid
157
+ *
158
+ * @since 0.1
159
+ */
160
+ public function is_valid_type( $type ) {
161
+ global $rtb_controller;
162
+
163
+ $types = $rtb_controller->fields->get_valid_field_types();
164
+ return !empty( $type ) && array_key_exists( $type, $types );
165
+ }
166
+
167
+ /**
168
+ * Return a valid type. Falls back to default if specified type is
169
+ * not valid. Also allows a `fieldset` type to pass
170
+ *
171
+ * @since 0.1
172
+ */
173
+ public function get_valid_type( $type ) {
174
+ global $rtb_controller;
175
+
176
+ if ( $type == 'fieldset' ) {
177
+ return $type;
178
+ }
179
+
180
+ if ( $this->is_valid_type( $type ) ) {
181
+ return $type;
182
+ }
183
+
184
+ $defaults = $rtb_controller->fields->get_default_field_values();
185
+ return $defaults['type'];
186
+ }
187
+
188
+ /**
189
+ * Return a valid subtype. Falls back to first subtype of type if
190
+ * subtype is not valid.
191
+ *
192
+ * @since 0.1
193
+ */
194
+ public function get_valid_subtype( $subtype ) {
195
+ global $rtb_controller;
196
+
197
+ if( $subtype == 'fieldset' ) {
198
+ return $subtype;
199
+ }
200
+
201
+ $types = $rtb_controller->fields->get_valid_field_types();
202
+ if ( array_key_exists( $subtype, $types[ $this->type ]['subtypes'] ) ) {
203
+ return $subtype;
204
+ }
205
+
206
+ reset( $types[ $this->type ][ 'subtypes' ] );
207
+
208
+ return key( $types[ $this->type ][ 'subtypes' ] );
209
+ }
210
+
211
+ /**
212
+ * Sanitize options
213
+ *
214
+ * @since 0.1
215
+ */
216
+ public function get_valid_options( $options ) {
217
+ global $rtb_controller;
218
+
219
+ $new_options = array();
220
+ foreach( $options as $key => $option ) {
221
+
222
+ // Store key for fields that were generated before the change in
223
+ // version 1.1, when the key represented the field id
224
+ if ( !isset( $option['id'] ) ) {
225
+ $option['id'] = $key;
226
+ }
227
+
228
+ $new_options[] = array(
229
+ 'id' => substr( $option['id'], 0, 3 ) == 'new' ? sanitize_text_field( $option['id'] ) : absint( $option['id'] ),
230
+ 'value' => isset( $option['value'] ) ? sanitize_text_field( $option['value'] ) : '',
231
+ 'disabled' => empty( $option['disabled'] ) ? false : true,
232
+ // An order param may not exist if the option was created in an
233
+ // earlier version of the plugin
234
+ 'order' => isset( $option['order'] ) ? absint( $option['order'] ) : 0,
235
+ );
236
+ }
237
+
238
+ usort( $new_options, array( $rtb_controller->fields, 'sort_by_order' ) );
239
+
240
+ return $new_options;
241
+ }
242
+
243
+ /**
244
+ * Prepare an options array for input as `post_meta`
245
+ *
246
+ * Each option must have a unique, permanent ID. If no ID exists, create a
247
+ * unique ID
248
+ *
249
+ * @since 0.1
250
+ */
251
+ public function prepare_options_input() {
252
+
253
+ // Load existing options
254
+ $options = array();
255
+ if ( !empty( $this->ID ) ) {
256
+ $meta = get_post_meta( $this->ID, 'cffrtb', true );
257
+ if ( isset( $meta['options'] ) ) {
258
+ $options = $meta['options'];
259
+ }
260
+ }
261
+
262
+ // Disable options that are no longer available
263
+ foreach( $options as $i => $option ) {
264
+
265
+ // Store key for fields that were generated before the change in
266
+ // version 1.1, when the key represented the field id
267
+ if ( !isset( $option['id'] ) ) {
268
+ $option['id'] = $i;
269
+ }
270
+
271
+ $exists = false;
272
+ foreach( $this->options as $new_option ) {
273
+ if ( $new_option['id'] == $option['id'] ) {
274
+ $exists = true;
275
+ break;
276
+ }
277
+ }
278
+
279
+ if ( !$exists ) {
280
+ $options[$i]['disabled'] = true;
281
+ }
282
+ }
283
+
284
+ // Generate new options array with properly assigned IDs for new options
285
+ $i = count( $options );
286
+ foreach( $this->options as $key => $option ) {
287
+ if ( substr( $option['id'], 0, 3 ) == 'new' ) {
288
+ $option['id'] = $i;
289
+ $i++;
290
+ }
291
+ $options[$key] = $option;
292
+ }
293
+
294
+ return $options;
295
+ }
296
+
297
+ /**
298
+ * Check if this field has an id
299
+ *
300
+ * @since 0.1
301
+ */
302
+ public function has_id() {
303
+ return !empty( $this->ID );
304
+ }
305
+
306
+ /**
307
+ * Check if an option is valid
308
+ *
309
+ * @since 0.1
310
+ */
311
+ public function is_valid_option( $value ) {
312
+
313
+ if ( !is_array( $this->options ) ) {
314
+ return false;
315
+ }
316
+
317
+ return array_key_exists( $value, $this->options );
318
+ }
319
+
320
+ /**
321
+ * Save the label of this field
322
+ *
323
+ * @since 0.1
324
+ */
325
+ public function save_label() {
326
+ global $rtb_controller;
327
+
328
+ // A default field shouldn't be saved as a custom field post
329
+ // type. Instead we need to overwrite the label for the slug.
330
+ if ( !$this->has_id() ) {
331
+
332
+ if ( empty( $this->slug ) ) {
333
+ return array(
334
+ false,
335
+ array(
336
+ 'error' => 'missing_slug',
337
+ 'msg' => __( 'No field slug was sent with this request to update a default field.', 'custom-fields-for-rtb' ) . ' ' . $rtb_controller->custom_fields->common_error_msg,
338
+ 'data' => array( 'field' => $field, 'post_vars' => $_POST )
339
+ )
340
+ );
341
+ }
342
+
343
+ $modified = get_option( $rtb_controller->custom_fields->modified_option_key );
344
+
345
+ $new = $modified;
346
+
347
+ if ( empty( $new ) ) {
348
+ $new = array();
349
+ }
350
+
351
+ if ( empty( $new[ $this->slug ] ) ) {
352
+ $new[ $this->slug ] = array();
353
+ }
354
+
355
+ $new[ $this->slug ][ 'title'] = $this->title;
356
+ $new[ $this->slug ][ 'fieldset'] = $this->fieldset;
357
+
358
+ if ( update_option( $rtb_controller->custom_fields->modified_option_key, $new ) ) {
359
+ return array(
360
+ true,
361
+ array(
362
+ 'field' => $this
363
+ )
364
+ );
365
+
366
+ } else {
367
+
368
+ /**
369
+ * update_option() returns false if the new option is
370
+ * the same as the old option, so let's check if that's
371
+ * why we got a false response and send out a true
372
+ * response if there's no error with the save process.
373
+ */
374
+ $same = true;
375
+
376
+ if ( empty( $modified ) || empty( $modified[ $this->slug ] ) ) {
377
+ $same = false;
378
+ }
379
+
380
+ if ( ( isset( $modified[ $this->slug ]['title'] ) && $modified[ $this->slug ]['title'] !== $this->title ) ||
381
+ ( !isset( $modified[ $this->slug ]['title'] ) && !empty( $this->title ) ) ) {
382
+ $same = false;
383
+ }
384
+
385
+ if ( empty( $modified[ $this->slug ]['fieldset'] ) || $modified[ $this->slug ]['fieldset'] !== $this->fieldset ) {
386
+ $same = false;
387
+ }
388
+
389
+ if ( $same ) {
390
+ return array(
391
+ true,
392
+ array(
393
+ 'field' => $this
394
+ )
395
+ );
396
+
397
+ } else {
398
+ return array(
399
+ false,
400
+ array(
401
+ 'error' => 'save_failed',
402
+ 'msg' => __( 'An error occurred while updating the label for this default field. Please try again.', 'custom-fields-for-rtb' ),
403
+ 'field' => $this,
404
+ 'option' => $new,
405
+ )
406
+ );
407
+ }
408
+ }
409
+
410
+ // Custom field
411
+ } else {
412
+
413
+ $field = array(
414
+ 'ID' => $this->ID,
415
+ 'post_title' => $this->title,
416
+ );
417
+
418
+ if ( wp_update_post( $field ) ) {
419
+ return array(
420
+ true,
421
+ array(
422
+ 'title' => get_the_title( $this->ID ),
423
+ )
424
+ );
425
+
426
+ } else {
427
+ return array(
428
+ false,
429
+ array(
430
+ 'error' => 'save_failed',
431
+ 'msg' => __( 'An error occurred while updating the label for this custom field. Please try again.', 'custom-fields-for-rtb' ),
432
+ 'field' => $this,
433
+ )
434
+ );
435
+ }
436
+ }
437
+ }
438
+
439
+ /**
440
+ * Save a field
441
+ *
442
+ * @since 0.1
443
+ */
444
+ public function save_field() {
445
+ global $rtb_controller;
446
+
447
+ if ( empty( $this->title ) || empty( $this->type ) || ( $this->type !== 'fieldset' && empty( $this->subtype ) ) ) {
448
+ return array(
449
+ false,
450
+ array(
451
+ 'error' => 'missing_data',
452
+ 'msg' => __( 'This field could not be saved because required data was missing.', 'custom-fields-for-rtb' ),
453
+ 'field' => $this,
454
+ )
455
+ );
456
+ }
457
+
458
+ $post = array(
459
+ 'post_title' => $this->title,
460
+ 'post_type' => 'cffrtb_field',
461
+ 'post_status' => $this->status,
462
+ );
463
+ if ( $this->has_id() ) { $post['ID'] = $this->ID; }
464
+ if ( !empty( $this->slug ) ) { $post['post_name'] = $this->slug; }
465
+ if ( !empty( $this->order ) ) { $post['menu_order'] = $this->order; }
466
+
467
+ $post = apply_filters( 'cffrtb_insert_field_data', $post, $this );
468
+
469
+ $id = wp_insert_post( $post );
470
+ if ( is_wp_error( $id ) || empty( $id ) ) {
471
+ return array(
472
+ false,
473
+ array(
474
+ 'error' => 'save_post_failed',
475
+ 'msg' => __( 'An error occurred while saving this field. Please try again. If the problem persists, please refresh the page.', 'custom-fields-for-rtb' ),
476
+ 'field' => $this,
477
+ 'wp_error' => $id
478
+ )
479
+ );
480
+ }
481
+
482
+ $is_new_field = !$this->has_id();
483
+
484
+ $this->ID = $id;
485
+
486
+ $post_item = get_post( $id );
487
+ $this->title = get_the_title( $id );
488
+ $this->slug = $post_item->post_name;
489
+
490
+ $post_meta = array(
491
+ 'type' => $this->type,
492
+ );
493
+ if ( !empty( $this->subtype ) ) { $post_meta['subtype'] = $this->subtype; }
494
+ if ( !empty( $this->required ) ) { $post_meta['required'] = $this->required; }
495
+ if ( !empty( $this->fieldset ) ) { $post_meta['fieldset'] = $this->fieldset; }
496
+ if ( !empty( $this->options ) && $this->type == 'options' ) { $post_meta['options'] = $this->prepare_options_input(); }
497
+
498
+ $post_meta = apply_filters( 'cffrtb_insert_field_metadata', $post_meta, $this );
499
+
500
+ update_post_meta( $id, 'cffrtb', $post_meta );
501
+
502
+ $field = array(
503
+ 'ID' => $this->ID,
504
+ 'title' => $this->title,
505
+ );
506
+
507
+ if ( $this->type == 'fieldset' ) {
508
+ $type = 'fieldset';
509
+ $field['legend'] = $this->title;
510
+ } else {
511
+ $type = 'field';
512
+ }
513
+
514
+ return array(
515
+ true,
516
+ array(
517
+ 'ID' => $this->ID,
518
+ 'is_new_field' => $is_new_field,
519
+ 'field' => $rtb_controller->editor->print_field( $this->slug, $field, $type ),
520
+ 'type' => $this->type,
521
+ )
522
+ );
523
+ }
524
+
525
+ /**
526
+ * Validate the input for a field
527
+ *
528
+ * @since 0.1
529
+ */
530
+ public function validate_input( $booking ) {
531
+
532
+ // Don't validate fieldsets
533
+ if ( $this->type === 'fieldset' ) {
534
+ return;
535
+ }
536
+
537
+ // Instantiate the custom fields array if it's missing
538
+ if ( !isset( $booking->custom_fields ) ) {
539
+ $booking->custom_fields = array();
540
+ }
541
+
542
+ $input = isset( $_POST['rtb-' . $this->slug ] ) ? $_POST['rtb-' . $this->slug] : '';
543
+
544
+ // Skip empty fields
545
+ // required checks are performed by base plugin validation
546
+ if ( ( is_string( $input ) && trim( $input ) == '' ) ||
547
+ ( is_array( $input ) && empty( $input ) ) ) {
548
+ return;
549
+ }
550
+
551
+ // Option fields
552
+ if ( $this->type == 'options' ) {
553
+
554
+ if ( !is_array( $input ) ) {
555
+ $input = array( $input );
556
+ }
557
+
558
+ foreach( $input as $input_i ) {
559
+ if ( !$this->is_valid_option( $input_i ) ) {
560
+ $booking->validation_errors[] = array(
561
+ 'field' => $this->slug,
562
+ 'post_variable' => $input,
563
+ 'message' => __( 'The option you selected is not valid. Please make another choice.', 'custom-fields-for-rtb' )
564
+ );
565
+
566
+ return;
567
+ }
568
+ }
569
+
570
+ if ( $this->subtype === 'select' || $this->subtype === 'radio' ) {
571
+ $val = absint( $input[0] );
572
+ if ( isset( $this->options[ $val ] ) ) {
573
+ $booking->custom_fields[ $this->slug ] = $val;
574
+ }
575
+ } elseif ( $this->subtype === 'checkbox' ) {
576
+ $val = array_map( 'absint', $input );
577
+ $new_val = array();
578
+ foreach( $val as $i ) {
579
+ if ( isset( $this->options[ $i ] ) ) {
580
+ $new_val[] = $i;
581
+ }
582
+ }
583
+ $booking->custom_fields[ $this->slug ] = $new_val;
584
+ }
585
+
586
+ // Confirm fields (always true if we've reached this stage)
587
+ } elseif ( $this->type === 'confirm' ) {
588
+ $booking->custom_fields[ $this->slug ] = true;
589
+
590
+ // Text fields just need to be sanitized
591
+ } elseif ( $this->type === 'text' ) {
592
+ $booking->custom_fields[ $this->slug ] = sanitize_text_field( $input );
593
+ }
594
+ }
595
+
596
+ }
597
+ } // endif;
includes/Import.class.php ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class to import bookings from a spreadsheet
5
+ */
6
+
7
+ if ( !defined( 'ABSPATH' ) )
8
+ exit;
9
+
10
+ if (!class_exists('ComposerAutoloaderInit4618f5c41cf5e27cc7908556f031e4d4')) {require_once FDM_PLUGIN_DIR . '/lib/PHPSpreadsheet/vendor/autoload.php';}
11
+ use PhpOffice\PhpSpreadsheet\Spreadsheet;
12
+ class rtbImport {
13
+
14
+ /**
15
+ * Hook suffix for the page
16
+ *
17
+ * @since 0.1
18
+ */
19
+ public $hook_suffix;
20
+
21
+ /**
22
+ * The success/error message content
23
+ *
24
+ * @since 0.1
25
+ */
26
+ public $status;
27
+
28
+ /**
29
+ * Whether the operation was a success or not
30
+ *
31
+ * @since 0.1
32
+ */
33
+ public $message;
34
+
35
+ public function __construct() {
36
+ add_action( 'admin_menu', array($this, 'register_install_screen' ));
37
+
38
+ if ( isset( $_POST['rtbImport'] ) ) { add_action( 'admin_init', array($this, 'import_bookings' )); }
39
+
40
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_import_scripts' ) );
41
+ }
42
+
43
+ public function register_install_screen() {
44
+ $this->hook_suffix = add_submenu_page(
45
+ 'rtb-bookings',
46
+ _x( 'Import', 'Title of the Imports page', 'restaurant-reservations' ),
47
+ _x( 'Import', 'Title of Imports link in the admin menu', 'restaurant-reservations' ),
48
+ 'manage_options',
49
+ 'rtb-imports',
50
+ array( $this, 'display_editor_page' )
51
+ );
52
+
53
+ // Print the error modal and enqueue assets
54
+ add_action( 'load-' . $this->hook_suffix, array( $this, 'enqueue_admin_assets' ) );
55
+ }
56
+
57
+ public function display_import_screen() {
58
+ global $rtb_controller;
59
+
60
+ $import_permission = $rtb_controller->permissions->check_permission( 'import' );
61
+ ?>
62
+ <div class='wrap'>
63
+ <h2>Import</h2>
64
+ <?php if ( $import_permission ) { ?>
65
+ <form method='post' enctype="multipart/form-data">
66
+ <p>
67
+ <label for="rtb_bookings_spreadsheet"><?php _e("Spreadsheet Containing Bookings", 'restaurant-reservations') ?></label><br />
68
+ <input name="rtb_bookings_spreadsheet" type="file" value=""/>
69
+ </p>
70
+ <input type='submit' name='rtbImport' value='Import Bookings' class='button button-primary' />
71
+ </form>
72
+ <?php } else { ?>
73
+ <div class='rtb-premium-locked'>
74
+ <a href="https://www.fivestarplugins.com/license-payment/?Selected=RTB&Quantity=1" target="_blank">Upgrade</a> to the premium version to use this feature
75
+ </div>
76
+ <?php } ?>
77
+ </div>
78
+ <?php }
79
+
80
+ public function import_bookings() {
81
+ global $rtb_controller;
82
+
83
+ $fields = $rtb_controller->settings->get_booking_form_fields();
84
+
85
+ $update = $this->handle_spreadsheet_upload();
86
+
87
+ if ( $update['message_type'] != 'Success' ) :
88
+ $this->status = false;
89
+ $this->message = $update['message'];
90
+
91
+ add_action( 'admin_notices', array( $this, 'display_notice' ) );
92
+
93
+ return;
94
+ endif;
95
+
96
+ $excel_url = RTB_PLUGIN_DIR . '/user-sheets/' . $update['filename'];
97
+
98
+ // Build the workbook object out of the uploaded spreadsheet
99
+ $spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($excel_url);
100
+
101
+ // Create a worksheet object out of the product sheet in the workbook
102
+ $sheet = $spreadsheet->getActiveSheet();
103
+
104
+ $allowable_fields = array();
105
+ foreach ($fields as $field) {$allowable_fields[] = $field->name;}
106
+ //List of fields that can be accepted via upload
107
+ //$allowed_fields = array("ID", "Title", "Description", "Price", "Sections");
108
+
109
+
110
+ // Get column names
111
+ $highest_column = $sheet->getHighestColumn();
112
+ $highest_column_index = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($highest_column);
113
+ for ($column = 1; $column <= $highest_column_index; $column++) {
114
+ /*if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "ID") {$ID_column = $column;}
115
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Title") {$title_column = $column;}
116
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Description") {$description_column = $column;}
117
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Price") {$price_column = $column;}
118
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == "Sections") {$sections_column = $column;}*/
119
+
120
+ foreach ($fields as $key => $field) {
121
+ if (trim($sheet->getCellByColumnAndRow($column, 1)->getValue()) == $field->name) {$field->column = $column;}
122
+ }
123
+ }
124
+
125
+
126
+ // Put the spreadsheet data into a multi-dimensional array to facilitate processing
127
+ $highest_row = $sheet->getHighestRow();
128
+ for ($row = 2; $row <= $highest_row; $row++) {
129
+ for ($column = 1; $column <= $highest_column_index; $column++) {
130
+ $data[$row][$column] = $sheet->getCellByColumnAndRow($column, $row)->getValue();
131
+ }
132
+ }
133
+
134
+ // Create the query to insert the products one at a time into the database and then run it
135
+ foreach ($data as $booking) {
136
+ // Create an array of the values that are being inserted for each order,
137
+ // edit if it's a current order, otherwise add it
138
+ foreach ($booking as $col_index => $value) {
139
+ if ($col_index == $ID_column and $ID_column !== null) {$post['ID'] = esc_sql($value);}
140
+ if ($col_index == $title_column and $title_column !== null) {$post['post_title'] = esc_sql($value);}
141
+ if ($col_index == $description_column and $description_column !== null) {$post['post_content'] = esc_sql($value);}
142
+ if ($col_index == $price_column and $price_column !== null) {$post_prices = explode(",", esc_sql($value));}
143
+ if (isset($sections_column) and $col_index == $sections_column and $sections_column !== null) {$post_sections = explode(",", esc_sql($value));}
144
+ }
145
+
146
+ if (!is_array($post_prices)) {$post_prices = array();}
147
+ if (!is_array($post_sections)) {$post_sections = array();}
148
+
149
+ if ($post['post_title'] == '') {continue;}
150
+
151
+ $post['post_status'] = 'publish';
152
+ $post['post_type'] = 'fdm-menu-item';
153
+
154
+ if ( isset( $post['ID'] ) and $post['ID'] != '') { $post_id = wp_update_post($post); }
155
+ else { $post_id = wp_insert_post($post); }
156
+
157
+ if ( $post_id != 0 ) {
158
+ foreach ( $post_sections as $section ) {
159
+ $menu_section = term_exists($section, 'fdm-menu-section');
160
+ if ( $menu_section !== 0 && $menu_section !== null ) { $menu_section_ids[] = (int) $menu_section['term_id']; }
161
+ }
162
+ if ( isset($menu_section_ids) and is_array($menu_section_ids) ) { wp_set_object_terms($post_id, $menu_section_ids, 'fdm-menu-section'); }
163
+
164
+ update_post_meta( $post_id, 'fdm_item_price', implode(",", $post_prices) );
165
+
166
+ $field_values = array();
167
+ foreach ( $fields as $field ) {
168
+ if (isset($field->column) and isset($menu_item[$field->column])) {
169
+ $field_values[$field->slug] = esc_sql($menu_item[$field->column]);
170
+
171
+ }
172
+ }
173
+ update_post_meta($post_id, '_fdm_menu_item_custom_fields', $field_values);
174
+ }
175
+
176
+ unset($post);
177
+ unset($post_sections);
178
+ unset($menu_section_ids);
179
+ unset($post_prices);
180
+ unset($field_values);
181
+ }
182
+
183
+ $this->status = true;
184
+ $this->message = __("Menu items added successfully.", 'food-and-drink-menu');
185
+
186
+ add_action( 'admin_notices', array( $this, 'display_notice' ) );
187
+ }
188
+
189
+ function handle_spreadsheet_upload() {
190
+ /* Test if there is an error with the uploaded spreadsheet and return that error if there is */
191
+ if (!empty($_FILES['fdm_menu_items_spreadsheet']['error']))
192
+ {
193
+ switch($_FILES['fdm_menu_items_spreadsheet']['error'])
194
+ {
195
+
196
+ case '1':
197
+ $error = __('The uploaded file exceeds the upload_max_filesize directive in php.ini', 'food-and-drink-menu');
198
+ break;
199
+ case '2':
200
+ $error = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', 'food-and-drink-menu');
201
+ break;
202
+ case '3':
203
+ $error = __('The uploaded file was only partially uploaded', 'food-and-drink-menu');
204
+ break;
205
+ case '4':
206
+ $error = __('No file was uploaded.', 'food-and-drink-menu');
207
+ break;
208
+
209
+ case '6':
210
+ $error = __('Missing a temporary folder', 'food-and-drink-menu');
211
+ break;
212
+ case '7':
213
+ $error = __('Failed to write file to disk', 'food-and-drink-menu');
214
+ break;
215
+ case '8':
216
+ $error = __('File upload stopped by extension', 'food-and-drink-menu');
217
+ break;
218
+ case '999':
219
+ default:
220
+ $error = __('No error code avaiable', 'food-and-drink-menu');
221
+ }
222
+ }
223
+ /* Make sure that the file exists */
224
+ elseif (empty($_FILES['fdm_menu_items_spreadsheet']['tmp_name']) || $_FILES['fdm_menu_items_spreadsheet']['tmp_name'] == 'none') {
225
+ $error = __('No file was uploaded here..', 'food-and-drink-menu');
226
+ }
227
+ /* Move the file and store the URL to pass it onwards*/
228
+ /* Check that it is a .xls or .xlsx file */
229
+ if(!isset($_FILES['fdm_menu_items_spreadsheet']['name']) or (!preg_match("/\.(xls.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']) and !preg_match("/\.(csv.?)$/", $_FILES['fdm_menu_items_spreadsheet']['name']))) {
230
+ $error = __('File must be .csv, .xls or .xlsx', 'food-and-drink-menu');
231
+ }
232
+ else {
233
+ $filename = basename( $_FILES['fdm_menu_items_spreadsheet']['name']);
234
+ $filename = mb_ereg_replace("([^\w\s\d\-_~,;\[\]\(\).])", '', $filename);
235
+ $filename = mb_ereg_replace("([\.]{2,})", '', $filename);
236
+
237
+ //for security reason, we force to remove all uploaded file
238
+ $target_path = FDM_PLUGIN_DIR . "/user-sheets/";
239
+
240
+ $target_path = $target_path . $filename;
241
+
242
+ if (!move_uploaded_file($_FILES['fdm_menu_items_spreadsheet']['tmp_name'], $target_path)) {
243
+ $error .= "There was an error uploading the file, please try again!";
244
+ }
245
+ else {
246
+ $excel_file_name = $filename;
247
+ }
248
+ }
249
+
250
+ /* Pass the data to the appropriate function in Update_Admin_Databases.php to create the products */
251
+ if (!isset($error)) {
252
+ $update = array("message_type" => "Success", "filename" => $excel_file_name);
253
+ }
254
+ else {
255
+ $update = array("message_type" => "Error", "message" => $error);
256
+ }
257
+ return $update;
258
+ }
259
+
260
+ public function enqueue_import_scripts() {
261
+ $screen = get_current_screen();
262
+ if($screen->id == 'fdm-menu_page_fdm-import'){
263
+ wp_enqueue_style( 'fdm-admin', FDM_PLUGIN_URL . '/assets/css/admin.css', array(), '2.0.0' );
264
+ wp_enqueue_script( 'fdm-admin-js', FDM_PLUGIN_URL . '/assets/js/admin.js', array( 'jquery' ), '2.0.0', true );
265
+ }
266
+ }
267
+
268
+ public function display_notice() {
269
+ if ( $this->status ) {
270
+ echo "<div class='updated'><p>" . $this->message . "</p></div>";
271
+ }
272
+ else {
273
+ echo "<div class='error'><p>" . $this->message . "</p></div>";
274
+ }
275
+ }
276
+
277
+ }
278
+
279
+
includes/InstallationWalkthrough.class.php ADDED
@@ -0,0 +1,391 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class to handle everything related to the walk-through that runs on plugin activation
5
+ */
6
+
7
+ if ( !defined( 'ABSPATH' ) )
8
+ exit;
9
+
10
+ class rtbInstallationWalkthrough {
11
+
12
+ public function __construct() {
13
+ add_action( 'admin_menu', array($this, 'register_install_screen' ));
14
+ add_action( 'admin_head', array($this, 'hide_install_screen_menu_item' ));
15
+ add_action( 'admin_init', array($this, 'redirect'), 9999);
16
+
17
+ add_action('admin_head', array($this, 'admin_enqueue'));
18
+
19
+ add_action('wp_ajax_rtb_welcome_add_menu_page', array($this, 'add_reservations_page'));
20
+ add_action('wp_ajax_rtb_welcome_set_schedule', array($this, 'set_schedule'));
21
+ add_action('wp_ajax_rtb_welcome_set_options', array($this, 'set_options'));
22
+ }
23
+
24
+ public function redirect() {
25
+ if ( ! get_transient( 'rtb-getting-started' ) )
26
+ return;
27
+
28
+ delete_transient( 'rtb-getting-started' );
29
+
30
+ if ( is_network_admin() || isset( $_GET['activate-multi'] ) )
31
+ return;
32
+
33
+ $menu_items = get_posts(array('post_type' => 'menu-item'));
34
+ if (!empty($menu_items)) {
35
+ set_transient('rtb-admin-install-notice', true, 5);
36
+ return;
37
+ }
38
+
39
+ wp_safe_redirect( admin_url( 'index.php?page=rtb-getting-started' ) );
40
+ exit;
41
+ }
42
+
43
+ public function register_install_screen() {
44
+ add_dashboard_page(
45
+ esc_html__( 'Five-Star Restaurant Reservations - Welcome!', 'restaurant-reservations' ),
46
+ esc_html__( 'Five-Star Restaurant Reservations - Welcome!', 'restaurant-reservations' ),
47
+ 'manage_options',
48
+ 'rtb-getting-started',
49
+ array($this, 'display_install_screen')
50
+ );
51
+ }
52
+
53
+ public function hide_install_screen_menu_item() {
54
+ remove_submenu_page( 'index.php', 'rtb-getting-started' );
55
+ }
56
+
57
+ public function add_reservations_page() {
58
+ $reservations_page = wp_insert_post(array(
59
+ 'post_title' => (isset($_POST['reservations_page_title']) ? stripslashes_deep($_POST['reservations_page_title']) : ''),
60
+ 'post_content' => '',
61
+ 'post_status' => 'publish',
62
+ 'post_type' => 'page'
63
+ ));
64
+
65
+ if ( $reservations_page ) {
66
+ $rtb_options = get_option( 'rtb-settings' );
67
+ $rtb_options['booking-page'] = $reservations_page;
68
+ update_option( 'rtb-settings', $rtb_options );
69
+ }
70
+
71
+ exit();
72
+ }
73
+
74
+ public function set_schedule() {
75
+ $rtb_options = get_option( 'rtb-settings' );
76
+ $rtb_options['schedule-open'] = json_decode( stripslashes( $_POST['schedule_open'] ), true );
77
+ update_option( 'rtb-settings', $rtb_options );
78
+
79
+ exit();
80
+ }
81
+
82
+ public function set_options() {
83
+ $rtb_options = get_option( 'rtb-settings' );
84
+ $rtb_options['party-size-min'] = sanitize_text_field( $_POST['party_size_min'] );
85
+ $rtb_options['party-size'] = sanitize_text_field( $_POST['party_size'] );
86
+ $rtb_options['early-bookings'] = sanitize_text_field( $_POST['early_bookings'] );
87
+ $rtb_options['late-bookings'] = sanitize_text_field( $_POST['late_bookings'] );
88
+ $rtb_options['time-interval'] = sanitize_text_field( $_POST['time_interval'] );
89
+ update_option( 'rtb-settings', $rtb_options );
90
+
91
+ exit();
92
+ }
93
+
94
+ function admin_enqueue() {
95
+ wp_enqueue_style('rtb-admin-css', RTB_PLUGIN_URL . '/lib/simple-admin-pages/css/admin.css', array(), RTB_VERSION);
96
+ wp_enqueue_style('rtb-welcome-screen', RTB_PLUGIN_URL . '/assets/css/admin-rtb-welcome-screen.css', array(), RTB_VERSION);
97
+ wp_enqueue_style('pickadate-default', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/themes/default.css', array(), RTB_VERSION);
98
+ wp_enqueue_style('pickadate-date', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/themes/default.date.css', array(), RTB_VERSION);
99
+ wp_enqueue_style('pickadate-time', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/themes/default.time.css', array(), RTB_VERSION);
100
+
101
+ wp_enqueue_script('rtb-getting-started', RTB_PLUGIN_URL . '/assets/js/admin-rtb-welcome-screen.js', array('jquery'), RTB_VERSION);
102
+ wp_enqueue_script('pickadate', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/picker.js', array('jquery'), RTB_VERSION, true);
103
+ wp_enqueue_script('pickadate-date', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/picker.date.js', array('jquery'), RTB_VERSION, true);
104
+ wp_enqueue_script('pickadate-time', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/picker.time.js', array('jquery'), RTB_VERSION, true);
105
+ wp_enqueue_script('pickadate-legacy', RTB_PLUGIN_URL . '/lib/simple-admin-pages/lib/pickadate/legacy.js', array('jquery'), RTB_VERSION, true);
106
+ wp_enqueue_script('sap-scheduler', RTB_PLUGIN_URL . '/lib/simple-admin-pages/js/scheduler.js', array('jquery'), RTB_VERSION, true);
107
+
108
+ $sap_scheduler_settings[ 'schedule-open' ] = array(
109
+ 'time_interval' => 15,
110
+ 'time_format' => 'h:i A',
111
+ 'date_format' => 'd mmmm, yyyy',
112
+ 'template' => $this->get_template(),
113
+ 'weekdays' => array(
114
+ 'monday' => 'Mo',
115
+ 'tuesday' => 'Tu',
116
+ 'wednesday' => 'We',
117
+ 'thursday' => 'Th',
118
+ 'friday' => 'Fr',
119
+ 'saturday' => 'Sa',
120
+ 'sunday' => 'Su',
121
+ ),
122
+ 'weeks' => array(
123
+ 'first' => '1st',
124
+ 'second' => '2nd',
125
+ 'third' => '3rd',
126
+ 'fourth' => '4th',
127
+ 'last' => 'last',
128
+ ),
129
+ 'disable_weekdays' => false,
130
+ 'disable_weeks' => true,
131
+ 'disable_date' => true,
132
+ 'disable_time' => false,
133
+ 'disable_multiple' => false,
134
+ 'summaries' => array(
135
+ 'never' => __( 'Never', 'restaurant-reservations' ),
136
+ 'weekly_always' => __( 'Every day', 'restaurant-reservations' ),
137
+ 'monthly_weekdays' => sprintf( __( '%s on the %s week of the month', 'restaurant-reservations' ), '{days}', '{weeks}' ),
138
+ 'monthly_weeks' => sprintf( __( '%s week of the month', 'restaurant-reservations' ), '{weeks}' ),
139
+ 'all_day' => __( 'All day', 'restaurant-reservations' ),
140
+ 'before' => __( 'Ends at', 'restaurant-reservations' ),
141
+ 'after' => __( 'Starts at', 'restaurant-reservations' ),
142
+ 'separator' => __( '&mdash', 'restaurant-reservations' ),
143
+ ),
144
+ );
145
+
146
+ // This gets called multiple times, but only the last call is actually
147
+ // pushed to the script.
148
+ wp_localize_script(
149
+ 'sap-scheduler',
150
+ 'sap_scheduler',
151
+ array(
152
+ 'settings' => $sap_scheduler_settings
153
+ )
154
+ );
155
+ }
156
+
157
+ public function display_install_screen() { ?>
158
+ <div class='rtb-welcome-screen'>
159
+ <?php if (!isset($_GET['exclude'])) { ?>
160
+ <div class='rtb-welcome-screen-header'>
161
+ <h1><?php _e('Welcome to the Five-Star Restaurant Reservations Plugin', 'restaurant-reservations'); ?></h1>
162
+ <p><?php _e('Thanks for choosing the Five-Star Restaurant Reservations! The following will help you get started with the setup of your reservations system by creating your reservations page, setting times when bookings are allowed as well as configuring a few key options.', 'restaurant-reservations'); ?></p>
163
+ </div>
164
+ <?php } ?>
165
+
166
+ <div class='rtb-welcome-screen-box rtb-welcome-screen-reservations_page rtb-welcome-screen-open' data-screen='reservations_page'>
167
+ <h2><?php _e('1. Add a Reservations Page', 'restaurant-reservations'); ?></h2>
168
+ <div class='rtb-welcome-screen-box-content'>
169
+ <p><?php _e('You can create a dedicated reservations booking page below, or skip this step and add your reservations to a page you\'ve already created manually.', 'restaurant-reservations'); ?></p>
170
+ <div class='rtb-welcome-screen-menu-page'>
171
+ <div class='rtb-welcome-screen-add-reservations-page-name rtb-welcome-screen-box-content-divs'><label><?php _e('Page Title:', 'restaurant-reservations'); ?></label><input type='text' value='Reservations' /></div>
172
+ <div class='rtb-welcome-screen-add-reservations-page-button' data-nextaction='schedule_open'><?php _e('Create Page', 'restaurant-reservations'); ?></div>
173
+ </div>
174
+ <div class='rtb-welcome-screen-next-button rtb-welcome-screen-next-button-not-top-margin' data-nextaction='schedule_open'><?php _e('Next Step', 'restaurant-reservations'); ?></div>
175
+ <div class='clear'></div>
176
+ </div>
177
+ </div>
178
+
179
+ <div class='rtb-welcome-screen-box rtb-welcome-screen-schedule_open' data-screen='schedule_open'>
180
+ <h2><?php _e('2. Create Booking Schedule', 'restaurant-reservations'); ?></h2>
181
+ <div class='rtb-welcome-screen-box-content'>
182
+ <p><?php _e('Choose what times each week your restaurant is available to book reservations.', 'restaurant-reservations'); ?></p>
183
+ <div class='rtb-welcome-screen-created-schedule-open'>
184
+ <div class="sap-scheduler" id="schedule-open"></div>
185
+ <div class="sap-add-scheduler">
186
+ <a href="#" class="button">
187
+ <?php _e('Add new scheduling rule', 'restaurant-reservations' ); ?>
188
+ </a>
189
+ </div>
190
+ </div>
191
+ <div class='rtb-welcome-screen-save-schedule-open-button'><?php _e('Save Schedule', 'restaurant-reservations'); ?></div>
192
+ <div class="rtb-welcome-clear"></div>
193
+ <div class='rtb-welcome-screen-next-button' data-nextaction='options'><?php _e('Next Step', 'restaurant-reservations'); ?></div>
194
+ <div class='rtb-welcome-screen-previous-button' data-previousaction='reservations_page'><?php _e('Previous Step', 'restaurant-reservations'); ?></div>
195
+ <div class='clear'></div>
196
+ </div>
197
+ </div>
198
+
199
+ <div class='rtb-welcome-screen-box rtb-welcome-screen-options' data-screen='options'>
200
+ <h2><?php _e('3. Set Key Options', 'restaurant-reservations'); ?></h2>
201
+ <div class='rtb-welcome-screen-box-content'>
202
+ <p><?php _e('Set a min/max party size for bookings, choose how early and late bookings can be made, and pick the time interval between different booking options.', 'restaurant-reservations'); ?></p>
203
+ <div class='rtb-welcome-screen-option'>
204
+ <label><?php _e('Min Party Size:', 'restaurant-reservations'); ?></label>
205
+ <select name='min-party-size'>
206
+ <?php for ( $i = 1; $i <= 100; $i++ ) { ?>
207
+ <option value='<?php echo $i; ?>'><?php echo $i; ?></option>
208
+ <?php } ?>
209
+ </select>
210
+ </div>
211
+ <div class='rtb-welcome-screen-option'>
212
+ <label><?php _e('Max Party Size:', 'restaurant-reservations'); ?></label>
213
+ <select name='party-size'>
214
+ <option><?php _e('Any Size', 'restaurant-reservations' ); ?></option>
215
+ <?php for ( $i = 1; $i <= 100; $i++ ) { ?>
216
+ <option value='<?php echo $i; ?>'><?php echo $i; ?></option>
217
+ <?php } ?>
218
+ </select>
219
+ </div>
220
+ <div class='rtb-welcome-screen-option'>
221
+ <label><?php _e('Early Bookings:', 'restaurant-reservations'); ?></label>
222
+ <select name='early-bookings'>
223
+ <option><?php _e('Any Time', 'restaurant-reservations' ); ?></option>
224
+ <option value='1'><?php _e('From 1 day in advance', 'restaurant-reservations' ); ?></option>
225
+ <option value='7'><?php _e('From 1 week in advance', 'restaurant-reservations' ); ?></option>
226
+ <option value='14'><?php _e('From 2 weeks in advance', 'restaurant-reservations' ); ?></option>
227
+ <option value='30'><?php _e('From 30 days in advance', 'restaurant-reservations' ); ?></option>
228
+ <option value='90'><?php _e('From 90 days in advance', 'restaurant-reservations' ); ?></option>
229
+ </select>
230
+ </div>
231
+ <div class='rtb-welcome-screen-option'>
232
+ <label><?php _e('Late Bookings:', 'restaurant-reservations'); ?></label>
233
+ <select name='late-bookings'>
234
+ <option><?php _e('Up to the last minute', 'restaurant-reservations' ); ?></option>
235
+ <option value='15'><?php _e('At least 15 minutes in advance', 'restaurant-reservations' ); ?></option>
236
+ <option value='30'><?php _e('At least 30 minutes in advance', 'restaurant-reservations' ); ?></option>
237
+ <option value='45'><?php _e('At least 45 minutes in advance', 'restaurant-reservations' ); ?></option>
238
+ <option value='60'><?php _e('At least 1 hour in advance', 'restaurant-reservations' ); ?></option>
239
+ <option value='240'><?php _e('At least 4 hours in advance', 'restaurant-reservations' ); ?></option>
240
+ <option value='1440'><?php _e('At least 24 hours in advance', 'restaurant-reservations' ); ?></option>
241
+ <option value='same_day'><?php _e('Block same-day-bookings', 'restaurant-reservations' ); ?></option>
242
+ </select>
243
+ </div>
244
+ <div class='rtb-welcome-screen-option'>
245
+ <label><?php _e('Time Interval:', 'restaurant-reservations'); ?></label>
246
+ <select name='time-interval'>
247
+ <option><?php _e('Every 30 minutes', 'restaurant-reservations' ); ?></option>
248
+ <option value='15'><?php _e('Every 15 minutes', 'restaurant-reservations' ); ?></option>
249
+ <option value='10'><?php _e('Every 10 minutes', 'restaurant-reservations' ); ?></option>
250
+ <option value='5'><?php _e('Every 5 minutes', 'restaurant-reservations' ); ?></option>
251
+ </select>
252
+ </div>
253
+ <div class='rtb-welcome-screen-save-options-button'><?php _e('Save Options', 'restaurant-reservations'); ?></div>
254
+ <div class="rtb-welcome-clear"></div>
255
+ <div class='rtb-welcome-screen-previous-button' data-previousaction='schedule_open'><?php _e('Previous Step', 'restaurant-reservations'); ?></div>
256
+ <div class='rtb-welcome-screen-finish-button'><a href='admin.php?page=rtb-dashboard'><?php _e('Finish', 'restaurant-reservations'); ?></a></div>
257
+ <div class='clear'></div>
258
+ </div>
259
+ </div>
260
+
261
+ <div class='rtb-welcome-screen-skip-container'>
262
+ <a href='admin.php?page=rtb-dashboard'><div class='rtb-welcome-screen-skip-button'><?php _e('Skip Setup', 'restaurant-reservations'); ?></div></a>
263
+ </div>
264
+ </div>
265
+
266
+ <?php }
267
+
268
+ /**
269
+ * Retrieve the template for a scheduling rule
270
+ * @since 2.0
271
+ */
272
+ public function get_template( $id = 0, $values = array(), $list = false ) {
273
+
274
+ $date_format = 'weekly';
275
+ $time_format = 'all-day';
276
+
277
+ $weekdays = array(
278
+ 'monday' => 'Mo',
279
+ 'tuesday' => 'Tu',
280
+ 'wednesday' => 'We',
281
+ 'thursday' => 'Th',
282
+ 'friday' => 'Fr',
283
+ 'saturday' => 'Sa',
284
+ 'sunday' => 'Su',
285
+ );
286
+
287
+ ob_start();
288
+ ?>
289
+
290
+ <div class="sap-scheduler-rule clearfix<?php echo $list ? ' list' : ''; ?>">
291
+ <div class="sap-scheduler-date weekly">
292
+ <ul class="sap-selector">
293
+
294
+ <li>
295
+ <div class="dashicons dashicons-calendar"></div>
296
+ <?php _e( 'Weekly', 'restaurant-reservations' ); ?>
297
+ </li>
298
+
299
+ </ul>
300
+
301
+ <ul class="sap-scheduler-weekdays">
302
+ <li class="label">
303
+ <?php _e( 'Days of the week', 'restaurant-reservations' ); ?>
304
+ </li>
305
+ <?php
306
+ foreach ( $weekdays as $slug => $label ) :
307
+ $input_name = 'rtb-setting[schedule_open][' . $id . '][weekdays][' . esc_attr( $slug ) . ']';
308
+ ?>
309
+ <li>
310
+ &nbsp;<input type="checkbox" name="<?php echo $input_name; ?>" id="<?php echo $input_name; ?>" value="1" data-day="<?php echo esc_attr( $slug ); ?>"><label for="<?php echo $input_name; ?>"><?php echo ucfirst( $label ); ?></label>
311
+ </li>
312
+ <?php endforeach; ?>
313
+ </ul>
314
+
315
+ </div>
316
+
317
+ <div class="sap-scheduler-time all-day">
318
+
319
+ <ul class="sap-selector">
320
+ <li>
321
+ <div class="dashicons dashicons-clock"></div>
322
+ <a href="#" data-format="time-slot">
323
+ <?php _e( 'Time', 'restaurant-reservations' ); ?>
324
+ </a>
325
+ </li>
326
+ <li>
327
+ <a href="#" data-format="all-day" class="selected">
328
+ <?php _e( 'All day', 'restaurant-reservations' ); ?>
329
+ </a>
330
+ </li>
331
+ </ul>
332
+
333
+ <div class="sap-scheduler-time-input clearfix">
334
+
335
+ <div class="start">
336
+ <label for="rtb-setting[schedule_open][<?php echo $id; ?>][time][start]">
337
+ <?php _e( 'Start', 'restaurant-reservations' ); ?>
338
+ </label>
339
+ <input type="text" name="<?php echo 'rtb-setting[schedule_open][' . $id . '][time][start]'; ?>" id="<?php echo 'rtb-setting[schedule_open][' . $id . '][time][start]'; ?>">
340
+ </div>
341
+
342
+ <div class="end">
343
+ <label for="rtb-setting[schedule_open][<?php echo $id; ?>][time][end]">
344
+ <?php _e( 'End', 'restaurant-reservations' ); ?>
345
+ </label>
346
+ <input type="text" name="<?php echo'rtb-setting[schedule_open][' . $id . '][time][end]'; ?>" id="<?php echo 'rtb-setting[schedule_open][' . $id . '][time][end]'; ?>">
347
+ </div>
348
+
349
+ </div>
350
+
351
+ <div class="sap-scheduler-all-day">
352
+ <?php printf( __( 'All day long. Want to %sset a time slot%s?', 'restaurant-reservations' ), '<a href="#" data-format="time-slot">', '</a>' ); ?>
353
+ </div>
354
+
355
+ </div>
356
+
357
+ <div class="sap-scheduler-brief">
358
+ <div class="date">
359
+ <div class="dashicons dashicons-calendar"></div>
360
+ <span class="value"></span>
361
+ </div>
362
+ <div class="time">
363
+ <div class="dashicons dashicons-clock"></div>
364
+ <span class="value"></span>
365
+ </div>
366
+ </div>
367
+ <div class="sap-scheduler-control">
368
+ <a href="#" class="toggle" title="<?php _e( 'Open and close this rule', 'restaurant-reservations' ); ?>">
369
+ <div class="dashicons dashicons-<?php echo $list ? 'edit' : 'arrow-up-alt2'; ?>"></div>
370
+ <span class="screen-reader-text">
371
+ <?php _e( 'Open and close this rule', 'restaurant-reservations' ); ?>
372
+ </span>
373
+ </a>
374
+ <a href="#" class="delete" title="<?php _e( 'Delete rule', 'restaurant-reservations' ); ?>">
375
+ <div class="dashicons dashicons-dismiss"></div>
376
+ <span class="screen-reader-text">
377
+ <?php _e( 'Delete scheduling rule', 'restaurant-reservations' ); ?>
378
+ </span>
379
+ </a>
380
+ </div>
381
+ </div>
382
+
383
+ <?php
384
+ $output = ob_get_clean();
385
+
386
+ return $output;
387
+ }
388
+ }
389
+
390
+
391
+ ?>
includes/MailChimp.class.php ADDED
@@ -0,0 +1,535 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class used to add in MailChimp compatibility
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) )
6
+ exit;
7
+
8
+ if ( !class_exists( 'mcfrtbInit' ) ) {
9
+ class mcfrtbInit {
10
+
11
+ public $api_key = null;
12
+
13
+ public $status = null;
14
+
15
+ public $api_call_cache = array();
16
+
17
+ public function __construct() {
18
+
19
+ add_action( 'plugins_loaded', array( $this, 'init' ) );
20
+
21
+ }
22
+
23
+ /**
24
+ * Initialize the plugin and register hooks
25
+ */
26
+ public function init() {
27
+ global $rtb_controller;
28
+
29
+ // Initialize the plugin
30
+ add_action( 'init', array( $this, 'load_config' ), 9 ); // Load before the settings panel is defined in Restaurant Reservations
31
+ add_action( 'mcfrtb_list_merge_fields', array( $this, 'maybe_add_location_merge_field' ) );
32
+ add_action( 'mcfrtb_list_merge_fields', array( $this, 'maybe_add_merge_options' ) );
33
+
34
+ // Load assets
35
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_assets' ) );
36
+
37
+ // Receive ajax calls for mailchimp lists
38
+ add_action( 'wp_ajax_nopriv_mcfrtb-get-lists' , array( $this , 'ajax_nopriv_get_lists' ) );
39
+ add_action( 'wp_ajax_mcfrtb-get-lists', array( $this, 'ajax_get_lists' ) );
40
+
41
+ // Receive ajax calls for merge fields
42
+ add_action( 'wp_ajax_nopriv_mcfrtb-load-merge-fields' , array( $this , 'ajax_nopriv_load_merge_fields' ) );
43
+ add_action( 'wp_ajax_mcfrtb-load-merge-fields', array( $this, 'ajax_load_merge_fields' ) );
44
+
45
+
46
+ // Process subscription calls
47
+ add_action( 'wp_ajax_nopriv_mcfrtb-subscribe' , array( $this , 'subscribe' ) );
48
+ add_action( 'wp_ajax_mcfrtb-subscribe', array( $this, 'subscribe' ) );
49
+ add_filter( 'mcfrtb_merge_fields_data', array( $this, 'maybe_send_location_merge_field' ), 10, 3 );
50
+ add_filter( 'mcfrtb_merge_fields_data', array( $this, 'maybe_send_merge_fields' ), 10, 3 );
51
+
52
+ // Only add the opt-in details with the frontend form
53
+ if ( !is_admin() and $rtb_controller->permissions->check_permission( 'mailchimp' ) ) {
54
+
55
+ // Add optin checkbox to booking form
56
+ add_filter( 'rtb_booking_form_fields', array( $this, 'add_optin_field' ), 10, 2 );
57
+
58
+ // Validate the optin request data
59
+ add_filter( 'rtb_validate_booking_submission', array( $this, 'validate_optin_request' ) );
60
+
61
+ // Enqueue assets to send subscription request
62
+ add_filter( 'rtb_insert_booking', array( $this, 'enqueue_subscription_call' ) );
63
+ }
64
+ }
65
+
66
+
67
+ /**
68
+ * Load the configuration parameters
69
+ */
70
+ public function load_config() {
71
+
72
+ global $rtb_controller;
73
+ $api_key = $rtb_controller->settings->get_setting( 'mc-apikey' );
74
+
75
+ $this->api_key = $api_key['api_key'];
76
+ $this->status = $api_key['status'];
77
+
78
+ $this->merge_fields = apply_filters(
79
+ 'mcfrtb_list_merge_fields',
80
+ array(
81
+ 'datetime' => __( 'Date/Time of Booking', 'restaurant-reservations' ),
82
+ 'name' => __( 'Name', 'restaurant-reservations' ),
83
+ 'party' => __( 'Party Size', 'restaurant-reservations' ),
84
+ 'phone' => __( 'Phone Number', 'restaurant-reservations' ),
85
+ 'message' => __( 'Message', 'restaurant-reservations' ),
86
+ )
87
+ );
88
+
89
+ }
90
+
91
+ /**
92
+ * Add merge field for location if multi-location support is active
93
+ *
94
+ * @param array $fields Key/value list of booking data available for merge
95
+ * @since 1.2
96
+ */
97
+ public function maybe_add_location_merge_field( $fields ) {
98
+
99
+ global $rtb_controller;
100
+
101
+ if ( !empty( $rtb_controller->locations ) && !empty( $rtb_controller->locations->post_type ) ) {
102
+ $fields['location'] = __( 'Location', 'restaurant-reservations' );
103
+ }
104
+
105
+ return $fields;
106
+ }
107
+
108
+ /**
109
+ * Add merge field options for custom fields
110
+ *
111
+ * @param array $fields Key/value list of booking data available for merge
112
+ * @since 1.3
113
+ */
114
+ public function maybe_add_merge_options( $fields ) {
115
+
116
+ $custom_fields = rtb_get_custom_fields();
117
+
118
+ $custom_merge_fields = array();
119
+ foreach( $custom_fields as $custom_field ) {
120
+ $custom_merge_fields['cf-' . $custom_field->slug] = $custom_field->title;
121
+ }
122
+
123
+ return array_merge( $fields, $custom_merge_fields );
124
+ }
125
+
126
+ /**
127
+ * Enqueue the admin-only CSS and Javascript
128
+ * @since 0.0.1
129
+ */
130
+ public function enqueue_admin_assets() {
131
+
132
+ global $rtb_controller;
133
+
134
+ // Use the page reference in $admin_page_hooks because
135
+ // it changes in SOME hooks when it is translated.
136
+ // https://core.trac.wordpress.org/ticket/18857
137
+ global $admin_page_hooks;
138
+
139
+ $screen = get_current_screen();
140
+ if ( empty( $screen ) || empty( $admin_page_hooks['rtb-bookings'] ) ) {
141
+ return;
142
+ }
143
+
144
+ if ( $screen->base == 'toplevel_page_rtb-bookings' || $screen->base == $admin_page_hooks['rtb-bookings'] . '_page_rtb-settings' ) {
145
+
146
+ wp_enqueue_script( 'rtb-admin-mc', RTB_PLUGIN_URL . '/assets/js/mailchimp-admin.js', array( 'jquery' ), '', true );
147
+ wp_localize_script(
148
+ 'rtb-admin-mc',
149
+ 'rtb_admin_mc',
150
+ array(
151
+ 'ajax_nonce' => wp_create_nonce( 'rtb-admin-mc' ),
152
+ 'merge_fields' => $this->merge_fields,
153
+ 'lists' => $rtb_controller->settings->get_setting( 'mc-lists' ),
154
+ 'strings' => array(
155
+ 'merge_booking_data' => __( 'Booking Form Data', 'restaurant-reservations' ),
156
+ 'merge_list_field' => __( 'MailChimp List Field', 'restaurant-reservations' ),
157
+ 'merge_description' => __( 'Connect information from the booking request to <a href="http://kb.mailchimp.com/article/getting-started-with-merge-tags" target="_blank">merge fields</a> in your MailChimp list.', 'restaurant-reservations' ),
158
+ 'api_unknown_error' => __( 'There was an unexpected error when trying to retrieve the list\'s merge fields.', 'restaurant-reservations' ),
159
+ 'merge_email_label' => __( 'Email', 'restaurant-reservations' ),
160
+ 'merge_email_description' => __( 'The email field is automatically merged.', 'restaurant-reservations' ),
161
+ )
162
+ )
163
+ );
164
+ }
165
+ }
166
+
167
+
168
+ /**
169
+ * Handle ajax request for lists from logged out user
170
+ */
171
+ public function ajax_nopriv_get_lists() {
172
+
173
+ wp_send_json_error(
174
+ array(
175
+ 'error' => 'loggedout',
176
+ 'msg' => __( 'You have been logged out. Please login again to retrieve the mailing lists.', 'restaurant-reservations' ),
177
+ )
178
+ );
179
+ }
180
+
181
+ /**
182
+ * Handle ajax request for lists
183
+ */
184
+ public function ajax_get_lists() {
185
+
186
+ if ( !check_ajax_referer( 'rtb-admin-mc', 'nonce' ) || !current_user_can( 'manage_options' )) {
187
+ wp_send_json_error(
188
+ array(
189
+ 'error' => 'nopriv',
190
+ 'msg' => __( 'You do not have permission to retrieve the mailing lists. Please login to an administrator account if you have one.', 'restaurant-reservations' ),
191
+ )
192
+ );
193
+ }
194
+
195
+ $this->load_api( $this->api_key );
196
+
197
+ $this->api_call( '/lists' )->send_json_response();
198
+ }
199
+
200
+ /**
201
+ * Handle ajax request for list merge fields from logged out user
202
+ */
203
+ public function ajax_nopriv_load_merge_fields() {
204
+
205
+ wp_send_json_error(
206
+ array(
207
+ 'error' => 'loggedout',
208
+ 'msg' => __( 'You have been logged out. Please login again to retrieve the merge fields for this list.', 'restaurant-reservations' ),
209
+ )
210
+ );
211
+ }
212
+
213
+ /**
214
+ * Handle ajax request for list merge fields
215
+ */
216
+ public function ajax_load_merge_fields() {
217
+
218
+ if ( !check_ajax_referer( 'rtb-admin-mc', 'nonce' ) || !current_user_can( 'manage_options' ) || empty( $_POST['list'] ) ) {
219
+ wp_send_json_error(
220
+ array(
221
+ 'error' => 'nopriv',
222
+ 'msg' => __( 'You do not have permission to modify the merge field settings. Please login to an administrator account if you have one.', 'restaurant-reservations' ),
223
+ )
224
+ );
225
+ }
226
+
227
+ $this->load_api( $this->api_key );
228
+
229
+ $this->api_call( '/lists/' . sanitize_key( $_POST['list'] ) . '/merge-fields' )->send_json_response();
230
+ }
231
+
232
+ /**
233
+ * Load the api request class
234
+ *
235
+ * @param string $api_key MailChimp API key
236
+ */
237
+ public function load_api( $api_key = '' ) {
238
+
239
+ // Don't load it twice
240
+ if ( !empty( $this->mc ) ) {
241
+ return;
242
+ }
243
+
244
+ require_once( RTB_PLUGIN_DIR . '/includes/MailChimpRequest.class.php' );
245
+
246
+ // Update the api key
247
+ if ( $api_key ) {
248
+ $this->api_key = $api_key;
249
+ }
250
+
251
+ // Load the API wrapper library
252
+ $this->mc = new mcrftbMailChimpRequest( $this->api_key );
253
+ }
254
+
255
+ /**
256
+ * Make a call to the API or pull results from cache
257
+ *
258
+ * @param string $method HTTP method. Only GET and POST supported for now
259
+ * @param string $endpoint API endpoint to query, eg: /lists
260
+ * @param array $params Parameters to pass with the API request
261
+ */
262
+ public function api_call( $endpoint = '', $method = 'GET', $params = array() ) {
263
+ return $this->mc->call( $endpoint, $method, $params );
264
+ }
265
+
266
+ /**
267
+ * Check if the API key is valid
268
+ */
269
+ public function is_valid_api_key() {
270
+
271
+ if ( empty( $this->api_key ) || empty( $this->mc ) ) {
272
+ return false;
273
+ }
274
+
275
+ // Bad API key if no data center available
276
+ if ( strpos( $this->api_key, '-' ) === false ) {
277
+ return false;
278
+ }
279
+
280
+ // Make a test call to the API
281
+ $result = $this->api_call( '/lists' )->get_response();
282
+ if ( empty( $result ) || ( is_object( $result ) && get_class( $result ) == 'WP_Error' ) ) {
283
+ return false;
284
+ } else {
285
+ return true;
286
+ }
287
+
288
+ return false;
289
+ }
290
+
291
+ /**
292
+ * Add the optin checkbox field to the booking form
293
+ */
294
+ public function add_optin_field( $fields, $request ) {
295
+
296
+ global $rtb_controller;
297
+ $optout = $rtb_controller->settings->get_setting( 'mc-optout' );
298
+ $lists = $rtb_controller->settings->get_setting( 'mc-lists' );
299
+
300
+ if ( $optout !== 'no' && !empty( $lists['list'] ) ) {
301
+ $optprompt = $rtb_controller->settings->get_setting( 'mc-optprompt' );
302
+
303
+ $fields['optin'] = array(
304
+ 'fields' => array(
305
+ 'mc-optin' => array(
306
+ 'title' => $optprompt,
307
+ 'request_input' => empty( $request->mc_optin ) ? '' : $request->mc_optin,
308
+ 'callback' => array( $this, 'print_optin_field' ),
309
+ )
310
+ ),
311
+ 'order' => 1000,
312
+ );
313
+ }
314
+
315
+ return $fields;
316
+ }
317
+
318
+ /**
319
+ * Print the optin checkbox field on the booking form
320
+ */
321
+ public function print_optin_field( $slug, $title, $value ) {
322
+
323
+ global $rtb_controller;
324
+ $optout = $rtb_controller->settings->get_setting( 'mc-optout' );
325
+ $lists = $rtb_controller->settings->get_setting( 'mc-lists' );
326
+
327
+ // Check the box if it's been selected or if the setting is
328
+ // auto-checked and the form hasn't been submitted with it
329
+ // un-checked
330
+ $checked = $value ? true : false;
331
+ if ( !$checked && $optout == 'checked' && ( empty( $_POST['action'] ) || $_POST['action'] !== 'booking_request' ) ) {
332
+ $checked = true;
333
+ }
334
+
335
+ if ( $optout !== 'no' && !empty( $lists['list'] ) ) {
336
+ $label = $rtb_controller->settings->get_setting( 'mc-optprompt' );
337
+ ?>
338
+
339
+ <div class="mc-optin">
340
+ <label>
341
+ <input type="checkbox" name="<?php echo esc_attr( $slug ); ?>" value="1"<?php checked( $checked ); ?>>
342
+ <?php echo $label; ?>
343
+ </label>
344
+ </div>
345
+
346
+ <?php
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Validate the optin request data
352
+ */
353
+ public function validate_optin_request( $request ) {
354
+
355
+ global $rtb_controller;
356
+ if ( $rtb_controller->settings->get_setting( 'mc-optout' ) !== 'no' && !empty( $_POST['mc-optin'] ) && $_POST['mc-optin'] == '1' ) {
357
+ $request->mc_optin = true;
358
+ }
359
+ }
360
+
361
+ /**
362
+ * Enqueue some JavaScript to subscribe the user after they've
363
+ * booked.
364
+ */
365
+ public function enqueue_subscription_call( $booking ) {
366
+
367
+ global $rtb_controller;
368
+
369
+ // Did they opt out?
370
+ $optout = $rtb_controller->settings->get_setting( 'mc-optout' );
371
+ if ( !$optout && empty( $booking->mc_optin ) ) {
372
+ return;
373
+ }
374
+
375
+ // Do we have a list and email address to make the subscription
376
+ $lists = $rtb_controller->settings->get_setting( 'mc-lists' );
377
+ if ( empty( $lists['list'] ) || empty( $booking->email ) ) {
378
+ return;
379
+ }
380
+
381
+ wp_enqueue_script( 'rtb-mc-subscribe', RTB_PLUGIN_URL . '/assets/js/mailchimp-subscribe.js', array( 'jquery' ), '', true );
382
+ wp_localize_script(
383
+ 'rtb-mc-subscribe',
384
+ 'rtb_subscribe_mc',
385
+ array(
386
+ 'ajax_nonce' => wp_create_nonce( 'rtb-mc-subscribe' ),
387
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
388
+ 'booking' => $booking,
389
+ )
390
+ );
391
+
392
+ }
393
+
394
+ /**
395
+ * Process a subscription request
396
+ */
397
+ public function subscribe() {
398
+
399
+ if ( !check_ajax_referer( 'rtb-mc-subscribe', 'nonce' ) || empty( $_POST['booking'] ) ) {
400
+ wp_send_json_error(
401
+ array(
402
+ 'error' => 'badnonce',
403
+ 'msg' => __( 'The subscription request has been rejected because it does not appear to have come from this site.', 'restaurant-reservations' ),
404
+ )
405
+ );
406
+
407
+ return;
408
+ }
409
+
410
+ $booking = $_POST['booking'];
411
+
412
+ global $rtb_controller;
413
+
414
+ // Did they opt out?
415
+ $optout = $rtb_controller->settings->get_setting( 'mc-optout' );
416
+ if ( $optout != 'no' && empty( $booking['mc_optin'] ) ) {
417
+ return;
418
+ }
419
+
420
+ // Do we have a list and email address to make the subscription
421
+ $lists = $rtb_controller->settings->get_setting( 'mc-lists' );
422
+ if ( empty( $lists['list'] ) || empty( $booking['email'] ) ) {
423
+ return;
424
+ }
425
+
426
+ // Prepare post parameters to send
427
+ $params = array(
428
+ 'email_address' => $booking['email'],
429
+ 'status' => 'pending',
430
+ 'merge_fields' => (object) $this->get_merge_fields_data( $lists['fields'], $booking ),
431
+ );
432
+
433
+ // Pass in the user's IP for geolocation if available
434
+ if ( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
435
+ $params['ip_signup'] = $_SERVER['REMOTE_ADDR'];
436
+ $params['ip_opt'] = $_SERVER['REMOTE_ADDR'];
437
+ }
438
+
439
+ $params = apply_filters( 'mcfrtb_mailchimp_subscribe_args', $params, $booking );
440
+
441
+ $this->load_api( $this->api_key );
442
+
443
+ $this->api_call( '/lists/' . $lists['list'] . '/members', 'POST', $params )->send_json_response();
444
+ }
445
+
446
+ /**
447
+ * Get merge fields array to send to the MailChimp API
448
+ *
449
+ * @merge_fields array Merge fields data pulled locally from settings
450
+ */
451
+ public function get_merge_fields_data( $merge_fields, $booking ) {
452
+
453
+ $output = array();
454
+
455
+ foreach( $this->merge_fields as $field => $title ) {
456
+ if ( !empty( $merge_fields[$field] ) ) {
457
+
458
+ if ( $field == 'datetime' ) {
459
+ $output[$merge_fields[$field]] = $booking['date'];
460
+ }
461
+
462
+ if ( $field == 'name' ) {
463
+ $output[$merge_fields[$field]] = $booking['name'];
464
+ }
465
+
466
+ if ( $field == 'party' ) {
467
+ $output[$merge_fields[$field]] = $booking['party'];
468
+ }
469
+
470
+ if ( $field == 'phone' ) {
471
+ $output[$merge_fields[$field]] = $booking['phone'];
472
+ }
473
+
474
+ if ( $field == 'message' ) {
475
+ $output[$merge_fields[$field]] = $booking['message'];
476
+ }
477
+ }
478
+ }
479
+
480
+ return apply_filters( 'mcfrtb_merge_fields_data', $output, $merge_fields, $booking );
481
+ }
482
+
483
+ /**
484
+ * Add location to the data merge field when appropriate
485
+ *
486
+ * @param array $send Key/value array of merge data to be sent
487
+ * @param array $merge_fields Key/value array of configured merge fields
488
+ * @param rtbBooking $booking Booking object
489
+ * @since 1.2
490
+ */
491
+ public function maybe_send_location_merge_field( $send, $merge_fields, $booking ) {
492
+
493
+ global $rtb_controller;
494
+
495
+ if ( empty( $rtb_controller->locations ) || empty( $rtb_controller->locations->post_type ) ) {
496
+ return $send;
497
+ }
498
+
499
+ if ( !empty( $booking['location'] ) && !empty( $merge_fields['location'] ) ) {
500
+ $term = get_term( $booking['location'] );
501
+ if ( !empty( $term ) && is_a( $term, 'WP_Term' ) ) {
502
+ $send[$merge_fields['location']] = $term->name;
503
+ }
504
+ }
505
+
506
+ return $send;
507
+ }
508
+
509
+ /**
510
+ * Send merge field data for custom fields
511
+ *
512
+ * @param array $send Key/value array of merge data to be sent
513
+ * @param array $merge_fields Key/value array of configured merge fields
514
+ * @param rtbBooking $booking Booking object
515
+ * @since 1.3
516
+ */
517
+ public function maybe_send_merge_fields( $send, $merge_fields, $booking ) {
518
+ global $rtb_controller;
519
+
520
+ $custom_fields = rtb_get_custom_fields();
521
+
522
+ foreach( $custom_fields as $custom_field ) {
523
+ if ( !empty( $merge_fields['cf-' . $custom_field->slug] ) && isset( $booking['custom_fields'] ) && isset( $booking['custom_fields'][$custom_field->slug] ) ) {
524
+ if ( $custom_field->type == 'confirm' ) {
525
+ $send[$merge_fields['cf-' . $custom_field->slug]] = 'Checked';
526
+ } else {
527
+ $send[$merge_fields['cf-' . $custom_field->slug]] = $rtb_controller->fields->get_display_value( $booking['custom_fields'][$custom_field->slug], $custom_field, '', false );
528
+ }
529
+ }
530
+ }
531
+
532
+ return $send;
533
+ }
534
+ }
535
+ } // endif;
includes/MailChimpRequest.class.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php defined( 'ABSPATH' ) || exit;
2
+ /**
3
+ * Handle a single request to MailChimp API v3
4
+ *
5
+ * This is based on the very simple v2 API wrapper from Drew McLellan. That
6
+ * class, and this one, is licensed under the MIT.
7
+ * @see https://github.com/drewm/mailchimp-api/
8
+ *
9
+ */
10
+ class mcrftbMailChimpRequest {
11
+
12
+ /**
13
+ * MailChimp API key
14
+ *
15
+ * @param string
16
+ */
17
+ private $api_key = '';
18
+
19
+ /**
20
+ * API v3 endpoint URL
21
+ *
22
+ * @param string
23
+ */
24
+ private $api_url = 'https://<dc>.api.mailchimp.com/3.0';
25
+
26
+ /**
27
+ * Request details
28
+ *
29
+ * @param array {
30
+ * string $method
31
+ * string $endpoint
32
+ * array $args
33
+ * }
34
+ */
35
+ private $request;
36
+
37
+ /**
38
+ * Reponse to this request
39
+ *
40
+ * This stores the complete response from a wp_remote_get or wp_remote_post
41
+ * request. However, the helper method get_response() will retrieve just
42
+ * the body of the full response, which represents the data returned from
43
+ * the api request. The helper method get_response_complete() should be used
44
+ * if the metadata is desired.
45
+ *
46
+ * @param array
47
+ */
48
+ private $response;
49
+
50
+ /**
51
+ * Initialize a new request
52
+ *
53
+ * @param string $api_key
54
+ */
55
+ public function __construct( $api_key ) {
56
+
57
+ $this->api_key = $api_key;
58
+ $datacenter = explode('-', $this->api_key);
59
+ $this->api_url = str_replace( '<dc>', $datacenter[1], $this->api_url );
60
+
61
+ }
62
+
63
+ /**
64
+ * Make a call to the API
65
+ *
66
+ * @param string $method HTTP method. Only GET and POST supported for now
67
+ * @param string $endpoint API endpoint to query, eg: /lists
68
+ * @param array $params Parameters to pass with the API request
69
+ */
70
+ public function call( $endpoint = '', $method = 'GET', $params = array() ) {
71
+
72
+ $url = $this->api_url . $endpoint;
73
+
74
+ $args = array(
75
+ 'headers' => array(
76
+ 'Authorization' => 'MailChimpForRestaurantReservations ' . $this->api_key,
77
+ ),
78
+ );
79
+
80
+ if ( !empty( $params ) ) {
81
+ $args['body'] = json_encode( $params );
82
+ }
83
+
84
+ $args = apply_filters( 'mcfrtb_mailchimp_api_request_args', $args, $endpoint, $method, $params );
85
+
86
+ $this->request = array(
87
+ 'method' => $method,
88
+ 'endpoint' => $endpoint,
89
+ 'args' => $args,
90
+ 'params' => $params,
91
+ );
92
+
93
+ $this->response = $method == 'GET' ? wp_remote_get( $url, $args ) : wp_remote_post( $url, $args );
94
+
95
+ return $this;
96
+ }
97
+
98
+ /**
99
+ * Retrieve the cached response
100
+ */
101
+ public function get_response() {
102
+
103
+ if ( is_object( $this->response ) && get_class( $this->response ) == 'WP_Error' ) {
104
+ return $this->response;
105
+ }
106
+
107
+ return isset( $this->response['body'] ) ? $this->response['body'] : null;
108
+ }
109
+
110
+ /**
111
+ * Retrieve the full details of the response array returned by wp_remote_get
112
+ * or wp_remote_post
113
+ */
114
+ public function get_response_complete() {
115
+ return $this->response;
116
+ }
117
+
118
+ /**
119
+ * Send the response for this request
120
+ *
121
+ * The response can be a successful or error response from MailChimp, or a
122
+ * WP_Error from wp_remote_get or wp_remote_post. This small wrapper around
123
+ * wp_send_json_* ensures any json is decoded
124
+ */
125
+ public function send_json_response() {
126
+
127
+ $response = $this->get_response();
128
+
129
+ if ( empty( $response ) || ( is_object( $this->response ) && get_class( $response ) == 'WP_Error' ) ) {
130
+ wp_send_json_error( $response );
131
+ }
132
+
133
+ wp_send_json_success( json_decode( $response ) );
134
+ }
135
+
136
+ /**
137
+ * Retrieve details about this request
138
+ */
139
+ public function get_request() {
140
+ return $this->request;
141
+ }
142
+ }
includes/Notification.Email.class.php CHANGED
@@ -136,6 +136,12 @@ class rtbNotificationEmail extends rtbNotification {
136
  } elseif ( $this->event == 'pending_to_closed' ) {
137
  $subject = $rtb_controller->settings->get_setting( 'subject-rejected-user' );
138
 
 
 
 
 
 
 
139
  // Use a subject that's been appended manually if available
140
  } else {
141
  $subject = empty( $this->subject ) ? '' : $this->subject;
@@ -188,6 +194,16 @@ class rtbNotificationEmail extends rtbNotification {
188
  $template = $this->get_template( 'template-rejected-user' );
189
  }
190
 
 
 
 
 
 
 
 
 
 
 
191
  // Use a message that's been appended manually if available
192
  } else {
193
  $template = empty( $this->message ) ? '' : $this->message;
@@ -226,7 +242,7 @@ class rtbNotificationEmail extends rtbNotification {
226
  * @since 0.0.1
227
  */
228
  public function send_notification() {
229
- wp_mail( $this->to_email, $this->subject, $this->message, $this->headers, apply_filters( 'rtb_notification_email_attachments', array(), $this ) );
230
  }
231
  }
232
  } // endif;
136
  } elseif ( $this->event == 'pending_to_closed' ) {
137
  $subject = $rtb_controller->settings->get_setting( 'subject-rejected-user' );
138
 
139
+ } elseif ( $this->event == 'late_user' ) {
140
+ $subject = $rtb_controller->settings->get_setting( 'subject-late-user' );
141
+
142
+ } elseif ( $this->event == 'reminder' ) {
143
+ $subject = $rtb_controller->settings->get_setting( 'subject-reminder-user' );
144
+
145
  // Use a subject that's been appended manually if available
146
  } else {
147
  $subject = empty( $this->subject ) ? '' : $this->subject;
194
  $template = $this->get_template( 'template-rejected-user' );
195
  }
196
 
197
+ } elseif ( $this->event == 'late_user' ) {
198
+ if ( $this->target == 'user' ) {
199
+ $template = $this->get_template( 'template-late-user' );
200
+ }
201
+
202
+ } elseif ( $this->event == 'reminder' ) {
203
+ if ( $this->target == 'user' ) {
204
+ $template = $this->get_template( 'template-reminder-user' );
205
+ }
206
+
207
  // Use a message that's been appended manually if available
208
  } else {
209
  $template = empty( $this->message ) ? '' : $this->message;
242
  * @since 0.0.1
243
  */
244
  public function send_notification() {
245
+ return wp_mail( $this->to_email, $this->subject, $this->message, $this->headers, apply_filters( 'rtb_notification_email_attachments', array(), $this ) );
246
  }
247
  }
248
  } // endif;
includes/Permissions.class.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( !defined( 'ABSPATH' ) ) exit;
3
+
4
+ if ( !class_exists( 'rtbPermissions' ) ) {
5
+ /**
6
+ * Class to handle plugin permissions for Restaurant Reservations
7
+ *
8
+ * @since 2.0.0
9
+ */
10
+ class rtbPermissions {
11
+
12
+ private $plugin_permissions;
13
+ private $permission_level;
14
+
15
+ public function __construct() {
16
+ $this->plugin_permissions = array(
17
+ "styling" => 2,
18
+ "import" => 2,
19
+ "export" => 2,
20
+ "custom_fields" => 2,
21
+ "mailchimp" => 2,
22
+ "templates" => 2,
23
+ "designer" => 2,
24
+ "premium_view_bookings" => 2,
25
+ "premium_table_restrictions" => 2,
26
+ "reminders" => 2,
27
+ );
28
+ }
29
+
30
+ public function set_permissions() {
31
+ global $rtb_controller;
32
+
33
+ $cffrtb = $rtb_controller->settings->get_setting( 'license-cffrtb' );
34
+ $ebfrtb = $rtb_controller->settings->get_setting( 'license-ebfrtb' );
35
+ $etfrtb = $rtb_controller->settings->get_setting( 'license-etfrtb' );
36
+
37
+ $bookings_objects = get_posts( array( 'post_type' => array( RTB_BOOKING_POST_TYPE ) ) );
38
+
39
+ $this->permission_level = ( ( $cffrtb['status'] == 'valid' or $ebfrtb['status'] == 'valid' or $etfrtb['status'] == 'valid' or get_option("mcfrtb_license_key") ) ? 2 : ( ! empty($bookings_objects) ? 1 : 0 ) );
40
+
41
+ update_option( "rtb-permission-level", $this->permission_level );
42
+ }
43
+
44
+ public function get_permission_level() {
45
+ $this->permission_level = get_option( "rtb-permission-level" );
46
+
47
+ if ( ! $this->permission_level ) { $this->set_permissions(); }
48
+ }
49
+
50
+ public function check_permission($permission_type = '') {
51
+ if ( ! $this->permission_level ) { $this->get_permission_level(); }
52
+
53
+ return ( array_key_exists( $permission_type, $this->plugin_permissions ) ? ( $this->permission_level >= $this->plugin_permissions[$permission_type] ? true : false ) : false );
54
+ }
55
+
56
+ public function update_permissions() {
57
+ $this->permission_level = get_option( "rtb-permission-level" );
58
+ }
59
+ }
60
+
61
+ }
includes/Query.class.php CHANGED
@@ -93,7 +93,11 @@ class rtbQuery {
93
 
94
  $args = $this->args;
95
 
96
- if ( is_string( $args['date_range'] ) ) {
 
 
 
 
97
 
98
  if ( !empty( $args['start_date'] ) || !empty( $args['end_date'] ) ) {
99
  $date_query = array( 'inclusive' => true );
93
 
94
  $args = $this->args;
95
 
96
+ if ( ! empty( $args['date_query'] ) ) {
97
+ $args['date_query'] = $args['date_query'];
98
+ }
99
+
100
+ elseif ( is_string( $args['date_range'] ) ) {
101
 
102
  if ( !empty( $args['start_date'] ) || !empty( $args['end_date'] ) ) {
103
  $date_query = array( 'inclusive' => true );
includes/Settings.class.php CHANGED
@@ -89,11 +89,21 @@ class rtbSettings {
89
 
90
  $this->defaults = array(
91
 
 
 
92
  'success-message' => _x( 'Thanks, your booking request is waiting to be confirmed. Updates will be sent to the email address you provided.', 'restaurant-reservations' ),
93
  'date-format' => _x( 'mmmm d, yyyy', 'Default date format for display. Must match formatting rules at http://amsul.ca/pickadate.js/date/#formats', 'restaurant-reservations' ),
94
  'time-format' => _x( 'h:i A', 'Default time format for display. Must match formatting rules at http://amsul.ca/pickadate.js/time/#formats', 'restaurant-reservations' ),
95
  'time-interval' => _x( '30', 'Default interval in minutes when selecting a time.', 'restaurant-reservations' ),
96
 
 
 
 
 
 
 
 
 
97
  // Email address where admin notifications should be sent
98
  'admin-email-address' => get_option( 'admin_email' ),
99
 
@@ -171,7 +181,45 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
171
  &nbsp;
172
 
173
  <em>This message was sent by {site_link} on {current_time}.</em>',
174
- 'Default email sent to users when they make a new booking request. The tags in {brackets} will be replaced by the appropriate content and should be left in place. HTML is allowed, but be aware that many email clients do not handle HTML very well.',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  'restaurant-reservations'
176
  ),
177
 
@@ -217,11 +265,12 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
217
  * @sa https://github.com/NateWr/simple-admin-pages
218
  */
219
  public function load_settings_panel() {
 
220
 
221
  require_once( RTB_PLUGIN_DIR . '/lib/simple-admin-pages/simple-admin-pages.php' );
222
  $sap = sap_initialize_library(
223
  $args = array(
224
- 'version' => '2.1.2',
225
  'lib_url' => RTB_PLUGIN_URL . '/lib/simple-admin-pages/',
226
  )
227
  );
@@ -235,7 +284,196 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
235
  'parent_menu' => 'rtb-bookings',
236
  'description' => '',
237
  'capability' => 'manage_options',
238
- 'default_tab' => 'rtb-general',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  )
240
  );
241
 
@@ -244,7 +482,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
244
  array(
245
  'id' => 'rtb-general',
246
  'title' => __( 'General', 'restaurant-reservations' ),
247
- 'is_tab' => true,
248
  )
249
  );
250
 
@@ -291,6 +529,20 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
291
  )
292
  );
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  $sap->add_setting(
295
  'rtb-settings',
296
  'rtb-general',
@@ -324,7 +576,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
324
  array(
325
  'id' => 'rtb-booking-form',
326
  'title' => __( 'Booking Form', 'restaurant-reservations' ),
327
- 'tab' => 'rtb-general',
328
  )
329
  );
330
 
@@ -372,7 +624,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
372
  array(
373
  'id' => 'rtb-security',
374
  'title' => __( 'Security', 'restaurant-reservations' ),
375
- 'tab' => 'rtb-general',
376
  )
377
  );
378
 
@@ -403,7 +655,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
403
  array(
404
  'id' => 'rtb-privacy',
405
  'title' => __( 'Privacy', 'restaurant-reservations' ),
406
- 'tab' => 'rtb-general',
407
  )
408
  );
409
 
@@ -414,7 +666,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
414
  array(
415
  'id' => 'require-consent',
416
  'title' => __( 'Require Consent', 'restaurant-reservations' ),
417
- 'label' => __( 'Require customers to consent to the collection of their details when making a booking. This may be required to comply with privacy laws in your country.', 'restaurant-reservations' )
418
  )
419
  );
420
 
@@ -446,174 +698,285 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
446
  )
447
  );
448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
449
  $sap->add_section(
450
  'rtb-settings',
451
  array(
452
- 'id' => 'rtb-schedule',
453
- 'title' => __( 'Booking Schedule', 'restaurant-reservations' ),
454
  'is_tab' => true,
455
  )
456
  );
457
 
458
- // Translateable strings for scheduler components
459
- $scheduler_strings = array(
460
- 'add_rule' => __( 'Add new scheduling rule', 'restaurant-reservations' ),
461
- 'weekly' => _x( 'Weekly', 'Format of a scheduling rule', 'restaurant-reservations' ),
462
- 'monthly' => _x( 'Monthly', 'Format of a scheduling rule', 'restaurant-reservations' ),
463
- 'date' => _x( 'Date', 'Format of a scheduling rule', 'restaurant-reservations' ),
464
- 'weekdays' => _x( 'Days of the week', 'Label for selecting days of the week in a scheduling rule', 'restaurant-reservations' ),
465
- 'month_weeks' => _x( 'Weeks of the month', 'Label for selecting weeks of the month in a scheduling rule', 'restaurant-reservations' ),
466
- 'date_label' => _x( 'Date', 'Label to select a date for a scheduling rule', 'restaurant-reservations' ),
467
- 'time_label' => _x( 'Time', 'Label to select a time slot for a scheduling rule', 'restaurant-reservations' ),
468
- 'allday' => _x( 'All day', 'Label to set a scheduling rule to last all day', 'restaurant-reservations' ),
469
- 'start' => _x( 'Start', 'Label for the starting time of a scheduling rule', 'restaurant-reservations' ),
470
- 'end' => _x( 'End', 'Label for the ending time of a scheduling rule', 'restaurant-reservations' ),
471
- 'set_time_prompt' => _x( 'All day long. Want to %sset a time slot%s?', 'Prompt displayed when a scheduling rule is set without any time restrictions', 'restaurant-reservations' ),
472
- 'toggle' => _x( 'Open and close this rule', 'Toggle a scheduling rule open and closed', 'restaurant-reservations' ),
473
- 'delete' => _x( 'Delete rule', 'Delete a scheduling rule', 'restaurant-reservations' ),
474
- 'delete_schedule' => __( 'Delete scheduling rule', 'restaurant-reservations' ),
475
- 'never' => _x( 'Never', 'Brief default description of a scheduling rule when no weekdays or weeks are included in the rule', 'restaurant-reservations' ),
476
- 'weekly_always' => _x( 'Every day', 'Brief default description of a scheduling rule when all the weekdays/weeks are included in the rule', 'restaurant-reservations' ),
477
- 'monthly_weekdays' => _x( '%s on the %s week of the month', 'Brief default description of a scheduling rule when some weekdays are included on only some weeks of the month. %s should be left alone and will be replaced by a comma-separated list of days and weeks in the following format: M, T, W on the first, second week of the month', 'restaurant-reservations' ),
478
- 'monthly_weeks' => _x( '%s week of the month', 'Brief default description of a scheduling rule when some weeks of the month are included but all or no weekdays are selected. %s should be left alone and will be replaced by a comma-separated list of weeks in the following format: First, second week of the month', 'restaurant-reservations' ),
479
- 'all_day' => _x( 'All day', 'Brief default description of a scheduling rule when no times are set', 'restaurant-reservations' ),
480
- 'before' => _x( 'Ends at', 'Brief default description of a scheduling rule when an end time is set but no start time. If the end time is 6pm, it will read: Ends at 6pm', 'restaurant-reservations' ),
481
- 'after' => _x( 'Starts at', 'Brief default description of a scheduling rule when a start time is set but no end time. If the start time is 6pm, it will read: Starts at 6pm', 'restaurant-reservations' ),
482
- 'separator' => _x( '&mdash;', 'Separator between times of a scheduling rule', 'restaurant-reservations' ),
483
  );
484
-
485
  $sap->add_setting(
486
  'rtb-settings',
487
- 'rtb-schedule',
488
- 'scheduler',
489
  array(
490
- 'id' => 'schedule-open',
491
- 'title' => __( 'Schedule', 'restaurant-reservations' ),
492
- 'description' => __( 'Define the weekly schedule during which you accept bookings.', 'restaurant-reservations' ),
493
- 'weekdays' => array(
494
- 'monday' => _x( 'Mo', 'Monday abbreviation', 'restaurant-reservations' ),
495
- 'tuesday' => _x( 'Tu', 'Tuesday abbreviation', 'restaurant-reservations' ),
496
- 'wednesday' => _x( 'We', 'Wednesday abbreviation', 'restaurant-reservations' ),
497
- 'thursday' => _x( 'Th', 'Thursday abbreviation', 'restaurant-reservations' ),
498
- 'friday' => _x( 'Fr', 'Friday abbreviation', 'restaurant-reservations' ),
499
- 'saturday' => _x( 'Sa', 'Saturday abbreviation', 'restaurant-reservations' ),
500
- 'sunday' => _x( 'Su', 'Sunday abbreviation', 'restaurant-reservations' )
501
  ),
502
- 'time_format' => $this->get_setting( 'time-format' ),
503
- 'date_format' => $this->get_setting( 'date-format' ),
504
- 'disable_weeks' => true,
505
- 'disable_date' => true,
506
- 'strings' => $scheduler_strings,
507
  )
508
  );
509
-
510
- $scheduler_strings['all_day'] = _x( 'Closed all day', 'Brief default description of a scheduling exception when no times are set', 'restaurant-reservations' );
511
  $sap->add_setting(
512
  'rtb-settings',
513
- 'rtb-schedule',
514
- 'scheduler',
515
  array(
516
- 'id' => 'schedule-closed',
517
- 'title' => __( 'Exceptions', 'restaurant-reservations' ),
518
- 'description' => __( "Define special opening hours for holidays, events or other needs. Leave the time empty if you're closed all day.", 'restaurant-reservations' ),
519
- 'time_format' => $this->get_setting( 'time-format' ),
520
- 'date_format' => $this->get_setting( 'date-format' ),
521
- 'disable_weekdays' => true,
522
- 'disable_weeks' => true,
523
- 'strings' => $scheduler_strings,
524
  )
525
  );
526
-
527
  $sap->add_setting(
528
  'rtb-settings',
529
- 'rtb-schedule',
530
- 'select',
531
  array(
532
- 'id' => 'early-bookings',
533
- 'title' => __( 'Early Bookings', 'restaurant-reservations' ),
534
- 'description' => __( 'Select how early customers can make their booking. (Administrators and Booking Managers are not restricted by this setting.)', 'restaurant-reservations' ),
535
- 'blank_option' => false,
536
- 'options' => array(
537
- '' => __( 'Any time', 'restaurant-reservations' ),
538
- '1' => __( 'From 1 day in advance', 'restaurant-reservations' ),
539
- '7' => __( 'From 1 week in advance', 'restaurant-reservations' ),
540
- '14' => __( 'From 2 weeks in advance', 'restaurant-reservations' ),
541
- '30' => __( 'From 30 days in advance', 'restaurant-reservations' ),
542
- '90' => __( 'From 90 days in advance', 'restaurant-reservations' ),
543
- )
544
  )
545
  );
546
 
 
 
 
 
 
 
 
 
 
 
 
547
  $sap->add_setting(
548
  'rtb-settings',
549
- 'rtb-schedule',
550
- 'select',
551
  array(
552
- 'id' => 'late-bookings',
553
- 'title' => __( 'Late Bookings', 'restaurant-reservations' ),
554
- 'description' => __( 'Select how late customers can make their booking. (Administrators and Booking Managers are not restricted by this setting.)', 'restaurant-reservations' ),
 
555
  'blank_option' => false,
556
- 'options' => array(
557
- '' => __( 'Up to the last minute', 'restaurant-reservations' ),
558
- '15' => __( 'At least 15 minutes in advance', 'restaurant-reservations' ),
559
- '30' => __( 'At least 30 minutes in advance', 'restaurant-reservations' ),
560
- '45' => __( 'At least 45 minutes in advance', 'restaurant-reservations' ),
561
- '60' => __( 'At least 1 hour in advance', 'restaurant-reservations' ),
562
- '240' => __( 'At least 4 hours in advance', 'restaurant-reservations' ),
563
- '1440' => __( 'At least 24 hours in advance', 'restaurant-reservations' ),
564
- 'same_day' => __( 'Block same-day bookings', 'restaurant-reservations' ),
565
- )
566
  )
567
  );
568
-
569
  $sap->add_setting(
570
  'rtb-settings',
571
- 'rtb-schedule',
572
- 'select',
573
  array(
574
- 'id' => 'date-onload',
575
- 'title' => __( 'Date Pre-selection', 'restaurant-reservations' ),
576
- 'description' => __( 'When the booking form is loaded, should it automatically attempt to select a valid date?', 'restaurant-reservations' ),
577
- 'blank_option' => false,
578
- 'options' => array(
579
- '' => __( 'Select today if valid', 'restaurant-reservations' ),
580
- 'soonest' => __( 'Select today or next valid date', 'restaurant-reservations' ),
581
- 'empty' => __( 'Leave empty', 'restaurant-reservations' ),
582
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
583
  )
584
  );
585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
  $sap->add_setting(
587
  'rtb-settings',
588
- 'rtb-schedule',
589
- 'select',
590
  array(
591
- 'id' => 'time-interval',
592
- 'title' => __( 'Time Interval', 'restaurant-reservations' ),
593
- 'description' => __( 'Select the number of minutes between each available time.', 'restaurant-reservations' ),
594
- 'blank_option' => false,
595
- 'options' => array(
596
- '' => __( 'Every 30 minutes', 'restaurant-reservations' ),
597
- '15' => __( 'Every 15 minutes', 'restaurant-reservations' ),
598
- '10' => __( 'Every 10 minutes', 'restaurant-reservations' ),
599
- '5' => __( 'Every 5 minutes', 'restaurant-reservations' ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
600
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  )
602
  );
603
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
604
  $sap->add_setting(
605
  'rtb-settings',
606
- 'rtb-schedule',
607
- 'select',
608
  array(
609
- 'id' => 'week-start',
610
- 'title' => __( 'Week Starts On', 'restaurant-reservations' ),
611
- 'description' => __( 'Select the first day of the week', 'restaurant-reservations' ),
612
- 'blank_option' => false,
613
- 'options' => array(
614
- '0' => __( 'Sunday', 'restaurant-reservations' ),
615
- '1' => __( 'Monday', 'restaurant-reservations' ),
616
- )
617
  )
618
  );
619
 
@@ -621,8 +984,8 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
621
  'rtb-settings',
622
  array(
623
  'id' => 'rtb-notifications',
624
- 'title' => __( 'Notifications', 'restaurant-reservations' ),
625
- 'is_tab' => true,
626
  )
627
  );
628
 
@@ -657,7 +1020,7 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
657
  array(
658
  'id' => 'admin-email-option',
659
  'title' => __( 'Admin Notification', 'restaurant-reservations' ),
660
- 'label' => __( 'Send an email notification to an administrator when a new booking is requested.', 'restaurant-reservations' )
661
  )
662
  );
663
 
@@ -677,8 +1040,8 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
677
  'rtb-settings',
678
  array(
679
  'id' => 'rtb-notifications-templates',
680
- 'title' => __( 'Email Templates', 'restaurant-reservations' ),
681
- 'tab' => 'rtb-notifications',
682
  'description' => __( 'Adjust the messages that are emailed to users and admins during the booking process.', 'restaurant-reservations' ),
683
  )
684
  );
@@ -804,13 +1167,120 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
804
  )
805
  );
806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
807
  $sap->add_section(
808
  'rtb-settings',
809
  array(
810
  'id' => 'rtb-notifications-advanced',
811
  'title' => __( 'Advanced', 'restaurant-reservations' ),
812
  'description' => __( "Modifying the settings below can prevent your emails from being delivered. Do not make changes unless you know what you're doing.", 'restaurant-reservations' ),
813
- 'tab' => 'rtb-notifications',
814
  )
815
  );
816
 
@@ -826,6 +1296,303 @@ Sorry, we could not accomodate your booking request. We\'re full or not open at
826
  )
827
  );
828
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
829
  $sap = apply_filters( 'rtb_settings_page', $sap );
830
 
831
  $sap->add_admin_menus();
89
 
90
  $this->defaults = array(
91
 
92
+ 'auto-confirm-max-party-size' => 1,
93
+ 'rtb-dining-block-length' => '120_minutes',
94
  'success-message' => _x( 'Thanks, your booking request is waiting to be confirmed. Updates will be sent to the email address you provided.', 'restaurant-reservations' ),
95
  'date-format' => _x( 'mmmm d, yyyy', 'Default date format for display. Must match formatting rules at http://amsul.ca/pickadate.js/date/#formats', 'restaurant-reservations' ),
96
  'time-format' => _x( 'h:i A', 'Default time format for display. Must match formatting rules at http://amsul.ca/pickadate.js/time/#formats', 'restaurant-reservations' ),
97
  'time-interval' => _x( '30', 'Default interval in minutes when selecting a time.', 'restaurant-reservations' ),
98
 
99
+ // Export defaults
100
+ 'ebfrtb-paper-size' => 'A4',
101
+ 'ebfrtb-pdf-lib' => 'mpdf',
102
+ 'ebfrtb-csv-date-format' => get_option( 'date_format' ) . ' ' . get_option( 'time_format' ),
103
+
104
+ // MailChimp defaults
105
+ 'mc-optprompt' => __( 'Sign up for our mailing list.', 'restaurant-reservations' ),
106
+
107
  // Email address where admin notifications should be sent
108
  'admin-email-address' => get_option( 'admin_email' ),
109
 
181
  &nbsp;
182
 
183
  <em>This message was sent by {site_link} on {current_time}.</em>',
184
+ 'Default email sent to users when their booking request is rejected. The tags in {brackets} will be replaced by the appropriate content and should be left in place. HTML is allowed, but be aware that many email clients do not handle HTML very well.',
185
+ 'restaurant-reservations'
186
+ ),
187
+
188
+ // Email template sent to a user when a booking request is rejected
189
+ 'subject-reminder-user' => sprintf( _x( 'Reminder: Your reservation at %s', 'Default email subject sent to user as a reminder about for their booking. %s will be replaced by the website name', 'restaurant-reservations' ), get_bloginfo( 'name' ) ),
190
+ 'template-reminder-user' => _x( 'Hi {user_name},
191
+
192
+ You have a reservation with the following details:
193
+
194
+ {date}
195
+ {user_name}
196
+ {party} people
197
+
198
+ If you won\'t be able to make it or need to modify your reservation, please let us know.
199
+
200
+ &nbsp;
201
+
202
+ <em>This message was sent by {site_link} on {current_time}.</em>',
203
+ 'Default email sent to users as a reminder about their booking request. The tags in {brackets} will be replaced by the appropriate content and should be left in place. HTML is allowed, but be aware that many email clients do not handle HTML very well.',
204
+ 'restaurant-reservations'
205
+ ),
206
+
207
+ // Email template sent to a user when a booking request is rejected
208
+ 'subject-late-user' => sprintf( _x( 'You\'re late for your booking at %s', 'Default email subject sent to user when they are late for their booking. %s will be replaced by the website name', 'restaurant-reservations' ), get_bloginfo( 'name' ) ),
209
+ 'template-late-user' => _x( 'Hi {user_name},
210
+
211
+ You previously made a reservation with the following details:
212
+
213
+ {date}
214
+ {user_name}
215
+ {party} people
216
+
217
+ If you won\'t be able to make it, please let us know so that we can release your table to other guests.
218
+
219
+ &nbsp;
220
+
221
+ <em>This message was sent by {site_link} on {current_time}.</em>',
222
+ 'Default email sent to users when they are late for their booking request. The tags in {brackets} will be replaced by the appropriate content and should be left in place. HTML is allowed, but be aware that many email clients do not handle HTML very well.',
223
  'restaurant-reservations'
224
  ),
225
 
265
  * @sa https://github.com/NateWr/simple-admin-pages
266
  */
267
  public function load_settings_panel() {
268
+ global $rtb_controller;
269
 
270
  require_once( RTB_PLUGIN_DIR . '/lib/simple-admin-pages/simple-admin-pages.php' );
271
  $sap = sap_initialize_library(
272
  $args = array(
273
+ 'version' => '2.2.0',
274
  'lib_url' => RTB_PLUGIN_URL . '/lib/simple-admin-pages/',
275
  )
276
  );
284
  'parent_menu' => 'rtb-bookings',
285
  'description' => '',
286
  'capability' => 'manage_options',
287
+ 'default_tab' => 'rtb-schedule-tab',
288
+ )
289
+ );
290
+
291
+ $sap->add_section(
292
+ 'rtb-settings',
293
+ array(
294
+ 'id' => 'rtb-schedule-tab',
295
+ 'title' => __( 'Booking Schedule', 'restaurant-reservations' ),
296
+ 'is_tab' => true,
297
+ )
298
+ );
299
+
300
+ $sap->add_section(
301
+ 'rtb-settings',
302
+ array(
303
+ 'id' => 'rtb-schedule',
304
+ 'title' => __( 'Scheduling Options', 'restaurant-reservations' ),
305
+ 'tab' => 'rtb-schedule-tab',
306
+ )
307
+ );
308
+
309
+ // Translateable strings for scheduler components
310
+ $scheduler_strings = array(
311
+ 'add_rule' => __( 'Add new scheduling rule', 'restaurant-reservations' ),
312
+ 'weekly' => _x( 'Weekly', 'Format of a scheduling rule', 'restaurant-reservations' ),
313
+ 'monthly' => _x( 'Monthly', 'Format of a scheduling rule', 'restaurant-reservations' ),
314
+ 'date' => _x( 'Date', 'Format of a scheduling rule', 'restaurant-reservations' ),
315
+ 'weekdays' => _x( 'Days of the week', 'Label for selecting days of the week in a scheduling rule', 'restaurant-reservations' ),
316
+ 'month_weeks' => _x( 'Weeks of the month', 'Label for selecting weeks of the month in a scheduling rule', 'restaurant-reservations' ),
317
+ 'date_label' => _x( 'Date', 'Label to select a date for a scheduling rule', 'restaurant-reservations' ),
318
+ 'time_label' => _x( 'Time', 'Label to select a time slot for a scheduling rule', 'restaurant-reservations' ),
319
+ 'allday' => _x( 'All day', 'Label to set a scheduling rule to last all day', 'restaurant-reservations' ),
320
+ 'start' => _x( 'Start', 'Label for the starting time of a scheduling rule', 'restaurant-reservations' ),
321
+ 'end' => _x( 'End', 'Label for the ending time of a scheduling rule', 'restaurant-reservations' ),
322
+ 'set_time_prompt' => _x( 'All day long. Want to %sset a time slot%s?', 'Prompt displayed when a scheduling rule is set without any time restrictions', 'restaurant-reservations' ),
323
+ 'toggle' => _x( 'Open and close this rule', 'Toggle a scheduling rule open and closed', 'restaurant-reservations' ),
324
+ 'delete' => _x( 'Delete rule', 'Delete a scheduling rule', 'restaurant-reservations' ),
325
+ 'delete_schedule' => __( 'Delete scheduling rule', 'restaurant-reservations' ),
326
+ 'never' => _x( 'Never', 'Brief default description of a scheduling rule when no weekdays or weeks are included in the rule', 'restaurant-reservations' ),
327
+ 'weekly_always' => _x( 'Every day', 'Brief default description of a scheduling rule when all the weekdays/weeks are included in the rule', 'restaurant-reservations' ),
328
+ 'monthly_weekdays' => _x( '%s on the %s week of the month', 'Brief default description of a scheduling rule when some weekdays are included on only some weeks of the month. %s should be left alone and will be replaced by a comma-separated list of days and weeks in the following format: M, T, W on the first, second week of the month', 'restaurant-reservations' ),
329
+ 'monthly_weeks' => _x( '%s week of the month', 'Brief default description of a scheduling rule when some weeks of the month are included but all or no weekdays are selected. %s should be left alone and will be replaced by a comma-separated list of weeks in the following format: First, second week of the month', 'restaurant-reservations' ),
330
+ 'all_day' => _x( 'All day', 'Brief default description of a scheduling rule when no times are set', 'restaurant-reservations' ),
331
+ 'before' => _x( 'Ends at', 'Brief default description of a scheduling rule when an end time is set but no start time. If the end time is 6pm, it will read: Ends at 6pm', 'restaurant-reservations' ),
332
+ 'after' => _x( 'Starts at', 'Brief default description of a scheduling rule when a start time is set but no end time. If the start time is 6pm, it will read: Starts at 6pm', 'restaurant-reservations' ),
333
+ 'separator' => _x( '&mdash;', 'Separator between times of a scheduling rule', 'restaurant-reservations' ),
334
+ );
335
+
336
+ $sap->add_setting(
337
+ 'rtb-settings',
338
+ 'rtb-schedule',
339
+ 'scheduler',
340
+ array(
341
+ 'id' => 'schedule-open',
342
+ 'title' => __( 'Schedule', 'restaurant-reservations' ),
343
+ 'description' => __( 'Define the weekly schedule during which you accept bookings.', 'restaurant-reservations' ),
344
+ 'weekdays' => array(
345
+ 'monday' => _x( 'Mo', 'Monday abbreviation', 'restaurant-reservations' ),
346
+ 'tuesday' => _x( 'Tu', 'Tuesday abbreviation', 'restaurant-reservations' ),
347
+ 'wednesday' => _x( 'We', 'Wednesday abbreviation', 'restaurant-reservations' ),
348
+ 'thursday' => _x( 'Th', 'Thursday abbreviation', 'restaurant-reservations' ),
349
+ 'friday' => _x( 'Fr', 'Friday abbreviation', 'restaurant-reservations' ),
350
+ 'saturday' => _x( 'Sa', 'Saturday abbreviation', 'restaurant-reservations' ),
351
+ 'sunday' => _x( 'Su', 'Sunday abbreviation', 'restaurant-reservations' )
352
+ ),
353
+ 'time_format' => $this->get_setting( 'time-format' ),
354
+ 'date_format' => $this->get_setting( 'date-format' ),
355
+ 'disable_weeks' => true,
356
+ 'disable_date' => true,
357
+ 'strings' => $scheduler_strings,
358
+ )
359
+ );
360
+
361
+ $scheduler_strings['all_day'] = _x( 'Closed all day', 'Brief default description of a scheduling exception when no times are set', 'restaurant-reservations' );
362
+ $sap->add_setting(
363
+ 'rtb-settings',
364
+ 'rtb-schedule',
365
+ 'scheduler',
366
+ array(
367
+ 'id' => 'schedule-closed',
368
+ 'title' => __( 'Exceptions', 'restaurant-reservations' ),
369
+ 'description' => __( "Define special opening hours for holidays, events or other needs. Leave the time empty if you're closed all day.", 'restaurant-reservations' ),
370
+ 'time_format' => $this->get_setting( 'time-format' ),
371
+ 'date_format' => $this->get_setting( 'date-format' ),
372
+ 'disable_weekdays' => true,
373
+ 'disable_weeks' => true,
374
+ 'strings' => $scheduler_strings,
375
+ )
376
+ );
377
+
378
+ $sap->add_setting(
379
+ 'rtb-settings',
380
+ 'rtb-schedule',
381
+ 'select',
382
+ array(
383
+ 'id' => 'early-bookings',
384
+ 'title' => __( 'Early Bookings', 'restaurant-reservations' ),
385
+ 'description' => __( 'Select how early customers can make their booking. (Administrators and Booking Managers are not restricted by this setting.)', 'restaurant-reservations' ),
386
+ 'blank_option' => false,
387
+ 'options' => array(
388
+ '' => __( 'Any time', 'restaurant-reservations' ),
389
+ '1' => __( 'From 1 day in advance', 'restaurant-reservations' ),
390
+ '7' => __( 'From 1 week in advance', 'restaurant-reservations' ),
391
+ '14' => __( 'From 2 weeks in advance', 'restaurant-reservations' ),
392
+ '30' => __( 'From 30 days in advance', 'restaurant-reservations' ),
393
+ '90' => __( 'From 90 days in advance', 'restaurant-reservations' ),
394
+ )
395
+ )
396
+ );
397
+
398
+ $sap->add_setting(
399
+ 'rtb-settings',
400
+ 'rtb-schedule',
401
+ 'select',
402
+ array(
403
+ 'id' => 'late-bookings',
404
+ 'title' => __( 'Late Bookings', 'restaurant-reservations' ),
405
+ 'description' => __( 'Select how late customers can make their booking. (Administrators and Booking Managers are not restricted by this setting.)', 'restaurant-reservations' ),
406
+ 'blank_option' => false,
407
+ 'options' => array(
408
+ '' => __( 'Up to the last minute', 'restaurant-reservations' ),
409
+ '15' => __( 'At least 15 minutes in advance', 'restaurant-reservations' ),
410
+ '30' => __( 'At least 30 minutes in advance', 'restaurant-reservations' ),
411
+ '45' => __( 'At least 45 minutes in advance', 'restaurant-reservations' ),
412
+ '60' => __( 'At least 1 hour in advance', 'restaurant-reservations' ),
413
+ '240' => __( 'At least 4 hours in advance', 'restaurant-reservations' ),
414
+ '1440' => __( 'At least 24 hours in advance', 'restaurant-reservations' ),
415
+ 'same_day' => __( 'Block same-day bookings', 'restaurant-reservations' ),
416
+ )
417
+ )
418
+ );
419
+
420
+ $sap->add_setting(
421
+ 'rtb-settings',
422
+ 'rtb-schedule',
423
+ 'select',
424
+ array(
425
+ 'id' => 'date-onload',
426
+ 'title' => __( 'Date Pre-selection', 'restaurant-reservations' ),
427
+ 'description' => __( 'When the booking form is loaded, should it automatically attempt to select a valid date?', 'restaurant-reservations' ),
428
+ 'blank_option' => false,
429
+ 'options' => array(
430
+ '' => __( 'Select today if valid', 'restaurant-reservations' ),
431
+ 'soonest' => __( 'Select today or next valid date', 'restaurant-reservations' ),
432
+ 'empty' => __( 'Leave empty', 'restaurant-reservations' ),
433
+ )
434
+ )
435
+ );
436
+
437
+ $sap->add_setting(
438
+ 'rtb-settings',
439
+ 'rtb-schedule',
440
+ 'select',
441
+ array(
442
+ 'id' => 'time-interval',
443
+ 'title' => __( 'Time Interval', 'restaurant-reservations' ),
444
+ 'description' => __( 'Select the number of minutes between each available time.', 'restaurant-reservations' ),
445
+ 'blank_option' => false,
446
+ 'options' => array(
447
+ '' => __( 'Every 30 minutes', 'restaurant-reservations' ),
448
+ '15' => __( 'Every 15 minutes', 'restaurant-reservations' ),
449
+ '10' => __( 'Every 10 minutes', 'restaurant-reservations' ),
450
+ '5' => __( 'Every 5 minutes', 'restaurant-reservations' ),
451
+ )
452
+ )
453
+ );
454
+
455
+ $sap->add_setting(
456
+ 'rtb-settings',
457
+ 'rtb-schedule',
458
+ 'select',
459
+ array(
460
+ 'id' => 'week-start',
461
+ 'title' => __( 'Week Starts On', 'restaurant-reservations' ),
462
+ 'description' => __( 'Select the first day of the week', 'restaurant-reservations' ),
463
+ 'blank_option' => false,
464
+ 'options' => array(
465
+ '0' => __( 'Sunday', 'restaurant-reservations' ),
466
+ '1' => __( 'Monday', 'restaurant-reservations' ),
467
+ )
468
+ )
469
+ );
470
+
471
+ $sap->add_section(
472
+ 'rtb-settings',
473
+ array(
474
+ 'id' => 'rtb-basic',
475
+ 'title' => __( 'Basic', 'restaurant-reservations' ),
476
+ 'is_tab' => true,
477
  )
478
  );
479
 
482
  array(
483
  'id' => 'rtb-general',
484
  'title' => __( 'General', 'restaurant-reservations' ),
485
+ 'tab' => 'rtb-basic',
486
  )
487
  );
488
 
529
  )
530
  );
531
 
532
+ $sap->add_setting(
533
+ 'rtb-settings',
534
+ 'rtb-general',
535
+ 'select',
536
+ array(
537
+ 'id' => 'auto-confirm-max-party-size',
538
+ 'title' => __( 'Automatically Confirm Below Party Size', 'restaurant-reservations' ),
539
+ 'description' => __( 'Set a maximum party size below which all bookings will be automatically confirmed.', 'restaurant-reservations' ),
540
+ 'blank_option' => false,
541
+ 'default' => $this->defaults['auto-confirm-max-party-size'],
542
+ 'options' => $this->get_party_size_setting_options( false ),
543
+ )
544
+ );
545
+
546
  $sap->add_setting(
547
  'rtb-settings',
548
  'rtb-general',
576
  array(
577
  'id' => 'rtb-booking-form',
578
  'title' => __( 'Booking Form', 'restaurant-reservations' ),
579
+ 'tab' => 'rtb-basic',
580
  )
581
  );
582
 
624
  array(
625
  'id' => 'rtb-security',
626
  'title' => __( 'Security', 'restaurant-reservations' ),
627
+ 'tab' => 'rtb-basic',
628
  )
629
  );
630
 
655
  array(
656
  'id' => 'rtb-privacy',
657
  'title' => __( 'Privacy', 'restaurant-reservations' ),
658
+ 'tab' => 'rtb-basic',
659
  )
660
  );
661
 
666
  array(
667
  'id' => 'require-consent',
668
  'title' => __( 'Require Consent', 'restaurant-reservations' ),
669
+ 'description' => __( 'Require customers to consent to the collection of their details when making a booking. This may be required to comply with privacy laws in your country.', 'restaurant-reservations' )
670
  )
671
  );
672
 
698
  )
699
  );
700
 
701
+ if ( ! $rtb_controller->permissions->check_permission('premium_view_bookings') ) {
702
+ $premium_view_bookings_permissions = array(
703
+ 'disabled' => true,
704
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
705
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
706
+ );
707
+ }
708
+ else { $premium_view_bookings_permissions = array(); }
709
+
710
+ if ( ! $rtb_controller->permissions->check_permission('premium_table_restrictions') ) {
711
+ $premium_table_restrictions_permissions = array(
712
+ 'disabled' => true,
713
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
714
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
715
+ );
716
+ }
717
+ else { $premium_table_restrictions_permissions = array(); }
718
+
719
  $sap->add_section(
720
  'rtb-settings',
721
  array(
722
+ 'id' => 'rtb-premium',
723
+ 'title' => __( 'Premium', 'restaurant-reservations' ),
724
  'is_tab' => true,
725
  )
726
  );
727
 
728
+ $sap->add_section(
729
+ 'rtb-settings',
730
+ array_merge(
731
+ array(
732
+ 'id' => 'rtb-view-bookings-form',
733
+ 'title' => __( 'View Bookings Form', 'restaurant-reservations' ),
734
+ 'tab' => 'rtb-premium',
735
+ ),
736
+ $premium_view_bookings_permissions
737
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
  );
 
739
  $sap->add_setting(
740
  'rtb-settings',
741
+ 'rtb-view-bookings-form',
742
+ 'post',
743
  array(
744
+ 'id' => 'view-bookings-page',
745
+ 'title' => __( 'View Bookings Page', 'restaurant-reservations' ),
746
+ 'description' => __( 'Select a page on your site to automatically display the view bookings form. Useful for restaurant staff checking guests in as they arrive.', 'restaurant-reservations' ),
747
+ 'blank_option' => true,
748
+ 'args' => array(
749
+ 'post_type' => 'page',
750
+ 'posts_per_page' => -1,
751
+ 'post_status' => 'publish',
 
 
 
752
  ),
 
 
 
 
 
753
  )
754
  );
 
 
755
  $sap->add_setting(
756
  'rtb-settings',
757
+ 'rtb-view-bookings-form',
758
+ 'toggle',
759
  array(
760
+ 'id' => 'view-bookings-private',
761
+ 'title' => __( 'Keep View Bookings Private', 'restaurant-reservations' ),
762
+ 'description' => __( 'Only display the view bookings form to visitors who are logged in to your site.', 'restaurant-reservations' )
 
 
 
 
 
763
  )
764
  );
 
765
  $sap->add_setting(
766
  'rtb-settings',
767
+ 'rtb-view-bookings-form',
768
+ 'toggle',
769
  array(
770
+ 'id' => 'view-bookings-arrivals',
771
+ 'title' => __( 'Check In Arrivals', 'restaurant-reservations' ),
772
+ 'description' => __( 'Allow guests to be checked in as they arrive. This is necessary for late arrival reminders to work correctly.', 'restaurant-reservations' )
 
 
 
 
 
 
 
 
 
773
  )
774
  );
775
 
776
+ $sap->add_section(
777
+ 'rtb-settings',
778
+ array_merge(
779
+ array(
780
+ 'id' => 'rtb-table-seat-assignments',
781
+ 'title' => __( 'Table/Seat Restrictions', 'restaurant-reservations' ),
782
+ 'tab' => 'rtb-premium',
783
+ ),
784
+ $premium_table_restrictions_permissions
785
+ )
786
+ );
787
  $sap->add_setting(
788
  'rtb-settings',
789
+ 'rtb-table-seat-assignments',
790
+ 'count',
791
  array(
792
+ 'id' => 'rtb-dining-block-length',
793
+ 'title' => __( 'Dining Block Length', 'restaurant-reservations' ),
794
+ 'description' => __( 'How long does a meal generally last? This setting affects a table and/or seat unavailable for after someone makes a reservation.', 'restaurant-reservations' ),
795
+ 'default' => $this->defaults['rtb-dining-block-length'],
796
  'blank_option' => false,
797
+ 'min_value' => 10,
798
+ 'max_value' => 240,
799
+ 'increment' => 5,
800
+ 'units' => array( 'minutes' => 'Minutes' )
 
 
 
 
 
 
801
  )
802
  );
 
803
  $sap->add_setting(
804
  'rtb-settings',
805
+ 'rtb-table-seat-assignments',
806
+ 'toggle',
807
  array(
808
+ 'id' => 'rtb-enable-max-tables',
809
+ 'title' => __( 'Enable Max Reservations', 'restaurant-reservations' ),
810
+ 'description' => __( 'Only allow a certain number of reservations (set below) during a specific time. Once the maximum number of reservations has been reached, visitors will only be able to select other reservation times.', 'restaurant-reservations' )
811
+ )
812
+ );
813
+ $sap->add_setting(
814
+ 'rtb-settings',
815
+ 'rtb-table-seat-assignments',
816
+ 'count',
817
+ array(
818
+ 'id' => 'rtb-max-tables-count',
819
+ 'title' => __( 'Max Reservations', 'restaurant-reservations' ),
820
+ 'description' => __( 'How many reservations, if enabled above, should be allowed at the same time? Set dining block length setting above to change how long a meal typically lasts.', 'restaurant-reservations' ),
821
+ 'min_value' => 1,
822
+ 'max_value' => 100,
823
+ 'increment' => 1
824
+ )
825
+ );
826
+ $sap->add_setting(
827
+ 'rtb-settings',
828
+ 'rtb-table-seat-assignments',
829
+ 'count',
830
+ array(
831
+ 'id' => 'auto-confirm-max-reservations',
832
+ 'title' => __( 'Automatically Confirm Below Reservation Number', 'restaurant-reservations' ),
833
+ 'description' => __( 'Set a maximum number of reservations at one time below which all bookings will be automatically confirmed.', 'restaurant-reservations' ),
834
+ 'min_value' => 1,
835
+ 'max_value' => 100,
836
+ 'increment' => 1
837
+ )
838
+ );
839
+ $sap->add_setting(
840
+ 'rtb-settings',
841
+ 'rtb-table-seat-assignments',
842
+ 'count',
843
+ array(
844
+ 'id' => 'auto-confirm-max-seats',
845
+ 'title' => __( 'Automatically Confirm Below Seats Number', 'restaurant-reservations' ),
846
+ 'description' => __( 'Set a maximum number of seats at one time below which all bookings will be automatically confirmed.', 'restaurant-reservations' ),
847
+ 'min_value' => 1,
848
+ 'max_value' => 400,
849
+ 'increment' => 1
850
  )
851
  );
852
 
853
+ if ( ! $rtb_controller->permissions->check_permission('mailchimp') ) {
854
+ $mailchimp_permissions = array(
855
+ 'disabled' => true,
856
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
857
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
858
+ );
859
+ }
860
+ else { $mailchimp_permissions = array(); }
861
+
862
+ $sap->add_section(
863
+ 'rtb-settings',
864
+ array_merge(
865
+ array(
866
+ 'id' => 'rtb-mailchimp',
867
+ 'title' => __( 'MailChimp', 'restaurant-reservations' ),
868
+ 'tab' => 'rtb-premium',
869
+ ),
870
+ $mailchimp_permissions
871
+ )
872
+ );
873
+
874
+ // MailChimp API key
875
  $sap->add_setting(
876
  'rtb-settings',
877
+ 'rtb-mailchimp',
878
+ 'mcapikey',
879
  array(
880
+ 'id' => 'mc-apikey',
881
+ 'title' => __( 'MailChimp API Key', 'restaurant-reservations' ),
882
+ 'description' => '<a href="https://admin.mailchimp.com/account/api/" target="_blank">' . __( 'Retrieve or create an API key for your MailChimp account', 'restaurant-reservations' ) . '</a>',
883
+ 'placeholder' => __( 'API Key', 'restaurant-reservations' ),
884
+ 'string_status_connected' => __( 'Connected', 'restaurant-reservations' ),
885
+ 'string_status_error' => __( 'Invalid Key', 'restaurant-reservations' ),
886
+ )
887
+ );
888
+
889
+ // Don't show the settings until an API key has been successfully entered
890
+ if ( $rtb_controller->mailchimp->status === true ) {
891
+
892
+ // MailChimp list and merge fields
893
+ $sap->add_setting(
894
+ 'rtb-settings',
895
+ 'rtb-mailchimp',
896
+ 'mclistmerge',
897
+ array(
898
+ 'id' => 'mc-lists',
899
+ 'title' => __( 'Subscribe List', 'restaurant-reservations' ),
900
+ 'description' => __( 'New booking requests will be subscribed to this list.', 'restaurant-reservations' ),
901
+ 'fields' => $rtb_controller->mailchimp->merge_fields,
902
+ 'string_loading' => __( 'Loading...', 'restaurant-reservations' ),
903
+ )
904
+ );
905
+
906
+ // Opt-out Option
907
+ $sap->add_setting(
908
+ 'rtb-settings',
909
+ 'rtb-mailchimp',
910
+ 'select',
911
+ array(
912
+ 'id' => 'mc-optout',
913
+ 'title' => __( 'Opt-in', 'restaurant-reservations' ),
914
+ 'description' => __( 'Whether to show an option for users to opt-in to being signed up for your mailing list when making a reservation.', 'restaurant-reservations' ),
915
+ 'blank_option' => false,
916
+ 'options' => array(
917
+ '' => __( 'Show opt-in prompt', 'restaurant-reservations' ),
918
+ 'checked' => __( 'Show pre-checked opt-in prompt', 'restaurant-reservations' ),
919
+ 'no' => __( 'Don\'t show opt-in prompt', 'restaurant-reservations' ),
920
+ ),
921
  )
922
+ );
923
+
924
+ // Opt-out prompt text
925
+ $sap->add_setting(
926
+ 'rtb-settings',
927
+ 'rtb-mailchimp',
928
+ 'text',
929
+ array(
930
+ 'id' => 'mc-optprompt',
931
+ 'title' => __( 'Opt-in Prompt', 'restaurant-reservations' ),
932
+ 'description' => __( 'Text to display with the opt-in option.', 'restaurant-reservations' ),
933
+ 'placeholder' => $this->defaults['mc-optprompt'],
934
+ )
935
+ );
936
+ }
937
+
938
+ if ( ! $rtb_controller->permissions->check_permission('designer') ) {
939
+ $designer_permissions = array(
940
+ 'disabled' => true,
941
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
942
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
943
+ );
944
+ }
945
+ else { $designer_permissions = array(); }
946
+
947
+ $sap->add_section(
948
+ 'rtb-settings',
949
+ array(
950
+ 'id' => 'rtb-notifications-tab',
951
+ 'title' => __( 'Notifications', 'restaurant-reservations' ),
952
+ 'is_tab' => true,
953
  )
954
  );
955
 
956
+ $sap->add_section(
957
+ 'rtb-settings',
958
+ array_merge(
959
+ array(
960
+ 'id' => 'rtb-email-templates',
961
+ 'title' => __( 'Email Templates', 'restaurant-reservations' ),
962
+ 'tab' => 'rtb-notifications-tab',
963
+ ),
964
+ $designer_permissions
965
+ )
966
+ );
967
+
968
+ $notifications_settings_url = admin_url( '/admin.php?page=rtb-settings&tab=rtb-notifications-tab' );
969
+ $customizer_url = admin_url( '/customize.php?etfrtb_designer=1&return=' . urlencode( $notifications_settings_url ) );
970
+
971
  $sap->add_setting(
972
  'rtb-settings',
973
+ 'rtb-email-templates',
974
+ 'html',
975
  array(
976
+ 'id' => 'etfrtb-load-customizer',
977
+ 'title' => __( 'Email Designer', 'restaurant-reservations' ),
978
+ 'html' => '<a href="' . esc_url( $customizer_url ) . '" class="button">' . __( 'Launch Email Designer', 'restaurant-reservations' ) . '</a>',
979
+ 'position' => array( 'top' ),
 
 
 
 
980
  )
981
  );
982
 
984
  'rtb-settings',
985
  array(
986
  'id' => 'rtb-notifications',
987
+ 'title' => __( 'General', 'restaurant-reservations' ),
988
+ 'tab' => 'rtb-notifications-tab',
989
  )
990
  );
991
 
1020
  array(
1021
  'id' => 'admin-email-option',
1022
  'title' => __( 'Admin Notification', 'restaurant-reservations' ),
1023
+ 'description' => __( 'Send an email notification to an administrator when a new booking is requested.', 'restaurant-reservations' )
1024
  )
1025
  );
1026
 
1040
  'rtb-settings',
1041
  array(
1042
  'id' => 'rtb-notifications-templates',
1043
+ 'title' => __( 'Notification Emails', 'restaurant-reservations' ),
1044
+ 'tab' => 'rtb-notifications-tab',
1045
  'description' => __( 'Adjust the messages that are emailed to users and admins during the booking process.', 'restaurant-reservations' ),
1046
  )
1047
  );
1167
  )
1168
  );
1169
 
1170
+ if ( ! $rtb_controller->permissions->check_permission('reminders') ) {
1171
+ $reminders_permissions = array(
1172
+ 'disabled' => true,
1173
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
1174
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
1175
+ );
1176
+ }
1177
+ else { $reminders_permissions = array(); }
1178
+
1179
+ // $sap->add_section(
1180
+ // 'rtb-settings',
1181
+ // array_merge(
1182
+ // array(
1183
+ // 'id' => 'rtb-reservation-reminders',
1184
+ // 'title' => __( 'Reservation Reminders', 'restaurant-reservations' ),
1185
+ // 'tab' => 'rtb-notifications-tab',
1186
+ // 'description' => __( 'Set up reservation and late arrival reminders.' ),
1187
+ // ),
1188
+ // $reminders_permissions
1189
+ // )
1190
+ // );
1191
+
1192
+ // $sap->add_setting(
1193
+ // 'rtb-settings',
1194
+ // 'rtb-reservation-reminders',
1195
+ // 'count',
1196
+ // array(
1197
+ // 'id' => 'time-reminder-user',
1198
+ // 'title' => __( 'Reservation Reminder Before Time', 'restaurant-reservations' ),
1199
+ // 'description' => __( 'How long before a reservation should a reminder email be sent? Leave blank to not send a reservation reminder.', 'restaurant-reservations' ),
1200
+ // 'min_value' => 1,
1201
+ // 'max_value' => 60,
1202
+ // 'increment' => 1,
1203
+ // 'units' => array(
1204
+ // 'minutes' => 'Minutes',
1205
+ // 'hours' => 'Hours',
1206
+ // 'days' => 'Days'
1207
+ // )
1208
+ // )
1209
+ // );
1210
+
1211
+ // $sap->add_setting(
1212
+ // 'rtb-settings',
1213
+ // 'rtb-reservation-reminders',
1214
+ // 'text',
1215
+ // array(
1216
+ // 'id' => 'subject-reminder-user',
1217
+ // 'title' => __( 'Reservation Reminder Email Subject', 'restaurant-reservations' ),
1218
+ // 'description' => __( 'The email subject a user should receive as a reminder about their reservation.', 'restaurant-reservations' ),
1219
+ // 'placeholder' => $this->defaults['subject-reminder-user'],
1220
+ // )
1221
+ // );
1222
+
1223
+ // $sap->add_setting(
1224
+ // 'rtb-settings',
1225
+ // 'rtb-reservation-reminders',
1226
+ // 'editor',
1227
+ // array(
1228
+ // 'id' => 'template-reminder-user',
1229
+ // 'title' => __( 'Reservation Reminder Email', 'restaurant-reservations' ),
1230
+ // 'description' => __( 'Enter the email a user should receive as a reminder about their reservation.', 'restaurant-reservations' ),
1231
+ // 'default' => $this->defaults['template-reminder-user'],
1232
+ // )
1233
+ // );
1234
+
1235
+ // $sap->add_setting(
1236
+ // 'rtb-settings',
1237
+ // 'rtb-notifications-templates',
1238
+ // 'count',
1239
+ // array(
1240
+ // 'id' => 'time-late-user',
1241
+ // 'title' => __( 'Late for Reservation Time', 'restaurant-reservations' ),
1242
+ // 'description' => __( 'How long after being late for a reservation should a late arrival email be sent? Leave blank to not send a late arrival email.', 'restaurant-reservations' ),
1243
+ // 'min_value' => 1,
1244
+ // 'max_value' => 60,
1245
+ // 'increment' => 1,
1246
+ // 'units' => array(
1247
+ // 'minutes' => 'Minutes',
1248
+ // 'hours' => 'Hours',
1249
+ // )
1250
+ // )
1251
+ // );
1252
+
1253
+ // $sap->add_setting(
1254
+ // 'rtb-settings',
1255
+ // 'rtb-reservation-reminders',
1256
+ // 'text',
1257
+ // array(
1258
+ // 'id' => 'subject-late-user',
1259
+ // 'title' => __( 'Late for Reservation Email Subject', 'restaurant-reservations' ),
1260
+ // 'description' => __( 'The email subject a user should receive when they are late for their reservation.', 'restaurant-reservations' ),
1261
+ // 'placeholder' => $this->defaults['subject-late-user'],
1262
+ // )
1263
+ // );
1264
+
1265
+ // $sap->add_setting(
1266
+ // 'rtb-settings',
1267
+ // 'rtb-reservation-reminders',
1268
+ // 'editor',
1269
+ // array(
1270
+ // 'id' => 'template-late-user',
1271
+ // 'title' => __( 'Late for Reservation Email', 'restaurant-reservations' ),
1272
+ // 'description' => __( 'Enter the email a user should receive when they are late for their reservation.', 'restaurant-reservations' ),
1273
+ // 'default' => $this->defaults['template-late-user'],
1274
+ // )
1275
+ // );
1276
+
1277
  $sap->add_section(
1278
  'rtb-settings',
1279
  array(
1280
  'id' => 'rtb-notifications-advanced',
1281
  'title' => __( 'Advanced', 'restaurant-reservations' ),
1282
  'description' => __( "Modifying the settings below can prevent your emails from being delivered. Do not make changes unless you know what you're doing.", 'restaurant-reservations' ),
1283
+ 'tab' => 'rtb-notifications-tab',
1284
  )
1285
  );
1286
 
1296
  )
1297
  );
1298
 
1299
+ if ( ! $rtb_controller->permissions->check_permission('export') ) {
1300
+ $export_permissions = array(
1301
+ 'disabled' => true,
1302
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
1303
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
1304
+ );
1305
+ }
1306
+ else { $export_permissions = array(); }
1307
+
1308
+ //Create a tab for export settings
1309
+ $sap->add_section(
1310
+ 'rtb-settings',
1311
+ array(
1312
+ 'id' => 'rtb-export-tab',
1313
+ 'title' => _x( 'Export', 'Label for the Export tab in the settings page', 'restaurant-reservations' ),
1314
+ 'is_tab' => true,
1315
+ )
1316
+ );
1317
+
1318
+ $sap->add_section(
1319
+ 'rtb-settings',
1320
+ array_merge(
1321
+ array(
1322
+ 'id' => 'rtb-export',
1323
+ 'title' => __( 'Settings', 'restaurant-reservations' ),
1324
+ 'tab' => 'rtb-export-tab',
1325
+ ),
1326
+ $export_permissions
1327
+ )
1328
+ );
1329
+
1330
+ $sap->add_setting(
1331
+ 'rtb-settings',
1332
+ 'rtb-export',
1333
+ 'select',
1334
+ array(
1335
+ 'id' => 'ebfrtb-paper-size',
1336
+ 'title' => __( 'Paper Size', 'restaurant-reservations' ),
1337
+ 'description' => __( 'Select your preferred paper size.', 'restaurant-reservations' ),
1338
+ 'blank_option' => false,
1339
+ 'options' => array(
1340
+ 'A4' => 'A4',
1341
+ 'LETTER' => 'Letter (U.S.)',
1342
+ )
1343
+ )
1344
+ );
1345
+
1346
+ $sap->add_setting(
1347
+ 'rtb-settings',
1348
+ 'rtb-export',
1349
+ 'select',
1350
+ array(
1351
+ 'id' => 'ebfrtb-pdf-lib',
1352
+ 'title' => __( 'PDF Renderer', 'restaurant-reservations' ),
1353
+ 'description' => __( 'mPDF looks nicer but is not compatible with all servers. Select TCPDF only if you get errors when trying to export a PDF.', 'restaurant-reservations' ),
1354
+ 'blank_option' => false,
1355
+ 'options' => array(
1356
+ 'mpdf' => 'mPDF',
1357
+ 'tcpdf' => 'TCPDF',
1358
+ ),
1359
+ )
1360
+ );
1361
+
1362
+ $sap->add_setting(
1363
+ 'rtb-settings',
1364
+ 'rtb-export',
1365
+ 'text',
1366
+ array(
1367
+ 'id' => 'ebfrtb-csv-date-format',
1368
+ 'title' => __( 'Excel/CSV Date Format', 'restaurant-reservations' ),
1369
+ 'description' => __( 'Enter a custom date format to be used when generating Excel/CSV exports if you want the format to be different than your WordPress setting. This is useful if you need the date in a machine-readable format.', 'restaurant-reservations' ),
1370
+ 'placeholder' => $this->defaults['ebfrtb-csv-date-format'],
1371
+ )
1372
+ );
1373
+
1374
+ if ( ! $rtb_controller->permissions->check_permission('styling') ) {
1375
+ $styling_permissions = array(
1376
+ 'disabled' => true,
1377
+ 'disabled_image'=> 'https://www.etoilewebdesign.com/wp-content/uploads/2018/06/Logo-White-Filled40-px.png',
1378
+ 'purchase_link' => 'https://www.fivestarplugins.com/plugins/five-star-restaurant-reservations/'
1379
+ );
1380
+ }
1381
+ else { $styling_permissions = array(); }
1382
+
1383
+ // Create a tab for styling settings
1384
+ $sap->add_section(
1385
+ 'rtb-settings',
1386
+ array(
1387
+ 'id' => 'rtb-styling-settings-tab',
1388
+ 'title' => __( 'Styling', 'restaurant-reservations' ),
1389
+ 'is_tab' => true
1390
+ )
1391
+ );
1392
+
1393
+ $sap->add_section(
1394
+ 'rtb-settings',
1395
+ array_merge(
1396
+ array(
1397
+ 'id' => 'rtb-reservation-form-styling',
1398
+ 'title' => __( 'Reservation Form', 'restaurant-reservations' ),
1399
+ 'tab' => 'rtb-styling-settings-tab',
1400
+ ),
1401
+ $styling_permissions
1402
+ )
1403
+ );
1404
+
1405
+ $sap->add_setting(
1406
+ 'rtb-settings',
1407
+ 'rtb-reservation-form-styling',
1408
+ 'radio',
1409
+ array(
1410
+ 'id' => 'rtb-styling-layout',
1411
+ 'title' => __( 'Layout', 'restaurant-reservations' ),
1412
+ 'description' => __( 'Choose which layout you want to use for your reservation form', 'restaurant-reservations' ),
1413
+ 'options' => array(
1414
+ 'default' => 'Default',
1415
+ 'contemporary' => 'Contemporary',
1416
+ 'columns' => 'Columns',
1417
+ )
1418
+ )
1419
+ );
1420
+
1421
+ $sap->add_setting(
1422
+ 'rtb-settings',
1423
+ 'rtb-reservation-form-styling',
1424
+ 'text',
1425
+ array(
1426
+ 'id' => 'rtb-styling-section-title-font-family',
1427
+ 'title' => __( 'Section Title Font Family', 'restaurant-reservations' ),
1428
+ 'description' => __( 'Choose the font family for the section titles. (Please note that the font family must already be loaded on the site. This does not load it.)', 'restaurant-reservations' )
1429
+ )
1430
+ );
1431
+ $sap->add_setting(
1432
+ 'rtb-settings',
1433
+ 'rtb-reservation-form-styling',
1434
+ 'text',
1435
+ array(
1436
+ 'id' => 'rtb-styling-section-title-font-size',
1437
+ 'title' => __( 'Section Title Font Size', 'restaurant-reservations' ),
1438
+ 'description' => __( 'Choose the font size for the section titles. Include the unit (e.g. 20px or 2em).', 'restaurant-reservations' )
1439
+ )
1440
+ );
1441
+ $sap->add_setting(
1442
+ 'rtb-settings',
1443
+ 'rtb-reservation-form-styling',
1444
+ 'colorpicker',
1445
+ array(
1446
+ 'id' => 'rtb-styling-section-title-color',
1447
+ 'title' => __( 'Section Title Color', 'restaurant-reservations' ),
1448
+ 'description' => __( 'Choose the color for the section titles.', 'restaurant-reservations' )
1449
+ )
1450
+ );
1451
+
1452
+ $sap->add_setting(
1453
+ 'rtb-settings',
1454
+ 'rtb-reservation-form-styling',
1455
+ 'colorpicker',
1456
+ array(
1457
+ 'id' => 'rtb-styling-section-background-color',
1458
+ 'title' => __( 'Section Background Color', 'restaurant-reservations' ),
1459
+ 'description' => __( 'Choose the background color for the form sections.', 'restaurant-reservations' )
1460
+ )
1461
+ );
1462
+ $sap->add_setting(
1463
+ 'rtb-settings',
1464
+ 'rtb-reservation-form-styling',
1465
+ 'text',
1466
+ array(
1467
+ 'id' => 'rtb-styling-section-border-size',
1468
+ 'title' => __( 'Section Border Size', 'restaurant-reservations' ),
1469
+ 'description' => __( 'Choose the border size for the form sections (in the default layout). Include the unit (e.g. 2px).', 'restaurant-reservations' )
1470
+ )
1471
+ );
1472
+ $sap->add_setting(
1473
+ 'rtb-settings',
1474
+ 'rtb-reservation-form-styling',
1475
+ 'colorpicker',
1476
+ array(
1477
+ 'id' => 'rtb-styling-section-border-color',
1478
+ 'title' => __( 'Section Border Color', 'restaurant-reservations' ),
1479
+ 'description' => __( 'Choose the color for the section border (in the default layout).', 'restaurant-reservations' )
1480
+ )
1481
+ );
1482
+
1483
+ $sap->add_setting(
1484
+ 'rtb-settings',
1485
+ 'rtb-reservation-form-styling',
1486
+ 'text',
1487
+ array(
1488
+ 'id' => 'rtb-styling-label-font-family',
1489
+ 'title' => __( 'Label Font Family', 'restaurant-reservations' ),
1490
+ 'description' => __( 'Choose the font family for the form field labels. (Please note that the font family must already be loaded on the site. This does not load it.)', 'restaurant-reservations' )
1491
+ )
1492
+ );
1493
+ $sap->add_setting(
1494
+ 'rtb-settings',
1495
+ 'rtb-reservation-form-styling',
1496
+ 'text',
1497
+ array(
1498
+ 'id' => 'rtb-styling-label-font-size',
1499
+ 'title' => __( 'Label Font Size', 'restaurant-reservations' ),
1500
+ 'description' => __( 'Choose the font size for the form field labels. Include the unit (e.g. 20px or 2em).', 'restaurant-reservations' )
1501
+ )
1502
+ );
1503
+ $sap->add_setting(
1504
+ 'rtb-settings',
1505
+ 'rtb-reservation-form-styling',
1506
+ 'colorpicker',
1507
+ array(
1508
+ 'id' => 'rtb-styling-label-color',
1509
+ 'title' => __( 'Label Color', 'restaurant-reservations' ),
1510
+ 'description' => __( 'Choose the color for the form field labels.', 'restaurant-reservations' )
1511
+ )
1512
+ );
1513
+
1514
+ $sap->add_setting(
1515
+ 'rtb-settings',
1516
+ 'rtb-reservation-form-styling',
1517
+ 'colorpicker',
1518
+ array(
1519
+ 'id' => 'rtb-styling-add-message-button-background-color',
1520
+ 'title' => __( '"Add a Message" Button Background Color', 'restaurant-reservations' ),
1521
+ 'description' => __( 'Choose the background color for the "Add a Message" button.', 'restaurant-reservations' )
1522
+ )
1523
+ );
1524
+ $sap->add_setting(
1525
+ 'rtb-settings',
1526
+ 'rtb-reservation-form-styling',
1527
+ 'colorpicker',
1528
+ array(
1529
+ 'id' => 'rtb-styling-add-message-button-background-hover-color',
1530
+ 'title' => __( '"Add a Message" Button Background Hover Color', 'restaurant-reservations' ),
1531
+ 'description' => __( 'Choose the background color for the "Add a Message" button on hover.', 'restaurant-reservations' )
1532
+ )
1533
+ );
1534
+ $sap->add_setting(
1535
+ 'rtb-settings',
1536
+ 'rtb-reservation-form-styling',
1537
+ 'colorpicker',
1538
+ array(
1539
+ 'id' => 'rtb-styling-add-message-button-text-color',
1540
+ 'title' => __( '"Add a Message" Button Text Color', 'restaurant-reservations' ),
1541
+ 'description' => __( 'Choose the text color for the "Add a Message" button.', 'restaurant-reservations' )
1542
+ )
1543
+ );
1544
+ $sap->add_setting(
1545
+ 'rtb-settings',
1546
+ 'rtb-reservation-form-styling',
1547
+ 'colorpicker',
1548
+ array(
1549
+ 'id' => 'rtb-styling-add-message-button-text-hover-color',
1550
+ 'title' => __( '"Add a Message" Button Text Hover Color', 'restaurant-reservations' ),
1551
+ 'description' => __( 'Choose the text color for the "Add a Message" button on hover.', 'restaurant-reservations' )
1552
+ )
1553
+ );
1554
+
1555
+ $sap->add_setting(
1556
+ 'rtb-settings',
1557
+ 'rtb-reservation-form-styling',
1558
+ 'colorpicker',
1559
+ array(
1560
+ 'id' => 'rtb-styling-request-booking-button-background-color',
1561
+ 'title' => __( '"Request Booking" Button Background Color', 'restaurant-reservations' ),
1562
+ 'description' => __( 'Choose the background color for the "Request Booking" button.', 'restaurant-reservations' )
1563
+ )
1564
+ );
1565
+ $sap->add_setting(
1566
+ 'rtb-settings',
1567
+ 'rtb-reservation-form-styling',
1568
+ 'colorpicker',
1569
+ array(
1570
+ 'id' => 'rtb-styling-request-booking-button-background-hover-color',
1571
+ 'title' => __( '"Request Booking" Button Background Hover Color', 'restaurant-reservations' ),
1572
+ 'description' => __( 'Choose the background color for the "Request Booking" button on hover.', 'restaurant-reservations' )
1573
+ )
1574
+ );
1575
+ $sap->add_setting(
1576
+ 'rtb-settings',
1577
+ 'rtb-reservation-form-styling',
1578
+ 'colorpicker',
1579
+ array(
1580
+ 'id' => 'rtb-styling-request-booking-button-text-color',
1581
+ 'title' => __( '"Request Booking" Button Text Color', 'restaurant-reservations' ),
1582
+ 'description' => __( 'Choose the text color for the "Request Booking" button.', 'restaurant-reservations' )
1583
+ )
1584
+ );
1585
+ $sap->add_setting(
1586
+ 'rtb-settings',
1587
+ 'rtb-reservation-form-styling',
1588
+ 'colorpicker',
1589
+ array(
1590
+ 'id' => 'rtb-styling-request-booking-button-text-hover-color',
1591
+ 'title' => __( '"Request Booking" Button Text Hover Color', 'restaurant-reservations' ),
1592
+ 'description' => __( 'Choose the text color for the "Request Booking" button on hover.', 'restaurant-reservations' )
1593
+ )
1594
+ );
1595
+
1596
  $sap = apply_filters( 'rtb_settings_page', $sap );
1597
 
1598
  $sap->add_admin_menus();
includes/class-designer.php ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php defined( 'ABSPATH' ) || exit;
2
+ /**
3
+ * Class to deliver data to the templates
4
+ *
5
+ * @since 0.1
6
+ */
7
+ class etfrtbDesigner {
8
+
9
+ /**
10
+ * The email type
11
+ *
12
+ * @param string $email_type Email type, eg - `rejected-user`
13
+ * @since 0.1
14
+ */
15
+ public $email_type;
16
+
17
+ /**
18
+ * The associated notification email
19
+ *
20
+ * This may be null if we're previewing a template.
21
+ *
22
+ * @param rtbNotification $notification
23
+ * @since 0.1
24
+ */
25
+ public $notification;
26
+
27
+ /**
28
+ * Available templates for this notification
29
+ *
30
+ * @param array $template_options
31
+ * @since 0.1
32
+ */
33
+ public $template_options;
34
+
35
+ /**
36
+ * Data to be fetched in the templates
37
+ *
38
+ * @param array $_data Key/value store
39
+ * @since 0.1
40
+ */
41
+ private $_data = array();
42
+
43
+ /**
44
+ * Set up the designer object with a specific email type. Most email types
45
+ * also expect an associated notification. But may not always have one if
46
+ * the email is being previewed.
47
+ *
48
+ * @param string $email_type Type of email being handled
49
+ * @param rtbNotification $notification
50
+ * @since 0.1
51
+ */
52
+ public function setup( $email_type, $notification = null ) {
53
+
54
+ global $rtb_controller;
55
+
56
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
57
+
58
+ $this->set( 'color_primary', get_option( 'etfrtb_color_primary', '#66BB7F' ) );
59
+ $this->set( 'color_primary_text', get_option( 'etfrtb_color_primary_text', '#FFFFFF' ) );
60
+ $this->set( 'color_button', get_option( 'etfrtb_color_button', '#66BB7F' ) );
61
+ $this->set( 'color_button_text', get_option( 'etfrtb_color_button_text', '#FFFFFF' ) );
62
+ $this->set( 'acknowledgement', get_option( 'etfrtb_acknowledgement', __( 'This message was sent by {site_link} on {current_time}. You are receiving this email because we received a booking request from this email address.', 'email-templates-for-rtb' ) ) );
63
+
64
+ $this->set_logo( 'logo', get_option( 'etfrtb_logo', false ) );
65
+
66
+ if ( is_a( $notification, 'rtbNotification' ) ) {
67
+ $this->set_notification( $notification );
68
+ }
69
+
70
+ $this->set_email_type( $email_type );
71
+
72
+ do_action( 'etfrtb_designer_setup', $this );
73
+ }
74
+
75
+ /**
76
+ * Get data for this email
77
+ *
78
+ * @param string $key Key of data to retrieve
79
+ * @since 0.1
80
+ */
81
+ public function get( $key ) {
82
+
83
+ if ( isset( $this->_data[$key] ) ) {
84
+ return $this->_data[$key];
85
+ }
86
+
87
+ switch ( $key ) {
88
+
89
+ case 'notification' :
90
+ return null;
91
+
92
+ case 'default' :
93
+ return '';
94
+ }
95
+ }
96
+
97
+ /**
98
+ * Set data for this email
99
+ *
100
+ * @param string $key
101
+ * @param mixed $value
102
+ * @since 0.1
103
+ */
104
+ public function set( $key, $value ) {
105
+ $this->_data[$key] = $value;
106
+ }
107
+
108
+ /**
109
+ * Set the logo and get height and width values
110
+ *
111
+ * @param string $url Optional url. If not provided, it will fetch the set
112
+ * option.
113
+ * @since 0.1
114
+ */
115
+ public function set_logo( $url = '' ) {
116
+
117
+ $logo = get_option( 'etfrtb_logo', false );
118
+
119
+ if ( !$logo ) {
120
+ return;
121
+ }
122
+
123
+ $logo = wp_get_attachment_image_src( $logo, 'etfrtb_logo' );
124
+
125
+ if ( !$logo ) {
126
+ return;
127
+ }
128
+
129
+ // Ensure that the image is not wider or taller than 200px, and adjust
130
+ // the width/height values if necessary, so that exact pixel sizes can
131
+ // be put into the templates
132
+ $width = $logo[1];
133
+ $height = $logo[2];
134
+ if ( $width > 200 || $height > 200 ) {
135
+ $shrink = $width > $height ? 200 / $width : 200 / $height;
136
+ $width = round( $width * $shrink );
137
+ $height = round( $height * $shrink );
138
+ }
139
+
140
+ $this->set( 'logo', $logo[0] );
141
+ $this->set( 'logo_width', $width );
142
+ $this->set( 'logo_height', $height );
143
+ }
144
+
145
+ /**
146
+ * Set the email type and fetch associated data
147
+ *
148
+ * @param rtbBooking $booking
149
+ * @since 0.1
150
+ */
151
+ public function set_email_type( $email_type ) {
152
+
153
+ global $rtb_controller;
154
+
155
+ $this->email_type = $email_type;
156
+
157
+ switch( $this->email_type ) {
158
+
159
+ case 'booking-admin' :
160
+ $this->set( 'template', get_option( 'etfrtb_booking_admin_template', 'conversations.php' ) );
161
+ $this->set( 'lead', get_option( 'etfrtb_booking_admin_headline', $rtb_controller->settings->get_setting( 'subject-booking-admin' ) ) );
162
+ $this->set( 'footer_message', get_option( 'etfrtb_booking_admin_footer_message', '' ) );
163
+ break;
164
+
165
+ case 'booking-user' :
166
+ $this->set( 'template', get_option( 'etfrtb_booking_user_template', 'conversations.php' ) );
167
+ $this->set( 'lead', get_option( 'etfrtb_booking_user_headline', $rtb_controller->settings->get_setting( 'subject-booking-user' ) ) );
168
+ $this->set( 'footer_message', get_option( 'etfrtb_booking_user_footer_message', '' ) );
169
+ break;
170
+
171
+ case 'confirmed-user' :
172
+ $this->set( 'template', get_option( 'etfrtb_confirmed_user_template', 'conversations.php' ) );
173
+ $this->set( 'lead', get_option( 'etfrtb_confirmed_user_headline', $rtb_controller->settings->get_setting( 'subject-confirmed-user' ) ) );
174
+ $this->set( 'footer_message', get_option( 'etfrtb_confirmed_user_footer_message', '' ) );
175
+ break;
176
+
177
+ case 'rejected-user' :
178
+ $this->set( 'template', get_option( 'etfrtb_rejected_user_template', 'conversations.php' ) );
179
+ $this->set( 'lead', get_option( 'etfrtb_rejected_user_headline', $rtb_controller->settings->get_setting( 'subject-rejected-user' ) ) );
180
+ $this->set( 'book_again', get_option( 'etfrtb_rejected_user_book_again', __( 'Book Another Time', 'email-templates-for-rtb' ) ) );
181
+ $this->set( 'footer_message', get_option( 'etfrtb_rejected_user_footer_message', '' ) );
182
+ break;
183
+
184
+ case 'admin-notice' :
185
+ $this->set( 'template', get_option( 'etfrtb_admin_notice_template', 'conversations.php' ) );
186
+ $this->set( 'lead', get_option( 'etfrtb_admin_notice_headline', $rtb_controller->settings->get_setting( 'subject-admin-notice' ) ) );
187
+ $this->set( 'footer_message', get_option( 'etfrtb_admin_notice_footer_message', '' ) );
188
+ break;
189
+ }
190
+
191
+ // Set up default notification templates when no actual notification
192
+ // is being sent. This is used for previewing templates in the
193
+ // customizer.
194
+ if ( !is_a( $this->notification, 'rtbNotificationEmail' ) ) {
195
+
196
+ global $rtb_controller;
197
+
198
+ switch( $this->email_type ) {
199
+
200
+ case 'booking-admin' :
201
+ $this->set( 'subject', $rtb_controller->settings->get_setting( 'subject-booking-admin' ) );
202
+ $this->set( 'content', wpautop( $rtb_controller->settings->get_setting( 'template-booking-admin' ) ) );
203
+ break;
204
+
205
+ case 'booking-user' :
206
+ $this->set( 'subject', $rtb_controller->settings->get_setting( 'subject-booking-user' ) );
207
+ $this->set( 'content', wpautop( $rtb_controller->settings->get_setting( 'template-booking-user' ) ) );
208
+ break;
209
+
210
+ case 'confirmed-user' :
211
+ $this->set( 'subject', $rtb_controller->settings->get_setting( 'subject-confirmed-user' ) );
212
+ $this->set( 'content', wpautop( $rtb_controller->settings->get_setting( 'template-confirmed-user' ) ) );
213
+ break;
214
+
215
+ case 'rejected-user' :
216
+ $this->set( 'subject', $rtb_controller->settings->get_setting( 'subject-rejected-user' ) );
217
+ $this->set( 'content', wpautop( $rtb_controller->settings->get_setting( 'template-rejected-user' ) ) );
218
+ break;
219
+
220
+ case 'admin-notice' :
221
+ $this->set( 'subject', $rtb_controller->settings->get_setting( 'subject-admin-notice' ) );
222
+ $this->set( 'content', __( "This is an example of an Admin Update email. You can send a message to a customer from the list of bookings in your admin panel." ) );
223
+ break;
224
+ }
225
+ }
226
+ }
227
+
228
+ /**
229
+ * Set the notification data for this email
230
+ *
231
+ * @param rtbNotification $notification
232
+ * @since 0.1
233
+ */
234
+ public function set_notification( $notification ) {
235
+ $this->notification = $notification;
236
+ $this->set( 'subject', $notification->subject );
237
+ $this->set( 'content', $notification->message );
238
+ }
239
+
240
+ /**
241
+ * Render the final email content
242
+ *
243
+ * Loads the appropriate template and returns the output.
244
+ *
245
+ * @since 0.1
246
+ */
247
+ public function render() {
248
+
249
+ // Return content with no template if none is selected
250
+ if ( !$this->get( 'template' ) ) {
251
+ return $this->get( 'content' );
252
+ }
253
+
254
+ $template_dirs = apply_filters(
255
+ 'etfrtb_template_directories',
256
+ array(
257
+ get_stylesheet_directory() . '/etfrtb_templates/',
258
+ get_template_directory() . '/etfrtb_templates/',
259
+ RTB_PLUGIN_DIR . '/templates/',
260
+ )
261
+ );
262
+
263
+ $file = '';
264
+ foreach( $template_dirs as $dir ) {
265
+ if ( file_exists( $dir . $this->get( 'template' ) ) ) {
266
+ $file = $dir . $this->get( 'template' );
267
+ break;
268
+ }
269
+ }
270
+
271
+ // Return content with no template if no matching file is found
272
+ if ( empty( $file ) ) {
273
+ return $this->get( 'content' );
274
+ }
275
+
276
+ ob_start();
277
+ include $file;
278
+ $output = ob_get_clean();
279
+
280
+ // Process any template tags in the final output
281
+ if ( is_a( $this->notification, 'rtbNotificationEmail' ) ) {
282
+ $output = $this->notification->process_template( $output );
283
+ }
284
+
285
+ return $output;
286
+ }
287
+ }
includes/custom_fields_pointers.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Set up admin pointer tooltips to describe editor features on initial load
4
+ *
5
+ * @since 0.1
6
+ */
7
+ if ( !function_exists( 'cffrtb_register_pointers' ) ) {
8
+ function cffrtb_register_pointers( $pointers ) {
9
+
10
+ // Admin pointers
11
+ $pointers[] = array(
12
+ 'id' => 'cffrtb-add-new',
13
+ 'target' => '.add-new-h2.add-field',
14
+ 'options' => array(
15
+ 'content' => sprintf(
16
+ '<h3>%s</h3><p>%s</p>',
17
+ esc_html__( 'Add New Field', 'custom-fields-for-rtb' ),
18
+ esc_html__( 'Add a new field or fieldset to your form.', 'custom-fields-for-rtb' )
19
+ ),
20
+ 'position' => array( 'edge' => 'top', 'align' => 'left' ),
21
+ ),
22
+ );
23
+ $pointers[] = array(
24
+ 'id' => 'cffrtb-order-fields',
25
+ 'target' => '.fields .field',
26
+ 'options' => array(
27
+ 'content' => sprintf(
28
+ '<h3>%s</h3><p>%s</p>',
29
+ esc_html__( 'Re-order Fields', 'custom-fields-for-rtb' ),
30
+ esc_html__( 'Drag and drop a field to re-order it or move it to a different fieldset.', 'custom-fields-for-rtb' )
31
+ ),
32
+ 'position' => array( 'edge' => 'top', 'align' => 'left' ),
33
+ ),
34
+ );
35
+ $pointers[] = array(
36
+ 'id' => 'cffrtb-change-labels',
37
+ 'target' => '.field a.label',
38
+ 'options' => array(
39
+ 'content' => sprintf(
40
+ '<h3>%s</h3><p>%s</p>',
41
+ esc_html__( 'Change Labels', 'custom-fields-for-rtb' ),
42
+ esc_html__( "Click the pencil icon to edit a field's label.", 'custom-fields-for-rtb' )
43
+ ),
44
+ 'position' => array( 'edge' => 'left', 'align' => 'right' ),
45
+ ),
46
+ );
47
+ $pointers[] = array(
48
+ 'id' => 'cffrtb-disable-field',
49
+ 'target' => '.field a.delete',
50
+ 'options' => array(
51
+ 'content' => sprintf(
52
+ '<h3>%s</h3><p>%s</p>',
53
+ esc_html__( 'Remove Fields', 'custom-fields-for-rtb' ),
54
+ esc_html__( 'Click the X icon to remove a field. Some fields are required and can not be removed.', 'custom-fields-for-rtb' )
55
+ ),
56
+ 'position' => array( 'edge' => 'left', 'align' => 'right' ),
57
+ ),
58
+ );
59
+ $pointers[] = array(
60
+ 'id' => 'cffrtb-disable-field',
61
+ 'target' => '#cffrtb-disabled .reset-all',
62
+ 'options' => array(
63
+ 'content' => sprintf(
64
+ '<h3>%s</h3><p>%s</p>',
65
+ esc_html__( 'Disabled Fields', 'custom-fields-for-rtb' ),
66
+ esc_html__( 'Default fields that have been removed will be listed in this column. If you get yourself into a bind, click the "Revert to Default" button that will appear to wipe away all of your changes. Be careful, though. This will delete any custom fields you have created.', 'custom-fields-for-rtb' )
67
+ ),
68
+ 'position' => array( 'edge' => 'top', 'align' => 'left' ),
69
+ ),
70
+ );
71
+ $pointers[] = array(
72
+ 'id' => 'cffrtb-add-new',
73
+ 'target' => '.add-new-h2.add-field',
74
+ 'options' => array(
75
+ 'content' => sprintf(
76
+ '<h3>%s</h3><p>%s</p>',
77
+ esc_html__( 'Get Started', 'custom-fields-for-rtb' ),
78
+ esc_html__( 'Got it? Get started by adding a new custom field.', 'custom-fields-for-rtb' )
79
+ ),
80
+ 'position' => array( 'edge' => 'top', 'align' => 'left' ),
81
+ ),
82
+ );
83
+
84
+
85
+ $dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
86
+ $live_pointers = array();
87
+ foreach( $pointers as $pointer ) {
88
+
89
+ if ( in_array( $pointer['id'], $dismissed ) || empty( $pointer ) || empty( $pointer['id'] ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) ) {
90
+ continue;
91
+ }
92
+
93
+ $live_pointers[] = $pointer;
94
+ }
95
+
96
+ return $live_pointers;
97
+ }
98
+ add_filter( 'cffrtb_pointers', 'cffrtb_register_pointers' );
99
+ }
includes/integrations/business-profile.php CHANGED
@@ -196,3 +196,181 @@ function rtb_bp_food_schema_types() {
196
  'Winery' => __( '--- Winery', 'restaurant-reservations' ),
197
  );
198
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  'Winery' => __( '--- Winery', 'restaurant-reservations' ),
197
  );
198
  }
199
+
200
+
201
+ /**
202
+ * Email template functions that are dependent on Business Profile
203
+ *
204
+ * @since 2.0.0
205
+ */
206
+
207
+ /**
208
+ * Add Contact Card details to the designer
209
+ *
210
+ * @param stdClass $designer Handler which populates the email template
211
+ * @param rtbBooking $booking Associated booking
212
+ * @since 0.1
213
+ */
214
+ function etfrtb_bp_designer_setup( $designer ) {
215
+ global $rtb_controller;
216
+
217
+ // Get Business Profile details if that plugin is active
218
+ if ( !function_exists( 'bpfwp_setting' ) or ! $rtb_controller->permissions->check_permission( 'templates' ) ) {
219
+ return;
220
+ }
221
+
222
+ $location = false;
223
+ if ( is_a( $designer->get( 'notification' ), 'rtbNotification' ) &&
224
+ is_a( $designer->get( 'notification')->booking, 'rtbBooking' ) &&
225
+ isset( $designer->get( 'notification')->booking->location ) ) {
226
+ $location = $designer->get( 'notification')->booking->location;
227
+ }
228
+
229
+ $designer->set( 'address', bpfwp_setting( 'address', $location ) );
230
+ $designer->set( 'phone', bpfwp_setting( 'phone', $location ) );
231
+ $designer->set( 'contact-email', bpfwp_setting( 'contact-email', $location ) );
232
+ $designer->set( 'contact-page', bpfwp_setting( 'contact-page', $location ) );
233
+ $designer->set( 'bpfwp_setting', bpfwp_setting( 'bpfwp_setting', $location ) );
234
+ if ( $location ) {
235
+ $designer->set( 'location_name', get_the_title( $location ) );
236
+ $designer->set( 'location_url', get_permalink( $location ) );
237
+ }
238
+
239
+ switch( $designer->email_type ) {
240
+
241
+ case 'booking-admin' :
242
+ $designer->set( 'show_contact', get_option( 'etfrtb_booking_admin_footer_contact', 1 ) );
243
+ break;
244
+
245
+ case 'booking-user' :
246
+ $designer->set( 'show_contact', get_option( 'etfrtb_booking_user_footer_contact', 1 ) );
247
+ break;
248
+
249
+ case 'confirmed-user' :
250
+ $designer->set( 'show_contact', get_option( 'etfrtb_confirmed_user_footer_contact', 1 ) );
251
+ break;
252
+
253
+ case 'rejected-user' :
254
+ $designer->set( 'show_contact', get_option( 'etfrtb_rejected_user_footer_contact', 1 ) );
255
+ break;
256
+
257
+ case 'admin-notice' :
258
+ $designer->set( 'show_contact', get_option( 'etfrtb_admin_notice_footer_contact', 1 ) );
259
+ break;
260
+ }
261
+ }
262
+ add_filter( 'etfrtb_designer_setup', 'etfrtb_bp_designer_setup' );
263
+
264
+ /**
265
+ * Add Customizer Controls
266
+ *
267
+ * @since 0.1
268
+ */
269
+ function etfrtb_bp_customize_register( $wp_customize ) {
270
+ global $rtb_controller;
271
+
272
+ // Get Business Profile details if that plugin is active
273
+ if ( !function_exists( 'bpfwp_setting' ) or ! $rtb_controller->permissions->check_permission( 'templates' ) ) {
274
+ return;
275
+ }
276
+
277
+ etfrtb_bp_customize_register_settings( $wp_customize );
278
+
279
+ $footer_contact_settings = array(
280
+ 'type' => 'radio',
281
+ 'label' => __( 'Footer Contact Details', 'restaurant-reservations' ),
282
+ 'choices' => array(
283
+ '1' => __( 'Yes', 'restaurant-reservations' ),
284
+ '0' => __( 'No', 'restaurant-reservations' ),
285
+ ),
286
+ 'description' => 'Display your address and phone number in the footer?',
287
+ );
288
+
289
+ $wp_customize->add_control(
290
+ 'etfrtb_booking_admin_footer_contact',
291
+ array_merge(
292
+ $footer_contact_settings,
293
+ array(
294
+ 'section' => 'etfrtb-content-booking-admin',
295
+ 'settings' => 'etfrtb_booking_admin_footer_contact',
296
+ )
297
+ )
298
+ );
299
+
300
+ $wp_customize->add_control(
301
+ 'etfrtb_booking_user_footer_contact',
302
+ array_merge(
303
+ $footer_contact_settings,
304
+ array(
305
+ 'section' => 'etfrtb-content-booking-user',
306
+ 'settings' => 'etfrtb_booking_user_footer_contact',
307
+ )
308
+ )
309
+ );
310
+
311
+ $wp_customize->add_control(
312
+ 'etfrtb_confirmed_user_footer_contact',
313
+ array_merge(
314
+ $footer_contact_settings,
315
+ array(
316
+ 'section' => 'etfrtb-content-confirmed-user',
317
+ 'settings' => 'etfrtb_confirmed_user_footer_contact',
318
+ )
319
+ )
320
+ );
321
+
322
+ $wp_customize->add_control(
323
+ 'etfrtb_rejected_user_footer_contact',
324
+ array_merge(
325
+ $footer_contact_settings,
326
+ array(
327
+ 'section' => 'etfrtb-content-rejected-user',
328
+ 'settings' => 'etfrtb_rejected_user_footer_contact',
329
+ )
330
+ )
331
+ );
332
+
333
+ $wp_customize->add_control(
334
+ 'etfrtb_admin_notice_footer_contact',
335
+ array_merge(
336
+ $footer_contact_settings,
337
+ array(
338
+ 'section' => 'etfrtb-content-admin-notice',
339
+ 'settings' => 'etfrtb_admin_notice_footer_contact',
340
+ )
341
+ )
342
+ );
343
+ }
344
+ add_action( 'customize_register_email_designer' , 'etfrtb_bp_customize_register', 20 );
345
+
346
+ /**
347
+ * Register Customizer Settings
348
+ *
349
+ * This is loaded with every customizer instance to ensure that the settings
350
+ * are available when the instance is saved
351
+ *
352
+ * @since 0.1
353
+ */
354
+ function etfrtb_bp_customize_register_settings( $wp_customize ) {
355
+ global $rtb_controller;
356
+
357
+ // Get Business Profile details if that plugin is active
358
+ if ( !function_exists( 'bpfwp_setting' ) or ! $rtb_controller->permissions->check_permission( 'templates' ) ) {
359
+ return;
360
+ }
361
+
362
+ $footer_contact_settings = array(
363
+ 'default' => 1,
364
+ 'sanitize_callback' => 'sanitize_text_field',
365
+ 'capability' => 'manage_options',
366
+ 'type' => 'option',
367
+ 'autoload' => false,
368
+ );
369
+
370
+ $wp_customize->add_setting( 'etfrtb_booking_admin_footer_contact', $footer_contact_settings );
371
+ $wp_customize->add_setting( 'etfrtb_booking_user_footer_contact', $footer_contact_settings );
372
+ $wp_customize->add_setting( 'etfrtb_confirmed_user_footer_contact', $footer_contact_settings );
373
+ $wp_customize->add_setting( 'etfrtb_rejected_user_footer_contact', $footer_contact_settings );
374
+ $wp_customize->add_setting( 'etfrtb_admin_notice_footer_contact', $footer_contact_settings );
375
+ }
376
+ add_action( 'customize_register', 'etfrtb_bp_customize_register_settings' );
includes/load-customizer.php ADDED
@@ -0,0 +1,711 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php defined( 'ABSPATH' ) || exit;
2
+ /**
3
+ * Functions to manage the live email preview in the customizer
4
+ */
5
+
6
+ if ( isset( $_GET['etfrtb_designer'] ) ) {
7
+ add_filter( 'customize_loaded_components', 'etfrtb_customize_init_blank_state' );
8
+ add_action( 'customize_controls_enqueue_scripts', 'etfrtb_customize_control_assets' );
9
+ add_action( 'customize_controls_init', 'etfrtb_customize_inject_url_param' );
10
+ add_action( 'customize_register_email_designer', 'etfrtb_customize_register' );
11
+ add_action( 'customize_preview_init', 'etfrtb_customize_preview_init' );
12
+ }
13
+
14
+ /**
15
+ * Initialize the callbacks to turn the Customizer into a "blank slate"
16
+ *
17
+ * This is the first of a series of callbacks which remove all registered
18
+ * panels, sections and controls from the Customizer. This is only done when
19
+ * the customizer is loaded with a special query arg from the notifications
20
+ * settings screen.
21
+ *
22
+ * @see https://github.com/xwp/wp-customizer-blank-slate
23
+ * @param $components Components that have been loaded
24
+ * @since 0.1
25
+ */
26
+ function etfrtb_customize_init_blank_state( $components ) {
27
+ global $rtb_controller;
28
+
29
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
30
+
31
+ // Reset the customize register actions
32
+ add_action( 'wp_loaded', 'etfrtb_customize_reset_register', 1 );
33
+
34
+ // Remove all registered components
35
+ $components = array();
36
+ return $components;
37
+ }
38
+
39
+ /**
40
+ * Prevent other constructs from being registered and register only those we
41
+ * want registered in our instance of the Customizer
42
+ *
43
+ * @since 0.1
44
+ */
45
+ function etfrtb_customize_reset_register() {
46
+
47
+ global $wp_customize;
48
+
49
+ // Prevent anything from hooking in to register controls
50
+ remove_all_actions( 'customize_register' );
51
+
52
+ $wp_customize->register_panel_type( 'WP_Customize_Panel' );
53
+ $wp_customize->register_section_type( 'WP_Customize_Section' );
54
+ $wp_customize->register_control_type( 'WP_Customize_Color_Control' );
55
+ $wp_customize->register_control_type( 'WP_Customize_Image_Control' );
56
+ $wp_customize->register_control_type( 'WP_Customize_Media_Control' );
57
+
58
+ // Register our Customizer controls
59
+ do_action( 'customize_register_email_designer', $wp_customize );
60
+ }
61
+
62
+ /**
63
+ * Register customizer controls to manage the email designer
64
+ *
65
+ * @since 0.1
66
+ */
67
+ function etfrtb_customize_register( $wp_customize ) {
68
+ global $rtb_controller;
69
+
70
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
71
+
72
+ etfrtb_customize_register_settings( $wp_customize );
73
+
74
+ $template_selection = array( '0' => __( 'No Email Template', 'email-templates-for-rtb' ) );
75
+ foreach( $rtb_controller->email_templates->template_options as $file => $template ) {
76
+ $template_selection[$file] = $template['title'];
77
+ }
78
+
79
+ $wp_customize->add_section(
80
+ 'etfrtb_style',
81
+ array(
82
+ 'title' => __( 'Logo & Colors', 'email-templates-for-rtb' ),
83
+ )
84
+ );
85
+
86
+ $wp_customize->add_control(
87
+ new WP_Customize_Media_Control(
88
+ $wp_customize,
89
+ 'etfrtb_logo',
90
+ array(
91
+ 'section' => 'etfrtb_style',
92
+ 'label' => __( 'Logo', 'email-templates-for-rtb' ),
93
+ 'settings' => 'etfrtb_logo',
94
+ 'mime_type' => 'image',
95
+ )
96
+ )
97
+ );
98
+
99
+ $wp_customize->add_control(
100
+ new WP_Customize_Color_Control(
101
+ $wp_customize,
102
+ 'etfrtb_color_primary',
103
+ array(
104
+ 'section' => 'etfrtb_style',
105
+ 'label' => __( 'Primary Color', 'email-templates-for-rtb' ),
106
+ 'settings' => 'etfrtb_color_primary',
107
+ )
108
+ )
109
+ );
110
+
111
+ $wp_customize->add_control(
112
+ new WP_Customize_Color_Control(
113
+ $wp_customize,
114
+ 'etfrtb_color_primary_text',
115
+ array(
116
+ 'section' => 'etfrtb_style',
117
+ 'label' => __( 'Primary Text Color', 'email-templates-for-rtb' ),
118
+ 'description' => __( 'Some templates display text on a background of the Primary Color. Adjust the text color in these cases to make sure it can be read easily.', 'email-templates-for-rtb' ),
119
+ 'settings' => 'etfrtb_color_primary_text',
120
+ )
121
+ )
122
+ );
123
+
124
+ $wp_customize->add_control(
125
+ new WP_Customize_Color_Control(
126
+ $wp_customize,
127
+ 'etfrtb_color_button',
128
+ array(
129
+ 'section' => 'etfrtb_style',
130
+ 'label' => __( 'Button Color', 'email-templates-for-rtb' ),
131
+ 'description' => __( 'Some emails include a button. Select a background color for these buttons.', 'email-templates-for-rtb' ),
132
+ 'settings' => 'etfrtb_color_button',
133
+ )
134
+ )
135
+ );
136
+
137
+ $wp_customize->add_control(
138
+ new WP_Customize_Color_Control(
139
+ $wp_customize,
140
+ 'etfrtb_color_button_text',
141
+ array(
142
+ 'section' => 'etfrtb_style',
143
+ 'label' => __( 'Button Text Color', 'email-templates-for-rtb' ),
144
+ 'description' => __( 'Some templates include a button. Select a text color for these buttons', 'email-templates-for-rtb' ),
145
+ 'settings' => 'etfrtb_color_button_text',
146
+ )
147
+ )
148
+ );
149
+
150
+ $wp_customize->add_control(
151
+ 'etfrtb_acknowledgement',
152
+ array(
153
+ 'section' => 'etfrtb_style',
154
+ 'label' => __( 'Email Acknowledgement', 'email-templates-for-rtb' ),
155
+ 'settings' => 'etfrtb_acknowledgement',
156
+ 'description' => __( 'Display a brief acknowledgement of why the user is receiving this message at the bottom of the email.', 'email-templates-for-rtb' ),
157
+ )
158
+ );
159
+
160
+ // Initial booking request email for admin
161
+ $wp_customize->add_section(
162
+ 'etfrtb-content-booking-admin',
163
+ array(
164
+ 'title' => __( 'Admin Notification Email', 'email-templates-for-rtb' ),
165
+ 'description' => __( 'The email sent to the admin when a new booking is made.', 'email-templates-for-rtb' ),
166
+ )
167
+ );
168
+
169
+ $wp_customize->add_control(
170
+ 'etfrtb_booking_admin_template',
171
+ array(
172
+ 'section' => 'etfrtb-content-booking-admin',
173
+ 'settings' => 'etfrtb_booking_admin_template',
174
+ 'type' => 'select',
175
+ 'label' => __( 'Template', 'email-templates-for-rtb' ),
176
+ 'choices' => $template_selection,
177
+ )
178
+ );
179
+
180
+ $wp_customize->add_control(
181
+ 'etfrtb_booking_admin_headline',
182
+ array(
183
+ 'section' => 'etfrtb-content-booking-admin',
184
+ 'label' => __( 'Lead Sentence', 'email-templates-for-rtb' ),
185
+ 'settings' => 'etfrtb_booking_admin_headline',
186
+ 'description' => 'Add an attention-grabbing headline to this email.',
187
+ )
188
+ );
189
+
190
+ $wp_customize->add_control(
191
+ 'etfrtb_booking_admin_footer_message',
192
+ array(
193
+ 'section' => 'etfrtb-content-booking-admin',
194
+ 'label' => __( 'Footer Message', 'email-templates-for-rtb' ),
195
+ 'settings' => 'etfrtb_booking_admin_footer_message',
196
+ 'description' => 'Add a short message to the footer.',
197
+ )
198
+ );
199
+
200
+ // Initial booking request email for user
201
+ $wp_customize->add_section(
202
+ 'etfrtb-content-booking-user',
203
+ array(
204
+ 'title' => __( 'New Request Email', 'email-templates-for-rtb' ),
205
+ 'description' => __( 'The email a user receives when they make an initial booking request.', 'email-templates-for-rtb' ),
206
+ )
207
+ );
208
+
209
+ $wp_customize->add_control(
210
+ 'etfrtb_booking_user_template',
211
+ array(
212
+ 'section' => 'etfrtb-content-booking-user',
213
+ 'settings' => 'etfrtb_booking_user_template',
214
+ 'type' => 'select',
215
+ 'label' => __( 'Template', 'email-templates-for-rtb' ),
216
+ 'choices' => $template_selection,
217
+ )
218
+ );
219
+
220
+ $wp_customize->add_control(
221
+ 'etfrtb_booking_user_headline',
222
+ array(
223
+ 'section' => 'etfrtb-content-booking-user',
224
+ 'label' => __( 'Lead Sentence', 'email-templates-for-rtb' ),
225
+ 'settings' => 'etfrtb_booking_user_headline',
226
+ 'description' => 'Add an attention-grabbing headline to this email.',
227
+ )
228
+ );
229
+
230
+ $wp_customize->add_control(
231
+ 'etfrtb_booking_user_footer_message',
232
+ array(
233
+ 'section' => 'etfrtb-content-booking-user',
234
+ 'label' => __( 'Footer Message', 'email-templates-for-rtb' ),
235
+ 'settings' => 'etfrtb_booking_user_footer_message',
236
+ 'description' => 'Add a short message to the footer.',
237
+ )
238
+ );
239
+
240
+ // Booking confirmed email
241
+ $wp_customize->add_section(
242
+ 'etfrtb-content-confirmed-user',
243
+ array(
244
+ 'title' => __( 'Confirmed Email', 'email-templates-for-rtb' ),
245
+ 'description' => __( 'The email a user receives when their booking is confirmed.', 'email-templates-for-rtb' ),
246
+ )
247
+ );
248
+
249
+ $wp_customize->add_control(
250
+ 'etfrtb_confirmed_user_template',
251
+ array(
252
+ 'section' => 'etfrtb-content-confirmed-user',
253
+ 'settings' => 'etfrtb_confirmed_user_template',
254
+ 'type' => 'select',
255
+ 'label' => __( 'Template', 'email-templates-for-rtb' ),
256
+ 'choices' => $template_selection,
257
+ )
258
+ );
259
+
260
+ $wp_customize->add_control(
261
+ 'etfrtb_confirmed_user_headline',
262
+ array(
263
+ 'section' => 'etfrtb-content-confirmed-user',
264
+ 'label' => __( 'Lead Sentence', 'email-templates-for-rtb' ),
265
+ 'settings' => 'etfrtb_confirmed_user_headline',
266
+ 'description' => 'Add an attention-grabbing headline to this email.',
267
+ )
268
+ );
269
+
270
+ $wp_customize->add_control(
271
+ 'etfrtb_confirmed_user_footer_message',
272
+ array(
273
+ 'section' => 'etfrtb-content-confirmed-user',
274
+ 'label' => __( 'Footer Message', 'email-templates-for-rtb' ),
275
+ 'settings' => 'etfrtb_confirmed_user_footer_message',
276
+ 'description' => 'Add a short message to the footer.',
277
+ )
278
+ );
279
+
280
+ // Rejected email
281
+ $wp_customize->add_section(
282
+ 'etfrtb-content-rejected-user',
283
+ array(
284
+ 'title' => __( 'Rejected Email', 'email-templates-for-rtb' ),
285
+ 'description' => __( 'The email a user receives when their booking has been rejected.', 'email-templates-for-rtb' ),
286
+ )
287
+ );
288
+
289
+ $wp_customize->add_control(
290
+ 'etfrtb_rejected_user_template',
291
+ array(
292
+ 'section' => 'etfrtb-content-rejected-user',
293
+ 'settings' => 'etfrtb_rejected_user_template',
294
+ 'type' => 'select',
295
+ 'label' => __( 'Template', 'email-templates-for-rtb' ),
296
+ 'choices' => $template_selection,
297
+ )
298
+ );
299
+
300
+ $wp_customize->add_control(
301
+ 'etfrtb_rejected_user_headline',
302
+ array(
303
+ 'section' => 'etfrtb-content-rejected-user',
304
+ 'label' => __( 'Lead Sentence', 'email-templates-for-rtb' ),
305
+ 'settings' => 'etfrtb_rejected_user_headline',
306
+ 'description' => 'Add an attention-grabbing headline to this email.',
307
+ )
308
+ );
309
+
310
+ $wp_customize->add_control(
311
+ 'etfrtb_rejected_user_book_again',
312
+ array(
313
+ 'section' => 'etfrtb-content-rejected-user',
314
+ 'label' => __( 'Book Again Label', 'email-templates-for-rtb' ),
315
+ 'settings' => 'etfrtb_rejected_user_book_again',
316
+ 'description' => 'Add a label to display a button encouraging customers to book for a different time.',
317
+ )
318
+ );
319
+
320
+ $wp_customize->add_control(
321
+ 'etfrtb_rejected_user_footer_message',
322
+ array(
323
+ 'section' => 'etfrtb-content-rejected-user',
324
+ 'label' => __( 'Footer Message', 'email-templates-for-rtb' ),
325
+ 'settings' => 'etfrtb_rejected_user_footer_message',
326
+ 'description' => 'Add a short message to the footer.',
327
+ )
328
+ );
329
+
330
+ // Admin update email
331
+ $wp_customize->add_section(
332
+ 'etfrtb-content-admin-notice',
333
+ array(
334
+ 'title' => __( 'Admin Update', 'email-templates-for-rtb' ),
335
+ 'description' => sprintf(
336
+ __( 'The email a user receives when an admin sends them a custom email message from the %sbookings panel%s.', 'email-templates-for-rtb' ),
337
+ '<a href="' . admin_url( '?page=rtb-bookings' ) . '">',
338
+ '</a>'
339
+ ),
340
+ )
341
+ );
342
+
343
+ $wp_customize->add_control(
344
+ 'etfrtb_admin_notice_template',
345
+ array(
346
+ 'section' => 'etfrtb-content-admin-notice',
347
+ 'settings' => 'etfrtb_admin_notice_template',
348
+ 'type' => 'select',
349
+ 'label' => __( 'Template', 'email-templates-for-rtb' ),
350
+ 'choices' => $template_selection,
351
+ )
352
+ );
353
+
354
+ $wp_customize->add_control(
355
+ 'etfrtb_admin_notice_headline',
356
+ array(
357
+ 'section' => 'etfrtb-content-admin-notice',
358
+ 'label' => __( 'Lead Sentence', 'email-templates-for-rtb' ),
359
+ 'settings' => 'etfrtb_admin_notice_headline',
360
+ 'description' => 'Add an attention-grabbing headline to this email.',
361
+ )
362
+ );
363
+
364
+ $wp_customize->add_control(
365
+ 'etfrtb_admin_notice_footer_message',
366
+ array(
367
+ 'section' => 'etfrtb-content-admin-notice',
368
+ 'label' => __( 'Footer Message', 'email-templates-for-rtb' ),
369
+ 'settings' => 'etfrtb_admin_notice_footer_message',
370
+ 'description' => 'Add a short message to the footer.',
371
+ )
372
+ );
373
+ }
374
+
375
+ /**
376
+ * Register the customizer settings
377
+ *
378
+ * The settings must be registered both in and out of the customizer's "blank
379
+ * slate" mode. When the customizer is saved, the request is processed outside
380
+ * of the "blank slate" mode. If the setting is not registered there, the value
381
+ * will not be saved.
382
+ *
383
+ * @since 0.1
384
+ */
385
+ function etfrtb_customize_register_settings( $wp_customize ) {
386
+
387
+ global $rtb_controller;
388
+
389
+ $wp_customize->add_setting(
390
+ 'etfrtb_logo',
391
+ array(
392
+ 'default' => get_theme_mod( 'custom_logo' ),
393
+ 'sanitize_callback' => 'absint',
394
+ 'capability' => 'manage_options',
395
+ 'type' => 'option',
396
+ 'autoload' => false,
397
+ )
398
+ );
399
+
400
+ $wp_customize->add_setting(
401
+ 'etfrtb_color_primary',
402
+ array(
403
+ 'default' => '#66BB7F',
404
+ 'sanitize_callback' => 'sanitize_text_field',
405
+ 'capability' => 'manage_options',
406
+ 'type' => 'option',
407
+ 'autoload' => false,
408
+ )
409
+ );
410
+
411
+ $wp_customize->add_setting(
412
+ 'etfrtb_color_primary_text',
413
+ array(
414
+ 'default' => '#FFFFFF',
415
+ 'sanitize_callback' => 'sanitize_text_field',
416
+ 'capability' => 'manage_options',
417
+ 'type' => 'option',
418
+ 'autoload' => false,
419
+ )
420
+ );
421
+
422
+ $wp_customize->add_setting(
423
+ 'etfrtb_color_button',
424
+ array(
425
+ 'default' => '#66BB7F',
426
+ 'sanitize_callback' => 'sanitize_text_field',
427
+ 'capability' => 'manage_options',
428
+ 'type' => 'option',
429
+ 'autoload' => false,
430
+ )
431
+ );
432
+
433
+ $wp_customize->add_setting(
434
+ 'etfrtb_color_button_text',
435
+ array(
436
+ 'default' => '#FFFFFF',
437
+ 'sanitize_callback' => 'sanitize_text_field',
438
+ 'capability' => 'manage_options',
439
+ 'type' => 'option',
440
+ 'autoload' => false,
441
+ )
442
+ );
443
+
444
+ $wp_customize->add_setting(
445
+ 'etfrtb_acknowledgement',
446
+ array(
447
+ 'default' => __( 'This message was sent by {site_link} on {current_time}. You are receiving this email because we received a booking request from this email address.', 'email-templates-for-rtb' ),
448
+ 'sanitize_callback' => 'sanitize_text_field',
449
+ 'capability' => 'manage_options',
450
+ 'type' => 'option',
451
+ 'autoload' => false,
452
+ )
453
+ );
454
+
455
+ // Initial booking admin notification
456
+ $wp_customize->add_setting(
457
+ 'etfrtb_booking_admin_headline',
458
+ array(
459
+ 'default' => $rtb_controller->settings->get_setting( 'subject-booking-admin' ),
460
+ 'sanitize_callback' => 'sanitize_text_field',
461
+ 'capability' => 'manage_options',
462
+ 'type' => 'option',
463
+ 'autoload' => false,
464
+ )
465
+ );
466
+
467
+ $wp_customize->add_setting(
468
+ 'etfrtb_booking_admin_template',
469
+ array(
470
+ 'default' => 'conversations.php',
471
+ 'sanitize_callback' => 'sanitize_file_name',
472
+ 'capability' => 'manage_options',
473
+ 'type' => 'option',
474
+ 'autoload' => false,
475
+ )
476
+ );
477
+
478
+ $wp_customize->add_setting(
479
+ 'etfrtb_booking_admin_footer_message',
480
+ array(
481
+ 'default' => '',
482
+ 'sanitize_callback' => 'sanitize_text_field',
483
+ 'capability' => 'manage_options',
484
+ 'type' => 'option',
485
+ 'autoload' => false,
486
+ )
487
+ );
488
+
489
+ // Initial booking user notification
490
+ $wp_customize->add_setting(
491
+ 'etfrtb_booking_user_headline',
492
+ array(
493
+ 'default' => $rtb_controller->settings->get_setting( 'subject-booking-user' ),
494
+ 'sanitize_callback' => 'sanitize_text_field',
495
+ 'capability' => 'manage_options',
496
+ 'type' => 'option',
497
+ 'autoload' => false,
498
+ )
499
+ );
500
+
501
+ $wp_customize->add_setting(
502
+ 'etfrtb_booking_user_template',
503
+ array(
504
+ 'default' => 'conversations.php',
505
+ 'sanitize_callback' => 'sanitize_file_name',
506
+ 'capability' => 'manage_options',
507
+ 'type' => 'option',
508
+ 'autoload' => false,
509
+ )
510
+ );
511
+
512
+ $wp_customize->add_setting(
513
+ 'etfrtb_booking_user_footer_message',
514
+ array(
515
+ 'default' => '',
516
+ 'sanitize_callback' => 'sanitize_text_field',
517
+ 'capability' => 'manage_options',
518
+ 'type' => 'option',
519
+ 'autoload' => false,
520
+ )
521
+ );
522
+
523
+ // Confirmed booking user notification
524
+ $wp_customize->add_setting(
525
+ 'etfrtb_confirmed_user_headline',
526
+ array(
527
+ 'default' => $rtb_controller->settings->get_setting( 'subject-confirmed-user' ),
528
+ 'sanitize_callback' => 'sanitize_text_field',
529
+ 'capability' => 'manage_options',
530
+ 'type' => 'option',
531
+ 'autoload' => false,
532
+ )
533
+ );
534
+
535
+ $wp_customize->add_setting(
536
+ 'etfrtb_confirmed_user_template',
537
+ array(
538
+ 'default' => 'conversations.php',
539
+ 'sanitize_callback' => 'sanitize_file_name',
540
+ 'capability' => 'manage_options',
541
+ 'type' => 'option',
542
+ 'autoload' => false,
543
+ )
544
+ );
545
+
546
+ $wp_customize->add_setting(
547
+ 'etfrtb_confirmed_user_footer_message',
548
+ array(
549
+ 'default' => '',
550
+ 'sanitize_callback' => 'sanitize_text_field',
551
+ 'capability' => 'manage_options',
552
+ 'type' => 'option',
553
+ 'autoload' => false,
554
+ )
555
+ );
556
+
557
+ // Rejected email
558
+ $wp_customize->add_setting(
559
+ 'etfrtb_rejected_user_template',
560
+ array(
561
+ 'default' => 'conversations.php',
562
+ 'sanitize_callback' => 'sanitize_file_name',
563
+ 'capability' => 'manage_options',
564
+ 'type' => 'option',
565
+ 'autoload' => false,
566
+ )
567
+ );
568
+
569
+ $wp_customize->add_setting(
570
+ 'etfrtb_rejected_user_headline',
571
+ array(
572
+ 'default' => $rtb_controller->settings->get_setting( 'subject-rejected-user' ),
573
+ 'sanitize_callback' => 'sanitize_text_field',
574
+ 'capability' => 'manage_options',
575
+ 'type' => 'option',
576
+ 'autoload' => false,
577
+ )
578
+ );
579
+
580
+ $wp_customize->add_setting(
581
+ 'etfrtb_rejected_user_book_again',
582
+ array(
583
+ 'default' => __( 'Book Another Time', 'email-templates-for-rtb' ),
584
+ 'sanitize_callback' => 'sanitize_text_field',
585
+ 'capability' => 'manage_options',
586
+ 'type' => 'option',
587
+ 'autoload' => false,
588
+ )
589
+ );
590
+
591
+ $wp_customize->add_setting(
592
+ 'etfrtb_rejected_user_footer_message',
593
+ array(
594
+ 'default' => '',
595
+ 'sanitize_callback' => 'sanitize_text_field',
596
+ 'capability' => 'manage_options',
597
+ 'type' => 'option',
598
+ 'autoload' => false,
599
+ )
600
+ );
601
+
602
+ // Admin update email
603
+ $wp_customize->add_setting(
604
+ 'etfrtb_admin_notice_template',
605
+ array(
606
+ 'default' => 'conversations.php',
607
+ 'sanitize_callback' => 'sanitize_file_name',
608
+ 'capability' => 'manage_options',
609
+ 'type' => 'option',
610
+ 'autoload' => false,
611
+ )
612
+ );
613
+
614
+ $wp_customize->add_setting(
615
+ 'etfrtb_admin_notice_headline',
616
+ array(
617
+ 'default' => $rtb_controller->settings->get_setting( 'subject-admin-notice' ),
618
+ 'sanitize_callback' => 'sanitize_text_field',
619
+ 'capability' => 'manage_options',
620
+ 'type' => 'option',
621
+ 'autoload' => false,
622
+ )
623
+ );
624
+
625
+ $wp_customize->add_setting(
626
+ 'etfrtb_admin_notice_footer_message',
627
+ array(
628
+ 'default' => '',
629
+ 'sanitize_callback' => 'sanitize_text_field',
630
+ 'capability' => 'manage_options',
631
+ 'type' => 'option',
632
+ 'autoload' => false,
633
+ )
634
+ );
635
+ }
636
+ add_action( 'customize_register', 'etfrtb_customize_register_settings' );
637
+
638
+ /**
639
+ * Inject the query param into the preview URL
640
+ *
641
+ * @since 0.1
642
+ */
643
+ function etfrtb_customize_inject_url_param() {
644
+ global $wp_customize;
645
+ global $rtb_controller;
646
+
647
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
648
+
649
+ $wp_customize->set_preview_url(
650
+ add_query_arg(
651
+ array( 'etfrtb_designer' => '1' ),
652
+ $wp_customize->get_preview_url()
653
+ )
654
+ );
655
+ }
656
+
657
+ /**
658
+ * Load wp-util dependency missing in WP versions prior to 4.7
659
+ *
660
+ * @since 0.1
661
+ */
662
+ function etfrtb_customize_control_assets() {
663
+ global $rtb_controller;
664
+
665
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
666
+
667
+
668
+ $min = SCRIPT_DEBUG ? '.min' : '';
669
+
670
+ wp_enqueue_script( 'wp-util' );
671
+ wp_enqueue_script( 'etfrtb-customizer-control', RTB_PLUGIN_URL . '/assets/js/customizer-control' . $min . '.js', array( 'customize-controls' ) );
672
+ }
673
+
674
+ /**
675
+ * Initialize the customizer preview window
676
+ *
677
+ * @since 0.1
678
+ */
679
+ function etfrtb_customize_preview_init() {
680
+ global $rtb_controller;
681
+
682
+ if ( ! $rtb_controller->permissions->check_permission( 'templates' ) ) { return; }
683
+
684
+ add_rewrite_endpoint( 'etfrtb_designer', EP_NONE);
685
+ add_rewrite_endpoint( 'etfrtb_designer_template', EP_NONE);
686
+ add_rewrite_endpoint( 'etfrtb_designer_email', EP_NONE);
687
+ add_filter( 'template_include', 'etfrtb_customize_preview_load_email_designer' );
688
+ }
689
+
690
+ /**
691
+ * Load the email designer in the customizer preview
692
+ *
693
+ * @param string $template
694
+ * @since 0.1
695
+ */
696
+ function etfrtb_customize_preview_load_email_designer( $template ) {
697
+
698
+ global $wp_query;
699
+
700
+ if ( !isset( $wp_query->query['etfrtb_designer'] ) ) {
701
+ return $template;
702
+ }
703
+
704
+ $email = !isset( $wp_query->query['etfrtb_designer_email'] ) ? 'booking-user' : $wp_query->query['etfrtb_designer_email'];
705
+
706
+ $designer = new etfrtbDesigner();
707
+ $designer->setup( $email );
708
+
709
+ echo $designer->render();
710
+ exit();
711
+ }
includes/load-notifications.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php defined( 'ABSPATH' ) || exit;
2
+ /**
3
+ * Functions to intercept email notifications and inject them into templates
4
+ */
5
+
6
+ /**
7
+ * Intercept an email notification and inject it into a template
8
+ *
9
+ * @param rtbNotificationEmail $notification The notification object. A copy of
10
+ * the booking will be found at $notification->booking. The message is at
11
+ * $notification->message.
12
+ * @since 0.1
13
+ */
14
+ function etfrtb_notification_email_template( $notification ) {
15
+ global $rtb_controller;
16
+
17
+ if ( !is_a( $notification, 'rtbNotificationEmail' ) or ! $rtb_controller->permissions->check_permission( 'templates' ) ) {
18
+ return;
19
+ }
20
+
21
+ $designer = new etfrtbDesigner();
22
+
23
+ switch ( $notification->event ) {
24
+
25
+ case 'new_submission' :
26
+ if ( $notification->target == 'admin' ) {
27
+ $designer->setup( 'booking-admin', $notification );
28
+ $notification->message = $designer->render();
29
+ } elseif ( $notification->target == 'user' ) {
30
+ $designer->setup( 'booking-user', $notification );
31
+ $notification->message = $designer->render();
32
+ }
33
+ break;
34
+
35
+ case 'pending_to_confirmed' :
36
+ $designer->setup( 'confirmed-user', $notification );
37
+ $notification->message = $designer->render();
38
+ break;
39
+
40
+ case 'pending_to_closed' :
41
+ $designer->setup( 'rejected-user', $notification );
42
+ $notification->message = $designer->render();
43
+ break;
44
+
45
+ case 'admin_email_notice' :
46
+ $designer->setup( 'admin-notice', $notification );
47
+ $notification->message = $designer->render();
48
+ break;
49
+ }
50
+ }
51
+ add_action( 'rtb_send_notification_before', 'etfrtb_notification_email_template', 100 );
includes/template-functions.php CHANGED
@@ -50,6 +50,9 @@ function rtb_print_booking_form( $args = array() ) {
50
  // Enqueue assets for the form
51
  rtb_enqueue_assets();
52
 
 
 
 
53
  // Allow themes and plugins to override the booking form's HTML output.
54
  $output = apply_filters( 'rtb_booking_form_html_pre', '' );
55
  if ( !empty( $output ) ) {
@@ -148,6 +151,147 @@ function rtb_print_booking_form( $args = array() ) {
148
  }
149
  } // endif;
150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  /**
152
  * Enqueue the front-end CSS and Javascript for the booking form
153
  * @since 0.0.1
@@ -155,7 +299,7 @@ function rtb_print_booking_form( $args = array() ) {
155
  if ( !function_exists( 'rtb_enqueue_assets' ) ) {
156
  function rtb_enqueue_assets() {
157
 
158
- global $wp_scripts;
159
 
160
  wp_enqueue_style( 'rtb-booking-form' );
161
 
@@ -171,6 +315,15 @@ function rtb_enqueue_assets() {
171
 
172
  wp_enqueue_script( 'rtb-booking-form' );
173
 
 
 
 
 
 
 
 
 
 
174
  // Pass date and time format settings to the pickadate controls
175
  global $rtb_controller;
176
  wp_localize_script(
@@ -186,6 +339,7 @@ function rtb_enqueue_assets() {
186
  'schedule_closed' => $rtb_controller->settings->get_setting( 'schedule-closed' ),
187
  'early_bookings' => is_admin() && current_user_can( 'manage_bookings' ) ? '' : $rtb_controller->settings->get_setting( 'early-bookings' ),
188
  'late_bookings' => is_admin() && current_user_can( 'manage_bookings' ) ? '' : $rtb_controller->settings->get_setting( 'late-bookings' ),
 
189
  'date_onload' => $rtb_controller->settings->get_setting( 'date-onload' ),
190
  'time_interval' => $rtb_controller->settings->get_setting( 'time-interval' ),
191
  'first_day' => $rtb_controller->settings->get_setting( 'week-start' ),
@@ -513,3 +667,83 @@ function rtb_print_element_class( $slug, $additional_classes = array() ) {
513
 
514
  }
515
  } // endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  // Enqueue assets for the form
51
  rtb_enqueue_assets();
52
 
53
+ // Custom styling
54
+ rtb_add_custom_styling();
55
+
56
  // Allow themes and plugins to override the booking form's HTML output.
57
  $output = apply_filters( 'rtb_booking_form_html_pre', '' );
58
  if ( !empty( $output ) ) {
151
  }
152
  } // endif;
153
 
154
+ /**
155
+ * Create a shortcode to view and (optionally) sign in bookings
156
+ * @since 2.0.0
157
+ */
158
+ if ( !function_exists( 'rtb_display_bookings_form_shortcode' ) ) {
159
+ function rtb_display_bookings_form_shortcode( $args = array() ) {
160
+
161
+ $args = shortcode_atts(
162
+ array(
163
+ 'location' => 0,
164
+ ),
165
+ $args,
166
+ 'view-booking-form'
167
+ );
168
+
169
+ return rtb_print_view_bookings_form( $args );
170
+ }
171
+ add_shortcode( 'view-bookings-form', 'rtb_display_bookings_form_shortcode' );
172
+ } // endif;
173
+
174
+ /**
175
+ * Print the display bookings form's HTML code, including error handling and confirmation
176
+ * notices.
177
+ * @since 2.0.0
178
+ */
179
+ if ( !function_exists( 'rtb_print_view_bookings_form' ) ) {
180
+ function rtb_print_view_bookings_form( $args = array() ) {
181
+
182
+ global $rtb_controller;
183
+
184
+ // Only allow the form to be displayed once on a page
185
+ if ( $rtb_controller->display_bookings_form_rendered === true ) {
186
+ return;
187
+ } else {
188
+ $rtb_controller->display_bookings_form_rendered = true;
189
+ }
190
+
191
+ // Sanitize incoming arguments
192
+ if ( isset( $args['location'] ) ) {
193
+ $args['location'] = $rtb_controller->locations->get_location_term_id( $args['location'] );
194
+ } else {
195
+ $args['location'] = 0;
196
+ }
197
+ if ( ! isset( $args['date'] ) ) {
198
+ $args['date'] = date('Y-m-d');
199
+ }
200
+
201
+ // Enqueue assets for the form
202
+ rtb_enqueue_assets();
203
+
204
+ // Allow themes and plugins to override the booking form's HTML output.
205
+ $output = apply_filters( 'rtb_display_bookings_form_html_pre', '' );
206
+ if ( !empty( $output ) ) {
207
+ return $output;
208
+ }
209
+
210
+ require_once( RTB_PLUGIN_DIR . '/includes/Booking.class.php' );
211
+
212
+ $params = array(
213
+ 'post_type' => 'rtb-booking',
214
+ 'year' => substr($args['date'], 0, 4),
215
+ 'month' => substr($args['date'], 5, 2),
216
+ 'day' => substr($args['date'], 8, 2),
217
+ 'post_status' => array_keys( $rtb_controller->cpts->booking_statuses ),
218
+ 'orderby' => 'date',
219
+ 'order' => 'ASC'
220
+ );
221
+
222
+ $query = new WP_Query( $params );
223
+
224
+ ob_start();
225
+
226
+ ?>
227
+
228
+ <div class="rtb-view-bookings-form">
229
+
230
+ <div class='rtb-view-bookings-form-date-selector-div'>
231
+ <select class='rtb-view-bookings-form-date-selector'>
232
+ <?php for ( $i=0; $i<7; $i++ ) { ?>
233
+ <?php $timestamp = time() + $i * 3600*24; ?>
234
+ <option value='<?php echo date('Y-m-d', $timestamp); ?>' <?php echo ( date('Y-m-d', $timestamp) == $args['date'] ? 'selected="selected"' : '' ); ?> ><?php echo date('l, F jS', $timestamp); ?></option>
235
+ <?php } ?>
236
+ </select>
237
+ </div>
238
+
239
+ <div class='rtb-view-bookings-form-confirmation-div rtb-hidden'>
240
+ <?php _e("Set reservation status to 'Arrived'?", 'restaurant-reservations'); ?>
241
+ <div class='rtb-view-bookings-form-confirmation-accept'><?php _e("Yes", 'restaurant-reservations'); ?></div>
242
+ <div class='rtb-view-bookings-form-confirmation-decline'><?php _e("No", 'restaurant-reservations'); ?></div>
243
+ </div>
244
+ <div class='rtb-view-bookings-form-confirmation-background-div rtb-hidden'></div>
245
+
246
+ <table class='rtb-view-bookings-table'>
247
+ <thead>
248
+ <tr>
249
+ <?php if ( $rtb_controller->settings->get_setting( 'view-bookings-arrivals' ) ) {?> <th><?php _e('Arrived', 'restaurant-reservations'); ?></th><?php } ?>
250
+ <th><?php _e('Time', 'restaurant-reservations'); ?></th>
251
+ <th><?php _e('Party', 'restaurant-reservations'); ?></th>
252
+ <th><?php _e('Name', 'restaurant-reservations'); ?></th>
253
+ <th><?php _e('Email', 'restaurant-reservations'); ?></th>
254
+ <th><?php _e('Phone', 'restaurant-reservations'); ?></th>
255
+ <th><?php _e('Status', 'restaurant-reservations'); ?></th>
256
+ <th><?php _e('Details', 'restaurant-reservations'); ?></th>
257
+ </tr>
258
+ </thead>
259
+ <tbody>
260
+ <?php foreach ( $query->posts as $booking ) { ?>
261
+ <?php $booking_object = new rtbBooking(); ?>
262
+ <?php $booking_object->load_post( $booking->ID ); ?>
263
+ <tr>
264
+ <?php if ( $rtb_controller->settings->get_setting( 'view-bookings-arrivals' ) ) {?>
265
+ <?php if ( $booking_object->post_status != 'arrived' ) : ?><td><input type='checkbox' class='rtb-edit-view-booking' data-bookingid='<?php echo $booking_object->ID; ?>' /></td></th>
266
+ <?php else : ?><td></td>
267
+ <?php endif; ?>
268
+ <?php } ?>
269
+ <td><?php echo date('H:i:s', strtotime($booking_object->date)); ?></td>
270
+ <td><?php echo $booking_object->party; ?></td>
271
+ <td><?php echo $booking_object->name; ?></td>
272
+ <td><?php echo $booking_object->email; ?></td>
273
+ <td><?php echo $booking_object->phone; ?></td>
274
+ <td><?php echo $rtb_controller->cpts->booking_statuses[$booking_object->post_status]['label'] ?></td>
275
+ <td><?php echo apply_filters( 'rtb_bookings_table_column_details', $booking_object->message, $booking_object ); ?></td>
276
+ </tr>
277
+ <?php } ?>
278
+ </tbody>
279
+ </table>
280
+
281
+ </div>
282
+
283
+ <?php
284
+
285
+ wp_reset_postdata();
286
+
287
+ $output = ob_get_clean();
288
+
289
+ $output = apply_filters( 'rtb_display_bookings_form_html_post', $output );
290
+
291
+ return $output;
292
+ }
293
+ } // endif;
294
+
295
  /**
296
  * Enqueue the front-end CSS and Javascript for the booking form
297
  * @since 0.0.1
299
  if ( !function_exists( 'rtb_enqueue_assets' ) ) {
300
  function rtb_enqueue_assets() {
301
 
302
+ global $wp_scripts, $rtb_controller;
303
 
304
  wp_enqueue_style( 'rtb-booking-form' );
305
 
315
 
316
  wp_enqueue_script( 'rtb-booking-form' );
317
 
318
+ if( $rtb_controller->settings->get_setting('rtb-styling-layout') == 'contemporary' ){
319
+ wp_enqueue_style( 'rtb-contemporary-css', RTB_PLUGIN_URL . '/assets/css/contemporary.css' );
320
+ wp_enqueue_script( 'rtb-contemporary-js', RTB_PLUGIN_URL . '/assets/js/contemporary.js', array( 'jquery' ), '', true );
321
+ }
322
+ if( $rtb_controller->settings->get_setting('rtb-styling-layout') == 'columns' ){
323
+ wp_enqueue_style( 'rtb-columns-css', RTB_PLUGIN_URL . '/assets/css/columns.css' );
324
+ wp_enqueue_script( 'rtb-columns-js', RTB_PLUGIN_URL . '/assets/js/columns.js', array( 'jquery' ), '', true );
325
+ }
326
+
327
  // Pass date and time format settings to the pickadate controls
328
  global $rtb_controller;
329
  wp_localize_script(
339
  'schedule_closed' => $rtb_controller->settings->get_setting( 'schedule-closed' ),
340
  'early_bookings' => is_admin() && current_user_can( 'manage_bookings' ) ? '' : $rtb_controller->settings->get_setting( 'early-bookings' ),
341
  'late_bookings' => is_admin() && current_user_can( 'manage_bookings' ) ? '' : $rtb_controller->settings->get_setting( 'late-bookings' ),
342
+ 'enable_max_reservations' => $rtb_controller->settings->get_setting( 'rtb-enable-max-tables' ),
343
  'date_onload' => $rtb_controller->settings->get_setting( 'date-onload' ),
344
  'time_interval' => $rtb_controller->settings->get_setting( 'time-interval' ),
345
  'first_day' => $rtb_controller->settings->get_setting( 'week-start' ),
667
 
668
  }
669
  } // endif;
670
+
671
+
672
+ /**
673
+ * Retrieve an array of custom `cffrtbField` objects
674
+ *
675
+ * @since 0.1
676
+ */
677
+ if ( !function_exists( 'rtb_get_custom_fields' ) ) {
678
+ function rtb_get_custom_fields() {
679
+
680
+ $fields = array();
681
+
682
+ // Avoid use of WP_Query here so that we don't tamper with the $post global.
683
+ // This function gets called during `init` in the admin area, before
684
+ // any $post global is setup, so wp_reset_postdata is unable to restore it
685
+ // to `null` after modifying it. This caused issues, such as overriding the
686
+ // date folder media uploads are saved into.
687
+ $posts = get_posts( array( 'post_type' => 'cffrtb_field', 'post_status' => 'publish', 'posts_per_page' => 1000 ) );
688
+
689
+ foreach ($posts as $post) {
690
+ $fields[] = new cffrtbField(
691
+ array(
692
+ 'ID' => $post->ID,
693
+ )
694
+ );
695
+ }
696
+
697
+ return $fields;
698
+ }
699
+ }
700
+
701
+ /**
702
+ * Retrieve the submitted request data for a custom field
703
+ *
704
+ * @lookup int|string field ID or slug
705
+ * @since 0.1
706
+ */
707
+ if ( !function_exists( 'rtb_get_request_input' ) ) {
708
+ function rtb_get_request_input( $lookup, $request ) {
709
+
710
+ // Retrieve slug from ID
711
+ if ( is_int( $lookup ) ) {
712
+ $post = get_post( $lookup );
713
+ $lookup = $post->post_name;
714
+ }
715
+
716
+ if ( empty( $request->custom_fields ) || !isset( $request->custom_fields[ $lookup ] ) ) {
717
+ return '';
718
+ }
719
+
720
+ return $request->custom_fields[ $lookup ];
721
+ }
722
+ }
723
+
724
+ if ( !function_exists( 'rtb_add_custom_styling' ) ) {
725
+ function rtb_add_custom_styling() {
726
+ global $rtb_controller;
727
+ echo '<style>';
728
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-title-font-family') != '' ) { echo '.rtb-booking-form fieldset legend { font-family: \'' . $rtb_controller->settings->get_setting('rtb-styling-section-title-font-family') . '\' !important; }'; }
729
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-title-font-size') != '' ) { echo '.rtb-booking-form fieldset legend { font-size: ' . $rtb_controller->settings->get_setting('rtb-styling-section-title-font-size') . ' !important; }'; }
730
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-title-color') != '' ) { echo '.rtb-booking-form fieldset legend { color: ' . $rtb_controller->settings->get_setting('rtb-styling-section-title-color') . ' !important; }'; }
731
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-background-color') != '' ) { echo '.rtb-booking-form fieldset { background-color: ' . $rtb_controller->settings->get_setting('rtb-styling-section-background-color') . ' !important; }'; }
732
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-border-color') != '' ) { echo '.rtb-booking-form fieldset { border-color: ' . $rtb_controller->settings->get_setting('rtb-styling-section-border-color') . ' !important; }'; }
733
+ if ( $rtb_controller->settings->get_setting('rtb-styling-section-border-size') != '' ) { echo '.rtb-booking-form fieldset { border-width: ' . $rtb_controller->settings->get_setting('rtb-styling-section-border-size') . ' !important; }'; }
734
+ if ( $rtb_controller->settings->get_setting('rtb-styling-label-font-family') != '' ) { echo '.rtb-booking-form fieldset label, .rtb-booking-form .add-message a { font-family: \'' . $rtb_controller->settings->get_setting('rtb-styling-label-font-family') . '\' !important; }'; }
735
+ if ( $rtb_controller->settings->get_setting('rtb-styling-label-font-size') != '' ) { echo '.rtb-booking-form fieldset label { font-size: ' . $rtb_controller->settings->get_setting('rtb-styling-label-font-size') . ' !important; }'; }
736
+ if ( $rtb_controller->settings->get_setting('rtb-styling-label-color') != '' ) { echo '.rtb-booking-form fieldset label { color: ' . $rtb_controller->settings->get_setting('rtb-styling-label-color') . ' !important; }'; }
737
+ if ( $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-color') != '' ) { echo '.rtb-booking-form .add-message a { background-color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-color') . ' !important; border-color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-color') . ' !important; padding: 6px 12px !important; }'; }
738
+ if ( $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-hover-color') != '' ) { echo '.rtb-booking-form .add-message a:hover { background-color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-hover-color') . ' !important; border-color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-background-hover-color') . ' !important; }'; }
739
+ if ( $rtb_controller->settings->get_setting('rtb-styling-add-message-button-text-color') != '' ) { echo '.rtb-booking-form .add-message a { color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-text-color') . ' !important; }'; }
740
+ if ( $rtb_controller->settings->get_setting('rtb-styling-add-message-button-text-hover-color') != '' ) { echo '.rtb-booking-form .add-message a:hover { color: ' . $rtb_controller->settings->get_setting('rtb-styling-add-message-button-text-hover-color') . ' !important; }'; }
741
+ if ( $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-color') != '' ) { echo '.rtb-booking-form form button { background-color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-color') . ' !important; border-color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-color') . ' !important; padding: 13px 28px !important; }'; }
742
+ if ( $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-hover-color') != '' ) { echo '.rtb-booking-form form button:hover { background-color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-hover-color') . ' !important; border-color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-background-hover-color') . ' !important; }'; }
743
+ if ( $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-text-color') != '' ) { echo '.rtb-booking-form form button { color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-text-color') . ' !important; }'; }
744
+ if ( $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-text-hover-color') != '' ) { echo '.rtb-booking-form form button:hover { color: ' . $rtb_controller->settings->get_setting('rtb-styling-request-booking-button-text-hover-color') . ' !important; }'; }
745
+ echo '</style>';
746
+ }
747
+ }
748
+
749
+
lib/mpdf/CHANGELOG.txt ADDED
@@ -0,0 +1,3110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ===========================
2
+ mPDF 6.0
3
+ 20/12/2014
4
+ ===========================
5
+ New features / Improvements
6
+ ---------------------------
7
+ Support for OpenTypeLayout tables / features for complex scripts and Advances Typography.
8
+ Improved bidirectional text handling.
9
+ Improved line-breaking, including for complex scripts e.g. Lao, Thai and Khmer.
10
+ Updated page-breaking options.
11
+ Automatic language mark-up and font selection using autoScriptToLang and autoLangToFont.
12
+ Kashida for text-justification in arabic scripts.
13
+ Index collation for non-ASCII characters.
14
+ Index mark-up allowing control over layout using CSS.
15
+ {PAGENO} and {nbpg} can use any of the number types as in list-style e.g. set in <pagebreak> using pagenumstyle.
16
+ CSS support for lists.
17
+ Default stylesheet - mpdf.css - updated.
18
+
19
+
20
+ Added CSS support
21
+ -----------------
22
+ - lang attribute selector e.g. :lang(fr), [lang="fr"]
23
+ - font-variant-position
24
+ - font-variant-caps
25
+ - font-variant-ligatures
26
+ - font-variant-numeric
27
+ - font-variant-alternates - Only [normal | historical-forms] supported (i.e. most are NOT supported)
28
+ - font-variant - as above, and except for: east-asian-variant-values, east-asian-width-values, ruby
29
+ - font-language-override
30
+ - font-feature-settings
31
+ - text-outline is now supported on TD/TH tags
32
+ - hebrew, khmer, cambodian, lao, and cjk-decimal recognised as values for "list-style-type" in numbered lists and page numbering.
33
+ - list-style-image and list-style-position
34
+ - transform (on <img> only)
35
+ - text-decoration:overline
36
+ - image-rendering
37
+ - unicode-bidi (also <bdi> tag)
38
+ - vertical-align can use lengths e.g. 0.5em
39
+ - line-stacking-strategy
40
+ - line-stacking-shift
41
+
42
+ ================
43
+ mPDF 5.7.4
44
+ 15/12/2014
45
+ ================
46
+ Bug Fixes & Minor Additions
47
+ ---------------------------
48
+ - SVG images now support embedded images e.g. <image xlink:href="image.png" width="100px" height="100px" />
49
+ - SVG images now supports <tspan> element e.g. <tspan x,y,dx,dy,text-anchor >, and also <tref>
50
+ - SVG images now can use Autofont (see top of classes/svg.php file)
51
+ - SVG images now has limited support for CSS classes (see top of classes/svg.php file)
52
+ - SVG images - style inheritance improved
53
+ - SVG images - improved handling of comments and other extraneous code
54
+ - SVG images - fix to ensure opacity is reset before another element
55
+ - SVG images - font-size not resetting after a <text> element
56
+ - SVG radial gradients bug (if the focus [fx,fy] lies outside circle defined by [cx,cy] and r) cf. pservers-grad-15-b.svg
57
+ - SVG allows spaces in attribute definitions in <use> or <defs> e.g. <use x = "0" y = "0" xlink:href = "#s3" />
58
+ - SVG text which contains a < sign, it will break the text - now processed as &lt; (despite the fact that this does not conform to XML spec)
59
+ - SVG images - support automatic font selection and (minimal) use of CSS classes - cf. the defined constants at top of svg.php file
60
+ - SVG images - text-anchor now supported as a CSS style, as well as an HTML attribute
61
+ - CSS support for :nth-child() selector improved to fully support the draft CSS3 spec - http://www.w3.org/TR/selectors/#nth-child-pseudo
62
+ [NB only works on table columns or rows]
63
+ - text-indent when set as "em" - incorrectly calculated if last text in line in different font size than for block
64
+ - CSS not applying cascaded styles on <A> elements - [changed MergeCSS() type to INLINE for 'A', LEGEND, METER and PROGRESS]
65
+ - fix for underline/strikethrough/overline so that line position(s) are based correctly on font-size/font in nested situations
66
+ - Error: Strict warning: Only variables should be passed by reference - in PHP5.5.9
67
+ - bug accessing images from some servers (HTTP 403 Forbidden whn accessed using fopen etc.)
68
+ - Setting page format incorrectly set default twice and missed some options
69
+ - bug fixed in Overwrite() when specifying replacement as a string
70
+ - barcode C93 - updated C93 code from TCPDF because of bug - incorrect checksum character for "153-2-4"
71
+ - Tables - bug when using colspan across columns which may have a cell width specified
72
+ cf. http://www.mpdf1.com/forum/discussion/2221/colspan-bug
73
+ - Tables - cell height (when specified) is not resized when table is shrunk
74
+ - Tables - if table width specified, but narrower than minimum cell wdith, and less than page width - table will expand to
75
+ minimum cell width(s) as long as $keep_table_proportions = true
76
+ - Tables - if using packTableData, and borders-collapse, wider border is overwriting content of adjacent cell
77
+ Test case:
78
+ <table style="border-collapse: collapse;">
79
+ <tr><td style="border-bottom: 42px solid #0FF; "> Hallo world </td></tr>
80
+ <tr><td style="border-top: 14px solid #0F0; "> Hallo world </td></tr>
81
+ </table>
82
+ - Images - image height is reset proportional to original if width is set to maximum e.g. <img width="100%" height="20mm"
83
+ - URL handling changed to work with special characters in path fragments; affects <a> links, <mg> images and
84
+ CSS url() e.g background-image
85
+ - also to ignore "../" included as a query value
86
+ - Barcodes with bottom numerals e.g. EAN-13 - incorrect numeral size when using core fonts
87
+ --------------------------------
88
+ NB Spec. for embedded SVG images:
89
+ as per http://www.w3.org/TR/2003/REC-SVG11-20030114/struct.html#ImageElement
90
+ Attributes supported:
91
+ x
92
+ y
93
+ xlink:href (required) - can be jpeg, png or gif image - not vector (SVG or WMF) image
94
+ width (required)
95
+ height (required)
96
+ preserveAspectRatio
97
+
98
+ Note: all attribute names and values are case-sensitive
99
+ width and height cannot be assigned by CSS - must be attributes
100
+ ---------------------------------
101
+ ================
102
+ mPDF 5.7.3
103
+ 24/8/2014
104
+ ================
105
+ Bug Fixes & Minor Additions
106
+ ---------------------------
107
+ - Tables - cellSpacing and cellPadding taking preference over CSS stylesheet
108
+ - Tables - background images in table inside HTML Footer incorrectly positioned
109
+ - Tables - cell in a nested table with a specified width, should determine width of parent table cell
110
+ (cf. http://www.mpdf1.com/forum/discussion/1648/nested-table-bug-)
111
+ - Tables - colspan (on a row after first row) exceeds number of columns in table
112
+ - Gradients in Imported documents (mPDFI) causing error in some browsers
113
+ - Fatal error after page-break-after:always on root level block element
114
+ - Support for 'https/SSL' if file_get_contents_by_socket required (e.g. getting images with allow_url_fopen turned off)
115
+ - Improved support for specified ports when getting external CSS stylesheets e.g. www.domain.com:80
116
+ - error accessing local .css files with dummy queries (cache-busting) e.g. mpdfstyleA4.css?v=2.0.18.9
117
+ - start of end tag in PRE incorrectly changed to &lt;
118
+ - error thrown when open.basedir restriction in effect (deleting temporary files)
119
+ - image which forces pagebreak incorrectly positioned at top of page
120
+ - [changes to avoid warning notices by checking if (isset(x)) before referencing it]
121
+ - text with letter-spacing set inside table which needs to be resixed (shrunk) - letter-spacing was not adjusted
122
+ - nested table incorrectly calculating width and unnecessarily wrapping text
123
+ - vertical-align:super|sub can be nested using <span> elements
124
+ - inline elements can be nested e.g. text <sup>text<sup>13</sup>text</sup> text
125
+ - CSS vertical-align:0.5em (or %) now supported
126
+ - underline and strikethrough now use the parent inline block baseline/fontsize/color for child inline elements *** change in behaviour
127
+ (Adjusts line height to take account of superscript and subscript except in tables)
128
+ - nested table incorrectly calculating width and unnecessarily wrapping text
129
+ - tables - font size carrying over from one nested table to the next nested table
130
+ - tables - border set as attribute on <TABLE> overrides border set as CSS on <TD>
131
+ - tables - if table width set to 100% and one cell/column is empty with no padding/border, sizing incorrectly
132
+ (http://www.mpdf1.com/forum/discussion/1886/td-fontsize-in-nested-table-bug-#Item_5)
133
+ - <main> added as recognised tag
134
+ - CSS style transform supported on <img> element (only)
135
+ All transform functions are supported except matrix() i.e. translate(), translateX(), translateY(), skew(), skewX(), skewY(),
136
+ scale(), scaleX(), scaleY(), rotate()
137
+ NB When using Columns or Keep-with-table (use_kwt), cannot use transform
138
+ - CSS background-color now supported on <img> element
139
+ - @page :first not recognised unless @page {} has styles set
140
+ - left/right margins not allowed on @page :first
141
+
142
+
143
+
144
+ ================
145
+ mPDF 5.7.2
146
+ 28/12/2013
147
+ ================
148
+ Bug Fixes
149
+ ---------
150
+ - <tfoot> not printing at all (since v5.7)
151
+ - list-style incorrectly overriding list-style-type in cascading CSS
152
+ - page-break-after:avoid not taking into account bottom padding and margin when estimating if next line can fit on page
153
+ - images not displayed when using "https://" if images are referenced by src="//domain.com/image"
154
+ - +aCJK incorrectly parsed when instantiating class e.g. new mpDF('ja+aCJK')
155
+ - line-breaking - zero-width object at end of line (e.g. index entry) causing a space left untrimmed at end of line
156
+ - ToC since v5.7 incorrectly handling non-ascii characters, entities or tags
157
+ - cell height miscalculated when using hard-hyphenate
158
+ - border colors set with transparency not working
159
+ - transparency settings for stroke and fill interfering with one another
160
+ - 'float' inside a HTML header/footer - not clearing the float before first line of text
161
+ - error if script run across date change at midnight
162
+ - temporary file name collisions (e.g. when processing images) if numerous users
163
+ - <watermarkimage> position attribute not working
164
+ - < (less-than sign) inside a PRE element, and NOT start of a valid tag, was incorrectly removed
165
+ - file attachments not opening in Reader XI
166
+ - JPG images not recognised if not containing JFIF or Exif markers
167
+ - instance of preg_replace with /e modifier causing error in PHP 5.5
168
+ - correctly handle CSS URLs with no scheme
169
+ - Index entries causing errors when repeat entries are used within page-break-inside:avoid, rotated tables etc.
170
+ - table with fixed width column and long word in cell set to colspan across this column (adding spare width to all columns)
171
+ - incorrect hyphenation if multiple soft-hyphens on line before break
172
+ - SVG images - objects contained in <defs> being displayed
173
+ - SVG images - multiple, or quoted fonts e.g. style="font-family:'lucida grande', verdana" not recognised
174
+ - SVG images - line with opacity=0 still visible (only in some PDF viewers/browsers)
175
+ - text in an SVG image displaying with incorrect font in some PDF viewers/browsers
176
+ - SVG images - fill:RGB(0,0,0) not recognised when uppercase
177
+ - background images using data:image\/(jpeg|gif|png);base64 format - error when reading in stylesheet
178
+
179
+ New CSS support
180
+ ---------------
181
+ - added support for style="opacity:0.6;" in SVG images - previously only supported style="fill-opacity:0.6; stroke-opacity: 0.6;"
182
+ - improved PNG image handling for some cases of alpha channel transparency
183
+ - khmer, cambodian and lao recognised as list-style-type for numbered lists
184
+
185
+ SVG Images
186
+ ----------
187
+ Limited support for <use> and <defs>
188
+
189
+ ================
190
+ mPDF 5.7.1
191
+ 1/09/2013
192
+ ================
193
+ 1) FILES: mpdf.php
194
+ Bug fix; Dollar sign enclosed by <pre> tag causing error.
195
+ Test e.g.: <pre>Test $1.00 Test</pre> <pre>Test $2.00 Test</pre> <pre>Test $3.00 Test</pre> <pre>Test $4.00 Test</pre>
196
+ -----------------------------
197
+ 2) FILES: includes/functions.php AND mpdf.php
198
+ Changes to preg_replace with /e modifier to use preg_replace_callback
199
+ (/e depracated from PHP 5.5)
200
+ -----------------------------
201
+ 3) FILES: classes/barcode.php
202
+ Small change to function barcode_c128() which allows ASCII 0 - 31 to be used in C128A e.g. chr(13) in:
203
+ <barcode code="5432&#013;1068" type="C128A" />
204
+ -----------------------------
205
+ 4) FILES: mpdf.php
206
+ Using $use_kwt ("keep-[heading]-with-table") if <h4></h4> before table is on 2 lines and pagebreak occurs after first line
207
+ the first line is displayed at the bottom of the 2nd page.
208
+ Edited so that $use_kwt only works if the HEADING is only one line. Else ignores (but prints correctly)
209
+ -----------------------------
210
+ 5) FILES: mpdf.php
211
+ Clearing old temporary files from _MPDF_TEMP_PATH will now ignore "hidden" files e.g. starting with a "." .htaccess, .gitignore etc.
212
+ and also leave dummy.txt alone
213
+ -----------------------------
214
+
215
+
216
+ ===========================
217
+ mPDF 5.7
218
+ 14/07/2013
219
+ ===========================
220
+
221
+ Files changed
222
+ -------------
223
+ config.php
224
+ mpdf.php
225
+ classes/tocontents.php
226
+ classes/cssmgr.php
227
+ classes/svg.php
228
+ includes/functions.php
229
+ includes/out.php
230
+ examples/formsubmit.php [Important - Security update]
231
+
232
+ Updated Example Files in /examples/
233
+ -----------------------------------
234
+ All example files
235
+ mpdfstyleA4.css
236
+
237
+
238
+ config.php
239
+ ----------
240
+ Removed:
241
+ $this->hyphenateTables
242
+ $this->hyphenate
243
+ $this->orphansAllowed
244
+ Edited:
245
+ "hyphens: manual" - Added to $this->defaultCSS
246
+ $this->allowedCSStags now includes '|TEXTCIRCLE|DOTTAB'
247
+ New:
248
+ $this->decimal_align = array('DP'=>'.', 'DC'=>',', 'DM'=>"\xc2\xb7", 'DA'=>"\xd9\xab", 'DD'=>'-');
249
+ $this->h2toc = array('H1'=>0, 'H2'=>1, 'H3'=>2);
250
+ $this->h2bookmarks = array('H1'=>0, 'H2'=>1, 'H3'=>2);
251
+ $this->CJKforceend = false; // Forces overflowng punctuation to hang outside right margin (used with CJK script)
252
+
253
+
254
+ Backwards compatability
255
+ -----------------------
256
+ Changes in mPDF 5.7 may cause some changes to the way your documents appear. There are two main differences:
257
+ 1) Hyphenation. To retain appearance compatible with earlier versions, set the CSS property "hyphens: auto" whenever
258
+ you previously used $mpdf->hyphenate=true;
259
+ 2) Table of Contents - appearance can now be controlled with CSS styles. By default, in mPDF 5.7, no styling is applied so you will get:
260
+ - No indent (previous default of 5mm) - ($tocindent is ignored)
261
+ - Any font, font-size set ($tocfont or $tocfontsize) will not work
262
+ - HyperLinks will appear with your default appearance - usually blue and underlined
263
+ - line spacing will be narrower (can use line-height or margin-top in CSS)
264
+
265
+
266
+ New features / Improvements
267
+ ---------------------------
268
+ Layout of Table of Content ToC now controlled using CSS styles
269
+ Text alignment on decimal mark inside tables
270
+ Automatically generated bookmarks and/or ToC entries from H1 - H6 tags
271
+ Support for unit of "rem" as size e.g. font-size: 1rem;
272
+ Origin and clipping for background images and gradients controlled by CSS i.e. background-origin, background-size, background-clip
273
+ Text-outline controlled by CSS (compatible with CSS3 spec.)
274
+ Use of <dottab> enhanced by custom CSS "outdent" property
275
+ Image HTML attributes <img> added: max-height, max-width, min-height and min-width
276
+ Spotcolor can now be defined as it is used e.g. color: spot(PANTONE 534 EC, 100%, 85, 65, 47, 9);
277
+ Lists - added support for "start" attribute in <ol> e.g. <ol start="5">
278
+ Hyphenation controlled using CSS, consistent with CSS3 spec.
279
+ Line breaking improved to avoid breaks within words where HTML tags are used e.g. H<sub>2<sub>0
280
+ Line breaking in CJK scripts improved (and ability to force hanging punctuation)
281
+ Numerals in a CJK script are kept together
282
+ RTL improved support for phrases containing numerals and \ and /
283
+ Bidi override codes supported - Right-to-Left Embedding [RLE] U+202B, Left-to-Right Embedding [LRE] U+202A,
284
+ U+202C POP DIRECTIONAL FORMATTING (PDF)
285
+ Support for <base href=""> in HTML - uses it to SetBasePath for relative URLs.
286
+ HTML tag - added support for <wbr> or <wbr /> - converted to a soft-hyphen
287
+ CSS now takes precedence over HTML attribute e.g. <table bgcolor="black" style="background-color:yellow">
288
+
289
+
290
+
291
+ Added CSS support
292
+ -----------------
293
+ - max-height, max-width, min-height and min-width for images <img>
294
+ - "hyphens: none|manual|auto" as per CSS3 spec.
295
+ - Decimal mark alignment e.g. text-align: "." center;
296
+ - "rem" accepted as a valid (font)size in CSS e.g. font-size: 1.5rem
297
+ - text-outline, text-outline-width and text-outline-color supported everywhere except in tables (blur not supported)
298
+ - background-origin, background-size, background-clip are now supported everywhere except in tables
299
+ - "visibility: hidden|visible|printonly|screenonly" for inline elements e.g. <span>
300
+ - Colors: device-cmyk(c,m,y,k) as per CSS3 spec. For consistency, device-cmyka also supported (not CSS3 spec)
301
+ - "z-index" can be used to utilise layers in the PDF document
302
+ - Custom CSS property added: "outdent" - opposite of indent
303
+
304
+ The HTML elements <dottab> and <textcircle> can now have CSS properties applied to them.
305
+
306
+
307
+ Bug fixes
308
+ ---------
309
+ - SVG images - path including e.g. 1.234E-15 incorrectly parsed (not recognising capital E)
310
+ - Tables - if a table starts when the Y position on page is below bottom margin caused endless loop
311
+ - Float-ing DIVs - starting a float at bottom of page and it causes page break before anything output, second new page is forced
312
+ - Tables - Warning notice now given in Table footer or header if <tfoot> placed after <tbody> and table spans page
313
+ - Columns - block with border-width wider than the length of the border line, line overflows
314
+ - Columns - block with no padding containing a block with borders but no backgound colour, borders not printed
315
+ - Table in Columns - when background color set by surrounding block element - colour missing for height of half bottom border.
316
+ - TOCpagebreakByArray() when called by function was not adding the pagebreak
317
+ - Border around block element - dashed not showing correctly (not resetting linewidth between different edges)
318
+ - Double border in table - when background colour set in surrounding block element - shows as black line between the 2 bits of double
319
+ - Borders around DIVs - "double" border problem if not all 4 sides equally - fixed
320
+ - Borders around DIVs - solid (and double) borders overlap as in tables - now fixed so mitred joins as in browser
321
+ [Inadvertently improves borders in Columns because of change in LineCap]
322
+ - Page numbering - $mpdf->pagenumSuffix etc not suppressed in HTML headers/footers if number suppressed
323
+ - Page numbering - Page number total {nbpg} incorrect - e.g. showing decreasing numbers through document, when ToC present
324
+ - RTL numerals - incorrectly reversing a number followed by a comma
325
+ - Transform to uppercase/lowercase not working for chars > ASCII 128 when using core fonts
326
+ - TOCpagebreak - Not setting TOC-FOOTER
327
+ - TOCpagebreak - toc-even-header-name etc. not working
328
+ - Parsing some relative URLs incorrectly
329
+ - Textcircle - when moved to next page by "page-break-inside: avoid"
330
+ - Bookmarks will now work if jump more than one level e.g. 0,2,1 Inserts a new blank entry at level 1
331
+ - Paths to img or stylesheets - incorrectly reading "//www.domain.com" i.e. when starting with two /
332
+ - data:image as background url() - incorrectly adjusting path on server if MPDF_PATH not specified (included in release mPDF 5.6.1)
333
+ - Image problem if spaces or commas in path using http:// URL (included in release mPDF 5.6.1)
334
+ - Image URL parsing rewritten to handle both urlencoded URLs and not urlencoded (included in release mPDF 5.6.1)
335
+ - <dottab> fixed to allow color, font-size and font-family to be correctly used, avoid dots being moved to new page, and to work in RTL
336
+ - Table {colsum} summed figures in table header
337
+ - list-style-type (custom) colour not working
338
+ - <tocpagebreak> toc-preHTML and toc-postHTML can now contain quotes
339
+
340
+
341
+
342
+ ===========================
343
+ mPDF 5.6
344
+ 20/01/2013
345
+ ===========================
346
+
347
+ Files changed
348
+ -------------
349
+ mpdf.php
350
+ config.php
351
+ includes/functions.php
352
+ classes/meter.php
353
+ classes/directw.php
354
+
355
+
356
+ config.php changes
357
+ ------------------
358
+ $this->allowedCSStags - added HTML5 tags + textcircle AND
359
+ $this->outerblocktags - added HTML5 tags
360
+ $this->defaultCSS - added default CSS properties
361
+
362
+
363
+ New features / Improvements
364
+ ---------------------------
365
+ CSS support added for for min-height, min-width, max-height and max-width in <img>
366
+
367
+ Images embedded in CSS
368
+ <img src="data:image/gif;base64,...."> improved to make it more robust, and
369
+ background: url(data:image... now added to work
370
+
371
+ HTML5 tags supported
372
+ - as generic block elements: <article><aside><details><figure><figcaption><footer><header><hgroup><nav><section><summary>
373
+ - as in-line elements: <mark><time><meter><progress>
374
+ - <mark> has a default CSS set in config.php to yellow highlight
375
+ - <meter> and <progress> support attributes as for HTML5
376
+ - custom appearances for <meter> and <progress> can be made by editing classes/meter.php file
377
+ - <meter> and <progress> suppress text inside the tags
378
+
379
+ Textcircle/Circular
380
+ font: "auto" added: automatically sizes text to fill semicircle (if both set) or full circle (if only one set)
381
+ NB for this AND ALL CSS on <textcircle>: does not inherit CSS styles
382
+ attribute: divider="[characters including HTML entities]" added
383
+ <textcircle r="30mm" top-text="Text Circular Text Circular" bottom-text="Text Circular Text Circular"
384
+ divider="&nbsp;&bull;&nbsp;" style="font-size: auto" />
385
+
386
+ &raquo; &rsquo; &sbquo; &bdquo; are now included in "orphan"-management at the end of lines
387
+
388
+ Improved CJK line wrapping (if CJK character at end of line, breaks there rather than previous wordspace)
389
+
390
+ NB mPDF 5.5 added support for <fieldset> and <legend> (omitted from ChangeLog)
391
+
392
+ Bug fixes
393
+ ---------
394
+ - embedded fonts: Panose string incorrectly output as decimals - changed to hexadecimal
395
+ Only a problem in limited circumstances.
396
+ *****Need to delete all ttfontdata/ files in order for fix to have effect.
397
+ - <textCircle> background white even when set to none/transparent
398
+ - border="0" causing mPDF to add border to table CELLS as well as table
399
+ - iteration counter in THEAD crashed in some circumstances
400
+ - CSS color now supports spaces in the rgb() format e.g. border: 1px solid rgb(170, 170, 170);
401
+ - CJK not working in table following changes made in v5.4
402
+ - images fixed to work with Google Chart API (now mPDF does not urldecode the query part of the src)
403
+ - CSS <style> within HTML page crashed if CSS is too large (? > 32Kb)
404
+ - SVG image nested int eht HTML failed to show if code too large (? > 32Kb)
405
+ - cyrillic character p &#1088; at end of table cell caused cell height to be incorrectly calculated
406
+
407
+
408
+ ===========================
409
+ mPDF 5.5
410
+ 02/03/2012
411
+ ===========================
412
+
413
+ Files changed
414
+ -------------
415
+ mpdf.php
416
+ classes/ttfontsuni.php
417
+ classes/svg.php
418
+ classes/tocontents.php
419
+ config.php
420
+ config_fonts.php
421
+ utils/font_collections.php
422
+ utils/font_coverage.php
423
+ utils/font_dump.php
424
+
425
+ Files added
426
+ -----------
427
+ classes/ttfontsuni_analysis.php
428
+
429
+ config.php changes
430
+ ------------------
431
+ To avoid just the border/background-color of the (empty) end of a block being moved on to next page (</div></div>)
432
+ $this->margBuffer = 0; // Allow an (empty) end of block to extend beyond the bottom margin by this amount (mm)
433
+
434
+ config_fonts.php changes
435
+ ------------------------
436
+ Added to (arabic) fonts to allow "use non-mapped Arabic Glyphs" e.g. for Pashto
437
+ 'unAGlyphs' => true,
438
+
439
+ Arabic text
440
+ -----------
441
+ Arabic text (RTL) rewritten with improved support for Pashto/Sindhi/Urdu/Kurdish
442
+ Presentation forms added:
443
+ U+0649, U+0681, U+0682, U+0685, U+069A-U+069E, U+06A0, U+06A2, U+06A3, U+06A5, U+06AB-U+06AE,
444
+ U+06B0-U+06B4, U+06B5-U+06B9, U+06BB, U+06BC, U+06BE, U+06BF, U+06C0, U+06CD, U+06CE, U+06D1, U+06D3, U+0678
445
+ Joining improved:
446
+ U+0672, U+0675, U+0676, U+0677, U+0679-U+067D, U+067F, U+0680, U+0683, U+0684, U+0687, U+0687, U+0688-U+0692,
447
+ U+0694, U+0695, U+0697, U+0699, U+068F, U+06A1, U+06A4, U+06A6, U+06A7, U+06A8, U+06AA, U+06BA, U+06C2-U+06CB, U+06CF
448
+
449
+ Note -
450
+ Some characters in Pashto/Sindhi/Urdu/Kurdish do not have Unicode values for the final/initial/medial forms of the characters.
451
+ However, some fonts include these characters "un-mapped" to Unicode (including XB Zar and XB Riyaz, which are bundled with mPDF).
452
+ 'unAGlyphs' => true,
453
+ added to the config_fonts.php file for appropriate fonts will
454
+
455
+ This requires the font file to include a Format 2.0 POST table which references the glyphs as e.g. uni067C.med or uni067C.medi:
456
+ e.g. XB Riyaz, XB Zar, Arabic Typesetting (MS), Arial (MS)
457
+ NB If you want to know if a font file is suitable, you can open a .ttf file in a text editor and search for "uni067C.med"
458
+ - if it exists, it may work!
459
+ Using "unAGlyphs" forces subsetting of fonts, and will not work with SIP/SMP fonts (using characters beyond the Unicode BMP Plane).
460
+
461
+ mPDF maps these characters to part of the Private Use Area allocated by Unicode U+F500-F7FF. This could interfere with correct use
462
+ if the font already utilises these codes (unlikely).
463
+
464
+ mPDF now deletes U+200C,U+200D,U+200E,U+200F zero-widthjoiner/non-joiner, LTR and RTL marks so they will not appear
465
+ even though some fonts contain glyphs for these characters.
466
+
467
+
468
+ Other New features / Improvements
469
+ ---------------------------------
470
+ Avoid just the border/background-color of the (empty) end of a block being moved on to next page (</div></div>)
471
+ using configurable variable: $this->margBuffer;
472
+
473
+
474
+ The TTFontsUni class contained a long function (extractcoreinfo) which is not used routinely in mPDF
475
+ This has been moved to a new file: classes/ttfontsuni_analysis.php
476
+ The 3 utility scripts have been updated to use the new extended class:
477
+ - utils/font_collections.php
478
+ - utils/font_coverage.php
479
+ - utils/font_dump.php
480
+
481
+
482
+ Bug fixes
483
+ ---------
484
+ - Border & background when closing 2 blocks (e.g. </div></div>) incorrectly being moved to next page because incorrectly
485
+ calculating how much space required
486
+ - Fixed/Absolute-positioned elements not inheriting letter-spacing style
487
+ - Rotated cell - error if text-rotate set on a table cell, but no text content in cell
488
+ - SVG images, text-anchor not working
489
+ - Nested table - not resetting cell style (font, color etc) after nested table, if text follows immediately
490
+ - Nested table - font-size 70% set in extenal style sheet; if repeated nested tables, sets 70% of 70% etc etc
491
+ - SVG setting font-size as percent on successive <text> elements gives progressively smaller text
492
+ - mPDF will check if magic_quotes_runtime set ON even >= PHP 5.3 (will now cause an error message)
493
+ - not resetting after 2 nested tags of same type e.g. <b><b>bold</b></b> still bold
494
+ - When using charset_in other than utf-8, HTML Footers using tags e.g. <htmlpageheader> do not decode correctly
495
+ - ToC if nested > 3 levels, line spacing reduces and starts to overlap
496
+
497
+
498
+
499
+
500
+ ===========================
501
+ mPDF 5.4
502
+ 14/02/2012
503
+ ===========================
504
+ Files changed
505
+ -------------
506
+ mpdf.php
507
+ config.php
508
+ compress.php
509
+ classes/ttfontsuni.php
510
+ classes/barcode.php
511
+ classes/indic.php
512
+ classes/svg.php
513
+ examples/show_code.php ----- SECURITY RISK**
514
+ examples/example49_changelog.php
515
+ examples/example57_new_mPDF_v5-3_active_forms_b (replace example57_new_mPDF_v5-3_active_forms)
516
+ includes/out.php
517
+ mpdfi/fpdi_pdf_parser.php
518
+
519
+ Files added
520
+ -----------
521
+ classes/bmp.php
522
+ classes/directw.php
523
+ classes/form.php
524
+ classes/grad.php
525
+ classes/tocontents.php
526
+ classes/wmf.php
527
+ examples/example58_new_mPDF_v5-4_features
528
+
529
+ config.php changes
530
+ ------------------
531
+ Edited: $this->allowedCSStags, $this->innerblocktags, $this->defaultCSS; (CAPTION added in each case)
532
+ Moved: Numerous $form_.. variables are now in /classes/form.php
533
+
534
+ New config variables
535
+ --------------------
536
+ $this->bookmarkStyles = array();
537
+ $this->cacheTables = true;
538
+
539
+ New methods
540
+ -----------
541
+ function CircularText()
542
+ function SetVisibility()
543
+
544
+ New/Extended CSS
545
+ ----------------
546
+ box-shadow (block elements - does NOT support "inset")
547
+ text-shadow (all text elements - does NOT support "blur")
548
+ visibility: visible|hidden|printonly|screenonly (block-level elements and images IMG only)
549
+ text-transform: capitalize|uppercase|lowercase (extended to support TD/TH)
550
+ tr|td|th:nth-child(odd|even|2n+1)
551
+ color, strikethrough, underline and background-color (extended to support rotated TD/TH)
552
+ underline and strike-through (extended to support TD/TH)
553
+ underline (line colour) (extended to work correctly in watermark)
554
+ page-break-after: left|right|always (block elements and tables)
555
+ NB respects $mpdf->restoreBlockPagebreaks = true; i.e. will make pagebreak act like formfeed
556
+ background[-color]: extended to support rgba|cmyka|cmyk|hsla|hsl|spot
557
+ border(extended to support inline elements)
558
+
559
+
560
+ New HTML
561
+ --------
562
+ <caption>
563
+ <textcircle />
564
+
565
+
566
+ New features / Improvements
567
+ ---------------------------
568
+ Tables - Zebra Stripes
569
+ Tables: overlapping rowspans (partially) supported
570
+ Tables - Disk caching
571
+ Using progress bars (or $showStats) now reports 'real' memory usage i.e. get_memory_usage(true)
572
+ Support for query string in the URLs for external stylesheets e.g. @import url("style.css?ltcyy7");
573
+ Table caption partially supported
574
+ CircularText
575
+ BookMark styling
576
+ Spread tables i.e. can split table (columns) across several pages width.
577
+ Can use chelvetica, ctimes and ccourier to specify core fonts in a non-core font document
578
+ Spread tables i.e. can split table (columns) across several pages width.
579
+ {colsum} in <tfoot> cell will insert a column total per page.
580
+ SVG embedded as island in HTML supported
581
+ Active Forms
582
+ textarea and input (text types) now accept javascript as:
583
+ onKeystroke, onValidate, onCalculate and onFormat
584
+ onChange is depracated but works as onCalculate (for textarea and input)
585
+ (PS Select still accepts onChange cf. 5.3.37)
586
+ Ledger and Tabloid added as page formats recognised. NB Ledger is same as tabloid but landscape. In mPDF, both give the same size (portrait)
587
+ so need to add -L e.g. Ledger-L for landscape.
588
+
589
+
590
+ Internal script changes
591
+ -----------------------
592
+ Changed this->k to _MPDFK throughout all scripts
593
+ Changes to color (packed binary data in string rather than array) to reduce memory usage esp in tables
594
+ Internal variables Removed
595
+ $usetableheader;
596
+ $tableheadernrows;
597
+ $tablefooternrows;
598
+ vars $ChangePage, $p_bottom_border, $img_margin_top(+) $issetcolor + other similar removed
599
+
600
+ Removed a whole load of // comments
601
+ Updates to remove some more Warning Notices (not all marked in text)
602
+ Border set on TR - changed so set on each cell, rather than retrospectively at end of TR
603
+ All references to table['text'] removed as not needed - uses ['textbuffer'] instead
604
+ OpenTag(TD) changes to reduce memory usage with tables
605
+ Includes different method to set a default timezone
606
+ fn _smallCaps does not need (undefined) $space
607
+ this->chrs and this->ords replaced by chr() and ord()
608
+ Headers in out.php updated to match those used in Output()
609
+ Change to SetFont() to improve performance time
610
+ Change to GetStringWidth() to improve performance time
611
+ Corrected copying of Glyphs 0,1,2, to all subset fonts (non-SMP/SIP), and only setting 32->127 in subset
612
+ Subset fonts (non-SMP/SIP) have additionally Unicode CMap tables (0,0,4 and 0,3,4) as well as Microsoft (3,1,4)
613
+ Subset fonts (SMP/SIP) have CMap tables (1,0,6 and 3,0,4) - rather than 1,0,6 and 3,0,6
614
+ Subset fonts (SMP/SIP) have 'name' table changed to give 1,0 and 3,0. As it is a symbol font (not Unicode encoded) :
615
+ needs to have a name entry in 3,0 (e.g. symbol) - original font will have 3,1 (i.e. Unicode)
616
+ Automatically checks for HTML code length > 100000 characters and gives error warning if
617
+ PHP < 5.2.0 (as not configurable) or increases pcre.backtrack_limit if PHP < 5.3.7
618
+
619
+ Removed/Depracated
620
+ ------------------
621
+ function UseTableHeader($opt=true) fn removed / depracated
622
+ function UsePRE($opt=true) removed
623
+ $attr['REPEAT_HEADER'] == true CSS removed / depracated
624
+ $this->usepre=true; removed / depracated as never needed - always respects PRE whitespace
625
+
626
+ ToC: NB Values can no longer be set directly e.g. as in example
627
+ $mpdf->TOCheader = array(); // array as for setting header/footer
628
+ $mpdf->TOCfooter = array(); // array as for setting header/footer
629
+ $mpdf->TOCpreHTML = '<h2>Contents - Portrait</h2>'; // HTML text to appear before table of contents
630
+ $mpdf->TOCpostHTML = ''; // HTML text to appear after table of contents
631
+ $mpdf->TOCbookmarkText = 'Content list'; // Text as it will appear in the Bookmarks (leave blank for none)
632
+ Need to use TOCpagebreak either direct (or array version) or as HTML
633
+ OR if absolutley necessary, could use:
634
+ $mpdf->tocontents->TOCheader = array(); // array as for setting header/footer
635
+ $mpdf->tocontents->TOCfooter = array(); // array as for setting header/footer
636
+ $mpdf->tocontents->TOCpreHTML = '<h2>Contents - Portrait</h2>'; // HTML text to appear before table of contents
637
+ $mpdf->tocontents->TOCpostHTML = ''; // HTML text to appear after table of contents
638
+ $mpdf->tocontents->TOCbookmarkText = 'Content list'; // Text as it will appear in the Bookmarks (leave blank for none)
639
+
640
+
641
+
642
+ Further Details
643
+ ===============
644
+
645
+ CSS border on inline elements
646
+ -----------------------------
647
+ Support for CSS border (and variants) on inline elements e.g. <span style="border-bottom: 1px dashed #000000;">
648
+ Border styles solid|dotted|dashed|double only are supported. Border radius not supported.
649
+ Nested inline elements will have repeat left|right borders on the nested content (unlike browsers)
650
+
651
+ Tables - Zebra Stripes
652
+ ----------------------
653
+ TABLE - striped rows cf. http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/
654
+ tr:nth-child(odd) { background-color: #99ff99; }
655
+ thead tr:nth-child(3n+2) { background-color: #FFBBFF; }
656
+ td:nth-child(2n+1) { background-color: #BBBBFF; }
657
+ table.zebraTable td:nth-child(2n+1) { background-color: #BBBBFF; }
658
+ table.zebraTable th:nth-child(2n+1) { background-color: #BBBBFF; }
659
+
660
+ NB mPDF does NOT correctly apply specificity to all CSS
661
+ table.zebra tbody tr:nth-child(2n+1) td { background-color: #FFFFBB; }
662
+ table.zebra tbody td:nth-child(odd) { background-color: #BBBBFF; }
663
+
664
+ should make every odd row yellow, and every odd coloumn blue, but with the row/yellow overriding the column/blue.
665
+ In mPDF the td:nth-child(odd) trumps the plain td, so the column colour wins out. You can force the effect you want by using
666
+ table.zebra tbody tr:nth-child(2n+1) td:nth-child(1n+0) { background-color: #FFFFBB; }
667
+
668
+ (The :nth-child(1n+0) selector just selects every td cell.)
669
+
670
+
671
+
672
+ Tables - Disk caching
673
+ ---------------------
674
+ TABLES: using disk caching
675
+ // Using disk to cache table data can reduce memory usage dramatically, but at a cost of increased
676
+ // executon time and disk access (read and write)
677
+ $this->cacheTables = true;
678
+ NB $this->packTableData will be overridden to => true; // required for cacheTables
679
+ $this->simpleTables will be overridden to => false; // Cannot co-exist with cacheTables
680
+
681
+
682
+ Table caption
683
+ -------------
684
+ Must come immediately after <table...>
685
+ CSS caption-side and HTML align attribute of top|bottom supported (not attribute left|right)
686
+ Handled as a separate block element brought outside the table, so:
687
+ CSS will not cascade correctly on the table
688
+ width of caption block is that of page or of the block element containing the table
689
+ so alignment will be to the page-width not the table width
690
+ if table page-break-after: always, the caption will follow the pagebreak.
691
+ This does work:
692
+ <style>
693
+ .tablecaption { caption-side: bottom; text-align: left; font-weight: bold; color: green; }
694
+ </style>
695
+ ...
696
+ <table>
697
+ <caption class="tablecaption">Caption title here</caption>
698
+ <tbody>
699
+
700
+ CSS visibility: printonly, screenonly
701
+ -------------------------------------
702
+ Roughly based on CSS
703
+
704
+ Works on Block elements P, DIV etc, or Image
705
+ Cannot nest / layer.
706
+ Inner blocks/image with set visibility are ignored if already set on enclosing block element.
707
+ (Block element) does not work inside table (image does)
708
+ So 'visible' does nothing but is set as default
709
+ (NB Changes output to PDF version 1.5)
710
+ Incompatible with PDFA / PDFX
711
+
712
+ 'visibility'
713
+ Value: visible | hidden | (collapse | inherit)
714
+ Initial: visible
715
+ Applies to: all elements
716
+ Inherited: yes
717
+
718
+ The 'visibility' property specifies whether the boxes generated by an element are rendered.
719
+ Invisible boxes still affect layout (set the 'display' property to 'none' to suppress box generation altogether).
720
+ Values have the following meanings:
721
+
722
+ visible
723
+ The generated box is visible.
724
+ hidden
725
+ The generated box is invisible (fully transparent, nothing is drawn), but still affects layout.
726
+ Furthermore, descendants of the element will be visible if they have 'visibility: visible'.
727
+ collapse | inherit
728
+ NOT supported in mPDF
729
+
730
+ CUSTOM:
731
+ printonly | screenonly
732
+
733
+
734
+ Added VISIBILITY function
735
+ $mpdf->SetVisibility('screenonly'); or 'printonly' 'visible' or 'hidden'
736
+ (NB Changes output to PDF version 1.5)
737
+ Incompatible with PDFA / PDFX
738
+
739
+ CircularText
740
+ ------------
741
+ function CircularText($x, $y, $r, $text, $align='top', $kerning=120, $fontwidth=100) {
742
+ x: abscissa of center
743
+ y: ordinate of center
744
+ r: radius of circle
745
+ text: text to be printed
746
+ align: text alignment: top or bottom. Default value: top
747
+ kerning: spacing between letters in percentage. Default value: 120. Zero is not allowed.
748
+ fontwidth: width of letters in percentage. Default value: 100. Zero is not allowed
749
+
750
+ - now uses Kerning between letters if useKerning == true (set manually see example)
751
+
752
+ BookMark styling
753
+ ----------------
754
+ New configurable variable to control appearance of Bookmarks e.g.
755
+ $this->bookmarkStyles = array(
756
+ 0 => array('color'=> array(0,64,128), 'style'=>'B'),
757
+ 1 => array('color'=> array(128,0,0), 'style'=>''),
758
+ 2 => array('color'=> array(0,128,0), 'style'=>'I'),
759
+ );
760
+
761
+ Column sums
762
+ -----------
763
+ (Also changed some preg_replace to str_replace to improve performance)
764
+ To use: just add {colsum} to any cells of the table footer <tfoot>
765
+ Add a number to specify a fixed number of decimal points e.g. <td>�{colsum2}</td> will give you �123.40
766
+ The width of the column will be calculated using the actual string {colsum} as a placeholder.
767
+ If you need the column to be wider, use underscores "_" to pad it e.g. {colsum2_____}
768
+
769
+
770
+ Spread tables
771
+ -------------
772
+ i.e. can split table (columns) across several pages width.
773
+ CSS <table style="overflow: visible">
774
+ Cannot use with:
775
+ $this->kwt - ignored
776
+ $this->table_rotate - ignored
777
+ $this->table_keep_together - ignored
778
+ $this->ColActive - cancels spread tables
779
+
780
+ Messes up with:
781
+ $mpdf->forcePortraitHeaders = true;
782
+ $mpdf->forcePortraitMargins = true;
783
+ Problems with CJK, and RTL
784
+
785
+ Will do no resizing of fonts at all.
786
+ Maximum width of column = page width i.e. will not split columns across pages - NB will keep colspan>1 on one page
787
+ If table row too high for page will die with error message.
788
+ Will override some specs for width if this creates conflicts
789
+ Recommended to specify absolute value of width on each column.
790
+
791
+
792
+
793
+
794
+ Bug fixes
795
+ =========
796
+ Dottab - if text after dottab is hyperlinked <a></a> then dots are underlined
797
+
798
+ page-break-before now respects $mpdf->restoreBlockPagebreaks = true; i.e. will make pagebreak act like formfeed
799
+ Annotation() function called directly with colorarray(r,g,b)
800
+
801
+ Added urldecode to _getImage to cope with ../name%20of%20image.jpg
802
+ Added urldecode AND htmlspecials_decode to href in <a> link e.g. https://www.google.com/search?hl=en&amp;q=mpdf&amp;filename=name%20of%20file
803
+ [barcode.php] Allow &nbsp; in C39 codes - will be changed to spaces
804
+
805
+ <table> inside a <div position:fixed, left:300px;> not calculating table width correctly
806
+ - leading to either upside down table or error width less than 1 character
807
+
808
+ Depracated magic_quotes_runtime() in compress.php
809
+
810
+ DIRECTW included twice in compress.php
811
+ FORMS mark up for compress.php corrected
812
+
813
+ double backslashes not preserved inside <pre> or <textarea>
814
+
815
+ font-weight and font-style not recognised in <pageheader>
816
+
817
+ Progress bars causing corrupt PDF file (out.php) changed fopen from "r" mode to "rb" (binary)
818
+ Target around image - <a href="#internaltarget"><img ... /></a> - not working
819
+
820
+ SmallCaps in <thead> error
821
+
822
+ Fonts with "name" table in format 1 not recognised correctly
823
+ Rotated table which does not fit on remaining page, forces a new page even if already at top of page
824
+
825
+ Locale causing problems - all instances of sprintf() using %.3f changed to %.3F so not locale aware
826
+
827
+ CSS border radius not implemented on fixed/absolute positioned block element
828
+
829
+ Background color in rotated table extending way beyond bottom of table
830
+
831
+ Nested table containing <thead> or <tfoot> was confused with <thead> or <tfoot> of parent table
832
+
833
+ Correct handling of spaces, < or & in textarea
834
+
835
+ <option> and <input ..> attributes value/title decoded with fn lesser_entity_decode instead of htmlspecialchars_decode to include &apos;
836
+
837
+ line width not restored to correct value after "line-through" text in Cell()
838
+
839
+ Kannada - incorrect positioning of Reph
840
+
841
+ Forms - In <input> or <option> (select) not correctly handling HTML named entities e.g. &lt; in value or title
842
+ Active forms - &nbsp; as Value or Title incorrectly showing as Euro - PDFDocEncoding fixed
843
+
844
+ Unicode data in embedded fonts not encrypted when doc encrypted
845
+
846
+ Nested block elements which are empty including innermost one, top margin of innermost block was ignored
847
+
848
+ font-size: xx% inside a block was setting on block's parent font-size
849
+
850
+ Active forms - radio buttons (removed name from Widget - leave on Radio group)
851
+ causing problems accessing field for radio buttons
852
+
853
+ When using simple tables and border-collapse, if table border set, but cell borders not set, should display table border (fixed)
854
+ position:fixed block - if neither top nor bottom nor height specified, was positioned incorrectly (y)
855
+ Leave - if top, bottom, margin-top, margiin-bottom and height are all left unspecified (or auto), will centre vertically
856
+ on the page (specific to mPDF - not consistent with CSS2.1)
857
+ But if any one of them are specified (including e.g. margin-top=0), follows CSS spec, so top is the current "static" position
858
+
859
+ background-image-opacity=0 not working on BODY or BLOCK
860
+
861
+ Lists - if LI continues after a nested List, would add as a new LI item (should continue as part of earlier LI item)
862
+
863
+ fn WriteCell() converts to 'windows-1252' when required
864
+ if multiple calls to mPDF used, cannot redefine function cmp()
865
+ internal link targets <a name="xx" /> in ToC not moved when using: page-break-inside:avoid
866
+ internal link targets <a name="xx" /> not moved when using: columns, page-break-inside:avoid, keep-with-table or table rotate
867
+
868
+ Active Forms - onChange not working for SELECT (cf. 5.3.25) Example 57 only worked by chance as JS was carried over from Select to Text field
869
+ Bug is fixed, but example file needed updating to onCalculate for the display field.
870
+
871
+ Table cell: if height set as %, currently sets it as % of page-width; instead this now ignores it.
872
+
873
+ Bengali letter Khanda Ta (U+09CE) character not recognised; was added in Unicode v4.1 and prior to this, (U+09A4 U+09CD U+200D)
874
+ so mPDF converts to this string and seems to work.
875
+
876
+ OCR characters wrong size in barcodes if using different ocr font - fixed
877
+
878
+ ===========================
879
+ mPDF v5.3 (21/07/2011)
880
+ ===========================
881
+
882
+ New Features
883
+ ------------
884
+ - Active forms (see on-line manual for details)
885
+ - 128-bit encryption (optional) with additional user-permissions (see on-line manual)
886
+
887
+ PLEASE READ - Change in Font management
888
+ ---------------------------------------
889
+ The font name imported from the font and included by mPDF in the PDF file was stripping any '-' in the name.
890
+ This is the PostScript name which is utilised by some PostScript programmes.
891
+ mPDF has been changed to leave the PostScript font name unchanged. In 99% cases no difference will be noted, but
892
+ you MUST delete all the temporary font data files cached in the /ttfontdata/ folder for this to be effective.
893
+
894
+
895
+ Minor changes
896
+ -------------
897
+ If @page CSS is used to select a first page with settings different from the default, mPDF did create a blank page
898
+ then pagebreak to the new @page settings - this has been changed so it now will start with the new page settings.
899
+
900
+ New function added: DeletePages($start_page, $end_page=-1) e.g. $mpdf->DeletePages(1);
901
+ Can be used just before calling Output()
902
+
903
+ compress.php utility extended to exclude active forms and images-svg
904
+
905
+
906
+ Bug fixes
907
+ ---------
908
+ - list-style-type: (custom version, user-defined bullet) colour change not working if colour is set on the list item line
909
+ - background-image: SVG or WMF images as background-images in tables/tr/cells not working
910
+ - font-weight: bold font not always reset after inline <b>...</b> thus miscalculating width
911
+ - forms (inactive) in 'c' core fonts using unicode characters 127-255 incorrect display in input text and button text
912
+ - form elements (inactive) if in-line with mixed size fonts, error in vertical positioning of text related to box
913
+ - ToC: wrapped lines in ToC not retaining formatting e.g. bold style
914
+ - HTMLHeaders: using setAutoTopMargin="pad"; not correctly setting top margin for first page
915
+ - output headers changed: Content-length not used if server uses output compression
916
+ - embedded font subsets from fonts which contain non-BMP plane 0 characters (incl. e.g. dejavusanscondensed)
917
+ - causing Adobe Reader to create a CJK encoded font subset internally when loading interactive Forms
918
+ - Changed so unsets the flag in the subset font to show no non-BMP characters.
919
+
920
+
921
+ Configurable variables added (see config.php file):
922
+ --------------------------------------------------
923
+ All for Active Forms:
924
+ $this->useActiveForms
925
+ $this->formExportType
926
+ $this->formSubmitNoValueFields
927
+ $this->formSelectDefaultOption
928
+ $this->form_border_color
929
+ $this->form_background_color
930
+ $this->form_border_width
931
+ $this->form_border_style
932
+ $this->form_button_border_color
933
+ $this->form_button_background_color
934
+ $this->form_button_border_width
935
+ $this->form_button_border_style
936
+ $this->form_radio_color
937
+ $this->form_radio_background_color
938
+
939
+ PLUS: see additional values added to $this->allowedCSStags close to bottom of file - required for Active forms
940
+
941
+
942
+ Updated files
943
+ -------------
944
+ mpdf.php
945
+ config.php (NB as well as form stuff at top, 5.2.07 $this->allowedCSStags close to bottom of file)
946
+ compress.php
947
+ classes/ttfontsuni.php
948
+ examples/example57...
949
+ examples/formsubmit.php
950
+
951
+
952
+
953
+ ===========================
954
+ mPDF v5.2 (18/06/2011)
955
+ ===========================
956
+
957
+ New Features
958
+ ------------------
959
+ Improvements in font handling resulting in clearer display of fonts on screen, and improved compatibility with PostScript drivers
960
+ (e.g. use with GSView/GhostScript, see below)
961
+
962
+ CJK line-breaking implemented (roughly) according to rules. Configurable variables allow control of behaviour (except in tables).
963
+
964
+ Viewer preferences: added options for initial 2 page display where you can specify whether
965
+ 1st page is on left or right (cf. SetDisplayMode).
966
+
967
+ Custom list-style-type for a list (ul,ol) or a list-item (li) in which you can determine the character and colour of the bullet:
968
+ list-style-type: U+263Argb(255,0,0); - where U+263A is the Unicode HEX value of the character you want for the bullet
969
+ - character MUST be included in the font used for that list item. rgb() bit is optional
970
+
971
+
972
+ Bug fixes
973
+ ---------
974
+ - Fonts: embedding a BMP TTC font (e.g. Cambria) as a full font caused error
975
+ - Table: If cell width set by CSS as %, and page-break-inside avoid requires a new page, was losing the sizing
976
+ - Table: table borders CSS parsing error; if border-width, border-style, border-color set, not inherited correctly
977
+ - Table: Table background image or gradient not working in HTMLHeader/Footer
978
+ - Table: background color set on table (anywhere) will overwrite image/gradient
979
+ - Table Background image/gradient: If left/right margin is set on table, gradient/image set on table is too wide
980
+ - Table: rotated table - height (after first page does not correctly allow for thead i.e. too much)
981
+ - Table: blank <tr></tr> causes error
982
+ - Table/Letter-spacing: If letter-spacing set inside table, not calculating table width correctly, and if oversized, freezes
983
+ - ToC: ToC at top of page (non-mirrored or already ODD) did not reset page_number if told
984
+ - Character subsititutions: characters missed if first element in a $html code e.g. WriteHTML('Not in a tag &#10003;');
985
+ - Kerning: kerning info: if reading font file for first time (or if not cached in ttfontdata/) did not register kerning info
986
+ - Textarea: multiple new lines run into only one newline
987
+ - QRCode - colors wrong because QRcode class only accepts RGB input (hardcoded now to always give black on white)
988
+ - QRCode always producing "Your message here"
989
+ - Columns: if transforming height of column, not always closing transform Q
990
+ - CakePHP compatibility
991
+ - compress.php - error due to markup comments in mpdf.php script file
992
+
993
+ Backwards compatibility
994
+ -----------------------
995
+ Changes in mPDF 5.2 are backwards compatible with version 5.1
996
+ Your document fonts may appear slightly different in the PDF viewer because of the changes to embedded font subsets (cf.)
997
+ The new Indic fonts may result in a change in spacing (due to the different character width of the space character from the original font)
998
+
999
+ PostScript e.g. GSView/GhostScript
1000
+ ----------------------------------
1001
+ A number of errors have been reported when opening mPDF-created PDF files with a PostScript programme. Some of the errors were due to mPDF,
1002
+ but others were due to peculiarities of GSView/GhostScript.
1003
+ - Diacritic Characters were not displayed when embedding a font subset
1004
+ - Fonts containing SIP/SMP characters (supplementary Unicode planes) caused errors
1005
+ - Error with text justification (word-spacing) when embedding a full font can occur in some fonts*
1006
+ The first 2 problems should now be fixed in v5.2
1007
+ *The error with text justification can be optionally fixed by setting the configurable variable in config.php:
1008
+ $this->repackageTTF = true;
1009
+ When mPDF embeds a full font, it simply embeds the whole original TTF file into the PDF document. For some fonts (containing
1010
+ a GSUB table) this was causing problems. $this->repackageTTF forces mPDF to repackage the original TTF file excluding some of
1011
+ the tables like GSUB.
1012
+ (See ADDITIONAL INFO FONTS.txt in downloaded files)
1013
+
1014
+
1015
+ Font appearance in PDF viewer
1016
+ -----------------------------
1017
+ Font subsetting has been improved to include additional information in the embedded file. Overall the effects are of greater clarity
1018
+ when viewing the document on a screen (it will not affect print output), but the changes are dependent on:
1019
+ - the original TTF font i.e. the options that the font's author has built into the file
1020
+ - the PDF viewer i.e. whether the programme chooses to use the available information
1021
+ - the resolution (zoom) of the page you are viewing
1022
+ (See ADDITIONAL INFO FONTS.txt in downloaded files)
1023
+
1024
+
1025
+ Indic fonts
1026
+ -----------
1027
+ A new set of Indic fonts (ind_xx_1_001) is distributed with version 5.2 containing the additional font information as described above.
1028
+ In addition, some changes have been made to the ASCII characters in the font from the files previously distributed:
1029
+ The original files (Raghu font files) do not contain the characters a-z and A-Z. When the first version indic files were created for mPDF,
1030
+ ALL of the ASCII characters (32-127) were inserted/overwritten from DejaVuSansCondensed to make the font more usable.
1031
+ In the latest version, only the missing characters are taken from DejaVuSansCondensed, leaving punctuation and numerals from the original
1032
+ fonts. This also means that the space character has a different width, and this will cause slight changes to the word spacing in documents.
1033
+ (See ADDITIONAL INFO FONTS.txt in downloaded files)
1034
+
1035
+
1036
+ CJK line-breaking (text wrapping)
1037
+ ---------------------------------
1038
+ CJK (chinese-japanese-korean) text often contains no spaces. mPDF previously has wrapped text whenever a character reached the end of
1039
+ the line. mPDF version 5.2 attempts to follow the line-breaking rules described for each of the languages. Configurable variables
1040
+ allow some control over this behaviour, especially whether to squeeze a character into the space available at the end of a line, or
1041
+ whether to allow it to overflow the right margin.
1042
+
1043
+
1044
+ Configurable variables (see config.php file):
1045
+ ----------------------
1046
+ Control wrapping of CJK text:
1047
+ $this->allowCJKorphans = true; // FALSE=always wrap to next line; TRUE=squeeze or overflow
1048
+ $this->allowCJKoverflow = false; // FALSE=squeeze; TRUE=overflow (only selected)
1049
+ When Embedding full TTF font files, remakes the font file using only core tables
1050
+ May improve function with PostScript printers
1051
+ $this->repackageTTF = false;
1052
+
1053
+ Updated files
1054
+ -------------
1055
+ mpdf.php
1056
+ compress.php
1057
+ utils/font_dump.php
1058
+ classes/ttfontsuni.php
1059
+ config.php (3 new variables - see above)
1060
+
1061
+ All ttfonts/ind_*
1062
+ New set of Indic fonts for PostScript compatibilty - and clearer font display
1063
+
1064
+
1065
+
1066
+ ===========================
1067
+ mPDF v5.1 (27/02/2011)
1068
+ ===========================
1069
+
1070
+ New Features
1071
+ ------------
1072
+ - CSS background (images, colours or gradients) on <TR> and <TABLE>
1073
+ - CSS border on <TR> (only in border-collapsed mode)
1074
+ - support for Mozilla and CSS3 gradient syntax:
1075
+ -moz-linear-gradient, linear-gradient
1076
+ -moz-radial-gradient, radial-gradient
1077
+ -moz-repeating-linear-gradient, linear-repeating-gradient
1078
+ -moz-repeating-radial-gradient, radial-repeating-gradient
1079
+ - expanded support for gradients (including in SVG images):
1080
+ - multiple colour 'stops'
1081
+ - opacity (transparency)
1082
+ - angle and/or position can be specified
1083
+ - gradient can be used as an image mask (custom mPDF styles: gradient-mask)
1084
+ - image-orientation supported for <IMG> (similar to existing custom mPDF attribute: rotate) [CSS3]
1085
+ - image-resolution supported for <IMG> [CSS3]
1086
+ - background-image-resolution (custom mPDF CSS-type style) to define resolution of background images
1087
+ - improved support for SVG images
1088
+ - SVG and WMF images supported in background-image
1089
+ - file attachments
1090
+ - numeric list-styles added e.g. arabic-indic, bengali, devanagari, persian, thai [CSS3]
1091
+ - font kerning supported (inter-character spacing between specific pairs)
1092
+ - letter-spacing and word-spacing supported [CSS3]
1093
+ - colors supported as rgb(), rgba(), hsl(), hsla(), cmyk(), cmyka(), or spot()
1094
+ - spot colors supported e.g PANTONE 310 EC
1095
+ - PDF/X compatible files
1096
+ - optionally force use of grayscale, RGB or CMYK colorspace
1097
+ - automatic colour conversion for most objects between grayscale, RGB and CMYK
1098
+
1099
+ Backwards compatibility
1100
+ -----------------------
1101
+ Most changes in mPDF 5.1 are backwards compatible with version 5.0 i.e. your documents should
1102
+ look the same running 5.1 However some changes may alter display from previous versions:
1103
+ - RTL (right-to-left) languages - see below
1104
+ - bleed margins when using @page CSS - see below
1105
+ - Default distance for "cross" from inner margin changed 10->5mm [hardcoded in fn. Footer()]
1106
+ - If height set on a block element, will force a new page if set-height will not fit on page
1107
+ - If table rotated, 5mm margin at bottom is now reduced to 1mm
1108
+ - If image is too big for page and automatically sixed to maximum height of page, 10mm margin at bottom reduced to 1mm
1109
+
1110
+ Colours may appear more vibrant
1111
+ -------------------------------
1112
+ Unless specifically set, Adobe Reader uses the RGB colorSpace by default when displaying documents. However
1113
+ if an image or gradient using transparency (or alpha channel) is included in the document, Adobe Reader
1114
+ automatically sets the default colorSpace to CMYK - which makes the colours look less vibrant/bright on screen.
1115
+ mPDF 5.1 now specifies by default a colorSpace RGB for each page, and this will maintain the more
1116
+ vibrant colours. This is overridden if you use on of the options to restrict the colorSpace (cf.)
1117
+
1118
+ RTL
1119
+ ---
1120
+ **** IMPORTANT - PLEASE READ IF USING RTL SCRIPTS ****
1121
+ Handling of RTL (right-to-left) languages has been significantly rewritten, and is likely to cause
1122
+ changes to the resulting files if you have previously been using mPDF. The changes have made mPDF
1123
+ act more like a browser, respecting the HTML/CSS rules.
1124
+ Changes include:
1125
+ - the document now has a baseline direction; this determines the
1126
+ - behaviour of blocks for which text-align has not been specifically set
1127
+ - layout of mirrored page-margins, columns, ToC and Indexes, headers and footers
1128
+ - base direction can be set by any of:
1129
+ - $mpdf->SetDirectionality('rtl');
1130
+ - <html dir="rtl" or style="direction: rtl;">
1131
+ - <body dir="rtl" or style="direction: rtl;">
1132
+ - base direction is an inherited CSS property, so will affect all content, unless...
1133
+ - direction can be set for all HTML block elements e.g. <DIV><P><TABLE><UL> etc using
1134
+ - CSS property < style="direction: rtl;">
1135
+ - direction can only be set on the top-level element of nested lists
1136
+ - direction can only be set on <TABLE>, NOT on THEAD, TBODY, TD etc.
1137
+ - nested tables CAN have different directions
1138
+ - NOTE that block/table margins/paddings are NOT reversed by direction
1139
+ NB mPDF <5.1 reversed the margins/paddings for blocks when RTL set.
1140
+ - language (either CSS "lang", using Autofont, or through initial set-up e.g. $mpdf = new mPDF('ar') )
1141
+ no longer affects direction in any way.
1142
+ NB config_cp.php has been changed as a result; any values of "dir" set here are now ineffective
1143
+ - default text-align is now as per CSS spec: "a nameless value which is dependent on direction"
1144
+ NB default text-align removed in default stylesheet in config.php
1145
+ - once text-align is specified, it is respected and inherited
1146
+ NB mPDF <5.1 reversed the text-align property for all blocks when RTL set.
1147
+ - the configurable value $rtlcss is depracated, as it is no longer required
1148
+ - improved algorithm for dtermining text direction
1149
+ - english word blocks are handled in text reversal as one block i.e. dir="rtl"
1150
+ [arabic text] this will not be reversed [arabic text]
1151
+ - arabic numerals 0-9 handled correctly
1152
+
1153
+ Although the control of direction for block elements is now more configurable, the control of
1154
+ text direction (RTL arabic characters) remains fully automatic and unconfigurable.
1155
+ <BDO> etc has no effect. Enclosing text in silent tags can sometimes help e.g.
1156
+ content<span>[arabic text]</span>content
1157
+
1158
+ Justified text
1159
+ --------------
1160
+ Text-align: justify - no longer uses configurable variable $jSpacing= C | W | ''
1161
+ The default value is for mixed letter- and word-spacing, set by jSWord and jSmaxChar
1162
+ If a line contains a cursive script (RTL or Indic [devanagari, punjabi, bengali]) then it prevents letter-spacing
1163
+ for justification on that line - effectively the same as setting letter-spacing:0
1164
+ Spacing values have been removed from the config_cp.php configuration file, so the "lang" property
1165
+ (in config_cp) no longer determines justification behaviour (this includes the use of Autofont()).
1166
+ When using RTL or Indic [devanagari, punjabi, bengali] scripts, you should set CSS letter-spacing:0
1167
+ whenever you use text-align:justify.
1168
+
1169
+
1170
+ @page media
1171
+ -----------
1172
+ When using @page to create a print publication with page-size less than sheet-size
1173
+ - bleed margin is now configurable (also crop- and cross-mark margins)
1174
+ - backgrounds/gradients/images now use the bleed box as their "container box"
1175
+ - odd-header-name: supports the value "_default" - allows current non-HTML header to remain unchanged
1176
+ - marks: crop cross; i.e. both together supported
1177
+ - background-image-opacity and background-image-resize now work with @page CSS
1178
+
1179
+
1180
+ SVG images - extended support
1181
+ -----------------------------
1182
+ - support for spreadMethod property for gradients (repeat and reflect)
1183
+ - support for style="font-family; font-size; font-style; font-weight" i.e. inline CSS
1184
+ - when viewPort="" and width="" height="" all specified, uses width to set SVG size of a "pixel"
1185
+ - support for opacity and multiple "stops" (and colorspace) in gradients
1186
+
1187
+
1188
+
1189
+ Minor Enhancements
1190
+ ------------------
1191
+ - support for colors as rgb(87%, 56%, 25%) [used especially in SVG]
1192
+ - added option of "NoPrintScaling" in SetDisplayPreferences
1193
+ - compress.php - now combines BACKGROUND-IMAGES and GRADIENTS as BACKGROUNDS, and added PROGRESS-BAR
1194
+ - table with THEAD row will force a new page if no room for the THEAD AND a row from TBODY
1195
+ - Small-Caps now works properly together with text-align justify
1196
+ - embedded font subsets restructured (minor) for greater compatibility e.g. with Postscript printers
1197
+ - PDF/A will convert everything except grayscale to RGB (by default) or CMYK (optionally)
1198
+
1199
+
1200
+
1201
+
1202
+ Bug fixes
1203
+ ---------
1204
+ - Display changed to CMYK colour gamut when document contained an object with transparency set.
1205
+ Now will retain RGB colorspace (brighter colours)
1206
+ - If using dir="rtl", tables containing nested tables were not properly reversed
1207
+ - "text-rotate: 0" set in CSS stylesheet did not 'undo' any text-rotate set on the row (TR)
1208
+ - Malayalam - character re-ordering
1209
+ - If height set on a block element, was not taking account of padding top/bottom
1210
+ - embedded font subsets: error in array of Font Widths fixed
1211
+ - <style>..</style> containing /* import url() */ the comments were not ignored
1212
+ - If call mPDF class more than once, error using multiple barcodes or gif files because classes not reinstantiated
1213
+ - Floating blocks were collapsing bottom/top margins - incorrectly
1214
+ - Table: if colspan>1 contents are wider than the width of the included columns, did not increase column width(s) to accommodate
1215
+ - Resizing table - script hanging and new page forced when not required (still)
1216
+ - If a table style="page-break-inside:avoid" not fit on the page, was adding new page before resizing EVEN IF on a blank page
1217
+ - End of 2 blocks (e.g. </div></div>) at very bottom of page, forcing unwanted pagebreak
1218
+ - Corrected handling of tags inside <pre>
1219
+ - RTL left-aligned text - line ending with <br /> not correctly left-aligned
1220
+ - <input type=submit|reset etc name="xxx" e.g. Google button showed as I&039;m feeling lucky
1221
+ - Annotations all linked to Page 1 (parent object)
1222
+ - Error "division by zero" using columns
1223
+ - MultiCell() and Write() [direct writing functions] - miscalculating length of line in non-core fonts (+ other bugs)
1224
+ - error if CJK space at end or beginning of line with 0x20 spaces in as well
1225
+
1226
+ Configurable variables (see config.php file):
1227
+ ----------------------
1228
+ $this->printers_info
1229
+ $this->bleedMargin
1230
+ $this->crossMarkMargin
1231
+ $this->cropMarkMargin
1232
+ $this->cropMarkLength
1233
+ $this->nonPrintMargin
1234
+ $this->restrictColorSpace
1235
+ $this->PDFX
1236
+ $this->PDFXauto;
1237
+ $this->useKerning
1238
+ [$this->rtlcss removed]
1239
+
1240
+ Updated files
1241
+ -------------
1242
+ mpdf.php
1243
+ config.php
1244
+ config_cp.php (removed references to dir - but not essential to update - just redundant information)
1245
+ compress.php
1246
+ includes/out.php
1247
+ includes/functions.php
1248
+ classes/svg.php
1249
+ classes/ttfontsuni.php
1250
+ classes/indic.php
1251
+ /font/helvetica*.php and /times*.php
1252
+
1253
+ Added CSS support
1254
+ =================
1255
+ All Block elements including <BODY> <TABLE> <TR>
1256
+ ------------------------------------------------
1257
+ background-image-resolution: normal | [ from-image || <dpi> ]
1258
+ direction: [ rtl | ltr ] (HTML attribute dir also supported)
1259
+ background: [ gradients ]
1260
+ background-image: [gradients ]
1261
+
1262
+ For [ gradients ] syntax see:
1263
+ - Mozilla linear - https://developer.mozilla.org/en/CSS/-moz-linear-gradient
1264
+ - Mozilla radial - https://developer.mozilla.org/en/CSS/-moz-radial-gradient
1265
+ - Mozilla gradients use - https://developer.mozilla.org/en/Using_gradients
1266
+ - CSS3 linear gradients - http://dev.w3.org/csswg/css3-images/#linear-gradients
1267
+ - CSS3 radial gradients - http://dev.w3.org/csswg/css3-images/#radial-gradients
1268
+
1269
+
1270
+ Almost all elements - block and in-line
1271
+ ---------------------------------------
1272
+ font-kerning: auto | normal | none // need to set $mpdf->useKerning = true;
1273
+ letter-spacing: normal | <length>
1274
+ word-spacing: normal | <length>
1275
+
1276
+ Colours
1277
+ -------
1278
+ Anywhere that color is specified (e.g. color, background-color, borders)
1279
+ - rgb(255,255,255)
1280
+ - rgba(255,255,255,1) // last value is transparency (alpha) - between 0-1
1281
+ - rgb(100%,100%,100%)
1282
+ - hsl(360,100%,100%) // H: 0-360; S/L: 0-100%; a:0-1
1283
+ - hsla(360,100%,100%,1)
1284
+ - cmyk(100,100,100,100) // or 0-100%
1285
+ - spot(COLOR NAME, 100%) // e.g PANTONE 310 EC; use AddSpotColor() to define first
1286
+
1287
+ <TR>
1288
+ border:
1289
+
1290
+ <TABLE> <TR>
1291
+ background:
1292
+ background-color:
1293
+ background-image:
1294
+
1295
+ <IMG>
1296
+ gradient-mask: [can use any of the gradient syntax]
1297
+ image-orientation: <angle> - supports deg, rad or grad
1298
+ image-resolution: normal | [ from-image || <dpi> ]
1299
+
1300
+ <OL|UL>
1301
+ list-style: arabic-indic | bengali | devanagari | gujarati | gurmukhi | kannada | malayalam | oriya |
1302
+ persian | telugu | thai | urdu | tamil
1303
+
1304
+
1305
+ @page
1306
+ marks: [ crop || cross ] - i.e. crop and cross can be used together
1307
+ odd-header-name: "_default" - allows current non-HTML header to remain unchanged
1308
+ background-image-opacity: [ 0-1 ]
1309
+ background-image-resize: [ 1-6 ] - see Manual
1310
+
1311
+
1312
+ ===========================
1313
+ mPDF v5.0 (30/09/2010)
1314
+ ===========================
1315
+
1316
+ New Features
1317
+ ------------
1318
+ - Font handling simplified, reads TrueType font files directly
1319
+
1320
+
1321
+ Minor Enhancements
1322
+ ------------------
1323
+ - rotation of fixed-position block elements (see example 10 and manual for supported CSS)
1324
+ - support for CSS Small-Caps font-variant added
1325
+ - utility scripts in /utils/ folder to help font management
1326
+ - new simplified functions AddPageByArray() and TOCPageBreakByArray() added
1327
+ - progress bar simplified and customisable
1328
+ - improved word-wrapping for CJK langauges
1329
+ - improved recognition of CJK/Indic/Arabic characters
1330
+ - invalid UTF-8 input now outputs a meaningful error by displaying input html with errors marked
1331
+ - GIF or PNG images with transparency/interlaced/non-standard compression handled as internal data
1332
+ if /tmp/ folder is not present or writeable
1333
+ - support for <html dir="rtl">
1334
+ - support for "display: none" on inline elements
1335
+ - annotations supported in fixed-position block elements
1336
+
1337
+
1338
+ Bug fixes
1339
+ ---------
1340
+ - <br /> preceded by space does not correctly text-align to right
1341
+ - zero-width character in middle of line caused line-break (e.g. diacritic or U+200C = ZWNJ)
1342
+ - HTML attributes not recognised if spaces e.g. 'src = "..."'
1343
+ - Headers changed for output - problem reported on IE8 64-bit using SSL
1344
+ - using SetAutoPageBreak(false) used caused unexpected behaviour with table rows at page break
1345
+ - (from Beta) incorrect check for temporary font data folder causing errors
1346
+ - artificial Bold/Italic not working in table cell when using rotated text
1347
+ - allow <dottab> to inherit font color correctly
1348
+ - SVG now works with Adobe 7
1349
+ - background in header overwriting text
1350
+ - vertical text in table header not correctly horizontally positioned when repeated
1351
+ - compatibility with PHP >= 4.3 (htmlspecialchars_decode, stripos)
1352
+ - updated depracated script PHP 5.3.0 ($string{1} to $string[1], $var =& new Object(), set_magic_quotes_runtime)
1353
+ - index (CreateIndex) number string incorrect if arabic(rtl) text anywhere in document
1354
+ - MultiCell incorrectly calculate string length/width when using core fonts
1355
+ - page-break-inside:avoid - used with non-HTML footer had space inserted for footer height
1356
+ - page-break-inside:avoid - error if more than 1 page height but not enough to trigger second pagebreak
1357
+ - page-break-inside:avoid - incorrectly layering page backgrounds (headers and content brought forward)
1358
+
1359
+
1360
+ Changes from 5.0 Beta
1361
+ ---------------------
1362
+ If you are upgrading from the Beta version - you MUST delete all files in the /ttfontdata/ temporary directory
1363
+ - config.php file has been changed (extra CJK characters to recognise CJK blocks)
1364
+ - $this->backupSubsFont (in config_fonts.php) optionally now takes an array
1365
+ - no need to define 'cjk'=>true or 'sip|smp'=>true in config_fonts.php (ignored; cf. $this->BMPonly)
1366
+ - Indic language fonts have been altered to add Latin and Latin-1 Supplement characters
1367
+ - progress bars now has an external progbar.css and configurable main heading
1368
+ - added initial parameter new mPDF('+aCJK') or '-aCJK' to override default useAdobeCJK at runtime
1369
+ - QRCode is not included in main download (but as an extra package)
1370
+
1371
+ BACKWARD COMPATIBILITY
1372
+ ----------------------
1373
+ If you have been using earlier versions of mPDF, most scripts should work as before. But note:
1374
+ - Arial, Helvetica, Times and Courier are now treated like any other font
1375
+ - the whole CSS font string is parsed e.g. style="font-family:'Lucida Grande';" will look for a font 'lucidagrande'
1376
+ and not 'lucida'
1377
+
1378
+ Configurable variables (see config.php file):
1379
+ ----------------------
1380
+ - $mpdf->useSubstitutionsMB is now depracated, but will work as an alias for $mpdf->useSubstitutions
1381
+ The initial parameters e.g. new mPDF('utf-8') have all changed. Old ones may be recognised, or will be ignored.
1382
+ - $mpdf->useOnlyCoreFonts is now depracated and is ignored. Use new mPDF('c')
1383
+ - $this->use_CJK_only is now depracated and is ignored. See $this->useAdobeCJK and new mPDF('+aCJK') or '-aCJK'
1384
+ Control SmallCaps appearance
1385
+ - $mpdf->smCapsScale = 0.75; // Factor of 1 to scale capital letters
1386
+ - $mpdf->smCapsStretch = 115; // % to stretch small caps horizontally
1387
+ Customisable Progress bar
1388
+ - $mpdf->progbar_heading = 'mPDF file progress';
1389
+ - $mpdf->progbar_altHTML = '';
1390
+ Control fonts/subsetting
1391
+ - $mpdf->maxTTFFilesize = 2000;
1392
+ - $mpdf->percentSubset = 30;
1393
+ - $mpdf->debugfonts // show font errors and warnings
1394
+ Replaceable alias
1395
+ - $mpdf->iterationCounter = false; // Allow use of {iteration varname} in THEAD
1396
+
1397
+
1398
+ ===========================
1399
+ mPDF v5.0Beta (21/07/2010)
1400
+ ===========================
1401
+
1402
+ New features
1403
+ ------------
1404
+ The main change in mPDF v5 is the handling of TTF and TTC fonts directly.
1405
+ See README.txt and FONT INFO.txt for more information
1406
+
1407
+
1408
+ QR-code (2-dimensional barcode) Added
1409
+ -------------------------------------
1410
+ type="QR"
1411
+ Size=1 is an arbitrary 25mm widthxheight. error="L|M|H|Q"
1412
+ text="" can be numeric, alphanumeric or binary(?)
1413
+ Required whitespace is always included around it
1414
+
1415
+
1416
+ Enhancements
1417
+ ------------
1418
+ - progress-bar is simplified (no javascript class)
1419
+ - dir="rtl" supported in <html> or <body> tag
1420
+
1421
+ Bug fixes
1422
+ ---------
1423
+ - artificial Bold/Italic now working in table cells with rotated text
1424
+ - "-" is now allowed in a font name e.g. sun-exta
1425
+ - <dottab> now inherits font color correctly
1426
+ - SVG class bugs fixed (was crashing in Adobe Reader v 7)
1427
+ - background color/image in header no longer overwrites the header text
1428
+
1429
+ Changed Config variables
1430
+ ------------------------
1431
+ $this->useSubstitutionsMB is depracated
1432
+ Character substitution always occurs when using core fonts.
1433
+ Use $this->useSubstitutions for all cases.
1434
+
1435
+
1436
+ New Configurable variables
1437
+ --------------------------
1438
+ $this->useAdobeCJK = true; // Uses Adobe CJK fonts for CJK languages
1439
+ // default TRUE; only set false if you have defined some available fonts that support CJK
1440
+ // If true this will not stop other CJK fonts if specified by font-family:
1441
+ // and vice versa i.e. only dictates behaviour when specified by lang="" incl. AutoFont()
1442
+
1443
+ // Set maximum size of TTF font file to allow non-subsets - in kB
1444
+ // Used to avoid e.g. Arial Unicode MS (perhaps used for substituteCharsMB) to ever be fully embedded
1445
+ // NB Free serif is 1.5MB, most files are <= 600kB (most 200-400KB)
1446
+ $this->maxTTFFilesize = 2000;
1447
+
1448
+ // If not -s (i.e. forced subset) this value determines whether to subset or not
1449
+ // 0 - 100 = percent characters
1450
+ // i.e. if ==40, mPDF will embed whole font if >40% characters in that font
1451
+ // or embed subset if <40% characters
1452
+ // 0 will force whole file to be embedded
1453
+ // 100 will force always to subset
1454
+ $this->percentSubset = 30;
1455
+
1456
+ $this->debugfonts - show errors and warnings for font parsing
1457
+
1458
+ Config variables removed
1459
+ ------------------------
1460
+ $this->use_CJK_only
1461
+ $this->useOnlyCoreFonts
1462
+
1463
+ ================================================================================
1464
+
1465
+ ====
1466
+ 4.6
1467
+ ====
1468
+
1469
+ mPDF
1470
+
1471
+ files changed:
1472
+ mpdf.php
1473
+ config.php
1474
+ makefonts/makefonts.php
1475
+ class/t1asm.php
1476
+ class/svg.php
1477
+ graph.php
1478
+
1479
+ examples_04 (images)
1480
+
1481
+ config var added:
1482
+ $this->tableMinSizePriority
1483
+
1484
+ 4.5.015
1485
+ Bug fix:
1486
+ Complex page with ToC entries ++ (example_ToC_bug4_5_015.php) caused Apache to crash
1487
+ AdjustHTML() preg_pattern for matching <hx>... </hx> <table for keep-together - altered and fixed ? matching
1488
+ Seemed to crash when content="Graph 12" between the <h> - 2 numbers (12) crash, 1 didn't!!!
1489
+
1490
+
1491
+ 4.5.014
1492
+ Bug fix:
1493
+ Using TrueType fonts, unused font is not embedded in the PDF doc. This was fine except an error message appeared after printing in Adobe Reader,
1494
+ because Font reference /F1 still present in doc pointing to non-existent resource.
1495
+ Edited so that the reference is now removed from the page if font unused.
1496
+
1497
+
1498
+ 4.5.013
1499
+ Enhancement
1500
+ TrueTypeUnicode fonts width array inserted as shortened form array (smaller file size)
1501
+
1502
+ 4.5.012
1503
+ Bug fix: Incorrect handling orphan characters in table
1504
+ (cf. http://mpdf.bpm1.com/forum/comments.php?DiscussionID=193 fixed in 4.2 - but going back to it still problems)
1505
+ If xxxxx. fits but xxxxx.. doesn't: WriteFlowingBlock wraps it to next line, TableWordWrap sqeezed it onto one line
1506
+ TableWordWrap fixed to only allow one orphan char. even if it fits with that one.
1507
+
1508
+
1509
+ 4.5.011
1510
+ Added Windows BMP image support
1511
+
1512
+ 4.5.010
1513
+ SVG class:
1514
+ - improved recognition of lineargradients/radialgradients referenced by xlink:href
1515
+ - does not die if empty text string
1516
+ - support for many text properties as style="" as well as currently as attributes (bold, fill etc)
1517
+ - if using MB font, was respecting "Times" and "Courier" from the SVG file but using as ANSI not utf-8
1518
+
1519
+ 4.5.009
1520
+ graph.php updated to include SVG - need to define in graph.php (as well as set up TTF fonts)
1521
+ (SVG graph does not include CSIM, 3D skew.)
1522
+
1523
+ 4.5.008
1524
+ t1asm.php has an error in the error message if .dat fontfile not found (".char.dat")
1525
+
1526
+ 4.5.007
1527
+ Bug fix: Using page-break-inside:avoid, if nothing would have been printed on page 1 before next page, elements going all over the place!
1528
+ Also problem shifting images - fixed
1529
+ Also wasn't shifting WMF/SVG images - fixed
1530
+
1531
+ 4.5.006
1532
+ New config var
1533
+ $this->tableMinSizePriority = false;
1534
+ If page-break-inside:avoid but cannot fit on full page without
1535
+ exceeding autosize; setting this value to true will force respsect for
1536
+ autosize, and disable the page-break-inside:avoid
1537
+ [NB edit Manual Table>>autolayout algorithm]
1538
+
1539
+
1540
+ 4.5.005
1541
+ Bug fix
1542
+ Table set to avoid page-break-inside: in some circumstances entered loop with recalculating size
1543
+ Fudge factor added of 0.001 in tbsqrt to calculate shrink factor
1544
+
1545
+ 4.5.004
1546
+ Bug fix
1547
+ If table set to avoid page-break-inside and table height (resized) exactly==remaining page - was triggering page break
1548
+ Fudge factor added of 0.001 in tablewrite to query pagebreak
1549
+
1550
+ 4.5.003
1551
+ Bug fix in makefonts/makefonts.php
1552
+ Also changed the links in Step4 & 8 which move the newly created files to the font directory - will now show error message if error -
1553
+ will NOT overwrite existing files. (Put in manual already)
1554
+
1555
+ 4.5.002
1556
+ Bug fix in class/t1asm.php
1557
+ If you have magic_quotes_runtime set On - problems using embedded subset.
1558
+
1559
+ 4.5.001
1560
+ JPG "Exif" file recognised from header, and handled much more quickly and efficiently (not using GD)
1561
+
1562
+
1563
+
1564
+ ===========================
1565
+ mPDF v4.5 (21/04/2010)
1566
+ ===========================
1567
+
1568
+ New Features
1569
+ ------------
1570
+ The main change in 4.5 is the improved class for importing SVG images. (See details below)
1571
+
1572
+ Font files
1573
+ ----------
1574
+ Some bugs in the "makefonts" utility caused some errors in the files produced for embedding font subsets.
1575
+ Surprisingly these are not easily detectable (I have yet to find one!).
1576
+ All the font files used for embedding font subsets (the .dat and .dat.php files in /unifont/ folder)
1577
+ have been re-generated. Download them if you are having problems with any fonts - otherwise, you probably
1578
+ don't need to bother.
1579
+
1580
+ Minor Enhancements
1581
+ ------------------
1582
+ If keepColumns = true (i.e. disable readjustment of column length), mPDF will now reproduce
1583
+ table header/footer rows in each column [4.4.015]
1584
+
1585
+ A number of changes to improve processing time [4.4.012]
1586
+ [Thanks to carlholmberg http://mpdf.bpm1.com/forum/comments.php?DiscussionID=274&page=1#Item_3]
1587
+
1588
+ JPG files with header marked as "progressive DCT-based JPEG" are now supported [4.4.004]
1589
+
1590
+ Configurable variable (config.php) $dpi can be set to vary size interpreted from "px" values in HTML/CSS
1591
+ NB Recommended that $dpi should always be set the same as $img_dpi
1592
+
1593
+ Support added for "ex" as a size value (approximates "ex" as half of font height)
1594
+
1595
+ Configurable variable (config.php) $watermarkImgAlphaBlend will determine how watermark images
1596
+ will blend with underlying objects.
1597
+
1598
+
1599
+ Bug fixes
1600
+ ---------
1601
+ - Make-fonts utility : makefonts/makefonts.php [4.4.016]
1602
+ (All font files have been updated)
1603
+ - Table header of only one column width - not printing right border [4.4.014]
1604
+ - WMF and SVG images not rotating correctly to 90 or -90 degrees [4.4.013]
1605
+ - Using templates, error if imported doc contains templates itself [4.4.001]
1606
+
1607
+
1608
+ Updated Files
1609
+ -------------
1610
+ mpdf.php
1611
+ config.php
1612
+ classes/svg.php
1613
+ makefonts/makefonts.php
1614
+ ALL subset font files (/unifont/ .dat and .dat.php files), and all garuda and norasi files
1615
+
1616
+ New files
1617
+ ---------
1618
+ None
1619
+
1620
+ New config variables
1621
+ --------------------
1622
+ $this->watermarkImgAlphaBlend
1623
+ $this->dpi
1624
+
1625
+ BACKWARD COMPATIBILITY
1626
+ ----------------------
1627
+ All but one changes in mPDF 4.5 are fully backwards compatible.
1628
+ The configurable variable $this->watermarkImgBehind was introduced in v4.4 and was unintentionally set to TRUE
1629
+ In v4.5 this is set to FALSE in the config.php file.
1630
+
1631
+
1632
+ SVG Images
1633
+ ----------
1634
+ [svg.php CHANGED]
1635
+ - Text stroke-width default changed to 1 [4.4.011]
1636
+ - Text stroke - line-join type changed [4.4.010]
1637
+ - Default value for fill changed to "black" [4.4.008]
1638
+ - Bug fixes:
1639
+ * to correct calculation of text-length (and therefore alignment R and C) [4.4.009]
1640
+ * Corrected errors in path implementation esp. quadratic Bezier curves
1641
+ * rounded corners to rectangles - error corrected
1642
+ * Recognition of font-family improved
1643
+ * remove \n (and other non-printable chars) from text
1644
+ * zero length shapes are not output e.g. zero-width rectangle, zero-length line, zero-radius circle
1645
+ - Support added for:
1646
+ * gradient stop offsets and gradientUnits="userSpaceOnUse" [4.4.007]
1647
+ In mpdf.php enabled define inner radius for radial gradients - only used internally by SVG at present
1648
+ * user defined <ENTITY /> cf. 'render-elems-03-t.svg' in SVG Test Suite [4.4.006]
1649
+ * "color" attribute and "currentColor" value for fill and stroke [4.4.005]
1650
+ * fill:url(#...) in a style as well as attribute
1651
+ * xlink:href for gradients
1652
+ * 1.3002e-005 in svg path
1653
+ * text-style changes (e.g. text-anchor) set on <g> element - not just on <text>
1654
+ * fill-rule=evenodd|nozero
1655
+ * dashed lines / stroke-dasharray & stroke-dashoffset
1656
+ * gradientUnits=userSpaceOnUse;
1657
+ * units e.g. 3mm or 14pt in Rectangle, Circle, Ellipse, Line and Text position
1658
+ * transform on <text> element
1659
+ * stroke as well as fill on text
1660
+
1661
+ NB The following are still NOT supported for SVG
1662
+ - filters
1663
+ - <marker>
1664
+ - images
1665
+ - DOM
1666
+ - <pattern>
1667
+ - textlength; lengthadjust; tspan, tref, toap, textPath;
1668
+ - <use ../>
1669
+ - gradient on stroke/text;
1670
+ - <clipPath>
1671
+ - text-underline and strikethrough
1672
+ - text opacity
1673
+ - colors as rgb(87%, 56%, 25%)
1674
+ - rect using units for dimensions
1675
+ - Only uses default spreadMethod = "pad" for gradients
1676
+
1677
+
1678
+
1679
+
1680
+
1681
+ ===========================
1682
+ mPDF v4.4 (24/03/2010)
1683
+ ===========================
1684
+
1685
+ New Features
1686
+ ------------
1687
+ - Support SVG image files (partial)
1688
+ - Rotate images or graphs (by multiples of 90 degrees)
1689
+ - Set opacity (transparency) for background images
1690
+ - Control resizing of background images
1691
+ - Set whether to print watermark images behind or in front of page contents
1692
+ - Reduced memory usage when printing tables (partly configurable)
1693
+ - Option to set path to folder for temporary files
1694
+ - Improved compliance for CSS text-align justify
1695
+ - Increased support for CSS "media"
1696
+ - Improved performance when accessing local image files
1697
+
1698
+
1699
+ Minor Enhancements
1700
+ ------------------
1701
+ - Allows space in output file name e.g. $mpdf->Output('t est.pdf','D'); [4.3.007B]
1702
+ - Header changed in Output to improve compatability with IE6 (affects 'D' and 'I') [4.3.012B]
1703
+ - background-images do not show noimage.jpg if missing [4.3.012D]
1704
+ - simpleTables (which improves performance) now also allows: background-color, -gradient and -image, padding
1705
+ and rotated text to be set for each cell. Only borders are not supported cell-by-cell. [4.3.006]
1706
+
1707
+
1708
+ Bug fixes
1709
+ ---------
1710
+ - Page width not correctly reset when defining default page margins (L/R) by @page [4.3.007C]
1711
+ - Table row <TR> with a background-color, paints the whole row, including the spaces between cells [4.3.005]
1712
+ NB This should have been fixed in [4.2.028] but got left out!
1713
+ - UseSubstitutionsMB causes errors inside <textarea> and <select> so now disabled in these 2 situations [4.3.004]
1714
+ - CSS background: 'none' did not cancel background-image/background-color if it comes later [4.3.002, 4.3.011]
1715
+ - Warning message 'depracated' (as of PHP 5.3) when using Templates [4.3.007]
1716
+ - AutoFont incorrectly altering multibyte characters ending in \xa0 [4.3.012C]
1717
+ - "Initial" default value for border-width changed from 1px to 'medium' e.g. border-top: solid #000000; [4.3.010]
1718
+ - WMF image sometimes inverted [4.3.016]
1719
+
1720
+ Updated Files
1721
+ -------------
1722
+ mpdf.php
1723
+ config.php
1724
+ changelog.txt
1725
+
1726
+
1727
+ New files
1728
+ ---------
1729
+ classes/svg.php
1730
+
1731
+
1732
+ New config variables
1733
+ --------------------
1734
+ $this->justifyB4br=false;
1735
+ $this->CSSselectMedia='print';
1736
+ $this->watermarkImgBehind = false;
1737
+
1738
+ BACKWARD COMPATIBILITY
1739
+ ----------------------
1740
+ All changes are backwards compatible except the handling of some background-images - please see notes below.
1741
+
1742
+
1743
+ Watermark Image z-order
1744
+ -----------------------
1745
+ By default mPDF prints watermarks on top of the page contents to ensure that they are not hidden by backgrounds
1746
+ (especially table cells).
1747
+ You can specify watermark images to be printed behind page contents by setting a configurable variable:
1748
+ $this->watermarkImgBehind = true; // default=false
1749
+ [4.3.018]
1750
+
1751
+
1752
+ Rotating Images and Graphs
1753
+ --------------------------
1754
+ Images or graphs can be rotated (by multiples of 90 degrees) using a custom HTML attribute e.g.
1755
+ <img rotate="90|-90|180" ... />
1756
+ <jpgraph rotate="90" ... />
1757
+ Valid options are: 90|-90|180.
1758
+ Positive values are clockwise.
1759
+ If width is specified e.g. width="3cm" this is applied to the rotated image i.e. will be width 3cm after rotating
1760
+ [4.3.016]
1761
+
1762
+
1763
+ Background Image Opacity
1764
+ ------------------------
1765
+ A custom CSS property "background-image-opacity": is now supported on BODY, DIV+ (block elements) and TD
1766
+ Takes values between 0 and 1.0
1767
+
1768
+
1769
+ Resizing Background Images
1770
+ --------------------------
1771
+ A custom CSS property "background-image-resize": is now supported on BODY, DIV+ (block elements) and TD
1772
+ 0 - No resizing (default)
1773
+ 1 - Shrink-to-fit w (keep aspect ratio)
1774
+ 2 - Shrink-to-fit h (keep aspect ratio)
1775
+ 3 - Shrink-to-fit w and/or h (keep aspect ratio)
1776
+ 4 - Resize-to-fit w (keep aspect ratio)
1777
+ 5 - Resize-to-fit h (keep aspect ratio)
1778
+ 6 - Resize-to-fit w and h
1779
+
1780
+ N.B. Prior to v4.4 background-images were incorrectly constrained to maximum width of the containing block.
1781
+ The default is now to do NO resizing on background-images. Setting "background-image-resize:3" should be used
1782
+ for backwards compatibility.
1783
+ [4.3.015, 4.3.012D]
1784
+
1785
+
1786
+ SVG Image files
1787
+ ---------------
1788
+ SVG image files are now partially supported (but as for WMF - not as background-images).
1789
+ viewBox (preserveAspectRatio is not supported) viewBox="0 0 400 200" width="400" height="200"
1790
+ Takes viewBox in preference to width/height if present on <svg>
1791
+ If neither present, will size to width of page (square) as the containing box.
1792
+ Units are interpreted as pixels if undefined.
1793
+ Doesn't recognise internal CSS <style> elements
1794
+ Gradients only take 2 colours which are taken as stop-offset 0% and 100%
1795
+ [4.3.013 & 4.3.017]
1796
+
1797
+
1798
+ Reduced Memory Usage printing Tables
1799
+ ------------------------------------
1800
+ mPDF uses a lot of memory when processing large tables. Parts of the script have been rewritten to
1801
+ reduce memory consumption when writing tables which use collapsed borders (10-25% saving).
1802
+
1803
+ Memory usage can be reduced further by setting a configurable variable:
1804
+ $this->packTableData = true; // default=false
1805
+ but note that this causes a significant increase in processing time.
1806
+ [4.3.008, 4.3.019, 4.3.014]
1807
+
1808
+
1809
+
1810
+ User-defined path to Temporary folder
1811
+ -------------------------------------
1812
+ mPDF uses a folder to write and store temporary files when processing images. By default this is the
1813
+ [your_path_to_mpdf]/tmp/
1814
+ This is now user-definable by defining the constant _MPDF_TEMP_PATH before including mpdf.php script.
1815
+
1816
+
1817
+ Text Justification
1818
+ ------------------
1819
+ In a justified text block, an inline image, textarea, input, or select causing a new line will now force
1820
+ the previous line to be justified. HR and BR do NOT force justification (as in browsers).
1821
+ For optional compliance of MS Word behaviour, there is a new configurable variable:
1822
+ $this->justifyB4br = false; // Change to true to force justification before a <BR> (as in MS Word)
1823
+ [4.3.003]
1824
+
1825
+
1826
+ CSS support for @media
1827
+ ----------------------
1828
+ Now supports media-dependent CSS styles e.g.
1829
+ @media print {
1830
+ p { color: red; }
1831
+ }
1832
+ as well as
1833
+ <style media="...">...</style> and
1834
+ <link rel="stylesheet" media="print" href="..." />
1835
+ Proper matching of CSS media to select using configurable variable:
1836
+ $this->CSSselectMedia='print'; // default="print" set in config.php : screen, print, or any other CSS @media type (not "all")
1837
+ N.B. $this->disablePrintCSS in now depracated
1838
+ [4.3.001]
1839
+
1840
+
1841
+
1842
+
1843
+ ===========================
1844
+ mPDF v4.3 (28/02/2010)
1845
+ ===========================
1846
+
1847
+ NEW FEATURES
1848
+ ------------
1849
+ - Page (sheet) size can be reset within document (http://mpdf1.com/manual/index.php?tid=436) [4.2.024, 4.2.025]
1850
+ - PDF/A1-b compliant files (http://mpdf1.com/manual/index.php?tid=420)
1851
+ - Improve performance using simpleTables (http://mpdf1.com/manual/index.php?tid=430)
1852
+ - mPDFI incorporated into main mPDF class (http://mpdf1.com/manual/index.php?tid=432)
1853
+ - <dottab> added as custom HTML tag: inserts dots to the following text, which is right-aligned [4.2.031]
1854
+
1855
+ See Example files 38 and 39 for PDFA compliant file and <dottab>
1856
+
1857
+ BACKWARD COMPATIBILITY
1858
+ ----------------------
1859
+ All changes are backwards compatible except the use of mPDFI. You will need to make minor changes to your scripts.
1860
+ See the manual http://mpdf1.com/manual/index.php?tid=432 for details.
1861
+
1862
+ BUG FIXES
1863
+ ---------
1864
+ - When using Table of Contents and not resetting page numbers: HTML headers/footers showed incorrect page number [4.2.020]
1865
+ - Table of Contents: last page not printing page background-color [4.2.023]
1866
+ - Image file with space " " in the file name failing [4.2.016]
1867
+ - Image file path unnecessarily resolved to full URI - changed to use relative path if possible [4.2.029] ***
1868
+ - Table - not calculating height of cell correctly [4.2.015, 4.2.012, 4.2.011, 4.2.009]
1869
+ - Table row breaking after/during cell when image in cell taller than font-height [4.2.008]
1870
+ - When Table row(cell) greater height than the page-height but requiring resizing greater than allowed by autosize - not resizing [4.2.005]
1871
+ - Table cell border not resized correctly [4.2.002]
1872
+ - Table row <TR> with a background-color, paints the whole row, including the spaces between cells [4.2.028] ****
1873
+ - Background-image in HTMLFooter not correctly setting 0,0 origin [4.2.014]
1874
+ - Background-image set as an in-line style not working [4.2.013]
1875
+ - Background-image set in CSS @page or <body> was being constrained to less than page size [4.2.032]
1876
+ - Imported Templates overwriting Headers (with images or gradients) [4.2.004]
1877
+ - When using imports/templates, HTML header with background-image causing page to disappear [4.2.001]
1878
+ - block-style element breaking over more than 2 pages incorrectly adjusting L/R margins [4.2.022]
1879
+ - CSS @page property "size" set on :left :right or :first pseudo-selectors - disabled [4.2.022]
1880
+ - Annotations default colour incorrectly set in PDF as [100 100 0] corrected to [1 1 0] (seemed to work ok?) [4.2.026]
1881
+ - Overwrite() now parses input file more tolerantly recognising more source files [4.2.030]
1882
+
1883
+ **** Bug fix 4.2.028 never got into the release of v4.3 Included in next release [4.3.005]
1884
+ **** Bug fix 4.2.029 never not fully implmented in v4.3 Included in next release [4.3.012]
1885
+
1886
+ Changed files
1887
+ -------------
1888
+ mpdf.php
1889
+ compress.php
1890
+ config.php
1891
+ classes/t1asm.php
1892
+ includes/functions.php
1893
+ mpdfi/fpdi_pdf_parser.php
1894
+ Added files/folder: /mpdfi/filters/*.*
1895
+ Added file/folder: /iccprofiles/sRGB_IEC61966-2-1.icc
1896
+ mpdfi/mpdfi.php (no longer required)
1897
+
1898
+ New Configuration variables
1899
+ ---------------------------
1900
+ [config.php]
1901
+ $this->enableImports
1902
+ $this->simpleTables
1903
+ $this->PDFA
1904
+ $this->ICCProfile
1905
+ $this->PDFAauto
1906
+
1907
+
1908
+ Minor changes
1909
+ -------------
1910
+ Increased PDF file compatibility with spec 1.4
1911
+ - PDF version changed to 1.4
1912
+ - A binary file marker (a comment line with 4 characters > 127 ASCII) is added just after the first line
1913
+ - %%EOF no longer has line break after it [4.2.010]
1914
+ - /ID object is added to trailer object when not encrypted [4.2.010]
1915
+
1916
+ When using progress bars, one of the JS scripts is now referenced as an external file
1917
+ to allow it to be cached by user's browser and improve performance for end-user [4.2.007]
1918
+
1919
+ Importing external PDF files: LZW encoded PDF files are now supported
1920
+
1921
+ When adding an annotation, the popup window can be set be either open or closed when the document is opened [4.2.027]
1922
+ - size and position of the popup can also be specified
1923
+
1924
+
1925
+
1926
+ ===========================
1927
+ mPDF v4.2 (27/01/2010)
1928
+ ===========================
1929
+
1930
+ NEW FEATURES
1931
+ ------------
1932
+ - image handling improved
1933
+ - table layout - additional control over resizing
1934
+ - vertical-alignment of images - better support for all CSS types
1935
+ - top and bottom margins collapse between block elements
1936
+ - improved support for CSS line-height
1937
+ - display progress bar whilst generating file
1938
+ - CSS @page selector can be specified when adding a pagebreak
1939
+ - CSS @page selector allows different margins, backgrounds, headers/footers on :first :left and :right pages
1940
+ - PNG images with alpha channel fully supported
1941
+ - ability to generate italic and bold font variants from base font file
1942
+ - CJK fonts to embed as subsets
1943
+ - "double" border on block elements
1944
+ - character substitution for missing characters in UTF-8 fonts
1945
+ - direct passing of dynamically produced image data
1946
+ - background-gradient and background-image can now co-exist
1947
+
1948
+
1949
+
1950
+ Bug fixes
1951
+ ---------
1952
+ - empty variable (undefined var, false, null, array() etc.) sent to WriteHTML produced error message "Invalid UTF-8"
1953
+ - CJK in tables when not using CJK (utf-8-s) autosized very small as characters did not word-wrap
1954
+ - parsing stylesheets: background image not recognised if containbed uppercase characters in file name
1955
+ - "double" border on table used white between the lines instead of current background colour
1956
+ - $this->shrink_tables_to_fit = 0 or false caused fatal errors
1957
+ - background color or images not printing correctly when breaking across pages
1958
+ - background not printed for List inside a block element
1959
+ - columns starting near end of page with no room for a line triggering column change (resulting in text misplaced) not page break
1960
+ - table cell not calculating cell height correctly when "orphan" characters (;:,.?! etc.) at end of line
1961
+ - table breaking page in column 2 when col 1 is rowspan'ned
1962
+ - margin-collapse at top of page not working if bookmark/annotation/indexentry/toc
1963
+ - column break triggered by HR triggering a second column break
1964
+ - an empty 'position:fixed' element with no/auto width or height caused fatal error
1965
+ - mPDFI: template documents were overwriting HTML headers
1966
+ - mPDFI: function Overwrite (to change text in existing PDF) - fatal error if using with encrypted file
1967
+
1968
+ Bug - not fixed
1969
+ - WriteHTML('',2) with '2' parameter not recognising 'margin-collapse:collapse' for DIVs or 'line-height' set in default CSS 'BODY'
1970
+
1971
+
1972
+
1973
+ New or Updated Files
1974
+ --------------------
1975
+ mpdf.php
1976
+ compress.php
1977
+ config.php
1978
+ config_cp.php
1979
+ config_fonts.php
1980
+ mpdf.css
1981
+ classes/gif.php
1982
+ classes/indic.php
1983
+ includes/subs_core.php
1984
+ mpdfi/mpdfi.php
1985
+ unifont/ar_k_001.uni2gn.php
1986
+ All files in new folder: /progress/*.*
1987
+
1988
+ NEW FOLDER /tmp/ required with read/write permissions - used for temporary image files or progress bars
1989
+
1990
+
1991
+
1992
+
1993
+ ===========================
1994
+ mPDF v4.1.1 (21/12/2009)
1995
+ ===========================
1996
+ Error corrected in /makefont/makefonts.php file (moved completed Unicode files to font folder instead of unifont)
1997
+
1998
+ ===========================
1999
+ mPDF v4.1 (20/12/2009)
2000
+ ===========================
2001
+ MySQL support for embedded font subsets abandoned, and replaced with file-based.
2002
+
2003
+
2004
+ Files no longer required
2005
+ ------------------------
2006
+ config_db.php
2007
+ /unifont/RUNME.php
2008
+ /unifont/*.ufm and /unifont/*.t1a font files
2009
+
2010
+ MySQL Database no longer required
2011
+
2012
+ Files Updated
2013
+ -------------
2014
+ mpdf.php
2015
+ /classes/t1asm.php
2016
+ /makefont/makefonts.php
2017
+
2018
+ New files
2019
+ ---------
2020
+ /unifont/*.dat and /unifont/*.dat.php font files
2021
+
2022
+
2023
+ Bug-fixes
2024
+ ---------
2025
+ - Image - If automatically resizing to fit maximum page size incorrectly subtracted margin-header
2026
+ - Annotation and textarea in same HTML chunk causes mPDF to crash (preg_replace textarea with /u modifier in AdjustHTML)
2027
+ - set_magic_quotes_runtime error ($mgr not $mqr)
2028
+ - Table align did not reverse when using RTL document
2029
+
2030
+ Alteration: Image - if writing Image in fixedpos div position:absolute - to allow Image to be resized to full page size
2031
+
2032
+
2033
+ ===========================
2034
+ mPDF v4.0 (17/12/2009)
2035
+ ===========================
2036
+
2037
+ Major additions
2038
+ ---------------
2039
+ - Ability to embed font subsets (creating much smaller files)
2040
+ - Much improved support for Arabic languages
2041
+ - Support for Indic languages including consonant conjuncts
2042
+ - Support for Fixed position block elements
2043
+ - New utility to help create your own fonts
2044
+ - PNG alpha channel transparency supported
2045
+ - New utility to create smaller mpdf script with reduced functionality (less memory)
2046
+ - Multiple Barcode types supported
2047
+
2048
+ **********************************************************************************************
2049
+ * For more details see the documentation manual: http://mpdf1.com/manual/index.php?tid=410 *
2050
+ **********************************************************************************************
2051
+
2052
+ Bug fixes (parsing CSS)
2053
+ -----------------------
2054
+ - <link href="" ... was not recognised if > 1 space between words
2055
+ - #Content p em { font-style:italic; } was applied to "#Content p"
2056
+ - @import url() embedded in a stylesheet file requires path fixed relative to stylesheet file
2057
+ - background-image url() embedded in a stylesheet file requires path fixed relative to stylesheet file
2058
+ - comment tags inside CSS <style> embedded in the HTML were removed
2059
+ Now fixed so <style><!-- ... --></style> works; <!-- <style>...</style> --> is removed
2060
+
2061
+ Bug fixes (other)
2062
+ -----------------
2063
+ - clear (CSS property for floating elements) caused properties for that element to reset to defaults
2064
+ - width: auto caused collapse of border and padding on L & R of ordinary block elements
2065
+ - text-indent not inherited correctly (including em and % values)
2066
+ - named colour "steelblue" corrected RRGGBB hex code
2067
+ - table cell widths in %: if width of table cells set to >=100%, and not all columns are set
2068
+ This was fixed in 3.2 but led to problem where 2 cols: 1) 80% and 2) not set (see Table sizing test)
2069
+ Now fixed again to work for both(?)
2070
+ - parse PNG error fixed
2071
+ - bachground-image not correctly positioned in HTMLFooter and HTMLHeader (Not fixed properly in 3.2!)
2072
+ - fonts not supported with 0-9 in the name
2073
+ - font list in GetCodepage() in htmltoolkit.php (now config_cp.php) containing space " " not recognised
2074
+ - list number positioning
2075
+ - list font size set in CSS for UL/OL not working for first level list
2076
+ - table width (real value, not %) not working in nested table
2077
+ - GIF file failed if PDF file not compressed
2078
+ - list-style-type incorrectly inherited
2079
+ - line-height inheritance in lists
2080
+ - SetColumns added a new line - not required if at start of document/page
2081
+ - footer_line_spacing did not work
2082
+ - table cellPadding="" overwrote cell padding set on cell CSS
2083
+ - could not turn off Default non-HTML foter LINE
2084
+ - border specified as "em"
2085
+ - default values set in mpdf.css overriden by inherited properties e.g. <div><h1>Here</h1></div> lost font-size for H1
2086
+
2087
+
2088
+
2089
+ ===========================
2090
+ mPDF v3.2 (25/10/2009)
2091
+ ===========================
2092
+ Bug fixes
2093
+ ---------
2094
+ - Table cell widths in %: if width of table cells set to >=100%, and not all columns are set -> froze, because tries to produce a column of no width
2095
+ - Ouput download file changed to allow compatability with IE6 (http://mpdf.bpm1.com/forum/comments.php?DiscussionID=120&page=1#Item_4)
2096
+ - Image error if relative path used on domain root (e.g. img src="image.png" and basepath is http://www.yourdomain.com) [attempted fix in 3.1 not working]
2097
+ - Table: if font changed in cell, font was not retoring properly afterwards causing errors (restoreInlineProperties())
2098
+ - Lists: list items containing <br />, font not restoring after bullet
2099
+ - Graceful support for block elements inside list items e.g. <li><p>... (not supported, but tolerated)
2100
+ - Index: Created dividing letters separately for Uppercase and lowercase
2101
+ - Incorrectly changing input character set when encountering e.g. charset=iso-8859-1 in the text of the document
2102
+ - Changed so only detects it if within <head>...</head>
2103
+ - If Keep-with-table (i.e. H1-6 before table and use_kwt true), if pagebreak forced anyway, borders did not print on previous page
2104
+ - Background-image used in HTML footer not appearing (correctly)
2105
+ - RTL tables: nested tables will not automatically transpose L->R
2106
+ - "Keep heading with table" - changed to allow <h1 style=".."> not just <h1>
2107
+ - "Keep heading with table" - backgrounds (bgcolor, image or gradient) incorrectly handled - now removed
2108
+ - Rotated table spread over more than 1 page caused enclosing block background colours to be be rotated along with table
2109
+ - CSS text-indent % now correctly suported (% of containing block width)
2110
+ - CSS width em on a block element e.g. DIV now correctly suported
2111
+ - calculating _tableheight, if remainingpage==0, get error (div by zero)
2112
+ - Table moved to next page with page-break-inside=avoid, produced an enlarged table (font)
2113
+ - RTL text-align override on BODY text was not working consistently
2114
+ - Arab characters: Character &#x647; (HEH) appearing in Final presentation form instead of Isolated
2115
+ - Vertical position of background-image on whole page incorrect
2116
+ - SetProtection can now be used with no permissions set (was not working unless at least one permission set)
2117
+
2118
+
2119
+ Developers
2120
+ ----------
2121
+ Some more undefined indexes and variables declared (courtesy of DSmart http://mpdf.bpm1.com/forum/comments.php?DiscussionID=117&page=1#Item_0 )
2122
+ Comment lines removed for < v3.0 to tidy up code
2123
+
2124
+
2125
+ Enhancements
2126
+ ------------
2127
+ CSS style height now partially supported on block elements DIV, P, H1 etc. --IF--
2128
+ - block is all on one page
2129
+ - will extend the block but not shorten it
2130
+ - will not force a pagebreak (max. at bottom of page)
2131
+ - % is interpreted as % of printable page height (inside margins)
2132
+ <TFOOT> now supported (placed at start as in HTML spec) displays at end of table, and repeats as a footer
2133
+ Background-image and background-gradient now supported in TD and TH (works in all cases except: background-image is not rotated or
2134
+ positioned correctly if table is rotated)
2135
+ NB Background images and background-gradients do not work if Columns are being used, or if $use_kwt is TRUE (keep-with-table),
2136
+ or if page-break-inside:avoid is active.
2137
+
2138
+
2139
+ Updated files
2140
+ -------------
2141
+ mpdf.php
2142
+ htmltoolkit.php
2143
+
2144
+
2145
+
2146
+
2147
+ ===========================
2148
+ mPDF v3.1 (30/08/2009)
2149
+ ===========================
2150
+
2151
+ Bug fixes
2152
+ ---------
2153
+ - Image error if relative path used on domain root (e.g. img src="image.png" and basepath is http://www.yourdomain.com
2154
+ was giving http://www.yourdomain.com//image.png) [3.1]
2155
+ - Errors in parsing background CSS (background-repeat, background-position etc) [3.1]
2156
+ - Textarea did not corectly convert width or height in units relating to font e.g. em [3.0beta_01]
2157
+ - If page margin-bottom set to zero, SetHTMLfooter() crashes with "Division by zero" error [3.0beta_01]
2158
+ - Table with header row and rowspan in tbody, not calculating maxrowheightcorrectly
2159
+ - Prevent Index breaking column just after a dividing letter
2160
+ - Select or input form field when text around it is justified had text in the form field justified
2161
+ - TocBookMarkText needs to be htmlspecialchar-ed - decoded when entered inside <tocpagebreak>
2162
+ - <img src="" /> caused crash
2163
+ - DisplayPreferences used as a variable name and a function: function renamed to SetDisplayPreferences()
2164
+ - Image with src file not including a "." incorrectly parsed (e.g. http://www.domain.com/imagegenerator?params=23)
2165
+
2166
+ New Features
2167
+ ------------
2168
+ - var $debug (true|false) default false; show or hide error reporting at output stage [3.1]
2169
+ - var $autoPageBreak (true|false) default true; allows overriding of automatic page breaks [3.0beta_02]
2170
+ - <indexinsert /> HTML equivalent of CreateIndex() [was CreateReference()]
2171
+ - 2nd attribute/parameter "xref" in IndexEntry() and <indexentry> - works like IndexEntrySee() as cross-reference entry
2172
+ - function SetWatermarkText allows null parameters to be passed i.e. SetWatermarkText() - will clear the WatermarkText
2173
+ - <watermarktext content="" alpha="" /> - HTML equivalent of SetWatermarkText()
2174
+ - <watermarkimage src="" alpha="" position="" size="" /> - HTML equivalent of SetWatermarkImage()
2175
+
2176
+ Documentation
2177
+ -------------
2178
+ See Manual at http://mpdf.bpm1.com/manual/ for more information - especially:
2179
+ - User's Guide>>What Else Can I Do?>>Backgrounds & Borders
2180
+ - User's Guide>>What Else Can I Do?>>Floating blocks
2181
+
2182
+ Files updated:
2183
+ -------------
2184
+ mpdf.php
2185
+ htmltoolkit.php
2186
+ graph.php
2187
+
2188
+
2189
+ Developers only
2190
+ ---------------
2191
+ mPDF<=3.1 generated a large number of warning "Notices" if run with full eror_reporting on, due to array indexes not being initiated e.g.
2192
+ $arr = array();
2193
+ ...
2194
+ if ($arr['index'] == 5 ) {...}
2195
+
2196
+ To prevent this, lines were added at the start of the mpdf.php script to turn error notices OFF.
2197
+ In a move towards making mPDF able to run with full error_reporting on, a large amount of the script has been altered
2198
+ e.g. the line above would be changed to:
2199
+ if (isset($arr['index'] && $arr['index'] == 5 ) {...}
2200
+
2201
+ Although I have tested this with a number of examples, it is almost certainly not complete. Therefore the error_reporting for Notices is still turned
2202
+ off in mPDF 3.1
2203
+ If you care to test it, please uncomment line 43 (//error_reporting(E_ALL);) and report any warning notices that you get.
2204
+ NB This has added about 40kB to the script size.
2205
+
2206
+
2207
+
2208
+ ===========================
2209
+ mPDF v3.0beta (14/06/2009)
2210
+ ===========================
2211
+
2212
+
2213
+ New Features
2214
+ ------------
2215
+ - CSS "float" partially supported (as well as clear:left|right|both)
2216
+ - CSS "background-image" "background-position" "background-repeat" "background-color" "background" supported for block-level elements
2217
+ - CSS background-color and background-image for <body > element added: this covers the whole page i.e. not just inside the "margins"
2218
+ - CSS background-color and background-image can be defined for CSS @page{}
2219
+ - Background gradients (linear or radial) can be defined using a custom CSS style property
2220
+ - Border radius can be defined to give rounded edges to block elements (uses draft CSS3 spec.)
2221
+ - page number can be reset to any value during the document (in AddPage() <pagebreak> etc.)
2222
+ - PNG images: Interlaced and alpha-channel-set PNG images now supported
2223
+ - internal links supported in Indexes (parameter added to CreateIndex()/CreateReference(): $useLinking=true;)
2224
+ - HTML Headers and footers now support hyperlinks
2225
+ - improved handling of <br>, block elements, and text lines inside table - approximates better to browser handling
2226
+ - borders of block-level elements & table cell borders supported (partially) in columns
2227
+ - optional error reporting for problems with Images ($showImageErrors)
2228
+ - ToC will word-wrap long entries
2229
+ - internal links (Bookmarks, IndexEntry and ToCEntry) rewritten to give more accurate positioning (when used as <tag>)
2230
+ - autofont algorithm improved for CJK languages
2231
+ - define text before and after page numbers ($pagenumPrefix; $pagenumSuffix; $nbpgPrefix; $nbpgSuffix;)
2232
+ - Additional color names supported - full list from SVG1.0
2233
+
2234
+ Bug fixes
2235
+ ---------
2236
+ - Column width not resetting after an automatic pagebreak, or after setting HTMLheader
2237
+ - using AutoFont unnecssarily changed htmlspecialchars to code causing errors
2238
+ - Lists inside a table - incorrectly calculating table cell height
2239
+ - CJK - 4-byte utf-8 chars not displaying properly (includes HKCS characters)
2240
+ - mailto: links incorrectly handled
2241
+ - TOCpagebreak() - usePaging default clarified: true unless specified as '', 0, '0' or false; (null ->true)
2242
+ - <tocpagebreak> (as html tag) with no "name" defined, used at start of page, added a further blank page(s)
2243
+ - Lists - inaccurate calculation of space required for numbers in certain circumstances
2244
+ - Generated images (.php) only working if cURL enabled - (fixed, but rquires allow_url_fopen if remote file)
2245
+ - flag added to turn off error reporting when buffering used ($allow_output_buffering = false;)
2246
+ - RTL text in Bookmark, Title, Author, Creator, Keywords, and Subject was reversed - Adobe Reader 9 now correctly handles RTL text ( which Reader 8 did not)
2247
+ - TOC - if not using ODD/EVEN paging, did not add extra page and messed up
2248
+ - Rotated table which did not fit on remaining page resized to bigger than default
2249
+ - HR of width less than 100% - text continued on line after it
2250
+ - HR alignment not working (fixed so both CSS text-align and margin: 0 0 0 auto etc work)
2251
+ - HR in table did not correctly re-size when necessary
2252
+ - characters in symbols/zapfdingbats which in non-utf-8 mode are represented as chr(173) incorrectly handled as soft-hyphens
2253
+ (bug introduced 2.5 with soft-hyphens - affects symbols &#8593; arrow-up and Zapfdingbats &#9313; encircled 2)
2254
+ - Internal links (anchors) - Annotation/Bookmarks etc. incorrectly positioned when page orientation changed
2255
+ - ToC - when using multiple ToCs, internal links were not correctly adjusted
2256
+ - anchor (a name="") used inside a table was incorrectly positioned at the end of table
2257
+ - Tables: cell height calculated incorrectly when BR used
2258
+ - Table rotated with "page-break-inside:avoid" not kept on one page
2259
+ - Table rotated and split over > 1 page - vertical alignment inaccurate
2260
+ - Headers/Footers (non_html) when no style set caused errors
2261
+ - Table: breaking page when using rowspan error (line 17142)
2262
+ - ToC: If no indent defined in HTML tag <tocpagebreak> or defined as 0 gave error
2263
+
2264
+ Note
2265
+ ----
2266
+ In mPDF 3.0 the following sections of code have been significantly rewritten:
2267
+ - painting of borders and background colours for block-elements
2268
+ - table of contents
2269
+ - Index
2270
+ - vertical justification in columns (uses scaling to stretch vertically)
2271
+
2272
+ NB changed htmltoolkit AdjustHTML - does not now remove <br> before </div>
2273
+ Warning - may display differently in normal text as well as tables
2274
+
2275
+
2276
+ Files updated:
2277
+ -------------
2278
+ mpdf.php
2279
+ htmltoolkit.php
2280
+
2281
+
2282
+ Developers only
2283
+ ---------------
2284
+ - Background-color handling in CSS changed so only inherited/cascaded when Columns active or Keep-block-together
2285
+ - otherwise would overwrite background image with inherited color
2286
+ - all %.2f used in sprintf() changed to %.3f in htmltoolkit.php and mpdf.php to increase accuracy of div border lines in columns etc.
2287
+ - variable $use_embeddedfonts_1252 renamed to $useOnlyCoreFonts as more precise: depracated but still supported.
2288
+ - this version included quite abit of tidying up/future-proofing some code:
2289
+ $var{0} changed to substr($var,0,1) etc. (due to go in PHP6)
2290
+ ereg_ changed to preg_ (depracated in PHP5.3) - (NB mainly in htmltoolkit.php)
2291
+
2292
+
2293
+
2294
+ ===========================
2295
+ mPDF v2.5 (01/05/2009)
2296
+ ===========================
2297
+
2298
+ New Features
2299
+ ------------
2300
+ - Automatic Hyphenation added, and support for soft-hyphens
2301
+ - Encryption works now for CJK language documents
2302
+ - Improved text justification
2303
+ - Support for 'generated' images e.g. "../ontheflyimage.php"
2304
+
2305
+
2306
+ Bug fixes
2307
+ ---------
2308
+ - Tables: cell height did not reduce if font-size used was smaller than table default
2309
+ - Columns: if setcolumns() to the same number already active - did not print out last bit of previous columns
2310
+ - Page-break in the middle of a block caused incorrect margin and padding on next lines until end of block ($cMargin reset to 0 in AddPage)
2311
+ - <HR> in table cell was printing in incorrect position (bug introduced in mPDF 2.4)
2312
+ - Justification
2313
+ - if only one word on line, did not respect maximum character spacing
2314
+ - last character of line incorrectly had character spacing applied
2315
+ - Space at the end of last line of a Right Justify block - e.g. "end. </p>" now correctly ignored
2316
+ - &nbsp; incorrectly treated as a character when justifying text with word/char spacing
2317
+ - CJK punctuation (.,) added as 'orphans' to keep at end of line
2318
+ - PNG files - was still buggy reading larger PNG files (due to fread)
2319
+
2320
+
2321
+ Files updated:
2322
+ -------------
2323
+ mpdf.php
2324
+ htmltoolkit.php
2325
+ CJKdata.php
2326
+ /patterns/.. (new files)
2327
+
2328
+
2329
+ Developers only
2330
+ ---------------
2331
+ Variables renamed as more accurate or appropriate:
2332
+ - var $isunicode renamed as $is_MB
2333
+ - var $usingembeddedfonts renamed as $usingCoreFont
2334
+ CJK changed to act internally as UTF-8 encoded
2335
+ - (NB CJK Half-widths not supported from 2.5+ i.e. big5-hw gb-hw)
2336
+
2337
+
2338
+
2339
+ ===========================
2340
+ mPDF v2.4 (23/04/2009)
2341
+ ===========================
2342
+ Files updated
2343
+ -------------
2344
+ mpdf.php
2345
+ htmltoolkit.php
2346
+ mpdfi/mpdfi.php
2347
+
2348
+ New files
2349
+ ---------
2350
+ graph.php
2351
+ Graphs - Requires new folder: path_to_mpdf/graph_cache/ (must be writeable)
2352
+
2353
+ New features
2354
+ ------------
2355
+ Annotations improved so they appear as a pop-up
2356
+ Re-use Document Templates (cf. RestartDocTemplate() in manual)
2357
+ Limited support for CSS float property on an IMG element allowing text wrapping e.g. <img style="float: right;"> (cf. Images in manual)
2358
+ Utility function PreparePreText() allows output of a text file which may include <pre>
2359
+ Automatic generation of graphs from data in tables (requires integration with JPGraph) (cf. Graphs in manual)
2360
+
2361
+ Other Changes
2362
+ -------------
2363
+ IMPORTANT - User rights removed as not working with newer version of Adobe Reader 9 (affects Active forms and ability for users to modify annotations)
2364
+ Corrects text alignment when using {nb} or {nbpg} in (non-HTML) headers/footers
2365
+ Sets default timezone if not already set (at top of mpdf.php) to prevent E_STRICT ERROR message
2366
+ Suppresses E_NOTICE error reporting (at top of mpdf.php)
2367
+ Error capture in Output() to avoid PDF header being sent when error messages generated
2368
+ A function str_ireplace added to htmltoolkit to allow PHP4 to function
2369
+
2370
+ Bug fixes
2371
+ ---------
2372
+ WMF images incorrectly positioned when in-line
2373
+ PNG images > 8kB failed to load - (fix in 2.3 didn't work - fixed properly this time)
2374
+ Annotations containing a new line (\n) causing an error
2375
+ Evaluation of <pre> text: "<code>[TAB] " evaluated incorrect number of spaces to follow to align tabs, because < was calculated as 4 chars (&lt;)
2376
+
2377
+
2378
+
2379
+ ===========================
2380
+ mPDF v2.3 (22/03/2009)
2381
+ ===========================
2382
+
2383
+ New Features
2384
+ ------------
2385
+ - Optionally detect language and when to use special fonts i.e. RTL (arabic), CJK (chinese), Thai (see SetAutoFont() etc.)
2386
+ - Supports HTML attribute "lang" in all tags and uses special fonts when required (see $useLang)
2387
+ - Joins Arabic and Farsi/Persian text into presentation forms
2388
+ - Import another PDF file and use as templates in your document (see UseTemplate() and mPDFI in the manual.)
2389
+ - Replace specified text strings in an existing PDF file (see OverWrite() etc.)
2390
+ - More than one Table of Contents can be used in a document (see tocpagebreak etc.)
2391
+ - Restore properties of open HTML block elements after a page break (variable $restoreBlockPagebreaks or new tag <formfeed>)
2392
+ - <annotation> <bookmark> <indexentry> <tocentry> can now accept characters <>'"& as htmlentities - htmlspecialchars(..., ENT_QUOTES)
2393
+ - <annotation> can now accept "\n" for new line
2394
+ - support for opacity (CSS3 property) for images
2395
+ - specify the number of spaces to substitute for TAB when parsing <pre> tags
2396
+ - greater control over margins and display when changing page orientation during document (see $forcePortraitMargins and $displayDefaultOrientation)
2397
+
2398
+
2399
+
2400
+ Bug fixes
2401
+ ---------
2402
+ Fonts in CSS - Not parsing font-family: Trebuchet MS; correctly as trebuchet
2403
+ Fonts in CSS - CSS font-family: [unknown]; setting first $available_unifont rather than ignoring
2404
+ Images - not displaying on IIS platform
2405
+ Images - .wmf not displaying if (allow_url_fopen) not set
2406
+ Table borders - in defaultCSS, 'MARGIN-COLLAPSE'=> collapase not quoted therefore not working
2407
+ Line-break inside table - printing a blank background across page rather than just going down a line
2408
+ Form fields inside tables - will now resize if the table is autosized (shrunk)
2409
+ <pre> containing a '<' was changed to '&lt;'
2410
+ Tabs inside <pre> were all changed to 8 spaces, not the remainder following a string
2411
+ Header on first page was inset by 1mm left and right ($cMarginL and $cMarginR not set to zero)
2412
+ Table nested inside a cell with colspan > 1 was incorrectly handled
2413
+ PNG file crashed (?incorrectly defined PNG file) [adapted _parsepng to account for unexpected]
2414
+ Table or Cell - if font-size not recognised, mPDF set font-size to zero
2415
+ Font-sizes - [xx-small|x-small|small|medium|large|x-large|xx-large] were not recognised in tables
2416
+
2417
+
2418
+ ===========================
2419
+ mPDF v2.2.1 (17/02/2009)
2420
+ ===========================
2421
+ Bug fix - (bug introduced in 2.2)
2422
+ Table - header row did not return to top of page when repeating across pages.
2423
+
2424
+
2425
+ ===========================
2426
+ mPDF v2.2 (15/02/2009)
2427
+ ===========================
2428
+ Updated files from mPDF 2.1
2429
+ mpdf.php
2430
+ htmltoolkit.php
2431
+ mpdf.css (new)
2432
+ ===========================
2433
+ New files from mPDF <2.0 (only required for EAN Barcodes)
2434
+ font/ocrb.xx (several)
2435
+ unifont/ocrb.xx (several)
2436
+ IMPORTANT - you need to make sure the ocrb font is added to the config.php file
2437
+ - add 'ocrb' to the end of 3 arrays: $this->available_fonts $this->available_unifonts and $this->mono_fonts
2438
+ ===========================
2439
+
2440
+ Summary of changes
2441
+ - external stylesheet file (mpdf.css) is used to configure default values ($useDefaultCSS2 and $defaultCSS2 are no longer used)
2442
+ - special comment tags to hide mPDF tags from browsers: <!--mpdf ... mpdf-->
2443
+ - AddColumn() function added (equivalent to <columnbreak>)
2444
+ - annotations - pop-up messages the reader can move or delete (if you set permissions)
2445
+ - support for WMF images as well as GIF, JPG, PNG
2446
+ - watermark image can be set instead of, or as well as text
2447
+ - nested tables can include other content
2448
+ - improved control over table layout
2449
+ - margin: auto now supported for table and block elements
2450
+
2451
+ A number of methods and variables have been renamed or reCapitalised for consistency.
2452
+ Changes should be backwards comaptible.
2453
+ All user methods start with a Capital, all user-defined variables start with lowercase.
2454
+ Affected:
2455
+ Reference() -> IndexEntry()
2456
+ CreateReference() -> CreateIndex()
2457
+ $TopicIsUnvalidated -> $showWatermark
2458
+ setUnvalidatedText() -> SetWatermarkText()
2459
+
2460
+ PHP appears at present to be case-insensitive for function/method names
2461
+ All the following functions have been renamed in the script with a capital first letter:
2462
+ setUserRights()
2463
+ setBasePath()
2464
+ setAnchor2Bookmark()
2465
+ setHeader()
2466
+ setFooter()
2467
+ defHeaderByName()
2468
+ defFooterByName()
2469
+ setHeaderByName()
2470
+ setFooterByName()
2471
+ setHTMLHeader()
2472
+ setHTMLFooter()
2473
+ defHTMLHeaderByName()
2474
+ defHTMLFooterByName()
2475
+ setHTMLHeaderByName()
2476
+ setHTMLFooterByName()
2477
+ shaded_box()
2478
+ writeBarcode()
2479
+
2480
+ Variable names changed to lowercase first letter:
2481
+ (Variables are case-sensitive therefore aliases have been set up)
2482
+ Anchor2Bookmark
2483
+ BiDirectional
2484
+ KeepColumns
2485
+ AliasNbPg
2486
+ AliasNbPgGp
2487
+
2488
+ =========
2489
+ Bug fixes
2490
+ =========
2491
+ Columns - $keepColumns=true was incorrectly calculating the place to continue printing after 1 and half columns (of 3)
2492
+ Table cell height - incorrectly setting table cell height when cell contained a line of text of large size which wrapped to more than one line
2493
+ HR in Table cell - if table cell contains only HR (and column otherwise empty), HR was printed outside cell
2494
+ HR in Table cell - if table cell ended with a HR, height was one line too much
2495
+ Table page-break-inside:avoid - caused mPDF into permanent loop in some circumstances
2496
+ Paging - Total Pages/Group {nb} and {nbgp} didn't work in CJK
2497
+ CSS - Border size thin, medium and thick were only recognised in lowercase
2498
+ Table-header - rowspan not correctly output in THEAD
2499
+ Default CSS - table empty-cell:hide changed to show (CSS specification)
2500
+
2501
+ ===========================
2502
+ mPDF v2.1 (24/01/2009)
2503
+ ===========================
2504
+
2505
+ New Features in Version 2.1
2506
+ ---------------------------
2507
+ - CSS support improved generally (especially for cascading CSS, lists)
2508
+ - TableHeader changed to allow multiple rows in THEAD
2509
+
2510
+
2511
+ CSS changes
2512
+ -----------
2513
+ - display: none (block elements only - not lists or tables, nor HR)
2514
+ - width (TD/TH)
2515
+ - list-style-type (will also recognise the list-style-type from list-style) (OL/UL)
2516
+ recognised values: disc|circle|square|decimal|lower-roman|upper-roman|lower-latin|upper-latin|lower-alpha|upper-alpha|none
2517
+ - CSS support for <LI>: font-family, font-size, font-style, font-weight, color, background-color, text-decoration, text-transform, and list-style-type (will also recognise the list-style-type from list-style)
2518
+ - table cell borders - CSS rules have been adapted slightly - if a coloured/black line conflicts with a white line, and is the same width, coloured/black will overwrite even if Bottom or Right
2519
+
2520
+
2521
+ Numbered Lists
2522
+ --------------
2523
+ Variables set at the top of mpdf.php can be set to change:
2524
+ - text alignment of numbers in numbered lists (default Right)
2525
+ var $list_align_style = 'R';
2526
+ - content to follow a numbered list marker e.g. '.' gives 1. or IV. whereas ')' gives 1) or a)
2527
+ var $list_number_suffix = '.';
2528
+ (These can be altered at run time, but are not changeable through stylesheets or in-line style)
2529
+
2530
+
2531
+ Writing broken segments of HTML
2532
+ -------------------------------
2533
+ 2 new parameters have been added to WriteHTML()
2534
+ function WriteHTML($html,$sub=0,$init=true,$close=true) {
2535
+ $close - Leaves buffers/variables etc. in current state, so that it can continue to write the HTML where it leaves off
2536
+ $init - Clears and resets buffers/variables
2537
+ (N.B. You must end with a WriteHTML that calls $close=true)
2538
+ Example:
2539
+ $mpdf->WriteHTML('<p>This is the beginning...', 2, true, false);
2540
+ $mpdf->WriteHTML('...this is the middle...', 2, false, false);
2541
+ $mpdf->WriteHTML('...and this is the end</p>', 2, false, true);
2542
+
2543
+
2544
+ Rotated text in table cells
2545
+ ---------------------------
2546
+ NB This UPDATE will change expected output from previous versions******
2547
+
2548
+ Prior to v2.1 any cell set to rotate text anticlockwise was forced to vertical align = bottom.
2549
+ This has been changed so that it only overrides when the rotate angle is between 45 and 89 degrees: text rotated exactly 90 degrees will respect the set value for vertical-align.
2550
+
2551
+
2552
+ =========
2553
+ Bug fixes
2554
+ =========
2555
+ - List - list starting after "<div>Then some text not in a block element<ol>" incorrectly output
2556
+ - Tables - if cell font-size set smaller than default for the table, does not shrink the cell height
2557
+ - Columns (tables) - columns breaking across rows e.g. in the middle of a table cell
2558
+ - Tables - if table width set to e.g. 100% but cols are less, was not making up to set width
2559
+ - Watermark - was not printing if using HTMLFooter
2560
+ - Lists - not aligning numbering correctly if different font sizes used for bullet & text etc.
2561
+ - Lists - indent of text did not correctly allow for Maximum number in <ol> list
2562
+ - Table does not always move correctly to a new page
2563
+ - Table cell incorrectly calculated height causing text to overflow cell when printed
2564
+ - Table borders in columns not being correctly handled (bug since 2.0 introduced a buffer to save the borders and print at the end of the table - fixed so does not use buffer if in columns - potentially does not deal with conflicting borders as well, but works in columns)
2565
+ - Table cell width if set as a percent was being downsized when autosizing table
2566
+ - Table CSS was buggy - improved
2567
+ - SetBasePath (when fetching remote website) - now handles string with query string on it e.g. http://www.domain.com/index.php?tid=42
2568
+ - Table cells with Rotated text - text not positioned correctly
2569
+ - Page number totals not working in utf-8 mode
2570
+
2571
+
2572
+ ============================
2573
+ Code efficiency improvements
2574
+ ============================
2575
+ - BIG speed improvement (compared with 2.0) with tables (especially large tables)
2576
+ - considerable increase in speed if writing long HTML segments to mPDF
2577
+ - speed improvement for tables (may be very significant if some cells have a lot of text in them causing uneven column widths)
2578
+
2579
+ NB To speed up program more, consider setting $mpdf->useSubstitutions=false; if you do not use any characters outside the codepage selected
2580
+
2581
+
2582
+ ===============
2583
+ Keep-with-table
2584
+ ===============
2585
+ (This was introduced in v2.0 but I forgot to document it)
2586
+ If you set $this->use_kwt = true;
2587
+ All H1-H6 elements will try to keep with a table that follows immediately afterwards - (this is done in htmltoolkit, by adding an attribute KEEP-WITH-TABLE)
2588
+ See Known Issues re: Using kwt inside a div with border/background (doesn't work)
2589
+
2590
+
2591
+
2592
+
2593
+ ===========================
2594
+ mPDF v2.0 (07/12/2008)
2595
+ ===========================
2596
+ Main New Features in Version 2.0
2597
+ - nested tables are supported
2598
+ - supports both models of table border: separate and collapsed
2599
+ - improved parsing of CSS stylesheets, and better handling of styles throughout
2600
+ - additional recognised CSS styles
2601
+ - page orientation, size, and margins can be changed within the document, using PHP script or custom HTML
2602
+ - some limited support for @page CSS to define page-box areas, with crop/cross marks for printing
2603
+ - improved control over headers and footers (including HTML headers/footers)
2604
+ - improved presentation of Form elements including image-type input fields
2605
+ - generates an EAN barcode suitable for a book/printed publication
2606
+ - active forms can be generated - EXPERIMENTAL at present
2607
+ - change document permissions to allow the user to make annotations - EXPERIMENTAL at present
2608
+
2609
+ NB Lines are commented in mPDF script as changes for mPDF 1.4 - this became v2.0
2610
+
2611
+ =========
2612
+ UPGRADING
2613
+ =========
2614
+ IMPORTANT - Before Upgrading: Please note that some of the changes will cause mPDF 2.0 to render the pages differently from earlier versions i.e. it is not totally backwards comaptible. Read the notes on Backward compatibility before deleting your original set-up.
2615
+
2616
+ To upgrade from v<=1.3 to v2.0 you only need to copy and overwrite the following 2 files:
2617
+ mpdf.php
2618
+ htmltoolkit.php
2619
+
2620
+ Plus (optionally) if you want to use the EAN Barcode function, you will also need:
2621
+ font/ocrb.xx (several)
2622
+ unifont/ocrb.xx (several)
2623
+ IMPORTANT - you need to make sure the ocrb font is added to the config.php file
2624
+ - add 'ocrb' to the end of 3 arrays: $this->available_fonts $this->available_unifonts and $this->mono_fonts
2625
+
2626
+
2627
+ ==========
2628
+ Bug Fixes
2629
+ ==========
2630
+ <columns column-count="0"> did not turn off columns - Fixed
2631
+
2632
+ Margins as % - e.g. margin-right: 50% set from CSS incorrectly applied 50% of the fontsize
2633
+ (Fixed - adding parameter to fn. ConvertSize in htmltoolkit.php and in calls to that function)
2634
+
2635
+ DIV Width - e.g. div style="width: 50% was not working
2636
+ (Fixed - fn.SetCSS and OpenTag()'DIV')
2637
+
2638
+ CSS values as Zero - p { margin: 0; } did not work in stylesheet unless 0 had a unit
2639
+
2640
+ Multiple Non-breaking spaces collapsed - e.g. "1&nbsp; &nbsp; &nbsp;2" - was contracted to "1 2"
2641
+ (Fixed - fn.adjustHTML in htmltoolkit.php)
2642
+
2643
+ Table cell too narrow causing incorrect printing - If two characters are too wide to print (only likely within a table cf. example tables - Periodic table) the first character was not printed, just a new line
2644
+ (Fixed in fn.WriteFlowingBlock)
2645
+
2646
+ Font size by inline style for form elements <input> <textarea> gave wrong size when using a relative size 0.9em
2647
+ (Fixed - fn.ConvertSize in htmltoolkit.php)
2648
+
2649
+ Creation Date not correctly showing
2650
+ (Fixed - did not need to convert to UTF16)
2651
+
2652
+ New block element started at end of page - block borders not painted
2653
+ (Fixed - fn.AddPage)
2654
+
2655
+ DL did not close block correctly
2656
+ (Fixed - mistype in fn. CloseTag)
2657
+
2658
+ Transparent not recognised as color/background-color
2659
+ (Attempted a fix by setting to ignore it! - fn. convertcolor in htmltoolkit.php)
2660
+
2661
+ Zero (0) not displaying if only thing in table cell or tags e.g. <td>0</td> <p>0</p>
2662
+ (Fixed - fn.WriteHTML)
2663
+
2664
+ Page Headers/Footers - Simple Headers or Footers defined as e.g. '|{PAGENO}|' were not split into 3 components, but output |6| in the outer margin.
2665
+ (Fixed)
2666
+
2667
+ Could not copy from a completed PDF doc to clipboard when using a TrueTypeUnicode font
2668
+ (Fixed - fn._puttruetypeunicode - added CIDToGIDMap)
2669
+
2670
+ Creating an Index (confusing called CreateReference in mPDF) based on only 1 column (i.e. columns off) caused it to print FAIL
2671
+ (Fixed - fn. CreateReference())
2672
+
2673
+ Table of Contents - If a ToC entry reached other side of page a warning notice was produced
2674
+ Fixed - printing is now suppressed and it is moved down a line (but not when using rtl)
2675
+
2676
+ "Keep Block Together" (i.e. page-break-inside: avoid for a block element)
2677
+ If this property causes some text to be moved to the next page, internal link targets (i.e. <a name="xxx">) were incremented pagenumber by +1 - as this used the calculated document page number, didn't work if using e.g. roman numerals
2678
+ (Fixed)
2679
+ NB This is now ALWAYS disabled when it meets a table - can use page-break-inside:avoid for the table
2680
+
2681
+ @import url(style.css) without quotation marks "" was not picked up, although it is valid HTML
2682
+ (Fixed - fn.ReadCSS())
2683
+
2684
+ Reading CSS from external style sheets included all media
2685
+ Now set by default to ignore media="aural|braille"
2686
+ Allows media="print" but can exclude by: $mpdf->disablePrintCSS = true; (default = false)
2687
+ Works on both <link... and <style media="print">@import...
2688
+ See the web page example - this stops the CSS stylesheets specifically marked for "print" to be ignored
2689
+
2690
+ Table borders (in collapsed model) incorrectly calculated which border had dominance (mPDF <=1.3 determined the overriding border by its color)
2691
+ (Fixed to follow CSS 2.1 specifications: width >> CSS dominance (cell>table) >> T & L > B & R)
2692
+ In the border-collapse=collapse mode, the following rules determine which border style "wins" in case of a conflict:
2693
+ 1. Borders with the 'border-style' of 'hidden' take precedence over all other conflicting borders.
2694
+ 2. narrow borders are discarded in favor of wider ones.
2695
+ 3. styles are preferred in this order: 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and the lowest: 'inset'.
2696
+ 4. If border styles differ only in color, then a style set on a cell wins over one on a table.
2697
+ 5. When two elements of the same type conflict, then the one further to the left or top wins out.
2698
+
2699
+ Parsing CSS, a missed level would not be picked up i.e. CSS = div.refstr1 p {...} would not pick up:
2700
+ <div class="refstr1"> <div class="another"> <p>...
2701
+ (Fixed - fn. MergeCSS by carrying everything forwards)
2702
+ Note: I removed - && !$this->blk[$this->blklvl-1]['cascadeCSS']['CLASS>>'.$attr['CLASS']]['depth']
2703
+ Not sure why I put it there in the first place!
2704
+ In a later bit of function - && $this->blk[$this->blklvl-1]['cascadeCSS'][$tag]['depth']>1
2705
+ Haven't removed this, but is it needed???
2706
+
2707
+ CSS inline style set in TD/TH (font-size, color, weight, font-family or italic) didn't turn off at the end of the cell (and also formatted the top left cell)
2708
+ (Fixed)
2709
+
2710
+ CSS properties color, font-weight, and font-style set on a table were not inherited by the table cells
2711
+ (Fixed - var $base_table_properties)
2712
+
2713
+ When rotating a table, the text following was positioned incorrectly
2714
+ (Fixed - fn. printtablebuffer)
2715
+
2716
+ When rotating a table, links were not adjusted in position e.g. <a href="">...
2717
+ (Fixed - fn. printtablebuffer)
2718
+
2719
+ If a larger border-thickness was set for a cell in the middle of a table, cells before that inaccurately calculated the cell wdith needed
2720
+ (Fixed)
2721
+
2722
+ Text in a table cell which was not in a block and followed a list, there was no line break e.g. </ol>Text following</td>
2723
+ (Fixed - var $listjustfinished;)
2724
+
2725
+ Setting the default font-family from the body tag using in-line CSS did not work e.g. <body style="font-family:mono"> (did work in external stylesheets)
2726
+ (Fixed - fn.WriteHTML)
2727
+
2728
+ <link href="..." rel="stylesheet"> was not recognised (because the href comes before the rel)
2729
+ (Fixed)
2730
+
2731
+ Read linked CSS stylesheet OR @import stylesheet - now includes both.
2732
+
2733
+ <tag class="class1 class2"> did not set either class1 or class2. Fixed so that it will now pick out class1 (better than nothing!)
2734
+
2735
+ CSS line-height as % - interpreted 120% as 120 (x the font-size) - Fixed so it now accepts % and numbers
2736
+
2737
+ Setting the basepath (used for relative links/external stylesheets etc) with $mpdf->setBasePath() was generally buggy!
2738
+ Now allows a domain e.g. $mpdf->setBasePath("http://www.domain.com"); (previously needed slash on end)
2739
+ (Fixed - hopefully!)
2740
+
2741
+ If you were repeatedly calling mPDF in a loop to produce more than one PDF file, it would crash with error: "You have restricted the number of available fonts to 0". Fixed by editing line 751 require(_MPDF_PATH.'mpdf_config.php'); to require(...
2742
+
2743
+
2744
+ =============
2745
+ Improvements(?)
2746
+ =============
2747
+ Unsupported image files - mPDF died with an error message if image files didn't meet expected format e.g. an interlaced PNG file
2748
+ Changed so images are now replaced by the NOIMG image.
2749
+
2750
+ Footer margin (HTML and normal footers) now determines the lowest point that is printed (rather than the place to start printing the footer)
2751
+ NB IMPORTANT CHANGE - not backwards comaptible
2752
+
2753
+ Tabs in <pre> or <textarea> are now replaced by 8 spaces rather than 6 (consistent with http://www.w3.org/TR/1998/REC-html40-19980424/struct/text.html#edef-PRE) [fn. AdjustHTML() in htmltoolkit.php]
2754
+
2755
+ To insert the total number of pages in the document anywhere in the doc, just use '{nb}'
2756
+ The line: $mpdf->AliasNbPages();
2757
+ has now been uncommented allowing {nb} to be used
2758
+ NB This will always give the total no. of pages in the whole document regardless of any changes you have made to page numbering.
2759
+ You can change the default placeholder '{nb}' to any string using: $mpdf->AliasNbPages('[**my Chars**]');
2760
+
2761
+ $mpdf->AliasNbPageGroups(); default="{nbpg}"
2762
+ Can be used to set the total number of pages in the current group i.e. between where page numbering is reset
2763
+
2764
+ CSS border correctly fixes "solid 3mm #000000" i.e. (style width color) - (not a bug, but this is often incorrectly specified)
2765
+
2766
+ Can now print div background behind a rotated table.
2767
+
2768
+ You can keep columns as they are i.e. 1st column will finish page then start on second, by setting
2769
+ $mpdf->KeepColumns = true;
2770
+
2771
+ Image constrain
2772
+ ===============
2773
+ Image size is constrained to current margins and page position. Extra parameter added to end of fn. allows you to override this.
2774
+ $mpdf->Image('files/images/frontcover.jpg',0,0,210,297,'jpg','',true, false); // e.g. the last "false" allows a full page picture
2775
+ Useful for e.g. a cover page for your document
2776
+
2777
+ Cumulative CSS
2778
+ ==============
2779
+ In version <=1.3, if you call:
2780
+ $mpdf->WriteHTML($stylesheet,1);
2781
+ $mpdf->WriteHTML($html); // this one cleared the array $this->cascadeCSS; conatining cascaded CSS information from stylesheets
2782
+ You were meant to call:
2783
+ $mpdf->WriteHTML($html,2); // which doesn't re-parse the CSS information
2784
+ v2.0 changed so that
2785
+ $mpdf->WriteHTML($html); no longers clears the array $this->cascadeCSS and so can be used repeatedly;
2786
+
2787
+
2788
+
2789
+ ================================================
2790
+ Additional CSSstyles & HTML attributes supported
2791
+ ================================================
2792
+ <BODY> - font-style, font-weight, color
2793
+
2794
+ <IMG> - html attributes width="" and height=""
2795
+
2796
+ <TABLE|TD|TH> - border: 'thin' 'medium' and 'thick' are now converted to 1px, 3px and 5px
2797
+ <TABLE|TD|TH> - border now respects all types - e.g. 'double', 'solid', 'dashed', 'dotted', 'ridge', 'outset', 'groove', and 'inset'
2798
+ (NB mPDF only supports a full declaration of border e.g. "border: thin double #000000;")
2799
+
2800
+ <TD|TH> - CSS style="white-space: nowrap" and HTML attribute nowrap="nowrap"
2801
+ <TABLE> - page-break-inside: avoid
2802
+ <TABLE> - border-collapse: separate|collapse
2803
+ <TABLE> - border-spacing: 2px 2px; (horizontal/vertical) or just one figure (both) NB same as cellSpacing
2804
+ <TABLE> - empty-cells: hide|show (border-collapse:separate only)
2805
+ <TABLE> - margin-left and margin-right (previously only supported top and bottom)
2806
+ <TABLE> - padding: (this was incorrectly used for TD/TH before) (border-collapse:separate only)
2807
+ <TD|TH> - padding:
2808
+ <TABLE|TD|TH> - inline style "background" works (with a color only) the same as "background-color"
2809
+
2810
+ NB Table page-break-inside, autosize values and rotate are only respected for that set on first level table of nested tables
2811
+
2812
+ <TABLE> - cellSpacing and cellPadding HTML attributes:
2813
+ NB cellSpacing is the same as CSS style "border-spacing"
2814
+ NB cellPadding is a <table> attribute, but sets the cell padding - not table padding
2815
+
2816
+ <TABLE> - align="..." now works with a rotated table - but sets the alignment ignoring the rotation i.e. align=right sets the table to the right side of the page (looking as though it is bottom-aligned)
2817
+
2818
+ <BLOCK ELEMENTS> - page-break-before: always|left|right - NB any surrounding block tags will be closed before the new page is inserted.
2819
+
2820
+ @page - see notes on Paged Media
2821
+
2822
+ ==========================
2823
+ Unsupported HTML attribute
2824
+ ==========================
2825
+ <TD border="1"> - not valid HTML - no longer supported
2826
+
2827
+
2828
+ =========
2829
+ Additions
2830
+ =========
2831
+ "Keep-with-table"
2832
+ $mpdf->use_kwt = true; // default=false
2833
+ If set to true, will force any H1-H6 header immediately preceding a table to be kept together with the table
2834
+ - automatically sets the table to fit on one page (i.e. page-break-inside=avoid) if it is a rotated table
2835
+ - ignored if: Columns on, Keep-block-together active (page-break-inside=avoid for surrounding BLOCK), active Forms
2836
+
2837
+
2838
+ =====
2839
+ Notes
2840
+ =====
2841
+
2842
+ NB Not a change - but note you can use this to allow you to feed html code encoded in other than utf-8:
2843
+ $mpdf->allow_charset_conversion=true;
2844
+ $mpdf->charset_in='windows-1252'; (needs suitable codes for iconv i.e. windows-1252 not win-1252)
2845
+
2846
+ Fixing Optional tags
2847
+ ====================
2848
+ php.net website has illegal nesting of <dt>.. <dd> .. </dd> .. </dt> and <p>.. <div> .. </div> .. </p>
2849
+ The example wich parses the php.net webpage will not show correctly unless you change: $mpdf->allow_html_optional_endtags=false;
2850
+ Trying to fix incorrect (X)HTML with $mpdf->allow_html_optional_endtags==true cancels the P when it meets a DIV etc.
2851
+
2852
+
2853
+
2854
+ EAN barcode
2855
+ ===========
2856
+ An EAN barcode can be generated
2857
+ function writeBarcode($code, $showisbn=1, $x='', $y='', $size=1, $border=0, $paddingL=1, $paddingR=1, $paddingT=2, $paddingB=2) {
2858
+ It accepts 12 or 13 digits with or without - hyphens as $code e.g.
2859
+ $mpdf->writeBarcode('978-1234-567-890', 1, $mpdf->x, $mpdf->y);
2860
+ NB - IMPORTANT***
2861
+ A new font - OCR-B font/unifont is required, and needs to be added to the config.php file
2862
+ cf. http://www.gs1uk.org/downloads/bar_code/Bar coding getting it right.pdf
2863
+ Barcode size must be between 0.8 and 2.0 (80% to 200%)
2864
+
2865
+ CMYK Colors
2866
+ ===========
2867
+ Functions - SetDrawColor, SetTextColor and SetFillColor all now take an optional 4th parameter.
2868
+ If defined this will interpret the input as CMYK color i.e.
2869
+ SetDrawColor(15,82,0,10) // NB all values out of 100 - not 255 as for RGB
2870
+
2871
+ htmltoolkit.php fn.ConvertColor() - now interprets custom color definition: cmyk(15,82,0,10)
2872
+ like rgb(r,g,b) except values out of 100
2873
+ Intended to be used for calling the functions separately - BUT works in a limited way with CSS - does not get reset or inherited correctly
2874
+ <p style="color:cmyk(215,31,15,10)"> does work
2875
+
2876
+
2877
+ DEFAULT CSS
2878
+ ===========
2879
+ $defaultCSS has been updated to reflect better the standard HTML default e.g. using serif, table borders separate, cell vertical-align top
2880
+ To keep mPDF 1.3 (my favourites) I have introduced:
2881
+ $mpdf->useDefaultCSS2 = true;
2882
+
2883
+
2884
+ ===================================
2885
+ Permissions - forms and Annotations - Experimental!
2886
+ ===================================
2887
+ You can set the Permissions for the PDF file to allow the user to make Comments (annotations)
2888
+ $mpdf->setUserRights($enabled=true[default]|false, $annots="/Create/Delete/Modify/Copy/Import/Export",
2889
+ $form="/Add/Delete/FillIn/Import/Export/SubmitStandalone/SpawnTemplate", $signature="/Modify") )
2890
+
2891
+ If you encrypt the file, make sure the permissions match e.g.:
2892
+ $mpdf->setUserRights();
2893
+ $mpdf->SetProtection(array('print','annots'),'yourPassword','myPassword');
2894
+
2895
+ To allow this, changed the PDF-file version to %PDF1.5 (NB Probably needs PDF version > 1.5 but can't test for this...)
2896
+
2897
+ NOTE: If you output the PDF file straight to the browser, it will only allow annotations after you save the document
2898
+
2899
+
2900
+ ===========================
2901
+ Active Forms - Experimental!
2902
+ ===========================
2903
+ At present , using active forms will prevent any internal and external links - that appear before active forms(?) - from working (why?)
2904
+ May need to save form for proper use - see example, when scroll forwards and back, the form disappears??
2905
+ Need to set Userrights (see above), and $mpdf->useActiveForms=true;
2906
+ For Output options, see separate notes.
2907
+
2908
+
2909
+
2910
+ ============================
2911
+ Internal Programming changes
2912
+ ============================
2913
+ NB fn. tablerotate in htmltoolkit no longer used; now uses a 'transform' to shift the whole block of PDF code
2914
+
2915
+ Graphics State
2916
+ ==============
2917
+ ExtGState does not need to be redefined - e.g. if a watermark added on every page, turning on and off alpha/transparency
2918
+ Unnecessary file size.
2919
+ function AddExtGState() edited to check if graphics state already exists before adding new one
2920
+
2921
+ ASCII-proof code
2922
+ ================
2923
+ "���" used as a special identifier in the program changed to "\xbb\xa4\xac" to make the mpdf.php script file immune from someone saving it as a utf-8 encoded file
2924
+
2925
+ Images
2926
+ ======
2927
+ 1) When copying remote images locally - incorrectly used "unset" now changed to "unlink"
2928
+ 2) When parsing image files - was using CURL for any image src="http://... - even if this was on the local server - edited so it only uses CURL if necessary/appropriate.
2929
+ NB Handling images was updated in v1.3 because my ISP changed allow_url_fopen to false
2930
+ Fixed so mPDF tests if the file is available as a local call e.g. getimage('images/test.jpg') even if it is defined as a full URI e.g. http://www.mydomain.com/images/test.jpg as this is quicker(?), and permitted even if allow_url_fopen is false.
2931
+ If not available as a local file (and allow_url_fopen is set) mPDF tries to use fopen/file_get_contents using an http wrapper;
2932
+ Else, if CURL is available and allow_url_fopen is false: then tries using CURL.
2933
+ (Clear as mud???!!)
2934
+
2935
+
2936
+ ===========================
2937
+ mPDF v1.3 (21/09/2008)
2938
+ ===========================
2939
+ --------------
2940
+ Page Numbering
2941
+ --------------
2942
+ Program changes:
2943
+ fn. startPageNums() replaced with blank function
2944
+ fn. stopPageNums() - deleted
2945
+ fn. numPageNo() - deleted (all it did was return this->page anyway).
2946
+ var $_numbering - deleted
2947
+ var $_numberingFooter - deleted
2948
+ var $_numPageNum - deleted
2949
+
2950
+ NEW
2951
+ New: fn. AddPages() (as for AddPage but with type=NEXT-ODD or NEXT-EVEN see below)
2952
+ Edited: fn. AddPage() - new parameters added
2953
+ AddPage(orientation(NO),type="E|O", resetpagenum="1|0", pagenumstyle="I|i|A|a|1", suppress="on|off")
2954
+ New: fn. docPageNum() - returns the document page number (or '') based on...
2955
+ New : PageNumSubstitutions(array)
2956
+ New attributes:
2957
+ <pagebreak resetpagenum="1" // resets document page numbering to 1 from the new page onwards
2958
+ <pagebreak suppress="on" // turns on suppression of page numbering i.e. in headers and footers, {PAGENO} is replaced by blank string
2959
+ // ="0" turns suppression off
2960
+ <pagebreak pagenumstyle="I|i|A|a|1" // (re)sets page number stle/type from the new page onwards - as for lists
2961
+ // 1 - decimal; A/a - alpha (uppercase/lowercase); I/i - Roman (uppercase/lowercase)
2962
+ <pagebreak type="NEXT-ODD" // always adds a page + another if required to make odd
2963
+ <pagebreak type="NEXT-EVEN" // always adds a page + another if required to make even
2964
+
2965
+ Edited: fn. TOC() // sets the marker for a Table of Contents
2966
+ New parameters allow the page-numbering details to be set
2967
+ NB the page-numbering details set are for the page which follows on after the TOC marker is inserted. The page-numbering for the actual ToC is set later, when the ToC is generated and inserted here
2968
+ new parameters as above for pagebreak resetpagenum="1|0", pagenumstyle="I|i|A|a|1", suppress="on|off"
2969
+
2970
+ Can also be set by attribute in the <TOC>
2971
+ <TOC resetpagenum="1" pagenumstyle="I|i|A|a|1", suppress="on|off" />
2972
+
2973
+ --------------------------------------------
2974
+ Changes to allow Rotated Text in table Cells
2975
+ --------------------------------------------
2976
+ Edited:
2977
+ fn. OpenTag()
2978
+ fn. _tableColumnWidth()
2979
+ fn. _tableHeight()
2980
+ fn. _tableWrite()
2981
+ fn. tableHeader()
2982
+
2983
+ New custom style or attribute -- "text-rotate" -- can be set for either <tr> or <th|td>
2984
+ Allowed values: 45 - 90 (written as integers) - rotates text anticlockwise, and -90 (clockwise)
2985
+ Positive values less than 90 force cell to: vertical-align:bottom
2986
+
2987
+ Limitations:
2988
+ Only allows single line of text;
2989
+ Font, font-size, and style are determined by those set fro the cell, and cannot be changed;
2990
+ No changes in font (or any other in-line changes e.g. <sup>) are supported within the text
2991
+
2992
+ Example: <tr style="text-rotate:90">...
2993
+
2994
+ ---------
2995
+ Bug fixes
2996
+ ---------
2997
+ 1) HTML footer containing table was triggering page break.
2998
+ Added $this->InHTMLFooter as flag to prevent page triggering in footers containing table
2999
+ Set in fn.writeHTMLFooters() -> in fn.tableWrite() stops the pageBreak being reset
3000
+
3001
+ 2) Crashing when libcurl not installed.
3002
+ Edited OpenTag() curl_init - added if (function_exists) to exclude crash when libcurl not installed
3003
+
3004
+ 3) Single cell with borders not showing the borders.
3005
+ e.g. <table><tr><td style="border:1px solid #000000?>Hi</td></tr></table>
3006
+ Problem: mPDF overrides cell border properties with table border properties for external borders. $defaultCSS had CSS defined for table as '0px solid #000000'
3007
+ Quick fix - line 273 removed. A more complete fix will require reprogramming to distinguish between "border property not set" and border property set as "none".
3008
+
3009
+ 4) Empty textarea incorrectly handled (the following HTML code being output in the textarea)
3010
+ The html code for an empty textarea was incorrectly handled in htmltoolkit fn. AdjustHTML which has been edited
3011
+
3012
+
3013
+ ===========================
3014
+ mPDF v1.2 (2008-05-01)
3015
+ ===========================
3016
+ // Added v1.2 option to continue if invalid UTF-8 chars - used in function is_utf8()
3017
+ var $ignore_invalid_utf8 = false;
3018
+
3019
+ Reading CSS in fn. ReadCSS() and applying in fn. MergeCSS() -
3020
+ Edited to allow Tags, class and id with the same name to be distinct i.e. h5 {...} .h5 {...} #h5 {...}
3021
+ * mPDF 1.2 This version supports: .class {...} / #id { .... }
3022
+ * ADDED p {...} h1[-h6] {...} a {...} table {...} thead {...} th {...} td {...} hr {...}
3023
+ * body {...} sets default font and fontsize
3024
+ * It supports some cascaded CSS e.g. div.topic table.type1 td
3025
+ * Does not support non-block level e.g. a#hover { ... }
3026
+
3027
+ Table: font-size, weight, style, family and color should all work
3028
+ TD/TH: font-size, weight, style, family and color should all work
3029
+
3030
+ Added to htmltoolkit - fn.array_merge_recursive_unique()
3031
+
3032
+ memory_opt Removed in mPDF v1.2 - not working properly
3033
+
3034
+ fn. _begindoc() - changed to %PDF1.4 (was 1.3) as PDF version
3035
+
3036
+ Write HTML Headers and Footers
3037
+ ------------------------------
3038
+ fn. Close() - calls writeHTMLHeaders/Footers() before finishing doc
3039
+ fn. WriteHTML() - added parameter
3040
+ fn. _out - writes to outputbuffer when writing HTML footers/headers
3041
+
3042
+ New
3043
+ fn. writeHTMLHeaders()
3044
+ fn. writeHTMLFooters()
3045
+
3046
+
3047
+
3048
+
3049
+ =======================
3050
+ mPDF v1.1 (2008-05-01)
3051
+ =======================
3052
+
3053
+ Programming changes to increase efficiency
3054
+ ------------------------------------------
3055
+ fn. WriteHTML() - added lines to combine substituted characters <tta> etc
3056
+
3057
+ Memory Optimization added (script from FPDF site) - edited fn. _putpages() and fn. _endpage()
3058
+
3059
+ fn. SetFont() edited to return val quicker if font already set (increase efficiency)
3060
+
3061
+ new vars chrs and ords are used to store chr() and ord() - quicker than using functions
3062
+
3063
+ fn.setMBencoding() - only call mb_internal_encoding if need to change
3064
+
3065
+ Bugs
3066
+ ----
3067
+ fn. SetDefaultFontSize() - edited to allow to override that set in defaultCSS
3068
+
3069
+ fn. Output() - Added temporary(?) disablement of encryption in CJK as it doesn't work!
3070
+
3071
+ fn. OpenTag() [LI] $this->blockjustfinished=false to prevents newline after first bullet of list within table
3072
+
3073
+ Uses of mb_ereg_replace removed, and mb_split changed - requires regex_encoding (regex_encoding only used as UTF-8)
3074
+
3075
+ fn. WriteHTML: attributes are trimmed with trim() to allow correct handling of e.g. class="bpmBook "
3076
+
3077
+ fn. printbuffer() and fn. openTag() to ensure
3078
+ <div><div><p> outputs top margins/padding for both 1st and 2nd div
3079
+ and </p></div></div> ...
3080
+
3081
+ fn. SetFont() added line - bug fixing in CJK fonts
3082
+
3083
+ CSS functionality
3084
+ -----------------
3085
+ Added special CSS 'thead-underline' (similar to topntail)
3086
+
3087
+ var $thead_font_weight; added (openTag) to enable setting of font-weight for <TH> cells
3088
+
3089
+ Fixed table border inheritance: Table border inherits border="1" to cells, but not table style="border..."
3090
+
3091
+ "page-break-inside: avoid" added (var keep_block_together) to allow a DIV or P to be kept on one page
3092
+ - not compatible with table autosize or table rotate
3093
+ - only works over maximum of 2 pages
3094
+
3095
+ Enhancements
3096
+ ------------
3097
+ Orphans in line justification: R. Bracket ) added to defined list of orphans
3098
+
3099
+ allow_url_open
3100
+ --------------
3101
+ Following a change in the PHP ini config set on my website by my ISP, changes made to allow mPDF to work with allow_url_open=OFF.
3102
+ - file_get_contents() changed to use libcurl (for CSS files)
3103
+ - openTag('IMG') @fopen() and 3 functions _parsegif, _parseJPG, _parsePNG, edited to copy remote image files to local file to include images
3104
+
3105
+ FlowChart
3106
+ ---------
3107
+ Changes to enable mPDF work with a custom script producing Flowcharts:
3108
+ - WriteHTML() second parameter=3 will allow HTML to be parsed but not output
3109
+ - fn. Arrow() added
3110
+ - TableWordWrap() added parameter to force array return
lib/mpdf/CREDITS.txt ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ /*******************************************************************************
4
+ * Software: FPDF *
5
+ * Version: 1.53 *
6
+ * Date: 2004-12-31 *
7
+ * Author: Olivier PLATHEY *
8
+ * License: Freeware *
9
+ * *
10
+ * You may use and modify this software as you wish. *
11
+ *******************************************************************************/
12
+
13
+ /*******************************************************************************
14
+ * HTML2FPDF is a php script to read a HTML text and generate a PDF file. *
15
+ * Copyright (C) 2004-2005 Renato Coelho *
16
+ * *
17
+ * html2fpdf.php, htmltoolkit.php *
18
+ *******************************************************************************/
19
+
20
+ CREDITS From HTML2FPDF:
21
+
22
+ -Olivier Plathey for the fpdf.php class [http://www.fpdf.org]
23
+ -Damon Kohler for the Flowing Block script [mailto:damonkohler@yahoo.com]
24
+ -Cl�ment Lavoillotte for HTML-oriented FPDF idea
25
+ -Yamasoft for the gif.php class [http://www.yamasoft.com/]
26
+ -J�r�me Fenal for the _parsegif() function
27
+ -"VIETCOM" for the PDFTable code [http://www.freepgs.com/vietcom/tool/pdftable/] [mailto:vncommando@yahoo.com]
28
+ -Yukihiro O. for the SetDash() function [mailto:yukihiro_o@infoseek.jp]
29
+ -Ron Korving for the WordWrap() function
30
+ -Michel Poulain for the DisplayPreferences() function
31
+ -Patrick Benny for the MultiCellBlt() function idea [no longer in use]
32
+ -Seb for the _SetTextRendering() and SetTextOutline() functions [mailto:captainseb@wanadoo.fr]
33
+ -MorphSoft for the colornames list idea
34
+ -W3SCHOOLS for HTML-related reference info [http://www.w3schools.com/]
35
+
36
+
37
+
38
+ /****************************************************************************
39
+ * Software: FPDF_Protection *
40
+ * Version: 1.02 *
41
+ * Date: 2005/05/08 *
42
+ * Author: Klemen VODOPIVEC *
43
+ * License: Freeware *
44
+ * *
45
+ * You may use and modify this software as you wish as stated in original *
46
+ * FPDF package. *
47
+ ****************************************************************************/
48
+
49
+ /****************************************************************************
50
+ // FPDI - Version 1.2
51
+ //
52
+ // Copyright 2004-2007 Setasign - Jan Slabon
53
+ //
54
+ // Licensed under the Apache License, Version 2.0 (the "License");
55
+ // you may not use this file except in compliance with the License.
56
+ // You may obtain a copy of the License at
57
+ //
58
+ // http://www.apache.org/licenses/LICENSE-2.0
59
+ //
60
+ // Unless required by applicable law or agreed to in writing, software
61
+ // distributed under the License is distributed on an "AS IS" BASIS,
62
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
63
+ // See the License for the specific language governing permissions and
64
+ // limitations under the License.
65
+ ****************************************************************************/
66
+
67
+ /****************************************************************************
68
+ * @copyright Khaled Al-Shamaa 2008
69
+ * @link http://www.ar-php.org
70
+ * @author Khaled Al-Shamaa <khaled@ar-php.org>
71
+ * @desc Set of PHP5 / UTF-8 Classes developed to enhance Arabic web
72
+ * applications by providing set of tools includes stem-based searching,
73
+ * translitiration, soundex, Hijri calendar, charset detection and
74
+ * converter, spell numbers, keyboard language, Muslim prayer time,
75
+ * auto-summarization, and more...
76
+ * @package Arabic
77
+ *
78
+ * @version 1.8 released in Feb 15, 2009
79
+ *
80
+ * @license LGPL
81
+ ****************************************************************************/
82
+
83
+
84
+ This library is free software; you can redistribute it and/or
85
+ modify it under the terms of the GNU Lesser General Public
86
+ License as published by the Free Software Foundation;
87
+ This library is distributed in the hope that it will be useful,
88
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
89
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
90
+ Lesser General Public License for more details.
91
+ [http://www.opensource.org/licenses/lgpl-license.php]
92
+
lib/mpdf/LICENSE.txt ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
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
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License
307
+ along with this program; if not, write to the Free Software
308
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
+
310
+
311
+ Also add information on how to contact you by electronic and paper mail.
312
+
313
+ If the program is interactive, make it output a short notice like this
314
+ when it starts in an interactive mode:
315
+
316
+ Gnomovision version 69, Copyright (C) year name of author
317
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
+ This is free software, and you are welcome to redistribute it
319
+ under certain conditions; type `show c' for details.
320
+
321
+ The hypothetical commands `show w' and `show c' should show the appropriate
322
+ parts of the General Public License. Of course, the commands you use may
323
+ be called something other than `show w' and `show c'; they could even be
324
+ mouse-clicks or menu items--whatever suits your program.
325
+
326
+ You should also get your employer (if you work as a programmer) or your
327
+ school, if any, to sign a "copyright disclaimer" for the program, if
328
+ necessary. Here is a sample; alter the names:
329
+
330
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
+
333
+ <signature of Ty Coon>, 1 April 1989
334
+ Ty Coon, President of Vice
335
+
336
+ This General Public License does not permit incorporating your program into
337
+ proprietary programs. If your program is a subroutine library, you may
338
+ consider it more useful to permit linking proprietary applications with the
339
+ library. If this is what you want to do, use the GNU Library General
340
+ Public License instead of this License.
lib/mpdf/README.txt ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Installation
2
+ ============
3
+ * Download the .zip file and unzip it
4
+ * Create a folder e.g. /mpdf on your server
5
+ * Upload all of the files to the server, maintaining the folders as they are
6
+ * Ensure that you have write permissions set (CHMOD 6xx or 7xx) for the following folders:
7
+ /ttfontdata/ - used to cache font data; improves performance a lot
8
+ /tmp/ - used for some images and ProgressBar
9
+ /graph_cache/ - if you are using JpGraph in conjunction with mPDF
10
+
11
+ To test the installation, point your browser to the basic example file : [path_to_mpdf_folder]/mpdf/examples/example01_basic.php
12
+
13
+ If you wish to define a different folder for temporary files rather than /tmp/ see the note on 'Folder for temporary files' in
14
+ the section on Installation & Setup in the manual (http://mpdf1.com/manual/).
15
+
16
+ If you have problems, please read the section on troubleshooting in the manual.
17
+
18
+
19
+ Fonts
20
+ =====
21
+ Let us refer to font names in 2 ways:
22
+ "CSS font-family name" - mPDF is designed primarily to read HTML and CSS. This is the name used in CSS e.g.
23
+ <p style="font-family: 'Trebuchet MS';">
24
+
25
+ "mPDF font-family name" - the name used internally to process fonts. This could be anything you like,
26
+ but by default mPDF will convert CSS font-family names by removing any spaces and changing
27
+ to lowercase. Reading the name above, mPDF will look for a "mPDF font-family name" of
28
+ 'trebuchetms'.
29
+
30
+ The configurable values referred to below are set in the config_fonts.php file
31
+
32
+ When parsing HTML/CSS, mPDF will read the CSS font-family name (e.g. 'Trebuchet MS') and convert
33
+ by removing any spaces and changing to lowercase, to look for a mPDF font-family name (trebuchetms).
34
+
35
+ Next it will look for a translation (if set) in config_font.php e.g.:
36
+ $this->fonttrans = array(
37
+ 'trebuchetms' => 'trebuchet'
38
+ )
39
+
40
+ Now the mPDF font-family name to be used is 'trebuchet'
41
+
42
+ If you wish to make this font available, you need to specify the Truetype .ttf font files for each variant.
43
+ These should be defined in config_font.php in the array:
44
+ $this->fontdata = array(
45
+ "trebuchet" => array(
46
+ 'R' => "trebuc.ttf",
47
+ 'B' => "trebucbd.ttf",
48
+ 'I' => "trebucit.ttf",
49
+ 'BI' => "trebucbi.ttf",
50
+ )
51
+ )
52
+
53
+ This is the array which determines whether a font is available to mPDF. Each font-family must have a
54
+ Regular ['R'] file defined - the others (bold, italic, bold-italic) are optional.
55
+
56
+ mPDF will try to load the font-file. If you have defined _MPDF_SYSTEM_TTFONTS at the top of the
57
+ config_fonts.php file, it will first look for the font-file there. This is useful if you are running
58
+ mPDF on a computer which already has a folder with TTF fonts in (e.g. on Windows)
59
+
60
+ If the font-file is not there, or _MPDF_SYSTEM_TTFONTS is not defined, mPDF will look in the folder
61
+ /[your_path_to_mpdf]/ttfonts/
62
+
63
+ Note that the font-file names are case-sensitive and can contain capitals.
64
+
65
+ If the folder /ttfontdata/ is writeable (CHMOD 644 or 755), mPDF will save files there which it can
66
+ re-use next time it accesses a particular font. This will significantly improve processing time
67
+ and is strongly recommended.
68
+
69
+ mPDF should be able to read most TrueType Unicode font files with a .ttf extension
70
+ Truetype fonts with .otf extension that are OpenType also work OK.
71
+ TrueType collections (.ttc) will also work if they contain TrueType Unicode fonts.
72
+
73
+
74
+ Character substitution
75
+ ----------------------
76
+ Most people will have access to a Pan-Unicode font with most Unicode characters in it such as
77
+ Arial Unicode MS. Set $this->backupSubsFont = array('arialunicodems'); at the top of the config_fonts.php file
78
+ to use this font when substituting any characters not found in the specific font being used.
79
+
80
+ Example:
81
+ You can set $mpdf->useSubstitutions = true; at runtime
82
+ or $this->useSubstitutions = true; in the config.php file
83
+
84
+ <p style="font-family: 'Comic Sans MS'">This text contains a Thai character &#3617; which does not exist
85
+ in the Comic Sans MS font file</p>
86
+
87
+ When useSubstitutions is true, mPDF will try to find substitutions for any missing characters:
88
+ 1) firstly looks if the character is available in the inbuilt Symbols or ZapfDingbats fonts;
89
+ 2) [If defined] looks in each of the the font(s) set by $this->backupSubsFont array
90
+
91
+ NB There is an increase in processing time when using substitutions, and even more so if
92
+ a backupSubsFont is defined.
93
+
94
+ Controlling mPDF mode
95
+ =====================
96
+ The first parameter of new mPDF('') works as follows:
97
+ new mPDF('c') - forces mPDF to only use the built-in [c]ore Adobe fonts (Helvetica, Times etc)
98
+
99
+ new mPDF('') - default - font subsetting behaviour is determined by the configurable variables
100
+ $this->maxTTFFilesize and $this->percentSubset (see below)
101
+ Default values are set so that: 1) very large font files are always subset
102
+ 2) Fonts are embedded as subsets if < 30% of the characters are used
103
+
104
+ new mPDF('..+aCJK') new mPDF('+aCJK')
105
+ new mPDF('..-aCJK') new mPDF('-aCJK')
106
+ - used optionally together with a language or language/country code, +aCJK will force mPDF
107
+ to use the Adobe non-embedded CJK fonts when a passage is marked with e.g. "lang: ja"
108
+ This can be used at runtime to override the value set for $mpdf->useAdobeCJK in config.php
109
+ Use in conjunction with settings in config_cp.php
110
+
111
+ For backwards compatibility, new mPDF('-s') and new mPDF('s') will force subsetting by
112
+ setting $this->percentSubset=100
113
+ new mPDF('utf-8-s') and new mPDF('ar-s') are also recognised
114
+
115
+
116
+
117
+
118
+ Configuration variables changed
119
+ ===============================
120
+ Configuration variables are documented in the on-line manual (http://mpdf1.com/manual/).
121
+
122
+
123
+ Font folders
124
+ ============
125
+ If you wish to define your own font file folders (perhaps to share),
126
+ you can define the 2 constants in your script before including the mpdf.php script e.g.:
127
+
128
+ define('_MPDF_TTFONTPATH','your_path/ttfonts/');
129
+ define('_MPDF_TTFONTDATAPATH','your_path/ttfontdata/'); // should be writeable
130
+
lib/mpdf/classes/barcode.php ADDED
@@ -0,0 +1,1972 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Adapted for mPDF from TCPDF barcode. Original Details left below.
4
+
5
+ //============================================================+
6
+ // File name : barcodes.php
7
+ // Begin : 2008-06-09
8
+ // Last Update : 2009-04-15
9
+ // Version : 1.0.008
10
+ // License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
11
+ // ----------------------------------------------------------------------------
12
+ // Copyright (C) 2008-2009 Nicola Asuni - Tecnick.com S.r.l.
13
+ //
14
+ // This program is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published by
16
+ // the Free Software Foundation, either version 2.1 of the License, or
17
+ // (at your option) any later version.
18
+ //
19
+ // This program is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ // See LICENSE.TXT file for more information.
28
+ // ----------------------------------------------------------------------------
29
+ //
30
+ // Description : PHP class to creates array representations for
31
+ // common 1D barcodes to be used with TCPDF.
32
+ //
33
+ // Author: Nicola Asuni
34
+ //
35
+ // (c) Copyright:
36
+ // Nicola Asuni
37
+ // Tecnick.com S.r.l.
38
+ // Via della Pace, 11
39
+ // 09044 Quartucciu (CA)
40
+ // ITALY
41
+ // www.tecnick.com
42
+ // info@tecnick.com
43
+ //============================================================+
44
+
45
+ class PDFBarcode {
46
+
47
+ protected $barcode_array;
48
+ protected $gapwidth;
49
+ protected $print_ratio;
50
+ protected $daft;
51
+
52
+ public function __construct() {
53
+
54
+ }
55
+
56
+ public function getBarcodeArray($code, $type, $pr='') {
57
+ $this->setBarcode($code, $type, $pr);
58
+ return $this->barcode_array;
59
+ }
60
+ public function getChecksum($code, $type) {
61
+ $this->setBarcode($code, $type);
62
+ if (!$this->barcode_array) { return ''; }
63
+ else { return $this->barcode_array['checkdigit']; }
64
+ }
65
+
66
+ public function setBarcode($code, $type, $pr='') {
67
+ $this->print_ratio = 1;
68
+ switch (strtoupper($type)) {
69
+ case 'ISBN':
70
+ case 'ISSN':
71
+ case 'EAN13': { // EAN 13
72
+ $arrcode = $this->barcode_eanupc($code, 13);
73
+ $arrcode['lightmL'] = 11; // LEFT light margin = x X-dim (http://www.gs1uk.org)
74
+ $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
75
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
76
+ $arrcode['nom-H'] = 25.93; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
77
+ break;
78
+ }
79
+ case 'UPCA': { // UPC-A
80
+ $arrcode = $this->barcode_eanupc($code, 12);
81
+ $arrcode['lightmL'] = 9; // LEFT light margin = x X-dim (http://www.gs1uk.org)
82
+ $arrcode['lightmR'] = 9; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
83
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
84
+ $arrcode['nom-H'] = 25.91; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
85
+ break;
86
+ }
87
+ case 'UPCE': { // UPC-E
88
+ $arrcode = $this->barcode_eanupc($code, 6);
89
+ $arrcode['lightmL'] = 9; // LEFT light margin = x X-dim (http://www.gs1uk.org)
90
+ $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
91
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
92
+ $arrcode['nom-H'] = 25.93; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
93
+ break;
94
+ }
95
+ case 'EAN8': { // EAN 8
96
+ $arrcode = $this->barcode_eanupc($code, 8);
97
+ $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (http://www.gs1uk.org)
98
+ $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (http://www.gs1uk.org)
99
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
100
+ $arrcode['nom-H'] = 21.64; // Nominal bar height in mm incl. numerals (http://www.gs1uk.org)
101
+ break;
102
+ }
103
+ case 'EAN2': { // 2-Digits UPC-Based Extention
104
+ $arrcode = $this->barcode_eanext($code, 2);
105
+ $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (estimated)
106
+ $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (estimated)
107
+ $arrcode['sepM'] = 9; // SEPARATION margin = x X-dim (http://web.archive.org/web/19990501035133/http://www.uc-council.org/d36-d.htm)
108
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
109
+ $arrcode['nom-H'] = 20; // Nominal bar height in mm incl. numerals (estimated) not used when combined
110
+ break;
111
+ }
112
+ case 'EAN5': { // 5-Digits UPC-Based Extention
113
+ $arrcode = $this->barcode_eanext($code, 5);
114
+ $arrcode['lightmL'] = 7; // LEFT light margin = x X-dim (estimated)
115
+ $arrcode['lightmR'] = 7; // RIGHT light margin = x X-dim (estimated)
116
+ $arrcode['sepM'] = 9; // SEPARATION margin = x X-dim (http://web.archive.org/web/19990501035133/http://www.uc-council.org/d36-d.htm)
117
+ $arrcode['nom-X'] = 0.33; // Nominal value for X-dim in mm (http://www.gs1uk.org)
118
+ $arrcode['nom-H'] = 20; // Nominal bar height in mm incl. numerals (estimated) not used when combined
119
+ break;
120
+ }
121
+
122
+ case 'IMB': { // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
123
+ $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
124
+ $bpi = 22; // Bars per inch
125
+ // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
126
+ $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
127
+ $this->daft = array('D'=>2, 'A'=>2, 'F'=>3, 'T'=>1); // Descender; Ascender; Full; Tracker bar heights
128
+ $arrcode = $this->barcode_imb($code);
129
+ $arrcode['nom-X'] = $xdim ;
130
+ $arrcode['nom-H'] = 3.68; // Nominal value for Height of Full bar in mm (spec.)
131
+ // USPS-B-3200 Revision C = 4.623
132
+ // USPS-B-3200 Revision E = 3.68
133
+ $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (spec.)
134
+ $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (spec.)
135
+ $arrcode['quietTB'] = 0.711; // TOP/BOTTOM Quiet margin = mm (spec.)
136
+ break;
137
+ }
138
+ case 'RM4SCC': { // RM4SCC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
139
+ $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
140
+ $bpi = 22; // Bars per inch
141
+ // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
142
+ $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
143
+ $this->daft = array('D'=>5, 'A'=>5, 'F'=>8, 'T'=>2); // Descender; Ascender; Full; Tracker bar heights
144
+ $arrcode = $this->barcode_rm4scc($code, false);
145
+ $arrcode['nom-X'] = $xdim ;
146
+ $arrcode['nom-H'] = 5.0; // Nominal value for Height of Full bar in mm (spec.)
147
+ $arrcode['quietL'] = 2; // LEFT Quiet margin = mm (spec.)
148
+ $arrcode['quietR'] = 2; // RIGHT Quiet margin = mm (spec.)
149
+ $arrcode['quietTB'] = 2; // TOP/BOTTOM Quiet margin = mm (spec?)
150
+ break;
151
+ }
152
+ case 'KIX': { // KIX (Klant index - Customer index)
153
+ $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
154
+ $bpi = 22; // Bars per inch
155
+ // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
156
+ $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
157
+ $this->daft = array('D'=>5, 'A'=>5, 'F'=>8, 'T'=>2); // Descender; Ascender; Full; Tracker bar heights
158
+ $arrcode = $this->barcode_rm4scc($code, true);
159
+ $arrcode['nom-X'] = $xdim ;
160
+ $arrcode['nom-H'] = 5.0; // Nominal value for Height of Full bar in mm (? spec.)
161
+ $arrcode['quietL'] = 2; // LEFT Quiet margin = mm (spec.)
162
+ $arrcode['quietR'] = 2; // RIGHT Quiet margin = mm (spec.)
163
+ $arrcode['quietTB'] = 2; // TOP/BOTTOM Quiet margin = mm (spec.)
164
+ break;
165
+ }
166
+ case 'POSTNET': { // POSTNET
167
+ $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
168
+ $bpi = 22; // Bars per inch
169
+ // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
170
+ $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
171
+ $arrcode = $this->barcode_postnet($code, false);
172
+ $arrcode['nom-X'] = $xdim ;
173
+ $arrcode['nom-H'] = 3.175; // Nominal value for Height of Full bar in mm (spec.)
174
+ $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (?spec.)
175
+ $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (?spec.)
176
+ $arrcode['quietTB'] = 1.016; // TOP/BOTTOM Quiet margin = mm (?spec.)
177
+ break;
178
+ }
179
+ case 'PLANET': { // PLANET
180
+ $xdim = 0.508; // Nominal value for X-dim (bar width) in mm (spec.)
181
+ $bpi = 22; // Bars per inch
182
+ // Ratio of Nominal value for width of spaces in mm / Nominal value for X-dim (bar width) in mm based on bars per inch
183
+ $this->gapwidth = ((25.4/$bpi) - $xdim)/$xdim;
184
+ $arrcode = $this->barcode_postnet($code, true);
185
+ $arrcode['nom-X'] = $xdim ;
186
+ $arrcode['nom-H'] = 3.175; // Nominal value for Height of Full bar in mm (spec.)
187
+ $arrcode['quietL'] = 3.175; // LEFT Quiet margin = mm (?spec.)
188
+ $arrcode['quietR'] = 3.175; // RIGHT Quiet margin = mm (?spec.)
189
+ $arrcode['quietTB'] = 1.016; // TOP/BOTTOM Quiet margin = mm (?spec.)
190
+ break;
191
+ }
192
+
193
+ case 'C93': { // CODE 93 - USS-93
194
+ $arrcode = $this->barcode_code93($code);
195
+ if ($arrcode == false) { break; }
196
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
197
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
198
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
199
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
200
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
201
+ break;
202
+ }
203
+ case 'CODE11': { // CODE 11
204
+ if ($pr > 0) { $this->print_ratio = $pr; }
205
+ else { $this->print_ratio = 3; } // spec: Pr= 1:2.24 - 1:3.5
206
+ $arrcode = $this->barcode_code11($code);
207
+ if ($arrcode == false) { break; }
208
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
209
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
210
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
211
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
212
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
213
+ break;
214
+ }
215
+ case 'MSI': // MSI (Variation of Plessey code)
216
+ case 'MSI+': { // MSI + CHECKSUM (modulo 11)
217
+ if (strtoupper($type)=='MSI') { $arrcode = $this->barcode_msi($code, false); }
218
+ if (strtoupper($type)=='MSI+') { $arrcode = $this->barcode_msi($code, true); }
219
+ if ($arrcode == false) { break; }
220
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
221
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
222
+ $arrcode['lightmL'] = 12; // LEFT light margin = x X-dim (spec.)
223
+ $arrcode['lightmR'] = 12; // RIGHT light margin = x X-dim (spec.)
224
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
225
+ break;
226
+ }
227
+ case 'CODABAR': { // CODABAR
228
+ if ($pr > 0) { $this->print_ratio = $pr; }
229
+ else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
230
+ if (strtoupper($type)=='CODABAR') { $arrcode = $this->barcode_codabar($code); }
231
+ if ($arrcode == false) { break; }
232
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
233
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
234
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
235
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
236
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
237
+ break;
238
+ }
239
+ case 'C128A': // CODE 128 A
240
+ case 'C128B': // CODE 128 B
241
+ case 'C128C': // CODE 128 C
242
+ case 'EAN128A': // EAN 128 A
243
+ case 'EAN128B': // EAN 128 B
244
+ case 'EAN128C': { // EAN 128 C
245
+ if (strtoupper($type)=='C128A') { $arrcode = $this->barcode_c128($code, 'A'); }
246
+ if (strtoupper($type)=='C128B') { $arrcode = $this->barcode_c128($code, 'B'); }
247
+ if (strtoupper($type)=='C128C') { $arrcode = $this->barcode_c128($code, 'C'); }
248
+ if (strtoupper($type)=='EAN128A') { $arrcode = $this->barcode_c128($code, 'A', true); }
249
+ if (strtoupper($type)=='EAN128B') { $arrcode = $this->barcode_c128($code, 'B', true); }
250
+ if (strtoupper($type)=='EAN128C') { $arrcode = $this->barcode_c128($code, 'C', true); }
251
+ if ($arrcode == false) { break; }
252
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
253
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
254
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
255
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
256
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
257
+ break;
258
+ }
259
+ case 'C39': // CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
260
+ case 'C39+': // CODE 39 with checksum
261
+ case 'C39E': // CODE 39 EXTENDED
262
+ case 'C39E+': { // CODE 39 EXTENDED + CHECKSUM
263
+ if ($pr > 0) { $this->print_ratio = $pr; }
264
+ else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
265
+ $code = str_replace(chr(194).chr(160), ' ', $code); // mPDF 5.3.95 (for utf-8 encoded)
266
+ $code = str_replace(chr(160), ' ', $code); // mPDF 5.3.95 (for win-1252)
267
+ if (strtoupper($type)=='C39') { $arrcode = $this->barcode_code39($code, false, false); }
268
+ if (strtoupper($type)=='C39+') { $arrcode = $this->barcode_code39($code, false, true); }
269
+ if (strtoupper($type)=='C39E') { $arrcode = $this->barcode_code39($code, true, false); }
270
+ if (strtoupper($type)=='C39E+') { $arrcode = $this->barcode_code39($code, true, true); }
271
+ if ($arrcode == false) { break; }
272
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
273
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
274
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
275
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
276
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
277
+ break;
278
+ }
279
+ case 'S25': // Standard 2 of 5
280
+ case 'S25+': { // Standard 2 of 5 + CHECKSUM
281
+ if ($pr > 0) { $this->print_ratio = $pr; }
282
+ else { $this->print_ratio = 3; } // spec: Pr=1:3/1:4.5
283
+ if (strtoupper($type)=='S25') { $arrcode = $this->barcode_s25($code, false); }
284
+ if (strtoupper($type)=='S25+') { $arrcode = $this->barcode_s25($code, true); }
285
+ if ($arrcode == false) { break; }
286
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
287
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
288
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
289
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
290
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
291
+ break;
292
+ }
293
+ case 'I25': // Interleaved 2 of 5
294
+ case 'I25+': { // Interleaved 2 of 5 + CHECKSUM
295
+ if ($pr > 0) { $this->print_ratio = $pr; }
296
+ else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
297
+ if (strtoupper($type)=='I25') { $arrcode = $this->barcode_i25($code, false); }
298
+ if (strtoupper($type)=='I25+') { $arrcode = $this->barcode_i25($code, true); }
299
+ if ($arrcode == false) { break; }
300
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
301
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
302
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
303
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
304
+ $arrcode['lightTB'] = 0; // TOP/BOTTOM light margin = x X-dim (non-spec.)
305
+ break;
306
+ }
307
+ case 'I25B': // Interleaved 2 of 5 + Bearer bars
308
+ case 'I25B+': { // Interleaved 2 of 5 + CHECKSUM + Bearer bars
309
+ if ($pr > 0) { $this->print_ratio = $pr; }
310
+ else { $this->print_ratio = 2.5; } // spec: Pr= 1:2 - 1:3 (>2.2 if X<0.50)
311
+ if (strtoupper($type)=='I25B') { $arrcode = $this->barcode_i25($code, false); }
312
+ if (strtoupper($type)=='I25B+') { $arrcode = $this->barcode_i25($code, true); }
313
+ if ($arrcode == false) { break; }
314
+ $arrcode['nom-X'] = 0.381; // Nominal value for X-dim (bar width) in mm (2 X min. spec.)
315
+ $arrcode['nom-H'] = 10; // Nominal value for Height of Full bar in mm (non-spec.)
316
+ $arrcode['lightmL'] = 10; // LEFT light margin = x X-dim (spec.)
317
+ $arrcode['lightmR'] = 10; // RIGHT light margin = x X-dim (spec.)
318
+ $arrcode['lightTB'] = 2; // TOP/BOTTOM light margin = x X-dim (non-spec.) - used for bearer bars
319
+ break;
320
+ }
321
+ default: {
322
+ $this->barcode_array = false;
323
+ }
324
+ }
325
+ $this->barcode_array = $arrcode;
326
+ }
327
+
328
+ /**
329
+ * CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
330
+ */
331
+ protected function barcode_code39($code, $extended=false, $checksum=false) {
332
+ $chr['0'] = '111221211';
333
+ $chr['1'] = '211211112';
334
+ $chr['2'] = '112211112';
335
+ $chr['3'] = '212211111';
336
+ $chr['4'] = '111221112';
337
+ $chr['5'] = '211221111';
338
+ $chr['6'] = '112221111';
339
+ $chr['7'] = '111211212';
340
+ $chr['8'] = '211211211';
341
+ $chr['9'] = '112211211';
342
+ $chr['A'] = '211112112';
343
+ $chr['B'] = '112112112';
344
+ $chr['C'] = '212112111';
345
+ $chr['D'] = '111122112';
346
+ $chr['E'] = '211122111';
347
+ $chr['F'] = '112122111';
348
+ $chr['G'] = '111112212';
349
+ $chr['H'] = '211112211';
350
+ $chr['I'] = '112112211';
351
+ $chr['J'] = '111122211';
352
+ $chr['K'] = '211111122';
353
+ $chr['L'] = '112111122';
354
+ $chr['M'] = '212111121';
355
+ $chr['N'] = '111121122';
356
+ $chr['O'] = '211121121';
357
+ $chr['P'] = '112121121';
358
+ $chr['Q'] = '111111222';
359
+ $chr['R'] = '211111221';
360
+ $chr['S'] = '112111221';
361
+ $chr['T'] = '111121221';
362
+ $chr['U'] = '221111112';
363
+ $chr['V'] = '122111112';
364
+ $chr['W'] = '222111111';
365
+ $chr['X'] = '121121112';
366
+ $chr['Y'] = '221121111';
367
+ $chr['Z'] = '122121111';
368
+ $chr['-'] = '121111212';
369
+ $chr['.'] = '221111211';
370
+ $chr[' '] = '122111211';
371
+ $chr['$'] = '121212111';
372
+ $chr['/'] = '121211121';
373
+ $chr['+'] = '121112121';
374
+ $chr['%'] = '111212121';
375
+ $chr['*'] = '121121211';
376
+
377
+ $code = strtoupper($code);
378
+ $checkdigit = '';
379
+ if ($extended) {
380
+ // extended mode
381
+ $code = $this->encode_code39_ext($code);
382
+ }
383
+ if ($code === false) {
384
+ return false;
385
+ }
386
+ if ($checksum) {
387
+ // checksum
388
+ $checkdigit = $this->checksum_code39($code);
389
+ $code .= $checkdigit ;
390
+ }
391
+ // add start and stop codes
392
+ $code = '*'.$code.'*';
393
+
394
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
395
+ $k = 0;
396
+ $clen = strlen($code);
397
+ for ($i = 0; $i < $clen; ++$i) {
398
+ $char = $code[$i];
399
+ if(!isset($chr[$char])) {
400
+ // invalid character
401
+ return false;
402
+ }
403
+ for ($j = 0; $j < 9; ++$j) {
404
+ if (($j % 2) == 0) {
405
+ $t = true; // bar
406
+ } else {
407
+ $t = false; // space
408
+ }
409
+ $x = $chr[$char][$j];
410
+ if ($x == 2) { $w = $this->print_ratio; }
411
+ else { $w = 1; }
412
+
413
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
414
+ $bararray['maxw'] += $w;
415
+ ++$k;
416
+ }
417
+ $bararray['bcode'][$k] = array('t' => false, 'w' => 1, 'h' => 1, 'p' => 0);
418
+ $bararray['maxw'] += 1;
419
+ ++$k;
420
+ }
421
+ $bararray['checkdigit'] = $checkdigit;
422
+ return $bararray;
423
+ }
424
+
425
+ /**
426
+ * Encode a string to be used for CODE 39 Extended mode.
427
+ */
428
+ protected function encode_code39_ext($code) {
429
+ $encode = array(
430
+ chr(0) => '%U', chr(1) => '$A', chr(2) => '$B', chr(3) => '$C',
431
+ chr(4) => '$D', chr(5) => '$E', chr(6) => '$F', chr(7) => '$G',
432
+ chr(8) => '$H', chr(9) => '$I', chr(10) => '$J', chr(11) => '�K',
433
+ chr(12) => '$L', chr(13) => '$M', chr(14) => '$N', chr(15) => '$O',
434
+ chr(16) => '$P', chr(17) => '$Q', chr(18) => '$R', chr(19) => '$S',
435
+ chr(20) => '$T', chr(21) => '$U', chr(22) => '$V', chr(23) => '$W',
436
+ chr(24) => '$X', chr(25) => '$Y', chr(26) => '$Z', chr(27) => '%A',
437
+ chr(28) => '%B', chr(29) => '%C', chr(30) => '%D', chr(31) => '%E',
438
+ chr(32) => ' ', chr(33) => '/A', chr(34) => '/B', chr(35) => '/C',
439
+ chr(36) => '/D', chr(37) => '/E', chr(38) => '/F', chr(39) => '/G',
440
+ chr(40) => '/H', chr(41) => '/I', chr(42) => '/J', chr(43) => '/K',
441
+ chr(44) => '/L', chr(45) => '-', chr(46) => '.', chr(47) => '/O',
442
+ chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
443
+ chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
444
+ chr(56) => '8', chr(57) => '9', chr(58) => '/Z', chr(59) => '%F',
445
+ chr(60) => '%G', chr(61) => '%H', chr(62) => '%I', chr(63) => '%J',
446
+ chr(64) => '%V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
447
+ chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
448
+ chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
449
+ chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
450
+ chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
451
+ chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
452
+ chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => '%K',
453
+ chr(92) => '%L', chr(93) => '%M', chr(94) => '%N', chr(95) => '%O',
454
+ chr(96) => '%W', chr(97) => '+A', chr(98) => '+B', chr(99) => '+C',
455
+ chr(100) => '+D', chr(101) => '+E', chr(102) => '+F', chr(103) => '+G',
456
+ chr(104) => '+H', chr(105) => '+I', chr(106) => '+J', chr(107) => '+K',
457
+ chr(108) => '+L', chr(109) => '+M', chr(110) => '+N', chr(111) => '+O',
458
+ chr(112) => '+P', chr(113) => '+Q', chr(114) => '+R', chr(115) => '+S',
459
+ chr(116) => '+T', chr(117) => '+U', chr(118) => '+V', chr(119) => '+W',
460
+ chr(120) => '+X', chr(121) => '+Y', chr(122) => '+Z', chr(123) => '%P',
461
+ chr(124) => '%Q', chr(125) => '%R', chr(126) => '%S', chr(127) => '%T');
462
+ $code_ext = '';
463
+ $clen = strlen($code);
464
+ for ($i = 0 ; $i < $clen; ++$i) {
465
+ if (ord($code[$i]) > 127) {
466
+ return false;
467
+ }
468
+ $code_ext .= $encode[$code[$i]];
469
+ }
470
+ return $code_ext;
471
+ }
472
+
473
+ /**
474
+ * Calculate CODE 39 checksum (modulo 43).
475
+ */
476
+ protected function checksum_code39($code) {
477
+ $chars = array(
478
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
479
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
480
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
481
+ 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%');
482
+ $sum = 0;
483
+ $clen = strlen($code);
484
+ for ($i = 0 ; $i < $clen; ++$i) {
485
+ $k = array_keys($chars, $code[$i]);
486
+ $sum += $k[0];
487
+ }
488
+ $j = ($sum % 43);
489
+ return $chars[$j];
490
+ }
491
+
492
+ /**
493
+ * CODE 93 - USS-93
494
+ * Compact code similar to Code 39
495
+ */
496
+ protected function barcode_code93($code) {
497
+ $chr[48] = '131112'; // 0
498
+ $chr[49] = '111213'; // 1
499
+ $chr[50] = '111312'; // 2
500
+ $chr[51] = '111411'; // 3
501
+ $chr[52] = '121113'; // 4
502
+ $chr[53] = '121212'; // 5
503
+ $chr[54] = '121311'; // 6
504
+ $chr[55] = '111114'; // 7
505
+ $chr[56] = '131211'; // 8
506
+ $chr[57] = '141111'; // 9
507
+ $chr[65] = '211113'; // A
508
+ $chr[66] = '211212'; // B
509
+ $chr[67] = '211311'; // C
510
+ $chr[68] = '221112'; // D
511
+ $chr[69] = '221211'; // E
512
+ $chr[70] = '231111'; // F
513
+ $chr[71] = '112113'; // G
514
+ $chr[72] = '112212'; // H
515
+ $chr[73] = '112311'; // I
516
+ $chr[74] = '122112'; // J
517
+ $chr[75] = '132111'; // K
518
+ $chr[76] = '111123'; // L
519
+ $chr[77] = '111222'; // M
520
+ $chr[78] = '111321'; // N
521
+ $chr[79] = '121122'; // O
522
+ $chr[80] = '131121'; // P
523
+ $chr[81] = '212112'; // Q
524
+ $chr[82] = '212211'; // R
525
+ $chr[83] = '211122'; // S
526
+ $chr[84] = '211221'; // T
527
+ $chr[85] = '221121'; // U
528
+ $chr[86] = '222111'; // V
529
+ $chr[87] = '112122'; // W
530
+ $chr[88] = '112221'; // X
531
+ $chr[89] = '122121'; // Y
532
+ $chr[90] = '123111'; // Z
533
+ $chr[45] = '121131'; // -
534
+ $chr[46] = '311112'; // .
535
+ $chr[32] = '311211'; //
536
+ $chr[36] = '321111'; // $
537
+ $chr[47] = '112131'; // /
538
+ $chr[43] = '113121'; // +
539
+ $chr[37] = '211131'; // %
540
+ $chr[128] = '121221'; // ($)
541
+ $chr[129] = '311121'; // (/)
542
+ $chr[130] = '122211'; // (+)
543
+ $chr[131] = '312111'; // (%)
544
+ $chr[42] = '111141'; // start-stop
545
+ $code = strtoupper($code);
546
+ $encode = array(
547
+ chr(0) => chr(131).'U', chr(1) => chr(128).'A', chr(2) => chr(128).'B', chr(3) => chr(128).'C',
548
+ chr(4) => chr(128).'D', chr(5) => chr(128).'E', chr(6) => chr(128).'F', chr(7) => chr(128).'G',
549
+ chr(8) => chr(128).'H', chr(9) => chr(128).'I', chr(10) => chr(128).'J', chr(11) => '�K',
550
+ chr(12) => chr(128).'L', chr(13) => chr(128).'M', chr(14) => chr(128).'N', chr(15) => chr(128).'O',
551
+ chr(16) => chr(128).'P', chr(17) => chr(128).'Q', chr(18) => chr(128).'R', chr(19) => chr(128).'S',
552
+ chr(20) => chr(128).'T', chr(21) => chr(128).'U', chr(22) => chr(128).'V', chr(23) => chr(128).'W',
553
+ chr(24) => chr(128).'X', chr(25) => chr(128).'Y', chr(26) => chr(128).'Z', chr(27) => chr(131).'A',
554
+ chr(28) => chr(131).'B', chr(29) => chr(131).'C', chr(30) => chr(131).'D', chr(31) => chr(131).'E',
555
+ chr(32) => ' ', chr(33) => chr(129).'A', chr(34) => chr(129).'B', chr(35) => chr(129).'C',
556
+ chr(36) => chr(129).'D', chr(37) => chr(129).'E', chr(38) => chr(129).'F', chr(39) => chr(129).'G',
557
+ chr(40) => chr(129).'H', chr(41) => chr(129).'I', chr(42) => chr(129).'J', chr(43) => chr(129).'K',
558
+ chr(44) => chr(129).'L', chr(45) => '-', chr(46) => '.', chr(47) => chr(129).'O',
559
+ chr(48) => '0', chr(49) => '1', chr(50) => '2', chr(51) => '3',
560
+ chr(52) => '4', chr(53) => '5', chr(54) => '6', chr(55) => '7',
561
+ chr(56) => '8', chr(57) => '9', chr(58) => chr(129).'Z', chr(59) => chr(131).'F',
562
+ chr(60) => chr(131).'G', chr(61) => chr(131).'H', chr(62) => chr(131).'I', chr(63) => chr(131).'J',
563
+ chr(64) => chr(131).'V', chr(65) => 'A', chr(66) => 'B', chr(67) => 'C',
564
+ chr(68) => 'D', chr(69) => 'E', chr(70) => 'F', chr(71) => 'G',
565
+ chr(72) => 'H', chr(73) => 'I', chr(74) => 'J', chr(75) => 'K',
566
+ chr(76) => 'L', chr(77) => 'M', chr(78) => 'N', chr(79) => 'O',
567
+ chr(80) => 'P', chr(81) => 'Q', chr(82) => 'R', chr(83) => 'S',
568
+ chr(84) => 'T', chr(85) => 'U', chr(86) => 'V', chr(87) => 'W',
569
+ chr(88) => 'X', chr(89) => 'Y', chr(90) => 'Z', chr(91) => chr(131).'K',
570
+ chr(92) => chr(131).'L', chr(93) => chr(131).'M', chr(94) => chr(131).'N', chr(95) => chr(131).'O',
571
+ chr(96) => chr(131).'W', chr(97) => chr(130).'A', chr(98) => chr(130).'B', chr(99) => chr(130).'C',
572
+ chr(100) => chr(130).'D', chr(101) => chr(130).'E', chr(102) => chr(130).'F', chr(103) => chr(130).'G',
573
+ chr(104) => chr(130).'H', chr(105) => chr(130).'I', chr(106) => chr(130).'J', chr(107) => chr(130).'K',
574
+ chr(108) => chr(130).'L', chr(109) => chr(130).'M', chr(110) => chr(130).'N', chr(111) => chr(130).'O',
575
+ chr(112) => chr(130).'P', chr(113) => chr(130).'Q', chr(114) => chr(130).'R', chr(115) => chr(130).'S',
576
+ chr(116) => chr(130).'T', chr(117) => chr(130).'U', chr(118) => chr(130).'V', chr(119) => chr(130).'W',
577
+ chr(120) => chr(130).'X', chr(121) => chr(130).'Y', chr(122) => chr(130).'Z', chr(123) => chr(131).'P',
578
+ chr(124) => chr(131).'Q', chr(125) => chr(131).'R', chr(126) => chr(131).'S', chr(127) => chr(131).'T');
579
+ $code_ext = '';
580
+ $clen = strlen($code);
581
+ for ($i = 0 ; $i < $clen; ++$i) {
582
+ if (ord($code{$i}) > 127) {
583
+ return false;
584
+ }
585
+ $code_ext .= $encode[$code{$i}];
586
+ }
587
+ // checksum
588
+ $code_ext .= $this->checksum_code93($code_ext);
589
+ // add start and stop codes
590
+ $code = '*'.$code_ext.'*';
591
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
592
+ $k = 0;
593
+ $clen = strlen($code);
594
+ for ($i = 0; $i < $clen; ++$i) {
595
+ $char = ord($code{$i});
596
+ if(!isset($chr[$char])) {
597
+ // invalid character
598
+ return false;
599
+ }
600
+ for ($j = 0; $j < 6; ++$j) {
601
+ if (($j % 2) == 0) {
602
+ $t = true; // bar
603
+ } else {
604
+ $t = false; // space
605
+ }
606
+ $w = $chr[$char]{$j};
607
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
608
+ $bararray['maxw'] += $w;
609
+ ++$k;
610
+ }
611
+ }
612
+ $bararray['bcode'][$k] = array('t' => true, 'w' => 1, 'h' => 1, 'p' => 0);
613
+ $bararray['maxw'] += 1;
614
+ ++$k;
615
+ return $bararray;
616
+ }
617
+
618
+ /**
619
+ * Calculate CODE 93 checksum (modulo 47).
620
+ */
621
+ protected function checksum_code93($code) {
622
+ $chars = array(
623
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
624
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
625
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
626
+ 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%',
627
+ '<', '=', '>', '?');
628
+ // translate special characters
629
+ $code = strtr($code, chr(128).chr(131).chr(129).chr(130), '<=>?');
630
+ $len = strlen($code);
631
+ // calculate check digit C
632
+ $p = 1;
633
+ $check = 0;
634
+ for ($i = ($len - 1); $i >= 0; --$i) {
635
+ $k = array_keys($chars, $code{$i});
636
+ $check += ($k[0] * $p);
637
+ ++$p;
638
+ if ($p > 20) {
639
+ $p = 1;
640
+ }
641
+ }
642
+ $check %= 47;
643
+ $c = $chars[$check];
644
+ $code .= $c;
645
+ // calculate check digit K
646
+ $p = 1;
647
+ $check = 0;
648
+ for ($i = $len; $i >= 0; --$i) {
649
+ $k = array_keys($chars, $code{$i});
650
+ $check += ($k[0] * $p);
651
+ ++$p;
652
+ if ($p > 15) {
653
+ $p = 1;
654
+ }
655
+ }
656
+ $check %= 47;
657
+ $k = $chars[$check];
658
+ $checksum = $c.$k;
659
+ // resto respecial characters
660
+ $checksum = strtr($checksum, '<=>?', chr(128).chr(131).chr(129).chr(130));
661
+ return $checksum;
662
+ }
663
+
664
+ /**
665
+ * Checksum for standard 2 of 5 barcodes.
666
+ */
667
+ protected function checksum_s25($code) {
668
+ $len = strlen($code);
669
+ $sum = 0;
670
+ for ($i = 0; $i < $len; $i+=2) {
671
+ $sum += $code[$i];
672
+ }
673
+ $sum *= 3;
674
+ for ($i = 1; $i < $len; $i+=2) {
675
+ $sum += ($code[$i]);
676
+ }
677
+ $r = $sum % 10;
678
+ if($r > 0) {
679
+ $r = (10 - $r);
680
+ }
681
+ return $r;
682
+ }
683
+
684
+ /**
685
+ * MSI.
686
+ * Variation of Plessey code, with similar applications
687
+ * Contains digits (0 to 9) and encodes the data only in the width of bars.
688
+ */
689
+ protected function barcode_msi($code, $checksum=false) {
690
+ $chr['0'] = '100100100100';
691
+ $chr['1'] = '100100100110';
692
+ $chr['2'] = '100100110100';
693
+ $chr['3'] = '100100110110';
694
+ $chr['4'] = '100110100100';
695
+ $chr['5'] = '100110100110';
696
+ $chr['6'] = '100110110100';
697
+ $chr['7'] = '100110110110';
698
+ $chr['8'] = '110100100100';
699
+ $chr['9'] = '110100100110';
700
+ $chr['A'] = '110100110100';
701
+ $chr['B'] = '110100110110';
702
+ $chr['C'] = '110110100100';
703
+ $chr['D'] = '110110100110';
704
+ $chr['E'] = '110110110100';
705
+ $chr['F'] = '110110110110';
706
+ $checkdigit = '';
707
+ if ($checksum) {
708
+ // add checksum
709
+ $clen = strlen($code);
710
+ $p = 2;
711
+ $check = 0;
712
+ for ($i = ($clen - 1); $i >= 0; --$i) {
713
+ $check += (hexdec($code[$i]) * $p);
714
+ ++$p;
715
+ if ($p > 7) {
716
+ $p = 2;
717
+ }
718
+ }
719
+ $check %= 11;
720
+ if ($check > 0) {
721
+ $check = 11 - $check;
722
+ }
723
+ $code .= $check;
724
+ $checkdigit = $check;
725
+ }
726
+ $seq = '110'; // left guard
727
+ $clen = strlen($code);
728
+ for ($i = 0; $i < $clen; ++$i) {
729
+ $digit = $code[$i];
730
+ if (!isset($chr[$digit])) {
731
+ // invalid character
732
+ return false;
733
+ }
734
+ $seq .= $chr[$digit];
735
+ }
736
+ $seq .= '1001'; // right guard
737
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
738
+ $bararray['checkdigit'] = $checkdigit;
739
+ return $this->binseq_to_array($seq, $bararray);
740
+ }
741
+
742
+ /**
743
+ * Standard 2 of 5 barcodes.
744
+ * Used in airline ticket marking, photofinishing
745
+ * Contains digits (0 to 9) and encodes the data only in the width of bars.
746
+ */
747
+ protected function barcode_s25($code, $checksum=false) {
748
+ $chr['0'] = '10101110111010';
749
+ $chr['1'] = '11101010101110';
750
+ $chr['2'] = '10111010101110';
751
+ $chr['3'] = '11101110101010';
752
+ $chr['4'] = '10101110101110';
753
+ $chr['5'] = '11101011101010';
754
+ $chr['6'] = '10111011101010';
755
+ $chr['7'] = '10101011101110';
756
+ $chr['8'] = '10101110111010';
757
+ $chr['9'] = '10111010111010';
758
+ $checkdigit = '';
759
+ if ($checksum) {
760
+ // add checksum
761
+ $checkdigit = $this->checksum_s25($code);
762
+ $code .= $checkdigit ;
763
+ }
764
+ if((strlen($code) % 2) != 0) {
765
+ // add leading zero if code-length is odd
766
+ $code = '0'.$code;
767
+ }
768
+ $seq = '11011010';
769
+ $clen = strlen($code);
770
+ for ($i = 0; $i < $clen; ++$i) {
771
+ $digit = $code[$i];
772
+ if (!isset($chr[$digit])) {
773
+ // invalid character
774
+ return false;
775
+ }
776
+ $seq .= $chr[$digit];
777
+ }
778
+ $seq .= '1101011';
779
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
780
+ $bararray['checkdigit'] = $checkdigit;
781
+ return $this->binseq_to_array($seq, $bararray);
782
+ }
783
+
784
+ /**
785
+ * Convert binary barcode sequence to barcode array
786
+ */
787
+ protected function binseq_to_array($seq, $bararray) {
788
+ $len = strlen($seq);
789
+ $w = 0;
790
+ $k = 0;
791
+ for ($i = 0; $i < $len; ++$i) {
792
+ $w += 1;
793
+ if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq[$i] != $seq[($i+1)]))) {
794
+ if ($seq[$i] == '1') {
795
+ $t = true; // bar
796
+ } else {
797
+ $t = false; // space
798
+ }
799
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
800
+ $bararray['maxw'] += $w;
801
+ ++$k;
802
+ $w = 0;
803
+ }
804
+ }
805
+ return $bararray;
806
+ }
807
+
808
+ /**
809
+ * Interleaved 2 of 5 barcodes.
810
+ * Compact numeric code, widely used in industry, air cargo
811
+ * Contains digits (0 to 9) and encodes the data in the width of both bars and spaces.
812
+ */
813
+ protected function barcode_i25($code, $checksum=false) {
814
+ $chr['0'] = '11221';
815
+ $chr['1'] = '21112';
816
+ $chr['2'] = '12112';
817
+ $chr['3'] = '22111';
818
+ $chr['4'] = '11212';
819
+ $chr['5'] = '21211';
820
+ $chr['6'] = '12211';
821
+ $chr['7'] = '11122';
822
+ $chr['8'] = '21121';
823
+ $chr['9'] = '12121';
824
+ $chr['A'] = '11';
825
+ $chr['Z'] = '21';
826
+ $checkdigit = '';
827
+ if ($checksum) {
828
+ // add checksum
829
+ $checkdigit = $this->checksum_s25($code);
830
+ $code .= $checkdigit ;
831
+ }
832
+ if((strlen($code) % 2) != 0) {
833
+ // add leading zero if code-length is odd
834
+ $code = '0'.$code;
835
+ }
836
+ // add start and stop codes
837
+ $code = 'AA'.strtolower($code).'ZA';
838
+
839
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
840
+ $k = 0;
841
+ $clen = strlen($code);
842
+ for ($i = 0; $i < $clen; $i = ($i + 2)) {
843
+ $char_bar = $code[$i];
844
+ $char_space = $code[$i+1];
845
+ if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
846
+ // invalid character
847
+ return false;
848
+ }
849
+ // create a bar-space sequence
850
+ $seq = '';
851
+ $chrlen = strlen($chr[$char_bar]);
852
+ for ($s = 0; $s < $chrlen; $s++){
853
+ $seq .= $chr[$char_bar][$s] . $chr[$char_space][$s];
854
+ }
855
+ $seqlen = strlen($seq);
856
+ for ($j = 0; $j < $seqlen; ++$j) {
857
+ if (($j % 2) == 0) {
858
+ $t = true; // bar
859
+ } else {
860
+ $t = false; // space
861
+ }
862
+ $x = $seq[$j];
863
+ if ($x == 2) { $w = $this->print_ratio; }
864
+ else { $w = 1; }
865
+
866
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
867
+ $bararray['maxw'] += $w;
868
+ ++$k;
869
+ }
870
+ }
871
+ $bararray['checkdigit'] = $checkdigit;
872
+ return $bararray;
873
+ }
874
+
875
+ /**
876
+ * C128 barcodes.
877
+ * Very capable code, excellent density, high reliability; in very wide use world-wide
878
+ */
879
+ protected function barcode_c128($code, $type='B', $ean=false) {
880
+ $code = strcode2utf($code); // mPDF 5.7.1 Allows e.g. <barcode code="5432&#013;1068" type="C128A" />
881
+ $chr = array(
882
+ '212222', /* 00 */
883
+ '222122', /* 01 */
884
+ '222221', /* 02 */
885
+ '121223', /* 03 */
886
+ '121322', /* 04 */
887
+ '131222', /* 05 */
888
+ '122213', /* 06 */
889
+ '122312', /* 07 */
890
+ '132212', /* 08 */
891
+ '221213', /* 09 */
892
+ '221312', /* 10 */
893
+ '231212', /* 11 */
894
+ '112232', /* 12 */
895
+ '122132', /* 13 */
896
+ '122231', /* 14 */
897
+ '113222', /* 15 */
898
+ '123122', /* 16 */
899
+ '123221', /* 17 */
900
+ '223211', /* 18 */
901
+ '221132', /* 19 */
902
+ '221231', /* 20 */
903
+ '213212', /* 21 */
904
+ '223112', /* 22 */
905
+ '312131', /* 23 */
906
+ '311222', /* 24 */
907
+ '321122', /* 25 */
908
+ '321221', /* 26 */
909
+ '312212', /* 27 */
910
+ '322112', /* 28 */
911
+ '322211', /* 29 */
912
+ '212123', /* 30 */
913
+ '212321', /* 31 */
914
+ '232121', /* 32 */
915
+ '111323', /* 33 */
916
+ '131123', /* 34 */
917
+ '131321', /* 35 */
918
+ '112313', /* 36 */
919
+ '132113', /* 37 */
920
+ '132311', /* 38 */
921
+ '211313', /* 39 */
922
+ '231113', /* 40 */
923
+ '231311', /* 41 */
924
+ '112133', /* 42 */
925
+ '112331', /* 43 */
926
+ '132131', /* 44 */
927
+ '113123', /* 45 */
928
+ '113321', /* 46 */
929
+ '133121', /* 47 */
930
+ '313121', /* 48 */
931
+ '211331', /* 49 */
932
+ '231131', /* 50 */
933
+ '213113', /* 51 */
934
+ '213311', /* 52 */
935
+ '213131', /* 53 */
936
+ '311123', /* 54 */
937
+ '311321', /* 55 */
938
+ '331121', /* 56 */
939
+ '312113', /* 57 */
940
+ '312311', /* 58 */
941
+ '332111', /* 59 */
942
+ '314111', /* 60 */
943
+ '221411', /* 61 */
944
+ '431111', /* 62 */
945
+ '111224', /* 63 */
946
+ '111422', /* 64 */
947
+ '121124', /* 65 */
948
+ '121421', /* 66 */
949
+ '141122', /* 67 */
950
+ '141221', /* 68 */
951
+ '112214', /* 69 */
952
+ '112412', /* 70 */
953
+ '122114', /* 71 */
954
+ '122411', /* 72 */
955
+ '142112', /* 73 */
956
+ '142211', /* 74 */
957
+ '241211', /* 75 */
958
+ '221114', /* 76 */
959
+ '413111', /* 77 */
960
+ '241112', /* 78 */
961
+ '134111', /* 79 */
962
+ '111242', /* 80 */
963
+ '121142', /* 81 */
964
+ '121241', /* 82 */
965
+ '114212', /* 83 */
966
+ '124112', /* 84 */
967
+ '124211', /* 85 */
968
+ '411212', /* 86 */
969
+ '421112', /* 87 */
970
+ '421211', /* 88 */
971
+ '212141', /* 89 */
972
+ '214121', /* 90 */
973
+ '412121', /* 91 */
974
+ '111143', /* 92 */
975
+ '111341', /* 93 */
976
+ '131141', /* 94 */
977
+ '114113', /* 95 */
978
+ '114311', /* 96 */
979
+ '411113', /* 97 */
980
+ '411311', /* 98 */
981
+ '113141', /* 99 */
982
+ '114131', /* 100 */
983
+ '311141', /* 101 */
984
+ '411131', /* 102 */
985
+ '211412', /* 103 START A */
986
+ '211214', /* 104 START B */
987
+ '211232', /* 105 START C */
988
+ '233111', /* STOP */
989
+ '200000' /* END */
990
+ );
991
+ $keys = '';
992
+ switch(strtoupper($type)) {
993
+ case 'A': {
994
+ $startid = 103;
995
+ $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
996
+ for ($i = 0; $i < 32; ++$i) {
997
+ $keys .= chr($i);
998
+ }
999
+ break;
1000
+ }
1001
+ case 'B': {
1002
+ $startid = 104;
1003
+ $keys = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
1004
+ break;
1005
+ }
1006
+ case 'C': {
1007
+ $startid = 105;
1008
+ $keys = '';
1009
+ if ((strlen($code) % 2) != 0) {
1010
+ // The length of barcode value must be even ($code). You must pad the number with zeros
1011
+ return false;
1012
+ }
1013
+ for ($i = 0; $i <= 99; ++$i) {
1014
+ $keys .= chr($i);
1015
+ }
1016
+ $new_code = '';
1017
+ $hclen = (strlen($code) / 2);
1018
+ for ($i = 0; $i < $hclen; ++$i) {
1019
+ $new_code .= chr(intval($code{(2 * $i)}.$code{(2 * $i + 1)}));
1020
+ }
1021
+ $code = $new_code;
1022
+ break;
1023
+ }
1024
+ default: {
1025
+ return false;
1026
+ }
1027
+ }
1028
+
1029
+ // calculate check character
1030
+ $sum = $startid;
1031
+ if ($ean) { $code = chr(102) . $code; } // Add FNC 1 - which identifies it as EAN-128
1032
+ $clen = strlen($code);
1033
+ for ($i = 0; $i < $clen; ++$i) {
1034
+ if ($ean && $i==0) { $sum += 102; }
1035
+ else { $sum += (strpos($keys, $code[$i]) * ($i+1)); }
1036
+ }
1037
+ $check = ($sum % 103);
1038
+ $checkdigit = $check ;
1039
+ // add start, check and stop codes
1040
+ $code = chr($startid).$code.chr($check).chr(106).chr(107);
1041
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1042
+ $k = 0;
1043
+ $len = strlen($code);
1044
+ for ($i = 0; $i < $len; ++$i) {
1045
+ $ck = strpos($keys, $code[$i]);
1046
+ if (($i == 0) || ($ean && $i==1) | ($i > ($len-4))) {
1047
+ $char_num = ord($code[$i]);
1048
+ $seq = $chr[$char_num];
1049
+ } elseif(($ck >= 0) AND isset($chr[$ck])) {
1050
+ $seq = $chr[$ck];
1051
+ } else {
1052
+ // invalid character
1053
+ return false;
1054
+ }
1055
+ for ($j = 0; $j < 6; ++$j) {
1056
+ if (($j % 2) == 0) {
1057
+ $t = true; // bar
1058
+ } else {
1059
+ $t = false; // space
1060
+ }
1061
+ $w = $seq[$j];
1062
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1063
+ $bararray['maxw'] += $w;
1064
+ ++$k;
1065
+ }
1066
+ }
1067
+ $bararray['checkdigit'] = $checkdigit;
1068
+ return $bararray;
1069
+ }
1070
+
1071
+ /**
1072
+ * EAN13 and UPC-A barcodes.
1073
+ * EAN13: European Article Numbering international retail product code
1074
+ * UPC-A: Universal product code seen on almost all retail products in the USA and Canada
1075
+ * UPC-E: Short version of UPC symbol
1076
+ */
1077
+ protected function barcode_eanupc($code, $len=13) {
1078
+ $upce = false;
1079
+ $checkdigit = false;
1080
+ if ($len == 6) {
1081
+ $len = 12; // UPC-A
1082
+ $upce = true; // UPC-E mode
1083
+ }
1084
+ $data_len = $len - 1;
1085
+ //Padding
1086
+ $code = str_pad($code, $data_len, '0', STR_PAD_LEFT);
1087
+ $code_len = strlen($code);
1088
+ // calculate check digit
1089
+ $sum_a = 0;
1090
+ for ($i = 1; $i < $data_len; $i+=2) {
1091
+ $sum_a += $code[$i];
1092
+ }
1093
+ if ($len > 12) {
1094
+ $sum_a *= 3;
1095
+ }
1096
+ $sum_b = 0;
1097
+ for ($i = 0; $i < $data_len; $i+=2) {
1098
+ $sum_b += ($code[$i]);
1099
+ }
1100
+ if ($len < 13) {
1101
+ $sum_b *= 3;
1102
+ }
1103
+ $r = ($sum_a + $sum_b) % 10;
1104
+ if($r > 0) {
1105
+ $r = (10 - $r);
1106
+ }
1107
+ if ($code_len == $data_len) {
1108
+ // add check digit
1109
+ $code .= $r;
1110
+ $checkdigit = $r;
1111
+ } elseif ($r !== intval($code[$data_len])) {
1112
+ // wrong checkdigit
1113
+ return false;
1114
+ }
1115
+ if ($len == 12) {
1116
+ // UPC-A
1117
+ $code = '0'.$code;
1118
+ ++$len;
1119
+ }
1120
+ if ($upce) {
1121
+ // convert UPC-A to UPC-E
1122
+ $tmp = substr($code, 4, 3);
1123
+ $prod_code = intval(substr($code,7,5)); // product code
1124
+ $invalid_upce = false;
1125
+ if (($tmp == '000') OR ($tmp == '100') OR ($tmp == '200')) {
1126
+ // manufacturer code ends in 000, 100, or 200
1127
+ $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1128
+ if ($prod_code > 999) { $invalid_upce = true; }
1129
+ } else {
1130
+ $tmp = substr($code, 5, 2);
1131
+ if ($tmp == '00') {
1132
+ // manufacturer code ends in 00
1133
+ $upce_code = substr($code, 2, 3).substr($code, 10, 2).'3';
1134
+ if ($prod_code > 99) { $invalid_upce = true; }
1135
+ } else {
1136
+ $tmp = substr($code, 6, 1);
1137
+ if ($tmp == '0') {
1138
+ // manufacturer code ends in 0
1139
+ $upce_code = substr($code, 2, 4).substr($code, 11, 1).'4';
1140
+ if ($prod_code > 9) { $invalid_upce = true; }
1141
+ } else {
1142
+ // manufacturer code does not end in zero
1143
+ $upce_code = substr($code, 2, 5).substr($code, 11, 1);
1144
+ if ($prod_code > 9) { $invalid_upce = true; }
1145
+ }
1146
+ }
1147
+ }
1148
+ if ($invalid_upce) { die("Error - UPC-A cannot produce a valid UPC-E barcode"); } // Error generating a UPCE code
1149
+ }
1150
+ //Convert digits to bars
1151
+ $codes = array(
1152
+ 'A'=>array( // left odd parity
1153
+ '0'=>'0001101',
1154
+ '1'=>'0011001',
1155
+ '2'=>'0010011',
1156
+ '3'=>'0111101',
1157
+ '4'=>'0100011',
1158
+ '5'=>'0110001',
1159
+ '6'=>'0101111',
1160
+ '7'=>'0111011',
1161
+ '8'=>'0110111',
1162
+ '9'=>'0001011'),
1163
+ 'B'=>array( // left even parity
1164
+ '0'=>'0100111',
1165
+ '1'=>'0110011',
1166
+ '2'=>'0011011',
1167
+ '3'=>'0100001',
1168
+ '4'=>'0011101',
1169
+ '5'=>'0111001',
1170
+ '6'=>'0000101',
1171
+ '7'=>'0010001',
1172
+ '8'=>'0001001',
1173
+ '9'=>'0010111'),
1174
+ 'C'=>array( // right
1175
+ '0'=>'1110010',
1176
+ '1'=>'1100110',
1177
+ '2'=>'1101100',
1178
+ '3'=>'1000010',
1179
+ '4'=>'1011100',
1180
+ '5'=>'1001110',
1181
+ '6'=>'1010000',
1182
+ '7'=>'1000100',
1183
+ '8'=>'1001000',
1184
+ '9'=>'1110100')
1185
+ );
1186
+ $parities = array(
1187
+ '0'=>array('A','A','A','A','A','A'),
1188
+ '1'=>array('A','A','B','A','B','B'),
1189
+ '2'=>array('A','A','B','B','A','B'),
1190
+ '3'=>array('A','A','B','B','B','A'),
1191
+ '4'=>array('A','B','A','A','B','B'),
1192
+ '5'=>array('A','B','B','A','A','B'),
1193
+ '6'=>array('A','B','B','B','A','A'),
1194
+ '7'=>array('A','B','A','B','A','B'),
1195
+ '8'=>array('A','B','A','B','B','A'),
1196
+ '9'=>array('A','B','B','A','B','A')
1197
+ );
1198
+ $upce_parities = array();
1199
+ $upce_parities[0] = array(
1200
+ '0'=>array('B','B','B','A','A','A'),
1201
+ '1'=>array('B','B','A','B','A','A'),
1202
+ '2'=>array('B','B','A','A','B','A'),
1203
+ '3'=>array('B','B','A','A','A','B'),
1204
+ '4'=>array('B','A','B','B','A','A'),
1205
+ '5'=>array('B','A','A','B','B','A'),
1206
+ '6'=>array('B','A','A','A','B','B'),
1207
+ '7'=>array('B','A','B','A','B','A'),
1208
+ '8'=>array('B','A','B','A','A','B'),
1209
+ '9'=>array('B','A','A','B','A','B')
1210
+ );
1211
+ $upce_parities[1] = array(
1212
+ '0'=>array('A','A','A','B','B','B'),
1213
+ '1'=>array('A','A','B','A','B','B'),
1214
+ '2'=>array('A','A','B','B','A','B'),
1215
+ '3'=>array('A','A','B','B','B','A'),
1216
+ '4'=>array('A','B','A','A','B','B'),
1217
+ '5'=>array('A','B','B','A','A','B'),
1218
+ '6'=>array('A','B','B','B','A','A'),
1219
+ '7'=>array('A','B','A','B','A','B'),
1220
+ '8'=>array('A','B','A','B','B','A'),
1221
+ '9'=>array('A','B','B','A','B','A')
1222
+ );
1223
+ $k = 0;
1224
+ $seq = '101'; // left guard bar
1225
+ if ($upce) {
1226
+ $bararray = array('code' => $upce_code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1227
+ $p = $upce_parities[$code{1}][$r];
1228
+ for ($i = 0; $i < 6; ++$i) {
1229
+ $seq .= $codes[$p[$i]][$upce_code[$i]];
1230
+ }
1231
+ $seq .= '010101'; // right guard bar
1232
+ } else {
1233
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1234
+ $half_len = ceil($len / 2);
1235
+ if ($len == 8) {
1236
+ for ($i = 0; $i < $half_len; ++$i) {
1237
+ $seq .= $codes['A'][$code[$i]];
1238
+ }
1239
+ } else {
1240
+ $p = $parities[$code{0}];
1241
+ for ($i = 1; $i < $half_len; ++$i) {
1242
+ $seq .= $codes[$p[$i-1]][$code[$i]];
1243
+ }
1244
+ }
1245
+ $seq .= '01010'; // center guard bar
1246
+ for ($i = $half_len; $i < $len; ++$i) {
1247
+ $seq .= $codes['C'][$code[$i]];
1248
+ }
1249
+ $seq .= '101'; // right guard bar
1250
+ }
1251
+ $clen = strlen($seq);
1252
+ $w = 0;
1253
+ for ($i = 0; $i < $clen; ++$i) {
1254
+ $w += 1;
1255
+ if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq[$i] != $seq[($i+1)]))) {
1256
+ if ($seq[$i] == '1') {
1257
+ $t = true; // bar
1258
+ } else {
1259
+ $t = false; // space
1260
+ }
1261
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1262
+ $bararray['maxw'] += $w;
1263
+ ++$k;
1264
+ $w = 0;
1265
+ }
1266
+ }
1267
+ $bararray['checkdigit'] = $checkdigit;
1268
+ return $bararray;
1269
+ }
1270
+
1271
+ /**
1272
+ * UPC-Based Extentions
1273
+ * 2-Digit Ext.: Used to indicate magazines and newspaper issue numbers
1274
+ * 5-Digit Ext.: Used to mark suggested retail price of books
1275
+ */
1276
+ protected function barcode_eanext($code, $len=5) {
1277
+ //Padding
1278
+ $code = str_pad($code, $len, '0', STR_PAD_LEFT);
1279
+ // calculate check digit
1280
+ if ($len == 2) {
1281
+ $r = $code % 4;
1282
+ } elseif ($len == 5) {
1283
+ $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3}));
1284
+ $r %= 10;
1285
+ } else {
1286
+ return false;
1287
+ }
1288
+ //Convert digits to bars
1289
+ $codes = array(
1290
+ 'A'=>array( // left odd parity
1291
+ '0'=>'0001101',
1292
+ '1'=>'0011001',
1293
+ '2'=>'0010011',
1294
+ '3'=>'0111101',
1295
+ '4'=>'0100011',
1296
+ '5'=>'0110001',
1297
+ '6'=>'0101111',
1298
+ '7'=>'0111011',
1299
+ '8'=>'0110111',
1300
+ '9'=>'0001011'),
1301
+ 'B'=>array( // left even parity
1302
+ '0'=>'0100111',
1303
+ '1'=>'0110011',
1304
+ '2'=>'0011011',
1305
+ '3'=>'0100001',
1306
+ '4'=>'0011101',
1307
+ '5'=>'0111001',
1308
+ '6'=>'0000101',
1309
+ '7'=>'0010001',
1310
+ '8'=>'0001001',
1311
+ '9'=>'0010111')
1312
+ );
1313
+ $parities = array();
1314
+ $parities[2] = array(
1315
+ '0'=>array('A','A'),
1316
+ '1'=>array('A','B'),
1317
+ '2'=>array('B','A'),
1318
+ '3'=>array('B','B')
1319
+ );
1320
+ $parities[5] = array(
1321
+ '0'=>array('B','B','A','A','A'),
1322
+ '1'=>array('B','A','B','A','A'),
1323
+ '2'=>array('B','A','A','B','A'),
1324
+ '3'=>array('B','A','A','A','B'),
1325
+ '4'=>array('A','B','B','A','A'),
1326
+ '5'=>array('A','A','B','B','A'),
1327
+ '6'=>array('A','A','A','B','B'),
1328
+ '7'=>array('A','B','A','B','A'),
1329
+ '8'=>array('A','B','A','A','B'),
1330
+ '9'=>array('A','A','B','A','B')
1331
+ );
1332
+ $p = $parities[$len][$r];
1333
+ $seq = '1011'; // left guard bar
1334
+ $seq .= $codes[$p[0]][$code{0}];
1335
+ for ($i = 1; $i < $len; ++$i) {
1336
+ $seq .= '01'; // separator
1337
+ $seq .= $codes[$p[$i]][$code[$i]];
1338
+ }
1339
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1340
+ return $this->binseq_to_array($seq, $bararray);
1341
+ }
1342
+
1343
+ /**
1344
+ * POSTNET and PLANET barcodes.
1345
+ * Used by U.S. Postal Service for automated mail sorting
1346
+ */
1347
+ protected function barcode_postnet($code, $planet=false) {
1348
+ // bar lenght
1349
+ if ($planet) {
1350
+ $barlen = Array(
1351
+ 0 => Array(1,1,2,2,2),
1352
+ 1 => Array(2,2,2,1,1),
1353
+ 2 => Array(2,2,1,2,1),
1354
+ 3 => Array(2,2,1,1,2),
1355
+ 4 => Array(2,1,2,2,1),
1356
+ 5 => Array(2,1,2,1,2),
1357
+ 6 => Array(2,1,1,2,2),
1358
+ 7 => Array(1,2,2,2,1),
1359
+ 8 => Array(1,2,2,1,2),
1360
+ 9 => Array(1,2,1,2,2)
1361
+ );
1362
+ } else {
1363
+ $barlen = Array(
1364
+ 0 => Array(2,2,1,1,1),
1365
+ 1 => Array(1,1,1,2,2),
1366
+ 2 => Array(1,1,2,1,2),
1367
+ 3 => Array(1,1,2,2,1),
1368
+ 4 => Array(1,2,1,1,2),
1369
+ 5 => Array(1,2,1,2,1),
1370
+ 6 => Array(1,2,2,1,1),
1371
+ 7 => Array(2,1,1,1,2),
1372
+ 8 => Array(2,1,1,2,1),
1373
+ 9 => Array(2,1,2,1,1)
1374
+ );
1375
+ }
1376
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 5, 'bcode' => array());
1377
+ $k = 0;
1378
+ $code = str_replace('-', '', $code);
1379
+ $code = str_replace(' ', '', $code);
1380
+ $len = strlen($code);
1381
+ // calculate checksum
1382
+ $sum = 0;
1383
+ for ($i = 0; $i < $len; ++$i) {
1384
+ $sum += intval($code[$i]);
1385
+ }
1386
+ $chkd = ($sum % 10);
1387
+ if($chkd > 0) {
1388
+ $chkd = (10 - $chkd);
1389
+ }
1390
+ $code .= $chkd;
1391
+ $checkdigit = $chkd;
1392
+ $len = strlen($code);
1393
+ // start bar
1394
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 5, 'p' => 0);
1395
+ $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 5, 'p' => 0);
1396
+ $bararray['maxw'] += (1 + $this->gapwidth );
1397
+ for ($i = 0; $i < $len; ++$i) {
1398
+ for ($j = 0; $j < 5; ++$j) {
1399
+ $bh = $barlen[$code[$i]][$j];
1400
+ if ($bh == 2) {
1401
+ $h = 5;
1402
+ $p = 0;
1403
+ }
1404
+ else {
1405
+ $h = 2;
1406
+ $p = 3;
1407
+ }
1408
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1409
+ $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 2, 'p' => 0);
1410
+ $bararray['maxw'] += (1 + $this->gapwidth );
1411
+ }
1412
+ }
1413
+ // end bar
1414
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => 5, 'p' => 0);
1415
+ $bararray['maxw'] += 1;
1416
+ $bararray['checkdigit'] = $checkdigit;
1417
+ return $bararray;
1418
+ }
1419
+
1420
+ /**
1421
+ * RM4SCC - CBC - KIX
1422
+ * RM4SCC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code) - KIX (Klant index - Customer index)
1423
+ * RM4SCC is the name of the barcode symbology used by the Royal Mail for its Cleanmail service.
1424
+ */
1425
+ protected function barcode_rm4scc($code, $kix=false) {
1426
+ $notkix = !$kix;
1427
+ // bar mode
1428
+ // 1 = pos 1, length 2
1429
+ // 2 = pos 1, length 3
1430
+ // 3 = pos 2, length 1
1431
+ // 4 = pos 2, length 2
1432
+ $barmode = array(
1433
+ '0' => array(3,3,2,2),
1434
+ '1' => array(3,4,1,2),
1435
+ '2' => array(3,4,2,1),
1436
+ '3' => array(4,3,1,2),
1437
+ '4' => array(4,3,2,1),
1438
+ '5' => array(4,4,1,1),
1439
+ '6' => array(3,1,4,2),
1440
+ '7' => array(3,2,3,2),
1441
+ '8' => array(3,2,4,1),
1442
+ '9' => array(4,1,3,2),
1443
+ 'A' => array(4,1,4,1),
1444
+ 'B' => array(4,2,3,1),
1445
+ 'C' => array(3,1,2,4),
1446
+ 'D' => array(3,2,1,4),
1447
+ 'E' => array(3,2,2,3),
1448
+ 'F' => array(4,1,1,4),
1449
+ 'G' => array(4,1,2,3),
1450
+ 'H' => array(4,2,1,3),
1451
+ 'I' => array(1,3,4,2),
1452
+ 'J' => array(1,4,3,2),
1453
+ 'K' => array(1,4,4,1),
1454
+ 'L' => array(2,3,3,2),
1455
+ 'M' => array(2,3,4,1),
1456
+ 'N' => array(2,4,3,1),
1457
+ 'O' => array(1,3,2,4),
1458
+ 'P' => array(1,4,1,4),
1459
+ 'Q' => array(1,4,2,3),
1460
+ 'R' => array(2,3,1,4),
1461
+ 'S' => array(2,3,2,3),
1462
+ 'T' => array(2,4,1,3),
1463
+ 'U' => array(1,1,4,4),
1464
+ 'V' => array(1,2,3,4),
1465
+ 'W' => array(1,2,4,3),
1466
+ 'X' => array(2,1,3,4),
1467
+ 'Y' => array(2,1,4,3),
1468
+ 'Z' => array(2,2,3,3)
1469
+ );
1470
+ $code = strtoupper($code);
1471
+ $len = strlen($code);
1472
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => $this->daft['F'], 'bcode' => array());
1473
+ if ($notkix) {
1474
+ // table for checksum calculation (row,col)
1475
+ $checktable = array(
1476
+ '0' => array(1,1),
1477
+ '1' => array(1,2),
1478
+ '2' => array(1,3),
1479
+ '3' => array(1,4),
1480
+ '4' => array(1,5),
1481
+ '5' => array(1,0),
1482
+ '6' => array(2,1),
1483
+ '7' => array(2,2),
1484
+ '8' => array(2,3),
1485
+ '9' => array(2,4),
1486
+ 'A' => array(2,5),
1487
+ 'B' => array(2,0),
1488
+ 'C' => array(3,1),
1489
+ 'D' => array(3,2),
1490
+ 'E' => array(3,3),
1491
+ 'F' => array(3,4),
1492
+ 'G' => array(3,5),
1493
+ 'H' => array(3,0),
1494
+ 'I' => array(4,1),
1495
+ 'J' => array(4,2),
1496
+ 'K' => array(4,3),
1497
+ 'L' => array(4,4),
1498
+ 'M' => array(4,5),
1499
+ 'N' => array(4,0),
1500
+ 'O' => array(5,1),
1501
+ 'P' => array(5,2),
1502
+ 'Q' => array(5,3),
1503
+ 'R' => array(5,4),
1504
+ 'S' => array(5,5),
1505
+ 'T' => array(5,0),
1506
+ 'U' => array(0,1),
1507
+ 'V' => array(0,2),
1508
+ 'W' => array(0,3),
1509
+ 'X' => array(0,4),
1510
+ 'Y' => array(0,5),
1511
+ 'Z' => array(0,0)
1512
+ );
1513
+ $row = 0;
1514
+ $col = 0;
1515
+ for ($i = 0; $i < $len; ++$i) {
1516
+ $row += $checktable[$code[$i]][0];
1517
+ $col += $checktable[$code[$i]][1];
1518
+ }
1519
+ $row %= 6;
1520
+ $col %= 6;
1521
+ $chk = array_keys($checktable, array($row,$col));
1522
+ $code .= $chk[0];
1523
+ $bararray['checkdigit'] = $chk[0];
1524
+ ++$len;
1525
+ }
1526
+ $k = 0;
1527
+ if ($notkix) {
1528
+ // start bar
1529
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $this->daft['A'] , 'p' => 0);
1530
+ $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => $this->daft['A'] , 'p' => 0);
1531
+ $bararray['maxw'] += (1 + $this->gapwidth) ;
1532
+ }
1533
+ for ($i = 0; $i < $len; ++$i) {
1534
+ for ($j = 0; $j < 4; ++$j) {
1535
+ switch ($barmode[$code[$i]][$j]) {
1536
+ case 1: {
1537
+ // ascender (A)
1538
+ $p = 0;
1539
+ $h = $this->daft['A'];
1540
+ break;
1541
+ }
1542
+ case 2: {
1543
+ // full bar (F)
1544
+ $p = 0;
1545
+ $h = $this->daft['F'];
1546
+ break;
1547
+ }
1548
+ case 3: {
1549
+ // tracker (T)
1550
+ $p = ($this->daft['F'] - $this->daft['T'])/2;
1551
+ $h = $this->daft['T'];
1552
+ break;
1553
+ }
1554
+ case 4: {
1555
+ // descender (D)
1556
+ $p = $this->daft['F'] - $this->daft['D'];
1557
+ $h = $this->daft['D'];
1558
+ break;
1559
+ }
1560
+ }
1561
+
1562
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1563
+ $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth, 'h' => 2, 'p' => 0);
1564
+ $bararray['maxw'] += (1 + $this->gapwidth) ;
1565
+ }
1566
+ }
1567
+ if ($notkix) {
1568
+ // stop bar
1569
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $this->daft['F'], 'p' => 0);
1570
+ $bararray['maxw'] += 1;
1571
+ }
1572
+ return $bararray;
1573
+ }
1574
+
1575
+ /**
1576
+ * CODABAR barcodes.
1577
+ * Older code often used in library systems, sometimes in blood banks
1578
+ */
1579
+ protected function barcode_codabar($code) {
1580
+ $chr = array(
1581
+ '0' => '11111221',
1582
+ '1' => '11112211',
1583
+ '2' => '11121121',
1584
+ '3' => '22111111',
1585
+ '4' => '11211211',
1586
+ '5' => '21111211',
1587
+ '6' => '12111121',
1588
+ '7' => '12112111',
1589
+ '8' => '12211111',
1590
+ '9' => '21121111',
1591
+ '-' => '11122111',
1592
+ '$' => '11221111',
1593
+ ':' => '21112121',
1594
+ '/' => '21211121',
1595
+ '.' => '21212111',
1596
+ '+' => '11222221',
1597
+ 'A' => '11221211',
1598
+ 'B' => '12121121',
1599
+ 'C' => '11121221',
1600
+ 'D' => '11122211'
1601
+ );
1602
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1603
+ $k = 0;
1604
+ $w = 0;
1605
+ $seq = '';
1606
+ $code = strtoupper($code);
1607
+ $len = strlen($code);
1608
+ for ($i = 0; $i < $len; ++$i) {
1609
+ if (!isset($chr[$code[$i]])) {
1610
+ return false;
1611
+ }
1612
+ $seq = $chr[$code[$i]];
1613
+ for ($j = 0; $j < 8; ++$j) {
1614
+ if (($j % 2) == 0) {
1615
+ $t = true; // bar
1616
+ } else {
1617
+ $t = false; // space
1618
+ }
1619
+ $x = $seq[$j];
1620
+ if ($x == 2) { $w = $this->print_ratio; }
1621
+ else { $w = 1; }
1622
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1623
+ $bararray['maxw'] += $w;
1624
+ ++$k;
1625
+ }
1626
+ }
1627
+ return $bararray;
1628
+ }
1629
+
1630
+ /**
1631
+ * CODE11 barcodes.
1632
+ * Used primarily for labeling telecommunications equipment
1633
+ */
1634
+ protected function barcode_code11($code) {
1635
+ $chr = array(
1636
+ '0' => '111121',
1637
+ '1' => '211121',
1638
+ '2' => '121121',
1639
+ '3' => '221111',
1640
+ '4' => '112121',
1641
+ '5' => '212111',
1642
+ '6' => '122111',
1643
+ '7' => '111221',
1644
+ '8' => '211211',
1645
+ '9' => '211111',
1646
+ '-' => '112111',
1647
+ 'S' => '112211'
1648
+ );
1649
+
1650
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => 1, 'bcode' => array());
1651
+ $k = 0;
1652
+ $w = 0;
1653
+ $seq = '';
1654
+ $len = strlen($code);
1655
+ // calculate check digit C
1656
+ $p = 1;
1657
+ $check = 0;
1658
+ for ($i = ($len - 1); $i >= 0; --$i) {
1659
+ $digit = $code[$i];
1660
+ if ($digit == '-') {
1661
+ $dval = 10;
1662
+ } else {
1663
+ $dval = intval($digit);
1664
+ }
1665
+ $check += ($dval * $p);
1666
+ ++$p;
1667
+ if ($p > 10) {
1668
+ $p = 1;
1669
+ }
1670
+ }
1671
+ $check %= 11;
1672
+ if ($check == 10) {
1673
+ $check = '-';
1674
+ }
1675
+ $code .= $check;
1676
+ $checkdigit = $check;
1677
+ if ($len > 10) {
1678
+ // calculate check digit K
1679
+ $p = 1;
1680
+ $check = 0;
1681
+ for ($i = $len; $i >= 0; --$i) {
1682
+ $digit = $code[$i];
1683
+ if ($digit == '-') {
1684
+ $dval = 10;
1685
+ } else {
1686
+ $dval = intval($digit);
1687
+ }
1688
+ $check += ($dval * $p);
1689
+ ++$p;
1690
+ if ($p > 9) {
1691
+ $p = 1;
1692
+ }
1693
+ }
1694
+ $check %= 11;
1695
+ $code .= $check;
1696
+ $checkdigit .= $check;
1697
+ ++$len;
1698
+ }
1699
+ $code = 'S'.$code.'S';
1700
+ $len += 3;
1701
+ for ($i = 0; $i < $len; ++$i) {
1702
+ if (!isset($chr[$code[$i]])) {
1703
+ return false;
1704
+ }
1705
+ $seq = $chr[$code[$i]];
1706
+ for ($j = 0; $j < 6; ++$j) {
1707
+ if (($j % 2) == 0) {
1708
+ $t = true; // bar
1709
+ } else {
1710
+ $t = false; // space
1711
+ }
1712
+ $x = $seq[$j];
1713
+ if ($x == 2) { $w = $this->print_ratio; }
1714
+ else { $w = 1; }
1715
+ $bararray['bcode'][$k] = array('t' => $t, 'w' => $w, 'h' => 1, 'p' => 0);
1716
+ $bararray['maxw'] += $w;
1717
+ ++$k;
1718
+ }
1719
+ }
1720
+ $bararray['checkdigit'] = $checkdigit;
1721
+ return $bararray;
1722
+ }
1723
+
1724
+
1725
+ /**
1726
+ * IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
1727
+ * (requires PHP bcmath extension)
1728
+ * Intelligent Mail barcode is a 65-bar code for use on mail in the United States.
1729
+ * The fields are described as follows:<ul><li>The Barcode Identifier shall be assigned by USPS to encode the presort identification that is currently printed in human readable form on the optional endorsement line (OEL) as well as for future USPS use. This shall be two digits, with the second digit in the range of 0-4. The allowable encoding ranges shall be 00-04, 10-14, 20-24, 30-34, 40-44, 50-54, 60-64, 70-74, 80-84, and 90-94.</li><li>The Service Type Identifier shall be assigned by USPS for any combination of services requested on the mailpiece. The allowable encoding range shall be 000-999. Each 3-digit value shall correspond to a particular mail class with a particular combination of service(s). Each service program, such as OneCode Confirm and OneCode ACS, shall provide the list of Service Type Identifier values.</li><li>The Mailer or Customer Identifier shall be assigned by USPS as a unique, 6 or 9 digit number that identifies a business entity. The allowable encoding range for the 6 digit Mailer ID shall be 000000- 899999, while the allowable encoding range for the 9 digit Mailer ID shall be 900000000-999999999.</li><li>The Serial or Sequence Number shall be assigned by the mailer for uniquely identifying and tracking mailpieces. The allowable encoding range shall be 000000000-999999999 when used with a 6 digit Mailer ID and 000000-999999 when used with a 9 digit Mailer ID. e. The Delivery Point ZIP Code shall be assigned by the mailer for routing the mailpiece. This shall replace POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges shall be no ZIP Code, 00000-99999, 000000000-999999999, and 00000000000-99999999999.</li></ul>
1730
+ */
1731
+ protected function barcode_imb($code) {
1732
+ $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
1733
+ $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
1734
+ $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
1735
+ $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
1736
+ $code_arr = explode('-', $code);
1737
+ $tracking_number = $code_arr[0];
1738
+ if (isset($code_arr[1])) {
1739
+ $routing_code = $code_arr[1];
1740
+ } else {
1741
+ $routing_code = '';
1742
+ }
1743
+ // Conversion of Routing Code
1744
+ switch (strlen($routing_code)) {
1745
+ case 0: {
1746
+ $binary_code = 0;
1747
+ break;
1748
+ }
1749
+ case 5: {
1750
+ $binary_code = bcadd($routing_code, '1');
1751
+ break;
1752
+ }
1753
+ case 9: {
1754
+ $binary_code = bcadd($routing_code, '100001');
1755
+ break;
1756
+ }
1757
+ case 11: {
1758
+ $binary_code = bcadd($routing_code, '1000100001');
1759
+ break;
1760
+ }
1761
+ default: {
1762
+ return false;
1763
+ break;
1764
+ }
1765
+ }
1766
+ $binary_code = bcmul($binary_code, 10);
1767
+ $binary_code = bcadd($binary_code, $tracking_number{0});
1768
+ $binary_code = bcmul($binary_code, 5);
1769
+ $binary_code = bcadd($binary_code, $tracking_number{1});
1770
+ $binary_code .= substr($tracking_number, 2, 18);
1771
+ // convert to hexadecimal
1772
+ $binary_code = $this->dec_to_hex($binary_code);
1773
+ // pad to get 13 bytes
1774
+ $binary_code = str_pad($binary_code, 26, '0', STR_PAD_LEFT);
1775
+ // convert string to array of bytes
1776
+ $binary_code_arr = chunk_split($binary_code, 2, "\r");
1777
+ $binary_code_arr = substr($binary_code_arr, 0, -1);
1778
+ $binary_code_arr = explode("\r", $binary_code_arr);
1779
+ // calculate frame check sequence
1780
+ $fcs = $this->imb_crc11fcs($binary_code_arr);
1781
+ // exclude first 2 bits from first byte
1782
+ $first_byte = sprintf('%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
1783
+ $binary_code_102bit = $first_byte.substr($binary_code, 2);
1784
+ // convert binary data to codewords
1785
+ $codewords = array();
1786
+ $data = $this->hex_to_dec($binary_code_102bit);
1787
+ $codewords[0] = bcmod($data, 636) * 2;
1788
+ $data = bcdiv($data, 636);
1789
+ for ($i = 1; $i < 9; ++$i) {
1790
+ $codewords[$i] = bcmod($data, 1365);
1791
+ $data = bcdiv($data, 1365);
1792
+ }
1793
+ $codewords[9] = $data;
1794
+ if (($fcs >> 10) == 1) {
1795
+ $codewords[9] += 659;
1796
+ }
1797
+ // generate lookup tables
1798
+ $table2of13 = $this->imb_tables(2, 78);
1799
+ $table5of13 = $this->imb_tables(5, 1287);
1800
+ // convert codewords to characters
1801
+ $characters = array();
1802
+ $bitmask = 512;
1803
+ foreach($codewords as $k => $val) {
1804
+ if ($val <= 1286) {
1805
+ $chrcode = $table5of13[$val];
1806
+ } else {
1807
+ $chrcode = $table2of13[($val - 1287)];
1808
+ }
1809
+ if (($fcs & $bitmask) > 0) {
1810
+ // bitwise invert
1811
+ $chrcode = ((~$chrcode) & 8191);
1812
+ }
1813
+ $characters[] = $chrcode;
1814
+ $bitmask /= 2;
1815
+ }
1816
+ $characters = array_reverse($characters);
1817
+ // build bars
1818
+ $k = 0;
1819
+ $bararray = array('code' => $code, 'maxw' => 0, 'maxh' => $this->daft['F'], 'bcode' => array());
1820
+ for ($i = 0; $i < 65; ++$i) {
1821
+ $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
1822
+ $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
1823
+ if ($asc AND $dsc) {
1824
+ // full bar (F)
1825
+ $p = 0;
1826
+ $h = $this->daft['F'];
1827
+ } elseif ($asc) {
1828
+ // ascender (A)
1829
+ $p = 0;
1830
+ $h = $this->daft['A'];
1831
+ } elseif ($dsc) {
1832
+ // descender (D)
1833
+ $p = $this->daft['F'] - $this->daft['D'];
1834
+ $h = $this->daft['D'];
1835
+ } else {
1836
+ // tracker (T)
1837
+ $p = ($this->daft['F'] - $this->daft['T'])/2;
1838
+ $h = $this->daft['T'];
1839
+ }
1840
+ $bararray['bcode'][$k++] = array('t' => 1, 'w' => 1, 'h' => $h, 'p' => $p);
1841
+ // Gap
1842
+ $bararray['bcode'][$k++] = array('t' => 0, 'w' => $this->gapwidth , 'h' => 1, 'p' => 0);
1843
+ $bararray['maxw'] += (1 + $this->gapwidth );
1844
+ }
1845
+ unset($bararray['bcode'][($k - 1)]);
1846
+ $bararray['maxw'] -= $this->gapwidth ;
1847
+ return $bararray;
1848
+ }
1849
+
1850
+ /**
1851
+ * Convert large integer number to hexadecimal representation.
1852
+ * (requires PHP bcmath extension)
1853
+ */
1854
+ public function dec_to_hex($number) {
1855
+ $i = 0;
1856
+ $hex = array();
1857
+ if($number == 0) {
1858
+ return '00';
1859
+ }
1860
+ while($number > 0) {
1861
+ if($number == 0) {
1862
+ array_push($hex, '0');
1863
+ } else {
1864
+ array_push($hex, strtoupper(dechex(bcmod($number, '16'))));
1865
+ $number = bcdiv($number, '16', 0);
1866
+ }
1867
+ }
1868
+ $hex = array_reverse($hex);
1869
+ return implode($hex);
1870
+ }
1871
+
1872
+ /**
1873
+ * Convert large hexadecimal number to decimal representation (string).
1874
+ * (requires PHP bcmath extension)
1875
+ */
1876
+ public function hex_to_dec($hex) {
1877
+ $dec = 0;
1878
+ $bitval = 1;
1879
+ $len = strlen($hex);
1880
+ for($pos = ($len - 1); $pos >= 0; --$pos) {
1881
+ $dec = bcadd($dec, bcmul(hexdec($hex[$pos]), $bitval));
1882
+ $bitval = bcmul($bitval, 16);
1883
+ }
1884
+ return $dec;
1885
+ }
1886
+
1887
+ /**
1888
+ * Intelligent Mail Barcode calculation of Frame Check Sequence
1889
+ */
1890
+ protected function imb_crc11fcs($code_arr) {
1891
+ $genpoly = 0x0F35; // generator polynomial
1892
+ $fcs = 0x07FF; // Frame Check Sequence
1893
+ // do most significant byte skipping the 2 most significant bits
1894
+ $data = hexdec($code_arr[0]) << 5;
1895
+ for ($bit = 2; $bit < 8; ++$bit) {
1896
+ if (($fcs ^ $data) & 0x400) {
1897
+ $fcs = ($fcs << 1) ^ $genpoly;
1898
+ } else {
1899
+ $fcs = ($fcs << 1);
1900
+ }
1901
+ $fcs &= 0x7FF;
1902
+ $data <<= 1;
1903
+ }
1904
+ // do rest of bytes
1905
+ for ($byte = 1; $byte < 13; ++$byte) {
1906
+ $data = hexdec($code_arr[$byte]) << 3;
1907
+ for ($bit = 0; $bit < 8; ++$bit) {
1908
+ if (($fcs ^ $data) & 0x400) {
1909
+ $fcs = ($fcs << 1) ^ $genpoly;
1910
+ } else {
1911
+ $fcs = ($fcs << 1);
1912
+ }
1913
+ $fcs &= 0x7FF;
1914
+ $data <<= 1;
1915
+ }
1916
+ }
1917
+ return $fcs;
1918
+ }
1919
+
1920
+ /**
1921
+ * Reverse unsigned short value
1922
+ */
1923
+ protected function imb_reverse_us($num) {
1924
+ $rev = 0;
1925
+ for ($i = 0; $i < 16; ++$i) {
1926
+ $rev <<= 1;
1927
+ $rev |= ($num & 1);
1928
+ $num >>= 1;
1929
+ }
1930
+ return $rev;
1931
+ }
1932
+
1933
+ /**
1934
+ * generate Nof13 tables used for Intelligent Mail Barcode
1935
+ */
1936
+ protected function imb_tables($n, $size) {
1937
+ $table = array();
1938
+ $lli = 0; // LUT lower index
1939
+ $lui = $size - 1; // LUT upper index
1940
+ for ($count = 0; $count < 8192; ++$count) {
1941
+ $bit_count = 0;
1942
+ for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
1943
+ $bit_count += intval(($count & (1 << $bit_index)) != 0);
1944
+ }
1945
+ // if we don't have the right number of bits on, go on to the next value
1946
+ if ($bit_count == $n) {
1947
+ $reverse = ($this->imb_reverse_us($count) >> 3);
1948
+ // if the reverse is less than count, we have already visited this pair before
1949
+ if ($reverse >= $count) {
1950
+ // If count is symmetric, place it at the first free slot from the end of the list.
1951
+ // Otherwise, place it at the first free slot from the beginning of the list AND place $reverse ath the next free slot from the beginning of the list
1952
+ if ($reverse == $count) {
1953
+ $table[$lui] = $count;
1954
+ --$lui;
1955
+ } else {
1956
+ $table[$lli] = $count;
1957
+ ++$lli;
1958
+ $table[$lli] = $reverse;
1959
+ ++$lli;
1960
+ }
1961
+ }
1962
+ }
1963
+ }
1964
+ return $table;
1965
+ }
1966
+
1967
+ } // end of class
1968
+
1969
+ //============================================================+
1970
+ // END OF FILE
1971
+ //============================================================+
1972
+ ?>
lib/mpdf/classes/bmp.php ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class bmp {
4
+
5
+ var $mpdf = null;
6
+
7
+ function bmp(&$mpdf) {
8
+ $this->mpdf = $mpdf;
9
+ }
10
+
11
+
12
+ function _getBMPimage($data, $file) {
13
+ $info = array();
14
+ // Adapted from script by Valentin Schmidt
15
+ // http://staff.dasdeck.de/valentin/fpdf/fpdf_bmp/
16
+ $bfOffBits=$this->_fourbytes2int_le(substr($data,10,4));
17
+ $width=$this->_fourbytes2int_le(substr($data,18,4));
18
+ $height=$this->_fourbytes2int_le(substr($data,22,4));
19
+ $flip = ($height<0);
20
+ if ($flip) $height =-$height;
21
+ $biBitCount=$this->_twobytes2int_le(substr($data,28,2));
22
+ $biCompression=$this->_fourbytes2int_le(substr($data,30,4));
23
+ $info = array('w'=>$width, 'h'=>$height);
24
+ if ($biBitCount<16){
25
+ $info['cs'] = 'Indexed';
26
+ $info['bpc'] = $biBitCount;
27
+ $palStr = substr($data,54,($bfOffBits-54));
28
+ $pal = '';
29
+ $cnt = strlen($palStr)/4;
30
+ for ($i=0;$i<$cnt;$i++){
31
+ $n = 4*$i;
32
+ $pal .= $palStr[$n+2].$palStr[$n+1].$palStr[$n];
33
+ }
34
+ $info['pal'] = $pal;
35
+ }
36
+ else{
37
+ $info['cs'] = 'DeviceRGB';
38
+ $info['bpc'] = 8;
39
+ }
40
+
41
+ if ($this->mpdf->restrictColorSpace==1 || $this->mpdf->PDFX || $this->mpdf->restrictColorSpace==3) {
42
+ if (($this->mpdf->PDFA && !$this->mpdf->PDFAauto) || ($this->mpdf->PDFX && !$this->mpdf->PDFXauto)) { $this->mpdf->PDFAXwarnings[] = "Image cannot be converted to suitable colour space for PDFA or PDFX file - ".$file." - (Image replaced by 'no-image'.)"; }
43
+ return array('error' => "BMP Image cannot be converted to suitable colour space - ".$file." - (Image replaced by 'no-image'.)");
44
+ }
45
+
46
+ $biXPelsPerMeter=$this->_fourbytes2int_le(substr($data,38,4)); // horizontal pixels per meter, usually set to zero
47
+ //$biYPelsPerMeter=$this->_fourbytes2int_le(substr($data,42,4)); // vertical pixels per meter, usually set to zero
48
+ $biXPelsPerMeter=round($biXPelsPerMeter/1000 *25.4);
49
+ //$biYPelsPerMeter=round($biYPelsPerMeter/1000 *25.4);
50
+ $info['set-dpi'] = $biXPelsPerMeter;
51
+
52
+ switch ($biCompression){
53
+ case 0:
54
+ $str = substr($data,$bfOffBits);
55
+ break;
56
+ case 1: # BI_RLE8
57
+ $str = $this->rle8_decode(substr($data,$bfOffBits), $width);
58
+ break;
59
+ case 2: # BI_RLE4
60
+ $str = $this->rle4_decode(substr($data,$bfOffBits), $width);
61
+ break;
62
+ }
63
+ $bmpdata = '';
64
+ $padCnt = (4-ceil(($width/(8/$biBitCount)))%4)%4;
65
+ switch ($biBitCount){
66
+ case 1:
67
+ case 4:
68
+ case 8:
69
+ $w = floor($width/(8/$biBitCount)) + ($width%(8/$biBitCount)?1:0);
70
+ $w_row = $w + $padCnt;
71
+ if ($flip){
72
+ for ($y=0;$y<$height;$y++){
73
+ $y0 = $y*$w_row;
74
+ for ($x=0;$x<$w;$x++)
75
+ $bmpdata .= $str[$y0+$x];
76
+ }
77
+ }else{
78
+ for ($y=$height-1;$y>=0;$y--){
79
+ $y0 = $y*$w_row;
80
+ for ($x=0;$x<$w;$x++)
81
+ $bmpdata .= $str[$y0+$x];
82
+ }
83
+ }
84
+ break;
85
+
86
+ case 16:
87
+ $w_row = $width*2 + $padCnt;
88
+ if ($flip){
89
+ for ($y=0;$y<$height;$y++){
90
+ $y0 = $y*$w_row;
91
+ for ($x=0;$x<$width;$x++){
92
+ $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
93
+ $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7128;
94
+ $bmpdata .= chr($r) . chr($g) . chr($b);
95
+ }
96
+ }
97
+ }else{
98
+ for ($y=$height-1;$y>=0;$y--){
99
+ $y0 = $y*$w_row;
100
+ for ($x=0;$x<$width;$x++){
101
+ $n = (ord( $str[$y0 + 2*$x + 1])*256 + ord( $str[$y0 + 2*$x]));
102
+ $b = ($n & 31)<<3; $g = ($n & 992)>>2; $r = ($n & 31744)>>7;
103
+ $bmpdata .= chr($r) . chr($g) . chr($b);
104
+ }
105
+ }
106
+ }
107
+ break;
108
+
109
+ case 24:
110
+ case 32:
111
+ $byteCnt = $biBitCount/8;
112
+ $w_row = $width*$byteCnt + $padCnt;
113
+
114
+ if ($flip){
115
+ for ($y=0;$y<$height;$y++){
116
+ $y0 = $y*$w_row;
117
+ for ($x=0;$x<$width;$x++){
118
+ $i = $y0 + $x*$byteCnt ; # + 1
119
+ $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
120
+ }
121
+ }
122
+ }else{
123
+ for ($y=$height-1;$y>=0;$y--){
124
+ $y0 = $y*$w_row;
125
+ for ($x=0;$x<$width;$x++){
126
+ $i = $y0 + $x*$byteCnt ; # + 1
127
+ $bmpdata .= $str[$i+2].$str[$i+1].$str[$i];
128
+ }
129
+ }
130
+ }
131
+ break;
132
+
133
+ default:
134
+ return array('error' => 'Error parsing BMP image - Unsupported image biBitCount');
135
+ }
136
+ if ($this->mpdf->compress) {
137
+ $bmpdata=gzcompress($bmpdata);
138
+ $info['f']='FlateDecode';
139
+ }
140
+ $info['data']=$bmpdata;
141
+ $info['type']='bmp';
142
+ return $info;
143
+ }
144
+
145
+ function _fourbytes2int_le($s) {
146
+ //Read a 4-byte integer from string
147
+ return (ord($s[3])<<24) + (ord($s[2])<<16) + (ord($s[1])<<8) + ord($s[0]);
148
+ }
149
+
150
+ function _twobytes2int_le($s) {
151
+ //Read a 2-byte integer from string
152
+ return (ord(substr($s, 1, 1))<<8) + ord(substr($s, 0, 1));
153
+ }
154
+
155
+
156
+ # Decoder for RLE8 compression in windows bitmaps
157
+ # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
158
+ function rle8_decode ($str, $width){
159
+ $lineWidth = $width + (3 - ($width-1) % 4);
160
+ $out = '';
161
+ $cnt = strlen($str);
162
+ for ($i=0;$i<$cnt;$i++){
163
+ $o = ord($str[$i]);
164
+ switch ($o){
165
+ case 0: # ESCAPE
166
+ $i++;
167
+ switch (ord($str[$i])){
168
+ case 0: # NEW LINE
169
+ $padCnt = $lineWidth - strlen($out)%$lineWidth;
170
+ if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
171
+ break;
172
+ case 1: # END OF FILE
173
+ $padCnt = $lineWidth - strlen($out)%$lineWidth;
174
+ if ($padCnt<$lineWidth) $out .= str_repeat(chr(0), $padCnt); # pad line
175
+ break 3;
176
+ case 2: # DELTA
177
+ $i += 2;
178
+ break;
179
+ default: # ABSOLUTE MODE
180
+ $num = ord($str[$i]);
181
+ for ($j=0;$j<$num;$j++)
182
+ $out .= $str[++$i];
183
+ if ($num % 2) $i++;
184
+ }
185
+ break;
186
+ default:
187
+ $out .= str_repeat($str[++$i], $o);
188
+ }
189
+ }
190
+ return $out;
191
+ }
192
+
193
+ # Decoder for RLE4 compression in windows bitmaps
194
+ # see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_6x0u.asp
195
+ function rle4_decode ($str, $width){
196
+ $w = floor($width/2) + ($width % 2);
197
+ $lineWidth = $w + (3 - ( ($width-1) / 2) % 4);
198
+ $pixels = array();
199
+ $cnt = strlen($str);
200
+ for ($i=0;$i<$cnt;$i++){
201
+ $o = ord($str[$i]);
202
+ switch ($o){
203
+ case 0: # ESCAPE
204
+ $i++;
205
+ switch (ord($str[$i])){
206
+ case 0: # NEW LINE
207
+ while (count($pixels)%$lineWidth!=0)
208
+ $pixels[]=0;
209
+ break;
210
+ case 1: # END OF FILE
211
+ while (count($pixels)%$lineWidth!=0)
212
+ $pixels[]=0;
213
+ break 3;
214
+ case 2: # DELTA
215
+ $i += 2;
216
+ break;
217
+ default: # ABSOLUTE MODE
218
+ $num = ord($str[$i]);
219
+ for ($j=0;$j<$num;$j++){
220
+ if ($j%2==0){
221
+ $c = ord($str[++$i]);
222
+ $pixels[] = ($c & 240)>>4;
223
+ } else
224
+ $pixels[] = $c & 15;
225
+ }
226
+ if ($num % 2) $i++;
227
+ }
228
+ break;
229
+ default:
230
+ $c = ord($str[++$i]);
231
+ for ($j=0;$j<$o;$j++)
232
+ $pixels[] = ($j%2==0 ? ($c & 240)>>4 : $c & 15);
233
+ }
234
+ }
235
+
236
+ $out = '';
237
+ if (count($pixels)%2) $pixels[]=0;
238
+ $cnt = count($pixels)/2;
239
+ for ($i=0;$i<$cnt;$i++)
240
+ $out .= chr(16*$pixels[2*$i] + $pixels[2*$i+1]);
241
+ return $out;
242
+ }
243
+
244
+
245
+
246
+ }
247
+
248
+ ?>
lib/mpdf/classes/cssmgr.php ADDED
@@ -0,0 +1,1721 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class cssmgr {
4
+
5
+ var $mpdf = null;
6
+
7
+ var $tablecascadeCSS;
8
+ var $cascadeCSS;
9
+ var $CSS;
10
+ var $tbCSSlvl;
11
+
12
+
13
+ function cssmgr(&$mpdf) {
14
+ $this->mpdf = $mpdf;
15
+ $this->tablecascadeCSS = array();
16
+ $this->CSS=array();
17
+ $this->cascadeCSS = array();
18
+ $this->tbCSSlvl = 0;
19
+ }
20
+
21
+ function ReadCSS($html) {
22
+ preg_match_all('/<style[^>]*media=["\']([^"\'>]*)["\'].*?<\/style>/is',$html,$m);
23
+ for($i=0; $i<count($m[0]); $i++) {
24
+ if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
25
+ $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
26
+ }
27
+ }
28
+ preg_match_all('/<link[^>]*media=["\']([^"\'>]*)["\'].*?>/is',$html,$m);
29
+ for($i=0; $i<count($m[0]); $i++) {
30
+ if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
31
+ $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$html);
32
+ }
33
+ }
34
+
35
+ // mPDF 5.5.02
36
+ // Remove Comment tags <!-- ... --> inside CSS as <style> in HTML document
37
+ // Remove Comment tags /* ... */ inside CSS as <style> in HTML document
38
+ // But first, we replace upper and mixed case closing style tag with lower
39
+ // case so we can use str_replace later.
40
+ preg_replace('/<\/style>/i', '</style>', $html);
41
+ preg_match_all('/<style.*?>(.*?)<\/style>/si',$html,$m);
42
+ if (count($m[1])) {
43
+ for($i=0;$i<count($m[1]);$i++) {
44
+ // Remove comment tags
45
+ $sub = preg_replace('/(<\!\-\-|\-\->)/s',' ',$m[1][$i]);
46
+ $sub = '>'.preg_replace('|/\*.*?\*/|s',' ',$sub).'</style>';
47
+ $html = str_replace('>'.$m[1][$i].'</style>', $sub, $html);
48
+ }
49
+ }
50
+
51
+
52
+ $html = preg_replace('/<!--mpdf/i','',$html);
53
+ $html = preg_replace('/mpdf-->/i','',$html);
54
+ $html = preg_replace('/<\!\-\-.*?\-\->/s',' ',$html);
55
+
56
+ $match = 0; // no match for instance
57
+ $regexp = ''; // This helps debugging: showing what is the REAL string being processed
58
+ $CSSext = array();
59
+
60
+ //CSS inside external files
61
+ $regexp = '/<link[^>]*rel=["\']stylesheet["\'][^>]*href=["\']([^>"\']*)["\'].*?>/si';
62
+ $x = preg_match_all($regexp,$html,$cxt);
63
+ if ($x) {
64
+ $match += $x;
65
+ $CSSext = $cxt[1];
66
+ }
67
+ $regexp = '/<link[^>]*href=["\']([^>"\']*)["\'][^>]*?rel=["\']stylesheet["\'].*?>/si';
68
+ $x = preg_match_all($regexp,$html,$cxt);
69
+ if ($x) {
70
+ $match += $x;
71
+ $CSSext = array_merge($CSSext,$cxt[1]);
72
+ }
73
+
74
+ // look for @import stylesheets
75
+ //$regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css)[\'\"]{0,1}\)/si';
76
+ $regexp = '/@import url\([\'\"]{0,1}([^\)]*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
77
+ $x = preg_match_all($regexp,$html,$cxt);
78
+ if ($x) {
79
+ $match += $x;
80
+ $CSSext = array_merge($CSSext,$cxt[1]);
81
+ }
82
+
83
+ // look for @import without the url()
84
+ //$regexp = '/@import [\'\"]{0,1}([^;]*?\.css)[\'\"]{0,1}/si';
85
+ $regexp = '/@import [\'\"]{0,1}([^;]*?\.css(\?\S+)?)[\'\"]{0,1}/si';
86
+ $x = preg_match_all($regexp,$html,$cxt);
87
+ if ($x) {
88
+ $match += $x;
89
+ $CSSext = array_merge($CSSext,$cxt[1]);
90
+ }
91
+
92
+ $ind = 0;
93
+ $CSSstr = '';
94
+
95
+ if (!is_array($this->cascadeCSS)) $this->cascadeCSS = array();
96
+
97
+ while($match){
98
+ $path = $CSSext[$ind];
99
+
100
+ $path = htmlspecialchars_decode($path); // mPDF 6
101
+
102
+ $this->mpdf->GetFullPath($path);
103
+ $CSSextblock = $this->mpdf->_get_file($path);
104
+ if ($CSSextblock) {
105
+ // look for embedded @import stylesheets in other stylesheets
106
+ // and fix url paths (including background-images) relative to stylesheet
107
+ //$regexpem = '/@import url\([\'\"]{0,1}(.*?\.css)[\'\"]{0,1}\)/si';
108
+ $regexpem = '/@import url\([\'\"]{0,1}(.*?\.css(\?\S+)?)[\'\"]{0,1}\)/si';
109
+ $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
110
+ $cssBasePath = preg_replace('/\/[^\/]*$/','',$path) . '/';
111
+ if ($xem) {
112
+ foreach($cxtem[1] AS $cxtembedded) {
113
+ // path is relative to original stlyesheet!!
114
+ $this->mpdf->GetFullPath($cxtembedded, $cssBasePath );
115
+ $match++;
116
+ $CSSext[] = $cxtembedded;
117
+ }
118
+ }
119
+ $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
120
+ $xem = preg_match_all($regexpem,$CSSextblock,$cxtem);
121
+ if ($xem) {
122
+ for ($i=0;$i<count($cxtem[0]);$i++) {
123
+ // path is relative to original stlyesheet!!
124
+ $embedded = $cxtem[2][$i];
125
+ if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
126
+ $this->mpdf->GetFullPath($embedded, $cssBasePath );
127
+ $CSSextblock = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $CSSextblock);
128
+ }
129
+ }
130
+ }
131
+ $CSSstr .= ' '.$CSSextblock;
132
+ }
133
+ $match--;
134
+ $ind++;
135
+ } //end of match
136
+
137
+ $match = 0; // reset value, if needed
138
+ // CSS as <style> in HTML document
139
+ $regexp = '/<style.*?>(.*?)<\/style>/si';
140
+ $match = preg_match_all($regexp,$html,$CSSblock);
141
+ if ($match) {
142
+ $tmpCSSstr = implode(' ',$CSSblock[1]);
143
+ $regexpem = '/(background[^;]*url\s*\(\s*[\'\"]{0,1})([^\)\'\"]*)([\'\"]{0,1}\s*\))/si';
144
+ $xem = preg_match_all($regexpem,$tmpCSSstr ,$cxtem);
145
+ if ($xem) {
146
+ for ($i=0;$i<count($cxtem[0]);$i++) {
147
+ $embedded = $cxtem[2][$i];
148
+ if (!preg_match('/^data:image/i', $embedded)) { // mPDF 5.5.13
149
+ $this->mpdf->GetFullPath($embedded);
150
+ $tmpCSSstr = preg_replace('/'.preg_quote($cxtem[0][$i],'/').'/', ($cxtem[1][$i].$embedded.$cxtem[3][$i]), $tmpCSSstr );
151
+ }
152
+ }
153
+ }
154
+ $CSSstr .= ' '.$tmpCSSstr;
155
+ }
156
+ // Remove comments
157
+ $CSSstr = preg_replace('|/\*.*?\*/|s',' ',$CSSstr);
158
+ $CSSstr = preg_replace('/[\s\n\r\t\f]/s',' ',$CSSstr);
159
+
160
+ if (preg_match('/@media/',$CSSstr)) {
161
+ preg_match_all('/@media(.*?)\{(([^\{\}]*\{[^\{\}]*\})+)\s*\}/is',$CSSstr,$m);
162
+ for($i=0; $i<count($m[0]); $i++) {
163
+ if ($this->mpdf->CSSselectMedia && !preg_match('/('.trim($this->mpdf->CSSselectMedia).'|all)/i',$m[1][$i])) {
164
+ $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/','',$CSSstr);
165
+ }
166
+ else {
167
+ $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/',' '.$m[2][$i].' ',$CSSstr);
168
+ }
169
+ }
170
+ }
171
+
172
+ // Replace any background: url(data:image... with temporary image file reference
173
+ preg_match_all("/(url\(data:image\/(jpeg|gif|png);base64,(.*?)\))/si", $CSSstr, $idata); // mPDF 5.7.2
174
+ if (count($idata[0])) {
175
+ for($i=0;$i<count($idata[0]);$i++) {
176
+ $file = _MPDF_TEMP_PATH.'_tempCSSidata'.RAND(1,10000).'_'.$i.'.'.$idata[2][$i];
177
+ //Save to local file
178
+ file_put_contents($file, base64_decode($idata[3][$i]));
179
+ // $this->mpdf->GetFullPath($file); // ? is this needed - NO mPDF 5.6.03
180
+ $CSSstr = str_replace($idata[0][$i], 'url("'.$file.'")', $CSSstr); // mPDF 5.5.17
181
+ }
182
+ }
183
+
184
+ $CSSstr = preg_replace('/(<\!\-\-|\-\->)/s',' ',$CSSstr);
185
+
186
+ // mPDF 5.7.4 URLs
187
+ // Characters "(" ")" and ";" in url() e.g. background-image, cause problems parsing the CSS string
188
+ // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
189
+ // with a segment delimiter in the URI)
190
+ $tempmarker = '%ZZ';
191
+ if (strpos($CSSstr,'url(')!==false) {
192
+ preg_match_all( '/url\(\"(.*?)\"\)/', $CSSstr, $m);
193
+ for($i = 0; $i < count($m[1]) ; $i++) {
194
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
195
+ $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
196
+ }
197
+ preg_match_all( '/url\(\'(.*?)\'\)/', $CSSstr, $m);
198
+ for($i = 0; $i < count($m[1]) ; $i++) {
199
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
200
+ $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
201
+ }
202
+ preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $CSSstr, $m);
203
+ for($i = 0; $i < count($m[1]) ; $i++) {
204
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
205
+ $CSSstr = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $CSSstr);
206
+ }
207
+ }
208
+
209
+
210
+
211
+ if ($CSSstr ) {
212
+ $classproperties = array(); // mPDF 6
213
+ preg_match_all('/(.*?)\{(.*?)\}/',$CSSstr,$styles);
214
+ for($i=0; $i < count($styles[1]) ; $i++) {
215
+ // SET array e.g. $classproperties['COLOR'] = '#ffffff';
216
+ $stylestr= trim($styles[2][$i]);
217
+ $stylearr = explode(';',$stylestr);
218
+ foreach($stylearr AS $sta) {
219
+ if (trim($sta)) {
220
+ // Changed to allow style="background: url('http://www.bpm1.com/bg.jpg')"
221
+ $tmp = explode(':',$sta,2);
222
+ $property = $tmp[0];
223
+ if (isset($tmp[1])) { $value = $tmp[1]; }
224
+ else { $value = ''; }
225
+ $value = str_replace($tempmarker,';',$value); // mPDF 5.7.4 URLs
226
+ $property = trim($property);
227
+ $value = preg_replace('/\s*!important/i','',$value);
228
+ $value = trim($value);
229
+ if ($property && ($value || $value==='0')) {
230
+ // Ignores -webkit-gradient so doesn't override -moz-
231
+ if ((strtoupper($property)=='BACKGROUND-IMAGE' || strtoupper($property)=='BACKGROUND') && preg_match('/-webkit-gradient/i',$value)) {
232
+ continue;
233
+ }
234
+ $classproperties[strtoupper($property)] = $value;
235
+ }
236
+ }
237
+ }
238
+ $classproperties = $this->fixCSS($classproperties);
239
+ $tagstr = strtoupper(trim($styles[1][$i]));
240
+ $tagarr = explode(',',$tagstr);
241
+ $pageselectors = false; // used to turn on $this->mpdf->mirrorMargins
242
+ foreach($tagarr AS $tg) {
243
+ // mPDF 5.7.4
244
+ if (preg_match('/NTH-CHILD\((\s*(([\-+]?\d*)N(\s*[\-+]\s*\d+)?|[\-+]?\d+|ODD|EVEN)\s*)\)/',$tg,$m) ) {
245
+ $tg = preg_replace('/NTH-CHILD\(.*\)/', 'NTH-CHILD('.str_replace(' ','',$m[1]).')', $tg);
246
+ }
247
+ $tags = preg_split('/\s+/',trim($tg));
248
+ $level = count($tags);
249
+ $t = '';
250
+ $t2 = '';
251
+ $t3 = '';
252
+ if (trim($tags[0])=='@PAGE') {
253
+ if (isset($tags[0])) { $t = trim($tags[0]); }
254
+ if (isset($tags[1])) { $t2 = trim($tags[1]); }
255
+ if (isset($tags[2])) { $t3 = trim($tags[2]); }
256
+ $tag = '';
257
+ if ($level==1) { $tag = $t; }
258
+ else if ($level==2 && preg_match('/^[:](.*)$/',$t2,$m)) {
259
+ $tag = $t.'>>PSEUDO>>'.$m[1];
260
+ if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
261
+ }
262
+ else if ($level==2) { $tag = $t.'>>NAMED>>'.$t2; }
263
+ else if ($level==3 && preg_match('/^[:](.*)$/',$t3,$m)) {
264
+ $tag = $t.'>>NAMED>>'.$t2.'>>PSEUDO>>'.$m[1];
265
+ if ($m[1]=='LEFT' || $m[1]=='RIGHT') { $pageselectors = true; } // used to turn on $this->mpdf->mirrorMargins
266
+ }
267
+ if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
268
+ else if ($tag) { $this->CSS[$tag] = $classproperties; }
269
+ }
270
+
271
+ else if ($level == 1) { // e.g. p or .class or #id or p.class or p#id
272
+ if (isset($tags[0])) { $t = trim($tags[0]); }
273
+ if ($t) {
274
+ $tag = '';
275
+ if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
276
+ else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
277
+ else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
278
+ else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
279
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
280
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
281
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
282
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
283
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
284
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
285
+ if (isset($this->CSS[$tag]) && $tag) { $this->CSS[$tag] = $this->array_merge_recursive_unique($this->CSS[$tag], $classproperties); }
286
+ else if ($tag) { $this->CSS[$tag] = $classproperties; }
287
+ }
288
+ }
289
+ else {
290
+ $tmp = array();
291
+ for($n=0;$n<$level;$n++) {
292
+ if (isset($tags[$n])) { $t = trim($tags[$n]); }
293
+ else { $t = ''; }
294
+ if ($t) {
295
+ $tag = '';
296
+ if (preg_match('/^[.](.*)$/',$t,$m)) { $tag = 'CLASS>>'.$m[1]; }
297
+ else if (preg_match('/^[#](.*)$/',$t,$m)) { $tag = 'ID>>'.$m[1]; }
298
+ else if (preg_match('/^\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
299
+ else if (preg_match('/^:LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = 'LANG>>'.strtolower($m[1]); } // mPDF 6 Special case for lang as attribute selector
300
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[.](.*)$/',$t,$m)) { $tag = $m[1].'>>CLASS>>'.$m[2]; }
301
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\s*:NTH-CHILD\((.*)\)$/',$t,$m)) { $tag = $m[1].'>>SELECTORNTHCHILD>>'.$m[2]; }
302
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')[#](.*)$/',$t,$m)) { $tag = $m[1].'>>ID>>'.$m[2]; }
303
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')\[LANG=[\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\]$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
304
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.'):LANG\([\'\"]{0,1}([A-Z\-]{2,11})[\'\"]{0,1}\)$/',$t,$m)) { $tag = $m[1].'>>LANG>>'.strtolower($m[2]); } // mPDF 6 Special case for lang as attribute selector
305
+ else if (preg_match('/^('.$this->mpdf->allowedCSStags.')$/',$t)) { $tag= $t; }
306
+
307
+ if ($tag) $tmp[] = $tag;
308
+ else { break; }
309
+ }
310
+ }
311
+
312
+ if ($tag) {
313
+ $x = &$this->cascadeCSS;
314
+ foreach($tmp AS $tp) { $x = &$x[$tp]; }
315
+ $x = $this->array_merge_recursive_unique($x, $classproperties);
316
+ $x['depth'] = $level;
317
+ }
318
+ }
319
+ }
320
+ if ($pageselectors) { $this->mpdf->mirrorMargins = true; }
321
+ $properties = array();
322
+ $values = array();
323
+ $classproperties = array();
324
+ }
325
+ } // end of if
326
+ //Remove CSS (tags and content), if any
327
+ $regexp = '/<style.*?>(.*?)<\/style>/si'; // it can be <style> or <style type="txt/css">
328
+ $html = preg_replace($regexp,'',$html);
329
+ //print_r($this->CSS); exit;
330
+ //print_r($this->cascadeCSS); exit;
331
+ return $html;
332
+ }
333
+
334
+
335
+
336
+ function readInlineCSS($html) {
337
+ $html=htmlspecialchars_decode($html); // mPDF 5.7.4 URLs
338
+ // mPDF 5.7.4 URLs
339
+ // Characters "(" ")" and ";" in url() e.g. background-image, cause probems parsing the CSS string
340
+ // URLencode ( and ), but change ";" to a code which can be converted back after parsing (so as not to confuse ;
341
+ // with a segment delimiter in the URI)
342
+ $tempmarker = '%ZZ';
343
+ if (strpos($html,'url(')!==false) {
344
+ preg_match_all( '/url\(\"(.*?)\"\)/', $html, $m);
345
+ for($i = 0; $i < count($m[1]) ; $i++) {
346
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
347
+ $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
348
+ }
349
+ preg_match_all( '/url\(\'(.*?)\'\)/', $html, $m);
350
+ for($i = 0; $i < count($m[1]) ; $i++) {
351
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
352
+ $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
353
+ }
354
+ preg_match_all( '/url\(([^\'\"].*?[^\'\"])\)/', $html, $m);
355
+ for($i = 0; $i < count($m[1]) ; $i++) {
356
+ $tmp = str_replace(array('(',')',';'),array('%28','%29',$tempmarker),$m[1][$i]);
357
+ $html = preg_replace('/'.preg_quote($m[0][$i],'/').'/', 'url(\''.$tmp.'\')', $html);
358
+ }
359
+ }
360
+ //Fix incomplete CSS code
361
+ $size = strlen($html)-1;
362
+ if (substr($html,$size,1) != ';') $html .= ';';
363
+ //Make CSS[Name-of-the-class] = array(key => value)
364
+ $regexp = '|\\s*?(\\S+?):(.+?);|i';
365
+ preg_match_all( $regexp, $html, $styleinfo);
366
+ $properties = $styleinfo[1];
367
+ $values = $styleinfo[2];
368
+ //Array-properties and Array-values must have the SAME SIZE!
369
+ $classproperties = array();
370
+ for($i = 0; $i < count($properties) ; $i++) {
371
+ // Ignores -webkit-gradient so doesn't override -moz-
372
+ if ((strtoupper($properties[$i])=='BACKGROUND-IMAGE' || strtoupper($properties[$i])=='BACKGROUND') && preg_match('/-webkit-gradient/i',$values[$i])) {
373
+ continue;
374
+ }
375
+ $values[$i] = str_replace($tempmarker,';',$values[$i]); // mPDF 5.7.4 URLs
376
+ $classproperties[strtoupper($properties[$i])] = trim($values[$i]);
377
+ }
378
+ return $this->fixCSS($classproperties);
379
+ }
380
+
381
+
382
+
383
+ function _fix_borderStr($bd) {
384
+ preg_match_all("/\((.*?)\)/", $bd, $m);
385
+ if (count($m[1])) {
386
+ for($i=0;$i<count($m[1]);$i++) {
387
+ $sub = preg_replace("/ /", "", $m[1][$i]);
388
+ $bd = preg_replace('/'.preg_quote($m[1][$i], '/').'/si', $sub, $bd);
389
+ }
390
+ }
391
+
392
+ $prop = preg_split('/\s+/',trim($bd));
393
+ $w = 'medium';
394
+ $c = '#000000';
395
+ $s = 'none';
396
+
397
+ if ( count($prop) == 1 ) {
398
+ // solid
399
+ if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; }
400
+ // #000000
401
+ else if (is_array($this->mpdf->ConvertColor($prop[0]))) { $c = $prop[0]; }
402
+ // 1px
403
+ else { $w = $prop[0]; }
404
+ }
405
+ else if (count($prop) == 2 ) {
406
+ // 1px solid
407
+ if (in_array($prop[1],$this->mpdf->borderstyles) || $prop[1] == 'none' || $prop[1] == 'hidden' ) { $w = $prop[0]; $s = $prop[1]; }
408
+ // solid #000000
409
+ else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) { $s = $prop[0]; $c = $prop[1]; }
410
+ // 1px #000000
411
+ else { $w = $prop[0]; $c = $prop[1]; }
412
+ }
413
+ else if ( count($prop) == 3 ) {
414
+ // Change #000000 1px solid to 1px solid #000000 (proper)
415
+ if (substr($prop[0],0,1) == '#') { $c = $prop[0]; $w = $prop[1]; $s = $prop[2]; }
416
+ // Change solid #000000 1px to 1px solid #000000 (proper)
417
+ else if (substr($prop[0],1,1) == '#') { $s = $prop[0]; $c = $prop[1]; $w = $prop[2]; }
418
+ // Change solid 1px #000000 to 1px solid #000000 (proper)
419
+ else if (in_array($prop[0],$this->mpdf->borderstyles) || $prop[0] == 'none' || $prop[0] == 'hidden' ) {
420
+ $s = $prop[0]; $w = $prop[1]; $c = $prop[2];
421
+ }
422
+ else { $w = $prop[0]; $s = $prop[1]; $c = $prop[2]; }
423
+ }
424
+ else { return ''; }
425
+ $s = strtolower($s);
426
+ return $w.' '.$s.' '.$c;
427
+ }
428
+
429
+
430
+
431
+ function fixCSS($prop) {
432
+ if (!is_array($prop) || (count($prop)==0)) return array();
433
+ $newprop = array();
434
+ foreach($prop AS $k => $v) {
435
+ if ($k != 'BACKGROUND-IMAGE' && $k != 'BACKGROUND' && $k != 'ODD-HEADER-NAME' && $k != 'EVEN-HEADER-NAME' && $k != 'ODD-FOOTER-NAME' && $k != 'EVEN-FOOTER-NAME' && $k != 'HEADER' && $k != 'FOOTER') {
436
+ $v = strtolower($v);
437
+ }
438
+
439
+ if ($k == 'FONT') {
440
+ $s = trim($v);
441
+ preg_match_all('/\"(.*?)\"/',$s,$ff);
442
+ if (count($ff[1])) {
443
+ foreach($ff[1] AS $ffp) {
444
+ $w = preg_split('/\s+/',$ffp);
445
+ $s = preg_replace('/\"'.$ffp.'\"/',$w[0],$s);
446
+ }
447
+ }
448
+ preg_match_all('/\'(.*?)\'/',$s,$ff);
449
+ if (count($ff[1])) {
450
+ foreach($ff[1] AS $ffp) {
451
+ $w = preg_split('/\s+/',$ffp);
452
+ $s = preg_replace('/\''.$ffp.'\'/',$w[0],$s);
453
+ }
454
+ }
455
+ $s = preg_replace('/\s*,\s*/',',',$s);
456
+ $bits = preg_split('/\s+/',$s);
457
+ if (count($bits)>1) {
458
+ $k = 'FONT-FAMILY'; $v = $bits[(count($bits)-1)];
459
+ $fs = $bits[(count($bits)-2)];
460
+ if (preg_match('/(.*?)\/(.*)/',$fs, $fsp)) {
461
+ $newprop['FONT-SIZE'] = $fsp[1];
462
+ $newprop['LINE-HEIGHT'] = $fsp[2];
463
+ }
464
+ else { $newprop['FONT-SIZE'] = $fs; }
465
+ if (preg_match('/(italic|oblique)/i',$s)) { $newprop['FONT-STYLE'] = 'italic'; }
466
+ else { $newprop['FONT-STYLE'] = 'normal'; }
467
+ if (preg_match('/bold/i',$s)) { $newprop['FONT-WEIGHT'] = 'bold'; }
468
+ else { $newprop['FONT-WEIGHT'] = 'normal'; }
469
+ if (preg_match('/small-caps/i',$s)) { $newprop['TEXT-TRANSFORM'] = 'uppercase'; }
470
+ }
471
+ }
472
+ else if ($k == 'FONT-FAMILY') {
473
+ $aux_fontlist = explode(",",$v);
474
+ $found = 0;
475
+ foreach($aux_fontlist AS $f) {
476
+ $fonttype = trim($f);
477
+ $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
478
+ $fonttype = preg_replace('/ /','',$fonttype);
479
+ $v = strtolower(trim($fonttype));
480
+ if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
481
+ if ((!$this->mpdf->onlyCoreFonts && in_array($v,$this->mpdf->available_unifonts)) ||
482
+ in_array($v,array('ccourier','ctimes','chelvetica')) ||
483
+ ($this->mpdf->onlyCoreFonts && in_array($v,array('courier','times','helvetica','arial'))) ||
484
+ in_array($v, array('sjis','uhc','big5','gb'))) {
485
+ $newprop[$k] = $v;
486
+ $found = 1;
487
+ break;
488
+ }
489
+ }
490
+ if (!$found) {
491
+ foreach($aux_fontlist AS $f) {
492
+ $fonttype = trim($f);
493
+ $fonttype = preg_replace('/["\']*(.*?)["\']*/','\\1',$fonttype);
494
+ $fonttype = preg_replace('/ /','',$fonttype);
495
+ $v = strtolower(trim($fonttype));
496
+ if (isset($this->mpdf->fonttrans[$v]) && $this->mpdf->fonttrans[$v]) { $v = $this->mpdf->fonttrans[$v]; }
497
+ if (in_array($v,$this->mpdf->sans_fonts) || in_array($v,$this->mpdf->serif_fonts) || in_array($v,$this->mpdf->mono_fonts) ) {
498
+ $newprop[$k] = $v;
499
+ break;
500
+ }
501
+ }
502
+ }
503
+ }
504
+ // mPDF 5.7.1
505
+ else if ($k == 'FONT-VARIANT') {
506
+ if (preg_match('/(normal|none)/',$v, $m)) { // mPDF 6
507
+ $newprop['FONT-VARIANT-LIGATURES'] = $m[1];
508
+ $newprop['FONT-VARIANT-CAPS'] = $m[1];
509
+ $newprop['FONT-VARIANT-NUMERIC'] = $m[1];
510
+ $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
511
+ }
512
+ else {
513
+ if (preg_match_all('/(no-common-ligatures|\bcommon-ligatures|no-discretionary-ligatures|\bdiscretionary-ligatures|no-historical-ligatures|\bhistorical-ligatures|no-contextual|\bcontextual)/i',$v, $m)) {
514
+ $newprop['FONT-VARIANT-LIGATURES'] = implode(' ',$m[1]);
515
+ }
516
+ if (preg_match('/(all-small-caps|\bsmall-caps|all-petite-caps|\bpetite-caps|unicase|titling-caps)/i',$v, $m)) {
517
+ $newprop['FONT-VARIANT-CAPS'] = $m[1];
518
+ }
519
+ if (preg_match_all('/(lining-nums|oldstyle-nums|proportional-nums|tabular-nums|diagonal-fractions|stacked-fractions)/i',$v, $m)) {
520
+ $newprop['FONT-VARIANT-NUMERIC'] = implode(' ',$m[1]);
521
+ }
522
+ if (preg_match('/(historical-forms)/i',$v, $m)) {
523
+ $newprop['FONT-VARIANT-ALTERNATES'] = $m[1];
524
+ }
525
+ }
526
+ }
527
+ else if ($k == 'MARGIN') {
528
+ $tmp = $this->expand24($v);
529
+ $newprop['MARGIN-TOP'] = $tmp['T'];
530
+ $newprop['MARGIN-RIGHT'] = $tmp['R'];
531
+ $newprop['MARGIN-BOTTOM'] = $tmp['B'];
532
+ $newprop['MARGIN-LEFT'] = $tmp['L'];
533
+ }
534
+ /*-- BORDER-RADIUS --*/
535
+ else if ($k == 'BORDER-RADIUS' || $k == 'BORDER-TOP-LEFT-RADIUS' || $k == 'BORDER-TOP-RIGHT-RADIUS' || $k == 'BORDER-BOTTOM-LEFT-RADIUS' || $k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
536
+ $tmp = $this->border_radius_expand($v,$k);
537
+ if (isset($tmp['TL-H'])) $newprop['BORDER-TOP-LEFT-RADIUS-H'] = $tmp['TL-H'];
538
+ if (isset($tmp['TL-V'])) $newprop['BORDER-TOP-LEFT-RADIUS-V'] = $tmp['TL-V'];
539
+ if (isset($tmp['TR-H'])) $newprop['BORDER-TOP-RIGHT-RADIUS-H'] = $tmp['TR-H'];
540
+ if (isset($tmp['TR-V'])) $newprop['BORDER-TOP-RIGHT-RADIUS-V'] = $tmp['TR-V'];
541
+ if (isset($tmp['BL-H'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-H'] = $tmp['BL-H'];
542
+ if (isset($tmp['BL-V'])) $newprop['BORDER-BOTTOM-LEFT-RADIUS-V'] = $tmp['BL-V'];
543
+ if (isset($tmp['BR-H'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-H'] = $tmp['BR-H'];
544
+ if (isset($tmp['BR-V'])) $newprop['BORDER-BOTTOM-RIGHT-RADIUS-V'] = $tmp['BR-V'];
545
+ }
546
+ /*-- END BORDER-RADIUS --*/
547
+ else if ($k == 'PADDING') {
548
+ $tmp = $this->expand24($v);
549
+ $newprop['PADDING-TOP'] = $tmp['T'];
550
+ $newprop['PADDING-RIGHT'] = $tmp['R'];
551
+ $newprop['PADDING-BOTTOM'] = $tmp['B'];
552
+ $newprop['PADDING-LEFT'] = $tmp['L'];
553
+ }
554
+ else if ($k == 'BORDER') {
555
+ if ($v == '1') { $v = '1px solid #000000'; }
556
+ else { $v = $this->_fix_borderStr($v); }
557
+ $newprop['BORDER-TOP'] = $v;
558
+ $newprop['BORDER-RIGHT'] = $v;
559
+ $newprop['BORDER-BOTTOM'] = $v;
560
+ $newprop['BORDER-LEFT'] = $v;
561
+ }
562
+ else if ($k == 'BORDER-TOP') {
563
+ $newprop['BORDER-TOP'] = $this->_fix_borderStr($v);
564
+ }
565
+ else if ($k == 'BORDER-RIGHT') {
566
+ $newprop['BORDER-RIGHT'] = $this->_fix_borderStr($v);
567
+ }
568
+ else if ($k == 'BORDER-BOTTOM') {
569
+ $newprop['BORDER-BOTTOM'] = $this->_fix_borderStr($v);
570
+ }
571
+ else if ($k == 'BORDER-LEFT') {
572
+ $newprop['BORDER-LEFT'] = $this->_fix_borderStr($v);
573
+ }
574
+ else if ($k == 'BORDER-STYLE') {
575
+ $e = $this->expand24($v);
576
+ if (!empty($e)) {
577
+ $newprop['BORDER-TOP-STYLE'] = $e['T'];
578
+ $newprop['BORDER-RIGHT-STYLE'] = $e['R'];
579
+ $newprop['BORDER-BOTTOM-STYLE'] = $e['B'];
580
+ $newprop['BORDER-LEFT-STYLE'] = $e['L'];
581
+ }
582
+ }
583
+ else if ($k == 'BORDER-WIDTH') {
584
+ $e = $this->expand24($v);
585
+ if (!empty($e)) {
586
+ $newprop['BORDER-TOP-WIDTH'] = $e['T'];
587
+ $newprop['BORDER-RIGHT-WIDTH'] = $e['R'];
588
+ $newprop['BORDER-BOTTOM-WIDTH'] = $e['B'];
589
+ $newprop['BORDER-LEFT-WIDTH'] = $e['L'];
590
+ }
591
+ }
592
+ else if ($k == 'BORDER-COLOR') {
593
+ $e = $this->expand24($v);
594
+ if (!empty($e)) {
595
+ $newprop['BORDER-TOP-COLOR'] = $e['T'];
596
+ $newprop['BORDER-RIGHT-COLOR'] = $e['R'];
597
+ $newprop['BORDER-BOTTOM-COLOR'] = $e['B'];
598
+ $newprop['BORDER-LEFT-COLOR'] = $e['L'];
599
+ }
600
+ }
601
+
602
+ else if ($k == 'BORDER-SPACING') {
603
+ $prop = preg_split('/\s+/',trim($v));
604
+ if (count($prop) == 1 ) {
605
+ $newprop['BORDER-SPACING-H'] = $prop[0];
606
+ $newprop['BORDER-SPACING-V'] = $prop[0];
607
+ }
608
+ else if (count($prop) == 2 ) {
609
+ $newprop['BORDER-SPACING-H'] = $prop[0];
610
+ $newprop['BORDER-SPACING-V'] = $prop[1];
611
+ }
612
+ }
613
+ else if ($k == 'TEXT-OUTLINE') { // mPDF 5.6.07
614
+ $prop = preg_split('/\s+/',trim($v));
615
+ if (trim(strtolower($v)) == 'none' ) {
616
+ $newprop['TEXT-OUTLINE'] = 'none';
617
+ }
618
+ else if (count($prop) == 2 ) {
619
+ $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
620
+ $newprop['TEXT-OUTLINE-COLOR'] = $prop[1];
621
+ }
622
+ else if (count($prop) == 3 ) {
623
+ $newprop['TEXT-OUTLINE-WIDTH'] = $prop[0];
624
+ $newprop['TEXT-OUTLINE-COLOR'] = $prop[2];
625
+ }
626
+ }
627
+ else if ($k == 'SIZE') {
628
+ $prop = preg_split('/\s+/',trim($v));
629
+ if (preg_match('/(auto|portrait|landscape)/',$prop[0])) {
630
+ $newprop['SIZE'] = strtoupper($prop[0]);
631
+ }
632
+ else if (count($prop) == 1 ) {
633
+ $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
634
+ $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[0]);
635
+ }
636
+ else if (count($prop) == 2 ) {
637
+ $newprop['SIZE']['W'] = $this->mpdf->ConvertSize($prop[0]);
638
+ $newprop['SIZE']['H'] = $this->mpdf->ConvertSize($prop[1]);
639
+ }
640
+ }
641
+ else if ($k == 'SHEET-SIZE') {
642
+ $prop = preg_split('/\s+/',trim($v));
643
+ if (count($prop) == 2 ) {
644
+ $newprop['SHEET-SIZE'] = array($this->mpdf->ConvertSize($prop[0]), $this->mpdf->ConvertSize($prop[1]));
645
+ }
646
+ else {
647
+ if(preg_match('/([0-9a-zA-Z]*)-L/i',$v,$m)) { // e.g. A4-L = A$ landscape
648
+ $ft = $this->mpdf->_getPageFormat($m[1]);
649
+ $format = array($ft[1],$ft[0]);
650
+ }
651
+ else { $format = $this->mpdf->_getPageFormat($v); }
652
+ if ($format) { $newprop['SHEET-SIZE'] = array($format[0]/_MPDFK, $format[1]/_MPDFK); }
653
+ }
654
+ }
655
+ else if ($k == 'BACKGROUND') {
656
+ $bg = $this->parseCSSbackground($v);
657
+ if ($bg['c']) { $newprop['BACKGROUND-COLOR'] = $bg['c']; }
658
+ else { $newprop['BACKGROUND-COLOR'] = 'transparent'; }
659
+ /*-- BACKGROUNDS --*/
660
+ if ($bg['i']) {
661
+ $newprop['BACKGROUND-IMAGE'] = $bg['i'];
662
+ if ($bg['r']) { $newprop['BACKGROUND-REPEAT'] = $bg['r']; }
663
+ if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
664
+ }
665
+ else { $newprop['BACKGROUND-IMAGE'] = ''; }
666
+ /*-- END BACKGROUNDS --*/
667
+ }
668
+ /*-- BACKGROUNDS --*/
669
+ else if ($k == 'BACKGROUND-IMAGE') {
670
+ if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$v,$m)) {
671
+ $newprop['BACKGROUND-IMAGE'] = $m[0];
672
+ continue;
673
+ }
674
+ if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
675
+ $newprop['BACKGROUND-IMAGE'] = $m[1];
676
+ }
677
+
678
+ else if (strtolower($v)=='none') { $newprop['BACKGROUND-IMAGE'] = ''; }
679
+
680
+ }
681
+ else if ($k == 'BACKGROUND-REPEAT') {
682
+ if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/i',$v,$m)) {
683
+ $newprop['BACKGROUND-REPEAT'] = strtolower($m[1]);
684
+ }
685
+ }
686
+ else if ($k == 'BACKGROUND-POSITION') {
687
+ $s = $v;
688
+ $bits = preg_split('/\s+/',trim($s));
689
+ // These should be Position x1 or x2
690
+ if (count($bits)==1) {
691
+ if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
692
+ else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
693
+ else { $bg['p'] = $bits[0] . ' 50%'; }
694
+ }
695
+ else if (count($bits)==2) {
696
+ // Can be either right center or center right
697
+ if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
698
+ $bg['p'] = $bits[1] . ' '.$bits[0];
699
+ }
700
+ else {
701
+ $bg['p'] = $bits[0] . ' '.$bits[1];
702
+ }
703
+ }
704
+ if ($bg['p']) {
705
+ $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
706
+ $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
707
+ $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
708
+ if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
709
+ $bg['p'] = false;
710
+ }
711
+ }
712
+ if ($bg['p']) { $newprop['BACKGROUND-POSITION'] = $bg['p']; }
713
+ }
714
+ /*-- END BACKGROUNDS --*/
715
+ else if ($k == 'IMAGE-ORIENTATION') {
716
+ if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$v,$m)) {
717
+ $angle = $m[1] + 0;
718
+ if (strtolower($m[2])=='deg') { $angle = $angle; }
719
+ else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
720
+ else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
721
+ while($angle < 0) { $angle += 360; }
722
+ $angle = ($angle % 360);
723
+ $angle /= 90;
724
+ $angle = round($angle) * 90;
725
+ $newprop['IMAGE-ORIENTATION'] = $angle;
726
+ }
727
+ }
728
+ else if ($k == 'TEXT-ALIGN') {
729
+ if (preg_match('/["\'](.){1}["\']/i',$v,$m)) {
730
+ $d = array_search($m[1],$this->mpdf->decimal_align);
731
+ if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
732
+ if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
733
+ else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
734
+ }
735
+ else if (preg_match('/["\'](\\\[a-fA-F0-9]{1,6})["\']/i',$v,$m)) {
736
+ $utf8 = codeHex2utf(substr($m[1],1,6));
737
+ $d = array_search($utf8,$this->mpdf->decimal_align);
738
+ if ($d !== false) { $newprop['TEXT-ALIGN'] = $d; }
739
+ if (preg_match('/(center|left|right)/i',$v,$m)) { $newprop['TEXT-ALIGN'] .= strtoupper(substr($m[1],0,1)); }
740
+ else { $newprop['TEXT-ALIGN'] .= 'R'; } // default = R
741
+ }
742
+ else { $newprop[$k] = $v; }
743
+ }
744
+ // mpDF 6 Lists
745
+ else if ($k == 'LIST-STYLE') {
746
+ if (preg_match('/none/i',$v,$m)) {
747
+ $newprop['LIST-STYLE-TYPE'] = 'none';
748
+ $newprop['LIST-STYLE-IMAGE'] = 'none';
749
+ }
750
+ if (preg_match('/(lower-roman|upper-roman|lower-latin|lower-alpha|upper-latin|upper-alpha|decimal|disc|circle|square|arabic-indic|bengali|devanagari|gujarati|gurmukhi|kannada|malayalam|oriya|persian|tamil|telugu|thai|urdu|cambodian|khmer|lao|cjk-decimal|hebrew)/i',$v,$m)) {
751
+ $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
752
+ }
753
+ else if (preg_match('/U\+([a-fA-F0-9]+)/i',$v,$m)) {
754
+ $newprop['LIST-STYLE-TYPE'] = strtolower(trim($m[1]));
755
+ }
756
+ if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)/i',$v,$m)) {
757
+ $newprop['LIST-STYLE-IMAGE'] = strtolower(trim($m[1]));
758
+ }
759
+ if (preg_match('/(inside|outside)/i',$v,$m)) {
760
+ $newprop['LIST-STYLE-POSITION'] = strtolower(trim($m[1]));
761
+ }
762
+ }
763
+
764
+ else {
765
+ $newprop[$k] = $v;
766
+ }
767
+ }
768
+
769
+ return $newprop;
770
+ }
771
+
772
+ function setCSSboxshadow($v) {
773
+ $sh = array();
774
+ $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
775
+ for($i=0; $i<$c; $i++) {
776
+ $col = preg_replace('/,/','*',$x[0][$i]);
777
+ $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
778
+ }
779
+ $ss = explode(',',$v);
780
+ foreach ($ss AS $s) {
781
+ $new = array('inset'=>false, 'blur'=>0, 'spread'=>0);
782
+ if (preg_match('/inset/i',$s)) { $new['inset'] = true; $s = preg_replace('/\s*inset\s*/','',$s); }
783
+ $p = explode(' ',trim($s));
784
+ if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
785
+ if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false); }
786
+ if (isset($p[2])) {
787
+ if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
788
+ $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
789
+ }
790
+ else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
791
+ if (isset($p[3])) {
792
+ if (preg_match('/^\s*[\.\-0-9]/',$p[3])) {
793
+ $new['spread'] = $this->mpdf->ConvertSize(trim($p[3]),$this->mpdf->blk[$this->mpdf->blklvl-1]['inner_width'],$this->mpdf->FontSize,false);
794
+ }
795
+ else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3])); }
796
+ if (isset($p[4])) {
797
+ $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[4]));
798
+ }
799
+ }
800
+ }
801
+ if (!$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
802
+ if (isset($new['y'])) { array_unshift($sh, $new); }
803
+ }
804
+ return $sh;
805
+ }
806
+
807
+ function setCSStextshadow($v) {
808
+ $sh = array();
809
+ $c = preg_match_all('/(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl)\(.*?\)/',$v,$x); // mPDF 5.6.05
810
+ for($i=0; $i<$c; $i++) {
811
+ $col = preg_replace('/,/','*',$x[0][$i]);
812
+ $v = preg_replace('/'.preg_quote($x[0][$i],'/').'/',$col,$v);
813
+ }
814
+ $ss = explode(',',$v);
815
+ foreach ($ss AS $s) {
816
+ $new = array('blur'=>0);
817
+ $p = explode(' ',trim($s));
818
+ if (isset($p[0])) { $new['x'] = $this->mpdf->ConvertSize(trim($p[0]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
819
+ if (isset($p[1])) { $new['y'] = $this->mpdf->ConvertSize(trim($p[1]),$this->mpdf->FontSize,$this->mpdf->FontSize,false); }
820
+ if (isset($p[2])) {
821
+ if (preg_match('/^\s*[\.\-0-9]/',$p[2])) {
822
+ $new['blur'] = $this->mpdf->ConvertSize(trim($p[2]),$this->mpdf->blk[$this->mpdf->blklvl]['inner_width'],$this->mpdf->FontSize,false);
823
+ }
824
+ else { $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[2])); }
825
+ if (isset($p[3])) {
826
+ $new['col'] = $this->mpdf->ConvertColor(preg_replace('/\*/',',',$p[3]));
827
+ }
828
+ }
829
+ if (!isset($new['col']) || !$new['col']) { $new['col'] = $this->mpdf->ConvertColor('#888888'); }
830
+ if (isset($new['y'])) { array_unshift($sh, $new); }
831
+ }
832
+ return $sh;
833
+ }
834
+
835
+ function parseCSSbackground($s) {
836
+ $bg = array('c'=>false, 'i'=>false, 'r'=>false, 'p'=>false, );
837
+ /*-- BACKGROUNDS --*/
838
+ if (preg_match('/(-moz-)*(repeating-)*(linear|radial)-gradient\(.*\)/i',$s,$m)) {
839
+ $bg['i'] = $m[0];
840
+ }
841
+ else
842
+ /*-- END BACKGROUNDS --*/
843
+ if (preg_match('/url\(/i',$s)) {
844
+ // If color, set and strip it off
845
+ // mPDF 5.6.05
846
+ if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})\s+(url\(.*)/i',$s,$m)) {
847
+ $bg['c'] = strtolower($m[1]);
848
+ $s = $m[3];
849
+ }
850
+ /*-- BACKGROUNDS --*/
851
+ if (preg_match('/url\([\'\"]{0,1}(.*?)[\'\"]{0,1}\)\s*(.*)/i',$s,$m)) {
852
+ $bg['i'] = $m[1];
853
+ $s = strtolower($m[2]);
854
+ if (preg_match('/(repeat-x|repeat-y|no-repeat|repeat)/',$s,$m)) {
855
+ $bg['r'] = $m[1];
856
+ }
857
+ // Remove repeat, attachment (discarded) and also any inherit
858
+ $s = preg_replace('/(repeat-x|repeat-y|no-repeat|repeat|scroll|fixed|inherit)/','',$s);
859
+ $bits = preg_split('/\s+/',trim($s));
860
+ // These should be Position x1 or x2
861
+ if (count($bits)==1) {
862
+ if (preg_match('/bottom/',$bits[0])) { $bg['p'] = '50% 100%'; }
863
+ else if (preg_match('/top/',$bits[0])) { $bg['p'] = '50% 0%'; }
864
+ else { $bg['p'] = $bits[0] . ' 50%'; }
865
+ }
866
+ else if (count($bits)==2) {
867
+ // Can be either right center or center right
868
+ if (preg_match('/(top|bottom)/',$bits[0]) || preg_match('/(left|right)/',$bits[1])) {
869
+ $bg['p'] = $bits[1] . ' '.$bits[0];
870
+ }
871
+ else {
872
+ $bg['p'] = $bits[0] . ' '.$bits[1];
873
+ }
874
+ }
875
+ if ($bg['p']) {
876
+ $bg['p'] = preg_replace('/(left|top)/','0%',$bg['p']);
877
+ $bg['p'] = preg_replace('/(right|bottom)/','100%',$bg['p']);
878
+ $bg['p'] = preg_replace('/(center)/','50%',$bg['p']);
879
+ if (!preg_match('/[\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)* [\-]{0,1}\d+(in|cm|mm|pt|pc|em|ex|px|%)*/',$bg['p'])) {
880
+ $bg['p'] = false;
881
+ }
882
+ }
883
+ }
884
+ /*-- END BACKGROUNDS --*/
885
+ }
886
+ else if (preg_match('/^\s*(#[0-9a-fA-F]{3,6}|(rgba|rgb|device-cmyka|cmyka|device-cmyk|cmyk|hsla|hsl|spot)\(.*?\)|[a-zA-Z]{3,})/i',$s,$m)) { $bg['c'] = strtolower($m[1]); } // mPDF 5.6.05
887
+ return ($bg);
888
+ }
889
+
890
+
891
+ function expand24($mp) {
892
+ $prop = preg_split('/\s+/',trim($mp));
893
+ if (count($prop) == 1 ) {
894
+ return array('T' => $prop[0], 'R' => $prop[0], 'B' => $prop[0], 'L'=> $prop[0]);
895
+ }
896
+ if (count($prop) == 2 ) {
897
+ return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[0], 'L'=> $prop[1]);
898
+ }
899
+
900
+ if (count($prop) == 3 ) {
901
+ return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[1]);
902
+ }
903
+ if (count($prop) == 4 ) {
904
+ return array('T' => $prop[0], 'R' => $prop[1], 'B' => $prop[2], 'L'=> $prop[3]);
905
+ }
906
+ return array();
907
+ }
908
+
909
+ /*-- BORDER-RADIUS --*/
910
+ function border_radius_expand($val,$k) {
911
+ $b = array();
912
+ if ($k == 'BORDER-RADIUS') {
913
+ $hv = explode('/',trim($val));
914
+ $prop = preg_split('/\s+/',trim($hv[0]));
915
+ if (count($prop)==1) {
916
+ $b['TL-H'] = $b['TR-H'] = $b['BR-H'] = $b['BL-H'] = $prop[0];
917
+ }
918
+ else if (count($prop)==2) {
919
+ $b['TL-H'] = $b['BR-H'] = $prop[0];
920
+ $b['TR-H'] = $b['BL-H'] = $prop[1];
921
+ }
922
+ else if (count($prop)==3) {
923
+ $b['TL-H'] = $prop[0];
924
+ $b['TR-H'] = $b['BL-H'] = $prop[1];
925
+ $b['BR-H'] = $prop[2];
926
+ }
927
+ else if (count($prop)==4) {
928
+ $b['TL-H'] = $prop[0];
929
+ $b['TR-H'] = $prop[1];
930
+ $b['BR-H'] = $prop[2];
931
+ $b['BL-H'] = $prop[3];
932
+ }
933
+ if (count($hv)==2) {
934
+ $prop = preg_split('/\s+/',trim($hv[1]));
935
+ if (count($prop)==1) {
936
+ $b['TL-V'] = $b['TR-V'] = $b['BR-V'] = $b['BL-V'] = $prop[0];
937
+ }
938
+ else if (count($prop)==2) {
939
+ $b['TL-V'] = $b['BR-V'] = $prop[0];
940
+ $b['TR-V'] = $b['BL-V'] = $prop[1];
941
+ }
942
+ else if (count($prop)==3) {
943
+ $b['TL-V'] = $prop[0];
944
+ $b['TR-V'] = $b['BL-V'] = $prop[1];
945
+ $b['BR-V'] = $prop[2];
946
+ }
947
+ else if (count($prop)==4) {
948
+ $b['TL-V'] = $prop[0];
949
+ $b['TR-V'] = $prop[1];
950
+ $b['BR-V'] = $prop[2];
951
+ $b['BL-V'] = $prop[3];
952
+ }
953
+ }
954
+ else {
955
+ $b['TL-V'] = $b['TL-H'];
956
+ $b['TR-V'] = $b['TR-H'];
957
+ $b['BL-V'] = $b['BL-H'];
958
+ $b['BR-V'] = $b['BR-H'];
959
+ }
960
+ return $b;
961
+ }
962
+
963
+ // Parse 2
964
+ $h = 0;
965
+ $v = 0;
966
+ $prop = preg_split('/\s+/',trim($val));
967
+ if (count($prop)==1) { $h = $v = $val; }
968
+ else { $h = $prop[0]; $v = $prop[1]; }
969
+ if ($h==0 || $v==0) { $h = $v = 0; }
970
+ if ($k == 'BORDER-TOP-LEFT-RADIUS') {
971
+ $b['TL-H'] = $h;
972
+ $b['TL-V'] = $v;
973
+ }
974
+ else if ($k == 'BORDER-TOP-RIGHT-RADIUS') {
975
+ $b['TR-H'] = $h;
976
+ $b['TR-V'] = $v;
977
+ }
978
+ else if ($k == 'BORDER-BOTTOM-LEFT-RADIUS') {
979
+ $b['BL-H'] = $h;
980
+ $b['BL-V'] = $v;
981
+ }
982
+ else if ($k == 'BORDER-BOTTOM-RIGHT-RADIUS') {
983
+ $b['BR-H'] = $h;
984
+ $b['BR-V'] = $v;
985
+ }
986
+ return $b;
987
+
988
+ }
989
+ /*-- END BORDER-RADIUS --*/
990
+
991
+ function _mergeCSS($p, &$t) {
992
+ // Save Cascading CSS e.g. "div.topic p" at this block level
993
+ if (isset($p) && $p) {
994
+ if ($t) {
995
+ $t = $this->array_merge_recursive_unique($t, $p);
996
+ }
997
+ else { $t = $p; }
998
+ }
999
+ }
1000
+
1001
+ // for CSS handling
1002
+ function array_merge_recursive_unique($array1, $array2) {
1003
+ $arrays = func_get_args();
1004
+ $narrays = count($arrays);
1005
+ $ret = $arrays[0];
1006
+ for ($i = 1; $i < $narrays; $i ++) {
1007
+ foreach ($arrays[$i] as $key => $value) {
1008
+ if (((string) $key) === ((string) intval($key))) { // integer or string as integer key - append
1009
+ $ret[] = $value;
1010
+ }
1011
+ else { // string key - merge
1012
+ if (is_array($value) && isset($ret[$key])) {
1013
+ $ret[$key] = $this->array_merge_recursive_unique($ret[$key], $value);
1014
+ }
1015
+ else {
1016
+ $ret[$key] = $value;
1017
+ }
1018
+ }
1019
+ }
1020
+ }
1021
+ return $ret;
1022
+ }
1023
+
1024
+
1025
+
1026
+ function _mergeFullCSS($p, &$t, $tag, $classes, $id, $lang) { // mPDF 6
1027
+ if (isset($p[$tag])) { $this->_mergeCSS($p[$tag], $t); }
1028
+ // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1029
+ foreach($classes AS $class) {
1030
+ if (isset($p['CLASS>>'.$class])) { $this->_mergeCSS($p['CLASS>>'.$class], $t); }
1031
+ }
1032
+ // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1033
+ if ($tag=='TR' && isset($p) && $p) {
1034
+ foreach($p AS $k=>$val) {
1035
+ if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1036
+ $select = false;
1037
+ if ($tag=='TR') {
1038
+ $row = $this->mpdf->row;
1039
+ $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1040
+ $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1041
+ if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1042
+ else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1043
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1044
+ $select = $this->_nthchild($a, $row);
1045
+ }
1046
+ }
1047
+ else if ($tag=='TD' || $tag=='TH') {
1048
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1049
+ $select = $this->_nthchild($a, $this->mpdf->col);
1050
+ }
1051
+ }
1052
+ if ($select) {
1053
+ $this->_mergeCSS($p[$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $t);
1054
+ }
1055
+ }
1056
+ }
1057
+ }
1058
+ // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1059
+ if (isset($lang) && isset($p['LANG>>'.$lang])) {
1060
+ $this->_mergeCSS($p['LANG>>'.$lang], $t);
1061
+ }
1062
+ // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1063
+ if (isset($id) && isset($p['ID>>'.$id])) {
1064
+ $this->_mergeCSS($p['ID>>'.$id], $t);
1065
+ }
1066
+
1067
+ // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1068
+ foreach($classes AS $class) {
1069
+ if (isset($p[$tag.'>>CLASS>>'.$class])) { $this->_mergeCSS($p[$tag.'>>CLASS>>'.$class], $t); }
1070
+ }
1071
+ // STYLESHEET CLASS e.g. [lang=fr]{} or :lang(fr)
1072
+ if (isset($lang) && isset($p[$tag.'>>LANG>>'.$lang])) {
1073
+ $this->_mergeCSS($p[$tag.'>>LANG>>'.$lang], $t);
1074
+ }
1075
+ // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1076
+ if (isset($id) && isset($p[$tag.'>>ID>>'.$id])) {
1077
+ $this->_mergeCSS($p[$tag.'>>ID>>'.$id], $t);
1078
+ }
1079
+ }
1080
+
1081
+ function setBorderDominance($prop, $val) {
1082
+ if (isset($prop['BORDER-LEFT']) && $prop['BORDER-LEFT']) { $this->cell_border_dominance_L = $val; }
1083
+ if (isset($prop['BORDER-RIGHT']) && $prop['BORDER-RIGHT']) { $this->cell_border_dominance_R = $val; }
1084
+ if (isset($prop['BORDER-TOP']) && $prop['BORDER-TOP']) { $this->cell_border_dominance_T = $val; }
1085
+ if (isset($prop['BORDER-BOTTOM']) && $prop['BORDER-BOTTOM']) { $this->cell_border_dominance_B = $val; }
1086
+ }
1087
+
1088
+ function _set_mergedCSS(&$m, &$p, $d=true, $bd=false) {
1089
+ if (isset($m)) {
1090
+ if ((isset($m['depth']) && $m['depth']>1) || $d==false) { // include check for 'depth'
1091
+ if ($bd) { $this->setBorderDominance($m, $bd); } // *TABLES*
1092
+ if (is_array($m)) {
1093
+ $p = array_merge($p,$m);
1094
+ $this->_mergeBorders($p,$m);
1095
+ }
1096
+ }
1097
+ }
1098
+ }
1099
+
1100
+
1101
+ function _mergeBorders(&$b, &$a) { // Merges $a['BORDER-TOP-STYLE'] to $b['BORDER-TOP'] etc.
1102
+ foreach(array('TOP','RIGHT','BOTTOM','LEFT') AS $side) {
1103
+ foreach(array('STYLE','WIDTH','COLOR') AS $el) {
1104
+ if (isset($a['BORDER-'.$side.'-'.$el])) { // e.g. $b['BORDER-TOP-STYLE']
1105
+ $s = trim($a['BORDER-'.$side.'-'.$el]);
1106
+ if (isset($b['BORDER-'.$side])) { // e.g. $b['BORDER-TOP']
1107
+ $p = trim($b['BORDER-'.$side]);
1108
+ }
1109
+ else { $p = ''; }
1110
+ if ($el=='STYLE') {
1111
+ if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 '.$s.' \\3', $p); }
1112
+ else { $b['BORDER-'.$side] = '0px '.$s.' #000000'; }
1113
+ }
1114
+ else if ($el=='WIDTH') {
1115
+ if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', $s.' \\2 \\3', $p); }
1116
+ else { $b['BORDER-'.$side] = $s.' none #000000'; }
1117
+ }
1118
+ else if ($el=='COLOR') {
1119
+ if ($p) { $b['BORDER-'.$side] = preg_replace('/(\S+)\s+(\S+)\s+(\S+)/', '\\1 \\2 '.$s, $p); }
1120
+ else { $b['BORDER-'.$side] = '0px none '.$s; }
1121
+ }
1122
+ }
1123
+ }
1124
+ }
1125
+ }
1126
+
1127
+
1128
+ function MergeCSS($inherit,$tag,$attr) {
1129
+ $p = array();
1130
+ $zp = array();
1131
+
1132
+ $classes = array();
1133
+ if (isset($attr['CLASS'])) {
1134
+ $classes = preg_split('/\s+/',$attr['CLASS']);
1135
+ }
1136
+ if (!isset($attr['ID'])) { $attr['ID']=''; }
1137
+ // mPDF 6
1138
+ $shortlang = '';
1139
+ if (!isset($attr['LANG'])) { $attr['LANG']=''; }
1140
+ else {
1141
+ $attr['LANG'] = strtolower($attr['LANG']);
1142
+ if (strlen($attr['LANG']) == 5) {
1143
+ $shortlang = substr($attr['LANG'],0,2);
1144
+ }
1145
+ }
1146
+ //===============================================
1147
+ /*-- TABLES --*/
1148
+ // Set Inherited properties
1149
+ if ($inherit == 'TOPTABLE') { // $tag = TABLE
1150
+ //===============================================
1151
+ // Save Cascading CSS e.g. "div.topic p" at this block level
1152
+
1153
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'])) {
1154
+ $this->tablecascadeCSS[0] = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1155
+ }
1156
+ else {
1157
+ $this->tablecascadeCSS[0] = $this->cascadeCSS;
1158
+ }
1159
+ }
1160
+ //===============================================
1161
+ // Set Inherited properties
1162
+ if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') {
1163
+ //Cascade everything from last level that is not an actual property, or defined by current tag/attributes
1164
+ if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1]) && is_array($this->tablecascadeCSS[$this->tbCSSlvl-1])) {
1165
+ foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$v) {
1166
+ $this->tablecascadeCSS[$this->tbCSSlvl][$k] = $v;
1167
+ }
1168
+ }
1169
+ $this->_mergeFullCSS($this->cascadeCSS, $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1170
+ //===============================================
1171
+ // Cascading forward CSS e.g. "table.topic td" for this table in $this->tablecascadeCSS
1172
+ //===============================================
1173
+ // STYLESHEET TAG e.g. table
1174
+ $this->_mergeFullCSS($this->tablecascadeCSS[$this->tbCSSlvl-1], $this->tablecascadeCSS[$this->tbCSSlvl], $tag, $classes, $attr['ID'], $attr['LANG']);
1175
+ //===============================================
1176
+ }
1177
+ /*-- END TABLES --*/
1178
+ //===============================================
1179
+ // Set Inherited properties
1180
+ if ($inherit == 'BLOCK') {
1181
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']) && is_array($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'])) {
1182
+ foreach($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'] AS $k=>$v) {
1183
+ $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$k] = $v;
1184
+
1185
+ }
1186
+ }
1187
+
1188
+ //===============================================
1189
+ // Save Cascading CSS e.g. "div.topic p" at this block level
1190
+ $this->_mergeFullCSS($this->cascadeCSS, $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1191
+ //===============================================
1192
+ // Cascading forward CSS
1193
+ //===============================================
1194
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) {
1195
+ $this->_mergeFullCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'], $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'], $tag, $classes, $attr['ID'], $attr['LANG']);
1196
+ }
1197
+ //===============================================
1198
+ // Block properties which are inherited
1199
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['margin_collapse']) { $p['MARGIN-COLLAPSE'] = 'COLLAPSE'; } // custom tag, but follows CSS principle that border-collapse is inherited
1200
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']) { $p['LINE-HEIGHT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_height']; }
1201
+ // mPDF 6
1202
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']) { $p['LINE-STACKING-STRATEGY'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_strategy']; }
1203
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']) { $p['LINE-STACKING-SHIFT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['line_stacking_shift']; }
1204
+
1205
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']) { $p['DIRECTION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['direction']; }
1206
+ // mPDF 6 Lists
1207
+ if ($tag == 'LI') {
1208
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']) { $p['LIST-STYLE-TYPE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_type']; }
1209
+ }
1210
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']) { $p['LIST-STYLE-IMAGE'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_image']; }
1211
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']) { $p['LIST-STYLE-POSITION'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['list_style_position']; }
1212
+
1213
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['align']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['align']) {
1214
+ if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'L') { $p['TEXT-ALIGN'] = 'left'; }
1215
+ else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'J') { $p['TEXT-ALIGN'] = 'justify'; }
1216
+ else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'R') { $p['TEXT-ALIGN'] = 'right'; }
1217
+ else if ($this->mpdf->blk[$this->mpdf->blklvl-1]['align'] == 'C') { $p['TEXT-ALIGN'] = 'center'; }
1218
+ }
1219
+ if ($this->mpdf->ColActive || $this->mpdf->keep_block_together) {
1220
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) && $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolor']) { // Doesn't officially inherit, but default value is transparent (?=inherited)
1221
+ $cor = $this->mpdf->blk[$this->mpdf->blklvl-1]['bgcolorarray' ];
1222
+ $p['BACKGROUND-COLOR'] = $this->mpdf->_colAtoString($cor);
1223
+ }
1224
+ }
1225
+
1226
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']) && ($this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent'] || $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']===0)) { $p['TEXT-INDENT'] = $this->mpdf->blk[$this->mpdf->blklvl-1]['text_indent']; }
1227
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'])) {
1228
+ $biilp = $this->mpdf->blk[$this->mpdf->blklvl-1]['InlineProperties'];
1229
+ $this->inlinePropsToCSS($biilp, $p); // mPDF 5.7.1
1230
+ }
1231
+ else { $biilp = null; }
1232
+ }
1233
+ //===============================================
1234
+ //===============================================
1235
+ // INLINE HTML ATTRIBUTES e.g. .. ALIGN="CENTER">
1236
+ // mPDF 6 (added)
1237
+ if (isset($attr['DIR']) and $attr['DIR']!='') {
1238
+ $p['DIRECTION'] = $attr['DIR'];
1239
+ }
1240
+ // mPDF 6 (moved)
1241
+ if (isset($attr['LANG']) and $attr['LANG']!='') {
1242
+ $p['LANG'] = $attr['LANG'];
1243
+ }
1244
+ if (isset($attr['COLOR']) and $attr['COLOR']!='') {
1245
+ $p['COLOR'] = $attr['COLOR'];
1246
+ }
1247
+
1248
+ if ($tag != 'INPUT') {
1249
+ if (isset($attr['WIDTH']) and $attr['WIDTH']!='') {
1250
+ $p['WIDTH'] = $attr['WIDTH'];
1251
+ }
1252
+ if (isset($attr['HEIGHT']) and $attr['HEIGHT']!='') {
1253
+ $p['HEIGHT'] = $attr['HEIGHT'];
1254
+ }
1255
+ }
1256
+ if ($tag == 'FONT') {
1257
+ if (isset($attr['FACE'])) {
1258
+ $p['FONT-FAMILY'] = $attr['FACE'];
1259
+ }
1260
+ if (isset($attr['SIZE']) and $attr['SIZE']!='') {
1261
+ $s = '';
1262
+ if ($attr['SIZE'] === '+1') { $s = '120%'; }
1263
+ else if ($attr['SIZE'] === '-1') { $s = '86%'; }
1264
+ else if ($attr['SIZE'] === '1') { $s = 'XX-SMALL'; }
1265
+ else if ($attr['SIZE'] == '2') { $s = 'X-SMALL'; }
1266
+ else if ($attr['SIZE'] == '3') { $s = 'SMALL'; }
1267
+ else if ($attr['SIZE'] == '4') { $s = 'MEDIUM'; }
1268
+ else if ($attr['SIZE'] == '5') { $s = 'LARGE'; }
1269
+ else if ($attr['SIZE'] == '6') { $s = 'X-LARGE'; }
1270
+ else if ($attr['SIZE'] == '7') { $s = 'XX-LARGE'; }
1271
+ if ($s) $p['FONT-SIZE'] = $s;
1272
+ }
1273
+ }
1274
+ if (isset($attr['VALIGN']) and $attr['VALIGN']!='') {
1275
+ $p['VERTICAL-ALIGN'] = $attr['VALIGN'];
1276
+ }
1277
+ if (isset($attr['VSPACE']) and $attr['VSPACE']!='') {
1278
+ $p['MARGIN-TOP'] = $attr['VSPACE'];
1279
+ $p['MARGIN-BOTTOM'] = $attr['VSPACE'];
1280
+ }
1281
+ if (isset($attr['HSPACE']) and $attr['HSPACE']!='') {
1282
+ $p['MARGIN-LEFT'] = $attr['HSPACE'];
1283
+ $p['MARGIN-RIGHT'] = $attr['HSPACE'];
1284
+ }
1285
+ //===============================================
1286
+ //===============================================
1287
+ // DEFAULT for this TAG set in DefaultCSS
1288
+ if (isset($this->mpdf->defaultCSS[$tag])) {
1289
+ $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1290
+ if (is_array($zp)) { // Default overwrites Inherited
1291
+ $p = array_merge($p,$zp); // !! Note other way round !!
1292
+ $this->_mergeBorders($p,$zp);
1293
+ }
1294
+ }
1295
+ //===============================================
1296
+ /*-- TABLES --*/
1297
+ // mPDF 5.7.3
1298
+ // cellSpacing overwrites TABLE default but not specific CSS set on table
1299
+ if ($tag=='TABLE' && isset($attr['CELLSPACING'])) {
1300
+ $p['BORDER-SPACING-H'] = $p['BORDER-SPACING-V'] = $attr['CELLSPACING'];
1301
+ }
1302
+ // cellPadding overwrites TD/TH default but not specific CSS set on cell
1303
+ if (($tag=='TD' || $tag=='TH') && isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']) && ($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'] || $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding']==='0')) { // mPDF 5.7.3
1304
+ $p['PADDING-LEFT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1305
+ $p['PADDING-RIGHT'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1306
+ $p['PADDING-TOP'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1307
+ $p['PADDING-BOTTOM'] = $this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['cell_padding'];
1308
+ }
1309
+ /*-- END TABLES --*/
1310
+ //===============================================
1311
+ // STYLESHEET TAG e.g. h1 p div table
1312
+ if (isset($this->CSS[$tag]) && $this->CSS[$tag]) {
1313
+ $zp = $this->CSS[$tag];
1314
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1315
+ if (is_array($zp)) {
1316
+ $p = array_merge($p,$zp);
1317
+ $this->_mergeBorders($p,$zp);
1318
+ }
1319
+ }
1320
+ //===============================================
1321
+ // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1322
+ foreach($classes AS $class) {
1323
+ $zp = array();
1324
+ if (isset($this->CSS['CLASS>>'.$class]) && $this->CSS['CLASS>>'.$class]) { $zp = $this->CSS['CLASS>>'.$class]; }
1325
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1326
+ if (is_array($zp)) {
1327
+ $p = array_merge($p,$zp);
1328
+ $this->_mergeBorders($p,$zp);
1329
+ }
1330
+ }
1331
+ //===============================================
1332
+ /*-- TABLES --*/
1333
+ // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1334
+ if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1335
+ foreach($this->CSS AS $k=>$val) {
1336
+ if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1337
+ $select = false;
1338
+ if ($tag=='TR') {
1339
+ $row = $this->mpdf->row;
1340
+ $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1341
+ $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1342
+ if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1343
+ else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1344
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1345
+ $select = $this->_nthchild($a, $row);
1346
+ }
1347
+ }
1348
+ else if ($tag=='TD' || $tag=='TH') {
1349
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1350
+ $select = $this->_nthchild($a, $this->mpdf->col);
1351
+ }
1352
+ }
1353
+ if ($select) {
1354
+ $zp = $this->CSS[$tag.'>>SELECTORNTHCHILD>>'.$m[1]];
1355
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); }
1356
+ if (is_array($zp)) {
1357
+ $p = array_merge($p,$zp);
1358
+ $this->_mergeBorders($p,$zp);
1359
+ }
1360
+ }
1361
+ }
1362
+ }
1363
+ }
1364
+ /*-- END TABLES --*/
1365
+ //===============================================
1366
+ // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1367
+ if (isset($attr['LANG'])) {
1368
+ if (isset($this->CSS['LANG>>'.$attr['LANG']]) && $this->CSS['LANG>>'.$attr['LANG']]) {
1369
+ $zp = $this->CSS['LANG>>'.$attr['LANG']];
1370
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1371
+ if (is_array($zp)) {
1372
+ $p = array_merge($p,$zp);
1373
+ $this->_mergeBorders($p,$zp);
1374
+ }
1375
+ }
1376
+ else if (isset($this->CSS['LANG>>'.$shortlang]) && $this->CSS['LANG>>'.$shortlang]) {
1377
+ $zp = $this->CSS['LANG>>'.$shortlang];
1378
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1379
+ if (is_array($zp)) {
1380
+ $p = array_merge($p,$zp);
1381
+ $this->_mergeBorders($p,$zp);
1382
+ }
1383
+ }
1384
+ }
1385
+ //===============================================
1386
+ // STYLESHEET ID e.g. #smallone{} #redletter{}
1387
+ if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']]) && $this->CSS['ID>>'.$attr['ID']]) {
1388
+ $zp = $this->CSS['ID>>'.$attr['ID']];
1389
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1390
+ if (is_array($zp)) {
1391
+ $p = array_merge($p,$zp);
1392
+ $this->_mergeBorders($p,$zp);
1393
+ }
1394
+ }
1395
+
1396
+ //===============================================
1397
+ // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1398
+ foreach($classes AS $class) {
1399
+ $zp = array();
1400
+ if (isset($this->CSS[$tag.'>>CLASS>>'.$class]) && $this->CSS[$tag.'>>CLASS>>'.$class]) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1401
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1402
+ if (is_array($zp)) {
1403
+ $p = array_merge($p,$zp);
1404
+ $this->_mergeBorders($p,$zp);
1405
+ }
1406
+ }
1407
+ //===============================================
1408
+ // STYLESHEET LANG e.g. [lang=fr]{} or :lang(fr)
1409
+ if (isset($attr['LANG'])) {
1410
+ if (isset($this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) && $this->CSS[$tag.'>>LANG>>'.$attr['LANG']]) {
1411
+ $zp = $this->CSS[$tag.'>>LANG>>'.$attr['LANG']];
1412
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1413
+ if (is_array($zp)) {
1414
+ $p = array_merge($p,$zp);
1415
+ $this->_mergeBorders($p,$zp);
1416
+ }
1417
+ }
1418
+ else if (isset($this->CSS[$tag.'>>LANG>>'.$shortlang]) && $this->CSS[$tag.'>>LANG>>'.$shortlang]) {
1419
+ $zp = $this->CSS[$tag.'>>LANG>>'.$shortlang];
1420
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1421
+ if (is_array($zp)) {
1422
+ $p = array_merge($p,$zp);
1423
+ $this->_mergeBorders($p,$zp);
1424
+ }
1425
+ }
1426
+ }
1427
+ //===============================================
1428
+ // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1429
+ if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']]) && $this->CSS[$tag.'>>ID>>'.$attr['ID']]) {
1430
+ $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1431
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1432
+ if (is_array($zp)) {
1433
+ $p = array_merge($p,$zp);
1434
+ $this->_mergeBorders($p,$zp);
1435
+ }
1436
+ }
1437
+ //===============================================
1438
+ // Cascaded e.g. div.class p only works for block level
1439
+ if ($inherit == 'BLOCK') {
1440
+ if (isset($this->mpdf->blk[$this->mpdf->blklvl-1])) { // mPDF 6
1441
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag], $p);
1442
+ foreach($classes AS $class) {
1443
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['CLASS>>'.$class], $p);
1444
+ }
1445
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1446
+ foreach($classes AS $class) {
1447
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1448
+ }
1449
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl-1]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1450
+ }
1451
+ }
1452
+ else if ($inherit == 'INLINE') {
1453
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag], $p);
1454
+ foreach($classes AS $class) {
1455
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['CLASS>>'.$class], $p);
1456
+ }
1457
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS']['ID>>'.$attr['ID']], $p);
1458
+ foreach($classes AS $class) {
1459
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>CLASS>>'.$class], $p);
1460
+ }
1461
+ $this->_set_mergedCSS($this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'][$tag.'>>ID>>'.$attr['ID']], $p);
1462
+ }
1463
+ /*-- TABLES --*/
1464
+ else if ($inherit == 'TOPTABLE' || $inherit == 'TABLE') { // NB looks at $this->tablecascadeCSS-1 for cascading CSS
1465
+ if (isset($this->tablecascadeCSS[$this->tbCSSlvl-1])) { // mPDF 6
1466
+ // false, 9 = don't check for 'depth' and do set border dominance
1467
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag], $p, false, 9);
1468
+ foreach($classes AS $class) {
1469
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['CLASS>>'.$class], $p, false, 9);
1470
+ }
1471
+ // STYLESHEET nth-child SELECTOR e.g. tr:nth-child(odd) td:nth-child(2n+1)
1472
+ if ($tag=='TR' || $tag=='TD' || $tag=='TH') {
1473
+ foreach($this->tablecascadeCSS[$this->tbCSSlvl-1] AS $k=>$val) {
1474
+ if (preg_match('/'.$tag.'>>SELECTORNTHCHILD>>(.*)/',$k, $m)) {
1475
+ $select = false;
1476
+ if ($tag=='TR') {
1477
+ $row = $this->mpdf->row;
1478
+ $thnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_thead']) : 0);
1479
+ $tfnr = (isset($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) ? count($this->mpdf->table[$this->mpdf->tableLevel][$this->mpdf->tbctr[$this->mpdf->tableLevel]]['is_tfoot']) : 0);
1480
+ if ($this->mpdf->tabletfoot) { $row -= $thnr; }
1481
+ else if (!$this->mpdf->tablethead) { $row -= ($thnr + $tfnr); }
1482
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1483
+ $select = $this->_nthchild($a, $row);
1484
+ }
1485
+ }
1486
+ else if ($tag=='TD' || $tag=='TH') {
1487
+ if (preg_match('/(([\-+]?\d*)?N([\-+]\d+)?|[\-+]?\d+|ODD|EVEN)/',$m[1],$a)) { // mPDF 5.7.4
1488
+ $select = $this->_nthchild($a, $this->mpdf->col);
1489
+ }
1490
+ }
1491
+ if ($select) {
1492
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>SELECTORNTHCHILD>>'.$m[1]], $p, false, 9);
1493
+ }
1494
+ }
1495
+ }
1496
+ }
1497
+ }
1498
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1]['ID>>'.$attr['ID']], $p, false, 9);
1499
+ foreach($classes AS $class) {
1500
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>CLASS>>'.$class], $p, false, 9);
1501
+ }
1502
+ $this->_set_mergedCSS($this->tablecascadeCSS[$this->tbCSSlvl-1][$tag.'>>ID>>'.$attr['ID']], $p, false, 9);
1503
+ }
1504
+ /*-- END TABLES --*/
1505
+ //===============================================
1506
+ //===============================================
1507
+ // INLINE STYLE e.g. style="CSS:property"
1508
+ if (isset($attr['STYLE'])) {
1509
+ $zp = $this->readInlineCSS($attr['STYLE']);
1510
+ if ($tag=='TD' || $tag=='TH') { $this->setBorderDominance($zp, 9); } // *TABLES* // *TABLES-ADVANCED-BORDERS*
1511
+ if (is_array($zp)) {
1512
+ $p = array_merge($p,$zp);
1513
+ $this->_mergeBorders($p,$zp);
1514
+ }
1515
+ }
1516
+ //===============================================
1517
+ //===============================================
1518
+ return $p;
1519
+ }
1520
+
1521
+
1522
+ // Convert inline Properties back to CSS
1523
+ function inlinePropsToCSS($bilp, &$p) {
1524
+ if (isset($bilp[ 'family' ]) && $bilp[ 'family' ]) { $p['FONT-FAMILY'] = $bilp[ 'family' ]; }
1525
+ if (isset($bilp[ 'I' ]) && $bilp[ 'I' ]) { $p['FONT-STYLE'] = 'italic'; }
1526
+ if (isset($bilp[ 'sizePt' ]) && $bilp[ 'sizePt' ]) { $p['FONT-SIZE'] = $bilp[ 'sizePt' ] . 'pt'; }
1527
+ if (isset($bilp[ 'B' ]) && $bilp[ 'B' ]) { $p['FONT-WEIGHT'] = 'bold'; }
1528
+ if (isset($bilp[ 'colorarray' ]) && $bilp[ 'colorarray' ]) {
1529
+ $cor = $bilp[ 'colorarray' ];
1530
+ $p['COLOR'] = $this->mpdf->_colAtoString($cor);
1531
+ }
1532
+ if (isset($bilp[ 'lSpacingCSS' ]) && $bilp[ 'lSpacingCSS' ]) { $p['LETTER-SPACING'] = $bilp[ 'lSpacingCSS' ]; }
1533
+ if (isset($bilp[ 'wSpacingCSS' ]) && $bilp[ 'wSpacingCSS' ]) { $p['WORD-SPACING'] = $bilp[ 'wSpacingCSS' ]; }
1534
+
1535
+ if (isset($bilp[ 'textparam' ]) && $bilp[ 'textparam' ]) {
1536
+ if (isset($bilp[ 'textparam' ]['hyphens'])) {
1537
+ if ($bilp[ 'textparam' ]['hyphens']==2) { $p['HYPHENS'] = 'none'; }
1538
+ if ($bilp[ 'textparam' ]['hyphens']==1) { $p['HYPHENS'] = 'auto'; }
1539
+ if ($bilp[ 'textparam' ]['hyphens']==0) { $p['HYPHENS'] = 'manual'; }
1540
+ }
1541
+ if (isset($bilp[ 'textparam' ]['outline-s']) && !$bilp[ 'textparam' ]['outline-s']) { $p['TEXT-OUTLINE'] = 'none'; }
1542
+ if (isset($bilp[ 'textparam' ]['outline-COLOR']) && $bilp[ 'textparam' ]['outline-COLOR']) { $p['TEXT-OUTLINE-COLOR'] = $this->mpdf->_colAtoString($bilp[ 'textparam' ]['outline-COLOR']); }
1543
+ if (isset($bilp[ 'textparam' ]['outline-WIDTH']) && $bilp[ 'textparam' ]['outline-WIDTH']) { $p['TEXT-OUTLINE-WIDTH'] = $bilp[ 'textparam' ]['outline-WIDTH'].'mm'; }
1544
+ }
1545
+
1546
+ if (isset($bilp[ 'textvar' ]) && $bilp[ 'textvar' ]) {
1547
+ // CSS says text-decoration is not inherited, but IE7 does??
1548
+ if ($bilp[ 'textvar' ] & FD_LINETHROUGH) {
1549
+ if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline line-through'; }
1550
+ else { $p['TEXT-DECORATION'] = 'line-through'; }
1551
+ }
1552
+ else if ($bilp[ 'textvar' ] & FD_UNDERLINE) { $p['TEXT-DECORATION'] = 'underline'; }
1553
+ else { $p['TEXT-DECORATION'] = 'none'; }
1554
+
1555
+ if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['VERTICAL-ALIGN'] = 'super'; }
1556
+ else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['VERTICAL-ALIGN'] = 'sub'; }
1557
+ else { $p['VERTICAL-ALIGN'] = 'baseline'; }
1558
+
1559
+ if ($bilp[ 'textvar' ] & FT_CAPITALIZE) { $p['TEXT-TRANSFORM'] = 'capitalize'; }
1560
+ else if ($bilp[ 'textvar' ] & FT_UPPERCASE) { $p['TEXT-TRANSFORM'] = 'uppercase'; }
1561
+ else if ($bilp[ 'textvar' ] & FT_LOWERCASE) { $p['TEXT-TRANSFORM'] = 'lowercase'; }
1562
+ else { $p['TEXT-TRANSFORM'] = 'none'; }
1563
+
1564
+ if ($bilp[ 'textvar' ] & FC_KERNING) { $p['FONT-KERNING'] = 'normal'; } // ignore 'auto' as default already applied
1565
+ //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'kern'
1566
+ else { $p['FONT-KERNING'] = 'none'; }
1567
+
1568
+ if ($bilp[ 'textvar' ] & FA_SUPERSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'super'; }
1569
+ //if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]['Plus'] contains 'sups' / 'subs'
1570
+ else if ($bilp[ 'textvar' ] & FA_SUBSCRIPT) { $p['FONT-VARIANT-POSITION'] = 'sub'; }
1571
+ else { $p['FONT-VARIANT-POSITION'] = 'normal'; }
1572
+
1573
+ if ($bilp[ 'textvar' ] & FC_SMALLCAPS) { $p['FONT-VARIANT-CAPS'] = 'small-caps'; }
1574
+ }
1575
+ if (isset($bilp[ 'fontLanguageOverride' ])) {
1576
+ if ($bilp[ 'fontLanguageOverride' ]) { $p['FONT-LANGUAGE-OVERRIDE'] = $bilp[ 'fontLanguageOverride' ]; }
1577
+ else { $p['FONT-LANGUAGE-OVERRIDE'] = 'normal'; }
1578
+ }
1579
+ // All the variations of font-variant-* we are going to set as font-feature-settings...
1580
+ if (isset($bilp[ 'OTLtags' ]) && $bilp[ 'OTLtags' ]) {
1581
+ $ffs = array();
1582
+ if (isset($bilp['OTLtags']['Minus']) && $bilp['OTLtags']['Minus']) {
1583
+ $f = preg_split('/\s+/', trim($bilp['OTLtags']['Minus']));
1584
+ foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1585
+ }
1586
+ if (isset($bilp['OTLtags']['FFMinus']) && $bilp['OTLtags']['FFMinus']) {
1587
+ $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFMinus']));
1588
+ foreach($f AS $ff) { $ffs[] = "'".$ff."' 0"; }
1589
+ }
1590
+ if (isset($bilp['OTLtags']['Plus']) && $bilp['OTLtags']['Plus']) {
1591
+ $f = preg_split('/\s+/', trim($bilp['OTLtags']['Plus']));
1592
+ foreach($f AS $ff) { $ffs[] = "'".$ff."' 1"; }
1593
+ }
1594
+ if (isset($bilp['OTLtags']['FFPlus']) && $bilp['OTLtags']['FFPlus']) { // May contain numeric value e.g. salt4
1595
+ $f = preg_split('/\s+/', trim($bilp['OTLtags']['FFPlus']));
1596
+ foreach($f AS $ff) {
1597
+ if (strlen($ff)>4) { $ffs[] = "'".substr($ff,0,4)."' ".substr($ff,4); }
1598
+ else { $ffs[] = "'".$ff."' 1"; }
1599
+ }
1600
+ }
1601
+ $p['FONT-FEATURE-SETTINGS'] = implode(', ', $ffs);
1602
+ }
1603
+
1604
+
1605
+ }
1606
+
1607
+ function PreviewBlockCSS($tag,$attr) {
1608
+ // Looks ahead from current block level to a new level
1609
+ $p = array();
1610
+ $zp = array();
1611
+ $oldcascadeCSS = $this->mpdf->blk[$this->mpdf->blklvl]['cascadeCSS'];
1612
+ $classes = array();
1613
+ if (isset($attr['CLASS'])) { $classes = preg_split('/\s+/',$attr['CLASS']); }
1614
+ //===============================================
1615
+ // DEFAULT for this TAG set in DefaultCSS
1616
+ if (isset($this->mpdf->defaultCSS[$tag])) {
1617
+ $zp = $this->fixCSS($this->mpdf->defaultCSS[$tag]);
1618
+ if (is_array($zp)) { $p = array_merge($zp,$p); } // Inherited overwrites default
1619
+ }
1620
+ // STYLESHEET TAG e.g. h1 p div table
1621
+ if (isset($this->CSS[$tag])) {
1622
+ $zp = $this->CSS[$tag];
1623
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1624
+ }
1625
+ // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1626
+ foreach($classes AS $class) {
1627
+ $zp = array();
1628
+ if (isset($this->CSS['CLASS>>'.$class])) { $zp = $this->CSS['CLASS>>'.$class]; }
1629
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1630
+ }
1631
+ // STYLESHEET ID e.g. #smallone{} #redletter{}
1632
+ if (isset($attr['ID']) && isset($this->CSS['ID>>'.$attr['ID']])) {
1633
+ $zp = $this->CSS['ID>>'.$attr['ID']];
1634
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1635
+ }
1636
+ // STYLESHEET CLASS e.g. p.smallone{} div.redletter{}
1637
+ foreach($classes AS $class) {
1638
+ $zp = array();
1639
+ if (isset($this->CSS[$tag.'>>CLASS>>'.$class])) { $zp = $this->CSS[$tag.'>>CLASS>>'.$class]; }
1640
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1641
+ }
1642
+ // STYLESHEET CLASS e.g. p#smallone{} div#redletter{}
1643
+ if (isset($attr['ID']) && isset($this->CSS[$tag.'>>ID>>'.$attr['ID']])) {
1644
+ $zp = $this->CSS[$tag.'>>ID>>'.$attr['ID']];
1645
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1646
+ }
1647
+ //===============================================
1648
+ // STYLESHEET TAG e.g. div h1 div p
1649
+
1650
+ $this->_set_mergedCSS($oldcascadeCSS[$tag], $p);
1651
+ // STYLESHEET CLASS e.g. .smallone{} .redletter{}
1652
+ foreach($classes AS $class) {
1653
+
1654
+ $this->_set_mergedCSS($oldcascadeCSS['CLASS>>'.$class], $p);
1655
+ }
1656
+ // STYLESHEET CLASS e.g. #smallone{} #redletter{}
1657
+ if (isset($attr['ID'])) {
1658
+
1659
+ $this->_set_mergedCSS($oldcascadeCSS['ID>>'.$attr['ID']], $p);
1660
+ }
1661
+ // STYLESHEET CLASS e.g. div.smallone{} p.redletter{}
1662
+ foreach($classes AS $class) {
1663
+
1664
+ $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>CLASS>>'.$class], $p);
1665
+ }
1666
+ // STYLESHEET CLASS e.g. div#smallone{} p#redletter{}
1667
+ if (isset($attr['ID'])) {
1668
+
1669
+ $this->_set_mergedCSS($oldcascadeCSS[$tag.'>>ID>>'.$attr['ID']], $p);
1670
+ }
1671
+ //===============================================
1672
+ // INLINE STYLE e.g. style="CSS:property"
1673
+ if (isset($attr['STYLE'])) {
1674
+ $zp = $this->readInlineCSS($attr['STYLE']);
1675
+ if (is_array($zp)) { $p = array_merge($p,$zp); }
1676
+ }
1677
+ //===============================================
1678
+ return $p;
1679
+ }
1680
+
1681
+
1682
+ // mPDF 5.7.4 nth-child
1683
+ function _nthchild($f, $c) {
1684
+ // $f is formual e.g. 2N+1 spilt into a preg_match array
1685
+ // $c is the comparator value e.g row or column number
1686
+ $c += 1;
1687
+ $select = false;
1688
+ $a=1; $b=1;
1689
+ if ($f[0]=='ODD') { $a=2; $b=1; }
1690
+ else if ($f[0]=='EVEN') { $a=2; $b=0; }
1691
+ else if (count($f)==2) { $a=0; $b=$f[1]+0; } // e.g. (+6)
1692
+ else if (count($f)==3) { // e.g. (2N)
1693
+ if ($f[2]=='') { $a=1; }
1694
+ else if ($f[2]=='-') { $a=-1; }
1695
+ else { $a=$f[2]+0; }
1696
+ $b=0;
1697
+ }
1698
+ else if (count($f)==4) { // e.g. (2N+6)
1699
+ if ($f[2]=='') { $a=1; }
1700
+ else if ($f[2]=='-') { $a=-1; }
1701
+ else { $a=$f[2]+0; }
1702
+ $b=$f[3]+0;
1703
+ }
1704
+ else { return false; }
1705
+ if ($a>0) {
1706
+ if (((($c % $a) - $b) % $a) == 0 && $c >= $b) { $select = true; }
1707
+ }
1708
+ else if ($a==0) {
1709
+ if ($c == $b) { $select = true; }
1710
+ }
1711
+ else { // if ($a<0)
1712
+ if (((($c % $a) - $b) % $a) == 0 && $c <= $b) { $select = true; }
1713
+ }
1714
+ return $select;
1715
+ }
1716
+
1717
+
1718
+
1719
+ } // end of class
1720
+
1721
+ ?>
lib/mpdf/classes/desktop.ini ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ [ViewState]
2
+ Mode=
3
+ Vid=
4
+ FolderType=Documents
lib/mpdf/classes/directw.php ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class directw {
4
+
5
+ var $mpdf = null;
6
+
7
+ function directw(&$mpdf) {
8
+ $this->mpdf = $mpdf;
9
+ }
10
+
11
+
12
+ function Write($h,$txt,$currentx=0,$link='',$directionality='ltr',$align='') {
13
+ if (!$align) {
14
+ if ($directionality=='rtl') { $align = 'R'; }
15
+ else { $align = 'L'; }
16
+ }
17
+ if ($h == 0) { $this->mpdf->SetLineHeight(); $h = $this->mpdf->lineheight; }
18
+ //Output text in flowing mode
19
+ $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
20
+
21
+ $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
22
+ $s=str_replace("\r",'',$txt);
23
+ if ($this->mpdf->usingCoreFont) { $nb=strlen($s); }
24
+ else {
25
+ $nb=mb_strlen($s, $this->mpdf->mb_enc );
26
+ // handle single space character
27
+ if(($nb==1) && $s == " ") {
28
+ $this->mpdf->x += $this->mpdf->GetStringWidth($s);
29
+ return;
30
+ }
31
+ }
32
+ $sep=-1;
33
+ $i=0;
34
+ $j=0;
35
+ $l=0;
36
+ $nl=1;
37
+ if (!$this->mpdf->usingCoreFont) {
38
+ if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $txt)) { $this->mpdf->biDirectional = true; } // *RTL*
39
+ while($i<$nb) {
40
+ //Get next character
41
+ $c = mb_substr($s,$i,1,$this->mpdf->mb_enc );
42
+ if($c == "\n") {
43
+ // WORD SPACING
44
+ $this->mpdf->ResetSpacing();
45
+ //Explicit line break
46
+ $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc));
47
+ $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
48
+ $i++;
49
+ $sep = -1;
50
+ $j = $i;
51
+ $l = 0;
52
+ if($nl == 1) {
53
+ if ($currentx != 0) $this->mpdf->x=$currentx;
54
+ else $this->mpdf->x=$this->mpdf->lMargin;
55
+ $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
56
+ $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
57
+ }
58
+ $nl++;
59
+ continue;
60
+ }
61
+ if($c == " ") { $sep= $i; }
62
+ $l += $this->mpdf->GetCharWidthNonCore($c); // mPDF 5.3.04
63
+ if($l > $wmax) {
64
+ //Automatic line break (word wrapping)
65
+ if($sep == -1) {
66
+ // WORD SPACING
67
+ $this->mpdf->ResetSpacing();
68
+ if($this->mpdf->x > $this->mpdf->lMargin) {
69
+ //Move to next line
70
+ if ($currentx != 0) $this->mpdf->x=$currentx;
71
+ else $this->mpdf->x=$this->mpdf->lMargin;
72
+ $this->mpdf->y+=$h;
73
+ $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
74
+ $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
75
+ $i++;
76
+ $nl++;
77
+ continue;
78
+ }
79
+ if($i==$j) { $i++; }
80
+ $tmp = rtrim(mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc));
81
+ $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
82
+ }
83
+ else {
84
+ $tmp = rtrim(mb_substr($s,$j,$sep-$j,$this->mpdf->mb_enc));
85
+
86
+ if($align=='J') {
87
+ //////////////////////////////////////////
88
+ // JUSTIFY J using Unicode fonts (Word spacing doesn't work)
89
+ // WORD SPACING
90
+ // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
91
+ $tmp = str_replace(chr(194).chr(160),chr(32),$tmp );
92
+ $len_ligne = $this->mpdf->GetStringWidth($tmp );
93
+ $nb_carac = mb_strlen( $tmp , $this->mpdf->mb_enc ) ;
94
+ $nb_spaces = mb_substr_count( $tmp ,' ', $this->mpdf->mb_enc ) ;
95
+ $inclCursive=false;
96
+ if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
97
+ if (preg_match("/([".$this->mpdf->pregCURSchars."])/u", $tmp)) { $inclCursive = true; }
98
+ }
99
+ list($charspacing,$ws) = $this->mpdf->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK),$inclCursive);
100
+ $this->mpdf->SetSpacing($charspacing,$ws);
101
+ //////////////////////////////////////////
102
+ }
103
+ $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
104
+ $i=$sep+1;
105
+ }
106
+ $sep = -1;
107
+ $j = $i;
108
+ $l = 0;
109
+ if($nl==1) {
110
+ if ($currentx != 0) $this->mpdf->x=$currentx;
111
+ else $this->mpdf->x=$this->mpdf->lMargin;
112
+ $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
113
+ $wmax = ($w - ($this->mpdf->cMarginL+$this->mpdf->cMarginR));
114
+ }
115
+ $nl++;
116
+ }
117
+ else { $i++; }
118
+ }
119
+ //Last chunk
120
+ // WORD SPACING
121
+ $this->mpdf->ResetSpacing();
122
+ }
123
+ else {
124
+ while($i<$nb) {
125
+ //Get next character
126
+ $c=$s[$i];
127
+ if($c == "\n") {
128
+ //Explicit line break
129
+ // WORD SPACING
130
+ $this->mpdf->ResetSpacing();
131
+ $this->mpdf->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
132
+ $i++;
133
+ $sep = -1;
134
+ $j = $i;
135
+ $l = 0;
136
+ if($nl == 1) {
137
+ if ($currentx != 0) $this->mpdf->x=$currentx;
138
+ else $this->mpdf->x=$this->mpdf->lMargin;
139
+ $w = $this->mpdf->w - $this->mpdf->rMargin - $this->mpdf->x;
140
+ $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
141
+ }
142
+ $nl++;
143
+ continue;
144
+ }
145
+ if($c == " ") { $sep= $i; }
146
+ $l += $this->mpdf->GetCharWidthCore($c); // mPDF 5.3.04
147
+ if($l > $wmax) {
148
+ //Automatic line break (word wrapping)
149
+ if($sep == -1) {
150
+ // WORD SPACING
151
+ $this->mpdf->ResetSpacing();
152
+ if($this->mpdf->x > $this->mpdf->lMargin) {
153
+ //Move to next line
154
+ if ($currentx != 0) $this->mpdf->x=$currentx;
155
+ else $this->mpdf->x=$this->mpdf->lMargin;
156
+ $this->mpdf->y+=$h;
157
+ $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
158
+ $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
159
+ $i++;
160
+ $nl++;
161
+ continue;
162
+ }
163
+ if($i==$j) { $i++; }
164
+ $this->mpdf->Cell($w, $h, substr($s, $j, $i-$j), 0, 2, $align, $fill, $link);
165
+ }
166
+ else {
167
+ $tmp = substr($s, $j, $sep-$j);
168
+ if($align=='J') {
169
+ //////////////////////////////////////////
170
+ // JUSTIFY J using Unicode fonts
171
+ // WORD SPACING is not fully supported for complex scripts
172
+ // Change NON_BREAKING SPACE to spaces so they are 'spaced' properly
173
+ $tmp = str_replace(chr(160),chr(32),$tmp );
174
+ $len_ligne = $this->mpdf->GetStringWidth($tmp );
175
+ $nb_carac = strlen( $tmp ) ;
176
+ $nb_spaces = substr_count( $tmp ,' ' ) ;
177
+ list($charspacing,$ws) = $this->mpdf->GetJspacing($nb_carac,$nb_spaces,((($w-2) - $len_ligne) * _MPDFK),$false);
178
+ $this->mpdf->SetSpacing($charspacing,$ws);
179
+ //////////////////////////////////////////
180
+ }
181
+ $this->mpdf->Cell($w, $h, $tmp, 0, 2, $align, $fill, $link);
182
+ $i=$sep+1;
183
+ }
184
+ $sep = -1;
185
+ $j = $i;
186
+ $l = 0;
187
+ if($nl==1) {
188
+ if ($currentx != 0) $this->mpdf->x=$currentx;
189
+ else $this->mpdf->x=$this->mpdf->lMargin;
190
+ $w=$this->mpdf->w-$this->mpdf->rMargin-$this->mpdf->x;
191
+ $wmax=$w-($this->mpdf->cMarginL+$this->mpdf->cMarginR);
192
+ }
193
+ $nl++;
194
+ }
195
+ else {
196
+ $i++;
197
+ }
198
+ }
199
+ // WORD SPACING
200
+ $this->mpdf->ResetSpacing();
201
+ }
202
+ //Last chunk
203
+ if($i!=$j) {
204
+ if ($currentx != 0) $this->mpdf->x=$currentx;
205
+ else $this->mpdf->x=$this->mpdf->lMargin;
206
+ if ($this->mpdf->usingCoreFont) { $tmp = substr($s,$j,$i-$j); }
207
+ else { $tmp = mb_substr($s,$j,$i-$j,$this->mpdf->mb_enc); }
208
+ $this->mpdf->Cell($w,$h,$tmp,0,0,$align,$fill,$link);
209
+ }
210
+ }
211
+
212
+
213
+ function CircularText($x, $y, $r, $text, $align='top', $fontfamily='', $fontsizePt=0, $fontstyle='', $kerning=120, $fontwidth=100, $divider='') {
214
+ if ($fontfamily || $fontstyle || $fontsizePt) $this->mpdf->SetFont($fontfamily,$fontstyle,$fontsizePt);
215
+ $kerning/=100;
216
+ $fontwidth/=100;
217
+ if($kerning==0) $this->mpdf->Error('Please use values unequal to zero for kerning (CircularText)');
218
+ if($fontwidth==0) $this->mpdf->Error('Please use values unequal to zero for font width (CircularText)');
219
+ $text=str_replace("\r",'',$text);
220
+ //circumference
221
+ $u=($r*2)*M_PI;
222
+ $checking = true;
223
+ $autoset = false;
224
+ while($checking) {
225
+ $t=0;
226
+ $w = array();
227
+ if ($this->mpdf->usingCoreFont) {
228
+ $nb=strlen($text);
229
+ for($i=0; $i<$nb; $i++){
230
+ $w[$i]=$this->mpdf->GetStringWidth($text[$i]);
231
+ $w[$i]*=$kerning*$fontwidth;
232
+ $t+=$w[$i];
233
+ }
234
+ }
235
+ else {
236
+ $nb=mb_strlen($text, $this->mpdf->mb_enc );
237
+ $lastchar = '';
238
+ $unicode = $this->mpdf->UTF8StringToArray($text);
239
+ for($i=0; $i<$nb; $i++){
240
+ $c = mb_substr($text,$i,1,$this->mpdf->mb_enc );
241
+ $w[$i]=$this->mpdf->GetStringWidth($c);
242
+ $w[$i]*=$kerning*$fontwidth;
243
+ $char = $unicode[$i];
244
+ if ($this->mpdf->useKerning && $lastchar) {
245
+ if (isset($this->mpdf->CurrentFont['kerninfo'][$lastchar][$char])) {
246
+ $tk = $this->mpdf->CurrentFont['kerninfo'][$lastchar][$char] * ($this->mpdf->FontSize/ 1000) * $kerning * $fontwidth;
247
+ $w[$i] += $tk/2;
248
+ $w[$i-1] += $tk/2;
249
+ $t+=$tk;
250
+ }
251
+ }
252
+ $lastchar = $char;
253
+ $t+=$w[$i];
254
+ }
255
+ }
256
+ if ($fontsizePt>=0 || $autoset) { $checking = false; }
257
+ else {
258
+ $t+=$this->mpdf->GetStringWidth(' ');
259
+ if ($divider)
260
+ $t+=$this->mpdf->GetStringWidth(' ');
261
+ if ($fontsizePt==-2)
262
+ $fontsizePt = $this->mpdf->FontSizePt * 0.5 * $u/$t;
263
+ else
264
+ $fontsizePt = $this->mpdf->FontSizePt * $u/$t;
265
+ $this->mpdf->SetFontSize($fontsizePt);
266
+ $autoset = true;
267
+ }
268
+ }
269
+
270
+ //total width of string in degrees
271
+ $d=($t/$u)*360;
272
+
273
+ $this->mpdf->StartTransform();
274
+ // rotate matrix for the first letter to center the text
275
+ // (half of total degrees)
276
+ if($align=='top'){
277
+ $this->mpdf->transformRotate(-$d/2, $x, $y);
278
+ }
279
+ else{
280
+ $this->mpdf->transformRotate($d/2, $x, $y);
281
+ }
282
+ //run through the string
283
+ for($i=0; $i<$nb; $i++){
284
+ if($align=='top'){
285
+ //rotate matrix half of the width of current letter + half of the width of preceding letter
286
+ if($i==0){
287
+ $this->mpdf->transformRotate((($w[$i]/2)/$u)*360, $x, $y);
288
+ }
289
+ else{
290
+ $this->mpdf->transformRotate((($w[$i]/2+$w[$i-1]/2)/$u)*360, $x, $y);
291
+ }
292
+ if($fontwidth!=1){
293
+ $this->mpdf->StartTransform();
294
+ $this->mpdf->transformScale($fontwidth*100, 100, $x, $y);
295
+ }
296
+ $this->mpdf->SetXY($x-$w[$i]/2, $y-$r);
297
+ }
298
+ else{
299
+ //rotate matrix half of the width of current letter + half of the width of preceding letter
300
+ if($i==0){
301
+ $this->mpdf->transformRotate(-(($w[$i]/2)/$u)*360, $x, $y);
302
+ }
303
+ else{
304
+ $this->mpdf->transformRotate(-(($w[$i]/2+$w[$i-1]/2)/$u)*360, $x, $y);
305
+ }
306
+ if($fontwidth!=1){
307
+ $this->mpdf->StartTransform();
308
+ $this->mpdf->transformScale($fontwidth*100, 100, $x, $y);
309
+ }
310
+ $this->mpdf->SetXY($x-$w[$i]/2, $y+$r-($this->mpdf->FontSize));
311
+ }
312
+ if ($this->mpdf->usingCoreFont) { $c=$text[$i]; }
313
+ else { $c = mb_substr($text,$i,1,$this->mpdf->mb_enc ); }
314
+ $this->mpdf->Cell(($w[$i]),$this->mpdf->FontSize,$c,0,0,'C'); // mPDF 5.3.53
315
+ if($fontwidth!=1){
316
+ $this->mpdf->StopTransform();
317
+ }
318
+ }
319
+ $this->mpdf->StopTransform();
320
+
321
+ // mPDF 5.5.23
322
+ if($align=='top' && $divider!=''){
323
+ $wc=$this->mpdf->GetStringWidth($divider);
324
+ $wc*=$kerning*$fontwidth;
325
+
326
+ $this->mpdf->StartTransform();
327
+ $this->mpdf->transformRotate(90, $x, $y);
328
+ $this->mpdf->SetXY($x-$wc/2, $y-$r);
329
+ $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C');
330
+ $this->mpdf->StopTransform();
331
+
332
+ $this->mpdf->StartTransform();
333
+ $this->mpdf->transformRotate(-90, $x, $y);
334
+ $this->mpdf->SetXY($x-$wc/2, $y-$r);
335
+ $this->mpdf->Cell(($wc),$this->mpdf->FontSize,$divider,0,0,'C');
336
+ $this->mpdf->StopTransform();
337
+ }
338
+ }
339
+
340
+ function Shaded_box( $text,$font='',$fontstyle='B',$szfont='',$width='70%',$style='DF',$radius=2.5,$fill='#FFFFFF',$color='#000000',$pad=2 ) {
341
+ // F (shading - no line),S (line, no shading),DF (both)
342
+ if (!$font) { $font= $this->mpdf->default_font; }
343
+ if (!$szfont) { $szfont = ($this->mpdf->default_font_size * 1.8); }
344
+
345
+ $text = ' '.$text.' ';
346
+ $this->mpdf->SetFont( $font, $fontstyle, $szfont, false );
347
+
348
+ $text = $this->mpdf->purify_utf8_text($text);
349
+ if ($this->mpdf->text_input_as_HTML) {
350
+ $text = $this->mpdf->all_entities_to_utf8($text);
351
+ }
352
+ if ($this->mpdf->usingCoreFont) { $text = mb_convert_encoding($text,$this->mpdf->mb_enc,'UTF-8'); }
353
+
354
+
355
+ // DIRECTIONALITY
356
+ if (preg_match("/([".$this->mpdf->pregRTLchars."])/u", $text)) { $this->mpdf->biDirectional = true; } // *RTL*
357
+
358
+ $textvar = 0;
359
+ $save_OTLtags = $this->mpdf->OTLtags;
360
+ $this->mpdf->OTLtags = array();
361
+ if ($this->mpdf->useKerning) {
362
+ if ($this->mpdf->CurrentFont['haskernGPOS']) { $this->mpdf->OTLtags['Plus'] .= ' kern'; }
363
+ else { $textvar = ($textvar | FC_KERNING); }
364
+ }
365
+ // Use OTL OpenType Table Layout - GSUB & GPOS
366
+ if (isset($this->mpdf->CurrentFont['useOTL']) && $this->mpdf->CurrentFont['useOTL']) {
367
+ $text = $this->mpdf->otl->applyOTL($text, $this->mpdf->CurrentFont['useOTL']);
368
+ $OTLdata = $this->mpdf->otl->OTLdata;
369
+ }
370
+ $this->mpdf->OTLtags = $save_OTLtags ;
371
+
372
+ $this->mpdf->magic_reverse_dir($text, $this->mpdf->directionality, $OTLdata);
373
+
374
+ if (!$width) { $width = $this->mpdf->pgwidth; } else { $width=$this->mpdf->ConvertSize($width,$this->mpdf->pgwidth); }
375
+ $midpt = $this->mpdf->lMargin+($this->mpdf->pgwidth/2);
376
+ $r1 = $midpt-($width/2); //($this->mpdf->w / 2) - 40;
377
+ $r2 = $r1 + $width; //$r1 + 80;
378
+ $y1 = $this->mpdf->y;
379
+
380
+
381
+ $mid = ($r1 + $r2 ) / 2;
382
+ $loop = 0;
383
+
384
+ while ( $loop == 0 )
385
+ {
386
+ $this->mpdf->SetFont( $font, $fontstyle, $szfont, false );
387
+ $sz = $this->mpdf->GetStringWidth( $text, true, $OTLdata, $textvar );
388
+ if ( ($r1+$sz) > $r2 )
389
+ $szfont --;
390
+ else
391
+ $loop ++;
392
+ }
393
+ $this->mpdf->SetFont( $font, $fontstyle, $szfont, true, true );
394
+
395
+ $y2 = $this->mpdf->FontSize+($pad*2);
396
+
397
+ $this->mpdf->SetLineWidth(0.1);
398
+ $fc = $this->mpdf->ConvertColor($fill);
399
+ $tc = $this->mpdf->ConvertColor($color);
400
+ $this->mpdf->SetFColor($fc);
401
+ $this->mpdf->SetTColor($tc);
402
+ $this->mpdf->RoundedRect($r1, $y1, ($r2 - $r1), $y2, $radius, $style);
403
+ $this->mpdf->SetX( $r1);
404
+ $this->mpdf->Cell($r2-$r1, $y2, $text, 0, 1, "C",0,'',0,0,0,'M', 0, false, $OTLdata, $textvar );
405
+ $this->mpdf->SetY($y1+$y2+2); // +2 = mm margin below shaded box
406
+ $this->mpdf->Reset();
407
+ }
408
+
409
+
410
+ }
411
+
412
+ ?>
lib/mpdf/classes/gif.php ADDED
@@ -0,0 +1,700 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
3
+ // 2009-12-22 Adapted for mPDF 4.2
4
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
5
+ // GIF Util - (C) 2003 Yamasoft (S/C)
6
+ // http://www.yamasoft.com
7
+ // All Rights Reserved
8
+ // This file can be freely copied, distributed, modified, updated by anyone under the only
9
+ // condition to leave the original address (Yamasoft, http://www.yamasoft.com) and this header.
10
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
11
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
12
+ // 2009-12-22 Adapted INB
13
+ // Functions calling functionname($x, $len = 0) were not working on PHP5.1.5 as pass by reference
14
+ // All edited to $len = 0; then call function.
15
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
16
+
17
+
18
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
19
+
20
+ class CGIFLZW
21
+ {
22
+ var $MAX_LZW_BITS;
23
+ var $Fresh, $CodeSize, $SetCodeSize, $MaxCode, $MaxCodeSize, $FirstCode, $OldCode;
24
+ var $ClearCode, $EndCode, $Next, $Vals, $Stack, $sp, $Buf, $CurBit, $LastBit, $Done, $LastByte;
25
+
26
+ ///////////////////////////////////////////////////////////////////////////
27
+
28
+ // CONSTRUCTOR
29
+ function CGIFLZW()
30
+ {
31
+ $this->MAX_LZW_BITS = 12;
32
+ unSet($this->Next);
33
+ unSet($this->Vals);
34
+ unSet($this->Stack);
35
+ unSet($this->Buf);
36
+
37
+ $this->Next = range(0, (1 << $this->MAX_LZW_BITS) - 1);
38
+ $this->Vals = range(0, (1 << $this->MAX_LZW_BITS) - 1);
39
+ $this->Stack = range(0, (1 << ($this->MAX_LZW_BITS + 1)) - 1);
40
+ $this->Buf = range(0, 279);
41
+ }
42
+
43
+ ///////////////////////////////////////////////////////////////////////////
44
+
45
+ function deCompress($data, &$datLen)
46
+ {
47
+ $stLen = strlen($data);
48
+ $datLen = 0;
49
+ $ret = "";
50
+ $dp = 0; // data pointer
51
+
52
+ // INITIALIZATION
53
+ $this->LZWCommandInit($data, $dp);
54
+
55
+ while(($iIndex = $this->LZWCommand($data, $dp)) >= 0) {
56
+ $ret .= chr($iIndex);
57
+ }
58
+
59
+ $datLen = $dp;
60
+
61
+ if($iIndex != -2) {
62
+ return false;
63
+ }
64
+
65
+ return $ret;
66
+ }
67
+
68
+ ///////////////////////////////////////////////////////////////////////////
69
+ function LZWCommandInit(&$data, &$dp)
70
+ {
71
+ $this->SetCodeSize = ord($data[0]);
72
+ $dp += 1;
73
+
74
+ $this->CodeSize = $this->SetCodeSize + 1;
75
+ $this->ClearCode = 1 << $this->SetCodeSize;
76
+ $this->EndCode = $this->ClearCode + 1;
77
+ $this->MaxCode = $this->ClearCode + 2;
78
+ $this->MaxCodeSize = $this->ClearCode << 1;
79
+
80
+ $this->GetCodeInit($data, $dp);
81
+
82
+ $this->Fresh = 1;
83
+ for($i = 0; $i < $this->ClearCode; $i++) {
84
+ $this->Next[$i] = 0;
85
+ $this->Vals[$i] = $i;
86
+ }
87
+
88
+ for(; $i < (1 << $this->MAX_LZW_BITS); $i++) {
89
+ $this->Next[$i] = 0;
90
+ $this->Vals[$i] = 0;
91
+ }
92
+
93
+ $this->sp = 0;
94
+ return 1;
95
+ }
96
+
97
+ function LZWCommand(&$data, &$dp)
98
+ {
99
+ if($this->Fresh) {
100
+ $this->Fresh = 0;
101
+ do {
102
+ $this->FirstCode = $this->GetCode($data, $dp);
103
+ $this->OldCode = $this->FirstCode;
104
+ }
105
+ while($this->FirstCode == $this->ClearCode);
106
+
107
+ return $this->FirstCode;
108
+ }
109
+
110
+ if($this->sp > 0) {
111
+ $this->sp--;
112
+ return $this->Stack[$this->sp];
113
+ }
114
+
115
+ while(($Code = $this->GetCode($data, $dp)) >= 0) {
116
+ if($Code == $this->ClearCode) {
117
+ for($i = 0; $i < $this->ClearCode; $i++) {
118
+ $this->Next[$i] = 0;
119
+ $this->Vals[$i] = $i;
120
+ }
121
+
122
+ for(; $i < (1 << $this->MAX_LZW_BITS); $i++) {
123
+ $this->Next[$i] = 0;
124
+ $this->Vals[$i] = 0;
125
+ }
126
+
127
+ $this->CodeSize = $this->SetCodeSize + 1;
128
+ $this->MaxCodeSize = $this->ClearCode << 1;
129
+ $this->MaxCode = $this->ClearCode + 2;
130
+ $this->sp = 0;
131
+ $this->FirstCode = $this->GetCode($data, $dp);
132
+ $this->OldCode = $this->FirstCode;
133
+
134
+ return $this->FirstCode;
135
+ }
136
+
137
+ if($Code == $this->EndCode) {
138
+ return -2;
139
+ }
140
+
141
+ $InCode = $Code;
142
+ if($Code >= $this->MaxCode) {
143
+ $this->Stack[$this->sp++] = $this->FirstCode;
144
+ $Code = $this->OldCode;
145
+ }
146
+
147
+ while($Code >= $this->ClearCode) {
148
+ $this->Stack[$this->sp++] = $this->Vals[$Code];
149
+
150
+ if($Code == $this->Next[$Code]) // Circular table entry, big GIF Error!
151
+ return -1;
152
+
153
+ $Code = $this->Next[$Code];
154
+ }
155
+
156
+ $this->FirstCode = $this->Vals[$Code];
157
+ $this->Stack[$this->sp++] = $this->FirstCode;
158
+
159
+ if(($Code = $this->MaxCode) < (1 << $this->MAX_LZW_BITS)) {
160
+ $this->Next[$Code] = $this->OldCode;
161
+ $this->Vals[$Code] = $this->FirstCode;
162
+ $this->MaxCode++;
163
+
164
+ if(($this->MaxCode >= $this->MaxCodeSize) && ($this->MaxCodeSize < (1 << $this->MAX_LZW_BITS))) {
165
+ $this->MaxCodeSize *= 2;
166
+ $this->CodeSize++;
167
+ }
168
+ }
169
+
170
+ $this->OldCode = $InCode;
171
+ if($this->sp > 0) {
172
+ $this->sp--;
173
+ return $this->Stack[$this->sp];
174
+ }
175
+ }
176
+
177
+ return $Code;
178
+ }
179
+
180
+ ///////////////////////////////////////////////////////////////////////////
181
+
182
+ function GetCodeInit(&$data, &$dp)
183
+ {
184
+ $this->CurBit = 0;
185
+ $this->LastBit = 0;
186
+ $this->Done = 0;
187
+ $this->LastByte = 2;
188
+ return 1;
189
+ }
190
+
191
+ function GetCode(&$data, &$dp)
192
+ {
193
+ if(($this->CurBit + $this->CodeSize) >= $this->LastBit) {
194
+ if($this->Done) {
195
+ if($this->CurBit >= $this->LastBit) {
196
+ // Ran off the end of my bits
197
+ return 0;
198
+ }
199
+ return -1;
200
+ }
201
+
202
+ $this->Buf[0] = $this->Buf[$this->LastByte - 2];
203
+ $this->Buf[1] = $this->Buf[$this->LastByte - 1];
204
+
205
+ $Count = ord($data[$dp]);
206
+ $dp += 1;
207
+
208
+ if($Count) {
209
+ for($i = 0; $i < $Count; $i++) {
210
+ $this->Buf[2 + $i] = ord($data[$dp+$i]);
211
+ }
212
+ $dp += $Count;
213
+ }
214
+ else {
215
+ $this->Done = 1;
216
+ }
217
+
218
+ $this->LastByte = 2 + $Count;
219
+ $this->CurBit = ($this->CurBit - $this->LastBit) + 16;
220
+ $this->LastBit = (2 + $Count) << 3;
221
+ }
222
+
223
+ $iRet = 0;
224
+ for($i = $this->CurBit, $j = 0; $j < $this->CodeSize; $i++, $j++) {
225
+ $iRet |= (($this->Buf[intval($i / 8)] & (1 << ($i % 8))) != 0) << $j;
226
+ }
227
+
228
+ $this->CurBit += $this->CodeSize;
229
+ return $iRet;
230
+ }
231
+ }
232
+
233
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
234
+
235
+ class CGIFCOLORTABLE
236
+ {
237
+ var $m_nColors;
238
+ var $m_arColors;
239
+
240
+ ///////////////////////////////////////////////////////////////////////////
241
+
242
+ // CONSTRUCTOR
243
+ function CGIFCOLORTABLE()
244
+ {
245
+ unSet($this->m_nColors);
246
+ unSet($this->m_arColors);
247
+ }
248
+
249
+ ///////////////////////////////////////////////////////////////////////////
250
+
251
+ function load($lpData, $num)
252
+ {
253
+ $this->m_nColors = 0;
254
+ $this->m_arColors = array();
255
+
256
+ for($i = 0; $i < $num; $i++) {
257
+ $rgb = substr($lpData, $i * 3, 3);
258
+ if(strlen($rgb) < 3) {
259
+ return false;
260
+ }
261
+
262
+ $this->m_arColors[] = (ord($rgb[2]) << 16) + (ord($rgb[1]) << 8) + ord($rgb[0]);
263
+ $this->m_nColors++;
264
+ }
265
+
266
+ return true;
267
+ }
268
+
269
+ ///////////////////////////////////////////////////////////////////////////
270
+
271
+ function toString()
272
+ {
273
+ $ret = "";
274
+
275
+ for($i = 0; $i < $this->m_nColors; $i++) {
276
+ $ret .=
277
+ chr(($this->m_arColors[$i] & 0x000000FF)) . // R
278
+ chr(($this->m_arColors[$i] & 0x0000FF00) >> 8) . // G
279
+ chr(($this->m_arColors[$i] & 0x00FF0000) >> 16); // B
280
+ }
281
+
282
+ return $ret;
283
+ }
284
+
285
+
286
+ ///////////////////////////////////////////////////////////////////////////
287
+
288
+ function colorIndex($rgb)
289
+ {
290
+ $rgb = intval($rgb) & 0xFFFFFF;
291
+ $r1 = ($rgb & 0x0000FF);
292
+ $g1 = ($rgb & 0x00FF00) >> 8;
293
+ $b1 = ($rgb & 0xFF0000) >> 16;
294
+ $idx = -1;
295
+
296
+ for($i = 0; $i < $this->m_nColors; $i++) {
297
+ $r2 = ($this->m_arColors[$i] & 0x000000FF);
298
+ $g2 = ($this->m_arColors[$i] & 0x0000FF00) >> 8;
299
+ $b2 = ($this->m_arColors[$i] & 0x00FF0000) >> 16;
300
+ $d = abs($r2 - $r1) + abs($g2 - $g1) + abs($b2 - $b1);
301
+
302
+ if(($idx == -1) || ($d < $dif)) {
303
+ $idx = $i;
304
+ $dif = $d;
305
+ }
306
+ }
307
+
308
+ return $idx;
309
+ }
310
+ }
311
+
312
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
313
+
314
+ class CGIFFILEHEADER
315
+ {
316
+ var $m_lpVer;
317
+ var $m_nWidth;
318
+ var $m_nHeight;
319
+ var $m_bGlobalClr;
320
+ var $m_nColorRes;
321
+ var $m_bSorted;
322
+ var $m_nTableSize;
323
+ var $m_nBgColor;
324
+ var $m_nPixelRatio;
325
+ var $m_colorTable;
326
+
327
+ ///////////////////////////////////////////////////////////////////////////
328
+
329
+ // CONSTRUCTOR
330
+ function CGIFFILEHEADER()
331
+ {
332
+ unSet($this->m_lpVer);
333
+ unSet($this->m_nWidth);
334
+ unSet($this->m_nHeight);
335
+ unSet($this->m_bGlobalClr);
336
+ unSet($this->m_nColorRes);
337
+ unSet($this->m_bSorted);
338
+ unSet($this->m_nTableSize);
339
+ unSet($this->m_nBgColor);
340
+ unSet($this->m_nPixelRatio);
341
+ unSet($this->m_colorTable);
342
+ }
343
+
344
+ ///////////////////////////////////////////////////////////////////////////
345
+
346
+ function load($lpData, &$hdrLen)
347
+ {
348
+ $hdrLen = 0;
349
+
350
+ $this->m_lpVer = substr($lpData, 0, 6);
351
+ if(($this->m_lpVer <> "GIF87a") && ($this->m_lpVer <> "GIF89a")) {
352
+ return false;
353
+ }
354
+
355
+ $this->m_nWidth = $this->w2i(substr($lpData, 6, 2));
356
+ $this->m_nHeight = $this->w2i(substr($lpData, 8, 2));
357
+ if(!$this->m_nWidth || !$this->m_nHeight) {
358
+ return false;
359
+ }
360
+
361
+ $b = ord(substr($lpData, 10, 1));
362
+ $this->m_bGlobalClr = ($b & 0x80) ? true : false;
363
+ $this->m_nColorRes = ($b & 0x70) >> 4;
364
+ $this->m_bSorted = ($b & 0x08) ? true : false;
365
+ $this->m_nTableSize = 2 << ($b & 0x07);
366
+ $this->m_nBgColor = ord(substr($lpData, 11, 1));
367
+ $this->m_nPixelRatio = ord(substr($lpData, 12, 1));
368
+ $hdrLen = 13;
369
+
370
+ if($this->m_bGlobalClr) {
371
+ $this->m_colorTable = new CGIFCOLORTABLE();
372
+ if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
373
+ return false;
374
+ }
375
+ $hdrLen += 3 * $this->m_nTableSize;
376
+ }
377
+
378
+ return true;
379
+ }
380
+
381
+ ///////////////////////////////////////////////////////////////////////////
382
+
383
+ function w2i($str)
384
+ {
385
+ return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
386
+ }
387
+ }
388
+
389
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
390
+
391
+ class CGIFIMAGEHEADER
392
+ {
393
+ var $m_nLeft;
394
+ var $m_nTop;
395
+ var $m_nWidth;
396
+ var $m_nHeight;
397
+ var $m_bLocalClr;
398
+ var $m_bInterlace;
399
+ var $m_bSorted;
400
+ var $m_nTableSize;
401
+ var $m_colorTable;
402
+
403
+ ///////////////////////////////////////////////////////////////////////////
404
+
405
+ // CONSTRUCTOR
406
+ function CGIFIMAGEHEADER()
407
+ {
408
+ unSet($this->m_nLeft);
409
+ unSet($this->m_nTop);
410
+ unSet($this->m_nWidth);
411
+ unSet($this->m_nHeight);
412
+ unSet($this->m_bLocalClr);
413
+ unSet($this->m_bInterlace);
414
+ unSet($this->m_bSorted);
415
+ unSet($this->m_nTableSize);
416
+ unSet($this->m_colorTable);
417
+ }
418
+
419
+ ///////////////////////////////////////////////////////////////////////////
420
+
421
+ function load($lpData, &$hdrLen)
422
+ {
423
+ $hdrLen = 0;
424
+
425
+ $this->m_nLeft = $this->w2i(substr($lpData, 0, 2));
426
+ $this->m_nTop = $this->w2i(substr($lpData, 2, 2));
427
+ $this->m_nWidth = $this->w2i(substr($lpData, 4, 2));
428
+ $this->m_nHeight = $this->w2i(substr($lpData, 6, 2));
429
+
430
+ if(!$this->m_nWidth || !$this->m_nHeight) {
431
+ return false;
432
+ }
433
+
434
+ $b = ord($lpData{8});
435
+ $this->m_bLocalClr = ($b & 0x80) ? true : false;
436
+ $this->m_bInterlace = ($b & 0x40) ? true : false;
437
+ $this->m_bSorted = ($b & 0x20) ? true : false;
438
+ $this->m_nTableSize = 2 << ($b & 0x07);
439
+ $hdrLen = 9;
440
+
441
+ if($this->m_bLocalClr) {
442
+ $this->m_colorTable = new CGIFCOLORTABLE();
443
+ if(!$this->m_colorTable->load(substr($lpData, $hdrLen), $this->m_nTableSize)) {
444
+ return false;
445
+ }
446
+ $hdrLen += 3 * $this->m_nTableSize;
447
+ }
448
+
449
+ return true;
450
+ }
451
+
452
+ ///////////////////////////////////////////////////////////////////////////
453
+
454
+ function w2i($str)
455
+ {
456
+ return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
457
+ }
458
+ }
459
+
460
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
461
+
462
+ class CGIFIMAGE
463
+ {
464
+ var $m_disp;
465
+ var $m_bUser;
466
+ var $m_bTrans;
467
+ var $m_nDelay;
468
+ var $m_nTrans;
469
+ var $m_lpComm;
470
+ var $m_gih;
471
+ var $m_data;
472
+ var $m_lzw;
473
+
474
+ ///////////////////////////////////////////////////////////////////////////
475
+
476
+ function CGIFIMAGE()
477
+ {
478
+ unSet($this->m_disp);
479
+ unSet($this->m_bUser);
480
+ unSet($this->m_bTrans);
481
+ unSet($this->m_nDelay);
482
+ unSet($this->m_nTrans);
483
+ unSet($this->m_lpComm);
484
+ unSet($this->m_data);
485
+ $this->m_gih = new CGIFIMAGEHEADER();
486
+ $this->m_lzw = new CGIFLZW();
487
+ }
488
+
489
+ ///////////////////////////////////////////////////////////////////////////
490
+
491
+ function load($data, &$datLen)
492
+ {
493
+ $datLen = 0;
494
+
495
+ while(true) {
496
+ $b = ord($data[0]);
497
+ $data = substr($data, 1);
498
+ $datLen++;
499
+
500
+ switch($b) {
501
+ case 0x21: // Extension
502
+ $len = 0;
503
+ if(!$this->skipExt($data, $len)) {
504
+ return false;
505
+ }
506
+ $datLen += $len;
507
+ break;
508
+
509
+ case 0x2C: // Image
510
+ // LOAD HEADER & COLOR TABLE
511
+ $len = 0;
512
+ if(!$this->m_gih->load($data, $len)) {
513
+ return false;
514
+ }
515
+ $data = substr($data, $len);
516
+ $datLen += $len;
517
+
518
+ // ALLOC BUFFER
519
+ $len = 0;
520
+
521
+ if(!($this->m_data = $this->m_lzw->deCompress($data, $len))) {
522
+ return false;
523
+ }
524
+
525
+ $data = substr($data, $len);
526
+ $datLen += $len;
527
+
528
+ if($this->m_gih->m_bInterlace) {
529
+ $this->deInterlace();
530
+ }
531
+
532
+ return true;
533
+
534
+ case 0x3B: // EOF
535
+ default:
536
+ return false;
537
+ }
538
+ }
539
+ return false;
540
+ }
541
+
542
+ ///////////////////////////////////////////////////////////////////////////
543
+
544
+ function skipExt(&$data, &$extLen)
545
+ {
546
+ $extLen = 0;
547
+
548
+ $b = ord($data[0]);
549
+ $data = substr($data, 1);
550
+ $extLen++;
551
+
552
+ switch($b) {
553
+ case 0xF9: // Graphic Control
554
+ $b = ord($data[1]);
555
+ $this->m_disp = ($b & 0x1C) >> 2;
556
+ $this->m_bUser = ($b & 0x02) ? true : false;
557
+ $this->m_bTrans = ($b & 0x01) ? true : false;
558
+ $this->m_nDelay = $this->w2i(substr($data, 2, 2));
559
+ $this->m_nTrans = ord($data[4]);
560
+ break;
561
+
562
+ case 0xFE: // Comment
563
+ $this->m_lpComm = substr($data, 1, ord($data[0]));
564
+ break;
565
+
566
+ case 0x01: // Plain text
567
+ break;
568
+
569
+ case 0xFF: // Application
570
+ break;
571
+ }
572
+
573
+ // SKIP DEFAULT AS DEFS MAY CHANGE
574
+ $b = ord($data[0]);
575
+ $data = substr($data, 1);
576
+ $extLen++;
577
+ while($b > 0) {
578
+ $data = substr($data, $b);
579
+ $extLen += $b;
580
+ $b = ord($data[0]);
581
+ $data = substr($data, 1);
582
+ $extLen++;
583
+ }
584
+ return true;
585
+ }
586
+
587
+ ///////////////////////////////////////////////////////////////////////////
588
+
589
+ function w2i($str)
590
+ {
591
+ return ord(substr($str, 0, 1)) + (ord(substr($str, 1, 1)) << 8);
592
+ }
593
+
594
+ ///////////////////////////////////////////////////////////////////////////
595
+
596
+ function deInterlace()
597
+ {
598
+ $data = $this->m_data;
599
+
600
+ for($i = 0; $i < 4; $i++) {
601
+ switch($i) {
602
+ case 0:
603
+ $s = 8;
604
+ $y = 0;
605
+ break;
606
+
607
+ case 1:
608
+ $s = 8;
609
+ $y = 4;
610
+ break;
611
+
612
+ case 2:
613
+ $s = 4;
614
+ $y = 2;
615
+ break;
616
+
617
+ case 3:
618
+ $s = 2;
619
+ $y = 1;
620
+ break;
621
+ }
622
+
623
+ for(; $y < $this->m_gih->m_nHeight; $y += $s) {
624
+ $lne = substr($this->m_data, 0, $this->m_gih->m_nWidth);
625
+ $this->m_data = substr($this->m_data, $this->m_gih->m_nWidth);
626
+
627
+ $data =
628
+ substr($data, 0, $y * $this->m_gih->m_nWidth) .
629
+ $lne .
630
+ substr($data, ($y + 1) * $this->m_gih->m_nWidth);
631
+ }
632
+ }
633
+
634
+ $this->m_data = $data;
635
+ }
636
+ }
637
+
638
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
639
+
640
+ class CGIF
641
+ {
642
+ var $m_gfh;
643
+ var $m_lpData;
644
+ var $m_img;
645
+ var $m_bLoaded;
646
+
647
+ ///////////////////////////////////////////////////////////////////////////
648
+
649
+ // CONSTRUCTOR
650
+ function CGIF()
651
+ {
652
+ $this->m_gfh = new CGIFFILEHEADER();
653
+ $this->m_img = new CGIFIMAGE();
654
+ $this->m_lpData = "";
655
+ $this->m_bLoaded = false;
656
+ }
657
+
658
+ ///////////////////////////////////////////////////////////////////////////
659
+ function ClearData() {
660
+ $this->m_lpData = '';
661
+ unSet($this->m_img->m_data);
662
+ unSet($this->m_img->m_lzw->Next);
663
+ unSet($this->m_img->m_lzw->Vals);
664
+ unSet($this->m_img->m_lzw->Stack);
665
+ unSet($this->m_img->m_lzw->Buf);
666
+ }
667
+
668
+ function loadFile(&$data, $iIndex)
669
+ {
670
+ if($iIndex < 0) {
671
+ return false;
672
+ }
673
+ $this->m_lpData = $data;
674
+
675
+ // GET FILE HEADER
676
+ $len = 0;
677
+ if(!$this->m_gfh->load($this->m_lpData, $len)) {
678
+ return false;
679
+ }
680
+
681
+ $this->m_lpData = substr($this->m_lpData, $len);
682
+
683
+ do {
684
+ $imgLen = 0;
685
+ if(!$this->m_img->load($this->m_lpData, $imgLen)) {
686
+ return false;
687
+ }
688
+ $this->m_lpData = substr($this->m_lpData, $imgLen);
689
+ }
690
+ while($iIndex-- > 0);
691
+
692
+ $this->m_bLoaded = true;
693
+ return true;
694
+ }
695
+
696
+ }
697
+
698
+ ///////////////////////////////////////////////////////////////////////////////////////////////////
699
+
700
+ ?>
lib/mpdf/classes/grad.php ADDED
@@ -0,0 +1,724 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class grad {
4
+
5
+ var $mpdf = null;
6
+
7
+ function grad(&$mpdf) {
8
+ $this->mpdf = $mpdf;
9
+ }
10
+
11
+ // mPDF 5.3.A1
12
+ function CoonsPatchMesh($x, $y, $w, $h, $patch_array=array(), $x_min=0, $x_max=1, $y_min=0, $y_max=1, $colspace='RGB', $return=false){
13
+ $s=' q ';
14
+ $s.=sprintf(' %.3F %.3F %.3F %.3F re W n ', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK);
15
+ $s.=sprintf(' %.3F 0 0 %.3F %.3F %.3F cm ', $w*_MPDFK, $h*_MPDFK, $x*_MPDFK, ($this->mpdf->h-($y+$h))*_MPDFK);
16
+ $n = count($this->mpdf->gradients)+1;
17
+ $this->mpdf->gradients[$n]['type'] = 6; //coons patch mesh
18
+ $this->mpdf->gradients[$n]['colorspace'] = $colspace; //coons patch mesh
19
+ $bpcd=65535; //16 BitsPerCoordinate
20
+ $trans = false;
21
+ $this->mpdf->gradients[$n]['stream']='';
22
+ for($i=0;$i<count($patch_array);$i++){
23
+ $this->mpdf->gradients[$n]['stream'].=chr($patch_array[$i]['f']); //start with the edge flag as 8 bit
24
+ for($j=0;$j<count($patch_array[$i]['points']);$j++){
25
+ //each point as 16 bit
26
+ if (($j % 2) == 1) { // Y coordinate (adjusted as input is From top left)
27
+ $patch_array[$i]['points'][$j]=(($patch_array[$i]['points'][$j]-$y_min)/($y_max-$y_min))*$bpcd;
28
+ $patch_array[$i]['points'][$j]=$bpcd-$patch_array[$i]['points'][$j];
29
+ }
30
+ else {
31
+ $patch_array[$i]['points'][$j]=(($patch_array[$i]['points'][$j]-$x_min)/($x_max-$x_min))*$bpcd;
32
+ }
33
+ if($patch_array[$i]['points'][$j]<0) $patch_array[$i]['points'][$j]=0;
34
+ if($patch_array[$i]['points'][$j]>$bpcd) $patch_array[$i]['points'][$j]=$bpcd;
35
+ $this->mpdf->gradients[$n]['stream'].=chr(floor($patch_array[$i]['points'][$j]/256));
36
+ $this->mpdf->gradients[$n]['stream'].=chr(floor($patch_array[$i]['points'][$j]%256));
37
+ }
38
+ for($j=0;$j<count($patch_array[$i]['colors']);$j++){
39
+ //each color component as 8 bit
40
+ if ($colspace=='RGB') {
41
+ $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][1]);
42
+ $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][2]);
43
+ $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][3]);
44
+ if (isset($patch_array[$i]['colors'][$j][4]) && ord($patch_array[$i]['colors'][$j][4])<100) { $trans = true; }
45
+ }
46
+ else if ($colspace=='CMYK') {
47
+ $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][1])*2.55);
48
+ $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][2])*2.55);
49
+ $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][3])*2.55);
50
+ $this->mpdf->gradients[$n]['stream'].=chr(ord($patch_array[$i]['colors'][$j][4])*2.55);
51
+ if (isset($patch_array[$i]['colors'][$j][5]) && ord($patch_array[$i]['colors'][$j][5])<100) { $trans = true; }
52
+ }
53
+ else if ($colspace=='Gray') {
54
+ $this->mpdf->gradients[$n]['stream'].=($patch_array[$i]['colors'][$j][1]);
55
+ if ($patch_array[$i]['colors'][$j][2]==1) { $trans = true; } // transparency converted from rgba or cmyka()
56
+ }
57
+ }
58
+ }
59
+ // TRANSPARENCY
60
+ if ($trans) {
61
+ $this->mpdf->gradients[$n]['stream_trans']='';
62
+ for($i=0;$i<count($patch_array);$i++){
63
+ $this->mpdf->gradients[$n]['stream_trans'].=chr($patch_array[$i]['f']);
64
+ for($j=0;$j<count($patch_array[$i]['points']);$j++){
65
+ //each point as 16 bit
66
+ $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j]/256));
67
+ $this->mpdf->gradients[$n]['stream_trans'].=chr(floor($patch_array[$i]['points'][$j]%256));
68
+ }
69
+ for($j=0;$j<count($patch_array[$i]['colors']);$j++){
70
+ //each color component as 8 bit // OPACITY
71
+ if ($colspace=='RGB') {
72
+ $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][4])*2.55));
73
+ }
74
+ else if ($colspace=='CMYK') {
75
+ $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][5])*2.55));
76
+ }
77
+ else if ($colspace=='Gray') {
78
+ $this->mpdf->gradients[$n]['stream_trans'].=chr(intval(ord($patch_array[$i]['colors'][$j][3])*2.55));
79
+ }
80
+ }
81
+ }
82
+ $this->mpdf->gradients[$n]['trans'] = true;
83
+ $s .= ' /TGS'.$n.' gs ';
84
+ }
85
+ //paint the gradient
86
+ $s .= '/Sh'.$n.' sh'."\n";
87
+ //restore previous Graphic State
88
+ $s .= 'Q'."\n";
89
+ if ($return) { return $s; }
90
+ else { $this->mpdf->_out($s); }
91
+ }
92
+
93
+
94
+ // type = linear:2; radial: 3;
95
+ // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
96
+ // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
97
+ // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
98
+ // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
99
+ // (fx, fy) should be inside the circle, otherwise some areas will not be defined
100
+ // $col = array(R,G,B/255); or array(G/255); or array(C,M,Y,K/100)
101
+ // $stops = array('col'=>$col [, 'opacity'=>0-1] [, 'offset'=>0-1])
102
+ function Gradient($x, $y, $w, $h, $type, $stops=array(), $colorspace='RGB', $coords='', $extend='', $return=false, $is_mask=false) {
103
+ if (strtoupper(substr($type,0,1)) == 'L') { $type = 2; } // linear
104
+ else if (strtoupper(substr($type,0,1)) == 'R') { $type = 3; } // radial
105
+ if ($colorspace != 'CMYK' && $colorspace != 'Gray') {
106
+ $colorspace = 'RGB';
107
+ }
108
+ $bboxw = $w;
109
+ $bboxh = $h;
110
+ $usex = $x;
111
+ $usey = $y;
112
+ $usew = $bboxw;
113
+ $useh = $bboxh;
114
+
115
+ if ($type < 1) { $type = 2; }
116
+ if ($coords[0]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[0],$m)) {
117
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
118
+ if ($tmp) { $coords[0] = $tmp/$w; }
119
+ }
120
+ if ($coords[1]!==false && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$coords[1],$m)) {
121
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
122
+ if ($tmp) { $coords[1] = 1-($tmp/$h); }
123
+ }
124
+ // LINEAR
125
+ if ($type == 2) {
126
+ $angle = (isset($coords[4]) ? $coords[4] : false);
127
+ $repeat = (isset($coords[5]) ? $coords[5] : false);
128
+ // ALL POINTS SET (default for custom mPDF linear gradient) - no -moz
129
+ if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false) {
130
+ // do nothing - coords used as they are
131
+ }
132
+
133
+ // If both a <point> and <angle> are defined, the gradient axis starts from the point and runs along the angle. The end point is
134
+ // defined as before - in this case start points may not be in corners, and axis may not correctly fall in the right quadrant.
135
+ // NO end points (Angle defined & Start points)
136
+ else if ($angle!==false && $coords[0]!==false && $coords[1]!==false && $coords[2]===false && $coords[3]===false) {
137
+ if ($angle==0 || $angle==360) { $coords[3]=$coords[1]; if ($coords[0]==1) $coords[2]=2; else $coords[2]=1; }
138
+ else if ($angle==90) { $coords[2]=$coords[0]; $coords[3]=1; if ($coords[1]==1) $coords[3]=2; else $coords[3]=1; }
139
+ else if ($angle==180) { if ($coords[4]==0) $coords[2]=-1; else $coords[2]=0; $coords[3]=$coords[1]; }
140
+ else if ($angle==270) { $coords[2]=$coords[0]; if ($coords[1]==0) $coords[3]=-1; else $coords[3]=0; }
141
+ else {
142
+ $endx=1; $endy=1;
143
+ if ($angle <=90) {
144
+ if ($angle <=45) { $endy=tan(deg2rad($angle)); }
145
+ else { $endx=tan(deg2rad(90-$angle)); }
146
+ $b = atan2(($endy*$bboxh), ($endx*$bboxw));
147
+ $ny = 1 - $coords[1] - (tan($b) * (1-$coords[0]));
148
+ $tx = sin($b) * cos($b) * $ny;
149
+ $ty = cos($b) * cos($b) * $ny;
150
+ $coords[2] = 1+$tx; $coords[3] = 1-$ty;
151
+ }
152
+ else if ($angle <=180) {
153
+ if ($angle <=135) { $endx=tan(deg2rad($angle-90)); }
154
+ else { $endy=tan(deg2rad(180-$angle)); }
155
+ $b = atan2(($endy*$bboxh), ($endx*$bboxw));
156
+ $ny = 1 - $coords[1] - (tan($b) * ($coords[0]));
157
+ $tx = sin($b) * cos($b) * $ny;
158
+ $ty = cos($b) * cos($b) * $ny;
159
+ $coords[2] = -$tx; $coords[3] = 1-$ty;
160
+ }
161
+ else if ($angle <=270) {
162
+ if ($angle <=225) { $endy=tan(deg2rad($angle-180)); }
163
+ else { $endx=tan(deg2rad(270-$angle)); }
164
+ $b = atan2(($endy*$bboxh), ($endx*$bboxw));
165
+ $ny = $coords[1] - (tan($b) * ($coords[0]));
166
+ $tx = sin($b) * cos($b) * $ny;
167
+ $ty = cos($b) * cos($b) * $ny;
168
+ $coords[2] = -$tx; $coords[3] = $ty;
169
+ }
170
+ else {
171
+ if ($angle <=315) { $endx=tan(deg2rad($angle-270)); }
172
+ else { $endy=tan(deg2rad(360-$angle)); }
173
+ $b = atan2(($endy*$bboxh), ($endx*$bboxw));
174
+ $ny = $coords[1] - (tan($b) * (1-$coords[0]));
175
+ $tx = sin($b) * cos($b) * $ny;
176
+ $ty = cos($b) * cos($b) * $ny;
177
+ $coords[2] = 1+$tx; $coords[3] = $ty;
178
+
179
+ }
180
+ }
181
+ }
182
+
183
+ // -moz If the first parameter is only an <angle>, the gradient axis starts from the box's corner that would ensure the
184
+ // axis goes through the box. The axis runs along the specified angle. The end point of the axis is defined such that the
185
+ // farthest corner of the box from the starting point is perpendicular to the gradient axis at that point.
186
+ // NO end points or Start points (Angle defined)
187
+ else if ($angle!==false && $coords[0]===false && $coords[1]===false) {
188
+ if ($angle==0 || $angle==360) { $coords[0]=0; $coords[1]=0; $coords[2]=1; $coords[3]=0; }
189
+ else if ($angle==90) { $coords[0]=0; $coords[1]=0; $coords[2]=0; $coords[3]=1; }
190
+ else if ($angle==180) { $coords[0]=1; $coords[1]=0; $coords[2]=0; $coords[3]=0; }
191
+ else if ($angle==270) { $coords[0]=0; $coords[1]=1; $coords[2]=0; $coords[3]=0; }
192
+ else {
193
+ if ($angle <=90) {
194
+ $coords[0]=0; $coords[1]=0;
195
+ if ($angle <=45) { $endx=1; $endy=tan(deg2rad($angle)); }
196
+ else { $endx=tan(deg2rad(90-$angle)); $endy=1; }
197
+ }
198
+ else if ($angle <=180) {
199
+ $coords[0]=1; $coords[1]=0;
200
+ if ($angle <=135) { $endx=tan(deg2rad($angle-90)); $endy=1; }
201
+ else { $endx=1; $endy=tan(deg2rad(180-$angle)); }
202
+ }
203
+ else if ($angle <=270) {
204
+ $coords[0]=1; $coords[1]=1;
205
+ if ($angle <=225) { $endx=1; $endy=tan(deg2rad($angle-180)); }
206
+ else { $endx=tan(deg2rad(270-$angle)); $endy=1; }
207
+ }
208
+ else {
209
+ $coords[0]=0; $coords[1]=1;
210
+ if ($angle <=315) { $endx=tan(deg2rad($angle-270)); $endy=1; }
211
+ else { $endx=1; $endy=tan(deg2rad(360-$angle)); }
212
+ }
213
+ $b = atan2(($endy*$bboxh), ($endx*$bboxw));
214
+ $h2 = $bboxh - ($bboxh * tan($b));
215
+ $px = $bboxh + ($h2 * sin($b) * cos($b));
216
+ $py = ($bboxh * tan($b)) + ($h2 * sin($b) * sin($b));
217
+ $x1 = $px / $bboxh;
218
+ $y1 = $py / $bboxh;
219
+ if ($angle <=90) { $coords[2] = $x1; $coords[3] = $y1; }
220
+ else if ($angle <=180) { $coords[2] = 1-$x1; $coords[3] = $y1; }
221
+ else if ($angle <=270) { $coords[2] = 1-$x1; $coords[3] = 1-$y1; }
222
+ else { $coords[2] = $x1; $coords[3] = 1-$y1; }
223
+ }
224
+ }
225
+ // -moz If the first parameter to the gradient function is only a <point>, the gradient axis starts from the specified point,
226
+ // and ends at the point you would get if you rotated the starting point by 180 degrees about the center of the box that the
227
+ // gradient is to be applied to.
228
+ // NO angle and NO end points (Start points defined)
229
+ else if ((!isset($angle) || $angle===false) && $coords[0]!==false && $coords[1]!==false) { // should have start and end defined
230
+ $coords[2] = 1-$coords[0]; $coords[3] = 1-$coords[1];
231
+ $angle = rad2deg(atan2($coords[3]-$coords[1],$coords[2]-$coords[0]));
232
+ if ($angle < 0) { $angle += 360; }
233
+ else if ($angle > 360) { $angle -= 360; }
234
+ if ($angle!=0 && $angle!=360 && $angle!=90 && $angle!=180 && $angle!=270) {
235
+ if ($w >= $h) {
236
+ $coords[1] *= $h/$w ;
237
+ $coords[3] *= $h/$w ;
238
+ $usew = $useh = $bboxw;
239
+ $usey -= ($w-$h);
240
+ }
241
+ else {
242
+ $coords[0] *= $w/$h ;
243
+ $coords[2] *= $w/$h ;
244
+ $usew = $useh = $bboxh;
245
+ }
246
+ }
247
+ }
248
+
249
+ // -moz If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient
250
+ // axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
251
+ else { // default values T2B
252
+ // All values are set in parseMozGradient - so won't appear here
253
+ $coords = array(0,0,1,0); // default for original linear gradient (L2R)
254
+ }
255
+ $s = ' q';
256
+ $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK)."\n";
257
+ $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*_MPDFK, $useh*_MPDFK, $usex*_MPDFK, ($this->mpdf->h-($usey+$useh))*_MPDFK)."\n";
258
+ }
259
+
260
+ // RADIAL
261
+ else if ($type == 3) {
262
+ $radius = (isset($coords[4]) ? $coords[4] : false);
263
+ $angle = (isset($coords[5]) ? $coords[5] : false); // ?? no effect
264
+ $shape = (isset($coords[6]) ? $coords[6] : false);
265
+ $size = (isset($coords[7]) ? $coords[7] : false);
266
+ $repeat = (isset($coords[8]) ? $coords[8] : false);
267
+ // ALL POINTS AND RADIUS SET (default for custom mPDF radial gradient) - no -moz
268
+ if ($coords[0]!==false && $coords[1]!==false && $coords[2]!==false && $coords[3]!==false && $coords[4]!==false) {
269
+ // do nothing - coords used as they are
270
+ }
271
+ // If a <point> is defined
272
+ else if ($shape!==false && $size!==false) {
273
+ if ($coords[2]==false) { $coords[2] = $coords[0]; }
274
+ if ($coords[3]==false) { $coords[3] = $coords[1]; }
275
+ // ELLIPSE
276
+ if ($shape=='ellipse') {
277
+ $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
278
+ $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
279
+ $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
280
+ $corner4 = sqrt(pow((1-$coords[0]),2) + pow((1-$coords[1]),2));
281
+ if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
282
+ else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
283
+ else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (1-$coords[1])); }
284
+ else { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
285
+ }
286
+ // CIRCLE
287
+ else if ($shape=='circle') {
288
+ if ($w >= $h) {
289
+ $coords[1] = $coords[3] = ($coords[1] * $h/$w) ;
290
+ $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
291
+ $corner2 = sqrt(pow($coords[0],2) + pow((($h/$w)-$coords[1]),2));
292
+ $corner3 = sqrt(pow((1-$coords[0]),2) + pow($coords[1],2));
293
+ $corner4 = sqrt(pow((1-$coords[0]),2) + pow((($h/$w)-$coords[1]),2));
294
+ if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
295
+ else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
296
+ else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (1-$coords[0]), (($h/$w)-$coords[1])); }
297
+ else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
298
+ $usew = $useh = $bboxw;
299
+ $usey -= ($w-$h);
300
+ }
301
+ else {
302
+ $coords[0] = $coords[2] = ($coords[0] * $w/$h) ;
303
+ $corner1 = sqrt(pow($coords[0],2) + pow($coords[1],2));
304
+ $corner2 = sqrt(pow($coords[0],2) + pow((1-$coords[1]),2));
305
+ $corner3 = sqrt(pow((($w/$h)-$coords[0]),2) + pow($coords[1],2));
306
+ $corner4 = sqrt(pow((($w/$h)-$coords[0]),2) + pow((1-$coords[1]),2));
307
+ if ($size=='closest-side') { $radius = min($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
308
+ else if ($size=='closest-corner') { $radius = min($corner1, $corner2, $corner3, $corner4); }
309
+ else if ($size=='farthest-side') { $radius = max($coords[0], $coords[1], (($w/$h)-$coords[0]), (1-$coords[1])); }
310
+ else if ($size=='farthest-corner') { $radius = max($corner1, $corner2, $corner3, $corner4); } // farthest corner (default)
311
+ $usew = $useh = $bboxh;
312
+ }
313
+ }
314
+ if ($radius==0) { $radius=0.001; } // to prevent error
315
+ $coords[4] = $radius;
316
+ }
317
+
318
+ // -moz If entire function consists of only <stop> values
319
+ else { // default values
320
+ // All values are set in parseMozGradient - so won't appear here
321
+ $coords = array(0.5,0.5,0.5,0.5); // default for radial gradient (centred)
322
+ }
323
+ $s = ' q';
324
+ $s .= sprintf(' %.3F %.3F %.3F %.3F re W n', $x*_MPDFK, ($this->mpdf->h-$y)*_MPDFK, $w*_MPDFK, -$h*_MPDFK)."\n";
325
+ $s .= sprintf(' %.3F 0 0 %.3F %.3F %.3F cm', $usew*_MPDFK, $useh*_MPDFK, $usex*_MPDFK, ($this->mpdf->h-($usey+$useh))*_MPDFK)."\n";
326
+ }
327
+
328
+ $n = count($this->mpdf->gradients) + 1;
329
+ $this->mpdf->gradients[$n]['type'] = $type;
330
+ $this->mpdf->gradients[$n]['colorspace'] = $colorspace;
331
+ $trans = false;
332
+ $this->mpdf->gradients[$n]['is_mask'] = $is_mask;
333
+ if ($is_mask) { $trans = true; }
334
+ if (count($stops) == 1) { $stops[1] = $stops[0]; }
335
+ if (!isset($stops[0]['offset'])) { $stops[0]['offset'] = 0; }
336
+ if (!isset($stops[(count($stops)-1)]['offset'])) { $stops[(count($stops)-1)]['offset'] = 1; }
337
+
338
+ // Fix stop-offsets set as absolute lengths
339
+ if ($type==2) {
340
+ $axisx = ($coords[2]-$coords[0])*$usew;
341
+ $axisy = ($coords[3]-$coords[1])*$useh;
342
+ $axis_length = sqrt(pow($axisx,2) + pow($axisy,2));
343
+ }
344
+ else { $axis_length = $coords[4]*$usew; } // Absolute lengths are meaningless for an ellipse - Firefox uses Width as reference
345
+
346
+ for($i=0;$i<count($stops);$i++) {
347
+ if (isset($stops[$i]['offset']) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$stops[$i]['offset'],$m)) {
348
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
349
+ $stops[$i]['offset'] = $tmp/$axis_length;
350
+ }
351
+ }
352
+
353
+
354
+ if (isset($stops[0]['offset']) && $stops[0]['offset']>0) {
355
+ $firststop = $stops[0];
356
+ $firststop['offset'] = 0;
357
+ array_unshift($stops, $firststop);
358
+ }
359
+ if (!$repeat && isset($stops[(count($stops)-1)]['offset']) && $stops[(count($stops)-1)]['offset']<1) {
360
+ $endstop = $stops[(count($stops)-1)];
361
+ $endstop['offset'] = 1;
362
+ $stops[] = $endstop;
363
+ }
364
+ if ($stops[0]['offset'] > $stops[(count($stops)-1)]['offset']) {
365
+ $stops[0]['offset'] = 0;
366
+ $stops[(count($stops)-1)]['offset'] = 1;
367
+ }
368
+
369
+ for($i=0;$i<count($stops);$i++) {
370
+ // mPDF 5.3.74
371
+ if ($colorspace == 'CMYK') {
372
+ $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F %.3F', (ord($stops[$i]['col']{1})/100), (ord($stops[$i]['col']{2})/100), (ord($stops[$i]['col']{3})/100), (ord($stops[$i]['col']{4})/100));
373
+ }
374
+ else if ($colorspace == 'Gray') {
375
+ $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F', (ord($stops[$i]['col']{1})/255));
376
+ }
377
+ else {
378
+ $this->mpdf->gradients[$n]['stops'][$i]['col'] = sprintf('%.3F %.3F %.3F', (ord($stops[$i]['col']{1})/255), (ord($stops[$i]['col']{2})/255), (ord($stops[$i]['col']{3})/255));
379
+ }
380
+ if (!isset($stops[$i]['opacity'])) { $stops[$i]['opacity'] = 1; }
381
+ else if ($stops[$i]['opacity'] > 1 || $stops[$i]['opacity'] < 0) { $stops[$i]['opacity'] = 1; }
382
+ else if ($stops[$i]['opacity'] < 1) {
383
+ $trans = true;
384
+ }
385
+ $this->mpdf->gradients[$n]['stops'][$i]['opacity'] = $stops[$i]['opacity'];
386
+ // OFFSET
387
+ if ($i>0 && $i<(count($stops)-1)) {
388
+ if (!isset($stops[$i]['offset']) || (isset($stops[$i+1]['offset']) && $stops[$i]['offset']>$stops[$i+1]['offset']) || $stops[$i]['offset']<$stops[$i-1]['offset']) {
389
+ if (isset($stops[$i-1]['offset']) && isset($stops[$i+1]['offset'])) {
390
+ $stops[$i]['offset'] = ($stops[$i-1]['offset']+$stops[$i+1]['offset'])/2;
391
+ }
392
+ else {
393
+ for($j=($i+1);$j<count($stops);$j++) {
394
+ if(isset($stops[$j]['offset'])) { break; }
395
+ }
396
+ $int = ($stops[$j]['offset'] - $stops[($i-1)]['offset'])/($j-$i+1);
397
+ for($f=0;$f<($j-$i-1);$f++) {
398
+ $stops[($i+$f)]['offset'] = $stops[($i+$f-1)]['offset'] + ($int);
399
+ }
400
+ }
401
+ }
402
+ }
403
+ $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
404
+ $this->mpdf->gradients[$n]['stops'][$i]['offset'] = $stops[$i]['offset'];
405
+ }
406
+
407
+ if ($repeat) {
408
+ $ns = count($this->mpdf->gradients[$n]['stops']);
409
+ $offs = array();
410
+ for($i=0;$i<$ns;$i++) {
411
+ $offs[$i] = $this->mpdf->gradients[$n]['stops'][$i]['offset'];
412
+ }
413
+ $gp = 0;
414
+ $inside=true;
415
+ while($inside) {
416
+ $gp++;
417
+ for($i=0;$i<$ns;$i++) {
418
+ $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)] = $this->mpdf->gradients[$n]['stops'][(($ns*($gp-1))+$i)];
419
+ $tmp = $this->mpdf->gradients[$n]['stops'][(($ns*($gp-1))+($ns-1))]['offset']+$offs[$i] ;
420
+ if ($tmp < 1) { $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = $tmp; }
421
+ else {
422
+ $this->mpdf->gradients[$n]['stops'][(($ns*$gp)+$i)]['offset'] = 1;
423
+ $inside = false;
424
+ break(2);
425
+ }
426
+ }
427
+ }
428
+ }
429
+
430
+ if ($trans) {
431
+ $this->mpdf->gradients[$n]['trans'] = true;
432
+ $s .= ' /TGS'.$n.' gs ';
433
+ }
434
+ if (!is_array($extend) || count($extend) <1) {
435
+ $extend=array('true', 'true'); // These are supposed to be quoted - appear in PDF file as text
436
+ }
437
+ $this->mpdf->gradients[$n]['coords'] = $coords;
438
+ $this->mpdf->gradients[$n]['extend'] = $extend;
439
+ //paint the gradient
440
+ $s .= '/Sh'.$n.' sh '."\n";
441
+ //restore previous Graphic State
442
+ $s .= ' Q '."\n";
443
+ if ($return) { return $s; }
444
+ else { $this->mpdf->_out($s); }
445
+ }
446
+
447
+
448
+ function parseMozGradient($bg) {
449
+ // background[-image]: -moz-linear-gradient(left, #c7Fdde 20%, #FF0000 );
450
+ // background[-image]: linear-gradient(left, #c7Fdde 20%, #FF0000 ); // CSS3
451
+ if (preg_match('/repeating-/',$bg)) { $repeat = true; }
452
+ else { $repeat = false; }
453
+ if (preg_match('/linear-gradient\((.*)\)/',$bg,$m)) {
454
+ $g = array();
455
+ $g['type'] = 2;
456
+ $g['colorspace'] = 'RGB';
457
+ $g['extend'] = array('true','true');
458
+ $v = trim($m[1]);
459
+ // Change commas inside e.g. rgb(x,x,x)
460
+ while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
461
+ // Remove spaces inside e.g. rgb(x, x, x)
462
+ while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
463
+ $bgr = preg_split('/\s*,\s*/',$v);
464
+ for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
465
+ // Is first part $bgr[0] a valid point/angle?
466
+ $first = preg_split('/\s+/',trim($bgr[0]));
467
+ if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
468
+ $startStops = 1;
469
+ }
470
+ else if (trim($first[(count($first)-1)]) === "0") {
471
+ $startStops = 1;
472
+ }
473
+ else {
474
+ $check = $this->mpdf->ConvertColor($first[0]);
475
+ if ($check) $startStops = 0;
476
+ else $startStops = 1;
477
+ }
478
+ // first part a valid point/angle?
479
+ if ($startStops == 1) { // default values
480
+ // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
481
+ if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$bgr[0],$m)) {
482
+ $angle = $m[1] + 0;
483
+ if (strtolower($m[2])=='deg') { $angle = $angle; }
484
+ else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
485
+ else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
486
+ while($angle < 0) { $angle += 360; }
487
+ $angle = ($angle % 360);
488
+ }
489
+ else if (trim($first[(count($first)-1)]) === "0") { $angle = 0; }
490
+ if (preg_match('/left/i',$bgr[0])) { $startx = 0; }
491
+ else if (preg_match('/right/i',$bgr[0])) { $startx = 1; }
492
+ if (preg_match('/top/i',$bgr[0])) { $starty = 1; }
493
+ else if (preg_match('/bottom/i',$bgr[0])) { $starty = 0; }
494
+ // Check for %? ?% or %%
495
+ if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
496
+ else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
497
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
498
+ if ($tmp) { $startx = $m[1]; }
499
+ }
500
+ if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
501
+ else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
502
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
503
+ if ($tmp) { $starty = $m[1]; }
504
+ }
505
+ if (isset($startx) && !isset($starty)) { $starty = 0.5; }
506
+ if (!isset($startx) && isset($starty)) { $startx = 0.5; }
507
+
508
+ }
509
+ // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
510
+ else { // default values T2B
511
+ $starty = 1; $startx = 0.5;
512
+ $endy = 0; $endx = 0.5;
513
+ }
514
+ $coords = array();
515
+ if (!isset($startx)) { $startx = false; }
516
+ if (!isset($starty)) { $starty = false; }
517
+ if (!isset($endx)) { $endx = false; }
518
+ if (!isset($endy)) { $endy = false; }
519
+ if (!isset($angle)) { $angle = false; }
520
+ $g['coords'] = array($startx ,$starty ,$endx ,$endy, $angle, $repeat );
521
+ $g['stops'] = array();
522
+ for($i=$startStops;$i<count($bgr);$i++) {
523
+ $stop = array();
524
+ // parse stops
525
+ $el = preg_split('/\s+/',trim($bgr[$i]));
526
+ // mPDF 5.3.74
527
+ $col = $this->mpdf->ConvertColor($el[0]);
528
+ if ($col) { $stop['col'] = $col; }
529
+ else { $stop['col'] = $col = $this->mpdf->ConvertColor(255); }
530
+ if ($col{0}==1) $g['colorspace'] = 'Gray';
531
+ else if ($col{0}==4 || $col{0}==6) $g['colorspace'] = 'CMYK';
532
+ if ($col{0}==5) { $stop['opacity'] = ord($col{4})/100; } // transparency from rgba()
533
+ else if ($col{0}==6) { $stop['opacity'] = ord($col{5})/100; } // transparency from cmyka()
534
+ else if ($col{0}==1 && $col{2}==1) { $stop['opacity'] = ord($col{3})/100; } // transparency converted from rgba or cmyka()
535
+
536
+ if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
537
+ $stop['offset'] = $m[1]/100;
538
+ if ($stop['offset']>1) { unset($stop['offset']); }
539
+ }
540
+ else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
541
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
542
+ if ($tmp) { $stop['offset'] = $m[1]; }
543
+ }
544
+ $g['stops'][] = $stop;
545
+ }
546
+ if (count($g['stops'] )) { return $g; }
547
+ }
548
+ else if (preg_match('/radial-gradient\((.*)\)/',$bg,$m)) {
549
+ $g = array();
550
+ $g['type'] = 3;
551
+ $g['colorspace'] = 'RGB';
552
+ $g['extend'] = array('true','true');
553
+ $v = trim($m[1]);
554
+ // Change commas inside e.g. rgb(x,x,x)
555
+ while(preg_match('/(\([^\)]*?),/',$v)) { $v = preg_replace('/(\([^\)]*?),/','\\1@',$v); }
556
+ // Remove spaces inside e.g. rgb(x, x, x)
557
+ while(preg_match('/(\([^\)]*?)[ ]/',$v)) { $v = preg_replace('/(\([^\)]*?)[ ]/','\\1',$v); }
558
+ $bgr = preg_split('/\s*,\s*/',$v);
559
+ for($i=0;$i<count($bgr);$i++) { $bgr[$i] = preg_replace('/@/', ',', $bgr[$i]); }
560
+
561
+ // Is first part $bgr[0] a valid point/angle?
562
+ $startStops = 0;
563
+ $pos_angle = false;
564
+ $shape_size = false;
565
+ $first = preg_split('/\s+/',trim($bgr[0]));
566
+ $checkCol = $this->mpdf->ConvertColor($first[0]);
567
+ if (preg_match('/(left|center|right|bottom|top|deg|grad|rad)/i',$bgr[0]) && !preg_match('/(<#|rgb|rgba|hsl|hsla)/i',$bgr[0])) {
568
+ $startStops=1;
569
+ $pos_angle = $bgr[0];
570
+ }
571
+ else if (trim($first[(count($first)-1)]) === "0") {
572
+ $startStops=1;
573
+ $pos_angle = $bgr[0];
574
+ }
575
+ else if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[0])) {
576
+ $startStops=1;
577
+ $shape_size = $bgr[0];
578
+ }
579
+ else if (!$checkCol) {
580
+ $startStops=1;
581
+ $pos_angle = $bgr[0];
582
+ }
583
+ if (preg_match('/(circle|ellipse|closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$bgr[1])) {
584
+ $startStops=2;
585
+ $shape_size = $bgr[1];
586
+ }
587
+
588
+ // If valid point/angle?
589
+ if ($pos_angle) { // default values
590
+ // [<point> || <angle>,] = [<% em px left center right bottom top> || <deg grad rad 0>,]
591
+ if (preg_match('/left/i',$pos_angle)) { $startx = 0; }
592
+ else if (preg_match('/right/i',$pos_angle)) { $startx = 1; }
593
+ if (preg_match('/top/i',$pos_angle)) { $starty = 1; }
594
+ else if (preg_match('/bottom/i',$pos_angle)) { $starty = 0; }
595
+ // Check for %? ?% or %%
596
+ if (preg_match('/(\d+)[%]/i',$first[0],$m)) { $startx = $m[1]/100; }
597
+ else if (!isset($startx) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[0],$m)) {
598
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
599
+ if ($tmp) { $startx = $m[1]; }
600
+ }
601
+ if (isset($first[1]) && preg_match('/(\d+)[%]/i',$first[1],$m)) { $starty = 1 - ($m[1]/100); }
602
+ else if (!isset($starty) && isset($first[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$first[1],$m)) {
603
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
604
+ if ($tmp) { $starty = $m[1]; }
605
+ }
606
+
607
+ /*
608
+ // ?? Angle has no effect in radial gradient (does not exist in CSS3 spec.)
609
+ if (preg_match('/([\-]*[0-9\.]+)(deg|grad|rad)/i',$pos_angle,$m)) {
610
+ $angle = $m[1] + 0;
611
+ if (strtolower($m[2])=='deg') { $angle = $angle; }
612
+ else if (strtolower($m[2])=='grad') { $angle *= (360/400); }
613
+ else if (strtolower($m[2])=='rad') { $angle = rad2deg($angle); }
614
+ while($angle < 0) { $angle += 360; }
615
+ $angle = ($angle % 360);
616
+ }
617
+ */
618
+ if (!isset($starty)) { $starty = 0.5; }
619
+ if (!isset($startx)) { $startx = 0.5; }
620
+
621
+ }
622
+ // If neither a <point> or <angle> is specified, i.e. the entire function consists of only <stop> values, the gradient axis starts from the top of the box and runs vertically downwards, ending at the bottom of the box.
623
+ else { // default values Center
624
+ $starty = 0.5; $startx = 0.5;
625
+ $endy = 0.5; $endx = 0.5;
626
+ }
627
+
628
+ // If valid shape/size?
629
+ $shape = 'ellipse'; // default
630
+ $size = 'farthest-corner'; // default
631
+ if ($shape_size) { // default values
632
+ if (preg_match('/(circle|ellipse)/i',$shape_size, $m)) {
633
+ $shape = $m[1];
634
+ }
635
+ if (preg_match('/(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/i',$shape_size, $m)) {
636
+ $size = $m[1];
637
+ if ($size=='contain') { $size = 'closest-side'; }
638
+ else if ($size=='cover') { $size = 'farthest-corner'; }
639
+ }
640
+ }
641
+
642
+ $coords = array();
643
+ if (!isset($startx)) { $startx = false; }
644
+ if (!isset($starty)) { $starty = false; }
645
+ if (!isset($endx)) { $endx = false; }
646
+ if (!isset($endy)) { $endy = false; }
647
+ if (!isset($radius)) { $radius = false; }
648
+ if (!isset($angle)) { $angle = 0; }
649
+ $g['coords'] = array($startx ,$starty ,$endx ,$endy, $radius, $angle, $shape, $size, $repeat );
650
+
651
+ $g['stops'] = array();
652
+ for($i=$startStops;$i<count($bgr);$i++) {
653
+ $stop = array();
654
+ // parse stops
655
+ $el = preg_split('/\s+/',trim($bgr[$i]));
656
+ // mPDF 5.3.74
657
+ $col = $this->mpdf->ConvertColor($el[0]);
658
+ if ($col) { $stop['col'] = $col; }
659
+ else { $stop['col'] = $col = $this->mpdf->ConvertColor(255); }
660
+ if ($col{0}==1) $g['colorspace'] = 'Gray';
661
+ else if ($col{0}==4 || $col{0}==6) $g['colorspace'] = 'CMYK';
662
+ if ($col{0}==5) { $stop['opacity'] = ord($col{4})/100; } // transparency from rgba()
663
+ else if ($col{0}==6) { $stop['opacity'] = ord($col{5})/100; } // transparency from cmyka()
664
+ else if ($col{0}==1 && $col{2}==1) { $stop['opacity'] = ord($col{3})/100; } // transparency converted from rgba or cmyka()
665
+
666
+ if (isset($el[1]) && preg_match('/(\d+)[%]/',$el[1],$m)) {
667
+ $stop['offset'] = $m[1]/100;
668
+ if ($stop['offset']>1) { unset($stop['offset']); }
669
+ }
670
+ else if (isset($el[1]) && preg_match('/([0-9.]+(px|em|ex|pc|pt|cm|mm|in))/i',$el[1],$m)) {
671
+ $tmp = $this->mpdf->ConvertSize($m[1],$this->mpdf->w,$this->mpdf->FontSize,false);
672
+ $stop['offset'] = $el[1];
673
+ }
674
+ $g['stops'][] = $stop;
675
+ }
676
+ if (count($g['stops'] )) { return $g; }
677
+ }
678
+ return array();
679
+ }
680
+
681
+ function parseBackgroundGradient($bg) {
682
+ // background-gradient: linear #00FFFF #FFFF00 0 0.5 1 0.5; or
683
+ // background-gradient: radial #00FFFF #FFFF00 0.5 0.5 1 1 1.2;
684
+
685
+ $v = trim($bg);
686
+ $bgr = preg_split('/\s+/',$v);
687
+ $g = array();
688
+ if (count($bgr)> 6) {
689
+ if (strtoupper(substr($bgr[0],0,1)) == 'L' && count($bgr)==7) { // linear
690
+ $g['type'] = 2;
691
+ //$coords = array(0,0,1,1 ); // 0 0 1 0 or 0 1 1 1 is L 2 R; 1,1,0,1 is R2L; 1,1,1,0 is T2B; 1,0,1,1 is B2T
692
+ // Linear: $coords - array of the form (x1, y1, x2, y2) which defines the gradient vector (see linear_gradient_coords.jpg).
693
+ // The default value is from left to right (x1=0, y1=0, x2=1, y2=0).
694
+ $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6]);
695
+ }
696
+ else if (count($bgr)==8) { // radial
697
+ $g['type'] = 3;
698
+ // Radial: $coords - array of the form (fx, fy, cx, cy, r) where (fx, fy) is the starting point of the gradient with color1,
699
+ // (cx, cy) is the center of the circle with color2, and r is the radius of the circle (see radial_gradient_coords.jpg).
700
+ // (fx, fy) should be inside the circle, otherwise some areas will not be defined
701
+ $g['coords'] = array($bgr[3], $bgr[4], $bgr[5], $bgr[6], $bgr[7]);
702
+ }
703
+ $g['colorspace'] = 'RGB';
704
+ // mPDF 5.3.74
705
+ $cor = $this->mpdf->ConvertColor($bgr[1]);
706
+ if ($cor{0}==1) $g['colorspace'] = 'Gray';
707
+ else if ($cor{0}==4 || $cor{0}==6) $g['colorspace'] = 'CMYK';
708
+ if ($cor) { $g['col'] = $cor; }
709
+ else { $g['col'] = $this->mpdf->ConvertColor(255); }
710
+ $cor = $this->mpdf->ConvertColor($bgr[2]);
711
+ if ($cor) { $g['col2'] = $cor; }
712
+ else { $g['col2'] = $this->mpdf->ConvertColor(255); }
713
+ $g['extend'] = array('true','true');
714
+ $g['stops'] = array(array('col'=>$g['col'], 'opacity'=>1, 'offset'=>0), array('col'=>$g['col2'], 'opacity'=>1, 'offset'=>1));
715
+ return $g;
716
+ }
717
+ return false;
718
+ }
719
+
720
+
721
+
722
+ }
723
+
724
+ ?>
lib/mpdf/classes/indic.php ADDED
@@ -0,0 +1,1714 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class INDIC {
5
+
6
+ /* FROM hb-ot-shape-complex-indic-private.hh */
7
+ // indic_category
8
+ const OT_X = 0;
9
+ const OT_C = 1;
10
+ const OT_V = 2;
11
+ const OT_N = 3;
12
+ const OT_H = 4;
13
+ const OT_ZWNJ = 5;
14
+ const OT_ZWJ = 6;
15
+ const OT_M = 7; /* Matra or Dependent Vowel */
16
+ const OT_SM = 8;
17
+ const OT_VD = 9;
18
+ const OT_A = 10;
19
+ const OT_NBSP = 11;
20
+ const OT_DOTTEDCIRCLE = 12; /* Not in the spec, but special in Uniscribe. /Very very/ special! */
21
+ const OT_RS = 13; /* Register Shifter, used in Khmer OT spec */
22
+ const OT_Coeng = 14;
23
+ const OT_Repha = 15;
24
+ const OT_Ra = 16; /* Not explicitly listed in the OT spec, but used in the grammar. */
25
+ const OT_CM = 17;
26
+
27
+
28
+ // Based on indic_category used to make string to find syllables
29
+ // OT_ to string character (using e.g. OT_C from INDIC) hb-ot-shape-complex-indic-private.hh
30
+ public static $indic_category_char = array(
31
+ 'x',
32
+ 'C',
33
+ 'V',
34
+ 'N',
35
+ 'H',
36
+ 'Z',
37
+ 'J',
38
+ 'M',
39
+ 'S',
40
+ 'v',
41
+ 'A', /* Spec gives Andutta U+0952 as OT_A. However, testing shows that Uniscribe
42
+ * treats U+0951..U+0952 all as OT_VD - see set_indic_properties */
43
+ 's',
44
+ 'D',
45
+ 'F', /* Register shift Khmer only */
46
+ 'G', /* Khmer only */
47
+ 'r', /* 0D4E (dot reph) only one in Malayalam */
48
+ 'R',
49
+ 'm', /* Consonant medial only used in Indic 0A75 in Gurmukhi (0A00..0A7F) : also in Lao, Myanmar, Tai Tham, Javanese & Cham */
50
+ );
51
+
52
+
53
+ /* Visual positions in a syllable from left to right. */
54
+ /* FROM hb-ot-shape-complex-indic-private.hh */
55
+ // indic_position
56
+ const POS_START = 0;
57
+
58
+ const POS_RA_TO_BECOME_REPH = 1;
59
+ const POS_PRE_M = 2;
60
+ const POS_PRE_C = 3;
61
+
62
+ const POS_BASE_C = 4;
63
+ const POS_AFTER_MAIN = 5;
64
+
65
+ const POS_ABOVE_C = 6;
66
+
67
+ const POS_BEFORE_SUB = 7;
68
+ const POS_BELOW_C = 8;
69
+ const POS_AFTER_SUB = 9;
70
+
71
+ const POS_BEFORE_POST = 10;
72
+ const POS_POST_C = 11;
73
+ const POS_AFTER_POST = 12;
74
+
75
+ const POS_FINAL_C = 13;
76
+ const POS_SMVD = 14;
77
+
78
+ const POS_END = 15;
79
+
80
+ /*
81
+ * Basic features.
82
+ * These features are applied in order, one at a time, after initial_reordering.
83
+ */
84
+ /*
85
+ * Must be in the same order as the indic_features array. Ones starting with _ are F_GLOBAL
86
+ * Ones without the _ are only applied where the mask says!
87
+ */
88
+ const _NUKT = 0;
89
+ const _AKHN = 1;
90
+ const RPHF = 2;
91
+ const _RKRF = 3;
92
+ const PREF = 4;
93
+ const BLWF = 5;
94
+ const HALF = 6;
95
+ const ABVF = 7;
96
+ const PSTF = 8;
97
+ const CFAR = 9; // Khmer only
98
+ const _VATU = 10;
99
+ const _CJCT = 11;
100
+ const INIT = 12;
101
+
102
+
103
+ public static function set_indic_properties(&$info, $scriptblock ) {
104
+ $u = $info['uni'];
105
+ $type = self::indic_get_categories($u);
106
+ $cat = ($type & 0x7F);
107
+ $pos = ($type >> 8);
108
+
109
+ /*
110
+ * Re-assign category
111
+ */
112
+
113
+ if ($u == 0x17D1) $cat = self::OT_X;
114
+
115
+ if ($cat == self::OT_X && self::in_range($u, 0x17CB, 0x17D3)) { /* Khmer Various signs */
116
+ /* These are like Top Matras. */
117
+ $cat = self::OT_M;
118
+ $pos = self::POS_ABOVE_C;
119
+ }
120
+
121
+ if ($u == 0x17C6) $cat = self::OT_N; /* Khmer Bindu doesn't like to be repositioned. */
122
+
123
+ if ($u == 0x17D2) $cat = self::OT_Coeng; /* Khmer coeng */
124
+
125
+ /* The spec says U+0952 is OT_A. However, testing shows that Uniscribe
126
+ * treats U+0951..U+0952 all as OT_VD.
127
+ * TESTS:
128
+ * U+092E,U+0947,U+0952
129
+ * U+092E,U+0952,U+0947
130
+ * U+092E,U+0947,U+0951
131
+ * U+092E,U+0951,U+0947
132
+ * */
133
+ //if ($u == 0x0952) $cat = self::OT_A;
134
+ if (self::in_range($u, 0x0951, 0x0954))
135
+ $cat = self::OT_VD;
136
+
137
+ if ($u == 0x200C) $cat = self::OT_ZWNJ;
138
+ else if ($u == 0x200D) $cat = self::OT_ZWJ;
139
+ else if ($u == 0x25CC) $cat = self::OT_DOTTEDCIRCLE;
140
+ else if ($u == 0x0A71) $cat = self::OT_SM; /* GURMUKHI ADDAK. More like consonant medial. like 0A75. */
141
+
142
+ if ($cat == self::OT_Repha) {
143
+ /* There are two kinds of characters marked as Repha:
144
+ * - The ones that are GenCat=Mn are already positioned visually, ie. after base. (eg. Khmer)
145
+ * - The ones that are GenCat=Lo is encoded logically, ie. beginning of syllable. (eg. Malayalam)
146
+ *
147
+ * We recategorize the first kind to look like a Nukta and attached to the base directly.
148
+ */
149
+ if ($info['general_category'] == UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
150
+ $cat = self::OT_N;
151
+ }
152
+
153
+ /*
154
+ * Re-assign position.
155
+ */
156
+
157
+ if ((self::FLAG($cat) & (self::FLAG(self::OT_C) | self::FLAG(self::OT_CM) | self::FLAG(self::OT_Ra) | self::FLAG(self::OT_V) | self::FLAG(self::OT_NBSP) | self::FLAG(self::OT_DOTTEDCIRCLE)))) { // = CONSONANT_FLAGS like is_consonant
158
+ if ($scriptblock == UCDN::SCRIPT_KHMER) $pos = self::POS_BELOW_C; /* Khmer differs from Indic here. */
159
+ else $pos = self::POS_BASE_C; /* Will recategorize later based on font lookups. */
160
+
161
+ if (self::is_ra ($u))
162
+ $cat = self::OT_Ra;
163
+ }
164
+ else if ($cat == self::OT_M) {
165
+ $pos = self::matra_position($u, $pos);
166
+ }
167
+ else if ($cat == self::OT_SM || $cat == self::OT_VD) {
168
+ $pos = self::POS_SMVD;
169
+ }
170
+
171
+ if ($u == 0x0B01) $pos = self::POS_BEFORE_SUB; /* Oriya Bindu is BeforeSub in the spec. */
172
+
173
+ $info['indic_category'] = $cat;
174
+ $info['indic_position'] = $pos;
175
+ }
176
+
177
+ // syllable_type
178
+ const CONSONANT_SYLLABLE = 0;
179
+ const VOWEL_SYLLABLE = 1;
180
+ const STANDALONE_CLUSTER = 2;
181
+ const BROKEN_CLUSTER = 3;
182
+ const NON_INDIC_CLUSTER = 4;
183
+
184
+ public static function set_syllables(&$o, $s, &$broken_syllables) {
185
+ $ptr = 0;
186
+ $syllable_serial = 1;
187
+ $broken_syllables = false;
188
+
189
+ while($ptr < strlen($s)) {
190
+ $match = '';
191
+ $syllable_length = 1;
192
+ $syllable_type = self::NON_INDIC_CLUSTER ;
193
+ // CONSONANT_SYLLABLE Consonant syllable
194
+ // From OT spec:
195
+ if (preg_match('/^([CR]m*[N]?(H[ZJ]?|[ZJ]H))*[CR]m*[N]?[A]?(H[ZJ]?|[M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
196
+ // From HarfBuzz:
197
+ //if (preg_match('/^r?([CR]J?(Z?[N]{0,2})?[ZJ]?H(J[N]?)?){0,4}[CR]J?(Z?[N]{0,2})?A?((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
198
+ $syllable_length = strlen($ma[0]);
199
+ $syllable_type = self::CONSONANT_SYLLABLE ;
200
+ }
201
+ // VOWEL_SYLLABLE Vowel-based syllable
202
+ // From OT spec:
203
+ else if (preg_match('/^(RH|r)?V[N]?([ZJ]?H[CR]m*|J[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
204
+ // From HarfBuzz:
205
+ //else if (preg_match('/^(RH|r)?V(Z?[N]{0,2})?(J|([ZJ]?H(J[N]?)?[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2})/', substr($s,$ptr), $ma)) {
206
+ $syllable_length = strlen($ma[0]);
207
+ $syllable_type = self::VOWEL_SYLLABLE ;
208
+ }
209
+
210
+ /* Apply only if it's a word start. */
211
+ // STANDALONE_CLUSTER Stand Alone syllable at start of word
212
+ // From OT spec:
213
+ else if (($ptr==0 ||
214
+ $o[$ptr - 1]['general_category'] < UCDN::UNICODE_GENERAL_CATEGORY_LOWERCASE_LETTER ||
215
+ $o[$ptr - 1]['general_category'] > UCDN::UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK
216
+ )
217
+
218
+ && (preg_match('/^(RH|r)?[sD][N]?([ZJ]?H[CR]m*)?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma))) {
219
+ // From HarfBuzz:
220
+ // && (preg_match('/^(RH|r)?[sD](Z?[N]{0,2})?(([ZJ]?H(J[N]?)?)[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})?(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
221
+ $syllable_length = strlen($ma[0]);
222
+ $syllable_type = self::STANDALONE_CLUSTER ;
223
+ }
224
+
225
+ // BROKEN_CLUSTER syllable
226
+ else if (preg_match('/^(RH|r)?[N]?([ZJ]?H[CR])?([M]*[N]?[H]?)?[S]?[v]{0,2}/', substr($s,$ptr), $ma)) {
227
+ // From HarfBuzz:
228
+ //else if (preg_match('/^(RH|r)?(Z?[N]{0,2})?(([ZJ]?H(J[N]?)?)[CR]J?(Z?[N]{0,2})?){0,4}((([ZJ]?H(J[N]?)?)|HZ)|(HJ)?([ZJ]{0,3}M[N]?(H|JHJR)?){0,4})(S[Z]?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
229
+ if (strlen($ma[0])) { // May match blank
230
+ $syllable_length = strlen($ma[0]);
231
+ $syllable_type = self::BROKEN_CLUSTER ;
232
+ $broken_syllables = true;
233
+ }
234
+ }
235
+
236
+ for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
237
+ $ptr += $syllable_length ;
238
+ $syllable_serial++;
239
+ if ($syllable_serial == 16) $syllable_serial = 1;
240
+ }
241
+ }
242
+
243
+
244
+ public static function set_syllables_sinhala(&$o, $s, &$broken_syllables) {
245
+ $ptr = 0;
246
+ $syllable_serial = 1;
247
+ $broken_syllables = false;
248
+
249
+ while($ptr < strlen($s)) {
250
+ $match = '';
251
+ $syllable_length = 1;
252
+ $syllable_type = self::NON_INDIC_CLUSTER ;
253
+ // CONSONANT_SYLLABLE Consonant syllable
254
+ // From OT spec:
255
+ if (preg_match('/^([CR]HJ|[CR]JH){0,8}[CR][HM]{0,3}[S]{0,1}/', substr($s,$ptr), $ma)) {
256
+ $syllable_length = strlen($ma[0]);
257
+ $syllable_type = self::CONSONANT_SYLLABLE ;
258
+ }
259
+ // VOWEL_SYLLABLE Vowel-based syllable
260
+ // From OT spec:
261
+ else if (preg_match('/^V[S]{0,1}/', substr($s,$ptr), $ma)) {
262
+ $syllable_length = strlen($ma[0]);
263
+ $syllable_type = self::VOWEL_SYLLABLE ;
264
+ }
265
+
266
+ for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
267
+ $ptr += $syllable_length ;
268
+ $syllable_serial++;
269
+ if ($syllable_serial == 16) $syllable_serial = 1;
270
+ }
271
+ }
272
+
273
+ public static function set_syllables_khmer(&$o, $s, &$broken_syllables) {
274
+ $ptr = 0;
275
+ $syllable_serial = 1;
276
+ $broken_syllables = false;
277
+
278
+ while($ptr < strlen($s)) {
279
+ $match = '';
280
+ $syllable_length = 1;
281
+ $syllable_type = self::NON_INDIC_CLUSTER ;
282
+ // CONSONANT_SYLLABLE Consonant syllable
283
+ if (preg_match('/^r?([CR]J?((Z?F)?[N]{0,2})?[ZJ]?G(JN?)?){0,4}[CR]J?((Z?F)?[N]{0,2})?A?((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
284
+ $syllable_length = strlen($ma[0]);
285
+ $syllable_type = self::CONSONANT_SYLLABLE ;
286
+ }
287
+ // VOWEL_SYLLABLE Vowel-based syllable
288
+ else if (preg_match('/^(RH|r)?V((Z?F)?[N]{0,2})?(J|([ZJ]?G(JN?)?[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})?(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2})/', substr($s,$ptr), $ma)) {
289
+ $syllable_length = strlen($ma[0]);
290
+ $syllable_type = self::VOWEL_SYLLABLE ;
291
+ }
292
+
293
+
294
+ // BROKEN_CLUSTER syllable
295
+ else if (preg_match('/^(RH|r)?((Z?F)?[N]{0,2})?(([ZJ]?G(JN?)?)[CR]J?((Z?F)?[N]{0,2})?){0,4}((([ZJ]?G(JN?)?)|GZ)|(GJ)?([ZJ]{0,3}MN?(H|JHJR)?){0,4})(G([CR]J?((Z?F)?[N]{0,2})?|V))?(SZ?)?[v]{0,2}/', substr($s,$ptr), $ma)) {
296
+ if (strlen($ma[0])) { // May match blank
297
+ $syllable_length = strlen($ma[0]);
298
+ $syllable_type = self::BROKEN_CLUSTER ;
299
+ $broken_syllables = true;
300
+ }
301
+ }
302
+
303
+ for ($i = $ptr; $i < $ptr+$syllable_length; $i++) { $o[$i]['syllable'] = ($syllable_serial << 4) | $syllable_type; }
304
+ $ptr += $syllable_length ;
305
+ $syllable_serial++;
306
+ if ($syllable_serial == 16) $syllable_serial = 1;
307
+ }
308
+ }
309
+
310
+ public static function initial_reordering(&$info, $GSUBdata, $broken_syllables, $indic_config, $scriptblock, $is_old_spec, $dottedcircle) {
311
+
312
+ self::update_consonant_positions ($info, $GSUBdata);
313
+
314
+ if ($broken_syllables && $dottedcircle) { self::insert_dotted_circles ($info, $dottedcircle); }
315
+
316
+ $count = count($info);
317
+ if (!$count) return;
318
+ $last = 0;
319
+ $last_syllable = $info[0]['syllable'];
320
+ for ($i = 1; $i < $count; $i++) {
321
+ if ($last_syllable != $info[$i]['syllable']) {
322
+ self::initial_reordering_syllable ($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $i);
323
+ $last = $i;
324
+ $last_syllable = $info[$last]['syllable'];
325
+ }
326
+ }
327
+ self::initial_reordering_syllable($info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $last, $count);
328
+ }
329
+
330
+ public static function update_consonant_positions(&$info, $GSUBdata) {
331
+ $count = count($info);
332
+ for ($i = 0; $i < $count; $i++) {
333
+ if ($info[$i]['indic_position'] == self::POS_BASE_C) {
334
+ $c = $info[$i]['uni'];
335
+ // If would substitute...
336
+ if (isset($GSUBdata['pref'][$c])) { $info[$i]['indic_position'] = self::POS_POST_C; }
337
+ else if (isset($GSUBdata['blwf'][$c])) { $info[$i]['indic_position'] = self::POS_BELOW_C; }
338
+ else if (isset($GSUBdata['pstf'][$c])) { $info[$i]['indic_position'] = self::POS_POST_C; }
339
+ }
340
+ }
341
+ }
342
+
343
+ public static function insert_dotted_circles(&$info, $dottedcircle) {
344
+ $idx = 0;
345
+ $last_syllable = 0;
346
+ while ($idx < count($info)) {
347
+ $syllable = $info[$idx]['syllable'];
348
+ $syllable_type = ($syllable & 0x0F);
349
+ if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
350
+ $last_syllable = $syllable;
351
+
352
+ $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
353
+
354
+ /* Insert dottedcircle after possible Repha. */
355
+ while ($idx < count($info) && $last_syllable == $info[$idx]['syllable'] && $info[$idx]['indic_category'] == self::OT_Repha)
356
+ $idx++;
357
+ array_splice($info, $idx, 0, $dottedcircle);
358
+ }
359
+ else
360
+ $idx++;
361
+ }
362
+ // I am not sue how this code below got in here, since $idx should now be > count($info) and thus invalid.
363
+ // In case I am missing something(!) I'll leave a warning here for now:
364
+ if (isset($info[$idx])) { die("This shouldn't happen (in otl.php)"); exit; }
365
+ // In case of final bloken cluster...
366
+ //$syllable = $info[$idx]['syllable'];
367
+ //$syllable_type = ($syllable & 0x0F);
368
+ //if ($last_syllable != $syllable && $syllable_type == self::BROKEN_CLUSTER) {
369
+ // $dottedcircle[0]['syllable'] = $info[$idx]['syllable'];
370
+ // array_splice($info, $idx, 0, $dottedcircle);
371
+ //}
372
+ }
373
+
374
+
375
+
376
+ /* Rules from:
377
+ * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */
378
+
379
+ public static function initial_reordering_syllable (&$info, $GSUBdata, $indic_config, $scriptblock, $is_old_spec, $start, $end) {
380
+ /* vowel_syllable: We made the vowels look like consonants. So uses the consonant logic! */
381
+ /* broken_cluster: We already inserted dotted-circles, so just call the standalone_cluster. */
382
+ /* standalone_cluster: We treat NBSP/dotted-circle as if they are consonants, so we should just chain. */
383
+
384
+ $syllable_type = ($info[$start]['syllable'] & 0x0F);
385
+ if ($syllable_type==self::NON_INDIC_CLUSTER ) { return; }
386
+ if ($syllable_type==self::BROKEN_CLUSTER || $syllable_type==self::STANDALONE_CLUSTER ) {
387
+ //if ($uniscribe_bug_compatible) {
388
+ /* For dotted-circle, this is what Uniscribe does:
389
+ * If dotted-circle is the last glyph, it just does nothing.
390
+ * i.e. It doesn't form Reph. */
391
+ if ($info[$end - 1]['indic_category'] == self::OT_DOTTEDCIRCLE) {
392
+ return;
393
+ }
394
+ }
395
+
396
+ /* 1. Find base consonant:
397
+ *
398
+ * The shaping engine finds the base consonant of the syllable, using the
399
+ * following algorithm: starting from the end of the syllable, move backwards
400
+ * until a consonant is found that does not have a below-base or post-base
401
+ * form (post-base forms have to follow below-base forms), or that is not a
402
+ * pre-base reordering Ra, or arrive at the first consonant. The consonant
403
+ * stopped at will be the base.
404
+ *
405
+ * o If the syllable starts with Ra + Halant (in a script that has Reph)
406
+ * and has more than one consonant, Ra is excluded from candidates for
407
+ * base consonants.
408
+ */
409
+
410
+ $base = $end;
411
+ $has_reph = false;
412
+ $limit = $start;
413
+
414
+ if ($scriptblock != UCDN::SCRIPT_KHMER) {
415
+ /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
416
+ * and has more than one consonant, Ra is excluded from candidates for
417
+ * base consonants. */
418
+ if (count($GSUBdata['rphf']) /* ?? $indic_plan->mask_array[RPHF] */ && $start + 3 <= $end &&
419
+ (
420
+ ($indic_config[4] == self::REPH_MODE_IMPLICIT && !self::is_joiner($info[$start + 2])) ||
421
+ ($indic_config[4] == self::REPH_MODE_EXPLICIT && $info[$start + 2]['indic_category'] == self::OT_ZWJ)
422
+ )) {
423
+ /* See if it matches the 'rphf' feature. */
424
+ //$glyphs = array($info[$start]['uni'], $info[$start + 1]['uni']);
425
+ //if ($indic_plan->rphf->would_substitute ($glyphs, count($glyphs), true, face)) {
426
+ if (isset($GSUBdata['rphf'][$info[$start]['uni']]) && self::is_halant_or_coeng($info[$start + 1]) ) {
427
+ $limit += 2;
428
+ while ($limit < $end && self::is_joiner($info[$limit]))
429
+ $limit++;
430
+ $base = $start;
431
+ $has_reph = true;
432
+ }
433
+ }
434
+ else if ($indic_config[4] == self::REPH_MODE_LOG_REPHA && $info[$start]['indic_category'] == self::OT_Repha) {
435
+ $limit += 1;
436
+ while ($limit < $end && self::is_joiner($info[$limit]))
437
+ $limit++;
438
+ $base = $start;
439
+ $has_reph = true;
440
+ }
441
+ }
442
+
443
+ switch ($indic_config[2]) { // base_pos
444
+ case self::BASE_POS_LAST:
445
+ /* -> starting from the end of the syllable, move backwards */
446
+ $i = $end;
447
+ $seen_below = false;
448
+ do {
449
+ $i--;
450
+ /* -> until a consonant is found */
451
+ if (self::is_consonant($info[$i])) {
452
+ /* -> that does not have a below-base or post-base form
453
+ * (post-base forms have to follow below-base forms), */
454
+ if ($info[$i]['indic_position'] != self::POS_BELOW_C && ($info[$i]['indic_position'] != self::POS_POST_C || $seen_below)) {
455
+ $base = $i;
456
+ break;
457
+ }
458
+ if ($info[$i]['indic_position'] == self::POS_BELOW_C)
459
+ $seen_below = true;
460
+
461
+ /* -> or that is not a pre-base reordering Ra,
462
+ *
463
+ * IMPLEMENTATION NOTES:
464
+ *
465
+ * Our pre-base reordering Ra's are marked POS_POST_C, so will be skipped
466
+ * by the logic above already.
467
+ */
468
+
469
+ /* -> or arrive at the first consonant. The consonant stopped at will
470
+ * be the base. */
471
+ $base = $i;
472
+ }
473
+ else {
474
+ /* A ZWJ after a Halant stops the base search, and requests an explicit
475
+ * half form.
476
+ * [A ZWJ before a Halant, requests a subjoined form instead, and hence
477
+ * search continues. This is particularly important for Bengali
478
+ * sequence Ra,H,Ya that should form Ya-Phalaa by subjoining Ya] */
479
+ if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWJ && $info[$i - 1]['indic_category'] == self::OT_H) {
480
+ if (!defined("OMIT_INDIC_FIX_1") || OMIT_INDIC_FIX_1!=1) { $base = $i; } // INDIC_FIX_1
481
+ break;
482
+ }
483
+ // ZKI8
484
+ if ($start < $i && $info[$i]['indic_category'] == self::OT_ZWNJ) {
485
+ break;
486
+ }
487
+ }
488
+ } while ($i > $limit);
489
+ break;
490
+
491
+ case self::BASE_POS_FIRST:
492
+ /* In scripts without half forms (eg. Khmer), the first consonant is always the base. */
493
+
494
+ if (!$has_reph)
495
+ $base = $limit;
496
+
497
+ /* Find the last base consonant that is not blocked by ZWJ. If there is
498
+ * a ZWJ right before a base consonant, that would request a subjoined form. */
499
+ for ($i = $limit; $i < $end; $i++) {
500
+ if (self::is_consonant($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C) {
501
+ if ($limit < $i && $info[$i - 1]['indic_category'] == self::OT_ZWJ)
502
+ break;
503
+ else
504
+ $base = $i;
505
+ }
506
+ }
507
+
508
+ /* Mark all subsequent consonants as below. */
509
+ for ($i = $base + 1; $i < $end; $i++) {
510
+ if (self::is_consonant ($info[$i]) && $info[$i]['indic_position'] == self::POS_BASE_C)
511
+ $info[$i]['indic_position'] = self::POS_BELOW_C;
512
+ }
513
+ break;
514
+ //default:
515
+ //assert (false);
516
+ /* fallthrough */
517
+ }
518
+
519
+ /* -> If the syllable starts with Ra + Halant (in a script that has Reph)
520
+ * and has more than one consonant, Ra is excluded from candidates for
521
+ * base consonants.
522
+ *
523
+ * Only do this for unforced Reph. (ie. not for Ra,H,ZWJ. */
524
+ if ($scriptblock != UCDN::SCRIPT_KHMER) {
525
+ if ($has_reph && $base == $start && $limit - $base <= 2) {
526
+ /* Have no other consonant, so Reph is not formed and Ra becomes base. */
527
+ $has_reph = false;
528
+ }
529
+ }
530
+
531
+ /* 2. Decompose and reorder Matras:
532
+ *
533
+ * Each matra and any syllable modifier sign in the cluster are moved to the
534
+ * appropriate position relative to the consonant(s) in the cluster. The
535
+ * shaping engine decomposes two- or three-part matras into their constituent
536
+ * parts before any repositioning. Matra characters are classified by which
537
+ * consonant in a conjunct they have affinity for and are reordered to the
538
+ * following positions:
539
+ *
540
+ * o Before first half form in the syllable
541
+ * o After subjoined consonants
542
+ * o After post-form consonant
543
+ * o After main consonant (for above marks)
544
+ *
545
+ * IMPLEMENTATION NOTES:
546
+ *
547
+ * The normalize() routine has already decomposed matras for us, so we don't
548
+ * need to worry about that.
549
+ */
550
+
551
+
552
+ /* 3. Reorder marks to canonical order:
553
+ *
554
+ * Adjacent nukta and halant or nukta and vedic sign are always repositioned
555
+ * if necessary, so that the nukta is first.
556
+ *
557
+ * IMPLEMENTATION NOTES:
558
+ *
559
+ * Use the combining Class from Unicode categories? to bubble_sort.
560
+ */
561
+
562
+ /* Reorder characters */
563
+
564
+ for ($i = $start; $i < $base; $i++)
565
+ $info[$i]['indic_position'] = min(self::POS_PRE_C, $info[$i]['indic_position']);
566
+
567
+ if ($base < $end)
568
+ $info[$base]['indic_position'] = self::POS_BASE_C;
569
+
570
+ /* Mark final consonants. A final consonant is one appearing after a matra,
571
+ * ? only in Khmer. */
572
+ for ($i = $base + 1; $i < $end; $i++)
573
+ if ($info[$i]['indic_category'] == self::OT_M) {
574
+ for ($j = $i + 1; $j < $end; $j++)
575
+ if (self::is_consonant ($info[$j])) {
576
+ $info[$j]['indic_position'] = self::POS_FINAL_C;
577
+ break;
578
+ }
579
+ break;
580
+ }
581
+
582
+ /* Handle beginning Ra */
583
+ if ($scriptblock != UCDN::SCRIPT_KHMER) {
584
+ if ($has_reph)
585
+ $info[$start]['indic_position'] = self::POS_RA_TO_BECOME_REPH;
586
+ }
587
+
588
+
589
+ /* For old-style Indic script tags, move the first post-base Halant after
590
+ * last consonant. Only do this if there is *not* a Halant after last
591
+ * consonant. Otherwise it becomes messy. */
592
+ if ($is_old_spec) {
593
+ for ($i = $base + 1; $i < $end; $i++) {
594
+ if ($info[$i]['indic_category'] == self::OT_H) {
595
+ for ($j = $end - 1; $j > $i; $j--) {
596
+ if (self::is_consonant($info[$j]) || $info[$j]['indic_category'] == self::OT_H) { break; }
597
+ }
598
+ if ($info[$j]['indic_category'] != self::OT_H && $j > $i) {
599
+ /* Move Halant to after last consonant. */
600
+ self::_move_info_pos($info, $i, $j+1);
601
+ }
602
+ break;
603
+ }
604
+ }
605
+ }
606
+
607
+ /* Attach misc marks to previous char to move with them. */
608
+ $last_pos = self::POS_START;
609
+ for ($i = $start; $i < $end; $i++) {
610
+ if ((self::FLAG($info[$i]['indic_category']) & (self::FLAG(self::OT_ZWJ)| self::FLAG(self::OT_ZWNJ) | self::FLAG(self::OT_N) | self::FLAG (self::OT_RS) | self::FLAG (self::OT_H) | self::FLAG (self::OT_Coeng) ))) {
611
+ $info[$i]['indic_position'] = $last_pos;
612
+ if ($info[$i]['indic_category'] == self::OT_H && $info[$i]['indic_position'] == self::POS_PRE_M) {
613
+ /*
614
+ * Uniscribe doesn't move the Halant with Left Matra.
615
+ * TEST: U+092B,U+093F,U+094DE
616
+ * We follow. This is important for the Sinhala
617
+ * U+0DDA split matra since it decomposes to U+0DD9,U+0DCA
618
+ * where U+0DD9 is a left matra and U+0DCA is the virama.
619
+ * We don't want to move the virama with the left matra.
620
+ * TEST: U+0D9A,U+0DDA
621
+ */
622
+ for ($j = $i; $j > $start; $j--)
623
+ if ($info[$j - 1]['indic_position'] != self::POS_PRE_M) {
624
+ $info[$i]['indic_position'] = $info[$j - 1]['indic_position'];
625
+ break;
626
+ }
627
+ }
628
+ }
629
+ else if ($info[$i]['indic_position'] != self::POS_SMVD) {
630
+ $last_pos = $info[$i]['indic_position'];
631
+ }
632
+ }
633
+
634
+ /* Re-attach ZWJ, ZWNJ, and halant to next char, for after-base consonants. */
635
+ $last_halant = $end;
636
+ for ($i = $base + 1; $i < $end; $i++) {
637
+ if (self::is_halant_or_coeng($info[$i]))
638
+ $last_halant = $i;
639
+ else if (self::is_consonant($info[$i])) {
640
+ for ($j = $last_halant; $j < $i; $j++)
641
+ if ($info[$j]['indic_position'] != self::POS_SMVD)
642
+ $info[$j]['indic_position'] = $info[$i]['indic_position'];
643
+ }
644
+ }
645
+
646
+
647
+ if ($scriptblock == UCDN::SCRIPT_KHMER) {
648
+ /* KHMER_FIX_2 */
649
+ /* Move Coeng+RO (Halant,Ra) sequence before base consonant. */
650
+ for ($i = $base + 1; $i < $end; $i++) {
651
+ if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni'])) {
652
+ $info[$i]['indic_position'] = self::POS_PRE_C;
653
+ $info[$i + 1]['indic_position'] = self::POS_PRE_C;
654
+ break;
655
+ }
656
+ }
657
+ }
658
+
659
+
660
+ /*
661
+ if (!defined("OMIT_INDIC_FIX_2") || OMIT_INDIC_FIX_2 != 1) {
662
+ // INDIC_FIX_2
663
+ $ZWNJ_found = false;
664
+ $POST_ZWNJ_c_found = false;
665
+ for ($i = $base + 1; $i < $end; $i++) {
666
+ if ($info[$i]['indic_category'] == self::OT_ZWNJ) { $ZWNJ_found = true; }
667
+ else if ($ZWNJ_found && $info[$i]['indic_category'] == self::OT_C) { $POST_ZWNJ_c_found = true; }
668
+ else if ($POST_ZWNJ_c_found && $info[$i]['indic_position'] == self::POS_BEFORE_SUB) { $info[$i]['indic_position'] = self::POS_AFTER_SUB; }
669
+ }
670
+ }
671
+ */
672
+
673
+ /* Setup masks now */
674
+ for ($i = $start; $i < $end; $i++) {
675
+ $info[$i]['mask'] = 0;
676
+ }
677
+
678
+
679
+ if ($scriptblock == UCDN::SCRIPT_KHMER) {
680
+ /* Find a Coeng+RO (Halant,Ra) sequence and mark it for pre-base processing. */
681
+ $mask = self::FLAG(self::PREF);
682
+ for ($i = $base; $i < $end-1; $i++) { /* KHMER_FIX_1 From $start (not base) */
683
+ if (self::is_halant_or_coeng($info[$i]) && self::is_ra($info[$i + 1]['uni']) ) {
684
+
685
+ $info[$i]['mask'] |= self::FLAG(self::PREF);
686
+ $info[$i + 1]['mask'] |= self::FLAG(self::PREF);
687
+
688
+ /* Mark the subsequent stuff with 'cfar'. Used in Khmer.
689
+ * Read the feature spec.
690
+ * This allows distinguishing the following cases with MS Khmer fonts:
691
+ * U+1784,U+17D2,U+179A,U+17D2,U+1782 [C+Coeng+RO+Coeng+C] => Should activate CFAR
692
+ * U+1784,U+17D2,U+1782,U+17D2,U+179A [C+Coeng+C+Coeng+RO] => Should NOT activate CFAR
693
+ */
694
+ for ($j=($i+2); $j < $end; $j++)
695
+ $info[$j]['mask'] |= self::FLAG(self::CFAR);
696
+
697
+ break;
698
+ }
699
+ }
700
+ }
701
+
702
+
703
+
704
+ /* Sit tight, rock 'n roll! */
705
+ self::bubble_sort ($info, $start, $end - $start);
706
+
707
+ /* Find base again */
708
+ $base = $end;
709
+ for ($i = $start; $i < $end; $i++) {
710
+ if ($info[$i]['indic_position'] == self::POS_BASE_C) {
711
+ $base = $i;
712
+ break;
713
+ }
714
+ }
715
+
716
+ if ($scriptblock != UCDN::SCRIPT_KHMER) {
717
+ /* Reph */
718
+ for ($i = $start; $i < $end; $i++) {
719
+ if ($info[$i]['indic_position'] == self::POS_RA_TO_BECOME_REPH) {
720
+ $info[$i]['mask'] |= self::FLAG(self::RPHF);
721
+ }
722
+ }
723
+
724
+ /* Pre-base */
725
+ $mask = self::FLAG(self::HALF);
726
+ for ($i = $start; $i < $base; $i++) {
727
+ $info[$i]['mask'] |= $mask;
728
+ }
729
+ }
730
+
731
+ /* Post-base */
732
+ $mask = (self::FLAG(self::BLWF) | self::FLAG(self::ABVF) | self::FLAG(self::PSTF));
733
+ for ($i = $base + 1; $i < $end; $i++) {
734
+ $info[$i]['mask'] |= $mask;
735
+ }
736
+
737
+
738
+ if ($scriptblock != UCDN::SCRIPT_KHMER) {
739
+ if (!defined("OMIT_INDIC_FIX_3") || OMIT_INDIC_FIX_3 != 1) {
740
+ /* INDIC_FIX_3 */
741
+ /* Find a (pre-base) Consonant, Halant,Ra sequence and mark Halant|Ra for below-base BLWF processing. */
742
+ // TEST CASE &#x995;&#x9cd;&#x9b0;&#x9cd;&#x995; in FreeSans versus Vrinda
743
+ if (($base - $start) >= 3) {
744
+ for ($i = $start; $i < ($base-2); $i++) {
745
+ if (self::is_consonant($info[$i])) {
746
+ if (self::is_halant_or_coeng($info[$i + 1]) && self::is_ra($info[$i + 2]['uni'])) {
747
+ // If would substitute Halant+Ra...BLWF
748
+ if (isset($GSUBdata['blwf'][$info[$i+2]['uni']])) {
749
+ $info[$i + 1]['mask'] |= self::FLAG(self::BLWF);
750
+ $info[$i + 2]['mask'] |= self::FLAG(self::BLWF);
751
+ }
752
+ /* If would not substitute as blwf, mark Ra+Halant for RPHF using following Halant (if present) */
753
+ else if (self::is_halant_or_coeng($info[$i + 3])) {
754
+ $info[$i + 2]['mask'] |= self::FLAG(self::RPHF);
755
+ $info[$i + 3]['mask'] |= self::FLAG(self::RPHF);
756
+ }
757
+ break;
758
+ }
759
+ }
760
+ }
761
+ }
762
+ }
763
+ }
764
+
765
+
766
+
767
+ if ($is_old_spec && $scriptblock == UCDN::SCRIPT_DEVANAGARI) {
768
+ /* Old-spec eye-lash Ra needs special handling. From the spec:
769
+ * "The feature 'below-base form' is applied to consonants
770
+ * having below-base forms and following the base consonant.
771
+ * The exception is vattu, which may appear below half forms
772
+ * as well as below the base glyph. The feature 'below-base
773
+ * form' will be applied to all such occurrences of Ra as well."
774
+ *
775
+ * Test case: U+0924,U+094D,U+0930,U+094d,U+0915
776
+ * with Sanskri