Ultimate Posts Widget - Version 2.0.0

Version Description

  • Added a new standard template and custom template support
  • Added basic CSS styles for better formatting
  • Add hfeed microformat into new standard template
  • Improved widget options interface
  • Add option to filter by tags or current tag
  • Remove timthumb in favor of using built-in WordPress image sizes
  • Remove widget "More Button" options
  • Change date display options to now accept any custom date formats
  • Add before and after posts HTML fields
  • Add option for widget CSS class (thanks @avenirer)
  • Add option to display comment count
  • Set better defaults for newly created widgets
  • Various bug fixes and optimizations

Upgrading from an earlier version?

  • Upgrades from prior to 2.0.0 we retain the "legacy" template for you. To change which template to use, find the "Template" option under the "Display" tab.
  • If you used the "More Button", you will need to add in your own HTML into one of the new fields since the more button is now removed.
  • If you used custom thumbnail settings you will need to update them. You can now choose from pre-defined sizes available to WordPress. If you need an additional image size please see how to add image sizes.
  • Date formatting has changed, you will need to update your settings. By default it uses WordPress' date/time options.
Download this release

Release Info

Developer bostondv
Plugin Icon wp plugin Ultimate Posts Widget
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.8.1 to 2.0.0

.editorconfig ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ indent_style = space
7
+ indent_size = 2
8
+ end_of_line = lf
9
+ charset = utf-8
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
.gitignore CHANGED
@@ -1,2 +1,3 @@
1
  .svn
2
- cache/timthumb_int*
 
1
  .svn
2
+ node_modules
3
+ .sass-cache
cache/timthumb_cacheLastCleanTime.touch DELETED
File without changes
composer.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "bostondv/ultimate-posts-widget",
3
+ "type": "wordpress-plugin",
4
+ "license": "GPLv3",
5
+ "description": "The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.",
6
+ "homepage": "http://wordpress.org/plugins/ultimate-posts-widget/",
7
+ "authors": [
8
+ {
9
+ "name": "Boston Dell-Vandenberg",
10
+ "email": "boston@pomelodesign.com",
11
+ "homepage": "https://github.com/bostondv/"
12
+ }
13
+ ],
14
+ "keywords": [
15
+ "wordpress"
16
+ ],
17
+ "support": {
18
+ "issues": "https://github.com/bostondv/ultimate-posts-widget/issues/",
19
+ "forum": "http://wordpress.org/support/plugin/ultimate-posts-widget/"
20
+ },
21
+ "require": {
22
+ "php": ">=5.3.0",
23
+ "composer/installers": "~1.0"
24
+ }
25
+ }
css/upw-admin.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .upw-divider{border:0;border-top:1px solid #DFDFDF}.upw-tabs{display:block;border-bottom:1px solid #DFDFDF;margin:1em 0}.upw-tab-item{display:inline-block;border:1px solid transparent;border-bottom:0;color:#666;padding:8px 10px}.upw-tab-item:not(.active):focus,.upw-tab-item:not(.active):hover{color:#4d4d4d;background-color:#f7f7f7;cursor:pointer}.upw-tab-item:not(.active):active{color:#333;background-color:#f0f0f0}.upw-tab-item.active{color:#444;border-color:#DFDFDF;background:#fff;position:relative;bottom:-1px;cursor:default;font-weight:700}.upw-hide{display:none!important}.upw-credits{font-size:.9em;background:#f7f7f7;border:1px solid #ebebeb;padding:4px 6px}
css/upw-theme-standard.min.css ADDED
@@ -0,0 +1 @@
 
1
+ .upw-posts .hentry{display:block;margin-bottom:1.5rem;padding-bottom:1rem;border-bottom:1px solid #ddd}.upw-posts .hentry:last-child{border-bottom:0;padding-bottom:0}.upw-posts .entry-title{margin-bottom:.5rem}.upw-posts .entry-title a{text-decoration:none}.upw-posts .entry-title a:focus,.upw-posts .entry-title a:hover{text-decoration:underline}.upw-posts .entry-image{margin-bottom:1rem}.upw-posts .entry-image img{max-width:100%;height:auto}.upw-posts .entry-meta{color:#888;font-size:.9rem;margin-bottom:1rem;line-height:1.4}.upw-posts .entry-meta .comments{white-space:nowrap}.upw-posts .entry-content>:last-child,.upw-posts .entry-summary>:last-child{margin-bottom:1rem}.upw-posts .more-link{white-space:nowrap}.upw-posts footer{display:block;color:#888;font-size:.9rem;line-height:1.4}.upw-posts .custom-field,.upw-posts .entry-categories,.upw-posts .entry-custom-fields,.upw-posts .entry-tags{margin-bottom:.5rem}.upw-after,.upw-before{margin-bottom:1rem}.upw-after>:last-child,.upw-before>:last-child{margin-bottom:0}
gulpfile.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var gulp = require('gulp');
2
+ var sass = require('gulp-ruby-sass');
3
+ var prefix = require('gulp-autoprefixer');
4
+ var minify = require('gulp-minify-css');
5
+ var rename = require('gulp-rename');
6
+ var util = require('gulp-util');
7
+ var size = require('gulp-size');
8
+ var uglify = require('gulp-uglifyjs');
9
+
10
+ gulp.task('styles', function () {
11
+ return gulp.src([
12
+ 'scss/*.scss'
13
+ ])
14
+ .pipe(sass({
15
+ precision: 10
16
+ }))
17
+ .pipe(prefix('last 2 versions', 'ie 8'))
18
+ .pipe(minify({ keepSpecialComments: 1 }))
19
+ .pipe(size({
20
+ showFiles: true,
21
+ gzip: true,
22
+ title: 'Styles'
23
+ }))
24
+ .pipe(rename({suffix: '.min'}))
25
+ .pipe(gulp.dest('css'));
26
+ });
27
+
28
+ gulp.task('scripts', function() {
29
+
30
+ return gulp.src([
31
+ 'js/*.js',
32
+ '!js/*.min.js'
33
+ ])
34
+ .pipe(uglify())
35
+ .pipe(size({
36
+ gzip: true,
37
+ title: 'Scripts'
38
+ }))
39
+ .pipe(rename({suffix: '.min'}))
40
+ .pipe(gulp.dest('js'));
41
+
42
+ });
43
+
44
+ gulp.task('watch', function () {
45
+ gulp.watch('scss/**/*.scss', ['styles']);
46
+ gulp.watch('js/**/*.js', ['scripts']);
47
+ });
48
+
49
+ gulp.task('default', ['styles', 'scripts']);
js/upw-admin.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function($) {
2
+
3
+ $('#widgets-right').on('click', '.upw-tab-item', function(event) {
4
+ event.preventDefault();
5
+ var widget = $(this).parents('.widget');
6
+ console.log(widget);
7
+ widget.find('.upw-tab-item').removeClass('active');
8
+ $(this).addClass('active');
9
+ widget.find('.upw-tab').addClass('upw-hide');
10
+ widget.find('.' + $(this).data('toggle')).removeClass('upw-hide');
11
+ });
12
+
13
+ });
js/upw-admin.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(document).ready(function(a){a("#widgets-right").on("click",".upw-tab-item",function(b){b.preventDefault();var c=a(this).parents(".widget");console.log(c),c.find(".upw-tab-item").removeClass("active"),a(this).addClass("active"),c.find(".upw-tab").addClass("upw-hide"),c.find("."+a(this).data("toggle")).removeClass("upw-hide")})});
cache/index.html → languages/.gitkeep RENAMED
File without changes
languages/upw-sv_SE.mo ADDED
Binary file
languages/upw-sv_SE.po ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Ultimate Posts\n"
4
+ "POT-Creation-Date: 2014-03-19 12:19+0100\n"
5
+ "PO-Revision-Date: 2014-03-19 12:54+0100\n"
6
+ "Last-Translator: Stefan Pettersson <stefan.pettersson@lumano.se>\n"
7
+ "Language-Team: \n"
8
+ "Language: sv_SE\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.3\n"
13
+ "X-Poedit-Basepath: /Users/stefan/Documents/plugins/ultimate-posts-widget/\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-KeywordsList: __;_e\n"
16
+ "X-Poedit-SearchPath-0: .\n"
17
+
18
+ #: ultimate-posts-widget.php:34
19
+ msgid "Displays list of posts with an array of options"
20
+ msgstr "Visar en lista med inlägg. Inställningarna skickas med i en array."
21
+
22
+ #: ultimate-posts-widget.php:41
23
+ msgid "Ultimate Posts"
24
+ msgstr ""
25
+
26
+ #: ultimate-posts-widget.php:211
27
+ msgid "By"
28
+ msgstr "Av"
29
+
30
+ #: ultimate-posts-widget.php:227 ultimate-posts-widget.php:569
31
+ msgid "Categories"
32
+ msgstr "Kategorier"
33
+
34
+ #: ultimate-posts-widget.php:234
35
+ msgid "Tags"
36
+ msgstr "Etiketter"
37
+
38
+ #: ultimate-posts-widget.php:279
39
+ msgid "No posts found."
40
+ msgstr "Hittade inga inlägg"
41
+
42
+ #: ultimate-posts-widget.php:353
43
+ msgid "Read more &rarr;"
44
+ msgstr "Läs mer &rarr;"
45
+
46
+ #: ultimate-posts-widget.php:356
47
+ msgid "View More Posts"
48
+ msgstr "Visa fler inlägg"
49
+
50
+ #: ultimate-posts-widget.php:433 ultimate-posts-widget.php:607
51
+ msgid "Title"
52
+ msgstr "Titel"
53
+
54
+ #: ultimate-posts-widget.php:438
55
+ msgid "Title URL"
56
+ msgstr "Titel URL"
57
+
58
+ #: ultimate-posts-widget.php:443
59
+ msgid "Number of posts"
60
+ msgstr "Antal inlägg"
61
+
62
+ #: ultimate-posts-widget.php:449
63
+ msgid "Show more button"
64
+ msgstr "Visa knapp \"Läs mer\""
65
+
66
+ #: ultimate-posts-widget.php:453
67
+ msgid "More button text"
68
+ msgstr "Text på knappen \"Läs mer\""
69
+
70
+ #: ultimate-posts-widget.php:458
71
+ msgid "More button URL"
72
+ msgstr "Url på knappen \"Läs mer\""
73
+
74
+ #: ultimate-posts-widget.php:468
75
+ msgid "Show title"
76
+ msgstr "Visa titel"
77
+
78
+ #: ultimate-posts-widget.php:473
79
+ msgid "Show published date"
80
+ msgstr "Visa publiceringsdatum"
81
+
82
+ #: ultimate-posts-widget.php:478
83
+ msgid "Show published time"
84
+ msgstr "Visa publiceringstid"
85
+
86
+ #: ultimate-posts-widget.php:483
87
+ msgid "Show post author"
88
+ msgstr "Visa inläggets författare"
89
+
90
+ #: ultimate-posts-widget.php:488
91
+ msgid "Show excerpt"
92
+ msgstr "Visa utdrag"
93
+
94
+ #: ultimate-posts-widget.php:492
95
+ msgid "Excerpt length (in words)"
96
+ msgstr "Längd på utdrag (antal ord)"
97
+
98
+ #: ultimate-posts-widget.php:498
99
+ msgid "Show content"
100
+ msgstr "Visa innehållet"
101
+
102
+ #: ultimate-posts-widget.php:504
103
+ msgid "Show read more link"
104
+ msgstr "Visa länk \"Läs mer\""
105
+
106
+ #: ultimate-posts-widget.php:509
107
+ msgid "Read more text"
108
+ msgstr "Text \"Läs mer\""
109
+
110
+ #: ultimate-posts-widget.php:517
111
+ msgid "Show thumbnail"
112
+ msgstr "Visa miniatyr"
113
+
114
+ #: ultimate-posts-widget.php:521
115
+ msgid "Thumbnail size"
116
+ msgstr "Miniatyrstorlek"
117
+
118
+ #: ultimate-posts-widget.php:524
119
+ msgid "W"
120
+ msgstr "B"
121
+
122
+ #: ultimate-posts-widget.php:527
123
+ msgid "H"
124
+ msgstr "H"
125
+
126
+ #: ultimate-posts-widget.php:532
127
+ msgid "Crop mode"
128
+ msgstr "Beskärningssätt"
129
+
130
+ #: ultimate-posts-widget.php:535
131
+ msgid "Scale &amp; Crop to Fit"
132
+ msgstr "Skala &amp; beskär för att passa"
133
+
134
+ #: ultimate-posts-widget.php:536
135
+ msgid "Stretch to Fit"
136
+ msgstr "Sträck för att passa"
137
+
138
+ #: ultimate-posts-widget.php:537
139
+ msgid "Proportional Scale"
140
+ msgstr "Skala proportionellt"
141
+
142
+ #: ultimate-posts-widget.php:538
143
+ msgid "Proportional Scale No Borders"
144
+ msgstr "Skala proportionellt utan ramar"
145
+
146
+ #: ultimate-posts-widget.php:546
147
+ msgid "Show post categories"
148
+ msgstr "Visa inläggskategorier"
149
+
150
+ #: ultimate-posts-widget.php:551
151
+ msgid "Show post tags"
152
+ msgstr "Visa inläggsetiketter"
153
+
154
+ #: ultimate-posts-widget.php:555
155
+ msgid "Show Custom Fields (comma separated)"
156
+ msgstr "Visa egna fält (kommaseparerade)"
157
+
158
+ #: ultimate-posts-widget.php:565
159
+ msgid "Show posts only from current category"
160
+ msgstr "Visa bara inlägg från aktuella kategorin"
161
+
162
+ #: ultimate-posts-widget.php:580
163
+ msgid "Post types"
164
+ msgstr "Posttyper"
165
+
166
+ #: ultimate-posts-widget.php:592
167
+ msgid "Sticky posts"
168
+ msgstr "Fastklistrade inlägg"
169
+
170
+ #: ultimate-posts-widget.php:594
171
+ msgid "Show All Posts"
172
+ msgstr "Visa alla inlägg"
173
+
174
+ #: ultimate-posts-widget.php:595
175
+ msgid "Hide Sticky Posts"
176
+ msgstr "Dölj klistrade inlägg"
177
+
178
+ #: ultimate-posts-widget.php:596
179
+ msgid "Show Only Sticky Posts"
180
+ msgstr "Visa bara klistrade inlägg"
181
+
182
+ #: ultimate-posts-widget.php:606
183
+ msgid "Published Date"
184
+ msgstr "Publiceringsdatum"
185
+
186
+ #: ultimate-posts-widget.php:608
187
+ msgid "Comment Count"
188
+ msgstr "Antal kommentarer"
189
+
190
+ #: ultimate-posts-widget.php:609
191
+ msgid "Random"
192
+ msgstr "Slumpvis"
193
+
194
+ #: ultimate-posts-widget.php:615
195
+ msgid "Descending"
196
+ msgstr "Avtagande"
197
+
198
+ #: ultimate-posts-widget.php:616
199
+ msgid "Ascending"
200
+ msgstr "Ökande"
201
+
202
+ #: ultimate-posts-widget.php:620
203
+ msgid "Developed by"
204
+ msgstr "Utvecklad av"
license.txt ADDED
@@ -0,0 +1,621 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
package.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "bostondv/ultimate-posts-widget",
3
+ "version": "2.0.0",
4
+ "contributors": [
5
+ "Boston Dell-Vandenberg <boston@pomelodesign.com>"
6
+ ],
7
+ "homepage": "http://wordpress.org/plugins/ultimate-posts-widget/",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/bostondv/ultimate-posts-widget.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/bostondv/ultimate-posts-widget/issues/"
14
+ },
15
+ "licenses": [
16
+ {
17
+ "type": "GPLv3",
18
+ "url": "http://www.gnu.org/licenses/gpl.html"
19
+ }
20
+ ],
21
+ "engines": {
22
+ "node": ">= 0.10.0"
23
+ },
24
+ "devDependencies": {
25
+ "gulp": "^3.8.6",
26
+ "gulp-autoprefixer": "^0.0.8",
27
+ "gulp-minify-css": "^0.3.7",
28
+ "gulp-rename": "^1.2.0",
29
+ "gulp-ruby-sass": "^0.7.1",
30
+ "gulp-size": "^1.0.0",
31
+ "gulp-uglifyjs": "^0.4.2",
32
+ "gulp-util": "^3.0.0"
33
+ }
34
+ }
readme.txt CHANGED
@@ -1,71 +1,140 @@
1
  === Ultimate Posts Widget ===
2
  Contributors: bostondv
3
- Donate link: http://www.pomelodesign.com/donate
4
- Tags: widget, recent posts, custom post types, sticky posts, featured image, post thumbnail, excerpts, category, custom fields
5
- Requires at least: 3.0
6
- Tested up to: 3.6.1
7
- Stable tag: 1.8.1
8
- License: GPL2
9
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
12
 
13
  == Description ==
14
 
15
- The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
 
 
16
 
17
- Options:
18
 
19
  * Filter by categories
20
  * Filter by current category
 
 
21
  * Filter by custom post types
22
  * Filter by sticky posts
23
  * Select number of posts to display
24
  * Display title
25
- * Display publish date
26
- * Display publish time
27
- * Display post author
28
- * Display excerpt
29
- * Display content
30
- * Display read more link
31
- * Display featured image
32
- * Display more button link
33
  * Display post categories
34
  * Display post tags
35
  * Display custom fields
