summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2011-02-09 10:33:26 +0000
committerthomascube <thomas@roundcube.net>2011-02-09 10:33:26 +0000
commitce988a0778aee7fb42ce5fc42e2986d562b6ccbb (patch)
tree6a5147dfd3300938d0595da5388e8ddf683a77b7 /program
parent829cbfe88cb4cd86072cf2a2b926868e9d4558cf (diff)
Always generate valid DOM identifiers using html_identifier() write original identifier string to rel attribute where possible
Diffstat (limited to 'program')
-rw-r--r--program/include/main.inc17
-rw-r--r--program/js/app.js5
-rw-r--r--program/steps/addressbook/func.inc14
-rw-r--r--program/steps/addressbook/save.inc2
4 files changed, 30 insertions, 8 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 35f9ddc98..dd86a7821 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -741,6 +741,16 @@ function asciiwords($str, $css_id = false, $replace_with = '')
}
/**
+ * Convert the given string into a valid HTML identifier
+ * Same functionality as done in app.js with this.identifier_expr
+ *
+ */
+function html_identifier($str)
+{
+ return asciiwords($str, true, '_');
+}
+
+/**
* Remove single and double quotes from given string
*
* @param string Input value
@@ -791,7 +801,7 @@ function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col)
while ($table_data && ($sql_arr = $db->fetch_assoc($table_data)))
{
$zebra_class = $c % 2 ? 'even' : 'odd';
- $table->add_row(array('id' => 'rcmrow' . $sql_arr[$id_col], 'class' => $zebra_class));
+ $table->add_row(array('id' => 'rcmrow' . html_identifier($sql_arr[$id_col]), 'class' => $zebra_class));
// format each col
foreach ($a_show_cols as $col)
@@ -808,7 +818,7 @@ function rcube_table_output($attrib, $table_data, $a_show_cols, $id_col)
if (!empty($row_data['class']))
$zebra_class .= ' '.$row_data['class'];
- $table->add_row(array('id' => 'rcmrow' . $row_data[$id_col], 'class' => $zebra_class));
+ $table->add_row(array('id' => 'rcmrow' . html_identifier($row_data[$id_col]), 'class' => $zebra_class));
// format each col
foreach ($a_show_cols as $col)
@@ -1487,7 +1497,7 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $at
}
// make folder name safe for ids and class names
- $folder_id = asciiwords($folder['id'], true, '_');
+ $folder_id = html_identifier($folder['id']);
$classes = array('mailbox');
// set special class for Sent, Drafts, Trash and Junk
@@ -1522,6 +1532,7 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$mbox_name, &$jslist, $at
$link_attrib = $folder['virtual'] ? array() : array(
'href' => rcmail_url('', array('_mbox' => $folder['id'])),
'onclick' => sprintf("return %s.command('list','%s',this)", JS_OBJECT_NAME, $js_name),
+ 'rel' => $folder['id'],
'title' => $title,
);
diff --git a/program/js/app.js b/program/js/app.js
index 3c8502d0e..43be6ae8d 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -3781,6 +3781,9 @@ function rcube_webmail()
// update a contact record in the list
this.update_contact_row = function(cid, cols_arr, newcid)
{
+ cid = String(cid).replace(this.identifier_expr, '_');
+ newcid = String(newcid).replace(this.identifier_expr, '_');
+
var row;
if (this.contact_list.rows[cid] && (row = this.contact_list.rows[cid].obj)) {
for (var c=0; c<cols_arr.length; c++)
@@ -3813,7 +3816,7 @@ function rcube_webmail()
even = rowcount%2,
row = document.createElement('tr');
- row.id = 'rcmrow'+cid;
+ row.id = 'rcmrow'+String(cid).replace(this.identifier_expr, '_');
row.className = 'contact '+(even ? 'even' : 'odd');
if (this.contact_list.in_selection(cid))
diff --git a/program/steps/addressbook/func.inc b/program/steps/addressbook/func.inc
index 7597fa75a..3397d3712 100644
--- a/program/steps/addressbook/func.inc
+++ b/program/steps/addressbook/func.inc
@@ -120,6 +120,7 @@ function rcmail_directory_list($attrib)
$line_templ = html::tag('li', array(
'id' => 'rcmli%s', 'class' => 'addressbook %s'),
html::a(array('href' => '%s',
+ 'rel' => '%s',
'onclick' => "return ".JS_OBJECT_NAME.".command('list','%s',this)"), '%s'));
// currently selected is the first address source in the list
@@ -129,9 +130,11 @@ function rcmail_directory_list($attrib)
foreach ((array)$OUTPUT->env['address_sources'] as $j => $source) {
$id = strval($source['id'] ? $source['id'] : $j);
$js_id = JQ($id);
- $dom_id = preg_replace('/[^a-z0-9\-_]/i', '_', $id);
- $out .= sprintf($line_templ, $dom_id, ($current === $id ? 'selected' : ''),
+ $out .= sprintf($line_templ,
+ html_identifier($id),
+ ($current === $id ? 'selected' : ''),
Q(rcmail_url(null, array('_source' => $id))),
+ $source['id'],
$js_id, (!empty($source['name']) ? Q($source['name']) : Q($id)));
$groupdata = array('out' => $out, 'jsdata' => $jsdata, 'source' => $id);
@@ -158,11 +161,16 @@ function rcmail_contact_groups($args)
$line_templ = html::tag('li', array(
'id' => 'rcmliG%s', 'class' => 'contactgroup'),
html::a(array('href' => '#',
+ 'rel' => '%s:%s',
'onclick' => "return ".JS_OBJECT_NAME.".command('listgroup',{'source':'%s','id':'%s'},this)"), '%s'));
$jsdata = array();
foreach ($groups as $group) {
- $args['out'] .= sprintf($line_templ, asciiwords($args['source'] . $group['ID'], true, '_'), $args['source'], $group['ID'], Q($group['name']));
+ $args['out'] .= sprintf($line_templ,
+ html_identifier($args['source'] . $group['ID']),
+ $args['source'], $group['ID'],
+ $args['source'], $group['ID'], Q($group['name'])
+ );
$args['jsdata']['G'.$args['source'].$group['ID']] = array(
'source' => $args['source'], 'id' => $group['ID'],
'name' => $group['name'], 'type' => 'group');
diff --git a/program/steps/addressbook/save.inc b/program/steps/addressbook/save.inc
index 10155a1a9..aa45a4e15 100644
--- a/program/steps/addressbook/save.inc
+++ b/program/steps/addressbook/save.inc
@@ -249,7 +249,7 @@ else {
$result = $CONTACTS->search($CONTACTS->primary_key, $insert_id);
rcmail_js_contacts_list($result, 'parent.');
- $OUTPUT->command('parent.contact_list.select', $insert_id);
+ $OUTPUT->command('parent.contact_list.select', html_identifier($insert_id));
// update record count display
$CONTACTS->reset();