Good module! I would suggest that you the following function to get the nid because the method you're using would be problematic if the node is aliased. I would suggest that you just have it as a local function. I think something similar needs to be in the core...


function getnid(){
	$path = drupal_lookup_path('source', $_GET['q']);
	if($path == false){
		$path = $_GET['q'];
	}
	$pathvars = explode('/', $path);
	if ($pathvars[0] == 'node'){
		$nid = $pathvars[1];
	}
	return $nid;	
}

Comments

budda’s picture

Assigned: Unassigned » budda
Status: Active » Fixed

Thanks - have added your function to CVS / 4.7.0.

sami_k’s picture

Status: Fixed » Closed (fixed)

since you committed it, i am going to close this.. thanks!

tenrapid’s picture

Status: Closed (fixed) » Closed (won't fix)

This is unnecessary.

During bootstrap $_GET['q'] gets set to the system path and does not contain an aliased path anymore.

So the good old if(arg(0) == 'node') { $nid = arg(1); ... is the way to go.

tenrapid’s picture

Status: Closed (won't fix) » Active
sami_k’s picture

thanks for the clarification.

sami_k’s picture

i have checked, and this is in fact the case! so do revert the code back as tenrapid suggests... sorry about that.

budda’s picture

Version: 4.7.x-1.x-dev » master
Status: Active » Fixed

Reverted back to original code.

Anonymous’s picture

Status: Fixed » Closed (fixed)