36
- * Custom widget title link
37
- * Custom read more link text
38
- * Custom excerpt length (in words)
39
- * Custom featured image size
40
- * Feature image crop mode
41
- * Order by date, title, number of comments or random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
- For support please use [wordpress.org](http://wordpress.org/support/plugin/ultimate-posts-widget). Visit [our website](http://pomelodesign.com), follow [@bostondv](http://twitter.com/bostondv/) for updates.
 
 
 
 
44
 
45
- Fork or contribute on [Github](https://github.com/bostondv/ultimate-posts-widget)
 
 
46
 
47
  == Frequently Asked Questions ==
48
 
49
  = Thumbnail images are not displaying =
50
 
51
- This plugin uses the [TimThumb library](http://www.binarymoon.co.uk/projects/timthumb/) to resize post thumbnails. Please review these requirements and troubleshooting tips if you are having problems displaying thumbnails.
 
 
52
 
53
  * Right click > view image - If an image isn't loading then this is the first thing you should do. 9 times out of 10 it will tell you what the problem is in an easy to read error message.
54
- * JetPack plugin - There is a known conflict between JetPack's "Photon" component, please disable it for compatibility with TimThumb.
55
  * Server requirements - PHP and the GD image library must be installed on your web server. Normally most web servers include them by default.
56
  * Cache permissions - The cache directory `wp-content/plugins/ultimate-posts-widget/cache` should be set to 777 or if that doesn't work, you may find 755 is ok.
57
- * Image sizes - TimThumb is configured to only work for images smaller than 1500 x 1500. The plugin and automatically selects the "Large" size from Settings > Media, if it is greater than 1500 x 1500 you will need to reduce the size or modify the configuration in `thumb.php` to support larger image sizes.
58
- * Tilde(~) in url - Timthumb has a known issue with this, please use a url without a tilde until a fix is available. [Bug report](https://code.google.com/p/timthumb/issues/detail?id=263)
59
  * Thumbnail images only work with WordPress' native post thumbnail / featured image. Many theme use a custom image field for thumbnails, these are not supported.
60
 
61
- Still stuck? See [additional troubleshooting tips](http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/) from the TimThumb author.
62
 
63
  == Screenshots ==
64
 
65
- 1. Widget options
 
 
 
 
66
 
67
  == Changelog ==
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  = 1.8.1 =
70
 
71
  * Add content display option
@@ -138,9 +207,15 @@ Still stuck? See [additional troubleshooting tips](http://www.binarymoon.co.uk/2
138
 
139
  * First release.
140
 
 
 
 
 
 
 
141
  == Installation ==
142
 
143
  1. Download and extract the zip archive
144
  2. Upload `ultimate-posts-widget` folder to `/wp-content/plugins/`
145
  3. Activate the plugin through the 'Plugins' menu in WordPress
146
- 4. Add the widget to a sidebar and configure the options as desired
1
  === Ultimate Posts Widget ===
2
  Contributors: bostondv
3
+ Donate link: http://www.pomelodesign.com/donate/
4
+ License: GPLv3
5
+ License URI: http://www.gnu.org/licenses/gpl.html
6
+ Tags: widget, recent posts, custom post types, sticky posts, featured image, post thumbnail, excerpts, category, custom fields, list pages, widget query, microformats, customizable widget, categories widget, tags widget, excerpt, widget templates, post author, post date, custom query, ultimate posts, comments, orderby, comment count
7
+ Requires at least: 3.6
8
+ Tested up to: 4.0
9
+ Stable tag: 2.0.0
10
 
11
  The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
12
 
13
  == Description ==
14
 
15
+ The ultimate widget for displaying posts, custom post types or sticky posts with an array of options to customize the display.
16
+
17
+ Designed for both the average user and developer, Ultimate Posts Widgets aims to provide flexibility and ease of use for displaying any kinds of posts within your widget areas. An array of widget options are available as well as hooks, filters and custom templates for more advanced customization.
18
 
19
+ = Options =
20
 
21
  * Filter by categories
22
  * Filter by current category
23
+ * Filter by tags
24
+ * Filter by current tag
25
  * Filter by custom post types
26
  * Filter by sticky posts
27
  * Select number of posts to display
28
  * Display title
29
+ * Display publish date/time with custom format options
30
+ * Display post author and link
31
+ * Display post comment count
32
+ * Display excerpt or full content
33
+ * Display read more link with custom label
34
+ * Display featured image and at any size
 
 
35
  * Display post categories
36
  * Display post tags
37
  * Display custom fields
38
+ * Add text or HTML before and after posts list
39
+ * Add CSS class to widget
40
+ * Add widget title link
41
+ * Change excerpt length (in words)
42
+ * Order by date, title, number of comments, random or a custom field
43
+
44
+ = Filters =
45
+
46
+ `upw_enqueue_styles` (boolean)
47
+ Allows changing whether to load the template CSS file(s).
48
+
49
+ `upw_widget_title` (string)
50
+ Allows changing the widget title.
51
+
52
+ `upw_wp_query_args` (array)
53
+ Allows changing the WP_Query arguments for the widget.
54
+
55
+ `upw_custom_template_path` (string)
56
+ Allows changing the default custom template path.
57
+
58
+ = Templates =
59
+
60
+ `legacy`
61
+ As of version 2.0.0 we changed the widget HTML markup. For installs prior to 2.0.0 you can use the legacy template to retain the old HTML markup and compatibility.
62
+
63
+ `standard`
64
+ The new standard template as of version 2.0.0. It features better HTML5 markup, improved styling on various themes without the need for custom CSS, and hfeed microformat.
65
+
66
+ `custom`
67
+ As of version 2.0.0 you can now provide your own custom template files. In your theme, create a folder named `upw` then copy one of the templates from the plugin into this folder and edit as needed. In the widget settings under *Display* tab, choose *Custom* template from the drop down and enter the file name (excluding .PHP) into the subsequent field. For example, if your template is named `custom.php` then enter `custom` in the Custom Template Name field.
68
+
69
+ = More Information =
70
 
71
+ * For help use [wordpress.org](http://wordpress.org/support/plugin/ultimate-posts-widget/)
72
+ * Fork or contribute on [Github](https://github.com/bostondv/ultimate-posts-widget/)
73
+ * Visit [our website](http://pomelodesign.com/) for more
74
+ * Follow me on [Twitter](http://twitter.com/bostondv/)
75
+ * View my other [WordPress Plugins](http://profiles.wordpress.org/bostondv/)
76
 
77
+ = Support =
78
+
79
+ Did you enjoy this plugin? Please [donate to support ongoing development](http://pomelodesign.com/donate/). Your contribution would be greatly appreciated.
80
 
81
  == Frequently Asked Questions ==
82
 
83
  = Thumbnail images are not displaying =
84
 
85
+ *As of version 2.0.0 timthumb is no longer used.*
86
+
87
+ This plugin uses the [timthumb library](http://www.binarymoon.co.uk/projects/timthumb/) to resize post thumbnails. Please review these requirements and troubleshooting tips if you are having problems displaying thumbnails.
88
 
89
  * Right click > view image - If an image isn't loading then this is the first thing you should do. 9 times out of 10 it will tell you what the problem is in an easy to read error message.
90
+ * JetPack plugin - There is a known conflict between JetPack's "Photon" component, please disable it for compatibility with timthumb.
91
  * Server requirements - PHP and the GD image library must be installed on your web server. Normally most web servers include them by default.
92
  * Cache permissions - The cache directory `wp-content/plugins/ultimate-posts-widget/cache` should be set to 777 or if that doesn't work, you may find 755 is ok.
93
+ * Image sizes - timthumb is configured to only work for images smaller than 1500 x 1500. The plugin and automatically selects the "Large" size from Settings > Media, if it is greater than 1500 x 1500 you will need to reduce the size or modify the configuration in `thumb.php` to support larger image sizes.
94
+ * Tilde(~) in url - timthumb has a known issue with this, please use a url without a tilde until a fix is available. [Bug report](https://code.google.com/p/timthumb/issues/detail?id=263)
95
  * Thumbnail images only work with WordPress' native post thumbnail / featured image. Many theme use a custom image field for thumbnails, these are not supported.
96
 
97
+ **Still stuck?** See [additional troubleshooting tips](http://www.binarymoon.co.uk/2010/11/timthumb-hints-tips/) from the timthumb author.
98
 
99
  == Screenshots ==
100
 
101
+ 1. Example with TwentyTwelve theme with the default widget options
102
+ 2. General options tab
103
+ 3. Display options tab
104
+ 4. Filter options tab
105
+ 5. Order options tab
106
 
107
  == Changelog ==
108
 
109
+ = 2.0.0 =
110
+
111
+ * Added a new standard template and custom template support
112
+ * Added basic CSS styles for better formatting
113
+ * Add hfeed microformat into new standard template
114
+ * Improved widget options interface
115
+ * Add option to filter by tags or current tag
116
+ * Remove timthumb in favor of using built-in WordPress image sizes
117
+ * Remove widget "More Button" options
118
+ * Change date display options to now accept any custom date formats
119
+ * Add before and after posts HTML fields
120
+ * Add option for widget CSS class (thanks @avenirer)
121
+ * Add option to display comment count
122
+ * Set better defaults for newly created widgets
123
+ * Various bug fixes and optimizations
124
+
125
+ *Upgrading from an earlier version?*
126
+
127
+ * Upgrades from prior to 2.0.0 we retain the "legacy" template for you. To change which template to use, find the "Template" option under the "Display" tab.
128
+ * If you used the "More Button", you will need to add in your own HTML into one of the new fields since the more button is now removed.
129
+ * If you used custom thumbnail settings you will need to update them. You can now choose from pre-defined sizes available to WordPress. If you need an additional image size please see [how to add image sizes](http://codex.wordpress.org/Function_Reference/add_image_size/).
130
+ * Date formatting has changed, you will need to update your settings. By default it uses WordPress' date/time options.
131
+
132
+ = 1.9.0 =
133
+
134
+ * Adds option to order by custom field (thanks @enekochan)
135
+ * Remove "Permalink to:" from link titles (thanks @wirelessgizmo)
136
+ * Swedish translation (thanks @brstp)
137
+
138
  = 1.8.1 =
139
 
140
  * Add content display option
207
 
208
  * First release.
209
 
210
+ == Upgrade Notice ==
211
+
212
+ = 2.0.0 =
213
+
214
+ This is a major update and includes some breaking changes. New templates have been introduced, a few fields have changed, and thumbnails have been modified. See the changelog for details.
215
+
216
  == Installation ==
217
 
218
  1. Download and extract the zip archive
219
  2. Upload `ultimate-posts-widget` folder to `/wp-content/plugins/`
220
  3. Activate the plugin through the 'Plugins' menu in WordPress
221
+ 4. Add the widget to a sidebar and configure the options as desired
screenshot-1.png CHANGED
Binary file
screenshot-2.png ADDED
Binary file
screenshot-3.png ADDED
Binary file
screenshot-4.png ADDED
Binary file
screenshot-5.png ADDED
Binary file
scss/upw-admin.scss ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .upw-divider {
2
+ border: 0;
3
+ border-top: 1px solid #DFDFDF;
4
+ }
5
+
6
+ .upw-tabs {
7
+ display: block;
8
+ border-bottom: 1px solid #DFDFDF;
9
+ margin: 1em 0;
10
+ }
11
+
12
+ .upw-tab-item {
13
+ display: inline-block;
14
+ border: 1px solid transparent;
15
+ border-bottom: 0;
16
+ color: #666;
17
+ padding: 8px 10px;
18
+ &:not(.active) {
19
+ &:hover,
20
+ &:focus {
21
+ color: darken(#666, 10%);
22
+ background-color: darken(#fff, 3%);
23
+ cursor: pointer;
24
+ }
25
+ &:active {
26
+ color: darken(#666, 20%);
27
+ background-color: darken(#fff, 6%);
28
+ }
29
+ }
30
+ &.active {
31
+ color: #444;
32
+ border-color: #DFDFDF;
33
+ background: #fff;
34
+ position: relative;
35
+ bottom: -1px;
36
+ cursor: default;
37
+ font-weight: bold;
38
+ }
39
+ }
40
+
41
+ .upw-hide {
42
+ display: none !important;
43
+ }
44
+
45
+ .upw-credits {
46
+ font-size: 0.9em;
47
+ background: darken(#fff, 3%);
48
+ border: 1px solid darken(#fff, 8%);
49
+ padding: 4px 6px;
50
+ }
scss/upw-theme-standard.scss ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .upw-posts {
2
+
3
+ .hentry {
4
+ display: block;
5
+ margin-bottom: 1.5rem;
6
+ padding-bottom: 1rem;
7
+ border-bottom: 1px solid #ddd;
8
+ &:last-child {
9
+ border-bottom: 0;
10
+ padding-bottom: 0;
11
+ }
12
+ }
13
+
14
+ .entry-title {
15
+ margin-bottom: 0.5rem;
16
+ a {
17
+ text-decoration: none;
18
+ &:hover,
19
+ &:focus {
20
+ text-decoration: underline;
21
+ }
22
+ }
23
+ }
24
+
25
+ .entry-image {
26
+ margin-bottom: 1rem;
27
+ img {
28
+ max-width: 100%;
29
+ height: auto;
30
+ }
31
+ }
32
+
33
+ .entry-meta {
34
+ color: #888;
35
+ font-size: 0.9rem;
36
+ margin-bottom: 1rem;
37
+ line-height: 1.4;
38
+ .comments {
39
+ white-space: nowrap;
40
+ }
41
+ }
42
+
43
+ .entry-summary,
44
+ .entry-content {
45
+ > :last-child {
46
+ margin-bottom: 1rem;
47
+ }
48
+ }
49
+
50
+ .more-link {
51
+ white-space: nowrap;
52
+ }
53
+
54
+ footer {
55
+ display: block;
56
+ color: #888;
57
+ font-size: 0.9rem;
58
+ line-height: 1.4;
59
+ }
60
+
61
+ .entry-categories,
62
+ .entry-tags,
63
+ .entry-custom-fields {
64
+ margin-bottom: 0.5rem;
65
+ }
66
+
67
+ .custom-field {
68
+ margin-bottom: 0.5rem;
69
+ }
70
+
71
+ }
72
+
73
+ .upw-before,
74
+ .upw-after {
75
+ margin-bottom: 1rem;
76
+ > :last-child {
77
+ margin-bottom: 0;
78
+ }
79
+ }
templates/legacy.php ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($instance['before_posts']) : ?>
2
+ <div class="upw-before">
3
+ <?php echo wpautop($instance['before_posts']); ?>
4
+ </div>
5
+ <?php endif; ?>
6
+
7
+ <?php if ($upw_query->have_posts()) : ?>
8
+
9
+ <ul>
10
+
11
+ <?php while ($upw_query->have_posts()) : $upw_query->the_post(); ?>
12
+
13
+ <?php $current_post = ($post->ID == $current_post_id && is_single()) ? 'current-post-item' : ''; ?>
14
+
15
+ <li <?php post_class($current_post); ?>>
16
+
17
+ <?php if (current_theme_supports('post-thumbnails') && $instance['show_thumbnail'] && has_post_thumbnail()) : ?>
18
+ <div class="upw-image">
19
+ <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
20
+ <?php the_post_thumbnail($instance['thumb_size']); ?>
21
+ </a>
22
+ </div>
23
+ <?php endif; ?>
24
+
25
+ <div class="upw-content">
26
+
27
+ <?php if (get_the_title() && $instance['show_title']) : ?>
28
+ <p class="post-title">
29
+ <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
30
+ <?php the_title(); ?>
31
+ </a>
32
+ </p>
33
+ <?php endif; ?>
34
+
35
+ <?php if ($instance['show_date']) : ?>
36
+ <p class="post-date">
37
+ <?php the_time($instance['date_format']); ?>
38
+ </p>
39
+ <?php endif; ?>
40
+
41
+ <?php if ($instance['show_author']) : ?>
42
+ <p class="post-author">
43
+ <span class="post-author-label"><?php _e('By', 'upw'); ?>:</span>
44
+ <?php the_author_posts_link(); ?>
45
+ </p>
46
+ <?php endif; ?>
47
+
48
+ <?php if ($instance['show_comments']) : ?>
49
+ <p class="post-comments">
50
+ <?php comments_number(__('No responses', 'upw'), __('One response', 'upw'), __('% responses', 'upw')); ?>
51
+ </p>
52
+ <?php endif; ?>
53
+
54
+ <?php if ($instance['show_excerpt']) : ?>
55
+ <?php
56
+ $linkmore = '';
57
+ if ($instance['show_readmore']) {
58
+ $linkmore = ' <a href="'.get_permalink().'" class="more-link">'.$excerpt_readmore.'</a>';
59
+ }
60
+ ?>
61
+ <p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
62
+ <?php endif; ?>
63
+
64
+ <?php if ($instance['show_content']) : ?>
65
+ <p class="post-content"><?php the_content() ?></p>
66
+ <?php endif; ?>
67
+
68
+ <?php
69
+ $categories = get_the_term_list($post->ID, 'category', '', ', ');
70
+ if ($instance['show_cats'] && $categories) :
71
+ ?>
72
+ <p class="post-cats">
73
+ <span class="post-cats-label"><?php _e('Categories', 'upw'); ?>:</span>
74
+ <span class="post-cats-list"><?php echo $categories; ?></span>
75
+ </p>
76
+ <?php endif; ?>
77
+
78
+ <?php
79
+ $tags = get_the_term_list($post->ID, 'post_tag', '', ', ');
80
+ if ($instance['show_tags'] && $tags) :
81
+ ?>
82
+ <p class="post-tags">
83
+ <span class="post-tags-label"><?php _e('Tags', 'upw'); ?>:</span>
84
+ <span class="post-tags-list"><?php echo $tags; ?></span>
85
+ </p>
86
+ <?php endif; ?>
87
+
88
+ <?php if ($custom_fields) {
89
+ $custom_field_name = explode(',', $custom_fields);
90
+ foreach ($custom_field_name as $name) {
91
+ $name = trim($name);
92
+ $custom_field_values = get_post_meta($post->ID, $name, true);
93
+ if ($custom_field_values) {
94
+ echo '<p class="post-meta post-meta-'.$name.'">';
95
+ if (!is_array($custom_field_values)) {
96
+ echo $custom_field_values;
97
+ } else {
98
+ $last_value = end($custom_field_values);
99
+ foreach ($custom_field_values as $value) {
100
+ echo $value;
101
+ if ($value != $last_value) echo ', ';
102
+ }
103
+ }
104
+ echo '</p>';
105
+ }
106
+ }
107
+ } ?>
108
+
109
+ </div>
110
+
111
+ </li>
112
+
113
+ <?php endwhile; ?>
114
+
115
+ </ul>
116
+
117
+ <?php else : ?>
118
+
119
+ <p><?php _e('No posts found.', 'upw'); ?></p>
120
+
121
+ <?php endif; ?>
122
+
123
+ <?php if ($instance['after_posts']) : ?>
124
+ <div class="upw-after">
125
+ <?php echo wpautop($instance['after_posts']); ?>
126
+ </div>
127
+ <?php endif; ?>
templates/standard.php ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if ($instance['before_posts']) : ?>
2
+ <div class="upw-before">
3
+ <?php echo wpautop($instance['before_posts']); ?>
4
+ </div>
5
+ <?php endif; ?>
6
+
7
+ <div class="upw-posts hfeed">
8
+
9
+ <?php if ($upw_query->have_posts()) : ?>
10
+
11
+ <?php while ($upw_query->have_posts()) : $upw_query->the_post(); ?>
12
+
13
+ <?php $current_post = ($post->ID == $current_post_id && is_single()) ? 'active' : ''; ?>
14
+
15
+ <article <?php post_class($current_post); ?>>
16
+
17
+ <header>
18
+
19
+ <?php if (current_theme_supports('post-thumbnails') && $instance['show_thumbnail'] && has_post_thumbnail()) : ?>
20
+ <div class="entry-image">
21
+ <?php the_post_thumbnail($instance['thumb_size']); ?>
22
+ </div>
23
+ <?php endif; ?>
24
+
25
+ <?php if (get_the_title() && $instance['show_title']) : ?>
26
+ <h4 class="entry-title">
27
+ <a href="<?php the_permalink(); ?>" rel="bookmark">
28
+ <?php the_title(); ?>
29
+ </a>
30
+ </h4>
31
+ <?php endif; ?>
32
+
33
+ <?php if ($instance['show_date'] || $instance['show_author'] || $instance['show_comments']) : ?>
34
+
35
+ <div class="entry-meta">
36
+
37
+ <?php if ($instance['show_date']) : ?>
38
+ <time class="published" datetime="<?php echo get_the_time('c'); ?>"><?php echo get_the_time($instance['date_format']); ?></time>
39
+ <?php endif; ?>
40
+
41
+ <?php if ($instance['show_date'] && $instance['show_author']) : ?>
42
+ <span class="sep"><?php _e('|', 'upw'); ?></span>
43
+ <?php endif; ?>
44
+
45
+ <?php if ($instance['show_author']) : ?>
46
+ <span class="author vcard">
47
+ <?php echo __('By', 'upw'); ?>
48
+ <a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>" rel="author" class="fn">
49
+ <?php echo get_the_author(); ?>
50
+ </a>
51
+ </span>
52
+ <?php endif; ?>
53
+
54
+ <?php if ($instance['show_author'] && $instance['show_comments']) : ?>
55
+ <span class="sep"><?php _e('|', 'upw'); ?></span>
56
+ <?php endif; ?>
57
+
58
+ <?php if ($instance['show_comments']) : ?>
59
+ <a class="comments" href="<?php comments_link(); ?>">
60
+ <?php comments_number(__('No comments', 'upw'), __('One comment', 'upw'), __('% comments', 'upw')); ?>
61
+ </a>
62
+ <?php endif; ?>
63
+
64
+ </div>
65
+
66
+ <?php endif; ?>
67
+
68
+ </header>
69
+
70
+ <?php if ($instance['show_excerpt']) : ?>
71
+ <div class="entry-summary">
72
+ <p>
73
+ <?php echo get_the_excerpt(); ?>
74
+ <?php if ($instance['show_readmore']) : ?>
75
+ <a href="<?php the_permalink(); ?>" class="more-link"><?php echo $instance['excerpt_readmore']; ?></a>
76
+ <?php endif; ?>
77
+ </p>
78
+ </div>
79
+ <?php elseif ($instance['show_content']) : ?>
80
+ <div class="entry-content">
81
+ <?php the_content() ?>
82
+ </div>
83
+ <?php endif; ?>
84
+
85
+ <footer>
86
+
87
+ <?php
88
+ $categories = get_the_term_list($post->ID, 'category', '', ', ');
89
+ if ($instance['show_cats'] && $categories) :
90
+ ?>
91
+ <div class="entry-categories">
92
+ <strong class="entry-cats-label"><?php _e('Posted in', 'upw'); ?>:</strong>
93
+ <span class="entry-cats-list"><?php echo $categories; ?></span>
94
+ </div>
95
+ <?php endif; ?>
96
+
97
+ <?php
98
+ $tags = get_the_term_list($post->ID, 'post_tag', '', ', ');
99
+ if ($instance['show_tags'] && $tags) :
100
+ ?>
101
+ <div class="entry-tags">
102
+ <strong class="entry-tags-label"><?php _e('Tagged', 'upw'); ?>:</strong>
103
+ <span class="entry-tags-list"><?php echo $tags; ?></span>
104
+ </div>
105
+ <?php endif; ?>
106
+
107
+ <?php if ($custom_fields) : ?>
108
+ <?php $custom_field_name = explode(',', $custom_fields); ?>
109
+ <div class="entry-custom-fields">
110
+ <?php foreach ($custom_field_name as $name) :
111
+ $name = trim($name);
112
+ $custom_field_values = get_post_meta($post->ID, $name, true);
113
+ if ($custom_field_values) : ?>
114
+ <div class="custom-field custom-field-<?php echo $name; ?>">
115
+ <?php
116
+ if (!is_array($custom_field_values)) {
117
+ echo $custom_field_values;
118
+ } else {
119
+ $last_value = end($custom_field_values);
120
+ foreach ($custom_field_values as $value) {
121
+ echo $value;
122
+ if ($value != $last_value) echo ', ';
123
+ }
124
+ }
125
+ ?>
126
+ </div>
127
+ <?php endif;
128
+ endforeach; ?>
129
+ </div>
130
+ <?php endif; ?>
131
+
132
+ </footer>
133
+
134
+ </article>
135
+
136
+ <?php endwhile; ?>
137
+
138
+ <?php else : ?>
139
+
140
+ <p class="upw-not-found">
141
+ <?php _e('No posts found.', 'upw'); ?>
142
+ </p>
143
+
144
+ <?php endif; ?>
145
+
146
+ </div>
147
+
148
+ <?php if ($instance['after_posts']) : ?>
149
+ <div class="upw-after">
150
+ <?php echo wpautop($instance['after_posts']); ?>
151
+ </div>
152
+ <?php endif; ?>
thumb.php DELETED
@@ -1,1241 +0,0 @@
1
- <?php
2
- /**
3
- * TimThumb by Ben Gillbanks and Mark Maunder
4
- * Based on work done by Tim McDaniels and Darren Hoyt
5
- * http://code.google.com/p/timthumb/
6
- *
7
- * GNU General Public License, version 2
8
- * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9
- *
10
- * Examples and documentation available on the project homepage
11
- * http://www.binarymoon.co.uk/projects/timthumb/
12
- *
13
- * $Rev$
14
- */
15
-
16
- /*
17
- * --- TimThumb CONFIGURATION ---
18
- * To edit the configs it is best to create a file called timthumb-config.php
19
- * and define variables you want to customize in there. It will automatically be
20
- * loaded by timthumb. This will save you having to re-edit these variables
21
- * everytime you download a new version
22
- */
23
- define ('VERSION', '2.8.11'); // Version of this script
24
- //Load a config file if it exists. Otherwise, use the values below
25
- if( file_exists(dirname(__FILE__) . '/timthumb-config.php')) require_once('timthumb-config.php');
26
- if(! defined('DEBUG_ON') ) define ('DEBUG_ON', false); // Enable debug logging to web server error log (STDERR)
27
- if(! defined('DEBUG_LEVEL') ) define ('DEBUG_LEVEL', 1); // Debug level 1 is less noisy and 3 is the most noisy
28
- if(! defined('MEMORY_LIMIT') ) define ('MEMORY_LIMIT', '30M'); // Set PHP memory limit
29
- if(! defined('BLOCK_EXTERNAL_LEECHERS') ) define ('BLOCK_EXTERNAL_LEECHERS', false); // If the image or webshot is being loaded on an external site, display a red "No Hotlinking" gif.
30
-
31
- //Image fetching and caching
32
- if(! defined('ALLOW_EXTERNAL') ) define ('ALLOW_EXTERNAL', TRUE); // Allow image fetching from external websites. Will check against ALLOWED_SITES if ALLOW_ALL_EXTERNAL_SITES is false
33
- if(! defined('ALLOW_ALL_EXTERNAL_SITES') ) define ('ALLOW_ALL_EXTERNAL_SITES', false); // Less secure.
34
- if(! defined('FILE_CACHE_ENABLED') ) define ('FILE_CACHE_ENABLED', TRUE); // Should we store resized/modified images on disk to speed things up?
35
- if(! defined('FILE_CACHE_TIME_BETWEEN_CLEANS')) define ('FILE_CACHE_TIME_BETWEEN_CLEANS', 86400); // How often the cache is cleaned
36
-
37
- if(! defined('FILE_CACHE_MAX_FILE_AGE') ) define ('FILE_CACHE_MAX_FILE_AGE', 86400); // How old does a file have to be to be deleted from the cache
38
- if(! defined('FILE_CACHE_SUFFIX') ) define ('FILE_CACHE_SUFFIX', '.timthumb.txt'); // What to put at the end of all files in the cache directory so we can identify them
39
- if(! defined('FILE_CACHE_PREFIX') ) define ('FILE_CACHE_PREFIX', 'timthumb'); // What to put at the beg of all files in the cache directory so we can identify them
40
- if(! defined('FILE_CACHE_DIRECTORY') ) define ('FILE_CACHE_DIRECTORY', './cache'); // Directory where images are cached. Left blank it will use the system temporary directory (which is better for security)
41
- if(! defined('MAX_FILE_SIZE') ) define ('MAX_FILE_SIZE', 10485760); // 10 Megs is 10485760. This is the max internal or external file size that we'll process.
42
- if(! defined('CURL_TIMEOUT') ) define ('CURL_TIMEOUT', 20); // Timeout duration for Curl. This only applies if you have Curl installed and aren't using PHP's default URL fetching mechanism.
43
- if(! defined('WAIT_BETWEEN_FETCH_ERRORS') ) define ('WAIT_BETWEEN_FETCH_ERRORS', 3600); // Time to wait between errors fetching remote file
44
-
45
- //Browser caching
46
- if(! defined('BROWSER_CACHE_MAX_AGE') ) define ('BROWSER_CACHE_MAX_AGE', 864000); // Time to cache in the browser
47
- if(! defined('BROWSER_CACHE_DISABLE') ) define ('BROWSER_CACHE_DISABLE', false); // Use for testing if you want to disable all browser caching
48
-
49
- //Image size and defaults
50
- if(! defined('MAX_WIDTH') ) define ('MAX_WIDTH', 1500); // Maximum image width
51
- if(! defined('MAX_HEIGHT') ) define ('MAX_HEIGHT', 1500); // Maximum image height
52
- if(! defined('NOT_FOUND_IMAGE') ) define ('NOT_FOUND_IMAGE', ''); // Image to serve if any 404 occurs
53
- if(! defined('ERROR_IMAGE') ) define ('ERROR_IMAGE', ''); // Image to serve if an error occurs instead of showing error message
54
- if(! defined('PNG_IS_TRANSPARENT') ) define ('PNG_IS_TRANSPARENT', FALSE); // Define if a png image should have a transparent background color. Use False value if you want to display a custom coloured canvas_colour
55
- if(! defined('DEFAULT_Q') ) define ('DEFAULT_Q', 90); // Default image quality. Allows overrid in timthumb-config.php
56
- if(! defined('DEFAULT_ZC') ) define ('DEFAULT_ZC', 1); // Default zoom/crop setting. Allows overrid in timthumb-config.php
57
- if(! defined('DEFAULT_F') ) define ('DEFAULT_F', ''); // Default image filters. Allows overrid in timthumb-config.php
58
- if(! defined('DEFAULT_S') ) define ('DEFAULT_S', 0); // Default sharpen value. Allows overrid in timthumb-config.php
59
- if(! defined('DEFAULT_CC') ) define ('DEFAULT_CC', 'ffffff'); // Default canvas colour. Allows overrid in timthumb-config.php
60
-
61
-
62
- //Image compression is enabled if either of these point to valid paths
63
-
64
- //These are now disabled by default because the file sizes of PNGs (and GIFs) are much smaller than we used to generate.
65
- //They only work for PNGs. GIFs and JPEGs are not affected.
66
- if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false);
67
- if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng'); //This will run first because it gives better compression than pngcrush.
68
- if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false);
69
- if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush'); //This will only run if OPTIPNG_PATH is not set or is not valid
70
-
71
- /*
72
- -------====Website Screenshots configuration - BETA====-------
73
-
74
- If you just want image thumbnails and don't want website screenshots, you can safely leave this as is.
75
-
76
- If you would like to get website screenshots set up, you will need root access to your own server.
77
-
78
- Enable ALLOW_ALL_EXTERNAL_SITES so you can fetch any external web page. This is more secure now that we're using a non-web folder for cache.
79
- Enable BLOCK_EXTERNAL_LEECHERS so that your site doesn't generate thumbnails for the whole Internet.
80
-
81
- Instructions to get website screenshots enabled on Ubuntu Linux:
82
-
83
- 1. Install Xvfb with the following command: sudo apt-get install subversion libqt4-webkit libqt4-dev g++ xvfb
84
- 2. Go to a directory where you can download some code
85
- 3. Check-out the latest version of CutyCapt with the following command: svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
86
- 4. Compile CutyCapt by doing: cd cutycapt/CutyCapt
87
- 5. qmake
88
- 6. make
89
- 7. cp CutyCapt /usr/local/bin/
90
- 8. Test it by running: xvfb-run --server-args="-screen 0, 1024x768x24" CutyCapt --url="http://markmaunder.com/" --out=test.png
91
- 9. If you get a file called test.png with something in it, it probably worked. Now test the script by accessing it as follows:
92
- 10. http://yoursite.com/path/to/timthumb.php?src=http://markmaunder.com/&webshot=1
93
-
94
- Notes on performance:
95
- The first time a webshot loads, it will take a few seconds.
96
- From then on it uses the regular timthumb caching mechanism with the configurable options above
97
- and loading will be very fast.
98
-
99
- --ADVANCED USERS ONLY--
100
- If you'd like a slight speedup (about 25%) and you know Linux, you can run the following command which will keep Xvfb running in the background.
101
- nohup Xvfb :100 -ac -nolisten tcp -screen 0, 1024x768x24 > /dev/null 2>&1 &
102
- Then set WEBSHOT_XVFB_RUNNING = true below. This will save your server having to fire off a new Xvfb server and shut it down every time a new shot is generated.
103
- You will need to take responsibility for keeping Xvfb running in case it crashes. (It seems pretty stable)
104
- You will also need to take responsibility for server security if you're running Xvfb as root.
105
-
106
-
107
- */
108
- if(! defined('WEBSHOT_ENABLED') ) define ('WEBSHOT_ENABLED', false); //Beta feature. Adding webshot=1 to your query string will cause the script to return a browser screenshot rather than try to fetch an image.
109
- if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt'); //The path to CutyCapt.
110
- if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run'); //The path to the Xvfb server
111
- if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok
112
- if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok
113
- if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24'); //I haven't tested anything besides 24
114
- if(! defined('WEBSHOT_IMAGE_FORMAT') ) define ('WEBSHOT_IMAGE_FORMAT', 'png'); //png is about 2.5 times the size of jpg but is a LOT better quality
115
- if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20'); //Seconds to wait for a webshot
116
- if(! defined('WEBSHOT_USER_AGENT') ) define ('WEBSHOT_USER_AGENT', "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.18) Gecko/20110614 Firefox/3.6.18"); //I hate to do this, but a non-browser robot user agent might not show what humans see. So we pretend to be Firefox
117
- if(! defined('WEBSHOT_JAVASCRIPT_ON') ) define ('WEBSHOT_JAVASCRIPT_ON', true); //Setting to false might give you a slight speedup and block ads. But it could cause other issues.
118
- if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false); //Have only tested this as fase
119
- if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true); //Enable flash and other plugins
120
- if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', ''); //In case you're behind a proxy server.
121
- if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false); //ADVANCED: Enable this if you've got Xvfb running in the background.
122
-
123
-
124
- // If ALLOW_EXTERNAL is true and ALLOW_ALL_EXTERNAL_SITES is false, then external images will only be fetched from these domains and their subdomains.
125
- if(! isset($ALLOWED_SITES)){
126
- $ALLOWED_SITES = array ();
127
- }
128
- // -------------------------------------------------------------
129
- // -------------- STOP EDITING CONFIGURATION HERE --------------
130
- // -------------------------------------------------------------
131
-
132
- timthumb::start();
133
-
134
- class timthumb {
135
- protected $src = "";
136
- protected $is404 = false;
137
- protected $docRoot = "";
138
- protected $lastURLError = false;
139
- protected $localImage = "";
140
- protected $localImageMTime = 0;
141
- protected $url = false;
142
- protected $myHost = "";
143
- protected $isURL = false;
144
- protected $cachefile = '';
145
- protected $errors = array();
146
- protected $toDeletes = array();
147
- protected $cacheDirectory = '';
148
- protected $startTime = 0;
149
- protected $lastBenchTime = 0;
150
- protected $cropTop = false;
151
- protected $salt = "";
152
- protected $fileCacheVersion = 1; //Generally if timthumb.php is modifed (upgraded) then the salt changes and all cache files are recreated. This is a backup mechanism to force regen.
153
- protected $filePrependSecurityBlock = "<?php die('Execution denied!'); //"; //Designed to have three letter mime type, space, question mark and greater than symbol appended. 6 bytes total.
154
- protected static $curlDataWritten = 0;
155
- protected static $curlFH = false;
156
- public static function start(){
157
- $tim = new timthumb();
158
- $tim->handleErrors();
159
- $tim->securityChecks();
160
- if($tim->tryBrowserCache()){
161
- exit(0);
162
- }
163
- $tim->handleErrors();
164
- if(FILE_CACHE_ENABLED && $tim->tryServerCache()){
165
- exit(0);
166
- }
167
- $tim->handleErrors();
168
- $tim->run();
169
- $tim->handleErrors();
170
- exit(0);
171
- }
172
- public function __construct(){
173
- global $ALLOWED_SITES;
174
- $this->startTime = microtime(true);
175
- date_default_timezone_set('UTC');
176
- $this->debug(1, "Starting new request from " . $this->getIP() . " to " . $_SERVER['REQUEST_URI']);
177
- $this->calcDocRoot();
178
- //On windows systems I'm assuming fileinode returns an empty string or a number that doesn't change. Check this.
179
- $this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__);
180
- $this->debug(3, "Salt is: " . $this->salt);
181
- if(FILE_CACHE_DIRECTORY){
182
- if(! is_dir(FILE_CACHE_DIRECTORY)){
183
- @mkdir(FILE_CACHE_DIRECTORY);
184
- if(! is_dir(FILE_CACHE_DIRECTORY)){
185
- $this->error("Could not create the file cache directory.");
186
- return false;
187
- }
188
- }
189
- $this->cacheDirectory = FILE_CACHE_DIRECTORY;
190
- if (!touch($this->cacheDirectory . '/index.html')) {
191
- $this->error("Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory.");
192
- }
193
- } else {
194
- $this->cacheDirectory = sys_get_temp_dir();
195
- }
196
- //Clean the cache before we do anything because we don't want the first visitor after FILE_CACHE_TIME_BETWEEN_CLEANS expires to get a stale image.
197
- $this->cleanCache();
198
-
199
- $this->myHost = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST']);
200
- $this->src = $this->param('src');
201
- $this->url = parse_url($this->src);
202
- $this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '', $this->src);
203
-
204
- if(strlen($this->src) <= 3){
205
- $this->error("No image specified");
206
- return false;
207
- }
208
- if(BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && (! preg_match('/^https?:\/\/(?:www\.)?' . $this->myHost . '(?:$|\/)/i', $_SERVER['HTTP_REFERER']))){
209
- // base64 encoded red image that says 'no hotlinkers'
210
- // nothing to worry about! :)
211
- $imgData = base64_decode("R0lGODlhUAAMAIAAAP8AAP///yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZ\nOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpneb\nDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs=");
212
- header('Content-Type: image/gif');
213
- header('Content-Length: ' . sizeof($imgData));
214
- header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
215
- header("Pragma: no-cache");
216
- header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
217
- echo $imgData;
218
- return false;
219
- exit(0);
220
- }
221
- if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){
222
- $this->debug(2, "Is a request for an external URL: " . $this->src);
223
- $this->isURL = true;
224
- } else {
225
- $this->debug(2, "Is a request for an internal file: " . $this->src);
226
- }
227
- if($this->isURL && (! ALLOW_EXTERNAL)){
228
- $this->error("You are not allowed to fetch images from an external website.");
229
- return false;
230
- }
231
- if($this->isURL){
232
- if(ALLOW_ALL_EXTERNAL_SITES){
233
- $this->debug(2, "Fetching from all external sites is enabled.");
234
- } else {
235
- $this->debug(2, "Fetching only from selected external sites is enabled.");
236
- $allowed = false;
237
- foreach($ALLOWED_SITES as $site){
238
- if ((strtolower(substr($this->url['host'],-strlen($site)-1)) === strtolower(".$site")) || (strtolower($this->url['host'])===strtolower($site))) {
239
- $this->debug(3, "URL hostname {$this->url['host']} matches $site so allowing.");
240
- $allowed = true;
241
- }
242
- }
243
- if(! $allowed){
244
- return $this->error("You may not fetch images from that site. To enable this site in timthumb, you can either add it to \$ALLOWED_SITES and set ALLOW_EXTERNAL=true. Or you can set ALLOW_ALL_EXTERNAL_SITES=true, depending on your security needs.");
245
- }
246
- }
247
- }
248
-
249
- $cachePrefix = ($this->isURL ? '_ext_' : '_int_');
250
- if($this->isURL){
251
- $arr = explode('&', $_SERVER ['QUERY_STRING']);
252
- asort($arr);
253
- $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
254
- } else {
255
- $this->localImage = $this->getLocalImagePath($this->src);
256
- if(! $this->localImage){
257
- $this->debug(1, "Could not find the local image: {$this->localImage}");
258
- $this->error("Could not find the internal image you specified.");
259
- $this->set404();
260
- return false;
261
- }
262
- $this->debug(1, "Local image path is {$this->localImage}");
263
- $this->localImageMTime = @filemtime($this->localImage);
264
- //We include the mtime of the local file in case in changes on disk.
265
- $this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER ['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
266
- }
267
- $this->debug(2, "Cache file is: " . $this->cachefile);
268
-
269
- return true;
270
- }
271
- public function __destruct(){
272
- foreach($this->toDeletes as $del){
273
- $this->debug(2, "Deleting temp file $del");
274
- @unlink($del);
275
- }
276
- }
277
- public function run(){
278
- if($this->isURL){
279
- if(! ALLOW_EXTERNAL){
280
- $this->debug(1, "Got a request for an external image but ALLOW_EXTERNAL is disabled so returning error msg.");
281
- $this->error("You are not allowed to fetch images from an external website.");
282
- return false;
283
- }
284
- $this->debug(3, "Got request for external image. Starting serveExternalImage.");
285
- if($this->param('webshot')){
286
- if(WEBSHOT_ENABLED){
287
- $this->debug(3, "webshot param is set, so we're going to take a webshot.");
288
- $this->serveWebshot();
289
- } else {
290
- $this->error("You added the webshot parameter but webshots are disabled on this server. You need to set WEBSHOT_ENABLED == true to enable webshots.");
291
- }
292
- } else {
293
- $this->debug(3, "webshot is NOT set so we're going to try to fetch a regular image.");
294
- $this->serveExternalImage();
295
-
296
- }
297
- } else {
298
- $this->debug(3, "Got request for internal image. Starting serveInternalImage()");
299
- $this->serveInternalImage();
300
- }
301
- return true;
302
- }
303
- protected function handleErrors(){
304
- if($this->haveErrors()){
305
- if(NOT_FOUND_IMAGE && $this->is404()){
306
- if($this->serveImg(NOT_FOUND_IMAGE)){
307
- exit(0);
308
- } else {
309
- $this->error("Additionally, the 404 image that is configured could not be found or there was an error serving it.");
310
- }
311
- }
312
- if(ERROR_IMAGE){
313
- if($this->serveImg(ERROR_IMAGE)){
314
- exit(0);
315
- } else {
316
- $this->error("Additionally, the error image that is configured could not be found or there was an error serving it.");
317
- }
318
- }
319
- $this->serveErrors();
320
- exit(0);
321
- }
322
- return false;
323
- }
324
- protected function tryBrowserCache(){
325
- if(BROWSER_CACHE_DISABLE){ $this->debug(3, "Browser caching is disabled"); return false; }
326
- if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){
327
- $this->debug(3, "Got a conditional get");
328
- $mtime = false;
329
- //We've already checked if the real file exists in the constructor
330
- if(! is_file($this->cachefile)){
331
- //If we don't have something cached, regenerate the cached image.
332
- return false;
333
- }
334
- if($this->localImageMTime){
335
- $mtime = $this->localImageMTime;
336
- $this->debug(3, "Local real file's modification time is $mtime");
337
- } else if(is_file($this->cachefile)){ //If it's not a local request then use the mtime of the cached file to determine the 304
338
- $mtime = @filemtime($this->cachefile);
339
- $this->debug(3, "Cached file's modification time is $mtime");
340
- }
341
- if(! $mtime){ return false; }
342
-
343
- $iftime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
344
- $this->debug(3, "The conditional get's if-modified-since unixtime is $iftime");
345
- if($iftime < 1){
346
- $this->debug(3, "Got an invalid conditional get modified since time. Returning false.");
347
- return false;
348
- }
349
- if($iftime < $mtime){ //Real file or cache file has been modified since last request, so force refetch.
350
- $this->debug(3, "File has been modified since last fetch.");
351
- return false;
352
- } else { //Otherwise serve a 304
353
- $this->debug(3, "File has not been modified since last get, so serving a 304.");
354
- header ($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
355
- $this->debug(1, "Returning 304 not modified");
356
- return true;
357
- }
358
- }
359
- return false;
360
- }
361
- protected function tryServerCache(){
362
- $this->debug(3, "Trying server cache");
363
- if(file_exists($this->cachefile)){
364
- $this->debug(3, "Cachefile {$this->cachefile} exists");
365
- if($this->isURL){
366
- $this->debug(3, "This is an external request, so checking if the cachefile is empty which means the request failed previously.");
367
- if(filesize($this->cachefile) < 1){
368
- $this->debug(3, "Found an empty cachefile indicating a failed earlier request. Checking how old it is.");
369
- //Fetching error occured previously
370
- if(time() - @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){
371
- $this->debug(3, "File is older than " . WAIT_BETWEEN_FETCH_ERRORS . " seconds. Deleting and returning false so app can try and load file.");
372
- @unlink($this->cachefile);
373
- return false; //to indicate we didn't serve from cache and app should try and load
374
- } else {
375
- $this->debug(3, "Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.");
376
- $this->set404();
377
- $this->error("An error occured fetching image.");
378
- return false;
379
- }
380
- }
381
- } else {
382
- $this->debug(3, "Trying to serve cachefile {$this->cachefile}");
383
- }
384
- if($this->serveCacheFile()){
385
- $this->debug(3, "Succesfully served cachefile {$this->cachefile}");
386
- return true;
387
- } else {
388
- $this->debug(3, "Failed to serve cachefile {$this->cachefile} - Deleting it from cache.");
389
- //Image serving failed. We can't retry at this point, but lets remove it from cache so the next request recreates it
390
- @unlink($this->cachefile);
391
- return true;
392
- }
393
- }
394
- }
395
- protected function error($err){
396
- $this->debug(3, "Adding error message: $err");
397
- $this->errors[] = $err;
398
- return false;
399
-
400
- }
401
- protected function haveErrors(){
402
- if(sizeof($this->errors) > 0){
403
- return true;
404
- }
405
- return false;
406
- }
407
- protected function serveErrors(){
408
- header ($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
409
- $html = '<ul>';
410
- foreach($this->errors as $err){
411
- $html .= '<li>' . htmlentities($err) . '</li>';
412
- }
413
- $html .= '</ul>';
414
- echo '<h1>A TimThumb error has occured</h1>The following error(s) occured:<br />' . $html . '<br />';
415
- echo '<br />Query String : ' . htmlentities ($_SERVER['QUERY_STRING']);
416
- echo '<br />TimThumb version : ' . VERSION . '</pre>';
417
- }
418
- protected function serveInternalImage(){
419
- $this->debug(3, "Local image path is $this->localImage");
420
- if(! $this->localImage){
421
- $this->sanityFail("localImage not set after verifying it earlier in the code.");
422
- return false;
423
- }
424
- $fileSize = filesize($this->localImage);
425
- if($fileSize > MAX_FILE_SIZE){
426
- $this->error("The file you specified is greater than the maximum allowed file size.");
427
- return false;
428
- }
429
- if($fileSize <= 0){
430
- $this->error("The file you specified is <= 0 bytes.");
431
- return false;
432
- }
433
- $this->debug(3, "Calling processImageAndWriteToCache() for local image.");
434
- if($this->processImageAndWriteToCache($this->localImage)){
435
- $this->serveCacheFile();
436
- return true;
437
- } else {
438
- return false;
439
- }
440
- }
441
- protected function cleanCache(){
442
- if (FILE_CACHE_TIME_BETWEEN_CLEANS < 0) {
443
- return;
444
- }
445
- $this->debug(3, "cleanCache() called");
446
- $lastCleanFile = $this->cacheDirectory . '/timthumb_cacheLastCleanTime.touch';
447
-
448
- //If this is a new timthumb installation we need to create the file
449
- if(! is_file($lastCleanFile)){
450
- $this->debug(1, "File tracking last clean doesn't exist. Creating $lastCleanFile");
451
- if (!touch($lastCleanFile)) {
452
- $this->error("Could not create cache clean timestamp file.");
453
- }
454
- return;
455
- }
456
- if(@filemtime($lastCleanFile) < (time() - FILE_CACHE_TIME_BETWEEN_CLEANS) ){ //Cache was last cleaned more than 1 day ago
457
- $this->debug(1, "Cache was last cleaned more than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago. Cleaning now.");
458
- // Very slight race condition here, but worst case we'll have 2 or 3 servers cleaning the cache simultaneously once a day.
459
- if (!touch($lastCleanFile)) {
460
- $this->error("Could not create cache clean timestamp file.");
461
- }
462
- $files = glob($this->cacheDirectory . '/*' . FILE_CACHE_SUFFIX);
463
- if ($files) {
464
- $timeAgo = time() - FILE_CACHE_MAX_FILE_AGE;
465
- foreach($files as $file){
466
- if(@filemtime($file) < $timeAgo){
467
- $this->debug(3, "Deleting cache file $file older than max age: " . FILE_CACHE_MAX_FILE_AGE . " seconds");
468
- @unlink($file);
469
- }
470
- }
471
- }
472
- return true;
473
- } else {
474
- $this->debug(3, "Cache was cleaned less than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago so no cleaning needed.");
475
- }
476
- return false;
477
- }
478
- protected function processImageAndWriteToCache($localImage){
479
- $sData = getimagesize($localImage);
480
- $origType = $sData[2];
481
- $mimeType = $sData['mime'];
482
-
483
- $this->debug(3, "Mime type of image is $mimeType");
484
- if(! preg_match('/^image\/(?:gif|jpg|jpeg|png)$/i', $mimeType)){
485
- return $this->error("The image being resized is not a valid gif, jpg or png.");
486
- }
487
-
488
- if (!function_exists ('imagecreatetruecolor')) {
489
- return $this->error('GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library');
490
- }
491
-
492
- if (function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
493
- $imageFilters = array (
494
- 1 => array (IMG_FILTER_NEGATE, 0),
495
- 2 => array (IMG_FILTER_GRAYSCALE, 0),
496
- 3 => array (IMG_FILTER_BRIGHTNESS, 1),
497
- 4 => array (IMG_FILTER_CONTRAST, 1),
498
- 5 => array (IMG_FILTER_COLORIZE, 4),
499
- 6 => array (IMG_FILTER_EDGEDETECT, 0),
500
- 7 => array (IMG_FILTER_EMBOSS, 0),
501
- 8 => array (IMG_FILTER_GAUSSIAN_BLUR, 0),
502
- 9 => array (IMG_FILTER_SELECTIVE_BLUR, 0),
503
- 10 => array (IMG_FILTER_MEAN_REMOVAL, 0),
504
- 11 => array (IMG_FILTER_SMOOTH, 0),
505
- );
506
- }
507
-
508
- // get standard input properties
509
- $new_width = (int) abs ($this->param('w', 0));
510
- $new_height = (int) abs ($this->param('h', 0));
511
- $zoom_crop = (int) $this->param('zc', DEFAULT_ZC);
512
- $quality = (int) abs ($this->param('q', DEFAULT_Q));
513
- $align = $this->cropTop ? 't' : $this->param('a', 'c');
514
- $filters = $this->param('f', DEFAULT_F);
515
- $sharpen = (bool) $this->param('s', DEFAULT_S);
516
- $canvas_color = $this->param('cc', DEFAULT_CC);
517
- $canvas_trans = (bool) $this->param('ct', '1');
518
-
519
- // set default width and height if neither are set already
520
- if ($new_width == 0 && $new_height == 0) {
521
- $new_width = 100;
522
- $new_height = 100;
523
- }
524
-
525
- // ensure size limits can not be abused
526
- $new_width = min ($new_width, MAX_WIDTH);
527
- $new_height = min ($new_height, MAX_HEIGHT);
528
-
529
- // set memory limit to be able to have enough space to resize larger images
530
- $this->setMemoryLimit();
531
-
532
- // open the existing image
533
- $image = $this->openImage ($mimeType, $localImage);
534
- if ($image === false) {
535
- return $this->error('Unable to open image.');
536
- }
537
-
538
- // Get original width and height
539
- $width = imagesx ($image);
540
- $height = imagesy ($image);
541
- $origin_x = 0;
542
- $origin_y = 0;
543
-
544
- // generate new w/h if not provided
545
- if ($new_width && !$new_height) {
546
- $new_height = floor ($height * ($new_width / $width));
547
- } else if ($new_height && !$new_width) {
548
- $new_width = floor ($width * ($new_height / $height));
549
- }
550
-
551
- // scale down and add borders
552
- if ($zoom_crop == 3) {
553
-
554
- $final_height = $height * ($new_width / $width);
555
-
556
- if ($final_height > $new_height) {
557
- $new_width = $width * ($new_height / $height);
558
- } else {
559
- $new_height = $final_height;
560
- }
561
-
562
- }
563
-
564
- // create a new true color image
565
- $canvas = imagecreatetruecolor ($new_width, $new_height);
566
- imagealphablending ($canvas, false);
567
-
568
- if (strlen($canvas_color) == 3) { //if is 3-char notation, edit string into 6-char notation
569
- $canvas_color = str_repeat(substr($canvas_color, 0, 1), 2) . str_repeat(substr($canvas_color, 1, 1), 2) . str_repeat(substr($canvas_color, 2, 1), 2);
570
- } else if (strlen($canvas_color) != 6) {
571
- $canvas_color = DEFAULT_CC; // on error return default canvas color
572
- }
573
-
574
- $canvas_color_R = hexdec (substr ($canvas_color, 0, 2));
575
- $canvas_color_G = hexdec (substr ($canvas_color, 2, 2));
576
- $canvas_color_B = hexdec (substr ($canvas_color, 4, 2));
577
-
578
- // Create a new transparent color for image
579
- // If is a png and PNG_IS_TRANSPARENT is false then remove the alpha transparency
580
- // (and if is set a canvas color show it in the background)
581
- if(preg_match('/^image\/png$/i', $mimeType) && !PNG_IS_TRANSPARENT && $canvas_trans){
582
- $color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 127);
583
- }else{
584
- $color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 0);
585
- }
586
-
587
-
588
- // Completely fill the background of the new image with allocated color.
589
- imagefill ($canvas, 0, 0, $color);
590
-
591
- // scale down and add borders
592
- if ($zoom_crop == 2) {
593
-
594
- $final_height = $height * ($new_width / $width);
595
-
596
- if ($final_height > $new_height) {
597
-
598
- $origin_x = $new_width / 2;
599
- $new_width = $width * ($new_height / $height);
600
- $origin_x = round ($origin_x - ($new_width / 2));
601
-
602
- } else {
603
-
604
- $origin_y = $new_height / 2;
605
- $new_height = $final_height;
606
- $origin_y = round ($origin_y - ($new_height / 2));
607
-
608
- }
609
-
610
- }
611
-
612
- // Restore transparency blending
613
- imagesavealpha ($canvas, true);
614
-
615
- if ($zoom_crop > 0) {
616
-
617
- $src_x = $src_y = 0;
618
- $src_w = $width;
619
- $src_h = $height;
620
-
621
- $cmp_x = $width / $new_width;
622
- $cmp_y = $height / $new_height;
623
-
624
- // calculate x or y coordinate and width or height of source
625
- if ($cmp_x > $cmp_y) {
626
-
627
- $src_w = round ($width / $cmp_x * $cmp_y);
628
- $src_x = round (($width - ($width / $cmp_x * $cmp_y)) / 2);
629
-
630
- } else if ($cmp_y > $cmp_x) {
631
-
632
- $src_h = round ($height / $cmp_y * $cmp_x);
633
- $src_y = round (($height - ($height / $cmp_y * $cmp_x)) / 2);
634
-
635
- }
636
-
637
- // positional cropping!
638
- if ($align) {
639
- if (strpos ($align, 't') !== false) {
640
- $src_y = 0;
641
- }
642
- if (strpos ($align, 'b') !== false) {
643
- $src_y = $height - $src_h;
644
- }
645
- if (strpos ($align, 'l') !== false) {
646
- $src_x = 0;
647
- }
648
- if (strpos ($align, 'r') !== false) {
649
- $src_x = $width - $src_w;
650
- }
651
- }
652
-
653
- imagecopyresampled ($canvas, $image, $origin_x, $origin_y, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h);
654
-
655
- } else {
656
-
657
- // copy and resize part of an image with resampling
658
- imagecopyresampled ($canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
659
-
660
- }
661
-
662
- if ($filters != '' && function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
663
- // apply filters to image
664
- $filterList = explode ('|', $filters);
665
- foreach ($filterList as $fl) {
666
-
667
- $filterSettings = explode (',', $fl);
668
- if (isset ($imageFilters[$filterSettings[0]])) {
669
-
670
- for ($i = 0; $i < 4; $i ++) {
671
- if (!isset ($filterSettings[$i])) {
672
- $filterSettings[$i] = null;
673
- } else {
674
- $filterSettings[$i] = (int) $filterSettings[$i];
675
- }
676
- }
677
-
678
- switch ($imageFilters[$filterSettings[0]][1]) {
679
-
680
- case 1:
681
-
682
- imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1]);
683
- break;
684
-
685
- case 2:
686
-
687
- imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2]);
688
- break;
689
-
690
- case 3:
691
-
692
- imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3]);
693
- break;
694
-
695
- case 4:
696
-
697
- imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3], $filterSettings[4]);
698
- break;
699
-
700
- default:
701
-
702
- imagefilter ($canvas, $imageFilters[$filterSettings[0]][0]);
703
- break;
704
-
705
- }
706
- }
707
- }
708
- }
709
-
710
- // sharpen image
711
- if ($sharpen && function_exists ('imageconvolution')) {
712
-
713
- $sharpenMatrix = array (
714
- array (-1,-1,-1),
715
- array (-1,16,-1),
716
- array (-1,-1,-1),
717
- );
718
-
719
- $divisor = 8;
720
- $offset = 0;
721
-
722
- imageconvolution ($canvas, $sharpenMatrix, $divisor, $offset);
723
-
724
- }
725
- //Straight from Wordpress core code. Reduces filesize by up to 70% for PNG's
726
- if ( (IMAGETYPE_PNG == $origType || IMAGETYPE_GIF == $origType) && function_exists('imageistruecolor') && !imageistruecolor( $image ) && imagecolortransparent( $image ) > 0 ){
727
- imagetruecolortopalette( $canvas, false, imagecolorstotal( $image ) );
728
- }
729
-
730
- $imgType = "";
731
- $tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
732
- if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){
733
- $imgType = 'jpg';
734
- imagejpeg($canvas, $tempfile, $quality);
735
- } else if(preg_match('/^image\/png$/i', $mimeType)){
736
- $imgType = 'png';
737
- imagepng($canvas, $tempfile, floor($quality * 0.09));
738
- } else if(preg_match('/^image\/gif$/i', $mimeType)){
739
- $imgType = 'gif';
740
- imagegif($canvas, $tempfile);
741
- } else {
742
- return $this->sanityFail("Could not match mime type after verifying it previously.");
743
- }
744
-
745
- if($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)){
746
- $exec = OPTIPNG_PATH;
747
- $this->debug(3, "optipng'ing $tempfile");
748
- $presize = filesize($tempfile);
749
- $out = `$exec -o1 $tempfile`; //you can use up to -o7 but it really slows things down
750
- clearstatcache();
751
- $aftersize = filesize($tempfile);
752
- $sizeDrop = $presize - $aftersize;
753
- if($sizeDrop > 0){
754
- $this->debug(1, "optipng reduced size by $sizeDrop");
755
- } else if($sizeDrop < 0){
756
- $this->debug(1, "optipng increased size! Difference was: $sizeDrop");
757
- } else {
758
- $this->debug(1, "optipng did not change image size.");
759
- }
760
- } else if($imgType == 'png' && PNGCRUSH_ENABLED && PNGCRUSH_PATH && @is_file(PNGCRUSH_PATH)){
761
- $exec = PNGCRUSH_PATH;
762
- $tempfile2 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
763
- $this->debug(3, "pngcrush'ing $tempfile to $tempfile2");
764
- $out = `$exec $tempfile $tempfile2`;
765
- $todel = "";
766
- if(is_file($tempfile2)){
767
- $sizeDrop = filesize($tempfile) - filesize($tempfile2);
768
- if($sizeDrop > 0){
769
- $this->debug(1, "pngcrush was succesful and gave a $sizeDrop byte size reduction");
770
- $todel = $tempfile;
771
- $tempfile = $tempfile2;
772
- } else {
773
- $this->debug(1, "pngcrush did not reduce file size. Difference was $sizeDrop bytes.");
774
- $todel = $tempfile2;
775
- }
776
- } else {
777
- $this->debug(3, "pngcrush failed with output: $out");
778
- $todel = $tempfile2;
779
- }
780
- @unlink($todel);
781
- }
782
-
783
- $this->debug(3, "Rewriting image with security header.");
784
- $tempfile4 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
785
- $context = stream_context_create ();
786
- $fp = fopen($tempfile,'r',0,$context);
787
- file_put_contents($tempfile4, $this->filePrependSecurityBlock . $imgType . ' ?' . '>'); //6 extra bytes, first 3 being image type
788
- file_put_contents($tempfile4, $fp, FILE_APPEND);
789
- fclose($fp);
790
- @unlink($tempfile);
791
- $this->debug(3, "Locking and replacing cache file.");
792
- $lockFile = $this->cachefile . '.lock';
793
- $fh = fopen($lockFile, 'w');
794
- if(! $fh){
795
- return $this->error("Could not open the lockfile for writing an image.");
796
- }
797
- if(flock($fh, LOCK_EX)){
798
- @unlink($this->cachefile); //rename generally overwrites, but doing this in case of platform specific quirks. File might not exist yet.
799
- rename($tempfile4, $this->cachefile);
800
- flock($fh, LOCK_UN);
801
- fclose($fh);
802
- @unlink($lockFile);
803
- } else {
804
- fclose($fh);
805
- @unlink($lockFile);
806
- @unlink($tempfile4);
807
- return $this->error("Could not get a lock for writing.");
808
- }
809
- $this->debug(3, "Done image replace with security header. Cleaning up and running cleanCache()");
810
- imagedestroy($canvas);
811
- imagedestroy($image);
812
- return true;
813
- }
814
- protected function calcDocRoot(){
815
- $docRoot = @$_SERVER['DOCUMENT_ROOT'];
816
- if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
817
- $docRoot = LOCAL_FILE_BASE_DIRECTORY;
818
- }
819
- if(!isset($docRoot)){
820
- $this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting search 1.");
821
- if(isset($_SERVER['SCRIPT_FILENAME'])){
822
- $docRoot = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
823
- $this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot");
824
- }
825
- }
826
- if(!isset($docRoot)){
827
- $this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2.");
828
- if(isset($_SERVER['PATH_TRANSLATED'])){
829
- $docRoot = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
830
- $this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot");
831
- }
832
- }
833
- if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = preg_replace('/\/$/', '', $docRoot); }
834
- $this->debug(3, "Doc root is: " . $docRoot);
835
- $this->docRoot = $docRoot;
836
-
837
- }
838
- protected function getLocalImagePath($src){
839
- $src = ltrim($src, '/'); //strip off the leading '/'
840
- if(! $this->docRoot){
841
- $this->debug(3, "We have no document root set, so as a last resort, lets check if the image is in the current dir and serve that.");
842
- //We don't support serving images outside the current dir if we don't have a doc root for security reasons.
843
- $file = preg_replace('/^.*?([^\/\\\\]+)$/', '$1', $src); //strip off any path info and just leave the filename.
844
- if(is_file($file)){
845
- return $this->realpath($file);
846
- }
847
- return $this->error("Could not find your website document root and the file specified doesn't exist in timthumbs directory. We don't support serving files outside timthumb's directory without a document root for security reasons.");
848
- } //Do not go past this point without docRoot set
849
-
850
- //Try src under docRoot
851
- if(file_exists ($this->docRoot . '/' . $src)) {
852
- $this->debug(3, "Found file as " . $this->docRoot . '/' . $src);
853
- $real = $this->realpath($this->docRoot . '/' . $src);
854
- if(stripos($real, $this->docRoot) === 0){
855
- return $real;
856
- } else {
857
- $this->debug(1, "Security block: The file specified occurs outside the document root.");
858
- //allow search to continue
859
- }
860
- }
861
- //Check absolute paths and then verify the real path is under doc root
862
- $absolute = $this->realpath('/' . $src);
863
- if($absolute && file_exists($absolute)){ //realpath does file_exists check, so can probably skip the exists check here
864
- $this->debug(3, "Found absolute path: $absolute");
865
- if(! $this->docRoot){ $this->sanityFail("docRoot not set when checking absolute path."); }
866
- if(stripos($absolute, $this->docRoot) === 0){
867
- return $absolute;
868
- } else {
869
- $this->debug(1, "Security block: The file specified occurs outside the document root.");
870
- //and continue search
871
- }
872
- }
873
-
874
- $base = $this->docRoot;
875
-
876
- // account for Windows directory structure
877
- if (strstr($_SERVER['SCRIPT_FILENAME'],':')) {
878
- $sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
879
- } else {
880
- $sub_directories = explode('/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
881
- }
882
-
883
- foreach ($sub_directories as $sub){
884
- $base .= $sub . '/';
885
- $this->debug(3, "Trying file as: " . $base . $src);
886
- if(file_exists($base . $src)){
887
- $this->debug(3, "Found file as: " . $base . $src);
888
- $real = $this->realpath($base . $src);
889
- if(stripos($real, $this->realpath($this->docRoot)) === 0){
890
- return $real;
891
- } else {
892
- $this->debug(1, "Security block: The file specified occurs outside the document root.");
893
- //And continue search
894
- }
895
- }
896
- }
897
- return false;
898
- }
899
- protected function realpath($path){
900
- //try to remove any relative paths
901
- $remove_relatives = '/\w+\/\.\.\//';
902
- while(preg_match($remove_relatives,$path)){
903
- $path = preg_replace($remove_relatives, '', $path);
904
- }
905
- //if any remain use PHP realpath to strip them out, otherwise return $path
906
- //if using realpath, any symlinks will also be resolved
907
- return preg_match('#^\.\./|/\.\./#', $path) ? realpath($path) : $path;
908
- }
909
- protected function toDelete($name){
910
- $this->debug(3, "Scheduling file $name to delete on destruct.");
911
- $this->toDeletes[] = $name;
912
- }
913
- protected function serveWebshot(){
914
- $this->debug(3, "Starting serveWebshot");
915
- $instr = "Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots.";
916
- if(! is_file(WEBSHOT_CUTYCAPT)){
917
- return $this->error("CutyCapt is not installed. $instr");
918
- }
919
- if(! is_file(WEBSHOT_XVFB)){
920
- return $this->Error("Xvfb is not installed. $instr");
921
- }
922
- $cuty = WEBSHOT_CUTYCAPT;
923
- $xv = WEBSHOT_XVFB;
924
- $screenX = WEBSHOT_SCREEN_X;
925
- $screenY = WEBSHOT_SCREEN_Y;
926
- $colDepth = WEBSHOT_COLOR_DEPTH;
927
- $format = WEBSHOT_IMAGE_FORMAT;
928
- $timeout = WEBSHOT_TIMEOUT * 1000;
929
- $ua = WEBSHOT_USER_AGENT;
930
- $jsOn = WEBSHOT_JAVASCRIPT_ON ? 'on' : 'off';
931
- $javaOn = WEBSHOT_JAVA_ON ? 'on' : 'off';
932
- $pluginsOn = WEBSHOT_PLUGINS_ON ? 'on' : 'off';
933
- $proxy = WEBSHOT_PROXY ? ' --http-proxy=' . WEBSHOT_PROXY : '';
934
- $tempfile = tempnam($this->cacheDirectory, 'timthumb_webshot');
935
- $url = $this->src;
936
- if(! preg_match('/^https?:\/\/[a-zA-Z0-9\.\-]+/i', $url)){
937
- return $this->error("Invalid URL supplied.");
938
- }
939
- $url = preg_replace('/[^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+/', '', $url); //RFC 3986
940
- //Very important we don't allow injection of shell commands here. URL is between quotes and we are only allowing through chars allowed by a the RFC
941
- // which AFAIKT can't be used for shell injection.
942
- if(WEBSHOT_XVFB_RUNNING){
943
- putenv('DISPLAY=:100.0');
944
- $command = "$cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile";
945
- } else {
946
- $command = "$xv --server-args=\"-screen 0, {$screenX}x{$screenY}x{$colDepth}\" $cuty $proxy --max-wait=$timeout --user-agent=\"$ua\" --javascript=$jsOn --java=$javaOn --plugins=$pluginsOn --js-can-open-windows=off --url=\"$url\" --out-format=$format --out=$tempfile";
947
- }
948
- $this->debug(3, "Executing command: $command");
949
- $out = `$command`;
950
- $this->debug(3, "Received output: $out");
951
- if(! is_file($tempfile)){
952
- $this->set404();
953
- return $this->error("The command to create a thumbnail failed.");
954
- }
955
- $this->cropTop = true;
956
- if($this->processImageAndWriteToCache($tempfile)){
957
- $this->debug(3, "Image processed succesfully. Serving from cache");
958
- return $this->serveCacheFile();
959
- } else {
960
- return false;
961
- }
962
- }
963
- protected function serveExternalImage(){
964
- if(! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+/i', $this->src)){
965
- $this->error("Invalid URL supplied.");
966
- return false;
967
- }
968
- $tempfile = tempnam($this->cacheDirectory, 'timthumb');
969
- $this->debug(3, "Fetching external image into temporary file $tempfile");
970
- $this->toDelete($tempfile);
971
- #fetch file here
972
- if(! $this->getURL($this->src, $tempfile)){
973
- @unlink($this->cachefile);
974
- touch($this->cachefile);
975
- $this->debug(3, "Error fetching URL: " . $this->lastURLError);
976
- $this->error("Error reading the URL you specified from remote host." . $this->lastURLError);
977
- return false;
978
- }
979
-
980
- $mimeType = $this->getMimeType($tempfile);
981
- if(! preg_match("/^image\/(?:jpg|jpeg|gif|png)$/i", $mimeType)){
982
- $this->debug(3, "Remote file has invalid mime type: $mimeType");
983
- @unlink($this->cachefile);
984
- touch($this->cachefile);
985
- $this->error("The remote file is not a valid image. Mimetype = '" . $mimeType . "'" . $tempfile);
986
- return false;
987
- }
988
- if($this->processImageAndWriteToCache($tempfile)){
989
- $this->debug(3, "Image processed succesfully. Serving from cache");
990
- return $this->serveCacheFile();
991
- } else {
992
- return false;
993
- }
994
- }
995
- public static function curlWrite($h, $d){
996
- fwrite(self::$curlFH, $d);
997
- self::$curlDataWritten += strlen($d);
998
- if(self::$curlDataWritten > MAX_FILE_SIZE){
999
- return 0;
1000
- } else {
1001
- return strlen($d);
1002
- }
1003
- }
1004
- protected function serveCacheFile(){
1005
- $this->debug(3, "Serving {$this->cachefile}");
1006
- if(! is_file($this->cachefile)){
1007
- $this->error("serveCacheFile called in timthumb but we couldn't find the cached file.");
1008
- return false;
1009
- }
1010
- $fp = fopen($this->cachefile, 'rb');
1011
- if(! $fp){ return $this->error("Could not open cachefile."); }
1012
- fseek($fp, strlen($this->filePrependSecurityBlock), SEEK_SET);
1013
- $imgType = fread($fp, 3);
1014
- fseek($fp, 3, SEEK_CUR);
1015
- if(ftell($fp) != strlen($this->filePrependSecurityBlock) + 6){
1016
- @unlink($this->cachefile);
1017
- return $this->error("The cached image file seems to be corrupt.");
1018
- }
1019
- $imageDataSize = filesize($this->cachefile) - (strlen($this->filePrependSecurityBlock) + 6);
1020
- $this->sendImageHeaders($imgType, $imageDataSize);
1021
- $bytesSent = @fpassthru($fp);
1022
- fclose($fp);
1023
- if($bytesSent > 0){
1024
- return true;
1025
- }
1026
- $content = file_get_contents ($this->cachefile);
1027
- if ($content != FALSE) {
1028
- $content = substr($content, strlen($this->filePrependSecurityBlock) + 6);
1029
- echo $content;
1030
- $this->debug(3, "Served using file_get_contents and echo");
1031
- return true;
1032
- } else {
1033
- $this->error("Cache file could not be loaded.");
1034
- return false;
1035
- }
1036
- }
1037
- protected function sendImageHeaders($mimeType, $dataSize){
1038
- if(! preg_match('/^image\//i', $mimeType)){
1039
- $mimeType = 'image/' . $mimeType;
1040
- }
1041
- if(strtolower($mimeType) == 'image/jpg'){
1042
- $mimeType = 'image/jpeg';
1043
- }
1044
- $gmdate_expires = gmdate ('D, d M Y H:i:s', strtotime ('now +10 days')) . ' GMT';
1045
- $gmdate_modified = gmdate ('D, d M Y H:i:s') . ' GMT';
1046
- // send content headers then display image
1047
- header ('Content-Type: ' . $mimeType);
1048
- header ('Accept-Ranges: none'); //Changed this because we don't accept range requests
1049
- header ('Last-Modified: ' . $gmdate_modified);
1050
- header ('Content-Length: ' . $dataSize);
1051
- if(BROWSER_CACHE_DISABLE){
1052
- $this->debug(3, "Browser cache is disabled so setting non-caching headers.");
1053
- header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
1054
- header("Pragma: no-cache");
1055
- header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
1056
- } else {
1057
- $this->debug(3, "Browser caching is enabled");
1058
- header('Cache-Control: max-age=' . BROWSER_CACHE_MAX_AGE . ', must-revalidate');
1059
- header('Expires: ' . $gmdate_expires);
1060
- }
1061
- return true;
1062
- }
1063
- protected function securityChecks(){
1064
- }
1065
- protected function param($property, $default = ''){
1066
- if (isset ($_GET[$property])) {
1067
- return $_GET[$property];
1068
- } else {
1069
- return $default;
1070
- }
1071
- }
1072
- protected function openImage($mimeType, $src){
1073
- switch ($mimeType) {
1074
- case 'image/jpeg':
1075
- $image = imagecreatefromjpeg ($src);
1076
- break;
1077
-
1078
- case 'image/png':
1079
- $image = imagecreatefrompng ($src);
1080
- imagealphablending( $image, true );
1081
- imagesavealpha( $image, true );
1082
- break;
1083
-
1084
- case 'image/gif':
1085
- $image = imagecreatefromgif ($src);
1086
- break;
1087
-
1088
- default:
1089
- $this->error("Unrecognised mimeType");
1090
- }
1091
-
1092
- return $image;
1093
- }
1094
- protected function getIP(){
1095
- $rem = @$_SERVER["REMOTE_ADDR"];
1096
- $ff = @$_SERVER["HTTP_X_FORWARDED_FOR"];
1097
- $ci = @$_SERVER["HTTP_CLIENT_IP"];
1098
- if(preg_match('/^(?:192\.168|172\.16|10\.|127\.)/', $rem)){
1099
- if($ff){ return $ff; }
1100
- if($ci){ return $ci; }
1101
- return $rem;
1102
- } else {
1103
- if($rem){ return $rem; }
1104
- if($ff){ return $ff; }
1105
- if($ci){ return $ci; }
1106
- return "UNKNOWN";
1107
- }
1108
- }
1109
- protected function debug($level, $msg){
1110
- if(DEBUG_ON && $level <= DEBUG_LEVEL){
1111
- $execTime = sprintf('%.6f', microtime(true) - $this->startTime);
1112
- $tick = sprintf('%.6f', 0);
1113
- if($this->lastBenchTime > 0){
1114
- $tick = sprintf('%.6f', microtime(true) - $this->lastBenchTime);
1115
- }
1116
- $this->lastBenchTime = microtime(true);
1117
- error_log("TimThumb Debug line " . __LINE__ . " [$execTime : $tick]: $msg");
1118
- }
1119
- }
1120
- protected function sanityFail($msg){
1121
- return $this->error("There is a problem in the timthumb code. Message: Please report this error at <a href='http://code.google.com/p/timthumb/issues/list'>timthumb's bug tracking page</a>: $msg");
1122
- }
1123
- protected function getMimeType($file){
1124
- $info = getimagesize($file);
1125
- if(is_array($info) && $info['mime']){
1126
- return $info['mime'];
1127
- }
1128
- return '';
1129
- }
1130
- protected function setMemoryLimit(){
1131
- $inimem = ini_get('memory_limit');
1132
- $inibytes = timthumb::returnBytes($inimem);
1133
- $ourbytes = timthumb::returnBytes(MEMORY_LIMIT);
1134
- if($inibytes < $ourbytes){
1135
- ini_set ('memory_limit', MEMORY_LIMIT);
1136
- $this->debug(3, "Increased memory from $inimem to " . MEMORY_LIMIT);
1137
- } else {
1138
- $this->debug(3, "Not adjusting memory size because the current setting is " . $inimem . " and our size of " . MEMORY_LIMIT . " is smaller.");
1139
- }
1140
- }
1141
- protected static function returnBytes($size_str){
1142
- switch (substr ($size_str, -1))
1143
- {
1144
- case 'M': case 'm': return (int)$size_str * 1048576;
1145
- case 'K': case 'k': return (int)$size_str * 1024;
1146
- case 'G': case 'g': return (int)$size_str * 1073741824;
1147
- default: return $size_str;
1148
- }
1149
- }
1150
-
1151
- protected function getURL($url, $tempfile){
1152
- $this->lastURLError = false;
1153
- $url = preg_replace('/ /', '%20', $url);
1154
- if(function_exists('curl_init')){
1155
- $this->debug(3, "Curl is installed so using it to fetch URL.");
1156
- self::$curlFH = fopen($tempfile, 'w');
1157
- if(! self::$curlFH){
1158
- $this->error("Could not open $tempfile for writing.");
1159
- return false;
1160
- }
1161
- self::$curlDataWritten = 0;
1162
- $this->debug(3, "Fetching url with curl: $url");
1163
- $curl = curl_init($url);
1164
- curl_setopt ($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
1165
- curl_setopt ($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 Safari/534.30");
1166
- curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
1167
- curl_setopt ($curl, CURLOPT_HEADER, 0);
1168
- curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
1169
- curl_setopt ($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');
1170
- @curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
1171
- @curl_setopt ($curl, CURLOPT_MAXREDIRS, 10);
1172
-
1173
- $curlResult = curl_exec($curl);
1174
- fclose(self::$curlFH);
1175
- $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
1176
- if($httpStatus == 404){
1177
- $this->set404();
1178
- }
1179
- if($httpStatus == 302){
1180
- $this->error("External Image is Redirecting. Try alternate image url");
1181
- return false;
1182
- }
1183
- if($curlResult){
1184
- curl_close($curl);
1185
- return true;
1186
- } else {
1187
- $this->lastURLError = curl_error($curl);
1188
- curl_close($curl);
1189
- return false;
1190
- }
1191
- } else {
1192
- $img = @file_get_contents ($url);
1193
- if($img === false){
1194
- $err = error_get_last();
1195
- if(is_array($err) && $err['message']){
1196
- $this->lastURLError = $err['message'];
1197
- } else {
1198
- $this->lastURLError = $err;
1199
- }
1200
- if(preg_match('/404/', $this->lastURLError)){
1201
- $this->set404();
1202
- }
1203
-
1204
- return false;
1205
- }
1206
- if(! file_put_contents($tempfile, $img)){
1207
- $this->error("Could not write to $tempfile.");
1208
- return false;
1209
- }
1210
- return true;
1211
- }
1212
-
1213
- }
1214
- protected function serveImg($file){
1215
- $s = getimagesize($file);
1216
- if(! ($s && $s['mime'])){
1217
- return false;
1218
- }
1219
- header ('Content-Type: ' . $s['mime']);
1220
- header ('Content-Length: ' . filesize($file) );
1221
- header ('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
1222
- header ("Pragma: no-cache");
1223
- $bytes = @readfile($file);
1224
- if($bytes > 0){
1225
- return true;
1226
- }
1227
- $content = @file_get_contents ($file);
1228
- if ($content != FALSE){
1229
- echo $content;
1230
- return true;
1231
- }
1232
- return false;
1233
-
1234
- }
1235
- protected function set404(){
1236
- $this->is404 = true;
1237
- }
1238
- protected function is404(){
1239
- return $this->is404;
1240
- }
1241
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ultimate-posts-widget.php CHANGED
@@ -3,14 +3,19 @@
3
  Plugin Name: Ultimate Posts Widget
4
  Plugin URI: http://wordpress.org/plugins/ultimate-posts-widget/
5
  Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
6
- Version: 1.8.1
7
  Author: Boston Dell-Vandenberg
8
  Author URI: http://pomelodesign.com
9
- License: GPL2
 
 
10
 
11
- This program is free software; you can redistribute it and/or modify
 
 
 
12
  it under the terms of the GNU General Public License as published by
13
- the Free Software Foundation; either version 2 of the License, or
14
  (at your option) any later version.
15
 
16
  This program is distributed in the hope that it will be useful,
@@ -19,8 +24,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
  GNU General Public License for more details.
20
 
21
  You should have received a copy of the GNU General Public License
22
- along with this program; if not, write to the Free Software
23
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
  */
25
 
26
  if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
@@ -34,7 +38,9 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
34
  'description' => __( 'Displays list of posts with an array of options', 'upw' )
35
  );
36
 
37
- $control_options = array();
 
 
38
 
39
  $this->WP_Widget(
40
  'sticky-posts',
@@ -45,32 +51,37 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
45
 
46
  $this->alt_option_name = 'widget_ultimate_posts';
47
 
48
- add_action( 'save_post', array( &$this, 'flush_widget_cache' ) );
49
- add_action( 'deleted_post', array( &$this, 'flush_widget_cache' ) );
50
- add_action( 'switch_theme', array( &$this, 'flush_widget_cache' ) );
 
 
 
 
 
51
 
52
  load_plugin_textdomain('upw', false, basename( dirname( __FILE__ ) ) . '/languages' );
53
 
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  function widget( $args, $instance ) {
57
 
58
  global $post;
59
  $current_post_id = $post->ID;
60
 
61
- if( !function_exists('get_image_path') ) {
62
- function get_image_path($src) {
63
- global $blog_id;
64
- if(isset($blog_id) && $blog_id > 0) {
65
- $imageParts = explode('/files/' , $src);
66
- if(isset($imageParts[1])) {
67
- $src = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
68
- }
69
- }
70
- return $src;
71
- }
72
- }
73
-
74
  $cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
75
 
76
  if ( !is_array( $cache ) )
@@ -84,20 +95,22 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
84
  ob_start();
85
  extract( $args );
86
 
87
- $title = apply_filters( 'widget_title', $instance['title'] );
88
  $title_link = $instance['title_link'];
 
89
  $number = $instance['number'];
90
  $types = ($instance['types'] ? explode(',', $instance['types']) : '');
91
  $cats = ($instance['cats'] ? explode(',', $instance['cats']) : '');
 
92
  $atcat = $instance['atcat'] ? true : false;
93
- $thumb_w = $instance['thumb_w'];
94
- $thumb_h = $instance['thumb_h'];
95
- $thumb_crop = $instance['thumb_crop'];
96
  $excerpt_length = $instance['excerpt_length'];
97
  $excerpt_readmore = $instance['excerpt_readmore'];
98
  $sticky = $instance['sticky'];
99
  $order = $instance['order'];
100
  $orderby = $instance['orderby'];
 
101
  $custom_fields = $instance['custom_fields'];
102
 
103
  // Sticky posts
@@ -118,19 +131,36 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
118
  if ($atcat && is_single()) {
119
  $cats = '';
120
  foreach (get_the_category() as $catt) {
121
- $cats .= $catt->cat_ID.' ';
122
  }
123
  $cats = str_replace(" ", ",", trim($cats));
124
  }
125
 
126
- //Excerpt more filter
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  $new_excerpt_more = create_function('$more', 'return "...";');
128
  add_filter('excerpt_more', $new_excerpt_more);
129
 
130
  // Excerpt length filter
131
  $new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
132
  if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);
133
-
 
 
 
134
  echo $before_widget;
135
  if ( $title ) {
136
  echo $before_title;
@@ -145,140 +175,37 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
145
  'order' => $order,
146
  'orderby' => $orderby,
147
  'category__in' => $cats,
 
148
  'post_type' => $types
149
  );
150
 
 
 
 
 
151
  if (!empty($sticky_query)) {
152
  $args[key($sticky_query)] = reset($sticky_query);
153
  }
154
 
155
- $r = new WP_Query( $args );
156
-
157
- if ( $r->have_posts() ) :
158
-
159
- echo '<ul>';
160
-
161
- while ( $r->have_posts() ) : $r->the_post();
162
 
163
- ?>
164
 
165
- <li class="<?php echo ($post->ID == $current_post_id && is_single())?'current-post-item':'' ?>">
 
 
 
 
 
 
 
 
 
 
 
166
 
167
- <?php
168
- if ( function_exists('the_post_thumbnail') &&
169
- current_theme_supports("post-thumbnails") &&
170
- $instance["show_thumbnail"] &&
171
- has_post_thumbnail() ) :
172
- $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID),'large');
173
- $thumbnail_alt = get_post_meta(get_post_thumbnail_id($post->ID), '_wp_attachment_image_alt', true);
174
- $plugin_dir = 'ultimate-posts-widget';
175
- ?>
176
-
177
- <div class="upw-image">
178
- <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(array('before'=>'Permalink to: ')); ?>">
179
- <img src="<?php echo WP_PLUGIN_URL . '/ultimate-posts-widget/thumb.php?src='. get_image_path($thumbnail[0]) .'&amp;h='.$thumb_h.'&amp;w='.$thumb_w.'&amp;zc='.$thumb_crop; ?>" alt="<?php echo $thumbnail_alt; ?>" />
180
- </a>
181
- </div>
182
-
183
- <?php endif; ?>
184
-
185
- <div class="upw-content">
186
-
187
- <?php if ( get_the_title() && $instance['show_title'] ) : ?>
188
- <p class="post-title">
189
- <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(array('before'=>'Permalink to: ')); ?>">
190
- <?php the_title(); ?>
191
- </a>
192
- </p>
193
- <?php endif; ?>
194
-
195
- <?php if ( $instance['show_date'] || $instance['show_time'] ) : ?>
196
- <p class="post-date">
197
- <?php
198
- if ( $instance['show_date'] && $instance['show_time'] ) {
199
- the_time(get_option('date_format') . ' ' . get_option('time_format'));
200
- } elseif ( $instance['show_date'] && !$instance['show_time'] ) {
201
- the_time(get_option('date_format'));
202
- } else {
203
- the_time(get_option('time_format'));
204
- }
205
- ?>
206
- </p>
207
- <?php endif; ?>
208
-
209
- <?php if( $instance['show_author'] ) : ?>
210
- <p class="post-author">
211
- <span class="post-author-label"><?php _e('By', 'upw'); ?>:</span>
212
- <?php the_author_posts_link(); ?>
213
- </p>
214
- <?php endif; ?>
215
-
216
- <?php if ( $instance['show_excerpt'] ) :
217
- if ( $instance['show_readmore'] ) : $linkmore = ' <a href="'.get_permalink().'" class="more-link" title="'.the_title_attribute(array('before'=>'Permalink to: ', 'echo'=>false)).'">'.$excerpt_readmore.'</a>'; else: $linkmore =''; endif; ?>
218
- <p class="post-excerpt"><?php echo get_the_excerpt() . $linkmore; ?></p>
219
- <?php endif; ?>
220
-
221
- <?php if ( $instance['show_content'] ) : ?>
222
- <p class="post-content"><?php the_content() ?></p>
223
- <?php endif; ?>
224
-
225
- <?php if ( $instance['show_cats'] ) : ?>
226
- <p class="post-cats">
227
- <span class="post-cats-label"><?php _e('Categories', 'upw'); ?>:</span>
228
- <span class="post-cats-list"><?php the_category(', '); ?></span>
229
- </p>
230
- <?php endif; ?>
231
-
232
- <?php if ( $instance['show_tags'] ) : ?>
233
- <p class="post-tags">
234
- <span class="post-tags-label"><?php _e('Tags', 'upw'); ?>:</span>
235
- <?php the_tags('<span class="post-tags-list">', ', ', '</span>'); ?>
236
- </p>
237
- <?php endif; ?>
238
-
239
- <?php if ( $custom_fields ) {
240
- $custom_field_name = explode(',', $custom_fields);
241
- foreach ($custom_field_name as $name) {
242
- $name = trim($name);
243
- $custom_field_values = get_post_meta($post->ID, $name, true);
244
- if ($custom_field_values) {
245
- echo '<p class="post-meta post-meta-'.$name.'">';
246
- if (!is_array($custom_field_values)) {
247
- echo $custom_field_values;
248
- } else {
249
- $last_value = end($custom_field_values);
250
- foreach ($custom_field_values as $value) {
251
- echo $value;
252
- if ($value != $last_value) echo ', ';
253
- }
254
- }
255
- echo '</p>';
256
- }
257
- }
258
- } ?>
259
-
260
- </div>
261
-
262
- </li>
263
-
264
- <?php
265
- endwhile;
266
- echo '</ul>';
267
-
268
- if ( $instance['show_morebutton'] ) : ?>
269
- <div class="upw-more">
270
- <a href="<?php echo $instance['morebutton_url']; ?>" class="button"><?php echo $instance['morebutton_text']; ?></a>
271
- </div>
272
- <?php endif;
273
-
274
- // Reset the global $the_post as this query will have stomped on it
275
- wp_reset_postdata();
276
-
277
- else :
278
-
279
- echo __('No posts found.', 'upw');
280
-
281
- endif;
282
 
283
  echo $after_widget;
284
 
@@ -292,33 +219,43 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
292
  $instance = $old_instance;
293
 
294
  $instance['title'] = strip_tags( $new_instance['title'] );
 
295
  $instance['title_link'] = strip_tags( $new_instance['title_link'] );
296
  $instance['number'] = strip_tags( $new_instance['number'] );
297
  $instance['types'] = (isset( $new_instance['types'] )) ? implode(',', (array) $new_instance['types']) : '';
298
  $instance['cats'] = (isset( $new_instance['cats'] )) ? implode(',', (array) $new_instance['cats']) : '';
 
299
  $instance['atcat'] = isset( $new_instance['atcat'] );
 
300
  $instance['show_excerpt'] = isset( $new_instance['show_excerpt'] );
301
  $instance['show_content'] = isset( $new_instance['show_content'] );
302
  $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] );
303
  $instance['show_date'] = isset( $new_instance['show_date'] );
304
- $instance['show_time'] = isset( $new_instance['show_time'] );
305
  $instance['show_title'] = isset( $new_instance['show_title'] );
306
  $instance['show_author'] = isset( $new_instance['show_author'] );
307
- $instance['thumb_w'] = strip_tags( $new_instance['thumb_w'] );
308
- $instance['thumb_h'] = strip_tags( $new_instance['thumb_h'] );
309
- $instance['thumb_crop'] = $new_instance['thumb_crop'];
310
  $instance['show_readmore'] = isset( $new_instance['show_readmore']);
311
  $instance['excerpt_length'] = strip_tags( $new_instance['excerpt_length'] );
312
  $instance['excerpt_readmore'] = strip_tags( $new_instance['excerpt_readmore'] );
313
  $instance['sticky'] = $new_instance['sticky'];
314
  $instance['order'] = $new_instance['order'];
315
  $instance['orderby'] = $new_instance['orderby'];
316
- $instance['show_morebutton'] = isset( $new_instance['show_morebutton'] );
317
- $instance['morebutton_url'] = strip_tags( $new_instance['morebutton_url'] );
318
- $instance['morebutton_text'] = strip_tags( $new_instance['morebutton_text'] );
319
  $instance['show_cats'] = isset( $new_instance['show_cats'] );
320
  $instance['show_tags'] = isset( $new_instance['show_tags'] );
321
  $instance['custom_fields'] = strip_tags( $new_instance['custom_fields'] );
 
 
 
 
 
 
 
 
 
 
322
 
323
  $this->flush_widget_cache();
324
 
@@ -341,284 +278,352 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
341
  // Set default arguments
342
  $instance = wp_parse_args( (array) $instance, array(
343
  'title' => '',
 
344
  'title_link' => '' ,
345
  'number' => '5',
346
  'types' => 'post',
347
  'cats' => '',
 
348
  'atcat' => false,
349
- 'thumb_w' => 100,
350
- 'thumb_h' => 100,
351
- 'thumb_crop' => 1,
352
  'excerpt_length' => 10,
353
  'excerpt_readmore' => __('Read more &rarr;', 'upw'),
354
  'order' => 'DESC',
355
  'orderby' => 'date',
356
- 'morebutton_text' => __('View More Posts', 'upw'),
357
- 'morebutton_url' => site_url(),
358
  'sticky' => 'show',
359
  'show_cats' => false,
360
  'show_tags' => false,
361
- 'show_title' => false,
362
- 'show_date' => false,
363
- 'show_time' => false,
364
- 'show_author' => false,
365
- 'show_excerpt' => false,
 
366
  'show_content' => false,
367
- 'show_readmore' => false,
368
- 'show_thumbnail' => false,
369
  'custom_fields' => '',
370
- 'show_morebutton' => false
 
 
 
 
371
  ) );
372
 
373
  // Or use the instance
374
  $title = strip_tags($instance['title']);
 
375
  $title_link = strip_tags($instance['title_link']);
376
  $number = strip_tags($instance['number']);
377
  $types = $instance['types'];
378
  $cats = $instance['cats'];
 
379
  $atcat = $instance['atcat'];
380
- $thumb_w = strip_tags($instance['thumb_w']);
381
- $thumb_h = strip_tags($instance['thumb_h']);
382
- $thumb_crop = strip_tags($instance['thumb_crop']);
383
  $excerpt_length = strip_tags($instance['excerpt_length']);
384
  $excerpt_readmore = strip_tags($instance['excerpt_readmore']);
385
  $order = $instance['order'];
386
  $orderby = $instance['orderby'];
387
- $morebutton_text = strip_tags($instance['morebutton_text']);
388
- $morebutton_url = strip_tags($instance['morebutton_url']);
389
  $sticky = $instance['sticky'];
390
  $show_cats = $instance['show_cats'];
391
  $show_tags = $instance['show_tags'];
392
  $show_title = $instance['show_title'];
393
  $show_date = $instance['show_date'];
394
- $show_time = $instance['show_time'];
395
  $show_author = $instance['show_author'];
 
396
  $show_excerpt = $instance['show_excerpt'];
397
  $show_content = $instance['show_content'];
398
  $show_readmore = $instance['show_readmore'];
399
  $show_thumbnail = $instance['show_thumbnail'];
400
- $show_morebutton = $instance['show_morebutton'];
401
  $custom_fields = strip_tags($instance['custom_fields']);
 
 
 
 
402
 
403
- //Let's turn $types and $cats into an array
404
  $types = explode(',', $types);
405
  $cats = explode(',', $cats);
 
406
 
407
- //Count number of post types for select box sizing
408
  $cpt_types = get_post_types( array( 'public' => true ), 'names' );
409
- foreach ($cpt_types as $cpt ) {
410
- $cpt_ar[] = $cpt;
 
 
 
 
 
 
411
  }
412
- $n = count($cpt_ar);
413
- if($n > 10) { $n = 10; }
414
 
415
- //Count number of categories for select box sizing
416
  $cat_list = get_categories( 'hide_empty=0' );
417
- foreach ($cat_list as $cat ) {
418
- $cat_ar[] = $cat;
 
 
 
 
 
 
419
  }
420
- $c = count($cat_ar);
421
- if($c > 10) { $c = 10; }
422
-
423
- ?>
424
 
425
- <style>
426
- .upw-divider {
427
- border: 0;
428
- border-top: 1px solid #DFDFDF;
 
429
  }
430
- </style>
 
 
 
 
431
 
432
- <p>
433
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'upw' ); ?>:</label>
434
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
435
- </p>
436
 
437
- <p>
438
- <label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Title URL', 'upw' ); ?>:</label>
439
- <input class="widefat" id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" type="text" value="<?php echo $title_link; ?>" />
440
- </p>
 
 
441
 
442
- <p>
443
- <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts', 'upw' ); ?>:</label>
444
- <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="2" />
445
- </p>
446
 
447
- <p>
448
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_morebutton'); ?>" name="<?php echo $this->get_field_name('show_morebutton'); ?>" <?php checked( (bool) $show_morebutton, true ); ?> />
449
- <label for="<?php echo $this->get_field_id('show_morebutton'); ?>"> <?php _e('Show more button', 'upw'); ?></label>
450
- </p>
451
 
452
- <p>
453
- <label for="<?php echo $this->get_field_id('morebutton_text'); ?>"><?php _e( 'More button text', 'upw' ); ?>:</label>
454
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_text'); ?>" name="<?php echo $this->get_field_name('morebutton_text'); ?>" value="<?php echo $morebutton_text; ?>" />
455
- </p>
456
 
457
- <p>
458
- <label for="<?php echo $this->get_field_id('morebutton_url'); ?>"><?php _e( 'More button URL', 'upw' ); ?>:</label>
459
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('morebutton_url'); ?>" name="<?php echo $this->get_field_name('morebutton_url'); ?>" value="<?php echo $morebutton_url; ?>" />
460
- </p>
461
 
462
- <hr class="upw-divider">
 
 
 
463
 
464
- <h4>Post Display</h4>
 
 
 
465
 
466
- <p>
467
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" type="checkbox" <?php checked( (bool) $show_title, true ); ?> />
468
- <label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Show title', 'upw' ); ?></label>
469
- </p>
470
 
471
- <p>
472
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" type="checkbox" <?php checked( (bool) $show_date, true ); ?> />
473
- <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show published date', 'upw' ); ?></label>
474
- </p>
475
 
476
- <p>
477
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_time' ); ?>" name="<?php echo $this->get_field_name( 'show_time' ); ?>" type="checkbox" <?php checked( (bool) $show_time, true ); ?> />
478
- <label for="<?php echo $this->get_field_id( 'show_time' ); ?>"><?php _e( 'Show published time', 'upw' ); ?></label>
479
- </p>
 
 
 
 
480
 
481
- <p>
482
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_author' ); ?>" name="<?php echo $this->get_field_name( 'show_author' ); ?>" type="checkbox" <?php checked( (bool) $show_author, true ); ?> />
483
- <label for="<?php echo $this->get_field_id( 'show_author' ); ?>"><?php _e( 'Show post author', 'upw' ); ?></label>
484
- </p>
485
 
486
- <p>
487
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_excerpt' ); ?>" name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" type="checkbox" <?php checked( (bool) $show_excerpt, true ); ?> />
488
- <label for="<?php echo $this->get_field_id( 'show_excerpt' ); ?>"><?php _e( 'Show excerpt', 'upw' ); ?></label>
489
- </p>
490
 
491
- <p>
492
- <label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e( 'Excerpt length (in words)', 'upw' ); ?>:</label>
493
- <input style="text-align: center;" type="text" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" size="3" />
494
- </p>
495
 
496
- <p>
497
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_content' ); ?>" name="<?php echo $this->get_field_name( 'show_content' ); ?>" type="checkbox" <?php checked( (bool) $show_content, true ); ?> />
498
- <label for="<?php echo $this->get_field_id( 'show_content' ); ?>"><?php _e( 'Show content', 'upw' ); ?></label>
499
- </p>
500
 
501
- <p>
502
- <label for="<?php echo $this->get_field_id('show_readmore'); ?>">
503
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_readmore'); ?>" name="<?php echo $this->get_field_name('show_readmore'); ?>"<?php checked( (bool) $show_readmore, true ); ?> />
504
- <?php _e( 'Show read more link', 'upw' ); ?>
505
- </label>
506
- </p>
507
 
508
- <p>
509
- <label for="<?php echo $this->get_field_id('excerpt_readmore'); ?>"><?php _e( 'Read more text', 'upw' ); ?>:</label>
510
- <input class="widefat" type="text" id="<?php echo $this->get_field_id('excerpt_readmore'); ?>" name="<?php echo $this->get_field_name('excerpt_readmore'); ?>" value="<?php echo $excerpt_readmore; ?>" />
511
- </p>
512
 
513
- <?php if ( function_exists('the_post_thumbnail') && current_theme_supports( 'post-thumbnails' ) ) : ?>
 
 
 
514
 
515
  <p>
516
- <input class="checkbox" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" type="checkbox" <?php checked( (bool) $show_thumbnail, true ); ?> />
517
- <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show thumbnail', 'upw' ); ?></label>
 
 
 
 
 
518
  </p>
519
 
520
  <p>
521
- <label><?php _e('Thumbnail size', 'upw'); ?>:</label>
522
- <br />
523
- <label for="<?php echo $this->get_field_id('thumb_w'); ?>">
524
- <?php _e('W', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_w'); ?>" name="<?php echo $this->get_field_name('thumb_w'); ?>" value="<?php echo $thumb_w; ?>" />
525
- </label>
526
- <label for="<?php echo $this->get_field_id('thumb_h'); ?>">
527
- <?php _e('H', 'upw'); ?>: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id('thumb_h'); ?>" name="<?php echo $this->get_field_name('thumb_h'); ?>" value="<?php echo $thumb_h; ?>" />
 
528
  </label>
529
  </p>
530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  <p>
532
- <label><?php _e('Crop mode', 'upw'); ?>:</label>
533
- <br />
534
- <select id="<?php echo $this->get_field_id('thumb_crop'); ?>" name="<?php echo $this->get_field_name('thumb_crop'); ?>">
535
- <option value="1"<?php if($thumb_crop == 1) echo ' selected'; ?>><?php _e('Scale &amp; Crop to Fit', 'upw'); ?></option>
536
- <option value="0"<?php if($thumb_crop == 0) echo ' selected'; ?>><?php _e('Stretch to Fit', 'upw'); ?></option>
537
- <option value="2"<?php if($thumb_crop == 2) echo ' selected'; ?>><?php _e('Proportional Scale', 'upw'); ?></option>
538
- <option value="3"<?php if($thumb_crop == 3) echo ' selected'; ?>><?php _e('Proportional Scale No Borders', 'upw'); ?></option>
539
- </select>
540
  </p>
541
 
542
- <?php endif; ?>
 
 
 
543
 
544
- <p>
545
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_cats'); ?>" name="<?php echo $this->get_field_name('show_cats'); ?>" <?php checked( (bool) $show_cats, true ); ?> />
546
- <label for="<?php echo $this->get_field_id('show_cats'); ?>"> <?php _e('Show post categories', 'upw'); ?></label>
547
- </p>
548
 
549
- <p>
550
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_tags'); ?>" name="<?php echo $this->get_field_name('show_tags'); ?>" <?php checked( (bool) $show_tags, true ); ?> />
551
- <label for="<?php echo $this->get_field_id('show_tags'); ?>"> <?php _e('Show post tags', 'upw'); ?></label>
552
- </p>
553
 
554
- <p>
555
- <label for="<?php echo $this->get_field_id( 'custom_fields' ); ?>"><?php _e( 'Show Custom Fields (comma separated)', 'upw' ); ?>:</label>
556
- <input class="widefat" id="<?php echo $this->get_field_id( 'custom_fields' ); ?>" name="<?php echo $this->get_field_name( 'custom_fields' ); ?>" type="text" value="<?php echo $custom_fields; ?>" />
557
- </p>
558
 
559
- <hr class="upw-divider">
 
 
 
560
 
561
- <h4>Filters</h4>
 
 
 
 
 
 
 
 
 
562
 
563
- <p>
564
- <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atcat'); ?>" name="<?php echo $this->get_field_name('atcat'); ?>" <?php checked( (bool) $atcat, true ); ?> />
565
- <label for="<?php echo $this->get_field_id('atcat'); ?>"> <?php _e('Show posts only from current category', 'upw');?></label>
566
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
567
 
568
- <p>
569
- <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e( 'Categories', 'upw' ); ?>:</label>
570
- <select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
571
- <?php
572
- $categories = get_categories( 'hide_empty=0' );
573
- foreach ($categories as $category ) { ?>
574
- <option value="<?php echo $category->term_id; ?>" <?php if( in_array($category->term_id, $cats)) { echo 'selected="selected"'; } ?>><?php echo $category->cat_name;?></option>
575
- <?php } ?>
576
- </select>
577
- </p>
 
578
 
579
- <p>
580
- <label for="<?php echo $this->get_field_id('types'); ?>"><?php _e( 'Post types', 'upw' ); ?>:</label>
581
- <select name="<?php echo $this->get_field_name('types'); ?>[]" id="<?php echo $this->get_field_id('types'); ?>" class="widefat" style="height: auto;" size="<?php echo $n ?>" multiple>
582
- <?php
583
- $args = array( 'public' => true );
584
- $post_types = get_post_types( $args, 'names' );
585
- foreach ($post_types as $post_type ) { ?>
586
- <option value="<?php echo $post_type; ?>" <?php if( in_array($post_type, $types)) { echo 'selected="selected"'; } ?>><?php echo $post_type;?></option>
587
- <?php } ?>
588
- </select>
589
- </p>
590
 
591
- <p>
592
- <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e( 'Sticky posts', 'upw' ); ?>:</label>
593
- <select name="<?php echo $this->get_field_name('sticky'); ?>" id="<?php echo $this->get_field_id('sticky'); ?>" class="widefat">
594
- <option value="show"<?php if( $sticky === 'show') echo ' selected'; ?>><?php _e('Show All Posts', 'upw'); ?></option>
595
- <option value="hide"<?php if( $sticky == 'hide') echo ' selected'; ?>><?php _e('Hide Sticky Posts', 'upw'); ?></option>
596
- <option value="only"<?php if( $sticky == 'only') echo ' selected'; ?>><?php _e('Show Only Sticky Posts', 'upw'); ?></option>
597
- </select>
598
- </p>
599
 
600
- <hr class="upw-divider">
 
 
 
 
 
 
 
 
 
601
 
602
- <h4>Order</h4>
 
 
 
 
 
 
 
 
 
 
 
603
 
604
- <p>
605
- <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
606
- <option value="date"<?php if( $orderby == 'date') echo ' selected'; ?>><?php _e('Published Date', 'upw'); ?></option>
607
- <option value="title"<?php if( $orderby == 'title') echo ' selected'; ?>><?php _e('Title', 'upw'); ?></option>
608
- <option value="comment_count"<?php if( $orderby == 'comment_count') echo ' selected'; ?>><?php _e('Comment Count', 'upw'); ?></option>
609
- <option value="rand"<?php if( $orderby == 'rand') echo ' selected'; ?>><?php _e('Random'); ?></option>
610
- </select>
611
- </p>
612
 
613
- <p>
614
- <select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
615
- <option value="DESC"<?php if( $order == 'DESC') echo ' selected'; ?>><?php _e('Descending', 'upw'); ?></option>
616
- <option value="ASC"<?php if( $order == 'ASC') echo ' selected'; ?>><?php _e('Ascending', 'upw'); ?></option>
617
- </select>
618
  </p>
619
 
620
- <p class="credits"><small><?php _e('Developed by', 'upw'); ?> <a href="http://pomelodesign.com">Pomelo Design</a></small></p>
621
-
622
  <?php if ( $instance ) { ?>
623
 
624
  <script>
@@ -626,82 +631,84 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
626
  jQuery(document).ready(function($){
627
 
628
  var show_excerpt = $("#<?php echo $this->get_field_id( 'show_excerpt' ); ?>");
 
629
  var show_readmore = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>");
 
630
  var show_thumbnail = $("#<?php echo $this->get_field_id( 'show_thumbnail' ); ?>");
 
 
631
  var excerpt_length = $("#<?php echo $this->get_field_id( 'excerpt_length' ); ?>").parents('p');
632
- var excerpt_readmore = $("#<?php echo $this->get_field_id( 'excerpt_readmore' ); ?>").parents('p');
633
- var thumb_w = $("#<?php echo $this->get_field_id( 'thumb_w' ); ?>").parents('p');
634
- var thumb_crop = $("#<?php echo $this->get_field_id( 'thumb_crop' ); ?>").parents('p');
635
- var show_morebutton = $("#<?php echo $this->get_field_id( 'show_morebutton' ); ?>");
636
- var morebutton_text = $("#<?php echo $this->get_field_id( 'morebutton_text' ); ?>").parents('p');
637
- var morebutton_url = $("#<?php echo $this->get_field_id( 'morebutton_url' ); ?>").parents('p');
638
-
639
- <?php
640
- // Use PHP to determine if not checked and hide if so
641
- // jQuery method was acting up
642
- if ( !$show_excerpt ) {
643
- echo 'excerpt_length.hide();';
644
- }
645
- if ( !$show_readmore ) {
646
- echo 'excerpt_readmore.hide();';
647
- }
648
- if ( !$show_thumbnail ) {
649
- echo 'thumb_w.hide();';
650
- echo 'thumb_crop.hide();';
651
- }
652
- if ( !$show_morebutton ) {
653
- echo 'morebutton_text.hide();';
654
- echo 'morebutton_url.hide();';
655
  }
656
- ?>
657
 
658
- // Toggle excerpt length on click
659
- show_excerpt.click(function(){
660
-
661
- if ( $(this).is(":checked") ) {
662
- excerpt_length.show("fast");
663
  } else {
664
- excerpt_length.hide("fast");
665
  }
 
666
 
667
- });
 
 
 
 
 
 
 
 
668
 
669
  // Toggle excerpt length on click
670
- show_readmore.click(function(){
 
 
671
 
672
- if ( $(this).is(":checked") ) {
673
- excerpt_readmore.show("fast");
674
- } else {
675
- excerpt_readmore.hide("fast");
676
- }
677
 
678
- });
 
 
 
679
 
680
  // Toggle excerpt length on click
681
  show_thumbnail.click(function(){
 
 
682
 
683
- if ( $(this).is(":checked") ) {
684
- thumb_w.show("fast");
685
- thumb_crop.show("fast");
 
686
  } else {
687
- thumb_w.hide("fast");
688
- thumb_crop.hide("fast");
689
  }
690
-
691
  });
692
 
693
- // Toggle more button on click
694
- show_morebutton.click(function(){
695
-
696
- if ( $(this).is(":checked") ) {
697
- morebutton_text.show("fast");
698
- morebutton_url.show("fast");
699
  } else {
700
- morebutton_text.hide("fast");
701
- morebutton_url.hide("fast");
702
  }
703
-
704
- });
705
 
706
  });
707
 
@@ -715,12 +722,9 @@ if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
715
 
716
  }
717
 
718
- function init_WP_Widget_Ultimate_Posts() {
719
-
720
  register_widget( 'WP_Widget_Ultimate_Posts' );
721
-
722
  }
723
 
724
- add_action( 'widgets_init', 'init_WP_Widget_Ultimate_Posts' );
725
-
726
  }
3
  Plugin Name: Ultimate Posts Widget
4
  Plugin URI: http://wordpress.org/plugins/ultimate-posts-widget/
5
  Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
6
+ Version: 2.0.0
7
  Author: Boston Dell-Vandenberg
8
  Author URI: http://pomelodesign.com
9
+ Text Domain: upw
10
+ Domain Path: /languages/
11
+ License: GPLv3
12
 
13
+ Ultimate Posts Widget Plugin
14
+ Copyright (C) 2012-2014, Boston Dell-Vandenberg - boston@pomelodesign.com
15
+
16
+ This program is free software: you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
18
+ the Free Software Foundation, either version 3 of the License, or
19
  (at your option) any later version.
20
 
21
  This program is distributed in the hope that it will be useful,
24
  GNU General Public License for more details.
25
 
26
  You should have received a copy of the GNU General Public License
27
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
 
28
  */
29
 
30
  if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
38
  'description' => __( 'Displays list of posts with an array of options', 'upw' )
39
  );
40
 
41
+ $control_options = array(
42
+ 'width' => 450
43
+ );
44
 
45
  $this->WP_Widget(
46
  'sticky-posts',
51
 
52
  $this->alt_option_name = 'widget_ultimate_posts';
53
 
54
+ add_action('save_post', array(&$this, 'flush_widget_cache'));
55
+ add_action('deleted_post', array(&$this, 'flush_widget_cache'));
56
+ add_action('switch_theme', array(&$this, 'flush_widget_cache'));
57
+ add_action('admin_enqueue_scripts', array(&$this, 'enqueue_admin_scripts'));
58
+
59
+ if (apply_filters('upw_enqueue_styles', true) && !is_admin()) {
60
+ add_action('wp_enqueue_scripts', array(&$this, 'enqueue_theme_scripts'));
61
+ }
62
 
63
  load_plugin_textdomain('upw', false, basename( dirname( __FILE__ ) ) . '/languages' );
64
 
65
  }
66
 
67
+ function enqueue_admin_scripts() {
68
+ wp_register_style('upw_admin_styles', plugins_url('css/upw-admin.min.css', __FILE__));
69
+ wp_enqueue_style('upw_admin_styles');
70
+
71
+ wp_register_script('upw_admin_scripts', plugins_url('js/upw-admin.min.js', __FILE__), array('jquery'), null, true);
72
+ wp_enqueue_script('upw_admin_scripts');
73
+ }
74
+
75
+ function enqueue_theme_scripts() {
76
+ wp_register_style('upw_theme_standard', plugins_url('css/upw-theme-standard.min.css', __FILE__));
77
+ wp_enqueue_style('upw_theme_standard');
78
+ }
79
+
80
  function widget( $args, $instance ) {
81
 
82
  global $post;
83
  $current_post_id = $post->ID;
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  $cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
86
 
87
  if ( !is_array( $cache ) )
95
  ob_start();
96
  extract( $args );
97
 
98
+ $title = apply_filters( 'upw_widget_title', $instance['title'] );
99
  $title_link = $instance['title_link'];
100
+ $class = $instance['class'];
101
  $number = $instance['number'];
102
  $types = ($instance['types'] ? explode(',', $instance['types']) : '');
103
  $cats = ($instance['cats'] ? explode(',', $instance['cats']) : '');
104
+ $tags = ($instance['tags'] ? explode(',', $instance['tags']) : '');
105
  $atcat = $instance['atcat'] ? true : false;
106
+ $thumb_size = $instance['thumb_size'];
107
+ $attag = $instance['attag'] ? true : false;
 
108
  $excerpt_length = $instance['excerpt_length'];
109
  $excerpt_readmore = $instance['excerpt_readmore'];
110
  $sticky = $instance['sticky'];
111
  $order = $instance['order'];
112
  $orderby = $instance['orderby'];
113
+ $meta_key = $instance['meta_key'];
114
  $custom_fields = $instance['custom_fields'];
115
 
116
  // Sticky posts
131
  if ($atcat && is_single()) {
132
  $cats = '';
133
  foreach (get_the_category() as $catt) {
134
+ $cats .= $catt->term_id.' ';
135
  }
136
  $cats = str_replace(" ", ",", trim($cats));
137
  }
138
 
139
+ // If $attag true and in tag
140
+ if ($attag && is_tag()) {
141
+ $tags = get_query_var('tag_id');
142
+ }
143
+
144
+ // If $attag true and is single post
145
+ if ($attag && is_single()) {
146
+ $tags = '';
147
+ foreach (get_the_tags() as $tagg) {
148
+ $tags .= $tagg->term_id.' ';
149
+ }
150
+ $tags = str_replace(" ", ",", trim($tags));
151
+ }
152
+
153
+ // Excerpt more filter
154
  $new_excerpt_more = create_function('$more', 'return "...";');
155
  add_filter('excerpt_more', $new_excerpt_more);
156
 
157
  // Excerpt length filter
158
  $new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
159
  if ( $instance["excerpt_length"] > 0 ) add_filter('excerpt_length', $new_excerpt_length);
160
+ if( $class )
161
+ {
162
+ $before_widget = str_replace('class="', 'class="'. $class . ' ', $before_widget);
163
+ }
164
  echo $before_widget;
165
  if ( $title ) {
166
  echo $before_title;
175
  'order' => $order,
176
  'orderby' => $orderby,
177
  'category__in' => $cats,
178
+ 'tag__in' => $tags,
179
  'post_type' => $types
180
  );
181
 
182
+ if ($orderby === 'meta_value') {
183
+ $args['meta_key'] = $meta_key;
184
+ }
185
+
186
  if (!empty($sticky_query)) {
187
  $args[key($sticky_query)] = reset($sticky_query);
188
  }
189
 
190
+ $args = apply_filters('upw_wp_query_args', $args);
 
 
 
 
 
 
191
 
192
+ $upw_query = new WP_Query($args);
193
 
194
+ if ($instance['template'] === 'custom') {
195
+ $custom_template_path = apply_filters('upw_custom_template_path', '/upw/' . $instance['template_custom'] . '.php');
196
+ if (locate_template($custom_template_path)) {
197
+ require_once(get_stylesheet_directory() . $custom_template_path);
198
+ } else {
199
+ require_once('templates/standard.php');
200
+ }
201
+ } elseif ($instance['template']) {
202
+ require_once('templates/' . $instance['template'] . '.php');
203
+ } else {
204
+ require_once('templates/legacy.php');
205
+ }
206
 
207
+ // Reset the global $the_post as this query will have stomped on it
208
+ wp_reset_postdata();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
 
210
  echo $after_widget;
211
 
219
  $instance = $old_instance;
220
 
221
  $instance['title'] = strip_tags( $new_instance['title'] );
222
+ $instance['class'] = strip_tags( $new_instance['class']);
223
  $instance['title_link'] = strip_tags( $new_instance['title_link'] );
224
  $instance['number'] = strip_tags( $new_instance['number'] );
225
  $instance['types'] = (isset( $new_instance['types'] )) ? implode(',', (array) $new_instance['types']) : '';
226
  $instance['cats'] = (isset( $new_instance['cats'] )) ? implode(',', (array) $new_instance['cats']) : '';
227
+ $instance['tags'] = (isset( $new_instance['tags'] )) ? implode(',', (array) $new_instance['tags']) : '';
228
  $instance['atcat'] = isset( $new_instance['atcat'] );
229
+ $instance['attag'] = isset( $new_instance['attag'] );
230
  $instance['show_excerpt'] = isset( $new_instance['show_excerpt'] );
231
  $instance['show_content'] = isset( $new_instance['show_content'] );
232
  $instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] );
233
  $instance['show_date'] = isset( $new_instance['show_date'] );
234
+ $instance['date_format'] = strip_tags( $new_instance['date_format'] );
235
  $instance['show_title'] = isset( $new_instance['show_title'] );
236
  $instance['show_author'] = isset( $new_instance['show_author'] );
237
+ $instance['show_comments'] = isset( $new_instance['show_comments'] );
238
+ $instance['thumb_size'] = strip_tags( $new_instance['thumb_size'] );
 
239
  $instance['show_readmore'] = isset( $new_instance['show_readmore']);
240
  $instance['excerpt_length'] = strip_tags( $new_instance['excerpt_length'] );
241
  $instance['excerpt_readmore'] = strip_tags( $new_instance['excerpt_readmore'] );
242
  $instance['sticky'] = $new_instance['sticky'];
243
  $instance['order'] = $new_instance['order'];
244
  $instance['orderby'] = $new_instance['orderby'];
245
+ $instance['meta_key'] = $new_instance['meta_key'];
 
 
246
  $instance['show_cats'] = isset( $new_instance['show_cats'] );
247
  $instance['show_tags'] = isset( $new_instance['show_tags'] );
248
  $instance['custom_fields'] = strip_tags( $new_instance['custom_fields'] );
249
+ $instance['template'] = strip_tags( $new_instance['template'] );
250
+ $instance['template_custom'] = strip_tags( $new_instance['template_custom'] );
251
+
252
+ if (current_user_can('unfiltered_html')) {
253
+ $instance['before_posts'] = $new_instance['before_posts'];
254
+ $instance['after_posts'] = $new_instance['after_posts'];
255
+ } else {
256
+ $instance['before_posts'] = wp_filter_post_kses($new_instance['before_posts']);
257
+ $instance['after_posts'] = wp_filter_post_kses($new_instance['after_posts']);
258
+ }
259
 
260
  $this->flush_widget_cache();
261
 
278
  // Set default arguments
279
  $instance = wp_parse_args( (array) $instance, array(
280
  'title' => '',
281
+ 'class' => '',
282
  'title_link' => '' ,
283
  'number' => '5',
284
  'types' => 'post',
285
  'cats' => '',
286
+ 'tags' => '',
287
  'atcat' => false,
288
+ 'thumb_size' => 'thumbnail',
289
+ 'attag' => false,
 
290
  'excerpt_length' => 10,
291
  'excerpt_readmore' => __('Read more &rarr;', 'upw'),
292
  'order' => 'DESC',
293
  'orderby' => 'date',
294
+ 'meta_key' => '',
 
295
  'sticky' => 'show',
296
  'show_cats' => false,
297
  'show_tags' => false,
298
+ 'show_title' => true,
299
+ 'show_date' => true,
300
+ 'date_format' => get_option('date_format') . ' ' . get_option('time_format'),
301
+ 'show_author' => true,
302
+ 'show_comments' => false,
303
+ 'show_excerpt' => true,
304
  'show_content' => false,
305
+ 'show_readmore' => true,
306
+ 'show_thumbnail' => true,
307
  'custom_fields' => '',
308
+ // Set template to 'legacy' if field from UPW < 2.0 is set.
309
+ 'template' => empty($instance['morebutton_text']) ? 'standard' : 'legacy',
310
+ 'template_custom' => '',
311
+ 'before_posts' => '',
312
+ 'after_posts' => ''
313
  ) );
314
 
315
  // Or use the instance
316
  $title = strip_tags($instance['title']);
317
+ $class = strip_tags($instance['class']);
318
  $title_link = strip_tags($instance['title_link']);
319
  $number = strip_tags($instance['number']);
320
  $types = $instance['types'];
321
  $cats = $instance['cats'];
322
+ $tags = $instance['tags'];
323
  $atcat = $instance['atcat'];
324
+ $thumb_size = $instance['thumb_size'];
325
+ $attag = $instance['attag'];
 
326
  $excerpt_length = strip_tags($instance['excerpt_length']);
327
  $excerpt_readmore = strip_tags($instance['excerpt_readmore']);
328
  $order = $instance['order'];
329
  $orderby = $instance['orderby'];
330
+ $meta_key = $instance['meta_key'];
 
331
  $sticky = $instance['sticky'];
332
  $show_cats = $instance['show_cats'];
333
  $show_tags = $instance['show_tags'];
334
  $show_title = $instance['show_title'];
335
  $show_date = $instance['show_date'];
336
+ $date_format = $instance['date_format'];
337
  $show_author = $instance['show_author'];
338
+ $show_comments = $instance['show_comments'];
339
  $show_excerpt = $instance['show_excerpt'];
340
  $show_content = $instance['show_content'];
341
  $show_readmore = $instance['show_readmore'];
342
  $show_thumbnail = $instance['show_thumbnail'];
 
343
  $custom_fields = strip_tags($instance['custom_fields']);
344
+ $template = $instance['template'];
345
+ $template_custom = strip_tags($instance['template_custom']);
346
+ $before_posts = format_to_edit($instance['before_posts']);
347
+ $after_posts = format_to_edit($instance['after_posts']);
348
 
349
+ // Let's turn $types, $cats, and $tags into an array
350
  $types = explode(',', $types);
351
  $cats = explode(',', $cats);
352
+ $tags = explode(',', $tags);
353
 
354
+ // Count number of post types for select box sizing
355
  $cpt_types = get_post_types( array( 'public' => true ), 'names' );
356
+ if ($cpt_types) {
357
+ foreach ($cpt_types as $cpt ) {
358
+ $cpt_ar[] = $cpt;
359
+ }
360
+ $n = count($cpt_ar);
361
+ if($n > 6) { $n = 6; }
362
+ } else {
363
+ $n = 3;
364
  }
 
 
365
 
366
+ // Count number of categories for select box sizing
367
  $cat_list = get_categories( 'hide_empty=0' );
368
+ if ($cat_list) {
369
+ foreach ($cat_list as $cat) {
370
+ $cat_ar[] = $cat;
371
+ }
372
+ $c = count($cat_ar);
373
+ if($c > 6) { $c = 6; }
374
+ } else {
375
+ $c = 3;
376
  }
 
 
 
 
377
 
378
+ // Count number of tags for select box sizing
379
+ $tag_list = get_tags( 'hide_empty=0' );
380
+ if ($tag_list) {
381
+ foreach ($tag_list as $tag) {
382
+ $tag_ar[] = $tag;
383
  }
384
+ $t = count($tag_ar);
385
+ if($t > 6) { $t = 6; }
386
+ } else {
387
+ $t = 3;
388
+ }
389
 
390
+ ?>
 
 
 
391
 
392
+ <div class="upw-tabs">
393
+ <a class="upw-tab-item active" data-toggle="upw-tab-general"><?php _e('General', 'upw'); ?></a>
394
+ <a class="upw-tab-item" data-toggle="upw-tab-display"><?php _e('Display', 'upw'); ?></a>
395
+ <a class="upw-tab-item" data-toggle="upw-tab-filter"><?php _e('Filter', 'upw'); ?></a>
396
+ <a class="upw-tab-item" data-toggle="upw-tab-order"><?php _e('Order', 'upw'); ?></a>
397
+ </div>
398
 
399
+ <div class="upw-tab upw-tab-general">
 
 
 
400
 
401
+ <p>
402
+ <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'upw' ); ?>:</label>
403
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
404
+ </p>
405
 
