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
|
|
|
|
2008-04-24 14:36:41 +00:00
|
|
|
if(!$_POST['m']) die('no data'); //die if no data is sent
|
|
|
|
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__))));
|
|
|
|
if (file_exists($root.'/wp-load.php')) {
|
|
|
|
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-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();
|
|
|
|
$aMenu = (array) $json->decode(stripslashes($_POST['m']));
|
|
|
|
|
|
|
|
function saveList($parent, $children) {
|
|
|
|
global $wpdb, $excludePages;
|
|
|
|
|
|
|
|
$parent = (int) $parent;
|
|
|
|
$result = array();
|
|
|
|
$i = 1;
|
|
|
|
foreach ($children as $k => $v) {
|
|
|
|
|
|
|
|
//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'";
|
|
|
|
if (isset($v->renamed)) $postquery .= ", post_title='$v->renamed'";
|
|
|
|
$postquery .= " WHERE ID='$id'";
|
2008-02-20 14:40:54 +00:00
|
|
|
|
2008-04-24 14:36:41 +00:00
|
|
|
$wpdb->query($postquery); //$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET menu_order = %d, post_parent = %s WHERE ID = %d" ), $i, $parent, $id );
|
2008-02-20 14:40:54 +00:00
|
|
|
echo $postquery;
|
|
|
|
echo "\n";
|
2008-05-24 08:31:26 +00:00
|
|
|
|
2008-02-20 14:40:54 +00:00
|
|
|
if (isset($v->children[0])) {saveList($id, $v->children);}
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
}
|
2009-01-23 00:34:38 +00:00
|
|
|
|
|
|
|
$wp_rewrite->flush_rules();
|
|
|
|
|
2008-04-24 14:36:41 +00:00
|
|
|
echo "Update Pages: \n";
|
2008-02-20 14:40:54 +00:00
|
|
|
echo saveList(0, $aMenu);
|
2008-04-24 14:36:41 +00:00
|
|
|
$wpdb->print_error();
|
|
|
|
echo "\n \nExclude Pages: \n";
|
|
|
|
print_r($excludePages);
|
2008-02-20 14:40:54 +00:00
|
|
|
|
|
|
|
//update excludePages option in database
|
|
|
|
update_option("exclude_pages", $excludePages, '', 'yes');
|
|
|
|
?>
|