osc_item_url() would be perfect if it would accept an [optional] $id argument, but it only works for the currently selected item in a view template file. Instead I needed that to build a redirect table map to migrate an old site to the new site, in an external script.
old url --- redirect 301 ---> new url
To do this I cycled old ads based on another script and for each of them given the id of the new corresponding osclass item I needed to generate the new working url.
Another use was to do a random.php file in the osc root directory that would pick a random item and redirect to the item, per request of a client. Just for info I post how it came out (it works):
/random.php - if called
http://example.org/random.php it redirects to a random item
<?php
define('CLI', false);
require_once dirname( __FILE__ ) . '/oc-load.php';
ob_end_clean( );
$link = false;
$s = new Search;
$s->addItemConditions('1 = 1');
//$s->order('RAND()');
$s->order('','random');
$s->limit('0','1');
$items = $s->doSearch();
if( $items ) {
$link = osc_item_url_from_item( $items[0] );
}
if( $link ) {
header( 'Location: ' . $link );
exit;
} else {
echo 'Server Error';
exit;
}
?>