406
+ <p>
407
+ <label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Title URL', 'upw' ); ?>:</label>
408
+ <input class="widefat" id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" type="text" value="<?php echo $title_link; ?>" />
409
+ </p>
410
 
411
+ <p>
412
+ <label for="<?php echo $this->get_field_id( 'class' ); ?>"><?php _e( 'CSS class', 'upw' ); ?>:</label>
413
+ <input class="widefat" id="<?php echo $this->get_field_id( 'class' ); ?>" name="<?php echo $this->get_field_name( 'class' ); ?>" type="text" value="<?php echo $class; ?>" />
414
+ </p>
415
 
416
+ <p>
417
+ <label for="<?php echo $this->get_field_id('before_posts'); ?>"><?php _e('Before posts', 'upw'); ?>:</label>
418
+ <textarea class="widefat" id="<?php echo $this->get_field_id('before_posts'); ?>" name="<?php echo $this->get_field_name('before_posts'); ?>" rows="5"><?php echo $before_posts; ?></textarea>
419
+ </p>
420
 
421
+ <p>
422
+ <label for="<?php echo $this->get_field_id('after_posts'); ?>"><?php _e('After posts', 'upw'); ?>:</label>
423
+ <textarea class="widefat" id="<?php echo $this->get_field_id('after_posts'); ?>" name="<?php echo $this->get_field_name('after_posts'); ?>" rows="5"><?php echo $after_posts; ?></textarea>
424
+ </p>
425
 
