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 '
'; highlight_file(__FILE__); echo '
'; } else { header('Content-Type: text/plain; charset=UTF-8'); readfile(__FILE__); } die(); } function redirect($sninstance, $status) { if ($db = new SQLite3('knownsn.db')) { $qry = sprintf('SELECT url FROM statusnet where id = %d ', $sninstance); $result = @$db->querySingle($qry); if($result) { $updHit = sprintf('UPDATE statusnet SET hits = hits+1 WHERE id = %d ', $sninstance); @$db->exec($updHit); $link = $result.'/notice/new?status_textarea='.urlencode($status); header('HTTP/1.1 303 See Other'); header("Location: $link"); setcookie('share2sn',$sninstance,time()+60*60*24*30*12*5); die(); } else { $msgerror= "Failed to fetch statusnet URL for id ". $sninstance; } } return false; } ?> share to statusnet

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 "
'; echo '
'; echo '

Sharing

' . $title . " " . $url . '
'; echo '

Add new StatusNet instance

'; if(!empty($msgerror)) { echo '

'.$msgerror.'

'; } echo '
'; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; } else { echo('

Failed to open db

'); } } ?>