diff -rub similarterms.orig/similarterms.admin.inc similarterms/similarterms.admin.inc --- similarterms.orig/similarterms.admin.inc 2009-01-26 01:46:55.000000000 +0000 +++ similarterms/similarterms.admin.inc 2009-07-31 16:46:14.000000000 +0100 @@ -48,6 +48,27 @@ '#prefix' => '
', '#suffix' => '
', ); + $similarterms_blocks = variable_get('similarterms_blocks',array()); + $form['similarterms_blocks'] = array( + '#tree' => TRUE, + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#title' => t('Additional block configuration'), + ); + + $vocabs = taxonomy_get_vocabularies(); + $any = array('vid' => 0, 'name' => t('ANY')); + array_unshift($vocabs, (object)$any); + foreach ($vocabs as $v) { + $form['similarterms_blocks'][$v->vid] = array( + '#type' => 'textfield', + '#title' => t('Number of blocks for the @vocab vocabulary', array('@vocab' => $v->name)), + '#size' => 3, + '#default_value' => isset($similarterms_blocks[$v->vid])?$similarterms_blocks[$v->vid]:1, + '#description' => t('The number of blocks to offer in the block configuration for this vocabulary'), + ); + } $cache_options = drupal_map_assoc(array(0, 300, 600, 900, 1800, 3600, 7200, 21600, 43200, 86400, 604800, 1209600, 2419200, 4838400, 9676800, 31536000), 'format_interval'); $cache_options[0] = t('Never'); diff -rub similarterms.orig/similarterms.module similarterms/similarterms.module --- similarterms.orig/similarterms.module 2009-01-26 22:15:01.000000000 +0000 +++ similarterms/similarterms.module 2009-07-31 16:46:10.000000000 +0100 @@ -1,6 +1,8 @@ $v->name,'@count' => ($num>1?'#'.$i:''))); + $blocks['0_'.$i]['cache'] = BLOCK_CACHE_PER_PAGE; + } if (variable_get("similarterms_vocabularies", 'multi_select_and_tags') == 'all') { foreach (taxonomy_get_vocabularies() as $v) { - $blocks[$v->vid]['info'] = t('Similar entries from the @vocab vocabulary.', array('@vocab' => $v->name)); - $blocks[$v->vid]['cache'] = BLOCK_CACHE_PER_PAGE; + $num = isset($similarterms_blocks[$v->vid])?$similarterms_blocks[$v->vid] : 1; + for($i=1;$i<=$num;$i++) { + $blocks[$v->vid.'_'.$i]['info'] = t('Similar entries from the @vocab vocabulary. @count', array('@vocab' => $v->name,'@count' => ($num>1?'#'.$i:''))); + $blocks[$v->vid.'_'.$i]['cache'] = BLOCK_CACHE_PER_PAGE; + } + } } else { foreach (taxonomy_get_vocabularies() as $v) { // this only makes sense for multi-select vocabularies and free tagging if ($v->multiple || $v->tags) { - $blocks[$v->vid]['info'] = t('Similar entries from the @vocab vocabulary.', array('@vocab' => $v->name)); - $blocks[$v->vid]['cache'] = BLOCK_CACHE_PER_PAGE; + $num = isset($similarterms_blocks[$v->vid])?$similarterms_blocks[$v->vid] : 1; + for($i=1;$i<=$num;$i++) { + $blocks[$v->vid.'_'.$i]['info'] = t('Similar entries from the @vocab vocabulary. @count', array('@vocab' => $v->name,'@count' => ($num>1?'#'.$i:''))); + $blocks[$v->vid.'_'.$i]['cache'] = BLOCK_CACHE_PER_PAGE; + } } } } @@ -70,11 +83,12 @@ $form['showcurrentnode'] = array( '#type' => 'checkbox', '#title' => t('Show current node as active in the list'), - '#default_value' => variable_get('similarterms_showcurrentnode_'. $delta, FALSE), + '#default_value' => variable_get('similarterms_showcurrentnode_'. $delta , FALSE), '#required' => FALSE, ); //mimo addition to configuration to limit to same page type - $types = array('0' => t(''), '1' => t('same as current')); + $types = array( '0' => t(''), '1' => t('same as current'), + '2' => t('other than current') ); $arr_types_obj = node_get_types(); foreach ($arr_types_obj as $type => $obj) { $types[$type] = $obj->name; @@ -103,21 +117,21 @@ ); } return $form; - } - else if ($op == 'save') { + } else if ($op == 'save') { variable_set('simterms_count_'. $delta, $edit['count']); variable_set('simterms_sametype_'. $delta, $edit['sametype']); variable_set('simterms_ignoreterms_'. $delta, $edit['ignoreterms']); variable_set('similarterms_showcurrentnode_'. $delta, $edit['showcurrentnode']); - } - else if ($op == 'view') { - if ($delta == 0) { + } else if ($op == 'view') { + if ($delta === 0) { $block['subject'] = t('Similar'); $block['content'] = theme('similarterms', variable_get('similarterms_display_options', 'title_only'), similarterms_list()); + } else { + if(strpos($delta,'_') !== FALSE) { + list($vid,$num) = explode('_',$delta); } - else { $block['subject'] = t('Similar'); - $block['content'] = theme('similarterms', variable_get('similarterms_display_options', 'title_only'), similarterms_list($delta)); + $block['content'] = theme('similarterms', variable_get('similarterms_display_options', 'title_only'), similarterms_list($delta, $vid)); } return $block; } @@ -133,7 +147,7 @@ * @return * an array of node objects */ -function similarterms_list($vocid = 0, $nid = NULL) { +function similarterms_list($delta=0, $vocid = NULL, $nid = NULL, $count = 5) { $nodes = array(); $sql = ""; $args = array(); @@ -144,7 +158,7 @@ } if ($nid != NULL) { - $cid = "$vocid:$nid"; + $cid = "$delta:$vocid:$nid"; if ($cache_lifetime) { if ($cached = cache_get($cid, 'cache_similarterms')) { return $cached->data; @@ -158,9 +172,8 @@ else { $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node_obj, $vocid)); } - // Filter out some terms - $terms_filter = variable_get('simterms_ignoreterms_'. $vocid, array()); + $terms_filter = variable_get('simterms_ignoreterms_'. $delta, array()); foreach ($terms_filter as $v) { $idx = array_search($v, $terms); @@ -169,7 +182,7 @@ } } - $count = variable_get('simterms_count_'. $vocid, 5); + $count = variable_get('simterms_count_' . $delta, 5); if (!empty($terms)) { //past events @@ -193,13 +206,16 @@ } $sql .= ') '; - $types = variable_get('simterms_sametype_'. $vocid, FALSE); + $types = variable_get('simterms_sametype_'. $delta, FALSE); if (($types !== FALSE) && is_array($types) && count($types) > 0 && ($types['0'] == NULL) ) { - if ($types[1]) { + if ($types[1] || $types[2]) { $node_obj = node_load($nid); $types[1] = $node_obj->type; + if ($types[2] == 2) { // not in + $not = " NOT "; } - $sql .= 'AND n.type IN ('; + } + $sql .= 'AND n.type ' . $not . ' IN ('; $number_of_types = count($types); foreach ($types as $types_items) { $number_of_types--; @@ -213,9 +229,8 @@ } $sql .= ') '; } - //if showcurrentnode option is false (default state), create filter for query. - if (!variable_get('similarterms_showcurrentnode_'. $vocid, FALSE)) { + if (!variable_get('similarterms_showcurrentnode_'. $delta, FALSE)) { $sql .= 'AND n.nid != %d '; $args[] = $nid; }