PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / libraries / html / wpdash / rss / widget.php
vikappointments / libraries / html / wpdash / rss Last commit date
widget.php 4 years ago
widget.php
246 lines
1 <?php
2 /**
3 * @package VikAppointments - Libraries
4 * @subpackage html.wpdash
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Layout variables
16 * -----------------
17 * @var JRegistry $config The configuration registry
18 * @var JDashboardWidget $widget The widget instance.
19 * @var array $feeds A list of feeds.
20 */
21 extract($displayData);
22
23 $document = JFactory::getDocument();
24
25 $internalFilesOptions = array('version' => VIKAPPOINTMENTS_SOFTWARE_VERSION);
26
27 $document->addScript(VIKAPPOINTMENTS_CORE_MEDIA_URI . 'js/system.js', $internalFilesOptions, array('id' => 'vap-sys-script'));
28 $document->addScript(VIKAPPOINTMENTS_CORE_MEDIA_URI . 'js/admin.js', $internalFilesOptions, array('id' => 'vap-admin-script'));
29 $document->addScript(VIKAPPOINTMENTS_CORE_MEDIA_URI . 'js/bootstrap.min.js', $internalFilesOptions, array('id' => 'bootstrap-script'));
30 $document->addStyleSheet(VIKAPPOINTMENTS_CORE_MEDIA_URI . 'css/system.css', $internalFilesOptions, array('id' => 'vap-sys-style'));
31 $document->addStyleSheet(VIKAPPOINTMENTS_CORE_MEDIA_URI . 'css/bootstrap.lite.css', $internalFilesOptions, array('id' => 'bootstrap-lite-style'));
32
33 // prepare modal to display opt-in
34 echo JHtml::fetch(
35 'bootstrap.renderModal',
36 'jmodal-vap-rss-feed',
37 array(
38 'title' => '',
39 'closeButton' => true,
40 'keyboard' => true,
41 'top' => true,
42 'width' => 70,
43 'height' => 80,
44 ),
45 '{placeholder}'
46 );
47
48 ?>
49
50 <style>
51 #vik_appointments_rss .inside {
52 padding: 0 !important;
53 margin: 0 !important;
54 }
55 #vik_appointments_rss .modal-header h3 {
56 margin: 0;
57 line-height: 50px;
58 font-weight: normal;
59 font-size: 22px;
60 }
61 #vik_appointments_rss .modal-header h3 .dashicons-before:before {
62 line-height: 50px;
63 }
64 #vik_appointments_rss img {
65 max-width: 100%;
66 }
67
68 .vap-rss-widget ul {
69 margin: 0;
70 padding: 0;
71 }
72 .vap-rss-widget ul li {
73 list-style: none;
74 display: flex;
75 align-items: center;
76 justify-content: space-between;
77 flex-wrap: wrap;
78 margin: 0;
79 padding: 8px 12px;
80 border-bottom: 1px solid #eee;
81 }
82 .vap-rss-widget ul li:last-child {
83 border-bottom: 0;
84 }
85 .vap-rss-widget ul li:nth-child(odd) {
86 background: #fafafa;
87 }
88
89 .vap-rss-widget ul li .feed-icon {
90 width: 32px;
91 }
92 .vap-rss-widget ul li .feed-details {
93 flex: 1;
94 }
95 .vap-rss-widget ul li .feed-date-time {
96 text-align: right;
97 }
98
99 .vap-rss-widget .rss-missing-optin {
100 padding: 10px 10px 0 10px;
101 }
102 </style>
103
104 <div class="vap-rss-widget">
105
106 <?php
107 // make sure the RSS service is enabled
108 if (!$config->get('optin'))
109 {
110 // service not enabled
111 ?>
112 <div class="rss-missing-optin">
113 <div class="notice notice-error inline">
114 <p>
115 <?php _e('<b>You haven\'t opted in the RSS service!</b><br />Click the following button to start receiving RSS feeds.', 'vikappointments'); ?>
116 </p>
117
118 <p>
119 <a href="admin.php?page=vikappointments&view=editconfig#rss" class="button button-primary">
120 <?php _e('Activate RSS Feeds', 'vikappointments'); ?>
121 </a>
122 </p>
123 </div>
124 </div>
125 <?php
126 }
127 else if (!$feeds)
128 {
129 // no feeds to display
130 ?>
131 <div class="rss-missing-optin">
132 <div class="notice notice-warning inline">
133 <p>
134 <?php _e('No feeds to display', 'vikappointments'); ?>
135 </p>
136 </div>
137 </div>
138 <?php
139 }
140 else
141 {
142 ?>
143 <ul>
144 <?php
145 foreach ($feeds as $i => $feed)
146 {
147 switch (strtolower($feed->category))
148 {
149 case 'promo':
150 $icon = 'star-filled';
151 break;
152
153 case 'tips':
154 $icon = 'welcome-learn-more';
155 break;
156
157 case 'news':
158 $icon = 'megaphone';
159 break;
160
161 default:
162 $icon = 'rss';
163 }
164
165 ?>
166 <li data-id="<?php echo $feed->id; ?>">
167 <div class="feed-icon">
168 <span class="dashicons-before dashicons-<?php echo $icon; ?>"></span>
169 </div>
170
171 <div class="feed-details" data-title="<?php echo $this->escape($feed->title); ?>" data-category="<?php echo $this->escape($feed->category); ?>">
172 <div class="feed-title">
173 <a href="javascript: void(0);">
174 <b><?php echo $feed->title; ?></b>
175 </a>
176 </div>
177 <div class="feed-category"><?php echo $feed->category; ?></div>
178 </div>
179
180 <div class="feed-date-time">
181 <div class="feed-date">
182 <?php echo JHtml::fetch('date', $feed->date, JText::translate('DATE_FORMAT_LC3')); ?>
183 </div>
184 <div class="feed-time">
185 <?php echo JHtml::fetch('date', $feed->date, get_option('time_format')); ?>
186 </div>
187 </div>
188
189 <div style="display: none;" class="rss-content">
190 <?php echo $feed->content; ?>
191 </div>
192 </li>
193 <?php
194 }
195 ?>
196 </ul>
197 <?php
198 }
199 ?>
200
201 </div>
202
203 <script>
204
205 (function($) {
206 'use strict';
207
208 $(function() {
209 $('#vik_appointments_rss .feed-details a').on('click', function() {
210 // get parent <li>
211 var li = $(this).closest('li');
212 // find feed details
213 var details = li.find('.feed-details');
214 // find feed content
215 var content = li.find('.rss-content').html();
216
217 // get modal
218 var modal = $('#jmodal-vap-rss-feed');
219
220 // register feed ID
221 modal.attr('data-feed-id', li.data('id'));
222
223 // update modal title
224 modal.find('.modal-header h3').html(
225 li.find('.feed-icon').html() + ' ' +
226 details.data('category') + ' - ' +
227 details.data('title')
228 );
229
230 // update modal content
231 modal.find('.modal-body').html(content);
232
233 // manually adjust the links that specifiy a data attribute with a plain href
234 modal.find('.modal-body a[data-href-plain]').each(function() {
235 $(this).attr('href', $(this).data('href-plain'));
236 $(this).attr('data-href-plain', '');
237 });
238
239 // display modal
240 wpOpenJModal('vap-rss-feed');
241 });
242 });
243 })(jQuery);
244
245 </script>
246