Zendesk Chat - Version 1.3.9

Version Description

  • Refactoring of plugin files
Download this release

Release Info

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

Code changes from version 1.3.8 to 1.3.9

assets/css/zopim.css ADDED
@@ -0,0 +1,70 @@
1
+ .zopim_btn_orange {
2
+ display: inline-block;
3
+ width: 150px;
4
+ padding: 10px 0px;
5
+ background: #F38313;
6
+ color: #fff;
7
+ border-radius: 5px;
8
+ font-weight: 700;
9
+ font-style: normal;
10
+ font-size: 14px;
11
+ border: none;
12
+ text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.2);
13
+ text-decoration: none;
14
+ text-align: center;
15
+ border: 1px solid #E37A13;
16
+ box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.2);
17
+ }
18
+
19
+ .zopim-auth-error-message {
20
+ padding: 10px;
21
+ line-height: 17px;
22
+ }
23
+
24
+ .zopim-login-form {
25
+ padding: 10px;
26
+ }
27
+
28
+ .zopim-error {
29
+ color: red;
30
+ }
31
+
32
+ .zopim-package-title {
33
+ display: inline-block;
34
+ margin-left: 5px;
35
+ background: #444;
36
+ color: #fff;
37
+ font-size: 10px;
38
+ text-transform: uppercase;
39
+ padding: 3px 8px;
40
+ -moz-border-radius: 5px;
41
+ -webkit-border-radius: 5px;
42
+ }
43
+
44
+ .zopim-linked-view-wrapper {
45
+ background: #FFFEEB;
46
+ padding: 25px;
47
+ border: 1px solid #eee;
48
+ }
49
+
50
+ .zopim-linked-view-wrapper > span {
51
+ float: right;
52
+ }
53
+
54
+ a.no-underline {
55
+ text-decoration: none;
56
+ }
57
+
58
+ .zopim-linked-view-wrapper textarea[name="widget-options"] {
59
+ width: 680px;
60
+ height: 200px;
61
+ }
62
+
63
+ .animate {
64
+ background: url('https://dashboard.zopim.com/dashboard/images/spinner.gif') !important;
65
+ background-repeat: no-repeat !important;
66
+ background-color: #2ea2cc !important;
67
+ background-position: center center !important;
68
+ color: #2ea2cc !important;
69
+ opacity: 0.5;
70
+ }
assets/js/zopim.js ADDED
@@ -0,0 +1,3 @@
1
+ function animateButton() {
2
+ document.getElementById("linkup").className += " animate";
3
+ }
includes/JSON.php ADDED
@@ -0,0 +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
+ * 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)#x2F;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( '/^\[.*\]#x2F;s', $str ) || preg_match( '/^\{.*\}#x2F;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.*),?#x2F;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.*),?#x2F;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
+ ?>
includes/class-admin.php ADDED
@@ -0,0 +1,141 @@
1
+ <?php
2
+
3
+ class Zopim_Admin
4
+ {
5
+ private static $_instance = NULL;
6
+
7
+ private function __construct()
8
+ {
9
+ add_action( 'admin_enqueue_scripts', array( &$this, 'load_zopim_style' ) );
10
+ add_action( 'admin_init', array( &$this, 'add_zopim_caps' ) );
11
+ //call register settings function
12
+ add_action( 'admin_init', array( &$this, 'register_zopim_plugin_settings' ) );
13
+ add_action( 'admin_menu', array( &$this, 'zopim_create_menu' ) );
14
+ }
15
+
16
+ /**
17
+ * [get_instance description]
18
+ * @return [type] [description]
19
+ */
20
+ public static function get_instance()
21
+ {
22
+ if ( self::$_instance === NULL )
23
+ self::$_instance = new self();
24
+
25
+ return ( self::$_instance );
26
+ }
27
+
28
+ public function load_zopim_style()
29
+ {
30
+ wp_register_style( 'zopim_style', Zopim::get_asset( 'css/zopim.css' ) );
31
+ wp_enqueue_style( 'zopim_style' );
32
+ wp_register_script( 'zopim_js', Zopim::get_asset( 'js/zopim.js' ) );
33
+ wp_enqueue_script( 'zopim_js' );
34
+ }
35
+
36
+ public function zopim_create_menu()
37
+ {
38
+ //create new top-level menu
39
+ add_menu_page( __( 'Account Configuration', 'zopim' ), __( 'Zopim Chat', 'zopim' ), 'access_zopim', 'zopim_account_config', array( &$this, 'zopim_account_config' ), ZOPIM_SMALL_LOGO );
40
+ }
41
+
42
+
43
+ public function add_zopim_caps()
44
+ {
45
+ $role = get_role( 'administrator' );
46
+ $role->add_cap( 'access_zopim' );
47
+ }
48
+
49
+ // Register the option settings we will be using
50
+ public function register_zopim_plugin_settings()
51
+ {
52
+ // Authentication and codes
53
+ register_setting( 'zopim-settings-group', Zopim_Options::ZOPIM_OPTION_CODE );
54
+ register_setting( 'zopim-settings-group', Zopim_Options::ZOPIM_OPTION_USERNAME );
55
+ register_setting( 'zopim-settings-group', Zopim_Options::ZOPIM_OPTION_SALT );
56
+ }
57
+
58
+ /**
59
+ * Determines which page to display when viewing the plugin admin page and then displays it.
60
+ */
61
+ public function zopim_account_config()
62
+ {
63
+ $notices = Zopim_Notices::get_instance();
64
+ $login = new Zopim_Login();
65
+ $linkedView = new Zopim_Linked_View();
66
+ ?>
67
+ <div class="wrap">
68
+ <?php
69
+ if ( isset( $_GET[ 'action' ] ) && $_GET[ 'action' ] == 'deactivate' ) {
70
+ update_option( Zopim_Options::ZOPIM_OPTION_SALT, '' );
71
+ update_option( Zopim_Options::ZOPIM_OPTION_CODE, 'zopim' );
72
+ }
73
+
74
+ $authenticated = FALSE;
75
+
76
+ if ( isset( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'login' ) {
77
+ $login->do_login();
78
+ }
79
+
80
+ if ( get_option( Zopim_Options::ZOPIM_OPTION_CODE ) != '' && get_option( Zopim_Options::ZOPIM_OPTION_CODE ) != 'zopim' ) {
81
+ $accountDetails = $this->zopim_get_account_details( get_option( Zopim_Options::ZOPIM_OPTION_SALT ) );
82
+
83
+ if ( !isset( $accountDetails ) || isset( $accountDetails->error ) ) {
84
+ $authError = '
85
+ <div class="metabox-holder">
86
+ <div class="postbox">
87
+ <h3 class="hndle"><span>' . __( 'Account no longer linked!', 'zopim' ) . '</span></h3>
88
+ <div class="zopim-auth-error-message">' .
89
+ __( 'We could not verify your Zopim account. Please check your password and try again.', 'zopim' )
90
+ . '</div>
91
+ </div>
92
+ </div>';
93
+ $notices->add_notice( 'before_login', $authError, 'error' );
94
+ } else {
95
+
96
+ $authenticated = TRUE;
97
+ }
98
+ }
99
+
100
+ if ( $authenticated ) {
101
+ if ( isset( $_POST[ 'widget-options' ] ) ) {
102
+ $linkedView->update_widget_options();
103
+ }
104
+ $linkedView->display_linked_view( $accountDetails );
105
+ } else {
106
+ $login->display_login_form();
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Makes a POST request to the Zopim API.
112
+ *
113
+ * @param $url The full url endpoint to access.
114
+ * @param $_data The data to pass to the request.
115
+ * @return array|string
116
+ */
117
+ public function zopim_post_request( $url, $_data )
118
+ {
119
+ $args = array( 'body' => $_data );
120
+ $response = wp_remote_post( $url, $args );
121
+ if ( is_wp_error( $response ) ) {
122
+ $error = array( 'wp_error' => $response->get_error_message() );
123
+
124
+ return json_encode( $error );
125
+ }
126
+
127
+ return $response[ 'body' ];
128
+ }
129
+
130
+ /**
131
+ * Gets the current user's Zopim account details.
132
+ *
133
+ * @return array|mixed
134
+ */
135
+ public function zopim_get_account_details()
136
+ {
137
+ $salty = array( "salt" => get_option( Zopim_Options::ZOPIM_OPTION_SALT ) );
138
+
139
+ return json_decode( $this->zopim_post_request( ZOPIM_GETACCOUNTDETAILS_URL, $salty ) );
140
+ }
141
+ }
includes/class-base-view.php ADDED
@@ -0,0 +1,19 @@
1
+ <?php
2
+
3
+ abstract class Zopim_Base_View
4
+ {
5
+ protected $_messages = array();
6
+
7
+ public function __construct()
8
+ {
9
+ $this->set_messages();
10
+ }
11
+
12
+ // Force inheriting classes to set messages
13
+ abstract protected function set_messages();
14
+
15
+ public function get_message( $key )
16
+ {
17
+ return $this->_messages[ $key ];
18
+ }
19
+ }
includes/class-linked-view.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ class Zopim_Linked_View extends Zopim_Base_View
4
+ {
5
+ protected function set_messages()
6
+ {
7
+ $this->_messages = array(
8
+ 'options-updated' => __( 'Widget options updated.', 'zopim' ),
9
+ 'trial' => __( 'Trial Plan with 14 Days Full-features', 'zopim' ),
10
+ 'plan' => __( ' Plan', 'zopim' ),
11
+ 'deactivate' => __( 'Deactivate', 'zopim' ),
12
+ 'current-account-label' => __( 'Currently Activated Account', 'zopim' ),
13
+ 'dashboard-access-label' => __( 'To start using Zopim chat, launch our dashboard for access to all features, including widget customization!', 'zopim' ),
14
+ 'launch-dashboard' => __( 'Launch Dashboard', 'zopim' ),
15
+ 'open-tab-label' => __( 'This will open up a new browser tab', 'zopim' ),
16
+ 'textarea-label' => __( 'Optional code for customization with Zopim API:', 'zopim' ),
17
+ 'page-header' => __( 'Set up your Zopim Account', 'zopim' ),
18
+ );
19
+ }
20
+
21
+ /**
22
+ * Handles POST request when saving the Widget Options form.
23
+ */
24
+ public function update_widget_options()
25
+ {
26
+ $notices = Zopim_Notices::get_instance();
27
+ $opts = $_POST[ 'widget-options' ];
28
+ update_option( Zopim_Options::ZOPIM_OPTION_WIDGET, $opts );
29
+ $notices->add_notice( 'before_udpate_widget_textarea', '<i>' . $this->get_message( 'options-updated' ) . '<br/></i>', 'notice' );
30
+ }
31
+
32
+ /**
33
+ * Renders the Zopim update options form.
34
+ *
35
+ * @param object Account details retrieved from the Zopim API
36
+ */
37
+ public function display_linked_view( $accountDetails )
38
+ {
39
+ if ( $accountDetails->package_id == 'trial' ) {
40
+ $accountDetails->package_id = $this->get_message( 'trial' );
41
+ } else {
42
+ $accountDetails->package_id .= $this->get_message( 'plan' );
43
+ }
44
+
45
+ Zopim_Template::load_template( 'linked-view', array_merge( array( 'messages' => $this->_messages ), (array)$accountDetails ) );
46
+ }
47
+ }
includes/class-login.php ADDED
@@ -0,0 +1,67 @@
1
+ <?php
2
+
3
+ class Zopim_Login extends Zopim_Base_View
4
+ {
5
+ protected function set_messages()
6
+ {
7
+ $this->_messages = array(
8
+ 'login-fail' => __( 'Could not log in to Zopim. Please check your login details.', 'zopim' ),
9
+ 'wp-login-error' => __( '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', 'zopim' ),
10
+ 'setup-your-account' => __( 'Set up your Zopim Account', 'zopim' ),
11
+ 'congratulations' => __( 'Congratulations on successfully installing the Zopim WordPress plugin!', 'zopim' ),
12
+ 'link-up-title' => __( 'Link up with your Zopim account', 'zopim' ),
13
+ 'username' => __( 'Zopim Username (E-mail)', 'zopim' ),
14
+ 'password' => __( 'Zopim Password', 'zopim' ),
15
+ 'widget-display-notice' => __( 'The Zopim chat widget will display on your blog after your account is linked up.', 'zopim' ),
16
+ 'link-up-button' => __( 'Link Up', 'zopim' ),
17
+ 'sign-up-link' => __( 'Sign up now', 'zopim' ),
18
+ );
19
+ }
20
+
21
+ public function do_login()
22
+ {
23
+ $admin = Zopim_Admin::get_instance();
24
+ $notices = Zopim_Notices::get_instance();
25
+
26
+ if ( $_POST[ Zopim_Options::ZOPIM_OPTION_USERNAME ] != '' && $_POST[ 'zopimPassword' ] != '' ) {
27
+
28
+ $logindata = array( 'email' => $_POST[ Zopim_Options::ZOPIM_OPTION_USERNAME ], 'password' => $_POST[ 'zopimPassword' ] );
29
+ $loginresult = json_decode( $admin->zopim_post_request( ZOPIM_LOGIN_URL, $logindata ) );
30
+
31
+ if ( isset( $loginresult->error ) ) {
32
+ $notices->add_notice( 'login_form', $this->get_message( 'login-fail' ), 'error' );
33
+
34
+ update_option( Zopim_Options::ZOPIM_OPTION_SALT, 'wronglogin' );
35
+ } else if ( isset( $loginresult->salt ) ) {
36
+ update_option( Zopim_Options::ZOPIM_OPTION_USERNAME, $_POST[ Zopim_Options::ZOPIM_OPTION_USERNAME ] );
37
+ update_option( Zopim_Options::ZOPIM_OPTION_SALT, $loginresult->salt );
38
+ $account = $admin->zopim_get_account_details( get_option( Zopim_Options::ZOPIM_OPTION_SALT ) );
39
+
40
+ if ( isset( $account ) ) {
41
+ update_option( Zopim_Options::ZOPIM_OPTION_CODE, $account->account_key );
42
+
43
+ if ( get_option( 'zopimGreetings' ) == '' ) {
44
+ $jsongreetings = json_encode( $account->settings->greetings );
45
+
46
+ update_option( 'zopimGreetings', $jsongreetings );
47
+ }
48
+ }
49
+ } else {
50
+ update_option( Zopim_Options::ZOPIM_OPTION_SALT, '' );
51
+ $notices->add_notice( 'login_form', $this->get_message( 'wp-login-error' ), 'error' );
52
+ }
53
+ } else {
54
+ update_option( Zopim_Options::ZOPIM_OPTION_SALT, "wronglogin" );
55
+ $notices->add_notice( 'login_form', $this->get_message( 'login-fail' ), 'error' );
56
+ }
57
+ }
58
+
59
+ /**
60
+ *
61
+ */
62
+ public function display_login_form()
63
+ {
64
+ $notices = Zopim_Notices::get_instance();
65
+ Zopim_Template::load_template( 'login-form', array( 'notices' => $notices, 'messages' => $this->_messages ) );
66
+ }
67
+ }
includes/class-notices.php ADDED
@@ -0,0 +1,94 @@
1
+ <?php
2
+
3
+ /**
4
+ * The Notices Class
5
+ *
6
+ * This is a helper class to display notices.
7
+ *
8
+ */
9
+ class Zopim_Notices
10
+ {
11
+ protected static $instance = NULL;
12
+ protected $notices = array();
13
+
14
+ /*
15
+ * get an instance of this class
16
+ */
17
+ public static function get_instance()
18
+ {
19
+ if ( is_null( self::$instance ) ) {
20
+ self::$instance = new self();
21
+ }
22
+
23
+ return self::$instance;
24
+ }
25
+
26
+ /**
27
+ * Returns the current notices defined.
28
+ *
29
+ * @return array
30
+ */
31
+ public function get_notices()
32
+ {
33
+ return $this->notices;
34
+ }
35
+
36
+ /*
37
+ * Add Notice
38
+ *
39
+ * An internal function to add a notice to a specific context, where
40
+ * contexts are "places" that display notice messages, such as
41
+ * 'login_form' or 'tickets_widget'. The $text is the text to display
42
+ * and the $type is either 'note', 'confirm', or 'alert' which
43
+ * differs in colors when output.
44
+ *
45
+ */
46
+ public function add_notice( $context, $text, $type = 'note' )
47
+ {
48
+ if ( isset( $this->notices[ $context . '_' . $type ] ) ) {
49
+ $this->notices[ $context . '_' . $type ][ ] = $text;
50
+ } else {
51
+ $this->notices[ $context . '_' . $type ] = array( $text );
52
+ }
53
+ }
54
+
55
+ /*
56
+ * Do Notices
57
+ *
58
+ * Process all the added notices for a specific context and output
59
+ * them on screen using the _notice function. Loops through notes,
60
+ * confirms and alerts for the given context.
61
+ *
62
+ */
63
+ public function do_notices( $context )
64
+ {
65
+ echo '<div class="zopim-notices-group">';
66
+ foreach ( array( 'error', 'notice' ) as $type ) {
67
+ if ( isset( $this->notices[ $context . '_' . $type ] ) ) {
68
+ $notices = $this->notices[ $context . '_' . $type ];
69
+
70
+ foreach ( $notices as $notice ) {
71
+ $this->_notice( $notice, $type );
72
+ }
73
+ }
74
+ }
75
+ echo '</div>';
76
+ }
77
+
78
+ /*
79
+ * Notice
80
+ *
81
+ * Prints the notice to screen given a certain $type, which can be
82
+ * 'note', 'alert' and 'confirm' according to the stylesheets.
83
+ *
84
+ */
85
+ private function _notice( $text, $type = 'note' )
86
+ {
87
+ ?>
88
+ <div class="zopim-admin-notice zopim-<?php echo $type; ?>">
89
+ <p><?php echo $text; ?></p>
90
+ </div>
91
+ <?php
92
+ }
93
+
94
+ }
includes/class-options.php ADDED
@@ -0,0 +1,45 @@
1
+ <?php
2
+
3
+ class Zopim_Options
4
+ {
5
+ const ZOPIM_OPTION_SALT = 'zopimSalt';
6
+ const ZOPIM_OPTION_USERNAME = 'zopimUsername';
7
+ const ZOPIM_OPTION_CODE = 'zopimCode';
8
+ const ZOPIM_OPTION_WIDGET = 'zopimWidgetOptions';
9
+
10
+ /**
11
+ * Returns the addional widget options set on the plugin dashboard.
12
+ * @return string
13
+ */
14
+ public static function get_widget_options()
15
+ {
16
+ $opts = get_option( self::ZOPIM_OPTION_WIDGET );
17
+ if ( $opts )
18
+ return stripslashes( $opts );
19
+
20
+ $zopim_embed_opts = "\$zopim( function() {";
21
+ $zopim_embed_opts .= "\n})";
22
+ $opts = $zopim_embed_opts;
23
+
24
+ update_option( self::ZOPIM_OPTION_WIDGET, $opts );
25
+
26
+ $list = array(
27
+ 'zopimLang',
28
+ 'zopimPosition',
29
+ 'zopimTheme',
30
+ 'zopimColor',
31
+ 'zopimUseGreetings',
32
+ 'zopimUseBubble',
33
+ 'zopimBubbleTitle',
34
+ 'zopimBubbleText',
35
+ 'zopimBubbleEnable',
36
+ 'zopimHideOnOffline'
37
+ );
38
+
39
+ foreach ( $list as $key ):
40
+ delete_option( $key );
41
+ endforeach;
42
+
43
+ return ( $opts ) ? $opts : '';
44
+ }
45
+ }
includes/class-template.php ADDED
@@ -0,0 +1,23 @@
1
+ <?php
2
+
3
+ class Zopim_Template
4
+ {
5
+ /**
6
+ * Displays a view file. This will look for the correctly named view file in the `/views/` folder.
7
+ *
8
+ * @since 0.2
9
+ *
10
+ * @param String $name The filename of the view to display.
11
+ * @param Array $params An associative array of variables you want to pass to the view.
12
+ * e.g. ['count' => 1], which you can do "<?php echo $count ?>;" in the view.
13
+ */
14
+ public static function load_template( $name, $params = array() )
15
+ {
16
+ ob_start();
17
+
18
+ extract( $params );
19
+ include( ZOPIM_PLUGIN_DIR . 'includes/views/' . $name . '.php' );
20
+
21
+ ob_end_flush();
22
+ }
23
+ }
includes/class-widget.php ADDED
@@ -0,0 +1,40 @@
1
+ <?php
2
+
3
+ class Zopim_Widget
4
+ {
5
+ // We need some CSS to position the paragraph
6
+ public static function zopimme()
7
+ {
8
+ global $current_user;
9
+ get_currentuserinfo();
10
+
11
+ $code = get_option( Zopim_Options::ZOPIM_OPTION_CODE );
12
+
13
+ if ( ( $code == "" || $code == "zopim" ) && !( isset( $_GET[ 'page' ] ) && preg_match( "/zopim/", $_GET[ 'page' ] ) ) && ( !preg_match( "/zopim/", $_SERVER[ "SERVER_NAME" ] ) ) ) {
14
+ return;
15
+ }
16
+
17
+ echo "<!--Embed from Zopim Live Chat Wordpress Plugin v" . VERSION_NUMBER . "-->
18
+ <!--Start of Zopim Live Chat Script-->
19
+ <script type=\"text/javascript\">
20
+ window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=z.s=
21
+ d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o){z.set.
22
+ _.push(o)};z._=[];z.set._=[];$.async=!0;$.setAttribute('charset','utf-8');
23
+ $.src='//v2.zopim.com/?" . $code . "';z.t=+new Date;$.
24
+ type='text/javascript';e.parentNode.insertBefore($,e)})(document,'script');
25
+ </script>";
26
+
27
+ echo '<script>';
28
+ if ( isset( $current_user ) ):
29
+ $firstname = $current_user->display_name;
30
+ $useremail = $current_user->user_email;
31
+ if ( $firstname != "" && $useremail != "" ):
32
+ echo "\$zopim(function(){\$zopim.livechat.set({name: '$firstname', email: '$useremail'}); });";
33
+ endif;
34
+ endif;
35
+
36
+ echo Zopim_Options::get_widget_options();
37
+ echo '</script>';
38
+ echo "<!--End of Zopim Live Chat Script-->";
39
+ }
40
+ }
includes/compatibility.php ADDED
@@ -0,0 +1,22 @@
1
+ <?php
2
+
3
+ if ( !function_exists( 'json_decode' ) ) {
4
+ function json_decode( $json )
5
+ {
6
+ require_once( 'JSON.php' );
7
+ $jsonparser = new Services_JSON();
8
+
9
+ return $jsonparser->decode( $json );
10
+ }
11
+ }
12
+
13
+ if ( !function_exists( 'json_encode' ) ) {
14
+
15
+ function json_encode( $variable )
16
+ {
17
+ require_once( 'JSON.php' );
18
+ $jsonparser = new Services_JSON();
19
+
20
+ return $jsonparser->encode( $variable );
21
+ }
22
+ }
includes/views/linked-view.php ADDED
@@ -0,0 +1,39 @@
1
+ <div id="icon-options-general" class="icon32"><br/></div>
2
+ <h2><?php echo $messages[ 'page-header' ] ?></h2>
3
+ <br/>
4
+ <div class="zopim-linked-view-wrapper">
5
+ <span>
6
+ <a
7
+ href="admin.php?page=zopim_account_config&action=deactivate"><?php echo $messages[ 'deactivate' ] ?></a>
8
+ </span>
9
+ <?php echo $messages[ 'current-account-label' ] ?> &rarr;
10
+ <b><?php echo get_option( Zopim_Options::ZOPIM_OPTION_USERNAME ); ?></b>
11
+
12
+ <div class="zopim-package-title"><?php echo ucwords( $package_id ); ?></div>
13
+
14
+ <br><br><?php echo $messages[ 'dashboard-access-label' ]; ?>
15
+ <br><br>
16
+ <a class="no-underline" href="<?php echo ZOPIM_DASHBOARD_LINK . "&username=" . get_option( Zopim_Options::ZOPIM_OPTION_USERNAME ); ?>"
17
+ target="_blank"
18
+ data-popup="true">
19
+ <div class="zopim_btn_orange"><?php echo $messages[ 'launch-dashboard' ]; ?></div>
20
+ </a>
21
+ &nbsp;&nbsp;(<?php echo $messages[ 'open-tab-label' ]; ?>)
22
+
23
+
24
+ <form method="post" action="admin.php?page=zopim_account_config">
25
+ <?php
26
+ $notices = Zopim_Notices::get_instance();
27
+ $notices->do_notices( 'before_udpate_widget_textarea' );
28
+ ?>
29
+ <p>
30
+ <?php echo $messages[ 'textarea-label' ]; ?>
31
+ <br/>
32
+ <textarea name="widget-options"><?php echo esc_textarea( Zopim_Options::get_widget_options() ); ?></textarea>
33
+ <br/>
34
+ <input class="button-primary" type="submit" value="Update widget options"/>
35
+ </p>
36
+ </form>
37
+
38
+ </div>
39
+
includes/views/login-form.php ADDED
@@ -0,0 +1,52 @@
1
+ <div id="icon-options-general" class="icon32"><br/></div>
2
+ <h2><?php echo $messages[ 'setup-your-account' ]; ?></h2>
3
+ <?php
4
+ $noticesArray = $notices->get_notices();
5
+ $hasErrors = ( isset( $noticesArray[ 'before_login_error' ] ) && ( $noticesCount = count( $noticesArray[ 'before_login_error' ] ) ) > 0 ) ? $noticesCount : 0;
6
+ if ( !$hasErrors ) {
7
+ echo $messages[ 'congratulations' ];
8
+ }
9
+ $notices->do_notices( 'before_login' );
10
+ ?>
11
+ <div id="existingform">
12
+ <div class="metabox-holder">
13
+ <div class="postbox">
14
+ <h3 class="hndle"><span><?php echo $messages[ 'link-up-title' ]; ?></span></h3>
15
+
16
+ <div class="zopim-login-form">
17
+ <?php $notices->do_notices( 'login_form' ); ?>
18
+ <form method="post" action="admin.php?page=zopim_account_config">
19
+ <input type="hidden" name="action" value="login">
20
+ <table class="form-table">
21
+
22
+ <tr valign="top">
23
+ <th scope="row"><?php echo $messages[ 'username' ]; ?></th>
24
+ <td><input type="text" name="zopimUsername"
25
+ value="<?php echo get_option( Zopim_Options::ZOPIM_OPTION_USERNAME ); ?>"/>
26
+ </td>
27
+ </tr>
28
+
29
+ <tr valign="top">
30
+ <th scope="row"><?php echo $messages[ 'password' ]; ?></th>
31
+ <td><input type="password" name="zopimPassword" value=""/></td>
32
+ </tr>
33
+
34
+ </table>
35
+ <br/>
36
+ <?php echo $messages[ 'widget-display-notice' ]; ?>
37
+ <br/>
38
+
39
+ <p class="submit">
40
+ <input id="linkup" type="submit" onclick="animateButton()" class="button-primary"
41
+ value="<?php echo $messages[ 'link-up-button' ] ?>"/>
42
+ &nbsp;<?php _e( 'Don\'t have a Zopim account?', 'zopim' ); ?> <a
43
+ href="<?php echo ZOPIM_SIGNUP_REDIRECT_URL; ?>" target="_blank"
44
+ data-popup="true"><?php echo $messages[ 'sign-up-link' ]; ?></a>.
45
+ </p>
46
+
47
+ </form>
48
+
49
+ </div>
50
+ </div>
51
+ </div>
52
+ </div>
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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,6 +48,9 @@ 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.8 =
52
* Fix throwing of wordpress errors
53
* Fix PHP notice ('Notice: Undefined variable: error') on the plugin dashboard
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.9
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.9 =
52
+ * Refactoring of plugin files
53
+
54
= 1.3.8 =
55
* Fix throwing of wordpress errors
56
* Fix PHP notice ('Notice: Undefined variable: error') on the plugin dashboard
zopim.php CHANGED
@@ -5,13 +5,13 @@ 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" );
@@ -22,237 +22,74 @@ 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() {
37
- $role = get_role( 'administrator' );
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;
75
-
76
- echo zopim_get_widget_options();
77
- echo '</script>';
78
- echo "<!--End of Zopim Live Chat Script-->";
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',
96
- 'zopimPosition',
97
- 'zopimTheme',
98
- 'zopimColor',
99
- 'zopimUseGreetings',
100
- 'zopimUseBubble',
101
- 'zopimBubbleTitle',
102
- 'zopimBubbleText',
103
- 'zopimBubbleEnable',
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
193
- function register_zopim_plugin_settings() {
194
-
195
- // Authentication and codes
196
- register_setting( 'zopim-settings-group', 'zopimCode' );
197
- register_setting( 'zopim-settings-group', 'zopimUsername' );
198
- register_setting( 'zopim-settings-group', 'zopimSalt' );
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
-
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
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.9" );
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" );
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
+ define( 'ZOPIM_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
26
+
27
+ require_once( 'includes/compatibility.php' );
28
+
29
+ class Zopim
30
+ {
31
+ private static $_instance = NULL;
32
+
33
+ private function __construct()
34
+ {
35
+ spl_autoload_register( array( &$this, 'autoload' ) );
36
+
37
+ if ( is_admin() ) {
38
+ Zopim_Admin::get_instance();
39
+ }
40
+
41
+ add_action( 'wp_footer', array( 'Zopim_Widget', 'zopimme' ) );
42
+ add_action( 'plugins_loaded', array( &$this, 'load_textdomain' ) );
43
+ }
44
+
45
+ /**
46
+ * [get_instance description]
47
+ * @return [type] [description]
48
+ */
49
+ public static function get_instance()
50
+ {
51
+ if ( self::$_instance === NULL )
52
+ self::$_instance = new self();
53
+
54
+ return ( self::$_instance );
55
+ }
56
+
57
+ /*
58
+ * autoloading callback function
59
+ * @param string $class name of class to autoload
60
+ * @return TRUE to continue; otherwise FALSE
61
+ */
62
+ public function autoload( $class )
63
+ {
64
+ // setup the class name
65
+ $classname = str_replace( 'Zopim_', '', $class );
66
+ $classname = strtolower( str_replace( '_', '-', $classname ) );
67
+
68
+ $classfile = ZOPIM_PLUGIN_DIR . 'includes/class-' . $classname . '.php';
69
+
70
+ if ( file_exists( $classfile ) ) {
71
+ require_once( $classfile );
72
+ }
73
+ }
74
+
75
+ /*
76
+ * return reference to asset, relative to the base plugin's /assets/ directory
77
+ * @param string $ref asset name to reference
78
+ * @return string href to fully qualified location of referenced asset
79
+ */
80
+ public static function get_asset( $ref )
81
+ {
82
+ $ret = plugin_dir_url( __FILE__ ) . 'assets/' . $ref;
83
+
84
+ return ( $ret );
85
+ }
86
+
87
+ public function load_textdomain()
88
+ {
89
+ // Load plugin text domain
90
+ load_plugin_textdomain( 'zopim', FALSE, basename( dirname( __FILE__ ) ) . '/languages' );
91
+ }
92
93
}
94
95
+ Zopim::get_instance();