This repository has been archived by the owner on Sep 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsc_misc.module
executable file
·113 lines (93 loc) · 3.26 KB
/
rsc_misc.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
/**
* Implements hook_menu_alter().
*/
function rsc_misc_menu_alter(&$items) {
// disable some unwanted page callbacks:
$items['node']['page callback'] = 'drupal_not_found';
}
/**
* Implements hook_form_FORM_ID_alter
* Populate search form on search results page
*/
function rsc_misc_form_search_block_form_alter(&$form, &$form_state, $form_id) {
$a0 = arg(0);
$a2 = arg(2);
if($a0 == 'search' && $a2){
$form['search_block_form']['#default_value'] = $a2;
}
}
/**
* Implements hook_menu_breadcrumb_alter(&$active_trail, $item)
*/
function rsc_misc_menu_breadcrumb_alter(&$active_trail, $item) {
// If the breadcrumbs were not set by rsc_library, remove them! (except on admin pages)
if (!path_is_admin(current_path()) && empty($GLOBALS['rsc_library']['breadcrumb_set'])) {
$active_trail = array();
}
}
/**
* Implements hook_html_head_alter().
*
* Enable the use of Google Apps on the site by adding something like this to the header:
* <meta name="google-site-verification" content="9IjCIyPLJJ52UIDC00-aG-CiLfQGT4YuJD3XghhSTYY" />
*/
function rsc_misc_html_head_alter(&$head_elements) {
$head_elements['rsc_misc_google_site_verification'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'google-site-verification',
'content' => '9IjCIyPLJJ52UIDC00-aG-CiLfQGT4YuJD3XghhSTYY'
),
);
}
/**
* Implements hook_node_update_index().
*
* Adds the content of pdf attachments to the search index
* TODO: test whether the index is an accurate representation of the pdf contents
* If not, maybe replace this with Tika and https://drupal.org/project/apachesolr_attachments
*/
function rsc_misc_node_update_index($node) { // return Array of additional information to be indexed.
// index the content of pdfs attached to 'field_attachment' of 'library_article's
if ($node->type=='library_article') {
// TODO: only do this for files with .pdf extention of pdf mime-type (probably easier to check extention)
require_once('class.pdf2text.php');
$a = new PDF2Text();
$attachment = reset($node->field_attachment);
// TODO: use field_get_items
$uri = $attachment[0]['uri']; // This will only use the first language; will not work for multiple language sites
$target = file_create_url($uri);
$a->setFilename($target);
$a->decodePDF();
return $a->output();
}
return null;
}
/**
* Implements hook_page_alter(&$page).
* https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_page_alter/7
*/
function rsc_misc_page_alter(&$page) {
// fix the weight of the sections menu relative to the cached categories menu
if (!empty($page['sidebar_first']['menu_menu-sections-1'])) {
$page['sidebar_first']['menu_menu-sections-1']['#weight'] = -1;
$page['sidebar_first']['#sorted'] = FALSE; // indicate that is still needs to be sorted before rendering
}
// alter the search page
if (arg(0) == 'search') {
if (arg(2)) {
drupal_set_title(t("Search results"));
} else {
drupal_set_title(t("Search"));
}
// FIXME: apachesolr still sets the title in <head> to "Search for content ..."
}
}
/**
* Checked, chainable array_shift
*/
function rsc_shift(&$arr) {
return (is_array($arr)) ? array_shift($arr) : NULL;
}