| 1 |
<?php
|
| 2 |
/* $Id: microid.module,v 1.1 2007/09/11 12:18:26 digitalspaghetti Exp $ */
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The MicroID Module generates a microid class and meta tag
|
| 7 |
* See the specs for MicroID at http://microid.org
|
| 8 |
* See this module in action at http://digitalspaghetti.me.uk
|
| 9 |
*/
|
| 10 |
|
| 11 |
function microid_help($section=''){
|
| 12 |
$output = '';
|
| 13 |
|
| 14 |
switch ($section){
|
| 15 |
case "admin/help#microid":
|
| 16 |
$output = '<p>'. t("This module creates a MicroID and embeds it in users posts."). '</p>';
|
| 17 |
break;
|
| 18 |
case "admin/modules#description":
|
| 19 |
$output = '<p>'. t("This module creates a MicroID and embeds it in users posts."). '</p>';
|
| 20 |
break;
|
| 21 |
}
|
| 22 |
|
| 23 |
return $output;
|
| 24 |
}
|
| 25 |
|
| 26 |
function microid_perm(){
|
| 27 |
return array('access content');
|
| 28 |
}
|
| 29 |
|
| 30 |
|
| 31 |
/**
|
| 32 |
* function microid_genhash($email, $url)
|
| 33 |
* This function generates the hash from
|
| 34 |
* The users email and profile_homepage
|
| 35 |
*/
|
| 36 |
|
| 37 |
function generate($identity, $service, $algorithm = 'sha1', $legacy = false) {
|
| 38 |
$microid = "";
|
| 39 |
|
| 40 |
// add uritypes and algorithm if not using legacy mode
|
| 41 |
if (!$legacy) {
|
| 42 |
$microid .= substr($identity, 0, strpos($identity, ':')) . "+" .
|
| 43 |
substr($service, 0, strpos($service, ':')) . ":" .
|
| 44 |
strtolower($algorithm) . ":";
|
| 45 |
}
|
| 46 |
|
| 47 |
// try message digest engine
|
| 48 |
if (function_exists('hash')) {
|
| 49 |
if (in_array(strtolower($algorithm), hash_algos())) {
|
| 50 |
return $microid .= hash($algorithm, hash($algorithm, $identity) . hash($algorithm, $service));
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
| 54 |
// try mhash engine
|
| 55 |
if (function_exists('mhash')) {
|
| 56 |
$hash_method = @constant('MHASH_' . strtoupper($algorithm));
|
| 57 |
if ($hash_method != null) {
|
| 58 |
$identity_hash = bin2hex(mhash($hash_method, $identity));
|
| 59 |
$service_hash = bin2hex(mhash($hash_method, $service));
|
| 60 |
return $microid .= bin2hex(mhash($hash_method, $identity_hash . $service_hash));
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
// direct string function
|
| 65 |
if (function_exists($algorithm)) {
|
| 66 |
return $microid .= $algorithm($algorithm($identity) . $algorithm($service));
|
| 67 |
}
|
| 68 |
|
| 69 |
error_log("MicroID: unable to find adequate function for algorithm '$algorithm'");
|
| 70 |
}
|
| 71 |
|
| 72 |
function microid_nodeapi(&$node, $op, $teaser = NULL, $page = NULL){
|
| 73 |
switch($op) {
|
| 74 |
case 'load':
|
| 75 |
$nauthor = user_load(array('uid' => $node->uid));
|
| 76 |
return array('user_email' => $nauthor->mail);
|
| 77 |
break;
|
| 78 |
case 'view':
|
| 79 |
//watchdog('DS','<pre>'. print_r($node,true) .'</pre>');
|
| 80 |
$hashurl = "http://" . $_SERVER["SERVER_NAME"] . "/node/" . $node->nid;
|
| 81 |
$email = $node->user_email;
|
| 82 |
$hash = generate($email, $hashurl);
|
| 83 |
if ($page && !$teaser){
|
| 84 |
drupal_set_html_head('<meta name="microid" content="mailto' . $hash . '" />');
|
| 85 |
}
|
| 86 |
|
| 87 |
drupal_add_js('$(function(){$("#node-' . $node->nid . '").addClass("microid-mailto' . $hash . '")});', 'inline');
|
| 88 |
break;
|
| 89 |
}
|
| 90 |
}
|
| 91 |
|
| 92 |
/*function microid_comment($a1 = NULL, $op){
|
| 93 |
switch($op) {
|
| 94 |
case 'load':
|
| 95 |
$cauthor = user_load(array('uid' => $comment->uid));
|
| 96 |
return array('user_email' => $cauthor->email, 'user_homepage' => $cauthor->profile_homepage);
|
| 97 |
break;
|
| 98 |
case 'view':
|
| 99 |
if ($comment->uid > 0){
|
| 100 |
$hash = microid_genhash($comment->user_email, $comment->user_homepage);
|
| 101 |
drupal_add_js('$(function(){$("a[@id*=comment]").addClass("microid-' . $hash . '")});', 'inline');
|
| 102 |
}
|
| 103 |
break;
|
| 104 |
}
|
| 105 |
}*/
|