diff -r 346c88efed21 -r 5e2f62d02dcd wp/wp-content/plugins/portfolio/portfolio.php
--- a/wp/wp-content/plugins/portfolio/portfolio.php Mon Jun 08 16:11:51 2015 +0000
+++ b/wp/wp-content/plugins/portfolio/portfolio.php Tue Jun 09 03:35:32 2015 +0200
@@ -1,394 +1,715 @@
';
+ wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => 'portfolio_technologies', 'number' => 0 ) ) );
+ echo "
\n";
+ echo $args['after_widget'];
+ }
+ /* Function to save widget settings */
+ function update( $new_instance, $old_instance ) {
+ $instance = array();
+ $instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;
+ return $instance;
+ }
+ /* Function to displaying widget settings in back end */
+ function form( $instance ) {
+ $widget_title = isset( $instance['widget_title'] ) ? stripslashes( esc_html( $instance['widget_title'] ) ) : null; ?>
+ '.
- '
%2$s
'.
- '
'.
- '
'. $description .'
'.
+ '
' .
+ '
%2$s
' .
+ '
' .
+ '
' . $description .'
' .
'
';
- if ( '_prtfl_date_compl' == $args[0] ) {
+ if ( '_prtfl_date_compl' == $args[0] )
echo '';
- }
- return vsprintf( $label_format, $args );
- }
-}
-
-// This is the text area meta box
-if ( ! function_exists( 'prtfl_prtfl_text_area' ) ) {
- function prtfl_text_area( $args ) {
- global $post;
-
- $description = $args[2];
- $args[2] = esc_html( get_post_meta( $post->ID, $args[0], true ) );
- $label_format =
- '
'.
- '
%2$s
'.
- '
'.
- '
'. $description .'
'.
- '
';
return vsprintf( $label_format, $args );
}
}
@@ -462,91 +865,49 @@
function prtfl_save_postdata( $post_id, $post ) {
global $prtfl_boxes;
- if ( "portfolio" == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { // don't store custom data twice
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if( ! current_user_can ( 'edit_page', $post->ID ) ) {
+ register_prtfl_settings();
+
+ if ( "portfolio" == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { /* Don't store custom data twice */
+ /* Verify this came from the our screen and with proper authorization, because save_post can be triggered at other times */
+ if ( ! current_user_can ( 'edit_page', $post->ID ) ) {
return $post->ID;
- }
- // We'll put it into an array to make it easier to loop though.
- // The data is already in $prtfl_boxes, but we need to flatten it out.
- foreach( $prtfl_boxes as $prtfl_boxe ) {
- foreach( $prtfl_boxe as $prtfl_fields ) {
- $my_data[ $prtfl_fields[0] ] = $_POST[ $prtfl_fields[0] ];
- }
}
- // Add values of $my_data as custom fields
- // Let's cycle through the $my_data array!
- if( get_option( 'prtfl_postmeta_update' ) == '1' ) {
- if( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
- // Custom field has a value and this custom field exists in database
- update_post_meta( $post->ID, 'prtfl_information', $my_data );
- }
- elseif( $value ) {
- // Custom field has a value, but this custom field does not exist in database
- add_post_meta( $post->ID, 'prtfl_information', $my_data );
+ /* We'll put it into an array to make it easier to loop though. The data is already in $prtfl_boxes, but we need to flatten it out. */
+ foreach ( $prtfl_boxes as $prtfl_boxe ) {
+ foreach ( $prtfl_boxe as $prtfl_fields ) {
+ if ( $prtfl_fields[0] == '_prtfl_link' || $prtfl_fields[0] == '_prtfl_svn' )
+ $my_data[ $prtfl_fields[0] ] = esc_url( $_POST[ $prtfl_fields[0] ] );
+ else
+ $my_data[ $prtfl_fields[0] ] = stripslashes( esc_html( $_POST[ $prtfl_fields[0] ] ) );
}
- else {
- // Custom field does not have a value, but this custom field exists in database
- update_post_meta( $post->ID, 'prtfl_information', $my_data );
- }
+ }
+ /* Add values of $my_data as custom fields. Let's cycle through the $my_data array! */
+ if ( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
+ /* Custom field has a value and this custom field exists in database */
+ update_post_meta( $post->ID, 'prtfl_information', $my_data );
+ } elseif ( $value ) {
+ /* Custom field has a value, but this custom field does not exist in database */
+ add_post_meta( $post->ID, 'prtfl_information', $my_data );
} else {
- foreach( $my_data as $key => $value ) {
- // if $value is an array, make it a CSV (unlikely)
- $value = implode( ',', ( array ) $value );
- if( get_post_meta( $post->ID, $key, FALSE ) && $value ) {
- // Custom field has a value and this custom field exists in database
- update_post_meta( $post->ID, $key, $value );
- }
- elseif( $value ) {
- // Custom field has a value, but this custom field does not exist in database
- add_post_meta( $post->ID, $key, $value );
- }
- else {
- // Custom field does not have a value, but this custom field exists in database
- update_post_meta( $post->ID, $key, $value );
- }
- }
+ /* Custom field does not have a value, but this custom field exists in database */
+ update_post_meta( $post->ID, 'prtfl_information', $my_data );
}
}
}
}
-// This is pagenation functionality for portfolio post type
-if ( ! function_exists ( 'prtfl_pagination' ) ) {
- function prtfl_pagination( $pages = '', $range = 2 ) {
- $showitems = get_option( 'posts_per_page' );
-
- global $paged, $wp_query;
- if ( empty ( $paged ) )
- $paged = 1;
- if ( '' == $pages ) {
- $pages = $wp_query->max_num_pages;
- if( ! $pages ) {
- $pages = 1;
- }
- }
-
- if ( 1 != $pages ) {
- echo "\n";
+/**
+ * Replace shortcode [latest_portfolio_items] from portfolio content before portfolio saving
+ */
+if ( ! function_exists ( 'prtfl_content_save_pre' ) ) {
+ function prtfl_content_save_pre( $content ) {
+ global $post;
+ if ( isset( $post ) && "portfolio" == $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
+ /* remove shortcode */
+ $content = preg_replace( '/\[latest_portfolio_items count=[\d]*\]/', '', $content );
}
+ return $content;
}
}
@@ -554,364 +915,67 @@
function prtfl_register_plugin_links( $links, $file ) {
$base = plugin_basename(__FILE__);
if ( $file == $base ) {
- $links[] = '
' . __( 'Settings', 'portfolio' ) . ' ';
- $links[] = '
' . __( 'FAQ', 'portfolio' ) . ' ';
- $links[] = '
' . __( 'Support', 'portfolio' ) . ' ';
+ if ( ! is_network_admin() )
+ $links[] = '
' . __( 'Settings', 'portfolio' ) . ' ';
+ $links[] = '
' . __( 'FAQ', 'portfolio' ) . ' ';
+ $links[] = '
' . __( 'Support', 'portfolio' ) . ' ';
+ }
+ return $links;
+ }
+}
+
+if ( ! function_exists ( 'prtfl_plugin_action_links' ) ) {
+ function prtfl_plugin_action_links( $links, $file ) {
+ if ( ! is_network_admin() ) {
+ /* Static so we don't call plugin_basename on every plugin row. */
+ static $this_plugin;
+ if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
+
+ if ( $file == $this_plugin ) {
+ $settings_link = '
' . __( 'Settings', 'portfolio' ) . ' ';
+ array_unshift( $links, $settings_link );
+ }
}
return $links;
}
}
-if ( ! function_exists ( 'prtfl_replace_old_post_tag' ) ) {
- function prtfl_replace_old_post_tag() {
- global $wpdb;
- if ( false === get_option( 'prtfl_tag_update' ) ) {
- $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" );
- while( list( $key, $val ) = each( $tag_id_array ) ) {
- $wpdb->update(
- $wpdb->term_taxonomy,
- array(
- 'taxonomy' => 'portfolio_technologies'
- ),
- array(
- 'taxonomy' => 'post_tag' ,
- 'term_taxonomy_id' => $val->term_taxonomy_id
- ),
- array(
- '%s'
- ),
- array(
- '%s',
- '%d'
- )
- );
+
+if ( ! function_exists( 'prtfl_template_redirect' ) ) {
+ function prtfl_template_redirect() {
+ global $wp_query, $post, $posts, $prtfl_filenames, $prtfl_themepath;
+ if ( 'portfolio' == get_post_type() && "" == $wp_query->query_vars["s"] && ! isset( $wp_query->query_vars["technologies"] ) && ! isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
+ $file_exists_flag = true;
+ foreach ( $prtfl_filenames as $filename ) {
+ if ( ! file_exists( $prtfl_themepath . $filename ) )
+ $file_exists_flag = false;
}
- $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' " );
- $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = '_prtfl_short_descr'" );
- $wpdb->query( "UPDATE $wpdb->postmeta SET meta_key = REPLACE(meta_key, 'prtf_', 'prtfl_') WHERE meta_key LIKE '_prtf_%'" );
- add_option( 'prtfl_tag_update', '1', '', 'no' );
- }
- $postmeta = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta WHERE meta_key LIKE '%_short_descr%' LIMIT 0 , 1" );
- if ( empty( $postmeta ) && ! get_option( 'prtfl_postmeta_update' ) ) {
- add_option( 'prtfl_postmeta_update', 1 );
- }
- }
-}
-
-require_once( dirname( __FILE__ ) . '/bws_menu/bws_menu.php' );
-
-if ( ! function_exists( 'add_prtfl_admin_menu' ) ) {
- function add_prtfl_admin_menu() {
- add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( "images/px.png", __FILE__ ), 1001 );
- add_submenu_page( 'bws_plugins', __( 'Portfolio', 'portfolio' ), __( 'Portfolio', 'portfolio' ), 'manage_options', "portfolio.php", 'prtfl_settings_page' );
-
- //call register settings function
- add_action( 'admin_init', 'register_prtfl_settings' );
- }
-}
-
-// register settings function
-if ( ! function_exists( 'register_prtfl_settings' ) ) {
- function register_prtfl_settings() {
- global $wpmu, $prtfl_options;
-
- $prtfl_option_defaults = array(
- 'prtfl_custom_size_name' => array( 'portfolio-thumb', 'portfolio-photo-thumb' ),
- 'prtfl_custom_size_px' => array( array( 280, 300 ), array( 240, 260 ) ),
- 'prtfl_order_by' => 'menu_order',
- 'prtfl_order' => 'ASC',
- 'prtfl_custom_image_row_count' => 3,
- 'prtfl_date_additional_field' => 1,
- 'prtfl_link_additional_field' => 1,
- 'prtfl_shrdescription_additional_field' => 1,
- 'prtfl_description_additional_field' => 1,
- 'prtfl_svn_additional_field' => 1,
- 'prtfl_executor_additional_field' => 1,
- 'prtfl_technologies_additional_field' => 1,
- 'prtfl_link_additional_field_for_non_registered' => 1,
- 'prtfl_date_text_field' => __( 'Date of completion:', 'portfolio' ),
- 'prtfl_link_text_field' => __( 'Link:', 'portfolio' ),
- 'prtfl_shrdescription_text_field' => __( 'Short description:', 'portfolio' ),
- 'prtfl_description_text_field' => __( 'Description:', 'portfolio' ),
- 'prtfl_svn_text_field' => __( 'SVN:', 'portfolio' ),
- 'prtfl_executor_text_field' => __( 'Executor Profile:', 'portfolio' ),
- 'prtfl_screenshot_text_field' => __( 'More screenshots:', 'portfolio' ),
- 'prtfl_technologies_text_field' => __( 'Technologies:', 'portfolio' ),
- 'prtfl_slug' => 'portfolio'
- );
-
- // install the option defaults
- if ( 1 == $wpmu ) {
- if( !get_site_option( 'prtfl_options' ) ) {
- add_site_option( 'prtfl_options', $prtfl_option_defaults, '', 'yes' );
+ if ( $file_exists_flag ) {
+ include( get_stylesheet_directory() . '/portfolio-post.php' );
+ exit();
}
- } else {
- if( ! get_option( 'prtfl_options' ) )
- add_option( 'prtfl_options', $prtfl_option_defaults, '', 'yes' );
- }
-
- // get options from the database
- if ( 1 == $wpmu )
- $prtfl_options = get_site_option( 'prtfl_options' ); // get options from the database
- else
- $prtfl_options = get_option( 'prtfl_options' );// get options from the database
-
- if ( isset( $prtfl_options['prtfl_prettyPhoto_style'] ) )
- unset( $prtfl_options['prtfl_prettyPhoto_style'] );
-
- // array merge incase this version has added new options
- $prtfl_options = array_merge( $prtfl_option_defaults, $prtfl_options );
-
- update_option( 'prtfl_options', $prtfl_options );
-
- if ( function_exists( 'add_image_size' ) ) {
- add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true );
- add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
+ } elseif ( 'portfolio' == get_post_type() && ( isset( $wp_query->query_vars["technologies"] ) || isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) ) {
+ $file_exists_flag = true;
+ foreach ( $prtfl_filenames as $filename ) {
+ if ( ! file_exists( $prtfl_themepath . $filename ) )
+ $file_exists_flag = false;
+ }
+ if ( $file_exists_flag ) {
+ include( get_stylesheet_directory() . '/portfolio.php' );
+ exit();
+ }
}
}
}
-if( ! function_exists( 'prtfl_settings_page' ) ) {
- function prtfl_settings_page() {
- global $prtfl_options;
- $error = "";
-
- // Save data for settings page
- if( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'prtfl_nonce_name' ) ) {
- $prtfl_request_options = array();
- $prtfl_request_options["prtfl_custom_size_name"] = $prtfl_options["prtfl_custom_size_name"];
-
- $prtfl_request_options["prtfl_custom_size_px"] = array(
- array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_album'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_album'] ) ) ),
- array( intval( trim( $_REQUEST['prtfl_custom_image_size_w_photo'] ) ), intval( trim( $_REQUEST['prtfl_custom_image_size_h_photo'] ) ) )
- );
- $prtfl_request_options["prtfl_custom_image_row_count"] = intval( trim( $_REQUEST['prtfl_custom_image_row_count'] ) );
- if( $prtfl_request_options["prtfl_custom_image_row_count"] == "" || $prtfl_request_options["prtfl_custom_image_row_count"] < 1 )
- $prtfl_request_options["prtfl_custom_image_row_count"] = 1;
-
- $prtfl_request_options["prtfl_order_by"] = $_REQUEST['prtfl_order_by'];
- $prtfl_request_options["prtfl_order"] = $_REQUEST['prtfl_order'];
-
- $prtfl_request_options["prtfl_date_additional_field"] = isset( $_REQUEST["prtfl_date_additional_field"] ) ? $_REQUEST["prtfl_date_additional_field"] : 0;
- $prtfl_request_options["prtfl_link_additional_field"] = isset( $_REQUEST["prtfl_link_additional_field"] ) ? $_REQUEST["prtfl_link_additional_field"] : 0;
- $prtfl_request_options["prtfl_shrdescription_additional_field"] = isset( $_REQUEST["prtfl_shrdescription_additional_field"] ) ? $_REQUEST["prtfl_shrdescription_additional_field"] : 0;
- $prtfl_request_options["prtfl_description_additional_field"] = isset( $_REQUEST["prtfl_description_additional_field"] ) ? $_REQUEST["prtfl_description_additional_field"] : 0;
- $prtfl_request_options["prtfl_svn_additional_field"] = isset( $_REQUEST["prtfl_svn_additional_field"] ) ? $_REQUEST["prtfl_svn_additional_field"] : 0;
- $prtfl_request_options["prtfl_executor_additional_field"] = isset( $_REQUEST["prtfl_executor_additional_field"] ) ? $_REQUEST["prtfl_executor_additional_field"] : 0;
- $prtfl_request_options["prtfl_technologies_additional_field"] = isset( $_REQUEST["prtfl_technologies_additional_field"] ) ? $_REQUEST["prtfl_technologies_additional_field"] : 0;
-
- $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;
-
- $prtfl_request_options["prtfl_date_text_field"] = $_REQUEST["prtfl_date_text_field"];
- $prtfl_request_options["prtfl_link_text_field"] = $_REQUEST["prtfl_link_text_field"];
- $prtfl_request_options["prtfl_shrdescription_text_field"] = $_REQUEST["prtfl_shrdescription_text_field"];
- $prtfl_request_options["prtfl_description_text_field"] = $_REQUEST["prtfl_description_text_field"];
- $prtfl_request_options["prtfl_svn_text_field"] = $_REQUEST["prtfl_svn_text_field"];
- $prtfl_request_options["prtfl_executor_text_field"] = $_REQUEST["prtfl_executor_text_field"];
- $prtfl_request_options["prtfl_screenshot_text_field"] = $_REQUEST["prtfl_screenshot_text_field"];
- $prtfl_request_options["prtfl_technologies_text_field"] = $_REQUEST["prtfl_technologies_text_field"];
-
- $prtfl_request_options["prtfl_slug"] = trim( $_REQUEST['prtfl_slug'] );
- $prtfl_request_options["prtfl_slug"] = strtolower($prtfl_request_options["prtfl_slug"]);
- $prtfl_request_options["prtfl_slug"] = preg_replace("/[^a-z0-9\s-]/", "", $prtfl_request_options["prtfl_slug"]);
- $prtfl_request_options["prtfl_slug"] = trim(preg_replace("/[\s-]+/", " ", $prtfl_request_options["prtfl_slug"]));
- $prtfl_request_options["prtfl_slug"] = preg_replace("/\s/", "-", $prtfl_request_options["prtfl_slug"]);
-
- // for revrite prtfl_slug
- global $wp_rewrite;
- $rules = get_option( 'rewrite_rules' );
- prtfl_custom_permalinks( $rules );
- $wp_rewrite->flush_rules();
-
- // array merge incase this version has added new options
- $prtfl_options = array_merge( $prtfl_options, $prtfl_request_options );
-
- // Check select one point in the blocks Arithmetic actions and Difficulty on settings page
- update_option( 'prtfl_options', $prtfl_options, '', 'yes' );
- $message = __( "Settings saved.", 'portfolio' );
- }
-
- if ( ! file_exists( get_stylesheet_directory() .'/portfolio.php' ) || ! file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) ) {
- $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' );
- }
- // Display form on the setting page
- ?>
-
-
-
-
-
-
[latest_portfolio_items count=3],
-
- get_var( "SELECT meta_id FROM ".$wpdb->postmeta." WHERE meta_key = '".$prefix."_short_descr' LIMIT 1" ) != NULL ) { ?>
-
-
-
-
-
-
- query_vars["s"] && ! isset( $wp_query->query_vars["technologies"] ) ) {
- include( get_stylesheet_directory() . '/portfolio-post.php' );
- exit();
- } else if ( 'portfolio' == get_post_type() && isset( $wp_query->query_vars["technologies"] ) ) {
- include( get_stylesheet_directory() . '/portfolio.php' );
- exit();
- }
- }
-}
-
-if ( ! function_exists ( 'prtfl_add_template_in_new_theme' ) ) {
- function prtfl_add_template_in_new_theme() {
- if ( ! file_exists( get_stylesheet_directory() .'/portfolio.php' ) || ! file_exists( get_stylesheet_directory() .'/portfolio-post.php' ) )
- prtfl_plugin_install();
- }
-}
-
-if ( ! function_exists ( 'prtfl_plugin_action_links' ) ) {
- function prtfl_plugin_action_links( $links, $file ) {
- //Static so we don't call plugin_basename on every plugin row.
- static $this_plugin;
- if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
-
- if ( $file == $this_plugin ) {
- $settings_link = '
' . __( 'Settings', 'portfolio' ) . ' ';
- array_unshift( $links, $settings_link );
- }
- return $links;
- }
-}
-
if ( ! function_exists( 'prtfl_add_portfolio_ancestor_to_menu' ) ) {
- function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) {
+ function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) {
if ( is_singular( 'portfolio' ) ) {
global $wpdb, $post;
- $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" );
-
- if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) ) {
+ $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" );
+
+ if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) )
$classes[] = 'current-page-ancestor';
- }
}
return $classes;
}
@@ -919,80 +983,78 @@
if ( ! function_exists( 'prtfl_latest_items' ) ) {
function prtfl_latest_items( $atts ) {
- $content = '
';
- $args = array(
- 'post_type' => 'portfolio',
- 'post_status' => 'publish',
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'posts_per_page' => $atts['count'],
+ $content = '
';
+ if ( empty( $atts['count'] ) )
+ $atts['count'] = 3;
+ $args = array(
+ 'post_type' => 'portfolio',
+ 'post_status' => 'publish',
+ 'orderby' => 'date',
+ 'order' => 'DESC',
+ 'posts_per_page' => $atts['count'],
);
query_posts( $args );
-
- while ( have_posts() ) : the_post();
+
+ while ( have_posts() ) : the_post();
$content .= '
';
global $post;
- $meta_values = get_post_custom($post->ID);
- $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
+ $meta_values = get_post_custom($post->ID);
+ $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
if( empty ( $post_thumbnail_id ) ) {
$args = array(
- 'post_parent' => $post->ID,
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'numberposts' => 1
+ 'post_parent' => $post->ID,
+ 'post_type' => 'attachment',
+ 'post_mime_type' => 'image',
+ 'numberposts' => 1
);
- $attachments = get_children( $args );
- $post_thumbnail_id = key($attachments);
+ $attachments = get_children( $args );
+ $post_thumbnail_id = key($attachments);
}
- $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
- $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
- $image_desc = get_post($post_thumbnail_id);
- $image_desc = $image_desc->post_content;
- if( get_option( 'prtfl_postmeta_update' ) == '1' ) {
- $post_meta = get_post_meta( $post->ID, 'prtfl_information', true);
- $date_compl = $post_meta['_prtfl_date_compl'];
- if( ! empty( $date_compl ) && 'in progress' != $date_compl) {
- $date_compl = explode( "/", $date_compl );
- $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) );
- }
- $link = $post_meta['_prtfl_link'];
- $short_descr = $post_meta['_prtfl_short_descr'];
- } else {
- $date_compl = get_post_meta( $post->ID, '_prtfl_date_compl', true );
- if( ! empty( $date_compl ) && 'in progress' != $date_compl) {
- $date_compl = explode( "/", $date_compl );
- $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) );
- }
- $link = get_post_meta($post->ID, '_prtfl_link', true);
- $short_descr = get_post_meta($post->ID, '_prtfl_short_descr', true);
- }
-
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
+ $image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
+ $image_desc = get_post( $post_thumbnail_id );
+ $image_desc = $image_desc->post_content;
+ $post_meta = get_post_meta( $post->ID, 'prtfl_information', true);
+ $date_compl = isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
+ if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
+ $date_compl = explode( "/", $date_compl );
+ $date_compl = date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) );
+ }
+ $link = isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
+ $short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
+ if ( empty( $short_descr ) )
+ $short_descr = get_the_excerpt();
+ $title = get_the_title();
+ if ( empty( $title ) )
+ $title = '(' . __( 'No title', 'portfolio-pro' ) . ')';
+ $permalink = get_permalink();
+
$content .= '
-
+
';
- $content .= '
'.$short_descr.'
+ $content .= '
' . $short_descr . '
';
- $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' ) ;
- if ( is_array( $terms ) && count( $terms ) > 0) {
- $content .= __( 'Technologies', 'portfolio' ).':';
+ $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
+ if ( is_array( $terms ) && 0 < count( $terms ) ) {
+ $content .= __( 'Technologies', 'portfolio' ) . ':';
$count = 0;
foreach ( $terms as $term ) {
- if( $count > 0 )
- $content .= ', ';
- $content .= '
name ) . '" ' . '>' . $term->name.' ';
+ if ( $count > 0 )
+ $content .= ', ';
+ $content .= '
name ) . '" ' . '>' . $term->name . ' ';
$count++;
}
} else {
@@ -1000,7 +1062,7 @@
}
$content .= '
';
$content .= '
';
- endwhile;
+ endwhile;
$content .= '
';
wp_reset_query();
return $content;
@@ -1010,87 +1072,69 @@
/* Register style and script files */
if ( ! function_exists ( 'prtfl_admin_head' ) ) {
function prtfl_admin_head() {
- wp_enqueue_style( 'prtflStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
- wp_enqueue_style( 'prtflDatepickerStylesheet', plugins_url( 'datepicker/datepicker.css', __FILE__ ) );
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'prtflScript', plugins_url( 'js/script.js', __FILE__ ) );
- wp_enqueue_script( 'prtflDatepickerScript', plugins_url( 'datepicker/datepicker.js', __FILE__ ) );
+ global $wp_version, $prtfl_plugin_info, $post_type;
+ if ( $wp_version < 3.8 )
+ wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );
+ else
+ wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
+ wp_enqueue_style( 'prtfl_datepicker_stylesheet', plugins_url( 'datepicker/datepicker.css', __FILE__ ) );
- if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" )
- wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) );
+ if ( isset( $_GET['page'] ) && "portfolio.php" == $_GET['page'] ) {
+ wp_enqueue_script( 'prtfl_script', plugins_url( 'js/script.js', __FILE__ ) );
+ wp_localize_script( 'prtfl_script', 'prtfl_var', array(
+ 'prtfl_nonce' => wp_create_nonce( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' ),
+ 'update_img_message' => __( 'Updating images...', 'portfolio' ),
+ 'not_found_img_info' => __( 'No image found', 'portfolio'),
+ 'img_success' => __( 'All images are updated', 'portfolio' ),
+ 'img_error' => __( 'Error.', 'portfolio' ) ) );
+ }
+ wp_enqueue_script( 'prtfl_datepicker_script', plugins_url( 'datepicker/datepicker.js', __FILE__ ) );
}
}
if ( ! function_exists ( 'prtfl_wp_head' ) ) {
function prtfl_wp_head() {
- wp_enqueue_style( 'prtflLightboxStylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
- wp_enqueue_style( 'prtflStylesheet', plugins_url( 'css/stylesheet.css', __FILE__ ) );
-
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'prtflScript', plugins_url( 'js/script.js', __FILE__ ) );
- wp_enqueue_script( 'prtflFancyboxMousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
- wp_enqueue_script( 'prtflFancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
- }
-}
-
-if ( ! function_exists ( 'prtfl_update_info' ) ) {
- function prtfl_update_info(){
- global $wpdb;
- $action = isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
- $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
- switch($action) {
- case 'get_portfolio_id':
- $result = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'portfolio'" );
- echo json_encode( $result );
- break;
- case 'update_info':
- if( $id != "" && is_numeric( $id ) ) {
- $result = $wpdb->get_results( "SELECT * FROM " . $wpdb->postmeta . " WHERE meta_key LIKE '_prtf%' AND post_id = " . $id );
- if( ! empty( $result ) ) {
- $new_post_meta = array();
- foreach( $result as $value ) {
- $new_post_meta[ $value->meta_key ] = $value->meta_value;
- }
- add_post_meta($id, 'prtfl_information', $new_post_meta);
- $wpdb->query( "DELETE FROM " . $wpdb->postmeta . " WHERE meta_key LIKE '_prtf%' AND post_id = " . $id );
- }
- $post_meta = get_post_meta($id, 'prtfl_information', true);
- $wpdb->query( $wpdb->prepare( "UPDATE " . $wpdb->posts . " SET post_content = '%s' WHERE ID = " . $id, $post_meta["_prtfl_short_descr"] ) );
- }
- break;
- case 'update_options':
- add_option( 'prtfl_postmeta_update', '1', '', 'no' );
- break;
+ wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
+
+ if ( ! function_exists( 'is_plugin_active' ) )
+ require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
+
+ $all_plugins = get_plugins();
+
+ if ( ! is_plugin_active( 'gallery-plugin-pro/gallery-plugin-pro.php' ) || ( isset( $all_plugins["gallery-plugin-pro/gallery-plugin-pro.php"]["Version"] ) && "1.3.0" >= $all_plugins["gallery-plugin-pro/gallery-plugin-pro.php"]["Version"] ) ) {
+ wp_enqueue_style( 'prtfl_lightbox_stylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
+ wp_enqueue_script( 'prtfl_fancybox_mousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
+ wp_enqueue_script( 'prtfl_fancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
}
- die();
}
}
if ( ! function_exists ( 'prtfl_update_image' ) ) {
- function prtfl_update_image(){
+ function prtfl_update_image() {
global $wpdb;
- $action = isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
- $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
- switch($action) {
+ check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
+ $action = isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
+ $id = isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
+ switch ( $action ) {
case 'get_all_attachment':
- $result_parent_id = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'portfolio' ) , ARRAY_N );
- $array_parent_id = array();
-
- while(list($key, $val) = each($result_parent_id))
+ $result_parent_id = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'portfolio' ) , ARRAY_N );
+ $array_parent_id = array();
+
+ while ( list( $key, $val ) = each( $result_parent_id ) )
$array_parent_id[] = $val[0];
$string_parent_id = implode( ",", $array_parent_id );
-
- $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.")" );
+
+ $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 . ")" );
echo json_encode( $result_attachment_id );
break;
case 'update_image':
- $metadata = wp_get_attachment_metadata( $id );
- $uploads = wp_upload_dir();
- $path = $uploads['basedir']."/".$metadata['file'];
+ $metadata = wp_get_attachment_metadata( $id );
+ $uploads = wp_upload_dir();
+ $path = $uploads['basedir'] . "/" . $metadata['file'];
require_once( ABSPATH . 'wp-admin/includes/image.php' );
$metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata );
- wp_update_attachment_metadata( $id, array_merge($metadata, $metadata_new) );
+ wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
break;
case 'update_options':
add_option( 'prtfl_images_update', '1', '', 'no' );
@@ -1102,58 +1146,55 @@
if ( ! function_exists ( 'prtfl_wp_generate_attachment_metadata' ) ) {
function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
- $attachment = get_post( $attachment_id );
- $prtfl_options = get_option( 'prtfl_options' );
-
+ global $prtfl_options;
+ $attachment = get_post( $attachment_id );
add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true );
add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
$metadata = array();
- if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
- $imagesize = getimagesize( $file );
- $metadata['width'] = $imagesize[0];
- $metadata['height'] = $imagesize[1];
- list($uwidth, $uheight) = wp_constrain_dimensions($metadata['width'], $metadata['height'], 128, 96);
- $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
+ if ( preg_match('!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
+ $imagesize = getimagesize( $file );
+ $metadata['width'] = $imagesize[0];
+ $metadata['height'] = $imagesize[1];
+ list($uwidth, $uheight) = wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
+ $metadata['hwstring_small'] = "height='$uheight' width='$uwidth'";
- // Make the file path relative to the upload dir
- $metadata['file'] = _wp_relative_upload_path($file);
+ /* Make the file path relative to the upload dir */
+ $metadata['file']= _wp_relative_upload_path( $file );
- // make thumbnails and other intermediate sizes
+ /* Make thumbnails and other intermediate sizes */
global $_wp_additional_image_sizes;
-
- $image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb' );//get_intermediate_image_sizes();
-
+
+ $image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb' );/* get_intermediate_image_sizes(); */
+
foreach ( $image_size as $s ) {
- $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
- if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
- $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
+ $sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
+ if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) )
+ $sizes[ $s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); /* For theme-added sizes */
else
- $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
+ $sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
- $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
+ $sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); /* For theme-added sizes */
else
- $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
+ $sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
- $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
+ $sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); /* For theme-added sizes */
else
- $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
+ $sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
}
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
- foreach ($sizes as $size => $size_data ) {
+ foreach ( $sizes as $size => $size_data ) {
$resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
if ( $resized )
$metadata['sizes'][$size] = $resized;
}
- // fetch additional metadata from exif/iptc
+ /* Fetch additional metadata from exif/iptc */
$image_meta = wp_read_image_metadata( $file );
if ( $image_meta )
$metadata['image_meta'] = $image_meta;
-
}
-
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
}
}
@@ -1162,12 +1203,12 @@
function prtfl_image_make_intermediate_size( $file, $width, $height, $crop=false ) {
if ( $width || $height ) {
$resized_file = prtfl_image_resize( $file, $width, $height, $crop );
- if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize( $resized_file ) ) {
- $resized_file = apply_filters('image_make_intermediate_size', $resized_file);
+ if ( ! is_wp_error( $resized_file ) && $resized_file && $info = getimagesize( $resized_file ) ) {
+ $resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
return array(
- 'file' => wp_basename( $resized_file ),
- 'width' => $info[0],
- 'height' => $info[1],
+ 'file' => wp_basename( $resized_file ),
+ 'width' => $info[0],
+ 'height' => $info[1],
);
}
}
@@ -1177,82 +1218,73 @@
if ( ! function_exists ( 'prtfl_image_resize' ) ) {
function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
-
$size = @getimagesize( $file );
- if ( !$size )
- return new WP_Error('invalid_image', __('Image size not defined'), $file);
-
- $type = $size[2];
+ if ( !$size )
+ return new WP_Error( 'invalid_image', __( 'Image size not defined', 'portfolio' ), $file );
+ $type = $size[2];
- if ( $type == 3 )
- $image = imagecreatefrompng($file);
- else if ( $type == 2 )
- $image = imagecreatefromjpeg($file);
- else if ( $type == 1 )
- $image = imagecreatefromgif($file);
- else if ( $type == 15 )
- $image = imagecreatefromwbmp($file);
- else if ( $type == 16 )
- $image = imagecreatefromxbm($file);
- else
- return new WP_Error('invalid_image', __('We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other, please, manually reload image.'), $file );
+ if ( 3 == $type )
+ $image = imagecreatefrompng( $file );
+ else if ( 2 == $type )
+ $image = imagecreatefromjpeg( $file );
+ else if ( 1 == $type )
+ $image = imagecreatefromgif( $file );
+ else if ( 15 == $type )
+ $image = imagecreatefromwbmp( $file );
+ else if ( 16 == $type )
+ $image = imagecreatefromxbm( $file );
+ else
+ return new WP_Error( 'invalid_image', __( 'We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other, please, manually reload image.', 'portfolio' ), $file );
- if ( !is_resource( $image ) )
- return new WP_Error( 'error_loading_image', $image, $file );
+ if ( ! is_resource( $image ) )
+ return new WP_Error( 'error_loading_image', $image, $file );
- //$size = @getimagesize( $file );
- list( $orig_w, $orig_h, $orig_type ) = $size;
-
+ /* $size = @getimagesize( $file ); */
+ list( $orig_w, $orig_h, $orig_type ) = $size;
$dims = prtfl_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
- if ( !$dims )
- return new WP_Error( 'error_getting_dimensions', __('Image size changes not defined') );
+ if ( ! $dims )
+ return new WP_Error( 'error_getting_dimensions', __( 'Image size changes not defined', 'portfolio' ) );
list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
-
$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
-
- imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
-
- // convert from full colors to index colors, like original PNG.
- if ( IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor( $image ) )
+ imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
+ /* Convert from full colors to index colors, like original PNG. */
+ if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) )
imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
-
- // we don't need the original in memory anymore
+ /* We don't need the original in memory anymore */
imagedestroy( $image );
- // $suffix will be appended to the destination filename, just before the extension
- if ( !$suffix )
+ /* $suffix will be appended to the destination filename, just before the extension */
+ if ( ! $suffix )
$suffix = "{$dst_w}x{$dst_h}";
- $info = pathinfo($file);
- $dir = $info['dirname'];
- $ext = $info['extension'];
- $name = wp_basename($file, ".$ext");
+ $info = pathinfo( $file );
+ $dir = $info['dirname'];
+ $ext = $info['extension'];
+ $name = wp_basename( $file, ".$ext" );
- if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) )
+ if ( ! is_null( $dest_path ) and $_dest_path = realpath( $dest_path ) )
$dir = $_dest_path;
$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
if ( IMAGETYPE_GIF == $orig_type ) {
- if ( !imagegif( $newimage, $destfilename ) )
- return new WP_Error('resize_path_invalid', __( 'Invalid path' ));
+ if ( ! imagegif( $newimage, $destfilename ) )
+ return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
} elseif ( IMAGETYPE_PNG == $orig_type ) {
- if ( !imagepng( $newimage, $destfilename ) )
- return new WP_Error('resize_path_invalid', __( 'Invalid path' ));
+ if ( ! imagepng( $newimage, $destfilename ) )
+ return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
} else {
- // all other formats are converted to jpg
+ /* All other formats are converted to jpg */
$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
- if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
- return new WP_Error('resize_path_invalid', __( 'Invalid path' ));
+ if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
+ return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
}
imagedestroy( $newimage );
-
- // Set correct file permissions
- $stat = stat( dirname( $destfilename ));
- $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
- @ chmod( $destfilename, $perms );
-
+ /* Set correct file permissions */
+ $stat = stat( dirname( $destfilename ) );
+ $perms = $stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
+ @chmod( $destfilename, $perms );
return $destfilename;
}
}
@@ -1260,87 +1292,192 @@
if ( ! function_exists ( 'prtfl_image_resize_dimensions' ) ) {
function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
- if ( $orig_w <= 0 || $orig_h <= 0 )
+ if ( 0 >= $orig_w || 0 >= $orig_h )
return false;
- // at least one of dest_w or dest_h must be specific
- if ( $dest_w <= 0 && $dest_h <= 0 )
+ /* At least one of dest_w or dest_h must be specific */
+ if ( 0 >= $dest_w && 0 >= $dest_h )
return false;
if ( $crop ) {
- // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
- $aspect_ratio = $orig_w / $orig_h;
- $new_w = min($dest_w, $orig_w);
- $new_h = min($dest_h, $orig_h);
+ /* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
+ $aspect_ratio = $orig_w / $orig_h;
+ $new_w = min( $dest_w, $orig_w );
+ $new_h = min( $dest_h, $orig_h );
- if ( !$new_w ) {
- $new_w = intval($new_h * $aspect_ratio);
- }
-
- if ( !$new_h ) {
- $new_h = intval($new_w / $aspect_ratio);
+ if ( ! $new_w ) {
+ $new_w = intval( $new_h * $aspect_ratio );
}
- $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
+ if ( ! $new_h ) {
+ $new_h = intval( $new_w / $aspect_ratio );
+ }
- $crop_w = round($new_w / $size_ratio);
- $crop_h = round($new_h / $size_ratio);
-
- $s_x = floor( ($orig_w - $crop_w) / 2 );
- $s_y = 0;
+ $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
+ $crop_w = round( $new_w / $size_ratio );
+ $crop_h = round( $new_h / $size_ratio );
+ $s_x = floor( ( $orig_w - $crop_w ) / 2 );
+ $s_y = 0;
} else {
- // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
- $crop_w = $orig_w;
- $crop_h = $orig_h;
-
- $s_x = 0;
- $s_y = 0;
-
+ /* Don't crop, just resize using $dest_w x $dest_h as a maximum bounding box */
+ $crop_w = $orig_w;
+ $crop_h = $orig_h;
+ $s_x = 0;
+ $s_y = 0;
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
}
- // if the resulting image would be the same size or larger we don't want to resize it
+ /* If the resulting image would be the same size or larger we don't want to resize it */
if ( $new_w >= $orig_w && $new_h >= $orig_h )
return false;
-
- // the return array matches the parameters to imagecopyresampled()
- // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
+ /* The return array matches the parameters to imagecopyresampled() */
+ /* Int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h */
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
}
-register_activation_hook( __FILE__, 'prtfl_plugin_install'); // activate plugin
-register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' ); // deactivate plugin
+
+if ( ! function_exists( 'prtfl_sanitize_file_name' ) ) {
+ function prtfl_sanitize_file_name( $file_name ) {
+ global $prtfl_options;
+ if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] )
+ && isset( $prtfl_options['prtfl_rename_file'] ) && $prtfl_options['prtfl_rename_file'] == 1 ) {
+ $file_name_old = explode( '.', $file_name );
+ $file_name_new = preg_replace( '/--+/', '-', preg_replace( '/[^a-zA-Z0-9_-]/', '', $file_name_old[0] ) );
-// adds "Settings" link to the plugin action page
-add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 );
-add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
+ if ( $file_name_new == '' || $file_name_new == '-' ) {
+ $slug = isset( $prtfl_options['prtfl_slug'] ) && ! empty( $prtfl_options['prtfl_slug'] ) ? $prtfl_options['prtfl_slug'] : 'portfolio';
+ $file_name_new = $slug . '-' . time();
+ }
+ $file_name = $file_name_new . '.' . $file_name_old[1];
+ }
+ return $file_name;
+ }
+}
-//Additional links on the plugin page
-add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 );
+if ( ! function_exists( 'prtfl_filter_image_sizes' ) ) {
+ function prtfl_filter_image_sizes( $sizes ) {
+ if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] ) ) {
+ $prtfl_image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb', 'large' );
+ foreach ( $sizes as $key => $value ) {
+ if ( ! in_array( $key, $prtfl_image_size ) ) {
+ unset( $sizes[ $key ] );
+ }
+ }
+ }
+ return $sizes;
+ }
+}
-add_action( 'admin_init', 'prtfl_admin_error' );
+if ( ! function_exists ( 'prtfl_theme_body_classes' ) ) {
+ function prtfl_theme_body_classes( $classes ) {
+ if ( function_exists( 'wp_get_theme' ) ) {
+ $current_theme = wp_get_theme();
+ $classes[] = 'prtfl_' . basename( $current_theme->get( 'ThemeURI' ) );
+ }
+ return $classes;
+ }
+}
-add_action( 'admin_menu', 'add_prtfl_admin_menu' ); // add portfolio settings page in admin menu
-add_action( 'init', 'prtfl_plugin_init' ); // add language file
+if ( ! function_exists ( 'prtfl_admin_notices' ) ) {
+ function prtfl_admin_notices() {
+ global $hook_suffix, $prtfl_plugin_info, $prtfl_options;
+
+ if ( 'plugins.php' == $hook_suffix ) {
+ bws_plugin_banner( $prtfl_plugin_info, 'prtfl', 'portfolio', '56e6c97d1bca3199fb16cb817793a8f6', '74', '//ps.w.org/portfolio/assets/icon-128x128.png' );
+
+ /* Get options from the database */
+ if ( ! $prtfl_options )
+ $prtfl_options = get_option( 'prtfl_options' );
-add_action( 'init', 'prtfl_taxonomy_portfolio' ); // register taxonomy for portfolio
-add_action( 'init', 'prtfl_post_type_portfolio' ); // register post type
-add_action( 'init', 'prtfl_register_widget' ); // add widget for portfolio technologies
-add_action( 'save_post', 'prtfl_save_postdata', 1, 2 ); // save custom data from admin
-add_filter( 'pre_get_posts', 'prtfl_technologies_get_posts' ); // display tachnologies taxonomy
-add_action( 'template_redirect', 'prtfl_template_redirect' ); // add template for single gallery page
+ if ( $prtfl_options['widget_updated'] == 0 ) {
+ /* Save data for settings page */
+ if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'prtfl_nonce_name' ) ) {
+ $prtfl_options['widget_updated'] = 1;
+ update_option( 'prtfl_options', $prtfl_options );
+ } else { ?>
+
+
\ No newline at end of file