Rara One Click Demo Import - Version 1.2.6

Version Description

  • UPLOAD BUTTON ISSUE FIXED
Download this release

Release Info

Developer raratheme
Plugin Icon 128x128 Rara One Click Demo Import
Version 1.2.6
Comparing to
See all releases

Code changes from version 1.2.5 to 1.2.6

LICENSE.txt CHANGED
@@ -1,339 +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.
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.
assets/css/style.css CHANGED
@@ -1,172 +1,172 @@
1
- /* Overriding WordPress native styles */
2
-
3
- .rrdi h2 {
4
- text-align: inherit;
5
- }
6
-
7
- .rrdi h2:first-child,
8
- .rrdi h3:first-child {
9
- margin-top: 0;
10
- }
11
-
12
- .rrdi hr {
13
- margin: 2.62em 0;
14
- }
15
-
16
- .feature-section + hr {
17
- margin-top: 0;
18
- }
19
-
20
- #wpbody select {
21
- height: auto;
22
- padding: .62em;
23
- line-height: inherit;
24
- }
25
-
26
- .rrdi .notice {
27
- display: block !important;
28
- margin-top: 1.4em;
29
- margin-bottom: 0;
30
- }
31
-
32
- /* Plugin elements */
33
-
34
- .RRDI__demo-import-files {
35
- width: 100%;
36
- }
37
-
38
- .RRDI__demo-import-preview-image-message {
39
- font-style: italic;
40
- }
41
-
42
- /* Plugin title */
43
-
44
- .RRDI__title:before {
45
- width: auto;
46
- height: auto;
47
- font-size: inherit;
48
- }
49
-
50
- /* Plugin intro text */
51
-
52
- .RRDI__intro-text ul {
53
- padding: 0 4%;
54
- list-style-type: square;
55
- }
56
-
57
- /* Plugin multi select import and Plugin file upload containers */
58
-
59
- .RRDI__file-upload,
60
- .RRDI__multi-select-import,
61
- .RRDI__demo-import-notice:not(:empty) {
62
- padding: 4%;
63
- margin: 1.62em 0;
64
- background-color: #ffffff;
65
- border: 1px solid #e5e5e5;
66
- }
67
-
68
- .RRDI__file-upload {
69
- margin: 0;
70
- margin-bottom: -1px;
71
- }
72
-
73
- .RRDI__file-upload span {
74
- font-size: .81em;
75
- font-weight: normal;
76
- opacity: .66;
77
- }
78
-
79
- .RRDI__demo-import-notice:not(:empty) {
80
- border: 0;
81
- border-left: 4px solid #00a0d2;
82
- -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
83
- box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
84
- }
85
-
86
- [dir="rtl"] .RRDI__demo-import-notice:not(:empty) {
87
- border: 0;
88
- border-right: 4px solid #00a0d2;
89
- }
90
-
91
- /* Plugin button */
92
-
93
- .RRDI__button-container {
94
- margin-top: 1.62em;
95
- }
96
-
97
- /* AJAX loader */
98
-
99
- .RRDI__ajax-loader {
100
- font-size: 1.5em;
101
- display: none;
102
- }
103
-
104
- .RRDI__ajax-loader .spinner {
105
- display: inline-block;
106
- float: none;
107
- visibility: visible;
108
- margin-bottom: 6px;
109
- }
110
-
111
- #tabs-container .tabs-menu{
112
- margin: 0;
113
- padding: 0;
114
- list-style: none;
115
- overflow: hidden;
116
- text-transform: capitalize;
117
- }
118
-
119
- #tabs-container .tabs-menu li{
120
- float: left;
121
- border: 1px solid transparent;
122
- margin: 0;
123
- }
124
-
125
- #tabs-container .tabs-menu li.current{
126
- border: 1px solid #ddd;
127
- background: #fff;
128
- border-bottom: 1px solid transparent;
129
- }
130
-
131
- #tabs-container .tabs-menu li a{
132
- text-decoration: none;
133
- color: #444;
134
- display: block;
135
- padding: 10px 10px 10px;
136
- font-size: 18px;
137
- }
138
-
139
- #tabs-container .tabs-menu li a:focus{
140
- box-shadow: none;
141
- }
142
-
143
- #tabs-container .tab-content{
144
- background: #fff;
145
- padding: 10px .9em;
146
- display: none;
147
- border: 1px solid #ddd;
148
- margin-top: -1px;
149
- }
150
- #Demo_Import li {
151
- line-height: 35px;
152
- }
153
- div#Demo_Import {
154
- font-size: 15px;
155
- }
156
- .home-page-url{
157
- display: none;
158
- }
159
-
160
- .rddi-import-intro p,
161
- .rddi-import-intro{
162
- font-size: 19px;
163
- line-height: 25px;
164
- }
165
-
166
- .rddi-import-intro ul{
167
- list-style: square;
168
- padding-left: 26px;
169
- }
170
- .rddi-import-intro ul li span{
171
- font-weight: 800;
172
}
1
+ /* Overriding WordPress native styles */
2
+
3
+ .rrdi h2 {
4
+ text-align: inherit;
5
+ }
6
+
7
+ .rrdi h2:first-child,
8
+ .rrdi h3:first-child {
9
+ margin-top: 0;
10
+ }
11
+
12
+ .rrdi hr {
13
+ margin: 2.62em 0;
14
+ }
15
+
16
+ .feature-section + hr {
17
+ margin-top: 0;
18
+ }
19
+
20
+ #wpbody select {
21
+ height: auto;
22
+ padding: .62em;
23
+ line-height: inherit;
24
+ }
25
+
26
+ .rrdi .notice {
27
+ display: block !important;
28
+ margin-top: 1.4em;
29
+ margin-bottom: 0;
30
+ }
31
+
32
+ /* Plugin elements */
33
+
34
+ .RRDI__demo-import-files {
35
+ width: 100%;
36
+ }
37
+
38
+ .RRDI__demo-import-preview-image-message {
39
+ font-style: italic;
40
+ }
41
+
42
+ /* Plugin title */
43
+
44
+ .RRDI__title:before {
45
+ width: auto;
46
+ height: auto;
47
+ font-size: inherit;
48
+ }
49
+
50
+ /* Plugin intro text */
51
+
52
+ .RRDI__intro-text ul {
53
+ padding: 0 4%;
54
+ list-style-type: square;
55
+ }
56
+
57
+ /* Plugin multi select import and Plugin file upload containers */
58
+
59
+ .RRDI__file-upload,
60
+ .RRDI__multi-select-import,
61
+ .RRDI__demo-import-notice:not(:empty) {
62
+ padding: 4%;
63
+ margin: 1.62em 0;
64
+ background-color: #ffffff;
65
+ border: 1px solid #e5e5e5;
66
+ }
67
+
68
+ .RRDI__file-upload {
69
+ margin: 0;
70
+ margin-bottom: -1px;
71
+ }
72
+
73
+ .RRDI__file-upload span {
74
+ font-size: .81em;
75
+ font-weight: normal;
76
+ opacity: .66;
77
+ }
78
+
79
+ .RRDI__demo-import-notice:not(:empty) {
80
+ border: 0;
81
+ border-left: 4px solid #00a0d2;
82
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
83
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
84
+ }
85
+
86
+ [dir="rtl"] .RRDI__demo-import-notice:not(:empty) {
87
+ border: 0;
88
+ border-right: 4px solid #00a0d2;
89
+ }
90
+
91
+ /* Plugin button */
92
+
93
+ .RRDI__button-container {
94
+ margin-top: 1.62em;
95
+ }
96
+
97
+ /* AJAX loader */
98
+
99
+ .RRDI__ajax-loader {
100
+ font-size: 1.5em;
101
+ display: none;
102
+ }
103
+
104
+ .RRDI__ajax-loader .spinner {
105
+ display: inline-block;
106
+ float: none;
107
+ visibility: visible;
108
+ margin-bottom: 6px;
109
+ }
110
+
111
+ #tabs-container .tabs-menu{
112
+ margin: 0;
113
+ padding: 0;
114
+ list-style: none;
115
+ overflow: hidden;
116
+ text-transform: capitalize;
117
+ }
118
+
119
+ #tabs-container .tabs-menu li{
120
+ float: left;
121
+ border: 1px solid transparent;
122
+ margin: 0;
123
+ }
124
+
125
+ #tabs-container .tabs-menu li.current{
126
+ border: 1px solid #ddd;
127
+ background: #fff;
128
+ border-bottom: 1px solid transparent;
129
+ }
130
+
131
+ #tabs-container .tabs-menu li a{
132
+ text-decoration: none;
133
+ color: #444;
134
+ display: block;
135
+ padding: 10px 10px 10px;
136
+ font-size: 18px;
137
+ }
138
+
139
+ #tabs-container .tabs-menu li a:focus{
140
+ box-shadow: none;
141
+ }
142
+
143
+ #tabs-container .tab-content{
144
+ background: #fff;
145
+ padding: 10px .9em;
146
+ display: none;
147
+ border: 1px solid #ddd;
148
+ margin-top: -1px;
149
+ }
150
+ #Demo_Import li {
151
+ line-height: 35px;
152
+ }
153
+ div#Demo_Import {
154
+ font-size: 15px;
155
+ }
156
+ .home-page-url{
157
+ display: none;
158
+ }
159
+
160
+ .rddi-import-intro p,
161
+ .rddi-import-intro{
162
+ font-size: 19px;
163
+ line-height: 25px;
164
+ }
165
+
166
+ .rddi-import-intro ul{
167
+ list-style: square;
168
+ padding-left: 26px;
169
+ }
170
+ .rddi-import-intro ul li span{
171
+ font-weight: 800;
172
}
assets/js/script.js CHANGED
@@ -1,113 +1,120 @@
1
- jQuery( function ( $ ) {
2
-
3
- $( '.js-rrdi-import-data' ).on( 'click', function () {
4
- // Reset response div content.
5
- $( '.js-rrdi-ajax-response' ).empty();
6
-
7
- // Prepare data for the AJAX call
8
- var data = new FormData();
9
- data.append( 'action', 'rrdi_import_demo_data' );
10
- data.append( 'security', rrdi.ajax_nonce );
11
- data.append( 'selected', $( '#RRDI__demo-import-files' ).val() );
12
- if ( $('#RRDI__content-file-upload').length ) {
13
- data.append( 'content_file', $('#RRDI__content-file-upload')[0].files[0] );
14
- }
15
- if ( $('#RRDI__widget-file-upload').length ) {
16
- data.append( 'widget_file', $('#RRDI__widget-file-upload')[0].files[0] );
17
- }
18
- if ( $('#RRDI__customizer-file-upload').length ) {
19
- data.append( 'customizer_file', $('#RRDI__customizer-file-upload')[0].files[0] );
20
- }
21
-
22
- // AJAX call to import everything (content, widgets, before/after setup)
23
- ajaxCall( data );
24
-
25
- });
26
-
27
- function ajaxCall( data ) {
28
- $.ajax({
29
- method: 'POST',
30
- url: rrdi.ajax_url,
31
- data: data,
32
- contentType: false,
33
- processData: false,
34
- beforeSend: function() {
35
- $( '.js-rrdi-ajax-loader' ).show();
36
- }
37
- })
38
- .done( function( response ) {
39
-
40
- if ( 'undefined' !== typeof response.status && 'newAJAX' === response.status ) {
41
- ajaxCall( data );
42
- }
43
- else if ( 'undefined' !== typeof response.message ) {
44
- $( '.js-rrdi-ajax-response' ).append( '<p>' + response.message + '</p>' );
45
- $( '.js-rrdi-ajax-loader' ).hide();
46
- $( '.js-rrdi-import-data' ).prop('disabled', true);
47
- $( 'a.demo-importer' ).hide();
48
- $( 'a.home-page-url' ).show();
49
-
50
- }
51
- else {
52
- $( '.js-rrdi-ajax-response' ).append( '<div class="notice notice-error is-dismissible"><p>' + response + '</p></div>' );
53
- $( '.js-rrdi-ajax-loader' ).hide();
54
- $( '.js-rrdi-import-data' ).prop('disabled', true);
55
- $( 'a.demo-importer' ).hide();
56
- $( 'a.home-page-url' ).show();
57
- }
58
- })
59
- .fail( function( error ) {
60
- $( '.js-rrdi-ajax-response' ).append( '<div class="notice notice-error is-dismissible"><p>Error: ' + error.statusText + ' (' + error.status + ')' + '</p></div>' );
61
- $( '.js-rrdi-ajax-loader' ).hide();
62
- $( '.js-rrdi-import-data' ).prop('disabled', true);
63
- });
64
- }
65
-
66
- // Switch preview images on select change event, but only if the img element .js-rrdi-preview-image exists.
67
- // Also switch the import notice (if it exists).
68
- $( '#RRDI__demo-import-files' ).on( 'change', function(){
69
- if ( $( '.js-rrdi-preview-image' ).length ) {
70
-
71
- // Attempt to change the image, else display message for missing image.
72
- var currentFilePreviewImage = rrdi.import_files[ this.value ]['import_preview_image_url'] || '';
73
- $( '.js-rrdi-preview-image' ).prop( 'src', currentFilePreviewImage );
74
- $( '.js-rrdi-preview-image-message' ).html( '' );
75
-
76
- if ( '' === currentFilePreviewImage ) {
77
- $( '.js-rrdi-preview-image-message' ).html( rrdi.texts.missing_preview_image );
78
- }
79
- }
80
-
81
- // Update import notice.
82
- var currentImportNotice = rrdi.import_files[ this.value ]['import_notice'] || '';
83
- $( '.js-rrdi-demo-import-notice' ).html( currentImportNotice );
84
- });
85
-
86
- $('.tabs-menu a').click(function(event) {
87
- event.preventDefault();
88
- $(this).parent().addClass('current');
89
- $(this).parent().siblings().removeClass('current');
90
- var tab = $(this).attr('href');
91
- $('.tab-content').not(tab).css('display', 'none');
92
- $('#'+tab).show();
93
- });
94
-
95
- var uploadViewToggle = $( '.upload-view-toggle' ),
96
- $body = $( document.body );
97
- uploadViewToggle.on( 'click', function() {
98
- // Toggle the upload view.
99
- $body.toggleClass( 'show-upload-view' );
100
- // Toggle the `aria-expanded` button attribute.
101
- uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
102
- });
103
- $('.tabs-menu a').click(function(event) {
104
- if( $(this).attr('href') != 'Demo_Import')
105
- {
106
- $('.upload-view-toggle').hide();
107
- }
108
- else{
109
- $('.upload-view-toggle').show();
110
- }
111
- });
112
-
113
- });
1
+ jQuery( function ( $ ) {
2
+
3
+ $( '.js-rrdi-import-data' ).on( 'click', function () {
4
+ // Reset response div content.
5
+ $( '.js-rrdi-ajax-response' ).empty();
6
+
7
+ // Prepare data for the AJAX call
8
+ var data = new FormData();
9
+ data.append( 'action', 'rrdi_import_demo_data' );
10
+ data.append( 'security', rrdi.ajax_nonce );
11
+ data.append( 'selected', $( '#RRDI__demo-import-files' ).val() );
12
+ if ( $('#RRDI__content-file-upload').length ) {
13
+ data.append( 'content_file', $('#RRDI__content-file-upload')[0].files[0] );
14
+ }
15
+ if ( $('#RRDI__widget-file-upload').length ) {
16
+ data.append( 'widget_file', $('#RRDI__widget-file-upload')[0].files[0] );
17
+ }
18
+ if ( $('#RRDI__customizer-file-upload').length ) {
19
+ data.append( 'customizer_file', $('#RRDI__customizer-file-upload')[0].files[0] );
20
+ }
21
+
22
+ // AJAX call to import everything (content, widgets, before/after setup)
23
+ ajaxCall( data );
24
+
25
+ });
26
+
27
+ function ajaxCall( data ) {
28
+ $.ajax({
29
+ method: 'POST',
30
+ url: rrdi.ajax_url,
31
+ data: data,
32
+ contentType: false,
33
+ processData: false,
34
+ beforeSend: function() {
35
+ $( '.js-rrdi-ajax-loader' ).show();
36
+ }
37
+ })
38
+ .done( function( response ) {
39
+
40
+ if ( 'undefined' !== typeof response.status && 'newAJAX' === response.status ) {
41
+ ajaxCall( data );
42
+ }
43
+ else if ( 'undefined' !== typeof response.message ) {
44
+ $( '.js-rrdi-ajax-response' ).append( '<p>' + response.message + '</p>' );
45
+ $( '.js-rrdi-ajax-loader' ).hide();
46
+ $( '.js-rrdi-import-data' ).prop('disabled', true);
47
+ $( 'a.demo-importer' ).hide();
48
+ $( 'a.home-page-url' ).show();
49
+
50
+ }
51
+ else {
52
+ $( '.js-rrdi-ajax-response' ).append( '<div class="notice notice-error is-dismissible"><p>' + response + '</p></div>' );
53
+ $( '.js-rrdi-ajax-loader' ).hide();
54
+ $( '.js-rrdi-import-data' ).prop('disabled', true);
55
+ $( 'a.demo-importer' ).hide();
56
+ $( 'a.home-page-url' ).show();
57
+ }
58
+ })
59
+ .fail( function( error ) {
60
+ $( '.js-rrdi-ajax-response' ).append( '<div class="notice notice-error is-dismissible"><p>Error: ' + error.statusText + ' (' + error.status + ')' + '</p></div>' );
61
+ $( '.js-rrdi-ajax-loader' ).hide();
62
+ $( '.js-rrdi-import-data' ).prop('disabled', true);
63
+ });
64
+ }
65
+
66
+ // Switch preview images on select change event, but only if the img element .js-rrdi-preview-image exists.
67
+ // Also switch the import notice (if it exists).
68
+ $( '#RRDI__demo-import-files' ).on( 'change', function(){
69
+ if ( $( '.js-rrdi-preview-image' ).length ) {
70
+
71
+ // Attempt to change the image, else display message for missing image.
72
+ var currentFilePreviewImage = rrdi.import_files[ this.value ]['import_preview_image_url'] || '';
73
+ $( '.js-rrdi-preview-image' ).prop( 'src', currentFilePreviewImage );
74
+ $( '.js-rrdi-preview-image-message' ).html( '' );
75
+
76
+ if ( '' === currentFilePreviewImage ) {
77
+ $( '.js-rrdi-preview-image-message' ).html( rrdi.texts.missing_preview_image );
78
+ }
79
+ }
80
+
81
+ // Update import notice.
82
+ var currentImportNotice = rrdi.import_files[ this.value ]['import_notice'] || '';
83
+ $( '.js-rrdi-demo-import-notice' ).html( currentImportNotice );
84
+ });
85
+
86
+ $('.tabs-menu a').click(function(event) {
87
+ event.preventDefault();
88
+ $(this).parent().addClass('current');
89
+ $(this).parent().siblings().removeClass('current');
90
+ var tab = $(this).attr('href');
91
+ $('.tab-content').not(tab).css('display', 'none');
92
+ $('#'+tab).show();
93
+ });
94
+
95
+ var uploadViewToggle = $( '.upload-view-toggle' ),
96
+ $body = $( document.body );
97
+ uploadViewToggle.on( 'click', function() {
98
+ // Toggle the upload view.
99
+ $body.toggleClass( 'show-upload-view' );
100
+ // Toggle the `aria-expanded` button attribute.
101
+ uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
102
+ });
103
+ if( $('.tabs-menu a').attr('href') != 'Demo_Import')
104
+ {
105
+ $('.upload-view-toggle').hide();
106
+ }
107
+ else{
108
+ $('.upload-view-toggle').show();
109
+ }
110
+ $('.tabs-menu a').click(function(event) {
111
+ if( $(this).attr('href') != 'Demo_Import')
112
+ {
113
+ $('.upload-view-toggle').hide();
114
+ }
115
+ else{
116
+ $('.upload-view-toggle').show();
117
+ }
118
+ });
119
+
120
+ });
includes/class-rrdi-customizer-option.php CHANGED
@@ -1,24 +1,24 @@
1
- <?php
2
- /**
3
- * A class that extends WP_Customize_Setting so we can access
4
- * the protected updated method when importing options.
5
- *
6
- * Used in the Customizer importer.
7
- *
8
- * @since 1.0.1
9
- * @package rara-one-click-demo-import
10
- */
11
-
12
- final class RRDI_Customizer_Option extends WP_Customize_Setting {
13
-
14
- /**
15
- * Import an option value for this setting.
16
- *
17
- * @since 1.0.1
18
- * @param mixed $value The option value.
19
- * @return void
20
- */
21
- public function import( $value ) {
22
- $this->update( $value );
23
- }
24
- }
1
+ <?php
2
+ /**
3
+ * A class that extends WP_Customize_Setting so we can access
4
+ * the protected updated method when importing options.
5
+ *
6
+ * Used in the Customizer importer.
7
+ *
8
+ * @since 1.0.1
9
+ * @package rara-one-click-demo-import
10
+ */
11
+
12
+ final class RRDI_Customizer_Option extends WP_Customize_Setting {
13
+
14
+ /**
15
+ * Import an option value for this setting.
16
+ *
17
+ * @since 1.0.1
18
+ * @param mixed $value The option value.
19
+ * @return void
20
+ */
21
+ public function import( $value ) {
22
+ $this->update( $value );
23
+ }
24
+ }
includes/class-rrdi-helpers.php CHANGED
@@ -1,610 +1,610 @@
1
- <?php
2
- /**
3
- * Static functions used in the rrdi plugin.
4
- *
5
- * @package rara-one-click-demo-import
6
- */
7
-
8
- /**
9
- * Class with static helper functions.
10
- */
11
- class RRDI_Helpers {
12
-
13
- /**
14
- * Filter through the array of import files and get rid of those who do not comply.
15
- *
16
- * @param array $import_files list of arrays with import file details.
17
- * @return array list of filtered arrays.
18
- */
19
- public static function validate_import_file_info( $import_files ) {
20
- $filtered_import_file_info = array();
21
-
22
- foreach ( $import_files as $import_file ) {
23
- if ( self::is_import_file_info_format_correct( $import_file ) ) {
24
- $filtered_import_file_info[] = $import_file;
25
- }
26
- }
27
-
28
- return $filtered_import_file_info;
29
- }
30
-
31
-
32
- /**
33
- * Helper function: a simple check for valid import file format.
34
- *
35
- * @param array $import_file_info array with import file details.
36
- * @return boolean
37
- */
38
- private static function is_import_file_info_format_correct( $import_file_info ) {
39
- if ( ( empty( $import_file_info['import_file_url'] ) && empty( $import_file_info['local_import_file'] ) ) || empty( $import_file_info['import_file_name'] ) ) {
40
- return false;
41
- }
42
-
43
- return true;
44
- }
45
-
46
-
47
- /**
48
- * Download import files. Content .xml and widgets .wie|.json files.
49
- *
50
- * @param array $import_file_info array with import file details.
51
- * @param string $start_date string of date and time.
52
- * @return array|WP_Error array of paths to the downloaded files or WP_Error object with error message.
53
- */
54
- public static function download_import_files( $import_file_info, $start_date = '' ) {
55
-
56
- $downloaded_files = array();
57
- $upload_dir = wp_upload_dir();
58
- $upload_path = apply_filters( 'rrdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
59
-
60
- // ----- Set content file path -----
61
- // Check if 'import_file_url' is not defined. That would mean a local file.
62
- if ( empty( $import_file_info['import_file_url'] ) ) {
63
- if ( file_exists( $import_file_info['local_import_file'] ) ) {
64
- $downloaded_files['content'] = $import_file_info['local_import_file'];
65
- }
66
- else {
67
- return new WP_Error(
68
- 'url_or_local_file_not_defined',
69
- sprintf(
70
- __( '"import_file_url" or "local_import_file" for %s%s%s are not defined!', 'rara-one-click-demo-import' ),
71
- '<strong>',
72
- $import_file_info['import_file_name'],
73
- '</strong>'
74
- )
75
- );
76
- }
77
- }
78
- else {
79
-
80
- // Retrieve demo data content from the URL.
81
- $demo_import_content = self::get_content_from_url( $import_file_info['import_file_url'], $import_file_info['import_file_name'] );
82
-
83
- // Return from this function if there was an error.
84
- if ( is_wp_error( $demo_import_content ) ) {
85
- return $demo_import_content;
86
- }
87
-
88
- // Setup filename path to save the data content.
89
- $demo_import_file_path = $upload_path . apply_filters( 'rrdi/downloaded_content_file_prefix', 'demo-content-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_content_file_suffix_and_file_extension', '.xml' );
90
-
91
- // Write data content to the file and return the file path on successful write.
92
- $downloaded_files['content'] = self::write_to_file( $demo_import_content, $demo_import_file_path );
93
-
94
- // Return from this function if there was an error.
95
- if ( is_wp_error( $downloaded_files['content'] ) ) {
96
- return $downloaded_files['content'];
97
- }
98
- }
99
-
100
- // ----- Set widget file path -----
101
- // Get widgets file as well. If defined!
102
- if ( ! empty( $import_file_info['import_widget_file_url'] ) ) {
103
-
104
- // Retrieve widget content from the URL.
105
- $demo_import_widgets_content = self::get_content_from_url( $import_file_info['import_widget_file_url'], $import_file_info['import_file_name'] );
106
-
107
- // Return from this function if there was an error.
108
- if ( is_wp_error( $demo_import_widgets_content ) ) {
109
- return $demo_import_widgets_content;
110
- }
111
-
112
- // Setup filename path to save the widget content.
113
- $import_widgets_file_path = $upload_path . apply_filters( 'rrdi/downloaded_widgets_file_prefix', 'demo-widgets-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_widgets_file_suffix_and_file_extension', '.json' );
114
-
115
- // Write widget content to the file and return the file path on successful write.
116
- $downloaded_files['widgets'] = self::write_to_file( $demo_import_widgets_content, $import_widgets_file_path );
117
-
118
- // Return from this function if there was an error.
119
- if ( is_wp_error( $downloaded_files['widgets'] ) ) {
120
- return $downloaded_files['widgets'];
121
- }
122
- }
123
- else if ( ! empty( $import_file_info['local_import_widget_file'] ) ) {
124
- if ( file_exists( $import_file_info['local_import_widget_file'] ) ) {
125
- $downloaded_files['widgets'] = $import_file_info['local_import_widget_file'];
126
- }
127
- }
128
-
129
- // ----- Set customizer file path -----
130
- // Get customizer import file as well. If defined!
131
- if ( ! empty( $import_file_info['import_customizer_file_url'] ) ) {
132
-
133
- // Retrieve customizer content from the URL.
134
- $demo_import_customizer_content = self::get_content_from_url( $import_file_info['import_customizer_file_url'], $import_file_info['import_file_name'] );
135
-
136
- // Return from this function if there was an error.
137
- if ( is_wp_error( $demo_import_customizer_content ) ) {
138
- return $demo_import_customizer_content;
139
- }
140
-
141
- // Setup filename path to save the customizer content.
142
- $import_customizer_file_path = $upload_path . apply_filters( 'rrdi/downloaded_customizer_file_prefix', 'demo-customizer-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_customizer_file_suffix_and_file_extension', '.dat' );
143
-
144
- // Write customizer content to the file and return the file path on successful write.
145
- $downloaded_files['customizer'] = self::write_to_file( $demo_import_customizer_content, $import_customizer_file_path );
146
-
147
- // Return from this function if there was an error.
148
- if ( is_wp_error( $downloaded_files['customizer'] ) ) {
149
- return $downloaded_files['customizer'];
150
- }
151
- }
152
- else if ( ! empty( $import_file_info['local_import_customizer_file'] ) ) {
153
- if ( file_exists( $import_file_info['local_import_customizer_file'] ) ) {
154
- $downloaded_files['customizer'] = $import_file_info['local_import_customizer_file'];
155
- }
156
- }
157
-
158
- return $downloaded_files;
159
- }
160
-
161
-
162
- /**
163
- * Helper function: get content from an url.
164
- *
165
- * @param string $url URL to the content file.
166
- * @param string $file_name optional, name of the file (used in the error reports).
167
- * @return string|WP_Error, content from the URL or WP_Error object with error message
168
- */
169
- private static function get_content_from_url( $url, $file_name = 'Import file' ) {
170
-
171
- // Test if the URL to the file is defined.
172
- if ( empty( $url ) ) {
173
- return new WP_Error(
174
- 'url_not_defined',
175
- sprintf(
176
- __( 'URL for %s%s%s file is not defined!', 'rara-one-click-demo-import' ),
177
- '<strong>',
178
- $file_name,
179
- '</strong>'
180
- )
181
- );
182
- }
183
-
184
- // Get file content from the server.
185
- $response = wp_remote_get(
186
- $url,
187
- array( 'timeout' => apply_filters( 'rrdi/timeout_for_downloading_import_file', 20 ) )
188
- );
189
-
190
- if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
191
-
192
- // Collect the right format of error data (array or WP_Error).
193
- $response_error = self::get_error_from_response( $response );
194
-
195
- return new WP_Error(
196
- 'file_fetching_error',
197
- sprintf(
198
- __( 'An error occurred while fetching %s%s%s file from the server!%sReason: %s - %s.', 'rara-one-click-demo-import' ),
199
- '<strong>',
200
- $file_name,
201
- '</strong>',
202
- '<br>',
203
- $response_error['error_code'],
204
- $response_error['error_message']
205
- ) . '<br>' .
206
- apply_filters( 'rrdi/message_after_file_fetching_error', '' )
207
- );
208
- }
209
-
210
- // Return content retrieved from the URL.
211
- return wp_remote_retrieve_body( $response );
212
- }
213
-
214
-
215
- /**
216
- * Write content to a file.
217
- *
218
- * @param string $content content to be saved to the file.
219
- * @param string $file_path file path where the content should be saved.
220
- * @return string|WP_Error path to the saved file or WP_Error object with error message.
221
- */
222
- public static function write_to_file( $content, $file_path ) {
223
-
224
- // Verify WP file-system credentials.
225
- $verified_credentials = self::check_wp_filesystem_credentials();
226
-
227
- if ( is_wp_error( $verified_credentials ) ) {
228
- return $verified_credentials;
229
- }
230
-
231
- // By this point, the $wp_filesystem global should be working, so let's use it to create a file.
232
- global $wp_filesystem;
233
-
234
- if ( ! $wp_filesystem->put_contents( $file_path, $content ) ) {
235
- return new WP_Error(
236
- 'failed_writing_file_to_server',
237
- sprintf(
238
- __( 'An error occurred while writing file to your server! Tried to write a file to: %s%s.', 'rara-one-click-demo-import' ),
239
- '<br>',
240
- $file_path
241
- )
242
- );
243
- }
244
-
245
- // Return the file path on successful file write.
246
- return $file_path;
247
- }
248
-
249
-
250
- /**
251
- * Append content to the file.
252
- *
253
- * @param string $content content to be saved to the file.
254
- * @param string $file_path file path where the content should be saved.
255
- * @param string $separator_text separates the existing content of the file with the new content.
256
- * @return boolean|WP_Error, path to the saved file or WP_Error object with error message.
257
- */
258
- public static function append_to_file( $content, $file_path, $separator_text = '' ) {
259
-
260
- // Verify WP file-system credentials.
261
- $verified_credentials = self::check_wp_filesystem_credentials();
262
-
263
- if ( is_wp_error( $verified_credentials ) ) {
264
- return $verified_credentials;
265
- }
266
-
267
- // By this point, the $wp_filesystem global should be working, so let's use it to create a file.
268
- global $wp_filesystem;
269
-
270
- $existing_data = '';
271
- if ( file_exists( $file_path ) ) {
272
- $existing_data = $wp_filesystem->get_contents( $file_path );
273
- }
274
-
275
- // Style separator.
276
- $separator = PHP_EOL . '---' . $separator_text . '---' . PHP_EOL;
277
-
278
- if ( ! $wp_filesystem->put_contents( $file_path, $existing_data . $separator . $content . PHP_EOL ) ) {
279
- return new WP_Error(
280
- 'failed_writing_file_to_server',
281
- sprintf(
282
- __( 'An error occurred while writing file to your server! Tried to write a file to: %s%s.', 'rara-one-click-demo-import' ),
283
- '<br>',
284
- $file_path
285
- )
286
- );
287
- }
288
-
289
- return true;
290
- }
291
-
292
-
293
- /**
294
- * Get data from a file
295
- *
296
- * @param string $file_path file path where the content should be saved.
297
- * @return string $data, content of the file or WP_Error object with error message.
298
- */
299
- public static function data_from_file( $file_path ) {
300
-
301
- // Verify WP file-system credentials.
302
- $verified_credentials = self::check_wp_filesystem_credentials();
303
-
304
- if ( is_wp_error( $verified_credentials ) ) {
305
- return $verified_credentials;
306
- }
307
-
308
- // By this point, the $wp_filesystem global should be working, so let's use it to read a file.
309
- global $wp_filesystem;
310
-
311
- $data = $wp_filesystem->get_contents( $file_path );
312
-
313
- if ( ! $data ) {
314
- return new WP_Error(
315
- 'failed_reading_file_from_server',
316
- sprintf(
317
- __( 'An error occurred while reading a file from your server! Tried reading file from path: %s%s.', 'rara-one-click-demo-import' ),
318
- '<br>',
319
- $file_path
320
- )
321
- );
322
- }
323
-
324
- // Return the file data.
325
- return $data;
326
- }
327
-
328
-
329
- /**
330
- * Helper function: check for WP file-system credentials needed for reading and writing to a file.
331
- *
332
- * @return boolean|WP_Error
333
- */
334
- private static function check_wp_filesystem_credentials() {
335
-
336
- // Check if the file-system method is 'direct', if not display an error.
337
- if ( ! ( 'direct' === get_filesystem_method() ) ) {
338
- return new WP_Error(
339
- 'no_direct_file_access',
340
- sprintf(
341
- __( 'This WordPress page does not have %sdirect%s write file access. This plugin needs it in order to save the demo import xml file to the upload directory of your site. You can change this setting with these instructions: %s.', 'rara-one-click-demo-import' ),
342
- '<strong>',
343
- '</strong>',
344
- '<a href="http://gregorcapuder.com/wordpress-how-to-set-direct-filesystem-method/" target="_blank">How to set <strong>direct</strong> filesystem method</a>'
345
- )
346
- );
347
- }
348
-
349
- // Get plugin page settings.
350
- $plugin_page_setup = apply_filters( 'rrdi/plugin_page_setup', array(
351
- 'parent_slug' => 'themes.php',
352
- 'page_title' => esc_html__( 'Rara One Click Demo Import' , 'rara-one-click-demo-import' ),
353
- 'menu_title' => esc_html__( 'Rara Demo Import' , 'rara-one-click-demo-import' ),
354
- 'capability' => 'import',
355
- 'menu_slug' => 'rara-demo-import',
356
- )
357
- );
358
-
359
- // Get user credentials for WP file-system API.
360
- $demo_import_page_url = wp_nonce_url( $plugin_page_setup['parent_slug'] . '?page=' . $plugin_page_setup['menu_slug'], $plugin_page_setup['menu_slug'] );
361
-
362
- if ( false === ( $creds = request_filesystem_credentials( $demo_import_page_url, '', false, false, null ) ) ) {
363
- return new WP_error(
364
- 'filesystem_credentials_could_not_be_retrieved',
365
- __( 'An error occurred while retrieving reading/writing permissions to your server (could not retrieve WP filesystem credentials)!', 'rara-one-click-demo-import' )
366
- );
367
- }
368
-
369
- // Now we have credentials, try to get the wp_filesystem running.
370
- if ( ! WP_Filesystem( $creds ) ) {
371
- return new WP_Error(
372
- 'wrong_login_credentials',
373
- __( 'Your WordPress login credentials don\'t allow to use WP_Filesystem!', 'rara-one-click-demo-import' )
374
- );
375
- }
376
-
377
- return true;
378
- }
379
-
380
-
381
- /**
382
- * Helper function: get the right format of response errors
383
- *
384
- * @param array|WP_Error $response array or WP_Error.
385
- * @return array, with error code and error message.
386
- */
387
- private static function get_error_from_response( $response ) {
388
- $response_error = array();
389
-
390
- if ( is_array( $response ) ) {
391
- $response_error['error_code'] = $response['response']['code'];
392
- $response_error['error_message'] = $response['response']['message'];
393
- }
394
- else {
395
- $response_error['error_code'] = $response->get_error_code();
396
- $response_error['error_message'] = $response->get_error_message();
397
- }
398
-
399
- return $response_error;
400
- }
401
-
402
-
403
- /**
404
- * Get log file path
405
- *
406
- * @param string $start_date date|time|timestamp to use in the log filename.
407
- * @return string, path to the log file
408
- */
409
- public static function get_log_path( $start_date = '' ) {
410
-
411
- $upload_dir = wp_upload_dir();
412
- $upload_path = apply_filters( 'rrdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
413
-
414
- $log_path = $upload_path . apply_filters( 'rrdi/log_file_prefix', 'log_file_' ) . $start_date . apply_filters( 'rrdi/log_file_suffix_and_file_extension', '.txt' );
415
-
416
- self::register_file_as_media_attachment( $log_path );
417
-
418
- return $log_path;
419
- }
420
-
421
-
422
- /**
423
- * Register file as attachment to the Media page.
424
- *
425
- * @param string $log_path log file path.
426
- * @return void
427
- */
428
- public static function register_file_as_media_attachment( $log_path ) {
429
-
430
- // Check the type of file.
431
- $log_mimes = array( 'txt' => 'text/plain' );
432
- $filetype = wp_check_filetype( basename( $log_path ), apply_filters( 'rrdi/file_mimes', $log_mimes ) );
433
-
434
- // Prepare an array of post data for the attachment.
435
- $attachment = array(
436
- 'guid' => self::get_log_url( $log_path ),
437
- 'post_mime_type' => $filetype['type'],
438
- 'post_title' => apply_filters( 'rrdi/attachment_prefix', esc_html__( 'Rara One Click Demo Import - ', 'rara-one-click-demo-import' ) ) . preg_replace( '/\.[^.]+#x2F;', '', basename( $log_path ) ),
439
- 'post_content' => '',
440
- 'post_status' => 'inherit',
441
- );
442
-
443
- // Insert the file as attachment in Media page.
444
- $attach_id = wp_insert_attachment( $attachment, $log_path );
445
- }
446
-
447
-
448
- /**
449
- * Get log file url
450
- *
451
- * @param string $log_path log path to use for the log filename.
452
- * @return string, url to the log file.
453
- */
454
- public static function get_log_url( $log_path ) {
455
-
456
- $upload_dir = wp_upload_dir();
457
- $upload_url = apply_filters( 'rrdi/upload_file_url', trailingslashit( $upload_dir['url'] ) );
458
-
459
- return $upload_url . basename( $log_path );
460
- }
461
-
462
-
463
- /**
464
- * Check if the AJAX call is valid.
465
- */
466
- public static function verify_ajax_call() {
467
-
468
- check_ajax_referer( 'rrdi-ajax-verification', 'security' );
469
-
470
- // Check if user has the WP capability to import data.
471
- if ( ! current_user_can( 'import' ) ) {
472
- wp_die(
473
- sprintf(
474
- __( '%sYour user role isn\'t high enough. You don\'t have permission to import demo data.%s', 'rara-one-click-demo-import' ),
475
- '<div class="notice notice-error"><p>',
476
- '</p></div>'
477
- )
478
- );
479
- }
480
- }
481
-
482
-
483
- /**
484
- * Process uploaded files and return the paths to these files.
485
- *
486
- * @param array $uploaded_files $_FILES array form an AJAX request.
487
- * @param string $log_file_path path to the log file.
488
- * @return array of paths to the content import and widget import files.
489
- */
490
- public static function process_uploaded_files( $uploaded_files, $log_file_path ) {
491
-
492
- // Variable holding the paths to the uploaded files.
493
- $selected_import_files = array();
494
-
495
- // Upload settings to disable form and type testing for AJAX uploads.
496
- $upload_overrides = array(
497
- 'test_form' => false,
498
- 'test_type' => false,
499
- );
500
-
501
- // Handle demo content and widgets file upload.
502
- $content_file_info = wp_handle_upload( $_FILES['content_file'], $upload_overrides );
503
- $widget_file_info = wp_handle_upload( $_FILES['widget_file'], $upload_overrides );
504
- $customizer_file_info = wp_handle_upload( $_FILES['customizer_file'], $upload_overrides );
505
-
506
- if ( empty( $content_file_info['file'] ) || isset( $content_file_info['error'] ) ) {
507
-
508
- // Write error to log file and send an AJAX response with the error.
509
- self::log_error_and_send_ajax_response(
510
- __( 'Please upload XML file for content import. If you want to import widgets or customizer settings only, please use Widget Importer & Exporter or the Customizer Export/Import plugin.', 'rara-one-click-demo-import' ),
511
- $log_file_path,
512
- esc_html__( 'Upload files', 'rara-one-click-demo-import' )
513
- );
514
- }
515
-
516
- // Set uploaded content file.
517
- $selected_import_files['content'] = $content_file_info['file'];
518
-
519
- // Process widget import file.
520
- if ( $widget_file_info && ! isset( $widget_file_info['error'] ) ) {
521
-
522
- // Set uploaded widget file.
523
- $selected_import_files['widgets'] = $widget_file_info['file'];
524
- }
525
- else {
526
-
527
- // Add this error to log file.
528
- $log_added = self::append_to_file(
529
- sprintf(
530
- __( 'Widget file was not uploaded. Error: %s', 'rara-one-click-demo-import' ),
531
- $widget_file_info['error']
532
- ),
533
- $log_file_path,
534
- esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
535
- );
536
- }
537
-
538
- // Process Customizer import file.
539
- if ( $customizer_file_info && ! isset( $customizer_file_info['error'] ) ) {
540
-
541
- // Set uploaded widget file.
542
- $selected_import_files['customizer'] = $customizer_file_info['file'];
543
- }
544
- else {
545
-
546
- // Add this error to log file.
547
- $log_added = self::append_to_file(
548
- sprintf(
549
- __( 'Customizer file was not uploaded. Error: %s', 'rara-one-click-demo-import' ),
550
- $customizer_file_info['error']
551
- ),
552
- $log_file_path,
553
- esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
554
- );
555
- }
556
-
557
- // Add this message to log file.
558
- $log_added = self::append_to_file(
559
- __( 'The import files were successfully uploaded!', 'rara-one-click-demo-import' ) . self::import_file_info( $selected_import_files ),
560
- $log_file_path,
561
- esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
562
- );
563
-
564
- // Return array with paths of uploaded files.
565
- return $selected_import_files;
566
- }
567
-
568
-
569
- /**
570
- * Get import file information and max execution time.
571
- *
572
- * @param array $selected_import_files array of selected import files.
573
- */
574
- public static function import_file_info( $selected_import_files ) {
575
- return PHP_EOL .
576
- sprintf(
577
- __( 'Initial max execution time = %s', 'rara-one-click-demo-import' ),
578
- ini_get( 'max_execution_time' )
579
- ) . PHP_EOL .
580
- sprintf(
581
- __( 'Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = %4$s%1$sCustomizer file = %5$s', 'rara-one-click-demo-import' ),
582
- PHP_EOL,
583
- get_site_url(),
584
- $selected_import_files['content'],
585
- empty( $selected_import_files['widgets'] ) ? esc_html__( 'not defined!', 'rara-one-click-demo-import' ) : $selected_import_files['widgets'],
586
- empty( $selected_import_files['customizer'] ) ? esc_html__( 'not defined!', 'rara-one-click-demo-import' ) : $selected_import_files['customizer']
587
- );
588
- }
589
-
590
-
591
- /**
592
- * Write the error to the log file and send the AJAX response.
593
- *
594
- * @param string $error_text text to display in the log file and in the AJAX response.
595
- * @param string $log_file_path path to the log file.
596
- * @param string $separator title separating the old and new content.
597
- */
598
- public static function log_error_and_send_ajax_response( $error_text, $log_file_path, $separator = '' ) {
599
-
600
- // Add this error to log file.
601
- $log_added = self::append_to_file(
602
- $error_text,
603
- $log_file_path,
604
- $separator
605
- );
606
-
607
- // Send JSON Error response to the AJAX call.
608
- wp_send_json( $error_text );
609
- }
610
- }
1
+ <?php
2
+ /**
3
+ * Static functions used in the rrdi plugin.
4
+ *
5
+ * @package rara-one-click-demo-import
6
+ */
7
+
8
+ /**
9
+ * Class with static helper functions.
10
+ */
11
+ class RRDI_Helpers {
12
+
13
+ /**
14
+ * Filter through the array of import files and get rid of those who do not comply.
15
+ *
16
+ * @param array $import_files list of arrays with import file details.
17
+ * @return array list of filtered arrays.
18
+ */
19
+ public static function validate_import_file_info( $import_files ) {
20
+ $filtered_import_file_info = array();
21
+
22
+ foreach ( $import_files as $import_file ) {
23
+ if ( self::is_import_file_info_format_correct( $import_file ) ) {
24
+ $filtered_import_file_info[] = $import_file;
25
+ }
26
+ }
27
+
28
+ return $filtered_import_file_info;
29
+ }
30
+
31
+
32
+ /**
33
+ * Helper function: a simple check for valid import file format.
34
+ *
35
+ * @param array $import_file_info array with import file details.
36
+ * @return boolean
37
+ */
38
+ private static function is_import_file_info_format_correct( $import_file_info ) {
39
+ if ( ( empty( $import_file_info['import_file_url'] ) && empty( $import_file_info['local_import_file'] ) ) || empty( $import_file_info['import_file_name'] ) ) {
40
+ return false;
41
+ }
42
+
43
+ return true;
44
+ }
45
+
46
+
47
+ /**
48
+ * Download import files. Content .xml and widgets .wie|.json files.
49
+ *
50
+ * @param array $import_file_info array with import file details.
51
+ * @param string $start_date string of date and time.
52
+ * @return array|WP_Error array of paths to the downloaded files or WP_Error object with error message.
53
+ */
54
+ public static function download_import_files( $import_file_info, $start_date = '' ) {
55
+
56
+ $downloaded_files = array();
57
+ $upload_dir = wp_upload_dir();
58
+ $upload_path = apply_filters( 'rrdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
59
+
60
+ // ----- Set content file path -----
61
+ // Check if 'import_file_url' is not defined. That would mean a local file.
62
+ if ( empty( $import_file_info['import_file_url'] ) ) {
63
+ if ( file_exists( $import_file_info['local_import_file'] ) ) {
64
+ $downloaded_files['content'] = $import_file_info['local_import_file'];
65
+ }
66
+ else {
67
+ return new WP_Error(
68
+ 'url_or_local_file_not_defined',
69
+ sprintf(
70
+ __( '"import_file_url" or "local_import_file" for %s%s%s are not defined!', 'rara-one-click-demo-import' ),
71
+ '<strong>',
72
+ $import_file_info['import_file_name'],
73
+ '</strong>'
74
+ )
75
+ );
76
+ }
77
+ }
78
+ else {
79
+
80
+ // Retrieve demo data content from the URL.
81
+ $demo_import_content = self::get_content_from_url( $import_file_info['import_file_url'], $import_file_info['import_file_name'] );
82
+
83
+ // Return from this function if there was an error.
84
+ if ( is_wp_error( $demo_import_content ) ) {
85
+ return $demo_import_content;
86
+ }
87
+
88
+ // Setup filename path to save the data content.
89
+ $demo_import_file_path = $upload_path . apply_filters( 'rrdi/downloaded_content_file_prefix', 'demo-content-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_content_file_suffix_and_file_extension', '.xml' );
90
+
91
+ // Write data content to the file and return the file path on successful write.
92
+ $downloaded_files['content'] = self::write_to_file( $demo_import_content, $demo_import_file_path );
93
+
94
+ // Return from this function if there was an error.
95
+ if ( is_wp_error( $downloaded_files['content'] ) ) {
96
+ return $downloaded_files['content'];
97
+ }
98
+ }
99
+
100
+ // ----- Set widget file path -----
101
+ // Get widgets file as well. If defined!
102
+ if ( ! empty( $import_file_info['import_widget_file_url'] ) ) {
103
+
104
+ // Retrieve widget content from the URL.
105
+ $demo_import_widgets_content = self::get_content_from_url( $import_file_info['import_widget_file_url'], $import_file_info['import_file_name'] );
106
+
107
+ // Return from this function if there was an error.
108
+ if ( is_wp_error( $demo_import_widgets_content ) ) {
109
+ return $demo_import_widgets_content;
110
+ }
111
+
112
+ // Setup filename path to save the widget content.
113
+ $import_widgets_file_path = $upload_path . apply_filters( 'rrdi/downloaded_widgets_file_prefix', 'demo-widgets-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_widgets_file_suffix_and_file_extension', '.json' );
114
+
115
+ // Write widget content to the file and return the file path on successful write.
116
+ $downloaded_files['widgets'] = self::write_to_file( $demo_import_widgets_content, $import_widgets_file_path );
117
+
118
+ // Return from this function if there was an error.
119
+ if ( is_wp_error( $downloaded_files['widgets'] ) ) {
120
+ return $downloaded_files['widgets'];
121
+ }
122
+ }
123
+ else if ( ! empty( $import_file_info['local_import_widget_file'] ) ) {
124
+ if ( file_exists( $import_file_info['local_import_widget_file'] ) ) {
125
+ $downloaded_files['widgets'] = $import_file_info['local_import_widget_file'];
126
+ }
127
+ }
128
+
129
+ // ----- Set customizer file path -----
130
+ // Get customizer import file as well. If defined!
131
+ if ( ! empty( $import_file_info['import_customizer_file_url'] ) ) {
132
+
133
+ // Retrieve customizer content from the URL.
134
+ $demo_import_customizer_content = self::get_content_from_url( $import_file_info['import_customizer_file_url'], $import_file_info['import_file_name'] );
135
+
136
+ // Return from this function if there was an error.
137
+ if ( is_wp_error( $demo_import_customizer_content ) ) {
138
+ return $demo_import_customizer_content;
139
+ }
140
+
141
+ // Setup filename path to save the customizer content.
142
+ $import_customizer_file_path = $upload_path . apply_filters( 'rrdi/downloaded_customizer_file_prefix', 'demo-customizer-import-file_' ) . $start_date . apply_filters( 'rrdi/downloaded_customizer_file_suffix_and_file_extension', '.dat' );
143
+
144
+ // Write customizer content to the file and return the file path on successful write.
145
+ $downloaded_files['customizer'] = self::write_to_file( $demo_import_customizer_content, $import_customizer_file_path );
146
+
147
+ // Return from this function if there was an error.
148
+ if ( is_wp_error( $downloaded_files['customizer'] ) ) {
149
+ return $downloaded_files['customizer'];
150
+ }
151
+ }
152
+ else if ( ! empty( $import_file_info['local_import_customizer_file'] ) ) {
153
+ if ( file_exists( $import_file_info['local_import_customizer_file'] ) ) {
154
+ $downloaded_files['customizer'] = $import_file_info['local_import_customizer_file'];
155
+ }
156
+ }
157
+
158
+ return $downloaded_files;
159
+ }
160
+
161
+
162
+ /**
163
+ * Helper function: get content from an url.
164
+ *
165
+ * @param string $url URL to the content file.
166
+ * @param string $file_name optional, name of the file (used in the error reports).
167
+ * @return string|WP_Error, content from the URL or WP_Error object with error message
168
+ */
169
+ private static function get_content_from_url( $url, $file_name = 'Import file' ) {
170
+
171
+ // Test if the URL to the file is defined.
172
+ if ( empty( $url ) ) {
173
+ return new WP_Error(
174
+ 'url_not_defined',
175
+ sprintf(
176
+ __( 'URL for %s%s%s file is not defined!', 'rara-one-click-demo-import' ),
177
+ '<strong>',
178
+ $file_name,
179
+ '</strong>'
180
+ )
181
+ );
182
+ }
183
+
184
+ // Get file content from the server.
185
+ $response = wp_remote_get(
186
+ $url,
187
+ array( 'timeout' => apply_filters( 'rrdi/timeout_for_downloading_import_file', 20 ) )
188
+ );
189
+
190
+ if ( is_wp_error( $response ) || 200 !== $response['response']['code'] ) {
191
+
192
+ // Collect the right format of error data (array or WP_Error).
193
+ $response_error = self::get_error_from_response( $response );
194
+
195
+ return new WP_Error(
196
+ 'file_fetching_error',
197
+ sprintf(
198
+ __( 'An error occurred while fetching %s%s%s file from the server!%sReason: %s - %s.', 'rara-one-click-demo-import' ),
199
+ '<strong>',
200
+ $file_name,
201
+ '</strong>',
202
+ '<br>',
203
+ $response_error['error_code'],
204
+ $response_error['error_message']
205
+ ) . '<br>' .
206
+ apply_filters( 'rrdi/message_after_file_fetching_error', '' )
207
+ );
208
+ }
209
+
210
+ // Return content retrieved from the URL.
211
+ return wp_remote_retrieve_body( $response );
212
+ }
213
+
214
+
215
+ /**
216
+ * Write content to a file.
217
+ *
218
+ * @param string $content content to be saved to the file.
219
+ * @param string $file_path file path where the content should be saved.
220
+ * @return string|WP_Error path to the saved file or WP_Error object with error message.
221
+ */
222
+ public static function write_to_file( $content, $file_path ) {
223
+
224
+ // Verify WP file-system credentials.
225
+ $verified_credentials = self::check_wp_filesystem_credentials();
226
+
227
+ if ( is_wp_error( $verified_credentials ) ) {
228
+ return $verified_credentials;
229
+ }
230
+
231
+ // By this point, the $wp_filesystem global should be working, so let's use it to create a file.
232
+ global $wp_filesystem;
233
+
234
+ if ( ! $wp_filesystem->put_contents( $file_path, $content ) ) {
235
+ return new WP_Error(
236
+ 'failed_writing_file_to_server',
237
+ sprintf(
238
+ __( 'An error occurred while writing file to your server! Tried to write a file to: %s%s.', 'rara-one-click-demo-import' ),
239
+ '<br>',
240
+ $file_path
241
+ )
242
+ );
243
+ }
244
+
245
+ // Return the file path on successful file write.
246
+ return $file_path;
247
+ }
248
+
249
+
250
+ /**
251
+ * Append content to the file.
252
+ *
253
+ * @param string $content content to be saved to the file.
254
+ * @param string $file_path file path where the content should be saved.
255
+ * @param string $separator_text separates the existing content of the file with the new content.
256
+ * @return boolean|WP_Error, path to the saved file or WP_Error object with error message.
257
+ */
258
+ public static function append_to_file( $content, $file_path, $separator_text = '' ) {
259
+
260
+ // Verify WP file-system credentials.
261
+ $verified_credentials = self::check_wp_filesystem_credentials();
262
+
263
+ if ( is_wp_error( $verified_credentials ) ) {
264
+ return $verified_credentials;
265
+ }
266
+
267
+ // By this point, the $wp_filesystem global should be working, so let's use it to create a file.
268
+ global $wp_filesystem;
269
+
270
+ $existing_data = '';
271
+ if ( file_exists( $file_path ) ) {
272
+ $existing_data = $wp_filesystem->get_contents( $file_path );
273
+ }
274
+
275
+ // Style separator.
276
+ $separator = PHP_EOL . '---' . $separator_text . '---' . PHP_EOL;
277
+
278
+ if ( ! $wp_filesystem->put_contents( $file_path, $existing_data . $separator . $content . PHP_EOL ) ) {
279
+ return new WP_Error(
280
+ 'failed_writing_file_to_server',
281
+ sprintf(
282
+ __( 'An error occurred while writing file to your server! Tried to write a file to: %s%s.', 'rara-one-click-demo-import' ),
283
+ '<br>',
284
+ $file_path
285
+ )
286
+ );
287
+ }
288
+
289
+ return true;
290
+ }
291
+
292
+
293
+ /**
294
+ * Get data from a file
295
+ *
296
+ * @param string $file_path file path where the content should be saved.
297
+ * @return string $data, content of the file or WP_Error object with error message.
298
+ */
299
+ public static function data_from_file( $file_path ) {
300
+
301
+ // Verify WP file-system credentials.
302
+ $verified_credentials = self::check_wp_filesystem_credentials();
303
+
304
+ if ( is_wp_error( $verified_credentials ) ) {
305
+ return $verified_credentials;
306
+ }
307
+
308
+ // By this point, the $wp_filesystem global should be working, so let's use it to read a file.
309
+ global $wp_filesystem;
310
+
311
+ $data = $wp_filesystem->get_contents( $file_path );
312
+
313
+ if ( ! $data ) {
314
+ return new WP_Error(
315
+ 'failed_reading_file_from_server',
316
+ sprintf(
317
+ __( 'An error occurred while reading a file from your server! Tried reading file from path: %s%s.', 'rara-one-click-demo-import' ),
318
+ '<br>',
319
+ $file_path
320
+ )
321
+ );
322
+ }
323
+
324
+ // Return the file data.
325
+ return $data;
326
+ }
327
+
328
+
329
+ /**
330
+ * Helper function: check for WP file-system credentials needed for reading and writing to a file.
331
+ *
332
+ * @return boolean|WP_Error
333
+ */
334
+ private static function check_wp_filesystem_credentials() {
335
+
336
+ // Check if the file-system method is 'direct', if not display an error.
337
+ if ( ! ( 'direct' === get_filesystem_method() ) ) {
338
+ return new WP_Error(
339
+ 'no_direct_file_access',
340
+ sprintf(
341
+ __( 'This WordPress page does not have %sdirect%s write file access. This plugin needs it in order to save the demo import xml file to the upload directory of your site. You can change this setting with these instructions: %s.', 'rara-one-click-demo-import' ),
342
+ '<strong>',
343
+ '</strong>',
344
+ '<a href="http://gregorcapuder.com/wordpress-how-to-set-direct-filesystem-method/" target="_blank">How to set <strong>direct</strong> filesystem method</a>'
345
+ )
346
+ );
347
+ }
348
+
349
+ // Get plugin page settings.
350
+ $plugin_page_setup = apply_filters( 'rrdi/plugin_page_setup', array(
351
+ 'parent_slug' => 'themes.php',
352
+ 'page_title' => esc_html__( 'Rara One Click Demo Import' , 'rara-one-click-demo-import' ),
353
+ 'menu_title' => esc_html__( 'Rara Demo Import' , 'rara-one-click-demo-import' ),
354
+ 'capability' => 'import',
355
+ 'menu_slug' => 'rara-demo-import',
356
+ )
357
+ );
358
+
359
+ // Get user credentials for WP file-system API.
360
+ $demo_import_page_url = wp_nonce_url( $plugin_page_setup['parent_slug'] . '?page=' . $plugin_page_setup['menu_slug'], $plugin_page_setup['menu_slug'] );
361
+
362
+ if ( false === ( $creds = request_filesystem_credentials( $demo_import_page_url, '', false, false, null ) ) ) {
363
+ return new WP_error(
364
+ 'filesystem_credentials_could_not_be_retrieved',
365
+ __( 'An error occurred while retrieving reading/writing permissions to your server (could not retrieve WP filesystem credentials)!', 'rara-one-click-demo-import' )
366
+ );
367
+ }
368
+
369
+ // Now we have credentials, try to get the wp_filesystem running.
370
+ if ( ! WP_Filesystem( $creds ) ) {
371
+ return new WP_Error(
372
+ 'wrong_login_credentials',
373
+ __( 'Your WordPress login credentials don\'t allow to use WP_Filesystem!', 'rara-one-click-demo-import' )
374
+ );
375
+ }
376
+
377
+ return true;
378
+ }
379
+
380
+
381
+ /**
382
+ * Helper function: get the right format of response errors
383
+ *
384
+ * @param array|WP_Error $response array or WP_Error.
385
+ * @return array, with error code and error message.
386
+ */
387
+ private static function get_error_from_response( $response ) {
388
+ $response_error = array();
389
+
390
+ if ( is_array( $response ) ) {
391
+ $response_error['error_code'] = $response['response']['code'];
392
+ $response_error['error_message'] = $response['response']['message'];
393
+ }
394
+ else {
395
+ $response_error['error_code'] = $response->get_error_code();
396
+ $response_error['error_message'] = $response->get_error_message();
397
+ }
398
+
399
+ return $response_error;
400
+ }
401
+
402
+
403
+ /**
404
+ * Get log file path
405
+ *
406
+ * @param string $start_date date|time|timestamp to use in the log filename.
407
+ * @return string, path to the log file
408
+ */
409
+ public static function get_log_path( $start_date = '' ) {
410
+
411
+ $upload_dir = wp_upload_dir();
412
+ $upload_path = apply_filters( 'rrdi/upload_file_path', trailingslashit( $upload_dir['path'] ) );
413
+
414
+ $log_path = $upload_path . apply_filters( 'rrdi/log_file_prefix', 'log_file_' ) . $start_date . apply_filters( 'rrdi/log_file_suffix_and_file_extension', '.txt' );
415
+
416
+ self::register_file_as_media_attachment( $log_path );
417
+
418
+ return $log_path;
419
+ }
420
+
421
+
422
+ /**
423
+ * Register file as attachment to the Media page.
424
+ *
425
+ * @param string $log_path log file path.
426
+ * @return void
427
+ */
428
+ public static function register_file_as_media_attachment( $log_path ) {
429
+
430
+ // Check the type of file.
431
+ $log_mimes = array( 'txt' => 'text/plain' );
432
+ $filetype = wp_check_filetype( basename( $log_path ), apply_filters( 'rrdi/file_mimes', $log_mimes ) );
433
+
434
+ // Prepare an array of post data for the attachment.
435
+ $attachment = array(
436
+ 'guid' => self::get_log_url( $log_path ),
437
+ 'post_mime_type' => $filetype['type'],
438
+ 'post_title' => apply_filters( 'rrdi/attachment_prefix', esc_html__( 'Rara One Click Demo Import - ', 'rara-one-click-demo-import' ) ) . preg_replace( '/\.[^.]+#x2F;', '', basename( $log_path ) ),
439
+ 'post_content' => '',
440
+ 'post_status' => 'inherit',
441
+ );
442
+
443
+ // Insert the file as attachment in Media page.
444
+ $attach_id = wp_insert_attachment( $attachment, $log_path );
445
+ }
446
+
447
+
448
+ /**
449
+ * Get log file url
450
+ *
451
+ * @param string $log_path log path to use for the log filename.
452
+ * @return string, url to the log file.
453
+ */
454
+ public static function get_log_url( $log_path ) {
455
+
456
+ $upload_dir = wp_upload_dir();
457
+ $upload_url = apply_filters( 'rrdi/upload_file_url', trailingslashit( $upload_dir['url'] ) );
458
+
459
+ return $upload_url . basename( $log_path );
460
+ }
461
+
462
+
463
+ /**
464
+ * Check if the AJAX call is valid.
465
+ */
466
+ public static function verify_ajax_call() {
467
+
468
+ check_ajax_referer( 'rrdi-ajax-verification', 'security' );
469
+
470
+ // Check if user has the WP capability to import data.
471
+ if ( ! current_user_can( 'import' ) ) {
472
+ wp_die(
473
+ sprintf(
474
+ __( '%sYour user role isn\'t high enough. You don\'t have permission to import demo data.%s', 'rara-one-click-demo-import' ),
475
+ '<div class="notice notice-error"><p>',
476
+ '</p></div>'
477
+ )
478
+ );
479
+ }
480
+ }
481
+
482
+
483
+ /**
484
+ * Process uploaded files and return the paths to these files.
485
+ *
486
+ * @param array $uploaded_files $_FILES array form an AJAX request.
487
+ * @param string $log_file_path path to the log file.
488
+ * @return array of paths to the content import and widget import files.
489
+ */
490
+ public static function process_uploaded_files( $uploaded_files, $log_file_path ) {
491
+
492
+ // Variable holding the paths to the uploaded files.
493
+ $selected_import_files = array();
494
+
495
+ // Upload settings to disable form and type testing for AJAX uploads.
496
+ $upload_overrides = array(
497
+ 'test_form' => false,
498
+ 'test_type' => false,
499
+ );
500
+
501
+ // Handle demo content and widgets file upload.
502
+ $content_file_info = wp_handle_upload( $_FILES['content_file'], $upload_overrides );
503
+ $widget_file_info = wp_handle_upload( $_FILES['widget_file'], $upload_overrides );
504
+ $customizer_file_info = wp_handle_upload( $_FILES['customizer_file'], $upload_overrides );
505
+
506
+ if ( empty( $content_file_info['file'] ) || isset( $content_file_info['error'] ) ) {
507
+
508
+ // Write error to log file and send an AJAX response with the error.
509
+ self::log_error_and_send_ajax_response(
510
+ __( 'Please upload XML file for content import. If you want to import widgets or customizer settings only, please use Widget Importer & Exporter or the Customizer Export/Import plugin.', 'rara-one-click-demo-import' ),
511
+ $log_file_path,
512
+ esc_html__( 'Upload files', 'rara-one-click-demo-import' )
513
+ );
514
+ }
515
+
516
+ // Set uploaded content file.
517
+ $selected_import_files['content'] = $content_file_info['file'];
518
+
519
+ // Process widget import file.
520
+ if ( $widget_file_info && ! isset( $widget_file_info['error'] ) ) {
521
+
522
+ // Set uploaded widget file.
523
+ $selected_import_files['widgets'] = $widget_file_info['file'];
524
+ }
525
+ else {
526
+
527
+ // Add this error to log file.
528
+ $log_added = self::append_to_file(
529
+ sprintf(
530
+ __( 'Widget file was not uploaded. Error: %s', 'rara-one-click-demo-import' ),
531
+ $widget_file_info['error']
532
+ ),
533
+ $log_file_path,
534
+ esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
535
+ );
536
+ }
537
+
538
+ // Process Customizer import file.
539
+ if ( $customizer_file_info && ! isset( $customizer_file_info['error'] ) ) {
540
+
541
+ // Set uploaded widget file.
542
+ $selected_import_files['customizer'] = $customizer_file_info['file'];
543
+ }
544
+ else {
545
+
546
+ // Add this error to log file.
547
+ $log_added = self::append_to_file(
548
+ sprintf(
549
+ __( 'Customizer file was not uploaded. Error: %s', 'rara-one-click-demo-import' ),
550
+ $customizer_file_info['error']
551
+ ),
552
+ $log_file_path,
553
+ esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
554
+ );
555
+ }
556
+
557
+ // Add this message to log file.
558
+ $log_added = self::append_to_file(
559
+ __( 'The import files were successfully uploaded!', 'rara-one-click-demo-import' ) . self::import_file_info( $selected_import_files ),
560
+ $log_file_path,
561
+ esc_html__( 'Upload files' , 'rara-one-click-demo-import' )
562
+ );
563
+
564
+ // Return array with paths of uploaded files.
565
+ return $selected_import_files;
566
+ }
567
+
568
+
569
+ /**
570
+ * Get import file information and max execution time.
571
+ *
572
+ * @param array $selected_import_files array of selected import files.
573
+ */
574
+ public static function import_file_info( $selected_import_files ) {
575
+ return PHP_EOL .
576
+ sprintf(
577
+ __( 'Initial max execution time = %s', 'rara-one-click-demo-import' ),
578
+ ini_get( 'max_execution_time' )
579
+ ) . PHP_EOL .
580
+ sprintf(
581
+ __( 'Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = %4$s%1$sCustomizer file = %5$s', 'rara-one-click-demo-import' ),
582
+ PHP_EOL,
583
+ get_site_url(),
584
+ $selected_import_files['content'],
585
+ empty( $selected_import_files['widgets'] ) ? esc_html__( 'not defined!', 'rara-one-click-demo-import' ) : $selected_import_files['widgets'],
586
+ empty( $selected_import_files['customizer'] ) ? esc_html__( 'not defined!', 'rara-one-click-demo-import' ) : $selected_import_files['customizer']
587
+ );
588
+ }
589
+
590
+
591
+ /**
592
+ * Write the error to the log file and send the AJAX response.
593
+ *
594
+ * @param string $error_text text to display in the log file and in the AJAX response.
595
+ * @param string $log_file_path path to the log file.
596
+ * @param string $separator title separating the old and new content.
597
+ */
598
+ public static function log_error_and_send_ajax_response( $error_text, $log_file_path, $separator = '' ) {
599
+
600
+ // Add this error to log file.
601
+ $log_added = self::append_to_file(
602
+ $error_text,
603
+ $log_file_path,
604
+ $separator
605
+ );
606
+
607
+ // Send JSON Error response to the AJAX call.
608
+ wp_send_json( $error_text );
609
+ }
610
+ }
includes/class-rrdi-importer.php CHANGED
@@ -1,78 +1,78 @@
1
- <?php
2
- /**
3
- * Class for declaring the importer used in the Rara One Click Demo Import plugin
4
- *
5
- * @package rara-one-click-demo-import
6
- */
7
-
8
- class RRDI_Importer {
9
-
10
- private $importer;
11
-
12
- public function __construct( $importer_options = array(), $logger = null ) {
13
-
14
- // Include files that are needed for WordPress Importer v2.
15
- $this->include_required_files();
16
-
17
- // Set the WordPress Importer v2 as the importer used in this plugin.
18
- // More: https://github.com/humanmade/WordPress-Importer.
19
- $this->importer = new RRDI_WXR_Importer( $importer_options );
20
-
21
- // Set logger to the importer.
22
- if ( ! empty( $logger ) ) {
23
- $this->set_logger( $logger );
24
- }
25
- }
26
-
27
- /**
28
- * Include required files.
29
- */
30
- private function include_required_files() {
31
- defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
32
- include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
33
- if( is_plugin_active( 'theme-demo-import/theme-demo-import.php' ) )
34
- {
35
- }
36
- else if ( is_plugin_active( 'one-click-demo-import/one-click-demo-import.php' ) ){
37
- # code...
38
- }
39
- else{
40
- require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
41
- }
42
- require RRDI_PATH . 'includes/class-rrdi-wxr-importer.php';
43
- }
44
-
45
- /**
46
- * Imports content from a WordPress export file.
47
- *
48
- * @param string $data_file path to xml file, file with WordPress export data.
49
- */
50
- public function import( $data_file ) {
51
- $this->importer->import( $data_file );
52
- }
53
-
54
- /**
55
- * Set the logger used in the import
56
- *
57
- * @param object $logger logger instance.
58
- */
59
- public function set_logger( $logger ) {
60
- $this->importer->set_logger( $logger );
61
- }
62
-
63
- /**
64
- * Get all protected variables from the RDDI_WXR_Importer needed for continuing the import.
65
- */
66
- public function get_importer_data() {
67
- return $this->importer->get_importer_data();
68
- }
69
-
70
- /**
71
- * Sets all protected variables from the RDDI_WXR_Importer needed for continuing the import.
72
- *
73
- * @param array $data with set variables.
74
- */
75
- public function set_importer_data( $data ) {
76
- $this->importer->set_importer_data( $data );
77
- }
78
- }
1
+ <?php
2
+ /**
3
+ * Class for declaring the importer used in the Rara One Click Demo Import plugin
4
+ *
5
+ * @package rara-one-click-demo-import
6
+ */
7
+
8
+ class RRDI_Importer {
9
+
10
+ private $importer;
11
+
12
+ public function __construct( $importer_options = array(), $logger = null ) {
13
+
14
+ // Include files that are needed for WordPress Importer v2.
15
+ $this->include_required_files();
16
+
17
+ // Set the WordPress Importer v2 as the importer used in this plugin.
18
+ // More: https://github.com/humanmade/WordPress-Importer.
19
+ $this->importer = new RRDI_WXR_Importer( $importer_options );
20
+
21
+ // Set logger to the importer.
22
+ if ( ! empty( $logger ) ) {
23
+ $this->set_logger( $logger );
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Include required files.
29
+ */
30
+ private function include_required_files() {
31
+ defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
32
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
33
+ if( is_plugin_active( 'theme-demo-import/theme-demo-import.php' ) )
34
+ {
35
+ }
36
+ else if ( is_plugin_active( 'one-click-demo-import/one-click-demo-import.php' ) ){
37
+ # code...
38
+ }
39
+ else{
40
+ require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
41
+ }
42
+ require RRDI_PATH . 'includes/class-rrdi-wxr-importer.php';
43
+ }
44
+
45
+ /**
46
+ * Imports content from a WordPress export file.
47
+ *
48
+ * @param string $data_file path to xml file, file with WordPress export data.
49
+ */
50
+ public function import( $data_file ) {
51
+ $this->importer->import( $data_file );
52
+ }
53
+
54
+ /**
55
+ * Set the logger used in the import
56
+ *
57
+ * @param object $logger logger instance.
58
+ */
59
+ public function set_logger( $logger ) {
60
+ $this->importer->set_logger( $logger );
61
+ }
62
+
63
+ /**
64
+ * Get all protected variables from the RDDI_WXR_Importer needed for continuing the import.
65
+ */
66
+ public function get_importer_data() {
67
+ return $this->importer->get_importer_data();
68
+ }
69
+
70
+ /**
71
+ * Sets all protected variables from the RDDI_WXR_Importer needed for continuing the import.
72
+ *
73
+ * @param array $data with set variables.
74
+ */
75
+ public function set_importer_data( $data ) {
76
+ $this->importer->set_importer_data( $data );
77
+ }
78
+ }
includes/class-rrdi-include-files.php CHANGED
@@ -1,23 +1,23 @@
1
- <?php
2
- /**
3
- * Include files.
4
- *
5
- * @package rara-one-click-demo-import
6
- */
7
-
8
- /**
9
- * Rara One Click Demo Import class, so we don't have to worry about namespaces.
10
- */
11
- class RRDI_Theme_Demo_Include_Files {
12
-
13
- function __construct()
14
- {
15
- // Include files.
16
- require RRDI_PATH . 'includes/class-rrdi-helpers.php';
17
- require RRDI_PATH . 'includes/class-rrdi-importer.php';
18
- require RRDI_PATH . 'includes/vendor/class-rrdi-widget-importer.php';
19
- require RRDI_PATH . 'includes/vendor/class-rrdi-customizer-importer.php';
20
- require RRDI_PATH . 'includes/class-rrdi-logger.php';
21
- }
22
- }
23
new RRDI_Theme_Demo_Include_Files;
1
+ <?php
2
+ /**
3
+ * Include files.
4
+ *
5
+ * @package rara-one-click-demo-import
6
+ */
7
+
8
+ /**
9
+ * Rara One Click Demo Import class, so we don't have to worry about namespaces.
10
+ */
11
+ class RRDI_Theme_Demo_Include_Files {
12
+
13
+ function __construct()
14
+ {
15
+ // Include files.
16
+ require RRDI_PATH . 'includes/class-rrdi-helpers.php';
17
+ require RRDI_PATH . 'includes/class-rrdi-importer.php';
18
+ require RRDI_PATH . 'includes/vendor/class-rrdi-widget-importer.php';
19
+ require RRDI_PATH . 'includes/vendor/class-rrdi-customizer-importer.php';
20
+ require RRDI_PATH . 'includes/class-rrdi-logger.php';
21
+ }
22
+ }
23
new RRDI_Theme_Demo_Include_Files;
includes/class-rrdi-init.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
- /**
3
- * Display admin error message if PHP version is older than 5.3.2.
4
- * Otherwise execute the main plugin class.
5
- */
6
- class RDDI_init
7
- {
8
- function __construct()
9
- {
10
- $this->rddi_init_version_check();
11
- }
12
-
13
- function rddi_init_version_check()
14
- {
15
-
16
- if ( version_compare( phpversion(), '5.3.2', '<' ) ) {
17
-
18
- /**
19
- * Display an admin error notice when PHP is older the version 5.3.2.
20
- * Hook it to the 'admin_notices' action.
21
- */
22
- function rrdi_old_php_admin_error_notice() {
23
- $message = sprintf( esc_html__( 'The %2$sRara One Click Demo Import%3$s plugin requires %2$sPHP 5.3.2+%3$s to run properly. Please contact your hosting company and ask them to update the PHP version of your site to at least PHP 5.3.2.%4$s Your current version of PHP: %2$s%1$s%3$s', 'rara-one-click-demo-import' ), phpversion(), '<strong>', '</strong>', '<br>' );
24
-
25
- printf( '<div class="notice notice-error"><p>%1$s</p></div>', wp_kses_post( $message ) );
26
- }
27
- add_action( 'admin_notices', 'rrdi_old_php_admin_error_notice' );
28
- }
29
- else {
30
-
31
- $upload = wp_upload_dir();
32
- $upload_dir = $upload['basedir'];
33
- $upload_dir = $upload_dir . '/rara-demo-pack';
34
- if (! is_dir($upload_dir)) {
35
- mkdir( $upload_dir, 0755 );
36
- }
37
-
38
- // Require main plugin file.
39
- require RRDI_PATH . 'includes/class-rrdi-main.php';
40
-
41
- // Instantiate the main plugin class *Singleton*.
42
- $Theme_Demo_Import = RRDI_Theme_Demo_Import::Instance();
43
- }
44
- }
45
- }
46
new RDDI_init;
1
+ <?php
2
+ /**
3
+ * Display admin error message if PHP version is older than 5.3.2.
4
+ * Otherwise execute the main plugin class.
5
+ */
6
+ class RDDI_init
7
+ {
8
+ function __construct()
9
+ {
10
+ $this->rddi_init_version_check();
11
+ }
12
+
13
+ function rddi_init_version_check()
14
+ {
15
+
16
+ if ( version_compare( phpversion(), '5.3.2', '<' ) ) {
17
+
18
+ /**
19
+ * Display an admin error notice when PHP is older the version 5.3.2.
20
+ * Hook it to the 'admin_notices' action.
21
+ */
22
+ function rrdi_old_php_admin_error_notice() {
23
+ $message = sprintf( esc_html__( 'The %2$sRara One Click Demo Import%3$s plugin requires %2$sPHP 5.3.2+%3$s to run properly. Please contact your hosting company and ask them to update the PHP version of your site to at least PHP 5.3.2.%4$s Your current version of PHP: %2$s%1$s%3$s', 'rara-one-click-demo-import' ), phpversion(), '<strong>', '</strong>', '<br>' );
24
+
25
+ printf( '<div class="notice notice-error"><p>%1$s</p></div>', wp_kses_post( $message ) );
26
+ }
27
+ add_action( 'admin_notices', 'rrdi_old_php_admin_error_notice' );
28
+ }
29
+ else {
30
+
31
+ $upload = wp_upload_dir();
32
+ $upload_dir = $upload['basedir'];
33
+ $upload_dir = $upload_dir . '/rara-demo-pack';
34
+ if (! is_dir($upload_dir)) {
35
+ mkdir( $upload_dir, 0755 );
36
+ }
37
+
38
+ // Require main plugin file.
39
+ require RRDI_PATH . 'includes/class-rrdi-main.php';
40
+
41
+ // Instantiate the main plugin class *Singleton*.
42
+ $Theme_Demo_Import = RRDI_Theme_Demo_Import::Instance();
43
+ }
44
+ }
45
+ }
46
new RDDI_init;
includes/class-rrdi-logger.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Logger class used in the Rara One Click Demo Import plugin
4
- *
5
- * @package rara-one-click-demo-import
6
- */
7
-
8
- // Include files.
9
- require RRDI_PATH . 'includes/extras/class-logger.php';
10
- require RRDI_PATH . 'includes/extras/class-logger-cli.php';
11
-
12
- class RRDI_Logger extends RDDI_WP_Importer_Logger_CLI {
13
-
14
- /**
15
- * Variable for front-end error display.
16
- */
17
- public $error_output = '';
18
-
19
- /**
20
- * Overwritten log function from RDDI_WP_Importer_Logger_CLI.
21
- *
22
- * Logs with an arbitrary level.
23
- *
24
- * @param mixed $level level of reporting.
25
- * @param string $message log message.
26
- * @param array $context context to the log message.
27
- */
28
- public function log( $level, $message, array $context = array() ) {
29
-
30
- // Save error messages for front-end display.
31
- $this->error_output( $level, $message, $context = array() );
32
-
33
- if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
34
- return;
35
- }
36
-
37
- printf(
38
- '[%s] %s' . PHP_EOL,
39
- strtoupper( $level ),
40
- $message
41
- );
42
- }
43
-
44
-
45
- /**
46
- * Save messages for error output.
47
- * Only the messages greater then Error.
48
- *
49
- * @param mixed $level level of reporting.
50
- * @param string $message log message.
51
- * @param array $context context to the log message.
52
- */
53
- public function error_output( $level, $message, array $context = array() ) {
54
- if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( 'error' ) ) {
55
- return;
56
- }
57
-
58
- $this->error_output .= sprintf(
59
- '[%s] %s<br>',
60
- strtoupper( $level ),
61
- $message
62
- );
63
- }
64
}
1
+ <?php
2
+ /**
3
+ * Logger class used in the Rara One Click Demo Import plugin
4
+ *
5
+ * @package rara-one-click-demo-import
6
+ */
7
+
8
+ // Include files.
9
+ require RRDI_PATH . 'includes/extras/class-logger.php';
10
+ require RRDI_PATH . 'includes/extras/class-logger-cli.php';
11
+
12
+ class RRDI_Logger extends RDDI_WP_Importer_Logger_CLI {
13
+
14
+ /**
15
+ * Variable for front-end error display.
16
+ */
17
+ public $error_output = '';
18
+
19
+ /**
20
+ * Overwritten log function from RDDI_WP_Importer_Logger_CLI.
21
+ *
22
+ * Logs with an arbitrary level.
23
+ *
24
+ * @param mixed $level level of reporting.
25
+ * @param string $message log message.
26
+ * @param array $context context to the log message.
27
+ */
28
+ public function log( $level, $message, array $context = array() ) {
29
+
30
+ // Save error messages for front-end display.
31
+ $this->error_output( $level, $message, $context = array() );
32
+
33
+ if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( $this->min_level ) ) {
34
+ return;
35
+ }
36
+
37
+ printf(
38
+ '[%s] %s' . PHP_EOL,
39
+ strtoupper( $level ),
40
+ $message
41
+ );
42
+ }
43
+
44
+
45
+ /**
46
+ * Save messages for error output.
47
+ * Only the messages greater then Error.
48
+ *
49
+ * @param mixed $level level of reporting.
50
+ * @param string $message log message.
51
+ * @param array $context context to the log message.
52
+ */
53
+ public function error_output( $level, $message, array $context = array() ) {
54
+ if ( $this->level_to_numeric( $level ) < $this->level_to_numeric( 'error' ) ) {
55
+ return;
56
+ }
57
+
58
+ $this->error_output .= sprintf(
59
+ '[%s] %s<br>',
60
+ strtoupper( $level ),
61
+ $message
62
+ );
63
+ }
64
}
includes/class-rrdi-main.php CHANGED
@@ -1,761 +1,761 @@
1
- <?php
2
- /**
3
- * Main Rara One Click Demo Import plugin class/file.
4
- *
5
- * @package rara-one-click-demo-import
6
- */
7
- /**
8
- * Rara One Click Demo Import class, so we don't have to worry about namespaces.
9
- */
10
- class RRDI_Theme_Demo_Import {
11
-
12
- public $demo_config;
13
-
14
- /**
15
- * Demo packages.
16
- * @var array
17
- */
18
- public $demo_packages;
19
-
20
- /**
21
- * Demo installer.
22
- * @var bool
23
- */
24
- public $demo_installer = true;
25
-
26
- /**
27
- * @var $instance the reference to *Singleton* instance of this class
28
- */
29
- private static $instance;
30
-
31
- /**
32
- * Private variables used throughout the plugin.
33
- */
34
- private $importer, $plugin_page, $import_files, $logger, $log_file_path, $selected_index, $selected_import_files, $microtime, $frontend_error_messages, $ajax_call_number;
35
-
36
-
37
- /**
38
- * Returns the *Singleton* instance of this class.
39
- *
40
- * @return Theme_Demo_Import the *Singleton* instance.
41
- */
42
- public static function Instance() {
43
- if ( null === static::$instance ) {
44
- static::$instance = new static();
45
- }
46
-
47
- return static::$instance;
48
- }
49
-
50
-
51
- /**
52
- * Class construct function, to initiate the plugin.
53
- * Protected constructor to prevent creating a new instance of the
54
- * *Singleton* via the `new` operator from outside of this class.
55
- */
56
- protected function __construct() {
57
- require RRDI_PATH . 'includes/class-rrdi-include-files.php';
58
- // Actions.
59
-
60
- $this->includes();
61
-
62
-
63
- add_action( 'init', array( $this, 'setup' ), 5 );
64
- $get_theme = wp_get_theme();
65
-
66
- if( $get_theme->get( 'AuthorURI' ) == 'http://raratheme.com/' || $get_theme->get( 'AuthorURI' ) == 'https://raratheme.com/' || $get_theme->get( 'AuthorURI' ) == 'http://raratheme.com' || $get_theme->get( 'AuthorURI' ) == 'https://raratheme.com' )
67
- {
68
- add_action( 'admin_menu', array( $this, 'create_plugin_page' ) );
69
- }
70
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
71
- add_action( 'wp_ajax_rrdi_import_demo_data', array( $this, 'rrdi_import_demo_data_ajax_callback' ) );
72
- add_action( 'init', array( $this, 'setup_plugin_with_filter_data' ) );
73
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
74
- // AJAX Events to import demo and dismiss notice.
75
- add_action( 'wp_ajax_dismiss-notice', array( $this, 'ajax_dismiss_notice' ) );
76
- }
77
-
78
- /**
79
- * Demo importer setup.
80
- */
81
- public function setup() {
82
- $this->demo_config = apply_filters( 'rara_demo_importer_config', array() );
83
- $this->demo_packages = apply_filters( 'rara_demo_importer_packages', array() );
84
- $this->demo_installer = apply_filters( 'rara_demo_importer_installer', true );
85
- }
86
-
87
-
88
- function getNewestDir($path) {
89
- $working_dir = getcwd();
90
- chdir($path); ## chdir to requested dir
91
- $ret_val = false;
92
- if ($p = opendir($path) ) {
93
- while (false !== ($file = readdir($p))) {
94
- if ($file{0} != '.' && is_dir($file)) {
95
- $list[] = date('YmdHis', filemtime($path.'/'.$file)).$path.'/'.$file;
96
- }
97
- }
98
- if( isset($list) )
99
- {
100
- rsort($list);
101
- $ret_val = $list[0];
102
- }
103
- }
104
- chdir($working_dir); ## chdir back to script's dir
105
- return $ret_val;
106
- }
107
-
108
- /**
109
- * Includes.
110
- */
111
- private function includes() {
112
- $get_theme = wp_get_theme();
113
- if( $get_theme->get( 'AuthorURI' ) == 'http://raratheme.com/' || $get_theme->get( 'AuthorURI' ) == 'https://raratheme.com/' || $get_theme->get( 'AuthorURI' ) == 'http://raratheme.com' || $get_theme->get( 'AuthorURI' ) == 'https://raratheme.com' )
114
- {
115
- $td = $get_theme->get( 'TextDomain' ).'-demo-content';
116
- if ( strpos($td, 'pro') === false )
117
- {
118
- $upload_dir = wp_upload_dir();
119
- // Check the folder contains at least 1 valid demo config.
120
- $path = $upload_dir['basedir'] . '/rara-demo-pack/';
121
- $files = $path.$td.'/import-hooks.php';
122
- if (file_exists($files) && is_readable($files)) {
123
- include($files);
124
- }
125
- }
126
- }
127
- }
128
-
129
- /**
130
- * Private clone method to prevent cloning of the instance of the *Singleton* instance.
131
- *
132
- * @return void
133
- */