diff --git a/phpBB/includes/bbcode.php b/phpBB/includes/bbcode.php
index fc0fe4beef..ea0d6b2437 100644
--- a/phpBB/includes/bbcode.php
+++ b/phpBB/includes/bbcode.php
@@ -713,4 +713,56 @@ function bbcode_array_pop(&$stack)
return($return_val);
}
-?>
+//
+// Smilies code ... would this be better tagged on to the end of bbcode.php?
+// Probably so and I'll move it before B2
+//
+function smilies_pass($message)
+{
+ global $db, $board_config;
+ static $smilies;
+
+ if( empty($smilies) )
+ {
+ $sql = "SELECT code, smile_url
+ FROM " . SMILIES_TABLE;
+ if( !$result = $db->sql_query($sql) )
+ {
+ message_die(GENERAL_ERROR, "Couldn't obtain smilies data", "", __LINE__, __FILE__, $sql);
+ }
+
+ if( !$db->sql_numrows($result) )
+ {
+ return $message;
+ }
+
+ $smilies = $db->sql_fetchrowset($result);
+ }
+
+ usort($smilies, 'smiley_sort');
+ for($i = 0; $i < count($smilies); $i++)
+ {
+ $orig[] = "/(?<=.\\W|\\W.|^\\W)" . phpbb_preg_quote($smilies[$i]['code'], "/") . "(?=.\\W|\\W.|\\W$)/";
+ $repl[] = '
';
+ }
+
+ if( $i > 0 )
+ {
+ $message = preg_replace($orig, $repl, ' ' . $message . ' ');
+ $message = substr($message, 1, -1);
+ }
+
+ return $message;
+}
+
+function smiley_sort($a, $b)
+{
+ if ( strlen($a['code']) == strlen($b['code']) )
+ {
+ return 0;
+ }
+
+ return ( strlen($a['code']) > strlen($b['code']) ) ? -1 : 1;
+}
+
+?>
\ No newline at end of file
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php
index 732ff50585..995bb3d554 100644
--- a/phpBB/includes/functions.php
+++ b/phpBB/includes/functions.php
@@ -27,11 +27,6 @@ function get_db_stat($mode)
switch($mode)
{
- case 'postcount':
- $sql = "SELECT COUNT(post_id) AS total
- FROM " . POSTS_TABLE;
- break;
-
case 'usercount':
$sql = "SELECT COUNT(user_id) AS total
FROM " . USERS_TABLE . "
@@ -46,74 +41,68 @@ function get_db_stat($mode)
LIMIT 1";
break;
+ case 'postcount':
case 'topiccount':
- $sql = "SELECT SUM(forum_topics) AS total
+ $sql = "SELECT SUM(forum_topics) AS topic_total, SUM(forum_posts) AS post_total
FROM " . FORUMS_TABLE;
break;
}
- if(!$result = $db->sql_query($sql))
+ if ( !($result = $db->sql_query($sql)) )
{
return 'ERROR';
}
- else
+
+ $row = $db->sql_fetchrow($result);
+
+ switch ( $mode )
{
- $row = $db->sql_fetchrow($result);
- if($mode == 'newestuser')
- {
- return($row);
- }
- else
- {
- return($row['total']);
- }
+ case 'usercount':
+ return $row['total'];
+ break;
+ case 'newestuser':
+ return $row;
+ break;
+ case 'postcount':
+ return $row['post_total'];
+ break;
+ case 'topiccount':
+ return $row['topic_total'];
+ break;
}
+
+ return 'ERROR';
}
-function get_userdata_from_id($userid)
+function get_userdata_from_id($user_id)
{
global $db;
$sql = "SELECT *
FROM " . USERS_TABLE . "
- WHERE user_id = $userid";
- if(!$result = $db->sql_query($sql))
+ WHERE user_id = $user_id";
+ if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Couldn't obtain userdata for id", "", __LINE__, __FILE__, $sql);
}
- if( !$db->sql_numrows($result) )
- {
- return false;
- }
-
- $row = $db->sql_fetchrow($result);
-
- return($row);
-
+ return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
}
-function get_userdata($username) {
-
+function get_userdata($username)
+{
global $db;
$sql = "SELECT *
FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\'", "''", $username) . "'
AND user_id <> " . ANONYMOUS;
- if(!$result = $db->sql_query($sql))
+ if ( !($result = $db->sql_query($sql)) )
{
message_die(GENERAL_ERROR, "Tried obtaining data for a non-existent user", "", __LINE__, __FILE__, $sql);
}
- if( !$db->sql_numrows($result) )
- {
- return false;
- }
-
- $row = $db->sql_fetchrow($result);
-
- return($row);
+ return ( $row = $db->sql_fetchrow($result) ) ? $row : false;
}
function make_jumpbox($match_forum_id = 0)
@@ -165,7 +154,7 @@ function make_jumpbox($match_forum_id = 0)
// 'chapter' and 'forum' can create multiple items, therefore we are using a nested array.
//
$nav_links['chapter forum'][$forum_rows[$j]['forum_id']] = array (
- 'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=". $forum_rows[$j]['forum_id']),
+ 'url' => append_sid("viewforum.$phpEx?" . POST_FORUM_URL . "=" . $forum_rows[$j]['forum_id']),
'title' => $forum_rows[$j]['forum_name']
);
@@ -284,22 +273,15 @@ function init_userprefs($userdata)
{
if( $userdata['user_id'] != ANONYMOUS && isset($userdata['user_style']) )
{
- $theme = setup_style($userdata['user_style']);
- if( !$theme )
+ if( ($theme = setup_style($userdata['user_style'])) )
{
- $theme = setup_style($board_config['default_style']);
+ return;
}
}
- else
- {
- $theme = setup_style($board_config['default_style']);
- }
- }
- else
- {
- $theme = setup_style($board_config['default_style']);
}
+ $theme = setup_style($board_config['default_style']);
+
return;
}
@@ -366,7 +348,7 @@ function generate_activation_key()
}
$act_key_md = md5($act_key);
- return($act_key_md);
+ return $act_key_md;
}
function encode_ip($dotquad_ip)
@@ -399,7 +381,7 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add
$total_pages = ceil($num_items/$per_page);
- if( $total_pages == 1 )
+ if ( $total_pages == 1 )
{
return "";
}
@@ -407,49 +389,47 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add
$on_page = floor($start_item / $per_page) + 1;
$page_string = "";
-
- if( $total_pages > 8 )
+ if ( $total_pages > 10 )
{
-
- $init_page_max = ( $total_pages > 2 ) ? 2 : $total_pages;
+ $init_page_max = ( $total_pages > 3 ) ? 3 : $total_pages;
for($i = 1; $i < $init_page_max + 1; $i++)
{
- $page_string .= ($i == $on_page) ? "$i" : "$i";
- if( $i < $init_page_max )
+ $page_string .= ( $i == $on_page ) ? '' . $i . '' : '' . $i . '';
+ if ( $i < $init_page_max )
{
$page_string .= ", ";
}
}
- if( $total_pages > 2 )
+ if ( $total_pages > 3 )
{
- if( $on_page > 1 && $on_page < $total_pages )
+ if ( $on_page > 1 && $on_page < $total_pages )
{
- $page_string .= ( $on_page > 4 ) ? " ... " : ", ";
+ $page_string .= ( $on_page > 5 ) ? ' ... ' : ', ';
- $init_page_min = ( $on_page > 3 ) ? $on_page : 4;
- $init_page_max = ( $on_page < $total_pages - 3 ) ? $on_page : $total_pages - 3;
+ $init_page_min = ( $on_page > 4 ) ? $on_page : 5;
+ $init_page_max = ( $on_page < $total_pages - 4 ) ? $on_page : $total_pages - 4;
for($i = $init_page_min - 1; $i < $init_page_max + 2; $i++)
{
- $page_string .= ($i == $on_page) ? "$i" : "$i";
- if( $i < $init_page_max + 1 )
+ $page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . '';
+ if ( $i < $init_page_max + 1 )
{
- $page_string .= ", ";
+ $page_string .= ', ';
}
}
- $page_string .= ( $on_page < $total_pages - 3 ) ? " ... " : ", ";
+ $page_string .= ( $on_page < $total_pages - 4 ) ? ' ... ' : ', ';
}
else
{
- $page_string .= " ... ";
+ $page_string .= ' ... ';
}
- for($i = $total_pages - 1; $i < $total_pages + 1; $i++)
+ for($i = $total_pages - 2; $i < $total_pages + 1; $i++)
{
- $page_string .= ($i == $on_page) ? "$i" : "$i";
+ $page_string .= ( $i == $on_page ) ? '' . $i . '' : '' . $i . '';
if( $i < $total_pages )
{
$page_string .= ", ";
@@ -461,32 +441,31 @@ function generate_pagination($base_url, $num_items, $per_page, $start_item, $add
{
for($i = 1; $i < $total_pages + 1; $i++)
{
- $page_string .= ($i == $on_page) ? "$i" : "$i";
- if( $i < $total_pages )
+ $page_string .= ( $i == $on_page ) ? '' . $i . '' : '' . $i . '';
+ if ( $i < $total_pages )
{
- $page_string .= ", ";
+ $page_string .= ', ';
}
}
}
- if( $add_prevnext_text )
+ if ( $add_prevnext_text )
{
- if($on_page > 1)
+ if ( $on_page > 1 )
{
- $page_string = " " . $lang['Previous'] . " " . $page_string;
+ $page_string = ' ' . $lang['Previous'] . ' ' . $page_string;
}
- if($on_page < $total_pages)
+ if ( $on_page < $total_pages )
{
- $page_string .= " " . $lang['Next'] . "";
+ $page_string .= ' ' . $lang['Next'] . '';
}
}
- $page_string = $lang['Goto_page'] . " " . $page_string;
+ $page_string = $lang['Goto_page'] . ' ' . $page_string;
return $page_string;
-
}
@@ -499,37 +478,33 @@ function validate_username($username)
{
global $db, $lang, $userdata;
- $sql = "SELECT u.username, g.group_name
- FROM " . USERS_TABLE . " u, " . GROUPS_TABLE . " g, " . USER_GROUP_TABLE . " ug
- WHERE ug.user_id = u.user_id
- AND g.group_id = ug.group_id
- AND ( LOWER(u.username) = '" . strtolower(str_replace("\'", "''", $username)) . "'
- OR LOWER(g.group_name) = '" . strtolower(str_replace("\'", "''", $username)) . "' )";
+ $username = str_replace("\'", "''", $username);
+
+ $sql = "SELECT username
+ FROM " . USERS_TABLE . "
+ WHERE LOWER(username) = '" . strtolower($username) . "'";
if ( $result = $db->sql_query($sql) )
{
if ( $row = $db->sql_fetchrow($result) )
{
- if($userdata['session_logged_in'])
- {
- if($row['username'] != $userdata['username'])
- {
- return array('error' => $lang['Username_taken']);
- }
- else
- {
- return array('error' => '');
- }
- }
- else
- {
- return array('error' => $lang['Username_taken']);
- }
+ return ( $userdata['session_logged_in'] ) ? ( ( $row['username'] != $userdata['username'] ) ? array('error' => $lang['Username_taken']) : array('error' => '') ) : array('error' => $lang['Username_taken']);
+ }
+ }
+
+ $sql = "SELECT group_name
+ FROM " . GROUPS_TABLE . "
+ WHERE LOWER(group_name) = '" . strtolower($username) . "'";
+ if ( $result = $db->sql_query($sql) )
+ {
+ if ( $row = $db->sql_fetchrow($result) )
+ {
+ return array('error' => $lang['Username_taken']);
}
}
$sql = "SELECT disallow_username
FROM " . DISALLOW_TABLE . "
- WHERE '" . str_replace("\'", "''", $username) . "' LIKE disallow_username";
+ WHERE disallow_username LIKE '$username'";
if ( $result = $db->sql_query($sql) )
{
if ( $db->sql_fetchrow($result) )
@@ -577,12 +552,11 @@ function sync($type, $id)
{
message_die(GENERAL_ERROR, "Could not get forum IDs", "Error", __LINE__, __FILE__, $sql);
}
- $rowset = $db->sql_fetchrowset($result);
- for($i = 0; $i < count($rowset); $i++)
+ while( $row = $db->sql_fetchrow($result) )
{
- sync("forum", $row[$i]['forum_id']);
- }
+ sync("forum", $row['forum_id']);
+ }
break;
case 'all topics':
@@ -592,11 +566,10 @@ function sync($type, $id)
{
message_die(GENERAL_ERROR, "Could not get topic ID's", "Error", __LINE__, __FILE__, $sql);
}
- $rowset = $db->sql_fetchrowset($result);
- for($i = 0; $i < count($rowset); $i++)
+ while( $row = $db->sql_fetchrow($result) )
{
- sync("topic", $row[$i]['topic_id']);
+ sync("topic", $row['topic_id']);
}
break;
@@ -665,7 +638,7 @@ function sync($type, $id)
break;
case 'topic':
- $sql = "SELECT MAX(post_id) AS last_post
+ $sql = "SELECT MAX(post_id) AS last_post, MIN(post_id) AS first_post, COUNT(post_id) AS total_posts
FROM " . POSTS_TABLE . "
WHERE topic_id = $id";
if( !$result = $db->sql_query($sql) )
@@ -675,45 +648,21 @@ function sync($type, $id)
if( $row = $db->sql_fetchrow($result) )
{
- $last_post = ($row['last_post']) ? $row['last_post'] : 0;
- }
- else
- {
- $last_post = 0;
+ $sql = "UPDATE " . TOPICS_TABLE . "
+ SET topic_replies = " . ( $row['total_posts'] - 1 ) . ", topic_first_post_id = " . $row['first_post'] . ", topic_last_post_id = " . $row['last_post'] . "
+ WHERE topic_id = $id";
+ if( !($result = $db->sql_query($sql)) )
+ {
+ message_die(GENERAL_ERROR, "Could not update topic $id", "Error", __LINE__, __FILE__, $sql);
+ }
}
- $sql = "SELECT COUNT(post_id) AS total
- FROM " . POSTS_TABLE . "
- WHERE topic_id = $id";
- if( !$result = $db->sql_query($sql) )
- {
- message_die(GENERAL_ERROR, "Could not get post count", "Error", __LINE__, __FILE__, $sql);
- }
-
- if( $row = $db->sql_fetchrow($result) )
- {
- $total_posts = ($row['total']) ? $row['total'] - 1 : 0;
- }
- else
- {
- $total_posts = 0;
- }
-
- $sql = "UPDATE " . TOPICS_TABLE . "
- SET topic_replies = $total_posts, topic_last_post_id = $last_post
- WHERE topic_id = $id";
- if( !$result = $db->sql_query($sql) )
- {
- message_die(GENERAL_ERROR, "Could not update topic $id", "Error", __LINE__, __FILE__, $sql);
- }
break;
}
-
- return(TRUE);
-
+
+ return true;
}
-
//
// Pick a language, any language ...
//
@@ -723,30 +672,35 @@ function language_select($default, $select_name = "language", $dirname="language
$dir = opendir($dirname);
- $lang_select = "";
closedir($dir);
+ @asort($lang);
+ @reset($lang);
+
+ $lang_select = '';
+
return $lang_select;
}
-
//
-// Pick a template/theme combo, personally recommend
-// PSO - Blue but then I would ...
+// Pick a template/theme combo,
//
function style_select($default_style, $select_name = "style", $dirname = "templates")
{
@@ -762,19 +716,18 @@ function style_select($default_style, $select_name = "style", $dirname = "templa
$template_style = $db->sql_fetchrowset($result);
- $style_select = "