426
+ </div>
 
 
 
427
 
428
+ <div class="upw-tab upw-hide upw-tab-display">
 
 
 
429
 
430
+ <p>
431
+ <label for="<?php echo $this->get_field_id('template'); ?>"><?php _e('Template', 'upw'); ?>:</label>
432
+ <select name="<?php echo $this->get_field_name('template'); ?>" id="<?php echo $this->get_field_id('template'); ?>" class="widefat">
433
+ <option value="legacy"<?php if( $template == 'legacy') echo ' selected'; ?>><?php _e('Legacy', 'upw'); ?></option>
434
+ <option value="standard"<?php if( $template == 'standard') echo ' selected'; ?>><?php _e('Standard', 'upw'); ?></option>
435
+ <option value="custom"<?php if( $template == 'custom') echo ' selected'; ?>><?php _e('Custom', 'upw'); ?></option>
436
+ </select>
437
+ </p>
438
 
439
+ <p<?php if ($template !== 'custom') echo ' style="display:none;"'; ?>>
440
+ <label for="<?php echo $this->get_field_id('template_custom'); ?>"><?php _e('Custom Template Name', 'upw'); ?>:</label>
441
+ <input class="widefat" id="<?php echo $this->get_field_id('template_custom'); ?>" name="<?php echo $this->get_field_name('template_custom'); ?>" type="text" value="<?php echo $template_custom; ?>" />
442
+ </p>
443
 
