| 1 |
<?php |
| 2 |
|
| 3 |
class Mmb_Tags 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 |
if(!current_user_can('manage_categories')) |
| 34 |
return new IXR_Error(401, 'Sorry, you cannot manage Tags on the remote blog.'); |
| 35 |
global $wpdb; |
| 36 |
|
| 37 |
$count = count(get_tags(array('hide_empty' => FALSE))); |
| 38 |
$tags = get_tags(array( |
| 39 |
'offset' => $offset, |
| 40 |
'number' => $per_page, |
| 41 |
'hide_empty' => FALSE |
| 42 |
)); |
| 43 |
return array('tags' => $tags, 'count' => $count); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Updates a category locally |
| 48 |
* |
| 49 |
* @param mixed $args |
| 50 |
*/ |
| 51 |
function update($args) |
| 52 |
{ |
| 53 |
$this->_escape($args); |
| 54 |
$username = $args[0]; |
| 55 |
$password = $args[1]; |
| 56 |
$id = $args[2]; |
| 57 |
$name = $args[3]; |
| 58 |
$slug = $args[4]; |
| 59 |
$description = $args[5]; |
| 60 |
$taxonomy = $args[6]; |
| 61 |
|
| 62 |
if (!$user = $this->login($username, $password)) |
| 63 |
{ |
| 64 |
return $this->error; |
| 65 |
} |
| 66 |
|
| 67 |
if(!current_user_can('manage_categories')) |
| 68 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 69 |
|
| 70 |
if(empty($slug)) |
| 71 |
return new IXR_Error(401, 'Sorry, Slug cannot be Empty.'); |
| 72 |
|
| 73 |
|
| 74 |
$taxonomy = !empty($taxonomy) ? $taxonomy : 'post_tag'; |
| 75 |
$tag = get_term( $id, $taxonomy ); |
| 76 |
$args = array('name' => $name,'slug'=> $slug,'description' => $description); |
| 77 |
$is_success = wp_update_term($id, $taxonomy, $args); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
if($is_success && !is_wp_error($is_success)) |
| 83 |
return TRUE; |
| 84 |
else |
| 85 |
return new IXR_Error(401, 'Error Updating Tags. Try Again !!!'); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Adds a new category locally |
| 91 |
* |
| 92 |
* @param mixed $args |
| 93 |
*/ |
| 94 |
function add($args) |
| 95 |
{ |
| 96 |
$this->_escape($args); |
| 97 |
$username = $args[0]; |
| 98 |
$password = $args[1]; |
| 99 |
$tag_name = $args[2]; |
| 100 |
$tag_slug = $args[3]; |
| 101 |
$tag_desc = $args[4]; |
| 102 |
|
| 103 |
if (!$user = $this->login($username, $password)) |
| 104 |
{ |
| 105 |
return $this->error; |
| 106 |
} |
| 107 |
|
| 108 |
if(!current_user_can('manage_categories')) |
| 109 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 110 |
|
| 111 |
// wordpress' category adding function |
| 112 |
|
| 113 |
$params = array('tag-name' => $tag_name, |
| 114 |
'slug' => $tag_slug, |
| 115 |
'description' => $tag_desc |
| 116 |
); |
| 117 |
|
| 118 |
|
| 119 |
//$result = wp_create_tag($params); |
| 120 |
|
| 121 |
$result = wp_insert_term($tag_name, 'post_tag', $params); |
| 122 |
|
| 123 |
$term = get_terms('post_tag', array('include' => $result['term_id'], 'hide_empty'=>FALSE)); |
| 124 |
if($result && !is_wp_error($is_success)) |
| 125 |
return $term; |
| 126 |
else |
| 127 |
return new IXR_Error(401, 'Error Creating Tags. Try Again !!!'); |
| 128 |
// if ($tag_id = wp_create_term($params)) |
| 129 |
// { |
| 130 |
// return get_terms(); |
| 131 |
// } |
| 132 |
// |
| 133 |
// return FALSE; |
| 134 |
} |
| 135 |
|
| 136 |
function delete($args){ |
| 137 |
$this->_escape($args); |
| 138 |
$username = $args[0]; |
| 139 |
$password = $args[1]; |
| 140 |
$term = $args[2]; |
| 141 |
$taxonomy = $args[3]; |
| 142 |
|
| 143 |
if (!$user = $this->login($username, $password)) |
| 144 |
{ |
| 145 |
return $this->error; |
| 146 |
} |
| 147 |
if(!current_user_can('manage_categories')) |
| 148 |
return new IXR_Error(401, 'Sorry, you cannot manage categories on the remote blog.'); |
| 149 |
|
| 150 |
$taxonomy = !empty($taxonomy) ? $taxonomy : 'post_tag'; |
| 151 |
|
| 152 |
$is_success = wp_delete_term($term, $taxonomy); |
| 153 |
|
| 154 |
if($is_success && !is_wp_error($is_success)) |
| 155 |
return TRUE; |
| 156 |
else |
| 157 |
return new IXR_Error(401, 'Error Deleting Tags. Try Again !!!'); |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
} |
| 162 |
} |
| 163 |
|