'); echo('
'); echo('
'); echo(' '); echo('

'); echo('

About Twixt

'); echo('
'); echo('
'); echo(''); } function renderTwixtPage($msg) { $PRE_MSG = 'Twixt Message

'; $POST_MSG_1 = '

'; $numchars = strlen($msg); $numtweets = ceil($numchars/140); $footer = 'This ' . $numchars . '-character message would have taken ' . $numtweets . ' tweets!
Your sanity was restored by Twixt.'; $nextfile = getNextNumber() . ".htm"; $file = fopen($nextfile, 'w'); fwrite($file, $PRE_MSG); fwrite($file, parseLinks(sanitise(substr($msg,0,10000)))); fwrite($file, $POST_MSG_1); fwrite($file, $footer); fwrite($file, $POST_MSG_2); fclose($file); return $nextfile; } function shortenURL($url) { header('Location: http://is.gd/create.php?longurl=' . substr(curPageURL(), 0, strrpos(curPageURL(),"/")+1) . $url ); die(); } function apiShortenURL($url) { header('Location: http://is.gd/api.php?longurl=' . substr(curPageURL(), 0, strrpos(curPageURL(),"/")+1) . $url ); die(); } function getNextNumber() { $dir = opendir('.'); $max = 0; while($file = readdir($dir)) { if($file != '.' && $file != '..') { if (preg_match("/^\d*/", $file, $matches)) { if ($matches[0] > $max) { $max = $matches[0]; } } } } closedir($dir); return $max+1; } function sanitise($string) { $pattern[0] = '/\&/'; $pattern[1] = '//"; $pattern[3] = '/\n/'; $pattern[4] = '/"/'; $pattern[5] = "/'/"; $pattern[6] = "/%/"; $pattern[7] = '/\(/'; $pattern[8] = '/\)/'; $pattern[9] = '/\+/'; $pattern[10] = '/-/'; $replacement[0] = '&'; $replacement[1] = '<'; $replacement[2] = '>'; $replacement[3] = '
'; $replacement[4] = '"'; $replacement[5] = '''; $replacement[6] = '%'; $replacement[7] = '('; $replacement[8] = ')'; $replacement[9] = '+'; $replacement[10] = '-'; return preg_replace($pattern, $replacement, $string); } // Parses the tweet text, and links up URLs, @names and #tags. function parseLinks($html) { $html = preg_replace('/\\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i', "[link]", $html); $html = preg_replace('/^d\s(\w+)/', 'd \1', $html); $html = preg_replace('/(^|\s)@(\w+)/', '\1@\2', $html); $html = preg_replace('/(^|\s)#(\w+)/', '\1#\2', $html); return $html; } function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } ?>