TemplatesNext ToolKit - Version 1.1.2

Version Description

  • renamed file tnext-meta.php to tx-meta.php
Download this release

Release Info

Developer marsian
Plugin Icon 128x128 TemplatesNext ToolKit
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

Files changed (6) hide show
  1. inc/aq_resizer.php +239 -0
  2. inc/tx-meta.php +272 -0
  3. readme.txt +8 -1
  4. shortcodes.php +18 -19
  5. tx-functions.php +79 -73
  6. tx-toolkit.php +3 -2
inc/aq_resizer.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Title : Aqua Resizer
5
+ * Description : Resizes WordPress images on the fly
6
+ * Version : 1.2.0
7
+ * Author : Syamil MJ
8
+ * Author URI : http://aquagraphite.com
9
+ * License : WTFPL - http://sam.zoy.org/wtfpl/
10
+ * Documentation : https://github.com/sy4mil/Aqua-Resizer/
11
+ *
12
+ * @param string $url - (required) must be uploaded using wp media uploader
13
+ * @param int $width - (required)
14
+ * @param int $height - (optional)
15
+ * @param bool $crop - (optional) default to soft crop
16
+ * @param bool $single - (optional) returns an array if false
17
+ * @param bool $upscale - (optional) resizes smaller images
18
+ * @uses wp_upload_dir()
19
+ * @uses image_resize_dimensions()
20
+ * @uses wp_get_image_editor()
21
+ *
22
+ * @return str|array
23
+ */
24
+
25
+ if(!class_exists('Aq_Resize')) {
26
+ class Aq_Exception extends Exception {}
27
+
28
+ class Aq_Resize
29
+ {
30
+ /**
31
+ * The singleton instance
32
+ */
33
+ static private $instance = null;
34
+
35
+ /**
36
+ * Should an Aq_Exception be thrown on error?
37
+ * If false (default), then the error will just be logged.
38
+ */
39
+ public $throwOnError = false;
40
+
41
+ /**
42
+ * No initialization allowed
43
+ */
44
+ private function __construct() {}
45
+
46
+ /**
47
+ * No cloning allowed
48
+ */
49
+ private function __clone() {}
50
+
51
+ /**
52
+ * For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
53
+ */
54
+ static public function getInstance() {
55
+ if(self::$instance == null) {
56
+ self::$instance = new self;
57
+ }
58
+
59
+ return self::$instance;
60
+ }
61
+
62
+ /**
63
+ * Run, forest.
64
+ */
65
+ public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
66
+ try {
67
+ // Validate inputs.
68
+ if (!$url)
69
+ throw new Aq_Exception('$url parameter is required');
70
+ if (!$width)
71
+ throw new Aq_Exception('$width parameter is required');
72
+ if (!$height)
73
+ throw new Aq_Exception('$height parameter is required');
74
+
75
+ // Caipt'n, ready to hook.
76
+ if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
77
+
78
+ // Define upload path & dir.
79
+ $upload_info = wp_upload_dir();
80
+ $upload_dir = $upload_info['basedir'];
81
+ $upload_url = $upload_info['baseurl'];
82
+
83
+ $http_prefix = "http://";
84
+ $https_prefix = "https://";
85
+
86
+ /* if the $url scheme differs from $upload_url scheme, make them match
87
+ if the schemes differe, images don't show up. */
88
+ if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
89
+ $upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
90
+ }
91
+ elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
92
+ $upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
93
+ }
94
+
95
+
96
+ // Check if $img_url is local.
97
+ if ( false === strpos( $url, $upload_url ) )
98
+ throw new Aq_Exception('Image must be local: ' . $url);
99
+
100
+ // Define path of image.
101
+ $rel_path = str_replace( $upload_url, '', $url );
102
+ $img_path = $upload_dir . $rel_path;
103
+
104
+ // Check if img path exists, and is an image indeed.
105
+ if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) )
106
+ throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path);
107
+
108
+ // Get image info.
109
+ $info = pathinfo( $img_path );
110
+ $ext = $info['extension'];
111
+ list( $orig_w, $orig_h ) = getimagesize( $img_path );
112
+
113
+ // Get image size after cropping.
114
+ $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
115
+ $dst_w = $dims[4];
116
+ $dst_h = $dims[5];
117
+
118
+ // Return the original image only if it exactly fits the needed measures.
119
+ if ( ! $dims && ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
120
+ $img_url = $url;
121
+ $dst_w = $orig_w;
122
+ $dst_h = $orig_h;
123
+ } else {
124
+ // Use this to check if cropped image already exists, so we can return that instead.
125
+ $suffix = "{$dst_w}x{$dst_h}";
126
+ $dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
127
+ $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
128
+
129
+ if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
130
+ // Can't resize, so return false saying that the action to do could not be processed as planned.
131
+ throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
132
+ }
133
+ // Else check if cache exists.
134
+ elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
135
+ $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
136
+ }
137
+ // Else, we resize the image and return the new resized image url.
138
+ else {
139
+
140
+ $editor = wp_get_image_editor( $img_path );
141
+
142
+ if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
143
+ throw new Aq_Exception('Unable to get WP_Image_Editor: ' .
144
+ $editor->get_error_message() . ' (is GD or ImageMagick installed?)');
145
+ }
146
+
147
+ $resized_file = $editor->save();
148
+
149
+ if ( ! is_wp_error( $resized_file ) ) {
150
+ $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
151
+ $img_url = $upload_url . $resized_rel_path;
152
+ } else {
153
+ throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message());
154
+ }
155
+
156
+ }
157
+ }
158
+
159
+ // Okay, leave the ship.
160
+ if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
161
+
162
+ // Return the output.
163
+ if ( $single ) {
164
+ // str return.
165
+ $image = $img_url;
166
+ } else {
167
+ // array return.
168
+ $image = array (
169
+ 0 => $img_url,
170
+ 1 => $dst_w,
171
+ 2 => $dst_h
172
+ );
173
+ }
174
+
175
+ return $image;
176
+ }
177
+ catch (Aq_Exception $ex) {
178
+ error_log('Aq_Resize.process() error: ' . $ex->getMessage());
179
+
180
+ if ($this->throwOnError) {
181
+ // Bubble up exception.
182
+ throw $ex;
183
+ }
184
+ else {
185
+ // Return false, so that this patch is backwards-compatible.
186
+ return false;
187
+ }
188
+ }
189
+ }
190
+
191
+ /**
192
+ * Callback to overwrite WP computing of thumbnail measures
193
+ */
194
+ function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
195
+ if ( ! $crop ) return null; // Let the wordpress default function handle this.
196
+
197
+ // Here is the point we allow to use larger image size than the original one.
198
+ $aspect_ratio = $orig_w / $orig_h;
199
+ $new_w = $dest_w;
200
+ $new_h = $dest_h;
201
+
202
+ if ( ! $new_w ) {
203
+ $new_w = intval( $new_h * $aspect_ratio );
204
+ }
205
+
206
+ if ( ! $new_h ) {
207
+ $new_h = intval( $new_w / $aspect_ratio );
208
+ }
209
+
210
+ $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
211
+
212
+ $crop_w = round( $new_w / $size_ratio );
213
+ $crop_h = round( $new_h / $size_ratio );
214
+
215
+ $s_x = floor( ( $orig_w - $crop_w ) / 2 );
216
+ $s_y = floor( ( $orig_h - $crop_h ) / 2 );
217
+
218
+ return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
219
+ }
220
+ }
221
+ }
222
+
223
+
224
+
225
+
226
+
227
+ if(!function_exists('aq_resize')) {
228
+
229
+ /**
230
+ * This is just a tiny wrapper function for the class above so that there is no
231
+ * need to change any code in your own WP themes. Usage is still the same :)
232
+ */
233
+ function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
234
+ $aq_resize = Aq_Resize::getInstance();
235
+ return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
236
+ }
237
+ }
238
+
239
+
inc/tx-meta.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Registering meta boxes
4
+ *
5
+ * All the definitions of meta boxes are listed below with comments.
6
+ * Please read them CAREFULLY.
7
+ *
8
+ * You also should read the changelog to know what has been changed before updating.
9
+ *
10
+ * For more information, please visit:
11
+ * @link http://www.deluxeblogtips.com/meta-box/
12
+ */
13
+
14
+
15
+ add_filter( 'rwmb_meta_boxes', 'tx_register_meta_boxes' );
16
+
17
+ /**
18
+ * Register meta boxes
19
+ *
20
+ * @return void
21
+ */
22
+ function tx_register_meta_boxes( $meta_boxes )
23
+ {
24
+ /**
25
+ * Prefix of meta keys (optional)
26
+ * Use underscore (_) at the beginning to make keys hidden
27
+ * Alt.: You also can make prefix empty to disable it
28
+ */
29
+ // Better has an underscore as last sign
30
+ $prefix = 'tx_';
31
+
32
+ // 1st meta box
33
+ /*
34
+ $meta_boxes[] = array(
35
+ // Meta box id, UNIQUE per meta box. Optional since 4.1.5
36
+ 'id' => 'heading',
37
+
38
+ // Meta box title - Will appear at the drag and drop handle bar. Required.
39
+ 'title' => __( 'Page Heading Options', 'icraft' ),
40
+
41
+ // Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
42
+ 'pages' => array( 'post', 'page' ),
43
+
44
+ // Where the meta box appear: normal (default), advanced, side. Optional.
45
+ 'context' => 'normal',
46
+
47
+ // Order of meta box: high (default), low. Optional.
48
+ 'priority' => 'high',
49
+
50
+ // Auto save: true, false (default). Optional.
51
+ 'autosave' => true,
52
+
53
+ // List of meta fields
54
+ 'fields' => array(
55
+ // Hide Title
56
+ array(
57
+ 'name' => __( 'Hide Title', 'icraft' ),
58
+ 'id' => "{$prefix}hidetitle",
59
+ 'type' => 'checkbox',
60
+ // Value can be 0 or 1
61
+ 'std' => 0,
62
+ 'class' => 'hide-ttl',
63
+ ),
64
+ array(
65
+ 'name' => __( 'Show Default i-craft Slider', 'icraft' ),
66
+ 'id' => "{$prefix}show_slider",
67
+ 'type' => 'checkbox',
68
+ // Value can be 0 or 1
69
+ 'std' => 0,
70
+ 'class' => 'show-slider',
71
+ ),
72
+
73
+ // Custom Title
74
+ array(
75
+ // Field name - Will be used as label
76
+ 'name' => __( 'Custom title', 'icraft' ),
77
+ // Field ID, i.e. the meta key
78
+ 'id' => "{$prefix}customtitle",
79
+ // Field description (optional)
80
+ 'desc' => __( 'Enter custom title for the page', 'icraft' ),
81
+ 'type' => 'text',
82
+ // Default value (optional)
83
+ 'std' => __( '', 'icraft' ),
84
+ // CLONES: Add to make the field cloneable (i.e. have multiple value)
85
+ //'clone' => true,
86
+ 'class' => 'cust-ttl',
87
+ ),
88
+
89
+ // hide breadcrum
90
+ array(
91
+ 'name' => __( 'Hide breadcrumb', 'icraft' ),
92
+ 'id' => "{$prefix}hide_breadcrumb",
93
+ 'type' => 'checkbox',
94
+ // Value can be 0 or 1
95
+ 'std' => 0,
96
+ ),
97
+
98
+ // Custom Title
99
+ array(
100
+ // Field name - Will be used as label
101
+ 'name' => __( 'Other Slider Plugin Shortcode', 'icraft' ),
102
+ // Field ID, i.e. the meta key
103
+ 'id' => "{$prefix}other_slider",
104
+ // Field description (optional)
105
+ 'desc' => __( 'Enter a 3rd party slider shortcode, ex. meta slider, smart slider 2, wow slider, etc.', 'icraft' ),
106
+ 'type' => 'text',
107
+ // Default value (optional)
108
+ 'std' => __( '', 'icraft' ),
109
+ // CLONES: Add to make the field cloneable (i.e. have multiple value)
110
+ //'clone' => true,
111
+ 'class' => 'cust-ttl',
112
+ ),
113
+
114
+
115
+ )
116
+ );
117
+
118
+
119
+
120
+
121
+ $meta_boxes[] = array(
122
+ // Meta box id, UNIQUE per meta box. Optional since 4.1.5
123
+ 'id' => 'portfoliometa',
124
+
125
+ // Meta box title - Will appear at the drag and drop handle bar. Required.
126
+ 'title' => __( 'Portfolio Meta', 'ispirit' ),
127
+
128
+ // Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
129
+ 'pages' => array( 'portfolio' ),
130
+
131
+ // Where the meta box appear: normal (default), advanced, side. Optional.
132
+ 'context' => 'normal',
133
+
134
+ // Order of meta box: high (default), low. Optional.
135
+ 'priority' => 'high',
136
+
137
+ // Auto save: true, false (default). Optional.
138
+ 'autosave' => true,
139
+
140
+ // List of meta fields
141
+ 'fields' => array(
142
+ // Side bar
143
+
144
+ // ITEM DETAILS OPTIONS SECTION
145
+ array(
146
+ 'type' => 'heading',
147
+ 'name' => __( 'Portfolio Additinal Details', 'nx-admin' ),
148
+ 'id' => 'fake_id_pf1', // Not used but needed for plugin
149
+ ),
150
+ // Slide duration
151
+ array(
152
+ 'name' => __( 'Subtitle', 'nx-admin' ),
153
+ 'id' => "{$prefix}portfolio_subtitle",
154
+ 'desc' => __( 'Enter a subtitle for use within the portfolio item index (optional).', 'nx-admin' ),
155
+ 'type' => 'text',
156
+ ),
157
+
158
+ array(
159
+ 'name' => __( 'Portfolio Link(External)', 'nx-admin' ),
160
+ 'id' => "{$prefix}portfolio_url",
161
+ 'desc' => __( 'Enter an external link for the item (optional) (NOTE: INCLUDE HTTP://).', 'nx-admin' ),
162
+ 'type' => 'text',
163
+ ),
164
+ )
165
+ );
166
+ */
167
+
168
+
169
+ $meta_boxes[] = array(
170
+ // Meta box id, UNIQUE per meta box. Optional since 4.1.5
171
+ 'id' => 'itrans-slider',
172
+
173
+ // Meta box title - Will appear at the drag and drop handle bar. Required.
174
+ 'title' => __( 'itrans Slide Meta', 'ispirit' ),
175
+
176
+ // Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
177
+ 'pages' => array( 'itrans-slider' ),
178
+
179
+ // Where the meta box appear: normal (default), advanced, side. Optional.
180
+ 'context' => 'normal',
181
+
182
+ // Order of meta box: high (default), low. Optional.
183
+ 'priority' => 'high',
184
+
185
+ // Auto save: true, false (default). Optional.
186
+ 'autosave' => true,
187
+
188
+ // List of meta fields
189
+ 'fields' => array(
190
+
191
+ // name
192
+ array(
193
+ 'name' => __( 'Slide Button Text', 'nx-admin' ),
194
+ 'id' => "{$prefix}slide_link_text",
195
+ 'type' => 'text',
196
+ 'std' => __( '', 'nx-admin' ),
197
+ 'desc' => __('Enter the slide link button text.', 'nx-admin'),
198
+ ),
199
+
200
+ // designation
201
+ array(
202
+ 'name' => __( 'Lide Link URL', 'nx-admin' ),
203
+ 'id' => "{$prefix}slide_link_url",
204
+ 'type' => 'text',
205
+ 'std' => __( '', 'nx-admin' ),
206
+ 'desc' => __('Enter the slide link url', 'nx-admin'),
207
+ ),
208
+
209
+ )
210
+ );
211
+
212
+ $meta_boxes[] = array(
213
+ // Meta box id, UNIQUE per meta box. Optional since 4.1.5
214
+ 'id' => 'testimonialmeta',
215
+
216
+ // Meta box title - Will appear at the drag and drop handle bar. Required.
217
+ 'title' => __( 'Testimonial Meta', 'ispirit' ),
218
+
219
+ // Post types, accept custom post types as well - DEFAULT is array('post'). Optional.
220
+ 'pages' => array( 'testimonials' ),
221
+
222
+ // Where the meta box appear: normal (default), advanced, side. Optional.
223
+ 'context' => 'normal',
224
+
225
+ // Order of meta box: high (default), low. Optional.
226
+ 'priority' => 'high',
227
+
228
+ // Auto save: true, false (default). Optional.
229
+ 'autosave' => true,
230
+
231
+ // List of meta fields
232
+ 'fields' => array(
233
+
234
+ // name
235
+ array(
236
+ 'name' => __( 'Testimonial Cite', 'nx-admin' ),
237
+ 'id' => "{$prefix}testi_name",
238
+ 'type' => 'text',
239
+ 'std' => __( '', 'nx-admin' ),
240
+ 'desc' => __('Enter the testimonial cite name.', 'nx-admin'),
241
+ ),
242
+
243
+ // designation
244
+ array(
245
+ 'name' => __( 'Testimonial Cite Designation/position', 'nx-admin' ),
246
+ 'id' => "{$prefix}testi_desig",
247
+ 'type' => 'text',
248
+ 'std' => __( '', 'nx-admin' ),
249
+ 'desc' => __('Enter the cite designation or position', 'nx-admin'),
250
+ ),
251
+ // company name
252
+ array(
253
+ 'name' => __( 'Company name', 'nx-admin' ),
254
+ 'id' => "{$prefix}testi_company",
255
+ 'type' => 'text',
256
+ 'std' => __( '', 'nx-admin' ),
257
+ 'desc' => __('Enter the cite company name', 'nx-admin'),
258
+ ),
259
+
260
+
261
+
262
+ )
263
+ );
264
+
265
+
266
+
267
+
268
+ return $meta_boxes;
269
+ }
270
+
271
+
272
+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: marsian
4
  Tags: shortcode, shortcodes, columns, column, section, sections, portfolio, testimonial, border, borders, button, buttons, masonry, posts, post_type, font awesome, icons, fontawesome
