From ed1d212ae2daea5e4bd043417610177093e99f19 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 16 Jan 2016 03:03:51 -0500
Subject: [PATCH] Improved SVG cleanup code

---
 program/steps/settings/responses.inc |   55 +++++++++++++++++++++++++++++--------------------------
 1 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/program/steps/settings/responses.inc b/program/steps/settings/responses.inc
index cfc4148..1b88640 100644
--- a/program/steps/settings/responses.inc
+++ b/program/steps/settings/responses.inc
@@ -1,6 +1,6 @@
 <?php
 
-/*
+/**
  +-----------------------------------------------------------------------+
  | program/steps/settings/responses.inc                                  |
  |                                                                       |
@@ -21,8 +21,8 @@
 
 
 if (!empty($_POST['_insert'])) {
-    $name = trim(get_input_value('_name', RCUBE_INPUT_POST));
-    $text = trim(get_input_value('_text', RCUBE_INPUT_POST));
+    $name = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST));
+    $text = trim(rcube_utils::get_input_value('_text', rcube_utils::INPUT_POST, true));
 
     if (!empty($name) && !empty($text)) {
         $dupes = 0;
@@ -40,10 +40,10 @@
 
         if ($RCMAIL->user->save_prefs(array('compose_responses' => $responses))) {
             $RCMAIL->output->command('add_response_item', $response);
-            $RCMAIL->output->command('display_message', rcube_label('successfullysaved'), 'confirmation');
+            $RCMAIL->output->command('display_message', $RCMAIL->gettext('successfullysaved'), 'confirmation');
         }
         else {
-            $RCMAIL->output->command('display_message', rcube_label('errorsaving'), 'error');
+            $RCMAIL->output->command('display_message', $RCMAIL->gettext('errorsaving'), 'error');
         }
     }
 
@@ -51,9 +51,8 @@
     $RCMAIL->output->send();
 }
 
-
-if ($RCMAIL->action == 'delete-response') {
-    if ($key = get_input_value('_key', RCUBE_INPUT_GPC)) {
+if ($RCMAIL->action == 'delete-response' && $RCMAIL->output->ajax_call) {
+    if ($key = rcube_utils::get_input_value('_key', rcube_utils::INPUT_POST)) {
         $responses = $RCMAIL->get_compose_responses(false, true);
         foreach ($responses as $i => $response) {
             if (empty($response['key']))
@@ -67,18 +66,24 @@
     }
 
     if ($deleted) {
-        $RCMAIL->output->command('display_message', rcube_label('deletedsuccessfully'), 'confirmation');
+        $RCMAIL->output->command('display_message', $RCMAIL->gettext('deletedsuccessfully'), 'confirmation');
         $RCMAIL->output->command('remove_response', $key);
     }
 
-    if ($RCMAIL->output->ajax_call) {
-        $RCMAIL->output->send();
-    }
+    $RCMAIL->output->send();
 }
 
 
-$OUTPUT->set_pagetitle(rcube_label('responses'));
+$OUTPUT->set_pagetitle($RCMAIL->gettext('responses'));
 $OUTPUT->include_script('list.js');
+
+$OUTPUT->add_handlers(array(
+    'responseframe' => 'rcmail_response_frame',
+    'responseslist' => 'rcmail_responses_list',
+));
+$OUTPUT->add_label('deleteresponseconfirm');
+
+$OUTPUT->send('responses');
 
 
 /**
@@ -88,23 +93,28 @@
 {
     global $RCMAIL, $OUTPUT;
 
-    $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'table', 'cols' => 1);
+    $attrib += array('id' => 'rcmresponseslist', 'tagname' => 'table');
 
     $plugin = $RCMAIL->plugins->exec_hook('responses_list', array(
         'list' => $RCMAIL->get_compose_responses(true),
         'cols' => array('name')
     ));
 
-    $out = rcube_table_output($attrib, $plugin['list'], $plugin['cols'], 'key');
+    $out = $RCMAIL->table_output($attrib, $plugin['list'], $plugin['cols'], 'key');
+
+    $readonly_responses = array();
+    foreach ($plugin['list'] as $item) {
+        if (!empty($item['static'])) {
+            $readonly_responses[] = $item['key'];
+        }
+    }
 
     // set client env
     $OUTPUT->add_gui_object('responseslist', $attrib['id']);
-    $OUTPUT->set_env('readonly_responses', array_values(array_map(function($rec){ return $rec['key']; },
-      array_filter($plugin['list'], function($item){ return !empty($item['static']); }))));
+    $OUTPUT->set_env('readonly_responses', $readonly_responses);
 
     return $out;
 }
-
 
 // similar function as /steps/addressbook/func.inc::rcmail_contact_frame()
 function rcmail_response_frame($attrib)
@@ -116,13 +126,6 @@
     }
 
     $OUTPUT->set_env('contentframe', $attrib['id']);
+
     return $OUTPUT->frame($attrib, true);
 }
-
-$OUTPUT->add_handlers(array(
-    'responseframe' => 'rcmail_response_frame',
-    'responseslist' => 'rcmail_responses_list',
-));
-$OUTPUT->add_label('deleteresponseconfirm');
-
-$OUTPUT->send('responses');

--
Gitblit v1.9.1