diff options
33 files changed, 723 insertions, 65 deletions
diff --git a/phpBB/adm/style/acp_ban.html b/phpBB/adm/style/acp_ban.html index 539e8032dd..cf44f4aaa7 100644 --- a/phpBB/adm/style/acp_ban.html +++ b/phpBB/adm/style/acp_ban.html @@ -31,9 +31,9 @@  	function display_details(option)  	{ -		document.getElementById('acp_unban').unbangivereason.value = ban_give_reason[option]; -		document.getElementById('acp_unban').unbanreason.value = ban_reason[option]; -		document.getElementById('acp_unban').unbanlength.value = ban_length[option]; +		document.getElementById('acp_unban').unbangivereason.innerHTML = ban_give_reason[option]; +		document.getElementById('acp_unban').unbanreason.innerHTML = ban_reason[option]; +		document.getElementById('acp_unban').unbanlength.innerHTML = ban_length[option];  	}  // ]]> diff --git a/phpBB/docs/coding-guidelines.html b/phpBB/docs/coding-guidelines.html index 7f747e09e2..1978a0a307 100644 --- a/phpBB/docs/coding-guidelines.html +++ b/phpBB/docs/coding-guidelines.html @@ -288,7 +288,7 @@ PHPBB_QA                   (Set board to QA-Mode, which means the updater also c  		<div class="content"> -	<p>Please note that these Guidelines applies to all php, html, javascript and css files.</p> +	<p>Please note that these guidelines apply to all php, html, javascript and css files.</p>  	<a name="namingvars"></a><h3>2.i. Variable/Function Naming</h3> diff --git a/phpBB/includes/acp/acp_ban.php b/phpBB/includes/acp/acp_ban.php index 3198376584..a7ea57b753 100644 --- a/phpBB/includes/acp/acp_ban.php +++ b/phpBB/includes/acp/acp_ban.php @@ -224,7 +224,7 @@ class acp_ban  				$template->assign_block_vars('ban_reason', array(  					'BAN_ID'	=> $ban_id,  					'REASON'	=> $reason, -					'A_REASON'	=> addslashes(htmlspecialchars_decode($reason)), +					'A_REASON'	=> addslashes($reason),  				));  			}  		} @@ -236,7 +236,7 @@ class acp_ban  				$template->assign_block_vars('ban_give_reason', array(  					'BAN_ID'	=> $ban_id,  					'REASON'	=> $reason, -					'A_REASON'	=> addslashes(htmlspecialchars_decode($reason)), +					'A_REASON'	=> addslashes($reason),  				));  			}  		} diff --git a/phpBB/includes/acp/acp_captcha.php b/phpBB/includes/acp/acp_captcha.php index 56a57e319c..1893eed14f 100644 --- a/phpBB/includes/acp/acp_captcha.php +++ b/phpBB/includes/acp/acp_captcha.php @@ -89,14 +89,14 @@ class acp_captcha  					}  					else  					{ -						trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action)); +						trigger_error($user->lang['CAPTCHA_UNAVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING);  					}  				}  				trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));  			}  			else if ($submit)  			{ -				trigger_error($user->lang['FORM_INVALID'] . adm_back_link()); +				trigger_error($user->lang['FORM_INVALID'] . adm_back_link(), E_USER_WARNING);  			}  			else  			{ diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index 6261f866bb..f2f1bd80e2 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -983,7 +983,7 @@ class acp_forums  				if (!$row)  				{ -					trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&' . $this->parent_id), E_USER_WARNING); +					trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);  				}  				if ($row['forum_type'] == FORUM_LINK) diff --git a/phpBB/includes/acp/acp_php_info.php b/phpBB/includes/acp/acp_php_info.php index 9935c0466e..0499095004 100644 --- a/phpBB/includes/acp/acp_php_info.php +++ b/phpBB/includes/acp/acp_php_info.php @@ -35,9 +35,9 @@ class acp_php_info  		$this->tpl_name = 'acp_php_info';  		$this->page_title = 'ACP_PHP_INFO'; -		 +  		ob_start(); -		@phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES | INFO_VARIABLES); +		phpinfo(INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES | INFO_VARIABLES);  		$phpinfo = ob_get_clean();  		$phpinfo = trim($phpinfo); diff --git a/phpBB/includes/acp/acp_prune.php b/phpBB/includes/acp/acp_prune.php index 7eeb37133f..ffe20f86f5 100644 --- a/phpBB/includes/acp/acp_prune.php +++ b/phpBB/includes/acp/acp_prune.php @@ -315,8 +315,8 @@ class acp_prune  					'mode'			=> $mode,  					'prune'			=> 1, -					'users'			=> request_var('users', '', true), -					'username'		=> request_var('username', '', true), +					'users'			=> utf8_normalize_nfc(request_var('users', '', true)), +					'username'		=> utf8_normalize_nfc(request_var('username', '', true)),  					'email'			=> request_var('email', ''),  					'joined_select'	=> request_var('joined_select', ''),  					'joined'		=> request_var('joined', ''), @@ -369,7 +369,7 @@ class acp_prune  	{  		global $user, $db; -		$users = request_var('users', '', true); +		$users = utf8_normalize_nfc(request_var('users', '', true));  		if ($users)  		{ @@ -378,7 +378,7 @@ class acp_prune  		}  		else  		{ -			$username = request_var('username', '', true); +			$username = utf8_normalize_nfc(request_var('username', '', true));  			$email = request_var('email', '');  			$joined_select = request_var('joined_select', 'lt'); diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 7914edd056..3a405da825 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1706,7 +1706,7 @@ class acp_users  							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&u=' . $user_id), E_USER_WARNING);  					} -					if (avatar_process_user($error, $user_row)) +					if (avatar_process_user($error, $user_row, $can_upload))  					{  						trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&u=' . $user_row['user_id']));  					} diff --git a/phpBB/includes/acp/info/acp_board.php b/phpBB/includes/acp/info/acp_board.php index 58b650650c..3e18f55940 100644 --- a/phpBB/includes/acp/info/acp_board.php +++ b/phpBB/includes/acp/info/acp_board.php @@ -24,7 +24,7 @@ class acp_board_info  				'features'		=> array('title' => 'ACP_BOARD_FEATURES', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),  				'avatar'		=> array('title' => 'ACP_AVATAR_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),  				'message'		=> array('title' => 'ACP_MESSAGE_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION', 'ACP_MESSAGES')), -				'post'			=> array('title' => 'ACP_POST_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')), +				'post'			=> array('title' => 'ACP_POST_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION', 'ACP_MESSAGES')),  				'signature'		=> array('title' => 'ACP_SIGNATURE_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),  				'feed'			=> array('title' => 'ACP_FEED_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')),  				'registration'	=> array('title' => 'ACP_REGISTER_SETTINGS', 'auth' => 'acl_a_board', 'cat' => array('ACP_BOARD_CONFIGURATION')), diff --git a/phpBB/includes/db/oracle.php b/phpBB/includes/db/oracle.php index 55b3599800..5a9b18abf0 100644 --- a/phpBB/includes/db/oracle.php +++ b/phpBB/includes/db/oracle.php @@ -261,6 +261,10 @@ class dbal_oracle extends dbal  						{  							$cols = explode(', ', $regs[2]); +/*						The code inside this comment block breaks clob handling, but does allow the +						database restore script to work.  If you want to allow no posts longer than 4KB +						and/or need the db restore script, uncomment this. +  							preg_match_all('/\'(?:[^\']++|\'\')*+\'|[\d-.]+/', $regs[3], $vals, PREG_PATTERN_ORDER);  							if (sizeof($cols) !== sizeof($vals)) @@ -310,6 +314,7 @@ class dbal_oracle extends dbal  								$vals = array(0 => $vals);  							} +*/  							$inserts = $vals[0];  							unset($vals); diff --git a/phpBB/includes/db/postgres.php b/phpBB/includes/db/postgres.php index b3139b3d79..2a885f1d04 100644 --- a/phpBB/includes/db/postgres.php +++ b/phpBB/includes/db/postgres.php @@ -46,7 +46,10 @@ class dbal_postgres extends dbal  		if ($sqlserver)  		{ -			if (strpos($sqlserver, ':') !== false) +			// $sqlserver can carry a port separated by : for compatibility reasons +			// If $sqlserver has more than one : it's probably an IPv6 address. +			// In this case we only allow passing a port via the $port variable. +			if (substr_count($sqlserver, ':') === 1)  			{  				list($sqlserver, $port) = explode(':', $sqlserver);  			} diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 3e80f93114..3f097f171f 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -1660,10 +1660,11 @@ function get_complete_topic_tracking($forum_id, $topic_ids, $global_announce_lis  * @param string $sql_extra		Extra WHERE SQL statement  * @param string $sql_sort		ORDER BY SQL sorting statement  * @param string $sql_limit		Limits the size of unread topics list, 0 for unlimited query +* @param string $sql_limit_offset  Sets the offset of the first row to search, 0 to search from the start  *  * @return array[int][int]		Topic ids as keys, mark_time of topic as value  */ -function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001) +function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $sql_limit = 1001, $sql_limit_offset = 0)  {  	global $config, $db, $user; @@ -1709,7 +1710,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s  		);  		$sql = $db->sql_build_query('SELECT', $sql_array); -		$result = $db->sql_query_limit($sql, $sql_limit); +		$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);  		while ($row = $db->sql_fetchrow($result))  		{ @@ -1742,7 +1743,7 @@ function get_unread_topics($user_id = false, $sql_extra = '', $sql_sort = '', $s  			WHERE t.topic_last_post_time > ' . $user_lastmark . "  			$sql_extra  			$sql_sort"; -		$result = $db->sql_query_limit($sql, $sql_limit); +		$result = $db->sql_query_limit($sql, $sql_limit, $sql_limit_offset);  		while ($row = $db->sql_fetchrow($result))  		{ diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index 0fdae9b274..c035fd3739 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1025,6 +1025,9 @@ function set_user_options()  		'bbcode'		=> array('bit' => 8, 'default' => 1),  		'smilies'		=> array('bit' => 9, 'default' => 1),  		'popuppm'		=> array('bit' => 10, 'default' => 0), +		'sig_bbcode'	=> array('bit' => 15, 'default' => 1), +		'sig_smilies'	=> array('bit' => 16, 'default' => 1), +		'sig_links'		=> array('bit' => 17, 'default' => 1),  	);  	$option_field = 0; diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index ec348138f5..5e6239b070 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -969,11 +969,16 @@ function display_user_activity(&$userdata)  	$forum_ary = array_unique($forum_ary);  	$forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : ''; +	$fid_m_approve = $auth->acl_getf('m_approve', true); +	$sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : ''; +  	// Obtain active forum  	$sql = 'SELECT forum_id, COUNT(post_id) AS num_posts  		FROM ' . POSTS_TABLE . '  		WHERE poster_id = ' . $userdata['user_id'] . "  			AND post_postcount = 1 +			AND (post_approved = 1 +				$sql_m_approve)  			$forum_sql  		GROUP BY forum_id  		ORDER BY num_posts DESC"; @@ -996,6 +1001,8 @@ function display_user_activity(&$userdata)  		FROM ' . POSTS_TABLE . '  		WHERE poster_id = ' . $userdata['user_id'] . "  			AND post_postcount = 1 +			AND (post_approved = 1 +				$sql_m_approve)  			$forum_sql  		GROUP BY topic_id  		ORDER BY num_posts DESC"; diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 21e82030ee..bb99314ced 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -297,6 +297,7 @@ function user_add($user_row, $cp_data = false)  			if ($config['new_member_group_default'])  			{  				group_user_add($add_group_id, $user_id, false, false, true); +				$user_row['group_id'] = $add_group_id;  			}  			else  			{ @@ -527,7 +528,7 @@ function user_delete($mode, $user_id, $post_username = false)  	$db->sql_transaction('begin'); -	$table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE); +	$table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE, PRIVMSGS_FOLDER_TABLE, PRIVMSGS_RULES_TABLE);  	foreach ($table_ary as $table)  	{ @@ -2283,7 +2284,7 @@ function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $  /**  * Uploading/Changing user avatar  */ -function avatar_process_user(&$error, $custom_userdata = false) +function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null)  {  	global $config, $phpbb_root_path, $auth, $user, $db; @@ -2322,7 +2323,10 @@ function avatar_process_user(&$error, $custom_userdata = false)  	$avatar_select = basename(request_var('avatar_select', ''));  	// Can we upload? -	$can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; +	if (is_null($can_upload)) +	{ +		$can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; +	}  	if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload)  	{ diff --git a/phpBB/includes/session.php b/phpBB/includes/session.php index 0a01b4e73b..e157053e61 100644 --- a/phpBB/includes/session.php +++ b/phpBB/includes/session.php @@ -2134,9 +2134,9 @@ class user extends session  		// Zone offset  		$zone_offset = $this->timezone + $this->dst; -		// Show date <= 1 hour ago as 'xx min ago' +		// Show date <= 1 hour ago as 'xx min ago' but not greater than 60 seconds in the future  		// A small tolerence is given for times in the future but in the same minute are displayed as '< than a minute ago' -		if ($delta <= 3600 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO'])) +		if ($delta <= 3600 && $delta > -60 && ($delta >= -5 || (($now / 60) % 60) == (($gmepoch / 60) % 60)) && $date_cache[$format]['is_short'] !== false && !$forcedate && isset($this->lang['datetime']['AGO']))  		{  			return $this->lang(array('datetime', 'AGO'), max(0, (int) floor($delta / 60)));  		} diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index f4f4abad4a..363a4803b6 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -572,7 +572,7 @@ class ucp_profile  				{  					if (check_form_key('ucp_avatar'))  					{ -						if (avatar_process_user($error)) +						if (avatar_process_user($error, false, $can_upload))  						{  							meta_refresh(3, $this->u_action);  							$message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>'); diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 47d261dc46..83bbbf4577 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -685,7 +685,6 @@ function _add_modules($modules_to_install)  				WHERE module_class = '" . $db->sql_escape($module_data['class']) . "'  					AND parent_id = {$parent_id}  					AND left_id BETWEEN {$first_left_id} AND {$module_row['left_id']} -				GROUP BY left_id  				ORDER BY left_id";  			$result = $db->sql_query($sql);  			$steps = (int) $db->sql_fetchfield('num_modules'); @@ -1684,6 +1683,71 @@ function change_database_data(&$no_updates, $version)  			}  			$db->sql_freeresult($result); +			// Install modules +			$modules_to_install = array( +				'post'					=> array( +					'base'		=> 'board', +					'class'		=> 'acp', +					'title'		=> 'ACP_POST_SETTINGS', +					'auth'		=> 'acl_a_board', +					'cat'		=> 'ACP_MESSAGES', +					'after'		=> array('message', 'ACP_MESSAGE_SETTINGS') +				), +			); + +			_add_modules($modules_to_install); + +			// add Bing Bot +			$sql = 'SELECT group_id, group_colour +				FROM ' . GROUPS_TABLE . " +				WHERE group_name = 'BOTS'"; +			$result = $db->sql_query($sql); +			$group_row = $db->sql_fetchrow($result); +			$db->sql_freeresult($result); + +			if (!$group_row) +			{ +				// default fallback, should never get here +				$group_row['group_id'] = 6; +				$group_row['group_colour'] = '9E8DA7'; +			} + +			if (!function_exists('user_add')) +			{ +				include($phpbb_root_path . 'includes/functions_user.' . $phpEx); +			} + +			$bot_name = 'Bing [Bot]'; +			$bot_agent = 'bingbot/'; +			$bot_ip = ''; + +			$user_row = array( +				'user_type'				=> USER_IGNORE, +				'group_id'				=> $group_row['group_id'], +				'username'				=> $bot_name, +				'user_regdate'			=> time(), +				'user_password'			=> '', +				'user_colour'			=> $group_row['group_colour'], +				'user_email'			=> '', +				'user_lang'				=> $config['default_lang'], +				'user_style'			=> $config['default_style'], +				'user_timezone'			=> 0, +				'user_dateformat'		=> $config['default_dateformat'], +				'user_allow_massemail'	=> 0, +			); + +			$user_id = user_add($user_row); + +			$sql = 'INSERT INTO ' . BOTS_TABLE . ' ' . $db->sql_build_array('INSERT', array( +				'bot_active'	=> 1, +				'bot_name'		=> (string) $bot_name, +				'user_id'		=> (int) $user_id, +				'bot_agent'		=> (string) $bot_agent, +				'bot_ip'		=> (string) $bot_ip, +			)); + +			_sql($sql, $errored, $error_ary); +			// end Bing Bot addition  			$no_updates = false;  		break; diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index f4989b5bd7..4c22db07b2 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -2108,6 +2108,7 @@ class install_install extends module  		'Alta Vista [Bot]'			=> array('Scooter/', ''),  		'Ask Jeeves [Bot]'			=> array('Ask Jeeves', ''),  		'Baidu [Spider]'			=> array('Baiduspider+(', ''), +		'Bing [Bot]'                => array('bingbot/', ''),  		'Exabot [Bot]'				=> array('Exabot/', ''),  		'FAST Enterprise [Crawler]'	=> array('FAST Enterprise Crawler', ''),  		'FAST WebCrawler [Crawler]'	=> array('FAST-WebCrawler/', ''), diff --git a/phpBB/search.php b/phpBB/search.php index 7a9ab82f93..1e1e42d01f 100644 --- a/phpBB/search.php +++ b/phpBB/search.php @@ -387,18 +387,6 @@ if ($keywords || $author || $author_id || $search_id || $submit)  				gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);  				$s_sort_key = $s_sort_dir = $u_sort_param = $s_limit_days = ''; - -				$unread_list = array(); -				$unread_list = get_unread_topics($user->data['user_id'], $sql_where, $sql_sort); - -				if (!empty($unread_list)) -				{ -					$sql = 'SELECT t.topic_id -						FROM ' . TOPICS_TABLE . ' t -						WHERE ' . $db->sql_in_set('t.topic_id', array_keys($unread_list)) . " -						$sql_sort"; -					$field = 'topic_id'; -				}  			break;  			case 'newposts': @@ -476,6 +464,13 @@ if ($keywords || $author || $author_id || $search_id || $submit)  			$total_match_count = sizeof($id_ary) + $start;  			$id_ary = array_slice($id_ary, 0, $per_page);  		} +		else if ($search_id == 'unreadposts') +		{ +			$id_ary = array_keys(get_unread_topics($user->data['user_id'], $sql_where, $sql_sort, 1001 - $start, $start)); + +			$total_match_count = sizeof($id_ary) + $start; +			$id_ary = array_slice($id_ary, 0, $per_page); +		}  		else  		{  			$search_id = ''; diff --git a/phpBB/styles/prosilver/template/ucp_profile_signature.html b/phpBB/styles/prosilver/template/ucp_profile_signature.html index 5d25d2d9f4..ab23b84076 100644 --- a/phpBB/styles/prosilver/template/ucp_profile_signature.html +++ b/phpBB/styles/prosilver/template/ucp_profile_signature.html @@ -4,7 +4,7 @@  <h2>{L_TITLE}</h2> -<!-- IF SIGNATURE_PREVIEW --> +<!-- IF SIGNATURE_PREVIEW != '' -->  	<div class="panel">  		<div class="inner"><span class="corners-top"><span></span></span>  		<h3>{L_SIGNATURE_PREVIEW}</h3> diff --git a/phpBB/styles/prosilver/template/viewforum_body.html b/phpBB/styles/prosilver/template/viewforum_body.html index cc38ed9d2b..309375c269 100644 --- a/phpBB/styles/prosilver/template/viewforum_body.html +++ b/phpBB/styles/prosilver/template/viewforum_body.html @@ -122,12 +122,12 @@  	<!-- ENDIF -->  	<!-- IF topicrow.S_FIRST_ROW or not topicrow.S_TOPIC_TYPE_SWITCH --> -		<div class="forumbg<!-- IF topicrow.S_TOPIC_TYPE_SWITCH --> announcement<!-- ENDIF -->"> +		<div class="forumbg<!-- IF topicrow.S_TOPIC_TYPE_SWITCH and (topicrow.S_POST_ANNOUNCE or topicrow.S_POST_GLOBAL) --> announcement<!-- ENDIF -->">  		<div class="inner"><span class="corners-top"><span></span></span>  		<ul class="topiclist">  			<li class="header">  				<dl class="icon"> -					<dt><!-- IF S_DISPLAY_ACTIVE -->{L_ACTIVE_TOPICS}<!-- ELSEIF topicrow.S_TOPIC_TYPE_SWITCH and topicrow.S_TOPIC_TYPE gt 1 -->{L_ANNOUNCEMENTS}<!-- ELSE -->{L_TOPICS}<!-- ENDIF --></dt> +					<dt><!-- IF S_DISPLAY_ACTIVE -->{L_ACTIVE_TOPICS}<!-- ELSEIF topicrow.S_TOPIC_TYPE_SWITCH and (topicrow.S_POST_ANNOUNCE or topicrow.S_POST_GLOBAL) -->{L_ANNOUNCEMENTS}<!-- ELSE -->{L_TOPICS}<!-- ENDIF --></dt>  					<dd class="posts">{L_REPLIES}</dd>  					<dd class="views">{L_VIEWS}</dd>  					<dd class="lastpost"><span>{L_LAST_POST}</span></dd> @@ -137,7 +137,7 @@  		<ul class="topiclist topics">  	<!-- ENDIF --> -		<li class="row<!-- IF topicrow.S_ROW_COUNT is even --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- IF topicrow.S_POST_ANNOUNCE --> announce<!-- ENDIF --><!-- IF topicrow.S_POST_STICKY --> sticky<!-- ENDIF --><!-- IF topicrow.S_TOPIC_REPORTED --> reported<!-- ENDIF -->"> +		<li class="row<!-- IF topicrow.S_ROW_COUNT is even --> bg1<!-- ELSE --> bg2<!-- ENDIF --><!-- IF topicrow.S_POST_GLOBAL --> global-announce<!-- ENDIF --><!-- IF topicrow.S_POST_ANNOUNCE --> announce<!-- ENDIF --><!-- IF topicrow.S_POST_STICKY --> sticky<!-- ENDIF --><!-- IF topicrow.S_TOPIC_REPORTED --> reported<!-- ENDIF -->">  			<dl class="icon" style="background-image: url({topicrow.TOPIC_FOLDER_IMG_SRC}); background-repeat: no-repeat;">  				<dt<!-- IF topicrow.TOPIC_ICON_IMG and S_TOPIC_ICONS --> style="background-image: url({T_ICONS_PATH}{topicrow.TOPIC_ICON_IMG}); background-repeat: no-repeat;"<!-- ENDIF --> title="{topicrow.TOPIC_FOLDER_IMG_ALT}"><!-- IF topicrow.S_UNREAD_TOPIC --><a href="{topicrow.U_NEWEST_POST}">{NEWEST_POST_IMG}</a> <!-- ENDIF --><a href="{topicrow.U_VIEW_TOPIC}" class="topictitle">{topicrow.TOPIC_TITLE}</a>  					<!-- IF topicrow.S_TOPIC_UNAPPROVED or topicrow.S_POSTS_UNAPPROVED --><a href="{topicrow.U_MCP_QUEUE}">{topicrow.UNAPPROVED_IMG}</a> <!-- ENDIF --> diff --git a/phpBB/styles/prosilver/theme/forms.css b/phpBB/styles/prosilver/theme/forms.css index 4db342661c..4e48a93a55 100644 --- a/phpBB/styles/prosilver/theme/forms.css +++ b/phpBB/styles/prosilver/theme/forms.css @@ -96,6 +96,11 @@ fieldset.fields1 div {  	margin-bottom: 3px;  } +/* Set it back to 0px for the reCaptcha divs: PHPBB3-9587 */ +fieldset.fields1 #recaptcha_widget_div div { +	margin-bottom: 0; +} +  /* Specific layout 2 */  fieldset.fields2 dt {  	width: 15em; diff --git a/phpBB/styles/subsilver2/template/ucp_profile_signature.html b/phpBB/styles/subsilver2/template/ucp_profile_signature.html index 2b396ea0df..a33726e166 100644 --- a/phpBB/styles/subsilver2/template/ucp_profile_signature.html +++ b/phpBB/styles/subsilver2/template/ucp_profile_signature.html @@ -93,7 +93,7 @@  	</td>  </tr> -<!-- IF SIGNATURE_PREVIEW --> +<!-- IF SIGNATURE_PREVIEW != '' -->  	<tr>  		<th colspan="2" valign="middle">{L_SIGNATURE_PREVIEW}</th>  	</tr> diff --git a/phpBB/styles/subsilver2/template/viewtopic_body.html b/phpBB/styles/subsilver2/template/viewtopic_body.html index 8f01c64c0e..bba00ce685 100644 --- a/phpBB/styles/subsilver2/template/viewtopic_body.html +++ b/phpBB/styles/subsilver2/template/viewtopic_body.html @@ -238,7 +238,7 @@  						<span class="gensmall error"><br /><br />{L_DOWNLOAD_NOTICE}</span>  					<!-- ENDIF -->  					<!-- IF postrow.SIGNATURE --> -						<span class="postbody"><br />_________________<br />{postrow.SIGNATURE}</span> +						<div class="postbody"><br />_________________<br />{postrow.SIGNATURE}</div>  					<!-- ENDIF -->  					<!-- IF postrow.EDITED_MESSAGE or postrow.EDIT_REASON --> diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt new file mode 100644 index 0000000000..f1b40f71ad --- /dev/null +++ b/tests/RUNNING_TESTS.txt @@ -0,0 +1,33 @@ +Running Tests +------------- + +Prerequisites +------------- + +PHPUnit +======= + +phpBB unit tests use PHPUnit framework. Version 3.3 or better is required +to run the tests. PHPUnit prefers to be installed via PEAR; refer to +http://www.phpunit.de/ for more information. + +PHP extensions +============== + +Unit tests use several PHP extensions that board code does not use. Currently +the following PHP extensions must be installed and enabled to run unit tests: + +- ctype + +Running +------- + +Once the prerequisites are installed, run the tests from tests directory: + +$ phpunit all_tests.php + +More Information +---------------- + +Further information is available on phpbb wiki: +http://wiki.phpbb.com/display/DEV/Unit+Tests diff --git a/tests/all_tests.php b/tests/all_tests.php index e693427809..7894d688ee 100644 --- a/tests/all_tests.php +++ b/tests/all_tests.php @@ -23,6 +23,7 @@ require_once 'security/all_tests.php';  require_once 'template/all_tests.php';  require_once 'text_processing/all_tests.php';  require_once 'dbal/all_tests.php'; +require_once 'regex/all_tests.php';  // exclude the test directory from code coverage reports  PHPUnit_Util_Filter::addDirectoryToFilter('./'); @@ -44,6 +45,7 @@ class phpbb_all_tests  		$suite->addTest(phpbb_template_all_tests::suite());  		$suite->addTest(phpbb_text_processing_all_tests::suite());  		$suite->addTest(phpbb_dbal_all_tests::suite()); +		$suite->addTest(phpbb_regex_all_tests::suite());  		return $suite;  	} diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index f90b5efeb5..1cce891ca9 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -21,10 +21,7 @@ class phpbb_dbal_test extends phpbb_database_test_case  	{  		return array(  			array('phpbb_users', "username_clean = 'bertie'", array(array('username_clean' => 'bertie'))), -			array('phpbb_users', "username_clean = 'phpBB'", array()),  			array('phpbb_users', 'username_clean syntax_error', false), -			array('phpbb_users', 'column_not_exists = 2', false), -			array('table_not_exists', 'column_not_exists = 2', false),  		);  	} @@ -103,7 +100,6 @@ class phpbb_dbal_test extends phpbb_database_test_case  		return array(  			array('', array('barfoo', 'foobar', 'bertie')),  			array('user_id = 2', array('foobar')), -			array("username_clean = 'bertie'", array('bertie')),  		);  	} @@ -138,7 +134,6 @@ class phpbb_dbal_test extends phpbb_database_test_case  			array(0, 1, array(array('username_clean' => 'foobar'),  				array('username_clean' => 'bertie'))),  			array(1, 0, array(array('username_clean' => 'barfoo'))), -			array(1, 1, array(array('username_clean' => 'foobar'))),  			array(1, 2, array(array('username_clean' => 'bertie'))),  			array(2, 0, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'))), @@ -180,9 +175,6 @@ class phpbb_dbal_test extends phpbb_database_test_case  			array('bar*', array(array('username_clean' => 'barfoo'))),  			array('*bar*', array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'))), -			array('*b*', array(array('username_clean' => 'barfoo'), -				array('username_clean' => 'foobar'), -				array('username_clean' => 'bertie'))),  			array('b*r', array()),  			array('b*e', array(array('username_clean' => 'bertie'))),  			array('#b*e', array()), @@ -220,11 +212,11 @@ class phpbb_dbal_test extends phpbb_database_test_case  				array('username_clean' => 'foobar'))),  			array('user_id', 3, true, true, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'))), -			array('user_id', '3', false, false, array(array('username_clean' => 'bertie'))), -			array('user_id', '3', false, true, array(array('username_clean' => 'bertie'))), -			array('user_id', '3', true, false, array(array('username_clean' => 'barfoo'), +			array('username_clean', 'bertie', false, false, array(array('username_clean' => 'bertie'))), +			array('username_clean', 'bertie', false, true, array(array('username_clean' => 'bertie'))), +			array('username_clean', 'bertie', true, false, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'))), -			array('user_id', '3', true, true, array(array('username_clean' => 'barfoo'), +			array('username_clean', 'bertie', true, true, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'))),  			array('user_id', array(3), false, false, array(array('username_clean' => 'bertie'))),  			array('user_id', array(3), false, true, array(array('username_clean' => 'bertie'))), @@ -238,12 +230,12 @@ class phpbb_dbal_test extends phpbb_database_test_case  				array('username_clean' => 'bertie'))),  			array('user_id', array(1, 3), true, false, array(array('username_clean' => 'foobar'))),  			array('user_id', array(1, 3), true, true, array(array('username_clean' => 'foobar'))), -			array('user_id', '', false, false, array()), -			array('user_id', '', false, true, array()), -			array('user_id', '', true, false, array(array('username_clean' => 'barfoo'), +			array('username_clean', '', false, false, array()), +			array('username_clean', '', false, true, array()), +			array('username_clean', '', true, false, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'),  				array('username_clean' => 'bertie'))), -			array('user_id', '', true, true, array(array('username_clean' => 'barfoo'), +			array('username_clean', '', true, true, array(array('username_clean' => 'barfoo'),  				array('username_clean' => 'foobar'),  				array('username_clean' => 'bertie'))),  			array('user_id', array(), false, true, array()), @@ -310,10 +302,11 @@ class phpbb_dbal_test extends phpbb_database_test_case  			$db->sql_return_on_error(true);  		} -		$result = $db->sql_query('SELECT username_clean +		$sql = 'SELECT username_clean  			FROM phpbb_users  			WHERE ' . $db->sql_build_array('SELECT', $assoc_ary) . ' -			ORDER BY user_id ASC'); +			ORDER BY user_id ASC'; +		$result = $db->sql_query($sql);  		if ($catch_error)  		{ @@ -324,5 +317,174 @@ class phpbb_dbal_test extends phpbb_database_test_case  		$db->sql_freeresult($result);  	} -} +	public static function build_array_insert_data() +	{ +		return array( +			array(array( +				'config_name'	=> 'test_version', +				'config_value'	=> '0.0.0', +				'is_dynamic'	=> 1, +			)), +			array(array( +				'config_name'	=> 'second config', +				'config_value'	=> '10', +				'is_dynamic'	=> 0, +			)), +		); +	} + +	/** +	* @dataProvider build_array_insert_data +	*/ +	public function test_build_array_insert($sql_ary) +	{ +		$db = $this->new_dbal(); + +		$sql = 'INSERT INTO phpbb_config ' . $db->sql_build_array('INSERT', $sql_ary); +		$result = $db->sql_query($sql); + +		$sql = "SELECT * +			FROM phpbb_config +			WHERE config_name = '" . $sql_ary['config_name'] . "'"; +		$result = $db->sql_query_limit($sql, 1); + +		$this->assertEquals($sql_ary, $db->sql_fetchrow($result)); + +		$db->sql_freeresult($result); +	} + +	public static function delete_data() +	{ +		return array( +			array( +				"WHERE config_name = 'test_version'", +				array( +					array( +						'config_name'	=> 'second config', +						'config_value'	=> '10', +						'is_dynamic'	=> 0, +					), +				), +			), +			array( +				'', +				array(), +			), +		); +	} + +	/** +	* @dataProvider delete_data +	*/ +	public function test_delete($where, $expected) +	{ +		$db = $this->new_dbal(); + +		$sql = 'DELETE FROM phpbb_config +			' . $where; +		$result = $db->sql_query($sql); + +		$sql = 'SELECT * +			FROM phpbb_config'; +		$result = $db->sql_query($sql); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); + +		$db->sql_freeresult($result); +	} + +	public function test_multiple_insert() +	{ +		$db = $this->new_dbal(); + +		$batch_ary = array( +			array( +				'config_name'	=> 'batch one', +				'config_value'	=> 'b1', +				'is_dynamic'	=> 0, +			), +			array( +				'config_name'	=> 'batch two', +				'config_value'	=> 'b2', +				'is_dynamic'	=> 1, +			), +		); + +		$result = $db->sql_multi_insert('phpbb_config', $batch_ary); + +		$sql = 'SELECT * +			FROM phpbb_config +			ORDER BY config_name ASC'; +		$result = $db->sql_query($sql); + +		$this->assertEquals($batch_ary, $db->sql_fetchrowset($result)); + +		$db->sql_freeresult($result); +	} + +	public static function update_data() +	{ +		return array( +			array( +				array( +					'config_value'	=> '20', +					'is_dynamic'	=> 0, +				), +				" WHERE config_name = 'batch one'", +				array( +					array( +						'config_name'	=> 'batch one', +						'config_value'	=> '20', +						'is_dynamic'	=> 0, +					), +					array( +						'config_name'	=> 'batch two', +						'config_value'	=> 'b2', +						'is_dynamic'	=> 1, +					), +				), +			), +			array( +				array( +					'config_value'	=> '0', +					'is_dynamic'	=> 1, +				), +				'', +				array( +					array( +						'config_name'	=> 'batch one', +						'config_value'	=> '0', +						'is_dynamic'	=> 1, +					), +					array( +						'config_name'	=> 'batch two', +						'config_value'	=> '0', +						'is_dynamic'	=> 1, +					), +				), +			), +		); +	} + +	/** +	* @dataProvider update_data +	*/ +	public function test_update($sql_ary, $where, $expected) +	{ +		$db = $this->new_dbal(); + +		$sql = 'UPDATE phpbb_config +			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . $where; +		$result = $db->sql_query($sql); + +		$sql = 'SELECT * +			FROM phpbb_config +			ORDER BY config_name ASC'; +		$result = $db->sql_query($sql); + +		$this->assertEquals($expected, $db->sql_fetchrowset($result)); + +		$db->sql_freeresult($result); +	} +} diff --git a/tests/regex/all_tests.php b/tests/regex/all_tests.php new file mode 100644 index 0000000000..316a9d4a58 --- /dev/null +++ b/tests/regex/all_tests.php @@ -0,0 +1,46 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +if (!defined('PHPUnit_MAIN_METHOD')) +{ +	define('PHPUnit_MAIN_METHOD', 'phpbb_regex_all_tests::main'); +} + +require_once 'test_framework/framework.php'; +require_once 'PHPUnit/TextUI/TestRunner.php'; + +require_once 'regex/email.php'; +require_once 'regex/ipv4.php'; +require_once 'regex/ipv6.php'; +require_once 'regex/url.php'; + +class phpbb_regex_all_tests +{ +	public static function main() +	{ +		PHPUnit_TextUI_TestRunner::run(self::suite()); +	} + +	public static function suite() +	{ +		$suite = new PHPUnit_Framework_TestSuite('phpBB Regular Expressions'); + +		$suite->addTestSuite('phpbb_regex_email_test'); +		$suite->addTestSuite('phpbb_regex_ipv4_test'); +		$suite->addTestSuite('phpbb_regex_ipv6_test'); +		$suite->addTestSuite('phpbb_regex_url_test'); + +		return $suite; +	} +} + +if (PHPUnit_MAIN_METHOD == 'phpbb_regex_all_tests::main') +{ +	phpbb_regex_all_tests::main(); +} diff --git a/tests/regex/email.php b/tests/regex/email.php new file mode 100644 index 0000000000..b1519dfa5f --- /dev/null +++ b/tests/regex/email.php @@ -0,0 +1,78 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once '../phpBB/includes/functions.php'; + +class phpbb_regex_email_test extends phpbb_test_case +{ +	protected $regex; + +	public function setUp() +	{ +		$this->regex = '#^' . get_preg_expression('email') . '$#i'; +	} + +	public function positive_match_data() +	{ +		return array( +			array('nobody@phpbb.com'), +			array('Nobody@sub.phpbb.com'), +			array('alice.bob@foo.phpbb.com'), +			array('alice-foo@bar.phpbb.com'), +			array('alice_foo@bar.phpbb.com'), +			array('alice+tag@foo.phpbb.com'), +			array('alice&tag@foo.phpbb.com'), + +			//array('"John Doe"@example.com'), +			//array('Alice@[192.168.2.1]'),		// IPv4 +			//array('Bob@[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]'), // IPv6 +		); +	} + +	public function negative_match_data() +	{ +		return array( +			array('foo.example.com'),			// @ is missing +			array('.foo.example.com'),			// . as first character +			array('Foo.@example.com'),			// . is last in local part +			array('foo..123@example.com'),		// . doubled +			array('a@b@c@example.com'),			// @ doubled + +			array('()[]\;:,<>@example.com'),	// invalid characters +			array('abc(def@example.com'),		// invalid character ( +			array('abc)def@example.com'),		// invalid character ) +			array('abc[def@example.com'),		// invalid character [ +			array('abc]def@example.com'),		// invalid character ] +			array('abc\def@example.com'),		// invalid character \ +			array('abc;def@example.com'),		// invalid character ; +			array('abc:def@example.com'),		// invalid character : +			array('abc,def@example.com'),		// invalid character , +			array('abc<def@example.com'),		// invalid character < +			array('abc>def@example.com'),		// invalid character > +		); +	} + +	/** +	* @dataProvider positive_match_data +	*/ +	public function test_positive_match($email) +	{ +		$this->assertEquals(1, preg_match($this->regex, $email)); +	} + +	/** +	* @dataProvider negative_match_data +	*/ +	public function test_negative_match($address) +	{ +		$this->assertEquals(0, preg_match($this->regex, $email)); +	} +} + diff --git a/tests/regex/ipv4.php b/tests/regex/ipv4.php new file mode 100644 index 0000000000..9d131ad0ca --- /dev/null +++ b/tests/regex/ipv4.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once '../phpBB/includes/functions.php'; + +class phpbb_regex_ipv4_test extends phpbb_test_case +{ +	protected $regex; + +	public function setUp() +	{ +		$this->regex = get_preg_expression('ipv4'); +	} + +	public function positive_match_data() +	{ +		return array( +			array('0.0.0.0'), +			array('127.0.0.1'), +			array('192.168.0.1'), +			array('255.255.255.255'), +		); +	} + +	public function negative_match_data() +	{ +		return array( +			// IPv6 addresses +			array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'), +			array('2001:db8:85a3:c:d:8a2e:370:1337'), +			array('2001:db8:85a3::8a2e:370:1337'), +			array('2001:db8:0:1::192.168.0.2'), +			array('0:0:0:0:0:0:0:1'), +			array('0:0::0:0:1'), +			array('::1'), + +			// Out of scope +			array('255.255.255.256'), + +			// Other tests +			array('a.b.c.d'), +			array('11.22.33.'), +			array('11.22.33'), +			array('11.22'), +			array('11'), +		); +	} + +	/** +	* @dataProvider positive_match_data +	*/ +	public function test_positive_match($address) +	{ +		$this->assertEquals(1, preg_match($this->regex, $address)); +	} + +	/** +	* @dataProvider negative_match_data +	*/ +	public function test_negative_match($address) +	{ +		$this->assertEquals(0, preg_match($this->regex, $address)); +	} +} + diff --git a/tests/regex/ipv6.php b/tests/regex/ipv6.php new file mode 100644 index 0000000000..3d7a72e492 --- /dev/null +++ b/tests/regex/ipv6.php @@ -0,0 +1,143 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once '../phpBB/includes/functions.php'; + +class phpbb_regex_ipv6_test extends phpbb_test_case +{ +	protected $regex; + +	public function setUp() +	{ +		$this->regex = get_preg_expression('ipv6'); +	} + +	public function positive_match_data() +	{ +		return array( +			// Full length IPv6 address +			array('2001:0db8:85a3:0000:0000:8a2e:0370:1337'), +			array('0000:0000:0000:0000:0000:0000:0000:0001'), +			array('3FFE:0b00:0000:0000:0001:0000:0000:000a'), +			array('3ffe:0b00:0000:0000:0001:0000:0000:000a'), +			array('2002:0db8:0000:0000:0000:dead:1337:d00d'), + +			// No leading zeroes in the group +			array('2001:db8:85a3:0:0:8a2e:370:1337'), +			array('2001:db8:85a3:c:d:8a2e:370:1337'), + +			// Consecutive all-zero groups +			array('2001:db8:85a3::8a2e:370:1337'), +			array('1::2:3:4:5:6:7'), +			array('1::2:3:4:5:6'), +			array('1::2:3:4:5'), +			array('1::2:3:4'), +			array('1::2:3'), +			array('1::2'), + +			// Last 32bit in dotted quad notation +			array('2001:db8:0:1::192.168.0.2'), + +			// IPv4-compatible IPv6 address +			array('::13.1.68.3'), +			array('0:0:0:0:0:0:13.1.68.3'), + +			// IPv4-mapped IPv6 address +			array('::ffff:c000:280'), +			array('::ffff:c000:0280'), +			array('::ffff:192.0.2.128'), +			array('0:0:0:0:0:ffff:c000:280'), +			array('0:0:0:0:0:ffff:c000:0280'), +			array('0:0:0:0:0:ffff:192.0.2.128'), +			array('0000:0000:0000:0000:0000:ffff:c000:280'), +			array('0000:0000:0000:0000:0000:ffff:c000:0280'), +			array('0000:0000:0000:0000:0000:ffff:192.0.2.128'), + +			// No trailing zeroes +			array('fe80::'), +			array('2002::'), +			array('2001:db8::'), +			array('2001:0db8:1234::'), +			array('1:2:3:4:5:6::'), +			array('1:2:3:4:5::'), +			array('1:2:3:4::'), +			array('1:2:3::'), +			array('1:2::'), + +			// No leading zeroes +			array('::2:3:4:5:6:7:8'), +			array('::2:3:4:5:6:7'), +			array('::2:3:4:5:6'), +			array('::2:3:4:5'), +			array('::2:3:4'), +			array('::2:3'), +			array('::1'), +			array('::8'), +			array('::c'), +			array('::abcd'), + +			// All zeroes +			array('::'), +			array('0:0:0:0:0:0:0:0'), +			array('0000:0000:0000:0000:0000:0000:0000:0000'), + +			// More tests +			array('2::10'), +			array('0:0::0:0:1'), +			array('0:0:0:0:0:0:0:1'), +			array('::ffff:0:0'), +		); +	} + +	public function negative_match_data() +	{ +		return array( +			// Empty address +			array(''), + +			// IPv4 address +			array('192.168.0.2'), + +			// Out of scope +			array('abcd:efgh:0000::0'), +			array('::ffff:192.168.255.256'), + +			// Double :: +			array('2001::23de::2002'), +			array('3ffe:b00::1::b'), +			array('::1111:2222:3333:4444:5555:6666::'), + +			// Too many blocks +			array('2001:0db8:85a3:08d3:1319:8a2e:0370:1337:4430'), + +			// More tests +			array('02001:0000:1234:0000:0000:C1C0:ABCD:9876'), +			array('2001:0000:1234: 0000:0000:C1C0:ABCD:9876'), +			array('::ffff:192x168.255.255'), +		); +	} + +	/** +	* @dataProvider positive_match_data +	*/ +	public function test_positive_match($address) +	{ +		$this->assertEquals(1, preg_match($this->regex, $address)); +	} + +	/** +	* @dataProvider negative_match_data +	*/ +	public function test_negative_match($address) +	{ +		$this->assertEquals(0, preg_match($this->regex, $address)); +	} +} + diff --git a/tests/regex/url.php b/tests/regex/url.php new file mode 100644 index 0000000000..678b7d108f --- /dev/null +++ b/tests/regex/url.php @@ -0,0 +1,34 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2010 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once 'test_framework/framework.php'; +require_once '../phpBB/includes/functions.php'; + +class phpbb_regex_url_test extends phpbb_test_case +{ +	public function url_test_data() +	{ +		return array( +			array('http://www.phpbb.com/community/', 1), +			array('http://www.phpbb.com/path/file.ext#section', 1), +			array('ftp://ftp.phpbb.com/', 1), +			array('sip://bantu@phpbb.com', 1), + +			array('www.phpbb.com/community/', 0), +		); +	} + +	/** +	* @dataProvider url_test_data +	*/ +	public function test_url($url, $expected) +	{ +		$this->assertEquals($expected, preg_match('#^' . get_preg_expression('url') . '$#i', $url)); +	} +}  | 
