rendered paste body<?php
class RelocateComments extends Plugin
{
/**
* Return plugin metadata for this plugin
*
* @return array Plugin metadata
*/
public function info()
{
return array(
'link'=>'http://redalt.com',
'name'=>'Relocate Comments',
'license'=>'Apache License 2.0',
'author'=>'Owen Winkler',
'version'=>'1.0',
);
}
public function filter_rewrite_rules($rules)
{
$rules[] = new RewriteRule(array(
'name' => 'comment',
'parse_regex' => '/^(?P<id>([0-9]+))\/(?P<ccode>([0-9a-f]+))\/feedback[\/]{0,1}$/i',
'build_str' => '{$id}/{$ccode}/feedback',
'handler' => 'FeedbackHandler',
'action' => 'add_comment',
'priority' => 7,
'is_active' => 1,
));
return $rules;
}
public function filter_rewrite_args($args, $rulename)
{
switch($rulename) {
case 'comment':
$args['ccode'] = $this->get_code($args['id']);
setcookie('habari_rc[' . $args['ccode'] . ']', md5( Options::get('GUID') . 'other salt' . $args['id'] ), time()+60*60*2);
break;
}
return $args;
}
function filter_add_comment( $comment, $handlervars )
{
// This plugin ignores non-comments
if($comment->type != Comment::COMMENT) {
return $comment;
}
if(!$this->verify_code($handlervars['ccode'], $comment->post_id)) {
ob_end_clean();
header('HTTP/1.1 403 Forbidden');
die(_t('<h1>The selected action is forbidden.</h1>'));
}
if($_COOKIE['habari_rc'][$handlervars['ccode']] != md5( Options::get('GUID') . 'other salt' . $comment->post_id ) ) {
ob_end_clean();
header('HTTP/1.1 403 Forbidden');
die(_t('<h1>The selected action is forbidden.</h1>'));
}
return $comment;
}
/**
* Get a 10-digit hex code that identifies the user submitting the comment
* @param A post id to which the comment will be submitted
* @param The IP address of the commenter
* @return A 10-digit hex code
**/
public function get_code($post_id, $ip = '')
{
if( $ip == '' ) {
$ip = ip2long($_SERVER['REMOTE_ADDR']);
}
$code = substr(md5( $post_id . Options::get('GUID') . 'more salt' . $ip ), 0, 10);
$code = Plugins::filter('comment_code', $code, $post_id, $ip);
return $code;
}
/**
* Verify a 10-digit hex code that identifies the user submitting the comment
* @param A post id to which the comment has been submitted
* @param The IP address of the commenter
* @return True if the code is valid, false if not
**/
public function verify_code($suspect_code, $post_id, $ip = '')
{
if( $ip == '' ) {
$ip = ip2long($_SERVER['REMOTE_ADDR']);
}
$code = substr(md5( $post_id . Options::get('GUID') . 'more salt' . $ip ), 0, 10);
$code = Plugins::filter('comment_code', $code, $post_id, $ip);
return ($suspect_code == $code);
}
}
?>