PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 4.6.0.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v4.6.0.1
6.2.2 6.2.1 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 All 155 releases
mainwp / widgets / widget-mainwp-recent-posts.php

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

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