PASTEBIN
| #1 paste tool since 2002
create new paste
tools
api
archive
faq
PASTEBIN
create new paste
trending pastes
sign up
login
my alerts
my settings
my profile
Don't like ads?
PRO users
don't see any ads ;-)
Public Pastes
Untitled
1 sec ago
Untitled
1 sec ago
Untitled
3 sec ago
Untitled
6 sec ago
Untitled
7 sec ago
Untitled
7 sec ago
Untitled
9 sec ago
Untitled
13 sec ago
New Paste
<?php /** * Gravitywell * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Gravitywell * @package Gravitywell_Service * @subpackage TypePadAntiSpam * @license http://framework.zend.com/license/new-bsd New BSD License * @version $Id: TypePadAntiSpam.php 176 2009-10-26 11:09:05Z stuart $ */ /** * @see Zend_Version */ require_once 'Zend/Version.php'; /** * @see Zend_Service_Abstract */ require_once 'Zend/Service/Abstract.php'; /** * TypePadAntiSpam Anti Spam REST service implementation * * @uses Zend_Service_Abstract * @category Gravitywell * @package Zend_Service * @subpackage TypePadAntiSpam * @license http://framework.zend.com/license/new-bsd New BSD License */ class Gravitywell_Service_TypePadAntiSpam extends Zend_Service_Abstract { /** * TypePAd API key * @var string */ protected $_apiKey; /** * Blog URL * @var string */ protected $_blogUrl; /** * Charset used for encoding * @var string */ protected $_charset = 'UTF-8'; /** * TCP/IP port to use in requests * @var int */ protected $_port = 80; /** * User Agent string to send in requests * @var string */ protected $_userAgent; /** * Constructor * * @param string $apiKey TypePad API key * @param string $blog Blog URL * @return void */ public function __construct($apiKey, $blog) { $this->setBlogUrl($blog) ->setApiKey($apiKey) ->setUserAgent('Zend Framework/' . Zend_Version::VERSION . ' | TypePadAntiSpam/1.11'); } /** * Retrieve blog URL * * @return string */ public function getBlogUrl() { return $this->_blogUrl; } /** * Set blog URL * * @param string $blogUrl * @return Zend_Service_TypePadAntiSpam * @throws Zend_Service_Exception if invalid URL provided */ public function setBlogUrl($blogUrl) { require_once 'Zend/Uri.php'; if (!Zend_Uri::check($blogUrl)) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Invalid url provided for blog'); } $this->_blogUrl = $blogUrl; return $this; } /** * Retrieve API key * * @return string */ public function getApiKey() { return $this->_apiKey; } /** * Set API key * * @param string $apiKey * @return Zend_Service_TypePadAntiSpam */ public function setApiKey($apiKey) { $this->_apiKey = $apiKey; return $this; } /** * Retrieve charset * * @return string */ public function getCharset() { return $this->_charset; } /** * Set charset * * @param string $charset * @return Zend_Service_TypePadAntiSpam */ public function setCharset($charset) { $this->_charset = $charset; return $this; } /** * Retrieve TCP/IP port * * @return int */ public function getPort() { return $this->_port; } /** * Set TCP/IP port * * @param int $port * @return Zend_Service_TypePadAntiSpam * @throws Zend_Service_Exception if non-integer value provided */ public function setPort($port) { if (!is_int($port)) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Invalid port'); } $this->_port = $port; return $this; } /** * Retrieve User Agent string * * @return string */ public function getUserAgent() { return $this->_userAgent; } /** * Set User Agent * * Should be of form "Some user agent/version | TypePadAntiSpam/version" * * @param string $userAgent * @return Zend_Service_TypePadAntiSpam * @throws Zend_Service_Exception with invalid user agent string */ public function setUserAgent($userAgent) { if (!is_string($userAgent) || !preg_match(":^[^\n/]*/[^ ]* \| TypePadAntiSpam/[0-9\.]*$:i", $userAgent)) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Invalid User Agent string; must be of format "Application name/version | TypePadAntiSpam/version"'); } $this->_userAgent = $userAgent; return $this; } /** * Post a request * * @param string $host * @param string $path * @param array $params * @return mixed */ protected function _post($host, $path, array $params) { $uri = 'http://' . $host . ':' . $this->getPort() . $path; $client = self::getHttpClient(); $client->setUri($uri); $client->setConfig(array( 'useragent' => $this->getUserAgent(), )); $client->setHeaders(array( 'Host' => $host, 'Content-Type' => 'application/x-www-form-urlencoded; charset=' . $this->getCharset() )); $client->setParameterPost($params); $client->setMethod(Zend_Http_Client::POST); return $client->request(); } /** * Verify an API key * * @param string $key Optional; API key to verify * @param string $blog Optional; blog URL against which to verify key * @return boolean */ public function verifyKey($key = null, $blog = null) { if (null === $key) { $key = $this->getApiKey(); } if (null === $blog) { $blog = $this->getBlogUrl(); } $response = $this->_post('api.antispam.typepad.com', '/1.1/verify-key', array( 'key' => $key, 'blog' => $blog )); return ('valid' == $response->getBody()); } /** * Perform an API call * * @param string $path * @param array $params * @return Zend_Http_Response * @throws Zend_Service_Exception if missing user_ip or user_agent fields */ protected function _makeApiCall($path, $params) { if (empty($params['user_ip']) || empty($params['user_agent'])) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Missing required TypePadAntiSpam fields (user_ip and user_agent are required)'); } if (!isset($params['blog'])) { $params['blog'] = $this->getBlogUrl(); } return $this->_post($this->getApiKey() . '.api.antispam.typepad.com', $path, $params); } /** * Check a comment for spam * * Checks a comment to see if it is spam. $params should be an associative * array with one or more of the following keys (unless noted, all keys are * optional): * - blog: URL of the blog. If not provided, uses value returned by {@link getBlogUrl()} * - user_ip (required): IP address of comment submitter * - user_agent (required): User Agent used by comment submitter * - referrer: contents of HTTP_REFERER header * - permalink: location of the entry to which the comment was submitted * - comment_type: typically, one of 'blank', 'comment', 'trackback', or 'pingback', but may be any value * - comment_author: name submitted with the content * - comment_author_email: email submitted with the content * - comment_author_url: URL submitted with the content * - comment_content: actual content * * Additionally, TypePadAntiSpam suggests returning the key/value pairs in the * $_SERVER array, and these may be included in the $params. * * This method implements the TypePadAntiSpam comment-check REST method. * * @param array $params * @return boolean * @throws Zend_Service_Exception with invalid API key */ public function isSpam($params) { $response = $this->_makeApiCall('/1.1/comment-check', $params); $return = trim($response->getBody()); if ('invalid' == $return) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Invalid API key'); } if ('true' == $return) { return true; } return false; } /** * Submit spam * * Takes the same arguments as {@link isSpam()}. * * Submits known spam content to TypePadAntiSpam to help train it. * * This method implements TypePadAntiSpam's submit-spam REST method. * * @param array $params * @return void * @throws Zend_Service_Exception with invalid API key */ public function submitSpam($params) { $response = $this->_makeApiCall('/1.1/submit-spam', $params); $value = trim($response->getBody()); if ('invalid' == $value) { require_once 'Zend/Service/Exception.php'; throw new Zend_Service_Exception('Invalid API key'); } } /** * Submit ham * * Takes the same arguments as {@link isSpam()}. * * Submits a comment that has been falsely categorized as spam by TypePadAntiSpam * as a false positive, telling TypePadAntiSpam's filters not to filter such * comments as spam in the future. * * Unlike {@link submitSpam()} and {@link isSpam()}, a valid API key is * never necessary; as a result, this method never throws an exception * (unless an exception happens with the HTTP client layer). * * this method implements TypePadAntiSpam's submit-ham REST method. * * @param array $params * @return void */ public function submitHam($params) { $response = $this->_makeApiCall('/1.1/submit-ham', $params); } }
Optional Paste Settings
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
HTML 5
Java
JavaScript
Lua
None
Objective C
Perl
PHP
Python
Rails
-------------
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
ActionScript
ActionScript 3
Ada
ALGOL 68
Apache Log
AppleScript
APT Sources
ARM
ASM (NASM)
ASP
Asymptote
autoconf
Autohotkey
AutoIt
Avisynth
Awk
BASCOM AVR
Bash
Basic4GL
BibTeX
Blitz Basic
BNF
BOO
BrainFuck
C
C for Macs
C Intermediate Language
C#
C++
C++ (with QT extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
ChaiScript
Clojure
Clone C
Clone C++
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
DCL
DCPU-16
DCS
Delphi
Delphi Prism (Oxygene)
Diff
DIV
DOS
DOT
E
ECMAScript
Eiffel
Email
EPC
Erlang
F#
Falcon
FO Language
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
Game Maker
GDB
Genero
Genie
GetText
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9 Plus
HTML
HTML 5
Icon
IDL
INI file
Inno Script
INTERCAL
IO
J
Java
Java 5
JavaScript
jQuery
KiXtart
Latex
LDIF
Liberty BASIC
Linden Scripting
Lisp
LLVM
Loco Basic
Logtalk
LOL Code
Lotus Formulas
Lotus Script
LScript
Lua
M68000 Assembler
MagikSF
Make
MapBasic
MatLab
mIRC
MIX Assembler
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MPASM
MXML
MySQL
Nagios
newLISP
None
NullSoft Installer
Oberon 2
Objeck Programming Langua
Objective C
OCalm Brief
OCaml
Octave
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
ParaSail
PARI/GP
Pascal
PAWN
PCRE
Per
Perl
Perl 6
PHP
PHP Brief
Pic 16
Pike
Pixel Bender
PL/SQL
PostgreSQL
POV-Ray
Power Shell
PowerBuilder
ProFTPd
Progress
Prolog
Properties
ProvideX
PureBasic
PyCon
Python
Python for S60
q/kdb+
QBasic
R
Rails
REBOL
REG
Rexx
Robots
RPM Spec
Ruby
Ruby Gnuplot
SAS
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term
thinBasic
TypoScript
Unicon
UnrealScript
UPC
Urbi
Vala
VB.NET
Vedit
VeriLog
VHDL
VIM
Visual Pro Log
VisualBasic
VisualFoxPro
WhiteSpace
WHOIS
Winbatch
XBasic
XML
Xorg Config
XPP
YAML
Z80 Assembler
ZXBasic
Paste Expiration:
Never
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
Paste Exposure:
Public
Unlisted
Private (members only)
Paste Name / Title:
Hello
Guest
Sign Up
or
Login
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login