Instagram Widget by WPZOOM - Version 1.7.5

Version Description

  • Fixed strings text domain
  • Fixed dismiss url for admin notice
  • Added Text Domain and Domain Path to plugin description
Download this release

Release Info

Developer WPZOOM
Plugin Icon 128x128 Instagram Widget by WPZOOM
Version 1.7.5
Comparing to
See all releases

Code changes from version 1.6.4 to 1.7.5

LICENSE ADDED
@@ -0,0 +1,339 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
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.
class-wpzoom-instagram-image-uploader.php ADDED
@@ -0,0 +1,394 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Exit if accessed directly.
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ /**
10
+ * Class WPZOOM_Instagram_Image_Uploader
11
+ */
12
+ class WPZOOM_Instagram_Image_Uploader {
13
+ public static $ajax_action_name = 'wpzoom_instagram_get_image_async';
14
+ private static $instance;
15
+ private static $media_metakey_name = 'wpzoom_instagram_media_id';
16
+ private static $prefix_name = 'wpzoom-share-buttons';
17
+ private static $post_status_name = 'wpzoom-hidden';
18
+ private static $transient_name = 'zoom_instagram_is_configured';
19
+
20
+ /**
21
+ * WPZOOM_Instagram_Image_Uploader constructor.
22
+ */
23
+ private function __construct() {
24
+ // Private to disabled instantiation.
25
+ }
26
+
27
+ /**
28
+ * @return mixed
29
+ */
30
+ public static function getInstance() {
31
+ if ( null === self::$instance ) {
32
+ self::$instance = new self();
33
+ add_action( 'init', self::$instance, 'custom_post_status' );
34
+ add_action( 'wp_ajax_' . self::$ajax_action_name, array( self::$instance, 'get_image_async' ) );
35
+ add_action( 'wp_ajax_nopriv_' . self::$ajax_action_name, array( self::$instance, 'get_image_async' ) );
36
+
37
+ }
38
+
39
+ return self::$instance;
40
+ }
41
+
42
+ /**
43
+ * Get image.
44
+ *
45
+ * @param $media_size
46
+ * @param $media_url
47
+ * @param $media_id
48
+ *
49
+ * @return bool
50
+ */
51
+ static function get_image( $media_size, $media_url, $media_id ) {
52
+
53
+ $args = array(
54
+ 'post_type' => 'attachment',
55
+ 'posts_per_page' => 1,
56
+ 'post_status' => self::$post_status_name,
57
+ 'meta_query' => array(
58
+ array(
59
+ 'key' => self::$media_metakey_name,
60
+ 'value' => $media_id,
61
+ ),
62
+ ),
63
+ );
64
+ $query = new WP_Query( $args );
65
+
66
+ if ( $query->have_posts() ) {
67
+ $post = array_shift( $query->posts );
68
+ $attachment_id = $post->ID;
69
+
70
+ $image_src = wp_get_attachment_image_src( $attachment_id, self::get_image_size_name( $media_size ) );
71
+
72
+ return ! empty( $image_src ) ? $image_src[0] : $media_url;
73
+
74
+ }
75
+
76
+ return false;
77
+ }
78
+
79
+ /**
80
+ * Get prefixed image size name.
81
+ *
82
+ * @param $size
83
+ *
84
+ * @return string
85
+ */
86
+ public static function get_image_size_name( $size ) {
87
+
88
+ return self::$prefix_name . '-' . $size;
89
+
90
+ }
91
+
92
+ /**
93
+ * Get response api from transient.
94
+ *
95
+ * @return mixed
96
+ */
97
+ function get_api_transient() {
98
+ return json_decode( get_transient( self::$transient_name ) );
99
+ }
100
+
101
+ /**
102
+ * Get transient lifetime from settings.
103
+ *
104
+ * @return float|int
105
+ */
106
+ function get_transient_lifetime() {
107
+
108
+ $options = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
109
+
110
+ $values = array(
111
+ 'minutes' => MINUTE_IN_SECONDS,
112
+ 'hours' => HOUR_IN_SECONDS,
113
+ 'days' => DAY_IN_SECONDS,
114
+ );
115
+ $keys = array_keys( $values );
116
+ $type = in_array( $options['transient-lifetime-type'], $keys ) ? $values[ $options['transient-lifetime-type'] ] : $values['minutes'];
117
+
118
+ return $type * $options['transient-lifetime-value'];
119
+ }
120
+
121
+ /**
122
+ * Get image from ajax.
123
+ */
124
+ function get_image_async() {
125
+
126
+ $sliced = wp_array_slice_assoc( $_POST, array( 'media-id', 'nonce', 'image-resolution', 'image-width', 'regenerate-thumbnails' ) );
127
+ $sliced = array_map( 'sanitize_text_field', $sliced );
128
+
129
+ if ( ! wp_verify_nonce( $sliced['nonce'], self::get_nonce_action( $sliced['media-id'] ) ) ) {
130
+ $error = new WP_Error( '001', __( 'Invalid nonce.', 'wpzoom-instagram-widget' ), __( 'Invalid nonce provided for this action', 'wpzoom-instagram-widget' ) );
131
+
132
+ wp_send_json_error( $error, 500 );
133
+ }
134
+
135
+ $media_url = self::get_media_url_by_id( $sliced['media-id'] );
136
+
137
+ if ( empty( $media_url ) ) {
138
+ $error = new WP_Error( '002', __( 'Invalid media id.', 'wpzoom-instagram-widget' ), __( 'Could not retrieve image url with provided media id', 'wpzoom-instagram-widget' ) );
139
+
140
+ wp_send_json_error( $error, 500 );
141
+ }
142
+
143
+ $args = array(
144
+ 'post_type' => 'attachment',
145
+ 'posts_per_page' => 1,
146
+ 'post_status' => self::$post_status_name,
147
+ 'meta_query' => array(
148
+ array(
149
+ 'key' => self::$media_metakey_name,
150
+ 'value' => $sliced['media-id'],
151
+ ),
152
+ ),
153
+ );
154
+
155
+ $query = new WP_Query( $args );
156
+
157
+ if ( $query->have_posts() ) {
158
+ $post = array_shift( $query->posts );
159
+ $attachment_id = $post->ID;
160
+
161
+ } else {
162
+ $attachment_id = self::upload_image( $media_url, $sliced['media-id'] );
163
+ self::$instance->set_images_to_transient( $attachment_id, $sliced['media-id'] );
164
+ }
165
+
166
+ if ( wp_validate_boolean( $sliced['regenerate-thumbnails'] ) ) {
167
+
168
+ $metadata = $this->regenerate_thumbnails( $attachment_id );
169
+
170
+ if ( ! is_wp_error( $metadata ) && ! empty( $metadata ) ) {
171
+ self::$instance->set_images_to_transient( $attachment_id, $sliced['media-id'] );
172
+ }
173
+ }
174
+
175
+ if ( is_wp_error( $attachment_id ) ) {
176
+ wp_send_json_error( $attachment_id, 500 );
177
+ }
178
+
179
+ $media_size = self::$instance->get_best_size( $sliced['image-width'], $sliced['image-resolution'] );
180
+
181
+ $image_src = wp_get_attachment_image_src( $attachment_id, self::get_image_size_name( $media_size ) );
182
+
183
+ $image_src = ! empty( $image_src ) ? $image_src[0] : $media_url;
184
+
185
+ wp_send_json_success( array( 'image_src' => $image_src ) );
186
+ }
187
+
188
+ /**
189
+ * @param $id
190
+ *
191
+ * @return string
192
+ */
193
+ public static function get_nonce_action( $id ) {
194
+ return self::$ajax_action_name . '_' . $id;
195
+ }
196
+
197
+ public function regenerate_thumbnails( $attachment_id ) {
198
+ $fullsizepath = get_attached_file( $attachment_id );
199
+
200
+ add_filter( 'intermediate_image_sizes_advanced', array( self::$instance, 'set_image_sizes' ), 10 );
201
+
202
+ $metadata = wp_generate_attachment_metadata( $attachment_id, $fullsizepath );
203
+
204
+ remove_filter( 'intermediate_image_sizes_advanced', array( self::$instance, 'set_image_sizes' ), 10 );
205
+ return $metadata;
206
+ }
207
+
208
+ /**
209
+ * @param $media_id
210
+ *
211
+ * @return bool
212
+ */
213
+ public static function get_media_url_by_id( $media_id ) {
214
+
215
+ $transient = self::$instance->get_api_transient();
216
+
217
+ if ( empty( $transient->data ) ) {
218
+ return false;
219
+ }
220
+ $plucked = wp_list_pluck( $transient->data, 'media_url', 'id' );
221
+
222
+ return array_key_exists( $media_id, $plucked ) ? $plucked[ $media_id ] : false;
223
+ }
224
+
225
+ /**
226
+ * @param $media_url
227
+ * @param $media_id
228
+ *
229
+ * @return string|WP_Error
230
+ */
231
+ static function upload_image( $media_url, $media_id ) {
232
+
233
+ require_once ABSPATH . 'wp-admin/includes/media.php';
234
+ require_once ABSPATH . 'wp-admin/includes/file.php';
235
+ require_once ABSPATH . 'wp-admin/includes/image.php';
236
+
237
+ add_filter( 'intermediate_image_sizes_advanced', array( self::$instance, 'set_image_sizes' ), 10 );
238
+ add_filter( 'wp_insert_attachment_data', array( self::$instance, 'insert_post_data' ), 10 );
239
+
240
+ $attachment_id = media_sideload_image( $media_url, null, null, 'id' );
241
+
242
+ remove_filter( 'intermediate_image_sizes_advanced', array( self::$instance, 'set_image_sizes' ), 10 );
243
+ remove_filter( 'wp_insert_attachment_data', array( self::$instance, 'insert_post_data' ), 10 );
244
+
245
+ update_post_meta( $attachment_id, self::$media_metakey_name, $media_id );
246
+
247
+ return $attachment_id;
248
+
249
+ }
250
+
251
+ /**
252
+ * @param $post_data
253
+ *
254
+ * @return mixed
255
+ */
256
+ public function insert_post_data( $post_data ) {
257
+
258
+ $post_data['post_status'] = self::$post_status_name;
259
+
260
+ return $post_data;
261
+ }
262
+
263
+ /**
264
+ * Register custom post status.
265
+ */
266
+ function custom_post_status() {
267
+ register_post_status(
268
+ self::$post_status_name,
269
+ array(
270
+ 'public' => true,
271
+ 'exclude_from_search' => true,
272
+ 'internal' => true,
273
+ )
274
+ );
275
+ }
276
+
277
+ /**
278
+ * Disable the cloning of this class.
279
+ *
280
+ * @return void
281
+ */
282
+ final public function __clone() {
283
+ throw new Exception( 'Feature disabled.' );
284
+ }
285
+
286
+ /**
287
+ * Disable the wakeup of this class.
288
+ *
289
+ * @return void
290
+ */
291
+ final public function __wakeup() {
292
+ throw new Exception( 'Feature disabled.' );
293
+ }
294
+
295
+ /**
296
+ * Set image sizes.
297
+ *
298
+ * @param $sizes
299
+ *
300
+ * @return array
301
+ */
302
+ function set_image_sizes( $sizes ) {
303
+
304
+ return array(
305
+ self::get_image_size_name( 'thumbnail' ) => array(
306
+ 'width' => 150,
307
+ 'height' => 150,
308
+ ),
309
+ self::get_image_size_name( 'low_resolution' ) => array(
310
+ 'width' => 320,
311
+ 'height' => 320,
312
+ ),
313
+ self::get_image_size_name( 'standard_resolution' ) => array(
314
+ 'width' => 640,
315
+ 'height' => 640,
316
+ ),
317
+ );
318
+
319
+ }
320
+
321
+ /**
322
+ * Alter transient data object with the new values.
323
+ *
324
+ * @param $attachment_id
325
+ * @param $media_id
326
+ */
327
+ protected function set_images_to_transient( $attachment_id, $media_id ) {
328
+
329
+ $transient = self::$instance->get_api_transient();
330
+
331
+ if ( ! empty( $transient->data ) ) {
332
+ foreach ( $transient->data as $key => $item ) {
333
+ if ( $item->id === $media_id ) {
334
+ $thumbnail = wp_get_attachment_image_src( $attachment_id, self::get_image_size_name( 'thumbnail' ) );
335
+ $low_resolution = wp_get_attachment_image_src( $attachment_id, self::get_image_size_name( 'low_resolution' ) );
336
+ $standard_resolution = wp_get_attachment_image_src( $attachment_id, self::get_image_size_name( 'standard_resolution' ) );
337
+ $item->images->thumbnail->url = ! empty( $thumbnail ) ? $thumbnail[0] : '';
338
+ $item->images->low_resolution->url = ! empty( $low_resolution ) ? $low_resolution[0] : '';
339
+
340
+ $item->images->standard_resolution->url = ! empty( $standard_resolution ) ? $standard_resolution[0] : '';
341
+
342
+ $transient->data[ $key ] = $item;
343
+ }
344
+ }
345
+
346
+ $this->set_api_transient( $transient );
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Set api transient.
352
+ *
353
+ * @param $data
354
+ *
355
+ * @return bool
356
+ */
357
+ function set_api_transient( $data ) {
358
+ return set_transient( self::$transient_name, wp_json_encode( $data ), self::$instance->get_transient_lifetime() );
359
+ }
360
+
361
+ /**
362
+ * Get best image size.
363
+ *
364
+ * @param $desired_width
365
+ * @param string $image_resolution
366
+ *
367
+ * @return int|string
368
+ */
369
+ protected function get_best_size( $desired_width, $image_resolution = 'default_algorithm' ) {
370
+
371
+ $size = 'thumbnail';
372
+
373
+ $sizes = array(
374
+ 'thumbnail' => 150,
375
+ 'low_resolution' => 320,
376
+ 'standard_resolution' => 640,
377
+ );
378
+
379
+ $diff = PHP_INT_MAX;
380
+
381
+ if ( array_key_exists( $image_resolution, $sizes ) ) {
382
+ return $image_resolution;
383
+ }
384
+
385
+ foreach ( $sizes as $key => $value ) {
386
+ if ( abs( $desired_width - $value ) < $diff ) {
387
+ $size = $key;
388
+ $diff = abs( $desired_width - $value );
389
+ }
390
+ }
391
+
392
+ return $size;
393
+ }
394
+ }
class-wpzoom-instagram-widget-api.php CHANGED
@@ -1,333 +1,350 @@
1
  <?php
 
 
 
 
 
 
2
 
3
  class Wpzoom_Instagram_Widget_API {
4
- /**
5
- * @var Wpzoom_Instagram_Widget_API The reference to *Singleton* instance of this class
6
- */
7
- private static $instance;
8
-
9
- /**
10
- * Instagram Access Token
11
- *
12
- * @var string
13
- */
14
- protected $access_token;
15
-
16
- /**
17
- * Request headers.
18
- *
19
- * @var array
20
- */
21
- public $headers = [];
22
-
23
  /**
24
  * Errors collector.
25
  *
26
  * @var array|WP_Error
27
  */
28
- public $errors = [];
29
-
30
- /**
31
- * Returns the *Singleton* instance of this class.
32
- *
33
- * @return Wpzoom_Instagram_Widget_API The *Singleton* instance.
34
- */
35
- public static function getInstance()
36
- {
37
- if ( null === self::$instance ) {
38
- self::$instance = new self();
39
- }
40
-
41
- return self::$instance;
42
- }
43
-
44
- protected function __construct() {
45
- $options = get_option( 'wpzoom-instagram-widget-settings' , wpzoom_instagram_get_default_settings());
46
 
47
- $this->request_type = !empty($options['request-type']) ? $options['request-type'] : '';
48
- $this->access_token = $options['access-token'];
49
 
50
- if('with-basic-access-token' === $this->request_type){
51
- $this->access_token = $options['basic-access-token'];
52
- }
53
 
 
 
 
 
 
54
 
55
- $this->username = !empty($options['username']) ? $options['username'] : '';
56
- $this->transient_lifetime_type = !empty($options['transient-lifetime-type']) ? $options['transient-lifetime-type'] : 'days';
57
- $this->transient_lifetime_value = !empty($options['transient-lifetime-value']) ? $options['transient-lifetime-value'] : 1;
58
- $this->is_embed_stream = ! empty( $options['is-embed-stream'] ) ? wp_validate_boolean( $options['is-embed-stream'] ) : false;
59
- $this->is_forced_timeout = ! empty($options['is-forced-timeout']) ? wp_validate_boolean( $options['is-forced-timeout'] ) : false;
60
- $this->request_timeout_value = !empty($options['request-timeout-value']) ? $options['request-timeout-value'] : 15;
61
 
62
- if ($this->is_forced_timeout && !empty($this->request_timeout_value)) {
63
- $this->headers['timeout'] = $this->request_timeout_value;
64
- }
65
 
66
- $this->errors = new WP_Error();
67
 
68
- }
69
 
70
  /**
71
- * Get error messages collection.
72
  *
73
- * @return array
74
  */
75
- public function get_errors(){
76
- return [
77
- 'user-info-without-token' => [
78
- 'code' => 'user-info-without-token',
79
- 'message' => __('Empty json user info from Public Feed.', 'wpzoom-instagram-widget')
80
- ],
81
- 'response-data-without-token-from-json-invalid-response' => [
82
- 'code' => 'response-data-without-token-from-json-invalid-response',
83
- 'message' => __('The request from the Public Feed failed. Invalid server response from Public JSON API url.', 'wpzoom-instagram-widget')
84
- ],
85
- 'response-data-without-token-from-json-invalid-json-format' => [
86
- 'code' => 'response-data-without-token-from-json-invalid-json-format',
87
- 'message' => __('The request from the Public Feed failed. Invalid JSON format from Public JSON API url.', 'wpzoom-instagram-widget')
88
- ],
89
- 'response-data-without-token-from-html-invalid-response' => [
90
- 'code' => 'response-data-without-token-from-html-invalid-response',
91
- 'message' => __('The request from the Public Feed failed. Check username.', 'wpzoom-instagram-widget')
92
- ],
93
- 'response-data-without-token-from-html-invalid-json-format' => [
94
- 'code' => 'response-data-without-token-from-html-invalid-json-format',
95
- 'message' => __('The request from the Public Feed failed. Invalid JSON format from parsed html body.', 'wpzoom-instagram-widget')
96
- ],
97
- 'items-without-token-invalid-response' => [
98
- 'code' => 'items-without-token-invalid-response',
99
- 'message' => __('Get items from the Public Feed failed. Invalid response.', 'wpzoom-instagram-widget')
100
- ],
101
- 'items-without-token-invalid-json-structure' => [
102
- 'code' => 'items-without-token-invalid-json-structure',
103
- 'message' => __('Get items from the Public Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
104
- ],
105
- 'items-with-token-invalid-response' => [
106
- 'code' => 'items-with-token-invalid-response',
107
- 'message' => __('Geting items from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget')
108
- ],
109
- 'items-with-token-invalid-data-structure' => [
110
- 'code' => 'items-with-token-invalid-data-structure',
111
- 'message' => __('Get items from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
112
- ],
113
- 'user-with-token-invalid-response' => [
114
- 'code' => 'user-with-token-invalid-response',
115
- 'message' => __('Get user data from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget')
116
- ],
117
- 'user-with-token-invalid-data-structure' => [
118
- 'code' => 'user-with-token-invalid-data-structure',
119
- 'message' => __('Get user data from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget')
120
- ],
121
-
122
- ];
123
- }
124
 
125
  /**
126
- * Retrieve error message by key.
127
- *
128
- * @param $key
129
  *
130
- * @return bool|mixed
131
  */
132
- public function get_error( $key ) {
133
- $errors = $this->get_errors();
 
 
 
 
 
 
 
 
 
 
134
 
135
- return array_key_exists( $key, $errors ) ? $errors[ $key ] : false;
136
- }
 
 
 
137
 
138
- function get_transient_lifetime() {
139
 
140
- $values = array( 'minutes' => MINUTE_IN_SECONDS, 'hours' => HOUR_IN_SECONDS, 'days' => DAY_IN_SECONDS );
141
- $keys = array_keys( $values );
142
- $type = in_array( $this->transient_lifetime_type, $keys ) ? $values[ $this->transient_lifetime_type ] : $values['minutes'];
143
 
144
- return $type * $this->transient_lifetime_value;
145
- }
 
 
146
 
147
- function get_user_info_without_token( $user ) {
148
 
149
- $response = $this->get_response_without_token( $user );
 
150
 
151
- if ( is_wp_error( $response ) ) {
152
- $error_data = $this->get_error('user-info-without-token');
153
- $this->errors->add($error_data['code'], $error_data['message']);
154
- return new WP_Error( $error_data['code'], $error_data['message'] );
155
- }
156
 
157
- if (isset($response->entry_data->ProfilePage[0]->graphql->user)) {
158
- $user_info = $response->entry_data->ProfilePage[0]->graphql->user;
159
- } elseif (isset($response->graphql->user)) {
160
- $user_info = $response->graphql->user;
161
- } else {
162
- $error_data = $this->get_error('user-info-without-token');
163
- $this->errors->add($error_data['code'], $error_data['message']);
164
- return new WP_Error( $error_data['code'], $error_data['message'] );
165
- }
166
 
167
- $converted = new stdClass;
 
 
 
 
 
 
168
 
169
- $converted->data = (object) array(
170
- 'bio' => ! empty( $user_info->biography ) ? $user_info->biography : '',
171
- 'counts' => (object) array(
172
- 'followed_by' => ! empty( $user_info->edge_followed_by->count ) ? $user_info->edge_followed_by->count : 0,
173
- 'follows' => ! empty( $user_info->edge_follow->count ) ? $user_info->edge_follow->count : 0,
174
- 'media' => ! empty( $user_info->edge_owner_to_timeline_media->count ) ? $user_info->edge_owner_to_timeline_media->count : 0,
175
- ),
176
- 'full_name' => ! empty( $user_info->full_name ) ? $user_info->full_name : '',
177
- 'id' => ! empty( $user_info->id ) ? $user_info->id : '',
178
- 'is_business' => ! empty( $user_info->is_business_account ) ? $user_info->is_business_account : '',
179
- 'profile_picture' => ! empty( $user_info->profile_pic_url ) ? $user_info->profile_pic_url : '',
180
- 'username' => ! empty( $user_info->username ) ? $user_info->username : '',
181
- 'website' => ! empty( $user_info->external_url ) ? $user_info->external_url : ''
182
- );
183
 
184
- return $converted;
 
185
 
186
- }
 
187
 
188
- function convert_user_info_to_old_structure( $user_info ) {
 
189
 
190
- $converted = new stdClass;
191
 
192
- $converted->data = (object) array(
193
- 'bio' => null,
194
- 'counts' => (object) array(
195
- 'followed_by' => null,
196
- 'follows' => null,
197
- 'media' => null,
198
- ),
199
- 'full_name' => ! empty( $user_info->username ) ? $user_info->username : '',
200
- 'id' => ! empty( $user_info->id ) ? $user_info->id : '',
201
- 'is_business' => null,
202
- 'profile_picture' => null,
203
- 'username' => ! empty( $user_info->username ) ? $user_info->username : '',
204
- 'website' => null
205
- );
206
-
207
- return $converted;
208
 
209
- }
210
 
211
- function get_response_without_token_from_json( $user ) {
212
 
213
- $user = trim( $user );
214
- $url = 'https://instagram.com/' . str_replace( '@', '', $user ).'/?__a=1';
215
 
216
- $request = wp_remote_get( $url, $this->headers );
 
 
217
 
218
- if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
219
- $error_data = $this->get_error('response-data-without-token-from-json-invalid-response');
220
- $this->errors->add($error_data['code'], $error_data['message']);
221
- return new WP_Error($error_data['code'], $error_data['message']);
222
- }
223
 
224
- $result = json_decode( wp_remote_retrieve_body( $request ) );
 
225
 
226
- if ( empty( $result ) ) {
227
- $error_data = $this->get_error('response-data-without-token-from-json-invalid-json-format');
228
- $this->errors->add($error_data['code'], $error_data['message']);
229
- return new WP_Error($error_data['code'], $error_data['message']);
230
- }
231
 
232
- return $result;
233
- }
234
 
 
235
 
236
- function get_response_without_token( $user ) {
 
237
 
238
- $user = trim( $user );
239
- $url = 'https://instagram.com/' . str_replace( '@', '', $user );
240
 
241
- $request = wp_remote_get( $url, $this->headers );
 
 
242
 
243
- if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) {
 
 
244
 
245
- $error_data = $this->get_error('response-data-without-token-from-html-invalid-response');
246
- $this->errors->add($error_data['code'], $error_data['message']);
 
247
 
248
- $result = $this->get_response_without_token_from_json($user);
249
 
250
- if (is_wp_error($result)) {
251
- return new WP_Error('invalid_response', __('Invalid response from Instagram', 'wpzoom-instagram-widget'));
252
- } else {
253
- return $result;
254
- }
255
- }
256
 
257
- $body = wp_remote_retrieve_body( $request );
 
 
 
 
 
 
 
 
 
 
258
 
259
- $doc = new DOMDocument();
 
 
 
260
 
261
- @$doc->loadHTML( $body );
 
262
 
263
- $script_tags = $doc->getElementsByTagName( 'script' );
 
 
 
 
 
 
 
 
 
 
 
264
 
265
- $json = '';
266
 
267
- foreach ( $script_tags as $script_tag ) {
268
- if ( strpos( $script_tag->nodeValue, 'window._sharedData = ' ) !== false ) {
269
- $json = $script_tag->nodeValue;
270
- break;
271
- }
272
- }
273
 
274
- $json = str_replace( array( 'window._sharedData = ', '};' ), array( '', '}' ), $json );
275
- $result = json_decode( $json );
 
 
 
 
276
 
277
- if ( empty( $result ) ) {
 
278
 
279
- $error_data = $this->get_error('response-data-without-token-from-html-invalid-json-format');
280
- $this->errors->add($error_data['code'], $error_data['message']);
 
 
 
 
 
 
 
281
 
282
- $result = $this->get_response_without_token_from_json($user);
 
283
 
284
- if(is_wp_error($result)){
285
- return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
286
- }
287
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
289
- return $result;
290
- }
291
 
292
  function convert_items_to_old_structure( $data ) {
293
- $converted = new stdClass;
294
  $converted->data = array();
295
 
296
  foreach ( $data->data as $key => $item ) {
297
 
298
  $converted->data[] = (object) array(
299
  'id' => $item->id,
 
300
  'user' => (object) array(
301
  'id' => null,
302
  'fullname' => null,
303
  'profile_picture' => null,
304
- 'username' => $item->username
305
  ),
306
  'images' => (object) array(
307
  'thumbnail' => (object) array(
308
- 'url' => $this->convert_to_embed_url( 'thumbnail', $item->permalink ),
309
  'width' => 150,
310
- 'height' => 150
311
  ),
312
  'low_resolution' => (object) array(
313
- 'url' => $this->convert_to_embed_url( 'low_resolution', $item->permalink ),
314
  'width' => 320,
315
- 'height' => 320
316
  ),
317
  'standard_resolution' => (object) array(
318
- 'url' => $this->convert_to_embed_url( 'standard_resolution', $item->permalink ),
319
  'width' => 640,
320
- 'height' => 640
321
  ),
322
  ),
323
- 'type' => ($item->media_type === 'IMAGE' || $item->media_type === 'CAROUSEL_ALBUM') ? 'image' : 'video',
324
  'likes' => null,
325
  'comments' => null,
326
  'created_time' => null,
327
  'link' => $item->permalink,
328
  'caption' => (object) array(
329
- 'text' => isset( $item->caption ) ? $item->caption : ''
330
- )
331
  );
332
 
333
  }
@@ -335,443 +352,395 @@ class Wpzoom_Instagram_Widget_API {
335
  return $converted;
336
  }
337
 
338
- function get_items_without_token( $user ) {
339
-
340
- $result = $this->get_response_without_token( $user );
341
-
342
- if (is_wp_error($result)) {
343
- $error_data = $this->get_error('items-without-token-invalid-response');
344
- $this->errors->add($error_data['code'], $error_data['message']);
345
- return new WP_Error($error_data['code'], $error_data['message']);
346
- }
347
-
348
- if (isset($result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges)) {
349
- $edges = $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges;
350
- } elseif (isset($result->graphql->user->edge_owner_to_timeline_media->edges)) {
351
- $edges = $result->graphql->user->edge_owner_to_timeline_media->edges;
352
- } else {
353
- $error_data = $this->get_error('items-without-token-invalid-json-structure');
354
- $this->errors->add($error_data['code'], $error_data['message']);
355
- return new WP_Error($error_data['code'], $error_data['message']);
356
- }
357
-
358
- $converted = new stdClass;
359
- $converted->data = array();
360
- foreach ( $edges as $edge ) {
361
-
362
- $node = $edge->node;
363
-
364
- $converted->data[] = (object) array(
365
- 'user' => (object) array(
366
- 'id' => $node->owner->id,
367
- 'fullname' => '',
368
- 'profile_picture' => '',
369
- 'username' => $node->owner->username
370
- ),
371
- 'images' => (object) array(
372
- 'thumbnail' => (object) array(
373
- 'url' => $node->thumbnail_resources[0]->src,
374
- 'width' => $node->thumbnail_resources[0]->config_width,
375
- 'height' => $node->thumbnail_resources[0]->config_height
376
- ),
377
- 'low_resolution' => (object) array(
378
- 'url' => $node->thumbnail_resources[2]->src,
379
- 'width' => $node->thumbnail_resources[2]->config_width,
380
- 'height' => $node->thumbnail_resources[2]->config_height
381
- ),
382
- 'standard_resolution' => (object) array(
383
- 'url' => $node->thumbnail_resources[4]->src,
384
- 'width' => $node->thumbnail_resources[4]->config_width,
385
- 'height' => $node->thumbnail_resources[4]->config_height
386
- ),
387
- ),
388
- 'type' => empty($node->is_video) ? 'image': 'video',
389
- 'likes' => isset( $node->edge_liked_by ) ? $node->edge_liked_by : 0,
390
- 'comments' => isset( $node->edge_media_to_comment ) ? $node->edge_media_to_comment : 0,
391
- 'created_time' => $node->taken_at_timestamp,
392
- 'link' => sprintf( 'https://www.instagram.com/p/%s/', $node->shortcode ),
393
- 'caption' => (object) array(
394
- 'text' => isset( $node->edge_media_to_caption->edges[0]->node->text ) ? $node->edge_media_to_caption->edges[0]->node->text : ''
395
- )
396
- );
397
- }
398
-
399
- return $converted;
400
- }
401
-
402
- /**
403
- * @param $screen_name string Instagram username
404
- * @param $image_limit int Number of images to retrieve
405
- * @param $image_width int Desired image width to retrieve
406
- *
407
- * @return array|bool Array of tweets or false if method fails
408
- */
409
- public function get_items( $instance ) {
410
-
411
- $sliced = wp_array_slice_assoc( $instance, array(
412
- 'image-limit',
413
- 'image-width',
414
- 'image-resolution',
415
- 'username',
416
- 'disable-video-thumbs'
417
- ) );
418
-
419
- $image_limit = $sliced['image-limit'];
420
- $image_width = $sliced['image-width'];
421
- $image_resolution = ! empty( $sliced['image-resolution'] ) ? $sliced['image-resolution'] : 'default_algorithm';
422
- $injected_username = ! empty( $sliced['username'] ) ? $sliced['username'] : '';
423
- $disable_video_thumbs = ! empty( $sliced['disable-video-thumbs'] );
424
-
425
- $transient = 'zoom_instagram_is_configured';
426
-
427
- $injected_username = trim( $injected_username );
428
-
429
- if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
430
- $injected_username = str_replace( '@', '', $injected_username );
431
- $transient = $transient . '_' . $injected_username;
432
- }
433
-
434
- if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
435
-
436
- return $this->processing_response_data( $data, $image_width, $image_resolution, $image_limit, $disable_video_thumbs );
437
- }
438
-
439
- $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
440
- $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
441
-
442
-
443
- if ( ! empty( $this->access_token ) ) {
444
 
445
- $request_url = sprintf( 'https://api.instagram.com/v1/users/self/media/recent/?access_token=%s&count=%s', $this->access_token, 30 );
446
 
447
- if ( 'with-basic-access-token' === $this->request_type ) {
448
- $request_url = add_query_arg( [
449
- 'fields' => 'media_url,media_type,caption,username,permalink,thumbnail_url',
450
- 'access_token' => $this->access_token
451
- ],
452
- 'https://graph.instagram.com/me/media' );
453
- }
454
 
455
- $response = wp_remote_get( $request_url, $this->headers );
 
 
 
 
 
 
 
 
 
 
 
 
456
 
457
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
458
- set_transient( $transient, false, MINUTE_IN_SECONDS );
 
459
 
460
- $error_data = $this->get_error( 'items-with-token-invalid-response' );
461
- $this->errors->add( $error_data['code'], $error_data['message'] );
462
 
463
- return false;
464
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
 
466
- $data = json_decode( wp_remote_retrieve_body( $response ) );
 
467
 
468
- if ( 'with-basic-access-token' === $this->request_type ) {
469
- $data = $this->convert_items_to_old_structure( $data );
470
- }
471
- }
472
 
473
- if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
 
474
 
 
475
 
476
- $data = $this->get_items_without_token( $external_username );
477
 
478
- if ( is_wp_error( $data ) ) {
479
- set_transient( $transient, false, MINUTE_IN_SECONDS );
480
 
481
- return false;
482
- }
483
 
484
- }
 
 
 
 
 
485
 
486
- if ( ! empty( $data->data ) ) {
487
- set_transient( $transient, $data, $this->get_transient_lifetime() );
488
- } else {
489
- set_transient( $transient, false, MINUTE_IN_SECONDS );
490
 
491
- $error_data = $this->get_error('items-with-token-invalid-data-structure');
492
- $this->errors->add($error_data['code'], $error_data['message']);
493
 
494
- return false;
495
- }
496
 
497
- return $this->processing_response_data( $data, $image_width, $image_resolution, $image_limit, $disable_video_thumbs );
498
- }
499
 
500
- public function processing_response_data( $data, $image_width, $image_resolution = 'default_algorithm', $image_limit, $disable_video_thumbs = false ) {
501
 
502
- $result = array();
503
- $username = '';
 
 
 
 
504
 
505
- foreach ( $data->data as $key => $item ) {
 
506
 
507
- if ( empty( $username ) ) {
508
- $username = $item->user->username;
509
- }
510
 
511
- if ( $key === $image_limit ) {
512
- break;
513
- }
514
 
515
- if ( ! empty( $disable_video_thumbs ) && isset( $item->type ) && 'video' == $item->type ) {
516
- $image_limit++;
517
- continue;
518
 
519
- }
 
 
 
520
 
521
- $best_size = $this->get_best_size( $image_width, $image_resolution );
522
- $image_url = $this->is_embed_stream ? $this->convert_to_embed_url( $best_size, $item->link ) : $item->images->{$best_size}->url;
523
 
524
- $result[] = array(
525
- 'link' => $item->link,
526
- 'image-url' => $image_url,
527
- 'image-caption' => ! empty( $item->caption->text ) ? esc_attr( $item->caption->text ) : '',
528
- 'likes_count' => ! empty( $item->likes->count ) ? esc_attr( $item->likes->count ) : 0,
529
- 'comments_count' => ! empty( $item->comments->count ) ? esc_attr( $item->comments->count ) : 0
530
- );
531
- }
532
 
533
- $result = array( 'items' => $result, 'username' => $username );
 
534
 
535
- return $result;
536
- }
537
 
538
- public function get_user_info( $injected_username = '' ) {
 
 
539
 
 
 
540
 
541
- $transient = 'zoom_instagram_user_info';
542
 
543
- $injected_username = rtrim( $injected_username );
 
 
544
 
545
- if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
546
- $injected_username = str_replace( '@', '', $injected_username );
547
- $transient = $transient . '_' . $injected_username;
548
- }
549
 
550
- if ( false !== ( $data = get_transient( $transient ) ) && is_object( $data ) && ! empty( $data->data ) ) {
 
551
 
552
- return $data;
553
- }
 
 
 
 
554
 
555
- $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
556
- $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
557
 
558
- if ( ! empty( $this->access_token ) ) {
559
 
560
- $request_url = sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $this->access_token );
 
 
 
 
 
 
561
 
562
- if ( 'with-basic-access-token' === $this->request_type ) {
563
- $request_url = add_query_arg( [
564
- 'access_token' => $this->access_token,
565
- 'fields' => 'account_type,id,media_count,username'
566
- ],
567
- 'https://graph.instagram.com/me' );
568
- }
569
 
570
- $response = wp_remote_get( $request_url, $this->headers );
571
 
572
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
573
- set_transient( $transient, false, MINUTE_IN_SECONDS );
574
 
575
- $error_data = $this->get_error( 'user-with-token-invalid-response' );
576
- $this->errors->add( $error_data['code'], $error_data['message'] );
577
 
578
- return false;
579
- }
 
 
580
 
581
- $data = json_decode( wp_remote_retrieve_body( $response ) );
582
 
583
- if ( 'with-basic-access-token' === $this->request_type ) {
584
- $data = $this->convert_user_info_to_old_structure( $data );
585
- }
586
 
587
- }
 
