wp/wp-content/plugins/portfolio/portfolio.php
changeset 12 d8a8807227e4
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
11:bf1778c34b9a 12:d8a8807227e4
     4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/portfolio/
     4 Plugin URI: https://bestwebsoft.com/products/wordpress/plugins/portfolio/
     5 Description: Create your personal portfolio WordPress website. Manage and showcase past projects to get more clients.
     5 Description: Create your personal portfolio WordPress website. Manage and showcase past projects to get more clients.
     6 Author: BestWebSoft
     6 Author: BestWebSoft
     7 Text Domain: portfolio
     7 Text Domain: portfolio
     8 Domain Path: /languages
     8 Domain Path: /languages
     9 Version: 2.46
     9 Version: 2.51
    10 Author URI: https://bestwebsoft.com/
    10 Author URI: https://bestwebsoft.com/
    11 License: GPLv2 or later
    11 License: GPLv2 or later
    12 */
    12 */
    13 
    13 
    14 /*
    14 /*
    15 	@ Copyright 2017  BestWebSoft  ( https://support.bestwebsoft.com )
    15 	@ Copyright 2019  BestWebSoft  ( https://support.bestwebsoft.com )
    16 
    16 
    17 	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
    18 	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
    19 	published by the Free Software Foundation.
    19 	published by the Free Software Foundation.
    20 
    20 
   217 														),
   217 														),
   218 			'page_id_portfolio_template'				=> '',
   218 			'page_id_portfolio_template'				=> '',
   219 			'order_by' 									=>	'date',
   219 			'order_by' 									=>	'date',
   220 			'order' 									=>	'DESC',
   220 			'order' 									=>	'DESC',
   221 			'custom_image_row_count'					=>	3,
   221 			'custom_image_row_count'					=>	3,
       
   222 			'custom_portfolio_row_count'				=>  1,
   222 			'date_additional_field' 					=>	1,
   223 			'date_additional_field' 					=>	1,
   223 			'link_additional_field' 					=>	1,
   224 			'link_additional_field' 					=>	1,
   224 			'shrdescription_additional_field' 			=>	1,
   225 			'shrdescription_additional_field' 			=>	1,
   225 			'description_additional_field' 				=>	1,
   226 			'description_additional_field' 				=>	1,
   226 			'svn_additional_field' 						=>	1,
   227 			'svn_additional_field' 						=>	1,
  1087 	}
  1088 	}
  1088 }
  1089 }
  1089 
  1090 
  1090 /* forming content for portfolio items */
  1091 /* forming content for portfolio items */
  1091 if ( ! function_exists( 'prtfl_latest_items' ) ) {
  1092 if ( ! function_exists( 'prtfl_latest_items' ) ) {
  1092 	function prtfl_latest_items( $atts ) {
  1093 	function prtfl_latest_items( $atts, $widget = false ) {
  1093 		global $prtfl_options, $wp_query;
  1094 		global $prtfl_options, $wp_query;
  1094 		$old_wp_query = $wp_query;
  1095 		$old_wp_query = $wp_query;
  1095 
  1096 		$count_portfolio_row_block = 0;
       
  1097 		if ( $widget == false) {
       
  1098 			$custom_portfolio_row_count = $prtfl_options['custom_portfolio_row_count'];
       
  1099 		} else {
       
  1100 			$custom_portfolio_row_count = $widget;
       
  1101 		}
       
  1102 		$prtfl_widht = 100 / $custom_portfolio_row_count;
       
  1103 
       
  1104 
       
  1105 		if( 1 < $custom_portfolio_row_count  ) {
       
  1106 			$prtfl_read_more = 'style="float:left"';
       
  1107 			$prtfl_img_width = '';
       
  1108 		}else{
       
  1109 			$prtfl_read_more = "";
       
  1110 			$prtfl_img_width = 'style="width:165px"';
       
  1111 		}
       
  1112 		
  1096 		$content	=	'<div class="prtfl_portfolio_block">';
  1113 		$content	=	'<div class="prtfl_portfolio_block">';
  1097 		if ( empty( $atts['count'] ) ) {
  1114 		if ( empty( $atts['count'] ) ) {
  1098 			$atts['count'] = 3;
  1115 			$atts['count'] = 3;
  1099 		}
  1116 		}
  1100 		$args		=	array(
  1117 		$args		=	array(
  1101 			'post_type'			=> $prtfl_options['post_type_name'],
  1118 			'post_type'			=> $prtfl_options['post_type_name'],
  1102 			'post_status'		=> 'publish',
  1119 			'post_status'		=> 'publish',
  1103 			'orderby'			=> 'date',
  1120 			'orderby'			=> 'date',
  1104 			'order'				=> 'DESC',
  1121 			'order'				=> $prtfl_options['order'],
  1105 			'posts_per_page'	=> $atts['count'],
  1122 			'posts_per_page'	=> $atts['count'],
  1106 			);
  1123 			);
  1107 			$second_query = new WP_Query( $args );
  1124 			$second_query = new WP_Query( $args );
  1108 			$request = $second_query->request;
  1125 			$request = $second_query->request;
  1109 
  1126 
  1110 			if ( $second_query->have_posts() ) {
  1127 			if ( $second_query->have_posts() ) {
  1111 				while ( $second_query->have_posts() ) {
  1128 				while ( $second_query->have_posts() ) {
  1112 					$second_query->the_post();
  1129 					$second_query->the_post();
  1113 			$content .= '
  1130 					if ( $count_portfolio_row_block % $custom_portfolio_row_count == 0 ) {
       
  1131 						$content .= '<div class="portfolio_row_count">';
       
  1132 					}
       
  1133 					$content .= '<div id="portfolio_row_count_block" class="portfolio_row_count_block" style="width: ' . $prtfl_widht . '%">
  1114 			<div class="portfolio_content">
  1134 			<div class="portfolio_content">
  1115 				<div class="entry">';
  1135 				<div class="entry">';
  1116 					global $post;
  1136 					global $post;
  1117 					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  1137 					$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  1118 					if ( empty ( $post_thumbnail_id ) ) {
  1138 					if ( empty ( $post_thumbnail_id ) ) {
  1142 					if ( empty( $title ) ) {
  1162 					if ( empty( $title ) ) {
  1143 						$title = '(' . __( 'No title', 'portfolio' ) . ')';
  1163 						$title = '(' . __( 'No title', 'portfolio' ) . ')';
  1144 					}
  1164 					}
  1145 					$permalink = get_permalink();
  1165 					$permalink = get_permalink();
  1146 
  1166 
  1147 					$content .= '<div class="portfolio_thumb" style="width:165px">
  1167 					$content .= '<div class="portfolio_thumb" ' . $prtfl_img_width . '>
  1148 							<img src="' . $image[0] . '" width="' . $image[1] . '" alt="' . $image_alt . '" />
  1168 							<img src="' . $image[0] . '" width="' . $image[1] . '" alt="' . $image_alt . '" />
  1149 					</div>
  1169 					</div>
  1150 					<div class="portfolio_short_content">
  1170 					<div class="portfolio_short_content">
  1151 						<div class="item_title">
  1171 						<div class="item_title">
  1152 							<p>
  1172 							<p>
  1156 						if ( 1 == $prtfl_options['shrdescription_additional_field'] && ( ! empty( $short_descr ) ) ) {
  1176 						if ( 1 == $prtfl_options['shrdescription_additional_field'] && ( ! empty( $short_descr ) ) ) {
  1157 							$content .= '<p>' . $short_descr . '</p>';
  1177 							$content .= '<p>' . $short_descr . '</p>';
  1158 						}
  1178 						}
  1159 					$content .= '</div> <!-- .portfolio_short_content -->
  1179 					$content .= '</div> <!-- .portfolio_short_content -->
  1160 				</div> <!-- .entry -->
  1180 				</div> <!-- .entry -->
  1161 				<div class="read_more">
  1181 				<div class="read_more" ' . $prtfl_read_more . '>
  1162 					<a href="' . $permalink . '" rel="bookmark">' . __( 'Read more', 'portfolio' ) . '</a>
  1182 					<a href="' . $permalink . '" rel="bookmark">' . __( 'Read more', 'portfolio' ) . '</a>
  1163 				</div> <!-- .read_more -->
  1183 				</div> <!-- .read_more -->
  1164 				<div class="portfolio_terms">';
  1184 				<div class="portfolio_terms">';
  1165 				if ( 1 == $prtfl_options['technologies_additional_field'] ) {
  1185 				if ( 1 == $prtfl_options['technologies_additional_field'] ) {
  1166 					$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1186 					$terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1177 					} else {
  1197 					} else {
  1178 						$content .= '&nbsp;';
  1198 						$content .= '&nbsp;';
  1179 					}
  1199 					}
  1180 				}
  1200 				}
  1181 				$content .= '</div><!-- .portfolio_terms -->';
  1201 				$content .= '</div><!-- .portfolio_terms -->';
  1182 			$content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content -->';
  1202 			$content .= '<div class="prtfl_clear"></div></div> <!-- .portfolio_content --></div><!-- .gllr_image_block -->';
  1183 			}
  1203 			if ( ( $count_portfolio_row_block % $custom_portfolio_row_count ) == ( $custom_portfolio_row_count - 1 ) ) {
  1184 		}
  1204 				$content .= '<div class="clear"></div>
  1185 		$content .= '</div> <!-- .prtfl_portfolio_block -->';
  1205 				</div><!-- .gllr_image_row -->';
       
  1206 			}
       
  1207 			$count_portfolio_row_block = $count_portfolio_row_block + 1;
       
  1208 			}
       
  1209 		}
       
  1210 		$content .= '</div> <!-- .prtfl_portfolio_block --><div class="clear"></div>';
  1186 		wp_reset_query();
  1211 		wp_reset_query();
  1187 		$wp_query = $old_wp_query;
  1212 		$wp_query = $old_wp_query;
  1188 		return $content;
  1213 		return $content;
  1189 	}
  1214 	}
  1190 }
  1215 }
  1293 		check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
  1318 		check_ajax_referer( plugin_basename( __FILE__ ), 'prtfl_ajax_nonce_field' );
  1294 		$action	= isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
  1319 		$action	= isset( $_REQUEST['action1'] ) ? $_REQUEST['action1'] : "";
  1295 		$id		= isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
  1320 		$id		= isset( $_REQUEST['id'] ) ? $_REQUEST['id'] : "";
  1296 		switch ( $action ) {
  1321 		switch ( $action ) {
  1297 			case 'get_all_attachment':
  1322 			case 'get_all_attachment':
  1298 				$array_parent_id = $wpdb->get_col( "SELECT `ID` FROM $wpdb->posts WHERE `post_type` = {$prtfl_options['post_type_name']}" );
  1323 
       
  1324 			    $array_parent_id = $wpdb->get_col( $wpdb->prepare( "
       
  1325                     SELECT 
       
  1326                         ID 
       
  1327                     FROM 
       
  1328                         {$wpdb->posts}
       
  1329                     WHERE 
       
  1330                         post_type = %s
       
  1331                 ", $prtfl_options['post_type_name'] ) );
       
  1332 
  1299 				if ( ! empty( $array_parent_id ) ) {
  1333 				if ( ! empty( $array_parent_id ) ) {
  1300 					$string_parent_id = implode( ",", $array_parent_id );
  1334 					$string_parent_id = implode( ",", $array_parent_id );
  1301 
  1335 
  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 );
  1336 					$metas = $wpdb->get_results( "
       
  1337                         SELECT 
       
  1338                             meta_value 
       
  1339                         FROM 
       
  1340                             {$wpdb->postmeta} 
       
  1341                         WHERE 
       
  1342                             meta_key = '_prtfl_images' AND 
       
  1343                             post_id IN (" . $string_parent_id . ")
       
  1344                     ", ARRAY_A );
  1303 
  1345 
  1304 					$result_attachment_id = '';
  1346 					$result_attachment_id = '';
  1305 					foreach ( $metas as $key => $value ) {
  1347 					foreach ( $metas as $key => $value ) {
  1306 						if ( ! empty( $value['meta_value'] ) ) {
  1348 						if ( ! empty( $value['meta_value'] ) ) {
  1307 							$result_attachment_id .= $value['meta_value'] . ',';
  1349 							$result_attachment_id .= $value['meta_value'] . ',';
  1308 						}
  1350 						}
  1309 					}
  1351 					}
  1310 					$result_attachment_id_array = explode( ",", rtrim( $result_attachment_id, ',' ) );
  1352 					$result_attachment_id_array = explode( ",", rtrim( $result_attachment_id, ',' ) );
  1311 
  1353 
  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 );
  1354 					$attached_id = $wpdb->get_results( "
       
  1355                         SELECT 
       
  1356                             ID 
       
  1357                         FROM 
       
  1358                             {$wpdb->posts} 
       
  1359                         WHERE 
       
  1360                             post_type = 'attachment' AND 
       
  1361                             post_mime_type LIKE 'image%' AND 
       
  1362                             post_parent IN (" . $string_parent_id . ")
       
  1363                     ", ARRAY_A );
       
  1364 
  1313 					foreach ( $attached_id as $key => $value ) {
  1365 					foreach ( $attached_id as $key => $value ) {
  1314 						$result_attachment_id_array[] = $value['ID'];
  1366 						$result_attachment_id_array[] = $value['ID'];
  1315 					}
  1367 					}
  1316 					echo json_encode( array_unique( $result_attachment_id_array ) );
  1368 					echo json_encode( array_unique( $result_attachment_id_array ) );
  1317 				}
  1369 				}
  1678  * Prepare arguments for post query
  1730  * Prepare arguments for post query
  1679  * @return array|false
  1731  * @return array|false
  1680  */
  1732  */
  1681 if ( ! function_exists( 'prtfl_get_query_args' ) ) {
  1733 if ( ! function_exists( 'prtfl_get_query_args' ) ) {
  1682 	function prtfl_get_query_args() {
  1734 	function prtfl_get_query_args() {
  1683 		global $prtfl_options;
  1735 		global $prtfl_options, $wp_query;
  1684 		$count = 0;
  1736 		$count = 0;
  1685 		if ( get_query_var( 'paged' ) ) {
  1737 		if ( get_query_var( 'paged' ) ) {
  1686 			$paged = get_query_var( 'paged' );
  1738 			$paged = get_query_var( 'paged' );
  1687 		} elseif ( get_query_var( 'page' ) ) {
  1739 		} elseif ( get_query_var( 'page' ) ) {
  1688 			$paged = get_query_var( 'page' );
  1740 			$paged = get_query_var( 'page' );
  1749 if ( ! function_exists( 'prtfl_get_content' ) ) {
  1801 if ( ! function_exists( 'prtfl_get_content' ) ) {
  1750 	function prtfl_get_content( $second_query ) {
  1802 	function prtfl_get_content( $second_query ) {
  1751 		global $post, $prtfl_options;
  1803 		global $post, $prtfl_options;
  1752 
  1804 
  1753 		$request = $second_query->request;
  1805 		$request = $second_query->request;
       
  1806 		$count_portfolio_row_block = 0;
       
  1807 		$prtfl_widht = 99 / $prtfl_options['custom_portfolio_row_count'];
       
  1808 
       
  1809 		if( 1 < $prtfl_options['custom_portfolio_row_count']  ){
       
  1810 			$prtfl_read_more = 'style="float:left"';
       
  1811 		}else{
       
  1812 			$prtfl_read_more = "";
       
  1813 		}
  1754 
  1814 
  1755 		if ( ! empty( $post ) && ! empty( $post->post_content ) ) {
  1815 		if ( ! empty( $post ) && ! empty( $post->post_content ) ) {
  1756 			$page_content = $post->post_content;
  1816 			$page_content = $post->post_content;
  1757 			if ( function_exists( 'mltlngg_the_content_filter' ) ) $page_content = mltlngg_the_content_filter( $page_content );
  1817 			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 */
  1818 			/* dublicate filter 'the_content' - as we couldnt use it */
  1783 		<?php }
  1843 		<?php }
  1784 
  1844 
  1785 
  1845 
  1786 		if ( $second_query->have_posts() ) {
  1846 		if ( $second_query->have_posts() ) {
  1787 			while ( $second_query->have_posts() ) {
  1847 			while ( $second_query->have_posts() ) {
  1788 				$second_query->the_post(); ?>
  1848 				$second_query->the_post();
       
  1849 				if ( $count_portfolio_row_block % $prtfl_options['custom_portfolio_row_count'] == 0 ) {?>
       
  1850 					<div class="portfolio_row_count"><?php
       
  1851 				}?>
       
  1852 				<div id="portfolio_row_count_block" class="portfolio_row_count_block" style="width: <?php echo $prtfl_widht ?>%">
  1789 				<div class="portfolio_content <?php if ( 'twentyfourteen' == get_stylesheet() || 'twentythirteen' == get_stylesheet() || 'twentytwelve' == get_stylesheet() ) echo 'entry-content'; ?>">
  1853 				<div class="portfolio_content <?php if ( 'twentyfourteen' == get_stylesheet() || 'twentythirteen' == get_stylesheet() || 'twentytwelve' == get_stylesheet() ) echo 'entry-content'; ?>">
  1790 					<div class="entry">
  1854 					<div class="entry">
  1791 						<?php $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  1855 						<?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'] );
  1856 						$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 );
  1857 						$post_meta		= get_post_meta( $post->ID, 'prtfl_information', true );
  1848 								<p><span class="lable"><?php echo '<b>' . $prtfl_options['shrdescription_text_field'] . '</b>'; ?></span> <?php echo $short_descr; ?></p>
  1912 								<p><span class="lable"><?php echo '<b>' . $prtfl_options['shrdescription_text_field'] . '</b>'; ?></span> <?php echo $short_descr; ?></p>
  1849 							<?php } ?>
  1913 							<?php } ?>
  1850 						</div><!-- .portfolio_short_content -->
  1914 						</div><!-- .portfolio_short_content -->
  1851 					</div><!-- .entry -->
  1915 					</div><!-- .entry -->
  1852 					<div class="entry_footer">
  1916 					<div class="entry_footer">
  1853 						<div class="read_more">
  1917 						<div class="read_more" <?php echo $prtfl_read_more ?>>
  1854 							<a href="<?php the_permalink(); ?>" rel="bookmark"><?php _e( 'Read more', 'portfolio' ); ?></a>
  1918 							<a href="<?php the_permalink(); ?>" rel="bookmark"><?php _e( 'Read more', 'portfolio' ); ?></a>
  1855 						</div><!-- .read_more -->
  1919 						</div><!-- .read_more -->
  1856 						<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1920 						<?php $terms = wp_get_object_terms( $post->ID, 'portfolio_technologies' );
  1857 						if ( 1 == $prtfl_options['technologies_additional_field'] && ! is_wp_error( $terms ) ) {
  1921 						if ( 1 == $prtfl_options['technologies_additional_field'] && ! is_wp_error( $terms ) ) {
  1858 							if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
  1922 							if ( is_array( $terms ) && 0 < count( $terms ) ) { ?>
  1861 									$links = array();
  1925 									$links = array();
  1862 									foreach ( $terms as $term ) {
  1926 									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>';
  1927 										$links[] = '<a href="' . get_term_link( $term->slug, 'portfolio_technologies' ) . '" title="' . sprintf( __( "View all projects in %s" ), $term->name ) . '" ' . '>' . $term->name . '</a>';
  1864 									}
  1928 									}
  1865 									echo implode( ', ', $links ); ?>
  1929 									echo implode( ', ', $links ); ?>
  1866 								</div><!-- .portfolio_terms -->
  1930 								</div><!-- .portfolio_terms --><?php
  1867 							<?php }
  1931 							}
  1868 						} ?>
  1932 						} ?>
  1869 					</div><!-- .entry_footer -->
  1933 					</div><!-- .entry_footer -->
  1870 				</div><!-- .portfolio_content -->
  1934 				</div><!-- .portfolio_content -->
  1871 					<?php }
  1935                 </div>
  1872 		}
  1936 				<?php if ( ( $count_portfolio_row_block % $prtfl_options['custom_portfolio_row_count'] ) == ( $prtfl_options['custom_portfolio_row_count'] - 1 ) ) {?>
       
  1937                     <div class="clear"></div>
       
  1938                     </div><!-- .portfolio_row_count --><?php
       
  1939                 }
       
  1940                 $count_portfolio_row_block = $count_portfolio_row_block + 1;
       
  1941             }
       
  1942 		}
       
  1943 		if ( 0 != $count_portfolio_row_block % $prtfl_options['custom_portfolio_row_count'] )  {
       
  1944 			?></div><?php
       
  1945 		}
       
  1946 		?>
       
  1947        <div class="clear"></div><?php
  1873 	}
  1948 	}
  1874 }
  1949 }
  1875 
  1950 
  1876 /**
  1951 /**
  1877  * Display post template content
  1952  * Display post template content
  2221 		bws_include_init( plugin_basename( __FILE__ ) );
  2296 		bws_include_init( plugin_basename( __FILE__ ) );
  2222 		bws_delete_plugin( plugin_basename( __FILE__ ) );
  2297 		bws_delete_plugin( plugin_basename( __FILE__ ) );
  2223 	}
  2298 	}
  2224 }
  2299 }
  2225 
  2300 
       
  2301 
       
  2302 if ( ! function_exists( 'prtfl_get_data' ) ) {
       
  2303     function prtfl_get_data( $prtfl_id ) {
       
  2304 
       
  2305       $post_type = array('bws-portfolio');
       
  2306     
       
  2307       $prtfl_posts = $prtfl_images_all = array();
       
  2308 
       
  2309       if ( 'all' == $prtfl_id || is_array( $prtfl_id ) ) {
       
  2310 
       
  2311         $prtfl_id_list = ( is_array( $prtfl_id ) && ! empty( $prtfl_id ) ) ? $prtfl_id  : array();
       
  2312         $args = ( is_array( $prtfl_id ) ) ? array( 'post_type' => 'bws-portfolio',
       
  2313                                                          'include' => $prtfl_id_list ) : array( 'post_type' => 'bws-portfolio');
       
  2314         $prtfl_posts = get_posts( $args );
       
  2315 
       
  2316 	    } else if ( is_int( $prtfl_id ) || is_string( $prtfl_id ) ) {
       
  2317 
       
  2318 	      $prtfl_int_id = is_int( $prtfl_id ) ? $prtfl_id : intval( $prtfl_id );
       
  2319 	      $prtfl_posts = get_post( $prtfl_int_id );
       
  2320 
       
  2321 	    }
       
  2322 	    
       
  2323 	    $prtfl_posts_end = array();
       
  2324 	 	foreach ( (array)$prtfl_posts as $key => $prtfl_post ) {
       
  2325 
       
  2326 		    $prtfl_meta = get_post_meta( $prtfl_post->ID, '' );
       
  2327 		    unset($prtfl_meta['_edit_lock']);
       
  2328 		    unset($prtfl_meta['_edit_last']);
       
  2329 
       
  2330 		    foreach ( $prtfl_meta['prtfl_information']  as $key => $prtfl_information ) {
       
  2331 
       
  2332 		    	$prtfl_information =  isset( $prtfl_information ) ? unserialize( $prtfl_information ) : "";
       
  2333 		    	$prtfl_meta['prtfl_information'][$key] = $prtfl_information;
       
  2334 		    }
       
  2335 
       
  2336 		    foreach ( $prtfl_meta['_prtfl_images']  as $key => $prtfl_images ) {
       
  2337 		    	
       
  2338 		    	$prtfl_images_all =  isset( $prtfl_images ) ? explode( ',' , $prtfl_images ) : "";
       
  2339 		    	$args = array(  'post_type' => 'attachment','include' => $prtfl_images_all ) ;
       
  2340 		    	$prtfl_images = ! empty( $prtfl_images_all ) ? get_posts( $args ) : "";
       
  2341 		    	$prtfl_meta['_prtfl_images'][$key] = $prtfl_images;
       
  2342 		    }
       
  2343 
       
  2344 		    $prtfl_posts[$key]->prtfl_post_meta = $prtfl_meta;
       
  2345 	    }
       
  2346 
       
  2347         return $prtfl_posts;
       
  2348     }
       
  2349 }
       
  2350 
       
  2351 
       
  2352 if ( ! function_exists( 'prtfl_widgets_init' ) ) {
       
  2353 	function prtfl_widgets_init() {
       
  2354 		register_widget( "Prtfl_Widget" );
       
  2355 	}
       
  2356 }
       
  2357 
       
  2358 /**
       
  2359  * Class extends WP class WP_Widget, and create new widget
       
  2360  *
       
  2361  */
       
  2362 if ( ! class_exists( 'Prtfl_Widget' ) ) {
       
  2363 	class Prtfl_Widget extends WP_Widget {
       
  2364 		/**
       
  2365 		 * constructor of class
       
  2366 		 */
       
  2367 		public function __construct() {
       
  2368 			parent::__construct(
       
  2369 				'prtfl_widget',
       
  2370 				__( 'Latest Portfolio Items', 'portfolio' ),
       
  2371 				array( 'description' => __( 'Displays the latest Portfolio projects.', 'portfolio' ) )
       
  2372 			);
       
  2373 		}
       
  2374 		/**
       
  2375 		 * Function to displaying widget in front end
       
  2376 		 * @param array()	 $args 	array with sidebar settings
       
  2377 		 * @param array()	 $instance 	array with widget settings
       
  2378 		 * @return void
       
  2379 		 */
       
  2380 		public function widget( $args, $instance ) {
       
  2381 
       
  2382 			$widget_title = ( ! empty( $instance['widget_title'] ) ) ? apply_filters( 'widget_title', $instance['widget_title'], $instance, $this->id_base ) : '';
       
  2383 			$widget_count_posts = ( ! empty( $instance['widget_count_posts'] ) ) ?  $instance['widget_count_posts']: '';
       
  2384 			$widget_count_colums = ( ! empty( $instance['widget_count_colums'] ) ) ?  $instance['widget_count_colums']: '';
       
  2385 
       
  2386 			$atts['count'] = $widget_count_posts;
       
  2387 			$content = prtfl_latest_items( $atts, $widget_count_colums );
       
  2388 			echo $args['before_widget'] . $args['before_title'] . $widget_title . $args['after_title'] . $content;
       
  2389 		}
       
  2390 
       
  2391 		public function form( $instance ) {
       
  2392 			global $sbscrbr_options;
       
  2393 
       
  2394 			$widget_title          = isset( $instance['widget_title'] ) ? stripslashes( esc_html( $instance['widget_title'] ) ) : null;
       
  2395 			$widget_count_posts          = isset( $instance['widget_count_posts'] ) ? stripslashes( esc_html( $instance['widget_count_posts'] ) ) : null;
       
  2396 			$widget_count_colums         = isset( $instance['widget_count_colums'] ) ? stripslashes( esc_html( $instance['widget_count_colums'] ) ) : null;
       
  2397 			?>
       
  2398 			<p>
       
  2399 				<label for="<?php echo $this->get_field_id( 'widget_title' ); ?>">
       
  2400 					<?php _e( 'Title', 'portfolio' ); ?>:
       
  2401 					<input class="widefat" id="<?php echo $this->get_field_id( 'widget_title' ); ?>" name="<?php echo $this->get_field_name( 'widget_title' ); ?>" type="text" value="<?php echo esc_attr( $widget_title ); ?>"/>
       
  2402 				</label>
       
  2403 			</p>
       
  2404 			<p>
       
  2405 				<label for="<?php echo $this->get_field_id( 'widget_count_posts' ); ?>">
       
  2406 					<?php _e( 'Number of projects:', 'portfolio' ); ?>:
       
  2407 					<input class="widefat" id="<?php echo $this->get_field_id( 'widget_count_posts' ); ?>" name="<?php echo $this->get_field_name( 'widget_count_posts' ); ?>" type="number" name="prtfl_portfolio_custom_row_count" min="1" max="10000" value="<?php echo ! empty( ( $widget_count_posts ) ) ? esc_attr( $widget_count_posts ) : 5; ?>"/>
       
  2408 				</label>
       
  2409 			</p>
       
  2410 			<p>
       
  2411 				<label for="<?php echo $this->get_field_id( 'widget_count_colums' ); ?>">
       
  2412 					<?php _e( 'Number of Colums:', 'portfolio' ); ?>:
       
  2413 					<input class="widefat" id="<?php echo $this->get_field_id( 'widget_count_colums' ); ?>" name="<?php echo $this->get_field_name( 'widget_count_colums' ); ?>" type="number" name="prtfl_portfolio_custom_row_count_colums" min="1" max="100" value="<?php echo ! empty( ( $widget_count_colums ) ) ? esc_attr( $widget_count_colums ) : 3; ?>"/>
       
  2414 				</label>
       
  2415 			</p>
       
  2416 		<?php }
       
  2417 
       
  2418 		public function update( $new_instance, $old_instance ) {
       
  2419 			$instance = array();
       
  2420 			$instance['widget_title']          = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : null;
       
  2421 			$instance['widget_count_posts']    = ( ! empty( $new_instance['widget_count_posts'] ) ) ? strip_tags( $new_instance['widget_count_posts'] ) : null;
       
  2422 			$instance['widget_count_colums']    = ( ! empty( $new_instance['widget_count_colums'] ) ) ? strip_tags( $new_instance['widget_count_colums'] ) : null;
       
  2423 			return $instance;
       
  2424 		}
       
  2425 	}
       
  2426 }
       
  2427 
  2226 /* Activate plugin */
  2428 /* Activate plugin */
  2227 register_activation_hook( __FILE__, 'prtfl_plugin_activate' );
  2429 register_activation_hook( __FILE__, 'prtfl_plugin_activate' );
  2228 /* Add portfolio settings page in admin menu */
  2430 /* Add portfolio settings page in admin menu */
  2229 add_action( 'admin_menu', 'add_prtfl_admin_menu' );
  2431 add_action( 'admin_menu', 'add_prtfl_admin_menu' );
  2230 add_action( 'admin_init', 'prtfl_admin_init' );
  2432 add_action( 'admin_init', 'prtfl_admin_init' );
  2260 add_filter( 'rewrite_rules_array', 'prtfl_custom_permalinks' );
  2462 add_filter( 'rewrite_rules_array', 'prtfl_custom_permalinks' );
  2261 /* Additional links on the plugin page */
  2463 /* Additional links on the plugin page */
  2262 add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 );
  2464 add_filter( 'plugin_row_meta', 'prtfl_register_plugin_links', 10, 2 );
  2263 add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 );
  2465 add_filter( 'plugin_action_links', 'prtfl_plugin_action_links', 10, 2 );
  2264 
  2466 
       
  2467 add_action( 'widgets_init', 'prtfl_widgets_init' );
       
  2468 
  2265 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
  2469 add_filter( 'nav_menu_css_class', 'prtfl_add_portfolio_ancestor_to_menu', 10, 2 );
  2266 
  2470 
  2267 add_action( 'admin_notices', 'prtfl_admin_notices' );
  2471 add_action( 'admin_notices', 'prtfl_admin_notices' );
  2268 
  2472 
  2269 register_deactivation_hook( __FILE__, 'prtfl_plugin_deactivation' ); /* Deactivate plugin */
  2473 register_deactivation_hook( __FILE__, 'prtfl_plugin_deactivation' ); /* Deactivate plugin */