|
1 <?php |
|
2 /* |
|
3 Plugin Name: Portfolio |
|
4 Plugin URI: http://bestwebsoft.com/plugin/ |
|
5 Description: Plugin for portfolio. |
|
6 Author: BestWebSoft |
|
7 Version: 2.20 |
|
8 Author URI: http://bestwebsoft.com/ |
|
9 License: GPLv2 or later |
|
10 */ |
|
11 |
|
12 /* Copyright 2011 BestWebSoft ( http://support.bestwebsoft.com ) |
|
13 |
|
14 This program is free software; you can redistribute it and/or modify |
|
15 it under the terms of the GNU General Public License, version 2, as |
|
16 published by the Free Software Foundation. |
|
17 |
|
18 This program is distributed in the hope that it will be useful, |
|
19 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21 GNU General Public License for more details. |
|
22 |
|
23 You should have received a copy of the GNU General Public License |
|
24 along with this program; if not, write to the Free Software |
|
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
26 */ |
|
27 $prtfl_boxes = array(); |
|
28 |
|
29 if ( ! function_exists( 'prtfl_plugin_install' ) ) { |
|
30 function prtfl_plugin_install() { |
|
31 $filename_1 = WP_PLUGIN_DIR .'/portfolio/template/portfolio.php'; |
|
32 $filename_2 = WP_PLUGIN_DIR .'/portfolio/template/portfolio-post.php'; |
|
33 |
|
34 $filename_theme_1 = get_stylesheet_directory() .'/portfolio.php'; |
|
35 $filename_theme_2 = get_stylesheet_directory() .'/portfolio-post.php'; |
|
36 |
|
37 if ( ! file_exists( $filename_theme_1 ) ) { |
|
38 $handle = @fopen( $filename_1, "r" ); |
|
39 $contents = @fread( $handle, filesize( $filename_1 ) ); |
|
40 @fclose( $handle ); |
|
41 if ( ! ( $handle = @fopen( $filename_theme_1, 'w' ) ) ) |
|
42 return false; |
|
43 @fwrite( $handle, $contents ); |
|
44 @fclose( $handle ); |
|
45 chmod( $filename_theme_1, octdec(755) ); |
|
46 } else { |
|
47 $handle = @fopen( $filename_theme_1, "r" ); |
|
48 $contents = @fread( $handle, filesize( $filename_theme_1 ) ); |
|
49 @fclose( $handle ); |
|
50 if ( ! ( $handle = @fopen( $filename_theme_1.'.bak', 'w' ) ) ) |
|
51 return false; |
|
52 @fwrite( $handle, $contents ); |
|
53 @fclose( $handle ); |
|
54 |
|
55 $handle = @fopen( $filename_1, "r" ); |
|
56 $contents = @fread( $handle, filesize( $filename_1 ) ); |
|
57 @fclose( $handle ); |
|
58 if ( ! ( $handle = @fopen( $filename_theme_1, 'w' ) ) ) |
|
59 return false; |
|
60 @fwrite( $handle, $contents ); |
|
61 @fclose( $handle ); |
|
62 chmod( $filename_theme_1, octdec(755) ); |
|
63 } |
|
64 if ( ! file_exists( $filename_theme_2 ) ) { |
|
65 $handle = @fopen( $filename_2, "r" ); |
|
66 $contents = @fread( $handle, filesize( $filename_2 ) ); |
|
67 @fclose( $handle ); |
|
68 if ( ! ( $handle = @fopen( $filename_theme_2, 'w' ) ) ) |
|
69 return false; |
|
70 @fwrite( $handle, $contents ); |
|
71 @fclose( $handle ); |
|
72 chmod( $filename_theme_2, octdec(755) ); |
|
73 } else { |
|
74 $handle = @fopen( $filename_theme_2, "r" ); |
|
75 $contents = @fread( $handle, filesize( $filename_theme_2 ) ); |
|
76 @fclose( $handle ); |
|
77 if ( ! ( $handle = @fopen( $filename_theme_2.'.bak', 'w' ) ) ) |
|
78 return false; |
|
79 @fwrite( $handle, $contents ); |
|
80 @fclose( $handle ); |
|
81 |
|
82 $handle = @fopen( $filename_2, "r" ); |
|
83 $contents = @fread( $handle, filesize( $filename_2 ) ); |
|
84 @fclose( $handle ); |
|
85 if ( ! ( $handle = @fopen( $filename_theme_2, 'w' ) ) ) |
|
86 return false; |
|
87 @fwrite( $handle, $contents ); |
|
88 @fclose( $handle ); |
|
89 chmod( $filename_theme_2, octdec(755) ); |
|
90 } |
|
91 } |
|
92 } |
|
93 |
|
94 if ( ! function_exists( 'prtfl_admin_error' ) ) { |
|
95 function prtfl_admin_error() { |
|
96 $post = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : "" ; |
|
97 $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : "" ; |
|
98 if ( ( 'portfolio' == get_post_type( $post ) || 'portfolio' == $post_type ) && ( ! file_exists( get_stylesheet_directory() .'/portfolio.php' ) || ! file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) ) ) { |
|
99 echo '<div class="error"><p><strong>'.__( 'The files "portfolio.php" and "portfolio-post.php" are not found in your theme directory. Please copy them from the directory `wp-content/plugins/portfolio/template/` to your theme directory for correct work of the Portfolio plugin', 'portfolio' ).'</strong></p></div>'; |
|
100 } |
|
101 } |
|
102 } |
|
103 |
|
104 if ( ! function_exists( 'prtfl_plugin_uninstall' ) ) { |
|
105 function prtfl_plugin_uninstall() { |
|
106 if ( file_exists( get_stylesheet_directory() .'/portfolio.php' ) && ! unlink(get_stylesheet_directory() .'/portfolio.php') ) { |
|
107 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) ); |
|
108 } |
|
109 if ( file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) && ! unlink(get_stylesheet_directory() .'/portfolio-post.php') ) { |
|
110 add_action( 'admin_notices', create_function( '', ' return "Error delete template file";' ) ); |
|
111 } |
|
112 if( get_option( 'prtfl_postmeta_update' ) ) { |
|
113 delete_option( 'prtfl_postmeta_update' ); |
|
114 } |
|
115 if( get_option( 'prtfl_tag_update' ) ) { |
|
116 delete_option( 'prtfl_tag_update' ); |
|
117 } |
|
118 if( get_option( 'prtfl_options' ) ) { |
|
119 delete_option( 'prtfl_options' ); |
|
120 } |
|
121 } |
|
122 } |
|
123 |
|
124 if ( ! function_exists ( 'prtfl_plugin_init' ) ) { |
|
125 function prtfl_plugin_init() { |
|
126 // Internationalization, first(!) |
|
127 load_plugin_textdomain( 'portfolio', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
128 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/bws_menu/languages/' ); |
|
129 global $prtfl_boxes; |
|
130 $prtfl_boxes['Portfolio-Info'] = array( |
|
131 array( '_prtfl_short_descr', __( 'Short description', 'portfolio' ), __( 'A short description which you\'d like to be displayed on your portfolio page', 'portfolio' ), '', '' ), |
|
132 array( '_prtfl_date_compl', __( 'Date of completion', 'portfolio' ), __( 'The date when the task was completed', 'portfolio' ), '', '' ), |
|
133 array( '_prtfl_link', __( 'Link', 'portfolio' ), __( 'A link to the site', 'portfolio' ), '', '' ), |
|
134 array( '_prtfl_svn', __( 'SVN', 'portfolio' ), __( 'SVN URL', 'portfolio' ), '', '' ), |
|
135 ); |
|
136 |
|
137 } |
|
138 } |
|
139 |
|
140 // Create post type for portfolio |
|
141 if ( ! function_exists( 'prtfl_post_type_portfolio' ) ) { |
|
142 function prtfl_post_type_portfolio() { |
|
143 global $wpdb; |
|
144 prtfl_replace_old_post_tag(); |
|
145 $options = get_site_option( 'prtfl_options' ); |
|
146 $slug = isset( $options['prtfl_slug'] ) && ! empty( $options['prtfl_slug'] ) ? $options['prtfl_slug'] : 'portfolio'; |
|
147 register_post_type( |
|
148 'portfolio', |
|
149 array( |
|
150 'labels' => array( |
|
151 'name' => __( 'Portfolio', 'portfolio' ), |
|
152 'singular_name' => __( 'Portfolio', 'portfolio' ), |
|
153 'add_new' => __( 'Add New', 'portfolio' ), |
|
154 'add_new_item' => __( 'Add New Portfolio', 'portfolio' ), |
|
155 'edit' => __( 'Edit', 'portfolio' ), |
|
156 'edit_item' => __( 'Edit Portfolio', 'portfolio' ), |
|
157 'new_item' => __( 'New Portfolio', 'portfolio' ), |
|
158 'view' => __( 'View Portfolio', 'portfolio' ), |
|
159 'view_item' => __( 'View Portfolio', 'portfolio' ), |
|
160 'search_items' => __( 'Search Portfolio', 'portfolio' ), |
|
161 'not_found' => __( 'No portfolio found', 'portfolio' ), |
|
162 'not_found_in_trash' => __( 'No portfolio found in Trash', 'portfolio' ), |
|
163 'parent' => __( 'Parent Portfolio', 'portfolio' ), |
|
164 ), |
|
165 'description' => __( 'Create a portfolio item', 'portfolio' ), |
|
166 'public' => true, |
|
167 'show_ui' => true, |
|
168 'publicly_queryable' => true, |
|
169 'exclude_from_search' => true, |
|
170 'menu_position' => 6, |
|
171 'hierarchical' => true, |
|
172 'query_var' => true, |
|
173 'register_meta_box_cb' => 'prtfl_init_metaboxes', |
|
174 'rewrite' => array( 'slug' => $slug ), |
|
175 'supports' => array ( |
|
176 'title', //Text input field to create a post title. |
|
177 'editor', |
|
178 'custom-fields', |
|
179 'comments', //Ability to turn on/off comments. |
|
180 'thumbnail', //Displays a box for featured image. |
|
181 'author' |
|
182 ) |
|
183 ) |
|
184 ); |
|
185 } |
|
186 } |
|
187 |
|
188 // Create taxonomy for portfolio - Technologies and Executors Profile |
|
189 if ( ! function_exists( 'prtfl_taxonomy_portfolio' ) ) { |
|
190 function prtfl_taxonomy_portfolio() { |
|
191 register_taxonomy( |
|
192 'portfolio_executor_profile', |
|
193 'portfolio', |
|
194 array( |
|
195 'hierarchical' => false, |
|
196 'update_count_callback' => '_update_post_term_count', |
|
197 'labels' => array( |
|
198 'name' => __( 'Executor Profiles', 'portfolio' ), |
|
199 'singular_name' => __( 'Executor Profile', 'portfolio' ), |
|
200 'search_items' => __( 'Search Executor Profiles', 'portfolio' ), |
|
201 'popular_items' => __( 'Popular Executor Profiles', 'portfolio' ), |
|
202 'all_items' => __( 'All Executor Profiles', 'portfolio' ), |
|
203 'parent_item' => __( 'Parent Executor Profile', 'portfolio' ), |
|
204 'parent_item_colon' => __( 'Parent Executor Profile:', 'portfolio' ), |
|
205 'edit_item' => __( 'Edit Executor Profile', 'portfolio' ), |
|
206 'update_item' => __( 'Update Executor Profile', 'portfolio' ), |
|
207 'add_new_item' => __( 'Add New Executor Profile', 'portfolio' ), |
|
208 'new_item_name' => __( 'New Executor Name', 'portfolio' ), |
|
209 'separate_items_with_commas' => __( 'Separate Executor Profiles with commas', 'portfolio' ), |
|
210 'add_or_remove_items' => __( 'Add or remove Executor Profile', 'portfolio' ), |
|
211 'choose_from_most_used' => __( 'Choose from the most used Executor Profiles', 'portfolio' ), |
|
212 'menu_name' => __( 'Executors', 'portfolio' ) |
|
213 ), |
|
214 'sort' => true, |
|
215 'args' => array( 'orderby' => 'term_order' ), |
|
216 'rewrite' => array( 'slug' => 'executor_profile' ), |
|
217 'show_tagcloud' => false |
|
218 ) |
|
219 ); |
|
220 |
|
221 register_taxonomy( |
|
222 'portfolio_technologies', |
|
223 'portfolio', |
|
224 array( |
|
225 'hierarchical' => false, |
|
226 'update_count_callback' => '_update_post_term_count', |
|
227 'labels' => array( |
|
228 'name' => __( 'Technologies', 'portfolio' ), |
|
229 'singular_name' => __( 'Technology', 'portfolio'), |
|
230 'search_items' => __( 'Search Technologies', 'portfolio' ), |
|
231 'popular_items' => __( 'Popular Technologies', 'portfolio' ), |
|
232 'all_items' => __( 'All Technologies', 'portfolio' ), |
|
233 'parent_item' => __( 'Parent Technology', 'portfolio' ), |
|
234 'parent_item_colon' => __( 'Parent Technology:', 'portfolio' ), |
|
235 'edit_item' => __( 'Edit Technology', 'portfolio' ), |
|
236 'update_item' => __( 'Update Technology', 'portfolio' ), |
|
237 'add_new_item' => __( 'Add New Technology', 'portfolio' ), |
|
238 'new_item_name' => __( 'New Technology Name', 'portfolio' ), |
|
239 'separate_items_with_commas' => __( 'Separate Technologies with commas', 'portfolio' ), |
|
240 'add_or_remove_items' => __( 'Add or remove Technology', 'portfolio' ), |
|
241 'choose_from_most_used' => __( 'Choose from the most used technologies', 'portfolio' ), |
|
242 'menu_name' => __( 'Technologies', 'portfolio' ) |
|
243 ), |
|
244 'query_var' => 'technologies', |
|
245 'rewrite' => array( 'slug' => 'technologies' ), |
|
246 'public' => true, |
|
247 'show_ui' => true, |
|
248 '_builtin' => true, |
|
249 'show_tagcloud' => false |
|
250 ) |
|
251 ); |
|
252 } |
|
253 } |
|
254 |
|
255 if ( ! function_exists( 'prtfl_technologies_get_posts' ) ) { |
|
256 function prtfl_technologies_get_posts( $query ) { |
|
257 if ( isset( $query->query_vars["technologies"] ) ) |
|
258 $query->set( 'post_type', array( 'portfolio' ) ); |
|
259 return $query; |
|
260 } |
|
261 } |
|
262 |
|
263 if ( ! function_exists( 'prtfl_register_widget' ) ) { |
|
264 function prtfl_register_widget() { |
|
265 $control_ops = array('width' => 200, 'height' => 200, 'id_base' => 'portfolio_technologies_widget'); |
|
266 |
|
267 wp_register_sidebar_widget( |
|
268 'portfolio_technologies_widget', |
|
269 __( 'Technologies', 'portfolio' ), |
|
270 'prtfl_widget_display', |
|
271 array( |
|
272 'description' => __( 'Your most used portfolio technologies as a tag cloud', 'portfolio' ) |
|
273 ) |
|
274 ); |
|
275 wp_register_widget_control( |
|
276 'portfolio_technologies_widget', // your unique widget id |
|
277 __( 'Technologies', 'portfolio' ), // widget name |
|
278 'prtfl_widget_display_control', // Callback function |
|
279 $control_ops, |
|
280 array( 'number' => 1 ) |
|
281 ); |
|
282 } |
|
283 } |
|
284 |
|
285 if ( ! function_exists( 'prtfl_widget_display' ) ) { |
|
286 function prtfl_widget_display( $args, $vars = array() ) { |
|
287 // print some HTML for the widget to display here |
|
288 extract( $args); |
|
289 $options = get_option( 'widget-portfolio_technologies_widget' ); |
|
290 if ( !empty( $options[1]['title'] ) ) { |
|
291 $title = $options[1]['title']; |
|
292 } else { |
|
293 $title = $widget_name; |
|
294 } |
|
295 $title = apply_filters( 'widget_title', $title, '', 'portfolio_technologies_widget' ); |
|
296 |
|
297 echo $before_widget; |
|
298 if ( $title ) |
|
299 echo $before_title . $title . $after_title; |
|
300 echo '<div class="tagcloud">'; |
|
301 wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => 'portfolio_technologies', 'number'=>0 ) ) ); |
|
302 echo "</div>\n"; |
|
303 echo $after_widget; |
|
304 } |
|
305 } |
|
306 |
|
307 if ( ! function_exists( 'prtfl_widget_display_control' ) ) { |
|
308 function prtfl_widget_display_control( $args ) { |
|
309 |
|
310 $options = get_option( 'widget-portfolio_technologies_widget' ); |
|
311 if ( empty( $options ) ) $options = array(); |
|
312 if ( isset( $options[0] ) ) unset( $options[0] ); |
|
313 |
|
314 // update options array |
|
315 if ( ! empty( $_POST['widget-portfolio_technologies_widget'] ) && is_array( $_POST ) ){ |
|
316 foreach( $_POST['widget-portfolio_technologies_widget'] as $widget_number => $values ){ |
|
317 if ( empty( $values ) && isset( $options[$widget_number] ) ) // user clicked cancel |
|
318 continue; |
|
319 |
|
320 if ( ! isset( $options[$widget_number] ) && $args['number'] == -1 ){ |
|
321 $args['number'] = $widget_number; |
|
322 } |
|
323 $options[$widget_number] = $values; |
|
324 } |
|
325 // clear unused options and update options in DB. return actual options array |
|
326 $options = prtfl_widget_portfolio_technologies_update( 'widget-portfolio_technologies_widget', $options, $_POST['widget-portfolio_technologies_widget'], $_POST['sidebar'], 'widget-portfolio_technologies_widget' ); |
|
327 } |
|
328 // $number - is dynamic number for multi widget, gived by WP |
|
329 // by default $number = -1 (if no widgets activated). In this case we should use %i% for inputs |
|
330 // to allow WP generate number automatically |
|
331 $number = ( $args['number'] == -1)? '%i%' : $args['number']; |
|
332 |
|
333 // now we can output control |
|
334 $title = $options[$number]['title']; |
|
335 ?> |
|
336 <p><label for="widget-portfolio_technologies_widget-<?php echo $number; ?>-title"><?php _e( 'Title', 'portfolio' ); ?>:</label> |
|
337 <input type="text" value="<?php echo $title; ?>" name="widget-portfolio_technologies_widget[<?php echo $number; ?>][title]" id="widget-portfolio_technologies_widget-<?php echo $number; ?>-title" class="widefat"></p> |
|
338 <?php |
|
339 } |
|
340 } |
|
341 |
|
342 if( ! function_exists( 'prtfl_widget_portfolio_technologies_update' ) ) { |
|
343 function prtfl_widget_portfolio_technologies_update( $id_prefix, $options, $post, $sidebar, $option_name = '' ){ |
|
344 global $wp_registered_widgets; |
|
345 static $updated = false; |
|
346 |
|
347 // get active sidebar |
|
348 $sidebars_widgets = wp_get_sidebars_widgets(); |
|
349 if ( isset( $sidebars_widgets[$sidebar]) ) |
|
350 $this_sidebar =& $sidebars_widgets[$sidebar]; |
|
351 else |
|
352 $this_sidebar = array(); |
|
353 |
|
354 // search unused options |
|
355 foreach ( $this_sidebar as $_widget_id ) { |
|
356 if( preg_match( '/' . $id_prefix . '-([0-9]+)/i', $_widget_id, $match ) ){ |
|
357 $widget_number = $match[1]; |
|
358 |
|
359 // $_POST['widget-id'] contain current widgets set for current sidebar |
|
360 // $this_sidebar is not updated yet, so we can determine which was deleted |
|
361 if ( ! in_array( $match[0], $_POST['widget-id'] ) ) { |
|
362 unset( $options[$widget_number] ); |
|
363 } |
|
364 } |
|
365 } |
|
366 // update database |
|
367 if ( ! empty( $option_name ) ) { |
|
368 update_option( $option_name, $options ); |
|
369 $updated = true; |
|
370 } |
|
371 // return updated array |
|
372 return $options; |
|
373 } |
|
374 } |
|
375 |
|
376 // Create custom permalinks for portfolio post type |
|
377 if ( ! function_exists( 'prtfl_custom_permalinks' ) ) { |
|
378 function prtfl_custom_permalinks( $rules ) { |
|
379 $newrules = array(); |
|
380 $newrules['portfolio/page/([^/]+)/?$'] = 'index.php?pagename=portfolio&paged=$matches[1]'; |
|
381 $newrules['portfolio/page/([^/]+)?$'] = 'index.php?pagename=portfolio&paged=$matches[1]'; |
|
382 // return $newrules + $rules; |
|
383 if ( $rules ) { |
|
384 return array_merge( $newrules, $rules ); |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 // flush_rules() if our rules are not yet included |
|
390 if ( ! function_exists( 'prtfl_flush_rules' ) ) { |
|
391 function prtfl_flush_rules(){ |
|
392 $rules = get_option( 'rewrite_rules' ); |
|
393 if ( ! isset( $rules['portfolio/page/([^/]+)/?$'] ) ) { |
|
394 global $wp_rewrite; |
|
395 $wp_rewrite->flush_rules(); |
|
396 } |
|
397 } |
|
398 } |
|
399 |
|
400 // Initialization of all metaboxes on the 'Add Portfolio' and Edit Portfolio pages |
|
401 if ( ! function_exists( 'prtfl_init_metaboxes' ) ) { |
|
402 function prtfl_init_metaboxes() { |
|
403 add_meta_box( 'Portfolio-Info', __( 'Portfolio Info', 'portfolio' ), 'prtfl_post_custom_box', 'portfolio', 'normal', 'high' ); // Description metaboxe |
|
404 } |
|
405 } |
|
406 |
|
407 // Create custom meta box for portfolio post type |
|
408 if ( ! function_exists( 'prtfl_post_custom_box' ) ) { |
|
409 function prtfl_post_custom_box( $obj = '', $box = '' ) { |
|
410 global $prtfl_boxes; |
|
411 // Generate box contents |
|
412 foreach( $prtfl_boxes[ $box[ 'id' ] ] as $prtfl_box ) { |
|
413 echo prtfl_text_field( $prtfl_box ); |
|
414 } |
|
415 } |
|
416 } |
|
417 |
|
418 // This is the default text field meta box |
|
419 if ( ! function_exists( 'prtfl_text_field' ) ) { |
|
420 function prtfl_text_field( $args ) { |
|
421 global $post; |
|
422 |
|
423 $description = $args[2]; |
|
424 if ( get_option( 'prtfl_postmeta_update' ) == '1' ) { |
|
425 $post_meta = get_post_meta( $post->ID, 'prtfl_information', true); |
|
426 $args[ 2 ] = is_array( $post_meta ) ? esc_html ( $post_meta[ $args[0] ] ) : "" ; |
|
427 } else { |
|
428 $args[ 2 ] = esc_html ( get_post_meta( $post->ID, $args[0], true ) ); |
|
429 } |
|
430 $label_format = |
|
431 '<div class="portfolio_admin_box">'. |
|
432 '<p><label for="%1$s"><strong>%2$s</strong></label></p>'. |
|
433 '<p><input style="width: 80%%;" type="text" name="%1$s" id="%1$s" value="%3$s" /></p>'. |
|
434 '<p><em>'. $description .'</em></p>'. |
|
435 '</div>'; |
|
436 if ( '_prtfl_date_compl' == $args[0] ) { |
|
437 echo '<script type="text/javascript">jQuery(document).ready(function(){jQuery("#_prtfl_date_compl").simpleDatepicker({ startdate: new Date().getFullYear()-3, enddate: new Date().getFullYear()+3 });});</script>'; |
|
438 } |
|
439 return vsprintf( $label_format, $args ); |
|
440 } |
|
441 } |
|
442 |
|
443 // This is the text area meta box |
|
444 if ( ! function_exists( 'prtfl_prtfl_text_area' ) ) { |
|
445 function prtfl_text_area( $args ) { |
|
446 global $post; |
|
447 |
|
448 $description = $args[2]; |
|
449 $args[2] = esc_html( get_post_meta( $post->ID, $args[0], true ) ); |
|
450 $label_format = |
|
451 '<div class="portfolio_admin_box">'. |
|
452 '<p><label for="%1$s"><strong>%2$s</strong></label></p>'. |
|
453 '<p><textarea class="theEditor" id="theEditor" style="width: 90%%;color:#000;" name="%1$s">%3$s</textarea></p>'. |
|
454 '<p><em>'. $description .'</em></p>'. |
|
455 '</div>'; |
|
456 return vsprintf( $label_format, $args ); |
|
457 } |
|
458 } |
|
459 |
|
460 /* When the post is saved, saves our custom data */ |
|
461 if ( ! function_exists ( 'prtfl_save_postdata' ) ) { |
|
462 function prtfl_save_postdata( $post_id, $post ) { |
|
463 global $prtfl_boxes; |
|
464 |
|
465 if ( "portfolio" == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { // don't store custom data twice |
|
466 // verify this came from the our screen and with proper authorization, |
|
467 // because save_post can be triggered at other times |
|
468 if( ! current_user_can ( 'edit_page', $post->ID ) ) { |
|
469 return $post->ID; |
|
470 } |
|
471 // We'll put it into an array to make it easier to loop though. |
|
472 // The data is already in $prtfl_boxes, but we need to flatten it out. |
|
473 foreach( $prtfl_boxes as $prtfl_boxe ) { |
|
474 foreach( $prtfl_boxe as $prtfl_fields ) { |
|
475 $my_data[ $prtfl_fields[0] ] = $_POST[ $prtfl_fields[0] ]; |
|
476 } |
|
477 } |
|
478 |
|
479 // Add values of $my_data as custom fields |
|
480 // Let's cycle through the $my_data array! |
|
481 if( get_option( 'prtfl_postmeta_update' ) == '1' ) { |
|
482 if( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) { |
|
483 // Custom field has a value and this custom field exists in database |
|
484 update_post_meta( $post->ID, 'prtfl_information', $my_data ); |
|
485 } |
|
486 elseif( $value ) { |
|
487 // Custom field has a value, but this custom field does not exist in database |
|
488 add_post_meta( $post->ID, 'prtfl_information', $my_data ); |
|
489 } |
|
490 else { |
|
491 // Custom field does not have a value, but this custom field exists in database |
|
492 update_post_meta( $post->ID, 'prtfl_information', $my_data ); |
|
493 } |
|
494 } else { |
|
495 foreach( $my_data as $key => $value ) { |
|
496 // if $value is an array, make it a CSV (unlikely) |
|
497 $value = implode( ',', ( array ) $value ); |
|
498 if( get_post_meta( $post->ID, $key, FALSE ) && $value ) { |
|
499 // Custom field has a value and this custom field exists in database |
|
500 update_post_meta( $post->ID, $key, $value ); |
|
501 } |
|
502 elseif( $value ) { |
|
503 // Custom field has a value, but this custom field does not exist in database |
|
504 add_post_meta( $post->ID, $key, $value ); |
|
505 } |
|
506 else { |
|
507 // Custom field does not have a value, but this custom field exists in database |
|
508 update_post_meta( $post->ID, $key, $value ); |
|
509 } |
|
510 } |
|
511 } |
|
512 } |
|
513 } |
|
514 } |
|
515 |
|
516 // This is pagenation functionality for portfolio post type |
|
517 if ( ! function_exists ( 'prtfl_pagination' ) ) { |
|
518 function prtfl_pagination( $pages = '', $range = 2 ) { |
|
519 $showitems = get_option( 'posts_per_page' ); |
|
520 |
|
521 global $paged, $wp_query; |
|
522 if ( empty ( $paged ) ) |
|
523 $paged = 1; |
|
524 if ( '' == $pages ) { |
|
525 $pages = $wp_query->max_num_pages; |
|
526 if( ! $pages ) { |
|
527 $pages = 1; |
|
528 } |
|
529 } |
|
530 |
|
531 if ( 1 != $pages ) { |
|
532 echo "<div class='pagination'>"; |
|
533 if ( 2 < $paged && $paged > $range + 1 && $showitems < $pages ) |
|
534 echo "<a href='". get_pagenum_link( 1 ) ."'>«</a>"; |
|
535 if ( 1 < $paged && $showitems < $pages ) |
|
536 echo "<a href='". get_pagenum_link( $paged - 1 ) ."'>‹</a>"; |
|
537 |
|
538 for ( $i = 1; $i <= $pages; $i++ ) { |
|
539 if ( 1 != $pages && ( !( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) { |
|
540 echo ( $paged == $i ) ? "<span class='current'>". $i ."</span>":"<a href='". get_pagenum_link( $i) ."' class='inactive' >". $i ."</a>"; |
|
541 } |
|
542 } |
|
543 |
|
544 if ( $paged < $pages && $showitems < $pages ) |
|
545 echo "<a href='". get_pagenum_link( $paged + 1 ) ."'>›</a>"; |
|
546 if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) |
|
547 echo "<a href='". get_pagenum_link( $pages ) ."'>»</a>"; |
|
548 echo "</div>\n"; |
|
549 } |
|
550 } |
|
551 } |
|
552 |
|
553 if ( ! function_exists ( 'prtfl_register_plugin_links' ) ) { |
|
554 function prtfl_register_plugin_links( $links, $file ) { |
|
555 $base = plugin_basename(__FILE__); |
|
556 if ( $file == $base ) { |
|
557 $links[] = '<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>'; |
|
558 $links[] = '<a href="http://wordpress.org/extend/plugins/portfolio/faq/" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>'; |
|
559 $links[] = '<a href="http://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>'; |
|
560 } |
|
561 return $links; |
|
562 } |
|
563 } |
|
564 |
|
565 if ( ! function_exists ( 'prtfl_replace_old_post_tag' ) ) { |
|
566 function prtfl_replace_old_post_tag() { |
|
567 global $wpdb; |
|
568 if ( false === get_option( 'prtfl_tag_update' ) ) { |
|
569 $tag_id_array = $wpdb->get_results( "SELECT term_taxonomy_id FROM $wpdb->posts, $wpdb->term_relationships WHERE post_type = 'portfolio' AND $wpdb->posts.ID = $wpdb->term_relationships.object_id" ); |
|
570 while( list( $key, $val ) = each( $tag_id_array ) ) { |
|
571 $wpdb->update( |
|
572 $wpdb->term_taxonomy, |
|
573 array( |
|
574 'taxonomy' => 'portfolio_technologies' |
|
575 ), |
|
576 array( |
|
577 'taxonomy' => 'post_tag' , |
|
578 'term_taxonomy_id' => $val->term_taxonomy_id |
|
579 ), |
|
580 array( |
|
581 '%s' |
|
582 ), |
|
583 array( |
|
584 '%s', |
|
585 '%d' |
|
586 ) |
|
587 ); |
|
588 } |
|
589 $wpdb->query( "UPDATE $wpdb->posts, $wpdb->postmeta SET $wpdb->posts.post_content = $wpdb->postmeta.meta_value WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID AND $wpdb->posts.post_type = 'portfolio' AND $wpdb->postmeta.meta_key = '_prtfl_short_descr' " ); |
|
590 $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = '_prtfl_short_descr'" ); |
|
591 $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = REPLACE(meta_key, 'prtf_', 'prtfl_') WHERE meta_key LIKE '_prtf_%'" ); |
|
592 add_option( 'prtfl_tag_update', '1', '', 'no' ); |
|
593 } |
|
594 $postmeta = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '%_short_descr%' LIMIT 0 , 1" ); |
|
595 if ( empty( $postmeta ) && ! get_option( 'prtfl_postmeta_update' ) ) { |
|
596 add_option( 'prtfl_postmeta_update', 1 ); |
|
597 } |
|
598 } |
|
599 } |
|
600 |
|
601 require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' ); |
|
602 |
|
603 if ( ! function_exists( 'add_prtfl_admin_menu' ) ) { |
|
604 function add_prtfl_admin_menu() { |
|
605 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( "images/px.png", __FILE__ ), 1001 ); |
|
606 add_submenu_page( 'bws_plugins', __( 'Portfolio', 'portfolio' ), __( 'Portfolio', 'portfolio' ), 'manage_options', "portfolio.php", 'prtfl_settings_page' ); |
|
607 |
|
608 //call register settings function |
|
609 add_action( 'admin_init', 'register_prtfl_settings' ); |
|
610 } |
|
611 } |
|
612 |
|
613 // register settings function |
|
614 if ( ! function_exists( 'register_prtfl_settings' ) ) { |
|
615 function register_prtfl_settings() { |
|
616 global $wpmu, $prtfl_options; |
|
617 |
|
618 $prtfl_option_defaults = array( |
|
619 'prtfl_custom_size_name' => array( 'portfolio-thumb', 'portfolio-photo-thumb' ), |
|
620 'prtfl_custom_size_px' => array( array( 280, 300 ), array( 240, 260 ) ), |
|
621 'prtfl_order_by' => 'menu_order', |
|
622 'prtfl_order' => 'ASC', |
|
623 'prtfl_custom_image_row_count' => 3, |
|
624 'prtfl_date_additional_field' => 1, |
|
625 'prtfl_link_additional_field' => 1, |
|
626 'prtfl_shrdescription_additional_field' => 1, |
|
627 'prtfl_description_additional_field' => 1, |
|
628 'prtfl_svn_additional_field' => 1, |
|
629 'prtfl_executor_additional_field' => 1, |
|
630 'prtfl_technologies_additional_field' => 1, |
|
631 'prtfl_link_additional_field_for_non_registered' => 1, |
|
632 'prtfl_date_text_field' => __( 'Date of completion:', 'portfolio' ), |
|
633 'prtfl_link_text_field' => __( 'Link:', 'portfolio' ), |
|
634 'prtfl_shrdescription_text_field' => __( 'Short description:', 'portfolio' ), |
|
635 'prtfl_description_text_field' => __( 'Description:', 'portfolio' ), |
|
636 'prtfl_svn_text_field' => __( 'SVN:', 'portfolio' ), |
|
637 'prtfl_executor_text_field' => __( 'Executor Profile:', 'portfolio' ), |
|
638 'prtfl_screenshot_text_field' => __( 'More screenshots:', 'portfolio' ), |
|
639 'prtfl_technologies_text_field' => __( 'Technologies:', 'portfolio' ), |
|
640 'prtfl_slug' => 'portfolio' |
|
641 ); |
|
642 |
|
643 // install the option defaults |
|
644 if ( 1 == $wpmu ) { |
|
645 if( !get_site_option( 'prtfl_options' ) ) { |
|
646 add_site_option( 'prtfl_options', $prtfl_option_defaults, '', 'yes' ); |
|
647 } |
|
648 } else { |
|
649 if( ! get_option( 'prtfl_options' ) ) |
|
650 add_option( 'prtfl_options', $prtfl_option_defaults, '', 'yes' ); |
|
651 } |
|
652 |
|
653 // get options from the database |
|
654 if ( 1 == $wpmu ) |
|
655 $prtfl_options = get_site_option( 'prtfl_options' ); // get options from the database |
|
656 else |
|
657 $prtfl_options = get_option( 'prtfl_options' );// get options from the database |
|
658 |
|
659 if ( isset( $prtfl_options['prtfl_prettyPhoto_style'] ) ) |
|
660 unset( $prtfl_options['prtfl_prettyPhoto_style'] ); |
|
661 |
|
662 // array merge incase this version has added new options |
|
663 $prtfl_options = array_merge( $prtfl_option_defaults, $prtfl_options ); |
|
664 |
|
665 update_option( 'prtfl_options', $prtfl_options ); |
|
666 |
|
667 if ( function_exists( 'add_image_size' ) ) { |
|
668 add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true ); |
|
669 add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true ); |
|
670 } |
|
671 } |
|
672 } |
|
673 |
|
674 if( ! function_exists( 'prtfl_settings_page' ) ) { |
|
675 function prtfl_settings_page() { |
|
676 global $prtfl_options; |
|
677 $error = ""; |
|
678 |
|
679 // Save data for settings page |
|
680 if( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'prtfl_nonce_name' ) ) { |
|
681 $prtfl_request_options = array(); |
|
682 $prtfl_request_options["prtfl_custom_size_name"] = $prtfl_options["prtfl_custom_size_name"]; |
|
683 |
|
684 $prtfl_request_options["prtfl_custom_size_px"] = array( |
|
685 array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_album'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_album'] ) ) ), |
|
686 array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_photo'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_photo'] ) ) ) |
|
687 ); |
|
688 $prtfl_request_options["prtfl_custom_image_row_count"] = intval( trim( $_REQUEST['prtfl_custom_image_row_count'] ) ); |
|
689 if( $prtfl_request_options["prtfl_custom_image_row_count"] == "" || $prtfl_request_options["prtfl_custom_image_row_count"] < 1 ) |
|
690 $prtfl_request_options["prtfl_custom_image_row_count"] = 1; |
|
691 |
|
692 $prtfl_request_options["prtfl_order_by"] = $_REQUEST['prtfl_order_by']; |
|
693 $prtfl_request_options["prtfl_order"] = $_REQUEST['prtfl_order']; |
|
694 |
|
695 $prtfl_request_options["prtfl_date_additional_field"] = isset( $_REQUEST["prtfl_date_additional_field"] ) ? $_REQUEST["prtfl_date_additional_field"] : 0; |
|
696 $prtfl_request_options["prtfl_link_additional_field"] = isset( $_REQUEST["prtfl_link_additional_field"] ) ? $_REQUEST["prtfl_link_additional_field"] : 0; |
|
697 $prtfl_request_options["prtfl_shrdescription_additional_field"] = isset( $_REQUEST["prtfl_shrdescription_additional_field"] ) ? $_REQUEST["prtfl_shrdescription_additional_field"] : 0; |
|
698 $prtfl_request_options["prtfl_description_additional_field"] = isset( $_REQUEST["prtfl_description_additional_field"] ) ? $_REQUEST["prtfl_description_additional_field"] : 0; |
|
699 $prtfl_request_options["prtfl_svn_additional_field"] = isset( $_REQUEST["prtfl_svn_additional_field"] ) ? $_REQUEST["prtfl_svn_additional_field"] : 0; |
|
700 $prtfl_request_options["prtfl_executor_additional_field"] = isset( $_REQUEST["prtfl_executor_additional_field"] ) ? $_REQUEST["prtfl_executor_additional_field"] : 0; |
|
701 $prtfl_request_options["prtfl_technologies_additional_field"] = isset( $_REQUEST["prtfl_technologies_additional_field"] ) ? $_REQUEST["prtfl_technologies_additional_field"] : 0; |
|
702 |
|
703 $prtfl_request_options["prtfl_link_additional_field_for_non_registered"] = isset( $_REQUEST["prtfl_link_additional_field_for_non_registered"] ) ? $_REQUEST["prtfl_link_additional_field_for_non_registered"] : 0; |
|
704 |
|
705 $prtfl_request_options["prtfl_date_text_field"] = $_REQUEST["prtfl_date_text_field"]; |
|
706 $prtfl_request_options["prtfl_link_text_field"] = $_REQUEST["prtfl_link_text_field"]; |
|
707 $prtfl_request_options["prtfl_shrdescription_text_field"] = $_REQUEST["prtfl_shrdescription_text_field"]; |
|
708 $prtfl_request_options["prtfl_description_text_field"] = $_REQUEST["prtfl_description_text_field"]; |
|
709 $prtfl_request_options["prtfl_svn_text_field"] = $_REQUEST["prtfl_svn_text_field"]; |
|
710 $prtfl_request_options["prtfl_executor_text_field"] = $_REQUEST["prtfl_executor_text_field"]; |
|
711 $prtfl_request_options["prtfl_screenshot_text_field"] = $_REQUEST["prtfl_screenshot_text_field"]; |
|
712 $prtfl_request_options["prtfl_technologies_text_field"] = $_REQUEST["prtfl_technologies_text_field"]; |
|
713 |
|
714 $prtfl_request_options["prtfl_slug"] = trim( $_REQUEST['prtfl_slug'] ); |
|
715 $prtfl_request_options["prtfl_slug"] = strtolower($prtfl_request_options["prtfl_slug"]); |
|
716 $prtfl_request_options["prtfl_slug"] = preg_replace("/[^a-z0-9\s-]/", "", $prtfl_request_options["prtfl_slug"]); |
|
717 $prtfl_request_options["prtfl_slug"] = trim(preg_replace("/[\s-]+/", " ", $prtfl_request_options["prtfl_slug"])); |
|
718 $prtfl_request_options["prtfl_slug"] = preg_replace("/\s/", "-", $prtfl_request_options["prtfl_slug"]); |
|
719 |
|
720 // for revrite prtfl_slug |
|
721 global $wp_rewrite; |
|
722 $rules = get_option( 'rewrite_rules' ); |
|
723 prtfl_custom_permalinks( $rules ); |
|
724 $wp_rewrite->flush_rules(); |
|
725 |
|
726 // array merge incase this version has added new options |
|
727 $prtfl_options = array_merge( $prtfl_options, $prtfl_request_options ); |
|
728 |
|
729 // Check select one point in the blocks Arithmetic actions and Difficulty on settings page |
|
730 update_option( 'prtfl_options', $prtfl_options, '', 'yes' ); |
|
731 $message = __( "Settings saved.", 'portfolio' ); |
|
732 } |
|
733 |
|
734 if ( ! file_exists( get_stylesheet_directory() .'/portfolio.php' ) || ! file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) ) { |
|
735 $error .= __( 'The files "portfolio.php" and "portfolio-post.php" are not found in your theme directory. Please copy them from the directory `wp-content/plugins/portfolio/template/` to your theme directory for correct work of the Portfolio plugin', 'portfolio' ); |
|
736 } |
|
737 // Display form on the setting page |
|
738 ?> |
|
739 <div class="wrap"> |
|
740 <div class="icon32 icon32-bws" id="icon-options-general"></div> |
|
741 <h2><?php _e( 'Portfolio Settings', 'portfolio' ); ?></h2> |
|
742 <div class="updated fade" <?php if( ! isset( $_REQUEST['prtfl_form_submit'] ) || $error != "" ) echo "style=\"display:none\""; ?>><p><strong><?php echo $message; ?></strong></p></div> |
|
743 <div class="error" <?php if( "" == $error ) echo "style=\"display:none\""; ?>><p><strong><?php echo $error; ?></strong></p></div> |
|
744 <p><?php _e( "If you would like to add the Latest Portfolio Items to your page or post, just copy and paste this shortcode into your post or page:", 'portfolio' ); ?> [latest_portfolio_items count=3], <?php _e( 'where count=3 is a number of posts to show up in the portfolio.', 'portfolio' ); ?></p> |
|
745 <form method="post" action="admin.php?page=portfolio.php" id="prtfl_form_image_size"> |
|
746 <table class="form-table"> |
|
747 <tr valign="top"> |
|
748 <th scope="row"><?php _e('The album cover size', 'portfolio' ); ?> </th> |
|
749 <td> |
|
750 <label for="prtfl_custom_image_size_name"><?php _e( 'Image size name', 'portfolio' ); ?></label> <?php echo $prtfl_options["prtfl_custom_size_name"][0]; ?><br /> |
|
751 <label for="prtfl_custom_image_size_w"><?php _e( 'Width (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_w_album" value="<?php echo $prtfl_options["prtfl_custom_size_px"][0][0]; ?>" /><br /> |
|
752 <label for="prtfl_custom_image_size_h"><?php _e( 'Height (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_h_album" value="<?php echo $prtfl_options["prtfl_custom_size_px"][0][1]; ?>" /> |
|
753 </td> |
|
754 </tr> |
|
755 <tr valign="top"> |
|
756 <th scope="row"><?php _e('Size of portfolio images', 'portfolio' ); ?> </th> |
|
757 <td> |
|
758 <label for="prtfl_custom_image_size_name"><?php _e( 'Image size name', 'portfolio' ); ?></label> <?php echo $prtfl_options["prtfl_custom_size_name"][1]; ?><br /> |
|
759 <label for="prtfl_custom_image_size_w"><?php _e( 'Width (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_w_photo" value="<?php echo $prtfl_options["prtfl_custom_size_px"][1][0]; ?>" /><br /> |
|
760 <label for="prtfl_custom_image_size_h"><?php _e( 'Height (in px)', 'portfolio' ); ?></label> <input type="text" name="prtfl_custom_image_size_h_photo" value="<?php echo $prtfl_options["prtfl_custom_size_px"][1][1]; ?>" /> |
|
761 </td> |
|
762 </tr> |
|
763 <tr valign="top"> |
|
764 <td colspan="2"><span style="color: #888888;font-size: 10px;"><?php _e( 'WordPress will copy thumbnails with the specified dimensions when you upload a new image. It is necessary to click the Update images button at the bottom of this page in order to generate new images and set new dimensions', 'portfolio' ); ?></span></th> |
|
765 </tr> |
|
766 <tr valign="top"> |
|
767 <th scope="row"><?php _e('Sort portfolio by', 'portfolio' ); ?> </th> |
|
768 <td> |
|
769 <input class="prtfl_left" type="radio" name="prtfl_order_by" value="ID" <?php if( $prtfl_options["prtfl_order_by"] == 'ID' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order_by"><?php _e( 'portfolio id', 'gallery' ); ?></label><br /> |
|
770 <input class="prtfl_left" type="radio" name="prtfl_order_by" value="title" <?php if( $prtfl_options["prtfl_order_by"] == 'title' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order_by"><?php _e( 'portfolio title', 'gallery' ); ?></label><br /> |
|
771 <input class="prtfl_left" type="radio" name="prtfl_order_by" value="date" <?php if( $prtfl_options["prtfl_order_by"] == 'date' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order_by"><?php _e( 'date', 'gallery' ); ?></label><br /> |
|
772 <input class="prtfl_left" type="radio" name="prtfl_order_by" value="menu_order" <?php if( $prtfl_options["prtfl_order_by"] == 'menu_order' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order_by"><?php _e( 'menu order', 'gallery' ); ?></label><br /> |
|
773 <input class="prtfl_left" type="radio" name="prtfl_order_by" value="rand" <?php if( $prtfl_options["prtfl_order_by"] == 'rand' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order_by"><?php _e( 'random', 'gallery' ); ?></label> |
|
774 </td> |
|
775 </tr> |
|
776 <tr valign="top"> |
|
777 <th scope="row"><?php _e('Portfolio sorting', 'portfolio' ); ?> </th> |
|
778 <td> |
|
779 <input class="prtfl_left" type="radio" name="prtfl_order" value="ASC" <?php if( $prtfl_options["prtfl_order"] == 'ASC' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order"><?php _e( 'ASC (ascending order from lowest to highest values - 1, 2, 3; a, b, c)', 'gallery' ); ?></label><br /> |
|
780 <input class="prtfl_left" type="radio" name="prtfl_order" value="DESC" <?php if( $prtfl_options["prtfl_order"] == 'DESC' ) echo 'checked="checked"'; ?> /> <label class="label_radio prtfl_left" for="prtfl_order"><?php _e( 'DESC (descending order from highest to lowest values - 3, 2, 1; c, b, a)', 'gallery' ); ?></label> |
|
781 </td> |
|
782 </tr> |
|
783 <tr valign="top"> |
|
784 <th scope="row"><?php _e( 'Number of images in the row', 'portfolio' ); ?> </th> |
|
785 <td> |
|
786 <input type="text" name="prtfl_custom_image_row_count" value="<?php echo $prtfl_options["prtfl_custom_image_row_count"]; ?>" /> |
|
787 </td> |
|
788 </tr> |
|
789 <tr valign="top"> |
|
790 <th scope="row"><?php _e( 'Display additional fields', 'portfolio' ); ?> </th> |
|
791 <td> |
|
792 <input type="checkbox" name="prtfl_date_additional_field" value="1" id="prtfl_date_additional_field" <?php if( 1 == $prtfl_options['prtfl_date_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_date_additional_field" style="float:none;"><?php _e( 'Date', 'portfolio' ); ?></label> |
|
793 <input type="checkbox" name="prtfl_link_additional_field" value="1" id="prtfl_link_additional_field" <?php if( 1 == $prtfl_options['prtfl_link_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_link_additional_field" style="float:none;"><?php _e( 'Link', 'portfolio' ); ?></label> |
|
794 <input type="checkbox" name="prtfl_shrdescription_additional_field" value="1" id="prtfl_shrdescription_additional_field" <?php if( 1 == $prtfl_options['prtfl_shrdescription_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_shrdescription_additional_field" style="float:none;"><?php _e( 'Short Description', 'portfolio' ); ?></label> |
|
795 <input type="checkbox" name="prtfl_description_additional_field" value="1" id="prtfl_description_additional_field" <?php if( 1 == $prtfl_options['prtfl_description_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_description_additional_field" style="float:none;"><?php _e( 'Description', 'portfolio' ); ?></label> |
|
796 <input type="checkbox" name="prtfl_svn_additional_field" value="1" id="prtfl_svn_additional_field" <?php if( 1 == $prtfl_options['prtfl_svn_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_svn_additional_field" style="float:none;"><?php _e( 'SVN', 'portfolio' ); ?></label> |
|
797 <input type="checkbox" name="prtfl_executor_additional_field" value="1" id="prtfl_executor_additional_field" <?php if( 1 == $prtfl_options['prtfl_executor_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_executor_additional_field" style="float:none;"><?php _e( 'Executor', 'portfolio' ); ?></label> |
|
798 <input type="checkbox" name="prtfl_technologies_additional_field" value="1" id="prtfl_technologies_additional_field" <?php if( 1 == $prtfl_options['prtfl_technologies_additional_field'] ) echo "checked=\"checked\""; ?> /> <label for="prtfl_technologies_additional_field" style="float:none;"><?php _e( 'Technologies', 'portfolio' ); ?></label> |
|
799 </td> |
|
800 </tr> |
|
801 <tr valign="top"> |
|
802 <th scope="row"><?php _e( 'Display the link field as a text for non-registered users', 'portfolio' ); ?></th> |
|
803 <td> |
|
804 <input type="checkbox" name="prtfl_link_additional_field_for_non_registered" value="1" id="prtfl_link_additional_field_for_non_registered" <?php if( 1 == $prtfl_options['prtfl_link_additional_field_for_non_registered'] ) echo "checked=\"checked\""; ?> /> |
|
805 </td> |
|
806 </tr> |
|
807 <tr valign="top"> |
|
808 <th scope="row"><?php _e( 'Text for additional fields', 'portfolio' ); ?> </th> |
|
809 <td> |
|
810 <label for="prtfl_date_text_field"><?php _e( 'Date of completion:', 'portfolio' ); ?></label> <input type="text" name="prtfl_date_text_field" value="<?php echo $prtfl_options["prtfl_date_text_field"]; ?>" /><br /> |
|
811 <label for="prtfl_link_text_field"><?php _e( 'Link:', 'portfolio' ); ?></label> <input type="text" name="prtfl_link_text_field" value="<?php echo $prtfl_options["prtfl_link_text_field"]; ?>" /><br /> |
|
812 <label for="prtfl_shrdescription_text_field"><?php _e( 'Short description:', 'portfolio' ); ?></label> <input type="text" name="prtfl_shrdescription_text_field" value="<?php echo $prtfl_options["prtfl_shrdescription_text_field"]; ?>" /><br /> |
|
813 <label for="prtfl_description_text_field"><?php _e( 'Description:', 'portfolio' ); ?></label> <input type="text" name="prtfl_description_text_field" value="<?php echo $prtfl_options["prtfl_description_text_field"]; ?>" /><br /> |
|
814 <label for="prtfl_svn_text_field"><?php _e( 'SVN:', 'portfolio' ); ?></label> <input type="text" name="prtfl_svn_text_field" value="<?php echo $prtfl_options["prtfl_svn_text_field"]; ?>" /><br /> |
|
815 <label for="prtfl_executor_text_field"><?php _e( 'Executor Profile:', 'portfolio' ); ?></label> <input type="text" name="prtfl_executor_text_field" value="<?php echo $prtfl_options["prtfl_executor_text_field"]; ?>" /><br /> |
|
816 <label for="prtfl_screenshot_text_field"><?php _e( 'More screenshots:', 'portfolio' ); ?></label> <input type="text" name="prtfl_screenshot_text_field" value="<?php echo $prtfl_options["prtfl_screenshot_text_field"]; ?>" /><br /> |
|
817 <label for="prtfl_technologies_text_field"><?php _e( 'Technologies:', 'portfolio' ); ?></label> <input type="text" name="prtfl_technologies_text_field" value="<?php echo $prtfl_options["prtfl_technologies_text_field"]; ?>" /> |
|
818 </td> |
|
819 </tr> |
|
820 <tr valign="top"> |
|
821 <th scope="row"><?php _e( 'Slug for portfolio item', 'portfolio' ); ?></th> |
|
822 <td> |
|
823 <input type="text" name="prtfl_slug" value="<?php echo $prtfl_options["prtfl_slug"]; ?>" /> <span style="color: #888888;font-size: 10px;"><?php _e( 'for any structure of permalinks except the default structure', 'portfolio' ); ?></span> |
|
824 </td> |
|
825 </tr> |
|
826 </table> |
|
827 <input type="hidden" name="prtfl_form_submit" value="submit" /> |
|
828 <p class="submit"> |
|
829 <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
|
830 </p> |
|
831 <?php wp_nonce_field( plugin_basename(__FILE__), 'prtfl_nonce_name' ); ?> |
|
832 </form> |
|
833 <?php global $wpdb; |
|
834 if( get_option( 'prtfl_tag_update' ) == '1' ) |
|
835 $prefix = '_prtfl'; |
|
836 else |
|
837 $prefix = '_prtf'; |
|
838 if ( $wpdb->get_var( "SELECT meta_id FROM ".$wpdb->postmeta." WHERE meta_key = '".$prefix."_short_descr' LIMIT 1" ) != NULL ) { ?> |
|
839 <table class="form-table"> |
|
840 <tr valign="top"> |
|
841 <th scope="row"><?php _e( 'Change the way to store your post_meta information for portfolio', 'portfolio' ); ?> </th> |
|
842 <td style="position:relative"> |
|
843 <input type="button" value="<?php _e( 'Update All Info' ); ?>" id="ajax_update_postmeta" name="ajax_update_postmeta" class="button" onclick="javascript:update_postmeta();"> <div id="prtfl_loader"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" alt="loader" /></div> |
|
844 </td> |
|
845 </tr> |
|
846 </table> |
|
847 <script type="text/javascript"> |
|
848 var update_message = "<?php _e( 'Updating post_meta information...', 'portfolio' ) ?>"; |
|
849 var not_found_info = "<?php _e( 'No portfolio item found', 'portfolio'); ?>"; |
|
850 var success = "<?php _e( 'All info is updated', 'portfolio' ); ?>"; |
|
851 var error = "<?php _e( 'Error.', 'portfolio' ); ?>"; |
|
852 </script> |
|
853 <?php } ?> |
|
854 <table class="form-table"> |
|
855 <tr valign="top"> |
|
856 <th scope="row"><?php _e( 'Update images for portfolio', 'portfolio' ); ?> </th> |
|
857 <td style="position:relative"> |
|
858 <input type="button" value="<?php _e( 'Update images' ); ?>" id="ajax_update_images" name="ajax_update_images" class="button" onclick="javascript:update_images();"> <div id="prtfl_img_loader"><img src="<?php echo plugins_url( 'images/ajax-loader.gif', __FILE__ ); ?>" alt="loader" /></div> |
|
859 </td> |
|
860 </tr> |
|
861 </table> |
|
862 <script type="text/javascript"> |
|
863 var update_img_message = "<?php _e( 'Updating images...', 'portfolio' ) ?>"; |
|
864 var not_found_img_info = "<?php _e( 'No image found', 'portfolio'); ?>"; |
|
865 var img_success = "<?php _e( 'All images are updated', 'portfolio' ); ?>"; |
|
866 var img_error = "<?php _e( 'Error.', 'portfolio' ); ?>"; |
|
867 </script> |
|
868 </div> |
|
869 <?php } |
|
870 } |
|
871 |
|
872 if ( ! function_exists( 'prtfl_template_redirect' ) ) { |
|
873 function prtfl_template_redirect() { |
|
874 global $wp_query, $post, $posts; |
|
875 if ( 'portfolio' == get_post_type() && "" == $wp_query->query_vars["s"] && ! isset( $wp_query->query_vars["technologies"] ) ) { |
|
876 include( get_stylesheet_directory() . '/portfolio-post.php' ); |
|
877 exit(); |
|
878 } else if ( 'portfolio' == get_post_type() && isset( $wp_query->query_vars["technologies"] ) ) { |
|
879 include( get_stylesheet_directory() . '/portfolio.php' ); |
|
880 exit(); |
|
881 } |
|
882 } |
|
883 } |
|
884 |
|
885 if ( ! function_exists ( 'prtfl_add_template_in_new_theme' ) ) { |
|
886 function prtfl_add_template_in_new_theme() { |
|
887 if ( ! file_exists( get_stylesheet_directory() .'/portfolio.php' ) || ! file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) ) |
|
888 prtfl_plugin_install(); |
|
889 } |
|
890 } |
|
891 |
|
892 if ( ! function_exists ( 'prtfl_plugin_action_links' ) ) { |
|
893 function prtfl_plugin_action_links( $links, $file ) { |
|
894 //Static so we don't call plugin_basename on every plugin row. |
|
895 static $this_plugin; |
|
896 if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ ); |
|
897 |
|
898 if ( $file == $this_plugin ) { |
|
899 $settings_link = '<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>'; |
|
900 array_unshift( $links, $settings_link ); |
|
901 } |
|
902 return $links; |
|
903 } |
|
904 } |
|
905 |
|
906 if ( ! function_exists( 'prtfl_add_portfolio_ancestor_to_menu' ) ) { |
|
907 function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) { |
|
908 if ( is_singular( 'portfolio' ) ) { |
|
909 global $wpdb, $post; |
|
910 $parent = $wpdb->get_var( "SELECT $wpdb->posts.post_name FROM $wpdb->posts, $wpdb->postmeta WHERE meta_key = '_wp_page_template' AND meta_value = 'portfolio.php' AND (post_status = 'publish' OR post_status = 'private') AND $wpdb->posts.ID = $wpdb->postmeta.post_id" ); |
|
911 |
|
912 if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) ) { |
|
913 $classes[] = 'current-page-ancestor'; |
|
914 } |
|
915 } |
|
916 return $classes; |
|
917 } |
|
918 } |
|
919 |
|
920 if ( ! function_exists( 'prtfl_latest_items' ) ) { |
|
921 function prtfl_latest_items( $atts ) { |
|
922 $content = '<div class="prtfl_portfolio_block">'; |
|
923 $args = array( |
|
924 'post_type' => 'portfolio', |
|
925 'post_status' => 'publish', |
|
926 'orderby' => 'date', |
|
927 'order' => 'DESC', |
|
928 'posts_per_page' => $atts['count'], |
|
929 ); |
|
930 query_posts( $args ); |
|
931 |
|
932 while ( have_posts() ) : the_post(); |
|
933 $content .= ' |
|
934 <div class="portfolio_content"> |
|
935 <div class="entry">'; |
|
936 global $post; |
|
937 $meta_values = get_post_custom($post->ID); |
|
938 $post_thumbnail_id = get_post_thumbnail_id( $post->ID ); |
|
939 if( empty ( $post_thumbnail_id ) ) { |
|
940 $args = array( |
|
941 'post_parent' => $post->ID, |
|
942 'post_type' => 'attachment', |
|
943 'post_mime_type' => 'image', |
|
944 'numberposts' => 1 |
|
945 ); |
|
946 $attachments = get_children( $args ); |
|
947 $post_thumbnail_id = key($attachments); |
|
948 } |
|
949 $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' ); |
|
950 $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ); |
|
951 $image_desc = get_post($post_thumbnail_id); |
|
952 $image_desc = $image_desc->post_content; |
|
953 if( get_option( 'prtfl_postmeta_update' ) == '1' ) { |
|
954 $post_meta = get_post_meta( $post->ID, 'prtfl_information', true); |
|
955 $date_compl = $post_meta['_prtfl_date_compl']; |
|
956 if( ! empty( $date_compl ) && 'in progress' != $date_compl) { |
|
957 $date_compl = explode( "/", $date_compl ); |
|
958 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) ); |
|
959 } |
|
960 $link = $post_meta['_prtfl_link']; |
|
961 $short_descr = $post_meta['_prtfl_short_descr']; |
|
962 } else { |
|
963 $date_compl = get_post_meta( $post->ID, '_prtfl_date_compl', true ); |
|
964 if( ! empty( $date_compl ) && 'in progress' != $date_compl) { |
|
965 $date_compl = explode( "/", $date_compl ); |
|
966 $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) ); |
|
967 } |
|
968 $link = get_post_meta($post->ID, '_prtfl_link', true); |
|
969 $short_descr = get_post_meta($post->ID, '_prtfl_short_descr', true); |
|
970 } |
|
971 |
|
972 $content .= '<div class="portfolio_thumb" style="width:165px"> |
|
973 <img src="'.$image[0].'" width="'.$image[1].'" alt="'.$image_alt.'" /> |
|
974 </div> |
|
975 <div class="portfolio_short_content"> |
|
976 <div class="item_title"> |
|
977 <p> |
|
978 <a href="'.get_permalink().'" rel="bookmark">'.get_the_title().'</a> |
|
979 </p> |
|
980 </div> <!-- .item_title -->'; |
|
981 $content .= '<p>'.$short_descr.'</p> |
|
982 </div> <!-- .portfolio_short_content --> |
|
983 </div> <!-- .entry --> |
|
984 <div class="read_more"> |
|
985 <a href="'.get_permalink().'" rel="bookmark">'.__( 'Read more', 'portfolio' ).'</a> |
|
986 </div> <!-- .read_more --> |
|
987 <div class="portfolio_terms">'; |
|
988 $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' ) ; |
|
989 if ( is_array( $terms ) && count( $terms ) > 0) { |
|
990 $content .= __( 'Technologies', 'portfolio' ).':'; |
|
991 $count = 0; |
|
992 foreach ( $terms as $term ) { |
|
993 if( $count > 0 ) |
|
994 $content .= ', '; |
|
995 $content .= '<a href="'. get_term_link( $term->slug, 'portfolio_technologies') . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a>'; |
|
996 $count++; |
|
997 } |
|
998 } else { |
|
999 $content .= ' '; |
|
1000 } |
|
1001 $content .= '</div><!-- .portfolio_terms -->'; |
|
1002 $content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content -->'; |
|
1003 endwhile; |
|
1004 $content .= '</div> <!-- .prtfl_portfolio_block -->'; |
|
1005 wp_reset_query(); |
|
1006 return $content; |
|
1007 } |
|
1008 } |
|
1009 |
|
1010 /* Register style and script files */ |
|
1011 if ( ! function_exists ( 'prtfl_admin_head' ) ) { |
|
1012 function prtfl_admin_head() { |
|
1013 wp_enqueue_style( 'prtflStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) ); |
|
1014 wp_enqueue_style( 'prtflDatepickerStylesheet', plugins_url( 'datepicker/datepicker.css', __FILE__ ) ); |
|
1015 wp_enqueue_script( 'jquery' ); |
|
1016 wp_enqueue_script( 'prtflScript', plugins_url( 'js/script.js', __FILE__ ) ); |
|
1017 wp_enqueue_script( 'prtflDatepickerScript', plugins_url( 'datepicker/datepicker.js', __FILE__ ) ); |
|
1018 |
|
1019 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) |
|
1020 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) ); |
|
1021 } |
|
1022 } |
|
1023 |
|
1024 if ( ! function_exists ( 'prtfl_wp_head' ) ) { |
|
1025 function prtfl_wp_head() { |
|
1026 wp_enqueue_style( 'prtflLightboxStylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) ); |
|
1027 wp_enqueue_style( 'prtflStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) ); |
|
1028 |
|
1029 wp_enqueue_script( 'jquery' ); |
|
1030 wp_enqueue_script( 'prtflScript', plugins_url( 'js/script.js', __FILE__ ) ); |
|
1031 wp_enqueue_script( 'prtflFancyboxMousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) ); |
|
1032 wp_enqueue_script( 'prtflFancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) ); |
|
1033 } |
|
1034 } |
|
1035 |
|
1036 if ( ! function_exists ( 'prtfl_update_info' ) ) { |
|
1037 function prtfl_update_info(){ |
|
1038 global $wpdb; |
|
1039 $action = isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : ""; |
|
1040 $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : ""; |
|
1041 switch($action) { |
|
1042 case 'get_portfolio_id': |
|
1043 $result = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'portfolio'" ); |
|
1044 echo json_encode( $result ); |
|
1045 break; |
|
1046 case 'update_info': |
|
1047 if( $id != "" && is_numeric( $id ) ) { |
|
1048 $result = $wpdb->get_results( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key LIKE '_prtf%' AND post_id = " . $id ); |
|
1049 if( ! empty( $result ) ) { |
|
1050 $new_post_meta = array(); |
|
1051 foreach( $result as $value ) { |
|
1052 $new_post_meta[ $value->meta_key ] = $value->meta_value; |
|
1053 } |
|
1054 add_post_meta($id, 'prtfl_information', $new_post_meta); |
|
1055 $wpdb->query( "DELETE FROM " . $wpdb->postmeta . " WHERE meta_key LIKE '_prtf%' AND post_id = " . $id ); |
|
1056 } |
|
1057 $post_meta = get_post_meta($id, 'prtfl_information', true); |
|
1058 $wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->posts . " SET post_content = '%s' WHERE ID = " . $id, $post_meta["_prtfl_short_descr"] ) ); |
|
1059 } |
|
1060 break; |
|
1061 case 'update_options': |
|
1062 add_option( 'prtfl_postmeta_update', '1', '', 'no' ); |
|
1063 break; |
|
1064 } |
|
1065 die(); |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 if ( ! function_exists ( 'prtfl_update_image' ) ) { |
|
1070 function prtfl_update_image(){ |
|
1071 global $wpdb; |
|
1072 $action = isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : ""; |
|
1073 $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : ""; |
|
1074 switch($action) { |
|
1075 case 'get_all_attachment': |
|
1076 $result_parent_id = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'portfolio' ) , ARRAY_N ); |
|
1077 $array_parent_id = array(); |
|
1078 |
|
1079 while(list($key, $val) = each($result_parent_id)) |
|
1080 $array_parent_id[] = $val[0]; |
|
1081 |
|
1082 $string_parent_id = implode( ",", $array_parent_id ); |
|
1083 |
|
1084 $result_attachment_id = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'attachment' AND post_mime_type LIKE 'image%' AND post_parent IN (".$string_parent_id.")" ); |
|
1085 echo json_encode( $result_attachment_id ); |
|
1086 break; |
|
1087 case 'update_image': |
|
1088 $metadata = wp_get_attachment_metadata( $id ); |
|
1089 $uploads = wp_upload_dir(); |
|
1090 $path = $uploads['basedir']."/".$metadata['file']; |
|
1091 require_once( ABSPATH . 'wp-admin/includes/image.php' ); |
|
1092 $metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata ); |
|
1093 wp_update_attachment_metadata( $id, array_merge($metadata, $metadata_new) ); |
|
1094 break; |
|
1095 case 'update_options': |
|
1096 add_option( 'prtfl_images_update', '1', '', 'no' ); |
|
1097 break; |
|
1098 } |
|
1099 die(); |
|
1100 } |
|
1101 } |
|
1102 |
|
1103 if ( ! function_exists ( 'prtfl_wp_generate_attachment_metadata' ) ) { |
|
1104 function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) { |
|
1105 $attachment = get_post( $attachment_id ); |
|
1106 $prtfl_options = get_option( 'prtfl_options' ); |
|
1107 |
|
1108 add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true ); |
|
1109 add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true ); |
|
1110 |
|
1111 $metadata = array(); |
|
1112 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { |
|
1113 $imagesize = getimagesize( $file ); |
|
1114 $metadata['width'] = $imagesize[0]; |
|
1115 $metadata['height'] = $imagesize[1]; |
|
1116 list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96); |
|
1117 $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'"; |
|
1118 |
|
1119 // Make the file path relative to the upload dir |
|
1120 $metadata['file'] = _wp_relative_upload_path($file); |
|
1121 |
|
1122 // make thumbnails and other intermediate sizes |
|
1123 global $_wp_additional_image_sizes; |
|
1124 |
|
1125 $image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb' );//get_intermediate_image_sizes(); |
|
1126 |
|
1127 foreach ( $image_size as $s ) { |
|
1128 $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE ); |
|
1129 if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) |
|
1130 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes |
|
1131 else |
|
1132 $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options |
|
1133 if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) |
|
1134 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes |
|
1135 else |
|
1136 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options |
|
1137 if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) |
|
1138 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes |
|
1139 else |
|
1140 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options |
|
1141 } |
|
1142 |
|
1143 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); |
|
1144 foreach ($sizes as $size => $size_data ) { |
|
1145 $resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] ); |
|
1146 if ( $resized ) |
|
1147 $metadata['sizes'][$size] = $resized; |
|
1148 } |
|
1149 |
|
1150 // fetch additional metadata from exif/iptc |
|
1151 $image_meta = wp_read_image_metadata( $file ); |
|
1152 if ( $image_meta ) |
|
1153 $metadata['image_meta'] = $image_meta; |
|
1154 |
|
1155 } |
|
1156 |
|
1157 return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); |
|
1158 } |
|
1159 } |
|
1160 |
|
1161 if ( ! function_exists ( 'prtfl_image_make_intermediate_size' ) ) { |
|
1162 function prtfl_image_make_intermediate_size( $file, $width, $height, $crop=false ) { |
|
1163 if ( $width || $height ) { |
|
1164 $resized_file = prtfl_image_resize( $file, $width, $height, $crop ); |
|
1165 if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize( $resized_file ) ) { |
|
1166 $resized_file = apply_filters('image_make_intermediate_size', $resized_file); |
|
1167 return array( |
|
1168 'file' => wp_basename( $resized_file ), |
|
1169 'width' => $info[0], |
|
1170 'height' => $info[1], |
|
1171 ); |
|
1172 } |
|
1173 } |
|
1174 return false; |
|
1175 } |
|
1176 } |
|
1177 |
|
1178 if ( ! function_exists ( 'prtfl_image_resize' ) ) { |
|
1179 function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) { |
|
1180 |
|
1181 $size = @getimagesize( $file ); |
|
1182 if ( !$size ) |
|
1183 return new WP_Error('invalid_image', __('Image size not defined'), $file); |
|
1184 |
|
1185 $type = $size[2]; |
|
1186 |
|
1187 if ( $type == 3 ) |
|
1188 $image = imagecreatefrompng($file); |
|
1189 else if ( $type == 2 ) |
|
1190 $image = imagecreatefromjpeg($file); |
|
1191 else if ( $type == 1 ) |
|
1192 $image = imagecreatefromgif($file); |
|
1193 else if ( $type == 15 ) |
|
1194 $image = imagecreatefromwbmp($file); |
|
1195 else if ( $type == 16 ) |
|
1196 $image = imagecreatefromxbm($file); |
|
1197 else |
|
1198 return new WP_Error('invalid_image', __('We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other, please, manually reload image.'), $file ); |
|
1199 |
|
1200 if ( !is_resource( $image ) ) |
|
1201 return new WP_Error( 'error_loading_image', $image, $file ); |
|
1202 |
|
1203 //$size = @getimagesize( $file ); |
|
1204 list( $orig_w, $orig_h, $orig_type ) = $size; |
|
1205 |
|
1206 $dims = prtfl_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop); |
|
1207 |
|
1208 if ( !$dims ) |
|
1209 return new WP_Error( 'error_getting_dimensions', __('Image size changes not defined') ); |
|
1210 list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
|
1211 |
|
1212 $newimage = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
1213 |
|
1214 imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
1215 |
|
1216 // convert from full colors to index colors, like original PNG. |
|
1217 if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) ) |
|
1218 imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) ); |
|
1219 |
|
1220 // we don't need the original in memory anymore |
|
1221 imagedestroy( $image ); |
|
1222 |
|
1223 // $suffix will be appended to the destination filename, just before the extension |
|
1224 if ( !$suffix ) |
|
1225 $suffix = "{$dst_w}x{$dst_h}"; |
|
1226 |
|
1227 $info = pathinfo($file); |
|
1228 $dir = $info['dirname']; |
|
1229 $ext = $info['extension']; |
|
1230 $name = wp_basename($file, ".$ext"); |
|
1231 |
|
1232 if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) ) |
|
1233 $dir = $_dest_path; |
|
1234 $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; |
|
1235 |
|
1236 if ( IMAGETYPE_GIF == $orig_type ) { |
|
1237 if ( !imagegif( $newimage, $destfilename ) ) |
|
1238 return new WP_Error('resize_path_invalid', __( 'Invalid path' )); |
|
1239 } elseif ( IMAGETYPE_PNG == $orig_type ) { |
|
1240 if ( !imagepng( $newimage, $destfilename ) ) |
|
1241 return new WP_Error('resize_path_invalid', __( 'Invalid path' )); |
|
1242 } else { |
|
1243 // all other formats are converted to jpg |
|
1244 $destfilename = "{$dir}/{$name}-{$suffix}.jpg"; |
|
1245 if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) |
|
1246 return new WP_Error('resize_path_invalid', __( 'Invalid path' )); |
|
1247 } |
|
1248 |
|
1249 imagedestroy( $newimage ); |
|
1250 |
|
1251 // Set correct file permissions |
|
1252 $stat = stat( dirname( $destfilename )); |
|
1253 $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits |
|
1254 @ chmod( $destfilename, $perms ); |
|
1255 |
|
1256 return $destfilename; |
|
1257 } |
|
1258 } |
|
1259 |
|
1260 if ( ! function_exists ( 'prtfl_image_resize_dimensions' ) ) { |
|
1261 function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) { |
|
1262 |
|
1263 if ( $orig_w <= 0 || $orig_h <= 0 ) |
|
1264 return false; |
|
1265 // at least one of dest_w or dest_h must be specific |
|
1266 if ( $dest_w <= 0 && $dest_h <= 0 ) |
|
1267 return false; |
|
1268 |
|
1269 if ( $crop ) { |
|
1270 // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h |
|
1271 $aspect_ratio = $orig_w / $orig_h; |
|
1272 $new_w = min($dest_w, $orig_w); |
|
1273 $new_h = min($dest_h, $orig_h); |
|
1274 |
|
1275 if ( !$new_w ) { |
|
1276 $new_w = intval($new_h * $aspect_ratio); |
|
1277 } |
|
1278 |
|
1279 if ( !$new_h ) { |
|
1280 $new_h = intval($new_w / $aspect_ratio); |
|
1281 } |
|
1282 |
|
1283 $size_ratio = max($new_w / $orig_w, $new_h / $orig_h); |
|
1284 |
|
1285 $crop_w = round($new_w / $size_ratio); |
|
1286 $crop_h = round($new_h / $size_ratio); |
|
1287 |
|
1288 $s_x = floor( ($orig_w - $crop_w) / 2 ); |
|
1289 $s_y = 0; |
|
1290 } else { |
|
1291 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box |
|
1292 $crop_w = $orig_w; |
|
1293 $crop_h = $orig_h; |
|
1294 |
|
1295 $s_x = 0; |
|
1296 $s_y = 0; |
|
1297 |
|
1298 list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h ); |
|
1299 } |
|
1300 |
|
1301 // if the resulting image would be the same size or larger we don't want to resize it |
|
1302 if ( $new_w >= $orig_w && $new_h >= $orig_h ) |
|
1303 return false; |
|
1304 |
|
1305 // the return array matches the parameters to imagecopyresampled() |
|
1306 // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h |
|
1307 return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); |
|
1308 } |
|
1309 } |
|
1310 |
|
1311 register_activation_hook( __FILE__, 'prtfl_plugin_install'); // activate plugin |
|
1312 register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' ); // deactivate plugin |
|
1313 |
|
1314 // adds "Settings" link to the plugin action page |
|
1315 add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 ); |
|
1316 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 ); |
|
1317 |
|
1318 //Additional links on the plugin page |
|
1319 add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 ); |
|
1320 |
|
1321 add_action( 'admin_init', 'prtfl_admin_error' ); |
|
1322 |
|
1323 add_action( 'admin_menu', 'add_prtfl_admin_menu' ); // add portfolio settings page in admin menu |
|
1324 add_action( 'init', 'prtfl_plugin_init' ); // add language file |
|
1325 |
|
1326 add_action( 'init', 'prtfl_taxonomy_portfolio' ); // register taxonomy for portfolio |
|
1327 add_action( 'init', 'prtfl_post_type_portfolio' ); // register post type |
|
1328 add_action( 'init', 'prtfl_register_widget' ); // add widget for portfolio technologies |
|
1329 add_action( 'save_post', 'prtfl_save_postdata', 1, 2 ); // save custom data from admin |
|
1330 add_filter( 'pre_get_posts', 'prtfl_technologies_get_posts' ); // display tachnologies taxonomy |
|
1331 add_action( 'template_redirect', 'prtfl_template_redirect' ); // add template for single gallery page |
|
1332 |
|
1333 //add_action( 'init', 'prtfl_custom_permalinks' ); // add custom permalink for portfolio |
|
1334 add_filter( 'rewrite_rules_array', 'prtfl_custom_permalinks' ); // add custom permalink for gallery |
|
1335 add_action( 'wp_loaded', 'prtfl_flush_rules' ); |
|
1336 |
|
1337 add_action( 'after_setup_theme', 'prtfl_add_template_in_new_theme' ); // add template in theme after activate new theme |
|
1338 |
|
1339 add_shortcode('latest_portfolio_items', 'prtfl_latest_items'); |
|
1340 |
|
1341 add_action( 'admin_enqueue_scripts', 'prtfl_admin_head' ); |
|
1342 add_action( 'wp_enqueue_scripts', 'prtfl_wp_head' ); |
|
1343 |
|
1344 add_action( 'wp_ajax_prtfl_update_info', 'prtfl_update_info' ); |
|
1345 add_action( 'wp_ajax_prtfl_update_image', 'prtfl_update_image' ); |
|
1346 ?> |