-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-xowl-client.php
executable file
·76 lines (59 loc) · 2.5 KB
/
wp-xowl-client.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
<?php
/**
* Plugin Name: Xowl Service
* Plugin URI: http://demo.ximdex.com/xowl
* Description: An editor plugin for detect semantic entities on your content.
* Version: 0.1
* Author: OXE development team
* Author URI: http://www.ximdex.com/
* Text Domain: xowl-client
*
*/
// Constants definition
defined('ABSPATH') or die('Do not execute me naked, please!');
//Avoiding direct execution!
define('XOWL_VERSION', '0.1');
define('XOWL_MINIMUM_WP_VERSION', '4.2');
define('XOWL_PLUGIN_URL', plugin_dir_url(__FILE__));
define('XOWL_PLUGIN_DIR', plugin_dir_path(__FILE__));
require_once(XOWL_PLUGIN_DIR . '/inc/XowlClient.php');
Xowl_Plugin::init() ;
class Xowl_Plugin
{
static public function post_head()
{
$conf = array(
'xowl_endpoint' => get_option('xowl_endpoint'),
'xowl_apikey' => get_option('xowl_apikey'),
'xowl_plugin_url' => XowlClient::urlTo( ),
'xowl_css' => XowlClient::urlTo( 'assets/css/styles.css' ),
);
$confJson = json_encode($conf);
echo "<script type=\"text/javascript\">var xowlPlugin = {$confJson};</script>";
}
static public function filter_post_data($data, $postarr)
{
$changeFrom = array('/<a class=\\\"xowl-suggestion\\\" (.*) data-(.*)>/iUs');
$data['post_content'] = preg_replace($changeFrom, '<a \1>', $data['post_content']);
return $data;
}
static public function init()
{
register_activation_hook(__FILE__, array('XowlClient', 'plugin_activation'));
register_deactivation_hook(__FILE__, array('XowlClient', 'plugin_deactivation'));
// Activate the main stuff of the plugin
add_action('init', array('XowlClient', 'init'));
// Adding settings menu
add_action('admin_menu', array('XowlClient', 'admin_menu'), 5);
// Add the TinyMCE Xowl Plugin
add_filter("mce_external_plugins", array('XowlClient', "xowl_register_tinymce_plugin"));
add_filter('mce_buttons', array('XowlClient', 'xowl_add_tinymce_button'));
// Pass variables from wordpress to tinymce
foreach (array('post.php', 'post-new.php') as $hook) {
add_action("admin_head-$hook", array('Xowl_Plugin' , 'post_head'));
}
// Capture post content and filter link attributes
add_filter('wp_insert_post_data', array('Xowl_Plugin' , 'filter_post_data'), '99', 2);
add_filter('plugin_action_links_' . plugin_basename(__FILE__), array('XowlClient', 'admin_plugin_settings_link'), 10, 2);
}
}