444
+ <p>
445
+ <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts', 'upw' ); ?>:</label>
446
+ <input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" value="<?php echo $number; ?>" min="1" max="20" />
447
+ </p>
448
 
449
+ <p>
450
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" type="checkbox" <?php checked( (bool) $show_title, true ); ?> />
451
+ <label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Show title', 'upw' ); ?></label>
452
+ </p>
453
 
454
+ <p>
455
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" type="checkbox" <?php checked( (bool) $show_date, true ); ?> />
456
+ <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show published date', 'upw' ); ?></label>
457
+ </p>
458
 
459
+ <p<?php if (!$show_date) echo ' style="display:none;"'; ?>>
460
+ <label for="<?php echo $this->get_field_id('date_format'); ?>"><?php _e( 'Date format', 'upw' ); ?>:</label>
461
+ <input class="widefat" type="text" id="<?php echo $this->get_field_id('date_format'); ?>" name="<?php echo $this->get_field_name('date_format'); ?>" value="<?php echo $date_format; ?>" />
462
+ </p>
 
 
463
 
464
+ <p>
465
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_author' ); ?>" name="<?php echo $this->get_field_name( 'show_author' ); ?>" type="checkbox" <?php checked( (bool) $show_author, true ); ?> />
466
+ <label for="<?php echo $this->get_field_id( 'show_author' ); ?>"><?php _e( 'Show post author', 'upw' ); ?></label>
467
+ </p>
468
 
