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 | Zendesk Chat |
Version | 1.3.8 |
Comparing to | |
See all releases |
Code changes from version 1.3.7 to 1.3.8
- JSON.php +822 -804
- accountconfig.php +167 -144
- languages/zopim.pot +158 -0
- readme.txt +11 -3
- 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 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
/**
|
61 |
-
|
62 |
-
|
63 |
-
define('SERVICES_JSON_SLICE',
|
64 |
-
|
65 |
-
/**
|
66 |
-
|
67 |
-
|
68 |
-
define('SERVICES_JSON_IN_STR',
|
69 |
-
|
70 |
-
/**
|
71 |
-
|
72 |
-
|
73 |
-
define('SERVICES_JSON_IN_ARR',
|
74 |
-
|
75 |
-
/**
|
76 |
-
|
77 |
-
|
78 |
-
define('SERVICES_JSON_IN_OBJ',
|
79 |
-
|
80 |
-
/**
|
81 |
-
|
82 |
-
|
83 |
-
define('SERVICES_JSON_IN_CMT', 5);
|
84 |
-
|
85 |
-
/**
|
86 |
-
|
87 |
-
|
88 |
-
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
89 |
-
|
90 |
-
/**
|
91 |
-
|
92 |
-
|
93 |
-
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
94 |
-
|
95 |
-
/**
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
class Services_JSON
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
if (class_exists('
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
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 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
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
|
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
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
update_option('
|
30 |
-
|
31 |
-
$
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
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
|
|
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
45 |
}
|
46 |
-
|
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"
|
54 |
-
"first_name"
|
55 |
-
"last_name"
|
56 |
-
"display_name"
|
57 |
-
"eref"
|
58 |
-
"source"
|
59 |
"recaptcha_challenge_field" => $_POST["recaptcha_challenge_field"],
|
60 |
-
"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 |
-
|
67 |
-
|
|
|
|
|
|
|
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
|
|
|
71 |
}
|
72 |
}
|
73 |
|
74 |
-
if (get_option('zopimCode') != "" && get_option('zopimCode') != "zopim") {
|
75 |
-
$accountDetails =
|
76 |
|
77 |
-
if (!isset($accountDetails) || isset($accountDetails->error)) {
|
78 |
-
$gotologin
|
79 |
$error["auth"] = '
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
;
|
89 |
} else {
|
90 |
$authenticated = "ok";
|
91 |
}
|
92 |
}
|
93 |
|
94 |
-
if ($authenticated == "ok") {
|
95 |
|
96 |
-
if ($accountDetails->package_id=="trial") {
|
97 |
-
$accountDetails->package_id =
|
98 |
} else {
|
99 |
-
$accountDetails->package_id .=
|
100 |
}
|
101 |
|
102 |
-
?>
|
103 |
-
<div id="icon-options-general" class="icon32"><br/></div
|
104 |
-
<
|
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 → <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> (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 |
-
<
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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' ); ?> →
|
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> (<?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 |
+
<?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:
|
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 |
|
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.
|
9 |
Author URI: http://www.zopim.com/?iref=wp_plugin
|
|
|
|
|
10 |
*/
|
11 |
|
12 |
-
define('VERSION_NUMBER',
|
13 |
-
define('ZOPIM_BASE_URL',
|
14 |
-
define('ZOPIM_ACCOUNT_URL',
|
15 |
-
define('ZOPIM_SIGNUP_REDIRECT_URL',
|
16 |
-
define('ZOPIM_GETACCOUNTDETAILS_URL', ZOPIM_BASE_URL."plugins/getAccountDetails");
|
17 |
-
define('ZOPIM_SETDISPLAYNAME_URL',
|
18 |
-
define('ZOPIM_SETEDITOR_URL',
|
19 |
-
define('ZOPIM_LOGIN_URL',
|
20 |
-
define('ZOPIM_SIGNUP_URL',
|
21 |
-
define('ZOPIM_DASHBOARD_LINK',
|
22 |
-
define('ZOPIM_SMALL_LOGO',
|
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
|
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 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
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/?"
|
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)
|
|
|
|
|
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)
|
108 |
-
|
|
|
|
|
|
|
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'))
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
133 |
-
|
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'))
|
145 |
-
|
|
|
|
|
|
|
|
|
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', '
|
|
|
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('
|
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
|
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 |
-
|
|
|
198 |
}
|
199 |
|
200 |
-
function to_json($variable) {
|
201 |
-
require_once('JSON.php');
|
202 |
$jsonparser = new Services_JSON();
|
203 |
-
|
|
|
204 |
}
|
205 |
|
206 |
-
function
|
207 |
-
$salty = array("salt" => get_option('zopimSalt'));
|
208 |
-
|
|
|
209 |
}
|
210 |
|
211 |
-
function
|
212 |
-
$salty = array("salt" => get_option('zopimSalt'));
|
213 |
-
|
|
|
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 |
+
|