aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/develop/export_events_for_wiki.php
blob: 72e5607e0009c1595ee85df5bfba10c66fe4941b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
/**
*
* @copyright (c) 2012 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/

define('IN_PHPBB', 1);
define('ANONYMOUS', 1);
$phpEx = substr(strrchr(__FILE__, '.'), 1);
$phpbb_root_path = __DIR__.'/../';

include($phpbb_root_path . 'common.'.$phpEx);

function usage()
{
	echo "Usage: export_events_for_wiki.php COMMAND\n";
	echo "\n";
	echo "acp:\n";
	echo "    Export all events for files in the acp style.\n";
	echo "\n";
	echo "styles:\n";
	echo "    Export all events for files in the prosilver and subsilver2 styles.\n";
	exit(2);
}

function export_from_eventsmd($filter)
{
	global $phpbb_root_path;
	$file_content = file_get_contents($phpbb_root_path . 'docs/events.md');

	$events = explode("\n\n", $file_content);
	foreach ($events as $event)
	{
		// 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, $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 " || 3.1.0-a1 || " . str_replace("\n", ' ', $explanition) . "\n";

	}
}

function validate_argument_count($count)
{
	global $argv;

	if (count($argv) <= $count)
	{
		usage();
	}
}

validate_argument_count(1);

$action = $argv[1];

switch ($action)
{
	case 'acp':
		export_from_eventsmd('acp');
		break;

	case 'styles':
		export_from_eventsmd('styles');
		break;

	default:
		usage();
}