Changeset 2209 in subversion


Ignore:
Timestamp:
Jan 1, 2009 1:02:59 PM (4 years ago)
Author:
thomasb
Message:

Add plugin-api implementation from old devel branch

Location:
branches/devel-api
Files:
7 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/config/main.inc.php.dist

    r2195 r2209  
    3535// use this folder to store temp files (must be writeable for apache user) 
    3636$rcmail_config['temp_dir'] = 'temp/'; 
     37 
     38// use this folder to search for plugin sources 
     39$rcmail_config['plugins_dir'] = 'plugins/'; 
     40 
     41// List of active plugins. Add the name of a directory found in 'plugins_dir' 
     42$rcmail_config['plugins'] = array(); 
    3743 
    3844// enable caching of messages and mailbox data in the local database. 
  • branches/devel-api/index.php

    r2121 r2209  
    33 +-------------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                           | 
    5  | Version 0.2-20080829                                                    | 
    6  |                                                                         | 
    7  | Copyright (C) 2005-2008, RoundCube Dev. - Switzerland                   | 
     5 | Version 0.2-20090101                                                    | 
     6 |                                                                         | 
     7 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                   | 
    88 |                                                                         | 
    99 | This program is free software; you can redistribute it and/or modify    | 
     
    7171} 
    7272 
     73 
     74// trigger startup plugin hook 
     75$startup = $RCMAIL->plugins->exec_hook('startup', array('task' => $RCMAIL->task, 'action' => $RCMAIL->action)); 
     76$RCMAIL->set_task($startup['task']); 
     77$RCMAIL->action = $startup['action']; 
     78 
     79 
    7380// try to log in 
    7481if ($RCMAIL->action=='login' && $RCMAIL->task=='mail') { 
    75   $host = $RCMAIL->autoselect_host(); 
     82  $auth = $RCMAIL->plugins->exec_hook('authenticate', array( 
     83    'host' => $RCMAIL->autoselect_host(), 
     84    'user' => trim(get_input_value('_user', RCUBE_INPUT_POST)), 
     85  )) + array('pass' => get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1')); 
    7686   
    7787  // check if client supports cookies 
     
    7989    $OUTPUT->show_message("cookiesdisabled", 'warning'); 
    8090  } 
    81   else if ($_SESSION['temp'] && !empty($_POST['_user']) && !empty($_POST['_pass']) && 
    82            $RCMAIL->login(trim(get_input_value('_user', RCUBE_INPUT_POST), ' '), 
    83               get_input_value('_pass', RCUBE_INPUT_POST, true, 'ISO-8859-1'), $host)) { 
     91  else if ($_SESSION['temp'] && !empty($auth['user']) && !empty($auth['host']) && isset($auth['pass']) &&  
     92            $RCMAIL->login($auth['user'], $auth['pass'], $auth['host'])) { 
    8493    // create new session ID 
    8594    unset($_SESSION['temp']); 
  • branches/devel-api/program/include/main.inc

    r2187 r2209  
    296296function rep_specialchars_output($str, $enctype='', $mode='', $newlines=TRUE) 
    297297  { 
    298   global $OUTPUT; 
    299298  static $html_encode_arr = false; 
    300299  static $js_rep_table = false; 
    301300  static $xml_rep_table = false; 
    302301 
    303   $charset = $OUTPUT->get_charset(); 
     302  $charset = rcmail::get_instance()->config->get('charset', RCMAIL_CHARSET); 
    304303  $is_iso_8859_1 = false; 
    305304  if ($charset == 'ISO-8859-1') { 
  • branches/devel-api/program/include/rcmail.php

    r2188 r2209  
    3838  public $imap; 
    3939  public $output; 
     40  public $plugins; 
    4041  public $task = 'mail'; 
    4142  public $action = ''; 
     
    4849   * This implements the 'singleton' design pattern 
    4950   * 
    50    * @return object qvert The one and only instance 
     51   * @return object rcmail The one and only instance 
    5152   */ 
    5253  static function get_instance() 
     
    8990      openlog($syslog_id, LOG_ODELAY, $syslog_facility); 
    9091    } 
    91                                  
     92 
    9293    // set task and action properties 
    9394    $this->set_task(strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC))); 
     
    132133    if ($this->task == 'mail') 
    133134      $this->imap_init(); 
     135       
     136    // create plugin API and load plugins 
     137    $this->plugins = rcube_plugin_api::get_instance(); 
    134138  } 
    135139   
  • branches/devel-api/program/include/rcube_config.php

    r2126 r2209  
    7575    $this->prop['log_dir'] = $this->prop['log_dir'] ? unslashify($this->prop['log_dir']) : INSTALL_PATH . 'logs'; 
    7676    $this->prop['temp_dir'] = $this->prop['temp_dir'] ? unslashify($this->prop['temp_dir']) : INSTALL_PATH . 'temp'; 
     77    $this->prop['plugins_dir'] = $this->prop['plugins_dir'] ? unslashify($this->prop['plugins_dir']) : INSTALL_PATH . 'plugins'; 
    7778 
    7879    // fix default imap folders encoding 
  • branches/devel-api/program/steps/mail/func.inc

    r2197 r2209  
    626626function rcmail_print_body($part, $p = array()) 
    627627{ 
    628   global $REMOTE_OBJECTS; 
    629    
    630   $p += array('safe' => false, 'plain' => false, 'inline_html' => true); 
     628  global $RCMAIL, $REMOTE_OBJECTS; 
     629   
     630  // trigger plugin hook 
     631  $data = $RCMAIL->plugins->exec_hook('message-body-before', 
     632    array('type' => $part->ctype_secondary, 'body' => $part->body) + $p + array('safe' => false, 'plain' => false, 'inline_html' => true)); 
    631633   
    632634  // convert html to text/plain 
    633   if ($part->ctype_secondary == 'html' && $p['plain']) { 
    634     $txt = new html2text($part->body, false, true); 
     635  if ($data['type'] == 'html' && $data['plain']) { 
     636    $txt = new html2text($data['body'], false, true); 
    635637    $body = $txt->get_text(); 
    636638    $part->ctype_secondary = 'plain'; 
    637639  } 
    638640  // text/html 
    639   else if ($part->ctype_secondary == 'html') { 
    640     $html = $part->body; 
     641  else if ($data['type'] == 'html') { 
     642    $html = $data['body']; 
    641643 
    642644    // special replacements (not properly handled by washtml class) 
     
    676678    $wash_opts = array( 
    677679      'show_washed' => false, 
    678       'allow_remote' => $p['safe'], 
     680      'allow_remote' => $data['safe'], 
    679681      'blocked_src' => "./program/blocked.gif", 
    680682      'charset' => RCMAIL_CHARSET, 
     
    683685    ); 
    684686     
    685     if (!$p['inline_html']) { 
     687    if (!$data['inline_html']) { 
    686688      $wash_opts['html_elements'] = array('html','head','title','body'); 
    687689    } 
     
    696698    $body = $washer->wash($html); 
    697699    $REMOTE_OBJECTS = $washer->extlinks; 
    698  
    699     return $body; 
     700     
     701    $part->ctype_secondary = $data['type']; 
    700702  } 
    701703  // text/enriched 
    702   else if ($part->ctype_secondary=='enriched') { 
     704  else if ($data['type'] == 'enriched') { 
    703705    $part->ctype_secondary = 'html'; 
    704     return Q(enriched_to_html($part->body), 'show'); 
    705   } 
    706   else 
     706    $body = Q(enriched_to_html($data['body']), 'show'); 
     707  } 
     708  else { 
     709    // assert plaintext 
     710    $part->ctype_secondary = $data['type'] = 'plain'; 
    707711    $body = $part->body; 
    708  
    709  
    710   /**** assert plaintext ****/ 
    711  
    712   // make links and email-addresses clickable 
    713   $convert_patterns = $convert_replaces = $replace_strings = array(); 
    714    
    715   $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;'; 
    716   $url_chars_within = '\?\.~,!'; 
    717  
    718   $convert_patterns[] = "/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie"; 
    719   $convert_replaces[] = "rcmail_str_replacement('<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>', \$replace_strings)"; 
    720  
    721   $convert_patterns[] = "/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie"; 
    722   $convert_replaces[] = "rcmail_str_replacement('\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>', \$replace_strings)"; 
    723    
    724   $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie'; 
    725   $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return ".JS_OBJECT_NAME.".command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)"; 
    726    
    727   // search for patterns like links and e-mail addresses 
    728   $body = preg_replace($convert_patterns, $convert_replaces, $body); 
    729  
    730   // split body into single lines 
    731   $a_lines = preg_split('/\r?\n/', $body); 
    732   $quote_level = 0; 
    733  
    734   // colorize quoted parts 
    735   for ($n=0; $n < sizeof($a_lines); $n++) { 
    736     $line = $a_lines[$n]; 
    737     $quotation = ''; 
    738     $q = 0; 
    739      
    740     if (preg_match('/^(>+\s*)+/', $line, $regs)) { 
    741       $q    = strlen(preg_replace('/\s/', '', $regs[0])); 
    742       $line = substr($line, strlen($regs[0])); 
    743  
    744       if ($q > $quote_level) 
    745         $quotation = str_repeat('<blockquote>', $q - $quote_level); 
    746       else if ($q < $quote_level) 
    747         $quotation = str_repeat("</blockquote>", $quote_level - $q); 
    748     } 
    749     else if ($quote_level > 0) 
    750       $quotation = str_repeat("</blockquote>", $quote_level); 
    751  
    752     $quote_level = $q; 
    753     $a_lines[$n] = $quotation . Q($line, 'replace', false);  // htmlquote plaintext 
    754   } 
    755  
    756   // insert the links for urls and mailtos 
    757   $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines)); 
    758  
    759   return html::tag('pre', array(), $body); 
     712  } 
     713 
     714 
     715  if ($part->ctype_secondary == 'plain') { 
     716    // make links and email-addresses clickable 
     717    $convert_patterns = $convert_replaces = $replace_strings = array(); 
     718   
     719    $url_chars = 'a-z0-9_\-\+\*\$\/&%=@#:;'; 
     720    $url_chars_within = '\?\.~,!'; 
     721 
     722    $convert_patterns[] = "/([\w]+):\/\/([a-z0-9\-\.]+[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie"; 
     723    $convert_replaces[] = "rcmail_str_replacement('<a href=\"\\1://\\2\" target=\"_blank\">\\1://\\2</a>', \$replace_strings)"; 
     724 
     725    $convert_patterns[] = "/([^\/:]|\s)(www\.)([a-z0-9\-]{2,}[a-z]{2,4}([$url_chars$url_chars_within]*[$url_chars])?)/ie"; 
     726    $convert_replaces[] = "rcmail_str_replacement('\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>', \$replace_strings)"; 
     727   
     728    $convert_patterns[] = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/ie'; 
     729    $convert_replaces[] = "rcmail_str_replacement('<a href=\"mailto:\\1\" onclick=\"return ".JS_OBJECT_NAME.".command(\'compose\',\'\\1\',this)\">\\1</a>', \$replace_strings)"; 
     730   
     731    // search for patterns like links and e-mail addresses 
     732    $body = preg_replace($convert_patterns, $convert_replaces, $body); 
     733 
     734    // split body into single lines 
     735    $a_lines = preg_split('/\r?\n/', $body); 
     736    $quote_level = 0; 
     737 
     738    // colorize quoted parts 
     739    for ($n=0; $n < sizeof($a_lines); $n++) { 
     740      $line = $a_lines[$n]; 
     741      $quotation = ''; 
     742      $q = 0; 
     743     
     744      if (preg_match('/^(>+\s*)+/', $line, $regs)) { 
     745        $q    = strlen(preg_replace('/\s/', '', $regs[0])); 
     746        $line = substr($line, strlen($regs[0])); 
     747 
     748        if ($q > $quote_level) 
     749          $quotation = str_repeat('<blockquote>', $q - $quote_level); 
     750        else if ($q < $quote_level) 
     751          $quotation = str_repeat("</blockquote>", $quote_level - $q); 
     752      } 
     753      else if ($quote_level > 0) 
     754        $quotation = str_repeat("</blockquote>", $quote_level); 
     755 
     756      $quote_level = $q; 
     757      $a_lines[$n] = $quotation . Q($line, 'replace', false);  // htmlquote plaintext 
     758    } 
     759 
     760    // insert the links for urls and mailtos 
     761    $body = preg_replace("/##string_replacement\{([0-9]+)\}##/e", "\$replace_strings[\\1]", join("\n", $a_lines)); 
     762  } 
     763   
     764  // allow post-processing of the message body 
     765  $data = $RCMAIL->plugins->exec_hook('message-body-after', array('type' => $part->ctype_secondary, 'body' => $body) + $data); 
     766 
     767  return $data['type'] == 'html' ? $data['body'] : html::tag('pre', array(), $data['body']); 
    760768} 
    761769 
Note: See TracChangeset for help on using the changeset viewer.