array('http'=>'iso-8859-1', 'htmlentities'=>'ISO-8859-1'), '1251'=>array('http'=>'windows-1251', 'htmlentities'=>'cp1251') ); /** * Which character set to use? */ $charset='latin1'; /** * configure character set */ $CONF['htmlentity_encoding']=$charset_code[$charset]['htmlentities']; $CONF['http_charset']=$charset_code[$charset]['http']; set_time_limit(180); if (isset($_GET['maintain'])) { $CONF["maintainer_mode"]=1; } ////////////////////////////////////////////// // translation support /* create table original_phrase ( original_phrase_id int not null auto_increment, original text not null, used datetime not null, primary key(original_phrase_id), unique (original(128)) ); create table translated_phrase ( original_phrase_id int not null, lang char(2) not null, updated datetime not null, translated text, primary key(original_phrase_id,lang) ); */ function t($str) { //global $CONF; //if in maintainance mode, record this string in the translation db if ($CONF['maintainer_mode']) { $db=new DB; $db->_query("select * from original_phrase where original=?", $str); if ($db->_next_record()) { //update timestamp $original_phrase_id=$db->_f('original_phrase_id'); $db->_query("update original_phrase set used=now() where original_phrase_id=$original_phrase_id"); } else { //create new record $db->_query("insert into original_phrase(original,used) values (?, now())", $str); } } //if using english ui, just return the string //if a translation is available, use that //otherwise, use english return $str; } //html helpers using above translation system function h1($str) { echo '

'.t($str).'

'; } function p($str) { echo '

'.t($str).'

'; } function li($str) { echo '
  • '.t($str).'
  • '; } /////////////////////////////////////////////////////////////////////////////// // magic quotes are anything but magic - lose them! // if (get_magic_quotes_gpc()) { function callback_stripslashes(&$val, $name) { if (get_magic_quotes_gpc()) $val=stripslashes($val); } if (count($_GET)) array_walk ($_GET, 'callback_stripslashes'); if (count($_POST)) array_walk ($_POST, 'callback_stripslashes'); if (count($_COOKIE)) array_walk ($_COOKIE, 'callback_stripslashes'); } /////////////////////////////////////////////////////////////////////////////// // user submitted the "private pastebin" form? redirect them... // if ($_GET['goprivate']) { $sub=trim(strtolower($_GET['goprivate'])); if (preg_match('/^[a-z0-9][a-z0-9\.\-]*[a-z0-9]$/i', $sub)) { header("Location: http://{$sub}.pastebin.com"); exit; } } /////////////////////////////////////////////////////////////////////////////// // create our pastebin object // $pastebin=new Pastebin($CONF); /////////////////////////////////////////////////////////////////////////////// // process new posting // $errors=array(); if (isset($_POST['paste'])) { //process posting and redirect $id=$pastebin->doPost($_POST); if ($id) { $pastebin->redirectToPost($id); exit; } } /////////////////////////////////////////////////////////////////////////////// // process download // if (isset($_GET['dl'])) { $pid=$pastebin->cleanPostId($_GET['dl']); if (!$pastebin->doDownload($pid)) { //not fount echo "Pastebin entry $pid is not available"; } exit; } /////////////////////////////////////////////////////////////////////////////// // if we get this far, we're going to be displaying some HTML, so let's kick // off here... $page=array(); //figure out some nice defaults $page['current_format']=$CONF['default_highlighter']; $page['expiry']=$CONF['default_expiry']; $page['remember']=''; //see if we can come up with a better default using the subdomain if (strlen($CONF['subdomain']) && isset($CONF['all_syntax'][$CONF['subdomain']])) { //cool, domain is something like ruby.pastebin.com, so lets go with that //as a default $page['current_format']=$CONF['subdomain']; } //are we remembering the user? $cookie=$pastebin->extractCookie(); if ($cookie) { //initialise bits of page with cookie data $page['remember']='checked="checked"'; $page['current_format']=$cookie['last_format']; $page['poster']=$cookie['poster']; $page['expiry']=$cookie['last_expiry']; $page['token']=$cookie['token']; } //send feedback mail? if (isset($_POST['feedback']) && strlen($_POST['msg'])) { $matches=array(); $spam=false; //more than two links? preg_match_all('{http://}', $_POST['msg'], $matches); $spam=$spam || count($matches[0])>2; //[url=][/url] ? $spam=$spam || preg_match('{\[url=}i', $_POST['msg']); $spam=$spam || preg_match('{cleanPostId($_REQUEST['erase']); $post=$pastebin->getPost($pid); if (!empty($post['token']) && !empty($cookie['token']) && $post['token']==$cookie['token']) { $pastebin->deletePost($pid); $page['delete_message']=t('Your post has been deleted'); } else { $page['delete_message']=t('You cannot delete this post - contact us if you need further assistance'); $_REQUEST["show"]=$pid; } } //add list of recent posts $list=isset($_REQUEST["list"]) ? intval($_REQUEST["list"]) : 10; $page['recent']=$pastebin->getRecentPosts($list); /////////////////////////////////////////////////////////////////////////////// // show a post // if (isset($_REQUEST["show"])) { $pid=$pastebin->cleanPostId($_REQUEST['show']); //get the post $page['post']=$pastebin->getPost($pid); //ensure corrent format is selected $page['current_format']=$page['post']['format']; } else { $page['posttitle']='New Posting'; } //use configured title $page['title']= $CONF['title']; //on a subdomain, label it as private... if (strlen($CONF['subdomain'])) { $page['title']=$CONF['subdomain']. ' private pastebin - collaborative debugging tool'; } elseif ($page['current_format']!='text') { //give the page a title which features the syntax used.. $page['title']=$CONF['all_syntax'][$page['current_format']] . " ".$page['title']; } header("Content-Type: text/html; charset=".$CONF['http_charset']); /////////////////////////////////////////////////////////////////////////////// // HTML page output // include("layout.php"); // clean up older posts $pastebin->doGarbageCollection(); DB::dumpDiagnostics();