querySingle($qry);
if(!$result) {
$ok = checkSN($snurl);
if(!$ok) {
$msgerror="Not a valid URL";
} else {
$updHit = sprintf("INSERT INTO statusnet (url,hits) VALUES ('%s',0)", $snurl);
@$db->exec($updHit);
$instanceid = $db->lastInsertRowID();
$status=$title . " " . $url;
redirect($instanceid,$status);
}
} else {
$status=$title . " " . $url;
redirect($result,$status);
}
}
}
} else {
$url= isset($_GET['url']) ? $_GET['url'] : '';
$title=isset($_GET['title']) ? $_GET['title'] : '';
if( (isset($_COOKIE['share2sn']) || isset($_GET['snid'])) && !empty($url) ) {
$instanceid = (isset($_GET['snid'])) ? $_GET['snid'] : $_COOKIE['share2sn'];
$status=$title . " " . $url;
$ret = redirect($instanceid,$status);
if(!$ret) {
$msgerror='Hum.. looks like I can\'t redirect..';
if(isset($_GET['clearcookie'])) {
setcookie('share2sn', "", time()-3600);
unset($_COOKIE['share2sn']);
}
}
}
if (isset($_GET['source'])) {
showSource(isset($_GET['highlight']));
}
if(isset($_GET['clearcookie'])) {
setcookie('share2sn', "", time()-3600);
unset($_COOKIE['share2sn']);
}
}
function checkSN($url) {
$ret = file_get_contents($url."/api/statusnet/version.json");
if (false === $ret) return false;
return json_decode($ret);
}
function showSource($highlight = false) {
if ($highlight) {
echo '
share to statusnet
Hi! To use this service, just call this page with 2 parameters: url (required) and title (optional)';
echo '
for example: Share this!';
if(isset($_COOKIE['share2sn'])) {
if ($db = new SQLite3('knownsn.db')) {
$qry = sprintf('SELECT url FROM statusnet where id = %d ', $_COOKIE['share2sn']);
$result = @$db->querySingle($qry);
if($result) {
echo '
You are actually sharing to ' . $result . ' reset it?
';
}
}
}
} else {
if ($db = new SQLite3('knownsn.db')) {
echo "
\n";
echo "
StatusNet instances
";
echo "
";
$q = @$db->query('SELECT id, url FROM statusnet order by hits desc');
if ($q === false) {
$db->exec('CREATE TABLE statusnet (id INTEGER PRIMARY KEY, url TEXT, hits INTEGER); INSERT INTO statusnet (id,url,hits) VALUES (1,\'http://identi.ca\',1000);');
echo '- identi.ca
' ;
} else {
while ($entry = $q->fetchArray()) {
echo '- '.$entry['url'].'
' ;
}
}
echo '
';
echo '
';
} else {
echo('
Failed to open db
');
}
}
?>