Homepage | Documentation | Download



PHP Trackback

[ Expand All  |  Collapse All  |  Properties (8)  |  Methods (9) ]


trackback_cls.php

Properties implemented by Trackback
public method author

Default author name used throughout the class (ie. Ran Aroussi)

public method blog_name

Default blog name used throughout the class (ie. BLOGish)

public method encoding

Default encoding used throughout the class (ie. UTF-8)

public method expert

Retreives and holds $_POST['expert'] (if not empty)

public method get_id

Retreives and holds $_GET['id'] (if not empty)

public method post_id

Retreives and holds $_POST['id'] (if not empty)

public method title

Retreives and holds $_POST['title'] (if not empty)

public method url

Retreives and holds $_POST['url'] (if not empty)

 

Methods implemented by Trackback
public method auto_discovery

PHParray auto_discovery(string $text)

Search text for links, and searches links for trackback URLs.

<?php
include('trackback_cls.php');
$trackback = new Trackback('BLOGish', 'Ran Aroussi', 'UTF-8');
if ($tb_array = $trackback->auto_discovery(string TEXT)) {
	// Found trackbacks in TEXT. Looping...
	foreach($tb_array as $tb_key => $tb_url) {
	// Attempt to ping each one...
		if ($trackback->ping($tb_url, string URL, [string TITLE], [string EXPERT])) {
			// Successful ping...
			echo "Trackback sent to <i>$tb_url</i>...\n";
		} else {
			// Error pinging...
			echo "Trackback to <i>$tb_url</i> failed....\n";
		}
	}
} else {
	// No trackbacks in TEXT...
	echo "No trackbacks were auto-discover...\n"
}
?>

Arguments

  • $text

Return

Trackback URLs.

public method cut_short

PHPstring cut_short(string $string, integer $max_length)

Cuts a string short (with "...") accroding to $max_length...

Arguments

  • $string

  • $max_length [optional, default value = 255]

public method fetch

PHPstring fetch(boolean $success, string $response)

Feteched trackback information and produces an RSS-0.91 feed.

<?php
// 1
header('Content-Type: text/xml'); // MUST be the 1st line
// 2
include('trackback_cls.php');
$trackback = new Trackback('BLOGish', 'Ran Aroussi', 'UTF-8');
// 3
$tb_id = $trackback->get_id;
// 4
Do whatever to get trackback information by ID (search db, etc...)
if (GOT_TRACKBACK_INFO) {
	// Successful - pass trackback info as array()...
	$tb_info = array('title' => string TRACKBACK_TITLE, 
			'expert'	=> string TRACKBACK_EXPERT,
			'permalink' => string PERMALINK_URL,
			'trackback' => string TRACKBACK_URL
		);
	echo $trackback->fetch(true, $tb_info);
} else {
	// Something went wrong - tell my why...
	echo $trackback->fetch(false, string RESPONSE);
}
?>

Arguments

  • $success [optional, default value = false]

  • $response [optional, default value = ""]

Return

XML response to the caller

public method ping

PHPboolean ping(string $tb, string $url, string $title, string $excerpt)

Sends a trackback ping to a specified trackback URL. allowing clients to auto-discover the TrackBack Ping URL.

<?php
include('trackback_cls.php');
$trackback = new Trackback('BLOGish', 'Ran Aroussi', 'UTF-8');
if ($trackback->ping('http://tracked-blog.com', 'http://your-url.com', 'Your entry title')) {
	echo "Trackback sent successfully...";
} else {
	echo "Error sending trackback....";
}
?>

Arguments

  • $tb

  • $url

  • $title [optional, default value = ""]

  • $excerpt [optional, default value = ""]

public method rdf_autodiscover

PHPstring rdf_autodiscover(string $RFC822_date, string $title, string $expert, string $permalink, string $trackback, string $author)

Produces embedded RDF representing metadata about the entry, allowing clients to auto-discover the TrackBack Ping URL.

NOTE: DATE should be string in RFC822 Format - Use RFC822_from_datetime().

<?php
include('trackback_cls.php');
$trackback = new Trackback('BLOGish', 'Ran Aroussi', 'UTF-8');
echo $trackback->rdf_autodiscover(string DATE, string TITLE, string EXPERT, string PERMALINK, string TRACKBACK [, string AUTHOR]);
?>

Arguments

  • $RFC822_date

  • $title

  • $expert

  • $permalink

  • $trackback

  • $author [optional, default value = ""]

public method recieve

PHPboolean recieve(boolean $success, string $err_response)

Produces XML response for trackbackers with ok/error message.

<?php
// Set page header to XML
header('Content-Type: text/xml'); // MUST be the 1st line
//
// Instantiate the class
//
include('trackback_cls.php');
$trackback = new Trackback('BLOGish', 'Ran Aroussi', 'UTF-8');
//
// Get trackback information
//
$tb_id = $trackback->post_id; // The id of the item being trackbacked
$tb_url = $trackback->url; // The URL from which we got the trackback
$tb_title = $trackback->title; // Subject/title send by trackback
$tb_expert = $trackback->expert; // Short text send by trackback
//  
// Do whatever to log the trackback (save in DB, flatfile, etc...)
//
if (TRACKBACK_LOGGED_SUCCESSFULLY) {
	// Logged successfully...
	echo $trackback->recieve(true);
} else {
	// Something went wrong...
	echo $trackback->recieve(false, 'Explain why you return error');
}
?>

Arguments

  • $success [optional, default value = false]

  • $err_response [optional, default value = ""]

public method RFC822_from_datetime

PHPstring RFC822_from_datetime(string $datetime)

Other Useful functions used in this class

Converts MySQL datetime to a standart RFC 822 date format

Arguments

  • $datetime

Return

RFC 822 date

constructor Trackback   [Constructor]

PHPTrackback(string $blog_name, string $author, string $encoding)

Class Constructure

Arguments

  • $blog_name

  • $author

  • $encoding [optional, default value = "UTF-8"]

public method xml_safe

PHPstring xml_safe(string $string)

Converts a string into an XML-safe string (replaces &, <, >, " and ')

Arguments

  • $string

 


PHP Trackback by Ran Aroussi.
A simple, portable PHP class with full TrackBack capabilites.

Documentation generated by PHPEdit - Copyright © 1999-2003 Sébastien Hordeaux


SourceForge.net Logo