diff options
author | Eudyptula <eitan@mosenkis.net> | 2009-08-04 17:58:55 -0400 |
---|---|---|
committer | Eudyptula <eitan@mosenkis.net> | 2009-08-04 17:58:55 -0400 |
commit | d3da989d3e2d2cb03cdc4bd2e23783f716ef5035 (patch) | |
tree | 2f9f8c413d2800a3f72282dec0f86170a00ff4f6 /frontend | |
parent | Add visibility column to builds, configurations (diff) | |
download | ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.gz ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.tar.bz2 ingenue-d3da989d3e2d2cb03cdc4bd2e23783f716ef5035.zip |
Widespread cleanup - moved $conf, $death into $S; $S is given as arg to init_x() and body_x(); $request removed in favor of $_REQUEST; query() replaces $S[pdo]->query(); etc.
Diffstat (limited to 'frontend')
37 files changed, 195 insertions, 248 deletions
diff --git a/frontend/classes/forms.php b/frontend/classes/forms.php index 39843e9..daa95cf 100644 --- a/frontend/classes/forms.php +++ b/frontend/classes/forms.php @@ -10,8 +10,7 @@ abstract class form_element { echo "$this->label: "; } public function process() { - global $request; - return isset($request[$this->htmlname])?$request[$this->htmlname]:false; + return isset($_REQUEST[$this->htmlname])?$_REQUEST[$this->htmlname]:false; } public function verify($val) { return $val !== false; @@ -47,10 +46,9 @@ class select extends form_element { echo "<br/>\n"; } public function process() { - global $request; $vals=array_keys($this->options); - if (isset($request[$this->htmlname]) && is_numeric($request[$this->htmlname]) && isset($vals[$request[$this->htmlname]])) { - return $vals[$request[$this->htmlname]]; + if (isset($_REQUEST[$this->htmlname]) && is_numeric($_REQUEST[$this->htmlname]) && isset($vals[$_REQUEST[$this->htmlname]])) { + return $vals[$_REQUEST[$this->htmlname]]; } else return false; } public function verify($val) { @@ -90,11 +88,10 @@ class checkbox_array extends form_element { } } public function process() { - global $request; $val=array(); - if (isset($request[$this->htmlname])) { + if (isset($_REQUEST[$this->htmlname])) { $vals=array_keys($this->array); - foreach ($request[$this->htmlname] as $i => $null) { + foreach ($_REQUEST[$this->htmlname] as $i => $null) { $val[]=$vals[$i]; } } @@ -122,9 +119,9 @@ class checkbox_array extends form_element { class layered_checkbox_array extends checkbox_array { private $depth=0, $path_delims=array('', '/', '-'); function __construct($htmlname, $label, &$array, $delim=' ', $metadata) { - parent::__construct($htmlname, $label, &$array, $delim); + parent::__construct($htmlname, $label, $array, $delim); $this->metadata=$metadata; - for ($i=current(&$array); is_array($i); $i=current($i)) $this->depth++; + for ($i=current($array); is_array($i); $i=current($i)) $this->depth++; global $S; if (!in_array('lca', $S['scripts'])) { $S['scripts'][]='lca'; @@ -153,7 +150,7 @@ class layered_checkbox_array extends checkbox_array { } private function r_output(&$array, $depth=0, $path=null, $name=null) { static $uid=0, $ucid=0; - $conf=&$this->metadata[0]; + $S['conf']=&$this->metadata[0]; if ($depth == 0) { $search=$autosize=0; for ($i=1; $i<count($this->metadata); $i++) { @@ -166,18 +163,18 @@ class layered_checkbox_array extends checkbox_array { } } if ($search) { - if (!isset($conf['id'])) { - $conf['id']=self::b36($uid++); + if (!isset($S['conf']['id'])) { + $S['conf']['id']=self::b36($uid++); } - echo 'Search: <input id="'.$conf['id'].'-q" onkeyup="lca_search(this.value, document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$conf['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:lca_show_checked(document.getElementById(\''.$conf['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; + echo 'Search: <input id="'.$S['conf']['id'].'-q" onkeyup="lca_search(this.value, document.getElementById(\''.$S['conf']['id'].'\'), 0, '.$this->depth.')" /> <a href="javascript:q=document.getElementById(\''.$S['conf']['id'].'-q\'); q.value=\'\'; q.onkeyup()">Clear</a> <a href="javascript:lca_show_checked(document.getElementById(\''.$S['conf']['id'].'\'), 0, '.$this->depth.'); undefined">Show checked</a><br/>'."\n"; } - echo '<div class="lca'.(isset($conf['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$conf['id'].'">'."\n"; + echo '<div class="lca'.(isset($S['conf']['autosize'])?' autosize" style="font-size: '.pow(1.15, $autosize)*100.0.'%':'').'" id="'.$S['conf']['id'].'">'."\n"; foreach ($array as $name => &$val) { $this->r_output($val, $depth+1, $name, $name); $uid++; } echo '<h3 style="display: none">No results</h3></div>'; - echo "<script type=\"text/javascript\">\n<!--\nif (lca_show_checked(document.getElementById('{$conf['id']}'), 0, $this->depth) == 0) lca_search(document.getElementById('{$conf['id']}-q').value, document.getElementById('{$conf['id']}'), 0, $this->depth);\n-->\n</script>\n"; + echo "<script type=\"text/javascript\">\n<!--\nif (lca_show_checked(document.getElementById('{$S['conf']['id']}'), 0, $this->depth) == 0) lca_search(document.getElementById('{$S['conf']['id']}-q').value, document.getElementById('{$S['conf']['id']}'), 0, $this->depth);\n-->\n</script>\n"; } else { $meta=$this->metadata[$depth]; if (isset($meta['tag'])) { @@ -214,8 +211,7 @@ class layered_checkbox_array extends checkbox_array { } else { $meta=$this->metadata[$depth]; if (isset($meta['checkbox'])) { - global $request; - if (isset($request[$this->htmlname][self::b36($ucid)])) { + if (isset($_REQUEST[$this->htmlname][self::b36($ucid)])) { $r[]=$this->format_label($array, $meta['checkbox'], $path, $name); } $ucid++; diff --git a/frontend/classes/pdo.php b/frontend/classes/pdo.php deleted file mode 100644 index daf71ba..0000000 --- a/frontend/classes/pdo.php +++ /dev/null @@ -1,8 +0,0 @@ -<?php -class pdo_debug extends PDO { - function query($q, $a1=null, $a2=null, $a3=null) { - debug('pdo::query', $q); - return parent::query($q, $a1, $a2, $a3); - } -} -?> diff --git a/frontend/classes/wizard.php b/frontend/classes/wizard.php index 4d0d7b7..de37e72 100644 --- a/frontend/classes/wizard.php +++ b/frontend/classes/wizard.php @@ -1,6 +1,6 @@ <?php class wizard_step { - var $configuration, $module, $step, $title, $next, $data=array(); + public $configuration, $module, $step, $title, $next, $data=array(); function __construct(&$c, $step, $noload=false) { $this->configuration=&$c; $this->module=new module($c->module); @@ -16,13 +16,13 @@ class wizard_step { $this->next=isset($next)?$next:($this->step == $this->module->numsteps?null:$step+1); } public function output($rw=true) { - global $conf; + global $S; echo "<div class=\"wizard\" id=\"step$this->step\">"; if ($rw) echo '<form action="'.url('config/'.$this->configuration->id).'" method="post"><a style="float: right" href="'.url('config/'.$this->configuration->id.'/status').'">Status</a>'; if ($rw) { echo '<h3>Step '.$this->step.': '.$this->title."</h3>\n"; - $scale=$conf['progressbar_width']/$this->module->numsteps; + $scale=$S['conf']['progressbar_width']/$this->module->numsteps; echo '<img src="'.url('images/full.gif').'" style="border-left: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.$this->step*$scale.'px; height: 15px" /><img src="'.url('images/empty.gif').'" style="border-right: 1px solid black; border-top: 1px solid black; border-bottom: 1px solid black; width: '.(count($this->module->steps)-$this->step)*$scale.'px; height: 15px" /><br/>'."\n"; $this->echo_buttons(); } @@ -43,8 +43,7 @@ class wizard_step { echo '</div>'."\n"; } public function process() { - global $request; - if (!isset($request['wizard_submit'][$this->step])) { + if (!isset($_REQUEST['wizard_submit'][$this->step])) { return $this->step; } $result=$this->next; @@ -91,9 +90,6 @@ class wizard_step { private function layered_checkbox_array($optname, $htmlname, $label, &$array, $delim=' ', $metadata) { $this->data[]=array(new layered_checkbox_array($htmlname, $label, $array, $delim, $metadata), $optname); } - private function query($q) { - return $GLOBALS['S']['pdo']->query($q); - } private function set_opt($opt, $val) { return $this->configuration->set_opt($opt, $val); } diff --git a/frontend/css/debug.css b/frontend/css/debug.css index 38c6774..7f49bd5 100644 --- a/frontend/css/debug.css +++ b/frontend/css/debug.css @@ -1,4 +1,4 @@ -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> div#debug { font-family: monospace; background-color: white; diff --git a/frontend/css/general.css b/frontend/css/general.css index df0d3a6..4638de5 100644 --- a/frontend/css/general.css +++ b/frontend/css/general.css @@ -104,7 +104,7 @@ hr { .pointer { cursor: pointer; } -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> html { margin-bottom: 2em; } diff --git a/frontend/functions/onshutdown.php b/frontend/functions/onshutdown.php index 60c2cb4..f144275 100644 --- a/frontend/functions/onshutdown.php +++ b/frontend/functions/onshutdown.php @@ -1,17 +1,17 @@ <?php function onshutdown($footerloc, $headerloc) { - global $S, $request, $conf, $death; + global $S; if (isset($S) && is_array($S) && !$S['notemplates']) { require_once($headerloc); - if ($death) { - echo $death; + if ($S['death']) { + echo $S['death']; } require_once($footerloc); - } elseif (isset($conf) && isset($S) && is_array($S) && isset($request) && isset($request['ajax'])) { - if (isset($death)) { - echo '<death_message>'.$death.'</death_message>'; + } elseif (isset($S['conf']) && isset($S) && is_array($S) && isset($_REQUEST) && isset($_REQUEST['ajax'])) { + if (isset($S['death'])) { + echo '<death_message>'.$S['death'].'</death_message>'; } - if ($conf['debug']) { + if ($S['conf']['debug']) { foreach ($S['debug'] as $row) { list($type, $text)=$row; echo '<debug>'; diff --git a/frontend/functions/r_stripslashes.php b/frontend/functions/r_stripslashes.php index 8d6dccb..a0679f0 100644 --- a/frontend/functions/r_stripslashes.php +++ b/frontend/functions/r_stripslashes.php @@ -3,11 +3,10 @@ function r_stripslashes(&$array) { debug('r_stripslashes', print_r($array, true)); foreach ($array as $key => $value) { if (is_array($value)) { - $array[$key]=r_stripslashes($value); + r_stripslashes($value); } elseif (is_string($value)) { $array[$key]=stripslashes($value); } } - return $array; } ?> diff --git a/frontend/include/error_handling.php b/frontend/include/error_handling.php index 82f6122..5f616ee 100644 --- a/frontend/include/error_handling.php +++ b/frontend/include/error_handling.php @@ -1,12 +1,12 @@ <?php function exception_handler($e) { - global $death; + global $S; $trace=array(); foreach ($e->getTrace() as $t) { $trace[]='<b>'.$t['function'].'</b>(<b>'.htmlentities(implode(', ', $t['args'])).'</b>) at <b>'.$t['file'].'</b> line <b>'.$t['line'].'</b><br/>'; } $trace=implode(' from<br/>', $trace); - $death.=print_error('Uncaught '.get_class($e).': '.$e->getMessage(), 'Thrown at:<br/>'.$trace); + $S['death'].=print_error('Uncaught '.get_class($e).': '.$e->getMessage(), 'Thrown at:<br/>'.$trace); } set_exception_handler('exception_handler'); // Directly copied from PHP Manual -> Language Reference -> Predefined Exceptions -> ErrorException @@ -14,7 +14,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline ) { if ((error_reporting() & $errno) == 0) { // Don't report errors that aren't supposed to be reported return; } - global $death; + global $S; $errtypes=array( E_ERROR => 'Fatal Error', E_WARNING => 'Warning', @@ -54,7 +54,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline ) { } $trace.='from <b>'.(isset($t['function'])?(isset($t['class'])?$t['class'].$t['type']:'').$t['function'].'</b>'.(isset($t['args'])?'(<b>'.htmlentities(implode(', ', $t['args'])).'</b>)':''):(isset($t['args'])?'Included file(s) '.implode(', ', $t['args']):'')).(isset($t['file'])?' at <b>'.$t['file'].'</b>'.(isset($t['line'])?' line <b>'.$t['line'].'</b>':''):'').'<br/>'; } - $death.=print_error($type, $errstr.'<br/>'.$trace); + $S['death'].=print_error($type, $errstr.'<br/>'.$trace); } set_error_handler("exception_error_handler"); ?> diff --git a/frontend/include/footer.php b/frontend/include/footer.php index 96ba9b9..9b42bcc 100644 --- a/frontend/include/footer.php +++ b/frontend/include/footer.php @@ -1,19 +1,19 @@ </div><div id="bottom" class="box"> <?php -global $conf, $S; +global $S; if (isset($S['start'])) { $diff=round(microtime(true)-$S['start'], 3); echo 'Execution took '.$diff.' seconds.<br/>'."\n"; } echo /*'© Eitan Mosenkis '.date('Y').*/'</div>'; -if ($conf['debug']) { +if ($S['conf']['debug']) { echo '<br/><div id="debug"><div class="heading" onclick="toggledebugbox()">Debug (<span id="debugcount">'.$S['debugrow'].'</span>) <span id="debugactions">[<a href="javascript:cleardebug()" id="debugclear">Clear</a>] [<a href="javascript:closedebug()" id="debugclose">X</a>]</span></div><div id="debugbox">'./*$state->debug.*/'</div></div>'."\n"; echo '<script type="text/javascript"> <!-- toggledebugbox();'."\n"; foreach ($S['debug'] as $row) { list($type, $text)=$row; - $text=str_replace(array('"', "\r", "\n", "\t"), array('\"', '\\r', '\\n', '\\t'), $text); + $text=str_replace(array('\\', '"', "\r", "\n", "\t"), array('\\\\', '\"', '\\r', '\\n', '\\t'), $text); // $text used to have htmlentities() run on it, but that killed the SQL output tables if ($type == null) { echo 'debug("'.$text.'");'."\n"; diff --git a/frontend/include/header.php b/frontend/include/header.php index c11c480..6e57d43 100644 --- a/frontend/include/header.php +++ b/frontend/include/header.php @@ -9,11 +9,11 @@ echo xmlheader(); <link rel="shortcut icon" href="<?php echo url('images/favicon.ico'); ?>" /> <link rel="icon" href="<?php echo url('images/favicon.png'); ?>" type="image/gif" /> <title><?php -echo ($S['title'] != null?$S['title'].' | ':'').$conf['title']; +echo ($S['title'] != null?$S['title'].' | ':'').$S['conf']['title']; ?></title> <?php $scripts=array('GetXmlHttpObject', 'url', 'ajax'); -if ($conf['debug']) { +if ($S['conf']['debug']) { array_unshift($scripts, 'debug'); } foreach (array_merge($S['scripts'], $scripts) as $script) { @@ -40,9 +40,9 @@ echo '<li><a href="'.url('create').'">New configuration</a></li>'; echo '<li><a href="'.url('configurations').'">My configurations</a></li>'; echo '<li><a href="'.url('builds').'">My builds</a></li>'; if (isset($S['user'])) { - if ($conf['invite'] && ($S['user']->has_flag('a') || $conf['invite'] != 'admin')) + if ($S['conf']['invite'] && ($S['user']->has_flag('a') || $S['conf']['invite'] != 'admin')) echo '<li><a href="'.url('invite').'">Invite</a></li>'; -} elseif ($conf['registration']) +} elseif ($S['conf']['registration']) echo '<li><a href="'.url('register').'">Register</a>'; ?> </ul> @@ -54,7 +54,7 @@ if (isset($S['user'])) { $links['logout'.(strlen($S['request'])?'/'.$S['request']:'')]='Logout'; } else { $links['login'.(strlen($S['request'])?'/'.$S['request']:'')]='Login'; - if ($conf['registration']) $links['register']='Register'; + if ($S['conf']['registration']) $links['register']='Register'; } foreach ($links as $url => $text) { $links[$url]='<a href="'.url($url).'">'.htmlentities($text).'</a>'; @@ -64,8 +64,8 @@ if (isset($S['user'])) { </div> <div id="main" class="box"> <?php - if (isset($death)) { - echo $death; - $death=''; + if (isset($S['death'])) { + echo $S['death']; + $S['death']=''; } ?> diff --git a/frontend/include/setup.php b/frontend/include/setup.php index 2239c6c..825d759 100644 --- a/frontend/include/setup.php +++ b/frontend/include/setup.php @@ -3,6 +3,7 @@ if (!isset($S)) { $S=array(); } $S=array_merge($S, array( + 'death' => '', 'request' => $_GET['req'], 'notemplates' => false, 'title' => null, @@ -17,17 +18,17 @@ $S=array_merge($S, array( 'sql' => null )); unset($_REQUEST['req'], $_GET['req']); -$S['cookie_dir']=substr($conf['url'], strpos($conf['url'], '/', 8)).'/'; +$S['cookie_dir']=substr($S['conf']['url'], strpos($S['conf']['url'], '/', 8)).'/'; require_once(SHARED.'/include/dbinit.php'); -if (isset($_COOKIE[$conf['cookiename']])) { - $cookie=$_COOKIE[$conf['cookiename']]; - debug('session', 'cookie received '.$conf['cookiename'].'='.htmlentities($cookie)); +if (isset($_COOKIE[$S['conf']['cookiename']])) { + $cookie=$_COOKIE[$S['conf']['cookiename']]; + debug('session', 'cookie received '.$S['conf']['cookiename'].'='.htmlentities($cookie)); if (preg_match('/[a-z0-9]{30}/', $cookie)) { - $r=$S['pdo']->query('SELECT * FROM `sessions` WHERE `id`="'.$cookie.'"'); + $r=query('SELECT * FROM `sessions` WHERE `id`="'.$cookie.'"'); if ($r->rowCount()) { $S['session']=new sql_session($r->fetch(PDO::FETCH_ASSOC)); if ($S['session']->atime+$S['session']->expire < time()) { - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); $S['sesion']->delete(); unset($S['session']); } else { @@ -35,11 +36,11 @@ if (isset($_COOKIE[$conf['cookiename']])) { $S['session']->write(); $S['user']=new sql_user($S['session']->user); debug('session', 'sessionid='.$S['session']->id.', email='.$S['user']->email); - setcookie($conf['cookiename'], $S['session']->id, time()+$conf['sessionlength'], $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], $S['session']->id, time()+$S['conf']['sessionlength'], $S['cookie_dir'], '', false, true); } } else { debug('session', 'session not found'); - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); } } else { debug('session', 'session id invalid'); diff --git a/frontend/index.php b/frontend/index.php index a103dd9..1c1ea7d 100644 --- a/frontend/index.php +++ b/frontend/index.php @@ -1,12 +1,11 @@ <?php define('E_DEFAULT', error_reporting(E_ALL|E_STRICT)); -date_default_timezone_set('UTC'); require_once('../shared/include/includes.php'); require_once('include/error_handling.php'); +register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); // Needed to ensure that errors are printed require_once('include/constants.php'); require_once('include/setup.php'); -register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); -$request=get_magic_quotes_gpc()?r_stripslashes($_REQUEST):$_REQUEST; +if (get_magic_quotes_gpc()) r_stripslashes($_REQUEST); $routing=fopen('routing.csv', 'r'); for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768)) { $line=trim($line, "\r\n"); @@ -28,12 +27,12 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) fclose($routing); for ($i=0; $i < count($vars); $i++) { if (strpos($vars[$i],'=')) { - $request[substr($vars[$i],0,strpos($vars[$i],'='))]=substr($vars[$i],strpos($vars[$i],'=')+1); + $_REQUEST[substr($vars[$i],0,strpos($vars[$i],'='))]=substr($vars[$i],strpos($vars[$i],'=')+1); } else { if ($i+1 > count($matches)-1) { debug('routing',print_error('Routing failure','Trying to set request variable "'.$vars[$i].'" but ran out of matches (page='.$dest.')')); } else { - $request[$vars[$i]]=$matches[$i+1]; + $_REQUEST[$vars[$i]]=$matches[$i+1]; } } } @@ -46,7 +45,7 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) $dest=str_replace(array('/', '-'), '_', $dest); $initfunc='init_'.$dest; if (function_exists($initfunc)) { - $value=$initfunc(); + $value=$initfunc($S); if ($value === null) { break; } elseif (is_array($value)) { @@ -73,7 +72,7 @@ for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768) } $bodyfunc='body_'.str_replace('/','_',$dest); if (function_exists($bodyfunc)) { - $bodyresult=$bodyfunc(); + $bodyresult=$bodyfunc($S); if ($bodyresult !== null) { require($bodyresult); } diff --git a/frontend/js/ajax.js.php b/frontend/js/ajax.js.php index b34af86..d2bb137 100644 --- a/frontend/js/ajax.js.php +++ b/frontend/js/ajax.js.php @@ -26,7 +26,7 @@ function makepostdata(data) { function doajaxrequest(page,data,callback) { requestnum=ajaxrequestnum++; content=makepostdata(data); -<?php if ($conf['debug']) { ?> +<?php if ($S['conf']['debug']) { ?> debug('ajax:'+requestnum,'Sending to '+url(page)+':<br/>'+content); <?php } ?> httpobj=GetXmlHttpObject(); @@ -38,7 +38,7 @@ function doajaxrequest(page,data,callback) { if (this.readyState==4 || this.readyState=="complete") { if (this.responseXML != null && this.responseXML.documentElement.nodeName==page.replace('/','')+'response') { xml=this.responseXML.documentElement; - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('ajax:'+requestnum, 'Got response:<br/><pre>'+this.responseText.replace(/</g, '<').replace(/>/g, '>')+'</pre>'); if (debugenabled) { for (var i=0; i<xml.getElementsByTagName('debug').length; i++) { @@ -54,7 +54,7 @@ function doajaxrequest(page,data,callback) { } <?php } ?> callback(xml); - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> } else { if (this.responseText.length == 0) { debug('ajax'+requestnum, 'zero-length response received'); @@ -81,12 +81,12 @@ function XMLtoHTML(xml, notrecursive) { html.className=attr.value; } else if (attr.name.match(/^on/)) { var handlerfunc=new Function('event', attr.value); - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('XMLtoHTML', 'setting '+xml.nodeName+(xml.id?'#'+xml.id:'')+'.'+attr.name+':'+"\r\n"+handlerfunc); <?php } ?> html[attr.name]=handlerfunc; } else { - <?php if ($conf['debug']) { ?> + <?php if ($S['conf']['debug']) { ?> debug('XMLtoHTML', 'setting '+xml.nodeName+(xml.attributes.getNamedItem('id')?'#'+xml.attributes.getNamedItem('id').value:'')+'.'+attr.name+'='+attr.value); <?php } ?> html.setAttribute(attr.name, attr.value); diff --git a/frontend/js/debug.js.php b/frontend/js/debug.js.php index cc28959..39b9681 100644 --- a/frontend/js/debug.js.php +++ b/frontend/js/debug.js.php @@ -1,5 +1,5 @@ <?php // vim:filetype=javascript -if ($conf['debug']) { ?> +if ($S['conf']['debug']) { ?> var debugrow=0; var debugenabled=1; var debug_queue=[]; diff --git a/frontend/js/url.js.php b/frontend/js/url.js.php index a1b2b93..18dacc8 100644 --- a/frontend/js/url.js.php +++ b/frontend/js/url.js.php @@ -1,5 +1,5 @@ <?php // vim:filetype=javascript // Equivalent to php function of the same name ?> function url (relative) { - return "<?php echo $conf['url'] ?>/"+relative; + return "<?php echo $S['conf']['url'] ?>/"+relative; } diff --git a/frontend/modules/gentoo/step1.php b/frontend/modules/gentoo/step1.php index 297f7c0..67ebd71 100644 --- a/frontend/modules/gentoo/step1.php +++ b/frontend/modules/gentoo/step1.php @@ -1,6 +1,6 @@ <?php $opts=array(); -$r=$this->query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); +$r=query('SELECT * FROM `gentoo_profiles` WHERE `flags` NOT LIKE "%d%"'); while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { $profile=new sql_gentoo_profile($profile); $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/'); diff --git a/frontend/modules/gentoo/step2.php b/frontend/modules/gentoo/step2.php index 8eed939..1800255 100644 --- a/frontend/modules/gentoo/step2.php +++ b/frontend/modules/gentoo/step2.php @@ -4,7 +4,7 @@ $profile=new sql_gentoo_profile($this->get_opt('profile')); $this->checkbox_array('options', 'options', 'Configuration options', array('timezone' => 'Select timezone', 'dev-manager' => 'Select /dev manager', 'pruneinit' => 'Remove enabled-by-default init scripts')); $this->select('basesystem', 'basesystem', 'Base system', array('stage3' => 'Stage3 Tarball', 'autoprune' => 'Remove all non-vital packages', 'manual' => 'Manually select packages to remove from stage3')); $pkgsets=array(); -$r=$S['pdo']->query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$profile->id); +$r=query('SELECT * FROM `gentoo_pkgsets` WHERE `profile`='.$profile->id); while ($pkgset=$r->fetch(PDO::FETCH_ASSOC)) { $pkgset=new sql_gentoo_pkgset($pkgset); $pkgsets[$pkgset->id]=$pkgset->name; diff --git a/frontend/modules/gentoo/step3.php b/frontend/modules/gentoo/step3.php index dd2d72c..7074049 100644 --- a/frontend/modules/gentoo/step3.php +++ b/frontend/modules/gentoo/step3.php @@ -20,7 +20,7 @@ if (strlen($pkgsets=$this->get_opt('pkgsets'))) { } } if (in_array('pruneinit', $opts)) { - $r=$S['pdo']->query('SELECT * FROM `gentoo_baseinit` WHERE `profile`='.$profile->id.' ORDER BY `name`, `runlevel`'); + $r=query('SELECT * FROM `gentoo_baseinit` WHERE `profile`='.$profile->id.' ORDER BY `name`, `runlevel`'); $scripts=array(); while ($script=$r->fetch(PDO::FETCH_ASSOC)) { $script=new sql_gentoo_baseinit($script); @@ -29,7 +29,7 @@ if (in_array('pruneinit', $opts)) { $this->checkbox_array('pruneinit', 'pruneinit', 'Remove the following init scripts', $scripts); } if ($this->get_opt('basesystem') == 'manual') { - $r=$S['pdo']->query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id.' ORDER BY `pkg`'); + $r=query('SELECT * FROM `gentoo_basepkgs` WHERE `profile`='.$profile->id.' ORDER BY `pkg`'); $pkgs=array(); while ($pkg=$r->fetch(PDO::FETCH_ASSOC)) { $pkg=$pkg['pkg']; diff --git a/frontend/modules/gentoo_catalyst.info.alpha b/frontend/modules/gentoo_catalyst.info.alpha deleted file mode 100644 index 4803759..0000000 --- a/frontend/modules/gentoo_catalyst.info.alpha +++ /dev/null @@ -1,4 +0,0 @@ -<?php -$name='Gentoo Catalyst'; -require(dirname(__FILE__).'/gentoo_common.php'); -?> diff --git a/frontend/pages/404.php b/frontend/pages/404.php index ffc3b79..fc614c5 100644 --- a/frontend/pages/404.php +++ b/frontend/pages/404.php @@ -3,8 +3,7 @@ function init_404() { header('HTTP/1.0 404 Not Found', true, 404); return array('title' => '404: Not Found'); } -function body_404() { - global $S, $conf; - echo print_error('Page Not Found!','The page you are trying to reach, <i>'.$conf['url'].'/'.$S['request'].'</i> does not exist.'); +function body_404(&$S) { + echo print_error('Page Not Found!','The page you are trying to reach, <i>'.$S['conf']['url'].'/'.$S['request'].'</i> does not exist.'); } ?> diff --git a/frontend/pages/builds/delete.php b/frontend/pages/builds/delete.php index cf6c6d4..51aa9cf 100644 --- a/frontend/pages/builds/delete.php +++ b/frontend/pages/builds/delete.php @@ -1,16 +1,14 @@ <?php -function init_builds_delete() { - global $S, $request; +function init_builds_delete(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) return '404'; + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) return '404'; $S['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if (!owner_or_admin($S['build']->id)) return '404'; return array('title' => 'Delete Build'); } -function body_builds_delete() { - global $S; +function body_builds_delete(&$S) { if ($S['build']->status >= 0 || $S['build']->status == -128) { $S['build']->delete(); echo print_success('Build deleted.'); diff --git a/frontend/pages/builds/download.php b/frontend/pages/builds/download.php index c40606d..411efbf 100644 --- a/frontend/pages/builds/download.php +++ b/frontend/pages/builds/download.php @@ -1,14 +1,13 @@ <?php -function init_builds_download() { - global $S, $request; +function init_builds_download(&$S) { if (!isset($S['user'])) { return 'login'; } - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) { + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) { debug('builds_download', 'No build or badly formatted build requested'); return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) { debug('builds_download', 'build not found or not owned by user'); return '404'; @@ -41,8 +40,7 @@ function init_builds_download() { header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="'.(isset($build->name) && strlen($build->name)?str_replace('"', '\"', $build->name):'ingenue-'.$build->id).$ext); } -function body_builds_download() { - global $S; +function body_builds_download(&$S) { readfile($S['builds_download']['file']); // Log the download to db after sending data so hopefully HEAD requests won't artificially inflate the # of dls $S['builds_download']['dl']->write(); diff --git a/frontend/pages/builds/history.php b/frontend/pages/builds/history.php index cd8e581..c9789e3 100644 --- a/frontend/pages/builds/history.php +++ b/frontend/pages/builds/history.php @@ -1,11 +1,10 @@ <?php -function init_builds_history() { - global $S, $request; +function init_builds_history(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) { + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) { return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if (!$r->rowCount()) return '404'; $S['builds_history']['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if ($S['builds_history']['build']->visibility == 'private' && !owner_or_admin($S['builds_history']['build']->id)) { @@ -13,11 +12,10 @@ function init_builds_history() { } return array('title' => 'Download History'); } -function body_builds_history() { - global $S; +function body_builds_history(&$S) { $build=&$S['builds_history']['build']; echo $build->display(); - $r=$S['pdo']->query('SELECT * FROM `downloads` WHERE `build`="'.$build->id.'" ORDER BY `time` DESC'); + $r=query('SELECT * FROM `downloads` WHERE `build`="'.$build->id.'" ORDER BY `time` DESC'); while ($download=$r->fetch(PDO::FETCH_ASSOC)) { $download=new sql_download($download); $user=$download->get_user(); diff --git a/frontend/pages/builds/index.php b/frontend/pages/builds/index.php index 4b6b7c8..adc6566 100644 --- a/frontend/pages/builds/index.php +++ b/frontend/pages/builds/index.php @@ -1,12 +1,10 @@ <?php -function init_builds_index() { - global $S; +function init_builds_index(&$S) { if (!isset($S['user'])) return 'login'; return array('title' => 'My Builds'); } -function body_builds_index() { - global $S; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC'); +function body_builds_index(&$S) { + $r=query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC'); if ($r->rowCount() == 0) { echo print_warning('No builds found.'); } diff --git a/frontend/pages/builds/log.php b/frontend/pages/builds/log.php index 699887f..078b816 100644 --- a/frontend/pages/builds/log.php +++ b/frontend/pages/builds/log.php @@ -1,23 +1,21 @@ <?php -function init_builds_log() { - global $S, $request; +function init_builds_log(&$S) { $S['title']='Log Viewer'; if (!isset($S['user'])) return 'login'; - if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + if (!(isset($_REQUEST['build']) && strlen($_REQUEST['build']) == 6 && ctype_alnum($_REQUEST['build']))) return '404'; + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount()) { $S['builds_log']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); if ($S['builds_log']->visibility == 'private' && !owner_or_admin($S['builds_log']->owner)) return '404'; } else return '404'; - if (isset($request['task']) && is_numeric($request['task'])) + if (isset($_REQUEST['task']) && is_numeric($_REQUEST['task'])) return 'builds/task'; } -function body_builds_log() { - global $S; +function body_builds_log(&$S) { $build=&$S['builds_log']; echo $build->display(); - $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$build->id.'" ORDER BY `order` ASC'); + $r=query('SELECT * FROM `tasks` WHERE `build`="'.$build->id.'" ORDER BY `order` ASC'); if ($r->rowCount() == 0) { echo '<b>No tasks found.</b>'; } diff --git a/frontend/pages/builds/task.php b/frontend/pages/builds/task.php index ff3dd3f..0197372 100644 --- a/frontend/pages/builds/task.php +++ b/frontend/pages/builds/task.php @@ -1,39 +1,37 @@ <?php -function init_builds_task() { - global $S, $request; +function init_builds_task(&$S) { if (!isset($S['user'])) return 'login'; - if (!(isset($S['builds_log']) && isset($request['task']) && is_numeric($request['task']))) return 'builds/log'; - $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$request['task']); + if (!(isset($S['builds_log']) && isset($_REQUEST['task']) && is_numeric($_REQUEST['task']))) return 'builds/log'; + $r=query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$_REQUEST['task']); if ($r->rowCount()) { $S['builds_task']=new sql_task($r->fetch(PDO::FETCH_ASSOC)); } else return '404'; } -function body_builds_task() { - global $S, $request, $conf; +function body_builds_task(&$S) { $task=&$S['builds_task']; echo '<div style="font-size: 130%">'.$task->display().'</div>'; echo '<a href="'.url("build/$task->build").'">Back</a><br/>'; - $page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1; - $count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN); + $page=isset($_REQUEST['page']) && is_numeric($_REQUEST['page'])?$_REQUEST['page']:1; + $count=query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN); $pager=''; - if ($count > $conf['logview_max']) { + if ($count > $S['conf']['logview_max']) { $pager='<form action="'.url("build/$task->build/$task->order").'" method="post" onsubmit="window.location.href=\''.url("build/$task->build/$task->order").'/\'+this.page.value; return false">Page: '; if ($page > 1) { $pager.='<input type="button" value="<<" onclick="this.form.page.value='.($page-1).'; this.form.onsubmit()" /> '."\n"; } $pager.='<select name="page">'; - for ($i=1; ($i-1)*$conf['logview_max']<$count; $i++) { + for ($i=1; ($i-1)*$S['conf']['logview_max']<$count; $i++) { $pager.="<option value=\"$i\"".($i==$page?'selected="selected"':'').">$i</option>\n"; } $pager.='</select> <input type="submit" value="Go" />'; - if ($page*$conf['logview_max']<$count) { + if ($page*$S['conf']['logview_max']<$count) { $pager.=' <input type="button" value=">>" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n"; } $pager.='</form>'; echo $pager; } - $r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']); + $r=query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$S['conf']['logview_max'].' OFFSET '.($page-1)*$S['conf']['logview_max']); if ($r->rowCount()) { echo '<div style="font-family: monospace">'; $ansi=new ansi_to_html(); diff --git a/frontend/pages/configurations/manager.php b/frontend/pages/configurations/manager.php index dfd8322..6396aaa 100644 --- a/frontend/pages/configurations/manager.php +++ b/frontend/pages/configurations/manager.php @@ -1,20 +1,18 @@ <?php -function init_configurations_manager() { - global $S; +function init_configurations_manager(&$S) { if (!isset($S['user'])) { return 'login'; } return array('title' => 'Manage Configurations'); } -function body_configurations_manager() { - global $S, $request, $conf; +function body_configurations_manager(&$S) { echo '<h3>Configurations Manager</h3>'; - if (isset($request['build']) && isset($request['configuration'])) { - $c=new sql_configuration($request['configuration']); + if (isset($_REQUEST['build']) && isset($_REQUEST['configuration'])) { + $c=new sql_configuration($_REQUEST['configuration']); if ($c->owner!=$S['user']->id) { echo print_error('You do not have permission to build this configuration.'); } else { - $name=isset($request['name'])?$request['name']:null; + $name=isset($_REQUEST['name'])?$_REQUEST['name']:null; $build=$c->build($name); if (is_object($build)) echo print_success('Submitted for build - <a href="'.url("build/$build->id").'">Logs</a>'); @@ -22,12 +20,12 @@ function body_configurations_manager() { echo print_error('Invalid configuration', 'Your configuration could not be submitted for build. Please return to <a href="'.url("config/$c->id/$build").'">step '.$build.'</a> and continue configuration from there.'); } } - $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); + $r=query('SELECT * FROM `configurations` WHERE `owner`='.$S['user']->id); if ($r->rowCount() == 0) { echo print_warning('You have no configurations.').'<a href="'.url('create').'">Create a configuration</a>'; return; } - echo '<form action="'.url('configurations').'" method="post"><table><tr><th>ID</th><th>Name</th>'.(count($conf['modules']) > 1?'<th>Module</th>':'').'<th>Status</th><th>Options</th><th>Builds</th></tr>'."\n"; + echo '<form action="'.url('configurations').'" method="post"><table><tr><th>ID</th><th>Name</th>'.(count($S['conf']['modules']) > 1?'<th>Module</th>':'').'<th>Status</th><th>Options</th><th>Builds</th></tr>'."\n"; $ready=0; while($c=$r->fetch(PDO::FETCH_ASSOC)) { $c=new sql_configuration($c); @@ -39,7 +37,7 @@ function body_configurations_manager() { echo $c->id; } echo '</td><td>'.(isset($c->name) && strlen($c->name)?htmlentities($c->name):'<i>Unnamed</i>').'</td><td>'; - if (count($conf['modules']) > 1) { + if (count($S['conf']['modules']) > 1) { echo "$c->module</td><td>"; } if ($c->status > 0) { diff --git a/frontend/pages/configurations/status.php b/frontend/pages/configurations/status.php index d27efd4..f0ba8d5 100644 --- a/frontend/pages/configurations/status.php +++ b/frontend/pages/configurations/status.php @@ -1,13 +1,12 @@ <?php -function init_configurations_status() { - global $S, $request; +function init_configurations_status(&$S) { if (!isset($S['user'])) { return 'login'; } - if (!(isset($request['configuration']) && strlen($request['configuration']) == 6 && ctype_alnum($request['configuration']))) { + if (!(isset($_REQUEST['configuration']) && strlen($_REQUEST['configuration']) == 6 && ctype_alnum($_REQUEST['configuration']))) { return '404'; } - $r=$S['pdo']->query('SELECT * FROM `configurations` WHERE `id`=\''.$request['configuration'].'\''); + $r=query('SELECT * FROM `configurations` WHERE `id`=\''.$_REQUEST['configuration'].'\''); if ($r->rowCount() == 0) { return '404'; } @@ -17,8 +16,7 @@ function init_configurations_status() { } return array('title' => 'Status'); } -function body_configurations_status() { - global $S; +function body_configurations_status(&$S) { $c=&$S['status']['configuration']; $module=new module($c->module); $status=true; diff --git a/frontend/pages/configurations/wizard.php b/frontend/pages/configurations/wizard.php index 947e321..33b9949 100644 --- a/frontend/pages/configurations/wizard.php +++ b/frontend/pages/configurations/wizard.php @@ -1,17 +1,16 @@ <?php -function init_configurations_wizard() { - global $S, $request, $conf; +function init_configurations_wizard(&$S) { if (!isset($S['user'])) { return 'login'; } - if (isset($request['configuration']) && strlen($request['configuration']) == 6 && ctype_alnum($request['configuration'])) { - $S['wizard']['configuration']=new sql_configuration($request['configuration']); + if (isset($_REQUEST['configuration']) && strlen($_REQUEST['configuration']) == 6 && ctype_alnum($_REQUEST['configuration'])) { + $S['wizard']['configuration']=new sql_configuration($_REQUEST['configuration']); $configuration=&$S['wizard']['configuration']; if ($configuration->owner != $S['user']->id) { return '404'; } - if (isset($request['wizard_submit'])) { - $steps=array_keys($request['wizard_submit']); + if (isset($_REQUEST['wizard_submit'])) { + $steps=array_keys($_REQUEST['wizard_submit']); $step=$steps[0]; wizard_load_step($step); debug('wizard', "processing $configuration->module step $step"); @@ -28,16 +27,17 @@ function init_configurations_wizard() { $configuration->write(); wizard_load_step($result); } - } elseif (isset($request['step']) && ctype_alnum($request['step'])) { - wizard_load_step($request['step']); + } elseif (isset($_REQUEST['step']) && ctype_alnum($_REQUEST['step'])) { + wizard_load_step($_REQUEST['step']); } elseif ($configuration->status > 0) { wizard_load_step($configuration->status); } - } elseif (isset($request['init'])) { + } elseif (isset($_REQUEST['init'])) { $S['wizard']['configuration']=new sql_configuration(); $configuration=&$S['wizard']['configuration']; - $configuration->name=$request['name']; - $mod=isset($request['mod']) && isset($conf['modules'][$request['mod']])?$conf['modules'][$request['mod']]:$conf['modules'][0]; + $configuration->name=$_REQUEST['name']; + $configuration->visibility='public'; + $mod=isset($_REQUEST['mod']) && isset($S['conf']['modules'][$_REQUEST['mod']])?$S['conf']['modules'][$_REQUEST['mod']]:$S['conf']['modules'][0]; $configuration->module=$mod; $configuration->init(); debug('wizard', "Module: $mod"); @@ -49,8 +49,7 @@ function init_configurations_wizard() { return array('title' => 'Create'); } } -function body_configurations_wizard() { - global $S, $conf; +function body_configurations_wizard(&$S) { if (isset($S['wizard']['configuration'])) { $configuration=&$S['wizard']['configuration']; if (isset($S['wizard']['step'])) @@ -59,10 +58,10 @@ function body_configurations_wizard() { echo print_success('Config finished!', '<form action="'.url('configurations').'" method="post"><input type="hidden" name="configuration" value="'.$configuration->id.'" />Name (optional): <input name="name" value="'.($configuration->name?htmlentities($configuration->name):'').'" /> <input type="submit" name="build" value="Build" /></form>'); } else { echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your configuration (optional): <input name="name" /><br/>'; - if (count($conf['modules']) > 1) { + if (count($S['conf']['modules']) > 1) { echo 'Module: <select name="mod">'; $i=0; - foreach ($conf['modules'] as $mod) { + foreach ($S['conf']['modules'] as $mod) { $mod=new module($mod); echo '<option value="'.$i++.'">'.htmlentities($mod->name).'</option>'; } diff --git a/frontend/pages/invite.php b/frontend/pages/invite.php index 69047ab..8603906 100644 --- a/frontend/pages/invite.php +++ b/frontend/pages/invite.php @@ -1,16 +1,14 @@ <?php -function init_invite() { - global $S, $conf; - if (!$conf['invite']) return '404'; +function init_invite(&$S) { + if (!$S['conf']['invite']) return '404'; if (!isset($S['user'])) return 'login'; - if ($conf['invite'] == 'admin' && !$S['user']->has_flag('a')) return '404'; + if ($S['conf']['invite'] == 'admin' && !$S['user']->has_flag('a')) return '404'; return array('title' => 'Invite'); } -function body_invite() { - global $S, $request, $conf; - if (isset($request['emails'])) { +function body_invite(&$S) { + if (isset($_REQUEST['emails'])) { echo '<h3>Inviting Users</h3>'; - $emails=explode("\n", $request['emails']); + $emails=explode("\n", $_REQUEST['emails']); foreach ($emails as $email) { // TODO proper checking that user and registrationtoken don't exist for this email to avoid errors $email=trim($email); @@ -26,7 +24,7 @@ function body_invite() { $token->expire=time()+24*3600; // 24 hour shelf life (we're not checking currently) $token->owner=$S['user']->id; $token->write(); - xhtmlemail($email, null, $conf['title'].' invitation', htmlentities($S['user']->name).' has invited you to create an account for '.$conf['title'].'. To create an account, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>'); + xhtmlemail($email, null, $S['conf']['title'].' invitation', htmlentities($S['user']->name).' has invited you to create an account for '.$S['conf']['title'].'. To create an account, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>'); echo 'Invited '.htmlentities($email).'<br/>'; } echo '<a href="'.url('invite').'">Send more invitations</a>'; diff --git a/frontend/pages/login.php b/frontend/pages/login.php index 13eeb0a..953d2c4 100644 --- a/frontend/pages/login.php +++ b/frontend/pages/login.php @@ -1,12 +1,11 @@ <?php -function init_login() { - global $S, $request, $conf; +function init_login(&$S) { if (isset($S['user'])) { - // Should we let you continue to $request['go'] instead? + // Should we let you continue to $_REQUEST['go'] instead? return 'welcome'; } else { - if (isset($request['email']) && isset($request['password'])) { - $r=$S['pdo']->query('SELECT * FROM `users` WHERE `email`='.$S['pdo']->quote($request['email']).' AND `passhash`="'.sha1($request['password']).'"'); + if (isset($_REQUEST['email']) && isset($_REQUEST['password'])) { + $r=query('SELECT * FROM `users` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']).' AND `passhash`="'.sha1($_REQUEST['password']).'"'); if ($r->rowCount()) { $S['user']=new sql_user($r->fetch(PDO::FETCH_ASSOC)); $S['login.result']=sql_session::create(); @@ -17,10 +16,9 @@ function init_login() { return array('title' => 'Login'); } } -function body_login() { - global $request, $S; +function body_login(&$S) { if (substr($S['request'], 0, 5) != 'login') { - $request['go']=$S['request']; + $_REQUEST['go']=$S['request']; echo print_warning('Please sign in to access this page.'); } if (isset($S['login.result'])) { @@ -28,15 +26,15 @@ function body_login() { echo print_error('An error occurred while signing you in.'); } elseif ($S['login.result']) { echo print_success('Welcome, '.$S['user']->name); - echo '<a href="'.url(isset($request['go'])?$request['go']:'').'">Continue</a>'; + echo '<a href="'.url(isset($_REQUEST['go'])?$_REQUEST['go']:'').'">Continue</a>'; die; } else { echo print_error('Your email and password combination was not recognized.'); } } echo '<h3>Login</h3><form action="'.url('login').'" method="post">'; - if (isset($request['go'])) { - echo '<input type="hidden" name="go" value="'.htmlentities($request['go']).'" />'; + if (isset($_REQUEST['go'])) { + echo '<input type="hidden" name="go" value="'.htmlentities($_REQUEST['go']).'" />'; } echo 'Email: <input name="email" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Submit" /></form>'; } diff --git a/frontend/pages/logout.php b/frontend/pages/logout.php index 6eccd3d..71f8c11 100644 --- a/frontend/pages/logout.php +++ b/frontend/pages/logout.php @@ -1,12 +1,11 @@ <?php -function init_logout() { - global $S, $conf, $request; +function init_logout(&$S) { if (isset($S['session'])) { $S['session']->delete(); } - setcookie($conf['cookiename'], '', 1, $S['cookie_dir'], '', false, true); - if (isset($request['go'])) { - header('Location: '.url($request['go'])); + setcookie($S['conf']['cookiename'], '', 1, $S['cookie_dir'], '', false, true); + if (isset($_REQUEST['go'])) { + header('Location: '.url($_REQUEST['go'])); } } function body_logout() { diff --git a/frontend/pages/passthrough.php b/frontend/pages/passthrough.php index e444aa2..40ee579 100644 --- a/frontend/pages/passthrough.php +++ b/frontend/pages/passthrough.php @@ -1,11 +1,10 @@ <?php -function init_passthrough() { - global $S, $request; - if (strpos('../',$request['dir'].'/'.$request['file']) !== false || !file_exists($request['dir'].'/'.$request['file']) && !file_exists($request['dir'].'/'.$request['file'].'.php')) { - debug('passthrough','File not found '.$request['dir'].'/'.$request['file']); +function init_passthrough(&$S) { + if (strpos('../',$_REQUEST['dir'].'/'.$_REQUEST['file']) !== false || !file_exists($_REQUEST['dir'].'/'.$_REQUEST['file']) && !file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'].'.php')) { + debug('passthrough','File not found '.$_REQUEST['dir'].'/'.$_REQUEST['file']); return '404'; } - switch (strtolower($request['ext'])) { + switch (strtolower($_REQUEST['ext'])) { // http://www.w3schools.com/media/media_mimeref.asp case 'mp3': contenttype('audio/mpeg'); @@ -46,37 +45,36 @@ function init_passthrough() { contenttype('application/bzip2'); break; default: - debug('passthrough', 'Unknown extension '.$request['ext']); + debug('passthrough', 'Unknown extension '.$_REQUEST['ext']); return '404'; } // Set filesize if we're working with a static file (needed for normal download and streaming behavior) - if (strtolower($request['ext']) != 'php' && file_exists($request['dir'].'/'.$request['file'])) { - header('Content-Length: '.filesize($request['dir'].'/'.$request['file'])); + if (strtolower($_REQUEST['ext']) != 'php' && file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'])) { + header('Content-Length: '.filesize($_REQUEST['dir'].'/'.$_REQUEST['file'])); } // Force browser to download, possibly set dynamic filename, passed by previous page or by HTTP request (taken from the PHP manual on readfile() - if (isset($request['download']) && $request['download']) { + if (isset($_REQUEST['download']) && $_REQUEST['download']) { header('Content-Description: File Transfer'); header('Content-Transfer-Encoding: binary'); - if (isset($request['download_name']) && strlen($request['download_name']) > 0) { - header('Content-Disposition: attachment; filename="'.str_replace('"','\'', $request['download_name']).'"'); + if (isset($_REQUEST['download_name']) && strlen($_REQUEST['download_name']) > 0) { + header('Content-Disposition: attachment; filename="'.str_replace('"','\'', $_REQUEST['download_name']).'"'); } else { header('Content-Disposition: attachment'); } } $S['notemplates']=true; } -function body_passthrough() { - global $request; - if (strtolower($request['ext']) == 'php') { - $_SERVER['PHP_SELF']=substr($_SERVER['PHP_SELF'],0,strlen($_SERVER['PHP_SELF'])-strlen('main.php')).$request['dir'].'/'.$request['file']; - unset($GLOBALS['S'], $GLOBALS['request'], $GLOBALS['conf']); - chdir($request['dir']); +function body_passthrough(&$S) { + if (strtolower($_REQUEST['ext']) == 'php') { + $_SERVER['PHP_SELF']=substr($_SERVER['PHP_SELF'],0,strlen($_SERVER['PHP_SELF'])-strlen('main.php')).$_REQUEST['dir'].'/'.$_REQUEST['file']; + unset($GLOBALS['S']); + chdir($_REQUEST['dir']); error_reporting(E_DEFAULT); - return $request['file']; - } elseif (file_exists($request['dir'].'/'.$request['file'])) { - readfile($request['dir'].'/'.$request['file']); + return $_REQUEST['file']; + } elseif (file_exists($_REQUEST['dir'].'/'.$_REQUEST['file'])) { + readfile($_REQUEST['dir'].'/'.$_REQUEST['file']); } else { - return $request['dir'].'/'.$request['file'].'.php'; + return $_REQUEST['dir'].'/'.$_REQUEST['file'].'.php'; } } ?> diff --git a/frontend/pages/register.php b/frontend/pages/register.php index 1f76c69..441269c 100644 --- a/frontend/pages/register.php +++ b/frontend/pages/register.php @@ -1,22 +1,21 @@ <?php -function init_register() { - global $S, $request, $conf; +function init_register(&$S) { if (isset($S['user'])) { header('Location: '.url()); return 'welcome'; } - if (isset($request['token']) && preg_match('/^[a-zA-Z0-9]{30}$/', $request['token'])) { - $r=$S['pdo']->query('SELECT * FROM `registrationtokens` WHERE `id`=\''.$request['token'].'\''); + if (isset($_REQUEST['token']) && preg_match('/^[a-zA-Z0-9]{30}$/', $_REQUEST['token'])) { + $r=query('SELECT * FROM `registrationtokens` WHERE `id`=\''.$_REQUEST['token'].'\''); if ($r->rowCount()) { $S['register.token']=new sql_registrationtoken($r->fetch(PDO::FETCH_ASSOC)); - if (isset($request['password'])) { + if (isset($_REQUEST['password'])) { $S['register.fail']=''; - if (!isset($request['name']) || !Validate::username($request['name'])) + if (!isset($_REQUEST['name']) || !Validate::username($_REQUEST['name'])) $S['register.fail'].=print_warning('The username you entered is invalid. Names must be at least two characters long and may contain alphanumeric characters, period, space, underscore, and dash.'); - if (!isset($request['password']) || strlen($request['password']) <= 4) + if (!isset($_REQUEST['password']) || strlen($_REQUEST['password']) <= 4) $S['register.fail'].=print_warning('Please enter a password at least five characters long.'); if ($S['register.fail']=='') { - $S['user']=new sql_user(null, $S['register.token']->email, $request['name'], sha1($request['password']), ''); + $S['user']=new sql_user(null, $S['register.token']->email, $_REQUEST['name'], sha1($_REQUEST['password']), ''); $S['user']->write(); $S['register.token']->delete(); unset($S['register.token']); @@ -24,38 +23,37 @@ function init_register() { } } } - } elseif (!$conf['registration']) return '404'; + } elseif (!$S['conf']['registration']) return '404'; return array('title' => 'Register'); } -function body_register() { - global $S, $request, $conf; +function body_register(&$S) { if (isset($S['user'])) echo print_success('Account creation complete.'); - elseif (isset($request['email'])) { - if (!Validate::email($request['email'])) + elseif (isset($_REQUEST['email'])) { + if (!Validate::email($_REQUEST['email'])) echo print_warning('The email address you entered is invalid.').'<a href="javascript:history.go(-1)">Back</a>'; // 5.3.0 - goto print form else { - if ($S['pdo']->query('SELECT COUNT(*) FROM `users` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_COLUMN)) + if (query('SELECT COUNT(*) FROM `users` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']))->fetch(PDO::FETCH_COLUMN)) echo print_warning('An account already exists with this email address.').'<a href="'.url('login').'">Login</a>'; else { - if ($token=$S['pdo']->query('SELECT * FROM `registrationtokens` WHERE `email`='.$S['pdo']->quote($request['email']))->fetch(PDO::FETCH_ASSOC)) { + if ($token=query('SELECT * FROM `registrationtokens` WHERE `email`='.$S['pdo']->quote($_REQUEST['email']))->fetch(PDO::FETCH_ASSOC)) { echo print_warning('A confirmation email has already been sent to this email address... sending another email.'); $token=new sql_registrationtoken($token); } else { $token=sql_registrationtoken::create(); - $token->email=$request['email']; + $token->email=$_REQUEST['email']; } $token->expire=time()+24*3600; // 24 Hours before expiration (not implemented) $token->write(); - xhtmlemail($request['email'], null, $conf['title'].' account creation', 'To complete your account registration, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>.'); - echo print_success('You will receive an email soon at '.htmlentities($request['email']).' with instructions to finish creating your account.'); + xhtmlemail($_REQUEST['email'], null, $S['conf']['title'].' account creation', 'To complete your account registration, click this link: <a href="'.url('register/'.$token->id).'">'.url('register/'.$token->id).'</a>.'); + echo print_success('You will receive an email soon at '.htmlentities($_REQUEST['email']).' with instructions to finish creating your account.'); } } } elseif (isset($S['register.token'])) { if (isset($S['register.fail'])) echo $S['register.fail']; - echo '<h3>Register</h3><form action="'.url('register').'" method="post"><input type="hidden" name="token" value="'.$request['token'].'" />Display name: <input name="name" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Create Account" /></form>'; + echo '<h3>Register</h3><form action="'.url('register').'" method="post"><input type="hidden" name="token" value="'.$_REQUEST['token'].'" />Display name: <input name="name" /><br/>Password: <input type="password" name="password" /><br/><input type="submit" value="Create Account" /></form>'; } else echo '<h3>Register</h3><form action="'.url('register').'" method="post"> E-mail: <input name="email" /><br/> diff --git a/frontend/pages/stylesheet.php b/frontend/pages/stylesheet.php index 82a7f68..58087a1 100644 --- a/frontend/pages/stylesheet.php +++ b/frontend/pages/stylesheet.php @@ -1,10 +1,8 @@ <?php function init_stylesheet() { - global $state; contenttype('text/css'); } -function body_stylesheet() { - global $conf; +function body_stylesheet(&$S) { foreach (glob('css/*.css') as $file) { require($file); } diff --git a/frontend/pages/upload.php b/frontend/pages/upload.php index 04f8036..5f71eb3 100644 --- a/frontend/pages/upload.php +++ b/frontend/pages/upload.php @@ -1,18 +1,17 @@ <?php -function init_upload() { - global $S, $request; - if (!(isset($request['build'], $request['key'], $_FILES['file']) && preg_match('/^[a-zA-Z0-9]{6}$/', $request['build']) && preg_match('/^[a-zA-Z0-9]{30}$/', $request['key']))) { +function init_upload(&$S) { + if (!(isset($_REQUEST['build'], $_REQUEST['key'], $_FILES['file']) && preg_match('/^[a-zA-Z0-9]{6}$/', $_REQUEST['build']) && preg_match('/^[a-zA-Z0-9]{30}$/', $_REQUEST['key']))) { debug('upload', 'missing or malformed input'); return '404'; } - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"'); + $r=query('SELECT * FROM `builds` WHERE `id`="'.$_REQUEST['build'].'"'); if ($r->rowCount() == 0) { debug('upload', 'build not found'); return '404'; } $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); $opts=$build->get_opts(); - if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $request['key'])) { + if (!(isset($opts['uploadkey']) && $opts['uploadkey'] == $_REQUEST['key'])) { debug('upload', 'invalid upload key'); return '404'; } diff --git a/frontend/pages/welcome.php b/frontend/pages/welcome.php index 4b727e3..2de99a1 100644 --- a/frontend/pages/welcome.php +++ b/frontend/pages/welcome.php @@ -1,13 +1,11 @@ <?php -function init_welcome() { - global $S; +function init_welcome(&$S) { $S['title']='Welcome'; } -function body_welcome() { - global $S; +function body_welcome(&$S) { echo '<h2>Welcome</h2>'; echo '<div class="box"><h3>Most Popular Downloads</h3>'; - $r=$S['pdo']->query('SELECT `build` FROM `downloads` GROUP BY `build` ORDER BY COUNT(*) DESC LIMIT 3'); + $r=query('SELECT `build` FROM `downloads` GROUP BY `build` ORDER BY COUNT(*) DESC LIMIT 3'); if ($r->rowCount()) { while ($build=$r->fetch(PDO::FETCH_COLUMN)) { $build=new sql_build($build); @@ -18,7 +16,7 @@ function body_welcome() { } echo '</div>'; echo '<div class="box"><h3>Recently Downloaded</h3>'; - $r=$S['pdo']->query('SELECT * FROM `downloads` ORDER BY `time` DESC LIMIT 3'); + $r=query('SELECT * FROM `downloads` ORDER BY `time` DESC LIMIT 3'); if ($r->rowCount()) { while ($download=$r->fetch(PDO::FETCH_ASSOC)) { $download=new sql_download($download); @@ -29,7 +27,7 @@ function body_welcome() { } echo '</div>'; echo '<div class="box"><h3>Recently Built</h3>'; - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `status`="finished/success" ORDER BY `finish` DESC LIMIT 3'); + $r=query('SELECT * FROM `builds` WHERE `status`="finished/success" ORDER BY `finish` DESC LIMIT 3'); if ($r->rowCount()) { while ($build=$r->fetch(PDO::FETCH_ASSOC)) { $build=new sql_build($build); |