├── .gitignore ├── LICENSE ├── admin ├── class-settings-page.php ├── class-users-profile.php └── class-welcome-dashboard.php ├── assets └── images │ ├── owned-minifig-widget.png │ └── theme-years-widget.png ├── banner-1544x500.png ├── banner-772x250.png ├── brickset-api.php ├── inc ├── class-oembed.php ├── class-search-functions.php ├── class-shortcodes.php ├── class-template-tags.php ├── class-update-functions.php ├── class-utilities.php └── widgets │ ├── class-minifig-owned-widget.php │ ├── class-set-widget.php │ ├── class-theme-widget.php │ └── class-theme-years-widget.php ├── languages ├── default.mo └── default.po ├── readme.md ├── readme.txt ├── screenshot-1.png ├── screenshot-2.png ├── screenshot-3.png └── webservice-definition.json /.gitignore: -------------------------------------------------------------------------------- 1 | # osx noise 2 | .DS_Store 3 | profile 4 | 5 | # xcode noise 6 | build/* 7 | *.mode1 8 | *.mode1v3 9 | *.mode2v3 10 | *.perspective 11 | *.perspectivev3 12 | *.pbxuser 13 | *.xcworkspace 14 | xcuserdata 15 | 16 | # svn & cvs 17 | .svn 18 | CVS -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /admin/class-settings-page.php: -------------------------------------------------------------------------------- 1 | 46 |
47 |

48 |

49 | 50 |
51 | 52 | 53 | 54 |
55 |
56 | Brickset.com"; 132 | 133 | } 134 | 135 | /** 136 | * Displays the text field for the API Key 137 | * 138 | * @author Nate Jacobs 139 | * @date 2/2/13 140 | * @since 1.0 141 | */ 142 | public function apikey_callback() 143 | { 144 | $settings = (array) get_option( 'brickset-api-settings' ); 145 | $api_key = isset( $settings['api_key'] ) ? esc_attr( $settings['api_key'] ) : ''; 146 | 147 | echo ""; 148 | 149 | } 150 | 151 | /** 152 | * Displays the template tag settings header 153 | * 154 | * @author Nate Jacobs 155 | * @date 6/1/13 156 | * @since 1.3 157 | */ 158 | public function template_settings_callback() 159 | { 160 | echo __( 'These settings control what is displayed when you use the provided template tags, shortcodes, widgets and oembed.', 'bs_api' ); 161 | 162 | } 163 | 164 | /** 165 | * Displays the radio options for currency 166 | * 167 | * @author Nate Jacobs 168 | * @date 6/1/13 169 | * @since 1.3 170 | */ 171 | public function currency_callback() 172 | { 173 | $settings = (array) get_option( 'brickset-api-settings' ); 174 | $currency = isset( $settings['currency'] ) ? esc_attr( $settings['currency'] ) : ''; 175 | $currency_unk = isset( $settings['currency_unknown'] ) ? esc_attr( $settings['currency_unknown'] ) : ''; 176 | 177 | echo ""; 178 | echo "
"; 179 | echo "
"; 180 | echo "

". __( 'If no retail price is available for the currency selected the plugin should', 'bs_api' ).":"; 181 | echo "

"; 182 | echo "
"; 183 | echo "

".__( 'Brickset provides retail prices in US dollars, CA dollars, and UK pound sterling ', 'bs_api' ).""; 184 | 185 | } 186 | 187 | /** 188 | * Control if the Bricklink link should be appended to the set display 189 | * 190 | * @author Nate Jacobs 191 | * @date 6/2/13 192 | * @since 1.3 193 | */ 194 | public function bricklink_callback() 195 | { 196 | $settings = (array) get_option( 'brickset-api-settings' ); 197 | $bricklink = isset( $settings['bricklink_link'] ) ? esc_attr( $settings['bricklink_link'] ) : ''; 198 | 199 | echo ""; 200 | echo "
"; 201 | } 202 | 203 | /** 204 | * Control how long the transient is kept for 205 | * 206 | * @author Nate Jacobs 207 | * @date 6/3/13 208 | * @since 1.3 209 | */ 210 | public function transient_callback() 211 | { 212 | $settings = (array) get_option( 'brickset-api-settings' ); 213 | $transient = isset( $settings['transient'] ) ? esc_attr( $settings['transient'] ) : ''; 214 | 215 | echo ""; 216 | echo "
"; 217 | echo "
"; 218 | echo "

".__( 'The plugin uses the WordPress Transient API to store the data returned from Brickset to reduce page load times. By increasing the time the data is stored it requires fewer requests to Brickset. However, if the data changes frequently then your site will display out-of-date data until the cache expires.', 'bs_api' ).""; 219 | } 220 | } 221 | 222 | $brickset_settings = new BricksetAPISettingsPage(); -------------------------------------------------------------------------------- /admin/class-users-profile.php: -------------------------------------------------------------------------------- 1 | get_user_hash( $user->ID ); 40 | ?> 41 |

