redirect to archive

Discussion corner for Developers of Serendipity.
Post Reply
b33blebr0x

redirect to archive

Post by b33blebr0x »

hi!

I hacked a little script which i called serendipity_redirector.php. It redirects the user to the article using the article's ID. You just have to pass the ID to the script via GET. The script has to be located in the same folder as index.php. Simply call

serendipity_redirector.php?id=1

and it will forward you to the archive and show the specified article. This script is useful if you want a link to the original serendipity software, but do not know how to make a valid archive uri out of the entry data.

Code: Select all

<?php

/**
 * Serendipity redirector
 *
 * This script uses the serendipity built-in functions to
 * invoke a redirect to the article in the serendipity archive using
 * only the ID of that article.
 * Since Serendipity uses an entry's ID and its title to
 * build an archive uri to the original weblog entry, it is difficult
 * to link to an entry, if you just have the raw data and do not
 * exactly know how the uri is made.
 *
 * @package serendipity
 * @author Lars Tiedemann <php@larstiedemann.de>
 * @version 0.1
 * @since Tested with Serendipity 0.8.2
 *
 */

include_once('serendipity_config.inc.php');
include_once('include/functions.inc.php');
include_once('include/functions_entries.inc.php');

if (!isset($_GET['id'])) die("ID not set. ");
$_GET['id'] = (int) $_GET['id'];
if (!is_int($_GET['id']) or $_GET['id'] <= 0) die("ID is not a valid number. ");

$result = serendipity_fetchEntry("id", $_GET['id']);

$new_url = serendipity_archiveURL($_GET['id'], $result['title']);
//echo '<a href="'.$new_url.'">'.$new_url.'</a>';
header("location : ".$new_url);

?>
Post Reply