-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathannotator.module
112 lines (104 loc) · 2.78 KB
/
annotator.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
<?php
/**
* @file
* Annotator module.
*/
/**
* Implements hook_init().
*/
function annotator_init() {
if (user_access('administer annotations') || user_access('view annotations') || user_access('create annotations')) {
$library = libraries_load('annotator');
if ($library['loaded'] == FALSE) {
drupal_set_message($library['error message'], 'error');
}
drupal_add_js(array('annotator' => array('element' => variable_get('annotator_element', '.node'))), 'setting');
drupal_add_js(drupal_get_path('module', 'annotator') . '/js/annotator.js');
annotator_execute_plugins();
}
}
/**
* Implements hook_menu().
*/
function annotator_menu() {
$items = array();
$items['admin/config/content/annotator'] = array(
'title' => 'Annotator',
'description' => 'Configure Annotator settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array('annotator_admin'),
'access arguments' => array('administer annotations'),
'type' => MENU_NORMAL_ITEM,
'file' => 'annotator.pages.inc',
);
return $items;
}
/**
* Implements hook_library_info().
*/
function annotator_libraries_info() {
$libraries['annotator'] = array(
'name' => 'Annotator',
'vendor url' => 'http://annotatorjs.org',
'download url' => 'https://github.com/openannotation/annotator/releases/latest',
'version arguments' => array(
'file' => 'annotator-full.min.js',
'pattern' => '@Annotator\sv(.*)@',
'lines' => 10,
),
'files' => array(
'js' => array(
'annotator-full.min.js',
),
'css' => array(
'annotator.min.css',
),
),
'variants' => array(),
);
return $libraries;
}
/**
* Implements hook_ctools_plugin_directory().
*/
function annotator_ctools_plugin_directory($module, $plugin) {
if ($module == 'annotator') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_ctools_plugin_type().
*/
function annotator_ctools_plugin_type() {
return array(
'annotator' => array(
'cache' => FALSE,
),
);
}
/**
* Execute ctools plugins.
*/
function annotator_execute_plugins($annotation = NULL, $op = NULL) {
ctools_include('plugins');
$annotator_plugins = variable_get('annotator_plugins', array());
foreach ($annotator_plugins as $name => $enabled) {
if ((boolean) $enabled) {
$plugin = ctools_get_plugins('annotator', 'annotator', $name . 'AnnotatorPlugin');
$class = ctools_plugin_get_class($plugin, 'handler');
if (class_exists($class)) {
$instance = new $class($plugin);
$instance->setup();
if ($annotation && $op) {
$instance->alter($annotation, $op);
}
}
}
}
}
/**
* Implements hook_TYPE_alter().
*/
function annotator_annotation_alter($entity, $op) {
annotator_execute_plugins($entity, $op);
}