42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
57 | brickset_login( $user_id, sanitize_text_field( $_POST['bs_user_name'] ), $_POST['bs_password'] ); 77 | 78 | if( is_wp_error( $response ) ) 79 | { 80 | wp_die( $response->get_error_message(), 'brickset-login-error', array( 'back_link' => true ) ); 81 | } 82 | } 83 | } 84 | } 85 | 86 | $brickset_user_profile = new BricksetAPIUserProfile; -------------------------------------------------------------------------------- /admin/class-welcome-dashboard.php: -------------------------------------------------------------------------------- 1 | minimum_capability, 56 | 'bs-about', 57 | array( $this, 'about_screen' ) 58 | ); 59 | 60 | add_dashboard_page( 61 | __( 'Welcome to Brickset API', 'bs_api' ), 62 | __( 'Welcome to Brickset API', 'bs_api' ), 63 | $this->minimum_capability, 64 | 'bs-credits', 65 | array( $this, 'credits_screen' ) 66 | ); 67 | } 68 | 69 | /** 70 | * Hide Individual Dashboard Pages 71 | * 72 | * @date 9/12/13 73 | * @since 1.4.0 74 | */ 75 | public function admin_head() { 76 | remove_submenu_page( 'index.php', 'bs-about' ); 77 | remove_submenu_page( 'index.php', 'bs-credits' ); 78 | ?> 79 | 87 | 99 |
100 |

101 |
102 | 103 | 110 | 111 |
112 |

113 |
114 | 115 |

116 |

117 | 118 |

119 |

120 | 121 | 122 |
123 |
124 | 125 |
126 |

127 |
128 |

129 |

130 | add_filter('bs_get_themes_transient', 'bs_api_change_theme_cache_time'); 131 | 132 |

133 |

134 | 135 |
136 |
137 |
138 | 139 |
140 |
141 | 153 |
154 |

155 |
156 | 157 | 164 | 165 |

166 | 167 | contributors(); ?> 168 |
169 | get_contributors(); 181 | 182 | if ( empty( $contributors ) ) 183 | return ''; 184 | 185 | $contributor_list = ''; 201 | 202 | return $contributor_list; 203 | } 204 | 205 | /** 206 | * Retreive list of contributors from GitHub. 207 | * 208 | * @date 9/12/13 209 | * @since 1.4.0 210 | */ 211 | public function get_contributors() { 212 | $contributors = get_transient( 'bs_api_contributors' ); 213 | 214 | if ( false !== $contributors ) 215 | return $contributors; 216 | 217 | $response = wp_remote_get( 'https://api.github.com/repos/NateJacobs/Brickset-API/contributors', array( 'sslverify' => false ) ); 218 | 219 | if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) 220 | return array(); 221 | 222 | $contributors = json_decode( wp_remote_retrieve_body( $response ) ); 223 | 224 | if ( ! is_array( $contributors ) ) 225 | return array(); 226 | 227 | set_transient( 'bs_api_contributors', $contributors, 3600 ); 228 | 229 | return $contributors; 230 | } 231 | 232 | /** 233 | * Sends user to the Welcome page on first activation and upgrade 234 | * 235 | * @date 9/12/13 236 | * @since 1.4.0 237 | */ 238 | public function welcome() { 239 | 240 | // Bail if no activation redirect 241 | if ( ! get_transient( '_bs_api_activation_redirect' ) ) 242 | return; 243 | 244 | // Delete the redirect transient 245 | delete_transient( '_bs_api_activation_redirect' ); 246 | 247 | // Bail if activating from network, or bulk 248 | if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) 249 | return; 250 | 251 | wp_safe_redirect( admin_url( 'index.php?page=bs-about' ) ); exit; 252 | } 253 | } 254 | new BricksetWelcome(); -------------------------------------------------------------------------------- /assets/images/owned-minifig-widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/assets/images/owned-minifig-widget.png -------------------------------------------------------------------------------- /assets/images/theme-years-widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/assets/images/theme-years-widget.png -------------------------------------------------------------------------------- /banner-1544x500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/banner-1544x500.png -------------------------------------------------------------------------------- /banner-772x250.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/banner-772x250.png -------------------------------------------------------------------------------- /brickset-api.php: -------------------------------------------------------------------------------- 1 | Brickset.com. 7 | * Version: 1.4.1 8 | * License: GPL V2 9 | * Author: Nate Jacobs 10 | * Author URI: http://natejacobs.org 11 | */ 12 | 13 | class BricksetAPILoad 14 | { 15 | /** 16 | * Hook into the necessary actions to load the constants and call 17 | * the includes and admin classes. 18 | * 19 | * @author Nate Jacobs 20 | * @since 0.1 21 | */ 22 | public function __construct() 23 | { 24 | add_action( 'init', array( $this, 'localization' ), 1 ); 25 | add_action( 'plugins_loaded', array( $this, 'constants' ), 2 ); 26 | add_action( 'plugins_loaded', array( $this, 'includes' ), 3 ); 27 | add_action( 'plugins_loaded', array( $this, 'admin' ), 4 ); 28 | add_filter( 'http_request_timeout', array( $this, 'http_request_timeout' ) ); 29 | 30 | register_activation_hook( __FILE__, array( $this, 'install' ) ); 31 | } 32 | 33 | /** 34 | * Define the constants used through out the plugin. 35 | * 36 | * @author Nate Jacobs 37 | * @since 0.1 38 | */ 39 | public function constants() 40 | { 41 | define( 'BRICKSET_API_VERSION', '1.4.1' ); 42 | define( 'BRICKSET_API_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); 43 | define( 'BRICKSET_API_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) ); 44 | define( 'BRICKSET_API_INCLUDES', BRICKSET_API_DIR . trailingslashit( 'inc' ) ); 45 | define( 'BRICKSET_API_ADMIN', BRICKSET_API_DIR . trailingslashit( 'admin' ) ); 46 | } 47 | 48 | /** 49 | * Load the files containing the classes in the includes folder. 50 | * 51 | * @author Nate Jacobs 52 | * @since 0.1 53 | */ 54 | public function includes() 55 | { 56 | require_once( BRICKSET_API_INCLUDES . 'class-utilities.php' ); 57 | require_once( BRICKSET_API_INCLUDES . 'class-search-functions.php' ); 58 | require_once( BRICKSET_API_INCLUDES . 'class-oembed.php' ); 59 | require_once( BRICKSET_API_INCLUDES . 'widgets/class-theme-widget.php' ); 60 | require_once( BRICKSET_API_INCLUDES . 'widgets/class-theme-years-widget.php' ); 61 | require_once( BRICKSET_API_INCLUDES . 'widgets/class-set-widget.php' ); 62 | require_once( BRICKSET_API_INCLUDES . 'widgets/class-minifig-owned-widget.php' ); 63 | require_once( BRICKSET_API_INCLUDES . 'class-template-tags.php' ); 64 | require_once( BRICKSET_API_INCLUDES . 'class-shortcodes.php' ); 65 | require_once( BRICKSET_API_INCLUDES . 'class-update-functions.php' ); 66 | } 67 | 68 | /** 69 | * Load the files containing the classes in the admin folder 70 | * 71 | * @author Nate Jacobs 72 | * @since 0.1 73 | */ 74 | public function admin() 75 | { 76 | if ( is_admin() ) 77 | { 78 | require_once( BRICKSET_API_ADMIN . 'class-settings-page.php' ); 79 | require_once( BRICKSET_API_ADMIN . 'class-users-profile.php' ); 80 | require_once( BRICKSET_API_ADMIN . 'class-welcome-dashboard.php' ); 81 | } 82 | } 83 | 84 | /** 85 | * Declare text domain to use in translation. 86 | * 87 | * @author Nate Jacobs 88 | * @since 0.3 89 | */ 90 | public function localization() 91 | { 92 | load_plugin_textdomain( 'bs_api', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); 93 | } 94 | 95 | /** 96 | * Sometimes requests take longer than 5 seconds 97 | * 98 | * @author Nate Jacobs 99 | * @date 3/13/13 100 | * @since 1.0 101 | * 102 | * @param int $seconds 103 | */ 104 | public function http_request_timeout ( $seconds ) 105 | { 106 | return $seconds < 10 ? 15 : $seconds; 107 | } 108 | 109 | /** 110 | * Ensure the currency and Bricklink options are set. 111 | * The default will be US dollars and yes. 112 | * 113 | * @author Nate Jacobs 114 | * @date 9/12/13 115 | * @since 1.4 116 | */ 117 | public function install() 118 | { 119 | $settings = (array) get_option( 'brickset-api-settings' ); 120 | 121 | if( !isset( $settings['currency'] ) ) 122 | { 123 | $settings['currency'] = 'us'; 124 | update_option( 'brickset-api-settings', $settings ); 125 | } 126 | 127 | if( !isset( $settings['currency_unknown'] ) ) 128 | { 129 | $settings['currency_unknown'] = 'us'; 130 | update_option( 'brickset-api-settings', $settings ); 131 | } 132 | 133 | if( !isset( $settings['bricklink_link'] ) ) 134 | { 135 | $settings['bricklink_link'] = '1'; 136 | update_option( 'brickset-api-settings', $settings ); 137 | } 138 | 139 | // Bail if activating from network, or bulk 140 | if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) 141 | return; 142 | 143 | // Add the transient to redirect 144 | set_transient( '_bs_api_activation_redirect', true, 30 ); 145 | } 146 | } 147 | 148 | $brickset_load = new BricksetAPILoad(); -------------------------------------------------------------------------------- /inc/class-oembed.php: -------------------------------------------------------------------------------- 1 | get_key(); 38 | // Create our own oembed url 39 | $oembed_url = add_query_arg ( array ( 'brickset_oembed' => $key ), $oembed_url); 40 | 41 | wp_oembed_add_provider( '#https?://(www\.)?brickset.com/detail/\?Set\=.*/?#i', $oembed_url, true ); 42 | wp_oembed_add_provider( '#https?://(www\.)?brickset.com/browse/themes/\?theme\=.*/?#i', $oembed_url, true ); 43 | } 44 | 45 | /** 46 | * Create a random key to prevent hijacking 47 | * 48 | * @author Nate Jacobs 49 | * @date 3/10/13 50 | * @since 1.0 51 | * 52 | * @return string 53 | */ 54 | private function get_key() 55 | { 56 | 57 | $key = get_option ( 'brickset_oembed_key' ); 58 | 59 | if ( !$key ) { 60 | $key = md5 ( time() . rand ( 0,65535 ) ); 61 | add_option ( 'brickset_oembed_key', $key, '', 'yes' ); 62 | } 63 | 64 | return $key; 65 | 66 | } 67 | 68 | /** 69 | * Test if the correct key is present in the URL passed 70 | * 71 | * @author Nate Jacobs 72 | * @date 3/10/13 73 | * @since 1.0 74 | */ 75 | public function maybe_handle_oembed() 76 | { 77 | // If the query argument is there hand 78 | if ( isset ( $_GET['brickset_oembed'] ) ) 79 | { 80 | // Hand it off to the handle_oembed function 81 | return $this->handle_oembed(); 82 | } 83 | } 84 | 85 | /** 86 | * Takes care of formating the URL to call the Brickset API 87 | * 88 | * @author Nate Jacobs 89 | * @date 3/10/13 90 | * @since 1.0 91 | */ 92 | public function handle_oembed() 93 | { 94 | // Did we get here by mistake? 95 | if ( ! isset ( $_GET['brickset_oembed'] ) ) 96 | { 97 | // If so, get out of here 98 | return; 99 | } 100 | // Check this request is valid 101 | if ( $_GET['brickset_oembed'] != $this->get_key() ) 102 | { 103 | header ( 'HTTP/1.0 403 Forbidden' ); 104 | die ( 'Forbidden.' ); 105 | } 106 | 107 | // Check we have the required information 108 | $url = isset ( $_REQUEST['url'] ) ? $_REQUEST['url'] : null; 109 | $format = isset ( $_REQUEST['format'] ) ? $_REQUEST['format'] : null; 110 | 111 | if( !empty ( $format ) && $format != 'json' ) 112 | { 113 | header( 'HTTP/1.0 501 Not implemented' ); 114 | die( 'Only json allowed' ); 115 | } 116 | 117 | // Check if URL passed contains the string 'detail/?Set=' 118 | if( false !== strpos( $url, 'detail/?Set=' ) ) 119 | { 120 | // If it does, separate on this string 121 | $set_id = explode( '?Set=', $url ); 122 | 123 | // Is there additional arguments passed, if so only get what is before the & 124 | if( false !== strpos( $url, '&' ) ) 125 | $set_id[1] = strstr( $set_id[1], '&', true ); 126 | 127 | // Send it on to the Set method 128 | $this->oembed_set( $set_id[1] ); 129 | } 130 | // Now we are checking if the URL passed contains the string 'browse/themes/?theme=' 131 | elseif( false !== strpos( $url, 'browse/themes/?theme=' ) ) 132 | { 133 | // If it does, separate on this string 134 | $theme_name = explode( '?theme=', $url ); 135 | 136 | // Is there additional arguments passed, if so only get what is before the & 137 | if( false !== strpos( $url, '&' ) ) 138 | $theme_name[1] = strstr( $theme_name[1], '&', true ); 139 | 140 | // Convert %20 and other urlencoded strings to non urlencoded 141 | // The build_query method encodes them later 142 | $theme = urldecode( $theme_name[1] ); 143 | 144 | // Send it on to the set method 145 | $this->oembed_theme( $theme ); 146 | } 147 | else 148 | { 149 | header ( 'HTTP/1.0 404 Not Found' ); 150 | die( 'Invalid oembed' ); 151 | } 152 | } 153 | 154 | /** 155 | * Takes a set number from the Brickset URL and displays information about the set 156 | * 157 | * @author Nate Jacobs 158 | * @date 3/10/13 159 | * @since 1.0 160 | * 161 | * @param string the set number to display information about 162 | */ 163 | public function oembed_set( $set_number ) 164 | { 165 | // Call the API function 166 | $brickset = parent::get_by_number( $set_number ); 167 | 168 | // Build the Oembed class 169 | $response = new stdClass(); 170 | $response->type = 'rich'; 171 | $response->width = '10'; 172 | $response->height = '10'; 173 | $response->version = '1.0'; 174 | $response->title = $brickset->setData->setName; 175 | $response->html = '
'; 176 | 177 | // Check for errors 178 | if( is_wp_error( $brickset ) ) 179 | { 180 | $response->html .= '

'.$brickset->get_error_message().'

'; 181 | } 182 | else 183 | { 184 | global $brickset_api_utilities; 185 | $settings = $brickset_api_utilities->get_settings_rules(); 186 | 187 | $number = ''; 188 | $numberVariant = ''; 189 | 190 | if( true === $settings['bricklink'] ) 191 | { 192 | $bricklink = ''.__( 'BrickLink', 'bs_api' ).': BrickLink

'; 193 | } 194 | elseif( false === $settings['bricklink'] ) 195 | { 196 | $bricklink = ''; 197 | } 198 | 199 | // Loop through and display the set information 200 | foreach( $brickset as $result ) 201 | { 202 | $number = sanitize_text_field( $result->number ); 203 | $numberVariant = sanitize_text_field( $result->numberVariant ); 204 | 205 | if( empty( $result->$settings['currency_key'] ) && 'unk' === $settings['currency_unknown'] ) 206 | { 207 | $result->$settings['currency_key'] = __( ' Unknown', 'bs_api' ); 208 | } 209 | 210 | if( empty( $result->$settings['currency_key'] ) && 'us' === $settings['currency_unknown'] ) 211 | { 212 | $settings['currency'] = 'US'; 213 | $settings['currency_key'] = 'USRetailPrice'; 214 | $settings['currency_symbol'] = '$'; 215 | } 216 | 217 | $response->html .= '
'; 218 | $response->html .= ''.__( 'Set Name', 'bs_api' ).': '.sanitize_text_field( $result->setName ).'
'; 219 | $response->html .= ''.__( 'Set Number', 'bs_api' ).': '.$number.'-'.$numberVariant.'
'; 220 | $response->html .= ''.__( 'Year', 'bs_api' ).': '.sanitize_text_field( $result->year ).'
'; 221 | $response->html .= ''.__( 'Theme', 'bs_api' ).': '.sanitize_text_field( $result->theme ).'
'; 222 | $response->html .= ''.__( 'Subtheme', 'bs_api' ).': '.sanitize_text_field( $result->subtheme ).'
'; 223 | $response->html .= ''.sprintf( __( '%s Retail Price', 'bs_api' ), $settings['currency'] ).': '.$settings['currency_symbol'].sanitize_text_field( $result->$settings['currency_key'] ).'
'; 224 | $response->html .= ''.__( 'Pieces', 'bs_api' ).': '.sanitize_text_field( $result->pieces ).'
'; 225 | $response->html .= ''.__( 'Minifigs', 'bs_api' ).': '.sanitize_text_field( $result->minifigs ).'
'; 226 | $response->html .= ''.__( 'Set Guide', 'bs_api' ).': Brickset
'; 227 | $response->html .= $bricklink; 228 | } 229 | } 230 | 231 | $response->html .= '
'; 232 | 233 | header ( 'Content-Type: application/json' ); 234 | echo json_encode ( $response ); 235 | die(); 236 | } 237 | 238 | /** 239 | * Takes a theme name from the Brickset URL and displays information about all the sets in that theme in a table 240 | * 241 | * @author Nate Jacobs 242 | * @date 3/10/13 243 | * @since 1.0 244 | * 245 | * @param string the theme to display 246 | */ 247 | public function oembed_theme( $theme ) 248 | { 249 | // Call the API function 250 | $brickset = parent::get_by_theme( $theme ); 251 | 252 | // Build the Oembed class 253 | $response = new stdClass(); 254 | $response->type = 'rich'; 255 | $response->width = '10'; 256 | $response->height = '10'; 257 | $response->version = '1.0'; 258 | $response->title = 'Theme List'; 259 | $response->html = '
'; 260 | 261 | // Check for errors 262 | if( is_wp_error( $brickset ) ) 263 | { 264 | $response->html .= '

'.$brickset->get_error_message().'

'; 265 | } 266 | else 267 | { 268 | // Loop through and display the info about the sets in the theme 269 | $response->html .= ''; 270 | 271 | foreach ( $brickset as $updated ) 272 | { 273 | $response->html .= ''; 274 | $response->html .= ''; 275 | $response->html .= ''; 276 | $response->html .= ''; 277 | $response->html .= ''; 278 | $response->html .= ''; 279 | $response->html .= ''; 280 | } 281 | 282 | $response->html .= '
'. __( 'Image', 'bs_api' ).''. __( 'Set Name', 'bs_api' ).''. __( 'Set Number', 'bs_api' ).''. __( 'Year', 'bs_api' ).''. __( 'Pieces', 'bs_api' ).'
'.$updated->setName.''.$updated->number.'-'.$updated->numberVariant.''.$updated->year.''.$updated->pieces.'
'; 283 | } 284 | $response->html .= '
'; 285 | 286 | header ( 'Content-Type: application/json' ); 287 | echo json_encode ( $response ); 288 | die(); 289 | } 290 | } 291 | $brickset_oembed = new BricksetOembed(); -------------------------------------------------------------------------------- /inc/class-search-functions.php: -------------------------------------------------------------------------------- 1 | remote_request( 'get', 'listThemes' ); 37 | 38 | if( is_wp_error( $response ) ) 39 | { 40 | return $response; 41 | } 42 | set_transient( $transient, $response, apply_filters( 'bs_get_themes_transient', DAY_IN_SECONDS ) ); 43 | } 44 | 45 | // Return a SimpleXML object 46 | return new SimpleXMLElement( get_transient( $transient ) ); 47 | 48 | } 49 | 50 | /** 51 | * Get a list of all subthemes for a given theme 52 | * 53 | * Brickset returns the subthemeData response. 54 | * See webservice-definition.json for all the fields returned. 55 | * 56 | * @author Nate Jacobs 57 | * @since 0.1 58 | * @updated 1.0 59 | * 60 | * @param string 61 | * 62 | * @return object 63 | */ 64 | public function get_subthemes( $theme ) 65 | { 66 | // Is it a valid string 67 | if( is_wp_error( $validate_theme = $this->validate_theme_subtheme( $theme ) ) ) 68 | return $validate_theme; 69 | 70 | $theme = sanitize_text_field( strtolower( $theme ) ); 71 | $transient_theme = str_replace( " ", "", $theme ); 72 | 73 | $transient = 'bs_'.$transient_theme.'_subthemes'; 74 | 75 | // Have we stored a transient? 76 | if( false === get_transient( $transient ) ) 77 | { 78 | $args = array( 'theme' => $theme ); 79 | 80 | $params = $this->build_bs_query( $args ); 81 | $response = $this->remote_request( 'get', 'listSubthemes', $params ); 82 | 83 | if( is_wp_error( $response ) ) 84 | { 85 | return $response; 86 | } 87 | set_transient( $transient, $response, apply_filters( 'bs_get_subthemes_transient', DAY_IN_SECONDS ) ); 88 | } 89 | 90 | // Get it and return a SimpleXML object 91 | return new SimpleXMLElement( get_transient( $transient ) ); 92 | } 93 | 94 | /** 95 | * Get a list of years a theme was available 96 | * 97 | * Brickset returns the yearData response. 98 | * See webservice-definition.json for all the fields returned. 99 | * 100 | * @author Nate Jacobs 101 | * @since 0.1 102 | * @updated 1.0 103 | * 104 | * @param string 105 | * 106 | * @return object 107 | */ 108 | public function get_theme_years( $theme ) 109 | { 110 | // Is it a valid string 111 | if( is_wp_error( $validate_theme = $this->validate_theme_subtheme( $theme ) ) ) 112 | return $validate_theme; 113 | 114 | $theme = sanitize_text_field( strtolower( $theme ) ); 115 | $transient_theme = str_replace( " ", "", $theme ); 116 | 117 | $transient = 'bs_'.$transient_theme.'_years'; 118 | 119 | // Have we stored a transient? 120 | if( false === get_transient( $transient ) ) 121 | { 122 | $args = array( 'theme' => $theme ); 123 | 124 | $params = $this->build_bs_query( $args ); 125 | $response = $this->remote_request( 'get', 'listYears', $params ); 126 | 127 | if( is_wp_error( $response ) ) 128 | { 129 | return $response; 130 | } 131 | set_transient( $transient, $response, apply_filters( 'bs_get_theme_years_transient', DAY_IN_SECONDS ) ); 132 | } 133 | 134 | // Get it and return a SimpleXML object 135 | return new SimpleXMLElement( get_transient( $transient ) ); 136 | 137 | } 138 | 139 | /** 140 | * Get a list of the most searched for terms 141 | * 142 | * Brickset returns the searchData response 143 | * See webservice-definition.json for all the fields returned. 144 | * 145 | * @author Nate Jacobs 146 | * @since 0.1 147 | * @updated 1.0 148 | * 149 | * @return object 150 | */ 151 | public function get_popular_searches() 152 | { 153 | $transient = 'bs_popular_searches'; 154 | 155 | // Have we stored a transient? 156 | if( false === get_transient( $transient ) ) 157 | { 158 | $response = $this->remote_request( 'get', 'popularSearches' ); 159 | 160 | if( is_wp_error( $response ) ) 161 | { 162 | return $response; 163 | } 164 | set_transient( $transient, $response, apply_filters( 'bs_get_popular_searches_transient', HOUR_IN_SECONDS ) ); 165 | } 166 | 167 | // Get it and return a SimpleXML object 168 | return new SimpleXMLElement( get_transient( $transient ) ); 169 | } 170 | 171 | /** 172 | * Get all sets updated since a given date 173 | * 174 | * Brickset returns the setData response. 175 | * See webservice-definition.json for all the fields returned. 176 | * 177 | * @author Nate Jacobs 178 | * @since 0.1 179 | * @updated 1.0 180 | * 181 | * @param string use format of 'mm/dd/yyyy' 182 | * 183 | * @return object 184 | */ 185 | public function get_updated_since( $date ) 186 | { 187 | $exploded_date = explode( '/', $date ); 188 | 189 | // Is this a date in the correct format? 190 | if( false === checkdate( $exploded_date[0], $exploded_date[1], $exploded_date[2] ) ) 191 | return new WP_Error( 'not-a-date-format', __( 'The date is not formatted correctly.', 'bs_api' ) ); 192 | 193 | // Is it a valid year 194 | if( is_wp_error( $validate_year = $this->validate_year( $exploded_date[2] ) ) ) 195 | return $validate_year; 196 | 197 | $transient_date = str_replace( '/', '', $date ); 198 | 199 | $transient = 'bs_updated_since_'.$transient_date; 200 | 201 | // Have we stored a transient? 202 | if( false === get_transient( $transient ) ) 203 | { 204 | $params = 'apiKey='.$this->get_api_key().'&sinceDate='.$date; 205 | $response = $this->remote_request( 'get', 'updatedSince', $params ); 206 | 207 | if( is_wp_error( $response ) ) 208 | { 209 | return $response; 210 | } 211 | set_transient( $transient, $response, apply_filters( 'bs_get_updated_since_transient', DAY_IN_SECONDS ) ); 212 | } 213 | 214 | // Get it and return a SimpleXML object 215 | return new SimpleXMLElement( get_transient( $transient ) ); 216 | } 217 | 218 | /** 219 | * Get Set Info by Number 220 | * 221 | * Pass a set number and get all the information about that set. 222 | * Returns the setData response. 223 | * See webservice-definition.json for all the fields returned. 224 | * 225 | * @author Nate Jacobs 226 | * @since 0.1 227 | * @updated 1.0 228 | * 229 | * @param string set number 230 | * @param int user_id 231 | * @param bool true = return wanted 232 | * @param bool true = return owned 233 | * 234 | * @return object 235 | */ 236 | public function get_by_number( $number = '', $args = '' ) 237 | { 238 | $defaults = array( 239 | 'owned' => false, 240 | 'wanted' => false, 241 | 'user_id' => '' 242 | ); 243 | 244 | // Is there a number? 245 | if( empty( $number ) ) 246 | return new WP_Error( 'no-set-number', __( 'No set number requested.', 'bs_api' ) ); 247 | 248 | // Check on the number for variants 249 | if( is_wp_error( $sets = $this->validate_set_number( $number ) ) ) 250 | return $sets; 251 | 252 | $args['set_number'] = $sets; 253 | 254 | $args = wp_parse_args( $args, $defaults ); 255 | 256 | return $this->search( $args ); 257 | } 258 | 259 | /** 260 | * Get Wanted Sets 261 | * 262 | * Get all the wanted sets by the specified user. 263 | * Returns the setData response. 264 | * See webservice-definition.json for all the fields returned. 265 | * 266 | * @author Nate Jacobs 267 | * @since 0.2 268 | * @updated 1.0 269 | * 270 | * @param int user ID 271 | * 272 | * @return object 273 | */ 274 | public function get_wanted( $user_id = '' ) 275 | { 276 | // Is there a user? 277 | if( empty( $user_id ) ) 278 | return new WP_Error( 'no-user-specified', __( 'No user specified.', 'bs_api' ) ); 279 | 280 | $args['user_id'] = $user_id; 281 | $args['wanted'] = true; 282 | 283 | return $this->search( $args ); 284 | } 285 | 286 | /** 287 | * Get Owned Sets 288 | * 289 | * Get all the sets owned by the specified user. 290 | * Returns the setData resposne. 291 | * See webservice-definition.json for all the fields returned. 292 | * 293 | * @author Nate Jacobs 294 | * @since 0.3 295 | * @updated 1.0 296 | * 297 | * @param int user_id 298 | * 299 | * @return object 300 | */ 301 | public function get_owned( $user_id = '' ) 302 | { 303 | // Is there a user? 304 | if( empty( $user_id ) ) 305 | return new WP_Error( 'no-user-specified', __( 'No user specified.', 'bs_api' ) ); 306 | 307 | $args['user_id'] = $user_id; 308 | $args['owned'] = true; 309 | 310 | return $this->search( $args ); 311 | } 312 | 313 | 314 | /** 315 | * Get Set Info by Theme 316 | * 317 | * Pass a theme and get all the information about the sets in that theme. 318 | * Returns the setData response. 319 | * See webservice-definition.json for all the fields returned. 320 | * 321 | * @author Nate Jacobs 322 | * @since 0.1 323 | * @updated 1.0 324 | * 325 | * @param string 326 | * @param array user_id, owned, wanted 327 | * @param int 328 | * @param bool 329 | * @param bool 330 | * 331 | * @return object 332 | */ 333 | public function get_by_theme( $theme = '', $args = '' ) 334 | { 335 | $defaults = array( 336 | 'owned' => false, 337 | 'wanted' => false, 338 | 'user_id' => '' 339 | ); 340 | 341 | // Is there a theme? 342 | if( empty( $theme ) ) 343 | return new WP_Error( 'no-theme', __( 'No theme requested.', 'bs_api' ) ); 344 | 345 | $args['theme'] = $theme; 346 | 347 | $args = wp_parse_args( $args, $defaults ); 348 | 349 | return $this->search( $args ); 350 | } 351 | 352 | /** 353 | * Get Set Info by Subtheme 354 | * 355 | * Pass a subtheme and get all the information about the sets in that subtheme. 356 | * Returns the setData response. 357 | * See webservice-definition.json for all the fields returned. 358 | * 359 | * @author Nate Jacobs 360 | * @since 0.1 361 | * @updated 1.0 362 | * 363 | * @param int 364 | * @param array (user_id, owned, wanted) 365 | * @param int 366 | * @param int 367 | * @param int 368 | * 369 | * @return object 370 | */ 371 | public function get_by_subtheme( $subtheme = '', $args = '' ) 372 | { 373 | $defaults = array( 374 | 'owned' => false, 375 | 'wanted' => false, 376 | 'user_id' => '' 377 | ); 378 | 379 | // Is there a subtheme? 380 | if( empty( $subtheme ) ) 381 | return new WP_Error( 'no-subtheme', __( 'No subtheme requested.', 'bs_api' ) ); 382 | 383 | $args['subtheme'] = $subtheme; 384 | 385 | $args = wp_parse_args( $args, $defaults ); 386 | 387 | return $this->search( $args ); 388 | } 389 | 390 | /** 391 | * Get Set Info by Year 392 | * 393 | * Pass a year and get all the information about the sets produced that year. 394 | * Returns the setData response 395 | * See webservice-definition.json for all the fields returned. 396 | * 397 | * @author Nate Jacobs 398 | * @since 0.1 399 | * @updated 1.0 400 | * 401 | * @param int 402 | * @param array user_id, owned, wanted 403 | * @param int 404 | * @param int 405 | * @param int 406 | * 407 | * @return object 408 | */ 409 | public function get_by_year( $year = '', $args = '' ) 410 | { 411 | $defaults = array( 412 | 'owned' => false, 413 | 'wanted' => false, 414 | 'user_id' => '' 415 | ); 416 | 417 | // Is there a year? 418 | if( empty( $year ) ) 419 | return new WP_Error( 'no-year', __( 'No year requested.', 'bs_api' ) ); 420 | 421 | $args['year'] = $year; 422 | 423 | $args = wp_parse_args( $args, $defaults ); 424 | 425 | return $this->search( $args ); 426 | } 427 | 428 | /** 429 | * Get Instructions 430 | * 431 | * Retrieve instructions link by Brickset set ID. 432 | * Returns the instructionsData response 433 | * See webservice-definition.json for all the fields returned. 434 | * 435 | * @author Nate Jacobs 436 | * @date 3/22/13 437 | * @since 1.1 438 | * 439 | * @param string 440 | * 441 | * @return object 442 | */ 443 | public function get_instructions( $set_id = '' ) 444 | { 445 | // Is there a setID? 446 | if( empty( $set_id ) ) 447 | return new WP_Error( 'no-set-id', __( 'No set ID requested.', 'bs_api' ) ); 448 | 449 | // Is the string numeric 450 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 451 | return $validate_set_id; 452 | 453 | $transient = 'bs_instructions'.$set_id; 454 | 455 | // Have we stored a transient? 456 | if( false === get_transient( $transient ) ) 457 | { 458 | $params = 'setID='.$set_id; 459 | $response = $this->remote_request( 'get', 'listInstructions', $params ); 460 | 461 | if( is_wp_error( $response ) ) 462 | { 463 | return $response; 464 | } 465 | set_transient( $transient, $response, apply_filters( 'bs_get_instructions_transient', DAY_IN_SECONDS ) ); 466 | } 467 | 468 | // Get it and return a SimpleXML object 469 | return new SimpleXMLElement( get_transient( $transient ) ); 470 | } 471 | 472 | /** 473 | * Get by Set ID 474 | * 475 | * Retrieves a single set by Brickset internal set ID 476 | * Returns the setData response 477 | * See webservice-definition.json for all the fields returned. 478 | * 479 | * @author Nate Jacobs 480 | * @date 3/24/13 481 | * @since 1.1 482 | * 483 | * @param string 484 | * 485 | * @return object 486 | */ 487 | public function get_by_set_id( $set_id ) 488 | { 489 | // Is there a setID? 490 | if( empty( $set_id ) ) 491 | return new WP_Error( 'no-set-id', __( 'No set ID requested.', 'bs_api' ) ); 492 | 493 | // Is the string numeric 494 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 495 | return $validate_set_id; 496 | 497 | $transient = 'bs_set_id_search_'.$set_id; 498 | 499 | // Have we stored a transient? 500 | if( false === get_transient( $transient ) ) 501 | { 502 | $params = 'setID='.$set_id; 503 | $response = $this->remote_request( 'get', 'searchBySetID', $params ); 504 | 505 | if( is_wp_error( $response ) ) 506 | { 507 | return $response; 508 | } 509 | set_transient( $transient, $response, apply_filters( 'bs_get_by_set_id_transient', DAY_IN_SECONDS ) ); 510 | } 511 | 512 | // Get it and return a SimpleXML object 513 | return new SimpleXMLElement( get_transient( $transient ) ); 514 | } 515 | 516 | /** 517 | * Search the Brickset DB with a given set of criteria 518 | * 519 | * Provides method for searching Brickset's set database 520 | * Returns the setData response 521 | * See webservice-definition.json for all the fields returned. 522 | * 523 | * @author Nate Jacobs 524 | * @since 0.1 525 | * 526 | * @param array theme, subtheme, set number, year, owned, wanted, query, user id 527 | * 528 | * @return object 529 | */ 530 | public function search( $args = '' ) 531 | { 532 | $defaults = array( 533 | 'theme' => '', 534 | 'subtheme' => '', 535 | 'set_number'=> '', 536 | 'year' => '', 537 | 'owned' => false, 538 | 'wanted' => false, 539 | 'query' => '', 540 | 'user_id' => '' 541 | ); 542 | 543 | // Is there any criteria to search? 544 | if( empty( $args ) ) 545 | return new WP_Error( 'no-search-criteria', __( 'No search criteria specified.', 'bs_api' ) ); 546 | 547 | $args = wp_parse_args( $args, $defaults ); 548 | 549 | // Is it a valid year 550 | if( !empty( $args['year'] ) ) 551 | { 552 | if( is_wp_error( $validate_year = $this->validate_year( $args['year'] ) ) ) 553 | return $validate_year; 554 | } 555 | 556 | // Is it a valid user_id? 557 | if( !empty( $args['user_id'] ) ) 558 | { 559 | if( is_wp_error( $validate_user = $this->validate_user( $args['user_id'] ) ) ) 560 | return $validate_user; 561 | } 562 | 563 | // Is it a valid string 564 | if( !empty( $args['theme'] ) || !empty( $args['subtheme'] ) ) 565 | { 566 | if( is_wp_error( $validate_string = $this->validate_theme_subtheme( $args['theme'], $args['subtheme'] ) ) ) 567 | return $validate_string; 568 | } 569 | 570 | // Is it a valid string? 571 | if( !empty( $args['query'] ) ) 572 | { 573 | if( !is_string( $args['query'] ) ) 574 | return new WP_Error( 'not-valid-query', __( 'The query requested is not a valid string.', 'bs_api' ) ); 575 | } 576 | 577 | // Was a true or false passed for owned and wanted? 578 | if( is_wp_error( $validate_owned_wanted = $this->validate_owned_wanted( $args['owned'], $args['wanted'] ) ) ) 579 | return $validate_owned_wanted; 580 | 581 | if( is_wp_error( $sets = $this->validate_set_number( $args['set_number'] ) ) ) 582 | return $sets; 583 | 584 | $args['set_number'] = $sets; 585 | 586 | $args['theme'] = strtolower( $args['theme'] ); 587 | $args['subtheme'] = strtolower( $args['subtheme'] ); 588 | $args['query'] = strtolower( $args['query'] ); 589 | 590 | $transient_sets = str_replace( array( ',', '-' ), '', $args['set_number'] ); 591 | $transient_year = str_replace( ",", '', $args['year'] ); 592 | $transient_theme = str_replace( array( ',', '-', " " ), '', $args['theme'] ); 593 | $transient_subtheme = str_replace( array( ',', '-', " " ), '', $args['subtheme'] ); 594 | $transient_query = str_replace( array( ',', '-', " " ), '', $args['query'] ); 595 | 596 | $transient = 'bs_search_'.$transient_theme.$transient_subtheme.$transient_sets.$transient_year.$transient_query.'_user-'.$args['user_id'].'_want-'.$args['wanted'].'_own-'.$args['owned']; 597 | 598 | if( false === get_transient( $transient ) ) 599 | { 600 | $params = $this->build_bs_query( $args ); 601 | $response = $this->remote_request( 'get', 'search', $params ); 602 | 603 | if( is_wp_error( $response ) ) 604 | { 605 | return $response; 606 | } 607 | set_transient( $transient, $response, apply_filters( 'bs_search_transient', DAY_IN_SECONDS ) ); 608 | } 609 | 610 | return new SimpleXMLElement( get_transient( $transient ) ); 611 | } 612 | 613 | /** 614 | * Get Minifig Collection 615 | * 616 | * Retrieve a list of all minifigs owned or wanted by a user that optionally match a query. 617 | * Leave owned and wanted blank to retrieve those owned and wanted, or set one of them to '1' to get just owned or just wanted. 618 | * Query can be a complete minifig number (e.g. 'hp001'), or just a prefix (e.g. 'hp'). Leave blank to retrieve all. 619 | * Returns the minifigCollectionData response 620 | * See webservice-definition.json for all the fields returned. 621 | * 622 | * @author Nate Jacobs 623 | * @date 3/28/13 624 | * @since 1.1 625 | * 626 | * @param int 627 | * @param array query, owned, wanted 628 | * 629 | * @return object 630 | */ 631 | public function get_minifig_collection( $user_id, $args = '' ) 632 | { 633 | $defaults = array( 634 | 'query' => '', 635 | 'owned' => '', 636 | 'wanted' => '' 637 | ); 638 | 639 | if( empty( $args ) ) 640 | return new WP_Error( 'missing-arguments', __( 'You must include at least one of the following: query, owned, or wanted.', 'bs_api' ) ); 641 | 642 | $args = wp_parse_args( $args, $defaults ); 643 | 644 | // Is it a valid user? 645 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 646 | return $validate_user; 647 | 648 | // Is it a valid string? 649 | if( !empty( $args['query'] ) ) 650 | { 651 | if( !is_string( $args['query'] ) ) 652 | return new WP_Error( 'not-valid-query', __( 'The query requested is not a valid string.', 'bs_api' ) ); 653 | } 654 | 655 | // Was a true or false passed for owned? 656 | if( !empty( $args['owned'] ) ) 657 | { 658 | if( is_wp_error( $validate_owned = $this->validate_owned_wanted( $args['owned'] ) ) ) 659 | return $validate_owned; 660 | } 661 | 662 | // Was a true or false passed for wanted? 663 | if( !empty( $args['wanted'] ) ) 664 | { 665 | if( is_wp_error( $validate_wanted = $this->validate_owned_wanted( $args['wanted'] ) ) ) 666 | return $validate_wanted; 667 | } 668 | 669 | $args['query'] = strtolower( $args['query'] ); 670 | 671 | $transient_query = str_replace( array( ',', '-', " " ), '', $args['query'] ); 672 | 673 | $transient = 'bs_minifig_'.$transient_query.'_user-'.$user_id.'_want-'.$args['wanted'].'_own-'.$args['owned']; 674 | 675 | if( false === get_transient( $transient ) ) 676 | { 677 | $params = array( 678 | 'body' => array( 679 | 'userHash' => $this->get_user_hash( $user_id ), 680 | 'query' => sanitize_text_field( $args['query'] ), 681 | 'owned' => $args['owned'], 682 | 'wanted' => $args['wanted'] 683 | ) 684 | ); 685 | 686 | $response = $this->remote_request( 'post', 'searchMinifigCollection', $params ); 687 | 688 | if( is_wp_error( $response ) ) 689 | { 690 | return $response; 691 | } 692 | set_transient( $transient, $response, apply_filters( 'bs_get_minifig_collection_transient', DAY_IN_SECONDS ) ); 693 | } 694 | 695 | return new SimpleXMLElement( get_transient( $transient ) ); 696 | } 697 | } -------------------------------------------------------------------------------- /inc/class-shortcodes.php: -------------------------------------------------------------------------------- 1 | '', 36 | ), $atts, 'bs_set' ) ); 37 | 38 | $brickset = parent::get_by_number( $number ); 39 | 40 | if( is_wp_error( $brickset ) ) 41 | { 42 | return $brickset->get_error_message(); 43 | } 44 | else 45 | { 46 | global $brickset_api_utilities; 47 | $settings = $brickset_api_utilities->get_settings_rules(); 48 | 49 | $number = ''; 50 | $numberVariant = ''; 51 | 52 | if( true === $settings['bricklink'] ) 53 | { 54 | $bricklink = ''.__( 'BrickLink', 'bs_api' ).': BrickLink

'; 55 | } 56 | elseif( false === $settings['bricklink'] ) 57 | { 58 | $bricklink = ''; 59 | } 60 | 61 | $return = ''; 62 | 63 | foreach( $brickset as $result ) 64 | { 65 | $number = sanitize_text_field( $result->number ); 66 | $numberVariant = sanitize_text_field( $result->numberVariant ); 67 | 68 | if( empty( $result->$settings['currency_key'] ) && 'unk' === $settings['currency_unknown'] ) 69 | { 70 | $result->$settings['currency_key'] = __( ' Unknown', 'bs_api' ); 71 | } 72 | 73 | if( empty( $result->$settings['currency_key'] ) && 'us' === $settings['currency_unknown'] ) 74 | { 75 | $settings['currency'] = 'US'; 76 | $settings['currency_key'] = 'USRetailPrice'; 77 | $settings['currency_symbol'] = '$'; 78 | } 79 | 80 | $return .= '
'; 81 | $return .= ''.__( 'Set Name', 'bs_api' ).': '.sanitize_text_field( $result->setName ).'
'; 82 | $return .= ''.__( 'Set Number', 'bs_api' ).': '.$number.'-'.$numberVariant.'
'; 83 | $return .= ''.__( 'Year', 'bs_api' ).': '.sanitize_text_field( $result->year ).'
'; 84 | $return .= ''.__( 'Theme', 'bs_api' ).': '.sanitize_text_field( $result->theme ).'
'; 85 | $return .= ''.__( 'Subtheme', 'bs_api' ).': '.sanitize_text_field( $result->subtheme ).'
'; 86 | $return .= ''.sprintf( __( '%s Retail Price', 'bs_api' ), $settings['currency'] ).': '.$settings['currency_symbol'].sanitize_text_field( $result->$settings['currency_key'] ).'
'; 87 | $return .= ''.__( 'Pieces', 'bs_api' ).': '.sanitize_text_field( $result->pieces ).'
'; 88 | $return .= ''.__( 'Minifigs', 'bs_api' ).': '.sanitize_text_field( $result->minifigs ).'
'; 89 | $return .= ''.__( 'Set Guide', 'bs_api' ).': Brickset
'; 90 | $return .= $bricklink; 91 | } 92 | return $return; 93 | 94 | } 95 | } 96 | 97 | /** 98 | * My Wanted 99 | * 100 | * Returns a table with the post authors wanted sets 101 | * Not functional yet. 102 | * 103 | * @author Nate Jacobs 104 | * @date 2/16/13 105 | * @since 1.0 106 | */ 107 | public function my_wanted() 108 | { 109 | global $post; 110 | $user_id = $post->post_author; 111 | 112 | parent::get_wanted( $user_id ); 113 | 114 | $return = '

My Wanted List

'; 115 | $return .= ''; 116 | foreach ( $this->results as $result ) 117 | { 118 | $return .= ''; 119 | $return .= ''; 120 | $return .= ''; 121 | $return .= ''; 122 | $return .= ''; 123 | $return .= ''; 124 | } 125 | $return .= '
ImageSet NameSet NumberPieces
'.$result->setName.''.$result->number.''.$result->pieces.'
'; 126 | 127 | return $return; 128 | } 129 | 130 | /** 131 | * My Owned 132 | * 133 | * Returns a table with the post authors owned sets 134 | * Not functional yet. 135 | * 136 | * @author Nate Jacobs 137 | * @date 2/16/13 138 | * @since 1.0 139 | */ 140 | public function my_owned() 141 | { 142 | global $post; 143 | $user_id = $post->post_author; 144 | 145 | parent::get_owned( $user_id ); 146 | 147 | $return = '

My Set List

'; 148 | $return .= ''; 149 | foreach ( $this->results as $result ) 150 | { 151 | $return .= ''; 152 | $return .= ''; 153 | $return .= ''; 154 | $return .= ''; 155 | $return .= ''; 156 | $return .= ''; 157 | $return .= ''; 158 | } 159 | $return .= '
ImageSet NameSet NumberPiecesQuantity
'.$result->setName.''.$result->number.''.$result->pieces.''.$result->qtyOwned.'
'; 160 | 161 | return $return; 162 | } 163 | } 164 | $brickset_shortcodes = new BricksetAPIShortcode; -------------------------------------------------------------------------------- /inc/class-template-tags.php: -------------------------------------------------------------------------------- 1 | get_themes(); 17 | 18 | if( is_wp_error( $brickset ) ) 19 | { 20 | echo $brickset->get_error_message(); 21 | } 22 | else 23 | { 24 | foreach ( $brickset as $theme ) 25 | { 26 | echo '

'.$theme->theme.'

'; 27 | } 28 | } 29 | } 30 | 31 | /** 32 | * Display a table of all subthemes for a given theme 33 | * 34 | * Brickset returns the subthemeData response. 35 | * See webservice-definition.json for all the fields returned. 36 | * 37 | * @author Nate Jacobs 38 | * @date 2/2/13 39 | * @since 1.0 40 | * 41 | * @param string 42 | */ 43 | function brickset_subthemes( $theme ) 44 | { 45 | $brickset = new BricksetAPISearch(); 46 | $brickset = $brickset->get_subthemes( $theme ); 47 | 48 | if( is_wp_error( $brickset ) ) 49 | { 50 | echo $brickset->get_error_message(); 51 | } 52 | else 53 | { 54 | echo '

'.$brickset->theme.'

'; 55 | echo ''; 56 | foreach ( $brickset as $subtheme ) 57 | { 58 | echo ''; 59 | echo ''; 60 | echo ''; 61 | echo ''; 62 | echo ''; 63 | echo ''; 64 | } 65 | echo '
'. __( 'Subtheme', 'bs_api' ).''. __( 'Set Count', 'bs_api' ).''. __( 'First Year', 'bs_api' ).''. __( 'Last Year', 'bs_api' ).'
'.$subtheme->subtheme.''.$subtheme->setCount.''.$subtheme->yearFrom.''.$subtheme->yearTo.'
'; 66 | } 67 | } 68 | 69 | /** 70 | * Display a table of years a theme was available 71 | * 72 | * Brickset returns the yearData response. 73 | * See webservice-definition.json for all the fields returned. 74 | * 75 | * @author Nate Jacobs 76 | * @date 2/2/13 77 | * @since 1.0 78 | * 79 | * @param string 80 | */ 81 | function brickset_theme_years( $theme ) 82 | { 83 | $brickset = new BricksetAPISearch(); 84 | $brickset = $brickset->get_theme_years( $theme ); 85 | 86 | if( is_wp_error( $brickset ) ) 87 | { 88 | echo $brickset->get_error_message(); 89 | } 90 | else 91 | { 92 | echo '

'.$brickset->yearData->theme.'

'; 93 | echo ''; 94 | foreach ( $brickset as $year ) 95 | { 96 | echo ''; 97 | echo ''; 98 | echo ''; 99 | echo ''; 100 | } 101 | echo '
'. __( 'Year', 'bs_api' ).''. __( 'Set Count', 'bs_api' ).'
'.$year->year.''.$year->setCount.'
'; 102 | } 103 | } 104 | 105 | /** 106 | * Display a table of the most searched for terms 107 | * 108 | * Brickset returns searchData response. 109 | * See webservice-definition.json for all the fields returned. 110 | * 111 | * @author Nate Jacobs 112 | * @date 2/2/13 113 | * @since 1.0 114 | */ 115 | function brickset_popular_searches() 116 | { 117 | $brickset = new BricksetAPISearch(); 118 | $brickset = $brickset->get_popular_searches(); 119 | 120 | if( is_wp_error( $brickset ) ) 121 | { 122 | echo $brickset->get_error_message(); 123 | } 124 | else 125 | { 126 | echo ''; 127 | foreach ( $brickset as $search ) 128 | { 129 | echo ''; 130 | } 131 | } 132 | } 133 | 134 | /** 135 | * Display a list of all sets updated since a given date 136 | * 137 | * Brickset returns the setData response. 138 | * See webservice-definition.json for all the fields returned. 139 | * 140 | * use format of 'mm/dd/yyyy' 141 | * 142 | * @author Nate Jacobs 143 | * @date 2/2/13 144 | * @since 1.0 145 | * 146 | * @param string 147 | */ 148 | function brickset_updated_since( $date ) 149 | { 150 | $brickset = new BricksetAPISearch(); 151 | $brickset = $brickset->get_updated_since( $date ); 152 | 153 | if( is_wp_error( $brickset ) ) 154 | { 155 | echo $brickset->get_error_message(); 156 | } 157 | else 158 | { 159 | echo ''; 160 | foreach ( $brickset as $updated ) 161 | { 162 | echo ''; 163 | echo ''; 164 | echo ''; 165 | echo ''; 166 | echo ''; 167 | } 168 | echo '
'. __( 'Image', 'bs_api' ).''. __( 'Set Name', 'bs_api' ).''. __( 'Set Number', 'bs_api' ).'
'.$updated->setName.''.$updated->number.'-'.$updated->numberVariant.'
'; 169 | } 170 | } 171 | 172 | /** 173 | * Display a list of all sets specified 174 | * 175 | * Brickset returns the setData response. 176 | * See webservice-definition.json for all the fields returned. 177 | * 178 | * @author Nate Jacobs 179 | * @date 2/15/13 180 | * @since 1.0 181 | * 182 | * @param string the set number 183 | * @param array [owned, wanted, user_id] pass a 1 for the owned or wanted value to return the owned or wanted sets for the specified owner 184 | */ 185 | function brickset_set_number( $set, $args = '' ) 186 | { 187 | $brickset = new BricksetAPISearch(); 188 | $brickset = $brickset->get_by_number( $set, $args ); 189 | 190 | if( is_wp_error( $brickset ) ) 191 | { 192 | echo $brickset->get_error_message(); 193 | } 194 | else 195 | { 196 | global $brickset_api_utilities; 197 | $settings = $brickset_api_utilities->get_settings_rules(); 198 | 199 | $number = ''; 200 | $numberVariant = ''; 201 | 202 | if( true === $settings['bricklink'] ) 203 | { 204 | $bricklink = ''.__( 'BrickLink', 'bs_api' ).': BrickLink

'; 205 | } 206 | elseif( false === $settings['bricklink'] ) 207 | { 208 | $bricklink = ''; 209 | } 210 | 211 | foreach( $brickset as $result ) 212 | { 213 | $number = sanitize_text_field( $result->number ); 214 | $numberVariant = sanitize_text_field( $result->numberVariant ); 215 | 216 | if( empty( $result->$settings['currency_key'] ) && 'unk' === $settings['currency_unknown'] ) 217 | { 218 | $result->$settings['currency_key'] = __( ' Unknown', 'bs_api' ); 219 | } 220 | 221 | if( empty( $result->$settings['currency_key'] ) && 'us' === $settings['currency_unknown'] ) 222 | { 223 | $settings['currency'] = 'US'; 224 | $settings['currency_key'] = 'USRetailPrice'; 225 | $settings['currency_symbol'] = '$'; 226 | } 227 | 228 | echo '
'; 229 | echo ''.__( 'Set Name', 'bs_api' ).': '.sanitize_text_field( $result->setName ).'
'; 230 | echo ''.__( 'Set Number', 'bs_api' ).': '.$number.'-'.$numberVariant.'
'; 231 | echo ''.__( 'Year', 'bs_api' ).': '.sanitize_text_field( $result->year ).'
'; 232 | echo ''.__( 'Theme', 'bs_api' ).': '.sanitize_text_field( $result->theme ).'
'; 233 | echo ''.__( 'Subtheme', 'bs_api' ).': '.sanitize_text_field( $result->subtheme ).'
'; 234 | echo ''.sprintf( __( '%s Retail Price', 'bs_api' ), $settings['currency'] ).': '.$settings['currency_symbol'].sanitize_text_field( $result->$settings['currency_key'] ).'
'; 235 | echo ''.__( 'Pieces', 'bs_api' ).': '.sanitize_text_field( $result->pieces ).'
'; 236 | echo ''.__( 'Minifigs', 'bs_api' ).': '.sanitize_text_field( $result->minifigs ).'
'; 237 | echo ''.__( 'Set Guide', 'bs_api' ).': Brickset
'; 238 | echo $bricklink; 239 | } 240 | } 241 | } -------------------------------------------------------------------------------- /inc/class-update-functions.php: -------------------------------------------------------------------------------- 1 | validate_user( $user_id ) ) ) 36 | return $validate_user; 37 | 38 | // Is the string numeric? 39 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 40 | return $validate_set_id; 41 | 42 | // Is it a valid boolean? 43 | if( is_wp_error( $validate_own = $this->validate_owned_wanted( $own ) ) ) 44 | return $validate_own; 45 | 46 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'setID' => $set_id, 'own' => $own ) ); 47 | 48 | $response = $this->remote_request( 'post', 'updateOwn', $params ); 49 | 50 | $response = (array) simplexml_load_string( $response ); 51 | 52 | if( is_wp_error( $response ) ) 53 | { 54 | return $response; 55 | } 56 | elseif( $response[0] === '1' ) 57 | { 58 | return true; 59 | } 60 | } 61 | 62 | /** 63 | * Update Want 64 | * 65 | * Takes a setID, a userHash, and a 1 or 0 to specify whether the user wants the set or not. 66 | * If successful a 1 is returned. 67 | * 68 | * @author Nate Jacobs 69 | * @date 3/27/13 70 | * @since 1.1 71 | * 72 | * @param string 73 | * @param int 74 | * @param bool 75 | * 76 | * @return bool|object true|WP_Error 77 | */ 78 | public function update_want( $set_id, $user_id, $want ) 79 | { 80 | // Is it a valid user? 81 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 82 | return $validate_user; 83 | 84 | // Is the string numeric? 85 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 86 | return $validate_set_id; 87 | 88 | // Is it a valid boolean? 89 | if( is_wp_error( $validate_want = $this->validate_owned_wanted( $want ) ) ) 90 | return $validate_want; 91 | 92 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'setID' => $set_id, 'want' => $want ) ); 93 | 94 | $response = $this->remote_request( 'post', 'updateWant', $params ); 95 | 96 | $response = (array) simplexml_load_string( $response ); 97 | 98 | if( is_wp_error( $response ) ) 99 | { 100 | return $response; 101 | } 102 | elseif( $response[0] === '1' ) 103 | { 104 | return true; 105 | } 106 | } 107 | 108 | /** 109 | * Update Quantity 110 | * 111 | * Takes a setID, a userHash, and a integer value to specify how many of the set the user owns. 112 | * If successful a 1 is returned. 113 | * 114 | * @author Nate Jacobs 115 | * @date 3/27/13 116 | * @since 1.1 117 | * 118 | * @param string 119 | * @param int 120 | * @param int 121 | * 122 | * @return bool|object true|WP_Error 123 | */ 124 | public function update_quantity( $set_id, $user_id, $quantity ) 125 | { 126 | // Is it a valid user? 127 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 128 | return $validate_user; 129 | 130 | // Is the string numeric? 131 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 132 | return $validate_set_id; 133 | 134 | // Is a quantity value present? 135 | if( !isset( $quantity ) ) 136 | return new WP_Error( 'no-quantity-specified', __( 'No quantity specified.', 'bs_api' ) ); 137 | 138 | // Is quantity an integer? 139 | if( !is_int( $quantity ) ) 140 | return new WP_Error( 'quantity-not-integer', __( 'The quantity is not an integer.', 'bs_api' ) ); 141 | 142 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'setID' => $set_id, 'qty' => $quantity ) ); 143 | 144 | $response = $this->remote_request( 'post', 'updateQtyOwned', $params ); 145 | 146 | $response = (array) simplexml_load_string( $response ); 147 | 148 | if( is_wp_error( $response ) ) 149 | { 150 | return $response; 151 | } 152 | elseif( $response[0] === '1' ) 153 | { 154 | return true; 155 | } 156 | } 157 | 158 | /** 159 | * Update Notes 160 | * 161 | * Takes a setID, a userHash, and a string, which will replace the user's notes for the set. 162 | * If successful a 1 is returned. 163 | * 164 | * @author Nate Jacobs 165 | * @date 3/27/13 166 | * @since 1.1 167 | * 168 | * @param string 169 | * @param int 170 | * @param string 171 | * 172 | * @return bool|object true|WP_Error 173 | */ 174 | public function update_notes( $set_id, $user_id, $notes = '' ) 175 | { 176 | // Is it a valid user? 177 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 178 | return $validate_user; 179 | 180 | // Is the string numeric? 181 | if( is_wp_error( $validate_set_id = $this->validate_set_id( $set_id ) ) ) 182 | return $validate_set_id; 183 | 184 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'setID' => $set_id, 'notes' => sanitize_text_field( $notes ) ) ); 185 | 186 | $response = $this->remote_request( 'post', 'updateUserNotes', $params ); 187 | 188 | $response = (array) simplexml_load_string( $response ); 189 | 190 | if( is_wp_error( $response ) ) 191 | { 192 | return $response; 193 | } 194 | elseif( $response[0] === '1' ) 195 | { 196 | return true; 197 | } 198 | } 199 | 200 | /** 201 | * Update Minifig Quantity 202 | * 203 | * Used to set the quantity of loose minifigs a user has. If successful a 1 is returned. 204 | * 205 | * @author Nate Jacobs 206 | * @date 3/27/13 207 | * @since 1.1 208 | * 209 | * @param string 210 | * @param int 211 | * @param int 212 | * 213 | * @return bool|object true|WP_Error 214 | */ 215 | public function update_minifig_quantity( $minifig_id, $user_id, $quantity ) 216 | { 217 | // Is the minifig_id a string 218 | if( !is_string( $minifig_id ) ) 219 | return new WP_Error( 'no-minifig-number', __( 'No minifig number specified.', 'bs_api' ) ); 220 | 221 | // Is it a valid user? 222 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 223 | return $validate_user; 224 | 225 | // Is a quantity value present? 226 | if( !isset( $quantity ) ) 227 | return new WP_Error( 'no-quantity-specified', __( 'No quantity specified.', 'bs_api' ) ); 228 | 229 | // Is quantity an integer? 230 | if( !is_int( $quantity ) ) 231 | return new WP_Error( 'quantity-not-integer', __( 'The quantity is not an integer.', 'bs_api' ) ); 232 | 233 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'minifigNumber' => sanitize_text_field( $minifig_id ), 'qty' => $quantity ) ); 234 | 235 | $response = $this->remote_request( 'post', 'updateMinifigQtyOwned', $params ); 236 | 237 | $response = (array) simplexml_load_string( $response ); 238 | 239 | if( is_wp_error( $response ) ) 240 | { 241 | return $response; 242 | } 243 | elseif( $response[0] === '1' ) 244 | { 245 | return true; 246 | } 247 | } 248 | 249 | /** 250 | * Update Minifig Want 251 | * 252 | * Used to set whether the user wants a minifig. Currently users can't simultaneously own and want the same minifig, so setting a fig as wanted will clear the quantity owned. 253 | * If successful a 1 is returned. 254 | * 255 | * @author Nate Jacobs 256 | * @date 3/27/13 257 | * @since 1.1 258 | * 259 | * @param string 260 | * @param int 261 | * @param bool 262 | * 263 | * @return bool|object true|WP_Error 264 | */ 265 | public function update_minifig_want( $minifig_id, $user_id, $want ) 266 | { 267 | // Is the minifig_id a string 268 | if( !is_string( $minifig_id ) ) 269 | return new WP_Error( 'no-minifig-number', __( 'No minifig number specified.', 'bs_api' ) ); 270 | 271 | // Is it a valid user? 272 | if( is_wp_error( $validate_user = $this->validate_user( $user_id ) ) ) 273 | return $validate_user; 274 | 275 | // Is it a valid boolean? 276 | if( is_wp_error( $validate_want = $this->validate_owned_wanted( $want ) ) ) 277 | return $validate_want; 278 | 279 | $params = array( 'body' => array( 'userHash' => $this->get_user_hash( $user_id ), 'minifigNumber' => sanitize_text_field( $minifig_id ), 'want' => $want ) ); 280 | 281 | $response = $this->remote_request( 'post', 'updateMinifigWanted', $params ); 282 | 283 | $response = (array) simplexml_load_string( $response ); 284 | 285 | if( is_wp_error( $response ) ) 286 | { 287 | return $response; 288 | } 289 | elseif( $response[0] === '1' ) 290 | { 291 | return true; 292 | } 293 | } 294 | } -------------------------------------------------------------------------------- /inc/class-utilities.php: -------------------------------------------------------------------------------- 1 | strlen( $response_body ) && $type == 'get' ) 53 | { 54 | return new WP_Error( 'brickset-no-data', __( 'Sorry, no sets were found for that query', 'bs_api' ) ); 55 | } 56 | else 57 | { 58 | return $response_body; 59 | } 60 | } 61 | 62 | 63 | /** 64 | * Authenticates a user with Brickset and returns a hash. 65 | * The hash is then stored as a meta value with the key of 'brickset_user_hash' 66 | * in the *_usersmeta table. 67 | * 68 | * @author Nate Jacobs 69 | * @since 0.1 70 | * @updated 1.0 71 | * 72 | * @param int 73 | * @param string 74 | * @param string 75 | * 76 | * @return array if there is an error, a WP_Error array is returned 77 | */ 78 | protected function brickset_login( $user_id, $username, $password ) 79 | { 80 | // Which user is this? 81 | $user = get_userdata( $user_id ); 82 | 83 | // Build the parameters 84 | $params = 'u='.$username.'&p='.$password; 85 | 86 | // Send it off 87 | $response = $this->remote_request( 'get', 'login', $params ); 88 | 89 | if( is_wp_error( $response ) ) 90 | { 91 | return $response; 92 | } 93 | else 94 | { 95 | $user_hash = new SimpleXMLElement( $response ); 96 | 97 | update_user_meta( $user->ID, 'brickset_user_hash', (string) $user_hash[0] ); 98 | } 99 | } 100 | 101 | /** 102 | * Retrieves the API key from the database 103 | * 104 | * @author Nate Jacobs 105 | * @date 6/9/13 106 | * @since 1.0 107 | * 108 | * @return string 109 | */ 110 | protected function get_api_key() 111 | { 112 | $settings = (array) get_option( 'brickset-api-settings' ); 113 | 114 | return (isset( $settings['api_key'] ) ? $settings['api_key'] : ''); 115 | } 116 | /** 117 | * Returns the Brickset userHash from user_meta 118 | * 119 | * @author Nate Jacobs 120 | * @date 2/9/13 121 | * @since 1.0 122 | * 123 | * @param int 124 | * 125 | * @return string 126 | */ 127 | protected function get_user_hash( $user_id ) 128 | { 129 | return get_user_meta( $user_id, 'brickset_user_hash', true ); 130 | } 131 | 132 | /** 133 | * Takes an array of search criteria and returns a urlencoded query string 134 | * 135 | * @author Nate Jacobs 136 | * @date 2/22/13 137 | * @since 1.0 138 | * 139 | * @param array 140 | * 141 | * @return array 142 | */ 143 | protected function build_bs_query( $args = '' ) 144 | { 145 | $defaults = array( 146 | 'user_id' => '', 147 | 'query' => '', 148 | 'theme' => '', 149 | 'subtheme' => '', 150 | 'set_number'=> '', 151 | 'year' => '', 152 | 'owned' => '', 153 | 'wanted' => '' 154 | ); 155 | 156 | $args = wp_parse_args( $args, $defaults ); 157 | 158 | extract( $args, EXTR_SKIP ); 159 | 160 | $params = build_query( 161 | urlencode_deep( 162 | array( 163 | 'apiKey' => self::get_api_key(), 164 | 'query' => $query, 165 | 'theme' => $theme, 166 | 'subtheme' => $subtheme, 167 | 'setNumber' => $set_number, 168 | 'year' => $year, 169 | 'owned' => $owned, 170 | 'wanted' => $wanted 171 | ) 172 | ) 173 | ); 174 | 175 | $params = str_replace( '%2C', ',', $params ); 176 | return $params.'&userHash='.self::get_user_hash( $user_id ); 177 | } 178 | 179 | /** 180 | * Checks if the set number passed has a variant, if not, one is added 181 | * The search query requires sets in the format of 9999-9 182 | * 183 | * @author Nate Jacobs 184 | * @date 2/9/13 185 | * @since 1.0 186 | * 187 | * @param string 188 | * 189 | * @return string 190 | */ 191 | protected function validate_set_number( $set_number ) 192 | { 193 | // If no set is passed, get out 194 | if( empty( $set_number ) ) 195 | return ''; 196 | 197 | // Get set numbers into an array 198 | $set_numbers = explode( ',', $set_number ); 199 | 200 | // Holding container 201 | $sets = ''; 202 | 203 | foreach( $set_numbers as $set ) 204 | { 205 | $number_check = explode( '-', $set ); 206 | 207 | if( !is_numeric( $number_check[0] ) ) 208 | return new WP_Error( 'invalid-set-number', __( 'One of the sets requested is not a number.', 'bs_api' ) ); 209 | 210 | // No variant present, add the -1 211 | if( empty( $number_check[1] ) ) 212 | { 213 | $sets .= $number_check[0].'-1,'; 214 | } 215 | else 216 | { 217 | $sets .= $set.','; 218 | } 219 | } 220 | // Get rid of the space between commas 221 | return substr(str_replace(' ','',$sets), 0, -1); 222 | } 223 | 224 | /** 225 | * Takes a user ID and determines if it is an integer and is a valid user in the site 226 | * 227 | * @author Nate Jacobs 228 | * @date 2/22/13 229 | * @since 1.0 230 | * 231 | * @param int 232 | * 233 | * @return object WP_Error (if not a user or an int) 234 | * @return bool true (if a valid user and an int) 235 | */ 236 | protected function validate_user( $user_id ) 237 | { 238 | // Is there a user? 239 | if( empty( $user_id ) ) 240 | return new WP_Error( 'no-user-specified', __( 'No user specified.', 'bs_api' ) ); 241 | 242 | // Is it an integer? 243 | if( !is_int( $user_id ) ) 244 | return new WP_Error( 'no-user-specified', __( 'No user specified.', 'bs_api' ) ); 245 | 246 | // Does the user_id specified exist on this site? 247 | if( !get_user_by( 'id', $user_id ) ) 248 | return new WP_Error( 'not-valid-user', __( 'The user ID passed is not a valid user.', 'bs_api' ) ); 249 | 250 | $user_hash = $this->get_user_hash( $user_id ); 251 | 252 | if( empty( $user_hash ) ) 253 | return new WP_Error( 'no-user-hash', __( 'The user ID passed does not have a Brickset API identifier on file.', 'bs_api' ) ); 254 | } 255 | 256 | /** 257 | * Determines if the owned and wanted passed values are true or false 258 | * 259 | * @author Nate Jacobs 260 | * @date 2/22/13 261 | * @since 1.0 262 | * 263 | * @param bool 264 | * @param bool 265 | * 266 | * @return object WP_Error 267 | */ 268 | protected function validate_owned_wanted( $owned = false, $wanted = false ) 269 | { 270 | if( !is_bool( $owned ) ) 271 | return new WP_Error( 'no-boolean', __( 'Owned is not a true or false value.', 'bs_api' ) ); 272 | 273 | if( !is_bool( $wanted ) ) 274 | return new WP_Error( 'no-boolean', __( 'Wanted is not a true or false value.', 'bs_api' ) ); 275 | } 276 | 277 | /** 278 | * Checks and ensures the theme or subtheme passed is a valid string 279 | * 280 | * @author Nate Jacobs 281 | * @date 2/22/13 282 | * @since 1.0 283 | * 284 | * @param string 285 | * 286 | * @return object WP_Error 287 | */ 288 | protected function validate_theme_subtheme( $theme = '', $subtheme = '' ) 289 | { 290 | if( !is_string( $theme ) || !is_string( $subtheme ) ) 291 | return new WP_Error( 'invalid-string', __( 'The theme or subtheme requested is not a valid string.', 'bs_api' ) ); 292 | } 293 | 294 | /** 295 | * Ensures the string passed is numeric and is not empty 296 | * 297 | * @author Nate Jacobs 298 | * @date 3/24/13 299 | * @since 1.1 300 | * 301 | * @param string 302 | * 303 | * @return object WP_Error 304 | */ 305 | protected function validate_set_id( $set_id ) 306 | { 307 | // Is there a setID? 308 | if( empty( $set_id ) ) 309 | return new WP_Error( 'no-set-id', __( 'No set ID requested.', 'bs_api' ) ); 310 | 311 | // Is the string numeric 312 | if( false === is_numeric( $set_id ) ) 313 | return new WP_Error( 'set-id-not-valid', __( 'The set ID requested is not numeric.', 'bs_api' ) ); 314 | } 315 | 316 | /** 317 | * Checks if the year passed as a string is a valid year 318 | * 319 | * @author Nate Jacobs 320 | * @date 2/22/13 321 | * @since 1.0 322 | * 323 | * @param string|int the year to check 324 | */ 325 | protected function validate_year( $years ) 326 | { 327 | // Get set numbers into an array 328 | $years = explode( ',', $years ); 329 | 330 | // Holding container 331 | $total_years = ''; 332 | 333 | foreach( $years as $year ) 334 | { 335 | if( !is_numeric( $year ) || strlen( $year )!=4 ) 336 | return new WP_Error( 'invalid-year', __( 'The year requested is not a valid year.', 'bs_api' ) ); 337 | 338 | // Check if year is between 1950 and current year +1 339 | if( $year < '1950' || $year > date( 'Y', strtotime( '+1 year' ) ) ) 340 | return new WP_Error( 'year-out-range', __( 'The year is not in the accepted range, 1950 to year +1.', 'bs_api' ) ); 341 | 342 | $total_years .= $year.','; 343 | } 344 | // Get rid of the space between commas 345 | return substr(str_replace(' ','',$total_years), 0, -1); 346 | } 347 | 348 | /** 349 | * Returns all the settings set by the administrator in the plugin settings 350 | * 351 | * @author Nate Jacobs 352 | * @date 6/2/13 353 | * @since 1.3 354 | * 355 | * @return array the template settings as dictated by the plugin settings 356 | */ 357 | public function get_settings_rules() 358 | { 359 | $settings = (array) get_option( 'brickset-api-settings' ); 360 | $currency = isset( $settings['currency'] ) ? strtoupper( esc_attr( $settings['currency'] ) ) : ''; 361 | $bricklink = isset( $settings['bricklink_link'] ) ? (bool) esc_attr( $settings['bricklink_link'] ) : true; 362 | $transient = isset( $settings['transient'] ) ? esc_attr( $settings['transient'] ) : ''; 363 | 364 | if( 'month' === $transient ) 365 | { 366 | $transient = WEEK_IN_SECONDS*4; 367 | } 368 | elseif( 'day' === $transient ) 369 | { 370 | $transient = DAY_IN_SECONDS; 371 | } 372 | elseif( 'week' === $transient ) 373 | { 374 | $transient = WEEK_IN_SECONDS; 375 | } 376 | else 377 | { 378 | $transient = DAY_IN_SECONDS; 379 | } 380 | 381 | $currency_symbol = ( 'UK' === $currency ) ? '£' : '$'; 382 | 383 | $settings_array = array( 384 | 'currency' => $currency, 385 | 'currency_key' => $currency.'RetailPrice', 386 | 'currency_symbol' => $currency_symbol, 387 | 'currency_unknown' => $settings['currency_unknown'], 388 | 'bricklink' => $bricklink, 389 | 'transient' => $transient 390 | ); 391 | 392 | return $settings_array; 393 | } 394 | } 395 | 396 | $GLOBALS['brickset_api_utilities'] = new BricksetAPIUtilities(); -------------------------------------------------------------------------------- /inc/widgets/class-minifig-owned-widget.php: -------------------------------------------------------------------------------- 1 | __( 'A count of all the minifigs owned from Brickset for a user.', 'bs_api' ), 'classname' => 'brickset_owned_minifigs' ); 36 | parent::__construct('brickset_minifig_owned_widget', $name = __( 'Brickset Owned Minifigs', 'bs_api' ), $options ); 37 | } 38 | 39 | /** 40 | * Create the necessary form to customize the widget. 41 | * 42 | * @author Nate Jacobs 43 | * @date 9/12/13 44 | * @since 1.4 45 | * 46 | * @param array 47 | */ 48 | public function form( $instance ) 49 | { 50 | $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Owned Minifigs', 'bs_api' ) ) ); 51 | $title = esc_attr( $instance['title'] ); 52 | $userID = isset( $instance['user_id'] ) ? esc_attr( $instance['user_id'] ) : 'Pick a user'; 53 | ?> 54 |

55 | 56 | 57 |

58 |

59 | 60 | $this->get_field_id( 'user_id' ), 'name' => $this->get_field_name( 'user_id' ), 'class' => 'widefat', 'selected' => $userID, 'show_option_none' => 'Pick a user' ) ); ?> 61 |

62 | get_minifig_collection( (int) $instance['user_id'], array( 'owned' => true ) ); 104 | 105 | $user = get_userdata( (int) $instance['user_id']); 106 | 107 | // check for errors 108 | if( is_wp_error( $brickset ) ) 109 | { 110 | echo $brickset->get_error_message(); 111 | } 112 | else 113 | { 114 | $count = 0; 115 | foreach ( $minifigs as $minifig ) 116 | { 117 | $count += $minifig->ownedTotal; 118 | } 119 | echo $user->display_name .' - '. $count; 120 | echo $after_widget; 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /inc/widgets/class-set-widget.php: -------------------------------------------------------------------------------- 1 | __( 'A widget that display the details of a particular set from the Brickset.com database.', 'bs_api' ), 'classname' => 'brickset_set_details' ); 41 | parent::__construct('brickset_set_widget', $name = __( 'Brickset Set Details', 'bs_api' ), $options ); 42 | } 43 | 44 | /** 45 | * Create the necessary form to customize the widget. 46 | * 47 | * @author Nate Jacobs 48 | * @date 6/9/13 49 | * @since 1.3 50 | * 51 | * @param array 52 | */ 53 | public function form( $instance ) 54 | { 55 | $instance = wp_parse_args( ( array ) $instance, array( 'set_number' => __( 'Set Number', 'bs_api' ) ) ); 56 | $title = esc_attr( $instance['set_number'] ); 57 | ?> 58 |

59 | 60 | 61 |

62 | get_by_number( $instance['set_number'] ); 103 | 104 | // check for errors 105 | if( is_wp_error( $brickset ) ) 106 | { 107 | echo $brickset->get_error_message(); 108 | } 109 | else 110 | { 111 | global $brickset_api_utilities; 112 | $settings = $brickset_api_utilities->get_settings_rules(); 113 | 114 | $number = ''; 115 | $numberVariant = ''; 116 | 117 | foreach( $set as $result ) 118 | { 119 | $number = sanitize_text_field( $result->number ); 120 | $numberVariant = sanitize_text_field( $result->numberVariant ); 121 | 122 | if( true === $settings['bricklink'] ) 123 | { 124 | $bricklink = ''.__( 'BrickLink', 'bs_api' ).': BrickLink

'; 125 | } 126 | elseif( false === $settings['bricklink'] ) 127 | { 128 | $bricklink = ''; 129 | } 130 | 131 | if( empty( $result->$settings['currency_key'] ) && 'unk' === $settings['currency_unknown'] ) 132 | { 133 | $result->$settings['currency_key'] = __( ' Unknown', 'bs_api' ); 134 | } 135 | 136 | if( empty( $result->$settings['currency_key'] ) && 'us' === $settings['currency_unknown'] ) 137 | { 138 | $settings['currency'] = 'US'; 139 | $settings['currency_key'] = 'USRetailPrice'; 140 | $settings['currency_symbol'] = '$'; 141 | } 142 | 143 | echo '
'; 144 | echo ''.__( 'Set Name', 'bs_api' ).': '.sanitize_text_field( $result->setName ).'
'; 145 | echo ''.__( 'Set Number', 'bs_api' ).': '.$number.'-'.$numberVariant.'
'; 146 | echo ''.__( 'Year', 'bs_api' ).': '.sanitize_text_field( $result->year ).'
'; 147 | echo ''.__( 'Theme', 'bs_api' ).': '.sanitize_text_field( $result->theme ).'
'; 148 | echo ''.__( 'Subtheme', 'bs_api' ).': '.sanitize_text_field( $result->subtheme ).'
'; 149 | echo ''.sprintf( __( '%s Retail Price', 'bs_api' ), $settings['currency'] ).': '.$settings['currency_symbol'].sanitize_text_field( $result->$settings['currency_key'] ).'
'; 150 | echo ''.__( 'Pieces', 'bs_api' ).': '.sanitize_text_field( $result->pieces ).'
'; 151 | echo ''.__( 'Minifigs', 'bs_api' ).': '.sanitize_text_field( $result->minifigs ).'
'; 152 | echo ''.__( 'Set Guide', 'bs_api' ).': Brickset
'; 153 | echo $bricklink; 154 | } 155 | 156 | echo $after_widget; 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /inc/widgets/class-theme-widget.php: -------------------------------------------------------------------------------- 1 | __( 'A listing of all themes from Brickset sorted alphabetically with links to the theme pages on Brickset.com.', 'bs_api' ), 'classname' => 'brickset_theme' ); 39 | parent::__construct('brickset_theme_widget', $name = __( 'Brickset Themes', 'bs_api' ), $options ); 40 | } 41 | 42 | /** 43 | * Create the necessary form to customize the widget. 44 | * 45 | * @uses title @since 0.1 46 | * 47 | * @author Nate Jacobs 48 | * @since 0.1 49 | * 50 | * @param array 51 | */ 52 | public function form( $instance ) 53 | { 54 | $instance = wp_parse_args( ( array ) $instance, array( 'title' => __( 'Brickset Themes', 'bs_api' ) ) ); 55 | $title = esc_attr( $instance['title'] ); 56 | ?> 57 |

58 | 59 | 60 |

61 | get_themes(); 100 | 101 | // check for errors 102 | if( is_wp_error( $brickset ) ) 103 | { 104 | echo $brickset->get_error_message(); 105 | } 106 | else 107 | { 108 | foreach ( $themes as $theme ) 109 | { 110 | echo "".$theme->theme.''; 111 | echo '
'; 112 | } 113 | 114 | echo $after_widget; 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /inc/widgets/class-theme-years-widget.php: -------------------------------------------------------------------------------- 1 | __( 'A listing of all years a particular theme was available with links to the year/theme page on Brickset.com.', 'bs_api' ), 'classname' => 'brickset_theme_years' ); 38 | parent::__construct('brickset_theme_years_widget', $name = __( 'Brickset Theme Years', 'bs_api' ), $options ); 39 | } 40 | 41 | /** 42 | * Create the necessary form to customize the widget. 43 | * 44 | * @uses title @since 0.1 45 | * 46 | * @author Nate Jacobs 47 | * @date 09/13/13 48 | * @since 1.4 49 | * 50 | * @param array 51 | */ 52 | public function form( $instance ) 53 | { 54 | $instance = wp_parse_args( ( array ) $instance, array( 'themeName' => '' ) ); 55 | $themeName = esc_attr( $instance['themeName'] ); 56 | 57 | //call functions class and use get method to retrieve list of themes 58 | $brickset = new BricksetAPISearch; 59 | $themes = $brickset->get_themes(); 60 | 61 | 62 | ?> 63 |

64 | 65 | get_error_message(); 70 | } 71 | else 72 | { 73 | ?> 74 | 84 | 87 |

88 | get_theme_years($themeName); 129 | 130 | // check for errors 131 | if( is_wp_error( $brickset ) ) 132 | { 133 | echo $brickset->get_error_message(); 134 | } 135 | else 136 | { 137 | foreach ( $years as $year ) 138 | { 139 | $url = "http://brickset.com/browse/years/?year=$year->year&Theme=".urlencode($year->theme); 140 | 141 | echo __( 'Year', 'bs_api' ).': '.$year->year; 142 | echo '
'; 143 | echo __( 'Number of Sets', 'bs_api' ).': '.$year->setCount.''; 144 | echo '
'; 145 | } 146 | 147 | echo $after_widget; 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /languages/default.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/languages/default.mo -------------------------------------------------------------------------------- /languages/default.po: -------------------------------------------------------------------------------- 1 | msgid "" 2 | msgstr "" 3 | "Project-Id-Version: bs_api\n" 4 | "POT-Creation-Date: 2013-09-13 22:43-0700\n" 5 | "PO-Revision-Date: 2013-09-13 22:43-0700\n" 6 | "Last-Translator: Nate Jacobs \n" 7 | "Language-Team: \n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=UTF-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | "X-Generator: Poedit 1.5.7\n" 12 | "X-Poedit-KeywordsList: _;gettext;gettext_noop;__;_e\n" 13 | "X-Poedit-Basepath: ../\n" 14 | "X-Poedit-SearchPath-0: admin\n" 15 | "X-Poedit-SearchPath-1: inc\n" 16 | "X-Poedit-SearchPath-2: .\n" 17 | 18 | #: admin/class-settings-page.php:28 admin/class-settings-page.php:48 19 | msgid "Brickset API Settings" 20 | msgstr "" 21 | 22 | #: admin/class-settings-page.php:29 23 | msgid "Brickset API" 24 | msgstr "" 25 | 26 | #: admin/class-settings-page.php:70 27 | msgid "API Key" 28 | msgstr "" 29 | 30 | #: admin/class-settings-page.php:77 31 | msgid "Enter your API Key" 32 | msgstr "" 33 | 34 | #: admin/class-settings-page.php:85 35 | msgid "Template Tag Settings" 36 | msgstr "" 37 | 38 | #: admin/class-settings-page.php:92 39 | msgid "Which currency to use?" 40 | msgstr "" 41 | 42 | #: admin/class-settings-page.php:100 43 | msgid "Display link to Bricklink?" 44 | msgstr "" 45 | 46 | #: admin/class-settings-page.php:131 47 | msgid "You may obtain a key at " 48 | msgstr "" 49 | 50 | #: admin/class-settings-page.php:160 51 | msgid "" 52 | "These settings control what is displayed when you use the provided template " 53 | "tags, shortcodes, widgets and oembed." 54 | msgstr "" 55 | 56 | #: admin/class-settings-page.php:177 57 | msgid "US Dollar" 58 | msgstr "" 59 | 60 | #: admin/class-settings-page.php:178 61 | msgid "CA Dollar" 62 | msgstr "" 63 | 64 | #: admin/class-settings-page.php:179 65 | msgid "UK Pound Sterling" 66 | msgstr "" 67 | 68 | #: admin/class-settings-page.php:180 69 | msgid "" 70 | "If no retail price is available for the currency selected the plugin should" 71 | msgstr "" 72 | 73 | #: admin/class-settings-page.php:181 74 | msgid "Display the word Unknown" 75 | msgstr "" 76 | 77 | #: admin/class-settings-page.php:182 78 | msgid "Display the US retail price" 79 | msgstr "" 80 | 81 | #: admin/class-settings-page.php:183 82 | msgid "" 83 | "Brickset provides retail prices in US dollars, CA dollars, and UK pound " 84 | "sterling " 85 | msgstr "" 86 | 87 | #: admin/class-settings-page.php:199 88 | msgid "Yes" 89 | msgstr "" 90 | 91 | #: admin/class-settings-page.php:200 92 | msgid "No" 93 | msgstr "" 94 | 95 | #: admin/class-settings-page.php:215 96 | msgid "One Day" 97 | msgstr "" 98 | 99 | #: admin/class-settings-page.php:216 100 | msgid "One Week" 101 | msgstr "" 102 | 103 | #: admin/class-settings-page.php:217 104 | msgid "One Month" 105 | msgstr "" 106 | 107 | #: admin/class-settings-page.php:218 108 | msgid "" 109 | "The plugin uses the WordPress Transient API to store the data returned from " 110 | "Brickset to reduce page load times. By increasing the time the data is " 111 | "stored it requires fewer requests to Brickset. However, if the data changes " 112 | "frequently then your site will display out-of-date data until the cache " 113 | "expires." 114 | msgstr "" 115 | 116 | #: admin/class-users-profile.php:41 117 | msgid "Brickset Login Information" 118 | msgstr "" 119 | 120 | #: admin/class-users-profile.php:42 121 | msgid "" 122 | "If the Brickset Identifier is filled you do not need to add your username " 123 | "and password unless you have changed your password on Brickset." 124 | msgstr "" 125 | 126 | #: admin/class-users-profile.php:45 127 | msgid "Brickset Username" 128 | msgstr "" 129 | 130 | #: admin/class-users-profile.php:49 131 | msgid "Brickset Password" 132 | msgstr "" 133 | 134 | #: admin/class-users-profile.php:53 135 | msgid "Brickset Identifier" 136 | msgstr "" 137 | 138 | #: admin/class-welcome-dashboard.php:53 admin/class-welcome-dashboard.php:54 139 | #: admin/class-welcome-dashboard.php:61 admin/class-welcome-dashboard.php:62 140 | msgid "Welcome to Brickset API" 141 | msgstr "" 142 | 143 | #: admin/class-welcome-dashboard.php:100 admin/class-welcome-dashboard.php:154 144 | #, php-format 145 | msgid "Welcome to Brickset API %s" 146 | msgstr "" 147 | 148 | #: admin/class-welcome-dashboard.php:101 admin/class-welcome-dashboard.php:155 149 | msgid "" 150 | "Thank you for updating to the latest version! Brickset API helps you display " 151 | "and manage your LEGO® collection right from your WordPress site." 152 | msgstr "" 153 | 154 | #: admin/class-welcome-dashboard.php:105 admin/class-welcome-dashboard.php:159 155 | #, php-format 156 | msgid "What's New in %s" 157 | msgstr "" 158 | 159 | #: admin/class-welcome-dashboard.php:107 admin/class-welcome-dashboard.php:161 160 | msgid "Credits" 161 | msgstr "" 162 | 163 | #: admin/class-welcome-dashboard.php:112 164 | msgid "New Widgets" 165 | msgstr "" 166 | 167 | #: admin/class-welcome-dashboard.php:115 168 | msgid "Count of Owned Minifigs" 169 | msgstr "" 170 | 171 | #: admin/class-welcome-dashboard.php:116 172 | msgid "Show off the total count of all the minifigs you own." 173 | msgstr "" 174 | 175 | #: admin/class-welcome-dashboard.php:118 176 | msgid "Years a Theme was Available" 177 | msgstr "" 178 | 179 | #: admin/class-welcome-dashboard.php:119 180 | msgid "" 181 | "Display how many sets were made each year a theme was available. A link is " 182 | "included to the theme page on Brickset.com" 183 | msgstr "" 184 | 185 | #: admin/class-welcome-dashboard.php:126 186 | msgid "For the Developers" 187 | msgstr "" 188 | 189 | #: admin/class-welcome-dashboard.php:128 190 | msgid "Transient Filters" 191 | msgstr "" 192 | 193 | #: admin/class-welcome-dashboard.php:129 194 | msgid "" 195 | "You can now override the default caching of the Brickset API using " 196 | "add_filter. By default the plugin caches Brickset data for 24 hours to " 197 | "reduce page load times. By increasing the time the data is stored it " 198 | "requires fewer requests to Brickset. However, if the data changes frequently " 199 | "then your site will display out-of-date data until the cache expires." 200 | msgstr "" 201 | 202 | #: admin/class-welcome-dashboard.php:132 203 | msgid "Filter Shortcodes" 204 | msgstr "" 205 | 206 | #: admin/class-welcome-dashboard.php:133 207 | msgid "" 208 | "The plugin now takes advantage of the feature added in WordPress 3.6 to " 209 | "enable filtering of the shortcode attributes. You can learn more by reading" 210 | msgstr "" 211 | 212 | #: admin/class-welcome-dashboard.php:133 213 | msgid "this article" 214 | msgstr "" 215 | 216 | #: admin/class-welcome-dashboard.php:133 217 | msgid "by WordPress lead developer Mark Jaquith." 218 | msgstr "" 219 | 220 | #: admin/class-welcome-dashboard.php:138 221 | msgid "Go to the Brickset API Settings" 222 | msgstr "" 223 | 224 | #: admin/class-welcome-dashboard.php:165 225 | msgid "The Brickset API Plugin is created by the following developers." 226 | msgstr "" 227 | 228 | #: admin/class-welcome-dashboard.php:191 229 | #, php-format 230 | msgid "View %s" 231 | msgstr "" 232 | 233 | #: inc/class-oembed.php:192 inc/class-shortcodes.php:54 234 | #: inc/class-template-tags.php:204 inc/widgets/class-set-widget.php:119 235 | msgid "BrickLink" 236 | msgstr "" 237 | 238 | #: inc/class-oembed.php:207 inc/class-shortcodes.php:70 239 | #: inc/class-template-tags.php:218 inc/widgets/class-set-widget.php:132 240 | msgid " Unknown" 241 | msgstr "" 242 | 243 | #: inc/class-oembed.php:218 inc/class-oembed.php:269 244 | #: inc/class-shortcodes.php:81 inc/class-template-tags.php:159 245 | #: inc/class-template-tags.php:229 inc/widgets/class-set-widget.php:143 246 | msgid "Set Name" 247 | msgstr "" 248 | 249 | #: inc/class-oembed.php:219 inc/class-oembed.php:269 250 | #: inc/class-shortcodes.php:82 inc/class-template-tags.php:159 251 | #: inc/class-template-tags.php:230 inc/widgets/class-set-widget.php:55 252 | #: inc/widgets/class-set-widget.php:59 inc/widgets/class-set-widget.php:144 253 | msgid "Set Number" 254 | msgstr "" 255 | 256 | #: inc/class-oembed.php:220 inc/class-oembed.php:269 257 | #: inc/class-shortcodes.php:83 inc/class-template-tags.php:93 258 | #: inc/class-template-tags.php:231 inc/widgets/class-set-widget.php:145 259 | #: inc/widgets/class-theme-years-widget.php:141 260 | msgid "Year" 261 | msgstr "" 262 | 263 | #: inc/class-oembed.php:221 inc/class-shortcodes.php:84 264 | #: inc/class-template-tags.php:232 inc/widgets/class-set-widget.php:146 265 | msgid "Theme" 266 | msgstr "" 267 | 268 | #: inc/class-oembed.php:222 inc/class-shortcodes.php:85 269 | #: inc/class-template-tags.php:55 inc/class-template-tags.php:233 270 | #: inc/widgets/class-set-widget.php:147 271 | msgid "Subtheme" 272 | msgstr "" 273 | 274 | #: inc/class-oembed.php:223 inc/class-shortcodes.php:86 275 | #: inc/class-template-tags.php:234 inc/widgets/class-set-widget.php:148 276 | #, php-format 277 | msgid "%s Retail Price" 278 | msgstr "" 279 | 280 | #: inc/class-oembed.php:224 inc/class-oembed.php:269 281 | #: inc/class-shortcodes.php:87 inc/class-template-tags.php:235 282 | #: inc/widgets/class-set-widget.php:149 283 | msgid "Pieces" 284 | msgstr "" 285 | 286 | #: inc/class-oembed.php:225 inc/class-shortcodes.php:88 287 | #: inc/class-template-tags.php:236 inc/widgets/class-set-widget.php:150 288 | msgid "Minifigs" 289 | msgstr "" 290 | 291 | #: inc/class-oembed.php:226 inc/class-shortcodes.php:89 292 | #: inc/class-template-tags.php:237 inc/widgets/class-set-widget.php:151 293 | msgid "Set Guide" 294 | msgstr "" 295 | 296 | #: inc/class-oembed.php:269 inc/class-template-tags.php:159 297 | msgid "Image" 298 | msgstr "" 299 | 300 | #: inc/class-search-functions.php:191 301 | msgid "The date is not formatted correctly." 302 | msgstr "" 303 | 304 | #: inc/class-search-functions.php:246 305 | msgid "No set number requested." 306 | msgstr "" 307 | 308 | #: inc/class-search-functions.php:278 inc/class-search-functions.php:305 309 | #: inc/class-utilities.php:240 inc/class-utilities.php:244 310 | msgid "No user specified." 311 | msgstr "" 312 | 313 | #: inc/class-search-functions.php:343 314 | msgid "No theme requested." 315 | msgstr "" 316 | 317 | #: inc/class-search-functions.php:381 318 | msgid "No subtheme requested." 319 | msgstr "" 320 | 321 | #: inc/class-search-functions.php:419 322 | msgid "No year requested." 323 | msgstr "" 324 | 325 | #: inc/class-search-functions.php:447 inc/class-search-functions.php:491 326 | #: inc/class-utilities.php:309 327 | msgid "No set ID requested." 328 | msgstr "" 329 | 330 | #: inc/class-search-functions.php:545 331 | msgid "No search criteria specified." 332 | msgstr "" 333 | 334 | #: inc/class-search-functions.php:574 inc/class-search-functions.php:652 335 | msgid "The query requested is not a valid string." 336 | msgstr "" 337 | 338 | #: inc/class-search-functions.php:640 339 | msgid "" 340 | "You must include at least one of the following: query, owned, or wanted." 341 | msgstr "" 342 | 343 | #: inc/class-template-tags.php:55 inc/class-template-tags.php:93 344 | msgid "Set Count" 345 | msgstr "" 346 | 347 | #: inc/class-template-tags.php:55 348 | msgid "First Year" 349 | msgstr "" 350 | 351 | #: inc/class-template-tags.php:55 352 | msgid "Last Year" 353 | msgstr "" 354 | 355 | #: inc/class-template-tags.php:126 356 | msgid "Popular Searches on Brickset" 357 | msgstr "" 358 | 359 | #: inc/class-update-functions.php:136 inc/class-update-functions.php:227 360 | msgid "No quantity specified." 361 | msgstr "" 362 | 363 | #: inc/class-update-functions.php:140 inc/class-update-functions.php:231 364 | msgid "The quantity is not an integer." 365 | msgstr "" 366 | 367 | #: inc/class-update-functions.php:219 inc/class-update-functions.php:269 368 | msgid "No minifig number specified." 369 | msgstr "" 370 | 371 | #: inc/class-utilities.php:33 372 | msgid "Specify a type of request: get or post" 373 | msgstr "" 374 | 375 | #: inc/class-utilities.php:46 376 | msgid "Don't Panic! Something went wrong and Brickset didn't reply." 377 | msgstr "" 378 | 379 | #: inc/class-utilities.php:50 380 | msgid "Unknown error occurred" 381 | msgstr "" 382 | 383 | #: inc/class-utilities.php:54 384 | msgid "Sorry, no sets were found for that query" 385 | msgstr "" 386 | 387 | #: inc/class-utilities.php:208 388 | msgid "One of the sets requested is not a number." 389 | msgstr "" 390 | 391 | #: inc/class-utilities.php:248 392 | msgid "The user ID passed is not a valid user." 393 | msgstr "" 394 | 395 | #: inc/class-utilities.php:253 396 | msgid "The user ID passed does not have a Brickset API identifier on file." 397 | msgstr "" 398 | 399 | #: inc/class-utilities.php:271 400 | msgid "Owned is not a true or false value." 401 | msgstr "" 402 | 403 | #: inc/class-utilities.php:274 404 | msgid "Wanted is not a true or false value." 405 | msgstr "" 406 | 407 | #: inc/class-utilities.php:291 408 | msgid "The theme or subtheme requested is not a valid string." 409 | msgstr "" 410 | 411 | #: inc/class-utilities.php:313 412 | msgid "The set ID requested is not numeric." 413 | msgstr "" 414 | 415 | #: inc/class-utilities.php:336 416 | msgid "The year requested is not a valid year." 417 | msgstr "" 418 | 419 | #: inc/class-utilities.php:340 420 | msgid "The year is not in the accepted range, 1950 to year +1." 421 | msgstr "" 422 | 423 | #: inc/widgets/class-minifig-owned-widget.php:35 424 | msgid "A count of all the minifigs owned from Brickset for a user." 425 | msgstr "" 426 | 427 | #: inc/widgets/class-minifig-owned-widget.php:36 428 | msgid "Brickset Owned Minifigs" 429 | msgstr "" 430 | 431 | #: inc/widgets/class-minifig-owned-widget.php:50 432 | msgid "Owned Minifigs" 433 | msgstr "" 434 | 435 | #: inc/widgets/class-minifig-owned-widget.php:55 436 | #: inc/widgets/class-theme-widget.php:58 437 | msgid "Title" 438 | msgstr "" 439 | 440 | #: inc/widgets/class-minifig-owned-widget.php:59 441 | msgid "Which user to display minifigs for?" 442 | msgstr "" 443 | 444 | #: inc/widgets/class-set-widget.php:40 445 | msgid "" 446 | "A widget that display the details of a particular set from the Brickset.com " 447 | "database." 448 | msgstr "" 449 | 450 | #: inc/widgets/class-set-widget.php:41 451 | msgid "Brickset Set Details" 452 | msgstr "" 453 | 454 | #: inc/widgets/class-theme-widget.php:38 455 | msgid "" 456 | "A listing of all themes from Brickset sorted alphabetically with links to " 457 | "the theme pages on Brickset.com." 458 | msgstr "" 459 | 460 | #: inc/widgets/class-theme-widget.php:39 inc/widgets/class-theme-widget.php:54 461 | msgid "Brickset Themes" 462 | msgstr "" 463 | 464 | #: inc/widgets/class-theme-years-widget.php:37 465 | msgid "" 466 | "A listing of all years a particular theme was available with links to the " 467 | "year/theme page on Brickset.com." 468 | msgstr "" 469 | 470 | #: inc/widgets/class-theme-years-widget.php:38 471 | msgid "Brickset Theme Years" 472 | msgstr "" 473 | 474 | #: inc/widgets/class-theme-years-widget.php:64 475 | msgid "Theme Name" 476 | msgstr "" 477 | 478 | #: inc/widgets/class-theme-years-widget.php:125 479 | msgid " Years Available" 480 | msgstr "" 481 | 482 | #: inc/widgets/class-theme-years-widget.php:143 483 | msgid "Number of Sets" 484 | msgstr "" 485 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Brickset API # 2 | 3 | **This version is outdated. The Brickset API is now on version 2.0 and this code will no longer work.** 4 | 5 | Version 1.4 6 | 7 | Works with WordPress v3.5+ 8 | Works with Brickset API v2 9 | 10 | Display your favorite LEGO® set information on your website using the Brickset API. 11 | 12 | ## Description ## 13 | 14 | This plugin is an implementation of the Brickset Webservice. It includes methods to get LEGO® set and theme data from Brickset as well as pre-formated methods to display set data. The set data requested is cached daily to reduce HTTP requests and page load time. Please visit [Brickset](http://brickset.com/) for more information on the [webservice](http://www.brickset.com/webservices). You can obtain an API key from [Brickset](http://brickset.com/contact/). 15 | 16 | The main development is all happening on [GitHub](https://github.com/NateJacobs/Brickset-API). 17 | 18 | This is not an official Brickset.com plugin. LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this plugin. 19 | 20 | ## Oembed ## 21 | You can paste a Brickset set or theme url into your post or page. Once you publish the post or page information about the set or theme will be displayed. Two example URLs are below. 22 | 23 | * Set URL: http://brickset.com/detail/?Set=79003-1 24 | * Theme URL: http://brickset.com/browse/themes/?theme=The%20Hobbit 25 | 26 | ## Template Tags ## 27 | The plugin has numerous template tags you are able to use in your theme. They are listed below with a short description. 28 | 29 | * `brickset_themes();` outputs a list of all themes. 30 | * `brickset_subthemes( $theme );` outputs a table of all subthemes of the theme specified, the number of sets, and years available. 31 | * `brickset_theme_years( $theme );` outputs a table of all the years the specified theme was available and the number of sets each year. 32 | * `brickset_popular_searches();` outputs a list of the most popular search terms on Brickset.com. 33 | * `brickset_updated_since( $date );` outputs a table of the sets updated since the date specified. The table includes thumbnail, set name and set number. 34 | * `brickset_set_number( $set );` outputs a list of details about the sets specified. More than one set can be requested by separating the set numbers with a comma, e.g. '1380,10240'. 35 | 36 | ## Shortcode ## 37 | The plugin has a shortcode you may use in your posts and pages to display information about a set or sets. 38 | 39 | * `[bs_set number='XXX']` outputs information about a specific set. Thumbnail, set name, set number, pieces, theme, subtheme and year. You can display multiple sets by seperating the set numbers with a comma. 40 | 41 | ## Widgets ## 42 | The plugin has four widgets you can activate in your theme. The first displays a list of all themes on Brickset with a link to browse each theme on Brickset.com and the second to display the details about a specific set. The third allows you to show off the total count of your minifigs. The last widget displays a count of sets produced in each year for a given theme. 43 | 44 | ## Advanced Use ## 45 | This example shows how to get the data about a specific set. You can find the developer docs [here](https://github.com/NateJacobs/Brickset-API/wiki). 46 | 47 | 1. Instantiate the class. 48 | ``` 49 | $brickset = new BricksetAPISearch(); 50 | ``` 51 | 52 | 2. Pass a set number to the get_by_number method. 53 | ``` 54 | $set_data = $brickset->get_by_number( '8014' ); 55 | ``` 56 | 3. Test for an error 57 | ``` 58 | if( is_wp_error( $set_data ) { 59 | echo $set_data->get_error_message; 60 | } 61 | ``` 62 | 63 | 4. Display the results how you like. This will display the set's theme. 64 | ``` 65 | else { 66 | echo $set_data->theme; 67 | } 68 | ``` 69 | 70 | ## Road Map ## 71 | 1. Template tags to display sets specific to a user. 72 | 2. Caching of images 73 | 74 | You can follow all the open feature requests and enhancements on [GitHub](https://github.com/NateJacobs/Brickset-API/issues?milestone=&page=1&state=open). 75 | 76 | ## Installation ## 77 | 78 | 1. Upload the entire `brickset-api` folder to the `wp-content/plugins/` directory of your WordPress installation or download from the Plugin Repository 79 | 2. Activate the plugin through the Plugins menu in WordPress 80 | 3. Add your Brickset.com API key to the Brickset settings page which can be found as a submenu under the Settings menu 81 | 3. Either add a Brickset link (url) to a set or theme in a post or page, or add a template tag to a theme file, or for advanced use instantiate the class and create your own display method. 82 | 83 | ## Frequently Asked Questions ## 84 | 85 | ### Can I add sets to my set list on Brickset with this plugin? ### 86 | Yes you can, but it requires writing custom code using the API functions of the plugin. 87 | 88 | ### Does this plugin require an API Key from Brickset ### 89 | To display more than twenty sets from a search query an API key is required. You can obtain one by contacting Brickset on this [page](http://brickset.com/contact/). 90 | 91 | ## Screenshots ## 92 | ###1. Individual Set Display### 93 | ![Individual Set Display](https://raw.github.com/NateJacobs/Brickset-API/master/screenshot-1.png) 94 | 95 | ###2. Years theme is available### 96 | ![Years theme is available](https://raw.github.com/NateJacobs/Brickset-API/master/screenshot-2.png) 97 | 98 | ###3. Sets in space theme### 99 | ![Sets in space theme](https://raw.github.com/NateJacobs/Brickset-API/master/screenshot-3.png) 100 | 101 | 102 | ## Changelog ## 103 | 104 | ### Version 1.4.0 ### 105 | * New owned minifig widget - display how many minifigs you own 106 | * New theme years widget - display how many sets were produced for a given theme in a given year 107 | * Introduce filters to enable overwriting the default cache time of 24 hours for Brickset data 108 | * Add third parameter to shortcode functions 109 | 110 | ### Version 1.3 ### 111 | * Add a new widget to display set details 112 | * Add current_user_can check to user profile settings 113 | * Administrators can now select which currency (US dollar, CA dollar, UK pound) is displayed when using the built in template tags, shortcode and oembed set data 114 | * Administrators can choose if the Bricklink link is displayed in template tags, shortcode and oembed set data 115 | 116 | ### Version 1.2 ### 117 | * Removed anonymous function from class-widgets.php 118 | 119 | ### Version 1.1 ### 120 | * Add ability to update wanted and owned sets 121 | * Add ability to update the quantity owned of a set 122 | * Add ability to search a user's minifig collections 123 | * Add ability to update wanted and owned minifigs 124 | * Updated class name - BricksetAPIFunctions became BricksetAPISearch 125 | 126 | ### Version 1.0 ### 127 | * Enter your Brickset API from the settings submenu. 128 | * Allow users to authenticate with Brickset from their profile page. 129 | * Refactor code base 130 | * Add localization and translation .po 131 | * Create webservice-definition.json to display details about the availble calls 132 | * Brickset oembed support for set and theme URLs 133 | 134 | ### Version 0.3 ### 135 | * Added get_owned function and shortcode. 136 | 137 | ### Version 0.2 ### 138 | * Get_set and my_wanted shortcodes added. 139 | * BricksetAPIFunctions updated to use wp_remote_get. 140 | * Added template tags for use in themes. 141 | 142 | ### Version 0.1 ### 143 | * Initial plugin. 144 | 145 | License [GPLv2 or later]((http://www.gnu.org/licenses/gpl-2.0.html) 146 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Brickset API === 2 | 3 | Contributors: NateJacobs 4 | Tags: brickset, lego, brick 5 | Requires at least: 3.5 6 | Tested up to: 4.1 7 | Stable tag: 1.4.1 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Display your favorite LEGO® set information on your website using the Brickset API. 12 | 13 | == Description == 14 | 15 | This plugin is an implementation of the Brickset Webservice. It includes methods to get LEGO® set and theme data from Brickset as well as pre-formated methods to display set data. The set data requested is cached daily to reduce HTTP requests and page load time. Please visit [Brickset](http://brickset.com/) for more information on the [webservice](http://www.brickset.com/webservices). You can obtain an API key from [Brickset](http://brickset.com/contact/). 16 | 17 | The main development is all happening on [GitHub](https://github.com/NateJacobs/Brickset-API). 18 | 19 | This is not an official Brickset.com plugin. LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this plugin. 20 | 21 | = Oembed = 22 | You can paste a Brickset set or theme url into your post or page. Once you publish the post or page information about the set or theme will be displayed. Two example URLs are below. 23 | 24 | * Set URL: http://brickset.com/detail/?Set=79003-1 25 | * Theme URL: http://brickset.com/browse/themes/?theme=The%20Hobbit 26 | 27 | = Template Tags = 28 | The plugin has numerous template tags you are able to use in your theme. They are listed below with a short description. 29 | 30 | * `brickset_themes();` outputs a list of all themes. 31 | * `brickset_subthemes( $theme );` outputs a table of all subthemes of the theme specified, the number of sets, and years available. 32 | * `brickset_theme_years( $theme );` outputs a table of all the years the specified theme was available and the number of sets each year. 33 | * `brickset_popular_searches();` outputs a list of the most popular search terms on Brickset.com. 34 | * `brickset_updated_since( $date );` outputs a table of the sets updated since the date specified. The table includes thumbnail, set name and set number. 35 | * `brickset_set_number( $set );` outputs a list of details about the sets specified. More than one set can be requested by separating the set numbers with a comma, e.g. '1380,10240'. 36 | 37 | = Shortcode = 38 | The plugin has a shortcode you may use in your posts and pages to display information about a set or sets. 39 | 40 | * `[bs_set number='XXX']` outputs information about a specific set. Thumbnail, set name, set number, pieces, theme, subtheme and year. You can display multiple sets by seperating the set numbers with a comma. 41 | 42 | = Widgets = 43 | The plugin has four widgets you can activate in your theme. The first displays a list of all themes on Brickset with a link to browse each theme on Brickset.com and the second to display the details about a specific set. The third allows you to show off the total count of your minifigs. The last widget displays a count of sets produced in each year for a given theme. 44 | 45 | = Advanced Use = 46 | This example shows how to get the data about a specific set. You can find the developer docs [here](https://github.com/NateJacobs/Brickset-API/wiki). 47 | 48 | 1. Instantiate the class. 49 | ` 50 | $brickset = new BricksetAPISearch(); 51 | ` 52 | 53 | 2. Pass a set number to the get_by_number method. 54 | ` 55 | $set_data = $brickset->get_by_number( '8014' ); 56 | ` 57 | 3. Test for an error 58 | ` 59 | if( is_wp_error( $set_data ) { 60 | echo $set_data->get_error_message; 61 | } 62 | ` 63 | 64 | 4. Display the results how you like. This will display the set's theme. 65 | ` 66 | else { 67 | echo $set_data->theme; 68 | } 69 | ` 70 | == Road Map == 71 | 1. Template tags to display sets specific to a user. 72 | 2. Caching of images 73 | 74 | You can follow all the open feature requests and enhancements on [GitHub](https://github.com/NateJacobs/Brickset-API/issues?milestone=&page=1&state=open). 75 | 76 | == Installation == 77 | 78 | 1. Upload the entire `brickset-api` folder to the `wp-content/plugins/` directory of your WordPress installation or download from the Plugin Repository 79 | 2. Activate the plugin through the Plugins menu in WordPress 80 | 3. Add your Brickset.com API key to the Brickset settings page which can be found as a submenu under the Settings menu 81 | 3. Either add a Brickset link (url) to a set or theme in a post or page, or add a template tag to a theme file, or for advanced use instantiate the class and create your own display method. 82 | 83 | == Frequently Asked Questions == 84 | 85 | = Can I add sets to my set list on Brickset with this plugin? = 86 | Yes you can, but it requires writing custom code using the API functions of the plugin. 87 | 88 | = Does this plugin require an API Key from Brickset = 89 | To display more than twenty sets from a search query an API key is required. You can obtain one by contacting Brickset on this [page](http://brickset.com/contact/). 90 | 91 | == Screenshots == 92 | 1. Individual Set Display 93 | 2. Years theme is available 94 | 3. Sets in space theme 95 | 96 | == Changelog == 97 | 98 | = Version 1.4.0 = 99 | * New owned minifig widget - display how many minifigs you own 100 | * New theme years widget - display how many sets were produced for a given theme in a given year 101 | * Introduce filters to enable overwriting the default cache time of 24 hours for Brickset data 102 | * Add third parameter to shortcode functions 103 | 104 | = Version 1.3 = 105 | * Add a new widget to display set details 106 | * Add current_user_can check to user profile settings 107 | * Administrators can now select which currency (US dollar, CA dollar, UK pound) is displayed when using the built in template tags, shortcode and oembed set data 108 | * Administrators can choose if the Bricklink link is displayed in template tags, shortcode and oembed set data 109 | 110 | = Version 1.2 = 111 | * Removed anonymous function from class-widgets.php 112 | 113 | = Version 1.1 = 114 | * Add ability to update wanted and owned sets 115 | * Add ability to update the quantity owned of a set 116 | * Add ability to search a user's minifig collections 117 | * Add ability to update wanted and owned minifigs 118 | * Updated class name - BricksetAPIFunctions became BricksetAPISearch 119 | 120 | = Version 1.0 = 121 | * Enter your Brickset API from the settings submenu. 122 | * Allow users to authenticate with Brickset from their profile page. 123 | * Refactor code base 124 | * Add localization and translation .po 125 | * Create webservice-definition.json to display details about the availble calls 126 | * Brickset oembed support for set and theme URLs 127 | 128 | = Version 0.3 = 129 | * Added get_owned function and shortcode. 130 | 131 | = Version 0.2 = 132 | * Get_set and my_wanted shortcodes added. 133 | * BricksetAPIFunctions updated to use wp_remote_get. 134 | * Added template tags for use in themes. 135 | 136 | = Version 0.1 = 137 | * Initial plugin. -------------------------------------------------------------------------------- /screenshot-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/screenshot-1.png -------------------------------------------------------------------------------- /screenshot-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/screenshot-2.png -------------------------------------------------------------------------------- /screenshot-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NateJacobs/Brickset-API/ae7ecc4053c13c9fb7c8109386767dace08f4055/screenshot-3.png -------------------------------------------------------------------------------- /webservice-definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Brickset Web Services", 3 | "apiVersion": "2013-01-27", 4 | "baseUrl": "http://www.brickset.com/webservices/brickset.asmx", 5 | "xmlNamespace": "http://www.brickset.com/webServices/", 6 | "description": "Brickset Web Services allow you to create applications that use the Brickset set database.", 7 | "operations": { 8 | "search": { 9 | "httpMethod": "GET", 10 | "uri": "/search", 11 | "summary": "Search the database.", 12 | "responseClass": "setData", 13 | "parameters": { 14 | "apiKey": { 15 | "location": "query", 16 | "type": "string", 17 | "description": "Without providing a valid key a maximum of 20 results will be returned.", 18 | "required": true, 19 | "default": null 20 | }, 21 | "userHash": { 22 | "location": "query", 23 | "type": "string", 24 | "description": "If this is provided, the returned data will contain flags indicating whether the specified user owns and/or wants the set.", 25 | "required": true, 26 | "default": null 27 | }, 28 | "query": { 29 | "location": "query", 30 | "type": "string", 31 | "description": "A search string.", 32 | "required": true, 33 | "default": null 34 | }, 35 | "theme": { 36 | "location": "query", 37 | "type": "string", 38 | "description": "Valid name of a theme.", 39 | "required": true, 40 | "default": null 41 | }, 42 | "subtheme": { 43 | "location": "query", 44 | "type": "string", 45 | "description": "Valid name of a subtheme.", 46 | "required": true, 47 | "default": null 48 | }, 49 | "setNumber": { 50 | "location": "query", 51 | "type": "string", 52 | "description": "A set number. It must include a '-#' after the number. e.g. 8683-1", 53 | "required": true, 54 | "default": "" 55 | }, 56 | "year": { 57 | "location": "query", 58 | "type": "string", 59 | "description": "Release year of a set(s).", 60 | "required": true, 61 | "default": null 62 | }, 63 | "Owned": { 64 | "location": "query", 65 | "type": "string", 66 | "description": "Pass a '1' to get a list of set(s) the specified user owns.", 67 | "required": true, 68 | "default": null 69 | }, 70 | "Wanted": { 71 | "location": "query", 72 | "type": "string", 73 | "description": "Pass a '1' to get a list of set(s) the specified user wants.", 74 | "required": true, 75 | "default": null 76 | } 77 | } 78 | }, 79 | "searchBySetID": { 80 | "httpMethod": "GET", 81 | "uri": "/searchBySetID", 82 | "summary": "Search the database for a specific set using the Brickset interal set ID.", 83 | "responseClass": "setData", 84 | "parameters": { 85 | "SetID": { 86 | "location": "query", 87 | "type": "string", 88 | "description": "The internal Brickset setID", 89 | "required": true 90 | } 91 | } 92 | }, 93 | "updatedSince": { 94 | "httpMethod": "GET", 95 | "uri": "/updatedSince", 96 | "summary": "Lists all set records changed since the date you specify (in mm/dd/yy format). This is useful if you are planning on caching the database for offline use. The data set returned will contain user ownership fields, but they will not be populated (since userHash is not passed as a parameter).", 97 | "responseClass": "setData", 98 | "parameters": { 99 | "apiKey": { 100 | "location": "query", 101 | "type": "string", 102 | "description": "Without providing a valid key a maximum of 20 results will be returned.", 103 | "required": true, 104 | "default": null 105 | }, 106 | "sinceDate": { 107 | "location": "query", 108 | "type": "string", 109 | "description": "A date in the format of mm/dd/yy." 110 | } 111 | } 112 | }, 113 | "login": { 114 | "httpMethod": "GET", 115 | "uri": "/login", 116 | "summary": "Provides a means of authenticating a user by username and password. If the credentials match a valid user a userHash is returned.", 117 | "responseClass": "loginResponse", 118 | "parameters": { 119 | "u": { 120 | "location": "query", 121 | "type": "string", 122 | "description": "Username", 123 | "required": true 124 | }, 125 | "p": { 126 | "location": "query", 127 | "type": "string", 128 | "description": "Password", 129 | "required": true 130 | } 131 | } 132 | }, 133 | "updateOwn": { 134 | "httpMethod": "POST", 135 | "uri": "/updateOwn", 136 | "summary": "Add or delete a set from a users collection.", 137 | "responseClass": "updateOwnResponse", 138 | "parameters": { 139 | "userHash": { 140 | "location": "body", 141 | "type": "string", 142 | "description": "The userHash of the user that wants to add or delete a set.", 143 | "required": true 144 | }, 145 | "setID": { 146 | "location": "body", 147 | "type": "int", 148 | "description": "Brickset internal setID. ", 149 | "required": true 150 | }, 151 | "own": { 152 | "location": "body", 153 | "type": "int", 154 | "description": "Pass a 1 to add the set or a 0 to remove the set.", 155 | "required": true 156 | } 157 | } 158 | }, 159 | "updateWant": { 160 | "httpMethod": "POST", 161 | "uri": "/updateWant", 162 | "summary": "Add or delete a set from the users wanted list.", 163 | "responseClass": "updateWantResponse", 164 | "parameters": { 165 | "userHash": { 166 | "location": "body", 167 | "type": "string", 168 | "description": "The userHash of the user that wants to add or remove a wanted set.", 169 | "required": true 170 | }, 171 | "setID": { 172 | "location": "body", 173 | "type": "int", 174 | "description": "Brickset internal setID", 175 | "required": true 176 | }, 177 | "want": { 178 | "location": "body", 179 | "type": "int", 180 | "description": "Pass a 1 to add the set or a 0 to remove the set.", 181 | "required": true 182 | } 183 | } 184 | }, 185 | "updateUserNotes": { 186 | "httpMethod": "POST", 187 | "uri": "/updateUserNotes", 188 | "summary": "Add text which will replace the user's notes for the specified set.", 189 | "responseClass": "updateUserNotesResponse", 190 | "parameters": { 191 | "userHash": { 192 | "location": "body", 193 | "type": "string", 194 | "description": "The userHash of the user that wants to add or replace a note on a set.", 195 | "required": true 196 | }, 197 | "setID": { 198 | "location": "body", 199 | "type": "int", 200 | "description": "Brickset internal setID", 201 | "required": true 202 | }, 203 | "notes": { 204 | "location": "body", 205 | "type": "string", 206 | "description": "String which will replace the user's notes for the set.", 207 | "required": true 208 | } 209 | } 210 | }, 211 | "updateQtyOwned": { 212 | "httpMethod": "POST", 213 | "uri": "/updateQtyOwned", 214 | "summary": "Updates the quantity of a set the user owns.", 215 | "responseClass": "updateQtyOwnedResponse", 216 | "parameters": { 217 | "userHash": { 218 | "location": "body", 219 | "type": "string", 220 | "description": "The userHash of the user that wants to update the quantity owned of a set.", 221 | "required": true 222 | }, 223 | "setID": { 224 | "location": "body", 225 | "type": "int", 226 | "description": "Brickset internal setID. ", 227 | "required": true 228 | }, 229 | "qty": { 230 | "location": "body", 231 | "type": "int", 232 | "description": "An integer to specify how many of the set the user owns.", 233 | "required": true 234 | } 235 | } 236 | }, 237 | "listThemes": { 238 | "httpMethod": "GET", 239 | "uri": "/listThemes", 240 | "summary": "Return a list of themes and the number of sets in each.", 241 | "responseClass": "themeData" 242 | }, 243 | "listSubthemes": { 244 | "httpMethod": "GET", 245 | "uri": "/listSubthemes", 246 | "summary": "Return a list of subthemes for a given theme and the number of sets in each.", 247 | "responseClass": "subThemedata", 248 | "parameters": { 249 | "theme": { 250 | "location": "query", 251 | "type": "string", 252 | "description": "Theme name", 253 | "required": true 254 | } 255 | } 256 | }, 257 | "listYears": { 258 | "httpMethod": "GET", 259 | "uri": "/listYears", 260 | "summary": "Return a list of years a given theme was available in and the number of sets released that year.", 261 | "responseClass": "yearData", 262 | "parameters": { 263 | "theme": { 264 | "location": "query", 265 | "type": "string", 266 | "description": "Theme name.", 267 | "required": true 268 | } 269 | } 270 | }, 271 | "popularSearches": { 272 | "httpMethod": "GET", 273 | "uri": "/popularSearches", 274 | "summary": "Return a list of the most searched for terms as shown on the Brickset homepage.", 275 | "responseClass": "setData" 276 | }, 277 | "searchMinifigCollection": { 278 | "httpMethod": "GET", 279 | "uri": "/searchMinifigCollection", 280 | "summary": "Return a list of all minifigs owned or wanted by a user that optionally match a query. Leave owned and wanted blank to retrieve those owned and wanted, or set one of them to '1' to get just owned or just wanted. query can be a complete minifig number (e.g. 'hp001'), or just a prefix (e.g. 'hp'). Leave blank to retrieve all.", 281 | "responseClass": "minifigCollectionData", 282 | "parameters": { 283 | "userHash": { 284 | "location": "query", 285 | "type": "string", 286 | "description": "The userHash of the user whose minifig collection is to be searched.", 287 | "required": true 288 | }, 289 | "query": { 290 | "location": "query", 291 | "type": "string", 292 | "description": "A complete minifig number or a prefix, e.g. 'hp001' or just a prefix 'hp'.", 293 | "required": true, 294 | "default": null 295 | }, 296 | "owned": { 297 | "location": "query", 298 | "type": "string", 299 | "description": "Enter a 1 to retrieve all minifigs owned by the user that are returned from the query. Leave blank if want both owned and wanted.", 300 | "required": true, 301 | "default": null 302 | }, 303 | "wanted": { 304 | "location": "query", 305 | "type": "string", 306 | "description": "Enter a 1 to retrieve all minifigs wanted by the user that are returned from the query. Leave blank if want both owned and wanted.", 307 | "required": true, 308 | "default": null 309 | } 310 | } 311 | }, 312 | "updateMinifigQtyOwned": { 313 | "httpMethod": "POST", 314 | "uri": "/updateMinifigQtyOwned", 315 | "summary": "Update the quantity of loose minifigs a user has.", 316 | "responseClass": "updateMinifigQtyOwnedResponse", 317 | "parameters": { 318 | "userHash": { 319 | "location": "body", 320 | "type": "string", 321 | "description": "The userHash of the user to update the loose minifig count for.", 322 | "required": true 323 | }, 324 | "minifigNumber": { 325 | "location": "body", 326 | "type": "string", 327 | "description": "The Brickset internal minifig number.", 328 | "required": true 329 | }, 330 | "qty": { 331 | "location": "body", 332 | "type": "int", 333 | "description": "An integer specifiying how many loose minifigs of this type the user owns.", 334 | "required": true 335 | } 336 | } 337 | }, 338 | "updateMinifigWanted": { 339 | "httpMethod": "POST", 340 | "uri": "/updateMinifigWanted", 341 | "summary": "Set the wanted status of a minifig for a user. Currently users can't simultaneously own and want the same minifig. Setting a minifig as wanted will clear the quantity owned.", 342 | "responseClass": "updateMinifigWantedResponse", 343 | "parameters": { 344 | "userHash": { 345 | "location": "body", 346 | "type": "string", 347 | "description": "The userHash of the user to update the wanted status.", 348 | "required": true 349 | }, 350 | "minifigNumber": { 351 | "location": "body", 352 | "type": "string", 353 | "description": "The Brickset internal minifig number.", 354 | "required": true 355 | }, 356 | "want": { 357 | "location": "body", 358 | "type": "int", 359 | "description": "Pass the integer 1 to add a minifig to a users wanted list.", 360 | "required": true 361 | } 362 | } 363 | }, 364 | "listInstructions": { 365 | "httpMethod": "GET", 366 | "uri": "/listInstructions", 367 | "summary": "Returns the URL of the instructions available at LEGO Customer Services.", 368 | "responseClass": "instructionsData", 369 | "parameters": { 370 | "setID": { 371 | "location": "query", 372 | "type": "int", 373 | "description": "Brickset setID.", 374 | "required": true 375 | } 376 | } 377 | } 378 | }, 379 | "models": { 380 | "setData": { 381 | "type": "object", 382 | "properties": { 383 | "setID": { 384 | "location": "xml", 385 | "type": "int", 386 | "description": "Brickset internal set ID." 387 | }, 388 | "number": { 389 | "location": "xml", 390 | "type": "string", 391 | "description": "Set number." 392 | }, 393 | "numberVariant": { 394 | "location": "xml", 395 | "type": "int", 396 | "description": "Set number variant." 397 | }, 398 | "setName": { 399 | "location": "xml", 400 | "type": "string", 401 | "description": "Set name." 402 | }, 403 | "year": { 404 | "location": "xml", 405 | "type": "string", 406 | "description": "Release year." 407 | }, 408 | "theme": { 409 | "location": "xml", 410 | "type": "string", 411 | "description": "Set theme." 412 | }, 413 | "subtheme": { 414 | "location": "xml", 415 | "type": "string", 416 | "description": "Set subtheme." 417 | }, 418 | "pieces": { 419 | "location": "xml", 420 | "type": "string", 421 | "description": "Number of pieces in the set." 422 | }, 423 | "minifigs": { 424 | "location": "xml", 425 | "type": "string", 426 | "description": "Number of minifigs in the set." 427 | }, 428 | "image": { 429 | "location": "xml", 430 | "type": "boolean", 431 | "description": "Is an there an image?" 432 | }, 433 | "imageFilename": { 434 | "location": "xml", 435 | "type": "string", 436 | "description": "Filename of image." 437 | }, 438 | "thumbnailURL": { 439 | "location": "xml", 440 | "type": "string", 441 | "description": "URL of the thumbnail image." 442 | }, 443 | "imageURL": { 444 | "location": "xml", 445 | "type": "string", 446 | "description": "URL of the image." 447 | }, 448 | "bricksetURL": { 449 | "location": "xml", 450 | "type": "string", 451 | "description": "URL of the set on Brickset" 452 | }, 453 | "own": { 454 | "location": "xml", 455 | "type": "boolean", 456 | "description": "Is the set owned by the user specified in userHash?" 457 | }, 458 | "want": { 459 | "location": "xml", 460 | "type": "boolean", 461 | "description": "Is the set wanted by the user specified in userHash?" 462 | }, 463 | "qtyOwned": { 464 | "location": "xml", 465 | "type": "int", 466 | "description": "Quantity of this set owned by the user specified in userHash." 467 | }, 468 | "userNotes": { 469 | "location": "xml", 470 | "type": "string", 471 | "description": "Notes about the set entered by the user specified in userHash." 472 | }, 473 | "UKRetailPrice": { 474 | "location": "xml", 475 | "type": "string", 476 | "description": "Retail price in the United Kingdom." 477 | }, 478 | "USRetailPrice": { 479 | "location": "xml", 480 | "type": "string", 481 | "description": "Retail price in the United States." 482 | }, 483 | "CARetailPrice": { 484 | "location": "xml", 485 | "type": "string", 486 | "description": "Retail price in Canada." 487 | }, 488 | "instructionsAvailable": { 489 | "location": "xml", 490 | "type": "boolean", 491 | "description": "Are instructions available?" 492 | }, 493 | "EAN": { 494 | "location": "xml", 495 | "type": "string", 496 | "description": "International Article Number." 497 | }, 498 | "UPC": { 499 | "location": "xml", 500 | "type": "string", 501 | "description": "Universal Product Code." 502 | }, 503 | "lastUpdated": { 504 | "location": "xml", 505 | "type": "string", 506 | "description": "Last updated, dateTime string." 507 | } 508 | } 509 | }, 510 | "themeData": { 511 | "type": "object", 512 | "properties": { 513 | "theme": { 514 | "location": "xml", 515 | "type": "string", 516 | "description": "Theme name." 517 | }, 518 | "setCount": { 519 | "location": "xml", 520 | "type": "int", 521 | "description": "Number of sets in theme." 522 | } 523 | } 524 | }, 525 | "subthemeData": { 526 | "type": "object", 527 | "properties": { 528 | "theme": { 529 | "location": "xml", 530 | "type": "string", 531 | "description": "Parent theme." 532 | }, 533 | "subtheme": { 534 | "location": "xml", 535 | "type": "string", 536 | "description": "Subtheme name." 537 | }, 538 | "setCount": { 539 | "location": "xml", 540 | "type": "int", 541 | "description": "Number of sets in subtheme." 542 | }, 543 | "yearFrom": { 544 | "location": "xml", 545 | "type": "int", 546 | "description": "First year the subtheme was released." 547 | }, 548 | "yearTo": { 549 | "location": "xml", 550 | "type": "int", 551 | "description": "Last year the subtheme was released." 552 | } 553 | } 554 | }, 555 | "yearData": { 556 | "type": "object", 557 | "properties": { 558 | "theme": { 559 | "location": "xml", 560 | "type": "string", 561 | "description": "Theme name." 562 | }, 563 | "year": { 564 | "location": "xml", 565 | "type": "string", 566 | "description": "Release year." 567 | }, 568 | "setCount": { 569 | "location": "xml", 570 | "type": "int", 571 | "description": "Number of sets released that year." 572 | } 573 | } 574 | }, 575 | "searchData": { 576 | "type": "object", 577 | "properties": { 578 | "searchTerm": { 579 | "location": "xml", 580 | "type": "string", 581 | "description": "The search query." 582 | }, 583 | "count": { 584 | "location": "xml", 585 | "type": "int", 586 | "description": "Relative weightings of the search query." 587 | } 588 | } 589 | }, 590 | "minifigCollectionData": { 591 | "type": "object", 592 | "properties": { 593 | "minifigNumber": { 594 | "location": "xml", 595 | "type": "string", 596 | "description": "Brickset minifigID" 597 | }, 598 | "ownedInSets": { 599 | "location": "xml", 600 | "type": "int", 601 | "description": "Quantity of this minifig owned by the specified user as part of a set." 602 | }, 603 | "ownedLoose": { 604 | "location": "xml", 605 | "type": "int", 606 | "description": "Quantity of this minifig owned by the specified user not part of a set." 607 | }, 608 | "ownedTotal": { 609 | "location": "xml", 610 | "type": "int", 611 | "description": "Total quantity of this minifig owned by the specified user." 612 | }, 613 | "wanted": { 614 | "location": "xml", 615 | "type": "boolean", 616 | "description": "Is this minifig wanted by the specified user?" 617 | } 618 | } 619 | }, 620 | "instructionsData": { 621 | "type": "object", 622 | "properties": { 623 | "URL": { 624 | "location": "xml", 625 | "type": "string", 626 | "description": "URL of the pdf of the instructions." 627 | }, 628 | "description": { 629 | "location": "xml", 630 | "type": "string", 631 | "description": "Description returned with the instructions." 632 | } 633 | } 634 | }, 635 | "loginResponse": { 636 | "location": "xml", 637 | "type": "string", 638 | "description": "If valid user credentials are passed the response will be the userHash. If the response string is empty the credentials were invalid or no user was found." 639 | }, 640 | "updateOwnResponse": { 641 | "location": "xml", 642 | "type": "int", 643 | "description": "If the update is successful a 1 is returned." 644 | }, 645 | "updateWantResponse": { 646 | "location": "xml", 647 | "type": "int", 648 | "description": "If the update is successful a 1 is returned." 649 | }, 650 | "updateUserNotesResponse": { 651 | "location": "xml", 652 | "type": "int", 653 | "description": "If the update is successful a 1 is returned." 654 | }, 655 | "updateQtyOwnedResponse": { 656 | "location": "xml", 657 | "type": "int", 658 | "description": "If the update is successful a 1 is returned." 659 | }, 660 | "updateMinifigQtyOwnedResponse": { 661 | "location": "xml", 662 | "type": "int", 663 | "description": "If the update is successful a 1 is returned." 664 | }, 665 | "updateMinifigWantedResponse": { 666 | "location": "xml", 667 | "type": "int", 668 | "description": "If the update is successful a 1 is returned." 669 | } 670 | } 671 | } --------------------------------------------------------------------------------