Skip to content

Commit 1039fde

Browse files
committed
Use more descriptive placeholders
Fixes #10
1 parent c50eb99 commit 1039fde

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ replaced by the corresponding contents when inserted:
4343

4444
Placeholder | Description
4545
:-----------:|-------------------------
46-
%u | your username
47-
%r | the bug reporter's name
48-
%h | the bug handler's name
49-
%p | the project name
46+
{user} | your username
47+
{reporter} | the bug reporter's name
48+
{handler} | the bug handler's name
49+
{project} | the project name
5050

5151

5252
### Using Snippets

Snippets/Snippets.API.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
# Copyright (c) 2012 - 2014 MantisBT Team - [email protected]
55
# Licensed under the MIT license
66

7+
define( 'PLACEHOLDER_USER', '{user}' );
8+
define( 'PLACEHOLDER_REPORTER', '{reporter}' );
9+
define( 'PLACEHOLDER_HANDLER', '{handler}' );
10+
define( 'PLACEHOLDER_PROJECT', '{project}' );
11+
712
function xmlhttprequest_plugin_snippets_text() {
813
plugin_push_current("Snippets");
914

@@ -185,7 +190,7 @@ public static function clean($dirty, $target="view", $pattern=false) {
185190
* @return array Updated snippet objects
186191
*/
187192
public static function patterns($snippets, $bug_id) {
188-
$handler = '%h';
193+
$handler = PLACEHOLDER_HANDLER;
189194

190195
$current_user = auth_get_current_user_id();
191196

@@ -209,7 +214,7 @@ public static function patterns($snippets, $bug_id) {
209214

210215
foreach ($snippets as $snippet) {
211216
$snippet->value = str_replace(
212-
array('%u', '%r', '%h', '%p'),
217+
array(PLACEHOLDER_USER, PLACEHOLDER_REPORTER, PLACEHOLDER_HANDLER, PLACEHOLDER_PROJECT),
213218
array($username, $reporter, $handler, $project),
214219
$snippet->value);
215220
}
@@ -334,7 +339,11 @@ public static function delete_by_user_id($user_id) {
334339
private static function from_db_result($result) {
335340
$snippets = array();
336341
while ($row = db_fetch_array($result)) {
337-
$snippet = new Snippet($row["type"], $row["name"], $row["value"], $row["user_id"]);
342+
$snippet = new Snippet(
343+
$row['type'],
344+
$row['name'],
345+
Snippet::replace_legacy_placeholders($row['value']),
346+
$row['user_id']);
338347
$snippet->id = $row["id"];
339348

340349
$snippets[$row["id"]] = $snippet;
@@ -343,6 +352,21 @@ private static function from_db_result($result) {
343352
return $snippets;
344353
}
345354

355+
/**
356+
* Replace legacy placeholders (e.g. %u) with modern ones (e.g. {user}).
357+
*
358+
* @param string $p_value The snippet to process.
359+
* @return string The processed snippet.
360+
*/
361+
private static function replace_legacy_placeholders($p_value) {
362+
$t_value = $p_value;
363+
$t_value = str_replace('%u', PLACEHOLDER_USER, $t_value);
364+
$t_value = str_replace('%r', PLACEHOLDER_REPORTER, $t_value);
365+
$t_value = str_replace('%h', PLACEHOLDER_HANDLER, $t_value);
366+
$t_value = str_replace('%p', PLACEHOLDER_PROJECT, $t_value);
367+
return $t_value;
368+
}
369+
346370
public static function global_url($p_is_global = true) {
347371
if ($p_is_global) {
348372
return '&global=true';

Snippets/lang/strings_english.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ $s_plugin_Snippets_pattern_help = '
4747
with contextual data when pasted into a text field. The following<br/>
4848
placeholders are supported:<br/>
4949
<table>
50-
<tr><td><strong>%u</strong></td><td>Your username</td></tr>
51-
<tr><td><strong>%r</strong></td><td>Bug reporter\'s name</td></tr>
52-
<tr><td><strong>%h</strong></td><td>Bug handler\'s name</td></tr>
53-
<tr><td><strong>%p</strong></td><td>Project name</td></tr>
50+
<tr><td><strong>{user}</strong></td><td>Your username</td></tr>
51+
<tr><td><strong>{reporter}</strong></td><td>Bug reporter\'s name</td></tr>
52+
<tr><td><strong>{handler}</strong></td><td>Bug handler\'s name</td></tr>
53+
<tr><td><strong>{project}</strong></td><td>Project name</td></tr>
5454
</table>
5555
';
5656

Snippets/lang/strings_french.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ $s_plugin_Snippets_pattern_help = '
4747
des données contextuelles lors de leur insertion dans un champ texte.<br/>
4848
Les marqueurs suivants sont pris en compte :<br/>
4949
<table>
50-
<tr><td><strong>%u</strong></td><td>Votre nom d\'utilisateur</td></tr>
51-
<tr><td><strong>%r</strong></td><td>Le nom du rapporteur de la demande</td></tr>
52-
<tr><td><strong>%h</strong></td><td>Le nom de celui à qui la demande est affectée</td></tr>
53-
<tr><td><strong>%p</strong></td><td>Le nom du projet</td></tr>
50+
<tr><td><strong>{user}</strong></td><td>Votre nom d\'utilisateur</td></tr>
51+
<tr><td><strong>{reporter}</strong></td><td>Le nom du rapporteur de la demande</td></tr>
52+
<tr><td><strong>{handler}</strong></td><td>Le nom de celui à qui la demande est affectée</td></tr>
53+
<tr><td><strong>{project}</strong></td><td>Le nom du projet</td></tr>
5454
</table>
5555
';
5656

Snippets/lang/strings_german.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ $s_plugin_Snippets_pattern_help = '
4747
ein Textfeld durch einen aktuellen Wert ersetzt werden<br/>
4848
Die folgenden Platzhalter werden unterstützt:<br/>
4949
<table>
50-
<tr><td><strong>%u</strong></td><td>Ihr Benutzername</td></tr>
51-
<tr><td><strong>%r</strong></td><td>Benutzername des Reporters</td></tr>
52-
<tr><td><strong>%h</strong></td><td>Benutzername dem der Eintrag zugeordnet ist</td></tr>
53-
<tr><td><strong>%p</strong></td><td>Projektname</td></tr>
50+
<tr><td><strong>{user}</strong></td><td>Ihr Benutzername</td></tr>
51+
<tr><td><strong>{reporter}</strong></td><td>Benutzername des Reporters</td></tr>
52+
<tr><td><strong>{handler}</strong></td><td>Benutzername dem der Eintrag zugeordnet ist</td></tr>
53+
<tr><td><strong>{project}</strong></td><td>Projektname</td></tr>
5454
</table>
5555
';
5656

0 commit comments

Comments
 (0)