Towards facets.
[mkdru-moved-to-drupal.org.git] / mkdru.module
1 <?php
2
3 /**
4 * Implementation of hook_node_info().
5 */
6 function mkdru_node_info() {
7   return array(
8     'mkdru' => array(
9       'name' => t("Z39.50/SRU metasearch interface"),
10       'module' => 'mkdru',
11       'description' => t("Metasearch interface for Z39.50/SRU and other targets via a Pazpar2/Service Proxy backend"),
12
13     )
14   );
15 }
16
17 /**
18 * Implementation of hook_perm().
19 */
20 function mkdru_perm() {
21   return array('create metasearch interface', 'edit any metasearch interface', 'edit own metasearch interface');
22 }
23
24 /**
25 * Implementation of hook_access().
26 */
27 function mkdru_access($op, $node, $account) {
28
29   if ($op == 'create') {
30     // Only users with permission to do so may create this node type.
31     return user_access('create metasearch interface', $account);
32   }
33
34   // Users who create a node may edit or delete it later, assuming they have the
35   // necessary permissions.
36   if ($op == 'update' || $op == 'delete') {
37     if (user_access('edit own metasearch interface', $account) && ($account->uid == $node->uid)) {
38       return TRUE;
39     } else if (user_access('edit any metasearch interface', $account)) {
40       return TRUE;
41     }
42   }
43 }
44
45 /**
46 * Implementation of hook_form().
47 */
48 function mkdru_form(&$node, $form_state) {
49   $type = node_get_types('type', $node);
50
51   $form['title'] = array(
52     '#type' => 'textfield',
53     '#title' => check_plain($type->title_label),
54     '#required' => TRUE,
55     '#default_value' => $node->title,
56     '#weight' => -5
57   );
58
59   return $form;
60 }
61
62 /**
63 * Implementation of hook_theme().
64 */
65 function mkdru_theme() {
66   return array(
67     'mkdru_page' => array(
68       'template' => 'mkdru-page',
69       'arguments' => array(),
70     ),
71     'mkdru_page_js' => array(
72       'arguments' => array(),
73     ),
74 //     'mkdru_block_facet' => array(
75 //       'template' => 'mkdru-block-facet',
76 //       'arguments' => array('divId' => NULL),
77 //     ),
78   );
79 }
80
81 /**
82 * Theme function to include Javascript search client and deps
83 */
84 function theme_mkdru_page_js() {
85   $path = drupal_get_path('module', 'mkdru');
86   drupal_add_js('pazpar2/js/pz2.js', 'module', 'footer');
87   drupal_add_js($path . '/mkdru.theme.js', 'module', 'footer');
88   drupal_add_js($path . '/mkdru.client.js', 'module', 'footer');
89 }
90
91 /** 
92 * Implementation of hook_view()
93 */
94 function mkdru_view($node, $teaser = FALSE, $page = FALSE) {
95   $node->content['mkdru_page_js'] = array(
96     '#value' => theme('mkdru_page_js'), 
97     '#weight' => 0,
98   );
99   $node->content['mkdru_page'] = array(
100     '#value' => theme('mkdru_page'), 
101     '#weight' => 1,
102   );
103   return $node;
104 }
105
106 /** 
107 * Implementation of hook_block()
108 */
109 function mkdru_block($op='list', $delta='sources', $edit=array()) {
110   switch ($op) {
111     case 'list':
112       $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
113       $blocks['mkdru_sources']['cache'] = BLOCK_NO_CACHE;
114       $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
115       $blocks['mkdru_subjects']['cache'] = BLOCK_NO_CACHE;
116       $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
117       $blocks['mkdru_authors']['cache'] = BLOCK_NO_CACHE;
118       return $blocks;
119
120     case 'view':
121       switch ($delta) {
122         // TODO: make the facet themable, I have no clue why this won't work
123 //         case 'mkdru_sources':
124 //           $block['subject'] = t('Source');
125 //           $block['content'] = theme('mkdru_block_facet', 'mkdru-sources');
126 //           return $block;
127 //         case 'mkdru_subjects':
128 //           $block['subject'] = t('Subject');
129 //           $block['content'] = theme('mkdru_block_facet', 'mkdru-subjects');
130 //           return $block;
131 //         case 'mkdru_authors':
132 //           $block['subject'] = t('Author');
133 //           $block['content'] = theme('mkdru_block_facet', 'mkdru-authors');
134 //           return $block;
135         case 'mkdru_sources':
136           $block['subject'] = t('Source');
137           $block['content'] = '<div id="mkdru-sources"> </div>';
138           return $block;
139         case 'mkdru_subjects':
140           $block['subject'] = t('Subject');
141           $block['content'] = '<div id="mkdru-subjects"> </div>';
142           return $block;
143         case 'mkdru_authors':
144           $block['subject'] = t('Author');
145           $block['content'] = '<div id="mkdru-authors"> </div>';
146           return $block;
147     }
148   }
149 }