Skip to content

Instantly share code, notes, and snippets.

@baisong
Created October 3, 2012 13:54
Show Gist options
  • Select an option

  • Save baisong/3827031 to your computer and use it in GitHub Desktop.

Select an option

Save baisong/3827031 to your computer and use it in GitHub Desktop.
Code from iqss_gking.module whose functionality remains to be ported to D7
<?php
// $Id$
/**
* Impements hook_menu().
*
* @ingroup updatefile
* @ingroup biblioterm
*/
function iqss_gking_menu() {
$items = array();
$items['taxonomy/term/biblio/%/%'] = array(
'title' => 'Taxonomy term',
'page callback' => 'iqss_gking_biblio_term_page',
'page arguments' => array(3, 4),
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'taxonomy.pages.inc',
'file path' => drupal_get_path('module', 'taxonomy'),
);
return $items;
}
/**
* Implements hook_theme().
*
* @ingroup biblioterm
*/
function iqss_gking_theme() {
return array(
'iqss_gking_dl' => array(
'arguments' => array(
'term' => NULL,
),
),
);
}
/**
* Impements hook_block().
*
* Define the gking blocks with hook block
*
* @ingroup block
*/
function iqss_gking_block($op = 'list', $delta = FALSE, $edit = array()) {
if ($op == 'list') {
$blocks['filter_by_type']['info'] = t("Filter a Category by Content Type");
$blocks['gking_pub_by_type']['info'] = t('Gkings "Recent Works" to replace default Publications by type');
$blocks['class_materials']['info'] = t('Student Materials');
return $blocks;
}
elseif ($op == 'view') {
switch ($delta) {
case 'filter_by_type':
return iqss_gking_filter_by_type_block();
case 'gking_pub_by_type':
return iqss_gking_pub_by_type_block();
case 'student_materials':
return iqss_gking_student_materials_block();
}
}
}
/**
* Block callback for iqss_gking_student_materials_block
*
* @ingroup block
*/
function iqss_gking_student_materials_block() {
//$materials = node_load(array("nid"=>6814));
$materials = node_load(array(
"nid" => 6814,
));
$block['subject'] = t('Student Materials');
$block['content'] = node_view($materials, $teaser = FALSE, $page = TRUE, $links = TRUE);
return $block;
}
/**
* Block to filter a taxonomy by type.
*
* @ingroup biblioterm
* @ingroup block
*/
function iqss_gking_filter_by_type_block() {
$router_item = menu_get_item();
if (strpos($router_item['path'], 'taxonomy/term') !== 0) {
return array();
}
$view = views_get_view('publication_types');
$view->init();
$view->set_display('block_2');
$view->set_arguments(array(
current($router_item['page_arguments']),
));
//Change to the tax. path
$view->display['page_1']->handler->options['path'] = "taxonomy/term/biblio/%/%";
$view->execute();
$output = $view->render();
if (!$output) {
return array();
}
$a_term = taxonomy_get_term(current($router_item['page_arguments']));
return count($view->result) ? array(
'subject' => $a_term->name . " by Publication Type",
'content' => $output,
) : array();
}
/**
* Menu callback; displays all nodes associated with a term by publication type.
*
* @ingroup biblioterm
*/
function iqss_gking_biblio_term_page($str_tids, $s_biblio_type) {
$terms = taxonomy_terms_parse_string($str_tids);
if ($terms['tids']) {
$result = db_query(db_rewrite_sql('SELECT t.tid, t.name FROM {term_data} t WHERE t.tid IN (' . db_placeholders($terms['tids']) . ')', 't', 'tid'), $terms['tids']);
// we rebuild the $tids-array so it only contains terms the user has access to.
$tids = array();
$names = array();
while ($term = db_fetch_object($result)) {
$tids[] = $term->tid;
$names[] = $term->name;
}
if ($names) {
$title = implode(', ', $names);
drupal_set_title(check_plain($title));
$descendant_tids = array();
foreach ($tids as $index => $tid) {
$term = taxonomy_get_term($tid);
$tree = taxonomy_get_tree($term->vid, $tid, -1, 0);
$descendant_tids[] = array_merge(array(
$tid,
), array_map('_taxonomy_get_tid_from_term', $tree));
}
$args = call_user_func_array('array_merge', $descendant_tids);
$placeholders = db_placeholders($args, 'int');
$args[] = str_replace("-", " ", $s_biblio_type);
$sql = 'SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {biblio} b ON b.nid = n.nid INNER JOIN {biblio_types} bt ON b.biblio_type = bt.tid WHERE tn.tid IN (' . $placeholders . ') AND bt.name LIKE \'%s\' AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC';
return theme('taxonomy_term_page', $tids, db_query($sql, $args));
}
}
}
/**
* Implements hook_link_alter().
*
* Moves the admin links (above) at the end of the node links.
*
* @ingroup custom
*/
function iqss_gking_link_alter(&$links, $node) {
if (!iqss_gking_on_gking_site()) {
return;
}
if (isset($links['vsite-admin'])) {
$active_menu = menu_get_item();
if ($active_menu['path'] == 'iqss_gking_research_group' && $node->type == 'person') {
$links['vsite-admin']['title'] = str_replace(' ctools-dropdown ', ' ', $links['vsite-admin']['title']);
}
}
}
/**
* Block callback; overrides _scholar_publications_pub_by_type_wgt
*
* Allows for custom categories for Gary
*
* @ingroup block
*/
function iqss_gking_pub_by_type_block() {
$vsite = vsite_get_vsite();
$types[] = array(
'key' => array('journal-article', 'working-paper'),
'name' => 'Papers',
);
$types[] = array(
'key' => 'book',
'name' => 'Books',
);
$types[] = array(
'key' => 'software',
'name' => 'Software',
);
$output = "";
$i = 0;
$tabs = "<h3 class=\"title\">Recent Work</h3><ul class=\"ui-tabs-nav\">";
foreach ($types as $type) {
$tabs .= "<li><a href=\"#pub_type_tabs-{$i}\">{$type['name']}</a></li>";
$view = views_get_view('publication_types');
if (!is_array($type['key'])) {
$view->set_arguments(array($type['key']));
}
else {
$s_tids = db_result(db_query('SELECT CAST(GROUP_CONCAT(t.tid SEPARATOR \'\+\') as CHAR) FROM {biblio_types} as t WHERE tid > -2 AND visible = 1 AND name IN(' . db_placeholders($type['key'], 'varchar') . ') ', str_replace('-', ' ', $type['key'])));
$view->set_arguments(array('all', $s_tids));
};
$view->execute('page_1');
$output .= "<div id='pub_type_tabs-{$i}'>";
foreach ($view->result as $row) {
$node = node_load($row->nid);
$output .= "\n" . theme('biblio_entry', $node, variable_get('biblio_base', 'biblio'), biblio_get_style());
}
$s_url = is_array($type['key']) ? "publications/types/all/" . $s_tids : "publications/types/" . $type['key'];
$output .= '<div class="more-link">' . l("More " . $type['name'], $s_url) . '</div> ';
$output .= "</div>";
$i++;
}
// Presentations
$tabs .= "<li><a href=\"#pub_type_tabs-{$i}\">Presentations</a></li>";
$view = views_get_view('scholar_presentations');
$view->execute('page_1');
$output .= "<div id='pub_type_tabs-{$i}'>";
foreach ($view->result as $row) {
$node = node_load($row->nid);
$output .= node_view($node, TRUE);
}
$output .= '<div class="more-link">' . l("More Presentations", "presentations") . '</div> ';
$output .= "</div>";
$tabs .= "</ul>";
if (!$output) {
return array();
}
$output = "<div id='pub_type_tabs'>" . $tabs . $output . "</div>";
return array(
'subject' => "Recent Writings",
'content' => $output,
);
}
@baisong

baisong commented Oct 10, 2012

Copy link
Copy Markdown
Author

Currently, there appear to be 5 remaining customizations:

  • @InGroup block, block hooks and callbacks
  • @InGroup nodeorder, relates to nodeorder module
  • @InGroup contextual_annotation, relates to contextual_annotation module
  • @InGroup updatefile, relates to cron updating file fields
  • @InGroup biblioterm, a menu hook and block that overrides 'Publications by type'.
  • @InGroup random, term title formatting for "Research Interests"

@baisong

baisong commented Oct 10, 2012

Copy link
Copy Markdown
Author

correction, that's 6.

@baisong

baisong commented Oct 12, 2012

Copy link
Copy Markdown
Author

Remaining:

  • 3 blocks
  • 1 page (publications by type)
  • 1 link alter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment