wp/wp-content/plugins/portfolio/portfolio.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 12 d8a8807227e4
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /*
     2 /*
     3 Plugin Name: Portfolio by BestWebSoft
     3 Plugin Name: Portfolio by BestWebSoft
     4 Plugin URI: http://bestwebsoft.com/products/
     4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/portfolio/
     5 Description: Plugin for portfolio.
     5 Description: Create your personal portfolio WordPress website. Manage and showcase past projects to get more clients.
     6 Author: BestWebSoft
     6 Author: BestWebSoft
     7 Version: 2.33
     7 Text Domain: portfolio
     8 Author URI: http://bestwebsoft.com/
     8 Domain Path: /languages
       
     9 Version: 2.46
       
    10 Author URI: https://bestwebsoft.com/
     9 License: GPLv2 or later
    11 License: GPLv2 or later
    10 */
    12 */
    11 
    13 
    12 /*
    14 /*
    13 	@ Copyright 2015  BestWebSoft  ( http://support.bestwebsoft.com )
    15 	@ Copyright 2017  BestWebSoft  ( https://support.bestwebsoft.com )
    14 
    16 
    15 	This program is free software; you can redistribute it and/or modify
    17 	This program is free software; you can redistribute it and/or modify
    16 	it under the terms of the GNU General Public License, version 2, as
    18 	it under the terms of the GNU General Public License, version 2, as
    17 	published by the Free Software Foundation.
    19 	published by the Free Software Foundation.
    18 
    20 
    23 
    25 
    24 	You should have received a copy of the GNU General Public License
    26 	You should have received a copy of the GNU General Public License
    25 	along with this program; if not, write to the Free Software
    27 	along with this program; if not, write to the Free Software
    26 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    28 	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    27 */
    29 */
    28 global $prtfl_filenames, $prtfl_filepath, $prtfl_themepath;
    30 
    29 $prtfl_filepath = WP_PLUGIN_DIR . '/portfolio/template/';
    31 /* Function are using to add on admin-panel Wordpress page 'bws_panel' and sub-page of this plugin */
    30 $prtfl_themepath = get_stylesheet_directory() . '/';
       
    31 
       
    32 $prtfl_filenames[]	=	'portfolio.php';
       
    33 $prtfl_filenames[]	=	'portfolio-post.php';
       
    34 
       
    35 $prtfl_boxes = array();
       
    36 
       
    37 /* Function are using to add on admin-panel Wordpress page 'bws_plugins' and sub-page of this plugin */
       
    38 if ( ! function_exists( 'add_prtfl_admin_menu' ) ) {
    32 if ( ! function_exists( 'add_prtfl_admin_menu' ) ) {
    39 	function add_prtfl_admin_menu() {
    33 	function add_prtfl_admin_menu() {
    40 		bws_add_general_menu( plugin_basename( __FILE__ ) );
    34 		global $submenu, $prtfl_options, $prtfl_plugin_info, $wp_version;
    41 		add_submenu_page( 'bws_plugins', __( 'Portfolio', 'portfolio' ), __( 'Portfolio', 'portfolio' ), 'manage_options', "portfolio.php", 'prtfl_settings_page' );
    35 
    42 	}
    36 		if ( empty( $prtfl_options ) ) {
    43 }
    37 			register_prtfl_settings();
    44 
    38 		}
    45 if ( ! function_exists ( 'prtfl_init' ) ) {
    39 
       
    40 		$settings = add_submenu_page( 'edit.php?post_type=' . $prtfl_options['post_type_name'], __( 'Portfolio Settings', 'portfolio' ), __( 'Settings', 'portfolio' ), 'manage_options', 'portfolio.php', 'prtfl_settings_page' );
       
    41 
       
    42 		add_submenu_page( 'edit.php?post_type=' . $prtfl_options['post_type_name'], 'BWS Panel', 'BWS Panel', 'manage_options', 'prtfl-bws-panel', 'bws_add_menu_render' );
       
    43 
       
    44 		if ( isset( $submenu['edit.php?post_type=' . $prtfl_options['post_type_name']] ) ) {
       
    45 			$submenu['edit.php?post_type=' . $prtfl_options['post_type_name']][] = array(
       
    46 				'<span style="color:#d86463"> ' . __( 'Upgrade to Pro', 'portfolio' ) . '</span>',
       
    47 				'manage_options',
       
    48 				'https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=' . $prtfl_plugin_info["Version"] . '&wp_v=' . $wp_version );
       
    49 		}
       
    50 
       
    51 		add_action( 'load-' . $settings, 'prtfl_add_tabs' );
       
    52 		add_action( 'load-post-new.php', 'prtfl_add_tabs' );
       
    53 		add_action( 'load-post.php', 'prtfl_add_tabs' );
       
    54 		add_action( 'load-edit.php', 'prtfl_add_tabs' );
       
    55 	}
       
    56 }
       
    57 
       
    58 /* Internationalization, first(!)  */
       
    59 if ( ! function_exists( 'prtfl_plugins_loaded' ) ) {
       
    60 	function prtfl_plugins_loaded() {
       
    61 		load_plugin_textdomain( 'portfolio', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
       
    62 	}
       
    63 }
       
    64 
       
    65 if ( ! function_exists( 'prtfl_init' ) ) {
    46 	function prtfl_init() {
    66 	function prtfl_init() {
    47 		global $prtfl_boxes, $prtfl_plugin_info;
    67 		global $prtfl_boxes, $prtfl_plugin_info;
    48 		/* Internationalization, first(!) */
    68 
    49 		load_plugin_textdomain( 'portfolio', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
    69 		require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
    50 
    70 		bws_include_init( plugin_basename( __FILE__ ) );
    51 		require_once( dirname( __FILE__ ) . '/bws_menu/bws_functions.php' );
       
    52 
    71 
    53 		if ( ! $prtfl_plugin_info ) {
    72 		if ( ! $prtfl_plugin_info ) {
    54 			if ( ! function_exists( 'get_plugin_data' ) )
    73 			if ( ! function_exists( 'get_plugin_data' ) ) {
    55 				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
    74 				require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
       
    75 			}
    56 			$prtfl_plugin_info = get_plugin_data( __FILE__ );
    76 			$prtfl_plugin_info = get_plugin_data( __FILE__ );
    57 		}
    77 		}
    58 		/* Function check if plugin is compatible with current WP version  */
    78 		/* Function check if plugin is compatible with current WP version  */
    59 		bws_wp_version_check( plugin_basename( __FILE__ ), $prtfl_plugin_info, "3.1" );
    79 		bws_wp_min_version_check( plugin_basename( __FILE__ ), $prtfl_plugin_info, '3.9' );
    60 
    80 
    61 		$prtfl_boxes['Portfolio-Info'] = array(
    81 		$prtfl_boxes['Portfolio-Info'] = array(
    62 			array( '_prtfl_short_descr', __( 'Short description', 'portfolio' ), __( 'A short description which you\'d like to be displayed on your portfolio page', 'portfolio' ), '', '' ),
    82 			array(
    63 			array( '_prtfl_date_compl', __( 'Date of completion', 'portfolio' ), __( 'The date when the task was completed', 'portfolio' ), '', '' ),
    83 				'name'	=> '_prtfl_short_descr',
    64 			array( '_prtfl_link', __( 'Link', 'portfolio' ), __( 'A link to the site', 'portfolio' ), '', '' ),
    84 				'title'	=> __( 'Short description', 'portfolio' ),
    65 			array( '_prtfl_svn', __( 'SVN', 'portfolio' ), __( 'SVN URL', 'portfolio' ), '', '' ),
    85 				'type'	=> 'text'
       
    86 			),
       
    87 			array(
       
    88 				'name'	=> '_prtfl_date_compl',
       
    89 				'title'	=> __( 'Date of completion', 'portfolio' ),
       
    90 				'type'	=> 'text'
       
    91 			),
       
    92 			array(
       
    93 				'name'	=> '_prtfl_link',
       
    94 				'title'	=> __( 'Link', 'portfolio' ),
       
    95 				'type'	=> 'url'
       
    96 			),
       
    97 			array(
       
    98 				'name'	=> '_prtfl_svn',
       
    99 				'title'	=> __( 'SVN URL', 'portfolio' ),
       
   100 				'type'	=> 'url'
       
   101 			)
    66 		);
   102 		);
    67 		/* Call register settings function */
   103 		/* Call register settings function */
    68 		register_prtfl_settings();
   104 		register_prtfl_settings();
    69 		/* Register post type */
   105 		/* Register post type and taxonomy for portfolio */
    70 		prtfl_post_type_portfolio();
   106 		prtfl_post_type_portfolio();
    71 		/* Register taxonomy for portfolio */
   107 
    72 		prtfl_taxonomy_portfolio();
   108 		if ( ! is_admin() ) {
       
   109 			/* add template for gallery pages */
       
   110 			add_action( 'template_include', 'prtfl_template_include' );
       
   111 		}
       
   112 
       
   113 		/* demo data */
       
   114 		$demo_options = get_option( 'prtfl_demo_options' );
       
   115 		if ( ! empty( $demo_options ) || ( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
       
   116 			prtfl_include_demo_data();
       
   117 		}
    73 	}
   118 	}
    74 }
   119 }
    75 
   120 
    76 if ( ! function_exists( 'prtfl_admin_init' ) ) {
   121 if ( ! function_exists( 'prtfl_admin_init' ) ) {
    77 	function prtfl_admin_init() {
   122 	function prtfl_admin_init() {
    78 		global $bws_plugin_info, $prtfl_plugin_info;
   123 		global $bws_plugin_info, $prtfl_plugin_info, $bws_shortcode_list, $wpdb;
    79 
   124 
    80 		if ( ! isset( $bws_plugin_info ) || empty( $bws_plugin_info ) )
   125 		if ( empty( $bws_plugin_info ) ) {
    81 			$bws_plugin_info = array( 'id' => '74', 'version' => $prtfl_plugin_info["Version"] );
   126 			$bws_plugin_info = array( 'id' => '74', 'version' => $prtfl_plugin_info["Version"] );
    82 
   127 		}
    83 		prtfl_admin_error();
   128 
       
   129 		/* add Portfolio to global $bws_shortcode_list  */
       
   130 		$bws_shortcode_list['prtfl'] = array( 'name' => 'Portfolio', 'js_function' => 'prtfl_shortcode_init' );
       
   131 
       
   132 	}
       
   133 }
       
   134 
       
   135 /* Function for activation plugin */
       
   136 if ( ! function_exists( 'prtfl_plugin_activate' ) ) {
       
   137 	function prtfl_plugin_activate() {
       
   138 		if ( is_multisite() ) {
       
   139 			switch_to_blog( 1 );
       
   140 			register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' );
       
   141 			restore_current_blog();
       
   142 		} else {
       
   143 			register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' );
       
   144 		}
    84 	}
   145 	}
    85 }
   146 }
    86 
   147 
    87 /* Register settings function */
   148 /* Register settings function */
    88 if ( ! function_exists( 'register_prtfl_settings' ) ) {
   149 if ( ! function_exists( 'register_prtfl_settings' ) ) {
    89 	function register_prtfl_settings() {
   150 	function register_prtfl_settings() {
    90 		global $prtfl_options, $prtfl_plugin_info;
   151 		global $prtfl_options, $prtfl_plugin_info, $wpdb;
    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 
   152 
   121 		/* Install the option defaults */
   153 		/* Install the option defaults */
   122 		if ( ! get_option( 'prtfl_options' ) )
   154 		if ( ! get_option( 'prtfl_options' ) ) {
   123 			add_option( 'prtfl_options', $prtfl_option_defaults );
   155 			$option_defaults = prtfl_get_options_default();
       
   156 			add_option( 'prtfl_options', $option_defaults );
       
   157 		}
   124 
   158 
   125 		/* Get options from the database */
   159 		/* Get options from the database */
   126 		$prtfl_options = get_option( 'prtfl_options' );
   160 		$prtfl_options = get_option( 'prtfl_options' );
   127 
   161 
   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 */
   162 		/* 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"] ) {
   163 		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' )
   164 
   134 				$prtfl_option_defaults['widget_updated'] = 0;
   165 			$wpdb->query( "UPDATE {$wpdb->prefix}posts SET post_type = 'bws-portfolio' WHERE post_type = 'portfolio'" );
   135 
   166 
   136 			$prtfl_options = array_merge( $prtfl_option_defaults, $prtfl_options );
   167 			$option_defaults = prtfl_get_options_default();
   137 			$prtfl_options['plugin_option_version'] = $prtfl_plugin_info["Version"];
   168 
       
   169 			if ( ! isset( $prtfl_options['plugin_option_version'] ) || $prtfl_options['plugin_option_version'] < '2.29' ) {
       
   170 				$option_defaults['widget_updated'] = 0;
       
   171 			}
       
   172 			/* Add options 'post_type_name' */
       
   173 			if ( ! isset( $prtfl_options['post_type_name'] ) ) {
       
   174 				$option_defaults['post_type_name'] = 'bws-portfolio';
       
   175 			}
       
   176 
       
   177 			$prtfl_options = array_merge( $option_defaults, $prtfl_options );
       
   178 			$prtfl_options['plugin_option_version'] = $option_defaults['plugin_option_version'];
       
   179 			/* show pro features */
       
   180 			$prtfl_options['hide_premium_options'] = array();
       
   181 
   138 			update_option( 'prtfl_options', $prtfl_options );
   182 			update_option( 'prtfl_options', $prtfl_options );
   139 			/* update templates when updating plugin */
       
   140 			prtfl_plugin_install();
       
   141 		}
   183 		}
   142 
   184 
   143 		if ( function_exists( 'add_image_size' ) ) {
   185 		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 );
   186 			if ( 'portfolio-thumb' == $prtfl_options['image_size_album'] ) {
   145 			add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
   187 				add_image_size( 'portfolio-thumb', $prtfl_options['custom_size_px']['portfolio-thumb'][0], $prtfl_options['custom_size_px']['portfolio-thumb'][1], true );
   146 		}
   188 			}
   147 	}
   189 			if ( 'portfolio-photo-thumb' == $prtfl_options['image_size_photo'] ) {
   148 }
   190 				add_image_size( 'portfolio-photo-thumb', $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0], $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1], true );
   149 
   191 			}
   150 
   192 		}
   151 if ( ! function_exists( 'prtfl_plugin_install' ) ) {
   193 	}
   152 	function prtfl_plugin_install() {
   194 }
   153 		global $prtfl_filenames, $prtfl_filepath, $prtfl_themepath, $prtfl_options;
   195 
   154 
   196 /**
   155 		if ( empty( $prtfl_options ) )
   197  * Get Plugin default options
   156 			register_prtfl_settings();
   198  */
   157 
   199 if ( ! function_exists( 'prtfl_get_options_default' ) ) {
   158 		foreach ( $prtfl_filenames as $filename ) {
   200 	function prtfl_get_options_default() {
   159 			if ( ! file_exists( $prtfl_themepath . $filename ) ) {
   201 		global $prtfl_plugin_info;
   160 				$handle		=	@fopen( $prtfl_filepath . $filename, "r" );
   202 
   161 				$contents	=	@fread( $handle, filesize( $prtfl_filepath . $filename ) );
   203 		$option_defaults = array(
   162 				@fclose( $handle );
   204 			/* internal general */
   163 				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename, 'w' ) ) )
   205 			'plugin_option_version' 					=> $prtfl_plugin_info["Version"],
   164 					return false;
   206 			'first_install'								=> strtotime( "now" ),
   165 				@fwrite( $handle, $contents );
   207 			'suggest_feature_banner'					=> 1,
   166 				@fclose( $handle );
   208 			'display_settings_notice'					=> 1,
   167 				@chmod( $prtfl_themepath . $filename, octdec( 755 ) );
   209 			/* internal */
   168 			} elseif ( ! isset( $prtfl_options['prtfl_rewrite_template'] ) || 1 == $prtfl_options['prtfl_rewrite_template'] ) {
   210 			'display_demo_notice'						=> 1,
   169 				$handle		=	@fopen( $prtfl_themepath . $filename, "r" );
   211 			/* settings */
   170 				$contents	=	@fread( $handle, filesize( $prtfl_themepath . $filename ) );
   212 			'image_size_album'							=> 'medium',
   171 				@fclose( $handle );
   213 			'image_size_photo'							=> 'thumbnail',
   172 				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename . '.bak', 'w' ) ) )
   214 			'custom_size_px'							=> array(
   173 					return false;
   215 															'portfolio-thumb' => array( 280, 300 ),
   174 				@fwrite( $handle, $contents );
   216 															'portfolio-photo-thumb' => array( 240, 260 )
   175 				@fclose( $handle );
   217 														),
   176 				
   218 			'page_id_portfolio_template'				=> '',
   177 				$handle		=	@fopen( $prtfl_filepath . $filename, "r" );
   219 			'order_by' 									=>	'date',
   178 				$contents	=	@fread( $handle, filesize( $prtfl_filepath . $filename ) );
   220 			'order' 									=>	'DESC',
   179 				@fclose( $handle );
   221 			'custom_image_row_count'					=>	3,
   180 				if ( ! ( $handle = @fopen( $prtfl_themepath . $filename, 'w' ) ) )
   222 			'date_additional_field' 					=>	1,
   181 					return false;
   223 			'link_additional_field' 					=>	1,
   182 				@fwrite( $handle, $contents );
   224 			'shrdescription_additional_field' 			=>	1,
   183 				@fclose( $handle );
   225 			'description_additional_field' 				=>	1,
   184 				@chmod( $prtfl_themepath . $filename, octdec( 755 ) );
   226 			'svn_additional_field' 						=>	1,
   185 			}
   227 			'executor_additional_field' 				=>	1,
   186 		}
   228 			'technologies_additional_field'				=>	1,
   187 	}
   229 			'link_additional_field_for_non_registered'	=>	1,
   188 }
   230 			'date_text_field'							=>	__( 'Date of completion:', 'portfolio' ),
   189 
   231 			'link_text_field'							=>	__( 'Link:', 'portfolio' ),
   190 if ( ! function_exists ( 'prtfl_after_switch_theme' ) ) {
   232 			'shrdescription_text_field'					=>	__( 'Short description:', 'portfolio' ),
   191 	function prtfl_after_switch_theme() {
   233 			'description_text_field'					=>	__( 'Description:', 'portfolio' ),
   192 		global $prtfl_filenames, $prtfl_themepath;
   234 			'svn_text_field'							=>	__( 'SVN:', 'portfolio' ),
   193 		$file_exists_flag = true;
   235 			'executor_text_field'						=>	__( 'Executor:', 'portfolio' ),
   194 		foreach ( $prtfl_filenames as $filename ) {
   236 			'screenshot_text_field'						=>	__( 'More screenshots:', 'portfolio' ),
   195 			if ( ! file_exists( $prtfl_themepath . $filename ) )
   237 			'technologies_text_field'					=>	__( 'Technologies:', 'portfolio' ),
   196 				$file_exists_flag = false;
   238 			/* misc */
   197 		}
   239 			'slug' 										=>	'portfolio',
   198 		if ( ! $file_exists_flag )
   240 			'post_type_name'							=>	'bws-portfolio',
   199 			prtfl_plugin_install();
   241 			/* other */
   200 	}
   242 			'widget_updated' 							=>	1, /* this option is for updating plugin was added in v2.29 */
   201 }
   243 			'flush_rewrite_rules'						=>	1,
   202 
   244 		);
   203 if ( ! function_exists( 'prtfl_admin_error' ) ) {
   245 		return $option_defaults;
   204 	function prtfl_admin_error() {
   246 	}
   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 }
   247 }
   517 
   248 
   518 /* Create post type for portfolio */
   249 /* Create post type for portfolio */
   519 if ( ! function_exists( 'prtfl_post_type_portfolio' ) ) {
   250 if ( ! function_exists( 'prtfl_post_type_portfolio' ) ) {
   520 	function prtfl_post_type_portfolio() {
   251 	function prtfl_post_type_portfolio() {
   521 		global $wpdb, $prtfl_options;
   252 		global $wpdb, $prtfl_options;
   522 
   253 
   523 		$slug		=	isset( $prtfl_options['prtfl_slug'] ) && ! empty( $prtfl_options['prtfl_slug'] ) ? $prtfl_options['prtfl_slug'] : 'portfolio';
       
   524 		register_post_type(
   254 		register_post_type(
   525 			'portfolio',
   255 			$prtfl_options['post_type_name'],
   526 			array(
   256 			array(
   527 				'labels' => array(
   257 				'labels' => array(
   528 					'name'					=>	__( 'Portfolio', 'portfolio' ),
   258 					'name'					=> __( 'Portfolio', 'portfolio' ),
   529 					'singular_name'			=>	__( 'Portfolio', 'portfolio' ),
   259 					'all_items'				=> __( 'Projects', 'portfolio' ),
   530 					'add_new'				=>	__( 'Add New', 'portfolio' ),
   260 					'singular_name'			=> __( 'Project', 'portfolio' ),
   531 					'add_new_item'			=>	__( 'Add New Portfolio', 'portfolio' ),
   261 					'add_new'				=> __( 'Add New', 'portfolio' ),
   532 					'edit'					=>	__( 'Edit', 'portfolio' ),
   262 					'add_new_item'			=> __( 'Add New Project', 'portfolio' ),
   533 					'edit_item'				=>	__( 'Edit Portfolio', 'portfolio' ),
   263 					'edit'					=> __( 'Edit', 'portfolio' ),
   534 					'new_item'				=>	__( 'New Portfolio', 'portfolio' ),
   264 					'edit_item'				=> __( 'Edit Project', 'portfolio' ),
   535 					'view'					=>	__( 'View Portfolio', 'portfolio' ),
   265 					'new_item'				=> __( 'New Project', 'portfolio' ),
   536 					'view_item'				=>	__( 'View Portfolio', 'portfolio' ),
   266 					'view'					=> __( 'View Project', 'portfolio' ),
   537 					'search_items'			=>	__( 'Search Portfolio', 'portfolio' ),
   267 					'view_item'				=> __( 'View Project', 'portfolio' ),
   538 					'not_found'				=>	__( 'No portfolio found', 'portfolio' ),
   268 					'search_items'			=> __( 'Search Projects', 'portfolio' ),
   539 					'not_found_in_trash'	=>	__( 'No portfolio found in Trash', 'portfolio' ),
   269 					'not_found'				=> __( 'No project found', 'portfolio' ),
   540 					'parent'				=>	__( 'Parent Portfolio', 'portfolio' ),
   270 					'not_found_in_trash'	=> __( 'No project found in Trash', 'portfolio' ),
       
   271 					'parent'				=> __( 'Parent Project', 'portfolio' ),
       
   272 					'filter_items_list'		=> __( 'Filter projects list', 'portfolio' ),
       
   273 					'items_list_navigation'	=> __( 'Projects list navigation', 'portfolio' ),
       
   274 					'items_list'			=> __( 'Projects list', 'portfolio' )
   541 				),
   275 				),
   542 				'description'			=>	__( 'Create a portfolio item', 'portfolio' ),
   276 				'description'			=> __( 'Create a project item', 'portfolio' ),
   543 				'public'				=>	true,
   277 				'public'				=> true,
   544 				'show_ui'				=>	true,
   278 				'show_ui'				=> true,
   545 				'publicly_queryable'	=>	true,
   279 				'publicly_queryable'	=> true,
   546 				'exclude_from_search'	=>	true,
   280 				'exclude_from_search'	=> true,
   547 				'hierarchical'			=>	true,
   281 				'hierarchical'			=> true,
   548 				'query_var'				=>	true,
   282 				'query_var'				=> true,
   549 				'register_meta_box_cb'	=>	'prtfl_init_metaboxes',
   283 				'register_meta_box_cb'	=> 'prtfl_init_metaboxes',
   550 				'rewrite'				=>	array( 'slug' => $slug ),
   284 				'rewrite'				=> array( 'slug' => $prtfl_options['slug'] ),
   551 				'supports'				=>	array(
   285 				'menu_icon'				=> 'dashicons-id-alt',
       
   286 				'supports'				=> array(
   552 					'title', /* Text input field to create a post title. */
   287 					'title', /* Text input field to create a post title. */
   553 					'editor',
   288 					'editor',
   554 					'custom-fields',
   289 					'custom-fields',
   555 					'comments', /* Ability to turn on/off comments. */
   290 					'comments', /* Ability to turn on/off comments. */
   556 					'thumbnail', /* Displays a box for featured image. */
   291 					'thumbnail', /* Displays a box for featured image. */
   557 					'author',
   292 					'author',
   558 					'page-attributes'
   293 					'page-attributes'
   559 				)
   294 				)
   560 			)
   295 			)
   561 		);
   296 		);
   562 	}
   297 
   563 }
       
   564 
       
   565 /* Create taxonomy for portfolio - Technologies and Executors Profile */
       
   566 if ( ! function_exists( 'prtfl_taxonomy_portfolio' ) ) {
       
   567 	function prtfl_taxonomy_portfolio() {
       
   568 		register_taxonomy(
   298 		register_taxonomy(
   569 			'portfolio_executor_profile',
   299 			'portfolio_executor_profile',
   570 			'portfolio',
   300 			$prtfl_options['post_type_name'],
   571 			array(
   301 			array(
   572 				'hierarchical'			=>	false,
   302 				'hierarchical'			=> false,
   573 				'update_count_callback' =>	'_update_post_term_count',
   303 				'update_count_callback' => '_update_post_term_count',
   574 				'labels'				=>	array(
   304 				'labels'				=> array(
   575 					'name'							=>	__( 'Executor Profiles', 'portfolio' ),
   305 					'name'							=> __( 'Executors', 'portfolio' ),
   576 					'singular_name'					=>	__( 'Executor Profile', 'portfolio' ),
   306 					'singular_name'					=> __( 'Executor', 'portfolio' ),
   577 					'search_items'					=>	__( 'Search Executor Profiles', 'portfolio' ),
   307 					'search_items'					=> __( 'Search Executors', 'portfolio' ),
   578 					'popular_items'					=>	__( 'Popular Executor Profiles', 'portfolio' ),
   308 					'popular_items'					=> __( 'Popular Executors', 'portfolio' ),
   579 					'all_items'						=>	__( 'All Executor Profiles', 'portfolio' ),
   309 					'all_items'						=> __( 'All Executors', 'portfolio' ),
   580 					'parent_item'					=>	__( 'Parent Executor Profile', 'portfolio' ),
   310 					'parent_item'					=> __( 'Parent Executor', 'portfolio' ),
   581 					'parent_item_colon'				=>	__( 'Parent Executor Profile:', 'portfolio' ),
   311 					'parent_item_colon'				=> __( 'Parent Executor:', 'portfolio' ),
   582 					'edit_item'						=>	__( 'Edit Executor Profile', 'portfolio' ),
   312 					'edit_item'						=> __( 'Edit Executor', 'portfolio' ),
   583 					'update_item'					=>	__( 'Update Executor Profile', 'portfolio' ),
   313 					'update_item'					=> __( 'Update Executor', 'portfolio' ),
   584 					'add_new_item'					=>	__( 'Add New Executor Profile', 'portfolio' ),
   314 					'add_new_item'					=> __( 'Add New Executor', 'portfolio' ),
   585 					'new_item_name'					=>	__( 'New Executor Name', 'portfolio' ),
   315 					'new_item_name'					=> __( 'New Executor Name', 'portfolio' ),
   586 					'separate_items_with_commas'	=>	__( 'Separate Executor Profiles with commas', 'portfolio' ),
   316 					'separate_items_with_commas'	=> __( 'Separate executors with commas', 'portfolio' ),
   587 					'add_or_remove_items'			=>	__( 'Add or remove Executor Profile', 'portfolio' ),
   317 					'add_or_remove_items'			=> __( 'Add or remove Executor', 'portfolio' ),
   588 					'choose_from_most_used'			=>	__( 'Choose from the most used Executor Profiles', 'portfolio' ),
   318 					'choose_from_most_used'			=> __( 'Choose from the most used Executors', 'portfolio' ),
   589 					'menu_name'						=>	__( 'Executors', 'portfolio' )
   319 					'menu_name'						=> __( 'Executors', 'portfolio' ),
       
   320 					'items_list_navigation' 		=> __( 'Executors list navigation', 'portfolio' ),
       
   321 					'items_list'					=> __( 'Executors list', 'portfolio' )
   590 				),
   322 				),
   591 				'sort'					=>	true,
   323 				'sort'					=> true,
   592 				'args'					=>	array( 'orderby' => 'term_order' ),
   324 				'args'					=> array( 'orderby' => 'term_order' ),
   593 				'rewrite'				=>	array( 'slug' => 'executor_profile' ),
   325 				'rewrite'				=> array( 'slug' => 'executor_profile' ),
   594 				'show_tagcloud'			=>	false
   326 				'show_tagcloud'			=> false
   595 			)
   327 			)
   596 		);
   328 		);
   597 
   329 
   598 		register_taxonomy(
   330 		register_taxonomy(
   599 			'portfolio_technologies',
   331 			'portfolio_technologies',
   600 			'portfolio',
   332 			$prtfl_options['post_type_name'],
   601 			array(
   333 			array(
   602 				'hierarchical'			=>	false,
   334 				'hierarchical'			=> false,
   603 				'update_count_callback'	=>	'_update_post_term_count',
   335 				'update_count_callback'	=> '_update_post_term_count',
   604 				'labels'				=>	array(
   336 				'labels'				=> array(
   605 					'name'							=>	__( 'Technologies', 'portfolio' ),
   337 					'name'							=> __( 'Technologies', 'portfolio' ),
   606 					'singular_name'					=>	__( 'Technology', 'portfolio'),
   338 					'singular_name'					=> __( 'Technology', 'portfolio' ),
   607 					'search_items'					=>	__( 'Search Technologies', 'portfolio' ),
   339 					'search_items'					=> __( 'Search Technologies', 'portfolio' ),
   608 					'popular_items'					=>	__( 'Popular Technologies', 'portfolio' ),
   340 					'popular_items'					=> __( 'Popular Technologies', 'portfolio' ),
   609 					'all_items'						=>	__( 'All Technologies', 'portfolio' ),
   341 					'all_items'						=> __( 'All Technologies', 'portfolio' ),
   610 					'parent_item'					=>	__( 'Parent Technology', 'portfolio' ),
   342 					'parent_item'					=> __( 'Parent Technology', 'portfolio' ),
   611 					'parent_item_colon'				=>	__( 'Parent Technology:', 'portfolio' ),
   343 					'parent_item_colon'				=> __( 'Parent Technology:', 'portfolio' ),
   612 					'edit_item'						=>	__( 'Edit Technology', 'portfolio' ),
   344 					'edit_item'						=> __( 'Edit Technology', 'portfolio' ),
   613 					'update_item'					=>	__( 'Update Technology', 'portfolio' ),
   345 					'update_item'					=> __( 'Update Technology', 'portfolio' ),
   614 					'add_new_item'					=>	__( 'Add New Technology', 'portfolio' ),
   346 					'add_new_item'					=> __( 'Add New Technology', 'portfolio' ),
   615 					'new_item_name'					=>	__( 'New Technology Name', 'portfolio' ),
   347 					'new_item_name'					=> __( 'New Technology Name', 'portfolio' ),
   616 					'separate_items_with_commas'	=>	__( 'Separate Technologies with commas', 'portfolio' ),
   348 					'separate_items_with_commas'	=> __( 'Separate technologies with commas', 'portfolio' ),
   617 					'add_or_remove_items' 			=>	__( 'Add or remove Technology', 'portfolio' ),
   349 					'add_or_remove_items'			=> __( 'Add or remove Technology', 'portfolio' ),
   618 					'choose_from_most_used' 		=>	__( 'Choose from the most used technologies', 'portfolio' ),
   350 					'choose_from_most_used'			=> __( 'Choose from the most used technologies', 'portfolio' ),
   619 					'menu_name'						=>	__( 'Technologies', 'portfolio' )
   351 					'menu_name'						=> __( 'Technologies', 'portfolio' ),
       
   352 					'items_list_navigation'			=> __( 'Technologies list navigation', 'portfolio' ),
       
   353 					'items_list'					=> __( 'Technologies list', 'portfolio' )
   620 				),
   354 				),
   621 				'query_var'				=>	'technologies',
   355 				'query_var'				=> 'technologies',
   622 				'rewrite'				=>	array( 'slug' => 'technologies' ),
   356 				'rewrite'				=> array( 'slug' => 'technologies' ),
   623 				'public'				=>	true,
   357 				'show_ui'				=> true,
   624 				'show_ui'				=>	true,
   358 				'show_tagcloud' 		=> false
   625 				'_builtin'				=>	true,
       
   626 				'show_tagcloud' 		=>	false
       
   627 			)
   359 			)
   628 		);
   360 		);
   629 	}
   361 
       
   362 		if ( isset( $prtfl_options["flush_rewrite_rules"] ) && 1 == $prtfl_options["flush_rewrite_rules"]  ) {
       
   363 			flush_rewrite_rules();
       
   364 			$prtfl_options["flush_rewrite_rules"] = 0;
       
   365 			update_option( 'prtfl_options', $prtfl_options );
       
   366 		}
       
   367 	}
       
   368 }
       
   369 
       
   370 /**
       
   371  * Plugin include demo
       
   372  * @return void
       
   373  */
       
   374 if ( ! function_exists( 'prtfl_include_demo_data' ) ) {
       
   375 	function prtfl_include_demo_data() {
       
   376 		global $prtfl_BWS_demo_data;
       
   377 		require_once( plugin_dir_path( __FILE__ ) . 'inc/demo-data/class-bws-demo-data.php' );
       
   378 		$args = array(
       
   379 			'plugin_basename' 	=> plugin_basename( __FILE__ ),
       
   380 			'plugin_prefix'		=> 'prtfl_',
       
   381 			'plugin_name'		=> 'Portfolio',
       
   382 			'plugin_page'		=> 'portfolio.php&bws_active_tab=import-export',
       
   383 			'demo_folder'		=> plugin_dir_path( __FILE__ ) . 'inc/demo-data/'
       
   384 		);
       
   385 		$prtfl_BWS_demo_data = new Bws_Demo_Data( $args );
       
   386 
       
   387 		/* filter for image url from demo data */
       
   388 		add_filter( 'wp_get_attachment_url', array( $prtfl_BWS_demo_data, 'bws_wp_get_attachment_url' ), 10, 2 );
       
   389 		add_filter( 'wp_get_attachment_image_attributes', array( $prtfl_BWS_demo_data, 'bws_wp_get_attachment_image_attributes' ), 10, 3 );
       
   390 		add_filter( 'wp_update_attachment_metadata',array( $prtfl_BWS_demo_data, 'bws_wp_update_attachment_metadata' ), 10, 2 );
       
   391 	}
       
   392 }
       
   393 
       
   394 /**
       
   395  * Plugin settings page
       
   396  * @return void
       
   397  */
       
   398 if ( ! function_exists( 'prtfl_settings_page' ) ) {
       
   399 	function prtfl_settings_page() {
       
   400 		require_once( dirname( __FILE__ ) . '/inc/class-prtfl-settings.php' );
       
   401 		$page = new Prtfl_Settings_Tabs( plugin_basename( __FILE__ ) ); ?>
       
   402 		<div class="wrap">
       
   403 			<h1><?php _e( 'Portfolio Settings', 'portfolio' ); ?></h1>
       
   404 			<?php $page->display_content(); ?>
       
   405 		</div>
       
   406 	<?php }
   630 }
   407 }
   631 
   408 
   632 /* add query_var "post_type" in case we have another custom post type with query_var 'portfolio' (example: jetpack portfolio) */
   409 /* 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' ) ) {
   410 if ( ! function_exists( 'prtfl_request_filter' ) ) {
   634 	function prtfl_request_filter( $query_vars ) {
   411 	function prtfl_request_filter( $query_vars ) {
   635 		if ( isset( $query_vars["post_type"] ) && $query_vars["post_type"] == 'jetpack-portfolio' ) {
   412 		global $prtfl_options;
   636 			if ( ! get_posts( $query_vars ) )
   413 		if ( isset( $query_vars["post_type"] ) && 'jetpack-portfolio' == $query_vars["post_type"] ) {
   637 				$query_vars["post_type"] = 'portfolio';
   414 			if ( ! get_posts( $query_vars ) ) {
       
   415 				$query_vars["post_type"] = $prtfl_options['post_type_name'];
       
   416 			}
   638 		}
   417 		}
   639 		return $query_vars;
   418 		return $query_vars;
   640 	}
   419 	}
   641 }
   420 }
   642 
   421 
   643 if ( ! function_exists( 'prtfl_technologies_get_posts' ) ) {
   422 if ( ! function_exists( 'prtfl_technologies_get_posts' ) ) {
   644 	function prtfl_technologies_get_posts( $query ) {
   423 	function prtfl_technologies_get_posts( $query ) {
   645 		if ( ( isset( $query->query_vars["technologies"] ) || isset( $query->query_vars["portfolio_executor_profile"] ) ) && ( ! is_admin() ) )
   424 		global $prtfl_options;
   646 			$query->set( 'post_type', array( 'portfolio' ) );
   425 
       
   426 		if ( ( isset( $query->query_vars["technologies"] ) || isset( $query->query_vars["portfolio_executor_profile"] ) ) && ( ! is_admin() ) ) {
       
   427 			$query->set( 'post_type', array( $prtfl_options['post_type_name'] ) );
       
   428 		}
   647 		return $query;
   429 		return $query;
   648 	}
   430 	}
   649 }
   431 }
   650 
   432 
   651 /**
   433 /**
   656 		/* constructor of class */
   438 		/* constructor of class */
   657 		function __construct() {
   439 		function __construct() {
   658 			parent::__construct(
   440 			parent::__construct(
   659 					'portfolio_technologies_widget',
   441 					'portfolio_technologies_widget',
   660 					__( 'Technologies', 'portfolio' ),
   442 					__( 'Technologies', 'portfolio' ),
   661 					array( 'description' => __( 'Your most used portfolio technologies as a tag cloud', 'portfolio' ) )
   443 					array( 'description' => __( 'The tag cloud with your most used portfolio technologies.', 'portfolio' ) )
   662 				);
   444 				);
   663 		}
   445 		}
   664 		/* Function to displaying widget in front end */
   446 		/* Function to displaying widget in front end */
   665 		function widget( $args, $instance ) {
   447 		function widget( $args, $instance ) {
   666 			$widget_title = isset( $instance['widget_title'] ) ? $instance['widget_title'] : null;
   448 			$widget_title = isset( $instance['widget_title'] ) ? $instance['widget_title'] : null;
   667 			$widget_title = apply_filters( 'widget_title', $widget_title, '', 'portfolio_technologies_widget' );
   449 			$widget_title = apply_filters( 'widget_title', $widget_title, $instance, $this->id_base );
   668 			echo $args['before_widget'];
   450 			echo $args['before_widget'];
   669 			if ( $widget_title )
   451 			if ( $widget_title )
   670 				echo $args['before_title'] . $widget_title . $args['after_title'];
   452 				echo $args['before_title'] . $widget_title . $args['after_title'];
   671 			echo '<div class="tagcloud">';
   453 			echo '<div class="tagcloud">';
   672 			wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => 'portfolio_technologies', 'number' => 0 ) ) );
   454 			wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array( 'taxonomy' => 'portfolio_technologies', 'number' => 0 ) ) );
   674 			echo $args['after_widget'];
   456 			echo $args['after_widget'];
   675 		}
   457 		}
   676 		/* Function to save widget settings */
   458 		/* Function to save widget settings */
   677 		function update( $new_instance, $old_instance ) {
   459 		function update( $new_instance, $old_instance ) {
   678 			$instance = array();
   460 			$instance = array();
   679 			$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;		
   461 			$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;
   680 			return $instance;
   462 			return $instance;
   681 		}
   463 		}
   682 		/* Function to displaying widget settings in back end */
   464 		/* Function to displaying widget settings in back end */
   683 		function form( $instance ) {
   465 		function form( $instance ) {
   684 			$widget_title = isset( $instance['widget_title'] ) ? stripslashes( esc_html( $instance['widget_title'] ) ) : null; ?>
   466 			$widget_title = isset( $instance['widget_title'] ) ? stripslashes( esc_html( $instance['widget_title'] ) ) : null; ?>
   696 }
   478 }
   697 
   479 
   698 /* Create custom permalinks for portfolio post type */
   480 /* Create custom permalinks for portfolio post type */
   699 if ( ! function_exists( 'prtfl_custom_permalinks' ) ) {
   481 if ( ! function_exists( 'prtfl_custom_permalinks' ) ) {
   700 	function prtfl_custom_permalinks( $rules ) {
   482 	function prtfl_custom_permalinks( $rules ) {
       
   483 		global $prtfl_options;
   701 		$newrules = array();
   484 		$newrules = array();
   702 		$newrules['portfolio/page/([^/]+)/?$']	=	'index.php?pagename=portfolio&paged=$matches[1]';
   485 
   703 		$newrules['portfolio/page/([^/]+)?$']	=	'index.php?pagename=portfolio&paged=$matches[1]';
   486 		if ( empty( $prtfl_options ) ) {
   704 		/* return $newrules + $rules; */
   487 			$prtfl_options = get_option( 'prtfl_options' );
       
   488 			if ( empty( $prtfl_options ) ) {
       
   489 				register_prtfl_settings();
       
   490 			}
       
   491 		}
       
   492 
       
   493 		if ( ! empty( $prtfl_options['page_id_portfolio_template'] ) ) {
       
   494 			$parent = get_post( $prtfl_options['page_id_portfolio_template'] );
       
   495 			if ( ! empty( $parent ) ) {
       
   496 				if ( ! isset( $rules['(.+)/' . $parent->post_name . '/([^/]+)/?$'] ) || ! isset( $rules[ $parent->post_name . '/([^/]+)/?$'] ) ) {
       
   497 					$newrules['(.+)/' . $parent->post_name .  '/([^/]+)/?$'] = 'index.php?post_type=' . $prtfl_options['post_type_name'] . '&name=$matches[2]&posts_per_page=-1';
       
   498 					$newrules[ $parent->post_name . '/([^/]+)/?$'] = 'index.php?post_type=' . $prtfl_options['post_type_name'] . '&name=$matches[1]&posts_per_page=-1';
       
   499 					$newrules[ $parent->post_name . '/page/([^/]+)/?$'] = 'index.php?pagename=' . $parent->post_name . '&paged=$matches[1]';
       
   500 					$newrules[ $parent->post_name . '/page/([^/]+)?$'] = 'index.php?pagename=' . $parent->post_name . '&paged=$matches[1]';
       
   501 				}
       
   502 			}
       
   503 		}
       
   504 
       
   505 		/* fix feed permalink (<link rel="alternate" type="application/rss+xml" ... >) on the attachment single page (if the attachment is Attached to the portfolio page) */
       
   506 		if ( ! empty( $prtfl_options['slug'] ) ) {
       
   507 			$newrules[ $prtfl_options['slug'] . '/.+?/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?attachment=$matches[1]&feed=$matches[2]';
       
   508 			$newrules[ $prtfl_options['slug'] . '/.+?/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' ]      = 'index.php?attachment=$matches[1]&feed=$matches[2]';
       
   509 		}
   705 		if ( $rules )
   510 		if ( $rules )
   706 			return array_merge( $newrules, $rules );
   511 			return array_merge( $newrules, $rules );
   707 	}
   512 	}
   708 }
   513 }
   709 
   514 
   710 /* flush_rules() if our rules are not yet included */
   515 /**
   711 if ( ! function_exists( 'prtfl_flush_rules' ) ) {
   516 * Load a template. Handles template usage so that plugin can use own templates instead of the themes.
   712 	function prtfl_flush_rules() {
   517 *
   713 		$rules = get_option( 'rewrite_rules' );
   518 * Templates are in the 'templates' folder.
   714 		if ( ! isset( $rules['portfolio/page/([^/]+)/?$'] ) ) {
   519 * overrides in /{theme}/bws-templates/ by default.
   715 			global $wp_rewrite;
   520 * @param mixed $template
   716 			$wp_rewrite->flush_rules();
   521 * @return string
   717 		}
   522 */
       
   523 if ( ! function_exists( 'prtfl_template_include' ) ) {
       
   524 	function prtfl_template_include( $template ) {
       
   525 		global $prtfl_options, $wp_query;
       
   526 
       
   527 		if ( function_exists( 'is_embed' ) && is_embed() ) {
       
   528 			return $template;
       
   529 		}
       
   530 
       
   531 		$post_type = get_post_type();
       
   532 		if ( is_single() && $prtfl_options['post_type_name'] == $post_type ) {
       
   533 			$file = 'portfolio-post.php';
       
   534 		} elseif ( $prtfl_options['post_type_name'] == $post_type && ( isset( $wp_query->query_vars['technologies'] ) || isset( $wp_query->query_vars['portfolio_executor_profile'] ) ) ) {
       
   535 			$file = 'portfolio.php';
       
   536 		} elseif ( ! empty( $prtfl_options['page_id_portfolio_template'] ) && is_page( $prtfl_options['page_id_portfolio_template'] ) ) {
       
   537 			$file = 'portfolio.php';
       
   538 		}
       
   539 
       
   540 		if ( isset( $file ) ) {
       
   541 			if ( ! wp_script_is( 'prtfl_front_script', 'registered' ) ) {
       
   542 				wp_register_script( 'prtfl_front_script', plugins_url( 'js/front_script.js', __FILE__ ), array( 'jquery' ) );
       
   543 			}
       
   544 
       
   545 			$find = array( $file, 'bws-templates/' . $file );
       
   546 			$template = locate_template( $find );
       
   547 
       
   548 			if ( ! $template ) {
       
   549 				$template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . $file;
       
   550 			}
       
   551 		}
       
   552 
       
   553 		return $template;
   718 	}
   554 	}
   719 }
   555 }
   720 
   556 
   721 /* Initialization of all metaboxes on the 'Add Portfolio' and Edit Portfolio pages */
   557 /* Initialization of all metaboxes on the 'Add Portfolio' and Edit Portfolio pages */
   722 if ( ! function_exists( 'prtfl_init_metaboxes' ) ) {
   558 if ( ! function_exists( 'prtfl_init_metaboxes' ) ) {
   723 	function prtfl_init_metaboxes() {
   559 	function prtfl_init_metaboxes() {
   724 		add_meta_box( 'Portfolio-Info', __( 'Portfolio Info', 'portfolio' ), 'prtfl_post_custom_box', 'portfolio', 'normal', 'high' ); /* Description metaboxe */
   560 		global $prtfl_options;
   725 		add_meta_box( 'prtfl_categories_meta_box', __( 'Categories', 'portfolio' ), 'prtfl_categories_meta_box', 'portfolio', 'side', 'low' );
   561 		add_meta_box( 'prtfl_metabox_images', __( 'Images', 'portfolio' ), 'prtfl_metabox_images_block', $prtfl_options['post_type_name'], 'normal', 'high' );
   726 		if ( ! ( function_exists( 'rttchr_metabox_content_in_post' ) || function_exists( 'rttchrpr_metabox_content_in_post' ) ) ) {
   562 		add_meta_box( 'Portfolio-Info', __( 'General', 'portfolio' ), 'prtfl_post_custom_box', $prtfl_options['post_type_name'], 'normal', 'high' );
   727 			add_meta_box( 'prtfl_rttchr_metabox_ad', __( 'Already attached', 'portfolio' ), 'prtfl_rttchr_attach_box', 'portfolio', 'side', 'low' );
   563 
   728 		}
   564 		$bws_hide_premium_options_check = bws_hide_premium_options_check( $prtfl_options );
   729 		
   565 		if ( ! $bws_hide_premium_options_check ) {
       
   566 			add_meta_box( 'prtfl_categories_meta_box', __( 'Categories', 'portfolio' ), 'prtfl_categories_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
       
   567 			add_meta_box( 'prtfl_sectors_meta_box', __( 'Sectors', 'portfolio' ), 'prtfl_sectors_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
       
   568 			add_meta_box( 'prtfl_services_meta_box', __( 'Services', 'portfolio' ), 'prtfl_services_meta_box', $prtfl_options['post_type_name'], 'side', 'low' );
       
   569 		}
   730 	}
   570 	}
   731 }
   571 }
   732 
   572 
   733 /* Create custom meta box for portfolio post type */
   573 /* Create custom meta box for portfolio post type */
   734 if ( ! function_exists( 'prtfl_post_custom_box' ) ) {
   574 if ( ! function_exists( 'prtfl_post_custom_box' ) ) {
   735 	function prtfl_post_custom_box( $obj = '', $box = '' ) {
   575 	function prtfl_post_custom_box( $obj = '', $box = '' ) {
   736 		global $prtfl_boxes;
   576 		global $prtfl_boxes, $prtfl_plugin_info, $wp_version, $prtfl_options;
   737 		/* Generate box contents */
   577 		/* Generate box contents */
   738 		foreach ( $prtfl_boxes[ $box[ 'id' ] ] as $prtfl_box ) {
   578 		foreach ( $prtfl_boxes[ $box['id'] ] as $box ) {
   739 			echo prtfl_text_field( $prtfl_box );
   579 			echo prtfl_general_field( $box );
   740 		}
   580 		}
   741 	}
   581 
   742 }
   582 		$bws_hide_premium_options_check = bws_hide_premium_options_check( $prtfl_options );
   743 
   583 		if ( ! $bws_hide_premium_options_check ) { ?>
   744 /* Create custom meta box for re-attacher ad in portfolio */
   584 			<div class="bws_pro_version_bloc">
   745 if ( ! function_exists( 'prtfl_rttchr_attach_box' ) ) {
   585 				<div class="bws_pro_version_table_bloc">
   746 	function prtfl_rttchr_attach_box() { 
   586 					<div class="bws_table_bg" style="top: 0px; z-index: 2;"></div>
   747 		global $prtfl_plugin_info, $wp_version;
   587 
   748 
   588 
   749 		if ( ! function_exists( 'get_plugins' ) )
   589 					<div class="portfolio_admin_box">
   750 			require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
   590 						<p><label for="prtfl_client"><strong><?php _e( 'Client', 'portfolio' ); ?></strong></label></p>
   751 		$all_plugins = get_plugins();
   591 						<?php /* display visual editor */
   752 		if ( isset( $all_plugins['re-attacher/re-attacher.php'] ) || isset( $all_plugins['re-attacher-pro/re-attacher-pro.php'] ) ) {
   592 						$settings = array(
   753 			/* if re-attacher is installed */
   593 							'media_buttons' => 1,
   754 			$link = "plugins.php";
   594 							'textarea_name' => 'prtfl_client',
   755 			$text = __( 'Activate', 'portfolio' );
   595 							'textarea_rows' => 5,
   756 		} else {
   596 							'tinymce'       => 1
   757 			if ( function_exists( 'is_multisite' ) )
   597 						);
   758 				$link = ( ! is_multisite() ) ? admin_url( '/' ) : network_admin_url( '/' );
   598 						wp_editor( '', 'prtfl_client', $settings ); ?>
   759 			else
   599 					</div>
   760 				$link = admin_url( '/' );
   600 					<div class="portfolio_admin_box">
   761 			$link = $link . 'plugin-install.php?tab=search&type=term&s=Re-attacher+BestWebSoft&plugin-search-input=Search+Plugins';
   601 						<p><label for="prtfl_featured"><strong><?php _e( 'Featured project', 'portfolio' ); ?></strong></label></p>
   762 			$text = __( 'Install now', 'portfolio' );			
   602 						<p><input id="prtfl_featured" disabled="disabled" type="checkbox" name="prtfl_featured" value="1" />
   763 		} ?>
   603 							<em><?php _e( 'Add to slider', 'portfolio' ); ?></em>
   764 		<p>
   604 						</p>
   765 			<?php _e( "If you'd like to attach the files, which are already uploaded, please use Re-attacher plugin.", 'portfolio' ) ; 
   605 					</div>
   766 			if ( 3.5 > $wp_version ) { ?>
   606 					<div class="bws_pro_version_tooltip">
   767 				<br />
   607 						<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/portfolio/?k=f047e20c92c972c398187a4f70240285&pn=74&v=<?php echo $prtfl_plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="Portfolio Pro Plugin" style="z-index: 3;" ><?php _e( 'Learn More', 'portfolio' ); ?></a>
   768 				<strong>
   608 						<div class="clear"></div>
   769 					<?php echo '($nbsp;' . __( 'Requires at least', 'portfolio' ) . '&nbsp;WordPress 3.5 )'; ?>
   609 					</div>
   770 				</strong>
   610 				</div>
   771 			<?php } ?>
   611 			</div>
   772 		</p>
   612 		<?php }
   773 		<p>
   613 	}
   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>
   614 }
   775 			<a class="button-primary" href="<?php echo $link; ?>" target="_blank" style="margin-right: 5px;"><?php echo $text; ?></a>
   615 
   776 		</p>
   616 /**
       
   617  * This is the field meta box
       
   618  * @param     array      $args   array of data for meta box
       
   619  * @return                       html structure of meta box
       
   620  */
       
   621 if ( ! function_exists( 'prtfl_general_field' ) ) {
       
   622 	function prtfl_general_field( $args ) {
       
   623 		global $post;
       
   624 
       
   625 		$post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
       
   626 		$value = ! empty( $post_meta ) && is_array( $post_meta ) && ! empty( $post_meta[ $args['name'] ] ) ? $post_meta[ $args['name'] ] : ""; ?>
       
   627 		<div class="portfolio_admin_box">
       
   628 			<p><label for="<?php echo $args['name']; ?>"><strong><?php echo $args['title']; ?></strong></label></p>
       
   629 			<p><input id="<?php echo $args['name']; ?>" type="text" style="width:80%;" name="<?php echo $args['name']; ?>" value="<?php echo $value; ?>" /></p>
       
   630 		</div>
   777 	<?php }
   631 	<?php }
   778 }
   632 }
   779 
   633 
   780 /**
   634 /**
   781  * Banner on Portfolio Edit Page
   635  * Banner on Portfolio Edit Page
   792 							<ul class="category-tabs">
   646 							<ul class="category-tabs">
   793 								<li class="tabs"><a href="#"><?php _e( 'All Categories', 'portfolio' ); ?></a></li>
   647 								<li class="tabs"><a href="#"><?php _e( 'All Categories', 'portfolio' ); ?></a></li>
   794 								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
   648 								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
   795 							</ul>
   649 							</ul>
   796 							<div class="tabs-panel" style="display: none;">
   650 							<div class="tabs-panel" style="display: none;">
   797 								<ul class="categorychecklist form-no-clear">				
   651 								<ul class="categorychecklist form-no-clear">
   798 									<li class="popular-category">
   652 									<li class="popular-category">
   799 										<label class="selectit"><input checked="checked" disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
   653 										<label class="selectit"><input checked="checked" disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
   800 									</li>
   654 									</li>
   801 								</ul>
   655 								</ul>
   802 							</div>
   656 							</div>
   803 							<div class="tabs-panel">		
   657 							<div class="tabs-panel">
   804 								<ul class="categorychecklist form-no-clear">				
   658 								<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>
   659 									<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>
   660 								</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>
   661 							</div>
   820 						</div>
   662 						</div>
   821 					</div>
   663 					</div>
   822 				</div>
   664 				</div>
   823 				<div class="bws_pro_version_tooltip">
   665 				<div class="bws_pro_version_tooltip">
   824 					<div class="bws_info">
   666 					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/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>
   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>
   667 					<div class="clear"></div>
   834 				</div>
   668 				</div>
   835 			</div>
   669 			</div>
   836 		</div>
   670 		</div>
   837 	<?php }
   671 	<?php }
   838 }
   672 }
   839 
   673 
   840 /* This is the default text field meta box */
   674 /**
   841 if ( ! function_exists( 'prtfl_text_field' ) ) {
   675  * Banner on Portfolio Edit Page
   842 	function prtfl_text_field( $args ) {
   676  */
   843 		global $post;
   677 if ( ! function_exists( 'prtfl_sectors_meta_box' ) ) {
   844 		$description = $args[2];
   678 	function prtfl_sectors_meta_box() {
   845 		if ( '1' == get_option( 'prtfl_postmeta_update' ) ) {
   679 		global $prtfl_plugin_info, $wp_version; ?>
   846 			$post_meta = get_post_meta( $post->ID, 'prtfl_information', true);
   680 		<div class="bws_pro_version_bloc">
   847 			$args[2] = is_array( $post_meta ) ? esc_html( $post_meta[ $args[0] ] ) : "" ;
   681 			<div class="bws_pro_version_table_bloc">
   848 		} else {
   682 				<div class="bws_table_bg" style="top: 0px;"></div>
   849 			$args[2] = esc_html( get_post_meta( $post->ID, $args[0], true ) );
   683 				<div class="prtfl_portfolio_sectorsdiv">
   850 		}
   684 					<div class="inside">
   851 		$label_format =
   685 						<div class="">
   852 			'<div class="portfolio_admin_box">' .
   686 							<ul class="category-tabs">
   853 			'<p><label for="%1$s"><strong>%2$s</strong></label></p>' .
   687 								<li class="tabs"><a href="#"><?php _e( 'All Sectors', 'portfolio' ); ?></a></li>
   854 			'<p><input style="width: 80%%;" type="text" name="%1$s" id="%1$s" value="%3$s" /></p>' .
   688 								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
   855 			'<p><em>' . $description .'</em></p>' .
   689 							</ul>
   856 			'</div>';
   690 							<div class="tabs-panel" style="display: none;">
   857 		if ( '_prtfl_date_compl' == $args[0] )
   691 								<ul class="categorychecklist form-no-clear">
   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>';
   692 									<li class="popular-category">
   859 		return vsprintf( $label_format, $args );
   693 										<label class="selectit"><input disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
   860 	}
   694 									</li>
       
   695 								</ul>
       
   696 							</div>
       
   697 							<div class="tabs-panel">
       
   698 								<ul class="categorychecklist form-no-clear">
       
   699 									<li class="popular-category"><label class="selectit"><input value="236" name="tax_input[portfolio_sectors][]" disabled="disabled" type="checkbox" /> <?php _e( 'Sector', 'portfolio' ); ?> 1</label></li>
       
   700 									<li class="popular-category"><label class="selectit"><input value="237" name="tax_input[portfolio_sectors][]" disabled="disabled" type="checkbox" /> <?php _e( 'Sector', 'portfolio' ); ?> 2</label></li>
       
   701 								</ul>
       
   702 							</div>
       
   703 						</div>
       
   704 					</div>
       
   705 				</div>
       
   706 				<div class="bws_pro_version_tooltip">
       
   707 					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/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>
       
   708 					<div class="clear"></div>
       
   709 				</div>
       
   710 			</div>
       
   711 		</div>
       
   712 	<?php }
       
   713 }
       
   714 
       
   715 /**
       
   716  * Banner on Portfolio Edit Page
       
   717  */
       
   718 if ( ! function_exists( 'prtfl_services_meta_box' ) ) {
       
   719 	function prtfl_services_meta_box() {
       
   720 		global $prtfl_plugin_info, $wp_version; ?>
       
   721 		<div class="bws_pro_version_bloc">
       
   722 			<div class="bws_pro_version_table_bloc">
       
   723 				<div class="bws_table_bg" style="top: 0px;"></div>
       
   724 				<div class="prtfl_portfolio_servicesdiv">
       
   725 					<div class="inside">
       
   726 						<div class="">
       
   727 							<ul class="category-tabs">
       
   728 								<li class="tabs"><a href="#"><?php _e( 'All Services', 'portfolio' ); ?></a></li>
       
   729 								<li><a href="#"><?php _e( 'Most Used', 'portfolio' ); ?></a></li>
       
   730 							</ul>
       
   731 							<div class="tabs-panel" style="display: none;">
       
   732 								<ul class="categorychecklist form-no-clear">
       
   733 									<li class="popular-category">
       
   734 										<label class="selectit"><input disabled="disabled" value="236" type="checkbox" /><?php _e( 'Uncatgorized', 'portfolio' ); ?></label>
       
   735 									</li>
       
   736 								</ul>
       
   737 							</div>
       
   738 							<div class="tabs-panel">
       
   739 								<ul class="categorychecklist form-no-clear">
       
   740 									<li class="popular-category"><label class="selectit"><input value="236" name="tax_input[portfolio_services][]" disabled="disabled" type="checkbox" /> <?php _e( 'Service', 'portfolio' ); ?> 1</label></li>
       
   741 									<li class="popular-category"><label class="selectit"><input value="237" name="tax_input[portfolio_services][]" disabled="disabled" type="checkbox" /> <?php _e( 'Service', 'portfolio' ); ?> 2</label></li>
       
   742 								</ul>
       
   743 							</div>
       
   744 						</div>
       
   745 					</div>
       
   746 				</div>
       
   747 				<div class="bws_pro_version_tooltip">
       
   748 					<a class="bws_button" href="https://bestwebsoft.com/products/wordpress/plugins/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>
       
   749 					<div class="clear"></div>
       
   750 				</div>
       
   751 			</div>
       
   752 		</div>
       
   753 	<?php }
       
   754 }
       
   755 
       
   756 if ( ! function_exists( 'prtfl_metabox_images_block' ) ) {
       
   757 	function prtfl_metabox_images_block() {
       
   758 		global $post; ?>
       
   759 		<div id="prtfl_images_container">
       
   760 			<noscript><div class="error"><p><?php _e( 'Please enable JavaScript to add or delete images.', 'portfolio' ); ?></p></div></noscript>
       
   761 			<ul>
       
   762 				<?php if ( metadata_exists( 'post', $post->ID, '_prtfl_images' ) ) {
       
   763 					$prtfl_images = get_post_meta( $post->ID, '_prtfl_images', true );
       
   764 				} else {
       
   765 					/* Compatibility with old version 1.0.3 */
       
   766 					$args = array(
       
   767 						'post_parent'		=> $post->ID,
       
   768 						'post_type'			=> 'attachment',
       
   769 						'post_mime_type'	=> 'image',
       
   770 						'numberposts'		=> -1,
       
   771 						'orderby'			=> 'menu_order',
       
   772 						'order'				=> 'ASC',
       
   773 						'exclude'			=> get_post_thumbnail_id(),
       
   774 						'fields'			=> 'ids'
       
   775 					);
       
   776 					$attachments = get_children( $args );
       
   777 					$prtfl_images = implode( ',', $attachments );
       
   778 				}
       
   779 
       
   780 				$attachments = array_filter( explode( ',', $prtfl_images ) );
       
   781 
       
   782 				$update_meta = false;
       
   783 
       
   784 				if ( ! empty( $attachments ) ) {
       
   785 					foreach ( $attachments as $attachment_id ) {
       
   786 						$attachment = wp_get_attachment_image( $attachment_id, 'thumbnail' );
       
   787 
       
   788 						/* skip if attachment is empty */
       
   789 						if ( empty( $attachment ) ) {
       
   790 							$update_meta = true;
       
   791 							continue;
       
   792 						}
       
   793 
       
   794 						echo '<li class="prtfl_single_image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
       
   795 							' . $attachment . '
       
   796 							<span class="prtfl_delete_image"><a href="#" title="' . __( 'Delete image', 'portfolio' ) . '">' . __( 'Delete', 'portfolio' ) . '</a></span>
       
   797 						</li>';
       
   798 
       
   799 						$updated_images_ids[] = $attachment_id;
       
   800 					}
       
   801 
       
   802 					/* update product meta to set new portfolio ids */
       
   803 					if ( $update_meta )
       
   804 						update_post_meta( $post->ID, '_prtfl_images', implode( ',', $updated_images_ids ) );
       
   805 				} ?>
       
   806 			</ul>
       
   807 			<input type="hidden" id="prtfl_images" name="prtfl_images" value="<?php echo esc_attr( $prtfl_images ); ?>" />
       
   808 		</div>
       
   809 		<p class="prtfl_add_portfolio_images hide-if-no-js">
       
   810 			<a href="#" data-choose="<?php esc_attr_e( 'Add Images to Portfolio', 'portfolio' ); ?>" data-update="<?php esc_attr_e( 'Add to portfolio', 'portfolio' ); ?>" data-delete="<?php esc_attr_e( 'Delete image', 'portfolio' ); ?>" data-text="<?php esc_attr_e( 'Delete', 'portfolio' ); ?>"><?php _e( 'Add images', 'portfolio' ); ?></a>
       
   811 		</p>
       
   812 	<?php }
   861 }
   813 }
   862 
   814 
   863 /* When the post is saved, saves our custom data */
   815 /* When the post is saved, saves our custom data */
   864 if ( ! function_exists ( 'prtfl_save_postdata' ) ) {
   816 if ( ! function_exists( 'prtfl_save_postdata' ) ) {
   865 	function prtfl_save_postdata( $post_id, $post ) {
   817 	function prtfl_save_postdata( $post_id, $post ) {
   866 		global $prtfl_boxes;
   818 		global $prtfl_boxes, $prtfl_options;
   867 
   819 
   868 		register_prtfl_settings();
   820 		if ( $prtfl_options['post_type_name'] == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { /* Don't store custom data twice */
   869 
       
   870 		if ( "portfolio" == $post->post_type && ! wp_is_post_revision( $post_id ) && ! empty( $_POST ) ) { /* Don't store custom data twice */
       
   871 			/* Verify this came from the our screen and with proper authorization, because save_post can be triggered at other times */
   821 			/* 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 ) ) {
   822 			if ( ! current_user_can( 'edit_page', $post->ID ) ) {
   873 				return $post->ID;
   823 				return $post->ID;
   874 			}
   824 			}
   875 
   825 
   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. */
   826 			/* 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. */
   877 			foreach ( $prtfl_boxes as $prtfl_boxe ) {
   827 			foreach ( $prtfl_boxes as $prtfl_boxe ) {
   878 				foreach ( $prtfl_boxe as $prtfl_fields ) {
   828 				foreach ( $prtfl_boxe as $prtfl_fields ) {
   879 					if ( $prtfl_fields[0] == '_prtfl_link' || $prtfl_fields[0] == '_prtfl_svn' )
   829 					if ( isset( $_POST[ $prtfl_fields['name'] ] ) ) {
   880 						$my_data[ $prtfl_fields[0] ] = esc_url( $_POST[ $prtfl_fields[0] ] );
   830 						if ( 'url' == $prtfl_fields['type'] ) {
   881 					else
   831 							$my_data[ $prtfl_fields['name'] ] = esc_url( $_POST[ $prtfl_fields['name'] ] );
   882 						$my_data[ $prtfl_fields[0] ] = stripslashes( esc_html( $_POST[ $prtfl_fields[0] ] ) );
   832 						} else {
       
   833 							$my_data[ $prtfl_fields['name'] ] = stripslashes( esc_html( $_POST[ $prtfl_fields['name'] ] ) );
       
   834 						}
       
   835 					}
   883 				}
   836 				}
   884 			}
   837 			}
   885 			/*	Add values of $my_data as custom fields. Let's cycle through the $my_data array! */
   838 			if ( isset( $my_data ) ) {
   886 			if ( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
   839 				/*	Add values of $my_data as custom fields. Let's cycle through the $my_data array! */
   887 				/* Custom field has a value and this custom field exists in database */
   840 				if ( get_post_meta( $post->ID, 'prtfl_information', FALSE ) ) {
   888 				update_post_meta( $post->ID, 'prtfl_information', $my_data );
   841 					/* Custom field has a value and this custom field exists in database */
   889 			} elseif ( $value ) {
   842 					update_post_meta( $post->ID, 'prtfl_information', $my_data );
   890 				/* Custom field has a value, but this custom field does not exist in database */
   843 				} else {
   891 				add_post_meta( $post->ID, 'prtfl_information', $my_data );
   844 					/* Custom field does not have a value, but this custom field exists in database */
   892 			} else {
   845 					update_post_meta( $post->ID, 'prtfl_information', $my_data );
   893 				/* Custom field does not have a value, but this custom field exists in database */
   846 				}
   894 				update_post_meta( $post->ID, 'prtfl_information', $my_data );
   847 			}
       
   848 			if ( isset( $_POST['prtfl_images'] ) ) {
       
   849 				$attachment_ids = ! empty( $_POST['prtfl_images'] ) ? array_filter( explode( ',', sanitize_text_field( $_POST['prtfl_images'] ) ) ) : array();
       
   850 				update_post_meta( $post_id, '_prtfl_images', implode( ',', $attachment_ids ) );
   895 			}
   851 			}
   896 		}
   852 		}
   897 	}
   853 	}
   898 }
   854 }
   899 
   855 
   900 /**
   856 /**
   901  * Replace shortcode [latest_portfolio_items] from portfolio content before portfolio saving
   857  * Replace shortcode [latest_portfolio_items] from portfolio content before portfolio saving
   902  */
   858  */
   903 if ( ! function_exists ( 'prtfl_content_save_pre' ) ) {
   859 if ( ! function_exists( 'prtfl_content_save_pre' ) ) {
   904 	function prtfl_content_save_pre( $content ) {
   860 	function prtfl_content_save_pre( $content ) {
   905 		global $post;
   861 		global $post, $prtfl_options;
   906 		if ( isset( $post ) && "portfolio" == $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
   862 		if ( isset( $post ) && $prtfl_options['post_type_name'] == $post->post_type && ! wp_is_post_revision( $post->ID ) && ! empty( $_POST ) ) {
   907 			/* remove shortcode */
   863 			/* remove shortcode */
   908 			$content = preg_replace( '/\[latest_portfolio_items count=[\d]*\]/', '', $content );
   864 			$content = preg_replace( '/\[latest_portfolio_items count=[\d]*\]/', '', $content );
   909 		}
   865 		}
   910 		return $content;
   866 		return $content;
   911 	}
   867 	}
   912 }
   868 }
   913 
   869 
   914 if ( ! function_exists ( 'prtfl_register_plugin_links' ) ) {
   870 /* this function add custom fields and images for PDF&Print plugin in Portfolio post */
   915 	function prtfl_register_plugin_links( $links, $file ) {
   871 if ( ! function_exists( 'prtfl_add_pdf_print_content' ) ) {
   916 		$base = plugin_basename(__FILE__);
   872 	function prtfl_add_pdf_print_content( $content ) {
   917 		if ( $file == $base ) {
   873 		global $post, $prtfl_options;
   918 			if ( ! is_network_admin() )
   874 		$current_post_type = get_post_type();
   919 				$links[]	=	'<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
   875 		$custom_content = '';
   920 			$links[]	=	'<a href="http://wordpress.org/plugins/portfolio/faq/" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>';
   876 
   921 			$links[]	=	'<a href="http://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>';
   877 		if ( $prtfl_options['post_type_name'] == $current_post_type && ! empty( $post ) ) {
   922 		}
   878 
   923 		return $links;
   879 			if ( ! $prtfl_options ) {
   924 	}
   880 				$prtfl_options = get_option( 'prtfl_options' );
   925 }
   881 			}
   926 
   882 
   927 if ( ! function_exists ( 'prtfl_plugin_action_links' ) ) {
   883 			$post_meta	= get_post_meta( $post->ID, 'prtfl_information', true );
   928 	function prtfl_plugin_action_links( $links, $file ) {
   884 			$user_id 	= get_current_user_id();
   929 		if ( ! is_network_admin() ) {
   885 
   930 			/* Static so we don't call plugin_basename on every plugin row. */
   886 			if ( 1 == $prtfl_options['date_additional_field'] ) {
   931 			static $this_plugin;
   887 				$date_compl		=	isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
   932 			if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
   888 				if ( ! empty( $date_compl ) ) {
   933 
   889 					$custom_content .= '<p><span class="lable">' . $prtfl_options['date_text_field'] .' </span> ' . $date_compl . '</p>';
   934 			if ( $file == $this_plugin ) {
   890 				}
   935 				$settings_link = '<a href="admin.php?page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
   891 			}
   936 				array_unshift( $links, $settings_link );
   892 
   937 			}
   893 			if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $post_meta['_prtfl_link'] ) ) {
   938 		}
   894 
   939 		return $links;
   895 				if ( false !== parse_url( $post_meta['_prtfl_link'] ) ) {
   940 	}
   896 					if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) {
   941 }
   897 						$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> <a href="' . $post_meta['_prtfl_link'] . '">' . $post_meta['_prtfl_link'] . '</a></p>';
   942 
   898 					} else {
   943 
   899 						$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
   944 if ( ! function_exists( 'prtfl_template_redirect' ) ) {
   900 					}
   945 	function prtfl_template_redirect() {
   901 				} else {
   946 		global $wp_query, $post, $posts, $prtfl_filenames, $prtfl_themepath;
   902 					$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
   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"] ) ) {
   903 				}
   948 			$file_exists_flag = true;
   904 			}
   949 			foreach ( $prtfl_filenames as $filename ) {
   905 			if ( 0 != $user_id ) {
   950 				if ( ! file_exists( $prtfl_themepath . $filename ) )
   906 				if ( 1 == $prtfl_options['svn_additional_field'] && ! empty( $post_meta['_prtfl_svn'] ) ) {
   951 					$file_exists_flag = false;
   907 					$custom_content .= '<p><span class="lable">' . $prtfl_options['svn_text_field'] . '</span> ' . $post_meta['_prtfl_svn'] . '</p>';
   952 			}
   908 				}
   953 			if ( $file_exists_flag ) {
   909 
   954 				include( get_stylesheet_directory() . '/portfolio-post.php' );
   910 				if ( 1 == $prtfl_options['executor_additional_field'] ) {
   955 				exit();
   911 					$executors_profile = wp_get_object_terms( $post->ID, 'portfolio_executor_profile' );
   956 			}
   912 					if ( ! empty( $executors_profile ) ) {
   957 		} elseif ( 'portfolio' == get_post_type() && ( isset( $wp_query->query_vars["technologies"] ) || isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) ) {
   913 						$custom_content .= '<p><span class="lable">' . $prtfl_options['executor_text_field'] . '</span>';
   958 			$file_exists_flag = true;
   914 						$count = 0;
   959 			foreach ( $prtfl_filenames as $filename ) {
   915 						foreach ( $executors_profile as $profile ) {
   960 				if ( ! file_exists( $prtfl_themepath . $filename ) )
   916 							if ( $count > 0 ) {
   961 					$file_exists_flag = false;
   917 								$custom_content .= ', ';
   962 			}
   918 							}
   963 			if ( $file_exists_flag ) {
   919 							$custom_content .= '<a href="' . get_term_link( $profile->slug, 'portfolio_executor_profile' ) . '" title="' . $profile->name . ' profile" target="_blank">' . $profile->name . '</a>';
   964 				include( get_stylesheet_directory() . '/portfolio.php' );
   920 							$count++;
   965 				exit();
   921 						}
   966 			}
   922 						$custom_content .= '</p>';
   967 		}
   923 					}
   968 	}
   924 				}
   969 }
   925 			}
   970 
   926 
       
   927 		} elseif ( 'portfolio.php' == basename( get_page_template() ) ) {
       
   928 			global $wp_query, $request, $prtfl_options, $pdfprnt_options_array, $pdfprntpr_options;
       
   929 
       
   930 			if ( ! $prtfl_options ) {
       
   931 				$prtfl_options = get_option( 'prtfl_options' );
       
   932 			}
       
   933 
       
   934 			$count = 0;
       
   935 			if ( get_query_var( 'paged' ) ) {
       
   936 				$paged = get_query_var( 'paged' );
       
   937 			} elseif ( get_query_var( 'page' ) ) {
       
   938 				$paged = get_query_var( 'page' );
       
   939 			} else {
       
   940 				$paged = 1;
       
   941 			}
       
   942 			$per_page = $showitems = get_option( 'posts_per_page' );
       
   943 			$technologies = isset( $wp_query->query_vars["technologies"] ) ? $wp_query->query_vars["technologies"] : "";
       
   944 			$executor_profile = isset( $wp_query->query_vars["portfolio_executor_profile"] ) ? $wp_query->query_vars["portfolio_executor_profile"] : "";
       
   945 			if ( "" != $technologies ) {
       
   946 				$args = array(
       
   947 					'post_type' 		=> $prtfl_options['post_type_name'],
       
   948 					'post_status' 		=> 'publish',
       
   949 					'orderby' 			=> $prtfl_options['order_by'],
       
   950 					'order'			 	=> $prtfl_options['order'],
       
   951 					'posts_per_page'	=> $per_page,
       
   952 					'paged' 			=> $paged,
       
   953 					'tax_query' 		=> array(
       
   954 						array(
       
   955 							'taxonomy' 	=> 'portfolio_technologies',
       
   956 							'field' 	=> 'slug',
       
   957 							'terms' 	=> $technologies
       
   958 						)
       
   959 					)
       
   960 				);
       
   961 			} elseif ( "" != $executor_profile ) {
       
   962 				$args = array(
       
   963 					'post_type' 		=> $prtfl_options['post_type_name'],
       
   964 					'post_status' 		=> 'publish',
       
   965 					'orderby'			=> $prtfl_options['order_by'],
       
   966 					'order' 			=> $prtfl_options['order'],
       
   967 					'posts_per_page' 	=> $per_page,
       
   968 					'paged' 			=> $paged,
       
   969 					'tax_query' 		=> array(
       
   970 						array(
       
   971 							'taxonomy' 	=> 'portfolio_executor_profile',
       
   972 							'field' 	=> 'slug',
       
   973 							'terms' 	=> $executor_profile
       
   974 						)
       
   975 					)
       
   976 				);
       
   977 			} else {
       
   978 				$args = array(
       
   979 					'post_type'			=> $prtfl_options['post_type_name'],
       
   980 					'post_status'		=> 'publish',
       
   981 					'orderby'			=> $prtfl_options['order_by'],
       
   982 					'order'				=> $prtfl_options['order'],
       
   983 					'posts_per_page'	=> $per_page,
       
   984 					'paged'				=> $paged
       
   985 				);
       
   986 			}
       
   987 
       
   988 			$second_query = new WP_Query( $args );
       
   989 			$request = $second_query->request;
       
   990 
       
   991 			if ( $second_query->have_posts() ) {
       
   992 				while ( $second_query->have_posts() ) {
       
   993 					$second_query->the_post();
       
   994 					$custom_content .= '<div class="portfolio_content entry-content">
       
   995 						<div class="entry">';
       
   996 
       
   997 					$post_meta = get_post_meta( $post->ID, 'prtfl_information', true );
       
   998 					$user_id = get_current_user_id();
       
   999 
       
  1000 					$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
       
  1001 					if ( empty( $short_descr ) ) {
       
  1002 						$short_descr = get_the_excerpt();
       
  1003 					}
       
  1004 					$title = get_the_title();
       
  1005 					if ( empty( $title ) ) {
       
  1006 						$title = '(' . __( 'No title', 'portfolio' ) . ')';
       
  1007 					}
       
  1008 					$post_thumbnail_id	=	get_post_thumbnail_id( $post->ID );
       
  1009 					if ( empty( $post_thumbnail_id ) ) {
       
  1010 						$args = array(
       
  1011 							'post_parent'		=> $post->ID,
       
  1012 							'post_type'			=> 'attachment',
       
  1013 							'post_mime_type'	=> 'image',
       
  1014 							'numberposts'		=> 1
       
  1015 						);
       
  1016 						$attachments		= get_children( $args );
       
  1017 						$post_thumbnail_id	= key( $attachments );
       
  1018 					}
       
  1019 
       
  1020 					if ( ( isset( $pdfprnt_options_array['show_featured_image'] ) && 1 == $pdfprnt_options_array['show_featured_image'] )
       
  1021 						|| ( isset( $pdfprntpr_options['show_featured_image'] ) && 1 == $pdfprntpr_options['show_featured_image'] ) ) {
       
  1022 
       
  1023 						$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
       
  1024 
       
  1025 						if ( ! empty( $image[0] ) ) {
       
  1026 							/* get width and height for image_size_album */
       
  1027 							if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
       
  1028 								$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
       
  1029 								$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
       
  1030 							} else {
       
  1031 								$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
       
  1032 								$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
       
  1033 							}
       
  1034 							$image_alt 	= get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
       
  1035 
       
  1036 							$custom_content .= '<div class="portfolio_thumb"><img src="' . $image[0] . '" width="' . $width . '" height="' . $height . '" style="width:' . $width . 'px; height:' . $height . 'px;" alt="' . $image_alt . '" /></div>';
       
  1037 						}
       
  1038 					}
       
  1039 
       
  1040 					$custom_content .= '<div class="portfolio_short_content">
       
  1041 								<div class="item_title">
       
  1042 									<p><a href="' . get_permalink() . '" rel="bookmark">' . $title . '</a></p>
       
  1043 								</div>';
       
  1044 					if ( 1 == $prtfl_options['date_additional_field'] ) {
       
  1045 						$date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
       
  1046 						if ( ! empty( $date_compl ) ) {
       
  1047 							$custom_content .= '<p><span class="lable">' . $prtfl_options['date_text_field'] . '</span> ' . $date_compl . '</p>';
       
  1048 						}
       
  1049 					}
       
  1050 
       
  1051 					if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $post_meta['_prtfl_link'] ) ) {
       
  1052 						if ( false !== parse_url( $post_meta['_prtfl_link'] ) ) {
       
  1053 							if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) {
       
  1054 								$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> <a href="' . $post_meta['_prtfl_link'] . '">' . $post_meta['_prtfl_link'] . '</a></p>';
       
  1055 							} else {
       
  1056 								$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
       
  1057 							}
       
  1058 						} else {
       
  1059 							$custom_content .= '<p><span class="lable">' . $prtfl_options['link_text_field'] . '</span> ' . $post_meta['_prtfl_link'] . '</p>';
       
  1060 						}
       
  1061 					}
       
  1062 					if ( 1 == $prtfl_options['shrdescription_additional_field'] ) {
       
  1063 						$custom_content .= '<p><span class="lable">' . $prtfl_options['shrdescription_text_field'] . '</span> ' . $short_descr . '</p>';
       
  1064 					}
       
  1065 					$custom_content .= '</div>
       
  1066 						</div>
       
  1067 					</div>';
       
  1068 				}
       
  1069 			}
       
  1070 		}
       
  1071 		return $content . $custom_content;
       
  1072 	}
       
  1073 }
       
  1074 /* adding class to manu items  */
   971 if ( ! function_exists( 'prtfl_add_portfolio_ancestor_to_menu' ) ) {
  1075 if ( ! function_exists( 'prtfl_add_portfolio_ancestor_to_menu' ) ) {
   972 	function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) {
  1076 	function prtfl_add_portfolio_ancestor_to_menu( $classes, $item ) {
   973 		if ( is_singular( 'portfolio' ) ) {
  1077 		global $prtfl_options;
       
  1078 		if ( is_singular( $prtfl_options['post_type_name'] ) ) {
   974 			global $wpdb, $post;
  1079 			global $wpdb, $post;
   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" );
  1080 			$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" );
   976 
  1081 
   977 			if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) )
  1082 			if ( in_array( 'menu-item-' . $item->ID, $classes ) && $parent == strtolower( $item->title ) ) {
   978 				$classes[] = 'current-page-ancestor';
  1083 				$classes[] = 'current-page-ancestor';
       
  1084 			}
   979 		}
  1085 		}
   980 		return $classes;
  1086 		return $classes;
   981 	}
  1087 	}
   982 }
  1088 }
   983 
  1089 
       
  1090 /* forming content for portfolio items */
   984 if ( ! function_exists( 'prtfl_latest_items' ) ) {
  1091 if ( ! function_exists( 'prtfl_latest_items' ) ) {
   985 	function prtfl_latest_items( $atts ) {
  1092 	function prtfl_latest_items( $atts ) {
       
  1093 		global $prtfl_options, $wp_query;
       
  1094 		$old_wp_query = $wp_query;
       
  1095 
   986 		$content	=	'<div class="prtfl_portfolio_block">';
  1096 		$content	=	'<div class="prtfl_portfolio_block">';
   987 		if ( empty( $atts['count'] ) )
  1097 		if ( empty( $atts['count'] ) ) {
   988 			$atts['count'] = 3;
  1098 			$atts['count'] = 3;
       
  1099 		}
   989 		$args		=	array(
  1100 		$args		=	array(
   990 			'post_type'			=>	'portfolio',
  1101 			'post_type'			=> $prtfl_options['post_type_name'],
   991 			'post_status'		=>	'publish',
  1102 			'post_status'		=> 'publish',
   992 			'orderby'			=>	'date',
  1103 			'orderby'			=> 'date',
   993 			'order'				=>	'DESC',
  1104 			'order'				=> 'DESC',
   994 			'posts_per_page'	=>	$atts['count'],
  1105 			'posts_per_page'	=> $atts['count'],
   995 			);
  1106 			);
   996 		query_posts( $args );
  1107 			$second_query = new WP_Query( $args );
   997 
  1108 			$request = $second_query->request;
   998 		while ( have_posts() ) : the_post();
  1109 
       
  1110 			if ( $second_query->have_posts() ) {
       
  1111 				while ( $second_query->have_posts() ) {
       
  1112 					$second_query->the_post();
   999 			$content .= '
  1113 			$content .= '
  1000 			<div class="portfolio_content">
  1114 			<div class="portfolio_content">
  1001 				<div class="entry">';
  1115 				<div class="entry">';
  1002 					global $post;
  1116 					global $post;
  1003 					$meta_values		=	get_post_custom($post->ID);
  1117 					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  1004 					$post_thumbnail_id	=	get_post_thumbnail_id( $post->ID );
  1118 					if ( empty ( $post_thumbnail_id ) ) {
  1005 					if( empty ( $post_thumbnail_id ) ) {
       
  1006 						$args = array(
  1119 						$args = array(
  1007 							'post_parent'		=>	$post->ID,
  1120 							'post_parent'		=>	$post->ID,
  1008 							'post_type'			=>	'attachment',
  1121 							'post_type'			=>	'attachment',
  1009 							'post_mime_type'	=>	'image',
  1122 							'post_mime_type'	=>	'image',
  1010 							'numberposts'		=>	1
  1123 							'numberposts'		=>	1
  1011 						);
  1124 						);
  1012 						$attachments		=	get_children( $args );
  1125 						$attachments = get_children( $args );
  1013 						$post_thumbnail_id	=	key($attachments);
  1126 						$post_thumbnail_id = key( $attachments );
  1014 					}
  1127 					}
  1015 					$image		=	wp_get_attachment_image_src( $post_thumbnail_id, 'portfolio-thumb' );
  1128 					$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
       
  1129 
  1016 					$image_alt	=	get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
  1130 					$image_alt	=	get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true );
  1017 					$image_desc	=	get_post( $post_thumbnail_id );
  1131 					$image_desc	=	get_post( $post_thumbnail_id );
  1018 					$image_desc	=	$image_desc->post_content;
  1132 					$image_desc	=	$image_desc->post_content;
  1019 					$post_meta	=	get_post_meta( $post->ID, 'prtfl_information', true);
  1133 					$post_meta	=	get_post_meta( $post->ID, 'prtfl_information', true );
  1020 					$date_compl  =	isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
  1134 
  1021 					if ( ! empty( $date_compl ) && 'in progress' != $date_compl ) {
  1135 					$date_compl = isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
  1022 						$date_compl		=	explode( "/", $date_compl );
  1136 					$link = isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
  1023 						$date_compl		=	date( get_option( 'date_format' ), strtotime( $date_compl[1]."-".$date_compl[0].'-'.$date_compl[2] ) );
  1137 					$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
       
  1138 					if ( empty( $short_descr ) ) {
       
  1139 						$short_descr = get_the_excerpt();
  1024 					}
  1140 					}
  1025 					$link			=	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
       
  1026 					$short_descr	=	isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
       
  1027 					if ( empty( $short_descr ) )
       
  1028 						$short_descr = get_the_excerpt();
       
  1029 					$title = get_the_title();
  1141 					$title = get_the_title();
  1030 					if ( empty( $title ) )
  1142 					if ( empty( $title ) ) {
  1031 						$title = '(' . __( 'No title', 'portfolio-pro' ) . ')';
  1143 						$title = '(' . __( 'No title', 'portfolio' ) . ')';
       
  1144 					}
  1032 					$permalink = get_permalink();
  1145 					$permalink = get_permalink();
  1033 					
  1146 
  1034 					$content .= '<div class="portfolio_thumb" style="width:165px">
  1147 					$content .= '<div class="portfolio_thumb" style="width:165px">
  1035 							<img src="' . $image[0] . '" width="' . $image[1] . '" alt="' . $image_alt . '" />
  1148 							<img src="' . $image[0] . '" width="' . $image[1] . '" alt="' . $image_alt . '" />
  1036 					</div>
  1149 					</div>
  1037 					<div class="portfolio_short_content">
  1150 					<div class="portfolio_short_content">
  1038 						<div class="item_title">
  1151 						<div class="item_title">
  1039 							<p>
  1152 							<p>
  1040 								<a href="' . $permalink . '" rel="bookmark">' . $title . '</a>
  1153 								<a href="' . $permalink . '" rel="bookmark">' . $title . '</a>
  1041 							</p>
  1154 							</p>
  1042 						</div> <!-- .item_title -->';
  1155 						</div> <!-- .item_title -->';
  1043 						$content .= '<p>' . $short_descr . '</p>
  1156 						if ( 1 == $prtfl_options['shrdescription_additional_field'] && ( ! empty( $short_descr ) ) ) {
  1044 					</div> <!-- .portfolio_short_content -->
  1157 							$content .= '<p>' . $short_descr . '</p>';
       
  1158 						}
       
  1159 					$content .= '</div> <!-- .portfolio_short_content -->
  1045 				</div> <!-- .entry -->
  1160 				</div> <!-- .entry -->
  1046 				<div class="read_more">
  1161 				<div class="read_more">
  1047 					<a href="' . $permalink . '" rel="bookmark">' . __( 'Read more', 'portfolio' ) . '</a>
  1162 					<a href="' . $permalink . '" rel="bookmark">' . __( 'Read more', 'portfolio' ) . '</a>
  1048 				</div> <!-- .read_more -->
  1163 				</div> <!-- .read_more -->
  1049 				<div class="portfolio_terms">';
  1164 				<div class="portfolio_terms">';
  1050 				$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1165 				if ( 1 == $prtfl_options['technologies_additional_field'] ) {
  1051 				if ( is_array( $terms ) && 0 < count( $terms ) ) {
  1166 					$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1052 					$content .= __( 'Technologies', 'portfolio' ) . ':';
  1167 					if ( is_array( $terms ) && 0 < count( $terms ) ) {
  1053 					$count = 0;
  1168 						$content .= __( 'Technologies', 'portfolio' ) . ':';
  1054 					foreach ( $terms as $term ) {
  1169 						$count = 0;
  1055 						if ( $count > 0 )
  1170 						foreach ( $terms as $term ) {
  1056 							$content .= ', ';
  1171 							if ( $count > 0 ) {
  1057 						$content .= '<a href="' . get_term_link( $term->slug, 'portfolio_technologies') . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
  1172 								$content .= ', ';
  1058 						$count++;
  1173 							}
       
  1174 							$content .= '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
       
  1175 							$count++;
       
  1176 						}
       
  1177 					} else {
       
  1178 						$content .= '&nbsp;';
  1059 					}
  1179 					}
  1060 				} else {
       
  1061 					$content .= '&nbsp;';
       
  1062 				}
  1180 				}
  1063 				$content .= '</div><!-- .portfolio_terms -->';
  1181 				$content .= '</div><!-- .portfolio_terms -->';
  1064 			$content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content -->';
  1182 			$content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content -->';
  1065 		endwhile;
  1183 			}
       
  1184 		}
  1066 		$content .= '</div> <!-- .prtfl_portfolio_block -->';
  1185 		$content .= '</div> <!-- .prtfl_portfolio_block -->';
  1067 		wp_reset_query();
  1186 		wp_reset_query();
       
  1187 		$wp_query = $old_wp_query;
  1068 		return $content;
  1188 		return $content;
  1069 	}
  1189 	}
  1070 }
  1190 }
  1071 
  1191 
  1072 /* Register style and script files */
  1192 /* Register style and script files */
  1073 if ( ! function_exists ( 'prtfl_admin_head' ) ) {
  1193 if ( ! function_exists( 'prtfl_admin_head' ) ) {
  1074 	function prtfl_admin_head() {
  1194 	function prtfl_admin_head() {
  1075 		global $wp_version, $prtfl_plugin_info, $post_type;
  1195 		global $prtfl_plugin_info, $hook_suffix, $post_type, $prtfl_options;
  1076 		if ( $wp_version < 3.8 )
  1196 
  1077 			wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style_wp_before_3.8.css', __FILE__ ) );	
  1197 		wp_enqueue_style( 'prtfl_icon', plugins_url( 'css/icon.css', __FILE__ ) );
  1078 		else
  1198 
       
  1199 		if ( ( ( 'post.php' == $hook_suffix || 'post-new.php' == $hook_suffix ) && isset( $post_type ) && $prtfl_options['post_type_name'] == $post_type ) ||
       
  1200 			( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
  1079 			wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
  1201 			wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
  1080 		wp_enqueue_style( 'prtfl_datepicker_stylesheet', plugins_url( 'datepicker/datepicker.css', __FILE__ ) );
  1202 			wp_enqueue_style( 'prtfl_jquery-style', plugins_url( 'css/jquery-ui.css', __FILE__ ) );
  1081 
  1203 			wp_enqueue_script( 'jquery-ui-datepicker' );
  1082 		if ( isset( $_GET['page'] ) && "portfolio.php" == $_GET['page'] ) {
  1204 
  1083 			wp_enqueue_script( 'prtfl_script', plugins_url( 'js/script.js', __FILE__ ) );
  1205 			wp_enqueue_script( 'prtfl_script', plugins_url( 'js/script.js', __FILE__ ) );
  1084 			wp_localize_script( 'prtfl_script', 'prtfl_var', array(
  1206 			wp_localize_script( 'prtfl_script', 'prtfl_vars', array(
  1085 				'prtfl_nonce' 			=> wp_create_nonce( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' ),
  1207 				'prtfl_nonce' 			=> wp_create_nonce( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' ),
  1086 				'update_img_message'	=> __( 'Updating images...', 'portfolio' ),
  1208 				'update_img_message'	=> __( 'Updating images...', 'portfolio' ) . '<img class="prtfl_loader" src="' . plugins_url( 'images/ajax-loader.gif', __FILE__ ) . '" alt="" />',
  1087 				'not_found_img_info'	=> __( 'No image found', 'portfolio'),
  1209 				'not_found_img_info'	=> __( 'No image found.', 'portfolio' ),
  1088 				'img_success'			=> __( 'All images are updated', 'portfolio' ),
  1210 				'img_success'			=> __( 'All images are updated.', 'portfolio' ),
  1089 				'img_error'				=> __( 'Error.', 'portfolio' ) ) );
  1211 				'img_error'				=> __( 'Error:', 'portfolio' ) ) );
  1090 		}
  1212 
  1091 		wp_enqueue_script( 'prtfl_datepicker_script', plugins_url( 'datepicker/datepicker.js', __FILE__ ) );
  1213 			bws_enqueue_settings_scripts();
  1092 	}
  1214 			bws_plugins_include_codemirror();
  1093 }
  1215 		}
  1094 
  1216 	}
  1095 if ( ! function_exists ( 'prtfl_wp_head' ) ) {
  1217 }
       
  1218 
       
  1219 /* enqueue fancybox script and style css */
       
  1220 if ( ! function_exists( 'prtfl_wp_enqueue_scripts' ) ) {
       
  1221 	function prtfl_wp_enqueue_scripts() {
       
  1222 		wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
       
  1223 		wp_enqueue_style( 'prtfl_lightbox_stylesheet', plugins_url( 'fancybox/jquery.fancybox.min.css', __FILE__ ) );
       
  1224 	}
       
  1225 }
       
  1226 
       
  1227 /* styles for IE */
       
  1228 if ( ! function_exists( 'prtfl_wp_head' ) ) {
  1096 	function prtfl_wp_head() {
  1229 	function prtfl_wp_head() {
  1097 		wp_enqueue_style( 'prtfl_stylesheet', plugins_url( 'css/style.css', __FILE__ ) );
  1230 		global $prtfl_options;
  1098 		
  1231 		/* Add style for IE compatibility */
  1099 		if ( ! function_exists( 'is_plugin_active' ) )
  1232 		if ( isset( $_SERVER['HTTP_USER_AGENT'] ) && strpos( $_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0' ) !== false || strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) !== false ) {
  1100 			require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
  1233 			$post_type = get_post_type();
  1101 		
  1234 			if ( is_single() && $prtfl_options['post_type_name'] == $post_type ) { ?>
  1102 		$all_plugins = get_plugins();
  1235 				<style type="text/css">
  1103 		
  1236 					.portfolio_images_gallery {
  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"] ) ) { 
  1237 						display: block;
  1105 			wp_enqueue_style( 'prtfl_lightbox_stylesheet', plugins_url( 'fancybox/jquery.fancybox-1.3.4.css', __FILE__ ) );
  1238 					}
  1106 			wp_enqueue_script( 'prtfl_fancybox_mousewheelJs', plugins_url( 'fancybox/jquery.mousewheel-3.0.4.pack.js', __FILE__ ), array( 'jquery' ) );
  1239 					.portfolio_thumb {
  1107 			wp_enqueue_script( 'prtfl_fancyboxJs', plugins_url( 'fancybox/jquery.fancybox-1.3.4.pack.js', __FILE__ ), array( 'jquery' ) );
  1240 						float: none;
  1108 		}
  1241 					}
  1109 	}
  1242 				</style>
  1110 }
  1243 			<?php }
  1111 
  1244 		}
  1112 if ( ! function_exists ( 'prtfl_update_image' ) ) {
  1245 	}
       
  1246 }
       
  1247 
       
  1248 /* initializing script of fancybox */
       
  1249 if ( ! function_exists( 'prtfl_wp_footer' ) ) {
       
  1250 	function prtfl_wp_footer() {
       
  1251 		global $prtfl_options, $post, $wp_query;
       
  1252 		$post_thumbnail_id = '';
       
  1253 		if ( ! empty(  $wp_query->post->ID ) ) {
       
  1254 			$post_thumbnail_id = get_post_thumbnail_id( $wp_query->post->ID );
       
  1255 		}
       
  1256 		$image = wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
       
  1257 
       
  1258 		if ( wp_script_is( 'prtfl_front_script', 'registered' ) ) {
       
  1259 			wp_enqueue_script( 'prtfl_front_script' );
       
  1260 			wp_enqueue_script( 'prtfl_fancyboxJs', plugins_url( 'fancybox/jquery.fancybox.min.js', __FILE__ ), array( 'jquery' ) );
       
  1261 
       
  1262 			/* Initialization of fancybox script */
       
  1263 			if ( ! empty( $image[0] ) ) { ?>
       
  1264 				<script type="text/javascript">
       
  1265 					( function( $ ){
       
  1266 						$( document ).ready( function(){
       
  1267 							$( "a[data-fancybox=portfolio_fancybox]" ).fancybox({
       
  1268 								loop    : true,
       
  1269 								arrows  : false,
       
  1270 								infobar : true,
       
  1271 								speed : 500,
       
  1272 								toolbar: false,
       
  1273 								animationEffect : 'zoom',
       
  1274 								openEffect : 'elastic',
       
  1275 								closeEffect : 'elastic'
       
  1276 							} );
       
  1277 						} );
       
  1278 					} )( jQuery );
       
  1279 				</script>
       
  1280 			<?php }
       
  1281 		}
       
  1282 
       
  1283 	}
       
  1284 }
       
  1285 
       
  1286 /**
       
  1287  * Ajax function for updating images
       
  1288  * @return void
       
  1289  */
       
  1290 if ( ! function_exists( 'prtfl_update_image' ) ) {
  1113 	function prtfl_update_image() {
  1291 	function prtfl_update_image() {
  1114 		global $wpdb;
  1292 		global $wpdb, $prtfl_options;
  1115 		check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
  1293 		check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
  1116 		$action	=	isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
  1294 		$action	= isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
  1117 		$id		=	isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
  1295 		$id		= isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
  1118 		switch ( $action ) {
  1296 		switch ( $action ) {
  1119 			case 'get_all_attachment':
  1297 			case 'get_all_attachment':
  1120 				$result_parent_id	=	$wpdb->get_results( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = %s", 'portfolio' ) , ARRAY_N );
  1298 				$array_parent_id = $wpdb->get_col( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = {$prtfl_options['post_type_name']}" );
  1121 				$array_parent_id	=	array();
  1299 				if ( ! empty( $array_parent_id ) ) {
  1122 
  1300 					$string_parent_id = implode( ",", $array_parent_id );
  1123 				while ( list( $key, $val ) = each( $result_parent_id ) )
  1301 
  1124 					$array_parent_id[] = $val[0];
  1302 					$metas = $wpdb->get_results( "SELECT `meta_value` FROM $wpdb->postmeta WHERE `meta_key` = '_prtfl_images' AND `post_id` IN (" . $string_parent_id . ")", ARRAY_A );
  1125 
  1303 
  1126 				$string_parent_id = implode( ",", $array_parent_id );
  1304 					$result_attachment_id = '';
  1127 
  1305 					foreach ( $metas as $key => $value ) {
  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 . ")" );
  1306 						if ( ! empty( $value['meta_value'] ) ) {
  1129 				echo json_encode( $result_attachment_id );
  1307 							$result_attachment_id .= $value['meta_value'] . ',';
       
  1308 						}
       
  1309 					}
       
  1310 					$result_attachment_id_array = explode( ",", rtrim( $result_attachment_id, ',' ) );
       
  1311 
       
  1312 					$attached_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 . ")", ARRAY_A );
       
  1313 					foreach ( $attached_id as $key => $value ) {
       
  1314 						$result_attachment_id_array[] = $value['ID'];
       
  1315 					}
       
  1316 					echo json_encode( array_unique( $result_attachment_id_array ) );
       
  1317 				}
  1130 				break;
  1318 				break;
  1131 			case 'update_image':
  1319 			case 'update_image':
  1132 				$metadata	=	wp_get_attachment_metadata( $id );
  1320 				$metadata	= wp_get_attachment_metadata( $id );
  1133 				$uploads	=	wp_upload_dir();
  1321 				$uploads	= wp_upload_dir();
  1134 				$path		=	$uploads['basedir'] . "/" . $metadata['file'];
  1322 				$path		= $uploads['basedir'] . "/" . $metadata['file'];
  1135 				require_once( ABSPATH . 'wp-admin/includes/image.php' );
  1323 				require_once( ABSPATH . 'wp-admin/includes/image.php' );
  1136 				$metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata );
  1324 				$metadata_new = prtfl_wp_generate_attachment_metadata( $id, $path, $metadata );
  1137 				wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
  1325 				wp_update_attachment_metadata( $id, array_merge( $metadata, $metadata_new ) );
  1138 				break;
  1326 				break;
  1139 			case 'update_options':
  1327 			case 'update_options':
  1140 				add_option( 'prtfl_images_update', '1', '', 'no' );
  1328 				unset( $prtfl_options['need_image_update'] );
       
  1329 				update_option( 'prtfl_options', $prtfl_options );
  1141 				break;
  1330 				break;
  1142 		}
  1331 		}
  1143 		die();
  1332 		die();
  1144 	}
  1333 	}
  1145 }
  1334 }
  1146 
  1335 
  1147 if ( ! function_exists ( 'prtfl_wp_generate_attachment_metadata' ) ) {
  1336 if ( ! function_exists( 'prtfl_wp_generate_attachment_metadata' ) ) {
  1148 	function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
  1337 	function prtfl_wp_generate_attachment_metadata( $attachment_id, $file, $metadata ) {
  1149 		global $prtfl_options;
  1338 		global $prtfl_options;
  1150 		$attachment		=	get_post( $attachment_id );
  1339 		$attachment		=	get_post( $attachment_id );
  1151 		add_image_size( 'portfolio-thumb', $prtfl_options['prtfl_custom_size_px'][0][0], $prtfl_options['prtfl_custom_size_px'][0][1], true );
  1340 		$image_size 	= array( 'thumbnail' );
  1152 		add_image_size( 'portfolio-photo-thumb', $prtfl_options['prtfl_custom_size_px'][1][0], $prtfl_options['prtfl_custom_size_px'][1][1], true );
  1341 
       
  1342 		if ( 'portfolio-thumb' == $prtfl_options['image_size_album'] ) {
       
  1343 			add_image_size( 'portfolio-thumb', $prtfl_options['custom_size_px']['portfolio-thumb'][0], $prtfl_options['custom_size_px']['portfolio-thumb'][1], true );
       
  1344 			$image_size[] = 'portfolio-thumb';
       
  1345 		}
       
  1346 		if ( 'portfolio-photo-thumb' == $prtfl_options['image_size_photo'] ) {
       
  1347 			add_image_size( 'portfolio-photo-thumb', $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0], $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1], true );
       
  1348 			$image_size[] = 'portfolio-photo-thumb';
       
  1349 		}
  1153 
  1350 
  1154 		$metadata = array();
  1351 		$metadata = array();
  1155 		if ( preg_match('!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
  1352 		if ( preg_match( '!^image/!', get_post_mime_type( $attachment ) ) && file_is_displayable_image( $file ) ) {
  1156 			$imagesize					=	getimagesize( $file );
  1353 			$imagesize					= getimagesize( $file );
  1157 			$metadata['width']			=	$imagesize[0];
  1354 			$metadata['width']			= $imagesize[0];
  1158 			$metadata['height']			=	$imagesize[1];
  1355 			$metadata['height']			= $imagesize[1];
  1159 			list($uwidth, $uheight)		=	wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
  1356 			list( $uwidth, $uheight )	= wp_constrain_dimensions( $metadata['width'], $metadata['height'], 128, 96 );
  1160 			$metadata['hwstring_small']	=	"height='$uheight' width='$uwidth'";
  1357 			$metadata['hwstring_small']	= "height='$uheight' width='$uwidth'";
  1161 
  1358 
  1162 			/* Make the file path relative to the upload dir */
  1359 			/* Make the file path relative to the upload dir */
  1163 			$metadata['file']= _wp_relative_upload_path( $file );
  1360 			$metadata['file']= _wp_relative_upload_path( $file );
  1164 
  1361 
  1165 			/* Make thumbnails and other intermediate sizes */
  1362 			/* Make thumbnails and other intermediate sizes */
  1166 			global $_wp_additional_image_sizes;
  1363 			global $_wp_additional_image_sizes;
  1167 
  1364 
  1168 			$image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb' );/* get_intermediate_image_sizes(); */
       
  1169 
       
  1170 			foreach ( $image_size as $s ) {
  1365 			foreach ( $image_size as $s ) {
  1171 				$sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
  1366 				$sizes[ $s ] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
  1172 				if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) )
  1367 				if ( isset( $_wp_additional_image_sizes[ $s ]['width'] ) ) {
  1173 					$sizes[ $s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); /* For theme-added sizes */
  1368 					$sizes[ $s]['width'] = intval( $_wp_additional_image_sizes[ $s ]['width'] ); /* For theme-added sizes */
  1174 				else
  1369 				} else {
  1175 					$sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
  1370 					$sizes[ $s ]['width'] = get_option( "{$s}_size_w" ); /* For default sizes set in options */
  1176 				if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
  1371 				}
  1177 					$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); /* For theme-added sizes */
  1372 				if ( isset( $_wp_additional_image_sizes[ $s ]['height'] ) ) {
  1178 				else
  1373 					$sizes[ $s ]['height'] = intval( $_wp_additional_image_sizes[ $s ]['height'] ); /* For theme-added sizes */
       
  1374 				} else {
  1179 					$sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
  1375 					$sizes[ $s ]['height'] = get_option( "{$s}_size_h" ); /* For default sizes set in options */
  1180 				if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
  1376 				}
  1181 					$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); /* For theme-added sizes */
  1377 				if ( isset( $_wp_additional_image_sizes[ $s ]['crop'] ) ) {
  1182 				else
  1378 					$sizes[ $s ]['crop'] = intval( $_wp_additional_image_sizes[ $s ]['crop'] ); /* For theme-added sizes */
       
  1379 				} else {
  1183 					$sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
  1380 					$sizes[ $s ]['crop'] = get_option( "{$s}_crop" ); /* For default sizes set in options */
       
  1381 				}
  1184 			}
  1382 			}
  1185 
  1383 
  1186 			$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
  1384 			$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
  1187 			foreach ( $sizes as $size => $size_data ) {
  1385 			foreach ( $sizes as $size => $size_data ) {
  1188 				$resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
  1386 				$resized = prtfl_image_make_intermediate_size( $file, $size_data['width'], $size_data['height'], $size_data['crop'] );
  1189 				if ( $resized )
  1387 				if ( $resized ) {
  1190 					$metadata['sizes'][$size] = $resized;
  1388 					$metadata['sizes'][ $size ] = $resized;
       
  1389 				}
  1191 			}
  1390 			}
  1192 
  1391 
  1193 			/* Fetch additional metadata from exif/iptc */
  1392 			/* Fetch additional metadata from exif/iptc */
  1194 			$image_meta = wp_read_image_metadata( $file );
  1393 			$image_meta = wp_read_image_metadata( $file );
  1195 			if ( $image_meta )
  1394 			if ( $image_meta ) {
  1196 				$metadata['image_meta'] = $image_meta;
  1395 				$metadata['image_meta'] = $image_meta;
       
  1396 			}
  1197 		}
  1397 		}
  1198 		return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
  1398 		return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
  1199 	}
  1399 	}
  1200 }
  1400 }
  1201 
  1401 
  1202 if ( ! function_exists ( 'prtfl_image_make_intermediate_size' ) ) {
  1402 if ( ! function_exists( 'prtfl_image_make_intermediate_size' ) ) {
  1203 	function prtfl_image_make_intermediate_size( $file, $width, $height, $crop=false ) {
  1403 	function prtfl_image_make_intermediate_size( $file, $width, $height, $crop=false ) {
  1204 		if ( $width || $height ) {
  1404 		if ( $width || $height ) {
  1205 			$resized_file = prtfl_image_resize( $file, $width, $height, $crop );
  1405 			$resized_file = prtfl_image_resize( $file, $width, $height, $crop );
  1206 			if ( ! is_wp_error( $resized_file ) && $resized_file && $info = getimagesize( $resized_file ) ) {
  1406 			if ( ! is_wp_error( $resized_file ) && $resized_file && $info = getimagesize( $resized_file ) ) {
  1207 				$resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
  1407 				$resized_file = apply_filters( 'image_make_intermediate_size', $resized_file );
  1208 				return array(
  1408 				return array(
  1209 					'file'		=>	wp_basename( $resized_file ),
  1409 					'file'		=> wp_basename( $resized_file ),
  1210 					'width'		=>	$info[0],
  1410 					'width'		=> $info[0],
  1211 					'height'	=>	$info[1],
  1411 					'height'	=> $info[1],
  1212 				);
  1412 				);
  1213 			}
  1413 			}
  1214 		}
  1414 		}
  1215 		return false;
  1415 		return false;
  1216 	}
  1416 	}
  1217 }
  1417 }
  1218 
  1418 
  1219 if ( ! function_exists ( 'prtfl_image_resize' ) ) {
  1419 if ( ! function_exists( 'prtfl_image_resize' ) ) {
  1220 	function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
  1420 	function prtfl_image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
  1221 		$size = @getimagesize( $file );
  1421 		$size = @getimagesize( $file );
  1222 		if ( !$size )
  1422 		if ( ! $size ) {
  1223 			return new WP_Error( 'invalid_image', __( 'Image size not defined', 'portfolio' ), $file );
  1423 			return new WP_Error( 'invalid_image', __( 'Image size not defined', 'portfolio' ), $file );
       
  1424 		}
  1224 		$type = $size[2];
  1425 		$type = $size[2];
  1225 
  1426 
  1226 		if ( 3 == $type )
  1427 		if ( 3 == $type ) {
  1227 			$image = imagecreatefrompng( $file );
  1428 			$image = imagecreatefrompng( $file );
  1228 		else if ( 2 == $type )
  1429 		} elseif ( 2 == $type ) {
  1229 			$image = imagecreatefromjpeg( $file );
  1430 			$image = imagecreatefromjpeg( $file );
  1230 		else if ( 1 == $type )
  1431 		} elseif ( 1 == $type ) {
  1231 			$image = imagecreatefromgif( $file );
  1432 			$image = imagecreatefromgif( $file );
  1232 		else if ( 15 == $type )
  1433 		} elseif ( 15 == $type ) {
  1233 			$image = imagecreatefromwbmp( $file );
  1434 			$image = imagecreatefromwbmp( $file );
  1234 		else if ( 16 == $type )
  1435 		} elseif ( 16 == $type ) {
  1235 			$image = imagecreatefromxbm( $file );
  1436 			$image = imagecreatefromxbm( $file );
  1236 		else
  1437 		} 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 );
  1438 			return new WP_Error( 'invalid_image', __( 'We can update only PNG, JPEG, GIF, WPMP or XBM filetype. For other image formats, please manually reload image.', 'portfolio' ), $file );
  1238 
  1439 		}
  1239 		if ( ! is_resource( $image ) )
  1440 		if ( ! is_resource( $image ) ) {
  1240 			return new WP_Error( 'error_loading_image', $image, $file );
  1441 			return new WP_Error( 'error_loading_image', $image, $file );
  1241 
  1442 		}
  1242 		/* $size = @getimagesize( $file ); */
  1443 		/* $size = @getimagesize( $file ); */
  1243 		list( $orig_w, $orig_h, $orig_type ) = $size;
  1444 		list( $orig_w, $orig_h, $orig_type ) = $size;
  1244 		$dims = prtfl_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
  1445 		$dims = prtfl_image_resize_dimensions( $orig_w, $orig_h, $max_w, $max_h, $crop );
  1245 
  1446 
  1246 		if ( ! $dims )
  1447 		if ( ! $dims ) {
  1247 			return new WP_Error( 'error_getting_dimensions', __( 'Image size changes not defined', 'portfolio' ) );
  1448 			return new WP_Error( 'error_getting_dimensions', __( 'Image size changes not defined', 'portfolio' ) );
       
  1449 		}
  1248 		list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
  1450 		list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims;
  1249 		$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
  1451 		$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
  1250 		imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
  1452 		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. */
  1453 		/* Convert from full colors to index colors, like original PNG. */
  1252 		if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) )
  1454 		if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
  1253 			imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
  1455 			imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
       
  1456 		}
  1254 		/* We don't need the original in memory anymore */
  1457 		/* We don't need the original in memory anymore */
  1255 		imagedestroy( $image );
  1458 		imagedestroy( $image );
  1256 
  1459 
  1257 		/* $suffix will be appended to the destination filename, just before the extension */
  1460 		/* $suffix will be appended to the destination filename, just before the extension */
  1258 		if ( ! $suffix )
  1461 		if ( ! $suffix ) {
  1259 			$suffix = "{$dst_w}x{$dst_h}";
  1462 			$suffix = "{$dst_w}x{$dst_h}";
  1260 
  1463 		}
  1261 		$info	=	pathinfo( $file );
  1464 		$info = pathinfo( $file );
  1262 		$dir	=	$info['dirname'];
  1465 		$dir = $info['dirname'];
  1263 		$ext	=	$info['extension'];
  1466 		$ext = $info['extension'];
  1264 		$name	=	wp_basename( $file, ".$ext" );
  1467 		$name = wp_basename( $file, ".$ext" );
  1265 
  1468 
  1266 		if ( ! is_null( $dest_path ) and $_dest_path = realpath( $dest_path ) )
  1469 		if ( ! is_null( $dest_path ) and $_dest_path = realpath( $dest_path ) ) {
  1267 			$dir = $_dest_path;
  1470 			$dir = $_dest_path;
       
  1471 		}
  1268 		$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
  1472 		$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
  1269 
  1473 
  1270 		if ( IMAGETYPE_GIF == $orig_type ) {
  1474 		if ( IMAGETYPE_GIF == $orig_type ) {
  1271 			if ( ! imagegif( $newimage, $destfilename ) )
  1475 			if ( ! imagegif( $newimage, $destfilename ) ) {
  1272 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
  1476 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
       
  1477 			}
  1273 		} elseif ( IMAGETYPE_PNG == $orig_type ) {
  1478 		} elseif ( IMAGETYPE_PNG == $orig_type ) {
  1274 			if ( ! imagepng( $newimage, $destfilename ) )
  1479 			if ( ! imagepng( $newimage, $destfilename ) ) {
  1275 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
  1480 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
       
  1481 			}
  1276 		} else {
  1482 		} else {
  1277 			/* All other formats are converted to jpg */
  1483 			/* All other formats are converted to jpg */
  1278 			$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
  1484 			$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
  1279 			if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
  1485 			if ( ! imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) ) {
  1280 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
  1486 				return new WP_Error( 'resize_path_invalid', __( 'Invalid path', 'portfolio' ) );
       
  1487 			}
  1281 		}
  1488 		}
  1282 
  1489 
  1283 		imagedestroy( $newimage );
  1490 		imagedestroy( $newimage );
  1284 		/* Set correct file permissions */
  1491 		/* Set correct file permissions */
  1285 		$stat	=	stat( dirname( $destfilename ) );
  1492 		$stat	= stat( dirname( $destfilename ) );
  1286 		$perms	=	$stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
  1493 		$perms	= $stat['mode'] & 0000666; /* Same permissions as parent folder, strip off the executable bits */
  1287 		@chmod( $destfilename, $perms );
  1494 		@chmod( $destfilename, $perms );
  1288 		return $destfilename;
  1495 		return $destfilename;
  1289 	}
  1496 	}
  1290 }
  1497 }
  1291 
  1498 
  1292 if ( ! function_exists ( 'prtfl_image_resize_dimensions' ) ) {
  1499 if ( ! function_exists( 'prtfl_image_resize_dimensions' ) ) {
  1293 	function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
  1500 	function prtfl_image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
  1294 
  1501 
  1295 		if ( 0 >= $orig_w || 0 >= $orig_h )
  1502 		if ( 0 >= $orig_w || 0 >= $orig_h ) {
  1296 			return false;
  1503 			return false;
       
  1504 		}
  1297 		/* At least one of dest_w or dest_h must be specific */
  1505 		/* At least one of dest_w or dest_h must be specific */
  1298 		if ( 0 >= $dest_w && 0 >= $dest_h )
  1506 		if ( 0 >= $dest_w && 0 >= $dest_h ) {
  1299 			return false;
  1507 			return false;
       
  1508 		}
  1300 
  1509 
  1301 		if ( $crop ) {
  1510 		if ( $crop ) {
  1302 			/* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
  1511 			/* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h */
  1303 			$aspect_ratio	=	$orig_w / $orig_h;
  1512 			$aspect_ratio	=	$orig_w / $orig_h;
  1304 			$new_w			=	min( $dest_w, $orig_w );
  1513 			$new_w			=	min( $dest_w, $orig_w );
  1325 			$s_y	=	0;
  1534 			$s_y	=	0;
  1326 			list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
  1535 			list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
  1327 		}
  1536 		}
  1328 
  1537 
  1329 		/* If the resulting image would be the same size or larger we don't want to resize it */
  1538 		/* If the resulting image would be the same size or larger we don't want to resize it */
  1330 		if ( $new_w >= $orig_w && $new_h >= $orig_h )
  1539 		if ( $new_w >= $orig_w && $new_h >= $orig_h ) {
  1331 			return false;
  1540 			return false;
       
  1541 		}
  1332 		/* The return array matches the parameters to imagecopyresampled() */
  1542 		/* 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 */
  1543 		/* Int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h */
  1334 		return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
  1544 		return array( 0, 0, ( int ) $s_x, ( int ) $s_y, ( int ) $new_w, ( int ) $new_h, ( int ) $crop_w, ( int ) $crop_h );
  1335 	}
  1545 	}
  1336 }
  1546 }
  1337 
  1547 
  1338 
  1548 if ( ! function_exists( 'prtfl_theme_body_classes' ) ) {
  1339 if ( ! function_exists( 'prtfl_sanitize_file_name' ) ) {
  1549 	function prtfl_theme_body_classes( $classes ) {
  1340 	function prtfl_sanitize_file_name( $file_name ) {
       
  1341 		global $prtfl_options;
  1550 		global $prtfl_options;
  1342 		if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] )
       
  1343 			&& isset( $prtfl_options['prtfl_rename_file'] ) && $prtfl_options['prtfl_rename_file'] == 1 ) {	
       
  1344 			$file_name_old = explode( '.', $file_name );
       
  1345 			$file_name_new = preg_replace( '/--+/', '-', preg_replace( '/[^a-zA-Z0-9_-]/', '', $file_name_old[0] ) );
       
  1346 
       
  1347 			if ( $file_name_new == '' || $file_name_new == '-' ) {
       
  1348 				$slug = isset( $prtfl_options['prtfl_slug'] ) && ! empty( $prtfl_options['prtfl_slug'] ) ? $prtfl_options['prtfl_slug'] : 'portfolio';
       
  1349 				$file_name_new = $slug . '-' . time();
       
  1350 			}
       
  1351 			$file_name = $file_name_new . '.' . $file_name_old[1];
       
  1352 		}
       
  1353 		return $file_name;
       
  1354 	}
       
  1355 }
       
  1356 
       
  1357 if ( ! function_exists( 'prtfl_filter_image_sizes' ) ) {
       
  1358 	function prtfl_filter_image_sizes( $sizes ) {
       
  1359 		if ( isset( $_REQUEST['post_id'] ) && 'portfolio' == get_post_type( $_REQUEST['post_id'] ) ) {
       
  1360 			$prtfl_image_size = array( 'portfolio-thumb', 'portfolio-photo-thumb', 'large' );
       
  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' ) ) {
  1551 		if ( function_exists( 'wp_get_theme' ) ) {
  1374 			$current_theme = wp_get_theme();
  1552 			$current_theme = wp_get_theme();
  1375 			$classes[] = 'prtfl_' . basename( $current_theme->get( 'ThemeURI' ) );
  1553 			$classes[] = 'prtfl_' . basename( $current_theme->get( 'ThemeURI' ) );
  1376 		}
  1554 		}
       
  1555 		if ( in_array( 'page-id-' . $prtfl_options['page_id_portfolio_template'], $classes ) ) {
       
  1556 			$classes[]     = 'prtfl-page-template';
       
  1557 			$classes[]     = 'has-sidebar';
       
  1558 		}
  1377 		return $classes;
  1559 		return $classes;
  1378 	}
  1560 	}
  1379 }
  1561 }
  1380 
  1562 
  1381 if ( ! function_exists ( 'prtfl_admin_notices' ) ) {
  1563 if ( ! function_exists( 'prtfl_register_plugin_links' ) ) {
       
  1564 	function prtfl_register_plugin_links( $links, $file ) {
       
  1565 		global $prtfl_options;
       
  1566 		$base = plugin_basename( __FILE__ );
       
  1567 		if ( $file == $base ) {
       
  1568 			if ( ! is_network_admin() ) {
       
  1569 				$links[]	=	'<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
       
  1570 			}
       
  1571 			$links[]	=	'<a href="https://support.bestwebsoft.com/hc/en-us/sections/200538929" target="_blank">' . __( 'FAQ', 'portfolio' ) . '</a>';
       
  1572 			$links[]	=	'<a href="https://support.bestwebsoft.com">' . __( 'Support', 'portfolio' ) . '</a>';
       
  1573 		}
       
  1574 		return $links;
       
  1575 	}
       
  1576 }
       
  1577 
       
  1578 if ( ! function_exists( 'prtfl_plugin_action_links' ) ) {
       
  1579 	function prtfl_plugin_action_links( $links, $file ) {
       
  1580 		if ( ! is_network_admin() ) {
       
  1581 			/* Static so we don't call plugin_basename on every plugin row. */
       
  1582 			static $this_plugin;
       
  1583 			if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ );
       
  1584 
       
  1585 			if ( $file == $this_plugin ) {
       
  1586 				global $prtfl_options;
       
  1587 				$settings_link = '<a href="edit.php?post_type=' . $prtfl_options['post_type_name'] . '&page=portfolio.php">' . __( 'Settings', 'portfolio' ) . '</a>';
       
  1588 				array_unshift( $links, $settings_link );
       
  1589 			}
       
  1590 		}
       
  1591 		return $links;
       
  1592 	}
       
  1593 }
       
  1594 
       
  1595 if ( ! function_exists( 'prtfl_admin_notices' ) ) {
  1382 	function prtfl_admin_notices() {
  1596 	function prtfl_admin_notices() {
  1383 		global $hook_suffix, $prtfl_plugin_info, $prtfl_options;
  1597 		global $hook_suffix, $prtfl_plugin_info, $prtfl_options, $prtfl_BWS_demo_data;
  1384 		
  1598 
  1385 		if ( 'plugins.php' == $hook_suffix ) {
  1599 		if ( 'plugins.php' == $hook_suffix || ( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
  1386 			bws_plugin_banner( $prtfl_plugin_info, 'prtfl', 'portfolio', '56e6c97d1bca3199fb16cb817793a8f6', '74', '//ps.w.org/portfolio/assets/icon-128x128.png' );
       
  1387 
  1600 
  1388 			/* Get options from the database */
  1601 			/* Get options from the database */
  1389 			if ( ! $prtfl_options )
  1602 			if ( ! $prtfl_options ) {
  1390 				$prtfl_options = get_option( 'prtfl_options' );
  1603 				$prtfl_options = get_option( 'prtfl_options' );
  1391 
  1604 			}
  1392 			if ( $prtfl_options['widget_updated'] == 0 ) {
  1605 
  1393 				/* Save data for settings page */
  1606 			if ( ! $prtfl_BWS_demo_data ) {
  1394 				if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename(__FILE__), 'prtfl_nonce_name' ) ) {
  1607 				prtfl_include_demo_data();
  1395 					$prtfl_options['widget_updated'] = 1;
  1608 			}
  1396 					update_option( 'prtfl_options', $prtfl_options );
  1609 			$prtfl_BWS_demo_data->bws_handle_demo_notice( $prtfl_options['display_demo_notice'] );
  1397 				} else { ?>
  1610 
  1398 					<div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
  1611 			if ( 'plugins.php' == $hook_suffix ) {
  1399 						<div class="prtfl_admin_notices bws_banner_on_plugin_page">
  1612 				if ( isset( $prtfl_options['first_install'] ) && strtotime( '-1 week' ) > $prtfl_options['first_install'] ) {
  1400 							<form method="post" action="<?php echo $hook_suffix; ?>">
  1613 					bws_plugin_banner( $prtfl_plugin_info, 'prtfl', 'portfolio', '56e6c97d1bca3199fb16cb817793a8f6', '74', '//ps.w.org/portfolio/assets/icon-128x128.png' );
  1401 								<div class="text">
  1614 				}
  1402 									<p>
  1615 				if ( ! is_network_admin() ) {
  1403 										<strong><?php _e( "ATTENTION!", 'portfolio' ); ?></strong>
  1616 					bws_plugin_banner_to_settings( $prtfl_plugin_info, 'prtfl_options', 'portfolio', 'edit.php?post_type=portfolio&page=portfolio.php', 'Portfolio' );
  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' ); ?>
  1617 				}
  1405 									</p>
  1618 				if ( 0 == $prtfl_options['widget_updated'] ) {
  1406 									<input type="hidden" name="prtfl_form_submit" value="submit" />
  1619 					/* Save data for settings page */
  1407 									<p class="submit">
  1620 					if ( isset( $_REQUEST['prtfl_form_submit'] ) && check_admin_referer( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ) ) {
  1408 										<input type="submit" class="button-primary" value="<?php _e( 'Read and Understood' ); ?>" />
  1621 						$prtfl_options['widget_updated'] = 1;
  1409 									</p>
  1622 						update_option( 'prtfl_options', $prtfl_options );
  1410 									<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
  1623 					} else { ?>
  1411 								</div>
  1624 						<div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
  1412 							</form>
  1625 							<div class="prtfl_admin_notices bws_banner_on_plugin_page">
       
  1626 								<form method="post" action="<?php echo $hook_suffix; ?>">
       
  1627 									<div class="text">
       
  1628 										<p>
       
  1629 											<strong><?php _e( "ATTENTION!", 'portfolio' ); ?></strong>
       
  1630 											<?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' ); ?>
       
  1631 										</p>
       
  1632 										<input type="hidden" name="prtfl_form_submit" value="submit" />
       
  1633 										<p class="submit">
       
  1634 											<input type="submit" class="button-primary" value="<?php _e( 'Read and Understood', 'portfolio' ); ?>" />
       
  1635 										</p>
       
  1636 										<?php wp_nonce_field( plugin_basename( __FILE__ ), 'prtfl_nonce_name' ); ?>
       
  1637 									</div>
       
  1638 								</form>
       
  1639 							</div>
  1413 						</div>
  1640 						</div>
  1414 					</div>
  1641 					<?php }
  1415 				<?php }
  1642 				}
  1416 			}
  1643 			} else {
  1417 		}
  1644 				bws_plugin_suggest_feature_banner( $prtfl_plugin_info, 'prtfl_options', 'portfolio' );
  1418 	}
  1645 			}
  1419 }
  1646 		}
  1420 
  1647 	}
       
  1648 }
       
  1649 
       
  1650 /* This function will display title for portfolio type template */
       
  1651 if ( ! function_exists( 'prtfl_template_title' ) ) {
       
  1652 	function prtfl_template_title() {
       
  1653 		global $wp_query, $prtfl_options;
       
  1654 
       
  1655 		if ( isset( $wp_query->query_vars["technologies"] ) ) {
       
  1656 			$term = get_term_by( 'slug', $wp_query->query_vars["technologies"], 'portfolio_technologies' );
       
  1657 			echo $prtfl_options['technologies_text_field'] . " " . ( $term->name );
       
  1658 		} elseif ( isset( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
       
  1659 			$term = get_term_by( 'slug', $wp_query->query_vars["portfolio_executor_profile"], 'portfolio_executor_profile' );
       
  1660 			echo $prtfl_options['executor_text_field'] . " <h1>" . ( $term->name ) . "</h1>";
       
  1661 			$_SESSION['prtfl_page_name'] = $prtfl_options['executor_text_field'] . " " . ( $term->name );
       
  1662 			$_SESSION['prtfl_page_url'] = get_pagenum_link( $wp_query->query_vars['paged'] );
       
  1663 		} else {
       
  1664 			the_title( '<h2>', '</h2>' );
       
  1665 		}
       
  1666 	}
       
  1667 }
       
  1668 
       
  1669 /* This function will display title for portfolio post type template */
       
  1670 if ( ! function_exists( 'prtfl_post_template_title' ) ) {
       
  1671 	function prtfl_post_template_title() {
       
  1672 		$title = get_the_title();
       
  1673 		echo empty( $title ) ? '(' . __( 'No title', 'portfolio' ) . ')' : '<h2>'. $title . '</h2>' ;
       
  1674 	}
       
  1675 }
       
  1676 
       
  1677 /**
       
  1678  * Prepare arguments for post query
       
  1679  * @return array|false
       
  1680  */
       
  1681 if ( ! function_exists( 'prtfl_get_query_args' ) ) {
       
  1682 	function prtfl_get_query_args() {
       
  1683 		global $prtfl_options;
       
  1684 		$count = 0;
       
  1685 		if ( get_query_var( 'paged' ) ) {
       
  1686 			$paged = get_query_var( 'paged' );
       
  1687 		} elseif ( get_query_var( 'page' ) ) {
       
  1688 			$paged = get_query_var( 'page' );
       
  1689 		} else {
       
  1690 			$paged = 1;
       
  1691 		}
       
  1692 		$per_page = $showitems = get_option( 'posts_per_page' );
       
  1693 
       
  1694 		if ( ! empty( $wp_query->query_vars["technologies"] ) ) {
       
  1695 			$args = array(
       
  1696 				'post_type' 		=> $prtfl_options['post_type_name'],
       
  1697 				'post_status' 		=> 'publish',
       
  1698 				'orderby' 			=> $prtfl_options['order_by'],
       
  1699 				'order'			 	=> $prtfl_options['order'],
       
  1700 				'posts_per_page'	=> $per_page,
       
  1701 				'paged' 			=> $paged,
       
  1702 				'tax_query' 		=> array(
       
  1703 					array(
       
  1704 						'taxonomy' 	=> 'portfolio_technologies',
       
  1705 						'field' 	=> 'slug',
       
  1706 						'terms' 	=> $wp_query->query_vars["technologies"]
       
  1707 					)
       
  1708 				)
       
  1709 			);
       
  1710 		} elseif ( ! empty( $wp_query->query_vars["portfolio_executor_profile"] ) ) {
       
  1711 			$args = array(
       
  1712 				'post_type' 		=> $prtfl_options['post_type_name'],
       
  1713 				'post_status' 		=> 'publish',
       
  1714 				'orderby'			=> $prtfl_options['order_by'],
       
  1715 				'order' 			=> $prtfl_options['order'],
       
  1716 				'posts_per_page' 	=> $per_page,
       
  1717 				'paged' 			=> $paged,
       
  1718 				'tax_query' 		=> array(
       
  1719 					array(
       
  1720 						'taxonomy' 	=> 'portfolio_executor_profile',
       
  1721 						'field' 	=> 'slug',
       
  1722 						'terms' 	=> $wp_query->query_vars["portfolio_executor_profile"]
       
  1723 					)
       
  1724 				)
       
  1725 			);
       
  1726 		} else {
       
  1727 			$args = array(
       
  1728 				'post_type'			=> $prtfl_options['post_type_name'],
       
  1729 				'post_status'		=> 'publish',
       
  1730 				'orderby'			=> $prtfl_options['order_by'],
       
  1731 				'order'				=> $prtfl_options['order'],
       
  1732 				'posts_per_page'	=> $per_page,
       
  1733 				'paged'				=> $paged
       
  1734 			);
       
  1735 		}
       
  1736 
       
  1737 		if ( isset( $args ) ) {
       
  1738 			return $args;
       
  1739 		} else {
       
  1740 			return false;
       
  1741 		}
       
  1742 	}
       
  1743 }
       
  1744 
       
  1745 /**
       
  1746  * Display template content
       
  1747  * @return void
       
  1748  */
       
  1749 if ( ! function_exists( 'prtfl_get_content' ) ) {
       
  1750 	function prtfl_get_content( $second_query ) {
       
  1751 		global $post, $prtfl_options;
       
  1752 
       
  1753 		$request = $second_query->request;
       
  1754 
       
  1755 		if ( ! empty( $post ) && ! empty( $post->post_content ) ) {
       
  1756 			$page_content = $post->post_content;
       
  1757 			if ( function_exists( 'mltlngg_the_content_filter' ) ) $page_content = mltlngg_the_content_filter( $page_content );
       
  1758 			/* dublicate filter 'the_content' - as we couldnt use it */
       
  1759 			if ( function_exists( 'wptexturize' ) ) {
       
  1760 				$page_content = wptexturize( $page_content );
       
  1761 			}
       
  1762 			if ( function_exists( 'convert_smilies' ) ) {
       
  1763 				$page_content = convert_smilies( $page_content );
       
  1764 			}
       
  1765 			if ( function_exists( 'wpautop' ) ) {
       
  1766 				$page_content = wpautop( $page_content );
       
  1767 			}
       
  1768 			if ( function_exists( 'shortcode_unautop' ) ) {
       
  1769 				$page_content = shortcode_unautop( $page_content );
       
  1770 			}
       
  1771 			if ( function_exists( 'prepend_attachment' ) ) {
       
  1772 				$page_content = prepend_attachment( $page_content );
       
  1773 			}
       
  1774 			if ( function_exists( 'wp_make_content_images_responsive' ) ) {
       
  1775 				$page_content = wp_make_content_images_responsive( $page_content );
       
  1776 			}
       
  1777 			if ( function_exists( 'do_shortcode' ) ) {
       
  1778 				$page_content = do_shortcode( $page_content ); 
       
  1779 			} ?>
       
  1780 			<div class="portfolio_content entry-content">
       
  1781 				<div class="entry"><?php echo $page_content; ?></div>
       
  1782 			</div>
       
  1783 		<?php }
       
  1784 
       
  1785 
       
  1786 		if ( $second_query->have_posts() ) {
       
  1787 			while ( $second_query->have_posts() ) {
       
  1788 				$second_query->the_post(); ?>
       
  1789 				<div class="portfolio_content <?php if ( 'twentyfourteen' == get_stylesheet() || 'twentythirteen' == get_stylesheet() || 'twentytwelve' == get_stylesheet() ) echo 'entry-content'; ?>">
       
  1790 					<div class="entry">
       
  1791 						<?php $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
       
  1792 						$image			= wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
       
  1793 						$post_meta		= get_post_meta( $post->ID, 'prtfl_information', true );
       
  1794 
       
  1795 						$short_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
       
  1796 						if ( empty( $short_descr ) ) {
       
  1797 							$short_descr = get_the_excerpt();
       
  1798 						}
       
  1799 						$title = get_the_title();
       
  1800 						if ( empty( $title ) ) {
       
  1801 							$title = '(' . __( 'No title', 'portfolio' ) . ')';
       
  1802 						}
       
  1803 						$permalink = get_permalink();
       
  1804 						if ( ! empty( $image[0] ) ) {
       
  1805 							/* get width and height for image_size_album */
       
  1806 							if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
       
  1807 								$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
       
  1808 								$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
       
  1809 							} else {
       
  1810 								$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
       
  1811 								$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
       
  1812 							}
       
  1813 							$image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ); ?>
       
  1814 							<div class="portfolio_thumb">
       
  1815 								<a rel="bookmark" href="<?php echo $permalink; ?>" title="<?php echo $title; ?>">
       
  1816 									<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> style="<?php if ( $width ) echo 'width:' . $width . 'px;'; if ( $height ) echo 'height:' . $height . 'px;'; ?>" />
       
  1817 								</a>
       
  1818 							</div><!-- .portfolio_thumb -->
       
  1819 						<?php } ?>
       
  1820 						<div class="portfolio_short_content">
       
  1821 							<div class="item_title">
       
  1822 								<p>
       
  1823 									<a href="<?php echo $permalink; ?>" rel="bookmark"><?php echo $title; ?></a>
       
  1824 								</p>
       
  1825 							</div><!-- .item_title -->
       
  1826 							<?php $date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
       
  1827 							if ( 1 == $prtfl_options['date_additional_field'] && ! empty( $date_compl ) ) { ?>
       
  1828 								<p>
       
  1829 									<span class="lable"><?php echo '<b>' . $prtfl_options['date_text_field'] . '</b>'; ?></span> <?php echo $date_compl; ?>
       
  1830 								</p>
       
  1831 							<?php }
       
  1832 							$user_id = get_current_user_id();
       
  1833 
       
  1834 							$link =	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
       
  1835 							if ( 1 == $prtfl_options['link_additional_field'] && ! empty( $link ) ) {
       
  1836 
       
  1837 								if ( false !== parse_url( $link ) ) {
       
  1838 									if ( ( 0 == $user_id && 0 == $prtfl_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) { ?>
       
  1839 										<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <a href="<?php echo $link; ?>"><?php echo $link; ?></a></p>
       
  1840 									<?php } else { ?>
       
  1841 										<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
       
  1842 									<?php }
       
  1843 								} else { ?>prtfl_options
       
  1844 									<p><span class="lable"><?php echo '<b>' . $prtfl_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
       
  1845 								<?php }
       
  1846 							}
       
  1847 							if ( 1 == $prtfl_options['shrdescription_additional_field'] ) { ?>
       
  1848 								<p><span class="lable"><?php echo '<b>' . $prtfl_options['shrdescription_text_field'] . '</b>'; ?></span> <?php echo $short_descr; ?></p>
       
  1849 							<?php } ?>
       
  1850 						</div><!-- .portfolio_short_content -->
       
  1851 					</div><!-- .entry -->
       
  1852 					<div class="entry_footer">
       
  1853 						<div class="read_more">
       
  1854 							<a href="<?php the_permalink(); ?>" rel="bookmark"><?php _e( 'Read more', 'portfolio' ); ?></a>
       
  1855 						</div><!-- .read_more -->
       
  1856 						<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
       
  1857 						if ( 1 == $prtfl_options['technologies_additional_field'] && ! is_wp_error( $terms ) ) {
       
  1858 							if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
       
  1859 								<div class="portfolio_terms">
       
  1860 									<?php if ( isset( $prtfl_options['technologies_text_field'] ) ) echo '<b>' . $prtfl_options['technologies_text_field'] . '&nbsp;</b>';
       
  1861 									$links = array();
       
  1862 									foreach ( $terms as $term ) {
       
  1863 										$links[] = '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
       
  1864 									}
       
  1865 									echo implode( ', ', $links ); ?>
       
  1866 								</div><!-- .portfolio_terms -->
       
  1867 							<?php }
       
  1868 						} ?>
       
  1869 					</div><!-- .entry_footer -->
       
  1870 				</div><!-- .portfolio_content -->
       
  1871 					<?php }
       
  1872 		}
       
  1873 	}
       
  1874 }
       
  1875 
       
  1876 /**
       
  1877  * Display post template content
       
  1878  * @return void
       
  1879  */
       
  1880 if ( ! function_exists( 'prtfl_post_get_content' ) ) {
       
  1881 	function prtfl_post_get_content() {
       
  1882 		global $post, $prtfl_options;
       
  1883 
       
  1884 		while ( have_posts() ) : the_post(); ?>
       
  1885 			<article class="portfolio_content entry-content">
       
  1886 				<div class="entry">
       
  1887 					<?php global $post;
       
  1888 					$portfolio_options = get_option( 'prtfl_options' );
       
  1889 					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
       
  1890 					$image			= wp_get_attachment_image_src( $post_thumbnail_id, $prtfl_options['image_size_album'] );
       
  1891 					$post_meta		= get_post_meta( $post->ID, 'prtfl_information', true );
       
  1892 
       
  1893 					if ( ! empty( $image[0] ) ) {
       
  1894 						$image_large = wp_get_attachment_image_src( $post_thumbnail_id, 'large' );
       
  1895 						$image_desc = get_post( $post_thumbnail_id );
       
  1896 						$image_desc = $image_desc->post_content;
       
  1897 						/* get width and height for image_size_album */
       
  1898 						if ( 'portfolio-thumb' != $prtfl_options['image_size_album'] ) {
       
  1899 							$width  = absint( get_option( $prtfl_options['image_size_album'] . '_size_w' ) );
       
  1900 							$height = absint( get_option( $prtfl_options['image_size_album'] . '_size_h' ) );
       
  1901 						} else {
       
  1902 							$width  = $prtfl_options['custom_size_px']['portfolio-thumb'][0];
       
  1903 							$height = $prtfl_options['custom_size_px']['portfolio-thumb'][1];
       
  1904 						}
       
  1905 						$image_alt = get_post_meta( $post_thumbnail_id, '_wp_attachment_image_alt', true ); ?>
       
  1906 						<div class="portfolio_thumb">
       
  1907 							<a class="lightbox" data-fancybox="portfolio_fancybox" href="<?php echo $image_large[0]; ?>" title="<?php echo $image_desc; ?>">
       
  1908 								<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> />
       
  1909 							</a>
       
  1910 						</div><!-- .portfolio_thumb -->
       
  1911 					<?php } ?>
       
  1912 					<div class="portfolio_short_content">
       
  1913 						<?php $date_compl	= isset( $post_meta['_prtfl_date_compl'] ) ? $post_meta['_prtfl_date_compl'] : '';
       
  1914 						if ( 1 == $portfolio_options['date_additional_field'] && ! empty( $date_compl ) ) { ?>
       
  1915 							<p>
       
  1916 								<span class="lable"><?php echo '<b>' . $portfolio_options['date_text_field'] . '</b>'; ?></span> <?php echo $date_compl; ?>
       
  1917 							</p>
       
  1918 						<?php }
       
  1919 						$user_id = get_current_user_id();
       
  1920 
       
  1921 						$link =	isset( $post_meta['_prtfl_link'] ) ? $post_meta['_prtfl_link'] : '';
       
  1922 						if ( 1 == $portfolio_options['link_additional_field'] && ! empty( $link ) ) {
       
  1923 
       
  1924 							if ( false !== parse_url( $link ) ) { ?>
       
  1925 								<?php if ( ( 0 == $user_id && 0 == $portfolio_options['link_additional_field_for_non_registered'] ) || 0 != $user_id ) { ?>
       
  1926 									<p><span class="lable"><?php echo '<b>'.  $portfolio_options['link_text_field'] . '</b>'; ?></span> <a href="<?php echo $link; ?>"><?php echo $link; ?></a></p>
       
  1927 								<?php } else { ?>
       
  1928 									<p><span class="lable"><?php echo '<b>' . $portfolio_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
       
  1929 								<?php }
       
  1930 							} else { ?>
       
  1931 								<p><span class="lable"><?php echo '<b>' . $portfolio_options['link_text_field'] . '</b>'; ?></span> <?php echo $link; ?></p>
       
  1932 							<?php }
       
  1933 						}
       
  1934 						if ( 1 == $portfolio_options['description_additional_field'] ) {
       
  1935 							$full_descr = $post->post_content != "" ? $post->post_content : '';
       
  1936 							if ( empty( $full_descr ) ){
       
  1937 								$full_descr = isset( $post_meta['_prtfl_short_descr'] ) ? $post_meta['_prtfl_short_descr'] : '';
       
  1938 							} else {
       
  1939 								if ( function_exists( 'mltlngg_the_content_filter' ) ) {
       
  1940 									$full_descr = mltlngg_the_content_filter( $full_descr );
       
  1941 								}
       
  1942 								/* dublicate filter 'the_content' - as we couldnt use it */
       
  1943 								if ( function_exists( 'wptexturize' ) ) {
       
  1944 									$full_descr = wptexturize( $full_descr );
       
  1945 								}
       
  1946 								if ( function_exists( 'convert_smilies' ) ) {
       
  1947 									$full_descr = convert_smilies( $full_descr );
       
  1948 								}
       
  1949 								if ( function_exists( 'wpautop' ) ) {
       
  1950 									$full_descr = wpautop( $full_descr );
       
  1951 								}
       
  1952 								if ( function_exists( 'shortcode_unautop' ) ) {
       
  1953 									$full_descr = shortcode_unautop( $full_descr );
       
  1954 								}
       
  1955 								if ( function_exists( 'prepend_attachment' ) ) {
       
  1956 									$full_descr = prepend_attachment( $full_descr );
       
  1957 								}
       
  1958 								if ( function_exists( 'wp_make_content_images_responsive' ) ) {
       
  1959 									$full_descr = wp_make_content_images_responsive( $full_descr );
       
  1960 								}
       
  1961 								if ( function_exists( 'do_shortcode' ) ) {
       
  1962 									$full_descr = do_shortcode( $full_descr );
       
  1963 								}
       
  1964 							}
       
  1965 							if ( ! empty( $full_descr ) ) { ?>
       
  1966 								<div style = "clear: both;"><span class="lable"><?php echo '<b>' . $prtfl_options['description_text_field'] . '</b>'; ?></span> <?php echo $full_descr; ?></div>
       
  1967 							<?php }
       
  1968 						}
       
  1969 
       
  1970 						if ( 0 != $user_id && $portfolio_options ) {
       
  1971 							$svn = isset( $post_meta['_prtfl_svn'] ) ? $post_meta['_prtfl_svn'] : '';
       
  1972 							if ( 1 == $portfolio_options['svn_additional_field'] && ! empty( $svn ) ) { ?>
       
  1973 								<p><span class="lable"><?php echo '<b>' . $portfolio_options['svn_text_field'] . '</b>'; ?></span> <?php echo $svn; ?></p>
       
  1974 							<?php }
       
  1975 							$executors_profile = wp_get_object_terms( $post->ID, 'portfolio_executor_profile' );
       
  1976 							if ( 1 == $portfolio_options['executor_additional_field'] && ! empty( $executors_profile ) ) { ?>
       
  1977 								<p><span class="lable"><?php echo '<b>' . $portfolio_options['executor_text_field'] . '</b>'; ?></span>
       
  1978 								<?php $count = 0;
       
  1979 								foreach ( $executors_profile as $profile ) {
       
  1980 									if ( $count > 0 ) {
       
  1981 										echo ', ';
       
  1982 									} ?>
       
  1983 									<a href="<?php echo get_term_link( $profile->slug, 'portfolio_executor_profile' ); ?>" title="<?php echo $profile->name; ?> profile" target="_blank"><?php echo $profile->name; ?></a>
       
  1984 									<?php $count++;
       
  1985 								} ?>
       
  1986 								</p>
       
  1987 							<?php }
       
  1988 						 } ?>
       
  1989 					</div><!-- .portfolio_short_content -->
       
  1990 					<div class="portfolio_images_block" data-columns="<?php echo $portfolio_options['custom_image_row_count'] ?>">
       
  1991 						<?php if ( metadata_exists( 'post', $post->ID, '_prtfl_images' ) ) {
       
  1992 							$array_post_thumbnail_id = array_filter( explode( ',', get_post_meta( $post->ID, '_prtfl_images', true ) ) );
       
  1993 						} else {
       
  1994 							/* Compatibility with old plugin version 2.37 */
       
  1995 							$args = array(
       
  1996 								'post_parent'		=> $post->ID,
       
  1997 								'post_type'			=> 'attachment',
       
  1998 								'post_mime_type'	=> 'image',
       
  1999 								'numberposts'		=> -1,
       
  2000 								'orderby'			=> 'menu_order',
       
  2001 								'order'				=> 'ASC',
       
  2002 								'exclude'			=> $post_thumbnail_id,
       
  2003 								'fields'			=> 'ids'
       
  2004 							);
       
  2005 							$array_post_thumbnail_id = get_children( $args );
       
  2006 						}
       
  2007 						$count_element = count( $array_post_thumbnail_id );
       
  2008 
       
  2009 						foreach ( $array_post_thumbnail_id as $key => $value ) {
       
  2010 							$image			=	wp_get_attachment_image_src( $value, $prtfl_options['image_size_photo'] );
       
  2011 							$image_large	=	wp_get_attachment_image_src( $value, 'large' );
       
  2012 							$image_alt		=	get_post_meta( $value, '_wp_attachment_image_alt', true );
       
  2013 							$image_title	=	get_post_meta( $value, '_wp_attachment_image_title', true );
       
  2014 							$image_desc 	=	get_post( $value );
       
  2015 							$image_desc		=	$image_desc->post_content;
       
  2016 
       
  2017 							/* get width and height for image_size_photo */
       
  2018 							if ( 'portfolio-photo-thumb' != $prtfl_options['image_size_photo'] ) {
       
  2019 								$width  = absint( get_option( $prtfl_options['image_size_photo'] . '_size_w' ) );
       
  2020 								$height = absint( get_option( $prtfl_options['image_size_photo'] . '_size_h' ) );
       
  2021 							} else {
       
  2022 								$width  = $prtfl_options['custom_size_px']['portfolio-photo-thumb'][0];
       
  2023 								$height = $prtfl_options['custom_size_px']['portfolio-photo-thumb'][1];
       
  2024 							}
       
  2025 
       
  2026 							if ( 0 == $key ) { ?>
       
  2027 								<span class="lable"><?php echo '<b>' . $portfolio_options['screenshot_text_field'] . '</b>'; ?></span>
       
  2028 								<div class="portfolio_images_rows">
       
  2029 							<?php } ?>
       
  2030 							<div class="portfolio_images_gallery">
       
  2031 								<a class="lightbox" data-fancybox="portfolio_fancybox" href="<?php echo $image_large[0]; ?>" title="<?php echo $image_desc; ?>">
       
  2032 									<img src="<?php echo $image[0]; ?>" alt="<?php echo $image_alt; ?>" <?php if ( $width ) echo 'width="' . $width . '"'; if ( $height ) echo 'height="' . $height . '"'; ?> style="<?php if ( $width ) echo 'width:' . $width . 'px;'; if ( $height ) echo 'height:' . $height . 'px;'; ?>" />
       
  2033 								</a>
       
  2034 								<br /><?php echo $image_title;?>
       
  2035 							</div>
       
  2036 							<?php if ( 0 == ( $key + 1 ) % $portfolio_options['custom_image_row_count'] && 0 != $key && $key + 1 != $count_element ) { ?>
       
  2037 								</div><!-- .portfolio_images_rows -->
       
  2038 								<div class="portfolio_images_rows">
       
  2039 							<?php }
       
  2040 						}
       
  2041 						if ( 0 < $count_element ) { ?>
       
  2042 							</div><!-- .portfolio_images_rows -->
       
  2043 						<?php } ?>
       
  2044 					</div><!-- .portfolio_images_block -->
       
  2045 				</div><!-- .entry -->
       
  2046 				<div class="entry_footer entry-footer">
       
  2047 					<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
       
  2048 					if ( 1 == $portfolio_options['technologies_additional_field'] && ! ( empty( $terms ) || is_wp_error( $terms ) ) ) {
       
  2049 						if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
       
  2050 							<div class="portfolio_terms">
       
  2051 								<?php if ( isset( $portfolio_options['technologies_text_field'] ) ) echo '<b>'. $portfolio_options['technologies_text_field'] . '&nbsp;</b>';
       
  2052 								$links = array();
       
  2053 								foreach ( $terms as $term ) {
       
  2054 									$links[] = '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
       
  2055 								}
       
  2056 								echo implode( ', ', $links ); ?>
       
  2057 							</div><!-- .portfolio_terms -->
       
  2058 						<?php }
       
  2059 					} ?>
       
  2060 				</div><!-- .entry_footer .entry-footer -->
       
  2061 			</article><!-- .portfolio_content -->
       
  2062 		<?php endwhile;
       
  2063 	}
       
  2064 }
       
  2065 
       
  2066 /* This function prints pagination for portfolio post type template */
       
  2067 if ( ! function_exists( 'prtfl_pro_pagination' ) ) {
       
  2068 	function prtfl_pro_pagination( $second_query, &$args ) {
       
  2069 		global $wp_query, $prtfl_options;
       
  2070 		$count_all_albums = $second_query->found_posts;
       
  2071 
       
  2072 		$request 	= $wp_query->request;
       
  2073 		$paged 		= $showitems = $args['paged'];
       
  2074 		$per_page 	= $args['posts_per_page'];
       
  2075 		$pages 		= intval( $count_all_albums / $per_page );
       
  2076 
       
  2077 		if ( $count_all_albums % $per_page > 0 ) {
       
  2078 			$pages += 1;
       
  2079 		}
       
  2080 		$range = 2;
       
  2081 
       
  2082 		if ( ! $pages ) {
       
  2083 			$pages = 1;
       
  2084 		}
       
  2085 		if ( 1 != $pages ) { ?>
       
  2086 			<div class='clear'></div>
       
  2087 			<div id="portfolio_pagenation">
       
  2088 				<div class='pagination'>
       
  2089 					<?php if ( 2 < $paged && $paged > $range + 1 && $showitems < $pages ) {
       
  2090 						echo "<a href='" . get_pagenum_link( 1 ) . "'>&laquo;</a>";
       
  2091 					}
       
  2092 					if ( 1 < $paged && $showitems < $pages ) {
       
  2093 						echo "<a href='" . get_pagenum_link( $paged - 1 ) . "'>&lsaquo;</a>";
       
  2094 					}
       
  2095 					for ( $i = 1; $i <= $pages; $i++ ) {
       
  2096 						if ( 1 != $pages && ( ! ( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
       
  2097 							echo ( $paged == $i ) ? "<span class='current'>" . $i . "</span>":"<a href='" . get_pagenum_link( $i ) . "' class='inactive' >" . $i . "</a>";
       
  2098 						}
       
  2099 					}
       
  2100 					if ( $paged < $pages && $showitems < $pages ) {
       
  2101 						echo "<a href='" . get_pagenum_link( $paged + 1 ) . "'>&rsaquo;</a>";
       
  2102 					}
       
  2103 					if ( $paged < $pages - 1 && $paged + $range - 1 < $pages && $showitems < $pages ) {
       
  2104 						echo "<a href='" . get_pagenum_link( $pages ) . "'>&raquo;</a>";
       
  2105 					} ?>
       
  2106 					<div class='clear'></div>
       
  2107 				</div><!-- .pagination -->
       
  2108 				<?php if ( function_exists( 'pgntn_display_pagination' ) ) pgntn_display_pagination( 'custom', $second_query ); ?>
       
  2109 			</div><!-- #portfolio_pagenation -->
       
  2110 		<?php }
       
  2111 	}
       
  2112 }
       
  2113 
       
  2114 /* add shortcode content  */
       
  2115 if ( ! function_exists( 'prtfl_shortcode_button_content' ) ) {
       
  2116 	function prtfl_shortcode_button_content( $content ) { ?>
       
  2117 		<div id="prtfl" style="display:none;">
       
  2118 			<fieldset>
       
  2119 				<label>
       
  2120 					<input type="number" value="3" min="0" max="1000" name="prtfl_display_count" id="prtfl_display_count" class="small-text" />
       
  2121 					<span>
       
  2122 						<?php _e( 'The number of portfolio projects to display', 'portfolio' ); ?>
       
  2123 					</span>
       
  2124 				</label>
       
  2125 			</fieldset>
       
  2126 			<input class="bws_default_shortcode" type="hidden" name="default" value="[latest_portfolio_items count=3]" />
       
  2127 			<script type="text/javascript">
       
  2128 				function prtfl_shortcode_init() {
       
  2129 					( function( $ ) {
       
  2130 						$( '.mce-reset #prtfl_display_count' ).on( 'change', function() {
       
  2131 							var count = $( '.mce-reset #prtfl_display_count' ).val();
       
  2132 							var shortcode = '[latest_portfolio_items count=' + count + ']';
       
  2133 							$( '.mce-reset #bws_shortcode_display' ).text( shortcode );
       
  2134 						} );
       
  2135 					} )( jQuery );
       
  2136 				}
       
  2137 			</script>
       
  2138 			<div class="clear"></div>
       
  2139 		</div>
       
  2140 	<?php }
       
  2141 }
       
  2142 
       
  2143 /* add help tab  */
       
  2144 if ( ! function_exists( 'prtfl_add_tabs' ) ) {
       
  2145 	function prtfl_add_tabs() {
       
  2146 		global $prtfl_options;
       
  2147 		$screen = get_current_screen();
       
  2148 		if ( ( ! empty( $screen->post_type ) && $prtfl_options['post_type_name'] == $screen->post_type ) ||
       
  2149 			( ! empty( $screen->taxonomy ) && 'portfolio_executor_profile' == $screen->taxonomy ) ||
       
  2150 			( ! empty( $screen->taxonomy ) && 'portfolio_technologies' == $screen->taxonomy ) ||
       
  2151 			( isset( $_GET['page'] ) && 'portfolio.php' == $_GET['page'] ) ) {
       
  2152 			$args = array(
       
  2153 				'id' 			=> 'prtfl',
       
  2154 				'section' 		=> '200538929'
       
  2155 			);
       
  2156 			bws_help_tab( $screen, $args );
       
  2157 		}
       
  2158 	}
       
  2159 }
       
  2160 
       
  2161 if ( ! function_exists( 'prtfl_plugin_deactivation' ) ) {
       
  2162 	function prtfl_plugin_deactivation() {
       
  2163 		global $wpdb, $prtfl_BWS_demo_data;
       
  2164 
       
  2165 		if ( function_exists( 'is_multisite' ) && is_multisite() ) {
       
  2166 			$old_blog = $wpdb->blogid;
       
  2167 			/* Get all blog ids */
       
  2168 			$blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
       
  2169 			foreach ( $blogids as $blog_id ) {
       
  2170 				switch_to_blog( $blog_id );
       
  2171 				prtfl_include_demo_data();
       
  2172 				$prtfl_BWS_demo_data->bws_remove_demo_data();
       
  2173 			}
       
  2174 			switch_to_blog( $old_blog );
       
  2175 		} else {
       
  2176 			global $prtfl_BWS_demo_data;
       
  2177 
       
  2178 			if ( ! $prtfl_BWS_demo_data ) {
       
  2179 				prtfl_include_demo_data();
       
  2180 			}
       
  2181 			$prtfl_BWS_demo_data->bws_remove_demo_data();
       
  2182 		}
       
  2183 	}
       
  2184 }
  1421 
  2185 
  1422 if ( ! function_exists( 'prtfl_plugin_uninstall' ) ) {
  2186 if ( ! function_exists( 'prtfl_plugin_uninstall' ) ) {
  1423 	function prtfl_plugin_uninstall() {
  2187 	function prtfl_plugin_uninstall() {
       
  2188 		global $wpdb;
  1424 		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  2189 		require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  1425 
  2190 
  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();
  2191 		$plugins_list = get_plugins();
  1434 		if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) 
  2192 
  1435 			delete_option( 'widget-portfolio_technologies_widget' );
  2193 		if ( function_exists( 'is_multisite' ) && is_multisite() ) {
  1436 	}
  2194 			$old_blog = $wpdb->blogid;
  1437 }
  2195 			/* Get all blog ids */
  1438 
  2196 			$blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
  1439 register_activation_hook( __FILE__, 'prtfl_plugin_install' ); /* Activate plugin */
  2197 			foreach ( $blogids as $blog_id ) {
       
  2198 				switch_to_blog( $blog_id );
       
  2199 				if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) {
       
  2200 					delete_option( 'widget_portfolio_technologies_widget' );
       
  2201 					delete_option( 'prtfl_options' );
       
  2202 					delete_option( 'prtfl_tag_update' );
       
  2203 					delete_post_meta_by_key( 'prtfl_information' );
       
  2204 					delete_post_meta_by_key( '_prtfl_images' );
       
  2205 					delete_post_meta_by_key( 'prtfl_featured' );
       
  2206 				}
       
  2207 			}
       
  2208 			switch_to_blog( $old_blog );
       
  2209 		} else {
       
  2210 			if ( ! array_key_exists( 'portfolio-pro/portfolio-pro.php', $plugins_list ) ) {
       
  2211 				delete_option( 'widget_portfolio_technologies_widget' );
       
  2212 				delete_option( 'prtfl_options' );
       
  2213 				delete_option( 'prtfl_tag_update' );
       
  2214 				delete_post_meta_by_key( 'prtfl_information' );
       
  2215 				delete_post_meta_by_key( '_prtfl_images' );
       
  2216 				delete_post_meta_by_key( 'prtfl_featured' );
       
  2217 			}
       
  2218 		}
       
  2219 
       
  2220 		require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' );
       
  2221 		bws_include_init( plugin_basename( __FILE__ ) );
       
  2222 		bws_delete_plugin( plugin_basename( __FILE__ ) );
       
  2223 	}
       
  2224 }
       
  2225 
       
  2226 /* Activate plugin */
       
  2227 register_activation_hook( __FILE__, 'prtfl_plugin_activate' );
  1440 /* Add portfolio settings page in admin menu */
  2228 /* Add portfolio settings page in admin menu */
  1441 add_action( 'admin_menu', 'add_prtfl_admin_menu' );
  2229 add_action( 'admin_menu', 'add_prtfl_admin_menu' );
  1442 add_action( 'admin_init', 'prtfl_admin_init' );
  2230 add_action( 'admin_init', 'prtfl_admin_init' );
  1443 add_action( 'init', 'prtfl_init' );
  2231 add_action( 'init', 'prtfl_init' );
  1444 add_action( 'wp_loaded', 'prtfl_flush_rules' );
  2232 add_action( 'plugins_loaded', 'prtfl_plugins_loaded' );
  1445 /* Save custom data from admin  */
  2233 /* Save custom data from admin  */
  1446 add_action( 'save_post', 'prtfl_save_postdata', 1, 2 );
  2234 add_action( 'save_post', 'prtfl_save_postdata', 1, 2 );
  1447 add_filter( 'content_save_pre', 'prtfl_content_save_pre', 10, 1 );
  2235 add_filter( 'content_save_pre', 'prtfl_content_save_pre', 10, 1 );
  1448 
  2236 
  1449 /* Add template for single portfolio page */
  2237 /* this function add custom fields and images for PDF&Print plugin in Portfolio post */
  1450 add_action( 'template_redirect', 'prtfl_template_redirect' );
  2238 add_filter( 'bwsplgns_get_pdf_print_content', 'prtfl_add_pdf_print_content' );
  1451 /* Add template in theme after activate new theme */
       
  1452 add_action( 'after_switch_theme', 'prtfl_after_switch_theme', 10, 2 );
       
  1453 
  2239 
  1454 add_action( 'admin_enqueue_scripts', 'prtfl_admin_head' );
  2240 add_action( 'admin_enqueue_scripts', 'prtfl_admin_head' );
  1455 add_action( 'wp_enqueue_scripts', 'prtfl_wp_head' );
  2241 add_action( 'wp_enqueue_scripts', 'prtfl_wp_enqueue_scripts' );
       
  2242 add_action( 'wp_head', 'prtfl_wp_head' );
       
  2243 add_action( 'wp_footer', 'prtfl_wp_footer' );
  1456 
  2244 
  1457 /* add theme name as class to body tag */
  2245 /* add theme name as class to body tag */
  1458 add_filter( 'body_class', 'prtfl_theme_body_classes' );
  2246 add_filter( 'body_class', 'prtfl_theme_body_classes' );
  1459 
  2247 
  1460 /* Add widget for portfolio technologies */
  2248 /* Add widget for portfolio technologies */
  1461 add_action( 'widgets_init', 'prtfl_register_widget' );
  2249 add_action( 'widgets_init', 'prtfl_register_widget' );
  1462 
  2250 
  1463 add_action( 'wp_ajax_prtfl_update_image', 'prtfl_update_image' );
  2251 add_action( 'wp_ajax_prtfl_update_image', 'prtfl_update_image' );
  1464 
  2252 
  1465 add_shortcode( 'latest_portfolio_items', 'prtfl_latest_items' );
  2253 add_shortcode( 'latest_portfolio_items', 'prtfl_latest_items' );
       
  2254 /* custom filter for bws button in tinyMCE */
       
  2255 add_filter( 'bws_shortcode_button_content', 'prtfl_shortcode_button_content' );
  1466 
  2256 
  1467 add_filter( 'request', 'prtfl_request_filter' );
  2257 add_filter( 'request', 'prtfl_request_filter' );
  1468 /* Display tachnologies taxonomy */
  2258 /* Display tachnologies taxonomy */
  1469 add_filter( 'pre_get_posts', 'prtfl_technologies_get_posts' );
  2259 add_filter( 'pre_get_posts', 'prtfl_technologies_get_posts' );
  1470 add_filter( 'rewrite_rules_array', 'prtfl_custom_permalinks' );
  2260 add_filter( 'rewrite_rules_array', 'prtfl_custom_permalinks' );
  1472 add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 );
  2262 add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 );
  1473 add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 );
  2263 add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 );
  1474 
  2264 
  1475 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
  2265 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
  1476 
  2266 
  1477 add_filter( 'sanitize_file_name', 'prtfl_sanitize_file_name' );
  2267 add_action( 'admin_notices', 'prtfl_admin_notices' );
  1478 add_filter( 'intermediate_image_sizes_advanced', 'prtfl_filter_image_sizes' );
  2268 
  1479 
  2269 register_deactivation_hook( __FILE__, 'prtfl_plugin_deactivation' ); /* Deactivate plugin */
  1480 add_action( 'admin_notices', 'prtfl_admin_notices');
       
  1481 
       
  1482 register_uninstall_hook( __FILE__, 'prtfl_plugin_uninstall' ); /* Deactivate plugin */
       
  1483 ?>