5
  Requires at least: 3.6
6
  Tested up to: 4.1
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -25,6 +25,13 @@ Install the plugin into the `/wp-content/plugins/` folder, and activate it.
25
 
26
  == Changelog ==
27
 
 
 
 
 
 
 
 
28
 
29
  = 1.0.7 =
30
  * Added pagination for recent posts (blog) shortcode.
4
  Tags: shortcode, shortcodes, columns, column, section, sections, portfolio, testimonial, border, borders, button, buttons, masonry, posts, post_type, font awesome, icons, fontawesome
5
  Requires at least: 3.6
6
  Tested up to: 4.1
7
+ Stable tag: 1.1.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
25
 
26
  == Changelog ==
27
 
28
+ = 1.1.2 =
29
+ * renamed file tnext-meta.php to tx-meta.php
30
+
31
+ = 1.1.1 =
32
+ * Added 5 new widgets
33
+ * Added renamed function tx_register_shortcodes to avoide conflict
34
+ * added different style of services icon
35
 
36
  = 1.0.7 =
37
  * Added pagination for recent posts (blog) shortcode.
shortcodes.php CHANGED
@@ -39,6 +39,10 @@ function tx_blog_function($atts, $content = null) {
39
  'carousel' => 'no',
40
  ), $atts);
41
 
 
 
 
 
42
  $post_in_cat = tx_shortcodes_comma_delim_to_array( $atts['category_id'] );
43
  $post_comments = '';
44
 
@@ -82,22 +86,17 @@ function tx_blog_function($atts, $content = null) {
82
  if ( have_posts() ) : while ( have_posts() ) : the_post();
83
 
84
  $post_comments = get_comments_number();
85
-
86
- if (in_array("tx-medium", get_intermediate_image_sizes())) {
87
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'tx-medium' );
88
- } else
89
- {
90
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );
91
- }
92
  $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
93
-
94
 
95
-
 
 
96
  $return_string .= '<div class="tx-blog-item tx-post-col-'.$total_column.'"><div class="tx-border-box">';
97
 
98
  if ( has_post_thumbnail() ) {
99
  $return_string .= '<div class="tx-blog-img"><a href="'.esc_url($full_image_url[0]).'" class="tx-colorbox">';
100
- $return_string .= '<img src="'.esc_url($large_image_url[0]).'" alt="" class="blog-image" /></a><span class="tx-post-comm"><span>'.$post_comments.'</span></span></div>';
101
  } else
102
  {
103
  $return_string .= '<div class="tx-blog-imgpad"></div>';
@@ -394,6 +393,9 @@ function tx_portfolio_function($atts, $content = null) {
394
  $total_column = intval( $atts['columns'] );
395
  $tx_carousel = $atts['carousel'];
396
 
 
 
 
397
  if ( $atts['style'] == 'gallery' )
398
  {
399
  $style_class = 'folio-style-gallery';
@@ -432,13 +434,10 @@ function tx_portfolio_function($atts, $content = null) {
432
 
433
  if ( have_posts() ) : while ( have_posts() ) : the_post();
434
 
435
- if (in_array("tx-medium", get_intermediate_image_sizes())) {
436
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'tx-medium' );
437
- } else
438
- {
439
- $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );
440
- }
441
  $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
 
 
 
442
 
443
 
444
  $return_string .= '<div class="tx-portfolio-item tx-post-col-'.$total_column.'"><div class="tx-border-box">';
@@ -446,7 +445,7 @@ function tx_portfolio_function($atts, $content = null) {
446
 
447
  if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
448
  $return_string .= '<div class="tx-folio-img">';
449
- $return_string .= '<div class="tx-folio-img-wrap"><img src="'.esc_url($large_image_url[0]).'" alt="" class="folio-img" /></div>';
450
  $return_string .= '<div class="folio-links"><span>';
451
  $return_string .= '<a href="'.esc_url(get_permalink()).'" class="folio-linkico"><i class="fa fa-link"></i></a>';
452
  $return_string .= '<a href="'.esc_url($full_image_url[0]).'" class="tx-colorbox folio-zoomico"><i class="fa fa-search-plus"></i></a>';
@@ -543,7 +542,7 @@ function tx_slider_function($atts, $content = null) {
543
  $return_string = '';
544
  $cat_slug = '';
545
 
546
- if(!empty($atts['category']))
547
  {
548
  $cat_slug = $atts['category'];
549
  }
@@ -602,7 +601,7 @@ function tx_slider_function($atts, $content = null) {
602
 
603
 
604
  endwhile; else :
605
- $return_string .= '<p>Sorry, no slider matched your criteria. |'.$atts['category_id'].'|<pre>$post_in_cat</pre></p>';
606
  endif;
607
 
608
  $return_string .= '</div>';
39
  'carousel' => 'no',
40
  ), $atts);
41
 
42
+
43
+ $width = 600;
44
+ $height = 360;
45
+
46
  $post_in_cat = tx_shortcodes_comma_delim_to_array( $atts['category_id'] );
47
  $post_comments = '';
48
 
86
  if ( have_posts() ) : while ( have_posts() ) : the_post();
87
 
88
  $post_comments = get_comments_number();
89
+
 
 
 
 
 
 
90
  $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
 
91
 
92
+ $thumb_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
93
+ $thumb_image_url = aq_resize( $thumb_image_url[0], $width, $height, true, true, true );
94
+
95
  $return_string .= '<div class="tx-blog-item tx-post-col-'.$total_column.'"><div class="tx-border-box">';
96
 
97
  if ( has_post_thumbnail() ) {
98
  $return_string .= '<div class="tx-blog-img"><a href="'.esc_url($full_image_url[0]).'" class="tx-colorbox">';
99
+ $return_string .= '<img src="'.esc_url($thumb_image_url).'" alt="" class="blog-image" /></a><span class="tx-post-comm"><span>'.$post_comments.'</span></span></div>';
100
  } else
101
  {
102
  $return_string .= '<div class="tx-blog-imgpad"></div>';
393
  $total_column = intval( $atts['columns'] );
394
  $tx_carousel = $atts['carousel'];
395
 
396
+ $width = 600;
397
+ $height = 480;
398
+
399
  if ( $atts['style'] == 'gallery' )
400
  {
401
  $style_class = 'folio-style-gallery';
434
 
435
  if ( have_posts() ) : while ( have_posts() ) : the_post();
436
 
 
 
 
 
 
 
437
  $full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' );
438
+
439
+ $thumb_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
440
+ $thumb_image_url = aq_resize( $thumb_image_url[0], $width, $height, true, true, true );
441
 
442
 
443
  $return_string .= '<div class="tx-portfolio-item tx-post-col-'.$total_column.'"><div class="tx-border-box">';
445
 
446
  if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
447
  $return_string .= '<div class="tx-folio-img">';
448
+ $return_string .= '<div class="tx-folio-img-wrap"><img src="'.esc_url($thumb_image_url).'" alt="" class="folio-img" /></div>';
449
  $return_string .= '<div class="folio-links"><span>';
450
  $return_string .= '<a href="'.esc_url(get_permalink()).'" class="folio-linkico"><i class="fa fa-link"></i></a>';
451
  $return_string .= '<a href="'.esc_url($full_image_url[0]).'" class="tx-colorbox folio-zoomico"><i class="fa fa-search-plus"></i></a>';
542
  $return_string = '';
543
  $cat_slug = '';
544
 
545
+ if( !empty($atts['category']) )
546
  {
547
  $cat_slug = $atts['category'];
548
  }
601
 
602
 
603
  endwhile; else :
604
+ $return_string .= '<p>Sorry, no slider matched your criteria.</p>';
605
  endif;
606
 
607
  $return_string .= '</div>';
tx-functions.php CHANGED
@@ -73,35 +73,31 @@ function tx_get_category_list_key_array($category_name) {
73
  }
74
 
75
 
76
- /**
77
- * Resizes an image and returns an array containing the resized URL, width, height and file type. Uses native Wordpress functionality.
78
- *
79
  * @author Matthew Ruddy (http://easinglider.com)
80
  * @return array An array containing the resized image URL, width, height and file type.
81
  */
82
- function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $retina = false ) {
83
- global $wp_version;
84
-
85
- //######################################################################
86
- // First implementation
87
- //######################################################################
88
- if ( isset( $wp_version ) && version_compare( $wp_version, '3.5' ) >= 0 ) {
89
  global $wpdb;
90
  if ( empty( $url ) )
91
- return new WP_Error( 'no_image_url', 'No image URL has been entered.', $url );
92
  // Get default size from database
93
- $width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
94
  $height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
 
95
  // Allow for different retina sizes
96
  $retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
97
  // Get the image file path
98
  $file_path = parse_url( $url );
99
  $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
 
100
  // Check for Multisite
101
  if ( is_multisite() ) {
102
  global $blog_id;
103
  $blog_details = get_blog_details( $blog_id );
104
- $file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/' . $blog_id . '/files/', $file_path );
105
  }
106
  // Destination width and height variables
107
  $dest_width = $width * $retina;
@@ -113,11 +109,19 @@ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $re
113
  $dir = $info['dirname'];
114
  $ext = $info['extension'];
115
  $name = wp_basename( $file_path, ".$ext" );
 
 
 
116
  // Suffix applied to filename
117
  $suffix = "{$dest_width}x{$dest_height}";
118
  // Get the destination file name
119
  $dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
120
  if ( !file_exists( $dest_file_name ) ) {
 
 
 
 
 
121
  $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
122
  $get_attachment = $wpdb->get_results( $query );
123
  if ( !$get_attachment )
@@ -134,21 +138,18 @@ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $re
134
  $src_w = $orig_width;
135
  $src_h = $orig_height;
136
  if ( $crop ) {
137
-
138
  $cmp_x = $orig_width / $dest_width;
139
  $cmp_y = $orig_height / $dest_height;
140
-
141
  // Calculate x or y coordinate, and width or height of source
142
  if ( $cmp_x > $cmp_y ) {
143
  $src_w = round( $orig_width / $cmp_x * $cmp_y );
144
  $src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
145
  }
146
  else if ( $cmp_y > $cmp_x ) {
147
- $src_h = round( $orig_height / $cmp_y * $cmp_x );
148
- $src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
149
- }
150
  }
151
-
152
  // Time to crop the image!
153
  $editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
154
  // Now let's save the image
@@ -161,7 +162,7 @@ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $re
161
  // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
162
  $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
163
  if ( isset( $metadata['image_meta'] ) ) {
164
- $metadata['image_meta']['resized_images'][] = $resized_width . 'x' . $resized_height;
165
  wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
166
  }
167
  // Create the image array
@@ -183,154 +184,128 @@ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $re
183
  // Return image array
184
  return $image_array;
185
  }
186
-
187
- //######################################################################
188
- // Second implementation
189
- //######################################################################
190
- else {
191
  global $wpdb;
192
-
193
  if ( empty( $url ) )
194
- return new WP_Error( 'no_image_url', 'No image URL has been entered.', $url );
195
-
196
  // Bail if GD Library doesn't exist
197
- if ( !extension_loaded( 'gd' ) || !function_exists( 'gd_info' ) )
198
  return array( 'url' => $url, 'width' => $width, 'height' => $height );
199
-
200
  // Get default size from database
201
  $width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
202
  $height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
203
-
204
  // Allow for different retina sizes
205
  $retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
206
-
207
  // Destination width and height variables
208
  $dest_width = $width * $retina;
209
  $dest_height = $height * $retina;
210
-
211
  // Get image file path
212
  $file_path = parse_url( $url );
213
  $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
214
-
215
  // Check for Multisite
216
  if ( is_multisite() ) {
217
  global $blog_id;
218
  $blog_details = get_blog_details( $blog_id );
219
- $file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/' . $blog_id . '/files/', $file_path );
220
  }
221
-
222
  // Some additional info about the image
223
  $info = pathinfo( $file_path );
224
  $dir = $info['dirname'];
225
  $ext = $info['extension'];
226
  $name = wp_basename( $file_path, ".$ext" );
227
-
 
 
228
  // Suffix applied to filename
229
  $suffix = "{$dest_width}x{$dest_height}";
230
-
231
  // Get the destination file name
232
  $dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
233
-
234
  // No need to resize & create a new image if it already exists!
235
  if ( !file_exists( $dest_file_name ) ) {
236
-
237
  /*
238
- * Bail if this image isn't in the Media Library either.
239
- * We only want to resize Media Library images, so we can be sure they get deleted correctly when appropriate.
240
- */
241
  $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
242
  $get_attachment = $wpdb->get_results( $query );
243
  if ( !$get_attachment )
244
  return array( 'url' => $url, 'width' => $width, 'height' => $height );
245
-
246
  $image = wp_load_image( $file_path );
247
  if ( !is_resource( $image ) )
248
  return new WP_Error( 'error_loading_image_as_resource', $image, $file_path );
249
-
250
  // Get the current image dimensions and type
251
  $size = @getimagesize( $file_path );
252
  if ( !$size )
253
- return new WP_Error( 'file_path_getimagesize_failed', 'Failed to get $file_path information using getimagesize.' );
254
  list( $orig_width, $orig_height, $orig_type ) = $size;
255
-
256
  // Create new image
257
  $new_image = wp_imagecreatetruecolor( $dest_width, $dest_height );
258
-
259
  // Do some proportional cropping if enabled
260
  if ( $crop ) {
261
-
262
  $src_x = $src_y = 0;
263
  $src_w = $orig_width;
264
  $src_h = $orig_height;
265
-
266
  $cmp_x = $orig_width / $dest_width;
267
  $cmp_y = $orig_height / $dest_height;
268
-
269
  // Calculate x or y coordinate, and width or height of source
270
  if ( $cmp_x > $cmp_y ) {
271
  $src_w = round( $orig_width / $cmp_x * $cmp_y );
272
  $src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
273
  }
274
  else if ( $cmp_y > $cmp_x ) {
275
- $src_h = round( $orig_height / $cmp_y * $cmp_x );
276
- $src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
277
- }
278
-
279
  // Create the resampled image
280
  imagecopyresampled( $new_image, $image, 0, 0, $src_x, $src_y, $dest_width, $dest_height, $src_w, $src_h );
281
  }
282
  else
283
  imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $dest_width, $dest_height, $orig_width, $orig_height );
284
-
285
  // Convert from full colors to index colors, like original PNG.
286
- if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && !imageistruecolor( $image ) )
287
  imagetruecolortopalette( $new_image, false, imagecolorstotal( $image ) );
288
-
289
  // Remove the original image from memory (no longer needed)
290
  imagedestroy( $image );
291
-
292
  // Check the image is the correct file type
293
  if ( IMAGETYPE_GIF == $orig_type ) {
294
  if ( !imagegif( $new_image, $dest_file_name ) )
295
- return new WP_Error( 'resize_path_invalid', 'Resize path invalid (GIF)' );
296
  }
297
  elseif ( IMAGETYPE_PNG == $orig_type ) {
298
  if ( !imagepng( $new_image, $dest_file_name ) )
299
- return new WP_Error( 'resize_path_invalid', 'Resize path invalid (PNG).' );
300
  }
301
  else {
302
-
303
  // All other formats are converted to jpg
304
  if ( 'jpg' != $ext && 'jpeg' != $ext )
305
  $dest_file_name = "{$dir}/{$name}-{$suffix}.jpg";
306
  if ( !imagejpeg( $new_image, $dest_file_name, apply_filters( 'resize_jpeg_quality', 90 ) ) )
307
- return new WP_Error( 'resize_path_invalid', 'Resize path invalid (JPG).' );
308
  }
309
-
310
  // Remove new image from memory (no longer needed as well)
311
  imagedestroy( $new_image );
312
-
313
  // Set correct file permissions
314
- $stat = stat( dirname( $dest_file_name ) );
315
  $perms = $stat['mode'] & 0000666;
316
  @chmod( $dest_file_name, $perms );
317
-
318
  // Get some information about the resized image
319
  $new_size = @getimagesize( $dest_file_name );
320
  if ( !$new_size )
321
- return new WP_Error( 'resize_path_getimagesize_failed', 'Failed to get $dest_file_name (resized image) info via @getimagesize', $dest_file_name );
322
  list( $resized_width, $resized_height, $resized_type ) = $new_size;
323
-
324
  // Get the new image URL
325
  $resized_url = str_replace( basename( $url ), basename( $dest_file_name ), $url );
326
-
327
  // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
328
  $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
329
  if ( isset( $metadata['image_meta'] ) ) {
330
- $metadata['image_meta']['resized_images'][] = $resized_width . 'x' . $resized_height;
331
  wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
332
  }
333
-
334
  // Return array with resized image information
335
  $image_array = array(
336
  'url' => $resized_url,
@@ -347,10 +322,41 @@ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $re
347
  'type' => $ext
348
  );
349
  }
350
-
351
  return $image_array;
352
  }
353
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
 
355
  /*-----------------------------------------------------------------------------------*/
356
  /* changing default Excerpt length
73
  }
74
 
75
 
76
+ /*
 
 
77
  * @author Matthew Ruddy (http://easinglider.com)
78
  * @return array An array containing the resized image URL, width, height and file type.
79
  */
80
+ if ( isset( $wp_version ) && version_compare( $wp_version, '3.5' ) >= 0 ) {
81
+
82
+ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $retina = false ) {
 
 
 
 
83
  global $wpdb;
84
  if ( empty( $url ) )
85
+ return new WP_Error( 'no_image_url', __( 'No image URL has been entered.','wta' ), $url );
86
  // Get default size from database
87
+ $width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
88
  $height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
89
+
90
  // Allow for different retina sizes
91
  $retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
92
  // Get the image file path
93
  $file_path = parse_url( $url );
94
  $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
95
+
96
  // Check for Multisite
97
  if ( is_multisite() ) {
98
  global $blog_id;
99
  $blog_details = get_blog_details( $blog_id );
100
+ $file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/'. $blog_id .'/files/', $file_path );
101
  }
102
  // Destination width and height variables
103
  $dest_width = $width * $retina;
109
  $dir = $info['dirname'];
110
  $ext = $info['extension'];
111
  $name = wp_basename( $file_path, ".$ext" );
112
+ if ( 'bmp' == $ext ) {
113
+ return new WP_Error( 'bmp_mime_type', __( 'Image is BMP. Please use either JPG or PNG.','wta' ), $url );
114
+ }
115
  // Suffix applied to filename
116
  $suffix = "{$dest_width}x{$dest_height}";
117
  // Get the destination file name
118
  $dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
119
  if ( !file_exists( $dest_file_name ) ) {
120
+
121
+ /*
122
+ * Bail if this image isn't in the Media Library.
123
+ * We only want to resize Media Library images, so we can be sure they get deleted correctly when appropriate.
124
+ */
125
  $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
126
  $get_attachment = $wpdb->get_results( $query );
127
  if ( !$get_attachment )
138
  $src_w = $orig_width;
139
  $src_h = $orig_height;
140
  if ( $crop ) {
 
141
  $cmp_x = $orig_width / $dest_width;
142
  $cmp_y = $orig_height / $dest_height;
 
143
  // Calculate x or y coordinate, and width or height of source
144
  if ( $cmp_x > $cmp_y ) {
145
  $src_w = round( $orig_width / $cmp_x * $cmp_y );
146
  $src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
147
  }
148
  else if ( $cmp_y > $cmp_x ) {
149
+ $src_h = round( $orig_height / $cmp_y * $cmp_x );
150
+ $src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
151
+ }
152
  }
 
153
  // Time to crop the image!
154
  $editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
155
  // Now let's save the image
162
  // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
163
  $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
164
  if ( isset( $metadata['image_meta'] ) ) {
165
+ $metadata['image_meta']['resized_images'][] = $resized_width .'x'. $resized_height;
166
  wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
167
  }
168
  // Create the image array
184
  // Return image array
185
  return $image_array;
186
  }
187
+ }
188
+ else {
189
+ function tx_image_resize( $url, $width = NULL, $height = NULL, $crop = true, $retina = false ) {
 
 
190
  global $wpdb;
 
191
  if ( empty( $url ) )
192
+ return new WP_Error( 'no_image_url', __( 'No image URL has been entered.','wta' ), $url );
 
193
  // Bail if GD Library doesn't exist
194
+ if ( !extension_loaded('gd') || !function_exists('gd_info') )
195
  return array( 'url' => $url, 'width' => $width, 'height' => $height );
 
196
  // Get default size from database
197
  $width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
198
  $height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
 
199
  // Allow for different retina sizes
200
  $retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
 
201
  // Destination width and height variables
202
  $dest_width = $width * $retina;
203
  $dest_height = $height * $retina;
 
204
  // Get image file path
205
  $file_path = parse_url( $url );
206
  $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
207
+
208
  // Check for Multisite
209
  if ( is_multisite() ) {
210
  global $blog_id;
211
  $blog_details = get_blog_details( $blog_id );
212
+ $file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/'. $blog_id .'/files/', $file_path );
213
  }
 
214
  // Some additional info about the image
215
  $info = pathinfo( $file_path );
216
  $dir = $info['dirname'];
217
  $ext = $info['extension'];
218
  $name = wp_basename( $file_path, ".$ext" );
219
+ if ( 'bmp' == $ext ) {
220
+ return new WP_Error( 'bmp_mime_type', __( 'Image is BMP. Please use either JPG or PNG.','wta' ), $url );
221
+ }
222
  // Suffix applied to filename
223
  $suffix = "{$dest_width}x{$dest_height}";
 
224
  // Get the destination file name
225
  $dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
 
226
  // No need to resize & create a new image if it already exists!
227
  if ( !file_exists( $dest_file_name ) ) {
228
+
229
  /*
230
+ * Bail if this image isn't in the Media Library either.
231
+ * We only want to resize Media Library images, so we can be sure they get deleted correctly when appropriate.
232
+ */
233
  $query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
234
  $get_attachment = $wpdb->get_results( $query );
235
  if ( !$get_attachment )
236
  return array( 'url' => $url, 'width' => $width, 'height' => $height );
 
237
  $image = wp_load_image( $file_path );
238
  if ( !is_resource( $image ) )
239
  return new WP_Error( 'error_loading_image_as_resource', $image, $file_path );
 
240
  // Get the current image dimensions and type
241
  $size = @getimagesize( $file_path );
242
  if ( !$size )
243
+ return new WP_Error( 'file_path_getimagesize_failed', __( 'Failed to get $file_path information using "@getimagesize".','wta'), $file_path );
244
  list( $orig_width, $orig_height, $orig_type ) = $size;
245
+
246
  // Create new image
247
  $new_image = wp_imagecreatetruecolor( $dest_width, $dest_height );
 
248
  // Do some proportional cropping if enabled
249
  if ( $crop ) {
 
250
  $src_x = $src_y = 0;
251
  $src_w = $orig_width;
252
  $src_h = $orig_height;
 
253
  $cmp_x = $orig_width / $dest_width;
254
  $cmp_y = $orig_height / $dest_height;
 
255
  // Calculate x or y coordinate, and width or height of source
256
  if ( $cmp_x > $cmp_y ) {
257
  $src_w = round( $orig_width / $cmp_x * $cmp_y );
258
  $src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
259
  }
260
  else if ( $cmp_y > $cmp_x ) {
261
+ $src_h = round( $orig_height / $cmp_y * $cmp_x );
262
+ $src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
263
+ }
 
264
  // Create the resampled image
265
  imagecopyresampled( $new_image, $image, 0, 0, $src_x, $src_y, $dest_width, $dest_height, $src_w, $src_h );
266
  }
267
  else
268
  imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $dest_width, $dest_height, $orig_width, $orig_height );
 
269
  // Convert from full colors to index colors, like original PNG.
270
+ if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) )
271
  imagetruecolortopalette( $new_image, false, imagecolorstotal( $image ) );
 
272
  // Remove the original image from memory (no longer needed)
273
  imagedestroy( $image );
 
274
  // Check the image is the correct file type
275
  if ( IMAGETYPE_GIF == $orig_type ) {
276
  if ( !imagegif( $new_image, $dest_file_name ) )
277
+ return new WP_Error( 'resize_path_invalid', __( 'Resize path invalid (GIF)','wta' ) );
278
  }
279
  elseif ( IMAGETYPE_PNG == $orig_type ) {
280
  if ( !imagepng( $new_image, $dest_file_name ) )
281
+ return new WP_Error( 'resize_path_invalid', __( 'Resize path invalid (PNG).','wta' ) );
282
  }
283
  else {
 
284
  // All other formats are converted to jpg
285
  if ( 'jpg' != $ext && 'jpeg' != $ext )
286
  $dest_file_name = "{$dir}/{$name}-{$suffix}.jpg";
287
  if ( !imagejpeg( $new_image, $dest_file_name, apply_filters( 'resize_jpeg_quality', 90 ) ) )
288
+ return new WP_Error( 'resize_path_invalid', __( 'Resize path invalid (JPG).','wta' ) );
289
  }
 
290
  // Remove new image from memory (no longer needed as well)
291
  imagedestroy( $new_image );
 
292
  // Set correct file permissions
293
+ $stat = stat( dirname( $dest_file_name ));
294
  $perms = $stat['mode'] & 0000666;
295
  @chmod( $dest_file_name, $perms );
 
296
  // Get some information about the resized image
297
  $new_size = @getimagesize( $dest_file_name );
298
  if ( !$new_size )
299
+ return new WP_Error( 'resize_path_getimagesize_failed', __( 'Failed to get $dest_file_name (resized image) info via @getimagesize','wta' ), $dest_file_name );
300
  list( $resized_width, $resized_height, $resized_type ) = $new_size;
 
301
  // Get the new image URL
302
  $resized_url = str_replace( basename( $url ), basename( $dest_file_name ), $url );
 
303
  // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
304
  $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
305
  if ( isset( $metadata['image_meta'] ) ) {
306
+ $metadata['image_meta']['resized_images'][] = $resized_width .'x'. $resized_height;
307
  wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
308
  }
 
309
  // Return array with resized image information
310
  $image_array = array(
311
  'url' => $resized_url,
322
  'type' => $ext
323
  );
324
  }
 
325
  return $image_array;
326
  }
327
  }
328
+ /**
329
+ * Deletes the resized images when the original image is deleted from the Wordpress Media Library.
330
+ *
331
+ * @author Matthew Ruddy
332
+ */
333
+ add_action( 'delete_attachment', 'matthewruddy_delete_resized_images' );
334
+ function matthewruddy_delete_resized_images( $post_id ) {
335
+ // Get attachment image metadata
336
+ $metadata = wp_get_attachment_metadata( $post_id );
337
+ if ( !$metadata )
338
+ return;
339
+ // Do some bailing if we cannot continue
340
+ if ( !isset( $metadata['file'] ) || !isset( $metadata['image_meta']['resized_images'] ) )
341
+ return;
342
+ $pathinfo = pathinfo( $metadata['file'] );
343
+ $resized_images = $metadata['image_meta']['resized_images'];
344
+ // Get Wordpress uploads directory (and bail if it doesn't exist)
345
+ $wp_upload_dir = wp_upload_dir();
346
+ $upload_dir = $wp_upload_dir['basedir'];
347
+ if ( !is_dir( $upload_dir ) )
348
+ return;
349
+ // Delete the resized images
350
+ foreach ( $resized_images as $dims ) {
351
+ // Get the resized images filename
352
+ $file = $upload_dir .'/'. $pathinfo['dirname'] .'/'. $pathinfo['filename'] .'-'. $dims .'.'. $pathinfo['extension'];
353
+ // Delete the resized image
354
+ @unlink( $file );
355
+ }
356
+ }
357
+
358
+
359
+
360
 
361
  /*-----------------------------------------------------------------------------------*/
362
  /* changing default Excerpt length
tx-toolkit.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: TemplatesNext ToolKit
5
  Description: Custom Portfolio and Shortcode functionality for TemplatesNext Wordpress Themes
6
- Version: 1.1.1
7
  Author: TemplatesNext
8
  Author URI: http://templatesnext.org/
9
  License: GPLv2 or later
@@ -76,6 +76,7 @@ require_once('shortcodes.php');
76
  require_once('custom-post-types/testimonials-type.php');
77
  require_once('custom-post-types/portfolio-type.php');
78
  require_once('custom-post-types/itrans-slider.php');
 
79
 
80
 
81
  /*-----------------------------------------------------------------------------------*/
@@ -94,7 +95,7 @@ require_once('inc/widgets/widget-image.php');
94
  /* Metabox
95
  /*-----------------------------------------------------------------------------------*/
96
 
97
- require_once('inc/tnext-meta.php');
98
  require_once('inc/meta-box/meta-box.php');
99
 
100
 
3
  /*
4
  Plugin Name: TemplatesNext ToolKit
5
  Description: Custom Portfolio and Shortcode functionality for TemplatesNext Wordpress Themes
6
+ Version: 1.1.2
7
  Author: TemplatesNext
8
  Author URI: http://templatesnext.org/
9
  License: GPLv2 or later
76
  require_once('custom-post-types/testimonials-type.php');
77
  require_once('custom-post-types/portfolio-type.php');
78
  require_once('custom-post-types/itrans-slider.php');
79
+ require_once('inc/aq_resizer.php');
80
 
81
 
82
  /*-----------------------------------------------------------------------------------*/
95
  /* Metabox
96
  /*-----------------------------------------------------------------------------------*/
97
 
98
+ require_once('inc/tx-meta.php');
99
  require_once('inc/meta-box/meta-box.php');
100
 
101