wp/wp-content/themes/IN-MOTION-package-u1/in-motion/functions/custom-portfolio.php
changeset 0 d970ebf37754
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 
       
     3 
       
     4 // creating portfolio 
       
     5 
       
     6 add_action('init', 'portfolio_register');
       
     7  
       
     8 function portfolio_register() {
       
     9  
       
    10 	$labels = array(
       
    11 		'name' => _x('Portfolio', 'post type general name'),
       
    12 		'singular_name' => _x('Portfolio Item', 'post type singular name'),
       
    13 		'add_new' => _x('Add New', 'portfolio item'),
       
    14 		'add_new_item' => __('Add New Portfolio Item','pego_tr'),
       
    15 		'edit_item' => __('Edit Portfolio Item','pego_tr'),
       
    16 		'new_item' => __('New Portfolio Item','pego_tr'),
       
    17 		'view_item' => __('View Portfolio Item','pego_tr'),
       
    18 		'search_items' => __('Search Portfolio','pego_tr'),
       
    19 		'not_found' =>  __('Nothing found','pego_tr'),
       
    20 		'not_found_in_trash' => __('Nothing found in Trash','pego_tr'),
       
    21 		'parent_item_colon' => ''
       
    22 	);
       
    23  
       
    24 	$args = array(
       
    25 		'labels' => $labels,
       
    26 		'public' => true,
       
    27 		'publicly_queryable' => true,
       
    28 		'show_ui' => true,
       
    29 		'query_var' => true,
       
    30 		'rewrite' => true,
       
    31 		'capability_type' => 'post',
       
    32 		'hierarchical' => false,
       
    33 		'menu_position' => null,
       
    34 		'supports' => array('title','editor','thumbnail', 'custom-fields')
       
    35 	  ); 
       
    36  
       
    37 	register_post_type( 'portfolio' , $args );
       
    38 }
       
    39 
       
    40 //portfolio editing
       
    41 
       
    42 	add_action( 'admin_menu', 'hybrid_create_meta_box_portfolio' );
       
    43 	add_action( 'save_post', 'hybrid_save_meta_data_portfolio' );
       
    44 
       
    45 function hybrid_create_meta_box_portfolio() {
       
    46 	global $theme_name;
       
    47 	add_meta_box( 'post-meta-boxes_portfolio', __('Portfolio options','pego_tr'), 'post_meta_boxes_portfolio', 'portfolio', 'normal', 'high' );
       
    48 	add_meta_box( 'post-meta-boxes_portfolio_video', __('Portfolio video options','pego_tr'), 'post_meta_boxes_portfolio_video', 'portfolio', 'normal', 'high' );
       
    49 }
       
    50 
       
    51 register_taxonomy("portfolio_categories", array("portfolio"), array("hierarchical" => true, "label" => "Portfolio categories", "singular_label" => "Portfolio categorie", "rewrite" => true));
       
    52 
       
    53 function hybrid_post_meta_boxes_portfolio() {
       
    54 
       
    55 	/* Array of the meta box options. */
       
    56 	$meta_boxes = array(
       
    57 			'portfolio_type_selected' => array( 
       
    58 							'name' => 'portfolio_type_selected', 
       
    59 							'title' => __(' Type', 'pego_tr'), 
       
    60 							'description' => __('Select portfolio type.', 'pego_tr'), 
       
    61 							'type' => "select", 
       
    62 							'std' => 'Image',
       
    63 							'options' => array('Image', 'Slideshow', 'Video')),
       
    64 			'portfolio_client' => array( 
       
    65 							'name' => 'portfolio_client',
       
    66 							'title' => __("Site de l'intervenant", 'pego_tr'), 
       
    67 							'description' => __("Entrez le lien du site de l'intervenant.", 'pego_tr'), 
       
    68 							'type' => 'text' ),	
       
    69 			'portfolio_url' => array( 
       
    70 							'name' => 'portfolio_url',
       
    71 							'title' => __('Controverse', 'pego_tr'), 
       
    72 							'description' => __('Entre le lien de la controverse.', 'pego_tr'),
       
    73 							'type' => 'text' ),
       
    74 			'portfolio_abstract' => array( 
       
    75 							'name' => 'portfolio_abstract',
       
    76 							'title' => __('Abstract', 'pego_tr'), 
       
    77 							'description' => __("Entre le lien de l'abstract", 'pego_tr'),
       
    78 							'type' => 'text' ),
       
    79 			'portfolio_embed' => array( 
       
    80 							'name' => 'portfolio_embed',
       
    81 							'title' => __('Embed sound cloud', 'pego_tr'), 
       
    82 							'description' => __("Placez ici l'embed de sound cloud", 'pego_tr'),
       
    83 							'type' => 'text' ),
       
    84 			'portfolio_twitter' => array( 
       
    85 							'name' => 'portfolio_twitter',
       
    86 							'title' => __("Twitter de l'intervenant", 'pego_tr'), 
       
    87 							'description' => __("Placez ici seulement le nom twitter de l'intervenant (sans le @)", 'pego_tr'),
       
    88 							'type' => 'text' )
       
    89 	);
       
    90 
       
    91 	return apply_filters( 'hybrid_post_meta_boxes_portfolio', $meta_boxes );
       
    92 }
       
    93 
       
    94 function hybrid_post_meta_boxes_portfolio_video() {
       
    95 
       
    96 	/* Array of the meta box options. */
       
    97 	$meta_boxes = array(
       
    98 			'portfolio_video_url' => array( 
       
    99 							'name' => 'portfolio_video_url',
       
   100 							'title' => __('Video URL:', 'pego_tr'), 
       
   101 							'description' => __('Enter the embedded code of the portfolio.', 'pego_tr'),
       
   102 							'type' => 'textarea' )	
       
   103 	);
       
   104 
       
   105 	return apply_filters( 'hybrid_post_meta_boxes_portfolio_video', $meta_boxes);
       
   106 }
       
   107 
       
   108 function post_meta_boxes_portfolio() {
       
   109 	global $post;
       
   110 	$meta_boxes = hybrid_post_meta_boxes_portfolio(); ?>
       
   111 
       
   112 	<table class="form-table">
       
   113 	<?php foreach ( $meta_boxes as $meta ) :
       
   114 
       
   115 		$value = get_post_meta( $post->ID, $meta['name'], true );
       
   116 
       
   117 		if ( $meta['type'] == 'text' )
       
   118 			get_meta_text_input_portfolio( $meta, $value );
       
   119 		elseif ( $meta['type'] == 'textarea' )
       
   120 			get_meta_textarea_portfolio( $meta, $value );
       
   121 		elseif ( $meta['type'] == 'select' )
       
   122 			get_meta_select_portfolio( $meta, $value );
       
   123 
       
   124 	endforeach; ?>post
       
   125 	</table>
       
   126 <?php
       
   127 }
       
   128 
       
   129 function post_meta_boxes_portfolio_video() {
       
   130 	global $post;
       
   131 	$meta_boxes = hybrid_post_meta_boxes_portfolio_video(); ?>
       
   132 
       
   133 	<table class="form-table">
       
   134 	<?php foreach ( $meta_boxes as $meta ) :
       
   135 
       
   136 		$value = get_post_meta( $post->ID, $meta['name'], true );
       
   137 
       
   138 		if ( $meta['type'] == 'text' )
       
   139 			get_meta_text_input_portfolio( $meta, $value );
       
   140 		elseif ( $meta['type'] == 'textarea' )
       
   141 			get_meta_textarea_portfolio( $meta, $value );
       
   142 		elseif ( $meta['type'] == 'select' )
       
   143 			get_meta_select_portfolio( $meta, $value );
       
   144 
       
   145 	endforeach; ?>
       
   146 	</table>
       
   147 <?php
       
   148 }
       
   149 
       
   150 function get_meta_text_input_portfolio( $args = array(), $value = false ) {
       
   151 
       
   152 	extract( $args ); ?>
       
   153 
       
   154 	<tr>
       
   155 		<th style="width:30%;">
       
   156 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span  style="color:#777777;"><?php echo $description; ?></span></label>
       
   157 		</th>
       
   158 		<td>
       
   159 			<input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_html( $value ); ?>" size="30" tabindex="30" style="width: 97%;" />
       
   160 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   161 		</td>
       
   162 	</tr>
       
   163 	<?php
       
   164 }
       
   165 
       
   166 
       
   167 function get_meta_select_portfolio( $args = array(), $value = false ) {
       
   168 
       
   169 	extract( $args ); ?>
       
   170 
       
   171 	<tr>
       
   172 		<th style="width:30%;">
       
   173 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;" ><?php echo $description; ?></span></label>
       
   174 		</th>
       
   175 		<td>
       
   176 			<select style="width:100px;" name="<?php echo $name; ?>" id="<?php echo $name; ?>">
       
   177 			<?php foreach ( $options as $option ) : ?>
       
   178 				<option <?php if ( htmlentities( $value, ENT_QUOTES ) == $option ) echo ' selected="selected"'; ?>>
       
   179 					<?php echo $option; ?>
       
   180 				</option>
       
   181 			<?php endforeach; ?>
       
   182 			</select>
       
   183 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   184 		</td>
       
   185 	</tr>
       
   186 	<?php
       
   187 }
       
   188 
       
   189 function get_meta_textarea_portfolio( $args = array(), $value = false ) {
       
   190 
       
   191 	extract( $args ); ?>
       
   192 
       
   193 	<tr>
       
   194 		<th style="width:30%;">
       
   195 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;"><?php echo $description; ?></span></label>
       
   196 		</th>
       
   197 		<td>
       
   198 			<textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo esc_html( $value ); ?></textarea>
       
   199 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   200 		</td>
       
   201 	</tr>
       
   202 	<?php
       
   203 }
       
   204 
       
   205 function get_meta_color_portfolio( $args = array(), $value = false ) {
       
   206 
       
   207 	extract( $args ); ?>
       
   208 
       
   209 	<tr>
       
   210 		<th style="width:30%;">
       
   211 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;" ><?php echo $description; ?></span></label>
       
   212 		</th>
       
   213 		<td>
       
   214 			<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/functions/css/colorpicker.css" type="text/css" media="screen" />
       
   215 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/jquery.js"></script>
       
   216 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/colorpicker.js"></script>	
       
   217 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/eye.js"></script>
       
   218 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/layout.js?ver=1.0.2"></script>
       
   219 		   #<input type="text" maxlength="6" size="6" name="<?php echo $name; ?>"  id="colorpickerField1" value="<?php echo esc_html( $value ); ?>"  />
       
   220 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   221 		</td>
       
   222 	</tr>
       
   223 	<?php
       
   224 }
       
   225 
       
   226 function hybrid_save_meta_data_portfolio( $post_id ) {
       
   227 	global $post;
       
   228 
       
   229 		$meta_boxes = array_merge( hybrid_post_meta_boxes_portfolio() );
       
   230 
       
   231 	foreach ( $meta_boxes as $meta_box ) :
       
   232 
       
   233 		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
       
   234 			return $post_id;
       
   235 
       
   236 		if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
       
   237 			return $post_id;
       
   238 
       
   239 		elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
       
   240 			return $post_id;
       
   241 
       
   242 		$data = stripslashes( $_POST[$meta_box['name']] );
       
   243 
       
   244 		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
       
   245 			add_post_meta( $post_id, $meta_box['name'], $data, true );
       
   246 
       
   247 		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
       
   248 			update_post_meta( $post_id, $meta_box['name'], $data );
       
   249 
       
   250 		elseif ( $data == '' )
       
   251 			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
       
   252 
       
   253 	endforeach;
       
   254 	
       
   255 	$meta_boxes = array_merge( hybrid_post_meta_boxes_portfolio_video() );
       
   256 
       
   257 	foreach ( $meta_boxes as $meta_box ) :
       
   258 
       
   259 		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
       
   260 			return $post_id;
       
   261 
       
   262 		if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
       
   263 			return $post_id;
       
   264 
       
   265 		elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
       
   266 			return $post_id;
       
   267 
       
   268 		$data = stripslashes( $_POST[$meta_box['name']] );
       
   269 
       
   270 		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
       
   271 			add_post_meta( $post_id, $meta_box['name'], $data, true );
       
   272 
       
   273 		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
       
   274 			update_post_meta( $post_id, $meta_box['name'], $data );
       
   275 
       
   276 		elseif ( $data == '' )
       
   277 			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
       
   278 
       
   279 	endforeach;
       
   280 	
       
   281 }
       
   282 
       
   283 
       
   284 ?>