Cope with secondary (per forum) styles, probably other minor things too ... there is a known permissions problem, will work on that soon

git-svn-id: file:///svn/phpbb/trunk@4235 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Paul S. Owen 2003-07-13 15:13:59 +00:00
parent 4051c18ac3
commit 91a6952683
2 changed files with 73 additions and 37 deletions

View file

@ -56,11 +56,17 @@ class session
$this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $REMOTE_ADDR; $this->ip = (!empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : $REMOTE_ADDR;
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
if (preg_match('#^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)#', $_SERVER['HTTP_X_FORWARDED_FOR'], $ip_list))
{ {
$private_ip = array('#^0\.#', '#^127\.0\.0\.1#', '#^192\.168\.#', '#^172\.16\.#', '#^10\.#', '#^224\.#', '#^240\.#'); $private_ip = array('#^0\.#', '#^127\.0\.0\.1#', '#^192\.168\.#', '#^172\.16\.#', '#^10\.#', '#^224\.#', '#^240\.#');
$this->ip = preg_replace($private_ip, $this->ip, $ip_list[1]); foreach (explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']) as $x_ip)
{
if (preg_match('#([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)#', $x_ip, $ip_list))
{
if (($this->ip = trim(preg_replace($private_ip, $this->ip, $ip_list[1]))) == trim($ip_list[1]))
{
break;
}
}
} }
} }
@ -82,8 +88,8 @@ class session
// Added session check // Added session check
if (!empty($this->session_id) && (!defined('NEED_SID') || $this->session_id == $_GET['sid'])) if (!empty($this->session_id) && (!defined('NEED_SID') || $this->session_id == $_GET['sid']))
{ {
$sql = "SELECT u.*, s.* $sql = 'SELECT u.*, s.*
FROM " . SESSIONS_TABLE . " s, " . USERS_TABLE . " u FROM ' . SESSIONS_TABLE . ' s, ' . USERS_TABLE . " u
WHERE s.session_id = '" . $this->session_id . "' WHERE s.session_id = '" . $this->session_id . "'
AND u.user_id = s.session_user_id"; AND u.user_id = s.session_user_id";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -106,7 +112,7 @@ class session
// Only update session DB a minute or so after last update or if page changes // Only update session DB a minute or so after last update or if page changes
if (($current_time - $this->data['session_time'] > 60 || $this->data['session_page'] != $this->page) && $update) if (($current_time - $this->data['session_time'] > 60 || $this->data['session_page'] != $this->page) && $update)
{ {
$sql = "UPDATE " . SESSIONS_TABLE . " $sql = 'UPDATE ' . SESSIONS_TABLE . "
SET session_time = $current_time, session_page = '" . $db->sql_escape($this->page) . "' SET session_time = $current_time, session_page = '" . $db->sql_escape($this->page) . "'
WHERE session_id = '" . $this->session_id . "'"; WHERE session_id = '" . $this->session_id . "'";
$db->sql_query($sql); $db->sql_query($sql);
@ -166,9 +172,9 @@ class session
} }
// Grab user data ... join on session if it exists for session time // Grab user data ... join on session if it exists for session time
$sql = "SELECT u.*, s.session_time $sql = 'SELECT u.*, s.session_time
FROM (" . USERS_TABLE . " u FROM (' . USERS_TABLE . ' u
LEFT JOIN " . SESSIONS_TABLE . " s ON s.session_user_id = u.user_id) LEFT JOIN ' . SESSIONS_TABLE . " s ON s.session_user_id = u.user_id)
WHERE u.user_id = $user_id WHERE u.user_id = $user_id
ORDER BY s.session_time DESC"; ORDER BY s.session_time DESC";
$result = $db->sql_query($sql); $result = $db->sql_query($sql);
@ -187,7 +193,18 @@ class session
if (!$this->data['user_founder']) if (!$this->data['user_founder'])
{ {
$banned = false; $banned = false;
/*
$sql = 'SELECT 1
FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
WHERE g.group_name = \'BANNED\'
AND g.group_type = ' . GROUP_SPECIAL . '
AND ug.group_id = g.group_id
AND ug.user_id = ' . $this->data['user_id'];
$result = $db->sql_query($sql);
$banned = ($db->sql_fetchrow($result)) ? true : false;
$db->sql_freeresult($result);
*/
$sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end $sql = 'SELECT ban_ip, ban_userid, ban_email, ban_exclude, ban_give_reason, ban_end
FROM ' . BANLIST_TABLE . ' FROM ' . BANLIST_TABLE . '
WHERE ban_end >= ' . time() . ' WHERE ban_end >= ' . time() . '
@ -239,7 +256,7 @@ class session
// Create or update the session // Create or update the session
$db->sql_return_on_error(true); $db->sql_return_on_error(true);
$sql = "UPDATE " . SESSIONS_TABLE . " $sql = 'UPDATE ' . SESSIONS_TABLE . "
SET session_user_id = $user_id, session_last_visit = " . $this->data['session_last_visit'] . ", session_start = $current_time, session_time = $current_time, session_browser = '$this->browser', session_page = '$this->page', session_allow_viewonline = $viewonline SET session_user_id = $user_id, session_last_visit = " . $this->data['session_last_visit'] . ", session_start = $current_time, session_time = $current_time, session_browser = '$this->browser', session_page = '$this->page', session_allow_viewonline = $viewonline
WHERE session_id = '" . $this->session_id . "'"; WHERE session_id = '" . $this->session_id . "'";
if ($this->session_id == '' || !$db->sql_query($sql) || !$db->sql_affectedrows()) if ($this->session_id == '' || !$db->sql_query($sql) || !$db->sql_affectedrows())
@ -247,7 +264,7 @@ class session
$db->sql_return_on_error(false); $db->sql_return_on_error(false);
$this->session_id = md5(uniqid($this->ip)); $this->session_id = md5(uniqid($this->ip));
$sql = "INSERT INTO " . SESSIONS_TABLE . " $sql = 'INSERT INTO ' . SESSIONS_TABLE . "
(session_id, session_user_id, session_last_visit, session_start, session_time, session_ip, session_browser, session_page, session_allow_viewonline) (session_id, session_user_id, session_last_visit, session_start, session_time, session_ip, session_browser, session_page, session_allow_viewonline)
VALUES ('" . $this->session_id . "', $user_id, " . $this->data['session_last_visit'] . ", $current_time, $current_time, '$this->ip', '$this->browser', '$this->page', $viewonline)"; VALUES ('" . $this->session_id . "', $user_id, " . $this->data['session_last_visit'] . ", $current_time, $current_time, '$this->ip', '$this->browser', '$this->page', $viewonline)";
$db->sql_query($sql); $db->sql_query($sql);
@ -324,7 +341,7 @@ class session
$db->sql_query($sql); $db->sql_query($sql);
} }
$del_user_id .= (($del_user_id != '') ? ', ' : '') . " '" . $row['session_user_id'] . "'"; $del_user_id .= (($del_user_id != '') ? ', ' : '') . $row['session_user_id'];
$del_sessions++; $del_sessions++;
} }
while ($row = $db->sql_fetchrow($result)); while ($row = $db->sql_fetchrow($result));
@ -447,22 +464,30 @@ class user extends session
// Set up style // Set up style
$style = ($style) ? $style : ((!$config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $config['default_style']); $style = ($style) ? $style : ((!$config['override_user_style'] && $this->data['user_id'] != ANONYMOUS) ? $this->data['user_style'] : $config['default_style']);
$sql = "SELECT DISTINCT t.*, c.*, i.* $sql = 'SELECT DISTINCT s.style_id, t.*, c.*, i.*
FROM " . STYLES_TABLE . " s, " . STYLES_TPL_TABLE . " t, " . STYLES_CSS_TABLE . " c, " . STYLES_IMAGE_TABLE . " i FROM ' . STYLES_TABLE . ' s, ' . STYLES_TPL_TABLE . ' t, ' . STYLES_CSS_TABLE . ' c, ' . STYLES_IMAGE_TABLE . " i
WHERE s.style_id IN ($style, " . $config['default_style'] . ") WHERE s.style_id IN ($style, " . $config['default_style'] . ')
AND t.template_id = s.template_id AND t.template_id = s.template_id
AND c.theme_id = s.style_id AND c.theme_id = s.theme_id
AND i.imageset_id = s.imageset_id"; AND i.imageset_id = s.imageset_id';
$result = $db->sql_query($sql, 600); $result = $db->sql_query($sql, 600);
if (!($this->theme = $db->sql_fetchrow($result))) if (!($row = $db->sql_fetchrow($result)))
{ {
trigger_error('Could not get style data'); trigger_error('Could not get style data');
} }
$template->set_template($this->theme['template_path']); $this->theme = ($row2 = $db->sql_fetchrow($result)) ? array(
($style == $row['style_id']) ? 'primary' : 'secondary' => $row,
($style == $row2['style_id']) ? 'primary' : 'secondary' => $row2) : array('primary' => $row);
$this->img_lang = (file_exists($phpbb_root_path . 'imagesets/' . $this->theme['imageset_path'] . '/' . $this->lang_name)) ? $this->lang_name : $config['default_lang']; $db->sql_freeresult($result);
unset($row);
unset($row2);
$template->set_template();
$this->img_lang = (file_exists($phpbb_root_path . 'styles/imagesets/' . $this->theme['default']['imageset_path'] . '/' . $this->lang_name)) ? $this->lang_name : $config['default_lang'];
return; return;
} }
@ -491,7 +516,8 @@ class user extends session
$alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : ''; $alt = (!empty($this->lang[$alt])) ? $this->lang[$alt] : '';
$width = ($width) ? 'width="' . $width . '" ' : ''; $width = ($width) ? 'width="' . $width . '" ' : '';
$imgs[$img] = '<img src=' . str_replace('{LANG}', $this->img_lang, $this->theme[$img]) . ' ' . $width . 'alt="' . $alt . '" title="' . $alt . '" name="' . $img . '"/>';
$imgs[$img] = '<img src=' . str_replace('{LANG}', $this->img_lang, $this->theme['primary'][$img]) . ' ' . $width . 'alt="' . $alt . '" title="' . $alt . '" name="' . $img . '"/>';
} }
return $imgs[$img]; return $imgs[$img];
} }