588
 
589
- if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
590
 
591
- $data = $this->get_user_info_without_token( $external_username );
 
 
 
 
 
 
592
 
593
- if ( is_wp_error( $data ) ) {
594
- set_transient( $transient, false, MINUTE_IN_SECONDS );
595
 
596
- return false;
597
- }
598
 
599
- }
 
600
 
601
- if ( ! empty( $data->data ) ) {
602
- set_transient( $transient, $data, $this->get_transient_lifetime() );
603
- } else {
604
- set_transient( $transient, false, MINUTE_IN_SECONDS );
605
 
606
- $error_data = $this->get_error('user-with-token-invalid-data-structure');
607
- $this->errors->add($error_data['code'], $error_data['message']);
608
 
609
- return false;
610
- }
611
 
612
- return $data;
613
 
614
- }
615
 
616
- /**
617
- * @param $screen_name string Instagram username
618
- *
619
- * @return bool|int Instagram user id or false on error
620
- */
621
- protected function get_user_id( $screen_name ) {
622
- $user_id_option = 'zoom_instagram_uid_' . $screen_name;
623
 
624
- if ( false !== ( $user_id = get_option( $user_id_option ) ) ) {
625
- return $user_id;
626
- }
627
 
628
- $response = wp_remote_get( sprintf( 'https://api.instagram.com/v1/users/search?q=%s&access_token=%s', $screen_name, $this->access_token ), $this->headers );
 
 
 
629
 
630
- if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
631
- return false;
632
- }
633
 
634
- $result = json_decode( wp_remote_retrieve_body( $response ) );
 
635
 
636
- if ( ! isset( $result->data ) ) {
637
- return false;
638
- }
639
 
640
- $user_id = false;
641
 
642
- foreach ( $result->data as $user ) {
643
- if ( $user->username === $screen_name ) {
644
- $user_id = $user->id;
645
 
646
- break;
647
- }
648
- }
649
 
650
- update_option( $user_id_option, $user_id );
651
 
652
- return $user_id;
653
- }
654
 
655
- /**
656
- * @param $desired_width int Desired image width in pixels
657
- *
658
- * @return string Image size for Instagram API
659
- */
660
- protected function get_best_size( $desired_width, $image_resolution = 'default_algorithm' ) {
661
- $size = 'thumbnail';
662
- $sizes = array(
663
- 'thumbnail' => 150,
664
- 'low_resolution' => 306,
665
- 'standard_resolution' => 640
666
- );
667
 
668
- $diff = PHP_INT_MAX;
669
 
670
- if ( array_key_exists( $image_resolution, $sizes ) ) {
671
- return $image_resolution;
672
- }
673
 
674
- foreach ( $sizes as $key => $value ) {
675
- if ( abs( $desired_width - $value ) < $diff ) {
676
- $size = $key;
677
- $diff = abs( $desired_width - $value );
678
- }
679
- }
 
 
 
 
 
 
 
 
680
 
681
- return $size;
682
- }
683
 
684
- protected function convert_to_embed_url( $size, $link ) {
685
- $sizes = array(
686
- 'thumbnail' => 't',
687
- 'low_resolution' => 'm',
688
- 'standard_resolution' => 'l'
689
- );
690
 
691
- $shortcode = trim( basename( $link ) );
692
- $embed_url = sprintf( 'https://instagram.com/p/%1$s/media/?size=%2$s', $shortcode, $sizes[ $size ] );
693
 
694
- return $embed_url;
695
- }
696
 
697
- /**
698
- * Check if given access token is valid for Instagram Api.
699
- */
700
- public static function is_access_token_valid( $access_token, $request_type = '' ) {
701
 
702
- $request_url = sprintf( 'https://api.instagram.com/v1/users/self/?access_token=%s', $access_token );
 
 
703
 
704
- if ( empty( $access_token ) ) {
705
- return false;
706
  }
707
 
708
- if ( 'with-basic-access-token' === $request_type ) {
709
- $request_url = add_query_arg( [
710
- 'fields' => 'username',
711
- 'access_token' => $access_token
 
 
 
712
 
713
- ], 'https://graph.instagram.com/me' );
714
  }
715
 
716
- $response = wp_remote_get( $request_url );
717
 
718
- if ( is_wp_error( $response ) ) {
719
- return $response;
720
- }
 
 
 
 
 
 
 
 
 
 
 
721
 
722
- if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
723
- return false;
724
- }
725
 
726
- return true;
727
  }
728
 
729
  public function is_configured() {
730
- $transient = 'zoom_instagram_is_configured';
 
 
 
 
 
 
 
 
 
731
 
732
- if ( false !== ( $result = get_transient( $transient ) ) ) {
733
- if ( 'yes' === $result ) {
734
- return true;
735
- }
736
 
737
- if ( 'no' === $result ) {
738
- return false;
739
- }
740
 
741
- if ( ! empty( $result ) ) {
742
- return true;
743
- }
744
- }
745
 
746
- if(empty($this->username)){
747
- $condition = $this->is_access_token_valid( $this->access_token, $this->request_type );
748
 
749
- } else{
750
- $condition = true;
751
- }
752
 
 
753
 
754
- if ( true === $condition ) {
755
- set_transient( $transient, 'yes', DAY_IN_SECONDS );
756
 
757
- return true;
758
- }
 
 
759
 
760
- set_transient( $transient, 'no', DAY_IN_SECONDS );
 
 
761
 
762
- return false;
763
- }
 
 
764
 
765
- public static function reset_cache() {
766
- delete_transient( 'zoom_instagram_is_configured' );
767
- delete_transient( 'zoom_instagram_user_info' );
768
- }
 
 
 
 
 
769
 
770
- public function get_access_token() {
771
- return $this->access_token;
772
- }
773
 
774
- public function set_access_token( $access_token ) {
775
- $this->access_token = $access_token;
776
- }
777
- }
1
  <?php
2
+ /**
3
+ * Exit if accessed directly.
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
  class Wpzoom_Instagram_Widget_API {
10
+ /**
11
+ * @var Wpzoom_Instagram_Widget_API The reference to *Singleton* instance of this class
12
+ */
13
+ private static $instance;
14
+ /**
15
+ * Request headers.
16
+ *
17
+ * @var array
18
+ */
19
+ public $headers = array();
 
 
 
 
 
 
 
 
 
20
  /**
21
  * Errors collector.
22
  *
23
  * @var array|WP_Error
24
  */
25
+ public $errors = array();
26
+ /**
27
+ * Instagram Access Token
28
+ *
29
+ * @var string
30
+ */
31
+ protected $access_token;
 
 
 
 
 
 
 
 
 
 
 
32
 
33
+ protected function __construct() {
34
+ $options = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
35
 
36
+ $this->request_type = ! empty( $options['request-type'] ) ? $options['request-type'] : '';
37
+ $this->access_token = ! empty( $options['basic-access-token'] ) ? $options['basic-access-token'] : '';
 
38
 
39
+ $this->username = ! empty( $options['username'] ) ? $options['username'] : '';
40
+ $this->transient_lifetime_type = ! empty( $options['transient-lifetime-type'] ) ? $options['transient-lifetime-type'] : 'days';
41
+ $this->transient_lifetime_value = ! empty( $options['transient-lifetime-value'] ) ? $options['transient-lifetime-value'] : 1;
42
+ $this->is_forced_timeout = ! empty( $options['is-forced-timeout'] ) ? wp_validate_boolean( $options['is-forced-timeout'] ) : false;
43
+ $this->request_timeout_value = ! empty( $options['request-timeout-value'] ) ? $options['request-timeout-value'] : 15;
44
 
45
+ if ( $this->is_forced_timeout && ! empty( $this->request_timeout_value ) ) {
46
+ $this->headers['timeout'] = $this->request_timeout_value;
47
+ }
 
 
 
48
 
49
+ $this->image_uploader = WPZOOM_Instagram_Image_Uploader::getInstance();
 
 
50
 
51
+ $this->errors = new WP_Error();
52
 
53
+ }
54
 
55
  /**
56
+ * Returns the *Singleton* instance of this class.
57
  *
58
+ * @return Wpzoom_Instagram_Widget_API The *Singleton* instance.
59
  */
60
+ public static function getInstance() {
61
+ if ( null === self::$instance ) {
62
+ self::$instance = new self();
63
+ }
64
+
65
+ return self::$instance;
66
+ }
67
+
68
+ public static function reset_cache() {
69
+ delete_transient( 'zoom_instagram_is_configured' );
70
+ delete_transient( 'zoom_instagram_user_info' );
71
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  /**
74
+ * @param $screen_name string Instagram username
75
+ * @param $image_limit int Number of images to retrieve
76
+ * @param $image_width int Desired image width to retrieve
77
  *
78
+ * @return array|bool Array of tweets or false if method fails
79
  */
80
+ public function get_items( $instance ) {
81
+
82
+ $sliced = wp_array_slice_assoc(
83
+ $instance,
84
+ array(
85
+ 'image-limit',
86
+ 'image-width',
87
+ 'image-resolution',
88
+ 'username',
89
+ 'disable-video-thumbs',
90
+ )
91
+ );
92
 
93
+ $image_limit = $sliced['image-limit'];
94
+ $image_width = $sliced['image-width'];
95
+ $image_resolution = ! empty( $sliced['image-resolution'] ) ? $sliced['image-resolution'] : 'default_algorithm';
96
+ $injected_username = ! empty( $sliced['username'] ) ? $sliced['username'] : '';
97
+ $disable_video_thumbs = ! empty( $sliced['disable-video-thumbs'] );
98
 
99
+ $transient = 'zoom_instagram_is_configured';
100
 
101
+ $injected_username = trim( $injected_username );
 
 
102
 
103
+ if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
104
+ $injected_username = str_replace( '@', '', $injected_username );
105
+ $transient = $transient . '_' . $injected_username;
106
+ }
107
 
108
+ if ( false !== ( $data = json_decode( get_transient( $transient ) ) ) && is_object( $data ) && ! empty( $data->data ) ) {
109
 
110
+ return $this->processing_response_data( $data, $image_width, $image_resolution, $image_limit, $disable_video_thumbs );
111
+ }
112
 
113
+ $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
114
+ $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
 
 
 
115
 
116
+ if ( ! empty( $this->access_token ) ) {
 
 
 
 
 
 
 
 
117
 
118
+ $request_url = add_query_arg(
119
+ array(
120
+ 'fields' => 'media_url,media_type,caption,username,permalink,thumbnail_url',
121
+ 'access_token' => $this->access_token,
122
+ ),
123
+ 'https://graph.instagram.com/me/media'
124
+ );
125
 
126
+ $response = wp_remote_get( $request_url, $this->headers );
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
129
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
130
 
131
+ $error_data = $this->get_error( 'items-with-token-invalid-response' );
132
+ $this->errors->add( $error_data['code'], $error_data['message'] );
133
 
134
+ return false;
135
+ }
136
 
137
+ $data = json_decode( wp_remote_retrieve_body( $response ) );
138
 
139
+ $data = $this->convert_items_to_old_structure( $data );
140
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
+ if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
143
 
144
+ $data = $this->get_items_without_token( $external_username );
145
 
146
+ if ( is_wp_error( $data ) ) {
147
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
148
 
149
+ return false;
150
+ }
151
+ }
152
 
153
+ if ( ! empty( $data->data ) ) {
154
+ set_transient( $transient, wp_json_encode( $data ), $this->get_transient_lifetime() );
155
+ } else {
156
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
 
157
 
158
+ $error_data = $this->get_error( 'items-with-token-invalid-data-structure' );
159
+ $this->errors->add( $error_data['code'], $error_data['message'] );
160
 
161
+ return false;
162
+ }
 
 
 
163
 
164
+ return $this->processing_response_data( $data, $image_width, $image_resolution, $image_limit, $disable_video_thumbs );
165
+ }
166
 
167
+ public function processing_response_data( $data, $image_width, $image_resolution = 'default_algorithm', $image_limit, $disable_video_thumbs = false ) {
168
 
169
+ $result = array();
170
+ $username = '';
171
 
172
+ foreach ( $data->data as $key => $item ) {
 
173
 
174
+ if ( empty( $username ) ) {
175
+ $username = $item->user->username;
176
+ }
177
 
178
+ if ( $key === $image_limit ) {
179
+ break;
180
+ }
181
 
182
+ if ( ! empty( $disable_video_thumbs ) && isset( $item->type ) && 'VIDEO' == $item->type ) {
183
+ $image_limit ++;
184
+ continue;
185
 
186
+ }
187
 
188
+ $best_size = $this->get_best_size( $image_width, $image_resolution );
189
+ $image_url = $item->images->{$best_size}->url;
 
 
 
 
190
 
191
+ $result[] = array(
192
+ 'link' => $item->link,
193
+ 'image-url' => $image_url,
194
+ 'original-image-url' => $item->media_url,
195
+ 'type' => $item->type,
196
+ 'image-id' => ! empty( $item->id ) ? esc_attr( $item->id ) : '',
197
+ 'image-caption' => ! empty( $item->caption->text ) ? esc_attr( $item->caption->text ) : '',
198
+ 'likes_count' => ! empty( $item->likes->count ) ? esc_attr( $item->likes->count ) : 0,
199
+ 'comments_count' => ! empty( $item->comments->count ) ? esc_attr( $item->comments->count ) : 0,
200
+ );
201
+ }
202
 
203
+ $result = array(
204
+ 'items' => $result,
205
+ 'username' => $username,
206
+ );
207
 
208
+ return $result;
209
+ }
210
 
211
+ /**
212
+ * @param $desired_width int Desired image width in pixels
213
+ *
214
+ * @return string Image size for Instagram API
215
+ */
216
+ protected function get_best_size( $desired_width, $image_resolution = 'default_algorithm' ) {
217
+ $size = 'thumbnail';
218
+ $sizes = array(
219
+ 'thumbnail' => 150,
220
+ 'low_resolution' => 306,
221
+ 'standard_resolution' => 640,
222
+ );
223
 
224
+ $diff = PHP_INT_MAX;
225
 
226
+ if ( array_key_exists( $image_resolution, $sizes ) ) {
227
+ return $image_resolution;
228
+ }
 
 
 
229
 
230
+ foreach ( $sizes as $key => $value ) {
231
+ if ( abs( $desired_width - $value ) < $diff ) {
232
+ $size = $key;
233
+ $diff = abs( $desired_width - $value );
234
+ }
235
+ }
236
 
237
+ return $size;
238
+ }
239
 
240
+ /**
241
+ * Retrieve error message by key.
242
+ *
243
+ * @param $key
244
+ *
245
+ * @return bool|mixed
246
+ */
247
+ public function get_error( $key ) {
248
+ $errors = $this->get_errors();
249
 
250
+ return array_key_exists( $key, $errors ) ? $errors[ $key ] : false;
251
+ }
252
 
253
+ /**
254
+ * Get error messages collection.
255
+ *
256
+ * @return array
257
+ */
258
+ public function get_errors() {
259
+ return array(
260
+ 'user-info-without-token' => array(
261
+ 'code' => 'user-info-without-token',
262
+ 'message' => __( 'Empty json user info from Public Feed.', 'wpzoom-instagram-widget' ),
263
+ ),
264
+ 'response-data-without-token-from-json-invalid-response' => array(
265
+ 'code' => 'response-data-without-token-from-json-invalid-response',
266
+ 'message' => __( 'The request from the Public Feed failed. Invalid server response from Public JSON API url.', 'wpzoom-instagram-widget' ),
267
+ ),
268
+ 'response-data-without-token-from-json-invalid-json-format' => array(
269
+ 'code' => 'response-data-without-token-from-json-invalid-json-format',
270
+ 'message' => __( 'The request from the Public Feed failed. Invalid JSON format from Public JSON API url.', 'wpzoom-instagram-widget' ),
271
+ ),
272
+ 'response-data-without-token-from-html-invalid-response' => array(
273
+ 'code' => 'response-data-without-token-from-html-invalid-response',
274
+ 'message' => __( 'The request from the Public Feed failed. Check username.', 'wpzoom-instagram-widget' ),
275
+ ),
276
+ 'response-data-without-token-from-html-invalid-json-format' => array(
277
+ 'code' => 'response-data-without-token-from-html-invalid-json-format',
278
+ 'message' => __( 'The request from the Public Feed failed. Invalid JSON format from parsed html body.', 'wpzoom-instagram-widget' ),
279
+ ),
280
+ 'items-without-token-invalid-response' => array(
281
+ 'code' => 'items-without-token-invalid-response',
282
+ 'message' => __( 'Get items from the Public Feed failed. Invalid response.', 'wpzoom-instagram-widget' ),
283
+ ),
284
+ 'items-without-token-invalid-json-structure' => array(
285
+ 'code' => 'items-without-token-invalid-json-structure',
286
+ 'message' => __( 'Get items from the Public Feed failed. Malformed data structure.', 'wpzoom-instagram-widget' ),
287
+ ),
288
+ 'items-with-token-invalid-response' => array(
289
+ 'code' => 'items-with-token-invalid-response',
290
+ 'message' => __( 'Geting items from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget' ),
291
+ ),
292
+ 'items-with-token-invalid-data-structure' => array(
293
+ 'code' => 'items-with-token-invalid-data-structure',
294
+ 'message' => __( 'Get items from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget' ),
295
+ ),
296
+ 'user-with-token-invalid-response' => array(
297
+ 'code' => 'user-with-token-invalid-response',
298
+ 'message' => __( 'Get user data from the Instagram API Feed failed. Invalid response.', 'wpzoom-instagram-widget' ),
299
+ ),
300
+ 'user-with-token-invalid-data-structure' => array(
301
+ 'code' => 'user-with-token-invalid-data-structure',
302
+ 'message' => __( 'Get user data from the Instagram API Feed failed. Malformed data structure.', 'wpzoom-instagram-widget' ),
303
+ ),
304
 
305
+ );
306
+ }
307
 