469
+ <p>
470
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_comments' ); ?>" name="<?php echo $this->get_field_name( 'show_comments' ); ?>" type="checkbox" <?php checked( (bool) $show_comments, true ); ?> />
471
+ <label for="<?php echo $this->get_field_id( 'show_comments' ); ?>"><?php _e( 'Show comments count', 'upw' ); ?></label>
472
+ </p>
473
 
474
  <p>
475
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_excerpt' ); ?>" name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" type="checkbox" <?php checked( (bool) $show_excerpt, true ); ?> />
476
+ <label for="<?php echo $this->get_field_id( 'show_excerpt' ); ?>"><?php _e( 'Show excerpt', 'upw' ); ?></label>
477
+ </p>
478
+
479
+ <p<?php if (!$show_excerpt) echo ' style="display:none;"'; ?>>
480
+ <label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e( 'Excerpt length (in words)', 'upw' ); ?>:</label>
481
+ <input class="widefat" type="number" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" min="1" max="100" />
482
  </p>
483
 
484
  <p>
485
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_content' ); ?>" name="<?php echo $this->get_field_name( 'show_content' ); ?>" type="checkbox" <?php checked( (bool) $show_content, true ); ?> />
486
+ <label for="<?php echo $this->get_field_id( 'show_content' ); ?>"><?php _e( 'Show content', 'upw' ); ?></label>
487
+ </p>
488
+
489
+ <p<?php if (!$show_excerpt && !$show_content) echo ' style="display:none;"'; ?>>
490
+ <label for="<?php echo $this->get_field_id('show_readmore'); ?>">
491
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_readmore'); ?>" name="<?php echo $this->get_field_name('show_readmore'); ?>"<?php checked( (bool) $show_readmore, true ); ?> />
492
+ <?php _e( 'Show read more link', 'upw' ); ?>
493
  </label>
