Skip to content

Commit

Permalink
improved media integration with WP core
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed May 13, 2020
1 parent e13ace9 commit 8072a5b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 48 deletions.
2 changes: 1 addition & 1 deletion HAXService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function loadBaseAppStore($apikeys = array()) {
$jsonstring = '{
"details": {
"title": "Youtube",
"icon": "av:play-arrow",
"icon": "mdi-action:youtube-play",
"color": "red",
"author": "Google, Youtube LLC",
"description": "The most popular online video sharing and remix site.",
Expand Down
86 changes: 39 additions & 47 deletions haxtheweb.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
/**
* @package haxtheweb
* @version 3.9.0
* @version 3.9.1
*/
/*
Plugin Name: haxtheweb
Plugin URI: https://github.com/elmsln/wp-plugin-hax
Description: An ecosystem agnostic web editor to democratise the web and liberate users of platforms.
Author: Bryan Ollendyke
Version: 3.9.0
Version: 3.9.1
Author URI: https://haxtheweb.org/
*/

Expand Down Expand Up @@ -46,11 +46,15 @@ function haxtheweb_wordpress($hook) {
wp_register_style('haxtheweb_stylesheet', plugins_url('css/haxtheweb.css', __FILE__));
wp_enqueue_style( 'haxtheweb_stylesheet' );
}
if ($hook == 'upload.php') {
global $haxthewebUploadPage;
$haxthewebUploadPage = true;
}
}
add_action( 'admin_enqueue_scripts', 'haxtheweb_wordpress' );

// Wire up web components to WordPress
function haxtheweb_wordpress_connector() {
function haxtheweb_wordpress_connector($hook) {
$data = array(
'url' => get_site_url(null, '/wp-json/haxtheweb/v1/appstore.json?token=' . haxtheweb_generate_secure_key('haxTheWeb')),
);
Expand Down Expand Up @@ -562,7 +566,7 @@ function _HAXTHEWEB_site_connection() {
"operations": {
"browse": {
"method": "GET",
"endPoint": "wp-json/haxtheweb/v1/search-files.json?token=' . haxtheweb_generate_secure_key('haxTheWeb') . '",
"endPoint": "wp-json/wp/v2/media",
"pagination": {
"style": "link",
"props": {
Expand All @@ -573,23 +577,29 @@ function _HAXTHEWEB_site_connection() {
}
},
"search": {
"search": {
"title": "Search",
"type": "string"
}
},
"data": {
"per_page": 20
},
"resultMap": {
"defaultGizmoType": "image",
"items": "list",
"preview": {
"title": "name",
"details": "mime",
"image": "url",
"id": "uuid"
"title": "title.rendered",
"details": "caption.rendered",
"image": "media_details.sizes.thumbnail.source_url",
"id": "slug"
},
"gizmo": {
"source": "url",
"id": "uuid",
"title": "name",
"type": "type"
"source": "source_url",
"id": "slug",
"title": "title.rendered",
"caption": "caption.rendered",
"alt": "alt_text",
"mimetype": "mime_type"
}
}
},
Expand All @@ -610,7 +620,8 @@ function _HAXTHEWEB_site_connection() {
"defaultGizmoType": "image",
"gizmo": {
"source": "url",
"id": "uuid"
"id": "uuid",
"mimetype": "type"
}
}
}
Expand All @@ -620,42 +631,23 @@ function _HAXTHEWEB_site_connection() {
return $json;
}

add_action( 'rest_api_init', function () {
register_rest_route( 'haxtheweb/v1', '/search-files.json', array(
'methods' => 'GET',
'callback' => 'haxtheweb_search_files',
) );
} );

function haxtheweb_search_files(WP_REST_Request $request) {
// You can access parameters via direct array access on the object:
$token = $request->get_param( 'token' );
if ($token == haxtheweb_generate_secure_key('haxTheWeb')) {
// @todo return a list of media assets
$return = array();
// Create the response object
$response = new WP_REST_Response( $return );
$response->set_status( 200 );
// send back happy headers
$response->header( 'Content-Type', 'application/json' );
// output the response as json
return $response;
}
}

// Wire up web components to WordPress
function haxtheweb_deps() {
$location = get_option( 'haxtheweb_location', WP_HAXTHEWEB_WEBCOMPONENTS_LOCATION );
if ($location == 'other') {
$location = get_option( 'haxtheweb_location_other', '' );
}
$buildLocation = $location;
// support for build file to come local but assets via CDN
if (get_option('haxtheweb_local_build_file', false)) {
$buildLocation = get_site_url(null, '/wp-content/haxtheweb/');
// stupid hack to ensure that we don't screw up the upload.php page
global $haxthewebUploadPage;
if (!$haxthewebUploadPage) {
$location = get_option( 'haxtheweb_location', WP_HAXTHEWEB_WEBCOMPONENTS_LOCATION );
if ($location == 'other') {
$location = get_option( 'haxtheweb_location_other', '' );
}
$buildLocation = $location;
// support for build file to come local but assets via CDN
if (get_option('haxtheweb_local_build_file', false)) {
$buildLocation = get_site_url(null, '/wp-content/haxtheweb/');
}
$wc = new WebComponentsService();
print $wc->applyWebcomponents($buildLocation, $location);
}
$wc = new WebComponentsService();
print $wc->applyWebcomponents($buildLocation, $location);
}
// front end paths
add_action( 'wp_footer', 'haxtheweb_deps' );
Expand Down

0 comments on commit 8072a5b

Please sign in to comment.