| 1 |
<?php |
| 2 |
|
| 3 |
class Mmb_Category extends Mmb_Core |
| 4 |
{ |
| 5 |
function __construct() |
| 6 |
{ |
| 7 |
parent::__construct(); |
| 8 |
} |
| 9 |
|
| 10 |
/************************************************************* |
| 11 |
* FACADE functions |
| 12 |
* (functions to be called after a remote XMLRPC from Master) |
| 13 |
**************************************************************/ |
| 14 |
/** |
| 15 |
* Gets a list of local (slave) category |
| 16 |
* |
| 17 |
* @param mixed $args |
| 18 |
* @return mixed |
| 19 |
*/ |
| 20 |
function get_list($args) |
| 21 |
{ |
| 22 |
$this->_escape($args); |
| 23 |
$username = $args[0]; |
| 24 |
$password = $args[1]; |
| 25 |
$offset = $args[2]; |
| 26 |
$per_page = $args[3]; |
| 27 |
|
| 28 |
if (!$user = $this->login($username, $password)) |
| 29 |
{ |
| 30 |
return $this->error; |
| 31 |
} |
| 32 |
|
| 33 |
$count = count(get_categories(array('hide_empty' => FALSE))); |
| 34 |
$categories= get_categories(array( |
| 35 |
'offset' => $offset, |
| 36 |
'number' => $per_page, |
| 37 |
'hide_empty' => FALSE |
| 38 |
)); |
| 39 |
|
| 40 |
$cat_dropdown = wp_dropdown_categories(array('echo' => false, 'hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'category_parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); |
| 41 |
|
| 42 |
if(!current_user_can('manage_categories')) |
| 43 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 44 |
|
| 45 |
return array('categories' => $categories, 'count' => $count,'dropdown' => $cat_dropdown); |
| 46 |
|
| 47 |
//return get_categories(array('hide_empty' => FALSE)); |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Updates a category locally |
| 52 |
* |
| 53 |
* @param mixed $args |
| 54 |
*/ |
| 55 |
function update($args) |
| 56 |
{ |
| 57 |
$this->_escape($args); |
| 58 |
$username = $args[0]; |
| 59 |
$password = $args[1]; |
| 60 |
$id = $args[2]; |
| 61 |
$name = $args[3]; |
| 62 |
$slug = $args[4]; |
| 63 |
$description = $args[5]; |
| 64 |
$parent = $args[6]; |
| 65 |
|
| 66 |
if (!$user = $this->login($username, $password)) |
| 67 |
{ |
| 68 |
return $this->error; |
| 69 |
} |
| 70 |
|
| 71 |
if(!current_user_can('manage_categories')) |
| 72 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 73 |
|
| 74 |
$is_success = wp_update_category(array( |
| 75 |
'cat_ID' => $id, |
| 76 |
'category_description' => $description, |
| 77 |
'cat_name' => $name, |
| 78 |
'category_nicename' => $slug, |
| 79 |
'category_parent' => $parent, |
| 80 |
)); |
| 81 |
|
| 82 |
if(!$is_success) |
| 83 |
return new IXR_Error(401, 'Error Updating Category. Try Again !!!'); |
| 84 |
else |
| 85 |
return TRUE; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Adds a new category locally |
| 90 |
* |
| 91 |
* @param mixed $args |
| 92 |
*/ |
| 93 |
function add($args) |
| 94 |
{ |
| 95 |
$this->_escape($args); |
| 96 |
$username = $args[0]; |
| 97 |
$password = $args[1]; |
| 98 |
$params = $args[2]; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
if (!$user = $this->login($username, $password)) |
| 103 |
{ |
| 104 |
return $this->error; |
| 105 |
} |
| 106 |
|
| 107 |
if(!current_user_can('manage_categories')) |
| 108 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 109 |
|
| 110 |
// wordpress' category adding function |
| 111 |
if ($cat_id = wp_insert_category($params)) |
| 112 |
{ |
| 113 |
return get_category($cat_id, ARRAY_A); |
| 114 |
} |
| 115 |
|
| 116 |
return FALSE; |
| 117 |
} |
| 118 |
} |
| 119 |
|