nid != DRUPALORG_CORE_NID)) { //HACK: randomize algorithm rotation $_pivots_block_pid_double = PID_DOUBLE; // double pivot ID defaults to conversation pivots switch (rand(0,2)) { case 0: $_pivots_block_pid_double = 5004; // conversation pivots break; case 1: $_pivots_block_pid_double = 5005; // solr10 break; case 2: $_pivots_block_pid_double = 5006; // corrhr + solr10 break; } $output = _pivots_block_content($node->nid, $_pivots_block_pid_double, t("Related projects"), LIMIT_DOUBLE); //$output .= _pivots_block_suggestbox($node->nid, $_pivots_block_pid_double); return $output; } } function _pivots_block_content($node_id, $pivot_id, $title, $limit) { $output = ''; $ga_event = "$node_id"; $items = _pivots_block_generate_items($node_id, $pivot_id, $limit); if (!empty($items)) { foreach ($items as $position => $item) { $items[$position] = l($item['title'], "node/{$item['nid']}", array( 'attributes' => array( "onClick" => "javascript:pageTracker._trackEvent('PivotsClick_${pivot_id}', '${node_id}_{$item['nid']}');", "rel" => "nofollow" ))); $ga_event .= "_{$item['nid']}"; } //$output = theme('item_list', $items, $title); $output = theme('item_list', $items); // hack: don't show title } $GLOBALS['conf']['googleanalytics_codesnippet_after'] .= "gaq.push(['_trackEvent', 'PivotsPageview_{$pivot_id}', '{$ga_event}']);"; return $output; } function _pivots_block_generate_items($node_id, $pivot_id, $limit) { if ($limit <= 0) { $limit = LIMIT_MAX; } db_set_active('pivots'); // NOTE: here we activate the pivots database. // if there's database failure, we just pretend nothing happens whatsoever. pivots_block returns nothing in this case. $matches = @db_query("SELECT DISTINCT dest_id FROM {pivots_match} WHERE pivot_id=%d AND src_id=%d AND dest_id<>%d ORDER BY score DESC", $pivot_id, $node_id, $node_id); db_set_active(); // NOTE: change back to use the default database $count = 0; $items = array(); while (($match = @db_fetch_array($matches)) && $count < $limit) { $dest_id = $match['dest_id']; $result = db_query("SELECT title FROM {node} WHERE nid=%d AND status=1", $dest_id); // there might be cases that the node was deleted, or set to unpublished between pivots database refresh // so here we only count the valid node. $title = db_result($result); if ($title) { $items[] = array('nid' => $dest_id, 'title' => $title, 'pid' => $pivot_id); $count++; } } return $items; } /*function _pivots_block_suggestbox($node_id, $pivot_id) { $form = array(); $form['suggestion'] = array ( '#type' => 'textfield', //'#description' => t("Please suggest related projects. Multiple suggestions require multiple submission."), '#size' => 20, '#maxlength' => 128, '#weight' => 0, '#id' => 'pivots_block_suggestbox', ); $form['submit'] = array( '#type' => 'button', '#value' => t('Suggest project!'), '#weight' => 1, '#id' => 'pivots_block_suggestbutton' ); drupal_add_js(" $(document).ready(function() { $('#pivots_block_suggestbutton').click(function() { var pattern = /^http[:][/][/]drupal[.]org[/]project[/]\w+$/; var suggestion = $('#pivots_block_suggestbox').val(); while (!suggestion.match(pattern)) { suggestion = prompt('Please suggest a related project using URLs such as http://drupal.org/project/cck. Thank you.'); if (!suggestion) break; } if (suggestion) { alert('Thank you for suggesting a related project. All suggestions will be aggregated and updated to the results soon.'); pageTracker._trackEvent('PivotsSuggest_${pivot_id}', '${node_id}_'+suggestion); } }); }); ", 'inline'); return drupal_render_form('pivots_block_suggestbox', $form); }*/ /** * Implementation of hook_block() */ function pivots_block_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': return array( array( 'info' => t('pivots_block: Recommendations'), 'cache' => BLOCK_CACHE_PER_PAGE, 'pages' => 'project/*', ), ); return $blocks; case 'view': $block['subject'] = t('Related projects'); $block['content'] = pivots_block_output(); return $block; } }