This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

Proposal for extending taxonomy module to filter based on node type

This post is to propose an enhancement of taxonomy module so that it will be possible to to filter nodes also on node type.

This is a need when you have to share one vocabulary between multiple node types.
One example is the vocabulary 'Geography', containing all Cities and Regions. You could have events, stories and other custom made node types, sharing this vocabulary.
The need arises when you want to see only events of a certain region; if you filter only on region, you'll see also stories and the other custom node types.

The new syntax, according to new Drupal 4.5 syntax, could be the following:

taxonomy/term/term1,term2,term3(nodetype1,nodetype2)/........

to filter based on three terms (in OR each others) and on two different node types

or

taxonomy/term/term1+term2+term3(nodetype1,nodetype2)/........

to filter based on three terms (in AND each others) and on two different node types

The rest of the syntax for taxonomy/term will remain the same.

Node types should be tested for validity. You can specify one or more node types; if you omit node types, normal term filtering is issued.

I understand that this need is a common interest of many people; in the past I submitted a patch that adds such feature, but it remained in a limbo situation.

I would like to go on with it, because I need for some sites I'm setting up, but would like to avoid creating a new module, and would like to have such feature in the core, so that modules like taxonomy_html, taxonomy_browser and taxonomy_dhtml could benefit from it.

School assignment manager module?

I'm considering writing a module to handle assignments and classes for my school. The module would support teachers (a user group), the classes they create, and the assignments in each of those classes. I want students to be able to create a class list and easily see what assignments there are. I don't want any sort of "distance learning" features - this is a real brick-and-mortar school.

Expansion of Products in E-Commerce Module

I have just started designing a page around Drupal, and it is amazing...

My question:

Is there any way to add more fields to products?

Example: Add a size dropdown box to a listing for a shirt

trigger inserts after NEW user created

I'd like to trigger a couple of inserts that happen just after a new user is created. I've poked around the user.module and haven't yet found the best place to put something like this.

Any advice would be greatly appreciated! I'm running 4.5.1

thanks,
Phil

My Kingdom for A Simple iframe Module

As wonderful as Drupal is, it would be awesome if a generic container module was available that would allow for external web pages to be embedded in an iframe and then positioned as a Block. I have seen reams of complex how-to on this, but nothing straight forward for the rest of us mere mortal non-propeller heads. My guess is that there are thousands of other who would love to have the simplicity of such a tool, especially if it did not involve trying to write dozens of lines of code,

thanks much for your help

Module for auto-generation of path alias (beta)

If the user leaves the path alias field empty, this module will auto-generate the path. Optionaly information about creation date can be included in the path.

There is a lot of opinions on the best way to do this generation. Everyone seams to have their own idea on what should be included in the path and how it should be ordered. So I wrote the code so that it's fairly easy to add new methods for path generation.

One problem with this module is that it may wake expections that it does not fill. In a url like this www.domain.com/2004/10/23/a-title users may expect that shortening the url to www.domain.com/2004/10 will show the nodes from october.

In order to use the module, copy the code into a file named "path_automatic.module" and drop into your module folder.

// $Id: path_automatic_automatic.module,v 0.1 2004/12/21 21:22:26 Tommy Sundström Exp $


/** 
 * This module auto-generates a path alias.
 *
 * It needs path.module in order to work.
 */
 
/**
 * Implementation of hook_help().
 *
 */
function path_automatic_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      // This description is shown in the listing at admin/modules.
      return t('If the path module is active, renames the URLs automaticly.');
  }
}  



/**
  * Settings for how the path will get generated. 
	*/	
function path_automatic_settings() { 
  if (module_exist(path)) {
	  if (user_access('create url aliases') || user_access('administer url aliases')) {
		  $methods = array(
			             array('value' => 'default',
									       'label' => 'Just title',
												 'descr' => '<p>'.t('If Path Alias field is left blank, generates a path from the title.').'</p>'
												 ),
								 array('value' => 'yearmonth',
									       'label' => 'Include  year and month',
												 'descr' => '<p>'.t('Includes the creation month in the path, in addition to the title.').'</p>'
												 ),
									 array('value' => 'yearmonthday',
									       'label' => 'Include  year, month and day',
												 'descr' => '<p>'.t('Includes the creation date in the path, in addition to the title.').'</p>'
												 ),												 
									 );
			$options = array();
			$description = '<br /><dl>';
			foreach($methods as $method) {
			  $options[$method['value']] = $method['label'];
				$description .= '<dt>'.$method['label'].'</dt>';
				$description .= '<dd>'.$method['descr'].'</dd>';
				}
			$description .= '</dl>';
		
		  $output = form_select(t('Choose path generation method'), 
															'path_automatic_method', 
															variable_get('path_automatic_method','default'), 
															$options,
															$description
															);
															//)
															//$extra = 0, $multiple = FALSE, $required = FALSE);
		
		}
		else {
		  $output = t('You need permission from the path module to <i>create url aliases</i> or <i>administer url aliases</i> for this module to work');
		}
	}
	else {
	  $output = t('This module requires that the path module <a href="/admin/modules">is activated</a>.');
	} 
	return $output;
} 