308
  function convert_items_to_old_structure( $data ) {
309
+ $converted = new stdClass();
310
  $converted->data = array();
311
 
312
  foreach ( $data->data as $key => $item ) {
313
 
314
  $converted->data[] = (object) array(
315
  'id' => $item->id,
316
+ 'media_url' => ( 'VIDEO' === $item->media_type ) ? $item->thumbnail_url : $item->media_url,
317
  'user' => (object) array(
318
  'id' => null,
319
  'fullname' => null,
320
  'profile_picture' => null,
321
+ 'username' => $item->username,
322
  ),
323
  'images' => (object) array(
324
  'thumbnail' => (object) array(
325
+ 'url' => $this->image_uploader->get_image( 'thumbnail', $item->media_url, $item->id ),
326
  'width' => 150,
327
+ 'height' => 150,
328
  ),
329
  'low_resolution' => (object) array(
330
+ 'url' => $this->image_uploader->get_image( 'low_resolution', $item->media_url, $item->id ),
331
  'width' => 320,
332
+ 'height' => 320,
333
  ),
334
  'standard_resolution' => (object) array(
335
+ 'url' => $this->image_uploader->get_image( 'standard_resolution', $item->media_url, $item->id ),
336
  'width' => 640,
337
+ 'height' => 640,
338
  ),
339
  ),
340
+ 'type' => $item->media_type,
341
  'likes' => null,
342
  'comments' => null,
343
  'created_time' => null,
344
  'link' => $item->permalink,
345
  'caption' => (object) array(
346
+ 'text' => isset( $item->caption ) ? $item->caption : '',
347
+ ),
348
  );
349
 
350
  }
352
  return $converted;
353
  }
354
 
355
+ function get_items_without_token( $user ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
+ $result = $this->get_response_without_token( $user );
358
 
359
+ if ( is_wp_error( $result ) ) {
360
+ $error_data = $this->get_error( 'items-without-token-invalid-response' );
361
+ $this->errors->add( $error_data['code'], $error_data['message'] );
 
 
 
 
362
 
363
+ return new WP_Error( $error_data['code'], $error_data['message'] );
364
+ }
365
+
366
+ if ( isset( $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges ) ) {
367
+ $edges = $result->entry_data->ProfilePage[0]->graphql->user->edge_owner_to_timeline_media->edges;
368
+ } elseif ( isset( $result->graphql->user->edge_owner_to_timeline_media->edges ) ) {
369
+ $edges = $result->graphql->user->edge_owner_to_timeline_media->edges;
370
+ } else {
371
+ $error_data = $this->get_error( 'items-without-token-invalid-json-structure' );
372
+ $this->errors->add( $error_data['code'], $error_data['message'] );
373
+
374
+ return new WP_Error( $error_data['code'], $error_data['message'] );
375
+ }
376
 
377
+ $converted = new stdClass();
378
+ $converted->data = array();
379
+ foreach ( $edges as $edge ) {
380
 
381
+ $node = $edge->node;
 
382
 
383
+ $converted->data[] = (object) array(
384
+ 'user' => (object) array(
385
+ 'id' => $node->owner->id,
386
+ 'fullname' => '',
387
+ 'profile_picture' => '',
388
+ 'username' => $node->owner->username,
389
+ ),
390
+ 'images' => (object) array(
391
+ 'thumbnail' => (object) array(
392
+ 'url' => $node->thumbnail_resources[0]->src,
393
+ 'width' => $node->thumbnail_resources[0]->config_width,
394
+ 'height' => $node->thumbnail_resources[0]->config_height,
395
+ ),
396
+ 'low_resolution' => (object) array(
397
+ 'url' => $node->thumbnail_resources[2]->src,
398
+ 'width' => $node->thumbnail_resources[2]->config_width,
399
+ 'height' => $node->thumbnail_resources[2]->config_height,
400
+ ),
401
+ 'standard_resolution' => (object) array(
402
+ 'url' => $node->thumbnail_resources[4]->src,
403
+ 'width' => $node->thumbnail_resources[4]->config_width,
404
+ 'height' => $node->thumbnail_resources[4]->config_height,
405
+ ),
406
+ ),
407
+ 'type' => $this->get_media_type_without_token( $node->__typename ),
408
+ 'likes' => isset( $node->edge_liked_by ) ? $node->edge_liked_by : 0,
409
+ 'comments' => isset( $node->edge_media_to_comment ) ? $node->edge_media_to_comment : 0,
410
+ 'created_time' => $node->taken_at_timestamp,
411
+ 'link' => sprintf( 'https://www.instagram.com/p/%s/', $node->shortcode ),
412
+ 'caption' => (object) array(
413
+ 'text' => isset( $node->edge_media_to_caption->edges[0]->node->text ) ? $node->edge_media_to_caption->edges[0]->node->text : '',
414
+ ),
415
+ );
416
+ }
417
 
418
+ return $converted;
419
+ }
420
 
421
+ function get_response_without_token( $user ) {
 
 
 
422
 
423
+ $user = trim( $user );
424
+ $url = 'https://instagram.com/' . str_replace( '@', '', $user );
425
 
426
+ $request = wp_remote_get( $url, $this->headers );
427
 
428
+ if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
429
 
430
+ $error_data = $this->get_error( 'response-data-without-token-from-html-invalid-response' );
431
+ $this->errors->add( $error_data['code'], $error_data['message'] );
432
 
433
+ $result = $this->get_response_without_token_from_json( $user );
 
434
 
435
+ if ( is_wp_error( $result ) ) {
436
+ return new WP_Error( 'invalid_response', __( 'Invalid response from Instagram', 'wpzoom-instagram-widget' ) );
437
+ } else {
438
+ return $result;
439
+ }
440
+ }
441
 
442
+ $body = wp_remote_retrieve_body( $request );
 
 
 
443
 
444
+ $doc = new DOMDocument();
 
445
 
446
+ @$doc->loadHTML( $body );
 
447
 
448
+ $script_tags = $doc->getElementsByTagName( 'script' );
 
449
 
450
+ $json = '';
451
 
452
+ foreach ( $script_tags as $script_tag ) {
453
+ if ( strpos( $script_tag->nodeValue, 'window._sharedData = ' ) !== false ) {
454
+ $json = $script_tag->nodeValue;
455
+ break;
456
+ }
457
+ }
458
 
459
+ $json = str_replace( array( 'window._sharedData = ', '};' ), array( '', '}' ), $json );
460
+ $result = json_decode( $json );
461
 
462
+ if ( empty( $result ) ) {
 
 
463
 
464
+ $error_data = $this->get_error( 'response-data-without-token-from-html-invalid-json-format' );
465
+ $this->errors->add( $error_data['code'], $error_data['message'] );
 
466
 
467
+ $result = $this->get_response_without_token_from_json( $user );
 
 
468
 
469
+ if ( is_wp_error( $result ) ) {
470
+ return new WP_Error( 'empty-json', __( 'Empty json decoded data.', 'wpzoom-instagram-widget' ) );
471
+ }
472
+ }
473
 
474
+ return $result;
475
+ }
476
 
477
+ function get_response_without_token_from_json( $user ) {
 
 
 
 
 
 
 
478
 
479
+ $user = trim( $user );
480
+ $url = 'https://instagram.com/' . str_replace( '@', '', $user ) . '/?__a=1';
481
 
482
+ $request = wp_remote_get( $url, $this->headers );
 
483
 
484
+ if ( is_wp_error( $request ) || 200 != wp_remote_retrieve_response_code( $request ) ) {
485
+ $error_data = $this->get_error( 'response-data-without-token-from-json-invalid-response' );
486
+ $this->errors->add( $error_data['code'], $error_data['message'] );
487
 
488
+ return new WP_Error( $error_data['code'], $error_data['message'] );
489
+ }
490
 
491
+ $result = json_decode( wp_remote_retrieve_body( $request ) );
492
 
493
+ if ( empty( $result ) ) {
494
+ $error_data = $this->get_error( 'response-data-without-token-from-json-invalid-json-format' );
495
+ $this->errors->add( $error_data['code'], $error_data['message'] );
496
 
497
+ return new WP_Error( $error_data['code'], $error_data['message'] );
498
+ }
 
 
499
 
500
+ return $result;
501
+ }
502
 
503
+ function get_media_type_without_token( $media_type ) {
504
+ $media_types = array(
505
+ 'GraphImage' => 'IMAGE',
506
+ 'GraphSidecar' => 'CAROUSEL_ALBUM',
507
+ 'GraphVideo' => 'VIDEO',
508
+ );
509
 
510
+ return array_key_exists( $media_type, $media_types ) ? $media_types[ $media_type ] : array_shift( $media_types );
511
+ }
512
 
513
+ function get_transient_lifetime() {
514
 
515
+ $values = array(
516
+ 'minutes' => MINUTE_IN_SECONDS,
517
+ 'hours' => HOUR_IN_SECONDS,
518
+ 'days' => DAY_IN_SECONDS,
519
+ );
520
+ $keys = array_keys( $values );
521
+ $type = in_array( $this->transient_lifetime_type, $keys ) ? $values[ $this->transient_lifetime_type ] : $values['minutes'];
522
 
523
+ return $type * $this->transient_lifetime_value;
524
+ }
 
 
 
 
 
525
 
526
+ public function get_user_info( $injected_username = '' ) {
527
 
528
+ $transient = 'zoom_instagram_user_info';
 
529
 
530
+ $injected_username = rtrim( $injected_username );
 
531
 
532
+ if ( ! empty( $injected_username ) && 'without-access-token' === $this->request_type ) {
533
+ $injected_username = str_replace( '@', '', $injected_username );
534
+ $transient = $transient . '_' . $injected_username;
535
+ }
536
 
537
+ if ( false !== ( $data = json_decode( get_transient( $transient ) ) ) && is_object( $data ) && ! empty( $data->data ) ) {
538
 
539
+ return $data;
540
+ }
 
541
 
542
+ $is_external_username = ! empty( $this->username ) || ! empty( $injected_username );
543
+ $external_username = ! empty( $injected_username ) ? $injected_username : $this->username;
544
 
545
+ if ( ! empty( $this->access_token ) ) {
546
 
547
+ $request_url = add_query_arg(
548
+ array(
549
+ 'access_token' => $this->access_token,
550
+ 'fields' => 'account_type,id,media_count,username',
551
+ ),
552
+ 'https://graph.instagram.com/me'
553
+ );
554
 
555
+ $response = wp_remote_get( $request_url, $this->headers );
 
556
 
557
+ if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
558
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
559
 
560
+ $error_data = $this->get_error( 'user-with-token-invalid-response' );
561
+ $this->errors->add( $error_data['code'], $error_data['message'] );
562
 
563
+ return false;
564
+ }
 
 
565
 
566
+ $data = json_decode( wp_remote_retrieve_body( $response ) );
567
+ $data = $this->convert_user_info_to_old_structure( $data );
568
 
569
+ }
 
570
 
571
+ if ( 'without-access-token' === $this->request_type && ! empty( $is_external_username ) ) {
572
 
573
+ $data = $this->get_user_info_without_token( $external_username );
574
 
575
+ if ( is_wp_error( $data ) ) {
576
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
 
 
 
 
 
577
 
578
+ return false;
579
+ }
580
+ }
581
 
582
+ if ( ! empty( $data->data ) ) {
583
+ set_transient( $transient, wp_json_encode( $data ), $this->get_transient_lifetime() );
584
+ } else {
585
+ set_transient( $transient, wp_json_encode( false ), MINUTE_IN_SECONDS );
586
 
587
+ $error_data = $this->get_error( 'user-with-token-invalid-data-structure' );
588
+ $this->errors->add( $error_data['code'], $error_data['message'] );
 
589
 
590
+ return false;
591
+ }
592
 
593
+ return $data;
 
 
594
 
595
+ }
596
 
597
+ function convert_user_info_to_old_structure( $user_info ) {
 
 
598
 
599
+ $converted = new stdClass();
 
 
600
 
601
+ $user_info_from_settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
602
 
603
+ $avatar = null;
 
604
 
605
+ if ( ! empty( $user_info_from_settings['user-info-avatar'] ) ) {
606
+ $img_src = wp_get_attachment_image_src( $user_info_from_settings['user-info-avatar'] );
607
+ if ( ! empty( $img_src ) && is_array( $img_src ) ) {
608
+ $avatar = $img_src[0];
609
+ }
610
+ }
 
 
 
 
 
 
611
 
612
+ $fullname = ! empty( $user_info->username ) ? $user_info->username : null;
613
 
614
+ if ( ! empty( $user_info_from_settings['user-info-fullname'] ) ) {
615
+ $fullname = $user_info_from_settings['user-info-fullname'];
616
+ }
617
 
618
+ $converted->data = (object) array(
619
+ 'bio' => ! empty( $user_info_from_settings['user-info-biography'] ) ? $user_info_from_settings['user-info-biography'] : null,
620
+ 'counts' => (object) array(
621
+ 'followed_by' => null,
622
+ 'follows' => null,
623
+ 'media' => null,
624
+ ),
625
+ 'full_name' => $fullname,
626
+ 'id' => ! empty( $user_info->id ) ? $user_info->id : '',
627
+ 'is_business' => null,
628
+ 'profile_picture' => $avatar,
629
+ 'username' => ! empty( $user_info->username ) ? $user_info->username : '',
630
+ 'website' => null,
631
+ );
632
 
633
+ return $converted;
 
634
 
635
+ }
 
 
 
 
 
636
 
 
 
637
 
638
+ function get_user_info_without_token( $user ) {
 
639
 
640
+ $response = $this->get_response_without_token( $user );
 
 
 
641
 
642
+ if ( is_wp_error( $response ) ) {
643
+ $error_data = $this->get_error( 'user-info-without-token' );
644
+ $this->errors->add( $error_data['code'], $error_data['message'] );
645
 
646
+ return new WP_Error( $error_data['code'], $error_data['message'] );
 
647
  }
648
 
649
+ if ( isset( $response->entry_data->ProfilePage[0]->graphql->user ) ) {
650
+ $user_info = $response->entry_data->ProfilePage[0]->graphql->user;
651
+ } elseif ( isset( $response->graphql->user ) ) {
652
+ $user_info = $response->graphql->user;
653
+ } else {
654
+ $error_data = $this->get_error( 'user-info-without-token' );
655
+ $this->errors->add( $error_data['code'], $error_data['message'] );
656
 
657
+ return new WP_Error( $error_data['code'], $error_data['message'] );
658
  }
659
 
660
+ $converted = new stdClass();
661
 
662
+ $converted->data = (object) array(
663
+ 'bio' => ! empty( $user_info->biography ) ? $user_info->biography : '',
664
+ 'counts' => (object) array(
665
+ 'followed_by' => ! empty( $user_info->edge_followed_by->count ) ? $user_info->edge_followed_by->count : 0,
666
+ 'follows' => ! empty( $user_info->edge_follow->count ) ? $user_info->edge_follow->count : 0,
667
+ 'media' => ! empty( $user_info->edge_owner_to_timeline_media->count ) ? $user_info->edge_owner_to_timeline_media->count : 0,
668
+ ),
669
+ 'full_name' => ! empty( $user_info->full_name ) ? $user_info->full_name : '',
670
+ 'id' => ! empty( $user_info->id ) ? $user_info->id : '',
671
+ 'is_business' => ! empty( $user_info->is_business_account ) ? $user_info->is_business_account : '',
672
+ 'profile_picture' => ! empty( $user_info->profile_pic_url ) ? $user_info->profile_pic_url : '',
673
+ 'username' => ! empty( $user_info->username ) ? $user_info->username : '',
674
+ 'website' => ! empty( $user_info->external_url ) ? $user_info->external_url : '',
675
+ );
676
 
677
+ return $converted;
 
 
678
 
 
679
  }
680
 
681
  public function is_configured() {
682
+ $transient = 'zoom_instagram_is_configured';
683
+
684
+ if ( false !== ( $result = json_decode( get_transient( $transient ) ) ) ) {
685
+ if ( 'yes' === $result ) {
686
+ return true;
687
+ }
688
+
689
+ if ( 'no' === $result ) {
690
+ return false;
691
+ }
692
 
693
+ if ( ! empty( $result ) ) {
694
+ return true;
695
+ }
696
+ }
697
 
698
+ if ( empty( $this->username ) ) {
699
+ $condition = $this->is_access_token_valid( $this->access_token, $this->request_type );
 
700
 
701
+ } else {
702
+ $condition = true;
703
+ }
 
704
 
705
+ if ( true === $condition ) {
706
+ set_transient( $transient, wp_json_encode( 'yes' ), DAY_IN_SECONDS );
707
 
708
+ return true;
709
+ }
 
710
 
711
+ set_transient( $transient, wp_json_encode( 'no' ), DAY_IN_SECONDS );
712
 
713
+ return false;
714
+ }
715
 
716
+ /**
717
+ * Check if given access token is valid for Instagram Api.
718
+ */
719
+ public static function is_access_token_valid( $access_token, $request_type = '' ) {
720
 
721
+ if ( empty( $access_token ) ) {
722
+ return false;
723
+ }
724
 
725
+ $request_url = add_query_arg(
726
+ array(
727
+ 'fields' => 'username',
728
+ 'access_token' => $access_token,
729
 
730
+ ),
731
+ 'https://graph.instagram.com/me'
732
+ );
733
+
734
+ $response = wp_remote_get( $request_url );
735
+
736
+ if ( is_wp_error( $response ) ) {
737
+ return $response;
738
+ }
739
 
740
+ if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
741
+ return false;
742
+ }
743
 
744
+ return true;
745
+ }
746
+ }
 
class-wpzoom-instagram-widget-settings.php CHANGED
@@ -1,307 +1,273 @@
1
  <?php
 
 
 
 
 
 
2
 
3
  class Wpzoom_Instagram_Widget_Settings {
4
- public function __construct() {
5
- add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
6
- add_action( 'admin_init', array( $this, 'settings_init' ) );
7
-
8
- add_filter( 'plugin_action_links', array( $this, 'add_action_links' ), 10, 2 );
9
-
10
- add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ),9 );
11
- }
12
-
13
- function add_action_links( $links, $file ) {
14
- if ( $file != plugin_basename( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) ) {
15
- return $links;
16
- }
17
-
18
- $settings_link = sprintf(
19
- '<a href="%1$s">%2$s</a>',
20
- menu_page_url( 'wpzoom-instagram-widget', false ),
21
- esc_html__( 'Settings', 'wpzoom-instagram-widget' )
22
- );
23
-
24
- array_unshift( $links, $settings_link );
25
-
26
- return $links;
27
- }
28
-
29
- public function add_admin_menu() {
30
- add_options_page(
31
- 'Instagram Widget',
32
- 'Instagram Widget',
33
- 'manage_options',
34
- 'wpzoom-instagram-widget',
35
- array( $this, 'settings_page' )
36
- );
37
- }
38
-
39
- public function settings_init() {
40
- register_setting(
41
- 'wpzoom-instagram-widget-settings-group',
42
- 'wpzoom-instagram-widget-settings',
43
- array( $this, 'sanitize' )
44
- );
45
-
46
- add_settings_section(
47
- 'wpzoom-instagram-widget-settings-general',
48
- null,
49
- '__return_false',
50
- 'wpzoom-instagram-widget-settings-group'
51
- );
52
-
53
- add_settings_field(
54
- 'wpzoom-instagram-widget-request-type',
55
- __( 'Request Type', 'wpzoom-instagram-widget' ),
56
- array( $this, 'settings_field_request_type' ),
57
- 'wpzoom-instagram-widget-settings-group',
58
- 'wpzoom-instagram-widget-settings-general',
59
- array('class' => 'wpzoom-instagram-widget-with-token-group')
60
- );
61
-
62
-
63
- /**
64
- * Instagram with old token.
65
- */
66
- add_settings_field(
67
- 'wpzoom-instagram-widget-access-token-button',
68
- __( '', 'wpzoom-instagram-widget' ),
69
- array( $this, 'settings_field_access_token_button' ),
70
- 'wpzoom-instagram-widget-settings-group',
71
- 'wpzoom-instagram-widget-settings-general',
72
- array('class' => 'wpzoom-instagram-widget-with-access-token-group')
73
-
74
- );
75
-
76
- add_settings_field(
77
- 'wpzoom-instagram-widget-access-token-input',
78
- __( 'Access Token', 'wpzoom-instagram-widget' ),
79
- array( $this, 'settings_field_access_token_input' ),
80
- 'wpzoom-instagram-widget-settings-group',
81
- 'wpzoom-instagram-widget-settings-general',
82
- array('class' => 'wpzoom-instagram-widget-with-access-token-group')
83
-
84
- );
85
-
86
- /**
87
- * Instagram with basic api token.
88
- */
89
- add_settings_field(
90
- 'wpzoom-instagram-widget-basic-access-token-button',
91
- __( '', 'wpzoom-instagram-widget' ),
92
- array( $this, 'settings_field_basic_access_token_button' ),
93
- 'wpzoom-instagram-widget-settings-group',
94
- 'wpzoom-instagram-widget-settings-general',
95
- array('class' => 'wpzoom-instagram-widget-with-basic-access-token-group')
96
-
97
- );
98
-
99
- add_settings_field(
100
- 'wpzoom-instagram-widget-basic-access-token-input',
101
- __( 'Access Token', 'wpzoom-instagram-widget' ),
102
- array( $this, 'settings_field_basic_access_token_input' ),
103
- 'wpzoom-instagram-widget-settings-group',
104
- 'wpzoom-instagram-widget-settings-general',
105
- array('class' => 'wpzoom-instagram-widget-with-basic-access-token-group')
106
-
107
- );
108
-
109
- add_settings_field(
110
- 'wpzoom-instagram-widget-username-description',
111
- __( '', 'wpzoom-instagram-widget' ),
112
- array( $this, 'settings_field_username_description' ),
113
- 'wpzoom-instagram-widget-settings-group',
114
- 'wpzoom-instagram-widget-settings-general',
115
- array('class' => 'wpzoom-instagram-widget-without-access-token-group')
116
- );
117
-
118
- add_settings_field(
119
- 'wpzoom-instagram-widget-username',
120
- __( 'Username', 'wpzoom-instagram-widget' ),
121
- array( $this, 'settings_field_username' ),
122
- 'wpzoom-instagram-widget-settings-group',
123
- 'wpzoom-instagram-widget-settings-general',
124
- array('class' => 'wpzoom-instagram-widget-without-access-token-group')
125
-
126
- );
127
-
128
- add_settings_field(
129
- 'wpzoom-instagram-widget-transient-lifetime',
130
- __( 'Check for new Instagram posts every', 'wpzoom-instagram-widget' ),
131
- array( $this, 'settings_field_transient_lifetime' ),
132
- 'wpzoom-instagram-widget-settings-group',
133
- 'wpzoom-instagram-widget-settings-general'
134
- );
135
-
136
- add_settings_field(
137
- 'wpzoom-instagram-widget-is-embed-stream',
138
- __( 'Serve images from Instagram embed links', 'wpzoom-instagram-widget' ),
139
- array( $this, 'settings_field_is_embed_stream' ),
140
- 'wpzoom-instagram-widget-settings-group',
141
- 'wpzoom-instagram-widget-settings-general'
142
- );
143
-
144
- add_settings_field(
145
- 'wpzoom-instagram-widget-is-forced-timeout',
146
- __( 'Enable request timeout', 'wpzoom-instagram-widget' ),
147
- array( $this, 'settings_field_is_forced_timeout' ),
148
- 'wpzoom-instagram-widget-settings-group',
149
- 'wpzoom-instagram-widget-settings-general'
150
- );
151
-
152
- add_settings_field(
153
- 'wpzoom-instagram-widget-request-timeout',
154
- __( 'Request timeout in seconds.', 'wpzoom-instagram-widget' ),
155
- array( $this, 'settings_field_request_timeout' ),
156
- 'wpzoom-instagram-widget-settings-group',
157
- 'wpzoom-instagram-widget-settings-general',
158
- array('class' => 'wpzoom-instagram-widget-request-timeout')
159
- );
160
-
161
-
162
- }
163
-
164
- public function settings_field_access_token_button() {
165
- $oauth_url = 'https://instagram.com/oauth/authorize/?client_id=955bdb2319484968b93de8d6a1032c66&response_type=token&redirect_uri=https://www.wpzoom.com/instagram/';
166
- $oauth_url .= '?auth_site=' . esc_url( admin_url( 'options-general.php?page=wpzoom-instagram-widget' ) );
167
- $oauth_url.='&hl=en';
168
 
169
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
170
- ?>
171
 
172
- <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
 
173
 
174
- <br />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
- <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
177
- <?php if ( empty( $settings['access-token'] ) ) : ?>
178
- <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
179
- <?php else: ?>
180
- <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
181
- <?php endif; ?>
182
- </a>
183
- </p>
184
- <?php
185
  }
186
 
187
  public function settings_field_basic_access_token_button() {
188
 
189
  $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
190
 
191
- $oauth_url = add_query_arg( [
192
- 'client_id' => '1242932982579434',
193
- 'redirect_uri' => 'https://wpzoom.com/instagram-auth/',
194
- 'scope' => 'user_profile,user_media',
195
- 'response_type' => 'code',
196
- ], 'https://api.instagram.com/oauth/authorize' );
197
- $oauth_url.='&state='. base64_encode( urlencode(admin_url( 'options-general.php?page=wpzoom-instagram-widget' )) );
 
 
 
198
  ?>
199
 
200
- <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
 
201
 
202
- <br />
203
 
204
- <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
205
  <?php if ( empty( $settings['basic-access-token'] ) ) : ?>
206
- <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
207
- <?php else: ?>
208
- <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
209
  <?php endif; ?>
210
- </a>
211
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  <?php
213
  }
