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