/**
 * Implementation of hook_nodeapi().
 *
 * Allows URL aliases for nodes to be specified at node edit time rather
 * than through the administrative interface.
 */
function path_automatic_nodeapi(&$node, $op, $arg) {
  if (module_exist(path) && (user_access('create url aliases') || user_access('administer url aliases'))) {
    switch ($op) {
      case 'validate':
			  // (This is not realy validation, but this is the best place to patch in this funtionality.)
			
        $node->path = trim($node->path);
				
				// If no path alias is given and autogenerate is true (in settings), auto generates a path alias from the title.
				if (!$node->path) {  
				  // No alias, generating it 
					if ($node->title) {
					  $method = variable_get('path_automatic_method','default'); 
						$pathstart = '';
						
						// generate pathstart
						switch ($method) {
						  case 'default':
							  // No need to do anything							  
								break;
							case 'yearmonth':
							  $pathstart = date('Y/m',$node->created) . '/';
								break;
							case 'yearmonthday':
							  $pathstart = date('Y/m/d',$node->created) . '/';
								break;								
							default:
							  $pathstart = die('Error: the method given path_automatic does not exist');
							
						}
						if (strstr($pathstart,'***NOT_VALID***')) {
						  // One (or more) of the stringToPath has failed.
						  break;
							}
						
						// generate the path equivalent of the title
						$pathtitle = stringToPath($node->title);
						if ($pathtitle == '***NOT_VALID***') {
						  // The stringToPath has failed.
						  break;
						}
							
						// validate the path
						if (path_automatic_check_if_already_in_use($pathstart.$pathtitle, "node/$node->nid")) {
							// If in use, leave path blank
							break;
						}
													
						// create path
						$node->path = $pathstart.$pathtitle;						
					}
				}
			}
		}
	}
							
						

/** 
 * Clean a string so that it can be used as a path.
 */

function stringToPath($str) {
  $str = strip_tags($str);
						
	// Accented characters					
	$from = 'ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝàáâãäåçèéêëìíîïñòóôõöøùúûüýÿ';
	$to   = 'SZszYAAAAAACEEEEIIIINOOOOOOUUUUYaaaaaaceeeeiiiinoooooouuuuyy';
	for ($n=0; $n < strlen($to); $n++) {
		$str=str_replace(utf8_encode(substr($from, $n, 1)), substr($to, $n, 1), $str);
		}
	// Interpunction etc
	$str = preg_replace("/[ \/_]/", "-", $str);  // replace with dash
	$str = preg_replace("/[.,:;!?¤%&(){}@£$€<>|=*[\]\"\'\\\\]/", "", $str); // remove 
	$str = preg_replace("/-+/", "-", $str); // collapse mulitple dashes into one
	
	$str = trim($str);
	$str = strtolower($str);
	$str = urlencode($str); 
	if (!valid_url($str)) {
		// valid_url will not accept all urls that urlencode can generate (it does not seam to accept the %-encoding)
		// This should be a rare problem, but to be sure, skip path generation when this is the case.
		// (It will only be the case when the title contains other characters than a-z and the ones transformed above.)
		return ('***NOT_VALID***'); //$str = '';
		}
	return ($str); 
}

 

/** 
 * Check that a path alias is not already in use.
 */
function path_automatic_check_if_already_in_use($aliaspath, $realpath) {
  if (db_result(db_query("SELECT COUNT(dst) FROM {url_alias} WHERE dst = '%s' AND src != '%s'", $aliaspath, $realpath))) {
	  return TRUE; // In use
	} 
	else {
	  return FALSE; // Free to use
	}
}

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions