├── .DS_Store ├── .gitattributes ├── .gitignore ├── LICENSE ├── controllers ├── .DS_Store ├── core.php ├── multisite.php ├── posts.php ├── respond.php ├── users.php └── widgets.php ├── json-api.php ├── library ├── .DS_Store └── JSON.php ├── models ├── .DS_Store ├── attachment.php ├── author.php ├── category.php ├── comment.php ├── post.php └── tag.php ├── readme.md ├── readme.txt ├── screenshot-1.png ├── singletons ├── .DS_Store ├── api.php ├── introspector.php ├── query.php └── response.php └── tests ├── .DS_Store ├── core.get_author_index-01.phpt ├── core.get_author_posts-01.phpt ├── core.get_author_posts-02.phpt ├── core.get_author_posts-03.phpt ├── core.get_category_index-01.phpt ├── core.get_category_posts-01.phpt ├── core.get_date_index-01.phpt ├── core.get_date_posts-01.phpt ├── core.get_date_posts-02.phpt ├── core.get_date_posts-03.phpt ├── core.get_page-01.phpt ├── core.get_page-02.phpt ├── core.get_post-01.phpt ├── core.get_posts-01.phpt ├── core.get_posts-02.phpt ├── core.get_posts-03.phpt ├── core.get_recent_posts-01.phpt ├── core.get_recent_posts-02.phpt ├── core.get_recent_posts-03.phpt ├── core.get_search_posts-01.phpt ├── core.get_tag_index-01.phpt ├── core.get_tag_posts-01.phpt ├── core.info-01.phpt ├── core.info-02.phpt └── query-01.phpt /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | .DS_Store 4 | .DS_Store 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 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 | 635 | Copyright (C) 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 . 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 | Copyright (C) 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 | . 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 | . -------------------------------------------------------------------------------- /controllers/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/controllers/.DS_Store -------------------------------------------------------------------------------- /controllers/core.php: -------------------------------------------------------------------------------- 1 | query->controller)) { 13 | return $json_api->controller_info($json_api->query->controller); 14 | } else { 15 | $dir = json_api_dir(); 16 | if (file_exists("$dir/json-api.php")) { 17 | $php = file_get_contents("$dir/json-api.php"); 18 | } else { 19 | // Check one directory up, in case json-api.php was moved 20 | $dir = dirname($dir); 21 | if (file_exists("$dir/json-api.php")) { 22 | $php = file_get_contents("$dir/json-api.php"); 23 | } 24 | } 25 | if (preg_match('/^\s*Version:\s*(.+)$/m', $php, $matches)) { 26 | $version = $matches[1]; 27 | } else { 28 | $version = '(Unknown)'; 29 | } 30 | $active_controllers = explode(',', get_option('json_api_controllers', 'core')); 31 | $controllers = array_intersect($json_api->get_controllers(), $active_controllers); 32 | return array( 33 | 'json_api_version' => $version, 34 | 'controllers' => array_values($controllers) 35 | ); 36 | } 37 | } 38 | 39 | public function get_recent_posts() { 40 | global $json_api; 41 | $posts = $json_api->introspector->get_posts(); 42 | return $this->posts_result($posts); 43 | } 44 | 45 | public function get_posts() { 46 | global $json_api; 47 | $url = parse_url($_SERVER['REQUEST_URI']); 48 | $defaults = array( 49 | 'ignore_sticky_posts' => true 50 | ); 51 | $query = wp_parse_args($url['query']); 52 | unset($query['json']); 53 | unset($query['post_status']); 54 | $query = array_merge($defaults, $query); 55 | $posts = $json_api->introspector->get_posts($query); 56 | $result = $this->posts_result($posts); 57 | $result['query'] = $query; 58 | return $result; 59 | } 60 | 61 | public function get_post() { 62 | global $json_api, $post; 63 | $post = $json_api->introspector->get_current_post(); 64 | if ($post) { 65 | $previous = get_adjacent_post(false, '', true); 66 | $next = get_adjacent_post(false, '', false); 67 | $response = array( 68 | 'post' => new JSON_API_Post($post) 69 | ); 70 | if ($previous) { 71 | $response['previous_url'] = get_permalink($previous->ID); 72 | $response['previous_post_title'] = $previous->post_title; 73 | } 74 | if ($next) { 75 | $response['next_url'] = get_permalink($next->ID); 76 | $response['next_post_title'] = $next->post_title; 77 | } 78 | return $response; 79 | } else { 80 | $json_api->error("Not found."); 81 | } 82 | } 83 | 84 | public function get_page() { 85 | global $json_api; 86 | extract($json_api->query->get(array('id', 'slug', 'page_id', 'page_slug', 'children'))); 87 | if ($id || $page_id) { 88 | if (!$id) { 89 | $id = $page_id; 90 | } 91 | $posts = $json_api->introspector->get_posts(array( 92 | 'page_id' => $id 93 | )); 94 | } else if ($slug || $page_slug) { 95 | if (!$slug) { 96 | $slug = $page_slug; 97 | } 98 | $posts = $json_api->introspector->get_posts(array( 99 | 'pagename' => $slug 100 | )); 101 | } else { 102 | $json_api->error("Include 'id' or 'slug' var in your request."); 103 | } 104 | 105 | // Workaround for https://core.trac.wordpress.org/ticket/12647 106 | if (empty($posts)) { 107 | $url = $_SERVER['REQUEST_URI']; 108 | $parsed_url = parse_url($url); 109 | $path = $parsed_url['path']; 110 | if (preg_match('#^http://[^/]+(/.+)$#', get_bloginfo('url'), $matches)) { 111 | $blog_root = $matches[1]; 112 | $path = preg_replace("#^$blog_root#", '', $path); 113 | } 114 | if (substr($path, 0, 1) == '/') { 115 | $path = substr($path, 1); 116 | } 117 | $posts = $json_api->introspector->get_posts(array('pagename' => $path)); 118 | } 119 | 120 | if (count($posts) == 1) { 121 | if (!empty($children)) { 122 | $json_api->introspector->attach_child_posts($posts[0]); 123 | } 124 | return array( 125 | 'page' => $posts[0] 126 | ); 127 | } else { 128 | $json_api->error("Not found."); 129 | } 130 | } 131 | 132 | public function get_date_posts() { 133 | global $json_api; 134 | if ($json_api->query->date) { 135 | $date = preg_replace('/\D/', '', $json_api->query->date); 136 | if (!preg_match('/^\d{4}(\d{2})?(\d{2})?$/', $date)) { 137 | $json_api->error("Specify a date var in one of 'YYYY' or 'YYYY-MM' or 'YYYY-MM-DD' formats."); 138 | } 139 | $request = array('year' => substr($date, 0, 4)); 140 | if (strlen($date) > 4) { 141 | $request['monthnum'] = (int) substr($date, 4, 2); 142 | } 143 | if (strlen($date) > 6) { 144 | $request['day'] = (int) substr($date, 6, 2); 145 | } 146 | $posts = $json_api->introspector->get_posts($request); 147 | } else { 148 | $json_api->error("Include 'date' var in your request."); 149 | } 150 | return $this->posts_result($posts); 151 | } 152 | 153 | public function get_category_posts() { 154 | global $json_api; 155 | $category = $json_api->introspector->get_current_category(); 156 | 157 | if (!$category) { 158 | $json_api->error("Not found."); 159 | } 160 | $posts = $json_api->introspector->get_posts(array( 161 | 'cat' => $category->id 162 | )); 163 | 164 | return $this->posts_object_result($posts, $category); 165 | } 166 | 167 | public function get_tag_posts() { 168 | global $json_api; 169 | $tag = $json_api->introspector->get_current_tag(); 170 | if (!$tag) { 171 | $json_api->error("Not found."); 172 | } 173 | $posts = $json_api->introspector->get_posts(array( 174 | 'tag' => $tag->slug 175 | )); 176 | return $this->posts_object_result($posts, $tag); 177 | } 178 | 179 | public function get_author_posts() { 180 | global $json_api; 181 | $author = $json_api->introspector->get_current_author(); 182 | if (!$author) { 183 | $json_api->error("Not found."); 184 | } 185 | $posts = $json_api->introspector->get_posts(array( 186 | 'author' => $author->id 187 | )); 188 | return $this->posts_object_result($posts, $author); 189 | } 190 | 191 | public function get_search_results() { 192 | global $json_api; 193 | if ($json_api->query->search) { 194 | $posts = $json_api->introspector->get_posts(array( 195 | 's' => $json_api->query->search 196 | )); 197 | } else { 198 | $json_api->error("Include 'search' var in your request."); 199 | } 200 | return $this->posts_result($posts); 201 | } 202 | 203 | public function get_date_index() { 204 | global $json_api; 205 | $permalinks = $json_api->introspector->get_date_archive_permalinks(); 206 | $tree = $json_api->introspector->get_date_archive_tree($permalinks); 207 | return array( 208 | 'permalinks' => $permalinks, 209 | 'tree' => $tree 210 | ); 211 | } 212 | 213 | public function get_category_index() { 214 | global $json_api; 215 | $args = null; 216 | if (!empty($json_api->query->parent)) { 217 | $args = array( 218 | 'parent' => $json_api->query->parent 219 | ); 220 | } 221 | $categories = $json_api->introspector->get_categories($args); 222 | return array( 223 | 'count' => count($categories), 224 | 'categories' => $categories 225 | ); 226 | } 227 | 228 | public function get_tag_index() { 229 | global $json_api; 230 | $tags = $json_api->introspector->get_tags(); 231 | return array( 232 | 'count' => count($tags), 233 | 'tags' => $tags 234 | ); 235 | } 236 | 237 | public function get_author_index() { 238 | global $json_api; 239 | $authors = $json_api->introspector->get_authors(); 240 | return array( 241 | 'count' => count($authors), 242 | 'authors' => array_values($authors) 243 | ); 244 | } 245 | 246 | public function get_page_index() { 247 | global $json_api; 248 | $pages = array(); 249 | $post_type = $json_api->query->post_type ? $json_api->query->post_type : 'page'; 250 | 251 | // Thanks to blinder for the fix! 252 | $numberposts = empty($json_api->query->count) ? -1 : $json_api->query->count; 253 | $wp_posts = get_posts(array( 254 | 'post_type' => $post_type, 255 | 'post_parent' => 0, 256 | 'order' => 'ASC', 257 | 'orderby' => 'menu_order', 258 | 'numberposts' => $numberposts 259 | )); 260 | foreach ($wp_posts as $wp_post) { 261 | $pages[] = new JSON_API_Post($wp_post); 262 | } 263 | foreach ($pages as $page) { 264 | $json_api->introspector->attach_child_posts($page); 265 | } 266 | return array( 267 | 'pages' => $pages 268 | ); 269 | } 270 | 271 | 272 | public function get_menu() { 273 | 274 | global $json_api; 275 | $menu = $json_api->introspector->get_menu(); 276 | return array( 277 | 'menu' => $menu 278 | ); 279 | 280 | } 281 | 282 | public function get_list_menu() { 283 | 284 | global $json_api; 285 | $menu = $json_api->introspector->get_list_menu(); 286 | return array( 287 | 'menus' => $menu 288 | ); 289 | 290 | } 291 | 292 | public function get_nonce() { 293 | global $json_api; 294 | extract($json_api->query->get(array('controller', 'method'))); 295 | if ($controller && $method) { 296 | $controller = strtolower($controller); 297 | if (!in_array($controller, $json_api->get_controllers())) { 298 | $json_api->error("Unknown controller '$controller'."); 299 | } 300 | require_once $json_api->controller_path($controller); 301 | if (!method_exists($json_api->controller_class($controller), $method)) { 302 | $json_api->error("Unknown method '$method'."); 303 | } 304 | $nonce_id = $json_api->get_nonce_id($controller, $method); 305 | return array( 306 | 'controller' => $controller, 307 | 'method' => $method, 308 | 'nonce' => wp_create_nonce($nonce_id) 309 | ); 310 | } else { 311 | $json_api->error("Include 'controller' and 'method' vars in your request."); 312 | } 313 | } 314 | 315 | protected function get_object_posts($object, $id_var, $slug_var) { 316 | global $json_api; 317 | $object_id = "{$type}_id"; 318 | $object_slug = "{$type}_slug"; 319 | extract($json_api->query->get(array('id', 'slug', $object_id, $object_slug))); 320 | if ($id || $$object_id) { 321 | if (!$id) { 322 | $id = $$object_id; 323 | } 324 | $posts = $json_api->introspector->get_posts(array( 325 | $id_var => $id 326 | )); 327 | } else if ($slug || $$object_slug) { 328 | if (!$slug) { 329 | $slug = $$object_slug; 330 | } 331 | $posts = $json_api->introspector->get_posts(array( 332 | $slug_var => $slug 333 | )); 334 | } else { 335 | $json_api->error("No $type specified. Include 'id' or 'slug' var in your request."); 336 | } 337 | return $posts; 338 | } 339 | 340 | protected function posts_result($posts) { 341 | global $wp_query; 342 | return array( 343 | 'count' => count($posts), 344 | 'count_total' => (int) $wp_query->found_posts, 345 | 'pages' => $wp_query->max_num_pages, 346 | 'posts' => $posts 347 | ); 348 | } 349 | 350 | protected function posts_object_result($posts, $object) { 351 | global $wp_query; 352 | // Convert something like "JSON_API_Category" into "category" 353 | $object_key = strtolower(substr(get_class($object), 9)); 354 | return array( 355 | 'count' => count($posts), 356 | 'pages' => (int) $wp_query->max_num_pages, 357 | $object_key => $object, 358 | 'posts' => $posts 359 | ); 360 | } 361 | 362 | } 363 | 364 | -------------------------------------------------------------------------------- /controllers/multisite.php: -------------------------------------------------------------------------------- 1 | _verify_admin(); 25 | 26 | extract($_REQUEST); 27 | 28 | if(!isset($blog_id)) 29 | $json_api->error(__("You must send the 'blog_id' parameter.")); 30 | 31 | if(!isset($key)) 32 | $json_api->error(__("You must send the 'key' parameter.")); 33 | 34 | if(isset($default)) 35 | $default = (strtolower($default) == 'false'); 36 | else 37 | $default = false; 38 | 39 | return array( "option" => get_blog_option($blog_id, $key, $default) ); 40 | } 41 | 42 | /** RESTful endpoint for this multisite function. 43 | * 44 | * Get $_REQUEST options for this endpoint: 45 | * 46 | * u (optional) -- Username (if not logged in) 47 | * p (optional) -- Password (if not logged in) 48 | * nonce (required) -- the security nonce for this API function 49 | * blog_id (required) if not set then current site id is used 50 | * key (required) key of the blog option to add 51 | * value (required) value of the blog option 52 | * 53 | * Returns Success message or error 54 | */ 55 | public function add_blog_option() { 56 | global $json_api; 57 | 58 | $this->_verify_admin(); 59 | $this->_verify_nonce('add_blog_option'); 60 | 61 | extract($_REQUEST); 62 | 63 | if(!isset($blog_id)) 64 | $json_api->error(__("You must send the 'blog_id' parameter.")); 65 | 66 | if(!isset($key)) 67 | $json_api->error(__("You must send the 'key' parameter.")); 68 | 69 | if(!isset($value)) 70 | $json_api->error(__("You must send the 'value' parameter.")); 71 | 72 | add_blog_option( $blog_id, $key, $value ); 73 | 74 | return array( "message" => __("You successfully added a blog option.") ); 75 | } 76 | 77 | /** RESTful endpoint for this multisite function. 78 | * 79 | * Get $_REQUEST options for this endpoint: 80 | * 81 | * u (optional) -- Username (if not logged in) 82 | * p (optional) -- Password (if not logged in) 83 | * nonce (required) -- the security nonce for this API function 84 | * blog_id (required) if not set then current site id is used 85 | * key (required) key of the blog option to update 86 | * value (required) value of the blog option 87 | * 88 | * Returns Success message or error 89 | */ 90 | public function update_blog_option() { 91 | global $json_api; 92 | 93 | $this->_verify_admin(); 94 | $this->_verify_nonce('update_blog_option'); 95 | 96 | extract($_REQUEST); 97 | 98 | if(!isset($blog_id)) 99 | $json_api->error(__("You must send the 'blog_id' parameter.")); 100 | 101 | if(!isset($key)) 102 | $json_api->error(__("You must send the 'key' parameter.")); 103 | 104 | if(!isset($value)) 105 | $json_api->error(__("You must send the 'value' parameter.")); 106 | 107 | update_blog_option( $blog_id, $key, $value ); 108 | 109 | return array( "message" => __("You successfully updated your blog option.") ); 110 | } 111 | 112 | /** RESTful endpoint for this multisite function. 113 | * 114 | * Get $_REQUEST options for this endpoint: 115 | * 116 | * u (optional) -- Username (if not logged in) 117 | * p (optional) -- Password (if not logged in) 118 | * nonce (required) -- the security nonce for this API function 119 | * blog_id (required) if not set then current site id is used 120 | * key (required) key of the blog option to delete 121 | * 122 | * Returns Success message or error 123 | */ 124 | public function delete_blog_option() { 125 | global $json_api; 126 | 127 | $this->_verify_admin(); 128 | $this->_verify_nonce('delete_blog_option'); 129 | 130 | extract($_REQUEST); 131 | 132 | if(!isset($blog_id)) 133 | $json_api->error(__("You must send the 'blog_id' parameter.")); 134 | 135 | if(!isset($key)) 136 | $json_api->error(__("You must send the 'key' parameter.")); 137 | 138 | delete_blog_option( $blog_id, $key ); 139 | 140 | return array( "message" => __("You successfully deleted your blog option.") ); 141 | } 142 | 143 | /** RESTful endpoint for this multisite function. 144 | * 145 | * Get $_REQUEST options for this endpoint: 146 | * 147 | * blog_id (required) blog id to retrieve address for 148 | * 149 | * Returns blogaddress or error 150 | */ 151 | public function get_blogaddress_by_id() { 152 | global $json_api; 153 | 154 | extract( $_REQUEST ); 155 | 156 | if(!isset($blog_id)) 157 | $json_api->error(__("You must send the 'blog_id' parameter.")); 158 | 159 | $blogaddress = get_blogaddress_by_id( $blog_id ); 160 | 161 | return array( "blogaddress" => $blogaddress ); 162 | } 163 | 164 | /** RESTful endpoint for this multisite function. 165 | * 166 | * Get $_REQUEST options for this endpoint: 167 | * 168 | * name (required) blog name retrieve address for 169 | * 170 | * Returns blogaddress or error 171 | */ 172 | public function get_blogaddress_by_name() { 173 | global $json_api; 174 | 175 | extract( $_REQUEST ); 176 | 177 | if(!isset($blogname)) 178 | $json_api->error(__("You must send the 'blogname' parameter.")); 179 | 180 | $blogaddress = get_blogaddress_by_name( $blogname ); 181 | 182 | return array( "blogaddress" => $blogaddress ); 183 | } 184 | 185 | /** RESTful endpoint for this multisite function. 186 | * 187 | * Get $_REQUEST options for this endpoint: 188 | * 189 | * u (optional) -- Username (if not logged in) 190 | * p (optional) -- Password (if not logged in) 191 | * name (required) blog name retrieve id for 192 | * 193 | * Returns blog_id or error 194 | */ 195 | public function get_id_from_blogname() { 196 | global $json_api; 197 | 198 | $this->_verify_admin(); 199 | 200 | extract( $_REQUEST ); 201 | 202 | if(!isset($blogname)) 203 | $json_api->error(__("You must send the 'blogname' parameter.")); 204 | 205 | $blog_id = get_id_from_blogname( $blogname ); 206 | 207 | return array( "blog_id" => $blog_id ); 208 | } 209 | 210 | /** RESTful endpoint for this multisite function. 211 | * 212 | * Get $_REQUEST options for this endpoint: 213 | * 214 | * u (optional) -- Username (if not logged in) 215 | * p (optional) -- Password (if not logged in) 216 | * blog_id (required) id of the blog to get 217 | * 218 | * Returns JSON array of blog details in the "blog" array index 219 | */ 220 | public function get_blog_details() { 221 | global $json_api; 222 | 223 | $this->_verify_admin(); 224 | 225 | extract( $_REQUEST ); 226 | 227 | if(!isset($blog_id)) 228 | $json_api->error(__("You must send the 'blog_id' parameter.")); 229 | 230 | return array( "blog" => get_blog_details( $blog_id ) ); 231 | } 232 | 233 | /** RESTful endpoint for this multisite function. 234 | * 235 | * Get $_REQUEST options for this endpoint: 236 | * 237 | * u (optional) -- Username (if not logged in) 238 | * p (optional) -- Password (if not logged in) 239 | * nonce (required) -- the security nonce for this API function 240 | * domain (required) full domain of the new blog 241 | * path (optional) path of the new blog - defaults to '/' 242 | * title (required) title of the new blog 243 | * user_id (required) id of an existing user to be the admin of the new blog 244 | * meta (optional) an array of meta data (defaults to '') 245 | * 246 | * Returns JSON array of blog details in the "blog" array index 247 | */ 248 | public function wpmu_create_blog() { 249 | global $json_api; 250 | 251 | $this->_verify_admin(); 252 | $this->_verify_nonce('wpmu_create_blog'); 253 | 254 | extract( $_REQUEST ); 255 | 256 | if(!isset($domain)) 257 | $json_api->error(__("You must send the 'domain' parameter.")); 258 | 259 | if(!isset($title)) 260 | $json_api->error(__("You must send the 'title' parameter.")); 261 | 262 | if(!isset($user_id)) 263 | $json_api->error(__("You must send the 'user_id' parameter.")); 264 | 265 | if(!isset($path)) 266 | $path = '/'; 267 | 268 | if(!isset($meta)) 269 | $meta = ''; 270 | 271 | $blog_id = wpmu_create_blog( $domain, $path, $title, $user_id, $meta ); 272 | 273 | if ( is_wp_error( $blog_id ) ) 274 | $json_api->error( $blog_id->get_error_message() ); 275 | else 276 | return array( "blog" => get_blog_details( $blog_id ) ); 277 | } 278 | 279 | /** RESTful endpoint for this multisite function. 280 | * 281 | * Get $_REQUEST options for this endpoint: 282 | * 283 | * u (optional) -- Username (if not logged in) 284 | * p (optional) -- Password (if not logged in) 285 | * nonce (required) -- the security nonce for this API function 286 | * blog_id (required) Blog ID of the blog we're going to delete 287 | * drop (optional) Drop tables for this blog (defaults to false) 288 | * 289 | * Returns message of success or error 290 | */ 291 | public function wpmu_delete_blog() { 292 | global $json_api; 293 | 294 | $this->_verify_admin(); 295 | $this->_verify_nonce('wpmu_delete_blog'); 296 | 297 | extract( $_REQUEST ); 298 | 299 | if(!isset($blog_id)) 300 | $json_api->error(__("You must send the 'blog_id' parameter.")); 301 | 302 | if(!isset($drop)) 303 | $drop = false; 304 | else 305 | $drop = ($drop=='true'); 306 | 307 | if( !function_exists('wpmu_delete_blog') ) 308 | require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 309 | 310 | wpmu_delete_blog( $blog_id, $drop ); 311 | 312 | return array( "message" => __( "The Blog was Successfully Deleted." ) ); 313 | } 314 | 315 | /** RESTful endpoint for this multisite function. 316 | * 317 | * Get $_REQUEST options for this endpoint: 318 | * 319 | * u (optional) -- Username (if not logged in) 320 | * p (optional) -- Password (if not logged in) 321 | * nonce (required) -- the security nonce for this API function 322 | * blog_id (required) blog we'll be adding the user to 323 | * user_id (required) user we'll be adding to the blog 324 | * role (optional) role of the user on the new blog (defaults to 'subscriber') 325 | * 326 | * Returns Success message or error 327 | */ 328 | public function add_user_to_blog() { 329 | global $json_api; 330 | 331 | $this->_verify_admin(); 332 | $this->_verify_nonce('add_user_to_blog'); 333 | 334 | extract($_REQUEST); 335 | 336 | if(!isset($blog_id)) 337 | $json_api->error(__("You must send the 'blog_id' parameter.")); 338 | 339 | if(!isset($user_id)) 340 | $json_api->error(__("You must send the 'user_id' parameter.")); 341 | 342 | if(!isset($role)) 343 | $role = 'subscriber'; 344 | 345 | if( $returnval = add_user_to_blog( $blog_id, $user_id, $role ) ) 346 | return array( "message" => __("User was successfully added to the blog.") ); 347 | else 348 | { 349 | if(is_wp_error($returnval)) 350 | $json_api->error( $returnval->get_error_message() ); 351 | else 352 | $json_api->error( __("There was an error adding this user to your blog") ); 353 | } 354 | } 355 | 356 | /** RESTful endpoint for this multisite function. 357 | * 358 | * Get $_REQUEST options for this endpoint: 359 | * 360 | * u (optional) -- Username (if not logged in) 361 | * p (optional) -- Password (if not logged in) 362 | * nonce (required) -- the security nonce for this API function 363 | * user_id (required) user we'll be removing from the blog 364 | * blog_id (required) blog we'll be removing the user from 365 | * reassign (optional) user we'll be reassigning posts to (defaults to '') 366 | * 367 | */ 368 | public function remove_user_from_blog() { 369 | global $json_api; 370 | 371 | $this->_verify_admin(); 372 | $this->_verify_nonce('remove_user_from_blog'); 373 | 374 | extract($_REQUEST); 375 | 376 | if(!isset($blog_id)) 377 | $json_api->error(__("You must send the 'blog_id' parameter.")); 378 | 379 | if(!isset($user_id)) 380 | $json_api->error(__("You must send the 'user_id' parameter.")); 381 | 382 | if(!isset($reassign)) 383 | $reassign = ''; 384 | 385 | $returnval = remove_user_from_blog( $user_id, $blog_id, $reassign ); 386 | 387 | if( is_wp_error($returnval) ) 388 | $json_api->error( $returnval->get_error_message() ); 389 | else 390 | return array( "message" => __( "User was successfully removed from the blog." ) ); 391 | } 392 | 393 | /** RESTful endpoint for this multisite function. 394 | * 395 | * Get $_REQUEST options for this endpoint: 396 | * 397 | * u (optional) -- Username (if not logged in) 398 | * p (optional) -- Password (if not logged in) 399 | * domain (required) full domain of site we're checking on 400 | * path (required) path of the site we're checking on 401 | * site_id (optional) site id of the blog (defaults to 1) 402 | * 403 | */ 404 | public function domain_exists() { 405 | global $json_api; 406 | 407 | $this->_verify_admin(); 408 | 409 | extract($_REQUEST); 410 | 411 | if(!isset($domain)) 412 | $json_api->error(__("You must send the 'domain' parameter.")); 413 | 414 | if(!isset($path)) 415 | $json_api->error(__("You must send the 'path' parameter.")); 416 | 417 | if(!isset($site_id)) 418 | $site_id = 1; 419 | 420 | if( domain_exists( $domain, $path, $site_id ) ) 421 | return array( "message" => __("The Domain Exists.") ); 422 | else 423 | return array( "message" => __("The Domain Does Not Exist.") ); 424 | } 425 | 426 | /** RESTful endpoint for this multisite function. 427 | * 428 | * Get $_REQUEST options for this endpoint: 429 | * 430 | * u (optional) -- Username (if not logged in) 431 | * p (optional) -- Password (if not logged in) 432 | * user_id (required) User we want the active blog for 433 | * 434 | * Return blog or error 435 | */ 436 | public function get_active_blog_for_user() { 437 | global $json_api; 438 | 439 | $this->_verify_admin(); 440 | 441 | extract($_REQUEST); 442 | 443 | if(!isset($user_id)) 444 | $json_api->error(__("You must send the 'user_id' parameter.")); 445 | 446 | if( $blog = get_active_blog_for_user( $user_id ) ) 447 | return array( "blog" => $blog ); 448 | else 449 | $json_api->error(__("Active blog was not found.")); 450 | } 451 | 452 | /** RESTful endpoint for this multisite function. 453 | * 454 | * Get $_REQUEST options for this endpoint: 455 | * 456 | * u (optional) -- Username (if not logged in) 457 | * p (optional) -- Password (if not logged in) 458 | * user_id (required) User we want to list the blogs for 459 | * all (optional) Get all blogs (defaults to false) 460 | * 461 | * Return blogs or error 462 | */ 463 | public function get_blogs_of_user() { 464 | global $json_api; 465 | 466 | $this->_verify_admin(); 467 | 468 | extract( $_REQUEST ); 469 | 470 | if( !isset( $user_id ) ) 471 | $json_api->error(__("You must send the 'user_id' parameter.")); 472 | 473 | if(!isset($all)) 474 | $all = false; 475 | else 476 | $all = ($all=='true'); 477 | 478 | if( $blogs = get_blogs_of_user( $user_id ) ) 479 | return array( "blogs" => $blogs ); 480 | else 481 | $json_api->error(__("No blogs were found for this user.")); 482 | } 483 | 484 | /** RESTful endpoint for this multisite function. 485 | * 486 | * Get $_REQUEST options for this endpoint: 487 | * 488 | * u (optional) -- Username (if not logged in) 489 | * p (optional) -- Password (if not logged in) 490 | * domain (required) full domain we want the blog id for 491 | * path (optional) path we want the blog id for (defaults to '/') 492 | * 493 | */ 494 | public function get_blog_id_from_url() { 495 | global $json_api; 496 | 497 | $this->_verify_admin(); 498 | 499 | extract($_REQUEST); 500 | 501 | if(!isset($domain)) 502 | $json_api->error(__("You must send the 'domain' parameter.")); 503 | 504 | if(!isset($path)) 505 | $path = '/'; 506 | 507 | if( $blog_id = get_blog_id_from_url( $domain, $path ) ) 508 | return array( "blog_id" => $blog_id ); 509 | else 510 | $json_api->error(__("No blogs were found for this user.")); 511 | } 512 | 513 | /** RESTful endpoint for this multisite function. 514 | * 515 | * Get $_REQUEST options for this endpoint: 516 | * 517 | * u (optional) -- Username (if not logged in) 518 | * p (optional) -- Password (if not logged in) 519 | * 520 | */ 521 | public function is_subdomain_install() { 522 | global $json_api; 523 | 524 | $this->_verify_admin(); 525 | 526 | extract($_REQUEST); 527 | 528 | if( is_subdomain_install() ) 529 | return array( "message" => __("This is a subdomain install.") ); 530 | else 531 | return array( "message" => __("This is not a subdomain install.") ); 532 | } 533 | 534 | private function _verify_nonce($method) { 535 | global $json_api; 536 | 537 | if (!$json_api->query->nonce) 538 | $json_api->error(__("You must include a 'nonce' value to update users. Use the `get_nonce` Core API method.")); 539 | 540 | $nonce_id = $json_api->get_nonce_id('multisite', $method); 541 | 542 | if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) 543 | $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); 544 | } 545 | 546 | private function _verify_admin() { 547 | global $json_api; 548 | 549 | extract($_REQUEST); 550 | 551 | if (!current_user_can('administrator')) 552 | { 553 | if( isset($u) and isset($p) ) { 554 | if( !user_pass_ok($u, $p) ) 555 | $json_api->error(__("Your username or password was incorrect.")); 556 | } 557 | else 558 | $json_api->error(__("You must either provide the 'u' and 'p' parameters or login as an administrator.")); 559 | } 560 | } 561 | } 562 | 563 | ?> 564 | -------------------------------------------------------------------------------- /controllers/posts.php: -------------------------------------------------------------------------------- 1 | error("You need to login with a user that has 'edit_posts' capacity."); 13 | } 14 | if (!$json_api->query->nonce) { 15 | $json_api->error("You must include a 'nonce' value to create posts. Use the `get_nonce` Core API method."); 16 | } 17 | $nonce_id = $json_api->get_nonce_id('posts', 'create_post'); 18 | if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) { 19 | $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); 20 | } 21 | nocache_headers(); 22 | $post = new JSON_API_Post(); 23 | $id = $post->create($_REQUEST); 24 | if (empty($id)) { 25 | $json_api->error("Could not create post."); 26 | } 27 | return array( 28 | 'post' => $post 29 | ); 30 | } 31 | 32 | public function update_post() { 33 | global $json_api; 34 | $post = $json_api->introspector->get_current_post(); 35 | if (empty($post)) { 36 | $json_api->error("Post not found."); 37 | } 38 | if (!current_user_can('edit_post', $post->ID)) { 39 | $json_api->error("You need to login with a user that has the 'edit_post' capacity for that post."); 40 | } 41 | if (!$json_api->query->nonce) { 42 | $json_api->error("You must include a 'nonce' value to update posts. Use the `get_nonce` Core API method."); 43 | } 44 | $nonce_id = $json_api->get_nonce_id('posts', 'update_post'); 45 | if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) { 46 | $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); 47 | } 48 | nocache_headers(); 49 | $post = new JSON_API_Post($post); 50 | $post->update($_REQUEST); 51 | return array( 52 | 'post' => $post 53 | ); 54 | } 55 | 56 | public function delete_post() { 57 | global $json_api; 58 | $post = $json_api->introspector->get_current_post(); 59 | if (empty($post)) { 60 | $json_api->error("Post not found."); 61 | } 62 | if (!current_user_can('edit_post', $post->ID)) { 63 | $json_api->error("You need to login with a user that has the 'edit_post' capacity for that post."); 64 | } 65 | if (!current_user_can('delete_posts')) { 66 | $json_api->error("You need to login with a user that has the 'delete_posts' capacity."); 67 | } 68 | if ($post->post_author != get_current_user_id() && !current_user_can('delete_other_posts')) { 69 | $json_api->error("You need to login with a user that has the 'delete_other_posts' capacity."); 70 | } 71 | if (!$json_api->query->nonce) { 72 | $json_api->error("You must include a 'nonce' value to update posts. Use the `get_nonce` Core API method."); 73 | } 74 | $nonce_id = $json_api->get_nonce_id('posts', 'delete_post'); 75 | if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) { 76 | $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); 77 | } 78 | nocache_headers(); 79 | wp_delete_post($post->ID); 80 | return array(); 81 | } 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /controllers/respond.php: -------------------------------------------------------------------------------- 1 | error("No post specified. Include 'post_id' var in your request."); 14 | } else if (empty($_REQUEST['name']) || 15 | empty($_REQUEST['email']) || 16 | empty($_REQUEST['content'])) { 17 | $json_api->error("Please include all required arguments (name, email, content)."); 18 | } else if (!is_email($_REQUEST['email'])) { 19 | $json_api->error("Please enter a valid email address."); 20 | } 21 | $pending = new JSON_API_Comment(); 22 | return $pending->handle_submission(); 23 | } 24 | 25 | 26 | public function register_typeform(){ 27 | 28 | global $json_api, $WishListMemberInstance; 29 | 30 | $inputJSON = file_get_contents('php://input'); 31 | $json_input= json_decode( $inputJSON, TRUE ); //convert JSON into array 32 | $data_array = $json_input; 33 | 34 | 35 | //echo '
';
 36 | //print_r($data_array['form_response']['definition']['fields']);
 37 | //echo '
'; 38 | 39 | //echo '
';
 40 | //print_r($data_array['form_response']['answers']);
 41 | //echo '
'; 42 | 43 | 44 | 45 | foreach($data_array['form_response']['answers'] as $k){ 46 | 47 | if($k['field']['id']==56083034) $username= sanitize_user( strtolower(str_replace(' ', '.', $k['text']))); 48 | elseif($k['field']['id']==56083040) $email= sanitize_email($k['email']); 49 | 50 | } 51 | 52 | 53 | 54 | while(username_exists($username)){ 55 | $i++; 56 | $username = $username.'.'.$i; 57 | 58 | } 59 | 60 | if ($json_api->query->display_name) $display_name = sanitize_text_field( $json_api->query->display_name ); 61 | 62 | $user_pass = sanitize_text_field( $_REQUEST['user_pass'] ); 63 | 64 | //Add usernames we don't want used 65 | 66 | $invalid_usernames = array( 'admin' ); 67 | 68 | //Do username validation 69 | 70 | if ( !validate_username( $username ) || in_array( $username, $invalid_usernames ) ) { 71 | 72 | $json_api->error("Username is invalid."); 73 | 74 | } 75 | 76 | elseif ( username_exists( $username ) ) { 77 | 78 | $json_api->error("Username already exists."); 79 | 80 | } 81 | 82 | else{ 83 | 84 | 85 | if ( !is_email( $email ) ) { 86 | $json_api->error("E-mail address is invalid."); 87 | } 88 | elseif (email_exists($email)) { 89 | 90 | $json_api->error("E-mail address is already in use."); 91 | 92 | } 93 | 94 | else { 95 | 96 | //Everything has been validated, proceed with creating the user 97 | 98 | //Create the user 99 | 100 | if( !isset($_REQUEST['user_pass']) ) { 101 | $user_pass = wp_generate_password(); 102 | $_REQUEST['user_pass'] = $user_pass; 103 | } 104 | 105 | $_REQUEST['user_login'] = $username; 106 | $_REQUEST['user_email'] = $email; 107 | 108 | $allowed_params = array('user_login', 'user_email', 'user_pass', 'display_name', 'user_nicename', 'user_url', 'nickname', 'first_name', 109 | 'last_name', 'description', 'rich_editing', 'user_registered', 'jabber', 'aim', 'yim', 110 | 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' 111 | ); 112 | 113 | 114 | foreach($_REQUEST as $field => $value){ 115 | 116 | if( in_array($field, $allowed_params) ) $user[$field] = trim(sanitize_text_field($value)); 117 | 118 | } 119 | 120 | 121 | //$user_id = wp_insert_user( $user ); 122 | $user_id = register_new_user( $username, $email ); 123 | 124 | /* 125 | if( isset($_REQUEST['user_pass']) && $_REQUEST['notify']=='no') { 126 | $notify = ''; 127 | }elseif($_REQUEST['notify']!='no') $notify = $_REQUEST['notify']; 128 | 129 | */ 130 | //if($user_id) wp_new_user_notification( $user_id, '',$notify ); 131 | 132 | } 133 | } 134 | 135 | if($user_id && $reference) update_user_meta( $user_id, 'reference', $reference); 136 | 137 | 138 | $expiration = time() + apply_filters('auth_cookie_expiration', 1209600, $user_id, true); 139 | 140 | $cookie = wp_generate_auth_cookie($user_id, $expiration, 'logged_in'); 141 | 142 | return array( 143 | "cookie" => $cookie, 144 | "user_id" => $user_id 145 | ); 146 | 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /controllers/users.php: -------------------------------------------------------------------------------- 1 | error("You need to pass a value for 'user_login'."); 25 | 26 | if(!isset($_REQUEST['user_password'])) 27 | $json_api->error("You need to pass a value for 'user_password'."); 28 | 29 | if(!function_exists('wp_signon')) 30 | require_once(ABSPATH . WPINC . '/user.php'); 31 | 32 | $user = wp_signon( $_REQUEST, false ); 33 | if ( is_wp_error( $user ) ) 34 | $json_api->error( $user->get_error_message() ); 35 | 36 | return array( "message" => "Successfully Logged In" ); 37 | } 38 | 39 | /** API function provide a silent login feature for WordPress. 40 | * Since this method alters the session it won't work unless the 41 | * user is actually running this script from their browser ... as 42 | * opposed to a server site GET or POST call. 43 | * 44 | * Doesn't need any parameters via GET or POST to successfully run. 45 | * 46 | */ 47 | public function logout() { 48 | if(!function_exists('wp_logout')) 49 | require_once(ABSPATH . WPINC . '/pluggable.php'); 50 | 51 | wp_logout(); 52 | 53 | return array( "message" => "Successfully Logged Out"); 54 | } 55 | 56 | /** API function provide a way to programmatically check to see 57 | * if a user is currently logged in and returns the user id. 58 | * 59 | * Doesn't need any parameters via GET or POST to successfully run. 60 | * 61 | */ 62 | public function is_user_logged_in() { 63 | if(!function_exists('is_user_logged_in')) 64 | require_once(ABSPATH . WPINC . '/pluggable.php'); 65 | 66 | if ( is_user_logged_in() ) { 67 | global $current_user; 68 | 69 | @get_currentuserinfo(); 70 | 71 | if( 72 | WP_DEBUG 73 | && empty($current_user) 74 | && function_exists('error_get_last') 75 | ) 76 | { 77 | $error = error_get_last(); 78 | 79 | if( 80 | isset($error['message']) 81 | && stripos($error['message'], 'get_currentuserinfo') !== false 82 | && stripos($error['message'], 'wp_get_current_user()') !== false 83 | && function_exists('wp_get_current_user') 84 | ) 85 | { 86 | wp_get_current_user(); 87 | } 88 | } 89 | 90 | return array( "user" => $current_user ); 91 | } else { 92 | global $json_api; 93 | $json_api->error(__("No WordPress Users are logged in.")); 94 | } 95 | } 96 | 97 | /** API function to Create a User for WordPress 98 | * 99 | * Accepts the following parameters via GET or POST: 100 | * 101 | * nonce (required) -- the security nonce for this API function 102 | * user_login (required) -- the username of the new user 103 | * user_password (required) -- the password of the new user 104 | * user_email (required) -- the email of the new user 105 | * user_nicename (optional) 106 | * user_url (optional) 107 | * display_name (optional) 108 | * nickname (optional) 109 | * first_name (optional) 110 | * last_name (optional) 111 | * description (optional) 112 | * rich_editing (optional) 113 | * user_registered (optional) 114 | * role (optional) 115 | * jabber (optional) 116 | * aim (optional) 117 | * yim (optional) 118 | * 119 | */ 120 | public function create_user() { 121 | global $json_api; 122 | 123 | $this->_verify_admin(); 124 | 125 | $updating = (isset($_REQUEST['id'])); 126 | 127 | // Only Require these if we're updating 128 | if(!$updating) { 129 | if(!isset($_REQUEST['user_login'])) 130 | $json_api->error("You need to pass a value for 'user_login'."); 131 | 132 | if(!isset($_REQUEST['user_password'])) 133 | $json_api->error("You need to pass a value for 'user_password'."); 134 | 135 | if(!isset($_REQUEST['user_email'])) 136 | $json_api->error("You need to pass a value for 'user_email'."); 137 | 138 | if( email_exists( $_REQUEST[ 'user_email' ] ) ) 139 | $json_api->error(__("This email address already exists")); 140 | 141 | $this->_verify_nonce('create_user'); 142 | } 143 | else 144 | $this->_verify_nonce('update_user'); 145 | 146 | nocache_headers(); 147 | 148 | @require_once(ABSPATH . WPINC . '/registration.php'); 149 | 150 | if(isset($_REQUEST['user_password'])) 151 | $password = $_REQUEST['user_password']; 152 | else 153 | $password = wp_generate_password( 12, false ); 154 | 155 | $userdata = array( "user_pass" => $password, 156 | "user_login" => $_REQUEST['user_login'], 157 | "user_email" => $_REQUEST['user_email'] ); 158 | 159 | if($updating and isset($_REQUEST['id'])) 160 | $userdata['ID'] = $_REQUEST['id']; 161 | 162 | if(isset($_REQUEST['user_nicename'])) 163 | $userdata['user_nicename'] = $_REQUEST['user_nicename']; 164 | 165 | if(isset($_REQUEST['user_url'])) 166 | $userdata['user_url'] = $_REQUEST['user_url']; 167 | 168 | if(isset($_REQUEST['display_name'])) 169 | $userdata['display_name'] = $_REQUEST['display_name']; 170 | 171 | if(isset($_REQUEST['nickname'])) 172 | $userdata['nickname'] = $_REQUEST['nickname']; 173 | 174 | if(isset($_REQUEST['first_name'])) 175 | $userdata['first_name'] = $_REQUEST['first_name']; 176 | 177 | if(isset($_REQUEST['last_name'])) 178 | $userdata['last_name'] = $_REQUEST['last_name']; 179 | 180 | if(isset($_REQUEST['description'])) 181 | $userdata['description'] = $_REQUEST['description']; 182 | 183 | if(isset($_REQUEST['rich_editing'])) 184 | $userdata['rich_editing'] = $_REQUEST['rich_editing']; 185 | 186 | if(isset($_REQUEST['user_registered'])) 187 | $userdata['user_registered'] = $_REQUEST['user_registered']; 188 | 189 | if(isset($_REQUEST['role'])) 190 | $userdata['role'] = $_REQUEST['role']; 191 | 192 | if(isset($_REQUEST['jabber'])) 193 | $userdata['jabber'] = $_REQUEST['jabber']; 194 | 195 | if(isset($_REQUEST['aim'])) 196 | $userdata['aim'] = $_REQUEST['aim']; 197 | 198 | if(isset($_REQUEST['yim'])) 199 | $userdata['yim'] = $_REQUEST['yim']; 200 | 201 | if($updating) 202 | $user_id = wp_update_user( $userdata ); 203 | else 204 | $user_id = wp_insert_user( $userdata ); 205 | 206 | if($updating) 207 | $user_id = $_REQUEST['id']; 208 | 209 | if (empty($user_id)) 210 | $json_api->error(__("Could not create user.")); 211 | 212 | $user = get_userdata($user_id); 213 | 214 | return array( 'user' => $user ); 215 | } 216 | 217 | /** API function to Add User Meta for WordPress 218 | * 219 | * Accepts the following parameters via GET or POST: 220 | * 221 | * nonce (required) -- the security nonce for this API function 222 | * id (required) -- id of the user you're adding meta to 223 | * key (required) -- key of the user meta you're adding 224 | * value (required) -- value of the user meta 225 | * unique (optional) -- delete other values for this user meta so this entry is unique 226 | * 227 | */ 228 | public function add_user_meta() { 229 | global $json_api; 230 | 231 | $this->_verify_admin(); 232 | $this->_verify_nonce('add_user_meta'); 233 | 234 | nocache_headers(); 235 | 236 | if(!isset($_REQUEST['id'])) 237 | $json_api->error(__("The user's 'id' must be set.")); 238 | 239 | if(!isset($_REQUEST['key'])) 240 | $json_api->error(__("The 'key' must be set.")); 241 | 242 | if(!isset($_REQUEST['value'])) 243 | $json_api->error(__("The 'value' must be set.")); 244 | 245 | if(!isset($_REQUEST['unique'])) 246 | $unique = false; 247 | else 248 | $unique = ($_REQUEST['unique'] == 'true'); 249 | 250 | if( add_user_meta( $_REQUEST['id'], $_REQUEST['key'], $_REQUEST['value'], $unique ) ) 251 | return array( "message" => __("User meta was added successfully.") ); 252 | else 253 | $json_api->error( __("User meta wasn't able to be added.") ); 254 | } 255 | 256 | /** API function to Update a User for WordPress. 257 | * 258 | * Accepts the following parameters via GET or POST: 259 | * 260 | * nonce (required) -- the security nonce for this API function 261 | * id (required) -- id of the user you're updating a user 262 | * user_login (optional) -- the username of the new user 263 | * user_password (optional) -- the password of the new user 264 | * user_email (optional) -- the email of the new user 265 | * user_nicename (optional) 266 | * user_url (optional) 267 | * display_name (optional) 268 | * nickname (optional) 269 | * first_name (optional) 270 | * last_name (optional) 271 | * description (optional) 272 | * rich_editing (optional) 273 | * user_registered (optional) 274 | * role (optional) 275 | * jabber (optional) 276 | * aim (optional) 277 | * yim (optional) 278 | * 279 | */ 280 | public function update_user() { 281 | global $json_api; 282 | 283 | if(!isset($_REQUEST['id'])) 284 | $json_api->error(__("The user's 'id' must be set.")); 285 | 286 | return $this->create_user(); 287 | } 288 | 289 | /** API function to Update User Meta for WordPress. 290 | * 291 | * Accepts the following parameters via GET or POST: 292 | * 293 | * nonce (required) -- the security nonce for this API function 294 | * id (required) -- id of the user you're updating meta for 295 | * key (required) -- key of the user meta you're adding 296 | * value (required) -- value of the user meta 297 | * prev_value (optional) -- Previous value to replace 298 | * 299 | */ 300 | public function update_user_meta() { 301 | global $json_api; 302 | 303 | $this->_verify_admin(); 304 | $this->_verify_nonce('update_user_meta'); 305 | 306 | nocache_headers(); 307 | 308 | if(!isset($_REQUEST['id'])) 309 | $json_api->error(__("The user's 'id' must be set.")); 310 | 311 | if(!isset($_REQUEST['key'])) 312 | $json_api->error(__("The 'key' must be set.")); 313 | 314 | if(!isset($_REQUEST['value'])) 315 | $json_api->error(__("The 'value' must be set.")); 316 | 317 | if(!isset($_REQUEST['prev_value'])) 318 | $prev_value = ''; 319 | else 320 | $prev_value = $_REQUEST['prev_value']; 321 | 322 | if( update_user_meta( $_REQUEST['id'], $_REQUEST['key'], $_REQUEST['value'], $prev_value ) ) 323 | return array( "message" => __("User meta was updated successfully.") ); 324 | else 325 | $json_api->error( __("User meta wasn't able to be updated.") ); 326 | } 327 | 328 | /** API function to Delete a User for WordPress. 329 | * 330 | * Accepts the following parameters via GET or POST: 331 | * 332 | * nonce (required) -- the security nonce for this API function 333 | * id (required) -- id of the user you're updating a user 334 | * reassign (optional) -- the id of the user to reassign posts to -- defaults to admin's id 335 | * 336 | */ 337 | public function delete_user() { 338 | global $json_api; 339 | 340 | $this->_verify_admin(); 341 | $this->_verify_nonce('delete_user'); 342 | 343 | nocache_headers(); 344 | 345 | if(!isset($_REQUEST['id'])) 346 | $json_api->error(__("The user's 'id' must be set.")); 347 | 348 | if(!isset($_REQUEST['reassign'])) 349 | { 350 | $admin_email = get_option('admin_email'); 351 | 352 | @require_once(ABSPATH . WPINC . '/registration.php'); 353 | 354 | $reassign = email_exists($admin_email); 355 | } 356 | else 357 | $reassign = $_REQUEST['reassign']; 358 | 359 | if(!function_exists('wp_delete_user')) 360 | require_once(ABSPATH . 'wp-admin/includes/user.php'); 361 | 362 | if( wp_delete_user( (int)$_REQUEST['id'], (int)$reassign ) ) 363 | return array( "message" => __("User deleted successfully.") ); 364 | else 365 | $json_api->error( __("User wasn't able to be deleted.") ); 366 | } 367 | 368 | /** API function to Delete a User Meta for WordPress 369 | * 370 | * Accepts the following parameters via GET or POST: 371 | * 372 | * nonce (required) -- the security nonce for this API function 373 | * id (required) -- id of the user you're deleting meta for 374 | * key (required) -- key of the user meta you're deleting 375 | * value (optional) -- meta value to delete 376 | * 377 | */ 378 | public function delete_user_meta() { 379 | global $json_api; 380 | 381 | $this->_verify_admin(); 382 | $this->_verify_nonce('delete_user_meta'); 383 | 384 | nocache_headers(); 385 | 386 | if(!isset($_REQUEST['id'])) 387 | $json_api->error(__("The user's 'id' must be set.")); 388 | 389 | if(!isset($_REQUEST['key'])) 390 | $json_api->error(__("The 'key' must be set.")); 391 | 392 | if(!isset($_REQUEST['value'])) 393 | $value = ''; 394 | else 395 | $value = $_REQUEST['value']; 396 | 397 | if( delete_user_meta( $_REQUEST['id'], $_REQUEST['key'], $value ) ) 398 | return array( "message" => __("User meta was deleted successfully.") ); 399 | else 400 | $json_api->error( __("User meta wasn't able to be deleted.") ); 401 | } 402 | 403 | /** API function to Get Userdata for WordPress 404 | * 405 | * Accepts the following parameters via GET or POST: 406 | * 407 | * id (required) -- id of the user you're getting userdata for 408 | * 409 | */ 410 | public function get_userdata() { 411 | global $json_api; 412 | 413 | $this->_verify_admin(); 414 | 415 | if(!isset($_REQUEST['id'])) 416 | $json_api->error(__("The user's 'id' must be set.")); 417 | 418 | $userdata = get_userdata( $_REQUEST['id'] ); 419 | 420 | if(!$userdata) 421 | $json_api->error(__("User was not found.")); 422 | else 423 | return array( "user" => $userdata ); 424 | } 425 | 426 | /** API function to Get User Meta for WordPress. 427 | * 428 | * Accepts the following parameters via GET or POST: 429 | * 430 | * id (required) -- id of the user you're getting user_meta from 431 | * key (required) -- key of the user_meta your retrieving 432 | * single (optional) -- return one value -- defaults to false 433 | * 434 | */ 435 | public function get_user_meta() { 436 | global $json_api; 437 | 438 | $this->_verify_admin(); 439 | 440 | if(!isset($_REQUEST['id'])) 441 | $json_api->error(__("The user's 'id' must be set.")); 442 | 443 | if(!isset($_REQUEST['key'])) 444 | $json_api->error(__("The 'key' must be set.")); 445 | 446 | $single = ( $_REQUEST['single'] == 'true' ); 447 | 448 | $usermeta = get_user_meta( $_REQUEST['id'], $_REQUEST['key'], $single ); 449 | 450 | if(!$usermeta) 451 | $json_api->error( "'" . $_REQUEST['key'] . "' " . __("was not found.")); 452 | else 453 | return array( 'usermeta' => $usermeta ); 454 | } 455 | 456 | /** API function to Get Users for WordPress. 457 | * Doesn't require any GET or POST parameters. 458 | */ 459 | public function get_users() { 460 | global $json_api; 461 | 462 | $this->_verify_admin(); 463 | 464 | $blogusers = @get_users_of_blog(); 465 | 466 | if( 467 | WP_DEBUG 468 | && empty($blogusers) 469 | && function_exists('error_get_last') 470 | ) 471 | { 472 | $error = error_get_last(); 473 | 474 | if( 475 | isset($error['message']) 476 | && stripos($error['message'], 'get_users_of_blog') !== false 477 | && stripos($error['message'], 'get_users()') !== false 478 | && function_exists('get_users') 479 | ) 480 | { 481 | $blogusers = get_users(); 482 | } 483 | } 484 | 485 | return $blogusers; 486 | } 487 | 488 | private function _verify_nonce($method) 489 | { 490 | global $json_api; 491 | 492 | if (!$json_api->query->nonce) 493 | $json_api->error(__("You must include a 'nonce' value to update users. Use the `get_nonce` Core API method.")); 494 | 495 | $nonce_id = $json_api->get_nonce_id('users', $method); 496 | 497 | if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) 498 | $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method."); 499 | } 500 | 501 | private function _verify_admin() 502 | { 503 | global $json_api; 504 | 505 | extract($_REQUEST); 506 | 507 | if (!current_user_can('administrator')) 508 | { 509 | if( isset($u) and isset($p) ) 510 | { 511 | if( !@user_pass_ok($u, $p) ) 512 | { 513 | $json_api->error(__("Your username or password was incorrect.")); 514 | } 515 | 516 | if( 517 | WP_DEBUG 518 | && function_exists('error_get_last') 519 | ) 520 | { 521 | $error = error_get_last(); 522 | 523 | if( 524 | isset($error['message']) 525 | && stripos($error['message'], 'user_pass_ok') !== false 526 | && stripos($error['message'], 'wp_authenticate()') !== false 527 | && function_exists('wp_authenticate') 528 | ) 529 | { 530 | if(!wp_authenticate($u, $p)) 531 | { 532 | $json_api->error(__("Your username or password was incorrect.")); 533 | } 534 | } 535 | } 536 | } 537 | else 538 | $json_api->error(__("You must either provide the 'u' and 'p' parameters or login as an administrator.")); 539 | } 540 | } 541 | } 542 | 543 | ?> 544 | -------------------------------------------------------------------------------- /controllers/widgets.php: -------------------------------------------------------------------------------- 1 | error("No sidebar specified. Include 'sidebar_id' var in your request."); 14 | } else if (!is_active_sidebar($index)) { 15 | $json_api->error("Sidebar '$index' is not active."); 16 | } 17 | 18 | $widget_params = array( 19 | 'before_widget', 20 | 'after_widget', 21 | 'before_title', 22 | 'after_title' 23 | ); 24 | $json_api_params = array(); 25 | foreach ($widget_params as $param) { 26 | if (isset($_REQUEST[$param])) { 27 | $json_api_params[$param] = $_REQUEST[$param]; 28 | } 29 | } 30 | 31 | $widgets = array(); 32 | 33 | global $wp_registered_sidebars, $wp_registered_widgets; 34 | 35 | if ( is_int($index) ) { 36 | $index = "sidebar-$index"; 37 | } else { 38 | $index = sanitize_title($index); 39 | foreach ( (array) $wp_registered_sidebars as $key => $value ) { 40 | if ( sanitize_title($value['name']) == $index ) { 41 | $index = $key; 42 | break; 43 | } 44 | } 45 | } 46 | 47 | $sidebars_widgets = wp_get_sidebars_widgets(); 48 | 49 | if ( empty($wp_registered_sidebars[$index]) || !array_key_exists($index, $sidebars_widgets) || !is_array($sidebars_widgets[$index]) || empty($sidebars_widgets[$index]) ) 50 | return false; 51 | 52 | $sidebar = $wp_registered_sidebars[$index]; 53 | 54 | $did_one = false; 55 | foreach ( (array) $sidebars_widgets[$index] as $id ) { 56 | 57 | if ( !isset($wp_registered_widgets[$id]) ) continue; 58 | 59 | $params = array_merge( 60 | array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']), $json_api_params ) ), 61 | (array) $wp_registered_widgets[$id]['params'] 62 | ); 63 | 64 | 65 | // Substitute HTML id and class attributes into before_widget 66 | $classname_ = ''; 67 | foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) { 68 | if ( is_string($cn) ) 69 | $classname_ .= '_' . $cn; 70 | elseif ( is_object($cn) ) 71 | $classname_ .= '_' . get_class($cn); 72 | } 73 | $classname_ = ltrim($classname_, '_'); 74 | $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_); 75 | 76 | $params = apply_filters( 'dynamic_sidebar_params', $params ); 77 | 78 | $callback = $wp_registered_widgets[$id]['callback']; 79 | 80 | do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] ); 81 | 82 | if ( is_callable($callback) ) { 83 | ob_start(); 84 | $object = $callback[0]; 85 | $settings = $object->get_settings(); 86 | $widget_params = $wp_registered_widgets[$id]['params']; 87 | $number = $widget_params[0]['number']; 88 | $instance = $settings[$number]; 89 | call_user_func_array($callback, $params); 90 | $widgets[] = array( 91 | 'id' => $id, 92 | 'widget' => trim(ob_get_contents()), 93 | 'params' => $params[0], 94 | 'instance' => $instance 95 | ); 96 | ob_end_clean(); 97 | } 98 | } 99 | 100 | return array( 101 | 'sidebar_id' => $index, 102 | 'widgets' => $widgets 103 | ); 104 | } 105 | 106 | } 107 | 108 | 109 | -------------------------------------------------------------------------------- /json-api.php: -------------------------------------------------------------------------------- 1 |

Sorry, JSON API requires PHP version 5.0 or greater.

"; 39 | } 40 | 41 | function json_api_class_warning() { 42 | echo "

Oops, JSON_API class not found. If you've defined a JSON_API_DIR constant, double check that the path is correct.

"; 43 | } 44 | 45 | function json_api_activation() { 46 | // Add the rewrite rule on activation 47 | global $wp_rewrite; 48 | add_filter('rewrite_rules_array', 'json_api_rewrites'); 49 | $wp_rewrite->flush_rules(); 50 | } 51 | 52 | function json_api_deactivation() { 53 | // Remove the rewrite rule on deactivation 54 | global $wp_rewrite; 55 | $wp_rewrite->flush_rules(); 56 | } 57 | 58 | function json_api_rewrites($wp_rules) { 59 | $base = get_option('json_api_base', 'api'); 60 | if (empty($base)) { 61 | return $wp_rules; 62 | } 63 | $json_api_rules = array( 64 | "$base\$" => 'index.php?json=info', 65 | "$base/(.+)\$" => 'index.php?json=$matches[1]' 66 | ); 67 | return array_merge($json_api_rules, $wp_rules); 68 | } 69 | 70 | function json_api_dir() { 71 | if (defined('JSON_API_DIR') && file_exists(JSON_API_DIR)) { 72 | return JSON_API_DIR; 73 | } else { 74 | return dirname(__FILE__); 75 | } 76 | } 77 | 78 | // Add initialization and activation hooks 79 | add_action('init', 'json_api_init'); 80 | register_activation_hook("$dir/json-api.php", 'json_api_activation'); 81 | register_deactivation_hook("$dir/json-api.php", 'json_api_deactivation'); 82 | ?> 83 | -------------------------------------------------------------------------------- /library/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/library/.DS_Store -------------------------------------------------------------------------------- /models/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/models/.DS_Store -------------------------------------------------------------------------------- /models/attachment.php: -------------------------------------------------------------------------------- 1 | import_wp_object($wp_attachment); 17 | if ($this->is_image()) { 18 | $this->query_images(); 19 | } 20 | } 21 | } 22 | 23 | function import_wp_object($wp_attachment) { 24 | $this->id = (int) $wp_attachment->ID; 25 | $this->url = $wp_attachment->guid; 26 | $this->slug = $wp_attachment->post_name; 27 | $this->title = $wp_attachment->post_title; 28 | $this->description = $wp_attachment->post_content; 29 | $this->caption = $wp_attachment->post_excerpt; 30 | $this->parent = (int) $wp_attachment->post_parent; 31 | $this->mime_type = $wp_attachment->post_mime_type; 32 | } 33 | 34 | function is_image() { 35 | return (substr($this->mime_type, 0, 5) == 'image'); 36 | } 37 | 38 | function query_images() { 39 | $sizes = array('thumbnail', 'medium', 'large', 'full'); 40 | if (function_exists('get_intermediate_image_sizes')) { 41 | $sizes = array_merge(array('full'), get_intermediate_image_sizes()); 42 | } 43 | $this->images = array(); 44 | $home = get_bloginfo('url'); 45 | $attachment = wp_get_attachment_metadata($this->id); 46 | foreach ($attachment['sizes'] as $size => $data) { 47 | $filename = WP_CONTENT_DIR . '/uploads/' . pathinfo($attachment['file'])['dirname'] . '/' . $data['file']; 48 | if (file_exists($filename)) { 49 | list($measured_width, $measured_height) = getimagesize($filename); 50 | if ($measured_width == $data['width'] && 51 | $measured_height == $data['height']) { 52 | $this->images[$size] = (object) array( 53 | 'url' => wp_get_attachment_image_src($this->id, $size)[0], 54 | 'width' => $data['width'], 55 | 'height' => $data['height'] 56 | ); 57 | } 58 | } 59 | } 60 | } 61 | 62 | } 63 | 64 | -------------------------------------------------------------------------------- /models/author.php: -------------------------------------------------------------------------------- 1 | id = (int) $id; 21 | } else { 22 | $this->id = (int) get_the_author_meta('ID'); 23 | } 24 | $this->set_value('slug', 'user_nicename'); 25 | $this->set_value('name', 'display_name'); 26 | $this->set_value('first_name', 'first_name'); 27 | $this->set_value('last_name', 'last_name'); 28 | $this->set_value('nickname', 'nickname'); 29 | $this->set_value('url', 'user_url'); 30 | $this->set_value('description', 'description'); 31 | $this->set_author_meta(); 32 | //$this->raw = get_userdata($this->id); 33 | } 34 | 35 | function set_value($key, $wp_key = false) { 36 | if (!$wp_key) { 37 | $wp_key = $key; 38 | } 39 | $this->$key = get_the_author_meta($wp_key, $this->id); 40 | } 41 | 42 | function set_author_meta() { 43 | global $json_api; 44 | if (!$json_api->query->author_meta) { 45 | return; 46 | } 47 | $protected_vars = array( 48 | 'user_login', 49 | 'user_pass', 50 | 'user_email', 51 | 'user_activation_key' 52 | ); 53 | $vars = explode(',', $json_api->query->author_meta); 54 | $vars = array_diff($vars, $protected_vars); 55 | foreach ($vars as $var) { 56 | $this->set_value($var); 57 | } 58 | } 59 | 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /models/category.php: -------------------------------------------------------------------------------- 1 | import_wp_object($wp_category); 16 | } 17 | } 18 | 19 | function import_wp_object($wp_category) { 20 | 21 | $this->id = (int) $wp_category->term_id; 22 | $this->slug = $wp_category->slug; 23 | $this->title = $wp_category->name; 24 | $this->description = $wp_category->description; 25 | $this->parent = (int) $wp_category->parent; 26 | $this->post_count = (int) $wp_category->count; 27 | 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /models/comment.php: -------------------------------------------------------------------------------- 1 | import_wp_object($wp_comment); 16 | } 17 | } 18 | 19 | function import_wp_object($wp_comment) { 20 | global $json_api; 21 | 22 | $date_format = $json_api->query->date_format; 23 | $content = apply_filters('comment_text', $wp_comment->comment_content); 24 | 25 | $this->id = (int) $wp_comment->comment_ID; 26 | $this->name = $wp_comment->comment_author; 27 | $this->url = $wp_comment->comment_author_url; 28 | $this->date = date($date_format, strtotime($wp_comment->comment_date)); 29 | $this->content = $content; 30 | $this->parent = (int) $wp_comment->comment_parent; 31 | //$this->raw = $wp_comment; 32 | 33 | if (!empty($wp_comment->user_id)) { 34 | $this->author = new JSON_API_Author($wp_comment->user_id); 35 | } else { 36 | unset($this->author); 37 | } 38 | } 39 | 40 | function handle_submission() { 41 | global $comment, $wpdb; 42 | add_action('comment_id_not_found', array(&$this, 'comment_id_not_found')); 43 | add_action('comment_closed', array(&$this, 'comment_closed')); 44 | add_action('comment_on_draft', array(&$this, 'comment_on_draft')); 45 | add_filter('comment_post_redirect', array(&$this, 'comment_post_redirect')); 46 | $_SERVER['REQUEST_METHOD'] = 'POST'; 47 | $_POST['comment_post_ID'] = $_REQUEST['post_id']; 48 | $_POST['author'] = $_REQUEST['name']; 49 | $_POST['email'] = $_REQUEST['email']; 50 | $_POST['url'] = empty($_REQUEST['url']) ? '' : $_REQUEST['url']; 51 | $_POST['comment'] = $_REQUEST['content']; 52 | $_POST['parent'] = $_REQUEST['parent']; 53 | include ABSPATH . 'wp-comments-post.php'; 54 | } 55 | 56 | function comment_id_not_found() { 57 | global $json_api; 58 | $json_api->error("Post ID '{$_REQUEST['post_id']}' not found."); 59 | } 60 | 61 | function comment_closed() { 62 | global $json_api; 63 | $json_api->error("Post is closed for comments."); 64 | } 65 | 66 | function comment_on_draft() { 67 | global $json_api; 68 | $json_api->error("You cannot comment on unpublished posts."); 69 | } 70 | 71 | function comment_post_redirect() { 72 | global $comment, $json_api; 73 | $status = ($comment->comment_approved) ? 'ok' : 'pending'; 74 | $new_comment = new JSON_API_Comment($comment); 75 | $json_api->response->respond($new_comment, $status); 76 | } 77 | 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /models/post.php: -------------------------------------------------------------------------------- 1 | import_wp_object($wp_post); 32 | } 33 | do_action("json_api_{$this->type}_constructor", $this); 34 | } 35 | 36 | function create($values = null) { 37 | unset($values['id']); 38 | if (empty($values) || empty($values['title'])) { 39 | $values = array( 40 | 'title' => 'Untitled', 41 | 'content' => '' 42 | ); 43 | } 44 | return $this->save($values); 45 | } 46 | 47 | function update($values) { 48 | $values['id'] = $this->id; 49 | return $this->save($values); 50 | } 51 | 52 | function save($values = null) { 53 | global $json_api, $user_ID; 54 | 55 | $wp_values = array(); 56 | 57 | if (!empty($values['id'])) { 58 | $wp_values['ID'] = $values['id']; 59 | } 60 | 61 | if (!empty($values['type'])) { 62 | $wp_values['post_type'] = $values['type']; 63 | } 64 | 65 | if (!empty($values['status'])) { 66 | $wp_values['post_status'] = $values['status']; 67 | } 68 | 69 | if (!empty($values['title'])) { 70 | $wp_values['post_title'] = $values['title']; 71 | } 72 | 73 | if (!empty($values['content'])) { 74 | $wp_values['post_content'] = $values['content']; 75 | } 76 | 77 | if (!empty($values['author'])) { 78 | $author = $json_api->introspector->get_author_by_login($values['author']); 79 | $wp_values['post_author'] = $author->id; 80 | } 81 | 82 | if (!empty($values['date'])) { 83 | $wp_values['post_date'] = $values['date']; 84 | } 85 | 86 | if (isset($values['categories'])) { 87 | $categories = explode(',', $values['categories']); 88 | foreach ($categories as $category_slug) { 89 | $category_slug = trim($category_slug); 90 | $category = $json_api->introspector->get_category_by_slug($category_slug); 91 | if (empty($wp_values['post_category'])) { 92 | $wp_values['post_category'] = array($category->id); 93 | } else { 94 | array_push($wp_values['post_category'], $category->id); 95 | } 96 | } 97 | } 98 | 99 | if (isset($values['tags'])) { 100 | $tags = explode(',', $values['tags']); 101 | foreach ($tags as $tag_slug) { 102 | $tag_slug = trim($tag_slug); 103 | if (empty($wp_values['tags_input'])) { 104 | $wp_values['tags_input'] = array($tag_slug); 105 | } else { 106 | array_push($wp_values['tags_input'], $tag_slug); 107 | } 108 | } 109 | } 110 | 111 | if (isset($wp_values['ID'])) { 112 | $this->id = wp_update_post($wp_values); 113 | } else { 114 | $this->id = wp_insert_post($wp_values); 115 | } 116 | 117 | if (isset($values['meta'])) { 118 | $meta = $values['meta']; 119 | foreach ($meta as $meta_key => $meta_value) { 120 | update_post_meta($this->id, $meta_key, $meta_value); 121 | } 122 | } 123 | 124 | if (!empty($_FILES['attachment'])) { 125 | include_once ABSPATH . '/wp-admin/includes/file.php'; 126 | include_once ABSPATH . '/wp-admin/includes/media.php'; 127 | include_once ABSPATH . '/wp-admin/includes/image.php'; 128 | $attachment_id = media_handle_upload('attachment', $this->id); 129 | $this->attachments[] = new JSON_API_Attachment($attachment_id); 130 | unset($_FILES['attachment']); 131 | } 132 | 133 | $wp_post = get_post($this->id); 134 | $this->import_wp_object($wp_post); 135 | 136 | return $this->id; 137 | } 138 | 139 | function import_wp_object($wp_post) { 140 | global $json_api, $post; 141 | $date_format = $json_api->query->date_format; 142 | $this->id = (int) $wp_post->ID; 143 | setup_postdata($wp_post); 144 | $this->set_value('type', $wp_post->post_type); 145 | $this->set_value('slug', $wp_post->post_name); 146 | $this->set_value('url', get_permalink($this->id)); 147 | $this->set_value('status', $wp_post->post_status); 148 | $this->set_value('title', get_the_title($this->id)); 149 | $this->set_value('title_plain', strip_tags(@$this->title)); 150 | $this->set_content_value(); 151 | $this->set_value('excerpt', apply_filters('the_excerpt', get_the_excerpt())); 152 | $this->set_value('date', get_the_time($date_format)); 153 | $this->set_value('modified', date($date_format, strtotime($wp_post->post_modified))); 154 | $this->set_categories_value(); 155 | $this->set_tags_value(); 156 | $this->set_author_value($wp_post->post_author); 157 | $this->set_comments_value(); 158 | $this->set_attachments_value(); 159 | $this->set_value('comment_count', (int) $wp_post->comment_count); 160 | $this->set_value('comment_status', $wp_post->comment_status); 161 | $this->set_thumbnail_value(); 162 | $this->set_custom_fields_value(); 163 | $this->set_custom_taxonomies($wp_post->post_type); 164 | do_action("json_api_import_wp_post", $this, $wp_post); 165 | } 166 | 167 | function set_value($key, $value) { 168 | global $json_api; 169 | if ($json_api->include_value($key)) { 170 | $this->$key = $value; 171 | } else { 172 | unset($this->$key); 173 | } 174 | } 175 | 176 | function set_content_value() { 177 | global $json_api; 178 | if ($json_api->include_value('content')) { 179 | $content = get_the_content($json_api->query->read_more); 180 | $content = apply_filters('the_content', $content); 181 | $content = str_replace(']]>', ']]>', $content); 182 | $this->content = $content; 183 | } else { 184 | unset($this->content); 185 | } 186 | } 187 | 188 | function set_categories_value() { 189 | global $json_api; 190 | if ($json_api->include_value('categories')) { 191 | $this->categories = array(); 192 | if ($wp_categories = get_the_category($this->id)) { 193 | foreach ($wp_categories as $wp_category) { 194 | $category = new JSON_API_Category($wp_category); 195 | if ($category->id == 1 && $category->slug == 'uncategorized') { 196 | // Skip the 'uncategorized' category 197 | continue; 198 | } 199 | $this->categories[] = $category; 200 | } 201 | } 202 | } else { 203 | unset($this->categories); 204 | } 205 | } 206 | 207 | function set_tags_value() { 208 | global $json_api; 209 | if ($json_api->include_value('tags')) { 210 | $this->tags = array(); 211 | if ($wp_tags = get_the_tags($this->id)) { 212 | foreach ($wp_tags as $wp_tag) { 213 | $this->tags[] = new JSON_API_Tag($wp_tag); 214 | } 215 | } 216 | } else { 217 | unset($this->tags); 218 | } 219 | } 220 | 221 | function set_author_value($author_id) { 222 | global $json_api; 223 | if ($json_api->include_value('author')) { 224 | $this->author = new JSON_API_Author($author_id); 225 | } else { 226 | unset($this->author); 227 | } 228 | } 229 | 230 | function set_comments_value() { 231 | global $json_api; 232 | if ($json_api->include_value('comments')) { 233 | $this->comments = $json_api->introspector->get_comments($this->id); 234 | } else { 235 | unset($this->comments); 236 | } 237 | } 238 | 239 | function set_attachments_value() { 240 | global $json_api; 241 | if ($json_api->include_value('attachments')) { 242 | $this->attachments = $json_api->introspector->get_attachments($this->id); 243 | } else { 244 | unset($this->attachments); 245 | } 246 | } 247 | 248 | function set_thumbnail_value() { 249 | global $json_api; 250 | if (!$json_api->include_value('thumbnail') || 251 | !function_exists('get_post_thumbnail_id')) { 252 | unset($this->thumbnail); 253 | return; 254 | } 255 | $attachment_id = get_post_thumbnail_id($this->id); 256 | if (!$attachment_id) { 257 | unset($this->thumbnail); 258 | return; 259 | } 260 | $thumbnail_size = $this->get_thumbnail_size(); 261 | $this->thumbnail_size = $thumbnail_size; 262 | $attachment = $json_api->introspector->get_attachment($attachment_id); 263 | $image = $attachment->images[$thumbnail_size]; 264 | $this->thumbnail = $image->url; 265 | $this->thumbnail_images = $attachment->images; 266 | } 267 | 268 | function set_custom_fields_value() { 269 | global $json_api; 270 | if ($json_api->include_value('custom_fields')) { 271 | $wp_custom_fields = get_post_custom($this->id); 272 | $this->custom_fields = new stdClass(); 273 | if ($json_api->query->custom_fields) { 274 | $keys = explode(',', $json_api->query->custom_fields); 275 | } 276 | foreach ($wp_custom_fields as $key => $value) { 277 | if ($json_api->query->custom_fields) { 278 | if (in_array($key, $keys)) { 279 | $this->custom_fields->$key = $wp_custom_fields[$key]; 280 | } 281 | } else if (substr($key, 0, 1) != '_') { 282 | $this->custom_fields->$key = $wp_custom_fields[$key]; 283 | } 284 | } 285 | } else { 286 | unset($this->custom_fields); 287 | } 288 | } 289 | 290 | function set_custom_taxonomies($type) { 291 | global $json_api; 292 | $taxonomies = get_taxonomies(array( 293 | 'object_type' => array($type), 294 | 'public' => true, 295 | '_builtin' => false 296 | ), 'objects'); 297 | foreach ($taxonomies as $taxonomy_id => $taxonomy) { 298 | $taxonomy_key = "taxonomy_$taxonomy_id"; 299 | if (!$json_api->include_value($taxonomy_key)) { 300 | continue; 301 | } 302 | $taxonomy_class = $taxonomy->hierarchical ? 'JSON_API_Category' : 'JSON_API_Tag'; 303 | $terms = get_the_terms($this->id, $taxonomy_id); 304 | $this->$taxonomy_key = array(); 305 | if (!empty($terms)) { 306 | $taxonomy_terms = array(); 307 | foreach ($terms as $term) { 308 | $taxonomy_terms[] = new $taxonomy_class($term); 309 | } 310 | $this->$taxonomy_key = $taxonomy_terms; 311 | } 312 | } 313 | } 314 | 315 | function get_thumbnail_size() { 316 | global $json_api; 317 | if ($json_api->query->thumbnail_size) { 318 | return $json_api->query->thumbnail_size; 319 | } else if (function_exists('get_intermediate_image_sizes')) { 320 | $sizes = get_intermediate_image_sizes(); 321 | if (in_array('post-thumbnail', $sizes)) { 322 | return 'post-thumbnail'; 323 | } 324 | } 325 | return 'thumbnail'; 326 | } 327 | 328 | } 329 | 330 | ?> 331 | -------------------------------------------------------------------------------- /models/tag.php: -------------------------------------------------------------------------------- 1 | import_wp_object($wp_tag); 13 | } 14 | } 15 | 16 | function import_wp_object($wp_tag) { 17 | $this->id = (int) $wp_tag->term_id; 18 | $this->slug = $wp_tag->slug; 19 | $this->title = $wp_tag->name; 20 | $this->description = $wp_tag->description; 21 | $this->post_count = (int) $wp_tag->count; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/screenshot-1.png -------------------------------------------------------------------------------- /singletons/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/singletons/.DS_Store -------------------------------------------------------------------------------- /singletons/api.php: -------------------------------------------------------------------------------- 1 | query = new JSON_API_Query(); 7 | $this->introspector = new JSON_API_Introspector(); 8 | $this->response = new JSON_API_Response(); 9 | add_action('template_redirect', array(&$this, 'template_redirect')); 10 | add_action('admin_menu', array(&$this, 'admin_menu')); 11 | add_action('update_option_json_api_base', array(&$this, 'flush_rewrite_rules')); 12 | add_action('pre_update_option_json_api_controllers', array(&$this, 'update_controllers')); 13 | } 14 | 15 | function template_redirect() { 16 | // Check to see if there's an appropriate API controller + method 17 | $controller = strtolower($this->query->get_controller()); 18 | $available_controllers = $this->get_controllers(); 19 | $enabled_controllers = explode(',', get_option('json_api_controllers', 'core')); 20 | $active_controllers = array_intersect($available_controllers, $enabled_controllers); 21 | 22 | if ($controller) { 23 | 24 | if (empty($this->query->dev)) { 25 | error_reporting(0); 26 | } 27 | 28 | if (!in_array($controller, $active_controllers)) { 29 | $this->error("Unknown controller '$controller'."); 30 | } 31 | 32 | $controller_path = $this->controller_path($controller); 33 | if (file_exists($controller_path)) { 34 | require_once $controller_path; 35 | } 36 | $controller_class = $this->controller_class($controller); 37 | 38 | if (!class_exists($controller_class)) { 39 | $this->error("Unknown controller '$controller_class'."); 40 | } 41 | 42 | $this->controller = new $controller_class(); 43 | $method = $this->query->get_method($controller); 44 | 45 | if ($method) { 46 | 47 | $this->response->setup(); 48 | 49 | // Run action hooks for method 50 | do_action("json_api", $controller, $method); 51 | do_action("json_api-{$controller}-$method"); 52 | 53 | // Error out if nothing is found 54 | if ($method == '404') { 55 | $this->error('Not found'); 56 | } 57 | 58 | // Build transient slug using method (and query params if set) 59 | $transient_slug = 'json-api-'; 60 | $transient_slug .= $method; 61 | 62 | $url = parse_url($_SERVER['REQUEST_URI']); 63 | 64 | if($url['query'] !== null): 65 | $args = wp_parse_args($url['query']); 66 | $transient_slug .= '-' . implode('-', array_keys($args)); 67 | $transient_slug .= '-' . implode('-', $args); 68 | endif; 69 | 70 | // Transient slug must be less than 45 characters (http://codex.wordpress.org/Transients_API) 71 | if(strlen($transient_slug) > 40): 72 | $transient_slug = 'json-api-' . md5($transient_slug); 73 | endif; 74 | 75 | if ( is_user_logged_in() ): 76 | // Never show cached content to a logged-in user 77 | $cached = false; 78 | else: 79 | // Check for cached value 80 | $cached = get_transient($transient_slug); 81 | endif; 82 | 83 | if($cached !== false): 84 | // Use the cached result 85 | $result = $cached; 86 | else: 87 | // Run the method and cache result for 24 hours 88 | $result = $this->controller->$method(); 89 | set_transient( $transient_slug, $result, 24 * 3600 ); 90 | endif; 91 | 92 | // Handle the result 93 | $this->response->respond($result); 94 | 95 | // Done! 96 | exit; 97 | } 98 | } 99 | } 100 | 101 | function admin_menu() { 102 | add_options_page('JSON API Settings', 'JSON API', 'manage_options', 'json-api', array(&$this, 'admin_options')); 103 | } 104 | 105 | function admin_options() { 106 | if (!current_user_can('manage_options')) { 107 | wp_die( __('You do not have sufficient permissions to access this page.') ); 108 | } 109 | 110 | $available_controllers = $this->get_controllers(); 111 | $active_controllers = explode(',', get_option('json_api_controllers', 'core')); 112 | 113 | if (count($active_controllers) == 1 && empty($active_controllers[0])) { 114 | $active_controllers = array(); 115 | } 116 | 117 | if (!empty($_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'], "update-options")) { 118 | if ((!empty($_REQUEST['action']) || !empty($_REQUEST['action2'])) && 119 | (!empty($_REQUEST['controller']) || !empty($_REQUEST['controllers']))) { 120 | if (!empty($_REQUEST['action'])) { 121 | $action = $_REQUEST['action']; 122 | } else { 123 | $action = $_REQUEST['action2']; 124 | } 125 | 126 | if (!empty($_REQUEST['controllers'])) { 127 | $controllers = $_REQUEST['controllers']; 128 | } else { 129 | $controllers = array($_REQUEST['controller']); 130 | } 131 | 132 | foreach ($controllers as $controller) { 133 | if (in_array($controller, $available_controllers)) { 134 | if ($action == 'activate' && !in_array($controller, $active_controllers)) { 135 | $active_controllers[] = $controller; 136 | } else if ($action == 'deactivate') { 137 | $index = array_search($controller, $active_controllers); 138 | if ($index !== false) { 139 | unset($active_controllers[$index]); 140 | } 141 | } 142 | } 143 | } 144 | $this->save_option('json_api_controllers', implode(',', $active_controllers)); 145 | } 146 | if (isset($_REQUEST['json_api_base'])) { 147 | $this->save_option('json_api_base', $_REQUEST['json_api_base']); 148 | } 149 | } 150 | 151 | ?> 152 |
153 |

154 |

JSON API Settings

155 |
156 | 157 |

Controllers

158 | print_controller_actions(); ?> 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | controller_info($controller); 182 | 183 | if (is_string($info)) { 184 | $active = false; 185 | $error = true; 186 | $info = array( 187 | 'name' => $controller, 188 | 'description' => "

Error: $info

", 189 | 'methods' => array(), 190 | 'url' => null 191 | ); 192 | } 193 | 194 | ?> 195 | 196 | 199 | 217 | 234 | 235 | 236 | 237 |
ControllerDescription
ControllerDescription
197 | 198 | 200 | 201 |
202 | ' . __('Deactivate') . ''; 206 | } else if (!$error) { 207 | echo '' . __('Activate') . ''; 208 | } 209 | 210 | if (!empty($info['url'])) { 211 | echo ' | '; 212 | echo 'Docs
'; 213 | } 214 | 215 | ?> 216 |
218 |

219 |

220 | get_method_url($controller, $method); 224 | if ($active) { 225 | echo "$method "; 226 | } else { 227 | echo "$method "; 228 | } 229 | } 230 | 231 | ?> 232 |

233 |
238 | print_controller_actions('action2'); ?> 239 |

Address

240 |

Specify a base URL for JSON API. For example, using api as your API base URL would enable the following /api/get_recent_posts/. If you assign a blank value the API will only be available by setting a json query variable.

241 | 242 | 243 | 244 | 245 | 246 |
API base/
247 | 248 |
249 |

Note: User-friendly permalinks are not currently enabled. Change Permalinks 250 | 251 |

252 | 253 |

254 |
255 |
256 | 261 |
262 |
263 | 268 | 269 |
270 |
271 |
272 |
273 | $value) { 283 | $args[] = urlencode($key) . '=' . urlencode($value); 284 | } 285 | $args = implode('&', $args); 286 | } else { 287 | $args = $options; 288 | } 289 | if ($controller != 'core') { 290 | $method = "$controller/$method"; 291 | } 292 | if (!empty($base) && !empty($permalink_structure)) { 293 | if (!empty($args)) { 294 | $args = "?$args"; 295 | } 296 | return "$url/$base/$method/$args"; 297 | } else { 298 | return "$url?json=$method&$args"; 299 | } 300 | } 301 | 302 | function save_option($id, $value) { 303 | $option_exists = (get_option($id, null) !== null); 304 | if ($option_exists) { 305 | update_option($id, $value); 306 | } else { 307 | add_option($id, $value); 308 | } 309 | } 310 | 311 | function get_controllers() { 312 | $controllers = array(); 313 | $dir = json_api_dir(); 314 | $this->check_directory_for_controllers("$dir/controllers", $controllers); 315 | $this->check_directory_for_controllers(get_stylesheet_directory(), $controllers); 316 | $controllers = apply_filters('json_api_controllers', $controllers); 317 | return array_map('strtolower', $controllers); 318 | } 319 | 320 | function check_directory_for_controllers($dir, &$controllers) { 321 | $dh = opendir($dir); 322 | while ($file = readdir($dh)) { 323 | if (preg_match('/(.+)\.php$/i', $file, $matches)) { 324 | $src = file_get_contents("$dir/$file"); 325 | if (preg_match("/class\s+JSON_API_{$matches[1]}_Controller/i", $src)) { 326 | $controllers[] = $matches[1]; 327 | } 328 | } 329 | } 330 | } 331 | 332 | function controller_is_active($controller) { 333 | if (defined('JSON_API_CONTROLLERS')) { 334 | $default = JSON_API_CONTROLLERS; 335 | } else { 336 | $default = 'core'; 337 | } 338 | $active_controllers = explode(',', get_option('json_api_controllers', $default)); 339 | return (in_array($controller, $active_controllers)); 340 | } 341 | 342 | function update_controllers($controllers) { 343 | if (is_array($controllers)) { 344 | return implode(',', $controllers); 345 | } else { 346 | return $controllers; 347 | } 348 | } 349 | 350 | function controller_info($controller) { 351 | $path = $this->controller_path($controller); 352 | $class = $this->controller_class($controller); 353 | $response = array( 354 | 'name' => $controller, 355 | 'description' => '(No description available)', 356 | 'methods' => array() 357 | ); 358 | if (file_exists($path)) { 359 | $source = file_get_contents($path); 360 | if (preg_match('/^\s*Controller name:(.+)$/im', $source, $matches)) { 361 | $response['name'] = trim($matches[1]); 362 | } 363 | if (preg_match('/^\s*Controller description:(.+)$/im', $source, $matches)) { 364 | $response['description'] = trim($matches[1]); 365 | } 366 | if (preg_match('/^\s*Controller URI:(.+)$/im', $source, $matches)) { 367 | $response['docs'] = trim($matches[1]); 368 | } 369 | if (!class_exists($class)) { 370 | require_once($path); 371 | } 372 | $response['methods'] = get_class_methods($class); 373 | return $response; 374 | } else if (is_admin()) { 375 | return "Cannot find controller class '$class' (filtered path: $path)."; 376 | } else { 377 | $this->error("Unknown controller '$controller'."); 378 | } 379 | return $response; 380 | } 381 | 382 | function controller_class($controller) { 383 | return "json_api_{$controller}_controller"; 384 | } 385 | 386 | function controller_path($controller) { 387 | $json_api_dir = json_api_dir(); 388 | $json_api_path = "$json_api_dir/controllers/$controller.php"; 389 | $theme_dir = get_stylesheet_directory(); 390 | $theme_path = "$theme_dir/$controller.php"; 391 | if (file_exists($theme_path)) { 392 | $path = $theme_path; 393 | } else if (file_exists($json_api_path)) { 394 | $path = $json_api_path; 395 | } else { 396 | $path = null; 397 | } 398 | $controller_class = $this->controller_class($controller); 399 | return apply_filters("{$controller_class}_path", $path); 400 | } 401 | 402 | function get_nonce_id($controller, $method) { 403 | $controller = strtolower($controller); 404 | $method = strtolower($method); 405 | return "json_api-$controller-$method"; 406 | } 407 | 408 | function flush_rewrite_rules() { 409 | global $wp_rewrite; 410 | $wp_rewrite->flush_rules(); 411 | } 412 | 413 | function error($message = 'Unknown error', $status = 'error', $header = '400') { 414 | $this->response->respond(array( 415 | 'error' => $message 416 | ), $status, $header); 417 | } 418 | 419 | function include_value($key) { 420 | return $this->response->is_value_included($key); 421 | } 422 | 423 | } 424 | 425 | ?> 426 | -------------------------------------------------------------------------------- /singletons/introspector.php: -------------------------------------------------------------------------------- 1 | set_posts_query($query); 8 | $output = array(); 9 | while (have_posts()) { 10 | the_post(); 11 | if ($wp_posts) { 12 | $new_post = $post; 13 | } else { 14 | $new_post = new JSON_API_Post($post); 15 | } 16 | $output[] = $new_post; 17 | } 18 | return $output; 19 | } 20 | 21 | public function get_date_archive_permalinks() { 22 | $archives = wp_get_archives('echo=0'); 23 | preg_match_all("/href='([^']+)'/", $archives, $matches); 24 | return $matches[1]; 25 | } 26 | 27 | public function get_date_archive_tree($permalinks) { 28 | $tree = array(); 29 | foreach ($permalinks as $url) { 30 | if (preg_match('#(\d{4})/(\d{2})#', $url, $date)) { 31 | $year = $date[1]; 32 | $month = $date[2]; 33 | } else if (preg_match('/(\d{4})(\d{2})/', $url, $date)) { 34 | $year = $date[1]; 35 | $month = $date[2]; 36 | } else { 37 | continue; 38 | } 39 | $count = $this->get_date_archive_count($year, $month); 40 | if (empty($tree[$year])) { 41 | $tree[$year] = array( 42 | $month => $count 43 | ); 44 | } else { 45 | $tree[$year][$month] = $count; 46 | } 47 | } 48 | return $tree; 49 | } 50 | 51 | public function get_date_archive_count($year, $month) { 52 | if (!isset($this->month_archives)) { 53 | global $wpdb; 54 | $post_counts = $wpdb->get_results(" 55 | SELECT DATE_FORMAT(post_date, '%Y%m') AS month, 56 | COUNT(ID) AS post_count 57 | FROM $wpdb->posts 58 | WHERE post_status = 'publish' 59 | AND post_type = 'post' 60 | GROUP BY month 61 | "); 62 | $this->month_archives = array(); 63 | foreach ($post_counts as $post_count) { 64 | $this->month_archives[$post_count->month] = $post_count->post_count; 65 | } 66 | } 67 | return $this->month_archives["$year$month"]; 68 | } 69 | 70 | public function get_categories($args = null) { 71 | $wp_categories = get_categories($args); 72 | $categories = array(); 73 | foreach ($wp_categories as $wp_category) { 74 | if ($wp_category->term_id == 1 && $wp_category->slug == 'uncategorized') { 75 | continue; 76 | } 77 | $categories[] = $this->get_category_object($wp_category); 78 | } 79 | return $categories; 80 | } 81 | 82 | public function get_current_post() { 83 | global $json_api; 84 | extract($json_api->query->get(array('id', 'slug', 'post_id', 'post_slug'))); 85 | if ($id || $post_id) { 86 | if (!$id) { 87 | $id = $post_id; 88 | } 89 | $posts = $this->get_posts(array( 90 | 'p' => $id 91 | ), true); 92 | } else if ($slug || $post_slug) { 93 | if (!$slug) { 94 | $slug = $post_slug; 95 | } 96 | $posts = $this->get_posts(array( 97 | 'name' => $slug 98 | ), true); 99 | } else { 100 | $json_api->error("Include 'id' or 'slug' var in your request."); 101 | } 102 | if (!empty($posts)) { 103 | return $posts[0]; 104 | } else { 105 | return null; 106 | } 107 | } 108 | 109 | public function get_menu() { 110 | global $json_api; 111 | extract($json_api->query->get(array('name'))); 112 | 113 | $items = wp_get_nav_menu_items($name); 114 | return $items; 115 | 116 | } 117 | public function get_list_menu() { 118 | global $json_api; 119 | $menus = get_terms('nav_menu'); 120 | //$items = get_registered_nav_menus(); 121 | return $menus; 122 | 123 | } 124 | 125 | public function get_current_category() { 126 | global $json_api; 127 | extract($json_api->query->get(array('id', 'slug', 'category_id', 'category_slug'))); 128 | if ($id || $category_id) { 129 | if (!$id) { 130 | $id = $category_id; 131 | } 132 | return $this->get_category_by_id($id); 133 | } else if ($slug || $category_slug) { 134 | if (!$slug) { 135 | $slug = $category_slug; 136 | } 137 | return $this->get_category_by_slug($slug); 138 | } else { 139 | $json_api->error("Include 'id' or 'slug' var in your request."); 140 | } 141 | return null; 142 | } 143 | 144 | public function get_category_by_id($category_id) { 145 | $wp_category = get_term_by('id', $category_id, 'category'); 146 | return $this->get_category_object($wp_category); 147 | } 148 | 149 | public function get_category_by_slug($category_slug) { 150 | $wp_category = get_term_by('slug', $category_slug, 'category'); 151 | return $this->get_category_object($wp_category); 152 | } 153 | 154 | public function get_tags() { 155 | $wp_tags = get_tags(); 156 | return array_map(array(&$this, 'get_tag_object'), $wp_tags); 157 | } 158 | 159 | public function get_current_tag() { 160 | global $json_api; 161 | extract($json_api->query->get(array('id', 'slug', 'tag_id', 'tag_slug'))); 162 | if ($id || $tag_id) { 163 | if (!$id) { 164 | $id = $tag_id; 165 | } 166 | return $this->get_tag_by_id($id); 167 | } else if ($slug || $tag_slug) { 168 | if (!$slug) { 169 | $slug = $tag_slug; 170 | } 171 | return $this->get_tag_by_slug($slug); 172 | } else { 173 | $json_api->error("Include 'id' or 'slug' var in your request."); 174 | } 175 | return null; 176 | } 177 | 178 | public function get_tag_by_id($tag_id) { 179 | $wp_tag = get_term_by('id', $tag_id, 'post_tag'); 180 | return $this->get_tag_object($wp_tag); 181 | } 182 | 183 | public function get_tag_by_slug($tag_slug) { 184 | $wp_tag = get_term_by('slug', $tag_slug, 'post_tag'); 185 | return $this->get_tag_object($wp_tag); 186 | } 187 | 188 | public function get_authors() { 189 | global $wpdb; 190 | $author_ids = $wpdb->get_col(" 191 | SELECT u.ID, m.meta_value AS last_name 192 | FROM $wpdb->users AS u, 193 | $wpdb->usermeta AS m 194 | WHERE m.user_id = u.ID 195 | AND m.meta_key = 'last_name' 196 | ORDER BY last_name 197 | "); 198 | $all_authors = array_map(array(&$this, 'get_author_by_id'), $author_ids); 199 | $active_authors = array_filter($all_authors, array(&$this, 'is_active_author')); 200 | return $active_authors; 201 | } 202 | 203 | public function get_current_author() { 204 | global $json_api; 205 | extract($json_api->query->get(array('id', 'slug', 'author_id', 'author_slug'))); 206 | if ($id || $author_id) { 207 | if (!$id) { 208 | $id = $author_id; 209 | } 210 | return $this->get_author_by_id($id); 211 | } else if ($slug || $author_slug) { 212 | if (!$slug) { 213 | $slug = $author_slug; 214 | } 215 | return $this->get_author_by_login($slug); 216 | } else { 217 | $json_api->error("Include 'id' or 'slug' var in your request."); 218 | } 219 | return null; 220 | } 221 | 222 | public function get_author_by_id($id) { 223 | $id = get_the_author_meta('ID', $id); 224 | if (!$id) { 225 | return null; 226 | } 227 | return new JSON_API_Author($id); 228 | } 229 | 230 | public function get_author_by_login($login) { 231 | global $wpdb; 232 | $id = $wpdb->get_var($wpdb->prepare(" 233 | SELECT ID 234 | FROM $wpdb->users 235 | WHERE user_nicename = %s 236 | ", $login)); 237 | return $this->get_author_by_id($id); 238 | } 239 | 240 | public function get_comments($post_id) { 241 | global $wpdb; 242 | $wp_comments = $wpdb->get_results($wpdb->prepare(" 243 | SELECT * 244 | FROM $wpdb->comments 245 | WHERE comment_post_ID = %d 246 | AND comment_approved = 1 247 | AND comment_type = '' 248 | ORDER BY comment_date 249 | ", $post_id)); 250 | $comments = array(); 251 | foreach ($wp_comments as $wp_comment) { 252 | $comments[] = new JSON_API_Comment($wp_comment); 253 | } 254 | return $comments; 255 | } 256 | 257 | public function get_attachments($post_id) { 258 | $wp_attachments = get_children(array( 259 | 'post_type' => 'attachment', 260 | 'post_parent' => $post_id, 261 | 'orderby' => 'menu_order', 262 | 'order' => 'ASC', 263 | 'suppress_filters' => false 264 | )); 265 | $attachments = array(); 266 | if (!empty($wp_attachments)) { 267 | foreach ($wp_attachments as $wp_attachment) { 268 | $attachments[] = new JSON_API_Attachment($wp_attachment); 269 | } 270 | } 271 | return $attachments; 272 | } 273 | 274 | public function get_attachment($attachment_id) { 275 | global $wpdb; 276 | $wp_attachment = $wpdb->get_row( 277 | $wpdb->prepare(" 278 | SELECT * 279 | FROM $wpdb->posts 280 | WHERE ID = %d 281 | ", $attachment_id) 282 | ); 283 | return new JSON_API_Attachment($wp_attachment); 284 | } 285 | 286 | public function attach_child_posts(&$post) { 287 | $post->children = array(); 288 | $wp_children = get_posts(array( 289 | 'post_type' => $post->type, 290 | 'post_parent' => $post->id, 291 | 'order' => 'ASC', 292 | 'orderby' => 'menu_order', 293 | 'numberposts' => -1, 294 | 'suppress_filters' => false 295 | )); 296 | foreach ($wp_children as $wp_post) { 297 | $new_post = new JSON_API_Post($wp_post); 298 | $new_post->parent = $post->id; 299 | $post->children[] = $new_post; 300 | } 301 | foreach ($post->children as $child) { 302 | $this->attach_child_posts($child); 303 | } 304 | } 305 | 306 | protected function get_category_object($wp_category) { 307 | if (!$wp_category) { 308 | return null; 309 | } 310 | 311 | return new JSON_API_Category($wp_category); 312 | } 313 | 314 | protected function get_tag_object($wp_tag) { 315 | if (!$wp_tag) { 316 | return null; 317 | } 318 | return new JSON_API_Tag($wp_tag); 319 | } 320 | 321 | protected function is_active_author($author) { 322 | if (!isset($this->active_authors)) { 323 | $this->active_authors = explode(',', wp_list_authors(array( 324 | 'html' => false, 325 | 'echo' => false, 326 | 'exclude_admin' => false 327 | ))); 328 | $this->active_authors = array_map('trim', $this->active_authors); 329 | } 330 | return in_array($author->name, $this->active_authors); 331 | } 332 | 333 | protected function set_posts_query($query = false) { 334 | global $json_api, $wp_query; 335 | 336 | if (!$query) { 337 | $query = array(); 338 | } 339 | 340 | $query = array_merge($query, $wp_query->query); 341 | 342 | if ($json_api->query->page) { 343 | $query['paged'] = $json_api->query->page; 344 | } 345 | 346 | if ($json_api->query->count) { 347 | $query['posts_per_page'] = $json_api->query->count; 348 | } 349 | 350 | if ($json_api->query->post_type) { 351 | $query['post_type'] = $json_api->query->post_type; 352 | } 353 | 354 | if ($json_api->query->post_status) { 355 | $query['post_status'] = $json_api->query->post_status; 356 | } 357 | 358 | if ($json_api->query->category_id) { 359 | $query['cat'] = $json_api->query->category_id; 360 | } 361 | 362 | if ($json_api->query->category_slug) { 363 | $query['category_name'] = $json_api->query->category_slug; 364 | } 365 | 366 | if ($json_api->query->tag_id) { 367 | $query['tag_id'] = $json_api->query->tag_id; 368 | } 369 | 370 | if ($json_api->query->tag_slug) { 371 | $query['tag'] = $json_api->query->tag_slug; 372 | } 373 | 374 | if (!empty($query)) { 375 | query_posts($query); 376 | do_action('json_api_query', $wp_query); 377 | } 378 | } 379 | 380 | } 381 | 382 | ?> -------------------------------------------------------------------------------- /singletons/query.php: -------------------------------------------------------------------------------- 1 | 'Y-m-d H:i:s', 8 | 'read_more' => 'Read more' 9 | ); 10 | 11 | function __construct() { 12 | // Register JSON API query vars 13 | add_filter('query_vars', array(&$this, 'query_vars')); 14 | } 15 | 16 | function get($key) { 17 | if (is_array($key)) { 18 | $result = array(); 19 | foreach ($key as $k) { 20 | $result[$k] = $this->get($k); 21 | } 22 | return $result; 23 | } 24 | $query_var = (isset($_REQUEST[$key])) ? $_REQUEST[$key] : null; 25 | $wp_query_var = $this->wp_query_var($key); 26 | if ($wp_query_var) { 27 | return $wp_query_var; 28 | } else if ($query_var) { 29 | return $this->strip_magic_quotes($query_var); 30 | } else if (isset($this->defaults[$key])) { 31 | return $this->defaults[$key]; 32 | } else { 33 | return null; 34 | } 35 | } 36 | 37 | function __get($key) { 38 | return $this->get($key); 39 | } 40 | 41 | function __isset($key) { 42 | return ($this->get($key) !== null); 43 | } 44 | 45 | function wp_query_var($key) { 46 | $wp_translation = array( 47 | 'json' => 'json', 48 | 'post_id' => 'p', 49 | 'post_slug' => 'name', 50 | 'page_id' => 'page_id', 51 | 'page_slug' => 'name', 52 | 'category_id' => 'cat', 53 | 'category_slug' => 'category_name', 54 | 'tag_id' => 'tag_id', 55 | 'tag_slug' => 'tag', 56 | 'author_id' => 'author', 57 | 'author_slug' => 'author_name', 58 | 'search' => 's', 59 | 'order' => 'order', 60 | 'order_by' => 'orderby', 61 | 'post_status' => 'post_status' 62 | ); 63 | if ($key == 'date') { 64 | $date = null; 65 | if (get_query_var('year')) { 66 | $date = get_query_var('year'); 67 | } 68 | if (get_query_var('monthnum')) { 69 | $month = get_query_var('monthnum'); 70 | if ($month < 10) { 71 | $month = "0$month"; 72 | } 73 | $date .= $month; 74 | } 75 | if (get_query_var('day')) { 76 | $day = get_query_var('day'); 77 | if ($day < 10) { 78 | $day = "0$day"; 79 | } 80 | $date .= $day; 81 | } 82 | return $date; 83 | } else if (isset($wp_translation[$key])) { 84 | return get_query_var($wp_translation[$key]); 85 | } else { 86 | return null; 87 | } 88 | } 89 | 90 | function strip_magic_quotes($value) { 91 | // Deprecated! 92 | //if (get_magic_quotes_gpc()) { 93 | // return stripslashes($value); 94 | //} else { 95 | return $value; 96 | //} 97 | } 98 | 99 | function query_vars($wp_vars) { 100 | $wp_vars[] = 'json'; 101 | return $wp_vars; 102 | } 103 | 104 | function get_controller() { 105 | $json = $this->get('json'); 106 | if (empty($json)) { 107 | return false; 108 | } 109 | if (preg_match('/^[a-zA-Z_]+$/', $json)) { 110 | return $this->get_legacy_controller($json); 111 | } else if (preg_match('/^([a-zA-Z0-9_]+)(\/|\.)[a-zA-Z0-9_]+$/', $json, $matches)) { 112 | return $matches[1]; 113 | } else { 114 | return 'core'; 115 | } 116 | } 117 | 118 | function get_legacy_controller($json) { 119 | global $json_api; 120 | if ($json == 'submit_comment') { 121 | if ($json_api->controller_is_active('respond')) { 122 | return 'respond'; 123 | } else { 124 | $json_api->error("The 'submit_comment' method has been removed from the Core controller. To use this method you must enable the Respond controller from WP Admin > Settings > JSON API."); 125 | } 126 | } else if ($json == 'create_post') { 127 | if ($json_api->controller_is_active('posts')) { 128 | return 'posts'; 129 | } else { 130 | $json_api->error("The 'create_post' method has been removed from the Core controller. To use this method you must enable the Posts controller from WP Admin > Settings > JSON API."); 131 | } 132 | } else { 133 | return 'core'; 134 | } 135 | } 136 | 137 | function get_method($controller) { 138 | 139 | global $json_api; 140 | 141 | // Returns an appropriate API method name or false. Four possible outcomes: 142 | // 1. API isn't being invoked at all (return false) 143 | // 2. A specific API method was requested (return method name) 144 | // 3. A method is chosen implicitly on a given WordPress page 145 | // 4. API invoked incorrectly (return "error" method) 146 | // 147 | // Note: 148 | // The implicit outcome (3) is invoked by setting the json query var to a 149 | // non-empty value on any WordPress page: 150 | // * http://example.org/2009/11/10/hello-world/?json=1 (get_post) 151 | // * http://example.org/2009/11/?json=1 (get_date_posts) 152 | // * http://example.org/category/foo?json=1 (get_category_posts) 153 | 154 | $method = $this->get('json'); 155 | if (strpos($method, '/') !== false) { 156 | $method = substr($method, strpos($method, '/') + 1); 157 | } else if (strpos($method, '.') !== false) { 158 | $method = substr($method, strpos($method, '.') + 1); 159 | } 160 | 161 | if (empty($method)) { 162 | // Case 1: we're not being invoked (done!) 163 | return false; 164 | } else if (method_exists("JSON_API_{$controller}_Controller", $method)) { 165 | // Case 2: an explicit method was specified 166 | return $method; 167 | } else if ($controller == 'core') { 168 | // Case 3: choose the method implicitly based on which page we're on... 169 | if (is_search()) { 170 | return 'get_search_results'; 171 | } else if (is_home()) { 172 | if (empty($_GET['json'])) { 173 | $json_api->error("Unknown method '$method'."); 174 | } 175 | return 'get_recent_posts'; 176 | } else if (is_page()) { 177 | return 'get_page'; 178 | } else if (is_single()) { 179 | return 'get_post'; 180 | } else if (is_category()) { 181 | return 'get_category_posts'; 182 | } else if (is_tag()) { 183 | return 'get_tag_posts'; 184 | } else if (is_author()) { 185 | return 'get_author_posts'; 186 | } else if (is_date()) { 187 | return 'get_date_posts'; 188 | } else if (is_404()) { 189 | return '404'; 190 | } 191 | } 192 | // Case 4: either the method doesn't exist or we don't support the page implicitly 193 | return 'error'; 194 | } 195 | 196 | } 197 | -------------------------------------------------------------------------------- /singletons/response.php: -------------------------------------------------------------------------------- 1 | include_values = array(); 8 | $this->exclude_values = array(); 9 | if ($json_api->query->include) { 10 | $this->include_values = explode(',', $json_api->query->include); 11 | } 12 | // Props to ikesyo for submitting a fix! 13 | if ($json_api->query->exclude) { 14 | $this->exclude_values = explode(',', $json_api->query->exclude); 15 | $this->include_values = array_diff($this->include_values, $this->exclude_values); 16 | } 17 | 18 | // Compatibility with Disqus plugin 19 | remove_action('loop_end', 'dsq_loop_end'); 20 | } 21 | 22 | function get_json($data, $status = 'ok') { 23 | global $json_api; 24 | // Include a status value with the response 25 | if (is_array($data)) { 26 | $data = array_merge(array('status' => $status), $data); 27 | } else if (is_object($data)) { 28 | $data = get_object_vars($data); 29 | $data = array_merge(array('status' => $status), $data); 30 | } 31 | 32 | $data = apply_filters('json_api_encode', $data); 33 | 34 | if (function_exists('json_encode')) { 35 | // Use the built-in json_encode function if it's available 36 | if (version_compare(PHP_VERSION, '5.3') < 0) { 37 | $json = json_encode($data); 38 | } else { 39 | $json_encode_options = 0; 40 | if ($json_api->query->json_encode_options) { 41 | $json_encode_options = $json_api->query->json_encode_options; 42 | } 43 | $json = json_encode($data, $json_encode_options); 44 | } 45 | } else { 46 | // Use PEAR's Services_JSON encoder otherwise 47 | if (!class_exists('Services_JSON')) { 48 | $dir = json_api_dir(); 49 | require_once "$dir/library/JSON.php"; 50 | } 51 | $json_service = new Services_JSON(); 52 | $json = $json_service->encode($data); 53 | } 54 | 55 | // Thanks to Stack Overflow user Gumbo stackoverflow.com/questions/2934563 56 | if ($json_api->query->json_unescaped_unicode) { 57 | $callback = array($this, 'replace_unicode_escape_sequence'); 58 | $json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', $callback, $json); 59 | } 60 | 61 | return $json; 62 | } 63 | 64 | function is_value_included($key) { 65 | // Props to ikesyo for submitting a fix! 66 | if (empty($this->include_values) && empty($this->exclude_values)) { 67 | return true; 68 | } else { 69 | if (empty($this->exclude_values)) { 70 | return in_array($key, $this->include_values); 71 | } else { 72 | return !in_array($key, $this->exclude_values); 73 | } 74 | } 75 | } 76 | 77 | function respond($result, $status = 'ok', $header = '200 OK') { 78 | global $json_api; 79 | $json = $this->get_json($result, $status); 80 | $status_redirect = "redirect_$status"; 81 | if ($json_api->query->dev || !empty($_REQUEST['dev'])) { 82 | // Output the result in a human-redable format 83 | if (!headers_sent()) { 84 | header('HTTP/1.1 200 OK'); 85 | header('Content-Type: text/plain; charset: UTF-8', true); 86 | } else { 87 | echo '
';
 88 |       }
 89 |       echo $this->prettify($json);
 90 |     } else if (!empty($_REQUEST[$status_redirect])) {
 91 |       wp_safe_redirect($_REQUEST[$status_redirect]);
 92 |     } else if ($json_api->query->redirect) {
 93 |       $url = $this->add_status_query_var($json_api->query->redirect, $status);
 94 |       wp_safe_redirect($url);
 95 |     } else if ($json_api->query->callback) {
 96 |       // Run a JSONP-style callback with the result
 97 |       $this->callback($json_api->query->callback, $json);
 98 |     } else {
 99 |       // Output the result
100 |       $this->output($json, $header);
101 |     }
102 |     exit;
103 |   }
104 |   
105 |   function output($result, $header) {
106 |     $charset = get_option('blog_charset');
107 |     if (!headers_sent()) {
108 |       header("HTTP/1.1 $header", true);
109 |       header("Content-Type: application/json; charset=$charset", true);
110 |     }
111 |     echo $result;
112 |   }
113 |   
114 |   function callback($callback, $result) {
115 |     $charset = get_option('blog_charset');
116 |     if (!headers_sent()) {
117 |       header('HTTP/1.1 200 OK', true);
118 |       header("Content-Type: application/javascript; charset=$charset", true);
119 |     }
120 |     echo "$callback($result)";
121 |   }
122 |   
123 |   function add_status_query_var($url, $status) {
124 |     if (strpos($url, '#')) {
125 |       // Remove the anchor hash for now
126 |       $pos = strpos($url, '#');
127 |       $anchor = substr($url, $pos);
128 |       $url = substr($url, 0, $pos);
129 |     }
130 |     if (strpos($url, '?')) {
131 |       $url .= "&status=$status";
132 |     } else {
133 |       $url .= "?status=$status";
134 |     }
135 |     if (!empty($anchor)) {
136 |       // Add the anchor hash back in
137 |       $url .= $anchor;
138 |     }
139 |     return $url;
140 |   }
141 |   
142 |   function prettify($ugly) {
143 |     $pretty = "";
144 |     $indent = "";
145 |     $last = '';
146 |     $pos = 0;
147 |     $level = 0;
148 |     $string = false;
149 |     while ($pos < strlen($ugly)) {
150 |       $char = substr($ugly, $pos++, 1);
151 |       if (!$string) {
152 |         if ($char == '{' || $char == '[') {
153 |           if ($char == '[' && substr($ugly, $pos, 1) == ']') {
154 |             $pretty .= "[]";
155 |             $pos++;
156 |           } else if ($char == '{' && substr($ugly, $pos, 1) == '}') {
157 |             $pretty .= "{}";
158 |             $pos++;
159 |           } else {
160 |             $pretty .= "$char\n";
161 |             $indent = str_repeat('  ', ++$level);
162 |             $pretty .= "$indent";
163 |           }
164 |         } else if ($char == '}' || $char == ']') {
165 |           $indent = str_repeat('  ', --$level);
166 |           if ($last != '}' && $last != ']') {
167 |             $pretty .= "\n$indent";
168 |           } else if (substr($pretty, -2, 2) == '  ') {
169 |             $pretty = substr($pretty, 0, -2);
170 |           }
171 |           $pretty .= $char;
172 |           if (substr($ugly, $pos, 1) == ',') {
173 |             $pretty .= ",";
174 |             $last = ',';
175 |             $pos++;
176 |           }
177 |           $pretty .= "\n$indent";
178 |         } else if ($char == ':') {
179 |           $pretty .= ": ";
180 |         } else if ($char == ',') {
181 |           $pretty .= ",\n$indent";
182 |         } else if ($char == '"') {
183 |           $pretty .= '"';
184 |           $string = true;
185 |         } else {
186 |           $pretty .= $char;
187 |         }
188 |       } else {
189 |         if ($last != '\\' && $char == '"') {
190 |           $string = false;
191 |         }
192 |         $pretty .= $char;
193 |       }
194 |       $last = $char;
195 |     }
196 |     return $pretty;
197 |   }
198 |   
199 |   function replace_unicode_escape_sequence($match) {
200 |     return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
201 |   }
202 |   
203 | }
204 | 
205 | ?>
206 | 


--------------------------------------------------------------------------------
/tests/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PI-Media/json-api/ac348c6c5c2f7379fa129d98cdcef6b6fe5cce4e/tests/.DS_Store


--------------------------------------------------------------------------------
/tests/core.get_author_index-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_author_index
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_author_index&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $author = $response->authors[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Author count: $response->count\n";
15 | echo "Author name: $author->name\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Author count: 1
21 | Author name: themedemos
22 | 


--------------------------------------------------------------------------------
/tests/core.get_author_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_author_posts by slug
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_author_posts&slug=themedemos&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $author = $response->author;
12 | $post = $response->posts[0];
13 | 
14 | echo "Response status: $response->status\n";
15 | echo "Post count: $response->count\n";
16 | echo "First post title: $post->title\n";
17 | 
18 | ?>
19 | --EXPECT--
20 | Response status: ok
21 | Post count: 10
22 | First post title: Markup: HTML Tags and Formatting
23 | 


--------------------------------------------------------------------------------
/tests/core.get_author_posts-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_author_posts by author_slug
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_author_posts&author_slug=themedemos&page=2&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $author = $response->author;
12 | $post = $response->posts[0];
13 | 
14 | echo "Response status: $response->status\n";
15 | echo "Post count: $response->count\n";
16 | echo "First post title: $post->title\n";
17 | 
18 | ?>
19 | --EXPECT--
20 | Response status: ok
21 | Post count: 10
22 | First post title: Template: Paginated
23 | 


--------------------------------------------------------------------------------
/tests/core.get_author_posts-03.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_author_posts by id
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_author_posts&id=2&count=20&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $author = $response->author;
12 | $post = $response->posts[0];
13 | 
14 | echo "Response status: $response->status\n";
15 | echo "Post count: $response->count\n";
16 | echo "First post title: $post->title\n";
17 | 
18 | ?>
19 | --EXPECT--
20 | Response status: ok
21 | Post count: 20
22 | First post title: Markup: HTML Tags and Formatting
23 | 


--------------------------------------------------------------------------------
/tests/core.get_category_index-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_category_index 
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_category_index&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $category = $response->categories[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Category count: $response->count\n";
15 | echo "Category name: $category->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Category count: 63
21 | Category name: aciform
22 | 


--------------------------------------------------------------------------------
/tests/core.get_category_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_category_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_category_posts&slug=markup&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 6
21 | Post title: Markup: HTML Tags and Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.get_date_index-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_search_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_date_index&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $count = count($response->permalinks);
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Permalink count: $count\n";
15 | echo "Tree:\n";
16 | var_dump($response->tree);
17 | 
18 | 
19 | ?>
20 | --EXPECT--
21 | Response status: ok
22 | Permalink count: 20
23 | Tree:
24 | object(stdClass)#5 (5) {
25 |   ["2013"]=>
26 |   object(stdClass)#6 (1) {
27 |     ["01"]=>
28 |     string(1) "5"
29 |   }
30 |   ["2012"]=>
31 |   object(stdClass)#4 (2) {
32 |     ["03"]=>
33 |     string(1) "5"
34 |     ["01"]=>
35 |     string(1) "6"
36 |   }
37 |   ["2011"]=>
38 |   object(stdClass)#7 (1) {
39 |     ["03"]=>
40 |     string(1) "1"
41 |   }
42 |   ["2010"]=>
43 |   object(stdClass)#8 (10) {
44 |     ["10"]=>
45 |     string(1) "1"
46 |     ["09"]=>
47 |     string(1) "2"
48 |     ["08"]=>
49 |     string(1) "3"
50 |     ["07"]=>
51 |     string(1) "1"
52 |     ["06"]=>
53 |     string(1) "3"
54 |     ["05"]=>
55 |     string(1) "1"
56 |     ["04"]=>
57 |     string(1) "1"
58 |     ["03"]=>
59 |     string(1) "1"
60 |     ["02"]=>
61 |     string(1) "1"
62 |     ["01"]=>
63 |     string(1) "1"
64 |   }
65 |   ["2009"]=>
66 |   object(stdClass)#9 (6) {
67 |     ["10"]=>
68 |     string(1) "1"
69 |     ["09"]=>
70 |     string(1) "1"
71 |     ["08"]=>
72 |     string(1) "1"
73 |     ["07"]=>
74 |     string(1) "1"
75 |     ["06"]=>
76 |     string(1) "1"
77 |     ["05"]=>
78 |     string(1) "1"
79 |   }
80 | }
81 | 


--------------------------------------------------------------------------------
/tests/core.get_date_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_date_posts by day
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_date_posts&date=2013-01&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 5
21 | Post title: Markup: HTML Tags and Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.get_date_posts-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_date_posts by month
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_date_posts&date=2013-01&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 5
21 | Post title: Markup: HTML Tags and Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.get_date_posts-03.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_date_posts by year
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_date_posts&date=2012&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 10
21 | Post title: Template: Featured Image (Vertical)
22 | 


--------------------------------------------------------------------------------
/tests/core.get_page-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_page default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_page&slug=about&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | 
12 | echo "Response status: $response->status\n";
13 | echo "Page title: {$response->page->title}\n";
14 | 
15 | 
16 | ?>
17 | --EXPECT--
18 | Response status: ok
19 | Page title: About The Tests
20 | 


--------------------------------------------------------------------------------
/tests/core.get_page-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_page children argument
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_page&slug=level-1&children=1&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $page = $response->page;
12 | $child = $page->children[0];
13 | $grandchild = $child->children[0];
14 | 
15 | echo "Response status: $response->status\n";
16 | echo "Page title: $page->title\n";
17 | echo "Child title: $child->title\n";
18 | echo "Grandchild title: $grandchild->title\n";
19 | 
20 | ?>
21 | --EXPECT--
22 | Response status: ok
23 | Page title: Level 1
24 | Child title: Level 2
25 | Grandchild title: Level 3
26 | 


--------------------------------------------------------------------------------
/tests/core.get_post-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_post default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_post&slug=markup-html-tags-and-formatting&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | 
12 | echo "Response status: $response->status\n";
13 | echo "post title: {$response->post->title}\n";
14 | 
15 | ?>
16 | --EXPECT--
17 | Response status: ok
18 | post title: Markup: HTML Tags and Formatting
19 | 


--------------------------------------------------------------------------------
/tests/core.get_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_posts&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 10
21 | Post title: Markup: HTML Tags and Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.get_posts-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_posts by meta key
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_posts&meta_key=enclosure&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | $attachment = $post->attachments[0];
13 | 
14 | echo "Response status: $response->status\n";
15 | echo "Post count: $response->count\n";
16 | echo "Post title: $post->title\n";
17 | echo "Attachment title: $attachment->title\n";
18 | 
19 | ?>
20 | --EXPECT--
21 | Response status: ok
22 | Post count: 1
23 | Post title: Post Format: Audio
24 | Attachment title: St. Louis Blues
25 | 


--------------------------------------------------------------------------------
/tests/core.get_posts-03.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_posts by meta value
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_posts&meta_key=_wp_old_slug&meta_value=excerpt&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | echo "Post slug: $post->slug\n";
17 | 
18 | ?>
19 | --EXPECT--
20 | Response status: ok
21 | Post count: 1
22 | Post title: Template: Excerpt (Defined)
23 | Post slug: template-excerpt-defined
24 | 


--------------------------------------------------------------------------------
/tests/core.get_recent_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_recent_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_recent_posts&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 11
21 | Post title: Template: Sticky
22 | 


--------------------------------------------------------------------------------
/tests/core.get_recent_posts-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_recent_posts count argument
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_recent_posts&count=3&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[3];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 4
21 | Post title: Markup: Text Alignment
22 | 


--------------------------------------------------------------------------------
/tests/core.get_recent_posts-03.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_recent_posts page argument
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_recent_posts&page=2&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 10
21 | Post title: Template: Paginated
22 | 


--------------------------------------------------------------------------------
/tests/core.get_search_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_search_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_search_results&search=foolish&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 2
21 | Post title: Page Markup And Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.get_tag_index-01.phpt:
--------------------------------------------------------------------------------
  1 | --TEST--
  2 | core.get_tag_index
  3 | --FILE--
  4 | get('http://wordpress.test/?json=core.get_tag_index&dev=1');
  9 | $response = $http->currentResponse();
 10 | $response = json_decode($response['body']);
 11 | 
 12 | echo "Response status: $response->status\n";
 13 | echo "Tag count: $response->count\n";
 14 | echo "Tags:\n";
 15 | var_dump($response->tags);
 16 | 
 17 | ?>
 18 | --EXPECT--
 19 | Response status: ok
 20 | Tag count: 60
 21 | Tags:
 22 | array(60) {
 23 |   [0]=>
 24 |   object(stdClass)#5 (5) {
 25 |     ["id"]=>
 26 |     int(66)
 27 |     ["slug"]=>
 28 |     string(4) "8bit"
 29 |     ["title"]=>
 30 |     string(4) "8BIT"
 31 |     ["description"]=>
 32 |     string(22) "Tags posts about 8BIT."
 33 |     ["post_count"]=>
 34 |     int(1)
 35 |   }
 36 |   [1]=>
 37 |   object(stdClass)#6 (5) {
 38 |     ["id"]=>
 39 |     int(67)
 40 |     ["slug"]=>
 41 |     string(11) "alignment-2"
 42 |     ["title"]=>
 43 |     string(9) "alignment"
 44 |     ["description"]=>
 45 |     string(0) ""
 46 |     ["post_count"]=>
 47 |     int(3)
 48 |   }
 49 |   [2]=>
 50 |   object(stdClass)#4 (5) {
 51 |     ["id"]=>
 52 |     int(68)
 53 |     ["slug"]=>
 54 |     string(8) "articles"
 55 |     ["title"]=>
 56 |     string(8) "Articles"
 57 |     ["description"]=>
 58 |     string(26) "Tags posts about Articles."
 59 |     ["post_count"]=>
 60 |     int(1)
 61 |   }
 62 |   [3]=>
 63 |   object(stdClass)#7 (5) {
 64 |     ["id"]=>
 65 |     int(69)
 66 |     ["slug"]=>
 67 |     string(5) "aside"
 68 |     ["title"]=>
 69 |     string(5) "aside"
 70 |     ["description"]=>
 71 |     string(0) ""
 72 |     ["post_count"]=>
 73 |     int(1)
 74 |   }
 75 |   [4]=>
 76 |   object(stdClass)#8 (5) {
 77 |     ["id"]=>
 78 |     int(70)
 79 |     ["slug"]=>
 80 |     string(5) "audio"
 81 |     ["title"]=>
 82 |     string(5) "audio"
 83 |     ["description"]=>
 84 |     string(0) ""
 85 |     ["post_count"]=>
 86 |     int(1)
 87 |   }
 88 |   [5]=>
 89 |   object(stdClass)#9 (5) {
 90 |     ["id"]=>
 91 |     int(71)
 92 |     ["slug"]=>
 93 |     string(10) "captions-2"
 94 |     ["title"]=>
 95 |     string(8) "captions"
 96 |     ["description"]=>
 97 |     string(0) ""
 98 |     ["post_count"]=>
 99 |     int(2)
100 |   }
101 |   [6]=>
102 |   object(stdClass)#10 (5) {
103 |     ["id"]=>
104 |     int(72)
105 |     ["slug"]=>
106 |     string(10) "categories"
107 |     ["title"]=>
108 |     string(10) "categories"
109 |     ["description"]=>
110 |     string(0) ""
111 |     ["post_count"]=>
112 |     int(2)
113 |   }
114 |   [7]=>
115 |   object(stdClass)#11 (5) {
116 |     ["id"]=>
117 |     int(73)
118 |     ["slug"]=>
119 |     string(4) "chat"
120 |     ["title"]=>
121 |     string(4) "chat"
122 |     ["description"]=>
123 |     string(0) ""
124 |     ["post_count"]=>
125 |     int(2)
126 |   }
127 |   [8]=>
128 |   object(stdClass)#12 (5) {
129 |     ["id"]=>
130 |     int(77)
131 |     ["slug"]=>
132 |     string(5) "codex"
133 |     ["title"]=>
134 |     string(5) "Codex"
135 |     ["description"]=>
136 |     string(0) ""
137 |     ["post_count"]=>
138 |     int(3)
139 |   }
140 |   [9]=>
141 |   object(stdClass)#13 (5) {
142 |     ["id"]=>
143 |     int(78)
144 |     ["slug"]=>
145 |     string(10) "comments-2"
146 |     ["title"]=>
147 |     string(8) "comments"
148 |     ["description"]=>
149 |     string(0) ""
150 |     ["post_count"]=>
151 |     int(4)
152 |   }
153 |   [10]=>
154 |   object(stdClass)#14 (5) {
155 |     ["id"]=>
156 |     int(79)
157 |     ["slug"]=>
158 |     string(9) "content-2"
159 |     ["title"]=>
160 |     string(7) "content"
161 |     ["description"]=>
162 |     string(0) ""
163 |     ["post_count"]=>
164 |     int(12)
165 |   }
166 |   [11]=>
167 |   object(stdClass)#15 (5) {
168 |     ["id"]=>
169 |     int(81)
170 |     ["slug"]=>
171 |     string(3) "css"
172 |     ["title"]=>
173 |     string(3) "css"
174 |     ["description"]=>
175 |     string(0) ""
176 |     ["post_count"]=>
177 |     int(7)
178 |   }
179 |   [12]=>
180 |   object(stdClass)#16 (5) {
181 |     ["id"]=>
182 |     int(85)
183 |     ["slug"]=>
184 |     string(6) "dowork"
185 |     ["title"]=>
186 |     string(6) "dowork"
187 |     ["description"]=>
188 |     string(25) "Tags posts about #dowork."
189 |     ["post_count"]=>
190 |     int(1)
191 |   }
192 |   [13]=>
193 |   object(stdClass)#17 (5) {
194 |     ["id"]=>
195 |     int(86)
196 |     ["slug"]=>
197 |     string(9) "edge-case"
198 |     ["title"]=>
199 |     string(9) "edge case"
200 |     ["description"]=>
201 |     string(0) ""
202 |     ["post_count"]=>
203 |     int(8)
204 |   }
205 |   [14]=>
206 |   object(stdClass)#18 (5) {
207 |     ["id"]=>
208 |     int(87)
209 |     ["slug"]=>
210 |     string(8) "embeds-2"
211 |     ["title"]=>
212 |     string(6) "embeds"
213 |     ["description"]=>
214 |     string(0) ""
215 |     ["post_count"]=>
216 |     int(4)
217 |   }
218 |   [15]=>
219 |   object(stdClass)#19 (5) {
220 |     ["id"]=>
221 |     int(91)
222 |     ["slug"]=>
223 |     string(9) "excerpt-2"
224 |     ["title"]=>
225 |     string(7) "excerpt"
226 |     ["description"]=>
227 |     string(0) ""
228 |     ["post_count"]=>
229 |     int(3)
230 |   }
231 |   [16]=>
232 |   object(stdClass)#20 (5) {
233 |     ["id"]=>
234 |     int(92)
235 |     ["slug"]=>
236 |     string(4) "fail"
237 |     ["title"]=>
238 |     string(4) "Fail"
239 |     ["description"]=>
240 |     string(22) "Tags posts about fail."
241 |     ["post_count"]=>
242 |     int(1)
243 |   }
244 |   [17]=>
245 |   object(stdClass)#21 (5) {
246 |     ["id"]=>
247 |     int(93)
248 |     ["slug"]=>
249 |     string(14) "featured-image"
250 |     ["title"]=>
251 |     string(14) "featured image"
252 |     ["description"]=>
253 |     string(0) ""
254 |     ["post_count"]=>
255 |     int(3)
256 |   }
257 |   [18]=>
258 |   object(stdClass)#22 (5) {
259 |     ["id"]=>
260 |     int(96)
261 |     ["slug"]=>
262 |     string(12) "formatting-2"
263 |     ["title"]=>
264 |     string(10) "formatting"
265 |     ["description"]=>
266 |     string(0) ""
267 |     ["post_count"]=>
268 |     int(1)
269 |   }
270 |   [19]=>
271 |   object(stdClass)#23 (5) {
272 |     ["id"]=>
273 |     int(97)
274 |     ["slug"]=>
275 |     string(3) "ftw"
276 |     ["title"]=>
277 |     string(3) "FTW"
278 |     ["description"]=>
279 |     string(0) ""
280 |     ["post_count"]=>
281 |     int(1)
282 |   }
283 |   [20]=>
284 |   object(stdClass)#24 (5) {
285 |     ["id"]=>
286 |     int(98)
287 |     ["slug"]=>
288 |     string(3) "fun"
289 |     ["title"]=>
290 |     string(3) "Fun"
291 |     ["description"]=>
292 |     string(21) "Tags posts about fun."
293 |     ["post_count"]=>
294 |     int(1)
295 |   }
296 |   [21]=>
297 |   object(stdClass)#25 (5) {
298 |     ["id"]=>
299 |     int(99)
300 |     ["slug"]=>
301 |     string(7) "gallery"
302 |     ["title"]=>
303 |     string(7) "gallery"
304 |     ["description"]=>
305 |     string(0) ""
306 |     ["post_count"]=>
307 |     int(3)
308 |   }
309 |   [22]=>
310 |   object(stdClass)#26 (5) {
311 |     ["id"]=>
312 |     int(105)
313 |     ["slug"]=>
314 |     string(4) "html"
315 |     ["title"]=>
316 |     string(4) "html"
317 |     ["description"]=>
318 |     string(0) ""
319 |     ["post_count"]=>
320 |     int(5)
321 |   }
322 |   [23]=>
323 |   object(stdClass)#27 (5) {
324 |     ["id"]=>
325 |     int(106)
326 |     ["slug"]=>
327 |     string(5) "image"
328 |     ["title"]=>
329 |     string(5) "image"
330 |     ["description"]=>
331 |     string(0) ""
332 |     ["post_count"]=>
333 |     int(7)
334 |   }
335 |   [24]=>
336 |   object(stdClass)#28 (5) {
337 |     ["id"]=>
338 |     int(109)
339 |     ["slug"]=>
340 |     string(9) "jetpack-2"
341 |     ["title"]=>
342 |     string(7) "jetpack"
343 |     ["description"]=>
344 |     string(0) ""
345 |     ["post_count"]=>
346 |     int(3)
347 |   }
348 |   [25]=>
349 |   object(stdClass)#29 (5) {
350 |     ["id"]=>
351 |     int(111)
352 |     ["slug"]=>
353 |     string(6) "layout"
354 |     ["title"]=>
355 |     string(6) "layout"
356 |     ["description"]=>
357 |     string(0) ""
358 |     ["post_count"]=>
359 |     int(4)
360 |   }
361 |   [26]=>
362 |   object(stdClass)#30 (5) {
363 |     ["id"]=>
364 |     int(112)
365 |     ["slug"]=>
366 |     string(4) "link"
367 |     ["title"]=>
368 |     string(4) "link"
369 |     ["description"]=>
370 |     string(0) ""
371 |     ["post_count"]=>
372 |     int(2)
373 |   }
374 |   [27]=>
375 |   object(stdClass)#31 (5) {
376 |     ["id"]=>
377 |     int(113)
378 |     ["slug"]=>
379 |     string(7) "lists-2"
380 |     ["title"]=>
381 |     string(5) "lists"
382 |     ["description"]=>
383 |     string(0) ""
384 |     ["post_count"]=>
385 |     int(1)
386 |   }
387 |   [28]=>
388 |   object(stdClass)#32 (5) {
389 |     ["id"]=>
390 |     int(115)
391 |     ["slug"]=>
392 |     string(4) "love"
393 |     ["title"]=>
394 |     string(4) "Love"
395 |     ["description"]=>
396 |     string(22) "Tags posts about love."
397 |     ["post_count"]=>
398 |     int(1)
399 |   }
400 |   [29]=>
401 |   object(stdClass)#33 (5) {
402 |     ["id"]=>
403 |     int(116)
404 |     ["slug"]=>
405 |     string(8) "markup-2"
406 |     ["title"]=>
407 |     string(6) "markup"
408 |     ["description"]=>
409 |     string(0) ""
410 |     ["post_count"]=>
411 |     int(6)
412 |   }
413 |   [30]=>
414 |   object(stdClass)#34 (5) {
415 |     ["id"]=>
416 |     int(117)
417 |     ["slug"]=>
418 |     string(5) "media"
419 |     ["title"]=>
420 |     string(5) "media"
421 |     ["description"]=>
422 |     string(0) ""
423 |     ["post_count"]=>
424 |     int(1)
425 |   }
426 |   [31]=>
427 |   object(stdClass)#35 (5) {
428 |     ["id"]=>
429 |     int(122)
430 |     ["slug"]=>
431 |     string(10) "mothership"
432 |     ["title"]=>
433 |     string(10) "Mothership"
434 |     ["description"]=>
435 |     string(29) "Tags posts about motherships."
436 |     ["post_count"]=>
437 |     int(1)
438 |   }
439 |   [32]=>
440 |   object(stdClass)#36 (5) {
441 |     ["id"]=>
442 |     int(123)
443 |     ["slug"]=>
444 |     string(8) "mustread"
445 |     ["title"]=>
446 |     string(9) "Must Read"
447 |     ["description"]=>
448 |     string(40) "Tags posts about articles you must read."
449 |     ["post_count"]=>
450 |     int(1)
451 |   }
452 |   [33]=>
453 |   object(stdClass)#37 (5) {
454 |     ["id"]=>
455 |     int(124)
456 |     ["slug"]=>
457 |     string(8) "nailedit"
458 |     ["title"]=>
459 |     string(9) "Nailed It"
460 |     ["description"]=>
461 |     string(32) "Tags posts about that nailed it."
462 |     ["post_count"]=>
463 |     int(1)
464 |   }
465 |   [34]=>
466 |   object(stdClass)#38 (5) {
467 |     ["id"]=>
468 |     int(126)
469 |     ["slug"]=>
470 |     string(10) "pagination"
471 |     ["title"]=>
472 |     string(10) "pagination"
473 |     ["description"]=>
474 |     string(0) ""
475 |     ["post_count"]=>
476 |     int(1)
477 |   }
478 |   [35]=>
479 |   object(stdClass)#39 (5) {
480 |     ["id"]=>
481 |     int(128)
482 |     ["slug"]=>
483 |     string(10) "password-2"
484 |     ["title"]=>
485 |     string(8) "password"
486 |     ["description"]=>
487 |     string(0) ""
488 |     ["post_count"]=>
489 |     int(1)
490 |   }
491 |   [36]=>
492 |   object(stdClass)#40 (5) {
493 |     ["id"]=>
494 |     int(129)
495 |     ["slug"]=>
496 |     string(8) "pictures"
497 |     ["title"]=>
498 |     string(8) "Pictures"
499 |     ["description"]=>
500 |     string(0) ""
501 |     ["post_count"]=>
502 |     int(1)
503 |   }
504 |   [37]=>
505 |   object(stdClass)#41 (5) {
506 |     ["id"]=>
507 |     int(130)
508 |     ["slug"]=>
509 |     string(11) "pingbacks-2"
510 |     ["title"]=>
511 |     string(9) "pingbacks"
512 |     ["description"]=>
513 |     string(0) ""
514 |     ["post_count"]=>
515 |     int(1)
516 |   }
517 |   [38]=>
518 |   object(stdClass)#42 (5) {
519 |     ["id"]=>
520 |     int(133)
521 |     ["slug"]=>
522 |     string(4) "post"
523 |     ["title"]=>
524 |     string(4) "post"
525 |     ["description"]=>
526 |     string(0) ""
527 |     ["post_count"]=>
528 |     int(1)
529 |   }
530 |   [39]=>
531 |   object(stdClass)#43 (5) {
532 |     ["id"]=>
533 |     int(38)
534 |     ["slug"]=>
535 |     string(12) "post-formats"
536 |     ["title"]=>
537 |     string(12) "Post Formats"
538 |     ["description"]=>
539 |     string(0) ""
540 |     ["post_count"]=>
541 |     int(16)
542 |   }
543 |   [40]=>
544 |   object(stdClass)#44 (5) {
545 |     ["id"]=>
546 |     int(139)
547 |     ["slug"]=>
548 |     string(5) "quote"
549 |     ["title"]=>
550 |     string(5) "quote"
551 |     ["description"]=>
552 |     string(0) ""
553 |     ["post_count"]=>
554 |     int(2)
555 |   }
556 |   [41]=>
557 |   object(stdClass)#45 (5) {
558 |     ["id"]=>
559 |     int(141)
560 |     ["slug"]=>
561 |     string(9) "read-more"
562 |     ["title"]=>
563 |     string(9) "read more"
564 |     ["description"]=>
565 |     string(0) ""
566 |     ["post_count"]=>
567 |     int(1)
568 |   }
569 |   [42]=>
570 |   object(stdClass)#46 (5) {
571 |     ["id"]=>
572 |     int(142)
573 |     ["slug"]=>
574 |     string(11) "readability"
575 |     ["title"]=>
576 |     string(11) "readability"
577 |     ["description"]=>
578 |     string(0) ""
579 |     ["post_count"]=>
580 |     int(1)
581 |   }
582 |   [43]=>
583 |   object(stdClass)#47 (5) {
584 |     ["id"]=>
585 |     int(145)
586 |     ["slug"]=>
587 |     string(9) "shortcode"
588 |     ["title"]=>
589 |     string(9) "shortcode"
590 |     ["description"]=>
591 |     string(0) ""
592 |     ["post_count"]=>
593 |     int(6)
594 |   }
595 |   [44]=>
596 |   object(stdClass)#48 (5) {
597 |     ["id"]=>
598 |     int(147)
599 |     ["slug"]=>
600 |     string(10) "standard-2"
601 |     ["title"]=>
602 |     string(8) "standard"
603 |     ["description"]=>
604 |     string(0) ""
605 |     ["post_count"]=>
606 |     int(2)
607 |   }
608 |   [45]=>
609 |   object(stdClass)#49 (5) {
610 |     ["id"]=>
611 |     int(148)
612 |     ["slug"]=>
613 |     string(6) "status"
614 |     ["title"]=>
615 |     string(6) "status"
616 |     ["description"]=>
617 |     string(0) ""
618 |     ["post_count"]=>
619 |     int(1)
620 |   }
621 |   [46]=>
622 |   object(stdClass)#50 (5) {
623 |     ["id"]=>
624 |     int(149)
625 |     ["slug"]=>
626 |     string(8) "sticky-2"
627 |     ["title"]=>
628 |     string(6) "sticky"
629 |     ["description"]=>
630 |     string(0) ""
631 |     ["post_count"]=>
632 |     int(1)
633 |   }
634 |   [47]=>
635 |   object(stdClass)#51 (5) {
636 |     ["id"]=>
637 |     int(150)
638 |     ["slug"]=>
639 |     string(7) "success"
640 |     ["title"]=>
641 |     string(7) "Success"
642 |     ["description"]=>
643 |     string(25) "Tags posts about success."
644 |     ["post_count"]=>
645 |     int(1)
646 |   }
647 |   [48]=>
648 |   object(stdClass)#52 (5) {
649 |     ["id"]=>
650 |     int(151)
651 |     ["slug"]=>
652 |     string(7) "swagger"
653 |     ["title"]=>
654 |     string(7) "Swagger"
655 |     ["description"]=>
656 |     string(25) "Tags posts about swagger."
657 |     ["post_count"]=>
658 |     int(1)
659 |   }
660 |   [49]=>
661 |   object(stdClass)#53 (5) {
662 |     ["id"]=>
663 |     int(158)
664 |     ["slug"]=>
665 |     string(4) "tags"
666 |     ["title"]=>
667 |     string(4) "Tags"
668 |     ["description"]=>
669 |     string(33) "Tags posts about tags. #inception"
670 |     ["post_count"]=>
671 |     int(1)
672 |   }
673 |   [50]=>
674 |   object(stdClass)#54 (5) {
675 |     ["id"]=>
676 |     int(159)
677 |     ["slug"]=>
678 |     string(8) "template"
679 |     ["title"]=>
680 |     string(8) "template"
681 |     ["description"]=>
682 |     string(0) ""
683 |     ["post_count"]=>
684 |     int(12)
685 |   }
686 |   [51]=>
687 |   object(stdClass)#55 (5) {
688 |     ["id"]=>
689 |     int(163)
690 |     ["slug"]=>
691 |     string(5) "tiled"
692 |     ["title"]=>
693 |     string(5) "tiled"
694 |     ["description"]=>
695 |     string(0) ""
696 |     ["post_count"]=>
697 |     int(1)
698 |   }
699 |   [52]=>
700 |   object(stdClass)#56 (5) {
701 |     ["id"]=>
702 |     int(164)
703 |     ["slug"]=>
704 |     string(5) "title"
705 |     ["title"]=>
706 |     string(5) "title"
707 |     ["description"]=>
708 |     string(0) ""
709 |     ["post_count"]=>
710 |     int(5)
711 |   }
712 |   [53]=>
713 |   object(stdClass)#57 (5) {
714 |     ["id"]=>
715 |     int(165)
716 |     ["slug"]=>
717 |     string(12) "trackbacks-2"
718 |     ["title"]=>
719 |     string(10) "trackbacks"
720 |     ["description"]=>
721 |     string(0) ""
722 |     ["post_count"]=>
723 |     int(1)
724 |   }
725 |   [54]=>
726 |   object(stdClass)#58 (5) {
727 |     ["id"]=>
728 |     int(166)
729 |     ["slug"]=>
730 |     string(9) "twitter-2"
731 |     ["title"]=>
732 |     string(7) "twitter"
733 |     ["description"]=>
734 |     string(0) ""
735 |     ["post_count"]=>
736 |     int(2)
737 |   }
738 |   [55]=>
739 |   object(stdClass)#59 (5) {
740 |     ["id"]=>
741 |     int(168)
742 |     ["slug"]=>
743 |     string(6) "unseen"
744 |     ["title"]=>
745 |     string(6) "Unseen"
746 |     ["description"]=>
747 |     string(46) "Tags posts about things that cannot be unseen."
748 |     ["post_count"]=>
749 |     int(1)
750 |   }
751 |   [56]=>
752 |   object(stdClass)#60 (5) {
753 |     ["id"]=>
754 |     int(169)
755 |     ["slug"]=>
756 |     string(5) "video"
757 |     ["title"]=>
758 |     string(5) "video"
759 |     ["description"]=>
760 |     string(0) ""
761 |     ["post_count"]=>
762 |     int(3)
763 |   }
764 |   [57]=>
765 |   object(stdClass)#61 (5) {
766 |     ["id"]=>
767 |     int(170)
768 |     ["slug"]=>
769 |     string(10) "videopress"
770 |     ["title"]=>
771 |     string(10) "videopress"
772 |     ["description"]=>
773 |     string(0) ""
774 |     ["post_count"]=>
775 |     int(2)
776 |   }
777 |   [58]=>
778 |   object(stdClass)#62 (5) {
779 |     ["id"]=>
780 |     int(172)
781 |     ["slug"]=>
782 |     string(9) "wordpress"
783 |     ["title"]=>
784 |     string(9) "WordPress"
785 |     ["description"]=>
786 |     string(27) "Tags posts about WordPress."
787 |     ["post_count"]=>
788 |     int(1)
789 |   }
790 |   [59]=>
791 |   object(stdClass)#63 (5) {
792 |     ["id"]=>
793 |     int(173)
794 |     ["slug"]=>
795 |     string(12) "wordpress-tv"
796 |     ["title"]=>
797 |     string(12) "wordpress.tv"
798 |     ["description"]=>
799 |     string(0) ""
800 |     ["post_count"]=>
801 |     int(2)
802 |   }
803 | }
804 | 


