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;
 }
	.ooyala-item .photo { margin:4px; }
	.ooyala-item .photo img { width: 256px; height:144px}
	.ooyala-item .item-title {text-align:center;}
</style>

<div class="wrap">
	<?php 
screen_icon('ooyala');
?>
	<h2>
		<?php 
esc_html_e('Ooyala Video Browser', 'ooyalavideo');
?>
	</h2>
	<?php 
$backlot = new WP_Ooyala_Backlot(get_option('ooyala'));
if (isset($_POST['submit'])) {
    $response = $backlot->update(json_encode(array('name' => sanitize_text_field($_POST['ooyala']['title']), 'embed_code' => sanitize_text_field($_POST['ooyala']['embed']), 'hosted_at' => sanitize_url($_POST['ooyala']['hosted_at']), 'description' => sanitize_text_field($_POST['ooyala']['description']))), sanitize_text_field($_POST['ooyala']['embed']));
    if (200 == wp_remote_retrieve_response_code($response)) {
        echo '<div id="message" class="updated below-h2"><p>' . esc_html__('Video updated.', 'ooyalavideo') . '</p></div>';
    } else {
        echo '<div id="message" class="error below-h2"><p>' . esc_html__('There was an error communicating with Ooyala API.', 'ooyalavideo') . '</p></div>';
    }
} elseif (!empty($_GET['edit'])) {
    $response = $backlot->query(array('where' => "embed_code='" . esc_attr($_GET['edit']) . "'"), array(), true);
} else {
    $key_word = isset($_GET['s']) ? esc_attr($_GET['s']) : '';
    $field = isset($_GET['ooyalasearchfield']) ? esc_attr($_GET['ooyalasearchfield']) : '';
    if ($key_word && $field) {
        $where = $field . "='" . $key_word . "' AND status='live'";
    } else {