1. Go to this page and download the library: Download kodhe/trackback library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kodhe / trackback example snippets
declare(strict_types=1);
use Kodhe\Framework\Trackback\Trackback;
$tb = new Trackback();
$success = $tb->send([
'url' => 'https://blog-saya.com/tulisan/baru', // URL tulisan kita
'title' => 'Judul Tulisan',
'excerpt' => 'Ringkasan singkat tulisan...',
'blog_name' => 'Blog Saya',
'ping_url' => 'https://blog-lain/trackback/123', // satu atau array
'charset' => 'UTF-8', // opsional
]);
if ($success === false) {
echo $tb->error_string ?? ''; // properti error gaya CI3
}
$tb->send([
'url' => 'https://blog-saya.com/post/1',
'title' => 'Post 1',
'excerpt' => 'Cuplikan...',
'blog_name' => 'Blog Saya',
'ping_url' => ['https://a.com/tb/1', 'https://b.com/tb/2'],
]);
// send() mengembalikan FALSE bila salah satu ping gagal; tiap URL divalidasi
// oleh extract_urls()/validate_url() sebelum dikirim.
if ($tb->receive()) {
$data = $tb->data('title'); // field tunggal
// simpan $tb->data(...) ke DB, lalu balas sukses:
$tb->send_success(); // <response><flerror>false</flerror></response>
} else {
$tb->send_error('Incomplete Information'); // balas error (XML ke output)
}
use Kodhe\Framework\Trackback\Support\TrackbackConfig;
$config = $tb->getConfig();
$config->setTimeout(5); // default 10 detik
$config->setExcerptLength(250); // default 500 karakter
$config->setCharset('ISO-8859-1'); // default UTF-8
$tb->setConfig($config);
use Kodhe\Framework\Trackback\Client\TrackbackClient;
use Kodhe\Framework\Trackback\ValueObjects\TrackbackRequest;
$request = TrackbackRequest::fromArray([
'url' => 'https://blog-saya.com/post/1',
'title' => 'Judul', 'excerpt' => '...', 'blog_name' => 'Blog',
'ping_url' => 'https://target/tb',
]);
$client = new TrackbackClient();
$result = $client->send($request); // bool / exception dari Exceptions\*