214
 
215
- public function settings_field_transient_lifetime() {
216
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
217
- $lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
218
- $lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
219
- ?>
220
- <input class="regular-text code"
221
- id="wpzoom-instagram-widget-settings_transient-lifetime-value"
222
- name="wpzoom-instagram-widget-settings[transient-lifetime-value]"
223
- value="<?php echo esc_attr( $lifetime_value ) ?>"
224
- type="number"
225
- min="1">
226
-
227
- <select class="regular-text code"
228
- id="wpzoom-instagram-widget-settings_transient-lifetime-type"
229
- name="wpzoom-instagram-widget-settings[transient-lifetime-type]">
230
- <option <?php selected( $lifetime_type, 'hours' ); ?> value="hours"><?php _e( 'Hours', 'wpzoom-instagram-widget' ) ?></option>
231
- <option <?php selected( $lifetime_type, 'days' ); ?> value="days"><?php _e( 'Days', 'wpzoom-instagram-widget' ) ?></option>
232
- <option <?php selected( $lifetime_type, 'minutes' ); ?> value="minutes"><?php _e( 'Minutes', 'wpzoom-instagram-widget' ) ?></option>
233
- </select>
234
- <?php
235
- }
236
-
237
- public function settings_field_is_embed_stream() {
238
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
239
- $is_embed_stream = ! empty( $settings['is-embed-stream'] ) ? wp_validate_boolean($settings['is-embed-stream']) : false;
240
- ?>
241
- <input class="regular-text code"
242
- id="wpzoom-instagram-widget-settings_is-embed-stream"
243
- name="wpzoom-instagram-widget-settings[is-embed-stream]"
244
- <?php checked(true , $is_embed_stream)?>
245
- value="1"
246
- type="checkbox">
247
-
248
- <?php
249
- }
250
-
251
- public function settings_field_is_forced_timeout() {
252
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
253
- $is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean($settings['is-forced-timeout']) : false;
254
- ?>
255
- <input class="regular-text code"
256
- id="wpzoom-instagram-widget-settings_is-forced-timeout"
257
- name="wpzoom-instagram-widget-settings[is-forced-timeout]"
258
- <?php checked(true , $is_forced_timeout)?>
259
- value="1"
260
- type="checkbox">
261
-
262
- <?php
263
- }
264
-
265
- public function settings_field_request_timeout() {
266
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
267
- $timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
268
- ?>
269
- <input class="regular-text code"
270
- id="wpzoom-instagram-widget-settings_request-timeout-value"
271
- name="wpzoom-instagram-widget-settings[request-timeout-value]"
272
- value="<?php echo esc_attr( $timeout_value ) ?>"
273
- type="number"
274
- min="1"
275
- max="30">
276
- <?php
277
- }
278
-
279
- public function settings_field_access_token_input() {
280
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
281
- $access_token = ! empty( $settings['access-token'] ) ? $settings['access-token'] : '';
282
-
283
- ?>
284
- <input class="regular-text code" id="wpzoom-instagram-widget-settings_access-token" name="wpzoom-instagram-widget-settings[access-token]" value="<?php echo esc_attr( $access_token ) ?>" type="text">
285
- <p class="description">
286
- <?php
287
- printf(
288
- __(
289
- 'The Instagram Access Token is a long string of characters unique to your account that grants other applications access to your Instagram feed. You can also get it manually from <a href="%1$s">here</a>.',
290
- 'wpzoom-instagram-widget'
291
- ),
292
- 'https://www.wpzoom.com/instagram/'
293
- );
294
- ?>
295
- </p>
296
- <?php
297
- }
298
 
299
  public function settings_field_basic_access_token_input() {
300
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
301
  $basic_access_token = ! empty( $settings['basic-access-token'] ) ? $settings['basic-access-token'] : '';
302
  ?>
303
- <input class="regular-text code" id="wpzoom-instagram-widget-settings_basic-access-token" name="wpzoom-instagram-widget-settings[basic-access-token]" value="<?php echo esc_attr( $basic_access_token ) ?>" type="text">
304
- <p class="description">
 
 
305
  <?php
306
  printf(
307
  __(
@@ -311,195 +277,226 @@ class Wpzoom_Instagram_Widget_Settings {
311
  'https://www.wpzoom.com/instagram-auth/'
312
  );
313
  ?>
314
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  <?php
316
  }
317
 
318
- public function settings_field_username_description() {
319
- ?>
320
- <p class="description"><?php _e( 'Using this method, a public feed, limited to <strong>12 photos</strong>, will be displayed in the widget.<br/>This option is useful if you want to display the feed of an Instagram account which you don\'t own or you have troubles getting your Access Token.', 'wpzoom-instagram-widget' ); ?></p>
321
-
322
- </p>
323
- <?php
324
- }
325
-
326
- public function settings_field_username() {
327
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
328
- ?>
329
- <input class="regular-text code" id="wpzoom-instagram-widget-settings_username" name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ) ?>" type="text">
330
- <p class="description">
331
- <?php
332
- printf(
333
- __(
334
- 'The username entered here will be used in the Instagram feed, unless a different username will be entered in the widget settings.',
335
- 'wpzoom-instagram-widget'
336
- )
337
- );
338
- ?>
339
- </p>
340
- <?php
341
- }
342
-
343
- public function settings_field_request_type() {
344
- $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
345
- $request_type = empty( $settings['request-type'] ) ? 'with-access-token' : $settings['request-type'];
346
- ?>
347
-
348
- <div class="wpzoom-instagram-widget-settings-request-type-wrapper">
349
-
350
- <div class="label-wrap">
351
- <input class="code"
352
- id="wpzoom-instagram-widget-settings_with-basic-access-token"
353
- name="wpzoom-instagram-widget-settings[request-type]"
354
- value="with-basic-access-token" <?php checked( $request_type, 'with-basic-access-token' ) ?>
355
- type="radio">
356
- <label for="wpzoom-instagram-widget-settings_with-basic-access-token">
357
- <?php _e( 'With Basic Instagram API Access Token (New)', 'wpzoom-instagram-widget' ) ?>
358
- </label>
359
- </div>
360
- <div class="label-wrap">
361
- <input class="code"
362
- id="wpzoom-instagram-widget-settings_without-access-token"
363
- name="wpzoom-instagram-widget-settings[request-type]"
364
- value="without-access-token"
365
- <?php checked( $request_type, 'without-access-token' ) ?>
366
- type="radio">
367
- <label for="wpzoom-instagram-widget-settings_without-access-token">
368
- <?php _e( 'Public Feed (12 photos)', 'wpzoom-instagram-widget' ) ?>
369
- </label>
370
- </div>
371
- <div class="label-wrap">
372
- <input class="code"
373
- id="wpzoom-instagram-widget-settings_with-access-token"
374
- name="wpzoom-instagram-widget-settings[request-type]"
375
- value="with-access-token" <?php checked( $request_type, 'with-access-token' ) ?>
376
- type="radio">
377
- <label for="wpzoom-instagram-widget-settings_with-access-token">
378
- <?php _e( 'With Instagram Legacy API Access Token (Retired)', 'wpzoom-instagram-widget' ) ?>
379
- &nbsp;</label>
380
- </div>
381
-
382
- </div>
383
-
384
- <?php
385
- }
386
-
387
- public function settings_page() {
388
- ?>
389
-
390
- <div class="wrap">
391
-
392
- <h1><?php _e( 'Instagram Widget by WPZOOM', 'wpzoom-instagram-widget' ); ?></h1>
393
-
394
- <div class="zoom-instagram-widget">
395
-
396
- <h2><?php _e( 'Connect your account', 'wpzoom-instagram-widget' ); ?></h2>
397
-
398
- <p><?php _e( 'To get started, select an option below. If you want to show your own feed, use the first option: <strong>With Access Token</strong>. If you want to show the feed of an Instagram account which you don\'t own, use the option <strong>Public Feed</strong>.', 'wpzoom-instagram-widget' ); ?></p>
399
-
400
- <form action="options.php" method="post">
401
-
402
- <?php
403
- settings_fields( 'wpzoom-instagram-widget-settings-group' );
404
- do_settings_sections( 'wpzoom-instagram-widget-settings-group' );
405
- submit_button();
406
- ?>
407
-
408
- </form>
409
-
410
- </div>
411
-
412
- <div class="zoom-themes-link">
413
-
414
- <h2><?php _e( 'Premium WordPress Themes by WPZOOM', 'wpzoom-instagram-widget' ); ?></h2>
415
-
416
- <p><?php _e( 'Are you looking to give your website a new look?<br/> Check out our collection of <strong>40 expertly-crafted themes</strong> and find the perfect one for your needs!', 'wpzoom-instagram-widget' ); ?></p>
417
-
418
- <p><?php printf( __( '<a class="cta-button" target="_blank" href="%1$s"">View our Themes &rarr;</a>' ), 'https://www.wpzoom.com/themes/' ); ?></p>
419
-
420
- </div>
421
-
422
- </div>
423
-
424
- <?php
425
- }
426
-
427
- public function scripts( $hook ) {
428
- if ( $hook != 'settings_page_wpzoom-instagram-widget' ) {
429
- return;
430
- }
431
-
432
- wp_enqueue_style( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/admin-instagram-widget.css', array(), '1.6.0' );
433
- wp_enqueue_script( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/admin-instagram-widget.js', array( 'jquery' ), '1.6.0' );
434
- wp_localize_script( 'zoom-instagram-widget-admin', 'zoom_instagram_widget_admin', array(
435
- 'i18n_connect_confirm' => __( "Instagram Widget is already connected to Instagram.\r\n\r\nDo you want to connect again?", 'wpzoom-instagram-widget' ),
436
- ) );
437
- }
438
-
439
- public function sanitize( $input ) {
440
- $result = array();
441
-
442
- $result['access-token'] = sanitize_text_field( $input['access-token'] );
443
- $result['basic-access-token'] = sanitize_text_field( $input['basic-access-token'] );
444
- $result['request-type'] = sanitize_text_field( $input['request-type'] );
445
-
446
- if ( ! empty( $result['access-token'] ) && !empty($result['request-type']) && 'with-access-token' === $result['request-type'] ) {
447
- $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['access-token'], $result['request-type']);
448
-
449
- if ( $validation_result !== true ) {
450
- $access_token_error_message = __( 'Provided Access Token has been rejected by Instagram Legacy API (Retired). Please try again or use the other option.', 'wpzoom-instagram-widget' );
451
-
452
- if ( is_wp_error( $validation_result ) ) {
453
- $access_token_error_message = $validation_result->get_error_message();
454
- }
455
-
456
- if ( $validation_result !== true ) {
457
- add_settings_error(
458
- 'wpzoom-instagram-widget-access-token',
459
- esc_attr( 'wpzoom-instagram-widget-access-token-invalid' ),
460
- $access_token_error_message,
461
- 'error'
462
- );
463
- }
464
 
465
- $result['access-token'] = '';
466
- }
467
- }
468
 
469
- if ( ! empty( $result['basic-access-token'] ) && !empty($result['request-type']) && 'with-basic-access-token' === $result['request-type'] ) {
470
- $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['basic-access-token'], $result['request-type'] );
 
 
 
471
 
472
- if ( $validation_result !== true ) {
473
- $access_token_error_message = __( 'Provided Access Token has been rejected by Basic Instagram API (new). Please try again or use the other option.', 'wpzoom-instagram-widget' );
474
 
475
- if ( is_wp_error( $validation_result ) ) {
476
- $access_token_error_message = $validation_result->get_error_message();
477
- }
478
 
479
- if ( $validation_result !== true ) {
480
- add_settings_error(
481
- 'wpzoom-instagram-widget-access-token',
482
- esc_attr( 'wpzoom-instagram-widget-access-token-invalid' ),
483
- $access_token_error_message,
484
- 'error'
485
- );
486
- }
487
 
488
- $result['basic-access-token'] = '';
489
- }
490
- }
491
 
492
- $result['username'] = sanitize_text_field( $input['username'] );
493
- $result['transient-lifetime-value'] = sanitize_text_field( $input['transient-lifetime-value'] );
494
- $result['transient-lifetime-type'] = sanitize_text_field( $input['transient-lifetime-type'] );
495
- $result['is-embed-stream']= ! empty( $input['is-embed-stream'] ) ? wp_validate_boolean($input['is-embed-stream']) : false;
496
- $result['is-forced-timeout']= ! empty( $input['is-forced-timeout'] ) ? wp_validate_boolean($input['is-forced-timeout']) : false;
497
- $result['request-timeout-value'] = sanitize_text_field( $input['request-timeout-value'] );
498
 
499
- Wpzoom_Instagram_Widget_API::reset_cache();
500
 
501
- return $result;
502
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  }
504
 
505
  new Wpzoom_Instagram_Widget_Settings();
1
  <?php
2
+ /**
3
+ * Exit if accessed directly.
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
  class Wpzoom_Instagram_Widget_Settings {
10
+ public function __construct() {
11
+ add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
12
+ add_action( 'admin_init', array( $this, 'settings_init' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ add_filter( 'plugin_action_links', array( $this, 'add_action_links' ), 10, 2 );
 
15
 
16
+ add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ), 9 );
17
+ }
18
 
19
+ function add_action_links( $links, $file ) {
20
+ if ( $file != plugin_basename( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) ) {
21
+ return $links;
22
+ }
23
+
24
+ $settings_link = sprintf(
25
+ '<a href="%1$s">%2$s</a>',
26
+ menu_page_url( 'wpzoom-instagram-widget', false ),
27
+ esc_html__( 'Settings', 'wpzoom-instagram-widget' )
28
+ );
29
+
30
+ array_unshift( $links, $settings_link );
31
+
32
+ return $links;
33
+ }
34
+
35
+ public function add_admin_menu() {
36
+ add_options_page(
37
+ 'Instagram Widget',
38
+ 'Instagram Widget',
39
+ 'manage_options',
40
+ 'wpzoom-instagram-widget',
41
+ array( $this, 'settings_page' )
42
+ );
43
+ }
44
+
45
+ public function settings_init() {
46
+ register_setting(
47
+ 'wpzoom-instagram-widget-settings-group',
48
+ 'wpzoom-instagram-widget-settings',
49
+ array( $this, 'sanitize' )
50
+ );
51
+
52
+ add_settings_section(
53
+ 'wpzoom-instagram-widget-settings-general',
54
+ null,
55
+ '__return_false',
56
+ 'wpzoom-instagram-widget-settings-group'
57
+ );
58
+
59
+ add_settings_section(
60
+ 'wpzoom-instagram-widget-settings-user-info',
61
+ __( 'User Details (optional)', 'wpzoom-instagram-widget' ),
62
+ array( $this, 'settings_field_user_details' ),
63
+ 'wpzoom-instagram-widget-settings-group'
64
+ );
65
+
66
+ add_settings_field(
67
+ 'wpzoom-instagram-widget-user-info-avatar',
68
+ __( 'Profile Picture', 'wpzoom-instagram-widget' ),
69
+ array( $this, 'settings_field_user_info_avatar' ),
70
+ 'wpzoom-instagram-widget-settings-group',
71
+ 'wpzoom-instagram-widget-settings-user-info'
72
+ );
73
+
74
+ add_settings_field(
75
+ 'wpzoom-instagram-widget-user-info-fullname',
76
+ __( 'Your Name', 'wpzoom-instagram-widget' ),
77
+ array( $this, 'settings_field_user_info_fullname' ),
78
+ 'wpzoom-instagram-widget-settings-group',
79
+ 'wpzoom-instagram-widget-settings-user-info'
80
+ );
81
+
82
+ add_settings_field(
83
+ 'wpzoom-instagram-widget-user-info-biography',
84
+ __( 'Bio', 'wpzoom-instagram-widget' ),
85
+ array( $this, 'settings_field_user_info_biography' ),
86
+ 'wpzoom-instagram-widget-settings-group',
87
+ 'wpzoom-instagram-widget-settings-user-info'
88
+ );
89
+
90
+ add_settings_field(
91
+ 'wpzoom-instagram-widget-request-type',
92
+ __( 'Request Type', 'wpzoom-instagram-widget' ),
93
+ array( $this, 'settings_field_request_type' ),
94
+ 'wpzoom-instagram-widget-settings-group',
95
+ 'wpzoom-instagram-widget-settings-general',
96
+ array( 'class' => 'wpzoom-instagram-widget-with-token-group' )
97
+ );
98
+
99
+ /**
100
+ * Instagram with basic api token.
101
+ */
102
+ add_settings_field(
103
+ 'wpzoom-instagram-widget-basic-access-token-button',
104
+ __( '', 'wpzoom-instagram-widget' ),
105
+ array( $this, 'settings_field_basic_access_token_button' ),
106
+ 'wpzoom-instagram-widget-settings-group',
107
+ 'wpzoom-instagram-widget-settings-general',
108
+ array( 'class' => 'wpzoom-instagram-widget-with-basic-access-token-group' )
109
+ );
110
+
111
+ add_settings_field(
112
+ 'wpzoom-instagram-widget-basic-access-token-input',
113
+ __( 'Access Token', 'wpzoom-instagram-widget' ),
114
+ array( $this, 'settings_field_basic_access_token_input' ),
115
+ 'wpzoom-instagram-widget-settings-group',
116
+ 'wpzoom-instagram-widget-settings-general',
117
+ array( 'class' => 'wpzoom-instagram-widget-with-basic-access-token-group' )
118
+ );
119
+
120
+ add_settings_field(
121
+ 'wpzoom-instagram-widget-username-description',
122
+ __( '', 'wpzoom-instagram-widget' ),
123
+ array( $this, 'settings_field_username_description' ),
124
+ 'wpzoom-instagram-widget-settings-group',
125
+ 'wpzoom-instagram-widget-settings-general',
126
+ array( 'class' => 'wpzoom-instagram-widget-without-access-token-group' )
127
+ );
128
+
129
+ add_settings_field(
130
+ 'wpzoom-instagram-widget-username',
131
+ __( 'Username', 'wpzoom-instagram-widget' ),
132
+ array( $this, 'settings_field_username' ),
133
+ 'wpzoom-instagram-widget-settings-group',
134
+ 'wpzoom-instagram-widget-settings-general',
135
+ array( 'class' => 'wpzoom-instagram-widget-without-access-token-group' )
136
+ );
137
+
138
+ add_settings_field(
139
+ 'wpzoom-instagram-widget-transient-lifetime',
140
+ __( 'Check for new posts every', 'wpzoom-instagram-widget' ),
141
+ array( $this, 'settings_field_transient_lifetime' ),
142
+ 'wpzoom-instagram-widget-settings-group',
143
+ 'wpzoom-instagram-widget-settings-general'
144
+ );
145
+
146
+ add_settings_field(
147
+ 'wpzoom-instagram-widget-is-forced-timeout',
148
+ __( 'Enable request timeout', 'wpzoom-instagram-widget' ),
149
+ array( $this, 'settings_field_is_forced_timeout' ),
150
+ 'wpzoom-instagram-widget-settings-group',
151
+ 'wpzoom-instagram-widget-settings-general'
152
+ );
153
+
154
+ add_settings_field(
155
+ 'wpzoom-instagram-widget-request-timeout',
156
+ __( 'Request timeout in seconds', 'wpzoom-instagram-widget' ),
157
+ array( $this, 'settings_field_request_timeout' ),
158
+ 'wpzoom-instagram-widget-settings-group',
159
+ 'wpzoom-instagram-widget-settings-general',
160
+ array( 'class' => 'wpzoom-instagram-widget-request-timeout' )
161
+ );
162
+
163
+ add_settings_field(
164
+ 'wpzoom-instagram-widget-request-timeout',
165
+ __( 'Request timeout in seconds', 'wpzoom-instagram-widget' ),
166
+ array( $this, 'settings_field_request_timeout' ),
167
+ 'wpzoom-instagram-widget-settings-group',
168
+ 'wpzoom-instagram-widget-settings-general',
169
+ array( 'class' => 'wpzoom-instagram-widget-request-timeout' )
170
+ );
171
 
 
 
 
 
 
 
 
 
 
172
  }
173
 
