Overview
Comment:Add filters to UserTemplates: 'delete_leading_number' and 'get_leading_number'
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA3-256: 4f0dbadebce637db6f35e5b9616f0d0307659d54309228284dc5454648e1f867
User & Date: bohwaz on 2021-11-29 15:10:04
Other Links: manifest | tags
Context
2021-11-29
15:24
Fix display bug on table of contents check-in: 7520ddffea user: bohwaz tags: trunk, stable
15:10
Add filters to UserTemplates: 'delete_leading_number' and 'get_leading_number' check-in: 4f0dbadebc user: bohwaz tags: trunk, stable
2021-11-27
15:44
Change to ADMIN_URL for absolute URIs to admin check-in: 33f97696be user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/UserTemplate/Modifiers.php from [98d18e40cb] to [e8643bac45].

35
36
37
38
39
40
41


42


43
44
45
46
47
48
49
		'truncate',
		'excerpt',
		'protect_contact',
		'atom_date',
		'xml_escape',
		'replace',
		'regexp_replace',


	];



	static public function replace($str, $find, $replace): string
	{
		return str_replace($find, $replace, $str);
	}

	static public function regexp_replace($str, $pattern, $replace)







>
>

>
>







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
		'truncate',
		'excerpt',
		'protect_contact',
		'atom_date',
		'xml_escape',
		'replace',
		'regexp_replace',
		'remove_leading_number',
		'get_leading_number',
	];

	const LEADING_NUMBER_REGEXP = '/^([\d.]+)\s*[.\)]\s*/';

	static public function replace($str, $find, $replace): string
	{
		return str_replace($find, $replace, $str);
	}

	static public function regexp_replace($str, $pattern, $replace)
117
118
119
120
121
122
123
124
125
126











	static public function atom_date($date)
	{
		return Utils::date_fr($date, DATE_ATOM);
	}

	static public function xml_escape($str)
	{
		return htmlspecialchars($str, ENT_XML1 | ENT_QUOTES);
	}
}


















|

|
>
>
>
>
>
>
>
>
>
>
>
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
	static public function atom_date($date)
	{
		return Utils::date_fr($date, DATE_ATOM);
	}

	static public function xml_escape($str)
	{
		return htmlspecialchars($str, ENT_XML1);
	}

	static public function remove_leading_number($str): string
	{
		return preg_replace(self::LEADING_NUMBER_REGEXP, '', trim($str));
	}

	static public function get_leading_number($str): ?string
	{
		$match = preg_match(self::LEADING_NUMBER_REGEXP, $str);
		return $match[1] ?? null;
	}
}