Skip to content

Instantly share code, notes, and snippets.

@pepegar
Created August 22, 2013 09:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepegar/6304801 to your computer and use it in GitHub Desktop.
Save pepegar/6304801 to your computer and use it in GitHub Desktop.
This is a plugin for WordPress that extends the Media Explorer plugin with a new service. You may want to use it as a template
<?php
/*
Plugin Name: new service
Plugin URI: garhdez.com
Description: new service
Author: Pepe
*/
class MEXP_New_Template extends MEXP_Template {
/**
* Template for single elements returned from the API
*
* @param string $id the id of the view
* @param string $tab the tab were the user is right now
*/
public function item( $id, $tab ) {
?>
<div id="mexp-item-<?php echo esc_attr( $tab ); ?>-{{ data.id }}" class="mexp-item-area mexp-item" data-id="{{ data.id }}">
<div class="mexp-item-container clearfix">
<div class="mexp-item-thumb">
<img src="{{ data.thumbnail }}">
</div>
<div class="mexp-item-main">
<div class="mexp-item-content">
{{ data.content }}
</div>
<div class="mexp-item-channel">
<?php _e( 'by', 'mexp' ) ?> {{ data.meta.user }}
</div>
<div class="mexp-item-date">
{{ data.date }}
</div>
</div>
</div>
</div>
<a href="#" id="mexp-check-{{ data.id }}" data-id="{{ data.id }}" class="check" title="<?php esc_attr_e( 'Deselect', 'mexp' ); ?>">
<div class="media-modal-icon"></div>
</a>
<?php
}
public function thumbnail( $id ) {
?>
<?php
}
/**
* Template for the search form
*
* @param string $id the id of the view
* @param string $tab the tab were the user is right now
*/
public function search( $id, $tab ) {
?>
<form action="#" class="mexp-toolbar-container clearfix tab-all">
<input
type="text"
name="q"
value="{{ data.params.q }}"
class="mexp-input-text mexp-input-search"
size="40"
>
<input class="button button-large" type="submit" value="<?php esc_attr_e( 'Search', 'mexp') ?>">
<div class="spinner"></div>
</form>
<?php
}
}
class MEXP_New_Service extends MEXP_Service {
const DEFAULT_MAX_RESULTS = 18;
public function __construct() {
$this->set_template( new MEXP_New_Template );
}
public function load() {
}
public function request( array $request ) {
// Create the response for the API
$response = new MEXP_Response();
$item = new MEXP_Response_Item();
$item->set_url( esc_url( "http://www.youtube.com/watch?v=%s" ) );
$item->set_id( 4 );
$item->set_content( "This is a test" );
$item->set_thumbnail( "google.com/logo.png" );
$item->set_date( strtotime( '30-10-1990' ) );
$item->set_date_format( 'g:i A - j M y' );
$response->add_item($item);
return $response;
}
public function tabs() {
return array(
'all' => array(
'text' => _x( 'All', 'Tab title', 'mexp'),
'defaultTab' => true
),
);
}
public function labels() {
return array(
'title' => __( 'Insert New', 'mexp' ),
'insert' => __( 'Insert', 'mexp' ),
'noresults' => __( 'No videos matched your search query.', 'mexp' ),
);
}
}
add_filter( 'mexp_services', 'mexp_service_new' );
function mexp_service_new( array $services ) {
$services['new'] = new MEXP_New_Service;
return $services;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment