Zendesk Chat - Version 1.1.0

Version Description

  • Maintenace update: Greeting messages are now saved properly.
  • Add more language options in customization page.
  • Using new Zopim async embed script: improve page's load time and do not block page's rendering anymore.
Download this release

Release Info

Developer bencxr
Plugin Icon 128x128 Zendesk Chat
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.7 to 1.1.0

customizewidget.php CHANGED
@@ -142,6 +142,8 @@ function zopim_customize_widget() {
142
  var el = document.getElementById(inputs[i]);
143
  el.disabled = isDisabled;
144
  }
 
 
145
  }
146
 
147
  var timer;
@@ -340,7 +342,7 @@ line-height:21px;
340
  </div>
341
 
342
  <?php
343
- if (get_option("zopimUseGreetings") && get_option("zopimUseGreetings"!="disabled")) {
344
  $useGreetings = true;
345
  } else {
346
  $useGreetings = false;
@@ -354,7 +356,7 @@ line-height:21px;
354
  <tr>
355
  <td colspan="2">
356
  <input type="checkbox" id="zopimUseGreetings" onchange="greetingsChanged()" value="zopimUseGreetings" name="zopimUseGreetings"
357
- <?php if (get_option('zopimUseGreetings') && get_option('zopimUseGreetings')!="disabled") { echo "checked='checked'"; } ?>/>
358
  Use these greeting messages
359
  </td>
360
  </tr>
@@ -450,16 +452,13 @@ function generate_options($options, $current) {
450
  }
451
 
452
  function get_languages() {
453
-
454
- $langjson = '{"--":" - Auto Detect - ","ar":"Arabic","bg":"Bulgarian","cs":"Czech","da":"Danish","de":"German","en":"English","es":"Spanish; Castilian","fa":"Persian","fo":"Faroese","fr":"French","he":"Hebrew","hr":"Croatian","id":"Indonesian","it":"Italian","ja":"Japanese","ko":"Korean","ms":"Malay","nb":"Norwegian Bokmal","nl":"Dutch; Flemish","pl":"Polish","pt":"Portuguese","ru":"Russian","sk":"Slovak","sl":"Slovenian","sv":"Swedish","th":"Thai","tr":"Turkish","ur":"Urdu","vi":"Vietnamese","zh_CN":"Chinese (China)"}hihi{"--":" - Auto Detect - ","ar":"Arabic","bg":"Bulgarian","cs":"Czech","da":"Danish","de":"German","en":"English","es":"Spanish; Castilian","fa":"Persian","fo":"Faroese","fr":"French","he":"Hebrew","hr":"Croatian","id":"Indonesian","it":"Italian","ja":"Japanese","ko":"Korean","ms":"Malay","nb":"Norwegian Bokmal","nl":"Dutch; Flemish","pl":"Polish","pt":"Portuguese","ru":"Russian","sk":"Slovak","sl":"Slovenian","sv":"Swedish","th":"Thai","tr":"Turkish","ur":"Urdu","vi":"Vietnamese","zh_CN":"Chinese (China)"}';
455
 
456
  return json_to_array($langjson);
457
  }
458
 
459
  function update_checkbox($fieldname) {
460
  if (isset($_POST["$fieldname"]) && $_POST["$fieldname"] != "") {
461
- echo $fieldname." : ".$_POST["$fieldname"];
462
-
463
  update_option($fieldname, $_POST["$fieldname"]);
464
  } else {
465
  update_option($fieldname, "disabled");
142
  var el = document.getElementById(inputs[i]);
143
  el.disabled = isDisabled;
144
  }
145
+
146
+ updateWidget();
147
  }
148
 
149
  var timer;
342
  </div>
343
 
344
  <?php
345
+ if (get_option('zopimUseGreetings') && get_option('zopimUseGreetings')!="disabled") {
346
  $useGreetings = true;
347
  } else {
348
  $useGreetings = false;
356
  <tr>
357
  <td colspan="2">
358
  <input type="checkbox" id="zopimUseGreetings" onchange="greetingsChanged()" value="zopimUseGreetings" name="zopimUseGreetings"
359
+ <?php if ($useGreetings) { echo "checked='checked'"; } ?>/>
360
  Use these greeting messages
361
  </td>
362
  </tr>
452
  }
453
 
454
  function get_languages() {
455
+ $langjson = '{"--":" - Auto Detect - ","ar":"Arabic","bn":"Bengali","bg":"Bulgarian","zh_CN":"Chinese (China)","zh_TW":"Chinese (Taiwan)","hr":"Croatian","cs":"Czech","da":"Danish","nl":"Dutch; Flemish","et":"Estonian","fo":"Faroese","fi":"Finnish","fr":"French","ka":"Georgian","de":"German","el":"Greek","he":"Hebrew","hu":"Hungarian","is":"Icelandic","id":"Indonesian","it":"Italian","ja":"Japanese","ko":"Korean","ku":"Kurdish","lv":"Latvian","lt":"Lithuanian","mk":"Macedonian","ms":"Malay","nb":"Norwegian Bokmal","fa":"Persian","pl":"Polish","pt":"Portuguese","pt_BR":"Portuguese (Brazil)","ro":"Romanian","ru":"Russian","sr":"Serbian","sk":"Slovak","sl":"Slovenian","es":"Spanish; Castilian","sv":"Swedish","th":"Thai","tr":"Turkish","uk":"Ukrainian","ur":"Urdu","vi":"Vietnamese"}';
 
456
 
457
  return json_to_array($langjson);
458
  }
459
 
460
  function update_checkbox($fieldname) {
461
  if (isset($_POST["$fieldname"]) && $_POST["$fieldname"] != "") {
 
 
462
  update_option($fieldname, $_POST["$fieldname"]);
463
  } else {
464
  update_option($fieldname, "disabled");
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: bencxr
3
  Tags: widget, plugin, sidebar, page, admin, enhancement, livechat, chat, widget
4
  Requires at least: 2.7
5
- Tested up to: 3.0.3
6
- Stable tag: 1.0.7
7
 
8
  Zopim is an award winning facebook-like chatbar built for websites. It connects website owners and visitors together via a cross-browser platform.
9
 
@@ -44,6 +44,11 @@ Zopim shows up as a chatbar docked to the bottom of your website. Visitors chat
44
 
45
 
46
  == Changelog ==
 
 
 
 
 
47
  = 1.0.7 =
48
  * Maintenance update: Remove phased out "middle left", "middle right" positions
49
  * Add options to let user decides hiding of chat bubble, no longer force show/hide
2
  Contributors: bencxr
3
  Tags: widget, plugin, sidebar, page, admin, enhancement, livechat, chat, widget
4
  Requires at least: 2.7
5
+ Tested up to: 3.1.1
6
+ Stable tag: 1.1.0
7
 
8
  Zopim is an award winning facebook-like chatbar built for websites. It connects website owners and visitors together via a cross-browser platform.
9
 
44
 
45
 
46
  == Changelog ==
47
+ = 1.1.0 =
48
+ * Maintenace update: Greeting messages are now saved properly.
49
+ * Add more language options in customization page.
50
+ * Using new Zopim async embed script: improve page's load time and do not block page's rendering anymore.
51
+
52
  = 1.0.7 =
53
  * Maintenance update: Remove phased out "middle left", "middle right" positions
54
  * Add options to let user decides hiding of chat bubble, no longer force show/hide
trunk/JSON.php ADDED
@@ -0,0 +1,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
+ /**
119
+ * constructs a new JSON instance
120
+ *
121
+ * @param int $use object behavior flags; combine with boolean-OR
122
+ *
123
+ * possible values:
124
+ * - SERVICES_JSON_LOOSE_TYPE: loose typing.
125
+ * "{...}" syntax creates associative arrays
126
+ * instead of objects in decode().
127
+ * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
128
+ * Values which can't be encoded (e.g. resources)
129
+ * appear as NULL instead of throwing errors.
130
+ * By default, a deeply-nested resource will
131
+ * bubble up with an error, so all return values
132
+ * from encode() should be checked with isError()
133
+ */
134
+ function Services_JSON($use = 0)
135
+ {
136
+ $this->use = $use;
137
+ }
138
+
139
+ /**
140
+ * convert a string from one UTF-16 char to one UTF-8 char
141
+ *
142
+ * Normally should be handled by mb_convert_encoding, but
143
+ * provides a slower PHP-only method for installations
144
+ * that lack the multibye string extension.
145
+ *
146
+ * @param string $utf16 UTF-16 character
147
+ * @return string UTF-8 character
148
+ * @access private
149
+ */
150
+ function utf162utf8($utf16)
151
+ {
152
+ // oh please oh please oh please oh please oh please
153
+ if(function_exists('mb_convert_encoding')) {
154
+ return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
155
+ }
156
+
157
+ $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
158
+
159
+ switch(true) {
160
+ case ((0x7F & $bytes) == $bytes):
161
+ // this case should never be reached, because we are in ASCII range
162
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
163
+ return chr(0x7F & $bytes);
164
+
165
+ case (0x07FF & $bytes) == $bytes:
166
+ // return a 2-byte UTF-8 character
167
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
168
+ return chr(0xC0 | (($bytes >> 6) & 0x1F))
169
+ . chr(0x80 | ($bytes & 0x3F));
170
+
171
+ case (0xFFFF & $bytes) == $bytes:
172
+ // return a 3-byte UTF-8 character
173
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
174
+ return chr(0xE0 | (($bytes >> 12) & 0x0F))
175
+ . chr(0x80 | (($bytes >> 6) & 0x3F))
176
+ . chr(0x80 | ($bytes & 0x3F));
177
+ }
178
+
179
+ // ignoring UTF-32 for now, sorry
180
+ return '';
181
+ }
182
+
183
+ /**
184
+ * convert a string from one UTF-8 char to one UTF-16 char
185
+ *
186
+ * Normally should be handled by mb_convert_encoding, but
187
+ * provides a slower PHP-only method for installations
188
+ * that lack the multibye string extension.
189
+ *
190
+ * @param string $utf8 UTF-8 character
191
+ * @return string UTF-16 character
192
+ * @access private
193
+ */
194
+ function utf82utf16($utf8)
195
+ {
196
+ // oh please oh please oh please oh please oh please
197
+ if(function_exists('mb_convert_encoding')) {
198
+ return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
199
+ }
200
+
201
+ switch(strlen($utf8)) {
202
+ case 1:
203
+ // this case should never be reached, because we are in ASCII range
204
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
205
+ return $utf8;
206
+
207
+ case 2:
208
+ // return a UTF-16 character from a 2-byte UTF-8 char
209
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
210
+ return chr(0x07 & (ord($utf8{0}) >> 2))
211
+ . chr((0xC0 & (ord($utf8{0}) << 6))
212
+ | (0x3F & ord($utf8{1})));
213
+
214
+ case 3:
215
+ // return a UTF-16 character from a 3-byte UTF-8 char
216
+ // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
217
+ return chr((0xF0 & (ord($utf8{0}) << 4))
218
+ | (0x0F & (ord($utf8{1}) >> 2)))
219
+ . chr((0xC0 & (ord($utf8{1}) << 6))
220
+ | (0x7F & ord($utf8{2})));
221
+ }
222
+
223
+ // ignoring UTF-32 for now, sorry
224
+ return '';
225
+ }
226
+
227
+ /**
228
+ * encodes an arbitrary variable into JSON format
229
+ *
230
+ * @param mixed $var any number, boolean, string, array, or object to be encoded.
231
+ * see argument 1 to Services_JSON() above for array-parsing behavior.
232
+ * if var is a strng, note that encode() always expects it
233
+ * to be in ASCII or UTF-8 format!
234
+ *
235
+ * @return mixed JSON string representation of input var or an error if a problem occurs
236
+ * @access public
237
+ */
238
+ function encode($var)
239
+ {
240
+ switch (gettype($var)) {
241
+ case 'boolean':
242
+ return $var ? 'true' : 'false';
243
+
244
+ case 'NULL':
245
+ return 'null';
246
+
247
+ case 'integer':
248
+ return (int) $var;
249
+
250
+ case 'double':
251
+ case 'float':
252
+ return (float) $var;
253
+
254
+ case 'string':
255
+ // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
256
+ $ascii = '';
257
+ $strlen_var = strlen($var);
258
+
259
+ /*
260
+ * Iterate over every character in the string,
261
+ * escaping with a slash or encoding to UTF-8 where necessary
262
+ */
263
+ for ($c = 0; $c < $strlen_var; ++$c) {
264
+
265
+ $ord_var_c = ord($var{$c});
266
+
267
+ switch (true) {
268
+ case $ord_var_c == 0x08:
269
+ $ascii .= '\b';
270
+ break;
271
+ case $ord_var_c == 0x09:
272
+ $ascii .= '\t';
273
+ break;
274
+ case $ord_var_c == 0x0A:
275
+ $ascii .= '\n';
276
+ break;
277
+ case $ord_var_c == 0x0C:
278
+ $ascii .= '\f';
279
+ break;
280
+ case $ord_var_c == 0x0D:
281
+ $ascii .= '\r';
282
+ break;
283
+
284
+ case $ord_var_c == 0x22:
285
+ case $ord_var_c == 0x2F:
286
+ case $ord_var_c == 0x5C:
287
+ // double quote, slash, slosh
288
+ $ascii .= '\\'.$var{$c};
289
+ break;
290
+
291
+ case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
292
+ // characters U-00000000 - U-0000007F (same as ASCII)
293
+ $ascii .= $var{$c};
294
+ break;
295
+
296
+ case (($ord_var_c & 0xE0) == 0xC0):
297
+ // characters U-00000080 - U-000007FF, mask 110XXXXX
298
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
299
+ $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
300
+ $c += 1;
301
+ $utf16 = $this->utf82utf16($char);
302
+ $ascii .= sprintf('\u%04s', bin2hex($utf16));
303
+ break;
304
+
305
+ case (($ord_var_c & 0xF0) == 0xE0):
306
+ // characters U-00000800 - U-0000FFFF, mask 1110XXXX
307
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
308
+ $char = pack('C*', $ord_var_c,
309
+ ord($var{$c + 1}),
310
+ ord($var{$c + 2}));
311
+ $c += 2;
312
+ $utf16 = $this->utf82utf16($char);
313
+ $ascii .= sprintf('\u%04s', bin2hex($utf16));
314
+ break;
315
+
316
+ case (($ord_var_c & 0xF8) == 0xF0):
317
+ // characters U-00010000 - U-001FFFFF, mask 11110XXX
318
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
319
+ $char = pack('C*', $ord_var_c,
320
+ ord($var{$c + 1}),
321
+ ord($var{$c + 2}),
322
+ ord($var{$c + 3}));
323
+ $c += 3;
324
+ $utf16 = $this->utf82utf16($char);
325
+ $ascii .= sprintf('\u%04s', bin2hex($utf16));
326
+ break;
327
+
328
+ case (($ord_var_c & 0xFC) == 0xF8):
329
+ // characters U-00200000 - U-03FFFFFF, mask 111110XX
330
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
331
+ $char = pack('C*', $ord_var_c,
332
+ ord($var{$c + 1}),
333
+ ord($var{$c + 2}),
334
+ ord($var{$c + 3}),
335
+ ord($var{$c + 4}));
336
+ $c += 4;
337
+ $utf16 = $this->utf82utf16($char);
338
+ $ascii .= sprintf('\u%04s', bin2hex($utf16));
339
+ break;
340
+
341
+ case (($ord_var_c & 0xFE) == 0xFC):
342
+ // characters U-04000000 - U-7FFFFFFF, mask 1111110X
343
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
344
+ $char = pack('C*', $ord_var_c,
345
+ ord($var{$c + 1}),
346
+ ord($var{$c + 2}),
347
+ ord($var{$c + 3}),
348
+ ord($var{$c + 4}),
349
+ ord($var{$c + 5}));
350
+ $c += 5;
351
+ $utf16 = $this->utf82utf16($char);
352
+ $ascii .= sprintf('\u%04s', bin2hex($utf16));
353
+ break;
354
+ }
355
+ }
356
+
357
+ return '"'.$ascii.'"';
358
+
359
+ case 'array':
360
+ /*
361
+ * As per JSON spec if any array key is not an integer
362
+ * we must treat the the whole array as an object. We
363
+ * also try to catch a sparsely populated associative
364
+ * array with numeric keys here because some JS engines
365
+ * will create an array with empty indexes up to
366
+ * max_index which can cause memory issues and because
367
+ * the keys, which may be relevant, will be remapped
368
+ * otherwise.
369
+ *
370
+ * As per the ECMA and JSON specification an object may
371
+ * have any string as a property. Unfortunately due to
372
+ * a hole in the ECMA specification if the key is a
373
+ * ECMA reserved word or starts with a digit the
374
+ * parameter is only accessible using ECMAScript's
375
+ * bracket notation.
376
+ */
377
+
378
+ // treat as a JSON object
379
+ if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
380
+ $properties = array_map(array($this, 'name_value'),
381
+ array_keys($var),
382
+ array_values($var));
383
+
384
+ foreach($properties as $property) {
385
+ if(Services_JSON::isError($property)) {
386
+ return $property;
387
+ }
388
+ }
389
+
390
+ return '{' . join(',', $properties) . '}';
391
+ }
392
+
393
+ // treat it like a regular array
394
+ $elements = array_map(array($this, 'encode'), $var);
395
+
396
+ foreach($elements as $element) {
397
+ if(Services_JSON::isError($element)) {
398
+ return $element;
399
+ }
400
+ }
401
+
402
+ return '[' . join(',', $elements) . ']';
403
+
404
+ case 'object':
405
+ $vars = get_object_vars($var);
406
+
407
+ $properties = array_map(array($this, 'name_value'),
408
+ array_keys($vars),
409
+ array_values($vars));
410
+
411
+ foreach($properties as $property) {
412
+ if(Services_JSON::isError($property)) {
413
+ return $property;
414
+ }
415
+ }
416
+
417
+ return '{' . join(',', $properties) . '}';
418
+
419
+ default:
420
+ return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
421
+ ? 'null'
422
+ : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
423
+ }
424
+ }
425
+
426
+ /**
427
+ * array-walking function for use in generating JSON-formatted name-value pairs
428
+ *
429
+ * @param string $name name of key to use
430
+ * @param mixed $value reference to an array element to be encoded
431
+ *
432
+ * @return string JSON-formatted name-value pair, like '"name":value'
433
+ * @access private
434
+ */
435
+ function name_value($name, $value)
436
+ {
437
+ $encoded_value = $this->encode($value);
438
+
439
+ if(Services_JSON::isError($encoded_value)) {
440
+ return $encoded_value;
441
+ }
442
+
443
+ return $this->encode(strval($name)) . ':' . $encoded_value;
444
+ }
445
+
446
+ /**
447
+ * reduce a string by removing leading and trailing comments and whitespace
448
+ *
449
+ * @param $str string string value to strip of comments and whitespace
450
+ *
451
+ * @return string string value stripped of comments and whitespace
452
+ * @access private
453
+ */
454
+ function reduce_string($str)
455
+ {
456
+ $str = preg_replace(array(
457
+
458
+ // eliminate single line comments in '// ...' form
459
+ '#^\s*//(.+)$#m',
460
+
461
+ // eliminate multi-line comments in '/* ... */' form, at start of string
462
+ '#^\s*/\*(.+)\*/#Us',
463
+
464
+ // eliminate multi-line comments in '/* ... */' form, at end of string
465
+ '#/\*(.+)\*/\s*$#Us'
466
+
467
+ ), '', $str);
468
+
469
+ // eliminate extraneous space
470
+ return trim($str);
471
+ }
472
+
473
+ /**
474
+ * decodes a JSON string into appropriate variable
475
+ *
476
+ * @param string $str JSON-formatted string
477
+ *
478
+ * @return mixed number, boolean, string, array, or object
479
+ * corresponding to given JSON input string.
480
+ * See argument 1 to Services_JSON() above for object-output behavior.
481
+ * Note that decode() always returns strings
482
+ * in ASCII or UTF-8 format!
483
+ * @access public
484
+ */
485
+ function decode($str)
486
+ {
487
+ $str = $this->reduce_string($str);
488
+
489
+ switch (strtolower($str)) {
490
+ case 'true':
491
+ return true;
492
+
493
+ case 'false':
494
+ return false;
495
+
496
+ case 'null':
497
+ return null;
498
+
499
+ default:
500
+ $m = array();
501
+
502
+ if (is_numeric($str)) {
503
+ // Lookie-loo, it's a number
504
+
505
+ // This would work on its own, but I'm trying to be
506
+ // good about returning integers where appropriate:
507
+ // return (float)$str;
508
+
509
+ // Return float or int, as appropriate
510
+ return ((float)$str == (integer)$str)
511
+ ? (integer)$str
512
+ : (float)$str;
513
+
514
+ } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
515
+ // STRINGS RETURNED IN UTF-8 FORMAT
516
+ $delim = substr($str, 0, 1);
517
+ $chrs = substr($str, 1, -1);
518
+ $utf8 = '';
519
+ $strlen_chrs = strlen($chrs);
520
+
521
+ for ($c = 0; $c < $strlen_chrs; ++$c) {
522
+
523
+ $substr_chrs_c_2 = substr($chrs, $c, 2);
524
+ $ord_chrs_c = ord($chrs{$c});
525
+
526
+ switch (true) {
527
+ case $substr_chrs_c_2 == '\b':
528
+ $utf8 .= chr(0x08);
529
+ ++$c;
530
+ break;
531
+ case $substr_chrs_c_2 == '\t':
532
+ $utf8 .= chr(0x09);
533
+ ++$c;
534
+ break;
535
+ case $substr_chrs_c_2 == '\n':
536
+ $utf8 .= chr(0x0A);
537
+ ++$c;
538
+ break;
539
+ case $substr_chrs_c_2 == '\f':
540
+ $utf8 .= chr(0x0C);
541
+ ++$c;
542
+ break;
543
+ case $substr_chrs_c_2 == '\r':
544
+ $utf8 .= chr(0x0D);
545
+ ++$c;
546
+ break;
547
+
548
+ case $substr_chrs_c_2 == '\\"':
549
+ case $substr_chrs_c_2 == '\\\'':
550
+ case $substr_chrs_c_2 == '\\\\':
551
+ case $substr_chrs_c_2 == '\\/':
552
+ if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
553
+ ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
554
+ $utf8 .= $chrs{++$c};
555
+ }
556
+ break;
557
+
558
+ case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
559
+ // single, escaped unicode character
560
+ $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
561
+ . chr(hexdec(substr($chrs, ($c + 4), 2)));
562
+ $utf8 .= $this->utf162utf8($utf16);
563
+ $c += 5;
564
+ break;
565
+
566
+ case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
567
+ $utf8 .= $chrs{$c};
568
+ break;
569
+
570
+ case ($ord_chrs_c & 0xE0) == 0xC0:
571
+ // characters U-00000080 - U-000007FF, mask 110XXXXX
572
+ //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
573
+ $utf8 .= substr($chrs, $c, 2);
574
+ ++$c;
575
+ break;
576
+
577
+ case ($ord_chrs_c & 0xF0) == 0xE0:
578
+ // characters U-00000800 - U-0000FFFF, mask 1110XXXX
579
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
580
+ $utf8 .= substr($chrs, $c, 3);
581
+ $c += 2;
582
+ break;
583
+
584
+ case ($ord_chrs_c & 0xF8) == 0xF0:
585
+ // characters U-00010000 - U-001FFFFF, mask 11110XXX
586
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
587
+ $utf8 .= substr($chrs, $c, 4);
588
+ $c += 3;
589
+ break;
590
+
591
+ case ($ord_chrs_c & 0xFC) == 0xF8:
592
+ // characters U-00200000 - U-03FFFFFF, mask 111110XX
593
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
594
+ $utf8 .= substr($chrs, $c, 5);
595
+ $c += 4;
596
+ break;
597
+
598
+ case ($ord_chrs_c & 0xFE) == 0xFC:
599
+ // characters U-04000000 - U-7FFFFFFF, mask 1111110X
600
+ // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
601
+ $utf8 .= substr($chrs, $c, 6);
602
+ $c += 5;
603
+ break;
604
+
605
+ }
606
+
607
+ }
608
+
609
+ return $utf8;
610
+
611
+ } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
612
+ // array, or object notation
613
+
614
+ if ($str{0} == '[') {
615
+ $stk = array(SERVICES_JSON_IN_ARR);
616
+ $arr = array();
617
+ } else {
618
+ if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
619
+ $stk = array(SERVICES_JSON_IN_OBJ);
620
+ $obj = array();
621
+ } else {
622
+ $stk = array(SERVICES_JSON_IN_OBJ);
623
+ $obj = new stdClass();
624
+ }
625
+ }
626
+
627
+ array_push($stk, array('what' => SERVICES_JSON_SLICE,
628
+ 'where' => 0,
629
+ 'delim' => false));
630
+
631
+ $chrs = substr($str, 1, -1);
632
+ $chrs = $this->reduce_string($chrs);
633
+
634
+ if ($chrs == '') {
635
+ if (reset($stk) == SERVICES_JSON_IN_ARR) {
636
+ return $arr;
637
+
638
+ } else {
639
+ return $obj;
640
+
641
+ }
642
+ }
643
+
644
+ //print("\nparsing {$chrs}\n");
645
+
646
+ $strlen_chrs = strlen($chrs);
647
+
648
+ for ($c = 0; $c <= $strlen_chrs; ++$c) {
649
+
650
+ $top = end($stk);
651
+ $substr_chrs_c_2 = substr($chrs, $c, 2);
652
+
653
+ if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
654
+ // found a comma that is not inside a string, array, etc.,
655
+ // OR we've reached the end of the character list
656
+ $slice = substr($chrs, $top['where'], ($c - $top['where']));
657
+ array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
658
+ //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
659
+
660
+ if (reset($stk) == SERVICES_JSON_IN_ARR) {
661
+ // we are in an array, so just push an element onto the stack
662
+ array_push($arr, $this->decode($slice));
663
+
664
+ } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
665
+ // we are in an object, so figure
666
+ // out the property name and set an
667
+ // element in an associative array,
668
+ // for now
669
+ $parts = array();
670
+
671
+ if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
672
+ // "name":value pair
673
+ $key = $this->decode($parts[1]);
674
+ $val = $this->decode($parts[2]);
675
+
676
+ if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
677
+ $obj[$key] = $val;
678
+ } else {
679
+ $obj->$key = $val;
680
+ }
681
+ } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
682
+ // name:value pair, where name is unquoted
683
+ $key = $parts[1];
684
+ $val = $this->decode($parts[2]);
685
+
686
+ if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
687
+ $obj[$key] = $val;
688
+ } else {
689
+ $obj->$key = $val;
690
+ }
691
+ }
692
+
693
+ }
694
+
695
+ } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
696
+ // found a quote, and we are not inside a string
697
+ array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
698
+ //print("Found start of string at {$c}\n");
699
+
700
+ } elseif (($chrs{$c} == $top['delim']) &&
701
+ ($top['what'] == SERVICES_JSON_IN_STR) &&
702
+ ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
703
+ // found a quote, we're in a string, and it's not escaped
704
+ // we know that it's not escaped becase there is _not_ an
705
+ // odd number of backslashes at the end of the string so far
706
+ array_pop($stk);
707
+ //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
708
+
709
+ } elseif (($chrs{$c} == '[') &&
710
+ in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
711
+ // found a left-bracket, and we are in an array, object, or slice
712
+ array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
713
+ //print("Found start of array at {$c}\n");
714
+
715
+ } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
716
+ // found a right-bracket, and we're in an array
717
+ array_pop($stk);
718
+ //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
719
+
720
+ } elseif (($chrs{$c} == '{') &&
721
+ in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
722
+ // found a left-brace, and we are in an array, object, or slice
723
+ array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
724
+ //print("Found start of object at {$c}\n");
725
+
726
+ } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
727
+ // found a right-brace, and we're in an object
728
+ array_pop($stk);
729
+ //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
730
+
731
+ } elseif (($substr_chrs_c_2 == '/*') &&
732
+ in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
733
+ // found a comment start, and we are in an array, object, or slice
734
+ array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
735
+ $c++;
736
+ //print("Found start of comment at {$c}\n");
737
+
738
+ } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
739
+ // found a comment end, and we're in one now
740
+ array_pop($stk);
741
+ $c++;
742
+
743
+ for ($i = $top['where']; $i <= $c; ++$i)
744
+ $chrs = substr_replace($chrs, ' ', $i, 1);
745
+
746
+ //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
747
+
748
+ }
749
+
750
+ }
751
+
752
+ if (reset($stk) == SERVICES_JSON_IN_ARR) {
753
+ return $arr;
754
+
755
+ } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
756
+ return $obj;
757
+
758
+ }
759
+
760
+ }
761
+ }
762
+ }
763
+
764
+ /**
765
+ * @todo Ultimately, this should just call PEAR::isError()
766
+ */
767
+ function isError($data, $code = null)
768
+ {
769
+ if (class_exists('pear')) {
770
+ return PEAR::isError($data, $code);
771
+ } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
772
+ is_subclass_of($data, 'services_json_error'))) {
773
+ return true;
774
+ }
775
+
776
+ return false;
777
+ }
778
+ }
779
+
780
+ if (class_exists('PEAR_Error')) {
781
+
782
+ class Services_JSON_Error extends PEAR_Error
783
+ {
784
+ function Services_JSON_Error($message = 'unknown error', $code = null,
785
+ $mode = null, $options = null, $userinfo = null)
786
+ {
787
+ parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
788
+ }
789
+ }
790
+
791
+ } else {
792
+
793
+ /**
794
+ * @todo Ultimately, this class shall be descended from PEAR_Error
795
+ */
796
+ class Services_JSON_Error
797
+ {
798
+ function Services_JSON_Error($message = 'unknown error', $code = null,
799
+ $mode = null, $options = null, $userinfo = null)
800
+ {
801
+
802
+ }
803
+ }
804
+
805
+ }
806
+ endif;
807
+ ?>
trunk/ZeroClipboard.js ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Simple Set Clipboard System
2
+ // Author: Joseph Huckaby
3
+
4
+ var ZeroClipboard = {
5
+
6
+ version: "1.0.5",
7
+ clients: {}, // registered upload clients on page, indexed by id
8
+ moviePath: 'ZeroClipboard.swf', // URL to movie
9
+ nextId: 1, // ID of next movie
10
+
11
+ $: function(thingy) {
12
+ // simple DOM lookup utility function
13
+ if (typeof(thingy) == 'string') thingy = document.getElementById(thingy);
14
+ if (!thingy.addClass) {
15
+ // extend element with a few useful methods
16
+ thingy.hide = function() { this.style.display = 'none'; };
17
+ thingy.show = function() { this.style.display = ''; };
18
+ thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
19
+ thingy.removeClass = function(name) {
20
+ this.className = this.className.replace( new RegExp("(^|\\s+)" + name + "(\\s+|$)"), "").replace(/^\s+|\s+$/g, '');
21
+ };
22
+ thingy.hasClass = function(name) {
23
+ return !!this.className.match( new RegExp("\\s*" + name + "\\s*") );
24
+ };
25
+ }
26
+ return thingy;
27
+ },
28
+
29
+ setMoviePath: function(path) {
30
+ // set path to ZeroClipboard.swf
31
+ this.moviePath = path;
32
+ },
33
+
34
+ dispatch: function(id, eventName, args) {
35
+ // receive event from flash movie, send to client
36
+ var client = this.clients[id];
37
+ if (client) {
38
+ client.receiveEvent(eventName, args);
39
+ }
40
+ },
41
+
42
+ register: function(id, client) {
43
+ // register new client to receive events
44
+ this.clients[id] = client;
45
+ },
46
+
47
+ getDOMObjectPosition: function(obj, stopObj) {
48
+ // get absolute coordinates for dom element
49
+ var info = {
50
+ left: 0,
51
+ top: 0,
52
+ width: obj.width ? obj.width : obj.offsetWidth,
53
+ height: obj.height ? obj.height : obj.offsetHeight
54
+ };
55
+
56
+ while (obj && (obj != stopObj)) {
57
+ info.left += obj.offsetLeft;
58
+ info.top += obj.offsetTop;
59
+ obj = obj.offsetParent;
60
+ }
61
+
62
+ return info;
63
+ },
64
+
65
+ Client: function(elem) {
66
+ // constructor for new simple upload client
67
+ this.handlers = {};
68
+
69
+ // unique ID
70
+ this.id = ZeroClipboard.nextId++;
71
+ this.movieId = 'ZeroClipboardMovie_' + this.id;
72
+
73
+ // register client with singleton to receive flash events
74
+ ZeroClipboard.register(this.id, this);
75
+
76
+ // create movie
77
+ if (elem) this.glue(elem);
78
+ }
79
+ };
80
+
81
+ ZeroClipboard.Client.prototype = {
82
+
83
+ id: 0, // unique ID for us
84
+ ready: false, // whether movie is ready to receive events or not
85
+ movie: null, // reference to movie object
86
+ clipText: '', // text to copy to clipboard
87
+ handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
88
+ cssEffects: true, // enable CSS mouse effects on dom container
89
+ handlers: null, // user event handlers
90
+
91
+ glue: function(elem, appendElem, stylesToAdd) {
92
+ // glue to DOM element
93
+ // elem can be ID or actual DOM element object
94
+ this.domElement = ZeroClipboard.$(elem);
95
+
96
+ // float just above object, or zIndex 99 if dom element isn't set
97
+ var zIndex = 99;
98
+ if (this.domElement.style.zIndex) {
99
+ zIndex = parseInt(this.domElement.style.zIndex, 10) + 1;
100
+ }
101
+
102
+ if (typeof(appendElem) == 'string') {
103
+ appendElem = ZeroClipboard.$(appendElem);
104
+ }
105
+ else if (typeof(appendElem) == 'undefined') {
106
+ appendElem = document.getElementsByTagName('body')[0];
107
+ }
108
+
109
+ // find X/Y position of domElement
110
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem);
111
+
112
+ // create floating DIV above element
113
+ this.div = document.createElement('div');
114
+ var style = this.div.style;
115
+ style.position = 'absolute';
116
+ style.left = '' + box.left + 'px';
117
+ style.top = '' + box.top + 'px';
118
+ style.width = '' + box.width + 'px';
119
+ style.height = '' + box.height + 'px';
120
+ style.zIndex = zIndex;
121
+
122
+ if (typeof(stylesToAdd) == 'object') {
123
+ for (addedStyle in stylesToAdd) {
124
+ style[addedStyle] = stylesToAdd[addedStyle];
125
+ }
126
+ }
127
+
128
+ // style.backgroundColor = '#f00'; // debug
129
+
130
+ appendElem.appendChild(this.div);
131
+
132
+ this.div.innerHTML = this.getHTML( box.width, box.height );
133
+ },
134
+
135
+ getHTML: function(width, height) {
136
+ // return HTML for movie
137
+ var html = '';
138
+ var flashvars = 'id=' + this.id +
139
+ '&width=' + width +
140
+ '&height=' + height;
141
+
142
+ if (navigator.userAgent.match(/MSIE/)) {
143
+ // IE gets an OBJECT tag
144
+ var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
145
+ html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="'+protocol+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+width+'" height="'+height+'" id="'+this.movieId+'" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="'+ZeroClipboard.moviePath+'" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="'+flashvars+'"/><param name="wmode" value="transparent"/></object>';
146
+ }
147
+ else {
148
+ // all other browsers get an EMBED tag
149
+ html += '<embed id="'+this.movieId+'" src="'+ZeroClipboard.moviePath+'" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="'+width+'" height="'+height+'" name="'+this.movieId+'" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="'+flashvars+'" wmode="transparent" />';
150
+ }
151
+ return html;
152
+ },
153
+
154
+ hide: function() {
155
+ // temporarily hide floater offscreen
156
+ if (this.div) {
157
+ this.div.style.left = '-2000px';
158
+ }
159
+ },
160
+
161
+ show: function() {
162
+ // show ourselves after a call to hide()
163
+ this.reposition();
164
+ },
165
+
166
+ destroy: function() {
167
+ // destroy control and floater
168
+ if (this.domElement && this.div) {
169
+ this.hide();
170
+ this.div.innerHTML = '';
171
+
172
+ var body = document.getElementsByTagName('body')[0];
173
+ try { body.removeChild( this.div ); } catch(e) {;}
174
+
175
+ this.domElement = null;
176
+ this.div = null;
177
+ }
178
+ },
179
+
180
+ reposition: function(elem) {
181
+ // reposition our floating div, optionally to new container
182
+ // warning: container CANNOT change size, only position
183
+ if (elem) {
184
+ this.domElement = ZeroClipboard.$(elem);
185
+ if (!this.domElement) this.hide();
186
+ }
187
+
188
+ if (this.domElement && this.div) {
189
+ var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
190
+ var style = this.div.style;
191
+ style.left = '' + box.left + 'px';
192
+ style.top = '' + box.top + 'px';
193
+ }
194
+ },
195
+
196
+ setText: function(newText) {
197
+ // set text to be copied to clipboard
198
+ this.clipText = newText;
199
+ if (this.ready) this.movie.setText(newText);
200
+ },
201
+
202
+ addEventListener: function(eventName, func) {
203
+ // add user event listener for event
204
+ // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
205
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
206
+ if (!this.handlers[eventName]) this.handlers[eventName] = [];
207
+ this.handlers[eventName].push(func);
208
+ },
209
+
210
+ setHandCursor: function(enabled) {
211
+ // enable hand cursor (true), or default arrow cursor (false)
212
+ this.handCursorEnabled = enabled;
213
+ if (this.ready) this.movie.setHandCursor(enabled);
214
+ },
215
+
216
+ setCSSEffects: function(enabled) {
217
+ // enable or disable CSS effects on DOM container
218
+ this.cssEffects = !!enabled;
219
+ },
220
+
221
+ receiveEvent: function(eventName, args) {
222
+ // receive event from flash
223
+ eventName = eventName.toString().toLowerCase().replace(/^on/, '');
224
+
225
+ // special behavior for certain events
226
+ switch (eventName) {
227
+ case 'load':
228
+ // movie claims it is ready, but in IE this isn't always the case...
229
+ // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
230
+ this.movie = document.getElementById(this.movieId);
231
+ if (!this.movie) {
232
+ var self = this;
233
+ setTimeout( function() { self.receiveEvent('load', null); }, 1 );
234
+ return;
235
+ }
236
+
237
+ // firefox on pc needs a "kick" in order to set these in certain cases
238
+ if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
239
+ var self = this;
240
+ setTimeout( function() { self.receiveEvent('load', null); }, 100 );
241
+ this.ready = true;
242
+ return;
243
+ }
244
+
245
+ this.ready = true;
246
+ this.movie.setText( this.clipText );
247
+ this.movie.setHandCursor( this.handCursorEnabled );
248
+ break;
249
+
250
+ case 'mouseover':
251
+ if (this.domElement && this.cssEffects) {
252
+ this.domElement.addClass('hover');
253
+ if (this.recoverActive) this.domElement.addClass('active');
254
+ }
255
+ break;
256
+
257
+ case 'mouseout':
258
+ if (this.domElement && this.cssEffects) {
259
+ this.recoverActive = false;
260
+ if (this.domElement.hasClass('active')) {
261
+ this.domElement.removeClass('active');
262
+ this.recoverActive = true;
263
+ }
264
+ this.domElement.removeClass('hover');
265
+ }
266
+ break;
267
+
268
+ case 'mousedown':
269
+ if (this.domElement && this.cssEffects) {
270
+ this.domElement.addClass('active');
271
+ }
272
+ break;
273
+
274
+ case 'mouseup':
275
+ if (this.domElement && this.cssEffects) {
276
+ this.domElement.removeClass('active');
277
+ this.recoverActive = false;
278
+ }
279
+ break;
280
+ } // switch eventName
281
+
282
+ if (this.handlers[eventName]) {
283
+ for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
284
+ var func = this.handlers[eventName][idx];
285
+
286
+ if (typeof(func) == 'function') {
287
+ // actual function reference
288
+ func(this, args);
289
+ }
290
+ else if ((typeof(func) == 'object') && (func.length == 2)) {
291
+ // PHP style object + method, i.e. [myObject, 'myMethod']
292
+ func[0][ func[1] ](this, args);
293
+ }
294
+ else if (typeof(func) == 'string') {
295
+ // name of function
296
+ window[func](this, args);
297
+ }
298
+ } // foreach event handler defined
299
+ } // user defined handler for event
300
+ }
301
+
302
+ };
trunk/ZeroClipboard.swf ADDED
Binary file
trunk/accountconfig.php ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Settings page in the admin panel
4
+ function zopim_account_config() {
5
+ global $usernameToCodeURL, $languagesURL, $current_user;
6
+
7
+ ?>
8
+
9
+ <div class="wrap">
10
+
11
+ <?php
12
+
13
+ if ($_GET["action"]=="deactivate") {
14
+ update_option('zopimSalt', "");
15
+ update_option('zopimCode', "zopim");
16
+ }
17
+
18
+ $message = "";
19
+ if ($_POST["action"]=="login") {
20
+ if ($_POST["zopimUseSSL"] == "") {
21
+ $_POST["zopimUseSSL"] = "nossl";
22
+ }
23
+ update_option('zopimUseSSL', $_POST["zopimUseSSL"]);
24
+
25
+ if ($_POST["zopimPassword"] != "password") {
26
+
27
+ $logindata = array("email" => $_POST["zopimUsername"], "password" => $_POST["zopimPassword"]);
28
+ $loginresult = json_to_array(do_post_request(ZOPIM_LOGIN_URL, $logindata));
29
+
30
+ if (isset($loginresult->error)) {
31
+ $error["login"] = "<b>Could not log in to Zopim. Please check your login details. If problem persists, try connecting without SSL enabled.</b>";
32
+ $gotologin = 1;
33
+ update_option('zopimSalt', "wronglogin");
34
+ } else if (isset($loginresult->salt)) {
35
+ update_option('zopimUsername', $_POST["zopimUsername"]);
36
+ update_option('zopimSalt', $loginresult->salt);
37
+ $account = getAccountDetails(get_option('zopimSalt'));
38
+
39
+ if (isset($account)) {
40
+ update_option('zopimCode', $account->account_key);
41
+
42
+ if (get_option('zopimGreetings') == "") {
43
+ $jsongreetings = to_json($account->settings->greetings);
44
+ update_option('zopimGreetings', $jsongreetings);
45
+ }
46
+ }
47
+ } else {
48
+ update_option('zopimSalt', "");
49
+ $error["login"] = "<b>Could not log in to Zopim. We were unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>";
50
+ }
51
+ }
52
+ } else if ($_POST["action"]=="signup") {
53
+
54
+ if ($_POST["zopimUseSSL"] == "") {
55
+ $_POST["zopimUseSSL"] = "nossl";
56
+ }
57
+ update_option('zopimUseSSL', $_POST["zopimUseSSL"]);
58
+
59
+ $createdata = array(
60
+ "email" => $_POST["zopimnewemail"],
61
+ "first_name" => $_POST["zopimfirstname"],
62
+ "last_name" => $_POST["zopimlastname"],
63
+ "display_name" => $_POST["zopimfirstname"]." ".$_POST["zopimlastname"],
64
+ "eref" => $_POST["zopimeref"],
65
+ "source" => "wordpress",
66
+ "recaptcha_challenge_field" => $_POST["recaptcha_challenge_field"],
67
+ "recaptcha_response_field" => $_POST["recaptcha_response_field"]
68
+ );
69
+
70
+ $signupresult = json_to_array(do_post_request(ZOPIM_SIGNUP_URL, $createdata));
71
+ if (isset($signupresult->error)) {
72
+ $message = "<div style='color:#c33;'>Error during activation: <b>".$signupresult->error."</b>. Please try again.</div>";
73
+ } else if (isset($signupresult->account_key)) {
74
+ $message = "<b>Thank you for signing up. Please check your mail for your password to complete the process. </b>";
75
+ $gotologin = 1;
76
+ } else {
77
+ $message = "<b>Could not activate account. The wordpress installation was unable to contact Zopim servers. Please check with your server administrator to ensure that <a href='http://www.php.net/manual/en/book.curl.php'>PHP Curl</a> is installed and permissions are set correctly.</b>";
78
+ }
79
+ }
80
+
81
+ if (get_option('zopimCode') != "" && get_option('zopimCode') != "zopim") {
82
+
83
+ $accountDetails = getAccountDetails(get_option('zopimSalt'));
84
+
85
+ if (!isset($accountDetails) || isset($accountDetails->error)) {
86
+ $gotologin = 1;
87
+ $error["auth"] = '
88
+ <div class="metabox-holder">
89
+ <div class="postbox">
90
+ <h3 class="hndle"><span>Account no longer linked!</span></h3>
91
+ <div style="padding:10px;line-height:17px;">
92
+ We could not verify your Zopim account. Please check your password and try again.
93
+ </div>
94
+ </div>
95
+ </div>'
96
+ ;
97
+ } else {
98
+ $authenticated = "ok";
99
+ }
100
+ }
101
+
102
+ if ($authenticated == "ok") {
103
+ if ($accountDetails->package_id=="trial") {
104
+ $accountDetails->package_id = "Free Lite Package + 14 Days Full-features";
105
+ } else {
106
+ $accountDetails->package_id .= " Package";
107
+ }
108
+ ?>
109
+ <div id="icon-options-general" class="icon32"><br/></div><h2>Set up your Zopim Account</h2>
110
+ <br/>
111
+ <div style="background:#FFFEEB;padding:25px;border:1px solid #eee;">
112
+ <span style="float:right;"><a href="admin.php?page=zopim_account_config&action=deactivate">Deactivate</a></span>
113
+ Currently Activated Account &rarr; <b><?php echo get_option('zopimUsername'); ?></b> <div style="display:inline-block;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>
114
+ <br><p><br>You can <a href="admin.php?page=zopim_customize_widget">customize</a> the chat widget, <a href="admin.php?page=zopim_instant_messaging">relay messages</a> to your favourite IM client, or <a href="admin.php?page=zopim_dashboard">launch the dashboard</a> for advanced features.
115
+ </div>
116
+
117
+ <?php } else { ?>
118
+ <div id="icon-options-general" class="icon32"><br/></div><h2>Set up your Zopim Account</h2>
119
+ <?php if ($error && $error["auth"]) {
120
+ echo $error["auth"];
121
+ } else if ($message == "") { ?>
122
+ Congratulations on successfully installing the Zopim WordPress plugin! Activate an account to start using Zopim Live Chat.<br>
123
+ <br>
124
+ <?php } else { echo $message; } ?>
125
+
126
+ <script type="text/javascript">
127
+
128
+ function showSignup(whichform) {
129
+ if (whichform == '1') {
130
+ document.getElementById('existingform').style.display = "none";
131
+ document.getElementById('signupform').style.display = "block";
132
+ document.getElementById('formtoshow_signup').checked = 'true';
133
+ } else {
134
+ document.getElementById('signupform').style.display = "none";
135
+ document.getElementById('existingform').style.display = "block";
136
+ document.getElementById('formtoshow_existing').checked = 'true';
137
+ }
138
+ }
139
+
140
+
141
+ </script>
142
+ <div class="metabox-holder">
143
+ <div class="postbox">
144
+ <h3 class="hndle"><span>Select a Setup</span></h3>
145
+ <div style="padding:10px;">
146
+ <div onclick="javascript: showSignup(1)"><input type="radio" name="formtoshow" id="formtoshow_signup" value="yes" onchange="javascript: showSignup(1)"/> Give me a new account &mdash; <i>absolutely free!</i></div>
147
+ <br/>
148
+ <div onclick="javascript: showSignup(0)"><input type="radio" name="formtoshow" id="formtoshow_existing" value="no" onchange="javascript: showSignup(0)"/> I already have a Zopim account</div>
149
+ </div>
150
+ </div>
151
+ </div>
152
+
153
+
154
+ <div id="existingform" style="display: none">
155
+ <div class="metabox-holder">
156
+ <div class="postbox">
157
+ <h3 class="hndle"><span>Link up to your Zopim account</span></h3>
158
+ <div style="padding:10px;">
159
+ <?php if (isset($error) && isset($error["login"])) { echo $error["login"]; } ?>
160
+ <form method="post" action="admin.php?page=zopim_account_config">
161
+ <input type="hidden" name="action" value="login">
162
+ <table class="form-table">
163
+
164
+ <tr valign="top">
165
+ <th scope="row">Zopim Username (E-mail)</th>
166
+ <td><input type="text" name="zopimUsername" value="<?php echo get_option('zopimUsername'); ?>" /></td>
167
+ </tr>
168
+
169
+ <tr valign="top">
170
+ <th scope="row">Zopim Password</th>
171
+ <td><input type="password" name="zopimPassword" value="<?php if (get_option('zopimSalt') != "") { echo "password"; }; ?>" /></td>
172
+ </tr>
173
+
174
+ <tr valign="center">
175
+ <th scope="row">Use SSL</th>
176
+ <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>
177
+ </tr>
178
+ </table>
179
+ <br/>
180
+ The Zopim chat bar will displayed on your blog once your account is linked up.
181
+ <br/><br/>
182
+ <p class="submit">
183
+ <input type="submit" class="button-primary" value="<?php _e('Link Up') ?>" />
184
+ </p>
185
+
186
+ </form>
187
+
188
+ </div>
189
+ </div>
190
+ </div>
191
+ </div>
192
+
193
+ <div id="signupform" style="display: none">
194
+ <div class="metabox-holder">
195
+ <div class="postbox">
196
+ <h3 class="hndle"><span>Activate your free Zopim Account</span></h3>
197
+ <div style="padding:10px;">
198
+ <form method="post" action="admin.php?page=zopim_account_config" onSubmit="return checkSignUp();">
199
+ <input type="hidden" name="action" value="signup">
200
+ <div id="signuperror"></div>
201
+ <table class="form-table">
202
+
203
+ <tr valign="top">
204
+ <th scope="row">First Name</th>
205
+ <td><input id="zopimfirstname" type="text" name="zopimfirstname" value="<?php if (isset($_POST["zopimfirstname"])) { echo $_POST["zopimfirstname"]; } else { echo $current_user->data->first_name; } ?>"></td>
206
+ </tr>
207
+
208
+ <tr valign="top">
209
+ <th scope="row">Last Name</th>
210
+ <td><input id="zopimlastname" type="text" name="zopimlastname" value="<?php if (isset($_POST["zopimlastname"])) { echo $_POST["zopimnlastname"]; } else { echo $current_user->data->last_name; } ?>"></td>
211
+ </tr>
212
+
213
+ <tr valign="top">
214
+ <th scope="row">E-mail</th>
215
+ <td><input id="zopimnewemail" type="text" name="zopimnewemail" value="<?php if (isset($_POST["zopimnewemail"])) { echo $_POST["zopimnewemail"]; } else { echo $current_user->data->user_email; } ?>"></td>
216
+ </tr>
217
+
218
+ <tr valign="top">
219
+ <th scope="row">Use SSL</th>
220
+ <td><input type="checkbox" name="zopimUseSSL" value="zopimUseSSL" checked="checked" } ?> uncheck this if you are unable to login</td>
221
+ </tr>
222
+
223
+ <tr valign="top">
224
+ <th scope="row">Verification</th>
225
+ <td>
226
+ <script type="text/javascript" src="https://api-secure.recaptcha.net/challenge?k=6Lfr8AQAAAAAAC7MpRXM2hgLfyss_KKjvcJ_JFIk">
227
+ </script>
228
+ <noscript>
229
+ <iframe src="https://api-secure.recaptcha.net/noscript?k=6Lfr8AQAAAAAAC7MpRXM2hgLfyss_KKjvcJ_JFIk"
230
+ height="300" width="500" frameborder="0"></iframe><br>
231
+ <textarea name="recaptcha_challenge_field" rows="3" cols="40">
232
+ </textarea>
233
+ <input type="hidden" name="recaptcha_response_field"
234
+ value="manual_challenge">
235
+ </noscript>
236
+
237
+ </td>
238
+ </tr>
239
+ <!--
240
+ <tr valign="top">
241
+ <th scope="row">Referral E-mail or ID</th>
242
+ <td><input id="zopimeref" type="text" name="zopimeref" value="<?php if (isset($_POST)) { echo $_POST["zopimeref"]; } ?>"></td>
243
+ </tr>
244
+ -->
245
+ </table>
246
+ <br/>
247
+ The Zopim chat bar will displayed on your blog once your account is activated.<br/><br/>
248
+ <input id="zopimagree" type="checkbox" name="zopimagree" value=""> I agree to Zopim's <a href="http://www.zopim.com/termsnconditions" target="_blank">Terms of Service</a> & <a href="http://www.zopim.com/privacypolicy" target="_blank">Privacy Policy</a>.
249
+ <br/><br/>
250
+ <p class="submit">
251
+ <input type="submit" class="button-primary" value="<?php _e('Activate Now') ?>" />
252
+ </p>
253
+ </form>
254
+ </div>
255
+ </div>
256
+ </div>
257
+
258
+ </div>
259
+ </div>
260
+
261
+ <script type="text/javascript">
262
+ <?php
263
+ if ($authenticated != "ok" && !isset($gotologin) && get_option("zopimCode")=="zopim") {
264
+ echo "showSignup(1); ";
265
+ } else {
266
+ echo "showSignup(0); ";
267
+ }
268
+
269
+ ?>
270
+
271
+ function checkSignUp() {
272
+
273
+ var message = 'Oops! ';
274
+ if (document.getElementById('zopimfirstname').value == '') {
275
+
276
+ message = message + 'First name is required. ';
277
+ }
278
+ if (document.getElementById('zopimlastname').value == '') {
279
+
280
+ message = message + 'Last name is required. ';
281
+ }
282
+ if (document.getElementById('zopimagree').checked == '') {
283
+
284
+ message = message + 'You must agree to our Terms of Service to continue. ';
285
+ }
286
+
287
+ if (message != 'Oops! ') {
288
+
289
+ document.getElementById('signuperror').innerHTML = message;
290
+ return false;
291
+ }
292
+
293
+ return true;
294
+ }
295
+ </script>
296
+
297
+ <?php } } ?>
trunk/customizewidget.php ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Zopim Customize Widget Page
4
+
5
+ function zopim_customize_widget() {
6
+ global $current_user;
7
+ $ul = $current_user->data->first_name;
8
+ $useremail = $current_user->data->user_email;
9
+ $greetings = json_to_array(get_option('zopimGreetings'));
10
+
11
+ $message = "";
12
+
13
+
14
+ if (count($_POST) > 0) {
15
+ update_option('zopimLang', $_POST["zopimLang"]);
16
+ update_option('zopimPosition', $_POST["zopimPosition"]);
17
+ update_option("zopimBubbleEnable", $_POST["zopimBubbleEnable"] );
18
+ update_option('zopimColor', $_POST["zopimColor"]);
19
+ update_option('zopimTheme', $_POST["zopimTheme"]);
20
+ update_option('zopimBubbleTitle', stripslashes($_POST["zopimBubbleTitle"]));
21
+ update_option('zopimBubbleText', stripslashes($_POST["zopimBubbleText"]));
22
+
23
+ update_checkbox("zopimGetVisitorInfo");
24
+ update_checkbox("zopimHideOnOffline");
25
+ update_checkbox("zopimUseGreetings");
26
+
27
+ if ( isset($_POST['zopimUseGreetings']) && $_POST['zopimUseGreetings'] != "") {
28
+ $greetings->online->window = stripslashes($_POST["zopimOnlineLong"]);
29
+ $greetings->online->bar = stripslashes($_POST["zopimOnlineShort"]);
30
+ $greetings->away->window = stripslashes($_POST["zopimAwayLong"]);
31
+ $greetings->away->bar = stripslashes($_POST["zopimAwayShort"]);
32
+ $greetings->offline->window = stripslashes($_POST["zopimOfflineLong"]);
33
+ $greetings->offline->bar = stripslashes($_POST["zopimOfflineShort"]);
34
+
35
+ update_option('zopimGreetings', to_json($greetings));
36
+ }
37
+
38
+ $message = "<b>Changes saved!</b><br>";
39
+ }
40
+
41
+ zopimme();
42
+
43
+
44
+ $accountDetails = getAccountDetails(get_option('zopimSalt'));
45
+
46
+ if (get_option('zopimCode')=="zopim") {
47
+
48
+ $message = '<div class="metabox-holder">
49
+ <div class="postbox">
50
+ <h3 class="hndle"><span>Customizing in Demo Mode</span></h3>
51
+ <div style="padding:10px;line-height:17px;">
52
+ Currently customizing in demo mode. Messages in this widget will go to Zopim staff. The chat widget will not appear on your site until you <a href="admin.php?page=zopim_account_config">activate / link up an account</a>. <br>
53
+ </div>
54
+ </div>
55
+ </div>';
56
+ $accountDetails->widget_customization_enabled = 1;
57
+ $accountDetails->color_customization_enabled = 1;
58
+ } else if (isset($accountDetails->error)) {
59
+ $message = '
60
+ <div class="metabox-holder">
61
+ <div class="postbox">
62
+ <h3 class="hndle"><span>Account no longer linked!</span></h3>
63
+ <div style="padding:10px;line-height:17px;">
64
+ We could not connect to your Zopim account. As a result, this customization page is running in demo mode.<br> Please <a href="admin.php?page=zopim_account_config">check your password in account setup</a> and try again.
65
+ </div>
66
+ </div>
67
+ </div>';
68
+ } else {
69
+ $message .= "Click 'Save Changes' when you're done. Happy customizing!";
70
+ }
71
+
72
+ // unset($accountDetails->widget_customization_enabled);
73
+ // unset($accountDetails->color_customization_enabled);
74
+ ?>
75
+
76
+ <script type="text/javascript">
77
+
78
+ function updateWidget() {
79
+
80
+ var lang = document.getElementById('zopimLang').options[ document.getElementById('zopimLang').options.selectedIndex ].value;
81
+ $zopim.livechat.setLanguage(lang);
82
+
83
+ if (document.getElementById("zopimGetVisitorInfo").checked) {
84
+ $zopim.livechat.setName('<?php echo $ul; ?>');
85
+ $zopim.livechat.setEmail('<?php echo $useremail; ?>');
86
+ } else {
87
+ $zopim.livechat.setName('Visitor');
88
+ $zopim.livechat.setEmail('');
89
+ }
90
+
91
+ if (document.getElementById("zopimHideOnOffline").checked) {
92
+ $zopim.livechat.button.setHideWhenOffline(true);
93
+ } else {
94
+ $zopim.livechat.button.setHideWhenOffline(false);
95
+ }
96
+
97
+ $zopim.livechat.window.setColor(document.getElementById("zopimColor").value);
98
+ $zopim.livechat.window.setTheme(document.getElementById("zopimTheme").value);
99
+
100
+ $zopim.livechat.bubble.setTitle(document.getElementById("zopimBubbleTitle").value);
101
+ $zopim.livechat.bubble.setText(document.getElementById("zopimBubbleText").value);
102
+
103
+ $zopim.livechat.setGreetings({
104
+ 'online': [document.getElementById("zopimOnlineShort").value, document.getElementById("zopimOnlineLong").value],
105
+ 'offline': [document.getElementById("zopimOfflineShort").value, document.getElementById("zopimOfflineLong").value],
106
+ 'away': [document.getElementById("zopimAwayShort").value, document.getElementById("zopimAwayLong").value]
107
+ });
108
+ }
109
+
110
+ function updatePosition() {
111
+
112
+ var position = document.getElementById('zopimPosition').options[ document.getElementById('zopimPosition').options.selectedIndex ].value;
113
+ $zopim.livechat.button.setPosition(position);
114
+ }
115
+
116
+ function updateBubbleStatus() {
117
+ var value = document.getElementById("zopimBubbleEnable").value;
118
+ switch (value) {
119
+ case 'default':
120
+ $zopim.livechat.bubble.reset();
121
+ break;
122
+ case 'show':
123
+ $zopim.livechat.bubble.show();
124
+ break;
125
+ case 'hide':
126
+ $zopim.livechat.bubble.hide();
127
+ break;
128
+ }
129
+ }
130
+
131
+ function greetingsChanged() {
132
+ var inputs = ['zopimOnlineShort', 'zopimAwayShort', 'zopimOfflineShort',
133
+ 'zopimOnlineLong' , 'zopimAwayLong', 'zopimOfflineLong'];
134
+ var isDisabled = false;
135
+
136
+ if (document.getElementById('zopimUseGreetings').checked)
137
+ isDisabled = false;
138
+ else
139
+ isDisabled = true;
140
+
141
+ for (var i=0; i<inputs.length; i++) {
142
+ var el = document.getElementById(inputs[i]);
143
+ el.disabled = isDisabled;
144
+ }
145
+
146
+ updateWidget();
147
+ }
148
+
149
+ var timer;
150
+ function updateSoon() {
151
+
152
+ clearTimeout(timer);
153
+ timer = setTimeout("updateWidget()", 300);
154
+ }
155
+ </script>
156
+
157
+ <style type="text/css">
158
+ .smallExplanation {
159
+ background:#FAFAFA;
160
+ color:#667788;
161
+ font-size:8pt;
162
+ line-height:13px;
163
+ margin:4px 0 0 0;
164
+ padding:8px;
165
+ display: inline-block;
166
+ }
167
+ .inputtextshort {
168
+ width:200px;
169
+ }
170
+ .inputtext {
171
+ width:450px;
172
+ }
173
+ .secthead {
174
+ border-bottom:1px solid #EEEEEE;
175
+ color:#8899AA;
176
+ font-size:13px;
177
+ line-height:21px;
178
+ }
179
+ .sethead {
180
+ width:200px;
181
+ }
182
+ .swatch {
183
+ float: left;
184
+ width: 15px
185
+ }
186
+ .swatch:hover {
187
+ background-image:url(http://www.zopim.com/static/images/colorselectbg.gif);
188
+ cursor:pointer;
189
+ }
190
+ .sorry {
191
+ color:#c33;
192
+ }
193
+ </style>
194
+
195
+ <div class="wrap">
196
+ <div id="icon-themes" class="icon32"><br/></div><h2>Customize your widget</h2>
197
+
198
+ <?php echo $message; ?>
199
+ <form method="post" action="admin.php?page=zopim_customize_widget">
200
+ <div class="metabox-holder">
201
+ <div class="postbox">
202
+ <h3 class="hndle"><span>General Settings</span></h3>
203
+ <div style="padding:10px;">
204
+ <table class="form-table">
205
+ <tr valign="top">
206
+ <th scope="row" class="sethead">Language</th>
207
+ <td>
208
+
209
+ <select name="zopimLang" id="zopimLang" onchange="updateWidget()">
210
+ <?php
211
+
212
+ $languages = get_languages();
213
+ echo generate_options($languages, get_option('zopimLang'));
214
+ ?>
215
+ </select>
216
+ </td>
217
+ </tr>
218
+ <tr valign="top" style="display:none;">
219
+ <th scope="row">Use Logged in Username / Email</th>
220
+ <td><input onchange="updateWidget()" type="checkbox" id="zopimGetVisitorInfo" name="zopimGetVisitorInfo" value="zopimGetVisitorInfo" <?php if (get_option('zopimGetVisitorInfo')!="disabled") { echo "checked='checked'"; } ?> /></td>
221
+ </tr>
222
+ <tr valign="top">
223
+ <th scope="row" class="sethead">Position</th>
224
+ <td>
225
+
226
+ <select name="zopimPosition" id="zopimPosition" onchange="updatePosition()">
227
+ <?php
228
+ $positions = array("br" => "Bottom Right", "bl" => "Bottom Left");
229
+ echo generate_options($positions, get_option('zopimPosition'));
230
+ ?>
231
+ </select>
232
+ </td>
233
+ </tr>
234
+
235
+ <tr valign="top">
236
+ <th scope="row">Hide chat bar when offline<br>
237
+ <!-- <div class="smallExplanation">Hide the chat bar when no agents are available to answer questions. This prevents visitors from sending you offline messages. </div> -->
238
+ </th>
239
+ <td>
240
+ <input onchange="updateWidget()" type="checkbox" id="zopimHideOnOffline" name="zopimHideOnOffline" value="zopimHideOnOffline" <?php if (get_option('zopimHideOnOffline') && get_option('zopimHideOnOffline')!="disabled") { echo "checked='checked'"; } ?> /> This prevents visitors from sending you offline messages -
241
+ <a href="#" onclick="$zopim.livechat.button.show();return false">force show chat button</a>
242
+ </td>
243
+ </tr>
244
+ </table>
245
+ </div>
246
+ </div>
247
+ </div>
248
+ <div class="metabox-holder">
249
+ <div class="postbox">
250
+ <h3 class="hndle"><span>Color & Theme Settings</span></h3>
251
+ <div style="padding:10px;">
252
+ Settings reflect instantly on your preview widget. Try it out!<br/>
253
+ <table class="form-table" style="width: 700px">
254
+ <tr valign="top">
255
+ <td colspan="2">
256
+ <input type="hidden" id="zopimColor" name="zopimColor" value="<?php echo get_option('zopimColor'); ?>">
257
+ <?php
258
+
259
+ if ($accountDetails->color_customization_enabled == 1) {
260
+ echo "<div style='display:inline-block;border:11px solid #888;background:#888;color:#fee;'>";
261
+ $colors = curl_get_url(ZOPIM_COLORS_LIST);
262
+ $colors = explode("\n", $colors);
263
+
264
+ $i=0;
265
+ foreach ($colors as $color) {
266
+ echo "<div class='swatch' style='background-color: $color;' onclick=\"document.getElementById('zopimColor').value='$color'; updateWidget();\">&nbsp</div>";
267
+ if (++$i%40==0) {
268
+ echo "<br>";
269
+ }
270
+ }
271
+ echo "<br><a href=# style='color:#ff8' onclick=\"document.getElementById('zopimColor').value=''; updateWidget();\">Restore default color</a></div>";
272
+ } else {
273
+ echo "<div class='sorry'>Sorry, your plan does not allow for color customization. Please upgrade to enjoy choice of color!</div>";
274
+ }
275
+ ?>
276
+ </td>
277
+ </tr>
278
+ <tr valign="top">
279
+ <th scope="row" class="sethead">Select A Theme</th>
280
+ <td style="width: 400px"><div align="left">
281
+ <?php
282
+
283
+ if ($accountDetails->widget_customization_enabled == 1) {
284
+ echo '<select name="zopimTheme" id="zopimTheme" onchange="updateWidget()">';
285
+ $themes = curl_get_url(ZOPIM_THEMES_LIST);
286
+ $themes = valuekeys(explode("\n", $themes));
287
+ ksort($themes);
288
+
289
+ echo generate_options($themes, get_option('zopimTheme'));
290
+ echo "</select> <a href='#' onclick='\$zopim.livechat.window.toggle();return false;'>View the Chat Panel</a> for changes";
291
+ } else {
292
+ echo "<div class='sorry'>Sorry, your plan does not allow for theme customization. Please upgrade to enjoy choice of themes!</div>";
293
+ echo '<input type=hidden value="" name="zopimTheme" id="zopimTheme">';
294
+ }
295
+ ?>
296
+ </td>
297
+ </tr>
298
+ </table>
299
+ </div>
300
+ </div>
301
+ </div>
302
+
303
+ <div class="metabox-holder">
304
+ <div class="postbox">
305
+ <h3 class="hndle"><span>Help Bubble Settings</span></h3>
306
+ <div style="padding:10px;">
307
+ <table class="form-table">
308
+
309
+ <tr valign="top">
310
+ <th scope="row">Display Help Bubble<br>
311
+ </th>
312
+ <td>
313
+ <select onchange="updateBubbleStatus()" type="checkbox" id="zopimBubbleEnable" name="zopimBubbleEnable">
314
+ <?php
315
+ $bubble_modes = array("default" => "Let user decide", "show" => "Always show", "hide" => "Always hide");
316
+ echo generate_options($bubble_modes, get_option('zopimBubbleEnable'));
317
+ ?>
318
+ </select>
319
+ </tr>
320
+ <tr valign="top">
321
+ <th scope="row" class="sethead">Help Bubble Title
322
+ <!--<div class="smallExplanation">Entice your visitors with this friendly chat bubble title!</div>--></th>
323
+ <td>
324
+
325
+ <input class="inputtextshort" name="zopimBubbleTitle" id="zopimBubbleTitle" onKeyup="updateSoon()" value="<?php echo get_option('zopimBubbleTitle'); ?>"> <a href="#" onclick="updateBubbleStatus();">Refresh</a>
326
+ </td>
327
+ </tr>
328
+
329
+ <tr valign="top">
330
+ <th scope="row" class="sethead">Help Bubble Message
331
+ <!--<div class="smallExplanation">Welcome your visitors and encourage them to talk with you</div>--></th>
332
+ <td>
333
+
334
+ <input class="inputtext" name="zopimBubbleText" id="zopimBubbleText" onKeyup="updateSoon()" value="<?php echo get_option('zopimBubbleText'); ?>">
335
+ </td>
336
+ </tr>
337
+
338
+
339
+ </table>
340
+ </div>
341
+ </div>
342
+ </div>
343
+
344
+ <?php
345
+ if (get_option('zopimUseGreetings') && get_option('zopimUseGreetings')!="disabled") {
346
+ $useGreetings = true;
347
+ } else {
348
+ $useGreetings = false;
349
+ }
350
+ ?>
351
+ <div class="metabox-holder">
352
+ <div class="postbox">
353
+ <h3 class="hndle"><span>Greeting Message Settings</span></h3>
354
+ <div style="padding:10px;">
355
+ <table class="form-table">
356
+ <tr>
357
+ <td colspan="2">
358
+ <input type="checkbox" id="zopimUseGreetings" onchange="greetingsChanged()" value="zopimUseGreetings" name="zopimUseGreetings"
359
+ <?php if ($useGreetings) { echo "checked='checked'"; } ?>/>
360
+ Use these greeting messages
361
+ </td>
362
+ </tr>
363
+ <tr><td colspan="2"><div class="secthead">Message Shown on Chat Bar (max 26 characters)</div></td></tr>
364
+ <tr valign="top">
365
+ <th scope="row" class="sethead">Online</th>
366
+ <td>
367
+ <input class="inputtextshort" name="zopimOnlineShort" id="zopimOnlineShort" onKeyup="updateSoon()"
368
+ value="<?php echo $greetings->online->bar; ?>"
369
+ <?php if (!$useGreetings) echo "disabled='disabled'"?>
370
+ maxlength="26">
371
+ </td>
372
+ </tr>
373
+
374
+ <tr valign="top">
375
+ <th scope="row" class="sethead">Away</th>
376
+ <td>
377
+ <input class="inputtextshort" name="zopimAwayShort" id="zopimAwayShort" onKeyup="updateSoon()" value="<?php echo $greetings->away->bar; ?>" <?php if (!$useGreetings) echo "disabled='disabled'"?> maxlength="26">
378
+ </td>
379
+ </tr>
380
+
381
+ <tr valign="top">
382
+ <th scope="row" class="sethead">Offline</th>
383
+ <td>
384
+ <input class="inputtextshort" name="zopimOfflineShort" id="zopimOfflineShort" onKeyup="updateSoon()" value="<?php echo $greetings->offline->bar; ?>" <?php if (!$useGreetings) echo "disabled='disabled'"?> maxlength="26">
385
+ </td>
386
+ </tr>
387
+
388
+
389
+ <tr><td colspan="2"><div class="secthead">Message Shown on Chat Panel (max 140 characters)</div></td></tr>
390
+ <tr valign="top">
391
+ <th scope="row" class="sethead">Online</th>
392
+ <td>
393
+ <textarea class="inputtext" name="zopimOnlineLong" id="zopimOnlineLong" onKeyup="updateSoon()" <?php if (!$useGreetings) echo "disabled='disabled'"?> ><?php echo $greetings->online->window; ?></textarea>
394
+ </td>
395
+ </tr>
396
+
397
+ <tr valign="top">
398
+ <th scope="row" class="sethead">Away</th>
399
+ <td>
400
+ <textarea class="inputtext" name="zopimAwayLong" id="zopimAwayLong" onKeyup="updateSoon()" <?php if (!$useGreetings) echo "disabled='disabled'"?> ><?php echo $greetings->away->window; ?></textarea>
401
+ </td>
402
+ </tr>
403
+
404
+ <tr valign="top">
405
+ <th scope="row" class="sethead">Offline</th>
406
+ <td>
407
+ <textarea class="inputtext" name="zopimOfflineLong" id="zopimOfflineLong" onKeyup="updateSoon()" <?php if (!$useGreetings) echo "disabled='disabled'"?> ><?php echo $greetings->offline->window; ?></textarea>
408
+ </td>
409
+ </tr>
410
+ </table>
411
+
412
+ </div>
413
+ </div>
414
+ </div>
415
+
416
+
417
+
418
+ <p class="submit">
419
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
420
+ </p>
421
+
422
+ </form>
423
+ </div>
424
+
425
+ <?php }
426
+
427
+ function valuekeys($array) {
428
+
429
+ $newarray = array();
430
+ foreach ($array as $s) {
431
+ $newarray[$s] = $s;
432
+ }
433
+
434
+ return $newarray;
435
+ }
436
+
437
+ function generate_options($options, $current) {
438
+
439
+ $out = "";
440
+ foreach ($options as $key => $value) {
441
+
442
+ if ($value != "") {
443
+ $isselected = "";
444
+ if ($current == $key) {
445
+ $isselected = "selected";
446
+ }
447
+ $out .= '<option value="'.$key.'" '.$isselected.'>'.$value.'</option>';
448
+ }
449
+ }
450
+
451
+ return $out;
452
+ }
453
+
454
+ function get_languages() {
455
+ $langjson = '{"--":" - Auto Detect - ","ar":"Arabic","bn":"Bengali","bg":"Bulgarian","zh_CN":"Chinese (China)","zh_TW":"Chinese (Taiwan)","hr":"Croatian","cs":"Czech","da":"Danish","nl":"Dutch; Flemish","et":"Estonian","fo":"Faroese","fi":"Finnish","fr":"French","ka":"Georgian","de":"German","el":"Greek","he":"Hebrew","hu":"Hungarian","is":"Icelandic","id":"Indonesian","it":"Italian","ja":"Japanese","ko":"Korean","ku":"Kurdish","lv":"Latvian","lt":"Lithuanian","mk":"Macedonian","ms":"Malay","nb":"Norwegian Bokmal","fa":"Persian","pl":"Polish","pt":"Portuguese","pt_BR":"Portuguese (Brazil)","ro":"Romanian","ru":"Russian","sr":"Serbian","sk":"Slovak","sl":"Slovenian","es":"Spanish; Castilian","sv":"Swedish","th":"Thai","tr":"Turkish","uk":"Ukrainian","ur":"Urdu","vi":"Vietnamese"}';
456
+
457
+ return json_to_array($langjson);
458
+ }
459
+
460
+ function update_checkbox($fieldname) {
461
+ if (isset($_POST["$fieldname"]) && $_POST["$fieldname"] != "") {
462
+ update_option($fieldname, $_POST["$fieldname"]);
463
+ } else {
464
+ update_option($fieldname, "disabled");
465
+ }
466
+ }
467
+
468
+ ?>
trunk/imintegration.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function zopim_instant_messaging() { ?>
4
+
5
+ <div class="wrap">
6
+ <div id="icon-users" class="icon32"></div>
7
+ <h2>Relay your messages</h2>
8
+ Use your favourite Instant Messaging (IM) client to chat with your website visitors!<p>
9
+
10
+
11
+ <?php
12
+
13
+ $salt = array('salt' => get_option('zopimSalt'));
14
+
15
+ if (isset($_GET["remove"]) && $_GET["remove"] == 1) {
16
+ echo "Removed IM Set Up. <br><br>";
17
+
18
+ json_to_array(do_post_request(ZOPIM_IMREMOVE_URL, $salt));
19
+ }
20
+ $iminfo = json_to_array(do_post_request(ZOPIM_IMINFO_URL, $salt));
21
+
22
+ if (isset($iminfo->bots)) { // Can set up IM ?>
23
+
24
+ <style>
25
+ td {}
26
+ .clients td.first {border:none;background:#888;color:#fff;}
27
+ .steps {width:100%}
28
+ .steps td {background:#f9f9f9;padding:15px;}
29
+ .clients td {padding:8px;border-top:1px solid #dfdfdf;background:#fff;}
30
+ .clients {border:1px solid #dfdfdf;background:#fff}
31
+ .explain {
32
+ background:#FAFAFA;
33
+ color:#667788;
34
+ font-size:8pt;
35
+ line-height:13px;
36
+ margin:4px 0 0 0;
37
+ padding:8px 3px;
38
+ display: inline-block;
39
+ }
40
+ </style>
41
+
42
+ <div class="metabox-holder">
43
+ <div class="postbox">
44
+ <h3 class="hndle"><span>Setting up your Chat Bots</span></h3>
45
+ <div style="padding:10px 0px;line-height:17px;">
46
+
47
+ <table class="steps" cellspacing="0" cellpadding="0">
48
+ <tr valign="top">
49
+ <td style="border-right:5px solid #fff;width:394px;">
50
+ 1. Add the Control Bot to the IM Client of your choice.<br/><br/>
51
+
52
+ <table class="clients" cellpadding="0" cellspacing="0">
53
+ <tr><td align="center" width="160" class="first"><b>IM Cient</b></td><td class="first" width="200"><b>Chat Bot's Name</b></td></tr>
54
+ <tr><td valign="center" align="center"><img src="<?php echo ZOPIM_IM_LOGOS ?>big/gtalk.png"></td><td><?php echo $iminfo->bots->gtalk; ?></td></tr>
55
+ <tr><td valign="center" align="center"><img src="<?php echo ZOPIM_IM_LOGOS ?>big/msn.png"></td><td><?php echo $iminfo->bots->msn; ?></td></tr>
56
+ <tr><td valign="center" align="center"><img src="<?php echo ZOPIM_IM_LOGOS ?>big/yahoo.png"></td><td><?php echo $iminfo->bots->yahoo; ?></td></tr>
57
+ <tr><td valign="center" align="center"><img src="<?php echo ZOPIM_IM_LOGOS ?>big/aim.png"></td><td><?php echo $iminfo->bots->aim; ?></td></tr>
58
+ </table>
59
+ <div class="explain">For example, to use <b>MSN Live Messenger</b> to chat,<br/>add <b>zdctrlbot01@hotmail.com</b> to your MSN contact list.</div>
60
+ </td>
61
+ <td>
62
+ 2. Send the Control Bot this message:<br/><br/><input style="font-size:31px;color:#555;margin:0 0 5px;width:380px;" type="text" value="#setup <?php echo $iminfo->auth_key; ?>" id="box-content" readonly></input><br/>
63
+ <input id="copy" value="Copy to Clipboard" type="button"></input>
64
+
65
+ <br/><br/>
66
+ 3. Accept the invitations to add the Chat Bots.<br>
67
+ <div class="explain">Depending on the number of Chat Bots available in your Package,<br/>you may need to accept up to 8 invitations</div>
68
+ <br/><br/>That's all!<br/><br/>
69
+ The Chat Bot will now relay all messages sent from<br/>your website to your IM Client.
70
+ <br/><br/>
71
+ Chat away!
72
+ </td>
73
+ </tr>
74
+ </table>
75
+
76
+ </div>
77
+ </div>
78
+ </div>
79
+ <script type="text/javascript" src="http://www.zopim.com/static/ZeroClipboard.js"></script>
80
+ <script language="javascript">
81
+
82
+ //create client
83
+ ZeroClipboard.setMoviePath('http://www.zopim.com/static/ZeroClipboard.swf');
84
+ var clip = new ZeroClipboard.Client();
85
+
86
+ //event
87
+ function $(id) { return document.getElementById(id); }
88
+
89
+ clip.addEventListener('mousedown',function() {
90
+ clip.setText(document.getElementById('box-content').value);
91
+ });
92
+ clip.addEventListener('complete',function(client,text) {
93
+ window.status = 'copied: ' + text;
94
+ });
95
+ //glue it to the button
96
+ clip.glue('copy');
97
+ </script>
98
+
99
+ <?php } else if (isset($iminfo->status)) { // integration already set up ?>
100
+
101
+ <h3><img src="<?php echo ZOPIM_IM_LOGOS.$iminfo->protocol; ?>.png"> Your <?php echo strtoupper($iminfo->protocol); ?> account is now linked with Zopim.</h3>
102
+
103
+ You are connected using the account: <?php echo $iminfo->username; ?>. <br>
104
+ Your status is now <b><?php echo $iminfo->status; ?></b>.<br><br>
105
+
106
+ <H3>Disable IM Integration</h3>
107
+ You can <a href="admin.php?page=zopim_instant_messaging&remove=1">disable IM integration by clicking here</a>.
108
+
109
+ <?php } else { // could not contact zopim to get the IM status
110
+
111
+ if (get_option('zopimCode') != "zopim") {
112
+
113
+ ?>
114
+
115
+ <div class="metabox-holder">
116
+ <div class="postbox">
117
+ <h3 class="hndle"><span>Account not linked</span></h3>
118
+ <div style="padding:10px;line-height:17px;">
119
+ Please <a href="admin.php?page=zopim_account_config">link your account / check your password</a> before setting up Chat Bots.
120
+
121
+ </div>
122
+ </div>
123
+ </div>
124
+
125
+ <?php } else { ?>
126
+
127
+ <div class="metabox-holder">
128
+ <div class="postbox">
129
+ <h3 class="hndle"><span>Account not activated</span></h3>
130
+ <div style="padding:10px;line-height:17px;">
131
+ Please <a href="admin.php?page=zopim_account_config">activate your account</a> before setting up Chat Bots.
132
+
133
+ </div>
134
+ </div>
135
+ </div>
136
+
137
+ <?php } }
138
+
139
+ }
140
+ ?>
trunk/readme.txt ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Zopim Live Chat ===
2
+ Contributors: bencxr
3
+ Tags: widget, plugin, sidebar, page, admin, enhancement, livechat, chat, widget
4
+ Requires at least: 2.7
5
+ Tested up to: 3.1.1
6
+ Stable tag: 1.1.0
7
+
8
+ Zopim is an award winning facebook-like chatbar built for websites. It connects website owners and visitors together via a cross-browser platform.
9
+
10
+ == Description ==
11
+
12
+ Update: In Oct 2010, Zopim was nominated Asia.s Top 10 Web Apps and selected as Red Herring Asia Top 100 Finalists. Read about it here: <a href="http://blog.zopim.com/?p=681">http://blog.zopim.com/?p=681</a>
13
+ <br/>
14
+ Build relationships with visitors to your website. They will be pleasantly surprised to know that a real person is there to respond to them.
15
+
16
+ * Know what your customers are looking at. See which product page they are currently viewing
17
+
18
+ * Let customers with questions reach you directly. Or proactively click on them to start a conversation
19
+
20
+ * Reply to chats via any browser, or your favorite IM client. Chat from Gtalk, MSN, Yahoo! Messenger, AOL, and from Smart Phones that support mobile IM client.
21
+
22
+ **What does Zopim look like?**
23
+ Zopim shows up as a chatbar docked to the bottom of your website. Visitors chat with you by clicking on the Zopim Chat Bar.
24
+
25
+ **3 Reasons to Use Zopim (& Not Anyone Else)**
26
+
27
+ * Nice Interface, Great User Experience
28
+
29
+ * One click deployment. So simple to setup and use, you.ll start loving it :)
30
+
31
+ * 16 hours online chat support even for free accounts . simply visit our website!
32
+
33
+ **Zopim works across major browsers and IM**
34
+
35
+ * Internet Explorer 6+, Firefox, Google Chrome, Opera, Safari ...
36
+
37
+ * Gtalk / MSN / Yahoo! Messenger / AIM
38
+
39
+ * iPhone, Blackberry & any other Smart Phones that supports mobile IM clients
40
+
41
+ **See all languages available, lovingly translated by Zopim users (in alphabetical order)**
42
+
43
+ * 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
44
+
45
+
46
+ == Changelog ==
47
+ = 1.1.0 =
48
+ * Maintenace update: Greeting messages are now saved properly.
49
+ * Add more language options in customization page.
50
+ * Using new Zopim async embed script: improve page's load time and do not block page's rendering anymore.
51
+
52
+ = 1.0.7 =
53
+ * Maintenance update: Remove phased out "middle left", "middle right" positions
54
+ * Add options to let user decides hiding of chat bubble, no longer force show/hide
55
+ * Enable option for not using plugins' greeting messages
56
+
57
+ = 1.0.6 =
58
+ * Maintenance update: Class' redeclaration conflict fix.
59
+
60
+ = 1.0.5 =
61
+ * Maintenance update: fix minor bug on widget customization page - online msg input
62
+
63
+ = 1.0.4 =
64
+ * Robustness update: Make sure widget won't appear more than once.
65
+
66
+ = 1.0.3 =
67
+ * Maintenance update: New line bugfixes.
68
+
69
+ = 1.0.2 =
70
+ * Maintenance update: More curl robustness enhancements.
71
+
72
+ = 1.0.1 =
73
+ * Maintenance update: More robust connectivity, CURL errors caught
74
+ * Note: PHP Curl is required (and has always been).
75
+
76
+ = 1.0 =
77
+ * Stability update: Official Plugin Launched
78
+
79
+ = 0.6.1 =
80
+ * Update: Launched with improved signup process and minor cosmetic fixes.
81
+
82
+ = 0.6.0 =
83
+ * UI fix: Improved account management page.
84
+
85
+ = 0.5.0 =
86
+
87
+ * Feature: Push surveys and questions to the visitor.
88
+ * Bugfix: In-plugin dashboard will be hidden in full screen mode.
89
+
90
+ = 0.4.0 =
91
+
92
+ * Feature: Provide customer service through your favourite IM client (MSN, GTalk, Yahoo, AIM)
93
+ * Feature: You can access the dashboard in full screen!
94
+
95
+ = 0.3.0 =
96
+
97
+ * Feature: Connect to Zopim servers using 256-bit industry standard SSL for increased security!
98
+ * Feature: You can experiment with customizing the widget even without an account.
99
+ * Feature: Change the automatic messages displayed on the widget when it first loads, and depending on your online status.
100
+ * Feature: Customize the language of the widget.
101
+ * Bugfix: Positioning customization now works properly.
102
+
103
+ = 0.2.0 =
104
+
105
+ * Feature: Live Visitor Analytics (page your users are on, webpaths, length of stay, repeat visits and much more!)
106
+ * Feature: Create an account directly in the plugin.
107
+ * Feature: Rank Visitors by priority of importance.
108
+
109
+ = 0.1.0 =
110
+
111
+ * Feature: Add the Zopim live chat widget to your site!
112
+ * Feature: Customize look and feel of the widget, including themes and color!
113
+ * Feature: Use wordpress user information to populate visitor data in the plugin.
114
+
115
+ == Screenshots ==
116
+
117
+ 1. Chat window on your website - active chat
118
+ 2. Chat widget on your website - minimized
119
+ 3. Account Configuration
120
+ 4. Styling and customiation
121
+ 5. Another nice screenshot on a 'virtual' monitor
122
+
123
+ == Frequently Asked Questions ==
124
+
125
+ = Do I have to install any software on my server to get this working? =
126
+
127
+ Not at all! Zopim is a hosted livechat service. Simply configure the plugin and you're done!
128
+
129
+ = Which web browsers work best with this plugin =
130
+
131
+ Though designed to work on most browsers, Zopim works best in the following environment: IE 6 or later (PC), Firefox 2 or later (Mac, PC, or Linux), Safari 2 or later (Mac), Google Chrome (PC, Mac).
132
+
133
+ = I managed to install the plugin but cannot link up to Zopim. Why? =
134
+ Most likely PHP Curl is not installed or configured properly. Please request your server administrator to enable the PHP CURL extension (see http://www.php.net/manual/en/book.curl.php for details).
135
+
136
+ Alternatively, you can also manually include the script in the footer file ("wp-content/themes/default/footer.php" in your wordpress installation).
137
+
138
+ = Is it free to use? =
139
+
140
+ The plugin comes with a free plan specially tailored for Wordpress users. Power users can purchase upgrade options anytime.
141
+
142
+ = Its just not working for me! HELP! =
143
+
144
+ Dont worry!! We are happy to assist! Just come on down to our site at http://www.zopim.com or leave an email for us at wordpress@zopim.com and we will help you with installation.
145
+
146
+ == Usage ==
147
+
148
+ After enabling the plug in, head on to the widget customization page to change settings and integrate it's look and feel with your site. When done, enable it by visiting the account configuration page and completing the instant signup process.
149
+
150
+ == Installation ==
151
+
152
+ *Server Requirements:* PHP4 or PHP5 with PHP Curl installed.<br/>
153
+ *Wordpress versions:* Wordpress 2.7 and up.<br/>
154
+ *Thanks for using us* :)
trunk/screenshot-1.png ADDED
Binary file
trunk/screenshot-2.png ADDED
Binary file
trunk/screenshot-3.png ADDED
Binary file
trunk/screenshot-4.png ADDED
Binary file
trunk/zopim.php ADDED
@@ -0,0 +1,298 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ Plugin Name: Zopim Widget
5
+ Plugin URI: http://www.zopim.org
6
+ Description: Zopim embeds a chatbar on your website, so that any visitor can chat with you directly by clicking on the chatbar.
7
+ Author: Isidore
8
+ Version: 1.1.0
9
+ Author URI: http://www.isidorechan.com/
10
+ */
11
+
12
+ define('ZOPIM_SCRIPT_DOMAIN', "zopim.com");
13
+ define('ZOPIM_BASE_URL', "https://www.zopim.com/");
14
+ define('ZOPIM_GETACCOUNTDETAILS_URL', ZOPIM_BASE_URL."plugins/getAccountDetails");
15
+ define('ZOPIM_SETDISPLAYNAME_URL', ZOPIM_BASE_URL."plugins/setDisplayName");
16
+ define('ZOPIM_IMINFO_URL', ZOPIM_BASE_URL."plugins/getImSetupInfo");
17
+ define('ZOPIM_IMREMOVE_URL', ZOPIM_BASE_URL."plugins/removeImSetup");
18
+ define('ZOPIM_LOGIN_URL', ZOPIM_BASE_URL."plugins/login");
19
+ define('ZOPIM_SIGNUP_URL', ZOPIM_BASE_URL."plugins/createTrialAccount");
20
+ define('ZOPIM_THEMES_LIST', "http://zopim.com/assets/dashboard/themes/window/plugins-themes.txt");
21
+ define('ZOPIM_COLORS_LIST', "http://zopim.com/assets/dashboard/themes/window/plugins-colors.txt");
22
+ define('ZOPIM_LANGUAGES_URL', "http://translate.zopim.com/projects/zopim/");
23
+ define('ZOPIM_DASHBOARD_URL', "http://dashboard.zopim.com/");
24
+ define('ZOPIM_SMALL_LOGO', "http://zopim.com/assets/branding/zopim.com/chatman/online.png");
25
+ define('ZOPIM_IM_LOGOS', "http://www.zopim.com/static/images/im/");
26
+ define('ZOPIM_THEMES_URL', "http://");
27
+ define('ZOPIM_COLOURS_URL', "http://");
28
+
29
+ require_once dirname( __FILE__ ) . '/accountconfig.php';
30
+ require_once dirname( __FILE__ ) . '/customizewidget.php';
31
+ require_once dirname( __FILE__ ) . '/imintegration.php';
32
+
33
+ // We need some CSS to position the paragraph
34
+ function zopimme() {
35
+ global $current_user, $zopimshown;
36
+
37
+ $code = get_option('zopimCode');
38
+
39
+ if (($code == "" || $code=="zopim") && (!ereg("zopim", $_GET["page"]))&& (!ereg("zopim", $_SERVER["SERVER_NAME"]))) { return; }
40
+
41
+ // dont show this more than once
42
+ if (isset($zopimshown) && $zopimshown == 1) { return; }
43
+ $zopimshown = 1;
44
+
45
+ // Use zopim's code...
46
+ echo "
47
+ <!-- Start of Zopim Live Chat Script -->
48
+ <script type=\"text/javascript\">
49
+ window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=
50
+ z.s=d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o
51
+ ){z.set._.push(o)};$.setAttribute('charset','utf-8');$.async=!0;z.set.
52
+ _=[];$.src=('https:'==d.location.protocol?'https://ssl':'http://cdn')+
53
+ '.zopim.com/?".$code."';$.type='text/java'+s;z.
54
+ t=+new Date;z._=[];e.parentNode.insertBefore($,e)})(document,'script')
55
+ </script>
56
+ <!-- End of Zopim Live Chat Script -->
57
+ ";
58
+
59
+ $theoptions = array();
60
+ if (get_option('zopimLang') != "" && get_option('zopimLang') != "--") {
61
+ $theoptions[] = " language: '".get_option('zopimLang')."'";
62
+ }
63
+
64
+
65
+ if ( isset($current_user) && get_option("zopimGetVisitorInfo") == "checked" )
66
+ {
67
+ $ul = $current_user->data->first_name;
68
+ $useremail = $current_user->data->user_email;
69
+
70
+ if ($ul!="" && $useremail != "") {
71
+ $theoptions[] = "
72
+ name: '$ul',
73
+ email: '$useremail'
74
+ ";
75
+ }
76
+ }
77
+
78
+ echo "
79
+ \n<script type=\"text/javascript\">
80
+ \n\$zopim( function() {
81
+ ";
82
+ if (count($theoptions) > 0) {
83
+ echo '$zopim.livechat.set({';
84
+ echo implode(", ", $theoptions);
85
+ echo "});";
86
+ }
87
+ if (get_option('zopimPosition') != "") {
88
+ echo "\n\$zopim.livechat.button.setPosition('".get_option('zopimPosition')."');";
89
+ }
90
+ if (get_option('zopimTheme') != "") {
91
+ echo "\n\$zopim.livechat.window.setTheme('".get_option('zopimTheme')."');";
92
+ }
93
+ if (get_option('zopimColor') != "") {
94
+ echo "\n\$zopim.livechat.window.setColor('".get_option('zopimColor')."');";
95
+ }
96
+ if (get_option('zopimBubbleTitle') != "") {
97
+ echo "\n\$zopim.livechat.bubble.setTitle('".addslashes(get_option('zopimBubbleTitle'))."');";
98
+ }
99
+ if (get_option('zopimBubbleText') != "") {
100
+ echo "\n\$zopim.livechat.bubble.setText('".addslashes(get_option('zopimBubbleText'))."');";
101
+ }
102
+ if (get_option('zopimBubbleEnable') == "show") {
103
+ echo "\n\$zopim.livechat.bubble.show(true);";
104
+ } elseif (get_option('zopimBubbleEnable') == "hide") {
105
+ echo "\n\$zopim.livechat.bubble.hide(true);";
106
+ }
107
+
108
+ if (get_option('zopimUseGreetings') == "zopimUseGreetings") {
109
+ if (get_option('zopimGreetings') != "") {
110
+ $greetings = json_to_array(get_option('zopimGreetings'));
111
+ foreach ($greetings as $i => $v) {
112
+ foreach ($v as $j => $k) {
113
+ $greetings->$i->$j = str_replace("\r\n", "\\n", $greetings->$i->$j);
114
+ }
115
+ }
116
+ echo "\n\$zopim.livechat.setGreetings({
117
+ 'online' : ['".addslashes($greetings->online->bar)."', '".addslashes($greetings->online->window)."'],
118
+ 'offline': ['".addslashes($greetings->offline->bar)."', '".addslashes($greetings->offline->window)."'],
119
+ 'away' : ['".addslashes($greetings->away->bar)."', '".addslashes($greetings->away->window)."'] });
120
+ ";
121
+ }
122
+ }
123
+ // this need to be called last
124
+ if (get_option('zopimHideOnOffline') == "zopimHideOnOffline") {
125
+ echo "\n\$zopim.livechat.button.setHideWhenOffline(true);";
126
+ }
127
+ echo "\n})</script>";
128
+ }
129
+
130
+ function zopim_create_menu() {
131
+
132
+ //create new top-level menu
133
+ add_menu_page('Account Configuration', 'Zopim Chat', 'administrator', 'zopim_account_config', 'zopim_account_config', ZOPIM_SMALL_LOGO);
134
+ // add_submenu_page('zopim_about', "About", "About", "administrator", 'zopim_about', 'zopim_about');
135
+ add_submenu_page('zopim_account_config', 'Account Configuration', 'Account Setup', 'administrator', 'zopim_account_config', 'zopim_account_config');
136
+ add_submenu_page('zopim_account_config', 'Customize Widget', 'Customize', 'administrator', 'zopim_customize_widget', 'zopim_customize_widget');
137
+ add_submenu_page('zopim_account_config', 'IM Integration', 'IM Chat Bots', 'administrator', 'zopim_instant_messaging', 'zopim_instant_messaging');
138
+ add_submenu_page('zopim_account_config', 'Dashboard', 'Dashboard', 'administrator', 'zopim_dashboard', 'zopim_dashboard');
139
+
140
+
141
+ //call register settings function
142
+ add_action( 'admin_init', 'register_mysettings' );
143
+ }
144
+
145
+ function check_zopimCode() {
146
+ /*
147
+ // if (get_option('zopimCode') == '' && ($_GET["page"] != "zopim_account_config")) {
148
+ if (ereg("zopim", $_GET["page"] )) {
149
+ //add_action( 'admin_notices', create_function( '', 'echo "<div class=\"error\"><p>" . sprintf( "Please <a href=\"%s\">input your Zopim account details</a>.", "admin.php?page=zopim_account_config" ) . "</p></div>";' ) );
150
+ add_action( 'admin_notices', create_function( '', 'echo "<div class=\"error\"><p>This Zopim plugin is a work in progress. We will launch on the 25th of January. Thank you for your interest.</p></div>";' ) );
151
+ }
152
+ */
153
+ return false;
154
+ }
155
+
156
+ function zopim_loader() {
157
+
158
+ add_action( 'admin_menu', 'check_zopimCode' );
159
+ }
160
+
161
+ add_action( 'init', 'zopim_loader' );
162
+
163
+ function zopim_about() {
164
+
165
+ echo "about";
166
+ }
167
+
168
+ function zopim_dashboard() {
169
+
170
+ echo '<div id="dashboarddiv"><iframe id="dashboardiframe" src="'.ZOPIM_DASHBOARD_URL.'" height=700 width=98% scrolling="no"></iframe></div> You may also <a href="'.ZOPIM_DASHBOARD_URL.'" target="_newWindow" onClick="javascript:document.getElementById(\'dashboarddiv\').innerHTML=\'\'; ">access the dashboard in a new window</a>.
171
+ ';
172
+ }
173
+
174
+ // Register the option settings we will be using
175
+ function register_mysettings() {
176
+
177
+ // Authentication and codes
178
+ register_setting( 'zopim-settings-group', 'zopimCode' );
179
+ register_setting( 'zopim-settings-group', 'zopimUsername' );
180
+ register_setting( 'zopim-settings-group', 'zopimSalt' );
181
+ register_setting( 'zopim-settings-group', 'zopimUseSSL' );
182
+
183
+ // General Widget settings
184
+ register_setting( 'zopim-settings-group', 'zopimGetVisitorInfo' );
185
+ register_setting( 'zopim-settings-group', 'zopimLang' );
186
+
187
+ // Chat button settings
188
+ register_setting( 'zopim-settings-group', 'zopimPosition' );
189
+ register_setting( 'zopim-settings-group', 'zopimHideOnOffline' );
190
+ register_setting( 'zopim-settings-group', 'zopimBubbleTitle' );
191
+ register_setting( 'zopim-settings-group', 'zopimBubbleText' );
192
+ register_setting( 'zopim-settings-group', 'zopimBubbleEnable' );
193
+
194
+ // Themes / Color
195
+ register_setting( 'zopim-settings-group', 'zopimColor' );
196
+ register_setting( 'zopim-settings-group', 'zopimTheme' );
197
+
198
+ // Message Settings
199
+ register_setting( 'zopim-settings-group', 'zopimGreetings' );
200
+ register_setting( 'zopim-settings-group', 'zopimUseGreetings' );
201
+
202
+ if (get_option('zopimCode') == "") {
203
+ update_option('zopimCode', "zopim");
204
+ }
205
+
206
+ if (get_option('zopimBubbleTitle') == "") {
207
+ update_option('zopimBubbleTitle', "Questions?");
208
+ }
209
+ if (get_option('zopimBubbleText') == "") {
210
+ update_option('zopimBubbleText', "Click here to chat with us!");
211
+ }
212
+ if (get_option('zopimBubbleEnable') == "") {
213
+ update_option('zopimBubbleEnable', "checked");
214
+ }
215
+
216
+ if (get_option('zopimUseGreetings') == "") {
217
+ update_option('zopimUseGreetings', "disabled");
218
+ }
219
+
220
+ if (get_option('zopimGreetings') == "") {
221
+ update_option('zopimGreetings', '{"away":{"window":"If you leave a question or comment, our agents will be notified and will try to attend to you shortly =)","bar":"Click here to chat"},"offline":{"window":"We are offline, but if you leave your message and contact details, we will try to get back to you =)","bar":"Leave a message"},"online":{"window":"Leave a question or comment and our agents will try to attend to you shortly =)","bar":"Click here to chat"}}');
222
+ }
223
+ }
224
+
225
+ add_action('get_footer', 'zopimme');
226
+ // create custom plugin settings menu
227
+ add_action('admin_menu', 'zopim_create_menu');
228
+
229
+ function do_post_request($url, $_data, $optional_headers = null)
230
+ {
231
+ if (get_option('zopimUseSSL') != "zopimUseSSL") {
232
+ $url = str_replace("https", "http", $url);
233
+ }
234
+
235
+ $data = array();
236
+
237
+ while(list($n,$v) = each($_data)){
238
+ $data[] = urlencode($n)."=".urlencode($v);
239
+ }
240
+
241
+ $data = implode('&', $data);
242
+
243
+ $ch = curl_init();
244
+
245
+ curl_setopt($ch, CURLOPT_URL, $url);
246
+ curl_setopt($ch, CURLOPT_POST, true);
247
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
248
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
249
+
250
+ $response = curl_exec($ch);
251
+ curl_close($ch);
252
+
253
+ return $response;
254
+ }
255
+
256
+ function json_to_array($json) {
257
+
258
+ // json_decode does exist but only in php > 5.2.0
259
+ require_once('JSON.php');
260
+
261
+ $jsonparser = new Services_JSON();
262
+
263
+ return ($jsonparser->decode($json));
264
+ }
265
+
266
+ function to_json($variable) {
267
+
268
+ // json_decode does exist but only in php > 5.2.0
269
+ require_once('JSON.php');
270
+
271
+ $jsonparser = new Services_JSON();
272
+
273
+ return ($jsonparser->encode($variable));
274
+ }
275
+
276
+ function getAccountDetails($salt) {
277
+
278
+ $salty = array(
279
+ "salt" => get_option('zopimSalt')
280
+ );
281
+
282
+ return json_to_array(do_post_request(ZOPIM_GETACCOUNTDETAILS_URL, $salty));
283
+ }
284
+
285
+ function curl_get_url($filename) {
286
+
287
+ $ch = curl_init();
288
+ $timeout = 5; // set to zero for no timeout
289
+ curl_setopt ($ch, CURLOPT_URL, $filename);
290
+ curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
291
+ curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
292
+ $file_contents = curl_exec($ch);
293
+ curl_close($ch);
294
+
295
+ return $file_contents;
296
+ }
297
+
298
+ ?>
zopim.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: Zopim Widget
5
  Plugin URI: http://www.zopim.org
6
  Description: Zopim embeds a chatbar on your website, so that any visitor can chat with you directly by clicking on the chatbar.
7
  Author: Isidore
8
- Version: 1.0.7
9
  Author URI: http://www.isidorechan.com/
10
  */
11
 
@@ -44,10 +44,15 @@ function zopimme() {
44
 
45
  // Use zopim's code...
46
  echo "
47
- <!-- Start of Zopim Live Chat Script -->
48
- <script type=\"text/javascript\">
49
- document.write(unescape(\"%3Cscript src='\" + document.location.protocol + \"//".ZOPIM_SCRIPT_DOMAIN."/?".$code."' charset='utf-8' type='text/javascript'%3E%3C/script%3E\"));
50
- </script>
 
 
 
 
 
51
  <!-- End of Zopim Live Chat Script -->
52
  ";
53
 
@@ -70,11 +75,14 @@ document.write(unescape(\"%3Cscript src='\" + document.location.protocol + \"//"
70
  }
71
  }
72
 
73
- echo '<script type="text/javascript">';
 
 
 
74
  if (count($theoptions) > 0) {
75
  echo '$zopim.livechat.set({';
76
  echo implode(", ", $theoptions);
77
- echo " });";
78
  }
79
  if (get_option('zopimPosition') != "") {
80
  echo "\n\$zopim.livechat.button.setPosition('".get_option('zopimPosition')."');";
@@ -106,17 +114,17 @@ document.write(unescape(\"%3Cscript src='\" + document.location.protocol + \"//"
106
  }
107
  }
108
  echo "\n\$zopim.livechat.setGreetings({
109
- 'online': ['".addslashes($greetings->online->bar)."', '".addslashes($greetings->online->window)."'],
110
- 'offline': ['".addslashes($greetings->offline->bar)."', '".addslashes($greetings->offline->window)."'],
111
- 'away': ['".addslashes($greetings->away->bar)."', '".addslashes($greetings->away->window)."'] });
112
- ";
113
  }
114
  }
115
  // this need to be called last
116
  if (get_option('zopimHideOnOffline') == "zopimHideOnOffline") {
117
  echo "\n\$zopim.livechat.button.setHideWhenOffline(true);";
118
  }
119
- echo "</script>";
120
  }
121
 
122
  function zopim_create_menu() {
@@ -129,6 +137,7 @@ function zopim_create_menu() {
129
  add_submenu_page('zopim_account_config', 'IM Integration', 'IM Chat Bots', 'administrator', 'zopim_instant_messaging', 'zopim_instant_messaging');
130
  add_submenu_page('zopim_account_config', 'Dashboard', 'Dashboard', 'administrator', 'zopim_dashboard', 'zopim_dashboard');
131
 
 
132
  //call register settings function
133
  add_action( 'admin_init', 'register_mysettings' );
134
  }
@@ -188,6 +197,7 @@ function register_mysettings() {
188
 
189
  // Message Settings
190
  register_setting( 'zopim-settings-group', 'zopimGreetings' );
 
191
 
192
  if (get_option('zopimCode') == "") {
193
  update_option('zopimCode', "zopim");
@@ -203,6 +213,10 @@ function register_mysettings() {
203
  update_option('zopimBubbleEnable', "checked");
204
  }
205
 
 
 
 
 
206
  if (get_option('zopimGreetings') == "") {
207
  update_option('zopimGreetings', '{"away":{"window":"If you leave a question or comment, our agents will be notified and will try to attend to you shortly =)","bar":"Click here to chat"},"offline":{"window":"We are offline, but if you leave your message and contact details, we will try to get back to you =)","bar":"Leave a message"},"online":{"window":"Leave a question or comment and our agents will try to attend to you shortly =)","bar":"Click here to chat"}}');
208
  }
5
  Plugin URI: http://www.zopim.org
6
  Description: Zopim embeds a chatbar on your website, so that any visitor can chat with you directly by clicking on the chatbar.
7
  Author: Isidore
8
+ Version: 1.1.0
9
  Author URI: http://www.isidorechan.com/
10
  */
11
 
44
 
45
  // Use zopim's code...
46
  echo "
47
+ <!-- Start of Zopim Live Chat Script -->
48
+ <script type=\"text/javascript\">
49
+ window.\$zopim||(function(d,s){var z=\$zopim=function(c){z._.push(c)},$=
50
+ z.s=d.createElement(s),e=d.getElementsByTagName(s)[0];z.set=function(o
51
+ ){z.set._.push(o)};$.setAttribute('charset','utf-8');$.async=!0;z.set.
52
+ _=[];$.src=('https:'==d.location.protocol?'https://ssl':'http://cdn')+
53
+ '.zopim.com/?".$code."';$.type='text/java'+s;z.
54
+ t=+new Date;z._=[];e.parentNode.insertBefore($,e)})(document,'script')
55
+ </script>
56
  <!-- End of Zopim Live Chat Script -->
57
  ";
58
 
75
  }
76
  }
77
 
78
+ echo "
79
+ \n<script type=\"text/javascript\">
80
+ \n\$zopim( function() {
81
+ ";
82
  if (count($theoptions) > 0) {
83
  echo '$zopim.livechat.set({';
84
  echo implode(", ", $theoptions);
85
+ echo "});";
86
  }
87
  if (get_option('zopimPosition') != "") {
88
  echo "\n\$zopim.livechat.button.setPosition('".get_option('zopimPosition')."');";
114
  }
115
  }
116
  echo "\n\$zopim.livechat.setGreetings({
117
+ 'online' : ['".addslashes($greetings->online->bar)."', '".addslashes($greetings->online->window)."'],
118
+ 'offline': ['".addslashes($greetings->offline->bar)."', '".addslashes($greetings->offline->window)."'],
119
+ 'away' : ['".addslashes($greetings->away->bar)."', '".addslashes($greetings->away->window)."'] });
120
+ ";
121
  }
122
  }
123
  // this need to be called last
124
  if (get_option('zopimHideOnOffline') == "zopimHideOnOffline") {
125
  echo "\n\$zopim.livechat.button.setHideWhenOffline(true);";
126
  }
127
+ echo "\n})</script>";
128
  }
129
 
130
  function zopim_create_menu() {
137
  add_submenu_page('zopim_account_config', 'IM Integration', 'IM Chat Bots', 'administrator', 'zopim_instant_messaging', 'zopim_instant_messaging');
138
  add_submenu_page('zopim_account_config', 'Dashboard', 'Dashboard', 'administrator', 'zopim_dashboard', 'zopim_dashboard');
139
 
140
+
141
  //call register settings function
142
  add_action( 'admin_init', 'register_mysettings' );
143
  }
197
 
198
  // Message Settings
199
  register_setting( 'zopim-settings-group', 'zopimGreetings' );
200
+ register_setting( 'zopim-settings-group', 'zopimUseGreetings' );
201
 
202
  if (get_option('zopimCode') == "") {
203
  update_option('zopimCode', "zopim");
213
  update_option('zopimBubbleEnable', "checked");
214
  }
215
 
216
+ if (get_option('zopimUseGreetings') == "") {
217
+ update_option('zopimUseGreetings', "disabled");
218
+ }
219
+
220
  if (get_option('zopimGreetings') == "") {
221
  update_option('zopimGreetings', '{"away":{"window":"If you leave a question or comment, our agents will be notified and will try to attend to you shortly =)","bar":"Click here to chat"},"offline":{"window":"We are offline, but if you leave your message and contact details, we will try to get back to you =)","bar":"Leave a message"},"online":{"window":"Leave a question or comment and our agents will try to attend to you shortly =)","bar":"Click here to chat"}}');
222
  }