View file

@ -37,7 +37,7 @@
to this source to this source
*/ */
class Template class template
{ {
// variable that holds all the data we'll be substituting into // variable that holds all the data we'll be substituting into
@ -48,6 +48,7 @@ class Template
var $_tpldata = array(); var $_tpldata = array();
// Root dir and hash of filenames for each template handle. // Root dir and hash of filenames for each template handle.
var $tpl = '';
var $root = ''; var $root = '';
var $cache_root = 'cache/templates/'; var $cache_root = 'cache/templates/';
var $files = array(); var $files = array();
@ -63,13 +64,22 @@ class Template
var $static_lang; var $static_lang;
var $force_recompile; var $force_recompile;
function set_template($static_lang = false, $force_recompile = false)
function set_template($template = '', $static_lang = false, $force_recompile = true)
{ {
global $phpbb_root_path; global $phpbb_root_path, $config, $user;
$this->root = $phpbb_root_path . 'templates/' . $template; if (file_exists($phpbb_root_path . 'styles/templates/' . $user->theme['primary']['template_path']))
$this->cachedir = $phpbb_root_path . $this->cache_root . $template . '/'; {
// $this->tpl = 'primary';
$this->root = $phpbb_root_path . 'styles/templates/' . $user->theme['primary']['template_path'];
$this->cachedir = $phpbb_root_path . $this->cache_root . $user->theme['primary']['template_path'] . '/';
}
else
{
// $this->tpl = 'secondary';
$this->root = $phpbb_root_path . 'styles/templates/' . $user->theme['secondary']['template_path'];
$this->cachedir = $phpbb_root_path . $this->cache_root . $user->theme['secondary']['template_path'] . '/';
}
$this->static_lang = $static_lang; $this->static_lang = $static_lang;
$this->force_recompile = $force_recompile; $this->force_recompile = $force_recompile;
@ -101,20 +111,12 @@ class Template
} }
$this->filename[$handle] = $filename; $this->filename[$handle] = $filename;
$this->files[$handle] = $this->make_filename($filename); $this->files[$handle] = $this->root . '/' . $filename;
} }
return true; return true;
} }
// Generates a full path+filename for the given filename, which can either
// be an absolute name, or a name relative to the rootdir for this Template
// object.
function make_filename($filename)
{
// Check if it's an absolute or relative path.
return (substr($filename, 0, 1) != '/') ? $this->root . '/' . $filename : $filename;
}
// Destroy template data set // Destroy template data set
function destroy() function destroy()
@ -140,6 +142,7 @@ class Template
return true; return true;
} }
// Load a compiled template if possible, if not, recompile it // Load a compiled template if possible, if not, recompile it
function _tpl_load(&$handle) function _tpl_load(&$handle)
{ {
@ -153,6 +156,7 @@ class Template
return $filename; return $filename;
} }
// If the file for this handle is already loaded and compiled, do nothing. // If the file for this handle is already loaded and compiled, do nothing.
if (!empty($this->uncompiled_code[$handle])) if (!empty($this->uncompiled_code[$handle]))
{ {
@ -165,6 +169,12 @@ class Template
trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR); trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR);
} }
if (!file_exists($this->files[$handle]))
{
// $this->tpl = 'secondary';
$this->files[$handle] = $phpbb_root_path . 'styles/templates/' . $user->theme['secondary']['template_path'] . '/' . $this->filename[$handle];
}
$str = ''; $str = '';
// Try and open template for read // Try and open template for read
if (!($fp = @fopen($this->files[$handle], 'r'))) if (!($fp = @fopen($this->files[$handle], 'r')))
@ -242,7 +252,7 @@ class Template
$handle = $filename; $handle = $filename;
$this->filename[$handle] = $filename; $this->filename[$handle] = $filename;
$this->files[$handle] = $this->make_filename($filename); $this->files[$handle] = $this->root . '/' . $filename;
$filename = $this->_tpl_load($handle); $filename = $this->_tpl_load($handle);