-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathebtools.module
463 lines (446 loc) · 13.7 KB
/
ebtools.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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
<?php
/**
* @file
* A block module that displays recent blog and forum posts.
*/
/**
* Implements hook_help;
*
* Displays help and module information.
*
* @param path
* Which path of the site we're using to display help
* @param arg
* Array that holds the current path as returned from arg() function
*/
function ebtools_help($path, $arg) {
switch ($path) {
case "admin/help#ebtools":
return '<p>' . t("Various tools for accessing Ebart services") . '</p>';
break;
}
}
/**
* Display form for date selection
*
* @return form
*/
function ebtools_dateselect_form(){
$form['dateselection'] = array(
'#type' => 'fieldset',
'#title' => t('Date range'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['dateselection']['startdate'] = array(
'#type' => 'date',
'#title' => t('Start date'),
);
$form['dateselection']['enddate'] = array(
'#type' => 'date',
'#title' => t('End date'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
return $form;
}
/**
* Form for filter on person page
*/
function ebtools_personfilter_form() {
$opts_genres = array(
t('Genres') => array(
'all' => t('All'),
'interview' => t('Interview'),
'bio' => t('Biographical data'),
'aboutperson' => t('About other person'),
),
);
$rpath = request_path();
$particles = explode('/', $rpath);
$person = array_pop($particles);
$themes = _ebtools_person_themes_total($person, 'novina');
$ops = array('All' => t('All'),);
/*
$replacements = array(
' ' => '-',
'š' => 's',
'č' => 'c',
'ć' => 'c',
'đ' => 'd',
'ž' => 'z',);
*/
foreach($themes as $theme) {
/*
$op = strtr(strtolower($theme), $replacements);
$ops[$op] = $theme;
*/
$ops[$theme] = $theme;
}
$opts_themes = array(t('Themes') => $ops);
$form['personfilter'] = array(
'#type' => 'fieldset',
'#title' => t('Filters'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['personfilter']['genreselect'] = array(
'#type' => 'select',
'#title' => t('Genres'),
'#options' => $opts_genres,
);
$form['personfilter']['themeselect'] = array(
'#type' => 'select',
'#title' => t('Themes'),
'#options' => $opts_themes,
);
$form['personfilter']['dateselection'] = array(
'#type' => 'fieldset',
'#title' => t('Date range'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
if (module_exists('date_popup')) {
//use fancy date_popup if it installed
$default = strftime('%Y-%m-%d');
$format = 'd.m.Y';
$min_year = variable_get('ebtools_start_year');
$max_year = variable_get('ebtools_end_year');
$year_range = $min_year . ':' . $max_year;
$form['personfilter']['dateselection']['startdate'] = array(
'#type' => 'date_popup',
'#title' => t('Start date'),
'#date_label_position' => 'within',
'#date_text_parts' => array('year', 'month', 'day'),
'#default_value' => $default,
'#date_format' => $format,
'#date_year_range' => $year_range,
);
$form['personfilter']['dateselection']['enddate'] = array(
'#type' => 'date_popup',
'#title' => t('End date'),
'#date_label_position' => 'within',
'#date_text_parts' => array('year', 'month', 'day'),
'#default_value' => $default,
'#date_format' => $format,
'#date_year_range' => $year_range,
);
} else {
$form['personfilter']['dateselection']['startdate'] = array(
'#type' => 'date',
'#title' => t('Start date'),
);
$form['personfilter']['dateselection']['enddate'] = array(
'#type' => 'date',
'#title' => t('End date'),
);
}
/*
$form['ftsearch'] = array(
'#type' => 'fieldset',
'#title' => t('Full text search'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['ftsearch']['personftsearch'] = array(
'#type' => 'textfield',
'#title' => t('Search'),
);*/
$form['personfilter']['submit'] = array(
'#type' => 'submit',
'#value' => t('Refine'),
);
return $form;
}
/**
* Filter form for lists things
*/
function ebtools_tablefilter_form() {
$form['tablefilter'] = array(
'#type' => 'textfield',
'#title' => t('Filter:'),
/*'#default_value' => t('Enter text to refine'),
'#size' => 60,
'#maxlength' => 128,*/
);
return $form;
}
/**
* Display form for search
*/
function ebtools_search_form(){
$form['ebsearch'] = array(
'#type' => 'textfield',
'#size' => 20,
'#maxlength' => 120,
);
$form['ebsearch_submit'] = array(
'#type' => 'submit',
//'#value' => t('Search'),
);
return $form;
}
/**
* Return user access list as item_list
*/
function ebtools_user_rights() {
$access_rights = array(
'access news archive' => array(t('NEWS ARCHIVE'), 'ebart/novinski/medij/'),
'access video archive' => array(t('VIDEO ARCHIVE'), 'ebart/video/NEPOSTOJI/'),
'access press clipping' => array(t('PRESS CLIPPING'), 'ebart/press/'),
'access video clipping' => array(t('VIDEO CLIPPING'), 'ebart/videoclipping/'),
'access web clipping' => array(t('WEB CLIPPING'), 'ebart/webclipping/'),
'access media analysis' => array(t('MEDIA ANALYSIS'), 'ebart/analize/'),
);
$items = array();
foreach($access_rights as $right => $data) {
if (user_access($right)) {
$name = $data[0];
$link = $data[1];
$items[] = l($name, $link);
}
}
return $items;
}
/**
* submit function for dateselect form
*/
function ebtools_dateselect_form_submit($form, &$form_state) {
$values = $form_state['values'];
$sdate = implode('.', array($values['startdate']['day'], $values['startdate']['month'], $values['startdate']['year']));
$edate = implode('.', array($values['enddate']['day'], $values['enddate']['month'], $values['enddate']['year']));
//drupal_set_message(t('Start date: !start, end date: !end', array('!start' => $sdate, '!end' => $edate)));
}
/**
* submit function for search form
*/
function ebtools_search_form_submit($form, &$form_state) {
$query = $form_state['values']['ebsearch'];
$url = 'ebart/pretraga/novinski/' . check_plain($query);
$form_state['redirect'] = $url;
}
function ebtools_personfilter_form_submit($form, $form_state) {
$values = $form_state['values'];
$genre = $values['genreselect'];
$theme = $values['themeselect'];
if (module_exists('date_popup')) {
$sdate = $values['startdate'];
$edate = $values['enddate'];
} else {
$sdate = implode('.', array($values['startdate']['day'], $values['startdate']['month'], $values['startdate']['year']));
$edate = implode('.', array($values['enddate']['day'], $values['enddate']['month'], $values['enddate']['year']));
}
drupal_set_message("Odabrano:\nGenre: " . $genre . "\tTheme: " . $theme . "\tFROM: " . $sdate . ' - TO: ' . $edate);
/*
$rpath = request_path();
$particles = explode('/', $path);
$name = array_pop($particles);
$url = 'ebart/novinski/licnostzanr/' . $selected . '/' . $name;
drupal_set_message('Odabrano: ' . check_plain($selected));
$form_state['redirect'] = $url;
$ftsearch = $form_state['values']['personftsearch'];
$genre = &drupal_static('ebtools_personfilter_genre');
$genre = $selected;
$search = &drupal_static('ebtools_personfilter_search');
$search = $ftsearch;
drupal_set_message('Odabrano: ' . check_plain($selected) . "\tFT: " . check_plain($ftsearch));*/
}
/**
* Implements hook_block_info().
*/
function ebtools_block_info() {
$blocks['dateform'] = array(
'info' => t('Ebtools - dates block'),
'cache' => DRUPAL_CACHE_PER_ROLE, //default
);
$blocks['personfilter'] = array(
'info' => t('Ebtools - filter form for person page'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['ebsearch'] = array(
'info' => t('Ebtools - search form'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['ebfilter'] = array(
'info' => t('Ebtools - filter block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['listall'] = array(
'info' => t('Ebtools - List ALL of type'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['listallby'] = array(
'info' => t('Ebtools - List ALL for value (list for)'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
$blocks['myebart'] = array(
'info' => t('Ebtools - MyEbart block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}
/**
* Implements hook_permission().
*/
function ebtools_permission() {
return array(
'access ebtools search results page' => array(
'title' => t('Access search results page'),
'description' => t('Allow users to access page with search results'),
),
'access news archive' => array(
'title' => t('News archive access'),
'description' => t('Allows users to access "News article" archive'),
),
'access video archive' => array(
'title' => t('Video archive access'),
'description' => t('Allows users to access "Video clip" archive'),
),
'access press clipping' => array(
'title' => t('Press clipping access'),
'description' => t('Allow users to access "Press clipping" service'),
),
'access video clipping' => array(
'title' => t('Video clipping access'),
'description' => t('Allow users to access "Video clipping" service'),
),
'access web clipping' => array(
'title' => t('Web clipping access'),
'description' => t('Allow users to access "Web clipping" service'),
),
'access media analysis' => array(
'title' => t('Media analysis access'),
'description' => t('Allow users to access "Media analysis" service'),
),
);
}
/**
* Implements hook_block_view().
*
* Prepares the contents of the block.
*/
function ebtools_block_view($delta = '') {
if ($delta == 'dateform') {
$block['subject'] = t('Select dates');
$block['content'] = drupal_get_form('ebtools_dateselect_form');
} elseif ($delta == 'ebsearch') {
//$block['subject'] = t('Pretraga');
$block['content'] = drupal_get_form('ebtools_search_form');
} elseif ($delta == 'ebfilter') {
$block['content'] = drupal_get_form('ebtools_tablefilter_form');
} elseif ($delta == 'personfilter') {
$block['content'] = drupal_get_form('ebtools_personfilter_form');
} elseif ($delta == 'listall') {
//$block['subject'] = t('All media');
if (user_access('access content')) {
$items = _ebtools_block_list();
if (empty($items)) {
$block['content'] = t('No results found');
} else {
$block['content'] = array(
'#theme' => 'item_list',
'#items' => $items,
'#attributes' => array(
'class' => 'all-items-list'),
);
}
}
} elseif ($delta == 'listallby') {
if (user_access('access content')) {
$data = _ebtools_block_listby();
if (empty($data)) {
$block['content'] = t('No results found');
} else {
$block['content'] = $data;
}
}
} elseif ($delta == 'myebart') {
$block['subject'] = t('My Ebart');
$items = ebtools_user_rights();
if (empty($items)) {
$block['content'] = t('No rights given to this user');
} else {
$block['content'] = array(
'#theme' => 'item_list',
'#attributes' => array('class' => 'user-services'),
'#items' => $items);
}
} /*else {
$block['content'] = t('Wrong block type !delta', array('!delta' => $delta));
}*/
return $block;
}
/**
* Implements hook_menu().
*/
function ebtools_menu() {
$items = array();
$items['admin/config/content/ebtools'] = array(
'title' => t('Ebart tools'),
'description' => 'Configuration for Ebart tools module',
'page callback' => 'drupal_get_form',
'page arguments' => array('ebtools_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'file' => 'ebtools.admin.inc',
);
$items['ebart/pretraga/%/%'] = array(
'title' => t('Search results (Ebart)'),
'page callback' => 'ebtools_pretraga',
'page arguments' => array(2,3),
'access arguments' => array('access ebtools search results page'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
$items['ebart/news/bydate'] = array(
'title' => t('Listing by date'),
'page callback' => '_ebtools_archive_bydate',
#'page arguments' => array(4,5,6),
#/GODINA/MESEC/DAN
'access arguments' => array('access news archive'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
$items['ebart/novinski/clanak/%/%'] = array(
'title' => t('Article view'),
'page callback' => 'ebtools_novinski_clanak',
'page arguments' => array(3,4),
'access arguments' => array('access news archive'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
$items['ebart/novinski/clanaksirovo/%/%'] = array(
'title' => t('Raw article view'),
'page callback' => '_ebtools_archive_rawarticle',
'page arguments' => array(3,4),
'access arguments' => array('access ebtools archive article page'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
/*
$items['ebart/novinski/licnostzanr'] = array(
'title' => t('Person + genre'),
'page_callback' => '_ebtools_archive_persongenre',
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
*/
$items['ebart/novinski'] = array(
'title' => t('Listing'),
'page callback' => '_ebtools_list',
'access arguments' => array('access news archive'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
$items['ebart/novinski/%/%/clanak/%/%'] = array(
'title' => t('Article'),
'page callback' => '_ebtools_dump',
'page arguments' => array(2,3,5,6),
'access arguments' => array('access news archive'),
'type' => MENU_CALLBACK,
'file' => 'ebtools.pages.inc',
);
return $items;
}