-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxowl.module
executable file
·150 lines (111 loc) · 3.89 KB
/
xowl.module
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
<?php
/**
* @file
* Module to interact with Xowl for semantic tagging
* @author Ximdex <[email protected]>
*/
function xowl_install() {
Drupal::config('xowl.settings')->set('endpoint', 'http://localhost/xowl')->save();
}
/**
* <p>Implements hook_help().</p>
*
* <p>Displays help and module information</p>
*
* @param string path
* path of the site we're using to display help
* @param array arg
* Array that holds the current path as returned from arg() function
*/
function xowl_help($path, $arg)
{
switch ($path) {
case "admin/help#xowl":
return '<p>' . t("A module to provide semantic tagging to Drupal content through Xowl") . '</p>';
break;
default:
break;
}
}
/**
* <p>Configuration form for Xowl module</p>
*/
function xowl_server_configuration_form()
{
$form = array();
$form['overview'] = array(
'#markup' => t('This interface allows the user to integrate the XOwl module with Drupal'),
'#prefix' => '<p>',
'#suffix' => '</p>',
);
$form['xowl_endpoint'] = array(
'#title' => t('Endpoint'),
'#description' => t('Set the endpoint of the XOwl server. Example: http://domain.com:port/xowl'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => \Drupal::config()->get('xowl_endpoint', 'http://localhost/xowl'),
);
return system_settings_form($form);
}
/**
* <p>Implements hook_form_alter()</p>
* <p>Modify the edit form to include some JS variables needed to decide whether the enhancer button must be enabled or not</p>
*/
function xowl_form_node_form_alter(&$form, &$form_state, $form_id) {
$nodeType = $form_state->getFormObject()->getEntity()->getType() ;
$config = \Drupal::config('xowl.settings');
$endpoint = $config->get('endpoint');
$xowlSettings = array(
'enabled' => 1 ,
'path' => drupal_get_path('module', 'xowl') ,
"basedir" => base_path() . drupal_get_path('module', 'xowl'),
"url" => '/xowl/enhance' ,
);
$form['#attached']['html_head'][] = [
[
'#tag' => 'script',
'#value' => 'xowlSettings = ' . json_encode( $xowlSettings ) . ' ;' ,
],
'xowl-settings'
];
$form['suggestions'] = array(
'#title' => t('Suggestions'),
'#description' => t('Selected suggestions'),
'#type' => 'hidden',
'#attributes' => array('id' => "suggestions_field"),
'#weight' => 0,
);
}
function xowl_editor_js_settings_alter(array &$settings) {
if (empty($settings['editor']['formats'])) {
return;
}
foreach ($settings['editor']['formats'] as $format => $setting) {
$settings['editor']['formats'][$format]['editorSettings']['extraPlugins'] .= ',xowl' ;
$settings['editor']['formats'][$format]['editorSettings']['drupalExternalPlugins']['xowl'] = base_path() . drupal_get_path('module', 'xowl') . '/js/plugins/xowl/xowl.js' ;
$settings['editor']['formats'][$format]['editorSettings']['toolbar'][]= array(
'name' => 'xowl',
'items' => array(
'xowl'),
);
}
}
function xowl_ckeditor_css_alter( array &$settings ) {
array_push( $settings, base_path() . drupal_get_path('module', 'xowl') . '/css/xowl.module.css' ) ;
}
/**
* <p>Callback function for 'xowl/enhance' endpoint</p>
*
* <p>This function calls Ximdex XOwl endpoint to analyze and enhance the content</p>
*/
function xowl_enhance_content()
{
module_load_include('php', 'xowl', 'includes/XowlStanbolService');
$xowlEndpoint = \Drupal::config()->get('xowl_endpoint');
$content = filter_input(INPUT_POST, 'content');
$service = new XowlStanbolService($xowlEndpoint);
$data = $service->suggest($content)->getData();
$data["text"] = $content;
header('Content-type: application/json');
echo json_encode($data);
}