/** * Retrieve a attachment * * @see WP_JSON_Posts::get_post() */ public function get_post($id, $context = 'view') { $id = (int) $id; if (empty($id)) { json_error(BigAppErr::$post['code'], BigAppErr::$comment['msg'], __lan("Invalid post id")); } $post = get_post($id, ARRAY_A); if ($post['post_type'] !== 'attachment') { json_error(BigAppErr::$post['code'], BigAppErr::$comment['msg'], __lan("Invalid post type")); } return parent::get_post($id, $context, true); //特征图给了一个特殊表示,用于返回数组 }
/** * 设置AK SK * @param ak,sk */ public function set_ak_sk($ak, $sk) { $ak = trim($ak); $sk = trim($sk); $st = false; if (strlen($ak) == 32 && strlen($sk) == 32) { $ak_sk = array('ak' => $ak, 'sk' => $sk); $st = update_option("bigapp_ak_sk", json_encode($ak_sk)); $st = true; } else { json_error(BigAppErr::$server['code'], __lan("app key/app secret format is wrong"), ""); } return $st; }
/** * Get all terms for a post type * base function * @param string $taxonomy Taxonomy slug:category,post_tag,nav_menu,link_category,post_format * @return array Term collection */ public function get_taxonomy_terms($taxonomy, $filter = array()) { if (!taxonomy_exists($taxonomy)) { json_error(BigAppErr::$taxonomy['code'], BigAppErr::$taxonomy['msg'], __lan("Invalid taxonomy ID.")); } $args = array('hide_empty' => false); // Allow args in get_terms function. This is a partial list and does not include hide_empty and cache_domain. $valid_vars = array('orderby', 'order', 'exclude', 'exclude_tree', 'include', 'number', 'fields', 'slug', 'parent', 'hierarchical', 'child_of', 'get', 'name__like', 'description__like', 'pad_counts', 'offset', 'search'); foreach ($valid_vars as $var) { if (isset($filter[$var])) { $args[$var] = apply_filters('json_tax_query_var-' . $var, $filter[$var]); } } $terms = get_terms($taxonomy, $args); if (is_wp_error($terms)) { json_error(BigAppErr::$taxonomy['code'], BigAppErr::$taxonomy['msg'], "get_term return error"); } $data = array(); foreach ($terms as $term) { $data[] = $this->prepare_taxonomy_term($term); } return $data; }
/** * Delete a post for any registered post type * * @uses wp_delete_post() * @param int $id * @return true on success */ public function delete_post($id, $force = false) { $id = (int) $id; $post = get_post($id, ARRAY_A); if (empty($id) || empty($post['ID'])) { json_error(BigAppErr::$post['code'], "post id is Invalid", $id); } if (!json_check_post_permission($post, 'delete')) { json_error(BigAppErr::$post['code'], "Sorry, you are not allowed to delete this post."); } $result = wp_delete_post($id, $force); if (!$result) { json_error(BigAppErr::$post['code'], "The post cannot be deleted."); } if ($force) { return array('message' => __('Permanently deleted post')); } else { // TODO: return a HTTP 202 here instead return array('message' => __lan('Deleted post'), 'id' => $id); } }
/** * 检测到评论过快的时候,会进入该接口 */ public static function bigapp_json_api_flood_comment($time_lastcomment = 0, $time_newcomment = 0) { $result = array("error_code" => BigAppErr::$comment['code'], "error_msg" => __('You are posting comments too quickly. Slow down.'), "data" => __lan('dup comment')); bigapp_core::set_response($result); }
protected function insert_user($data) { $user = new stdClass(); if (!empty($data['ID'])) { $existing = get_userdata($data['ID']); if (!$existing) { json_error(BigAppErr::$user['code'], BigAppErr::$user['msg'], __lan("Invalid user ID")); } if (!current_user_can('edit_user', $data['ID'])) { json_error(BigAppErr::$user['code'], BigAppErr::$user['msg'], __lan("Sorry, you are not allowed to edit users.")); } $user->ID = $existing->ID; $update = true; } else { if (!current_user_can('create_users')) { json_error(BigAppErr::$user['code'], BigAppErr::$user['msg'], __lan("Sorry, you are not allowed to create users.")); } $required = array('username', 'password', 'email'); foreach ($required as $arg) { if (empty($data[$arg])) { json_error(BigAppErr::$user['code'], BigAppErr::$user['msg'], __lan("Missing parameter {$arg}")); } } $update = false; } // Basic authentication details if (isset($data['username'])) { $user->user_login = $data['username']; } if (isset($data['password'])) { $user->user_pass = $data['password']; } // Names if (isset($data['name'])) { $user->display_name = $data['name']; } if (isset($data['first_name'])) { $user->first_name = $data['first_name']; } if (isset($data['last_name'])) { $user->last_name = $data['last_name']; } if (isset($data['nickname'])) { $user->nickname = $data['nickname']; } if (!empty($data['slug'])) { $user->user_nicename = $data['slug']; } // URL if (!empty($data['URL'])) { $escaped = esc_url_raw($user->user_url); if ($escaped !== $user->user_url) { json_error(BigAppErr::$user['code'], BigAppErr::$user['msg'], __lan("Invalid user URL.")); } $user->user_url = $data['URL']; } // Description if (!empty($data['description'])) { $user->description = $data['description']; } // Email if (!empty($data['email'])) { $user->user_email = $data['email']; } // Role if (!empty($data['role'])) { $user->role = $data['role']; } // Pre-flight check $user = apply_filters('json_pre_insert_user', $user, $data); if (is_wp_error($user)) { return $user; } $user_id = $update ? wp_update_user($user) : wp_insert_user($user); if (is_wp_error($user_id)) { return $user_id; } $user->ID = $user_id; do_action('json_insert_user', $user, $data, $update); return $user_id; }
/** * 头部的帮助菜单 */ public static function admin_help() { $current_screen = get_current_screen(); if (current_user_can('manage_options')) { $current_screen->add_help_tab(array('id' => 'account', 'title' => __lan('Account'), 'content' => '<p><strong>' . esc_html(__lan('bigapp Configuration')) . '</strong></p>')); } //帮助的侧边菜单 $current_screen->set_help_sidebar('<p><strong>' . esc_html(__lan('For more information:')) . '</strong></p>'); }
/** * Sort parameters by order specified in method declaration * * Takes a callback and a list of available params, then filters and sorts * by the parameters the method actually needs, using the Reflection API * * @param callback $callback * @param array $params * @return array */ protected function sort_callback_params($callback, $provided) { if (is_array($callback)) { $ref_func = new ReflectionMethod($callback[0], $callback[1]); } else { $ref_func = new ReflectionFunction($callback); } $wanted = $ref_func->getParameters(); $ordered_parameters = array(); foreach ($wanted as $param) { if (isset($provided[$param->getName()])) { // We have this parameters in the list to choose from $ordered_parameters[] = $provided[$param->getName()]; } elseif ($param->isDefaultValueAvailable()) { // We don't have this parameter, but it's optional $ordered_parameters[] = $param->getDefaultValue(); } else { // We don't have this parameter and it wasn't optional, abort! json_error(BigAppErr::$server['code'], BigAppErr::$server['msg'], __lan('Missing parameter:%s.', $param->getName())); } } return $ordered_parameters; }
/** * 公共的出错函数,返回json格式数据,再退出 */ function json_error($code, $msg = '', $data = '') { $result = array('error_code' => $code, 'error_msg' => __lan($msg), 'data' => $data); $req = Bigapp_Common::getInstance(); $req->setResponse($result); }
/** * 删除之前收藏的帖子 */ public function remove_favorite($post_id) { $status = true; if (empty($post_id)) { json_error(BigAppErr::$favorite['code'], BigAppErr::$favorite['msg'], __lan("post id is empty")); } if ($this->favroite_enabled == true) { wpfp_remove_favorite($post_id); } else { if ($this->_do_remove_favorite($post_id)) { // removed, now? do_action('wpfp_after_remove', $post_id); #if (wpfp_get_option('statistics')) wpfp_update_post_meta($post_id, -1); } } $response = new WP_JSON_Response(); $response->set_data($status); return $response; }
/** * 获取公告内容 */ public static function get_notice_info() { $use_api_notice = false; $notice = __lan("欢迎使用BigApp,如果您在使用过程中遇到任何问题,请随时与我们联系,我们将终身提供免费技术支持服务,<strong>QQ: 2510709749;免费电话: 4006852216;</strong><br><br>\n 请先前往<a href='http://bigapp.youzu.com' target='_blank'> BigApp应用中心 </a> 进行认证,并生成您的App!"); if ($use_api_notice == true) { $notice_info = curl_info("http://bigapp.youzu.com/mc/mcapi/getNotice"); if ($notice_info && $notice_info['error_code'] == 0) { $notice = $notice_info['data']['notice'] ? $notice_info['data']['notice'] : $notice; } } return $notice; }
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ define('YZ_BIG_APP_VERSION', '1.0.0'); define('YZ_BIG_INNER_VERSION', '6142'); define('YZ_BIG_LAST_MODIFICATION', ' 2015-10-09 15:19'); define('YZ_APP_API_VERSION', '1'); define('YZ_APP_MINIMUM_WP_VERSION', '2.0'); define('YZ_APP_API_DEBUG', true); define('YZ_APP_API_RESOURCE', false); //资源版本号 if (!function_exists('add_action')) { echo __lan('Hi there! I\'m just a plugin, not much I can do when called directly.'); exit; } if (!defined('BIGAPP_ROOT')) { define('BIGAPP_ROOT', dirname(__FILE__)); } if (!defined('BIGAPP_FOLDER')) { define('BIGAPP_FOLDER', basename(BIGAPP_ROOT)); } if (!defined('BIGAPP_URL')) { define('BIGAPP_URL', plugin_dir_url(BIGAPP_FOLDER) . BIGAPP_FOLDER . '/'); } require_once BIGAPP_ROOT . '/bigapp.class.php'; function wp_json_validate_auth_login() { add_filter('determine_current_user', 'wp_json_validate_auth_login', 0);
/** * Delete a comment. * * @uses wp_delete_comment * @param int $id Post ID * @param int $comment Comment ID * @param boolean $force Skip trash * @return array */ public function delete_comment($comment, $force = false) { $comment = (int) $comment; if (empty($comment)) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("comment id invalid")); } $comment_array = get_comment($comment, ARRAY_A); if (empty($comment_array)) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("comment id invalid")); } $user_id = get_current_user_id(); if ($user_id == 0) { //未登录用户,不能删除评论 json_error(BigAppErr::$login['code'], BigAppErr::$login['msg'], __lan("need login")); } if (!current_user_can('edit_comment', $comment_array['comment_ID']) && $user_id != $comment_array['user_id']) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("no auth to delete comment ")); } $result = wp_delete_comment($comment_array['comment_ID'], $force); if (!$result) { json_error(BigAppErr::$comment['code'], BigAppErr::$comment['msg'], __lan("delete comment failed")); } return array('message' => __('Deleted comment'), 'id' => $comment); }