494
  </p>
495
 
496
+ <p<?php if (!$show_readmore || (!$show_excerpt && !$show_content)) echo ' style="display:none;"'; ?>>
497
+ <input class="widefat" type="text" id="<?php echo $this->get_field_id('excerpt_readmore'); ?>" name="<?php echo $this->get_field_name('excerpt_readmore'); ?>" value="<?php echo $excerpt_readmore; ?>" />
498
+ </p>
499
+
500
+ <?php if ( function_exists('the_post_thumbnail') && current_theme_supports( 'post-thumbnails' ) ) : ?>
501
+
502
+ <?php $sizes = get_intermediate_image_sizes(); ?>
503
+
504
+ <p>
505
+ <input class="checkbox" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" type="checkbox" <?php checked( (bool) $show_thumbnail, true ); ?> />
506
+
507
+ <label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show thumbnail', 'upw' ); ?></label>
508
+ </p>
509
+
510
+ <p<?php if (!$show_thumbnail) echo ' style="display:none;"'; ?>>
511
+ <select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" class="widefat">
512
+ <?php foreach ($sizes as $size) : ?>
513
+ <option value="<?php echo $size; ?>"<?php if ($thumb_size == $size) echo ' selected'; ?>><?php echo $size; ?></option>
514
+ <?php endforeach; ?>
515
+ </select>
516
+ </p>
517
+
518
+ <?php endif; ?>
519
+
520
  <p>
