Changeset 4025 in subversion


Ignore:
Timestamp:
Sep 30, 2010 9:24:33 AM (3 years ago)
Author:
alec
Message:
  • Plugin API: improved 'abort' flag handling, added 'result' item in some hooks: group_*, contact_*, identity_* (#1486914)
Location:
trunk/roundcubemail
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r4024 r4025  
    1313- Change reply prefix to display email address only if sender name doesn't exist (#1486550) 
    1414- Fix charset replacement in HTML message bodies (#1487021) 
     15- Plugin API: improved 'abort' flag handling, added 'result' item in some hooks (#1486914)  
    1516 
    1617RELEASE 0.4.1 
  • trunk/roundcubemail/program/steps/addressbook/copy.inc

    r3989 r4025  
    3838 
    3939    foreach ($arr_cids as $cid) { 
    40       $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( 
    41         'record' => $CONTACTS->get_record($cid, true), 
    42         'source' => $target, 
    43         'group' => $target_group, 
    44       )); 
    45       $a_record = $plugin['record']; 
     40      $a_record = $CONTACTS->get_record($cid, true); 
    4641 
    47       if (!$plugin['abort']) { 
    48         // check if contact exists, if so, we'll need it's ID 
    49         $result = $TARGET->search('email', $a_record['email'], true, true); 
     42      // check if contact exists, if so, we'll need it's ID 
     43      $result = $TARGET->search('email', $a_record['email'], true, true); 
    5044 
    51         // insert contact record 
    52         if (!$result->count) { 
     45      // insert contact record 
     46      if (!$result->count) { 
     47        $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( 
     48          'record' => $a_record, 'source' => $target, 'group' => $target_group)); 
     49 
     50        if (!$plugin['abort']) { 
    5351          if ($insert_id = $TARGET->insert($a_record, false)) { 
    5452            $ids[] = $insert_id; 
     
    5654          } 
    5755        } 
    58         else { 
    59           $record = $result->first(); 
    60           $ids[] = $record['ID']; 
     56        else if ($plugin['result']) { 
     57          $ids = array_merge($ids, $plugin['result']); 
     58          $success++; 
    6159        } 
     60      } 
     61      else { 
     62        $record = $result->first(); 
     63        $ids[] = $record['ID']; 
    6264      } 
    6365    } 
     
    8082          $success = $cnt; 
    8183      } 
     84      else if ($plugin['result']) 
     85        $success = $plugin['result']; 
    8286    } 
    8387  } 
  • trunk/roundcubemail/program/steps/addressbook/delete.inc

    r3989 r4025  
    2424    preg_match('/^[a-zA-Z0-9\+\/=_-]+(,[a-zA-Z0-9\+\/=_-]+)*$/', $cid) 
    2525) { 
    26   $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array('id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); 
     26  $plugin = $RCMAIL->plugins->exec_hook('contact_delete', array( 
     27    'id' => $cid, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); 
    2728 
    28   $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : false; 
    29   if (!$deleted) 
    30     { 
     29  $deleted = !$plugin['abort'] ? $CONTACTS->delete($cid) : $plugin['result']; 
     30 
     31  if (!$deleted) { 
    3132    // send error message 
    3233    exit; 
    33     } 
     34  } 
    3435 
    3536  // count contacts for this user 
     
    4748  // send response 
    4849  $OUTPUT->send(); 
    49   } 
     50} 
    5051 
    5152exit; 
  • trunk/roundcubemail/program/steps/addressbook/groups.inc

    r3989 r4025  
    3434    $num2add = count(explode(',', $plugin['ids'])); 
    3535     
    36     if (!$plugin['abort'] && ($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) 
    37       $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); 
    38     else if (!$plugin['abort'] && $CONTACTS->add_to_group($gid, $plugin['ids'])) 
     36    if (!$plugin['abort']) { 
     37      if (($maxnum = $RCMAIL->config->get('max_group_members', 0)) && ($CONTACTS->count()->count + $num2add > $maxnum)) { 
     38        $OUTPUT->show_message('maxgroupmembersreached', 'warning', array('max' => $maxnum)); 
     39        $OUTPUT->send(); 
     40      } 
     41      $result = $CONTACTS->add_to_group($gid, $plugin['ids']); 
     42    } 
     43    else { 
     44      $result = $plugin['result']; 
     45    } 
     46 
     47    if ($result)  
    3948      $OUTPUT->show_message('contactaddedtogroup'); 
    4049    else if ($plugin['message']) 
     
    4756    $plugin = $RCMAIL->plugins->exec_hook('group_delmembers', array('group_id' => $gid, 'ids' => $ids, 'source' => $source)); 
    4857     
    49     if (!$plugin['abort'] && $CONTACTS->remove_from_group($gid, $plugin['ids'])) 
     58    if (!$plugin['abort']) 
     59      $result = $CONTACTS->remove_from_group($gid, $plugin['ids']); 
     60    else 
     61      $result = $plugin['result']; 
     62 
     63    if ($result)  
    5064      $OUTPUT->show_message('contactremovedfromgroup'); 
    5165    else if ($plugin['message']) 
     
    5771  if ($name = trim(get_input_value('_name', RCUBE_INPUT_POST))) { 
    5872    $plugin = $RCMAIL->plugins->exec_hook('group_create', array('name' => $name, 'source' => $source)); 
     73 
    5974    if (!$plugin['abort']) 
    6075      $created = $CONTACTS->create_group($plugin['name']); 
     76    else 
     77      $created = $plugin['result']; 
    6178  } 
    6279   
     
    7390  if (($gid = get_input_value('_gid', RCUBE_INPUT_POST)) && ($name = trim(get_input_value('_name', RCUBE_INPUT_POST)))) { 
    7491    $plugin = $RCMAIL->plugins->exec_hook('group_rename', array('group_id' => $gid, 'name' => $name, 'source' => $source)); 
     92 
    7593    if (!$plugin['abort']) 
    7694      $newname = $CONTACTS->rename_group($gid, $plugin['name']); 
     95    else 
     96      $newname = $plugin['result']; 
    7797  } 
    7898 
     
    86106  if ($gid = get_input_value('_gid', RCUBE_INPUT_POST)) { 
    87107    $plugin = $RCMAIL->plugins->exec_hook('group_delete', array('group_id' => $gid, 'source' => $source)); 
     108 
    88109    if (!$plugin['abort']) 
    89110      $deleted = $CONTACTS->delete_group($gid); 
     111    else 
     112      $deleted = $plugin['result']; 
    90113  } 
    91114 
  • trunk/roundcubemail/program/steps/addressbook/import.inc

    r3989 r4025  
    160160 
    161161      // insert record and send response 
    162       if (!$plugin['abort'] && ($success = $CONTACTS->insert($a_record))) { 
     162      if (!$plugin['abort']) 
     163        $success = $CONTACTS->insert($a_record); 
     164      else 
     165        $success = $plugin['result']; 
     166 
     167      if ($success) { 
    163168        $IMPORT_STATS->inserted++; 
    164169        $IMPORT_STATS->names[] = $vcard->displayname; 
  • trunk/roundcubemail/program/steps/addressbook/save.inc

    r3989 r4025  
    5959  $a_record = $plugin['record']; 
    6060   
    61   if (!$plugin['abort'] && ($result = $CONTACTS->update($cid, $a_record))) 
    62   { 
     61  if (!$plugin['abort']) 
     62    $result = $CONTACTS->update($cid, $a_record); 
     63  else 
     64    $result = $plugin['result']; 
     65 
     66  if ($result) { 
    6367    // LDAP DN change 
    6468    if (is_string($result) && strlen($result)>1) { 
     
    8286    rcmail_overwrite_action('show'); 
    8387  } 
    84   else 
    85   { 
     88  else { 
    8689    // show error message 
    87     $OUTPUT->show_message('errorsaving', 'error', null, false); 
     90    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
    8891    rcmail_overwrite_action('show'); 
    8992  } 
     
    9194 
    9295// insert a new contact 
    93 else 
    94 { 
     96else { 
    9597  // check for existing contacts 
    9698  $existing = $CONTACTS->search('email', $a_record['email'], true, false); 
    9799 
    98100  // show warning message 
    99   if ($existing->count) 
    100   { 
     101  if ($existing->count) { 
    101102    $OUTPUT->show_message('contactexists', 'warning', null, false); 
    102103    rcmail_overwrite_action('add'); 
     
    104105  } 
    105106 
    106   $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); 
     107  $plugin = $RCMAIL->plugins->exec_hook('contact_create', array( 
     108    'record' => $a_record, 'source' => get_input_value('_source', RCUBE_INPUT_GPC))); 
    107109  $a_record = $plugin['record']; 
    108110 
    109111  // insert record and send response 
    110   if (!$plugin['abort'] && ($insert_id = $CONTACTS->insert($a_record))) 
    111   { 
     112  if (!$plugin['abort']) 
     113    $insert_id = $CONTACTS->insert($a_record); 
     114  else 
     115    $insert_id = $plugin['result']; 
     116 
     117 
     118  if ($insert_id) { 
    112119    // add contact row or jump to the page where it should appear 
    113120    $CONTACTS->reset(); 
     
    125132    $OUTPUT->send('iframe'); 
    126133  } 
    127   else 
    128   { 
     134  else { 
    129135    // show error message 
    130     $OUTPUT->show_message('errorsaving', 'error', null, false); 
     136    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
    131137    rcmail_overwrite_action('add'); 
    132138  } 
    133139} 
    134  
    135  
  • trunk/roundcubemail/program/steps/mail/addcontact.inc

    r4009 r4025  
    3131  $contact_arr = $IMAP->decode_address_list(get_input_value('_address', RCUBE_INPUT_POST, true), 1, false); 
    3232   
    33   if (!empty($contact_arr[1]['mailto'])) 
    34   { 
     33  if (!empty($contact_arr[1]['mailto'])) { 
    3534    $contact = array( 
    3635      'email' => $contact_arr[1]['mailto'], 
     
    4645    // check for existing contacts 
    4746    $existing = $CONTACTS->search('email', $contact['email'], true, false); 
     47 
    4848    if ($done = $existing->count) 
    4949      $OUTPUT->show_message('contactexists', 'warning'); 
    50     else 
    51     { 
     50    else { 
    5251      $plugin = $RCMAIL->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null)); 
    5352      $contact = $plugin['record']; 
    5453 
    55       if (!$plugin['abort'] && ($done = $CONTACTS->insert($contact))) 
     54      $done = !$plugin['abort'] ? $CONTACTS->insert($contact) : $plugin['result']; 
     55 
     56      if ($done) 
    5657        $OUTPUT->show_message('addedsuccessfully', 'confirmation'); 
    5758    } 
     
    6061 
    6162if (!$done) 
    62   $OUTPUT->show_message('errorsavingcontact', 'warning'); 
     63  $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsavingcontact', 'warning'); 
    6364 
    6465$OUTPUT->send(); 
  • trunk/roundcubemail/program/steps/settings/delete_identity.inc

    r3989 r4025  
    3333  $plugin = $RCMAIL->plugins->exec_hook('identity_delete', array('id' => $iid)); 
    3434   
    35   if (!$plugin['abort'] && $USER->delete_identity($iid)) { 
     35  $deleted = !$plugin['abort'] ? $USER->delete_identity($iid) : $plugin['result']; 
     36 
     37  if ($deleted) 
    3638    $OUTPUT->show_message('deletedsuccessfully', 'confirmation', null, false); 
    37   } 
    38   else { 
    39     $OUTPUT->show_message('nodeletelastidentity', 'error', null, false); 
    40   } 
     39  else 
     40    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'nodeletelastidentity', 'error', null, false); 
     41 
    4142  // send response 
    4243  if ($OUTPUT->ajax_call) 
     
    4950// go to identities page 
    5051rcmail_overwrite_action('identities'); 
    51  
    52  
  • trunk/roundcubemail/program/steps/settings/save_identity.inc

    r4009 r4025  
    8484    $save_data['reply-to'] = idn_to_ascii($save_data['reply-to']); 
    8585 
    86   if (!$plugin['abort'] && ($updated = $USER->update_identity($iid, $save_data))) 
    87   { 
     86  if (!$plugin['abort']) 
     87    $updated = $USER->update_identity($iid, $save_data); 
     88  else 
     89    $updated = $plugin['result']; 
     90 
     91  if ($updated) { 
    8892    $OUTPUT->show_message('successfullysaved', 'confirmation'); 
    89      
     93 
    9094    if (!empty($_POST['_standard'])) 
    9195      $default_id = get_input_value('_iid', RCUBE_INPUT_POST); 
    92      
    93     if ($_POST['_framed']) 
    94     { 
     96 
     97    if ($_POST['_framed']) { 
    9598      // update the changed col in list 
    9699      // ... 
    97100    } 
    98101  } 
    99   else if ($plugin['abort'] || $DB->is_error()) 
    100   { 
     102  else { 
    101103    // show error message 
    102     $OUTPUT->show_message('errorsaving', 'error', null, false); 
     104    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
    103105    rcmail_overwrite_action('edit-identity'); 
    104106    return; 
     
    119121  $save_data['reply-to'] = idn_to_ascii($save_data['reply-to']); 
    120122 
    121   if (!$plugin['abort'] && $save_data['email'] && ($insert_id = $USER->insert_identity($save_data))) 
    122   { 
     123  if (!$plugin['abort']) 
     124    $insert_id = $save_data['email'] ? $USER->insert_identity($save_data) : null; 
     125  else 
     126    $insert_id = $plugin['result']; 
     127 
     128  if ($insert_id) { 
    123129    $OUTPUT->show_message('successfullysaved', 'confirmation', null, false); 
    124130     
     
    128134      $default_id = $insert_id; 
    129135  } 
    130   else 
    131   { 
     136  else { 
    132137    // show error message 
    133     $OUTPUT->show_message('errorsaving', 'error', null, false); 
     138    $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); 
    134139    rcmail_overwrite_action('edit-identity'); 
    135140    return; 
     
    146151// go to next step 
    147152rcmail_overwrite_action('identities'); 
    148  
    149  
Note: See TracChangeset for help on using the changeset viewer.