From 59478e06c25303a790a0840ab2ac30662c4ef781 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 5 Aug 2014 16:46:22 +0200 Subject: c'est la merde.. --- program/steps/settings/about.inc | 67 +- program/steps/settings/edit_folder.inc | 5 +- program/steps/settings/edit_prefs.inc | 2 +- program/steps/settings/edit_response.inc | 107 ++ program/steps/settings/folders.inc | 16 +- program/steps/settings/func.inc | 1961 +++++++++++++----------------- program/steps/settings/responses.inc | 128 ++ program/steps/settings/save_prefs.inc | 4 - 8 files changed, 1144 insertions(+), 1146 deletions(-) create mode 100644 program/steps/settings/edit_response.inc create mode 100644 program/steps/settings/responses.inc (limited to 'program/steps/settings') diff --git a/program/steps/settings/about.inc b/program/steps/settings/about.inc index 0fdefddda..9b13402f1 100644 --- a/program/steps/settings/about.inc +++ b/program/steps/settings/about.inc @@ -40,28 +40,17 @@ function rcmail_plugins_list($attrib) $attrib['id'] = 'rcmpluginlist'; $plugins = array_filter((array) $RCMAIL->config->get('plugins')); - $plugin_info = array(); + $plugins = array_flip($plugins); - foreach ($plugins as $name) { - if ($info = $RCMAIL->plugins->get_info($name)) - $plugin_info[$name] = $info; + foreach ($plugins as $name => $plugin) { + rcube_plugin_data($name, $plugins); } - // load info from required plugins, too - foreach ($plugin_info as $name => $info) { - if (is_array($info['required']) && !empty($info['required'])) { - foreach ($info['required'] as $req_name) { - if (!isset($plugin_info[$req_name]) && ($req_info = $RCMAIL->plugins->get_info($req_name))) - $plugin_info[$req_name] = $req_info; - } - } - } - - if (empty($plugin_info)) { + if (empty($plugins)) { return ''; } - ksort($plugin_info, SORT_LOCALE_STRING); + ksort($plugins, SORT_LOCALE_STRING); $table = new html_table($attrib); @@ -71,8 +60,8 @@ function rcmail_plugins_list($attrib) $table->add_header('license', rcube_label('license')); $table->add_header('source', rcube_label('source')); - foreach ($plugin_info as $name => $data) { - $uri = $data['src_uri'] ? $data['src_uri'] : $data['uri']; + foreach ($plugins as $name => $data) { + $uri = $data['srcuri'] ? $data['srcuri'] : $data['uri']; if ($uri && stripos($uri, 'http') !== 0) { $uri = 'http://' . $uri; } @@ -89,6 +78,48 @@ function rcmail_plugins_list($attrib) return $table->show(); } +function rcube_plugin_data($name, &$plugins = array()) +{ + // XPaths of plugin metadata elements + $metadata = array( + 'name' => 'string(//rc:package/rc:name)', + 'version' => 'string(//rc:package/rc:version/rc:release)', + 'license' => 'string(//rc:package/rc:license)', + 'license_uri' => 'string(//rc:package/rc:license/@uri)', + 'srcuri' => 'string(//rc:package/rc:srcuri)', + 'uri' => 'string(//rc:package/rc:uri)', + ); + + $package = INSTALL_PATH . "/plugins/$name/package.xml"; + if (file_exists($package) && ($file = file_get_contents($package))) { + $doc = new DOMDocument(); + $doc->loadXML($file); + $xpath = new DOMXPath($doc); + $xpath->registerNamespace('rc', "http://pear.php.net/dtd/package-2.0"); + $data = array(); + + foreach ($metadata as $key => $path) { + $data[$key] = $xpath->evaluate($path); + } + + $plugins[$name] = $data; + + // dependent required plugins (can be used, but not included in config) + $deps = $xpath->evaluate('//rc:package/rc:dependencies/rc:required/rc:package/rc:name'); + $cnt = $deps->length; + + for ($i=0; $i<$cnt; $i++) { + $dn = $deps->item($i)->nodeValue; + if (!array_key_exists($dn, $plugins)) { + rcube_plugin_data($dn, $plugins); + } + } + } + else { + unset($plugins[$name]); + } +} + $OUTPUT->set_pagetitle(rcube_label('about')); diff --git a/program/steps/settings/edit_folder.inc b/program/steps/settings/edit_folder.inc index f19e2177b..fdb38e602 100644 --- a/program/steps/settings/edit_folder.inc +++ b/program/steps/settings/edit_folder.inc @@ -264,12 +264,9 @@ function rcmail_folder_form($attrib) $content = rcmail_get_form_part($tab, $attrib); } - if ($content && sizeof($form) > 1) { + if ($content) { $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n"; } - else { - $out .= $content ."\n"; - } } $out .= "\n$form_end"; diff --git a/program/steps/settings/edit_prefs.inc b/program/steps/settings/edit_prefs.inc index 468e4994d..971ed60b6 100644 --- a/program/steps/settings/edit_prefs.inc +++ b/program/steps/settings/edit_prefs.inc @@ -40,7 +40,7 @@ function rcmail_user_prefs_form($attrib) $out = $form_start; - foreach ($SECTIONS[$CURR_SECTION]['blocks'] as $block) { + foreach ($SECTIONS[$CURR_SECTION]['blocks'] as $idx => $block) { if (!empty($block['options'])) { $table = new html_table(array('cols' => 2)); diff --git a/program/steps/settings/edit_response.inc b/program/steps/settings/edit_response.inc new file mode 100644 index 000000000..49856775a --- /dev/null +++ b/program/steps/settings/edit_response.inc @@ -0,0 +1,107 @@ + | + +-----------------------------------------------------------------------+ +*/ + +$responses = $RCMAIL->get_compose_responses(); + +// edit-response +if (($key = get_input_value('_key', RCUBE_INPUT_GPC))) { + foreach ($responses as $i => $response) { + if ($response['key'] == $key) { + $RESPONSE_RECORD = $response; + $RESPONSE_RECORD['index'] = $i; + break; + } + } +} + +// save response +if ($RCMAIL->action == 'save-response' && isset($_POST['_name']) && !$RESPONSE_RECORD['static']) { + $name = trim(get_input_value('_name', RCUBE_INPUT_POST)); + $text = trim(get_input_value('_text', RCUBE_INPUT_POST)); + + if (!empty($name) && !empty($text)) { + $dupes = 0; + foreach ($responses as $i => $resp) { + if ($RESPONSE_RECORD && $RESPONSE_RECORD['index'] === $i) + continue; + if (strcasecmp($name, preg_replace('/\s\(\d+\)$/', '', $resp['name'])) == 0) + $dupes++; + } + if ($dupes) { // require a unique name + $name .= ' (' . ++$dupes . ')'; + } + + $response = array('name' => $name, 'text' => $text, 'format' => 'text', 'key' => substr(md5($name), 0, 16)); + if ($RESPONSE_RECORD && $responses[$RESPONSE_RECORD['index']]) { + $responses[$RESPONSE_RECORD['index']] = $response; + } + else { + $responses[] = $response; + } + + $responses = array_filter($responses, function($item){ return empty($item['static']); }); + if ($RCMAIL->user->save_prefs(array('compose_responses' => array_values($responses)))) { + $RCMAIL->output->show_message('successfullysaved', 'confirmation'); + $RCMAIL->output->command('parent.update_response_row', $response, $key); + $RCMAIL->overwrite_action('edit-response'); + $RESPONSE_RECORD = $response; + } + } + else { + $RCMAIL->output->show_message('formincomplete', 'error'); + } +} + + +function rcube_response_form($attrib) +{ + global $RCMAIL, $OUTPUT, $RESPONSE_RECORD; + + // Set form tags and hidden fields + $disabled = !empty($RESPONSE_RECORD['static']); + $key = $RESPONSE_RECORD['key']; + list($form_start, $form_end) = get_form_tags($attrib, 'save-response', $key, array('name' => '_key', 'value' => $key)); + unset($attrib['form'], $attrib['id']); + + // return the complete edit form as table + $out = "$form_start\n"; + + $table = new html_table(array('cols' => 2)); + $label = rcube_label('responsename'); + + $table->add('title', html::label('ffname', Q(rcube_label('responsename')))); + $table->add(null, rcube_output::get_edit_field('name', $RESPONSE_RECORD['name'], array('id' => 'ffname', 'size' => $attrib['size'], 'disabled' => $disabled), 'text')); + + $table->add('title', html::label('fftext', Q(rcube_label('responsetext')))); + $table->add(null, rcube_output::get_edit_field('text', $RESPONSE_RECORD['text'], array('id' => 'fftext', 'size' => $attrib['textareacols'], 'rows' => $attrib['textarearows'], 'disabled' => $disabled), 'textarea')); + + $out .= $table->show($attrib); + $out .= $form_end; + + return $out; +} + +$OUTPUT->set_env('readonly', !empty($RESPONSE_RECORD['static'])); +$OUTPUT->add_handler('responseform', 'rcube_response_form'); +$OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-response' ? 'savenewresponse' : 'editresponse'))); + +$OUTPUT->send('responseedit'); + diff --git a/program/steps/settings/folders.inc b/program/steps/settings/folders.inc index 64af18d62..778d93c03 100644 --- a/program/steps/settings/folders.inc +++ b/program/steps/settings/folders.inc @@ -232,16 +232,16 @@ function rcube_subscription_form($attrib) // add any necessary "virtual" parent folders if ($parent_folder && !isset($seen[$parent_folder])) { for ($i=1; $i<=$level; $i++) { - $ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); - if ($ancestor_folder && !$seen[$ancestor_folder]++) { - $ancestor_name = rcube_charset_convert($foldersplit[$i-1], 'UTF7-IMAP'); - $list_folders[] = array( + $ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); + if ($ancestor_folder && !$seen[$ancestor_folder]++) { + $ancestor_name = rcube_charset_convert($foldersplit[$i-1], 'UTF7-IMAP'); + $list_folders[] = array( 'id' => $ancestor_folder, 'name' => $ancestor_name, 'level' => $i-1, 'virtual' => true, ); - } + } } } @@ -283,6 +283,7 @@ function rcube_subscription_form($attrib) $noselect = false; $classes = array($i%2 ? 'even' : 'odd'); + $folder_js = Q($folder['id']); $folder_utf8 = rcube_charset_convert($folder['id'], 'UTF7-IMAP'); $display_folder = str_repeat('    ', $folder['level']) . Q($protected ? rcmail_localize_foldername($folder['id']) : $folder['name']); @@ -291,8 +292,7 @@ function rcube_subscription_form($attrib) $classes[] = 'virtual'; } - // Check \Noselect flag (of existing folder) - if (!$protected && in_array($folder['id'], $a_unsubscribed)) { + if (!$protected) { $attrs = $STORAGE->folder_attributes($folder['id']); $noselect = in_array('\\Noselect', $attrs); } @@ -394,7 +394,7 @@ function rcmail_rename_folder($oldname, $newname) $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); $oldprefix = '/^' . preg_quote($oldname . $delimiter, '/') . '/'; - foreach (array_keys($a_threaded) as $key) { + foreach ($a_threaded as $key => $val) { if ($key == $oldname) { unset($a_threaded[$key]); $a_threaded[$newname] = true; diff --git a/program/steps/settings/func.inc b/program/steps/settings/func.inc index fdc07be9e..981d4e406 100644 --- a/program/steps/settings/func.inc +++ b/program/steps/settings/func.inc @@ -19,1176 +19,915 @@ +-----------------------------------------------------------------------+ */ -if (!$OUTPUT->ajax_call) { - $OUTPUT->set_pagetitle(rcube_label('preferences')); -} +if (!$OUTPUT->ajax_call) + $OUTPUT->set_pagetitle(rcube_label('preferences')); + // similar function as /steps/settings/identities.inc::rcmail_identity_frame() function rcmail_preferences_frame($attrib) { - global $OUTPUT; + global $OUTPUT; - if (!$attrib['id']) { - $attrib['id'] = 'rcmprefsframe'; - } + if (!$attrib['id']) + $attrib['id'] = 'rcmprefsframe'; - return $OUTPUT->frame($attrib, true); + return $OUTPUT->frame($attrib, true); } function rcmail_sections_list($attrib) { - global $RCMAIL; + global $RCMAIL; - // add id to message list table if not specified - if (!strlen($attrib['id'])) { - $attrib['id'] = 'rcmsectionslist'; - } + // add id to message list table if not specified + if (!strlen($attrib['id'])) + $attrib['id'] = 'rcmsectionslist'; - list($list, $cols) = rcmail_user_prefs(); + list($list, $cols) = rcmail_user_prefs(); - // create XHTML table - $out = rcube_table_output($attrib, $list, $cols, 'id'); + // create XHTML table + $out = rcube_table_output($attrib, $list, $cols, 'id'); - // set client env - $RCMAIL->output->add_gui_object('sectionslist', $attrib['id']); - $RCMAIL->output->include_script('list.js'); + // set client env + $RCMAIL->output->add_gui_object('sectionslist', $attrib['id']); + $RCMAIL->output->include_script('list.js'); - return $out; + return $out; } function rcmail_identities_list($attrib) { - global $OUTPUT, $RCMAIL; + global $OUTPUT, $RCMAIL; - // add id to message list table if not specified - if (!strlen($attrib['id'])) { - $attrib['id'] = 'rcmIdentitiesList'; - } + // add id to message list table if not specified + if (!strlen($attrib['id'])) + $attrib['id'] = 'rcmIdentitiesList'; - // get identities list and define 'mail' column - $list = $RCMAIL->user->list_identities(); - foreach ($list as $idx => $row) { - $list[$idx]['mail'] = trim($row['name'] . ' <' . rcube_idn_to_utf8($row['email']) .'>'); - } + // get identities list and define 'mail' column + $list = $RCMAIL->user->list_identities(); + foreach ($list as $idx => $row) + $list[$idx]['mail'] = trim($row['name'] . ' <' . rcube_idn_to_utf8($row['email']) .'>'); - // get all identites from DB and define list of cols to be displayed - $plugin = $RCMAIL->plugins->exec_hook('identities_list', array( - 'list' => $list, - 'cols' => array('mail') - )); + // get all identites from DB and define list of cols to be displayed + $plugin = $RCMAIL->plugins->exec_hook('identities_list', array( + 'list' => $list, + 'cols' => array('mail'))); - // @TODO: use