521
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_cats'); ?>" name="<?php echo $this->get_field_name('show_cats'); ?>" <?php checked( (bool) $show_cats, true ); ?> />
522
+ <label for="<?php echo $this->get_field_id('show_cats'); ?>"> <?php _e('Show post categories', 'upw'); ?></label>
 
 
 
 
 
 
523
  </p>
524
 
525
+ <p>
526
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_tags'); ?>" name="<?php echo $this->get_field_name('show_tags'); ?>" <?php checked( (bool) $show_tags, true ); ?> />
527
+ <label for="<?php echo $this->get_field_id('show_tags'); ?>"> <?php _e('Show post tags', 'upw'); ?></label>
528
+ </p>
529
 
530
+ <p>
531
+ <label for="<?php echo $this->get_field_id( 'custom_fields' ); ?>"><?php _e( 'Show custom fields (comma separated)', 'upw' ); ?>:</label>
532
+ <input class="widefat" id="<?php echo $this->get_field_id( 'custom_fields' ); ?>" name="<?php echo $this->get_field_name( 'custom_fields' ); ?>" type="text" value="<?php echo $custom_fields; ?>" />
533
+ </p>
534
 
535
+ </div>
 
 
 
536
 
537
+ <div class="upw-tab upw-hide upw-tab-filter">
 
 
 
538
 
539
+ <p>
540
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atcat'); ?>" name="<?php echo $this->get_field_name('atcat'); ?>" <?php checked( (bool) $atcat, true ); ?> />
541
+ <label for="<?php echo $this->get_field_id('atcat'); ?>"> <?php _e('Show posts only from current category', 'upw');?></label>
542
+ </p>
543
 
544
+ <p>
545
+ <label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e( 'Categories', 'upw' ); ?>:</label>
546
+ <select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
547
+ <?php
548
+ $categories = get_categories( 'hide_empty=0' );
549
+ foreach ($categories as $category ) { ?>
550
+ <option value="<?php echo $category->term_id; ?>" <?php if( in_array($category->term_id, $cats)) { echo 'selected="selected"'; } ?>><?php echo $category->cat_name;?></option>
551
+ <?php } ?>
552
+ </select>
553
+ </p>
554
 
555
+ <?php if ($tag_list) : ?>
556
+ <p>
557
+ <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('attag'); ?>" name="<?php echo $this->get_field_name('attag'); ?>" <?php checked( (bool) $attag, true ); ?> />
558
+ <label for="<?php echo $this->get_field_id('attag'); ?>"> <?php _e('Show posts only from current tag', 'upw');?></label>
559
+ </p>
560
+
561
+ <p>
562
+ <label for="<?php echo $this->get_field_id('tags'); ?>"><?php _e( 'Tags', 'upw' ); ?>:</label>
563
+ <select name="<?php echo $this->get_field_name('tags'); ?>[]" id="<?php echo $this->get_field_id('tags'); ?>" class="widefat" style="height: auto;" size="<?php echo $t ?>" multiple>
564
+ <?php
565
+ foreach ($tag_list as $tag) { ?>
566
+ <option value="<?php echo $tag->term_id; ?>" <?php if( in_array($tag->term_id, $tags)) { echo 'selected="selected"'; } ?>><?php echo $tag->name;?></option>
567
+ <?php } ?>
568
+ </select>
569
+ </p>
570
+ <?php endif; ?>
571
 
572
+ <p>
573
+ <label for="<?php echo $this->get_field_id('types'); ?>"><?php _e( 'Post types', 'upw' ); ?>:</label>
574
+ <select name="<?php echo $this->get_field_name('types'); ?>[]" id="<?php echo $this->get_field_id('types'); ?>" class="widefat" style="height: auto;" size="<?php echo $n ?>" multiple>
575
+ <?php
576
+ $args = array( 'public' => true );
577
+ $post_types = get_post_types( $args, 'names' );
578
+ foreach ($post_types as $post_type ) { ?>
579
+ <option value="<?php echo $post_type; ?>" <?php if( in_array($post_type, $types)) { echo 'selected="selected"'; } ?>><?php echo $post_type;?></option>
580
+ <?php } ?>
581
+ </select>
582
+ </p>
583
 
584
+ <p>
585
+ <label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e( 'Sticky posts', 'upw' ); ?>:</label>
586
+ <select name="<?php echo $this->get_field_name('sticky'); ?>" id="<?php echo $this->get_field_id('sticky'); ?>" class="widefat">
587
+ <option value="show"<?php if( $sticky === 'show') echo ' selected'; ?>><?php _e('Show All Posts', 'upw'); ?></option>
588
+ <option value="hide"<?php if( $sticky == 'hide') echo ' selected'; ?>><?php _e('Hide Sticky Posts', 'upw'); ?></option>
589
+ <option value="only"<?php if( $sticky == 'only') echo ' selected'; ?>><?php _e('Show Only Sticky Posts', 'upw'); ?></option>
590
+ </select>
591
+ </p>
 
 
 
592
 
593
+ </div>
594
+
595
+ <div class="upw-tab upw-hide upw-tab-order">
 
 
 
 
 
596
 
597
+ <p>
598
+ <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e('Order by', 'upw'); ?>:</label>
599
+ <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
600
+ <option value="date"<?php if( $orderby == 'date') echo ' selected'; ?>><?php _e('Published Date', 'upw'); ?></option>
601
+ <option value="title"<?php if( $orderby == 'title') echo ' selected'; ?>><?php _e('Title', 'upw'); ?></option>
602
+ <option value="comment_count"<?php if( $orderby == 'comment_count') echo ' selected'; ?>><?php _e('Comment Count', 'upw'); ?></option>
603
+ <option value="rand"<?php if( $orderby == 'rand') echo ' selected'; ?>><?php _e('Random'); ?></option>
604
+ <option value="meta_value"<?php if( $orderby == 'meta_value') echo ' selected'; ?>><?php _e('Custom Field', 'upw'); ?></option>
605
+ </select>
606
+ </p>
607
 
608
+ <p<?php if ($orderby !== 'meta_value') echo ' style="display:none;"'; ?>>
609
+ <label for="<?php echo $this->get_field_id( 'meta_key' ); ?>"><?php _e('Custom field', 'upw'); ?>:</label>
610
+ <input class="widefat" id="<?php echo $this->get_field_id('meta_key'); ?>" name="<?php echo $this->get_field_name('meta_key'); ?>" type="text" value="<?php echo $meta_key; ?>" />
611
+ </p>
612
+
613
+ <p>
614
+ <label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Order', 'upw'); ?>:</label>
615
+ <select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
616
+ <option value="DESC"<?php if( $order == 'DESC') echo ' selected'; ?>><?php _e('Descending', 'upw'); ?></option>
617
+ <option value="ASC"<?php if( $order == 'ASC') echo ' selected'; ?>><?php _e('Ascending', 'upw'); ?></option>
618
+ </select>
619
+ </p>
620
 
621
+ </div>
 
 
 
 
 
 
 
622
 
623
+ <p class="upw-credits">
624
+ Enjoy this plugin? Please <a href="http://pomelodesign.com/donate/" target="_blank">donate to support development</a>.
 
 
 
625
  </p>
626
 
 
 
627
  <?php if ( $instance ) { ?>
628
 
629
  <script>
631
  jQuery(document).ready(function($){
632
 
633
  var show_excerpt = $("#<?php echo $this->get_field_id( 'show_excerpt' ); ?>");
634
+ var show_content = $("#<?php echo $this->get_field_id( 'show_content' ); ?>");
635
  var show_readmore = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>");
636
+ var show_readmore_wrap = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>").parents('p');
637
  var show_thumbnail = $("#<?php echo $this->get_field_id( 'show_thumbnail' ); ?>");
638
+ var show_date = $("#<?php echo $this->get_field_id( 'show_date' ); ?>");
639
+ var date_format = $("#<?php echo $this->get_field_id( 'date_format' ); ?>").parents('p');
640
  var excerpt_length = $("#<?php echo $this->get_field_id( 'excerpt_length' ); ?>").parents('p');
641
+ var excerpt_readmore_wrap = $("#<?php echo $this->get_field_id( 'excerpt_readmore' ); ?>").parents('p');
642
+ var thumb_size_wrap = $("#<?php echo $this->get_field_id( 'thumb_size' ); ?>").parents('p');
643
+ var order = $("#<?php echo $this->get_field_id('orderby'); ?>");
644
+ var meta_key_wrap = $("#<?php echo $this->get_field_id( 'meta_key' ); ?>").parents('p');
645
+ var template = $("#<?php echo $this->get_field_id('template'); ?>");
646
+ var template_custom = $("#<?php echo $this->get_field_id('template_custom'); ?>").parents('p');
647
+
648
+ var toggleReadmore = function() {
649
+ if (show_excerpt.is(':checked') || show_content.is(':checked')) {
650
+ show_readmore_wrap.show('fast');
651
+ } else {
652
+ show_readmore_wrap.hide('fast');
653
+ }
654
+ toggleExcerptReadmore();
 
 
 
 
 
 
 
 
 
655
  }
 
656
 
657
+ var toggleExcerptReadmore = function() {
658
+ if ((show_excerpt.is(':checked') || show_content.is(':checked')) && show_readmore.is(':checked')) {
659
+ excerpt_readmore_wrap.show('fast');
 
 
660
  } else {
661
+ excerpt_readmore_wrap.hide('fast');
662
  }
663
+ }
664
 
665
+ // Toggle read more option
666
+ show_excerpt.click(function() {
667
+ toggleReadmore();
668
+ });
669
+
670
+ // Toggle read more option
671
+ show_content.click(function() {
672
+ toggleReadmore();
673
+ });
674
 
675
  // Toggle excerpt length on click
676
+ show_excerpt.click(function(){
677
+ excerpt_length.toggle('fast');
678
+ });
679
 
680
+ // Toggle excerpt length on click
681
+ show_readmore.click(function(){
682
+ toggleExcerptReadmore();
683
+ });
 
684
 
685
+ // Toggle date format on click
686
+ show_date.click(function(){
687
+ date_format.toggle('fast');
688
+ });
689
 
690
  // Toggle excerpt length on click
691
  show_thumbnail.click(function(){
692
+ thumb_size_wrap.toggle('fast');
693
+ });
694
 
695
+ // Show or hide custom field meta_key value on order change
696
+ order.change(function(){
697
+ if ($(this).val() === 'meta_value') {
698
+ meta_key_wrap.show('fast');
699
  } else {
700
+ meta_key_wrap.hide('fast');
 
701
  }
 
702
  });
703
 
704
+ // Show or hide custom template field
705
+ template.change(function(){
706
+ if ($(this).val() === 'custom') {
707
+ template_custom.show('fast');
 
 
708
  } else {
709
+ template_custom.hide('fast');
 
710
  }
711
+ });
 
712
 
713
  });
714
 
722
 
723
  }
724
 
725
+ function init_wp_widget_ultimate_posts() {
 
726
  register_widget( 'WP_Widget_Ultimate_Posts' );
 
727
  }
728
 
729
+ add_action( 'widgets_init', 'init_wp_widget_ultimate_posts' );
 
730
  }