Zendesk Chat - Version 1.3.8

Version Description

  • Fix throwing of wordpress errors
  • Fix PHP notice ('Notice: Undefined variable: error') on the plugin dashboard
  • Remove unused globals
  • Standardize function names
  • Use _() and _e() for translations
  • Add english language file
  • Added icon assets
Download this release

Release Info

Developer zendesk_official
Plugin Icon 128x128 Zendesk Chat
Version 1.3.8
Comparing to
See all releases

Code changes from version 1.3.7 to 1.3.8

Files changed (5) hide show
  1. JSON.php +822 -804
  2. accountconfig.php +167 -144
  3. languages/zopim.pot +158 -0
  4. readme.txt +11 -3
  5. zopim.php +123 -81
JSON.php CHANGED
@@ -1,807 +1,825 @@
1
  <?php
2
- if(!class_exists('Services_JSON')):
3
- /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
-
5
- /**
6
- * Converts to and from JSON format.
7
- *
8
- * JSON (JavaScript Object Notation) is a lightweight data-interchange
9
- * format. It is easy for humans to read and write. It is easy for machines
10
- * to parse and generate. It is based on a subset of the JavaScript
11
- * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
12
- * This feature can also be found in Python. JSON is a text format that is
13
- * completely language independent but uses conventions that are familiar
14
- * to programmers of the C-family of languages, including C, C++, C#, Java,
15
- * JavaScript, Perl, TCL, and many others. These properties make JSON an
16
- * ideal data-interchange language.
17
- *
18
- * This package provides a simple encoder and decoder for JSON notation. It
19
- * is intended for use with client-side Javascript applications that make
20
- * use of HTTPRequest to perform server communication functions - data can
21
- * be encoded into JSON notation for use in a client-side javascript, or
22
- * decoded from incoming Javascript requests. JSON format is native to
23
- * Javascript, and can be directly eval()'ed with no further parsing
24
- * overhead
25
- *
26
- * All strings should be in ASCII or UTF-8 format!
27
- *
28
- * LICENSE: Redistribution and use in source and binary forms, with or
29
- * without modification, are permitted provided that the following
30
- * conditions are met: Redistributions of source code must retain the
31
- * above copyright notice, this list of conditions and the following
32
- * disclaimer. Redistributions in binary form must reproduce the above
33
- * copyright notice, this list of conditions and the following disclaimer
34
- * in the documentation and/or other materials provided with the
35
- * distribution.
36
- *
37
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
38
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
40
- * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
41
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
42
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
43
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45
- * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
46
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
47
- * DAMAGE.
48
- *
49
- * @category
50
- * @package Services_JSON
51
- * @author Michal Migurski <mike-json@teczno.com>
52
- * @author Matt Knapp <mdknapp[at]gmail[dot]com>
53
- * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
54
- * @copyright 2005 Michal Migurski
55
- * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
56
- * @license http://www.opensource.org/licenses/bsd-license.php
57
- * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
58
- */
59
-
60
- /**
61
- * Marker constant for Services_JSON::decode(), used to flag stack state
62
- */
63
- define('SERVICES_JSON_SLICE', 1);
64
-
65
- /**
66
- * Marker constant for Services_JSON::decode(), used to flag stack state
67
- */
68
- define('SERVICES_JSON_IN_STR', 2);
69
-
70
- /**
71
- * Marker constant for Services_JSON::decode(), used to flag stack state
72
- */
73
- define('SERVICES_JSON_IN_ARR', 3);
74
-
75
- /**
76
- * Marker constant for Services_JSON::decode(), used to flag stack state
77
- */
78
- define('SERVICES_JSON_IN_OBJ', 4);
79
-
80
- /**
81
- * Marker constant for Services_JSON::decode(), used to flag stack state
82
- */
83
- define('SERVICES_JSON_IN_CMT', 5);
84
-
85
- /**
86
- * Behavior switch for Services_JSON::decode()
87
- */
88
- define('SERVICES_JSON_LOOSE_TYPE', 16);
89
-
90
- /**
91
- * Behavior switch for Services_JSON::decode()
92
- */
93
- define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
94
-
95
- /**
96
- * Converts to and from JSON format.
97
- *
98
- * Brief example of use:
99
- *
100
- * <code>
101
- * // create a new instance of Services_JSON
102
- * $json = new Services_JSON();
103
- *
104
- * // convert a complexe value to JSON notation, and send it to the browser
105
- * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
106
- * $output = $json->encode($value);
107
- *
108
- * print($output);
109
- * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
110
- *
111
- * // accept incoming POST data, assumed to be in JSON notation
112
- * $input = file_get_contents('php://input', 1000000);
113
- * $value = $json->decode($input);
114
- * </code>
115
- */
116
- class Services_JSON
117
- {
118
- /**
119
- * constructs a new JSON instance
120
- *
121
- * @param int $use object behavior flags; combine with boolean-OR
122
- *
123
- * possible values:
124
- * - SERVICES_JSON_LOOSE_TYPE: loose typing.
125
- * "{...}" syntax creates associative arrays
126
- * instead of objects in decode().
127
- * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
128
- * Values which can't be encoded (e.g. resources)
129
- * appear as NULL instead of throwing errors.
130
- * By default, a deeply-nested resource will
131
- * bubble up with an error, so all return values
132
- * from encode() should be checked with isError()
133
- */
134
- function Services_JSON($use = 0)
135
- {
136
- $this->use = $use;
137
- }
138
-
139
- /**
140
- * convert a string from one UTF-16 char to one UTF-8 char
141
- *
142
- * Normally should be handled by mb_convert_encoding, but
143
- * provides a slower PHP-only method for installations
144
- * that lack the multibye string extension.
145
- *
146
- * @param string $utf16 UTF-16 character
147
- * @return string UTF-8 character
148
- * @access private
149
- */
150
- function utf162utf8($utf16)
151
- {
152
- // oh please oh please oh please oh please oh please
153
- if(function_exists('mb_convert_encoding')) {
154
- return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
155
- }
156
-
157
- $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
158
-
159
- switch(true) {
160
- case ((0x7F & $bytes) == $bytes):
161
- // this case should never be reached, because we are in ASCII range
162
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
163
- return chr(0x7F & $bytes);
164
-
165
- case (0x07FF & $bytes) == $bytes:
166
- // return a 2-byte UTF-8 character
167
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
168
- return chr(0xC0 | (($bytes >> 6) & 0x1F))
169
- . chr(0x80 | ($bytes & 0x3F));
170
-
171
- case (0xFFFF & $bytes) == $bytes:
172
- // return a 3-byte UTF-8 character
173
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
174
- return chr(0xE0 | (($bytes >> 12) & 0x0F))
175
- . chr(0x80 | (($bytes >> 6) & 0x3F))
176
- . chr(0x80 | ($bytes & 0x3F));
177
- }
178
-
179
- // ignoring UTF-32 for now, sorry
180
- return '';
181
- }
182
-
183
- /**
184
- * convert a string from one UTF-8 char to one UTF-16 char
185
- *
186
- * Normally should be handled by mb_convert_encoding, but
187
- * provides a slower PHP-only method for installations
188
- * that lack the multibye string extension.
189
- *
190
- * @param string $utf8 UTF-8 character
191
- * @return string UTF-16 character
192
- * @access private
193
- */
194
- function utf82utf16($utf8)
195
- {
196
- // oh please oh please oh please oh please oh please
197
- if(function_exists('mb_convert_encoding')) {
198
- return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
199
- }
200
-
201
- switch(strlen($utf8)) {
202
- case 1:
203
- // this case should never be reached, because we are in ASCII range
204
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
205
- return $utf8;
206
-
207
- case 2:
208
- // return a UTF-16 character from a 2-byte UTF-8 char
209
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
210
- return chr(0x07 & (ord($utf8{0}) >> 2))
211
- . chr((0xC0 & (ord($utf8{0}) << 6))
212
- | (0x3F & ord($utf8{1})));
213
-
214
- case 3:
215
- // return a UTF-16 character from a 3-byte UTF-8 char
216
- // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
217
- return chr((0xF0 & (ord($utf8{0}) << 4))
218
- | (0x0F & (ord($utf8{1}) >> 2)))
219
- . chr((0xC0 & (ord($utf8{1}) << 6))
220
- | (0x7F & ord($utf8{2})));
221
- }
222
-
223
- // ignoring UTF-32 for now, sorry
224
- return '';
225
- }
226
-
227
- /**
228
- * encodes an arbitrary variable into JSON format
229
- *
230
- * @param mixed $var any number, boolean, string, array, or object to be encoded.
231
- * see argument 1 to Services_JSON() above for array-parsing behavior.
232
- * if var is a strng, note that encode() always expects it
233
- * to be in ASCII or UTF-8 format!
234
- *
235
- * @return mixed JSON string representation of input var or an error if a problem occurs
236
- * @access public
237
- */
238
- function encode($var)
239
- {
240
- switch (gettype($var)) {
241
- case 'boolean':
242
- return $var ? 'true' : 'false';
243
-
244
- case 'NULL':
245
- return 'null';
246
-
247
- case 'integer':
248
- return (int) $var;
249
-
250
- case 'double':
251
- case 'float':
252
- return (float) $var;
253
-
254
- case 'string':
255
- // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
256
- $ascii = '';
257
- $strlen_var = strlen($var);
258
-
259
- /*
260
- * Iterate over every character in the string,
261
- * escaping with a slash or encoding to UTF-8 where necessary
262
- */
263
- for ($c = 0; $c < $strlen_var; ++$c) {
264
-
265
- $ord_var_c = ord($var{$c});
266
-
267
- switch (true) {
268
- case $ord_var_c == 0x08:
269
- $ascii .= '\b';
270
- break;
271
- case $ord_var_c == 0x09:
272
- $ascii .= '\t';
273
- break;
274
- case $ord_var_c == 0x0A:
275
- $ascii .= '\n';
276
- break;
277
- case $ord_var_c == 0x0C:
278
- $ascii .= '\f';
279
- break;
280
- case $ord_var_c == 0x0D:
281
- $ascii .= '\r';
282
- break;
283
-
284
- case $ord_var_c == 0x22:
285
- case $ord_var_c == 0x2F:
286
- case $ord_var_c == 0x5C:
287
- // double quote, slash, slosh
288
- $ascii .= '\\'.$var{$c};
289
- break;
290
-
291
- case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
292
- // characters U-00000000 - U-0000007F (same as ASCII)
293
- $ascii .= $var{$c};
294
- break;
295
-
296
- case (($ord_var_c & 0xE0) == 0xC0):
297
- // characters U-00000080 - U-000007FF, mask 110XXXXX
298
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
299
- $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
300
- $c += 1;
301
- $utf16 = $this->utf82utf16($char);
302
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
303
- break;
304
-
305
- case (($ord_var_c & 0xF0) == 0xE0):
306
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
307
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
308
- $char = pack('C*', $ord_var_c,
309
- ord($var{$c + 1}),
310
- ord($var{$c + 2}));
311
- $c += 2;
312
- $utf16 = $this->utf82utf16($char);
313
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
314
- break;
315
-
316
- case (($ord_var_c & 0xF8) == 0xF0):
317
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
318
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
319
- $char = pack('C*', $ord_var_c,
320
- ord($var{$c + 1}),
321
- ord($var{$c + 2}),
322
- ord($var{$c + 3}));
323
- $c += 3;
324
- $utf16 = $this->utf82utf16($char);
325
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
326
- break;
327
-
328
- case (($ord_var_c & 0xFC) == 0xF8):
329
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
330
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
331
- $char = pack('C*', $ord_var_c,
332
- ord($var{$c + 1}),
333
- ord($var{$c + 2}),
334
- ord($var{$c + 3}),
335
- ord($var{$c + 4}));
336
- $c += 4;
337
- $utf16 = $this->utf82utf16($char);
338
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
339
- break;
340
-
341
- case (($ord_var_c & 0xFE) == 0xFC):
342
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
343
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
344
- $char = pack('C*', $ord_var_c,
345
- ord($var{$c + 1}),
346
- ord($var{$c + 2}),
347
- ord($var{$c + 3}),
348
- ord($var{$c + 4}),
349
- ord($var{$c + 5}));
350
- $c += 5;
351
- $utf16 = $this->utf82utf16($char);
352
- $ascii .= sprintf('\u%04s', bin2hex($utf16));
353
- break;
354
- }
355
- }
356
-
357
- return '"'.$ascii.'"';
358
-
359
- case 'array':
360
- /*
361
- * As per JSON spec if any array key is not an integer
362
- * we must treat the the whole array as an object. We
363
- * also try to catch a sparsely populated associative
364
- * array with numeric keys here because some JS engines
365
- * will create an array with empty indexes up to
366
- * max_index which can cause memory issues and because
367
- * the keys, which may be relevant, will be remapped
368
- * otherwise.
369
- *
370
- * As per the ECMA and JSON specification an object may
371
- * have any string as a property. Unfortunately due to
372
- * a hole in the ECMA specification if the key is a
373
- * ECMA reserved word or starts with a digit the
374
- * parameter is only accessible using ECMAScript's
375
- * bracket notation.
376
- */
377
-
378
- // treat as a JSON object
379
- if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
380
- $properties = array_map(array($this, 'name_value'),
381
- array_keys($var),
382
- array_values($var));
383
-
384
- foreach($properties as $property) {
385
- if(Services_JSON::isError($property)) {
386
- return $property;
387
- }
388
- }
389
-
390
- return '{' . join(',', $properties) . '}';
391
- }
392
-
393
- // treat it like a regular array
394
- $elements = array_map(array($this, 'encode'), $var);
395
-
396
- foreach($elements as $element) {
397
- if(Services_JSON::isError($element)) {
398
- return $element;
399
- }
400
- }
401
-
402
- return '[' . join(',', $elements) . ']';
403
-
404
- case 'object':
405
- $vars = get_object_vars($var);
406
-
407
- $properties = array_map(array($this, 'name_value'),
408
- array_keys($vars),
409
- array_values($vars));
410
-
411
- foreach($properties as $property) {
412
- if(Services_JSON::isError($property)) {
413
- return $property;
414
- }
415
- }
416
-
417
- return '{' . join(',', $properties) . '}';
418
-
419
- default:
420
- return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
421
- ? 'null'
422
- : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
423
- }
424
- }
425
-
426
- /**
427
- * array-walking function for use in generating JSON-formatted name-value pairs
428
- *
429
- * @param string $name name of key to use
430
- * @param mixed $value reference to an array element to be encoded
431
- *
432
- * @return string JSON-formatted name-value pair, like '"name":value'
433
- * @access private
434
- */
435
- function name_value($name, $value)
436
- {
437
- $encoded_value = $this->encode($value);
438
-
439
- if(Services_JSON::isError($encoded_value)) {
440
- return $encoded_value;
441
- }
442
-
443
- return $this->encode(strval($name)) . ':' . $encoded_value;
444
- }
445
-
446
- /**
447
- * reduce a string by removing leading and trailing comments and whitespace
448
- *
449
- * @param $str string string value to strip of comments and whitespace
450
- *
451
- * @return string string value stripped of comments and whitespace
452
- * @access private
453
- */
454
- function reduce_string($str)
455
- {
456
- $str = preg_replace(array(
457
-
458
- // eliminate single line comments in '// ...' form
459
- '#^\s*//(.+)$#m',
460
-
461
- // eliminate multi-line comments in '/* ... */' form, at start of string
462
- '#^\s*/\*(.+)\*/#Us',
463
-
464
- // eliminate multi-line comments in '/* ... */' form, at end of string
465
- '#/\*(.+)\*/\s*$#Us'
466
-
467
- ), '', $str);
468
-
469
- // eliminate extraneous space
470
- return trim($str);
471
- }
472
-
473
- /**
474
- * decodes a JSON string into appropriate variable
475
- *
476
- * @param string $str JSON-formatted string
477
- *
478
- * @return mixed number, boolean, string, array, or object
479
- * corresponding to given JSON input string.
480
- * See argument 1 to Services_JSON() above for object-output behavior.
481
- * Note that decode() always returns strings
482
- * in ASCII or UTF-8 format!
483
- * @access public
484
- */
485
- function decode($str)
486
- {
487
- $str = $this->reduce_string($str);
488
-
489
- switch (strtolower($str)) {
490
- case 'true':
491
- return true;
492
-
493
- case 'false':
494
- return false;
495
-
496
- case 'null':
497
- return null;
498
-
499
- default:
500
- $m = array();
501
-
502
- if (is_numeric($str)) {
503
- // Lookie-loo, it's a number
504
-
505
- // This would work on its own, but I'm trying to be
506
- // good about returning integers where appropriate:
507
- // return (float)$str;
508
-
509
- // Return float or int, as appropriate
510
- return ((float)$str == (integer)$str)
511
- ? (integer)$str
512
- : (float)$str;
513
-
514
- } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
515
- // STRINGS RETURNED IN UTF-8 FORMAT
516
- $delim = substr($str, 0, 1);
517
- $chrs = substr($str, 1, -1);
518
- $utf8 = '';
519
- $strlen_chrs = strlen($chrs);
520
-
521
- for ($c = 0; $c < $strlen_chrs; ++$c) {
522
-
523
- $substr_chrs_c_2 = substr($chrs, $c, 2);
524
- $ord_chrs_c = ord($chrs{$c});
525
-
526
- switch (true) {
527
- case $substr_chrs_c_2 == '\b':
528
- $utf8 .= chr(0x08);
529
- ++$c;
530
- break;
531
- case $substr_chrs_c_2 == '\t':
532
- $utf8 .= chr(0x09);
533
- ++$c;
534
- break;
535
- case $substr_chrs_c_2 == '\n':
536
- $utf8 .= chr(0x0A);
537
- ++$c;
538
- break;
539
- case $substr_chrs_c_2 == '\f':
540
- $utf8 .= chr(0x0C);
541
- ++$c;
542
- break;
543
- case $substr_chrs_c_2 == '\r':
544
- $utf8 .= chr(0x0D);
545
- ++$c;
546
- break;
547
-
548
- case $substr_chrs_c_2 == '\\"':
549
- case $substr_chrs_c_2 == '\\\'':
550
- case $substr_chrs_c_2 == '\\\\':
551
- case $substr_chrs_c_2 == '\\/':
552
- if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
553
- ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
554
- $utf8 .= $chrs{++$c};
555
- }
556
- break;
557
-
558
- case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
559
- // single, escaped unicode character
560
- $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
561
- . chr(hexdec(substr($chrs, ($c + 4), 2)));
562
- $utf8 .= $this->utf162utf8($utf16);
563
- $c += 5;
564
- break;
565
-
566
- case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
567
- $utf8 .= $chrs{$c};
568
- break;
569
-
570
- case ($ord_chrs_c & 0xE0) == 0xC0:
571
- // characters U-00000080 - U-000007FF, mask 110XXXXX
572
- //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
573
- $utf8 .= substr($chrs, $c, 2);
574
- ++$c;
575
- break;
576
-
577
- case ($ord_chrs_c & 0xF0) == 0xE0:
578
- // characters U-00000800 - U-0000FFFF, mask 1110XXXX
579
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
580
- $utf8 .= substr($chrs, $c, 3);
581
- $c += 2;
582
- break;
583
-
584
- case ($ord_chrs_c & 0xF8) == 0xF0:
585
- // characters U-00010000 - U-001FFFFF, mask 11110XXX
586
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
587
- $utf8 .= substr($chrs, $c, 4);
588
- $c += 3;
589
- break;
590
-
591
- case ($ord_chrs_c & 0xFC) == 0xF8:
592
- // characters U-00200000 - U-03FFFFFF, mask 111110XX
593
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
594
- $utf8 .= substr($chrs, $c, 5);
595
- $c += 4;
596
- break;
597
-
598
- case ($ord_chrs_c & 0xFE) == 0xFC:
599
- // characters U-04000000 - U-7FFFFFFF, mask 1111110X
600
- // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
601
- $utf8 .= substr($chrs, $c, 6);
602
- $c += 5;
603
- break;
604
-
605
- }
606
-
607
- }
608
-
609
- return $utf8;
610
-
611
- } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
612
- // array, or object notation
613
-
614
- if ($str{0} == '[') {
615
- $stk = array(SERVICES_JSON_IN_ARR);
616
- $arr = array();
617
- } else {
618
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
619
- $stk = array(SERVICES_JSON_IN_OBJ);
620
- $obj = array();
621
- } else {
622
- $stk = array(SERVICES_JSON_IN_OBJ);
623
- $obj = new stdClass();
624
- }
625
- }
626
-
627
- array_push($stk, array('what' => SERVICES_JSON_SLICE,
628
- 'where' => 0,
629
- 'delim' => false));
630
-
631
- $chrs = substr($str, 1, -1);
632
- $chrs = $this->reduce_string($chrs);
633
-
634
- if ($chrs == '') {
635
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
636
- return $arr;
637
-
638
- } else {
639
- return $obj;
640
-
641
- }
642
- }
643
-
644
- //print("\nparsing {$chrs}\n");
645
-
646
- $strlen_chrs = strlen($chrs);
647
-
648
- for ($c = 0; $c <= $strlen_chrs; ++$c) {
649
-
650
- $top = end($stk);
651
- $substr_chrs_c_2 = substr($chrs, $c, 2);
652
-
653
- if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
654
- // found a comma that is not inside a string, array, etc.,
655
- // OR we've reached the end of the character list
656
- $slice = substr($chrs, $top['where'], ($c - $top['where']));
657
- array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
658
- //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
659
-
660
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
661
- // we are in an array, so just push an element onto the stack
662
- array_push($arr, $this->decode($slice));
663
-
664
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
665
- // we are in an object, so figure
666
- // out the property name and set an
667
- // element in an associative array,
668
- // for now
669
- $parts = array();
670
-
671
- if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
672
- // "name":value pair
673
- $key = $this->decode($parts[1]);
674
- $val = $this->decode($parts[2]);
675
-
676
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
677
- $obj[$key] = $val;
678
- } else {
679
- $obj->$key = $val;
680
- }
681
- } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
682
- // name:value pair, where name is unquoted
683
- $key = $parts[1];
684
- $val = $this->decode($parts[2]);
685
-
686
- if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
687
- $obj[$key] = $val;
688
- } else {
689
- $obj->$key = $val;
690
- }
691
- }
692
-
693
- }
694
-
695
- } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
696
- // found a quote, and we are not inside a string
697
- array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
698
- //print("Found start of string at {$c}\n");
699
-
700
- } elseif (($chrs{$c} == $top['delim']) &&
701
- ($top['what'] == SERVICES_JSON_IN_STR) &&
702
- ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
703
- // found a quote, we're in a string, and it's not escaped
704
- // we know that it's not escaped becase there is _not_ an
705
- // odd number of backslashes at the end of the string so far
706
- array_pop($stk);
707
- //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
708
-
709
- } elseif (($chrs{$c} == '[') &&
710
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
711
- // found a left-bracket, and we are in an array, object, or slice
712
- array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
713
- //print("Found start of array at {$c}\n");
714
-
715
- } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
716
- // found a right-bracket, and we're in an array
717
- array_pop($stk);
718
- //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
719
-
720
- } elseif (($chrs{$c} == '{') &&
721
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
722
- // found a left-brace, and we are in an array, object, or slice
723
- array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
724
- //print("Found start of object at {$c}\n");
725
-
726
- } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
727
- // found a right-brace, and we're in an object
728
- array_pop($stk);
729
- //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
730
-
731
- } elseif (($substr_chrs_c_2 == '/*') &&
732
- in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
733
- // found a comment start, and we are in an array, object, or slice
734
- array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
735
- $c++;
736
- //print("Found start of comment at {$c}\n");
737
-
738
- } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
739
- // found a comment end, and we're in one now
740
- array_pop($stk);
741
- $c++;
742
-
743
- for ($i = $top['where']; $i <= $c; ++$i)
744
- $chrs = substr_replace($chrs, ' ', $i, 1);
745
-
746
- //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
747
-
748
- }
749
-
750
- }
751
-
752
- if (reset($stk) == SERVICES_JSON_IN_ARR) {
753
- return $arr;
754
-
755
- } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
756
- return $obj;
757
-
758
- }
759
-
760
- }
761
- }
762
- }
763
-
764
- /**
765
- * @todo Ultimately, this should just call PEAR::isError()
766
- */
767
- function isError($data, $code = null)
768
- {
769
- if (class_exists('pear')) {
770
- return PEAR::isError($data, $code);
771
- } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
772
- is_subclass_of($data, 'services_json_error'))) {
773
- return true;
774
- }
775
-
776
- return false;
777
- }
778
- }
779
-
780
- if (class_exists('PEAR_Error')) {
781
-
782
- class Services_JSON_Error extends PEAR_Error
783
- {
784
- function Services_JSON_Error($message = 'unknown error', $code = null,
785
- $mode = null, $options = null, $userinfo = null)
786
- {
787
- parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
788
- }
789
- }
790
-
791
- } else {
792
-
793
- /**
794
- * @todo Ultimately, this class shall be descended from PEAR_Error
795
- */
796
- class Services_JSON_Error
797
- {
798
- function Services_JSON_Error($message = 'unknown error', $code = null,
799
- $mode = null, $options = null, $userinfo = null)
800
- {
801
-
802
- }
803
- }
804
-
805
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
806
  endif;
807
  ?>
1
  <?php
2
+ if ( ! class_exists( 'Services_JSON' ) ):
3
+ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
+
5
+ /**
6
+ * Converts to and from JSON format.
7
+ *
8
+ * JSON (JavaScript Object Notation) is a lightweight data-interchange
9
+ * format. It is easy for humans to read and write. It is easy for machines
10
+ * to parse and generate. It is based on a subset of the JavaScript
11
+ * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
12
+ * This feature can also be found in Python. JSON is a text format that is
13
+ * completely language independent but uses conventions that are familiar
14
+ * to programmers of the C-family of languages, including C, C++, C#, Java,
15
+ * JavaScript, Perl, TCL, and many others. These properties make JSON an
16
+ * ideal data-interchange language.
17
+ *
18
+ * This package provides a simple encoder and decoder for JSON notation. It
19
+ * is intended for use with client-side Javascript applications that make
20
+ * use of HTTPRequest to perform server communication functions - data can
21
+ * be encoded into JSON notation for use in a client-side javascript, or
22
+ * decoded from incoming Javascript requests. JSON format is native to
23
+ * Javascript, and can be directly eval()'ed with no further parsing
24
+ * overhead
25
+ *
26
+ * All strings should be in ASCII or UTF-8 format!
27
+ *
28
+ * LICENSE: Redistribution and use in source and binary forms, with or
29
+ * without modification, are permitted provided that the following
30
+ * conditions are met: Redistributions of source code must retain the
31
+ * above copyright notice, this list of conditions and the following
32
+ * disclaimer. Redistributions in binary form must reproduce the above
33
+ * copyright notice, this list of conditions and the following disclaimer
34
+ * in the documentation and/or other materials provided with the
35
+ * distribution.
36
+ *
37
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
38
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
39
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
40
+ * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
41
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
42
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
43
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
46
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
47
+ * DAMAGE.
48
+ *
49
+ * @category
50
+ * @package Services_JSON
51
+ * @author Michal Migurski <mike-json@teczno.com>
52
+ * @author Matt Knapp <mdknapp[at]gmail[dot]com>
53
+ * @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
54
+ * @copyright 2005 Michal Migurski
55
+ * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
56
+ * @license http://www.opensource.org/licenses/bsd-license.php
57
+ * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
58
+ */
59
+
60
+ /**
61
+ * Marker constant for Services_JSON::decode(), used to flag stack state
62
+ */
63
+ define( 'SERVICES_JSON_SLICE', 1 );
64
+
65
+ /**
66
+ * Marker constant for Services_JSON::decode(), used to flag stack state
67
+ */
68
+ define( 'SERVICES_JSON_IN_STR', 2 );
69
+
70
+ /**
71
+ * Marker constant for Services_JSON::decode(), used to flag stack state
72
+ */
73
+ define( 'SERVICES_JSON_IN_ARR', 3 );
74
+
75
+ /**
76
+ * Marker constant for Services_JSON::decode(), used to flag stack state
77
+ */
78
+ define( 'SERVICES_JSON_IN_OBJ', 4 );
79
+
80
+ /**
81
+ * Marker constant for Services_JSON::decode(), used to flag stack state
82
+ */
83
+ define( 'SERVICES_JSON_IN_CMT', 5 );
84
+
85
+ /**
86
+ * Behavior switch for Services_JSON::decode()
87
+ */
88
+ define( 'SERVICES_JSON_LOOSE_TYPE', 16 );
89
+
90
+ /**
91
+ * Behavior switch for Services_JSON::decode()
92
+ */
93
+ define( 'SERVICES_JSON_SUPPRESS_ERRORS', 32 );
94
+
95
+ /**
96
+ * Converts to and from JSON format.
97
+ *
98
+ * Brief example of use:
99
+ *
100
+ * <code>
101
+ * // create a new instance of Services_JSON
102
+ * $json = new Services_JSON();
103
+ *
104
+ * // convert a complexe value to JSON notation, and send it to the browser
105
+ * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
106
+ * $output = $json->encode($value);
107
+ *
108
+ * print($output);
109
+ * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
110
+ *
111
+ * // accept incoming POST data, assumed to be in JSON notation
112
+ * $input = file_get_contents('php://input', 1000000);
113
+ * $value = $json->decode($input);
114
+ * </code>
115
+ */
116
+ class Services_JSON {
117
+ /**
118
+ * constructs a new JSON instance
119
+ *
120
+ * @param int $use object behavior flags; combine with boolean-OR
121
+ *
122
+ * possible values:
123
+ * - SERVICES_JSON_LOOSE_TYPE: loose typing.
124
+ * "{...}" syntax creates associative arrays
125
+ * instead of objects in decode().
126
+ * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
127
+ * Values which can't be encoded (e.g. resources)
128
+ * appear as NULL instead of throwing errors.
129
+ * By default, a deeply-nested resource will
130
+ * bubble up with an error, so all return values
131
+ * from encode() should be checked with isError()
132
+ */
133
+ function Services_JSON( $use = 0 ) {
134
+ $this->use = $use;
135
+ }
136
+
137
+ /**
138
+ * convert a string from one UTF-16 char to one UTF-8 char
139
+ *
140
+ * Normally should be handled by mb_convert_encoding, but
141
+ * provides a slower PHP-only method for installations
142
+ * that lack the multibye string extension.
143
+ *
144
+ * @param string $utf16 UTF-16 character
145
+ *
146
+ * @return string UTF-8 character
147
+ * @access private
148
+ */
149
+ function utf162utf8( $utf16 ) {
150
+ // oh please oh please oh please oh please oh please
151
+ if ( function_exists( 'mb_convert_encoding' ) ) {
152
+ return mb_convert_encoding( $utf16, 'UTF-8', 'UTF-16' );
153
+ }
154
+
155
+ $bytes = ( ord( $utf16{0} ) << 8 ) | ord( $utf16{1} );
156
+
157
+ switch ( true ) {
158
+ case ( ( 0x7F & $bytes ) == $bytes ):
159
+ // this case should never be reached, because we are in ASCII range
160
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
161
+ return chr( 0x7F & $bytes );
162
+
163
+ case ( 0x07FF & $bytes ) == $bytes:
164
+ // return a 2-byte UTF-8 character
165
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
166
+ return chr( 0xC0 | ( ( $bytes >> 6 ) & 0x1F ) )
167
+ . chr( 0x80 | ( $bytes & 0x3F ) );
168
+
169
+ case ( 0xFFFF & $bytes ) == $bytes:
170
+ // return a 3-byte UTF-8 character
171
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
172
+ return chr( 0xE0 | ( ( $bytes >> 12 ) & 0x0F ) )
173
+ . chr( 0x80 | ( ( $bytes >> 6 ) & 0x3F ) )
174
+ . chr( 0x80 | ( $bytes & 0x3F ) );
175
+ }
176
+
177
+ // ignoring UTF-32 for now, sorry
178
+ return '';
179
+ }
180
+
181
+ /**
182
+ * convert a string from one UTF-8 char to one UTF-16 char
183
+ *
184
+ * Normally should be handled by mb_convert_encoding, but
185
+ * provides a slower PHP-only method for installations
186
+ * that lack the multibye string extension.
187
+ *
188
+ * @param string $utf8 UTF-8 character
189
+ *
190
+ * @return string UTF-16 character
191
+ * @access private
192
+ */
193
+ function utf82utf16( $utf8 ) {
194
+ // oh please oh please oh please oh please oh please
195
+ if ( function_exists( 'mb_convert_encoding' ) ) {
196
+ return mb_convert_encoding( $utf8, 'UTF-16', 'UTF-8' );
197
+ }
198
+
199
+ switch ( strlen( $utf8 ) ) {
200
+ case 1:
201
+ // this case should never be reached, because we are in ASCII range
202
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
203
+ return $utf8;
204
+
205
+ case 2:
206
+ // return a UTF-16 character from a 2-byte UTF-8 char
207
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
208
+ return chr( 0x07 & ( ord( $utf8{0} ) >> 2 ) )
209
+ . chr( ( 0xC0 & ( ord( $utf8{0} ) << 6 ) )
210
+ | ( 0x3F & ord( $utf8{1} ) ) );
211
+
212
+ case 3:
213
+ // return a UTF-16 character from a 3-byte UTF-8 char
214
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
215
+ return chr( ( 0xF0 & ( ord( $utf8{0} ) << 4 ) )
216
+ | ( 0x0F & ( ord( $utf8{1} ) >> 2 ) ) )
217
+ . chr( ( 0xC0 & ( ord( $utf8{1} ) << 6 ) )
218
+ | ( 0x7F & ord( $utf8{2} ) ) );
219
+ }
220
+
221
+ // ignoring UTF-32 for now, sorry
222
+ return '';
223
+ }
224
+
225
+ /**
226
+ * encodes an arbitrary variable into JSON format
227
+ *
228
+ * @param mixed $var any number, boolean, string, array, or object to be encoded.
229
+ * see argument 1 to Services_JSON() above for array-parsing behavior.
230
+ * if var is a strng, note that encode() always expects it
231
+ * to be in ASCII or UTF-8 format!
232
+ *
233
+ * @return mixed JSON string representation of input var or an error if a problem occurs
234
+ * @access public
235
+ */
236
+ function encode( $var ) {
237
+ switch ( gettype( $var ) ) {
238
+ case 'boolean':
239
+ return $var ? 'true' : 'false';
240
+
241
+ case 'NULL':
242
+ return 'null';
243
+
244
+ case 'integer':
245
+ return (int) $var;
246
+
247
+ case 'double':
248
+ case 'float':
249
+ return (float) $var;
250
+
251
+ case 'string':
252
+ // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
253
+ $ascii = '';
254
+ $strlen_var = strlen( $var );
255
+
256
+ /*
257
+ * Iterate over every character in the string,
258
+ * escaping with a slash or encoding to UTF-8 where necessary
259
+ */
260
+ for ( $c = 0; $c < $strlen_var; ++ $c ) {
261
+
262
+ $ord_var_c = ord( $var{$c} );
263
+
264
+ switch ( true ) {
265
+ case $ord_var_c == 0x08:
266
+ $ascii .= '\b';
267
+ break;
268
+ case $ord_var_c == 0x09:
269
+ $ascii .= '\t';
270
+ break;
271
+ case $ord_var_c == 0x0A:
272
+ $ascii .= '\n';
273
+ break;
274
+ case $ord_var_c == 0x0C:
275
+ $ascii .= '\f';
276
+ break;
277
+ case $ord_var_c == 0x0D:
278
+ $ascii .= '\r';
279
+ break;
280
+
281
+ case $ord_var_c == 0x22:
282
+ case $ord_var_c == 0x2F:
283
+ case $ord_var_c == 0x5C:
284
+ // double quote, slash, slosh
285
+ $ascii .= '\\' . $var{$c};
286
+ break;
287
+
288
+ case ( ( $ord_var_c >= 0x20 ) && ( $ord_var_c <= 0x7F ) ):
289
+ // characters U-00000000 - U-0000007F (same as ASCII)
290
+ $ascii .= $var{$c};
291
+ break;
292
+
293
+ case ( ( $ord_var_c & 0xE0 ) == 0xC0 ):
294
+ // characters U-00000080 - U-000007FF, mask 110XXXXX
295
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
296
+ $char = pack( 'C*', $ord_var_c, ord( $var{$c + 1} ) );
297
+ $c += 1;
298
+ $utf16 = $this->utf82utf16( $char );
299
+ $ascii .= sprintf( '\u%04s', bin2hex( $utf16 ) );
300
+ break;
301
+
302
+ case ( ( $ord_var_c & 0xF0 ) == 0xE0 ):
303
+ // characters U-00000800 - U-0000FFFF, mask 1110XXXX
304
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
305
+ $char = pack( 'C*', $ord_var_c,
306
+ ord( $var{$c + 1} ),
307
+ ord( $var{$c + 2} ) );
308
+ $c += 2;
309
+ $utf16 = $this->utf82utf16( $char );
310
+ $ascii .= sprintf( '\u%04s', bin2hex( $utf16 ) );
311
+ break;
312
+
313
+ case ( ( $ord_var_c & 0xF8 ) == 0xF0 ):
314
+ // characters U-00010000 - U-001FFFFF, mask 11110XXX
315
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
316
+ $char = pack( 'C*', $ord_var_c,
317
+ ord( $var{$c + 1} ),
318
+ ord( $var{$c + 2} ),
319
+ ord( $var{$c + 3} ) );
320
+ $c += 3;
321
+ $utf16 = $this->utf82utf16( $char );
322
+ $ascii .= sprintf( '\u%04s', bin2hex( $utf16 ) );
323
+ break;
324
+
325
+ case ( ( $ord_var_c & 0xFC ) == 0xF8 ):
326
+ // characters U-00200000 - U-03FFFFFF, mask 111110XX
327
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
328
+ $char = pack( 'C*', $ord_var_c,
329
+ ord( $var{$c + 1} ),
330
+ ord( $var{$c + 2} ),
331
+ ord( $var{$c + 3} ),
332
+ ord( $var{$c + 4} ) );
333
+ $c += 4;
334
+ $utf16 = $this->utf82utf16( $char );
335
+ $ascii .= sprintf( '\u%04s', bin2hex( $utf16 ) );
336
+ break;
337
+
338
+ case ( ( $ord_var_c & 0xFE ) == 0xFC ):
339
+ // characters U-04000000 - U-7FFFFFFF, mask 1111110X
340
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
341
+ $char = pack( 'C*', $ord_var_c,
342
+ ord( $var{$c + 1} ),
343
+ ord( $var{$c + 2} ),
344
+ ord( $var{$c + 3} ),
345
+ ord( $var{$c + 4} ),
346
+ ord( $var{$c + 5} ) );
347
+ $c += 5;
348
+ $utf16 = $this->utf82utf16( $char );
349
+ $ascii .= sprintf( '\u%04s', bin2hex( $utf16 ) );
350
+ break;
351
+ }
352
+ }
353
+
354
+ return '"' . $ascii . '"';
355
+
356
+ case 'array':
357
+ /*
358
+ * As per JSON spec if any array key is not an integer
359
+ * we must treat the the whole array as an object. We
360
+ * also try to catch a sparsely populated associative
361
+ * array with numeric keys here because some JS engines
362
+ * will create an array with empty indexes up to
363
+ * max_index which can cause memory issues and because
364
+ * the keys, which may be relevant, will be remapped
365
+ * otherwise.
366
+ *
367
+ * As per the ECMA and JSON specification an object may
368
+ * have any string as a property. Unfortunately due to
369
+ * a hole in the ECMA specification if the key is a
370
+ * ECMA reserved word or starts with a digit the
371
+ * parameter is only accessible using ECMAScript's
372
+ * bracket notation.
373
+ */
374
+
375
+ // treat as a JSON object
376
+ if ( is_array( $var ) && count( $var ) && ( array_keys( $var ) !== range( 0,
377
+ sizeof( $var ) - 1 ) )
378
+ ) {
379
+ $properties = array_map( array( $this, 'name_value' ),
380
+ array_keys( $var ),
381
+ array_values( $var ) );
382
+
383
+ foreach ( $properties as $property ) {
384
+ if ( Services_JSON::isError( $property ) ) {
385
+ return $property;
386
+ }
387
+ }
388
+
389
+ return '{' . join( ',', $properties ) . '}';
390
+ }
391
+
392
+ // treat it like a regular array
393
+ $elements = array_map( array( $this, 'encode' ), $var );
394
+
395
+ foreach ( $elements as $element ) {
396
+ if ( Services_JSON::isError( $element ) ) {
397
+ return $element;
398
+ }
399
+ }
400
+
401
+ return '[' . join( ',', $elements ) . ']';
402
+
403
+ case 'object':
404
+ $vars = get_object_vars( $var );
405
+
406
+ $properties = array_map( array( $this, 'name_value' ),
407
+ array_keys( $vars ),
408
+ array_values( $vars ) );
409
+
410
+ foreach ( $properties as $property ) {
411
+ if ( Services_JSON::isError( $property ) ) {
412
+ return $property;
413
+ }
414
+ }
415
+
416
+ return '{' . join( ',', $properties ) . '}';
417
+
418
+ default:
419
+ return ( $this->use & SERVICES_JSON_SUPPRESS_ERRORS )
420
+ ? 'null'
421
+ : new Services_JSON_Error( gettype( $var ) . " can not be encoded as JSON string" );
422
+ }
423
+ }
424
+
425
+ /**
426
+ * array-walking function for use in generating JSON-formatted name-value pairs
427
+ *
428
+ * @param string $name name of key to use
429
+ * @param mixed $value reference to an array element to be encoded
430
+ *
431
+ * @return string JSON-formatted name-value pair, like '"name":value'
432
+ * @access private
433
+ */
434
+ function name_value( $name, $value ) {
435
+ $encoded_value = $this->encode( $value );
436
+
437
+ if ( Services_JSON::isError( $encoded_value ) ) {
438
+ return $encoded_value;
439
+ }
440
+
441
+ return $this->encode( strval( $name ) ) . ':' . $encoded_value;
442
+ }
443
+
444
+ /**
445
+ * reduce a string by removing leading and trailing comments and whitespace
446
+ *
447
+ * @param $str string string value to strip of comments and whitespace
448
+ *
449
+ * @return string string value stripped of comments and whitespace
450
+ * @access private
451
+ */
452
+ function reduce_string( $str ) {
453
+ $str = preg_replace( array(
454
+
455
+ // eliminate single line comments in '// ...' form
456
+ '#^\s*//(.+)$#m',
457
+ // eliminate multi-line comments in '/* ... */' form, at start of string
458
+ '#^\s*/\*(.+)\*/#Us',
459
+ // eliminate multi-line comments in '/* ... */' form, at end of string
460
+ '#/\*(.+)\*/\s*$#Us'
461
+
462
+ ), '', $str );
463
+
464
+ // eliminate extraneous space
465
+ return trim( $str );
466
+ }
467
+
468
+ /**
469
+ * decodes a JSON string into appropriate variable
470
+ *
471
+ * @param string $str JSON-formatted string
472
+ *
473
+ * @return mixed number, boolean, string, array, or object
474
+ * corresponding to given JSON input string.
475
+ * See argument 1 to Services_JSON() above for object-output behavior.
476
+ * Note that decode() always returns strings
477
+ * in ASCII or UTF-8 format!
478
+ * @access public
479
+ */
480
+ function decode( $str ) {
481
+ $str = $this->reduce_string( $str );
482
+
483
+ switch ( strtolower( $str ) ) {
484
+ case 'true':
485
+ return true;
486
+
487
+ case 'false':
488
+ return false;
489
+
490
+ case 'null':
491
+ return null;
492
+
493
+ default:
494
+ $m = array();
495
+
496
+ if ( is_numeric( $str ) ) {
497
+ // Lookie-loo, it's a number
498
+
499
+ // This would work on its own, but I'm trying to be
500
+ // good about returning integers where appropriate:
501
+ // return (float)$str;
502
+
503
+ // Return float or int, as appropriate
504
+ return ( (float) $str == (integer) $str )
505
+ ? (integer) $str
506
+ : (float) $str;
507
+
508
+ } elseif ( preg_match( '/^("|\').*(\1)$/s', $str, $m ) && $m[1] == $m[2] ) {
509
+ // STRINGS RETURNED IN UTF-8 FORMAT
510
+ $delim = substr( $str, 0, 1 );
511
+ $chrs = substr( $str, 1, - 1 );
512
+ $utf8 = '';
513
+ $strlen_chrs = strlen( $chrs );
514
+
515
+ for ( $c = 0; $c < $strlen_chrs; ++ $c ) {
516
+
517
+ $substr_chrs_c_2 = substr( $chrs, $c, 2 );
518
+ $ord_chrs_c = ord( $chrs{$c} );
519
+
520
+ switch ( true ) {
521
+ case $substr_chrs_c_2 == '\b':
522
+ $utf8 .= chr( 0x08 );
523
+ ++ $c;
524
+ break;
525
+ case $substr_chrs_c_2 == '\t':
526
+ $utf8 .= chr( 0x09 );
527
+ ++ $c;
528
+ break;
529
+ case $substr_chrs_c_2 == '\n':
530
+ $utf8 .= chr( 0x0A );
531
+ ++ $c;
532
+ break;
533
+ case $substr_chrs_c_2 == '\f':
534
+ $utf8 .= chr( 0x0C );
535
+ ++ $c;
536
+ break;
537
+ case $substr_chrs_c_2 == '\r':
538
+ $utf8 .= chr( 0x0D );
539
+ ++ $c;
540
+ break;
541
+
542
+ case $substr_chrs_c_2 == '\\"':
543
+ case $substr_chrs_c_2 == '\\\'':
544
+ case $substr_chrs_c_2 == '\\\\':
545
+ case $substr_chrs_c_2 == '\\/':
546
+ if ( ( $delim == '"' && $substr_chrs_c_2 != '\\\'' ) ||
547
+ ( $delim == "'" && $substr_chrs_c_2 != '\\"' )
548
+ ) {
549
+ $utf8 .= $chrs{++ $c};
550
+ }
551
+ break;
552
+
553
+ case preg_match( '/\\\u[0-9A-F]{4}/i', substr( $chrs, $c, 6 ) ):
554
+ // single, escaped unicode character
555
+ $utf16 = chr( hexdec( substr( $chrs, ( $c + 2 ), 2 ) ) )
556
+ . chr( hexdec( substr( $chrs, ( $c + 4 ), 2 ) ) );
557
+ $utf8 .= $this->utf162utf8( $utf16 );
558
+ $c += 5;
559
+ break;
560
+
561
+ case ( $ord_chrs_c >= 0x20 ) && ( $ord_chrs_c <= 0x7F ):
562
+ $utf8 .= $chrs{$c};
563
+ break;
564
+
565
+ case ( $ord_chrs_c & 0xE0 ) == 0xC0:
566
+ // characters U-00000080 - U-000007FF, mask 110XXXXX
567
+ //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
568
+ $utf8 .= substr( $chrs, $c, 2 );
569
+ ++ $c;
570
+ break;
571
+
572
+ case ( $ord_chrs_c & 0xF0 ) == 0xE0:
573
+ // characters U-00000800 - U-0000FFFF, mask 1110XXXX
574
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
575
+ $utf8 .= substr( $chrs, $c, 3 );
576
+ $c += 2;
577
+ break;
578
+
579
+ case ( $ord_chrs_c & 0xF8 ) == 0xF0:
580
+ // characters U-00010000 - U-001FFFFF, mask 11110XXX
581
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
582
+ $utf8 .= substr( $chrs, $c, 4 );
583
+ $c += 3;
584
+ break;
585
+
586
+ case ( $ord_chrs_c & 0xFC ) == 0xF8:
587
+ // characters U-00200000 - U-03FFFFFF, mask 111110XX
588
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
589
+ $utf8 .= substr( $chrs, $c, 5 );
590
+ $c += 4;
591
+ break;
592
+
593
+ case ( $ord_chrs_c & 0xFE ) == 0xFC:
594
+ // characters U-04000000 - U-7FFFFFFF, mask 1111110X
595
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
596
+ $utf8 .= substr( $chrs, $c, 6 );
597
+ $c += 5;
598
+ break;
599
+
600
+ }
601
+
602
+ }
603
+
604
+ return $utf8;
605
+
606
+ } elseif ( preg_match( '/^\[.*\]$/s', $str ) || preg_match( '/^\{.*\}$/s', $str ) ) {
607
+ // array, or object notation
608
+
609
+ if ( $str{0} == '[' ) {
610
+ $stk = array( SERVICES_JSON_IN_ARR );
611
+ $arr = array();
612
+ } else {
613
+ if ( $this->use & SERVICES_JSON_LOOSE_TYPE ) {
614
+ $stk = array( SERVICES_JSON_IN_OBJ );
615
+ $obj = array();
616
+ } else {
617
+ $stk = array( SERVICES_JSON_IN_OBJ );
618
+ $obj = new stdClass();
619
+ }
620
+ }
621
+
622
+ array_push( $stk, array(
623
+ 'what' => SERVICES_JSON_SLICE,
624
+ 'where' => 0,
625
+ 'delim' => false
626
+ ) );
627
+
628
+ $chrs = substr( $str, 1, - 1 );
629
+ $chrs = $this->reduce_string( $chrs );
630
+
631
+ if ( $chrs == '' ) {
632
+ if ( reset( $stk ) == SERVICES_JSON_IN_ARR ) {
633
+ return $arr;
634
+
635
+ } else {
636
+ return $obj;
637
+
638
+ }
639
+ }
640
+
641
+ //print("\nparsing {$chrs}\n");
642
+
643
+ $strlen_chrs = strlen( $chrs );
644
+
645
+ for ( $c = 0; $c <= $strlen_chrs; ++ $c ) {
646
+
647
+ $top = end( $stk );
648
+ $substr_chrs_c_2 = substr( $chrs, $c, 2 );
649
+
650
+ if ( ( $c == $strlen_chrs ) || ( ( $chrs{$c} == ',' ) && ( $top['what'] == SERVICES_JSON_SLICE ) ) ) {
651
+ // found a comma that is not inside a string, array, etc.,
652
+ // OR we've reached the end of the character list
653
+ $slice = substr( $chrs, $top['where'], ( $c - $top['where'] ) );
654
+ array_push( $stk,
655
+ array( 'what' => SERVICES_JSON_SLICE, 'where' => ( $c + 1 ), 'delim' => false ) );
656
+ //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
657
+
658
+ if ( reset( $stk ) == SERVICES_JSON_IN_ARR ) {
659
+ // we are in an array, so just push an element onto the stack
660
+ array_push( $arr, $this->decode( $slice ) );
661
+
662
+ } elseif ( reset( $stk ) == SERVICES_JSON_IN_OBJ ) {
663
+ // we are in an object, so figure
664
+ // out the property name and set an
665
+ // element in an associative array,
666
+ // for now
667
+ $parts = array();
668
+
669
+ if ( preg_match( '/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice,
670
+ $parts ) ) {
671
+ // "name":value pair
672
+ $key = $this->decode( $parts[1] );
673
+ $val = $this->decode( $parts[2] );
674
+
675
+ if ( $this->use & SERVICES_JSON_LOOSE_TYPE ) {
676
+ $obj[ $key ] = $val;
677
+ } else {
678
+ $obj->$key = $val;
679
+ }
680
+ } elseif ( preg_match( '/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts ) ) {
681
+ // name:value pair, where name is unquoted
682
+ $key = $parts[1];
683
+ $val = $this->decode( $parts[2] );
684
+
685
+ if ( $this->use & SERVICES_JSON_LOOSE_TYPE ) {
686
+ $obj[ $key ] = $val;
687
+ } else {
688
+ $obj->$key = $val;
689
+ }
690
+ }
691
+
692
+ }
693
+
694
+ } elseif ( ( ( $chrs{$c} == '"' ) || ( $chrs{$c} == "'" ) ) && ( $top['what'] != SERVICES_JSON_IN_STR ) ) {
695
+ // found a quote, and we are not inside a string
696
+ array_push( $stk,
697
+ array( 'what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c} ) );
698
+ //print("Found start of string at {$c}\n");
699
+
700
+ } elseif ( ( $chrs{$c} == $top['delim'] ) &&
701
+ ( $top['what'] == SERVICES_JSON_IN_STR ) &&
702
+ ( ( strlen( substr( $chrs, 0, $c ) ) - strlen( rtrim( substr( $chrs, 0, $c ),
703
+ '\\' ) ) ) % 2 != 1 )
704
+ ) {
705
+ // found a quote, we're in a string, and it's not escaped
706
+ // we know that it's not escaped becase there is _not_ an
707
+ // odd number of backslashes at the end of the string so far
708
+ array_pop( $stk );
709
+ //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
710
+
711
+ } elseif ( ( $chrs{$c} == '[' ) &&
712
+ in_array( $top['what'],
713
+ array( SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ ) )
714
+ ) {
715
+ // found a left-bracket, and we are in an array, object, or slice
716
+ array_push( $stk,
717
+ array( 'what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false ) );
718
+ //print("Found start of array at {$c}\n");
719
+
720
+ } elseif ( ( $chrs{$c} == ']' ) && ( $top['what'] == SERVICES_JSON_IN_ARR ) ) {
721
+ // found a right-bracket, and we're in an array
722
+ array_pop( $stk );
723
+ //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
724
+
725
+ } elseif ( ( $chrs{$c} == '{' ) &&
726
+ in_array( $top['what'],
727
+ array( SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ ) )
728
+ ) {
729
+ // found a left-brace, and we are in an array, object, or slice
730
+ array_push( $stk,
731
+ array( 'what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false ) );
732
+ //print("Found start of object at {$c}\n");
733
+
734
+ } elseif ( ( $chrs{$c} == '}' ) && ( $top['what'] == SERVICES_JSON_IN_OBJ ) ) {
735
+ // found a right-brace, and we're in an object
736
+ array_pop( $stk );
737
+ //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
738
+
739
+ } elseif ( ( $substr_chrs_c_2 == '/*' ) &&
740
+ in_array( $top['what'],
741
+ array( SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ ) )
742
+ ) {
743
+ // found a comment start, and we are in an array, object, or slice
744
+ array_push( $stk,
745
+ array( 'what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false ) );
746
+ $c ++;
747
+ //print("Found start of comment at {$c}\n");
748
+
749
+ } elseif ( ( $substr_chrs_c_2 == '*/' ) && ( $top['what'] == SERVICES_JSON_IN_CMT ) ) {
750
+ // found a comment end, and we're in one now
751
+ array_pop( $stk );
752
+ $c ++;
753
+
754
+ for ( $i = $top['where']; $i <= $c; ++ $i ) {
755
+ $chrs = substr_replace( $chrs, ' ', $i, 1 );
756
+ }
757
+
758
+ //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
759
+
760
+ }
761
+
762
+ }
763
+
764
+ if ( reset( $stk ) == SERVICES_JSON_IN_ARR ) {
765
+ return $arr;
766
+
767
+ } elseif ( reset( $stk ) == SERVICES_JSON_IN_OBJ ) {
768
+ return $obj;
769
+
770
+ }
771
+
772
+ }
773
+ }
774
+ }
775
+
776
+ /**
777
+ * @todo Ultimately, this should just call PEAR::isError()
778
+ */
779
+ function isError( $data, $code = null ) {
780
+ if ( class_exists( 'pear' ) ) {
781
+ return PEAR::isError( $data, $code );
782
+ } elseif ( is_object( $data ) && ( get_class( $data ) == 'services_json_error' ||
783
+ is_subclass_of( $data, 'services_json_error' ) )
784
+ ) {
785
+ return true;
786
+ }
787
+
788
+ return false;
789
+ }
790
+ }
791
+
792
+ if ( class_exists( 'PEAR_Error' ) ) {
793
+
794
+ class Services_JSON_Error extends PEAR_Error {
795
+ function Services_JSON_Error(
796
+ $message = 'unknown error',
797
+ $code = null,
798
+ $mode = null,
799
+ $options = null,
800
+ $userinfo = null
801
+ ) {
802
+ parent::PEAR_Error( $message, $code, $mode, $options, $userinfo );
803
+ }
804
+ }
805
+
806
+ } else {
807
+
808
+ /**
809
+ * @todo Ultimately, this class shall be descended from PEAR_Error
810
+ */
811
+ class Services_JSON_Error {
812
+ function Services_JSON_Error(
813
+ $message = 'unknown error',
814
+ $code = null,
815
+ $mode = null,
816
+ $options = null,
817
+ $userinfo = null
818
+ ) {
819
+
820
+ }
821
+ }
822
+
823
+ }
824
  endif;
825
  ?>
accountconfig.php CHANGED
@@ -1,183 +1,206 @@
1
  <?php
2
  // Settings page in the admin panel
3
  function zopim_account_config() {
4
- global $usernameToCodeURL, $languagesURL, $current_user;
5
-
6
- ?>
7
- <div class="wrap">
8
- <?php
9
- if (isset($_GET["action"]) && $_GET["action"]=="deactivate") {
10
- update_option('zopimSalt', "");
11
- update_option('zopimCode', "zopim");
12
  }
13
 
14
- $message = "";
15
  $authenticated = "";
16
 
17
- if (isset($_POST["action"]) && $_POST["action"]=="login") {
18
-
19
- if ($_POST["zopimUsername"] != "" && $_POST["zopimPassword"] != "") {
20
- $logindata = array("email" => $_POST["zopimUsername"], "password" => $_POST["zopimPassword"]);
21
- $loginresult = json_to_array(zopim_post_request(ZOPIM_LOGIN_URL, $logindata));
22
-
23
- if (isset($loginresult->error)) {
24
- $error["login"] = "<b>Could not log in to Zopim. Please check your login details.</b>";
25
- $gotologin = 1;
26
- update_option('zopimSalt', "wronglogin");
27
- } else if (isset($loginresult->salt)) {
28
- update_option('zopimUsername', $_POST["zopimUsername"]);
29
- update_option('zopimSalt', $loginresult->salt);
30
- $account = getAccountDetails(get_option('zopimSalt'));
31
- $editor = setEditor(get_option('zopimSalt'));
32
-
33
- if (isset($account)) {
34
- update_option('zopimCode', $account->account_key);
35
-
36
- if (get_option('zopimGreetings') == "") {
37
- $jsongreetings = to_json($account->settings->greetings);
38
- update_option('zopimGreetings', $jsongreetings);
 
39
  }
40
  }
41
- } else {
42
- update_option('zopimSalt', "");
43
- $error["login"] = "<b>Could not log in to Zopim. We were unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>";
 
44
  }
 
 
 
 
 
45
  }
46
- else {
47
- update_option('zopimSalt', "wronglogin");
48
- $gotologin = 1;
49
- $error["login"] = "<b>Could not log in to Zopim. Please check your login details.</b>";
50
- }
51
- } else if (isset($_POST["action"]) && $_POST["action"]=="signup") {
52
  $createdata = array(
53
- "email" => $_POST["zopimnewemail"],
54
- "first_name" => $_POST["zopimfirstname"],
55
- "last_name" => $_POST["zopimlastname"],
56
- "display_name" => $_POST["zopimfirstname"]." ".$_POST["zopimlastname"],
57
- "eref" => $_POST["zopimeref"],
58
- "source" => "wordpress",
59
  "recaptcha_challenge_field" => $_POST["recaptcha_challenge_field"],
60
- "recaptcha_response_field" => $_POST["recaptcha_response_field"]
61
  );
62
 
63
- $signupresult = json_to_array(zopim_post_request(ZOPIM_SIGNUP_URL, $createdata));
64
- if (isset($signupresult->error)) {
65
- $message = "<div style='color:#c33;'>Error during activation: <b>".$signupresult->error."</b>. Please try again.</div>";
66
- } else if (isset($signupresult->account_key)) {
67
- $message = "<b>Thank you for signing up. Please check your mail for your password to complete the process. </b>";
 
 
 
68
  $gotologin = 1;
69
  } else {
70
- $message = "<b>Could not activate account. The wordpress installation was unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>";
 
71
  }
72
  }
73
 
74
- if (get_option('zopimCode') != "" && get_option('zopimCode') != "zopim") {
75
- $accountDetails = getAccountDetails(get_option('zopimSalt'));
76
 
77
- if (!isset($accountDetails) || isset($accountDetails->error)) {
78
- $gotologin = 1;
79
  $error["auth"] = '
80
- <div class="metabox-holder">
81
- <div class="postbox">
82
- <h3 class="hndle"><span>Account no longer linked!</span></h3>
83
- <div style="padding:10px;line-height:17px;">
84
- We could not verify your Zopim account. Please check your password and try again.
85
- </div>
86
- </div>
87
- </div>'
88
- ;
89
  } else {
90
  $authenticated = "ok";
91
  }
92
  }
93
 
94
- if ($authenticated == "ok") {
95
 
96
- if ($accountDetails->package_id=="trial") {
97
- $accountDetails->package_id = "Free Lite Package + 14 Days Full-features";
98
  } else {
99
- $accountDetails->package_id .= " Package";
100
  }
101
 
102
- ?>
103
- <div id="icon-options-general" class="icon32"><br/></div><h2>Set up your Zopim Account</h2>
104
- <br/>
105
- <div style="background:#FFFEEB;padding:25px;border:1px solid #eee;">
106
- <span style="float:right;"><a href="admin.php?page=zopim_account_config&action=deactivate">Deactivate</a></span>
107
- Currently Activated Account &rarr; <b><?php echo get_option('zopimUsername'); ?></b> <div style="display:inline-block;margin-left:5px;background:#444;color:#fff;font-size:10px;text-transform:uppercase;padding:3px 8px;-moz-border-radius:5px;-webkit-border-radius:5px;"><?php echo ucwords($accountDetails->package_id); ?></div>
108
- <!--<br><p><br>You can <a href="admin.php?page=zopim_customize_widget">customize</a> the chat widget, or <a href="admin.php?page=zopim_dashboard">launch the dashboard</a> for advanced features.-->
109
- <br><br>To start using Zopim chat, launch our dashboard for access to all features, including widget customization!
110
- <br><br><a href="<?php echo ZOPIM_DASHBOARD_LINK."&username=".get_option('zopimUsername'); ?>" style="text-decoration:none;" target="_blank" data-popup="true"><div class="zopim_btn_orange">Launch Dashboard</div></a>&nbsp;&nbsp;(This will open up a new browser tab)
111
-
112
-
113
- <form method="post" action="admin.php?page=zopim_account_config">
114
- <?php
115
- if (isset($_POST['widget-options'])) {
116
- $opts = $_POST['widget-options'];
117
- update_option('zopimWidgetOptions', $opts);
118
- echo '<i>Widget options updated.<br/></i>';
119
- }
120
-
121
- ?>
122
- <p>
123
- Optional code for customization with Zopim API:
124
- <br/>
125
- <textarea name="widget-options" style="width:680px; height: 200px;"><?php echo esc_textarea(zopim_get_widget_options()); ?></textarea>
126
- <br/>
127
- <input class="button-primary" type="submit" value="Update widget options" />
128
- </p>
129
- </form>
130
-
131
- </div>
132
- <?php } else { ?>
133
- <div id="icon-options-general" class="icon32"><br/></div><h2>Set up your Zopim Account</h2>
134
- <?php if (isset($error["auth"])) {
135
- echo $error["auth"];
136
- } else if ($message == "") { ?>
137
- Congratulations on successfully installing the Zopim WordPress plugin!<br>
138
- <br>
139
- <?php } else { echo $message;} ?>
140
- <div id="existingform">
141
- <div class="metabox-holder">
142
- <div class="postbox">
143
- <h3 class="hndle"><span>Link up with your Zopim account</span></h3>
144
- <div style="padding:10px;">
145
- <?php if (isset($error["login"])) { echo '<span class="error">'.$error["login"].'</span>'; } ?>
146
- <form method="post" action="admin.php?page=zopim_account_config">
147
- <input type="hidden" name="action" value="login">
148
- <table class="form-table">
149
-
150
- <tr valign="top">
151
- <th scope="row">Zopim Username (E-mail)</th>
152
- <td><input type="text" name="zopimUsername" value="<?php echo get_option('zopimUsername'); ?>" /></td>
153
- </tr>
154
-
155
- <tr valign="top">
156
- <th scope="row">Zopim Password</th>
157
- <td><input type="password" name="zopimPassword" value="" /></td>
158
- </tr>
159
-
160
- <!--<tr valign="center">
161
- <th scope="row">Use SSL</th>
162
- <td><input type="checkbox" name="zopimUseSSL" value="zopimUseSSL" <?php if (get_option('zopimUseSSL') == "zopimUseSSL") { echo "checked='checked'"; } ?> /> uncheck this if you are unable to login</td>
163
- </tr>-->
164
- </table>
165
- <br/>
166
- The Zopim chat widget will display on your blog after your account is linked up.
167
  <br/>
168
- <p class="submit">
169
- <input id="linkup" type="submit" onclick="animateButton()" class="button-primary" value="<?php _e('Link Up') ?>" />
170
- &nbsp;Don't have a Zopim account? <a href="<?php echo ZOPIM_SIGNUP_REDIRECT_URL; ?>" target="_blank" data-popup="true">Sign up now</a>.
171
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- </form>
 
 
 
 
 
 
 
 
 
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  </div>
176
  </div>
177
- </div>
178
- </div>
179
 
180
- </div>
181
 
182
 
183
- <?php } } ?>
 
1
  <?php
2
  // Settings page in the admin panel
3
  function zopim_account_config() {
4
+ ?>
5
+ <div class="wrap">
6
+ <?php
7
+ if ( isset( $_GET["action"] ) && $_GET["action"] == "deactivate" ) {
8
+ update_option( 'zopimSalt', "" );
9
+ update_option( 'zopimCode', "zopim" );
 
 
10
  }
11
 
12
+ $message = "";
13
  $authenticated = "";
14
 
15
+ if ( isset( $_POST["action"] ) && $_POST["action"] == "login" ) {
16
+
17
+ if ( $_POST["zopimUsername"] != "" && $_POST["zopimPassword"] != "" ) {
18
+ $logindata = array( "email" => $_POST["zopimUsername"], "password" => $_POST["zopimPassword"] );
19
+ $loginresult = json_to_array( zopim_post_request( ZOPIM_LOGIN_URL, $logindata ) );
20
+
21
+ if ( isset( $loginresult->error ) ) {
22
+ $error["login"] = "<b>" . __( 'Could not log in to Zopim. Please check your login details.',
23
+ 'zopim' ) . "</b>";
24
+ $gotologin = 1;
25
+ update_option( 'zopimSalt', "wronglogin" );
26
+ } else if ( isset( $loginresult->salt ) ) {
27
+ update_option( 'zopimUsername', $_POST["zopimUsername"] );
28
+ update_option( 'zopimSalt', $loginresult->salt );
29
+ $account = zopim_get_account_details( get_option( 'zopimSalt' ) );
30
+ $editor = zopim_set_editor( get_option( 'zopimSalt' ) );
31
+
32
+ if ( isset( $account ) ) {
33
+ update_option( 'zopimCode', $account->account_key );
34
+
35
+ if ( get_option( 'zopimGreetings' ) == "" ) {
36
+ $jsongreetings = to_json( $account->settings->greetings );
37
+ update_option( 'zopimGreetings', $jsongreetings );
38
  }
39
  }
40
+ } else if ( isset( $loginresult->wp_error ) ) {
41
+ update_option( 'zopimSalt', "" );
42
+ $error["login"] = "<b>" . __( "Could not log in to Zopim. We were unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly",
43
+ "zopim" ) . "</b>";
44
  }
45
+ } else {
46
+ update_option( 'zopimSalt', "wronglogin" );
47
+ $gotologin = 1;
48
+ $error["login"] = "<b>" . __( 'Could not log in to Zopim. Please check your login details.',
49
+ 'zopim' ) . "</b>";
50
  }
51
+ } else if ( isset( $_POST["action"] ) && $_POST["action"] == "signup" ) {
 
 
 
 
 
52
  $createdata = array(
53
+ "email" => $_POST["zopimnewemail"],
54
+ "first_name" => $_POST["zopimfirstname"],
55
+ "last_name" => $_POST["zopimlastname"],
56
+ "display_name" => $_POST["zopimfirstname"] . " " . $_POST["zopimlastname"],
57
+ "eref" => $_POST["zopimeref"],
58
+ "source" => "wordpress",
59
  "recaptcha_challenge_field" => $_POST["recaptcha_challenge_field"],
60
+ "recaptcha_response_field" => $_POST["recaptcha_response_field"]
61
  );
62
 
63
+ $signupresult = json_to_array( zopim_post_request( ZOPIM_SIGNUP_URL, $createdata ) );
64
+ if ( isset( $signupresult->error ) ) {
65
+ $message = "<div style='color:#c33;'>";
66
+ $message .= sprintf( __( 'Error during activation: <b>%s</b>. Please try again.</div>', 'zopim' ),
67
+ $signupresult->error );
68
+ } else if ( isset( $signupresult->account_key ) ) {
69
+ $message = "<b>" . __( 'Thank you for signing up. Please check your mail for your password to complete the process.',
70
+ 'zopim' ) . "</b>";
71
  $gotologin = 1;
72
  } else {
73
+ $message = "<b>" . __( "Could not activate account. The wordpress installation was unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.",
74
+ 'zopim' ) . "</b>";
75
  }
76
  }
77
 
78
+ if ( get_option( 'zopimCode' ) != "" && get_option( 'zopimCode' ) != "zopim" ) {
79
+ $accountDetails = zopim_get_account_details( get_option( 'zopimSalt' ) );
80
 
81
+ if ( ! isset( $accountDetails ) || isset( $accountDetails->error ) ) {
82
+ $gotologin = 1;
83
  $error["auth"] = '
84
+ <div class="metabox-holder">
85
+ <div class="postbox">
86
+ <h3 class="hndle"><span>' . __( 'Account no longer linked!', 'zopim' ) . '</span></h3>
87
+ <div style="padding:10px;line-height:17px;">'
88
+ . __( 'We could not verify your Zopim account. Please check your password and try again.', 'zopim' )
89
+ . '</div>
90
+ </div>
91
+ </div>';
 
92
  } else {
93
  $authenticated = "ok";
94
  }
95
  }
96
 
97
+ if ( $authenticated == "ok" ) {
98
 
99
+ if ( $accountDetails->package_id == "trial" ) {
100
+ $accountDetails->package_id = __( 'Free Lite Package + 14 Days Full-features', 'zopim' );
101
  } else {
102
+ $accountDetails->package_id .= __( ' Package', 'zopim' );
103
  }
104
 
105
+ ?>
106
+ <div id="icon-options-general" class="icon32"><br/></div>
107
+ <h2><?php _e( 'Set up your Zopim Account', 'zopim' ); ?></h2>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  <br/>
109
+ <div style="background:#FFFEEB;padding:25px;border:1px solid #eee;">
110
+ <span style="float:right;">
111
+ <a href="admin.php?page=zopim_account_config&action=deactivate"><?php _e( 'Deactivate',
112
+ 'zopim' ); ?></a>
113
+ </span>
114
+ <?php _e( 'Currently Activated Account', 'zopim' ); ?> &rarr;
115
+ <b><?php echo get_option( 'zopimUsername' ); ?></b>
116
+
117
+ <div style="display:inline-block;margin-left:5px;background:#444;color:#fff;font-size:10px;text-transform:uppercase;padding:3px 8px;-moz-border-radius:5px;-webkit-border-radius:5px;"><?php echo ucwords( $accountDetails->package_id ); ?></div>
118
+ <!--<br><p><br>You can <a href="admin.php?page=zopim_customize_widget">customize</a> the chat widget, or <a href="admin.php?page=zopim_dashboard">launch the dashboard</a> for advanced features.-->
119
+ <br><br><?php _e( 'To start using Zopim chat, launch our dashboard for access to all features, including widget customization!',
120
+ 'zopim' ); ?>
121
+ <br><br><a href="<?php echo ZOPIM_DASHBOARD_LINK . "&username=" . get_option( 'zopimUsername' ); ?>"
122
+ style="text-decoration:none;" target="_blank" data-popup="true">
123
+ <div class="zopim_btn_orange"><?php _e( 'Launch Dashboard', 'zopim' ); ?></div>
124
+ </a>&nbsp;&nbsp;(<?php _e( 'This will open up a new browser tab', 'zopim' ); ?>)
125
+
126
+
127
+ <form method="post" action="admin.php?page=zopim_account_config">
128
+ <?php
129
+ if ( isset( $_POST['widget-options'] ) ) {
130
+ $opts = $_POST['widget-options'];
131
+ update_option( 'zopimWidgetOptions', $opts );
132
+ echo '<i>' . __( 'Widget options updated.', 'zopim' ) . '<br/></i>';
133
+ }
134
 
135
+ ?>
136
+ <p>
137
+ <?php _e( 'Optional code for customization with Zopim API:', 'zopim' ); ?>
138
+ <br/>
139
+ <textarea name="widget-options"
140
+ style="width:680px; height: 200px;"><?php echo esc_textarea( zopim_get_widget_options() ); ?></textarea>
141
+ <br/>
142
+ <input class="button-primary" type="submit" value="Update widget options"/>
143
+ </p>
144
+ </form>
145
 
146
+ </div>
147
+ <?php } else { ?>
148
+ <div id="icon-options-general" class="icon32"><br/></div><h2><?php _e( 'Set up your Zopim Account',
149
+ 'zopim' ); ?></h2>
150
+ <?php if ( isset( $error["auth"] ) ) {
151
+ echo $error["auth"];
152
+ } else if ( $message == "" ) { ?>
153
+ <?php _e( 'Congratulations on successfully installing the Zopim WordPress plugin!', 'zopim' ); ?><br>
154
+ <br>
155
+ <?php } else {
156
+ echo $message;
157
+ } ?>
158
+ <div id="existingform">
159
+ <div class="metabox-holder">
160
+ <div class="postbox">
161
+ <h3 class="hndle"><span><?php _e( 'Link up with your Zopim account', 'zopim' ); ?></span></h3>
162
+
163
+ <div style="padding:10px;">
164
+ <?php if ( isset( $error["login"] ) ) {
165
+ echo '<span class="error">' . $error["login"] . '</span>';
166
+ } ?>
167
+ <form method="post" action="admin.php?page=zopim_account_config">
168
+ <input type="hidden" name="action" value="login">
169
+ <table class="form-table">
170
+
171
+ <tr valign="top">
172
+ <th scope="row"><?php _e( 'Zopim Username (E-mail)', 'zopim' ); ?></th>
173
+ <td><input type="text" name="zopimUsername"
174
+ value="<?php echo get_option( 'zopimUsername' ); ?>"/></td>
175
+ </tr>
176
+
177
+ <tr valign="top">
178
+ <th scope="row"><?php _e( 'Zopim Password', 'zopim' ); ?></th>
179
+ <td><input type="password" name="zopimPassword" value=""/></td>
180
+ </tr>
181
+
182
+ </table>
183
+ <br/>
184
+ <?php _e( 'The Zopim chat widget will display on your blog after your account is linked up.', 'zopim' ); ?>
185
+ <br/>
186
+
187
+ <p class="submit">
188
+ <input id="linkup" type="submit" onclick="animateButton()" class="button-primary"
189
+ value="<?php _e( 'Link Up', 'zopim' ) ?>"/>
190
+ &nbsp;<?php _e( 'Don\'t have a Zopim account?', 'zopim' ); ?> <a
191
+ href="<?php echo ZOPIM_SIGNUP_REDIRECT_URL; ?>" target="_blank"
192
+ data-popup="true"><?php _e( 'Sign up now', 'zopim' ); ?></a>.
193
+ </p>
194
+
195
+ </form>
196
+
197
+ </div>
198
+ </div>
199
  </div>
200
  </div>
 
 
201
 
202
+ </div>
203
 
204
 
205
+ <?php }
206
+ } ?>
languages/zopim.pot ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015 Zopim Widget
2
+ # This file is distributed under the same license as the Zopim Widget package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Zopim Widget 1.3.6\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/zopim-live-chat\n"
7
+ "POT-Creation-Date: 2015-05-05 09:02:33+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+
15
+ #: accountconfig.php:22 accountconfig.php:47
16
+ msgid "Could not log in to Zopim. Please check your login details."
17
+ msgstr ""
18
+
19
+ #: accountconfig.php:41
20
+ msgid ""
21
+ "Could not log in to Zopim. We were unable to contact Zopim servers. Please "
22
+ "check with your server administrator to ensure that <a href='http://www.php."
23
+ "net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are "
24
+ "set correctly"
25
+ msgstr ""
26
+
27
+ #: accountconfig.php:64
28
+ msgid "Error during activation: <b>%s</b>. Please try again.</div>"
29
+ msgstr ""
30
+
31
+ #: accountconfig.php:66
32
+ msgid ""
33
+ "Thank you for signing up. Please check your mail for your password to "
34
+ "complete the process."
35
+ msgstr ""
36
+
37
+ #: accountconfig.php:69
38
+ msgid ""
39
+ "Could not activate account. The wordpress installation was unable to contact "
40
+ "Zopim servers. Please check with your server administrator to ensure that <a "
41
+ "href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed "
42
+ "and permissions are set correctly."
43
+ msgstr ""
44
+
45
+ #: accountconfig.php:81
46
+ msgid "Account no longer linked!"
47
+ msgstr ""
48
+
49
+ #: accountconfig.php:83
50
+ msgid ""
51
+ "We could not verify your Zopim account. Please check your password and try "
52
+ "again."
53
+ msgstr ""
54
+
55
+ #: accountconfig.php:96
56
+ msgid "Free Lite Package + 14 Days Full-features"
57
+ msgstr ""
58
+
59
+ #: accountconfig.php:98
60
+ msgid " Package"
61
+ msgstr ""
62
+
63
+ #: accountconfig.php:102 accountconfig.php:132
64
+ msgid "Set up your Zopim Account"
65
+ msgstr ""
66
+
67
+ #: accountconfig.php:105
68
+ msgid "Deactivate"
69
+ msgstr ""
70
+
71
+ #: accountconfig.php:106
72
+ msgid "Currently Activated Account"
73
+ msgstr ""
74
+
75
+ #: accountconfig.php:108
76
+ msgid ""
77
+ "To start using Zopim chat, launch our dashboard for access to all features, "
78
+ "including widget customization!"
79
+ msgstr ""
80
+
81
+ #: accountconfig.php:109
82
+ msgid "Launch Dashboard"
83
+ msgstr ""
84
+
85
+ #: accountconfig.php:109
86
+ msgid "This will open up a new browser tab"
87
+ msgstr ""
88
+
89
+ #: accountconfig.php:117
90
+ msgid "Widget options updated."
91
+ msgstr ""
92
+
93
+ #: accountconfig.php:122
94
+ msgid "Optional code for customization with Zopim API:"
95
+ msgstr ""
96
+
97
+ #: accountconfig.php:136
98
+ msgid "Congratulations on successfully installing the Zopim WordPress plugin!"
99
+ msgstr ""
100
+
101
+ #: accountconfig.php:142
102
+ msgid "Link up with your Zopim account"
103
+ msgstr ""
104
+
105
+ #: accountconfig.php:150
106
+ msgid "Zopim Username (E-mail)"
107
+ msgstr ""
108
+
109
+ #: accountconfig.php:155
110
+ msgid "Zopim Password"
111
+ msgstr ""
112
+
113
+ #: accountconfig.php:165
114
+ msgid ""
115
+ "The Zopim chat widget will display on your blog after your account is linked "
116
+ "up."
117
+ msgstr ""
118
+
119
+ #: accountconfig.php:168
120
+ msgid "Link Up"
121
+ msgstr ""
122
+
123
+ #: accountconfig.php:169
124
+ msgid "Don't have a Zopim account?"
125
+ msgstr ""
126
+
127
+ #: accountconfig.php:169
128
+ msgid "Sign up now"
129
+ msgstr ""
130
+
131
+ #: zopim.php:162
132
+ msgid "Account Configuration"
133
+ msgstr ""
134
+
135
+ #: zopim.php:162
136
+ msgid "Zopim Chat"
137
+ msgstr ""
138
+
139
+ #. Plugin Name of the plugin/theme
140
+ msgid "Zopim Widget"
141
+ msgstr ""
142
+
143
+ #. #-#-#-#-# zopim.pot (Zopim Widget 1.3.6) #-#-#-#-#
144
+ #. Plugin URI of the plugin/theme
145
+ #. #-#-#-#-# zopim.pot (Zopim Widget 1.3.6) #-#-#-#-#
146
+ #. Author URI of the plugin/theme
147
+ msgid "http://www.zopim.com/?iref=wp_plugin"
148
+ msgstr ""
149
+
150
+ #. Description of the plugin/theme
151
+ msgid ""
152
+ "Zopim is an award winning chat solution that helps website owners to engage "
153
+ "their visitors and convert customers into fans!"
154
+ msgstr ""
155
+
156
+ #. Author of the plugin/theme
157
+ msgid "Zopim"
158
+ msgstr ""
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Zopim Live Chat ===
2
- Contributors: bencxr
3
  Tags: chat, chat online, contact plugin, contact us, customer support, free chat, chat software, IM chat, live chat, live chat inc, live chat services, live chat software, live chatting, live help, live support, live web chat, livechat, live help, live support, olark, online chat, online support, php live chat, snapengage, support software, website chat, wordpress chat, wordpress live chat, wordpress live chat plugin, Zopim, zendesk, Zopim live chat, banckle, clickdesk, click desk
4
  Requires at least: 3.1
5
  Tested up to: 4.1.1
6
- Stable tag: 1.3.7
7
 
8
  Zopim lets you monitor and chat with visitors surfing your store in real-time. Impress them personally and ease them into their purchase.
9
 
@@ -48,8 +48,16 @@ What are you waiting for? Download Zopim Live Chat plugin now and <a href="https
48
  * Arabic | Bulgarian | Chinese | Croatian | Czech | Danish | Dutch; Flemish | Estonian | Faroese | Finnish | French | Georgian | German | Greek | Hebrew | Hungarian | Icelandic | Indonesian | Italian | Japanese | Korean | Kurdish | Latvian | Lithuanian | Macedonian | Malay | Norwegian Bokmal | Persian | Polish | Portuguese | Romanian | Russian | Serbian | Slovak | Slovenian | Spanish; Castilian | Swedish | Thai | Turkish | Ukranian | Urdu | Vietnamese
49
 
50
  == Changelog ==
 
 
 
 
 
 
 
 
 
51
  = 1.3.7 =
52
- * Fix PHP notices
53
  * Add documentation for releasing new versions of the plugin
54
 
55
  = 1.3.6 =
1
  === Zopim Live Chat ===
2
+ Contributors: zendesk_official
3
  Tags: chat, chat online, contact plugin, contact us, customer support, free chat, chat software, IM chat, live chat, live chat inc, live chat services, live chat software, live chatting, live help, live support, live web chat, livechat, live help, live support, olark, online chat, online support, php live chat, snapengage, support software, website chat, wordpress chat, wordpress live chat, wordpress live chat plugin, Zopim, zendesk, Zopim live chat, banckle, clickdesk, click desk
4
  Requires at least: 3.1
5
  Tested up to: 4.1.1
6
+ Stable tag: 1.3.8
7
 
8
  Zopim lets you monitor and chat with visitors surfing your store in real-time. Impress them personally and ease them into their purchase.
9
 
48
  * Arabic | Bulgarian | Chinese | Croatian | Czech | Danish | Dutch; Flemish | Estonian | Faroese | Finnish | French | Georgian | German | Greek | Hebrew | Hungarian | Icelandic | Indonesian | Italian | Japanese | Korean | Kurdish | Latvian | Lithuanian | Macedonian | Malay | Norwegian Bokmal | Persian | Polish | Portuguese | Romanian | Russian | Serbian | Slovak | Slovenian | Spanish; Castilian | Swedish | Thai | Turkish | Ukranian | Urdu | Vietnamese
49
 
50
  == Changelog ==
51
+ = 1.3.8 =
52
+ * Fix throwing of wordpress errors
53
+ * Fix PHP notice ('Notice: Undefined variable: error') on the plugin dashboard
54
+ * Remove unused globals
55
+ * Standardize function names
56
+ * Use _() and _e() for translations
57
+ * Add english language file
58
+ * Added icon assets
59
+
60
  = 1.3.7 =
 
61
  * Add documentation for releasing new versions of the plugin
62
 
63
  = 1.3.6 =
zopim.php CHANGED
@@ -1,34 +1,36 @@
1
  <?php
2
-
3
  /*
4
  Plugin Name: Zopim Widget
5
  Plugin URI: http://www.zopim.com/?iref=wp_plugin
6
  Description: Zopim is an award winning chat solution that helps website owners to engage their visitors and convert customers into fans!
7
  Author: Zopim
8
- Version: 1.3.7
9
  Author URI: http://www.zopim.com/?iref=wp_plugin
 
 
10
  */
11
 
12
- define('VERSION_NUMBER', "1.3.7");
13
- define('ZOPIM_BASE_URL', "https://www.zopim.com/");
14
- define('ZOPIM_ACCOUNT_URL', "https://account.zopim.com/");
15
- define('ZOPIM_SIGNUP_REDIRECT_URL', ZOPIM_ACCOUNT_URL."?aref=MjUxMjY4:1TeORR:9SP1e-iPTuAVXROJA6UU5seC8x4&visit_id=6ffe00ec3cfc11e2b5ab22000a1db8fa&utm_source=account%2Bsetup%2Bpage&utm_medium=link&utm_campaign=wp%2Bsignup2#signup");
16
- define('ZOPIM_GETACCOUNTDETAILS_URL', ZOPIM_BASE_URL."plugins/getAccountDetails");
17
- define('ZOPIM_SETDISPLAYNAME_URL', ZOPIM_BASE_URL."plugins/setDisplayName");
18
- define('ZOPIM_SETEDITOR_URL', ZOPIM_BASE_URL."plugins/setEditor");
19
- define('ZOPIM_LOGIN_URL', ZOPIM_BASE_URL."plugins/login");
20
- define('ZOPIM_SIGNUP_URL', ZOPIM_BASE_URL."plugins/createTrialAccount");
21
- define('ZOPIM_DASHBOARD_LINK', "https://dashboard.zopim.com/?utm_source=wp&utm_medium=link&utm_campaign=wp%2Bdashboard");
22
- define('ZOPIM_SMALL_LOGO', "https://dashboard.zopim.com/assets/branding/zopim.com/chatman/online.png");
23
 
24
  require_once dirname( __FILE__ ) . '/accountconfig.php';
25
 
26
 
27
- function load_zopim_style() {
28
- wp_register_style('zopim_style', plugins_url('zopim.css', __FILE__));
29
- wp_enqueue_style('zopim_style');
30
  wp_register_script( 'zopim_js', plugins_url( 'zopim.js', __FILE__ ) );
31
- wp_enqueue_script('zopim_js');
32
  }
33
 
34
  function add_zopim_caps() {
@@ -36,37 +38,37 @@ function add_zopim_caps() {
36
  $role->add_cap( 'access_zopim' );
37
  }
38
 
39
- add_action('admin_enqueue_scripts', 'load_zopim_style');
40
- add_action('admin_init', 'add_zopim_caps');
41
 
42
  // We need some CSS to position the paragraph
43
  function zopimme() {
44
- global $current_user, $zopimshown;
45
  get_currentuserinfo();
46
 
47
- $code = get_option('zopimCode');
48
-
49
- if ( ( $code == "" || $code == "zopim" ) && ( !isset($_GET['page']) && !preg_match( "/zopim/", $_GET['page'] ) ) && ( !preg_match( "/zopim/", $_SERVER["SERVER_NAME"] ) ) ) { return; }
50
 
51
- // dont show this more than once
52
- if (isset($zopimshown) && $zopimshown == 1) { return; }
53
- $zopimshown = 1;
 
 
54
 
55
- echo "<!--Embed from Zopim Live Chat Wordpress Plugin v".VERSION_NUMBER."-->
56
  <!--Start of Zopim Live Chat Script-->
57
  <script type=\"text/javascript\">
58
  window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=z.s=
59
  d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
60
  _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
61
- $.src='//v2.zopim.com/?".$code."';z.t=+new Date;$.
62
  type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
63
  </script>";
64
 
65
  echo '<script>';
66
- if (isset($current_user)):
67
  $firstname = $current_user->display_name;
68
  $useremail = $current_user->user_email;
69
- if ($firstname!="" && $useremail != ""):
70
  echo "\$zopim(function(){\$zopim.livechat.set({name: '$firstname', email: '$useremail'}); });";
71
  endif;
72
  endif;
@@ -77,15 +79,17 @@ type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
77
  }
78
 
79
  function zopim_get_widget_options() {
80
- $opts = get_option('zopimWidgetOptions');
81
- if ($opts) return stripslashes($opts);
 
 
82
 
83
  //$opts = zopim_old_plugin_settings();
84
  $zopim_embed_opts = "\$zopim( function() {";
85
  $zopim_embed_opts .= "\n})";
86
  $opts = $zopim_embed_opts;
87
 
88
- update_option('zopimWidgetOptions', $opts);
89
 
90
  $list = array(
91
  'zopimLang',
@@ -100,70 +104,89 @@ function zopim_get_widget_options() {
100
  'zopimHideOnOffline'
101
  );
102
 
103
- foreach ($list as $key):
104
- delete_option($key);
105
  endforeach;
106
 
107
- if ($opts) return $opts;
108
- else return '';
 
 
 
109
  }
110
 
111
 
112
  function zopim_old_plugin_settings() {
113
  $theoptions = array();
114
 
115
- if (get_option('zopimLang') != "" && get_option('zopimLang') != "--")
116
- $theoptions[] = " language: '".get_option('zopimLang')."'";
 
117
 
118
  $zopim_embed_opts = '';
119
  $zopim_embed_opts .= "\$zopim( function() {";
120
 
121
- if (count($theoptions) > 0)
122
- $zopim_embed_opts .= '$zopim.livechat.set({'.implode(", ", $theoptions)."});";
 
123
 
124
- if (get_option('zopimPosition')) $zopim_embed_opts .= "\n\$zopim.livechat.button.setPosition('".get_option('zopimPosition')."');";
125
- if (get_option('zopimTheme')) $zopim_embed_opts .= "\n\$zopim.livechat.window.setTheme('".get_option('zopimTheme')."');";
126
- if (get_option('zopimColor')) $zopim_embed_opts .= "\n\$zopim.livechat.window.setColor('".get_option('zopimColor')."');";
 
 
 
 
 
 
127
 
128
- if (get_option('zopimUseGreetings') == "zopimUseGreetings") {
129
- if (get_option('zopimGreetings') != "") {
130
- $greetings = json_to_array(get_option('zopimGreetings'));
131
- foreach ($greetings as $i => $v) {
132
- foreach ($v as $j => $k) {
133
- $greetings->$i->$j = str_replace("\r\n", "\\n", $greetings->$i->$j);
134
  }
135
  }
136
  $zopim_embed_opts .= "\n\$zopim.livechat.setGreetings({
137
- 'online' : ['".addslashes($greetings->online->bar)."', '".addslashes($greetings->online->window)."'],
138
- 'offline': ['".addslashes($greetings->offline->bar)."', '".addslashes($greetings->offline->window)."'],
139
- 'away' : ['".addslashes($greetings->away->bar)."', '".addslashes($greetings->away->window)."'] });";
140
  }
141
  }
142
 
143
- if (get_option('zopimUseBubble') == "zopimUseBubble") {
144
- if (get_option('zopimBubbleTitle')) $zopim_embed_opts .= "\n\$zopim.livechat.bubble.setTitle('".addslashes(get_option('zopimBubbleTitle'))."');";
145
- if (get_option('zopimBubbleText')) $zopim_embed_opts .= "\n\$zopim.livechat.bubble.setText('".addslashes(get_option('zopimBubbleText'))."');";
 
 
 
 
146
  }
147
 
148
- if (get_option('zopimBubbleEnable') == "show")
149
  $zopim_embed_opts .= "\n\$zopim.livechat.bubble.show(true);";
150
- else if (get_option('zopimBubbleEnable') == "hide")
151
  $zopim_embed_opts .= "\n\$zopim.livechat.bubble.hide(true);";
 
152
 
153
  // this must be called last
154
- if (get_option('zopimHideOnOffline') == "zopimHideOnOffline")
155
  $zopim_embed_opts .= "\n\$zopim.livechat.button.setHideWhenOffline(true);";
 
 
 
156
 
157
- $zopim_embed_opts .= "\n})";
158
  return $zopim_embed_opts;
159
 
160
  }
161
 
162
  function zopim_create_menu() {
163
  //create new top-level menu
164
- add_menu_page('Account Configuration', 'Zopim Chat', 'access_zopim', 'zopim_account_config', 'zopim_account_config', ZOPIM_SMALL_LOGO);
 
165
  //call register settings function
166
- add_action('admin_init', 'register_zopim_plugin_settings' );
167
  }
168
 
169
  // Register the option settings we will be using
@@ -176,41 +199,60 @@ function register_zopim_plugin_settings() {
176
 
177
  }
178
 
179
- add_action('get_footer', 'zopimme');
180
  // create custom plugin settings menu
181
- add_action('admin_menu', 'zopim_create_menu');
182
 
183
- function zopim_post_request($url, $_data, $optional_headers = null) {
184
- $args = array('body' => $_data);
185
  $response = wp_remote_post( $url, $args );
 
 
 
 
 
 
186
  return $response['body'];
187
  }
188
 
189
- function zopim_url_get($filename) {
190
- $response = wp_remote_get($filename);
 
 
 
 
 
 
 
191
  return $response['body'];
192
  }
193
 
194
- function json_to_array($json) {
195
- require_once('JSON.php');
196
  $jsonparser = new Services_JSON();
197
- return ($jsonparser->decode($json));
 
198
  }
199
 
200
- function to_json($variable) {
201
- require_once('JSON.php');
202
  $jsonparser = new Services_JSON();
203
- return ($jsonparser->encode($variable));
 
204
  }
205
 
206
- function getAccountDetails($salt) {
207
- $salty = array("salt" => get_option('zopimSalt'));
208
- return json_to_array(zopim_post_request(ZOPIM_GETACCOUNTDETAILS_URL, $salty));
 
209
  }
210
 
211
- function setEditor($salt) {
212
- $salty = array("salt" => get_option('zopimSalt'));
213
- return json_to_array(zopim_post_request(ZOPIM_SETEDITOR_URL, $salty));
 
214
  }
215
 
216
- ?>
 
 
1
  <?php
2
+
3
  /*
4
  Plugin Name: Zopim Widget
5
  Plugin URI: http://www.zopim.com/?iref=wp_plugin
6
  Description: Zopim is an award winning chat solution that helps website owners to engage their visitors and convert customers into fans!
7
  Author: Zopim
8
+ Version: 1.3.8
9
  Author URI: http://www.zopim.com/?iref=wp_plugin
10
+ Text Domain: zopim
11
+ Domain path: /language
12
  */
13
 
14
+ define( 'VERSION_NUMBER', "1.3.8" );
15
+ define( 'ZOPIM_BASE_URL', "https://www.zopim.com/" );
16
+ define( 'ZOPIM_ACCOUNT_URL', "https://account.zopim.com/" );
17
+ define( 'ZOPIM_SIGNUP_REDIRECT_URL', ZOPIM_ACCOUNT_URL . "?aref=MjUxMjY4:1TeORR:9SP1e-iPTuAVXROJA6UU5seC8x4&visit_id=6ffe00ec3cfc11e2b5ab22000a1db8fa&utm_source=account%2Bsetup%2Bpage&utm_medium=link&utm_campaign=wp%2Bsignup2#signup" );
18
+ define( 'ZOPIM_GETACCOUNTDETAILS_URL', ZOPIM_BASE_URL . "plugins/getAccountDetails" );
19
+ define( 'ZOPIM_SETDISPLAYNAME_URL', ZOPIM_BASE_URL . "plugins/setDisplayName" );
20
+ define( 'ZOPIM_SETEDITOR_URL', ZOPIM_BASE_URL . "plugins/setEditor" );
21
+ define( 'ZOPIM_LOGIN_URL', ZOPIM_BASE_URL . "plugins/login" );
22
+ define( 'ZOPIM_SIGNUP_URL', ZOPIM_BASE_URL . "plugins/createTrialAccount" );
23
+ define( 'ZOPIM_DASHBOARD_LINK', "https://dashboard.zopim.com/?utm_source=wp&utm_medium=link&utm_campaign=wp%2Bdashboard" );
24
+ define( 'ZOPIM_SMALL_LOGO', "https://dashboard.zopim.com/assets/branding/zopim.com/chatman/online.png" );
25
 
26
  require_once dirname( __FILE__ ) . '/accountconfig.php';
27
 
28
 
29
+ function load_zopim_style() {
30
+ wp_register_style( 'zopim_style', plugins_url( 'zopim.css', __FILE__ ) );
31
+ wp_enqueue_style( 'zopim_style' );
32
  wp_register_script( 'zopim_js', plugins_url( 'zopim.js', __FILE__ ) );
33
+ wp_enqueue_script( 'zopim_js' );
34
  }
35
 
36
  function add_zopim_caps() {
38
  $role->add_cap( 'access_zopim' );
39
  }
40
 
41
+ add_action( 'admin_enqueue_scripts', 'load_zopim_style' );
42
+ add_action( 'admin_init', 'add_zopim_caps' );
43
 
44
  // We need some CSS to position the paragraph
45
  function zopimme() {
46
+ global $current_user;
47
  get_currentuserinfo();
48
 
49
+ $code = get_option( 'zopimCode' );
 
 
50
 
51
+ if ( ( $code == "" || $code == "zopim" ) && ( ! isset( $_GET['page'] ) && ! preg_match( "/zopim/",
52
+ $_GET['page'] ) ) && ( ! preg_match( "/zopim/", $_SERVER["SERVER_NAME"] ) )
53
+ ) {
54
+ return;
55
+ }
56
 
57
+ echo "<!--Embed from Zopim Live Chat Wordpress Plugin v" . VERSION_NUMBER . "-->
58
  <!--Start of Zopim Live Chat Script-->
59
  <script type=\"text/javascript\">
60
  window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=z.s=
61
  d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
62
  _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
63
+ $.src='//v2.zopim.com/?" . $code . "';z.t=+new Date;$.
64
  type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
65
  </script>";
66
 
67
  echo '<script>';
68
+ if ( isset( $current_user ) ):
69
  $firstname = $current_user->display_name;
70
  $useremail = $current_user->user_email;
71
+ if ( $firstname != "" && $useremail != "" ):
72
  echo "\$zopim(function(){\$zopim.livechat.set({name: '$firstname', email: '$useremail'}); });";
73
  endif;
74
  endif;
79
  }
80
 
81
  function zopim_get_widget_options() {
82
+ $opts = get_option( 'zopimWidgetOptions' );
83
+ if ( $opts ) {
84
+ return stripslashes( $opts );
85
+ }
86
 
87
  //$opts = zopim_old_plugin_settings();
88
  $zopim_embed_opts = "\$zopim( function() {";
89
  $zopim_embed_opts .= "\n})";
90
  $opts = $zopim_embed_opts;
91
 
92
+ update_option( 'zopimWidgetOptions', $opts );
93
 
94
  $list = array(
95
  'zopimLang',
104
  'zopimHideOnOffline'
105
  );
106
 
107
+ foreach ( $list as $key ):
108
+ delete_option( $key );
109
  endforeach;
110
 
111
+ if ( $opts ) {
112
+ return $opts;
113
+ } else {
114
+ return '';
115
+ }
116
  }
117
 
118
 
119
  function zopim_old_plugin_settings() {
120
  $theoptions = array();
121
 
122
+ if ( get_option( 'zopimLang' ) != "" && get_option( 'zopimLang' ) != "--" ) {
123
+ $theoptions[] = " language: '" . get_option( 'zopimLang' ) . "'";
124
+ }
125
 
126
  $zopim_embed_opts = '';
127
  $zopim_embed_opts .= "\$zopim( function() {";
128
 
129
+ if ( count( $theoptions ) > 0 ) {
130
+ $zopim_embed_opts .= '$zopim.livechat.set({' . implode( ", ", $theoptions ) . "});";
131
+ }
132
 
133
+ if ( get_option( 'zopimPosition' ) ) {
134
+ $zopim_embed_opts .= "\n\$zopim.livechat.button.setPosition('" . get_option( 'zopimPosition' ) . "');";
135
+ }
136
+ if ( get_option( 'zopimTheme' ) ) {
137
+ $zopim_embed_opts .= "\n\$zopim.livechat.window.setTheme('" . get_option( 'zopimTheme' ) . "');";
138
+ }
139
+ if ( get_option( 'zopimColor' ) ) {
140
+ $zopim_embed_opts .= "\n\$zopim.livechat.window.setColor('" . get_option( 'zopimColor' ) . "');";
141
+ }
142
 
143
+ if ( get_option( 'zopimUseGreetings' ) == "zopimUseGreetings" ) {
144
+ if ( get_option( 'zopimGreetings' ) != "" ) {
145
+ $greetings = json_to_array( get_option( 'zopimGreetings' ) );
146
+ foreach ( $greetings as $i => $v ) {
147
+ foreach ( $v as $j => $k ) {
148
+ $greetings->$i->$j = str_replace( "\r\n", "\\n", $greetings->$i->$j );
149
  }
150
  }
151
  $zopim_embed_opts .= "\n\$zopim.livechat.setGreetings({
152
+ 'online' : ['" . addslashes( $greetings->online->bar ) . "', '" . addslashes( $greetings->online->window ) . "'],
153
+ 'offline': ['" . addslashes( $greetings->offline->bar ) . "', '" . addslashes( $greetings->offline->window ) . "'],
154
+ 'away' : ['" . addslashes( $greetings->away->bar ) . "', '" . addslashes( $greetings->away->window ) . "'] });";
155
  }
156
  }
157
 
158
+ if ( get_option( 'zopimUseBubble' ) == "zopimUseBubble" ) {
159
+ if ( get_option( 'zopimBubbleTitle' ) ) {
160
+ $zopim_embed_opts .= "\n\$zopim.livechat.bubble.setTitle('" . addslashes( get_option( 'zopimBubbleTitle' ) ) . "');";
161
+ }
162
+ if ( get_option( 'zopimBubbleText' ) ) {
163
+ $zopim_embed_opts .= "\n\$zopim.livechat.bubble.setText('" . addslashes( get_option( 'zopimBubbleText' ) ) . "');";
164
+ }
165
  }
166
 
167
+ if ( get_option( 'zopimBubbleEnable' ) == "show" ) {
168
  $zopim_embed_opts .= "\n\$zopim.livechat.bubble.show(true);";
169
+ } else if ( get_option( 'zopimBubbleEnable' ) == "hide" ) {
170
  $zopim_embed_opts .= "\n\$zopim.livechat.bubble.hide(true);";
171
+ }
172
 
173
  // this must be called last
174
+ if ( get_option( 'zopimHideOnOffline' ) == "zopimHideOnOffline" ) {
175
  $zopim_embed_opts .= "\n\$zopim.livechat.button.setHideWhenOffline(true);";
176
+ }
177
+
178
+ $zopim_embed_opts .= "\n})";
179
 
 
180
  return $zopim_embed_opts;
181
 
182
  }
183
 
184
  function zopim_create_menu() {
185
  //create new top-level menu
186
+ add_menu_page( __( 'Account Configuration', 'zopim' ), __( 'Zopim Chat', 'zopim' ), 'access_zopim',
187
+ 'zopim_account_config', 'zopim_account_config', ZOPIM_SMALL_LOGO );
188
  //call register settings function
189
+ add_action( 'admin_init', 'register_zopim_plugin_settings' );
190
  }
191
 
192
  // Register the option settings we will be using
199
 
200
  }
201
 
202
+ add_action( 'wp_footer', 'zopimme' );
203
  // create custom plugin settings menu
204
+ add_action( 'admin_menu', 'zopim_create_menu' );
205
 
206
+ function zopim_post_request( $url, $_data, $optional_headers = null ) {
207
+ $args = array( 'body' => $_data );
208
  $response = wp_remote_post( $url, $args );
209
+ if ( is_wp_error( $response ) ) {
210
+ $error = array( 'wp_error' => $response->get_error_message() );
211
+
212
+ return json_encode( $error );
213
+ }
214
+
215
  return $response['body'];
216
  }
217
 
218
+ function zopim_url_get( $filename ) {
219
+ $response = wp_remote_get( $filename );
220
+
221
+ if ( is_wp_error( $response ) ) {
222
+ $error = array( 'wp_error' => $response->get_error_message() );
223
+
224
+ return json_encode( $error );
225
+ }
226
+
227
  return $response['body'];
228
  }
229
 
230
+ function json_to_array( $json ) {
231
+ require_once( 'JSON.php' );
232
  $jsonparser = new Services_JSON();
233
+
234
+ return ( $jsonparser->decode( $json ) );
235
  }
236
 
237
+ function to_json( $variable ) {
238
+ require_once( 'JSON.php' );
239
  $jsonparser = new Services_JSON();
240
+
241
+ return ( $jsonparser->encode( $variable ) );
242
  }
243
 
244
+ function zopim_get_account_details( $salt ) {
245
+ $salty = array( "salt" => get_option( 'zopimSalt' ) );
246
+
247
+ return json_to_array( zopim_post_request( ZOPIM_GETACCOUNTDETAILS_URL, $salty ) );
248
  }
249
 
250
+ function zopim_set_editor( $salt ) {
251
+ $salty = array( "salt" => get_option( 'zopimSalt' ) );
252
+
253
+ return json_to_array( zopim_post_request( ZOPIM_SETEDITOR_URL, $salty ) );
254
  }
255
 
256
+ // Load plugin text domain
257
+ load_plugin_textdomain( 'zopim', false, basename( dirname( __FILE__ ) ) . '/languages' );
258
+