PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/backwpup/inc/class-page-backwpup.php

https://bitbucket.org/cesarmedrano/cesarmedrano
PHP | 290 lines | 223 code | 28 blank | 39 comment | 52 complexity | 01db96863430f6e36a318f8d95d16253 MD5 | raw file
  1. <?php
  2. /**
  3. * Render plugin dashboard.
  4. *
  5. * @author danielhuesken
  6. */
  7. class BackWPup_Page_BackWPup {
  8. /**
  9. * Called on load action.
  10. *
  11. * @return void
  12. */
  13. public static function load() {
  14. global $wpdb;
  15. if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'dbdumpdl' ) {
  16. //check permissions
  17. check_admin_referer( 'backwpupdbdumpdl' );
  18. if ( ! current_user_can( 'backwpup_jobs_edit' ) )
  19. die();
  20. //doing dump
  21. header( "Pragma: public" );
  22. header( "Expires: 0" );
  23. header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
  24. header( "Content-Type: application/octet-stream; charset=". get_bloginfo( 'charset' ) );
  25. header( "Content-Disposition: attachment; filename=" . DB_NAME . ".sql.gz;" );
  26. try {
  27. $sql_dump = new BackWPup_MySQLDump( array( 'compression'=> 'gz' ) );
  28. foreach ( $sql_dump->tables_to_dump as $key => $table ) {
  29. if ( $wpdb->prefix != substr( $table,0 , strlen( $wpdb->prefix ) ) )
  30. unset( $sql_dump->tables_to_dump[ $key ] );
  31. }
  32. $sql_dump->execute();
  33. unset( $sql_dump );
  34. } catch ( Exception $e ) {
  35. die( $e->getMessage() );
  36. }
  37. die();
  38. }
  39. }
  40. /**
  41. * Enqueue style.
  42. *
  43. * @return void
  44. */
  45. public static function admin_print_styles() {
  46. wp_enqueue_style('backwpupgeneral');
  47. }
  48. /**
  49. * Enqueue script.
  50. *
  51. * @return void
  52. */
  53. public static function admin_print_scripts() {
  54. wp_enqueue_script( 'backwpupgeneral' );
  55. }
  56. /**
  57. * Print the markup.
  58. *
  59. * @return void
  60. */
  61. public static function page() {
  62. // get wizards
  63. $wizards = BackWPup::get_wizards();
  64. ?>
  65. <div class="wrap">
  66. <?php screen_icon(); ?>
  67. <h2><?php echo sprintf( __( '%s Dashboard', 'backwpup' ), BackWPup::get_plugin_data( 'name') ); ?></h2>
  68. <div style="float:left;width:63%;margin-right:10px;min-width:500px">
  69. <?php
  70. if ( class_exists( 'BackWPup_Features') ) { ?>
  71. <div class="backwpup-welcome">
  72. <p><?php _e('Here you can schedule backup plans with a wizard.','backwpup' ) ?><br />
  73. <?php _e('The backup files can be used to save your whole installation including <code>/wp-content/</code> and push them to an external Backup Service, if you don’t want to save the backups on the same server. With a single backup file you are able to restore an installation.','backwpup'); ?></p>
  74. <p><?php _e('First set up a job, and plan what you want to save. You can use the wizards or the normal mode. Please note: the plugin author gives no warranty for your data.','backwpup'); ?></p>
  75. </div>
  76. <?php } else {?>
  77. <div class="backwpup-welcome">
  78. <p><?php _e('Use the short links in the <b>First steps</b> box to schedule backup plans.','backwpup' ) ?><br />
  79. <?php _e('The backup files can be used to save your whole installation including <code>/wp-content/</code> and push them to an external Backup Service, if you don’t want to save the backups on the same server. With a single backup file you are able to restore an installation.','backwpup'); ?></p>
  80. <p><?php _e('First set up a job, and plan what you want to save. Please note: the plugin author gives no warranty for your data.','backwpup'); ?></p>
  81. </div>
  82. <?php }
  83. if ( class_exists( 'BackWPup_Features' ) ) {
  84. foreach ( $wizards as $wizard_class ) {
  85. //check permissions
  86. if ( ! current_user_can( $wizard_class->info[ 'cap' ] ) )
  87. continue;
  88. //get info of wizard
  89. echo '<div class="wizardbox" id="wizard-' . strtolower( $wizard_class->info[ 'ID' ] ) . '"><form method="get" action="' . network_admin_url( 'admin.php' ) . '">';
  90. echo '<div class="wizardbox_name">' . $wizard_class->info[ 'name' ] . '</div>';
  91. echo '<div class="wizardbox_description">' . $wizard_class->info[ 'description' ] . '</div>';
  92. $conf_names = $wizard_class->get_pre_configurations();
  93. if ( ! empty ( $conf_names ) ) {
  94. echo '<select id="wizardbox_pre_conf" name="pre_conf" size="1">';
  95. foreach( $conf_names as $conf_key => $conf_name) {
  96. echo '<option value="' . esc_attr( $conf_key ) . '">' . esc_attr( $conf_name ) . '</option>';
  97. }
  98. echo '</select>';
  99. } else {
  100. echo '<input type="hidden" name="pre_conf" value="" />';
  101. }
  102. wp_nonce_field( 'wizard' );
  103. echo '<input type="hidden" name="page" value="backwpupwizard" />';
  104. echo '<input type="hidden" name="wizard_start" value="' . esc_attr( $wizard_class->info[ 'ID' ] ) . '" />';
  105. echo '<div class="wizardbox_start"><input type="submit" name="submit" class="button-primary-bwp" value="' . esc_attr( __( 'Start wizard', 'backwpup' ) ) . '" /></div>';
  106. echo '</form></div>';
  107. }
  108. }
  109. ?>
  110. </div>
  111. <?php if ( current_user_can( 'backwpup_jobs_edit' ) && current_user_can( 'backwpup_logs' ) && current_user_can( 'backwpup_jobs_start' ) ) {?>
  112. <div class="metabox-holder postbox" style="padding-top:0;margin:10px;cursor:auto;width:30%;float:left;min-width:300px">
  113. <h3 class="hndle" style="cursor: auto;"><span><?php _e( 'First Steps', 'backwpup' ); ?></span></h3>
  114. <div class="inside">
  115. <ul style="margin-left: 30px;">
  116. <?php if ( class_exists( 'BackWPup_Features' ) ) { ?>
  117. <li type="1"><a href="<?php echo wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupwizard&wizard_start=SYSTEMTEST', 'wizard' ); ?>"><?php _e( 'Test the installation', 'backwpup' ); ?></a></li>
  118. <li type="1"><a href="<?php echo wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupwizard&wizard_start=JOB', 'wizard' ); ?>"><?php _e( 'Create a Job', 'backwpup' ); ?></a></li>
  119. <?php } else { ?>
  120. <li type="1"><a href="<?php echo network_admin_url( 'admin.php' ) . '?page=backwpupsettings#backwpup-tab-information'; ?>"><?php _e( 'Check the installation', 'backwpup' ); ?></a></li>
  121. <li type="1"><a href="<?php echo network_admin_url( 'admin.php' ) . '?page=backwpupeditjob'; ?>"><?php _e( 'Create a Job', 'backwpup' ); ?></a></li>
  122. <?php } ?>
  123. <li type="1"><a href="<?php echo network_admin_url( 'admin.php' ) . '?page=backwpupjobs'; ?>"><?php _e( 'Run the created job', 'backwpup' ); ?></a></li>
  124. <li type="1"><a href="<?php echo network_admin_url( 'admin.php' ) . '?page=backwpuplogs'; ?>"><?php _e( 'Check the job log', 'backwpup' ); ?></a></li>
  125. </ul>
  126. </div>
  127. </div>
  128. <?php }
  129. if ( current_user_can( 'backwpup_jobs_start' ) ) {?>
  130. <div class="metabox-holder postbox" style="padding-top:0;margin:10px;cursor:auto;width:30%;float:left;min-width:300px">
  131. <h3 class="hndle" style="cursor: auto;"><span><?php _e( 'One click backup', 'backwpup' ); ?></span></h3>
  132. <div class="inside" style="text-align: center;">
  133. <a href="<?php echo wp_nonce_url( network_admin_url( 'admin.php' ). '?page=backwpup&action=dbdumpdl', 'backwpupdbdumpdl' ); ?>" class="button-primary" title="<?php _e( 'Generate a database backup of WordPress tables and download it right away!', 'backwpup' ); ?>"><?php _e( 'Download database backup', 'backwpup' ); ?></a><br />
  134. </div>
  135. </div>
  136. <?php }
  137. self::mb_next_jobs();
  138. self::mb_last_logs();
  139. ?>
  140. </div>
  141. <?php
  142. }
  143. /**
  144. * Displaying last logs
  145. */
  146. private static function mb_last_logs() {
  147. if ( ! current_user_can( 'backwpup_logs' ) )
  148. return;
  149. ?>
  150. <table class="wp-list-table widefat" cellspacing="0" style="margin:10px;width:30%;float:left;clear:none;min-width:300px">
  151. <thead>
  152. <tr><th colspan="3" style="font-size:15px"><?php _e( 'Last logs', 'backwpup' ); ?></tr>
  153. <tr><th style="width:30%"><?php _e( 'Time', 'backwpup' ); ?></th><th style="width:55%"><?php _e( 'Job', 'backwpup' ); ?></th><th style="width:20%"><?php _e( 'Result', 'backwpup' ); ?></th></tr>
  154. </thead>
  155. <?php
  156. //get log files
  157. $logfiles = array();
  158. if ( is_writeable( BackWPup_Option::get( 'cfg', 'logfolder' ) ) && $dir = @opendir( BackWPup_Option::get( 'cfg', 'logfolder' ) ) ) {
  159. while ( ( $file = readdir( $dir ) ) !== FALSE ) {
  160. if ( is_file( BackWPup_Option::get( 'cfg', 'logfolder' ) . $file ) && strstr( $file, 'backwpup_log_' ) && ( strstr( $file, '.html' ) || strstr( $file, '.html.gz' ) ) )
  161. $logfiles[ ] = $file;
  162. }
  163. closedir( $dir );
  164. rsort( $logfiles );
  165. }
  166. if ( count( $logfiles ) > 0 ) {
  167. $count = 0;
  168. $alternate = TRUE;
  169. foreach ( $logfiles as $logfile ) {
  170. $logdata = BackWPup_Job::read_logheader( BackWPup_Option::get( 'cfg', 'logfolder' ) . $logfile );
  171. if ( ! $alternate ) {
  172. echo '<tr>';
  173. $alternate = TRUE;
  174. } else {
  175. echo '<tr class="alternate">';
  176. $alternate = FALSE;
  177. }
  178. echo '<td>' . date_i18n( get_option( 'date_format' ) , $logdata[ 'logtime' ] ). '<br />' . date_i18n( get_option( 'time_format' ), $logdata[ 'logtime' ] ) . '</td>';
  179. echo '<td><a class="thickbox" href="' . admin_url( 'admin-ajax.php' ) . '?&action=backwpup_view_log&logfile=' . basename( $logfile ) .'&_ajax_nonce=' . wp_create_nonce( 'view-logs' ) . '&height=440&width=630&TB_iframe=true" title="' . esc_attr( basename( $logfile ) ) . '">' . $logdata[ 'name' ] . '</i></a></td>';
  180. echo '<td>';
  181. if ( $logdata[ 'errors' ] > 0 )
  182. printf( '<span style="color:red;font-weight:bold;">' . _n( "%d ERROR", "%d ERRORS", $logdata[ 'errors' ], 'backwpup' ) . '</span><br />', $logdata[ 'errors' ] );
  183. if ( $logdata[ 'warnings' ] > 0 )
  184. printf( '<span style="color:#e66f00;font-weight:bold;">' . _n( "%d WARNING", "%d WARNINGS", $logdata[ 'warnings' ], 'backwpup' ) . '</span><br />', $logdata[ 'warnings' ] );
  185. if ( $logdata[ 'errors' ] == 0 && $logdata[ 'warnings' ] == 0 )
  186. echo '<span style="color:green;font-weight:bold;">' . __( 'OK', 'backwpup' ) . '</span>';
  187. echo '</td></tr>';
  188. $count ++;
  189. if ( $count >= 5 )
  190. break;
  191. }
  192. }
  193. else {
  194. echo '<tr><td colspan="3">' . __( 'none', 'backwpup' ) . '</td></tr>';
  195. }
  196. ?>
  197. </table>
  198. <?php
  199. }
  200. /**
  201. * Displaying next jobs
  202. */
  203. private static function mb_next_jobs() {
  204. if ( ! current_user_can( 'backwpup_jobs' ) )
  205. return;
  206. ?>
  207. <table class="wp-list-table widefat" cellspacing="0" style="margin:10px;width:30%;float:left;clear:none;min-width:300px">
  208. <thead>
  209. <tr><th colspan="2" style="font-size:15px"><?php _e( 'Next scheduled jobs', 'backwpup' ); ?></th></tr>
  210. <tr>
  211. <th style="width: 30%"><?php _e( 'Time', 'backwpup' ); ?></th>
  212. <th style="width: 70%"><?php _e( 'Job', 'backwpup' ); ?></th>
  213. </tr>
  214. </thead>
  215. <?php
  216. //get next jobs
  217. $job_object = BackWPup_Job::get_working_data();
  218. $mainsactive = BackWPup_Option::get_job_ids( 'activetype', 'wpcron' );
  219. sort( $mainsactive );
  220. $alternate = TRUE;
  221. // add working job if it not in active jobs
  222. if ( is_object( $job_object ) && ! empty( $job_object->job[ 'jobid' ] ) && ! in_array( $job_object->job[ 'jobid' ], $mainsactive ) )
  223. $mainsactive[ ] = $job_object->job[ 'jobid' ];
  224. foreach ( $mainsactive as $jobid ) {
  225. $name = BackWPup_Option::get( $jobid, 'name' );
  226. if ( is_object( $job_object ) && ! empty( $job_object->job[ 'jobid' ] ) && $job_object->job[ 'jobid' ] == $jobid ) {
  227. $runtime = current_time( 'timestamp' ) - $job_object->start_time;
  228. if ( ! $alternate ) {
  229. echo '<tr>';
  230. $alternate = TRUE;
  231. } else {
  232. echo '<tr class="alternate">';
  233. $alternate = FALSE;
  234. }
  235. echo '<td>' . sprintf( '<span style="color:#e66f00;">' . __( 'working since %d seconds', 'backwpup' ) . '</span>', $runtime ) . '</td>';
  236. echo '<td><span style="font-weight:bold;">' . $name . '</span><br />';
  237. echo "<a style=\"color:red;\" href=\"" . wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupjobs&action=abort', 'abort-job' ) . "\">" . __( 'Abort', 'backwpup' ) . "</a>";
  238. echo "</td></tr>";
  239. }
  240. else {
  241. if ( ! $alternate ) {
  242. echo '<tr>';
  243. $alternate = TRUE;
  244. } else {
  245. echo '<tr class="alternate">';
  246. $alternate = FALSE;
  247. }
  248. if ( $nextrun = wp_next_scheduled( 'backwpup_cron', array( 'id' => $jobid ) ) + ( get_option( 'gmt_offset' ) * 3600 ) )
  249. echo '<td>' . date_i18n( get_option( 'date_format' ), $nextrun, TRUE ) . '<br />' . date_i18n( get_option( 'time_format' ), $nextrun, TRUE ) . '</td>';
  250. else
  251. echo '<td><em>' . __( 'Not scheduled!', 'backwpup' ) . '</em></td>';
  252. echo '<td><a href="' . wp_nonce_url( network_admin_url( 'admin.php' ) . '?page=backwpupeditjob&jobid=' . $jobid, 'edit-job' ) . '" title="' . esc_attr( __( 'Edit Job', 'backwpup' ) ) . '">' . $name . '</a></td></tr>';
  253. }
  254. }
  255. if ( empty( $mainsactive ) and ! $job_object ) {
  256. echo '<tr><td colspan="2"><i>' . __( 'none', 'backwpup' ) . '</i></td></tr>';
  257. }
  258. ?>
  259. </table>
  260. <?php
  261. }
  262. }