PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.2
6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 5.2.2 5.3 All 153 releases
mainwp / widgets / widget-mainwp-recent-posts.php

widget-mainwp-recent-posts.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 4.2, at widgets/widget-mainwp-recent-posts.php

865 lines 33.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * MainWP Recent Posts Widget
4 *
5 * Displays the Child Sites most recent published draft, pending, trash & future posts.
6 *
7 * @package MainWP/Widget_Recent_Posts
8 */
9
10 namespace MainWP\Dashboard;
11
12 /**
13 * Class MainWP_Recent_Posts
14 *
15 * Displays the Child Sites most recent published draft, pending, trash & future posts.
16 */
17 class MainWP_Recent_Posts {
18
19 /**
20 * Method get_class_name()
21 *
22 * @return string __CLASS__ Class Name
23 */
24 public static function get_class_name() {
25 return __CLASS__;
26 }
27
28 /**
29 * Method render()
30 *
31 * Fire off render_sites().
32 */
33 public static function render() {
34 self::render_sites();
35 }
36
37 /**
38 * Method render_sites()
39 *
40 * Build the recent posts list.
41 *
42 * @uses \MainWP\Dashboard\MainWP_DB::query()
43 * @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_for_current_user()
44 * @uses \MainWP\Dashboard\MainWP_DB::fetch_object()
45 * @uses \MainWP\Dashboard\MainWP_DB::free_result()
46 * @uses \MainWP\Dashboard\MainWP_System_Utility::get_current_wpid()
47 */
48 public static function render_sites() {
49
50 /**
51 * Sets number of recent posts & pages
52 *
53 * Limits the number of recent posts & pages to show in the widget. Min 0, Max 30, Default 5.
54 *
55 * @since 4.0
56 */
57 $recent_number = apply_filters( 'mainwp_recent_posts_pages_number', 5 );
58
59 $current_wpid = MainWP_System_Utility::get_current_wpid();
60
61 if ( $current_wpid ) {
62 $sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid );
63 $individual = true;
64 } else {
65 $sql = MainWP_DB::instance()->get_sql_websites_for_current_user();
66 $individual = false;
67 }
68
69 $websites = MainWP_DB::instance()->query( $sql );
70
71 $allPosts = array();
72 if ( $websites ) {
73 while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
74 if ( '' == $website->recent_posts ) {
75 continue;
76 }
77
78 $posts = json_decode( $website->recent_posts, 1 );
79 if ( 0 == count( $posts ) ) {
80 continue;
81 }
82 foreach ( $posts as $post ) {
83 $post['website'] = (object) array(
84 'id' => $website->id,
85 'url' => $website->url,
86 'name' => $website->name,
87 );
88 $allPosts[] = $post;
89 }
90 }
91 MainWP_DB::free_result( $websites );
92 }
93
94 self::render_top_grid();
95
96 /**
97 * Action: mainwp_recent_posts_widget_top
98 *
99 * Fires at the top of the Recent Posts widget.
100 *
101 * @since 4.1
102 */
103 do_action( 'mainwp_recent_posts_widget_top' );
104
105 self::render_published_posts( $allPosts, $recent_number, $individual );
106 self::render_draft_posts( $allPosts, $recent_number, $individual );
107 self::render_pending_posts( $allPosts, $recent_number, $individual );
108 self::render_future_posts( $allPosts, $recent_number, $individual );
109 self::render_trash_posts( $allPosts, $recent_number, $individual );
110
111 /**
112 * Action: mainwp_recent_posts_after_lists
113 *
114 * Fires after the recent posts lists, before the bottom actions section.
115 *
116 * @since 4.1
117 */
118 do_action( 'mainwp_recent_posts_after_lists' );
119 ?>
120
121
122 <div class="ui hidden divider"></div>
123
124 <div class="ui two column grid">
125 <div class="column">
126 <a href="<?php echo admin_url( 'admin.php?page=PostBulkManage' ); ?>" title="" class="ui button green basic"><?php esc_html_e( 'Manage Posts', 'mainwp' ); ?></a>
127 </div>
128 <div class="column right aligned">
129 <a href="<?php echo admin_url( 'admin.php?page=PostBulkAdd' ); ?>" title="" class="ui button green"><?php esc_html_e( 'Create New Post', 'mainwp' ); ?></a>
130 </div>
131 </div>
132 <?php
133 /**
134 * Action: mainwp_recent_posts_widget_bottom
135 *
136 * Fires at the bottom of the Recent Posts widget.
137 *
138 * @since 4.1
139 */
140 do_action( 'mainwp_recent_posts_widget_bottom' );
141 }
142
143 /**
144 * Render MainWP Recent Posts Widget Header
145 */
146 public static function render_top_grid() {
147 ?>
148 <div class="ui grid">
149 <div class="twelve wide column">
150 <h3 class="ui header handle-drag">
151 <?php
152 /**
153 * Filter: mainwp_recent_posts_widget_title
154 *
155 * Filters the recent posts widget title text.
156 *
157 * @since 4.1
158 */
159 echo esc_html( apply_filters( 'mainwp_recent_posts_widget_title', __( 'Recent Posts', 'mainwp' ) ) );
160 ?>
161 <div class="sub header"><?php esc_html_e( 'The most recent posts from your websites', 'mainwp' ); ?></div>
162 </h3>
163 </div>
164 <div class="four wide column right aligned">
165 <div class="ui dropdown right pointing mainwp-dropdown-tab">
166 <div class="text"><?php esc_html_e( 'Published', 'mainwp' ); ?></div>
167 <i class="dropdown icon"></i>
168 <div class="menu">
169 <a class="item recent_posts_published_lnk" data-tab="published" data-value="published" title="<?php esc_attr_e( 'Published', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Published', 'mainwp' ); ?></a>
170 <a class="item recent_posts_draft_lnk" data-tab="draft" data-value="draft" title="<?php esc_attr_e( 'Draft', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Draft', 'mainwp' ); ?></a>
171 <a class="item recent_posts_pending_lnk" data-tab="pending" data-value="pending" title="<?php esc_attr_e( 'Pending', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Pending', 'mainwp' ); ?></a>
172 <a class="item recent_posts_future_lnk" data-tab="future" data-value="future" title="<?php esc_attr_e( 'Scheduled', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Scheduled', 'mainwp' ); ?></a>
173 <a class="item recent_posts_trash_lnk" data-tab="trash" data-value="trash" title="<?php esc_attr_e( 'Trash', 'mainwp' ); ?>" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
174 </div>
175 </div>
176 </div>
177 </div>
178 <div class="ui section hidden divider"></div>
179 <?php
180 }
181
182 /**
183 * Render Published Posts.
184 *
185 * @param array $allPosts All posts data.
186 * @param int $recent_number Number of posts.
187 * @param bool $individual Determins if it's individual site dashbaord.
188 *
189 * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
190 * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
191 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
192 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
193 */
194 public static function render_published_posts( $allPosts, $recent_number, $individual ) {
195 $recent_posts_published = MainWP_Utility::get_sub_array_having( $allPosts, 'status', 'publish' );
196 $recent_posts_published = MainWP_Utility::sortmulti( $recent_posts_published, 'dts', 'desc' );
197 ?>
198 <div class="recent_posts_published ui tab active" data-tab="published">
199 <?php
200 /**
201 * Action: mainwp_recent_posts_before_publised_list
202 *
203 * Fires before the list of recent published Posts.
204 *
205 * @param array $allPosts All posts data.
206 * @param int $recent_number Number of posts.
207 *
208 * @since 4.1
209 */
210 do_action( 'mainwp_recent_posts_before_publised_list', $allPosts, $recent_number );
211 if ( 0 == count( $recent_posts_published ) ) {
212 ?>
213 <h2 class="ui icon header">
214 <i class="folder open outline icon"></i>
215 <div class="content">
216 <?php esc_html_e( 'No published posts found!', 'mainwp' ); ?>
217 </div>
218 </h2>
219 <?php
220 }
221 ?>
222 <div class="ui middle aligned divided selection list">
223 <?php
224 $_count = count( $recent_posts_published );
225 for ( $i = 0; $i < $_count && $i < $recent_number; $i ++ ) {
226 if ( ! isset( $recent_posts_published[ $i ]['title'] ) || ( '' == $recent_posts_published[ $i ]['title'] ) ) {
227 $recent_posts_published[ $i ]['title'] = '(No Title)';
228 }
229 if ( isset( $recent_posts_published[ $i ]['dts'] ) ) {
230 if ( ! stristr( $recent_posts_published[ $i ]['dts'], '-' ) ) {
231 $recent_posts_published[ $i ]['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $recent_posts_published[ $i ]['dts'] ) );
232 }
233 }
234
235 $name = wp_strip_all_tags( $recent_posts_published[ $i ]['website']->name );
236
237 ?>
238 <div class="item">
239 <div class="ui grid">
240 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_published[ $i ]['id'] ); ?>"/>
241 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_published[ $i ]['website']->id ); ?>"/>
242 <div class="six wide column middle aligned">
243 <a href="<?php echo esc_url( $recent_posts_published[ $i ]['website']->url ); ?>?p=<?php echo esc_attr( $recent_posts_published[ $i ]['id'] ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo htmlentities( $recent_posts_published[ $i ]['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ); ?></a>
244 </div>
245 <div class="<?php echo $individual ? 'eight' : 'four'; ?> wide column middle aligned">
246 <?php echo esc_html( $recent_posts_published[ $i ]['dts'] ); ?>
247 </div>
248 <?php if ( ! $individual ) : ?>
249 <div class="four wide column middle aligned">
250 <a href="<?php echo esc_url( $recent_posts_published[ $i ]['website']->url ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo $name; ?></a>
251 </div>
252 <?php endif; ?>
253 <div class="two wide column right aligned">
254 <div class="ui left pointing dropdown icon mini basic green button" style="z-index:999">
255 <i class="ellipsis horizontal icon"></i>
256 <div class="menu">
257 <a class="item mainwp-post-unpublish" href="#"><?php esc_html_e( 'Unpublish', 'mainwp' ); ?></a>
258 <a class="item" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo $recent_posts_published[ $i ]['website']->id; ?>&location=<?php echo base64_encode( 'post.php?action=editpost&post=' . $recent_posts_published[ $i ]['id'] . '&action=edit' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>" target="_blank"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
259 <a class="item mainwp-post-trash" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
260 <a class="item" href="<?php echo esc_url( $recent_posts_published[ $i ]['website']->url ) . ( '/' != substr( $recent_posts_published[ $i ]['website']->url, - 1 ) ? '/' : '' ) . '?p=' . esc_attr( $recent_posts_published[ $i ]['id'] ); ?>" target="_blank"><?php esc_html_e( 'View', 'mainwp' ); ?></a>
261 </div>
262 </div>
263 </div>
264 </div>
265 <div class="mainwp-row-actions-working"><i class="notched circle loading icon"></i><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div>
266 </div>
267 <?php } ?>
268 </div>
269 <?php
270 /**
271 * Action: mainwp_recent_posts_after_publised_list
272 *
273 * Fires after the list of recent published Posts.
274 *
275 * @param array $allPosts All posts data.
276 * @param int $recent_number Number of posts.
277 *
278 * @since 4.1
279 */
280 do_action( 'mainwp_recent_posts_after_publised_list', $allPosts, $recent_number );
281 ?>
282 </div>
283 <?php
284 }
285
286 /**
287 * Render all draft posts.
288 *
289 * @param array $allPosts All posts data.
290 * @param int $recent_number Number of posts.
291 * @param bool $individual Determins if it's individual site dashbaord.
292 *
293 * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
294 * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
295 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
296 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
297 */
298 public static function render_draft_posts( $allPosts, $recent_number, $individual ) {
299
300 $recent_posts_draft = MainWP_Utility::get_sub_array_having( $allPosts, 'status', 'draft' );
301 $recent_posts_draft = MainWP_Utility::sortmulti( $recent_posts_draft, 'dts', 'desc' );
302 ?>
303 <div class="recent_posts_draft ui tab" data-tab="draft">
304 <?php
305 /**
306 * Action: mainwp_recent_posts_before_draft_list
307 *
308 * Fires before the list of recent draft Posts.
309 *
310 * @param array $allPosts All posts data.
311 * @param int $recent_number Number of posts.
312 *
313 * @since 4.1
314 */
315 do_action( 'mainwp_recent_posts_before_draft_list', $allPosts, $recent_number );
316 if ( 0 == count( $recent_posts_draft ) ) {
317 ?>
318 <h2 class="ui icon header">
319 <i class="folder open outline icon"></i>
320 <div class="content">
321 <?php esc_html_e( 'No draft posts found!', 'mainwp' ); ?>
322 </div>
323 </h2>
324 <?php
325 }
326 ?>
327 <div class="ui middle aligned divided selection list">
328 <?php
329 $_count = count( $recent_posts_draft );
330 for ( $i = 0; $i < $_count && $i < $recent_number; $i ++ ) {
331 if ( ! isset( $recent_posts_draft[ $i ]['title'] ) || ( '' == $recent_posts_draft[ $i ]['title'] ) ) {
332 $recent_posts_draft[ $i ]['title'] = '(No Title)';
333 }
334 if ( isset( $recent_posts_draft[ $i ]['dts'] ) ) {
335 if ( ! stristr( $recent_posts_draft[ $i ]['dts'], '-' ) ) {
336 $recent_posts_draft[ $i ]['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $recent_posts_draft[ $i ]['dts'] ) );
337 }
338 }
339 $name = wp_strip_all_tags( $recent_posts_draft[ $i ]['website']->name );
340 ?>
341 <div class="item">
342 <div class="ui grid">
343 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_draft[ $i ]['id'] ); ?>"/>
344 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_draft[ $i ]['website']->id ); ?>"/>
345 <div class="six wide column middle aligned">
346 <a href="<?php echo esc_url( $recent_posts_draft[ $i ]['website']->url ); ?>?p=<?php echo esc_attr( $recent_posts_draft[ $i ]['id'] ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo htmlentities( $recent_posts_draft[ $i ]['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ); ?></a>
347 </div>
348 <div class="<?php echo $individual ? 'eight' : 'four'; ?> wide column middle aligned">
349 <?php echo esc_html( $recent_posts_draft[ $i ]['dts'] ); ?>
350 </div>
351 <?php if ( ! $individual ) : ?>
352 <div class="four wide column middle aligned">
353 <a href="<?php echo esc_url( $recent_posts_draft[ $i ]['website']->url ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo $name; ?></a>
354 </div>
355 <?php endif; ?>
356 <div class="two wide column right aligned">
357 <div class="ui left pointing dropdown icon mini basic green button" style="z-index:999">
358 <i class="ellipsis horizontal icon"></i>
359 <div class="menu">
360 <a class="item mainwp-post-publish" href="#"><?php esc_html_e( 'Publish', 'mainwp' ); ?></a>
361 <a class="item" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_attr( $recent_posts_draft[ $i ]['website']->id ); ?>&location=<?php echo base64_encode( 'post.php?action=editpost&post=' . $recent_posts_draft[ $i ]['id'] . '&action=edit' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>" target="_blank"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
362 <a class="item mainwp-post-trash" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
363 </div>
364 </div>
365 </div>
366 </div>
367 <div class="mainwp-row-actions-working"><i class="notched circle loading icon"></i><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div>
368 </div>
369 <?php } ?>
370 </div>
371 <?php
372 /**
373 * Action: mainwp_recent_posts_after_draft_list
374 *
375 * Fires after the list of recent draft Posts.
376 *
377 * @param array $allPosts All posts data.
378 * @param int $recent_number Number of posts.
379 *
380 * @since 4.1
381 */
382 do_action( 'mainwp_recent_posts_after_draft_list', $allPosts, $recent_number );
383 ?>
384 </div>
385 <?php
386 }
387
388 /**
389 * Render all pending posts.
390 *
391 * @param array $allPosts All posts data.
392 * @param int $recent_number Number of posts.
393 * @param bool $individual Determins if it's individual site dashbaord.
394 *
395 * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
396 * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
397 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
398 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
399 */
400 public static function render_pending_posts( $allPosts, $recent_number, $individual ) {
401 $recent_posts_pending = MainWP_Utility::get_sub_array_having( $allPosts, 'status', 'pending' );
402 $recent_posts_pending = MainWP_Utility::sortmulti( $recent_posts_pending, 'dts', 'desc' );
403
404 ?>
405 <div class="recent_posts_pending ui bottom attached tab" data-tab="pending">
406 <?php
407 /**
408 * Action: mainwp_recent_posts_before_pending_list
409 *
410 * Fires before the list of recent pending Posts.
411 *
412 * @param array $allPosts All posts data.
413 * @param int $recent_number Number of posts.
414 *
415 * @since 4.1
416 */
417 do_action( 'mainwp_recent_posts_before_pending_list', $allPosts, $recent_number );
418 if ( 0 == count( $recent_posts_pending ) ) {
419 ?>
420 <h2 class="ui icon header">
421 <i class="folder open outline icon"></i>
422 <div class="content">
423 <?php esc_html_e( 'No pending posts found!', 'mainwp' ); ?>
424 </div>
425 </h2>
426 <?php
427 }
428 ?>
429 <div class="ui middle aligned divided selection list">
430 <?php
431 $_count = count( $recent_posts_pending );
432 for ( $i = 0; $i < $_count && $i < $recent_number; $i ++ ) {
433 if ( ! isset( $recent_posts_pending[ $i ]['title'] ) || ( '' == $recent_posts_pending[ $i ]['title'] ) ) {
434 $recent_posts_pending[ $i ]['title'] = '(No Title)';
435 }
436 if ( isset( $recent_posts_pending[ $i ]['dts'] ) ) {
437 if ( ! stristr( $recent_posts_pending[ $i ]['dts'], '-' ) ) {
438 $recent_posts_pending[ $i ]['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $recent_posts_pending[ $i ]['dts'] ) );
439 }
440 }
441 $name = wp_strip_all_tags( $recent_posts_pending[ $i ]['website']->name );
442 ?>
443 <div class="item">
444 <div class="ui grid">
445 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_pending[ $i ]['id'] ); ?>"/>
446 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_pending[ $i ]['website']->id ); ?>"/>
447 <div class="six wide column middle aligned">
448 <a href="<?php echo esc_url( $recent_posts_pending[ $i ]['website']->url ); ?>?p=<?php echo esc_attr( $recent_posts_pending[ $i ]['id'] ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo htmlentities( $recent_posts_pending[ $i ]['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ); ?></a>
449 </div>
450 <div class="<?php echo $individual ? 'eight' : 'four'; ?> wide column middle aligned">
451 <?php echo esc_html( $recent_posts_pending[ $i ]['dts'] ); ?>
452 </div>
453 <?php if ( ! $individual ) : ?>
454 <div class="four wide column middle aligned">
455 <a href="<?php echo esc_url( $recent_posts_pending[ $i ]['website']->url ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo $name; ?></a>
456 </div>
457 <?php endif; ?>
458 <div class="two wide column right aligned">
459 <div class="ui left pointing dropdown icon mini basic green button" style="z-index:999">
460 <i class="ellipsis horizontal icon"></i>
461 <div class="menu">
462 <a class="item mainwp-post-publish" href="#"><?php esc_html_e( 'Publish', 'mainwp' ); ?></a>
463 <a class="item" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_attr( $recent_posts_pending[ $i ]['website']->id ); ?>&location=<?php echo base64_encode( 'post.php?action=editpost&post=' . $recent_posts_pending[ $i ]['id'] . '&action=edit' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>" target="_blank"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
464 <a class="item mainwp-post-trash" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
465 </div>
466 </div>
467 </div>
468 </div>
469 <div class="mainwp-row-actions-working"><i class="notched circle loading icon"></i><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div>
470 </div>
471 <?php } ?>
472 </div>
473 <?php
474 /**
475 * Action: mainwp_recent_posts_after_pending_list
476 *
477 * Fires after the list of recent pending Posts.
478 *
479 * @param array $allPosts All posts data.
480 * @param int $recent_number Number of posts.
481 *
482 * @since 4.1
483 */
484 do_action( 'mainwp_recent_posts_after_pending_list', $allPosts, $recent_number );
485 ?>
486 </div>
487 <?php
488 }
489
490 /**
491 * Render all future posts.
492 *
493 * @param array $allPosts All posts data.
494 * @param int $recent_number Number of posts.
495 * @param bool $individual Determins if it's individual site dashbaord.
496 *
497 * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
498 * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
499 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
500 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
501 */
502 public static function render_future_posts( $allPosts, $recent_number, $individual ) {
503 $recent_posts_future = MainWP_Utility::get_sub_array_having( $allPosts, 'status', 'future' );
504 $recent_posts_future = MainWP_Utility::sortmulti( $recent_posts_future, 'dts', 'desc' );
505 ?>
506 <div class="recent_posts_future ui tab" data-tab="future">
507 <?php
508 /**
509 * Action: mainwp_recent_posts_before_future_list
510 *
511 * Fires before the list of recent future Posts.
512 *
513 * @param array $allPosts All posts data.
514 * @param int $recent_number Number of posts.
515 *
516 * @since 4.1
517 */
518 do_action( 'mainwp_recent_posts_before_future_list', $allPosts, $recent_number );
519 if ( 0 == count( $recent_posts_future ) ) {
520 ?>
521 <h2 class="ui icon header">
522 <i class="folder open outline icon"></i>
523 <div class="content">
524 <?php esc_html_e( 'No future posts found!', 'mainwp' ); ?>
525 </div>
526 </h2>
527 <?php
528 }
529 ?>
530 <div class="ui middle aligned divided selection list">
531 <?php
532 $_count = count( $recent_posts_future );
533 for ( $i = 0; $i < $_count && $i < $recent_number; $i ++ ) {
534 if ( ! isset( $recent_posts_future[ $i ]['title'] ) || ( '' == $recent_posts_future[ $i ]['title'] ) ) {
535 $recent_posts_future[ $i ]['title'] = '(No Title)';
536 }
537 if ( isset( $recent_posts_future[ $i ]['dts'] ) ) {
538 if ( ! stristr( $recent_posts_future[ $i ]['dts'], '-' ) ) {
539 $recent_posts_future[ $i ]['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $recent_posts_future[ $i ]['dts'] ) );
540 }
541 }
542 $name = wp_strip_all_tags( $recent_posts_future[ $i ]['website']->name );
543 ?>
544 <div class="item">
545 <div class="ui grid">
546 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_future[ $i ]['id'] ); ?>"/>
547 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_future[ $i ]['website']->id ); ?>"/>
548 <div class="six wide column middle aligned">
549 <a href="<?php echo esc_url( $recent_posts_future[ $i ]['website']->url ); ?>?p=<?php echo esc_attr( $recent_posts_future[ $i ]['id'] ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo htmlentities( $recent_posts_future[ $i ]['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ); ?></a>
550 </div>
551 <div class="<?php echo $individual ? 'eight' : 'four'; ?> wide column middle aligned">
552 <?php echo esc_html( $recent_posts_future[ $i ]['dts'] ); ?>
553 </div>
554 <?php if ( ! $individual ) : ?>
555 <div class="four wide column middle aligned">
556 <a href="<?php echo esc_url( $recent_posts_future[ $i ]['website']->url ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo $name; ?></a>
557 </div>
558 <?php endif; ?>
559 <div class="two wide column right aligned">
560 <div class="ui left pointing dropdown icon mini basic green button" style="z-index:999">
561 <i class="ellipsis horizontal icon"></i>
562 <div class="menu">
563 <a class="item mainwp-post-publish" href="#"><?php esc_html_e( 'Publish', 'mainwp' ); ?></a>
564 <a class="item" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_attr( $recent_posts_future[ $i ]['website']->id ); ?>&location=<?php echo base64_encode( 'post.php?action=editpost&post=' . $recent_posts_future[ $i ]['id'] . '&action=edit' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>" target="_blank"><?php esc_html_e( 'Edit', 'mainwp' ); ?></a>
565 <a class="item mainwp-post-trash" href="#"><?php esc_html_e( 'Trash', 'mainwp' ); ?></a>
566 <a class="item" href="admin.php?page=SiteOpen&newWindow=yes&websiteid=<?php echo esc_attr( $recent_posts_future[ $i ]['website']->id ); ?>&newWindow=yes&openUrl=yes&location=<?php echo base64_encode( '?p=' . $recent_posts_future[ $i ]['id'] . '&preview=true' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. ?>" target="_blank"><?php esc_html_e( 'Preview', 'mainwp' ); ?></a>
567 </div>
568 </div>
569 </div>
570 </div>
571 <div class="mainwp-row-actions-working"><i class="notched circle loading icon"></i><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div>
572 </div>
573 <?php } ?>
574 </div>
575 <?php
576 /**
577 * Action: mainwp_recent_posts_after_future_list
578 *
579 * Fires after the list of recent future Posts.
580 *
581 * @param array $allPosts All posts data.
582 * @param int $recent_number Number of posts.
583 *
584 * @since 4.1
585 */
586 do_action( 'mainwp_recent_posts_after_future_list', $allPosts, $recent_number );
587 ?>
588 </div>
589 <?php
590 }
591
592 /**
593 * Render all trashed posts.
594 *
595 * @param array $allPosts All posts data.
596 * @param int $recent_number Number of posts.
597 * @param bool $individual Determins if it's individual site dashbaord.
598 *
599 * @uses \MainWP\Dashboard\MainWP_Utility::get_sub_array_having()
600 * @uses \MainWP\Dashboard\MainWP_Utility::sortmulti()
601 * @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp()
602 * @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp()
603 */
604 public static function render_trash_posts( $allPosts, $recent_number, $individual ) {
605 $recent_posts_trash = MainWP_Utility::get_sub_array_having( $allPosts, 'status', 'trash' );
606 $recent_posts_trash = MainWP_Utility::sortmulti( $recent_posts_trash, 'dts', 'desc' );
607
608 ?>
609 <div class="recent_posts_trash ui tab" data-tab="trash">
610 <?php
611 /**
612 * Action: mainwp_recent_posts_before_trash_list
613 *
614 * Fires before the list of recent trash Posts.
615 *
616 * @param array $allPosts All posts data.
617 * @param int $recent_number Number of posts.
618 *
619 * @since 4.1
620 */
621 do_action( 'mainwp_recent_posts_before_trash_list', $allPosts, $recent_number );
622 if ( 0 == count( $recent_posts_trash ) ) {
623 ?>
624 <h2 class="ui icon header">
625 <i class="folder open outline icon"></i>
626 <div class="content">
627 <?php esc_html_e( 'No trashed posts found!', 'mainwp' ); ?>
628 </div>
629 </h2>
630 <?php
631 }
632 ?>
633 <div class="ui middle aligned divided selection list">
634 <?php
635 $_count = count( $recent_posts_trash );
636 for ( $i = 0; $i < $_count && $i < $recent_number; $i ++ ) {
637 if ( ! isset( $recent_posts_trash[ $i ]['title'] ) || ( '' == $recent_posts_trash[ $i ]['title'] ) ) {
638 $recent_posts_trash[ $i ]['title'] = '(No Title)';
639 }
640 if ( isset( $recent_posts_trash[ $i ]['dts'] ) ) {
641 if ( ! stristr( $recent_posts_trash[ $i ]['dts'], '-' ) ) {
642 $recent_posts_trash[ $i ]['dts'] = MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $recent_posts_trash[ $i ]['dts'] ) );
643 }
644 }
645 $name = wp_strip_all_tags( $recent_posts_trash[ $i ]['website']->name );
646 ?>
647 <div class="item">
648 <div class="ui grid">
649 <input class="postId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_trash[ $i ]['id'] ); ?>"/>
650 <input class="websiteId" type="hidden" name="id" value="<?php echo esc_attr( $recent_posts_trash[ $i ]['website']->id ); ?>"/>
651 <div class="six wide column middle aligned">
652 <?php echo htmlentities( $recent_posts_trash[ $i ]['title'], ENT_COMPAT | ENT_HTML401, 'UTF-8' ); ?>
653 </div>
654 <div class="<?php echo $individual ? 'eight' : 'four'; ?> wide column middle aligned">
655 <?php echo esc_html( $recent_posts_trash[ $i ]['dts'] ); ?>
656 </div>
657 <?php if ( ! $individual ) : ?>
658 <div class="four wide column middle aligned">
659 <a href="<?php echo esc_url( $recent_posts_trash[ $i ]['website']->url ); ?>" class="mainwp-may-hide-referrer" target="_blank"><?php echo $name; ?></a>
660 </div>
661 <?php endif; ?>
662 <div class="two wide column right aligned">
663 <div class="ui left pointing dropdown icon mini basic green button" style="z-index:999">
664 <i class="ellipsis horizontal icon"></i>
665 <div class="menu">
666 <a href="#" class="item mainwp-post-restore"><?php esc_html_e( 'Restore', 'mainwp' ); ?></a>
667 <a href="#" class="item mainwp-post-delete"><?php esc_html_e( 'Delete permanently', 'mainwp' ); ?></a>
668 </div>
669 </div>
670 </div>
671 </div>
672 <div class="mainwp-row-actions-working"><i class="notched circle loading icon"></i><?php esc_html_e( 'Please wait...', 'mainwp' ); ?></div>
673 </div>
674 <?php } ?>
675 </div>
676 <?php
677 /**
678 * Action: mainwp_recent_posts_after_trash_list
679 *
680 * Fires after the list of recent trash Posts.
681 *
682 * @param array $allPosts All posts data.
683 * @param int $recent_number Number of posts.
684 *
685 * @since 4.1
686 */
687 do_action( 'mainwp_recent_posts_after_trash_list', $allPosts, $recent_number );
688 ?>
689 </div>
690 <?php
691 }
692
693 /**
694 * Method publish()
695 *
696 * Publish Post.
697 */
698 public static function publish() {
699 self::action( 'publish' );
700 die( wp_json_encode( array( 'result' => __( 'Post has been published!', 'mainwp' ) ) ) );
701 }
702
703 /**
704 * Method approve()
705 *
706 * Approve Post.
707 */
708 public static function approve() {
709 self::action( 'publish' );
710 die( wp_json_encode( array( 'result' => __( 'Post has been approved!', 'mainwp' ) ) ) );
711 }
712
713 /**
714 * Method unpublish()
715 *
716 * Unpublish Post.
717 */
718 public static function unpublish() {
719 self::action( 'unpublish' );
720 die( wp_json_encode( array( 'result' => __( 'Post has been unpublished!', 'mainwp' ) ) ) );
721 }
722
723 /**
724 * Method trash()
725 *
726 * Trash Post.
727 */
728 public static function trash() {
729 self::action( 'trash' );
730 die( wp_json_encode( array( 'result' => __( 'Post has been moved to trash!', 'mainwp' ) ) ) );
731 }
732
733 /**
734 * Method delete()
735 *
736 * Delete Post.
737 */
738 public static function delete() {
739 self::action( 'delete' );
740 die( wp_json_encode( array( 'result' => __( 'Post has been permanently deleted!', 'mainwp' ) ) ) );
741 }
742
743 /**
744 * Method restore()
745 *
746 * Restore Post.
747 */
748 public static function restore() {
749 self::action( 'restore' );
750 die( wp_json_encode( array( 'result' => __( 'Post has been restored!', 'mainwp' ) ) ) );
751 }
752
753 /**
754 * Method action()
755 *
756 * Initiate try catch for chosen Action
757 *
758 * @param string $pAction Post Action.
759 * @param string $type Post type.
760 *
761 * @throws \Exception Error message.
762 *
763 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
764 * @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
765 * @uses \MainWP\Dashboard\MainWP_Exception
766 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
767 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
768 */
769 public static function action( $pAction, $type = 'post' ) {
770 $postId = isset( $_POST['postId'] ) ? intval( $_POST['postId'] ) : false;
771 $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false;
772
773 if ( empty( $postId ) || empty( $websiteId ) ) {
774 die( wp_json_encode( array( 'error' => 'Post ID or site ID not found. Please, reload the page and try again.' ) ) );
775 }
776
777 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
778 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
779 die( wp_json_encode( array( 'error' => 'You can not edit this website!' ) ) );
780 }
781
782 /**
783 * Action: mainwp_before_post_action
784 *
785 * Fires before post/page publish/unpublish/trash/delete/restore actions.
786 *
787 * @since 4.1
788 */
789 do_action( 'mainwp_before_post_action', $type, $pAction, $postId, $website );
790
791 try {
792 $information = MainWP_Connect::fetch_url_authed(
793 $website,
794 'post_action',
795 array(
796 'action' => $pAction,
797 'id' => $postId,
798 )
799 );
800 } catch ( MainWP_Exception $e ) {
801 die( wp_json_encode( array( 'error' => MainWP_Error_Helper::get_error_message( $e ) ) ) );
802 }
803
804 /**
805 * Action: mainwp_after_post_action
806 *
807 * Fires after post/page publish/unpublish/trash/delete/restore actions.
808 *
809 * @since 4.1
810 */
811 do_action( 'mainwp_after_post_action', $information, $type, $pAction, $postId, $website );
812
813 if ( ! isset( $information['status'] ) || ( 'SUCCESS' != $information['status'] ) ) {
814 die( wp_json_encode( array( 'error' => 'Unexpected error!' ) ) );
815 }
816 }
817
818 /**
819 * Method action_update()
820 *
821 * Update Post Action.
822 *
823 * @param mixed $pAction Post Action.
824 *
825 * @throws \Exception Error message.
826 *
827 * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
828 * @uses \MainWP\Dashboard\MainWP_Exception
829 * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
830 * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
831 */
832 public static function action_update( $pAction ) {
833 $postId = isset( $_POST['postId'] ) ? intval( $_POST['postId'] ) : false;
834 $websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false;
835 $post_data = isset( $_POST['post_data'] ) ? wp_unslash( $_POST['post_data'] ) : array();
836
837 if ( empty( $postId ) || empty( $websiteId ) ) {
838 die( 'FAIL' );
839 }
840
841 $website = MainWP_DB::instance()->get_website_by_id( $websiteId );
842 if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
843 die( 'FAIL' );
844 }
845
846 try {
847 $information = MainWP_Connect::fetch_url_authed(
848 $website,
849 'post_action',
850 array(
851 'action' => $pAction,
852 'id' => $postId,
853 'post_data' => $post_data,
854 )
855 );
856 } catch ( MainWP_Exception $e ) {
857 die( 'FAIL' );
858 }
859 if ( ! isset( $information['status'] ) || ( 'SUCCESS' != $information['status'] ) ) {
860 die( 'FAIL' );
861 }
862 }
863
864 }
865