post-carousel.php 13.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
<?php

/**
 * @class FLPostCarouselModule
 */
class FLPostCarouselModule extends FLBuilderModule {

	/**
	 * @method __construct
	 */
	public function __construct()
	{
		parent::__construct(array(
			'name'          	=> __('Posts Carousel', 'fl-builder'),
			'description'   	=> __('Display a carousel of your WordPress posts.', 'fl-builder'),
			'category'      	=> __('高级模块', 'fl-builder'),
			'editor_export' 	=> false,
			'partial_refresh'	=> true
		));

		$this->add_css('jquery-bxslider');
		$this->add_js('jquery-bxslider');
	}

	/**
	 * Remove pagination parameters
	 *
	 * @param array $query_args 	Generated query args to override
	 * @return array 				Updated query args
	 */
	public function remove_pagination_args($query_args){
		$query_args['paged'] = 0;
		$query_args['offset'] = isset($this->settings->offset) ? $this->settings->offset : 0;
		return $query_args;
	}


	/**
	 * Full attachment image url.
	 *
	 * Gets a post ID and returns the url for the 'full' size of the attachment
	 * set as featured image.
	 * 
	 * @param  int $id 	 The post ID.
	 * @since  1.5.9
	 * @return string    The featured image url for the 'full' size.
	 */
	protected function _get_uncropped_url( $id ){
		$thumb_id = get_post_thumbnail_id( $id );
		$size = isset( $this->settings->image_size ) ? $this->settings->image_size : 'medium';
		$img = wp_get_attachment_image_src( $thumb_id, $size );
		return $img[0];
	}


	/**
	 * Get the featured image data.
	 *
	 * Gets a post ID and returns an array containing the featured image data.
	 * 
	 * @param  int $id 	 The post ID.
	 * @since  1.5.9
	 * @return array    The image data.
	 */	
	protected function _get_img_data( $id ){

		$thumb_id = get_post_thumbnail_id( $id );

		return FLBuilderPhoto::get_attachment_data( $thumb_id );

	}


	/**
	 * Render thumbnail image for mobile.
	 *
	 * Get's the post ID and renders the html markup for the featured image
	 * in the desired cropped size.
	 * 
	 * @param  int $id    The post ID.
	 * @since  1.5.9
	 * @return void
	 */
	public function render_img( $id = null ) {

		// check if image_type is set
		if( isset( $this->settings->show_image ) && $this->settings->show_image == 1 ){

			// get image source and data
			$src = $this->_get_uncropped_url( $id );
			$photo_data = $this->_get_img_data( $id );

			// set params
			$photo_settings = array(
				'align'         => 'center',
				'link_type'     => 'url',
				'crop'          => $this->settings->crop,
				'photo'         => $photo_data,
				'photo_src'     => $src,
				'photo_source'  => 'library',
				'attributes'	=> array( 'data-no-lazy' => 1 )
			);

			// if link id is provided, set link_url param
			if( $id ){
				$photo_settings['link_url'] = get_the_permalink( $id );
			}

			// render image
			FLBuilder::render_module_html( 'photo', $photo_settings );

		}

	}

}

/**
 * Register the module and its form settings.
 */
