*/
function mkdru_install() {
// Disable comments by default
- variable_set('comment_mkdru', COMMENT_NODE_DISABLED);
+ variable_set('comment_mkdru', COMMENT_NODE_HIDDEN);
+ // Facets
+ $facets = array('source', 'subject', 'author');
+ variable_set('mkdru_facets', $facets);
+ // Restrict facet block visibility
+ foreach ($facets as $facet) {
+ db_insert('block_node_type')
+ ->fields(array(
+ 'module' => 'mkdru',
+ 'delta' => 'mkdru_facet_' . $facet,
+ 'type' => 'mkdru'))->execute();
+ }
}
/**
function mkdru_uninstall() {
// Delete variables
variable_del('pz2_js_path');
+ // Clear block visibility
+ db_delete('block_node_type')->condition('module', 'mkdru')->execute();
}
\ No newline at end of file
function mkdru_delete($node) {
// Deleting by nid covers all revisions.
db_delete('mkdru')
- ->condition('nid', $nid->nid)
+ ->condition('nid', $node->nid)
->execute();
}
* Implements hook_block_info()
*/
function mkdru_block_info() {
- // NB: block caching is redundant for static content
- $blocks['mkdru_sources']['info'] = t('mkdru - source facets');
- $blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE;
- $blocks['mkdru_subjects']['info'] = t('mkdru - subject facets');
- $blocks['mkdru_subjects']['cache'] = DRUPAL_NO_CACHE;
- $blocks['mkdru_authors']['info'] = t('mkdru - author facets');
- $blocks['mkdru_authors']['cache'] = DRUPAL_NO_CACHE;
+ // facet blocks
+ $facets = variable_get('mkdru_facets');
+ foreach ($facets as $facet) {
+ // NB: block caching is redundant for static content
+ $blocks['mkdru_facet_' . $facet]['info'] = "mkdru - $facet " . t('facet');
+ $blocks['mkdru_facet_' . $facet]['cache'] = DRUPAL_NO_CACHE;
+ }
// search blocks
$result = db_query("SELECT title, nid FROM {node} WHERE type = 'mkdru';");
t('mkdru - search box for "' . $node->title . '"');
$blocks['mkdru_sources']['cache'] = DRUPAL_NO_CACHE;
};
+
return $blocks;
}
* Implements hook_block_view()
*/
function mkdru_block_view($delta) {
- switch ($delta) {
- case 'mkdru_sources':
- $block['subject'] = t('Source');
- $block['content'] = theme('mkdru_block_facet',
- array('class' => 'mkdru-facet-source'));
- return $block;
- case 'mkdru_subjects':
- $block['subject'] = t('Subject');
- $block['content'] = theme('mkdru_block_facet',
- array('class' => 'mkdru-facet-subject'));
- return $block;
- case 'mkdru_authors':
- $block['subject'] = t('Author');
- $block['content'] = theme('mkdru_block_facet',
- array('class' => 'mkdru-facet-author'));
- return $block;
- }
- if (substr($delta, 0, 13) == 'mkdru_search_') {
+ if (substr($delta, 0, 12) == 'mkdru_facet_') {
+ $facet = substr($delta, 12);
+ $block['subject'] = t(ucwords($facet));
+ $block['content'] = theme('mkdru_block_facet',
+ array('class' => 'mkdru-facet-' . $facet));
+ return $block;
+ }
+ elseif (substr($delta, 0, 13) == 'mkdru_search_') {
$nid = substr($delta, 13);
$block['content'] = theme('mkdru_block_search',
array('nid' => $nid, 'path' => '/node/' . $nid));