diff options
Diffstat (limited to 'phpBB/develop')
| -rw-r--r-- | phpBB/develop/benchmark.php | 12 | ||||
| -rw-r--r-- | phpBB/develop/create_schema_files.php | 547 | ||||
| -rw-r--r-- | phpBB/develop/export_events_for_wiki.php | 315 | 
3 files changed, 93 insertions, 781 deletions
| diff --git a/phpBB/develop/benchmark.php b/phpBB/develop/benchmark.php index c653fdaa24..27176c97d3 100644 --- a/phpBB/develop/benchmark.php +++ b/phpBB/develop/benchmark.php @@ -366,18 +366,10 @@ function make_user($username)  	$password = md5("benchpass");  	$email = "nobody@localhost"; -	$icq = "12345678"; -	$website = "http://www.phpbb.com"; -	$occupation = "phpBB tester"; -	$location = "phpBB world hq"; -	$interests = "Eating, sleeping, living, and breathing phpBB";  	$signature = "$username: phpBB tester.";  	$signature_bbcode_uid = "";  	$avatar_filename = "";  	$viewemail = 0; -	$aim = 0; -	$yim = 0; -	$msn = 0;  	$attachsig = 1;  	$allowsmilies = 1;  	$allowhtml = 1; @@ -422,8 +414,8 @@ function make_user($username)  	} -	$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmilies, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey) -		VALUES ($new_user_id, '$username', " . time() . ", '$password', '$email', '$icq', '$website', '$occupation', '$location', '$interests', '$signature', '$signature_bbcode_uid', '$avatar_filename', $viewemail, '$aim', '$yim', '$msn', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $user_timezone, '$user_dateformat', '$user_lang', $user_style, 0, 1, "; +	$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_sig, user_sig_bbcode_uid, user_avatar, user_viewemail, user_attachsig, user_allowsmilies, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey) +		VALUES ($new_user_id, '$username', " . time() . ", '$password', '$email', '$signature', '$signature_bbcode_uid', '$avatar_filename', $viewemail, $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $user_timezone, '$user_dateformat', '$user_lang', $user_style, 0, 1, ";  	$sql .= "1, '')"; diff --git a/phpBB/develop/create_schema_files.php b/phpBB/develop/create_schema_files.php index 5ef278d493..9ab8bd193f 100644 --- a/phpBB/develop/create_schema_files.php +++ b/phpBB/develop/create_schema_files.php @@ -12,6 +12,16 @@  */  $schema_path = dirname(__FILE__) . '/../install/schemas/'; +$supported_dbms = array( +	'firebird', +	'mssql', +	'mysql_40', +	'mysql_41', +	'oracle', +	'postgres', +	'sqlite', +); +$table_prefix = 'phpbb_';  if (!is_writable($schema_path))  { @@ -19,22 +29,40 @@ if (!is_writable($schema_path))  }  define('IN_PHPBB', true); +$phpbb_root_path = dirname(__FILE__) . '/../'; +$phpEx = substr(strrchr(__FILE__, '.'), 1); -require(dirname(__FILE__) . '/../includes/db/schema_data.php'); -require(dirname(__FILE__) . '/../phpbb/db/tools.php'); +include($phpbb_root_path . 'includes/constants.' . $phpEx); +require($phpbb_root_path . 'phpbb/class_loader.' . $phpEx); +$phpbb_class_loader = new \phpbb\class_loader('phpbb\\', "{$phpbb_root_path}phpbb/", $phpEx); +$phpbb_class_loader->register(); +class phpbb_extension_empty_manager extends \phpbb\extension\manager +{ +	public function __construct() +	{ +		$this->extensions = array(); +	} +} + +$finder = new \phpbb\extension\finder(new \phpbb_extension_empty_manager(), new \phpbb\filesystem(), $phpbb_root_path); +$classes = $finder->core_path('phpbb/') +	->directory('db/migration/data') +	->get_classes(); + +$db = new \phpbb\db\driver\sqlite(); +$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix); +$schema_data = $schema_generator->get_schema();  $dbms_type_map = phpbb\db\tools::get_dbms_type_map(); -// A list of types being unsigned for better reference in some db's -$unsigned_types = array('UINT', 'UINT:', 'USINT', 'BOOL', 'TIMESTAMP'); -$supported_dbms = array('firebird', 'mssql', 'mysql_40', 'mysql_41', 'oracle', 'postgres', 'sqlite'); +$fp = fopen($schema_path . 'schema.json', 'wb'); +fwrite($fp, json_encode($schema_data, JSON_PRETTY_PRINT)); +fclose($fp);  foreach ($supported_dbms as $dbms)  {  	$fp = fopen($schema_path . $dbms . '_schema.sql', 'wb'); -	$line = ''; -  	// Write Header  	switch ($dbms)  	{ @@ -62,16 +90,9 @@ foreach ($supported_dbms as $dbms)  		break;  	} +	$line = '';  	switch ($dbms)  	{ -		case 'firebird': -			$line .= custom_data('firebird') . "\n"; -		break; - -		case 'sqlite': -			$line .= "BEGIN TRANSACTION;\n\n"; -		break; -  		case 'oracle':  			$line .= custom_data('oracle') . "\n";  		break; @@ -79,501 +100,7 @@ foreach ($supported_dbms as $dbms)  		case 'postgres':  			$line .= "BEGIN;\n\n";  			$line .= custom_data('postgres') . "\n"; -		break; -	} - -	fwrite($fp, $line); - -	foreach ($schema_data as $table_name => $table_data) -	{ -		// Write comment about table -		switch ($dbms) -		{ -			case 'mysql_40': -			case 'mysql_41': -			case 'firebird': -			case 'sqlite': -				fwrite($fp, "# Table: '{$table_name}'\n"); -			break; - -			case 'mssql': -			case 'oracle': -			case 'postgres': -				fwrite($fp, "/*\n\tTable: '{$table_name}'\n*/\n"); -			break; -		} - -		// Create Table statement -		$generator = $textimage = false; -		$line = ''; - -		switch ($dbms) -		{ -			case 'mysql_40': -			case 'mysql_41': -			case 'firebird': -			case 'oracle': -			case 'sqlite': -			case 'postgres': -				$line = "CREATE TABLE {$table_name} (\n"; -			break; - -			case 'mssql': -				$line = "CREATE TABLE [{$table_name}] (\n"; -			break; -		} - -		// Table specific so we don't get overlap -		$modded_array = array(); - -		// Write columns one by one... -		foreach ($table_data['COLUMNS'] as $column_name => $column_data) -		{ -			if (strlen($column_name) > 30) -			{ -				trigger_error("Column name '$column_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); -			} -			if (isset($column_data[2]) && $column_data[2] == 'auto_increment' && strlen($column_name) > 26) // "${column_name}_gen" -			{ -				trigger_error("Index name '${column_name}_gen' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); -			} - -			// Get type -			if (strpos($column_data[0], ':') !== false) -			{ -				list($orig_column_type, $column_length) = explode(':', $column_data[0]); -				if (!is_array($dbms_type_map[$dbms][$orig_column_type . ':'])) -				{ -					$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'], $column_length); -				} -				else -				{ -					if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['rule'])) -					{ -						switch ($dbms_type_map[$dbms][$orig_column_type . ':']['rule'][0]) -						{ -							case 'div': -								$column_length /= $dbms_type_map[$dbms][$orig_column_type . ':']['rule'][1]; -								$column_length = ceil($column_length); -								$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); -							break; -						} -					} - -					if (isset($dbms_type_map[$dbms][$orig_column_type . ':']['limit'])) -					{ -						switch ($dbms_type_map[$dbms][$orig_column_type . ':']['limit'][0]) -						{ -							case 'mult': -								$column_length *= $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][1]; -								if ($column_length > $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][2]) -								{ -									$column_type = $dbms_type_map[$dbms][$orig_column_type . ':']['limit'][3]; -									$modded_array[$column_name] = $column_type; -								} -								else -								{ -									$column_type = sprintf($dbms_type_map[$dbms][$orig_column_type . ':'][0], $column_length); -								} -							break; -						} -					} -				} -				$orig_column_type .= ':'; -			} -			else -			{ -				$orig_column_type = $column_data[0]; -				$column_type = $dbms_type_map[$dbms][$column_data[0]]; -				if ($column_type == 'text' || $column_type == 'blob') -				{ -					$modded_array[$column_name] = $column_type; -				} -			} - -			// Adjust default value if db-dependent specified -			if (is_array($column_data[1])) -			{ -				$column_data[1] = (isset($column_data[1][$dbms])) ? $column_data[1][$dbms] : $column_data[1]['default']; -			} - -			switch ($dbms) -			{ -				case 'mysql_40': -				case 'mysql_41': -					$line .= "\t{$column_name} {$column_type} "; - -					// For hexadecimal values do not use single quotes -					if (!is_null($column_data[1]) && substr($column_type, -4) !== 'text' && substr($column_type, -4) !== 'blob') -					{ -						$line .= (strpos($column_data[1], '0x') === 0) ? "DEFAULT {$column_data[1]} " : "DEFAULT '{$column_data[1]}' "; -					} -					$line .= 'NOT NULL'; - -					if (isset($column_data[2])) -					{ -						if ($column_data[2] == 'auto_increment') -						{ -							$line .= ' auto_increment'; -						} -						else if ($dbms === 'mysql_41' && $column_data[2] == 'true_sort') -						{ -							$line .= ' COLLATE utf8_unicode_ci'; -						} -					} - -					$line .= ",\n"; -				break; - -				case 'sqlite': -					if (isset($column_data[2]) && $column_data[2] == 'auto_increment') -					{ -						$line .= "\t{$column_name} INTEGER PRIMARY KEY "; -						$generator = $column_name; -					} -					else -					{ -						$line .= "\t{$column_name} {$column_type} "; -					} - -					$line .= 'NOT NULL '; -					$line .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}'" : ''; -					$line .= ",\n"; -				break; - -				case 'firebird': -					$line .= "\t{$column_name} {$column_type} "; - -					if (!is_null($column_data[1])) -					{ -						$line .= 'DEFAULT ' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ' '; -					} - -					$line .= 'NOT NULL'; - -					// This is a UNICODE column and thus should be given it's fair share -					if (preg_match('/^X?STEXT_UNI|VCHAR_(CI|UNI:?)/', $column_data[0])) -					{ -						$line .= ' COLLATE UNICODE'; -					} - -					$line .= ",\n"; - -					if (isset($column_data[2]) && $column_data[2] == 'auto_increment') -					{ -						$generator = $column_name; -					} -				break; - -				case 'mssql': -					if ($column_type == '[text]') -					{ -						$textimage = true; -					} - -					$line .= "\t[{$column_name}] {$column_type} "; - -					if (!is_null($column_data[1])) -					{ -						// For hexadecimal values do not use single quotes -						if (strpos($column_data[1], '0x') === 0) -						{ -							$line .= 'DEFAULT (' . $column_data[1] . ') '; -						} -						else -						{ -							$line .= 'DEFAULT (' . ((is_numeric($column_data[1])) ? $column_data[1] : "'{$column_data[1]}'") . ') '; -						} -					} - -					if (isset($column_data[2]) && $column_data[2] == 'auto_increment') -					{ -						$line .= 'IDENTITY (1, 1) '; -					} - -					$line .= 'NOT NULL'; -					$line .= " ,\n"; -				break; - -				case 'oracle': -					$line .= "\t{$column_name} {$column_type} "; -					$line .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; - -					// In Oracle empty strings ('') are treated as NULL. -					// Therefore in oracle we allow NULL's for all DEFAULT '' entries -					$line .= ($column_data[1] === '') ? ",\n" : "NOT NULL,\n"; - -					if (isset($column_data[2]) && $column_data[2] == 'auto_increment') -					{ -						$generator = $column_name; -					} -				break; - -				case 'postgres': -					$line .= "\t{$column_name} {$column_type} "; - -					if (isset($column_data[2]) && $column_data[2] == 'auto_increment') -					{ -						$line .= "DEFAULT nextval('{$table_name}_seq'),\n"; - -						// Make sure the sequence will be created before creating the table -						$line = "CREATE SEQUENCE {$table_name}_seq;\n\n" . $line; -					} -					else -					{ -						$line .= (!is_null($column_data[1])) ? "DEFAULT '{$column_data[1]}' " : ''; -						$line .= "NOT NULL"; - -						// Unsigned? Then add a CHECK contraint -						if (in_array($orig_column_type, $unsigned_types)) -						{ -							$line .= " CHECK ({$column_name} >= 0)"; -						} - -						$line .= ",\n"; -					} -				break; -			} -		} - -		switch ($dbms) -		{ -			case 'firebird': -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n);;\n\n"; -			break; - -			case 'mssql': -				$line = substr($line, 0, -2); -				$line .= "\n) ON [PRIMARY]" . (($textimage) ? ' TEXTIMAGE_ON [PRIMARY]' : '') . "\n"; -				$line .= "GO\n\n"; -			break; -		} - -		// Write primary key -		if (isset($table_data['PRIMARY_KEY'])) -		{ -			if (!is_array($table_data['PRIMARY_KEY'])) -			{ -				$table_data['PRIMARY_KEY'] = array($table_data['PRIMARY_KEY']); -			} - -			switch ($dbms) -			{ -				case 'mysql_40': -				case 'mysql_41': -				case 'postgres': -					$line .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; -				break; - -				case 'firebird': -					$line .= "ALTER TABLE {$table_name} ADD PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . ");;\n\n"; -				break; - -				case 'sqlite': -					if ($generator === false || !in_array($generator, $table_data['PRIMARY_KEY'])) -					{ -						$line .= "\tPRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; -					} -				break; - -				case 'mssql': -					$line .= "ALTER TABLE [{$table_name}] WITH NOCHECK ADD \n"; -					$line .= "\tCONSTRAINT [PK_{$table_name}] PRIMARY KEY  CLUSTERED \n"; -					$line .= "\t(\n"; -					$line .= "\t\t[" . implode("],\n\t\t[", $table_data['PRIMARY_KEY']) . "]\n"; -					$line .= "\t)  ON [PRIMARY] \n"; -					$line .= "GO\n\n"; -				break; - -				case 'oracle': -					$line .= "\tCONSTRAINT pk_{$table_name} PRIMARY KEY (" . implode(', ', $table_data['PRIMARY_KEY']) . "),\n"; -				break; -			} -		} - -		switch ($dbms) -		{ -			case 'oracle': -				// UNIQUE contrains to be added? -				if (isset($table_data['KEYS'])) -				{ -					foreach ($table_data['KEYS'] as $key_name => $key_data) -					{ -						if (!is_array($key_data[1])) -						{ -							$key_data[1] = array($key_data[1]); -						} - -						if ($key_data[0] == 'UNIQUE') -						{ -							$line .= "\tCONSTRAINT u_phpbb_{$key_name} UNIQUE (" . implode(', ', $key_data[1]) . "),\n"; -						} -					} -				} - -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n)\n/\n\n"; -			break; - -			case 'postgres': -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n);\n\n"; -			break; - -			case 'sqlite': -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n);\n\n"; -			break; -		} - -		// Write Keys -		if (isset($table_data['KEYS'])) -		{ -			foreach ($table_data['KEYS'] as $key_name => $key_data) -			{ -				if (!is_array($key_data[1])) -				{ -					$key_data[1] = array($key_data[1]); -				} - -				if (strlen($table_name . $key_name) > 30) -				{ -					trigger_error("Index name '${table_name}_$key_name' on table '$table_name' is too long. The maximum is 30 characters.", E_USER_ERROR); -				} - -				switch ($dbms) -				{ -					case 'mysql_40': -					case 'mysql_41': -						$line .= ($key_data[0] == 'INDEX') ? "\tKEY" : ''; -						$line .= ($key_data[0] == 'UNIQUE') ? "\tUNIQUE" : ''; -						foreach ($key_data[1] as $key => $col_name) -						{ -							if (isset($modded_array[$col_name])) -							{ -								switch ($modded_array[$col_name]) -								{ -									case 'text': -									case 'blob': -										$key_data[1][$key] = $col_name . '(255)'; -									break; -								} -							} -						} -						$line .= ' ' . $key_name . ' (' . implode(', ', $key_data[1]) . "),\n"; -					break; - -					case 'firebird': -						$line .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; -						$line .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - -						$line .= ' ' . $table_name . '_' . $key_name . ' ON ' . $table_name . '(' . implode(', ', $key_data[1]) . ");;\n"; -					break; - -					case 'mssql': -						$line .= ($key_data[0] == 'INDEX') ? 'CREATE  INDEX' : ''; -						$line .= ($key_data[0] == 'UNIQUE') ? 'CREATE  UNIQUE  INDEX' : ''; -						$line .= " [{$key_name}] ON [{$table_name}]([" . implode('], [', $key_data[1]) . "]) ON [PRIMARY]\n"; -						$line .= "GO\n\n"; -					break; - -					case 'oracle': -						if ($key_data[0] == 'UNIQUE') -						{ -							continue; -						} - -						$line .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; - -						$line .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ")\n"; -						$line .= "/\n"; -					break; - -					case 'sqlite': -						$line .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; -						$line .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - -						$line .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; -					break; - -					case 'postgres': -						$line .= ($key_data[0] == 'INDEX') ? 'CREATE INDEX' : ''; -						$line .= ($key_data[0] == 'UNIQUE') ? 'CREATE UNIQUE INDEX' : ''; - -						$line .= " {$table_name}_{$key_name} ON {$table_name} (" . implode(', ', $key_data[1]) . ");\n"; -					break; -				} -			} -		} - -		switch ($dbms) -		{ -			case 'mysql_40': -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n);\n\n"; -			break; - -			case 'mysql_41': -				// Remove last line delimiter... -				$line = substr($line, 0, -2); -				$line .= "\n) CHARACTER SET `utf8` COLLATE `utf8_bin`;\n\n"; -			break; - -			// Create Generator -			case 'firebird': -				if ($generator !== false) -				{ -					$line .= "\nCREATE GENERATOR {$table_name}_gen;;\n"; -					$line .= 'SET GENERATOR ' . $table_name . "_gen TO 0;;\n\n"; - -					$line .= 'CREATE TRIGGER t_' . $table_name . ' FOR ' . $table_name . "\n"; -					$line .= "BEFORE INSERT\nAS\nBEGIN\n"; -					$line .= "\tNEW.{$generator} = GEN_ID({$table_name}_gen, 1);\nEND;;\n\n"; -				} -			break; - -			case 'oracle': -				if ($generator !== false) -				{ -					$line .= "\nCREATE SEQUENCE {$table_name}_seq\n/\n\n"; - -					$line .= "CREATE OR REPLACE TRIGGER t_{$table_name}\n"; -					$line .= "BEFORE INSERT ON {$table_name}\n"; -					$line .= "FOR EACH ROW WHEN (\n"; -					$line .= "\tnew.{$generator} IS NULL OR new.{$generator} = 0\n"; -					$line .= ")\nBEGIN\n"; -					$line .= "\tSELECT {$table_name}_seq.nextval\n"; -					$line .= "\tINTO :new.{$generator}\n"; -					$line .= "\tFROM dual;\nEND;\n/\n\n"; -				} -			break; -		} - -		fwrite($fp, $line . "\n"); -	} - -	$line = ''; - -	// Write custom function at the end for some db's -	switch ($dbms) -	{ -		case 'mssql': -			// No need to do this, no transaction support for schema changes -			//$line = "\nCOMMIT\nGO\n\n"; -		break; - -		case 'sqlite': -			$line = "\nCOMMIT;"; -		break; - -		case 'postgres': -			$line = "\nCOMMIT;"; +			$line .= "COMMIT;\n\n";  		break;  	} diff --git a/phpBB/develop/export_events_for_wiki.php b/phpBB/develop/export_events_for_wiki.php index b276b4c5fa..f4ebb42cf4 100644 --- a/phpBB/develop/export_events_for_wiki.php +++ b/phpBB/develop/export_events_for_wiki.php @@ -16,291 +16,84 @@ $phpbb_root_path = __DIR__ . '/../';  function usage()  { -	echo "Usage: export_events_for_wiki.php COMMAND\n"; +	echo "Usage: export_events_for_wiki.php COMMAND [EXTENSION]\n";  	echo "\n"; -	echo "acp:\n"; -	echo "    Export all events for files in the acp style.\n"; +	echo "COMMAND:\n"; +	echo "    all:\n"; +	echo "        Generate the complete wikipage for https://wiki.phpbb.com/Event_List\n";  	echo "\n"; -	echo "styles:\n"; -	echo "    Export all events for files in the prosilver and subsilver2 styles.\n"; +	echo "    php:\n"; +	echo "        Generate the PHP event section of Event_List\n"; +	echo "\n"; +	echo "    adm:\n"; +	echo "        Generate the ACP Template event section of Event_List\n"; +	echo "\n"; +	echo "    styles:\n"; +	echo "        Generate the Styles Template event section of Event_List\n"; +	echo "\n"; +	echo "EXTENSION (Optional):\n"; +	echo "    If not given, only core events will be exported.\n"; +	echo "    Otherwise only events from the extension will be exported.\n";  	echo "\n"; -	echo "php:\n"; -	echo "    Export all events for php-files.\n";  	exit(2);  } -function export_from_eventsmd($phpbb_root_path, $filter) +function validate_argument_count($arguments, $count)  { -	$file_content = file_get_contents($phpbb_root_path . 'docs/events.md'); - -	$events = explode("\n\n", $file_content); -	foreach ($events as $event) +	if ($arguments <= $count)  	{ -		// Last row of the file -		if (strpos($event, "\n===\n") === false) continue; - -		list($event_name, $details) = explode("\n===\n", $event); - -		if ($filter == 'acp' && strpos($event_name, 'acp_') !== 0) continue; -		if ($filter == 'styles' && strpos($event_name, 'acp_') === 0) continue; - -		list($file_details, $details) = explode("\n* Since: ", $details); -		list($version, $explanition) = explode("\n* Purpose: ", $details); - -		echo "|- id=\"{$event_name}\"\n"; -		echo "| [[#{$event_name}|{$event_name}]] || "; - -		if (strpos($file_details, "* Locations:\n    + ") === 0) -		{ -			$file_details = substr($file_details, strlen("* Locations:\n    + ")); -			$files = explode("\n    + ", $file_details); -			$prosilver = $subsilver2 = array(); -			foreach ($files as $file) -			{ -				if (strpos($file, 'styles/prosilver/template/') === 0) -				{ -					$prosilver[] = substr($file, strlen('styles/prosilver/template/')); -				} -				if (strpos($file, 'styles/subsilver2/template/') === 0) -				{ -					$subsilver2[] = substr($file, strlen('styles/subsilver2/template/')); -				} -			} -			echo implode(', ', $prosilver) . ' || ' . implode(', ', $subsilver2); -		} -		else if ($filter == 'acp') -		{ -			echo substr($file_details, strlen("* Location: adm/style/")); -		} -		echo " || {$version} || " . str_replace("\n", ' ', $explanition) . "\n"; - +		usage();  	}  } -function export_from_php($phpbb_root_path) -{ -	$files = get_file_list($phpbb_root_path); -	$events = array(); -	foreach ($files as $file) -	{ -		$file_events = check_for_events($phpbb_root_path, $file); -		if (!empty($file_events)) -		{ -			$events = array_merge($events, $file_events); -		} -	} - -	ksort($events); +validate_argument_count($argc, 1); -	foreach ($events as $event) -	{ -		echo '|- id="' . $event['event'] . '"' . "\n"; -		echo '| [[#' . $event['event'] . '|' . $event['event'] . ']] || ' . $event['file'] . ' || ' . implode(', ', $event['arguments']) . ' || ' . $event['since'] . ' || ' . $event['description'] . "\n"; -	} -} +$action = $argv[1]; +$extension = isset($argv[2]) ? $argv[2] : null; +require __DIR__ . '/../phpbb/event/php_exporter.' . $phpEx; +require __DIR__ . '/../phpbb/event/md_exporter.' . $phpEx; +require __DIR__ . '/../phpbb/event/recursive_event_filter_iterator.' . $phpEx; +require __DIR__ . '/../phpbb/recursive_dot_prefix_filter_iterator.' . $phpEx; -function check_for_events($phpbb_root_path, $file) +switch ($action)  { -	$events = array(); -	$content = file_get_contents($phpbb_root_path . $file); - -	if (strpos($content, "phpbb_dispatcher->trigger_event('") || strpos($content, "phpbb_dispatcher->dispatch('")) -	{ -		$lines = explode("\n", $content); -		for ($i = 0, $num_lines = sizeof($lines); $i < $num_lines; $i++) -		{ -			$event_line = 0; -			if ($found_trigger_event = strpos($lines[$i], "phpbb_dispatcher->trigger_event('")) -			{ -				$event_line = $i; -				$event_name = $lines[$event_line]; -				$event_name = substr($event_name, $found_trigger_event + strlen("phpbb_dispatcher->trigger_event('")); -				$event_name = substr($event_name, 0, strpos($event_name, "'")); +	case 'all': +		echo '__FORCETOC__' . "\n"; -				// Find $vars array lines -				$find_varsarray_line = 1; -				while (strpos($lines[$event_line - $find_varsarray_line], "vars = array('") === false) -				{ -					$find_varsarray_line++; - -					if ($find_varsarray_line > min(50, $event_line)) -					{ -						throw new LogicException('Can not find "$vars = array()"-line for event "' . $event_name . '" in file "' . $file . '"'); -					} -				} -				$varsarray = substr(trim($lines[$event_line - $find_varsarray_line]), strlen("\$vars = array('"), -3); -				$arguments = explode("', '", $varsarray); - -				// Validate $vars array with @var -				$find_vars_line = 3; -				$doc_vars = array(); -				while (strpos(trim($lines[$event_line - $find_vars_line]), '*') === 0) -				{ -					$var_line = trim($lines[$event_line - $find_vars_line]); -					$var_line = preg_replace('!\s+!', ' ', $var_line); -					if (strpos($var_line, '* @var ') === 0) -					{ -						$doc_line = explode(' ', $var_line); -						if (isset($doc_line[3])) -						{ -							$doc_vars[] = $doc_line[3]; -						} -					} -					$find_vars_line++; -				} -				if (sizeof($arguments) !== sizeof($doc_vars) && array_intersect($arguments, $doc_vars)) -				{ -					throw new LogicException('$vars array does not match the list of @var tags for event "' . $event_name . '" in file "' . $file . '"'); -				} -			} -			else if ($found_trigger_event = strpos($lines[$i], "phpbb_dispatcher->dispatch('")) -			{ -				$event_line = $i; -				$event_name = $lines[$event_line]; -				$event_name = substr($event_name, $found_trigger_event + strlen("phpbb_dispatcher->dispatch('")); -				$event_name = substr($event_name, 0, strpos($event_name, "'")); -				$arguments = array(); -			} - -			if ($event_line) -			{ -				// Validate @event name -				$find_event_line = 1; -				while (strpos($lines[$event_line - $find_event_line], '* @event ') === false) -				{ -					$find_event_line++; - -					if ($find_event_line > min(50, $event_line)) -					{ -						throw new LogicException('Can not find @event tag for event "' . $event_name . '" in file "' . $file . '"'); -					} -				} -				$event_name_tag = substr(trim($lines[$event_line - $find_event_line]), strlen('* @event ')); -				if ($event_name_tag !== $event_name) -				{ -					throw new LogicException('Event name does not match @event tag for event "' . $event_name . '" in file "' . $file . '"'); -				} - -				// Find @since -				$find_since_line = 1; -				while (strpos($lines[$event_line - $find_since_line], '* @since ') === false) -				{ -					$find_since_line++; - -					if ($find_since_line > min(50, $event_line)) -					{ -						throw new LogicException('Can not find @since tag for event "' . $event_name . '" in file "' . $file . '"'); -					} -				} -				$since = substr(trim($lines[$event_line - $find_since_line]), strlen('* @since ')); -				$since = ($since == '3.1-A1') ? '3.1.0-a1' : $since; - -				// Find event description line -				$find_description_line = 3; -				while (strpos(trim($lines[$event_line - $find_description_line]), '*') === 0) -				{ -					$find_description_line++; - -					if ($find_description_line > min(50, $event_line)) -					{ -						throw new LogicException('Can not find description-line for event "' . $event_name . '" in file "' . $file . '"'); -					} -				} -				$description = substr(trim($lines[$event_line - $find_description_line + 1]), strlen('* ')); +	case 'php': +		$exporter = new \phpbb\event\php_exporter($phpbb_root_path, $extension); +		$exporter->crawl_phpbb_directory_php(); +		echo $exporter->export_events_for_wiki(); -				$events[$event_name] = array( -					'event'			=> $event_name, -					'file'			=> $file, -					'arguments'		=> $arguments, -					'since'			=> $since, -					'description'	=> $description, -				); -			} +		if ($action === 'php') +		{ +			break;  		} -	} - -	return $events; -} +		echo "\n"; +		// no break; -/** -* Returns a list of files in that directory -* -* Works recursive with any depth -* -* @param	string	$dir	Directory to go through -* @return	array	List of files (including directories from within $dir -*/ -function get_file_list($dir, $path = '') -{ -	try -	{ -		$iterator = new \DirectoryIterator($dir); -	} -	catch (Exception $e) -	{ -		return array(); -	} +	case 'styles': +		$exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension); +		$exporter->crawl_phpbb_directory_styles('docs/events.md'); +		echo $exporter->export_events_for_wiki(); -	$files = array(); -	foreach ($iterator as $file_info) -	{ -		if ($file_info->isDot()) +		if ($action === 'styles')  		{ -			continue; +			break;  		} +		echo "\n"; +		// no break; -		// Do not scan some directories -		if ($file_info->isDir() && ( -			($path == '' && in_array($file_info->getFilename(), array('cache', 'develop', 'ext', 'files', 'language', 'store', 'vendor'))) -			|| ($path == '/includes' && in_array($file_info->getFilename(), array('utf'))) -			|| ($path == '/phpbb/db/migration' && in_array($file_info->getFilename(), array('data'))) -			|| ($path == '/phpbb' && in_array($file_info->getFilename(), array('event'))) -		)) -		{ -			continue; -		} -		else if ($file_info->isDir()) -		{ -			$sub_dir = get_file_list($file_info->getPath() . '/' . $file_info->getFilename(), $path . '/' . $file_info->getFilename()); -			foreach ($sub_dir as $file) -			{ -				$files[] = $file_info->getFilename() . '/' . $file; -			} -		} -		else if ($file_info->getExtension() == 'php') +	case 'adm': +		$exporter = new \phpbb\event\md_exporter($phpbb_root_path, $extension); +		$exporter->crawl_phpbb_directory_adm('docs/events.md'); +		echo $exporter->export_events_for_wiki(); + +		if ($action === 'all')  		{ -			$files[] = $file_info->getFilename(); +			echo "\n" . '[[Category:Events and Listeners]]' . "\n";  		} -	} - -	return $files; -} - -function validate_argument_count($arguments, $count) -{ -	if ($arguments <= $count) -	{ -		usage(); -	} -} - -validate_argument_count($argc, 1); - -$action = $argv[1]; - -switch ($action) -{ -	case 'acp': -		export_from_eventsmd($phpbb_root_path, 'acp'); -		break; - -	case 'styles': -		export_from_eventsmd($phpbb_root_path, 'styles'); -		break; - -	case 'php': -		export_from_php($phpbb_root_path); -		break; +	break;  	default:  		usage(); | 
