tedeh / pingback
Pingback client and server implementation
Installs: 90
Dependents: 0
Suggesters: 0
Security: 0
Stars: 27
Watchers: 1
Forks: 12
Open Issues: 1
pkg:composer/tedeh/pingback
Requires
- php: >=5.0.0
This package is not auto-updated.
Last update: 2025-04-12 15:11:33 UTC
README
Created and copyrighted by Tedde Lundgren and licensed under MIT.
Introduction
Pingbacks, quoting Wikipedia, are "one of three types of linkbacks, methods for Web authors to request notification when somebody links to one of their documents". More precisely, an explicitly defined procedure based on XML-RPC that enable web applications (typically blogs) to communicate about links.
This library was built to comply with the official pingback specification and supports both the sending and the reception of pingback requests.
Requirements
Requirements center around libraries commonly available in PHP5.
- PHP >= 5
- cURL (http://se.php.net/manual/en/book.curl.php)
- XML-RPC (http://se.php.net/manual/en/book.xmlrpc.php)
- Document Object Model (http://se.php.net/manual/en/book.dom.php)
Usage and notes on implementation
Overview
The library consists of three classes.
- Pingback_Server manages the server and composite validation of requests
- Pingback_Utility provides a set of static methods to aid the server and enable the client
- Pingback_Exception is the class that exceptions thrown by the library will be of
Pingback_Utility
Pingback_Utility contains the following static methods.
Pingback_Utility::isURL()
@param string $urlThe URL@return booleanWheter the URL is valid
Returns a boolean value determining wheter the first argument is a valid URL or not.
Pingback_Utility::isPingbackEnabled()
@param string $urlThe URL@return booleanWheter the URL is pingback enabled
Returns a boolean value determining wheter the first argument supports the reception of pingbacks.
Pingback_Utility::getRawPostData()
@return stringThe raw POST data
Reads the raw, unfiltered POST data and returns it
Pingback_Utility::getPingbackURL()
@param string @urlThe URL@return stringThe server address if found
Extracts the pingback URL from the first argument.
PingbackUtility::isBacklinking()
@param string $fromThe URL of the page@param string $toThe URL that should exist in atleast one link@return booleanWheter there is a link or not
Determines wheter the first argument is linking to the second.
PingbackUtility::sendPingback()
@param string $fromThe originator of the pingback@param string $toThe target of the pingback@param string $serverThe URL of the server@return stringThe raw response from the server
The client implementation. Takes three arguments. The first one is the source URL
(originator) of the pingback request, the second one is the target url,
and the third one is the url to the pingback server. Returns the raw server
response, which is easily parsed with xmlrpc_decode_request().
Pingback_Server
PingbackServer is an instantiable class representing a pingback server resource. The majority of requirements put upon a valid pingback request are automatically evaluated. However, two specific requirements have to be evaluated by additional, user-provided logic. These corresponding faults of these two requirements are:
- Pingback_Server::RESPONSE_FAULT_ALREADY_REGISTERED the pingback has already been registered
- Pingback_Server::RESPONSE_FAULT_ACCESS_DENIED access to the server resource has been denied
After execution of the bound request, the implementor may leverage Pingback_Server->setFault() to
ensure a proper response if all requirements of the request have not been met.
Pingback_Server->__construct()
@param array $optionsArray of options
Takes an array of options that will be automatically set. Creates the server instance and enabled the pingback method on it.
Pingback_Server->getOption()
@param string $optionOption to return@return mixedThe value or null if not exist
Returns an option.
Pingback_Server->setOption()
@param string $optionName of option@param mixed $valueValue to set
Takes an array of options.
Pingback_Server->setOptions()
@param array $optionsArray of options
Takes an array of options.
Pingback_Server->execute()
@param string $requestEvaluate this request
Evaluates the given request. If no argument is given, evaluates the set request.
Pingback_Server->setResponse()
@param string $responseThe response
Sets the response as a string.
Pingback_Server->setRequest()
@param string $requestThe request
Sets the request as a string.
Pingback_Server->getRequest()
@return stringThe request
Returns the request.
Pingback_Server->getResponse()
@return stringThe response
Returns the response.
Pingback_Server->getSourceURL()
@return stringThe source URL
Returns the source URL from the request.
Pingback_Server->getTargetURL()
@return stringThe target URL
Returns the target URL from the request.
Pingback_Server->getTargetURL()
@return booleanThe target URL
Returns the target URL from the request.
Pingback_Server->getFaultAsArray()
@param integer $faultCodeThe fault code@return arrayThe fault (code and string) formatted as an array
Returns the passed fault code as an array fit for the response.
Pingback_Server->setFault()
@param integer $faultCodeThe fault code to set
Sets the fault code of the request.
Pingback_Server->getSuccessAsArray()
@return arrayThe success array
Returns the success response as an array fit for the response.
Pingback_Server->setSuccess()
Marks the current request as successful.
Pingback_Server->isValid()
@return booleanThe request validity
Returns wheter or not the current request is considered valid.
Available options
The methods for setting options supports the following option names and values:
string 'encoding'encoding used by the server
Responses
Pingback_Server has a set of class constants that may be used with the
appropriate methods on a server instance. The actual messages returned by the server
can be manipulated by changing the strings in the Pingback_Server->responses array (where
the array keys correspond to the class constants).
- Pingback_Server::RESPONSE_FAULT_GENERIC Unknown error
- Pingback_Server::RESPONSE_FAULT_SOURCE Source link invalid
- Pingback_Server::RESPONSE_FAULT_SOURCE_LINK Source is not backlinking to target
- Pingback_Server::RESPONSE_FAULT_TARGET Target link invalid
- Pingback_Server::RESPONSE_FAULT_TARGET_INVALID Target is not pingback enabled
- Pingback_Server::RESPONSE_FAULT_ALREADY_REGISTERED Pingback already registered
- Pingback_Server::RESPONSE_FAULT_ACCESS_DENIED Access denied
- Pingback_Server::RESPONSE_SUCCESS Indicates success