Skip to content

Commit 9494aee

Browse files
committed
Implemented list update and other UX/lang tweaks
1 parent ae38380 commit 9494aee

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

Snippets/lang/strings_english.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ $s_plugin_Snippets_create_name = "Name";
2626
$s_plugin_Snippets_create_value = "Snippet";
2727

2828
$s_plugin_Snippets_action_go = "Go";
29+
$s_plugin_Snippets_action_create = "create";
2930
$s_plugin_Snippets_action_edit = "Edit";
3031
$s_plugin_Snippets_action_delete = "Delete";
3132
$s_plugin_Snippets_action_delete_confirm = "Do you really want to delete the following snippets?";

Snippets/pages/snippet_create.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@
2020
$snippet->save();
2121

2222
form_security_purge("plugin_snippets_create");
23-
print_successful_redirect(plugin_page("snippet_list", true) . $global ? "&global=true" : "");
23+
print_successful_redirect(plugin_page("snippet_list", true) . ($global ? "&global=true" : ""));
2424

Snippets/pages/snippet_list.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
?>
2121

2222
<br/>
23-
<form action="<?php echo plugin_page("snippet_list_action"), $global ? "&global=true" : "" ?>" method="post">
23+
<form action="<?php echo plugin_page("snippet_list_action") ?>" method="post">
2424
<?php echo form_security_field("plugin_Snippets_list_action") ?>
25+
<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
2526
<table class="width75" align="center">
2627

2728
<tr>
@@ -30,7 +31,7 @@
3031
</tr>
3132

3233
<tr class="row-category">
33-
<td> </td>
34+
<td width="5%"> </td>
3435
<td><?php echo plugin_lang_get("list_name") ?></td>
3536
<td><?php echo plugin_lang_get("list_value") ?></td>
3637
</tr>
@@ -61,24 +62,25 @@
6162
<br/>
6263
<form action="<?php echo plugin_page("snippet_create") ?>" method="post">
6364
<?php echo form_security_field("plugin_snippets_create") ?>
65+
<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
6466
<table class="width75" align="center">
6567

6668
<tr>
67-
<td class="form-title" colspan="2">Create Snippet</td>
69+
<td class="form-title" colspan="2"><?php echo plugin_lang_get($global ? "create_global_title" : "create_title") ?></td>
6870
</tr>
6971

7072
<tr <?php echo helper_alternate_class() ?>>
71-
<td class="category">Short Name</td>
73+
<td class="category"><?php echo plugin_lang_get("create_name") ?></td>
7274
<td><input name="name"/></td>
7375
</tr>
7476

7577
<tr <?php echo helper_alternate_class() ?>>
76-
<td class="category">Full Text</td>
78+
<td class="category"><?php echo plugin_lang_get("create_value") ?></td>
7779
<td><textarea name="value" cols="80" rows="6"></textarea></td>
7880
</tr>
7981

8082
<tr>
81-
<td class="center" colspan="2"><input type="submit"/></td>
83+
<td class="center" colspan="2"><input type="submit" value="<?php echo plugin_lang_get("action_create") ?>"/></td>
8284
</tr>
8385

8486
</table>

Snippets/pages/snippet_list_action.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616

1717
$action = gpc_get_string("action");
1818

19-
$snippet_list = gpc_get_int_array("snippet_list");
19+
$snippet_list = gpc_get_int_array("snippet_list", array());
20+
21+
if (count($snippet_list) < 1) {
22+
form_security_purge("plugin_Snippets_list_action");
23+
print_header_redirect(plugin_page("snippet_list", true) . ($global ? "&global=true" : ""));
24+
}
25+
2026
$snippets = Snippet::load_by_id($snippet_list, $user_id);
2127

2228
function array_object_properties($arr, $prop) {
@@ -43,8 +49,9 @@ function array_object_properties($arr, $prop) {
4349
?>
4450

4551
<br/>
46-
<form action="<?php echo plugin_page("snippet_list_action"), $global ? "&global=true" : "" ?>" method="post">
52+
<form action="<?php echo plugin_page("snippet_list_action") ?>" method="post">
4753
<?php echo form_security_field("plugin_Snippets_list_action") ?>
54+
<?php if ($global): ?><input type="hidden" name="global" value="true"/><?php endif ?>
4855
<input type="hidden" name="action" value="update"/>
4956
<table class="width75" align="center">
5057

@@ -81,6 +88,23 @@ function array_object_properties($arr, $prop) {
8188

8289
### UPDATE
8390
} elseif ($action == "update") {
91+
foreach($snippets as $snippet_id => $snippet) {
92+
$new_name = gpc_get_string("name_{$snippet_id}");
93+
$new_value = gpc_get_string("value_{$snippet_id}");
94+
95+
if ($snippet->name != $new_name
96+
|| $snippet->value != $new_value)
97+
{
98+
$snippet->name = $new_name;
99+
$snippet->value = $new_value;
100+
101+
$snippet->save();
102+
}
103+
}
104+
105+
form_security_purge("plugin_Snippets_list_action");
106+
print_successful_redirect(plugin_page("snippet_list", true) . ($global ? "&global=true" : ""));
107+
84108
}
85109

86110

0 commit comments

Comments
 (0)