2008-02-20 14:40:54 +00:00
|
|
|
<?php
|
2008-04-24 14:36:41 +00:00
|
|
|
/* __ __ _
|
|
|
|
WordPress Plugin | \/ | | |
|
|
|
|
_ __ __ _ __ _ ___| \ / | __ _ ___| |__
|
|
|
|
| '_ \ / _` |/ _` |/ _ \ |\/| |/ _` / __| '_ \
|
|
|
|
| |_) | (_| | (_| | __/ | | | (_| \__ \ | | |
|
|
|
|
| .__/ \__,_|\__, |\___|_| |_|\__,_|___/_| |_|
|
|
|
|
| | __/ | Author: Joel Starnes
|
|
|
|
|_| |___/ URL: pagemash.joelstarnes.co.uk
|
|
|
|
|
|
|
|
>>Decodes JSON data and updates database accordingly
|
|
|
|
*/
|
2008-02-20 14:40:54 +00:00
|
|
|
|
2009-02-20 21:40:28 +00:00
|
|
|
|
|
|
|
if(!$_POST['m']) die('No data.'); //die if no data is sent
|
2008-04-24 14:36:41 +00:00
|
|
|
error_reporting(E_ALL);
|
|
|
|
require_once('myjson.php'); //JSON decode lib
|
2008-09-04 19:12:35 +00:00
|
|
|
|
|
|
|
$root = dirname(dirname(dirname(dirname(__FILE__))));
|
2009-02-20 21:40:28 +00:00
|
|
|
if(file_exists($root.'/wp-load.php')) {
|
2008-09-04 19:12:35 +00:00
|
|
|
require_once($root.'/wp-load.php');
|
|
|
|
} else {
|
|
|
|
// Pre-2.6 compatibility
|
|
|
|
require_once($root.'/wp-config.php');
|
|
|
|
require_once($root.'/wp-settings.php');
|
|
|
|
}
|
2008-02-20 14:40:54 +00:00
|
|
|
|
2009-02-20 21:40:28 +00:00
|
|
|
if(!current_user_can('edit_pages')) die("You don't have the correct priviledges.");
|
|
|
|
|
2009-01-23 00:34:38 +00:00
|
|
|
global $wpdb, $excludePages, $wp_rewrite;
|
2008-03-18 13:35:49 +00:00
|
|
|
$excludePages = array();
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
// fetch JSON object from $_POST['m']
|
|
|
|
$json = new Services_JSON();
|
2009-02-20 21:40:28 +00:00
|
|
|
$data = (array) $json->decode(stripslashes($_POST['m']));
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
function saveList($parent, $children) {
|
|
|
|
global $wpdb, $excludePages;
|
|
|
|
|
|
|
|
$parent = (int) $parent;
|
|
|
|
$result = array();
|
|
|
|
$i = 1;
|
2009-02-20 21:40:28 +00:00
|
|
|
foreach($children as $k => $v) {
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
//IDs are 'JM_#' so strip first 3 characters
|
|
|
|
$id = (int) substr($children[$k]->id, 3);
|
|
|
|
|
2008-03-16 23:25:12 +00:00
|
|
|
//if it had the remove class it is now added to the excludePages array
|
2008-04-24 14:36:41 +00:00
|
|
|
if(isset($v->hide)) $excludePages[] = $id;
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
//update pages in db
|
2008-04-24 14:36:41 +00:00
|
|
|
$postquery = "UPDATE $wpdb->posts SET ";
|
|
|
|
$postquery .= "menu_order='$i', post_parent='$parent'";
|
2009-02-20 21:40:28 +00:00
|
|
|
if(isset($v->renamed)) $postquery .= ", post_title='".$wpdb->escape($v->renamed)."'";
|
2008-04-24 14:36:41 +00:00
|
|
|
$postquery .= " WHERE ID='$id'";
|
2008-02-20 14:40:54 +00:00
|
|
|
|
2009-02-20 21:40:28 +00:00
|
|
|
$wpdb->show_errors();
|
|
|
|
$wpdb->query($postquery);
|
|
|
|
echo $postquery."\n";
|
2008-05-24 08:31:26 +00:00
|
|
|
|
2009-02-20 21:40:28 +00:00
|
|
|
if(isset($v->children[0])) saveList($id, $v->children);
|
|
|
|
$i++;
|
2008-02-20 14:40:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-23 00:34:38 +00:00
|
|
|
|
|
|
|
$wp_rewrite->flush_rules();
|
|
|
|
|
2008-04-24 14:36:41 +00:00
|
|
|
echo "Update Pages: \n";
|
2009-02-20 21:40:28 +00:00
|
|
|
echo saveList(0, $data);
|
2008-04-24 14:36:41 +00:00
|
|
|
$wpdb->print_error();
|
2009-02-20 21:40:28 +00:00
|
|
|
|
|
|
|
echo "\n\nExclude Pages: \n";
|
2008-04-24 14:36:41 +00:00
|
|
|
print_r($excludePages);
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
//update excludePages option in database
|
|
|
|
update_option("exclude_pages", $excludePages, '', 'yes');
|
|
|
|
?>
|