Changeset 3170 in subversion
- Timestamp:
- Dec 9, 2009 3:18:47 AM (3 years ago)
- Location:
- trunk/roundcubemail
- Files:
-
- 6 edited
-
CHANGELOG (modified) (1 diff)
-
program/include/rcube_json_output.php (modified) (2 diffs)
-
program/include/rcube_shared.inc (modified) (1 diff)
-
program/include/rcube_template.php (modified) (1 diff)
-
program/steps/mail/compose.inc (modified) (1 diff)
-
program/steps/mail/func.inc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/roundcubemail/CHANGELOG
r3166 r3170 2 2 =========================== 3 3 4 - Use built-in json_encode() for proper JSON format in AJAX replies 4 5 - Allow setting only selected params in 'message_compose' hook (#1486312) 5 6 - Plugin API: added 'message_compose_body' hook (#1486285) -
trunk/roundcubemail/program/include/rcube_json_output.php
r2905 r3170 240 240 $response['callbacks'] = $this->callbacks; 241 241 242 echo json_ serialize($response);242 echo json_encode($response); 243 243 } 244 244 … … 256 256 $method = array_shift($args); 257 257 foreach ($args as $i => $arg) { 258 $args[$i] = json_ serialize($arg);258 $args[$i] = json_encode($arg); 259 259 } 260 260 -
trunk/roundcubemail/program/include/rcube_shared.inc
r3132 r3170 106 106 exit; 107 107 } 108 }109 110 111 /**112 * Returns whether an $str is a reserved word for any of the version of Javascript or ECMAScript113 * @param str String to check114 * @return boolean True if $str is a reserver word, False if not115 */116 function is_js_reserved_word($str)117 {118 return in_array($str, array(119 // ECMASript ver 4 reserved words120 'as','break','case','catch','class','const','continue',121 'default','delete','do','else','export','extends','false','finally','for','function',122 'if','import','in','instanceof','is','namespace','new','null','package','private',123 'public','return','super','switch','this','throw','true','try','typeof','use','var',124 'void','while','with',125 // ECMAScript ver 4 future reserved words126 'abstract','debugger','enum','goto','implements','interface','native','protected',127 'synchronized','throws','transient','volatile',128 // special meaning in some contexts129 'get','set',130 // were reserved in ECMAScript ver 3131 'boolean','byte','char','double','final','float','int','long','short','static'132 ));133 }134 135 136 /**137 * Convert a variable into a javascript object notation138 *139 * @param mixed Input value140 * @return string Serialized JSON string141 */142 function json_serialize($var)143 {144 if (is_object($var))145 $var = get_object_vars($var);146 147 if (is_array($var))148 {149 // empty array150 if (!sizeof($var))151 return '[]';152 else153 {154 $keys_arr = array_keys($var);155 $is_assoc = $have_numeric = 0;156 157 for ($i=0; $i<sizeof($keys_arr); ++$i)158 {159 if (is_numeric($keys_arr[$i]))160 $have_numeric = 1;161 if (!is_numeric($keys_arr[$i]) || $keys_arr[$i] != $i)162 $is_assoc = 1;163 if ($is_assoc && $have_numeric)164 break;165 }166 167 $brackets = $is_assoc ? '{}' : '[]';168 $pairs = array();169 170 foreach ($var as $key => $value)171 {172 // enclose key with quotes if it is not variable-name conform173 if (!preg_match('/^[_a-zA-Z]{1}[_a-zA-Z0-9]*$/', $key) || is_js_reserved_word($key))174 $key = "'$key'";175 176 $pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value));177 }178 179 return $brackets{0} . implode(',', $pairs) . $brackets{1};180 }181 }182 else if (!is_string($var) && strval(intval($var)) === strval($var))183 return $var;184 else if (is_bool($var))185 return $var ? '1' : '0';186 else187 return "'".JQ($var)."'";188 }189 190 191 /**192 * Function to convert an array to a javascript array193 * Actually an alias function for json_serialize()194 * @deprecated195 */196 function array2js($arr, $type='')197 {198 return json_serialize($arr);199 108 } 200 109 -
trunk/roundcubemail/program/include/rcube_template.php
r2980 r3170 415 415 $out = ''; 416 416 if (!$this->framed && !empty($this->js_env)) { 417 $out .= JS_OBJECT_NAME . '.set_env('.json_ serialize($this->js_env).");\n";417 $out .= JS_OBJECT_NAME . '.set_env('.json_encode($this->js_env).");\n"; 418 418 } 419 419 foreach ($this->js_commands as $i => $args) { 420 420 $method = array_shift($args); 421 421 foreach ($args as $i => $arg) { 422 $args[$i] = json_ serialize($arg);422 $args[$i] = json_encode($arg); 423 423 } 424 424 $parent = $this->framed || preg_match('/^parent\./', $method); -
trunk/roundcubemail/program/steps/mail/compose.inc
r3166 r3170 507 507 JQ(Q(rcube_label('revertto'))), 508 508 JQ(Q(rcube_label('nospellerrors'))), 509 json_ serialize($spellcheck_langs),509 json_encode($spellcheck_langs), 510 510 $lang, 511 511 $attrib['id'], -
trunk/roundcubemail/program/steps/mail/func.inc
r3099 r3170 523 523 if (is_array($quota)) { 524 524 $OUTPUT->add_script('$(document).ready(function(){ 525 rcmail.set_quota('.json_ serialize($quota).')});', 'foot');525 rcmail.set_quota('.json_encode($quota).')});', 'foot'); 526 526 $quota = ''; 527 527 }
Note: See TracChangeset
for help on using the changeset viewer.
