Proposal to share a module for generating block content based on taxonomy term.

I've made a module that creates a block based on the taxonomy terms of the /node or /taxonomy page.

I created it for displaying adverts, as the ad module does create taxonomy based blocks (there is an unresolved issue relating to this here: http://drupal.org/node/166562 )

Would the module I made be of any use to others? If so where would I place it?

The code for my moduleis below. It would not be diffuclt to modify it for other sites, though there is no user interface for changing it. A sample of the module in action can be seen here: http://www.pokersoftwareanalysis.com/

<?php

function poker_ad_module_help($section) {
  switch($section) {
    case "admin/system/modules#name":
      return "onthisdate";
      break;
    case "admin/system/modules#description":
      return t("Display a list of nodes that were created a week ago.");
      break;
  }
}


function poker_ad_module_perm() {
  return array("access onthisdate", "administer onthisdate");
}

function poker_ad_module_block($op='list', $delta=0) {

  // listing of blocks, such as on the admin/system/block page
  if ($op == "list") {
    $block[0]["info"] = t("Vertical Poker Banner");
    return $block;
  } else {
  // our block content
  
    // TAXONOMY
    if (arg(0) == 'taxonomy' && is_numeric(arg(2))) {
    	$tid     = arg(2);
    	$terms   = taxonomy_get_parents_all($tid);
		$terms[] = taxonomy_get_term($tid);	

    }

    
	// NODE
  	if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
	  	$terms = taxonomy_node_get_terms(node_load(arg(1)));        
	} else {
	       // $out.= 'No associated categories.';
	}
	
	$out .= poker_ad_module_get_advert($terms);

  }

    $block['subject']='';
    $block['content']=$out;
    
    return $block;

}

function poker_ad_module_get_advert($terms){

	if(count($terms)==0){
		return '';
	}

  foreach($terms as $term){
  
  	//echo '-' . $term->name;

    if(stripos($term->name,'poker office')>-1
    	||
    	stripos($term->name,'trackers')>-1
    	){
      return '<a title="poker office" href="http://www.pokeroffice.com/portal.php?AffID=10045"><img title="poker office" src="http://www.pokq.com/affiliates/banners/PO_120x60_4.gif" /></a>';
    }
    
    if(stripos($term->name,'texas calculatem')>-1){
      
      return '<!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_110_2_410_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top">

<img src="http://www.superpokeraffiliates.com/_media?data=135039_19_2_X_MiRXZlozRmhmUHlzMg%3D%3D" height="600" width="160" border=0 />
</a> <!-- END SuperPokerAffiliates Media --> ';
		}
  
  }
  
  if(stripos($term->name,'holdem genius')>-1){
  	return '<!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_3_2_3_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top"><img src="http://www.superpokeraffiliates.com/_media?data=530689_3_2_3_MiR5VkZNVHFUbk1BUQ%3D%3D" height="600" width="160" border=0></a> <!-- END SuperPokerAffiliates Media --> ';
  }
  
  if(stripos($term->name,'calculatem pro')>-1){
  	return ' <!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_125_2_422_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top"><img src="http://www.superpokeraffiliates.com/_media?data=530689_125_2_422_MiR5VkZNVHFUbk1BUQ%3D%3D" height="600" width="160" border=0></a> <!-- END SuperPokerAffiliates Media --> ';
  }  
  
  if(stripos($term->name,'sng shark')>-1){
   return '<!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_31_2_116_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top"><img src="http://www.superpokeraffiliates.com/_media?data=530689_31_2_116_MiR5VkZNVHFUbk1BUQ%3D%3D" height="600" width="160" border=0></a> <!-- END SuperPokerAffiliates Media -->';
   }
   
    if(stripos($term->name,'calculators')>-1){      
      return '<!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_110_2_410_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top"><img src="http://www.superpokeraffiliates.com/_media?data=135039_19_2_X_MiRXZlozRmhmUHlzMg%3D%3D" height="600" width="160" border=0 /></a> <!-- END SuperPokerAffiliates Media --> ';
	}
  
  return '<!-- SuperPokerAffiliates Media --> <a href="http://www.superpokeraffiliates.com/_page?data=530689_110_2_410_MiR5VkZNVHFUbk1BUQ%3D%3D" target="_top"><img src="http://www.superpokeraffiliates.com/_media?data=135039_19_2_X_MiRXZlozRmhmUHlzMg%3D%3D" height="600" width="160" border=0 /></a> <!-- END SuperPokerAffiliates Media --> ';
  
  
  

}


?>

Comments

nevets’s picture

I would say its more versatile to make a content type that represents ads, use the same vocabulary to categorize and use views to generate the block.

fcmisc’s picture

Perhaps. I tried what you suggested, but am inexperienced with views and could not do it. Are there any tutorials that would demonstrate how to do this?

vm’s picture

how to do it specifically no. However the advanced help.module contains the buk of views documentation and is a great help.