| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Backup Tasks |
| 4 |
* |
| 5 |
* Displays the MainWP > Backups Page ( Legacy ). |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class MainWP_Backup_Tasks. |
| 14 |
* |
| 15 |
* @uses \MainWP\Dashboard\MainWP_Utility::format_timestamp() |
| 16 |
* @uses \MainWP\Dashboard\MainWP_Utility::get_timestamp() |
| 17 |
*/ |
| 18 |
class MainWP_Backup_Tasks { |
| 19 |
|
| 20 |
/** |
| 21 |
* Method get_class_name() |
| 22 |
* |
| 23 |
* Get Class Name. |
| 24 |
* |
| 25 |
* @return string CLASS Class Name. |
| 26 |
*/ |
| 27 |
public static function get_class_name() { |
| 28 |
return __CLASS__; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Method get_name() |
| 33 |
* |
| 34 |
* Get backup tasks name. |
| 35 |
* |
| 36 |
* @return string backup tasks |
| 37 |
*/ |
| 38 |
public static function get_name() { |
| 39 |
return __( 'Backup Tasks', 'mainwp' ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Method render() |
| 44 |
* |
| 45 |
* Render MainWP Legacy Backups List. |
| 46 |
* |
| 47 |
* @uses \MainWP\Dashboard\MainWP_DB_Backup::get_backup_tasks_for_user() |
| 48 |
* @uses \MainWP\Dashboard\MainWP_DB::get_sql_websites_by_group_id() |
| 49 |
*/ |
| 50 |
public static function render() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 51 |
|
| 52 |
$tasks = MainWP_DB_Backup::instance()->get_backup_tasks_for_user(); |
| 53 |
|
| 54 |
?> |
| 55 |
<h3><?php esc_html_e( 'Backup tasks', 'mainwp' ); ?></h3> |
| 56 |
<?php |
| 57 |
if ( count( $tasks ) == 0 ) { |
| 58 |
echo 'You have no scheduled backup tasks. <a href="admin.php?page=ManageBackupsAddNew">Go create one!</a>'; |
| 59 |
} else { |
| 60 |
?> |
| 61 |
<div class="mainwp-row-top" style="text-align: right; margin-bottom: 1em;"> |
| 62 |
<a href="admin.php?page=ManageBackups" class="button" ><?php esc_html_e( 'Manage Backups', 'mainwp' ); ?></a> |
| 63 |
<?php if ( mainwp_current_user_have_right( 'dashboard', 'add_backup_tasks' ) ) { ?> |
| 64 |
<a href="admin.php?page=ManageBackupsAddNew" class="button-primary" ><?php esc_html_e( 'Add new task', 'mainwp' ); ?></a> |
| 65 |
<?php } ?> |
| 66 |
</div> |
| 67 |
<div id="mainwp-backup-tasks-widget"> |
| 68 |
<style> |
| 69 |
@keyframes blinker { |
| 70 |
0% { background: #7fb100 ;} |
| 71 |
100% { background: #446200 ;} |
| 72 |
} |
| 73 |
@-webkit-keyframes blinker { |
| 74 |
0% { background: #7fb100 ;} |
| 75 |
100% { background: #446200 ;} |
| 76 |
} |
| 77 |
|
| 78 |
.mainwp-blink-me { |
| 79 |
animation: blinker 1s linear 0s infinite alternate; |
| 80 |
-webkit-animation: blinker 1s linear 0s infinite alternate; |
| 81 |
} |
| 82 |
</style> |
| 83 |
<?php |
| 84 |
foreach ( $tasks as $task ) { |
| 85 |
$sites = array(); |
| 86 |
if ( '' != $task->groups ) { |
| 87 |
$groups = explode( ',', $task->groups ); |
| 88 |
foreach ( $groups as $groupid ) { |
| 89 |
$group_sites = MainWP_DB::instance()->get_websites_by_group_id( $groupid ); |
| 90 |
foreach ( $group_sites as $group_site ) { |
| 91 |
if ( in_array( $group_site->id, $sites ) ) { |
| 92 |
continue; |
| 93 |
} |
| 94 |
$sites[] = $group_site->id; |
| 95 |
} |
| 96 |
} |
| 97 |
} elseif ( '' != $task->sites ) { |
| 98 |
$sites = explode( ',', $task->sites ); |
| 99 |
} |
| 100 |
?> |
| 101 |
<div class="ui grid mainwp-recent"> |
| 102 |
<div class="eight wide column"> |
| 103 |
<strong><a href="admin.php?page=ManageBackups&id=<?php echo esc_attr( $task->id ); ?>"><?php echo stripslashes( $task->name ); ?></a></strong><br /> |
| 104 |
<span style="font-size: 11px">(<?php echo strtoupper( $task->schedule ); ?> - <?php echo ( 'db' == $task->type ? __( 'Database backup', 'mainwp' ) : __( 'Full backup', 'mainwp' ) ); ?>)</span> |
| 105 |
</div> |
| 106 |
<div class="two wide column"> |
| 107 |
<?php |
| 108 |
if ( 1 == $task->paused ) { |
| 109 |
echo ( '<span title="Paused" style="background: #999; padding: .3em 1em; color: white; border-radius: 15px; -moz-border-radius: 15px; -webkit-border-radius: 15px;">' . count( $sites ) . '</span>' ); |
| 110 |
} elseif ( 0 == count( $sites ) ) { |
| 111 |
echo ( '<span title="0 Scheduled Websites" style="background: #c80000; padding: .3em 1em; color: white; border-radius: 15px; -moz-border-radius: 15px; -webkit-border-radius: 15px;">0</span>' ); |
| 112 |
} elseif ( 0 != $task->last_run && $task->completed < $task->last_run ) { |
| 113 |
echo ( '<span title="Backup in Progress" class="mainwp-blink-me" style="padding: .3em 1em; color: white; border-radius: 15px; -moz-border-radius: 15px; -webkit-border-radius: 15px;">' . count( $sites ) . '</span>' ); |
| 114 |
} else { |
| 115 |
echo ( '<span title="Scheduled Websites" style="background: #7fb100; padding: .3em 1em; color: white; border-radius: 15px; -moz-border-radius: 15px; -webkit-border-radius: 15px;">' . count( $sites ) . '</span>' ); |
| 116 |
} |
| 117 |
?> |
| 118 |
</div> |
| 119 |
<div class="six wide column"> |
| 120 |
<strong><?php esc_html_e( 'LAST RUN: ', 'mainwp' ); ?></strong> <?php echo ( 0 == $task->last_run ? '-' : MainWP_Utility::format_timestamp( MainWP_Utility::get_timestamp( $task->last_run ) ) ); ?><br /> |
| 121 |
<strong><?php esc_html_e( 'NEXT RUN: ', 'mainwp' ); ?></strong> <?php echo ( 0 == $task->last_run ? __( 'Any minute', 'mainwp' ) : MainWP_Utility::format_timestamp( ( 'daily' == $task->schedule ? ( 60 * 60 * 24 ) : ( 'weekly' == $task->schedule ? ( 60 * 60 * 24 * 7 ) : ( 60 * 60 * 24 * 30 ) ) ) + MainWP_Utility::get_timestamp( $task->last_run ) ) ); ?> |
| 122 |
</div> |
| 123 |
</div> |
| 124 |
<?php |
| 125 |
} |
| 126 |
?> |
| 127 |
</div> |
| 128 |
<?php |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|