예제 #1
0
 /**
  * Retrieve posts.
  *
  * @since 3.4.0
  *
  * The optional $filter parameter modifies the query used to retrieve posts.
  * Accepted keys are 'post_type', 'post_status', 'number', 'offset',
  * 'orderby', and 'order'.
  *
  * @uses wp_get_recent_posts()
  * @see get_posts() for more on $filter values
  *
  * @param array $filter Parameters to pass through to `WP_Query`
  * @param string $context The context; 'view' (default) or 'edit'.
  * @param string|array $type Post type slug, or array of slugs
  * @param int $page Page number (1-indexed)
  * @return stdClass[] Collection of Post entities
  */
 public function get_posts($filter = array(), $context = 'view', $type = 'post', $page = 1, $limit = 3)
 {
     $query = array();
     error_log("filters " . serialize($filter));
     $refguid = $filter[refguid];
     $optr = $filter[optr];
     if ($refguid == 'none') {
         $refguid = '0';
     }
     $taxonomy = $filter[taxonomy];
     $tagid = $filter[tagid];
     error_log("limit " . $limit);
     // Validate post types and permissions
     $query['post_type'] = array();
     foreach ((array) $type as $type_name) {
         $post_type = get_post_type_object($type_name);
         if (!(bool) $post_type || !$post_type->show_in_json) {
             return new WP_Error('json_invalid_post_type', sprintf(__('The post type "%s" is not valid'), $type_name), array('status' => 403));
         }
         $query['post_type'][] = $post_type->name;
     }
     global $wp, $wpdb;
     $my_select_q = "SELECT * FROM {$wpdb->posts}";
     $my_where_q = " WHERE  {$wpdb->posts}.post_type = '" . $type . "'";
     if ($tagid != 'all') {
         //$category = get_term_by('name', 'elgg', $taxonomy);
         $my_select_q .= " INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id) INNER JOIN {$wpdb->term_taxonomy} ON ({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id) ";
         $my_where_q .= " AND {$wpdb->term_taxonomy}.taxonomy = '" . $taxonomy . "'";
         //$tag_ids = "(".explode(",",$tagid).")";
         //$term_ids = "('3', '13')";
         //if term has childrens then try to include them too. get_term_children( $cata, $taxonomy );
         // $my_where_q .= "' AND $wpdb->term_taxonomy.term_id IN $tag_ids";
         $my_where_q .= " AND {$wpdb->term_taxonomy}.term_id = {$tagid}";
     }
     /*
                 get rid of icon time from client side
     */
     if ($refguid != 0 and $optr != 'lt') {
         $return['sync'] = $this->Sync_post($my_select_q, $my_where_q, $refguid, $limit);
     }
     if ($optr == 'gt' or $optr == 'lt') {
         $result[$optr] = $this->Retrieve_post($optr, $my_select_q, $my_where_q, $refguid, $limit);
     }
     $return = array('status' => '0', 'result' => $result);
     $response = new ENGAP_Response();
     $response->set_data($return);
     return $response;
 }
예제 #2
0
파일: plugin.php 프로젝트: enraiser/engap
/**
 * Handle OPTIONS requests for the server
 *
 * This is handled outside of the server code, as it doesn't obey normal route
 * mapping.
 *
 * @param mixed $response Current response, either response or `null` to indicate pass-through
 * @param ENGAP_Server $handler ResponseHandler instance (usually ENGAP_Server)
 * @return ENGAP_ResponseHandler Modified response, either response or `null` to indicate pass-through
 */
function json_handle_options_request($response, $handler)
{
    if (!empty($response) || $handler->method !== 'OPTIONS') {
        return $response;
    }
    $response = new ENGAP_Response();
    $accept = array();
    $handler_class = get_class($handler);
    $class_vars = get_class_vars($handler_class);
    $map = $class_vars['method_map'];
    foreach ($handler->get_routes() as $route => $endpoints) {
        $match = preg_match('@^' . $route . '$@i', $handler->path, $args);
        if (!$match) {
            continue;
        }
        foreach ($endpoints as $endpoint) {
            foreach ($map as $type => $bitmask) {
                if ($endpoint[1] & $bitmask) {
                    $accept[] = $type;
                }
            }
        }
        break;
    }
    $accept = array_unique($accept);
    $response->header('Accept', implode(', ', $accept));
    return $response;
}
예제 #3
0
 /**
  * Create a new user.
  *
  * @param $data
  * @return mixed
  */
 public function create_user($data)
 {
     if (!current_user_can('create_users')) {
         return new WP_Error('json_cannot_create', __('Sorry, you are not allowed to create users.'), array('status' => 403));
     }
     if (!empty($data['ID'])) {
         return new WP_Error('json_user_exists', __('Cannot create existing user.'), array('status' => 400));
     }
     $user_id = $this->insert_user($data);
     if (is_wp_error($user_id)) {
         return $user_id;
     }
     $response = $this->get_user($user_id);
     if (!$response instanceof ENGAP_ResponseInterface) {
         $response = new ENGAP_Response($response);
     }
     $response->set_status(201);
     $response->header('Location', json_url('/users/' . $user_id));
     return $response;
 }