Skip to content

Commit

Permalink
Merge pull request #210 from PRX/feat/208-published-draft-revisions
Browse files Browse the repository at this point in the history
#208: install Revisionary  plugin for draft preview Revisions
  • Loading branch information
brandonhundt authored May 13, 2024
2 parents e2c877a + c411fc7 commit d08ed75
Show file tree
Hide file tree
Showing 153 changed files with 45,406 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'microsoft-start/index.php',
'pwa/pwa.php',
'redirection/redirection.php',
'revisionary/revisionary.php',
'user-role-editor/user-role-editor.php',
'taxopress-pro/taxopress-pro.php',
'tw-call-to-actions/tw-call-to-actions.php',
Expand Down
81 changes: 81 additions & 0 deletions wp-content/plugins/revisionary/activation_rvy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
class RevisionaryActivation {
function __construct($args = []) {
$args = (array) $args;
if (!empty($args['import_legacy'])) {
$this->importLegacyRevisions();
}
}

function importLegacyRevisions() {
global $wpdb;

if (!get_option('revisionary_last_version') && get_site_transient('revisionary_previous_install')) {
// Trigger dismissible migration notice even if no pending or scheduled revisions currently stored
set_site_transient('_revisionary_1x_migration', true, 86400);
}

if (defined('REVISIONARY_FORCE_REIMPORT') && REVISIONARY_FORCE_REIMPORT) {
$id_csv = '';
} elseif ($imported_ids = (array) get_option('revisionary_imported_ids')) {
$id_csv = implode("','", array_map('intval', $imported_ids));
} else {
$imported_ids = [];
$id_csv = '';
}

if (!$revisions = $wpdb->get_results(
"SELECT r.post_author AS post_author, r.post_date AS rev_date, r.post_date_gmt AS rev_date_gmt,"
. " r.post_content AS post_content, r.post_title AS post_title, r.post_excerpt AS post_excerpt,"
. " r.post_status AS post_status, r.post_modified AS post_modified, r.post_modified_gmt AS post_modified_gmt,"
. " r.ID AS rev_ID, r.post_parent AS comment_count, p.post_parent AS post_parent,"
. " p.post_type AS post_type, p.post_date AS post_date, p.post_date_gmt AS post_date_gmt, p.guid AS guid,"
. " p.comment_status AS comment_status, p.ping_status AS ping_status, p.menu_order AS menu_order"
. " FROM $wpdb->posts AS r"
. " INNER JOIN $wpdb->posts AS p"
. " ON r.post_type = 'revision' AND r.post_status IN ('pending', 'future') AND r.post_parent = p.ID"
. " WHERE r.ID NOT IN('$id_csv')"
. " ORDER BY p.ID, r.ID"
)
) {
return;
}

$last_post_id = 0;

foreach($revisions as $old) {
$new = (array) $old;
unset($new['rev_date']);
unset($new['rev_date_gmt']);
unset($new['rev_ID']);

if ('future' == $old->post_status) {
$new['post_status'] = 'future-revision';
$new['post_date'] = $old->rev_date;
$new['post_date_gmt'] = $old->rev_date_gmt;
} else {
$new['post_status'] = 'pending-revision';
}

$wpdb->insert($wpdb->posts, $new);
$new_revision_id = (int)$wpdb->insert_id;

add_post_meta($new_revision_id, '_rvy_base_post_id', $new['comment_count']);
add_post_meta($new_revision_id, '_rvy_imported_revision', $old->rev_ID);

if ($new['comment_count'] != $last_post_id) { // avoid redundant update for same post
require_once(dirname(__FILE__).'/rvy_init.php');
rvy_update_post_meta($new['comment_count'], '_rvy_has_revisions', true);
$last_post_id = $new['comment_count'];
}

if (defined('REVISIONARY_DELETE_LEGACY_REVISIONS')) {
$wpdb->delete($wpdb->posts, ['ID' => $old->rev_ID]);
}

$imported_ids []= $old->rev_ID;
}

update_option('revisionary_imported_ids', $imported_ids);
}
}
200 changes: 200 additions & 0 deletions wp-content/plugins/revisionary/admin/RevisionEditSubmitMetabox.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
<?php
class RvyRevisionEditSubmitMetabox
{
/**
* Classic Editor Post Submit Metabox: HTML
*/
public static function post_submit_meta_box($post, $args = [])
{
do_action('revisionary_post_submit_meta_box');

$type_obj = get_post_type_object($post->post_type);
$post_status = $post->post_mime_type;

$post_status_obj = get_post_status_object($post_status);

$can_publish = current_user_can($type_obj->cap->publish_posts);

$_args = compact('type_obj', 'post_status_obj', 'can_publish');
$_args = array_merge($args, $_args); // in case args passed into metabox are needed within static calls in the future
?>
<div class="submitbox" id="submitpost">
<?php ob_start();

?>
<div id="minor-publishing">
<div id="minor-publishing-actions">
<div id="save-action">
<?php self::post_save_button($post, $_args); ?>
</div>
<div id="preview-action">
<?php self::post_preview_button($post, $_args); ?>
</div>
<div class="clear"></div>
</div><?php // minor-publishing-actions ?>

<div id="misc-publishing-actions">
<div class="misc-pub-section">
<?php self::post_status_display($post, $_args); ?>
</div>

<?php
if ($can_publish) : // Contributors don't get to choose the date of publish
?>
<div class="misc-pub-section curtime misc-pub-section-last">
<?php self::post_time_display($post, $_args); ?>
</div>
<?php endif; ?>

<?php do_action('post_submitbox_misc_actions', $post); ?>
</div> <?php // misc-publishing-actions ?>

<div class="clear"></div>
</div> <?php // minor-publishing ?>

<div id="major-publishing-actions">
<?php do_action('post_submitbox_start', $post); ?>

<div id="delete-action">
<?php // PP: no change from WP core
if (current_user_can("delete_post", $post->ID)) {
if (!EMPTY_TRASH_DAYS)
$delete_text = (defined('RVY_DISCARD_CAPTION')) ? esc_html__('Discard Revision', 'revisionary') : esc_html__('Delete Revision', 'revisionary');
else
$delete_text = esc_html__('Move to Trash');
?>
<a class="submitdelete deletion"
href="<?php echo esc_url(get_delete_post_link($post->ID)); ?>"><?php echo esc_html($delete_text); ?></a><?php
} ?>
</div>

<div class="clear"></div>
</div> <?php // major-publishing-actions ?>

<?php
$html = apply_filters('revisionary_submit_revision_metabox_classic', ob_get_clean(), $post);
echo $html;
?>
</div> <?php // submitpost ?>

<?php
}

/*
* Classic Editor Post Submit Metabox: Post Save Button HTML
*/
public static function post_save_button($post, $args)
{
if (!$draft_label = pp_revisions_status_label($post->post_mime_type, 'update')) {
$draft_label = pp_revisions_label('update_revision');
}
?>
<input type="submit" name="save" id="save-post" value="<?php echo esc_attr($draft_label) ?>"
tabindex="4" class="button button-highlighted"/>

<span class="spinner" style="margin:2px 2px 0"></span>
<?php
}

/**
* Classic Editor Post Submit Metabox: Post Preview Button HTML
*/
public static function post_preview_button($post, $args)
{
if (empty($args['post_status_obj'])) return;

$post_status_obj = $args['post_status_obj'];
?>
<?php
if (rvy_get_option('revision_preview_links') || current_user_can('administrator') || is_super_admin()) {
$preview_link = esc_url(get_permalink($post->ID));

$type_obj = get_post_type_object($post->post_type);

if (empty($type_obj->public)) {
return;
}

$can_publish = current_user_can('edit_post', rvy_post_id($post->ID));

if ($type_obj && empty($type_obj->public)) {
return;
} else {
$preview_button = esc_html__('Preview', 'revisionary');
$preview_title = esc_html__('Preview revision in progress', 'revisionary');
}
?>
<a class="preview button" href="<?php echo esc_url($preview_link); ?>" target="_blank" id="post-preview"
tabindex="4" title="<?php echo esc_attr($preview_title);?>"><?php echo esc_html($preview_button); ?></a>

<input type="hidden" name="wp-preview" id="wp-preview" value="">
<?php
}
}

/**
* Classic Editor Post Submit Metabox: Post Status Dropdown HTML
*/
public static function post_status_display($post, $args)
{
$defaults = ['post_status_obj' => false];
$args = array_merge($defaults, $args);
foreach (array_keys($defaults) as $var) {
$$var = $args[$var];
}

?>
<label for="post_status"><?php echo esc_html__('Status:'); ?></label>
<?php
$status_label = (!empty($post_status_obj->labels->caption)) ? $post_status_obj->labels->caption : $post_status_obj->label;
?>
<span id="post-status-display">
<?php
echo esc_html($status_label);
?>
</span>&nbsp;

<?php /* Output status select for js consistency with date select OK / Cancel */?>
<div id="post-status-select" class="hide-if-js" style="display:none">
<select name='post_status' id='post_status' tabindex='4'>
<option selected value='<?php echo esc_attr($post_status_obj->name) ?>'><?php echo esc_html($status_label) ?></option>
</select>
</div>
<?php
}

/**
* Classic Editor Post Submit Metabox: Post Time Display HTML
*/
public static function post_time_display($post, $args)
{
global $action;

if (empty($args['post_status_obj'])) return;

$post_status_obj = $args['post_status_obj'];
?>
<span id="timestamp">
<?php
// translators: Publish box date formt, see http://php.net/date
$datef = esc_html__('M j, Y @ G:i', 'revisionary');

$published_stati = get_post_stati(['public' => true, 'private' => true], 'names', 'or');

if ('future-revision' == $post_status_obj->name) { // scheduled for publishing at a future date
printf(esc_html__('Scheduled for: %s'), '<b>' . esc_html(date_i18n($datef, strtotime($post->post_date))) . '</b>'); ?></span>
<?php
} elseif (strtotime($post->post_date_gmt) > agp_time_gmt()) {
printf(esc_html__('Publish on: %s'), '<b>' . esc_html(date_i18n($datef, strtotime($post->post_date))) . '</b>'); ?></span>
<?php
} else {
printf(esc_html__('Publish %son approval%s', 'revisionary'), '<b>', '</b>'); ?></span>
<?php
}
?>

<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php echo esc_html__('Edit') ?></a>
<div id="timestampdiv" class="hide-if-js"><?php touch_time(($action == 'edit'), 1, 4); ?></div>
<?php
}
}
31 changes: 31 additions & 0 deletions wp-content/plugins/revisionary/admin/admin-dashboard_rvy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
class RevisionaryDashboard {
public function __construct() {
}

public function recentPostsQueryArgs($query_args) {
add_filter('posts_clauses_request', [&$this, 'fltDashboardQueryClauses']);
return $query_args;
}

public function fltDashboardQueryClauses( $clauses ) {
global $wpdb, $revisionary;

$types = array_keys($revisionary->enabled_post_types);
$post_types_csv = implode( "','", array_map('sanitize_key', $types));
$clauses['where'] = str_replace( "$wpdb->posts.post_type = 'post'", "$wpdb->posts.post_type IN ('$post_types_csv')", $clauses['where'] );

$clauses['where'] = str_replace( "$wpdb->posts.post_status = 'future'", "($wpdb->posts.post_status = 'future' OR ($wpdb->posts.post_status = 'pending' AND $wpdb->posts.post_mime_type = 'future-revision'))", $clauses['where'] );

$revisionary->is_revisions_query = false;

remove_filter('posts_clauses_request', [&$this, 'fltDashboardQueryClauses']);
return $clauses;
}

public static function glancePending($items = []) {
return $items;

// @todo: modify this function for post_mime_type schema
}
}
Loading

0 comments on commit d08ed75

Please sign in to comment.