Version Description
No upgrade notices
Download this release
Release Info
Developer | Archetyped |
Plugin | Favicon Rotator |
Version | 1.0 |
Comparing to | |
See all releases |
Version 1.0
- COPYING +339 -0
- css/admin_styles.css +48 -0
- images/icon_close.gif +0 -0
- includes/class.base.php +183 -0
- includes/class.media.php +528 -0
- includes/class.utilities.php +544 -0
- js/admin.js +169 -0
- js/media.js +27 -0
- main.php +12 -0
- model.php +330 -0
- readme.txt +40 -0
- resources/admin_help.html +16 -0
- screenshot-1.png +0 -0
- screenshot-2.png +0 -0
COPYING
ADDED
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
GNU GENERAL PUBLIC LICENSE
|
2 |
+
Version 2, June 1991
|
3 |
+
|
4 |
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
5 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
6 |
+
Everyone is permitted to copy and distribute verbatim copies
|
7 |
+
of this license document, but changing it is not allowed.
|
8 |
+
|
9 |
+
Preamble
|
10 |
+
|
11 |
+
The licenses for most software are designed to take away your
|
12 |
+
freedom to share and change it. By contrast, the GNU General Public
|
13 |
+
License is intended to guarantee your freedom to share and change free
|
14 |
+
software--to make sure the software is free for all its users. This
|
15 |
+
General Public License applies to most of the Free Software
|
16 |
+
Foundation's software and to any other program whose authors commit to
|
17 |
+
using it. (Some other Free Software Foundation software is covered by
|
18 |
+
the GNU Lesser General Public License instead.) You can apply it to
|
19 |
+
your programs, too.
|
20 |
+
|
21 |
+
When we speak of free software, we are referring to freedom, not
|
22 |
+
price. Our General Public Licenses are designed to make sure that you
|
23 |
+
have the freedom to distribute copies of free software (and charge for
|
24 |
+
this service if you wish), that you receive source code or can get it
|
25 |
+
if you want it, that you can change the software or use pieces of it
|
26 |
+
in new free programs; and that you know you can do these things.
|
27 |
+
|
28 |
+
To protect your rights, we need to make restrictions that forbid
|
29 |
+
anyone to deny you these rights or to ask you to surrender the rights.
|
30 |
+
These restrictions translate to certain responsibilities for you if you
|
31 |
+
distribute copies of the software, or if you modify it.
|
32 |
+
|
33 |
+
For example, if you distribute copies of such a program, whether
|
34 |
+
gratis or for a fee, you must give the recipients all the rights that
|
35 |
+
you have. You must make sure that they, too, receive or can get the
|
36 |
+
source code. And you must show them these terms so they know their
|
37 |
+
rights.
|
38 |
+
|
39 |
+
We protect your rights with two steps: (1) copyright the software, and
|
40 |
+
(2) offer you this license which gives you legal permission to copy,
|
41 |
+
distribute and/or modify the software.
|
42 |
+
|
43 |
+
Also, for each author's protection and ours, we want to make certain
|
44 |
+
that everyone understands that there is no warranty for this free
|
45 |
+
software. If the software is modified by someone else and passed on, we
|
46 |
+
want its recipients to know that what they have is not the original, so
|
47 |
+
that any problems introduced by others will not reflect on the original
|
48 |
+
authors' reputations.
|
49 |
+
|
50 |
+
Finally, any free program is threatened constantly by software
|
51 |
+
patents. We wish to avoid the danger that redistributors of a free
|
52 |
+
program will individually obtain patent licenses, in effect making the
|
53 |
+
program proprietary. To prevent this, we have made it clear that any
|
54 |
+
patent must be licensed for everyone's free use or not licensed at all.
|
55 |
+
|
56 |
+
The precise terms and conditions for copying, distribution and
|
57 |
+
modification follow.
|
58 |
+
|
59 |
+
GNU GENERAL PUBLIC LICENSE
|
60 |
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
61 |
+
|
62 |
+
0. This License applies to any program or other work which contains
|
63 |
+
a notice placed by the copyright holder saying it may be distributed
|
64 |
+
under the terms of this General Public License. The "Program", below,
|
65 |
+
refers to any such program or work, and a "work based on the Program"
|
66 |
+
means either the Program or any derivative work under copyright law:
|
67 |
+
that is to say, a work containing the Program or a portion of it,
|
68 |
+
either verbatim or with modifications and/or translated into another
|
69 |
+
language. (Hereinafter, translation is included without limitation in
|
70 |
+
the term "modification".) Each licensee is addressed as "you".
|
71 |
+
|
72 |
+
Activities other than copying, distribution and modification are not
|
73 |
+
covered by this License; they are outside its scope. The act of
|
74 |
+
running the Program is not restricted, and the output from the Program
|
75 |
+
is covered only if its contents constitute a work based on the
|
76 |
+
Program (independent of having been made by running the Program).
|
77 |
+
Whether that is true depends on what the Program does.
|
78 |
+
|
79 |
+
1. You may copy and distribute verbatim copies of the Program's
|
80 |
+
source code as you receive it, in any medium, provided that you
|
81 |
+
conspicuously and appropriately publish on each copy an appropriate
|
82 |
+
copyright notice and disclaimer of warranty; keep intact all the
|
83 |
+
notices that refer to this License and to the absence of any warranty;
|
84 |
+
and give any other recipients of the Program a copy of this License
|
85 |
+
along with the Program.
|
86 |
+
|
87 |
+
You may charge a fee for the physical act of transferring a copy, and
|
88 |
+
you may at your option offer warranty protection in exchange for a fee.
|
89 |
+
|
90 |
+
2. You may modify your copy or copies of the Program or any portion
|
91 |
+
of it, thus forming a work based on the Program, and copy and
|
92 |
+
distribute such modifications or work under the terms of Section 1
|
93 |
+
above, provided that you also meet all of these conditions:
|
94 |
+
|
95 |
+
a) You must cause the modified files to carry prominent notices
|
96 |
+
stating that you changed the files and the date of any change.
|
97 |
+
|
98 |
+
b) You must cause any work that you distribute or publish, that in
|
99 |
+
whole or in part contains or is derived from the Program or any
|
100 |
+
part thereof, to be licensed as a whole at no charge to all third
|
101 |
+
parties under the terms of this License.
|
102 |
+
|
103 |
+
c) If the modified program normally reads commands interactively
|
104 |
+
when run, you must cause it, when started running for such
|
105 |
+
interactive use in the most ordinary way, to print or display an
|
106 |
+
announcement including an appropriate copyright notice and a
|
107 |
+
notice that there is no warranty (or else, saying that you provide
|
108 |
+
a warranty) and that users may redistribute the program under
|
109 |
+
these conditions, and telling the user how to view a copy of this
|
110 |
+
License. (Exception: if the Program itself is interactive but
|
111 |
+
does not normally print such an announcement, your work based on
|
112 |
+
the Program is not required to print an announcement.)
|
113 |
+
|
114 |
+
These requirements apply to the modified work as a whole. If
|
115 |
+
identifiable sections of that work are not derived from the Program,
|
116 |
+
and can be reasonably considered independent and separate works in
|
117 |
+
themselves, then this License, and its terms, do not apply to those
|
118 |
+
sections when you distribute them as separate works. But when you
|
119 |
+
distribute the same sections as part of a whole which is a work based
|
120 |
+
on the Program, the distribution of the whole must be on the terms of
|
121 |
+
this License, whose permissions for other licensees extend to the
|
122 |
+
entire whole, and thus to each and every part regardless of who wrote it.
|
123 |
+
|
124 |
+
Thus, it is not the intent of this section to claim rights or contest
|
125 |
+
your rights to work written entirely by you; rather, the intent is to
|
126 |
+
exercise the right to control the distribution of derivative or
|
127 |
+
collective works based on the Program.
|
128 |
+
|
129 |
+
In addition, mere aggregation of another work not based on the Program
|
130 |
+
with the Program (or with a work based on the Program) on a volume of
|
131 |
+
a storage or distribution medium does not bring the other work under
|
132 |
+
the scope of this License.
|
133 |
+
|
134 |
+
3. You may copy and distribute the Program (or a work based on it,
|
135 |
+
under Section 2) in object code or executable form under the terms of
|
136 |
+
Sections 1 and 2 above provided that you also do one of the following:
|
137 |
+
|
138 |
+
a) Accompany it with the complete corresponding machine-readable
|
139 |
+
source code, which must be distributed under the terms of Sections
|
140 |
+
1 and 2 above on a medium customarily used for software interchange; or,
|
141 |
+
|
142 |
+
b) Accompany it with a written offer, valid for at least three
|
143 |
+
years, to give any third party, for a charge no more than your
|
144 |
+
cost of physically performing source distribution, a complete
|
145 |
+
machine-readable copy of the corresponding source code, to be
|
146 |
+
distributed under the terms of Sections 1 and 2 above on a medium
|
147 |
+
customarily used for software interchange; or,
|
148 |
+
|
149 |
+
c) Accompany it with the information you received as to the offer
|
150 |
+
to distribute corresponding source code. (This alternative is
|
151 |
+
allowed only for noncommercial distribution and only if you
|
152 |
+
received the program in object code or executable form with such
|
153 |
+
an offer, in accord with Subsection b above.)
|
154 |
+
|
155 |
+
The source code for a work means the preferred form of the work for
|
156 |
+
making modifications to it. For an executable work, complete source
|
157 |
+
code means all the source code for all modules it contains, plus any
|
158 |
+
associated interface definition files, plus the scripts used to
|
159 |
+
control compilation and installation of the executable. However, as a
|
160 |
+
special exception, the source code distributed need not include
|
161 |
+
anything that is normally distributed (in either source or binary
|
162 |
+
form) with the major components (compiler, kernel, and so on) of the
|
163 |
+
operating system on which the executable runs, unless that component
|
164 |
+
itself accompanies the executable.
|
165 |
+
|
166 |
+
If distribution of executable or object code is made by offering
|
167 |
+
access to copy from a designated place, then offering equivalent
|
168 |
+
access to copy the source code from the same place counts as
|
169 |
+
distribution of the source code, even though third parties are not
|
170 |
+
compelled to copy the source along with the object code.
|
171 |
+
|
172 |
+
4. You may not copy, modify, sublicense, or distribute the Program
|
173 |
+
except as expressly provided under this License. Any attempt
|
174 |
+
otherwise to copy, modify, sublicense or distribute the Program is
|
175 |
+
void, and will automatically terminate your rights under this License.
|
176 |
+
However, parties who have received copies, or rights, from you under
|
177 |
+
this License will not have their licenses terminated so long as such
|
178 |
+
parties remain in full compliance.
|
179 |
+
|
180 |
+
5. You are not required to accept this License, since you have not
|
181 |
+
signed it. However, nothing else grants you permission to modify or
|
182 |
+
distribute the Program or its derivative works. These actions are
|
183 |
+
prohibited by law if you do not accept this License. Therefore, by
|
184 |
+
modifying or distributing the Program (or any work based on the
|
185 |
+
Program), you indicate your acceptance of this License to do so, and
|
186 |
+
all its terms and conditions for copying, distributing or modifying
|
187 |
+
the Program or works based on it.
|
188 |
+
|
189 |
+
6. Each time you redistribute the Program (or any work based on the
|
190 |
+
Program), the recipient automatically receives a license from the
|
191 |
+
original licensor to copy, distribute or modify the Program subject to
|
192 |
+
these terms and conditions. You may not impose any further
|
193 |
+
restrictions on the recipients' exercise of the rights granted herein.
|
194 |
+
You are not responsible for enforcing compliance by third parties to
|
195 |
+
this License.
|
196 |
+
|
197 |
+
7. If, as a consequence of a court judgment or allegation of patent
|
198 |
+
infringement or for any other reason (not limited to patent issues),
|
199 |
+
conditions are imposed on you (whether by court order, agreement or
|
200 |
+
otherwise) that contradict the conditions of this License, they do not
|
201 |
+
excuse you from the conditions of this License. If you cannot
|
202 |
+
distribute so as to satisfy simultaneously your obligations under this
|
203 |
+
License and any other pertinent obligations, then as a consequence you
|
204 |
+
may not distribute the Program at all. For example, if a patent
|
205 |
+
license would not permit royalty-free redistribution of the Program by
|
206 |
+
all those who receive copies directly or indirectly through you, then
|
207 |
+
the only way you could satisfy both it and this License would be to
|
208 |
+
refrain entirely from distribution of the Program.
|
209 |
+
|
210 |
+
If any portion of this section is held invalid or unenforceable under
|
211 |
+
any particular circumstance, the balance of the section is intended to
|
212 |
+
apply and the section as a whole is intended to apply in other
|
213 |
+
circumstances.
|
214 |
+
|
215 |
+
It is not the purpose of this section to induce you to infringe any
|
216 |
+
patents or other property right claims or to contest validity of any
|
217 |
+
such claims; this section has the sole purpose of protecting the
|
218 |
+
integrity of the free software distribution system, which is
|
219 |
+
implemented by public license practices. Many people have made
|
220 |
+
generous contributions to the wide range of software distributed
|
221 |
+
through that system in reliance on consistent application of that
|
222 |
+
system; it is up to the author/donor to decide if he or she is willing
|
223 |
+
to distribute software through any other system and a licensee cannot
|
224 |
+
impose that choice.
|
225 |
+
|
226 |
+
This section is intended to make thoroughly clear what is believed to
|
227 |
+
be a consequence of the rest of this License.
|
228 |
+
|
229 |
+
8. If the distribution and/or use of the Program is restricted in
|
230 |
+
certain countries either by patents or by copyrighted interfaces, the
|
231 |
+
original copyright holder who places the Program under this License
|
232 |
+
may add an explicit geographical distribution limitation excluding
|
233 |
+
those countries, so that distribution is permitted only in or among
|
234 |
+
countries not thus excluded. In such case, this License incorporates
|
235 |
+
the limitation as if written in the body of this License.
|
236 |
+
|
237 |
+
9. The Free Software Foundation may publish revised and/or new versions
|
238 |
+
of the General Public License from time to time. Such new versions will
|
239 |
+
be similar in spirit to the present version, but may differ in detail to
|
240 |
+
address new problems or concerns.
|
241 |
+
|
242 |
+
Each version is given a distinguishing version number. If the Program
|
243 |
+
specifies a version number of this License which applies to it and "any
|
244 |
+
later version", you have the option of following the terms and conditions
|
245 |
+
either of that version or of any later version published by the Free
|
246 |
+
Software Foundation. If the Program does not specify a version number of
|
247 |
+
this License, you may choose any version ever published by the Free Software
|
248 |
+
Foundation.
|
249 |
+
|
250 |
+
10. If you wish to incorporate parts of the Program into other free
|
251 |
+
programs whose distribution conditions are different, write to the author
|
252 |
+
to ask for permission. For software which is copyrighted by the Free
|
253 |
+
Software Foundation, write to the Free Software Foundation; we sometimes
|
254 |
+
make exceptions for this. Our decision will be guided by the two goals
|
255 |
+
of preserving the free status of all derivatives of our free software and
|
256 |
+
of promoting the sharing and reuse of software generally.
|
257 |
+
|
258 |
+
NO WARRANTY
|
259 |
+
|
260 |
+
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
261 |
+
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
262 |
+
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
263 |
+
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
264 |
+
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
265 |
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
266 |
+
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
267 |
+
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
268 |
+
REPAIR OR CORRECTION.
|
269 |
+
|
270 |
+
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
271 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
272 |
+
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
273 |
+
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
274 |
+
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
275 |
+
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
276 |
+
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
277 |
+
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
278 |
+
POSSIBILITY OF SUCH DAMAGES.
|
279 |
+
|
280 |
+
END OF TERMS AND CONDITIONS
|
281 |
+
|
282 |
+
How to Apply These Terms to Your New Programs
|
283 |
+
|
284 |
+
If you develop a new program, and you want it to be of the greatest
|
285 |
+
possible use to the public, the best way to achieve this is to make it
|
286 |
+
free software which everyone can redistribute and change under these terms.
|
287 |
+
|
288 |
+
To do so, attach the following notices to the program. It is safest
|
289 |
+
to attach them to the start of each source file to most effectively
|
290 |
+
convey the exclusion of warranty; and each file should have at least
|
291 |
+
the "copyright" line and a pointer to where the full notice is found.
|
292 |
+
|
293 |
+
<one line to give the program's name and a brief idea of what it does.>
|
294 |
+
Copyright (C) <year> <name of author>
|
295 |
+
|
296 |
+
This program is free software; you can redistribute it and/or modify
|
297 |
+
it under the terms of the GNU General Public License as published by
|
298 |
+
the Free Software Foundation; either version 2 of the License, or
|
299 |
+
(at your option) any later version.
|
300 |
+
|
301 |
+
This program is distributed in the hope that it will be useful,
|
302 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
303 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
304 |
+
GNU General Public License for more details.
|
305 |
+
|
306 |
+
You should have received a copy of the GNU General Public License along
|
307 |
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
308 |
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
309 |
+
|
310 |
+
Also add information on how to contact you by electronic and paper mail.
|
311 |
+
|
312 |
+
If the program is interactive, make it output a short notice like this
|
313 |
+
when it starts in an interactive mode:
|
314 |
+
|
315 |
+
Gnomovision version 69, Copyright (C) year name of author
|
316 |
+
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
317 |
+
This is free software, and you are welcome to redistribute it
|
318 |
+
under certain conditions; type `show c' for details.
|
319 |
+
|
320 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
321 |
+
parts of the General Public License. Of course, the commands you use may
|
322 |
+
be called something other than `show w' and `show c'; they could even be
|
323 |
+
mouse-clicks or menu items--whatever suits your program.
|
324 |
+
|
325 |
+
You should also get your employer (if you work as a programmer) or your
|
326 |
+
school, if any, to sign a "copyright disclaimer" for the program, if
|
327 |
+
necessary. Here is a sample; alter the names:
|
328 |
+
|
329 |
+
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
330 |
+
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
331 |
+
|
332 |
+
<signature of Ty Coon>, 1 April 1989
|
333 |
+
Ty Coon, President of Vice
|
334 |
+
|
335 |
+
This General Public License does not permit incorporating your program into
|
336 |
+
proprietary programs. If your program is a subroutine library, you may
|
337 |
+
consider it more useful to permit linking proprietary applications with the
|
338 |
+
library. If this is what you want to do, use the GNU Lesser General
|
339 |
+
Public License instead of this License.
|
css/admin_styles.css
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Favicon Admin Styles */
|
2 |
+
#fv_list_container {
|
3 |
+
margin: 1em;
|
4 |
+
}
|
5 |
+
|
6 |
+
#fv_list {
|
7 |
+
width: 100%;
|
8 |
+
overflow: hidden;
|
9 |
+
}
|
10 |
+
|
11 |
+
.fv_item,
|
12 |
+
.fv_item .icon,
|
13 |
+
.fv_item .details {
|
14 |
+
float: left;
|
15 |
+
}
|
16 |
+
|
17 |
+
.fv_item {
|
18 |
+
width: auto;
|
19 |
+
border: 1px solid #e2e2e2;
|
20 |
+
background: #fcfcfc;
|
21 |
+
margin: 0 1em 1em 0;
|
22 |
+
padding: 1em 2em 1em 1em;
|
23 |
+
position: relative;
|
24 |
+
-moz-border-radius: 5px;
|
25 |
+
}
|
26 |
+
|
27 |
+
.fv_item .icon {
|
28 |
+
margin-right: 0.8em;
|
29 |
+
border: 1px solid #ddd;
|
30 |
+
width: 16px;
|
31 |
+
height: 16px;
|
32 |
+
}
|
33 |
+
|
34 |
+
.fv_item .remove {
|
35 |
+
background: url('../images/icon_close.gif') no-repeat;
|
36 |
+
text-indent: -2000em;
|
37 |
+
display: block;
|
38 |
+
width: 10px;
|
39 |
+
height: 10px;
|
40 |
+
position: absolute;
|
41 |
+
top: 2px;
|
42 |
+
right: 2px;
|
43 |
+
opacity: .5;
|
44 |
+
}
|
45 |
+
|
46 |
+
.fv_item a:hover.remove {
|
47 |
+
opacity: 1;
|
48 |
+
}
|
images/icon_close.gif
ADDED
Binary file
|
includes/class.base.php
ADDED
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once 'class.utilities.php';
|
4 |
+
|
5 |
+
/**
|
6 |
+
* @package Favicon Rotator
|
7 |
+
* @author Archetyped
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class FVRT_Base {
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Prefix for Cornerstone-related data (attributes, DB tables, etc.)
|
14 |
+
* @var string
|
15 |
+
*/
|
16 |
+
var $prefix = 'fvrt';
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Utilities instance
|
20 |
+
* @var FVRT_Utilities
|
21 |
+
*/
|
22 |
+
var $util;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Legacy constructor
|
26 |
+
*/
|
27 |
+
function FVRT_Base() {
|
28 |
+
$this->__construct();
|
29 |
+
}
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Constructor
|
33 |
+
*/
|
34 |
+
function __construct() {
|
35 |
+
$this->util =& new FVRT_Utilities();
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Default initialization method
|
40 |
+
* To be overriden by child classes
|
41 |
+
*/
|
42 |
+
function init() {
|
43 |
+
$func = 'register_hooks';
|
44 |
+
if ( isset($this) ) {
|
45 |
+
if ( method_exists($this, $func) )
|
46 |
+
call_user_method($func, $this);
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
+
function register_hooks() {
|
51 |
+
//Activation
|
52 |
+
$func_activate = 'activate';
|
53 |
+
if ( method_exists($this, $func_activate) )
|
54 |
+
register_activation_hook($this->util->get_plugin_base_file(), $this->m($func_activate));
|
55 |
+
//Deactivation
|
56 |
+
$func_deactivate = 'deactivate';
|
57 |
+
if ( method_exists($this, $func_deactivate) )
|
58 |
+
register_deactivation_hook($this->util->get_plugin_base_file(), $this->m($func_deactivate));
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Returns callback to instance method
|
63 |
+
* @param string $method Method name
|
64 |
+
* @return array Callback array
|
65 |
+
*/
|
66 |
+
function &m($method) {
|
67 |
+
return $this->util->m($this, $method);
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Retrieves post metadata for internal methods
|
72 |
+
* Metadata set internally is wrapped in an array so it is unwrapped before returned the retrieved value
|
73 |
+
* @see get_post_meta()
|
74 |
+
* @param int $post_id Post ID
|
75 |
+
* @param string $key Name of metadata to retrieve
|
76 |
+
* @param boolean $single Whether or not to retrieve single value or not
|
77 |
+
* @return mixed Retrieved post metadata
|
78 |
+
*/
|
79 |
+
function post_meta_get($post_id, $key, $single = false) {
|
80 |
+
$meta_value = get_post_meta($post_id, $this->post_meta_get_key($key), $single);
|
81 |
+
if (is_array($meta_value) && count($meta_value) == 1)
|
82 |
+
$meta_value = $meta_value[0];
|
83 |
+
return $meta_value;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Wraps metadata in array for storage in database
|
88 |
+
* @param mixed $meta_value Value to be set as metadata
|
89 |
+
* @return array Wrapped metadata value
|
90 |
+
*/
|
91 |
+
function post_meta_prepare_value($meta_value) {
|
92 |
+
return array($meta_value);
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Adds Metadata for a post to database
|
97 |
+
* For internal methods
|
98 |
+
* @see add_post_meta
|
99 |
+
* @param $post_id
|
100 |
+
* @param $meta_key
|
101 |
+
* @param $meta_value
|
102 |
+
* @param $unique
|
103 |
+
* @return boolean Result of operation
|
104 |
+
*/
|
105 |
+
function post_meta_add($post_id, $meta_key, $meta_value, $unique = false) {
|
106 |
+
$meta_value = $this->post_meta_value_prepare($meta_value);
|
107 |
+
return add_post_meta($post_id, $meta_key, $meta_value, $unique);
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Updates post metadata for internal data/methods
|
112 |
+
* @see update_post_meta()
|
113 |
+
* @param $post_id
|
114 |
+
* @param $meta_key
|
115 |
+
* @param $meta_value
|
116 |
+
* @param $prev_value
|
117 |
+
* @return boolean Result of operation
|
118 |
+
*/
|
119 |
+
function post_meta_update($post_id, $meta_key, $meta_value, $prev_value = '') {
|
120 |
+
$meta_value = $this->post_meta_prepare_value($meta_value);
|
121 |
+
return update_post_meta($post_id, $meta_key, $meta_value, $prev_value);
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Builds postmeta key for custom data set by plugin
|
126 |
+
* @param string $key Base key name
|
127 |
+
* @return string Formatted postmeta key
|
128 |
+
*/
|
129 |
+
function post_meta_get_key($key) {
|
130 |
+
$sep = '_';
|
131 |
+
if ( strpos($key, $sep . $this->prefix) !== 0 ) {
|
132 |
+
$key_base = func_get_args();
|
133 |
+
if ( !empty($key_base) ) {
|
134 |
+
$key = array_merge((array)$this->prefix, $key_base);
|
135 |
+
return $sep . implode($sep, $key);
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
return $key;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Retrieve class prefix (with separator if set)
|
144 |
+
* @param bool|string $sep Separator to append to class prefix (Default: no separator)
|
145 |
+
* @return string Class prefix
|
146 |
+
*/
|
147 |
+
function get_prefix($sep = false) {
|
148 |
+
$sep = ( is_string($sep) ) ? $sep : '';
|
149 |
+
$prefix = ( !empty($this->prefix) ) ? $this->prefix . $sep : '';
|
150 |
+
return $prefix;
|
151 |
+
}
|
152 |
+
|
153 |
+
/**
|
154 |
+
* Prepend plugin prefix to some text
|
155 |
+
* @param string $text Text to add to prefix
|
156 |
+
* @param string $sep Text used to separate prefix and text
|
157 |
+
* @return string Text with prefix prepended
|
158 |
+
*/
|
159 |
+
function add_prefix($text = '', $sep = '_') {
|
160 |
+
return $this->get_prefix($sep) . $text;
|
161 |
+
}
|
162 |
+
|
163 |
+
/**
|
164 |
+
* Creates a meta key for storing post meta data
|
165 |
+
* Prefixes standard prefixed text with underscore to hide meta data on post edit forms
|
166 |
+
* @param string $text Text to use as base of meta key
|
167 |
+
* @return string Formatted meta key
|
168 |
+
*/
|
169 |
+
function make_meta_key($text = '') {
|
170 |
+
return '_' . $this->add_prefix($text);
|
171 |
+
}
|
172 |
+
|
173 |
+
/**
|
174 |
+
* Returns Database prefix for Cornerstone-related DB Tables
|
175 |
+
* @return string Database prefix
|
176 |
+
*/
|
177 |
+
function get_db_prefix() {
|
178 |
+
global $wpdb;
|
179 |
+
return $wpdb->prefix . $this->get_prefix('_');
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
?>
|
includes/class.media.php
ADDED
@@ -0,0 +1,528 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
require_once 'class.base.php';
|
3 |
+
|
4 |
+
/**
|
5 |
+
* Core properties/methods for Media management
|
6 |
+
* @package Favicon Rotator
|
7 |
+
* @subpackage Media
|
8 |
+
* @author Archetyped
|
9 |
+
*/
|
10 |
+
class FVRT_Media extends FVRT_Base {
|
11 |
+
/**
|
12 |
+
* Prefix for all instance variables that should be prefixed
|
13 |
+
* @var string
|
14 |
+
*/
|
15 |
+
var $prefix_var = 'var_';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Query var used to set field media is being selected for
|
19 |
+
* Prefix added upon instantiation
|
20 |
+
* @var string
|
21 |
+
*/
|
22 |
+
var $var_type = 'icon';
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Query var used to set media upload action
|
26 |
+
* Prefix added upon instantiation
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
var $var_action = 'action';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* ID of variable used to submit selected icon
|
33 |
+
* Prefix added upon instantiation
|
34 |
+
* @var unknown_type
|
35 |
+
*/
|
36 |
+
var $var_setmedia = 'setmedia';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Mime types for favicon
|
40 |
+
* @var array
|
41 |
+
*/
|
42 |
+
var $mime_types = array('png', 'gif', 'jpg', 'x-icon');
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Arguments for upload URL building
|
46 |
+
* @var array
|
47 |
+
*/
|
48 |
+
var $upload_url_args;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Legacy Constructor
|
52 |
+
*/
|
53 |
+
function FVRT_Media() {
|
54 |
+
$this->__construct();
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Constructor
|
59 |
+
*/
|
60 |
+
function __construct() {
|
61 |
+
parent::__construct();
|
62 |
+
$this->init_vars();
|
63 |
+
}
|
64 |
+
|
65 |
+
/* Methods */
|
66 |
+
|
67 |
+
function register_hooks() {
|
68 |
+
//Register handler for custom media requests
|
69 |
+
add_action('media_upload_' . $this->add_prefix('icon'), $this->m('upload_icon'));
|
70 |
+
//Display 'Set as...' button in media item box
|
71 |
+
add_filter('attachment_fields_to_edit', $this->m('attachment_fields_to_edit'), 11, 2);
|
72 |
+
|
73 |
+
//Modify tabs in upload popup for fields
|
74 |
+
add_filter('media_upload_tabs', $this->m('field_upload_tabs'));
|
75 |
+
|
76 |
+
//Restrict file types in upload file dialog
|
77 |
+
add_filter('upload_file_glob', $this->m('upload_file_types'));
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Initialize value of instance variables
|
82 |
+
*/
|
83 |
+
function init_vars() {
|
84 |
+
//Get object variables
|
85 |
+
$vars = get_object_vars($this);
|
86 |
+
foreach ( $vars as $var => $val ) {
|
87 |
+
if ( strpos($var, $this->prefix_var) === 0 )
|
88 |
+
$this->{$var} = $this->add_prefix($val);
|
89 |
+
}
|
90 |
+
}
|
91 |
+
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Sets acceptable file types for uploading
|
95 |
+
* Also sets File dialog description (hacky but works)
|
96 |
+
* @param string $types
|
97 |
+
* @return string Modified file types value & file dialog description
|
98 |
+
*/
|
99 |
+
function upload_file_types($types) {
|
100 |
+
if ( $this->is_custom_media() ) {
|
101 |
+
$filetypes = '*.' . implode(';*.', array('png', 'gif', 'jpg', 'ico'));
|
102 |
+
$types = esc_js($filetypes) . '",file_types_description: "' . esc_js(__('Favicon files'));
|
103 |
+
}
|
104 |
+
return $types;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Modifies media upload URL to work with plugin attachments
|
109 |
+
* @param string $url Full admin URL
|
110 |
+
* @param string $path Path part of URL
|
111 |
+
* @return string Modified media upload URL
|
112 |
+
*/
|
113 |
+
function media_upload_url($url) {
|
114 |
+
if ( strpos($url, 'media-upload.php') === 0 ) {
|
115 |
+
$url = add_query_arg(array($this->var_action => 1, 'type' => $this->var_type, 'tab' => 'type'), $url);
|
116 |
+
}
|
117 |
+
return $url;
|
118 |
+
}
|
119 |
+
|
120 |
+
/**
|
121 |
+
* Handles upload/selecting of an icon
|
122 |
+
*/
|
123 |
+
function upload_icon() {
|
124 |
+
$errors = array();
|
125 |
+
$id = 0;
|
126 |
+
|
127 |
+
//Process media selection
|
128 |
+
if ( isset($_POST[$this->var_setmedia]) ) {
|
129 |
+
/* Send image data to main post edit form and close popup */
|
130 |
+
//Get Attachment ID
|
131 |
+
$field_var = $this->add_prefix('field');
|
132 |
+
$args = new stdClass();
|
133 |
+
$args->id = array_shift( array_keys($_POST[$this->var_setmedia]) );
|
134 |
+
$a =& get_post($args->id);
|
135 |
+
//Build object of properties to send to parent page
|
136 |
+
if ( ! empty($a) && wp_attachment_is_image($a->ID) ) {
|
137 |
+
$args->url = wp_get_attachment_url($a->ID);
|
138 |
+
$args->name = basename($args->url);
|
139 |
+
}
|
140 |
+
//Build JS Arguments string
|
141 |
+
$arg_string = array();
|
142 |
+
foreach ( (array)$args as $key => $val ) {
|
143 |
+
$arg_string[] = "'$key':'$val'";
|
144 |
+
}
|
145 |
+
$arg_string = '{' . implode(',', $arg_string) . '}';
|
146 |
+
?>
|
147 |
+
<script type="text/javascript">
|
148 |
+
/* <![CDATA[ */
|
149 |
+
var win = window.dialogArguments || opener || parent || top;
|
150 |
+
win.fvrt.media.setIcon(<?php echo $arg_string; ?>);
|
151 |
+
/* ]]> */
|
152 |
+
</script>
|
153 |
+
<?php
|
154 |
+
exit;
|
155 |
+
}
|
156 |
+
|
157 |
+
//Handle HTML upload
|
158 |
+
if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
|
159 |
+
$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
|
160 |
+
//Clear uploaded files
|
161 |
+
unset($_FILES);
|
162 |
+
if ( is_wp_error($id) ) {
|
163 |
+
$errors['upload_error'] = $id;
|
164 |
+
$id = false;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
//Display default UI
|
169 |
+
|
170 |
+
//Determine media type
|
171 |
+
$type = ( isset($_REQUEST['type']) ) ? $_REQUEST['type'] : $this->var_type;
|
172 |
+
//Determine UI to use (disk or URL upload)
|
173 |
+
$upload_form = ( isset($_GET['tab']) && 'type_url' == $_GET['tab'] ) ? 'media_upload_type_url_form' : 'media_upload_type_form';
|
174 |
+
//Load UI
|
175 |
+
return wp_iframe( $upload_form, $type, $errors, $id );
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Modifies array of form fields to display on Attachment edit form
|
180 |
+
* Array items are in the form:
|
181 |
+
* 'key' => array(
|
182 |
+
* 'label' => "Label Text",
|
183 |
+
* 'value' => Value
|
184 |
+
* )
|
185 |
+
*
|
186 |
+
* @return array Form fields to display on Attachment edit form
|
187 |
+
* @param array $form_fields Associative array of Fields to display on form (@see get_attachment_fields_to_edit())
|
188 |
+
* @param object $attachment Attachment post object
|
189 |
+
*/
|
190 |
+
function attachment_fields_to_edit($form_fields, $attachment) {
|
191 |
+
|
192 |
+
if ( $this->is_custom_media() ) {
|
193 |
+
$post =& get_post($attachment);
|
194 |
+
//Clear all form fields
|
195 |
+
$form_fields = array();
|
196 |
+
|
197 |
+
//Add "Set as Image" button (if valid attachment type)
|
198 |
+
if ( isset($post->post_type) && strpos($post->post_mime_type, 'image/') === 0 ) {
|
199 |
+
$set_as = __('Add icon');
|
200 |
+
$field = array(
|
201 |
+
'input' => 'html',
|
202 |
+
'html' => '<input type="submit" class="button" value="' . $set_as . '" name="' . $this->var_setmedia . '[' . $post->ID . ']" />'
|
203 |
+
);
|
204 |
+
//Add field ID value as hidden field (if set)
|
205 |
+
if ( isset($_REQUEST[$this->var_type]) ) {
|
206 |
+
$field = array(
|
207 |
+
'input' => 'hidden',
|
208 |
+
'value' => $_REQUEST[$this->var_type]
|
209 |
+
);
|
210 |
+
$form_fields[$this->var_type] = $field;
|
211 |
+
}
|
212 |
+
} else {
|
213 |
+
$field = array(
|
214 |
+
'input' => 'hidden',
|
215 |
+
'value' => ''
|
216 |
+
);
|
217 |
+
}
|
218 |
+
$form_fields['buttons'] = $field;
|
219 |
+
}
|
220 |
+
return $form_fields;
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Checks if value represents a valid media item
|
225 |
+
* @param int|object $media Attachment ID or Object to check
|
226 |
+
* @return bool TRUE if item is media, FALSE otherwise
|
227 |
+
*/
|
228 |
+
function is_media($media) {
|
229 |
+
$media =& get_post($media);
|
230 |
+
return ( ! empty($media) && 'attachment' == $media->post_type );
|
231 |
+
}
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Checks whether current media upload/selection request is initiated by the plugin
|
235 |
+
*/
|
236 |
+
function is_custom_media() {
|
237 |
+
$ret = false;
|
238 |
+
$action = $this->var_action;
|
239 |
+
$upload = false;
|
240 |
+
if (isset($_REQUEST[$action]))
|
241 |
+
$ret = true;
|
242 |
+
else {
|
243 |
+
$qs = array();
|
244 |
+
$ref = parse_url($_SERVER['HTTP_REFERER']);
|
245 |
+
if ( isset($ref['query']) )
|
246 |
+
parse_str($ref['query'], $qs);
|
247 |
+
if (array_key_exists($action, $qs))
|
248 |
+
$ret = true;
|
249 |
+
}
|
250 |
+
|
251 |
+
return $ret;
|
252 |
+
}
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Builds URI for media upload iframe
|
256 |
+
* @param string $type Type of media to upload
|
257 |
+
* @return string Upload URI
|
258 |
+
*/
|
259 |
+
function get_upload_iframe_src($type = 'media', $args = null) {
|
260 |
+
//Build filter tag and callback method
|
261 |
+
$tag = $type . '_upload_iframe_src';
|
262 |
+
$callback =& $this->m('media_upload_url');
|
263 |
+
//Load arguments into instance
|
264 |
+
$this->load_upload_args($args);
|
265 |
+
//Add filter
|
266 |
+
add_filter($tag, $callback);
|
267 |
+
//Build Upload URI
|
268 |
+
$ret = get_upload_iframe_src($type);
|
269 |
+
//Remove filter
|
270 |
+
remove_filter($tag, $callback);
|
271 |
+
//Clear arguments from instance
|
272 |
+
$this->unload_upload_args();
|
273 |
+
//Return URI
|
274 |
+
return $ret;
|
275 |
+
}
|
276 |
+
|
277 |
+
/**
|
278 |
+
* Loads upload URL arguments into instance variable
|
279 |
+
* @param array $args Arguments for upload URL
|
280 |
+
*/
|
281 |
+
function load_upload_args($args) {
|
282 |
+
if ( !is_array($args) )
|
283 |
+
$args = array();
|
284 |
+
$this->upload_url_args = $args;
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Clears upload URL arguments from instance variable
|
289 |
+
* @uses load_upload_args()
|
290 |
+
*/
|
291 |
+
function unload_upload_args() {
|
292 |
+
$this->load_upload_args(null);
|
293 |
+
}
|
294 |
+
|
295 |
+
/*-** Field-Specific **-*/
|
296 |
+
|
297 |
+
/**
|
298 |
+
* Removes URL tab from media upload popup for fields
|
299 |
+
* Fields currently only support media stored @ website
|
300 |
+
* @param array $default_tabs Media upload tabs
|
301 |
+
* @see media_upload_tabs() for full $default_tabs array
|
302 |
+
* @return array Modified tabs array
|
303 |
+
*/
|
304 |
+
function field_upload_tabs($default_tabs) {
|
305 |
+
if ( $this->is_custom_media() )
|
306 |
+
unset($default_tabs['type_url']);
|
307 |
+
return $default_tabs;
|
308 |
+
}
|
309 |
+
|
310 |
+
/*-** Post Attachments **-*/
|
311 |
+
|
312 |
+
/**
|
313 |
+
* Retrieves matching attachments for post
|
314 |
+
* @param object|int $post Post object or Post ID (Default: current global post)
|
315 |
+
* @param array $args (optional) Associative array of query arguments
|
316 |
+
* @see get_posts() for query arguments
|
317 |
+
* @return array|bool Array of post attachments (FALSE on failure)
|
318 |
+
*/
|
319 |
+
function post_get_attachments($post = null, $args = '', $filter_special = true) {
|
320 |
+
if (!$this->util->check_post($post))
|
321 |
+
return false;
|
322 |
+
global $wpdb;
|
323 |
+
|
324 |
+
//Default arguments
|
325 |
+
$defaults = array(
|
326 |
+
'post_type' => 'attachment',
|
327 |
+
'post_parent' => (int) $post->ID,
|
328 |
+
'numberposts' => -1
|
329 |
+
);
|
330 |
+
|
331 |
+
$args = wp_parse_args($args, $defaults);
|
332 |
+
|
333 |
+
//Get attachments
|
334 |
+
$attachments = get_children($args);
|
335 |
+
|
336 |
+
//Filter special attachments
|
337 |
+
if ( $filter_special ) {
|
338 |
+
$start = '[';
|
339 |
+
$end = ']';
|
340 |
+
$removed = false;
|
341 |
+
foreach ( $attachments as $i => $a ) {
|
342 |
+
if ( $start == substr($a->post_title, 0, 1) && $end == substr($a->post_title, -1) ) {
|
343 |
+
unset($attachments[$i]);
|
344 |
+
$removed = true;
|
345 |
+
}
|
346 |
+
}
|
347 |
+
if ( $removed )
|
348 |
+
$attachments = array_values($attachments);
|
349 |
+
}
|
350 |
+
|
351 |
+
//Return attachments
|
352 |
+
return $attachments;
|
353 |
+
}
|
354 |
+
|
355 |
+
/**
|
356 |
+
* Retrieve the attachment's path
|
357 |
+
* Path = Full URL to attachment - site's base URL
|
358 |
+
* Useful for filesystem operations (e.g. file_exists(), etc.)
|
359 |
+
* @param object|id $post Attachment object or ID
|
360 |
+
* @return string Attachment path
|
361 |
+
*/
|
362 |
+
function get_attachment_path($post = null) {
|
363 |
+
if (!$this->util->check_post($post))
|
364 |
+
return '';
|
365 |
+
//Get Attachment URL
|
366 |
+
$url = wp_get_attachment_url($post->ID);
|
367 |
+
//Replace with absolute path
|
368 |
+
$path = str_replace(get_bloginfo('wpurl') . '/', ABSPATH, $url);
|
369 |
+
return $path;
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Retrieves filesize of an attachment
|
374 |
+
* @param obj|int $post (optional) Attachment object or ID (uses global $post object if parameter not provided)
|
375 |
+
* @param bool $formatted (optional) Whether or not filesize should be formatted (kb/mb, etc.) (Default: TRUE)
|
376 |
+
* @return int|string Filesize in bytes (@see filesize()) or as formatted string based on parameters
|
377 |
+
*/
|
378 |
+
function get_attachment_filesize($post = null, $formatted = true) {
|
379 |
+
$size = 0;
|
380 |
+
if (!$this->util->check_post($post))
|
381 |
+
return $size;
|
382 |
+
//Get path to attachment
|
383 |
+
$path = $this->get_attachment_path($post);
|
384 |
+
//Get file size
|
385 |
+
if (file_exists($path))
|
386 |
+
$size = filesize($path);
|
387 |
+
if ($size > 0 && $formatted) {
|
388 |
+
$size = (int) $size;
|
389 |
+
$label = 'b';
|
390 |
+
$format = "%s%s";
|
391 |
+
//Format file size
|
392 |
+
if ($size >= 1024 && $size < 102400) {
|
393 |
+
$label = 'kb';
|
394 |
+
$size = intval($size/1024);
|
395 |
+
}
|
396 |
+
elseif ($size >= 102400) {
|
397 |
+
$label = 'mb';
|
398 |
+
$size = round(($size/1024)/1024, 1);
|
399 |
+
}
|
400 |
+
$size = sprintf($format, $size, $label);
|
401 |
+
}
|
402 |
+
|
403 |
+
return $size;
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
+
* Prints the attachment's filesize
|
408 |
+
* @param obj|int $post (optional) Attachment object or ID (uses global $post object if parameter not provided)
|
409 |
+
* @param bool $formatted (optional) Whether or not filesize should be formatted (kb/mb, etc.) (Default: TRUE)
|
410 |
+
*/
|
411 |
+
function the_attachment_filesize($post = null, $formatted = true) {
|
412 |
+
echo $this->get_attachment_filesize($post, $formatted);
|
413 |
+
}
|
414 |
+
|
415 |
+
/**
|
416 |
+
* Build output for media item
|
417 |
+
* Based on media type and output type parameter
|
418 |
+
* @param int|obj $media Media object or ID
|
419 |
+
* @param string $type (optional) Output type (Default: source URL)
|
420 |
+
* @return string Media output
|
421 |
+
*/
|
422 |
+
function get_media_output($media, $type = 'url', $attr = array()) {
|
423 |
+
$ret = '';
|
424 |
+
$media =& get_post($media);
|
425 |
+
//Continue processing valid media items
|
426 |
+
if ( $this->is_media($media) ) {
|
427 |
+
//URL - Same for all attachments
|
428 |
+
if ( 'url' == $type ) {
|
429 |
+
$ret = wp_get_attachment_url($media->ID);
|
430 |
+
} elseif ( 'link' == $type ) {
|
431 |
+
$ret = $this->get_link($media, $attr);
|
432 |
+
} else {
|
433 |
+
//Determine media type
|
434 |
+
$mime = get_post_mime_type($media);
|
435 |
+
$mime_main = substr($mime, 0, strpos($mime, '/'));
|
436 |
+
|
437 |
+
//Pass to handler for media type + output type
|
438 |
+
$handler = implode('_', array('get', $mime_main, 'output'));
|
439 |
+
if ( method_exists($this, $handler))
|
440 |
+
$ret = $this->{$handler}($media, $type, $attr);
|
441 |
+
else {
|
442 |
+
//Default output if no handler exists
|
443 |
+
$ret = $this->get_image_output($media, $type, $attr);
|
444 |
+
}
|
445 |
+
}
|
446 |
+
}
|
447 |
+
|
448 |
+
|
449 |
+
return apply_filters($this->add_prefix('get_media_output'), $ret, $media, $type);
|
450 |
+
}
|
451 |
+
|
452 |
+
/**
|
453 |
+
* Build HTML for displaying media
|
454 |
+
* Output based on media type (image, video, etc.)
|
455 |
+
* @param int|obj $media (Media object or ID)
|
456 |
+
* @return string HTML for media
|
457 |
+
*/
|
458 |
+
function get_media_html($media) {
|
459 |
+
$out = '';
|
460 |
+
return $out;
|
461 |
+
}
|
462 |
+
|
463 |
+
function get_link($media, $attr = array()) {
|
464 |
+
$ret = '';
|
465 |
+
$media =& get_post($media);
|
466 |
+
if ( $this->is_media($media) ) {
|
467 |
+
$attr['href'] = wp_get_attachment_url($media->ID);
|
468 |
+
$text = ( isset($attr['text']) ) ? $attr['text'] : basename($attr['href']);
|
469 |
+
unset($attr['text']);
|
470 |
+
//Build attribute string
|
471 |
+
$attr = wp_parse_args($attr, array('href' => ''));
|
472 |
+
$attr_string = $this->util->build_attribute_string($attr);
|
473 |
+
$ret = '<a ' . $attr_string . '>' . $text . '</a>';
|
474 |
+
}
|
475 |
+
return $ret;
|
476 |
+
}
|
477 |
+
|
478 |
+
/**
|
479 |
+
* Builds output for image attachments
|
480 |
+
* @param int|obj $media Media object or ID
|
481 |
+
* @param string $type Output type
|
482 |
+
* @return string Image output
|
483 |
+
*/
|
484 |
+
function get_image_output($media, $type = 'html', $attr = array()) {
|
485 |
+
$ret = '';
|
486 |
+
$icon = !wp_attachment_is_image($media->ID);
|
487 |
+
|
488 |
+
//Get image properties
|
489 |
+
$attr = wp_parse_args($attr, array('alt' => trim(strip_tags( $media->post_excerpt ))));
|
490 |
+
list($attr['src'], $attribs['width'], $attribs['height']) = wp_get_attachment_image_src($media->ID, '', $icon);
|
491 |
+
|
492 |
+
switch ( $type ) {
|
493 |
+
case 'html' :
|
494 |
+
$attr_str = $this->util->build_attribute_string($attr);
|
495 |
+
$ret = '<img ' . $attr_str . ' />';
|
496 |
+
break;
|
497 |
+
}
|
498 |
+
|
499 |
+
return $ret;
|
500 |
+
}
|
501 |
+
|
502 |
+
/**
|
503 |
+
* Build HTML IMG element of an Image
|
504 |
+
* @param array $image Array of image properties
|
505 |
+
* 0: Source URI
|
506 |
+
* 1: Width
|
507 |
+
* 2: Height
|
508 |
+
* @return string HTML IMG element of specified image
|
509 |
+
*/
|
510 |
+
function get_image_html($image, $attributes = '') {
|
511 |
+
$ret = '';
|
512 |
+
if (is_array($image) && count($image) >= 3) {
|
513 |
+
//Build attribute string
|
514 |
+
if (is_array($attributes)) {
|
515 |
+
$attribs = '';
|
516 |
+
$attr_format = '%s="%s"';
|
517 |
+
foreach ($attributes as $attr => $val) {
|
518 |
+
$attribs .= sprintf($attr_format, $attr, attribute_escape($val));
|
519 |
+
}
|
520 |
+
$attributes = $attribs;
|
521 |
+
}
|
522 |
+
$format = '<img src="%1$s" width="%2$d" height="%3$d" ' . $attributes . ' />';
|
523 |
+
$ret = sprintf($format, $image[0], $image[1], $image[2]);
|
524 |
+
}
|
525 |
+
return $ret;
|
526 |
+
}
|
527 |
+
}
|
528 |
+
?>
|
includes/class.utilities.php
ADDED
@@ -0,0 +1,544 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Utility methods
|
5 |
+
*
|
6 |
+
* @package Redactor
|
7 |
+
* @author Archetyped
|
8 |
+
*
|
9 |
+
*/
|
10 |
+
class FVRT_Utilities {
|
11 |
+
|
12 |
+
function FVRT_Utilities() {
|
13 |
+
$this->__construct();
|
14 |
+
}
|
15 |
+
|
16 |
+
function __construct() {
|
17 |
+
|
18 |
+
}
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Returns callback array to instance method
|
22 |
+
* @param object $obj Instance object
|
23 |
+
* @param string $method Name of method
|
24 |
+
* @return array Callback array
|
25 |
+
*/
|
26 |
+
function &m(&$obj, $method = '') {
|
27 |
+
if ( $obj == null && isset($this) )
|
28 |
+
$obj =& $this;
|
29 |
+
$arr = array(&$obj, $method);
|
30 |
+
return $arr;
|
31 |
+
}
|
32 |
+
|
33 |
+
/* Helper Functions */
|
34 |
+
|
35 |
+
/*-** WP **-*/
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Checks if $post is a valid Post object
|
39 |
+
* If $post is not valid, assigns global post object to $post (if available)
|
40 |
+
* @return bool TRUE if $post is valid object by end of function processing
|
41 |
+
* @param object $post Post object to evaluate
|
42 |
+
*/
|
43 |
+
function check_post(&$post) {
|
44 |
+
if (empty($post)) {
|
45 |
+
if (isset($GLOBALS['post'])) {
|
46 |
+
$post = $GLOBALS['post'];
|
47 |
+
$GLOBALS['post'] =& $post;
|
48 |
+
}
|
49 |
+
else
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
if (is_array($post))
|
53 |
+
$post = (object) $post;
|
54 |
+
elseif (is_numeric($post))
|
55 |
+
$post = get_post($post);
|
56 |
+
if (!is_object($post))
|
57 |
+
return false;
|
58 |
+
return true;
|
59 |
+
}
|
60 |
+
|
61 |
+
/*-** Request **-*/
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Checks $_SERVER['SCRIPT_NAME'] to see if file base name matches specified file name
|
65 |
+
* @param string $filename Filename to check for
|
66 |
+
* @return bool TRUE if current page matches specified filename, FALSE otherwise
|
67 |
+
*/
|
68 |
+
function is_file( $filename ) {
|
69 |
+
return ( $filename == basename( $_SERVER['SCRIPT_NAME'] ) );
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Checks whether the current page is a management page
|
74 |
+
* @return bool TRUE if current page is a management page, FALSE otherwise
|
75 |
+
*/
|
76 |
+
function is_admin_management_page() {
|
77 |
+
return ( is_admin()
|
78 |
+
&& ( $this->is_file('edit.php')
|
79 |
+
|| ( $this->is_file('admin.php')
|
80 |
+
&& isset($_GET['page'])
|
81 |
+
&& strpos($_GET['page'], 'cnr') === 0 )
|
82 |
+
)
|
83 |
+
);
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Joins and normalizes the slashes in the paths passed to method
|
88 |
+
* All forward/back slashes are converted to forward slashes
|
89 |
+
* Multiple path segments can be passed as additional argments
|
90 |
+
* @param string $path Path to normalize
|
91 |
+
* @param bool $trailing_slash (optional) Whether or not normalized path should have a trailing slash or not (Default: FALSE)
|
92 |
+
* If multiple path segments are passed, $trailing_slash will be the LAST parameter (default value used if omitted)
|
93 |
+
*/
|
94 |
+
function normalize_path($path, $trailing_slash = false) {
|
95 |
+
$sl_f = '/';
|
96 |
+
$sl_b = '\\';
|
97 |
+
$parts = func_get_args();
|
98 |
+
if ( func_num_args() > 1 ) {
|
99 |
+
if ( is_bool(($tr = $parts[count($parts) - 1])) ) {
|
100 |
+
$trailing_slash = $tr;
|
101 |
+
//Remove from args array
|
102 |
+
array_pop($parts);
|
103 |
+
} else {
|
104 |
+
$trailing_slash = false;
|
105 |
+
}
|
106 |
+
//Trim trailing slashes from path parts
|
107 |
+
foreach ( $parts as $key => $part ) {
|
108 |
+
$part = trim($part);
|
109 |
+
$parts[$key] = trim($part, $sl_f . $sl_b);
|
110 |
+
}
|
111 |
+
}
|
112 |
+
$parts = implode($sl_b, $parts);
|
113 |
+
$parts = str_replace($sl_b, $sl_f, $parts);
|
114 |
+
if ( $trailing_slash )
|
115 |
+
$parts . $sl_f;
|
116 |
+
return $parts;
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Returns URL of file (assumes that it is in plugin directory)
|
121 |
+
* @param string $file name of file get URL
|
122 |
+
* @return string File path
|
123 |
+
*/
|
124 |
+
function get_file_url($file) {
|
125 |
+
if (is_string($file) && '' != trim($file)) {
|
126 |
+
$file = ltrim(trim($file), '/');
|
127 |
+
$file = sprintf('%s/%s', $this->get_url_base(), $file);
|
128 |
+
}
|
129 |
+
return $file;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Retrieve base URL for plugin-specific files
|
134 |
+
* @return string Base URL
|
135 |
+
*/
|
136 |
+
function get_url_base() {
|
137 |
+
static $url_base = '';
|
138 |
+
if ( '' == $url_base ) {
|
139 |
+
$url_base = $this->normalize_path(WP_PLUGIN_URL, $this->get_plugin_base());
|
140 |
+
}
|
141 |
+
return $url_base;
|
142 |
+
}
|
143 |
+
|
144 |
+
function get_path_base() {
|
145 |
+
static $path_base = '';
|
146 |
+
if ( '' == $path_base ) {
|
147 |
+
$path_base = $this->normalize_path(WP_PLUGIN_DIR, $this->get_plugin_base());
|
148 |
+
}
|
149 |
+
return $path_base;
|
150 |
+
}
|
151 |
+
|
152 |
+
function get_plugin_base() {
|
153 |
+
static $plugin_dir = '';
|
154 |
+
if ( '' == $plugin_dir ) {
|
155 |
+
$plugin_dir = str_replace($this->normalize_path(WP_PLUGIN_DIR), '', $this->normalize_path(dirname(dirname(__FILE__))));
|
156 |
+
}
|
157 |
+
return $plugin_dir;
|
158 |
+
}
|
159 |
+
|
160 |
+
function get_plugin_base_file() {
|
161 |
+
$file = 'main.php';
|
162 |
+
return $this->get_path_base() . '/' . $file;
|
163 |
+
}
|
164 |
+
|
165 |
+
function get_plugin_base_name() {
|
166 |
+
$file = $this->get_plugin_base_file();
|
167 |
+
return plugin_basename($file);
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Retrieve current action based on URL query variables
|
172 |
+
* @param mixed $default (optional) Default action if no action exists
|
173 |
+
* @return string Current action
|
174 |
+
*/
|
175 |
+
function get_action($default = null) {
|
176 |
+
$action = '';
|
177 |
+
|
178 |
+
//Check if action is set in URL
|
179 |
+
if ( isset($_GET['action']) )
|
180 |
+
$action = $_GET['action'];
|
181 |
+
//Otherwise, Determine action based on plugin plugin admin page suffix
|
182 |
+
elseif ( isset($_GET['page']) && ($pos = strrpos($_GET['page'], '-')) && $pos !== false && ( $pos != count($_GET['page']) - 1 ) )
|
183 |
+
$action = trim(substr($_GET['page'], $pos + 1), '-_');
|
184 |
+
|
185 |
+
//Determine action for core admin pages
|
186 |
+
if ( ! isset($_GET['page']) || empty($action) ) {
|
187 |
+
$actions = array(
|
188 |
+
'add' => array('page-new', 'post-new'),
|
189 |
+
'edit-item' => array('page', 'post'),
|
190 |
+
'edit' => array('edit', 'edit-pages')
|
191 |
+
);
|
192 |
+
$page = basename($_SERVER['SCRIPT_NAME'], '.php');
|
193 |
+
|
194 |
+
foreach ( $actions as $act => $pages ) {
|
195 |
+
if ( in_array($page, $pages) ) {
|
196 |
+
$action = $act;
|
197 |
+
break;
|
198 |
+
}
|
199 |
+
}
|
200 |
+
}
|
201 |
+
if ( empty($action) )
|
202 |
+
$action = $default;
|
203 |
+
return $action;
|
204 |
+
}
|
205 |
+
|
206 |
+
/*-** General **-*/
|
207 |
+
|
208 |
+
/**
|
209 |
+
* Checks if a property exists in a class or object
|
210 |
+
* (Compatibility method for PHP 4
|
211 |
+
* @param mixed $class Class or object to check
|
212 |
+
* @param string $property Name of property to look for in $class
|
213 |
+
*/
|
214 |
+
function property_exists($class, $property) {
|
215 |
+
if ( !is_object($class) && !is_array($class) )
|
216 |
+
return false;
|
217 |
+
if ( function_exists('property_exists') && is_object($class) ) {
|
218 |
+
return property_exists($class, $property);
|
219 |
+
} else {
|
220 |
+
return array_key_exists($property, $class);
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Retrieve specified property from object or array
|
226 |
+
* @param object|array $obj Object or array to get property from
|
227 |
+
* @param string $property Property name to retrieve
|
228 |
+
* @return mixed Property value
|
229 |
+
*/
|
230 |
+
function &get_property(&$obj, $property) {
|
231 |
+
$property = trim($property);
|
232 |
+
//Object
|
233 |
+
if ( is_object($obj) )
|
234 |
+
return $obj->{$property};
|
235 |
+
//Array
|
236 |
+
if ( is_array($obj) )
|
237 |
+
return $obj[$property];
|
238 |
+
//Class
|
239 |
+
if ( is_string($obj) && class_exists($obj) ) {
|
240 |
+
$cvars = get_class_vars($obj);
|
241 |
+
if ( isset($cvars[$property]) )
|
242 |
+
return $cvars[$property];
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Merges 1 or more arrays together
|
248 |
+
* Methodology
|
249 |
+
* - Set first parameter as base array
|
250 |
+
* - All other parameters will be merged into base array
|
251 |
+
* - Iterate through other parameters (arrays)
|
252 |
+
* - Skip all non-array parameters
|
253 |
+
* - Iterate though key/value pairs of current array
|
254 |
+
* - Merge item in base array with current item based on key name
|
255 |
+
* - If the current item's value AND the corresponding item in the base array are BOTH arrays, recursively merge the the arrays
|
256 |
+
* - If the current item's value OR the corresponding item in the base array is NOT an array, current item overwrites base item
|
257 |
+
* @todo Append numerical elements (as opposed to overwriting element at same index in base array)
|
258 |
+
* @param array Variable number of arrays
|
259 |
+
* @return array Merged array
|
260 |
+
*/
|
261 |
+
function array_merge_recursive_distinct() {
|
262 |
+
//Get all arrays passed to function
|
263 |
+
$args = func_get_args();
|
264 |
+
if (empty($args))
|
265 |
+
return false;
|
266 |
+
//Set first array as base array
|
267 |
+
$merged = $args[0];
|
268 |
+
//Iterate through arrays to merge
|
269 |
+
$arg_length = count($args);
|
270 |
+
for ($x = 1; $x < $arg_length; $x++) {
|
271 |
+
//Skip if argument is not an array (only merge arrays)
|
272 |
+
if (!is_array($args[$x]))
|
273 |
+
continue;
|
274 |
+
//Iterate through argument items
|
275 |
+
foreach ($args[$x] as $key => $val) {
|
276 |
+
if (!isset($merged[$key]) || !is_array($merged[$key]) || !is_array($val)) {
|
277 |
+
$merged[$key] = $val;
|
278 |
+
} elseif (is_array($merged[$key]) && is_array($val)) {
|
279 |
+
$merged[$key] = $this->array_merge_recursive_distinct($merged[$key], $val);
|
280 |
+
}
|
281 |
+
//$merged[$key] = (is_array($val) && isset($merged[$key])) ? $this->array_merge_recursive_distinct($merged[$key], $val) : $val;
|
282 |
+
}
|
283 |
+
}
|
284 |
+
return $merged;
|
285 |
+
}
|
286 |
+
|
287 |
+
/**
|
288 |
+
* Replaces string value in one array with the value of the matching element in a another array
|
289 |
+
*
|
290 |
+
* @param string $search Text to search for in array
|
291 |
+
* @param array $arr_replace Array to use for replacing values
|
292 |
+
* @param array $arr_subject Array to search for specified value
|
293 |
+
* @return array Searched array with replacements made
|
294 |
+
*/
|
295 |
+
function array_replace_recursive($search, $arr_replace, $arr_subject) {
|
296 |
+
foreach ($arr_subject as $key => $val) {
|
297 |
+
//Skip element if key does not exist in the replacement array
|
298 |
+
if (!isset($arr_replace[$key]))
|
299 |
+
continue;
|
300 |
+
//If element values for both arrays are strings, replace text
|
301 |
+
if (is_string($val) && strpos($val, $search) !== false && is_string($arr_replace[$key]))
|
302 |
+
$arr_subject[$key] = str_replace($search, $arr_replace[$key], $val);
|
303 |
+
//If value in both arrays are arrays, recursively replace text
|
304 |
+
if (is_array($val) && is_array($arr_replace[$key]))
|
305 |
+
$arr_subject[$key] = $this->array_replace_recursive($search, $arr_replace[$key], $val);
|
306 |
+
}
|
307 |
+
|
308 |
+
return $arr_subject;
|
309 |
+
}
|
310 |
+
|
311 |
+
/**
|
312 |
+
* Checks if item at specified path in array is set
|
313 |
+
* @param array $arr Array to check for item
|
314 |
+
* @param array $path Array of segments that form path to array (each array item is a deeper dimension in the array)
|
315 |
+
* @return boolean TRUE if item is set in array, FALSE otherwise
|
316 |
+
*/
|
317 |
+
function array_item_isset(&$arr, &$path) {
|
318 |
+
$f_path = $this->get_array_path($path);
|
319 |
+
return eval('return isset($arr' . $f_path . ');');
|
320 |
+
}
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Returns value of item at specified path in array
|
324 |
+
* @param array $arr Array to get item from
|
325 |
+
* @param array $path Array of segments that form path to array (each array item is a deeper dimension in the array)
|
326 |
+
* @return mixed Value of item in array (Default: empty string)
|
327 |
+
*/
|
328 |
+
function &get_array_item(&$arr, &$path) {
|
329 |
+
$item = '';
|
330 |
+
if ($this->array_item_isset($arr, $path)) {
|
331 |
+
eval('$item =& $arr' . $this->get_array_path($path) . ';');
|
332 |
+
}
|
333 |
+
return $item;
|
334 |
+
}
|
335 |
+
|
336 |
+
function get_array_path($attribute = '', $format = null) {
|
337 |
+
//Formatted value
|
338 |
+
$fmtd = '';
|
339 |
+
if (!empty($attribute)) {
|
340 |
+
//Make sure attribute is array
|
341 |
+
if (!is_array($attribute)) {
|
342 |
+
$attribute = array($attribute);
|
343 |
+
}
|
344 |
+
//Format attribute
|
345 |
+
$format = strtolower($format);
|
346 |
+
switch ($format) {
|
347 |
+
case 'id':
|
348 |
+
$fmtd = array_shift($attribute) . '[' . implode('][', $attribute) . ']';
|
349 |
+
break;
|
350 |
+
case 'metadata':
|
351 |
+
case 'attribute':
|
352 |
+
//Join segments
|
353 |
+
$delim = '_';
|
354 |
+
$fmtd = implode($delim, $attribute);
|
355 |
+
//Replace white space and repeating delimiters
|
356 |
+
$fmtd = str_replace(' ', $delim, $fmtd);
|
357 |
+
while (strpos($fmtd, $delim.$delim) !== false)
|
358 |
+
$fmtd = str_replace($delim.$delim, $delim, $fmtd);
|
359 |
+
//Prefix formatted value with delimeter for metadata keys
|
360 |
+
if ('metadata' == $format)
|
361 |
+
$fmtd = $delim . $fmtd;
|
362 |
+
break;
|
363 |
+
case 'path':
|
364 |
+
case 'post':
|
365 |
+
default:
|
366 |
+
$fmtd = '["' . implode('"]["', $attribute) . '"]';
|
367 |
+
}
|
368 |
+
}
|
369 |
+
return $fmtd;
|
370 |
+
}
|
371 |
+
|
372 |
+
/**
|
373 |
+
* Builds array of path elements based on arguments
|
374 |
+
* Each item in path array represents a deeper level in structure path is for (object, array, filesystem, etc.)
|
375 |
+
* @param array|string Value to add to the path
|
376 |
+
* @return array 1-dimensional array of path elements
|
377 |
+
*/
|
378 |
+
function build_path() {
|
379 |
+
$path = array();
|
380 |
+
$args = func_get_args();
|
381 |
+
|
382 |
+
//Iterate through parameters and build path
|
383 |
+
foreach ( $args as $arg ) {
|
384 |
+
if ( empty($arg) )
|
385 |
+
continue;
|
386 |
+
|
387 |
+
if (is_array($arg)) {
|
388 |
+
//Recurse through array items to pull out any more arrays
|
389 |
+
foreach ($arg as $key => $val) {
|
390 |
+
$path = array_merge($path, $this->build_path($val));
|
391 |
+
}
|
392 |
+
//$path = array_merge($path, array_values($arg));
|
393 |
+
} elseif ( is_scalar($arg) ) {
|
394 |
+
$path[] = $arg;
|
395 |
+
}
|
396 |
+
}
|
397 |
+
|
398 |
+
return $path;
|
399 |
+
}
|
400 |
+
|
401 |
+
/**
|
402 |
+
* Builds attribute string for HTML element
|
403 |
+
* @param array $attr Attributes
|
404 |
+
* @return string Formatted attribute string
|
405 |
+
*/
|
406 |
+
function build_attribute_string($attr) {
|
407 |
+
$ret = '';
|
408 |
+
if ( is_object($attr) )
|
409 |
+
$attr = (array) $attr;
|
410 |
+
if ( is_array($attr) ) {
|
411 |
+
array_map('esc_attr', $attr);
|
412 |
+
$attr_str = array();
|
413 |
+
foreach ( $attr as $key => $val ) {
|
414 |
+
$attr_str[] = $key . '="' . $val . '"';
|
415 |
+
}
|
416 |
+
$ret = implode(' ', $attr_str);
|
417 |
+
}
|
418 |
+
return $ret;
|
419 |
+
}
|
420 |
+
|
421 |
+
/*-** Admin **-*/
|
422 |
+
|
423 |
+
/**
|
424 |
+
* Add submenu page in the admin menu
|
425 |
+
* Adds ability to set the position of the page in the menu
|
426 |
+
* @see add_submin_menu (Wraps functionality)
|
427 |
+
*
|
428 |
+
* @param $parent
|
429 |
+
* @param $page_title
|
430 |
+
* @param $menu_title
|
431 |
+
* @param $access_level
|
432 |
+
* @param $file
|
433 |
+
* @param $function
|
434 |
+
* @param int $pos Index position of menu page
|
435 |
+
*
|
436 |
+
* @global array $submenu Admin page submenus
|
437 |
+
*/
|
438 |
+
function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '', $pos = false) {
|
439 |
+
global $submenu;
|
440 |
+
|
441 |
+
//Add submenu page as usual
|
442 |
+
$args = func_get_args();
|
443 |
+
$hookname = call_user_func_array('add_submenu_page', $args);
|
444 |
+
|
445 |
+
if ( is_int($pos) ) {
|
446 |
+
//Get last submenu added
|
447 |
+
$parent = $this->get_submenu_parent_file($parent);
|
448 |
+
$subs =& $submenu[$parent];
|
449 |
+
|
450 |
+
//Make sure menu isn't already in the desired position
|
451 |
+
if ( $pos <= ( count($subs) - 1 ) ) {
|
452 |
+
//Get submenu that was just added
|
453 |
+
$sub = array_pop($subs);
|
454 |
+
//Insert into desired position
|
455 |
+
if ( 0 == $pos ) {
|
456 |
+
array_unshift($subs, $sub);
|
457 |
+
} else {
|
458 |
+
$top = array_slice($subs, 0, $pos);
|
459 |
+
$bottom = array_slice($subs, $pos);
|
460 |
+
array_push($top, $sub);
|
461 |
+
$subs = array_merge($top, $bottom);
|
462 |
+
}
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
return $hookname;
|
467 |
+
}
|
468 |
+
|
469 |
+
/**
|
470 |
+
* Remove admin submenu
|
471 |
+
* @param string $parent Submenu parent file
|
472 |
+
* @param string $file Submenu file name
|
473 |
+
* @return int|null Index of removed submenu (NULL if submenu not found)
|
474 |
+
*
|
475 |
+
* @global array $submenu
|
476 |
+
* @global array $_registered_pages
|
477 |
+
*/
|
478 |
+
function remove_submenu_page($parent, $file) {
|
479 |
+
global $submenu, $_registered_pages;
|
480 |
+
$ret = null;
|
481 |
+
|
482 |
+
$parent = $this->get_submenu_parent_file($parent);
|
483 |
+
$file = plugin_basename($file);
|
484 |
+
$file_index = 2;
|
485 |
+
|
486 |
+
//Find submenu
|
487 |
+
if ( isset($submenu[$parent]) ) {
|
488 |
+
$subs =& $submenu[$parent];
|
489 |
+
for ($x = 0; $x < count($subs); $x++) {
|
490 |
+
if ( $subs[$x][$file_index] == $file ) {
|
491 |
+
//Remove matching submenu
|
492 |
+
$hookname = get_plugin_page_hookname($file, $parent);
|
493 |
+
remove_all_actions($hookname);
|
494 |
+
unset($_registered_pages[$hookname]);
|
495 |
+
unset($subs[$x]);
|
496 |
+
$subs = array_values($subs);
|
497 |
+
//Set index and stop processing
|
498 |
+
$ret = $x;
|
499 |
+
break;
|
500 |
+
}
|
501 |
+
}
|
502 |
+
}
|
503 |
+
|
504 |
+
return $ret;
|
505 |
+
}
|
506 |
+
|
507 |
+
/**
|
508 |
+
* Replace a submenu page
|
509 |
+
* Adds a submenu page in the place of an existing submenu page that has the same $file value
|
510 |
+
*
|
511 |
+
* @param $parent
|
512 |
+
* @param $page_title
|
513 |
+
* @param $menu_title
|
514 |
+
* @param $access_level
|
515 |
+
* @param $file
|
516 |
+
* @param $function
|
517 |
+
* @return string Hookname
|
518 |
+
*
|
519 |
+
* @global array $submenu
|
520 |
+
*/
|
521 |
+
function replace_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function = '') {
|
522 |
+
global $submenu;
|
523 |
+
//Remove matching submenu (if exists)
|
524 |
+
$pos = $this->remove_submenu_page($parent, $file);
|
525 |
+
//Insert submenu page
|
526 |
+
$hookname = $this->add_submenu_page($parent, $page_title, $menu_title, $access_level, $file, $function, $pos);
|
527 |
+
return $hookname;
|
528 |
+
}
|
529 |
+
|
530 |
+
/**
|
531 |
+
* Retrieves parent file for submenu
|
532 |
+
* @param string $parent Parent file
|
533 |
+
* @return string Formatted parent file name
|
534 |
+
*
|
535 |
+
* @global array $_wp_real_parent_file;
|
536 |
+
*/
|
537 |
+
function get_submenu_parent_file($parent) {
|
538 |
+
global $_wp_real_parent_file;
|
539 |
+
$parent = plugin_basename($parent);
|
540 |
+
if ( isset($_wp_real_parent_file[$parent]) )
|
541 |
+
$parent = $_wp_real_parent_file[$parent];
|
542 |
+
return $parent;
|
543 |
+
}
|
544 |
+
}
|
js/admin.js
ADDED
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Admin JS
|
3 |
+
* @package Favicon Rotator
|
4 |
+
*/
|
5 |
+
|
6 |
+
/* Prototypes */
|
7 |
+
|
8 |
+
if ( !Array.indexOf ) {
|
9 |
+
Array.prototype.indexOf = function(val) {
|
10 |
+
for ( var x = 0; x < this.length; x++ ) {
|
11 |
+
if ( this[x] == val )
|
12 |
+
return x;
|
13 |
+
}
|
14 |
+
return -1;
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
if ( typeof(fvrt) == 'undefined' || typeof(fvrt) != 'object' )
|
19 |
+
fvrt = {};
|
20 |
+
(function($) {
|
21 |
+
/**
|
22 |
+
* Initialization routines
|
23 |
+
*/
|
24 |
+
fvrt['init'] = function() {
|
25 |
+
this.setupActions();
|
26 |
+
};
|
27 |
+
|
28 |
+
fvrt['sel'] = {
|
29 |
+
list: '#fv_list',
|
30 |
+
item: '.fv_item',
|
31 |
+
image: '.icon',
|
32 |
+
details: '.details',
|
33 |
+
name: '.name',
|
34 |
+
itemTemplate: '#fv_item_temp',
|
35 |
+
remove: '.remove',
|
36 |
+
field: '#fv_ids'
|
37 |
+
};
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Setup event actions for icon elements
|
41 |
+
*/
|
42 |
+
fvrt['setupActions'] = function() {
|
43 |
+
//Get remove links on page
|
44 |
+
var t = this;
|
45 |
+
$(this.buildSelector('list', 'item', 'remove')).live('click', function() {
|
46 |
+
t.removeItem(this);
|
47 |
+
return false;
|
48 |
+
});
|
49 |
+
};
|
50 |
+
|
51 |
+
fvrt['buildSelector'] = function() {
|
52 |
+
var sel = [];
|
53 |
+
for ( var i = 0; i < arguments.length; i++ ) {
|
54 |
+
if ( arguments[i] in this.sel ) {
|
55 |
+
sel.push(this.sel[arguments[i]]);
|
56 |
+
}
|
57 |
+
}
|
58 |
+
return sel.length ? sel.join(' ') : '';
|
59 |
+
};
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Retrieve IDs hidden field
|
63 |
+
* @return object IDs field
|
64 |
+
*/
|
65 |
+
fvrt['getField'] = function() {
|
66 |
+
return $(this.sel.field);
|
67 |
+
};
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Gets IDs of icons
|
71 |
+
* @return array Icon IDs
|
72 |
+
*/
|
73 |
+
fvrt['getIds'] = function() {
|
74 |
+
return $(this.getField()).val().split(',');
|
75 |
+
};
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Check if ID is already added
|
79 |
+
* @param int itemId Icon ID
|
80 |
+
* @return bool TRUE if icon is already added
|
81 |
+
*/
|
82 |
+
fvrt['hasId'] = function(itemId) {
|
83 |
+
return ( this.getIds().indexOf(itemId) != -1 ) ? true : false;
|
84 |
+
};
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Sets list of Icon IDs
|
88 |
+
* @param array Icon IDs
|
89 |
+
*/
|
90 |
+
fvrt['setIds'] = function(ids) {
|
91 |
+
$(this.getField()).val(ids.join(','));
|
92 |
+
};
|
93 |
+
|
94 |
+
/**
|
95 |
+
* Add ID to IDs field
|
96 |
+
* @param int itemId Attachment ID to add
|
97 |
+
*/
|
98 |
+
fvrt['addId'] = function(itemId) {
|
99 |
+
if ( !this.hasId(itemId) ) {
|
100 |
+
var vals = this.getIds();
|
101 |
+
vals.push(itemId);
|
102 |
+
this.setIds(vals);
|
103 |
+
}
|
104 |
+
};
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Remove ID from IDs field
|
108 |
+
* @param int itemId Icon ID to remove
|
109 |
+
*/
|
110 |
+
fvrt['removeId'] = function(itemId) {
|
111 |
+
var vals = this.getIds();
|
112 |
+
var idx = vals.indexOf(itemId);
|
113 |
+
if ( idx != -1 )
|
114 |
+
vals.splice(idx, 1);
|
115 |
+
this.setIds(vals);
|
116 |
+
};
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Get Icon ID of specified item
|
120 |
+
* @param {Object} el Node element
|
121 |
+
*/
|
122 |
+
fvrt['getItemId'] = function(el) {
|
123 |
+
var id = '';
|
124 |
+
var parts = el.id.split('_');
|
125 |
+
if ( parts.length )
|
126 |
+
id = parts[parts.length - 1];
|
127 |
+
return id;
|
128 |
+
};
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Add item to list
|
132 |
+
* @param object args Icon properties
|
133 |
+
* id: Attachment ID
|
134 |
+
* name: File name
|
135 |
+
* url: Attachment URL
|
136 |
+
*/
|
137 |
+
fvrt['addItem'] = function(args) {
|
138 |
+
if (typeof args == 'object' && args.id && args.name && args.url && !this.hasId(args.id)) {
|
139 |
+
//Build new item
|
140 |
+
var item = $(this.sel.itemTemplate).clone();
|
141 |
+
$(item).attr('id', 'fv_item_' + args.id);
|
142 |
+
$(item).find(this.sel.image).attr('src', args.url);
|
143 |
+
$(item).find(this.sel.name).text(args.name);
|
144 |
+
$(item).find(this.sel.remove).attr('id', 'fv_id_' + args.id);
|
145 |
+
|
146 |
+
//Add element to container
|
147 |
+
$(item).appendTo(this.sel.list)
|
148 |
+
|
149 |
+
//Add element ID to list
|
150 |
+
this.addId(args.id);
|
151 |
+
}
|
152 |
+
};
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Remove item from list
|
156 |
+
* @param {Object} el Node to remove
|
157 |
+
*/
|
158 |
+
fvrt['removeItem'] = function(el) {
|
159 |
+
//Get ID of item
|
160 |
+
var id = this.getItemId(el);
|
161 |
+
//Remove item
|
162 |
+
$(el).parents('.fv_item').remove();
|
163 |
+
//Remove ID from field
|
164 |
+
this.removeId(id);
|
165 |
+
};
|
166 |
+
|
167 |
+
//Initialize on document load
|
168 |
+
$(document).ready(function() {fvrt.init();});
|
169 |
+
}) (jQuery);
|
js/media.js
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Media
|
3 |
+
* @package Favicon Rotator
|
4 |
+
* @author Archetyped
|
5 |
+
*/
|
6 |
+
|
7 |
+
if ( typeof(fvrt) == 'undefined' || typeof(fvrt) != 'object' )
|
8 |
+
fvrt = {};
|
9 |
+
(function($) {
|
10 |
+
fvrt['media'] = {
|
11 |
+
/**
|
12 |
+
* Set selected image as an icon in rotation
|
13 |
+
* @param object a Media arguments
|
14 |
+
* Arguments
|
15 |
+
* id: Attachment ID
|
16 |
+
* name: Attachment file name
|
17 |
+
* url: Attachment URL
|
18 |
+
*/
|
19 |
+
setIcon : function (a) {
|
20 |
+
if ( typeof(a) == 'object' ) {
|
21 |
+
fvrt.addItem(a);
|
22 |
+
}
|
23 |
+
//Close popup
|
24 |
+
tb_remove();
|
25 |
+
}
|
26 |
+
}
|
27 |
+
})(jQuery);
|
main.php
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Favicon Rotator
|
4 |
+
Plugin URI: http://archetyped.com/tools/favicon-rotator/
|
5 |
+
Description: Easily set site favicon and even rotate through multiple icons
|
6 |
+
Version: 1.0
|
7 |
+
Author: Archetyped
|
8 |
+
Author URI: http://archetyped.com
|
9 |
+
*/
|
10 |
+
|
11 |
+
require_once 'model.php';
|
12 |
+
$fvrt = new FaviconRotator();
|
model.php
ADDED
@@ -0,0 +1,330 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
require_once 'includes/class.base.php';
|
4 |
+
require_once 'includes/class.media.php';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Redactor class
|
8 |
+
* @author Archetyped
|
9 |
+
*
|
10 |
+
*/
|
11 |
+
class FaviconRotator extends FVRT_Base {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Admin Page hook
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
+
var $page;
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Plugin options
|
21 |
+
* @var array
|
22 |
+
*/
|
23 |
+
var $options = null;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Plugin Options key
|
27 |
+
* @var string
|
28 |
+
*/
|
29 |
+
var $opt_key = 'options';
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Key to use for icons array in options
|
33 |
+
* @var string
|
34 |
+
*/
|
35 |
+
var $opt_icons = 'icons';
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Save action
|
39 |
+
* @var string
|
40 |
+
*/
|
41 |
+
var $action_save = 'action_save';
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Path to admin contextual help file
|
45 |
+
* @var string
|
46 |
+
*/
|
47 |
+
var $file_admin_help = 'resources/admin_help.html';
|
48 |
+
|
49 |
+
/*-** Instance objects **-*/
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Media instance
|
53 |
+
* @var FVRT_Media
|
54 |
+
*/
|
55 |
+
var $media;
|
56 |
+
|
57 |
+
/*-** Initialization **-*/
|
58 |
+
|
59 |
+
function FaviconRotator() {
|
60 |
+
$this->__construct();
|
61 |
+
}
|
62 |
+
|
63 |
+
function __construct() {
|
64 |
+
parent::__construct();
|
65 |
+
$this->opt_key = $this->add_prefix($this->opt_key);
|
66 |
+
$this->action_save = $this->add_prefix($this->action_save);
|
67 |
+
$this->media =& new FVRT_Media();
|
68 |
+
$this->register_hooks();
|
69 |
+
}
|
70 |
+
|
71 |
+
function register_hooks() {
|
72 |
+
/*-** Admin **-*/
|
73 |
+
|
74 |
+
//Menu
|
75 |
+
add_action('admin_menu', $this->m('admin_menu'));
|
76 |
+
//Plugins page
|
77 |
+
add_filter('plugin_action_links_' . $this->util->get_plugin_base_name(), $this->m('admin_plugin_action_links'), 10, 4);
|
78 |
+
|
79 |
+
/*-** Main **-*/
|
80 |
+
|
81 |
+
//Template
|
82 |
+
add_action('wp_head', $this->m('display_icon'));
|
83 |
+
|
84 |
+
//Instance setup
|
85 |
+
$this->media->register_hooks();
|
86 |
+
}
|
87 |
+
|
88 |
+
/*-** Helpers **-*/
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Retrieve options array (or specific option if specified)
|
92 |
+
* @param $key Option to retrieve
|
93 |
+
* @return mixed Full options array or value of specific key (Default: empty array)
|
94 |
+
*/
|
95 |
+
function get_options($key = null) {
|
96 |
+
//Retrieve options entry from DB
|
97 |
+
$ret = $this->options;
|
98 |
+
if ( is_null($ret) ) {
|
99 |
+
$ret = get_option($this->opt_key);
|
100 |
+
if ( false === $ret )
|
101 |
+
$ret = array();
|
102 |
+
$this->options = $ret;
|
103 |
+
}
|
104 |
+
|
105 |
+
if ( !is_null($key) && isset($ret[$key]) )
|
106 |
+
$ret = $ret[$key];
|
107 |
+
return $ret;
|
108 |
+
}
|
109 |
+
|
110 |
+
function set_option($key, $val) {
|
111 |
+
//Make sure options array initialized
|
112 |
+
$this->get_options();
|
113 |
+
//Set option value
|
114 |
+
$this->options[$key] = $val;
|
115 |
+
//Save updated options to DB
|
116 |
+
update_option($this->opt_key, $this->options);
|
117 |
+
}
|
118 |
+
|
119 |
+
/*-** Media **-*/
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Retrieve Post IDs of favicons
|
123 |
+
* @return array Icon IDs
|
124 |
+
*/
|
125 |
+
function get_icon_ids() {
|
126 |
+
//Get array of post IDs for icons
|
127 |
+
$icons = $this->get_options($this->opt_icons);
|
128 |
+
return $icons;
|
129 |
+
}
|
130 |
+
|
131 |
+
function get_icon_ids_list() {
|
132 |
+
return implode(',', $this->get_icon_ids());
|
133 |
+
}
|
134 |
+
|
135 |
+
/**
|
136 |
+
* Retrieve icons saved in options menu
|
137 |
+
* @return array Media attachment objects
|
138 |
+
*/
|
139 |
+
function get_icons() {
|
140 |
+
$icons = array();
|
141 |
+
//Get icon ids
|
142 |
+
$ids = $this->get_icon_ids();
|
143 |
+
//Retrieve attachment objects
|
144 |
+
if ( !empty($ids) ) {
|
145 |
+
$icons = get_posts(array('post_type' => 'attachment', 'include' => $ids));
|
146 |
+
}
|
147 |
+
return $icons;
|
148 |
+
}
|
149 |
+
|
150 |
+
/**
|
151 |
+
* Save list of selected icons to DB
|
152 |
+
*/
|
153 |
+
function save_icons($ids = null) {
|
154 |
+
//Check if valid icon IDs are passed to function
|
155 |
+
if ( !is_null($ids) ) {
|
156 |
+
if ( !is_array($ids) ) {
|
157 |
+
$ids = ( is_int($ids) ) ? array($ids) : null;
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
+
//Get icon IDs from form submission
|
162 |
+
if ( is_null($ids) && isset($_POST['fv_ids']) && check_admin_referer($this->action_save) )
|
163 |
+
$ids = explode(',', $_POST['fv_ids']);
|
164 |
+
|
165 |
+
//Save to DB
|
166 |
+
if ( is_array($ids) )
|
167 |
+
$this->set_option($this->opt_icons, $ids);
|
168 |
+
}
|
169 |
+
|
170 |
+
/**
|
171 |
+
* Build favicon element for output in template
|
172 |
+
*/
|
173 |
+
function display_icon() {
|
174 |
+
//Get icons
|
175 |
+
$icons = $icons_orig = $this->get_icon_ids();
|
176 |
+
$icon = null;
|
177 |
+
//Retrieve icon data
|
178 |
+
while ( is_null($icon) && count($icons) > 0 ) {
|
179 |
+
//Select one from random
|
180 |
+
$idx = ( count($icons) > 1 ) ? array_rand($icons) : 0;
|
181 |
+
$icon_id = $icons[$idx];
|
182 |
+
$icon = wp_get_attachment_url($icon_id);
|
183 |
+
if ( !$icon || ( !wp_attachment_is_image($icon_id) && 'ico' != substr($icon, strrpos($icon, '.') + 1) ) ) {
|
184 |
+
//Reset variable to NULL
|
185 |
+
$icon = null;
|
186 |
+
//Remove icon from list (no longer valid)
|
187 |
+
unset($icons[$idx]);
|
188 |
+
array_values($icons);
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
//Display icon
|
193 |
+
if ( !is_null($icon) ) {
|
194 |
+
?>
|
195 |
+
<link rel="shortcut icon" href="<?php echo esc_attr($icon); ?>" />
|
196 |
+
<?php
|
197 |
+
}
|
198 |
+
|
199 |
+
//Update icons array (if necessary)
|
200 |
+
if ( $icons !== $icons_orig )
|
201 |
+
$this->save_icons($icons);
|
202 |
+
}
|
203 |
+
|
204 |
+
/*-** Admin **-*/
|
205 |
+
|
206 |
+
/**
|
207 |
+
* Adds custom links below plugin on plugin listing page
|
208 |
+
* @param $actions
|
209 |
+
* @param $plugin_file
|
210 |
+
* @param $plugin_data
|
211 |
+
* @param $context
|
212 |
+
*/
|
213 |
+
function admin_plugin_action_links($actions, $plugin_file, $plugin_data, $context) {
|
214 |
+
//Add link to settings (only if active)
|
215 |
+
if ( is_plugin_active($this->util->get_plugin_base_name()) ) {
|
216 |
+
$settings = __('Settings');
|
217 |
+
$settings_url = add_query_arg('page', dirname($this->util->get_plugin_base_name()), admin_url('themes.php'));
|
218 |
+
array_unshift($actions, '<a href="' . $settings_url . '" title="' . $settings . '">' . $settings . '</a>');
|
219 |
+
}
|
220 |
+
return $actions;
|
221 |
+
}
|
222 |
+
|
223 |
+
/**
|
224 |
+
* Get ID of settings section on admin page
|
225 |
+
* @return string ID of settings section
|
226 |
+
*/
|
227 |
+
function admin_get_settings_section() {
|
228 |
+
return $this->add_prefix('settings');
|
229 |
+
}
|
230 |
+
|
231 |
+
/**
|
232 |
+
* Adds admin submenu item to Appearance menu
|
233 |
+
*/
|
234 |
+
function admin_menu() {
|
235 |
+
$this->page = $p = add_theme_page(__('Favicon'), __('Favicon'), 'edit_theme_options', $this->util->get_plugin_base(), $this->m('admin_page'));
|
236 |
+
//Head
|
237 |
+
add_action("admin_print_scripts-$p", $this->m('admin_scripts'));
|
238 |
+
add_action("admin_print_styles-$p", $this->m('admin_styles'));
|
239 |
+
add_action("admin_head-$p", $this->m('admin_help'));
|
240 |
+
}
|
241 |
+
|
242 |
+
|
243 |
+
/**
|
244 |
+
* Defines content for admin page
|
245 |
+
*/
|
246 |
+
function admin_page() {
|
247 |
+
if ( ! current_user_can('edit_theme_options') )
|
248 |
+
wp_die(__('You do not have permission to customize favicons.'));
|
249 |
+
|
250 |
+
//Get saved icons
|
251 |
+
if ( isset($_POST['fv_submit']) )
|
252 |
+
$this->save_icons();
|
253 |
+
$icons = $this->get_icons();
|
254 |
+
?>
|
255 |
+
|
256 |
+
<div class="wrap">
|
257 |
+
<?php screen_icon(); ?>
|
258 |
+
<h2><?php _e('Favicon Rotator'); ?> <a href="<?php echo $this->media->get_upload_iframe_src('image'); ?>" class="button add-new-h2 thickbox" title="<?php esc_attr_e('Add Icon'); ?>"><?php echo esc_html_x('Add new', 'file')?></a></h2>
|
259 |
+
<div id="fv_list_container">
|
260 |
+
<?php if ( !$icons ) : ?>
|
261 |
+
<p>No favicons set</p>
|
262 |
+
<?php endif; //No icons message ?>
|
263 |
+
<ul id="fv_list">
|
264 |
+
<?php foreach ( $icons as $icon ) : //List icons
|
265 |
+
$src = wp_get_attachment_image_src($icon->ID, 'full');
|
266 |
+
$src = $src[0];
|
267 |
+
?>
|
268 |
+
<li class="fv_item">
|
269 |
+
<div>
|
270 |
+
<img class="icon" src="<?php echo $src; ?>" />
|
271 |
+
<div class="details">
|
272 |
+
<div class="name"><?php echo basename($src); ?></div>
|
273 |
+
<div class="options">
|
274 |
+
<a href="#" id="fv_id_<?php echo esc_attr($icon->ID); ?>" class="remove">Remove</a>
|
275 |
+
</div>
|
276 |
+
</div>
|
277 |
+
</div>
|
278 |
+
</li>
|
279 |
+
<?php endforeach; //End icon listing ?>
|
280 |
+
</ul>
|
281 |
+
<div style="display: none">
|
282 |
+
<li id="fv_item_temp" class="fv_item">
|
283 |
+
<div>
|
284 |
+
<img class="icon" src="" />
|
285 |
+
<div class="details">
|
286 |
+
<div class="name"></div>
|
287 |
+
<div class="options">
|
288 |
+
<a href="#" class="remove">Remove</a>
|
289 |
+
</div>
|
290 |
+
</div>
|
291 |
+
</div>
|
292 |
+
</li>
|
293 |
+
</div>
|
294 |
+
</div>
|
295 |
+
<form method="post" action="<?php echo esc_attr($_SERVER['REQUEST_URI']); ?>">
|
296 |
+
<input type="hidden" id="fv_ids" name="fv_ids" value="<?php echo esc_attr($this->get_icon_ids_list()); ?>" />
|
297 |
+
<?php wp_nonce_field($this->action_save); ?>
|
298 |
+
<p class="submit"><input type="submit" class="button-primary" name="fv_submit" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p>
|
299 |
+
</form>
|
300 |
+
</div>
|
301 |
+
<?php
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Adds JS to Admin page
|
306 |
+
*/
|
307 |
+
function admin_scripts() {
|
308 |
+
wp_enqueue_script('media-upload');
|
309 |
+
$h_admin = $this->add_prefix('admin_script');
|
310 |
+
$h_media = $this->add_prefix('media');
|
311 |
+
wp_enqueue_script($h_admin, $this->util->get_file_url('js/admin.js'), array('jquery', 'thickbox'));
|
312 |
+
wp_enqueue_script($h_media, $this->util->get_file_url('js/media.js'), array('jquery', $h_admin));
|
313 |
+
}
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Adds CSS to Admin page
|
317 |
+
*/
|
318 |
+
function admin_styles() {
|
319 |
+
add_thickbox();
|
320 |
+
wp_enqueue_style($this->add_prefix('admin_styles'), $this->util->get_file_url('css/admin_styles.css'));
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* Add contextual help to admin page
|
325 |
+
*/
|
326 |
+
function admin_help() {
|
327 |
+
$help = file_get_contents(dirname(__FILE__) . '/resources/admin_help.html');
|
328 |
+
add_contextual_help($this->page, $help);
|
329 |
+
}
|
330 |
+
}
|
readme.txt
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== Plugin Name ===
|
2 |
+
Contributors: archetyped
|
3 |
+
Tags: favicon,icon,template,theme,customization,simple,media
|
4 |
+
Requires at least: 3.0
|
5 |
+
Tested up to: 3.0.1
|
6 |
+
Stable tag: trunk
|
7 |
+
|
8 |
+
Easily set site favicon and even rotate through multiple icons
|
9 |
+
|
10 |
+
== Description ==
|
11 |
+
|
12 |
+
Favicon Rotator makes it easy to customize the favicon for your site. Just add a favicon below and it will be displayed whenever someone visits your site.
|
13 |
+
|
14 |
+
Favicon Rotator supports **multiple icons**, from which a **randomly selected** favicon from the rotation will be displayed.
|
15 |
+
|
16 |
+
[More Information on Favicons](http://wikipedia.org/wiki/Favicon)
|
17 |
+
|
18 |
+
== Installation ==
|
19 |
+
|
20 |
+
1. Activate the plugin through the 'Plugins' menu in WordPress
|
21 |
+
1. Go to **Theme > Favicon** admin page to add images to use for the favicon
|
22 |
+
1. Verify that your theme uses the `wp_head()` template tag (this is where the necessary code will be added to your theme output)
|
23 |
+
1. Plugin will automatically add a favicon from the rotation to your theme when a visitor loads your site
|
24 |
+
|
25 |
+
== Upgrade Notice ==
|
26 |
+
|
27 |
+
No upgrade notices
|
28 |
+
|
29 |
+
== Frequently Asked Questions ==
|
30 |
+
|
31 |
+
Go to http://archetyped.com/tools/favicon-rotator/ for any questions or comments
|
32 |
+
|
33 |
+
== Screenshots ==
|
34 |
+
|
35 |
+
1. Simple Administration
|
36 |
+
1. Favicon submenu in Appearance menu
|
37 |
+
|
38 |
+
== Changelog ==
|
39 |
+
= 1.0 =
|
40 |
+
* Initial release
|
resources/admin_help.html
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<p>Favicon Rotator makes it easy to customize the favicon for your site. Just add a favicon below and it will be displayed whenever someone visits your site.</p>
|
2 |
+
<p>Favicon Rotator supports <strong>multiple icons</strong>, from which a <strong>randomly selected</strong> favicon from the rotation will be displayed.</p>
|
3 |
+
<h3>Adding an icon to the rotation</h3>
|
4 |
+
<ol>
|
5 |
+
<li>Click "Add new" button</li>
|
6 |
+
<li>Upload an image or select an image from the Library tab</li>
|
7 |
+
<li>Click the "Add icon" button to add it to the rotation</li>
|
8 |
+
<li>Click "Save Changes" button</li>
|
9 |
+
</ol>
|
10 |
+
<h3>Removing an icon from the rotation</h3>
|
11 |
+
<ol>
|
12 |
+
<li>Click the "x" button in the upper-right corner of the icon you want to remove</li>
|
13 |
+
<li>Click "Save Changes" button</li>
|
14 |
+
</ol>
|
15 |
+
<p><a href="http://archetyped.com/tools/favicon-rotator/" title="Favicon Home Page" target="_blank">Favicon Rotator Home page</a></p>
|
16 |
+
<p><a href="http://wikipedia.org/wiki/Favicon" title="Favicon Information" target="_blank">Favicon Information</a></p>
|
screenshot-1.png
ADDED
Binary file
|
screenshot-2.png
ADDED
Binary file
|