| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
class WINP_RevisionsMetaBox extends WINP_MetaBox { |
| 9 |
|
| 10 |
/** |
| 11 |
* A visible title of the metabox. |
| 12 |
* |
| 13 |
* Inherited from the class FactoryMetabox. |
| 14 |
* @link http://codex.wordpress.org/Function_Reference/add_meta_box |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
* @var string |
| 18 |
*/ |
| 19 |
public $title; |
| 20 |
|
| 21 |
/** |
| 22 |
* The part of the page where the edit screen |
| 23 |
* section should be shown ('normal', 'advanced', or 'side'). |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
public $context = 'normal'; |
| 29 |
|
| 30 |
/** |
| 31 |
* The priority within the context where the boxes should show ('high', 'core', 'default' or 'low'). |
| 32 |
* |
| 33 |
* @link http://codex.wordpress.org/Function_Reference/add_meta_box |
| 34 |
* Inherited from the class FactoryMetabox. |
| 35 |
* |
| 36 |
* @since 1.0.0 |
| 37 |
* @var string |
| 38 |
*/ |
| 39 |
public $priority = 'core'; |
| 40 |
|
| 41 |
public $css_class = 'factory-bootstrap-423 factory-fontawesome-000'; |
| 42 |
|
| 43 |
public function __construct( $plugin ) { |
| 44 |
parent::__construct( $plugin ); |
| 45 |
|
| 46 |
$this->title = __( 'Code Revisions', 'insert-php' ) . ' (PRO)'; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Configures a metabox. |
| 51 |
* |
| 52 |
* @since 1.0.0 |
| 53 |
* |
| 54 |
* @param Wbcr_Factory422_ScriptList $scripts A set of scripts to include. |
| 55 |
* @param Wbcr_Factory422_StyleList $styles A set of style to include. |
| 56 |
* |
| 57 |
* @return void |
| 58 |
*/ |
| 59 |
public function configure( $scripts, $styles ) { |
| 60 |
$styles->add( WINP_PLUGIN_URL . '/admin/assets/css/revisions.css' ); |
| 61 |
} |
| 62 |
|
| 63 |
public function html() { |
| 64 |
global $post; |
| 65 |
|
| 66 |
$snippet_id = (int) $post->ID; |
| 67 |
if ( 0 === $snippet_id ) { |
| 68 |
wp_die( __( 'Access denied', 'insert-php' ) ); |
| 69 |
} |
| 70 |
$snippet = get_post( $snippet_id ); |
| 71 |
$revisions = array( |
| 72 |
array( |
| 73 |
'ID' => 1, |
| 74 |
'time' => time() + 2 * DAY_IN_SECONDS + 100, |
| 75 |
), |
| 76 |
array( |
| 77 |
'ID' => 2, |
| 78 |
'time' => time() + DAY_IN_SECONDS + HOUR_IN_SECONDS + 50, |
| 79 |
), |
| 80 |
array( |
| 81 |
'ID' => 3, |
| 82 |
'time' => time(), |
| 83 |
), |
| 84 |
); |
| 85 |
|
| 86 |
$this->renderMetabox( $snippet, $revisions ); |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* @param $snippet WP_Post |
| 91 |
* @param $revisions WP_Post[] |
| 92 |
*/ |
| 93 |
public function renderMetabox( $snippet, $revisions ) { |
| 94 |
?> |
| 95 |
<table class="wp-list-table widefat fixed striped snippet-revisions"> |
| 96 |
<thead> |
| 97 |
<tr> |
| 98 |
<th><?php _e( "Compare", "insert-php" ); ?></th> |
| 99 |
<th><?php _e( "Revision", "insert-php" ); ?></th> |
| 100 |
<th><?php _e( "Author", "insert-php" ); ?></th> |
| 101 |
<th><?php _e( "Delete", "insert-php" ); ?></th> |
| 102 |
<th><?php _e( "Restore", "insert-php" ); ?></th> |
| 103 |
</tr> |
| 104 |
</thead> |
| 105 |
<tbody> |
| 106 |
<?php |
| 107 |
foreach ( $revisions as $revision ): |
| 108 |
?> |
| 109 |
<tr> |
| 110 |
<td> |
| 111 |
<input class="winp_rev_radio_from" type="radio" name="winp_rev_from" |
| 112 |
value="<?php echo $revision['ID']; ?>" |
| 113 |
data-panel="from"> |
| 114 |
<input class="winp_rev_radio_to" type="radio" name="winp_rev_to" |
| 115 |
value="<?php echo $revision['ID']; ?>" |
| 116 |
data-panel="to"> |
| 117 |
</td> |
| 118 |
<td><?php echo date_i18n( __( 'M j, Y @ H:i' ), $revision['time'] ); ?></td> |
| 119 |
<td><?php echo wp_get_current_user()->user_login; ?></td> |
| 120 |
<th><input type="checkbox" name="winp_rev_delete_mark" |
| 121 |
value="<?php echo $revision['ID']; ?>"></th> |
| 122 |
<th> |
| 123 |
<a href="<?php echo admin_url( 'post.php?post=' . $snippet->ID . '&action=edit#' ); ?>"> |
| 124 |
<?php _e( 'Restore', 'insert-php' ); ?> |
| 125 |
</a> |
| 126 |
</th> |
| 127 |
</tr> |
| 128 |
<?php |
| 129 |
endforeach; |
| 130 |
?> |
| 131 |
</tbody> |
| 132 |
</table> |
| 133 |
<?php WINP_Helper::get_purchase_button() ?> |
| 134 |
<div class="revisions-actionbar"> |
| 135 |
<button type="button" |
| 136 |
class="button action winp_rev_compare"><?php _e( 'Compare', 'insert-php' ); ?></button> |
| 137 |
<button type="button" |
| 138 |
class="button action winp_rev_delete"><?php _e( 'Delete', 'insert-php' ); ?></button> |
| 139 |
</div> |
| 140 |
<?php |
| 141 |
} |
| 142 |
} |
| 143 |
|