174
  public function settings_field_basic_access_token_button() {
175
 
176
  $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
177
 
178
+ $oauth_url = add_query_arg(
179
+ array(
180
+ 'client_id' => '1242932982579434',
181
+ 'redirect_uri' => 'https://wpzoom.com/instagram-auth/',
182
+ 'scope' => 'user_profile,user_media',
183
+ 'response_type' => 'code',
184
+ ),
185
+ 'https://api.instagram.com/oauth/authorize'
186
+ );
187
+ $oauth_url .= '&state=' . base64_encode( urlencode( admin_url( 'options-general.php?page=wpzoom-instagram-widget' ) ) );
188
  ?>
189
 
190
+ <p class="description"><?php _e( 'Using this method, you will be prompted to authorize the plugin to access your Instagram photos. The widget will automatically display the latest photos of the account which was authorized on this page.', 'wpzoom-instagram-widget' ); ?></p>
191
+ <p class="description" style="color:#185373;"><strong><?php _e( 'Access tokens are valid for <u>60 days</u>. If the widget stops working, please generate a new Access Token below.', 'wpzoom-instagram-widget' ); ?></strong></p>
192
 
193
+ <br/>
194
 
195
+ <a class="button button-connect" href="<?php echo esc_url( $oauth_url ); ?>">
196
  <?php if ( empty( $settings['basic-access-token'] ) ) : ?>
197
+ <span><?php _e( 'Connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
198
+ <?php else : ?>
199
+ <span class="zoom-instagarm-widget-connected"><?php _e( 'Re-connect with Instagram', 'wpzoom-instagram-widget' ); ?></span>
200
  <?php endif; ?>
201
+ </a>
202
+ </p>
203
+ <?php
204
+ }
205
+
206
+ public function settings_field_transient_lifetime() {
207
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
208
+ $lifetime_value = ! empty( $settings['transient-lifetime-value'] ) ? $settings['transient-lifetime-value'] : 1;
209
+ $lifetime_type = ! empty( $settings['transient-lifetime-type'] ) ? $settings['transient-lifetime-type'] : 'days';
210
+ ?>
211
+ <input class="regular-text code"
212
+ id="wpzoom-instagram-widget-settings_transient-lifetime-value"
213
+ name="wpzoom-instagram-widget-settings[transient-lifetime-value]"
214
+ value="<?php echo esc_attr( $lifetime_value ); ?>"
215
+ type="number"
216
+ min="1">
217
+
218
+ <select class="regular-text code"
219
+ id="wpzoom-instagram-widget-settings_transient-lifetime-type"
220
+ name="wpzoom-instagram-widget-settings[transient-lifetime-type]">
221
+ <option <?php selected( $lifetime_type, 'hours' ); ?>
222
+ value="hours"><?php _e( 'Hours', 'wpzoom-instagram-widget' ); ?></option>
223
+ <option <?php selected( $lifetime_type, 'days' ); ?>
224
+ value="days"><?php _e( 'Days', 'wpzoom-instagram-widget' ); ?></option>
225
+ <option <?php selected( $lifetime_type, 'minutes' ); ?>
226
+ value="minutes"><?php _e( 'Minutes', 'wpzoom-instagram-widget' ); ?></option>
227
+ </select>
228
  <?php
229
  }
230
 
231
+ public function settings_field_is_forced_timeout() {
232
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
233
+ $is_forced_timeout = ! empty( $settings['is-forced-timeout'] ) ? wp_validate_boolean( $settings['is-forced-timeout'] ) : false;
234
+ ?>
235
+ <input class="regular-text code"
236
+ id="wpzoom-instagram-widget-settings_is-forced-timeout"
237
+ name="wpzoom-instagram-widget-settings[is-forced-timeout]"
238
+ <?php checked( true, $is_forced_timeout ); ?>
239
+ value="1"
240
+ type="checkbox">
241
+
242
+ <?php
243
+ }
244
+
245
+ public function settings_field_request_timeout() {
246
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
247
+ $timeout_value = ! empty( $settings['request-timeout-value'] ) ? $settings['request-timeout-value'] : 15;
248
+ ?>
249
+ <input class="regular-text code"
250
+ id="wpzoom-instagram-widget-settings_request-timeout-value"
251
+ name="wpzoom-instagram-widget-settings[request-timeout-value]"
252
+ value="<?php echo esc_attr( $timeout_value ); ?>"
253
+ type="number"
254
+ min="1"
255
+ max="30">
256
+
257
+
258
+ <p class="description"><?php _e( 'The default timeout to get your Instagram feed is 15 seconds, but on some servers, this might not be enough time. Enter a higher value like 30 (seconds) and save changes to see if there is a difference.', 'wpzoom-instagram-widget' ); ?></p>
259
+
260
+ <?php
261
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
 
263
  public function settings_field_basic_access_token_input() {
264
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
265
  $basic_access_token = ! empty( $settings['basic-access-token'] ) ? $settings['basic-access-token'] : '';
266
  ?>
267
+ <input class="regular-text code" id="wpzoom-instagram-widget-settings_basic-access-token"
268
+ name="wpzoom-instagram-widget-settings[basic-access-token]"
269
+ value="<?php echo esc_attr( $basic_access_token ); ?>" type="text">
270
+ <p class="description">
271
  <?php
272
  printf(
273
  __(
277
  'https://www.wpzoom.com/instagram-auth/'
278
  );
279
  ?>
280
+ </p>
281
+ <?php
282
+ }
283
+
284
+ public function settings_field_username_description() {
285
+ ?>
286
+ <p class="description"><?php _e( '<strong style="color:#e44;">This method is no longer supported by Instagram and it will be soon deprecated.</strong>', 'wpzoom-instagram-widget' ); ?></p>
287
+ <p class="description"><?php _e( 'Using this method, a public feed, limited to <strong>12 photos</strong>, will be displayed in the widget.<br/>This option is useful if you want to display the feed of an Instagram account which you don\'t own or you have troubles getting your Access Token.', 'wpzoom-instagram-widget' ); ?></p>
288
+
289
+ </p>
290
+ <?php
291
+ }
292
+
293
+ public function settings_field_user_details() {
294
+ ?>
295
+ <p class="description"><?php _e( 'Below you can add additional details which you can display in the header of the Instagram Widget.', 'wpzoom-instagram-widget' ); ?></p>
296
+
297
+ </p>
298
+ <?php
299
+ }
300
+
301
+
302
+ public function settings_field_username() {
303
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
304
+ ?>
305
+ <input class="regular-text code" id="wpzoom-instagram-widget-settings_username"
306
+ name="wpzoom-instagram-widget-settings[username]" value="<?php echo esc_attr( $settings['username'] ); ?>"
307
+ type="text">
308
+ <p class="description">
309
+ <?php
310
+ printf(
311
+ __(
312
+ 'The username entered here will be used in the Instagram feed, unless a different username will be entered in the widget settings.',
313
+ 'wpzoom-instagram-widget'
314
+ )
315
+ );
316
+ ?>
317
+ </p>
318
+ <?php
319
+ }
320
+
321
+ public function settings_field_request_type() {
322
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
323
+ $request_type = empty( $settings['request-type'] ) ? 'with-basic-access-token' : $settings['request-type'];
324
+ ?>
325
+
326
+ <div class="wpzoom-instagram-widget-settings-request-type-wrapper">
327
+
328
+ <div class="label-wrap">
329
+ <input class="code"
330
+ id="wpzoom-instagram-widget-settings_with-basic-access-token"
331
+ name="wpzoom-instagram-widget-settings[request-type]"
332
+ value="with-basic-access-token" <?php checked( $request_type, 'with-basic-access-token' ); ?>
333
+ type="radio">
334
+ <label for="wpzoom-instagram-widget-settings_with-basic-access-token">
335
+ <?php _e( 'With Access Token (Instagram API)', 'wpzoom-instagram-widget' ); ?>
336
+ </label>
337
+ </div>
338
+ <div class="label-wrap">
339
+ <input class="code"
340
+ id="wpzoom-instagram-widget-settings_without-access-token"
341
+ name="wpzoom-instagram-widget-settings[request-type]"
342
+ value="without-access-token"
343
+ <?php checked( $request_type, 'without-access-token' ); ?>
344
+ type="radio">
345
+ <label for="wpzoom-instagram-widget-settings_without-access-token">
346
+ <?php _e( 'Public Feed (12 photos)', 'wpzoom-instagram-widget' ); ?>
347
+ </label>
348
+ </div>
349
+
350
+ </div>
351
+
352
+ <?php
353
+ }
354
+
355
+ public function settings_field_user_info_fullname() {
356
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
357
+ $user_info_fullname = empty( $settings['user-info-fullname'] ) ? '' : $settings['user-info-fullname'];
358
+ ?>
359
+ <input class="code"
360
+ id="wpzoom-instagram-widget-settings-user-info-fullname"
361
+ name="wpzoom-instagram-widget-settings[user-info-fullname]"
362
+ value="<?php echo esc_attr( $user_info_fullname ); ?>"
363
+ type="text">
364
+ <?php
365
+ }
366
+
367
+ public function settings_field_user_info_avatar() {
368
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
369
+ $user_info_avatar = empty( $settings['user-info-avatar'] ) ? '' : $settings['user-info-avatar'];
370
+ ?>
371
+ <div class="zoom-instagram-user-avatar-media-uploader"
372
+ data-type="image"
373
+ data-button-add-text="<?php _e( 'Upload a picture', 'wpzoom-instagram-widget' ); ?>"
374
+ data-button-replace-text="<?php _e( 'Replace Profile Picture', 'wpzoom-instagram-widget' ); ?>">
375
+ <a href="#" class="button add-media" title="Upload Profile Picture">
376
+ <span class="wp-media-buttons-icon"></span>
377
+ <?php _e( 'Upload a picture', 'wpzoom-instagram-widget' ); ?>
378
+ </a>
379
+ <button type="button" class="remove-avatar button-link delete-attachment">
380
+ <?php _e( 'Remove Profile Picture', 'wpzoom-instagram-widget' ); ?>
381
+ </button>
382
+ <div class="file-wrapper"></div>
383
+ <input class="attachment-input"
384
+ type="hidden"
385
+ name="wpzoom-instagram-widget-settings[user-info-avatar]"
386
+ value="<?php echo esc_attr( $user_info_avatar ); ?>">
387
+ </div>
388
+ <?php
389
+ }
390
+
391
+ public function settings_field_user_info_biography() {
392
+ $settings = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
393
+ $user_info_biography = empty( $settings['user-info-biography'] ) ? '' : $settings['user-info-biography'];
394
+ ?>
395
+ <textarea class="code"
396
+ id="wpzoom-instagram-widget-settings-user-info-biography"
397
+ name="wpzoom-instagram-widget-settings[user-info-biography]"
398
+ type="text"><?php echo esc_attr( $user_info_biography ); ?></textarea>
399
  <?php
400
  }
401
 
402
+ public function settings_page() {
403
+ ?>
404
+
405
+ <div class="wrap">
406
+
407
+ <h1><?php _e( 'Instagram Widget by WPZOOM', 'wpzoom-instagram-widget' ); ?></h1>
408
+
409
+ <div class="zoom-instagram-widget">
410
+
411
+ <h2><?php _e( 'Connect your Instagram account', 'wpzoom-instagram-widget' ); ?></h2>
412
+
413
+ <p><?php _e( 'To get started, select an option below. If you want to show <strong>your own feed</strong>, use the first option. If you want to show the feed of an Instagram account which you don\'t own, use the option <strong>Public Feed</strong>.', 'wpzoom-instagram-widget' ); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
+ <form action="options.php" method="post">
 
 
416
 
417
+ <?php
418
+ settings_fields( 'wpzoom-instagram-widget-settings-group' );
419
+ do_settings_sections( 'wpzoom-instagram-widget-settings-group' );
420
+ submit_button();
421
+ ?>
422
 
423
+ </form>
 
424
 
425
+ </div>
 
 
426
 
427
+ <div class="zoom-themes-link">
 
 
 
 
 
 
 
428
 
429
+ <h2><?php _e( 'Premium WordPress Themes by WPZOOM', 'wpzoom-instagram-widget' ); ?></h2>
 
 
430
 
431
+ <p><?php _e( 'Are you looking to give your website a new look?<br/> Check out our collection of <strong>35 expertly-crafted themes</strong> and find the perfect one for your needs!', 'wpzoom-instagram-widget' ); ?></p>
 
 
 
 
 
432
 
433
+ <p><a class="cta-button" target="_blank" href="https://www.wpzoom.com/themes/"><?php _e( 'Check out our Themes &rarr;', 'wpzoom-instagram-widget' ); ?></a></p>
434
 
435
+ </div>
436
+
437
+ </div>
438
+
439
+ <?php
440
+ }
441
+
442
+ public function scripts( $hook ) {
443
+ if ( $hook != 'settings_page_wpzoom-instagram-widget' ) {
444
+ return;
445
+ }
446
+ wp_enqueue_media();
447
+ wp_enqueue_style( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/admin-instagram-widget.css', array(), '1.7.3' );
448
+ wp_enqueue_script( 'zoom-instagram-widget-admin', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/admin-instagram-widget.js', array( 'jquery' ), '1.7.3' );
449
+ wp_localize_script(
450
+ 'zoom-instagram-widget-admin',
451
+ 'zoom_instagram_widget_admin',
452
+ array(
453
+ 'i18n_connect_confirm' => __( "Instagram Widget is already connected to Instagram.\r\n\r\nDo you want to connect again?", 'wpzoom-instagram-widget' ),
454
+ )
455
+ );
456
+ }
457
+
458
+ public function sanitize( $input ) {
459
+ $result = array();
460
+
461
+ $result['basic-access-token'] = sanitize_text_field( $input['basic-access-token'] );
462
+ $result['request-type'] = sanitize_text_field( $input['request-type'] );
463
+
464
+ if ( ! empty( $result['basic-access-token'] ) && ! empty( $result['request-type'] ) && 'with-basic-access-token' === $result['request-type'] ) {
465
+ $validation_result = Wpzoom_Instagram_Widget_API::is_access_token_valid( $result['basic-access-token'], $result['request-type'] );
466
+
467
+ if ( $validation_result !== true ) {
468
+ $access_token_error_message = __( 'Provided Access Token expired. Please connect the plugin with your Instagram account again.', 'wpzoom-instagram-widget' );
469
+
470
+ if ( is_wp_error( $validation_result ) ) {
471
+ $access_token_error_message = $validation_result->get_error_message();
472
+ }
473
+
474
+ if ( $validation_result !== true ) {
475
+ add_settings_error(
476
+ 'wpzoom-instagram-widget-access-token',
477
+ esc_attr( 'wpzoom-instagram-widget-access-token-invalid' ),
478
+ $access_token_error_message,
479
+ 'error'
480
+ );
481
+ }
482
+
483
+ $result['basic-access-token'] = '';
484
+ }
485
+ }
486
+
487
+ $result['username'] = sanitize_text_field( $input['username'] );
488
+ $result['transient-lifetime-value'] = sanitize_text_field( $input['transient-lifetime-value'] );
489
+ $result['transient-lifetime-type'] = sanitize_text_field( $input['transient-lifetime-type'] );
490
+ $result['is-forced-timeout'] = ! empty( $input['is-forced-timeout'] ) ? wp_validate_boolean( $input['is-forced-timeout'] ) : false;
491
+ $result['request-timeout-value'] = sanitize_text_field( $input['request-timeout-value'] );
492
+ $result['user-info-avatar'] = sanitize_text_field( $input['user-info-avatar'] );
493
+ $result['user-info-fullname'] = sanitize_text_field( $input['user-info-fullname'] );
494
+ $result['user-info-biography'] = sanitize_text_field( $input['user-info-biography'] );
495
+
496
+ Wpzoom_Instagram_Widget_API::reset_cache();
497
+
498
+ return $result;
499
+ }
500
  }
501
 
502
  new Wpzoom_Instagram_Widget_Settings();
class-wpzoom-instagram-widget.php CHANGED
@@ -1,4 +1,10 @@
1
  <?php
 
 
 
 
 
 
2
 
3
  class Wpzoom_Instagram_Widget extends WP_Widget {
4
  /**
@@ -27,10 +33,11 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
27
  'image-limit' => 9,
28
  'show-view-on-instagram-button' => true,
29
  'show-counts-on-hover' => false,
30
- 'show-user-info' => false,
31
  'show-user-bio' => false,
32
  'lazy-load-images' => false,
33
  'disable-video-thumbs' => false,
 
34
  'images-per-row' => 3,
35
  'image-width' => 120,
36
  'image-spacing' => 10,
@@ -40,16 +47,73 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
40
 
41
  $this->api = Wpzoom_Instagram_Widget_API::getInstance();
42
 
43
- add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
  /**
47
- * Widget specific scripts & styles
48
  */
49
- public function scripts() {
50
- wp_enqueue_style( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'css/instagram-widget.css', array('dashicons'), '1.6.0' );
51
- wp_enqueue_script( 'zoom-instagram-widget-lazy-load', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/jquery.lazy.min.js', array( 'jquery' ), '1.4.2' );
52
- wp_enqueue_script( 'zoom-instagram-widget', plugin_dir_url( dirname( __FILE__ ) . '/instagram-widget-by-wpzoom.php' ) . 'js/instagram-widget.js', array( 'jquery' ), '1.6.0' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
 
55
  /**
@@ -61,6 +125,9 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
61
  * @param array $instance Saved values from database.
62
  */
63
  public function widget( $args, $instance ) {
 
 
 
64
  $instance = wp_parse_args( (array) $instance, $this->defaults );
65
 
66
  echo $args['before_widget'];
@@ -69,16 +136,15 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
69
  echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
70
  }
71
 
72
-
73
- $items = $this->api->get_items( $instance );
74
  $errors = $this->api->errors->get_error_messages();
75
 
76
  if ( ! is_array( $items ) ) {
77
- $this->display_errors($errors);
78
  } else {
79
 
80
  if ( ! empty( $instance['show-user-info'] ) ) {
81
- $user_info = $this->api->get_user_info($instance['username']);
82
 
83
  if (
84
  is_object( $user_info ) &&
@@ -93,10 +159,276 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
93
  $this->display_instagram_button( $instance, $items['username'] );
94
  }
95
 
96
-
97
  echo $args['after_widget'];
98
  }
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  /**
101
  * Sanitize widget form values as they are saved.
102
  *
@@ -108,24 +440,24 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
108
  * @return array Updated safe values to be saved.
109
  */
110
  public function update( $new_instance, $old_instance ) {
111
- $instance['title'] = sanitize_text_field( $new_instance['title'] );
112
  $instance['button_text'] = sanitize_text_field( $new_instance['button_text'] );
113
 
114
  $instance['image-limit'] = ( 0 !== (int) $new_instance['image-limit'] ) ? (int) $new_instance['image-limit'] : null;
115
 
116
- $instance['images-per-row'] = ( 0 !== (int) $new_instance['images-per-row'] ) ? (int) $new_instance['images-per-row'] : null;
117
- $instance['image-width'] = ( 0 !== (int) $new_instance['image-width'] ) ? (int) $new_instance['image-width'] : null;
118
- $instance['image-spacing'] = ( 0 <= (int) $new_instance['image-spacing'] ) ? (int) $new_instance['image-spacing'] : null;
119
- $instance['image-resolution'] = !empty($new_instance['image-resolution']) ? $new_instance['image-resolution'] : $this->defaults['image-resolution'];
120
- $instance['username'] = !empty($new_instance['username']) ? $new_instance['username'] : $this->defaults['username'];
121
 
122
  $instance['show-view-on-instagram-button'] = ! empty( $new_instance['show-view-on-instagram-button'] );
123
  $instance['show-counts-on-hover'] = ! empty( $new_instance['show-counts-on-hover'] );
124
- $instance['show-user-info'] = ! empty( $new_instance['show-user-info'] );
125
  $instance['show-user-bio'] = ! empty( $new_instance['show-user-bio'] );
126
  $instance['lazy-load-images'] = ! empty( $new_instance['lazy-load-images'] );
127
  $instance['disable-video-thumbs'] = ! empty( $new_instance['disable-video-thumbs'] );
128
-
129
 
130
  return $instance;
131
  }
@@ -143,41 +475,77 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
143
  $instance = wp_parse_args( (array) $instance, $this->defaults );
144
  ?>
145
 
146
- <?php if ( empty($instance['username']) && ! $this->api->is_configured() ) : ?>
147
 
148
  <p style="color: #d54e21">
149
  <?php
150
- printf( __( 'You need to configure <a href="%1$s">plugin settings</a> before using this widget.', 'wpzoom-instagram-widget' ),
151
- menu_page_url( 'wpzoom-instagram-widget', false ) );
152
- ?>
 
 
153
  </p>
154
 
155
  <?php endif; ?>
156
 
157
  <p>
158
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'wpzoom-instagram-widget' ); ?></label>
159
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>"/>
 
 
160
  </p>
161
 
162
 
163
  <p>
164
  <label for="<?php echo $this->get_field_id( 'image-limit' ); ?>"><?php esc_html_e( 'Number of Images Shown:', 'wpzoom-instagram-widget' ); ?></label>
165
- <input class="widefat" id="<?php echo $this->get_field_id( 'image-limit' ); ?>" name="<?php echo $this->get_field_name( 'image-limit' ); ?>" type="number" min="1" max="30" value="<?php echo esc_attr( $instance['image-limit'] ); ?>"/>
 
 
166
  </p>
167
 
168
  <p>
169
  <label for="<?php echo $this->get_field_id( 'images-per-row' ); ?>"><?php esc_html_e( 'Desired number of Images per row:', 'wpzoom-instagram-widget' ); ?></label>
170
- <input class="widefat" id="<?php echo $this->get_field_id( 'images-per-row' ); ?>" name="<?php echo $this->get_field_name( 'images-per-row' ); ?>" type="number" min="1" max="20" value="<?php echo esc_attr( $instance['images-per-row'] ); ?>"/>
 
 
171
  </p>
172
 
173
  <p>
174
- <label for="<?php echo $this->get_field_id( 'image-width' ); ?>"><?php esc_html_e( 'Desired Image width in pixels:', 'wpzoom-instagram-widget' ); ?> <small>(Just integer)</small></label>
175
- <input class="widefat" id="<?php echo $this->get_field_id( 'image-width' ); ?>" name="<?php echo $this->get_field_name( 'image-width' ); ?>" type="number" min="20" value="<?php echo esc_attr( $instance['image-width'] ); ?>"/>
 
 
 
 
176
  </p>
177
 
178
  <p>
179
- <label for="<?php echo $this->get_field_id( 'image-spacing' ); ?>"><?php esc_html_e( 'Image spacing in pixels:', 'wpzoom-instagram-widget' ); ?> <small>(Just integer)</small></label>
180
- <input class="widefat" id="<?php echo $this->get_field_id( 'image-spacing' ); ?>" name="<?php echo $this->get_field_name( 'image-spacing' ); ?>" type="number" min="0" max="50" value="<?php echo esc_attr( $instance['image-spacing'] ); ?>"/>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  </p>
182
 
183
  <p class="description">
@@ -190,271 +558,76 @@ class Wpzoom_Instagram_Widget extends WP_Widget {
190
 
191
  <p>
192
  <label for="<?php echo $this->get_field_id( 'username' ); ?>"><strong><?php esc_html_e( 'Instagram @username:', 'wpzoom-instagram-widget' ); ?></strong></label>
193
- <input class="widefat" id="<?php echo $this->get_field_id( 'username' ); ?>" name="<?php echo $this->get_field_name( 'username' ); ?>" type="text" value="<?php echo esc_attr( $instance['username'] ); ?>"/>
 
 
194
  </p>
195
 
196
- <p class="description">
197
 
198
- <?php
199
- printf( __( 'If you have already connected your Instagram account in the <a href="%1$s">plugin settings</a>, leave this field empty. You can use this option if you want to display the feed of a different Instagram account.', 'wpzoom-instagram-widget' ),
200
- menu_page_url( 'wpzoom-instagram-widget', false ) );
201
- ?>
 
 
202
 
203
- </p>
204
 
205
  <p>
206
- <label for="<?php echo $this->get_field_id( 'image-resolution' ); ?>"><?php esc_html_e( 'Set forced image resolution:', 'wpzoom-instagram-widget' ); ?></label>
207
- <select class="widefat" id="<?php echo $this->get_field_id( 'image-resolution' ); ?>" name="<?php echo $this->get_field_name( 'image-resolution' ); ?>">
208
- <option value="default_algorithm" <?php selected( $instance['image-resolution'], "default_algorithm" ); ?>>
209
- <?php _e('By Default Algorithm', 'wpzoom-instagram-widget' ); ?>
210
- </option>
211
- <option value="thumbnail" <?php selected( $instance['image-resolution'], "thumbnail" ); ?>>
212
- <?php _e('Thumbnail ( 150x150px )', 'wpzoom-instagram-widget' ); ?>
213
- </option>
214
- <option value="low_resolution" <?php selected( $instance['image-resolution'], "low_resolution" ); ?>>
215
- <?php _e('Low Resolution ( 320x320px )', 'wpzoom-instagram-widget' ); ?>
216
-
217
- </option>
218
- <option value="standard_resolution" <?php selected( $instance['image-resolution'], "standard_resolution" ); ?>>
219
- <?php _e('Standard Resolution ( 640x640px )', 'wpzoom-instagram-widget' ); ?>
220
- </option>
221
- </select>
222
  </p>
 
223
  <p>
224
- <input class="checkbox" type="checkbox" <?php checked( $instance['show-user-info'] ); ?> id="<?php echo $this->get_field_id( 'show-user-info' ); ?>" name="<?php echo $this->get_field_name( 'show-user-info' ); ?>" />
225
- <label for="<?php echo $this->get_field_id( 'show-user-info' ); ?>"><?php _e(' Display <strong>User Details</strong>', 'wpzoom-instagram-widget' ); ?></label>
 
 
226
  </p>
227
 
228
- <p>
229
- <input class="checkbox" type="checkbox" <?php checked( $instance['show-user-bio'] ); ?> id="<?php echo $this->get_field_id( 'show-user-bio' ); ?>" name="<?php echo $this->get_field_name( 'show-user-bio' ); ?>" />
230
- <label for="<?php echo $this->get_field_id( 'show-user-bio' ); ?>"><?php _e(' Display <strong>Bio in User Details</strong>', 'wpzoom-instagram-widget' ); ?></label>
231
- </p>
232
-
233
  <p>
234
- <input class="checkbox" type="checkbox" <?php checked( $instance['show-view-on-instagram-button'] ); ?> id="<?php echo $this->get_field_id( 'show-view-on-instagram-button' ); ?>" name="<?php echo $this->get_field_name( 'show-view-on-instagram-button' ); ?>" />
235
- <label for="<?php echo $this->get_field_id( 'show-view-on-instagram-button' ); ?>"><?php _e(' Display <strong>View on Instagram</strong> button', 'wpzoom-instagram-widget' ); ?></label>
 
 
236
  </p>
237
 
238
  <p>
239
- <input class="checkbox" type="checkbox" <?php checked( $instance['show-counts-on-hover'] ); ?> id="<?php echo $this->get_field_id( 'show-counts-on-hover' ); ?>" name="<?php echo $this->get_field_name( 'show-counts-on-hover' ); ?>" />
240
- <label for="<?php echo $this->get_field_id( 'show-counts-on-hover' ); ?>"><?php _e(' Show <strong>overlay with number of comments and likes</strong> on hover', 'wpzoom-instagram-widget' ); ?></label>
 
 
241
  </p>
242
 
243
  <p>
244
- <input class="checkbox" type="checkbox" <?php checked( $instance['lazy-load-images'] ); ?> id="<?php echo $this->get_field_id( 'lazy-load-images' ); ?>" name="<?php echo $this->get_field_name( 'lazy-load-images' ); ?>" />
245
- <label for="<?php echo $this->get_field_id( 'lazy-load-images' ); ?>"><?php _e('Lazy Load <strong>images</strong>', 'wpzoom-instagram-widget' ); ?></label>
 
 
246
  </p>
247
  <p>
248
- <input class="checkbox" type="checkbox" <?php checked( $instance['disable-video-thumbs'] ); ?> id="<?php echo $this->get_field_id( 'disable-video-thumbs' ); ?>" name="<?php echo $this->get_field_name( 'disable-video-thumbs' ); ?>" />
249
- <label for="<?php echo $this->get_field_id( 'disable-video-thumbs' ); ?>"><?php _e('Hide video <strong>thumbnails</strong>', 'wpzoom-instagram-widget' ); ?></label>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  </p>
251
- <p>
252
- <label for="<?php echo $this->get_field_id( 'button_text' ); ?>"><?php esc_html_e( 'Button Text:', 'wpzoom-instagram-widget' ); ?></label>
253
- <input class="widefat" id="<?php echo $this->get_field_id( 'button_text' ); ?>" name="<?php echo $this->get_field_name( 'button_text' ); ?>" type="text" value="<?php echo esc_attr( $instance['button_text'] ); ?>"/>
254
- </p>
255
-
256
-
257
-
258
- <?php
259
- }
260
-
261
- protected function display_items( $items, $instance ) {
262
- $count = 0;
263
- $show_overlay = wp_validate_boolean($instance['show-counts-on-hover']);
264
- $small_class = (!empty($instance['image-width']) && $instance['image-width'] <= 180) ? 'small' : '';
265
- ?>
266
- <ul class="zoom-instagram-widget__items zoom-instagram-widget__items--no-js"
267
- data-images-per-row="<?php echo esc_attr( $instance['images-per-row'] ); ?>"
268
- data-image-width="<?php echo esc_attr( $instance['image-width'] ); ?>"
269
- data-image-spacing="<?php echo esc_attr( $instance['image-spacing'] ); ?>"
270
- data-image-lazy-loading="<?php echo esc_attr( $instance['lazy-load-images'] ); ?>">
271
-
272
- <?php foreach ( $items as $item ) : ?>
273
- <?php
274
- $link = $item['link'];
275
- $src = $item['image-url'];
276
- $alt = esc_attr($item['image-caption']);
277
- $likes = $item['likes_count'];
278
- $comments = $item['comments_count'];
279
- ?>
280
-
281
- <li class="zoom-instagram-widget__item">
282
-
283
- <?php
284
- $inline_style = 'width:'.esc_attr( $instance['image-width']).'px;';
285
- $inline_style .= 'height:'.esc_attr( $instance['image-width']).'px;';
286
- if(empty( $instance['lazy-load-images'] )){
287
- $inline_style.= "background-image: url('".$src."');";
288
- }
289
-
290
- if($show_overlay):?>
291
- <div class="hover-layout zoom-instagram-widget__overlay zoom-instagram-widget__black <?php echo $small_class?>">
292
-
293
- <?php if( !empty($likes) && !empty($comments) ):?>
294
- <div class="hover-controls">
295
- <span class="dashicons dashicons-heart"></span>
296
- <span class="counter"><?php echo $this->format_number($likes); ?></span>
297
- <span class="dashicons dashicons-format-chat"></span>
298
- <span class="counter"><?php echo $this->format_number($comments); ?></span>
299
- </div>
300
- <?php endif;?>
301
- <div class="zoom-instagram-icon-wrap">
302
- <a class="zoom-svg-instagram-stroke" href="<?php echo $link; ?>" rel="noopener" target="_blank" title="<?php echo $alt; ?>"></a>
303
- </div>
304
-
305
-
306
- <a class="zoom-instagram-link" data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
307
- href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
308
- >
309
- </a>
310
- </div>
311
- <?php else: ?>
312
- <a class="zoom-instagram-link" data-src="<?php echo $src; ?>" style="<?php echo $inline_style; ?>"
313
- href="<?php echo $link; ?>" target="_blank" rel="noopener" title="<?php echo $alt; ?>"
314
- >
315
- </a>
316
- <?php endif; ?>
317
- </li>
318
-
319
- <?php if ( ++$count === $instance['image-limit'] ) break; ?>
320
-
321
- <?php endforeach; ?>
322
-
323
- </ul>
324
-
325
- <div style="clear:both;"></div>
326
- <?php
327
- }
328
-
329
-
330
- protected function display_user_info( $instance, $user_info ) {
331
- ?>
332
- <div class="zoom-instagram-widget-user-info">
333
- <?php if ( ! empty( $user_info->data->profile_picture ) ): ?>
334
- <div class="zoom-instagram-widget-user-info-picture">
335
- <a target="_blank" rel="noopener" href="<?php printf( 'http://instagram.com/%s?ref=badge', esc_attr( $user_info->data->username ) ); ?>"><img width="90" src="<?php echo $user_info->data->profile_picture ?>" alt="<?php echo esc_attr( $user_info->data->full_name ) ?>"/></a>
336
- </div>
337
- <?php endif; ?>
338
- <div class="zoom-instagram-widget-user-info-meta">
339
- <div class="zoom-instagram-widget-user-info-about-data">
340
- <div class="zoom-instagram-widget-user-info-names-wrapper">
341
- <?php if ( ! empty( $user_info->data->full_name ) ): ?>
342
- <div class="zoom-instagram-widget-user-info-fullname">
343
- <?php esc_html_e( $user_info->data->full_name ) ?>
344
- </div>
345
- <?php endif; ?>
346
- <?php if ( ! empty( $user_info->data->username ) ): ?>
347
- <div class="zoom-instagram-widget-user-info-username">
348
- <?php esc_html_e( '@' . $user_info->data->username ) ?>
349
- </div>
350
- <?php endif; ?>
351
- </div>
352
- <div>
353
- <a class="zoom-instagram-widget-user-info-follow-button" target="_blank" rel="noopener" href="<?php printf( 'http://instagram.com/%s?ref=badge', esc_attr( $user_info->data->username ) ); ?>">
354
- <?php _e( 'Follow', 'wpzoom-instagram-widget' ) ?>
355
- </a>
356
- </div>
357
- </div>
358
- <div class="zoom-instagram-widget-user-info-stats">
359
- <?php if ( ! empty( $user_info->data->counts->media ) ): ?>
360
- <div>
361
- <div class="zoom-instagram-widget-user-info-counts"
362
- title="<?php echo number_format($user_info->data->counts->media)?>">
363
- <?php echo $this->format_number($user_info->data->counts->media); ?>
364
- </div>
365
- <div class="zoom-instagram-widget-user-info-counts-subhead">
366
- <?php _e( 'posts', 'wpzoom-instagram-widget' ); ?>
367
- </div>
368
- </div>
369
- <?php endif; ?>
370
- <?php if ( ! empty( $user_info->data->counts->followed_by ) ): ?>
371
- <div class="zoom-instagram-widget-user-info-middle-cell">
372
- <div class="zoom-instagram-widget-user-info-counts"
373
- title="<?php echo number_format($user_info->data->counts->followed_by)?>">
374
- <?php echo $this->format_number($user_info->data->counts->followed_by); ?>
375
- </div>
376
- <div class="zoom-instagram-widget-user-info-counts-subhead">
377
- <?php _e( 'followers', 'wpzoom-instagram-widget' ); ?>
378
- </div>
379
- </div>
380
- <?php endif; ?>
381
- <?php if ( ! empty( $user_info->data->counts->follows ) ): ?>
382
- <div>
383
- <div class="zoom-instagram-widget-user-info-counts"
384
- title="<?php echo number_format($user_info->data->counts->follows)?>">
385
- <?php echo $this->format_number($user_info->data->counts->follows); ?>
386
- </div>
387
- <div class="zoom-instagram-widget-user-info-counts-subhead">
388
- <?php _e( 'following', 'wpzoom-instagram-widget' ); ?>
389
- </div>
390
- </div>
391
- <?php endif; ?>
392
- </div>
393
- </div>
394
-
395
- </div>
396
- <?php
397
- if ( ! empty( $instance['show-user-bio'] ) ) {
398
-
399
- if ( ! empty( $user_info->data->bio ) ): ?>
400
- <div class="zoom-instagram-widget-user-info-bio"><?php echo nl2br( $user_info->data->bio ) ?></div>
401
- <?php endif;
402
-
403
- } ?>
404
-
405
- <?php
406
- }
407
-
408
- public function format_number( $num ) {
409
-
410
- if ( $num < 10000 ) {
411
- return number_format( $num );
412
- }
413
-
414
- $units = array( '', 'k', 'm', 'b', 't' );
415
- for ( $i = 0; $num >= 1000; $i ++ ) {
416
- $num /= 1000;
417
- }
418
-
419
- return round( $num, 1 ) . $units[ $i ];
420
- }
421
-
422
- protected function display_instagram_button( $instance, $username) {
423
- $show_view_on_instagram_button = $instance['show-view-on-instagram-button'];
424
-
425
- if ( ! $show_view_on_instagram_button ) {
426
- return;
427
- }
428
-
429
- ?>
430
- <div class="zoom-instagram-widget__follow-me">
431
- <a href="<?php printf( 'http://instagram.com/%s?ref=badge', esc_attr( $username ) ); ?>" class="ig-b- ig-b-v-24" rel="noopener" target="_blank"><?php echo esc_attr( $instance['button_text'] ); ?></a>
432
- </div>
433
- <?php
434
- }
435
 
436
- /**
437
- * Output errors if widget is misconfigured and current user can manage options (plugin settings).
438
- *
439
- * @return void
440
- */
441
- protected function display_errors($errors) {
442
- if ( current_user_can( 'edit_theme_options' ) ) {
443
- ?>
444
- <p>
445
- <?php _e( 'Instagram Widget misconfigured, check plugin &amp; widget settings.', 'wpzoom-instagram-widget' ); ?>
446
- </p>
447
 
448
- <?php if ( ! empty( $errors ) ): ?>
449
- <ul>
450
- <?php foreach ( $errors as $error ): ?>
451
- <li><?php echo $error; ?></li>
452
- <?php endforeach; ?>
453
- </ul>
454
- <?php endif; ?>
455
  <?php
456
- } else {
457
- echo "&#8230;";
458
- }
459
  }
460
  }
1
  <?php
2
+ /**
3
+ * Exit if accessed directly.
4
+ */
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
 
9
  class Wpzoom_Instagram_Widget extends WP_Widget {
10
  /**
33
  'image-limit' => 9,
34
  'show-view-on-instagram-button' => true,
35
  'show-counts-on-hover' => false,
36
+ 'show-user-info' => false,
37
  'show-user-bio' => false,
38
  'lazy-load-images' => false,
39
  'disable-video-thumbs' => false,
40
+ 'display-media-type-icons' => false,
41
  'images-per-row' => 3,
42
  'image-width' => 120,
43
  'image-spacing' => 10,
47
 
48
  $this->api = Wpzoom_Instagram_Widget_API::getInstance();
49
 
50
+ add_action( 'wp_enqueue_scripts', array( $this, 'styles' ) );
51
+ add_action( 'wp_enqueue_scripts', array( $this, 'register_scripts' ) );
52
+
53
+ /**
54
+ * Enqueue styles and scripts for SiteOrigin Page Builder.
55
+ */
56
+ add_action( 'siteorigin_panel_enqueue_admin_scripts', array( $this, 'styles' ) );
57
+ add_action( 'siteorigin_panel_enqueue_admin_scripts', array( $this, 'register_scripts' ) );
58
+ add_action( 'siteorigin_panel_enqueue_admin_scripts', array( $this, 'enqueue_scripts' ) );
59
+
60
+ }
61
+
62
+ /**
63
+ * Convert $url to file path.
64
+ *
65
+ * @param $url
66
+ *
67
+ * @return string|string[]
68
+ */
69
+ function convert_url_to_path( $url ) {
70
+ return str_replace(
71
+ wp_get_upload_dir()['baseurl'],
72
+ wp_get_upload_dir()['basedir'],
73
+ $url
74
+ );
75
+ }
76
+
77
+ /**
78
+ * Load widget specific styles.
79
+ */
80
+ public function styles() {
81
+ wp_enqueue_style(
82
+ 'zoom-instagram-widget',
83
+ plugin_dir_url( __FILE__ ) . 'css/instagram-widget.css',
84
+ array( 'dashicons' ),
85
+ WPZOOM_INSTAGRAM_VERSION
86
+ );
87
  }
88
 
89
  /**
90
+ * Register widget specific scripts.
91
  */
92
+ public function register_scripts() {
93
+ $file_mod_time = filemtime( plugin_dir_path( __FILE__ ) . 'js/jquery.lazy.min.js' );
94
+
95
+ wp_register_script(
96
+ 'zoom-instagram-widget-lazy-load',
97
+ plugin_dir_url( __FILE__ ) . 'js/jquery.lazy.min.js',
98
+ array( 'jquery' ),
99
+ strval( $file_mod_time ),
100
+ true
101
+ );
102
+ wp_register_script(
103
+ 'zoom-instagram-widget',
104
+ plugin_dir_url( __FILE__ ) . 'js/instagram-widget.js',
105
+ array( 'jquery', 'underscore', 'wp-util' ),
106
+ WPZOOM_INSTAGRAM_VERSION,
107
+ true
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Load widget specific scripts.
113
+ */
114
+ public function enqueue_scripts() {
115
+ wp_enqueue_script( 'zoom-instagram-widget-lazy-load' );
116
+ wp_enqueue_script( 'zoom-instagram-widget' );
117
  }
118
 
119
  /**
125
  * @param array $instance Saved values from database.
126
  */
127
  public function widget( $args, $instance ) {
128
+
129
+ $this->enqueue_scripts();
130
+
131
  $instance = wp_parse_args( (array) $instance, $this->defaults );
132
 
133
  echo $args['before_widget'];
136
  echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
137
  }
138
 
139
+ $items = $this->api->get_items( $instance );
 
140
  $errors = $this->api->errors->get_error_messages();
141
 
142
  if ( ! is_array( $items ) ) {
143
+ $this->display_errors( $errors );
144
  } else {
145
 
146
  if ( ! empty( $instance['show-user-info'] ) ) {
147
+ $user_info = $this->api->get_user_info( $instance['username'] );
148
 
149
  if (
150
  is_object( $user_info ) &&
159
  $this->display_instagram_button( $instance, $items['username'] );
160
  }
161
 
 
162
  echo $args['after_widget'];
163
  }
164
 
165
+ /**
166
+ * Output errors if widget is misconfigured and current user can manage options (plugin settings).
167
+ *
168
+ * @return void
169
+ */
170
+ protected function display_errors( $errors ) {
171
+ if ( current_user_can( 'edit_theme_options' ) ) {
172
+ ?>
173
+ <p>
174
+ <?php _e( 'Instagram Widget misconfigured or your Access Token <strong>expired</strong>. Please check', 'wpzoom-instagram-widget' ); ?>
175
+ <strong><a href="<?php echo admin_url( 'options-general.php?page=wpzoom-instagram-widget' ); ?>" target="_blank"><?php _e( 'Instagram Settings Page', 'wpzoom-instagram-widget' ); ?></a></strong> <?php _e( 'and make sure the plugin is properly configured', 'wpzoom-instagram-widget' ); ?>
176
+
177
+ </p>
178
+
179
+ <?php if ( ! empty( $errors ) ) : ?>
180
+ <ul>
181
+ <?php foreach ( $errors as $error ) : ?>
182
+ <li><?php echo $error; ?></li>
183
+ <?php endforeach; ?>
184
+ </ul>
185
+ <?php endif; ?>
186
+ <?php
187
+ } else {
188
+ echo '&#8230;';
189
+ }
190
+ }
191
+
192
+ protected function display_user_info( $instance, $user_info ) {
193
+ ?>
194
+ <div class="zoom-instagram-widget-user-info">
195
+ <?php if ( ! empty( $user_info->data->profile_picture ) ) : ?>
196
+ <div class="zoom-instagram-widget-user-info-picture">
197
+ <a target="_blank" rel="noopener nofollow"
198
+ href="<?php printf( 'https://instagram.com/%s?ref=badge', esc_attr( $user_info->data->username ) ); ?>"><img
199
+ width="90" src="<?php echo $user_info->data->profile_picture; ?>"
200
+ alt="<?php echo esc_attr( $user_info->data->full_name ); ?>"/></a>
201
+ </div>
202
+ <?php endif; ?>
203
+ <div class="zoom-instagram-widget-user-info-meta">
204
+ <div class="zoom-instagram-widget-user-info-about-data">
205
+ <div class="zoom-instagram-widget-user-info-names-wrapper">
206
+ <?php if ( ! empty( $user_info->data->full_name ) ) : ?>
207
+ <div class="zoom-instagram-widget-user-info-fullname">
208
+ <?php esc_html_e( $user_info->data->full_name, 'wpzoom-instagram-widget' ); ?>
209
+ </div>
210
+ <?php endif; ?>
211
+ <?php if ( ! empty( $user_info->data->username ) ) : ?>
212
+ <div class="zoom-instagram-widget-user-info-username">
213
+ <?php esc_html_e( '@' . $user_info->data->username, 'wpzoom-instagram-widget' ); ?>
214
+ </div>
215
+ <?php endif; ?>
216
+ </div>
217
+ <div>
218
+ <a class="zoom-instagram-widget-user-info-follow-button" target="_blank" rel="noopener nofollow"
219
+ href="<?php printf( 'https://instagram.com/%s?ref=badge', esc_attr( $user_info->data->username ) ); ?>">
220
+ <?php _e( 'Follow', 'wpzoom-instagram-widget' ); ?>
221
+ </a>
222
+ </div>
223
+ </div>
224
+ <div class="zoom-instagram-widget-user-info-stats">
225
+ <?php if ( ! empty( $user_info->data->counts->media ) ) : ?>
226
+ <div>
227
+ <div class="zoom-instagram-widget-user-info-counts"
228
+ title="<?php echo number_format( $user_info->data->counts->media ); ?>">
229
+ <?php echo $this->format_number( $user_info->data->counts->media ); ?>
230
+ </div>
231
+ <div class="zoom-instagram-widget-user-info-counts-subhead">
232
+ <?php _e( 'posts', 'wpzoom-instagram-widget' ); ?>
233
+ </div>
234
+ </div>
235
+ <?php endif; ?>
236
+ <?php if ( ! empty( $user_info->data->counts->followed_by ) ) : ?>
237
+ <div class="zoom-instagram-widget-user-info-middle-cell">
238
+ <div class="zoom-instagram-widget-user-info-counts"
239
+ title="<?php echo number_format( $user_info->data->counts->followed_by ); ?>">
240
+ <?php echo $this->format_number( $user_info->data->counts->followed_by ); ?>
241
+ </div>
242
+ <div class="zoom-instagram-widget-user-info-counts-subhead">
243
+ <?php _e( 'followers', 'wpzoom-instagram-widget' ); ?>
244
+ </div>
245
+ </div>
246
+ <?php endif; ?>
247
+ <?php if ( ! empty( $user_info->data->counts->follows ) ) : ?>
248
+ <div>
249
+ <div class="zoom-instagram-widget-user-info-counts"
250
+ title="<?php echo number_format( $user_info->data->counts->follows ); ?>">
251
+ <?php echo $this->format_number( $user_info->data->counts->follows ); ?>
252
+ </div>
253
+ <div class="zoom-instagram-widget-user-info-counts-subhead">
254
+ <?php _e( 'following', 'wpzoom-instagram-widget' ); ?>
255
+ </div>
256
+ </div>
257
+ <?php endif; ?>
258
+ </div>
259
+ </div>
260
+
261
+ </div>
262
+ <?php
263
+ if ( ! empty( $instance['show-user-bio'] ) ) {
264
+
265
+ if ( ! empty( $user_info->data->bio ) ) :
266
+ ?>
267
+ <div class="zoom-instagram-widget-user-info-bio"><?php echo nl2br( $user_info->data->bio ); ?></div>
268
+ <?php
269
+ endif;
270
+
271
+ }
272
+ ?>
273
+
274
+ <?php
275
+ }
276
+
277
+ public function format_number( $num ) {
278
+
279
+ if ( $num < 10000 ) {
280
+ return number_format( $num );
281
+ }
282
+
283
+ $units = array( '', 'k', 'm', 'b', 't' );
284
+ for ( $i = 0; $num >= 1000; $i ++ ) {
285
+ $num /= 1000;
286
+ }
287
+
288
+ return round( $num, 1 ) . $units[ $i ];
289
+ }
290
+
291
+ protected function display_items( $items, $instance ) {
292
+ $count = 0;
293
+ $show_overlay = wp_validate_boolean( $instance['show-counts-on-hover'] );
294
+ $show_media_type_icons = wp_validate_boolean( $instance['display-media-type-icons'] );
295
+ $small_class = ( ! empty( $instance['image-width'] ) && $instance['image-width'] <= 180 ) ? 'small' : '';
296
+ $svg_icons = plugin_dir_url( __FILE__ ) . 'images/wpzoom-instagram-icons.svg';
297
+ ?>
298
+ <ul class="zoom-instagram-widget__items zoom-instagram-widget__items--no-js"
299
+ data-images-per-row="<?php echo esc_attr( $instance['images-per-row'] ); ?>"
300
+ data-image-width="<?php echo esc_attr( $instance['image-width'] ); ?>"
301
+ data-image-spacing="<?php echo esc_attr( $instance['image-spacing'] ); ?>"
302
+ data-image-resolution="<?php echo esc_attr( $instance['image-resolution'] ); ?>"
303
+ data-image-lazy-loading="<?php echo esc_attr( $instance['lazy-load-images'] ); ?>">
304
+
305
+ <?php foreach ( $items as $item ) : ?>
306
+ <?php
307
+
308
+ $inline_attrs = '';
309
+ $overwrite_src = false;
310
+ $link = $item['link'];
311
+ $src = $item['image-url'];
312
+ $media_id = $item['image-id'];
313
+ $alt = esc_attr( $item['image-caption'] );
314
+ $likes = $item['likes_count'];
315
+ $type = in_array(
316
+ $item['type'],
317
+ array(
318
+ 'VIDEO',
319
+ 'CAROUSEL_ALBUM',
320
+ )
321
+ ) ? strtolower( $item['type'] ) : false;
322
+ $comments = $item['comments_count'];
323
+
324
+ if ( ! empty( $media_id ) && empty( $src ) ) {
325
+
326
+ $inline_attrs = 'data-media-id="' . esc_attr( $media_id ) . '"';
327
+ $inline_attrs .= 'data-nonce="' . wp_create_nonce( WPZOOM_Instagram_Image_Uploader::get_nonce_action( $media_id ) ) . '"';
328
+
329
+ $overwrite_src = true;
330
+ }
331
+
332
+ if (
333
+ ! empty( $media_id ) &&
334
+ ! empty( $src ) &&
335
+ ! file_exists( $this->convert_url_to_path( $src ) )
336
+ ) {
337
+
338
+ $inline_attrs = 'data-media-id="' . esc_attr( $media_id ) . '"';
339
+ $inline_attrs .= 'data-nonce="' . wp_create_nonce( WPZOOM_Instagram_Image_Uploader::get_nonce_action( $media_id ) ) . '"';
340
+ $inline_attrs .= 'data-regenerate-thumbnails="1"';
341
+
342
+ $overwrite_src = true;
343
+ }
344
+
345
+ if ( $overwrite_src ) {
346
+ $src = $item['original-image-url'];
347
+ }
348
+ ?>
349
+
350
+ <li class="zoom-instagram-widget__item" <?php echo $inline_attrs; ?>>
351
+
352
+ <?php
353
+ $inline_style = 'width:' . esc_attr( $instance['image-width'] ) . 'px;';
354
+ $inline_style .= 'height:' . esc_attr( $instance['image-width'] ) . 'px;';
355
+ if ( empty( $instance['lazy-load-images'] ) ) {
356
+ $inline_style .= "background-image: url('" . $src . "');";
357
+ }
358
+
359
+ if ( $show_overlay ) :
360
+ ?>
361
+ <div class="hover-layout zoom-instagram-widget__overlay zoom-instagram-widget__black <?php echo $small_class; ?>">
362
+ <?php if ( $show_media_type_icons && ! empty( $type ) ) : ?>
363
+ <svg class="svg-icon" shape-rendering="geometricPrecision">
364
+ <use xlink:href="<?php echo esc_url( $svg_icons ); ?>#<?php echo $type; ?>"></use>
365
+ </svg>
366
+ <?php endif; ?>
367
+
368
+ <?php if ( ! empty( $likes ) && ! empty( $comments ) ) : ?>
369
+ <div class="hover-controls">
370
+ <span class="dashicons dashicons-heart"></span>
371
+ <span class="counter"><?php echo $this->format_number( $likes ); ?></span>
372
+ <span class="dashicons dashicons-format-chat"></span>
373
+ <span class="counter"><?php echo $this->format_number( $comments ); ?></span>
374
+ </div>
375
+ <?php endif; ?>
376
+ <div class="zoom-instagram-icon-wrap">
377
+ <a class="zoom-svg-instagram-stroke" href="<?php echo $link; ?>" rel="noopener nofollow"
378
+ target="_blank" title="<?php echo $alt; ?>"></a>
379
+ </div>
380
+
381
+
382
+ <a class="zoom-instagram-link" data-src="<?php echo $src; ?>"
383
+ style="<?php echo $inline_style; ?>"
384
+ href="<?php echo $link; ?>" target="_blank" rel="noopener nofollow" title="<?php echo $alt; ?>"
385
+ >
386
+ </a>
387
+ </div>
388
+ <?php else : ?>
389
+ <a class="zoom-instagram-link" data-src="<?php echo $src; ?>"
390
+ style="<?php echo $inline_style; ?>"
391
+ href="<?php echo $link; ?>" target="_blank" rel="noopener nofollow" title="<?php echo $alt; ?>"
392
+ >
393
+ <?php if ( $show_media_type_icons && ! empty( $type ) ) : ?>
394
+ <svg class="svg-icon" shape-rendering="geometricPrecision">
395
+ <use xlink:href="<?php echo esc_url( $svg_icons ); ?>#<?php echo $type; ?>"></use>
396
+ </svg>
397
+ <?php endif; ?>
398
+ </a>
399
+ <?php endif; ?>
400
+ </li>
401
+
402
+ <?php
403
+ if ( ++ $count === $instance['image-limit'] ) {
404
+ break;
405
+ }
406
+ ?>
407
+
408
+ <?php endforeach; ?>
409
+
410
+ </ul>
411
+
412
+ <div style="clear:both;"></div>
413
+ <?php
414
+ }
415
+
416
+ protected function display_instagram_button( $instance, $username ) {
417
+ $show_view_on_instagram_button = $instance['show-view-on-instagram-button'];
418
+
419
+ if ( ! $show_view_on_instagram_button ) {
420
+ return;
421
+ }
422
+
423
+ ?>
424
+ <div class="zoom-instagram-widget__follow-me">
425
+ <a href="<?php printf( 'https://instagram.com/%s?ref=badge', esc_attr( $username ) ); ?>"
426
+ class="ig-b- ig-b-v-24" rel="noopener nofollow"
427
+ target="_blank"><?php echo esc_attr( $instance['button_text'] ); ?></a>
428
+ </div>
429
+ <?php
430
+ }
431
+
432
  /**
433
  * Sanitize widget form values as they are saved.
434
  *
440
  * @return array Updated safe values to be saved.
441
  */
442
  public function update( $new_instance, $old_instance ) {
443
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
444
  $instance['button_text'] = sanitize_text_field( $new_instance['button_text'] );
445
 
446
  $instance['image-limit'] = ( 0 !== (int) $new_instance['image-limit'] ) ? (int) $new_instance['image-limit'] : null;
447
 
448
+ $instance['images-per-row'] = ( 0 !== (int) $new_instance['images-per-row'] ) ? (int) $new_instance['images-per-row'] : null;
449
+ $instance['image-width'] = ( 0 !== (int) $new_instance['image-width'] ) ? (int) $new_instance['image-width'] : null;
450
+ $instance['image-spacing'] = ( 0 <= (int) $new_instance['image-spacing'] ) ? (int) $new_instance['image-spacing'] : null;
451
+ $instance['image-resolution'] = ! empty( $new_instance['image-resolution'] ) ? $new_instance['image-resolution'] : $this->defaults['image-resolution'];
452
+ $instance['username'] = ! empty( $new_instance['username'] ) ? $new_instance['username'] : $this->defaults['username'];
453
 
454
  $instance['show-view-on-instagram-button'] = ! empty( $new_instance['show-view-on-instagram-button'] );
455
  $instance['show-counts-on-hover'] = ! empty( $new_instance['show-counts-on-hover'] );
456
+ $instance['show-user-info'] = ! empty( $new_instance['show-user-info'] );
457
  $instance['show-user-bio'] = ! empty( $new_instance['show-user-bio'] );
458
  $instance['lazy-load-images'] = ! empty( $new_instance['lazy-load-images'] );
459
  $instance['disable-video-thumbs'] = ! empty( $new_instance['disable-video-thumbs'] );
460
+ $instance['display-media-type-icons'] = ! empty( $new_instance['display-media-type-icons'] );
461
 
462
  return $instance;
463
  }
475
  $instance = wp_parse_args( (array) $instance, $this->defaults );
476
  ?>
477
 
478
+ <?php if ( empty( $instance['username'] ) && ! $this->api->is_configured() ) : ?>
479
 
480
  <p style="color: #d54e21">
481
  <?php
482
+ printf(
483
+ __( 'You need to configure <a href="%1$s">plugin settings</a> before using this widget.', 'wpzoom-instagram-widget' ),
484
+ menu_page_url( 'wpzoom-instagram-widget', false )
485
+ );
486
+ ?>
487
  </p>
488
 
489
  <?php endif; ?>
490
 
491
  <p>
492
  <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'wpzoom-instagram-widget' ); ?></label>
493
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>"
494
+ name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
495
+ value="<?php echo esc_attr( $instance['title'] ); ?>"/>
496
  </p>
497
 
498
 
499
  <p>
500
  <label for="<?php echo $this->get_field_id( 'image-limit' ); ?>"><?php esc_html_e( 'Number of Images Shown:', 'wpzoom-instagram-widget' ); ?></label>
501
+ <input class="widefat" id="<?php echo $this->get_field_id( 'image-limit' ); ?>"
502
+ name="<?php echo $this->get_field_name( 'image-limit' ); ?>" type="number" min="1" max="30"
503
+ value="<?php echo esc_attr( $instance['image-limit'] ); ?>"/>
504
  </p>
505
 
506
  <p>
507
  <label for="<?php echo $this->get_field_id( 'images-per-row' ); ?>"><?php esc_html_e( 'Desired number of Images per row:', 'wpzoom-instagram-widget' ); ?></label>
508
+ <input class="widefat" id="<?php echo $this->get_field_id( 'images-per-row' ); ?>"
509
+ name="<?php echo $this->get_field_name( 'images-per-row' ); ?>" type="number" min="1" max="20"
510
+ value="<?php echo esc_attr( $instance['images-per-row'] ); ?>"/>
511
  </p>
512
 
513
  <p>
514
+ <label for="<?php echo $this->get_field_id( 'image-width' ); ?>"><?php esc_html_e( 'Desired Image width in pixels:', 'wpzoom-instagram-widget' ); ?>
515
+ <small>(Just integer)</small>
516
+ </label>
517
+ <input class="widefat" id="<?php echo $this->get_field_id( 'image-width' ); ?>"
518
+ name="<?php echo $this->get_field_name( 'image-width' ); ?>" type="number" min="20"
519
+ value="<?php echo esc_attr( $instance['image-width'] ); ?>"/>
520
  </p>
521
 
522
  <p>
523
+ <label for="<?php echo $this->get_field_id( 'image-resolution' ); ?>"><?php esc_html_e( 'Force image resolution:', 'wpzoom-instagram-widget' ); ?></label>
524
+ <select class="widefat" id="<?php echo $this->get_field_id( 'image-resolution' ); ?>"
525
+ name="<?php echo $this->get_field_name( 'image-resolution' ); ?>">
526
+ <option value="default_algorithm" <?php selected( $instance['image-resolution'], 'default_algorithm' ); ?>>
527
+ <?php _e( 'By Default Algorithm', 'wpzoom-instagram-widget' ); ?>
528
+ </option>
529
+ <option value="thumbnail" <?php selected( $instance['image-resolution'], 'thumbnail' ); ?>>
530
+ <?php _e( 'Thumbnail ( 150x150px )', 'wpzoom-instagram-widget' ); ?>
531
+ </option>
532
+ <option value="low_resolution" <?php selected( $instance['image-resolution'], 'low_resolution' ); ?>>
533
+ <?php _e( 'Low Resolution ( 320x320px )', 'wpzoom-instagram-widget' ); ?>
534
+
535
+ </option>
536
+ <option value="standard_resolution" <?php selected( $instance['image-resolution'], 'standard_resolution' ); ?>>
537
+ <?php _e( 'Standard Resolution ( 640x640px )', 'wpzoom-instagram-widget' ); ?>
538
+ </option>
539
+ </select>
540
+ </p>
541
+
542
+ <p>
543
+ <label for="<?php echo $this->get_field_id( 'image-spacing' ); ?>"><?php esc_html_e( 'Image spacing in pixels:', 'wpzoom-instagram-widget' ); ?>
544
+ <small>(Just integer)</small>
545
+ </label>
546
+ <input class="widefat" id="<?php echo $this->get_field_id( 'image-spacing' ); ?>"
547
+ name="<?php echo $this->get_field_name( 'image-spacing' ); ?>" type="number" min="0" max="50"
548
+ value="<?php echo esc_attr( $instance['image-spacing'] ); ?>"/>
549
  </p>
550
 
551
  <p class="description">
558
 
559
  <p>
560
  <label for="<?php echo $this->get_field_id( 'username' ); ?>"><strong><?php esc_html_e( 'Instagram @username:', 'wpzoom-instagram-widget' ); ?></strong></label>
561
+ <input class="widefat" id="<?php echo $this->get_field_id( 'username' ); ?>"
562
+ name="<?php echo $this->get_field_name( 'username' ); ?>" type="text"
563
+ value="<?php echo esc_attr( $instance['username'] ); ?>"/>
564
  </p>
565
 
566
+ <p class="description">
567
 
568
+ <?php
569
+ printf(
570
+ __( 'If you have already connected your Instagram account in the <a href="%1$s">plugin settings</a>, leave this field empty. You can use this option if you want to display the feed of a different Instagram account.', 'wpzoom-instagram-widget' ),
571
+ menu_page_url( 'wpzoom-instagram-widget', false )
572
+ );
573
+ ?>
574
 
575
+ </p>
576
 
577
  <p>
578
+ <input class="checkbox" type="checkbox" <?php checked( $instance['show-user-info'] ); ?>
579
+ id="<?php echo $this->get_field_id( 'show-user-info' ); ?>"
580
+ name="<?php echo $this->get_field_name( 'show-user-info' ); ?>"/>
581
+ <label for="<?php echo $this->get_field_id( 'show-user-info' ); ?>"><?php _e( ' Display <strong>User Details</strong>', 'wpzoom-instagram-widget' ); ?></label>
 
 
 
 
 
 
 
 
 
 
 
 
582
  </p>
583
+
584
  <p>
585
+ <input class="checkbox" type="checkbox" <?php checked( $instance['show-user-bio'] ); ?>
586
+ id="<?php echo $this->get_field_id( 'show-user-bio' ); ?>"
587
+ name="<?php echo $this->get_field_name( 'show-user-bio' ); ?>"/>
588
+ <label for="<?php echo $this->get_field_id( 'show-user-bio' ); ?>"><?php _e( ' Display <strong>Bio in User Details</strong>', 'wpzoom-instagram-widget' ); ?></label>
589
  </p>
590
 
 
 
 
 
 
591
  <p>
592
+ <input class="checkbox" type="checkbox" <?php checked( $instance['show-view-on-instagram-button'] ); ?>
593
+ id="<?php echo $this->get_field_id( 'show-view-on-instagram-button' ); ?>"
594
+ name="<?php echo $this->get_field_name( 'show-view-on-instagram-button' ); ?>"/>
595
+ <label for="<?php echo $this->get_field_id( 'show-view-on-instagram-button' ); ?>"><?php _e( ' Display <strong>View on Instagram</strong> button', 'wpzoom-instagram-widget' ); ?></label>
596
  </p>
597
 
598
  <p>
599
+ <input class="checkbox" type="checkbox" <?php checked( $instance['show-counts-on-hover'] ); ?>
600
+ id="<?php echo $this->get_field_id( 'show-counts-on-hover' ); ?>"
601
+ name="<?php echo $this->get_field_name( 'show-counts-on-hover' ); ?>"/>
602
+ <label for="<?php echo $this->get_field_id( 'show-counts-on-hover' ); ?>"><?php _e( ' Show <strong>overlay with Instagram icon</strong> on hover', 'wpzoom-instagram-widget' ); ?></label>
603
  </p>
604
 
605
  <p>
606
+ <input class="checkbox" type="checkbox" <?php checked( $instance['lazy-load-images'] ); ?>
607
+ id="<?php echo $this->get_field_id( 'lazy-load-images' ); ?>"
608
+ name="<?php echo $this->get_field_name( 'lazy-load-images' ); ?>"/>
609
+ <label for="<?php echo $this->get_field_id( 'lazy-load-images' ); ?>"><?php _e( 'Lazy Load <strong>images</strong>', 'wpzoom-instagram-widget' ); ?></label>
610
  </p>
611
  <p>
612
+ <input class="checkbox" type="checkbox" <?php checked( $instance['disable-video-thumbs'] ); ?>
613
+ id="<?php echo $this->get_field_id( 'disable-video-thumbs' ); ?>"
614
+ name="<?php echo $this->get_field_name( 'disable-video-thumbs' ); ?>"/>
615
+ <label for="<?php echo $this->get_field_id( 'disable-video-thumbs' ); ?>"><?php _e( 'Hide video <strong>thumbnails</strong>', 'wpzoom-instagram-widget' ); ?></label>
616
+ </p>
617
+ <p>
618
+ <input class="checkbox" type="checkbox" <?php checked( $instance['display-media-type-icons'] ); ?>
619
+ id="<?php echo $this->get_field_id( 'display-media-type-icons' ); ?>"
620
+ name="<?php echo $this->get_field_name( 'display-media-type-icons' ); ?>"/>
621
+ <label for="<?php echo $this->get_field_id( 'display-media-type-icons' ); ?>"><?php _e( 'Show <strong>media type icons</strong>', 'wpzoom-instagram-widget' ); ?></label>
622
+ </p>
623
+ <p>
624
+ <label for="<?php echo $this->get_field_id( 'button_text' ); ?>"><?php esc_html_e( 'Button Text:', 'wpzoom-instagram-widget' ); ?></label>
625
+ <input class="widefat" id="<?php echo $this->get_field_id( 'button_text' ); ?>"
626
+ name="<?php echo $this->get_field_name( 'button_text' ); ?>" type="text"
627
+ value="<?php echo esc_attr( $instance['button_text'] ); ?>"/>
628
  </p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
629
 
 
 
 
 
 
 
 
 
 
 
 
630
 
 
 
 
 
 
 
 
631
  <?php
 
 
 
632
  }
633
  }
css/admin-instagram-widget.css CHANGED
@@ -78,10 +78,16 @@
78
  background-color: #fff6f6;
79
  }
80
 
81
- .zoom-instagram-widget .wpzoom-instagram-widget-with-basic-access-token-group, .zoom-instagram-widget .wpzoom-instagram-widget-without-access-token-group {
 
82
  background-color: #e0f0e3;
83
  }
84
 
 
 
 
 
 
85
  .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_with-basic-access-token'],
86
  .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_without-access-token'] {
87
  background-color: #e0f0e3;
@@ -113,10 +119,26 @@
113
  z-index: 1;
114
  }
115
 
116
- .zoom-instagram-widget .form-table th {
117
- padding-left: 10px;
 
118
  }
119
 
 
120
  .zoom-instagram-widget .wpzoom-instagram-widget-with-token-group > td {
121
  padding-right: 0px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
78
  background-color: #fff6f6;
79
  }
80
 
81
+ .zoom-instagram-widget .wpzoom-instagram-widget-with-basic-access-token-group,
82
+ .zoom-instagram-widget .wpzoom-instagram-widget-without-access-token-group {
83
  background-color: #e0f0e3;
84
  }
85
 
86
+ .zoom-instagram-widget .wpzoom-instagram-widget-with-basic-access-token-group th,
87
+ .zoom-instagram-widget .wpzoom-instagram-widget-without-access-token-group th {
88
+ padding-left: 10px;
89
+ }
90
+
91
  .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_with-basic-access-token'],
92
  .zoom-instagram-widget .label-wrap input[type=radio]:checked + label[for='wpzoom-instagram-widget-settings_without-access-token'] {
93
  background-color: #e0f0e3;
119
  z-index: 1;
120
  }
121
 
122
+ .zoom-instagram-widget form h2 {
123
+ border-top: 2px solid #eee;
124
+ padding-top: 40px;
125
  }
126
 
127
+
128
  .zoom-instagram-widget .wpzoom-instagram-widget-with-token-group > td {
129
  padding-right: 0px;
130
+ }
131
+
132
+
133
+ .zoom-instagram-user-avatar-media-uploader .remove-avatar {
134
+ margin: 6px 20px;
135
+ color: #a00;
136
+ }
137
+
138
+ .zoom-instagram-user-avatar-media-uploader .file-wrapper{
139
+ margin-top: 10px;
140
+ }
141
+ #wpzoom-instagram-widget-settings-user-info-biography{
142
+ width: 100%;
143
+ min-height: 100px;
144
  }
css/instagram-widget.css CHANGED
@@ -1,10 +1,25 @@
1
  /* Widget Grid */
2
  .zoom-instagram-widget__follow-me { margin-top: 15px; text-align: center; }
3
 
4
- .zoom-instagram-widget__items { list-style: none; }
5
- .zoom-instagram-widget__item { float: left; position: relative; margin-top: 0 !important;}
 
 
 
 
 
 
 
 
 
 
6
 
7
- .zoom-instagram-widget__items--no-js .zoom-instagram-widget__item { margin-right: 10px; margin-bottom: 10px; }
 
 
 
 
 
8
 
9
 
10
  /* View on Instagram button */
@@ -181,6 +196,7 @@ a.ig-b-v-24:hover {
181
  flex-direction: column;
182
  margin-left: 15px;
183
  text-align: left;
 
184
  }
185
 
186
  .zoom-instagram-widget-user-info .zoom-instagram-widget-user-info-about-data {
@@ -275,4 +291,15 @@ a.ig-b-v-24:hover {
275
  background-size: cover;
276
  background-position: center center;
277
  background-repeat: no-repeat
278
- }
 
 
 
 
 
 
 
 
 
 
 
1
  /* Widget Grid */
2
  .zoom-instagram-widget__follow-me { margin-top: 15px; text-align: center; }
3
 
4
+ .zoom-instagram-widget__items { list-style: none !important; }
5
+ .zoom-instagram-widget__items::before,
6
+ .zoom-instagram-widget__items::after {
7
+ content: '';
8
+ clear: both;
9
+ display: table;
10
+ }
11
+ .zoom-instagram-widget__item {
12
+ float: left;
13
+ position: relative;
14
+ margin-top: 0 !important;
15
+ }
16
 
17
+ /* Prevent extra space conflict from theme */
18
+ .widget.zoom-instagram-widget ul li.zoom-instagram-widget__item {
19
+ padding: 0;
20
+ }
21
+
22
+ .zoom-instagram-widget__items--no-js.zoom-instagram-widget__items .zoom-instagram-widget__item { margin-right: 10px; margin-bottom: 10px; }
23
 
24
 
25
  /* View on Instagram button */
196
  flex-direction: column;
197
  margin-left: 15px;
198
  text-align: left;
199
+ justify-content: center;
200
  }
201
 
202
  .zoom-instagram-widget-user-info .zoom-instagram-widget-user-info-about-data {
291
  background-size: cover;
292
  background-position: center center;
293
  background-repeat: no-repeat
294
+ }
295
+
296
+ .zoom-instagram-widget__items .svg-icon {
297
+ position: absolute;
298
+ width: 32px;
299
+ padding: 8px;
300
+ height: 32px;
301
+ display: flex;
302
+ top: 0;
303
+ right: 0;
304
+ z-index: 1;
305
+ }
images/wpzoom-instagram-icons.svg ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg">
3
+ <symbol xmlns="http://www.w3.org/2000/svg" id="carousel_album" viewBox="0 0 512 512" fill="#ffffff">
4
+ <path d="M464 0c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48H176c-26.51 0-48-21.49-48-48V48c0-26.51 21.49-48 48-48h288M176 416c-44.112 0-80-35.888-80-80V128H48c-26.51 0-48 21.49-48 48v288c0 26.51 21.49 48 48 48h288c26.51 0 48-21.49 48-48v-48H176z"/>
5
+ </symbol>
6
+ <symbol xmlns="http://www.w3.org/2000/svg" id="video" viewBox="0 0 576 512" fill="#ffffff">
7
+ <path d="M336.2 64H47.8C21.4 64 0 85.4 0 111.8v288.4C0 426.6 21.4 448 47.8 448h288.4c26.4 0 47.8-21.4 47.8-47.8V111.8c0-26.4-21.4-47.8-47.8-47.8zm189.4 37.7L416 177.3v157.4l109.6 75.5c21.2 14.6 50.4-.3 50.4-25.8V127.5c0-25.4-29.1-40.4-50.4-25.8z"/>
8
+ </symbol>
9
+ </svg>
instagram-widget-by-wpzoom.php CHANGED
@@ -1,18 +1,31 @@
1
  <?php
2
-
3
  /**
4
  * Plugin Name: WPZOOM Instagram Widget
5
  * Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
6
- * Description: Simple and responsive widget for WordPress to display your Instagram feed
 
7
  * Author: WPZOOM
8
  * Author URI: https://www.wpzoom.com/
9
- * Version: 1.6.4
 
10
  * License: GPLv2 or later
11
  */
12
 
13
- require_once( plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-api.php' );
14
- require_once( plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-settings.php' );
15
- require_once( plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget.php' );
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  add_action( 'widgets_init', 'zoom_instagram_widget_register' );
18
  function zoom_instagram_widget_register() {
@@ -21,71 +34,99 @@ function zoom_instagram_widget_register() {
21
 
22
  /* Display a notice that can be dismissed */
23
 
24
- add_action('admin_notices', 'wpzoom_instagram_admin_notice');
25
 
26
  function wpzoom_instagram_admin_notice() {
27
- global $current_user ;
 
 
 
 
 
28
  $user_id = $current_user->ID;
29
  /* Check that the user hasn't already clicked to ignore the message */
30
- if ( ! get_user_meta($user_id, 'wpzoom_instagram_admin_notice') ) {
31
- echo '<div class="error notice" style="position:relative"><p>';
32
- printf(__('<strong>Please configure Instagram Widget</strong><br /><br/> If you have just installed or updated this plugin, please go to the <a href="options-general.php?page=wpzoom-instagram-widget">Settings page</a> and <strong>connect</strong> it with your Instagram account.<br/> You can ignore this message if you have already configured it. <a style="text-decoration: none" class="notice-dismiss" href="%1$s"></a>'), '?wpzoom_instagram_ignore_admin_notice=0');
33
- echo "</p></div>";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  }
35
  }
36
 
37
- add_action('admin_init', 'wpzoom_instagram_ignore_admin_notice');
38
 
39
  function wpzoom_instagram_ignore_admin_notice() {
40
  global $current_user;
41
  $user_id = $current_user->ID;
42
  /* If user clicks to ignore the notice, add that to their user meta */
43
- if ( isset($_GET['wpzoom_instagram_ignore_admin_notice']) && '0' == $_GET['wpzoom_instagram_ignore_admin_notice'] ) {
44
- add_user_meta($user_id, 'wpzoom_instagram_admin_notice', 'true', true);
45
  }
46
  }
47
 
48
- function wpzoom_instagram_legacy_api_admin_notice() {
49
-
50
- global $current_user ;
51
- $user_id = $current_user->ID;
52
-
53
- $options = get_option( 'wpzoom-instagram-widget-settings', wpzoom_instagram_get_default_settings() );
54
-
55
- $request_type = !empty($options['request-type']) ? $options['request-type'] : '';
56
-
57
- /* Check that the user hasn't already clicked to ignore the message */
58
- if ( ! get_user_meta($user_id, 'wpzoom_instagram_legacy_api_admin_notice') && $request_type === 'with-access-token') {
59
- echo '<div class="error notice" style="position:relative"><p>';
60
- printf(__('You’re using an <strong>outdated method</strong> to display your <strong>Instagram feed</strong>. This method will be <a target="_blank" href="https://www.instagram.com/developer/">deprecated</a> on <strong>June 29, 2020</strong>, and we recommend go to the <a href="options-general.php?page=wpzoom-instagram-widget">Settings page</a> and <strong>switch</strong> to the new method.<a style="text-decoration: none" class="notice-dismiss" href="%1$s"></a>'), '?wpzoom_instagram_legacy_api_admin_notice=0');
61
- echo "</p></div>";
62
- }
63
- }
64
 
65
  function wpzoom_instagram_get_default_settings() {
66
- return [
67
  'access-token' => '',
68
  'basic-access-token' => '',
69
  'request-type' => 'with-basic-access-token',
70
  'username' => '',
71
  'transient-lifetime-value' => 1,
72
  'transient-lifetime-type' => 'days',
73
- 'is-embed-stream' => '',
74
  'is-forced-timeout' => '',
75
- 'request-timeout-value' => 15
76
- ];
 
 
 
77
  }
78
 
79
- function wpzoom_instagram_ignore_legacy_api_admin_notice() {
80
- global $current_user;
81
- $user_id = $current_user->ID;
82
- /* If user clicks to ignore the notice, add that to their user meta */
83
 
84
- if ( isset($_GET['wpzoom_instagram_legacy_api_admin_notice']) && '0' == $_GET['wpzoom_instagram_legacy_api_admin_notice'] ) {
85
- add_user_meta($user_id, 'wpzoom_instagram_legacy_api_admin_notice', 'true', true);
 
 
 
86
  }
87
- }
88
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
- add_action('admin_notices', 'wpzoom_instagram_legacy_api_admin_notice');
91
- add_action('admin_init', 'wpzoom_instagram_ignore_legacy_api_admin_notice');
 
 
 
 
1
  <?php
 
2
  /**
3
  * Plugin Name: WPZOOM Instagram Widget
4
  * Plugin URI: https://www.wpzoom.com/plugins/instagram-widget/
5
+ * Description: Simple and lightweight widget for WordPress to display your Instagram feed
6
+ * Version: 1.7.4
7
  * Author: WPZOOM
8
  * Author URI: https://www.wpzoom.com/
9
+ * Text Domain: wpzoom-instagram-widget
10
+ * Domain Path: /languages
11
  * License: GPLv2 or later
12
  */
13
 
14
+ /**
15
+ * Exit if accessed directly.
16
+ */
17
+ if ( ! defined( 'ABSPATH' ) ) {
18
+ exit;
19
+ }
20
+
21
+ if ( ! defined( 'WPZOOM_INSTAGRAM_VERSION' ) ) {
22
+ define( 'WPZOOM_INSTAGRAM_VERSION', '1.7.5' );
23
+ }
24
+
25
+ require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-image-uploader.php';
26
+ require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-api.php';
27
+ require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget-settings.php';
28
+ require_once plugin_dir_path( __FILE__ ) . 'class-wpzoom-instagram-widget.php';
29
 
30
  add_action( 'widgets_init', 'zoom_instagram_widget_register' );
31
  function zoom_instagram_widget_register() {
34
 
35
  /* Display a notice that can be dismissed */
36
 
37
+ add_action( 'admin_notices', 'wpzoom_instagram_admin_notice' );
38
 
39
  function wpzoom_instagram_admin_notice() {
40
+
41
+ if ( ! current_user_can( 'manage_options' ) ) {
42
+ return;
43
+ }
44
+
45
+ global $current_user;
46
  $user_id = $current_user->ID;
47
  /* Check that the user hasn't already clicked to ignore the message */
48
+ if ( ! get_user_meta( $user_id, 'wpzoom_instagram_admin_notice' ) ) {
49
+ /**
50
+ * Fixed dismiss url
51
+ *
52
+ * @since 1.7.5
53
+ */
54
+ $hide_notices_url = html_entity_decode( // to convert &amp;s to normal &, otherwise produces invalid link.
55
+ add_query_arg(
56
+ array(
57
+ 'wpzoom_instagram_ignore_admin_notice' => '0',
58
+ ),
59
+ wpzoom_instagram_get_current_admin_url() ? wpzoom_instagram_get_current_admin_url() : admin_url( 'options-general.php?page=wpzoom-instagram-widget' )
60
+ )
61
+ );
62
+
63
+ $configure_message = '<strong>' . __( 'Please configure Instagram Widget', 'wpzoom-instagram-widget' ) . '</strong><br/><br/>';
64
+ $configure_message .= sprintf( __( 'If you have just installed or updated this plugin, please go to the %1$s and %2$s it with your Instagram account.', 'wpzoom-instagram-widget' ), '<a href="options-general.php?page=wpzoom-instagram-widget">' . __( 'Settings page', 'wpzoom-instagram-widget' ) . '</a>', '<strong>' . __( 'connect', 'wpzoom-instagram-widget' ) . '</strong>' ) . '&nbsp;';
65
+ $configure_message .= __( 'You can ignore this message if you have already configured it.', 'wpzoom-instagram-widget' );
66
+ $configure_message .= '<a style="text-decoration: none" class="notice-dismiss" href="' . $hide_notices_url . '"></a>';
67
+
68
+ echo '<div class="notice-warning notice" style="position:relative"><p>';
69
+ echo wp_kses_post( $configure_message );
70
+ echo '</p></div>';
71
  }
72
  }
73
 
74
+ add_action( 'admin_init', 'wpzoom_instagram_ignore_admin_notice' );
75
 
76
  function wpzoom_instagram_ignore_admin_notice() {
77
  global $current_user;
78
  $user_id = $current_user->ID;
79
  /* If user clicks to ignore the notice, add that to their user meta */
80
+ if ( isset( $_GET['wpzoom_instagram_ignore_admin_notice'] ) && '0' == $_GET['wpzoom_instagram_ignore_admin_notice'] ) {
81
+ add_user_meta( $user_id, 'wpzoom_instagram_admin_notice', 'true', true );
82
  }
83
  }
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  function wpzoom_instagram_get_default_settings() {
87
+ return array(
88
  'access-token' => '',
89
  'basic-access-token' => '',
90
  'request-type' => 'with-basic-access-token',
91
  'username' => '',
92
  'transient-lifetime-value' => 1,
93
  'transient-lifetime-type' => 'days',
 
94
  'is-forced-timeout' => '',
95
+ 'request-timeout-value' => 15,
96
+ 'user-info-avatar' => '',
97
+ 'user-info-fullname' => '',
98
+ 'user-info-biography' => '',
99
+ );
100
  }
101
 
102
+ add_action(
103
+ 'init',
104
+ function () {
 
105
 
106
+ $option_name = 'wpzoom-instagram-transition-between-4_7-4_8-versions';
107
+ if ( empty( get_option( $option_name ) ) ) {
108
+ update_option( $option_name, true );
109
+ delete_transient( 'zoom_instagram_is_configured' );
110
+ }
111
  }
112
+ );
113
 
114
+ /**
115
+ * Get current admin page URL.
116
+ *
117
+ * Returns an empty string if it cannot generate a URL.
118
+ *
119
+ * @internal
120
+ * @since 1.7.5
121
+ * @return string
122
+ */
123
+ function wpzoom_instagram_get_current_admin_url() {
124
+ $uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
125
+ $uri = preg_replace( '|^.*/wp-admin/|i', '', $uri );
126
 
127
+ if ( ! $uri ) {
128
+ return '';
129
+ }
130
+
131
+ return remove_query_arg( array( '_wpnonce', 'wpzoom_instagram_ignore_admin_notice' ), admin_url( $uri ) );
132
+ }
js/admin-instagram-widget.js CHANGED
@@ -2,6 +2,110 @@
2
 
3
  jQuery(function($) {
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  $('.wpzoom-instagram-widget-settings-request-type-wrapper').find('input[type=radio]').on('change', function (e) {
6
  e.preventDefault();
7
 
2
 
3
  jQuery(function($) {
4
 
5
+ $.fn.imageMediaControl = function () {
6
+
7
+ this.each(function () {
8
+ var $this = $(this);
9
+
10
+ var mediaControl = {
11
+ // Initializes a new media manager or returns an existing frame.
12
+ // @see wp.media.featuredImage.frame()
13
+ frame: function () {
14
+ if (this._frame)
15
+ return this._frame;
16
+
17
+ this._frame = wp.media({
18
+ title: $this.data('title'),
19
+ library: {
20
+ type: $this.data('type')
21
+ },
22
+ button: {
23
+ text: $this.data('button')
24
+ },
25
+ multiple: false,
26
+ selection: []
27
+ });
28
+
29
+ this._frame.on('open', this.updateFrame).state('library').on('select', this.select);
30
+
31
+ return this._frame;
32
+ },
33
+ select: function () {
34
+ var $attachmentInput = $this.find('.attachment-input');
35
+ var selection = this.get('selection');
36
+ var attachmentId = selection.pluck('id');
37
+
38
+ $attachmentInput.val(attachmentId).trigger('change');
39
+ },
40
+
41
+ updateFrame: function () {
42
+ },
43
+
44
+ init: function () {
45
+
46
+ var $fileWrapper = $this.find('.file-wrapper');
47
+ var $attachmentInput = $this.find('.attachment-input');
48
+ var $addButton = $this.find('.add-media');
49
+ var $removeButton = $this.find('.remove-avatar');
50
+
51
+ $addButton.on('click', function (e) {
52
+ e.preventDefault();
53
+ mediaControl.frame().open();
54
+ });
55
+
56
+ $removeButton.on('click', function (e) {
57
+ e.preventDefault();
58
+ $attachmentInput.val('').trigger('change');
59
+ });
60
+
61
+
62
+ $attachmentInput.on('change', function (e) {
63
+ e.preventDefault();
64
+
65
+ var attachmentId = $this.find('.attachment-input').val();
66
+ if (!!attachmentId) {
67
+ $addButton.text($this.data('button-replace-text'));
68
+ $removeButton.show();
69
+ var attachment = wp.media.attachment(attachmentId);
70
+ attachment.fetch().then(function (fetched) {
71
+ $fileWrapper.fadeOut(400, function () {
72
+ var imgSrc = fetched.url;
73
+
74
+ if (_.findKey(fetched, 'thumbnail')) {
75
+ imgSrc = fetched.sizes.thumbnail.url;
76
+ }
77
+
78
+ $(this).html('<img width="150" height="150" src="' + imgSrc + '"/>').fadeIn(400);
79
+ });
80
+ });
81
+ } else {
82
+ $fileWrapper.hide();
83
+ $removeButton.hide();
84
+ $addButton.text($this.data('button-add-text'));
85
+ }
86
+ }).trigger('change');
87
+ }
88
+ };
89
+
90
+ mediaControl.frame().on('open', function () {
91
+ var $attachmentInput = $this.find('.attachment-input');
92
+ var frame = mediaControl.frame();
93
+ var selection = frame.state().get('selection'),
94
+ attachmentId = $attachmentInput.val(),
95
+ attachment = wp.media.attachment(attachmentId);
96
+
97
+ frame.reset();
98
+
99
+ if (attachment.id) {
100
+ selection.add(attachment);
101
+ }
102
+ });
103
+ mediaControl.init();
104
+ });
105
+ }
106
+
107
+ $('.zoom-instagram-user-avatar-media-uploader').imageMediaControl();
108
+
109
  $('.wpzoom-instagram-widget-settings-request-type-wrapper').find('input[type=radio]').on('change', function (e) {
110
  e.preventDefault();
111
 
js/instagram-widget.js CHANGED
@@ -1,13 +1,60 @@
1
- jQuery(function($) {
2
  var ticking = false;
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  $.fn.zoomInstagramWidget = function () {
5
  return $(this).each(function () {
6
  var $list = $(this);
7
 
8
- var minItemsPerRow = $list.data('images-per-row');
9
  var desiredItemWidth = $list.data('image-width');
10
- var itemSpacing = $list.data('image-spacing');
11
  var imageLazyLoading = $list.data('image-lazy-loading');
12
 
13
  var containerWidth = $list.width();
@@ -17,14 +64,20 @@ jQuery(function($) {
17
 
18
  if (containerWidth / desiredItemWidth < minItemsPerRow) {
19
  fitPerRow = minItemsPerRow;
20
- itemWidth = Math.floor((containerWidth - 1 - (minItemsPerRow - 1) * itemSpacing) / minItemsPerRow);
21
  } else {
22
  fitPerRow = Math.floor((containerWidth - 1) / desiredItemWidth);
23
- itemWidth = Math.floor((containerWidth - 1 - (fitPerRow - 1) * itemSpacing) / fitPerRow);
24
  }
25
 
26
- $list.find('li').each(function(i) {
27
- if ( ++i % fitPerRow == 0 ) {
 
 
 
 
 
 
28
  $(this).css('margin-right', '0');
29
  } else {
30
  $(this).css('margin-right', itemSpacing + 'px');
@@ -53,12 +106,12 @@ jQuery(function($) {
53
  }
54
 
55
  function requestAnimationFrame() {
56
- return window.requestAnimationFrame ||
57
- window.webkitRequestAnimationFrame ||
58
- window.mozRequestAnimationFrame ||
59
- function (callback){
60
- window.setTimeout(callback, 1000 / 60);
61
- };
62
  }
63
 
64
  function update() {
@@ -68,4 +121,20 @@ jQuery(function($) {
68
 
69
  $(window).on('resize orientationchange', requestTick);
70
  requestTick();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  });
1
+ jQuery(function ($) {
2
  var ticking = false;
3
 
4
+ $.fn.zoomLoadAsyncImages = function () {
5
+ return $(this).each(function () {
6
+ var $list = $(this);
7
+
8
+ var desiredItemWidth = $list.data('image-width');
9
+ var imageResolution = $list.data('image-resolution');
10
+
11
+ var delayedItems = $list.find('li').filter(function () {
12
+ return $(this).data('media-id');
13
+ }).map(function () {
14
+ return {
15
+ 'media-id': $(this).attr('data-media-id'),
16
+ 'nonce': $(this).attr('data-nonce'),
17
+ 'regenerate-thumbnails': $(this)[0].hasAttribute("data-regenerate-thumbnails")
18
+ };
19
+ });
20
+
21
+ var getAsyncImages = function (images) {
22
+
23
+ var isLastImage = images.length == 0;
24
+
25
+ if (isLastImage) {
26
+ return;
27
+ }
28
+
29
+ var image = images.shift();
30
+
31
+ wp.ajax.post('wpzoom_instagram_get_image_async', {
32
+ 'media-id': image['media-id'],
33
+ nonce: image['nonce'],
34
+ 'image-resolution': imageResolution,
35
+ 'image-width': desiredItemWidth,
36
+ 'regenerate-thumbnails': image['regenerate-thumbnails']
37
+ }).done(function (data) {
38
+ $list.find('li[data-media-id="' + image['media-id'] + '"] .zoom-instagram-link').css('background-image', 'url(' + data.image_src + ')');
39
+ }).fail(function () {
40
+ }).always(function () {
41
+ getAsyncImages(images);
42
+ });
43
+ };
44
+
45
+ if (delayedItems.length) {
46
+ getAsyncImages(delayedItems.toArray());
47
+ }
48
+ });
49
+ };
50
+
51
  $.fn.zoomInstagramWidget = function () {
52
  return $(this).each(function () {
53
  var $list = $(this);
54
 
55
+ var minItemsPerRow = $list.data('images-per-row');
56
  var desiredItemWidth = $list.data('image-width');
57
+ var itemSpacing = $list.data('image-spacing');
58
  var imageLazyLoading = $list.data('image-lazy-loading');
59
 
60
  var containerWidth = $list.width();
64
 
65
  if (containerWidth / desiredItemWidth < minItemsPerRow) {
66
  fitPerRow = minItemsPerRow;
67
+ itemWidth = Math.floor(((containerWidth - 1 - (minItemsPerRow - 1) * itemSpacing) / minItemsPerRow));
68
  } else {
69
  fitPerRow = Math.floor((containerWidth - 1) / desiredItemWidth);
70
+ itemWidth = Math.floor(((containerWidth - 1 - (fitPerRow - 1) * itemSpacing) / fitPerRow));
71
  }
72
 
73
+ $list.find('li').each(function (i) {
74
+ var loop = ++i;
75
+ if (loop % fitPerRow == 1) {
76
+ $(this).css('clear', 'left');
77
+ } else {
78
+ $(this).css('clear', 'none');
79
+ }
80
+ if (loop % fitPerRow == 0) {
81
  $(this).css('margin-right', '0');
82
  } else {
83
  $(this).css('margin-right', itemSpacing + 'px');
106
  }
107
 
108
  function requestAnimationFrame() {
109
+ return window.requestAnimationFrame ||
110
+ window.webkitRequestAnimationFrame ||
111
+ window.mozRequestAnimationFrame ||
112
+ function (callback) {
113
+ window.setTimeout(callback, 1000 / 60);
114
+ };
115
  }
116
 
117
  function update() {
121
 
122
  $(window).on('resize orientationchange', requestTick);
123
  requestTick();
124
+
125
+ $('.zoom-instagram-widget__items').zoomLoadAsyncImages();
126
+
127
+
128
+ var siteOriginInit = function () {
129
+ var $widgets = $('.zoom-instagram-widget__items');
130
+ if ($widgets.length) {
131
+ $('.zoom-instagram-widget__items').zoomInstagramWidget();
132
+ $('.zoom-instagram-widget__items').zoomLoadAsyncImages();
133
+ }
134
+
135
+ };
136
+
137
+ var debounceInit = _.debounce(siteOriginInit, 1500);
138
+ $(document).on('panels_setup_preview', debounceInit);
139
+
140
  });
languages/wpzoom-instagram-widget.pot ADDED
@@ -0,0 +1,464 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2021 WPZOOM
2
+ # This file is distributed under the GPLv2 or later.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: WPZOOM Instagram Widget 1.7.5\n"
6
+ "Report-Msgid-Bugs-To: "
7
+ "https://wordpress.org/support/plugin/instagram-widget-by-wpzoom\n"
8
+ "POT-Creation-Date: 2021-05-19 08:24:10+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=utf-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2021-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: en\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "X-Poedit-Country: United States\n"
18
+ "X-Poedit-SourceCharset: UTF-8\n"
19
+ "X-Poedit-KeywordsList: "
20
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
21
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
22
+ "X-Poedit-Basepath: ../\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+ "X-Poedit-Bookmarks: \n"
25
+ "X-Textdomain-Support: yes\n"
26
+ "X-Generator: grunt-wp-i18n 1.0.3\n"
27
+
28
+ #: class-wpzoom-instagram-image-uploader.php:130
29
+ msgid "Invalid nonce."
30
+ msgstr ""
31
+
32
+ #: class-wpzoom-instagram-image-uploader.php:130
33
+ msgid "Invalid nonce provided for this action"
34
+ msgstr ""
35
+
36
+ #: class-wpzoom-instagram-image-uploader.php:138
37
+ msgid "Invalid media id."
38
+ msgstr ""
39
+
40
+ #: class-wpzoom-instagram-image-uploader.php:138
41
+ msgid "Could not retrieve image url with provided media id"
42
+ msgstr ""
43
+
44
+ #: class-wpzoom-instagram-widget-api.php:262
45
+ msgid "Empty json user info from Public Feed."
46
+ msgstr ""
47
+
48
+ #: class-wpzoom-instagram-widget-api.php:266
49
+ msgid ""
50
+ "The request from the Public Feed failed. Invalid server response from "
51
+ "Public JSON API url."
52
+ msgstr ""
53
+
54
+ #: class-wpzoom-instagram-widget-api.php:270
55
+ msgid ""
56
+ "The request from the Public Feed failed. Invalid JSON format from Public "
57
+ "JSON API url."
58
+ msgstr ""
59
+
60
+ #: class-wpzoom-instagram-widget-api.php:274
61
+ msgid "The request from the Public Feed failed. Check username."
62
+ msgstr ""
63
+
64
+ #: class-wpzoom-instagram-widget-api.php:278
65
+ msgid ""
66
+ "The request from the Public Feed failed. Invalid JSON format from parsed "
67
+ "html body."
68
+ msgstr ""
69
+
70
+ #: class-wpzoom-instagram-widget-api.php:282
71
+ msgid "Get items from the Public Feed failed. Invalid response."
72
+ msgstr ""
73
+
74
+ #: class-wpzoom-instagram-widget-api.php:286
75
+ msgid "Get items from the Public Feed failed. Malformed data structure."
76
+ msgstr ""
77
+
78
+ #: class-wpzoom-instagram-widget-api.php:290
79
+ msgid "Geting items from the Instagram API Feed failed. Invalid response."
80
+ msgstr ""
81
+
82
+ #: class-wpzoom-instagram-widget-api.php:294
83
+ msgid "Get items from the Instagram API Feed failed. Malformed data structure."
84
+ msgstr ""
85
+
86
+ #: class-wpzoom-instagram-widget-api.php:298
87
+ msgid "Get user data from the Instagram API Feed failed. Invalid response."
88
+ msgstr ""
89
+
90
+ #: class-wpzoom-instagram-widget-api.php:302
91
+ msgid "Get user data from the Instagram API Feed failed. Malformed data structure."
92
+ msgstr ""
93
+
94
+ #: class-wpzoom-instagram-widget-api.php:436
95
+ msgid "Invalid response from Instagram"
96
+ msgstr ""
97
+
98
+ #: class-wpzoom-instagram-widget-api.php:470
99
+ msgid "Empty json decoded data."
100
+ msgstr ""
101
+
102
+ #: class-wpzoom-instagram-widget-settings.php:27
103
+ msgid "Settings"
104
+ msgstr ""
105
+
106
+ #: class-wpzoom-instagram-widget-settings.php:61
107
+ msgid "User Details (optional)"
108
+ msgstr ""
109
+
110
+ #: class-wpzoom-instagram-widget-settings.php:68
111
+ msgid "Profile Picture"
112
+ msgstr ""
113
+
114
+ #: class-wpzoom-instagram-widget-settings.php:76
115
+ msgid "Your Name"
116
+ msgstr ""
117
+
118
+ #: class-wpzoom-instagram-widget-settings.php:84
119
+ msgid "Bio"
120
+ msgstr ""
121
+
122
+ #: class-wpzoom-instagram-widget-settings.php:92
123
+ msgid "Request Type"
124
+ msgstr ""
125
+
126
+ #: class-wpzoom-instagram-widget-settings.php:113
127
+ msgid "Access Token"
128
+ msgstr ""
129
+
130
+ #: class-wpzoom-instagram-widget-settings.php:131
131
+ msgid "Username"
132
+ msgstr ""
133
+
134
+ #: class-wpzoom-instagram-widget-settings.php:140
135
+ msgid "Check for new posts every"
136
+ msgstr ""
137
+
138
+ #: class-wpzoom-instagram-widget-settings.php:148
139
+ msgid "Enable request timeout"
140
+ msgstr ""
141
+
142
+ #: class-wpzoom-instagram-widget-settings.php:156
143
+ #: class-wpzoom-instagram-widget-settings.php:165
144
+ msgid "Request timeout in seconds"
145
+ msgstr ""
146
+
147
+ #: class-wpzoom-instagram-widget-settings.php:190
148
+ msgid ""
149
+ "Using this method, you will be prompted to authorize the plugin to access "
150
+ "your Instagram photos. The widget will automatically display the latest "
151
+ "photos of the account which was authorized on this page."
152
+ msgstr ""
153
+
154
+ #: class-wpzoom-instagram-widget-settings.php:191
155
+ msgid ""
156
+ "Access tokens are valid for <u>60 days</u>. If the widget stops working, "
157
+ "please generate a new Access Token below."
158
+ msgstr ""
159
+
160
+ #: class-wpzoom-instagram-widget-settings.php:197
161
+ msgid "Connect with Instagram"
162
+ msgstr ""
163
+
164
+ #: class-wpzoom-instagram-widget-settings.php:199
165
+ msgid "Re-connect with Instagram"
166
+ msgstr ""
167
+
168
+ #: class-wpzoom-instagram-widget-settings.php:222
169
+ msgid "Hours"
170
+ msgstr ""
171
+
172
+ #: class-wpzoom-instagram-widget-settings.php:224
173
+ msgid "Days"
174
+ msgstr ""
175
+
176
+ #: class-wpzoom-instagram-widget-settings.php:226
177
+ msgid "Minutes"
178
+ msgstr ""
179
+
180
+ #: class-wpzoom-instagram-widget-settings.php:258
181
+ msgid ""
182
+ "The default timeout to get your Instagram feed is 15 seconds, but on some "
183
+ "servers, this might not be enough time. Enter a higher value like 30 "
184
+ "(seconds) and save changes to see if there is a difference."
185
+ msgstr ""
186
+
187
+ #: class-wpzoom-instagram-widget-settings.php:273
188
+ msgid ""
189
+ "The Instagram Access Token is a long string of characters unique to your "
190
+ "account that grants other applications access to your Instagram feed. You "
191
+ "can also get it manually from <a href=\"%1$s\">here</a>."
192
+ msgstr ""
193
+
194
+ #: class-wpzoom-instagram-widget-settings.php:286
195
+ msgid ""
196
+ "<strong style=\"color:#e44;\">This method is no longer supported by "
197
+ "Instagram and it will be soon deprecated.</strong>"
198
+ msgstr ""
199
+
200
+ #: class-wpzoom-instagram-widget-settings.php:287
201
+ msgid ""
202
+ "Using this method, a public feed, limited to <strong>12 photos</strong>, "
203
+ "will be displayed in the widget.<br/>This option is useful if you want to "
204
+ "display the feed of an Instagram account which you don't own or you have "
205
+ "troubles getting your Access Token."
206
+ msgstr ""
207
+
208
+ #: class-wpzoom-instagram-widget-settings.php:295
209
+ msgid ""
210
+ "Below you can add additional details which you can display in the header of "
211
+ "the Instagram Widget."
212
+ msgstr ""
213
+
214
+ #: class-wpzoom-instagram-widget-settings.php:311
215
+ msgid ""
216
+ "The username entered here will be used in the Instagram feed, unless a "
217
+ "different username will be entered in the widget settings."
218
+ msgstr ""
219
+
220
+ #: class-wpzoom-instagram-widget-settings.php:335
221
+ msgid "With Access Token (Instagram API)"
222
+ msgstr ""
223
+
224
+ #: class-wpzoom-instagram-widget-settings.php:346
225
+ msgid "Public Feed (12 photos)"
226
+ msgstr ""
227
+
228
+ #: class-wpzoom-instagram-widget-settings.php:373
229
+ #: class-wpzoom-instagram-widget-settings.php:377
230
+ msgid "Upload a picture"
231
+ msgstr ""
232
+
233
+ #: class-wpzoom-instagram-widget-settings.php:374
234
+ msgid "Replace Profile Picture"
235
+ msgstr ""
236
+
237
+ #: class-wpzoom-instagram-widget-settings.php:380
238
+ msgid "Remove Profile Picture"
239
+ msgstr ""
240
+
241
+ #: class-wpzoom-instagram-widget-settings.php:407
242
+ #: class-wpzoom-instagram-widget.php:23
243
+ msgid "Instagram Widget by WPZOOM"
244
+ msgstr ""
245
+
246
+ #: class-wpzoom-instagram-widget-settings.php:411
247
+ msgid "Connect your Instagram account"
248
+ msgstr ""
249
+
250
+ #: class-wpzoom-instagram-widget-settings.php:413
251
+ msgid ""
252
+ "To get started, select an option below. If you want to show <strong>your "
253
+ "own feed</strong>, use the first option. If you want to show the feed of an "
254
+ "Instagram account which you don't own, use the option <strong>Public "
255
+ "Feed</strong>."
256
+ msgstr ""
257
+
258
+ #: class-wpzoom-instagram-widget-settings.php:429
259
+ msgid "Premium WordPress Themes by WPZOOM"
260
+ msgstr ""
261
+
262
+ #: class-wpzoom-instagram-widget-settings.php:431
263
+ msgid ""
264
+ "Are you looking to give your website a new look?<br/> Check out our "
265
+ "collection of <strong>35 expertly-crafted themes</strong> and find the "
266
+ "perfect one for your needs!"
267
+ msgstr ""
268
+
269
+ #: class-wpzoom-instagram-widget-settings.php:433
270
+ msgid "Check out our Themes &rarr;"
271
+ msgstr ""
272
+
273
+ #: class-wpzoom-instagram-widget-settings.php:453
274
+ msgid ""
275
+ "Instagram Widget is already connected to Instagram.\r\n"
276
+ "\r\n"
277
+ "Do you want to connect again?"
278
+ msgstr ""
279
+
280
+ #: class-wpzoom-instagram-widget-settings.php:468
281
+ msgid ""
282
+ "Provided Access Token expired. Please connect the plugin with your "
283
+ "Instagram account again."
284
+ msgstr ""
285
+
286
+ #: class-wpzoom-instagram-widget.php:26
287
+ msgid "Displays a user's Instagram timeline."
288
+ msgstr ""
289
+
290
+ #: class-wpzoom-instagram-widget.php:31
291
+ msgid "Instagram"
292
+ msgstr ""
293
+
294
+ #: class-wpzoom-instagram-widget.php:32
295
+ msgid "View on Instagram"
296
+ msgstr ""
297
+
298
+ #: class-wpzoom-instagram-widget.php:174
299
+ msgid ""
300
+ "Instagram Widget misconfigured or your Access Token "
301
+ "<strong>expired</strong>. Please check"
302
+ msgstr ""
303
+
304
+ #: class-wpzoom-instagram-widget.php:175
305
+ msgid "Instagram Settings Page"
306
+ msgstr ""
307
+
308
+ #: class-wpzoom-instagram-widget.php:175
309
+ msgid "and make sure the plugin is properly configured"
310
+ msgstr ""
311
+
312
+ #: class-wpzoom-instagram-widget.php:220
313
+ msgid "Follow"
314
+ msgstr ""
315
+
316
+ #: class-wpzoom-instagram-widget.php:232
317
+ msgid "posts"
318
+ msgstr ""
319
+
320
+ #: class-wpzoom-instagram-widget.php:243
321
+ msgid "followers"
322
+ msgstr ""
323
+
324
+ #: class-wpzoom-instagram-widget.php:254
325
+ msgid "following"
326
+ msgstr ""
327
+
328
+ #: class-wpzoom-instagram-widget.php:483
329
+ msgid ""
330
+ "You need to configure <a href=\"%1$s\">plugin settings</a> before using "
331
+ "this widget."
332
+ msgstr ""
333
+
334
+ #: class-wpzoom-instagram-widget.php:492
335
+ msgid "Title:"
336
+ msgstr ""
337
+
338
+ #: class-wpzoom-instagram-widget.php:500
339
+ msgid "Number of Images Shown:"
340
+ msgstr ""
341
+
342
+ #: class-wpzoom-instagram-widget.php:507
343
+ msgid "Desired number of Images per row:"
344
+ msgstr ""
345
+
346
+ #: class-wpzoom-instagram-widget.php:514
347
+ msgid "Desired Image width in pixels:"
348
+ msgstr ""
349
+
350
+ #: class-wpzoom-instagram-widget.php:523
351
+ msgid "Force image resolution:"
352
+ msgstr ""
353
+
354
+ #: class-wpzoom-instagram-widget.php:527
355
+ msgid "By Default Algorithm"
356
+ msgstr ""
357
+
358
+ #: class-wpzoom-instagram-widget.php:530
359
+ msgid "Thumbnail ( 150x150px )"
360
+ msgstr ""
361
+
362
+ #: class-wpzoom-instagram-widget.php:533
363
+ msgid "Low Resolution ( 320x320px )"
364
+ msgstr ""
365
+
366
+ #: class-wpzoom-instagram-widget.php:537
367
+ msgid "Standard Resolution ( 640x640px )"
368
+ msgstr ""
369
+
370
+ #: class-wpzoom-instagram-widget.php:543
371
+ msgid "Image spacing in pixels:"
372
+ msgstr ""
373
+
374
+ #: class-wpzoom-instagram-widget.php:554
375
+ msgid ""
376
+ "Fields above do not influence directly widget appearance. Final number of "
377
+ "images per row and image width is calculated depending on browser "
378
+ "resolution. This ensures your photos look beautiful on all devices."
379
+ msgstr ""
380
+
381
+ #: class-wpzoom-instagram-widget.php:560
382
+ msgid "Instagram @username:"
383
+ msgstr ""
384
+
385
+ #: class-wpzoom-instagram-widget.php:570
386
+ msgid ""
387
+ "If you have already connected your Instagram account in the <a "
388
+ "href=\"%1$s\">plugin settings</a>, leave this field empty. You can use this "
389
+ "option if you want to display the feed of a different Instagram account."
390
+ msgstr ""
391
+
392
+ #: class-wpzoom-instagram-widget.php:581
393
+ msgid " Display <strong>User Details</strong>"
394
+ msgstr ""
395
+
396
+ #: class-wpzoom-instagram-widget.php:588
397
+ msgid " Display <strong>Bio in User Details</strong>"
398
+ msgstr ""
399
+
400
+ #: class-wpzoom-instagram-widget.php:595
401
+ msgid " Display <strong>View on Instagram</strong> button"
402
+ msgstr ""
403
+
404
+ #: class-wpzoom-instagram-widget.php:602
405
+ msgid " Show <strong>overlay with Instagram icon</strong> on hover"
406
+ msgstr ""
407
+
408
+ #: class-wpzoom-instagram-widget.php:609
409
+ msgid "Lazy Load <strong>images</strong>"
410
+ msgstr ""
411
+
412
+ #: class-wpzoom-instagram-widget.php:615
413
+ msgid "Hide video <strong>thumbnails</strong>"
414
+ msgstr ""
415
+
416
+ #: class-wpzoom-instagram-widget.php:621
417
+ msgid "Show <strong>media type icons</strong>"
418
+ msgstr ""
419
+
420
+ #: class-wpzoom-instagram-widget.php:624
421
+ msgid "Button Text:"
422
+ msgstr ""
423
+
424
+ #: instagram-widget-by-wpzoom.php:63
425
+ msgid "Please configure Instagram Widget"
426
+ msgstr ""
427
+
428
+ #: instagram-widget-by-wpzoom.php:64
429
+ msgid ""
430
+ "If you have just installed or updated this plugin, please go to the %1$s "
431
+ "and %2$s it with your Instagram account."
432
+ msgstr ""
433
+
434
+ #: instagram-widget-by-wpzoom.php:64
435
+ msgid "Settings page"
436
+ msgstr ""
437
+
438
+ #: instagram-widget-by-wpzoom.php:64
439
+ msgid "connect"
440
+ msgstr ""
441
+
442
+ #: instagram-widget-by-wpzoom.php:65
443
+ msgid "You can ignore this message if you have already configured it."
444
+ msgstr ""
445
+
446
+ #. Plugin Name of the plugin/theme
447
+ msgid "WPZOOM Instagram Widget"
448
+ msgstr ""
449
+
450
+ #. Plugin URI of the plugin/theme
451
+ msgid "https://www.wpzoom.com/plugins/instagram-widget/"
452
+ msgstr ""
453
+
454
+ #. Description of the plugin/theme
455
+ msgid "Simple and lightweight widget for WordPress to display your Instagram feed"
456
+ msgstr ""
457
+
458
+ #. Author of the plugin/theme
459
+ msgid "WPZOOM"
460
+ msgstr ""
461
+
462
+ #. Author URI of the plugin/theme
463
+ msgid "https://www.wpzoom.com/"
464
+ msgstr ""
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WPZOOM Social Feed Widget ===
2
  Contributors: WPZOOM, nvartolomei, ciorici
3
  Donate link: https://www.wpzoom.com/
4
- Tags: instagram, widget, timeline, social network, latest images, feed, instagram feed, story, stories, insta, instagram widget
5
  Requires at least: 4.3
6
- Tested up to: 5.5
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
@@ -67,6 +67,27 @@ Make sure to connect your Instagram account with the plugin. You can do that in
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  = 1.6.4 =
71
  * Minor bug fixes for PHP 7.4
72
 
1
  === WPZOOM Social Feed Widget ===
2
  Contributors: WPZOOM, nvartolomei, ciorici
3
  Donate link: https://www.wpzoom.com/
4
+ Tags: instagram, instagram feed, instagram gallery, instagram photos, instagram widget, instagram stories, widget, timeline, social network, latest images, feed, story, stories, insta
5
  Requires at least: 4.3
6
+ Tested up to: 5.7
7
  Requires PHP: 5.6
8
  Stable tag: trunk
9
  License: GPLv2 or later
67
 
68
  == Changelog ==
69
 
70
+ = 1.7.5 =
71
+ * Fixed strings text domain
72
+ * Fixed dismiss url for admin notice
73
+ * Added Text Domain and Domain Path to plugin description
74
+
75
+ = 1.7.4 =
76
+ * Added the "nofollow" parameter to all links from the widget.
77
+ * Fixing issues with thumbnails that were deleted by third-party plugins.
78
+
79
+ = 1.7.3 =
80
+ * Multiple improvements and bug fixes
81
+
82
+ = 1.7.2 =
83
+ * Fixing issues with images not loading on specific websites
84
+
85
+ = 1.7.1 =
86
+ * Minor bug fixes
87
+
88
+ = 1.7.0 =
89
+ * Added support for the new Facebook oEmbed endpoints due to deprecation of the old Instagram oEmbed on October 24, 2020.
90
+
91
  = 1.6.4 =
92
  * Minor bug fixes for PHP 7.4
93