Permalink
Browse files

Admin UI / Try to better indicate options for Trashing/Erasing a synd…

…icated post.
  • Loading branch information...
Charles Johnson
Charles Johnson committed Feb 21, 2013
1 parent 0fcb967 commit b15fdd1f99452deb38e55c6c2670e19d5aed61d8
Showing with 137 additions and 0 deletions.
  1. +57 −0 feedwordpress.php
  2. +80 −0 myphp.class.php
View
@@ -104,6 +104,7 @@
endif;
$dir = dirname(__FILE__);
+require_once("${dir}/myphp.class.php");
require_once("${dir}/admin-ui.php");
require_once("${dir}/feedwordpresssyndicationpage.class.php");
require_once("${dir}/compatability.php"); // Legacy API
@@ -224,6 +225,7 @@
add_filter('syndicated_item_content', array('SyndicatedPost', 'resolve_relative_uris'), 0, 2);
add_filter('syndicated_item_content', array('SyndicatedPost', 'sanitize_content'), 0, 2);
+ add_action('plugins_loaded', array('FeedWordPress', 'admin_api'));
else :
# Hook in the menus, which will just point to the upgrade interface
add_action('admin_menu', 'fwp_add_pages');
@@ -653,6 +655,8 @@ function syndication_comments_feed_link ($link) {
################################################################################
function fwp_add_pages () {
+ global $feedwordpress;
+
$menu_cap = FeedWordPress::menu_cap();
$settings_cap = FeedWordPress::menu_cap(/*sub=*/ true);
$syndicationMenu = FeedWordPress::path('syndication.php');
@@ -706,6 +710,9 @@ function fwp_add_pages () {
$syndicationMenu, 'FeedWordPress Diagnostics', 'Diagnostics',
$settings_cap, FeedWordPress::path('diagnostics-page.php')
);
+
+ add_filter('page_row_actions', array($feedwordpress, 'row_actions'), 10, 2);
+ add_filter('post_row_actions', array($feedwordpress, 'row_actions'), 10, 2);
} /* function fwp_add_pages () */
function fwp_check_debug () {
@@ -1207,6 +1214,28 @@ static function admin_init () {
endif;
} /* FeedWordPress::admin_init() */
+ function admin_api () {
+ // This sucks, but WordPress doesn't give us any other way to
+ // easily invoke a permanent-delete from a plugged in post
+ // actions link. So we create a magic parameter, and when this
+ // magic parameter is activated, the WordPress trashcan is
+ // temporarily de-activated.
+
+ if (MyPHP::request('fwp_post_delete')=='nuke') :
+ // Get post ID #
+ $post_id = MyPHP::request('post');
+ if (!$post_id) :
+ $post_id = MyPHP::request('post_ID');
+ endif;
+
+ // Make sure we've got the right nonce and all that.
+ check_admin_referer('delete-post_' . $post_id);
+
+ // If so, disable the trashcan.
+ define('EMPTY_TRASH_DAYS', 0);
+ endif;
+ }
+
function init () {
global $fwp_path;
@@ -1267,6 +1296,34 @@ function redirect_retired () {
endif;
}
+ function row_actions ($actions, $post) {
+ if (is_syndicated($post->ID)) :
+ $link = get_delete_post_link($post->ID, '', true);
+ $link = MyPHP::url($link, array("fwp_post_delete" => "nuke"));
+
+ $caption = 'Erase the record of this post (will be re-syndicated if it still appears on the feed).';
+ $linktext = 'Erase/Resyndicate';
+
+ $keys = array_keys($actions);
+ $links = array();
+ foreach ($keys as $key) :
+ $links[$key] = $actions[$key];
+
+ if ('trash'==$key) :
+ $links[$key] = "<a class='submitdelete' title='" . esc_attr( __( 'Move this item to the Trash (will NOT be re-syndicated)' ) ) . "' href='" . get_delete_post_link( $post->ID ) . "'>" . __( 'Trash/Don&#8217;t Resyndicate' ) . "</a>";
+
+ // Placeholder.
+ $links['delete'] = '';
+ endif;
+ endforeach;
+
+ $links['delete'] = '<a class="submitdelete" title="'.esc_attr(__($caption)).'" href="' . $link . '">' . __($linktext) . '</a>';
+
+ $actions = $links;
+ endif;
+ return $actions;
+ }
+
function dashboard_setup () {
$see_it = FeedWordPress::menu_cap();
View
@@ -0,0 +1,80 @@
+<?php
+if (!class_exists('MyPHP')) :
+ class MyPHP {
+ // For dealing with HTTP GET/POST parameters sent to us as input
+ static public function param ($key, $default = NULL, $type = 'REQUEST') {
+ $where = '_'.strtoupper($type);
+ $ret = $default;
+ if (isset($GLOBALS[$where]) and is_array($GLOBALS[$where])) :
+ if (isset($GLOBALS[$where][$key])) :
+ $ret = $GLOBALS[$where][$key];
+
+ // Magic quotes are like the stupidest
+ // thing ever.
+ if (get_magic_quotes_gpc()) :
+ $ret = self::stripslashes_deep($ret);
+ endif;
+ endif;
+ endif;
+ return $ret;
+ } /* MyPHP::param () */
+
+ static function post ($key, $default = NULL) {
+ return self::param($key, $default, 'POST');
+ } /*MyPHP::post () */
+
+ static function get ($key, $default = NULL) {
+ return self::param($key, $default, "GET");
+ } /* MyPHP::get () */
+
+ static function request ($key, $default = NULL) {
+ return self::param($key, $default, "REQUEST");
+ } /* MyPHP::request () */
+
+ static function stripslashes_deep ($value) {
+ if ( is_array($value) ) {
+ $value = array_map(array(__CLASS__, 'stripslashes_deep'), $value);
+ } elseif ( is_object($value) ) {
+ $vars = get_object_vars( $value );
+ foreach ($vars as $key=>$data) {
+ $value->{$key} = stripslashes_deep( $data );
+ }
+ } else {
+ $value = stripslashes($value);
+ }
+ return $value;
+ } /* MyPHP::stripslashes_deep () */
+
+ static function url ($url, $params = array()) {
+ $sep = '?';
+ if (strpos($url, '?') !== false) :
+ $sep = '&';
+ endif;
+ $url .= $sep . self::to_http_post($params);
+
+ return $url;
+ } /* MyPHP::url () */
+
+ /**
+ * MyPHP::to_http_post () -- convert a hash table or object into
+ * an application/x-www-form-urlencoded query string
+ */
+ static function to_http_post ($params) {
+ $getQuery = array();
+ foreach ($params as $key => $value) :
+ if (is_scalar($value)) :
+ $getQuery[] = urlencode($key) . '=' . urlencode($value);
+ else :
+ // Make some attempt to deal with array and
+ // object members. Really we should descend
+ // recursively to get the whole thing....
+ foreach ((array) $value as $k => $v) :
+ $getQuery[] = urlencode($key.'['.$k.']') . '=' . urlencode($v);
+ endforeach;
+ endif;
+ endforeach;
+ return implode("&", $getQuery);
+ } /* MyPHP::to_http_post () */
+ }
+endif;
+

0 comments on commit b15fdd1

Please sign in to comment.