summaryrefslogtreecommitdiff
path: root/program/include
diff options
context:
space:
mode:
Diffstat (limited to 'program/include')
-rw-r--r--program/include/main.inc13
-rw-r--r--program/include/rcmail.php16
-rw-r--r--program/include/rcube_addressbook.php29
-rw-r--r--program/include/rcube_contacts.php22
-rw-r--r--program/include/rcube_json_output.php7
-rwxr-xr-xprogram/include/rcube_template.php6
6 files changed, 84 insertions, 9 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 697b3ff21..155f4afee 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -84,6 +84,7 @@ function get_sequence_name($sequence)
* It's a global wrapper for rcmail::gettext()
*
* @param mixed Named parameters array or label name
+ * @param string Domain to search in (e.g. plugin name)
* @return string Localized text
* @see rcmail::gettext()
*/
@@ -94,6 +95,18 @@ function rcube_label($p, $domain=null)
/**
+ * Global wrapper of rcmail::text_exists()
+ * to check whether a text label is defined
+ *
+ * @see rcmail::text_exists()
+ */
+function rcube_label_exists($name, $domain=null)
+{
+ return rcmail::get_instance()->text_exists($name, $domain);
+}
+
+
+/**
* Overwrite action variable
*
* @param string New action value
diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 8c80fe20b..1c9810681 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -926,6 +926,22 @@ class rcmail
/**
+ * Check if the given text lable exists
+ *
+ * @param string Label name
+ * @return boolean True if text exists (either in the current language or in en_US)
+ */
+ public function text_exists($name, $domain=null)
+ {
+ // load localization files if not done yet
+ if (empty($this->texts))
+ $this->load_language();
+
+ // check for text with domain first
+ return ($domain && isset($this->texts[$domain.'.'.$name])) || isset($this->texts[$name]);
+ }
+
+ /**
* Load a localization package
*
* @param string Language ID
diff --git a/program/include/rcube_addressbook.php b/program/include/rcube_addressbook.php
index c3c8e9271..648ef838e 100644
--- a/program/include/rcube_addressbook.php
+++ b/program/include/rcube_addressbook.php
@@ -168,6 +168,35 @@ abstract class rcube_addressbook
$this->page_size = (int)$size;
}
+
+ /**
+ * Check the given data before saving.
+ * If input not valid, the message to display can be fetched using get_error()
+ *
+ * @param array Assoziative array with data to save
+ * @return boolean True if input is valid, False if not.
+ */
+ public function validate($save_data)
+ {
+ if (empty($save_data['name'])) {
+ $this->set_error('warning', 'nonamewarning');
+ return false;
+ }
+
+ // check validity of email addresses
+ foreach ($this->get_col_values('email', $save_data, true) as $email) {
+ if (strlen($email)) {
+ if (!check_email(rcube_idn_to_ascii($email))) {
+ $this->set_error('warning', rcube_label(array('name' => 'emailformaterror', 'vars' => array('email' => $email))));
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+
/**
* Create a new contact record
*
diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php
index 4a4c1e27e..9ad4f17bb 100644
--- a/program/include/rcube_contacts.php
+++ b/program/include/rcube_contacts.php
@@ -396,6 +396,28 @@ class rcube_contacts extends rcube_addressbook
/**
+ * Check the given data before saving.
+ * If input not valid, the message to display can be fetched using get_error()
+ *
+ * @param array Assoziative array with data to save
+ * @return boolean True if input is valid, False if not.
+ */
+ public function validate($save_data)
+ {
+ // check for name input
+ $valid = parent::validate($save_data);
+
+ // require at least one e-mail address (syntax check is done later in save.inc)
+ if ($valid && !array_filter($this->get_col_values('email', $save_data, true))) {
+ $this->set_error('warning', 'noemailwarning');
+ $valid = false;
+ }
+
+ return $valid;
+ }
+
+
+ /**
* Create a new contact record
*
* @param array Associative array with save data
diff --git a/program/include/rcube_json_output.php b/program/include/rcube_json_output.php
index c6d3c25f9..d1c9de279 100644
--- a/program/include/rcube_json_output.php
+++ b/program/include/rcube_json_output.php
@@ -170,11 +170,8 @@ class rcube_json_output
{
if ($override || !$this->message) {
$this->message = $message;
- $this->command(
- 'display_message',
- rcube_label(array('name' => $message, 'vars' => $vars)),
- $type
- );
+ $msgtext = rcube_label_exists($message) ? rcube_label(array('name' => $message, 'vars' => $vars)) : $message;
+ $this->command('display_message', $msgtext, $type);
}
}
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 2102aaa1f..70c175a98 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -255,10 +255,8 @@ class rcube_template extends rcube_html_page
{
if ($override || !$this->message) {
$this->message = $message;
- $this->command(
- 'display_message',
- rcube_label(array('name' => $message, 'vars' => $vars)),
- $type);
+ $msgtext = rcube_label_exists($message) ? rcube_label(array('name' => $message, 'vars' => $vars)) : $message;
+ $this->command('display_message', $msgtext, $type);
}
}