-
Notifications
You must be signed in to change notification settings - Fork 2
/
vinculum.admin.inc
executable file
·177 lines (148 loc) · 4.93 KB
/
vinculum.admin.inc
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* @file
* Admin pages for the vinculum module.
*/
/**
* Menu callback for admin/config/content/vinculum.
*
* Allows the handlers to be prioritised.
*/
function vinculum_settings_form($form) {
$form['vinculum_validate_remote_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Validate remote pages'),
'#description' => t('When linkbacks are received, check that the remote URL is reachable and contains a link to the referenced node.'),
'#default_value' => variable_get('vinculum_validate_remote_pages', FALSE),
);
// Fetch a list of the available handlers (and reset the cache to ensure it's
// always current on this page).
// Handlers are listed by module-weight.
$handlers = vinculum_load_all_handlers(TRUE);
$form['handlers'] = array(
'#tree' => TRUE,
'#theme' => 'vinculum_settings_handlers_form_element',
'#handlers' => $handlers,
);
foreach ($handlers as $handler) {
$form['handlers'][$handler->module] = array(
'#type' => 'weight',
'#title' => check_plain($handler->protocol),
'#default_value' => $handler->weight,
'#attributes' => array(
'class' => array('vinculum-handler-weight'),
),
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
/**
* Submit handler for the configuration form.
*/
function vinculum_settings_form_submit(&$form, &$form_state) {
$weights = $form_state['values']['handlers'];
vinculum_set_weights($weights);
variable_set('vinculum_validate_remote_pages', (bool) $form_state['values']['vinculum_validate_remote_pages']);
drupal_set_message(t('Your settings have been saved.'));
}
/**
* Theme handler for the list of handlers on the vinculum configuration form.
* This transforms the list of handlers into a draggable table.
*/
function theme_vinculum_settings_handlers_form_element($variables) {
$form = $variables['form'];
// Form the handlers into a table.
$header = array(
t('Protocol'),
t('Weight'),
);
$rows = array();
foreach ($form['#handlers'] as $key => $handler) {
// Remove the element's title attribute (it's in the table header).
$form[$key]['#title'] = '';
$rows[] = array(
'data' => array(
'protocol' => $form['#handlers'][$key]->protocol,
'weight' => drupal_render($form[$key]),
),
'class' => array('draggable'),
);
}
$output = '';
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'vinculum-table')));
$output .= drupal_render_children($form);
drupal_add_tabledrag('vinculum-table', 'order', 'sibling', 'vinculum-handler-weight');
return $output;
}
/**
* Report of all vinculums sent.
*/
function vinculum_report_sent() {
$header = array(
array('data' => t('Date'), 'field' => 'timestamp', 'sort' => 'desc'),
array('data' => t('From'), 'field' => 'n.title'),
array('data' => t('Remote URL'), 'field' => 'url'),
array('data' => t('Handler'), 'field' => 'handler'),
);
$query = db_select('node_vinculum_sent', 'l');
$query->join('node', 'n', 'n.nid = l.nid');
$query->extend('PagerDefault')
->limit(1)
->extend('TableSort')
->orderByHeader($header)
->fields('n', array('title'))
->fields('l');
$results = $query->execute();
$handlers = vinculum_get_handler();
$rows = array();
foreach ($results as $result) {
$rows[] = array(
date('d/m/Y H:i', $result->timestamp),
l($result->title, "node/{$result->nid}"),
l($result->url, $result->url),
isset($handlers[$result->handler]) ? $handlers[$result->handler]->protocol : $result->handler,
);
}
$html = '';
$html .= theme('table', array('header' => $header, 'rows'=>$rows));
$html .= theme('pager', array('tags' => array()));
return $html;
}
/**
* Report of all vinculums received.
*/
function vinculum_report_received() {
$header = array(
array('data' => t('Date'), 'field' => 'timestamp', 'sort' => 'desc'),
array('data' => t('Content'), 'field' => 'n.title'),
array('data' => t('Remote URL'), 'field' => 'url'),
array('data' => t('Handler'), 'field' => 'handler'),
);
$query = db_select('node_vinculum_received', 'l');
$query->join('node', 'n', 'n.nid = l.nid');
$query->extend('PagerDefault')
->limit(1)
->extend('TableSort')
->orderByHeader($header)
->fields('n', array('title'))
->fields('l');
$results = $query->execute();
$handlers = vinculum_get_handler();
$rows = array();
foreach ($results as $result) {
$rows[] = array(
date('d/m/Y H:i', $result->timestamp),
l($result->title, "node/{$result->nid}"),
l($result->url, $result->url),
isset($handlers[$result->handler]) ? $handlers[$result->handler]->protocol : $result->handler,
);
}
$html = '';
$html .= theme('table', array('header' => $header, 'rows'=>$rows));
$html .= theme('pager', array('tags' => array()));
return $html;
}