--------------------------------------------------------------------------------
/tests/core.get_tag_posts-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_tag_posts default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.get_tag_posts&slug=css&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $post = $response->posts[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Post count: $response->count\n";
15 | echo "Post title: $post->title\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Post count: 7
21 | Post title: Markup: HTML Tags and Formatting
22 | 


--------------------------------------------------------------------------------
/tests/core.info-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.info default
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.info&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | 
12 | echo "Response status: $response->status\n";
13 | echo "Controllers:\n";
14 | var_dump($response->controllers);
15 | 
16 | ?>
17 | --EXPECT--
18 | Response status: ok
19 | Controllers:
20 | array(4) {
21 |   [0]=>
22 |   string(4) "core"
23 |   [1]=>
24 |   string(5) "posts"
25 |   [2]=>
26 |   string(7) "respond"
27 |   [3]=>
28 |   string(7) "widgets"
29 | }
30 | 


--------------------------------------------------------------------------------
/tests/core.info-02.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.info controller detail
 3 | --FILE--
 4 | get('http://wordpress.test/?json=core.info&controller=core&dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | 
12 | echo "Response status: $response->status\n";
13 | echo "Name: $response->name\n";
14 | echo "Description: $response->description\n";
15 | echo "Methods:\n";
16 | var_dump($response->methods);
17 | 
18 | ?>
19 | --EXPECT--
20 | Response status: ok
21 | Name: Core
22 | Description: Basic introspection methods
23 | Methods:
24 | array(16) {
25 |   [0]=>
26 |   string(4) "info"
27 |   [1]=>
28 |   string(16) "get_recent_posts"
29 |   [2]=>
30 |   string(9) "get_posts"
31 |   [3]=>
32 |   string(8) "get_post"
33 |   [4]=>
34 |   string(8) "get_page"
35 |   [5]=>
36 |   string(14) "get_date_posts"
37 |   [6]=>
38 |   string(18) "get_category_posts"
39 |   [7]=>
40 |   string(13) "get_tag_posts"
41 |   [8]=>
42 |   string(16) "get_author_posts"
43 |   [9]=>
44 |   string(18) "get_search_results"
45 |   [10]=>
46 |   string(14) "get_date_index"
47 |   [11]=>
48 |   string(18) "get_category_index"
49 |   [12]=>
50 |   string(13) "get_tag_index"
51 |   [13]=>
52 |   string(16) "get_author_index"
53 |   [14]=>
54 |   string(14) "get_page_index"
55 |   [15]=>
56 |   string(9) "get_nonce"
57 | }
58 | 


--------------------------------------------------------------------------------
/tests/query-01.phpt:
--------------------------------------------------------------------------------
 1 | --TEST--
 2 | core.get_author_index with user-friendly URLs
 3 | --FILE--
 4 | get('http://wordpress.test/api/core/get_author_index?dev=1');
 9 | $response = $http->currentResponse();
10 | $response = json_decode($response['body']);
11 | $author = $response->authors[0];
12 | 
13 | echo "Response status: $response->status\n";
14 | echo "Author count: $response->count\n";
15 | echo "Author name: $author->name\n";
16 | 
17 | ?>
18 | --EXPECT--
19 | Response status: ok
20 | Author count: 1
21 | Author name: themedemos
22 | 


--------------------------------------------------------------------------------