示例#1
0
 /**
  * Retrieves oEmbed from url/object ID
  * @since  0.9.5
  * @param  string $url       URL to retrieve oEmbed
  * @param  int    $object_id Object ID
  * @param  array  $args      Arguments for method
  * @return string            html markup with embed or fallback
  */
 public function get_oembed($url, $object_id, $args = array())
 {
     global $wp_embed;
     $oembed_url = esc_url($url);
     self::$object_id = absint($object_id);
     $args = self::$embed_args = wp_parse_args($args, array('object_type' => 'post', 'oembed_args' => self::$embed_args, 'field_id' => false));
     // set the post_ID so oEmbed won't fail
     $wp_embed->post_ID = self::$object_id;
     // Special scenario if NOT a post object
     if (isset($args['object_type']) && $args['object_type'] != 'post') {
         // Ok, we need to hijack the oembed cache system
         self::$hijack = true;
         self::$object_type = $args['object_type'];
         // Gets ombed cache from our object's meta (vs postmeta)
         add_filter('get_post_metadata', array('cpmb_Meta_Box_ajax', 'hijack_oembed_cache_get'), 10, 3);
         // Sets ombed cache in our object's meta (vs postmeta)
         add_filter('update_post_metadata', array('cpmb_Meta_Box_ajax', 'hijack_oembed_cache_set'), 10, 4);
     }
     $embed_args = '';
     foreach ($args['oembed_args'] as $key => $val) {
         $embed_args .= " {$key}=\"{$val}\"";
     }
     // ping WordPress for an embed
     $check_embed = $wp_embed->run_shortcode('[embed' . $embed_args . ']' . $oembed_url . '[/embed]');
     // fallback that WordPress creates when no oEmbed was found
     $fallback = $wp_embed->maybe_make_link($oembed_url);
     // Send back our embed
     if ($check_embed && $check_embed != $fallback) {
         return '<div class="embed_status">' . $check_embed . '<p><a href="#" class="cpmb_remove_file_button" rel="' . $args['field_id'] . '">' . __('Remove Embed', 'cpmb') . '</a></p></div>';
     }
     // Otherwise, send back error info that no oEmbeds were found
     return '<p class="ui-state-error-text">' . sprintf(__('No oEmbed Results Found for %s. View more info at', 'cpmb'), $fallback) . ' <a href="http://codex.wordpress.org/Embeds" target="_blank">codex.wordpress.org/Embeds</a>.</p>';
 }
示例#2
0
 public static function oembed($field, $meta, $object_id, $object_type)
 {
     echo '<input class="cpmb_oembed" type="text" name="', $field['id'], '" id="', $field['id'], '" value="', '' !== $meta ? $meta : $field['std'], '" />', self::desc($field['desc'], true);
     echo '<p class="cpmb-spinner spinner" style="display:none;"><img src="' . admin_url('/images/wpspin_light.gif') . '" alt="spinner"/></p>';
     echo '<div id="', $field['id'], '_status" class="cpmb_media_status ui-helper-clearfix embed_wrap">';
     if ($meta != '') {
         echo cpmb_Meta_Box_ajax::get_oembed($meta, $object_id, array('object_type' => $object_type, 'oembed_args' => array('width' => '640'), 'field_id' => $field['id']));
     }
     echo '</div>';
 }