| 1 |
<?php |
| 2 |
/** |
| 3 |
* feedwordpress.wp-admin.post-edit.functions.php |
| 4 |
* |
| 5 |
* @author radgeek |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Adds edit controls on a post |
| 10 |
* |
| 11 |
* @uses InspectPostMeta |
| 12 |
* @uses FeedWordPressDiagnostic::is_on() |
| 13 |
* @global $feedwordpress |
| 14 |
* @global $inspectPostMeta |
| 15 |
* |
| 16 |
*/ |
| 17 |
function feedwordpress_add_post_edit_controls() { |
| 18 |
global $feedwordpress; |
| 19 |
global $inspectPostMeta; |
| 20 |
|
| 21 |
// Put in Manual Editing checkbox |
| 22 |
add_action( 'add_meta_boxes', 'feedwordpress_post_add_meta_boxes', 10, 2 ); |
| 23 |
|
| 24 |
add_filter( 'user_can_richedit', array( $feedwordpress, 'user_can_richedit' ), 1000, 1); |
| 25 |
|
| 26 |
if ( FeedWordPressDiagnostic::is_on( 'syndicated_posts:static_meta_data' ) ) : |
| 27 |
$inspectPostMeta = new InspectPostMeta; |
| 28 |
endif; |
| 29 |
} /* function feedwordpress_add_post_edit_controls() */ |
| 30 |
|
| 31 |
/** |
| 32 |
* Adds meta box on this post. |
| 33 |
* |
| 34 |
* For a more detailed description of the parameters, |
| 35 |
* @see add_meta_box() |
| 36 |
* |
| 37 |
* @param string|array|WP_Screen $post_type Screen(s) where to show the meta box. |
| 38 |
* @param int $post Unused. |
| 39 |
*/ |
| 40 |
function feedwordpress_post_add_meta_boxes( $post_type, $post ) { |
| 41 |
add_meta_box( |
| 42 |
'feedwordpress-post-controls', |
| 43 |
__( 'Syndication' ), |
| 44 |
'feedwordpress_post_edit_controls', |
| 45 |
$post_type, |
| 46 |
'side', |
| 47 |
'high' |
| 48 |
); |
| 49 |
} /* function feedwordpress_post_add_meta_boxes() */ |
| 50 |
|
| 51 |
/** |
| 52 |
* Displays the post edit controls. |
| 53 |
* |
| 54 |
* @uses get_post_custom_values() |
| 55 |
* @global $post |
| 56 |
*/ |
| 57 |
function feedwordpress_post_edit_controls() { |
| 58 |
global $post; |
| 59 |
|
| 60 |
$frozen_values = get_post_custom_values( '_syndication_freeze_updates', $post->ID ); |
| 61 |
$frozen_post = ( null !== $frozen_values and count( $frozen_values ) > 0 and 'yes' == $frozen_values[0] ); |
| 62 |
|
| 63 |
if ( ! empty( $post ) and ! empty( $post->ID ) and is_syndicated( $post->ID ) ) : |
| 64 |
?> |
| 65 |
<p><?php esc_html_e( 'This is a syndicated post, which originally appeared at' ); ?> |
| 66 |
<cite><?php print esc_html( get_syndication_source( NULL, $post->ID ) ); ?></cite>. |
| 67 |
<a href="<?php print esc_html( get_syndication_permalink( $post->ID ) ); ?>"><?php esc_html_e( 'View original post' ); ?></a>.</p> |
| 68 |
|
| 69 |
<?php do_action( 'feedwordpress_post_edit_controls_pre', $post ); ?> |
| 70 |
|
| 71 |
<p><input type="hidden" name="feedwordpress_noncename" id="feedwordpress_noncename" value="<?php print esc_attr( wp_create_nonce( plugin_basename( __FILE__ ) ) ); ?>" /> |
| 72 |
<label><input type="checkbox" name="freeze_updates" value="yes" <?php if ( $frozen_post ) : ?>checked="checked"<?php endif; ?> /> <strong><?php esc_html_e( 'Manual editing.' ); ?></strong> |
| 73 |
<?php esc_html_e( 'If set, FeedWordPress will not overwrite the changes you make manually to this post, if the syndicated content is updated on the feed.' ); ?></label></p> |
| 74 |
|
| 75 |
<?php do_action( 'feedwordpress_post_edit_controls', $post ); ?> |
| 76 |
|
| 77 |
<?php |
| 78 |
else : |
| 79 |
?> |
| 80 |
<p><?php esc_html_e( 'This post was created locally at this website.' ); ?></p> |
| 81 |
<?php |
| 82 |
endif; |
| 83 |
} /* function feedwordpress_post_edit_controls() */ |
| 84 |
|
| 85 |
/** |
| 86 |
* Displays the saved post edit controls. |
| 87 |
* |
| 88 |
* @param int $post_id WordPress post ID. |
| 89 |
* |
| 90 |
* @return int|mixed|null Post ID or null if something failed. |
| 91 |
* |
| 92 |
* @global $post |
| 93 |
*/ |
| 94 |
function feedwordpress_save_post_edit_controls( $post_id ) { |
| 95 |
global $post; |
| 96 |
|
| 97 |
$noncename = FeedWordPress::post( 'feedwordpress_noncename' ); |
| 98 |
|
| 99 |
if ( is_null( $noncename ) || ! wp_verify_nonce( $noncename, plugin_basename( __FILE__ ) ) ) : |
| 100 |
return $post_id; |
| 101 |
endif; |
| 102 |
|
| 103 |
// Verify if this is an auto save routine. If it is our form has |
| 104 |
// not been submitted, so we don't want to do anything. |
| 105 |
if ( defined( 'DOING_AUTOSAVE' ) and DOING_AUTOSAVE ) : |
| 106 |
return $post_id; |
| 107 |
endif; |
| 108 |
|
| 109 |
// The data in $_POST is for applying only to the post actually |
| 110 |
// in the edit window, i.e. $post |
| 111 |
if ( $post_id != $post->ID ) : |
| 112 |
return $post_id; |
| 113 |
endif; |
| 114 |
|
| 115 |
// Check permissions |
| 116 |
$cap[0] = 'edit_post'; |
| 117 |
|
| 118 |
$post_type = FeedWordPress::post( 'post_type' ); |
| 119 |
$cap[1] = sanitize_key( 'edit_' . $post_type ); |
| 120 |
|
| 121 |
if ( |
| 122 |
! current_user_can( $cap[0], $post_id ) |
| 123 |
and ! current_user_can( $cap[1], $post_id ) |
| 124 |
) : |
| 125 |
return $post_id; |
| 126 |
endif; |
| 127 |
|
| 128 |
// OK, we're golden. Now let's save some data. |
| 129 |
$freeze_updates = FeedWordPress::post( 'freeze_updates' ); |
| 130 |
if ( ! is_null( $freeze_updates ) ) : |
| 131 |
update_post_meta( |
| 132 |
$post_id, |
| 133 |
'_syndication_freeze_updates', |
| 134 |
sanitize_meta( '_syndication_freeze_updates', $freeze_updates, 'post' ) |
| 135 |
); |
| 136 |
$ret = $freeze_updates; |
| 137 |
|
| 138 |
// If you make manual edits through the WordPress editing |
| 139 |
// UI then they should be run through normal WP formatting |
| 140 |
// filters. |
| 141 |
update_post_meta( $post_id, '_feedwordpress_formatting_filters', 'yes' ); |
| 142 |
else : |
| 143 |
delete_post_meta( $post_id, '_syndication_freeze_updates' ); |
| 144 |
$ret = NULL; |
| 145 |
endif; |
| 146 |
|
| 147 |
do_action( 'feedwordpress_save_edit_controls', $post_id ); |
| 148 |
|
| 149 |
return $ret; |
| 150 |
} /* function feedwordpress_save_edit_controls() */ |
| 151 |
|