Skip to content
Browse files

Changed $location to $env['location'] to avoid conflicts. Added suppo…

…rt for custom HTTP response codes via $env['status'].
  • Loading branch information...
1 parent 0f4a8c1 commit 1b73a5228cc6473249db4b0961213762075a5e31 @trustmaster trustmaster committed Sep 17, 2010
View
2 admin.php
@@ -12,7 +12,7 @@
define('COT_CODE', TRUE);
define('COT_ADMIN', TRUE);
define('COT_CORE', TRUE);
-$location = 'Administration';
+$env['location'] = 'administration';
$z = 'admin';
require_once './datas/config.php';
View
2 install.php
@@ -13,7 +13,7 @@
define('COT_CODE', TRUE);
define('COT_INSTALL', TRUE);
//define('COT_ADMIN', TRUE);
-$location = 'Install';
+$env['location'] = 'install';
$z = 'install';
if (file_exists('./datas/config.php'))
View
20 message.php
@@ -12,7 +12,7 @@
define('COT_CODE', TRUE);
define('COT_MESSAGE', TRUE);
define('COT_CORE', TRUE);
-$location = 'Messages';
+$env['location'] = 'messages';
$z = 'message';
require_once './datas/config.php';
@@ -59,7 +59,7 @@
case '153':
if ($num > 0)
{
- $body .= "<br />(-> ".date($cfg['dateformat'], $num)."GMT".")";
+ $body .= cot_rc('msg_code_153_date', array('date' => date($cfg['dateformat'], $num)));
}
break;
@@ -116,19 +116,19 @@
switch ($rc)
{
case '100':
- $r['100'] = cot_url('admin', "m=plug");
+ $r['100'] = cot_url('admin', 'm=plug');
break;
case '101':
- $r['101'] = cot_url('admin', "m=hitsperday");
+ $r['101'] = cot_url('admin', 'm=hitsperday');
break;
case '102':
- $r['102'] = cot_url('admin', "m=polls");
+ $r['102'] = cot_url('admin', 'm=polls');
break;
case '103':
- $r['103'] = cot_url('admin', "m=forums");
+ $r['103'] = cot_url('admin', 'm=forums');
break;
case '200':
@@ -146,8 +146,8 @@
{
$r["$rc"] = COT_ABSOLUTE_URL . $r["$rc"];
}
- $plug_head .= "<meta http-equiv=\"refresh\" content=\"2;url=".$r["$rc"]."\" /><br />"; // TODO: in resources
- $body .= "<br />".$L['msgredir'];
+ $out['head'] .= cot_rc('msg_code_redir_head', array('delay' => 2, 'url' => $r["$rc"]));
+ $body .= $R['code_error_separator'] . $L['msgredir'];
}
elseif ($rd != '')
@@ -156,8 +156,8 @@
{
$ru = COT_ABSOLUTE_URL.ltrim($ru, '/');
}
- $plug_head .= "<meta http-equiv=\"refresh\" content=\"".$rd.";url=".$ru."\" />"; // TODO: in resources
- $body .= "<br />".$L['msgredir'];
+ $out['head'] .= cot_rc('msg_code_redir_head', array('delay' => $rd, 'url' => $ru));
+ $body .= $R['code_error_separator'] . $L['msgredir'];
}
/* === Hook === */
View
2 modules/forums/forums.php
@@ -21,7 +21,7 @@
// Environment setup
define('COT_FORUMS', TRUE);
-$location = 'Forums';
+$env['location'] = 'forums';
// Additional requirements
cot_require_api('extrafields');
View
2 modules/index/index.php
@@ -19,7 +19,7 @@
// Environment setup
define('COT_INDEX', TRUE);
-$location = 'Home';
+$env['location'] = 'home';
/* === Hook === */
foreach (cot_getextplugins('index.first') as $pl)
View
2 modules/page/inc/page.list.php
@@ -15,7 +15,7 @@
// Environment setup
define('COT_LIST', TRUE);
-$location = 'List';
+$env['location'] = 'list';
$s = cot_import('s', 'G', 'ALP'); // order field name without "page_"
$w = cot_import('w', 'G', 'ALP', 4); // order way (asc, desc)
View
8 modules/page/inc/page.main.php
@@ -32,7 +32,11 @@
LEFT JOIN $db_users AS u ON u.user_id=p.page_ownerid
WHERE $where LIMIT 1");
-cot_die(cot_db_numrows($sql) == 0);
+if(cot_db_numrows($sql) == 0)
+{
+ $env['status'] = '404 Not Found';
+ cot_redirect(cot_url('message', 'msg=404', '', true));
+}
$pag = cot_db_fetcharray($sql);
list($usr['auth_read'], $usr['auth_write'], $usr['isadmin'], $usr['auth_download']) = cot_auth('page', $pag['page_cat'], 'RWA1');
@@ -51,11 +55,13 @@
if ($pag['page_state'] == 1 && !$usr['isadmin'] && $usr['id'] != $pag['page_ownerid'])
{
+ $env['status'] = '403 Forbidden';
cot_log("Attempt to directly access an un-validated page", 'sec'); // TODO i18n
cot_redirect(cot_url('message', "msg=930", '', true));
}
if (mb_substr($pag['page_text'], 0, 6) == 'redir:')
{
+ $env['status'] = '303 See Other';
$redir = trim(str_replace('redir:', '', $pag['page_text']));
$sql = cot_db_query("UPDATE $db_pages SET page_filecount=page_filecount+1 WHERE page_id='".$id."'");
header('Location: ' . (preg_match('#^(http|ftp)s?://#', $redir) ? '' : COT_ABSOLUTE_URL) . $redir);
View
2 modules/page/page.php
@@ -21,7 +21,7 @@
// Environment setup
define('COT_PAGES', TRUE);
-$location = 'Pages';
+$env['location'] = 'pages';
// Additional API requirements
cot_require_api('extrafields');
View
2 modules/pfs/pfs.php
@@ -21,7 +21,7 @@
// Environment setup
define('COT_PFS', TRUE);
-$location = 'PFS';
+$env['location'] = 'pfs';
// Additional API requirements
cot_require_api('uploads');
View
2 modules/pm/inc/pm.send.php
@@ -15,6 +15,8 @@
list($usr['auth_read'], $usr['auth_write'], $usr['isadmin']) = cot_auth('pm', 'a');
cot_block($usr['auth_write']);
+cot_require_api('email');
+
$to = cot_import('to', 'G', 'TXT');
$a = cot_import('a','G','TXT');
$id = cot_import('id','G','INT');
View
2 modules/pm/pm.php
@@ -21,7 +21,7 @@
// Environment setup
define('COT_PM', TRUE);
-$location = 'Private_Messages';
+$env['location'] = 'private_messages';
// Additional API requirements
cot_require_api('extrafields');
View
2 modules/polls/polls.php
@@ -21,7 +21,7 @@
// Environment setup
define('COT_POLLS', TRUE);
-$location = 'Polls';
+$env['location'] = 'polls';
/* === Hook === */
foreach (cot_getextplugins('polls.first') as $pl)
View
2 modules/rss/rss.php
@@ -34,7 +34,7 @@
// Environment setup
define('COT_RSS', TRUE);
-$location = 'RSS';
+$env['location'] = 'rss';
cot_dieifdisabled($cfg['disable_rss']);
View
2 modules/view/view.php
@@ -19,7 +19,7 @@
// Environment setup
define('COT_VIEW', TRUE);
-$location = 'Views';
+$env['location'] = 'views';
$v = cot_import('v', 'G', 'TXT');
View
2 system/footer.php
@@ -65,7 +65,7 @@
}
/* ===== */
- $mskin = cot_skinfile($cfg['enablecustomhf'] ? array('footer', mb_strtolower($location)) : 'footer', '+', defined('COT_ADMIN'));
+ $mskin = cot_skinfile($cfg['enablecustomhf'] ? array('footer', $env['location']) : 'footer', '+', defined('COT_ADMIN'));
$t = new XTemplate($mskin);
$t->assign(array(
View
31 system/functions.php
@@ -482,38 +482,38 @@ function cot_load_structure()
* @global string $db_online
* @global Cache $cot_cache
* @global array $cot_usersonline
- * @global string $location Location string
+ * @global array $env
*/
function cot_online_update()
{
- global $cfg, $sys, $usr, $out, $db_online, $db_stats, $cot_cache, $cot_usersonline, $location, $Ls;
+ global $cfg, $sys, $usr, $out, $db_online, $db_stats, $cot_cache, $cot_usersonline, $env, $Ls;
if (!$cfg['disablewhosonline'])
{
- if ($location != $sys['online_location']
+ if ($env['location'] != $sys['online_location']
|| !empty($sys['sublocaction']) && $sys['sublocaction'] != $sys['online_subloc'])
{
if ($usr['id'] > 0)
{
if (empty($sys['online_location']))
{
cot_db_query("INSERT INTO $db_online (online_ip, online_name, online_lastseen, online_location, online_subloc, online_userid, online_shield, online_hammer)
- VALUES ('".$usr['ip']."', '".cot_db_prep($usr['name'])."', ".(int)$sys['now'].", '".cot_db_prep($location)."', '".cot_db_prep($sys['sublocation'])."', ".(int)$usr['id'].", 0, 0)");
+ VALUES ('".$usr['ip']."', '".cot_db_prep($usr['name'])."', ".(int)$sys['now'].", '".cot_db_prep($env['location'])."', '".cot_db_prep($sys['sublocation'])."', ".(int)$usr['id'].", 0, 0)");
}
else
{
- cot_db_query("UPDATE $db_online SET online_lastseen='".$sys['now']."', online_location='".cot_db_prep($location)."', online_subloc='".cot_db_prep($sys['sublocation'])."', online_hammer=".(int)$sys['online_hammer']." WHERE online_userid=".$usr['id']);
+ cot_db_query("UPDATE $db_online SET online_lastseen='".$sys['now']."', online_location='".cot_db_prep($env['location'])."', online_subloc='".cot_db_prep($sys['sublocation'])."', online_hammer=".(int)$sys['online_hammer']." WHERE online_userid=".$usr['id']);
}
}
else
{
if (empty($sys['online_location']))
{
cot_db_query("INSERT INTO $db_online (online_ip, online_name, online_lastseen, online_location, online_subloc, online_userid, online_shield, online_hammer)
- VALUES ('".$usr['ip']."', 'v', ".(int)$sys['now'].", '".cot_db_prep($location)."', '".cot_db_prep($sys['sublocation'])."', -1, 0, 0)");
+ VALUES ('".$usr['ip']."', 'v', ".(int)$sys['now'].", '".cot_db_prep($env['location'])."', '".cot_db_prep($sys['sublocation'])."', -1, 0, 0)");
}
else
{
- cot_db_query("UPDATE $db_online SET online_lastseen='".$sys['now']."', online_location='".$location."', online_subloc='".cot_db_prep($sys['sublocation'])."', online_hammer=".(int)$sys['online_hammer']." WHERE online_ip='".$usr['ip']."'");
+ cot_db_query("UPDATE $db_online SET online_lastseen='".$sys['now']."', online_location='".$env['location']."', online_subloc='".cot_db_prep($sys['sublocation'])."', online_hammer=".(int)$sys['online_hammer']." WHERE online_ip='".$usr['ip']."'");
}
}
}
@@ -604,13 +604,13 @@ function cot_outputfilters($output)
* Sends standard HTTP headers and disables browser cache
*
* @param string $content_type Content-Type value (without charset)
- * @param string $status_line HTTP status line containing response code
+ * @param string $response_code HTTP response code, e.g. '404 Not Found'
* @return bool
*/
-function cot_sendheaders($content_type = 'text/html', $status_line = 'HTTP/1.1 200 OK')
+function cot_sendheaders($content_type = 'text/html', $response_code = '200 OK')
{
global $cfg;
- header($status_line);
+ header('HTTP/1.1 ' . $response_code);
header('Expires: Mon, Apr 01 1974 00:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: post-check=0,pre-check=0', FALSE);
@@ -1794,9 +1794,11 @@ function cot_clear_messages($src = '', $class = '')
*/
function cot_die($cond=TRUE)
{
+ global $env;
if ($cond)
{
- cot_redirect(cot_url('message', "msg=950", '', true));
+ $env['status'] = '403 Forbidden';
+ cot_redirect(cot_url('message', 'msg=950', '', true));
}
return FALSE;
}
@@ -2971,7 +2973,7 @@ function cot_load_urltrans()
*/
function cot_redirect($url)
{
- global $cfg, $cot_error;
+ global $cfg, $cot_error, $env;
if ($cot_error && $_SERVER['REQUEST_METHOD'] == 'POST')
{
@@ -2984,6 +2986,11 @@ function cot_redirect($url)
$url = COT_ABSOLUTE_URL . $url;
}
+ if (isset($env['status']))
+ {
+ header('HTTP/1.1' . $env['status']);
+ }
+
if ($cfg['redirmode'])
{
$output = $cfg['doctype'].<<<HTM
View
11 system/header.php
@@ -47,7 +47,14 @@
$out['meta_lastmod'] = gmdate('D, d M Y H:i:s');
$out['head_head'] = $out['head'];
-cot_sendheaders($out['meta_contenttype']);
+if (isset($env['status']))
+{
+ cot_sendheaders($out['meta_contenttype'], $env['status']);
+}
+else
+{
+ cot_sendheaders($out['meta_contenttype']);
+}
if (!COT_AJAX)
{
@@ -99,7 +106,7 @@
}
/* ===== */
- $mskin = cot_skinfile($cfg['enablecustomhf'] ? array('header', mb_strtolower($location)) : 'header', '+', defined('COT_ADMIN'));
+ $mskin = cot_skinfile($cfg['enablecustomhf'] ? array('header', $env['location']) : 'header', '+', defined('COT_ADMIN'));
$t = new XTemplate($mskin);
$t->assign(array(
View
6 system/resources.php
@@ -62,6 +62,12 @@
$R['form_guest_username'] = '<input type="text" name="rusername" size="12" maxlength="100" />';
/**
+ * Messages
+ */
+$R['msg_code_153_date'] = '<br />(-&gt; {$date}GMT)';
+$R['msg_code_redir_head'] = '<meta http-equiv="refresh" content="{$delay};url={$url}" />';
+
+/**
* Misc
*/
View
2 users.php
@@ -12,7 +12,7 @@
define('COT_CODE', TRUE);
define('COT_USERS', TRUE);
define('COT_CORE', TRUE);
-$location = 'Users';
+$env['location'] = 'users';
$z = 'users';
if (isset($_GET['m']) && $_GET['m'] == 'auth')

0 comments on commit 1b73a52

Please sign in to comment.
Something went wrong with that request. Please try again.