WP_Ooyala_Backlot::query PHP Method

query() public method

public query ( $params, $request = [], $return = false )
    public function query($params, $request = array(), $return = false)
    {
        $default_request = array('method' => 'GET', 'path' => '/v2/assets');
        $default_params = array('api_key' => $this->api_key, 'expires' => time() + 900, 'where' => "status='live'", 'limit' => 8, 'orderby' => 'created_at descending');
        $params = wp_parse_args($params, $default_params);
        $request = wp_parse_args($request, $default_request);
        $params['signature'] = $this->sign_request($request, $params);
        foreach ($params as &$param) {
            $param = rawurlencode($param);
        }
        $url = add_query_arg($params, 'https://api.ooyala.com' . $request['path']);
        $response = wp_remote_get($url, array('timeout' => apply_filters('ooyala_http_request_timeout', 10)));
        if ($return) {
            return $response;
        }
        if (200 == wp_remote_retrieve_response_code($response)) {
            $this->render_popup(wp_remote_retrieve_body($response));
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Ajax callback that handles the request to Ooyala API from the Ooyala popup
  *
  * @uses OoyalaBacklotAPI::query() to run the queries
  * @uses OoyalaBacklotAPI::print_results() to output the results
  */
 function ooyala_request()
 {
     global $_wp_additional_image_sizes;
     if (!isset($_GET['ooyala'])) {
         die('-1');
     }
     $do = $_GET['ooyala'];
     $limit = Ooyala_Video::VIDEOS_PER_PAGE;
     $key_word = isset($_GET['key_word']) ? esc_attr($_GET['key_word']) : '';
     $field = isset($_GET['search_field']) ? esc_attr($_GET['search_field']) : 'description';
     $pageid = isset($_GET['pageid']) ? $_GET['pageid'] : '';
     $backlot = new WP_Ooyala_Backlot(get_option('ooyala'));
     switch ($do) {
         case 'search':
             if (!empty($pageid) && '' != $key_word) {
                 $backlot->query(array('where' => $field . "='" . $key_word . "' AND status='live'", 'orderby' => 'created_at descending', 'limit' => $limit, 'page_token' => absint($pageid)));
             } else {
                 if ('' != $key_word) {
                     $backlot->query(array('where' => $field . "='" . $key_word . "' AND status='live'", 'orderby' => 'created_at descending', 'limit' => $limit));
                 } else {
                     echo 'Please enter a search term!';
                     die;
                 }
             }
             break;
         case 'last_few':
             if (!empty($pageid)) {
                 $backlot->query(array('where' => "status='live'", 'orderby' => 'created_at descending', 'limit' => $limit, 'page_token' => absint($pageid)));
             } else {
                 $backlot->query(array('where' => "status='live'", 'orderby' => 'created_at descending', 'limit' => $limit));
             }
             break;
     }
     die;
 }
All Usage Examples Of WP_Ooyala_Backlot::query