Version Description
- ADD: More flexible settings for information bar per slide
- ADD: Switch from TimThumb to BFI Thumb
- FIX: Change mysql_real_escape_string() to esc_sql()
- REMOVE: Images tester is no longer needed
Download this release
Release Info
Developer | contrid |
Plugin | Slideshow Gallery |
Version | 1.4.2 |
Comparing to | |
See all releases |
Code changes from version 1.4.1 to 1.4.2
- helpers/db.php +2 -2
- helpers/html.php +29 -22
- js/gallery.js +2 -2
- models/slide.php +2 -4
- readme.txt +7 -1
- slideshow-gallery-plugin.php +5 -3
- slideshow-gallery.php +3 -45
- vendors/BFI_Thumb.php +663 -0
- vendors/timthumb.php +0 -1264
- views/admin/metaboxes/settings-general.php +0 -9
- views/admin/metaboxes/settings-styles.php +5 -14
- views/admin/metaboxes/settings-submit.php +0 -4
- views/admin/settings-images.php +4 -5
- views/admin/slides/loop.php +1 -1
- views/admin/slides/order.php +1 -1
- views/admin/slides/save.php +12 -7
- views/default/gallery.php +11 -11
helpers/db.php
CHANGED
@@ -259,7 +259,7 @@ class GalleryDbHelper extends GalleryPlugin {
|
|
259 |
if (is_array($this -> data -> {$field}) || is_object($this -> data -> {$field})) {
|
260 |
$value = serialize($this -> data -> {$field});
|
261 |
} else {
|
262 |
-
$value =
|
263 |
}
|
264 |
|
265 |
$query1 .= "`" . $field . "`";
|
@@ -305,7 +305,7 @@ class GalleryDbHelper extends GalleryPlugin {
|
|
305 |
if (is_array($this -> data -> {$field}) || is_object($this -> data -> {$field})) {
|
306 |
$value = serialize($this -> data -> {$field});
|
307 |
} else {
|
308 |
-
$value =
|
309 |
}
|
310 |
|
311 |
$query .= "`" . $field . "` = '" . $value . "'";
|
259 |
if (is_array($this -> data -> {$field}) || is_object($this -> data -> {$field})) {
|
260 |
$value = serialize($this -> data -> {$field});
|
261 |
} else {
|
262 |
+
$value = esc_sql($this -> data -> {$field});
|
263 |
}
|
264 |
|
265 |
$query1 .= "`" . $field . "`";
|
305 |
if (is_array($this -> data -> {$field}) || is_object($this -> data -> {$field})) {
|
306 |
$value = serialize($this -> data -> {$field});
|
307 |
} else {
|
308 |
+
$value = esc_sql($this -> data -> {$field});
|
309 |
}
|
310 |
|
311 |
$query .= "`" . $field . "` = '" . $value . "'";
|
helpers/html.php
CHANGED
@@ -27,7 +27,7 @@ class GalleryHtmlHelper extends GalleryPlugin {
|
|
27 |
return str_replace("\\", "/", WP_CONTENT_DIR . '/uploads');
|
28 |
}
|
29 |
|
30 |
-
function uploads_url() {
|
31 |
if ($upload_dir = wp_upload_dir()) {
|
32 |
return $upload_dir['baseurl'];
|
33 |
}
|
@@ -94,33 +94,40 @@ class GalleryHtmlHelper extends GalleryPlugin {
|
|
94 |
return false;
|
95 |
}
|
96 |
|
97 |
-
function
|
98 |
-
$
|
99 |
-
|
100 |
-
|
101 |
-
$
|
102 |
-
$
|
103 |
-
$
|
104 |
-
$
|
105 |
-
|
106 |
-
|
107 |
-
$
|
|
|
|
|
108 |
return $tt_image;
|
109 |
}
|
110 |
|
111 |
-
function
|
112 |
-
$
|
113 |
-
|
114 |
-
|
115 |
-
$
|
116 |
-
$
|
117 |
-
$
|
118 |
-
$
|
|
|
|
|
|
|
|
|
|
|
119 |
return $tt_image;
|
120 |
}
|
121 |
|
122 |
-
function
|
123 |
-
return plugins_url() . '/slideshow-gallery/vendors/
|
124 |
}
|
125 |
|
126 |
function image_url($filename = null) {
|
27 |
return str_replace("\\", "/", WP_CONTENT_DIR . '/uploads');
|
28 |
}
|
29 |
|
30 |
+
public static function uploads_url() {
|
31 |
if ($upload_dir = wp_upload_dir()) {
|
32 |
return $upload_dir['baseurl'];
|
33 |
}
|
94 |
return false;
|
95 |
}
|
96 |
|
97 |
+
function bfithumb_image($image = null, $width = null, $height = null, $quality = 100, $class = "slideshow", $rel = "") {
|
98 |
+
require_once($this -> plugin_base() . DS . 'vendors' . DS . 'BFI_Thumb.php');
|
99 |
+
|
100 |
+
$params = array();
|
101 |
+
if (!empty($width)) { $params['width'] = $width; }
|
102 |
+
if (!empty($height)) { $params['height'] = $height; }
|
103 |
+
$resizeimagescrop = $this -> get_option('resizeimagescrop');
|
104 |
+
$crop = (!empty($resizeimagescrop) && $resizeimagescrop == "Y") ? true : false;
|
105 |
+
$params['crop'] = $crop;
|
106 |
+
|
107 |
+
$src = bfi_thumb($image, $params);
|
108 |
+
|
109 |
+
$tt_image = '<img src="' . $src . '" />';
|
110 |
return $tt_image;
|
111 |
}
|
112 |
|
113 |
+
function bfithumb_image_src($image = null, $width = null, $height = null, $quality = 100) {
|
114 |
+
require_once($this -> plugin_base() . DS . 'vendors' . DS . 'BFI_Thumb.php');
|
115 |
+
|
116 |
+
$params = array();
|
117 |
+
if (!empty($width)) { $params['width'] = $width; }
|
118 |
+
if (!empty($height)) { $params['height'] = $height; }
|
119 |
+
$resizeimagescrop = $this -> get_option('resizeimagescrop');
|
120 |
+
$crop = (!empty($resizeimagescrop) && $resizeimagescrop == "Y") ? true : false;
|
121 |
+
$params['crop'] = $crop;
|
122 |
+
|
123 |
+
$src = bfi_thumb($image, $params);
|
124 |
+
|
125 |
+
$tt_image = $src;
|
126 |
return $tt_image;
|
127 |
}
|
128 |
|
129 |
+
function bfithumb_url() {
|
130 |
+
return plugins_url() . '/slideshow-gallery/vendors/bfithumb.php';
|
131 |
}
|
132 |
|
133 |
function image_url($filename = null) {
|
js/gallery.js
CHANGED
@@ -83,7 +83,7 @@ TINY.slideshow.prototype={
|
|
83 |
this.is(t,c)
|
84 |
},
|
85 |
is:function(s,c){
|
86 |
-
if(this.info && this.a[s].t.length > 0){
|
87 |
TINY.height.set(this.r,1,this.infoSpeed/2,-1)
|
88 |
}
|
89 |
var i=new Image();
|
@@ -147,7 +147,7 @@ TINY.slideshow.prototype={
|
|
147 |
var h=parseInt(this.r.offsetHeight);
|
148 |
this.r.style.height=0;
|
149 |
|
150 |
-
if (s.t.length > 0) {
|
151 |
TINY.height.set(this.r,h,this.infoSpeed,0);
|
152 |
TINY.alpha.set(this.r,s.io,5);
|
153 |
}
|
83 |
this.is(t,c)
|
84 |
},
|
85 |
is:function(s,c){
|
86 |
+
if(this.info && (this.a[s].t.length > 0 || this.a[s].d.length > 0)) {
|
87 |
TINY.height.set(this.r,1,this.infoSpeed/2,-1)
|
88 |
}
|
89 |
var i=new Image();
|
147 |
var h=parseInt(this.r.offsetHeight);
|
148 |
this.r.style.height=0;
|
149 |
|
150 |
+
if (s.t.length > 0 || s.d.length > 0) {
|
151 |
TINY.height.set(this.r,h,this.infoSpeed,0);
|
152 |
TINY.alpha.set(this.r,s.io,5);
|
153 |
}
|
models/slide.php
CHANGED
@@ -14,7 +14,7 @@ class GallerySlide extends GalleryDbHelper {
|
|
14 |
'id' => "INT(11) NOT NULL AUTO_INCREMENT",
|
15 |
'title' => "VARCHAR(150) NOT NULL DEFAULT ''",
|
16 |
'description' => "TEXT NOT NULL",
|
17 |
-
'
|
18 |
'iopacity' => "INT(11) NOT NULL DEFAULT '70'",
|
19 |
'image' => "VARCHAR(50) NOT NULL DEFAULT ''",
|
20 |
'type' => "ENUM('file','url') NOT NULL DEFAULT 'file'",
|
@@ -85,13 +85,12 @@ class GallerySlide extends GalleryDbHelper {
|
|
85 |
extract($data, EXTR_SKIP);
|
86 |
|
87 |
if (empty($title)) { $this -> errors['title'] = __('Please fill in a title', $this -> plugin_name); }
|
88 |
-
if (empty($
|
89 |
|
90 |
if (empty($type)) { $this -> errors['type'] = __('Please select an image type', $this -> plugin_name); }
|
91 |
elseif ($type == "file") {
|
92 |
if (!empty($image_oldfile) && empty($_FILES['image_file']['name'])) {
|
93 |
$imagename = $image_oldfile;
|
94 |
-
//$imagepath = ABSPATH . "wp-content" . DS . "uploads" . DS . $this -> plugin_name . DS;
|
95 |
$imagepath = GalleryHtmlHelper::uploads_path() . DS . $this -> plugin_name . DS;
|
96 |
$imagefull = $imagepath . $imagename;
|
97 |
|
@@ -114,7 +113,6 @@ class GallerySlide extends GalleryDbHelper {
|
|
114 |
@chmod($imagefull, 0644);
|
115 |
|
116 |
$this -> data -> image = $imagename;
|
117 |
-
//$this -> data -> image_path = GalleryHtmlHelper::uploads_path() . DS . $this -> plugin_name . DS . $imagename;
|
118 |
$imagespath = $this -> get_option('imagespath');
|
119 |
if (empty($imagespath)) {
|
120 |
$this -> image_path = GalleryHtmlHelper::uploads_path() . DS . 'slideshow-gallery' . DS . $imagename;
|
14 |
'id' => "INT(11) NOT NULL AUTO_INCREMENT",
|
15 |
'title' => "VARCHAR(150) NOT NULL DEFAULT ''",
|
16 |
'description' => "TEXT NOT NULL",
|
17 |
+
'showinfo' => "VARCHAR(50) NOT NULL DEFAULT 'both'",
|
18 |
'iopacity' => "INT(11) NOT NULL DEFAULT '70'",
|
19 |
'image' => "VARCHAR(50) NOT NULL DEFAULT ''",
|
20 |
'type' => "ENUM('file','url') NOT NULL DEFAULT 'file'",
|
85 |
extract($data, EXTR_SKIP);
|
86 |
|
87 |
if (empty($title)) { $this -> errors['title'] = __('Please fill in a title', $this -> plugin_name); }
|
88 |
+
if (empty($showinfo)) { $this -> data -> showinfo = "both"; }
|
89 |
|
90 |
if (empty($type)) { $this -> errors['type'] = __('Please select an image type', $this -> plugin_name); }
|
91 |
elseif ($type == "file") {
|
92 |
if (!empty($image_oldfile) && empty($_FILES['image_file']['name'])) {
|
93 |
$imagename = $image_oldfile;
|
|
|
94 |
$imagepath = GalleryHtmlHelper::uploads_path() . DS . $this -> plugin_name . DS;
|
95 |
$imagefull = $imagepath . $imagename;
|
96 |
|
113 |
@chmod($imagefull, 0644);
|
114 |
|
115 |
$this -> data -> image = $imagename;
|
|
|
116 |
$imagespath = $this -> get_option('imagespath');
|
117 |
if (empty($imagespath)) {
|
118 |
$this -> image_path = GalleryHtmlHelper::uploads_path() . DS . 'slideshow-gallery' . DS . $imagename;
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://tribulant.com/
|
|
4 |
Tags: wordpress plugins, wordpress slideshow gallery, slides, slideshow, image gallery, images, gallery, featured content, content gallery, javascript, javascript slideshow, slideshow gallery
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.9
|
7 |
-
Stable tag: 1.4.
|
8 |
|
9 |
Feature content in a JavaScript powered slideshow gallery showcase on your WordPress website
|
10 |
|
@@ -122,6 +122,12 @@ There is an "Images Tester" utility under Slideshow > Configuration on the right
|
|
122 |
|
123 |
== Changelog ==
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
= 1.4.1 =
|
126 |
* ADD: Set opacity for information bar per slide
|
127 |
* ADD: Setting per slide to show title/description or not
|
4 |
Tags: wordpress plugins, wordpress slideshow gallery, slides, slideshow, image gallery, images, gallery, featured content, content gallery, javascript, javascript slideshow, slideshow gallery
|
5 |
Requires at least: 3.1
|
6 |
Tested up to: 3.9
|
7 |
+
Stable tag: 1.4.2
|
8 |
|
9 |
Feature content in a JavaScript powered slideshow gallery showcase on your WordPress website
|
10 |
|
122 |
|
123 |
== Changelog ==
|
124 |
|
125 |
+
= 1.4.2 =
|
126 |
+
* ADD: More flexible settings for information bar per slide
|
127 |
+
* ADD: Switch from TimThumb to BFI Thumb
|
128 |
+
* FIX: Change mysql_real_escape_string() to esc_sql()
|
129 |
+
* REMOVE: Images tester is no longer needed
|
130 |
+
|
131 |
= 1.4.1 =
|
132 |
* ADD: Set opacity for information bar per slide
|
133 |
* ADD: Setting per slide to show title/description or not
|
slideshow-gallery-plugin.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
class GalleryPlugin {
|
4 |
|
5 |
-
var $version = '1.4.
|
6 |
var $plugin_name;
|
7 |
var $plugin_base;
|
8 |
var $pre = 'Gallery';
|
@@ -24,6 +24,7 @@ class GalleryPlugin {
|
|
24 |
$this -> plugin_base = rtrim(dirname($base), DS);
|
25 |
$this -> sections = (object) $this -> sections;
|
26 |
$this -> initialize_classes();
|
|
|
27 |
|
28 |
global $wpdb;
|
29 |
$debugging = get_option('tridebugging');
|
@@ -117,9 +118,10 @@ class GalleryPlugin {
|
|
117 |
'resizeimages' => "N",
|
118 |
);
|
119 |
|
120 |
-
$this -> add_option('
|
|
|
|
|
121 |
$this -> add_option('styles', $styles);
|
122 |
-
$this -> add_option('timthumb_align', "c");
|
123 |
$this -> add_option('fadespeed', 10);
|
124 |
$this -> add_option('shownav', "Y");
|
125 |
$this -> add_option('navopacity', 25);
|
2 |
|
3 |
class GalleryPlugin {
|
4 |
|
5 |
+
var $version = '1.4.2';
|
6 |
var $plugin_name;
|
7 |
var $plugin_base;
|
8 |
var $pre = 'Gallery';
|
24 |
$this -> plugin_base = rtrim(dirname($base), DS);
|
25 |
$this -> sections = (object) $this -> sections;
|
26 |
$this -> initialize_classes();
|
27 |
+
$this -> initialize_options();
|
28 |
|
29 |
global $wpdb;
|
30 |
$debugging = get_option('tridebugging');
|
118 |
'resizeimages' => "N",
|
119 |
);
|
120 |
|
121 |
+
$this -> add_option('resizeimagescrop', "Y");
|
122 |
+
//$this -> add_option('imagespath', $this -> Html -> uploads_path() . DS . 'slideshow-gallery' . DS);
|
123 |
+
$this -> update_option('imagespath', $this -> Html -> uploads_url() . '/slideshow-gallery/');
|
124 |
$this -> add_option('styles', $styles);
|
|
|
125 |
$this -> add_option('fadespeed', 10);
|
126 |
$this -> add_option('shownav', "Y");
|
127 |
$this -> add_option('navopacity', 25);
|
slideshow-gallery.php
CHANGED
@@ -6,10 +6,10 @@ Plugin URI: http://wpgallery.tribulant.net
|
|
6 |
Author: Tribulant Software
|
7 |
Author URI: http://tribulant.com
|
8 |
Description: Feature content in a JavaScript powered slideshow gallery showcase on your WordPress website. The slideshow is flexible and all aspects can easily be configured. Embedding or hardcoding the slideshow gallery is a breeze. To embed into a post/page, simply insert <code>[tribulant_slideshow]</code> into its content with an optional <code>post_id</code> parameter. To hardcode into any PHP file of your WordPress theme, simply use <code><?php if (function_exists('slideshow')) { slideshow($output = true, $post_id = false, $gallery_id = false, $params = array()); } ?></code>.
|
9 |
-
Version: 1.4.
|
10 |
License: GNU General Public License v2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
-
Tags: slideshow gallery, slideshow, gallery, slider, jquery,
|
13 |
Text Domain: slideshow-gallery
|
14 |
Domain Path: /languages
|
15 |
*/
|
@@ -24,7 +24,7 @@ if (file_exists($path)) {
|
|
24 |
if (!class_exists('Gallery')) {
|
25 |
class Gallery extends GalleryPlugin {
|
26 |
|
27 |
-
function Gallery() {
|
28 |
$url = explode("&", $_SERVER['REQUEST_URI']);
|
29 |
$this -> url = $url[0];
|
30 |
$this -> referer = (empty($_SERVER['HTTP_REFERER'])) ? $this -> url : $_SERVER['HTTP_REFERER'];
|
@@ -103,13 +103,6 @@ if (!class_exists('Gallery')) {
|
|
103 |
$msg_type = (!empty($_GET[$this -> pre . 'updated'])) ? 'msg' : 'err';
|
104 |
call_user_func(array($this, 'render_' . $msg_type), $_GET[$this -> pre . 'message']);
|
105 |
}
|
106 |
-
|
107 |
-
if (!empty($_GET['page']) && (empty($_GET['method']) || $_GET['method'] != "imagestester") && in_array($_GET['page'], (array) $this -> sections)) {
|
108 |
-
$dismiss_imagestester = $this -> get_option('dismiss_imagestester');
|
109 |
-
if (empty($dismiss_imagestester)) {
|
110 |
-
$this -> render_msg(sprintf(__('Slideshow Gallery plugin images and thumbnails working fine? If not, use the %sImages Tester%s to fix it. Working fine? Then you can %s this message.', $this -> plugin_name), '<a class="button button-small" href="admin.php?page=' . $this -> sections -> settings . '&method=imagestester">', '</a>', '<a class="button button-small" href="admin.php?page=' . $this -> sections -> settings . '&method=dismiss&dismiss=imagestester">' . __('Dismiss', $this -> plugin_name) . '</a>'));
|
111 |
-
}
|
112 |
-
}
|
113 |
}
|
114 |
|
115 |
function mce_buttons($buttons) {
|
@@ -233,7 +226,6 @@ if (!class_exists('Gallery')) {
|
|
233 |
$imagespath = $this -> get_option('imagespath');
|
234 |
|
235 |
foreach ($slides as $skey => $slide) {
|
236 |
-
//$slides[$skey] -> image_path = $this -> Html -> uploads_path() . DS . $this -> plugin_name . DS . $slide -> image;
|
237 |
if (empty($imagespath)) {
|
238 |
$slides[$skey] -> image_path = $this -> Html -> uploads_path() . DS . 'slideshow-gallery' . DS . $slide -> image;
|
239 |
} else {
|
@@ -467,40 +459,6 @@ if (!class_exists('Gallery')) {
|
|
467 |
|
468 |
$this -> redirect($this -> referer);
|
469 |
break;
|
470 |
-
case 'imagestester' :
|
471 |
-
|
472 |
-
if (!empty($_GET['changepath'])) {
|
473 |
-
$newpath = $_GET['changepath'];
|
474 |
-
|
475 |
-
switch ($newpath) {
|
476 |
-
case 1 :
|
477 |
-
$path = $this -> Html -> uploads_path() . DS . $this -> plugin_name . DS;
|
478 |
-
break;
|
479 |
-
case 2 :
|
480 |
-
if (is_multisite()) {
|
481 |
-
global $blog_id;
|
482 |
-
$path = 'wp-content' . DS . 'uploads' . DS . 'sites' . DS . $blog_id . DS . $this -> plugin_name . DS;
|
483 |
-
} else {
|
484 |
-
$path = 'wp-content' . DS . 'uploads' . DS . $this -> plugin_name . DS;
|
485 |
-
}
|
486 |
-
break;
|
487 |
-
case 3 :
|
488 |
-
$path = $this -> Html -> uploads_url() . DS . $this -> plugin_name . DS;
|
489 |
-
break;
|
490 |
-
}
|
491 |
-
|
492 |
-
$this -> update_option('imagespath', $path);
|
493 |
-
$this -> render_msg(__('Images path has been updated, please check if the images work now. If not, click "Try Different Path" again in Step 3.', $this -> plugin_name));
|
494 |
-
}
|
495 |
-
|
496 |
-
$conditions = false;
|
497 |
-
if (!empty($_GET['id'])) {
|
498 |
-
$conditions['id'] = $_GET['id'];
|
499 |
-
}
|
500 |
-
|
501 |
-
$slide = $this -> Slide -> find($conditions, false, "RAND");
|
502 |
-
$this -> render('settings-images', array('slide' => $slide), true, 'admin');
|
503 |
-
break;
|
504 |
case 'reset' :
|
505 |
global $wpdb;
|
506 |
$query = "DELETE FROM `" . $wpdb -> prefix . "options` WHERE `option_name` LIKE '" . $this -> pre . "%';";
|
6 |
Author: Tribulant Software
|
7 |
Author URI: http://tribulant.com
|
8 |
Description: Feature content in a JavaScript powered slideshow gallery showcase on your WordPress website. The slideshow is flexible and all aspects can easily be configured. Embedding or hardcoding the slideshow gallery is a breeze. To embed into a post/page, simply insert <code>[tribulant_slideshow]</code> into its content with an optional <code>post_id</code> parameter. To hardcode into any PHP file of your WordPress theme, simply use <code><?php if (function_exists('slideshow')) { slideshow($output = true, $post_id = false, $gallery_id = false, $params = array()); } ?></code>.
|
9 |
+
Version: 1.4.2
|
10 |
License: GNU General Public License v2 or later
|
11 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
+
Tags: slideshow gallery, slideshow, gallery, slider, jquery, bfithumb, galleries, photos, images
|
13 |
Text Domain: slideshow-gallery
|
14 |
Domain Path: /languages
|
15 |
*/
|
24 |
if (!class_exists('Gallery')) {
|
25 |
class Gallery extends GalleryPlugin {
|
26 |
|
27 |
+
function Gallery() {
|
28 |
$url = explode("&", $_SERVER['REQUEST_URI']);
|
29 |
$this -> url = $url[0];
|
30 |
$this -> referer = (empty($_SERVER['HTTP_REFERER'])) ? $this -> url : $_SERVER['HTTP_REFERER'];
|
103 |
$msg_type = (!empty($_GET[$this -> pre . 'updated'])) ? 'msg' : 'err';
|
104 |
call_user_func(array($this, 'render_' . $msg_type), $_GET[$this -> pre . 'message']);
|
105 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
function mce_buttons($buttons) {
|
226 |
$imagespath = $this -> get_option('imagespath');
|
227 |
|
228 |
foreach ($slides as $skey => $slide) {
|
|
|
229 |
if (empty($imagespath)) {
|
230 |
$slides[$skey] -> image_path = $this -> Html -> uploads_path() . DS . 'slideshow-gallery' . DS . $slide -> image;
|
231 |
} else {
|
459 |
|
460 |
$this -> redirect($this -> referer);
|
461 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
case 'reset' :
|
463 |
global $wpdb;
|
464 |
$query = "DELETE FROM `" . $wpdb -> prefix . "options` WHERE `option_name` LIKE '" . $this -> pre . "%';";
|
vendors/BFI_Thumb.php
ADDED
@@ -0,0 +1,663 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
* bfi_thumb - WP Image Resizer v1.3
|
4 |
+
*
|
5 |
+
* (c) 2013 Benjamin F. Intal / Gambit
|
6 |
+
*
|
7 |
+
* This program is free software: you can redistribute it and/or modify
|
8 |
+
* it under the terms of the GNU General Public License as published by
|
9 |
+
* the Free Software Foundation, either version 3 of the License, or
|
10 |
+
* (at your option) any later version.
|
11 |
+
*
|
12 |
+
* This program is distributed in the hope that it will be useful,
|
13 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
+
* GNU General Public License for more details.
|
16 |
+
*
|
17 |
+
* You should have received a copy of the GNU General Public License
|
18 |
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19 |
+
*/
|
20 |
+
|
21 |
+
/** Uses WP's Image Editor Class to resize and filter images
|
22 |
+
*
|
23 |
+
* @param $url string the local image URL to manipulate
|
24 |
+
* @param $params array the options to perform on the image. Keys and values supported:
|
25 |
+
* 'width' int pixels
|
26 |
+
* 'height' int pixels
|
27 |
+
* 'opacity' int 0-100
|
28 |
+
* 'color' string hex-color #000000-#ffffff
|
29 |
+
* 'grayscale' bool
|
30 |
+
* 'negate' bool
|
31 |
+
* 'crop' bool
|
32 |
+
* @param $single boolean, if false then an array of data will be returned
|
33 |
+
* @return string|array containing the url of the resized modofied image
|
34 |
+
*/
|
35 |
+
|
36 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
37 |
+
|
38 |
+
if ( !function_exists( 'bfi_thumb' ) ) {
|
39 |
+
function bfi_thumb($url, $params = array(), $single = true) {
|
40 |
+
$class = BFI_Class_Factory::getNewestVersion( 'BFI_Thumb' );
|
41 |
+
return call_user_func( array( $class, 'thumb' ), $url, $params, $single );
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Class factory, this is to make sure that when multiple bfi_thumb scripts
|
48 |
+
* are used (e.g. a plugin and a theme both use it), we always use the
|
49 |
+
* latest version.
|
50 |
+
*/
|
51 |
+
if ( !class_exists( 'BFI_Class_Factory' ) ) {
|
52 |
+
class BFI_Class_Factory {
|
53 |
+
public static $versions = array();
|
54 |
+
public static $latestClass = array();
|
55 |
+
|
56 |
+
public static function addClassVersion( $baseClassName, $className, $version ) {
|
57 |
+
if ( empty( self::$versions[$baseClassName] ) ) {
|
58 |
+
self::$versions[$baseClassName] = array();
|
59 |
+
}
|
60 |
+
self::$versions[$baseClassName][] = array(
|
61 |
+
'class' => $className,
|
62 |
+
'version' => $version
|
63 |
+
);
|
64 |
+
}
|
65 |
+
|
66 |
+
public static function getNewestVersion( $baseClassName ) {
|
67 |
+
if ( empty( self::$latestClass[$baseClassName] ) ) {
|
68 |
+
usort( self::$versions[$baseClassName], array( __CLASS__, "versionCompare" ) );
|
69 |
+
self::$latestClass[$baseClassName] = self::$versions[$baseClassName][0]['class'];
|
70 |
+
unset( self::$versions[$baseClassName] );
|
71 |
+
}
|
72 |
+
return self::$latestClass[$baseClassName];
|
73 |
+
}
|
74 |
+
|
75 |
+
public static function versionCompare( $a, $b ) {
|
76 |
+
return version_compare( $a['version'], $b['version'] ) == 1 ? -1 : 1;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
/*
|
84 |
+
* Change the default image editors
|
85 |
+
*/
|
86 |
+
add_filter('wp_image_editors', 'bfi_wp_image_editor');
|
87 |
+
|
88 |
+
// Instead of using the default image editors, use our extended ones
|
89 |
+
if ( !function_exists( 'bfi_wp_image_editor' ) ) {
|
90 |
+
function bfi_wp_image_editor($editorArray) {
|
91 |
+
// Make sure that we use the latest versions
|
92 |
+
return array(
|
93 |
+
BFI_Class_Factory::getNewestVersion( 'BFI_Image_Editor_GD' ),
|
94 |
+
BFI_Class_Factory::getNewestVersion( 'BFI_Image_Editor_Imagick' ),
|
95 |
+
);
|
96 |
+
}
|
97 |
+
}
|
98 |
+
|
99 |
+
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
|
100 |
+
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
|
101 |
+
require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
/**
|
106 |
+
* check for ImageMagick or GD
|
107 |
+
*/
|
108 |
+
add_action('admin_init', 'bfi_wp_image_editor_check');
|
109 |
+
if ( !function_exists( 'bfi_wp_image_editor_check' ) ) {
|
110 |
+
function bfi_wp_image_editor_check() {
|
111 |
+
$arg = array('mime_type' => 'image/jpeg');
|
112 |
+
if (wp_image_editor_supports($arg) !== true) {
|
113 |
+
add_filter('admin_notices', 'bfi_wp_image_editor_check_notice');
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
if ( !function_exists( 'bfi_wp_image_editor_check_notice' ) ) {
|
118 |
+
function bfi_wp_image_editor_check_notice() {
|
119 |
+
printf("<div class='error'><p>%s</div>",
|
120 |
+
__("The server does not have ImageMagick or GD installed and/or enabled! Any of these libraries are required for WordPress to be able to resize images. Please contact your server administrator to enable this before continuing.", "default"));
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
|
125 |
+
/*
|
126 |
+
* Enhanced Imagemagick Image Editor
|
127 |
+
*/
|
128 |
+
if ( !class_exists( 'BFI_Image_Editor_Imagick_1_3' ) ) {
|
129 |
+
BFI_Class_Factory::addClassVersion( 'BFI_Image_Editor_Imagick', 'BFI_Image_Editor_Imagick_1_3', '1.3' );
|
130 |
+
|
131 |
+
class BFI_Image_Editor_Imagick_1_3 extends WP_Image_Editor_Imagick {
|
132 |
+
|
133 |
+
/** Changes the opacity of the image
|
134 |
+
*
|
135 |
+
* @supports 3.5.1
|
136 |
+
* @access public
|
137 |
+
*
|
138 |
+
* @param float $opacity (0.0-1.0)
|
139 |
+
* @return boolean|WP_Error
|
140 |
+
*/
|
141 |
+
public function opacity($opacity) {
|
142 |
+
$opacity /= 100;
|
143 |
+
|
144 |
+
try {
|
145 |
+
// From: http://stackoverflow.com/questions/3538851/php-imagick-setimageopacity-destroys-transparency-and-does-nothing
|
146 |
+
// preserves transparency
|
147 |
+
//$this->image->setImageOpacity($opacity);
|
148 |
+
return $this->image->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity, Imagick::CHANNEL_ALPHA);
|
149 |
+
} catch ( Exception $e ) {
|
150 |
+
return new WP_Error( 'image_opacity_error', $e->getMessage() );
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
/** Tints the image a different color
|
155 |
+
*
|
156 |
+
* @supports 3.5.1
|
157 |
+
* @access public
|
158 |
+
*
|
159 |
+
* @param string hex color e.g. #ff00ff
|
160 |
+
* @return boolean|WP_Error
|
161 |
+
*/
|
162 |
+
public function colorize($hexColor) {
|
163 |
+
try {
|
164 |
+
return $this->image->colorizeImage($hexColor, 1.0);
|
165 |
+
} catch (Exception $e) {
|
166 |
+
return new WP_Error( 'image_colorize_error', $e->getMessage() );
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
/** Makes the image grayscale
|
171 |
+
*
|
172 |
+
* @supports 3.5.1
|
173 |
+
* @access public
|
174 |
+
*
|
175 |
+
* @return boolean|WP_Error
|
176 |
+
*/
|
177 |
+
public function grayscale() {
|
178 |
+
try {
|
179 |
+
return $this->image->modulateImage(100,0,100);
|
180 |
+
} catch (Exception $e) {
|
181 |
+
return new WP_Error( 'image_grayscale_error', $e->getMessage() );
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
/** Negates the image
|
186 |
+
*
|
187 |
+
* @supports 3.5.1
|
188 |
+
* @access public
|
189 |
+
*
|
190 |
+
* @return boolean|WP_Error
|
191 |
+
*/
|
192 |
+
public function negate() {
|
193 |
+
try {
|
194 |
+
return $this->image->negateImage(false);
|
195 |
+
} catch (Exception $e) {
|
196 |
+
return new WP_Error( 'image_negate_error', $e->getMessage() );
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
}
|
201 |
+
|
202 |
+
|
203 |
+
/*
|
204 |
+
* Enhanced GD Image Editor
|
205 |
+
*/
|
206 |
+
if ( !class_exists( 'BFI_Image_Editor_GD_1_3' ) ) {
|
207 |
+
BFI_Class_Factory::addClassVersion( 'BFI_Image_Editor_GD', 'BFI_Image_Editor_GD_1_3', '1.3' );
|
208 |
+
|
209 |
+
class BFI_Image_Editor_GD_1_3 extends WP_Image_Editor_GD {
|
210 |
+
/** Rotates current image counter-clockwise by $angle.
|
211 |
+
* Ported from image-edit.php
|
212 |
+
* Added presevation of alpha channels
|
213 |
+
*
|
214 |
+
* @since 3.5.0
|
215 |
+
* @access public
|
216 |
+
*
|
217 |
+
* @param float $angle
|
218 |
+
* @return boolean|WP_Error
|
219 |
+
*/
|
220 |
+
public function rotate( $angle ) {
|
221 |
+
if ( function_exists('imagerotate') ) {
|
222 |
+
$rotated = imagerotate( $this->image, $angle, 0 );
|
223 |
+
|
224 |
+
// Add alpha blending
|
225 |
+
imagealphablending($rotated, true);
|
226 |
+
imagesavealpha($rotated, true);
|
227 |
+
|
228 |
+
if ( is_resource( $rotated ) ) {
|
229 |
+
imagedestroy( $this->image );
|
230 |
+
$this->image = $rotated;
|
231 |
+
$this->update_size();
|
232 |
+
return true;
|
233 |
+
}
|
234 |
+
}
|
235 |
+
return new WP_Error( 'image_rotate_error', __('Image rotate failed.', 'default'), $this->file );
|
236 |
+
}
|
237 |
+
|
238 |
+
/** Changes the opacity of the image
|
239 |
+
*
|
240 |
+
* @supports 3.5.1
|
241 |
+
* @access public
|
242 |
+
*
|
243 |
+
* @param float $opacity (0.0-1.0)
|
244 |
+
* @return boolean|WP_Error
|
245 |
+
*/
|
246 |
+
public function opacity($opacity) {
|
247 |
+
$opacity /= 100;
|
248 |
+
|
249 |
+
$filtered = $this->_opacity($this->image, $opacity);
|
250 |
+
|
251 |
+
if (is_resource($filtered)) {
|
252 |
+
// imagedestroy($this->image);
|
253 |
+
$this->image = $filtered;
|
254 |
+
return true;
|
255 |
+
}
|
256 |
+
|
257 |
+
return new WP_Error( 'image_opacity_error', __('Image opacity change failed.', 'default'), $this->file );
|
258 |
+
}
|
259 |
+
|
260 |
+
// from: http://php.net/manual/en/function.imagefilter.php
|
261 |
+
// params: image resource id, opacity (eg. 0.0-1.0)
|
262 |
+
protected function _opacity($image, $opacity) {
|
263 |
+
if (!function_exists('imagealphablending') ||
|
264 |
+
!function_exists('imagecolorat') ||
|
265 |
+
!function_exists('imagecolorallocatealpha') ||
|
266 |
+
!function_exists('imagesetpixel')) return false;
|
267 |
+
|
268 |
+
//get image width and height
|
269 |
+
$w = imagesx( $image );
|
270 |
+
$h = imagesy( $image );
|
271 |
+
|
272 |
+
//turn alpha blending off
|
273 |
+
imagealphablending( $image, false );
|
274 |
+
|
275 |
+
//find the most opaque pixel in the image (the one with the smallest alpha value)
|
276 |
+
$minalpha = 127;
|
277 |
+
for ($x = 0; $x < $w; $x++) {
|
278 |
+
for ($y = 0; $y < $h; $y++) {
|
279 |
+
$alpha = (imagecolorat($image, $x, $y) >> 24 ) & 0xFF;
|
280 |
+
if( $alpha < $minalpha ) {
|
281 |
+
$minalpha = $alpha;
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
//loop through image pixels and modify alpha for each
|
287 |
+
for ( $x = 0; $x < $w; $x++ ) {
|
288 |
+
for ( $y = 0; $y < $h; $y++ ) {
|
289 |
+
//get current alpha value (represents the TANSPARENCY!)
|
290 |
+
$colorxy = imagecolorat( $image, $x, $y );
|
291 |
+
$alpha = ( $colorxy >> 24 ) & 0xFF;
|
292 |
+
//calculate new alpha
|
293 |
+
if ( $minalpha !== 127 ) {
|
294 |
+
$alpha = 127 + 127 * $opacity * ( $alpha - 127 ) / ( 127 - $minalpha );
|
295 |
+
} else {
|
296 |
+
$alpha += 127 * $opacity;
|
297 |
+
}
|
298 |
+
//get the color index with new alpha
|
299 |
+
$alphacolorxy = imagecolorallocatealpha( $image, ( $colorxy >> 16 ) & 0xFF, ( $colorxy >> 8 ) & 0xFF, $colorxy & 0xFF, $alpha );
|
300 |
+
//set pixel with the new color + opacity
|
301 |
+
if(!imagesetpixel($image, $x, $y, $alphacolorxy)) {
|
302 |
+
return false;
|
303 |
+
}
|
304 |
+
}
|
305 |
+
}
|
306 |
+
|
307 |
+
imagesavealpha($image, true);
|
308 |
+
|
309 |
+
return $image;
|
310 |
+
}
|
311 |
+
|
312 |
+
/** Tints the image a different color
|
313 |
+
*
|
314 |
+
* @supports 3.5.1
|
315 |
+
* @access public
|
316 |
+
*
|
317 |
+
* @param string hex color e.g. #ff00ff
|
318 |
+
* @return boolean|WP_Error
|
319 |
+
*/
|
320 |
+
public function colorize($hexColor) {
|
321 |
+
if (function_exists('imagefilter') &&
|
322 |
+
function_exists('imagesavealpha') &&
|
323 |
+
function_exists('imagealphablending')) {
|
324 |
+
$hexColor = preg_replace('#^\##', '', $hexColor);
|
325 |
+
$r = hexdec (substr ($hexColor, 0, 2));
|
326 |
+
$g = hexdec (substr ($hexColor, 2, 2));
|
327 |
+
$b = hexdec (substr ($hexColor, 2, 2));
|
328 |
+
|
329 |
+
imagealphablending( $this->image, false );
|
330 |
+
if (imagefilter($this->image, IMG_FILTER_COLORIZE, $r, $g, $b, 0)) {
|
331 |
+
imagesavealpha($this->image, true);
|
332 |
+
return true;
|
333 |
+
}
|
334 |
+
}
|
335 |
+
return new WP_Error( 'image_colorize_error', __('Image color change failed.', 'default'), $this->file );
|
336 |
+
}
|
337 |
+
|
338 |
+
/** Makes the image grayscale
|
339 |
+
*
|
340 |
+
* @supports 3.5.1
|
341 |
+
* @access public
|
342 |
+
*
|
343 |
+
* @return boolean|WP_Error
|
344 |
+
*/
|
345 |
+
public function grayscale() {
|
346 |
+
if (function_exists('imagefilter')) {
|
347 |
+
if (imagefilter($this->image, IMG_FILTER_GRAYSCALE)) {
|
348 |
+
return true;
|
349 |
+
}
|
350 |
+
}
|
351 |
+
return new WP_Error( 'image_grayscale_error', __('Image grayscale failed.', 'default'), $this->file );
|
352 |
+
}
|
353 |
+
|
354 |
+
/** Negates the image
|
355 |
+
*
|
356 |
+
* @supports 3.5.1
|
357 |
+
* @access public
|
358 |
+
*
|
359 |
+
* @return boolean|WP_Error
|
360 |
+
*/
|
361 |
+
public function negate() {
|
362 |
+
if (function_exists('imagefilter')) {
|
363 |
+
if (imagefilter($this->image, IMG_FILTER_NEGATE)) {
|
364 |
+
return true;
|
365 |
+
}
|
366 |
+
}
|
367 |
+
return new WP_Error( 'image_negate_error', __('Image negate failed.', 'default'), $this->file );
|
368 |
+
}
|
369 |
+
}
|
370 |
+
}
|
371 |
+
|
372 |
+
|
373 |
+
/*
|
374 |
+
* Main Class
|
375 |
+
*/
|
376 |
+
if ( !class_exists( 'BFI_Thumb_1_3' ) ) {
|
377 |
+
BFI_Class_Factory::addClassVersion( 'BFI_Thumb', 'BFI_Thumb_1_3', '1.3' );
|
378 |
+
|
379 |
+
class BFI_Thumb_1_3 {
|
380 |
+
/** Uses WP's Image Editor Class to resize and filter images
|
381 |
+
* Inspired by: https://github.com/sy4mil/Aqua-Resizer/blob/master/aq_resizer.php
|
382 |
+
*
|
383 |
+
* @param $url string the local image URL to manipulate
|
384 |
+
* @param $params array the options to perform on the image. Keys and values supported:
|
385 |
+
* 'width' int pixels
|
386 |
+
* 'height' int pixels
|
387 |
+
* 'opacity' int 0-100
|
388 |
+
* 'color' string hex-color #000000-#ffffff
|
389 |
+
* 'grayscale' bool
|
390 |
+
* 'crop' bool
|
391 |
+
* 'negate' bool
|
392 |
+
* @param $single boolean, if false then an array of data will be returned
|
393 |
+
* @return string|array
|
394 |
+
*/
|
395 |
+
public static function thumb($url, $params = array(), $single = true) {
|
396 |
+
extract($params);
|
397 |
+
|
398 |
+
//validate inputs
|
399 |
+
if(!$url) return false;
|
400 |
+
|
401 |
+
//define upload path & dir
|
402 |
+
$upload_info = wp_upload_dir();
|
403 |
+
$upload_dir = $upload_info['basedir'];
|
404 |
+
$upload_url = $upload_info['baseurl'];
|
405 |
+
$theme_url = get_template_directory_uri();
|
406 |
+
$theme_dir = get_template_directory();
|
407 |
+
|
408 |
+
// find the path of the image. Perform 2 checks:
|
409 |
+
// #1 check if the image is in the uploads folder
|
410 |
+
if(strpos( $url, $upload_url ) !== false) {
|
411 |
+
$rel_path = str_replace( $upload_url, '', $url);
|
412 |
+
$img_path = $upload_dir . $rel_path;
|
413 |
+
|
414 |
+
// #2 check if the image is in the current theme folder
|
415 |
+
} else if (strpos($url, $theme_url) !== false) {
|
416 |
+
$rel_path = str_replace( $theme_url, '', $url);
|
417 |
+
$img_path = $theme_dir . $rel_path;
|
418 |
+
}
|
419 |
+
|
420 |
+
// Fail if we can't find the image in our WP local directory
|
421 |
+
if ( empty( $img_path ) ) return $url;
|
422 |
+
|
423 |
+
//check if img path exists, and is an image indeed
|
424 |
+
if( !@file_exists($img_path) OR !getimagesize($img_path) ) return $url;
|
425 |
+
|
426 |
+
// This is the filename
|
427 |
+
$basename = basename($img_path);
|
428 |
+
|
429 |
+
//get image info
|
430 |
+
$info = pathinfo($img_path);
|
431 |
+
$ext = $info['extension'];
|
432 |
+
list($orig_w,$orig_h) = getimagesize($img_path);
|
433 |
+
|
434 |
+
// support percentage dimensions. compute percentage based on
|
435 |
+
// the original dimensions
|
436 |
+
if (isset($width)) {
|
437 |
+
if (stripos($width, '%') !== false) {
|
438 |
+
$width = (int)((float)str_replace('%', '', $width) / 100 * $orig_w);
|
439 |
+
}
|
440 |
+
}
|
441 |
+
if (isset($height)) {
|
442 |
+
if (stripos($height, '%') !== false) {
|
443 |
+
$height = (int)((float)str_replace('%', '', $height) / 100 * $orig_h);
|
444 |
+
}
|
445 |
+
}
|
446 |
+
|
447 |
+
// The only purpose of this is to detemine the final width and height
|
448 |
+
// without performing any actual image manipulation, which will be used
|
449 |
+
// to check whether a resize was previously done.
|
450 |
+
if (isset($width)) {
|
451 |
+
//get image size after cropping
|
452 |
+
$dims = image_resize_dimensions($orig_w, $orig_h, $width, isset($height) ? $height : null, isset($crop) ? $crop : false);
|
453 |
+
$dst_w = $dims[4];
|
454 |
+
$dst_h = $dims[5];
|
455 |
+
}
|
456 |
+
|
457 |
+
// create the suffix for the saved file
|
458 |
+
// we can use this to check whether we need to create a new file or just use an existing one.
|
459 |
+
$suffix = (string)filemtime($img_path) .
|
460 |
+
(isset($width) ? str_pad((string)$width, 5, '0', STR_PAD_LEFT) : '00000') .
|
461 |
+
(isset($height) ? str_pad((string)$height, 5, '0', STR_PAD_LEFT) : '00000') .
|
462 |
+
(isset($opacity) ? str_pad((string)$opacity, 3, '0', STR_PAD_LEFT) : '100') .
|
463 |
+
(isset($color) ? str_pad(preg_replace('#^\##', '', $color), 8, '0', STR_PAD_LEFT) : '00000000') .
|
464 |
+
(isset($grayscale) ? ($grayscale ? '1' : '0') : '0') .
|
465 |
+
(isset($crop) ? ($crop ? '1' : '0') : '0') .
|
466 |
+
(isset($negate) ? ($negate ? '1' : '0') : '0');
|
467 |
+
$suffix = self::base_convert_arbitrary($suffix, 10, 36);
|
468 |
+
|
469 |
+
// use this to check if cropped image already exists, so we can return that instead
|
470 |
+
$dst_rel_path = str_replace( '.'.$ext, '', basename($img_path));
|
471 |
+
|
472 |
+
// If opacity is set, change the image type to png
|
473 |
+
if (isset($opacity)) $ext = 'png';
|
474 |
+
|
475 |
+
|
476 |
+
// Create the upload subdirectory, this is where
|
477 |
+
// we store all our generated images
|
478 |
+
if ( defined( 'BFITHUMB_UPLOAD_DIR' ) ) {
|
479 |
+
$upload_dir .= "/" . BFITHUMB_UPLOAD_DIR;
|
480 |
+
$upload_url .= "/" . BFITHUMB_UPLOAD_DIR;
|
481 |
+
} else {
|
482 |
+
$upload_dir .= "/bfi_thumb";
|
483 |
+
$upload_url .= "/bfi_thumb";
|
484 |
+
}
|
485 |
+
if ( !is_dir( $upload_dir ) ) {
|
486 |
+
wp_mkdir_p( $upload_dir );
|
487 |
+
}
|
488 |
+
|
489 |
+
|
490 |
+
// desination paths and urls
|
491 |
+
$destfilename = "{$upload_dir}/{$dst_rel_path}-{$suffix}.{$ext}";
|
492 |
+
$img_url = "{$upload_url}/{$dst_rel_path}-{$suffix}.{$ext}";
|
493 |
+
|
494 |
+
// if file exists, just return it
|
495 |
+
if (@file_exists($destfilename) && getimagesize($destfilename)) {
|
496 |
+
} else {
|
497 |
+
// perform resizing and other filters
|
498 |
+
$editor = wp_get_image_editor($img_path);
|
499 |
+
|
500 |
+
if (is_wp_error( $editor )) return false;
|
501 |
+
|
502 |
+
/*
|
503 |
+
* Perform image manipulations
|
504 |
+
*/
|
505 |
+
if ( ( isset( $width ) && $width ) || ( isset( $height ) && $height ) ) {
|
506 |
+
if ( is_wp_error( $editor->resize( isset( $width ) ? $width : null, isset( $height ) ? $height : null, isset( $crop ) ? $crop : false ) ) ) {
|
507 |
+
return false;
|
508 |
+
}
|
509 |
+
}
|
510 |
+
|
511 |
+
if ( isset( $negate ) ) {
|
512 |
+
if ( $negate ) {
|
513 |
+
if ( is_wp_error( $editor->negate() ) ) {
|
514 |
+
return false;
|
515 |
+
}
|
516 |
+
}
|
517 |
+
}
|
518 |
+
|
519 |
+
if ( isset( $opacity ) ) {
|
520 |
+
if ( is_wp_error( $editor->opacity( $opacity ) ) ) {
|
521 |
+
return false;
|
522 |
+
}
|
523 |
+
}
|
524 |
+
|
525 |
+
if ( isset( $grayscale ) ) {
|
526 |
+
if ( $grayscale ) {
|
527 |
+
if ( is_wp_error( $editor->grayscale() ) ) {
|
528 |
+
return false;
|
529 |
+
}
|
530 |
+
}
|
531 |
+
}
|
532 |
+
|
533 |
+
if ( isset( $color ) ) {
|
534 |
+
if ( is_wp_error( $editor->colorize( $color ) ) ) {
|
535 |
+
return false;
|
536 |
+
}
|
537 |
+
}
|
538 |
+
|
539 |
+
// save our new image
|
540 |
+
$mime_type = isset( $opacity ) ? 'image/png' : null;
|
541 |
+
$resized_file = $editor->save($destfilename, $mime_type);
|
542 |
+
}
|
543 |
+
|
544 |
+
//return the output
|
545 |
+
if($single) {
|
546 |
+
$image = $img_url;
|
547 |
+
} else {
|
548 |
+
//array return
|
549 |
+
$image = array (
|
550 |
+
0 => $img_url,
|
551 |
+
1 => isset($dst_w) ? $dst_w : $orig_w,
|
552 |
+
2 => isset($dst_h) ? $dst_h : $orig_h,
|
553 |
+
);
|
554 |
+
}
|
555 |
+
|
556 |
+
return $image;
|
557 |
+
}
|
558 |
+
|
559 |
+
/** Shortens a number into a base 36 string
|
560 |
+
*
|
561 |
+
* @param $number string a string of numbers to convert
|
562 |
+
* @param $fromBase starting base
|
563 |
+
* @param $toBase base to convert the number to
|
564 |
+
* @return string base converted characters
|
565 |
+
*/
|
566 |
+
protected static function base_convert_arbitrary($number, $fromBase, $toBase) {
|
567 |
+
$digits = '0123456789abcdefghijklmnopqrstuvwxyz';
|
568 |
+
$length = strlen($number);
|
569 |
+
$result = '';
|
570 |
+
|
571 |
+
$nibbles = array();
|
572 |
+
for ($i = 0; $i < $length; ++$i) {
|
573 |
+
$nibbles[$i] = strpos($digits, $number[$i]);
|
574 |
+
}
|
575 |
+
|
576 |
+
do {
|
577 |
+
$value = 0;
|
578 |
+
$newlen = 0;
|
579 |
+
for ($i = 0; $i < $length; ++$i) {
|
580 |
+
$value = $value * $fromBase + $nibbles[$i];
|
581 |
+
if ($value >= $toBase) {
|
582 |
+
$nibbles[$newlen++] = (int)($value / $toBase);
|
583 |
+
$value %= $toBase;
|
584 |
+
}
|
585 |
+
else if ($newlen > 0) {
|
586 |
+
$nibbles[$newlen++] = 0;
|
587 |
+
}
|
588 |
+
}
|
589 |
+
$length = $newlen;
|
590 |
+
$result = $digits[$value].$result;
|
591 |
+
}
|
592 |
+
while ($newlen != 0);
|
593 |
+
return $result;
|
594 |
+
}
|
595 |
+
}
|
596 |
+
}
|
597 |
+
|
598 |
+
|
599 |
+
// don't use the default resizer since we want to allow resizing to larger sizes (than the original one)
|
600 |
+
// Parts are copied from media.php
|
601 |
+
// Crop is always applied
|
602 |
+
add_filter('image_resize_dimensions', 'bfi_image_resize_dimensions', 10, 5);
|
603 |
+
if ( !function_exists( 'bfi_image_resize_dimensions' ) ) {
|
604 |
+
function bfi_image_resize_dimensions($payload, $orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
|
605 |
+
$aspect_ratio = $orig_w / $orig_h;
|
606 |
+
|
607 |
+
$new_w = $dest_w;
|
608 |
+
$new_h = $dest_h;
|
609 |
+
|
610 |
+
if ( !$new_w ) {
|
611 |
+
$new_w = intval($new_h * $aspect_ratio);
|
612 |
+
}
|
613 |
+
|
614 |
+
if ( !$new_h ) {
|
615 |
+
$new_h = intval($new_w / $aspect_ratio);
|
616 |
+
}
|
617 |
+
|
618 |
+
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
|
619 |
+
|
620 |
+
$crop_w = round($new_w / $size_ratio);
|
621 |
+
$crop_h = round($new_h / $size_ratio);
|
622 |
+
$s_x = floor( ($orig_w - $crop_w) / 2 );
|
623 |
+
$s_y = floor( ($orig_h - $crop_h) / 2 );
|
624 |
+
|
625 |
+
// the return array matches the parameters to imagecopyresampled()
|
626 |
+
// int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
|
627 |
+
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
|
628 |
+
}
|
629 |
+
}
|
630 |
+
|
631 |
+
|
632 |
+
// This function allows us to latch on WP image functions such as
|
633 |
+
// the_post_thumbnail, get_image_tag and wp_get_attachment_image_src
|
634 |
+
// so that you won't have to use the function bfi_thumb in order to do resizing.
|
635 |
+
// To make this work, in the WP image functions, when specifying an
|
636 |
+
// array for the image dimensions, add a 'bfi_thumb' => true to
|
637 |
+
// the array, then add your normal $params arguments.
|
638 |
+
//
|
639 |
+
// e.g. the_post_thumbnail( array( 1024, 400, 'bfi_thumb' => true, 'grayscale' => true ) );
|
640 |
+
add_filter( 'image_downsize', 'bfi_image_downsize', 1, 3 );
|
641 |
+
if ( !function_exists( 'bfi_image_downsize' ) ) {
|
642 |
+
function bfi_image_downsize( $out, $id, $size ) {
|
643 |
+
if ( ! is_array( $size ) ) {
|
644 |
+
return false;
|
645 |
+
}
|
646 |
+
if ( ! array_key_exists( 'bfi_thumb', $size ) ) {
|
647 |
+
return false;
|
648 |
+
}
|
649 |
+
if ( empty( $size['bfi_thumb'] ) ) {
|
650 |
+
return false;
|
651 |
+
}
|
652 |
+
|
653 |
+
$img_url = wp_get_attachment_url( $id );
|
654 |
+
|
655 |
+
$params = $size;
|
656 |
+
$params['width'] = $size[0];
|
657 |
+
$params['height'] = $size[1];
|
658 |
+
|
659 |
+
$resized_img_url = bfi_thumb( $img_url, $params );
|
660 |
+
|
661 |
+
return array( $resized_img_url, $size[0], $size[1], false );
|
662 |
+
}
|
663 |
+
}
|
vendors/timthumb.php
DELETED
@@ -1,1264 +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.13'); // 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 |
-
if(! defined('DISPLAY_ERROR_MESSAGES') ) define ('DISPLAY_ERROR_MESSAGES', true); // Display error messages. Set to false to turn off errors (good for production websites)
|
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', '../../../uploads/slideshow-gallery/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 |
-
if(! defined('DEFAULT_WIDTH') ) define ('DEFAULT_WIDTH', 100); // Default thumbnail width. Allows overrid in timthumb-config.php
|
61 |
-
if(! defined('DEFAULT_HEIGHT') ) define ('DEFAULT_HEIGHT', 100); // Default thumbnail height. Allows overrid in timthumb-config.php
|
62 |
-
|
63 |
-
/**
|
64 |
-
* Additional Parameters:
|
65 |
-
* LOCAL_FILE_BASE_DIRECTORY = Override the DOCUMENT_ROOT. This is best used in timthumb-config.php
|
66 |
-
*/
|
67 |
-
|
68 |
-
//Image compression is enabled if either of these point to valid paths
|
69 |
-
|
70 |
-
//These are now disabled by default because the file sizes of PNGs (and GIFs) are much smaller than we used to generate.
|
71 |
-
//They only work for PNGs. GIFs and JPEGs are not affected.
|
72 |
-
if(! defined('OPTIPNG_ENABLED') ) define ('OPTIPNG_ENABLED', false);
|
73 |
-
if(! defined('OPTIPNG_PATH') ) define ('OPTIPNG_PATH', '/usr/bin/optipng'); //This will run first because it gives better compression than pngcrush.
|
74 |
-
if(! defined('PNGCRUSH_ENABLED') ) define ('PNGCRUSH_ENABLED', false);
|
75 |
-
if(! defined('PNGCRUSH_PATH') ) define ('PNGCRUSH_PATH', '/usr/bin/pngcrush'); //This will only run if OPTIPNG_PATH is not set or is not valid
|
76 |
-
|
77 |
-
/*
|
78 |
-
-------====Website Screenshots configuration - BETA====-------
|
79 |
-
|
80 |
-
If you just want image thumbnails and don't want website screenshots, you can safely leave this as is.
|
81 |
-
|
82 |
-
If you would like to get website screenshots set up, you will need root access to your own server.
|
83 |
-
|
84 |
-
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.
|
85 |
-
Enable BLOCK_EXTERNAL_LEECHERS so that your site doesn't generate thumbnails for the whole Internet.
|
86 |
-
|
87 |
-
Instructions to get website screenshots enabled on Ubuntu Linux:
|
88 |
-
|
89 |
-
1. Install Xvfb with the following command: sudo apt-get install subversion libqt4-webkit libqt4-dev g++ xvfb
|
90 |
-
2. Go to a directory where you can download some code
|
91 |
-
3. Check-out the latest version of CutyCapt with the following command: svn co https://cutycapt.svn.sourceforge.net/svnroot/cutycapt
|
92 |
-
4. Compile CutyCapt by doing: cd cutycapt/CutyCapt
|
93 |
-
5. qmake
|
94 |
-
6. make
|
95 |
-
7. cp CutyCapt /usr/local/bin/
|
96 |
-
8. Test it by running: xvfb-run --server-args="-screen 0, 1024x768x24" CutyCapt --url="http://markmaunder.com/" --out=test.png
|
97 |
-
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:
|
98 |
-
10. http://yoursite.com/path/to/timthumb.php?src=http://markmaunder.com/&webshot=1
|
99 |
-
|
100 |
-
Notes on performance:
|
101 |
-
The first time a webshot loads, it will take a few seconds.
|
102 |
-
From then on it uses the regular timthumb caching mechanism with the configurable options above
|
103 |
-
and loading will be very fast.
|
104 |
-
|
105 |
-
--ADVANCED USERS ONLY--
|
106 |
-
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.
|
107 |
-
nohup Xvfb :100 -ac -nolisten tcp -screen 0, 1024x768x24 > /dev/null 2>&1 &
|
108 |
-
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.
|
109 |
-
You will need to take responsibility for keeping Xvfb running in case it crashes. (It seems pretty stable)
|
110 |
-
You will also need to take responsibility for server security if you're running Xvfb as root.
|
111 |
-
|
112 |
-
|
113 |
-
*/
|
114 |
-
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.
|
115 |
-
if(! defined('WEBSHOT_CUTYCAPT') ) define ('WEBSHOT_CUTYCAPT', '/usr/local/bin/CutyCapt'); //The path to CutyCapt.
|
116 |
-
if(! defined('WEBSHOT_XVFB') ) define ('WEBSHOT_XVFB', '/usr/bin/xvfb-run'); //The path to the Xvfb server
|
117 |
-
if(! defined('WEBSHOT_SCREEN_X') ) define ('WEBSHOT_SCREEN_X', '1024'); //1024 works ok
|
118 |
-
if(! defined('WEBSHOT_SCREEN_Y') ) define ('WEBSHOT_SCREEN_Y', '768'); //768 works ok
|
119 |
-
if(! defined('WEBSHOT_COLOR_DEPTH') ) define ('WEBSHOT_COLOR_DEPTH', '24'); //I haven't tested anything besides 24
|
120 |
-
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
|
121 |
-
if(! defined('WEBSHOT_TIMEOUT') ) define ('WEBSHOT_TIMEOUT', '20'); //Seconds to wait for a webshot
|
122 |
-
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
|
123 |
-
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.
|
124 |
-
if(! defined('WEBSHOT_JAVA_ON') ) define ('WEBSHOT_JAVA_ON', false); //Have only tested this as fase
|
125 |
-
if(! defined('WEBSHOT_PLUGINS_ON') ) define ('WEBSHOT_PLUGINS_ON', true); //Enable flash and other plugins
|
126 |
-
if(! defined('WEBSHOT_PROXY') ) define ('WEBSHOT_PROXY', ''); //In case you're behind a proxy server.
|
127 |
-
if(! defined('WEBSHOT_XVFB_RUNNING') ) define ('WEBSHOT_XVFB_RUNNING', false); //ADVANCED: Enable this if you've got Xvfb running in the background.
|
128 |
-
|
129 |
-
|
130 |
-
// 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.
|
131 |
-
if(! isset($ALLOWED_SITES)){
|
132 |
-
$ALLOWED_SITES = array (
|
133 |
-
'flickr.com',
|
134 |
-
'staticflickr.com',
|
135 |
-
'picasa.com',
|
136 |
-
'img.youtube.com',
|
137 |
-
'upload.wikimedia.org',
|
138 |
-
'photobucket.com',
|
139 |
-
'imgur.com',
|
140 |
-
'imageshack.us',
|
141 |
-
'tinypic.com',
|
142 |
-
);
|
143 |
-
}
|
144 |
-
// -------------------------------------------------------------
|
145 |
-
// -------------- STOP EDITING CONFIGURATION HERE --------------
|
146 |
-
// -------------------------------------------------------------
|
147 |
-
|
148 |
-
timthumb::start();
|
149 |
-
|
150 |
-
class timthumb {
|
151 |
-
protected $src = "";
|
152 |
-
protected $is404 = false;
|
153 |
-
protected $docRoot = "";
|
154 |
-
protected $lastURLError = false;
|
155 |
-
protected $localImage = "";
|
156 |
-
protected $localImageMTime = 0;
|
157 |
-
protected $url = false;
|
158 |
-
protected $myHost = "";
|
159 |
-
protected $isURL = false;
|
160 |
-
protected $cachefile = '';
|
161 |
-
protected $errors = array();
|
162 |
-
protected $toDeletes = array();
|
163 |
-
protected $cacheDirectory = '';
|
164 |
-
protected $startTime = 0;
|
165 |
-
protected $lastBenchTime = 0;
|
166 |
-
protected $cropTop = false;
|
167 |
-
protected $salt = "";
|
168 |
-
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.
|
169 |
-
protected $filePrependSecurityBlock = "<?php die('Execution denied!'); //"; //Designed to have three letter mime type, space, question mark and greater than symbol appended. 6 bytes total.
|
170 |
-
protected static $curlDataWritten = 0;
|
171 |
-
protected static $curlFH = false;
|
172 |
-
public static function start(){
|
173 |
-
$tim = new timthumb();
|
174 |
-
$tim->handleErrors();
|
175 |
-
$tim->securityChecks();
|
176 |
-
if($tim->tryBrowserCache()){
|
177 |
-
exit(0);
|
178 |
-
}
|
179 |
-
$tim->handleErrors();
|
180 |
-
if(FILE_CACHE_ENABLED && $tim->tryServerCache()){
|
181 |
-
exit(0);
|
182 |
-
}
|
183 |
-
$tim->handleErrors();
|
184 |
-
$tim->run();
|
185 |
-
$tim->handleErrors();
|
186 |
-
exit(0);
|
187 |
-
}
|
188 |
-
public function __construct(){
|
189 |
-
global $ALLOWED_SITES;
|
190 |
-
$this->startTime = microtime(true);
|
191 |
-
date_default_timezone_set('UTC');
|
192 |
-
$this->debug(1, "Starting new request from " . $this->getIP() . " to " . $_SERVER['REQUEST_URI']);
|
193 |
-
$this->calcDocRoot();
|
194 |
-
//On windows systems I'm assuming fileinode returns an empty string or a number that doesn't change. Check this.
|
195 |
-
$this->salt = @filemtime(__FILE__) . '-' . @fileinode(__FILE__);
|
196 |
-
$this->debug(3, "Salt is: " . $this->salt);
|
197 |
-
if(FILE_CACHE_DIRECTORY){
|
198 |
-
if(! is_dir(FILE_CACHE_DIRECTORY)){
|
199 |
-
@mkdir(FILE_CACHE_DIRECTORY);
|
200 |
-
if(! is_dir(FILE_CACHE_DIRECTORY)){
|
201 |
-
$this->error("Could not create the file cache directory.");
|
202 |
-
return false;
|
203 |
-
}
|
204 |
-
}
|
205 |
-
$this->cacheDirectory = FILE_CACHE_DIRECTORY;
|
206 |
-
if (!touch($this->cacheDirectory . '/index.html')) {
|
207 |
-
$this->error("Could not create the index.html file - to fix this create an empty file named index.html file in the cache directory.");
|
208 |
-
}
|
209 |
-
} else {
|
210 |
-
$this->cacheDirectory = sys_get_temp_dir();
|
211 |
-
}
|
212 |
-
//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.
|
213 |
-
$this->cleanCache();
|
214 |
-
|
215 |
-
$this->myHost = preg_replace('/^www\./i', '', $_SERVER['HTTP_HOST']);
|
216 |
-
$this->src = $this->param('src');
|
217 |
-
$this->url = parse_url($this->src);
|
218 |
-
$this->src = preg_replace('/https?:\/\/(?:www\.)?' . $this->myHost . '/i', '', $this->src);
|
219 |
-
|
220 |
-
if(strlen($this->src) <= 3){
|
221 |
-
$this->error("No image specified");
|
222 |
-
return false;
|
223 |
-
}
|
224 |
-
if(BLOCK_EXTERNAL_LEECHERS && array_key_exists('HTTP_REFERER', $_SERVER) && (! preg_match('/^https?:\/\/(?:www\.)?' . $this->myHost . '(?:$|\/)/i', $_SERVER['HTTP_REFERER']))){
|
225 |
-
// base64 encoded red image that says 'no hotlinkers'
|
226 |
-
// nothing to worry about! :)
|
227 |
-
$imgData = base64_decode("R0lGODlhUAAMAIAAAP8AAP///yH5BAAHAP8ALAAAAABQAAwAAAJpjI+py+0Po5y0OgAMjjv01YUZ\nOGplhWXfNa6JCLnWkXplrcBmW+spbwvaVr/cDyg7IoFC2KbYVC2NQ5MQ4ZNao9Ynzjl9ScNYpneb\nDULB3RP6JuPuaGfuuV4fumf8PuvqFyhYtjdoeFgAADs=");
|
228 |
-
header('Content-Type: image/gif');
|
229 |
-
header('Content-Length: ' . strlen($imgData));
|
230 |
-
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
231 |
-
header("Pragma: no-cache");
|
232 |
-
header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
|
233 |
-
echo $imgData;
|
234 |
-
return false;
|
235 |
-
exit(0);
|
236 |
-
}
|
237 |
-
if(preg_match('/^https?:\/\/[^\/]+/i', $this->src)){
|
238 |
-
$this->debug(2, "Is a request for an external URL: " . $this->src);
|
239 |
-
$this->isURL = true;
|
240 |
-
} else {
|
241 |
-
$this->debug(2, "Is a request for an internal file: " . $this->src);
|
242 |
-
}
|
243 |
-
if($this->isURL && (! ALLOW_EXTERNAL)){
|
244 |
-
$this->error("You are not allowed to fetch images from an external website.");
|
245 |
-
return false;
|
246 |
-
}
|
247 |
-
if($this->isURL){
|
248 |
-
if(ALLOW_ALL_EXTERNAL_SITES){
|
249 |
-
$this->debug(2, "Fetching from all external sites is enabled.");
|
250 |
-
} else {
|
251 |
-
$this->debug(2, "Fetching only from selected external sites is enabled.");
|
252 |
-
$allowed = false;
|
253 |
-
foreach($ALLOWED_SITES as $site){
|
254 |
-
if ((strtolower(substr($this->url['host'],-strlen($site)-1)) === strtolower(".$site")) || (strtolower($this->url['host'])===strtolower($site))) {
|
255 |
-
$this->debug(3, "URL hostname {$this->url['host']} matches $site so allowing.");
|
256 |
-
$allowed = true;
|
257 |
-
}
|
258 |
-
}
|
259 |
-
if(! $allowed){
|
260 |
-
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.");
|
261 |
-
}
|
262 |
-
}
|
263 |
-
}
|
264 |
-
|
265 |
-
$cachePrefix = ($this->isURL ? '_ext_' : '_int_');
|
266 |
-
if($this->isURL){
|
267 |
-
$arr = explode('&', $_SERVER ['QUERY_STRING']);
|
268 |
-
asort($arr);
|
269 |
-
$this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . implode('', $arr) . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
|
270 |
-
} else {
|
271 |
-
$this->localImage = $this->getLocalImagePath($this->src);
|
272 |
-
if(! $this->localImage){
|
273 |
-
$this->debug(1, "Could not find the local image: {$this->localImage}");
|
274 |
-
$this->error("Could not find the internal image you specified.");
|
275 |
-
$this->set404();
|
276 |
-
return false;
|
277 |
-
}
|
278 |
-
$this->debug(1, "Local image path is {$this->localImage}");
|
279 |
-
$this->localImageMTime = @filemtime($this->localImage);
|
280 |
-
//We include the mtime of the local file in case in changes on disk.
|
281 |
-
$this->cachefile = $this->cacheDirectory . '/' . FILE_CACHE_PREFIX . $cachePrefix . md5($this->salt . $this->localImageMTime . $_SERVER ['QUERY_STRING'] . $this->fileCacheVersion) . FILE_CACHE_SUFFIX;
|
282 |
-
}
|
283 |
-
$this->debug(2, "Cache file is: " . $this->cachefile);
|
284 |
-
|
285 |
-
return true;
|
286 |
-
}
|
287 |
-
public function __destruct(){
|
288 |
-
foreach($this->toDeletes as $del){
|
289 |
-
$this->debug(2, "Deleting temp file $del");
|
290 |
-
@unlink($del);
|
291 |
-
}
|
292 |
-
}
|
293 |
-
public function run(){
|
294 |
-
if($this->isURL){
|
295 |
-
if(! ALLOW_EXTERNAL){
|
296 |
-
$this->debug(1, "Got a request for an external image but ALLOW_EXTERNAL is disabled so returning error msg.");
|
297 |
-
$this->error("You are not allowed to fetch images from an external website.");
|
298 |
-
return false;
|
299 |
-
}
|
300 |
-
$this->debug(3, "Got request for external image. Starting serveExternalImage.");
|
301 |
-
if($this->param('webshot')){
|
302 |
-
if(WEBSHOT_ENABLED){
|
303 |
-
$this->debug(3, "webshot param is set, so we're going to take a webshot.");
|
304 |
-
$this->serveWebshot();
|
305 |
-
} else {
|
306 |
-
$this->error("You added the webshot parameter but webshots are disabled on this server. You need to set WEBSHOT_ENABLED == true to enable webshots.");
|
307 |
-
}
|
308 |
-
} else {
|
309 |
-
$this->debug(3, "webshot is NOT set so we're going to try to fetch a regular image.");
|
310 |
-
$this->serveExternalImage();
|
311 |
-
|
312 |
-
}
|
313 |
-
} else {
|
314 |
-
$this->debug(3, "Got request for internal image. Starting serveInternalImage()");
|
315 |
-
$this->serveInternalImage();
|
316 |
-
}
|
317 |
-
return true;
|
318 |
-
}
|
319 |
-
protected function handleErrors(){
|
320 |
-
if($this->haveErrors()){
|
321 |
-
if(NOT_FOUND_IMAGE && $this->is404()){
|
322 |
-
if($this->serveImg(NOT_FOUND_IMAGE)){
|
323 |
-
exit(0);
|
324 |
-
} else {
|
325 |
-
$this->error("Additionally, the 404 image that is configured could not be found or there was an error serving it.");
|
326 |
-
}
|
327 |
-
}
|
328 |
-
if(ERROR_IMAGE){
|
329 |
-
if($this->serveImg(ERROR_IMAGE)){
|
330 |
-
exit(0);
|
331 |
-
} else {
|
332 |
-
$this->error("Additionally, the error image that is configured could not be found or there was an error serving it.");
|
333 |
-
}
|
334 |
-
}
|
335 |
-
$this->serveErrors();
|
336 |
-
exit(0);
|
337 |
-
}
|
338 |
-
return false;
|
339 |
-
}
|
340 |
-
protected function tryBrowserCache(){
|
341 |
-
if(BROWSER_CACHE_DISABLE){ $this->debug(3, "Browser caching is disabled"); return false; }
|
342 |
-
if(!empty($_SERVER['HTTP_IF_MODIFIED_SINCE']) ){
|
343 |
-
$this->debug(3, "Got a conditional get");
|
344 |
-
$mtime = false;
|
345 |
-
//We've already checked if the real file exists in the constructor
|
346 |
-
if(! is_file($this->cachefile)){
|
347 |
-
//If we don't have something cached, regenerate the cached image.
|
348 |
-
return false;
|
349 |
-
}
|
350 |
-
if($this->localImageMTime){
|
351 |
-
$mtime = $this->localImageMTime;
|
352 |
-
$this->debug(3, "Local real file's modification time is $mtime");
|
353 |
-
} 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
|
354 |
-
$mtime = @filemtime($this->cachefile);
|
355 |
-
$this->debug(3, "Cached file's modification time is $mtime");
|
356 |
-
}
|
357 |
-
if(! $mtime){ return false; }
|
358 |
-
|
359 |
-
$iftime = strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
360 |
-
$this->debug(3, "The conditional get's if-modified-since unixtime is $iftime");
|
361 |
-
if($iftime < 1){
|
362 |
-
$this->debug(3, "Got an invalid conditional get modified since time. Returning false.");
|
363 |
-
return false;
|
364 |
-
}
|
365 |
-
if($iftime < $mtime){ //Real file or cache file has been modified since last request, so force refetch.
|
366 |
-
$this->debug(3, "File has been modified since last fetch.");
|
367 |
-
return false;
|
368 |
-
} else { //Otherwise serve a 304
|
369 |
-
$this->debug(3, "File has not been modified since last get, so serving a 304.");
|
370 |
-
header ($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
|
371 |
-
$this->debug(1, "Returning 304 not modified");
|
372 |
-
return true;
|
373 |
-
}
|
374 |
-
}
|
375 |
-
return false;
|
376 |
-
}
|
377 |
-
protected function tryServerCache(){
|
378 |
-
$this->debug(3, "Trying server cache");
|
379 |
-
if(file_exists($this->cachefile)){
|
380 |
-
$this->debug(3, "Cachefile {$this->cachefile} exists");
|
381 |
-
if($this->isURL){
|
382 |
-
$this->debug(3, "This is an external request, so checking if the cachefile is empty which means the request failed previously.");
|
383 |
-
if(filesize($this->cachefile) < 1){
|
384 |
-
$this->debug(3, "Found an empty cachefile indicating a failed earlier request. Checking how old it is.");
|
385 |
-
//Fetching error occured previously
|
386 |
-
if(time() - @filemtime($this->cachefile) > WAIT_BETWEEN_FETCH_ERRORS){
|
387 |
-
$this->debug(3, "File is older than " . WAIT_BETWEEN_FETCH_ERRORS . " seconds. Deleting and returning false so app can try and load file.");
|
388 |
-
@unlink($this->cachefile);
|
389 |
-
return false; //to indicate we didn't serve from cache and app should try and load
|
390 |
-
} else {
|
391 |
-
$this->debug(3, "Empty cachefile is still fresh so returning message saying we had an error fetching this image from remote host.");
|
392 |
-
$this->set404();
|
393 |
-
$this->error("An error occured fetching image.");
|
394 |
-
return false;
|
395 |
-
}
|
396 |
-
}
|
397 |
-
} else {
|
398 |
-
$this->debug(3, "Trying to serve cachefile {$this->cachefile}");
|
399 |
-
}
|
400 |
-
if($this->serveCacheFile()){
|
401 |
-
$this->debug(3, "Succesfully served cachefile {$this->cachefile}");
|
402 |
-
return true;
|
403 |
-
} else {
|
404 |
-
$this->debug(3, "Failed to serve cachefile {$this->cachefile} - Deleting it from cache.");
|
405 |
-
//Image serving failed. We can't retry at this point, but lets remove it from cache so the next request recreates it
|
406 |
-
@unlink($this->cachefile);
|
407 |
-
return true;
|
408 |
-
}
|
409 |
-
}
|
410 |
-
}
|
411 |
-
protected function error($err){
|
412 |
-
$this->debug(3, "Adding error message: $err");
|
413 |
-
$this->errors[] = $err;
|
414 |
-
return false;
|
415 |
-
|
416 |
-
}
|
417 |
-
protected function haveErrors(){
|
418 |
-
if(sizeof($this->errors) > 0){
|
419 |
-
return true;
|
420 |
-
}
|
421 |
-
return false;
|
422 |
-
}
|
423 |
-
protected function serveErrors(){
|
424 |
-
header ($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
425 |
-
if ( ! DISPLAY_ERROR_MESSAGES ) {
|
426 |
-
return;
|
427 |
-
}
|
428 |
-
$html = '<ul>';
|
429 |
-
foreach($this->errors as $err){
|
430 |
-
$html .= '<li>' . htmlentities($err) . '</li>';
|
431 |
-
}
|
432 |
-
$html .= '</ul>';
|
433 |
-
echo '<h1>A TimThumb error has occured</h1>The following error(s) occured:<br />' . $html . '<br />';
|
434 |
-
echo '<br />Query String : ' . htmlentities( $_SERVER['QUERY_STRING'], ENT_QUOTES );
|
435 |
-
echo '<br />TimThumb version : ' . VERSION . '</pre>';
|
436 |
-
}
|
437 |
-
protected function serveInternalImage(){
|
438 |
-
$this->debug(3, "Local image path is $this->localImage");
|
439 |
-
if(! $this->localImage){
|
440 |
-
$this->sanityFail("localImage not set after verifying it earlier in the code.");
|
441 |
-
return false;
|
442 |
-
}
|
443 |
-
$fileSize = filesize($this->localImage);
|
444 |
-
if($fileSize > MAX_FILE_SIZE){
|
445 |
-
$this->error("The file you specified is greater than the maximum allowed file size.");
|
446 |
-
return false;
|
447 |
-
}
|
448 |
-
if($fileSize <= 0){
|
449 |
-
$this->error("The file you specified is <= 0 bytes.");
|
450 |
-
return false;
|
451 |
-
}
|
452 |
-
$this->debug(3, "Calling processImageAndWriteToCache() for local image.");
|
453 |
-
if($this->processImageAndWriteToCache($this->localImage)){
|
454 |
-
$this->serveCacheFile();
|
455 |
-
return true;
|
456 |
-
} else {
|
457 |
-
return false;
|
458 |
-
}
|
459 |
-
}
|
460 |
-
protected function cleanCache(){
|
461 |
-
if (FILE_CACHE_TIME_BETWEEN_CLEANS < 0) {
|
462 |
-
return;
|
463 |
-
}
|
464 |
-
$this->debug(3, "cleanCache() called");
|
465 |
-
$lastCleanFile = $this->cacheDirectory . '/timthumb_cacheLastCleanTime.touch';
|
466 |
-
|
467 |
-
//If this is a new timthumb installation we need to create the file
|
468 |
-
if(! is_file($lastCleanFile)){
|
469 |
-
$this->debug(1, "File tracking last clean doesn't exist. Creating $lastCleanFile");
|
470 |
-
if (!touch($lastCleanFile)) {
|
471 |
-
$this->error("Could not create cache clean timestamp file.");
|
472 |
-
}
|
473 |
-
return;
|
474 |
-
}
|
475 |
-
if(@filemtime($lastCleanFile) < (time() - FILE_CACHE_TIME_BETWEEN_CLEANS) ){ //Cache was last cleaned more than 1 day ago
|
476 |
-
$this->debug(1, "Cache was last cleaned more than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago. Cleaning now.");
|
477 |
-
// Very slight race condition here, but worst case we'll have 2 or 3 servers cleaning the cache simultaneously once a day.
|
478 |
-
if (!touch($lastCleanFile)) {
|
479 |
-
$this->error("Could not create cache clean timestamp file.");
|
480 |
-
}
|
481 |
-
$files = glob($this->cacheDirectory . '/*' . FILE_CACHE_SUFFIX);
|
482 |
-
if ($files) {
|
483 |
-
$timeAgo = time() - FILE_CACHE_MAX_FILE_AGE;
|
484 |
-
foreach($files as $file){
|
485 |
-
if(@filemtime($file) < $timeAgo){
|
486 |
-
$this->debug(3, "Deleting cache file $file older than max age: " . FILE_CACHE_MAX_FILE_AGE . " seconds");
|
487 |
-
@unlink($file);
|
488 |
-
}
|
489 |
-
}
|
490 |
-
}
|
491 |
-
return true;
|
492 |
-
} else {
|
493 |
-
$this->debug(3, "Cache was cleaned less than " . FILE_CACHE_TIME_BETWEEN_CLEANS . " seconds ago so no cleaning needed.");
|
494 |
-
}
|
495 |
-
return false;
|
496 |
-
}
|
497 |
-
protected function processImageAndWriteToCache($localImage){
|
498 |
-
$sData = getimagesize($localImage);
|
499 |
-
$origType = $sData[2];
|
500 |
-
$mimeType = $sData['mime'];
|
501 |
-
|
502 |
-
$this->debug(3, "Mime type of image is $mimeType");
|
503 |
-
if(! preg_match('/^image\/(?:gif|jpg|jpeg|png)$/i', $mimeType)){
|
504 |
-
return $this->error("The image being resized is not a valid gif, jpg or png.");
|
505 |
-
}
|
506 |
-
|
507 |
-
if (!function_exists ('imagecreatetruecolor')) {
|
508 |
-
return $this->error('GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library');
|
509 |
-
}
|
510 |
-
|
511 |
-
if (function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
|
512 |
-
$imageFilters = array (
|
513 |
-
1 => array (IMG_FILTER_NEGATE, 0),
|
514 |
-
2 => array (IMG_FILTER_GRAYSCALE, 0),
|
515 |
-
3 => array (IMG_FILTER_BRIGHTNESS, 1),
|
516 |
-
4 => array (IMG_FILTER_CONTRAST, 1),
|
517 |
-
5 => array (IMG_FILTER_COLORIZE, 4),
|
518 |
-
6 => array (IMG_FILTER_EDGEDETECT, 0),
|
519 |
-
7 => array (IMG_FILTER_EMBOSS, 0),
|
520 |
-
8 => array (IMG_FILTER_GAUSSIAN_BLUR, 0),
|
521 |
-
9 => array (IMG_FILTER_SELECTIVE_BLUR, 0),
|
522 |
-
10 => array (IMG_FILTER_MEAN_REMOVAL, 0),
|
523 |
-
11 => array (IMG_FILTER_SMOOTH, 0),
|
524 |
-
);
|
525 |
-
}
|
526 |
-
|
527 |
-
// get standard input properties
|
528 |
-
$new_width = (int) abs ($this->param('w', 0));
|
529 |
-
$new_height = (int) abs ($this->param('h', 0));
|
530 |
-
$zoom_crop = (int) $this->param('zc', DEFAULT_ZC);
|
531 |
-
$quality = (int) abs ($this->param('q', DEFAULT_Q));
|
532 |
-
$align = $this->cropTop ? 't' : $this->param('a', 'c');
|
533 |
-
$filters = $this->param('f', DEFAULT_F);
|
534 |
-
$sharpen = (bool) $this->param('s', DEFAULT_S);
|
535 |
-
$canvas_color = $this->param('cc', DEFAULT_CC);
|
536 |
-
$canvas_trans = (bool) $this->param('ct', '1');
|
537 |
-
|
538 |
-
// set default width and height if neither are set already
|
539 |
-
if ($new_width == 0 && $new_height == 0) {
|
540 |
-
$new_width = (int) DEFAULT_WIDTH;
|
541 |
-
$new_height = (int) DEFAULT_HEIGHT;
|
542 |
-
}
|
543 |
-
|
544 |
-
// ensure size limits can not be abused
|
545 |
-
$new_width = min ($new_width, MAX_WIDTH);
|
546 |
-
$new_height = min ($new_height, MAX_HEIGHT);
|
547 |
-
|
548 |
-
// set memory limit to be able to have enough space to resize larger images
|
549 |
-
$this->setMemoryLimit();
|
550 |
-
|
551 |
-
// open the existing image
|
552 |
-
$image = $this->openImage ($mimeType, $localImage);
|
553 |
-
if ($image === false) {
|
554 |
-
return $this->error('Unable to open image.');
|
555 |
-
}
|
556 |
-
|
557 |
-
// Get original width and height
|
558 |
-
$width = imagesx ($image);
|
559 |
-
$height = imagesy ($image);
|
560 |
-
$origin_x = 0;
|
561 |
-
$origin_y = 0;
|
562 |
-
|
563 |
-
// generate new w/h if not provided
|
564 |
-
if ($new_width && !$new_height) {
|
565 |
-
$new_height = floor ($height * ($new_width / $width));
|
566 |
-
} else if ($new_height && !$new_width) {
|
567 |
-
$new_width = floor ($width * ($new_height / $height));
|
568 |
-
}
|
569 |
-
|
570 |
-
// scale down and add borders
|
571 |
-
if ($zoom_crop == 3) {
|
572 |
-
|
573 |
-
$final_height = $height * ($new_width / $width);
|
574 |
-
|
575 |
-
if ($final_height > $new_height) {
|
576 |
-
$new_width = $width * ($new_height / $height);
|
577 |
-
} else {
|
578 |
-
$new_height = $final_height;
|
579 |
-
}
|
580 |
-
|
581 |
-
}
|
582 |
-
|
583 |
-
// create a new true color image
|
584 |
-
$canvas = imagecreatetruecolor ($new_width, $new_height);
|
585 |
-
imagealphablending ($canvas, false);
|
586 |
-
|
587 |
-
if (strlen($canvas_color) == 3) { //if is 3-char notation, edit string into 6-char notation
|
588 |
-
$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);
|
589 |
-
} else if (strlen($canvas_color) != 6) {
|
590 |
-
$canvas_color = DEFAULT_CC; // on error return default canvas color
|
591 |
-
}
|
592 |
-
|
593 |
-
$canvas_color_R = hexdec (substr ($canvas_color, 0, 2));
|
594 |
-
$canvas_color_G = hexdec (substr ($canvas_color, 2, 2));
|
595 |
-
$canvas_color_B = hexdec (substr ($canvas_color, 4, 2));
|
596 |
-
|
597 |
-
// Create a new transparent color for image
|
598 |
-
// If is a png and PNG_IS_TRANSPARENT is false then remove the alpha transparency
|
599 |
-
// (and if is set a canvas color show it in the background)
|
600 |
-
if(preg_match('/^image\/png$/i', $mimeType) && !PNG_IS_TRANSPARENT && $canvas_trans){
|
601 |
-
$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 127);
|
602 |
-
}else{
|
603 |
-
$color = imagecolorallocatealpha ($canvas, $canvas_color_R, $canvas_color_G, $canvas_color_B, 0);
|
604 |
-
}
|
605 |
-
|
606 |
-
|
607 |
-
// Completely fill the background of the new image with allocated color.
|
608 |
-
imagefill ($canvas, 0, 0, $color);
|
609 |
-
|
610 |
-
// scale down and add borders
|
611 |
-
if ($zoom_crop == 2) {
|
612 |
-
|
613 |
-
$final_height = $height * ($new_width / $width);
|
614 |
-
|
615 |
-
if ($final_height > $new_height) {
|
616 |
-
|
617 |
-
$origin_x = $new_width / 2;
|
618 |
-
$new_width = $width * ($new_height / $height);
|
619 |
-
$origin_x = round ($origin_x - ($new_width / 2));
|
620 |
-
|
621 |
-
} else {
|
622 |
-
|
623 |
-
$origin_y = $new_height / 2;
|
624 |
-
$new_height = $final_height;
|
625 |
-
$origin_y = round ($origin_y - ($new_height / 2));
|
626 |
-
|
627 |
-
}
|
628 |
-
|
629 |
-
}
|
630 |
-
|
631 |
-
// Restore transparency blending
|
632 |
-
imagesavealpha ($canvas, true);
|
633 |
-
|
634 |
-
if ($zoom_crop > 0) {
|
635 |
-
|
636 |
-
$src_x = $src_y = 0;
|
637 |
-
$src_w = $width;
|
638 |
-
$src_h = $height;
|
639 |
-
|
640 |
-
$cmp_x = $width / $new_width;
|
641 |
-
$cmp_y = $height / $new_height;
|
642 |
-
|
643 |
-
// calculate x or y coordinate and width or height of source
|
644 |
-
if ($cmp_x > $cmp_y) {
|
645 |
-
|
646 |
-
$src_w = round ($width / $cmp_x * $cmp_y);
|
647 |
-
$src_x = round (($width - ($width / $cmp_x * $cmp_y)) / 2);
|
648 |
-
|
649 |
-
} else if ($cmp_y > $cmp_x) {
|
650 |
-
|
651 |
-
$src_h = round ($height / $cmp_y * $cmp_x);
|
652 |
-
$src_y = round (($height - ($height / $cmp_y * $cmp_x)) / 2);
|
653 |
-
|
654 |
-
}
|
655 |
-
|
656 |
-
// positional cropping!
|
657 |
-
if ($align) {
|
658 |
-
if (strpos ($align, 't') !== false) {
|
659 |
-
$src_y = 0;
|
660 |
-
}
|
661 |
-
if (strpos ($align, 'b') !== false) {
|
662 |
-
$src_y = $height - $src_h;
|
663 |
-
}
|
664 |
-
if (strpos ($align, 'l') !== false) {
|
665 |
-
$src_x = 0;
|
666 |
-
}
|
667 |
-
if (strpos ($align, 'r') !== false) {
|
668 |
-
$src_x = $width - $src_w;
|
669 |
-
}
|
670 |
-
}
|
671 |
-
|
672 |
-
imagecopyresampled ($canvas, $image, $origin_x, $origin_y, $src_x, $src_y, $new_width, $new_height, $src_w, $src_h);
|
673 |
-
|
674 |
-
} else {
|
675 |
-
|
676 |
-
// copy and resize part of an image with resampling
|
677 |
-
imagecopyresampled ($canvas, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
|
678 |
-
|
679 |
-
}
|
680 |
-
|
681 |
-
if ($filters != '' && function_exists ('imagefilter') && defined ('IMG_FILTER_NEGATE')) {
|
682 |
-
// apply filters to image
|
683 |
-
$filterList = explode ('|', $filters);
|
684 |
-
foreach ($filterList as $fl) {
|
685 |
-
|
686 |
-
$filterSettings = explode (',', $fl);
|
687 |
-
if (isset ($imageFilters[$filterSettings[0]])) {
|
688 |
-
|
689 |
-
for ($i = 0; $i < 4; $i ++) {
|
690 |
-
if (!isset ($filterSettings[$i])) {
|
691 |
-
$filterSettings[$i] = null;
|
692 |
-
} else {
|
693 |
-
$filterSettings[$i] = (int) $filterSettings[$i];
|
694 |
-
}
|
695 |
-
}
|
696 |
-
|
697 |
-
switch ($imageFilters[$filterSettings[0]][1]) {
|
698 |
-
|
699 |
-
case 1:
|
700 |
-
|
701 |
-
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1]);
|
702 |
-
break;
|
703 |
-
|
704 |
-
case 2:
|
705 |
-
|
706 |
-
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2]);
|
707 |
-
break;
|
708 |
-
|
709 |
-
case 3:
|
710 |
-
|
711 |
-
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3]);
|
712 |
-
break;
|
713 |
-
|
714 |
-
case 4:
|
715 |
-
|
716 |
-
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0], $filterSettings[1], $filterSettings[2], $filterSettings[3], $filterSettings[4]);
|
717 |
-
break;
|
718 |
-
|
719 |
-
default:
|
720 |
-
|
721 |
-
imagefilter ($canvas, $imageFilters[$filterSettings[0]][0]);
|
722 |
-
break;
|
723 |
-
|
724 |
-
}
|
725 |
-
}
|
726 |
-
}
|
727 |
-
}
|
728 |
-
|
729 |
-
// sharpen image
|
730 |
-
if ($sharpen && function_exists ('imageconvolution')) {
|
731 |
-
|
732 |
-
$sharpenMatrix = array (
|
733 |
-
array (-1,-1,-1),
|
734 |
-
array (-1,16,-1),
|
735 |
-
array (-1,-1,-1),
|
736 |
-
);
|
737 |
-
|
738 |
-
$divisor = 8;
|
739 |
-
$offset = 0;
|
740 |
-
|
741 |
-
imageconvolution ($canvas, $sharpenMatrix, $divisor, $offset);
|
742 |
-
|
743 |
-
}
|
744 |
-
//Straight from Wordpress core code. Reduces filesize by up to 70% for PNG's
|
745 |
-
if ( (IMAGETYPE_PNG == $origType || IMAGETYPE_GIF == $origType) && function_exists('imageistruecolor') && !imageistruecolor( $image ) && imagecolortransparent( $image ) > 0 ){
|
746 |
-
imagetruecolortopalette( $canvas, false, imagecolorstotal( $image ) );
|
747 |
-
}
|
748 |
-
|
749 |
-
$imgType = "";
|
750 |
-
$tempfile = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
751 |
-
if(preg_match('/^image\/(?:jpg|jpeg)$/i', $mimeType)){
|
752 |
-
$imgType = 'jpg';
|
753 |
-
imagejpeg($canvas, $tempfile, $quality);
|
754 |
-
} else if(preg_match('/^image\/png$/i', $mimeType)){
|
755 |
-
$imgType = 'png';
|
756 |
-
imagepng($canvas, $tempfile, floor($quality * 0.09));
|
757 |
-
} else if(preg_match('/^image\/gif$/i', $mimeType)){
|
758 |
-
$imgType = 'gif';
|
759 |
-
imagegif($canvas, $tempfile);
|
760 |
-
} else {
|
761 |
-
return $this->sanityFail("Could not match mime type after verifying it previously.");
|
762 |
-
}
|
763 |
-
|
764 |
-
if($imgType == 'png' && OPTIPNG_ENABLED && OPTIPNG_PATH && @is_file(OPTIPNG_PATH)){
|
765 |
-
$exec = OPTIPNG_PATH;
|
766 |
-
$this->debug(3, "optipng'ing $tempfile");
|
767 |
-
$presize = filesize($tempfile);
|
768 |
-
$out = `$exec -o1 $tempfile`; //you can use up to -o7 but it really slows things down
|
769 |
-
clearstatcache();
|
770 |
-
$aftersize = filesize($tempfile);
|
771 |
-
$sizeDrop = $presize - $aftersize;
|
772 |
-
if($sizeDrop > 0){
|
773 |
-
$this->debug(1, "optipng reduced size by $sizeDrop");
|
774 |
-
} else if($sizeDrop < 0){
|
775 |
-
$this->debug(1, "optipng increased size! Difference was: $sizeDrop");
|
776 |
-
} else {
|
777 |
-
$this->debug(1, "optipng did not change image size.");
|
778 |
-
}
|
779 |
-
} else if($imgType == 'png' && PNGCRUSH_ENABLED && PNGCRUSH_PATH && @is_file(PNGCRUSH_PATH)){
|
780 |
-
$exec = PNGCRUSH_PATH;
|
781 |
-
$tempfile2 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
782 |
-
$this->debug(3, "pngcrush'ing $tempfile to $tempfile2");
|
783 |
-
$out = `$exec $tempfile $tempfile2`;
|
784 |
-
$todel = "";
|
785 |
-
if(is_file($tempfile2)){
|
786 |
-
$sizeDrop = filesize($tempfile) - filesize($tempfile2);
|
787 |
-
if($sizeDrop > 0){
|
788 |
-
$this->debug(1, "pngcrush was succesful and gave a $sizeDrop byte size reduction");
|
789 |
-
$todel = $tempfile;
|
790 |
-
$tempfile = $tempfile2;
|
791 |
-
} else {
|
792 |
-
$this->debug(1, "pngcrush did not reduce file size. Difference was $sizeDrop bytes.");
|
793 |
-
$todel = $tempfile2;
|
794 |
-
}
|
795 |
-
} else {
|
796 |
-
$this->debug(3, "pngcrush failed with output: $out");
|
797 |
-
$todel = $tempfile2;
|
798 |
-
}
|
799 |
-
@unlink($todel);
|
800 |
-
}
|
801 |
-
|
802 |
-
$this->debug(3, "Rewriting image with security header.");
|
803 |
-
$tempfile4 = tempnam($this->cacheDirectory, 'timthumb_tmpimg_');
|
804 |
-
$context = stream_context_create ();
|
805 |
-
$fp = fopen($tempfile,'r',0,$context);
|
806 |
-
file_put_contents($tempfile4, $this->filePrependSecurityBlock . $imgType . ' ?' . '>'); //6 extra bytes, first 3 being image type
|
807 |
-
file_put_contents($tempfile4, $fp, FILE_APPEND);
|
808 |
-
fclose($fp);
|
809 |
-
@unlink($tempfile);
|
810 |
-
$this->debug(3, "Locking and replacing cache file.");
|
811 |
-
$lockFile = $this->cachefile . '.lock';
|
812 |
-
$fh = fopen($lockFile, 'w');
|
813 |
-
if(! $fh){
|
814 |
-
return $this->error("Could not open the lockfile for writing an image.");
|
815 |
-
}
|
816 |
-
if(flock($fh, LOCK_EX)){
|
817 |
-
@unlink($this->cachefile); //rename generally overwrites, but doing this in case of platform specific quirks. File might not exist yet.
|
818 |
-
rename($tempfile4, $this->cachefile);
|
819 |
-
flock($fh, LOCK_UN);
|
820 |
-
fclose($fh);
|
821 |
-
@unlink($lockFile);
|
822 |
-
} else {
|
823 |
-
fclose($fh);
|
824 |
-
@unlink($lockFile);
|
825 |
-
@unlink($tempfile4);
|
826 |
-
return $this->error("Could not get a lock for writing.");
|
827 |
-
}
|
828 |
-
$this->debug(3, "Done image replace with security header. Cleaning up and running cleanCache()");
|
829 |
-
imagedestroy($canvas);
|
830 |
-
imagedestroy($image);
|
831 |
-
return true;
|
832 |
-
}
|
833 |
-
protected function calcDocRoot(){
|
834 |
-
$docRoot = @$_SERVER['DOCUMENT_ROOT'];
|
835 |
-
if (defined('LOCAL_FILE_BASE_DIRECTORY')) {
|
836 |
-
$docRoot = LOCAL_FILE_BASE_DIRECTORY;
|
837 |
-
}
|
838 |
-
if(!isset($docRoot)){
|
839 |
-
$this->debug(3, "DOCUMENT_ROOT is not set. This is probably windows. Starting search 1.");
|
840 |
-
if(isset($_SERVER['SCRIPT_FILENAME'])){
|
841 |
-
$docRoot = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
|
842 |
-
$this->debug(3, "Generated docRoot using SCRIPT_FILENAME and PHP_SELF as: $docRoot");
|
843 |
-
}
|
844 |
-
}
|
845 |
-
if(!isset($docRoot)){
|
846 |
-
$this->debug(3, "DOCUMENT_ROOT still is not set. Starting search 2.");
|
847 |
-
if(isset($_SERVER['PATH_TRANSLATED'])){
|
848 |
-
$docRoot = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
|
849 |
-
$this->debug(3, "Generated docRoot using PATH_TRANSLATED and PHP_SELF as: $docRoot");
|
850 |
-
}
|
851 |
-
}
|
852 |
-
if($docRoot && $_SERVER['DOCUMENT_ROOT'] != '/'){ $docRoot = preg_replace('/\/$/', '', $docRoot); }
|
853 |
-
$this->debug(3, "Doc root is: " . $docRoot);
|
854 |
-
$this->docRoot = $docRoot;
|
855 |
-
|
856 |
-
}
|
857 |
-
protected function getLocalImagePath($src){
|
858 |
-
$src = ltrim($src, '/'); //strip off the leading '/'
|
859 |
-
if(! $this->docRoot){
|
860 |
-
$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.");
|
861 |
-
//We don't support serving images outside the current dir if we don't have a doc root for security reasons.
|
862 |
-
$file = preg_replace('/^.*?([^\/\\\\]+)$/', '$1', $src); //strip off any path info and just leave the filename.
|
863 |
-
if(is_file($file)){
|
864 |
-
return $this->realpath($file);
|
865 |
-
}
|
866 |
-
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.");
|
867 |
-
} else if ( ! is_dir( $this->docRoot ) ) {
|
868 |
-
$this->error("Server path does not exist. Ensure variable \$_SERVER['DOCUMENT_ROOT'] is set correctly");
|
869 |
-
}
|
870 |
-
|
871 |
-
//Do not go past this point without docRoot set
|
872 |
-
|
873 |
-
//Try src under docRoot
|
874 |
-
if(file_exists ($this->docRoot . '/' . $src)) {
|
875 |
-
$this->debug(3, "Found file as " . $this->docRoot . '/' . $src);
|
876 |
-
$real = $this->realpath($this->docRoot . '/' . $src);
|
877 |
-
if(stripos($real, $this->docRoot) === 0){
|
878 |
-
return $real;
|
879 |
-
} else {
|
880 |
-
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
881 |
-
//allow search to continue
|
882 |
-
}
|
883 |
-
}
|
884 |
-
//Check absolute paths and then verify the real path is under doc root
|
885 |
-
$absolute = $this->realpath('/' . $src);
|
886 |
-
if($absolute && file_exists($absolute)){ //realpath does file_exists check, so can probably skip the exists check here
|
887 |
-
$this->debug(3, "Found absolute path: $absolute");
|
888 |
-
if(! $this->docRoot){ $this->sanityFail("docRoot not set when checking absolute path."); }
|
889 |
-
if(stripos($absolute, $this->docRoot) === 0){
|
890 |
-
return $absolute;
|
891 |
-
} else {
|
892 |
-
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
893 |
-
//and continue search
|
894 |
-
}
|
895 |
-
}
|
896 |
-
|
897 |
-
$base = $this->docRoot;
|
898 |
-
|
899 |
-
// account for Windows directory structure
|
900 |
-
if (strstr($_SERVER['SCRIPT_FILENAME'],':')) {
|
901 |
-
$sub_directories = explode('\\', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
|
902 |
-
} else {
|
903 |
-
$sub_directories = explode('/', str_replace($this->docRoot, '', $_SERVER['SCRIPT_FILENAME']));
|
904 |
-
}
|
905 |
-
|
906 |
-
foreach ($sub_directories as $sub){
|
907 |
-
$base .= $sub . '/';
|
908 |
-
$this->debug(3, "Trying file as: " . $base . $src);
|
909 |
-
if(file_exists($base . $src)){
|
910 |
-
$this->debug(3, "Found file as: " . $base . $src);
|
911 |
-
$real = $this->realpath($base . $src);
|
912 |
-
if(stripos($real, $this->realpath($this->docRoot)) === 0){
|
913 |
-
return $real;
|
914 |
-
} else {
|
915 |
-
$this->debug(1, "Security block: The file specified occurs outside the document root.");
|
916 |
-
//And continue search
|
917 |
-
}
|
918 |
-
}
|
919 |
-
}
|
920 |
-
return false;
|
921 |
-
}
|
922 |
-
protected function realpath($path){
|
923 |
-
//try to remove any relative paths
|
924 |
-
$remove_relatives = '/\w+\/\.\.\//';
|
925 |
-
while(preg_match($remove_relatives,$path)){
|
926 |
-
$path = preg_replace($remove_relatives, '', $path);
|
927 |
-
}
|
928 |
-
//if any remain use PHP realpath to strip them out, otherwise return $path
|
929 |
-
//if using realpath, any symlinks will also be resolved
|
930 |
-
return preg_match('#^\.\./|/\.\./#', $path) ? realpath($path) : $path;
|
931 |
-
}
|
932 |
-
protected function toDelete($name){
|
933 |
-
$this->debug(3, "Scheduling file $name to delete on destruct.");
|
934 |
-
$this->toDeletes[] = $name;
|
935 |
-
}
|
936 |
-
protected function serveWebshot(){
|
937 |
-
$this->debug(3, "Starting serveWebshot");
|
938 |
-
$instr = "Please follow the instructions at http://code.google.com/p/timthumb/ to set your server up for taking website screenshots.";
|
939 |
-
if(! is_file(WEBSHOT_CUTYCAPT)){
|
940 |
-
return $this->error("CutyCapt is not installed. $instr");
|
941 |
-
}
|
942 |
-
if(! is_file(WEBSHOT_XVFB)){
|
943 |
-
return $this->Error("Xvfb is not installed. $instr");
|
944 |
-
}
|
945 |
-
$cuty = WEBSHOT_CUTYCAPT;
|
946 |
-
$xv = WEBSHOT_XVFB;
|
947 |
-
$screenX = WEBSHOT_SCREEN_X;
|
948 |
-
$screenY = WEBSHOT_SCREEN_Y;
|
949 |
-
$colDepth = WEBSHOT_COLOR_DEPTH;
|
950 |
-
$format = WEBSHOT_IMAGE_FORMAT;
|
951 |
-
$timeout = WEBSHOT_TIMEOUT * 1000;
|
952 |
-
$ua = WEBSHOT_USER_AGENT;
|
953 |
-
$jsOn = WEBSHOT_JAVASCRIPT_ON ? 'on' : 'off';
|
954 |
-
$javaOn = WEBSHOT_JAVA_ON ? 'on' : 'off';
|
955 |
-
$pluginsOn = WEBSHOT_PLUGINS_ON ? 'on' : 'off';
|
956 |
-
$proxy = WEBSHOT_PROXY ? ' --http-proxy=' . WEBSHOT_PROXY : '';
|
957 |
-
$tempfile = tempnam($this->cacheDirectory, 'timthumb_webshot');
|
958 |
-
$url = $this->src;
|
959 |
-
if(! preg_match('/^https?:\/\/[a-zA-Z0-9\.\-]+/i', $url)){
|
960 |
-
return $this->error("Invalid URL supplied.");
|
961 |
-
}
|
962 |
-
$url = preg_replace('/[^A-Za-z0-9\-\.\_\~:\/\?\#\[\]\@\!\$\&\'\(\)\*\+\,\;\=]+/', '', $url); //RFC 3986
|
963 |
-
//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
|
964 |
-
// which AFAIKT can't be used for shell injection.
|
965 |
-
if(WEBSHOT_XVFB_RUNNING){
|
966 |
-
putenv('DISPLAY=:100.0');
|
967 |
-
$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";
|
968 |
-
} else {
|
969 |
-
$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";
|
970 |
-
}
|
971 |
-
$this->debug(3, "Executing command: $command");
|
972 |
-
$out = `$command`;
|
973 |
-
$this->debug(3, "Received output: $out");
|
974 |
-
if(! is_file($tempfile)){
|
975 |
-
$this->set404();
|
976 |
-
return $this->error("The command to create a thumbnail failed.");
|
977 |
-
}
|
978 |
-
$this->cropTop = true;
|
979 |
-
if($this->processImageAndWriteToCache($tempfile)){
|
980 |
-
$this->debug(3, "Image processed succesfully. Serving from cache");
|
981 |
-
return $this->serveCacheFile();
|
982 |
-
} else {
|
983 |
-
return false;
|
984 |
-
}
|
985 |
-
}
|
986 |
-
protected function serveExternalImage(){
|
987 |
-
if(! preg_match('/^https?:\/\/[a-zA-Z0-9\-\.]+/i', $this->src)){
|
988 |
-
$this->error("Invalid URL supplied.");
|
989 |
-
return false;
|
990 |
-
}
|
991 |
-
$tempfile = tempnam($this->cacheDirectory, 'timthumb');
|
992 |
-
$this->debug(3, "Fetching external image into temporary file $tempfile");
|
993 |
-
$this->toDelete($tempfile);
|
994 |
-
#fetch file here
|
995 |
-
if(! $this->getURL($this->src, $tempfile)){
|
996 |
-
@unlink($this->cachefile);
|
997 |
-
touch($this->cachefile);
|
998 |
-
$this->debug(3, "Error fetching URL: " . $this->lastURLError);
|
999 |
-
$this->error("Error reading the URL you specified from remote host." . $this->lastURLError);
|
1000 |
-
return false;
|
1001 |
-
}
|
1002 |
-
|
1003 |
-
$mimeType = $this->getMimeType($tempfile);
|
1004 |
-
if(! preg_match("/^image\/(?:jpg|jpeg|gif|png)$/i", $mimeType)){
|
1005 |
-
$this->debug(3, "Remote file has invalid mime type: $mimeType");
|
1006 |
-
@unlink($this->cachefile);
|
1007 |
-
touch($this->cachefile);
|
1008 |
-
$this->error("The remote file is not a valid image. Mimetype = '" . $mimeType . "'" . $tempfile);
|
1009 |
-
return false;
|
1010 |
-
}
|
1011 |
-
if($this->processImageAndWriteToCache($tempfile)){
|
1012 |
-
$this->debug(3, "Image processed succesfully. Serving from cache");
|
1013 |
-
return $this->serveCacheFile();
|
1014 |
-
} else {
|
1015 |
-
return false;
|
1016 |
-
}
|
1017 |
-
}
|
1018 |
-
public static function curlWrite($h, $d){
|
1019 |
-
fwrite(self::$curlFH, $d);
|
1020 |
-
self::$curlDataWritten += strlen($d);
|
1021 |
-
if(self::$curlDataWritten > MAX_FILE_SIZE){
|
1022 |
-
return 0;
|
1023 |
-
} else {
|
1024 |
-
return strlen($d);
|
1025 |
-
}
|
1026 |
-
}
|
1027 |
-
protected function serveCacheFile(){
|
1028 |
-
$this->debug(3, "Serving {$this->cachefile}");
|
1029 |
-
if(! is_file($this->cachefile)){
|
1030 |
-
$this->error("serveCacheFile called in timthumb but we couldn't find the cached file.");
|
1031 |
-
return false;
|
1032 |
-
}
|
1033 |
-
$fp = fopen($this->cachefile, 'rb');
|
1034 |
-
if(! $fp){ return $this->error("Could not open cachefile."); }
|
1035 |
-
fseek($fp, strlen($this->filePrependSecurityBlock), SEEK_SET);
|
1036 |
-
$imgType = fread($fp, 3);
|
1037 |
-
fseek($fp, 3, SEEK_CUR);
|
1038 |
-
if(ftell($fp) != strlen($this->filePrependSecurityBlock) + 6){
|
1039 |
-
@unlink($this->cachefile);
|
1040 |
-
return $this->error("The cached image file seems to be corrupt.");
|
1041 |
-
}
|
1042 |
-
$imageDataSize = filesize($this->cachefile) - (strlen($this->filePrependSecurityBlock) + 6);
|
1043 |
-
$this->sendImageHeaders($imgType, $imageDataSize);
|
1044 |
-
$bytesSent = @fpassthru($fp);
|
1045 |
-
fclose($fp);
|
1046 |
-
if($bytesSent > 0){
|
1047 |
-
return true;
|
1048 |
-
}
|
1049 |
-
$content = file_get_contents ($this->cachefile);
|
1050 |
-
if ($content != FALSE) {
|
1051 |
-
$content = substr($content, strlen($this->filePrependSecurityBlock) + 6);
|
1052 |
-
echo $content;
|
1053 |
-
$this->debug(3, "Served using file_get_contents and echo");
|
1054 |
-
return true;
|
1055 |
-
} else {
|
1056 |
-
$this->error("Cache file could not be loaded.");
|
1057 |
-
return false;
|
1058 |
-
}
|
1059 |
-
}
|
1060 |
-
protected function sendImageHeaders($mimeType, $dataSize){
|
1061 |
-
if(! preg_match('/^image\//i', $mimeType)){
|
1062 |
-
$mimeType = 'image/' . $mimeType;
|
1063 |
-
}
|
1064 |
-
if(strtolower($mimeType) == 'image/jpg'){
|
1065 |
-
$mimeType = 'image/jpeg';
|
1066 |
-
}
|
1067 |
-
$gmdate_expires = gmdate ('D, d M Y H:i:s', strtotime ('now +10 days')) . ' GMT';
|
1068 |
-
$gmdate_modified = gmdate ('D, d M Y H:i:s') . ' GMT';
|
1069 |
-
// send content headers then display image
|
1070 |
-
header ('Content-Type: ' . $mimeType);
|
1071 |
-
header ('Accept-Ranges: none'); //Changed this because we don't accept range requests
|
1072 |
-
header ('Last-Modified: ' . $gmdate_modified);
|
1073 |
-
header ('Content-Length: ' . $dataSize);
|
1074 |
-
if(BROWSER_CACHE_DISABLE){
|
1075 |
-
$this->debug(3, "Browser cache is disabled so setting non-caching headers.");
|
1076 |
-
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
1077 |
-
header("Pragma: no-cache");
|
1078 |
-
header('Expires: ' . gmdate ('D, d M Y H:i:s', time()));
|
1079 |
-
} else {
|
1080 |
-
$this->debug(3, "Browser caching is enabled");
|
1081 |
-
header('Cache-Control: max-age=' . BROWSER_CACHE_MAX_AGE . ', must-revalidate');
|
1082 |
-
header('Expires: ' . $gmdate_expires);
|
1083 |
-
}
|
1084 |
-
return true;
|
1085 |
-
}
|
1086 |
-
protected function securityChecks(){
|
1087 |
-
}
|
1088 |
-
protected function param($property, $default = ''){
|
1089 |
-
if (isset ($_GET[$property])) {
|
1090 |
-
return $_GET[$property];
|
1091 |
-
} else {
|
1092 |
-
return $default;
|
1093 |
-
}
|
1094 |
-
}
|
1095 |
-
protected function openImage($mimeType, $src){
|
1096 |
-
switch ($mimeType) {
|
1097 |
-
case 'image/jpeg':
|
1098 |
-
$image = imagecreatefromjpeg ($src);
|
1099 |
-
break;
|
1100 |
-
|
1101 |
-
case 'image/png':
|
1102 |
-
$image = imagecreatefrompng ($src);
|
1103 |
-
imagealphablending( $image, true );
|
1104 |
-
imagesavealpha( $image, true );
|
1105 |
-
break;
|
1106 |
-
|
1107 |
-
case 'image/gif':
|
1108 |
-
$image = imagecreatefromgif ($src);
|
1109 |
-
break;
|
1110 |
-
|
1111 |
-
default:
|
1112 |
-
$this->error("Unrecognised mimeType");
|
1113 |
-
}
|
1114 |
-
|
1115 |
-
return $image;
|
1116 |
-
}
|
1117 |
-
protected function getIP(){
|
1118 |
-
$rem = @$_SERVER["REMOTE_ADDR"];
|
1119 |
-
$ff = @$_SERVER["HTTP_X_FORWARDED_FOR"];
|
1120 |
-
$ci = @$_SERVER["HTTP_CLIENT_IP"];
|
1121 |
-
if(preg_match('/^(?:192\.168|172\.16|10\.|127\.)/', $rem)){
|
1122 |
-
if($ff){ return $ff; }
|
1123 |
-
if($ci){ return $ci; }
|
1124 |
-
return $rem;
|
1125 |
-
} else {
|
1126 |
-
if($rem){ return $rem; }
|
1127 |
-
if($ff){ return $ff; }
|
1128 |
-
if($ci){ return $ci; }
|
1129 |
-
return "UNKNOWN";
|
1130 |
-
}
|
1131 |
-
}
|
1132 |
-
protected function debug($level, $msg){
|
1133 |
-
if(DEBUG_ON && $level <= DEBUG_LEVEL){
|
1134 |
-
$execTime = sprintf('%.6f', microtime(true) - $this->startTime);
|
1135 |
-
$tick = sprintf('%.6f', 0);
|
1136 |
-
if($this->lastBenchTime > 0){
|
1137 |
-
$tick = sprintf('%.6f', microtime(true) - $this->lastBenchTime);
|
1138 |
-
}
|
1139 |
-
$this->lastBenchTime = microtime(true);
|
1140 |
-
error_log("TimThumb Debug line " . __LINE__ . " [$execTime : $tick]: $msg");
|
1141 |
-
}
|
1142 |
-
}
|
1143 |
-
protected function sanityFail($msg){
|
1144 |
-
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");
|
1145 |
-
}
|
1146 |
-
protected function getMimeType($file){
|
1147 |
-
$info = getimagesize($file);
|
1148 |
-
if(is_array($info) && $info['mime']){
|
1149 |
-
return $info['mime'];
|
1150 |
-
}
|
1151 |
-
return '';
|
1152 |
-
}
|
1153 |
-
protected function setMemoryLimit(){
|
1154 |
-
$inimem = ini_get('memory_limit');
|
1155 |
-
$inibytes = timthumb::returnBytes($inimem);
|
1156 |
-
$ourbytes = timthumb::returnBytes(MEMORY_LIMIT);
|
1157 |
-
if($inibytes < $ourbytes){
|
1158 |
-
ini_set ('memory_limit', MEMORY_LIMIT);
|
1159 |
-
$this->debug(3, "Increased memory from $inimem to " . MEMORY_LIMIT);
|
1160 |
-
} else {
|
1161 |
-
$this->debug(3, "Not adjusting memory size because the current setting is " . $inimem . " and our size of " . MEMORY_LIMIT . " is smaller.");
|
1162 |
-
}
|
1163 |
-
}
|
1164 |
-
protected static function returnBytes($size_str){
|
1165 |
-
switch (substr ($size_str, -1))
|
1166 |
-
{
|
1167 |
-
case 'M': case 'm': return (int)$size_str * 1048576;
|
1168 |
-
case 'K': case 'k': return (int)$size_str * 1024;
|
1169 |
-
case 'G': case 'g': return (int)$size_str * 1073741824;
|
1170 |
-
default: return $size_str;
|
1171 |
-
}
|
1172 |
-
}
|
1173 |
-
|
1174 |
-
protected function getURL($url, $tempfile){
|
1175 |
-
$this->lastURLError = false;
|
1176 |
-
$url = preg_replace('/ /', '%20', $url);
|
1177 |
-
if(function_exists('curl_init')){
|
1178 |
-
$this->debug(3, "Curl is installed so using it to fetch URL.");
|
1179 |
-
self::$curlFH = fopen($tempfile, 'w');
|
1180 |
-
if(! self::$curlFH){
|
1181 |
-
$this->error("Could not open $tempfile for writing.");
|
1182 |
-
return false;
|
1183 |
-
}
|
1184 |
-
self::$curlDataWritten = 0;
|
1185 |
-
$this->debug(3, "Fetching url with curl: $url");
|
1186 |
-
$curl = curl_init($url);
|
1187 |
-
curl_setopt ($curl, CURLOPT_TIMEOUT, CURL_TIMEOUT);
|
1188 |
-
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");
|
1189 |
-
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
|
1190 |
-
curl_setopt ($curl, CURLOPT_HEADER, 0);
|
1191 |
-
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
1192 |
-
curl_setopt ($curl, CURLOPT_WRITEFUNCTION, 'timthumb::curlWrite');
|
1193 |
-
@curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, true);
|
1194 |
-
@curl_setopt ($curl, CURLOPT_MAXREDIRS, 10);
|
1195 |
-
|
1196 |
-
$curlResult = curl_exec($curl);
|
1197 |
-
fclose(self::$curlFH);
|
1198 |
-
$httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
1199 |
-
if($httpStatus == 404){
|
1200 |
-
$this->set404();
|
1201 |
-
}
|
1202 |
-
if($httpStatus == 302){
|
1203 |
-
$this->error("External Image is Redirecting. Try alternate image url");
|
1204 |
-
return false;
|
1205 |
-
}
|
1206 |
-
if($curlResult){
|
1207 |
-
curl_close($curl);
|
1208 |
-
return true;
|
1209 |
-
} else {
|
1210 |
-
$this->lastURLError = curl_error($curl);
|
1211 |
-
curl_close($curl);
|
1212 |
-
return false;
|
1213 |
-
}
|
1214 |
-
} else {
|
1215 |
-
$img = @file_get_contents ($url);
|
1216 |
-
if($img === false){
|
1217 |
-
$err = error_get_last();
|
1218 |
-
if(is_array($err) && $err['message']){
|
1219 |
-
$this->lastURLError = $err['message'];
|
1220 |
-
} else {
|
1221 |
-
$this->lastURLError = $err;
|
1222 |
-
}
|
1223 |
-
if(preg_match('/404/', $this->lastURLError)){
|
1224 |
-
$this->set404();
|
1225 |
-
}
|
1226 |
-
|
1227 |
-
return false;
|
1228 |
-
}
|
1229 |
-
if(! file_put_contents($tempfile, $img)){
|
1230 |
-
$this->error("Could not write to $tempfile.");
|
1231 |
-
return false;
|
1232 |
-
}
|
1233 |
-
return true;
|
1234 |
-
}
|
1235 |
-
|
1236 |
-
}
|
1237 |
-
protected function serveImg($file){
|
1238 |
-
$s = getimagesize($file);
|
1239 |
-
if(! ($s && $s['mime'])){
|
1240 |
-
return false;
|
1241 |
-
}
|
1242 |
-
header ('Content-Type: ' . $s['mime']);
|
1243 |
-
header ('Content-Length: ' . filesize($file) );
|
1244 |
-
header ('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
1245 |
-
header ("Pragma: no-cache");
|
1246 |
-
$bytes = @readfile($file);
|
1247 |
-
if($bytes > 0){
|
1248 |
-
return true;
|
1249 |
-
}
|
1250 |
-
$content = @file_get_contents ($file);
|
1251 |
-
if ($content != FALSE){
|
1252 |
-
echo $content;
|
1253 |
-
return true;
|
1254 |
-
}
|
1255 |
-
return false;
|
1256 |
-
|
1257 |
-
}
|
1258 |
-
protected function set404(){
|
1259 |
-
$this->is404 = true;
|
1260 |
-
}
|
1261 |
-
protected function is404(){
|
1262 |
-
return $this->is404;
|
1263 |
-
}
|
1264 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
views/admin/metaboxes/settings-general.php
CHANGED
@@ -2,7 +2,6 @@
|
|
2 |
|
3 |
<?php
|
4 |
|
5 |
-
$imagespath = $this -> get_option('imagespath');
|
6 |
$autospeed = $this -> get_option('autospeed');
|
7 |
$fadespeed = $this -> get_option('fadespeed');
|
8 |
$navopacity = $this -> get_option('navopacity');
|
@@ -16,14 +15,6 @@ $thumbscrollspeed = $this -> get_option('thumbscrollspeed');
|
|
16 |
|
17 |
<table class="form-table">
|
18 |
<tbody>
|
19 |
-
<tr>
|
20 |
-
<th><label for="imagespath"><?php _e('Images Path', $this -> plugin_name); ?></label>
|
21 |
-
<?php echo $this -> Html -> help(__('This is the relative or absolute path or even absolute URL to the images for slides and thumbnails. By default, it loads an absolute path in order to be accurate but it may not work on all hosting setups. If images are not working, use the "Images Tester" link on the right-hand side of this page to determine the issue and resolve it.', $this -> plugin_name)); ?></th>
|
22 |
-
<td>
|
23 |
-
<input type="text" class="widefat" name="imagespath" value="<?php echo esc_attr(stripslashes($imagespath)); ?>" id="imagespath" />
|
24 |
-
<span class="howto"><?php _e('Path to images where slide and thumbnail images are generated from.', $this -> plugin_name); ?></span>
|
25 |
-
</td>
|
26 |
-
</tr>
|
27 |
<tr>
|
28 |
<th><label for="autoslideY"><?php _e('Auto Slide', $this -> plugin_name); ?></label>
|
29 |
<?php echo $this -> Html -> help(__('Turn this on so that the slideshow can automatically slide through the slides.<br/><br/><strong>Override per slideshow:</strong> Using parameter <code>auto</code> with value <code>true</code> or <code>false</code> eg. <code>[tribulant_slideshow auto="false"]</code>.', $this -> plugin_name)); ?></th>
|
2 |
|
3 |
<?php
|
4 |
|
|
|
5 |
$autospeed = $this -> get_option('autospeed');
|
6 |
$fadespeed = $this -> get_option('fadespeed');
|
7 |
$navopacity = $this -> get_option('navopacity');
|
15 |
|
16 |
<table class="form-table">
|
17 |
<tbody>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
<tr>
|
19 |
<th><label for="autoslideY"><?php _e('Auto Slide', $this -> plugin_name); ?></label>
|
20 |
<?php echo $this -> Html -> help(__('Turn this on so that the slideshow can automatically slide through the slides.<br/><br/><strong>Override per slideshow:</strong> Using parameter <code>auto</code> with value <code>true</code> or <code>false</code> eg. <code>[tribulant_slideshow auto="false"]</code>.', $this -> plugin_name)); ?></th>
|
views/admin/metaboxes/settings-styles.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
<?php
|
4 |
|
5 |
$styles = $this -> get_option('styles');
|
6 |
-
$
|
7 |
|
8 |
?>
|
9 |
|
@@ -59,20 +59,11 @@ $timthumb_align = $this -> get_option('timthumb_align');
|
|
59 |
<table class="form-table">
|
60 |
<tbody>
|
61 |
<tr>
|
62 |
-
<th><label for="
|
63 |
-
<?php echo $this -> Html -> help(__('With this setting you can choose the location from which the image will be cropped/resized. For example if you prefer to have the top parts of images shown instead of being cut off, you can change this setting to "Top".', $this -> plugin_name)); ?></th>
|
64 |
<td>
|
65 |
-
<?php
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
?>
|
70 |
-
<select name="timthumb_align" id="timthumb_align">
|
71 |
-
<?php foreach ($alignments as $akey => $aval) : ?>
|
72 |
-
<option <?php echo (!empty($timthumb_align) && $timthumb_align == $akey) ? 'selected="selected"' : ''; ?> value="<?php echo $akey; ?>"><?php echo $aval; ?></option>
|
73 |
-
<?php endforeach; ?>
|
74 |
-
</select>
|
75 |
-
<span class="howto"><?php _e('Choose the image crop/resize location which is used as the starting point.', $this -> plugin_name); ?></span>
|
76 |
</td>
|
77 |
</tr>
|
78 |
</tbody>
|
3 |
<?php
|
4 |
|
5 |
$styles = $this -> get_option('styles');
|
6 |
+
$resizeimagescrop = $this -> get_option('resizeimagescrop');
|
7 |
|
8 |
?>
|
9 |
|
59 |
<table class="form-table">
|
60 |
<tbody>
|
61 |
<tr>
|
62 |
+
<th><label for="resizeimagescrop_Y"><?php _e('Crop', $this -> plugin_name); ?></label></th>
|
|
|
63 |
<td>
|
64 |
+
<label><input <?php echo (!empty($resizeimagescrop) && $resizeimagescrop == "Y") ? 'checked="checked"' : ''; ?> type="radio" name="resizeimagescrop" value="Y" id="resizeimagescrop_Y" /> <?php _e('Yes', $this -> plugin_name); ?></label>
|
65 |
+
<label><input <?php echo (!empty($resizeimagescrop) && $resizeimagescrop == "N") ? 'checked="checked"' : ''; ?> type="radio" name="resizeimagescrop" value="N" id="resizeimagescrop_N" /> <?php _e('No', $this -> plugin_name); ?></label>
|
66 |
+
<span class="howto"><?php _e('Should images be cropped?', $this -> plugin_name); ?></span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
</td>
|
68 |
</tr>
|
69 |
</tbody>
|
views/admin/metaboxes/settings-submit.php
CHANGED
@@ -12,10 +12,6 @@ $debugging = get_option('tridebugging');
|
|
12 |
<div class="misc-pub-section">
|
13 |
<a href="<?php echo $this -> url; ?>&method=reset" title="<?php _e('Reset all configuration settings to their default values', $this -> plugin_name); ?>" onclick="if (!confirm('<?php _e('Are you sure you wish to reset all configuration settings?', $this -> plugin_name); ?>')) { return false; }"><?php _e('Reset to Defaults', $this -> plugin_name); ?></a>
|
14 |
</div>
|
15 |
-
<div class="misc-pub-section">
|
16 |
-
<a href="<?php echo $this -> url; ?>&method=imagestester"><?php _e('Images Tester', $this -> plugin_name); ?></a>
|
17 |
-
<?php echo $this -> Html -> help(__('Slide or thumbnail images not working? Use the images tester to fix the problem', $this -> plugin_name)); ?>
|
18 |
-
</div>
|
19 |
<div class="misc-pub-section misc-pub-section-last">
|
20 |
<label><input <?php echo (!empty($debugging) && $debugging == 1) ? 'checked="checked"' : ''; ?> type="checkbox" name="debugging" value="1" id="debugging" /> <?php _e('Turn on debugging', $this -> plugin_name); ?></label>
|
21 |
</div>
|
12 |
<div class="misc-pub-section">
|
13 |
<a href="<?php echo $this -> url; ?>&method=reset" title="<?php _e('Reset all configuration settings to their default values', $this -> plugin_name); ?>" onclick="if (!confirm('<?php _e('Are you sure you wish to reset all configuration settings?', $this -> plugin_name); ?>')) { return false; }"><?php _e('Reset to Defaults', $this -> plugin_name); ?></a>
|
14 |
</div>
|
|
|
|
|
|
|
|
|
15 |
<div class="misc-pub-section misc-pub-section-last">
|
16 |
<label><input <?php echo (!empty($debugging) && $debugging == 1) ? 'checked="checked"' : ''; ?> type="checkbox" name="debugging" value="1" id="debugging" /> <?php _e('Turn on debugging', $this -> plugin_name); ?></label>
|
17 |
</div>
|
views/admin/settings-images.php
CHANGED
@@ -42,18 +42,17 @@ if (!empty($_GET['changepath'])) {
|
|
42 |
<p><?php _e('Below is a button to open the resized image in a new tab and then an actual 100 by 100 pixels sample of the image.', $this -> plugin_name); ?><br/>
|
43 |
<?php _e('If both the image from the button below and the sample below works fine, there is nothing wrong with the image cropping procedure.', $this -> plugin_name); ?><br/>
|
44 |
<?php _e('If neither of them work, there is something wrong, continue to step 3 below.', $this -> plugin_name); ?></p>
|
45 |
-
<p><a class="button" target="_blank" href="<?php echo $this -> Html ->
|
46 |
-
<p><?php echo $this -> Html ->
|
47 |
</li>
|
48 |
<li>
|
49 |
<h3><?php _e('Analyze Error Message', $this -> plugin_name); ?></h3>
|
50 |
-
<p><?php _e('When you clicked the "Open Resized Image" button above, it opened the
|
51 |
-
<?php _e('
|
52 |
|
53 |
<p><?php _e('If the error is simply "Could not find the internal image you specified." then you now your "Images Path" setting is incorrect.', $this -> plugin_name); ?><br/>
|
54 |
<?php _e('With that being the case, let us try a different "Images Path" to see if that resolves it. Click "Try Different Path" below.', $this -> plugin_name); ?><br/>
|
55 |
<?php _e('Alternatively, if you know what the path should be, go and change it under Slideshow > Configuration > General Settings.', $this -> plugin_name); ?></p>
|
56 |
-
<p><a class="button" href="?page=<?php echo $this -> sections -> settings; ?>&method=imagestester&id=<?php echo $slide -> id; ?>&changepath=<?php echo $newpath; ?>"><?php _e('Try Different Path', $this -> plugin_name); ?></a></p>
|
57 |
</li>
|
58 |
</ol>
|
59 |
<?php else : ?>
|
42 |
<p><?php _e('Below is a button to open the resized image in a new tab and then an actual 100 by 100 pixels sample of the image.', $this -> plugin_name); ?><br/>
|
43 |
<?php _e('If both the image from the button below and the sample below works fine, there is nothing wrong with the image cropping procedure.', $this -> plugin_name); ?><br/>
|
44 |
<?php _e('If neither of them work, there is something wrong, continue to step 3 below.', $this -> plugin_name); ?></p>
|
45 |
+
<p><a class="button" target="_blank" href="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, 100, 100, 100); ?>"><?php echo sprintf(__('Open Resized Image: %s', $this -> plugin_name), __($slide -> title)); ?></a></p>
|
46 |
+
<p><?php echo $this -> Html -> bfithumb_image($slide -> image_path, 100, 100, 100, "slideshow_dropshadow"); ?></p>
|
47 |
</li>
|
48 |
<li>
|
49 |
<h3><?php _e('Analyze Error Message', $this -> plugin_name); ?></h3>
|
50 |
+
<p><?php _e('When you clicked the "Open Resized Image" button above, it opened the BFI Thumb URL of the image.', $this -> plugin_name); ?><br/>
|
51 |
+
<?php _e('BFI Thumb will give you a descriptive error telling you what is wrong.', $this -> plugin_name); ?></p>
|
52 |
|
53 |
<p><?php _e('If the error is simply "Could not find the internal image you specified." then you now your "Images Path" setting is incorrect.', $this -> plugin_name); ?><br/>
|
54 |
<?php _e('With that being the case, let us try a different "Images Path" to see if that resolves it. Click "Try Different Path" below.', $this -> plugin_name); ?><br/>
|
55 |
<?php _e('Alternatively, if you know what the path should be, go and change it under Slideshow > Configuration > General Settings.', $this -> plugin_name); ?></p>
|
|
|
56 |
</li>
|
57 |
</ol>
|
58 |
<?php else : ?>
|
views/admin/slides/loop.php
CHANGED
@@ -118,7 +118,7 @@
|
|
118 |
<td><?php echo $slide -> id; ?></td>
|
119 |
<td style="width:75px;">
|
120 |
<?php $image = $slide -> image; ?>
|
121 |
-
<a href="<?php echo $this -> Html -> image_url($image); ?>" title="<?php echo $slide -> title; ?>" class="colorbox" rel="slides"><img class="dropshadow" src="<?php echo $this -> Html ->
|
122 |
</td>
|
123 |
<td>
|
124 |
<a class="row-title" href="<?php echo $this -> url; ?>&method=save&id=<?php echo $slide -> id; ?>" title=""><?php echo $slide -> title; ?></a>
|
118 |
<td><?php echo $slide -> id; ?></td>
|
119 |
<td style="width:75px;">
|
120 |
<?php $image = $slide -> image; ?>
|
121 |
+
<a href="<?php echo $this -> Html -> image_url($image); ?>" title="<?php echo $slide -> title; ?>" class="colorbox" rel="slides"><img class="dropshadow" src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, 50, 50, 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> title); ?>" /></a>
|
122 |
</td>
|
123 |
<td>
|
124 |
<a class="row-title" href="<?php echo $this -> url; ?>&method=save&id=<?php echo $slide -> id; ?>" title=""><?php echo $slide -> title; ?></a>
|
views/admin/slides/order.php
CHANGED
@@ -14,7 +14,7 @@
|
|
14 |
<ul id="slidelist">
|
15 |
<?php foreach ($slides as $slide) : ?>
|
16 |
<li class="gallerylineitem" id="item_<?php echo $slide -> id; ?>">
|
17 |
-
<span class="gallery_slide_image" style="display:none;"><img src="<?php echo $this -> Html ->
|
18 |
<span class="gallery_slide_title"><?php echo __($slide -> title); ?></span>
|
19 |
</li>
|
20 |
<?php endforeach; ?>
|
14 |
<ul id="slidelist">
|
15 |
<?php foreach ($slides as $slide) : ?>
|
16 |
<li class="gallerylineitem" id="item_<?php echo $slide -> id; ?>">
|
17 |
+
<span class="gallery_slide_image" style="display:none;"><img src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, 89, 89, 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> title); ?>" /></span>
|
18 |
<span class="gallery_slide_title"><?php echo __($slide -> title); ?></span>
|
19 |
</li>
|
20 |
<?php endforeach; ?>
|
views/admin/slides/save.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
|
3 |
<?php
|
4 |
|
5 |
-
$
|
6 |
|
7 |
?>
|
8 |
|
@@ -34,20 +34,25 @@ $showtd = $this -> Slide -> data -> showtd;
|
|
34 |
</td>
|
35 |
</tr>
|
36 |
<tr>
|
37 |
-
<th><label for="
|
|
|
38 |
<td>
|
39 |
-
<label><input onclick="
|
40 |
-
<
|
|
|
|
|
|
|
41 |
</td>
|
42 |
</tr>
|
43 |
</tbody>
|
44 |
</table>
|
45 |
|
46 |
-
<div id="
|
47 |
<table class="form-table">
|
48 |
<tbody>
|
49 |
<tr>
|
50 |
-
<th><label for="iopacity"><?php _e('Opacity', $this -> plugin_name); ?></label
|
|
|
51 |
<td>
|
52 |
<input type="text" id="iopacity" class="widefat" style="width:45px;" name="Slide[iopacity]" value="<?php echo esc_attr(stripslashes($this -> Slide -> data -> iopacity)); ?>" />
|
53 |
<span class="howto"><?php _e('A value between 0 and 100. Leave empty for default.', $this -> plugin_name); ?></span>
|
@@ -106,7 +111,7 @@ $showtd = $this -> Slide -> data -> showtd;
|
|
106 |
|
107 |
<input type="hidden" name="Slide[image_oldfile]" value="<?php echo esc_attr(stripslashes($this -> Slide -> data -> image)); ?>" />
|
108 |
<p><small><?php _e('Current image. Leave the field above blank to keep this image.', $this -> plugin_name); ?></small></p>
|
109 |
-
<p><a title="<?php echo esc_attr($this -> Slide -> data -> title); ?>" class="colorbox" href="<?php echo $this -> Html -> image_url($this -> Slide -> data -> image); ?>"><img src="<?php echo $this -> Html ->
|
110 |
|
111 |
<?php
|
112 |
}
|
2 |
|
3 |
<?php
|
4 |
|
5 |
+
$showinfo = $this -> Slide -> data -> showinfo;
|
6 |
|
7 |
?>
|
8 |
|
34 |
</td>
|
35 |
</tr>
|
36 |
<tr>
|
37 |
+
<th><label for="showinfo_both"><?php _e('Show Information?', $this -> plugin_name); ?></label>
|
38 |
+
<?php echo $this -> Html -> help(__('You can choose to show both title and description, only title, only description or not show the information bar at all. Please note that this setting is only effective when the information bar is turned on in configuration or via a parameter in shortcode or hardcode.', $this -> plugin_name)); ?></th>
|
39 |
<td>
|
40 |
+
<label><input onclick="jQuery('#showinfo_div').show();" <?php echo (!empty($showinfo) && $showinfo == "both") ? 'checked="checked"' : ''; ?> type="radio" name="Slide[showinfo]" value="both" id="showinfo_both" /> <?php _e('Both title and description', $this -> plugin_name); ?></label><br/>
|
41 |
+
<label><input onclick="jQuery('#showinfo_div').show();" <?php echo (!empty($showinfo) && $showinfo == "title") ? 'checked="checked"' : ''; ?> type="radio" name="Slide[showinfo]" value="title" id="showinfo_title" /> <?php _e('Title only', $this -> plugin_name); ?></label><br/>
|
42 |
+
<label><input onclick="jQuery('#showinfo_div').show();" <?php echo (!empty($showinfo) && $showinfo == "description") ? 'checked="checked"' : ''; ?> type="radio" name="Slide[showinfo]" value="description" id="showinfo_description" /> <?php _e('Description only', $this -> plugin_name); ?></label><br/>
|
43 |
+
<label><input onclick="jQuery('#showinfo_div').hide();" <?php echo (!empty($showinfo) && $showinfo == "none") ? 'checked="checked"' : ''; ?> type="radio" name="Slide[showinfo]" value="none" id="showinfo_none" /> <?php _e('None, do not show', $this -> plugin_name); ?></label>
|
44 |
+
<span class="howto"><?php _e('Choose how the information bar will be displayed on this slide.', $this -> plugin_name); ?></span>
|
45 |
</td>
|
46 |
</tr>
|
47 |
</tbody>
|
48 |
</table>
|
49 |
|
50 |
+
<div id="showinfo_div" style="display:<?php echo (!empty($showinfo) && $showinfo != "none") ? 'block' : 'none'; ?>;">
|
51 |
<table class="form-table">
|
52 |
<tbody>
|
53 |
<tr>
|
54 |
+
<th><label for="iopacity"><?php _e('Info Opacity', $this -> plugin_name); ?></label>
|
55 |
+
<?php echo $this -> Html -> help(__('The opacity of the information bar from 0 to 100 where 0 is transparent and 100 is opague.', $this -> plugin_name)); ?></th>
|
56 |
<td>
|
57 |
<input type="text" id="iopacity" class="widefat" style="width:45px;" name="Slide[iopacity]" value="<?php echo esc_attr(stripslashes($this -> Slide -> data -> iopacity)); ?>" />
|
58 |
<span class="howto"><?php _e('A value between 0 and 100. Leave empty for default.', $this -> plugin_name); ?></span>
|
111 |
|
112 |
<input type="hidden" name="Slide[image_oldfile]" value="<?php echo esc_attr(stripslashes($this -> Slide -> data -> image)); ?>" />
|
113 |
<p><small><?php _e('Current image. Leave the field above blank to keep this image.', $this -> plugin_name); ?></small></p>
|
114 |
+
<p><a title="<?php echo esc_attr($this -> Slide -> data -> title); ?>" class="colorbox" href="<?php echo $this -> Html -> image_url($this -> Slide -> data -> image); ?>"><img src="<?php echo $this -> Html -> bfithumb_image_src($this -> Slide -> data -> image_path, 100, 100, 100); ?>" alt="" class="slideshow" /></a></p>
|
115 |
|
116 |
<?php
|
117 |
}
|
views/default/gallery.php
CHANGED
@@ -17,7 +17,7 @@ $thumbopacity = $this -> get_option('thumbopacity');
|
|
17 |
<?php $full_image_path = get_attached_file($slide -> ID); ?>
|
18 |
<?php $full_image_url = wp_get_attachment_url($slide -> ID); ?>
|
19 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
20 |
-
<span><?php echo $this -> Html ->
|
21 |
<?php else : ?>
|
22 |
<span><?php echo $full_image_href[0]; ?></span>
|
23 |
<?php endif; ?>
|
@@ -25,9 +25,9 @@ $thumbopacity = $this -> get_option('thumbopacity');
|
|
25 |
<?php $thumbnail_link = wp_get_attachment_image_src($slide -> ID, 'thumbnail', false); ?>
|
26 |
<?php if ($options['showthumbs'] == "true") : ?>
|
27 |
<?php if (!empty($slide -> guid)) : ?>
|
28 |
-
<a href="<?php echo $slide -> guid; ?>" target="_self" title="<?php echo esc_attr($slide -> post_title); ?>"><img src="<?php echo $this -> Html ->
|
29 |
<?php else : ?>
|
30 |
-
<a><img src="<?php echo $this -> Html ->
|
31 |
<?php endif; ?>
|
32 |
<?php else : ?>
|
33 |
<a href="<?php echo $slide -> guid; ?>" title="<?php echo $slide -> post_title; ?>"></a>
|
@@ -40,16 +40,16 @@ $thumbopacity = $this -> get_option('thumbopacity');
|
|
40 |
<li>
|
41 |
<h3><?php echo stripslashes($slide -> title); ?></h3>
|
42 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
43 |
-
<span><?php echo $this -> Html ->
|
44 |
<?php else : ?>
|
45 |
<span><?php echo site_url() . '/' . $slide -> image_url; ?></span>
|
46 |
<?php endif; ?>
|
47 |
<p><?php echo substr(stripslashes($slide -> description), 0, 255); ?></p>
|
48 |
<?php if ($options['showthumbs'] == "true") : ?>
|
49 |
<?php if (!empty($slide -> post_id)) : ?>
|
50 |
-
<a href="<?php echo get_permalink($slide -> post_id); ?>" target="_self" title="<?php echo esc_attr($slide -> title); ?>"><img src="<?php echo $this -> Html ->
|
51 |
<?php else : ?>
|
52 |
-
<a><img src="<?php echo $this -> Html ->
|
53 |
<?php endif; ?>
|
54 |
<?php else : ?>
|
55 |
<a href="<?php echo get_permalink($slide -> post_id); ?>" target="_self" title="<?php echo esc_attr($slide -> title); ?>"></a>
|
@@ -60,18 +60,18 @@ $thumbopacity = $this -> get_option('thumbopacity');
|
|
60 |
<?php else : ?>
|
61 |
<?php foreach ($slides as $slide) : ?>
|
62 |
<li>
|
63 |
-
<h3 style="opacity:<?php echo (!empty($slide -> iopacity)) ? ($slide -> iopacity) : 70; ?>;"><?php echo (!empty($slide ->
|
64 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
65 |
-
<span><?php echo $this -> Html ->
|
66 |
<?php else : ?>
|
67 |
<span><?php echo $this -> Html -> image_url($slide -> image); ?></span>
|
68 |
<?php endif; ?>
|
69 |
-
<p><?php echo (!empty($slide ->
|
70 |
<?php if ($options['showthumbs'] == "true") : ?>
|
71 |
<?php if ($slide -> uselink == "Y" && !empty($slide -> link)) : ?>
|
72 |
-
<a href="<?php echo $slide -> link; ?>" title="<?php echo esc_attr($slide -> title); ?>" target="_<?php echo $slide -> linktarget; ?>"><img src="<?php echo $this -> Html ->
|
73 |
<?php else : ?>
|
74 |
-
<a><img src="<?php echo $this -> Html ->
|
75 |
<?php endif; ?>
|
76 |
<?php else : ?>
|
77 |
<?php if ($slide -> uselink == "Y" && !empty($slide -> link)) : ?>
|
17 |
<?php $full_image_path = get_attached_file($slide -> ID); ?>
|
18 |
<?php $full_image_url = wp_get_attachment_url($slide -> ID); ?>
|
19 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
20 |
+
<span><?php echo $this -> Html -> bfithumb_image_src($full_image_path, $options['width'], $options['height'], 100); ?></span>
|
21 |
<?php else : ?>
|
22 |
<span><?php echo $full_image_href[0]; ?></span>
|
23 |
<?php endif; ?>
|
25 |
<?php $thumbnail_link = wp_get_attachment_image_src($slide -> ID, 'thumbnail', false); ?>
|
26 |
<?php if ($options['showthumbs'] == "true") : ?>
|
27 |
<?php if (!empty($slide -> guid)) : ?>
|
28 |
+
<a href="<?php echo $slide -> guid; ?>" target="_self" title="<?php echo esc_attr($slide -> post_title); ?>"><img src="<?php echo $this -> Html -> bfithumb_image_src($full_image_path, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> post_title); ?>" /></a>
|
29 |
<?php else : ?>
|
30 |
+
<a><img src="<?php echo $this -> Html -> bfithumb_image_src($full_image_path, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> post_title); ?>" /></a>
|
31 |
<?php endif; ?>
|
32 |
<?php else : ?>
|
33 |
<a href="<?php echo $slide -> guid; ?>" title="<?php echo $slide -> post_title; ?>"></a>
|
40 |
<li>
|
41 |
<h3><?php echo stripslashes($slide -> title); ?></h3>
|
42 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
43 |
+
<span><?php echo $this -> Html -> bfithumb_image_src($slide -> image_url, $options['width'], $options['height'], 100); ?></span>
|
44 |
<?php else : ?>
|
45 |
<span><?php echo site_url() . '/' . $slide -> image_url; ?></span>
|
46 |
<?php endif; ?>
|
47 |
<p><?php echo substr(stripslashes($slide -> description), 0, 255); ?></p>
|
48 |
<?php if ($options['showthumbs'] == "true") : ?>
|
49 |
<?php if (!empty($slide -> post_id)) : ?>
|
50 |
+
<a href="<?php echo get_permalink($slide -> post_id); ?>" target="_self" title="<?php echo esc_attr($slide -> title); ?>"><img src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_url, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" /></a>
|
51 |
<?php else : ?>
|
52 |
+
<a><img src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_url, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" /></a>
|
53 |
<?php endif; ?>
|
54 |
<?php else : ?>
|
55 |
<a href="<?php echo get_permalink($slide -> post_id); ?>" target="_self" title="<?php echo esc_attr($slide -> title); ?>"></a>
|
60 |
<?php else : ?>
|
61 |
<?php foreach ($slides as $slide) : ?>
|
62 |
<li>
|
63 |
+
<h3 style="opacity:<?php echo (!empty($slide -> iopacity)) ? ($slide -> iopacity) : 70; ?>;"><?php echo (!empty($slide -> showinfo) && ($slide -> showinfo == "both" || $slide -> showinfo == "title")) ? $slide -> title : ''; ?></h3>
|
64 |
<?php if ($options['layout'] != "responsive" && $options['resizeimages'] == "true" && $options['width'] != "auto") : ?>
|
65 |
+
<span><?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, $options['width'], $options['height'], 100); ?></span>
|
66 |
<?php else : ?>
|
67 |
<span><?php echo $this -> Html -> image_url($slide -> image); ?></span>
|
68 |
<?php endif; ?>
|
69 |
+
<p><?php echo (!empty($slide -> showinfo) && ($slide -> showinfo == "both" || $slide -> showinfo == "description")) ? $slide -> description : ''; ?></p>
|
70 |
<?php if ($options['showthumbs'] == "true") : ?>
|
71 |
<?php if ($slide -> uselink == "Y" && !empty($slide -> link)) : ?>
|
72 |
+
<a href="<?php echo $slide -> link; ?>" title="<?php echo esc_attr($slide -> title); ?>" target="_<?php echo $slide -> linktarget; ?>"><img src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> title); ?>" /></a>
|
73 |
<?php else : ?>
|
74 |
+
<a><img src="<?php echo $this -> Html -> bfithumb_image_src($slide -> image_path, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> title); ?>" /></a>
|
75 |
<?php endif; ?>
|
76 |
<?php else : ?>
|
77 |
<?php if ($slide -> uselink == "Y" && !empty($slide -> link)) : ?>
|