Created
January 17, 2014 22:30
-
-
Save naeluh/8482861 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<!-- | |
Strongly Typed 1.1 by HTML5 UP | |
html5up.net | @n33co | |
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license) | |
--> | |
<html> | |
<head> | |
<title></title> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | |
<meta name="description" content="" /> | |
<meta name="keywords" content="" /> | |
<meta name="viewport" content="width=1040" /> | |
<link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600|Arvo:700" rel="stylesheet" type="text/css" /> | |
</head> | |
<body class="homepage"> | |
<!-- Main Wrapper --> | |
<div id="main-wrapper"> | |
<!-- Main --> | |
<div id="main" class="container"> | |
<div class="row"> | |
<!-- Content --> | |
<div id="content" class="8u"> | |
<!-- Post --> | |
<article class="is-post"> | |
<div class="content"> | |
<form action="" accept-charset="UTF-8" method="post" id="comment-form"> | |
<div> | |
<div class="form-item" id="edit-name-wrapper"> | |
<label for="edit-name">Your name: <span class="form-required" title="This field is required.">*</span></label> | |
<input type="text" maxlength="60" name="name" id="edit-name" size="30" value="Anonymous" class="form-text required comment-processed"> | |
</div> | |
<div class="form-item" id="edit-mail-wrapper"> | |
<label for="edit-mail">E-mail: <span class="form-required" title="This field is required.">*</span></label> | |
<input type="text" maxlength="64" name="mail" id="edit-mail" size="30" value="" class="form-text required comment-processed"> | |
<div class="description">The content of this field is kept private and will not be shown publicly.</div> | |
</div> | |
<div class="form-item" id="edit-homepage-wrapper"> | |
<label for="edit-homepage">Homepage: </label> | |
<input type="text" maxlength="255" name="homepage" id="edit-homepage" size="30" value="" class="form-text"> | |
</div> | |
<div class="form-item" id="edit-subject-wrapper"> | |
<label for="edit-subject">Subject: </label> | |
<input type="text" maxlength="64" name="subject" id="edit-subject" size="60" value="" class="form-text"> | |
</div> | |
<div class="form-item" id="edit-comment-wrapper"> | |
<label for="edit-comment">Comment: <span class="form-required" title="This field is required.">*</span></label> | |
<div class="resizable-textarea"> | |
<span> | |
<textarea cols="60" rows="15" name="comment" id="edit-comment" class="form-textarea resizable required textarea-processed"></textarea> | |
<div class="grippie" style="margin-right: 488px;"></div> | |
</span> | |
</div> | |
</div> | |
<?php | |
require ('mollom.class.inc'); | |
class MollomMyPlatform extends Mollom { | |
public function loadConfiguration($name) { | |
// You may also hard-code your settings like this: | |
$config = array( | |
'publicKey' => 'placekeyhere', | |
'privateKey' => 'placekeyhere', | |
); | |
return $config[$name]; | |
} | |
public function saveConfiguration($name, $value) {} | |
public function deleteConfiguration($name) {} | |
public function getClientInformation() { | |
$data = array( | |
// Only supply different platform values, if your client maps to a | |
// public platform/application that may be used by others. | |
// Examples: Drupal 7.x, Wordpress 3.6, etc. | |
'platformName' => 'PHP', | |
'platformVersion' => PHP_VERSION, | |
// Always specify your implementation values here: | |
'clientName' => 'Mollom PHP client example', | |
'clientVersion' => '1.0', | |
); | |
return $data; | |
} | |
protected function request($method, $server, $path, $query = NULL, array $headers = array()) { | |
$ch = curl_init(); | |
// CURLOPT_HTTPHEADER expects all headers as values: | |
// @see http://php.net/manual/function.curl-setopt.php | |
foreach ($headers as $name => &$value) { | |
$value = $name . ': ' . $value; | |
} | |
// Compose the Mollom endpoint URL. | |
$url = $server . '/' . $path; | |
if (isset($query) && $method == 'GET') { | |
$url .= '?' . $query; | |
} | |
curl_setopt($ch, CURLOPT_URL, $url); | |
// Send OAuth + other request headers. | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
// Prevent API calls from taking too long. | |
// Under normal operations, API calls may time out for Mollom users without | |
// a paid subscription. | |
curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); | |
if ($method == 'POST') { | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); | |
} | |
else { | |
curl_setopt($ch, CURLOPT_HTTPGET, TRUE); | |
} | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
//curl_setopt($ch, CURLOPT_VERBOSE, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, TRUE); | |
// Execute the HTTP request. | |
if ($raw_response = curl_exec($ch)) { | |
// Split the response headers from the response body. | |
list($raw_response_headers, $response_body) = explode("\r\n\r\n", $raw_response, 2); | |
// Parse HTTP response headers. | |
// @see http_parse_headers() | |
$raw_response_headers = str_replace("\r", '', $raw_response_headers); | |
$raw_response_headers = explode("\n", $raw_response_headers); | |
$message = array_shift($raw_response_headers); | |
$response_headers = array(); | |
foreach ($raw_response_headers as $line) { | |
list($name, $value) = explode(': ', $line, 2); | |
// Mollom::handleRequest() expects response header names in lowercase. | |
$response_headers[strtolower($name)] = $value; | |
} | |
$info = curl_getinfo($ch); | |
$response = array( | |
'code' => $info['http_code'], | |
'message' => $message, | |
'headers' => $response_headers, | |
'body' => $response_body, | |
); | |
} | |
else { | |
$response = array( | |
'code' => curl_errno($ch), | |
'message' => curl_error($ch), | |
); | |
} | |
curl_close($ch); | |
$response = (object) $response; | |
return $response; | |
} | |
} | |
// When a comment is submitted: | |
$mollom = new MollomMyPlatform(); | |
//THIS IS THE FIELDS YOU ARE CHECKING AND WHICH BECOMES THE ARRAY $result | |
$comment = $_POST['comment']; | |
$result = $mollom->checkContent(array( | |
'checks' => array('spam'), | |
'postTitle' => $comment['title'], | |
'postBody' => $comment['body'], | |
'authorName' => $comment['name'], | |
'authorUrl' => $comment['homepage'], | |
'authorIp' => $_SERVER['REMOTE_ADDR'], | |
'authorId' => $userid, // If the author is logged in. | |
)); | |
// You might want to make the fallback case configurable: | |
if (!is_array($result) || !isset($result['id'])) { | |
print "The content moderation system is currently unavailable. Please try again later."; | |
die(); | |
} | |
// Check the final spam classification. | |
switch ($result['spamClassification']) { | |
case 'ham': | |
// Do nothing. (Accept content.) | |
break; | |
case 'spam': | |
// Discard (block) the form submission. | |
print "Your submission has triggered the spam filter and will not be accepted."; | |
die(); | |
break; | |
case 'unsure': | |
// Require to solve a CAPTCHA to get the post submitted. | |
$captcha = $mollom->createCaptcha(array( | |
'contentId' => $result['id'], | |
'type' => 'image', | |
)); | |
if (!is_array($captcha) || !isset($captcha['id'])) { | |
print "The content moderation system is currently unavailable. Please try again later."; | |
die(); | |
} | |
// Output the CAPTCHA. | |
print '<img src="' . $captcha['url'] . '" alt="Type the characters you see in this picture." />'; | |
print '<input type="text" name="captcha" size="10" value="" autocomplete="off" />'; | |
// Re-inject the submitted form values, re-render the form, | |
// and ask the user to solve the CAPTCHA. | |
break; | |
default: | |
// If we end up here, Mollom responded with a unknown spamClassification. | |
// Normally, this should not happen. | |
break; | |
} | |
?> | |
<input type="submit" name="op" id="edit-submit" value="Save" class="form-submit"> | |
</div> | |
</form> | |
</div> | |
</article> | |
<!-- Post --> | |
<article class="is-post"> | |
</article> | |
</div> | |
<!-- Sidebar --> | |
<div id="sidebar" class="4u"> | |
<!-- Excerpts --> | |
<section> | |
<ul class="divided"> | |
<li> | |
<!-- Excerpt --> | |
<article class="is-excerpt"> | |
</article> | |
</li> | |
<li> | |
<!-- Excerpt --> | |
<article class="is-excerpt"> | |
</article> | |
</li> | |
<li> | |
<!-- Excerpt --> | |
<article class="is-excerpt"> | |
</article> | |
</li> | |
</ul> | |
</section> | |
<!-- Highlights --> | |
<section> | |
<ul class="divided"> | |
<li> | |
<!-- Highlight --> | |
<article class="is-highlight"> | |
</article> | |
</li> | |
<li> | |
<!-- Highlight --> | |
<article class="is-highlight"> | |
</article> | |
</li> | |
</ul> | |
</section> | |
</div> | |
</div> | |
</div> | |
</div> | |
<!-- Copyright --> | |
<div id="copyright" class="container"> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment