Disqus Comment System - Version 2.81

Version Description

  • Fix for automatic comment syncing
  • Make sure all markup validates for HTML5
Download this release

Release Info

Developer ryanv12
Plugin Icon Disqus Comment System
Version 2.81
Comparing to
See all releases

Code changes from version 2.77 to 2.81

LICENSE CHANGED
@@ -1,674 +1,674 @@
1
- GNU GENERAL PUBLIC LICENSE
2
- Version 3, 29 June 2007
3
-
4
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
- Everyone is permitted to copy and distribute verbatim copies
6
- of this license document, but changing it is not allowed.
7
-
8
- Preamble
9
-
10
- The GNU General Public License is a free, copyleft license for
11
- software and other kinds of works.
12
-
13
- The licenses for most software and other practical works are designed
14
- to take away your freedom to share and change the works. By contrast,
15
- the GNU General Public License is intended to guarantee your freedom to
16
- share and change all versions of a program--to make sure it remains free
17
- software for all its users. We, the Free Software Foundation, use the
18
- GNU General Public License for most of our software; it applies also to
19
- any other work released this way by its authors. You can apply it to
20
- your programs, too.
21
-
22
- When we speak of free software, we are referring to freedom, not
23
- price. Our General Public Licenses are designed to make sure that you
24
- have the freedom to distribute copies of free software (and charge for
25
- them if you wish), that you receive source code or can get it if you
26
- want it, that you can change the software or use pieces of it in new
27
- free programs, and that you know you can do these things.
28
-
29
- To protect your rights, we need to prevent others from denying you
30
- these rights or asking you to surrender the rights. Therefore, you have
31
- certain responsibilities if you distribute copies of the software, or if
32
- you modify it: responsibilities to respect the freedom of others.
33
-
34
- For example, if you distribute copies of such a program, whether
35
- gratis or for a fee, you must pass on to the recipients the same
36
- freedoms that you received. You must make sure that they, too, receive
37
- or can get the source code. And you must show them these terms so they
38
- know their rights.
39
-
40
- Developers that use the GNU GPL protect your rights with two steps:
41
- (1) assert copyright on the software, and (2) offer you this License
42
- giving you legal permission to copy, distribute and/or modify it.
43
-
44
- For the developers' and authors' protection, the GPL clearly explains
45
- that there is no warranty for this free software. For both users' and
46
- authors' sake, the GPL requires that modified versions be marked as
47
- changed, so that their problems will not be attributed erroneously to
48
- authors of previous versions.
49
-
50
- Some devices are designed to deny users access to install or run
51
- modified versions of the software inside them, although the manufacturer
52
- can do so. This is fundamentally incompatible with the aim of
53
- protecting users' freedom to change the software. The systematic
54
- pattern of such abuse occurs in the area of products for individuals to
55
- use, which is precisely where it is most unacceptable. Therefore, we
56
- have designed this version of the GPL to prohibit the practice for those
57
- products. If such problems arise substantially in other domains, we
58
- stand ready to extend this provision to those domains in future versions
59
- of the GPL, as needed to protect the freedom of users.
60
-
61
- Finally, every program is threatened constantly by software patents.
62
- States should not allow patents to restrict development and use of
63
- software on general-purpose computers, but in those that do, we wish to
64
- avoid the special danger that patents applied to a free program could
65
- make it effectively proprietary. To prevent this, the GPL assures that
66
- patents cannot be used to render the program non-free.
67
-
68
- The precise terms and conditions for copying, distribution and
69
- modification follow.
70
-
71
- TERMS AND CONDITIONS
72
-
73
- 0. Definitions.
74
-
75
- "This License" refers to version 3 of the GNU General Public License.
76
-
77
- "Copyright" also means copyright-like laws that apply to other kinds of
78
- works, such as semiconductor masks.
79
-
80
- "The Program" refers to any copyrightable work licensed under this
81
- License. Each licensee is addressed as "you". "Licensees" and
82
- "recipients" may be individuals or organizations.
83
-
84
- To "modify" a work means to copy from or adapt all or part of the work
85
- in a fashion requiring copyright permission, other than the making of an
86
- exact copy. The resulting work is called a "modified version" of the
87
- earlier work or a work "based on" the earlier work.
88
-
89
- A "covered work" means either the unmodified Program or a work based
90
- on the Program.
91
-
92
- To "propagate" a work means to do anything with it that, without
93
- permission, would make you directly or secondarily liable for
94
- infringement under applicable copyright law, except executing it on a
95
- computer or modifying a private copy. Propagation includes copying,
96
- distribution (with or without modification), making available to the
97
- public, and in some countries other activities as well.
98
-
99
- To "convey" a work means any kind of propagation that enables other
100
- parties to make or receive copies. Mere interaction with a user through
101
- a computer network, with no transfer of a copy, is not conveying.
102
-
103
- An interactive user interface displays "Appropriate Legal Notices"
104
- to the extent that it includes a convenient and prominently visible
105
- feature that (1) displays an appropriate copyright notice, and (2)
106
- tells the user that there is no warranty for the work (except to the
107
- extent that warranties are provided), that licensees may convey the
108
- work under this License, and how to view a copy of this License. If
109
- the interface presents a list of user commands or options, such as a
110
- menu, a prominent item in the list meets this criterion.
111
-
112
- 1. Source Code.
113
-
114
- The "source code" for a work means the preferred form of the work
115
- for making modifications to it. "Object code" means any non-source
116
- form of a work.
117
-
118
- A "Standard Interface" means an interface that either is an official
119
- standard defined by a recognized standards body, or, in the case of
120
- interfaces specified for a particular programming language, one that
121
- is widely used among developers working in that language.
122
-
123
- The "System Libraries" of an executable work include anything, other
124
- than the work as a whole, that (a) is included in the normal form of
125
- packaging a Major Component, but which is not part of that Major
126
- Component, and (b) serves only to enable use of the work with that
127
- Major Component, or to implement a Standard Interface for which an
128
- implementation is available to the public in source code form. A
129
- "Major Component", in this context, means a major essential component
130
- (kernel, window system, and so on) of the specific operating system
131
- (if any) on which the executable work runs, or a compiler used to
132
- produce the work, or an object code interpreter used to run it.
133
-
134
- The "Corresponding Source" for a work in object code form means all
135
- the source code needed to generate, install, and (for an executable
136
- work) run the object code and to modify the work, including scripts to
137
- control those activities. However, it does not include the work's
138
- System Libraries, or general-purpose tools or generally available free
139
- programs which are used unmodified in performing those activities but
140
- which are not part of the work. For example, Corresponding Source
141
- includes interface definition files associated with source files for
142
- the work, and the source code for shared libraries and dynamically
143
- linked subprograms that the work is specifically designed to require,
144
- such as by intimate data communication or control flow between those
145
- subprograms and other parts of the work.
146
-
147
- The Corresponding Source need not include anything that users
148
- can regenerate automatically from other parts of the Corresponding
149
- Source.
150
-
151
- The Corresponding Source for a work in source code form is that
152
- same work.
153
-
154
- 2. Basic Permissions.
155
-
156
- All rights granted under this License are granted for the term of
157
- copyright on the Program, and are irrevocable provided the stated
158
- conditions are met. This License explicitly affirms your unlimited
159
- permission to run the unmodified Program. The output from running a
160
- covered work is covered by this License only if the output, given its
161
- content, constitutes a covered work. This License acknowledges your
162
- rights of fair use or other equivalent, as provided by copyright law.
163
-
164
- You may make, run and propagate covered works that you do not
165
- convey, without conditions so long as your license otherwise remains
166
- in force. You may convey covered works to others for the sole purpose
167
- of having them make modifications exclusively for you, or provide you
168
- with facilities for running those works, provided that you comply with
169
- the terms of this License in conveying all material for which you do
170
- not control copyright. Those thus making or running the covered works
171
- for you must do so exclusively on your behalf, under your direction
172
- and control, on terms that prohibit them from making any copies of
173
- your copyrighted material outside their relationship with you.
174
-
175
- Conveying under any other circumstances is permitted solely under
176
- the conditions stated below. Sublicensing is not allowed; section 10
177
- makes it unnecessary.
178
-
179
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
-
181
- No covered work shall be deemed part of an effective technological
182
- measure under any applicable law fulfilling obligations under article
183
- 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
- similar laws prohibiting or restricting circumvention of such
185
- measures.
186
-
187
- When you convey a covered work, you waive any legal power to forbid
188
- circumvention of technological measures to the extent such circumvention
189
- is effected by exercising rights under this License with respect to
190
- the covered work, and you disclaim any intention to limit operation or
191
- modification of the work as a means of enforcing, against the work's
192
- users, your or third parties' legal rights to forbid circumvention of
193
- technological measures.
194
-
195
- 4. Conveying Verbatim Copies.
196
-
197
- You may convey verbatim copies of the Program's source code as you
198
- receive it, in any medium, provided that you conspicuously and
199
- appropriately publish on each copy an appropriate copyright notice;
200
- keep intact all notices stating that this License and any
201
- non-permissive terms added in accord with section 7 apply to the code;
202
- keep intact all notices of the absence of any warranty; and give all
203
- recipients a copy of this License along with the Program.
204
-
205
- You may charge any price or no price for each copy that you convey,
206
- and you may offer support or warranty protection for a fee.
207
-
208
- 5. Conveying Modified Source Versions.
209
-
210
- You may convey a work based on the Program, or the modifications to
211
- produce it from the Program, in the form of source code under the
212
- terms of section 4, provided that you also meet all of these conditions:
213
-
214
- a) The work must carry prominent notices stating that you modified
215
- it, and giving a relevant date.
216
-
217
- b) The work must carry prominent notices stating that it is
218
- released under this License and any conditions added under section
219
- 7. This requirement modifies the requirement in section 4 to
220
- "keep intact all notices".
221
-
222
- c) You must license the entire work, as a whole, under this
223
- License to anyone who comes into possession of a copy. This
224
- License will therefore apply, along with any applicable section 7
225
- additional terms, to the whole of the work, and all its parts,
226
- regardless of how they are packaged. This License gives no
227
- permission to license the work in any other way, but it does not
228
- invalidate such permission if you have separately received it.
229
-
230
- d) If the work has interactive user interfaces, each must display
231
- Appropriate Legal Notices; however, if the Program has interactive
232
- interfaces that do not display Appropriate Legal Notices, your
233
- work need not make them do so.
234
-
235
- A compilation of a covered work with other separate and independent
236
- works, which are not by their nature extensions of the covered work,
237
- and which are not combined with it such as to form a larger program,
238
- in or on a volume of a storage or distribution medium, is called an
239
- "aggregate" if the compilation and its resulting copyright are not
240
- used to limit the access or legal rights of the compilation's users
241
- beyond what the individual works permit. Inclusion of a covered work
242
- in an aggregate does not cause this License to apply to the other
243
- parts of the aggregate.
244
-
245
- 6. Conveying Non-Source Forms.
246
-
247
- You may convey a covered work in object code form under the terms
248
- of sections 4 and 5, provided that you also convey the
249
- machine-readable Corresponding Source under the terms of this License,
250
- in one of these ways:
251
-
252
- a) Convey the object code in, or embodied in, a physical product
253
- (including a physical distribution medium), accompanied by the
254
- Corresponding Source fixed on a durable physical medium
255
- customarily used for software interchange.
256
-
257
- b) Convey the object code in, or embodied in, a physical product
258
- (including a physical distribution medium), accompanied by a
259
- written offer, valid for at least three years and valid for as
260
- long as you offer spare parts or customer support for that product
261
- model, to give anyone who possesses the object code either (1) a
262
- copy of the Corresponding Source for all the software in the
263
- product that is covered by this License, on a durable physical
264
- medium customarily used for software interchange, for a price no
265
- more than your reasonable cost of physically performing this
266
- conveying of source, or (2) access to copy the
267
- Corresponding Source from a network server at no charge.
268
-
269
- c) Convey individual copies of the object code with a copy of the
270
- written offer to provide the Corresponding Source. This
271
- alternative is allowed only occasionally and noncommercially, and
272
- only if you received the object code with such an offer, in accord
273
- with subsection 6b.
274
-
275
- d) Convey the object code by offering access from a designated
276
- place (gratis or for a charge), and offer equivalent access to the
277
- Corresponding Source in the same way through the same place at no
278
- further charge. You need not require recipients to copy the
279
- Corresponding Source along with the object code. If the place to
280
- copy the object code is a network server, the Corresponding Source
281
- may be on a different server (operated by you or a third party)
282
- that supports equivalent copying facilities, provided you maintain
283
- clear directions next to the object code saying where to find the
284
- Corresponding Source. Regardless of what server hosts the
285
- Corresponding Source, you remain obligated to ensure that it is
286
- available for as long as needed to satisfy these requirements.
287
-
288
- e) Convey the object code using peer-to-peer transmission, provided
289
- you inform other peers where the object code and Corresponding
290
- Source of the work are being offered to the general public at no
291
- charge under subsection 6d.
292
-
293
- A separable portion of the object code, whose source code is excluded
294
- from the Corresponding Source as a System Library, need not be
295
- included in conveying the object code work.
296
-
297
- A "User Product" is either (1) a "consumer product", which means any
298
- tangible personal property which is normally used for personal, family,
299
- or household purposes, or (2) anything designed or sold for incorporation
300
- into a dwelling. In determining whether a product is a consumer product,
301
- doubtful cases shall be resolved in favor of coverage. For a particular
302
- product received by a particular user, "normally used" refers to a
303
- typical or common use of that class of product, regardless of the status
304
- of the particular user or of the way in which the particular user
305
- actually uses, or expects or is expected to use, the product. A product
306
- is a consumer product regardless of whether the product has substantial
307
- commercial, industrial or non-consumer uses, unless such uses represent
308
- the only significant mode of use of the product.
309
-
310
- "Installation Information" for a User Product means any methods,
311
- procedures, authorization keys, or other information required to install
312
- and execute modified versions of a covered work in that User Product from
313
- a modified version of its Corresponding Source. The information must
314
- suffice to ensure that the continued functioning of the modified object
315
- code is in no case prevented or interfered with solely because
316
- modification has been made.
317
-
318
- If you convey an object code work under this section in, or with, or
319
- specifically for use in, a User Product, and the conveying occurs as
320
- part of a transaction in which the right of possession and use of the
321
- User Product is transferred to the recipient in perpetuity or for a
322
- fixed term (regardless of how the transaction is characterized), the
323
- Corresponding Source conveyed under this section must be accompanied
324
- by the Installation Information. But this requirement does not apply
325
- if neither you nor any third party retains the ability to install
326
- modified object code on the User Product (for example, the work has
327
- been installed in ROM).
328
-
329
- The requirement to provide Installation Information does not include a
330
- requirement to continue to provide support service, warranty, or updates
331
- for a work that has been modified or installed by the recipient, or for
332
- the User Product in which it has been modified or installed. Access to a
333
- network may be denied when the modification itself materially and
334
- adversely affects the operation of the network or violates the rules and
335
- protocols for communication across the network.
336
-
337
- Corresponding Source conveyed, and Installation Information provided,
338
- in accord with this section must be in a format that is publicly
339
- documented (and with an implementation available to the public in
340
- source code form), and must require no special password or key for
341
- unpacking, reading or copying.
342
-
343
- 7. Additional Terms.
344
-
345
- "Additional permissions" are terms that supplement the terms of this
346
- License by making exceptions from one or more of its conditions.
347
- Additional permissions that are applicable to the entire Program shall
348
- be treated as though they were included in this License, to the extent
349
- that they are valid under applicable law. If additional permissions
350
- apply only to part of the Program, that part may be used separately
351
- under those permissions, but the entire Program remains governed by
352
- this License without regard to the additional permissions.
353
-
354
- When you convey a copy of a covered work, you may at your option
355
- remove any additional permissions from that copy, or from any part of
356
- it. (Additional permissions may be written to require their own
357
- removal in certain cases when you modify the work.) You may place
358
- additional permissions on material, added by you to a covered work,
359
- for which you have or can give appropriate copyright permission.
360
-
361
- Notwithstanding any other provision of this License, for material you
362
- add to a covered work, you may (if authorized by the copyright holders of
363
- that material) supplement the terms of this License with terms:
364
-
365
- a) Disclaiming warranty or limiting liability differently from the
366
- terms of sections 15 and 16 of this License; or
367
-
368
- b) Requiring preservation of specified reasonable legal notices or
369
- author attributions in that material or in the Appropriate Legal
370
- Notices displayed by works containing it; or
371
-
372
- c) Prohibiting misrepresentation of the origin of that material, or
373
- requiring that modified versions of such material be marked in
374
- reasonable ways as different from the original version; or
375
-
376
- d) Limiting the use for publicity purposes of names of licensors or
377
- authors of the material; or
378
-
379
- e) Declining to grant rights under trademark law for use of some
380
- trade names, trademarks, or service marks; or
381
-
382
- f) Requiring indemnification of licensors and authors of that
383
- material by anyone who conveys the material (or modified versions of
384
- it) with contractual assumptions of liability to the recipient, for
385
- any liability that these contractual assumptions directly impose on
386
- those licensors and authors.
387
-
388
- All other non-permissive additional terms are considered "further
389
- restrictions" within the meaning of section 10. If the Program as you
390
- received it, or any part of it, contains a notice stating that it is
391
- governed by this License along with a term that is a further
392
- restriction, you may remove that term. If a license document contains
393
- a further restriction but permits relicensing or conveying under this
394
- License, you may add to a covered work material governed by the terms
395
- of that license document, provided that the further restriction does
396
- not survive such relicensing or conveying.
397
-
398
- If you add terms to a covered work in accord with this section, you
399
- must place, in the relevant source files, a statement of the
400
- additional terms that apply to those files, or a notice indicating
401
- where to find the applicable terms.
402
-
403
- Additional terms, permissive or non-permissive, may be stated in the
404
- form of a separately written license, or stated as exceptions;
405
- the above requirements apply either way.
406
-
407
- 8. Termination.
408
-
409
- You may not propagate or modify a covered work except as expressly
410
- provided under this License. Any attempt otherwise to propagate or
411
- modify it is void, and will automatically terminate your rights under
412
- this License (including any patent licenses granted under the third
413
- paragraph of section 11).
414
-
415
- However, if you cease all violation of this License, then your
416
- license from a particular copyright holder is reinstated (a)
417
- provisionally, unless and until the copyright holder explicitly and
418
- finally terminates your license, and (b) permanently, if the copyright
419
- holder fails to notify you of the violation by some reasonable means
420
- prior to 60 days after the cessation.
421
-
422
- Moreover, your license from a particular copyright holder is
423
- reinstated permanently if the copyright holder notifies you of the
424
- violation by some reasonable means, this is the first time you have
425
- received notice of violation of this License (for any work) from that
426
- copyright holder, and you cure the violation prior to 30 days after
427
- your receipt of the notice.
428
-
429
- Termination of your rights under this section does not terminate the
430
- licenses of parties who have received copies or rights from you under
431
- this License. If your rights have been terminated and not permanently
432
- reinstated, you do not qualify to receive new licenses for the same
433
- material under section 10.
434
-
435
- 9. Acceptance Not Required for Having Copies.
436
-
437
- You are not required to accept this License in order to receive or
438
- run a copy of the Program. Ancillary propagation of a covered work
439
- occurring solely as a consequence of using peer-to-peer transmission
440
- to receive a copy likewise does not require acceptance. However,
441
- nothing other than this License grants you permission to propagate or
442
- modify any covered work. These actions infringe copyright if you do
443
- not accept this License. Therefore, by modifying or propagating a
444
- covered work, you indicate your acceptance of this License to do so.
445
-
446
- 10. Automatic Licensing of Downstream Recipients.
447
-
448
- Each time you convey a covered work, the recipient automatically
449
- receives a license from the original licensors, to run, modify and
450
- propagate that work, subject to this License. You are not responsible
451
- for enforcing compliance by third parties with this License.
452
-
453
- An "entity transaction" is a transaction transferring control of an
454
- organization, or substantially all assets of one, or subdividing an
455
- organization, or merging organizations. If propagation of a covered
456
- work results from an entity transaction, each party to that
457
- transaction who receives a copy of the work also receives whatever
458
- licenses to the work the party's predecessor in interest had or could
459
- give under the previous paragraph, plus a right to possession of the
460
- Corresponding Source of the work from the predecessor in interest, if
461
- the predecessor has it or can get it with reasonable efforts.
462
-
463
- You may not impose any further restrictions on the exercise of the
464
- rights granted or affirmed under this License. For example, you may
465
- not impose a license fee, royalty, or other charge for exercise of
466
- rights granted under this License, and you may not initiate litigation
467
- (including a cross-claim or counterclaim in a lawsuit) alleging that
468
- any patent claim is infringed by making, using, selling, offering for
469
- sale, or importing the Program or any portion of it.
470
-
471
- 11. Patents.
472
-
473
- A "contributor" is a copyright holder who authorizes use under this
474
- License of the Program or a work on which the Program is based. The
475
- work thus licensed is called the contributor's "contributor version".
476
-
477
- A contributor's "essential patent claims" are all patent claims
478
- owned or controlled by the contributor, whether already acquired or
479
- hereafter acquired, that would be infringed by some manner, permitted
480
- by this License, of making, using, or selling its contributor version,
481
- but do not include claims that would be infringed only as a
482
- consequence of further modification of the contributor version. For
483
- purposes of this definition, "control" includes the right to grant
484
- patent sublicenses in a manner consistent with the requirements of
485
- this License.
486
-
487
- Each contributor grants you a non-exclusive, worldwide, royalty-free
488
- patent license under the contributor's essential patent claims, to
489
- make, use, sell, offer for sale, import and otherwise run, modify and
490
- propagate the contents of its contributor version.
491
-
492
- In the following three paragraphs, a "patent license" is any express
493
- agreement or commitment, however denominated, not to enforce a patent
494
- (such as an express permission to practice a patent or covenant not to
495
- sue for patent infringement). To "grant" such a patent license to a
496
- party means to make such an agreement or commitment not to enforce a
497
- patent against the party.
498
-
499
- If you convey a covered work, knowingly relying on a patent license,
500
- and the Corresponding Source of the work is not available for anyone
501
- to copy, free of charge and under the terms of this License, through a
502
- publicly available network server or other readily accessible means,
503
- then you must either (1) cause the Corresponding Source to be so
504
- available, or (2) arrange to deprive yourself of the benefit of the
505
- patent license for this particular work, or (3) arrange, in a manner
506
- consistent with the requirements of this License, to extend the patent
507
- license to downstream recipients. "Knowingly relying" means you have
508
- actual knowledge that, but for the patent license, your conveying the
509
- covered work in a country, or your recipient's use of the covered work
510
- in a country, would infringe one or more identifiable patents in that
511
- country that you have reason to believe are valid.
512
-
513
- If, pursuant to or in connection with a single transaction or
514
- arrangement, you convey, or propagate by procuring conveyance of, a
515
- covered work, and grant a patent license to some of the parties
516
- receiving the covered work authorizing them to use, propagate, modify
517
- or convey a specific copy of the covered work, then the patent license
518
- you grant is automatically extended to all recipients of the covered
519
- work and works based on it.
520
-
521
- A patent license is "discriminatory" if it does not include within
522
- the scope of its coverage, prohibits the exercise of, or is
523
- conditioned on the non-exercise of one or more of the rights that are
524
- specifically granted under this License. You may not convey a covered
525
- work if you are a party to an arrangement with a third party that is
526
- in the business of distributing software, under which you make payment
527
- to the third party based on the extent of your activity of conveying
528
- the work, and under which the third party grants, to any of the
529
- parties who would receive the covered work from you, a discriminatory
530
- patent license (a) in connection with copies of the covered work
531
- conveyed by you (or copies made from those copies), or (b) primarily
532
- for and in connection with specific products or compilations that
533
- contain the covered work, unless you entered into that arrangement,
534
- or that patent license was granted, prior to 28 March 2007.
535
-
536
- Nothing in this License shall be construed as excluding or limiting
537
- any implied license or other defenses to infringement that may
538
- otherwise be available to you under applicable patent law.
539
-
540
- 12. No Surrender of Others' Freedom.
541
-
542
- If conditions are imposed on you (whether by court order, agreement or
543
- otherwise) that contradict the conditions of this License, they do not
544
- excuse you from the conditions of this License. If you cannot convey a
545
- covered work so as to satisfy simultaneously your obligations under this
546
- License and any other pertinent obligations, then as a consequence you may
547
- not convey it at all. For example, if you agree to terms that obligate you
548
- to collect a royalty for further conveying from those to whom you convey
549
- the Program, the only way you could satisfy both those terms and this
550
- License would be to refrain entirely from conveying the Program.
551
-
552
- 13. Use with the GNU Affero General Public License.
553
-
554
- Notwithstanding any other provision of this License, you have
555
- permission to link or combine any covered work with a work licensed
556
- under version 3 of the GNU Affero General Public License into a single
557
- combined work, and to convey the resulting work. The terms of this
558
- License will continue to apply to the part which is the covered work,
559
- but the special requirements of the GNU Affero General Public License,
560
- section 13, concerning interaction through a network will apply to the
561
- combination as such.
562
-
563
- 14. Revised Versions of this License.
564
-
565
- The Free Software Foundation may publish revised and/or new versions of
566
- the GNU General Public License from time to time. Such new versions will
567
- be similar in spirit to the present version, but may differ in detail to
568
- address new problems or concerns.
569
-
570
- Each version is given a distinguishing version number. If the
571
- Program specifies that a certain numbered version of the GNU General
572
- Public License "or any later version" applies to it, you have the
573
- option of following the terms and conditions either of that numbered
574
- version or of any later version published by the Free Software
575
- Foundation. If the Program does not specify a version number of the
576
- GNU General Public License, you may choose any version ever published
577
- by the Free Software Foundation.
578
-
579
- If the Program specifies that a proxy can decide which future
580
- versions of the GNU General Public License can be used, that proxy's
581
- public statement of acceptance of a version permanently authorizes you
582
- to choose that version for the Program.
583
-
584
- Later license versions may give you additional or different
585
- permissions. However, no additional obligations are imposed on any
586
- author or copyright holder as a result of your choosing to follow a
587
- later version.
588
-
589
- 15. Disclaimer of Warranty.
590
-
591
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
- APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
- HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
- OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
- PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
- IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
- ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
-
600
- 16. Limitation of Liability.
601
-
602
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
- WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
- THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
- GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
- USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
- DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
- PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
- EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
- SUCH DAMAGES.
611
-
612
- 17. Interpretation of Sections 15 and 16.
613
-
614
- If the disclaimer of warranty and limitation of liability provided
615
- above cannot be given local legal effect according to their terms,
616
- reviewing courts shall apply local law that most closely approximates
617
- an absolute waiver of all civil liability in connection with the
618
- Program, unless a warranty or assumption of liability accompanies a
619
- copy of the Program in return for a fee.
620
-
621
- END OF TERMS AND CONDITIONS
622
-
623
- How to Apply These Terms to Your New Programs
624
-
625
- If you develop a new program, and you want it to be of the greatest
626
- possible use to the public, the best way to achieve this is to make it
627
- free software which everyone can redistribute and change under these terms.
628
-
629
- To do so, attach the following notices to the program. It is safest
630
- to attach them to the start of each source file to most effectively
631
- state the exclusion of warranty; and each file should have at least
632
- the "copyright" line and a pointer to where the full notice is found.
633
-
634
- Disqus WordPress Plugin
635
- Copyright (C) 2010 DISQUS
636
-
637
- This program is free software: you can redistribute it and/or modify
638
- it under the terms of the GNU General Public License as published by
639
- the Free Software Foundation, either version 3 of the License, or
640
- (at your option) any later version.
641
-
642
- This program is distributed in the hope that it will be useful,
643
- but WITHOUT ANY WARRANTY; without even the implied warranty of
644
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
- GNU General Public License for more details.
646
-
647
- You should have received a copy of the GNU General Public License
648
- along with this program. If not, see <http://www.gnu.org/licenses/>.
649
-
650
- Also add information on how to contact you by electronic and paper mail.
651
-
652
- If the program does terminal interaction, make it output a short
653
- notice like this when it starts in an interactive mode:
654
-
655
- Disqus WordPress Plugin Copyright (C) 2010 DISQUS
656
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
- This is free software, and you are welcome to redistribute it
658
- under certain conditions; type `show c' for details.
659
-
660
- The hypothetical commands `show w' and `show c' should show the appropriate
661
- parts of the General Public License. Of course, your program's commands
662
- might be different; for a GUI interface, you would use an "about box".
663
-
664
- You should also get your employer (if you work as a programmer) or school,
665
- if any, to sign a "copyright disclaimer" for the program, if necessary.
666
- For more information on this, and how to apply and follow the GNU GPL, see
667
- <http://www.gnu.org/licenses/>.
668
-
669
- The GNU General Public License does not permit incorporating your program
670
- into proprietary programs. If your program is a subroutine library, you
671
- may consider it more useful to permit linking proprietary applications with
672
- the library. If this is what you want to do, use the GNU Lesser General
673
- Public License instead of this License. But first, please read
674
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
622
+
623
+ How to Apply These Terms to Your New Programs
624
+
625
+ If you develop a new program, and you want it to be of the greatest
626
+ possible use to the public, the best way to achieve this is to make it
627
+ free software which everyone can redistribute and change under these terms.
628
+
629
+ To do so, attach the following notices to the program. It is safest
630
+ to attach them to the start of each source file to most effectively
631
+ state the exclusion of warranty; and each file should have at least
632
+ the "copyright" line and a pointer to where the full notice is found.
633
+
634
+ Disqus WordPress Plugin
635
+ Copyright (C) 2010 Disqus
636
+
637
+ This program is free software: you can redistribute it and/or modify
638
+ it under the terms of the GNU General Public License as published by
639
+ the Free Software Foundation, either version 3 of the License, or
640
+ (at your option) any later version.
641
+
642
+ This program is distributed in the hope that it will be useful,
643
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
+ GNU General Public License for more details.
646
+
647
+ You should have received a copy of the GNU General Public License
648
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649
+
650
+ Also add information on how to contact you by electronic and paper mail.
651
+
652
+ If the program does terminal interaction, make it output a short
653
+ notice like this when it starts in an interactive mode:
654
+
655
+ Disqus WordPress Plugin Copyright (C) 2010 Disqus
656
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657
+ This is free software, and you are welcome to redistribute it
658
+ under certain conditions; type `show c' for details.
659
+
660
+ The hypothetical commands `show w' and `show c' should show the appropriate
661
+ parts of the General Public License. Of course, your program's commands
662
+ might be different; for a GUI interface, you would use an "about box".
663
+
664
+ You should also get your employer (if you work as a programmer) or school,
665
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
666
+ For more information on this, and how to apply and follow the GNU GPL, see
667
+ <http://www.gnu.org/licenses/>.
668
+
669
+ The GNU General Public License does not permit incorporating your program
670
+ into proprietary programs. If your program is a subroutine library, you
671
+ may consider it more useful to permit linking proprietary applications with
672
+ the library. If this is what you want to do, use the GNU Lesser General
673
+ Public License instead of this License. But first, please read
674
  <http://www.gnu.org/philosophy/why-not-lgpl.html>.
comments.php CHANGED
@@ -1,134 +1,95 @@
1
- <?php
2
- if (DISQUS_DEBUG) {
3
- echo "<p><strong>Disqus Debug</strong> thread_id: ".get_post_meta($post->ID, 'dsq_thread_id', true)."</p>";
4
- }
5
- ?>
6
-
7
- <div id="disqus_thread">
8
- <?php if (!get_option('disqus_disable_ssr') && have_comments()): ?>
9
- <?php
10
- // if (is_file(TEMPLATEPATH . '/comments.php')) {
11
- // include(TEMPLATEPATH . '/comments.php');
12
- // }
13
- ?>
14
- <div id="dsq-content">
15
-
16
- <?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
17
- <div class="navigation">
18
- <div class="nav-previous"><?php previous_comments_link(dsq_i( '<span class="meta-nav">&larr;</span> Older Comments')); ?></div>
19
- <div class="nav-next"><?php next_comments_link(dsq_i('Newer Comments <span class="meta-nav">&rarr;</span>')); ?></div>
20
- </div> <!-- .navigation -->
21
- <?php endif; // check for comment navigation ?>
22
-
23
- <ul id="dsq-comments">
24
- <?php
25
- /* Loop through and list the comments. Tell wp_list_comments()
26
- * to use dsq_comment() to format the comments.
27
- */
28
- wp_list_comments(array('callback' => 'dsq_comment'));
29
- ?>
30
- </ul>
31
-
32
- <?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
33
- <div class="navigation">
34
- <div class="nav-previous"><?php previous_comments_link(dsq_i( '<span class="meta-nav">&larr;</span> Older Comments')); ?></div>
35
- <div class="nav-next"><?php next_comments_link(dsq_i( 'Newer Comments <span class="meta-nav">&rarr;</span>')); ?></div>
36
- </div><!-- .navigation -->
37
- <?php endif; // check for comment navigation ?>
38
-
39
- </div>
40
-
41
- <?php endif; ?>
42
- </div>
43
-
44
- <script type="text/javascript">
45
- /* <![CDATA[ */
46
- var disqus_url = '<?php echo get_permalink(); ?>';
47
- var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
48
- var disqus_container_id = 'disqus_thread';
49
- var disqus_domain = '<?php echo DISQUS_DOMAIN; ?>';
50
- var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
51
- var disqus_title = <?php echo cf_json_encode(dsq_title_for_post($post)); ?>;
52
- var disqus_config = function () {
53
- var config = this; // Access to the config object
54
- config.language = '<?php echo esc_js(apply_filters('disqus_language_filter', '')) ?>';
55
-
56
- /* Add the ability to add javascript callbacks */
57
- <?php do_action( 'disqus_config' ); ?>
58
-
59
- /*
60
- All currently supported events:
61
- * preData fires just before we request for initial data
62
- * preInit - fires after we get initial data but before we load any dependencies
63
- * onInit - fires when all dependencies are resolved but before dtpl template is rendered
64
- * afterRender - fires when template is rendered but before we show it
65
- * onReady - everything is done
66
- */
67
-
68
- config.callbacks.preData.push(function() {
69
- // clear out the container (its filled for SEO/legacy purposes)
70
- document.getElementById(disqus_container_id).innerHTML = '';
71
- });
72
- <?php if (!get_option('disqus_manual_sync')): ?>
73
- config.callbacks.onReady.push(function() {
74
- // sync comments in the background so we don't block the page
75
- var script = document.createElement('script');
76
- script.async = true;
77
- script.src = '?cf_action=sync_comments&post_id=<?php echo $post->ID; ?>';
78
-
79
- var firstScript = document.getElementsByTagName( "script" )[0];
80
- firstScript.parentNode.insertBefore(script, firstScript);
81
- });
82
- <?php endif; ?>
83
- <?php
84
- $sso = dsq_sso();
85
- if ($sso) {
86
- foreach ($sso as $k=>$v) {
87
- echo "this.page.{$k} = '{$v}';\n";
88
- }
89
- echo dsq_sso_login();
90
- }
91
- ?>
92
- };
93
- /* ]]> */
94
- </script>
95
-
96
- <script type="text/javascript">
97
- /* <![CDATA[ */
98
- var DsqLocal = {
99
- 'trackbacks': [
100
- <?php
101
- $count = 0;
102
- foreach ((array)$comments as $comment) {
103
- $comment_type = get_comment_type();
104
- if ( $comment_type != 'comment' ) {
105
- if( $count ) { echo ','; }
106
- ?>
107
- {
108
- 'author_name': <?php echo cf_json_encode(get_comment_author()); ?>,
109
- 'author_url': <?php echo cf_json_encode(get_comment_author_url()); ?>,
110
- 'date': <?php echo cf_json_encode(get_comment_date('m/d/Y h:i A')); ?>,
111
- 'excerpt': <?php echo cf_json_encode(str_replace(array("\r\n", "\n", "\r"), '<br />', get_comment_excerpt())); ?>,
112
- 'type': <?php echo cf_json_encode($comment_type); ?>
113
- }
114
- <?php
115
- $count++;
116
- }
117
- }
118
- ?>
119
- ],
120
- 'trackback_url': <?php echo cf_json_encode(get_trackback_url()); ?>
121
- };
122
- /* ]]> */
123
- </script>
124
-
125
- <script type="text/javascript">
126
- /* <![CDATA[ */
127
- (function() {
128
- var dsq = document.createElement('script'); dsq.type = 'text/javascript';
129
- dsq.async = true;
130
- dsq.src = '//' + disqus_shortname + '.' + '<?php echo DISQUS_DOMAIN; ?>' + '/' + 'embed' + '.js' + '?pname=wordpress&pver=<?php echo DISQUS_VERSION; ?>';
131
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
132
- })();
133
- /* ]]> */
134
- </script>
1
+ <?php
2
+ if (DISQUS_DEBUG) {
3
+ echo "<p><strong>Disqus Debug</strong> thread_id: ".get_post_meta($post->ID, 'dsq_thread_id', true)."</p>";
4
+ }
5
+ ?>
6
+
7
+ <div id="disqus_thread">
8
+ <?php if (!get_option('disqus_disable_ssr') && have_comments()): ?>
9
+ <div id="dsq-content">
10
+
11
+ <?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
12
+ <div class="navigation">
13
+ <div class="nav-previous">
14
+ <span class="meta-nav">&larr;</span>&nbsp;
15
+ <?php previous_comments_link( dsq_i('Older Comments')); ?>
16
+ </div>
17
+ <div class="nav-next">
18
+ <?php next_comments_link(dsq_i('Newer Comments')); ?>
19
+ &nbsp;<span class="meta-nav">&rarr;</span>
20
+ </div>
21
+ </div> <!-- .navigation -->
22
+ <?php endif; // check for comment navigation ?>
23
+
24
+ <ul id="dsq-comments">
25
+ <?php
26
+ /* Loop through and list the comments. Tell wp_list_comments()
27
+ * to use dsq_comment() to format the comments.
28
+ */
29
+ wp_list_comments(array('callback' => 'dsq_comment'));
30
+ ?>
31
+ </ul>
32
+
33
+ <?php if (get_comment_pages_count() > 1 && get_option('page_comments')): // Are there comments to navigate through? ?>
34
+ <div class="navigation">
35
+ <div class="nav-previous">
36
+ <span class="meta-nav">&larr;</span>
37
+ &nbsp;<?php previous_comments_link( dsq_i('Older Comments') ); ?>
38
+ </div>
39
+ <div class="nav-next">
40
+ <?php next_comments_link( dsq_i('Newer Comments') ); ?>
41
+ &nbsp;<span class="meta-nav">&rarr;</span>
42
+ </div>
43
+ </div><!-- .navigation -->
44
+ <?php endif; // check for comment navigation ?>
45
+
46
+ </div>
47
+
48
+ <?php endif; ?>
49
+ </div>
50
+
51
+ <?php
52
+
53
+ global $wp_version;
54
+
55
+ $embed_vars = array(
56
+ 'disqusConfig' => array(
57
+ 'platform' => 'wordpress@'.$wp_version,
58
+ 'language' => apply_filters( 'disqus_language_filter', '' ),
59
+ ),
60
+ 'disqusIdentifier' => dsq_identifier_for_post( $post ),
61
+ 'disqusShortname' => strtolower( get_option( 'disqus_forum_url' ) ),
62
+ 'disqusTitle' => dsq_title_for_post( $post ),
63
+ 'disqusUrl' => get_permalink(),
64
+ 'options' => array(
65
+ 'manualSync' => get_option('disqus_manual_sync'),
66
+ ),
67
+ 'postId' => $post->ID,
68
+ );
69
+
70
+ // Add SSO vars if enabled
71
+ $sso = dsq_sso();
72
+ if ($sso) {
73
+ global $current_site;
74
+
75
+ foreach ($sso as $k=>$v) {
76
+ $embed_vars['disqusConfig'][$k] = $v;
77
+ }
78
+
79
+ $siteurl = site_url();
80
+ $sitename = get_bloginfo('name');
81
+ $embed_vars['disqusConfig']['sso'] = array(
82
+ 'name' => wp_specialchars_decode($sitename, ENT_QUOTES),
83
+ 'button' => get_option('disqus_sso_button'),
84
+ 'url' => $siteurl.'/wp-login.php',
85
+ 'logout' => $siteurl.'/wp-login.php?action=logout',
86
+ 'width' => '800',
87
+ 'height' => '700',
88
+ );
89
+ }
90
+
91
+ wp_register_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
92
+ wp_localize_script( 'dsq_embed_script', 'embedVars', $embed_vars );
93
+ wp_enqueue_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
94
+
95
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
disqus.php CHANGED
@@ -1,1583 +1,1493 @@
1
- <?php
2
- /*
3
- Plugin Name: Disqus Comment System
4
- Plugin URI: http://disqus.com/
5
- Description: The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus. Head over to the Comments admin page to set up your DISQUS Comment System.
6
- Author: Disqus <team@disqus.com>
7
- Version: 2.77
8
- Author URI: http://disqus.com/
9
- */
10
-
11
- /*.
12
- require_module 'standard';
13
- require_module 'pcre';
14
- require_module 'mysql';
15
- .*/
16
-
17
- require_once(dirname(__FILE__) . '/lib/wp-api.php');
18
-
19
- if (defined('DISQUS_LOCAL')) { // DISQUS defines this for local development purposes
20
- define('DISQUS_DOMAIN', 'dev.disqus.org:8000');
21
- define('DISQUS_IMPORTER_URL', 'http://dev.disqus.org:8001/');
22
- } else {
23
- define('DISQUS_DOMAIN', 'disqus.com');
24
- define('DISQUS_IMPORTER_URL', 'https://import.disqus.com/');
25
- }
26
- define('DISQUS_URL', 'http://' . DISQUS_DOMAIN . '/');
27
- define('DISQUS_MEDIA_URL', 'http://' . DISQUS_DOMAIN . '/media/');
28
- define('DISQUS_API_URL', 'http://' . DISQUS_DOMAIN . '/api/');
29
- define('DISQUS_RSS_PATH', '/latest.rss');
30
- define('DISQUS_CAN_EXPORT', is_file(dirname(__FILE__) . '/export.php'));
31
- if (!defined('DISQUS_DEBUG')) {
32
- define('DISQUS_DEBUG', false);
33
- }
34
- define('DISQUS_VERSION', '2.77');
35
- define('DISQUS_SYNC_TIMEOUT', 30);
36
-
37
- /**
38
- * Returns an array of all option identifiers used by DISQUS.
39
- * @return array[int]string
40
- */
41
- function dsq_options() {
42
- return array(
43
- '_disqus_sync_lock',
44
- '_disqus_sync_post_ids',
45
- # render disqus in the embed
46
- 'disqus_active',
47
- 'disqus_forum_url',
48
- 'disqus_api_key',
49
- 'disqus_user_api_key',
50
- 'disqus_replace',
51
- 'disqus_cc_fix',
52
- # SSO features
53
- 'disqus_partner_key',
54
- 'disqus_public_key',
55
- 'disqus_secret_key',
56
- 'disqus_sso_button',
57
- 'disqus_sso_icon',
58
- # disables automatic sync via cron
59
- 'disqus_manual_sync',
60
- # disables server side rendering
61
- 'disqus_disable_ssr',
62
- # the last sync comment id (from get_forum_posts)
63
- 'disqus_last_comment_id',
64
- 'disqus_version',
65
- );
66
- }
67
-
68
- /**
69
- * @param string $file
70
- * @return string
71
- */
72
- function dsq_plugin_basename($file) {
73
- $file = dirname($file);
74
-
75
- // From WP2.5 wp-includes/plugin.php:plugin_basename()
76
- $file = str_replace('\\','/',$file); // sanitize for Win32 installs
77
- $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
78
- $file = preg_replace('|^.*/' . PLUGINDIR . '/|','',$file); // get relative path from plugins dir
79
-
80
- if ( strstr($file, '/') === false ) {
81
- return $file;
82
- }
83
-
84
- $pieces = explode('/', $file);
85
- return !empty($pieces[count($pieces)-1]) ? $pieces[count($pieces)-1] : $pieces[count($pieces)-2];
86
- }
87
-
88
- if ( !defined('PLUGINDIR') ) {
89
- define('PLUGINDIR', 'wp-content/plugins'); // Relative to ABSPATH. For back compat.
90
- }
91
-
92
- $mt_disqus_version = '2.01';
93
- /**
94
- * Response from Disqus get_thread API call for comments template.
95
- *
96
- * @global string $dsq_response
97
- * @since 1.0
98
- */
99
- $dsq_response = '';
100
- /**
101
- * Disqus API instance.
102
- *
103
- * @global string $dsq_api
104
- * @since 1.0
105
- */
106
- $dsq_api = new DisqusWordPressAPI(get_option('disqus_forum_url'), get_option('disqus_api_key'));
107
-
108
- /**
109
- * DISQUS currently unsupported dev toggle to output comments for this query.
110
- *
111
- * @global bool $DSQ_QUERY_COMMENTS
112
- * @since ?
113
- */
114
- $DSQ_QUERY_COMMENTS = false;
115
-
116
- /**
117
- * DISQUS array to store post_ids from WP_Query for comment JS output.
118
- *
119
- * @global array $DSQ_QUERY_POST_IDS
120
- * @since 2.2
121
- */
122
- $DSQ_QUERY_POST_IDS = array();
123
-
124
- /**
125
- * Helper functions.
126
- */
127
-
128
- /**
129
- * Tests if required options are configured to display the Disqus embed.
130
- * @return bool
131
- */
132
- function dsq_is_installed() {
133
- return get_option('disqus_forum_url') && get_option('disqus_api_key');
134
- }
135
-
136
- /**
137
- * @return bool
138
- */
139
- function dsq_can_replace() {
140
- global $id, $post;
141
-
142
- if (get_option('disqus_active') === '0'){ return false; }
143
-
144
- $replace = get_option('disqus_replace');
145
-
146
- if ( is_feed() ) { return false; }
147
- if ( !isset($post) ) { return false; }
148
- if ( 'draft' == $post->post_status ) { return false; }
149
- if ( !get_option('disqus_forum_url') ) { return false; }
150
- else if ( 'all' == $replace ) { return true; }
151
-
152
- if ( !isset($post->comment_count) ) {
153
- $num_comments = 0;
154
- } else {
155
- if ( 'empty' == $replace ) {
156
- // Only get count of comments, not including pings.
157
-
158
- // If there are comments, make sure there are comments (that are not track/pingbacks)
159
- if ( $post->comment_count > 0 ) {
160
- // Yuck, this causes a DB query for each post. This can be
161
- // replaced with a lighter query, but this is still not optimal.
162
- $comments = get_approved_comments($post->ID);
163
- foreach ( $comments as $comment ) {
164
- if ( $comment->comment_type != 'trackback' && $comment->comment_type != 'pingback' ) {
165
- $num_comments++;
166
- }
167
- }
168
- } else {
169
- $num_comments = 0;
170
- }
171
- }
172
- else {
173
- $num_comments = $post->comment_count;
174
- }
175
- }
176
-
177
- return ( ('empty' == $replace && 0 == $num_comments)
178
- || ('closed' == $replace && 'closed' == $post->comment_status) );
179
- }
180
-
181
- function dsq_manage_dialog($message, $error = false) {
182
- global $wp_version;
183
-
184
- echo '<div '
185
- . ( $error ? 'id="disqus_warning" ' : '')
186
- . 'class="updated fade'
187
- . ( (version_compare($wp_version, '2.5', '<') && $error) ? '-ff0000' : '' )
188
- . '"><p><strong>'
189
- . $message
190
- . '</strong></p></div>';
191
- }
192
-
193
- function dsq_sync_comments($comments) {
194
- global $wpdb;
195
-
196
- // user MUST be logged out during this process
197
- wp_set_current_user(0);
198
-
199
- // we need the thread_ids so we can map them to posts
200
- $thread_map = array();
201
- foreach ( $comments as $comment ) {
202
- $thread_map[$comment->thread->id] = null;
203
- }
204
- $thread_ids = "'" . implode("', '", array_keys($thread_map)) . "'";
205
-
206
- $results = $wpdb->get_results( "SELECT post_id, meta_value FROM $wpdb->postmeta WHERE meta_key = 'dsq_thread_id' AND meta_value IN ({$thread_ids}) LIMIT 1");
207
- foreach ( $results as $result ) {
208
- $thread_map[$result->meta_value] = $result->post_id;
209
- }
210
- unset($result);
211
-
212
- foreach ( $comments as $comment ) {
213
- $ts = strtotime($comment->created_at);
214
- if (!$thread_map[$comment->thread->id] && !empty($comment->thread->identifier)) {
215
- // legacy threads dont already have their meta stored
216
- foreach ( $comment->thread->identifier as $identifier ) {
217
- // we know identifier starts with post_ID
218
- if ($post_ID = (int)substr($identifier, 0, strpos($identifier, ' '))) {
219
- $thread_map[$comment->thread->id] = $post_ID;
220
- update_post_meta($post_ID, 'dsq_thread_id', $comment->thread->id);
221
- if (DISQUS_DEBUG) {
222
- echo "updated post {$post_ID}: dsq_thread_id set to {$comment->thread->id}\n";
223
- }
224
- }
225
- }
226
- unset($identifier);
227
- }
228
- if (!$thread_map[$comment->thread->id]) {
229
- // shouldn't ever happen, but we can't be certain
230
- if (DISQUS_DEBUG) {
231
- if (!empty($comment->thread->identifier)) {
232
- $idents = implode(', ', $comment->thread->identifier);
233
- echo "skipped {$comment->id}: missing thread for identifiers ({$idents})\n";
234
- } else {
235
- echo "skipped {$comment->id}: missing thread (no identifier)\n";
236
- }
237
- }
238
- continue;
239
- }
240
- $results = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->id));
241
- if (count($results)) {
242
- // already exists
243
- if (DISQUS_DEBUG) {
244
- echo "skipped {$comment->id}: comment already exists\n";
245
- }
246
- if (count($results) > 1) {
247
- // clean up duplicates -- fixes an issue where a race condition allowed comments to be synced multiple times
248
- $results = array_slice($results, 1);
249
- foreach ($results as $result) {
250
- $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %s LIMIT 1", $result);
251
- }
252
- }
253
- continue;
254
- }
255
-
256
- $commentdata = false;
257
-
258
- // first lets check by the id we have stored
259
- if ($comment->meta) {
260
- $meta = explode(';', $comment->meta);
261
- foreach ($meta as $value) {
262
- $value = explode('=', $value);
263
- $meta[$value[0]] = $value[1];
264
- }
265
- unset($value);
266
- if ($meta['wp_id']) {
267
- $commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_ID = %s LIMIT 1", $meta['wp_id']), ARRAY_A);
268
- }
269
- }
270
-
271
- // skip comments that were imported but are missing meta information
272
- if (!$commentdata && $comment->imported) {
273
- if (DISQUS_DEBUG) {
274
- echo "skipped {$comment->id}: comment not found and marked as imported\n";
275
- }
276
- continue;
277
- }
278
-
279
- // and follow up using legacy Disqus agent
280
- if (!$commentdata) {
281
- $commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_agent = %s LIMIT 1", 'Disqus/1.0:'.$comment->id), ARRAY_A);
282
- }
283
- if (!$commentdata) {
284
- // Comment doesnt exist yet, lets insert it
285
- if ($comment->status == 'approved') {
286
- $approved = 1;
287
- } elseif ($comment->status == 'spam') {
288
- $approved = 'spam';
289
- } else {
290
- $approved = 0;
291
- }
292
- $commentdata = array(
293
- 'comment_post_ID' => $thread_map[$comment->thread->id],
294
- 'comment_date' => date('Y-m-d\TH:i:s', strtotime($comment->created_at) + (get_option('gmt_offset') * 3600)),
295
- 'comment_date_gmt' => $comment->created_at,
296
- 'comment_content' => apply_filters('pre_comment_content', $comment->message),
297
- 'comment_approved' => $approved,
298
- 'comment_agent' => 'Disqus/1.1('.DISQUS_VERSION.'):'.intval($comment->id),
299
- 'comment_type' => '',
300
- );
301
- if ($comment->is_anonymous) {
302
- $commentdata['comment_author'] = $comment->anonymous_author->name;
303
- $commentdata['comment_author_email'] = $comment->anonymous_author->email;
304
- $commentdata['comment_author_url'] = $comment->anonymous_author->url;
305
- $commentdata['comment_author_IP'] = $comment->ip_address;
306
- } else {
307
- if (!empty($comment->author->display_name)) {
308
- $commentdata['comment_author'] = $comment->author->display_name;
309
- } else {
310
- $commentdata['comment_author'] = $comment->author->username;
311
- }
312
- $commentdata['comment_author_email'] = $comment->author->email;
313
- $commentdata['comment_author_url'] = $comment->author->url;
314
- $commentdata['comment_author_IP'] = $comment->ip_address;
315
- }
316
- $commentdata = wp_filter_comment($commentdata);
317
- if ($comment->parent_post) {
318
- $parent_id = $wpdb->get_var($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->parent_post));
319
- if ($parent_id) {
320
- $commentdata['comment_parent'] = $parent_id;
321
- }
322
- }
323
-
324
- // due to a race condition we need to test again for coment existance
325
- if ($wpdb->get_row($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->id))) {
326
- // already exists
327
- if (DISQUS_DEBUG) {
328
- echo "skipped {$comment->id}: comment already exists (second check)\n";
329
- }
330
- continue;
331
- }
332
-
333
- $commentdata['comment_ID'] = wp_insert_comment($commentdata);
334
- if (DISQUS_DEBUG) {
335
- echo "inserted {$comment->id}: id is {$commentdata[comment_ID]}\n";
336
- }
337
- }
338
- if (!$commentdata['comment_parent'] && $comment->parent_post) {
339
- $parent_id = $wpdb->get_var($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->parent_post));
340
- if ($parent_id) {
341
- $wpdb->query($wpdb->prepare( "UPDATE $wpdb->comments SET comment_parent = %s WHERE comment_id = %s", $parent_id, $commentdata['comment_ID']));
342
- if (DISQUS_DEBUG) {
343
- echo "updated {$comment->id}: comment_parent changed to {$parent_id}\n";
344
- }
345
-
346
- }
347
- }
348
- $comment_id = $commentdata['comment_ID'];
349
- update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
350
- update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
351
- }
352
- unset($comment);
353
-
354
- if( isset($_POST['dsq_api_key']) && $_POST['dsq_api_key'] == get_option('disqus_api_key') ) {
355
- if( isset($_GET['dsq_sync_action']) && isset($_GET['dsq_sync_comment_id']) ) {
356
- $comment_parts = explode('=', $_GET['dsq_sync_comment_id']);
357
-
358
- if (!($comment_id = intval($comment_parts[1])) > 0) {
359
- return;
360
- }
361
-
362
- if( 'wp_id' != $comment_parts[0] ) {
363
- $comment_id = $wpdb->get_var($wpdb->prepare('SELECT comment_ID FROM ' . $wpdb->comments . ' WHERE comment_post_ID = %d AND comment_agent LIKE %s', intval($post->ID), 'Disqus/1.0:' . $comment_id));
364
- }
365
-
366
- switch( $_GET['dsq_sync_action'] ) {
367
- case 'mark_spam':
368
- wp_set_comment_status($comment_id, 'spam');
369
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'spam') -->";
370
- break;
371
- case 'mark_approved':
372
- wp_set_comment_status($comment_id, 'approve');
373
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'approve') -->";
374
- break;
375
- case 'mark_killed':
376
- wp_set_comment_status($comment_id, 'hold');
377
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'hold') -->";
378
- break;
379
- }
380
- }
381
- }
382
- }
383
-
384
- function dsq_request_handler() {
385
- global $dsq_response;
386
- global $dsq_api;
387
- global $post;
388
- global $wpdb;
389
-
390
- if (!empty($_GET['cf_action'])) {
391
- switch ($_GET['cf_action']) {
392
- case 'sync_comments':
393
- if( !( $post_id = $_GET['post_id'] ) ) {
394
- header("HTTP/1.0 400 Bad Request");
395
- die();
396
- }
397
- // schedule the event for 5 minutes from now in case they
398
- // happen to make a quick post
399
- dsq_add_pending_post_id($post_id);
400
-
401
- if (DISQUS_DEBUG) {
402
- $response = dsq_sync_forum();
403
- if (!$response) {
404
- die('// error: '.$dsq_api->get_last_error());
405
- } else {
406
- list($last_comment_id, $comments) = $response;
407
- die('// synced '.$comments.' comments');
408
- }
409
- } else {
410
- $ts = time() + 300;
411
- wp_schedule_single_event($ts, 'dsq_sync_forum');
412
- die('// sync scheduled');
413
- }
414
- break;
415
- case 'export_comments':
416
- if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
417
- $timestamp = intval($_GET['timestamp']);
418
- $post_id = intval($_GET['post_id']);
419
- global $wpdb, $dsq_api;
420
- $post = $wpdb->get_results($wpdb->prepare("
421
- SELECT *
422
- FROM $wpdb->posts
423
- WHERE post_type != 'revision'
424
- AND post_status = 'publish'
425
- AND comment_count > 0
426
- AND ID > %d
427
- ORDER BY ID ASC
428
- LIMIT 1
429
- ", $post_id));
430
- $post = $post[0];
431
- $post_id = $post->ID;
432
- $max_post_id = $wpdb->get_var($wpdb->prepare("
433
- SELECT MAX(ID)
434
- FROM $wpdb->posts
435
- WHERE post_type != 'revision'
436
- AND post_status = 'publish'
437
- AND comment_count > 0
438
- ", $post_id));
439
- $eof = (int)($post_id == $max_post_id);
440
- if ($eof) {
441
- $status = 'complete';
442
- $msg = dsq_i('Your comments have been sent to Disqus and queued for import!<br/><a href="'.DISQUS_IMPORTER_URL.'" target="_blank">See the status of your import at Disqus</a>');
443
- }
444
- else {
445
- $status = 'partial';
446
- $msg = dsq_i('Processed comments on post #%s&hellip;', $post_id);
447
- }
448
- $result = 'fail';
449
- $response = null;
450
- if ($post) {
451
- require_once(dirname(__FILE__) . '/export.php');
452
- $wxr = dsq_export_wp($post);
453
- $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
454
- if (!($response['group_id'] > 0)) {
455
- $result = 'fail';
456
- $msg = '<p class="status dsq-export-fail">'. dsq_i('Sorry, something unexpected happened with the export. Please <a href="#" id="dsq_export_retry">try again</a></p><p>If your API key has changed, you may need to reinstall Disqus (deactivate the plugin and then reactivate it). If you are still having issues, refer to the <a href="%s" onclick="window.open(this.href); return false">WordPress help page</a>.', 'http://disqus.com/help/wordpress'). '</p>';
457
- $response = $dsq_api->get_last_error();
458
- }
459
- else {
460
- if ($eof) {
461
- $msg = dsq_i('Your comments have been sent to Disqus and queued for import!<br/><a href="%s" target="_blank">See the status of your import at Disqus</a>', $response['link']);
462
-
463
- }
464
- $result = 'success';
465
- }
466
- }
467
- // send AJAX response
468
- $response = compact('result', 'timestamp', 'status', 'post_id', 'msg', 'eof', 'response');
469
- header('Content-type: text/javascript');
470
- echo cf_json_encode($response);
471
- die();
472
- }
473
- break;
474
- case 'import_comments':
475
- if (current_user_can('manage_options')) {
476
- if (!isset($_GET['last_comment_id'])) $last_comment_id = false;
477
- else $last_comment_id = $_GET['last_comment_id'];
478
-
479
- if ($_GET['wipe'] == '1') {
480
- $wpdb->query("DELETE FROM `".$wpdb->prefix."commentmeta` WHERE meta_key IN ('dsq_post_id', 'dsq_parent_post_id')");
481
- $wpdb->query("DELETE FROM `".$wpdb->prefix."comments` WHERE comment_agent LIKE 'Disqus/%%'");
482
- }
483
-
484
- ob_start();
485
- $response = dsq_sync_forum($last_comment_id, true);
486
- $debug = ob_get_clean();
487
- if (!$response) {
488
- $status = 'error';
489
- $result = 'fail';
490
- $error = $dsq_api->get_last_error();
491
- $msg = '<p class="status dsq-export-fail">'.dsq_i('There was an error downloading your comments from Disqus.').'<br/>'.htmlspecialchars($error).'</p>';
492
- } else {
493
- list($comments, $last_comment_id) = $response;
494
- if (!$comments) {
495
- $status = 'complete';
496
- $msg = dsq_i('Your comments have been downloaded from Disqus and saved in your local database.');
497
- } else {
498
- $status = 'partial';
499
- $msg = dsq_i('Import in progress (last post id: %s) &hellip;', $last_comment_id);
500
- }
501
- $result = 'success';
502
- }
503
- $debug = explode("\n", $debug);
504
- $response = compact('result', 'status', 'comments', 'msg', 'last_comment_id', 'debug');
505
- header('Content-type: text/javascript');
506
- echo cf_json_encode($response);
507
- die();
508
- }
509
- break;
510
- }
511
- }
512
- }
513
-
514
- add_action('init', 'dsq_request_handler');
515
-
516
- /**
517
- * @param string $option_name
518
- */
519
- function dsq_image_upload_handler($option_name) {
520
- // If the upload field has a file in it
521
- if(isset($_FILES[$option_name]) && ($_FILES[$option_name]['size'] > 0)) {
522
- // Get the type of the uploaded file. This is returned as "type/extension"
523
- $arr_file_type = wp_check_filetype(basename($_FILES[$option_name]['name']));
524
- $uploaded_file_type = $arr_file_type['type'];
525
- // Set an array containing a list of acceptable formats
526
- $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png','image/x-icon');
527
- // If the uploaded file is the right format
528
- if(in_array($uploaded_file_type, $allowed_file_types)) {
529
- // Options array for the wp_handle_upload function. 'test_upload' => false
530
- $upload_overrides = array( 'test_form' => false );
531
- // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
532
- $uploaded_file = wp_handle_upload($_FILES[$option_name], $upload_overrides);
533
- // If the wp_handle_upload call returned a local path for the image
534
- if(isset($uploaded_file['url'])) {
535
- update_option($option_name, $uploaded_file['url']);
536
- }
537
- }
538
- }
539
- }
540
-
541
- function dsq_add_pending_post_id($post_id) {
542
- update_post_meta($post_id, 'dsq_needs_sync', '1', $unique=true);
543
- }
544
-
545
- function dsq_get_pending_post_ids() {
546
- global $wpdb;
547
-
548
- $results = $wpdb->get_results( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'dsq_needs_sync'");
549
- $post_ids = array();
550
- foreach ($results as $result) {
551
- $post_ids[] = $result->post_id;
552
- }
553
- return $post_ids;
554
- }
555
-
556
- function dsq_clear_pending_post_ids($post_ids) {
557
- global $wpdb;
558
-
559
- $post_ids_query = "'" . implode("', '", $post_ids) . "'";
560
- $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key = 'dsq_needs_sync' AND post_id IN ({$post_ids_query})");
561
-
562
- update_meta_cache('dsq_needs_sync', $post_ids);
563
- }
564
-
565
-
566
- function dsq_sync_post($post_id) {
567
- global $dsq_api, $wpdb;
568
-
569
- $post = get_post($post_id);
570
-
571
- // Call update_thread to ensure our permalink is up to date
572
- dsq_update_permalink($post);
573
- }
574
-
575
- function dsq_sync_forum($last_comment_id=false, $force=false) {
576
- global $dsq_api, $wpdb;
577
-
578
- set_time_limit(DISQUS_SYNC_TIMEOUT);
579
-
580
- if ($force) {
581
- $sync_time = null;
582
- } else {
583
- $sync_time = (int)get_option('_disqus_sync_lock');
584
- }
585
-
586
- // lock expires after 1 hour
587
- if ($sync_time && $sync_time > time() - 60*60) {
588
- $dsq_api->api->last_error = 'Sync already in progress (lock found)';
589
- return false;
590
- } else {
591
- update_option('_disqus_sync_lock', time());
592
- }
593
-
594
- // sync all pending posts
595
- $post_ids = dsq_get_pending_post_ids();
596
- dsq_clear_pending_post_ids($post_ids);
597
-
598
- foreach ($post_ids as $post_id) {
599
- dsq_sync_post($post_id);
600
- }
601
-
602
- if ($last_comment_id === false) {
603
- $last_comment_id = get_option('disqus_last_comment_id');
604
- if (!$last_comment_id) {
605
- $last_comment_id = 0;
606
- }
607
- }
608
- if ($last_comment_id) {
609
- $last_comment_id++;
610
- }
611
-
612
- //$last_comment_id = 0;
613
-
614
- // Pull comments from API
615
- $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
616
- if( $dsq_response < 0 || $dsq_response === false ) {
617
- return false;
618
- }
619
-
620
- // Sync comments with database.
621
- dsq_sync_comments($dsq_response);
622
- $total = 0;
623
- if ($dsq_response) {
624
- foreach ($dsq_response as $comment) {
625
- $total += 1;
626
- if ($comment->id > $last_comment_id) $last_comment_id = $comment->id;
627
- }
628
- if ($last_comment_id > get_option('disqus_last_comment_id')) {
629
- update_option('disqus_last_comment_id', $last_comment_id);
630
- }
631
- }
632
- unset($comment);
633
- delete_option('_disqus_sync_lock');
634
- return array($total, $last_comment_id);
635
- }
636
-
637
- add_action('dsq_sync_forum', 'dsq_sync_forum');
638
-
639
- function dsq_update_permalink($post) {
640
- global $dsq_api;
641
-
642
- if (DISQUS_DEBUG) {
643
- echo "updating post on disqus: {$post->ID}\n";
644
- }
645
-
646
- $response = $dsq_api->api->update_thread(null, array(
647
- 'thread_identifier' => dsq_identifier_for_post($post),
648
- 'title' => dsq_title_for_post($post),
649
- 'url' => dsq_link_for_post($post)
650
- ));
651
-
652
- update_post_meta($post->ID, 'dsq_thread_id', $response->id);
653
-
654
- return $response;
655
- }
656
-
657
- /**
658
- * Compatibility
659
- */
660
-
661
- if (!function_exists ( '_wp_specialchars' ) ) {
662
- function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
663
- $string = (string) $string;
664
-
665
- if ( 0 === strlen( $string ) ) {
666
- return '';
667
- }
668
-
669
- // Don't bother if there are no specialchars - saves some processing
670
- if ( !preg_match( '/[&<>"\']/', $string ) ) {
671
- return $string;
672
- }
673
-
674
- // Account for the previous behaviour of the function when the $quote_style is not an accepted value
675
- if ( empty( $quote_style ) ) {
676
- $quote_style = ENT_NOQUOTES;
677
- } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
678
- $quote_style = ENT_QUOTES;
679
- }
680
-
681
- // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
682
- if ( !$charset ) {
683
- static $_charset;
684
- if ( !isset( $_charset ) ) {
685
- $alloptions = wp_load_alloptions();
686
- $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
687
- }
688
- $charset = $_charset;
689
- }
690
- if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
691
- $charset = 'UTF-8';
692
- }
693
-
694
- $_quote_style = $quote_style;
695
-
696
- if ( $quote_style === 'double' ) {
697
- $quote_style = ENT_COMPAT;
698
- $_quote_style = ENT_COMPAT;
699
- } elseif ( $quote_style === 'single' ) {
700
- $quote_style = ENT_NOQUOTES;
701
- }
702
-
703
- // Handle double encoding ourselves
704
- if ( !$double_encode ) {
705
- $string = wp_specialchars_decode( $string, $_quote_style );
706
- $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
707
- }
708
-
709
- $string = @htmlspecialchars( $string, $quote_style, $charset );
710
-
711
- // Handle double encoding ourselves
712
- if ( !$double_encode ) {
713
- $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string );
714
- }
715
-
716
- // Backwards compatibility
717
- if ( 'single' === $_quote_style ) {
718
- $string = str_replace( "'", '&#039;', $string );
719
- }
720
-
721
- return $string;
722
- }
723
- }
724
-
725
- if (!function_exists ( 'wp_check_invalid_utf8' ) ) {
726
- function wp_check_invalid_utf8( $string, $strip = false ) {
727
- $string = (string) $string;
728
-
729
- if ( 0 === strlen( $string ) ) {
730
- return '';
731
- }
732
-
733
- // Store the site charset as a static to avoid multiple calls to get_option()
734
- static $is_utf8;
735
- if ( !isset( $is_utf8 ) ) {
736
- $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
737
- }
738
- if ( !$is_utf8 ) {
739
- return $string;
740
- }
741
-
742
- // Check for support for utf8 in the installed PCRE library once and store the result in a static
743
- static $utf8_pcre;
744
- if ( !isset( $utf8_pcre ) ) {
745
- $utf8_pcre = @preg_match( '/^./u', 'a' );
746
- }
747
- // We can't demand utf8 in the PCRE installation, so just return the string in those cases
748
- if ( !$utf8_pcre ) {
749
- return $string;
750
- }
751
-
752
- // preg_match fails when it encounters invalid UTF8 in $string
753
- if ( 1 === @preg_match( '/^./us', $string ) ) {
754
- return $string;
755
- }
756
-
757
- // Attempt to strip the bad chars if requested (not recommended)
758
- if ( $strip && function_exists( 'iconv' ) ) {
759
- return iconv( 'utf-8', 'utf-8', $string );
760
- }
761
-
762
- return '';
763
- }
764
- }
765
-
766
- if (!function_exists ( 'esc_html' ) ) {
767
- function esc_html( $text ) {
768
- $safe_text = wp_check_invalid_utf8( $text );
769
- $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
770
- return apply_filters( 'esc_html', $safe_text, $text );
771
- }
772
- }
773
-
774
- if (!function_exists ( 'esc_attr' ) ) {
775
- function esc_attr( $text ) {
776
- $safe_text = wp_check_invalid_utf8( $text );
777
- $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
778
- return apply_filters( 'attribute_escape', $safe_text, $text );
779
- }
780
- }
781
-
782
- /**
783
- * Filters/Actions
784
- */
785
-
786
- // ugly global hack for comments closing
787
- $EMBED = false;
788
- function dsq_comments_template($value) {
789
- global $EMBED;
790
- global $post;
791
- global $comments;
792
-
793
- if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
794
- return;
795
- }
796
-
797
- if ( !dsq_is_installed() || !dsq_can_replace() ) {
798
- return $value;
799
- }
800
-
801
- // TODO: If a disqus-comments.php is found in the current template's
802
- // path, use that instead of the default bundled comments.php
803
- //return TEMPLATEPATH . '/disqus-comments.php';
804
- $EMBED = true;
805
- return dirname(__FILE__) . '/comments.php';
806
- }
807
-
808
- function dsq_comment( $comment, $args, $depth ) {
809
- $GLOBALS['comment'] = $comment;
810
- switch ($comment->comment_type):
811
- case '' :
812
- ?>
813
- <li <?php comment_class(); ?> id="dsq-comment-<?php echo comment_ID(); ?>">
814
- <div id="dsq-comment-header-<?php echo comment_ID(); ?>" class="dsq-comment-header">
815
- <cite id="dsq-cite-<?php echo comment_ID(); ?>">
816
- <?php if(comment_author_url()) : ?>
817
- <a id="dsq-author-user-<?php echo comment_ID(); ?>" href="<?php echo comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo comment_author(); ?></a>
818
- <?php else : ?>
819
- <span id="dsq-author-user-<?php echo comment_ID(); ?>"><?php echo comment_author(); ?></span>
820
- <?php endif; ?>
821
- </cite>
822
- </div>
823
- <div id="dsq-comment-body-<?php echo comment_ID(); ?>" class="dsq-comment-body">
824
- <div id="dsq-comment-message-<?php echo comment_ID(); ?>" class="dsq-comment-message"><?php echo wp_filter_kses(comment_text()); ?></div>
825
- </div>
826
-
827
- <?php
828
- break;
829
- case 'pingback' :
830
- case 'trackback' :
831
- ?>
832
- <li class="post pingback">
833
- <p><?php echo dsq_i('Pingback:'); ?> <?php comment_author_link(); ?><?php edit_comment_link(dsq_i('(Edit)'), ' '); ?></p>
834
- </li>
835
- <?php
836
- break;
837
- endswitch;
838
- }
839
-
840
- // Mark entries in index to replace comments link.
841
- // As of WordPress 3.1 this is required to return a numerical value
842
- function dsq_comments_number($count) {
843
- global $post;
844
-
845
- return $count;
846
- }
847
-
848
- function dsq_comments_text($comment_text) {
849
- global $post;
850
-
851
- if ( dsq_can_replace() ) {
852
- return '<span class="dsq-postid" rel="'.htmlspecialchars(dsq_identifier_for_post($post)).'">'.$comment_text.'</span>';
853
- } else {
854
- return $comment_text;
855
- }
856
- }
857
-
858
- function dsq_bloginfo_url($url) {
859
- if ( get_feed_link('comments_rss2') == $url && dsq_can_replace() ) {
860
- return 'https://' . strtolower(get_option('disqus_forum_url')) . '.' . DISQUS_DOMAIN . DISQUS_RSS_PATH;
861
- } else {
862
- return $url;
863
- }
864
- }
865
-
866
- function dsq_plugin_action_links($links, $file) {
867
- $plugin_file = basename(__FILE__);
868
- if (basename($file) == $plugin_file) {
869
- if (!dsq_is_installed()) {
870
- $settings_link = '<a href="edit-comments.php?page=disqus">'.dsq_i('Configure').'</a>';
871
- } else {
872
- $settings_link = '<a href="edit-comments.php?page=disqus#adv">'.dsq_i('Settings').'</a>';
873
- }
874
- array_unshift($links, $settings_link);
875
- }
876
- return $links;
877
- }
878
- add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
879
-
880
- /**
881
- * Hide the default comment form to stop spammers by marking all comments
882
- * as closed.
883
- */
884
- function dsq_comments_open($open, $post_id=null) {
885
- global $EMBED;
886
- if ($EMBED) return false;
887
- return $open;
888
- }
889
- add_filter('comments_open', 'dsq_comments_open');
890
-
891
- // Always add Disqus management page to the admin menu
892
- function dsq_add_pages() {
893
- add_submenu_page(
894
- 'edit-comments.php',
895
- 'Disqus',
896
- 'Disqus',
897
- 'moderate_comments',
898
- 'disqus',
899
- 'dsq_manage'
900
- );
901
- }
902
- add_action('admin_menu', 'dsq_add_pages', 10);
903
-
904
- // a little jQuery goodness to get comments menu working as desired
905
- function dsq_menu_admin_head() {
906
- ?>
907
- <script type="text/javascript">
908
- jQuery(function($) {
909
- // fix menu
910
- var mc = $('#menu-comments');
911
- mc.find('a.wp-has-submenu').attr('href', 'edit-comments.php?page=disqus').end().find('.wp-submenu li:has(a[href="edit-comments.php?page=disqus"])').prependTo(mc.find('.wp-submenu ul'));
912
- // fix admin bar
913
- $('#wp-admin-bar-comments').find('a.ab-item').attr('href', 'edit-comments.php?page=disqus');
914
- });
915
- </script>
916
- <?php
917
- }
918
- add_action('admin_head', 'dsq_menu_admin_head');
919
-
920
- // only active on dashboard
921
- function dsq_dash_comment_counts() {
922
- global $wpdb;
923
- // taken from wp-includes/comment.php - WP 2.8.5
924
- $count = $wpdb->get_results("
925
- SELECT comment_approved, COUNT( * ) AS num_comments
926
- FROM {$wpdb->comments}
927
- WHERE comment_type != 'trackback'
928
- AND comment_type != 'pingback'
929
- GROUP BY comment_approved
930
- ", ARRAY_A );
931
- $total = 0;
932
- $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
933
- $known_types = array_keys( $approved );
934
- foreach( (array) $count as $row_num => $row ) {
935
- $total += $row['num_comments'];
936
- if ( in_array( $row['comment_approved'], $known_types ) && array_key_exists($row['comment_approved'], $approved) )
937
- $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
938
- }
939
-
940
- $stats['total_comments'] = $total;
941
- foreach ( $approved as $key ) {
942
- if ( empty($stats[$key]) )
943
- $stats[$key] = 0;
944
- }
945
- $stats = (object) $stats;
946
- ?>
947
- <script type="text/javascript">
948
- jQuery(function($) {
949
- $('#dashboard_right_now').find('.b-comments a').html('<?php echo number_format($stats->total_comments); ?>').end().find('.b_approved a').html('<?php echo number_format($stats->approved); ?>').end().find('.b-waiting a').html('<?php echo number_format($stats->moderated); ?>').end().find('.b-spam a').html('<?php echo number_format($stats->spam); ?>');
950
- $('#dashboard_recent_comments div.trackback').remove();
951
- $('#dashboard_right_now .inside table td.last a, #dashboard_recent_comments .inside .textright a.button').attr('href', 'edit-comments.php?page=disqus');
952
- });
953
- </script>
954
- <?php
955
- }
956
- function dsq_wp_dashboard_setup() {
957
- add_action('admin_head', 'dsq_dash_comment_counts');
958
- }
959
- add_action('wp_dashboard_setup', 'dsq_wp_dashboard_setup');
960
-
961
- function dsq_manage() {
962
- if (dsq_does_need_update() && isset($_POST['upgrade'])) {
963
- dsq_install();
964
- }
965
-
966
- if (dsq_does_need_update() && !isset($_POST['reset'])) {
967
- include_once(dirname(__FILE__) . '/upgrade.php');
968
- } else {
969
- include_once(dirname(__FILE__) . '/manage.php');
970
- }
971
- }
972
-
973
- function dsq_admin_head() {
974
- if (isset($_GET['page']) && $_GET['page'] == 'disqus') {
975
- ?>
976
- <link rel='stylesheet' href='<?php echo plugins_url( 'media/styles/manage.css', __FILE__ ); ?>' type='text/css' />
977
- <style type="text/css">
978
- .dsq-importing, .dsq-imported, .dsq-import-fail, .dsq-exporting, .dsq-exported, .dsq-export-fail {
979
- background: url(<?php echo admin_url('images/loading.gif'); ?>) left center no-repeat;
980
- line-height: 16px;
981
- padding-left: 20px;
982
- }
983
- p.status {
984
- padding-top: 0;
985
- padding-bottom: 0;
986
- margin: 0;
987
- }
988
- .dsq-imported, .dsq-exported {
989
- background: url(<?php echo admin_url('images/yes.png'); ?>) left center no-repeat;
990
- }
991
- .dsq-import-fail, .dsq-export-fail {
992
- background: url(<?php echo admin_url('images/no.png'); ?>) left center no-repeat;
993
- }
994
- </style>
995
- <script type="text/javascript">
996
- jQuery(function($) {
997
- $('#dsq-tabs li').click(function() {
998
- $('#dsq-tabs li.selected').removeClass('selected');
999
- $(this).addClass('selected');
1000
- $('.dsq-main, .dsq-advanced').hide();
1001
- $('.' + $(this).attr('rel')).show();
1002
- });
1003
- if (location.href.indexOf('#adv') != -1) {
1004
- $('#dsq-tab-advanced').click();
1005
- }
1006
- dsq_fire_export();
1007
- dsq_fire_import();
1008
- });
1009
- dsq_fire_export = function() {
1010
- var $ = jQuery;
1011
- $('#dsq_export a.button, #dsq_export_retry').unbind().click(function() {
1012
- $('#dsq_export').html('<p class="status"></p>');
1013
- $('#dsq_export .status').removeClass('dsq-export-fail').addClass('dsq-exporting').html('Processing...');
1014
- dsq_export_comments();
1015
- return false;
1016
- });
1017
- }
1018
- dsq_export_comments = function() {
1019
- var $ = jQuery;
1020
- var status = $('#dsq_export .status');
1021
- var export_info = (status.attr('rel') || '0|' + (new Date().getTime()/1000)).split('|');
1022
- $.get(
1023
- '<?php echo admin_url('index.php'); ?>',
1024
- {
1025
- cf_action: 'export_comments',
1026
- post_id: export_info[0],
1027
- timestamp: export_info[1]
1028
- },
1029
- function(response) {
1030
- switch (response.result) {
1031
- case 'success':
1032
- status.html(response.msg).attr('rel', response.post_id + '|' + response.timestamp);
1033
- switch (response.status) {
1034
- case 'partial':
1035
- dsq_export_comments();
1036
- break;
1037
- case 'complete':
1038
- status.removeClass('dsq-exporting').addClass('dsq-exported');
1039
- break;
1040
- }
1041
- break;
1042
- case 'fail':
1043
- status.parent().html(response.msg);
1044
- dsq_fire_export();
1045
- break;
1046
- }
1047
- },
1048
- 'json'
1049
- );
1050
- }
1051
- dsq_fire_import = function() {
1052
- var $ = jQuery;
1053
- $('#dsq_import a.button, #dsq_import_retry').unbind().click(function() {
1054
- var wipe = $('#dsq_import_wipe').is(':checked');
1055
- $('#dsq_import').html('<p class="status"></p>');
1056
- $('#dsq_import .status').removeClass('dsq-import-fail').addClass('dsq-importing').html('Processing...');
1057
- dsq_import_comments(wipe);
1058
- return false;
1059
- });
1060
- }
1061
- dsq_import_comments = function(wipe) {
1062
- var $ = jQuery;
1063
- var status = $('#dsq_import .status');
1064
- var last_comment_id = status.attr('rel') || '0';
1065
- $.get(
1066
- '<?php echo admin_url('index.php'); ?>',
1067
- {
1068
- cf_action: 'import_comments',
1069
- last_comment_id: last_comment_id,
1070
- wipe: (wipe ? 1 : 0)
1071
- },
1072
- function(response) {
1073
- switch (response.result) {
1074
- case 'success':
1075
- status.html(response.msg).attr('rel', response.last_comment_id);
1076
- switch (response.status) {
1077
- case 'partial':
1078
- dsq_import_comments(false);
1079
- break;
1080
- case 'complete':
1081
- status.removeClass('dsq-importing').addClass('dsq-imported');
1082
- break;
1083
- }
1084
- break;
1085
- case 'fail':
1086
- status.parent().html(response.msg);
1087
- dsq_fire_import();
1088
- break;
1089
- }
1090
- },
1091
- 'json'
1092
- );
1093
- }
1094
- </script>
1095
- <?php
1096
- // HACK: Our own styles for older versions of WordPress.
1097
- global $wp_version;
1098
- if ( version_compare($wp_version, '2.5', '<') ) {
1099
- echo "<link rel='stylesheet' href='" . plugins_url( 'media/styles/manage-pre25.css', __FILE__ ) . "' type='text/css' />";
1100
- }
1101
- }
1102
- }
1103
- add_action('admin_head', 'dsq_admin_head');
1104
-
1105
- /**
1106
- * Wrapper for built-in __() which pulls all text from
1107
- * the disqus domain and supports variable interpolation.
1108
- */
1109
- function dsq_i($text, $params=null) {
1110
- if (!is_array($params))
1111
- {
1112
- $params = func_get_args();
1113
- $params = array_slice($params, 1);
1114
- }
1115
- return vsprintf(__($text, 'disqus'), $params);
1116
- }
1117
-
1118
- // catch original query
1119
- function dsq_parse_query($query) {
1120
- add_action('the_posts', 'dsq_add_request_post_ids', 999);
1121
- }
1122
- add_action('parse_request', 'dsq_parse_query');
1123
-
1124
- // track the original request post_ids, only run once
1125
- function dsq_add_request_post_ids($posts) {
1126
- dsq_add_query_posts($posts);
1127
- remove_action('the_posts', 'dsq_log_request_post_ids', 999);
1128
- return $posts;
1129
- }
1130
-
1131
- function dsq_maybe_add_post_ids($posts) {
1132
- global $DSQ_QUERY_COMMENTS;
1133
- if ($DSQ_QUERY_COMMENTS) {
1134
- dsq_add_query_posts($posts);
1135
- }
1136
- return $posts;
1137
- }
1138
- add_action('the_posts', 'dsq_maybe_add_post_ids');
1139
-
1140
- function dsq_add_query_posts($posts) {
1141
- global $DSQ_QUERY_POST_IDS;
1142
- if (count($posts)) {
1143
- foreach ($posts as $post) {
1144
- $post_ids[] = intval($post->ID);
1145
- }
1146
- $DSQ_QUERY_POST_IDS[md5(serialize($post_ids))] = $post_ids;
1147
- }
1148
- }
1149
-
1150
- // check to see if the posts in the loop match the original request or an explicit request, if so output the JS
1151
- function dsq_loop_end($query) {
1152
- if ( get_option('disqus_cc_fix') == '1' || !count($query->posts) || is_single() || is_page() || is_feed() || !dsq_can_replace() ) {
1153
- return;
1154
- }
1155
- global $DSQ_QUERY_POST_IDS;
1156
- foreach ($query->posts as $post) {
1157
- $loop_ids[] = intval($post->ID);
1158
- }
1159
- $posts_key = md5(serialize($loop_ids));
1160
- if (isset($DSQ_QUERY_POST_IDS[$posts_key])) {
1161
- dsq_output_loop_comment_js($DSQ_QUERY_POST_IDS[$posts_key]);
1162
- }
1163
- }
1164
- add_action('loop_end', 'dsq_loop_end');
1165
-
1166
- // if someone has a better hack, let me know
1167
- // prevents duplicate calls to count.js
1168
- $_HAS_COUNTS = false;
1169
-
1170
- function dsq_output_loop_comment_js($post_ids = null) {
1171
- global $_HAS_COUNTS;
1172
- if ($_HAS_COUNTS) return;
1173
- $_HAS_COUNTS = true;
1174
- if (count($post_ids)) {
1175
- ?>
1176
- <script type="text/javascript">
1177
- // <![CDATA[
1178
- var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
1179
- (function () {
1180
- var nodes = document.getElementsByTagName('span');
1181
- for (var i = 0, url; i < nodes.length; i++) {
1182
- if (nodes[i].className.indexOf('dsq-postid') != -1) {
1183
- nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
1184
- url = nodes[i].parentNode.href.split('#', 1);
1185
- if (url.length == 1) { url = url[0]; }
1186
- else { url = url[1]; }
1187
- nodes[i].parentNode.href = url + '#disqus_thread';
1188
- }
1189
- }
1190
- var s = document.createElement('script'); s.async = true;
1191
- s.type = 'text/javascript';
1192
- s.src = '//' + disqus_shortname + '.<?php echo DISQUS_DOMAIN; ?>/count.js';
1193
- (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
1194
- }());
1195
- //]]>
1196
- </script>
1197
- <?php
1198
- }
1199
- }
1200
-
1201
- function dsq_output_footer_comment_js() {
1202
- if (!dsq_can_replace()) return;
1203
- if (get_option('disqus_cc_fix') != '1') return;
1204
- ?>
1205
- <script type="text/javascript">
1206
- // <![CDATA[
1207
- var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
1208
- (function () {
1209
- var nodes = document.getElementsByTagName('span');
1210
- for (var i = 0, url; i < nodes.length; i++) {
1211
- if (nodes[i].className.indexOf('dsq-postid') != -1) {
1212
- nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
1213
- url = nodes[i].parentNode.href.split('#', 1);
1214
- if (url.length == 1) url = url[0];
1215
- else url = url[1]
1216
- nodes[i].parentNode.href = url + '#disqus_thread';
1217
- }
1218
- }
1219
- var s = document.createElement('script'); s.async = true;
1220
- s.type = 'text/javascript';
1221
- s.src = '//' + disqus_shortname + '.<?php echo DISQUS_DOMAIN; ?>/count.js';
1222
- (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
1223
- }());
1224
- //]]>
1225
- </script>
1226
- <?php
1227
- }
1228
- add_action('wp_footer', 'dsq_output_footer_comment_js');
1229
-
1230
- // UPDATE DSQ when a permalink changes
1231
-
1232
- $dsq_prev_permalinks = array();
1233
-
1234
- function dsq_prev_permalink($post_id) {
1235
- $post = get_post($post_id);
1236
- // if post not published, return
1237
- if ($post->post_status != 'publish') {
1238
- return;
1239
- }
1240
- global $dsq_prev_permalinks;
1241
- $dsq_prev_permalinks['post_'.$post_id] = get_permalink($post_id);
1242
- }
1243
- add_action('pre_post_update', 'dsq_prev_permalink');
1244
-
1245
- function dsq_check_permalink($post_id) {
1246
- global $dsq_prev_permalinks;
1247
- if (!empty($dsq_prev_permalinks['post_'.$post_id]) && $dsq_prev_permalinks['post_'.$post_id] != get_permalink($post_id)) {
1248
- $post = get_post($post_id);
1249
- dsq_update_permalink($post);
1250
- }
1251
- }
1252
- add_action('edit_post', 'dsq_check_permalink');
1253
-
1254
- // Only replace comments if the disqus_forum_url option is set.
1255
- add_filter('comments_template', 'dsq_comments_template');
1256
- add_filter('comments_number', 'dsq_comments_text');
1257
- add_filter('get_comments_number', 'dsq_comments_number');
1258
- add_filter('bloginfo_url', 'dsq_bloginfo_url');
1259
-
1260
- /**
1261
- * JSON ENCODE for PHP < 5.2.0
1262
- * Checks if json_encode is not available and defines json_encode
1263
- * to use php_json_encode in its stead
1264
- * Works on iteratable objects as well - stdClass is iteratable, so all WP objects are gonna be iteratable
1265
- */
1266
- if(!function_exists('cf_json_encode')) {
1267
- function cf_json_encode($data) {
1268
- // json_encode is sending an application/x-javascript header on Joyent servers
1269
- // for some unknown reason.
1270
- // if(function_exists('json_encode')) { return json_encode($data); }
1271
- // else { return cfjson_encode($data); }
1272
- return cfjson_encode($data);
1273
- }
1274
-
1275
- function cfjson_encode_string($str) {
1276
- if(is_bool($str)) {
1277
- return $str ? 'true' : 'false';
1278
- }
1279
-
1280
- return str_replace(
1281
- array(
1282
- '"'
1283
- , '/'
1284
- , "\n"
1285
- , "\r"
1286
- )
1287
- , array(
1288
- '\"'
1289
- , '\/'
1290
- , '\n'
1291
- , '\r'
1292
- )
1293
- , $str
1294
- );
1295
- }
1296
-
1297
- function cfjson_encode($arr) {
1298
- $json_str = '';
1299
- if (is_array($arr)) {
1300
- $pure_array = true;
1301
- $array_length = count($arr);
1302
- for ( $i = 0; $i < $array_length ; $i++) {
1303
- if (!isset($arr[$i])) {
1304
- $pure_array = false;
1305
- break;
1306
- }
1307
- }
1308
- if ($pure_array) {
1309
- $json_str = '[';
1310
- $temp = array();
1311
- for ($i=0; $i < $array_length; $i++) {
1312
- $temp[] = sprintf("%s", cfjson_encode($arr[$i]));
1313
- }
1314
- $json_str .= implode(',', $temp);
1315
- $json_str .="]";
1316
- }
1317
- else {
1318
- $json_str = '{';
1319
- $temp = array();
1320
- foreach ($arr as $key => $value) {
1321
- $temp[] = sprintf("\"%s\":%s", $key, cfjson_encode($value));
1322
- }
1323
- $json_str .= implode(',', $temp);
1324
- $json_str .= '}';
1325
- }
1326
- }
1327
- else if (is_object($arr)) {
1328
- $json_str = '{';
1329
- $temp = array();
1330
- foreach ($arr as $k => $v) {
1331
- $temp[] = '"'.$k.'":'.cfjson_encode($v);
1332
- }
1333
- $json_str .= implode(',', $temp);
1334
- $json_str .= '}';
1335
- }
1336
- else if (is_string($arr)) {
1337
- $json_str = '"'. cfjson_encode_string($arr) . '"';
1338
- }
1339
- else if (is_numeric($arr)) {
1340
- $json_str = $arr;
1341
- }
1342
- else if (is_bool($arr)) {
1343
- $json_str = $arr ? 'true' : 'false';
1344
- }
1345
- else {
1346
- $json_str = '"'. cfjson_encode_string($arr) . '"';
1347
- }
1348
- return $json_str;
1349
- }
1350
- }
1351
-
1352
- // Single Sign-on Integration
1353
-
1354
- function dsq_sso() {
1355
- if ($key = get_option('disqus_partner_key')) {
1356
- // use old style SSO
1357
- $new = false;
1358
- } elseif (($key = get_option('disqus_secret_key')) && ($public = get_option('disqus_public_key'))) {
1359
- // use new style SSO
1360
- $new = true;
1361
- } else {
1362
- // sso is not configured
1363
- return array();
1364
- }
1365
- global $current_user, $dsq_api;
1366
- get_currentuserinfo();
1367
- if ($current_user->ID) {
1368
- $avatar_tag = get_avatar($current_user->ID);
1369
- $avatar_data = array();
1370
- preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
1371
- $avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
1372
- $user_data = array(
1373
- 'username' => $current_user->display_name,
1374
- 'id' => $current_user->ID,
1375
- 'avatar' => $avatar,
1376
- 'email' => $current_user->user_email,
1377
- 'url' => $current_user->user_url,
1378
- );
1379
- }
1380
- else {
1381
- $user_data = array();
1382
- }
1383
- $user_data = base64_encode(cf_json_encode($user_data));
1384
- $time = time();
1385
- $hmac = dsq_hmacsha1($user_data.' '.$time, $key);
1386
-
1387
- $payload = $user_data.' '.$hmac.' '.$time;
1388
-
1389
- if ($new) {
1390
- return array('remote_auth_s3'=>$payload, 'api_key'=>$public);
1391
- } else {
1392
- return array('remote_auth_s2'=>$payload);
1393
- }
1394
- }
1395
-
1396
- function dsq_sso_login() {
1397
- global $current_site;
1398
- $sitename = get_bloginfo('name');
1399
- $siteurl = site_url();
1400
- $button = get_option('disqus_sso_button');
1401
- $icon = get_option('disqus_sso_icon');
1402
- $sso_login_str = 'this.sso = {
1403
- name: "'.wp_specialchars_decode($sitename, ENT_QUOTES).'",
1404
- button: "'.$button.'",
1405
- icon: "'.$icon.'",
1406
- url: "'.$siteurl.'/wp-login.php",
1407
- logout: "'.$siteurl.'/wp-login.php?action=logout",
1408
- width: "800",
1409
- height: "700"
1410
- }';
1411
- return $sso_login_str;
1412
- }
1413
-
1414
- // from: http://www.php.net/manual/en/function.sha1.php#39492
1415
- // Calculate HMAC-SHA1 according to RFC2104
1416
- // http://www.ietf.org/rfc/rfc2104.txt
1417
- function dsq_hmacsha1($data, $key) {
1418
- $blocksize=64;
1419
- $hashfunc='sha1';
1420
- if (strlen($key)>$blocksize)
1421
- $key=pack('H*', $hashfunc($key));
1422
- $key=str_pad($key,$blocksize,chr(0x00));
1423
- $ipad=str_repeat(chr(0x36),$blocksize);
1424
- $opad=str_repeat(chr(0x5c),$blocksize);
1425
- $hmac = pack(
1426
- 'H*',$hashfunc(
1427
- ($key^$opad).pack(
1428
- 'H*',$hashfunc(
1429
- ($key^$ipad).$data
1430
- )
1431
- )
1432
- )
1433
- );
1434
- return bin2hex($hmac);
1435
- }
1436
-
1437
- function dsq_identifier_for_post($post) {
1438
- return $post->ID . ' ' . $post->guid;
1439
- }
1440
-
1441
- function dsq_title_for_post($post) {
1442
- $title = get_the_title($post);
1443
- $title = strip_tags($title, DISQUS_ALLOWED_HTML);
1444
- return $title;
1445
- }
1446
-
1447
- function dsq_link_for_post($post) {
1448
- return get_permalink($post);
1449
- }
1450
-
1451
- function dsq_does_need_update() {
1452
- $version = (string)get_option('disqus_version');
1453
- if (empty($version)) {
1454
- $version = '0';
1455
- }
1456
-
1457
- if (version_compare($version, '2.49', '<')) {
1458
- return true;
1459
- }
1460
-
1461
- return false;
1462
- }
1463
-
1464
- function dsq_install($allow_database_install=true) {
1465
- global $wpdb, $userdata;
1466
-
1467
- $version = (string)get_option('disqus_version');
1468
- if (!$version) {
1469
- $version = '0';
1470
- }
1471
-
1472
- if ($allow_database_install)
1473
- {
1474
- dsq_install_database($version);
1475
- }
1476
-
1477
- if (version_compare($version, DISQUS_VERSION, '=')) return;
1478
-
1479
- // if this is a new install, we should not set disqus active
1480
- if ($version == '0') {
1481
- add_option('disqus_active', '0');
1482
- } else {
1483
- add_option('disqus_active', '1');
1484
- }
1485
-
1486
- update_option('disqus_version', DISQUS_VERSION);
1487
- }
1488
-
1489
- /**
1490
- * Adds a simple WordPress pointer to Comments menu, to remind the user to configure the plugin
1491
- */
1492
- function dsq_enqueue_pointer_script_style( $hook_suffix ) {
1493
-
1494
- // Assume pointer shouldn't be shown
1495
- $enqueue_pointer_script_style = false;
1496
-
1497
- // Get array list of dismissed pointers for current user and convert it to array
1498
- $dismissed_pointers = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
1499
-
1500
- // Check if our pointer is not among dismissed ones
1501
- if( !in_array( 'disqus_settings_pointer', $dismissed_pointers ) ) {
1502
- $enqueue_pointer_script_style = true;
1503
-
1504
- // Add footer scripts using callback function
1505
- add_action( 'admin_print_footer_scripts', 'dsq_pointer_print_scripts' );
1506
- }
1507
-
1508
- // Enqueue pointer CSS and JS files, if needed
1509
- if( $enqueue_pointer_script_style ) {
1510
- wp_enqueue_style( 'wp-pointer' );
1511
- wp_enqueue_script( 'wp-pointer' );
1512
- }
1513
-
1514
- }
1515
- if (!dsq_is_installed()) {
1516
- // Only show the pointer when Disqus isn't already configured
1517
- add_action( 'admin_enqueue_scripts', 'dsq_enqueue_pointer_script_style' );
1518
- }
1519
-
1520
- function dsq_pointer_print_scripts() {
1521
-
1522
- $pointer_content = '<h3>DISQUS needs to be configured</h3>';
1523
- $pointer_content .= '<p>Configure DISQUS by clicking Comments to the left.</p>';
1524
- ?>
1525
-
1526
- <script type="text/javascript">
1527
- //<![CDATA[
1528
- jQuery(document).ready( function($) {
1529
- $('#menu-comments').pointer({
1530
- content: '<?php echo $pointer_content; ?>',
1531
- position: {
1532
- edge: 'left', // arrow direction
1533
- align: 'center' // vertical alignment
1534
- },
1535
- pointerWidth: 350,
1536
- close: function() {
1537
- $.post( ajaxurl, {
1538
- pointer: 'disqus_settings_pointer', // pointer ID
1539
- action: 'dismiss-wp-pointer'
1540
- });
1541
- }
1542
- }).pointer('open');
1543
- });
1544
- //]]>
1545
- </script>
1546
-
1547
- <?php
1548
- }
1549
-
1550
- /**
1551
- * Initializes the database if it's not already present.
1552
- */
1553
- function dsq_install_database($version=0) {
1554
- global $wpdb;
1555
-
1556
- if (version_compare($version, '2.49', '<')) {
1557
- $wpdb->query("CREATE INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta` (meta_key, meta_value(11));");
1558
- }
1559
- }
1560
- function dsq_reset_database($version=0) {
1561
- global $wpdb;
1562
-
1563
- if (version_compare($version, '2.49', '>=')) {
1564
- $wpdb->query("DROP INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta`;");
1565
- }
1566
- }
1567
-
1568
- /**
1569
- * Disable internal Wordpress commenting if Disqus is enabled - this prevents spam bots from
1570
- * commenting using POST requests to /wp-comments-post.php.
1571
- *
1572
- * @param int $comment_post_ID
1573
- * @return int
1574
- */
1575
- function dsq_pre_comment_on_post($comment_post_ID) {
1576
- if (dsq_can_replace()) {
1577
- wp_die( dsq_i('Sorry, the built-in commenting system is disabled because Disqus is active.') );
1578
- }
1579
- return $comment_post_ID;
1580
- }
1581
- add_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
1582
-
1583
- ?>
1
+ <?php
2
+ /*
3
+ Plugin Name: Disqus Comment System
4
+ Plugin URI: http://disqus.com/
5
+ Description: The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus. Head over to the Comments admin page to set up your Disqus Comment System.
6
+ Author: Disqus <team@disqus.com>
7
+ Version: 2.81
8
+ Author URI: http://disqus.com/
9
+ */
10
+
11
+ require_once(dirname(__FILE__) . '/lib/wp-api.php');
12
+
13
+ define('DISQUS_DOMAIN', 'disqus.com');
14
+ define('DISQUS_IMPORTER_URL', 'https://import.disqus.com/');
15
+ define('DISQUS_API_URL', 'http://disqus.com/api/');
16
+ define('DISQUS_RSS_PATH', '/latest.rss');
17
+ define('DISQUS_CAN_EXPORT', is_file(dirname(__FILE__) . '/export.php'));
18
+ if (!defined('DISQUS_DEBUG')) {
19
+ define('DISQUS_DEBUG', false);
20
+ }
21
+ define('DISQUS_VERSION', '2.81');
22
+ define('DISQUS_SYNC_TIMEOUT', 30);
23
+
24
+ /**
25
+ * Returns an array of all option identifiers used by Disqus.
26
+ * @return array[int]string
27
+ */
28
+ function dsq_options() {
29
+ return array(
30
+ '_disqus_sync_lock',
31
+ '_disqus_sync_post_ids',
32
+ # render disqus in the embed
33
+ 'disqus_active',
34
+ 'disqus_forum_url',
35
+ 'disqus_api_key',
36
+ 'disqus_user_api_key',
37
+ 'disqus_replace',
38
+ 'disqus_cc_fix',
39
+ # SSO features
40
+ 'disqus_partner_key',
41
+ 'disqus_public_key',
42
+ 'disqus_secret_key',
43
+ 'disqus_sso_button',
44
+ # disables automatic sync via cron
45
+ 'disqus_manual_sync',
46
+ # disables server side rendering
47
+ 'disqus_disable_ssr',
48
+ # the last sync comment id (from get_forum_posts)
49
+ 'disqus_last_comment_id',
50
+ 'disqus_version',
51
+ );
52
+ }
53
+
54
+ /**
55
+ * @param string $file
56
+ * @return string
57
+ */
58
+ function dsq_plugin_basename($file) {
59
+ $file = dirname($file);
60
+
61
+ // From WP2.5 wp-includes/plugin.php:plugin_basename()
62
+ $file = str_replace('\\','/',$file); // sanitize for Win32 installs
63
+ $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
64
+ $file = preg_replace('|^.*/' . PLUGINDIR . '/|','',$file); // get relative path from plugins dir
65
+
66
+ if ( strstr($file, '/') === false ) {
67
+ return $file;
68
+ }
69
+
70
+ $pieces = explode('/', $file);
71
+ return !empty($pieces[count($pieces)-1]) ? $pieces[count($pieces)-1] : $pieces[count($pieces)-2];
72
+ }
73
+
74
+ if ( !defined('PLUGINDIR') ) {
75
+ define('PLUGINDIR', 'wp-content/plugins'); // Relative to ABSPATH. For back compat.
76
+ }
77
+
78
+ $mt_disqus_version = '2.01';
79
+ /**
80
+ * Response from Disqus get_thread API call for comments template.
81
+ *
82
+ * @global string $dsq_response
83
+ * @since 1.0
84
+ */
85
+ $dsq_response = '';
86
+ /**
87
+ * Disqus API instance.
88
+ *
89
+ * @global string $dsq_api
90
+ * @since 1.0
91
+ */
92
+ $dsq_api = new DisqusWordPressAPI(get_option('disqus_forum_url'), get_option('disqus_api_key'));
93
+
94
+ /**
95
+ * Disqus currently unsupported dev toggle to output comments for this query.
96
+ *
97
+ * @global bool $DSQ_QUERY_COMMENTS
98
+ * @since ?
99
+ */
100
+ $DSQ_QUERY_COMMENTS = false;
101
+
102
+ /**
103
+ * Disqus array to store post_ids from WP_Query for comment JS output.
104
+ *
105
+ * @global array $DSQ_QUERY_POST_IDS
106
+ * @since 2.2
107
+ */
108
+ $DSQ_QUERY_POST_IDS = array();
109
+
110
+ /**
111
+ * Admin scripts
112
+ */
113
+
114
+ add_action('wp_dashboard_setup', 'dsq_wp_dashboard_setup');
115
+ add_action( 'admin_enqueue_scripts', 'load_admin_scripts' );
116
+
117
+ function load_admin_scripts($hook) {
118
+
119
+ // Only show the pointer when Disqus isn't already configured
120
+ if ( dsq_is_installed() === false ) {
121
+ add_action( 'admin_print_footer_scripts', 'load_pointer_script_style' );
122
+ }
123
+
124
+ // Only load these scripts on the Disqus admin page
125
+ if ( 'comments_page_disqus' != $hook ) {
126
+ return;
127
+ }
128
+
129
+ $admin_vars = array(
130
+ 'indexUrl' => admin_url('index.php'),
131
+ );
132
+
133
+ wp_register_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ) );
134
+ wp_localize_script( 'admin_script', 'adminVars', $admin_vars );
135
+ wp_enqueue_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ), array( 'jQuery') );
136
+
137
+ wp_register_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__) );
138
+ wp_enqueue_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__), array( 'jQuery') );
139
+ }
140
+
141
+ function dsq_wp_dashboard_setup() {
142
+ add_action('admin_enqueue_scripts', 'load_dashboard_scripts');
143
+ }
144
+
145
+ function load_dashboard_scripts() {
146
+ $stats = get_dash_comment_counts();
147
+ $dashboard_vars = array(
148
+ 'stats' => array(
149
+ 'totalComments' => number_format($stats->total_comments),
150
+ 'approved' => number_format($stats->approved),
151
+ 'moderated' => number_format($stats->moderated),
152
+ 'spam' => number_format($stats->spam),
153
+ ),
154
+ );
155
+
156
+ wp_register_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ) );
157
+ wp_localize_script( 'dashboard_script', 'dashboardVars', $dashboard_vars );
158
+ wp_enqueue_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ), array( 'jQuery') );
159
+ }
160
+
161
+ /**
162
+ * Adds a simple WordPress pointer to Comments menu, to remind the user to configure the plugin
163
+ */
164
+ function load_pointer_script_style() {
165
+
166
+ // Assume pointer shouldn't be shown
167
+ $enqueue_pointer_script_style = false;
168
+
169
+ // Get array list of dismissed pointers for current user and convert it to array
170
+ $dismissed_pointers = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
171
+
172
+ // Check if our pointer is not among dismissed ones
173
+ if( !in_array( 'disqus_settings_pointer', $dismissed_pointers ) ) {
174
+ $enqueue_pointer_script_style = true;
175
+
176
+ // Add footer scripts using callback function
177
+ $pointer_content = '<h3>'.dsq_i('Disqus needs to be configured').'</h3>';
178
+ $pointer_content .= '<p>'.dsq_i('Configure Disqus by clicking Comments to the left.').'</p>';
179
+
180
+ wp_register_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ) );
181
+ wp_localize_script( 'pointer_script', 'pointerContent', $pointer_content );
182
+ wp_enqueue_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ), array( 'jQuery') );
183
+ }
184
+
185
+ // Enqueue pointer CSS and JS files, if needed
186
+ if( $enqueue_pointer_script_style ) {
187
+ wp_enqueue_style( 'wp-pointer' );
188
+ wp_enqueue_script( 'wp-pointer' );
189
+ }
190
+ }
191
+
192
+ /**
193
+ * Helper functions.
194
+ */
195
+
196
+ /**
197
+ * Tests if site is running on Wordpress VIP
198
+ * @return bool
199
+ */
200
+ function is_wp_vip() {
201
+ return defined( 'WPCOM_IS_VIP_ENV' ) && WPCOM_IS_VIP_ENV;
202
+ }
203
+
204
+ /**
205
+ * Tests if required options are configured to display the Disqus embed.
206
+ * @return bool
207
+ */
208
+ function dsq_is_installed() {
209
+ $disqus_forum_url = get_option('disqus_forum_url');
210
+ $disqus_api_key = get_option('disqus_api_key');
211
+ if ( strlen( $disqus_forum_url ) > 0 && strlen( $disqus_api_key ) > 0 ) {
212
+ return true;
213
+ }
214
+ else {
215
+ return false;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * @return bool
221
+ */
222
+ function dsq_can_replace() {
223
+ global $id, $post;
224
+
225
+ if (get_option('disqus_active') === '0'){ return false; }
226
+
227
+ $replace = get_option('disqus_replace');
228
+
229
+ if ( is_feed() ) { return false; }
230
+ if ( !isset($post) ) { return false; }
231
+ if ( 'draft' == $post->post_status ) { return false; }
232
+ if ( !get_option('disqus_forum_url') ) { return false; }
233
+ else if ( 'all' == $replace ) { return true; }
234
+
235
+ if ( !isset($post->comment_count) ) {
236
+ $num_comments = 0;
237
+ } else {
238
+ if ( 'empty' == $replace ) {
239
+ // Only get count of comments, not including pings.
240
+
241
+ // If there are comments, make sure there are comments (that are not track/pingbacks)
242
+ if ( $post->comment_count > 0 ) {
243
+ // Yuck, this causes a DB query for each post. This can be
244
+ // replaced with a lighter query, but this is still not optimal.
245
+ $comments = get_approved_comments($post->ID);
246
+ foreach ( $comments as $comment ) {
247
+ if ( $comment->comment_type != 'trackback' && $comment->comment_type != 'pingback' ) {
248
+ $num_comments++;
249
+ }
250
+ }
251
+ } else {
252
+ $num_comments = 0;
253
+ }
254
+ }
255
+ else {
256
+ $num_comments = $post->comment_count;
257
+ }
258
+ }
259
+
260
+ return ( ('empty' == $replace && 0 == $num_comments)
261
+ || ('closed' == $replace && 'closed' == $post->comment_status) );
262
+ }
263
+
264
+ function dsq_manage_dialog($message, $error = false) {
265
+ global $wp_version;
266
+
267
+ echo '<div '
268
+ . ( $error ? 'id="disqus_warning" ' : '')
269
+ . 'class="updated fade'
270
+ . ( (version_compare($wp_version, '2.5', '<') && $error) ? '-ff0000' : '' )
271
+ . '"><p><strong>'
272
+ . esc_attr($message)
273
+ . '</strong></p></div>';
274
+ }
275
+
276
+ function dsq_sync_comments($comments) {
277
+ global $wpdb;
278
+
279
+ // user MUST be logged out during this process
280
+ wp_set_current_user(0);
281
+
282
+ // we need the thread_ids so we can map them to posts
283
+ $thread_map = array();
284
+ foreach ( $comments as $comment ) {
285
+ $thread_map[$comment->thread->id] = null;
286
+ }
287
+
288
+ $thread_ids = array_keys($thread_map);
289
+
290
+ // add as many placeholders as needed
291
+ $sql = "
292
+ SELECT post_id, meta_value
293
+ FROM $wpdb->postmeta
294
+ WHERE meta_key = 'dsq_thread_id' AND meta_value IN (".implode(', ', array_fill(0, count($thread_ids), '%s')).")
295
+ ";
296
+
297
+ // Call $wpdb->prepare passing the values of the array as separate arguments
298
+ $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $thread_ids));
299
+
300
+ $results = $wpdb->get_results($query);
301
+
302
+ foreach ( $results as $result ) {
303
+ $thread_map[$result->meta_value] = $result->post_id;
304
+ }
305
+ unset($result);
306
+
307
+ foreach ( $comments as $comment ) {
308
+ $ts = strtotime($comment->created_at);
309
+ if (!$thread_map[$comment->thread->id] && !empty($comment->thread->identifier)) {
310
+ // legacy threads dont already have their meta stored
311
+ foreach ( $comment->thread->identifier as $identifier ) {
312
+ // we know identifier starts with post_ID
313
+ if ($post_ID = (int)substr($identifier, 0, strpos($identifier, ' '))) {
314
+ $thread_map[$comment->thread->id] = $post_ID;
315
+ $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $comment->thread->id, 'post' );
316
+ update_post_meta($post_ID, 'dsq_thread_id', $cleaned_thread_id);
317
+ if (DISQUS_DEBUG) {
318
+ echo "updated post {$post_ID}: dsq_thread_id set to {$comment->thread->id}\n";
319
+ }
320
+ }
321
+ }
322
+ unset($identifier);
323
+ }
324
+ if (!$thread_map[$comment->thread->id]) {
325
+ // shouldn't ever happen, but we can't be certain
326
+ if (DISQUS_DEBUG) {
327
+ if (!empty($comment->thread->identifier)) {
328
+ $idents = implode(', ', $comment->thread->identifier);
329
+ echo "skipped {$comment->id}: missing thread for identifiers ({$idents})\n";
330
+ } else {
331
+ echo "skipped {$comment->id}: missing thread (no identifier)\n";
332
+ }
333
+ }
334
+ continue;
335
+ }
336
+ $results = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->id));
337
+ if (count($results)) {
338
+ // already exists
339
+ if (DISQUS_DEBUG) {
340
+ echo "skipped {$comment->id}: comment already exists\n";
341
+ }
342
+ if (count($results) > 1) {
343
+ // clean up duplicates -- fixes an issue where a race condition allowed comments to be synced multiple times
344
+ $results = array_slice($results, 1);
345
+ foreach ($results as $result) {
346
+ $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %s LIMIT 1", $result);
347
+ }
348
+ }
349
+ continue;
350
+ }
351
+
352
+ $commentdata = false;
353
+
354
+ // first lets check by the id we have stored
355
+ if ($comment->meta) {
356
+ $meta = explode(';', $comment->meta);
357
+ foreach ($meta as $value) {
358
+ $value = explode('=', $value);
359
+ $meta[$value[0]] = $value[1];
360
+ }
361
+ unset($value);
362
+ if ($meta['wp_id']) {
363
+ $commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_ID = %s LIMIT 1", $meta['wp_id']), ARRAY_A);
364
+ }
365
+ }
366
+
367
+ // skip comments that were imported but are missing meta information
368
+ if (!$commentdata && $comment->imported) {
369
+ if (DISQUS_DEBUG) {
370
+ echo "skipped {$comment->id}: comment not found and marked as imported\n";
371
+ }
372
+ continue;
373
+ }
374
+
375
+ // and follow up using legacy Disqus agent
376
+ if (!$commentdata) {
377
+ $commentdata = $wpdb->get_row($wpdb->prepare( "SELECT comment_ID, comment_parent FROM $wpdb->comments WHERE comment_agent = %s LIMIT 1", 'Disqus/1.0:'.$comment->id), ARRAY_A);
378
+ }
379
+ if (!$commentdata) {
380
+ // Comment doesnt exist yet, lets insert it
381
+ if ($comment->status == 'approved') {
382
+ $approved = 1;
383
+ } elseif ($comment->status == 'spam') {
384
+ $approved = 'spam';
385
+ } else {
386
+ $approved = 0;
387
+ }
388
+ $commentdata = array(
389
+ 'comment_post_ID' => $thread_map[$comment->thread->id],
390
+ 'comment_date' => date('Y-m-d\TH:i:s', strtotime($comment->created_at) + (get_option('gmt_offset') * 3600)),
391
+ 'comment_date_gmt' => $comment->created_at,
392
+ 'comment_content' => apply_filters('pre_comment_content', $comment->message),
393
+ 'comment_approved' => $approved,
394
+ 'comment_agent' => 'Disqus/1.1('.DISQUS_VERSION.'):'.intval($comment->id),
395
+ 'comment_type' => '',
396
+ );
397
+ if ($comment->is_anonymous) {
398
+ $commentdata['comment_author'] = $comment->anonymous_author->name;
399
+ $commentdata['comment_author_email'] = $comment->anonymous_author->email;
400
+ $commentdata['comment_author_url'] = $comment->anonymous_author->url;
401
+ $commentdata['comment_author_IP'] = $comment->ip_address;
402
+ } else {
403
+ if (!empty($comment->author->display_name)) {
404
+ $commentdata['comment_author'] = $comment->author->display_name;
405
+ } else {
406
+ $commentdata['comment_author'] = $comment->author->username;
407
+ }
408
+ $commentdata['comment_author_email'] = $comment->author->email;
409
+ $commentdata['comment_author_url'] = $comment->author->url;
410
+ $commentdata['comment_author_IP'] = $comment->ip_address;
411
+ }
412
+ $commentdata = wp_filter_comment($commentdata);
413
+ if ($comment->parent_post) {
414
+ $parent_id = $wpdb->get_var($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->parent_post));
415
+ if ($parent_id) {
416
+ $commentdata['comment_parent'] = $parent_id;
417
+ }
418
+ }
419
+
420
+ // due to a race condition we need to test again for coment existance
421
+ if ($wpdb->get_row($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->id))) {
422
+ // already exists
423
+ if (DISQUS_DEBUG) {
424
+ echo "skipped {$comment->id}: comment already exists (second check)\n";
425
+ }
426
+ continue;
427
+ }
428
+
429
+ $commentdata['comment_ID'] = wp_insert_comment($commentdata);
430
+ if (DISQUS_DEBUG) {
431
+ echo "inserted {$comment->id}: id is {$commentdata[comment_ID]}\n";
432
+ }
433
+ }
434
+ if ((isset($commentdata['comment_parent']) && !$commentdata['comment_parent']) && $comment->parent_post) {
435
+ $parent_id = $wpdb->get_var($wpdb->prepare( "SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = 'dsq_post_id' AND meta_value = %s LIMIT 1", $comment->parent_post));
436
+ if ($parent_id) {
437
+ $wpdb->query($wpdb->prepare( "UPDATE $wpdb->comments SET comment_parent = %s WHERE comment_id = %s", $parent_id, $commentdata['comment_ID']));
438
+ if (DISQUS_DEBUG) {
439
+ echo "updated {$comment->id}: comment_parent changed to {$parent_id}\n";
440
+ }
441
+
442
+ }
443
+ }
444
+ $comment_id = $commentdata['comment_ID'];
445
+ update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
446
+ update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
447
+ }
448
+ unset($comment);
449
+
450
+ if( isset($_POST['dsq_api_key']) && $_POST['dsq_api_key'] == get_option('disqus_api_key') ) {
451
+ if( isset($_GET['dsq_sync_action']) && isset($_GET['dsq_sync_comment_id']) ) {
452
+ $comment_parts = explode('=', $_GET['dsq_sync_comment_id']);
453
+
454
+ if (!($comment_id = intval($comment_parts[1])) > 0) {
455
+ return;
456
+ }
457
+
458
+ if( 'wp_id' != $comment_parts[0] ) {
459
+ $comment_id = $wpdb->get_var($wpdb->prepare('SELECT comment_ID FROM ' . $wpdb->comments . ' WHERE comment_post_ID = %d AND comment_agent LIKE %s', intval($post->ID), 'Disqus/1.0:' . $comment_id));
460
+ }
461
+
462
+ switch( $_GET['dsq_sync_action'] ) {
463
+ case 'mark_spam':
464
+ wp_set_comment_status($comment_id, 'spam');
465
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'spam') -->";
466
+ break;
467
+ case 'mark_approved':
468
+ wp_set_comment_status($comment_id, 'approve');
469
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'approve') -->";
470
+ break;
471
+ case 'mark_killed':
472
+ wp_set_comment_status($comment_id, 'hold');
473
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'hold') -->";
474
+ break;
475
+ }
476
+ }
477
+ }
478
+ }
479
+
480
+ function dsq_request_handler() {
481
+ global $dsq_response;
482
+ global $dsq_api;
483
+ global $post;
484
+ global $wpdb;
485
+
486
+ if (!empty($_GET['cf_action'])) {
487
+ switch ($_GET['cf_action']) {
488
+ case 'sync_comments':
489
+ if( !( $post_id = $_GET['post_id'] ) ) {
490
+ header("HTTP/1.0 400 Bad Request");
491
+ die();
492
+ }
493
+ // schedule the event for 5 minutes from now in case they
494
+ // happen to make a quick post
495
+ dsq_add_pending_post_id($post_id);
496
+
497
+ if (DISQUS_DEBUG) {
498
+ $response = dsq_sync_forum();
499
+ if (!$response) {
500
+ die('// error: '.$dsq_api->get_last_error());
501
+ } else {
502
+ list($last_comment_id, $comments) = $response;
503
+ die('// synced '.$comments.' comments');
504
+ }
505
+ } else {
506
+ $ts = time() + 300;
507
+ wp_schedule_single_event($ts, 'dsq_sync_forum');
508
+ die('// sync scheduled');
509
+ }
510
+ break;
511
+ case 'export_comments':
512
+ if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
513
+ $msg = '';
514
+ $result = '';
515
+ $response = null;
516
+
517
+ $timestamp = intval($_GET['timestamp']);
518
+ $post_id = intval($_GET['post_id']);
519
+ if ( isset($_GET['_dsqexport_wpnonce']) === false ) {
520
+ $msg = dsq_i('Unable to export comments. Make sure you are accessing this page from the Wordpress dashboard.');
521
+ $result = 'fail';
522
+ }
523
+ else {
524
+
525
+ // Check nonce
526
+ check_admin_referer('dsq-wpnonce_export', '_dsqexport_wpnonce');
527
+
528
+ global $wpdb, $dsq_api;
529
+ $post = $wpdb->get_results($wpdb->prepare("
530
+ SELECT *
531
+ FROM $wpdb->posts
532
+ WHERE post_type != 'revision'
533
+ AND post_status = 'publish'
534
+ AND comment_count > 0
535
+ AND ID > %d
536
+ ORDER BY ID ASC
537
+ LIMIT 1
538
+ ", $post_id));
539
+ $post = $post[0];
540
+ $post_id = $post->ID;
541
+ $max_post_id = $wpdb->get_var("
542
+ SELECT MAX(Id)
543
+ FROM $wpdb->posts
544
+ WHERE post_type != 'revision'
545
+ AND post_status = 'publish'
546
+ AND comment_count > 0
547
+ ");
548
+ $eof = (int)($post_id == $max_post_id);
549
+ if ($eof) {
550
+ $status = 'complete';
551
+ $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
552
+ $msg .= '<br/><a href="'.DISQUS_IMPORTER_URL.'" target="_blank">';
553
+ $msg .= dsq_i('See the status of your import at Disqus') . '</a>';
554
+ }
555
+ else {
556
+ $status = 'partial';
557
+ $msg = dsq_i('Processed comments on post') . ' #'. $post_id . '&hellip;';
558
+ }
559
+ $result = 'fail';
560
+ if ($post) {
561
+ require_once(dirname(__FILE__) . '/export.php');
562
+ $wxr = dsq_export_wp($post);
563
+ $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
564
+ if (!($response['group_id'] > 0)) {
565
+ $result = 'fail';
566
+ $msg = '<p class="status dsq-export-fail">';
567
+ $msg .= dsq_i('Sorry, something unexpected happened with the export. Please try again.');
568
+ $msg .= '</p><p>';
569
+ $msg .= dsq_i('If your API key has changed, you may need to reinstall Disqus (deactivate the plugin and then reactivate it).');
570
+ $msg .= dsq_i('If you are still having issues, refer to the %s WordPress help page',
571
+ '<a href="https://help.disqus.com/customer/portal/articles/472005" onclick="window.open(this.href); return false">');
572
+ $msg .= '</a></p>';
573
+ $response = $dsq_api->get_last_error();
574
+ }
575
+ else {
576
+ if ($eof) {
577
+ $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
578
+ $msg .= '<br/><a href="' . $response['link'] . '" target="_blank">';
579
+ $msg .= dsq_i('See the status of your import at Disqus');
580
+ $msg .= '</a>';
581
+ }
582
+ $result = 'success';
583
+ }
584
+ }
585
+ }
586
+
587
+ // send AJAX response
588
+ $response = compact('result', 'timestamp', 'status', 'post_id', 'msg', 'eof', 'response');
589
+ header('Content-type: text/javascript');
590
+ echo cf_json_encode($response);
591
+ die();
592
+ }
593
+ break;
594
+ case 'import_comments':
595
+ if (current_user_can('manage_options')) {
596
+ $msg = '';
597
+ $result = '';
598
+ $response = null;
599
+
600
+ if ( isset($_GET['_dsqimport_wpnonce']) === false ) {
601
+ $msg = dsq_i('Unable to import comments. Make sure you are accessing this page from the Wordpress dashboard.');
602
+ $result = 'fail';
603
+ }
604
+ else
605
+ {
606
+ // Check nonce
607
+ check_admin_referer('dsq-wpnonce_import', '_dsqimport_wpnonce');
608
+
609
+ if (!isset($_GET['last_comment_id'])) $last_comment_id = false;
610
+ else $last_comment_id = $_GET['last_comment_id'];
611
+
612
+ if ($_GET['wipe'] == '1') {
613
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."commentmeta` WHERE meta_key IN ('dsq_post_id', 'dsq_parent_post_id')");
614
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."comments` WHERE comment_agent LIKE 'Disqus/%%'");
615
+ }
616
+
617
+ ob_start();
618
+ $response = dsq_sync_forum($last_comment_id, true);
619
+ $debug = ob_get_clean();
620
+ if (!$response) {
621
+ $status = 'error';
622
+ $result = 'fail';
623
+ $error = $dsq_api->get_last_error();
624
+ $msg = '<p class="status dsq-export-fail">'.dsq_i('There was an error downloading your comments from Disqus.').'<br/>'.esc_attr($error).'</p>';
625
+ } else {
626
+ list($comments, $last_comment_id) = $response;
627
+ if (!$comments) {
628
+ $status = 'complete';
629
+ $msg = dsq_i('Your comments have been downloaded from Disqus and saved in your local database.');
630
+ } else {
631
+ $status = 'partial';
632
+ $msg = dsq_i('Import in progress (last post id: %s)', $last_comment_id) . ' &hellip;';
633
+ }
634
+ $result = 'success';
635
+ }
636
+ $debug = explode("\n", $debug);
637
+ $response = compact('result', 'status', 'comments', 'msg', 'last_comment_id', 'debug');
638
+ header('Content-type: text/javascript');
639
+ echo cf_json_encode($response);
640
+ die();
641
+ }
642
+ }
643
+ break;
644
+ }
645
+ }
646
+ }
647
+
648
+ add_action('init', 'dsq_request_handler');
649
+
650
+ /**
651
+ * @param string $option_name
652
+ */
653
+ function dsq_image_upload_handler($option_name) {
654
+ // If the upload field has a file in it
655
+ if(isset($_FILES[$option_name]) && ($_FILES[$option_name]['size'] > 0)) {
656
+ // Get the type of the uploaded file. This is returned as "type/extension"
657
+ $arr_file_type = wp_check_filetype(basename($_FILES[$option_name]['name']));
658
+ $uploaded_file_type = $arr_file_type['type'];
659
+ // Set an array containing a list of acceptable formats
660
+ $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png','image/x-icon');
661
+ // If the uploaded file is the right format
662
+ if(in_array($uploaded_file_type, $allowed_file_types)) {
663
+ // Options array for the wp_handle_upload function. 'test_upload' => false
664
+ $upload_overrides = array( 'test_form' => false );
665
+ // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
666
+ $uploaded_file = wp_handle_upload($_FILES[$option_name], $upload_overrides);
667
+ // If the wp_handle_upload call returned a local path for the image
668
+ if(isset($uploaded_file['url'])) {
669
+ update_option($option_name, $uploaded_file['url']);
670
+ }
671
+ }
672
+ }
673
+ }
674
+
675
+ function dsq_add_pending_post_id($post_id) {
676
+ update_post_meta($post_id, 'dsq_needs_sync', '1', $unique=true);
677
+ }
678
+
679
+ function dsq_get_pending_post_ids() {
680
+ global $wpdb;
681
+
682
+ $results = $wpdb->get_results( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'dsq_needs_sync'");
683
+ $post_ids = array();
684
+ foreach ($results as $result) {
685
+ $post_ids[] = $result->post_id;
686
+ }
687
+ return $post_ids;
688
+ }
689
+
690
+ function dsq_clear_pending_post_ids($post_ids) {
691
+ global $wpdb;
692
+
693
+ // add as many placeholders as needed
694
+ $sql = "
695
+ DELETE FROM {$wpdb->postmeta}
696
+ WHERE meta_key = 'dsq_needs_sync' AND post_id IN (".implode(', ', array_fill(0, count($post_ids), '%s')).")
697
+ ";
698
+
699
+ // Call $wpdb->prepare passing the values of the array as separate arguments
700
+ $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $post_ids));
701
+
702
+ $wpdb->query($query);
703
+
704
+ update_meta_cache('dsq_needs_sync', $post_ids);
705
+ }
706
+
707
+
708
+ function dsq_sync_post($post_id) {
709
+ global $dsq_api, $wpdb;
710
+
711
+ $post = get_post($post_id);
712
+
713
+ // Call update_thread to ensure our permalink is up to date
714
+ dsq_update_permalink($post);
715
+ }
716
+
717
+ function dsq_sync_forum($last_comment_id=false, $force=false) {
718
+ global $dsq_api, $wpdb;
719
+
720
+ set_time_limit(DISQUS_SYNC_TIMEOUT);
721
+
722
+ if ($force) {
723
+ $sync_time = null;
724
+ } else {
725
+ $sync_time = (int)get_option('_disqus_sync_lock');
726
+ }
727
+
728
+ // lock expires after 1 hour
729
+ if ($sync_time && $sync_time > time() - 60*60) {
730
+ $dsq_api->api->last_error = 'Sync already in progress (lock found)';
731
+ return false;
732
+ } else {
733
+ update_option('_disqus_sync_lock', time());
734
+ }
735
+
736
+ // sync all pending posts
737
+ $post_ids = dsq_get_pending_post_ids();
738
+ dsq_clear_pending_post_ids($post_ids);
739
+
740
+ foreach ($post_ids as $post_id) {
741
+ dsq_sync_post($post_id);
742
+ }
743
+
744
+ if ($last_comment_id === false) {
745
+ $last_comment_id = get_option('disqus_last_comment_id');
746
+ if (!$last_comment_id) {
747
+ $last_comment_id = 0;
748
+ }
749
+ }
750
+ if ($last_comment_id) {
751
+ $last_comment_id++;
752
+ }
753
+
754
+ //$last_comment_id = 0;
755
+
756
+ // Pull comments from API
757
+ $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
758
+ if( $dsq_response < 0 || $dsq_response === false ) {
759
+ return false;
760
+ }
761
+
762
+ // Sync comments with database.
763
+ dsq_sync_comments($dsq_response);
764
+ $total = 0;
765
+ if ($dsq_response) {
766
+ foreach ($dsq_response as $comment) {
767
+ $total += 1;
768
+ if ($comment->id > $last_comment_id) $last_comment_id = $comment->id;
769
+ }
770
+ if ($last_comment_id > get_option('disqus_last_comment_id')) {
771
+ update_option('disqus_last_comment_id', $last_comment_id);
772
+ }
773
+ }
774
+ unset($comment);
775
+ delete_option('_disqus_sync_lock');
776
+ return array($total, $last_comment_id);
777
+ }
778
+
779
+ add_action('dsq_sync_forum', 'dsq_sync_forum');
780
+
781
+ function dsq_update_permalink($post) {
782
+ global $dsq_api;
783
+
784
+ if (DISQUS_DEBUG) {
785
+ echo "updating post on disqus: {$post->ID}\n";
786
+ }
787
+
788
+ $response = $dsq_api->api->update_thread(null, array(
789
+ 'thread_identifier' => dsq_identifier_for_post($post),
790
+ 'title' => dsq_title_for_post($post),
791
+ 'url' => dsq_link_for_post($post)
792
+ ));
793
+
794
+ $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $response->id, 'post' );
795
+ update_post_meta($post->ID, 'dsq_thread_id', $cleaned_thread_id);
796
+
797
+ return $response;
798
+ }
799
+
800
+ /**
801
+ * Compatibility
802
+ */
803
+
804
+ if (!function_exists ( '_wp_specialchars' ) ) {
805
+ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
806
+ $string = (string) $string;
807
+
808
+ if ( 0 === strlen( $string ) ) {
809
+ return '';
810
+ }
811
+
812
+ // Don't bother if there are no specialchars - saves some processing
813
+ if ( !preg_match( '/[&<>"\']/', $string ) ) {
814
+ return $string;
815
+ }
816
+
817
+ // Account for the previous behaviour of the function when the $quote_style is not an accepted value
818
+ if ( empty( $quote_style ) ) {
819
+ $quote_style = ENT_NOQUOTES;
820
+ } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
821
+ $quote_style = ENT_QUOTES;
822
+ }
823
+
824
+ // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
825
+ if ( !$charset ) {
826
+ static $_charset;
827
+ if ( !isset( $_charset ) ) {
828
+ $alloptions = wp_load_alloptions();
829
+ $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
830
+ }
831
+ $charset = $_charset;
832
+ }
833
+ if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
834
+ $charset = 'UTF-8';
835
+ }
836
+
837
+ $_quote_style = $quote_style;
838
+
839
+ if ( $quote_style === 'double' ) {
840
+ $quote_style = ENT_COMPAT;
841
+ $_quote_style = ENT_COMPAT;
842
+ } elseif ( $quote_style === 'single' ) {
843
+ $quote_style = ENT_NOQUOTES;
844
+ }
845
+
846
+ // Handle double encoding ourselves
847
+ if ( !$double_encode ) {
848
+ $string = wp_specialchars_decode( $string, $_quote_style );
849
+ $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
850
+ }
851
+
852
+ $string = @esc_attr( $string, $quote_style, $charset );
853
+
854
+ // Handle double encoding ourselves
855
+ if ( !$double_encode ) {
856
+ $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string );
857
+ }
858
+
859
+ // Backwards compatibility
860
+ if ( 'single' === $_quote_style ) {
861
+ $string = str_replace( "'", '&#039;', $string );
862
+ }
863
+
864
+ return $string;
865
+ }
866
+ }
867
+
868
+ if (!function_exists ( 'wp_check_invalid_utf8' ) ) {
869
+ function wp_check_invalid_utf8( $string, $strip = false ) {
870
+ $string = (string) $string;
871
+
872
+ if ( 0 === strlen( $string ) ) {
873
+ return '';
874
+ }
875
+
876
+ // Store the site charset as a static to avoid multiple calls to get_option()
877
+ static $is_utf8;
878
+ if ( !isset( $is_utf8 ) ) {
879
+ $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
880
+ }
881
+ if ( !$is_utf8 ) {
882
+ return $string;
883
+ }
884
+
885
+ // Check for support for utf8 in the installed PCRE library once and store the result in a static
886
+ static $utf8_pcre;
887
+ if ( !isset( $utf8_pcre ) ) {
888
+ $utf8_pcre = @preg_match( '/^./u', 'a' );
889
+ }
890
+ // We can't demand utf8 in the PCRE installation, so just return the string in those cases
891
+ if ( !$utf8_pcre ) {
892
+ return $string;
893
+ }
894
+
895
+ // preg_match fails when it encounters invalid UTF8 in $string
896
+ if ( 1 === @preg_match( '/^./us', $string ) ) {
897
+ return $string;
898
+ }
899
+
900
+ // Attempt to strip the bad chars if requested (not recommended)
901
+ if ( $strip && function_exists( 'iconv' ) ) {
902
+ return iconv( 'utf-8', 'utf-8', $string );
903
+ }
904
+
905
+ return '';
906
+ }
907
+ }
908
+
909
+ if (!function_exists ( 'esc_html' ) ) {
910
+ function esc_html( $text ) {
911
+ $safe_text = wp_check_invalid_utf8( $text );
912
+ $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
913
+ return apply_filters( 'esc_html', $safe_text, $text );
914
+ }
915
+ }
916
+
917
+ if (!function_exists ( 'esc_attr' ) ) {
918
+ function esc_attr( $text ) {
919
+ $safe_text = wp_check_invalid_utf8( $text );
920
+ $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
921
+ return apply_filters( 'attribute_escape', $safe_text, $text );
922
+ }
923
+ }
924
+
925
+ /**
926
+ * Filters/Actions
927
+ */
928
+
929
+ // ugly global hack for comments closing
930
+ $EMBED = false;
931
+ function dsq_comments_template($value) {
932
+ global $EMBED;
933
+ global $post;
934
+ global $comments;
935
+
936
+ if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
937
+ return;
938
+ }
939
+
940
+ if ( !dsq_is_installed() || !dsq_can_replace() ) {
941
+ return $value;
942
+ }
943
+
944
+ // TODO: If a disqus-comments.php is found in the current template's
945
+ // path, use that instead of the default bundled comments.php
946
+ //return TEMPLATEPATH . '/disqus-comments.php';
947
+ $EMBED = true;
948
+ return dirname(__FILE__) . '/comments.php';
949
+ }
950
+
951
+ function dsq_comment( $comment, $args, $depth ) {
952
+ $GLOBALS['comment'] = $comment;
953
+ switch ($comment->comment_type):
954
+ case '' :
955
+ ?>
956
+ <li <?php comment_class(); ?> id="dsq-comment-<?php echo comment_ID(); ?>">
957
+ <div id="dsq-comment-header-<?php echo comment_ID(); ?>" class="dsq-comment-header">
958
+ <cite id="dsq-cite-<?php echo comment_ID(); ?>">
959
+ <?php if(comment_author_url()) : ?>
960
+ <a id="dsq-author-user-<?php echo comment_ID(); ?>" href="<?php echo comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo comment_author(); ?></a>
961
+ <?php else : ?>
962
+ <span id="dsq-author-user-<?php echo comment_ID(); ?>"><?php echo comment_author(); ?></span>
963
+ <?php endif; ?>
964
+ </cite>
965
+ </div>
966
+ <div id="dsq-comment-body-<?php echo comment_ID(); ?>" class="dsq-comment-body">
967
+ <div id="dsq-comment-message-<?php echo comment_ID(); ?>" class="dsq-comment-message"><?php echo wp_filter_kses(comment_text()); ?></div>
968
+ </div>
969
+
970
+ <?php
971
+ break;
972
+ case 'pingback' :
973
+ case 'trackback' :
974
+ ?>
975
+ <li class="post pingback">
976
+ <p><?php echo dsq_i('Pingback:'); ?> <?php comment_author_link(); ?>(<?php edit_comment_link(dsq_i('Edit'), ' '); ?>)</p>
977
+ </li>
978
+ <?php
979
+ break;
980
+ endswitch;
981
+ }
982
+
983
+ // Mark entries in index to replace comments link.
984
+ // As of WordPress 3.1 this is required to return a numerical value
985
+ function dsq_comments_number($count) {
986
+ global $post;
987
+
988
+ return $count;
989
+ }
990
+
991
+ function dsq_comments_text($comment_text) {
992
+ global $post;
993
+
994
+ if ( dsq_can_replace() ) {
995
+ return '<span class="dsq-postid" data-dsqidentifier="'.esc_attr(dsq_identifier_for_post($post)).'">'.$comment_text.'</span>';
996
+ } else {
997
+ return $comment_text;
998
+ }
999
+ }
1000
+
1001
+ function dsq_bloginfo_url($url) {
1002
+ if ( get_feed_link('comments_rss2') == $url && dsq_can_replace() ) {
1003
+ return 'https://' . strtolower(get_option('disqus_forum_url')) . '.disqus.com' . DISQUS_RSS_PATH;
1004
+ } else {
1005
+ return $url;
1006
+ }
1007
+ }
1008
+
1009
+ function dsq_plugin_action_links($links, $file) {
1010
+ $plugin_file = basename(__FILE__);
1011
+ if (basename($file) == $plugin_file) {
1012
+ if (!dsq_is_installed()) {
1013
+ $settings_link = '<a href="edit-comments.php?page=disqus">'.dsq_i('Configure').'</a>';
1014
+ } else {
1015
+ $settings_link = '<a href="edit-comments.php?page=disqus#adv">'.dsq_i('Settings').'</a>';
1016
+ }
1017
+ array_unshift($links, $settings_link);
1018
+ }
1019
+ return $links;
1020
+ }
1021
+ add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
1022
+
1023
+ /**
1024
+ * Hide the default comment form to stop spammers by marking all comments
1025
+ * as closed.
1026
+ */
1027
+ function dsq_comments_open($open, $post_id=null) {
1028
+ global $EMBED;
1029
+ if ($EMBED) return false;
1030
+ return $open;
1031
+ }
1032
+ add_filter('comments_open', 'dsq_comments_open');
1033
+
1034
+ // Always add Disqus management page to the admin menu
1035
+ function dsq_add_pages() {
1036
+ add_submenu_page(
1037
+ 'edit-comments.php',
1038
+ 'Disqus',
1039
+ 'Disqus',
1040
+ 'moderate_comments',
1041
+ 'disqus',
1042
+ 'dsq_manage'
1043
+ );
1044
+ }
1045
+ add_action('admin_menu', 'dsq_add_pages', 10);
1046
+
1047
+ // only active on dashboard
1048
+ function get_dash_comment_counts() {
1049
+ global $wpdb;
1050
+ // taken from wp-includes/comment.php - WP 2.8.5
1051
+ $count = $wpdb->get_results("
1052
+ SELECT comment_approved, COUNT( * ) AS num_comments
1053
+ FROM {$wpdb->comments}
1054
+ WHERE comment_type != 'trackback'
1055
+ AND comment_type != 'pingback'
1056
+ GROUP BY comment_approved
1057
+ ", ARRAY_A );
1058
+ $total = 0;
1059
+ $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
1060
+ $known_types = array_keys( $approved );
1061
+ foreach( (array) $count as $row_num => $row ) {
1062
+ $total += $row['num_comments'];
1063
+ if ( in_array( $row['comment_approved'], $known_types ) && array_key_exists($row['comment_approved'], $approved) )
1064
+ $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1065
+ }
1066
+
1067
+ $stats['total_comments'] = $total;
1068
+ foreach ( $approved as $key ) {
1069
+ if ( empty($stats[$key]) )
1070
+ $stats[$key] = 0;
1071
+ }
1072
+ return (object) $stats;
1073
+ }
1074
+
1075
+ function dsq_manage() {
1076
+ if (dsq_does_need_update() && isset($_POST['upgrade'])) {
1077
+ dsq_install();
1078
+ }
1079
+
1080
+ if (dsq_does_need_update() && !isset($_POST['reset'])) {
1081
+ include_once(dirname(__FILE__) . '/upgrade.php');
1082
+ } else {
1083
+ include_once(dirname(__FILE__) . '/manage.php');
1084
+ }
1085
+ }
1086
+
1087
+ function dsq_admin_head() {
1088
+ if (isset($_GET['page']) && $_GET['page'] == 'disqus') {
1089
+ ?>
1090
+ <link rel='stylesheet' href='<?php echo esc_url( plugins_url( 'media/styles/manage.css', __FILE__ ) ); ?>' type='text/css' />
1091
+ <style type="text/css">
1092
+ .dsq-importing, .dsq-imported, .dsq-import-fail, .dsq-exporting, .dsq-exported, .dsq-export-fail {
1093
+ background: url(<?php echo esc_url( admin_url('images/loading.gif') ); ?>) left center no-repeat;
1094
+ line-height: 16px;
1095
+ padding-left: 20px;
1096
+ }
1097
+ p.status {
1098
+ padding-top: 0;
1099
+ padding-bottom: 0;
1100
+ margin: 0;
1101
+ }
1102
+ .dsq-imported, .dsq-exported {
1103
+ background: url(<?php echo esc_url( admin_url('images/yes.png') ); ?>) left center no-repeat;
1104
+ }
1105
+ .dsq-import-fail, .dsq-export-fail {
1106
+ background: url(<?php echo esc_url( admin_url('images/no.png') ); ?>) left center no-repeat;
1107
+ }
1108
+ </style>
1109
+ <?php
1110
+ // HACK: Our own styles for older versions of WordPress.
1111
+ global $wp_version;
1112
+ if ( version_compare($wp_version, '2.5', '<') ) {
1113
+ echo "<link rel='stylesheet' href='" . esc_url( plugins_url( 'media/styles/manage-pre25.css', __FILE__ ) ) . "' type='text/css' />";
1114
+ }
1115
+ }
1116
+ }
1117
+ add_action('admin_head', 'dsq_admin_head');
1118
+
1119
+ /**
1120
+ * Wrapper for built-in __() which pulls all text from
1121
+ * the disqus domain and supports variable interpolation.
1122
+ */
1123
+ function dsq_i($text, $params=null) {
1124
+ if (!is_array($params))
1125
+ {
1126
+ $params = func_get_args();
1127
+ $params = array_slice($params, 1);
1128
+ }
1129
+ return vsprintf(__($text, 'disqus'), $params);
1130
+ }
1131
+
1132
+ // catch original query
1133
+ function dsq_parse_query($query) {
1134
+ add_action('the_posts', 'dsq_add_request_post_ids', 999);
1135
+ }
1136
+ add_action('parse_request', 'dsq_parse_query');
1137
+
1138
+ // track the original request post_ids, only run once
1139
+ function dsq_add_request_post_ids($posts) {
1140
+ dsq_add_query_posts($posts);
1141
+ remove_action('the_posts', 'dsq_log_request_post_ids', 999);
1142
+ return $posts;
1143
+ }
1144
+
1145
+ function dsq_maybe_add_post_ids($posts) {
1146
+ global $DSQ_QUERY_COMMENTS;
1147
+ if ($DSQ_QUERY_COMMENTS) {
1148
+ dsq_add_query_posts($posts);
1149
+ }
1150
+ return $posts;
1151
+ }
1152
+ add_action('the_posts', 'dsq_maybe_add_post_ids');
1153
+
1154
+ function dsq_add_query_posts($posts) {
1155
+ global $DSQ_QUERY_POST_IDS;
1156
+ if (count($posts)) {
1157
+ foreach ($posts as $post) {
1158
+ $post_ids[] = intval($post->ID);
1159
+ }
1160
+ $DSQ_QUERY_POST_IDS[md5(serialize($post_ids))] = $post_ids;
1161
+ }
1162
+ }
1163
+
1164
+ // check to see if the posts in the loop match the original request or an explicit request, if so output the JS
1165
+ function dsq_loop_end($query) {
1166
+ if ( get_option('disqus_cc_fix') == '1' ||
1167
+ !count($query->posts) ||
1168
+ is_single() ||
1169
+ is_page() ||
1170
+ is_feed() ||
1171
+ !dsq_can_replace()
1172
+ ) {
1173
+ return;
1174
+ }
1175
+ global $DSQ_QUERY_POST_IDS;
1176
+ foreach ($query->posts as $post) {
1177
+ $loop_ids[] = intval($post->ID);
1178
+ }
1179
+ $posts_key = md5(serialize($loop_ids));
1180
+ if (isset($DSQ_QUERY_POST_IDS[$posts_key])) {
1181
+ dsq_output_loop_comment_js($DSQ_QUERY_POST_IDS[$posts_key]);
1182
+ }
1183
+ }
1184
+ add_action('loop_end', 'dsq_loop_end');
1185
+
1186
+ // if someone has a better hack, let me know
1187
+ // prevents duplicate calls to count.js
1188
+ $_HAS_COUNTS = false;
1189
+
1190
+ function dsq_output_count_js() {
1191
+ $count_vars = array(
1192
+ 'disqusShortname' => strtolower( get_option( 'disqus_forum_url' ) ),
1193
+ );
1194
+
1195
+ wp_register_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1196
+ wp_localize_script( 'dsq_count_script', 'countVars', $count_vars );
1197
+ wp_enqueue_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1198
+ }
1199
+
1200
+ function dsq_output_loop_comment_js($post_ids = null) {
1201
+ global $_HAS_COUNTS;
1202
+ if ($_HAS_COUNTS) return;
1203
+ $_HAS_COUNTS = true;
1204
+ if (count($post_ids)) {
1205
+ dsq_output_count_js();
1206
+ }
1207
+ }
1208
+
1209
+ function dsq_output_footer_comment_js() {
1210
+ if (!dsq_can_replace()) return;
1211
+ if (get_option('disqus_cc_fix') != '1') return;
1212
+
1213
+ dsq_output_count_js();
1214
+ }
1215
+
1216
+ add_action('wp_footer', 'dsq_output_footer_comment_js');
1217
+
1218
+ // UPDATE DSQ when a permalink changes
1219
+
1220
+ $dsq_prev_permalinks = array();
1221
+
1222
+ function dsq_prev_permalink($post_id) {
1223
+ $post = get_post($post_id);
1224
+ // if post not published, return
1225
+ if ($post->post_status != 'publish') {
1226
+ return;
1227
+ }
1228
+ global $dsq_prev_permalinks;
1229
+ $dsq_prev_permalinks['post_'.$post_id] = get_permalink($post_id);
1230
+ }
1231
+ add_action('pre_post_update', 'dsq_prev_permalink');
1232
+
1233
+ function dsq_check_permalink($post_id) {
1234
+ global $dsq_prev_permalinks;
1235
+ if (!empty($dsq_prev_permalinks['post_'.$post_id]) &&
1236
+ $dsq_prev_permalinks['post_'.$post_id] != get_permalink($post_id)
1237
+ ) {
1238
+ $post = get_post($post_id);
1239
+ dsq_update_permalink($post);
1240
+ }
1241
+ }
1242
+ add_action('edit_post', 'dsq_check_permalink');
1243
+
1244
+ // Only replace comments if the disqus_forum_url option is set.
1245
+ add_filter('comments_template', 'dsq_comments_template');
1246
+ add_filter('comments_number', 'dsq_comments_text');
1247
+ add_filter('get_comments_number', 'dsq_comments_number');
1248
+ add_filter('bloginfo_url', 'dsq_bloginfo_url');
1249
+
1250
+ /**
1251
+ * JSON ENCODE for PHP < 5.2.0
1252
+ * Checks if json_encode is not available and defines json_encode
1253
+ * to use php_json_encode in its stead
1254
+ * Works on iteratable objects as well - stdClass is iteratable, so all WP objects are gonna be iteratable
1255
+ */
1256
+ if(!function_exists('cf_json_encode')) {
1257
+ function cf_json_encode($data) {
1258
+
1259
+ // json_encode is sending an application/x-javascript header on Joyent servers
1260
+ // for some unknown reason.
1261
+ return cfjson_encode($data);
1262
+ }
1263
+
1264
+ function cfjson_encode_string($str) {
1265
+ if(is_bool($str)) {
1266
+ return $str ? 'true' : 'false';
1267
+ }
1268
+
1269
+ return str_replace(
1270
+ array(
1271
+ '"'
1272
+ , '/'
1273
+ , "\n"
1274
+ , "\r"
1275
+ )
1276
+ , array(
1277
+ '\"'
1278
+ , '\/'
1279
+ , '\n'
1280
+ , '\r'
1281
+ )
1282
+ , $str
1283
+ );
1284
+ }
1285
+
1286
+ function cfjson_encode($arr) {
1287
+ $json_str = '';
1288
+ if (is_array($arr)) {
1289
+ $pure_array = true;
1290
+ $array_length = count($arr);
1291
+ for ( $i = 0; $i < $array_length ; $i++) {
1292
+ if (!isset($arr[$i])) {
1293
+ $pure_array = false;
1294
+ break;
1295
+ }
1296
+ }
1297
+ if ($pure_array) {
1298
+ $json_str = '[';
1299
+ $temp = array();
1300
+ for ($i=0; $i < $array_length; $i++) {
1301
+ $temp[] = sprintf("%s", cfjson_encode($arr[$i]));
1302
+ }
1303
+ $json_str .= implode(',', $temp);
1304
+ $json_str .="]";
1305
+ }
1306
+ else {
1307
+ $json_str = '{';
1308
+ $temp = array();
1309
+ foreach ($arr as $key => $value) {
1310
+ $temp[] = sprintf("\"%s\":%s", $key, cfjson_encode($value));
1311
+ }
1312
+ $json_str .= implode(',', $temp);
1313
+ $json_str .= '}';
1314
+ }
1315
+ }
1316
+ else if (is_object($arr)) {
1317
+ $json_str = '{';
1318
+ $temp = array();
1319
+ foreach ($arr as $k => $v) {
1320
+ $temp[] = '"'.$k.'":'.cfjson_encode($v);
1321
+ }
1322
+ $json_str .= implode(',', $temp);
1323
+ $json_str .= '}';
1324
+ }
1325
+ else if (is_string($arr)) {
1326
+ $json_str = '"'. cfjson_encode_string($arr) . '"';
1327
+ }
1328
+ else if (is_numeric($arr)) {
1329
+ $json_str = $arr;
1330
+ }
1331
+ else if (is_bool($arr)) {
1332
+ $json_str = $arr ? 'true' : 'false';
1333
+ }
1334
+ else {
1335
+ $json_str = '"'. cfjson_encode_string($arr) . '"';
1336
+ }
1337
+ return $json_str;
1338
+ }
1339
+ }
1340
+
1341
+ // Single Sign-on Integration
1342
+
1343
+ function dsq_sso() {
1344
+ if ($key = get_option('disqus_partner_key')) {
1345
+ // use old style SSO
1346
+ $new = false;
1347
+ } elseif (($key = get_option('disqus_secret_key')) && ($public = get_option('disqus_public_key'))) {
1348
+ // use new style SSO
1349
+ $new = true;
1350
+ } else {
1351
+ // sso is not configured
1352
+ return array();
1353
+ }
1354
+ global $current_user, $dsq_api;
1355
+ get_currentuserinfo();
1356
+ if ($current_user->ID) {
1357
+ $avatar_tag = get_avatar($current_user->ID);
1358
+ $avatar_data = array();
1359
+ preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
1360
+ $avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
1361
+ $user_data = array(
1362
+ 'username' => $current_user->display_name,
1363
+ 'id' => $current_user->ID,
1364
+ 'avatar' => $avatar,
1365
+ 'email' => $current_user->user_email,
1366
+ 'url' => $current_user->user_url,
1367
+ );
1368
+ }
1369
+ else {
1370
+ $user_data = array();
1371
+ }
1372
+ $user_data = base64_encode(cf_json_encode($user_data));
1373
+ $time = time();
1374
+ $hmac = dsq_hmacsha1($user_data.' '.$time, $key);
1375
+
1376
+ $payload = $user_data.' '.$hmac.' '.$time;
1377
+
1378
+ if ($new) {
1379
+ return array('remote_auth_s3'=>$payload, 'api_key'=>$public);
1380
+ } else {
1381
+ return array('remote_auth_s2'=>$payload);
1382
+ }
1383
+ }
1384
+
1385
+ // from: http://www.php.net/manual/en/function.sha1.php#39492
1386
+ // Calculate HMAC-SHA1 according to RFC2104
1387
+ // http://www.ietf.org/rfc/rfc2104.txt
1388
+ function dsq_hmacsha1($data, $key) {
1389
+ $blocksize=64;
1390
+ $hashfunc='sha1';
1391
+ if (strlen($key)>$blocksize)
1392
+ $key=pack('H*', $hashfunc($key));
1393
+ $key=str_pad($key,$blocksize,chr(0x00));
1394
+ $ipad=str_repeat(chr(0x36),$blocksize);
1395
+ $opad=str_repeat(chr(0x5c),$blocksize);
1396
+ $hmac = pack(
1397
+ 'H*',$hashfunc(
1398
+ ($key^$opad).pack(
1399
+ 'H*',$hashfunc(
1400
+ ($key^$ipad).$data
1401
+ )
1402
+ )
1403
+ )
1404
+ );
1405
+ return bin2hex($hmac);
1406
+ }
1407
+
1408
+ function dsq_identifier_for_post($post) {
1409
+ return $post->ID . ' ' . $post->guid;
1410
+ }
1411
+
1412
+ function dsq_title_for_post($post) {
1413
+ $title = get_the_title($post);
1414
+ $title = strip_tags($title, DISQUS_ALLOWED_HTML);
1415
+ return $title;
1416
+ }
1417
+
1418
+ function dsq_link_for_post($post) {
1419
+ return get_permalink($post);
1420
+ }
1421
+
1422
+ function dsq_does_need_update() {
1423
+ $version = (string)get_option('disqus_version');
1424
+ if (empty($version)) {
1425
+ $version = '0';
1426
+ }
1427
+
1428
+ if (version_compare($version, '2.49', '<')) {
1429
+ return true;
1430
+ }
1431
+
1432
+ return false;
1433
+ }
1434
+
1435
+ function dsq_install($allow_database_install=true) {
1436
+ global $wpdb, $userdata;
1437
+
1438
+ $version = (string)get_option('disqus_version');
1439
+ if (!$version) {
1440
+ $version = '0';
1441
+ }
1442
+
1443
+ if ($allow_database_install)
1444
+ {
1445
+ dsq_install_database($version);
1446
+ }
1447
+
1448
+ if (version_compare($version, DISQUS_VERSION, '=')) return;
1449
+
1450
+ // if this is a new install, we should not set disqus active
1451
+ if ($version == '0') {
1452
+ add_option('disqus_active', '0');
1453
+ } else {
1454
+ add_option('disqus_active', '1');
1455
+ }
1456
+
1457
+ update_option('disqus_version', DISQUS_VERSION);
1458
+ }
1459
+
1460
+ /**
1461
+ * Initializes the database if it's not already present.
1462
+ */
1463
+ function dsq_install_database($version=0) {
1464
+ global $wpdb;
1465
+
1466
+ if ( version_compare($version, '2.49', '<') && !is_wp_vip() ) {
1467
+ $wpdb->query("CREATE INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta` (meta_key, meta_value(11));");
1468
+ }
1469
+ }
1470
+ function dsq_reset_database($version=0) {
1471
+ global $wpdb;
1472
+
1473
+ if ( version_compare($version, '2.49', '>=') && !is_wp_vip() ) {
1474
+ $wpdb->query("DROP INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta`;");
1475
+ }
1476
+ }
1477
+
1478
+ /**
1479
+ * Disable internal Wordpress commenting if Disqus is enabled - this prevents spam bots from
1480
+ * commenting using POST requests to /wp-comments-post.php.
1481
+ *
1482
+ * @param int $comment_post_ID
1483
+ * @return int
1484
+ */
1485
+ function dsq_pre_comment_on_post($comment_post_ID) {
1486
+ if (dsq_can_replace()) {
1487
+ wp_die( dsq_i('Sorry, the built-in commenting system is disabled because Disqus is active.') );
1488
+ }
1489
+ return $comment_post_ID;
1490
+ }
1491
+ add_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
1492
+
1493
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
export.php CHANGED
@@ -1,195 +1,195 @@
1
- <?php
2
- /**
3
- * Adapted from WordPress 2.8
4
- */
5
- @set_time_limit(0);
6
- @ini_set('memory_limit', '256M');
7
- define('WXR_VERSION', '1.0');
8
-
9
- /**
10
- * {@internal Missing Short Description}}
11
- *
12
- * @since unknown
13
- *
14
- * @param unknown_type $categories
15
- */
16
- function dsq_export_wxr_missing_parents($categories) {
17
- if ( !is_array($categories) || empty($categories) )
18
- return array();
19
-
20
- foreach ( $categories as $category )
21
- $parents[$category->term_id] = $category->parent;
22
-
23
- $parents = array_unique(array_diff($parents, array_keys($parents)));
24
-
25
- if ( $zero = array_search('0', $parents) )
26
- unset($parents[$zero]);
27
-
28
- return $parents;
29
- }
30
-
31
- /**
32
- * Place string in CDATA tag.
33
- *
34
- * @since unknown
35
- *
36
- * @param string $str String to place in XML CDATA tag.
37
- */
38
- function dsq_export_wxr_cdata($str) {
39
- if ( seems_utf8($str) == false )
40
- $str = utf8_encode($str);
41
-
42
- // $str = ent2ncr(esc_html($str));
43
-
44
- $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
45
-
46
- return $str;
47
- }
48
-
49
- /**
50
- * {@internal Missing Short Description}}
51
- *
52
- * @since unknown
53
- *
54
- * @return string Site URL.
55
- */
56
- function dsq_export_wxr_site_url() {
57
- global $current_site;
58
-
59
- // mu: the base url
60
- if ( isset($current_site->domain) ) {
61
- return 'http://'.$current_site->domain.$current_site->path;
62
- }
63
- // wp: the blog url
64
- else {
65
- return get_bloginfo_rss('url');
66
- }
67
- }
68
-
69
- /**
70
- * {@internal Missing Short Description}}
71
- *
72
- * @since unknown
73
- *
74
- * @param object $c Category Object
75
- */
76
- function dsq_export_wxr_cat_name($c) {
77
- if ( empty($c->name) )
78
- return;
79
-
80
- echo '<wp:cat_name>' . dsq_export_wxr_cdata($c->name) . '</wp:cat_name>';
81
- }
82
-
83
- /**
84
- * {@internal Missing Short Description}}
85
- *
86
- * @since unknown
87
- *
88
- * @param object $c Category Object
89
- */
90
- function dsq_export_wxr_category_description($c) {
91
- if ( empty($c->description) )
92
- return;
93
-
94
- echo '<wp:category_description>' . dsq_export_wxr_cdata($c->description) . '</wp:category_description>';
95
- }
96
-
97
- /**
98
- * {@internal Missing Short Description}}
99
- *
100
- * @since unknown
101
- *
102
- * @param object $t Tag Object
103
- */
104
- function dsq_export_wxr_tag_name($t) {
105
- if ( empty($t->name) )
106
- return;
107
-
108
- echo '<wp:tag_name>' . dsq_export_wxr_cdata($t->name) . '</wp:tag_name>';
109
- }
110
-
111
- /**
112
- * {@internal Missing Short Description}}
113
- *
114
- * @since unknown
115
- *
116
- * @param object $t Tag Object
117
- */
118
- function dsq_export_wxr_tag_description($t) {
119
- if ( empty($t->description) )
120
- return;
121
-
122
- echo '<wp:tag_description>' . dsq_export_wxr_cdata($t->description) . '</wp:tag_description>';
123
- }
124
-
125
- // receives an array of posts to export
126
- function dsq_export_wp($post, $comments=null) {
127
- global $wpdb;
128
-
129
- if (!$comments) {
130
- $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%'", $post->ID) );
131
- }
132
-
133
- // start catching output
134
- ob_start();
135
-
136
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
137
- ?>
138
- <?php the_generator('export');?>
139
- <rss version="2.0"
140
- xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
141
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
142
- xmlns:dsq="http://www.disqus.com/"
143
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
144
- xmlns:dc="http://purl.org/dc/elements/1.1/"
145
- xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
146
- >
147
-
148
- <channel>
149
- <title><?php bloginfo_rss('name'); ?></title>
150
- <link><?php bloginfo_rss('url') ?></link>
151
- <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
152
- <generator>WordPress <?php bloginfo_rss('version'); ?>; Disqus <?php echo DISQUS_VERSION; ?></generator>
153
- <?php
154
- global $wp_query, $post;
155
- $wp_query->in_the_loop = true; // Fake being in the loop.
156
- setup_postdata($post); ?>
157
- <item>
158
- <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
159
- <link><?php the_permalink_rss() ?></link>
160
- <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
161
- <dc:creator><?php echo dsq_export_wxr_cdata(get_the_author()); ?></dc:creator>
162
- <guid isPermaLink="false"><?php the_guid(); ?></guid>
163
- <content:encoded><?php echo dsq_export_wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
164
- <dsq:thread_identifier><?php echo dsq_identifier_for_post($post); ?></dsq:thread_identifier>
165
- <wp:post_id><?php echo $post->ID; ?></wp:post_id>
166
- <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
167
- <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
168
- <?php
169
- if ( $comments ) { foreach ( $comments as $c ) { ?>
170
- <wp:comment>
171
- <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
172
- <wp:comment_author><?php echo dsq_export_wxr_cdata($c->comment_author); ?></wp:comment_author>
173
- <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
174
- <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
175
- <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
176
- <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
177
- <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
178
- <wp:comment_content><?php echo dsq_export_wxr_cdata($c->comment_content) ?></wp:comment_content>
179
- <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
180
- <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
181
- <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
182
- </wp:comment>
183
- <?php } } // comments ?>
184
- </item>
185
- </channel>
186
- </rss>
187
- <?php
188
-
189
- // end of WXR output
190
- $output = ob_get_clean();
191
-
192
- return $output;
193
- }
194
-
195
- ?>
1
+ <?php
2
+ /**
3
+ * Adapted from WordPress 2.8
4
+ */
5
+ @set_time_limit(0);
6
+ @ini_set('memory_limit', '256M');
7
+ define('WXR_VERSION', '1.0');
8
+
9
+ /**
10
+ * {@internal Missing Short Description}}
11
+ *
12
+ * @since unknown
13
+ *
14
+ * @param unknown_type $categories
15
+ */
16
+ function dsq_export_wxr_missing_parents($categories) {
17
+ if ( !is_array($categories) || empty($categories) )
18
+ return array();
19
+
20
+ foreach ( $categories as $category )
21
+ $parents[$category->term_id] = $category->parent;
22
+
23
+ $parents = array_unique(array_diff($parents, array_keys($parents)));
24
+
25
+ if ( $zero = array_search('0', $parents) )
26
+ unset($parents[$zero]);
27
+
28
+ return $parents;
29
+ }
30
+
31
+ /**
32
+ * Place string in CDATA tag.
33
+ *
34
+ * @since unknown
35
+ *
36
+ * @param string $str String to place in XML CDATA tag.
37
+ */
38
+ function dsq_export_wxr_cdata($str) {
39
+ if ( seems_utf8($str) == false )
40
+ $str = utf8_encode($str);
41
+
42
+ // $str = ent2ncr(esc_html($str));
43
+
44
+ $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
45
+
46
+ return $str;
47
+ }
48
+
49
+ /**
50
+ * {@internal Missing Short Description}}
51
+ *
52
+ * @since unknown
53
+ *
54
+ * @return string Site URL.
55
+ */
56
+ function dsq_export_wxr_site_url() {
57
+ global $current_site;
58
+
59
+ // mu: the base url
60
+ if ( isset($current_site->domain) ) {
61
+ return 'http://'.$current_site->domain.$current_site->path;
62
+ }
63
+ // wp: the blog url
64
+ else {
65
+ return get_bloginfo_rss('url');
66
+ }
67
+ }
68
+
69
+ /**
70
+ * {@internal Missing Short Description}}
71
+ *
72
+ * @since unknown
73
+ *
74
+ * @param object $c Category Object
75
+ */
76
+ function dsq_export_wxr_cat_name($c) {
77
+ if ( empty($c->name) )
78
+ return;
79
+
80
+ echo '<wp:cat_name>' . dsq_export_wxr_cdata($c->name) . '</wp:cat_name>';
81
+ }
82
+
83
+ /**
84
+ * {@internal Missing Short Description}}
85
+ *
86
+ * @since unknown
87
+ *
88
+ * @param object $c Category Object
89
+ */
90
+ function dsq_export_wxr_category_description($c) {
91
+ if ( empty($c->description) )
92
+ return;
93
+
94
+ echo '<wp:category_description>' . dsq_export_wxr_cdata($c->description) . '</wp:category_description>';
95
+ }
96
+
97
+ /**
98
+ * {@internal Missing Short Description}}
99
+ *
100
+ * @since unknown
101
+ *
102
+ * @param object $t Tag Object
103
+ */
104
+ function dsq_export_wxr_tag_name($t) {
105
+ if ( empty($t->name) )
106
+ return;
107
+
108
+ echo '<wp:tag_name>' . dsq_export_wxr_cdata($t->name) . '</wp:tag_name>';
109
+ }
110
+
111
+ /**
112
+ * {@internal Missing Short Description}}
113
+ *
114
+ * @since unknown
115
+ *
116
+ * @param object $t Tag Object
117
+ */
118
+ function dsq_export_wxr_tag_description($t) {
119
+ if ( empty($t->description) )
120
+ return;
121
+
122
+ echo '<wp:tag_description>' . dsq_export_wxr_cdata($t->description) . '</wp:tag_description>';
123
+ }
124
+
125
+ // receives an array of posts to export
126
+ function dsq_export_wp($post, $comments=null) {
127
+ global $wpdb;
128
+
129
+ if (!$comments) {
130
+ $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%'", $post->ID) );
131
+ }
132
+
133
+ // start catching output
134
+ ob_start();
135
+
136
+ echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
137
+ ?>
138
+ <?php the_generator('export');?>
139
+ <rss version="2.0"
140
+ xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
141
+ xmlns:content="http://purl.org/rss/1.0/modules/content/"
142
+ xmlns:dsq="http://www.disqus.com/"
143
+ xmlns:wfw="http://wellformedweb.org/CommentAPI/"
144
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
145
+ xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
146
+ >
147
+
148
+ <channel>
149
+ <title><?php bloginfo_rss('name'); ?></title>
150
+ <link><?php bloginfo_rss('url') ?></link>
151
+ <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
152
+ <generator>WordPress <?php bloginfo_rss('version'); ?>; Disqus <?php echo DISQUS_VERSION; ?></generator>
153
+ <?php
154
+ global $wp_query, $post;
155
+ $wp_query->in_the_loop = true; // Fake being in the loop.
156
+ setup_postdata($post); ?>
157
+ <item>
158
+ <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
159
+ <link><?php the_permalink_rss() ?></link>
160
+ <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
161
+ <dc:creator><?php echo dsq_export_wxr_cdata(get_the_author()); ?></dc:creator>
162
+ <guid isPermaLink="false"><?php the_guid(); ?></guid>
163
+ <content:encoded><?php echo dsq_export_wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
164
+ <dsq:thread_identifier><?php echo dsq_identifier_for_post($post); ?></dsq:thread_identifier>
165
+ <wp:post_id><?php echo $post->ID; ?></wp:post_id>
166
+ <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
167
+ <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
168
+ <?php
169
+ if ( $comments ) { foreach ( $comments as $c ) { ?>
170
+ <wp:comment>
171
+ <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
172
+ <wp:comment_author><?php echo dsq_export_wxr_cdata($c->comment_author); ?></wp:comment_author>
173
+ <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
174
+ <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
175
+ <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
176
+ <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
177
+ <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
178
+ <wp:comment_content><?php echo dsq_export_wxr_cdata($c->comment_content) ?></wp:comment_content>
179
+ <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
180
+ <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
181
+ <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
182
+ </wp:comment>
183
+ <?php } } // comments ?>
184
+ </item>
185
+ </channel>
186
+ </rss>
187
+ <?php
188
+
189
+ // end of WXR output
190
+ $output = ob_get_clean();
191
+
192
+ return $output;
193
+ }
194
+
195
+ ?>
lib/api/LICENSE DELETED
@@ -1,202 +0,0 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright 2010 DISQUS
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/api/README.rst DELETED
@@ -1,18 +0,0 @@
1
- Disqus API 1.1
2
-
3
- Please see http://groups.google.com/group/disqus-dev/web/api-1-1 for more information.
4
-
5
- Sample usage::
6
-
7
- require('disqus/disqus.php');
8
-
9
- $dsq = new DisqusAPI($user_api_key, $forum_api_key);
10
- if (($username = $dsq->get_user_name()) === false)
11
- {
12
- throw new Exception($dsq->get_last_error());
13
- }
14
-
15
-
16
- To run the included unit tests you will need to install PHPUnit::
17
-
18
- php disqus/tests.php <your user_api_key>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/api/disqus/disqus.php CHANGED
@@ -1,461 +1,461 @@
1
- <?php
2
- /**
3
- * Implementation of the Disqus v1.1 API.
4
- *
5
- * http://groups.google.com/group/disqus-dev/web/api-1-1
6
- *
7
- * @author Disqus <team@disqus.com>
8
- * @copyright 2007-2010 Big Head Labs
9
- * @link http://disqus.com/
10
- * @package Disqus
11
- * @version 1.1
12
- */
13
-
14
- require_once(dirname(__FILE__) . '/url.php');
15
-
16
- /** @#+
17
- * Constants
18
- */
19
- /**
20
- * Base URL for Disqus.
21
- */
22
-
23
- define('DISQUS_TYPE_SPAM', 'spam');
24
- define('DISQUS_TYPE_DELETED', 'killed');
25
- define('DISQUS_TYPE_KILLED', DISQUS_TYPE_DELETED);
26
- define('DISQUS_TYPE_NEW', 'new');
27
-
28
- define('DISQUS_STATE_APPROVED', 'approved');
29
- define('DISQUS_STATE_UNAPPROVED', 'unapproved');
30
- define('DISQUS_STATE_SPAM', 'spam');
31
- define('DISQUS_STATE_DELETED', 'killed');
32
- define('DISQUS_STATE_KILLED', DISQUS_STATE_DELETED);
33
-
34
- define('DISQUS_ACTION_SPAM', 'spam');
35
- define('DISQUS_ACTION_APPROVE', 'approve');
36
- define('DISQUS_ACTION_DELETE', 'delete');
37
- define('DISQUS_ACTION_KILL', 'kill');
38
-
39
- if (!extension_loaded('json')) {
40
- require_once(dirname(__FILE__) . '/json.php');
41
- function dsq_json_decode($data) {
42
- $json = new JSON;
43
- return $json->unserialize($data);
44
- }
45
- } else {
46
- function dsq_json_decode($data) {
47
- return json_decode($data);
48
- }
49
- }
50
-
51
- /**
52
- * Helper methods for all of the Disqus 1.1 API methods.
53
- *
54
- * @package Disqus
55
- * @author DISQUS.com <team@disqus.com>
56
- * @copyright 2007-2010 Big Head Labs
57
- * @version 1.1
58
- */
59
- class DisqusAPI {
60
- var $user_api_key;
61
- var $forum_api_key;
62
- var $api_url = 'https://www.disqus.com/api/';
63
- var $api_version = '1.1';
64
-
65
- /**
66
- * Creates a new interface to the Disqus API.
67
- *
68
- * @param $user_api_key
69
- * (optional) The User API key to use.
70
- * @param $forum_api_key
71
- * (optional) The Forum API key to use.
72
- * @param $api_url
73
- * (optional) The prefix URL to use when calling the Disqus API.
74
- */
75
- function DisqusAPI($user_api_key, $forum_api_key, $api_url='https://www.disqus.com/api/') {
76
- $this->user_api_key = $user_api_key;
77
- $this->forum_api_key = $forum_api_key;
78
- $this->api_url = $api_url;
79
- $this->last_error = null;
80
- }
81
-
82
- /**
83
- * Makes a call to a Disqus API method.
84
- *
85
- * @return
86
- * The Disqus object.
87
- * @param $method
88
- * The Disqus API method to call.
89
- * @param $args
90
- * An associative array of arguments to be passed.
91
- * @param $post
92
- * TRUE or FALSE, depending on whether we're making a POST call.
93
- */
94
- function call($method, $args=array(), $post=false) {
95
- $url = $this->api_url . $method . '/';
96
-
97
- if (!isset($args['user_api_key'])) {
98
- $args['user_api_key'] = $this->user_api_key;
99
- }
100
- if (!isset($args['forum_api_key'])) {
101
- $args['forum_api_key'] = $this->forum_api_key;
102
- }
103
- if (!isset($args['api_version'])) {
104
- $args['api_version'] = $this->api_version;
105
- }
106
-
107
- foreach ($args as $key=>$value) {
108
- // XXX: Disqus is lacking some exception handling and we sometimes
109
- // end up with 500s when passing invalid values
110
- if (empty($value)) unset($args[$key]);
111
- }
112
-
113
- if (!$post) {
114
- $url .= '?' . dsq_get_query_string($args);
115
- $args = null;
116
- }
117
-
118
- if (!($response = dsq_urlopen($url, $args)) || !$response['code']) {
119
- $this->last_error = 'Unable to connect to the Disqus API servers';
120
- return false;
121
- }
122
-
123
- if ($response['code'] != 200) {
124
- if ($response['code'] == 500) {
125
- // Try to grab the exception ID for better reporting
126
- if (!empty($response['headers']['X-Sentry-ID'])) {
127
- $this->last_error = 'DISQUS returned a bad response (HTTP '.$response['code'].', ReferenceID: '.$response['headers']['X-Sentry-ID'].')';
128
- return false;
129
- }
130
- } elseif ($response['code'] == 400) {
131
- $data = dsq_json_decode($response['data']);
132
- if ($data && $data->message) {
133
- $this->last_error = $data->message;
134
- } else {
135
- $this->last_error = "DISQUS returned a bad response (HTTP ".$response['code'].")";
136
- }
137
- return false;
138
- }
139
- $this->last_error = "DISQUS returned a bad response (HTTP ".$response['code'].")";
140
- return false;
141
- }
142
-
143
- $data = dsq_json_decode($response['data']);
144
-
145
- if (!$data) {
146
- $this->last_error = 'No valid JSON content returned from Disqus';
147
- return false;
148
- }
149
-
150
- if (!$data->succeeded) {
151
- if (!$data->message) {
152
- $this->last_error = '(No error message was received)';
153
- } else {
154
- $this->last_error = $data->message;
155
- }
156
- return false;
157
- }
158
-
159
- $this->last_error = null;
160
-
161
- return $data->message;
162
- }
163
-
164
- /**
165
- * Retrieve the last error message recorded.
166
- *
167
- * @return
168
- * The last recorded error from the API
169
- */
170
- function get_last_error() {
171
- if (empty($this->last_error)) return;
172
- if (!is_string($this->last_error)) {
173
- return var_export($this->last_error);
174
- }
175
- return $this->last_error;
176
- }
177
-
178
- /**
179
- * Validate API key and get username.
180
- *
181
- * @return
182
- * Username matching the API key
183
- */
184
- function get_user_name() {
185
- return $this->call('get_user_name', array(), true);
186
- }
187
-
188
- /**
189
- * Returns an array of hashes representing all forums the user owns.
190
- *
191
- * @return
192
- * An array of hashes representing all forums the user owns.
193
- */
194
- function get_forum_list() {
195
- return $this->call('get_forum_list');
196
- }
197
-
198
- /**
199
- * Get a forum API key for a specific forum.
200
- *
201
- * @param $forum_id
202
- * the unique id of the forum
203
- * @return
204
- * A string which is the Forum Key for the given forum.
205
- */
206
- function get_forum_api_key($forum_id) {
207
- $params = array(
208
- 'forum_id' => $forum_id,
209
- );
210
-
211
- return $this->call('get_forum_api_key', $params);
212
- }
213
-
214
- /**
215
- * Get a list of comments on a website.
216
- *
217
- * Both filter and exclude are multivalue arguments with comma as a divider.
218
- * That makes is possible to use combined requests. For example, if you want
219
- * to get all deleted spam messages, your filter argument should contain
220
- * 'spam,killed' string.
221
- *
222
- * @param $forum_id
223
- * The forum ID.
224
- * @param $params
225
- * - limit: Number of entries that should be included in the response. Default is 25.
226
- * - start: Starting point for the query. Default is 0.
227
- * - filter: Type of entries that should be returned.
228
- * - exclude: Type of entries that should be excluded from the response.
229
- * @return
230
- * Returns posts from a forum specified by id.
231
- */
232
- function get_forum_posts($forum_id, $params=array()) {
233
- $params['forum_id'] = $forum_id;
234
-
235
- return $this->call('get_forum_posts', $params);
236
- }
237
-
238
- /**
239
- * Count a number of comments in articles.
240
- *
241
- * @param $thread_ids
242
- * an array of thread IDs belonging to the given forum.
243
- * @return
244
- * A hash having thread_ids as keys and 2-element arrays as values.
245
- */
246
- function get_num_posts($thread_ids) {
247
- $params = array(
248
- 'thread_ids' => is_array($thread_ids) ? implode(',', $thread_ids) : $thread_ids,
249
- );
250
-
251
- return $this->call('get_num_posts', $params);
252
- }
253
-
254
- /**
255
- * Returns a list of categories that were created for a website (forum) provided.
256
- *
257
- * @param $forum_id
258
- * the unique of the forum
259
- * @return
260
- * A hash containing category_id, title, forum_id, and is_default.
261
- */
262
- function get_categories_list($forum_id) {
263
- $params = array(
264
- 'forum_id' => $forum_id,
265
- );
266
-
267
- return $this->call('get_categories_list', $params);
268
- }
269
-
270
- /**
271
- * Get a list of threads on a website.
272
- *
273
- * @param $forum_id
274
- * the unique id of the forum.
275
- * @param $params
276
- * - limit: Number of entries that should be included in the response. Default is 25.
277
- * - start: Starting point for the query. Default is 0.
278
- * - category_id: Filter entries by category
279
- * @return
280
- * An array of hashes representing all threads belonging to the given forum.
281
- */
282
- function get_thread_list($forum_id, $params=array()) {
283
- $params['forum_id'] = $forum_id;
284
-
285
- return $this->call('get_thread_list', $params);
286
- }
287
-
288
- /**
289
- * Get a list of threads with new comments.
290
- *
291
- * @param $forum_id
292
- * The Forum ID.
293
- * @param $since
294
- * Start date for new posts. Format: 2009-03-30T15:41, Timezone: UTC.
295
- * @return
296
- * An array of hashes representing all threads with new comments since offset.
297
- */
298
- function get_updated_threads($forum_id, $since) {
299
- $params = array(
300
- 'forum_id' => $forum_id,
301
- 'since' => is_string($since) ? $string : strftime('%Y-%m-%dT%H:%M', $since),
302
- );
303
-
304
- return $this->call('get_updated_threads', $params);
305
- }
306
-
307
- /**
308
- * Get a list of comments in a thread.
309
- *
310
- * Both filter and exclude are multivalue arguments with comma as a divider.
311
- * That makes is possible to use combined requests. For example, if you want
312
- * to get all deleted spam messages, your filter argument should contain
313
- * 'spam,killed' string. Note that values are joined by AND statement so
314
- * 'spam,new' will return all messages that are new and marked as spam. It
315
- * will not return messages that are new and not spam or that are spam but
316
- * not new (i.e. has already been moderated).
317
- *
318
- * @param $thread_id
319
- * The ID of a thread belonging to the given forum
320
- * @param $params
321
- * - limit: Number of entries that should be included in the response. Default is 25.
322
- * - start: Starting point for the query. Default is 0.
323
- * - filter: Type of entries that should be returned (new, spam or killed).
324
- * - exclude: Type of entries that should be excluded from the response (new, spam or killed).
325
- * @return
326
- * An array of hashes representing representing all posts belonging to the
327
- * given forum.
328
- */
329
- function get_thread_posts($thread_id, $params=array()) {
330
- $params['thread_id'] = $thread_id;
331
-
332
- return $this->call('get_thread_posts', $params);
333
- }
334
-
335
- /**
336
- * Get or create thread by identifier.
337
- *
338
- * This method tries to find a thread by its identifier and title. If there is
339
- * no such thread, the method creates it. In either case, the output value is
340
- * a thread object.
341
- *
342
- * @param $identifier
343
- * Unique value (per forum) for a thread that is used to keep be able to get
344
- * data even if permalink is changed.
345
- * @param $title
346
- * The title of the thread to possibly be created.
347
- * @param $params
348
- * - category_id: Filter entries by category
349
- * - create_on_fail: if thread does not exist, the method will create it
350
- * @return
351
- * Returns a hash with two keys:
352
- * - thread: a hash representing the thread corresponding to the identifier.
353
- * - created: indicates whether the thread was created as a result of this
354
- * method call. If created, it will have the specified title.
355
- */
356
- function thread_by_identifier($identifier, $title, $params=array()) {
357
- $params['identifier'] = $identifier;
358
- $params['title'] = $title;
359
-
360
- return $this->call('thread_by_identifier', $params, true);
361
- }
362
-
363
- /**
364
- * Get thread by URL.
365
- *
366
- * Finds a thread by its URL. Output value is a thread object.
367
- *
368
- * @param $url
369
- * the URL to check for an associated thread
370
- * @param $partner_api_key
371
- * (optional) The Partner API key.
372
- * @return
373
- * A thread object, otherwise NULL.
374
- */
375
- function get_thread_by_url($url, $partner_api_key=null) {
376
- $params = array(
377
- 'url' => $url,
378
- 'partner_api_key' => $partner_api_key,
379
- );
380
-
381
- return $this->call('get_thread_by_url', $params);
382
- }
383
-
384
- /**
385
- * Updates thread.
386
- *
387
- * Updates thread, specified by id and forum API key, with values described in
388
- * the optional arguments.
389
- *
390
- * @param $thread_id
391
- * the ID of a thread belonging to the given forum
392
- * @param $params
393
- * - title: the title of the thread
394
- * - slug: the per-forum-unique string used for identifying this thread in
395
- * disqus.com URL’s relating to this thread. Composed of
396
- * underscore-separated alphanumeric strings.
397
- * - url: the URL this thread is on, if known.
398
- * - allow_comments: whether this thread is open to new comments
399
- * @return
400
- * Returns an empty success message.
401
- */
402
- function update_thread($thread_id, $params=array()) {
403
- $params['thread_id'] = $thread_id;
404
-
405
- return $this->call('update_thread', $params, true);
406
- }
407
-
408
- /**
409
- * Creates a new post.
410
- *
411
- * Creates a comment to the thread specified by id.
412
- *
413
- * @param $thread_id
414
- * the thread to post to
415
- * @param $message
416
- * the content of the post
417
- * @param $author_name
418
- * the post creator’s name
419
- * @param $author_email
420
- * the post creator’s email address
421
- * @param $params
422
- * - partner_api_key
423
- * - created_at: Format: 2009-03-30T15:41, Timezone: UTC
424
- * - ip_address: the author’s IP address
425
- * - author_url: the author's homepage
426
- * - parent_post: the id of the parent post
427
- * - state: Comment's state, must be one of the following: approved,
428
- * unapproved, spam, killed
429
- * @return
430
- * Returns modified version.
431
- */
432
- function create_post($thread_id, $message, $author_name, $author_email, $params=array()) {
433
- $params['thread_id'] = $thread_id;
434
- $params['message'] = $message;
435
- $params['author_name'] = $author_name;
436
- $params['author_email'] = $author_email;
437
-
438
- return $this->call('create_post', $params, true);
439
- }
440
-
441
- /**
442
- * Delete a comment or mark it as spam (or not spam).
443
- *
444
- * @param $post_id
445
- * The Post ID.
446
- * @param $action
447
- * Name of action to be performed. Value can be 'spam', 'approve' or 'kill'.
448
- * @return
449
- * Returns modified version.
450
- */
451
- function moderate_post($post_id, $action) {
452
- $params = array(
453
- 'post_id' => $post_id,
454
- 'action' => $action,
455
- );
456
-
457
- return $this->call('moderate_post', $params, true);
458
- }
459
- }
460
-
461
- ?>
1
+ <?php
2
+ /**
3
+ * Implementation of the Disqus v1.1 API.
4
+ *
5
+ * http://groups.google.com/group/disqus-dev/web/api-1-1
6
+ *
7
+ * @author Disqus <team@disqus.com>
8
+ * @copyright 2007-2010 Big Head Labs
9
+ * @link http://disqus.com/
10
+ * @package Disqus
11
+ * @version 1.1
12
+ */
13
+
14
+ require_once(dirname(__FILE__) . '/url.php');
15
+
16
+ /** @#+
17
+ * Constants
18
+ */
19
+ /**
20
+ * Base URL for Disqus.
21
+ */
22
+
23
+ define('DISQUS_TYPE_SPAM', 'spam');
24
+ define('DISQUS_TYPE_DELETED', 'killed');
25
+ define('DISQUS_TYPE_KILLED', DISQUS_TYPE_DELETED);
26
+ define('DISQUS_TYPE_NEW', 'new');
27
+
28
+ define('DISQUS_STATE_APPROVED', 'approved');
29
+ define('DISQUS_STATE_UNAPPROVED', 'unapproved');
30
+ define('DISQUS_STATE_SPAM', 'spam');
31
+ define('DISQUS_STATE_DELETED', 'killed');
32
+ define('DISQUS_STATE_KILLED', DISQUS_STATE_DELETED);
33
+
34
+ define('DISQUS_ACTION_SPAM', 'spam');
35
+ define('DISQUS_ACTION_APPROVE', 'approve');
36
+ define('DISQUS_ACTION_DELETE', 'delete');
37
+ define('DISQUS_ACTION_KILL', 'kill');
38
+
39
+ if (!extension_loaded('json')) {
40
+ require_once(dirname(__FILE__) . '/json.php');
41
+ function dsq_json_decode($data) {
42
+ $json = new JSON;
43
+ return $json->unserialize($data);
44
+ }
45
+ } else {
46
+ function dsq_json_decode($data) {
47
+ return json_decode($data);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * Helper methods for all of the Disqus 1.1 API methods.
53
+ *
54
+ * @package Disqus
55
+ * @author DISQUS.com <team@disqus.com>
56
+ * @copyright 2007-2010 Big Head Labs
57
+ * @version 1.1
58
+ */
59
+ class DisqusAPI {
60
+ var $user_api_key;
61
+ var $forum_api_key;
62
+ var $api_url = 'https://www.disqus.com/api/';
63
+ var $api_version = '1.1';
64
+
65
+ /**
66
+ * Creates a new interface to the Disqus API.
67
+ *
68
+ * @param $user_api_key
69
+ * (optional) The User API key to use.
70
+ * @param $forum_api_key
71
+ * (optional) The Forum API key to use.
72
+ * @param $api_url
73
+ * (optional) The prefix URL to use when calling the Disqus API.
74
+ */
75
+ function DisqusAPI($user_api_key, $forum_api_key, $api_url='https://www.disqus.com/api/') {
76
+ $this->user_api_key = $user_api_key;
77
+ $this->forum_api_key = $forum_api_key;
78
+ $this->api_url = $api_url;
79
+ $this->last_error = null;
80
+ }
81
+
82
+ /**
83
+ * Makes a call to a Disqus API method.
84
+ *
85
+ * @return
86
+ * The Disqus object.
87
+ * @param $method
88
+ * The Disqus API method to call.
89
+ * @param $args
90
+ * An associative array of arguments to be passed.
91
+ * @param $post
92
+ * TRUE or FALSE, depending on whether we're making a POST call.
93
+ */
94
+ function call($method, $args=array(), $post=false) {
95
+ $url = $this->api_url . $method . '/';
96
+
97
+ if (!isset($args['user_api_key'])) {
98
+ $args['user_api_key'] = $this->user_api_key;
99
+ }
100
+ if (!isset($args['forum_api_key'])) {
101
+ $args['forum_api_key'] = $this->forum_api_key;
102
+ }
103
+ if (!isset($args['api_version'])) {
104
+ $args['api_version'] = $this->api_version;
105
+ }
106
+
107
+ foreach ($args as $key=>$value) {
108
+ // XXX: Disqus is lacking some exception handling and we sometimes
109
+ // end up with 500s when passing invalid values
110
+ if (empty($value)) unset($args[$key]);
111
+ }
112
+
113
+ if (!$post) {
114
+ $url .= '?' . dsq_get_query_string($args);
115
+ $args = null;
116
+ }
117
+
118
+ if (!($response = dsq_urlopen($url, $args)) || !$response['code']) {
119
+ $this->last_error = 'Unable to connect to the Disqus API servers';
120
+ return false;
121
+ }
122
+
123
+ if ($response['code'] != 200) {
124
+ if ($response['code'] == 500) {
125
+ // Try to grab the exception ID for better reporting
126
+ if (!empty($response['headers']['X-Sentry-ID'])) {
127
+ $this->last_error = 'DISQUS returned a bad response (HTTP '.$response['code'].', ReferenceID: '.$response['headers']['X-Sentry-ID'].')';
128
+ return false;
129
+ }
130
+ } elseif ($response['code'] == 400) {
131
+ $data = dsq_json_decode($response['data']);
132
+ if ($data && $data->message) {
133
+ $this->last_error = $data->message;
134
+ } else {
135
+ $this->last_error = "DISQUS returned a bad response (HTTP ".$response['code'].")";
136
+ }
137
+ return false;
138
+ }
139
+ $this->last_error = "DISQUS returned a bad response (HTTP ".$response['code'].")";
140
+ return false;
141
+ }
142
+
143
+ $data = dsq_json_decode($response['data']);
144
+
145
+ if (!$data) {
146
+ $this->last_error = 'No valid JSON content returned from Disqus';
147
+ return false;
148
+ }
149
+
150
+ if (!$data->succeeded) {
151
+ if (!$data->message) {
152
+ $this->last_error = '(No error message was received)';
153
+ } else {
154
+ $this->last_error = $data->message;
155
+ }
156
+ return false;
157
+ }
158
+
159
+ $this->last_error = null;
160
+
161
+ return $data->message;
162
+ }
163
+
164
+ /**
165
+ * Retrieve the last error message recorded.
166
+ *
167
+ * @return
168
+ * The last recorded error from the API
169
+ */
170
+ function get_last_error() {
171
+ if (empty($this->last_error)) return;
172
+ if (!is_string($this->last_error)) {
173
+ return var_export($this->last_error);
174
+ }
175
+ return $this->last_error;
176
+ }
177
+
178
+ /**
179
+ * Validate API key and get username.
180
+ *
181
+ * @return
182
+ * Username matching the API key
183
+ */
184
+ function get_user_name() {
185
+ return $this->call('get_user_name', array(), true);
186
+ }
187
+
188
+ /**
189
+ * Returns an array of hashes representing all forums the user owns.
190
+ *
191
+ * @return
192
+ * An array of hashes representing all forums the user owns.
193
+ */
194
+ function get_forum_list() {
195
+ return $this->call('get_forum_list');
196
+ }
197
+
198
+ /**
199
+ * Get a forum API key for a specific forum.
200
+ *
201
+ * @param $forum_id
202
+ * the unique id of the forum
203
+ * @return
204
+ * A string which is the Forum Key for the given forum.
205
+ */
206
+ function get_forum_api_key($forum_id) {
207
+ $params = array(
208
+ 'forum_id' => $forum_id,
209
+ );
210
+
211
+ return $this->call('get_forum_api_key', $params);
212
+ }
213
+
214
+ /**
215
+ * Get a list of comments on a website.
216
+ *
217
+ * Both filter and exclude are multivalue arguments with comma as a divider.
218
+ * That makes is possible to use combined requests. For example, if you want
219
+ * to get all deleted spam messages, your filter argument should contain
220
+ * 'spam,killed' string.
221
+ *
222
+ * @param $forum_id
223
+ * The forum ID.
224
+ * @param $params
225
+ * - limit: Number of entries that should be included in the response. Default is 25.
226
+ * - start: Starting point for the query. Default is 0.
227
+ * - filter: Type of entries that should be returned.
228
+ * - exclude: Type of entries that should be excluded from the response.
229
+ * @return
230
+ * Returns posts from a forum specified by id.
231
+ */
232
+ function get_forum_posts($forum_id, $params=array()) {
233
+ $params['forum_id'] = $forum_id;
234
+
235
+ return $this->call('get_forum_posts', $params);
236
+ }
237
+
238
+ /**
239
+ * Count a number of comments in articles.
240
+ *
241
+ * @param $thread_ids
242
+ * an array of thread IDs belonging to the given forum.
243
+ * @return
244
+ * A hash having thread_ids as keys and 2-element arrays as values.
245
+ */
246
+ function get_num_posts($thread_ids) {
247
+ $params = array(
248
+ 'thread_ids' => is_array($thread_ids) ? implode(',', $thread_ids) : $thread_ids,
249
+ );
250
+
251
+ return $this->call('get_num_posts', $params);
252
+ }
253
+
254
+ /**
255
+ * Returns a list of categories that were created for a website (forum) provided.
256
+ *
257
+ * @param $forum_id
258
+ * the unique of the forum
259
+ * @return
260
+ * A hash containing category_id, title, forum_id, and is_default.
261
+ */
262
+ function get_categories_list($forum_id) {
263
+ $params = array(
264
+ 'forum_id' => $forum_id,
265
+ );
266
+
267
+ return $this->call('get_categories_list', $params);
268
+ }
269
+
270
+ /**
271
+ * Get a list of threads on a website.
272
+ *
273
+ * @param $forum_id
274
+ * the unique id of the forum.
275
+ * @param $params
276
+ * - limit: Number of entries that should be included in the response. Default is 25.
277
+ * - start: Starting point for the query. Default is 0.
278
+ * - category_id: Filter entries by category
279
+ * @return
280
+ * An array of hashes representing all threads belonging to the given forum.
281
+ */
282
+ function get_thread_list($forum_id, $params=array()) {
283
+ $params['forum_id'] = $forum_id;
284
+
285
+ return $this->call('get_thread_list', $params);
286
+ }
287
+
288
+ /**
289
+ * Get a list of threads with new comments.
290
+ *
291
+ * @param $forum_id
292
+ * The Forum ID.
293
+ * @param $since
294
+ * Start date for new posts. Format: 2009-03-30T15:41, Timezone: UTC.
295
+ * @return
296
+ * An array of hashes representing all threads with new comments since offset.
297
+ */
298
+ function get_updated_threads($forum_id, $since) {
299
+ $params = array(
300
+ 'forum_id' => $forum_id,
301
+ 'since' => is_string($since) ? $string : strftime('%Y-%m-%dT%H:%M', $since),
302
+ );
303
+
304
+ return $this->call('get_updated_threads', $params);
305
+ }
306
+
307
+ /**
308
+ * Get a list of comments in a thread.
309
+ *
310
+ * Both filter and exclude are multivalue arguments with comma as a divider.
311
+ * That makes is possible to use combined requests. For example, if you want
312
+ * to get all deleted spam messages, your filter argument should contain
313
+ * 'spam,killed' string. Note that values are joined by AND statement so
314
+ * 'spam,new' will return all messages that are new and marked as spam. It
315
+ * will not return messages that are new and not spam or that are spam but
316
+ * not new (i.e. has already been moderated).
317
+ *
318
+ * @param $thread_id
319
+ * The ID of a thread belonging to the given forum
320
+ * @param $params
321
+ * - limit: Number of entries that should be included in the response. Default is 25.
322
+ * - start: Starting point for the query. Default is 0.
323
+ * - filter: Type of entries that should be returned (new, spam or killed).
324
+ * - exclude: Type of entries that should be excluded from the response (new, spam or killed).
325
+ * @return
326
+ * An array of hashes representing representing all posts belonging to the
327
+ * given forum.
328
+ */
329
+ function get_thread_posts($thread_id, $params=array()) {
330
+ $params['thread_id'] = $thread_id;
331
+
332
+ return $this->call('get_thread_posts', $params);
333
+ }
334
+
335
+ /**
336
+ * Get or create thread by identifier.
337
+ *
338
+ * This method tries to find a thread by its identifier and title. If there is
339
+ * no such thread, the method creates it. In either case, the output value is
340
+ * a thread object.
341
+ *
342
+ * @param $identifier
343
+ * Unique value (per forum) for a thread that is used to keep be able to get
344
+ * data even if permalink is changed.
345
+ * @param $title
346
+ * The title of the thread to possibly be created.
347
+ * @param $params
348
+ * - category_id: Filter entries by category
349
+ * - create_on_fail: if thread does not exist, the method will create it
350
+ * @return
351
+ * Returns a hash with two keys:
352
+ * - thread: a hash representing the thread corresponding to the identifier.
353
+ * - created: indicates whether the thread was created as a result of this
354
+ * method call. If created, it will have the specified title.
355
+ */
356
+ function thread_by_identifier($identifier, $title, $params=array()) {
357
+ $params['identifier'] = $identifier;
358
+ $params['title'] = $title;
359
+
360
+ return $this->call('thread_by_identifier', $params, true);
361
+ }
362
+
363
+ /**
364
+ * Get thread by URL.
365
+ *
366
+ * Finds a thread by its URL. Output value is a thread object.
367
+ *
368
+ * @param $url
369
+ * the URL to check for an associated thread
370
+ * @param $partner_api_key
371
+ * (optional) The Partner API key.
372
+ * @return
373
+ * A thread object, otherwise NULL.
374
+ */
375
+ function get_thread_by_url($url, $partner_api_key=null) {
376
+ $params = array(
377
+ 'url' => $url,
378
+ 'partner_api_key' => $partner_api_key,
379
+ );
380
+
381
+ return $this->call('get_thread_by_url', $params);
382
+ }
383
+
384
+ /**
385
+ * Updates thread.
386
+ *
387
+ * Updates thread, specified by id and forum API key, with values described in
388
+ * the optional arguments.
389
+ *
390
+ * @param $thread_id
391
+ * the ID of a thread belonging to the given forum
392
+ * @param $params
393
+ * - title: the title of the thread
394
+ * - slug: the per-forum-unique string used for identifying this thread in
395
+ * disqus.com URL’s relating to this thread. Composed of
396
+ * underscore-separated alphanumeric strings.
397
+ * - url: the URL this thread is on, if known.
398
+ * - allow_comments: whether this thread is open to new comments
399
+ * @return
400
+ * Returns an empty success message.
401
+ */
402
+ function update_thread($thread_id, $params=array()) {
403
+ $params['thread_id'] = $thread_id;
404
+
405
+ return $this->call('update_thread', $params, true);
406
+ }
407
+
408
+ /**
409
+ * Creates a new post.
410
+ *
411
+ * Creates a comment to the thread specified by id.
412
+ *
413
+ * @param $thread_id
414
+ * the thread to post to
415
+ * @param $message
416
+ * the content of the post
417
+ * @param $author_name
418
+ * the post creator’s name
419
+ * @param $author_email
420
+ * the post creator’s email address
421
+ * @param $params
422
+ * - partner_api_key
423
+ * - created_at: Format: 2009-03-30T15:41, Timezone: UTC
424
+ * - ip_address: the author’s IP address
425
+ * - author_url: the author's homepage
426
+ * - parent_post: the id of the parent post
427
+ * - state: Comment's state, must be one of the following: approved,
428
+ * unapproved, spam, killed
429
+ * @return
430
+ * Returns modified version.
431
+ */
432
+ function create_post($thread_id, $message, $author_name, $author_email, $params=array()) {
433
+ $params['thread_id'] = $thread_id;
434
+ $params['message'] = $message;
435
+ $params['author_name'] = $author_name;
436
+ $params['author_email'] = $author_email;
437
+
438
+ return $this->call('create_post', $params, true);
439
+ }
440
+
441
+ /**
442
+ * Delete a comment or mark it as spam (or not spam).
443
+ *
444
+ * @param $post_id
445
+ * The Post ID.
446
+ * @param $action
447
+ * Name of action to be performed. Value can be 'spam', 'approve' or 'kill'.
448
+ * @return
449
+ * Returns modified version.
450
+ */
451
+ function moderate_post($post_id, $action) {
452
+ $params = array(
453
+ 'post_id' => $post_id,
454
+ 'action' => $action,
455
+ );
456
+
457
+ return $this->call('moderate_post', $params, true);
458
+ }
459
+ }
460
+
461
+ ?>
lib/api/disqus/json.php CHANGED
@@ -1,378 +1,378 @@
1
- <?php
2
- /*
3
- ***************************************************************************
4
- * Copyright (C) 2007 by Cesar D. Rodas *
5
- * crodas@phpy.org *
6
- * *
7
- * Permission is hereby granted, free of charge, to any person obtaining *
8
- * a copy of this software and associated documentation files (the *
9
- * "Software"), to deal in the Software without restriction, including *
10
- * without limitation the rights to use, copy, modify, merge, publish, *
11
- * distribute, sublicense, and/or sell copies of the Software, and to *
12
- * permit persons to whom the Software is furnished to do so, subject to *
13
- * the following conditions: *
14
- * *
15
- * The above copyright notice and this permission notice shall be *
16
- * included in all copies or substantial portions of the Software. *
17
- * *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
19
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
21
- * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
22
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
23
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
24
- * OTHER DEALINGS IN THE SOFTWARE. *
25
- ***************************************************************************
26
- */
27
-
28
- /**
29
- * Serialize and Unserialize PHP Objects and array
30
- * into JSON notation.
31
- *
32
- * @category Javascript
33
- * @package JSON
34
- * @author Cesar D. Rodas <crodas@phpy.org>
35
- * @copyright 2007 Cesar D. Rodas
36
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
37
- * @version 1.0
38
- * @link http://cesars.users.phpclasses.org/json
39
- */
40
-
41
- define('IN_NOWHERE',0);
42
- define('IN_STRING',1);
43
- define('IN_OBJECT',2);
44
- define('IN_ATOMIC',3);
45
- define('IN_ASSIGN',4);
46
- define('IN_ENDSTMT',5);
47
- define('IN_ARRAY',6);
48
-
49
- /**
50
- * JSON
51
- *
52
- * This class serilize an PHP OBJECT or an ARRAY into JSON
53
- * notation. Also convert a JSON text into a PHP OBJECT or
54
- * array.
55
- *
56
- * @category Javascript
57
- * @package JSON
58
- * @author Cesar D. Rodas <crodas@phpy.org>
59
- * @copyright 2007 Cesar D. Rodas
60
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61
- * @version 1.0
62
- * @link http://cesars.users.phpclasses.org/json
63
- */
64
- class JSON
65
- {
66
- /**
67
- * Was parsed with an error?
68
- *
69
- * var bool
70
- * @access private
71
- */
72
- var $error;
73
-
74
- function Json() {
75
- $this->error = false;
76
- }
77
-
78
- /**
79
- * Serialize
80
- *
81
- * Serialize a PHP OBJECT or an ARRAY into
82
- * JSON notation.
83
- *
84
- * param mixed $obj Object or array to serialize
85
- * return string JSON.
86
- */
87
- function serialize($obj) {
88
- if ( is_object($obj) ) {
89
- $e = get_object_vars($obj);
90
- /* bug reported by Ben Rowe */
91
- /* Adding default empty array if the */
92
- /* object doesn't have any property */
93
- $properties = array();
94
- foreach ($e as $k => $v) {
95
- $properties[] = $this->_serialize( $k,$v );
96
- }
97
- return "{".implode(",",$properties)."}";
98
- } else if ( is_array($obj) ) {
99
- return $this->_serialize('',$obj);
100
- }
101
- }
102
-
103
- /**
104
- * UnSerialize
105
- *
106
- * Transform an JSON text into a PHP object
107
- * and return it.
108
- * @access public
109
- * @param string $text JSON text
110
- * @return mixed PHP Object, array or false.
111
- */
112
- function unserialize( $text ) {
113
- $this->error = false;
114
-
115
- return !$this->error ? $this->_unserialize($text) : false;
116
- }
117
-
118
- /**
119
- * UnSerialize
120
- *
121
- * Transform an JSON text into a PHP object
122
- * and return it.
123
- * @access private
124
- * @param string $text JSON text
125
- * @return mixed PHP Object, array or false.
126
- */
127
- function _unserialize($text) {
128
- $ret = new stdClass;
129
-
130
- while ( $f = $this->getNextToken($text,$i,$type) ) {
131
- switch ( $type ) {
132
- case IN_ARRAY:
133
- $tmp = $this->_unserializeArray($text);
134
- $ret = $tmp[0];
135
- break;
136
- case IN_OBJECT:
137
- $g=0;
138
- do {
139
- $varName = $this->getNextToken($f,$g,$xType);
140
- if ( $xType != IN_STRING ) {
141
- return false; /* error parsing */
142
- }
143
- $this->getNextToken($f,$g,$xType);
144
- if ( $xType != IN_ASSIGN) return false;
145
- $value = $this->getNextToken($f,$g,$xType);
146
-
147
- if ( $xType == IN_OBJECT) {
148
- $ret->$varName = $this->unserialize( "{".$value."}" );
149
- $g--;
150
- } else if ($xType == IN_ARRAY) {
151
- $ret->$varName = $this->_unserializeArray( $value);
152
- $g--;
153
- } else
154
- $ret->$varName = $value;
155
-
156
- $this->getNextToken($f,$g,$xType);
157
- } while ( $xType == IN_ENDSTMT);
158
- break;
159
- default:
160
- $this->error = true;
161
- break 2;
162
- }
163
- }
164
- return $ret;
165
- }
166
-
167
- /**
168
- * JSON Array Parser
169
- *
170
- * This method transform an json-array into a PHP
171
- * array
172
- * @access private
173
- * @param string $text String to parse
174
- * @return Array PHP Array
175
- */
176
- function _unserializeArray($text) {
177
- $r = array();
178
- do {
179
- $f = $this->getNextToken($text,$i,$type);
180
- switch ( $type ) {
181
- case IN_STRING:
182
- case IN_ATOMIC:
183
- $r[] = $f;
184
- break;
185
- case IN_OBJECT:
186
- $r[] = $this->unserialize("{".$f."}");
187
- $i--;
188
- break;
189
- case IN_ARRAY:
190
- $r[] = $this->_unserializeArray($f);
191
- $i--;
192
- break;
193
-
194
- }
195
- $this->getNextToken($text,$i,$type);
196
- } while ( $type == IN_ENDSTMT);
197
-
198
- return $r;
199
- }
200
-
201
- /**
202
- * Tokenizer
203
- *
204
- * Return to the Parser the next valid token and the type
205
- * of the token. If the tokenizer fails it returns false.
206
- *
207
- * @access private
208
- * @param string $e Text to extract token
209
- * @param integer $i Start position to search next token
210
- * @param integer $state Variable to get the token type
211
- * @return string|bool Token in string or false on error.
212
- */
213
- function getNextToken($e, &$i, &$state) {
214
- $state = IN_NOWHERE;
215
- $end = -1;
216
- $start = -1;
217
- while ( $i < strlen($e) && $end == -1 ) {
218
- switch( $e[$i] ) {
219
- /* objects */
220
- case "{":
221
- case "[":
222
- $_tag = $e[$i];
223
- $_endtag = $_tag == "{" ? "}" : "]";
224
- if ( $state == IN_NOWHERE ) {
225
- $start = $i+1;
226
- switch ($state) {
227
- case IN_NOWHERE:
228
- $aux = 1; /* for loop objects */
229
- $state = $_tag == "{" ? IN_OBJECT : IN_ARRAY;
230
- break;
231
- default:
232
- break 2; /* exit from switch and while */
233
- }
234
- while ( ++$i && $i < strlen($e) && $aux != 0 ) {
235
- switch( $e[$i] ) {
236
- case $_tag:
237
- $aux++;
238
- break;
239
- case $_endtag:
240
- $aux--;
241
- break;
242
- }
243
- }
244
- $end = $i-1;
245
- }
246
- break;
247
-
248
- case '"':
249
- case "'":
250
- $state = IN_STRING;
251
- $buf = "";
252
- while ( ++$i && $i < strlen($e) && $e[$i] != '"' ) {
253
- if ( $e[$i] == "\\")
254
- $i++;
255
- $buf .= $e[$i];
256
- }
257
- $i++;
258
- return $buf;
259
- break;
260
- case ":":
261
- $state = IN_ASSIGN;
262
- $end = 1;
263
- break;
264
- case "n":
265
- if ( substr($e,$i,4) == "null" ) {
266
- $i=$i+4;
267
- $state = IN_ATOMIC;
268
- return NULL;
269
- }
270
- else break 2; /* exit from switch and while */
271
- case "t":
272
- if ( substr($e,$i,4) == "true") {
273
- $state = IN_ATOMIC;
274
- $i=$i+4;
275
- return true;
276
- }
277
- else break 2; /* exit from switch and while */
278
- break;
279
- case "f":
280
- if ( substr($e,$i,5) == "false") {
281
- $state = IN_ATOMIC;
282
- $i=$i+5;
283
- return false;
284
- }
285
- else break 2; /* exit from switch and while */
286
- break;
287
- case ",":
288
- $state = IN_ENDSTMT;
289
- $end = 1;
290
- break;
291
- case " ":
292
- case "\t":
293
- case "\r":
294
- case "\n":
295
- break;
296
- case "+":
297
- case "-":
298
- case 0:
299
- case 1:
300
- case 2:
301
- case 3:
302
- case 4:
303
- case 5:
304
- case 6:
305
- case 7:
306
- case 8:
307
- case 9:
308
- case '.':
309
- $state = IN_ATOMIC;
310
- $start = (int)$i;
311
- if ( $e[$i] == "-" || $e[$i] == "+")
312
- $i++;
313
- for ( ; $i < strlen($e) && (is_numeric($e[$i]) || $e[$i] == "." || strtolower($e[$i]) == "e") ;$i++){
314
- $n = $i+1 < strlen($e) ? $e[$i+1] : "";
315
- $a = strtolower($e[$i]);
316
- if ( $a == "e" && ($n == "+" || $n == "-"))
317
- $i++;
318
- else if ( $a == "e")
319
- $this->error=true;
320
- }
321
-
322
- $end = $i;
323
- break 2; /* break while too */
324
- default:
325
- $this->error = true;
326
-
327
- }
328
- $i++;
329
- }
330
-
331
- return $start == -1 || $end == -1 ? false : substr($e, $start, $end - $start);
332
- }
333
-
334
- /**
335
- * Internal Serializer
336
- *
337
- * @param string $key Variable name
338
- * @param mixed $value Value of the variable
339
- * @access private
340
- * @return string Serialized variable
341
- */
342
- function _serialize ( $key = '', &$value ) {
343
- $r = '';
344
- if ( $key != '')$r .= "\"${key}\" : ";
345
- if ( is_numeric($value) ) {
346
- $r .= ''.$value.'';
347
- } else if ( is_string($value) ) {
348
- $r .= '"'.$this->toString($value).'"';
349
- } else if ( is_object($value) ) {
350
- $r .= $this->serialize($value);
351
- } else if ( is_null($value) ) {
352
- $r .= "null";
353
- } else if ( is_bool($value) ) {
354
- $r .= $value ? "true":"false";
355
- } else if ( is_array($value) ) {
356
- foreach($value as $k => $v)
357
- $f[] = $this->_serialize('',$v);
358
- $r .= "[".implode(",",$f)."]";
359
- unset($f);
360
- }
361
- return $r;
362
- }
363
-
364
- /**
365
- * Convert String variables
366
- *
367
- * @param string $e Variable with an string value
368
- * @access private
369
- * @return string Serialized variable
370
- */
371
- function toString($e) {
372
- $rep = array("\\","\r","\n","\t","'",'"');
373
- $val = array("\\\\",'\r','\n','\t','\'','\"');
374
- $e = str_replace($rep, $val, $e);
375
- return $e;
376
- }
377
- }
378
  ?>
1
+ <?php
2
+ /*
3
+ ***************************************************************************
4
+ * Copyright (C) 2007 by Cesar D. Rodas *
5
+ * crodas@phpy.org *
6
+ * *
7
+ * Permission is hereby granted, free of charge, to any person obtaining *
8
+ * a copy of this software and associated documentation files (the *
9
+ * "Software"), to deal in the Software without restriction, including *
10
+ * without limitation the rights to use, copy, modify, merge, publish, *
11
+ * distribute, sublicense, and/or sell copies of the Software, and to *
12
+ * permit persons to whom the Software is furnished to do so, subject to *
13
+ * the following conditions: *
14
+ * *
15
+ * The above copyright notice and this permission notice shall be *
16
+ * included in all copies or substantial portions of the Software. *
17
+ * *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
19
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
21
+ * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
22
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
23
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
24
+ * OTHER DEALINGS IN THE SOFTWARE. *
25
+ ***************************************************************************
26
+ */
27
+
28
+ /**
29
+ * Serialize and Unserialize PHP Objects and array
30
+ * into JSON notation.
31
+ *
32
+ * @category Javascript
33
+ * @package JSON
34
+ * @author Cesar D. Rodas <crodas@phpy.org>
35
+ * @copyright 2007 Cesar D. Rodas
36
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
37
+ * @version 1.0
38
+ * @link http://cesars.users.phpclasses.org/json
39
+ */
40
+
41
+ define('IN_NOWHERE',0);
42
+ define('IN_STRING',1);
43
+ define('IN_OBJECT',2);
44
+ define('IN_ATOMIC',3);
45
+ define('IN_ASSIGN',4);
46
+ define('IN_ENDSTMT',5);
47
+ define('IN_ARRAY',6);
48
+
49
+ /**
50
+ * JSON
51
+ *
52
+ * This class serilize an PHP OBJECT or an ARRAY into JSON
53
+ * notation. Also convert a JSON text into a PHP OBJECT or
54
+ * array.
55
+ *
56
+ * @category Javascript
57
+ * @package JSON
58
+ * @author Cesar D. Rodas <crodas@phpy.org>
59
+ * @copyright 2007 Cesar D. Rodas
60
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
61
+ * @version 1.0
62
+ * @link http://cesars.users.phpclasses.org/json
63
+ */
64
+ class JSON
65
+ {
66
+ /**
67
+ * Was parsed with an error?
68
+ *
69
+ * var bool
70
+ * @access private
71
+ */
72
+ var $error;
73
+
74
+ function Json() {
75
+ $this->error = false;
76
+ }
77
+
78
+ /**
79
+ * Serialize
80
+ *
81
+ * Serialize a PHP OBJECT or an ARRAY into
82
+ * JSON notation.
83
+ *
84
+ * param mixed $obj Object or array to serialize
85
+ * return string JSON.
86
+ */
87
+ function serialize($obj) {
88
+ if ( is_object($obj) ) {
89
+ $e = get_object_vars($obj);
90
+ /* bug reported by Ben Rowe */
91
+ /* Adding default empty array if the */
92
+ /* object doesn't have any property */
93
+ $properties = array();
94
+ foreach ($e as $k => $v) {
95
+ $properties[] = $this->_serialize( $k,$v );
96
+ }
97
+ return "{".implode(",",$properties)."}";
98
+ } else if ( is_array($obj) ) {
99
+ return $this->_serialize('',$obj);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * UnSerialize
105
+ *
106
+ * Transform an JSON text into a PHP object
107
+ * and return it.
108
+ * @access public
109
+ * @param string $text JSON text
110
+ * @return mixed PHP Object, array or false.
111
+ */
112
+ function unserialize( $text ) {
113
+ $this->error = false;
114
+
115
+ return !$this->error ? $this->_unserialize($text) : false;
116
+ }
117
+
118
+ /**
119
+ * UnSerialize
120
+ *
121
+ * Transform an JSON text into a PHP object
122
+ * and return it.
123
+ * @access private
124
+ * @param string $text JSON text
125
+ * @return mixed PHP Object, array or false.
126
+ */
127
+ function _unserialize($text) {
128
+ $ret = new stdClass;
129
+
130
+ while ( $f = $this->getNextToken($text,$i,$type) ) {
131
+ switch ( $type ) {
132
+ case IN_ARRAY:
133
+ $tmp = $this->_unserializeArray($text);
134
+ $ret = $tmp[0];
135
+ break;
136
+ case IN_OBJECT:
137
+ $g=0;
138
+ do {
139
+ $varName = $this->getNextToken($f,$g,$xType);
140
+ if ( $xType != IN_STRING ) {
141
+ return false; /* error parsing */
142
+ }
143
+ $this->getNextToken($f,$g,$xType);
144
+ if ( $xType != IN_ASSIGN) return false;
145
+ $value = $this->getNextToken($f,$g,$xType);
146
+
147
+ if ( $xType == IN_OBJECT) {
148
+ $ret->$varName = $this->unserialize( "{".$value."}" );
149
+ $g--;
150
+ } else if ($xType == IN_ARRAY) {
151
+ $ret->$varName = $this->_unserializeArray( $value);
152
+ $g--;
153
+ } else
154
+ $ret->$varName = $value;
155
+
156
+ $this->getNextToken($f,$g,$xType);
157
+ } while ( $xType == IN_ENDSTMT);
158
+ break;
159
+ default:
160
+ $this->error = true;
161
+ break 2;
162
+ }
163
+ }
164
+ return $ret;
165
+ }
166
+
167
+ /**
168
+ * JSON Array Parser
169
+ *
170
+ * This method transform an json-array into a PHP
171
+ * array
172
+ * @access private
173
+ * @param string $text String to parse
174
+ * @return Array PHP Array
175
+ */
176
+ function _unserializeArray($text) {
177
+ $r = array();
178
+ do {
179
+ $f = $this->getNextToken($text,$i,$type);
180
+ switch ( $type ) {
181
+ case IN_STRING:
182
+ case IN_ATOMIC:
183
+ $r[] = $f;
184
+ break;
185
+ case IN_OBJECT:
186
+ $r[] = $this->unserialize("{".$f."}");
187
+ $i--;
188
+ break;
189
+ case IN_ARRAY:
190
+ $r[] = $this->_unserializeArray($f);
191
+ $i--;
192
+ break;
193
+
194
+ }
195
+ $this->getNextToken($text,$i,$type);
196
+ } while ( $type == IN_ENDSTMT);
197
+
198
+ return $r;
199
+ }
200
+
201
+ /**
202
+ * Tokenizer
203
+ *
204
+ * Return to the Parser the next valid token and the type
205
+ * of the token. If the tokenizer fails it returns false.
206
+ *
207
+ * @access private
208
+ * @param string $e Text to extract token
209
+ * @param integer $i Start position to search next token
210
+ * @param integer $state Variable to get the token type
211
+ * @return string|bool Token in string or false on error.
212
+ */
213
+ function getNextToken($e, &$i, &$state) {
214
+ $state = IN_NOWHERE;
215
+ $end = -1;
216
+ $start = -1;
217
+ while ( $i < strlen($e) && $end == -1 ) {
218
+ switch( $e[$i] ) {
219
+ /* objects */
220
+ case "{":
221
+ case "[":
222
+ $_tag = $e[$i];
223
+ $_endtag = $_tag == "{" ? "}" : "]";
224
+ if ( $state == IN_NOWHERE ) {
225
+ $start = $i+1;
226
+ switch ($state) {
227
+ case IN_NOWHERE:
228
+ $aux = 1; /* for loop objects */
229
+ $state = $_tag == "{" ? IN_OBJECT : IN_ARRAY;
230
+ break;
231
+ default:
232
+ break 2; /* exit from switch and while */
233
+ }
234
+ while ( ++$i && $i < strlen($e) && $aux != 0 ) {
235
+ switch( $e[$i] ) {
236
+ case $_tag:
237
+ $aux++;
238
+ break;
239
+ case $_endtag:
240
+ $aux--;
241
+ break;
242
+ }
243
+ }
244
+ $end = $i-1;
245
+ }
246
+ break;
247
+
248
+ case '"':
249
+ case "'":
250
+ $state = IN_STRING;
251
+ $buf = "";
252
+ while ( ++$i && $i < strlen($e) && $e[$i] != '"' ) {
253
+ if ( $e[$i] == "\\")
254
+ $i++;
255
+ $buf .= $e[$i];
256
+ }
257
+ $i++;
258
+ return $buf;
259
+ break;
260
+ case ":":
261
+ $state = IN_ASSIGN;
262
+ $end = 1;
263
+ break;
264
+ case "n":
265
+ if ( substr($e,$i,4) == "null" ) {
266
+ $i=$i+4;
267
+ $state = IN_ATOMIC;
268
+ return NULL;
269
+ }
270
+ else break 2; /* exit from switch and while */
271
+ case "t":
272
+ if ( substr($e,$i,4) == "true") {
273
+ $state = IN_ATOMIC;
274
+ $i=$i+4;
275
+ return true;
276
+ }
277
+ else break 2; /* exit from switch and while */
278
+ break;
279
+ case "f":
280
+ if ( substr($e,$i,5) == "false") {
281
+ $state = IN_ATOMIC;
282
+ $i=$i+5;
283
+ return false;
284
+ }
285
+ else break 2; /* exit from switch and while */
286
+ break;
287
+ case ",":
288
+ $state = IN_ENDSTMT;
289
+ $end = 1;
290
+ break;
291
+ case " ":
292
+ case "\t":
293
+ case "\r":
294
+ case "\n":
295
+ break;
296
+ case "+":
297
+ case "-":
298
+ case 0:
299
+ case 1:
300
+ case 2:
301
+ case 3:
302
+ case 4:
303
+ case 5:
304
+ case 6:
305
+ case 7:
306
+ case 8:
307
+ case 9:
308
+ case '.':
309
+ $state = IN_ATOMIC;
310
+ $start = (int)$i;
311
+ if ( $e[$i] == "-" || $e[$i] == "+")
312
+ $i++;
313
+ for ( ; $i < strlen($e) && (is_numeric($e[$i]) || $e[$i] == "." || strtolower($e[$i]) == "e") ;$i++){
314
+ $n = $i+1 < strlen($e) ? $e[$i+1] : "";
315
+ $a = strtolower($e[$i]);
316
+ if ( $a == "e" && ($n == "+" || $n == "-"))
317
+ $i++;
318
+ else if ( $a == "e")
319
+ $this->error=true;
320
+ }
321
+
322
+ $end = $i;
323
+ break 2; /* break while too */
324
+ default:
325
+ $this->error = true;
326
+
327
+ }
328
+ $i++;
329
+ }
330
+
331
+ return $start == -1 || $end == -1 ? false : substr($e, $start, $end - $start);
332
+ }
333
+
334
+ /**
335
+ * Internal Serializer
336
+ *
337
+ * @param string $key Variable name
338
+ * @param mixed $value Value of the variable
339
+ * @access private
340
+ * @return string Serialized variable
341
+ */
342
+ function _serialize ( $key = '', &$value ) {
343
+ $r = '';
344
+ if ( $key != '')$r .= "\"${key}\" : ";
345
+ if ( is_numeric($value) ) {
346
+ $r .= ''.$value.'';
347
+ } else if ( is_string($value) ) {
348
+ $r .= '"'.$this->toString($value).'"';
349
+ } else if ( is_object($value) ) {
350
+ $r .= $this->serialize($value);
351
+ } else if ( is_null($value) ) {
352
+ $r .= "null";
353
+ } else if ( is_bool($value) ) {
354
+ $r .= $value ? "true":"false";
355
+ } else if ( is_array($value) ) {
356
+ foreach($value as $k => $v)
357
+ $f[] = $this->_serialize('',$v);
358
+ $r .= "[".implode(",",$f)."]";
359
+ unset($f);
360
+ }
361
+ return $r;
362
+ }
363
+
364
+ /**
365
+ * Convert String variables
366
+ *
367
+ * @param string $e Variable with an string value
368
+ * @access private
369
+ * @return string Serialized variable
370
+ */
371
+ function toString($e) {
372
+ $rep = array("\\","\r","\n","\t","'",'"');
373
+ $val = array("\\\\",'\r','\n','\t','\'','\"');
374
+ $e = str_replace($rep, $val, $e);
375
+ return $e;
376
+ }
377
+ }
378
  ?>
lib/api/disqus/url.php CHANGED
@@ -1,295 +1,295 @@
1
- <?php
2
- define('USER_AGENT', 'Disqus-WPPlugin/2.0-dev');
3
- define('SOCKET_TIMEOUT', 10);
4
-
5
- function dsq_get_query_string($postdata) {
6
- $postdata_str = '';
7
-
8
- if($postdata) {
9
- foreach($postdata as $key=>$value) {
10
- $postdata_str .= urlencode($key) . '=' . urlencode($value) . '&';
11
- }
12
- }
13
-
14
- return $postdata_str;
15
- }
16
-
17
-
18
- function dsq_get_post_content($boundary, $postdata, $file_name, $file_field) {
19
- if(empty($file_name) || empty($file_field)) {
20
- return dsq_get_query_string($postdata);
21
- }
22
-
23
- $content = array();
24
- $content[] = '--' . $boundary;
25
- foreach($postdata as $key=>$value) {
26
- $content[] = 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n" . $value;
27
- $content[] = '--' . $boundary;
28
- }
29
- $content[] = 'Content-Disposition: form-data; name="' . $file_field . '"; filename="' . $file_name . '"';
30
- // HACK: We only need to handle text/plain files right now.
31
- $content[] = "Content-Type: text/plain\r\n";
32
- $content[] = file_get_contents($file_name);
33
- $content[] = '--' . $boundary . '--';
34
- $content = implode("\r\n", $content);
35
- return $content;
36
- }
37
-
38
-
39
- function dsq_get_http_headers_for_request($boundary, $content, $file_name, $file_field) {
40
- $headers = array();
41
- $headers[] = 'User-Agent: ' . USER_AGENT;
42
- $headers[] = 'Connection: close';
43
- if($content) {
44
- $headers[] = 'Content-Length: ' . strlen($content);
45
- if($file_name && $file_field) {
46
- $headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
47
- } else {
48
- $headers[] = 'Content-Type: application/x-www-form-urlencoded';
49
- }
50
- }
51
- return implode("\r\n", $headers);
52
- }
53
-
54
-
55
- function _dsq_curl_urlopen($url, $postdata, &$response, $file_name, $file_field) {
56
- $c = curl_init($url);
57
- $postdata_str = dsq_get_query_string($postdata);
58
-
59
- $c_options = array(
60
- CURLOPT_USERAGENT => USER_AGENT,
61
- CURLOPT_RETURNTRANSFER => true,
62
- CURLOPT_POST => ($postdata_str ? 1 : 0),
63
- CURLOPT_HEADER => true,
64
- CURLOPT_HTTPHEADER => array('Expect:'),
65
- CURLOPT_TIMEOUT => SOCKET_TIMEOUT
66
- );
67
- if($postdata) {
68
- $c_options[CURLOPT_POSTFIELDS] = $postdata_str;
69
- }
70
- if($file_name && $file_field) {
71
- $postdata[$file_field] = '@' . $file_name;
72
- $c_options[CURLOPT_POSTFIELDS] = $postdata;
73
- $c_options[CURLOPT_RETURNTRANSFER] = 1;
74
- }
75
- curl_setopt_array($c, $c_options);
76
-
77
- $data = curl_exec($c);
78
- list($headers, $response['data']) = explode("\r\n\r\n", $data, 2);
79
-
80
- $response['headers'] = _dsq_get_response_headers($headers, $response);
81
- $response['code'] = curl_getinfo($c, CURLINFO_HTTP_CODE);
82
- }
83
-
84
- function _dsq_get_response_headers($headers, &$response) {
85
- $headers = explode("\r\n", $headers);
86
- list($unused, $response['code'], $unused) = explode(' ', $headers[0], 3);
87
- $headers = array_slice($headers, 1);
88
-
89
- // Convert headers into associative array.
90
- foreach($headers as $unused=>$header) {
91
- $header = explode(':', $header);
92
- $header[0] = trim($header[0]);
93
- $header[1] = trim($header[1]);
94
- $headers[strtolower($header[0])] = $header[1];
95
- }
96
-
97
- return $headers;
98
- }
99
-
100
- function _dsq_fsockopen_urlopen($url, $postdata, &$response, $file_name, $file_field) {
101
- $buf = '';
102
- $req = '';
103
- $length = 0;
104
- $boundary = '----------' . md5(time());
105
- $postdata_str = dsq_get_post_content($boundary, $postdata, $file_name, $file_field);
106
- $url_pieces = parse_url($url);
107
-
108
- // Set default port for supported schemes if none is provided.
109
- if(!isset($url_pieces['port'])) {
110
- switch($url_pieces['scheme']) {
111
- case 'http':
112
- $url_pieces['port'] = 80;
113
- break;
114
- case 'https':
115
- $url_pieces['port'] = 443;
116
- $url_pieces['host'] = 'ssl://' . $url_pieces['host'];
117
- break;
118
- }
119
- }
120
-
121
- // Set default path if trailing slash is not provided.
122
- if(!isset($url_pieces['path'])) { $url_pieces['path'] = '/'; }
123
-
124
- // Determine if we need to include the port in the Host header or not.
125
- if(($url_pieces['port'] == 80 && $url_pieces['scheme'] == 'http') ||
126
- ($url_pieces['port'] == 443 && $url_pieces['scheme'] == 'https')) {
127
- $host = $url_pieces['host'];
128
- } else {
129
- $host = $url_pieces['host'] . ':' . $url_pieces['port'];
130
- }
131
-
132
- $fp = @fsockopen($url_pieces['host'], $url_pieces['port'], $errno, $errstr, SOCKET_TIMEOUT);
133
- if(!$fp) { return false; }
134
-
135
- $path = $url_pieces['path'];
136
- if ($url_pieces['query']) $path .= '?'.$url_pieces['query'];
137
-
138
- $req .= ($postdata_str ? 'POST' : 'GET') . ' ' . $path . " HTTP/1.1\r\n";
139
- $req .= 'Host: ' . $host . "\r\n";
140
- $req .= dsq_get_http_headers_for_request($boundary, $postdata_str, $file_name, $file_field);
141
- if($postdata_str) {
142
- $req .= "\r\n\r\n" . $postdata_str;
143
- }
144
- $req .= "\r\n\r\n";
145
-
146
- fwrite($fp, $req);
147
- while(!feof($fp)) {
148
- $buf .= fgets($fp, 4096);
149
- }
150
-
151
- // Parse headers from the response buffers.
152
- list($headers, $response['data']) = explode("\r\n\r\n", $buf, 2);
153
-
154
- // Get status code from headers.
155
- $headers = _dsq_get_response_headers($headers, $response);
156
-
157
- // If transfer-coding is set to chunked, we need to join the message body
158
- // together.
159
- if(isset($headers['transfer-encoding']) && 'chunked' == strtolower($headers['transfer-encoding'])) {
160
- $chunk_data = $response['data'];
161
- $joined_data = '';
162
- while(true) {
163
- // Strip length from body.
164
- list($chunk_length, $chunk_data) = explode("\r\n", $chunk_data, 2);
165
- $chunk_length = hexdec($chunk_length);
166
- if(!$chunk_length || !strlen($chunk_data)) { break; }
167
-
168
- $joined_data .= substr($chunk_data, 0, $chunk_length);
169
- $chunk_data = substr($chunk_data, $chunk_length + 1);
170
- $length += $chunk_length;
171
- }
172
- $response['data'] = $joined_data;
173
- } else {
174
- $length = $headers['content-length'];
175
- }
176
- $response['headers'] = $headers;
177
- }
178
-
179
-
180
- function _dsq_fopen_urlopen($url, $postdata, &$response, $file_name, $file_field) {
181
- $params = array();
182
- if($file_name && $file_field) {
183
- $boundary = '----------' . md5(time());
184
- $content = dsq_get_post_content($boundary, $postdata, $file_name, $file_field);
185
- $header = dsq_get_http_headers_for_request($boundary, $content, $file_name, $file_field);
186
-
187
- $params = array('http' => array(
188
- 'method' => 'POST',
189
- 'header' => $header,
190
- 'content' => $content,
191
- 'timeout' => SOCKET_TIMEOUT
192
- ));
193
- } else {
194
- if($postdata) {
195
- $params = array('http' => array(
196
- 'method' => 'POST',
197
- 'header' => 'Content-Type: application/x-www-form-urlencoded',
198
- 'content' => dsq_get_query_string($postdata),
199
- 'timeout' => SOCKET_TIMEOUT
200
- ));
201
- }
202
- }
203
-
204
-
205
- ini_set('user_agent', USER_AGENT);
206
- $ctx = stream_context_create($params);
207
- $fp = fopen($url, 'rb', false, $ctx);
208
- if(!$fp) {
209
- return false;
210
- }
211
-
212
- // Get status code from headers.
213
- list($unused, $response['code'], $unused) = explode(' ', $http_response_header[0], 3);
214
- $headers = array_slice($http_response_header, 1);
215
-
216
- // Convert headers into associative array.
217
- foreach($headers as $unused=>$header) {
218
- $header = explode(':', $header);
219
- $header[0] = trim($header[0]);
220
- $header[1] = trim($header[1]);
221
- $headers[strtolower($header[0])] = strtolower($header[1]);
222
- }
223
-
224
- $response['data'] = stream_get_contents($fp);
225
- $response['headers'] = $headers;
226
- }
227
-
228
-
229
- /**
230
- * Wrapper to provide a single interface for making an HTTP request.
231
- *
232
- * Attempts to use cURL, fopen(), or fsockopen(), whichever is available
233
- * first.
234
- *
235
- * @param string $url URL to make request to.
236
- * @param array $postdata (optional) If postdata is provided, the request
237
- * method is POST with the key/value pairs as
238
- * the data.
239
- * @param array $file (optional) Should provide associative array
240
- * with two keys: name and field. Name should
241
- * be the name of the file and field is the name
242
- * of the field to POST.
243
- */
244
- function dsq_urlopen($url, $postdata=false, $file=false) {
245
- $response = array(
246
- 'data' => '',
247
- 'code' => 0
248
- );
249
-
250
- if($file) {
251
- extract($file, EXTR_PREFIX_ALL, 'file');
252
- }
253
- if(empty($file_name) || empty($file_field)) {
254
- $file_name = false;
255
- $file_field = false;
256
- }
257
-
258
- //
259
-
260
- // Try curl, fsockopen, fopen + stream (PHP5 only), exec wget
261
- if(function_exists('curl_init')) {
262
- if (!function_exists('curl_setopt_array')) {
263
- function curl_setopt_array(&$ch, $curl_options)
264
- {
265
- foreach ($curl_options as $option => $value) {
266
- if (!curl_setopt($ch, $option, $value)) {
267
- return false;
268
- }
269
- }
270
- return true;
271
- }
272
- }
273
- _dsq_curl_urlopen($url, $postdata, $response, $file_name, $file_field);
274
- } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
275
- _dsq_fopen_urlopen($url, $postdata, $response, $file_name, $file_field);
276
- } else {
277
- // TODO: Find the failure condition for fsockopen() (sockets?)
278
- _dsq_fsockopen_urlopen($url, $postdata, $response, $file_name, $file_field);
279
- }
280
-
281
- // returns array with keys data and code (from headers)
282
-
283
- return $response;
284
- }
285
-
286
- function dsq_url_method() {
287
- if(function_exists('curl_init')) {
288
- return 'curl';
289
- } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
290
- return 'fopen';
291
- } else {
292
- return 'fsockopen';
293
- }
294
- }
295
- ?>
1
+ <?php
2
+ define('USER_AGENT', 'Disqus-WPPlugin/2.0-dev');
3
+ define('SOCKET_TIMEOUT', 10);
4
+
5
+ function dsq_get_query_string($postdata) {
6
+ $postdata_str = '';
7
+
8
+ if($postdata) {
9
+ foreach($postdata as $key=>$value) {
10
+ $postdata_str .= urlencode($key) . '=' . urlencode($value) . '&';
11
+ }
12
+ }
13
+
14
+ return $postdata_str;
15
+ }
16
+
17
+
18
+ function dsq_get_post_content($boundary, $postdata, $file_name, $file_field) {
19
+ if(empty($file_name) || empty($file_field)) {
20
+ return dsq_get_query_string($postdata);
21
+ }
22
+
23
+ $content = array();
24
+ $content[] = '--' . $boundary;
25
+ foreach($postdata as $key=>$value) {
26
+ $content[] = 'Content-Disposition: form-data; name="' . $key . '"' . "\r\n\r\n" . $value;
27
+ $content[] = '--' . $boundary;
28
+ }
29
+ $content[] = 'Content-Disposition: form-data; name="' . $file_field . '"; filename="' . $file_name . '"';
30
+ // HACK: We only need to handle text/plain files right now.
31
+ $content[] = "Content-Type: text/plain\r\n";
32
+ $content[] = file_get_contents($file_name);
33
+ $content[] = '--' . $boundary . '--';
34
+ $content = implode("\r\n", $content);
35
+ return $content;
36
+ }
37
+
38
+
39
+ function dsq_get_http_headers_for_request($boundary, $content, $file_name, $file_field) {
40
+ $headers = array();
41
+ $headers[] = 'User-Agent: ' . USER_AGENT;
42
+ $headers[] = 'Connection: close';
43
+ if($content) {
44
+ $headers[] = 'Content-Length: ' . strlen($content);
45
+ if($file_name && $file_field) {
46
+ $headers[] = 'Content-Type: multipart/form-data; boundary=' . $boundary;
47
+ } else {
48
+ $headers[] = 'Content-Type: application/x-www-form-urlencoded';
49
+ }
50
+ }
51
+ return implode("\r\n", $headers);
52
+ }
53
+
54
+
55
+ function _dsq_curl_urlopen($url, $postdata, &$response, $file_name, $file_field) {
56
+ $c = curl_init($url);
57
+ $postdata_str = dsq_get_query_string($postdata);
58
+
59
+ $c_options = array(
60
+ CURLOPT_USERAGENT => USER_AGENT,
61
+ CURLOPT_RETURNTRANSFER => true,
62
+ CURLOPT_POST => ($postdata_str ? 1 : 0),
63
+ CURLOPT_HEADER => true,
64
+ CURLOPT_HTTPHEADER => array('Expect:'),
65
+ CURLOPT_TIMEOUT => SOCKET_TIMEOUT
66
+ );
67
+ if($postdata) {
68
+ $c_options[CURLOPT_POSTFIELDS] = $postdata_str;
69
+ }
70
+ if($file_name && $file_field) {
71
+ $postdata[$file_field] = '@' . $file_name;
72
+ $c_options[CURLOPT_POSTFIELDS] = $postdata;
73
+ $c_options[CURLOPT_RETURNTRANSFER] = 1;
74
+ }
75
+ curl_setopt_array($c, $c_options);
76
+
77
+ $data = curl_exec($c);
78
+ list($headers, $response['data']) = explode("\r\n\r\n", $data, 2);
79
+
80
+ $response['headers'] = _dsq_get_response_headers($headers, $response);
81
+ $response['code'] = curl_getinfo($c, CURLINFO_HTTP_CODE);
82
+ }
83
+
84
+ function _dsq_get_response_headers($headers, &$response) {
85
+ $headers = explode("\r\n", $headers);
86
+ list($unused, $response['code'], $unused) = explode(' ', $headers[0], 3);
87
+ $headers = array_slice($headers, 1);
88
+
89
+ // Convert headers into associative array.
90
+ foreach($headers as $unused=>$header) {
91
+ $header = explode(':', $header);
92
+ $header[0] = trim($header[0]);
93
+ $header[1] = trim($header[1]);
94
+ $headers[strtolower($header[0])] = $header[1];
95
+ }
96
+
97
+ return $headers;
98
+ }
99
+
100
+ function _dsq_fsockopen_urlopen($url, $postdata, &$response, $file_name, $file_field) {
101
+ $buf = '';
102
+ $req = '';
103
+ $length = 0;
104
+ $boundary = '----------' . md5(time());
105
+ $postdata_str = dsq_get_post_content($boundary, $postdata, $file_name, $file_field);
106
+ $url_pieces = parse_url($url);
107
+
108
+ // Set default port for supported schemes if none is provided.
109
+ if(!isset($url_pieces['port'])) {
110
+ switch($url_pieces['scheme']) {
111
+ case 'http':
112
+ $url_pieces['port'] = 80;
113
+ break;
114
+ case 'https':
115
+ $url_pieces['port'] = 443;
116
+ $url_pieces['host'] = 'ssl://' . $url_pieces['host'];
117
+ break;
118
+ }
119
+ }
120
+
121
+ // Set default path if trailing slash is not provided.
122
+ if(!isset($url_pieces['path'])) { $url_pieces['path'] = '/'; }
123
+
124
+ // Determine if we need to include the port in the Host header or not.
125
+ if(($url_pieces['port'] == 80 && $url_pieces['scheme'] == 'http') ||
126
+ ($url_pieces['port'] == 443 && $url_pieces['scheme'] == 'https')) {
127
+ $host = $url_pieces['host'];
128
+ } else {
129
+ $host = $url_pieces['host'] . ':' . $url_pieces['port'];
130
+ }
131
+
132
+ $fp = @fsockopen($url_pieces['host'], $url_pieces['port'], $errno, $errstr, SOCKET_TIMEOUT);
133
+ if(!$fp) { return false; }
134
+
135
+ $path = $url_pieces['path'];
136
+ if ($url_pieces['query']) $path .= '?'.$url_pieces['query'];
137
+
138
+ $req .= ($postdata_str ? 'POST' : 'GET') . ' ' . $path . " HTTP/1.1\r\n";
139
+ $req .= 'Host: ' . $host . "\r\n";
140
+ $req .= dsq_get_http_headers_for_request($boundary, $postdata_str, $file_name, $file_field);
141
+ if($postdata_str) {
142
+ $req .= "\r\n\r\n" . $postdata_str;
143
+ }
144
+ $req .= "\r\n\r\n";
145
+
146
+ fwrite($fp, $req);
147
+ while(!feof($fp)) {
148
+ $buf .= fgets($fp, 4096);
149
+ }
150
+
151
+ // Parse headers from the response buffers.
152
+ list($headers, $response['data']) = explode("\r\n\r\n", $buf, 2);
153
+
154
+ // Get status code from headers.
155
+ $headers = _dsq_get_response_headers($headers, $response);
156
+
157
+ // If transfer-coding is set to chunked, we need to join the message body
158
+ // together.
159
+ if(isset($headers['transfer-encoding']) && 'chunked' == strtolower($headers['transfer-encoding'])) {
160
+ $chunk_data = $response['data'];
161
+ $joined_data = '';
162
+ while(true) {
163
+ // Strip length from body.
164
+ list($chunk_length, $chunk_data) = explode("\r\n", $chunk_data, 2);
165
+ $chunk_length = hexdec($chunk_length);
166
+ if(!$chunk_length || !strlen($chunk_data)) { break; }
167
+
168
+ $joined_data .= substr($chunk_data, 0, $chunk_length);
169
+ $chunk_data = substr($chunk_data, $chunk_length + 1);
170
+ $length += $chunk_length;
171
+ }
172
+ $response['data'] = $joined_data;
173
+ } else {
174
+ $length = $headers['content-length'];
175
+ }
176
+ $response['headers'] = $headers;
177
+ }
178
+
179
+
180
+ function _dsq_fopen_urlopen($url, $postdata, &$response, $file_name, $file_field) {
181
+ $params = array();
182
+ if($file_name && $file_field) {
183
+ $boundary = '----------' . md5(time());
184
+ $content = dsq_get_post_content($boundary, $postdata, $file_name, $file_field);
185
+ $header = dsq_get_http_headers_for_request($boundary, $content, $file_name, $file_field);
186
+
187
+ $params = array('http' => array(
188
+ 'method' => 'POST',
189
+ 'header' => $header,
190
+ 'content' => $content,
191
+ 'timeout' => SOCKET_TIMEOUT
192
+ ));
193
+ } else {
194
+ if($postdata) {
195
+ $params = array('http' => array(
196
+ 'method' => 'POST',
197
+ 'header' => 'Content-Type: application/x-www-form-urlencoded',
198
+ 'content' => dsq_get_query_string($postdata),
199
+ 'timeout' => SOCKET_TIMEOUT
200
+ ));
201
+ }
202
+ }
203
+
204
+
205
+ ini_set('user_agent', USER_AGENT);
206
+ $ctx = stream_context_create($params);
207
+ $fp = fopen($url, 'rb', false, $ctx);
208
+ if(!$fp) {
209
+ return false;
210
+ }
211
+
212
+ // Get status code from headers.
213
+ list($unused, $response['code'], $unused) = explode(' ', $http_response_header[0], 3);
214
+ $headers = array_slice($http_response_header, 1);
215
+
216
+ // Convert headers into associative array.
217
+ foreach($headers as $unused=>$header) {
218
+ $header = explode(':', $header);
219
+ $header[0] = trim($header[0]);
220
+ $header[1] = trim($header[1]);
221
+ $headers[strtolower($header[0])] = strtolower($header[1]);
222
+ }
223
+
224
+ $response['data'] = stream_get_contents($fp);
225
+ $response['headers'] = $headers;
226
+ }
227
+
228
+
229
+ /**
230
+ * Wrapper to provide a single interface for making an HTTP request.
231
+ *
232
+ * Attempts to use cURL, fopen(), or fsockopen(), whichever is available
233
+ * first.
234
+ *
235
+ * @param string $url URL to make request to.
236
+ * @param array $postdata (optional) If postdata is provided, the request
237
+ * method is POST with the key/value pairs as
238
+ * the data.
239
+ * @param array $file (optional) Should provide associative array
240
+ * with two keys: name and field. Name should
241
+ * be the name of the file and field is the name
242
+ * of the field to POST.
243
+ */
244
+ function dsq_urlopen($url, $postdata=false, $file=false) {
245
+ $response = array(
246
+ 'data' => '',
247
+ 'code' => 0
248
+ );
249
+
250
+ if($file) {
251
+ extract($file, EXTR_PREFIX_ALL, 'file');
252
+ }
253
+ if(empty($file_name) || empty($file_field)) {
254
+ $file_name = false;
255
+ $file_field = false;
256
+ }
257
+
258
+ //
259
+
260
+ // Try curl, fsockopen, fopen + stream (PHP5 only), exec wget
261
+ if(function_exists('curl_init')) {
262
+ if (!function_exists('curl_setopt_array')) {
263
+ function curl_setopt_array(&$ch, $curl_options)
264
+ {
265
+ foreach ($curl_options as $option => $value) {
266
+ if (!curl_setopt($ch, $option, $value)) {
267
+ return false;
268
+ }
269
+ }
270
+ return true;
271
+ }
272
+ }
273
+ _dsq_curl_urlopen($url, $postdata, $response, $file_name, $file_field);
274
+ } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
275
+ _dsq_fopen_urlopen($url, $postdata, $response, $file_name, $file_field);
276
+ } else {
277
+ // TODO: Find the failure condition for fsockopen() (sockets?)
278
+ _dsq_fsockopen_urlopen($url, $postdata, $response, $file_name, $file_field);
279
+ }
280
+
281
+ // returns array with keys data and code (from headers)
282
+
283
+ return $response;
284
+ }
285
+
286
+ function dsq_url_method() {
287
+ if(function_exists('curl_init')) {
288
+ return 'curl';
289
+ } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
290
+ return 'fopen';
291
+ } else {
292
+ return 'fsockopen';
293
+ }
294
+ }
295
+ ?>
lib/wp-api.php CHANGED
@@ -1,107 +1,107 @@
1
- <?php
2
- /**
3
- * Implementation of the Disqus API designed for WordPress.
4
- *
5
- * @author Disqus <team@disqus.com>
6
- * @copyright 2007-2010 Big Head Labs
7
- * @link http://disqus.com/
8
- * @package Disqus
9
- * @subpackage DisqusWordPressAPI
10
- * @version 2.0
11
- */
12
-
13
- require_once(ABSPATH.WPINC.'/http.php');
14
- require_once(dirname(__FILE__) . '/api/disqus/disqus.php');
15
- /** @#+
16
- * Constants
17
- */
18
- /**
19
- * Base URL for Disqus.
20
- */
21
- define('DISQUS_ALLOWED_HTML', '<b><u><i><h1><h2><h3><code><blockquote><br><hr>');
22
-
23
- /**
24
- * Helper methods for all of the Disqus v2 API methods.
25
- *
26
- * @package Disqus
27
- * @subpackage DisqusWordPressAPI
28
- * @author DISQUS.com <team@disqus.com>
29
- * @copyright 2007-2008 Big Head Labs
30
- * @version 1.0
31
- */
32
- class DisqusWordPressAPI {
33
- var $short_name;
34
- var $forum_api_key;
35
-
36
- function DisqusWordPressAPI($short_name=null, $forum_api_key=null, $user_api_key=null) {
37
- $this->short_name = $short_name;
38
- $this->forum_api_key = $forum_api_key;
39
- $this->user_api_key = $user_api_key;
40
- $this->api = new DisqusAPI($user_api_key, $forum_api_key, DISQUS_API_URL);
41
- }
42
-
43
- function get_last_error() {
44
- return $this->api->get_last_error();
45
- }
46
-
47
- function get_user_api_key($username, $password) {
48
- $response = $this->api->call('get_user_api_key', array(
49
- 'username' => $username,
50
- 'password' => $password,
51
- ), true);
52
- return $response;
53
- }
54
-
55
- function get_forum_list($user_api_key) {
56
- $this->api->user_api_key = $user_api_key;
57
- return $this->api->get_forum_list();
58
- }
59
-
60
- function get_forum_api_key($user_api_key, $id) {
61
- $this->api->user_api_key = $user_api_key;
62
- return $this->api->get_forum_api_key($id);
63
- }
64
-
65
- function get_forum_posts($start_id=0) {
66
- $response = $this->api->get_forum_posts(null, array(
67
- 'filter' => 'approved',
68
- 'start_id' => $start_id,
69
- 'limit' => 100,
70
- 'order' => 'asc',
71
- 'full_info' => 1
72
- ));
73
- return $response;
74
- }
75
-
76
- function import_wordpress_comments(&$wxr, $timestamp, $eof=true) {
77
- $http = new WP_Http();
78
- $response = $http->request(
79
- DISQUS_IMPORTER_URL . 'api/import-wordpress-comments/',
80
- array(
81
- 'method' => 'POST',
82
- 'timeout' => 60,
83
- 'body' => array(
84
- 'forum_url' => $this->short_name,
85
- 'forum_api_key' => $this->forum_api_key,
86
- 'response_type' => 'php',
87
- 'wxr' => $wxr,
88
- 'timestamp' => $timestamp,
89
- 'eof' => (int)$eof
90
- ),
91
- )
92
- );
93
- if ($response->errors) {
94
- // hack
95
- $this->api->last_error = $response->errors;
96
- return -1;
97
- }
98
- $data = unserialize($response['body']);
99
- if (!$data || $data['stat'] == 'fail') {
100
- return -1;
101
- }
102
-
103
- return $data;
104
- }
105
- }
106
-
107
- ?>
1
+ <?php
2
+ /**
3
+ * Implementation of the Disqus API designed for WordPress.
4
+ *
5
+ * @author Disqus <team@disqus.com>
6
+ * @copyright 2007-2010 Big Head Labs
7
+ * @link http://disqus.com/
8
+ * @package Disqus
9
+ * @subpackage DisqusWordPressAPI
10
+ * @version 2.0
11
+ */
12
+
13
+ require_once(ABSPATH.WPINC.'/http.php');
14
+ require_once(dirname(__FILE__) . '/api/disqus/disqus.php');
15
+ /** @#+
16
+ * Constants
17
+ */
18
+ /**
19
+ * Base URL for Disqus.
20
+ */
21
+ define('DISQUS_ALLOWED_HTML', '<b><u><i><h1><h2><h3><code><blockquote><br><hr>');
22
+
23
+ /**
24
+ * Helper methods for all of the Disqus v2 API methods.
25
+ *
26
+ * @package Disqus
27
+ * @subpackage DisqusWordPressAPI
28
+ * @author DISQUS.com <team@disqus.com>
29
+ * @copyright 2007-2008 Big Head Labs
30
+ * @version 1.0
31
+ */
32
+ class DisqusWordPressAPI {
33
+ var $short_name;
34
+ var $forum_api_key;
35
+
36
+ function DisqusWordPressAPI($short_name=null, $forum_api_key=null, $user_api_key=null) {
37
+ $this->short_name = $short_name;
38
+ $this->forum_api_key = $forum_api_key;
39
+ $this->user_api_key = $user_api_key;
40
+ $this->api = new DisqusAPI($user_api_key, $forum_api_key, DISQUS_API_URL);
41
+ }
42
+
43
+ function get_last_error() {
44
+ return $this->api->get_last_error();
45
+ }
46
+
47
+ function get_user_api_key($username, $password) {
48
+ $response = $this->api->call('get_user_api_key', array(
49
+ 'username' => $username,
50
+ 'password' => $password,
51
+ ), true);
52
+ return $response;
53
+ }
54
+
55
+ function get_forum_list($user_api_key) {
56
+ $this->api->user_api_key = $user_api_key;
57
+ return $this->api->get_forum_list();
58
+ }
59
+
60
+ function get_forum_api_key($user_api_key, $id) {
61
+ $this->api->user_api_key = $user_api_key;
62
+ return $this->api->get_forum_api_key($id);
63
+ }
64
+
65
+ function get_forum_posts($start_id=0) {
66
+ $response = $this->api->get_forum_posts(null, array(
67
+ 'filter' => 'approved',
68
+ 'start_id' => $start_id,
69
+ 'limit' => 100,
70
+ 'order' => 'asc',
71
+ 'full_info' => 1
72
+ ));
73
+ return $response;
74
+ }
75
+
76
+ function import_wordpress_comments(&$wxr, $timestamp, $eof=true) {
77
+ $http = new WP_Http();
78
+ $response = $http->request(
79
+ DISQUS_IMPORTER_URL . 'api/import-wordpress-comments/',
80
+ array(
81
+ 'method' => 'POST',
82
+ 'timeout' => 60,
83
+ 'body' => array(
84
+ 'forum_url' => $this->short_name,
85
+ 'forum_api_key' => $this->forum_api_key,
86
+ 'response_type' => 'php',
87
+ 'wxr' => $wxr,
88
+ 'timestamp' => $timestamp,
89
+ 'eof' => (int)$eof
90
+ ),
91
+ )
92
+ );
93
+ if ($response['response']['code'] !== 200) {
94
+ // hack
95
+ $this->api->last_error = $response->errors;
96
+ return -1;
97
+ }
98
+ $data = unserialize($response['body']);
99
+ if (!$data || $data['stat'] == 'fail') {
100
+ return -1;
101
+ }
102
+
103
+ return $data;
104
+ }
105
+ }
106
+
107
+ ?>
lib/wp-cli.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
- /**
3
- * Helper script for setting up the WP command line environment
4
- */
5
- error_reporting(E_ALL | E_STRICT);
6
-
7
- if (php_sapi_name() != 'cli' && !empty($_SERVER['REMOTE_ADDR'])) {
8
- // Don't execute for web requests
9
- die("This script must be run from CLI.");
10
- }
11
-
12
- if (!isset($argv)) {
13
- $argv = array();
14
- }
15
-
16
- function print_line() {
17
- $args = func_get_args();
18
- $result = call_user_func_array('sprintf', $args);
19
- print("{$result}\n");
20
- }
21
-
22
- define('DOING_AJAX', true);
23
- define('WP_USE_THEMES', false);
24
- if (isset($_ENV['WORDPRESS_PATH'])) {
25
- define('ABSPATH', $_ENV['WORDPRESS_PATH']);
26
- } else {
27
- if (substr($_SERVER['SCRIPT_FILENAME'], 0, 1) != '/') {
28
- $script_path = $_SERVER['PWD'] . $_SERVER['SCRIPT_FILENAME'];
29
- } else {
30
- $script_path = $_SERVER['SCRIPT_FILENAME'];
31
- }
32
- $tree = '';
33
- $paths = array();
34
- $chunks = explode('/', dirname($script_path));
35
- foreach ($chunks as $chunk) {
36
- if (!$chunk) continue;
37
- $tree = $tree.'/'.$chunk;
38
- array_push($paths, $tree);
39
- }
40
- $paths = array_reverse($paths);
41
-
42
- foreach ($paths as $path) {
43
- if (is_file($path.'/wp-config.php')) {
44
- define('ABSPATH', $path . '/');
45
- break;
46
- }
47
- }
48
- }
49
-
50
- if (!defined('ABSPATH')) {
51
- print_line("Unable to determine wordpress path. Please set it using WORDPRESS_PATH.");
52
- die();
53
- }
54
-
55
- $_SERVER = array(
56
- "HTTP_HOST" => "disqus.com",
57
- "SCRIPT_NAME" => "",
58
- "PHP_SELF" => __FILE__,
59
- "SERVER_NAME" => "localhost",
60
- "REQUEST_URI" => "/",
61
- "REQUEST_METHOD" => "GET"
62
- );
63
- require_once(ABSPATH . 'wp-config.php');
64
-
65
- // swap out the object cache due to memory constraints
66
-
67
- global $wp_object_cache;
68
-
69
- class DummyWP_Object_Cache extends WP_Object_Cache {
70
- function set($id, $data, $group = 'default', $expire = '') {
71
- return;
72
- }
73
- function delete($id, $group = 'default', $force = false) {
74
- return;
75
- }
76
- function add($id, $data, $group = 'default', $expire = '') {
77
- return;
78
- }
79
- }
80
-
81
- // HACK: kill all output buffers (some plugins, like Hyper Cache, use theses)
82
- while (@ob_end_flush());
83
-
84
- // We cant simply replace the object cache incase set/add do something that
85
- // matters to the webserver
86
- // $wp_object_cache = new DummyWP_Object_Cache();
87
-
88
- ?>
1
+ <?php
2
+ /**
3
+ * Helper script for setting up the WP command line environment
4
+ */
5
+ error_reporting(E_ALL | E_STRICT);
6
+
7
+ if (php_sapi_name() != 'cli' && !empty($_SERVER['REMOTE_ADDR'])) {
8
+ // Don't execute for web requests
9
+ die("This script must be run from CLI.");
10
+ }
11
+
12
+ if (!isset($argv)) {
13
+ $argv = array();
14
+ }
15
+
16
+ function print_line() {
17
+ $args = func_get_args();
18
+ $result = call_user_func_array('sprintf', $args);
19
+ print("{$result}\n");
20
+ }
21
+
22
+ define('DOING_AJAX', true);
23
+ define('WP_USE_THEMES', false);
24
+ if (isset($_ENV['WORDPRESS_PATH'])) {
25
+ define('ABSPATH', $_ENV['WORDPRESS_PATH']);
26
+ } else {
27
+ if (substr($_SERVER['SCRIPT_FILENAME'], 0, 1) != '/') {
28
+ $script_path = $_SERVER['PWD'] . $_SERVER['SCRIPT_FILENAME'];
29
+ } else {
30
+ $script_path = $_SERVER['SCRIPT_FILENAME'];
31
+ }
32
+ $tree = '';
33
+ $paths = array();
34
+ $chunks = explode('/', dirname($script_path));
35
+ foreach ($chunks as $chunk) {
36
+ if (!$chunk) continue;
37
+ $tree = $tree.'/'.$chunk;
38
+ array_push($paths, $tree);
39
+ }
40
+ $paths = array_reverse($paths);
41
+
42
+ foreach ($paths as $path) {
43
+ if (is_file($path.'/wp-config.php')) {
44
+ define('ABSPATH', $path . '/');
45
+ break;
46
+ }
47
+ }
48
+ }
49
+
50
+ if (!defined('ABSPATH')) {
51
+ print_line("Unable to determine wordpress path. Please set it using WORDPRESS_PATH.");
52
+ die();
53
+ }
54
+
55
+ $_SERVER = array(
56
+ "HTTP_HOST" => "disqus.com",
57
+ "SCRIPT_NAME" => "",
58
+ "PHP_SELF" => __FILE__,
59
+ "SERVER_NAME" => "localhost",
60
+ "REQUEST_URI" => "/",
61
+ "REQUEST_METHOD" => "GET"
62
+ );
63
+ require_once(ABSPATH . 'wp-config.php');
64
+
65
+ // swap out the object cache due to memory constraints
66
+
67
+ global $wp_object_cache;
68
+
69
+ class DummyWP_Object_Cache extends WP_Object_Cache {
70
+ function set($id, $data, $group = 'default', $expire = '') {
71
+ return;
72
+ }
73
+ function delete($id, $group = 'default', $force = false) {
74
+ return;
75
+ }
76
+ function add($id, $data, $group = 'default', $expire = '') {
77
+ return;
78
+ }
79
+ }
80
+
81
+ // HACK: kill all output buffers (some plugins, like Hyper Cache, use theses)
82
+ while (@ob_end_flush());
83
+
84
+ // We cant simply replace the object cache incase set/add do something that
85
+ // matters to the webserver
86
+ // $wp_object_cache = new DummyWP_Object_Cache();
87
+
88
+ ?>
locales/default.mo CHANGED
Binary file
locales/default.po CHANGED
@@ -2,418 +2,466 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: disqus-wordpress\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2014-06-23 16:22-0800\n"
6
- "PO-Revision-Date: 2014-06-23 16:23-0800\n"
7
- "Last-Translator: Ryan Valentin <ryan@disqus.com>\n"
8
- "Language-Team: DISQUS <translation@disqus.com>\n"
9
  "Language: en_US\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
  "X-Poedit-KeywordsList: _;gettext;gettext_noop;dsq_i;__;_e\n"
14
  "X-Poedit-Basepath: ../\n"
15
- "X-Generator: Poedit 1.6.5\n"
16
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
- #: ../disqus/comments.php:18 ../disqus/comments.php:34
20
- msgid "<span class=\"meta-nav\">&larr;</span> Older Comments"
21
  msgstr ""
22
 
23
- #: ../disqus/comments.php:19 ../disqus/comments.php:35
24
- msgid "Newer Comments <span class=\"meta-nav\">&rarr;</span>"
25
  msgstr ""
26
 
27
- #: ../disqus/disqus.php:442
 
 
 
 
 
 
 
 
28
  msgid ""
29
- "Your comments have been sent to Disqus and queued for import!<br/><a href=\""
 
30
  msgstr ""
31
 
32
- #: ../disqus/disqus.php:446
33
- #, php-format
34
- msgid "Processed comments on post #%s&hellip;"
35
  msgstr ""
36
 
37
- #: ../disqus/disqus.php:456
38
- #, php-format
 
 
 
 
 
 
 
 
 
 
 
39
  msgid ""
40
- "Sorry, something unexpected happened with the export. Please <a href=\"#\" "
41
- "id=\"dsq_export_retry\">try again</a></p><p>If your API key has changed, you "
42
- "may need to reinstall Disqus (deactivate the plugin and then reactivate it). "
43
- "If you are still having issues, refer to the <a href=\"%s\" onclick=\"window."
44
- "open(this.href); return false\">WordPress help page</a>."
45
  msgstr ""
46
 
47
- #: ../disqus/disqus.php:461
48
  #, php-format
 
 
 
 
49
  msgid ""
50
- "Your comments have been sent to Disqus and queued for import!<br/><a href="
51
- "\"%s\" target=\"_blank\">See the status of your import at Disqus</a>"
52
  msgstr ""
53
 
54
- #: ../disqus/disqus.php:491
55
  msgid "There was an error downloading your comments from Disqus."
56
  msgstr ""
57
 
58
- #: ../disqus/disqus.php:496
59
  msgid ""
60
  "Your comments have been downloaded from Disqus and saved in your local "
61
  "database."
62
  msgstr ""
63
 
64
- #: ../disqus/disqus.php:499
65
  #, php-format
66
- msgid "Import in progress (last post id: %s) &hellip;"
67
  msgstr ""
68
 
69
- #: ../disqus/disqus.php:833
70
  msgid "Pingback:"
71
  msgstr ""
72
 
73
- #: ../disqus/disqus.php:833
74
- msgid "(Edit)"
75
  msgstr ""
76
 
77
- #: ../disqus/disqus.php:870
78
  msgid "Configure"
79
  msgstr ""
80
 
81
- #: ../disqus/disqus.php:872 ../disqus/manage.php:360
82
  msgid "Settings"
83
  msgstr ""
84
 
85
- #: ../disqus/disqus.php:1577
86
  msgid ""
87
  "Sorry, the built-in commenting system is disabled because Disqus is active."
88
  msgstr ""
89
 
90
- #: ../disqus/manage.php:61
91
  msgid "Disqus Reset"
92
  msgstr ""
93
 
94
- #: ../disqus/manage.php:64
95
  msgid "Disqus has been reset successfully."
96
  msgstr ""
97
 
98
- #: ../disqus/manage.php:66
99
  msgid "Local settings for the plugin were removed."
100
  msgstr ""
101
 
102
- #: ../disqus/manage.php:67
103
  msgid "Database changes by Disqus were reverted."
104
  msgstr ""
105
 
106
- #: ../disqus/manage.php:69
107
- msgid ""
108
- "If you wish to <a href=\"?page=disqus&amp;step=1\">reinstall</a>, you can do "
109
- "that now."
110
  msgstr ""
111
 
112
- #: ../disqus/manage.php:182
 
 
 
 
113
  msgid "Your settings have been changed."
114
  msgstr ""
115
 
116
- #: ../disqus/manage.php:206
117
- msgid ""
118
- "There was an error completing the installation of Disqus. If you are still "
119
- "having issues, refer to the <a href=\"https://help.disqus.com/customer/"
120
- "portal/articles/472005-wordpress-troubleshooting\">WordPress help page</a>."
121
  msgstr ""
122
 
123
- #: ../disqus/manage.php:236
124
- #, php-format
 
 
 
 
 
 
 
125
  msgid ""
126
- "There aren't any sites associated with this account. Maybe you want to <a "
127
- "href=\"%s\">create a site</a>?"
128
  msgstr ""
129
 
130
- #: ../disqus/manage.php:246
 
 
 
 
131
  msgid "Moderate"
132
  msgstr ""
133
 
134
- #: ../disqus/manage.php:246
135
  msgid "Install"
136
  msgstr ""
137
 
138
- #: ../disqus/manage.php:247
139
  msgid "Plugin Settings"
140
  msgstr ""
141
 
142
- #: ../disqus/manage.php:256 ../disqus/manage.php:267 ../disqus/manage.php:301
143
  msgid "Install Disqus Comments"
144
  msgstr ""
145
 
146
- #: ../disqus/manage.php:258
147
  msgid "Disqus has been installed on your blog."
148
  msgstr ""
149
 
150
- #: ../disqus/manage.php:259
 
 
 
 
151
  msgid ""
152
- "If you have existing comments, you may wish to <a href=\"?page=disqus&amp;"
153
- "t=adv#export\">export them</a> now. Otherwise, you're all set, and the "
154
- "Disqus network is now powering comments on your blog."
155
  msgstr ""
156
 
157
- #: ../disqus/manage.php:260
158
  msgid "Continue to the moderation dashboard"
159
  msgstr ""
160
 
161
- #: ../disqus/manage.php:273
162
  msgid "Select a website"
163
  msgstr ""
164
 
165
- #: ../disqus/manage.php:285
166
  msgid "Or register a new one on the Disqus website."
167
  msgstr ""
168
 
169
- #: ../disqus/manage.php:307
170
  msgid "Username or email"
171
  msgstr ""
172
 
173
- #: ../disqus/manage.php:310
174
- msgid "(don't have a Disqus Profile yet?)"
175
  msgstr ""
176
 
177
- #: ../disqus/manage.php:314
178
  msgid "Password"
179
  msgstr ""
180
 
181
- #: ../disqus/manage.php:317
182
- msgid "(forgot your password?)"
 
 
 
 
183
  msgstr ""
184
 
185
- #: ../disqus/manage.php:361
186
  #, php-format
187
  msgid "Version: %s"
188
  msgstr ""
189
 
190
- #: ../disqus/manage.php:365
191
- msgid ""
192
- "<p class=\"status\">Disqus comments are currently <span class=\"dsq-disabled-"
193
- "text\">disabled</span>. (<a href=\"?page=disqus&amp;active=1\">Enable</a>)</"
194
- "p>"
195
  msgstr ""
196
 
197
- #: ../disqus/manage.php:367
198
- msgid ""
199
- "<p class=\"status\">Disqus comments are currently <span class=\"dsq-enabled-"
200
- "text\">enabled</span>. (<a href=\"?page=disqus&amp;active=0\">Disable</a>)</"
201
- "p>"
202
  msgstr ""
203
 
204
- #: ../disqus/manage.php:375
205
- msgid "<h3>General</h3>"
206
  msgstr ""
207
 
208
- #: ../disqus/manage.php:378
 
 
 
 
209
  msgid "Forum Shortname"
210
  msgstr ""
211
 
212
- #: ../disqus/manage.php:383
213
  msgid ""
214
  "This is the unique identifier for your website in Disqus, automatically set "
215
  "during installation."
216
  msgstr ""
217
 
218
- #: ../disqus/manage.php:388
219
- msgid "<h3>Appearance</h3>"
220
  msgstr ""
221
 
222
- #: ../disqus/manage.php:391
223
  msgid "Use Disqus Comments on"
224
  msgstr ""
225
 
226
- #: ../disqus/manage.php:394
227
  msgid "All blog posts."
228
  msgstr ""
229
 
230
- #: ../disqus/manage.php:395
231
  msgid "Blog posts with closed comments only."
232
  msgstr ""
233
 
234
- #: ../disqus/manage.php:399
235
  msgid ""
236
  "You have selected to only enable Disqus on posts with closed comments. If "
237
- "you aren't seeing Disqus on new posts, change this option to <strong>All "
238
- "blog posts</strong>."
239
  msgstr ""
240
 
241
- #: ../disqus/manage.php:400
242
  msgid ""
243
  "Shows comments on either all blog posts, or ones with closed comments. "
244
- "Select the <strong>Blog posts with closed comments only</strong> option if "
245
- "you plan on disabling Disqus, but want to keep it on posts which already "
246
- "have comments."
247
  msgstr ""
248
 
249
- #: ../disqus/manage.php:406
250
- msgid "<h3>Sync</h3>"
251
  msgstr ""
252
 
253
- #: ../disqus/manage.php:409
254
  msgid "Comment Importing"
255
  msgstr ""
256
 
257
- #: ../disqus/manage.php:412
258
  msgid "Disable automated comment importing"
259
  msgstr ""
260
 
261
- #: ../disqus/manage.php:413
262
  msgid ""
263
  "If you have problems with WP-Cron taking too long, or have a large number of "
264
  "comments, you may wish to disable automated sync. Comments will only be "
265
  "imported to your local Wordpress database if you do so manually."
266
  msgstr ""
267
 
268
- #: ../disqus/manage.php:417
269
  msgid "Server-Side Rendering"
270
  msgstr ""
271
 
272
- #: ../disqus/manage.php:420
273
  msgid "Disable server-side rendering of comments"
274
  msgstr ""
275
 
276
- #: ../disqus/manage.php:421
277
  msgid "Hides comments from nearly all search engines."
278
  msgstr ""
279
 
280
- #: ../disqus/manage.php:426
281
- msgid "<h3>Patches</h3>"
282
  msgstr ""
283
 
284
- #: ../disqus/manage.php:430
285
  msgid "Template Conflicts"
286
  msgstr ""
287
 
288
- #: ../disqus/manage.php:433
289
  msgid "Output JavaScript in footer"
290
  msgstr ""
291
 
292
- #: ../disqus/manage.php:434
293
- #, php-format
294
  msgid ""
295
  "Enable this if you have problems with comment counts or other "
296
  "irregularities. For example: missing counts, counts always at 0, Disqus code "
297
  "showing on the page, broken image carousels, or longer-than-usual home page "
298
- "load times (<a href=\"%s\" onclick=\"window.open(this.href); return false"
299
- "\">more info</a>)."
300
  msgstr ""
301
 
302
- #: ../disqus/manage.php:439
303
- #, php-format
304
- msgid ""
305
- "<h3>Advanced</h3><h4>Single Sign-On</h4><p>Allows users to log in to Disqus "
306
- "via WordPress. (<a href=\"%s\" onclick=\"window.open(this.href); return false"
307
- "\">More info on SSO</a>)</p>"
308
  msgstr ""
309
 
310
- #: ../disqus/manage.php:443
 
 
 
 
 
 
 
 
 
 
 
 
311
  msgid "Disqus Partner Key"
312
  msgstr ""
313
 
314
- #: ../disqus/manage.php:450
315
  msgid "API Application Public Key"
316
  msgstr ""
317
 
318
- #: ../disqus/manage.php:454 ../disqus/manage.php:462
319
- #, php-format
320
- msgid "Found at <a href=\"%s\">Disqus API Applications</a>."
321
  msgstr ""
322
 
323
- #: ../disqus/manage.php:458
324
  msgid "API Application Secret Key"
325
  msgstr ""
326
 
327
- #: ../disqus/manage.php:466
328
  msgid "Custom Log-in Button"
329
  msgstr ""
330
 
331
- #: ../disqus/manage.php:516
332
  msgid "Change"
333
  msgstr ""
334
 
335
- #: ../disqus/manage.php:516
336
  msgid "Choose"
337
  msgstr ""
338
 
339
- #: ../disqus/manage.php:516
340
  msgid "button"
341
  msgstr ""
342
 
343
- #: ../disqus/manage.php:522
344
- #, php-format
345
- msgid ""
346
- "Adds a button to the Disqus log-in interface. (<a href=\"%s\">Example "
347
- "screenshot</a>.)"
348
  msgstr ""
349
 
350
- #: ../disqus/manage.php:523
351
- #, php-format
352
- msgid ""
353
- "<br />See <a href=\"%s\">our SSO button documentation</a> for a template to "
354
- "create your own button."
 
 
 
 
 
355
  msgstr ""
356
 
357
- #: ../disqus/manage.php:541
358
  msgid "Export comments to Disqus"
359
  msgstr ""
360
 
361
- #: ../disqus/manage.php:544
362
  msgid "Export Comments"
363
  msgstr ""
364
 
365
- #: ../disqus/manage.php:544
366
  msgid "This will export your existing WordPress comments to Disqus"
367
  msgstr ""
368
 
369
- #: ../disqus/manage.php:550
370
  msgid "Sync Disqus with WordPress"
371
  msgstr ""
372
 
373
- #: ../disqus/manage.php:554
374
  msgid "Sync Comments"
375
  msgstr ""
376
 
377
- #: ../disqus/manage.php:554
378
  msgid ""
379
  "This will download your Disqus comments and store them locally in WordPress"
380
  msgstr ""
381
 
382
- #: ../disqus/manage.php:555
383
  msgid "Remove all imported Disqus comments before syncing."
384
  msgstr ""
385
 
386
- #: ../disqus/manage.php:566
387
  msgid "Reset Disqus"
388
  msgstr ""
389
 
390
- #: ../disqus/manage.php:570
391
  msgid "Are you sure you want to reset the Disqus plugin?"
392
  msgstr ""
393
 
394
- #: ../disqus/manage.php:570
395
  msgid ""
396
  "This removes all Disqus-specific settings. Comments will remain unaffected."
397
  msgstr ""
398
 
399
- #: ../disqus/manage.php:571
400
  msgid ""
401
  "If you have problems with resetting taking too long you may wish to first "
402
- "manually drop the <code>disqus_dupecheck</code> index from your "
403
- "<code>commentmeta</code> table."
404
  msgstr ""
405
 
406
- #: ../disqus/manage.php:578
407
  msgid "Debug Information"
408
  msgstr ""
409
 
410
- #: ../disqus/manage.php:579
411
- #, php-format
412
  msgid ""
413
- "Having problems with the plugin? Check out our <a href=\"%s\" onclick="
414
- "\"window.open(this.href); return false\">WordPress Troubleshooting</a> "
415
- "documentation. You can also <a href=\"%s\">drop us a line</a> including the "
416
- "following details and we'll do what we can."
 
 
 
 
 
 
 
 
 
417
  msgstr ""
418
 
419
  #: ../disqus/upgrade.php:12
2
  msgstr ""
3
  "Project-Id-Version: disqus-wordpress\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2014-10-29 11:55-0800\n"
6
+ "PO-Revision-Date: 2014-10-29 11:55-0800\n"
7
+ "Last-Translator: Ryan <ryan@disqus.com>\n"
8
+ "Language-Team: Disqus <translation@disqus.com>\n"
9
  "Language: en_US\n"
10
  "MIME-Version: 1.0\n"
11
  "Content-Type: text/plain; charset=UTF-8\n"
12
  "Content-Transfer-Encoding: 8bit\n"
13
  "X-Poedit-KeywordsList: _;gettext;gettext_noop;dsq_i;__;_e\n"
14
  "X-Poedit-Basepath: ../\n"
15
+ "X-Generator: Poedit 1.6.10\n"
16
  "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
  "X-Poedit-SearchPath-0: ..\n"
18
 
19
+ #: ../disqus/comments.php:15 ../disqus/comments.php:37
20
+ msgid "Older Comments"
21
  msgstr ""
22
 
23
+ #: ../disqus/comments.php:18 ../disqus/comments.php:40
24
+ msgid "Newer Comments"
25
  msgstr ""
26
 
27
+ #: ../disqus/disqus.php:177
28
+ msgid "Disqus needs to be configured"
29
+ msgstr ""
30
+
31
+ #: ../disqus/disqus.php:178
32
+ msgid "Configure Disqus by clicking Comments to the left."
33
+ msgstr ""
34
+
35
+ #: ../disqus/disqus.php:513
36
  msgid ""
37
+ "Unable to export comments. Make sure you are accessing this page from the "
38
+ "Wordpress dashboard."
39
  msgstr ""
40
 
41
+ #: ../disqus/disqus.php:544 ../disqus/disqus.php:570
42
+ msgid "Your comments have been sent to Disqus and queued for import!"
 
43
  msgstr ""
44
 
45
+ #: ../disqus/disqus.php:546 ../disqus/disqus.php:572
46
+ msgid "See the status of your import at Disqus"
47
+ msgstr ""
48
+
49
+ #: ../disqus/disqus.php:550
50
+ msgid "Processed comments on post"
51
+ msgstr ""
52
+
53
+ #: ../disqus/disqus.php:560
54
+ msgid "Sorry, something unexpected happened with the export. Please try again."
55
+ msgstr ""
56
+
57
+ #: ../disqus/disqus.php:562
58
  msgid ""
59
+ "If your API key has changed, you may need to reinstall Disqus (deactivate "
60
+ "the plugin and then reactivate it)."
 
 
 
61
  msgstr ""
62
 
63
+ #: ../disqus/disqus.php:563
64
  #, php-format
65
+ msgid "If you are still having issues, refer to the %s WordPress help page"
66
+ msgstr ""
67
+
68
+ #: ../disqus/disqus.php:594
69
  msgid ""
70
+ "Unable to import comments. Make sure you are accessing this page from the "
71
+ "Wordpress dashboard."
72
  msgstr ""
73
 
74
+ #: ../disqus/disqus.php:617
75
  msgid "There was an error downloading your comments from Disqus."
76
  msgstr ""
77
 
78
+ #: ../disqus/disqus.php:622
79
  msgid ""
80
  "Your comments have been downloaded from Disqus and saved in your local "
81
  "database."
82
  msgstr ""
83
 
84
+ #: ../disqus/disqus.php:625
85
  #, php-format
86
+ msgid "Import in progress (last post id: %s)"
87
  msgstr ""
88
 
89
+ #: ../disqus/disqus.php:964
90
  msgid "Pingback:"
91
  msgstr ""
92
 
93
+ #: ../disqus/disqus.php:964
94
+ msgid "Edit"
95
  msgstr ""
96
 
97
+ #: ../disqus/disqus.php:1001
98
  msgid "Configure"
99
  msgstr ""
100
 
101
+ #: ../disqus/disqus.php:1003 ../disqus/manage.php:386
102
  msgid "Settings"
103
  msgstr ""
104
 
105
+ #: ../disqus/disqus.php:1475
106
  msgid ""
107
  "Sorry, the built-in commenting system is disabled because Disqus is active."
108
  msgstr ""
109
 
110
+ #: ../disqus/manage.php:62
111
  msgid "Disqus Reset"
112
  msgstr ""
113
 
114
+ #: ../disqus/manage.php:65
115
  msgid "Disqus has been reset successfully."
116
  msgstr ""
117
 
118
+ #: ../disqus/manage.php:67
119
  msgid "Local settings for the plugin were removed."
120
  msgstr ""
121
 
122
+ #: ../disqus/manage.php:68
123
  msgid "Database changes by Disqus were reverted."
124
  msgstr ""
125
 
126
+ #: ../disqus/manage.php:71
127
+ msgid "If you wish to reinstall, you can do that now."
 
 
128
  msgstr ""
129
 
130
+ #: ../disqus/manage.php:72
131
+ msgid "Reinstall"
132
+ msgstr ""
133
+
134
+ #: ../disqus/manage.php:188
135
  msgid "Your settings have been changed."
136
  msgstr ""
137
 
138
+ #: ../disqus/manage.php:213
139
+ msgid "There was an error completing the installation of Disqus."
 
 
 
140
  msgstr ""
141
 
142
+ #: ../disqus/manage.php:215
143
+ msgid "If you are still having issues, refer to the help documentation."
144
+ msgstr ""
145
+
146
+ #: ../disqus/manage.php:218
147
+ msgid "WordPress Help Page"
148
+ msgstr ""
149
+
150
+ #: ../disqus/manage.php:251
151
  msgid ""
152
+ "There aren't any sites associated with this account. Maybe you want to "
153
+ "create a site?"
154
  msgstr ""
155
 
156
+ #: ../disqus/manage.php:254
157
+ msgid "Create a site"
158
+ msgstr ""
159
+
160
+ #: ../disqus/manage.php:267
161
  msgid "Moderate"
162
  msgstr ""
163
 
164
+ #: ../disqus/manage.php:267
165
  msgid "Install"
166
  msgstr ""
167
 
168
+ #: ../disqus/manage.php:270
169
  msgid "Plugin Settings"
170
  msgstr ""
171
 
172
+ #: ../disqus/manage.php:280 ../disqus/manage.php:294 ../disqus/manage.php:328
173
  msgid "Install Disqus Comments"
174
  msgstr ""
175
 
176
+ #: ../disqus/manage.php:282
177
  msgid "Disqus has been installed on your blog."
178
  msgstr ""
179
 
180
+ #: ../disqus/manage.php:284
181
+ msgid "If you have existing comments, you may wish to export them now."
182
+ msgstr ""
183
+
184
+ #: ../disqus/manage.php:285
185
  msgid ""
186
+ "Otherwise, you're all set, and the Disqus network is now powering comments "
187
+ "on your site."
 
188
  msgstr ""
189
 
190
+ #: ../disqus/manage.php:287
191
  msgid "Continue to the moderation dashboard"
192
  msgstr ""
193
 
194
+ #: ../disqus/manage.php:300
195
  msgid "Select a website"
196
  msgstr ""
197
 
198
+ #: ../disqus/manage.php:312
199
  msgid "Or register a new one on the Disqus website."
200
  msgstr ""
201
 
202
+ #: ../disqus/manage.php:334
203
  msgid "Username or email"
204
  msgstr ""
205
 
206
+ #: ../disqus/manage.php:337
207
+ msgid "don't have a Disqus Profile yet?"
208
  msgstr ""
209
 
210
+ #: ../disqus/manage.php:341
211
  msgid "Password"
212
  msgstr ""
213
 
214
+ #: ../disqus/manage.php:344
215
+ msgid "forgot your password?"
216
+ msgstr ""
217
+
218
+ #: ../disqus/manage.php:364
219
+ msgid "Go to Disqus Moderation"
220
  msgstr ""
221
 
222
+ #: ../disqus/manage.php:387
223
  #, php-format
224
  msgid "Version: %s"
225
  msgstr ""
226
 
227
+ #: ../disqus/manage.php:393
228
+ msgid "Disqus comments are currently "
 
 
 
229
  msgstr ""
230
 
231
+ #: ../disqus/manage.php:396
232
+ msgid "Disable"
 
 
 
233
  msgstr ""
234
 
235
+ #: ../disqus/manage.php:396
236
+ msgid "Enable"
237
  msgstr ""
238
 
239
+ #: ../disqus/manage.php:405
240
+ msgid "General"
241
+ msgstr ""
242
+
243
+ #: ../disqus/manage.php:408
244
  msgid "Forum Shortname"
245
  msgstr ""
246
 
247
+ #: ../disqus/manage.php:413
248
  msgid ""
249
  "This is the unique identifier for your website in Disqus, automatically set "
250
  "during installation."
251
  msgstr ""
252
 
253
+ #: ../disqus/manage.php:418
254
+ msgid "Appearance"
255
  msgstr ""
256
 
257
+ #: ../disqus/manage.php:421
258
  msgid "Use Disqus Comments on"
259
  msgstr ""
260
 
261
+ #: ../disqus/manage.php:424
262
  msgid "All blog posts."
263
  msgstr ""
264
 
265
+ #: ../disqus/manage.php:425
266
  msgid "Blog posts with closed comments only."
267
  msgstr ""
268
 
269
+ #: ../disqus/manage.php:429
270
  msgid ""
271
  "You have selected to only enable Disqus on posts with closed comments. If "
272
+ "you aren't seeing Disqus on new posts, change this option to \"All blog posts"
273
+ "\"."
274
  msgstr ""
275
 
276
+ #: ../disqus/manage.php:430
277
  msgid ""
278
  "Shows comments on either all blog posts, or ones with closed comments. "
279
+ "Select the \"Blog posts with closed comments only\" option if you plan on "
280
+ "disabling Disqus, but want to keep it on posts which already have comments."
 
281
  msgstr ""
282
 
283
+ #: ../disqus/manage.php:436
284
+ msgid "Sync"
285
  msgstr ""
286
 
287
+ #: ../disqus/manage.php:439
288
  msgid "Comment Importing"
289
  msgstr ""
290
 
291
+ #: ../disqus/manage.php:442
292
  msgid "Disable automated comment importing"
293
  msgstr ""
294
 
295
+ #: ../disqus/manage.php:443
296
  msgid ""
297
  "If you have problems with WP-Cron taking too long, or have a large number of "
298
  "comments, you may wish to disable automated sync. Comments will only be "
299
  "imported to your local Wordpress database if you do so manually."
300
  msgstr ""
301
 
302
+ #: ../disqus/manage.php:447
303
  msgid "Server-Side Rendering"
304
  msgstr ""
305
 
306
+ #: ../disqus/manage.php:450
307
  msgid "Disable server-side rendering of comments"
308
  msgstr ""
309
 
310
+ #: ../disqus/manage.php:451
311
  msgid "Hides comments from nearly all search engines."
312
  msgstr ""
313
 
314
+ #: ../disqus/manage.php:456
315
+ msgid "Patches"
316
  msgstr ""
317
 
318
+ #: ../disqus/manage.php:460
319
  msgid "Template Conflicts"
320
  msgstr ""
321
 
322
+ #: ../disqus/manage.php:463
323
  msgid "Output JavaScript in footer"
324
  msgstr ""
325
 
326
+ #: ../disqus/manage.php:464
 
327
  msgid ""
328
  "Enable this if you have problems with comment counts or other "
329
  "irregularities. For example: missing counts, counts always at 0, Disqus code "
330
  "showing on the page, broken image carousels, or longer-than-usual home page "
331
+ "load times"
 
332
  msgstr ""
333
 
334
+ #: ../disqus/manage.php:470
335
+ msgid "Advanced"
 
 
 
 
336
  msgstr ""
337
 
338
+ #: ../disqus/manage.php:471
339
+ msgid "Single Sign-On"
340
+ msgstr ""
341
+
342
+ #: ../disqus/manage.php:473
343
+ msgid "Allows users to log in to Disqus via WordPress."
344
+ msgstr ""
345
+
346
+ #: ../disqus/manage.php:475
347
+ msgid "More info on SSO"
348
+ msgstr ""
349
+
350
+ #: ../disqus/manage.php:482
351
  msgid "Disqus Partner Key"
352
  msgstr ""
353
 
354
+ #: ../disqus/manage.php:489
355
  msgid "API Application Public Key"
356
  msgstr ""
357
 
358
+ #: ../disqus/manage.php:493 ../disqus/manage.php:501
359
+ msgid "Disqus API Applications"
 
360
  msgstr ""
361
 
362
+ #: ../disqus/manage.php:497
363
  msgid "API Application Secret Key"
364
  msgstr ""
365
 
366
+ #: ../disqus/manage.php:505
367
  msgid "Custom Log-in Button"
368
  msgstr ""
369
 
370
+ #: ../disqus/manage.php:519
371
  msgid "Change"
372
  msgstr ""
373
 
374
+ #: ../disqus/manage.php:519
375
  msgid "Choose"
376
  msgstr ""
377
 
378
+ #: ../disqus/manage.php:519
379
  msgid "button"
380
  msgstr ""
381
 
382
+ #: ../disqus/manage.php:525
383
+ msgid "Adds a button to the Disqus log-in interface."
 
 
 
384
  msgstr ""
385
 
386
+ #: ../disqus/manage.php:527
387
+ msgid "Example screenshot"
388
+ msgstr ""
389
+
390
+ #: ../disqus/manage.php:530
391
+ msgid "See our documentation for a template to create your own button."
392
+ msgstr ""
393
+
394
+ #: ../disqus/manage.php:532
395
+ msgid "SSO button documentation"
396
  msgstr ""
397
 
398
+ #: ../disqus/manage.php:551
399
  msgid "Export comments to Disqus"
400
  msgstr ""
401
 
402
+ #: ../disqus/manage.php:557
403
  msgid "Export Comments"
404
  msgstr ""
405
 
406
+ #: ../disqus/manage.php:558
407
  msgid "This will export your existing WordPress comments to Disqus"
408
  msgstr ""
409
 
410
+ #: ../disqus/manage.php:566
411
  msgid "Sync Disqus with WordPress"
412
  msgstr ""
413
 
414
+ #: ../disqus/manage.php:573
415
  msgid "Sync Comments"
416
  msgstr ""
417
 
418
+ #: ../disqus/manage.php:574
419
  msgid ""
420
  "This will download your Disqus comments and store them locally in WordPress"
421
  msgstr ""
422
 
423
+ #: ../disqus/manage.php:578
424
  msgid "Remove all imported Disqus comments before syncing."
425
  msgstr ""
426
 
427
+ #: ../disqus/manage.php:592
428
  msgid "Reset Disqus"
429
  msgstr ""
430
 
431
+ #: ../disqus/manage.php:597
432
  msgid "Are you sure you want to reset the Disqus plugin?"
433
  msgstr ""
434
 
435
+ #: ../disqus/manage.php:598
436
  msgid ""
437
  "This removes all Disqus-specific settings. Comments will remain unaffected."
438
  msgstr ""
439
 
440
+ #: ../disqus/manage.php:600
441
  msgid ""
442
  "If you have problems with resetting taking too long you may wish to first "
443
+ "manually drop the 'disqus_dupecheck' index from your 'commentmeta' table."
 
444
  msgstr ""
445
 
446
+ #: ../disqus/manage.php:607
447
  msgid "Debug Information"
448
  msgstr ""
449
 
450
+ #: ../disqus/manage.php:609
 
451
  msgid ""
452
+ "Having problems with the plugin? Check out our troubleshooting documentation."
453
+ msgstr ""
454
+
455
+ #: ../disqus/manage.php:611
456
+ msgid "WordPress troubleshooting ocumentation"
457
+ msgstr ""
458
+
459
+ #: ../disqus/manage.php:613
460
+ msgid "You can also email us and include the debug info below."
461
+ msgstr ""
462
+
463
+ #: ../disqus/manage.php:615
464
+ msgid "Contact support"
465
  msgstr ""
466
 
467
  #: ../disqus/upgrade.php:12
locales/index.html DELETED
File without changes
manage.php CHANGED
@@ -1,621 +1,651 @@
1
- <?php
2
- // HACK: For old versions of WordPress
3
- if ( !function_exists('wp_nonce_field') ) {
4
- function wp_nonce_field() {}
5
- }
6
-
7
- global $dsq_api;
8
-
9
- require(ABSPATH . 'wp-includes/version.php');
10
-
11
- if ( !current_user_can('moderate_comments') ) {
12
- die('The account you\'re logged in to doesn\'t have permission to access this page.');
13
- }
14
-
15
- function has_valid_nonce() {
16
- $nonce_actions = array('upgrade', 'reset', 'install', 'settings');
17
- $nonce_form_prefix = 'dsq-form_nonce_';
18
- $nonce_action_prefix = 'dsq-wpnonce_';
19
-
20
- // Check all available nonce actions
21
- foreach ( $nonce_actions as $key => $value ) {
22
- if ( isset($_POST[$nonce_form_prefix.$value]) ) {
23
- check_admin_referer($nonce_action_prefix.$value, $nonce_form_prefix.$value);
24
- return true;
25
- }
26
- }
27
-
28
- return false;
29
- }
30
-
31
- if ( ! empty($_POST) ) {
32
- $nonce_result_check = has_valid_nonce();
33
- if ($nonce_result_check === false) {
34
- die('Unable to save changes. Make sure you are accessing this page from the Wordpress dashboard.');
35
- }
36
- }
37
-
38
- if( isset($_POST['dsq_username']) ) {
39
- $_POST['dsq_username'] = stripslashes($_POST['dsq_username']);
40
- }
41
-
42
- if( isset($_POST['dsq_password']) ) {
43
- $_POST['dsq_password'] = stripslashes($_POST['dsq_password']);
44
- }
45
-
46
- // Handle export function.
47
- if( isset($_POST['export']) and DISQUS_CAN_EXPORT ) {
48
- require_once(dirname(__FILE__) . '/export.php');
49
- dsq_export_wp();
50
- }
51
-
52
- // Handle resetting.
53
- if ( isset($_POST['reset']) ) {
54
- foreach (dsq_options() as $opt) {
55
- delete_option($opt);
56
- }
57
- unset($_POST);
58
- dsq_reset_database();
59
- ?>
60
- <div class="wrap">
61
- <h2><?php echo dsq_i('Disqus Reset'); ?></h2>
62
- <form method="POST" action="?page=disqus">
63
- <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
64
- <p><?php echo dsq_i('Disqus has been reset successfully.') ?></p>
65
- <ul style="list-style: circle;padding-left:20px;">
66
- <li><?php echo dsq_i('Local settings for the plugin were removed.') ?></li>
67
- <li><?php echo dsq_i('Database changes by Disqus were reverted.') ?></li>
68
- </ul>
69
- <p><?php echo dsq_i('If you wish to <a href="?page=disqus&amp;step=1">reinstall</a>, you can do that now.') ?></p>
70
- </form>
71
- </div>
72
- <?php
73
- die();
74
- }
75
-
76
- // Post fields that require verification.
77
- $check_fields = array(
78
- 'dsq_user_api_key' => array(
79
- 'key_name' => 'dsq_user_api_key',
80
- 'min' => 64,
81
- 'max' => 64,
82
- ),
83
- 'disqus_api_key' => array(
84
- 'key_name' => 'disqus_api_key',
85
- 'min' => 64,
86
- 'max' => 64,
87
- ),
88
- 'disqus_public_key' => array(
89
- 'key_name' => 'disqus_public_key',
90
- 'min' => 64,
91
- 'max' => 64,
92
- ),
93
- 'disqus_secret_key' => array(
94
- 'key_name' => 'disqus_secret_key',
95
- 'min' => 64,
96
- 'max' => 64,
97
- ),
98
- 'disqus_partner_key' => array(
99
- 'key_name' => 'disqus_partner_key',
100
- 'min' => 64,
101
- 'max' => 64,
102
- ),
103
- 'dsq_forum' => array(
104
- 'key_name' => 'dsq_forum',
105
- 'min' => 1,
106
- 'max' => 64,
107
- ),
108
- 'disqus_forum_url' => array(
109
- 'key_name' => 'disqus_forum_url',
110
- 'min' => 1,
111
- 'max' => 64,
112
- ),
113
- 'disqus_replace' => array(
114
- 'key_name' => 'disqus_replace',
115
- 'min' => 3,
116
- 'max' => 6,
117
- ),
118
- 'dsq_username' => array(
119
- 'key_name' => 'dsq_username',
120
- 'min' => 3,
121
- 'max' => 250,
122
- ),
123
- );
124
-
125
- // Check keys keys and remove bad input.
126
- foreach ( $check_fields as $key ) {
127
-
128
- if ( isset($_POST[$key['key_name']]) ) {
129
-
130
- // Strip tags before checking
131
- $_POST[$key['key_name']] = trim(strip_tags($_POST[$key['key_name']]));
132
-
133
- // Check usernames independently because they can have special characters
134
- // or be email addresses
135
- if ( 'dsq_username' === $key['key_name'] ) {
136
- if ( !is_valid_dsq_username($_POST[$key['key_name']], $key['min'], $key['max']) ) {
137
- unset($_POST[$key['key_name']]);
138
- }
139
- }
140
- else {
141
- if ( !is_valid_dsq_key($_POST[$key['key_name']], $key['min'], $key['max']) ) {
142
- unset($_POST[$key['key_name']]);
143
- }
144
- }
145
- }
146
- }
147
-
148
- function is_valid_dsq_username($value, $min=3, $max=250) {
149
- if ( is_email($value) ) {
150
- return true;
151
- }
152
- else {
153
- return is_valid_dsq_key($value, $min, $max);
154
- }
155
- }
156
-
157
- function is_valid_dsq_key($value, $min=1, $max=64) {
158
- return preg_match('/^[\0-9\\:A-Za-z_-]{'.$min.','.$max.'}+$/', $value);
159
- }
160
-
161
- // Handle advanced options.
162
- if ( isset($_POST['disqus_forum_url']) && isset($_POST['disqus_replace']) ) {
163
- update_option('disqus_partner_key', trim(stripslashes($_POST['disqus_partner_key'])));
164
- update_option('disqus_replace', $_POST['disqus_replace']);
165
- update_option('disqus_cc_fix', isset($_POST['disqus_cc_fix']));
166
- update_option('disqus_manual_sync', isset($_POST['disqus_manual_sync']));
167
- update_option('disqus_disable_ssr', isset($_POST['disqus_disable_ssr']));
168
- update_option('disqus_public_key', $_POST['disqus_public_key']);
169
- update_option('disqus_secret_key', $_POST['disqus_secret_key']);
170
- // Handle any SSO button and icon uploads
171
- if ( version_compare($wp_version, '3.5', '>=') ) {
172
- // Use WP 3.5's new, streamlined, much-improved built-in media uploader
173
-
174
- // Only update if a value is actually POSTed, otherwise any time the form is saved the button and icon will be un-set
175
- if ($_POST['disqus_sso_button']) { update_option('disqus_sso_button', $_POST['disqus_sso_button']); }
176
- } else {
177
- // WP is older than 3.5, use legacy, less-elegant media uploader
178
- if(isset($_FILES['disqus_sso_button'])) {
179
- dsq_image_upload_handler('disqus_sso_button');
180
- }
181
- }
182
- dsq_manage_dialog(dsq_i('Your settings have been changed.'));
183
- }
184
-
185
- // handle disqus_active
186
- if ( isset($_GET['active']) ) {
187
- update_option('disqus_active', ($_GET['active'] == '1' ? '1' : '0'));
188
- }
189
-
190
- $dsq_user_api_key = isset($_POST['dsq_user_api_key']) ? $_POST['dsq_user_api_key'] : null;
191
-
192
- // Get installation step process (or 0 if we're already installed).
193
- $step = @intval($_GET['step']);
194
- if ($step > 1 && $step != 3 && $dsq_user_api_key) $step = 1;
195
- elseif ($step == 2 && !isset($_POST['dsq_username'])) $step = 1;
196
- $step = (dsq_is_installed()) ? 0 : ($step ? $step : 1);
197
-
198
- // Handle installation process.
199
- if ( 3 == $step && isset($_POST['dsq_forum']) && isset($_POST['dsq_user_api_key']) ) {
200
- list($dsq_forum_id, $dsq_forum_url) = explode(':', $_POST['dsq_forum']);
201
- update_option('disqus_forum_url', $dsq_forum_url);
202
- update_option('disqus_cc_fix', '1');
203
- $api_key = $dsq_api->get_forum_api_key($_POST['dsq_user_api_key'], $dsq_forum_id);
204
- if ( !$api_key || $api_key < 0 ) {
205
- update_option('disqus_replace', 'replace');
206
- dsq_manage_dialog(dsq_i('There was an error completing the installation of Disqus. If you are still having issues, refer to the <a href="https://help.disqus.com/customer/portal/articles/472005-wordpress-troubleshooting">WordPress help page</a>.'), true);
207
- } else {
208
- update_option('disqus_api_key', $api_key);
209
- update_option('disqus_user_api_key', $_POST['dsq_user_api_key']);
210
- update_option('disqus_replace', 'all');
211
- update_option('disqus_active', '1');
212
- }
213
-
214
- if (!empty($_POST['disqus_partner_key'])) {
215
- $partner_key = trim(stripslashes($_POST['disqus_partner_key']));
216
- if (!empty($partner_key)) {
217
- update_option('disqus_partner_key', $partner_key);
218
- }
219
- }
220
- }
221
-
222
- if ( 2 == $step && isset($_POST['dsq_username']) && isset($_POST['dsq_password']) ) {
223
- $dsq_user_api_key = $dsq_api->get_user_api_key($_POST['dsq_username'], $_POST['dsq_password']);
224
- if ( $dsq_user_api_key < 0 || !$dsq_user_api_key ) {
225
- $step = 1;
226
- dsq_manage_dialog($dsq_api->get_last_error(), true);
227
- }
228
-
229
- if ( $step == 2 ) {
230
- $dsq_sites = $dsq_api->get_forum_list($dsq_user_api_key);
231
- if ( $dsq_sites < 0 ) {
232
- $step = 1;
233
- dsq_manage_dialog($dsq_api->get_last_error(), true);
234
- } else if ( !$dsq_sites ) {
235
- $step = 1;
236
- dsq_manage_dialog(dsq_i('There aren\'t any sites associated with this account. Maybe you want to <a href="%s">create a site</a>?', 'https://disqus.com/admin/register/'), true);
237
- }
238
- }
239
- }
240
-
241
- $show_advanced = (isset($_GET['t']) && $_GET['t'] == 'adv');
242
-
243
- ?>
244
- <div class="wrap" id="dsq-wrap">
245
- <ul id="dsq-tabs">
246
- <li<?php if (!$show_advanced) echo ' class="selected"'; ?> id="dsq-tab-main" rel="dsq-main"><?php echo (dsq_is_installed() ? dsq_i('Moderate') : dsq_i('Install')); ?></li>
247
- <li<?php if ($show_advanced) echo ' class="selected"'; ?> id="dsq-tab-advanced" rel="dsq-advanced"><?php echo dsq_i('Plugin Settings'); ?></li>
248
- </ul>
249
-
250
- <div id="dsq-main" class="dsq-content">
251
- <?php
252
- switch ( $step ) {
253
- case 3:
254
- ?>
255
- <div id="dsq-step-3" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
256
- <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
257
-
258
- <p><?php echo dsq_i('Disqus has been installed on your blog.'); ?></p>
259
- <p><?php echo dsq_i('If you have existing comments, you may wish to <a href="?page=disqus&amp;t=adv#export">export them</a> now. Otherwise, you\'re all set, and the Disqus network is now powering comments on your blog.'); ?></p>
260
- <p><a href="edit-comments.php?page=disqus"><?php echo dsq_i('Continue to the moderation dashboard'); ?></a></p>
261
- </div>
262
- <?php
263
- break;
264
- case 2:
265
- ?>
266
- <div id="dsq-step-2" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
267
- <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
268
-
269
- <form method="POST" action="?page=disqus&amp;step=3">
270
- <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
271
- <table class="form-table">
272
- <tr>
273
- <th scope="row" valign="top"><?php echo dsq_i('Select a website'); ?></th>
274
- <td>
275
- <?php
276
- foreach ( $dsq_sites as $counter => $dsq_site ):
277
- ?>
278
- <input name="dsq_forum" type="radio" id="dsq-site-<?php echo $counter; ?>" value="<?php echo $dsq_site->id; ?>:<?php echo $dsq_site->shortname; ?>" />
279
- <label for="dsq-site-<?php echo $counter; ?>"><strong><?php echo htmlspecialchars($dsq_site->name); ?></strong> (<u><?php echo $dsq_site->shortname; ?>.disqus.com</u>)</label>
280
- <br />
281
- <?php
282
- endforeach;
283
- ?>
284
- <hr />
285
- <a href="<?php echo DISQUS_URL; ?>comments/register/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
286
- </td>
287
- </tr>
288
- </table>
289
-
290
- <p class="submit" style="text-align: left">
291
- <input type="hidden" name="dsq_user_api_key" value="<?php echo htmlspecialchars($dsq_user_api_key); ?>"/>
292
- <input name="submit" type="submit" value="Next &raquo;" />
293
- </p>
294
- </form>
295
- </div>
296
- <?php
297
- break;
298
- case 1:
299
- ?>
300
- <div id="dsq-step-1" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
301
- <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
302
-
303
- <form method="POST" action="?page=disqus&amp;step=2">
304
- <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
305
- <table class="form-table">
306
- <tr>
307
- <th scope="row" valign="top"><?php echo dsq_i('Username or email'); ?></th>
308
- <td>
309
- <input id="dsq-username" name="dsq_username" tabindex="1" type="text" />
310
- <a href="https://disqus.com/profile/signup/"><?php echo dsq_i('(don\'t have a Disqus Profile yet?)'); ?></a>
311
- </td>
312
- </tr>
313
- <tr>
314
- <th scope="row" valign="top"><?php echo dsq_i('Password'); ?></th>
315
- <td>
316
- <input type="password" id="dsq-password" name="dsq_password" tabindex="2">
317
- <a href="https://disqus.com/forgot/"><?php echo dsq_i('(forgot your password?)'); ?></a>
318
- </td>
319
- </tr>
320
- </table>
321
-
322
- <p class="submit" style="text-align: left">
323
- <input name="submit" type="submit" value="Next &raquo;" tabindex="3">
324
- </p>
325
-
326
- <script type="text/javascript"> document.getElementById('dsq-username').focus(); </script>
327
- </form>
328
- </div>
329
- <?php
330
- break;
331
- case 0:
332
- $base = is_ssl() ? 'https://' : 'http://';
333
- $url = get_option('disqus_forum_url');
334
- if ($url) { $mod_url = $base.$url.'.'.DISQUS_DOMAIN.'/admin/moderate/'; }
335
- else { $mod_url = DISQUS_URL.'admin/moderate/'; }
336
-
337
- ?>
338
- <div class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
339
- <h2><a href="<?php echo $mod_url ?>"><img src="<?php echo plugins_url( '/media/images/logo.png', __FILE__ ); ?>"></a></h2>
340
- <iframe src="<?php echo $mod_url ?>?template=wordpress" style="width: 100%; height: 80%; min-height: 600px;"></iframe>
341
- </div>
342
- <?php } ?>
343
- </div>
344
-
345
- <?php
346
- $dsq_replace = get_option('disqus_replace');
347
- $dsq_forum_url = strtolower(get_option('disqus_forum_url'));
348
- $dsq_api_key = get_option('disqus_api_key');
349
- $dsq_user_api_key = get_option('disqus_user_api_key');
350
- $dsq_partner_key = get_option('disqus_partner_key');
351
- $dsq_cc_fix = get_option('disqus_cc_fix');
352
- $dsq_manual_sync = get_option('disqus_manual_sync');
353
- $dsq_disable_ssr = get_option('disqus_disable_ssr');
354
- $dsq_public_key = get_option('disqus_public_key');
355
- $dsq_secret_key = get_option('disqus_secret_key');
356
- $dsq_sso_button = get_option('disqus_sso_button');
357
- ?>
358
- <!-- Settings -->
359
- <div id="dsq-advanced" class="dsq-content dsq-advanced"<?php if (!$show_advanced) echo ' style="display:none;"'; ?>>
360
- <h2><?php echo dsq_i('Settings'); ?></h2>
361
- <p><?php echo dsq_i('Version: %s', esc_html(DISQUS_VERSION)); ?></p>
362
- <?php
363
- if (get_option('disqus_active') == '0') {
364
- // disqus is not active
365
- echo dsq_i('<p class="status">Disqus comments are currently <span class="dsq-disabled-text">disabled</span>. (<a href="?page=disqus&amp;active=1">Enable</a>)</p>');
366
- } else {
367
- echo dsq_i('<p class="status">Disqus comments are currently <span class="dsq-enabled-text">enabled</span>. (<a href="?page=disqus&amp;active=0">Disable</a>)</p>');
368
- }
369
- ?>
370
- <form method="POST" enctype="multipart/form-data">
371
- <?php wp_nonce_field('dsq-wpnonce_settings', 'dsq-form_nonce_settings'); ?>
372
- <table class="form-table">
373
-
374
- <tr>
375
- <th scope="row" valign="top"><?php echo dsq_i('<h3>General</h3>'); ?></th>
376
- </tr>
377
- <tr>
378
- <th scope="row" valign="top"><?php echo dsq_i('Forum Shortname'); ?></th>
379
- <td>
380
- <input type="hidden" name="disqus_forum_url" value="<?php echo esc_attr($dsq_forum_url); ?>"/>
381
- <code><?php echo esc_attr($dsq_forum_url); ?></code>
382
- <br />
383
- <?php echo dsq_i('This is the unique identifier for your website in Disqus, automatically set during installation.'); ?>
384
- </td>
385
- </tr>
386
-
387
- <tr>
388
- <th scope="row" valign="top"><?php echo dsq_i('<h3>Appearance</h3>'); ?></th>
389
- </tr>
390
- <tr>
391
- <th scope="row" valign="top"><?php echo dsq_i('Use Disqus Comments on'); ?></th>
392
- <td>
393
- <select name="disqus_replace" tabindex="1" class="disqus-replace">
394
- <option value="all" <?php if($dsq_replace == 'all'){echo 'selected';}?>><?php echo dsq_i('All blog posts.'); ?></option>
395
- <option value="closed" <?php if('closed'==$dsq_replace){echo 'selected';}?>><?php echo dsq_i('Blog posts with closed comments only.'); ?></option>
396
- </select>
397
- <br />
398
- <?php
399
- if ($dsq_replace == 'closed') echo '<p class="dsq-alert">'.dsq_i('You have selected to only enable Disqus on posts with closed comments. If you aren\'t seeing Disqus on new posts, change this option to <strong>All blog posts</strong>.').'</p>';
400
- else echo dsq_i('Shows comments on either all blog posts, or ones with closed comments. Select the <strong>Blog posts with closed comments only</strong> option if you plan on disabling Disqus, but want to keep it on posts which already have comments.');
401
- ?>
402
- </td>
403
- </tr>
404
-
405
- <tr>
406
- <th scope="row" valign="top"><?php echo dsq_i('<h3>Sync</h3>'); ?></th>
407
- </tr>
408
- <tr>
409
- <th scope="row" valign="top"><?php echo dsq_i('Comment Importing'); ?></th>
410
- <td>
411
- <input type="checkbox" id="disqus_manual_sync" name="disqus_manual_sync" <?php if($dsq_manual_sync){echo 'checked="checked"';}?> >
412
- <label for="disqus_manual_sync"><?php echo dsq_i('Disable automated comment importing'); ?></label>
413
- <br /><?php echo dsq_i('If you have problems with WP-Cron taking too long, or have a large number of comments, you may wish to disable automated sync. Comments will only be imported to your local Wordpress database if you do so manually.'); ?>
414
- </td>
415
- </tr>
416
- <tr>
417
- <th scope="row" valign="top"><?php echo dsq_i('Server-Side Rendering'); ?></th>
418
- <td>
419
- <input type="checkbox" id="disqus_disable_ssr" name="disqus_disable_ssr" <?php if($dsq_disable_ssr){echo 'checked="checked"';}?> >
420
- <label for="disqus_disable_ssr"><?php echo dsq_i('Disable server-side rendering of comments'); ?></label>
421
- <br /><?php echo dsq_i('Hides comments from nearly all search engines.'); ?>
422
- </td>
423
- </tr>
424
-
425
- <tr>
426
- <th scope="row" valign="top"><?php echo dsq_i('<h3>Patches</h3>'); ?></th>
427
- </tr>
428
-
429
- <tr>
430
- <th scope="row" valign="top"><?php echo dsq_i('Template Conflicts'); ?></th>
431
- <td>
432
- <input type="checkbox" id="disqus_comment_count" name="disqus_cc_fix" <?php if($dsq_cc_fix == '1'){ echo 'checked="checked"'; } ?> >
433
- <label for="disqus_comment_count"><?php echo dsq_i('Output JavaScript in footer'); ?></label>
434
- <br /><?php echo dsq_i('Enable this if you have problems with comment counts or other irregularities. For example: missing counts, counts always at 0, Disqus code showing on the page, broken image carousels, or longer-than-usual home page load times (<a href="%s" onclick="window.open(this.href); return false">more info</a>).', 'https://help.disqus.com/customer/portal/articles/472005-wordpress-troubleshooting'); ?>
435
- </td>
436
- </tr>
437
-
438
- <tr>
439
- <th scope="row" valign="top" colspan="2"><?php echo dsq_i('<h3>Advanced</h3><h4>Single Sign-On</h4><p>Allows users to log in to Disqus via WordPress. (<a href="%s" onclick="window.open(this.href); return false">More info on SSO</a>)</p>', 'https://help.disqus.com/customer/portal/articles/684744'); ?></th>
440
- </tr>
441
- <?php if (!empty($dsq_partner_key)) {// this option only shows if it was already present ?>
442
- <tr>
443
- <th scope="row" valign="top"><?php echo dsq_i('Disqus Partner Key'); ?></th>
444
- <td>
445
- <input type="text" name="disqus_partner_key" value="<?php echo esc_attr($dsq_partner_key); ?>" tabindex="2">
446
- </td>
447
- </tr>
448
- <?php } ?>
449
- <tr>
450
- <th scope="row" valign="top"><?php echo dsq_i('API Application Public Key'); ?></th>
451
- <td>
452
- <input type="text" name="disqus_public_key" value="<?php echo esc_attr($dsq_public_key); ?>" tabindex="2">
453
- <br />
454
- <?php echo dsq_i('Found at <a href="%s">Disqus API Applications</a>.','https://disqus.com/api/applications/'); ?>
455
- </td>
456
- </tr>
457
- <tr>
458
- <th scope="row" valign="top"><?php echo dsq_i('API Application Secret Key'); ?></th>
459
- <td>
460
- <input type="text" name="disqus_secret_key" value="<?php echo esc_attr($dsq_secret_key); ?>" tabindex="2">
461
- <br />
462
- <?php echo dsq_i('Found at <a href="%s">Disqus API Applications</a>.','https://disqus.com/api/applications/'); ?>
463
- </td>
464
- </tr>
465
- <tr>
466
- <th scope="row" valign="top"><?php echo dsq_i('Custom Log-in Button'); ?></th>
467
- <td>
468
- <?php if (!empty($dsq_sso_button)) { ?>
469
- <img src="<?php echo esc_attr($dsq_sso_button); ?>" alt="<?php echo esc_attr($dsq_sso_button); ?>" />
470
- <br />
471
- <?php } ?>
472
-
473
- <?php if ( version_compare($wp_version, '3.5', '>=') ) {
474
- // HACK: Use WP's new (as of WP 3.5), streamlined, much-improved built-in media uploader
475
-
476
- // Use WP 3.5's new consolidated call to get all necessary media uploader scripts and styles
477
- wp_enqueue_media(); ?>
478
-
479
- <script type="text/javascript">
480
- // Uploading files
481
- var file_frame;
482
-
483
- jQuery('.upload_image_button').live('click', function( event ){
484
-
485
- event.preventDefault();
486
-
487
- // If the media frame already exists, reopen it.
488
- if ( file_frame ) {
489
- file_frame.open();
490
- return;
491
- }
492
-
493
- // Create the media frame.
494
- file_frame = wp.media.frames.file_frame = wp.media({
495
- title: jQuery( this ).data( 'uploader_title' ),
496
- button: {
497
- text: jQuery( this ).data( 'uploader_button_text' ),
498
- },
499
- multiple: false // Set to true to allow multiple files to be selected
500
- });
501
-
502
- // When an image is selected, run a callback.
503
- file_frame.on( 'select', function() {
504
- // We set multiple to false so only get one image from the uploader
505
- attachment = file_frame.state().get('selection').first().toJSON();
506
-
507
- // Do something with attachment.id and/or attachment.url here
508
- jQuery('#disqus_sso_button').val(attachment.url);
509
- });
510
-
511
- // Finally, open the modal
512
- file_frame.open();
513
- });
514
- </script>
515
-
516
- <input type="button" value="<?php echo ($dsq_sso_button ? dsq_i('Change') : dsq_i('Choose')).' '.dsq_i('button'); ?>" class="button upload_image_button" tabindex="2">
517
- <input type="hidden" name="disqus_sso_button" id="disqus_sso_button" value=""/>
518
- <?php } else { // use pre-WP 3.5 media upload functionality ?>
519
- <input type="file" name="disqus_sso_button" value="<?php echo esc_attr($dsq_sso_button); ?>" tabindex="2">
520
- <?php } ?>
521
- <br />
522
- <?php echo dsq_i('Adds a button to the Disqus log-in interface. (<a href="%s">Example screenshot</a>.)','https://d8v2sqslxfuhj.cloudfront.net/docs/sso-button.png'); ?>
523
- <?php echo dsq_i('<br />See <a href="%s">our SSO button documentation</a> for a template to create your own button.','https://help.disqus.com/customer/portal/articles/236206#sso-login-button'); ?>
524
- </td>
525
- </tr>
526
-
527
- </table>
528
-
529
- <p class="submit" style="text-align: left">
530
- <input type="hidden" name="disqus_api_key" value="<?php echo esc_attr($dsq_api_key); ?>"/>
531
- <input type="hidden" name="disqus_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
532
- <input name="submit" type="submit" value="Save" class="button-primary button" tabindex="4">
533
- </p>
534
- </form>
535
-
536
- <h3>Import and Export</h3>
537
-
538
- <table class="form-table">
539
- <?php if (DISQUS_CAN_EXPORT): ?>
540
- <tr id="export">
541
- <th scope="row" valign="top"><?php echo dsq_i('Export comments to Disqus'); ?></th>
542
- <td>
543
- <div id="dsq_export">
544
- <p class="status"><a href="#" class="button"><?php echo dsq_i('Export Comments'); ?></a> <?php echo dsq_i('This will export your existing WordPress comments to Disqus'); ?></p>
545
- </div>
546
- </td>
547
- </tr>
548
- <?php endif; ?>
549
- <tr>
550
- <th scope="row" valign="top"><?php echo dsq_i('Sync Disqus with WordPress'); ?></th>
551
- <td>
552
- <div id="dsq_import">
553
- <div class="status">
554
- <p><a href="#" class="button"><?php echo dsq_i('Sync Comments'); ?></a> <?php echo dsq_i('This will download your Disqus comments and store them locally in WordPress'); ?></p>
555
- <label><input type="checkbox" id="dsq_import_wipe" name="dsq_import_wipe" value="1"/> <?php echo dsq_i('Remove all imported Disqus comments before syncing.'); ?></label><br/>
556
- </div>
557
- </div>
558
- </td>
559
- </tr>
560
- </table>
561
-
562
- <h3>Reset</h3>
563
-
564
- <table class="form-table">
565
- <tr>
566
- <th scope="row" valign="top"><?php echo dsq_i('Reset Disqus'); ?></th>
567
- <td>
568
- <form action="?page=disqus" method="POST">
569
- <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
570
- <p><input type="submit" value="Reset" name="reset" onclick="return confirm('<?php echo dsq_i('Are you sure you want to reset the Disqus plugin?'); ?>')" class="button" /> <?php echo dsq_i('This removes all Disqus-specific settings. Comments will remain unaffected.') ?></p>
571
- <?php echo dsq_i('If you have problems with resetting taking too long you may wish to first manually drop the <code>disqus_dupecheck</code> index from your <code>commentmeta</code> table.') ?>
572
- </form>
573
- </td>
574
- </tr>
575
- </table>
576
- <br/>
577
-
578
- <h3><?php echo dsq_i('Debug Information'); ?></h3>
579
- <p><?php echo dsq_i('Having problems with the plugin? Check out our <a href="%s" onclick="window.open(this.href); return false">WordPress Troubleshooting</a> documentation. You can also <a href="%s">drop us a line</a> including the following details and we\'ll do what we can.', 'https://help.disqus.com/customer/portal/articles/472005-wordpress-troubleshooting', 'mailto:help+wp@disqus.com'); ?></p>
580
- <textarea style="width:90%; height:200px;">
581
- URL: <?php echo esc_attr(get_option('siteurl')); ?>
582
-
583
- PHP Version: <?php echo phpversion(); ?>
584
-
585
- Version: <?php echo $wp_version; ?>
586
-
587
- Active Theme:
588
- <?php
589
- if ( !function_exists('wp_get_theme') ) {
590
- $theme = get_theme(get_current_theme());
591
- echo $theme['Name'] . ' ' . $theme['Version'];
592
- } else {
593
- $theme = wp_get_theme();
594
- echo $theme->Name . ' ' . $theme->Version;
595
- }
596
- ?>
597
-
598
- URLOpen Method: <?php echo dsq_url_method(); ?>
599
-
600
- Plugin Version: <?php echo DISQUS_VERSION; ?>
601
-
602
- Settings:
603
- dsq_is_installed: <?php echo dsq_is_installed(); ?>
604
- <?php foreach (dsq_options() as $opt) {
605
- echo $opt.': '.esc_attr(get_option($opt))."\n";
606
- }
607
- ?>
608
-
609
- Plugins:
610
- <?php
611
- foreach (get_plugins() as $key => $plugin) {
612
- $isactive = "";
613
- if (is_plugin_active($key)) {
614
- $isactive = "(active)";
615
- }
616
- echo $plugin['Name'].' '.$plugin['Version'].' '.$isactive."\n";
617
- }
618
- ?>
619
- </textarea><br/>
620
- </div>
621
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // HACK: For old versions of WordPress
3
+ if ( !function_exists('wp_nonce_field') ) {
4
+ function wp_nonce_field() {}
5
+ }
6
+
7
+ global $dsq_api;
8
+
9
+ require(ABSPATH . 'wp-includes/version.php');
10
+
11
+ if ( !current_user_can('moderate_comments') ) {
12
+ die('The account you\'re logged in to doesn\'t have permission to access this page.');
13
+ }
14
+
15
+ function has_valid_nonce() {
16
+ $nonce_actions = array('upgrade', 'reset', 'install', 'settings', 'active');
17
+ $nonce_form_prefix = 'dsq-form_nonce_';
18
+ $nonce_action_prefix = 'dsq-wpnonce_';
19
+
20
+ // Check all available nonce actions
21
+ foreach ( $nonce_actions as $key => $value ) {
22
+ if ( isset($_POST[$nonce_form_prefix.$value]) ) {
23
+ check_admin_referer($nonce_action_prefix.$value, $nonce_form_prefix.$value);
24
+ return true;
25
+ }
26
+ }
27
+
28
+ return false;
29
+ }
30
+
31
+ if ( ! empty($_POST) ) {
32
+ $nonce_result_check = has_valid_nonce();
33
+ if ($nonce_result_check === false) {
34
+ die('Unable to save changes. Make sure you are accessing this page from the Wordpress dashboard.');
35
+ }
36
+ }
37
+
38
+ if( isset($_POST['dsq_username']) ) {
39
+ $_POST['dsq_username'] = stripslashes($_POST['dsq_username']);
40
+ }
41
+
42
+ if( isset($_POST['dsq_password']) ) {
43
+ $_POST['dsq_password'] = stripslashes($_POST['dsq_password']);
44
+ }
45
+
46
+ // Handle export function.
47
+ if( isset($_POST['export']) and DISQUS_CAN_EXPORT ) {
48
+ require_once(dirname(__FILE__) . '/export.php');
49
+ dsq_export_wp();
50
+ }
51
+
52
+ // Handle resetting.
53
+ if ( isset($_POST['reset']) ) {
54
+ foreach (dsq_options() as $opt) {
55
+ delete_option($opt);
56
+ }
57
+ unset($_POST);
58
+ dsq_reset_database();
59
+ ?>
60
+
61
+ <div class="wrap">
62
+ <h2><?php echo dsq_i('Disqus Reset'); ?></h2>
63
+ <form method="POST" action="?page=disqus">
64
+ <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
65
+ <p><?php echo dsq_i('Disqus has been reset successfully.') ?></p>
66
+ <ul style="list-style: circle;padding-left:20px;">
67
+ <li><?php echo dsq_i('Local settings for the plugin were removed.') ?></li>
68
+ <li><?php echo dsq_i('Database changes by Disqus were reverted.') ?></li>
69
+ </ul>
70
+ <p>
71
+ <?php echo dsq_i('If you wish to reinstall, you can do that now.') ?>
72
+ <a href="?page=disqus&amp;step=1">&nbsp;<?php echo dsq_i('Reinstall') ?></a>
73
+ </p>
74
+ </form>
75
+ </div>
76
+ <?php
77
+ die();
78
+ }
79
+
80
+ // Post fields that require verification.
81
+ $check_fields = array(
82
+ 'dsq_user_api_key' => array(
83
+ 'key_name' => 'dsq_user_api_key',
84
+ 'min' => 64,
85
+ 'max' => 64,
86
+ ),
87
+ 'disqus_api_key' => array(
88
+ 'key_name' => 'disqus_api_key',
89
+ 'min' => 64,
90
+ 'max' => 64,
91
+ ),
92
+ 'disqus_public_key' => array(
93
+ 'key_name' => 'disqus_public_key',
94
+ 'min' => 64,
95
+ 'max' => 64,
96
+ ),
97
+ 'disqus_secret_key' => array(
98
+ 'key_name' => 'disqus_secret_key',
99
+ 'min' => 64,
100
+ 'max' => 64,
101
+ ),
102
+ 'disqus_partner_key' => array(
103
+ 'key_name' => 'disqus_partner_key',
104
+ 'min' => 64,
105
+ 'max' => 64,
106
+ ),
107
+ 'dsq_forum' => array(
108
+ 'key_name' => 'dsq_forum',
109
+ 'min' => 1,
110
+ 'max' => 64,
111
+ ),
112
+ 'disqus_forum_url' => array(
113
+ 'key_name' => 'disqus_forum_url',
114
+ 'min' => 1,
115
+ 'max' => 64,
116
+ ),
117
+ 'disqus_replace' => array(
118
+ 'key_name' => 'disqus_replace',
119
+ 'min' => 3,
120
+ 'max' => 6,
121
+ ),
122
+ 'dsq_username' => array(
123
+ 'key_name' => 'dsq_username',
124
+ 'min' => 3,
125
+ 'max' => 250,
126
+ ),
127
+ );
128
+
129
+ // Check keys keys and remove bad input.
130
+ foreach ( $check_fields as $key ) {
131
+
132
+ if ( isset($_POST[$key['key_name']]) ) {
133
+
134
+ // Strip tags before checking
135
+ $_POST[$key['key_name']] = trim(strip_tags($_POST[$key['key_name']]));
136
+
137
+ // Check usernames independently because they can have special characters
138
+ // or be email addresses
139
+ if ( 'dsq_username' === $key['key_name'] ) {
140
+ if ( !is_valid_dsq_username($_POST[$key['key_name']], $key['min'], $key['max']) ) {
141
+ unset($_POST[$key['key_name']]);
142
+ }
143
+ }
144
+ else {
145
+ if ( !is_valid_dsq_key($_POST[$key['key_name']], $key['min'], $key['max']) ) {
146
+ unset($_POST[$key['key_name']]);
147
+ }
148
+ }
149
+ }
150
+ }
151
+
152
+ function is_valid_dsq_username($value, $min=3, $max=250) {
153
+ if ( is_email($value) ) {
154
+ return true;
155
+ }
156
+ else {
157
+ return is_valid_dsq_key($value, $min, $max);
158
+ }
159
+ }
160
+
161
+ function is_valid_dsq_key($value, $min=1, $max=64) {
162
+ return preg_match('/^[\0-9\\:A-Za-z_-]{'.$min.','.$max.'}+$/', $value);
163
+ }
164
+
165
+ // Handle advanced options.
166
+ if ( isset($_POST['disqus_forum_url']) && isset($_POST['disqus_replace']) ) {
167
+ update_option('disqus_partner_key', isset($_POST['disqus_partner_key']) ? esc_attr( trim(stripslashes($_POST['disqus_partner_key'])) ) : '');
168
+ update_option('disqus_replace', isset($_POST['disqus_replace']) ? esc_attr( $_POST['disqus_replace'] ) : 'all');
169
+ update_option('disqus_cc_fix', isset($_POST['disqus_cc_fix']));
170
+ update_option('disqus_manual_sync', isset($_POST['disqus_manual_sync']));
171
+ update_option('disqus_disable_ssr', isset($_POST['disqus_disable_ssr']));
172
+ update_option('disqus_public_key', isset($_POST['disqus_public_key']) ? esc_attr( $_POST['disqus_public_key'] ) : '');
173
+ update_option('disqus_secret_key', isset($_POST['disqus_secret_key']) ? esc_attr( $_POST['disqus_secret_key'] ) : '');
174
+ // Handle SSO button uploads
175
+ if ( version_compare($wp_version, '3.5', '>=') ) {
176
+ // Use WP 3.5's new, streamlined, much-improved built-in media uploader
177
+
178
+ // Only update if a value is actually POSTed, otherwise any time the form is saved the button will be un-set
179
+ if ( $_POST['disqus_sso_button'] ) {
180
+ update_option('disqus_sso_button', isset($_POST['disqus_sso_button']) ? esc_url( $_POST['disqus_sso_button'] ) : '');
181
+ }
182
+ } else {
183
+ // WP is older than 3.5, use legacy, less-elegant media uploader
184
+ if(isset($_FILES['disqus_sso_button'])) {
185
+ dsq_image_upload_handler('disqus_sso_button');
186
+ }
187
+ }
188
+ dsq_manage_dialog(dsq_i('Your settings have been changed.'));
189
+ }
190
+
191
+ // handle disqus_active
192
+ if ( isset($_POST['active']) && isset($_GET['active']) ) {
193
+ update_option('disqus_active', ($_GET['active'] == '1' ? '1' : '0'));
194
+ }
195
+
196
+ $dsq_user_api_key = isset($_POST['dsq_user_api_key']) ? $_POST['dsq_user_api_key'] : null;
197
+
198
+ // Get installation step process (or 0 if we're already installed).
199
+ $step = @intval($_GET['step']);
200
+ if ($step > 1 && $step != 3 && $dsq_user_api_key) $step = 1;
201
+ elseif ($step == 2 && !isset($_POST['dsq_username'])) $step = 1;
202
+ $step = (dsq_is_installed()) ? 0 : ($step ? $step : 1);
203
+
204
+ // Handle installation process.
205
+ if ( 3 == $step && isset($_POST['dsq_forum']) && isset($_POST['dsq_user_api_key']) ) {
206
+ list($dsq_forum_id, $dsq_forum_url) = explode(':', $_POST['dsq_forum']);
207
+ update_option('disqus_forum_url', esc_attr( $dsq_forum_url ) );
208
+ update_option('disqus_cc_fix', '1');
209
+ $api_key = $dsq_api->get_forum_api_key($_POST['dsq_user_api_key'], $dsq_forum_id);
210
+ if ( !$api_key || $api_key < 0 ) {
211
+ update_option('disqus_replace', 'replace');
212
+ dsq_manage_dialog(
213
+ dsq_i('There was an error completing the installation of Disqus.')
214
+ . ' '
215
+ . dsq_i('If you are still having issues, refer to the help documentation.')
216
+ . ' '
217
+ . '<a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank">'
218
+ . dsq_i('WordPress Help Page')
219
+ . '</a>',
220
+ true);
221
+ } else {
222
+ update_option('disqus_api_key', esc_attr( $api_key ));
223
+ update_option('disqus_user_api_key', esc_attr( $_POST['dsq_user_api_key']) );
224
+ update_option('disqus_replace', 'all');
225
+ update_option('disqus_active', '1');
226
+ }
227
+
228
+ if (!empty($_POST['disqus_partner_key'])) {
229
+ $partner_key = trim(stripslashes($_POST['disqus_partner_key']));
230
+ if (!empty($partner_key)) {
231
+ update_option('disqus_partner_key', $partner_key);
232
+ }
233
+ }
234
+ }
235
+
236
+ if ( 2 == $step && isset($_POST['dsq_username']) && isset($_POST['dsq_password']) ) {
237
+ $dsq_user_api_key = $dsq_api->get_user_api_key($_POST['dsq_username'], $_POST['dsq_password']);
238
+ if ( $dsq_user_api_key < 0 || !$dsq_user_api_key ) {
239
+ $step = 1;
240
+ dsq_manage_dialog($dsq_api->get_last_error(), true);
241
+ }
242
+
243
+ if ( $step == 2 ) {
244
+ $dsq_sites = $dsq_api->get_forum_list($dsq_user_api_key);
245
+ if ( $dsq_sites < 0 ) {
246
+ $step = 1;
247
+ dsq_manage_dialog($dsq_api->get_last_error(), true);
248
+ } else if ( !$dsq_sites ) {
249
+ $step = 1;
250
+ dsq_manage_dialog(
251
+ dsq_i('There aren\'t any sites associated with this account. Maybe you want to create a site?')
252
+ . ' '
253
+ . '<a href="https://disqus.com/admin/register/" target="_blank">'
254
+ . dsq_i('Create a site')
255
+ . '</a>',
256
+ true);
257
+ }
258
+ }
259
+ }
260
+
261
+ $show_advanced = (isset($_GET['t']) && $_GET['t'] == 'adv');
262
+
263
+ ?>
264
+ <div class="wrap" id="dsq-wrap">
265
+ <ul id="dsq-tabs">
266
+ <li<?php if (!$show_advanced) echo ' class="selected"'; ?> id="dsq-tab-main" rel="dsq-main">
267
+ <?php echo (dsq_is_installed() ? dsq_i('Moderate') : dsq_i('Install')); ?>
268
+ </li>
269
+ <li<?php if ($show_advanced) echo ' class="selected"'; ?> id="dsq-tab-advanced" rel="dsq-advanced">
270
+ <?php echo dsq_i('Plugin Settings'); ?>
271
+ </li>
272
+ </ul>
273
+
274
+ <div id="dsq-main" class="dsq-content">
275
+ <?php
276
+ switch ( $step ) {
277
+ case 3:
278
+ ?>
279
+ <div id="dsq-step-3" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
280
+ <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
281
+
282
+ <p><?php echo dsq_i('Disqus has been installed on your blog.'); ?></p>
283
+ <p>
284
+ <?php echo dsq_i('If you have existing comments, you may wish to export them now.') ?>&nbsp;
285
+ <?php echo dsq_i('Otherwise, you\'re all set, and the Disqus network is now powering comments on your site.'); ?>
286
+ </p>
287
+ <p><a href="edit-comments.php?page=disqus"><?php echo dsq_i('Continue to the moderation dashboard'); ?></a></p>
288
+ </div>
289
+ <?php
290
+ break;
291
+ case 2:
292
+ ?>
293
+ <div id="dsq-step-2" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
294
+ <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
295
+
296
+ <form method="POST" action="?page=disqus&amp;step=3">
297
+ <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
298
+ <table class="form-table">
299
+ <tr>
300
+ <th scope="row" valign="top"><?php echo dsq_i('Select a website'); ?></th>
301
+ <td>
302
+ <?php
303
+ foreach ( $dsq_sites as $counter => $dsq_site ):
304
+ ?>
305
+ <input name="dsq_forum" type="radio" id="dsq-site-<?php echo esc_attr($counter); ?>" value="<?php echo esc_attr($dsq_site->id); ?>:<?php echo esc_attr($dsq_site->shortname); ?>" />
306
+ <label for="dsq-site-<?php echo esc_attr($counter); ?>"><strong><?php echo esc_attr($dsq_site->name); ?></strong> (<u><?php echo esc_attr($dsq_site->shortname); ?>.disqus.com</u>)</label>
307
+ <br />
308
+ <?php
309
+ endforeach;
310
+ ?>
311
+ <hr />
312
+ <a href="https://disqus.com/admin/signup/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
313
+ </td>
314
+ </tr>
315
+ </table>
316
+
317
+ <p class="submit" style="text-align: left">
318
+ <input type="hidden" name="dsq_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
319
+ <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" />
320
+ </p>
321
+ </form>
322
+ </div>
323
+ <?php
324
+ break;
325
+ case 1:
326
+ ?>
327
+ <div id="dsq-step-1" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
328
+ <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
329
+
330
+ <form method="POST" action="?page=disqus&amp;step=2">
331
+ <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
332
+ <table class="form-table">
333
+ <tr>
334
+ <th scope="row" valign="top"><?php echo dsq_i('Username or email'); ?></th>
335
+ <td>
336
+ <input id="dsq-username" name="dsq_username" tabindex="1" type="text" />
337
+ (<a href="https://disqus.com/profile/signup/"><?php echo dsq_i('don\'t have a Disqus Profile yet?'); ?></a>)
338
+ </td>
339
+ </tr>
340
+ <tr>
341
+ <th scope="row" valign="top"><?php echo dsq_i('Password'); ?></th>
342
+ <td>
343
+ <input type="password" id="dsq-password" name="dsq_password" tabindex="2">
344
+ (<a href="https://disqus.com/forgot/"><?php echo dsq_i('forgot your password?'); ?></a>)
345
+ </td>
346
+ </tr>
347
+ </table>
348
+
349
+ <p class="submit" style="text-align: left">
350
+ <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" tabindex="3">
351
+ </p>
352
+ </form>
353
+ </div>
354
+ <?php
355
+ break;
356
+ case 0:
357
+ $url = get_option('disqus_forum_url');
358
+ if ($url) { $mod_url = 'https://'.$url.'.disqus.com/admin/moderate/'; }
359
+ else { $mod_url = 'https://disqus.com/admin/moderate/'; }
360
+
361
+ ?>
362
+ <div class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
363
+ <h2><a href="<?php echo esc_attr( $mod_url ) ?>"><img src="<?php echo esc_attr( plugins_url( '/media/images/logo.png', __FILE__ ) ); ?>"></a></h2>
364
+ <a class="button-primary button" href="<?php echo esc_attr( $mod_url ) ?>" target="_blank"><?php echo dsq_i('Go to Disqus Moderation'); ?></a>
365
+ </div>
366
+ <?php } ?>
367
+ </div>
368
+
369
+ <?php
370
+ $dsq_replace = get_option('disqus_replace');
371
+ $dsq_forum_url = strtolower(get_option('disqus_forum_url'));
372
+ $dsq_api_key = get_option('disqus_api_key');
373
+ $dsq_user_api_key = get_option('disqus_user_api_key');
374
+ $dsq_partner_key = get_option('disqus_partner_key');
375
+ $dsq_cc_fix = get_option('disqus_cc_fix');
376
+ $dsq_manual_sync = get_option('disqus_manual_sync');
377
+ $dsq_disable_ssr = get_option('disqus_disable_ssr');
378
+ $dsq_public_key = get_option('disqus_public_key');
379
+ $dsq_secret_key = get_option('disqus_secret_key');
380
+ $dsq_sso_button = get_option('disqus_sso_button');
381
+ $disqus_enabled = get_option('disqus_active') == '1';
382
+ $disqus_enabled_state = $disqus_enabled ? 'enabled' : 'disabled';
383
+ ?>
384
+ <!-- Settings -->
385
+ <div id="dsq-advanced" class="dsq-content dsq-advanced"<?php if (!$show_advanced) echo ' style="display:none;"'; ?>>
386
+ <h2><?php echo dsq_i('Settings'); ?></h2>
387
+ <p><?php echo dsq_i('Version: %s', esc_html(DISQUS_VERSION)); ?></p>
388
+
389
+ <!-- Enable/disable Disqus toggle -->
390
+ <form method="POST" action="?page=disqus&amp;active=<?php echo (string)((int)($disqus_enabled != true)); ?>">
391
+ <?php wp_nonce_field('dsq-wpnonce_active', 'dsq-form_nonce_active'); ?>
392
+ <p class="status">
393
+ <?php echo dsq_i('Disqus comments are currently '); ?>
394
+ <span class="dsq-<?php echo esc_attr( $disqus_enabled_state ); ?>-text"><?php echo $disqus_enabled_state; ?></span>
395
+ </p>
396
+ <input type="submit" name="active" class="button" value="<?php echo $disqus_enabled ? dsq_i('Disable') : dsq_i('Enable'); ?>" />
397
+ </form>
398
+
399
+ <!-- Configuration form -->
400
+ <form method="POST" enctype="multipart/form-data">
401
+ <?php wp_nonce_field('dsq-wpnonce_settings', 'dsq-form_nonce_settings'); ?>
402
+ <table class="form-table">
403
+
404
+ <tr>
405
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('General') . '</h3>'; ?></th>
406
+ </tr>
407
+ <tr>
408
+ <th scope="row" valign="top"><?php echo dsq_i('Forum Shortname'); ?></th>
409
+ <td>
410
+ <input type="hidden" name="disqus_forum_url" value="<?php echo esc_attr($dsq_forum_url); ?>"/>
411
+ <code><?php echo esc_attr($dsq_forum_url); ?></code>
412
+ <br />
413
+ <?php echo dsq_i('This is the unique identifier for your website in Disqus, automatically set during installation.'); ?>
414
+ </td>
415
+ </tr>
416
+
417
+ <tr>
418
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Appearance') . '</h3>'; ?></th>
419
+ </tr>
420
+ <tr>
421
+ <th scope="row" valign="top"><?php echo dsq_i('Use Disqus Comments on'); ?></th>
422
+ <td>
423
+ <select name="disqus_replace" tabindex="1" class="disqus-replace">
424
+ <option value="all" <?php if($dsq_replace == 'all'){echo 'selected';}?>><?php echo dsq_i('All blog posts.'); ?></option>
425
+ <option value="closed" <?php if('closed'==$dsq_replace){echo 'selected';}?>><?php echo dsq_i('Blog posts with closed comments only.'); ?></option>
426
+ </select>
427
+ <br />
428
+ <?php
429
+ if ($dsq_replace == 'closed') echo '<p class="dsq-alert">'.dsq_i('You have selected to only enable Disqus on posts with closed comments. If you aren\'t seeing Disqus on new posts, change this option to "All blog posts".').'</p>';
430
+ else echo dsq_i('Shows comments on either all blog posts, or ones with closed comments. Select the "Blog posts with closed comments only" option if you plan on disabling Disqus, but want to keep it on posts which already have comments.');
431
+ ?>
432
+ </td>
433
+ </tr>
434
+
435
+ <tr>
436
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Sync') . '</h3>'; ?></th>
437
+ </tr>
438
+ <tr>
439
+ <th scope="row" valign="top"><?php echo dsq_i('Comment Importing'); ?></th>
440
+ <td>
441
+ <input type="checkbox" id="disqus_manual_sync" name="disqus_manual_sync" <?php if($dsq_manual_sync){echo 'checked="checked"';}?> >
442
+ <label for="disqus_manual_sync"><?php echo dsq_i('Disable automated comment importing'); ?></label>
443
+ <br /><?php echo dsq_i('If you have problems with WP-Cron taking too long, or have a large number of comments, you may wish to disable automated sync. Comments will only be imported to your local Wordpress database if you do so manually.'); ?>
444
+ </td>
445
+ </tr>
446
+ <tr>
447
+ <th scope="row" valign="top"><?php echo dsq_i('Server-Side Rendering'); ?></th>
448
+ <td>
449
+ <input type="checkbox" id="disqus_disable_ssr" name="disqus_disable_ssr" <?php if($dsq_disable_ssr){echo 'checked="checked"';}?> >
450
+ <label for="disqus_disable_ssr"><?php echo dsq_i('Disable server-side rendering of comments'); ?></label>
451
+ <br /><?php echo dsq_i('Hides comments from nearly all search engines.'); ?>
452
+ </td>
453
+ </tr>
454
+
455
+ <tr>
456
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Patches') . '</h3>'; ?></th>
457
+ </tr>
458
+
459
+ <tr>
460
+ <th scope="row" valign="top"><?php echo dsq_i('Template Conflicts'); ?></th>
461
+ <td>
462
+ <input type="checkbox" id="disqus_comment_count" name="disqus_cc_fix" <?php if($dsq_cc_fix == '1'){ echo 'checked="checked"'; } ?> >
463
+ <label for="disqus_comment_count"><?php echo dsq_i('Output JavaScript in footer'); ?></label>
464
+ <br /><?php echo dsq_i('Enable this if you have problems with comment counts or other irregularities. For example: missing counts, counts always at 0, Disqus code showing on the page, broken image carousels, or longer-than-usual home page load times'); ?>
465
+ </td>
466
+ </tr>
467
+
468
+ <tr>
469
+ <th scope="row" valign="top" colspan="2">
470
+ <h3><?php echo dsq_i('Advanced'); ?></h3>
471
+ <h4><?php echo dsq_i('Single Sign-On'); ?></h4>
472
+ <p>
473
+ <?php echo dsq_i('Allows users to log in to Disqus via WordPress.'); ?>
474
+ <a href="https://help.disqus.com/customer/portal/articles/684744" target="_blank">
475
+ <?php echo dsq_i('More info on SSO'); ?>
476
+ </a>
477
+ </p>
478
+ </th>
479
+ </tr>
480
+ <?php if (!empty($dsq_partner_key)) {// this option only shows if it was already present ?>
481
+ <tr>
482
+ <th scope="row" valign="top"><?php echo dsq_i('Disqus Partner Key'); ?></th>
483
+ <td>
484
+ <input type="text" name="disqus_partner_key" value="<?php echo esc_attr($dsq_partner_key); ?>" tabindex="2">
485
+ </td>
486
+ </tr>
487
+ <?php } ?>
488
+ <tr>
489
+ <th scope="row" valign="top"><?php echo dsq_i('API Application Public Key'); ?></th>
490
+ <td>
491
+ <input type="text" name="disqus_public_key" value="<?php echo esc_attr($dsq_public_key); ?>" tabindex="2">
492
+ <br />
493
+ <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
494
+ </td>
495
+ </tr>
496
+ <tr>
497
+ <th scope="row" valign="top"><?php echo dsq_i('API Application Secret Key'); ?></th>
498
+ <td>
499
+ <input type="text" name="disqus_secret_key" value="<?php echo esc_attr($dsq_secret_key); ?>" tabindex="2">
500
+ <br />
501
+ <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
502
+ </td>
503
+ </tr>
504
+ <tr>
505
+ <th scope="row" valign="top"><?php echo dsq_i('Custom Log-in Button'); ?></th>
506
+ <td>
507
+ <?php if (!empty($dsq_sso_button)) { ?>
508
+ <img src="<?php echo esc_attr($dsq_sso_button); ?>" alt="<?php echo esc_attr($dsq_sso_button); ?>" />
509
+ <br />
510
+ <?php } ?>
511
+
512
+ <?php if ( version_compare($wp_version, '3.5', '>=') ) {
513
+ // HACK: Use WP's new (as of WP 3.5), streamlined, much-improved built-in media uploader
514
+
515
+ // Use WP 3.5's new consolidated call to get all necessary media uploader scripts and styles
516
+ wp_enqueue_media();
517
+ ?>
518
+
519
+ <input type="button" value="<?php echo ($dsq_sso_button ? dsq_i('Change') : dsq_i('Choose')).' '.dsq_i('button'); ?>" class="button upload_image_button" tabindex="2">
520
+ <input type="hidden" name="disqus_sso_button" id="disqus_sso_button" value=""/>
521
+ <?php } else { // use pre-WP 3.5 media upload functionality ?>
522
+ <input type="file" name="disqus_sso_button" value="<?php echo esc_attr($dsq_sso_button); ?>" tabindex="2">
523
+ <?php } ?>
524
+ <br />
525
+ <?php echo dsq_i('Adds a button to the Disqus log-in interface.'); ?>
526
+ (<a href="https://d8v2sqslxfuhj.cloudfront.net/docs/sso-button.png" target="_blank"><?php echo dsq_i('Example screenshot'); ?></a>)
527
+ <br />
528
+ <?php echo dsq_i('See our documentation for a template to create your own button.'); ?>&nbsp;
529
+ <a href="https://help.disqus.com/customer/portal/articles/236206#sso-login-button"><?php echo dsq_i('SSO button documentation'); ?></a>
530
+ </td>
531
+ </tr>
532
+
533
+ </table>
534
+
535
+ <p class="submit" style="text-align: left">
536
+ <input type="hidden" name="disqus_api_key" value="<?php echo esc_attr($dsq_api_key); ?>"/>
537
+ <input type="hidden" name="disqus_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
538
+ <input name="submit" type="submit" value="Save" class="button-primary button" tabindex="4">
539
+ </p>
540
+ </form>
541
+
542
+ <h3>Import and Export</h3>
543
+
544
+ <table class="form-table">
545
+ <?php if (DISQUS_CAN_EXPORT): ?>
546
+ <tr id="export">
547
+ <th scope="row" valign="top"><?php echo dsq_i('Export comments to Disqus'); ?></th>
548
+ <td>
549
+ <div id="dsq_export">
550
+ <form method="POST" action="">
551
+ <?php wp_nonce_field('dsq-wpnonce_export', 'dsq-form_nonce_export'); ?>
552
+ <p class="status">
553
+ <a href="#" class="button"><?php echo dsq_i('Export Comments'); ?></a>
554
+ <?php echo dsq_i('This will export your existing WordPress comments to Disqus'); ?>
555
+ </p>
556
+ </form>
557
+ </div>
558
+ </td>
559
+ </tr>
560
+ <?php endif; ?>
561
+ <tr>
562
+ <th scope="row" valign="top"><?php echo dsq_i('Sync Disqus with WordPress'); ?></th>
563
+ <td>
564
+ <div id="dsq_import">
565
+ <form method="POST" action="">
566
+ <?php wp_nonce_field('dsq-wpnonce_import', 'dsq-form_nonce_import'); ?>
567
+ <div class="status">
568
+ <p>
569
+ <a href="#" class="button"><?php echo dsq_i('Sync Comments'); ?></a>
570
+ <?php echo dsq_i('This will download your Disqus comments and store them locally in WordPress'); ?>
571
+ </p>
572
+ <label>
573
+ <input type="checkbox" id="dsq_import_wipe" name="dsq_import_wipe" value="1"/>
574
+ <?php echo dsq_i('Remove all imported Disqus comments before syncing.'); ?>
575
+ </label>
576
+ <br/>
577
+ </div>
578
+ </form>
579
+ </div>
580
+ </td>
581
+ </tr>
582
+ </table>
583
+
584
+ <h3>Reset</h3>
585
+
586
+ <table class="form-table">
587
+ <tr>
588
+ <th scope="row" valign="top"><?php echo dsq_i('Reset Disqus'); ?></th>
589
+ <td>
590
+ <form action="?page=disqus" method="POST">
591
+ <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
592
+ <p>
593
+ <input type="submit" value="Reset" name="reset" onclick="return confirm('<?php echo dsq_i('Are you sure you want to reset the Disqus plugin?'); ?>')" class="button" />
594
+ <?php echo dsq_i('This removes all Disqus-specific settings. Comments will remain unaffected.') ?>
595
+ </p>
596
+ <?php echo dsq_i('If you have problems with resetting taking too long you may wish to first manually drop the \'disqus_dupecheck\' index from your \'commentmeta\' table.') ?>
597
+ </form>
598
+ </td>
599
+ </tr>
600
+ </table>
601
+ <br/>
602
+
603
+ <h3><?php echo dsq_i('Debug Information'); ?></h3>
604
+ <p>
605
+ <?php echo dsq_i('Having problems with the plugin? Check out our troubleshooting documentation.'); ?>&nbsp;
606
+ <a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank"><?php echo dsq_i('WordPress troubleshooting ocumentation'); ?></a>
607
+ <?php echo dsq_i('You can also email us and include the debug info below.'); ?>&nbsp;
608
+ <a href="mailto:help+wp@disqus.com"><?php echo dsq_i('Contact support'); ?></a>
609
+ </p>
610
+ <textarea style="width:90%; height:200px;">
611
+ URL: <?php echo esc_url( get_option('siteurl') ); ?>
612
+
613
+ PHP Version: <?php echo esc_html( phpversion() ); ?>
614
+
615
+ Version: <?php echo esc_html( $wp_version ); ?>
616
+
617
+ Active Theme:
618
+ <?php
619
+ if ( !function_exists('wp_get_theme') ) {
620
+ $theme = get_theme(get_current_theme());
621
+ echo esc_html( $theme['Name'] . ' ' . $theme['Version'] );
622
+ } else {
623
+ $theme = wp_get_theme();
624
+ echo esc_html( $theme->Name . ' ' . $theme->Version );
625
+ }
626
+ ?>
627
+
628
+ URLOpen Method: <?php echo esc_html( dsq_url_method() ); ?>
629
+
630
+ Plugin Version: <?php echo esc_html( DISQUS_VERSION ); ?>
631
+
632
+ Settings:
633
+ dsq_is_installed: <?php echo esc_html( dsq_is_installed() ); ?>
634
+ <?php foreach (dsq_options() as $opt) {
635
+ echo esc_html( $opt.': '.get_option($opt)."\n" );
636
+ }
637
+ ?>
638
+
639
+ Plugins:
640
+ <?php
641
+ foreach (get_plugins() as $key => $plugin) {
642
+ $isactive = "";
643
+ if (is_plugin_active($key)) {
644
+ $isactive = "(active)";
645
+ }
646
+ echo esc_html( $plugin['Name'].' '.$plugin['Version'].' '.$isactive."\n" );
647
+ }
648
+ ?>
649
+ </textarea><br/>
650
+ </div>
651
+ </div>
media/js/admin.js ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+ // Replace comments dashboard link
4
+ $('#dashboard_right_now .inside table td.last a, #dashboard_recent_comments .inside .textright a.button').attr('href', 'edit-comments.php?page=disqus');
5
+
6
+ // Focuses on username text box if present
7
+ if ($('#dsq-username').length) {
8
+ $('#dsq-username').focus();
9
+ }
10
+
11
+ // Set current Disqus admin state
12
+ $('#dsq-tabs li').click(function() {
13
+ $('#dsq-tabs li.selected').removeClass('selected');
14
+ $(this).addClass('selected');
15
+ $('.dsq-main, .dsq-advanced').hide();
16
+ $('.' + $(this).attr('rel')).show();
17
+ });
18
+ if (location.href.indexOf('#adv') != -1) {
19
+ $('#dsq-tab-advanced').click();
20
+ }
21
+
22
+ // Bind click events to export/sync buttons
23
+ dsq_fire_export();
24
+ dsq_fire_import();
25
+ });
26
+
27
+ var dsq_fire_export = function() {
28
+ jQuery(function($) {
29
+ $('#dsq_export a.button').unbind().click(function() {
30
+ $('#dsq_export .status').removeClass('dsq-export-fail').addClass('dsq-exporting').html('Processing...');
31
+ dsq_export_comments();
32
+ return false;
33
+ });
34
+ });
35
+ };
36
+
37
+ var dsq_export_comments = function() {
38
+ jQuery(function($) {
39
+ var status = $('#dsq_export .status');
40
+ var nonce = $('#dsq-form_nonce_export').val();
41
+ var export_info = (status.attr('rel') || '0|' + (new Date().getTime()/1000)).split('|');
42
+ $.get(
43
+ adminVars.indexUrl,
44
+ {
45
+ cf_action: 'export_comments',
46
+ post_id: export_info[0],
47
+ timestamp: export_info[1],
48
+ _dsqexport_wpnonce: nonce
49
+ },
50
+ function(response) {
51
+ switch (response.result) {
52
+ case 'success':
53
+ status.html(response.msg).attr('rel', response.post_id + '|' + response.timestamp);
54
+ switch (response.status) {
55
+ case 'partial':
56
+ dsq_export_comments();
57
+ break;
58
+ case 'complete':
59
+ status.removeClass('dsq-exporting').addClass('dsq-exported');
60
+ break;
61
+ }
62
+ break;
63
+ case 'fail':
64
+ status.parent().html(response.msg);
65
+ dsq_fire_export();
66
+ break;
67
+ }
68
+ },
69
+ 'json'
70
+ );
71
+ });
72
+ };
73
+
74
+ var dsq_fire_import = function() {
75
+ jQuery(function($) {
76
+ $('#dsq_import a.button, #dsq_import_retry').unbind().click(function() {
77
+ var wipe = $('#dsq_import_wipe').is(':checked');
78
+ $('#dsq_import .status').removeClass('dsq-import-fail').addClass('dsq-importing').html('Processing...');
79
+ dsq_import_comments(wipe);
80
+ return false;
81
+ });
82
+ });
83
+ };
84
+
85
+ var dsq_import_comments = function(wipe) {
86
+ jQuery(function($) {
87
+ var status = $('#dsq_import .status');
88
+ var nonce = $('#dsq-form_nonce_import').val();
89
+ var last_comment_id = status.attr('rel') || '0';
90
+ $.get(
91
+ adminVars.indexUrl,
92
+ {
93
+ cf_action: 'import_comments',
94
+ last_comment_id: last_comment_id,
95
+ wipe: (wipe ? 1 : 0),
96
+ _dsqimport_wpnonce: nonce
97
+ },
98
+ function(response) {
99
+ switch (response.result) {
100
+ case 'success':
101
+ status.html(response.msg).attr('rel', response.last_comment_id);
102
+ switch (response.status) {
103
+ case 'partial':
104
+ dsq_import_comments(false);
105
+ break;
106
+ case 'complete':
107
+ status.removeClass('dsq-importing').addClass('dsq-imported');
108
+ break;
109
+ }
110
+ break;
111
+ case 'fail':
112
+ status.parent().html(response.msg);
113
+ dsq_fire_import();
114
+ break;
115
+ }
116
+ },
117
+ 'json'
118
+ );
119
+ });
120
+ };
media/js/count.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var disqus_shortname = countVars.disqusShortname;
2
+ (function () {
3
+ var nodes = document.getElementsByTagName('span');
4
+ for (var i = 0, url; i < nodes.length; i++) {
5
+ if (nodes[i].className.indexOf('dsq-postid') != -1) {
6
+ nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('data-dsqidentifier'));
7
+ url = nodes[i].parentNode.href.split('#', 1);
8
+ if (url.length == 1) { url = url[0]; }
9
+ else { url = url[1]; }
10
+ nodes[i].parentNode.href = url + '#disqus_thread';
11
+ }
12
+ }
13
+ var s = document.createElement('script'); s.async = true;
14
+ s.type = 'text/javascript';
15
+ s.src = '//' + disqus_shortname + '.disqus.com/count.js';
16
+ (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
17
+ }());
media/js/dashboard.js ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+ // fix menu
4
+ var mc = $('#menu-comments');
5
+ mc.find('a.wp-has-submenu').attr('href', 'edit-comments.php?page=disqus').end().find('.wp-submenu li:has(a[href="edit-comments.php?page=disqus"])').prependTo(mc.find('.wp-submenu ul'));
6
+
7
+ // fix admin bar
8
+ $('#wp-admin-bar-comments').find('a.ab-item').attr('href', 'edit-comments.php?page=disqus');
9
+
10
+ // Remove trackbacks
11
+ $('#dashboard_recent_comments div.trackback').remove();
12
+
13
+ // Replace comment counts
14
+ $('#dashboard_right_now').find('.b-comments a').html(dashboardVars.stats.totalComments).end().find('.b_approved a').html(dashboardVars.stats.approved).end().find('.b-waiting a').html(dashboardVars.stats.moderated).end().find('.b-spam a').html(dashboardVars.stats.spam);
15
+ });
media/js/disqus.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var disqus_url = embedVars.disqusUrl;
2
+ var disqus_identifier = embedVars.disqusIdentifier;
3
+ var disqus_container_id = 'disqus_thread';
4
+ var disqus_shortname = embedVars.disqusShortname;
5
+ var disqus_title = embedVars.disqusTitle;
6
+ var disqus_config_custom = window.disqus_config;
7
+ var disqus_config = function () {
8
+ /*
9
+ All currently supported events:
10
+ onReady: fires when everything is ready,
11
+ onNewComment: fires when a new comment is posted,
12
+ onIdentify: fires when user is authenticated
13
+ */
14
+ if (typeof embedVars.disqusConfig.remote_auth_s3 !== 'undefined') {
15
+ this.page.remote_auth_s3 = embedVars.disqusConfig.remote_auth_s3;
16
+ }
17
+
18
+ if (typeof embedVars.disqusConfig.api_key !== 'undefined') {
19
+ this.page.api_key = embedVars.disqusConfig.api_key;
20
+ }
21
+
22
+ if (typeof embedVars.disqusConfig.sso !== 'undefined') {
23
+ this.sso = {
24
+ name: embedVars.disqusConfig.sso.name,
25
+ button: embedVars.disqusConfig.sso.button,
26
+ url: embedVars.disqusConfig.sso.url,
27
+ logout: embedVars.disqusConfig.sso.logout,
28
+ width: embedVars.disqusConfig.sso.width,
29
+ height: embedVars.disqusConfig.sso.height
30
+ };
31
+ }
32
+
33
+ this.language = embedVars.disqusConfig.language;
34
+ this.callbacks.onReady.push(function () {
35
+ if (!embedVars.options.manualSync) {
36
+ // sync comments in the background so we don't block the page
37
+ var script = document.createElement('script');
38
+ script.async = true;
39
+ script.src = '?cf_action=sync_comments&post_id=' + embedVars.postId;
40
+
41
+ var firstScript = document.getElementsByTagName('script')[0];
42
+ firstScript.parentNode.insertBefore(script, firstScript);
43
+ }
44
+ });
45
+
46
+ if (disqus_config_custom) {
47
+ disqus_config_custom.call(this);
48
+ }
49
+ };
50
+
51
+ (function() {
52
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript';
53
+ dsq.async = true;
54
+ dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
55
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
56
+ })();
media/js/pointer.js ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready( function($) {
2
+ alert('pointer.js loaded');
3
+ console.log('pointerContent', pointerContent);
4
+
5
+ $('#menu-comments').pointer({
6
+ content: pointerContent,
7
+ position: {
8
+ edge: 'left', // arrow direction
9
+ align: 'center' // vertical alignment
10
+ },
11
+ pointerWidth: 350,
12
+ close: function() {
13
+ $.post(ajaxurl, {
14
+ pointer: 'disqus_settings_pointer', // pointer ID
15
+ action: 'dismiss-wp-pointer'
16
+ });
17
+ }
18
+ }).pointer('open');
19
+ });
media/js/upload.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var file_frame;
2
+
3
+ jQuery(document).ready(function($) {
4
+ $('.upload_image_button').on('click', function(event) {
5
+ event.preventDefault();
6
+
7
+ // If the media frame already exists, reopen it.
8
+ if ( file_frame ) {
9
+ file_frame.open();
10
+ return;
11
+ }
12
+
13
+ // Create the media frame.
14
+ file_frame = wp.media.frames.file_frame = wp.media({
15
+ title: $(this).data('uploader_title'),
16
+ button: {
17
+ text: $(this).data('uploader_button_text'),
18
+ },
19
+ multiple: false // Set to true to allow multiple files to be selected
20
+ });
21
+
22
+ // When an image is selected, run a callback.
23
+ file_frame.on('select', function() {
24
+ // We set multiple to false so only get one image from the uploader
25
+ attachment = file_frame.state().get('selection').first().toJSON();
26
+
27
+ // Do something with attachment.id and/or attachment.url here
28
+ $('#disqus_sso_button').val(attachment.url);
29
+ });
30
+
31
+ // Finally, open the modal
32
+ file_frame.open();
33
+ });
34
+ });
media/styles/manage-pre25.css CHANGED
@@ -1,67 +1,67 @@
1
- /* Selectors required for pre-WordPress 2.5 */
2
-
3
- .form-table {
4
- border-collapse: collapse;
5
- margin-top: 1em;
6
- width: 100%;
7
- color: #333;
8
- }
9
-
10
- .form-table tr {
11
- background-color: #eaf3fa;
12
- }
13
-
14
- .form-table td {
15
- margin-bottom: 9px;
16
- padding: 10px;
17
- line-height: 20px;
18
- font-size: 11px;
19
- border-bottom-width: 8px;
20
- border-bottom-style: solid;
21
- border-color: #fff;
22
- }
23
-
24
- .form-table th {
25
- vertical-align: top;
26
- text-align: left;
27
- padding: 10px;
28
- width: 150px;
29
- border-bottom-width: 8px;
30
- border-bottom-style: solid;
31
- border-color: #fff;
32
- }
33
-
34
- .form-table th.th-full {
35
- width: auto;
36
- }
37
-
38
- .form-table input, .form-table textarea {
39
- border-width: 1px;
40
- border-style: solid;
41
- }
42
-
43
- .form-table div.color-option {
44
- display: block;
45
- clear: both;
46
- }
47
-
48
- .form-table input.tog {
49
- margin-top: 2px;
50
- margin-right: 2px;
51
- float: left;
52
- }
53
-
54
- .form-table table.color-palette {
55
- vertical-align: bottom;
56
- float: left;
57
- margin: -3px 3px 8px;
58
- }
59
-
60
- .form-table .color-palette td {
61
- border-bottom: none;
62
- border: 1px solid #fff;
63
- font-size: 1px;
64
- line-height: 1px;
65
- }
66
-
67
- #disqus_warning{ background-color:#ff0000; }
1
+ /* Selectors required for pre-WordPress 2.5 */
2
+
3
+ .form-table {
4
+ border-collapse: collapse;
5
+ margin-top: 1em;
6
+ width: 100%;
7
+ color: #333;
8
+ }
9
+
10
+ .form-table tr {
11
+ background-color: #eaf3fa;
12
+ }
13
+
14
+ .form-table td {
15
+ margin-bottom: 9px;
16
+ padding: 10px;
17
+ line-height: 20px;
18
+ font-size: 11px;
19
+ border-bottom-width: 8px;
20
+ border-bottom-style: solid;
21
+ border-color: #fff;
22
+ }
23
+
24
+ .form-table th {
25
+ vertical-align: top;
26
+ text-align: left;
27
+ padding: 10px;
28
+ width: 150px;
29
+ border-bottom-width: 8px;
30
+ border-bottom-style: solid;
31
+ border-color: #fff;
32
+ }
33
+
34
+ .form-table th.th-full {
35
+ width: auto;
36
+ }
37
+
38
+ .form-table input, .form-table textarea {
39
+ border-width: 1px;
40
+ border-style: solid;
41
+ }
42
+
43
+ .form-table div.color-option {
44
+ display: block;
45
+ clear: both;
46
+ }
47
+
48
+ .form-table input.tog {
49
+ margin-top: 2px;
50
+ margin-right: 2px;
51
+ float: left;
52
+ }
53
+
54
+ .form-table table.color-palette {
55
+ vertical-align: bottom;
56
+ float: left;
57
+ margin: -3px 3px 8px;
58
+ }
59
+
60
+ .form-table .color-palette td {
61
+ border-bottom: none;
62
+ border: 1px solid #fff;
63
+ font-size: 1px;
64
+ line-height: 1px;
65
+ }
66
+
67
+ #disqus_warning{ background-color:#ff0000; }
media/styles/manage.css CHANGED
@@ -1,52 +1,52 @@
1
- ul#dsq-tabs li:last-child {
2
- width: 100px;
3
- }
4
- ul#dsq-tabs li.selected {
5
- font-weight: bold;
6
- }
7
- ul#dsq-tabs li {
8
- float: left;
9
- color: #333;
10
- padding: 0.25em;
11
- height: 16px;
12
- cursor: pointer;
13
- margin-right: 8px;
14
- text-align: right;
15
- }
16
-
17
- ul#dsq-tabs {
18
- display: block;
19
- height: 20px;
20
- list-style: none;
21
- margin: 15px 0;
22
- padding: 0;
23
- border: 0;
24
- position: absolute;
25
- right: 10px;
26
- }
27
-
28
- select.disqus-replace {
29
- border-color: #C6D9E9;
30
- }
31
-
32
- .dsq-content h2 {
33
- line-height: 41px;
34
- margin: 15px 0 10px;
35
- }
36
-
37
- .dsq-alert {
38
- color: #fff;
39
- background: #e76c35;
40
- border: 1px solid #8f3e1c;
41
- padding: 5px;
42
- }
43
-
44
- .dsq-disabled-text {
45
- color: #e76c35;
46
- font-weight: 700;
47
- }
48
-
49
- .dsq-enabled-text {
50
- color: #7fbd5a;
51
- font-weight: 700;
52
  }
1
+ ul#dsq-tabs li:last-child {
2
+ width: 100px;
3
+ }
4
+ ul#dsq-tabs li.selected {
5
+ font-weight: bold;
6
+ }
7
+ ul#dsq-tabs li {
8
+ float: left;
9
+ color: #333;
10
+ padding: 0.25em;
11
+ height: 16px;
12
+ cursor: pointer;
13
+ margin-right: 8px;
14
+ text-align: right;
15
+ }
16
+
17
+ ul#dsq-tabs {
18
+ display: block;
19
+ height: 20px;
20
+ list-style: none;
21
+ margin: 15px 0;
22
+ padding: 0;
23
+ border: 0;
24
+ position: absolute;
25
+ right: 10px;
26
+ }
27
+
28
+ select.disqus-replace {
29
+ border-color: #C6D9E9;
30
+ }
31
+
32
+ .dsq-content h2 {
33
+ line-height: 41px;
34
+ margin: 15px 0 10px;
35
+ }
36
+
37
+ .dsq-alert {
38
+ color: #fff;
39
+ background: #e76c35;
40
+ border: 1px solid #8f3e1c;
41
+ padding: 5px;
42
+ }
43
+
44
+ .dsq-disabled-text {
45
+ color: #e76c35;
46
+ font-weight: 700;
47
+ }
48
+
49
+ .dsq-enabled-text {
50
+ color: #7fbd5a;
51
+ font-weight: 700;
52
  }
readme.txt CHANGED
@@ -1,293 +1,312 @@
1
- === Disqus Comment System ===
2
- Contributors: disqus, alexkingorg, crowdfavorite, zeeg, tail, thetylerhayes
3
- Tags: comments, threaded, email, notification, spam, avatars, community, profile, widget, disqus
4
- Requires at least: 2.8
5
- Tested up to: 3.9.1
6
- Stable tag: 2.77
7
-
8
- The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus.
9
-
10
- == Description ==
11
-
12
- Disqus, pronounced "discuss", is a service and tool for web comments and
13
- discussions. Disqus makes commenting easier and more interactive,
14
- while connecting websites and commenters across a thriving discussion
15
- community.
16
-
17
- The Disqus for WordPress plugin seamlessly integrates using the Disqus API and by syncing with WordPress comments.
18
-
19
- = Disqus for WordPress =
20
-
21
- * Uses the Disqus API
22
- * Comments indexable by search engines (SEO-friendly)
23
- * Support for importing existing comments
24
- * Auto-sync (backup) of comments with Disqus and WordPress database
25
-
26
- = Disqus Features =
27
-
28
- * Threaded comments and replies
29
- * Notifications and reply by email
30
- * Subscribe and RSS options
31
- * Aggregated comments and social mentions
32
- * Powerful moderation and admin tools
33
- * Full spam filtering, blacklists and whitelists
34
- * Support for Disqus community widgets
35
- * Connected with a large discussion community
36
- * Increased exposure and readership
37
-
38
- == Installation ==
39
-
40
- **NOTE: It is recommended that you [backup your database](http://codex.wordpress.org/Backing_Up_Your_Database) before installing the plugin.**
41
-
42
- 1. Unpack archive to this archive to the 'wp-content/plugins/' directory inside
43
- of WordPress
44
-
45
- * Maintain the directory structure of the archive (all extracted files
46
- should exist in 'wp-content/plugins/disqus-comment-system/'
47
-
48
- 2. From your blog administration, click on Comments to change settings
49
- (WordPress 2.0 users can find the settings under Options > Disqus.)
50
-
51
- = More documentation =
52
-
53
- Go to [http://disqus.com/help/wordpress](http://disqus.com/help/wordpress)
54
-
55
- == Screenshots ==
56
-
57
- 1. Disqus Comments
58
- 2. Discovery Box (part of Disqus Comments)
59
- 3. Inline Moderation Interface
60
-
61
- == Changes ==
62
-
63
- 2.77
64
-
65
- * Fixes login by email issue
66
- * Make sure Disqus is enabled after installation
67
- * Additional security fixes
68
-
69
- 2.76
70
-
71
- * Security fixes (Thanks to Nik Cubrilovic, Alexander Concha and Marc-Alexandre Montpas)
72
- * Bump tested Wordpress version to 3.9.1
73
- * Remove obsolete SSO button uploader
74
- * Enable 'Output javascript in footer' by default during installation
75
- * Fix for 'Reset' function not completely working the first time
76
-
77
- 2.75
78
-
79
- * Bump supported WordPress version to 3.8.
80
- * Properly encode site name for SSO login button.
81
- * Increased timeout for comment exporter to 60 seconds.
82
- * Use https: for admin pages
83
- * Miscellaneous bug fixes and improvements.
84
-
85
- 2.74
86
-
87
- * Updated settings UI
88
- * Add filter hook for setting custom Disqus language
89
- * For WP >= 3.5, use new media uploader
90
- * Disable internal Wordpress commenting if Disqus is enabled (thanks Artem Russakovskii)
91
- * Cleaned up installation and configuration flow
92
- * Added link to WP backup guide in README
93
- * Fix admin bar comments link
94
- * Added a check to avoid a missing key notice when WP_DEBUG=TRUE (thanks Jason Lengstorf)
95
- * Prevent 404 errors for embed.js from being reported by Google Webmaster Tools (missed in 2.73 README)
96
-
97
- 2.73
98
-
99
- * Apply CDATA patch from Wordpress 3.4 to dsq_export_wxr_cdata() (thanks Artem
100
- Russakovskii for the patch).
101
- * Added Single Sign-On log-in button and icon to options (only for sites using SSO)
102
- * Output user website if set in SSO payload
103
- * Added plugin activation statuses to debug info
104
- * Bump supported WordPress version to 3.4.1
105
- * Fixed issue where disqus_dupecheck won't properly uninstall
106
- * Load second count.js (output-in-footer version) reference via SSL too
107
- * Added screenshots
108
-
109
- 2.72
110
-
111
- * Load count.js via SSL when page is accessed via HTTPS
112
- * Fixed styling issue with Disqus admin.
113
-
114
- 2.71
115
-
116
- * Fixed issue where embed wasn't using SSL if page was loaded via HTTPS
117
- * Fixed issue with syncing where to user's without a display_name would
118
- revert back to Anonymous (really this time).
119
- * Fixed issue where Google Webmaster Tools would incorrectly report 404s.
120
- * Fixed issue with Disqus admin display issues.
121
-
122
- 2.70
123
-
124
- * Properly uninstall disqus_dupecheck index when uninstalling plugin.
125
- * Fixed issue with syncing where to user's without a display_name would
126
- revert back to Anonymous.
127
- * Fixed issue where IP addresses weren't being synced properly.
128
- * Allow non-Administrators (e.g., editors) to see Disqus Moderate panel
129
- inline (fixes GH-3)
130
-
131
- 2.69
132
-
133
- * Bumped version number.
134
-
135
- 2.68
136
-
137
- * Removed debugging information from web requests in CLI scripts (thanks
138
- Ryan Dewhurst for the report).
139
- * Reduced sync lock time to 1 hour.
140
- * Fixed an issue which was not allowing pending posts (for sync) to clear.
141
- * Fixed an issue with CLI scripts when used with certain caching plugins.
142
-
143
- 2.67
144
-
145
- * Bumped synchronization timer delays to 5 minutes.
146
- * wp-cli.php now requires php_sapi_name to be set to 'cli' for execution.
147
- * Fixed a bug with imported comments not storing the correct relative date.
148
- * Added a lock for dsq_sync_forum, which can be overriden in the command line script
149
- with the --force tag.
150
- * dsq_sync_forum will now handle all pending post metadata updates (formerly a separate
151
- cron task, dsq_sync_post).
152
-
153
- 2.66
154
-
155
- * Fixed issue with jQuery usage which conflicted with updated jQuery version.
156
-
157
- 2.65
158
-
159
- * Corrected a bug that was causing posts to not appear due to invalid references.
160
-
161
- 2.64
162
-
163
- * Added an option to disable Disqus without deactivating the plugin.
164
- * Added a second check for comment sync to prevent stampede race conditions in WP cron.
165
-
166
- 2.63
167
-
168
- * Added command line script to import comments from DISQUS (scripts/import-comments.php).
169
- * Added command line script to export comments to DISQUS (scripts/export-comments.php).
170
- * The exporter will now only do one post at a time.
171
- * The exporter now only sends required attributes to DISQUS.
172
- * Moved media into its own directory.
173
-
174
- 2.62
175
-
176
- * Changed legacy query to use = operator instead of LIKE so it can be indexed.
177
-
178
- 2.61
179
-
180
- * Fixed an issue which was causing invalid information to be presented in RSS feeds.
181
-
182
- 2.60
183
-
184
- * Added support for new Single Sign-On (API version 3.0).
185
- * Improved support for legacy Single Sign-On.
186
-
187
- 2.55
188
-
189
- * Added support for get_comments_number in templates.
190
-
191
- 2.54
192
-
193
- * Updated URL to forum moderation.
194
-
195
- 2.53
196
-
197
- * Fixed an issue with fsockopen and GET requests (only affects certain users).
198
-
199
- 2.52
200
-
201
- * Fixed issue with Disqus-API package not getting updated (only affecting PHP4).
202
-
203
- 2.51
204
-
205
- * Added CDATA comments for JavaScript.
206
- * Syncing comments will now restore missing thread information from old imports.
207
- * Install and uninstall processes have been improved.
208
- * Fixed an issue in PHP4 with importing comments.
209
- * Fixed an issue that could cause duplicate comments in some places.
210
- * Added an option to remove existing imported comments when importing.
211
-
212
- 2.50
213
-
214
- * Added missing file.
215
-
216
- 2.49
217
-
218
- * Database usage has been optimized for storing comment meta data.
219
-
220
- You can perform this migration automatically by visiting Comments -> Disqus, or if
221
- you have a large database, you may do this by hand:
222
-
223
- CREATE INDEX disqus_dupecheck ON `wp_commentmeta` (meta_key, meta_value(11));
224
- INSERT INTO `wp_options` (blog_id, option_name, option_value, autoload) VALUES (0, 'disqus_version', '2.49', 'yes') ON DUPLICATE KEY UPDATE option_value = VALUES(option_value);
225
-
226
- 2.48
227
-
228
- * Comment synchronization has been optimized to be a single call per-site.
229
- * disqus.css will now only load when displaying comments
230
-
231
- 2.47
232
-
233
- * Fixed a security hole with comment importing.
234
- * Reverted ability to use default template comments design.
235
- * Comments will now store which version they were imported under.
236
- * Added an option to disable server side rendering.
237
-
238
- 2.46
239
-
240
- * Better debugging information for export errors.
241
- * Added the ability to manual import Disqus comments into Wordpress.
242
- * Added thread_identifier support to exports.
243
- * Cleaned up API error messages.
244
- * Fixed a bug which was causing the import process to not grab only the latest set of comments.
245
- * Added an option to disable automated synchronization with Disqus.
246
-
247
- 2.45
248
-
249
- * Comments should now store thread information as well as certain other meta data.
250
- * Optimize get_thread polling to only pull comments which aren't stored properly.
251
-
252
- 2.44
253
-
254
- * Fixed JavaScript response for comments sync call.
255
- * Comments are now marked as closed while showing the embed (fixes showing default respond form).
256
-
257
- 2.43
258
-
259
- * Fixed a JavaScript syntax error which would cause linting to fail.
260
- * Correct an issue that was causing comments.php to throw a syntax error under some configurations.
261
-
262
- 2.42
263
-
264
- * Correct a bug with saving disqus_user_api_key (non-critical).
265
- * Added settings to Debug Information.
266
- * Adjusting all includes to use absolute paths.
267
- * Adjusted JSON usage to solve a problem for some clients.
268
-
269
- 2.41
270
-
271
- * Correct a bug with double urlencoding titles.
272
-
273
- 2.40
274
-
275
- * Comments are now synced with Disqus as a delayed asynchronous cron event.
276
- * Comment count code has been updated to use the new widget. (Comment counts
277
- must be linked to get tracked within "the loop" now).
278
- * API bindings have been migrated to the generic 1.1 Disqus API.
279
- * Pages will now properly update their permalink with Disqus when it changes. This is
280
- done within the sync event above.
281
- * There is now a Debug Information pane under Advanced to assist with support requests.
282
- * When Disqus is unreachable it will fallback to the theme's built-in comment display.
283
- * Legacy mode is no longer available.
284
- * The plugin management interface can now be localized.
285
- * The plugin is now valid HTML5.
286
-
287
- == Support ==
288
-
289
- * Visit http://disqus.com/help/wordpress for help documentation.
290
-
291
- * Visit http://help.disqus.com for help from our support team.
292
-
293
- * Disqus also recommends the [WordPress HelpCenter](http://wphelpcenter.com/) for extended help. Disqus is not associated with the WordPress HelpCenter in any way.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Disqus Comment System ===
2
+ Contributors: disqus, alexkingorg, crowdfavorite, zeeg, tail, thetylerhayes
3
+ Tags: comments, threaded, email, notification, spam, avatars, community, profile, widget, disqus
4
+ Requires at least: 2.8
5
+ Tested up to: 4.0
6
+ Stable tag: 2.81
7
+
8
+ The Disqus comment system replaces your WordPress comment system with your comments hosted and powered by Disqus.
9
+
10
+ == Description ==
11
+
12
+ Disqus, pronounced "discuss", is a service and tool for web comments and
13
+ discussions. Disqus makes commenting easier and more interactive,
14
+ while connecting websites and commenters across a thriving discussion
15
+ community.
16
+
17
+ The Disqus for WordPress plugin seamlessly integrates using the Disqus API and by syncing with WordPress comments.
18
+
19
+ = Disqus for WordPress =
20
+
21
+ * Uses the Disqus API
22
+ * Comments indexable by search engines (SEO-friendly)
23
+ * Support for importing existing comments
24
+ * Auto-sync (backup) of comments with Disqus and WordPress database
25
+
26
+ = Disqus Features =
27
+
28
+ * Threaded comments and replies
29
+ * Notifications and reply by email
30
+ * Subscribe and RSS options
31
+ * Aggregated comments and social mentions
32
+ * Powerful moderation and admin tools
33
+ * Full spam filtering, blacklists and whitelists
34
+ * Support for Disqus community widgets
35
+ * Connected with a large discussion community
36
+ * Increased exposure and readership
37
+
38
+ == Installation ==
39
+
40
+ **NOTE: It is recommended that you [backup your database](http://codex.wordpress.org/Backing_Up_Your_Database) before installing the plugin.**
41
+
42
+ 1. Unpack archive to this archive to the 'wp-content/plugins/' directory inside
43
+ of WordPress
44
+
45
+ * Maintain the directory structure of the archive (all extracted files
46
+ should exist in 'wp-content/plugins/disqus-comment-system/'
47
+
48
+ 2. From your blog administration, click on Comments to change settings
49
+ (WordPress 2.0 users can find the settings under Options > Disqus.)
50
+
51
+ = More documentation =
52
+
53
+ Go to [http://disqus.com/help/wordpress](http://disqus.com/help/wordpress)
54
+
55
+ == Screenshots ==
56
+
57
+ 1. Disqus Comments
58
+ 2. Discovery Box (part of Disqus Comments)
59
+ 3. Moderation Interface
60
+
61
+ == Changelog ==
62
+
63
+ = 2.81 =
64
+
65
+ * Fix for automatic comment syncing
66
+ * Make sure all markup validates for HTML5
67
+
68
+ = 2.80 =
69
+
70
+ * Move all scripts to separate files instead of rendering them in php
71
+ * Added a hook to attach custom functions to disqus_config in javascript
72
+ * Fixed exporting bug introduced in 2.78 (Thanks to mkilian)
73
+ * Numerous small compatibility and security enhancements
74
+
75
+ = 2.79 =
76
+
77
+ * Reinstate changes removed by 2.78
78
+
79
+ = 2.78 =
80
+
81
+ * Security fixes
82
+ * Compatibility for Wordpress version 4.0
83
+
84
+ = 2.77 =
85
+
86
+ * Fixes login by email issue
87
+ * Make sure Disqus is enabled after installation
88
+ * Additional security fixes
89
+
90
+ = 2.76 =
91
+
92
+ * Security fixes (Thanks to Nik Cubrilovic, Alexander Concha and Marc-Alexandre Montpas)
93
+ * Bump tested Wordpress version to 3.9.1
94
+ * Remove obsolete SSO button uploader
95
+ * Enable 'Output javascript in footer' by default during installation
96
+ * Fix for 'Reset' function not completely working the first time
97
+
98
+ = 2.75 =
99
+
100
+ * Bump supported WordPress version to 3.8.
101
+ * Properly encode site name for SSO login button.
102
+ * Increased timeout for comment exporter to 60 seconds.
103
+ * Use https: for admin pages
104
+ * Miscellaneous bug fixes and improvements.
105
+
106
+ = 2.74 =
107
+
108
+ * Updated settings UI
109
+ * Add filter hook for setting custom Disqus language
110
+ * For WP >= 3.5, use new media uploader
111
+ * Disable internal Wordpress commenting if Disqus is enabled (thanks Artem Russakovskii)
112
+ * Cleaned up installation and configuration flow
113
+ * Added link to WP backup guide in README
114
+ * Fix admin bar comments link
115
+ * Added a check to avoid a missing key notice when WP_DEBUG=TRUE (thanks Jason Lengstorf)
116
+ * Prevent 404 errors for embed.js from being reported by Google Webmaster Tools (missed in 2.73 README)
117
+
118
+ = 2.73 =
119
+
120
+ * Apply CDATA patch from Wordpress 3.4 to dsq_export_wxr_cdata() (thanks Artem
121
+ Russakovskii for the patch).
122
+ * Added Single Sign-On log-in button and icon to options (only for sites using SSO)
123
+ * Output user website if set in SSO payload
124
+ * Added plugin activation statuses to debug info
125
+ * Bump supported WordPress version to 3.4.1
126
+ * Fixed issue where disqus_dupecheck won't properly uninstall
127
+ * Load second count.js (output-in-footer version) reference via SSL too
128
+ * Added screenshots
129
+
130
+ = 2.72 =
131
+
132
+ * Load count.js via SSL when page is accessed via HTTPS
133
+ * Fixed styling issue with Disqus admin.
134
+
135
+ = 2.71 =
136
+
137
+ * Fixed issue where embed wasn't using SSL if page was loaded via HTTPS
138
+ * Fixed issue with syncing where to user's without a display_name would
139
+ revert back to Anonymous (really this time).
140
+ * Fixed issue where Google Webmaster Tools would incorrectly report 404s.
141
+ * Fixed issue with Disqus admin display issues.
142
+
143
+ = 2.70 =
144
+
145
+ * Properly uninstall disqus_dupecheck index when uninstalling plugin.
146
+ * Fixed issue with syncing where to user's without a display_name would
147
+ revert back to Anonymous.
148
+ * Fixed issue where IP addresses weren't being synced properly.
149
+ * Allow non-Administrators (e.g., editors) to see Disqus Moderate panel
150
+ inline (fixes GH-3)
151
+
152
+ = 2.69 =
153
+
154
+ * Bumped version number.
155
+
156
+ = 2.68 =
157
+
158
+ * Removed debugging information from web requests in CLI scripts (thanks
159
+ Ryan Dewhurst for the report).
160
+ * Reduced sync lock time to 1 hour.
161
+ * Fixed an issue which was not allowing pending posts (for sync) to clear.
162
+ * Fixed an issue with CLI scripts when used with certain caching plugins.
163
+
164
+ = 2.67 =
165
+
166
+ * Bumped synchronization timer delays to 5 minutes.
167
+ * wp-cli.php now requires php_sapi_name to be set to 'cli' for execution.
168
+ * Fixed a bug with imported comments not storing the correct relative date.
169
+ * Added a lock for dsq_sync_forum, which can be overriden in the command line script
170
+ with the --force tag.
171
+ * dsq_sync_forum will now handle all pending post metadata updates (formerly a separate
172
+ cron task, dsq_sync_post).
173
+
174
+ = 2.66 =
175
+
176
+ * Fixed issue with jQuery usage which conflicted with updated jQuery version.
177
+
178
+ = 2.65 =
179
+
180
+ * Corrected a bug that was causing posts to not appear due to invalid references.
181
+
182
+ = 2.64 =
183
+
184
+ * Added an option to disable Disqus without deactivating the plugin.
185
+ * Added a second check for comment sync to prevent stampede race conditions in WP cron.
186
+
187
+ = 2.63 =
188
+
189
+ * Added command line script to import comments from DISQUS (scripts/import-comments.php).
190
+ * Added command line script to export comments to DISQUS (scripts/export-comments.php).
191
+ * The exporter will now only do one post at a time.
192
+ * The exporter now only sends required attributes to DISQUS.
193
+ * Moved media into its own directory.
194
+
195
+ = 2.62 =
196
+
197
+ * Changed legacy query to use = operator instead of LIKE so it can be indexed.
198
+
199
+ = 2.61 =
200
+
201
+ * Fixed an issue which was causing invalid information to be presented in RSS feeds.
202
+
203
+ = 2.60 =
204
+
205
+ * Added support for new Single Sign-On (API version 3.0).
206
+ * Improved support for legacy Single Sign-On.
207
+
208
+ = 2.55 =
209
+
210
+ * Added support for get_comments_number in templates.
211
+
212
+ = 2.54 =
213
+
214
+ * Updated URL to forum moderation.
215
+
216
+ = 2.53 =
217
+
218
+ * Fixed an issue with fsockopen and GET requests (only affects certain users).
219
+
220
+ = 2.52 =
221
+
222
+ * Fixed issue with Disqus-API package not getting updated (only affecting PHP4).
223
+
224
+ = 2.51 =
225
+
226
+ * Added CDATA comments for JavaScript.
227
+ * Syncing comments will now restore missing thread information from old imports.
228
+ * Install and uninstall processes have been improved.
229
+ * Fixed an issue in PHP4 with importing comments.
230
+ * Fixed an issue that could cause duplicate comments in some places.
231
+ * Added an option to remove existing imported comments when importing.
232
+
233
+ = 2.50 =
234
+
235
+ * Added missing file.
236
+
237
+ = 2.49 =
238
+
239
+ * Database usage has been optimized for storing comment meta data.
240
+
241
+ You can perform this migration automatically by visiting Comments -> Disqus, or if
242
+ you have a large database, you may do this by hand:
243
+
244
+ CREATE INDEX disqus_dupecheck ON `wp_commentmeta` (meta_key, meta_value(11));
245
+ INSERT INTO `wp_options` (blog_id, option_name, option_value, autoload) VALUES (0, 'disqus_version', '2.49', 'yes') ON DUPLICATE KEY UPDATE option_value = VALUES(option_value);
246
+
247
+ = 2.48 =
248
+
249
+ * Comment synchronization has been optimized to be a single call per-site.
250
+ * disqus.css will now only load when displaying comments
251
+
252
+ = 2.47 =
253
+
254
+ * Fixed a security hole with comment importing.
255
+ * Reverted ability to use default template comments design.
256
+ * Comments will now store which version they were imported under.
257
+ * Added an option to disable server side rendering.
258
+
259
+ = 2.46 =
260
+
261
+ * Better debugging information for export errors.
262
+ * Added the ability to manual import Disqus comments into Wordpress.
263
+ * Added thread_identifier support to exports.
264
+ * Cleaned up API error messages.
265
+ * Fixed a bug which was causing the import process to not grab only the latest set of comments.
266
+ * Added an option to disable automated synchronization with Disqus.
267
+
268
+ = 2.45 =
269
+
270
+ * Comments should now store thread information as well as certain other meta data.
271
+ * Optimize get_thread polling to only pull comments which aren't stored properly.
272
+
273
+ = 2.44 =
274
+
275
+ * Fixed JavaScript response for comments sync call.
276
+ * Comments are now marked as closed while showing the embed (fixes showing default respond form).
277
+
278
+ = 2.43 =
279
+
280
+ * Fixed a JavaScript syntax error which would cause linting to fail.
281
+ * Correct an issue that was causing comments.php to throw a syntax error under some configurations.
282
+
283
+ = 2.42 =
284
+
285
+ * Correct a bug with saving disqus_user_api_key (non-critical).
286
+ * Added settings to Debug Information.
287
+ * Adjusting all includes to use absolute paths.
288
+ * Adjusted JSON usage to solve a problem for some clients.
289
+
290
+ = 2.41 =
291
+
292
+ * Correct a bug with double urlencoding titles.
293
+
294
+ = 2.40 =
295
+
296
+ * Comments are now synced with Disqus as a delayed asynchronous cron event.
297
+ * Comment count code has been updated to use the new widget. (Comment counts
298
+ must be linked to get tracked within "the loop" now).
299
+ * API bindings have been migrated to the generic 1.1 Disqus API.
300
+ * Pages will now properly update their permalink with Disqus when it changes. This is
301
+ done within the sync event above.
302
+ * There is now a Debug Information pane under Advanced to assist with support requests.
303
+ * When Disqus is unreachable it will fallback to the theme's built-in comment display.
304
+ * Legacy mode is no longer available.
305
+ * The plugin management interface can now be localized.
306
+ * The plugin is now valid HTML5.
307
+
308
+ == Support ==
309
+
310
+ * Visit http://disqus.com/help/wordpress for help documentation.
311
+
312
+ * Visit http://help.disqus.com for help from our support team.
screenshot-1.png DELETED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.png DELETED
Binary file
scripts/export-comments.php CHANGED
@@ -1,106 +1,106 @@
1
- #!/usr/bin/php
2
- <?php
3
- /**
4
- * Incrementally (in chunks of EXPORT_CHUNK_SIZE) exports all comments to DISQUS.
5
- *
6
- * ``php export-comments.php``
7
- */
8
-
9
- require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
10
- require_once(dirname(__FILE__) . '/../disqus.php');
11
- require_once(dirname(__FILE__) . '/../export.php');
12
-
13
- define('EXPORT_CHUNK_SIZE', 100);
14
-
15
- $forum_url = get_option('disqus_forum_url');
16
-
17
- if (empty($forum_url)) {
18
- print_line("Disqus has not been configured on this installation!");
19
- die();
20
- }
21
-
22
- print_line('---------------------------------------------------------');
23
- print_line('Discovered DISQUS forum shortname as %s', $forum_url);
24
- print_line('---------------------------------------------------------');
25
-
26
- global $wpdb, $dsq_api;
27
-
28
- $timestamp = 0;
29
- $post_id = 0;
30
- $total = 0;
31
- $eof = 0;
32
- $total_exported = 0;
33
- $global_start = microtime();
34
-
35
- $max_post_id = $wpdb->get_var($wpdb->prepare("
36
- SELECT MAX(ID)
37
- FROM $wpdb->posts
38
- WHERE post_type != 'revision'
39
- AND post_status = 'publish'
40
- AND comment_count > 0
41
- AND ID > %d
42
- ", $post_id));
43
-
44
- print_line('Max post id is %d', $max_post_id);
45
-
46
- while ($post_id < $max_post_id) {
47
- $start = microtime();
48
-
49
- $post = $wpdb->get_results($wpdb->prepare("
50
- SELECT *
51
- FROM $wpdb->posts
52
- WHERE post_type != 'revision'
53
- AND post_status = 'publish'
54
- AND comment_count > 0
55
- AND ID > %d
56
- ORDER BY ID ASC
57
- LIMIT 1
58
- ", $post_id));
59
- $post = $post[0];
60
- $post_id = $post->ID;
61
-
62
- print_line(' Exporting comments for post id %d', $post_id);
63
-
64
- $response = null;
65
- $query = $wpdb->get_results( $wpdb->prepare("SELECT COUNT(*) as total FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE, $post_id) );
66
- $total_comments = $query[0]->total;
67
-
68
- $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE, $post_id) );
69
- $group_id = null;
70
- $at = 0;
71
-
72
- // we need to send empty files to ensure EOF happens
73
- while (($at === 0 && $post_id == $max_post_id) || $at < $total_comments) {
74
- if ($post_id == $max_post_id && ($at + EXPORT_CHUNK_SIZE) >= $total_comments) {
75
- $eof = 1;
76
- }
77
- $wxr = dsq_export_wp($post, $comments);
78
- $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
79
- if (!($response['group_id'] > 0)) {
80
- print_line('---------------------------------------------------------');
81
- print_line('There was an error communicating with DISQUS!');
82
- print_line($dsq_api->get_last_error());
83
- print_line('---------------------------------------------------------');
84
- }
85
- $group_id = $response['group_id'];
86
- print_line(' %d comments exported', count($comments), $time);
87
- $total_exported += count($comments);
88
- $at += EXPORT_CHUNK_SIZE;
89
- $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE." OFFSET {$at}", $post->ID) );
90
- // assuming the cache is the internal, reset it's value to empty to avoid
91
- // large memory consumption
92
- $wp_object_cache->cache = array();
93
- }
94
-
95
- $time = abs(microtime() - $start);
96
- print_line(' Done! (took %.2fs)', $time);
97
- }
98
- $total_time = abs(microtime() - $global_start);
99
- print_line('---------------------------------------------------------');
100
- print_line('Done (processing took %.2fs)! %d comments were sent to DISQUS', $total_time, $total_exported);
101
- if ($group_id) {
102
- print_line('');
103
- print_line('Status available at http://import.disqus.com/group/%d/', $group_id);
104
- }
105
- print_line('---------------------------------------------------------');
106
  ?>
1
+ #!/usr/bin/php
2
+ <?php
3
+ /**
4
+ * Incrementally (in chunks of EXPORT_CHUNK_SIZE) exports all comments to DISQUS.
5
+ *
6
+ * ``php export-comments.php``
7
+ */
8
+
9
+ require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
10
+ require_once(dirname(__FILE__) . '/../disqus.php');
11
+ require_once(dirname(__FILE__) . '/../export.php');
12
+
13
+ define('EXPORT_CHUNK_SIZE', 100);
14
+
15
+ $forum_url = get_option('disqus_forum_url');
16
+
17
+ if (empty($forum_url)) {
18
+ print_line("Disqus has not been configured on this installation!");
19
+ die();
20
+ }
21
+
22
+ print_line('---------------------------------------------------------');
23
+ print_line('Discovered DISQUS forum shortname as %s', $forum_url);
24
+ print_line('---------------------------------------------------------');
25
+
26
+ global $wpdb, $dsq_api;
27
+
28
+ $timestamp = 0;
29
+ $post_id = 0;
30
+ $total = 0;
31
+ $eof = 0;
32
+ $total_exported = 0;
33
+ $global_start = microtime();
34
+
35
+ $max_post_id = $wpdb->get_var($wpdb->prepare("
36
+ SELECT MAX(ID)
37
+ FROM $wpdb->posts
38
+ WHERE post_type != 'revision'
39
+ AND post_status = 'publish'
40
+ AND comment_count > 0
41
+ AND ID > %d
42
+ ", $post_id));
43
+
44
+ print_line('Max post id is %d', $max_post_id);
45
+
46
+ while ($post_id < $max_post_id) {
47
+ $start = microtime();
48
+
49
+ $post = $wpdb->get_results($wpdb->prepare("
50
+ SELECT *
51
+ FROM $wpdb->posts
52
+ WHERE post_type != 'revision'
53
+ AND post_status = 'publish'
54
+ AND comment_count > 0
55
+ AND ID > %d
56
+ ORDER BY ID ASC
57
+ LIMIT 1
58
+ ", $post_id));
59
+ $post = $post[0];
60
+ $post_id = $post->ID;
61
+
62
+ print_line(' Exporting comments for post id %d', $post_id);
63
+
64
+ $response = null;
65
+ $query = $wpdb->get_results( $wpdb->prepare("SELECT COUNT(*) as total FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE, $post_id) );
66
+ $total_comments = $query[0]->total;
67
+
68
+ $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE, $post_id) );
69
+ $group_id = null;
70
+ $at = 0;
71
+
72
+ // we need to send empty files to ensure EOF happens
73
+ while (($at === 0 && $post_id == $max_post_id) || $at < $total_comments) {
74
+ if ($post_id == $max_post_id && ($at + EXPORT_CHUNK_SIZE) >= $total_comments) {
75
+ $eof = 1;
76
+ }
77
+ $wxr = dsq_export_wp($post, $comments);
78
+ $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
79
+ if (!($response['group_id'] > 0)) {
80
+ print_line('---------------------------------------------------------');
81
+ print_line('There was an error communicating with DISQUS!');
82
+ print_line($dsq_api->get_last_error());
83
+ print_line('---------------------------------------------------------');
84
+ }
85
+ $group_id = $response['group_id'];
86
+ print_line(' %d comments exported', count($comments), $time);
87
+ $total_exported += count($comments);
88
+ $at += EXPORT_CHUNK_SIZE;
89
+ $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_agent NOT LIKE 'Disqus/%%' LIMIT ".EXPORT_CHUNK_SIZE." OFFSET {$at}", $post->ID) );
90
+ // assuming the cache is the internal, reset it's value to empty to avoid
91
+ // large memory consumption
92
+ $wp_object_cache->cache = array();
93
+ }
94
+
95
+ $time = abs(microtime() - $start);
96
+ print_line(' Done! (took %.2fs)', $time);
97
+ }
98
+ $total_time = abs(microtime() - $global_start);
99
+ print_line('---------------------------------------------------------');
100
+ print_line('Done (processing took %.2fs)! %d comments were sent to DISQUS', $total_time, $total_exported);
101
+ if ($group_id) {
102
+ print_line('');
103
+ print_line('Status available at http://import.disqus.com/group/%d/', $group_id);
104
+ }
105
+ print_line('---------------------------------------------------------');
106
  ?>
scripts/import-comments.php CHANGED
@@ -1,63 +1,63 @@
1
- #!/usr/bin/php
2
- <?php
3
- /**
4
- * Incrementally downloads all comments from DISQUS.
5
- *
6
- * ``php import-comments.php``
7
- */
8
-
9
- require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
10
- require_once(dirname(__FILE__) . '/../disqus.php');
11
-
12
- $forum_url = get_option('disqus_forum_url');
13
-
14
- if (empty($forum_url)) {
15
- print_line("Disqus has not been configured on this installation!");
16
- die();
17
- }
18
-
19
- print_line('---------------------------------------------------------');
20
- print_line('Discovered DISQUS forum shortname as %s', $forum_url);
21
- print_line('---------------------------------------------------------');
22
-
23
- $imported = true;
24
- if (in_array('--reset', $argv)) {
25
- $last_comment_id = 0;
26
- } else {
27
- $last_comment_id = get_option('disqus_last_comment_id');
28
- }
29
- $force = (in_array('--force', $argv));
30
- $total = 0;
31
- $global_start = microtime();
32
-
33
- $memory_usage = memory_get_peak_usage();
34
- while ($imported) {
35
- print_line(' Importing chunk starting at comment id %d', $last_comment_id);
36
- $start = microtime();
37
- $result = dsq_sync_forum($last_comment_id, $force);
38
- if ($result === false) {
39
- print_line('---------------------------------------------------------');
40
- print_line('There was an error communicating with DISQUS!');
41
- print_line($dsq_api->get_last_error());
42
- print_line('---------------------------------------------------------');
43
- die();
44
- break;
45
- } else {
46
- list($imported, $last_comment_id) = $result;
47
- }
48
- $total += $imported;
49
- $time = abs(microtime() - $start);
50
-
51
- // assuming the cache is the internal, reset it's value to empty to avoid
52
- // large memory consump
53
- $wp_object_cache->cache = array();
54
-
55
- $new_memory_usage = memory_get_peak_usage();
56
- print_line(' %d comments imported (took %.2fs, memory increased by %db)', $imported, $time, ($new_memory_usage - $memory_usage));
57
- $memory_usage = $new_memory_usage;
58
- }
59
- $total_time = abs(microtime() - $global_start);
60
- print_line('---------------------------------------------------------');
61
- print_line('Done (took %.2fs)! %d comments imported from DISQUS', $total_time, $total);
62
- print_line('---------------------------------------------------------');
63
  ?>
1
+ #!/usr/bin/php
2
+ <?php
3
+ /**
4
+ * Incrementally downloads all comments from DISQUS.
5
+ *
6
+ * ``php import-comments.php``
7
+ */
8
+
9
+ require_once(dirname(__FILE__) . '/../lib/wp-cli.php');
10
+ require_once(dirname(__FILE__) . '/../disqus.php');
11
+
12
+ $forum_url = get_option('disqus_forum_url');
13
+
14
+ if (empty($forum_url)) {
15
+ print_line("Disqus has not been configured on this installation!");
16
+ die();
17
+ }
18
+
19
+ print_line('---------------------------------------------------------');
20
+ print_line('Discovered DISQUS forum shortname as %s', $forum_url);
21
+ print_line('---------------------------------------------------------');
22
+
23
+ $imported = true;
24
+ if (in_array('--reset', $argv)) {
25
+ $last_comment_id = 0;
26
+ } else {
27
+ $last_comment_id = get_option('disqus_last_comment_id');
28
+ }
29
+ $force = (in_array('--force', $argv));
30
+ $total = 0;
31
+ $global_start = microtime();
32
+
33
+ $memory_usage = memory_get_peak_usage();
34
+ while ($imported) {
35
+ print_line(' Importing chunk starting at comment id %d', $last_comment_id);
36
+ $start = microtime();
37
+ $result = dsq_sync_forum($last_comment_id, $force);
38
+ if ($result === false) {
39
+ print_line('---------------------------------------------------------');
40
+ print_line('There was an error communicating with DISQUS!');
41
+ print_line($dsq_api->get_last_error());
42
+ print_line('---------------------------------------------------------');
43
+ die();
44
+ break;
45
+ } else {
46
+ list($imported, $last_comment_id) = $result;
47
+ }
48
+ $total += $imported;
49
+ $time = abs(microtime() - $start);
50
+
51
+ // assuming the cache is the internal, reset it's value to empty to avoid
52
+ // large memory consump
53
+ $wp_object_cache->cache = array();
54
+
55
+ $new_memory_usage = memory_get_peak_usage();
56
+ print_line(' %d comments imported (took %.2fs, memory increased by %db)', $imported, $time, ($new_memory_usage - $memory_usage));
57
+ $memory_usage = $new_memory_usage;
58
+ }
59
+ $total_time = abs(microtime() - $global_start);
60
+ print_line('---------------------------------------------------------');
61
+ print_line('Done (took %.2fs)! %d comments imported from DISQUS', $total_time, $total);
62
+ print_line('---------------------------------------------------------');
63
  ?>
upgrade.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- require(ABSPATH . 'wp-includes/version.php');
3
-
4
- if ( !current_user_can('manage_options') ) {
5
- die();
6
- }
7
-
8
- $step = (isset($_GET['step']) ? $_GET['step'] : null);
9
-
10
- ?>
11
- <div class="wrap">
12
- <h2><?php echo dsq_i('Upgrade Disqus Comments'); ?></h2>
13
- <form method="POST" action="?page=disqus&amp;step=<?php echo esc_attr($step); ?>">
14
- <?php wp_nonce_field('dsq-wpnonce_upgrade', 'dsq-form_nonce_upgrade'); ?>
15
- <p><?php echo dsq_i('You need to upgrade your database to continue.'); ?></p>
16
-
17
- <p class="submit" style="text-align: left">
18
- <input type="submit" name="upgrade" value="Upgrade &raquo;" />
19
- </p>
20
- </form>
21
  </div>
1
+ <?php
2
+ require(ABSPATH . 'wp-includes/version.php');
3
+
4
+ if ( !current_user_can('manage_options') ) {
5
+ die();
6
+ }
7
+
8
+ $step = (isset($_GET['step']) ? $_GET['step'] : null);
9
+
10
+ ?>
11
+ <div class="wrap">
12
+ <h2><?php echo dsq_i('Upgrade Disqus Comments'); ?></h2>
13
+ <form method="POST" action="?page=disqus&amp;step=<?php echo esc_attr($step); ?>">
14
+ <?php wp_nonce_field('dsq-wpnonce_upgrade', 'dsq-form_nonce_upgrade'); ?>
15
+ <p><?php echo dsq_i('You need to upgrade your database to continue.'); ?></p>
16
+
17
+ <p class="submit" style="text-align: left">
18
+ <input type="submit" name="upgrade" class="button-primary button" value="Upgrade &raquo;" />
19
+ </p>
20
+ </form>
21
  </div>
xd_receiver.htm DELETED
@@ -1 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <body> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js" type="text/javascript"></script> </body> </html>