FLBuilder::register_module('FLPostCarouselModule', array(
	'slider'      => array(
		'title'         => __('Slider', 'fl-builder'),
		'sections'      => array(
			'general'       => array(
				'title'         => '',
				'fields'        => array(
					'layout'     => array(
						'type'          => 'select',
						'label'         => __('Layout', 'fl-builder'),
						'default'       => 'grid',
						'options'       => array(
							'grid'          => __('Grid', 'fl-builder'),
							'gallery'      	=> __('Gallery', 'fl-builder'),
						),
						'toggle'		=> array(
							'grid'			=> array(
								'sections'		=> array( 'content' ),
								'fields'		=> array( 'show_image', 'text_color', 'link_color', 'equal_height' )
							),
							'gallery'		=> array(
								'sections'		=> array( 'icons' ),
								'fields'		=> array( 'hover_transition' )
							),
						)
					),
					'auto_play'     => array(
						'type'          => 'select',
						'label'         => __('Auto Play', 'fl-builder'),
						'default'       => 'true',
						'options'       => array(
							'false'         => __('No', 'fl-builder'),
							'true'          => __('Yes', 'fl-builder')
						)
					),
					'speed'         => array(
						'type'          => 'text',
						'label'         => __('Delay', 'fl-builder'),
						'default'       => '5',
						'size'          => '5',
						'description'   => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
					),
					'carousel_loop'     => array(
						'type'          => 'select',
						'label'         => __('Loop', 'fl-builder'),
						'default'       => 'false',
						'options'       => array(
							'false'            	=> __('No', 'fl-builder'),
							'true'				=> __('Yes', 'fl-builder'),
						)
					),
					'transition_duration' => array(
						'type'          => 'text',
						'label'         => __('Transition Speed', 'fl-builder'),
						'default'       => '1',
						'size'          => '5',
						'description'   => _x( 'seconds', 'Value unit for form field of time in seconds. Such as: "5 seconds"', 'fl-builder' )
					),
					'posts_per_page' => array(
						'type'          => 'text',
						'label'         => __('Number of Posts', 'fl-builder'),
						'default'       => '10',
						'size'          => '4'
					),
				)
			),
			'controls'       => array(
				'title'         => __('Slider Controls', 'fl-builder'),
				'fields'        => array(
					'pagination'     => array(
						'type'          => 'select',
						'label'         => __('Show Dots', 'fl-builder'),
						'default'       => 'yes',
						'options'       => array(
							'no'			=> __('No', 'fl-builder'),
							'yes'       	=> __('Yes', 'fl-builder'),
						)
					),
					'navigation'     => array(
						'type'          => 'select',
						'label'         => __('Show Arrows', 'fl-builder'),
						'default'       => 'no',
						'options'       => array(
							'no'            => __('No', 'fl-builder'),
							'yes'        	=> __('Yes', 'fl-builder'),
						),
						'toggle'		=> array(
							'yes'			=> array(
								'fields'		=> array( 'nav_arrow_color' )
							)
						)
					),
				)
			),

		)
	),
	'layout'        => array(
		'title'         => __('Layout', 'fl-builder'),
		'sections'      => array(
			'posts'          => array(
				'title'         => __('Posts', 'fl-builder'),
				'fields'        => array(
					'slide_width'  => array(
						'type'          => 'text',
						'label'         => __('Post Max Width', 'fl-builder'),
						'default'       => '300',
						'maxlength'     => '3',
						'size'          => '4',
						'description'   => 'px'
					),
					'space_between'  => array(
						'type'          => 'text',
						'label'         => __('Post Spacing', 'fl-builder'),
						'default'       => '30',
						'maxlength'     => '3',
						'size'          => '4',
						'description'   => 'px'
					),
					'equal_height'   => array(
						'type'          => 'select',
						'label'         => __('Equalize Column Heights', 'fl-builder'),
						'default'       => 'no',
						'options'       => array(
							'no'			=> __('No', 'fl-builder'),
							'yes'       	=> __('Yes', 'fl-builder'),
						)
					),
					'hover_transition'   => array(
						'type'          => 'select',
						'label'         => __('Post Hover Transition', 'fl-builder'),
						'default'       => 'fade',
						'options'       => array(
							'fade'			=> __('Fade', 'fl-builder'),
							'slide-up'     	=> __('Slide Up', 'fl-builder'),
							'slide-down'   	=> __('Slide Down', 'fl-builder'),
							'scale-up'   	=> __('Scale Up', 'fl-builder'),
							'scale-down'   	=> __('Scale Down', 'fl-builder'),
						)
					),
				)
			),
			'image'        => array(
				'title'         => __( 'Featured Image', 'fl-builder' ),
				'fields'        => array(
					'show_image'    => array(
						'type'          => 'select',
						'label'         => __('Image', 'fl-builder'),
						'default'       => '1',
						'options'       => array(
							'1'             => __( 'Show', 'fl-builder' ),
							'0'             => __( 'Hide', 'fl-builder' )
						),
						'toggle'        => array(
							'1'             => array(
								'fields'        => array( 'image_size', 'crop',  )
							)
						)
					),
					'image_size'    => array(
						'type'          => 'photo-sizes',
						'label'         => __( 'Size', 'fl-builder' ),
						'default'       => 'medium'
					),
					'crop'    => array(
						'type'          => 'select',
						'label'         => __( 'Crop', 'fl-builder' ),
						'default'       => 'landscape',
						'options'       => array(
							''              => _x( 'None', 'Photo Crop.', 'fl-builder' ),
							'landscape'     => __( 'Landscape', 'fl-builder' ),
							'panorama'      => __( 'Panorama', 'fl-builder' ),
							'portrait'      => __( 'Portrait', 'fl-builder' ),
							'square'        => __( 'Square', 'fl-builder' ),
							'circle'        => __( 'Circle', 'fl-builder' )
						)
					),

				)
			),
			'icons'          => array(
				'title'         => __('Icons', 'fl-builder'),
				'fields'        => array(
					'post_has_icon'   => array(
						'type'          => 'select',
						'label'         => __('Use Icon for Posts', 'fl-builder'),
						'default'       => 'no',
						'options'       => array(
							'yes'			=> __('Yes', 'fl-builder'),
							'no' 	      	=> __('No', 'fl-builder'),
						),
						'toggle'		=> array(
							'yes'			=> array(
								'fields'		=> array( 'post_icon', 'post_icon_position', 'post_icon_color', 'post_icon_size' )
							)
						),
					),
					'post_icon'  => array(
						'type'          => 'icon',
						'label'         => __('Post Icon', 'fl-builder'),
					),
					'post_icon_position'   => array(
						'type'          => 'select',
						'label'         => __('Post Icon Position', 'fl-builder'),
						'default'       => 'above',
						'options'       => array(
							'above'			=> __('Above Text', 'fl-builder'),
							'below'       	=> __('Below Text', 'fl-builder'),
						)
					),
					'post_icon_size'  => array(
						'type'          => 'text',
						'label'         => __('Post Icon Size', 'fl-builder'),
						'default'       => '24',
						'maxlength'     => '3',
						'size'          => '4',
						'description'   => 'px'
					),
				)
			),
			'info'          => array(
				'title'         => __( 'Post Info', 'fl-builder' ),
				'fields'        => array(
					'show_author'   => array(
						'type'          => 'select',
						'label'         => __('Author', 'fl-builder'),
						'default'       => '1',
						'options'       => array(
							'1'             => __('Show', 'fl-builder'),
							'0'             => __('Hide', 'fl-builder')
						)
					),
					'show_date'     => array(
						'type'          => 'select',
						'label'         => __('Date', 'fl-builder'),
						'default'       => '1',
						'options'       => array(
							'1'             => __('Show', 'fl-builder'),
							'0'             => __('Hide', 'fl-builder')
						),
						'toggle'        => array(
							'1'             => array(
								'fields'        => array('date_format')
							)
						)
					),
					'date_format'   => array(
						'type'          => 'select',
						'label'         => __('Date Format', 'fl-builder'),
						'default'       => 'default',
						'options'       => array(
							'default'		=> __('Default', 'fl-builder'),
							'M j, Y'        => date('M j, Y'),
							'F j, Y'        => date('F j, Y'),
							'm/d/Y'         => date('m/d/Y'),
							'm-d-Y'         => date('m-d-Y'),
							'd M Y'         => date('d M Y'),
							'd F Y'         => date('d F Y'),
							'Y-m-d'         => date('Y-m-d'),
							'Y/m/d'         => date('Y/m/d'),
						)
					),
				)
			),
			'content'       => array(
				'title'         => __( 'Content', 'fl-builder' ),
				'fields'        => array(
					'show_content'  => array(
						'type'          => 'select',
						'label'         => __('Content', 'fl-builder'),
						'default'       => '0',
						'options'       => array(
							'1'             => __('Show', 'fl-builder'),
							'0'             => __('Hide', 'fl-builder')
						)
					),
					'show_more_link' => array(
						'type'          => 'select',
						'label'         => __('More Link', 'fl-builder'),
						'default'       => '0',
						'options'       => array(
							'1'             => __('Show', 'fl-builder'),
							'0'             => __('Hide', 'fl-builder')
						)
					),
					'more_link_text' => array(
						'type'          => 'text',
						'label'         => __('More Link Text', 'fl-builder'),
						'default'       => __('Read More', 'fl-builder'),
					),
				)
			)
		)
	),
	'style'         => array( // Tab
		'title'         => __('Style', 'fl-builder'), // Tab title
		'sections'      => array( // Tab Sections
			'text_style'    => array(
				'title'         => __('Colors', 'fl-builder'),
				'fields'        => array(
					'text_color'    => array(
						'type'          => 'color',
						'label'         => __('Text Color', 'fl-builder'),
						'show_reset'    => true
					),
					'link_color'    => array(
						'type'          => 'color',
						'label'         => __('Link Color', 'fl-builder'),
						'show_reset'    => true
					),
					'link_hover_color' => array(
						'type'          => 'color',
						'label'         => __('Link Hover Color', 'fl-builder'),
						'show_reset'    => true
					),
					'text_bg_color' => array(
						'type'          => 'color',
						'label'         => __('Text Background Color', 'fl-builder'),
						'default'       => 'ffffff',
						'help'          => __('The color applies to the overlay behind text over the background selections.', 'fl-builder'),
						'show_reset'    => true
					),
					'post_icon_color' => array(
						'type'          => 'color',
						'label'         => __('Post Icon Color', 'fl-builder'),
						'show_reset'    => true
					),
					'text_bg_opacity' => array(
						'type'          => 'text',
						'label'         => __('Text Background Opacity', 'fl-builder'),
						'default'       => '100',
						'maxlength'     => '3',
						'size'          => '4',
						'description'   => '%'
					),
				)
			)
		)
	),

	'content'   => array(
		'title'         => __('Content', 'fl-builder'),
		'file'          => FL_BUILDER_DIR . 'includes/loop-settings.php',
	)
));