aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/acm/acm_db.php2
-rw-r--r--phpBB/includes/acm/acm_file.php24
-rw-r--r--phpBB/includes/acp/acp_groups.php700
-rw-r--r--phpBB/includes/functions.php29
-rw-r--r--phpBB/includes/functions_module.php20
-rw-r--r--phpBB/includes/functions_template.php668
-rw-r--r--phpBB/includes/functions_user.php112
-rw-r--r--phpBB/includes/template.php679
-rw-r--r--phpBB/includes/ucp/ucp_profile.php82
9 files changed, 1584 insertions, 732 deletions
diff --git a/phpBB/includes/acm/acm_db.php b/phpBB/includes/acm/acm_db.php
index ecabae0fd5..a9b75a9a77 100644
--- a/phpBB/includes/acm/acm_db.php
+++ b/phpBB/includes/acm/acm_db.php
@@ -159,7 +159,7 @@ class acm
if (empty($this->var_ready[$var_name]))
{
$this->vars[$var_name] = unserialize($this->vars[$var_name]);
- $this->var_ready[$var_name] = TRUE;
+ $this->var_ready[$var_name] = true;
}
return $this->vars[$var_name];
diff --git a/phpBB/includes/acm/acm_file.php b/phpBB/includes/acm/acm_file.php
index 4efc3621e1..8f7e79aad5 100644
--- a/phpBB/includes/acm/acm_file.php
+++ b/phpBB/includes/acm/acm_file.php
@@ -132,7 +132,7 @@ class acm
if ($fp = @fopen($this->cache_dir . 'data' . $var_name . ".$phpEx", 'wb'))
{
@flock($fp, LOCK_EX);
- fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? TRUE : FALSE;\nif (\$expired) { return; }\n\n\$data = unserialize('" . str_replace("'", "\\'", str_replace('\\', '\\\\', serialize($var))) . "');\n?>");
+ fwrite($fp, "<?php\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$data = unserialize('" . str_replace("'", "\\'", str_replace('\\', '\\\\', serialize($var))) . "');\n?>");
@flock($fp, LOCK_UN);
fclose($fp);
}
@@ -141,7 +141,7 @@ class acm
{
$this->vars[$var_name] = $var;
$this->var_expires[$var_name] = time() + $ttl;
- $this->is_modified = TRUE;
+ $this->is_modified = true;
}
}
@@ -172,13 +172,13 @@ class acm
}
@closedir($dir);
}
- elseif ($var_name{0} == '_')
+ else if ($var_name{0} == '_')
{
@unlink($this->cache_dir . 'data' . $var_name . ".$phpEx");
}
- elseif (isset($this->vars[$var_name]))
+ else if (isset($this->vars[$var_name]))
{
- $this->is_modified = TRUE;
+ $this->is_modified = true;
unset($this->vars[$var_name]);
unset($this->var_expires[$var_name]);
}
@@ -216,13 +216,13 @@ class acm
{
$lines[] = "'$k'=>" . $this->format_array($v);
}
- elseif (is_int($v))
+ else if (is_int($v))
{
$lines[] = "'$k'=>$v";
}
- elseif (is_bool($v))
+ else if (is_bool($v))
{
- $lines[] = "'$k'=>" . (($v) ? 'TRUE' : 'FALSE');
+ $lines[] = "'$k'=>" . (($v) ? 'true' : 'false');
}
else
{
@@ -249,12 +249,12 @@ class acm
if (!isset($expired))
{
- return FALSE;
+ return false;
}
- elseif ($expired)
+ else if ($expired)
{
unlink($this->cache_dir . 'sql_' . md5($query) . ".$phpEx");
- return FALSE;
+ return false;
}
return $query_id;
@@ -283,7 +283,7 @@ class acm
}
$db->sql_freeresult($query_result);
- fwrite($fp, "<?php\n\n/*\n$query\n*/\n\n\$expired = (time() > " . (time() + $ttl) . ") ? TRUE : FALSE;\nif (\$expired) { return; }\n\n\$this->sql_rowset[\$query_id] = array(" . implode(',', $lines) . ') ?>');
+ fwrite($fp, "<?php\n\n/*\n$query\n*/\n\n\$expired = (time() > " . (time() + $ttl) . ") ? true : false;\nif (\$expired) { return; }\n\n\$this->sql_rowset[\$query_id] = array(" . implode(',', $lines) . ') ?>');
@flock($fp, LOCK_UN);
fclose($fp);
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php
new file mode 100644
index 0000000000..70715f2e1f
--- /dev/null
+++ b/phpBB/includes/acp/acp_groups.php
@@ -0,0 +1,700 @@
+<?php
+/**
+*
+* @package acp
+* @version $Id$
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @package acp
+*/
+class acp_groups
+{
+ function main($id, $mode)
+ {
+ global $config, $db, $user, $auth, $template, $cache;
+ global $SID, $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
+
+ $user->add_lang('acp/groups');
+ $this->tpl_name = 'acp_groups';
+ $this->page_title = 'ACP_GROUPS_MANAGE';
+
+ $u_action = "{$phpbb_admin_path}index.$phpEx$SID&amp;i=$id&amp;mode=$mode";
+
+ include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+
+ // Check and set some common vars
+ $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : request_var('action', ''));
+ $group_id = request_var('g', 0);
+ $mark_ary = request_var('mark', array(0));
+ $name_ary = request_var('usernames', '');
+ $leader = request_var('leader', 0);
+ $default = request_var('default', 0);
+ $start = request_var('start', 0);
+ $update = (isset($_POST['update'])) ? true : false;
+
+ // Clear some vars
+ $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
+ $group_row = array();
+
+ // Grab basic data for group, if group_id is set and exists
+ if ($group_id)
+ {
+ $sql = 'SELECT *
+ FROM ' . GROUPS_TABLE . "
+ WHERE group_id = $group_id";
+ $result = $db->sql_query($sql);
+ $group_row = $db->sql_fetchrow($result);
+ $db->sql_freeresult($result);
+
+ if (!$group_row)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+ }
+
+ // Which page?
+ switch ($action)
+ {
+ case 'approve':
+ case 'demote':
+ case 'promote':
+ if (!$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ // Approve, demote or promote
+ group_user_attributes($action, $group_id, $mark_ary, false, ($group_id) ? $group_row['group_name'] : false);
+
+ switch ($action)
+ {
+ case 'demote':
+ $message = 'GROUP_MODS_DEMOTED';
+ break;
+
+ case 'promote':
+ $message = 'GROUP_MODS_PROMOTED';
+ break;
+
+ case 'approve':
+ $message = 'USERS_APPROVED';
+ break;
+ }
+
+ trigger_error($user->lang[$message] . adm_back_link($u_action));
+ break;
+
+ case 'default':
+ if (!$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ if (confirm_box(true))
+ {
+ if (!sizeof($mark_ary))
+ {
+ $start = 0;
+
+ do
+ {
+ $sql = 'SELECT user_id
+ FROM ' . USER_GROUP_TABLE . "
+ WHERE group_id = $group_id
+ ORDER BY user_id";
+ $result = $db->sql_query_limit($sql, 200, $start);
+
+ $mark_ary = array();
+ if ($row = $db->sql_fetchrow($result))
+ {
+ do
+ {
+ $mark_ary[] = $row['user_id'];
+ }
+ while ($row = $db->sql_fetchrow($result));
+
+ group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
+
+ $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
+ }
+ else
+ {
+ $start = 0;
+ }
+ $db->sql_freeresult($result);
+ }
+ while ($start);
+ }
+ else
+ {
+ group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
+ }
+
+ trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($u_action));
+ }
+ else
+ {
+ confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
+ 'mark' => $mark_ary,
+ 'g' => $group_id,
+ 'i' => $id,
+ 'mode' => $mode,
+ 'action' => $action))
+ );
+ }
+
+ break;
+
+ case 'deleteusers':
+ case 'delete':
+ if (confirm_box(true))
+ {
+ if (!$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ $error = '';
+
+ switch ($action)
+ {
+ case 'delete':
+ $error = group_delete($group_id, $group_row['group_name']);
+ break;
+
+ case 'deleteusers':
+ $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']);
+ break;
+ }
+
+ if ($error)
+ {
+ trigger_error($user->lang[$error] . adm_back_link($u_action));
+ }
+
+ $message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
+ trigger_error($user->lang[$message] . adm_back_link($u_action));
+ }
+ else
+ {
+ confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
+ 'mark' => $mark_ary,
+ 'g' => $group_id,
+ 'i' => $id,
+ 'mode' => $mode,
+ 'action' => $action))
+ );
+ }
+ break;
+
+ case 'addusers':
+ if (!$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ if (!$name_ary)
+ {
+ trigger_error($user->lang['NO_USERS'] . adm_back_link($u_action));
+ }
+
+ $name_ary = array_unique(explode("\n", $name_ary));
+
+ // Add user/s to group
+ if ($error = group_user_add($group_id, false, $name_ary, $group_row['group_name'], $default, $leader, 0, $group_row))
+ {
+ trigger_error($user->lang[$error] . adm_back_link($u_action));
+ }
+
+ $message = ($action == 'addleaders') ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
+ trigger_error($user->lang[$message] . adm_back_link($u_action));
+ break;
+
+ case 'edit':
+ case 'add':
+
+ $data = $submit_ary = array();
+
+ if ($action == 'edit' && !$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ $error = array();
+ $user->add_lang('ucp');
+
+ $avatar_select = basename(request_var('avatar_select', ''));
+ $category = basename(request_var('category', ''));
+
+ // Did we submit?
+ if ($update)
+ {
+ $group_name = request_var('group_name', '');
+ $group_description = request_var('group_description', '');
+ $group_type = request_var('group_type', GROUP_FREE);
+
+ $data['uploadurl'] = request_var('uploadurl', '');
+ $data['remotelink'] = request_var('remotelink', '');
+ $delete = request_var('delete', '');
+
+ $submit_ary = array(
+ 'colour' => request_var('group_colour', ''),
+ 'rank' => request_var('group_rank', 0),
+ 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
+ 'message_limit' => request_var('group_message_limit', 0)
+ );
+
+ if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
+ {
+ $data['width'] = request_var('width', '');
+ $data['height'] = request_var('height', '');
+
+ // Avatar stuff
+ $var_ary = array(
+ 'uploadurl' => array('string', true, 5, 255),
+ 'remotelink' => array('string', true, 5, 255),
+ 'width' => array('string', true, 1, 3),
+ 'height' => array('string', true, 1, 3),
+ );
+
+ if (!($error = validate_data($data, $var_ary)))
+ {
+ $data['user_id'] = "g$group_id";
+
+ if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
+ {
+ list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
+ }
+ else if ($data['remotelink'])
+ {
+ list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
+ }
+ }
+ }
+ else if ($avatar_select && $config['allow_avatar_local'])
+ {
+ // check avatar gallery
+ if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
+ {
+ $submit_ary['avatar_type'] = AVATAR_GALLERY;
+
+ list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
+ $submit_ary['avatar'] = $category . '/' . $avatar_select;
+ }
+ }
+ else if ($delete)
+ {
+ $submit_ary['avatar'] = '';
+ $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
+ }
+
+ if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']) || $group_row['group_avatar'] != $submit_ary['avatar'])) || $delete)
+ {
+ if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
+ {
+ avatar_delete($group_row['group_avatar']);
+ }
+ }
+
+ // Only set the rank, colour, etc. if it's changed or if we're adding a new
+ // group. This prevents existing group members being updated if no changes
+ // were made.
+
+ $group_attributes = array();
+ $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'message_limit');
+ foreach ($test_variables as $test)
+ {
+ if ($action == 'add' || (isset($submit_ary[$test]) && $group_row['group_' . $test] != $submit_ary[$test]))
+ {
+ $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
+ }
+ }
+
+ if (!($error = group_create($group_id, $group_type, $group_name, $group_description, $group_attributes)))
+ {
+ $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
+ trigger_error($user->lang[$message] . adm_back_link($u_action));
+ }
+ }
+ else if (!$group_id)
+ {
+ $group_name = request_var('group_name', '');
+ $group_description = '';
+ $group_rank = 0;
+ $group_type = GROUP_OPEN;
+ }
+ else
+ {
+ $group_name = $group_row['group_name'];
+ $group_description = $group_row['group_description'];
+ $group_type = $group_row['group_type'];
+ $group_rank = $group_row['group_rank'];
+ }
+
+ $sql = 'SELECT *
+ FROM ' . RANKS_TABLE . '
+ WHERE rank_special = 1
+ ORDER BY rank_title';
+ $result = $db->sql_query($sql);
+
+ $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
+ if ($row = $db->sql_fetchrow($result))
+ {
+ do
+ {
+ $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
+ $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
+ }
+ while ($row = $db->sql_fetchrow($result));
+ }
+ $db->sql_freeresult($result);
+
+ $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
+ $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
+ $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
+ $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
+
+ if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
+ {
+ switch ($group_row['group_avatar_type'])
+ {
+ case AVATAR_UPLOAD:
+ $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
+ break;
+ case AVATAR_GALLERY:
+ $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
+ break;
+ }
+ $avatar_img .= $group_row['group_avatar'];
+
+ $avatar_img = '<img src="' . $avatar_img . '" width="' . $group_row['group_avatar_width'] . '" height="' . $group_row['group_avatar_height'] . '" alt="" />';
+ }
+ else
+ {
+ $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
+ }
+
+ $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
+
+ if ($config['allow_avatar_local'] && $display_gallery)
+ {
+ avatar_gallery($category, $avatar_select, 4);
+ }
+
+ $template->assign_vars(array(
+ 'S_EDIT' => true,
+ 'S_INCLUDE_SWATCH' => true,
+ 'S_CAN_UPLOAD' => $can_upload,
+ 'S_ERROR' => (sizeof($error)) ? true : false,
+ 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false,
+ 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
+ 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
+
+ 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
+ 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
+ 'GROUP_DESCRIPTION' => $group_description,
+ 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
+ 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
+ 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
+
+ 'S_RANK_OPTIONS' => $rank_options,
+ 'AVATAR_IMAGE' => $avatar_img,
+ 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
+ 'GROUP_AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
+ 'GROUP_AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
+
+ 'GROUP_TYPE_FREE' => GROUP_FREE,
+ 'GROUP_TYPE_OPEN' => GROUP_OPEN,
+ 'GROUP_TYPE_CLOSED' => GROUP_CLOSED,
+ 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN,
+ 'GROUP_FREE' => $type_free,
+ 'GROUP_OPEN' => $type_open,
+ 'GROUP_CLOSED' => $type_closed,
+ 'GROUP_HIDDEN' => $type_hidden,
+
+ 'U_BACK' => $u_action,
+ 'U_SWATCH' => "{$phpbb_admin_path}swatch.$phpEx$SID&form=settings&name=group_colour",
+ 'U_ACTION' => "{$u_action}&amp;action=$action&amp;g=$group_id",
+ 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
+ )
+ );
+
+ return;
+ break;
+
+ case 'list':
+
+ if (!$group_id)
+ {
+ trigger_error($user->lang['NO_GROUP'] . adm_back_link($u_action));
+ }
+
+ $this->page_title = 'GROUP_MEMBERS';
+
+ // Total number of group leaders
+ $sql = 'SELECT COUNT(user_id) AS total_leaders
+ FROM ' . USER_GROUP_TABLE . "
+ WHERE group_id = $group_id
+ AND group_leader = 1";
+ $result = $db->sql_query($sql);
+
+ $total_leaders = (int) $db->sql_fetchfield('total_leaders', 0, $result);
+ $db->sql_freeresult($result);
+
+ // Total number of group members (non-leaders)
+ $sql = 'SELECT COUNT(user_id) AS total_members
+ FROM ' . USER_GROUP_TABLE . "
+ WHERE group_id = $group_id
+ AND group_leader <> 1";
+ $result = $db->sql_query($sql);
+
+ $total_members = (int) $db->sql_fetchfield('total_members', 0, $result);
+ $db->sql_freeresult($result);
+
+ // Grab the members
+ $sql = 'SELECT u.user_id, u.username, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
+ FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
+ WHERE ug.group_id = $group_id
+ AND u.user_id = ug.user_id
+ ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username";
+ $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
+
+ $leader = $member = 0;
+ $group_data = array();
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $type = ($row['group_leader']) ? 'leader' : 'member';
+
+ $group_data[$type][$$type]['user_id'] = $row['user_id'];
+ $group_data[$type][$$type]['group_id'] = $row['group_id'];
+ $group_data[$type][$$type]['username'] = $row['username'];
+ $group_data[$type][$$type]['user_regdate'] = $row['user_regdate'];
+ $group_data[$type][$$type]['user_posts'] = $row['user_posts'];
+ $group_data[$type][$$type]['user_pending'] = ($row['user_pending']) ? 1 : 0;
+
+ $$type++;
+ }
+ $db->sql_freeresult($result);
+
+ $s_action_options = '';
+ $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
+
+ foreach ($options as $option => $lang)
+ {
+ $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
+ }
+
+ $template->assign_vars(array(
+ 'S_LIST' => true,
+ 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
+ 'S_ACTION_OPTIONS' => $s_action_options,
+
+ 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start),
+ 'PAGINATION' => generate_pagination($u_action . "&amp;action=$action&amp;g=$group_id", $total_members, $config['topics_per_page'], $start, true),
+
+ 'U_ACTION' => $u_action . "&amp;g=$group_id",
+ 'U_BACK' => $u_action,
+ 'U_FIND_USERNAME' => $phpbb_root_path . "memberlist.$phpEx$SID&amp;mode=searchuser&amp;form=list&amp;field=usernames")
+ );
+
+ if ($group_row['group_type'] != GROUP_SPECIAL)
+ {
+ foreach ($group_data['leader'] as $row)
+ {
+ $template->assign_block_vars('leader', array(
+ 'U_USER_EDIT' => $phpbb_admin_path . "index.$phpEx$SID&amp;i=users&amp;action=edit&amp;u={$row['user_id']}",
+
+ 'USERNAME' => $row['username'],
+ 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
+ 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate'], $user->lang['DATE_FORMAT']) : '-',
+ 'USER_POSTS' => $row['user_posts'],
+ 'USER_ID' => $row['user_id'])
+ );
+ }
+ }
+
+ $pending = false;
+
+ foreach ($group_data['member'] as $row)
+ {
+ if ($row['user_pending'] && !$pending)
+ {
+ $template->assign_block_vars('member', array(
+ 'S_PENDING' => true)
+ );
+
+ $pending = true;
+ }
+
+ $template->assign_block_vars('member', array(
+ 'U_USER_EDIT' => $phpbb_admin_path . "index.$phpEx$SID&amp;i=users&amp;action=edit&amp;u={$row['user_id']}",
+
+ 'USERNAME' => $row['username'],
+ 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
+ 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate'], $user->lang['DATE_FORMAT']) : '-',
+ 'USER_POSTS' => $row['user_posts'],
+ 'USER_ID' => $row['user_id'])
+ );
+ }
+
+ return;
+ break;
+ }
+
+ $template->assign_vars(array(
+ 'U_ACTION' => $u_action,
+ )
+ );
+
+ $sql = 'SELECT g.group_id, g.group_name, g.group_type, COUNT(ug.user_id) AS total_members
+ FROM ' . GROUPS_TABLE . ' g
+ LEFT JOIN ' . USER_GROUP_TABLE . ' ug USING (group_id)
+ GROUP BY g.group_id
+ ORDER BY g.group_type ASC, g.group_name';
+ $result = $db->sql_query($sql);
+
+ $special = $normal = 0;
+ $group_ary = array();
+
+ while ($row = $db->sql_fetchrow($result))
+ {
+ $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal';
+
+ $group_ary[$type][$$type]['group_id'] = $row['group_id'];
+ $group_ary[$type][$$type]['group_name'] = $row['group_name'];
+ $group_ary[$type][$$type]['group_type'] = $row['group_type'];
+ $group_ary[$type][$$type]['total_members'] = $row['total_members'];
+
+ $$type++;
+ }
+ $db->sql_freeresult($result);
+
+ $special_toggle = false;
+ foreach ($group_ary as $type => $row_ary)
+ {
+ if ($type == 'special')
+ {
+ $template->assign_block_vars('groups', array(
+ 'S_SPECIAL' => true)
+ );
+ }
+
+ foreach ($row_ary as $row)
+ {
+ $group_id = $row['group_id'];
+ $group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name'];
+
+ $template->assign_block_vars('groups', array(
+ 'U_LIST' => "{$u_action}&amp;action=list&amp;g=$group_id",
+ 'U_DEFAULT' => "{$u_action}&amp;action=default&amp;g=$group_id",
+ 'U_EDIT' => "{$u_action}&amp;action=edit&amp;g=$group_id",
+ 'U_DELETE' => "{$u_action}&amp;action=delete&amp;g=$group_id",
+
+ 'S_GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL) ? true : false,
+
+ 'GROUP_NAME' => $group_name,
+ 'TOTAL_MEMBERS' => $row['total_members'],
+ )
+ );
+ }
+ }
+ }
+}
+
+/**
+* @package module_install
+*/
+class acp_groups_info
+{
+ function module()
+ {
+ return array(
+ 'filename' => 'acp_groups',
+ 'title' => 'ACP_GROUPS_MANAGEMENT',
+ 'version' => '1.0.0',
+ 'modes' => array(
+ 'manage' => array('title' => 'ACP_GROUPS_MANAGE', 'auth' => 'acl_a_group'),
+ ),
+ );
+ }
+
+ function install()
+ {
+ }
+
+ function uninstall()
+ {
+ }
+}
+
+
+
+/*
+ <tr>
+ <td class="cat" colspan="5">&nbsp;</td>
+ </tr>
+ </table>
+</form>
+
+<?php
+
+ adm_page_footer();
+
+// prefs
+ adm_page_header($user->lang['GROUP_PREFS']);
+
+ if ($update)
+ {
+ $user_lang = request_var('lang', '');
+ $user_tz = request_var('tz', 0.0);
+ $user_dst = request_var('dst', 0);
+ }
+ else
+ {
+ }
+
+?>
+<h1><?php echo $user->lang['GROUP_SETTINGS']; ?></h1>
+
+<p><?php echo $user->lang['GROUP_SETTINGS_EXPLAIN']; ?></p>
+
+<form method="post" action="<?php echo "admin_groups.$phpEx$SID&amp;action=edit&amp;g=$group_id"; ?>"><table class="bg" width="90%" cellspacing="1" cellpadding="4" border="0" align="center">
+ <tr>
+ <th colspan="2"><?php echo $user->lang['GROUP_SETTINGS']; ?></th>
+ </tr>
+ <tr>
+ <td class="row2"><?php echo $user->lang['GROUP_LANG']; ?>:</td>
+ <td class="row1"><select name="user_lang"><?php echo '<option value="-1" selected="selected">' . $user->lang['USER_DEFAULT'] . '</option>' . language_select(); ?></select></td>
+ </tr>
+ <tr>
+ <td class="row2"><?php echo $user->lang['GROUP_TIMEZONE']; ?>:</td>
+ <td class="row1"><select name="user_tz"><?php echo '<option value="-14" selected="selected">' . $user->lang['USER_DEFAULT'] . '</option>' . tz_select(); ?></select></td>
+ </tr>
+ <tr>
+ <td class="row2"><?php echo $user->lang['GROUP_DST']; ?>:</td>
+ <td class="row1" nowrap="nowrap"><input type="radio" name="user_dst" value="0" /> <?php echo $user->lang['DISABLED']; ?> &nbsp; <input type="radio" name="user_dst" value="1" /> <?php echo $user->lang['ENABLED']; ?> &nbsp; <input type="radio" name="user_dst" value="-1" checked="checked" /> <?php echo $user->lang['USER_DEFAULT']; ?></td>
+ </tr>
+ <tr>
+ <td class="cat" colspan="2" align="center"><input class="btnmain" type="submit" name="submitprefs" value="<?php echo $user->lang['SUBMIT']; ?>" /> &nbsp; <input class="btnlite" type="reset" value="<?php echo $user->lang['RESET']; ?>" /></td>
+ </tr>
+</table></form>
+
+<?php
+
+ adm_page_footer();
+ break;
+
+ default:
+ trigger_error($user->lang['NO_MODE']);
+}
+
+exit;
+*/
+
+
+?> \ No newline at end of file
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index f25e41443e..6e40431f62 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -1476,7 +1476,7 @@ function build_hidden_fields($field_ary)
function msg_handler($errno, $msg_text, $errfile, $errline)
{
global $cache, $db, $auth, $template, $config, $user;
- global $phpEx, $phpbb_root_path, $starttime, $display_header, $msg_title;
+ global $phpEx, $phpbb_root_path, $starttime, $msg_title;
switch ($errno)
{
@@ -1528,23 +1528,21 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
$user->setup();
}
+ $msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text;
+ $msg_title = (!isset($msg_title)) ? $user->lang['INFORMATION'] : ((!empty($user->lang[$msg_title])) ? $user->lang[$msg_title] : $msg_title);
+
if (!defined('HEADER_INC'))
{
if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
{
- // adm_page_header('', '', false);
- adm_page_header('');
+ adm_page_header($msg_title);
}
else
{
- page_header('');
+ page_header($msg_title);
}
}
- $msg_text = (!empty($user->lang[$msg_text])) ? $user->lang[$msg_text] : $msg_text;
- $msg_title = (!isset($msg_title)) ? $user->lang['INFORMATION'] : ((!empty($user->lang[$msg_title])) ? $user->lang[$msg_title] : $msg_title);
- $display_header = (!isset($display_header)) ? false : (bool) $display_header;
-
$template->set_filenames(array(
'body' => 'message_body.html')
);
@@ -1556,7 +1554,15 @@ function msg_handler($errno, $msg_text, $errfile, $errline)
// We do not want the cron script to be called on error messages
define('IN_CRON', true);
- page_footer();
+
+ if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
+ {
+ adm_page_footer();
+ }
+ else
+ {
+ page_footer();
+ }
exit;
break;
@@ -1570,6 +1576,11 @@ function page_header($page_title = '')
{
global $db, $config, $template, $SID, $user, $auth, $phpEx, $phpbb_root_path;
+ if (defined('HEADER_INC'))
+ {
+ return;
+ }
+
define('HEADER_INC', true);
// gzip_compression
diff --git a/phpBB/includes/functions_module.php b/phpBB/includes/functions_module.php
index ba43943406..5c5f7e30e2 100644
--- a/phpBB/includes/functions_module.php
+++ b/phpBB/includes/functions_module.php
@@ -382,16 +382,30 @@ class p_master
*/
function display($page_title)
{
- global $template;
+ global $template, $user;
// Generate the page
- page_header($page_title);
+ if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
+ {
+ adm_page_header($page_title);
+ }
+ else
+ {
+ page_header($page_title);
+ }
$template->set_filenames(array(
'body' => $this->get_tpl_name())
);
- page_footer();
+ if (defined('IN_ADMIN') && isset($user->data['session_admin']) && $user->data['session_admin'])
+ {
+ adm_page_footer();
+ }
+ else
+ {
+ page_footer();
+ }
}
/**
diff --git a/phpBB/includes/functions_template.php b/phpBB/includes/functions_template.php
new file mode 100644
index 0000000000..01ed80f61d
--- /dev/null
+++ b/phpBB/includes/functions_template.php
@@ -0,0 +1,668 @@
+<?php
+/**
+*
+* @package phpBB3
+* @version $Id$
+* @copyright (c) 2005 phpBB Group, sections (c) 2001 ispi of Lincoln Inc
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*
+*/
+
+/**
+* @package phpBB3
+*
+* Extension of template class - Functions needed for compiling templates only.
+*
+* psoTFX - Completion of file caching, decompilation routines and implementation of
+* conditionals/keywords and associated changes
+*
+* The interface was inspired by PHPLib templates, and the template file (formats are
+* quite similar)
+*
+* The keyword/conditional implementation is currently based on sections of code from
+* the Smarty templating engine (c) 2001 ispi of Lincoln, Inc. which is released
+* (on its own and in whole) under the LGPL. Section 3 of the LGPL states that any code
+* derived from an LGPL application may be relicenced under the GPL, this applies
+* to this source
+*
+* DEFINE directive inspired by a request by Cyberalien
+*/
+class template_compile
+{
+ /**
+ * constuctor
+ */
+ function template_compile($template)
+ {
+ $this->template = &$template;
+ }
+
+ /**
+ * Load template source from file
+ * @private
+ */
+ function _tpl_load_file($handle)
+ {
+ // Try and open template for read
+ if (!($fp = @fopen($this->template->files[$handle], 'r')))
+ {
+ trigger_error("template->_tpl_load_file(): File {$this->template->files[$handle]} does not exist or is empty", E_USER_ERROR);
+ }
+
+ $this->template->compiled_code[$handle] = $this->compile(trim(@fread($fp, filesize($this->template->files[$handle]))));
+ @fclose($fp);
+
+ // Actually compile the code now.
+ $this->compile_write($handle, $this->template->compiled_code[$handle]);
+ }
+
+ /**
+ * The all seeing all doing compile method. Parts are inspired by or directly
+ * from Smarty
+ * @private
+ */
+ function compile($code, $no_echo = false, $echo_var = '')
+ {
+ global $config;
+
+ if ($echo_var)
+ {
+ global $$echo_var;
+ }
+
+ // Remove any "loose" php ... we want to give admins the ability
+ // to switch on/off PHP for a given template. Allowing unchecked
+ // php is a no-no. There is a potential issue here in that non-php
+ // content may be removed ... however designers should use entities
+ // if they wish to display < and >
+ $match_php_tags = array('#\<\?php .*?\?\>#is', '#\<\script language="php"\>.*?\<\/script\>#is', '#\<\?.*?\?\>#s', '#\<%.*?%\>#s');
+ $code = preg_replace($match_php_tags, '', $code);
+
+ // Pull out all block/statement level elements and seperate plain text
+ preg_match_all('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', $code, $matches);
+ $php_blocks = $matches[1];
+ $code = preg_replace('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', '<!-- PHP -->', $code);
+
+ preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', $code, $matches);
+ $include_blocks = $matches[1];
+ $code = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDE -->', $code);
+
+ preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.\\\\]+?) -->#', $code, $matches);
+ $includephp_blocks = $matches[1];
+ $code = preg_replace('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDEPHP -->', $code);
+
+ preg_match_all('#<!-- (.*?) (.*?)?[ ]?-->#', $code, $blocks);
+ $text_blocks = preg_split('#<!-- (.*?) (.*?)?[ ]?-->#', $code);
+
+ for ($i = 0, $j = sizeof($text_blocks); $i < $j; $i++)
+ {
+ $this->compile_var_tags($text_blocks[$i]);
+ }
+ $compile_blocks = array();
+
+ for ($curr_tb = 0, $tb_size = sizeof($text_blocks); $curr_tb < $tb_size; $curr_tb++)
+ {
+ if (!isset($blocks[1][$curr_tb]))
+ {
+ $blocks[1][$curr_tb] = '';
+ }
+
+ switch ($blocks[1][$curr_tb])
+ {
+ case 'BEGIN':
+ $this->template->block_else_level[] = false;
+ $compile_blocks[] = '<?php ' . $this->compile_tag_block($blocks[2][$curr_tb]) . ' ?>';
+ break;
+
+ case 'BEGINELSE':
+ $this->template->block_else_level[sizeof($this->template->block_else_level) - 1] = true;
+ $compile_blocks[] = '<?php }} else { ?>';
+ break;
+
+ case 'END':
+ array_pop($this->template->block_names);
+ $compile_blocks[] = '<?php ' . ((array_pop($this->template->block_else_level)) ? '}' : '}}') . ' ?>';
+ break;
+
+ case 'IF':
+ $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], false) . ' ?>';
+ break;
+
+ case 'ELSE':
+ $compile_blocks[] = '<?php } else { ?>';
+ break;
+
+ case 'ELSEIF':
+ $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], true) . ' ?>';
+ break;
+
+ case 'ENDIF':
+ $compile_blocks[] = '<?php } ?>';
+ break;
+
+ case 'DEFINE':
+ $compile_blocks[] = '<?php ' . $this->compile_tag_define($blocks[2][$curr_tb], true) . ' ?>';
+ break;
+
+ case 'UNDEFINE':
+ $compile_blocks[] = '<?php ' . $this->compile_tag_define($blocks[2][$curr_tb], false) . ' ?>';
+ break;
+
+ case 'INCLUDE':
+ $temp = '';
+ list(, $temp) = each($include_blocks);
+ $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';
+ $this->template->_tpl_include($temp, false);
+ break;
+
+ case 'INCLUDEPHP':
+ if ($config['tpl_php'])
+ {
+ $temp = '';
+ list(, $temp) = each($includephp_blocks);
+ $compile_blocks[] = '<?php ' . $this->compile_tag_include_php($temp) . ' ?>';
+ }
+ else
+ {
+ $compile_blocks[] = '';
+ }
+ break;
+
+ case 'PHP':
+ if ($config['tpl_php'])
+ {
+ $temp = '';
+ list(, $temp) = each($php_blocks);
+ $compile_blocks[] = '<?php ' . $temp . ' ?>';
+ }
+ else
+ {
+ $compile_blocks[] = '';
+ }
+ break;
+
+ default:
+ $this->compile_var_tags($blocks[0][$curr_tb]);
+ $trim_check = trim($blocks[0][$curr_tb]);
+ $compile_blocks[] = (!$no_echo) ? ((!empty($trim_check)) ? $blocks[0][$curr_tb] : '') : ((!empty($trim_check)) ? $blocks[0][$curr_tb] : '');
+ break;
+ }
+ }
+
+ $template_php = '';
+ for ($i = 0, $size = sizeof($text_blocks); $i < $size; $i++)
+ {
+ $trim_check_text = trim($text_blocks[$i]);
+ $trim_check_block = trim($compile_blocks[$i]);
+ $template_php .= (!$no_echo) ? ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : '') : ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : '');
+ }
+
+ // There will be a number of occassions where we switch into and out of
+ // PHP mode instantaneously. Rather than "burden" the parser with this
+ // we'll strip out such occurences, minimising such switching
+ $template_php = str_replace(' ?><?php ', '', $template_php);
+
+ return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'";
+ }
+
+ /**
+ * Compile variables
+ * @private
+ */
+ function compile_var_tags(&$text_blocks)
+ {
+ // change template varrefs into PHP varrefs
+ $varrefs = array();
+
+ // This one will handle varrefs WITH namespaces
+ preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)(\$)?([A-Z0-9\-_]+?)\}#', $text_blocks, $varrefs);
+
+ for ($j = 0, $size = sizeof($varrefs[1]); $j < $size; $j++)
+ {
+ $namespace = $varrefs[1][$j];
+ $varname = $varrefs[4][$j];
+ $new = $this->generate_block_varref($namespace, $varname, true, $varrefs[3][$j]);
+
+ $text_blocks = str_replace($varrefs[0][$j], $new, $text_blocks);
+ }
+
+ // This will handle the remaining root-level varrefs
+ if (!$this->template->static_lang)
+ {
+ $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*?)\}#is', "<?php echo ((isset(\$this->_tpldata['.'][0]['L_\\1'])) ? \$this->_tpldata['.'][0]['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ ' . ucfirst(strtolower(str_replace('_', ' ', '\\1'))) . ' }')); ?>", $text_blocks);
+ }
+ else
+ {
+ global $user;
+
+ $text_blocks = preg_replace('#\{L_([A-Z0-9\-_]*?)\}#e', "'<?php echo ((isset(\$this->_tpldata[\'.\'][0][\'L_\\1\'])) ? \$this->_tpldata[\'.\'][0][\'L_\\1\'] : \'' . ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '') . '\'); ?>'" , $text_blocks);
+ }
+
+ $text_blocks = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "<?php echo (isset(\$this->_tpldata['.'][0]['\\1'])) ? \$this->_tpldata['.'][0]['\\1'] : ''; ?>", $text_blocks);
+ $text_blocks = preg_replace('#\{\$([a-z0-9\-_]*?)\}#is', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
+
+ return;
+ }
+
+ /**
+ * Compile blocks
+ * @private
+ */
+ function compile_tag_block($tag_args)
+ {
+ // Allow for control of looping (indexes start from zero):
+ // foo(2) : Will start the loop on the 3rd entry
+ // foo(-2) : Will start the loop two entries from the end
+ // foo(3,4) : Will start the loop on the fourth entry and end it on the fifth
+ // foo(3,-4) : Will start the loop on the fourth entry and end it four from last
+ if (preg_match('#^(.*?)\(([\-0-9]+)(,([\-0-9]+))?\)$#', $tag_args, $match))
+ {
+ $tag_args = $match[1];
+
+ if ($match[2] < 0)
+ {
+ $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')';
+ }
+ else
+ {
+ $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')';
+ }
+
+ if (strlen($match[4]) < 1 || $match[4] == -1)
+ {
+ $loop_end = '$_' . $tag_args . '_count';
+ }
+ else if ($match[4] >= 0)
+ {
+ $loop_end = '(' . ($match[4] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[4] + 1) . ')';
+ }
+ else //if ($match[4] < -1)
+ {
+ $loop_end = '$_' . $tag_args . '_count' . ($match[4] + 1);
+ }
+ }
+ else
+ {
+ $loop_start = 0;
+ $loop_end = '$_' . $tag_args . '_count';
+ }
+
+ $tag_template_php = '';
+ array_push($this->template->block_names, $tag_args);
+
+ if (sizeof($this->template->block_names) < 2)
+ {
+ // Block is not nested.
+ $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;";
+ }
+ else
+ {
+ // This block is nested.
+
+ // Generate a namespace string for this block.
+ $namespace = implode('.', $this->template->block_names);
+
+ // Get a reference to the data array for this block that depends on the
+ // current indices of all parent blocks.
+ $varref = $this->generate_block_data_ref($namespace, false);
+
+ // Create the for loop code to iterate over this block.
+ $tag_template_php = '$_' . $tag_args . '_count = (isset(' . $varref . ')) ? sizeof(' . $varref . ') : 0;';
+ }
+
+ $tag_template_php .= 'if ($_' . $tag_args . '_count) {';
+ $tag_template_php .= 'for ($this->_' . $tag_args . '_i = ' . $loop_start . '; $this->_' . $tag_args . '_i < ' . $loop_end . '; $this->_' . $tag_args . '_i++){';
+
+ return $tag_template_php;
+ }
+
+ /**
+ * Compile IF tags - much of this is from Smarty with
+ * some adaptions for our block level methods
+ * @private
+ */
+ function compile_tag_if($tag_args, $elseif)
+ {
+ // Tokenize args for 'if' tag.
+ preg_match_all('/(?:
+ "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |
+ \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |
+ [(),] |
+ [^\s(),]+)/x', $tag_args, $match);
+
+ $tokens = $match[0];
+ $is_arg_stack = array();
+
+ for ($i = 0, $size = sizeof($tokens); $i < $size; $i++)
+ {
+ $token = &$tokens[$i];
+
+ switch ($token)
+ {
+ case '!':
+ case '%':
+ case '!==':
+ case '==':
+ case '===':
+ case '>':
+ case '<':
+ case '!=':
+ case '<>':
+ case '<<':
+ case '>>':
+ case '<=':
+ case '>=':
+ case '&&':
+ case '||':
+ case '|':
+ case '^':
+ case '&':
+ case '~':
+ case ')':
+ case ',':
+ case '+':
+ case '-':
+ case '*':
+ case '/':
+ case '@':
+ break;
+
+ case 'eq':
+ $token = '==';
+ break;
+
+ case 'ne':
+ case 'neq':
+ $token = '!=';
+ break;
+
+ case 'lt':
+ $token = '<';
+ break;
+
+ case 'le':
+ case 'lte':
+ $token = '<=';
+ break;
+
+ case 'gt':
+ $token = '>';
+ break;
+
+ case 'ge':
+ case 'gte':
+ $token = '>=';
+ break;
+
+ case 'and':
+ $token = '&&';
+ break;
+
+ case 'or':
+ $token = '||';
+ break;
+
+ case 'not':
+ $token = '!';
+ break;
+
+ case 'mod':
+ $token = '%';
+ break;
+
+ case '(':
+ array_push($is_arg_stack, $i);
+ break;
+
+ case 'is':
+ $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;
+ $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
+
+ $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
+
+ array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
+
+ $i = $is_arg_start;
+
+ default:
+ if (preg_match('#^(([a-z0-9\-_]+?\.)+?)?(\$)?([A-Z]+[A-Z0-9\-_]+)$#s', $token, $varrefs))
+ {
+ $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[3]) . '[\'' . $varrefs[4] . '\']' : (($varrefs[3]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[4] . '\']' : '$this->_tpldata[\'.\'][0][\'' . $varrefs[4] . '\']');
+ }
+ else if (preg_match('#^\.((([a-z0-9\-_]+)?\.?)+?)$#s', $token, $varrefs))
+ {
+ $_tok = $this->generate_block_data_ref($varrefs[1], false);
+ $token = "(isset($_tok) && sizeof($_tok))";
+ }
+
+ break;
+ }
+ }
+
+ return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { ');
+ }
+
+ /**
+ * Compile DEFINE tags
+ * @private
+ */
+ function compile_tag_define($tag_args, $op)
+ {
+ preg_match('#^(([a-z0-9\-_]+?\.)+?)?\$([A-Z][A-Z0-9_\-]*?)( = (\'?)(.*?)(\'?))?$#', $tag_args, $match);
+
+ if (empty($match[3]) || (empty($match[6]) && $op))
+ {
+ return;
+ }
+
+ if (!$op)
+ {
+ return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ');';
+ }
+
+ // Are we a string?
+ if ($match[5] && $match[7])
+ {
+ $match[6] = addslashes(str_replace(array('\\\'', '\\\\'), array('\'', '\\'), $match[6]));
+
+ // Compile reference, we allow template variables in defines...
+ $match[6] = $this->compile($match[6]);
+
+ // Now replace the php code
+ $match[6] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[6]) . "'";
+ }
+ else
+ {
+ preg_match('#(true|false|\.)#i', $match[6], $type);
+
+ switch (strtolower($type[1]))
+ {
+ case 'true':
+ case 'false':
+ $match[6] = strtoupper($match[6]);
+ break;
+ case '.';
+ $match[6] = doubleval($match[6]);
+ break;
+ default:
+ $match[6] = intval($match[6]);
+ break;
+ }
+ }
+
+ return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ' = ' . $match[6] . ';';
+ }
+
+ /**
+ * Compile INCLUDE tag
+ * @private
+ */
+ function compile_tag_include($tag_args)
+ {
+ return "\$this->_tpl_include('$tag_args');";
+ }
+
+ /**
+ * Compile INCLUDE_PHP tag
+ * @private
+ */
+ function compile_tag_include_php($tag_args)
+ {
+ return "include('" . $this->template->root . '/' . $tag_args . "');";
+ }
+
+ /**
+ * parse expression
+ * This is from Smarty
+ * @private
+ */
+ function _parse_is_expr($is_arg, $tokens)
+ {
+ $expr_end = 0;
+ $negate_expr = false;
+
+ if (($first_token = array_shift($tokens)) == 'not')
+ {
+ $negate_expr = true;
+ $expr_type = array_shift($tokens);
+ }
+ else
+ {
+ $expr_type = $first_token;
+ }
+
+ switch ($expr_type)
+ {
+ case 'even':
+ if (@$tokens[$expr_end] == 'by')
+ {
+ $expr_end++;
+ $expr_arg = $tokens[$expr_end++];
+ $expr = "!(($is_arg / $expr_arg) % $expr_arg)";
+ }
+ else
+ {
+ $expr = "!($is_arg % 2)";
+ }
+ break;
+
+ case 'odd':
+ if (@$tokens[$expr_end] == 'by')
+ {
+ $expr_end++;
+ $expr_arg = $tokens[$expr_end++];
+ $expr = "(($is_arg / $expr_arg) % $expr_arg)";
+ }
+ else
+ {
+ $expr = "($is_arg % 2)";
+ }
+ break;
+
+ case 'div':
+ if (@$tokens[$expr_end] == 'by')
+ {
+ $expr_end++;
+ $expr_arg = $tokens[$expr_end++];
+ $expr = "!($is_arg % $expr_arg)";
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if ($negate_expr)
+ {
+ $expr = "!($expr)";
+ }
+
+ array_splice($tokens, 0, $expr_end, $expr);
+
+ return $tokens;
+ }
+
+ /**
+ * Generates a reference to the given variable inside the given (possibly nested)
+ * block namespace. This is a string of the form:
+ * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
+ * It's ready to be inserted into an "echo" line in one of the templates.
+ * NOTE: expects a trailing "." on the namespace.
+ * @private
+ */
+ function generate_block_varref($namespace, $varname, $echo = true, $defop = false)
+ {
+ // Strip the trailing period.
+ $namespace = substr($namespace, 0, -1);
+
+ // Get a reference to the data block for this namespace.
+ $varref = $this->generate_block_data_ref($namespace, true, $defop);
+ // Prepend the necessary code to stick this in an echo line.
+
+ // Append the variable reference.
+ $varref .= "['$varname']";
+ $varref = ($echo) ? "<?php echo $varref; ?>" : ((isset($varref)) ? $varref : '');
+
+ return $varref;
+ }
+
+ /**
+ * Generates a reference to the array of data values for the given
+ * (possibly nested) block namespace. This is a string of the form:
+ * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
+ *
+ * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
+ * NOTE: does not expect a trailing "." on the blockname.
+ * @private
+ */
+ function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)
+ {
+ // Get an array of the blocks involved.
+ $blocks = explode('.', $blockname);
+ $blockcount = sizeof($blocks) - 1;
+ $varref = '$this->_tpldata' . (($defop) ? '[\'DEFINE\']' : '');
+
+ // Build up the string with everything but the last child.
+ for ($i = 0; $i < $blockcount; $i++)
+ {
+ $varref .= "['" . $blocks[$i] . "'][\$this->_" . $blocks[$i] . '_i]';
+ }
+
+ // Add the block reference for the last child.
+ $varref .= "['" . $blocks[$blockcount] . "']";
+
+ // Add the iterator for the last child if requried.
+ if ($include_last_iterator)
+ {
+ $varref .= '[$this->_' . $blocks[$blockcount] . '_i]';
+ }
+
+ return $varref;
+ }
+
+ /**
+ * Write compiled file to cache directory
+ * @private
+ */
+ function compile_write(&$handle, $data)
+ {
+ global $phpEx, $user;
+
+ $filename = $this->template->cachepath . $this->template->filename[$handle] . '.' . (($this->template->static_lang) ? $user->data['user_lang'] . '.' : '') . $phpEx;
+
+ if ($fp = @fopen($filename, 'wb'))
+ {
+ @flock($fp, LOCK_EX);
+ @fwrite ($fp, $data);
+ @flock($fp, LOCK_UN);
+ @fclose($fp);
+
+ @umask(0);
+ @chmod($filename, 0644);
+ }
+
+ return;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php
index c5593c5ba3..f308f4805f 100644
--- a/phpBB/includes/functions_user.php
+++ b/phpBB/includes/functions_user.php
@@ -49,7 +49,7 @@ function user_get_id_name(&$user_id_ary, &$username_ary)
return 'NO_USERS';
}
- $id_ary = $username_ary = array();
+ $user_id_ary = $username_ary = array();
do
{
$username_ary[$row['user_id']] = $row['username'];
@@ -1061,57 +1061,98 @@ function avatar_upload($data, &$error)
/**
* Avatar Gallery
*/
-function avatar_gallery($category, &$error)
+function avatar_gallery($category, $avatar_select, $items_per_column, $block_var = 'avatar_row')
{
- global $user, $cache;
+ global $user, $cache, $template;
global $config, $phpbb_root_path;
+ $avatar_list = array();
+
$path = $phpbb_root_path . $config['avatar_gallery_path'];
if (!file_exists($path) || !is_dir($path))
{
- return array($user->lang['NONE'] => array());
+ $avatar_list = array($user->lang['NONE'] => array());
}
-
- // To be replaced with SQL ... before M3 completion
- $dp = @opendir($path);
-
- $data = array();
- $avatar_row_count = $avatar_col_count = 0;
- while ($file = readdir($dp))
+ else
{
- if ($file{0} != '.' && is_dir("$path/$file"))
- {
- $dp2 = @opendir("$path/$file");
+ // Collect images
+ $dp = @opendir($path);
- while ($sub_file = readdir($dp2))
+ while ($file = readdir($dp))
+ {
+ if ($file{0} != '.' && is_dir("$path/$file"))
{
- if (preg_match('#\.(gif$|png$|jpg|jpeg)$#i', $sub_file))
+ $avatar_row_count = $avatar_col_count = 0;
+
+ $dp2 = @opendir("$path/$file");
+ while ($sub_file = readdir($dp2))
{
- $data[$file][$avatar_row_count][$avatar_col_count]['file'] = "$file/$sub_file";
- $data[$file][$avatar_row_count][$avatar_col_count]['name'] = ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file)));
-
- $avatar_col_count++;
- if ($avatar_col_count == 4)
+ if (preg_match('#\.(gif$|png$|jpg|jpeg)$#i', $sub_file))
{
- $avatar_row_count++;
- $avatar_col_count = 0;
+ $avatar_list[$file][$avatar_row_count][$avatar_col_count] = array(
+ 'file' => "$file/$sub_file",
+ 'filename' => $sub_file,
+ 'name' => ucfirst(str_replace('_', ' ', preg_replace('#^(.*)\..*$#', '\1', $sub_file))),
+ );
+
+ $avatar_col_count++;
+ if ($avatar_col_count == $items_per_column)
+ {
+ $avatar_row_count++;
+ $avatar_col_count = 0;
+ }
}
}
+ closedir($dp2);
}
- closedir($dp2);
}
+ closedir($dp);
}
- closedir($dp);
- if (!sizeof($data))
+ if (!sizeof($avatar_list))
{
- return array($user->lang['NONE'] => array());
+ $avatar_list = array($user->lang['NONE'] => array());
}
- @ksort($data);
+ @ksort($avatar_list);
+
+ $category = (!$category) ? key($avatar_list) : $category;
+ $avatar_categories = array_keys($avatar_list);
+
+ $s_category_options = '';
+ foreach ($avatar_categories as $cat)
+ {
+ $s_category_options .= '<option value="' . $cat . '"' . (($cat == $category) ? ' selected="selected"' : '') . '>' . $cat . '</option>';
+ }
+
+ $template->assign_vars(array(
+ 'S_IN_AVATAR_GALLERY' => true,
+ 'S_CAT_OPTIONS' => $s_category_options)
+ );
+
+ $avatar_list = $avatar_list[$category];
+
+ foreach ($avatar_list as $avatar_row_ary)
+ {
+ $template->assign_block_vars($block_var, array());
+
+ foreach ($avatar_row_ary as $avatar_col_ary)
+ {
+ $template->assign_block_vars($block_var . '.avatar_column', array(
+ 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'],
+ 'AVATAR_NAME' => $avatar_col_ary['name'],
+ 'AVATAR_FILE' => $avatar_col_ary['filename'])
+ );
+
+ $template->assign_block_vars($block_var . '.avatar_option_column', array(
+ 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'],
+ 'S_OPTIONS_AVATAR' => $avatar_col_ary['filename'])
+ );
+ }
+ }
- return $data;
+ return $avatar_list;
}
//
@@ -1350,7 +1391,6 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
}
}
- $usernames = array();
if (sizeof($update_id_ary))
{
$sql = 'UPDATE ' . USER_GROUP_TABLE . '
@@ -1358,18 +1398,6 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false,
WHERE user_id IN (' . implode(', ', $update_id_ary) . ")
AND group_id = $group_id";
$db->sql_query($sql);
-
- foreach ($update_id_ary as $id)
- {
- $usernames[] = $username_ary[$id];
- }
- }
- else
- {
- foreach ($add_id_ary as $id)
- {
- $usernames[] = $username_ary[$id];
- }
}
if ($default)
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index 791cbb069e..5d051debab 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -53,6 +53,10 @@ class template
var $static_lang;
+ /**
+ * Set template location
+ * @public
+ */
function set_template($static_lang = false)
{
global $phpbb_root_path, $config, $user;
@@ -75,6 +79,10 @@ class template
return true;
}
+ /**
+ * Set custom template location (able to use directory outside of phpBB)
+ * @public
+ */
function set_custom_template($template_path, $template_name, $static_lang = false)
{
global $phpbb_root_path;
@@ -88,8 +96,11 @@ class template
return true;
}
- // Sets the template filenames for handles. $filename_array
- // should be a hash of handle => filename pairs.
+ /**
+ * Sets the template filenames for handles. $filename_array
+ * should be a hash of handle => filename pairs.
+ * @public
+ */
function set_filenames($filename_array)
{
if (!is_array($filename_array))
@@ -112,15 +123,19 @@ class template
return true;
}
-
- // Destroy template data set
+ /**
+ * Destroy template data set
+ * @public
+ */
function destroy()
{
$this->_tpldata = array();
}
-
- // Methods for loading and evaluating the templates
+ /**
+ * Display handle
+ * @public
+ */
function display($handle, $include_once = true)
{
global $user;
@@ -137,10 +152,34 @@ class template
return true;
}
- // Load a compiled template if possible, if not, recompile it
+ /**
+ * Display the handle and assign the output to a template variable
+ * @public
+ */
+ function assign_display($handle, $template_var, $return_content = false, $include_once = true)
+ {
+ ob_start();
+ $this->display($handle, $include_once);
+ $contents = ob_get_contents();
+ ob_end_clean();
+
+ if ($return_content)
+ {
+ return $contents;
+ }
+
+ $this->assign_var($template_var, $contents);
+
+ return true;
+ }
+
+ /**
+ * Load a compiled template if possible, if not, recompile it
+ * @private
+ */
function _tpl_load(&$handle)
{
- global $config, $user, $db, $phpEx;
+ global $user, $phpEx, $config;
$filename = $this->cachepath . $this->filename[$handle] . '.' . (($this->static_lang) ? $user->data['user_lang'] . '.' : '') . $phpEx;
@@ -152,6 +191,10 @@ class template
return $filename;
}
+ global $db, $phpbb_root_path;
+
+ include_once($phpbb_root_path . 'includes/functions_template.' . $phpEx);
+ $compile = new template_compile($this);
// If the file for this handle is already loaded and compiled, do nothing.
if (!empty($this->uncompiled_code[$handle]))
@@ -220,27 +263,14 @@ class template
return false;
}
- $this->_tpl_load_file($handle);
+ $compile->_tpl_load_file($handle);
return false;
}
- // Load template source from file
- function _tpl_load_file($handle)
- {
- // Try and open template for read
- if (!($fp = @fopen($this->files[$handle], 'r')))
- {
- trigger_error("template->_tpl_load_file(): File {$this->files[$handle]} does not exist or is empty", E_USER_ERROR);
- }
-
- $this->compiled_code[$handle] = $this->compile(trim(@fread($fp, filesize($this->files[$handle]))));
- @fclose($fp);
-
- // Actually compile the code now.
- $this->compile_write($handle, $this->compiled_code[$handle]);
- }
-
- // Assign key variable pairs from an array
+ /**
+ * Assign key variable pairs from an array
+ * @public
+ */
function assign_vars($vararray)
{
foreach ($vararray as $key => $val)
@@ -251,7 +281,10 @@ class template
return true;
}
- // Assign a single variable to a single key
+ /**
+ * Assign a single variable to a single key
+ * @public
+ */
function assign_var($varname, $varval)
{
$this->_tpldata['.'][0][$varname] = $varval;
@@ -259,7 +292,10 @@ class template
return true;
}
- // Assign key variable pairs from an array to a specified block
+ /**
+ * Assign key variable pairs from an array to a specified block
+ * @public
+ */
function assign_block_vars($blockname, $vararray)
{
if (strpos($blockname, '.') !== false)
@@ -362,6 +398,7 @@ class template
* Since counting begins by zero, inserting at the last position will result in this array: array(vararray, last positioned array)
* and inserting at position 1 will result in this array: array(first positioned array, vararray, following vars)
*
+ * @public
*/
function alter_block_array($blockname, $vararray, $key = false, $mode = 'insert')
{
@@ -431,7 +468,10 @@ class template
}
}
- // Include a seperate template
+ /**
+ * Include a seperate template
+ * @private
+ */
function _tpl_include($filename, $include = true)
{
$handle = $filename;
@@ -452,587 +492,6 @@ class template
eval(' ?>' . $this->compiled_code[$handle] . '<?php ');
}
}
-
-
-
- // This next set of methods could be seperated off and included since
- // they deal exclusively with compilation ... which is done infrequently
- // and would save a fair few kb
-
-
- // The all seeing all doing compile method. Parts are inspired by or directly
- // from Smarty
- function compile($code, $no_echo = false, $echo_var = '')
- {
- global $config;
-
- if ($echo_var)
- {
- global $$echo_var;
- }
-
- // Remove any "loose" php ... we want to give admins the ability
- // to switch on/off PHP for a given template. Allowing unchecked
- // php is a no-no. There is a potential issue here in that non-php
- // content may be removed ... however designers should use entities
- // if they wish to display < and >
- $match_php_tags = array('#\<\?php .*?\?\>#is', '#\<\script language="php"\>.*?\<\/script\>#is', '#\<\?.*?\?\>#s', '#\<%.*?%\>#s');
- $code = preg_replace($match_php_tags, '', $code);
-
- // Pull out all block/statement level elements and seperate plain text
- preg_match_all('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', $code, $matches);
- $php_blocks = $matches[1];
- $code = preg_replace('#<!-- PHP -->(.*?)<!-- ENDPHP -->#s', '<!-- PHP -->', $code);
-
- preg_match_all('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', $code, $matches);
- $include_blocks = $matches[1];
- $code = preg_replace('#<!-- INCLUDE ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDE -->', $code);
-
- preg_match_all('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.\\\\]+?) -->#', $code, $matches);
- $includephp_blocks = $matches[1];
- $code = preg_replace('#<!-- INCLUDEPHP ([a-zA-Z0-9\_\-\+\.]+?) -->#', '<!-- INCLUDEPHP -->', $code);
-
- preg_match_all('#<!-- (.*?) (.*?)?[ ]?-->#', $code, $blocks);
- $text_blocks = preg_split('#<!-- (.*?) (.*?)?[ ]?-->#', $code);
-
- for ($i = 0, $j = sizeof($text_blocks); $i < $j; $i++)
- {
- $this->compile_var_tags($text_blocks[$i]);
- }
- $compile_blocks = array();
-
- for ($curr_tb = 0, $tb_size = sizeof($text_blocks); $curr_tb < $tb_size; $curr_tb++)
- {
- if (!isset($blocks[1][$curr_tb]))
- {
- $blocks[1][$curr_tb] = '';
- }
-
- switch ($blocks[1][$curr_tb])
- {
- case 'BEGIN':
- $this->block_else_level[] = false;
- $compile_blocks[] = '<?php ' . $this->compile_tag_block($blocks[2][$curr_tb]) . ' ?>';
- break;
-
- case 'BEGINELSE':
- $this->block_else_level[sizeof($this->block_else_level) - 1] = true;
- $compile_blocks[] = '<?php }} else { ?>';
- break;
-
- case 'END':
- array_pop($this->block_names);
- $compile_blocks[] = '<?php ' . ((array_pop($this->block_else_level)) ? '}' : '}}') . ' ?>';
- break;
-
- case 'IF':
- $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], false) . ' ?>';
- break;
-
- case 'ELSE':
- $compile_blocks[] = '<?php } else { ?>';
- break;
-
- case 'ELSEIF':
- $compile_blocks[] = '<?php ' . $this->compile_tag_if($blocks[2][$curr_tb], true) . ' ?>';
- break;
-
- case 'ENDIF':
- $compile_blocks[] = '<?php } ?>';
- break;
-
- case 'DEFINE':
- $compile_blocks[] = '<?php ' . $this->compile_tag_define($blocks[2][$curr_tb], true) . ' ?>';
- break;
-
- case 'UNDEFINE':
- $compile_blocks[] = '<?php ' . $this->compile_tag_define($blocks[2][$curr_tb], false) . ' ?>';
- break;
-
- case 'INCLUDE':
- $temp = '';
- list(, $temp) = each($include_blocks);
- $compile_blocks[] = '<?php ' . $this->compile_tag_include($temp) . ' ?>';
- $this->_tpl_include($temp, false);
- break;
-
- case 'INCLUDEPHP':
- if ($config['tpl_php'])
- {
- $temp = '';
- list(, $temp) = each($includephp_blocks);
- $compile_blocks[] = '<?php ' . $this->compile_tag_include_php($temp) . ' ?>';
- }
- else
- {
- $compile_blocks[] = '';
- }
- break;
-
- case 'PHP':
- if ($config['tpl_php'])
- {
- $temp = '';
- list(, $temp) = each($php_blocks);
- $compile_blocks[] = '<?php ' . $temp . ' ?>';
- }
- else
- {
- $compile_blocks[] = '';
- }
- break;
-
- default:
- $this->compile_var_tags($blocks[0][$curr_tb]);
- $trim_check = trim($blocks[0][$curr_tb]);
- $compile_blocks[] = (!$no_echo) ? ((!empty($trim_check)) ? $blocks[0][$curr_tb] : '') : ((!empty($trim_check)) ? $blocks[0][$curr_tb] : '');
- break;
- }
- }
-
- $template_php = '';
- for ($i = 0, $size = sizeof($text_blocks); $i < $size; $i++)
- {
- $trim_check_text = trim($text_blocks[$i]);
- $trim_check_block = trim($compile_blocks[$i]);
- $template_php .= (!$no_echo) ? ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : '') : ((!empty($trim_check_text)) ? $text_blocks[$i] : '') . ((!empty($compile_blocks[$i])) ? $compile_blocks[$i] : '');
- }
-
- // There will be a number of occassions where we switch into and out of
- // PHP mode instantaneously. Rather than "burden" the parser with this
- // we'll strip out such occurences, minimising such switching
- $template_php = str_replace(' ?><?php ', '', $template_php);
-
- return (!$no_echo) ? $template_php : "\$$echo_var .= '" . $template_php . "'";
- }
-
- function compile_var_tags(&$text_blocks)
- {
- // change template varrefs into PHP varrefs
- $varrefs = array();
-
- // This one will handle varrefs WITH namespaces
- preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)(\$)?([A-Z0-9\-_]+?)\}#', $text_blocks, $varrefs);
-
- for ($j = 0, $size = sizeof($varrefs[1]); $j < $size; $j++)
- {
- $namespace = $varrefs[1][$j];
- $varname = $varrefs[4][$j];
- $new = $this->generate_block_varref($namespace, $varname, true, $varrefs[3][$j]);
-
- $text_blocks = str_replace($varrefs[0][$j], $new, $text_blocks);
- }
-
- // This will handle the remaining root-level varrefs
- if (!$this->static_lang)
- {
- $text_blocks = preg_replace('#\{L_([a-z0-9\-_]*?)\}#is', "<?php echo ((isset(\$this->_tpldata['.'][0]['L_\\1'])) ? \$this->_tpldata['.'][0]['L_\\1'] : ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '{ ' . ucfirst(strtolower(str_replace('_', ' ', '\\1'))) . ' }')); ?>", $text_blocks);
- }
- else
- {
- global $user;
-
- $text_blocks = preg_replace('#\{L_([A-Z0-9\-_]*?)\}#e', "'<?php echo ((isset(\$this->_tpldata[\'.\'][0][\'L_\\1\'])) ? \$this->_tpldata[\'.\'][0][\'L_\\1\'] : \'' . ((isset(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '') . '\'); ?>'" , $text_blocks);
- }
-
- $text_blocks = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "<?php echo (isset(\$this->_tpldata['.'][0]['\\1'])) ? \$this->_tpldata['.'][0]['\\1'] : ''; ?>", $text_blocks);
- $text_blocks = preg_replace('#\{\$([a-z0-9\-_]*?)\}#is', "<?php echo (isset(\$this->_tpldata['DEFINE']['.']['\\1'])) ? \$this->_tpldata['DEFINE']['.']['\\1'] : ''; ?>", $text_blocks);
-
- return;
- }
-
- function compile_tag_block($tag_args)
- {
- // Allow for control of looping (indexes start from zero):
- // foo(2) : Will start the loop on the 3rd entry
- // foo(-2) : Will start the loop two entries from the end
- // foo(3,4) : Will start the loop on the fourth entry and end it on the fifth
- // foo(3,-4) : Will start the loop on the fourth entry and end it four from last
- if (preg_match('#^(.*?)\(([\-0-9]+)(,([\-0-9]+))?\)$#', $tag_args, $match))
- {
- $tag_args = $match[1];
-
- if ($match[2] < 0)
- {
- $loop_start = '($_' . $tag_args . '_count ' . $match[2] . ' < 0 ? 0 : $_' . $tag_args . '_count ' . $match[2] . ')';
- }
- else
- {
- $loop_start = '($_' . $tag_args . '_count < ' . $match[2] . ' ? $_' . $tag_args . '_count : ' . $match[2] . ')';
- }
-
- if (strlen($match[4]) < 1 || $match[4] == -1)
- {
- $loop_end = '$_' . $tag_args . '_count';
- }
- else if ($match[4] >= 0)
- {
- $loop_end = '(' . ($match[4] + 1) . ' > $_' . $tag_args . '_count ? $_' . $tag_args . '_count : ' . ($match[4] + 1) . ')';
- }
- else //if ($match[4] < -1)
- {
- $loop_end = '$_' . $tag_args . '_count' . ($match[4] + 1);
- }
- }
- else
- {
- $loop_start = 0;
- $loop_end = '$_' . $tag_args . '_count';
- }
-
- $tag_template_php = '';
- array_push($this->block_names, $tag_args);
-
- if (sizeof($this->block_names) < 2)
- {
- // Block is not nested.
- $tag_template_php = '$_' . $tag_args . "_count = (isset(\$this->_tpldata['$tag_args'])) ? sizeof(\$this->_tpldata['$tag_args']) : 0;";
- }
- else
- {
- // This block is nested.
-
- // Generate a namespace string for this block.
- $namespace = implode('.', $this->block_names);
-
- // Get a reference to the data array for this block that depends on the
- // current indices of all parent blocks.
- $varref = $this->generate_block_data_ref($namespace, false);
-
- // Create the for loop code to iterate over this block.
- $tag_template_php = '$_' . $tag_args . '_count = (isset(' . $varref . ')) ? sizeof(' . $varref . ') : 0;';
- }
-
- $tag_template_php .= 'if ($_' . $tag_args . '_count) {';
- $tag_template_php .= 'for ($this->_' . $tag_args . '_i = ' . $loop_start . '; $this->_' . $tag_args . '_i < ' . $loop_end . '; $this->_' . $tag_args . '_i++){';
-
- return $tag_template_php;
- }
-
- /**
- * Compile IF tags - much of this is from Smarty with
- * some adaptions for our block level methods
- */
- function compile_tag_if($tag_args, $elseif)
- {
- // Tokenize args for 'if' tag.
- preg_match_all('/(?:
- "[^"\\\\]*(?:\\\\.[^"\\\\]*)*" |
- \'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\' |
- [(),] |
- [^\s(),]+)/x', $tag_args, $match);
-
- $tokens = $match[0];
- $is_arg_stack = array();
-
- for ($i = 0, $size = sizeof($tokens); $i < $size; $i++)
- {
- $token = &$tokens[$i];
-
- switch ($token)
- {
- case '!':
- case '%':
- case '!==':
- case '==':
- case '===':
- case '>':
- case '<':
- case '!=':
- case '<>':
- case '<<':
- case '>>':
- case '<=':
- case '>=':
- case '&&':
- case '||':
- case '|':
- case '^':
- case '&':
- case '~':
- case ')':
- case ',':
- case '+':
- case '-':
- case '*':
- case '/':
- case '@':
- break;
-
- case 'eq':
- $token = '==';
- break;
-
- case 'ne':
- case 'neq':
- $token = '!=';
- break;
-
- case 'lt':
- $token = '<';
- break;
-
- case 'le':
- case 'lte':
- $token = '<=';
- break;
-
- case 'gt':
- $token = '>';
- break;
-
- case 'ge':
- case 'gte':
- $token = '>=';
- break;
-
- case 'and':
- $token = '&&';
- break;
-
- case 'or':
- $token = '||';
- break;
-
- case 'not':
- $token = '!';
- break;
-
- case 'mod':
- $token = '%';
- break;
-
- case '(':
- array_push($is_arg_stack, $i);
- break;
-
- case 'is':
- $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1;
- $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start));
-
- $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1));
-
- array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens);
-
- $i = $is_arg_start;
-
- default:
- if (preg_match('#^(([a-z0-9\-_]+?\.)+?)?(\$)?([A-Z]+[A-Z0-9\-_]+)$#s', $token, $varrefs))
- {
- $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[3]) . '[\'' . $varrefs[4] . '\']' : (($varrefs[3]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[4] . '\']' : '$this->_tpldata[\'.\'][0][\'' . $varrefs[4] . '\']');
- }
- else if (preg_match('#^\.((([a-z0-9\-_]+)?\.?)+?)$#s', $token, $varrefs))
- {
- $_tok = $this->generate_block_data_ref($varrefs[1], false);
- $token = "(isset($_tok) && sizeof($_tok))";
- }
-
- break;
- }
- }
-
- return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { ');
- }
-
- function compile_tag_define($tag_args, $op)
- {
- preg_match('#^(([a-z0-9\-_]+?\.)+?)?\$([A-Z][A-Z0-9_\-]*?)( = (\'?)(.*?)(\'?))?$#', $tag_args, $match);
-
- if (empty($match[3]) || (empty($match[6]) && $op))
- {
- return;
- }
-
- if (!$op)
- {
- return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ');';
- }
-
- // Are we a string?
- if ($match[5] && $match[7])
- {
- $match[6] = addslashes(str_replace(array('\\\'', '\\\\'), array('\'', '\\'), $match[6]));
-
- // Compile reference, we allow template variables in defines...
- $match[6] = $this->compile($match[6]);
-
- // Now replace the php code
- $match[6] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[6]) . "'";
- }
- else
- {
- preg_match('#(true|false|\.)#i', $match[6], $type);
-
- switch (strtolower($type[1]))
- {
- case 'true':
- case 'false':
- $match[6] = strtoupper($match[6]);
- break;
- case '.';
- $match[6] = doubleval($match[6]);
- break;
- default:
- $match[6] = intval($match[6]);
- break;
- }
- }
-
- return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[3] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[3] . '\']') . ' = ' . $match[6] . ';';
- }
-
- function compile_tag_include($tag_args)
- {
- return "\$this->_tpl_include('$tag_args');";
- }
-
- function compile_tag_include_php($tag_args)
- {
- return "include('" . $this->root . '/' . $tag_args . "');";
- }
-
- // This is from Smarty
- function _parse_is_expr($is_arg, $tokens)
- {
- $expr_end = 0;
- $negate_expr = false;
-
- if (($first_token = array_shift($tokens)) == 'not')
- {
- $negate_expr = true;
- $expr_type = array_shift($tokens);
- }
- else
- {
- $expr_type = $first_token;
- }
-
- switch ($expr_type)
- {
- case 'even':
- if (@$tokens[$expr_end] == 'by')
- {
- $expr_end++;
- $expr_arg = $tokens[$expr_end++];
- $expr = "!(($is_arg / $expr_arg) % $expr_arg)";
- }
- else
- {
- $expr = "!($is_arg % 2)";
- }
- break;
-
- case 'odd':
- if (@$tokens[$expr_end] == 'by')
- {
- $expr_end++;
- $expr_arg = $tokens[$expr_end++];
- $expr = "(($is_arg / $expr_arg) % $expr_arg)";
- }
- else
- {
- $expr = "($is_arg % 2)";
- }
- break;
-
- case 'div':
- if (@$tokens[$expr_end] == 'by')
- {
- $expr_end++;
- $expr_arg = $tokens[$expr_end++];
- $expr = "!($is_arg % $expr_arg)";
- }
- break;
-
- default:
- break;
- }
-
- if ($negate_expr)
- {
- $expr = "!($expr)";
- }
-
- array_splice($tokens, 0, $expr_end, $expr);
-
- return $tokens;
- }
-
- /**
- * Generates a reference to the given variable inside the given (possibly nested)
- * block namespace. This is a string of the form:
- * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . '
- * It's ready to be inserted into an "echo" line in one of the templates.
- * NOTE: expects a trailing "." on the namespace.
- */
- function generate_block_varref($namespace, $varname, $echo = true, $defop = false)
- {
- // Strip the trailing period.
- $namespace = substr($namespace, 0, -1);
-
- // Get a reference to the data block for this namespace.
- $varref = $this->generate_block_data_ref($namespace, true, $defop);
- // Prepend the necessary code to stick this in an echo line.
-
- // Append the variable reference.
- $varref .= "['$varname']";
- $varref = ($echo) ? "<?php echo $varref; ?>" : ((isset($varref)) ? $varref : '');
-
- return $varref;
- }
-
- /**
- * Generates a reference to the array of data values for the given
- * (possibly nested) block namespace. This is a string of the form:
- * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN']
- *
- * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above.
- * NOTE: does not expect a trailing "." on the blockname.
- */
- function generate_block_data_ref($blockname, $include_last_iterator, $defop = false)
- {
- // Get an array of the blocks involved.
- $blocks = explode('.', $blockname);
- $blockcount = sizeof($blocks) - 1;
- $varref = '$this->_tpldata' . (($defop) ? '[\'DEFINE\']' : '');
-
- // Build up the string with everything but the last child.
- for ($i = 0; $i < $blockcount; $i++)
- {
- $varref .= "['" . $blocks[$i] . "'][\$this->_" . $blocks[$i] . '_i]';
- }
-
- // Add the block reference for the last child.
- $varref .= "['" . $blocks[$blockcount] . "']";
-
- // Add the iterator for the last child if requried.
- if ($include_last_iterator)
- {
- $varref .= '[$this->_' . $blocks[$blockcount] . '_i]';
- }
-
- return $varref;
- }
-
- function compile_write(&$handle, $data)
- {
- global $phpEx, $user;
-
- $filename = $this->cachepath . $this->filename[$handle] . '.' . (($this->static_lang) ? $user->data['user_lang'] . '.' : '') . $phpEx;
-
- if ($fp = @fopen($filename, 'wb'))
- {
- @flock($fp, LOCK_EX);
- @fwrite ($fp, $data);
- @flock($fp, LOCK_UN);
- @fclose($fp);
-
- @umask(0);
- @chmod($filename, 0644);
- }
-
- return;
- }
}
?> \ No newline at end of file
diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php
index f6edac0d7e..5881f15bf7 100644
--- a/phpBB/includes/ucp/ucp_profile.php
+++ b/phpBB/includes/ucp/ucp_profile.php
@@ -460,15 +460,11 @@ class ucp_profile
case 'avatar':
- $display_gallery = (isset($_POST['displaygallery'])) ? true : false;
- $category = request_var('category', '');
+ $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
$delete = (isset($_POST['delete'])) ? true : false;
- $avatarselect = request_var('avatarselect', '');
- $avatarselect = str_replace(array('../', '..\\', './', '.\\'), '', $avatarselect);
- if ($avatarselect && ($avatarselect{0} == '/' || $avatarselect{0} == "\\"))
- {
- $avatarselect = '';
- }
+
+ $avatar_select = basename(request_var('avatar_select', ''));
+ $category = basename(request_var('category', ''));
// Can we upload?
$can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false;
@@ -499,6 +495,7 @@ class ucp_profile
if (!sizeof($error))
{
$data['user_id'] = $user->data['user_id'];
+
if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload)
{
list($type, $filename, $width, $height) = avatar_upload($data, $error);
@@ -507,11 +504,21 @@ class ucp_profile
{
list($type, $filename, $width, $height) = avatar_remote($data, $error);
}
- else if ($avatarselect && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
+ else if ($avatar_select && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
{
$type = AVATAR_GALLERY;
- $filename = $avatarselect;
- list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $filename);
+ $filename = $avatar_select;
+
+ // check avatar gallery
+ if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
+ {
+ $type = $filename = $width = $height = '';
+ }
+ else
+ {
+ list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $filename);
+ $filename = $category . '/' . $filename;
+ }
}
else if ($delete && $auth->acl_get('u_chgavatar'))
{
@@ -543,8 +550,8 @@ class ucp_profile
}
}
- meta_refresh(3, "ucp.$phpEx$SID&amp;i=$id&amp;mode=$mode");
- $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], "<a href=\"ucp.$phpEx$SID&amp;i=$id&amp;mode=$mode\">", '</a>');
+ meta_refresh(3, "{$phpbb_root_path}ucp.$phpEx$SID&amp;i=$id&amp;mode=$mode");
+ $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], "<a href=\"{$phpbb_root_path}ucp.$phpEx$SID&amp;i=$id&amp;mode=$mode\">", '</a>');
trigger_error($message);
}
@@ -557,20 +564,22 @@ class ucp_profile
// Generate users avatar
$avatar_img = '';
+
if ($user->data['user_avatar'])
{
switch ($user->data['user_avatar_type'])
{
case AVATAR_UPLOAD:
$avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
- break;
+ break;
+
case AVATAR_GALLERY:
$avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
- break;
+ break;
}
$avatar_img .= $user->data['user_avatar'];
- $avatar_img = '<img src="' . $avatar_img . '" width="' . $user->data['user_avatar_width'] . '" height="' . $user->data['user_avatar_height'] . '" border="0" alt="" />';
+ $avatar_img = '<img src="' . $avatar_img . '" width="' . $user->data['user_avatar_width'] . '" height="' . $user->data['user_avatar_height'] . '" alt="" />';
}
$template->assign_vars(array(
@@ -583,44 +592,9 @@ class ucp_profile
'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),)
);
- $s_categories = $s_pages = '';
if ($display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'])
{
- $avatar_list = avatar_gallery($category, $error);
- $category = (!$category) ? key($avatar_list) : $category;
-
- $s_category_options = '';
- foreach (array_keys($avatar_list) as $cat)
- {
- $s_category_options .= '<option value="' . $cat . '"' . (($cat == $category) ? ' selected="selected"' : '') . '>' . $cat . '</option>';
- }
-
- $template->assign_vars(array(
- 'S_DISPLAY_GALLERY' => true,
- 'S_CAT_OPTIONS' => $s_category_options)
- );
-
- $avatar_list = $avatar_list[$category];
-
- foreach ($avatar_list as $avatar_row_ary)
- {
- $template->assign_block_vars('avatar_row', array());
-
- foreach ($avatar_row_ary as $avatar_col_ary)
- {
- $template->assign_block_vars('avatar_row.avatar_column', array(
- 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'],
- 'AVATAR_NAME' => $avatar_col_ary['name'],
- 'AVATAR_FILE' => $avatar_col_ary['file'])
- );
-
- $template->assign_block_vars('avatar_row.avatar_option_column', array(
- 'AVATAR_IMAGE' => $phpbb_root_path . $config['avatar_gallery_path'] . '/' . $avatar_col_ary['file'],
- 'S_OPTIONS_AVATAR' => $avatar_col_ary['file'])
- );
- }
- }
- unset($avatar_list);
+ avatar_gallery($category, $avatar_select, 4);
}
else
{
@@ -633,9 +607,7 @@ class ucp_profile
'S_UPLOAD_AVATAR_FILE' => $can_upload,
'S_UPLOAD_AVATAR_URL' => $can_upload,
'S_LINK_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) ? true : false,
- 'S_GALLERY_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false,
- 'S_AVATAR_CAT_OPTIONS' => $s_categories,
- 'S_AVATAR_PAGE_OPTIONS' => $s_pages,)
+ 'S_GALLERY_AVATAR' => ($auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) ? true : false)
);
}