| 1 |
<?php |
<?php |
| 2 |
// $Id: cocomment.module,v 1.3 2006/09/19 23:55:38 olav Exp $ |
// $Id: cocomment.module,v 1.4 2008/01/15 14:18:14 sanduhrs Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* CoComment integration |
* CoComment integration |
| 6 |
* http://www.cocomment.com |
* http://www.cocomment.com |
| 7 |
* |
* |
| 8 |
* Developed by Olaf Schettler |
* @author |
| 9 |
|
* Developed by Olaf Schettler |
| 10 |
|
* Update to Drupal-5 by Stefan Auditor <stefan.auditor@erdfisch.de> |
| 11 |
*/ |
*/ |
| 12 |
|
|
| 13 |
/* |
/** |
| 14 |
|
* Implementation of hook_menu(). |
| 15 |
|
*/ |
| 16 |
|
function cocomment_menu($may_cache) { |
| 17 |
|
if (!$may_cache) { |
| 18 |
|
//This is a workaround to reset $op to it's original value |
| 19 |
|
//that has been changed by cocomment's enabler.js and prevents |
| 20 |
|
//the comment submission |
| 21 |
|
if ($_POST['op'] == 'Submit Query') { |
| 22 |
|
$_POST['op'] = t('Post comment'); |
| 23 |
|
} |
| 24 |
|
} |
| 25 |
|
} |
| 26 |
|
|
| 27 |
|
/** |
| 28 |
* Implementation of hook_comment(). |
* Implementation of hook_comment(). |
| 29 |
*/ |
*/ |
| 30 |
function cocomment_comment($form, $op) { |
function cocomment_comment($form, $op) { |
| 31 |
global $base_url, $user; |
global $base_url, $user; |
| 32 |
|
|
|
$item = array(); |
|
| 33 |
if ($op == 'form') { |
if ($op == 'form') { |
| 34 |
|
//load necessary information |
| 35 |
|
$node = node_load($form['nid']['#value']); |
| 36 |
|
|
| 37 |
$site_title = check_plain(variable_get('site_name', $_SERVER['HTTP_HOST'])); |
//prepare data for cocomment |
| 38 |
|
$coco = array( |
| 39 |
$nid = $form['nid']['#value']; |
'tool' => 'Drupal (+http://drupal.org/)', |
| 40 |
$url = url('node/'. $node->nid, NULL, NULL, TRUE); |
'siteurl' => $base_url, |
| 41 |
$node = node_load($nid); |
'sitetitle' => variable_get('site_name', $_SERVER['HTTP_HOST']), |
| 42 |
$node_title = check_plain($node->title); |
'pageurl' => url('node/'. $node->nid, NULL, NULL, TRUE), |
| 43 |
|
'pagetitle' => $node->title, |
| 44 |
$item['submit'] = $form['submit']; |
'textareaID' => 'comment', |
| 45 |
$item['submit']['#attributes'] = array('id' => 'op_submit'); |
'buttonID' => 'edit-submit', |
| 46 |
|
'author' => $user->name ? $user->name : '', |
| 47 |
$item['#prefix'] = <<<EOS |
'authorID' => 'name', |
| 48 |
<script type="text/javascript"> |
'formID' => 'comment-form', |
| 49 |
var coco = { |
); |
| 50 |
tool : 'Drupal (+http://drupal.org/)', |
//add data to site header |
| 51 |
siteurl : '{$base_url}', |
drupal_add_js('coco = '. drupal_to_js($coco), 'inline'); |
| 52 |
sitetitle : '{$site_title}', |
|
| 53 |
pageurl : '{$url}', |
//add cocomment's enabler.js to the site |
| 54 |
pagetitle : '{$node_title}', |
$item['cocomment'] = array( |
| 55 |
|
'#value' => '<script type="text/javascript" id="cocomment-fetchlet" src="http://www.cocomment.com/js/enabler.js"></script>', |
| 56 |
EOS; |
); |
|
if (isset($form['author']['#value'])) { |
|
|
$item['#prefix'] .= " author : '{$form['author']['#value']}',\n"; |
|
|
} |
|
|
else { |
|
|
$item['#prefix'] .= " authorID : 'edit[name]',\n"; |
|
|
} |
|
|
$item['#prefix'] .= <<<EOS |
|
|
formID : 'comment_form', |
|
|
textareaID : 'edit[comment]', |
|
|
buttonID : 'op_submit' |
|
|
} |
|
|
</script><script |
|
|
type="text/javascript" id="cocomment-fetchlet" |
|
|
src="http://www.cocomment.com/js/enabler.js"></script> |
|
|
EOS; |
|
| 57 |
|
|
| 58 |
return $item; |
return $item; |
| 59 |
} |
} |