Changeset 478 in subversion


Ignore:
Timestamp:
Feb 13, 2007 12:10:57 PM (6 years ago)
Author:
till
Message:
  • some changes
Location:
branches/devel-vnext
Files:
3 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-vnext/index.php

    r473 r478  
    11<?php 
     2die('deprecated'); 
    23/* 
    34 +-----------------------------------------------------------------------+ 
  • branches/devel-vnext/json.php

    r476 r478  
    11<?php 
    22// RC STUFF 
    3 require_once dirname(__FILE__) . '/etc/main.cfg.php'; 
    4  
    5 $sj = new Services_JSON; 
    6 if (Pear::isError($sj)) 
    7 { 
    8     die('Unexpected error.'); 
    9 } 
    10  
    11 $component = ((isset($_REQUEST['component']) && !empty($_REQUEST['component']))?$_REQUEST['component']:null); 
    12 if (is_null($component)) 
    13 { 
    14     echo $sj->encode('error'); 
    15     exit; 
    16 } 
    17 $action = ((isset($_REQUEST['action']) && !empty($_REQUEST['action']))?$_REQUEST['action']:null); 
    18 if (is_null($action)) 
    19 { 
    20     echo $sh->encode('error'); 
    21     exit; 
    22 } 
    23  
    24 $call = sprintf('%s.%s', $component, $action); 
    25  
    26 $err    = null; 
     3require_once dirname(__FILE__) . '/program/etc/main.cfg.php'; 
    274 
    285try 
     
    329catch(rcException $e) 
    3310{ 
    34     var_dump($e); 
     11    echo $e->getMessage(); 
    3512    exit; 
    3613} 
    3714 
    38 function sendError($reason, $token, $data = null) 
     15$component = rcCore::get_input_value('component', RCUBE_INPUT_GET); 
     16if (is_null($component)) 
    3917{ 
    40     $errObj = new stdClass; 
    41     $errObj->status = 'failure'; 
    42     $errObj->reason = $reason; 
    43     $errObj->token  = $token; 
    44     $errObj->data   = $data; 
    45  
    46     return $GLOBALS['sj']->encode($errObj); 
     18    echo $rcCore->sendError('unknown', 'Unknown component.'); 
     19    exit; 
    4720} 
    48  
    49 function sendSuccess($token, $data) 
     21$action = rcCore::get_input_value('action', RCUBE_INPUT_GET); 
     22if (is_null($action)) 
    5023{ 
    51     $respObj = new stdClass; 
    52     $respObj->status = 'ok'; 
    53     $respObj->token  = $token; 
    54     $respObj->data   = $data; 
    55  
    56     return $GLOBALS['sj']->encode($respObj); 
     24    echo $rcCore->sendError($component, 'Unknown action.'); 
     25    exit; 
    5726} 
    58  
     27/* 
     28$json = rcCore::get_input_value('json', RCUBE_INPUT_GPC); 
     29if (!is_null($json)) 
     30{ 
     31    echo $rcCore->sendError($component, 'No JSON calls supplied.'); 
     32} 
     33*/ 
     34$call = sprintf('%s.%s', $component, $action); 
     35$err  = null; 
    5936 
    6037switch($call) 
    6138{ 
    6239    default: 
    63         if (empty($call)): 
    64             $err = array(0 => 'No action'); 
    65         else: 
    66             $err = array(0 => $action); 
    67         endif; 
    68         echo $sj->encode($err); 
     40        echo $rcCore->sendError($component, sprintf('Unknown component/action: %s', $call)); 
    6941        break; 
    7042 
    7143    case 'formauth.login': 
    72         $r = '[ { _user: "foo", _pass: "bar", _host: "" } ]'; 
    73         $data = $sj->decode($r); 
     44        $data = $rcCore->json->decode($json); 
    7445 
    7546        $_user = $data[0]->_user; 
     
    7748        $_host = $data[0]->_host; 
    7849 
    79         $host = ((isset($_host) && !empty($_host))?$_host:$rcCore->CONFIG['default_host']); 
     50        $host = ((isset($_host) && !empty($_host))?$_host:null); 
    8051 
    8152        try 
     
    8657        catch(rcException $e) 
    8758        { 
    88             var_dump($e); exit; 
     59            echo $rcCore->sendError($component, $e->getMessage()); 
     60            exit; 
    8961        } 
    90         var_dump($status); 
     62        if ($status === false) 
     63        { 
     64            echo $rcCore->sendError($component, 'Unknown response from login.'); 
     65        } 
     66        echo $status; 
    9167        break; 
    9268 
    93     /* 
    94     case 'brennan': 
     69    case 'webmail.deleteMessage': 
    9570        $o = new stdClass; 
    96         $o->developer = true; 
    97         $o->location = 'U.S.'; 
    98         $o->props = array('gender' => 'male', 'skin' => 'white'); 
    99         echo $sj->encode($o); 
     71        $o->requests = new stdClass; 
     72         
     73        $a = array(); 
     74         
     75        $ao = new stdClass; 
     76        $ao->component  = 'webmail'; 
     77        $ao->action     = 'deleteMessage'; 
     78        $ao->messageId  = '123'; 
     79        $ao->mailbox    = 'INBOX'; 
     80 
     81        $a[] = $ao; 
     82 
     83        $ao = new stdClass; 
     84        $ao->component  = 'webmail'; 
     85        $ao->action     = 'deleteMessage'; 
     86        $ao->messageId  = '456'; 
     87        $ao->mailbox    = 'INBOX'; 
     88 
     89        $a[] = $ao; 
     90 
     91        $o->requests = $a; 
     92 
     93        var_dump($o->requests); exit; 
     94 
     95 
     96        $data = $rcCore->decode($json); 
     97        try  
     98        { 
     99            $status = $rcCore->imap_deleteMessages($uids, $mailbox); 
     100        } 
     101        catch(rcException $e) 
     102        { 
     103            echo $rcCore->sendError($component, $e->getMessage()); 
     104        } 
     105        echo $status; 
    100106        break; 
    101107 
    102     case 'till': 
    103         $a = array('this', 'is', 'till'); 
    104         echo $sj->encode($a); 
     108    case 'webmail.getUpdates': 
     109        $data = $rcCore->decode($json); 
     110        try 
     111        { 
     112            $status = $rcCore->imap_getMessages($mailbox); 
     113        } 
     114        catch(rcException $e) 
     115        { 
     116            echo $rcCore->sendError($component, $e->getMessage()); 
     117        } 
    105118        break; 
    106  
    107     case 'instructions': 
    108         $a = array(); 
    109  
    110         $o = new stdClass; 
    111         $o->instruction = 'addControlTrayButton'; 
    112         $o->name = 'Four'; 
    113         $o->action = 'alert("4");'; 
    114         $a[] = $o; 
    115  
    116         $o = new stdClass; 
    117         $o->instruction = 'addControlTrayButton'; 
    118         $o->name = 'Five'; 
    119         $o->action = 'alert("5");'; 
    120         $a[] = $o; 
    121  
    122         $o = new stdClass; 
    123         $o->instruction = 'addControlTrayButton'; 
    124         $o->name = 'Six'; 
    125         $o->action = 'alert("6");'; 
    126         $a[] = $o; 
    127  
    128         echo $sj->encode($a); 
    129         break; 
    130     */ 
    131119} 
    132120?> 
  • branches/devel-vnext/program/include/main.inc.php

    r476 r478  
    2323 * rcException 
    2424 * 
    25  * @uses Pear_Exception 
     25 * @author Till Klampaeckel <klampaeckel@lagged.de> 
     26 * @desc   Wrapper to possibly add more methods later on. 
     27 * @uses   Pear_Exception 
    2628 */ 
    2729class rcException extends PEAR_Exception { } 
     
    3436include_once('config/main.inc.php'); 
    3537include_once('config/db.inc.php'); 
     38include_once('program/include/session.inc'); 
     39 
    3640 
    3741// define constannts for input reading 
     
    4246/** 
    4347 * rcCore 
     48 * 
     49 * @author Thomas Bruederli <roundcube@gmail.com> 
     50 * @author Till Klampaeckel <klampaeckel@lagged.de> 
     51 * @desc   Container for most rcmail_*() and rcube_*() calls 
     52 * @uses   Services_JSON 
     53 * @see    rcException 
     54 * @todo   A lot! 
     55 * @since  vNext 
    4456 */ 
    4557class rcCore 
     
    6173    var $sess_user_lang; 
    6274 
     75    var $json; 
     76 
     77    /** 
     78     * enforce calling of factory method 
     79     */ 
    6380    private function __construct() {} 
    6481 
     82    /** 
     83     * PHP4 equivalent to __construct 
     84     */ 
     85    function rcCore() {} 
     86 
    6587    // TODO: remove references to $GLOBALS 
     88    // TODO: check for PHP5 json extension and use it instead of Services_JSON 
     89    /** 
     90     * factory 
     91     * 
     92     * @access static 
     93     * @return mixed  rcException or rcCore class object 
     94     */ 
    6695    static function factory() 
    6796    { 
    6897        //var_dump($GLOBALS['rcmail_config']); 
     98        //throw new rcException('Error: this is a test'); 
     99 
     100        $json = new Services_JSON; 
     101        if (Services_JSON::isError($json)) 
     102        { 
     103            throw new rcException($json->getMessage()); 
     104        } 
     105        if (!is_object($json)) 
     106        { 
     107            throw new rcException('Could not initialize "Services_JSON"'); 
     108        } 
    69109 
    70110        $cls = new rcCore; 
     111 
     112        $cls->json = $json; 
     113 
    71114        $cls->CONFIG = (isset($GLOBALS['rc_mail_config']) && is_array($GLOBALS['rcmail_config'])) ? $GLOBALS['rcmail_config'] : array(); 
    72115        $cls->CONFIG['skin_path'] = isset($cls->CONFIG['skin_path']) && !empty($cls->CONFIG['skin_path']) ? rcMisc::unslashify($cls->CONFIG['skin_path']) : 'skins/default'; 
     
    99142            ini_set('display_errors', 0); 
    100143        } 
    101  
     144         
    102145        // set session garbage collecting time according to session_lifetime 
    103146        if (!empty($cls->CONFIG['session_lifetime'])) 
     
    124167        $cls->DB = $DB; 
    125168 
     169        $rcSession = rcSession::factory($DB); 
     170 
    126171        // we can use the database for storing session data 
    127         include_once('include/session.inc'); 
     172        //include_once('include/session.inc'); 
    128173        //return 'foo'; 
    129174        //session_start(); 
     
    134179         
    135180        return $cls; 
     181    } 
     182 
     183    /** 
     184     * sendError 
     185     * 
     186     * @access public 
     187     * @param  string $component 
     188     * @param  string $reason 
     189     * @return JSON 
     190     * @since  vNext 
     191     */ 
     192    public function sendError($component, $reason) 
     193    { 
     194        $errObj = new stdClass; 
     195        $errObj->status = 'failure'; 
     196 
     197        if (!is_array($component)) 
     198        { 
     199            $component = array($component); 
     200        } 
     201        if (!is_array($reason)) 
     202        { 
     203            $reason = array($reason); 
     204        } 
     205 
     206        $errObj->responses    = array(); 
     207        for ($i=0; $i<count($component); $i++) 
     208        { 
     209            $errObj->responses[$i] = new stdClass; 
     210            $errObj->responses[$i]->component = $component[$i]; 
     211            $errObj->responses[$i]->actions   = array( 
     212                                                'action' => 'showWarning', 
     213                                                'warning' => ((isset($reason[$i]) && !empty($reason[$i]))?$reason[$i]:'unknown') 
     214            ); 
     215        } 
     216        return $this->json->encode($errObj); 
     217    } 
     218 
     219    /** 
     220     * sendSuccess 
     221     * 
     222     * @access public 
     223     * @param  string $token 
     224     * @param  array  $data 
     225     * @return JSON 
     226     * @since  vNext 
     227     */ 
     228    function sendSuccess($component, $data) 
     229    { 
     230        $respObj = new stdClass; 
     231        $respObj->status = 'ok'; 
     232        $respObj->responses = array(); 
     233 
     234        $o = new stdClass; 
     235        $o->component = $component; 
     236        $o->actions   = $data; 
     237 
     238        $respObj->responses[] = $o; 
     239 
     240        return $this->json->encode($respObj); 
    136241    } 
    137242 
     
    327432    } 
    328433 
    329  
    330     // return correct name for a specific database table 
     434    /** 
     435     * return correct name for a specific database table 
     436     * 
     437     * @access static, protected 
     438     * @param  string $table 
     439     * @return string $table 
     440     */ 
    331441    function get_table_name($table) 
    332442    { 
     443        $cls = null; 
     444        if (!isset($this) || !is_object($this)) 
     445        { 
     446            $cls = rcCore::factory(); 
     447        } 
     448        else 
     449        { 
     450            $cls = $this; 
     451        } 
    333452        // return table name if configured 
    334453        $config_key = 'db_table_' . $table; 
    335454 
    336         if (strlen($this->CONFIG[$config_key])) 
    337             return $this->CONFIG[$config_key]; 
     455        if (strlen($cls->CONFIG[$config_key])) 
     456        { 
     457            return $cls->CONFIG[$config_key]; 
     458        } 
    338459   
    339460        return $table; 
     
    576697        // exit if IMAP login failed 
    577698        if (!($imap_login  = $this->IMAP->connect($host, $user, $pass, $imap_port, $imap_ssl))) 
    578             return FALSE; 
     699        { 
     700            return $this->sendError('formauth', sprintf('Could not connect to IMAP server: %s', $host)); 
     701        } 
    579702 
    580703        // user already registered 
     
    620743            $this->IMAP->create_default_folders(); 
    621744 
    622             return TRUE; 
    623         } 
    624         return FALSE; 
     745            $actions = array(); 
     746 
     747            $data             = new stdClass; 
     748            $data->action     = 'confirmLogin'; 
     749            $data->token      = 'foo'; 
     750            $data->expiration = 'foo'; 
     751 
     752            $actions[] = $data; 
     753 
     754            return $this->sendSuccess('formauth', $actions); 
     755        } 
     756        return $this->sendError('formauth', 'Could not login.'); 
    625757    } 
    626758 
     
    11381270     * Performs stripslashes() and charset conversion if necessary 
    11391271     *  
     1272     * @access static 
    11401273     * @param  string   Field name to read 
    11411274     * @param  int      Source to get value from (GPC) 
     
    11711304   
    11721305        // convert to internal charset 
    1173         if (is_object($this->OUTPUT)) 
    1174             return rcube_charset_convert($value, $this->OUTPUT->get_charset(), $charset); 
     1306        /*if (is_object($this->OUTPUT)) 
     1307            return $this->rcube_charset_convert($value, $this->OUTPUT->get_charset(), $charset); 
    11751308        else 
    11761309            return $value; 
     1310        */ 
     1311        return $value; 
    11771312    } 
    11781313 
     
    17801915 
    17811916 
     1917    /** 
     1918     * @deprecated vNext - 2007/02/07 
     1919     */ 
    17821920    // return code for the webmail login form 
    17831921    function rcmail_login_form($attrib) 
     
    18511989 
    18521990 
     1991    /** 
     1992     * @deprecated vNext - 2007/02/12 
     1993     */ 
    18531994    function rcmail_charset_selector($attrib) 
    18541995    { 
     
    19062047        console(sprintf("%s: %0.4f sec", $label, $diff)); 
    19072048    } 
     2049 
     2050    /** 
     2051     * imap_delete_messages 
     2052     * 
     2053     * Wrapper for delete_message call to internal IMAP object. 
     2054     * 
     2055     * @access public 
     2056     * @param  mixed  $uids 
     2057     * @param  string $mailbox 
     2058     * @see    rcube_imap::delete_message 
     2059     * @return mixed 
     2060     * @since  vNext 
     2061     */ 
     2062    public function imap_delete_messages($uids, $mailbox='') 
     2063    { 
     2064        if (empty($uids)) 
     2065        { 
     2066            throw new rcException('No message ids.'); 
     2067        } 
     2068        if (!is_array($uids) && strstr($uids, ',') !== false) 
     2069        { 
     2070            $uids = explode(',', $uids); 
     2071        } 
     2072        if (!is_array($uids)) 
     2073        { 
     2074            $uids = array($uids); 
     2075        } 
     2076        $this->IMAP->delete_message($uids, $mbox_name=''); 
     2077 
     2078        $actions = array();  
     2079    
     2080        for ($i=0; $i<count($uids); $i++) 
     2081        { 
     2082            $data             = new stdClass; 
     2083            $data->action     = 'confirmDeleteMessage'; 
     2084            $data->messageId  = $uids[$i]; 
     2085 
     2086            $actions[] = $data; 
     2087        } 
     2088        return $this->sendSuccess('webmail', $actions); 
     2089    } 
     2090 
     2091    /** 
     2092     * @access public 
     2093     * @todo   Implement 
     2094     * @since  vNext 
     2095     */ 
     2096    function imap_get_messages($mailbox) 
     2097    { 
     2098        return true; 
     2099    } 
    19082100} 
    19092101?> 
Note: See TracChangeset for help on using the changeset viewer.