Repository navigation
Expand file tree
/
Copy pathinfogram.php
More file actions
executable file
·111 lines (96 loc) · 4.34 KB
/
Copy pathinfogram.php
File metadata and controls
executable file
·111 lines (96 loc) · 4.34 KB
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
<?php
/*
Plugin Name: Infogr.am
Plugin URI: https://blog.infogr.am/new-infogram-wordpress-plugin/
Description: It allows you to insert graphics from the site infogr.am
Version: 1.2.10
Tags: infogram, shortcode, iframe, insert, rest api, json
*/
// Add setings page and register settings
add_action('admin_menu', 'infogr_add_pages');
function infogr_add_pages() {
//create new top-level menu
add_options_page('Infogr.am v1.2.10', 'Infogr.am settings', 'level_0', 'infogram', 'infogr_page');
//call register settings function
add_action('admin_init', 'register_infogr_settings');
}
function register_infogr_settings() {
//register our settings
register_setting('my-infogr-settings', 'infogr_api_key');
register_setting('my-infogr-settings', 'infogr_api_secret');
register_setting('my-infogr-settings', 'infogr_username');
}
function infogr_page() {
global $inforgam;
?>
<div class="wrap">
<h2>Infogram</h2>
<?php $inforgam->plugin_status(); ?>
<form method="post" action="options.php">
<?php settings_fields('my-infogr-settings'); ?>
<?php do_settings_sections('my-infogr-settings'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><?php _e('Your Api key:', 'infogram'); ?></th>
<td><input type="text" name="infogr_api_key" size="40" value="<?php echo esc_attr( get_option('infogr_api_key') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('Your Api secret:', 'infogram'); ?></th>
<td><input type="text" name="infogr_api_secret" size="40" value="<?php echo esc_attr( get_option('infogr_api_secret') ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><?php _e('User name:', 'infogram'); ?></th>
<td><input type="text" name="infogr_username" value="<?php echo esc_attr( get_option('infogr_username') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
function infogr_create_object() {
// Load Api config file
require_once('core/autoload.php');
// Load main Infogram class
require_once('class/class-infogram.php');
// Load media button function
require_once('button/add_button.php');
global $inforgam;
$options = array(
'api_key' => get_option('infogr_api_key'),
'api_secret' => get_option('infogr_api_secret'),
'username' => get_option('infogr_username')
);
if ( !$inforgam ) {
$inforgam = new Infogram($options);
}
}
// out infographic
function infogr_add_infographics($atts) {
$atts = shortcode_atts(array(
'id' => '',
'prefix' => '',
'format' => ''
), $atts, 'id');
if($atts['id']) {
if($atts['format'] && $atts['format'] == 'image') {
return '<script>!function(e,t,n,i,r){var d="script",o="InfogramEmbeds",a=e.getElementsByTagName(d),s=a[0];if(/^\/{2}/.test(n)&&0===t.location.protocol.indexOf("file")&&(n="http:"+n),!t[o]){t[o]={add:function(e,n,i){t[o].list.push({id:e,container:n,type:i})},script:n,list:[]};var c=e.createElement(d);c.async=1,c.src=n,s.parentNode.insertBefore(c,s)}var l=a[a.length-1],m=e.createElement("div");l.parentNode.insertBefore(m,l),t[o].add(i,m,r)}(document,window,"//e.infogr.am/js/dist/embed-loader-min.js","'.$atts['id'].'","image");</script>';
} else {
return '<script>!function(e,t,n,i,r){var d="script",o="InfogramEmbeds",a=e.getElementsByTagName(d),s=a[0];if(/^\/{2}/.test(n)&&0===t.location.protocol.indexOf("file")&&(n="http:"+n),!t[o]){t[o]={add:function(e,n,i){t[o].list.push({id:e,container:n,type:i})},script:n,list:[]};var c=e.createElement(d);c.async=1,c.src=n,s.parentNode.insertBefore(c,s)}var l=a[a.length-1],m=e.createElement("div");l.parentNode.insertBefore(m,l),t[o].add(i,m,r)}(document,window,"//e.infogr.am/js/dist/embed-loader-min.js","'.$atts['id'].'","interactive");</script>';
}
} else {
return 'This code is broken or not exists!';
}
}
add_shortcode('infogram', 'infogr_add_infographics');
// Global Infogram activation hook
function infogr_handle_activation() {}
// Global Infogram deactivation hook
function infogr_handle_deactivation() {}
// Activation hooks for some basic initialization
register_activation_hook(__FILE__, 'infogr_handle_activation');
register_deactivation_hook(__FILE__, 'infogr_handle_deactivation');
// Main Infogram activation hook
if ( is_admin() ) {
add_action('plugins_loaded', 'infogr_create_object');
};