Disqus Comment System - Version 2.86

Version Description

  • Don't attempt to use cURL on IIS servers
  • Check is dsq_sync_forum is scheduled before scheduling
  • Add updates for Travis CI
  • Fixes a bug in the upgrade process
Download this release

Release Info

Developer webrender
Plugin Icon Disqus Comment System
Version 2.86
Comparing to
See all releases

Code changes from version 2.83 to 2.86

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) 2016 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) 2016 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>.
assets/icon-256x256.png ADDED
Binary file
assets/icon.svg ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4
+ <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
+ width="200px" height="200px" viewBox="0 0 200 200" enable-background="new 0 0 200 200" xml:space="preserve">
6
+ <g id="background">
7
+ <rect fill="#2E9FFF" width="200" height="200"/>
8
+ </g>
9
+ <g id="Layer_2">
10
+ </g>
11
+ <path fill="#FFFFFF" d="M102.535,167.5c-16.518,0-31.621-6.036-43.298-16.021L30.5,155.405l11.102-27.401
12
+ c-3.868-8.535-6.038-18.01-6.038-28.004c0-37.277,29.984-67.5,66.971-67.5c36.984,0,66.965,30.223,66.965,67.5
13
+ C169.5,137.284,139.52,167.5,102.535,167.5z M139.102,99.807v-0.188c0-19.479-13.736-33.367-37.42-33.367h-25.58v67.5h25.201
14
+ C125.171,133.753,139.102,119.284,139.102,99.807L139.102,99.807z M101.964,117.168h-7.482V82.841h7.482
15
+ c10.989,0,18.283,6.265,18.283,17.07v0.188C120.247,110.995,112.953,117.168,101.964,117.168z"/>
16
+ </svg>
assets/screenshot-1.png ADDED
Binary file
assets/screenshot-2.png ADDED
Binary file
assets/screenshot-3.png ADDED
Binary file
comments.php CHANGED
@@ -1,156 +1,156 @@
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
- if ( get_option('dsq_external_js') == '1' ) {
92
- wp_register_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
93
- wp_localize_script( 'dsq_embed_script', 'embedVars', $embed_vars );
94
- wp_enqueue_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
95
- }
96
- else {
97
-
98
- ?>
99
- <script type="text/javascript">
100
- var disqus_url = '<?php echo get_permalink(); ?>';
101
- var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
102
- var disqus_container_id = 'disqus_thread';
103
- var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
104
- var disqus_title = <?php echo cf_json_encode( dsq_title_for_post($post) ); ?>;
105
- var disqus_config_custom = window.disqus_config;
106
- var disqus_config = function () {
107
- /*
108
- All currently supported events:
109
- onReady: fires when everything is ready,
110
- onNewComment: fires when a new comment is posted,
111
- onIdentify: fires when user is authenticated
112
- */
113
-
114
- <?php
115
- $sso = dsq_sso();
116
- if ($sso) {
117
- foreach ($sso as $k=>$v) {
118
- echo 'this.page.' . esc_js($k) . ' = \'' . esc_js($v) . '\';';
119
- echo "\n";
120
- }
121
- echo dsq_sso_login();
122
- }
123
- ?>
124
-
125
- this.language = '<?php echo esc_js( apply_filters('disqus_language_filter', '') ) ?>';
126
- <?php if (!get_option('disqus_manual_sync')): ?>
127
- this.callbacks.onReady.push(function () {
128
-
129
- // sync comments in the background so we don't block the page
130
- var script = document.createElement('script');
131
- script.async = true;
132
- script.src = '?cf_action=sync_comments&post_id=<?php echo esc_attr( $post->ID ); ?>';
133
-
134
- var firstScript = document.getElementsByTagName('script')[0];
135
- firstScript.parentNode.insertBefore(script, firstScript);
136
- });
137
- <?php endif; ?>
138
-
139
- if (disqus_config_custom) {
140
- disqus_config_custom.call(this);
141
- }
142
- };
143
-
144
- (function() {
145
- var dsq = document.createElement('script'); dsq.type = 'text/javascript';
146
- dsq.async = true;
147
- dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
148
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
149
- })();
150
- </script>
151
-
152
- <?php
153
-
154
- }
155
-
156
- ?>
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
+ if ( get_option('dsq_external_js') == '1' ) {
92
+ wp_register_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
93
+ wp_localize_script( 'dsq_embed_script', 'embedVars', $embed_vars );
94
+ wp_enqueue_script( 'dsq_embed_script', plugins_url( '/media/js/disqus.js', __FILE__ ) );
95
+ }
96
+ else {
97
+
98
+ ?>
99
+ <script type="text/javascript">
100
+ var disqus_url = '<?php echo get_permalink(); ?>';
101
+ var disqus_identifier = '<?php echo dsq_identifier_for_post($post); ?>';
102
+ var disqus_container_id = 'disqus_thread';
103
+ var disqus_shortname = '<?php echo strtolower(get_option('disqus_forum_url')); ?>';
104
+ var disqus_title = <?php echo cf_json_encode( dsq_title_for_post($post) ); ?>;
105
+ var disqus_config_custom = window.disqus_config;
106
+ var disqus_config = function () {
107
+ /*
108
+ All currently supported events:
109
+ onReady: fires when everything is ready,
110
+ onNewComment: fires when a new comment is posted,
111
+ onIdentify: fires when user is authenticated
112
+ */
113
+
114
+ <?php
115
+ $sso = dsq_sso();
116
+ if ($sso) {
117
+ foreach ($sso as $k=>$v) {
118
+ echo 'this.page.' . esc_js($k) . ' = \'' . esc_js($v) . '\';';
119
+ echo "\n";
120
+ }
121
+ echo dsq_sso_login();
122
+ }
123
+ ?>
124
+
125
+ this.language = '<?php echo esc_js( apply_filters('disqus_language_filter', '') ) ?>';
126
+ <?php if (!get_option('disqus_manual_sync')): ?>
127
+ this.callbacks.onReady.push(function () {
128
+
129
+ // sync comments in the background so we don't block the page
130
+ var script = document.createElement('script');
131
+ script.async = true;
132
+ script.src = '?cf_action=sync_comments&post_id=<?php echo esc_attr( $post->ID ); ?>';
133
+
134
+ var firstScript = document.getElementsByTagName('script')[0];
135
+ firstScript.parentNode.insertBefore(script, firstScript);
136
+ });
137
+ <?php endif; ?>
138
+
139
+ if (disqus_config_custom) {
140
+ disqus_config_custom.call(this);
141
+ }
142
+ };
143
+
144
+ (function() {
145
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript';
146
+ dsq.async = true;
147
+ dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
148
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
149
+ })();
150
+ </script>
151
+
152
+ <?php
153
+
154
+ }
155
+
156
+ ?>
disqus.php CHANGED
@@ -1,1514 +1,1523 @@
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.83
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.83');
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
- 'dsq_external_js',
40
- # SSO features
41
- 'disqus_partner_key',
42
- 'disqus_public_key',
43
- 'disqus_secret_key',
44
- 'disqus_sso_button',
45
- # disables automatic sync via cron
46
- 'disqus_manual_sync',
47
- # disables server side rendering
48
- 'disqus_disable_ssr',
49
- # the last sync comment id (from get_forum_posts)
50
- 'disqus_last_comment_id',
51
- 'disqus_version',
52
- );
53
- }
54
-
55
- /**
56
- * @param string $file
57
- * @return string
58
- */
59
- function dsq_plugin_basename($file) {
60
- $file = dirname($file);
61
-
62
- // From WP2.5 wp-includes/plugin.php:plugin_basename()
63
- $file = str_replace('\\','/',$file); // sanitize for Win32 installs
64
- $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
65
- $file = preg_replace('|^.*/' . PLUGINDIR . '/|','',$file); // get relative path from plugins dir
66
-
67
- if ( strstr($file, '/') === false ) {
68
- return $file;
69
- }
70
-
71
- $pieces = explode('/', $file);
72
- return !empty($pieces[count($pieces)-1]) ? $pieces[count($pieces)-1] : $pieces[count($pieces)-2];
73
- }
74
-
75
- if ( !defined('PLUGINDIR') ) {
76
- define('PLUGINDIR', 'wp-content/plugins'); // Relative to ABSPATH. For back compat.
77
- }
78
-
79
- $mt_disqus_version = '2.01';
80
- /**
81
- * Response from Disqus get_thread API call for comments template.
82
- *
83
- * @global string $dsq_response
84
- * @since 1.0
85
- */
86
- $dsq_response = '';
87
- /**
88
- * Disqus API instance.
89
- *
90
- * @global string $dsq_api
91
- * @since 1.0
92
- */
93
- $dsq_api = new DisqusWordPressAPI(get_option('disqus_forum_url'), get_option('disqus_api_key'));
94
-
95
- /**
96
- * Disqus currently unsupported dev toggle to output comments for this query.
97
- *
98
- * @global bool $DSQ_QUERY_COMMENTS
99
- * @since ?
100
- */
101
- $DSQ_QUERY_COMMENTS = false;
102
-
103
- /**
104
- * Disqus array to store post_ids from WP_Query for comment JS output.
105
- *
106
- * @global array $DSQ_QUERY_POST_IDS
107
- * @since 2.2
108
- */
109
- $DSQ_QUERY_POST_IDS = array();
110
-
111
- /**
112
- * Admin scripts
113
- */
114
-
115
- add_action('wp_dashboard_setup', 'dsq_wp_dashboard_setup');
116
- add_action( 'admin_enqueue_scripts', 'load_admin_scripts' );
117
-
118
- function load_admin_scripts($hook) {
119
-
120
- // Only show the pointer when Disqus isn't already configured
121
- if ( dsq_is_installed() === false ) {
122
- add_action( 'admin_print_footer_scripts', 'load_pointer_script_style' );
123
- }
124
-
125
- // Only load these scripts on the Disqus admin page
126
- if ( 'comments_page_disqus' != $hook ) {
127
- return;
128
- }
129
-
130
- $admin_vars = array(
131
- 'indexUrl' => admin_url('index.php'),
132
- );
133
-
134
- wp_register_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ) );
135
- wp_localize_script( 'admin_script', 'adminVars', $admin_vars );
136
- wp_enqueue_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ), array( 'jQuery') );
137
-
138
- wp_register_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__) );
139
- wp_enqueue_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__), array( 'jQuery') );
140
- }
141
-
142
- function dsq_wp_dashboard_setup() {
143
- add_action('admin_enqueue_scripts', 'load_dashboard_scripts');
144
- }
145
-
146
- function load_dashboard_scripts() {
147
- $stats = get_dash_comment_counts();
148
- $dashboard_vars = array(
149
- 'stats' => array(
150
- 'totalComments' => number_format($stats->total_comments),
151
- 'approved' => number_format($stats->approved),
152
- 'moderated' => number_format($stats->moderated),
153
- 'spam' => number_format($stats->spam),
154
- ),
155
- );
156
-
157
- wp_register_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ) );
158
- wp_localize_script( 'dashboard_script', 'dashboardVars', $dashboard_vars );
159
- wp_enqueue_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ), array( 'jQuery') );
160
- }
161
-
162
- /**
163
- * Adds a simple WordPress pointer to Comments menu, to remind the user to configure the plugin
164
- */
165
- function load_pointer_script_style() {
166
-
167
- // Assume pointer shouldn't be shown
168
- $enqueue_pointer_script_style = false;
169
-
170
- // Get array list of dismissed pointers for current user and convert it to array
171
- $dismissed_pointers = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
172
-
173
- // Check if our pointer is not among dismissed ones
174
- if( !in_array( 'disqus_settings_pointer', $dismissed_pointers ) ) {
175
- $enqueue_pointer_script_style = true;
176
-
177
- // Add footer scripts using callback function
178
- $pointer_content = '<h3>'.dsq_i('Disqus needs to be configured').'</h3>';
179
- $pointer_content .= '<p>'.dsq_i('Configure Disqus by clicking Comments to the left.').'</p>';
180
-
181
- wp_register_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ) );
182
- wp_localize_script( 'pointer_script', 'pointerContent', $pointer_content );
183
- wp_enqueue_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ), array( 'jQuery') );
184
- }
185
-
186
- // Enqueue pointer CSS and JS files, if needed
187
- if( $enqueue_pointer_script_style ) {
188
- wp_enqueue_style( 'wp-pointer' );
189
- wp_enqueue_script( 'wp-pointer' );
190
- }
191
- }
192
-
193
- /**
194
- * Helper functions.
195
- */
196
-
197
- /**
198
- * Tests if site is running on Wordpress VIP
199
- * @return bool
200
- */
201
- function is_wp_vip() {
202
- return defined( 'WPCOM_IS_VIP_ENV' ) && WPCOM_IS_VIP_ENV;
203
- }
204
-
205
- /**
206
- * Tests if required options are configured to display the Disqus embed.
207
- * @return bool
208
- */
209
- function dsq_is_installed() {
210
- $disqus_forum_url = get_option('disqus_forum_url');
211
- $disqus_api_key = get_option('disqus_api_key');
212
- if ( strlen( $disqus_forum_url ) > 0 && strlen( $disqus_api_key ) > 0 ) {
213
- return true;
214
- }
215
- else {
216
- return false;
217
- }
218
- }
219
-
220
- /**
221
- * @return bool
222
- */
223
- function dsq_can_replace() {
224
- global $id, $post;
225
-
226
- if (get_option('disqus_active') === '0'){ return false; }
227
-
228
- $replace = get_option('disqus_replace');
229
-
230
- if ( is_feed() ) { return false; }
231
- if ( !isset($post) ) { return false; }
232
- if ( 'draft' == $post->post_status ) { return false; }
233
- if ( !get_option('disqus_forum_url') ) { return false; }
234
- else if ( 'all' == $replace ) { return true; }
235
-
236
- if ( !isset($post->comment_count) ) {
237
- $num_comments = 0;
238
- } else {
239
- if ( 'empty' == $replace ) {
240
- // Only get count of comments, not including pings.
241
-
242
- // If there are comments, make sure there are comments (that are not track/pingbacks)
243
- if ( $post->comment_count > 0 ) {
244
- // Yuck, this causes a DB query for each post. This can be
245
- // replaced with a lighter query, but this is still not optimal.
246
- $comments = get_approved_comments($post->ID);
247
- foreach ( $comments as $comment ) {
248
- if ( $comment->comment_type != 'trackback' && $comment->comment_type != 'pingback' ) {
249
- $num_comments++;
250
- }
251
- }
252
- } else {
253
- $num_comments = 0;
254
- }
255
- }
256
- else {
257
- $num_comments = $post->comment_count;
258
- }
259
- }
260
-
261
- return ( ('empty' == $replace && 0 == $num_comments)
262
- || ('closed' == $replace && 'closed' == $post->comment_status) );
263
- }
264
-
265
- function dsq_manage_dialog($message, $error = false) {
266
- global $wp_version;
267
-
268
- echo '<div '
269
- . ( $error ? 'id="disqus_warning" ' : '')
270
- . 'class="updated fade'
271
- . ( (version_compare($wp_version, '2.5', '<') && $error) ? '-ff0000' : '' )
272
- . '"><p><strong>'
273
- . esc_attr($message)
274
- . '</strong></p></div>';
275
- }
276
-
277
- function dsq_sync_comments($comments) {
278
- if ( count($comments) < 1 ) {
279
- return;
280
- }
281
-
282
- global $wpdb;
283
-
284
- // user MUST be logged out during this process
285
- wp_set_current_user(0);
286
-
287
- // we need the thread_ids so we can map them to posts
288
- $thread_map = array();
289
- foreach ( $comments as $comment ) {
290
- $thread_map[$comment->thread->id] = null;
291
- }
292
-
293
- $thread_ids = array_keys($thread_map);
294
-
295
- $threads_query = implode(', ', array_fill(0, count($thread_ids), '%s'));
296
-
297
- // add as many placeholders as needed
298
- $sql = "
299
- SELECT post_id, meta_value
300
- FROM $wpdb->postmeta
301
- WHERE meta_key = 'dsq_thread_id' AND meta_value IN (" . $threads_query . ")
302
- ";
303
-
304
- // Call $wpdb->prepare passing the values of the array as separate arguments
305
- $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $thread_ids));
306
-
307
- $results = $wpdb->get_results($query);
308
-
309
- foreach ( $results as $result ) {
310
- $thread_map[$result->meta_value] = $result->post_id;
311
- }
312
- unset($result);
313
-
314
- foreach ( $comments as $comment ) {
315
- $ts = strtotime($comment->created_at);
316
- if (!$thread_map[$comment->thread->id] && !empty($comment->thread->identifier)) {
317
- // legacy threads dont already have their meta stored
318
- foreach ( $comment->thread->identifier as $identifier ) {
319
- // we know identifier starts with post_ID
320
- if ($post_ID = (int)substr($identifier, 0, strpos($identifier, ' '))) {
321
- $thread_map[$comment->thread->id] = $post_ID;
322
- $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $comment->thread->id, 'post' );
323
- update_post_meta($post_ID, 'dsq_thread_id', $cleaned_thread_id);
324
- if (DISQUS_DEBUG) {
325
- echo "updated post {$post_ID}: dsq_thread_id set to {$comment->thread->id}\n";
326
- }
327
- }
328
- }
329
- unset($identifier);
330
- }
331
- if (!$thread_map[$comment->thread->id]) {
332
- // shouldn't ever happen, but we can't be certain
333
- if (DISQUS_DEBUG) {
334
- if (!empty($comment->thread->identifier)) {
335
- $idents = implode(', ', $comment->thread->identifier);
336
- echo "skipped {$comment->id}: missing thread for identifiers ({$idents})\n";
337
- } else {
338
- echo "skipped {$comment->id}: missing thread (no identifier)\n";
339
- }
340
- }
341
- continue;
342
- }
343
- $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));
344
- if (count($results)) {
345
- // already exists
346
- if (DISQUS_DEBUG) {
347
- echo "skipped {$comment->id}: comment already exists\n";
348
- }
349
- if (count($results) > 1) {
350
- // clean up duplicates -- fixes an issue where a race condition allowed comments to be synced multiple times
351
- $results = array_slice($results, 1);
352
- foreach ($results as $result) {
353
- $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %s LIMIT 1", $result);
354
- }
355
- }
356
- continue;
357
- }
358
-
359
- $commentdata = false;
360
-
361
- // first lets check by the id we have stored
362
- if ($comment->meta) {
363
- $meta = explode(';', $comment->meta);
364
- foreach ($meta as $value) {
365
- $value = explode('=', $value);
366
- $meta[$value[0]] = $value[1];
367
- }
368
- unset($value);
369
- if ($meta['wp_id']) {
370
- $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);
371
- }
372
- }
373
-
374
- // skip comments that were imported but are missing meta information
375
- if (!$commentdata && $comment->imported) {
376
- if (DISQUS_DEBUG) {
377
- echo "skipped {$comment->id}: comment not found and marked as imported\n";
378
- }
379
- continue;
380
- }
381
-
382
- // and follow up using legacy Disqus agent
383
- if (!$commentdata) {
384
- $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);
385
- }
386
- if (!$commentdata) {
387
- // Comment doesnt exist yet, lets insert it
388
- if ($comment->status == 'approved') {
389
- $approved = 1;
390
- } elseif ($comment->status == 'spam') {
391
- $approved = 'spam';
392
- } else {
393
- $approved = 0;
394
- }
395
- $commentdata = array(
396
- 'comment_post_ID' => $thread_map[$comment->thread->id],
397
- 'comment_date' => date('Y-m-d\TH:i:s', strtotime($comment->created_at) + (get_option('gmt_offset') * 3600)),
398
- 'comment_date_gmt' => $comment->created_at,
399
- 'comment_content' => apply_filters('pre_comment_content', $comment->message),
400
- 'comment_approved' => $approved,
401
- 'comment_agent' => 'Disqus/1.1('.DISQUS_VERSION.'):'.intval($comment->id),
402
- 'comment_type' => '',
403
- );
404
- if ($comment->is_anonymous) {
405
- $commentdata['comment_author'] = $comment->anonymous_author->name;
406
- $commentdata['comment_author_email'] = $comment->anonymous_author->email;
407
- $commentdata['comment_author_url'] = $comment->anonymous_author->url;
408
- $commentdata['comment_author_IP'] = $comment->ip_address;
409
- } else {
410
- if (!empty($comment->author->display_name)) {
411
- $commentdata['comment_author'] = $comment->author->display_name;
412
- } else {
413
- $commentdata['comment_author'] = $comment->author->username;
414
- }
415
- $commentdata['comment_author_email'] = $comment->author->email;
416
- $commentdata['comment_author_url'] = $comment->author->url;
417
- $commentdata['comment_author_IP'] = $comment->ip_address;
418
- }
419
- $commentdata = wp_filter_comment($commentdata);
420
- if ($comment->parent_post) {
421
- $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));
422
- if ($parent_id) {
423
- $commentdata['comment_parent'] = $parent_id;
424
- }
425
- }
426
-
427
- // due to a race condition we need to test again for coment existance
428
- 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))) {
429
- // already exists
430
- if (DISQUS_DEBUG) {
431
- echo "skipped {$comment->id}: comment already exists (second check)\n";
432
- }
433
- continue;
434
- }
435
-
436
- $commentdata['comment_ID'] = wp_insert_comment($commentdata);
437
- if (DISQUS_DEBUG) {
438
- echo "inserted {$comment->id}: id is {$commentdata[comment_ID]}\n";
439
- }
440
- }
441
- if ((isset($commentdata['comment_parent']) && !$commentdata['comment_parent']) && $comment->parent_post) {
442
- $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));
443
- if ($parent_id) {
444
- $wpdb->query($wpdb->prepare( "UPDATE $wpdb->comments SET comment_parent = %s WHERE comment_id = %s", $parent_id, $commentdata['comment_ID']));
445
- if (DISQUS_DEBUG) {
446
- echo "updated {$comment->id}: comment_parent changed to {$parent_id}\n";
447
- }
448
-
449
- }
450
- }
451
- $comment_id = $commentdata['comment_ID'];
452
- update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
453
- update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
454
- }
455
- unset($comment);
456
-
457
- if( isset($_POST['dsq_api_key']) && $_POST['dsq_api_key'] == get_option('disqus_api_key') ) {
458
- if( isset($_GET['dsq_sync_action']) && isset($_GET['dsq_sync_comment_id']) ) {
459
- $comment_parts = explode('=', $_GET['dsq_sync_comment_id']);
460
-
461
- if (!($comment_id = intval($comment_parts[1])) > 0) {
462
- return;
463
- }
464
-
465
- if( 'wp_id' != $comment_parts[0] ) {
466
- $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));
467
- }
468
-
469
- switch( $_GET['dsq_sync_action'] ) {
470
- case 'mark_spam':
471
- wp_set_comment_status($comment_id, 'spam');
472
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'spam') -->";
473
- break;
474
- case 'mark_approved':
475
- wp_set_comment_status($comment_id, 'approve');
476
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'approve') -->";
477
- break;
478
- case 'mark_killed':
479
- wp_set_comment_status($comment_id, 'hold');
480
- echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'hold') -->";
481
- break;
482
- }
483
- }
484
- }
485
- }
486
-
487
- function dsq_request_handler() {
488
- global $dsq_response;
489
- global $dsq_api;
490
- global $post;
491
- global $wpdb;
492
-
493
- if (!empty($_GET['cf_action'])) {
494
- switch ($_GET['cf_action']) {
495
- case 'sync_comments':
496
- if( !( $post_id = $_GET['post_id'] ) ) {
497
- header("HTTP/1.0 400 Bad Request");
498
- die();
499
- }
500
- // schedule the event for 5 minutes from now in case they
501
- // happen to make a quick post
502
- dsq_add_pending_post_id($post_id);
503
-
504
- if (DISQUS_DEBUG) {
505
- $response = dsq_sync_forum();
506
- if (!$response) {
507
- die('// error: '.$dsq_api->get_last_error());
508
- } else {
509
- list($last_comment_id, $comments) = $response;
510
- die('// synced '.$comments.' comments');
511
- }
512
- } else {
513
- $ts = time() + 300;
514
- wp_schedule_single_event($ts, 'dsq_sync_forum');
515
- die('// sync scheduled');
516
- }
517
- break;
518
- case 'export_comments':
519
- if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
520
- $msg = '';
521
- $result = '';
522
- $response = null;
523
-
524
- $timestamp = intval($_GET['timestamp']);
525
- $post_id = intval($_GET['post_id']);
526
- if ( isset($_GET['_dsqexport_wpnonce']) === false ) {
527
- $msg = dsq_i('Unable to export comments. Make sure you are accessing this page from the Wordpress dashboard.');
528
- $result = 'fail';
529
- }
530
- else {
531
-
532
- // Check nonce
533
- check_admin_referer('dsq-wpnonce_export', '_dsqexport_wpnonce');
534
-
535
- global $wpdb, $dsq_api;
536
- $post = $wpdb->get_results($wpdb->prepare("
537
- SELECT *
538
- FROM $wpdb->posts
539
- WHERE post_type != 'revision'
540
- AND post_status = 'publish'
541
- AND comment_count > 0
542
- AND ID > %d
543
- ORDER BY ID ASC
544
- LIMIT 1
545
- ", $post_id));
546
- $post = $post[0];
547
- $post_id = $post->ID;
548
- $max_post_id = $wpdb->get_var("
549
- SELECT MAX(Id)
550
- FROM $wpdb->posts
551
- WHERE post_type != 'revision'
552
- AND post_status = 'publish'
553
- AND comment_count > 0
554
- ");
555
- $eof = (int)($post_id == $max_post_id);
556
- if ($eof) {
557
- $status = 'complete';
558
- $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
559
- $msg .= '<br/><a href="'.DISQUS_IMPORTER_URL.'" target="_blank">';
560
- $msg .= dsq_i('See the status of your import at Disqus') . '</a>';
561
- }
562
- else {
563
- $status = 'partial';
564
- $msg = dsq_i('Processed comments on post') . ' #'. $post_id . '&hellip;';
565
- }
566
- $result = 'fail';
567
- if ($post) {
568
- require_once(dirname(__FILE__) . '/export.php');
569
- $wxr = dsq_export_wp($post);
570
- $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
571
- if (!($response['group_id'] > 0)) {
572
- $result = 'fail';
573
- $msg = '<p class="status dsq-export-fail">';
574
- $msg .= dsq_i('Sorry, something unexpected happened with the export. Please try again.');
575
- $msg .= '</p><p>';
576
- $msg .= dsq_i('If your API key has changed, you may need to reinstall Disqus (deactivate the plugin and then reactivate it).');
577
- $msg .= dsq_i('If you are still having issues, refer to the %s WordPress help page',
578
- '<a href="https://help.disqus.com/customer/portal/articles/472005" onclick="window.open(this.href); return false">');
579
- $msg .= '</a></p>';
580
- $response = $dsq_api->get_last_error();
581
- }
582
- else {
583
- if ($eof) {
584
- $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
585
- $msg .= '<br/><a href="' . $response['link'] . '" target="_blank">';
586
- $msg .= dsq_i('See the status of your import at Disqus');
587
- $msg .= '</a>';
588
- }
589
- $result = 'success';
590
- }
591
- }
592
- }
593
-
594
- // send AJAX response
595
- $response = compact('result', 'timestamp', 'status', 'post_id', 'msg', 'eof', 'response');
596
- header('Content-type: text/javascript');
597
- echo cf_json_encode($response);
598
- die();
599
- }
600
- break;
601
- case 'import_comments':
602
- if (current_user_can('manage_options')) {
603
- $msg = '';
604
- $result = '';
605
- $response = null;
606
-
607
- if ( isset($_GET['_dsqimport_wpnonce']) === false ) {
608
- $msg = dsq_i('Unable to import comments. Make sure you are accessing this page from the Wordpress dashboard.');
609
- $result = 'fail';
610
- }
611
- else
612
- {
613
- // Check nonce
614
- check_admin_referer('dsq-wpnonce_import', '_dsqimport_wpnonce');
615
-
616
- if (!isset($_GET['last_comment_id'])) $last_comment_id = false;
617
- else $last_comment_id = $_GET['last_comment_id'];
618
-
619
- if ($_GET['wipe'] == '1') {
620
- $wpdb->query("DELETE FROM `".$wpdb->prefix."commentmeta` WHERE meta_key IN ('dsq_post_id', 'dsq_parent_post_id')");
621
- $wpdb->query("DELETE FROM `".$wpdb->prefix."comments` WHERE comment_agent LIKE 'Disqus/%%'");
622
- }
623
-
624
- ob_start();
625
- $response = dsq_sync_forum($last_comment_id, true);
626
- $debug = ob_get_clean();
627
- if (!$response) {
628
- $status = 'error';
629
- $result = 'fail';
630
- $error = $dsq_api->get_last_error();
631
- $msg = '<p class="status dsq-export-fail">'.dsq_i('There was an error downloading your comments from Disqus.').'<br/>'.esc_attr($error).'</p>';
632
- } else {
633
- list($comments, $last_comment_id) = $response;
634
- if (!$comments) {
635
- $status = 'complete';
636
- $msg = dsq_i('Your comments have been downloaded from Disqus and saved in your local database.');
637
- } else {
638
- $status = 'partial';
639
- $msg = dsq_i('Import in progress (last post id: %s)', $last_comment_id) . ' &hellip;';
640
- }
641
- $result = 'success';
642
- }
643
- $debug = explode("\n", $debug);
644
- $response = compact('result', 'status', 'comments', 'msg', 'last_comment_id', 'debug');
645
- header('Content-type: text/javascript');
646
- echo cf_json_encode($response);
647
- die();
648
- }
649
- }
650
- break;
651
- }
652
- }
653
- }
654
-
655
- add_action('init', 'dsq_request_handler');
656
-
657
- /**
658
- * @param string $option_name
659
- */
660
- function dsq_image_upload_handler($option_name) {
661
- // If the upload field has a file in it
662
- if(isset($_FILES[$option_name]) && ($_FILES[$option_name]['size'] > 0)) {
663
- // Get the type of the uploaded file. This is returned as "type/extension"
664
- $arr_file_type = wp_check_filetype(basename($_FILES[$option_name]['name']));
665
- $uploaded_file_type = $arr_file_type['type'];
666
- // Set an array containing a list of acceptable formats
667
- $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png','image/x-icon');
668
- // If the uploaded file is the right format
669
- if(in_array($uploaded_file_type, $allowed_file_types)) {
670
- // Options array for the wp_handle_upload function. 'test_upload' => false
671
- $upload_overrides = array( 'test_form' => false );
672
- // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
673
- $uploaded_file = wp_handle_upload($_FILES[$option_name], $upload_overrides);
674
- // If the wp_handle_upload call returned a local path for the image
675
- if(isset($uploaded_file['url'])) {
676
- update_option($option_name, $uploaded_file['url']);
677
- }
678
- }
679
- }
680
- }
681
-
682
- function dsq_add_pending_post_id($post_id) {
683
- update_post_meta($post_id, 'dsq_needs_sync', '1', $unique=true);
684
- }
685
-
686
- function dsq_get_pending_post_ids() {
687
- global $wpdb;
688
-
689
- $results = $wpdb->get_results( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'dsq_needs_sync'");
690
- $post_ids = array();
691
- foreach ($results as $result) {
692
- $post_ids[] = $result->post_id;
693
- }
694
- return $post_ids;
695
- }
696
-
697
- function dsq_clear_pending_post_ids($post_ids) {
698
- if ( count($post_ids) < 1 ) {
699
- return;
700
- }
701
-
702
- global $wpdb;
703
-
704
- $posts_query = implode(', ', array_fill(0, count($post_ids), '%s'));
705
-
706
- // add as many placeholders as needed
707
- $sql = "
708
- DELETE FROM {$wpdb->postmeta}
709
- WHERE meta_key = 'dsq_needs_sync' AND post_id IN (" . $posts_query . ")
710
- ";
711
-
712
- // Call $wpdb->prepare passing the values of the array as separate arguments
713
- $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $post_ids));
714
-
715
- $wpdb->query($query);
716
-
717
- update_meta_cache('dsq_needs_sync', $post_ids);
718
- }
719
-
720
-
721
- function dsq_sync_post($post_id) {
722
- global $dsq_api, $wpdb;
723
-
724
- $post = get_post($post_id);
725
-
726
- // Call update_thread to ensure our permalink is up to date
727
- dsq_update_permalink($post);
728
- }
729
-
730
- function dsq_sync_forum($last_comment_id=false, $force=false) {
731
- global $dsq_api, $wpdb;
732
-
733
- set_time_limit(DISQUS_SYNC_TIMEOUT);
734
-
735
- if ($force) {
736
- $sync_time = null;
737
- } else {
738
- $sync_time = (int)get_option('_disqus_sync_lock');
739
- }
740
-
741
- // lock expires after 1 hour
742
- if ($sync_time && $sync_time > time() - 60*60) {
743
- $dsq_api->api->last_error = 'Sync already in progress (lock found)';
744
- return false;
745
- } else {
746
- update_option('_disqus_sync_lock', time());
747
- }
748
-
749
- // sync all pending posts
750
- $post_ids = dsq_get_pending_post_ids();
751
- dsq_clear_pending_post_ids($post_ids);
752
-
753
- foreach ($post_ids as $post_id) {
754
- dsq_sync_post($post_id);
755
- }
756
-
757
- if ($last_comment_id === false) {
758
- $last_comment_id = get_option('disqus_last_comment_id');
759
- if (!$last_comment_id) {
760
- $last_comment_id = 0;
761
- }
762
- }
763
- if ($last_comment_id) {
764
- $last_comment_id++;
765
- }
766
-
767
- //$last_comment_id = 0;
768
-
769
- // Pull comments from API
770
- $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
771
- if( $dsq_response < 0 || $dsq_response === false ) {
772
- return false;
773
- }
774
-
775
- // Sync comments with database.
776
- dsq_sync_comments($dsq_response);
777
- $total = 0;
778
- if ($dsq_response) {
779
- foreach ($dsq_response as $comment) {
780
- $total += 1;
781
- if ($comment->id > $last_comment_id) $last_comment_id = $comment->id;
782
- }
783
- if ($last_comment_id > get_option('disqus_last_comment_id')) {
784
- update_option('disqus_last_comment_id', $last_comment_id);
785
- }
786
- }
787
- unset($comment);
788
- delete_option('_disqus_sync_lock');
789
- return array($total, $last_comment_id);
790
- }
791
-
792
- add_action('dsq_sync_forum', 'dsq_sync_forum');
793
-
794
- function dsq_update_permalink($post) {
795
- global $dsq_api;
796
-
797
- if (DISQUS_DEBUG) {
798
- echo "updating post on disqus: {$post->ID}\n";
799
- }
800
-
801
- $response = $dsq_api->api->update_thread(null, array(
802
- 'thread_identifier' => dsq_identifier_for_post($post),
803
- 'title' => dsq_title_for_post($post),
804
- 'url' => dsq_link_for_post($post)
805
- ));
806
-
807
- $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $response->id, 'post' );
808
- update_post_meta($post->ID, 'dsq_thread_id', $cleaned_thread_id);
809
-
810
- return $response;
811
- }
812
-
813
- /**
814
- * Compatibility
815
- */
816
-
817
- if (!function_exists ( '_wp_specialchars' ) ) {
818
- function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
819
- $string = (string) $string;
820
-
821
- if ( 0 === strlen( $string ) ) {
822
- return '';
823
- }
824
-
825
- // Don't bother if there are no specialchars - saves some processing
826
- if ( !preg_match( '/[&<>"\']/', $string ) ) {
827
- return $string;
828
- }
829
-
830
- // Account for the previous behaviour of the function when the $quote_style is not an accepted value
831
- if ( empty( $quote_style ) ) {
832
- $quote_style = ENT_NOQUOTES;
833
- } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
834
- $quote_style = ENT_QUOTES;
835
- }
836
-
837
- // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
838
- if ( !$charset ) {
839
- static $_charset;
840
- if ( !isset( $_charset ) ) {
841
- $alloptions = wp_load_alloptions();
842
- $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
843
- }
844
- $charset = $_charset;
845
- }
846
- if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
847
- $charset = 'UTF-8';
848
- }
849
-
850
- $_quote_style = $quote_style;
851
-
852
- if ( $quote_style === 'double' ) {
853
- $quote_style = ENT_COMPAT;
854
- $_quote_style = ENT_COMPAT;
855
- } elseif ( $quote_style === 'single' ) {
856
- $quote_style = ENT_NOQUOTES;
857
- }
858
-
859
- // Handle double encoding ourselves
860
- if ( !$double_encode ) {
861
- $string = wp_specialchars_decode( $string, $_quote_style );
862
- $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
863
- }
864
-
865
- $string = @esc_attr( $string, $quote_style, $charset );
866
-
867
- // Handle double encoding ourselves
868
- if ( !$double_encode ) {
869
- $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string );
870
- }
871
-
872
- // Backwards compatibility
873
- if ( 'single' === $_quote_style ) {
874
- $string = str_replace( "'", '&#039;', $string );
875
- }
876
-
877
- return $string;
878
- }
879
- }
880
-
881
- if (!function_exists ( 'wp_check_invalid_utf8' ) ) {
882
- function wp_check_invalid_utf8( $string, $strip = false ) {
883
- $string = (string) $string;
884
-
885
- if ( 0 === strlen( $string ) ) {
886
- return '';
887
- }
888
-
889
- // Store the site charset as a static to avoid multiple calls to get_option()
890
- static $is_utf8;
891
- if ( !isset( $is_utf8 ) ) {
892
- $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
893
- }
894
- if ( !$is_utf8 ) {
895
- return $string;
896
- }
897
-
898
- // Check for support for utf8 in the installed PCRE library once and store the result in a static
899
- static $utf8_pcre;
900
- if ( !isset( $utf8_pcre ) ) {
901
- $utf8_pcre = @preg_match( '/^./u', 'a' );
902
- }
903
- // We can't demand utf8 in the PCRE installation, so just return the string in those cases
904
- if ( !$utf8_pcre ) {
905
- return $string;
906
- }
907
-
908
- // preg_match fails when it encounters invalid UTF8 in $string
909
- if ( 1 === @preg_match( '/^./us', $string ) ) {
910
- return $string;
911
- }
912
-
913
- // Attempt to strip the bad chars if requested (not recommended)
914
- if ( $strip && function_exists( 'iconv' ) ) {
915
- return iconv( 'utf-8', 'utf-8', $string );
916
- }
917
-
918
- return '';
919
- }
920
- }
921
-
922
- if (!function_exists ( 'esc_html' ) ) {
923
- function esc_html( $text ) {
924
- $safe_text = wp_check_invalid_utf8( $text );
925
- $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
926
- return apply_filters( 'esc_html', $safe_text, $text );
927
- }
928
- }
929
-
930
- if (!function_exists ( 'esc_attr' ) ) {
931
- function esc_attr( $text ) {
932
- $safe_text = wp_check_invalid_utf8( $text );
933
- $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
934
- return apply_filters( 'attribute_escape', $safe_text, $text );
935
- }
936
- }
937
-
938
- /**
939
- * Filters/Actions
940
- */
941
-
942
- // ugly global hack for comments closing
943
- $EMBED = false;
944
- function dsq_comments_template($value) {
945
- global $EMBED;
946
- global $post;
947
- global $comments;
948
-
949
- if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
950
- return;
951
- }
952
-
953
- if ( !dsq_is_installed() || !dsq_can_replace() ) {
954
- return $value;
955
- }
956
-
957
- // TODO: If a disqus-comments.php is found in the current template's
958
- // path, use that instead of the default bundled comments.php
959
- //return TEMPLATEPATH . '/disqus-comments.php';
960
- $EMBED = true;
961
- return dirname(__FILE__) . '/comments.php';
962
- }
963
-
964
- function dsq_comment( $comment, $args, $depth ) {
965
- $GLOBALS['comment'] = $comment;
966
- switch ($comment->comment_type):
967
- case '' :
968
- ?>
969
- <li <?php comment_class(); ?> id="dsq-comment-<?php echo comment_ID(); ?>">
970
- <div id="dsq-comment-header-<?php echo comment_ID(); ?>" class="dsq-comment-header">
971
- <cite id="dsq-cite-<?php echo comment_ID(); ?>">
972
- <?php if(comment_author_url()) : ?>
973
- <a id="dsq-author-user-<?php echo comment_ID(); ?>" href="<?php echo comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo comment_author(); ?></a>
974
- <?php else : ?>
975
- <span id="dsq-author-user-<?php echo comment_ID(); ?>"><?php echo comment_author(); ?></span>
976
- <?php endif; ?>
977
- </cite>
978
- </div>
979
- <div id="dsq-comment-body-<?php echo comment_ID(); ?>" class="dsq-comment-body">
980
- <div id="dsq-comment-message-<?php echo comment_ID(); ?>" class="dsq-comment-message"><?php echo wp_filter_kses(comment_text()); ?></div>
981
- </div>
982
-
983
- <?php
984
- break;
985
- case 'pingback' :
986
- case 'trackback' :
987
- ?>
988
- <li class="post pingback">
989
- <p><?php echo dsq_i('Pingback:'); ?> <?php comment_author_link(); ?>(<?php edit_comment_link(dsq_i('Edit'), ' '); ?>)</p>
990
- </li>
991
- <?php
992
- break;
993
- endswitch;
994
- }
995
-
996
- // Mark entries in index to replace comments link.
997
- // As of WordPress 3.1 this is required to return a numerical value
998
- function dsq_comments_number($count) {
999
- global $post;
1000
-
1001
- return $count;
1002
- }
1003
-
1004
- function dsq_comments_text($comment_text) {
1005
- global $post;
1006
-
1007
- if ( dsq_can_replace() ) {
1008
- return '<span class="dsq-postid" data-dsqidentifier="'.esc_attr(dsq_identifier_for_post($post)).'">'.$comment_text.'</span>';
1009
- } else {
1010
- return $comment_text;
1011
- }
1012
- }
1013
-
1014
- function dsq_bloginfo_url($url) {
1015
- if ( get_feed_link('comments_rss2') == $url && dsq_can_replace() ) {
1016
- return 'https://' . strtolower(get_option('disqus_forum_url')) . '.disqus.com' . DISQUS_RSS_PATH;
1017
- } else {
1018
- return $url;
1019
- }
1020
- }
1021
-
1022
- function dsq_plugin_action_links($links, $file) {
1023
- $plugin_file = basename(__FILE__);
1024
- if (basename($file) == $plugin_file) {
1025
- if (!dsq_is_installed()) {
1026
- $settings_link = '<a href="edit-comments.php?page=disqus">'.dsq_i('Configure').'</a>';
1027
- } else {
1028
- $settings_link = '<a href="edit-comments.php?page=disqus#adv">'.dsq_i('Settings').'</a>';
1029
- }
1030
- array_unshift($links, $settings_link);
1031
- }
1032
- return $links;
1033
- }
1034
- add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
1035
-
1036
- /**
1037
- * Hide the default comment form to stop spammers by marking all comments
1038
- * as closed.
1039
- */
1040
- function dsq_comments_open($open, $post_id=null) {
1041
- global $EMBED;
1042
- if ($EMBED) return false;
1043
- return $open;
1044
- }
1045
- add_filter('comments_open', 'dsq_comments_open');
1046
-
1047
- // Always add Disqus management page to the admin menu
1048
- function dsq_add_pages() {
1049
- add_submenu_page(
1050
- 'edit-comments.php',
1051
- 'Disqus',
1052
- 'Disqus',
1053
- 'moderate_comments',
1054
- 'disqus',
1055
- 'dsq_manage'
1056
- );
1057
- }
1058
- add_action('admin_menu', 'dsq_add_pages', 10);
1059
-
1060
- // only active on dashboard
1061
- function get_dash_comment_counts() {
1062
- global $wpdb;
1063
- // taken from wp-includes/comment.php - WP 2.8.5
1064
- $count = $wpdb->get_results("
1065
- SELECT comment_approved, COUNT( * ) AS num_comments
1066
- FROM {$wpdb->comments}
1067
- WHERE comment_type != 'trackback'
1068
- AND comment_type != 'pingback'
1069
- GROUP BY comment_approved
1070
- ", ARRAY_A );
1071
- $total = 0;
1072
- $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
1073
- $known_types = array_keys( $approved );
1074
- foreach( (array) $count as $row_num => $row ) {
1075
- $total += $row['num_comments'];
1076
- if ( in_array( $row['comment_approved'], $known_types ) && array_key_exists($row['comment_approved'], $approved) )
1077
- $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1078
- }
1079
-
1080
- $stats['total_comments'] = $total;
1081
- foreach ( $approved as $key ) {
1082
- if ( empty($stats[$key]) )
1083
- $stats[$key] = 0;
1084
- }
1085
- return (object) $stats;
1086
- }
1087
-
1088
- function dsq_manage() {
1089
- if (dsq_does_need_update() && isset($_POST['upgrade'])) {
1090
- dsq_install();
1091
- }
1092
-
1093
- if (dsq_does_need_update() && !isset($_POST['reset'])) {
1094
- include_once(dirname(__FILE__) . '/upgrade.php');
1095
- } else {
1096
- include_once(dirname(__FILE__) . '/manage.php');
1097
- }
1098
- }
1099
-
1100
- function dsq_admin_head() {
1101
- if (isset($_GET['page']) && $_GET['page'] == 'disqus') {
1102
- ?>
1103
- <link rel='stylesheet' href='<?php echo esc_url( plugins_url( 'media/styles/manage.css', __FILE__ ) ); ?>' type='text/css' />
1104
- <style type="text/css">
1105
- .dsq-importing, .dsq-imported, .dsq-import-fail, .dsq-exporting, .dsq-exported, .dsq-export-fail {
1106
- background: url(<?php echo esc_url( admin_url('images/loading.gif') ); ?>) left center no-repeat;
1107
- line-height: 16px;
1108
- padding-left: 20px;
1109
- }
1110
- p.status {
1111
- padding-top: 0;
1112
- padding-bottom: 0;
1113
- margin: 0;
1114
- }
1115
- .dsq-imported, .dsq-exported {
1116
- background: url(<?php echo esc_url( admin_url('images/yes.png') ); ?>) left center no-repeat;
1117
- }
1118
- .dsq-import-fail, .dsq-export-fail {
1119
- background: url(<?php echo esc_url( admin_url('images/no.png') ); ?>) left center no-repeat;
1120
- }
1121
- </style>
1122
- <?php
1123
- // HACK: Our own styles for older versions of WordPress.
1124
- global $wp_version;
1125
- if ( version_compare($wp_version, '2.5', '<') ) {
1126
- echo "<link rel='stylesheet' href='" . esc_url( plugins_url( 'media/styles/manage-pre25.css', __FILE__ ) ) . "' type='text/css' />";
1127
- }
1128
- }
1129
- }
1130
- add_action('admin_head', 'dsq_admin_head');
1131
-
1132
- /**
1133
- * Wrapper for built-in __() which pulls all text from
1134
- * the disqus domain and supports variable interpolation.
1135
- */
1136
- function dsq_i($text, $params=null) {
1137
- if (!is_array($params))
1138
- {
1139
- $params = func_get_args();
1140
- $params = array_slice($params, 1);
1141
- }
1142
- return vsprintf(__($text, 'disqus'), $params);
1143
- }
1144
-
1145
- // catch original query
1146
- function dsq_parse_query($query) {
1147
- add_action('the_posts', 'dsq_add_request_post_ids', 999);
1148
- }
1149
- add_action('parse_request', 'dsq_parse_query');
1150
-
1151
- // track the original request post_ids, only run once
1152
- function dsq_add_request_post_ids($posts) {
1153
- dsq_add_query_posts($posts);
1154
- remove_action('the_posts', 'dsq_log_request_post_ids', 999);
1155
- return $posts;
1156
- }
1157
-
1158
- function dsq_maybe_add_post_ids($posts) {
1159
- global $DSQ_QUERY_COMMENTS;
1160
- if ($DSQ_QUERY_COMMENTS) {
1161
- dsq_add_query_posts($posts);
1162
- }
1163
- return $posts;
1164
- }
1165
- add_action('the_posts', 'dsq_maybe_add_post_ids');
1166
-
1167
- function dsq_add_query_posts($posts) {
1168
- global $DSQ_QUERY_POST_IDS;
1169
- if (count($posts)) {
1170
- foreach ($posts as $post) {
1171
- $post_ids[] = intval($post->ID);
1172
- }
1173
- $DSQ_QUERY_POST_IDS[md5(serialize($post_ids))] = $post_ids;
1174
- }
1175
- }
1176
-
1177
- function dsq_output_count_js() {
1178
- if ( get_option('dsq_external_js') == '1' ) {
1179
- $count_vars = array(
1180
- 'disqusShortname' => strtolower( get_option( 'disqus_forum_url' ) ),
1181
- );
1182
-
1183
- wp_register_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1184
- wp_localize_script( 'dsq_count_script', 'countVars', $count_vars );
1185
- wp_enqueue_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1186
- }
1187
- else {
1188
- ?>
1189
- <script type="text/javascript">
1190
- // <![CDATA[
1191
- var disqus_shortname = '<?php echo strtolower( get_option('disqus_forum_url') ); ?>';
1192
- (function () {
1193
- var nodes = document.getElementsByTagName('span');
1194
- for (var i = 0, url; i < nodes.length; i++) {
1195
- if (nodes[i].className.indexOf('dsq-postid') != -1) {
1196
- nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('rel'));
1197
- url = nodes[i].parentNode.href.split('#', 1);
1198
- if (url.length == 1) { url = url[0]; }
1199
- else { url = url[1]; }
1200
- nodes[i].parentNode.href = url + '#disqus_thread';
1201
- }
1202
- }
1203
- var s = document.createElement('script');
1204
- s.async = true;
1205
- s.type = 'text/javascript';
1206
- s.src = '//' + disqus_shortname + '.<?php echo DISQUS_DOMAIN; ?>/count.js';
1207
- (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
1208
- }());
1209
- // ]]>
1210
- </script>
1211
- <?php
1212
- }
1213
- }
1214
-
1215
- function dsq_output_footer_comment_js() {
1216
- if (!dsq_can_replace()) return;
1217
-
1218
- dsq_output_count_js();
1219
- }
1220
-
1221
- add_action('wp_footer', 'dsq_output_footer_comment_js');
1222
-
1223
- // UPDATE DSQ when a permalink changes
1224
-
1225
- $dsq_prev_permalinks = array();
1226
-
1227
- function dsq_prev_permalink($post_id) {
1228
- $post = get_post($post_id);
1229
- // if post not published, return
1230
- if ($post->post_status != 'publish') {
1231
- return;
1232
- }
1233
- global $dsq_prev_permalinks;
1234
- $dsq_prev_permalinks['post_'.$post_id] = get_permalink($post_id);
1235
- }
1236
- add_action('pre_post_update', 'dsq_prev_permalink');
1237
-
1238
- function dsq_check_permalink($post_id) {
1239
- global $dsq_prev_permalinks;
1240
- if (!empty($dsq_prev_permalinks['post_'.$post_id]) &&
1241
- $dsq_prev_permalinks['post_'.$post_id] != get_permalink($post_id)
1242
- ) {
1243
- $post = get_post($post_id);
1244
- dsq_update_permalink($post);
1245
- }
1246
- }
1247
- add_action('edit_post', 'dsq_check_permalink');
1248
-
1249
- // Only replace comments if the disqus_forum_url option is set.
1250
- add_filter('comments_template', 'dsq_comments_template');
1251
- add_filter('comments_number', 'dsq_comments_text');
1252
- add_filter('get_comments_number', 'dsq_comments_number');
1253
- add_filter('bloginfo_url', 'dsq_bloginfo_url');
1254
-
1255
- /**
1256
- * JSON ENCODE for PHP < 5.2.0
1257
- * Checks if json_encode is not available and defines json_encode
1258
- * to use php_json_encode in its stead
1259
- * Works on iteratable objects as well - stdClass is iteratable, so all WP objects are gonna be iteratable
1260
- */
1261
- if(!function_exists('cf_json_encode')) {
1262
- function cf_json_encode($data) {
1263
-
1264
- // json_encode is sending an application/x-javascript header on Joyent servers
1265
- // for some unknown reason.
1266
- return cfjson_encode($data);
1267
- }
1268
-
1269
- function cfjson_encode_string($str) {
1270
- if(is_bool($str)) {
1271
- return $str ? 'true' : 'false';
1272
- }
1273
-
1274
- return str_replace(
1275
- array(
1276
- '"'
1277
- , '/'
1278
- , "\n"
1279
- , "\r"
1280
- )
1281
- , array(
1282
- '\"'
1283
- , '\/'
1284
- , '\n'
1285
- , '\r'
1286
- )
1287
- , $str
1288
- );
1289
- }
1290
-
1291
- function cfjson_encode($arr) {
1292
- $json_str = '';
1293
- if (is_array($arr)) {
1294
- $pure_array = true;
1295
- $array_length = count($arr);
1296
- for ( $i = 0; $i < $array_length ; $i++) {
1297
- if (!isset($arr[$i])) {
1298
- $pure_array = false;
1299
- break;
1300
- }
1301
- }
1302
- if ($pure_array) {
1303
- $json_str = '[';
1304
- $temp = array();
1305
- for ($i=0; $i < $array_length; $i++) {
1306
- $temp[] = sprintf("%s", cfjson_encode($arr[$i]));
1307
- }
1308
- $json_str .= implode(',', $temp);
1309
- $json_str .="]";
1310
- }
1311
- else {
1312
- $json_str = '{';
1313
- $temp = array();
1314
- foreach ($arr as $key => $value) {
1315
- $temp[] = sprintf("\"%s\":%s", $key, cfjson_encode($value));
1316
- }
1317
- $json_str .= implode(',', $temp);
1318
- $json_str .= '}';
1319
- }
1320
- }
1321
- else if (is_object($arr)) {
1322
- $json_str = '{';
1323
- $temp = array();
1324
- foreach ($arr as $k => $v) {
1325
- $temp[] = '"'.$k.'":'.cfjson_encode($v);
1326
- }
1327
- $json_str .= implode(',', $temp);
1328
- $json_str .= '}';
1329
- }
1330
- else if (is_string($arr)) {
1331
- $json_str = '"'. cfjson_encode_string($arr) . '"';
1332
- }
1333
- else if (is_numeric($arr)) {
1334
- $json_str = $arr;
1335
- }
1336
- else if (is_bool($arr)) {
1337
- $json_str = $arr ? 'true' : 'false';
1338
- }
1339
- else {
1340
- $json_str = '"'. cfjson_encode_string($arr) . '"';
1341
- }
1342
- return $json_str;
1343
- }
1344
- }
1345
-
1346
- // Single Sign-on Integration
1347
-
1348
- function dsq_sso_login() {
1349
- global $current_site;
1350
- $sitename = get_bloginfo('name');
1351
- $siteurl = site_url();
1352
- $button = get_option('disqus_sso_button');
1353
- $sso_login_str = 'this.sso = {
1354
- name: "' . esc_js( $sitename ) . '",
1355
- button: "' . $button . '",
1356
- url: "' . $siteurl . '/wp-login.php",
1357
- logout: "' . $siteurl . '/wp-login.php?action=logout",
1358
- width: "800",
1359
- height: "700"
1360
- };';
1361
- return $sso_login_str;
1362
- }
1363
-
1364
- function dsq_sso() {
1365
- if ($key = get_option('disqus_partner_key')) {
1366
- // use old style SSO
1367
- $new = false;
1368
- } elseif (($key = get_option('disqus_secret_key')) && ($public = get_option('disqus_public_key'))) {
1369
- // use new style SSO
1370
- $new = true;
1371
- } else {
1372
- // sso is not configured
1373
- return array();
1374
- }
1375
- global $current_user, $dsq_api;
1376
- get_currentuserinfo();
1377
- if ($current_user->ID) {
1378
- $avatar_tag = get_avatar($current_user->ID);
1379
- $avatar_data = array();
1380
- preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
1381
- $avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
1382
- $user_data = array(
1383
- 'username' => $current_user->display_name,
1384
- 'id' => $current_user->ID,
1385
- 'avatar' => $avatar,
1386
- 'email' => $current_user->user_email,
1387
- 'url' => $current_user->user_url,
1388
- );
1389
- }
1390
- else {
1391
- $user_data = array();
1392
- }
1393
- $user_data = base64_encode(cf_json_encode($user_data));
1394
- $time = time();
1395
- $hmac = dsq_hmacsha1($user_data.' '.$time, $key);
1396
-
1397
- $payload = $user_data.' '.$hmac.' '.$time;
1398
-
1399
- if ($new) {
1400
- return array('remote_auth_s3'=>$payload, 'api_key'=>$public);
1401
- } else {
1402
- return array('remote_auth_s2'=>$payload);
1403
- }
1404
- }
1405
-
1406
- // from: http://www.php.net/manual/en/function.sha1.php#39492
1407
- // Calculate HMAC-SHA1 according to RFC2104
1408
- // http://www.ietf.org/rfc/rfc2104.txt
1409
- function dsq_hmacsha1($data, $key) {
1410
- $blocksize=64;
1411
- $hashfunc='sha1';
1412
- if (strlen($key)>$blocksize)
1413
- $key=pack('H*', $hashfunc($key));
1414
- $key=str_pad($key,$blocksize,chr(0x00));
1415
- $ipad=str_repeat(chr(0x36),$blocksize);
1416
- $opad=str_repeat(chr(0x5c),$blocksize);
1417
- $hmac = pack(
1418
- 'H*',$hashfunc(
1419
- ($key^$opad).pack(
1420
- 'H*',$hashfunc(
1421
- ($key^$ipad).$data
1422
- )
1423
- )
1424
- )
1425
- );
1426
- return bin2hex($hmac);
1427
- }
1428
-
1429
- function dsq_identifier_for_post($post) {
1430
- return $post->ID . ' ' . $post->guid;
1431
- }
1432
-
1433
- function dsq_title_for_post($post) {
1434
- $title = get_the_title($post);
1435
- $title = strip_tags($title, DISQUS_ALLOWED_HTML);
1436
- return $title;
1437
- }
1438
-
1439
- function dsq_link_for_post($post) {
1440
- return get_permalink($post);
1441
- }
1442
-
1443
- function dsq_does_need_update() {
1444
- $version = (string)get_option('disqus_version');
1445
- if (empty($version)) {
1446
- $version = '0';
1447
- }
1448
-
1449
- if (version_compare($version, '2.49', '<')) {
1450
- return true;
1451
- }
1452
-
1453
- return false;
1454
- }
1455
-
1456
- function dsq_install($allow_database_install=true) {
1457
- global $wpdb, $userdata;
1458
-
1459
- $version = (string)get_option('disqus_version');
1460
- if (!$version) {
1461
- $version = '0';
1462
- }
1463
-
1464
- if ($allow_database_install)
1465
- {
1466
- dsq_install_database($version);
1467
- }
1468
-
1469
- if (version_compare($version, DISQUS_VERSION, '=')) return;
1470
-
1471
- // if this is a new install, we should not set disqus active
1472
- if ($version == '0') {
1473
- add_option('disqus_active', '0');
1474
- } else {
1475
- add_option('disqus_active', '1');
1476
- }
1477
-
1478
- update_option('disqus_version', DISQUS_VERSION);
1479
- }
1480
-
1481
- /**
1482
- * Initializes the database if it's not already present.
1483
- */
1484
- function dsq_install_database($version=0) {
1485
- global $wpdb;
1486
-
1487
- if ( version_compare($version, '2.49', '<') && !is_wp_vip() ) {
1488
- $wpdb->query("CREATE INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta` (meta_key, meta_value(11));");
1489
- }
1490
- }
1491
- function dsq_reset_database($version=0) {
1492
- global $wpdb;
1493
-
1494
- if ( version_compare($version, '2.49', '>=') && !is_wp_vip() ) {
1495
- $wpdb->query("DROP INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta`;");
1496
- }
1497
- }
1498
-
1499
- /**
1500
- * Disable internal Wordpress commenting if Disqus is enabled - this prevents spam bots from
1501
- * commenting using POST requests to /wp-comments-post.php.
1502
- *
1503
- * @param int $comment_post_ID
1504
- * @return int
1505
- */
1506
- function dsq_pre_comment_on_post($comment_post_ID) {
1507
- if (dsq_can_replace()) {
1508
- wp_die( dsq_i('Sorry, the built-in commenting system is disabled because Disqus is active.') );
1509
- }
1510
- return $comment_post_ID;
1511
- }
1512
- add_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
1513
-
1514
- ?>
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Disqus Comment System
4
+ Plugin URI: https://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.86
8
+ Author URI: https://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', 'https://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.86');
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
+ 'dsq_external_js',
40
+ # SSO features
41
+ 'disqus_partner_key',
42
+ 'disqus_public_key',
43
+ 'disqus_secret_key',
44
+ 'disqus_sso_button',
45
+ # disables automatic sync via cron
46
+ 'disqus_manual_sync',
47
+ # disables server side rendering
48
+ 'disqus_disable_ssr',
49
+ # the last sync comment id (from get_forum_posts)
50
+ 'disqus_last_comment_id',
51
+ 'disqus_version',
52
+ );
53
+ }
54
+
55
+ /**
56
+ * @param string $file
57
+ * @return string
58
+ */
59
+ function dsq_plugin_basename($file) {
60
+ $file = dirname($file);
61
+
62
+ // From WP2.5 wp-includes/plugin.php:plugin_basename()
63
+ $file = str_replace('\\','/',$file); // sanitize for Win32 installs
64
+ $file = preg_replace('|/+|','/', $file); // remove any duplicate slash
65
+ $file = preg_replace('|^.*/' . PLUGINDIR . '/|','',$file); // get relative path from plugins dir
66
+
67
+ if ( strstr($file, '/') === false ) {
68
+ return $file;
69
+ }
70
+
71
+ $pieces = explode('/', $file);
72
+ return !empty($pieces[count($pieces)-1]) ? $pieces[count($pieces)-1] : $pieces[count($pieces)-2];
73
+ }
74
+
75
+ if ( !defined('PLUGINDIR') ) {
76
+ define('PLUGINDIR', 'wp-content/plugins'); // Relative to ABSPATH. For back compat.
77
+ }
78
+
79
+ $mt_disqus_version = '2.01';
80
+ /**
81
+ * Response from Disqus get_thread API call for comments template.
82
+ *
83
+ * @global string $dsq_response
84
+ * @since 1.0
85
+ */
86
+ $dsq_response = '';
87
+ /**
88
+ * Disqus API instance.
89
+ *
90
+ * @global string $dsq_api
91
+ * @since 1.0
92
+ */
93
+ $dsq_api = new DisqusWordPressAPI(get_option('disqus_forum_url'), get_option('disqus_api_key'));
94
+
95
+ /**
96
+ * Disqus currently unsupported dev toggle to output comments for this query.
97
+ *
98
+ * @global bool $DSQ_QUERY_COMMENTS
99
+ * @since ?
100
+ */
101
+ $DSQ_QUERY_COMMENTS = false;
102
+
103
+ /**
104
+ * Disqus array to store post_ids from WP_Query for comment JS output.
105
+ *
106
+ * @global array $DSQ_QUERY_POST_IDS
107
+ * @since 2.2
108
+ */
109
+ $DSQ_QUERY_POST_IDS = array();
110
+
111
+ /**
112
+ * Admin scripts
113
+ */
114
+
115
+ add_action('wp_dashboard_setup', 'dsq_wp_dashboard_setup');
116
+ add_action( 'admin_enqueue_scripts', 'load_admin_scripts' );
117
+
118
+ function load_admin_scripts($hook) {
119
+
120
+ // Only show the pointer when Disqus isn't already configured
121
+ if ( dsq_is_installed() === false ) {
122
+ add_action( 'admin_print_footer_scripts', 'load_pointer_script_style' );
123
+ }
124
+
125
+ // Only load these scripts on the Disqus admin page
126
+ if ( 'comments_page_disqus' != $hook ) {
127
+ return;
128
+ }
129
+
130
+ $admin_vars = array(
131
+ 'indexUrl' => admin_url('index.php'),
132
+ );
133
+
134
+ wp_register_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ) );
135
+ wp_localize_script( 'admin_script', 'adminVars', $admin_vars );
136
+ wp_enqueue_script( 'admin_script', plugins_url( '/media/js/admin.js', __FILE__ ), array( 'jQuery') );
137
+
138
+ wp_register_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__) );
139
+ wp_enqueue_script( 'upload_script', plugins_url( '/media/js/upload.js', __FILE__), array( 'jQuery') );
140
+ }
141
+
142
+ function dsq_wp_dashboard_setup() {
143
+ add_action('admin_enqueue_scripts', 'load_dashboard_scripts');
144
+ }
145
+
146
+ function load_dashboard_scripts() {
147
+ $stats = get_dash_comment_counts();
148
+ $dashboard_vars = array(
149
+ 'stats' => array(
150
+ 'totalComments' => number_format($stats->total_comments),
151
+ 'approved' => number_format($stats->approved),
152
+ 'moderated' => number_format($stats->moderated),
153
+ 'spam' => number_format($stats->spam),
154
+ ),
155
+ );
156
+
157
+ wp_register_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ) );
158
+ wp_localize_script( 'dashboard_script', 'dashboardVars', $dashboard_vars );
159
+ wp_enqueue_script( 'dashboard_script', plugins_url( '/media/js/dashboard.js', __FILE__ ), array( 'jQuery') );
160
+ }
161
+
162
+ /**
163
+ * Adds a simple WordPress pointer to Comments menu, to remind the user to configure the plugin
164
+ */
165
+ function load_pointer_script_style() {
166
+
167
+ // Assume pointer shouldn't be shown
168
+ $enqueue_pointer_script_style = false;
169
+
170
+ // Get array list of dismissed pointers for current user and convert it to array
171
+ $dismissed_pointers = explode( ',', get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
172
+
173
+ // Check if our pointer is not among dismissed ones
174
+ if( !in_array( 'disqus_settings_pointer', $dismissed_pointers ) ) {
175
+ $enqueue_pointer_script_style = true;
176
+
177
+ // Add footer scripts using callback function
178
+ $pointer_content = '<h3>'.dsq_i('Disqus needs to be configured').'</h3>';
179
+ $pointer_content .= '<p>'.dsq_i('Configure Disqus by clicking Comments to the left.').'</p>';
180
+
181
+ wp_register_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ) );
182
+ wp_localize_script( 'pointer_script', 'pointerContent', $pointer_content );
183
+ wp_enqueue_script( 'pointer_script', plugins_url( '/media/js/pointer.js', __FILE__ ), array( 'jQuery') );
184
+ }
185
+
186
+ // Enqueue pointer CSS and JS files, if needed
187
+ if( $enqueue_pointer_script_style ) {
188
+ wp_enqueue_style( 'wp-pointer' );
189
+ wp_enqueue_script( 'wp-pointer' );
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Helper functions.
195
+ */
196
+
197
+ /**
198
+ * Tests if site is running on Wordpress VIP
199
+ * @return bool
200
+ */
201
+ function is_wp_vip() {
202
+ return defined( 'WPCOM_IS_VIP_ENV' ) && WPCOM_IS_VIP_ENV;
203
+ }
204
+
205
+ /**
206
+ * Tests if required options are configured to display the Disqus embed.
207
+ * @return bool
208
+ */
209
+ function dsq_is_installed() {
210
+ $disqus_forum_url = get_option('disqus_forum_url');
211
+ $disqus_api_key = get_option('disqus_api_key');
212
+ if ( strlen( $disqus_forum_url ) > 0 && strlen( $disqus_api_key ) > 0 ) {
213
+ return true;
214
+ }
215
+ else {
216
+ return false;
217
+ }
218
+ }
219
+
220
+ /**
221
+ * @return bool
222
+ */
223
+ function dsq_can_replace() {
224
+ global $id, $post;
225
+
226
+ if (get_option('disqus_active') === '0'){ return false; }
227
+
228
+ $replace = get_option('disqus_replace');
229
+
230
+ if ( is_feed() ) { return false; }
231
+ if ( !isset($post) ) { return false; }
232
+ if ( 'draft' == $post->post_status ) { return false; }
233
+ if ( !get_option('disqus_forum_url') ) { return false; }
234
+ else if ( 'all' == $replace ) { return true; }
235
+
236
+ if ( !isset($post->comment_count) ) {
237
+ $num_comments = 0;
238
+ } else {
239
+ if ( 'empty' == $replace ) {
240
+ // Only get count of comments, not including pings.
241
+
242
+ // If there are comments, make sure there are comments (that are not track/pingbacks)
243
+ if ( $post->comment_count > 0 ) {
244
+ // Yuck, this causes a DB query for each post. This can be
245
+ // replaced with a lighter query, but this is still not optimal.
246
+ $comments = get_approved_comments($post->ID);
247
+ foreach ( $comments as $comment ) {
248
+ if ( $comment->comment_type != 'trackback' && $comment->comment_type != 'pingback' ) {
249
+ $num_comments++;
250
+ }
251
+ }
252
+ } else {
253
+ $num_comments = 0;
254
+ }
255
+ }
256
+ else {
257
+ $num_comments = $post->comment_count;
258
+ }
259
+ }
260
+
261
+ return ( ('empty' == $replace && 0 == $num_comments)
262
+ || ('closed' == $replace && 'closed' == $post->comment_status) );
263
+ }
264
+
265
+ function dsq_manage_dialog($message, $error = false) {
266
+ global $wp_version;
267
+
268
+ echo '<div '
269
+ . ( $error ? 'id="disqus_warning" ' : '')
270
+ . 'class="updated fade'
271
+ . ( (version_compare($wp_version, '2.5', '<') && $error) ? '-ff0000' : '' )
272
+ . '"><p><strong>'
273
+ . esc_attr($message)
274
+ . '</strong></p></div>';
275
+ }
276
+
277
+ function dsq_sync_comments($comments) {
278
+ if ( count($comments) < 1 ) {
279
+ return;
280
+ }
281
+
282
+ global $wpdb;
283
+
284
+ // user MUST be logged out during this process
285
+ wp_set_current_user(0);
286
+
287
+ // we need the thread_ids so we can map them to posts
288
+ $thread_map = array();
289
+ foreach ( $comments as $comment ) {
290
+ $thread_map[$comment->thread->id] = null;
291
+ }
292
+
293
+ $thread_ids = array_keys($thread_map);
294
+
295
+ $threads_query = implode(', ', array_fill(0, count($thread_ids), '%s'));
296
+
297
+ // add as many placeholders as needed
298
+ $sql = "
299
+ SELECT post_id, meta_value
300
+ FROM $wpdb->postmeta
301
+ WHERE meta_key = 'dsq_thread_id' AND meta_value IN (" . $threads_query . ")
302
+ ";
303
+
304
+ // Call $wpdb->prepare passing the values of the array as separate arguments
305
+ $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $thread_ids));
306
+
307
+ $results = $wpdb->get_results($query);
308
+
309
+ foreach ( $results as $result ) {
310
+ $thread_map[$result->meta_value] = $result->post_id;
311
+ }
312
+ unset($result);
313
+
314
+ foreach ( $comments as $comment ) {
315
+ $ts = strtotime($comment->created_at);
316
+ if (!$thread_map[$comment->thread->id] && !empty($comment->thread->identifier)) {
317
+ // legacy threads dont already have their meta stored
318
+ foreach ( $comment->thread->identifier as $identifier ) {
319
+ // we know identifier starts with post_ID
320
+ if ($post_ID = (int)substr($identifier, 0, strpos($identifier, ' '))) {
321
+ $thread_map[$comment->thread->id] = $post_ID;
322
+ $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $comment->thread->id, 'post' );
323
+ update_post_meta($post_ID, 'dsq_thread_id', $cleaned_thread_id);
324
+ if (DISQUS_DEBUG) {
325
+ echo "updated post {$post_ID}: dsq_thread_id set to {$comment->thread->id}\n";
326
+ }
327
+ }
328
+ }
329
+ unset($identifier);
330
+ }
331
+ if (!$thread_map[$comment->thread->id]) {
332
+ // shouldn't ever happen, but we can't be certain
333
+ if (DISQUS_DEBUG) {
334
+ if (!empty($comment->thread->identifier)) {
335
+ $idents = implode(', ', $comment->thread->identifier);
336
+ echo "skipped {$comment->id}: missing thread for identifiers ({$idents})\n";
337
+ } else {
338
+ echo "skipped {$comment->id}: missing thread (no identifier)\n";
339
+ }
340
+ }
341
+ continue;
342
+ }
343
+ $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));
344
+ if (count($results)) {
345
+ // already exists
346
+ if (DISQUS_DEBUG) {
347
+ echo "skipped {$comment->id}: comment already exists\n";
348
+ }
349
+ if (count($results) > 1) {
350
+ // clean up duplicates -- fixes an issue where a race condition allowed comments to be synced multiple times
351
+ $results = array_slice($results, 1);
352
+ foreach ($results as $result) {
353
+ $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id = %s LIMIT 1", $result);
354
+ }
355
+ }
356
+ continue;
357
+ }
358
+
359
+ $commentdata = false;
360
+
361
+ // first lets check by the id we have stored
362
+ if ($comment->meta) {
363
+ $meta = explode(';', $comment->meta);
364
+ foreach ($meta as $value) {
365
+ $value = explode('=', $value);
366
+ $meta[$value[0]] = $value[1];
367
+ }
368
+ unset($value);
369
+ if ($meta['wp_id']) {
370
+ $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);
371
+ }
372
+ }
373
+
374
+ // skip comments that were imported but are missing meta information
375
+ if (!$commentdata && $comment->imported) {
376
+ if (DISQUS_DEBUG) {
377
+ echo "skipped {$comment->id}: comment not found and marked as imported\n";
378
+ }
379
+ continue;
380
+ }
381
+
382
+ // and follow up using legacy Disqus agent
383
+ if (!$commentdata) {
384
+ $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);
385
+ }
386
+ if (!$commentdata) {
387
+ // Comment doesnt exist yet, lets insert it
388
+ if ($comment->status == 'approved') {
389
+ $approved = 1;
390
+ } elseif ($comment->status == 'spam') {
391
+ $approved = 'spam';
392
+ } else {
393
+ $approved = 0;
394
+ }
395
+ $commentdata = array(
396
+ 'comment_post_ID' => $thread_map[$comment->thread->id],
397
+ 'comment_date' => date('Y-m-d\TH:i:s', strtotime($comment->created_at) + (get_option('gmt_offset') * 3600)),
398
+ 'comment_date_gmt' => $comment->created_at,
399
+ 'comment_content' => apply_filters('pre_comment_content', $comment->message),
400
+ 'comment_approved' => $approved,
401
+ 'comment_agent' => 'Disqus/1.1('.DISQUS_VERSION.'):'.intval($comment->id),
402
+ 'comment_type' => '',
403
+ );
404
+ if ($comment->is_anonymous) {
405
+ $commentdata['comment_author'] = $comment->anonymous_author->name;
406
+ $commentdata['comment_author_email'] = $comment->anonymous_author->email;
407
+ $commentdata['comment_author_url'] = $comment->anonymous_author->url;
408
+ $commentdata['comment_author_IP'] = $comment->ip_address;
409
+ } else {
410
+ if (!empty($comment->author->display_name)) {
411
+ $commentdata['comment_author'] = $comment->author->display_name;
412
+ } else {
413
+ $commentdata['comment_author'] = $comment->author->username;
414
+ }
415
+ $commentdata['comment_author_email'] = $comment->author->email;
416
+ $commentdata['comment_author_url'] = $comment->author->url;
417
+ $commentdata['comment_author_IP'] = $comment->ip_address;
418
+ }
419
+ $commentdata = wp_filter_comment($commentdata);
420
+ if ($comment->parent_post) {
421
+ $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));
422
+ if ($parent_id) {
423
+ $commentdata['comment_parent'] = $parent_id;
424
+ }
425
+ }
426
+
427
+ // due to a race condition we need to test again for coment existance
428
+ 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))) {
429
+ // already exists
430
+ if (DISQUS_DEBUG) {
431
+ echo "skipped {$comment->id}: comment already exists (second check)\n";
432
+ }
433
+ continue;
434
+ }
435
+
436
+ $commentdata['comment_ID'] = wp_insert_comment($commentdata);
437
+ if (DISQUS_DEBUG) {
438
+ echo "inserted {$comment->id}: id is {$commentdata[comment_ID]}\n";
439
+ }
440
+ }
441
+ if ((isset($commentdata['comment_parent']) && !$commentdata['comment_parent']) && $comment->parent_post) {
442
+ $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));
443
+ if ($parent_id) {
444
+ $wpdb->query($wpdb->prepare( "UPDATE $wpdb->comments SET comment_parent = %s WHERE comment_id = %s", $parent_id, $commentdata['comment_ID']));
445
+ if (DISQUS_DEBUG) {
446
+ echo "updated {$comment->id}: comment_parent changed to {$parent_id}\n";
447
+ }
448
+
449
+ }
450
+ }
451
+ $comment_id = $commentdata['comment_ID'];
452
+ update_comment_meta($comment_id, 'dsq_parent_post_id', $comment->parent_post);
453
+ update_comment_meta($comment_id, 'dsq_post_id', $comment->id);
454
+ }
455
+ unset($comment);
456
+
457
+ if( isset($_POST['dsq_api_key']) && $_POST['dsq_api_key'] == get_option('disqus_api_key') ) {
458
+ if( isset($_GET['dsq_sync_action']) && isset($_GET['dsq_sync_comment_id']) ) {
459
+ $comment_parts = explode('=', $_GET['dsq_sync_comment_id']);
460
+
461
+ if (!($comment_id = intval($comment_parts[1])) > 0) {
462
+ return;
463
+ }
464
+
465
+ if( 'wp_id' != $comment_parts[0] ) {
466
+ $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));
467
+ }
468
+
469
+ switch( $_GET['dsq_sync_action'] ) {
470
+ case 'mark_spam':
471
+ wp_set_comment_status($comment_id, 'spam');
472
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'spam') -->";
473
+ break;
474
+ case 'mark_approved':
475
+ wp_set_comment_status($comment_id, 'approve');
476
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'approve') -->";
477
+ break;
478
+ case 'mark_killed':
479
+ wp_set_comment_status($comment_id, 'hold');
480
+ echo "<!-- dsq_sync: wp_set_comment_status($comment_id, 'hold') -->";
481
+ break;
482
+ }
483
+ }
484
+ }
485
+ }
486
+
487
+ function dsq_request_handler() {
488
+ global $dsq_response;
489
+ global $dsq_api;
490
+ global $post;
491
+ global $wpdb;
492
+
493
+ if (!empty($_GET['cf_action'])) {
494
+ switch ($_GET['cf_action']) {
495
+ case 'sync_comments':
496
+ if( !( $post_id = $_GET['post_id'] ) ) {
497
+ header("HTTP/1.0 400 Bad Request");
498
+ die();
499
+ }
500
+ // schedule the event for 5 minutes from now in case they
501
+ // happen to make a quick post
502
+ dsq_add_pending_post_id($post_id);
503
+
504
+ if (DISQUS_DEBUG) {
505
+ $response = dsq_sync_forum();
506
+ if (!$response) {
507
+ die('// error: '.$dsq_api->get_last_error());
508
+ } else {
509
+ list($last_comment_id, $comments) = $response;
510
+ die('// synced '.$comments.' comments');
511
+ }
512
+ } else {
513
+ $ts = time() + 300;
514
+ $next_scheduled = wp_next_scheduled('dsq_sync_forum');
515
+ if($next_scheduled) {
516
+ // error_log("Not scheduling dsq_sync_forum because it's already scheduled for " . $next_scheduled);
517
+ } else {
518
+ // error_log("Scheduling for $ts because dsq_sync_forum is not currently scheduled.");
519
+ wp_schedule_single_event($ts, 'dsq_sync_forum');
520
+ }
521
+ die('// sync scheduled');
522
+ }
523
+ break;
524
+ case 'export_comments':
525
+ if (current_user_can('manage_options') && DISQUS_CAN_EXPORT) {
526
+ $msg = '';
527
+ $result = '';
528
+ $response = null;
529
+
530
+ $timestamp = intval($_GET['timestamp']);
531
+ $post_id = intval($_GET['post_id']);
532
+ if ( isset($_GET['_dsqexport_wpnonce']) === false ) {
533
+ $msg = dsq_i('Unable to export comments. Make sure you are accessing this page from the Wordpress dashboard.');
534
+ $result = 'fail';
535
+ }
536
+ else {
537
+
538
+ // Check nonce
539
+ check_admin_referer('dsq-wpnonce_export', '_dsqexport_wpnonce');
540
+
541
+ global $wpdb, $dsq_api;
542
+ $post = $wpdb->get_results($wpdb->prepare("
543
+ SELECT *
544
+ FROM $wpdb->posts
545
+ WHERE post_type != 'revision'
546
+ AND post_status = 'publish'
547
+ AND comment_count > 0
548
+ AND ID > %d
549
+ ORDER BY ID ASC
550
+ LIMIT 1
551
+ ", $post_id));
552
+ $post = $post[0];
553
+ $post_id = $post->ID;
554
+ $max_post_id = $wpdb->get_var("
555
+ SELECT MAX(Id)
556
+ FROM $wpdb->posts
557
+ WHERE post_type != 'revision'
558
+ AND post_status = 'publish'
559
+ AND comment_count > 0
560
+ ");
561
+ $eof = (int)($post_id == $max_post_id);
562
+ if ($eof) {
563
+ $status = 'complete';
564
+ $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
565
+ $msg .= '<br/><a href="'.DISQUS_IMPORTER_URL.'" target="_blank">';
566
+ $msg .= dsq_i('See the status of your import at Disqus') . '</a>';
567
+ }
568
+ else {
569
+ $status = 'partial';
570
+ $msg = dsq_i('Processed comments on post') . ' #'. $post_id . '&hellip;';
571
+ }
572
+ $result = 'fail';
573
+ if ($post) {
574
+ require_once(dirname(__FILE__) . '/export.php');
575
+ $wxr = dsq_export_wp($post);
576
+ $response = $dsq_api->import_wordpress_comments($wxr, $timestamp, $eof);
577
+ if (!($response['group_id'] > 0)) {
578
+ $result = 'fail';
579
+ $msg = '<p class="status dsq-export-fail">';
580
+ $msg .= dsq_i('Sorry, something unexpected happened with the export. Please try again.');
581
+ $msg .= '</p><p>';
582
+ $msg .= dsq_i('If your API key has changed, you may need to reinstall Disqus (deactivate the plugin and then reactivate it).');
583
+ $msg .= dsq_i('If you are still having issues, refer to the %s WordPress help page',
584
+ '<a href="https://help.disqus.com/customer/portal/articles/472005" onclick="window.open(this.href); return false">');
585
+ $msg .= '</a></p>';
586
+ $response = $dsq_api->get_last_error();
587
+ }
588
+ else {
589
+ if ($eof) {
590
+ $msg = dsq_i('Your comments have been sent to Disqus and queued for import!');
591
+ $msg .= '<br/><a href="' . $response['link'] . '" target="_blank">';
592
+ $msg .= dsq_i('See the status of your import at Disqus');
593
+ $msg .= '</a>';
594
+ }
595
+ $result = 'success';
596
+ }
597
+ }
598
+ }
599
+
600
+ // send AJAX response
601
+ $response = compact('result', 'timestamp', 'status', 'post_id', 'msg', 'eof', 'response');
602
+ header('Content-type: text/javascript');
603
+ echo cf_json_encode($response);
604
+ die();
605
+ }
606
+ break;
607
+ case 'import_comments':
608
+ if (current_user_can('manage_options')) {
609
+ $msg = '';
610
+ $result = '';
611
+ $response = null;
612
+
613
+ if ( isset($_GET['_dsqimport_wpnonce']) === false ) {
614
+ $msg = dsq_i('Unable to import comments. Make sure you are accessing this page from the Wordpress dashboard.');
615
+ $result = 'fail';
616
+ }
617
+ else
618
+ {
619
+ // Check nonce
620
+ check_admin_referer('dsq-wpnonce_import', '_dsqimport_wpnonce');
621
+
622
+ if (!isset($_GET['last_comment_id'])) $last_comment_id = false;
623
+ else $last_comment_id = $_GET['last_comment_id'];
624
+
625
+ if ($_GET['wipe'] == '1') {
626
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."commentmeta` WHERE meta_key IN ('dsq_post_id', 'dsq_parent_post_id')");
627
+ $wpdb->query("DELETE FROM `".$wpdb->prefix."comments` WHERE comment_agent LIKE 'Disqus/%%'");
628
+ }
629
+
630
+ ob_start();
631
+ $response = dsq_sync_forum($last_comment_id, true);
632
+ $debug = ob_get_clean();
633
+ if (!$response) {
634
+ $status = 'error';
635
+ $result = 'fail';
636
+ $error = $dsq_api->get_last_error();
637
+ $msg = '<p class="status dsq-export-fail">'.dsq_i('There was an error downloading your comments from Disqus.').'<br/>'.esc_attr($error).'</p>';
638
+ } else {
639
+ list($comments, $last_comment_id) = $response;
640
+ if (!$comments) {
641
+ $status = 'complete';
642
+ $msg = dsq_i('Your comments have been downloaded from Disqus and saved in your local database.');
643
+ } else {
644
+ $status = 'partial';
645
+ $msg = dsq_i('Import in progress (last post id: %s)', $last_comment_id) . ' &hellip;';
646
+ }
647
+ $result = 'success';
648
+ }
649
+ $debug = explode("\n", $debug);
650
+ $response = compact('result', 'status', 'comments', 'msg', 'last_comment_id', 'debug');
651
+ header('Content-type: text/javascript');
652
+ echo cf_json_encode($response);
653
+ die();
654
+ }
655
+ }
656
+ break;
657
+ }
658
+ }
659
+ }
660
+
661
+ add_action('init', 'dsq_request_handler');
662
+
663
+ /**
664
+ * @param string $option_name
665
+ */
666
+ function dsq_image_upload_handler($option_name) {
667
+ // If the upload field has a file in it
668
+ if(isset($_FILES[$option_name]) && ($_FILES[$option_name]['size'] > 0)) {
669
+ // Get the type of the uploaded file. This is returned as "type/extension"
670
+ $arr_file_type = wp_check_filetype(basename($_FILES[$option_name]['name']));
671
+ $uploaded_file_type = $arr_file_type['type'];
672
+ // Set an array containing a list of acceptable formats
673
+ $allowed_file_types = array('image/jpg','image/jpeg','image/gif','image/png','image/x-icon');
674
+ // If the uploaded file is the right format
675
+ if(in_array($uploaded_file_type, $allowed_file_types)) {
676
+ // Options array for the wp_handle_upload function. 'test_upload' => false
677
+ $upload_overrides = array( 'test_form' => false );
678
+ // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array
679
+ $uploaded_file = wp_handle_upload($_FILES[$option_name], $upload_overrides);
680
+ // If the wp_handle_upload call returned a local path for the image
681
+ if(isset($uploaded_file['url'])) {
682
+ update_option($option_name, $uploaded_file['url']);
683
+ }
684
+ }
685
+ }
686
+ }
687
+
688
+ function dsq_add_pending_post_id($post_id) {
689
+ update_post_meta($post_id, 'dsq_needs_sync', '1', $unique=true);
690
+ }
691
+
692
+ function dsq_get_pending_post_ids() {
693
+ global $wpdb;
694
+
695
+ $results = $wpdb->get_results( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = 'dsq_needs_sync'");
696
+ $post_ids = array();
697
+ foreach ($results as $result) {
698
+ $post_ids[] = $result->post_id;
699
+ }
700
+ return $post_ids;
701
+ }
702
+
703
+ function dsq_clear_pending_post_ids($post_ids) {
704
+ if ( count($post_ids) < 1 ) {
705
+ return;
706
+ }
707
+
708
+ global $wpdb;
709
+
710
+ $posts_query = implode(', ', array_fill(0, count($post_ids), '%s'));
711
+
712
+ // add as many placeholders as needed
713
+ $sql = "
714
+ DELETE FROM {$wpdb->postmeta}
715
+ WHERE meta_key = 'dsq_needs_sync' AND post_id IN (" . $posts_query . ")
716
+ ";
717
+
718
+ // Call $wpdb->prepare passing the values of the array as separate arguments
719
+ $query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $post_ids));
720
+
721
+ $wpdb->query($query);
722
+
723
+ update_meta_cache('dsq_needs_sync', $post_ids);
724
+ }
725
+
726
+
727
+ function dsq_sync_post($post_id) {
728
+ global $dsq_api, $wpdb;
729
+
730
+ $post = get_post($post_id);
731
+
732
+ // Call update_thread to ensure our permalink is up to date
733
+ dsq_update_permalink($post);
734
+ }
735
+
736
+ function dsq_sync_forum($last_comment_id=false, $force=false) {
737
+ global $dsq_api, $wpdb;
738
+
739
+ set_time_limit(DISQUS_SYNC_TIMEOUT);
740
+
741
+ if ($force) {
742
+ $sync_time = null;
743
+ } else {
744
+ $sync_time = (int)get_option('_disqus_sync_lock');
745
+ }
746
+
747
+ // lock expires after 1 hour
748
+ if ($sync_time && $sync_time > time() - 60*60) {
749
+ $dsq_api->api->last_error = 'Sync already in progress (lock found)';
750
+ return false;
751
+ } else {
752
+ update_option('_disqus_sync_lock', time());
753
+ }
754
+
755
+ // sync all pending posts
756
+ $post_ids = dsq_get_pending_post_ids();
757
+ dsq_clear_pending_post_ids($post_ids);
758
+
759
+ foreach ($post_ids as $post_id) {
760
+ dsq_sync_post($post_id);
761
+ }
762
+
763
+ if ($last_comment_id === false) {
764
+ $last_comment_id = get_option('disqus_last_comment_id');
765
+ if (!$last_comment_id) {
766
+ $last_comment_id = 0;
767
+ }
768
+ }
769
+ if ($last_comment_id) {
770
+ $last_comment_id++;
771
+ }
772
+
773
+ //$last_comment_id = 0;
774
+
775
+ // Pull comments from API
776
+ $dsq_response = $dsq_api->get_forum_posts($last_comment_id);
777
+ if( $dsq_response < 0 || $dsq_response === false ) {
778
+ return false;
779
+ }
780
+
781
+ // Sync comments with database.
782
+ dsq_sync_comments($dsq_response);
783
+ $total = 0;
784
+ if ($dsq_response) {
785
+ foreach ($dsq_response as $comment) {
786
+ $total += 1;
787
+ if ($comment->id > $last_comment_id) $last_comment_id = $comment->id;
788
+ }
789
+ if ($last_comment_id > get_option('disqus_last_comment_id')) {
790
+ update_option('disqus_last_comment_id', $last_comment_id);
791
+ }
792
+ }
793
+ unset($comment);
794
+ delete_option('_disqus_sync_lock');
795
+ return array($total, $last_comment_id);
796
+ }
797
+
798
+ add_action('dsq_sync_forum', 'dsq_sync_forum');
799
+
800
+ function dsq_update_permalink($post) {
801
+ global $dsq_api;
802
+
803
+ if (DISQUS_DEBUG) {
804
+ echo "updating post on disqus: {$post->ID}\n";
805
+ }
806
+
807
+ $response = $dsq_api->api->update_thread(null, array(
808
+ 'thread_identifier' => dsq_identifier_for_post($post),
809
+ 'title' => dsq_title_for_post($post),
810
+ 'url' => dsq_link_for_post($post)
811
+ ));
812
+
813
+ //Make sure that response exists so that warnings are not thrown
814
+ if (! empty($response)) {
815
+ $cleaned_thread_id = sanitize_meta( 'dsq_thread_id', $response->id, 'post' );
816
+ update_post_meta($post->ID, 'dsq_thread_id', $cleaned_thread_id);
817
+ }
818
+
819
+ return $response;
820
+ }
821
+
822
+ /**
823
+ * Compatibility
824
+ */
825
+
826
+ if (!function_exists ( '_wp_specialchars' ) ) {
827
+ function _wp_specialchars( $string, $quote_style = ENT_NOQUOTES, $charset = false, $double_encode = false ) {
828
+ $string = (string) $string;
829
+
830
+ if ( 0 === strlen( $string ) ) {
831
+ return '';
832
+ }
833
+
834
+ // Don't bother if there are no specialchars - saves some processing
835
+ if ( !preg_match( '/[&<>"\']/', $string ) ) {
836
+ return $string;
837
+ }
838
+
839
+ // Account for the previous behaviour of the function when the $quote_style is not an accepted value
840
+ if ( empty( $quote_style ) ) {
841
+ $quote_style = ENT_NOQUOTES;
842
+ } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) {
843
+ $quote_style = ENT_QUOTES;
844
+ }
845
+
846
+ // Store the site charset as a static to avoid multiple calls to wp_load_alloptions()
847
+ if ( !$charset ) {
848
+ static $_charset;
849
+ if ( !isset( $_charset ) ) {
850
+ $alloptions = wp_load_alloptions();
851
+ $_charset = isset( $alloptions['blog_charset'] ) ? $alloptions['blog_charset'] : '';
852
+ }
853
+ $charset = $_charset;
854
+ }
855
+ if ( in_array( $charset, array( 'utf8', 'utf-8', 'UTF8' ) ) ) {
856
+ $charset = 'UTF-8';
857
+ }
858
+
859
+ $_quote_style = $quote_style;
860
+
861
+ if ( $quote_style === 'double' ) {
862
+ $quote_style = ENT_COMPAT;
863
+ $_quote_style = ENT_COMPAT;
864
+ } elseif ( $quote_style === 'single' ) {
865
+ $quote_style = ENT_NOQUOTES;
866
+ }
867
+
868
+ // Handle double encoding ourselves
869
+ if ( !$double_encode ) {
870
+ $string = wp_specialchars_decode( $string, $_quote_style );
871
+ $string = preg_replace( '/&(#?x?[0-9a-z]+);/i', '|wp_entity|$1|/wp_entity|', $string );
872
+ }
873
+
874
+ $string = @esc_attr( $string, $quote_style, $charset );
875
+
876
+ // Handle double encoding ourselves
877
+ if ( !$double_encode ) {
878
+ $string = str_replace( array( '|wp_entity|', '|/wp_entity|' ), array( '&', ';' ), $string );
879
+ }
880
+
881
+ // Backwards compatibility
882
+ if ( 'single' === $_quote_style ) {
883
+ $string = str_replace( "'", '&#039;', $string );
884
+ }
885
+
886
+ return $string;
887
+ }
888
+ }
889
+
890
+ if (!function_exists ( 'wp_check_invalid_utf8' ) ) {
891
+ function wp_check_invalid_utf8( $string, $strip = false ) {
892
+ $string = (string) $string;
893
+
894
+ if ( 0 === strlen( $string ) ) {
895
+ return '';
896
+ }
897
+
898
+ // Store the site charset as a static to avoid multiple calls to get_option()
899
+ static $is_utf8;
900
+ if ( !isset( $is_utf8 ) ) {
901
+ $is_utf8 = in_array( get_option( 'blog_charset' ), array( 'utf8', 'utf-8', 'UTF8', 'UTF-8' ) );
902
+ }
903
+ if ( !$is_utf8 ) {
904
+ return $string;
905
+ }
906
+
907
+ // Check for support for utf8 in the installed PCRE library once and store the result in a static
908
+ static $utf8_pcre;
909
+ if ( !isset( $utf8_pcre ) ) {
910
+ $utf8_pcre = @preg_match( '/^./u', 'a' );
911
+ }
912
+ // We can't demand utf8 in the PCRE installation, so just return the string in those cases
913
+ if ( !$utf8_pcre ) {
914
+ return $string;
915
+ }
916
+
917
+ // preg_match fails when it encounters invalid UTF8 in $string
918
+ if ( 1 === @preg_match( '/^./us', $string ) ) {
919
+ return $string;
920
+ }
921
+
922
+ // Attempt to strip the bad chars if requested (not recommended)
923
+ if ( $strip && function_exists( 'iconv' ) ) {
924
+ return iconv( 'utf-8', 'utf-8', $string );
925
+ }
926
+
927
+ return '';
928
+ }
929
+ }
930
+
931
+ if (!function_exists ( 'esc_html' ) ) {
932
+ function esc_html( $text ) {
933
+ $safe_text = wp_check_invalid_utf8( $text );
934
+ $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
935
+ return apply_filters( 'esc_html', $safe_text, $text );
936
+ }
937
+ }
938
+
939
+ if (!function_exists ( 'esc_attr' ) ) {
940
+ function esc_attr( $text ) {
941
+ $safe_text = wp_check_invalid_utf8( $text );
942
+ $safe_text = _wp_specialchars( $safe_text, ENT_QUOTES );
943
+ return apply_filters( 'attribute_escape', $safe_text, $text );
944
+ }
945
+ }
946
+
947
+ /**
948
+ * Filters/Actions
949
+ */
950
+
951
+ // ugly global hack for comments closing
952
+ $EMBED = false;
953
+ function dsq_comments_template($value) {
954
+ global $EMBED;
955
+ global $post;
956
+ global $comments;
957
+
958
+ if ( !( is_singular() && ( have_comments() || 'open' == $post->comment_status ) ) ) {
959
+ return;
960
+ }
961
+
962
+ if ( !dsq_is_installed() || !dsq_can_replace() ) {
963
+ return $value;
964
+ }
965
+
966
+ // TODO: If a disqus-comments.php is found in the current template's
967
+ // path, use that instead of the default bundled comments.php
968
+ //return TEMPLATEPATH . '/disqus-comments.php';
969
+ $EMBED = true;
970
+ return dirname(__FILE__) . '/comments.php';
971
+ }
972
+
973
+ function dsq_comment( $comment, $args, $depth ) {
974
+ $GLOBALS['comment'] = $comment;
975
+ switch ($comment->comment_type):
976
+ case '' :
977
+ ?>
978
+ <li <?php comment_class(); ?> id="dsq-comment-<?php echo comment_ID(); ?>">
979
+ <div id="dsq-comment-header-<?php echo comment_ID(); ?>" class="dsq-comment-header">
980
+ <cite id="dsq-cite-<?php echo comment_ID(); ?>">
981
+ <?php if(get_comment_author_url()) : ?>
982
+ <a id="dsq-author-user-<?php echo comment_ID(); ?>" href="<?php echo comment_author_url(); ?>" target="_blank" rel="nofollow"><?php echo comment_author(); ?></a>
983
+ <?php else : ?>
984
+ <span id="dsq-author-user-<?php echo comment_ID(); ?>"><?php echo comment_author(); ?></span>
985
+ <?php endif; ?>
986
+ </cite>
987
+ </div>
988
+ <div id="dsq-comment-body-<?php echo comment_ID(); ?>" class="dsq-comment-body">
989
+ <div id="dsq-comment-message-<?php echo comment_ID(); ?>" class="dsq-comment-message"><?php echo wp_filter_kses(comment_text()); ?></div>
990
+ </div>
991
+
992
+ <?php
993
+ break;
994
+ case 'pingback' :
995
+ case 'trackback' :
996
+ ?>
997
+ <li class="post pingback">
998
+ <p><?php echo dsq_i('Pingback:'); ?> <?php comment_author_link(); ?>(<?php edit_comment_link(dsq_i('Edit'), ' '); ?>)</p>
999
+ </li>
1000
+ <?php
1001
+ break;
1002
+ endswitch;
1003
+ }
1004
+
1005
+ // Mark entries in index to replace comments link.
1006
+ // As of WordPress 3.1 this is required to return a numerical value
1007
+ function dsq_comments_number($count) {
1008
+ global $post;
1009
+
1010
+ return $count;
1011
+ }
1012
+
1013
+ function dsq_comments_text($comment_text) {
1014
+ global $post;
1015
+
1016
+ if ( dsq_can_replace() ) {
1017
+ return '<span class="dsq-postid" data-dsqidentifier="'.esc_attr(dsq_identifier_for_post($post)).'">'.$comment_text.'</span>';
1018
+ } else {
1019
+ return $comment_text;
1020
+ }
1021
+ }
1022
+
1023
+ function dsq_bloginfo_url($url) {
1024
+ if ( get_feed_link('comments_rss2') == $url && dsq_can_replace() ) {
1025
+ return 'https://' . strtolower(get_option('disqus_forum_url')) . '.disqus.com' . DISQUS_RSS_PATH;
1026
+ } else {
1027
+ return $url;
1028
+ }
1029
+ }
1030
+
1031
+ function dsq_plugin_action_links($links, $file) {
1032
+ $plugin_file = basename(__FILE__);
1033
+ if (basename($file) == $plugin_file) {
1034
+ if (!dsq_is_installed()) {
1035
+ $settings_link = '<a href="edit-comments.php?page=disqus">'.dsq_i('Configure').'</a>';
1036
+ } else {
1037
+ $settings_link = '<a href="edit-comments.php?page=disqus#adv">'.dsq_i('Settings').'</a>';
1038
+ }
1039
+ array_unshift($links, $settings_link);
1040
+ }
1041
+ return $links;
1042
+ }
1043
+ add_filter('plugin_action_links', 'dsq_plugin_action_links', 10, 2);
1044
+
1045
+ /**
1046
+ * Hide the default comment form to stop spammers by marking all comments
1047
+ * as closed.
1048
+ */
1049
+ function dsq_comments_open($open, $post_id=null) {
1050
+ global $EMBED;
1051
+ if ($EMBED) return false;
1052
+ return $open;
1053
+ }
1054
+ add_filter('comments_open', 'dsq_comments_open');
1055
+
1056
+ // Always add Disqus management page to the admin menu
1057
+ function dsq_add_pages() {
1058
+ add_submenu_page(
1059
+ 'edit-comments.php',
1060
+ 'Disqus',
1061
+ 'Disqus',
1062
+ 'moderate_comments',
1063
+ 'disqus',
1064
+ 'dsq_manage'
1065
+ );
1066
+ }
1067
+ add_action('admin_menu', 'dsq_add_pages', 10);
1068
+
1069
+ // only active on dashboard
1070
+ function get_dash_comment_counts() {
1071
+ global $wpdb;
1072
+ // taken from wp-includes/comment.php - WP 2.8.5
1073
+ $count = $wpdb->get_results("
1074
+ SELECT comment_approved, COUNT( * ) AS num_comments
1075
+ FROM {$wpdb->comments}
1076
+ WHERE comment_type != 'trackback'
1077
+ AND comment_type != 'pingback'
1078
+ GROUP BY comment_approved
1079
+ ", ARRAY_A );
1080
+ $total = 0;
1081
+ $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam');
1082
+ $known_types = array_keys( $approved );
1083
+ foreach( (array) $count as $row_num => $row ) {
1084
+ $total += $row['num_comments'];
1085
+ if ( in_array( $row['comment_approved'], $known_types ) && array_key_exists($row['comment_approved'], $approved) )
1086
+ $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
1087
+ }
1088
+
1089
+ $stats['total_comments'] = $total;
1090
+ foreach ( $approved as $key ) {
1091
+ if ( empty($stats[$key]) )
1092
+ $stats[$key] = 0;
1093
+ }
1094
+ return (object) $stats;
1095
+ }
1096
+
1097
+ function dsq_manage() {
1098
+ if (dsq_does_need_update() && isset($_POST['upgrade'])) {
1099
+ dsq_install();
1100
+ }
1101
+
1102
+ if (dsq_does_need_update() && !isset($_POST['reset'])) {
1103
+ include_once(dirname(__FILE__) . '/upgrade.php');
1104
+ } else {
1105
+ include_once(dirname(__FILE__) . '/manage.php');
1106
+ }
1107
+ }
1108
+
1109
+ function dsq_admin_head() {
1110
+ if (isset($_GET['page']) && $_GET['page'] == 'disqus') {
1111
+ ?>
1112
+ <link rel='stylesheet' href='<?php echo esc_url( plugins_url( 'media/styles/manage.css', __FILE__ ) ); ?>' type='text/css' />
1113
+ <style type="text/css">
1114
+ .dsq-importing, .dsq-imported, .dsq-import-fail, .dsq-exporting, .dsq-exported, .dsq-export-fail {
1115
+ background: url(<?php echo esc_url( admin_url('images/loading.gif') ); ?>) left center no-repeat;
1116
+ line-height: 16px;
1117
+ padding-left: 20px;
1118
+ }
1119
+ p.status {
1120
+ padding-top: 0;
1121
+ padding-bottom: 0;
1122
+ margin: 0;
1123
+ }
1124
+ .dsq-imported, .dsq-exported {
1125
+ background: url(<?php echo esc_url( admin_url('images/yes.png') ); ?>) left center no-repeat;
1126
+ }
1127
+ .dsq-import-fail, .dsq-export-fail {
1128
+ background: url(<?php echo esc_url( admin_url('images/no.png') ); ?>) left center no-repeat;
1129
+ }
1130
+ </style>
1131
+ <?php
1132
+ // HACK: Our own styles for older versions of WordPress.
1133
+ global $wp_version;
1134
+ if ( version_compare($wp_version, '2.5', '<') ) {
1135
+ echo "<link rel='stylesheet' href='" . esc_url( plugins_url( 'media/styles/manage-pre25.css', __FILE__ ) ) . "' type='text/css' />";
1136
+ }
1137
+ }
1138
+ }
1139
+ add_action('admin_head', 'dsq_admin_head');
1140
+
1141
+ /**
1142
+ * Wrapper for built-in __() which pulls all text from
1143
+ * the disqus domain and supports variable interpolation.
1144
+ */
1145
+ function dsq_i($text, $params=null) {
1146
+ if (!is_array($params))
1147
+ {
1148
+ $params = func_get_args();
1149
+ $params = array_slice($params, 1);
1150
+ }
1151
+ return vsprintf(__($text, 'disqus'), $params);
1152
+ }
1153
+
1154
+ // catch original query
1155
+ function dsq_parse_query($query) {
1156
+ add_action('the_posts', 'dsq_add_request_post_ids', 999);
1157
+ }
1158
+ add_action('parse_request', 'dsq_parse_query');
1159
+
1160
+ // track the original request post_ids, only run once
1161
+ function dsq_add_request_post_ids($posts) {
1162
+ dsq_add_query_posts($posts);
1163
+ remove_action('the_posts', 'dsq_log_request_post_ids', 999);
1164
+ return $posts;
1165
+ }
1166
+
1167
+ function dsq_maybe_add_post_ids($posts) {
1168
+ global $DSQ_QUERY_COMMENTS;
1169
+ if ($DSQ_QUERY_COMMENTS) {
1170
+ dsq_add_query_posts($posts);
1171
+ }
1172
+ return $posts;
1173
+ }
1174
+ add_action('the_posts', 'dsq_maybe_add_post_ids');
1175
+
1176
+ function dsq_add_query_posts($posts) {
1177
+ global $DSQ_QUERY_POST_IDS;
1178
+ if (count($posts)) {
1179
+ foreach ($posts as $post) {
1180
+ $post_ids[] = intval($post->ID);
1181
+ }
1182
+ $DSQ_QUERY_POST_IDS[md5(serialize($post_ids))] = $post_ids;
1183
+ }
1184
+ }
1185
+
1186
+ function dsq_output_count_js() {
1187
+ if ( get_option('dsq_external_js') == '1' ) {
1188
+ $count_vars = array(
1189
+ 'disqusShortname' => strtolower( get_option( 'disqus_forum_url' ) ),
1190
+ );
1191
+
1192
+ wp_register_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1193
+ wp_localize_script( 'dsq_count_script', 'countVars', $count_vars );
1194
+ wp_enqueue_script( 'dsq_count_script', plugins_url( '/media/js/count.js', __FILE__ ) );
1195
+ }
1196
+ else {
1197
+ ?>
1198
+ <script type="text/javascript">
1199
+ // <![CDATA[
1200
+ var disqus_shortname = '<?php echo strtolower( get_option('disqus_forum_url') ); ?>';
1201
+ (function () {
1202
+ var nodes = document.getElementsByTagName('span');
1203
+ for (var i = 0, url; i < nodes.length; i++) {
1204
+ if (nodes[i].className.indexOf('dsq-postid') != -1 && nodes[i].parentNode.tagName == 'A') {
1205
+ nodes[i].parentNode.setAttribute('data-disqus-identifier', nodes[i].getAttribute('data-dsqidentifier'));
1206
+ url = nodes[i].parentNode.href.split('#', 1);
1207
+ if (url.length == 1) { url = url[0]; }
1208
+ else { url = url[1]; }
1209
+ nodes[i].parentNode.href = url + '#disqus_thread';
1210
+ }
1211
+ }
1212
+ var s = document.createElement('script');
1213
+ s.async = true;
1214
+ s.type = 'text/javascript';
1215
+ s.src = '//' + disqus_shortname + '.<?php echo DISQUS_DOMAIN; ?>/count.js';
1216
+ (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
1217
+ }());
1218
+ // ]]>
1219
+ </script>
1220
+ <?php
1221
+ }
1222
+ }
1223
+
1224
+ function dsq_output_footer_comment_js() {
1225
+ if (!dsq_can_replace()) return;
1226
+
1227
+ dsq_output_count_js();
1228
+ }
1229
+
1230
+ add_action('wp_footer', 'dsq_output_footer_comment_js');
1231
+
1232
+ // UPDATE DSQ when a permalink changes
1233
+
1234
+ $dsq_prev_permalinks = array();
1235
+
1236
+ function dsq_prev_permalink($post_id) {
1237
+ $post = get_post($post_id);
1238
+ // if post not published, return
1239
+ if ($post->post_status != 'publish') {
1240
+ return;
1241
+ }
1242
+ global $dsq_prev_permalinks;
1243
+ $dsq_prev_permalinks['post_'.$post_id] = get_permalink($post_id);
1244
+ }
1245
+ add_action('pre_post_update', 'dsq_prev_permalink');
1246
+
1247
+ function dsq_check_permalink($post_id) {
1248
+ global $dsq_prev_permalinks;
1249
+ if (!empty($dsq_prev_permalinks['post_'.$post_id]) &&
1250
+ $dsq_prev_permalinks['post_'.$post_id] != get_permalink($post_id)
1251
+ ) {
1252
+ $post = get_post($post_id);
1253
+ dsq_update_permalink($post);
1254
+ }
1255
+ }
1256
+ add_action('edit_post', 'dsq_check_permalink');
1257
+
1258
+ // Only replace comments if the disqus_forum_url option is set.
1259
+ add_filter('comments_template', 'dsq_comments_template');
1260
+ add_filter('comments_number', 'dsq_comments_text');
1261
+ add_filter('get_comments_number', 'dsq_comments_number');
1262
+ add_filter('bloginfo_url', 'dsq_bloginfo_url');
1263
+
1264
+ /**
1265
+ * JSON ENCODE for PHP < 5.2.0
1266
+ * Checks if json_encode is not available and defines json_encode
1267
+ * to use php_json_encode in its stead
1268
+ * Works on iteratable objects as well - stdClass is iteratable, so all WP objects are gonna be iteratable
1269
+ */
1270
+ if(!function_exists('cf_json_encode')) {
1271
+ function cf_json_encode($data) {
1272
+
1273
+ // json_encode is sending an application/x-javascript header on Joyent servers
1274
+ // for some unknown reason.
1275
+ return cfjson_encode($data);
1276
+ }
1277
+
1278
+ function cfjson_encode_string($str) {
1279
+ if(is_bool($str)) {
1280
+ return $str ? 'true' : 'false';
1281
+ }
1282
+
1283
+ return str_replace(
1284
+ array(
1285
+ '"'
1286
+ , '/'
1287
+ , "\n"
1288
+ , "\r"
1289
+ )
1290
+ , array(
1291
+ '\"'
1292
+ , '\/'
1293
+ , '\n'
1294
+ , '\r'
1295
+ )
1296
+ , $str
1297
+ );
1298
+ }
1299
+
1300
+ function cfjson_encode($arr) {
1301
+ $json_str = '';
1302
+ if (is_array($arr)) {
1303
+ $pure_array = true;
1304
+ $array_length = count($arr);
1305
+ for ( $i = 0; $i < $array_length ; $i++) {
1306
+ if (!isset($arr[$i])) {
1307
+ $pure_array = false;
1308
+ break;
1309
+ }
1310
+ }
1311
+ if ($pure_array) {
1312
+ $json_str = '[';
1313
+ $temp = array();
1314
+ for ($i=0; $i < $array_length; $i++) {
1315
+ $temp[] = sprintf("%s", cfjson_encode($arr[$i]));
1316
+ }
1317
+ $json_str .= implode(',', $temp);
1318
+ $json_str .="]";
1319
+ }
1320
+ else {
1321
+ $json_str = '{';
1322
+ $temp = array();
1323
+ foreach ($arr as $key => $value) {
1324
+ $temp[] = sprintf("\"%s\":%s", $key, cfjson_encode($value));
1325
+ }
1326
+ $json_str .= implode(',', $temp);
1327
+ $json_str .= '}';
1328
+ }
1329
+ }
1330
+ else if (is_object($arr)) {
1331
+ $json_str = '{';
1332
+ $temp = array();
1333
+ foreach ($arr as $k => $v) {
1334
+ $temp[] = '"'.$k.'":'.cfjson_encode($v);
1335
+ }
1336
+ $json_str .= implode(',', $temp);
1337
+ $json_str .= '}';
1338
+ }
1339
+ else if (is_string($arr)) {
1340
+ $json_str = '"'. cfjson_encode_string($arr) . '"';
1341
+ }
1342
+ else if (is_numeric($arr)) {
1343
+ $json_str = $arr;
1344
+ }
1345
+ else if (is_bool($arr)) {
1346
+ $json_str = $arr ? 'true' : 'false';
1347
+ }
1348
+ else {
1349
+ $json_str = '"'. cfjson_encode_string($arr) . '"';
1350
+ }
1351
+ return $json_str;
1352
+ }
1353
+ }
1354
+
1355
+ // Single Sign-on Integration
1356
+
1357
+ function dsq_sso_login() {
1358
+ global $current_site;
1359
+ $sitename = get_bloginfo('name');
1360
+ $siteurl = site_url();
1361
+ $button = get_option('disqus_sso_button');
1362
+ $sso_login_str = 'this.sso = {
1363
+ name: "' . esc_js( $sitename ) . '",
1364
+ button: "' . $button . '",
1365
+ url: "' . $siteurl . '/wp-login.php",
1366
+ logout: "' . $siteurl . '/wp-login.php?action=logout",
1367
+ width: "800",
1368
+ height: "700"
1369
+ };';
1370
+ return $sso_login_str;
1371
+ }
1372
+
1373
+ function dsq_sso() {
1374
+ if ($key = get_option('disqus_partner_key')) {
1375
+ // use old style SSO
1376
+ $new = false;
1377
+ } elseif (($key = get_option('disqus_secret_key')) && ($public = get_option('disqus_public_key'))) {
1378
+ // use new style SSO
1379
+ $new = true;
1380
+ } else {
1381
+ // sso is not configured
1382
+ return array();
1383
+ }
1384
+ global $current_user, $dsq_api;
1385
+ get_currentuserinfo();
1386
+ if ($current_user->ID) {
1387
+ $avatar_tag = get_avatar($current_user->ID);
1388
+ $avatar_data = array();
1389
+ preg_match('/(src)=((\'|")[^(\'|")]*(\'|"))/i', $avatar_tag, $avatar_data);
1390
+ $avatar = str_replace(array('"', "'"), '', $avatar_data[2]);
1391
+ $user_data = array(
1392
+ 'username' => $current_user->display_name,
1393
+ 'id' => $current_user->ID,
1394
+ 'avatar' => $avatar,
1395
+ 'email' => $current_user->user_email,
1396
+ 'url' => $current_user->user_url,
1397
+ );
1398
+ }
1399
+ else {
1400
+ $user_data = array();
1401
+ }
1402
+ $user_data = base64_encode(cf_json_encode($user_data));
1403
+ $time = time();
1404
+ $hmac = dsq_hmacsha1($user_data.' '.$time, $key);
1405
+
1406
+ $payload = $user_data.' '.$hmac.' '.$time;
1407
+
1408
+ if ($new) {
1409
+ return array('remote_auth_s3'=>$payload, 'api_key'=>$public);
1410
+ } else {
1411
+ return array('remote_auth_s2'=>$payload);
1412
+ }
1413
+ }
1414
+
1415
+ // from: http://www.php.net/manual/en/function.sha1.php#39492
1416
+ // Calculate HMAC-SHA1 according to RFC2104
1417
+ // http://www.ietf.org/rfc/rfc2104.txt
1418
+ function dsq_hmacsha1($data, $key) {
1419
+ $blocksize=64;
1420
+ $hashfunc='sha1';
1421
+ if (strlen($key)>$blocksize)
1422
+ $key=pack('H*', $hashfunc($key));
1423
+ $key=str_pad($key,$blocksize,chr(0x00));
1424
+ $ipad=str_repeat(chr(0x36),$blocksize);
1425
+ $opad=str_repeat(chr(0x5c),$blocksize);
1426
+ $hmac = pack(
1427
+ 'H*',$hashfunc(
1428
+ ($key^$opad).pack(
1429
+ 'H*',$hashfunc(
1430
+ ($key^$ipad).$data
1431
+ )
1432
+ )
1433
+ )
1434
+ );
1435
+ return bin2hex($hmac);
1436
+ }
1437
+
1438
+ function dsq_identifier_for_post($post) {
1439
+ return $post->ID . ' ' . $post->guid;
1440
+ }
1441
+
1442
+ function dsq_title_for_post($post) {
1443
+ $title = get_the_title($post);
1444
+ $title = strip_tags($title, DISQUS_ALLOWED_HTML);
1445
+ return $title;
1446
+ }
1447
+
1448
+ function dsq_link_for_post($post) {
1449
+ return get_permalink($post);
1450
+ }
1451
+
1452
+ function dsq_does_need_update() {
1453
+ $version = (string)get_option('disqus_version');
1454
+ if (empty($version)) {
1455
+ $version = '0';
1456
+ }
1457
+
1458
+ if (version_compare($version, '2.49', '<')) {
1459
+ return true;
1460
+ }
1461
+
1462
+ return false;
1463
+ }
1464
+
1465
+ function dsq_install($allow_database_install=true) {
1466
+ global $wpdb, $userdata;
1467
+
1468
+ $version = (string)get_option('disqus_version');
1469
+ if (!$version) {
1470
+ $version = '0';
1471
+ }
1472
+
1473
+ if ($allow_database_install)
1474
+ {
1475
+ dsq_install_database($version);
1476
+ }
1477
+
1478
+ if (version_compare($version, DISQUS_VERSION, '=')) return;
1479
+
1480
+ // if this is a new install, we should not set disqus active
1481
+ if ($version == '0') {
1482
+ add_option('disqus_active', '0');
1483
+ } else {
1484
+ add_option('disqus_active', '1');
1485
+ }
1486
+
1487
+ update_option('disqus_version', DISQUS_VERSION);
1488
+ }
1489
+
1490
+ /**
1491
+ * Initializes the database if it's not already present.
1492
+ */
1493
+ function dsq_install_database($version=0) {
1494
+ global $wpdb;
1495
+
1496
+ if ( version_compare($version, '2.49', '<') && !is_wp_vip() ) {
1497
+ $wpdb->query("CREATE INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta` (meta_key, meta_value(11));");
1498
+ }
1499
+ }
1500
+ function dsq_reset_database($version=0) {
1501
+ global $wpdb;
1502
+
1503
+ if ( version_compare($version, '2.49', '>=') && !is_wp_vip() ) {
1504
+ $wpdb->query("DROP INDEX disqus_dupecheck ON `".$wpdb->prefix."commentmeta`;");
1505
+ }
1506
+ }
1507
+
1508
+ /**
1509
+ * Disable internal Wordpress commenting if Disqus is enabled - this prevents spam bots from
1510
+ * commenting using POST requests to /wp-comments-post.php.
1511
+ *
1512
+ * @param int $comment_post_ID
1513
+ * @return int
1514
+ */
1515
+ function dsq_pre_comment_on_post($comment_post_ID) {
1516
+ if (dsq_can_replace()) {
1517
+ wp_die( dsq_i('Sorry, the built-in commenting system is disabled because Disqus is active.') );
1518
+ }
1519
+ return $comment_post_ID;
1520
+ }
1521
+ add_action('pre_comment_on_post', 'dsq_pre_comment_on_post');
1522
+
1523
+ ?>
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="https://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/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-2016 Big Head Labs
9
+ * @link https://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-2016 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://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 __construct($user_api_key, $forum_api_key, $api_url='https://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 __construct() {
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,296 @@
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
+ // Don't use cURL on IIS servers because it doesn't explicitly specify a CA bundle by default
262
+ if(function_exists('curl_init') && strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') == false) {
263
+ if (!function_exists('curl_setopt_array')) {
264
+ function curl_setopt_array(&$ch, $curl_options)
265
+ {
266
+ foreach ($curl_options as $option => $value) {
267
+ if (!curl_setopt($ch, $option, $value)) {
268
+ return false;
269
+ }
270
+ }
271
+ return true;
272
+ }
273
+ }
274
+ _dsq_curl_urlopen($url, $postdata, $response, $file_name, $file_field);
275
+ } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
276
+ _dsq_fopen_urlopen($url, $postdata, $response, $file_name, $file_field);
277
+ } else {
278
+ // TODO: Find the failure condition for fsockopen() (sockets?)
279
+ _dsq_fsockopen_urlopen($url, $postdata, $response, $file_name, $file_field);
280
+ }
281
+
282
+ // returns array with keys data and code (from headers)
283
+
284
+ return $response;
285
+ }
286
+
287
+ function dsq_url_method() {
288
+ if(function_exists('curl_init')) {
289
+ return 'curl';
290
+ } else if(ini_get('allow_url_fopen') && function_exists('stream_get_contents')) {
291
+ return 'fopen';
292
+ } else {
293
+ return 'fsockopen';
294
+ }
295
+ }
296
+ ?>
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['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
- ?>
1
+ <?php
2
+ /**
3
+ * Implementation of the Disqus API designed for WordPress.
4
+ *
5
+ * @author Disqus <team@disqus.com>
6
+ * @copyright 2007-2016 Big Head Labs
7
+ * @link https://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 __construct($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
+ ?>
manage.php CHANGED
@@ -1,668 +1,668 @@
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('dsq_external_js', isset($_POST['dsq_external_js']) ? '1' : '0');
171
- update_option('disqus_manual_sync', isset($_POST['disqus_manual_sync']));
172
- update_option('disqus_disable_ssr', isset($_POST['disqus_disable_ssr']));
173
- update_option('disqus_public_key', isset($_POST['disqus_public_key']) ? esc_attr( $_POST['disqus_public_key'] ) : '');
174
- update_option('disqus_secret_key', isset($_POST['disqus_secret_key']) ? esc_attr( $_POST['disqus_secret_key'] ) : '');
175
- // Handle SSO button uploads
176
- if ( version_compare($wp_version, '3.5', '>=') ) {
177
- // Use WP 3.5's new, streamlined, much-improved built-in media uploader
178
-
179
- // Only update if a value is actually POSTed, otherwise any time the form is saved the button will be un-set
180
- if ( $_POST['disqus_sso_button'] ) {
181
- update_option('disqus_sso_button', isset($_POST['disqus_sso_button']) ? esc_url( $_POST['disqus_sso_button'] ) : '');
182
- }
183
- } else {
184
- // WP is older than 3.5, use legacy, less-elegant media uploader
185
- if(isset($_FILES['disqus_sso_button'])) {
186
- dsq_image_upload_handler('disqus_sso_button');
187
- }
188
- }
189
- dsq_manage_dialog(dsq_i('Your settings have been changed.'));
190
- }
191
-
192
- // handle disqus_active
193
- if ( isset($_POST['active']) && isset($_GET['active']) ) {
194
- update_option('disqus_active', ($_GET['active'] == '1' ? '1' : '0'));
195
- }
196
-
197
- $dsq_user_api_key = isset($_POST['dsq_user_api_key']) ? $_POST['dsq_user_api_key'] : null;
198
-
199
- // Get installation step process (or 0 if we're already installed).
200
- $step = @intval($_GET['step']);
201
- if ($step > 1 && $step != 3 && $dsq_user_api_key) $step = 1;
202
- elseif ($step == 2 && !isset($_POST['dsq_username'])) $step = 1;
203
- $step = (dsq_is_installed()) ? 0 : ($step ? $step : 1);
204
-
205
- // Handle installation process.
206
- if ( 3 == $step && isset($_POST['dsq_forum']) && isset($_POST['dsq_user_api_key']) ) {
207
- list($dsq_forum_id, $dsq_forum_url) = explode(':', $_POST['dsq_forum']);
208
- update_option('disqus_forum_url', esc_attr( $dsq_forum_url ) );
209
-
210
- // Output javascript in external files by default
211
- update_option('dsq_external_js', '1');
212
-
213
- // Output Javascript in footer by default (no effect when dsq_external_js is enabld)
214
- update_option('disqus_cc_fix', '1');
215
-
216
- $api_key = $dsq_api->get_forum_api_key($_POST['dsq_user_api_key'], $dsq_forum_id);
217
- if ( !$api_key || $api_key < 0 ) {
218
- update_option('disqus_replace', 'replace');
219
- dsq_manage_dialog(
220
- dsq_i('There was an error completing the installation of Disqus.')
221
- . ' '
222
- . dsq_i('If you are still having issues, refer to the help documentation.')
223
- . ' '
224
- . '<a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank">'
225
- . dsq_i('WordPress Help Page')
226
- . '</a>',
227
- true);
228
- } else {
229
- update_option('disqus_api_key', esc_attr( $api_key ));
230
- update_option('disqus_user_api_key', esc_attr( $_POST['dsq_user_api_key']) );
231
- update_option('disqus_replace', 'all');
232
- update_option('disqus_active', '1');
233
- }
234
-
235
- if (!empty($_POST['disqus_partner_key'])) {
236
- $partner_key = trim(stripslashes($_POST['disqus_partner_key']));
237
- if (!empty($partner_key)) {
238
- update_option('disqus_partner_key', $partner_key);
239
- }
240
- }
241
- }
242
-
243
- if ( 2 == $step && isset($_POST['dsq_username']) && isset($_POST['dsq_password']) ) {
244
- $dsq_user_api_key = $dsq_api->get_user_api_key($_POST['dsq_username'], $_POST['dsq_password']);
245
- if ( $dsq_user_api_key < 0 || !$dsq_user_api_key ) {
246
- $step = 1;
247
- dsq_manage_dialog($dsq_api->get_last_error(), true);
248
- }
249
-
250
- if ( $step == 2 ) {
251
- $dsq_sites = $dsq_api->get_forum_list($dsq_user_api_key);
252
- if ( $dsq_sites < 0 ) {
253
- $step = 1;
254
- dsq_manage_dialog($dsq_api->get_last_error(), true);
255
- } else if ( !$dsq_sites ) {
256
- $step = 1;
257
- dsq_manage_dialog(
258
- dsq_i('There aren\'t any sites associated with this account. Maybe you want to create a site?')
259
- . ' '
260
- . '<a href="https://disqus.com/admin/register/" target="_blank">'
261
- . dsq_i('Create a site')
262
- . '</a>',
263
- true);
264
- }
265
- }
266
- }
267
-
268
- $show_advanced = (isset($_GET['t']) && $_GET['t'] == 'adv');
269
-
270
- ?>
271
- <div class="wrap" id="dsq-wrap">
272
- <ul id="dsq-tabs">
273
- <li<?php if (!$show_advanced) echo ' class="selected"'; ?> id="dsq-tab-main" rel="dsq-main">
274
- <?php echo (dsq_is_installed() ? dsq_i('Moderate') : dsq_i('Install')); ?>
275
- </li>
276
- <li<?php if ($show_advanced) echo ' class="selected"'; ?> id="dsq-tab-advanced" rel="dsq-advanced">
277
- <?php echo dsq_i('Plugin Settings'); ?>
278
- </li>
279
- </ul>
280
-
281
- <div id="dsq-main" class="dsq-content">
282
- <?php
283
- switch ( $step ) {
284
- case 3:
285
- ?>
286
- <div id="dsq-step-3" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
287
- <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
288
-
289
- <p><?php echo dsq_i('Disqus has been installed on your blog.'); ?></p>
290
- <p>
291
- <?php echo dsq_i('If you have existing comments, you may wish to export them now.') ?>&nbsp;
292
- <?php echo dsq_i('Otherwise, you\'re all set, and the Disqus network is now powering comments on your site.'); ?>
293
- </p>
294
- <p><a href="edit-comments.php?page=disqus"><?php echo dsq_i('Continue to the moderation dashboard'); ?></a></p>
295
- </div>
296
- <?php
297
- break;
298
- case 2:
299
- ?>
300
- <div id="dsq-step-2" 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=3">
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('Select a website'); ?></th>
308
- <td>
309
- <?php
310
- foreach ( $dsq_sites as $counter => $dsq_site ):
311
- ?>
312
- <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); ?>" />
313
- <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>
314
- <br />
315
- <?php
316
- endforeach;
317
- ?>
318
- <hr />
319
- <a href="https://disqus.com/admin/signup/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
320
- </td>
321
- </tr>
322
- </table>
323
-
324
- <p class="submit" style="text-align: left">
325
- <input type="hidden" name="dsq_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
326
- <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" />
327
- </p>
328
- </form>
329
- </div>
330
- <?php
331
- break;
332
- case 1:
333
- ?>
334
- <div id="dsq-step-1" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
335
- <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
336
-
337
- <form method="POST" action="?page=disqus&amp;step=2">
338
- <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
339
- <table class="form-table">
340
- <tr>
341
- <th scope="row" valign="top"><?php echo dsq_i('Username or email'); ?></th>
342
- <td>
343
- <input id="dsq-username" name="dsq_username" tabindex="1" type="text" />
344
- (<a href="https://disqus.com/profile/signup/"><?php echo dsq_i('don\'t have a Disqus Profile yet?'); ?></a>)
345
- </td>
346
- </tr>
347
- <tr>
348
- <th scope="row" valign="top"><?php echo dsq_i('Password'); ?></th>
349
- <td>
350
- <input type="password" id="dsq-password" name="dsq_password" tabindex="2">
351
- (<a href="https://disqus.com/forgot/"><?php echo dsq_i('forgot your password?'); ?></a>)
352
- </td>
353
- </tr>
354
- </table>
355
-
356
- <p class="submit" style="text-align: left">
357
- <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" tabindex="3">
358
- </p>
359
- </form>
360
- </div>
361
- <?php
362
- break;
363
- case 0:
364
- $url = get_option('disqus_forum_url');
365
- if ($url) { $mod_url = 'https://'.$url.'.disqus.com/admin/moderate/'; }
366
- else { $mod_url = 'https://disqus.com/admin/moderate/'; }
367
-
368
- ?>
369
- <div class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
370
- <h2><a href="<?php echo esc_attr( $mod_url ) ?>"><img src="<?php echo esc_attr( plugins_url( '/media/images/logo.png', __FILE__ ) ); ?>"></a></h2>
371
- <a class="button-primary button" href="<?php echo esc_attr( $mod_url ) ?>" target="_blank"><?php echo dsq_i('Go to Disqus Moderation'); ?></a>
372
- </div>
373
- <?php } ?>
374
- </div>
375
-
376
- <?php
377
- $dsq_replace = get_option('disqus_replace');
378
- $dsq_forum_url = strtolower(get_option('disqus_forum_url'));
379
- $dsq_api_key = get_option('disqus_api_key');
380
- $dsq_user_api_key = get_option('disqus_user_api_key');
381
- $dsq_partner_key = get_option('disqus_partner_key');
382
- $dsq_cc_fix = get_option('disqus_cc_fix');
383
- $dsq_external_js = get_option('dsq_external_js');
384
- $dsq_manual_sync = get_option('disqus_manual_sync');
385
- $dsq_disable_ssr = get_option('disqus_disable_ssr');
386
- $dsq_public_key = get_option('disqus_public_key');
387
- $dsq_secret_key = get_option('disqus_secret_key');
388
- $dsq_sso_button = get_option('disqus_sso_button');
389
- $disqus_enabled = get_option('disqus_active') == '1';
390
- $disqus_enabled_state = $disqus_enabled ? 'enabled' : 'disabled';
391
- ?>
392
- <!-- Settings -->
393
- <div id="dsq-advanced" class="dsq-content dsq-advanced"<?php if (!$show_advanced) echo ' style="display:none;"'; ?>>
394
- <h2><?php echo dsq_i('Settings'); ?></h2>
395
- <p><?php echo dsq_i('Version: %s', esc_html(DISQUS_VERSION)); ?></p>
396
-
397
- <!-- Enable/disable Disqus toggle -->
398
- <form method="POST" action="?page=disqus&amp;active=<?php echo (string)((int)($disqus_enabled != true)); ?>">
399
- <?php wp_nonce_field('dsq-wpnonce_active', 'dsq-form_nonce_active'); ?>
400
- <p class="status">
401
- <?php echo dsq_i('Disqus comments are currently '); ?>
402
- <span class="dsq-<?php echo esc_attr( $disqus_enabled_state ); ?>-text"><?php echo $disqus_enabled_state; ?></span>
403
- </p>
404
- <input type="submit" name="active" class="button" value="<?php echo $disqus_enabled ? dsq_i('Disable') : dsq_i('Enable'); ?>" />
405
- </form>
406
-
407
- <!-- Configuration form -->
408
- <form method="POST" enctype="multipart/form-data">
409
- <?php wp_nonce_field('dsq-wpnonce_settings', 'dsq-form_nonce_settings'); ?>
410
- <table class="form-table">
411
-
412
- <tr>
413
- <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('General') . '</h3>'; ?></th>
414
- </tr>
415
- <tr>
416
- <th scope="row" valign="top"><?php echo dsq_i('Forum Shortname'); ?></th>
417
- <td>
418
- <input type="hidden" name="disqus_forum_url" value="<?php echo esc_attr($dsq_forum_url); ?>"/>
419
- <code><?php echo esc_attr($dsq_forum_url); ?></code>
420
- <br />
421
- <?php echo dsq_i('This is the unique identifier for your website in Disqus, automatically set during installation.'); ?>
422
- </td>
423
- </tr>
424
-
425
- <tr>
426
- <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Appearance') . '</h3>'; ?></th>
427
- </tr>
428
- <tr>
429
- <th scope="row" valign="top"><?php echo dsq_i('Use Disqus Comments on'); ?></th>
430
- <td>
431
- <select name="disqus_replace" tabindex="1" class="disqus-replace">
432
- <option value="all" <?php if($dsq_replace == 'all'){echo 'selected';}?>><?php echo dsq_i('All blog posts.'); ?></option>
433
- <option value="closed" <?php if('closed'==$dsq_replace){echo 'selected';}?>><?php echo dsq_i('Blog posts with closed comments only.'); ?></option>
434
- </select>
435
- <br />
436
- <?php
437
- 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>';
438
- 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.');
439
- ?>
440
- </td>
441
- </tr>
442
-
443
- <tr>
444
- <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Sync') . '</h3>'; ?></th>
445
- </tr>
446
- <tr>
447
- <th scope="row" valign="top"><?php echo dsq_i('Comment Importing'); ?></th>
448
- <td>
449
- <input type="checkbox" id="disqus_manual_sync" name="disqus_manual_sync" <?php if($dsq_manual_sync){echo 'checked="checked"';}?> >
450
- <label for="disqus_manual_sync"><?php echo dsq_i('Disable automated comment importing'); ?></label>
451
- <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.'); ?>
452
- </td>
453
- </tr>
454
- <tr>
455
- <th scope="row" valign="top"><?php echo dsq_i('Server-Side Rendering'); ?></th>
456
- <td>
457
- <input type="checkbox" id="disqus_disable_ssr" name="disqus_disable_ssr" <?php if($dsq_disable_ssr){echo 'checked="checked"';}?> >
458
- <label for="disqus_disable_ssr"><?php echo dsq_i('Disable server-side rendering of comments'); ?></label>
459
- <br /><?php echo dsq_i('Hides comments from nearly all search engines.'); ?>
460
- </td>
461
- </tr>
462
-
463
- <tr>
464
- <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Patches') . '</h3>'; ?></th>
465
- </tr>
466
-
467
- <tr>
468
- <th scope="row" valign="top"><?php echo dsq_i('External Javascript Files'); ?></th>
469
- <td>
470
- <input type="checkbox" id="disqus_external_javascript" name="dsq_external_js" <?php if($dsq_external_js == '1'){ echo 'checked="checked"'; } ?> >
471
- <label for="disqus_external_javascript"><?php echo dsq_i('Render Javascript in external files'); ?></label>
472
- <br /><?php echo dsq_i('This will render the Disqus scripts as external files in the footer as recommended by Wordpress. Disable this if are not seeing Disqus appear on pages that normally have comments. This will fix the issue if your theme does not support the \'wp_enqueue_script\' function, are caching your site on a CDN.'); ?>
473
- </td>
474
- </tr>
475
-
476
- <tr>
477
- <th scope="row" valign="top"><?php echo dsq_i('Template Conflicts'); ?></th>
478
- <td>
479
- <input type="checkbox" id="disqus_comment_count" name="disqus_cc_fix" <?php if($dsq_external_js == '1'){ echo 'disabled '; } if($dsq_cc_fix == '1' || $dsq_external_js == '1'){ echo 'checked="checked"'; } ?> >
480
- <label for="disqus_comment_count"><?php echo dsq_i('Output JavaScript in footer'); ?></label>
481
- <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'); ?>
482
- </td>
483
- </tr>
484
-
485
- <tr>
486
- <th scope="row" valign="top" colspan="2">
487
- <h3><?php echo dsq_i('Advanced'); ?></h3>
488
- <h4><?php echo dsq_i('Single Sign-On'); ?></h4>
489
- <p>
490
- <?php echo dsq_i('Allows users to log in to Disqus via WordPress.'); ?>
491
- <a href="https://help.disqus.com/customer/portal/articles/684744" target="_blank">
492
- <?php echo dsq_i('More info on SSO'); ?>
493
- </a>
494
- </p>
495
- </th>
496
- </tr>
497
- <?php if (!empty($dsq_partner_key)) {// this option only shows if it was already present ?>
498
- <tr>
499
- <th scope="row" valign="top"><?php echo dsq_i('Disqus Partner Key'); ?></th>
500
- <td>
501
- <input type="text" name="disqus_partner_key" value="<?php echo esc_attr($dsq_partner_key); ?>" tabindex="2">
502
- </td>
503
- </tr>
504
- <?php } ?>
505
- <tr>
506
- <th scope="row" valign="top"><?php echo dsq_i('API Application Public Key'); ?></th>
507
- <td>
508
- <input type="text" name="disqus_public_key" value="<?php echo esc_attr($dsq_public_key); ?>" tabindex="2">
509
- <br />
510
- <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
511
- </td>
512
- </tr>
513
- <tr>
514
- <th scope="row" valign="top"><?php echo dsq_i('API Application Secret Key'); ?></th>
515
- <td>
516
- <input type="text" name="disqus_secret_key" value="<?php echo esc_attr($dsq_secret_key); ?>" tabindex="2">
517
- <br />
518
- <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
519
- </td>
520
- </tr>
521
- <tr>
522
- <th scope="row" valign="top"><?php echo dsq_i('Custom Log-in Button'); ?></th>
523
- <td>
524
- <?php if (!empty($dsq_sso_button)) { ?>
525
- <img src="<?php echo esc_attr($dsq_sso_button); ?>" alt="<?php echo esc_attr($dsq_sso_button); ?>" />
526
- <br />
527
- <?php } ?>
528
-
529
- <?php if ( version_compare($wp_version, '3.5', '>=') ) {
530
- // HACK: Use WP's new (as of WP 3.5), streamlined, much-improved built-in media uploader
531
-
532
- // Use WP 3.5's new consolidated call to get all necessary media uploader scripts and styles
533
- wp_enqueue_media();
534
- ?>
535
-
536
- <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">
537
- <input type="hidden" name="disqus_sso_button" id="disqus_sso_button" value=""/>
538
- <?php } else { // use pre-WP 3.5 media upload functionality ?>
539
- <input type="file" name="disqus_sso_button" value="<?php echo esc_attr($dsq_sso_button); ?>" tabindex="2">
540
- <?php } ?>
541
- <br />
542
- <?php echo dsq_i('Adds a button to the Disqus log-in interface.'); ?>
543
- (<a href="https://d8v2sqslxfuhj.cloudfront.net/docs/sso-button.png" target="_blank"><?php echo dsq_i('Example screenshot'); ?></a>)
544
- <br />
545
- <?php echo dsq_i('See our documentation for a template to create your own button.'); ?>&nbsp;
546
- <a href="https://help.disqus.com/customer/portal/articles/236206#sso-login-button"><?php echo dsq_i('SSO button documentation'); ?></a>
547
- </td>
548
- </tr>
549
-
550
- </table>
551
-
552
- <p class="submit" style="text-align: left">
553
- <input type="hidden" name="disqus_api_key" value="<?php echo esc_attr($dsq_api_key); ?>"/>
554
- <input type="hidden" name="disqus_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
555
- <input name="submit" type="submit" value="Save" class="button-primary button" tabindex="4">
556
- </p>
557
- </form>
558
-
559
- <h3>Import and Export</h3>
560
-
561
- <table class="form-table">
562
- <?php if (DISQUS_CAN_EXPORT): ?>
563
- <tr id="export">
564
- <th scope="row" valign="top"><?php echo dsq_i('Export comments to Disqus'); ?></th>
565
- <td>
566
- <div id="dsq_export">
567
- <form method="POST" action="">
568
- <?php wp_nonce_field('dsq-wpnonce_export', 'dsq-form_nonce_export'); ?>
569
- <p class="status">
570
- <a href="#" class="button"><?php echo dsq_i('Export Comments'); ?></a>
571
- <?php echo dsq_i('This will export your existing WordPress comments to Disqus'); ?>
572
- </p>
573
- </form>
574
- </div>
575
- </td>
576
- </tr>
577
- <?php endif; ?>
578
- <tr>
579
- <th scope="row" valign="top"><?php echo dsq_i('Sync Disqus with WordPress'); ?></th>
580
- <td>
581
- <div id="dsq_import">
582
- <form method="POST" action="">
583
- <?php wp_nonce_field('dsq-wpnonce_import', 'dsq-form_nonce_import'); ?>
584
- <div class="status">
585
- <p>
586
- <a href="#" class="button"><?php echo dsq_i('Sync Comments'); ?></a>
587
- <?php echo dsq_i('This will download your Disqus comments and store them locally in WordPress'); ?>
588
- </p>
589
- <label>
590
- <input type="checkbox" id="dsq_import_wipe" name="dsq_import_wipe" value="1"/>
591
- <?php echo dsq_i('Remove all imported Disqus comments before syncing.'); ?>
592
- </label>
593
- <br/>
594
- </div>
595
- </form>
596
- </div>
597
- </td>
598
- </tr>
599
- </table>
600
-
601
- <h3>Reset</h3>
602
-
603
- <table class="form-table">
604
- <tr>
605
- <th scope="row" valign="top"><?php echo dsq_i('Reset Disqus'); ?></th>
606
- <td>
607
- <form action="?page=disqus" method="POST">
608
- <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
609
- <p>
610
- <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" />
611
- <?php echo dsq_i('This removes all Disqus-specific settings. Comments will remain unaffected.') ?>
612
- </p>
613
- <?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.') ?>
614
- </form>
615
- </td>
616
- </tr>
617
- </table>
618
- <br/>
619
-
620
- <h3><?php echo dsq_i('Debug Information'); ?></h3>
621
- <p>
622
- <?php echo dsq_i('Having problems with the plugin? Check out our troubleshooting documentation.'); ?>&nbsp;
623
- <a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank"><?php echo dsq_i('WordPress troubleshooting ocumentation'); ?></a>
624
- <?php echo dsq_i('You can also email us and include the debug info below.'); ?>&nbsp;
625
- <a href="mailto:help+wp@disqus.com"><?php echo dsq_i('Contact support'); ?></a>
626
- </p>
627
- <textarea style="width:90%; height:200px;">
628
- URL: <?php echo esc_url( get_option('siteurl') ); ?>
629
-
630
- PHP Version: <?php echo esc_html( phpversion() ); ?>
631
-
632
- Version: <?php echo esc_html( $wp_version ); ?>
633
-
634
- Active Theme:
635
- <?php
636
- if ( !function_exists('wp_get_theme') ) {
637
- $theme = get_theme(get_current_theme());
638
- echo esc_html( $theme['Name'] . ' ' . $theme['Version'] );
639
- } else {
640
- $theme = wp_get_theme();
641
- echo esc_html( $theme->Name . ' ' . $theme->Version );
642
- }
643
- ?>
644
-
645
- URLOpen Method: <?php echo esc_html( dsq_url_method() ); ?>
646
-
647
- Plugin Version: <?php echo esc_html( DISQUS_VERSION ); ?>
648
-
649
- Settings:
650
- dsq_is_installed: <?php echo esc_html( dsq_is_installed() ); ?>
651
- <?php foreach (dsq_options() as $opt) {
652
- echo esc_html( $opt.': '.get_option($opt)."\n" );
653
- }
654
- ?>
655
-
656
- Plugins:
657
- <?php
658
- foreach (get_plugins() as $key => $plugin) {
659
- $isactive = "";
660
- if (is_plugin_active($key)) {
661
- $isactive = "(active)";
662
- }
663
- echo esc_html( $plugin['Name'].' '.$plugin['Version'].' '.$isactive."\n" );
664
- }
665
- ?>
666
- </textarea><br/>
667
- </div>
668
- </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('dsq_external_js', isset($_POST['dsq_external_js']) ? '1' : '0');
171
+ update_option('disqus_manual_sync', isset($_POST['disqus_manual_sync']));
172
+ update_option('disqus_disable_ssr', isset($_POST['disqus_disable_ssr']));
173
+ update_option('disqus_public_key', isset($_POST['disqus_public_key']) ? esc_attr( $_POST['disqus_public_key'] ) : '');
174
+ update_option('disqus_secret_key', isset($_POST['disqus_secret_key']) ? esc_attr( $_POST['disqus_secret_key'] ) : '');
175
+ // Handle SSO button uploads
176
+ if ( version_compare($wp_version, '3.5', '>=') ) {
177
+ // Use WP 3.5's new, streamlined, much-improved built-in media uploader
178
+
179
+ // Only update if a value is actually POSTed, otherwise any time the form is saved the button will be un-set
180
+ if ( $_POST['disqus_sso_button'] ) {
181
+ update_option('disqus_sso_button', isset($_POST['disqus_sso_button']) ? esc_url( $_POST['disqus_sso_button'] ) : '');
182
+ }
183
+ } else {
184
+ // WP is older than 3.5, use legacy, less-elegant media uploader
185
+ if(isset($_FILES['disqus_sso_button'])) {
186
+ dsq_image_upload_handler('disqus_sso_button');
187
+ }
188
+ }
189
+ dsq_manage_dialog(dsq_i('Your settings have been changed.'));
190
+ }
191
+
192
+ // handle disqus_active
193
+ if ( isset($_POST['active']) && isset($_GET['active']) ) {
194
+ update_option('disqus_active', ($_GET['active'] == '1' ? '1' : '0'));
195
+ }
196
+
197
+ $dsq_user_api_key = isset($_POST['dsq_user_api_key']) ? $_POST['dsq_user_api_key'] : null;
198
+
199
+ // Get installation step process (or 0 if we're already installed).
200
+ $step = @intval($_GET['step']);
201
+ if ($step > 1 && $step != 3 && $dsq_user_api_key) $step = 1;
202
+ elseif ($step == 2 && !isset($_POST['dsq_username'])) $step = 1;
203
+ $step = (dsq_is_installed()) ? 0 : ($step ? $step : 1);
204
+
205
+ // Handle installation process.
206
+ if ( 3 == $step && isset($_POST['dsq_forum']) && isset($_POST['dsq_user_api_key']) ) {
207
+ list($dsq_forum_id, $dsq_forum_url) = explode(':', $_POST['dsq_forum']);
208
+ update_option('disqus_forum_url', esc_attr( $dsq_forum_url ) );
209
+
210
+ // Output javascript in external files by default
211
+ update_option('dsq_external_js', '1');
212
+
213
+ // Output Javascript in footer by default (no effect when dsq_external_js is enabld)
214
+ update_option('disqus_cc_fix', '1');
215
+
216
+ $api_key = $dsq_api->get_forum_api_key($_POST['dsq_user_api_key'], $dsq_forum_id);
217
+ if ( !$api_key || $api_key < 0 ) {
218
+ update_option('disqus_replace', 'replace');
219
+ dsq_manage_dialog(
220
+ dsq_i('There was an error completing the installation of Disqus.')
221
+ . ' '
222
+ . dsq_i('If you are still having issues, refer to the help documentation.')
223
+ . ' '
224
+ . '<a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank">'
225
+ . dsq_i('WordPress Help Page')
226
+ . '</a>',
227
+ true);
228
+ } else {
229
+ update_option('disqus_api_key', esc_attr( $api_key ));
230
+ update_option('disqus_user_api_key', esc_attr( $_POST['dsq_user_api_key']) );
231
+ update_option('disqus_replace', 'all');
232
+ update_option('disqus_active', '1');
233
+ }
234
+
235
+ if (!empty($_POST['disqus_partner_key'])) {
236
+ $partner_key = trim(stripslashes($_POST['disqus_partner_key']));
237
+ if (!empty($partner_key)) {
238
+ update_option('disqus_partner_key', $partner_key);
239
+ }
240
+ }
241
+ }
242
+
243
+ if ( 2 == $step && isset($_POST['dsq_username']) && isset($_POST['dsq_password']) ) {
244
+ $dsq_user_api_key = $dsq_api->get_user_api_key($_POST['dsq_username'], $_POST['dsq_password']);
245
+ if ( $dsq_user_api_key < 0 || !$dsq_user_api_key ) {
246
+ $step = 1;
247
+ dsq_manage_dialog($dsq_api->get_last_error(), true);
248
+ }
249
+
250
+ if ( $step == 2 ) {
251
+ $dsq_sites = $dsq_api->get_forum_list($dsq_user_api_key);
252
+ if ( $dsq_sites < 0 ) {
253
+ $step = 1;
254
+ dsq_manage_dialog($dsq_api->get_last_error(), true);
255
+ } else if ( !$dsq_sites ) {
256
+ $step = 1;
257
+ dsq_manage_dialog(
258
+ dsq_i('There aren\'t any sites associated with this account. Maybe you want to create a site?')
259
+ . ' '
260
+ . '<a href="https://disqus.com/admin/register/" target="_blank">'
261
+ . dsq_i('Create a site')
262
+ . '</a>',
263
+ true);
264
+ }
265
+ }
266
+ }
267
+
268
+ $show_advanced = (isset($_GET['t']) && $_GET['t'] == 'adv');
269
+
270
+ ?>
271
+ <div class="wrap" id="dsq-wrap">
272
+ <ul id="dsq-tabs">
273
+ <li<?php if (!$show_advanced) echo ' class="selected"'; ?> id="dsq-tab-main" rel="dsq-main">
274
+ <?php echo (dsq_is_installed() ? dsq_i('Moderate') : dsq_i('Install')); ?>
275
+ </li>
276
+ <li<?php if ($show_advanced) echo ' class="selected"'; ?> id="dsq-tab-advanced" rel="dsq-advanced">
277
+ <?php echo dsq_i('Plugin Settings'); ?>
278
+ </li>
279
+ </ul>
280
+
281
+ <div id="dsq-main" class="dsq-content">
282
+ <?php
283
+ switch ( $step ) {
284
+ case 3:
285
+ ?>
286
+ <div id="dsq-step-3" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
287
+ <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
288
+
289
+ <p><?php echo dsq_i('Disqus has been installed on your blog.'); ?></p>
290
+ <p>
291
+ <?php echo dsq_i('If you have existing comments, you may wish to export them now.') ?>&nbsp;
292
+ <?php echo dsq_i('Otherwise, you\'re all set, and the Disqus network is now powering comments on your site.'); ?>
293
+ </p>
294
+ <p><a href="edit-comments.php?page=disqus"><?php echo dsq_i('Continue to the moderation dashboard'); ?></a></p>
295
+ </div>
296
+ <?php
297
+ break;
298
+ case 2:
299
+ ?>
300
+ <div id="dsq-step-2" 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=3">
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('Select a website'); ?></th>
308
+ <td>
309
+ <?php
310
+ foreach ( $dsq_sites as $counter => $dsq_site ):
311
+ ?>
312
+ <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); ?>" />
313
+ <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>
314
+ <br />
315
+ <?php
316
+ endforeach;
317
+ ?>
318
+ <hr />
319
+ <a href="https://disqus.com/admin/signup/"><?php echo dsq_i('Or register a new one on the Disqus website.'); ?></a>
320
+ </td>
321
+ </tr>
322
+ </table>
323
+
324
+ <p class="submit" style="text-align: left">
325
+ <input type="hidden" name="dsq_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
326
+ <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" />
327
+ </p>
328
+ </form>
329
+ </div>
330
+ <?php
331
+ break;
332
+ case 1:
333
+ ?>
334
+ <div id="dsq-step-1" class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
335
+ <h2><?php echo dsq_i('Install Disqus Comments'); ?></h2>
336
+
337
+ <form method="POST" action="?page=disqus&amp;step=2">
338
+ <?php wp_nonce_field('dsq-wpnonce_install', 'dsq-form_nonce_install'); ?>
339
+ <table class="form-table">
340
+ <tr>
341
+ <th scope="row" valign="top"><?php echo dsq_i('Username or email'); ?></th>
342
+ <td>
343
+ <input id="dsq-username" name="dsq_username" tabindex="1" type="text" />
344
+ (<a href="https://disqus.com/profile/signup/"><?php echo dsq_i('don\'t have a Disqus Profile yet?'); ?></a>)
345
+ </td>
346
+ </tr>
347
+ <tr>
348
+ <th scope="row" valign="top"><?php echo dsq_i('Password'); ?></th>
349
+ <td>
350
+ <input type="password" id="dsq-password" name="dsq_password" tabindex="2">
351
+ (<a href="https://disqus.com/forgot/"><?php echo dsq_i('forgot your password?'); ?></a>)
352
+ </td>
353
+ </tr>
354
+ </table>
355
+
356
+ <p class="submit" style="text-align: left">
357
+ <input name="submit" type="submit" class="button-primary button" value="Next &raquo;" tabindex="3">
358
+ </p>
359
+ </form>
360
+ </div>
361
+ <?php
362
+ break;
363
+ case 0:
364
+ $url = get_option('disqus_forum_url');
365
+ if ($url) { $mod_url = 'https://'.$url.'.disqus.com/admin/moderate/'; }
366
+ else { $mod_url = 'https://disqus.com/admin/moderate/'; }
367
+
368
+ ?>
369
+ <div class="dsq-main"<?php if ($show_advanced) echo ' style="display:none;"'; ?>>
370
+ <h2><a href="<?php echo esc_attr( $mod_url ) ?>"><img src="<?php echo esc_attr( plugins_url( '/media/images/logo.png', __FILE__ ) ); ?>"></a></h2>
371
+ <a class="button-primary button" href="<?php echo esc_attr( $mod_url ) ?>" target="_blank"><?php echo dsq_i('Go to Disqus Moderation'); ?></a>
372
+ </div>
373
+ <?php } ?>
374
+ </div>
375
+
376
+ <?php
377
+ $dsq_replace = get_option('disqus_replace');
378
+ $dsq_forum_url = strtolower(get_option('disqus_forum_url'));
379
+ $dsq_api_key = get_option('disqus_api_key');
380
+ $dsq_user_api_key = get_option('disqus_user_api_key');
381
+ $dsq_partner_key = get_option('disqus_partner_key');
382
+ $dsq_cc_fix = get_option('disqus_cc_fix');
383
+ $dsq_external_js = get_option('dsq_external_js');
384
+ $dsq_manual_sync = get_option('disqus_manual_sync');
385
+ $dsq_disable_ssr = get_option('disqus_disable_ssr');
386
+ $dsq_public_key = get_option('disqus_public_key');
387
+ $dsq_secret_key = get_option('disqus_secret_key');
388
+ $dsq_sso_button = get_option('disqus_sso_button');
389
+ $disqus_enabled = get_option('disqus_active') == '1';
390
+ $disqus_enabled_state = $disqus_enabled ? 'enabled' : 'disabled';
391
+ ?>
392
+ <!-- Settings -->
393
+ <div id="dsq-advanced" class="dsq-content dsq-advanced"<?php if (!$show_advanced) echo ' style="display:none;"'; ?>>
394
+ <h2><?php echo dsq_i('Settings'); ?></h2>
395
+ <p><?php echo dsq_i('Version: %s', esc_html(DISQUS_VERSION)); ?></p>
396
+
397
+ <!-- Enable/disable Disqus toggle -->
398
+ <form method="POST" action="?page=disqus&amp;active=<?php echo (string)((int)($disqus_enabled != true)); ?>">
399
+ <?php wp_nonce_field('dsq-wpnonce_active', 'dsq-form_nonce_active'); ?>
400
+ <p class="status">
401
+ <?php echo dsq_i('Disqus comments are currently '); ?>
402
+ <span class="dsq-<?php echo esc_attr( $disqus_enabled_state ); ?>-text"><?php echo $disqus_enabled_state; ?></span>
403
+ </p>
404
+ <input type="submit" name="active" class="button" value="<?php echo $disqus_enabled ? dsq_i('Disable') : dsq_i('Enable'); ?>" />
405
+ </form>
406
+
407
+ <!-- Configuration form -->
408
+ <form method="POST" enctype="multipart/form-data">
409
+ <?php wp_nonce_field('dsq-wpnonce_settings', 'dsq-form_nonce_settings'); ?>
410
+ <table class="form-table">
411
+
412
+ <tr>
413
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('General') . '</h3>'; ?></th>
414
+ </tr>
415
+ <tr>
416
+ <th scope="row" valign="top"><?php echo dsq_i('Forum Shortname'); ?></th>
417
+ <td>
418
+ <input type="hidden" name="disqus_forum_url" value="<?php echo esc_attr($dsq_forum_url); ?>"/>
419
+ <code><?php echo esc_attr($dsq_forum_url); ?></code>
420
+ <br />
421
+ <?php echo dsq_i('This is the unique identifier for your website in Disqus, automatically set during installation.'); ?>
422
+ </td>
423
+ </tr>
424
+
425
+ <tr>
426
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Appearance') . '</h3>'; ?></th>
427
+ </tr>
428
+ <tr>
429
+ <th scope="row" valign="top"><?php echo dsq_i('Use Disqus Comments on'); ?></th>
430
+ <td>
431
+ <select name="disqus_replace" tabindex="1" class="disqus-replace">
432
+ <option value="all" <?php if($dsq_replace == 'all'){echo 'selected';}?>><?php echo dsq_i('All blog posts.'); ?></option>
433
+ <option value="closed" <?php if('closed'==$dsq_replace){echo 'selected';}?>><?php echo dsq_i('Blog posts with closed comments only.'); ?></option>
434
+ </select>
435
+ <br />
436
+ <?php
437
+ 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>';
438
+ 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.');
439
+ ?>
440
+ </td>
441
+ </tr>
442
+
443
+ <tr>
444
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Sync') . '</h3>'; ?></th>
445
+ </tr>
446
+ <tr>
447
+ <th scope="row" valign="top"><?php echo dsq_i('Comment Importing'); ?></th>
448
+ <td>
449
+ <input type="checkbox" id="disqus_manual_sync" name="disqus_manual_sync" <?php if($dsq_manual_sync){echo 'checked="checked"';}?> >
450
+ <label for="disqus_manual_sync"><?php echo dsq_i('Disable automated comment importing'); ?></label>
451
+ <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.'); ?>
452
+ </td>
453
+ </tr>
454
+ <tr>
455
+ <th scope="row" valign="top"><?php echo dsq_i('Server-Side Rendering'); ?></th>
456
+ <td>
457
+ <input type="checkbox" id="disqus_disable_ssr" name="disqus_disable_ssr" <?php if($dsq_disable_ssr){echo 'checked="checked"';}?> >
458
+ <label for="disqus_disable_ssr"><?php echo dsq_i('Disable server-side rendering of comments'); ?></label>
459
+ <br /><?php echo dsq_i('Hides comments from nearly all search engines.'); ?>
460
+ </td>
461
+ </tr>
462
+
463
+ <tr>
464
+ <th scope="row" valign="top"><?php echo '<h3>' . dsq_i('Patches') . '</h3>'; ?></th>
465
+ </tr>
466
+
467
+ <tr>
468
+ <th scope="row" valign="top"><?php echo dsq_i('External Javascript Files'); ?></th>
469
+ <td>
470
+ <input type="checkbox" id="disqus_external_javascript" name="dsq_external_js" <?php if($dsq_external_js == '1'){ echo 'checked="checked"'; } ?> >
471
+ <label for="disqus_external_javascript"><?php echo dsq_i('Render Javascript in external files'); ?></label>
472
+ <br /><?php echo dsq_i('This will render the Disqus scripts as external files in the footer as recommended by Wordpress. Disable this if are not seeing Disqus appear on pages that normally have comments. This will fix the issue if your theme does not support the \'wp_enqueue_script\' function, are caching your site on a CDN.'); ?>
473
+ </td>
474
+ </tr>
475
+
476
+ <tr>
477
+ <th scope="row" valign="top"><?php echo dsq_i('Template Conflicts'); ?></th>
478
+ <td>
479
+ <input type="checkbox" id="disqus_comment_count" name="disqus_cc_fix" <?php if($dsq_external_js == '1'){ echo 'disabled '; } if($dsq_cc_fix == '1' || $dsq_external_js == '1'){ echo 'checked="checked"'; } ?> >
480
+ <label for="disqus_comment_count"><?php echo dsq_i('Output JavaScript in footer'); ?></label>
481
+ <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'); ?>
482
+ </td>
483
+ </tr>
484
+
485
+ <tr>
486
+ <th scope="row" valign="top" colspan="2">
487
+ <h3><?php echo dsq_i('Advanced'); ?></h3>
488
+ <h4><?php echo dsq_i('Single Sign-On'); ?></h4>
489
+ <p>
490
+ <?php echo dsq_i('Allows users to log in to Disqus via WordPress.'); ?>
491
+ <a href="https://help.disqus.com/customer/portal/articles/684744" target="_blank">
492
+ <?php echo dsq_i('More info on SSO'); ?>
493
+ </a>
494
+ </p>
495
+ </th>
496
+ </tr>
497
+ <?php if (!empty($dsq_partner_key)) {// this option only shows if it was already present ?>
498
+ <tr>
499
+ <th scope="row" valign="top"><?php echo dsq_i('Disqus Partner Key'); ?></th>
500
+ <td>
501
+ <input type="text" name="disqus_partner_key" value="<?php echo esc_attr($dsq_partner_key); ?>" tabindex="2">
502
+ </td>
503
+ </tr>
504
+ <?php } ?>
505
+ <tr>
506
+ <th scope="row" valign="top"><?php echo dsq_i('API Application Public Key'); ?></th>
507
+ <td>
508
+ <input type="text" name="disqus_public_key" value="<?php echo esc_attr($dsq_public_key); ?>" tabindex="2">
509
+ <br />
510
+ <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
511
+ </td>
512
+ </tr>
513
+ <tr>
514
+ <th scope="row" valign="top"><?php echo dsq_i('API Application Secret Key'); ?></th>
515
+ <td>
516
+ <input type="text" name="disqus_secret_key" value="<?php echo esc_attr($dsq_secret_key); ?>" tabindex="2">
517
+ <br />
518
+ <a href="https://disqus.com/api/applications/" target="_blank"><?php echo dsq_i('Disqus API Applications'); ?></a>
519
+ </td>
520
+ </tr>
521
+ <tr>
522
+ <th scope="row" valign="top"><?php echo dsq_i('Custom Log-in Button'); ?></th>
523
+ <td>
524
+ <?php if (!empty($dsq_sso_button)) { ?>
525
+ <img src="<?php echo esc_attr($dsq_sso_button); ?>" alt="<?php echo esc_attr($dsq_sso_button); ?>" />
526
+ <br />
527
+ <?php } ?>
528
+
529
+ <?php if ( version_compare($wp_version, '3.5', '>=') ) {
530
+ // HACK: Use WP's new (as of WP 3.5), streamlined, much-improved built-in media uploader
531
+
532
+ // Use WP 3.5's new consolidated call to get all necessary media uploader scripts and styles
533
+ wp_enqueue_media();
534
+ ?>
535
+
536
+ <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">
537
+ <input type="hidden" name="disqus_sso_button" id="disqus_sso_button" value=""/>
538
+ <?php } else { // use pre-WP 3.5 media upload functionality ?>
539
+ <input type="file" name="disqus_sso_button" value="<?php echo esc_attr($dsq_sso_button); ?>" tabindex="2">
540
+ <?php } ?>
541
+ <br />
542
+ <?php echo dsq_i('Adds a button to the Disqus log-in interface.'); ?>
543
+ (<a href="https://d8v2sqslxfuhj.cloudfront.net/docs/sso-button.png" target="_blank"><?php echo dsq_i('Example screenshot'); ?></a>)
544
+ <br />
545
+ <?php echo dsq_i('See our documentation for a template to create your own button.'); ?>&nbsp;
546
+ <a href="https://help.disqus.com/customer/portal/articles/236206#sso-login-button"><?php echo dsq_i('SSO button documentation'); ?></a>
547
+ </td>
548
+ </tr>
549
+
550
+ </table>
551
+
552
+ <p class="submit" style="text-align: left">
553
+ <input type="hidden" name="disqus_api_key" value="<?php echo esc_attr($dsq_api_key); ?>"/>
554
+ <input type="hidden" name="disqus_user_api_key" value="<?php echo esc_attr($dsq_user_api_key); ?>"/>
555
+ <input name="submit" type="submit" value="Save" class="button-primary button" tabindex="4">
556
+ </p>
557
+ </form>
558
+
559
+ <h3>Import and Export</h3>
560
+
561
+ <table class="form-table">
562
+ <?php if (DISQUS_CAN_EXPORT): ?>
563
+ <tr id="export">
564
+ <th scope="row" valign="top"><?php echo dsq_i('Export comments to Disqus'); ?></th>
565
+ <td>
566
+ <div id="dsq_export">
567
+ <form method="POST" action="">
568
+ <?php wp_nonce_field('dsq-wpnonce_export', 'dsq-form_nonce_export'); ?>
569
+ <p class="status">
570
+ <a href="#" class="button"><?php echo dsq_i('Export Comments'); ?></a>
571
+ <?php echo dsq_i('This will export your existing WordPress comments to Disqus'); ?>
572
+ </p>
573
+ </form>
574
+ </div>
575
+ </td>
576
+ </tr>
577
+ <?php endif; ?>
578
+ <tr>
579
+ <th scope="row" valign="top"><?php echo dsq_i('Sync Disqus with WordPress'); ?></th>
580
+ <td>
581
+ <div id="dsq_import">
582
+ <form method="POST" action="">
583
+ <?php wp_nonce_field('dsq-wpnonce_import', 'dsq-form_nonce_import'); ?>
584
+ <div class="status">
585
+ <p>
586
+ <a href="#" class="button"><?php echo dsq_i('Sync Comments'); ?></a>
587
+ <?php echo dsq_i('This will download your Disqus comments and store them locally in WordPress'); ?>
588
+ </p>
589
+ <label>
590
+ <input type="checkbox" id="dsq_import_wipe" name="dsq_import_wipe" value="1"/>
591
+ <?php echo dsq_i('Remove all imported Disqus comments before syncing.'); ?>
592
+ </label>
593
+ <br/>
594
+ </div>
595
+ </form>
596
+ </div>
597
+ </td>
598
+ </tr>
599
+ </table>
600
+
601
+ <h3>Reset</h3>
602
+
603
+ <table class="form-table">
604
+ <tr>
605
+ <th scope="row" valign="top"><?php echo dsq_i('Reset Disqus'); ?></th>
606
+ <td>
607
+ <form action="?page=disqus" method="POST">
608
+ <?php wp_nonce_field('dsq-wpnonce_reset', 'dsq-form_nonce_reset'); ?>
609
+ <p>
610
+ <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" />
611
+ <?php echo dsq_i('This removes all Disqus-specific settings. Comments will remain unaffected.') ?>
612
+ </p>
613
+ <?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.') ?>
614
+ </form>
615
+ </td>
616
+ </tr>
617
+ </table>
618
+ <br/>
619
+
620
+ <h3><?php echo dsq_i('Debug Information'); ?></h3>
621
+ <p>
622
+ <?php echo dsq_i('Having problems with the plugin? Check out our troubleshooting documentation.'); ?>&nbsp;
623
+ <a href="https://help.disqus.com/customer/portal/articles/472005" target="_blank"><?php echo dsq_i('WordPress troubleshooting ocumentation'); ?></a>
624
+ <?php echo dsq_i('You can also email us and include the debug info below.'); ?>&nbsp;
625
+ <a href="mailto:help+wp@disqus.com"><?php echo dsq_i('Contact support'); ?></a>
626
+ </p>
627
+ <textarea style="width:90%; height:200px;">
628
+ URL: <?php echo esc_url( get_option('siteurl') ); ?>
629
+
630
+ PHP Version: <?php echo esc_html( phpversion() ); ?>
631
+
632
+ Version: <?php echo esc_html( $wp_version ); ?>
633
+
634
+ Active Theme:
635
+ <?php
636
+ if ( !function_exists('wp_get_theme') ) {
637
+ $theme = get_theme(get_current_theme());
638
+ echo esc_html( $theme['Name'] . ' ' . $theme['Version'] );
639
+ } else {
640
+ $theme = wp_get_theme();
641
+ echo esc_html( $theme->Name . ' ' . $theme->Version );
642
+ }
643
+ ?>
644
+
645
+ URLOpen Method: <?php echo esc_html( dsq_url_method() ); ?>
646
+
647
+ Plugin Version: <?php echo esc_html( DISQUS_VERSION ); ?>
648
+
649
+ Settings:
650
+ dsq_is_installed: <?php echo esc_html( dsq_is_installed().'\n' ); ?>
651
+ <?php foreach (dsq_options() as $opt) {
652
+ echo esc_html( $opt.': '.get_option($opt).'\n' );
653
+ }
654
+ ?>
655
+
656
+ Plugins:
657
+ <?php
658
+ foreach (get_plugins() as $key => $plugin) {
659
+ $isactive = '';
660
+ if (is_plugin_active($key)) {
661
+ $isactive = '(active)';
662
+ }
663
+ echo esc_html( $plugin['Name'].' '.$plugin['Version'].' '.$isactive.'\n' );
664
+ }
665
+ ?>
666
+ </textarea><br/>
667
+ </div>
668
+ </div>
media/js/admin.js CHANGED
@@ -1,120 +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
- };
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 CHANGED
@@ -1,17 +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
- }());
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 && nodes[i].parentNode.tagName == 'A') {
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 CHANGED
@@ -1,15 +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
- });
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 CHANGED
@@ -1,56 +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
- })();
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 CHANGED
@@ -1,19 +1,17 @@
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
- });
1
+ jQuery(document).ready( function($) {
2
+
3
+ $('#menu-comments').pointer({
4
+ content: pointerContent,
5
+ position: {
6
+ edge: 'left', // arrow direction
7
+ align: 'center' // vertical alignment
8
+ },
9
+ pointerWidth: 350,
10
+ close: function() {
11
+ $.post(ajaxurl, {
12
+ pointer: 'disqus_settings_pointer', // pointer ID
13
+ action: 'dismiss-wp-pointer'
14
+ });
15
+ }
16
+ }).pointer('open');
17
+ });
 
 
media/js/upload.js CHANGED
@@ -1,34 +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
- });
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,321 +1,337 @@
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.83
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.83 =
64
-
65
- * Fix errors when using SSO and rendering javascript inline
66
-
67
- = 2.82 =
68
-
69
- * Fix PHP errors when there are no comments to sync
70
- * Adds a new option to render Disqus javascript directly in page markup
71
-
72
- = 2.81 =
73
-
74
- * Fix for automatic comment syncing
75
- * Make sure all markup validates for HTML5
76
-
77
- = 2.80 =
78
-
79
- * Move all scripts to separate files instead of rendering them in php
80
- * Added a hook to attach custom functions to disqus_config in javascript
81
- * Fixed exporting bug introduced in 2.78 (Thanks to mkilian)
82
- * Numerous small compatibility and security enhancements
83
-
84
- = 2.79 =
85
-
86
- * Reinstate changes removed by 2.78
87
-
88
- = 2.78 =
89
-
90
- * Security fixes
91
- * Compatibility for Wordpress version 4.0
92
-
93
- = 2.77 =
94
-
95
- * Fixes login by email issue
96
- * Make sure Disqus is enabled after installation
97
- * Additional security fixes
98
-
99
- = 2.76 =
100
-
101
- * Security fixes (Thanks to Nik Cubrilovic, Alexander Concha and Marc-Alexandre Montpas)
102
- * Bump tested Wordpress version to 3.9.1
103
- * Remove obsolete SSO button uploader
104
- * Enable 'Output javascript in footer' by default during installation
105
- * Fix for 'Reset' function not completely working the first time
106
-
107
- = 2.75 =
108
-
109
- * Bump supported WordPress version to 3.8.
110
- * Properly encode site name for SSO login button.
111
- * Increased timeout for comment exporter to 60 seconds.
112
- * Use https: for admin pages
113
- * Miscellaneous bug fixes and improvements.
114
-
115
- = 2.74 =
116
-
117
- * Updated settings UI
118
- * Add filter hook for setting custom Disqus language
119
- * For WP >= 3.5, use new media uploader
120
- * Disable internal Wordpress commenting if Disqus is enabled (thanks Artem Russakovskii)
121
- * Cleaned up installation and configuration flow
122
- * Added link to WP backup guide in README
123
- * Fix admin bar comments link
124
- * Added a check to avoid a missing key notice when WP_DEBUG=TRUE (thanks Jason Lengstorf)
125
- * Prevent 404 errors for embed.js from being reported by Google Webmaster Tools (missed in 2.73 README)
126
-
127
- = 2.73 =
128
-
129
- * Apply CDATA patch from Wordpress 3.4 to dsq_export_wxr_cdata() (thanks Artem
130
- Russakovskii for the patch).
131
- * Added Single Sign-On log-in button and icon to options (only for sites using SSO)
132
- * Output user website if set in SSO payload
133
- * Added plugin activation statuses to debug info
134
- * Bump supported WordPress version to 3.4.1
135
- * Fixed issue where disqus_dupecheck won't properly uninstall
136
- * Load second count.js (output-in-footer version) reference via SSL too
137
- * Added screenshots
138
-
139
- = 2.72 =
140
-
141
- * Load count.js via SSL when page is accessed via HTTPS
142
- * Fixed styling issue with Disqus admin.
143
-
144
- = 2.71 =
145
-
146
- * Fixed issue where embed wasn't using SSL if page was loaded via HTTPS
147
- * Fixed issue with syncing where to user's without a display_name would
148
- revert back to Anonymous (really this time).
149
- * Fixed issue where Google Webmaster Tools would incorrectly report 404s.
150
- * Fixed issue with Disqus admin display issues.
151
-
152
- = 2.70 =
153
-
154
- * Properly uninstall disqus_dupecheck index when uninstalling plugin.
155
- * Fixed issue with syncing where to user's without a display_name would
156
- revert back to Anonymous.
157
- * Fixed issue where IP addresses weren't being synced properly.
158
- * Allow non-Administrators (e.g., editors) to see Disqus Moderate panel
159
- inline (fixes GH-3)
160
-
161
- = 2.69 =
162
-
163
- * Bumped version number.
164
-
165
- = 2.68 =
166
-
167
- * Removed debugging information from web requests in CLI scripts (thanks
168
- Ryan Dewhurst for the report).
169
- * Reduced sync lock time to 1 hour.
170
- * Fixed an issue which was not allowing pending posts (for sync) to clear.
171
- * Fixed an issue with CLI scripts when used with certain caching plugins.
172
-
173
- = 2.67 =
174
-
175
- * Bumped synchronization timer delays to 5 minutes.
176
- * wp-cli.php now requires php_sapi_name to be set to 'cli' for execution.
177
- * Fixed a bug with imported comments not storing the correct relative date.
178
- * Added a lock for dsq_sync_forum, which can be overriden in the command line script
179
- with the --force tag.
180
- * dsq_sync_forum will now handle all pending post metadata updates (formerly a separate
181
- cron task, dsq_sync_post).
182
-
183
- = 2.66 =
184
-
185
- * Fixed issue with jQuery usage which conflicted with updated jQuery version.
186
-
187
- = 2.65 =
188
-
189
- * Corrected a bug that was causing posts to not appear due to invalid references.
190
-
191
- = 2.64 =
192
-
193
- * Added an option to disable Disqus without deactivating the plugin.
194
- * Added a second check for comment sync to prevent stampede race conditions in WP cron.
195
-
196
- = 2.63 =
197
-
198
- * Added command line script to import comments from DISQUS (scripts/import-comments.php).
199
- * Added command line script to export comments to DISQUS (scripts/export-comments.php).
200
- * The exporter will now only do one post at a time.
201
- * The exporter now only sends required attributes to DISQUS.
202
- * Moved media into its own directory.
203
-
204
- = 2.62 =
205
-
206
- * Changed legacy query to use = operator instead of LIKE so it can be indexed.
207
-
208
- = 2.61 =
209
-
210
- * Fixed an issue which was causing invalid information to be presented in RSS feeds.
211
-
212
- = 2.60 =
213
-
214
- * Added support for new Single Sign-On (API version 3.0).
215
- * Improved support for legacy Single Sign-On.
216
-
217
- = 2.55 =
218
-
219
- * Added support for get_comments_number in templates.
220
-
221
- = 2.54 =
222
-
223
- * Updated URL to forum moderation.
224
-
225
- = 2.53 =
226
-
227
- * Fixed an issue with fsockopen and GET requests (only affects certain users).
228
-
229
- = 2.52 =
230
-
231
- * Fixed issue with Disqus-API package not getting updated (only affecting PHP4).
232
-
233
- = 2.51 =
234
-
235
- * Added CDATA comments for JavaScript.
236
- * Syncing comments will now restore missing thread information from old imports.
237
- * Install and uninstall processes have been improved.
238
- * Fixed an issue in PHP4 with importing comments.
239
- * Fixed an issue that could cause duplicate comments in some places.
240
- * Added an option to remove existing imported comments when importing.
241
-
242
- = 2.50 =
243
-
244
- * Added missing file.
245
-
246
- = 2.49 =
247
-
248
- * Database usage has been optimized for storing comment meta data.
249
-
250
- You can perform this migration automatically by visiting Comments -> Disqus, or if
251
- you have a large database, you may do this by hand:
252
-
253
- CREATE INDEX disqus_dupecheck ON `wp_commentmeta` (meta_key, meta_value(11));
254
- 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);
255
-
256
- = 2.48 =
257
-
258
- * Comment synchronization has been optimized to be a single call per-site.
259
- * disqus.css will now only load when displaying comments
260
-
261
- = 2.47 =
262
-
263
- * Fixed a security hole with comment importing.
264
- * Reverted ability to use default template comments design.
265
- * Comments will now store which version they were imported under.
266
- * Added an option to disable server side rendering.
267
-
268
- = 2.46 =
269
-
270
- * Better debugging information for export errors.
271
- * Added the ability to manual import Disqus comments into Wordpress.
272
- * Added thread_identifier support to exports.
273
- * Cleaned up API error messages.
274
- * Fixed a bug which was causing the import process to not grab only the latest set of comments.
275
- * Added an option to disable automated synchronization with Disqus.
276
-
277
- = 2.45 =
278
-
279
- * Comments should now store thread information as well as certain other meta data.
280
- * Optimize get_thread polling to only pull comments which aren't stored properly.
281
-
282
- = 2.44 =
283
-
284
- * Fixed JavaScript response for comments sync call.
285
- * Comments are now marked as closed while showing the embed (fixes showing default respond form).
286
-
287
- = 2.43 =
288
-
289
- * Fixed a JavaScript syntax error which would cause linting to fail.
290
- * Correct an issue that was causing comments.php to throw a syntax error under some configurations.
291
-
292
- = 2.42 =
293
-
294
- * Correct a bug with saving disqus_user_api_key (non-critical).
295
- * Added settings to Debug Information.
296
- * Adjusting all includes to use absolute paths.
297
- * Adjusted JSON usage to solve a problem for some clients.
298
-
299
- = 2.41 =
300
-
301
- * Correct a bug with double urlencoding titles.
302
-
303
- = 2.40 =
304
-
305
- * Comments are now synced with Disqus as a delayed asynchronous cron event.
306
- * Comment count code has been updated to use the new widget. (Comment counts
307
- must be linked to get tracked within "the loop" now).
308
- * API bindings have been migrated to the generic 1.1 Disqus API.
309
- * Pages will now properly update their permalink with Disqus when it changes. This is
310
- done within the sync event above.
311
- * There is now a Debug Information pane under Advanced to assist with support requests.
312
- * When Disqus is unreachable it will fallback to the theme's built-in comment display.
313
- * Legacy mode is no longer available.
314
- * The plugin management interface can now be localized.
315
- * The plugin is now valid HTML5.
316
-
317
- == Support ==
318
-
319
- * Visit http://disqus.com/help/wordpress for help documentation.
320
-
321
- * Visit http://help.disqus.com for help from our support team.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Disqus Comment System ===
2
+ Contributors: disqus, alexkingorg, crowdfavorite, zeeg, tail, thetylerhayes, ryanv12
3
+ Tags: comments, threaded, email, notification, spam, avatars, community, profile, widget, disqus
4
+ Requires at least: 3.2
5
+ Tested up to: 4.6.1
6
+ Stable tag: 2.86
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 [https://disqus.com/help/wordpress](https://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.86 =
64
+
65
+ * Don't attempt to use cURL on IIS servers
66
+ * Check is dsq_sync_forum is scheduled before scheduling
67
+ * Add updates for Travis CI
68
+ * Fixes a bug in the upgrade process
69
+
70
+ = 2.85 =
71
+
72
+ * Fixes deprecation warnings on sites running PHP7
73
+ * Removes a javascript alert from the admin
74
+
75
+ = 2.84 =
76
+
77
+ * Fixes a bug where the comment count won't work on some themes
78
+
79
+ = 2.83 =
80
+
81
+ * Fix errors when using SSO and rendering javascript inline
82
+
83
+ = 2.82 =
84
+
85
+ * Fix PHP errors when there are no comments to sync
86
+ * Adds a new option to render Disqus javascript directly in page markup
87
+
88
+ = 2.81 =
89
+
90
+ * Fix for automatic comment syncing
91
+ * Make sure all markup validates for HTML5
92
+
93
+ = 2.80 =
94
+
95
+ * Move all scripts to separate files instead of rendering them in php
96
+ * Added a hook to attach custom functions to disqus_config in javascript
97
+ * Fixed exporting bug introduced in 2.78 (Thanks to mkilian)
98
+ * Numerous small compatibility and security enhancements
99
+
100
+ = 2.79 =
101
+
102
+ * Reinstate changes removed by 2.78
103
+
104
+ = 2.78 =
105
+
106
+ * Security fixes
107
+ * Compatibility for Wordpress version 4.0
108
+
109
+ = 2.77 =
110
+
111
+ * Fixes login by email issue
112
+ * Make sure Disqus is enabled after installation
113
+ * Additional security fixes
114
+
115
+ = 2.76 =
116
+
117
+ * Security fixes (Thanks to Nik Cubrilovic, Alexander Concha and Marc-Alexandre Montpas)
118
+ * Bump tested Wordpress version to 3.9.1
119
+ * Remove obsolete SSO button uploader
120
+ * Enable 'Output javascript in footer' by default during installation
121
+ * Fix for 'Reset' function not completely working the first time
122
+
123
+ = 2.75 =
124
+
125
+ * Bump supported WordPress version to 3.8.
126
+ * Properly encode site name for SSO login button.
127
+ * Increased timeout for comment exporter to 60 seconds.
128
+ * Use https: for admin pages
129
+ * Miscellaneous bug fixes and improvements.
130
+
131
+ = 2.74 =
132
+
133
+ * Updated settings UI
134
+ * Add filter hook for setting custom Disqus language
135
+ * For WP >= 3.5, use new media uploader
136
+ * Disable internal Wordpress commenting if Disqus is enabled (thanks Artem Russakovskii)
137
+ * Cleaned up installation and configuration flow
138
+ * Added link to WP backup guide in README
139
+ * Fix admin bar comments link
140
+ * Added a check to avoid a missing key notice when WP_DEBUG=TRUE (thanks Jason Lengstorf)
141
+ * Prevent 404 errors for embed.js from being reported by Google Webmaster Tools (missed in 2.73 README)
142
+
143
+ = 2.73 =
144
+
145
+ * Apply CDATA patch from Wordpress 3.4 to dsq_export_wxr_cdata() (thanks Artem
146
+ Russakovskii for the patch).
147
+ * Added Single Sign-On log-in button and icon to options (only for sites using SSO)
148
+ * Output user website if set in SSO payload
149
+ * Added plugin activation statuses to debug info
150
+ * Bump supported WordPress version to 3.4.1
151
+ * Fixed issue where disqus_dupecheck won't properly uninstall
152
+ * Load second count.js (output-in-footer version) reference via SSL too
153
+ * Added screenshots
154
+
155
+ = 2.72 =
156
+
157
+ * Load count.js via SSL when page is accessed via HTTPS
158
+ * Fixed styling issue with Disqus admin.
159
+
160
+ = 2.71 =
161
+
162
+ * Fixed issue where embed wasn't using SSL if page was loaded via HTTPS
163
+ * Fixed issue with syncing where to user's without a display_name would
164
+ revert back to Anonymous (really this time).
165
+ * Fixed issue where Google Webmaster Tools would incorrectly report 404s.
166
+ * Fixed issue with Disqus admin display issues.
167
+
168
+ = 2.70 =
169
+
170
+ * Properly uninstall disqus_dupecheck index when uninstalling plugin.
171
+ * Fixed issue with syncing where to user's without a display_name would
172
+ revert back to Anonymous.
173
+ * Fixed issue where IP addresses weren't being synced properly.
174
+ * Allow non-Administrators (e.g., editors) to see Disqus Moderate panel
175
+ inline (fixes GH-3)
176
+
177
+ = 2.69 =
178
+
179
+ * Bumped version number.
180
+
181
+ = 2.68 =
182
+
183
+ * Removed debugging information from web requests in CLI scripts (thanks
184
+ Ryan Dewhurst for the report).
185
+ * Reduced sync lock time to 1 hour.
186
+ * Fixed an issue which was not allowing pending posts (for sync) to clear.
187
+ * Fixed an issue with CLI scripts when used with certain caching plugins.
188
+
189
+ = 2.67 =
190
+
191
+ * Bumped synchronization timer delays to 5 minutes.
192
+ * wp-cli.php now requires php_sapi_name to be set to 'cli' for execution.
193
+ * Fixed a bug with imported comments not storing the correct relative date.
194
+ * Added a lock for dsq_sync_forum, which can be overriden in the command line script
195
+ with the --force tag.
196
+ * dsq_sync_forum will now handle all pending post metadata updates (formerly a separate
197
+ cron task, dsq_sync_post).
198
+
199
+ = 2.66 =
200
+
201
+ * Fixed issue with jQuery usage which conflicted with updated jQuery version.
202
+
203
+ = 2.65 =
204
+
205
+ * Corrected a bug that was causing posts to not appear due to invalid references.
206
+
207
+ = 2.64 =
208
+
209
+ * Added an option to disable Disqus without deactivating the plugin.
210
+ * Added a second check for comment sync to prevent stampede race conditions in WP cron.
211
+
212
+ = 2.63 =
213
+
214
+ * Added command line script to import comments from DISQUS (scripts/import-comments.php).
215
+ * Added command line script to export comments to DISQUS (scripts/export-comments.php).
216
+ * The exporter will now only do one post at a time.
217
+ * The exporter now only sends required attributes to DISQUS.
218
+ * Moved media into its own directory.
219
+
220
+ = 2.62 =
221
+
222
+ * Changed legacy query to use = operator instead of LIKE so it can be indexed.
223
+
224
+ = 2.61 =
225
+
226
+ * Fixed an issue which was causing invalid information to be presented in RSS feeds.
227
+
228
+ = 2.60 =
229
+
230
+ * Added support for new Single Sign-On (API version 3.0).
231
+ * Improved support for legacy Single Sign-On.
232
+
233
+ = 2.55 =
234
+
235
+ * Added support for get_comments_number in templates.
236
+
237
+ = 2.54 =
238
+
239
+ * Updated URL to forum moderation.
240
+
241
+ = 2.53 =
242
+
243
+ * Fixed an issue with fsockopen and GET requests (only affects certain users).
244
+
245
+ = 2.52 =
246
+
247
+ * Fixed issue with Disqus-API package not getting updated (only affecting PHP4).
248
+
249
+ = 2.51 =
250
+
251
+ * Added CDATA comments for JavaScript.
252
+ * Syncing comments will now restore missing thread information from old imports.
253
+ * Install and uninstall processes have been improved.
254
+ * Fixed an issue in PHP4 with importing comments.
255
+ * Fixed an issue that could cause duplicate comments in some places.
256
+ * Added an option to remove existing imported comments when importing.
257
+
258
+ = 2.50 =
259
+
260
+ * Added missing file.
261
+
262
+ = 2.49 =
263
+
264
+ * Database usage has been optimized for storing comment meta data.
265
+
266
+ You can perform this migration automatically by visiting Comments -> Disqus, or if
267
+ you have a large database, you may do this by hand:
268
+
269
+ CREATE INDEX disqus_dupecheck ON `wp_commentmeta` (meta_key, meta_value(11));
270
+ 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);
271
+
272
+ = 2.48 =
273
+
274
+ * Comment synchronization has been optimized to be a single call per-site.
275
+ * disqus.css will now only load when displaying comments
276
+
277
+ = 2.47 =
278
+
279
+ * Fixed a security hole with comment importing.
280
+ * Reverted ability to use default template comments design.
281
+ * Comments will now store which version they were imported under.
282
+ * Added an option to disable server side rendering.
283
+
284
+ = 2.46 =
285
+
286
+ * Better debugging information for export errors.
287
+ * Added the ability to manual import Disqus comments into Wordpress.
288
+ * Added thread_identifier support to exports.
289
+ * Cleaned up API error messages.
290
+ * Fixed a bug which was causing the import process to not grab only the latest set of comments.
291
+ * Added an option to disable automated synchronization with Disqus.
292
+
293
+ = 2.45 =
294
+
295
+ * Comments should now store thread information as well as certain other meta data.
296
+ * Optimize get_thread polling to only pull comments which aren't stored properly.
297
+
298
+ = 2.44 =
299
+
300
+ * Fixed JavaScript response for comments sync call.
301
+ * Comments are now marked as closed while showing the embed (fixes showing default respond form).
302
+
303
+ = 2.43 =
304
+
305
+ * Fixed a JavaScript syntax error which would cause linting to fail.
306
+ * Correct an issue that was causing comments.php to throw a syntax error under some configurations.
307
+
308
+ = 2.42 =
309
+
310
+ * Correct a bug with saving disqus_user_api_key (non-critical).
311
+ * Added settings to Debug Information.
312
+ * Adjusting all includes to use absolute paths.
313
+ * Adjusted JSON usage to solve a problem for some clients.
314
+
315
+ = 2.41 =
316
+
317
+ * Correct a bug with double urlencoding titles.
318
+
319
+ = 2.40 =
320
+
321
+ * Comments are now synced with Disqus as a delayed asynchronous cron event.
322
+ * Comment count code has been updated to use the new widget. (Comment counts
323
+ must be linked to get tracked within "the loop" now).
324
+ * API bindings have been migrated to the generic 1.1 Disqus API.
325
+ * Pages will now properly update their permalink with Disqus when it changes. This is
326
+ done within the sync event above.
327
+ * There is now a Debug Information pane under Advanced to assist with support requests.
328
+ * When Disqus is unreachable it will fallback to the theme's built-in comment display.
329
+ * Legacy mode is no longer available.
330
+ * The plugin management interface can now be localized.
331
+ * The plugin is now valid HTML5.
332
+
333
+ == Support ==
334
+
335
+ * Visit https://disqus.com/help/wordpress for help documentation.
336
+
337
+ * Visit https://help.disqus.com for help from our support team.
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 https://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" class="button-primary button" 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'] : '1');
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>