Changeset 478 in subversion
- Timestamp:
- Feb 13, 2007 12:10:57 PM (6 years ago)
- Location:
- branches/devel-vnext
- Files:
-
- 3 added
- 2 deleted
- 3 edited
-
etc (deleted)
-
index.php (modified) (1 diff)
-
json.php (modified) (4 diffs)
-
program/etc (added)
-
program/etc/main.cfg.php (added)
-
program/include/main.inc.php (modified) (15 diffs)
-
program/include/rcube_imap.inc (deleted)
-
program/include/rcube_imap.inc.php (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-vnext/index.php
r473 r478 1 1 <?php 2 die('deprecated'); 2 3 /* 3 4 +-----------------------------------------------------------------------+ -
branches/devel-vnext/json.php
r476 r478 1 1 <?php 2 2 // 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; 3 require_once dirname(__FILE__) . '/program/etc/main.cfg.php'; 27 4 28 5 try … … 32 9 catch(rcException $e) 33 10 { 34 var_dump($e);11 echo $e->getMessage(); 35 12 exit; 36 13 } 37 14 38 function sendError($reason, $token, $data = null) 15 $component = rcCore::get_input_value('component', RCUBE_INPUT_GET); 16 if (is_null($component)) 39 17 { 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; 47 20 } 48 49 function sendSuccess($token, $data)21 $action = rcCore::get_input_value('action', RCUBE_INPUT_GET); 22 if (is_null($action)) 50 23 { 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; 57 26 } 58 27 /* 28 $json = rcCore::get_input_value('json', RCUBE_INPUT_GPC); 29 if (!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; 59 36 60 37 switch($call) 61 38 { 62 39 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)); 69 41 break; 70 42 71 43 case 'formauth.login': 72 $r = '[ { _user: "foo", _pass: "bar", _host: "" } ]'; 73 $data = $sj->decode($r); 44 $data = $rcCore->json->decode($json); 74 45 75 46 $_user = $data[0]->_user; … … 77 48 $_host = $data[0]->_host; 78 49 79 $host = ((isset($_host) && !empty($_host))?$_host: $rcCore->CONFIG['default_host']);50 $host = ((isset($_host) && !empty($_host))?$_host:null); 80 51 81 52 try … … 86 57 catch(rcException $e) 87 58 { 88 var_dump($e); exit; 59 echo $rcCore->sendError($component, $e->getMessage()); 60 exit; 89 61 } 90 var_dump($status); 62 if ($status === false) 63 { 64 echo $rcCore->sendError($component, 'Unknown response from login.'); 65 } 66 echo $status; 91 67 break; 92 68 93 /* 94 case 'brennan': 69 case 'webmail.deleteMessage': 95 70 $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; 100 106 break; 101 107 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 } 105 118 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 */131 119 } 132 120 ?> -
branches/devel-vnext/program/include/main.inc.php
r476 r478 23 23 * rcException 24 24 * 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 26 28 */ 27 29 class rcException extends PEAR_Exception { } … … 34 36 include_once('config/main.inc.php'); 35 37 include_once('config/db.inc.php'); 38 include_once('program/include/session.inc'); 39 36 40 37 41 // define constannts for input reading … … 42 46 /** 43 47 * 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 44 56 */ 45 57 class rcCore … … 61 73 var $sess_user_lang; 62 74 75 var $json; 76 77 /** 78 * enforce calling of factory method 79 */ 63 80 private function __construct() {} 64 81 82 /** 83 * PHP4 equivalent to __construct 84 */ 85 function rcCore() {} 86 65 87 // 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 */ 66 95 static function factory() 67 96 { 68 97 //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 } 69 109 70 110 $cls = new rcCore; 111 112 $cls->json = $json; 113 71 114 $cls->CONFIG = (isset($GLOBALS['rc_mail_config']) && is_array($GLOBALS['rcmail_config'])) ? $GLOBALS['rcmail_config'] : array(); 72 115 $cls->CONFIG['skin_path'] = isset($cls->CONFIG['skin_path']) && !empty($cls->CONFIG['skin_path']) ? rcMisc::unslashify($cls->CONFIG['skin_path']) : 'skins/default'; … … 99 142 ini_set('display_errors', 0); 100 143 } 101 144 102 145 // set session garbage collecting time according to session_lifetime 103 146 if (!empty($cls->CONFIG['session_lifetime'])) … … 124 167 $cls->DB = $DB; 125 168 169 $rcSession = rcSession::factory($DB); 170 126 171 // we can use the database for storing session data 127 include_once('include/session.inc');172 //include_once('include/session.inc'); 128 173 //return 'foo'; 129 174 //session_start(); … … 134 179 135 180 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); 136 241 } 137 242 … … 327 432 } 328 433 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 */ 331 441 function get_table_name($table) 332 442 { 443 $cls = null; 444 if (!isset($this) || !is_object($this)) 445 { 446 $cls = rcCore::factory(); 447 } 448 else 449 { 450 $cls = $this; 451 } 333 452 // return table name if configured 334 453 $config_key = 'db_table_' . $table; 335 454 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 } 338 459 339 460 return $table; … … 576 697 // exit if IMAP login failed 577 698 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 } 579 702 580 703 // user already registered … … 620 743 $this->IMAP->create_default_folders(); 621 744 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.'); 625 757 } 626 758 … … 1138 1270 * Performs stripslashes() and charset conversion if necessary 1139 1271 * 1272 * @access static 1140 1273 * @param string Field name to read 1141 1274 * @param int Source to get value from (GPC) … … 1171 1304 1172 1305 // 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); 1175 1308 else 1176 1309 return $value; 1310 */ 1311 return $value; 1177 1312 } 1178 1313 … … 1780 1915 1781 1916 1917 /** 1918 * @deprecated vNext - 2007/02/07 1919 */ 1782 1920 // return code for the webmail login form 1783 1921 function rcmail_login_form($attrib) … … 1851 1989 1852 1990 1991 /** 1992 * @deprecated vNext - 2007/02/12 1993 */ 1853 1994 function rcmail_charset_selector($attrib) 1854 1995 { … … 1906 2047 console(sprintf("%s: %0.4f sec", $label, $diff)); 1907 2048 } 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 } 1908 2100 } 1909 2101 ?>
Note: See TracChangeset
for help on using the changeset viewer.
