-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelevatorasset.php
154 lines (118 loc) · 5.01 KB
/
elevatorasset.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
*
* @package elevatorasset
* @author Colin McFadden <mcfa0086@umn.edu>
* @license GPL-2.0+
* @link http://github.com/umn-latis/
* @copyright 2017
*
* @wordpress-plugin
* Plugin Name: Elevator Asset Browser
* Plugin URI: http://github.com/umn-latis/
* Description: Adds dropbox button before editor to choose an asset from Elevator
* Version: 0.1.9
* Author: Colin McFadden
* Author URI: http://www.cmcfaddenc.om
* Text Domain: elevatorasset
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/*----------------------------------------------------------------------------*
* Public-Facing Functionality
*----------------------------------------------------------------------------*/
require_once( plugin_dir_path( __FILE__ ) . 'public/class-elevatorasset.php' );
/*
* Register hooks that are fired when the plugin is activated or deactivated.
* When the plugin is deleted, the uninstall.php file is loaded.
*/
register_activation_hook( __FILE__, array( 'elevatorasset', 'activate' ) );
register_deactivation_hook( __FILE__, array( 'elevatorasset', 'deactivate' ) );
add_action( 'plugins_loaded', array( 'elevatorasset', 'get_instance' ) );
/*----------------------------------------------------------------------------*
* Dashboard and Administrative Functionality
*----------------------------------------------------------------------------*/
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'admin/class-elevatorasset-admin.php' );
add_action( 'plugins_loaded', array( 'elevatorasset_Admin', 'get_instance' ) );
}
require_once( plugin_dir_path( __FILE__ ) . 'elevatorAPI.php' );
function elevator_func( $atts ) {
$options = get_option('elevatorasset_global_settings');
$endpoint = $options["endpoint"];
$key = $options["apikey"];
$secret = $options["apisecret"];
$elevatorAPI = new elevatorAPI($endpoint . "/api/v1/",$key,$secret);
$a = shortcode_atts( array(
'width' => '',
'height' => '',
'fileobjectid' => '',
'objectid' => '',
'sourceurl' => '',
'includelink' => '',
'includesummary' => ''
), $atts );
$embedURL = $elevatorAPI->getEmbedContent($a['fileobjectid']);
$returnString = "<span class='elevatorEmbed' style='display:inline-block; width: " . $a['width'] . "px'><iframe width='" . $a['width'] . "' height='" . $a['height'] . "' allowfullscreen=yes frameborder=0 src='" . $embedURL . "'></iframe>";
$includeSummary = false;
$includeLink = false;
if($a['includesummary'] && $a['includesummary'] == "on") {
$includeSummary = true;
}
if($a['includelink'] && $a['includelink'] == "on") {
$includeLink = true;
}
if($includeSummary || $includeLink) {
$assetInfo = $elevatorAPI->assetPreview($a['objectid']);
$returnString .= "<div class='metadataSection'>";
if($includeLink) {
$returnString .= "<p class='metadataRow metadataLink'><a href='" . $a['sourceurl'] . "'>" . $assetInfo["title"] . "</a></p>";
}
if(!$includeLink && $includeSummary) {
$returnString .= "<p class='metadataRow metadataLink'>" . $assetInfo['title'] . "</p>";
}
if ($includeSummary && isset($assetInfo['entries'])){
foreach($assetInfo['entries'] as $entry) {
$returnString .= "<p class='metadataRow metadataEntry'><span class='metadataLabel'>" . $entry["label"] . ":</span> <span class='metadataValue'>" . implode(", ", $entry["entries"]) . "</span></p>";
}
}
$returnString .= "</div>";
}
$returnString .= "</span>";
return $returnString;
}
add_shortcode( 'elevator', 'elevator_func' );
add_action( 'enqueue_block_editor_assets', 'block_editor_assets' );
function block_editor_assets() {
// Scripts.
wp_enqueue_script(
'block-elevator-block-js',
plugins_url( 'dist/blocks.build.js', __FILE__ ),
[ 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components', 'wp-editor' ],
true
);
$options = get_option('elevatorasset_global_settings');
$endpoint = $options["endpoint"];
$key = $options["apikey"];
$secret = $options["apisecret"];
$includeLink = $options["linktooriginalasset"];
$includeSummary = $options["includesummary"];
$script = 'elevator_settings_endpoint = '. json_encode($endpoint) .'; ';
$script .= 'key = '. json_encode($key) .'; ';
$script .= 'secret = '. json_encode($secret) .'; ';
$script .= 'elevator_settings_includeLink = '. json_encode($includeLink) .'; ';
$script .= 'elevator_settings_includeSummary = '. json_encode($includeSummary) .'; ';
wp_add_inline_script('block-elevator-block-js', $script, 'before');
// Styles.
wp_enqueue_style(
'elevator-embed-block-editor',
plugins_url( 'dist/blocks.editor.build.css', __FILE__ ),
array( 'wp-edit-blocks' ),
filemtime( plugin_dir_path( __FILE__ ) . 'editor.css' )
);
}