Guest User

Untitled

a guest
Jul 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.46 KB | None | 0 0
  1. <?php
  2.  
  3. class Cu_ET_Builder_Module_Fullwidth_Portfolio extends ET_Builder_Module_Type_PostBased {
  4. function init() {
  5. $this->name = esc_html__( 'Fullwidth Portfolio', 'et_builder' );
  6. $this->slug = 'et_pb_fullwidth_portfolio';
  7. $this->vb_support = 'on';
  8. $this->fullwidth = true;
  9.  
  10. // need to use global settings from the slider module
  11. $this->global_settings_slug = 'et_pb_portfolio';
  12.  
  13. $this->main_css_element = '%%order_class%%';
  14.  
  15. $this->settings_modal_toggles = array(
  16. 'general' => array(
  17. 'toggles' => array(
  18. 'main_content' => esc_html__( 'Content', 'et_builder' ),
  19. 'elements' => esc_html__( 'Elements', 'et_builder' ),
  20. ),
  21. ),
  22. 'advanced' => array(
  23. 'toggles' => array(
  24. 'layout' => esc_html__( 'Layout', 'et_builder' ),
  25. 'overlay' => esc_html__( 'Overlay', 'et_builder' ),
  26. 'rotation' => esc_html__( 'Rotation', 'et_builder' ),
  27. 'text' => array(
  28. 'title' => esc_html__( 'Text', 'et_builder' ),
  29. 'priority' => 49,
  30. ),
  31. 'image' => esc_html__( 'Image', 'et_builder' ),
  32. ),
  33. ),
  34. 'custom_css' => array(
  35. 'toggles' => array(
  36. 'animation' => array(
  37. 'title' => esc_html__( 'Animation', 'et_builder' ),
  38. 'priority' => 90,
  39. ),
  40. ),
  41. ),
  42. );
  43.  
  44. $this->advanced_fields = array(
  45. 'fonts' => array(
  46. 'portfolio_header' => array(
  47. 'label' => esc_html__( 'Portfolio Title', 'et_builder' ),
  48. 'css' => array(
  49. 'main' => "{$this->main_css_element} .et_pb_portfolio_title",
  50. 'important' => 'all',
  51. ),
  52. 'header_level' => array(
  53. 'default' => 'h2',
  54. ),
  55. 'font_size' => array(
  56. 'default' => '26px',
  57. ),
  58. 'line_height' => array(
  59. 'default' => '1em',
  60. ),
  61. ),
  62. 'title' => array(
  63. 'label' => esc_html__( 'Portfolio Item Title', 'et_builder' ),
  64. 'css' => array(
  65. 'main' => "{$this->main_css_element} h3, {$this->main_css_element} h1.et_pb_module_header, {$this->main_css_element} h2.et_pb_module_header, {$this->main_css_element} h4.et_pb_module_header, {$this->main_css_element} h5.et_pb_module_header, {$this->main_css_element} h6.et_pb_module_header",
  66. 'important' => 'all',
  67. ),
  68. 'header_level' => array(
  69. 'default' => 'h3',
  70. ),
  71. ),
  72. 'caption' => array(
  73. 'label' => esc_html__( 'Meta', 'et_builder' ),
  74. 'css' => array(
  75. 'main' => "{$this->main_css_element} .post-meta, {$this->main_css_element} .post-meta a",
  76. 'text_align' => "{$this->main_css_element} .et_pb_portfolio_image p.post-meta",
  77. ),
  78. ),
  79. ),
  80. 'background' => array(
  81. 'settings' => array(
  82. 'color' => 'alpha',
  83. ),
  84. ),
  85. 'borders' => array(
  86. 'default' => array(
  87. 'css' => array(
  88. 'main' => array(
  89. 'border_radii' => "{$this->main_css_element}",
  90. 'border_styles' => "{$this->main_css_element}",
  91. )
  92. ),
  93. ),
  94. 'image' => array(
  95. 'css' => array(
  96. 'main' => array(
  97. 'border_radii' => "{$this->main_css_element} .et_pb_portfolio_image",
  98. 'border_styles' => "{$this->main_css_element} .et_pb_portfolio_image",
  99. ),
  100. ),
  101. 'label_prefix' => esc_html__( 'Image', 'et_builder' ),
  102. 'tab_slug' => 'advanced',
  103. 'toggle_slug' => 'image',
  104. ),
  105. ),
  106. 'box_shadow' => array(
  107. 'default' => array(
  108. 'css' => array(
  109. 'custom_style' => true,
  110. ),
  111. ),
  112. 'image' => array(
  113. 'label' => esc_html__( 'Image Box Shadow', 'et_builder' ),
  114. 'option_category' => 'layout',
  115. 'tab_slug' => 'advanced',
  116. 'toggle_slug' => 'image',
  117. 'css' => array(
  118. 'main' => '%%order_class%% .et_pb_portfolio_image',
  119. 'custom_style' => true,
  120. ),
  121. 'default_on_fronts' => array(
  122. 'color' => '',
  123. 'position' => '',
  124. ),
  125. ),
  126. ),
  127. 'text' => array(
  128. 'use_background_layout' => true,
  129. 'css' => array(
  130. 'text_orientation' => '%%order_class%% h2, %%order_class%% .et_pb_portfolio_image h3, %%order_class%% .et_pb_portfolio_image p, %%order_class%% .et_pb_portfolio_title, %%order_class%% .et_pb_portfolio_image .et_pb_module_header',
  131. ),
  132. 'options' => array(
  133. 'text_orientation' => array(
  134. 'default_on_front' => 'center',
  135. ),
  136. 'background_layout' => array(
  137. 'default_on_front' => 'light',
  138. ),
  139. ),
  140. ),
  141. 'filters' => array(
  142. 'css' => array(
  143. 'main' => '%%order_class%%',
  144. ),
  145. 'child_filters_target' => array(
  146. 'tab_slug' => 'advanced',
  147. 'toggle_slug' => 'image',
  148. ),
  149. ),
  150. 'image' => array(
  151. 'css' => array(
  152. 'main' => '%%order_class%% .et_pb_portfolio_image',
  153. ),
  154. ),
  155. 'button' => false,
  156. );
  157.  
  158. $this->custom_css_fields = array(
  159. 'portfolio_title' => array(
  160. 'label' => esc_html__( 'Portfolio Title', 'et_builder' ),
  161. 'selector' => '> h2',
  162. ),
  163. 'portfolio_item' => array(
  164. 'label' => esc_html__( 'Portfolio Item', 'et_builder' ),
  165. 'selector' => '.et_pb_portfolio_item',
  166. ),
  167. 'portfolio_overlay' => array(
  168. 'label' => esc_html__( 'Item Overlay', 'et_builder' ),
  169. 'selector' => 'span.et_overlay',
  170. ),
  171. 'portfolio_item_title' => array(
  172. 'label' => esc_html__( 'Item Title', 'et_builder' ),
  173. 'selector' => '.meta h3',
  174. ),
  175. 'portfolio_meta' => array(
  176. 'label' => esc_html__( 'Meta', 'et_builder' ),
  177. 'selector' => '.meta p',
  178. ),
  179. 'portfolio_arrows' => array(
  180. 'label' => esc_html__( 'Navigation Arrows', 'et_builder' ),
  181. 'selector' => '.et-pb-slider-arrows a',
  182. ),
  183. );
  184.  
  185. $this->help_videos = array(
  186. array(
  187. 'id' => esc_html( 'Mug6LhcJQ5M' ),
  188. 'name' => esc_html__( 'An introduction to the Fullwidth Portfolio module', 'et_builder' ),
  189. ),
  190. );
  191. }
  192.  
  193. function get_fields() {
  194. $fields = array(
  195. 'title' => array(
  196. 'label' => esc_html__( 'Portfolio Title', 'et_builder' ),
  197. 'type' => 'text',
  198. 'option_category' => 'basic_option',
  199. 'description' => esc_html__( 'Title displayed above the portfolio.', 'et_builder' ),
  200. 'toggle_slug' => 'main_content',
  201. ),
  202. 'fullwidth' => array(
  203. 'label' => esc_html__( 'Layout', 'et_builder' ),
  204. 'type' => 'select',
  205. 'option_category' => 'layout',
  206. 'options' => array(
  207. 'on' => esc_html__( 'Carousel', 'et_builder' ),
  208. 'off' => esc_html__( 'Grid', 'et_builder' ),
  209. ),
  210. 'default_on_front' => 'on',
  211. 'affects' => array(
  212. 'auto',
  213. ),
  214. 'tab_slug' => 'advanced',
  215. 'toggle_slug' => 'layout',
  216. 'description' => esc_html__( 'Choose your desired portfolio layout style.', 'et_builder' ),
  217. ),
  218. 'include_categories' => array(
  219. 'label' => esc_html__( 'Include Categories', 'et_builder' ),
  220. 'type' => 'categories',
  221. 'option_category' => 'basic_option',
  222. 'description' => esc_html__( 'Select the categories that you would like to include in the feed.', 'et_builder' ),
  223. 'computed_affects' => array(
  224. '__projects',
  225. ),
  226. 'taxonomy_name' => 'project_category',
  227. 'toggle_slug' => 'main_content',
  228. ),
  229. 'posts_number' => array(
  230. 'label' => esc_html__( 'Posts Number', 'et_builder' ),
  231. 'type' => 'text',
  232. 'option_category' => 'configuration',
  233. 'description' => esc_html__( 'Control how many projects are displayed. Leave blank or use 0 to not limit the amount.', 'et_builder' ),
  234. 'computed_affects' => array(
  235. '__projects',
  236. ),
  237. 'toggle_slug' => 'main_content',
  238. ),
  239. 'show_title' => array(
  240. 'label' => esc_html__( 'Show Title', 'et_builder' ),
  241. 'type' => 'yes_no_button',
  242. 'option_category' => 'configuration',
  243. 'options' => array(
  244. 'on' => esc_html__( 'Yes', 'et_builder' ),
  245. 'off' => esc_html__( 'No', 'et_builder' ),
  246. ),
  247. 'default_on_front' => 'on',
  248. 'toggle_slug' => 'elements',
  249. 'description' => esc_html__( 'Turn project titles on or off.', 'et_builder' ),
  250. ),
  251. 'show_date' => array(
  252. 'label' => esc_html__( 'Show Date', 'et_builder' ),
  253. 'type' => 'yes_no_button',
  254. 'option_category' => 'configuration',
  255. 'options' => array(
  256. 'on' => esc_html__( 'Yes', 'et_builder' ),
  257. 'off' => esc_html__( 'No', 'et_builder' ),
  258. ),
  259. 'default_on_front' => 'on',
  260. 'toggle_slug' => 'elements',
  261. 'description' => esc_html__( 'Turn the date display on or off.', 'et_builder' ),
  262. ),
  263. 'zoom_icon_color' => array(
  264. 'label' => esc_html__( 'Zoom Icon Color', 'et_builder' ),
  265. 'type' => 'color-alpha',
  266. 'custom_color' => true,
  267. 'tab_slug' => 'advanced',
  268. 'toggle_slug' => 'overlay',
  269. ),
  270. 'hover_overlay_color' => array(
  271. 'label' => esc_html__( 'Hover Overlay Color', 'et_builder' ),
  272. 'type' => 'color-alpha',
  273. 'custom_color' => true,
  274. 'tab_slug' => 'advanced',
  275. 'toggle_slug' => 'overlay',
  276. ),
  277. 'hover_icon' => array(
  278. 'label' => esc_html__( 'Hover Icon Picker', 'et_builder' ),
  279. 'type' => 'select_icon',
  280. 'option_category' => 'configuration',
  281. 'class' => array( 'et-pb-font-icon' ),
  282. 'tab_slug' => 'advanced',
  283. 'toggle_slug' => 'overlay',
  284. ),
  285. '__projects' => array(
  286. 'type' => 'computed',
  287. 'computed_callback' => array( 'Cu_ET_Builder_Module_Fullwidth_Portfolio', 'get_portfolio_item' ),
  288. 'computed_depends_on' => array(
  289. 'posts_number',
  290. 'include_categories',
  291. ),
  292. ),
  293. );
  294.  
  295. return $fields;
  296. }
  297.  
  298. /**
  299. * Get portfolio objects for portfolio module
  300. *
  301. * @param array arguments that affect et_pb_portfolio query
  302. * @param array passed conditional tag for update process
  303. * @param array passed current page params
  304. * @return array portfolio item data
  305. */
  306. static function get_portfolio_item( $args = array(), $conditional_tags = array(), $current_page = array() ) {
  307. $defaults = array(
  308. 'posts_number' => '',
  309. 'include_categories' => '',
  310. );
  311.  
  312. $args = wp_parse_args( $args, $defaults );
  313.  
  314. $query_args = array(
  315. 'post_type' => 'project',
  316. 'post_status' => 'publish',
  317. );
  318.  
  319. if ( is_numeric( $args['posts_number'] ) && $args['posts_number'] > 0 ) {
  320. $query_args['posts_per_page'] = $args['posts_number'];
  321. } else {
  322. $query_args['nopaging'] = true;
  323. }
  324.  
  325. $include_categories = self::filter_invalid_term_ids( explode( ',', $args['include_categories'] ), 'project_category' );
  326.  
  327. if ( ! empty( $include_categories ) ) {
  328. $query_args['tax_query'] = array(
  329. array(
  330. 'taxonomy' => 'project_category',
  331. 'field' => 'id',
  332. 'terms' => $include_categories,
  333. 'operator' => 'IN'
  334. )
  335. );
  336. }
  337.  
  338. // Get portfolio query
  339. $query = new WP_Query( $query_args );
  340.  
  341. // Format portfolio output, add supplementary data
  342. $width = (int) apply_filters( 'et_pb_portfolio_image_width', 510 );
  343. $height = (int) apply_filters( 'et_pb_portfolio_image_height', 382 );
  344.  
  345. if( $query->post_count > 0 ) {
  346. $post_index = 0;
  347. while ( $query->have_posts() ) {
  348. $query->the_post();
  349.  
  350. // Get thumbnail
  351. $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), array( $width, $height ) );
  352.  
  353. if ( isset( $thumbnail[2] ) && isset( $thumbnail[1] ) ) {
  354. $orientation = ( $thumbnail[2] > $thumbnail[1] ) ? 'portrait' : 'landscape';
  355. } else {
  356. $orientation = false;
  357. }
  358.  
  359. // Append value to query post
  360. $query->posts[ $post_index ]->post_permalink = get_permalink();
  361. $query->posts[ $post_index ]->post_thumbnail = isset( $thumbnail[0] ) ? $thumbnail[0] : false;
  362. $query->posts[ $post_index ]->post_thumbnail_orientation = $orientation;
  363. $query->posts[ $post_index ]->post_date_readable = get_the_date();
  364. $query->posts[ $post_index ]->post_class_name = get_post_class( 'et_pb_portfolio_item et_pb_grid_item ' );
  365.  
  366. $post_index++;
  367. }
  368. } else if ( wp_doing_ajax() ) {
  369. // This is for the VB
  370. $posts = '<div class="et_pb_row et_pb_no_results">';
  371. $posts .= self::get_no_results_template();
  372. $posts .= '</div>';
  373. $query = array( 'posts' => $posts );
  374. }
  375.  
  376. wp_reset_postdata();
  377.  
  378. return $query;
  379. }
  380.  
  381. function render( $attrs, $content = null, $render_slug ) {
  382. $title = $this->props['title'];
  383. $fullwidth = $this->props['fullwidth'];
  384. $include_categories = $this->props['include_categories'];
  385. $posts_number = $this->props['posts_number'];
  386. $show_title = $this->props['show_title'];
  387. $show_date = $this->props['show_date'];
  388. $background_layout = $this->props['background_layout'];
  389. $auto = $this->props['auto'];
  390. $auto_speed = $this->props['auto_speed'];
  391. $zoom_icon_color = $this->props['zoom_icon_color'];
  392. $hover_overlay_color = $this->props['hover_overlay_color'];
  393. $hover_icon = $this->props['hover_icon'];
  394. $header_level = $this->props['title_level'];
  395. $portfolio_header = $this->props['portfolio_header_level'];
  396.  
  397. $zoom_and_hover_selector = '.et_pb_fullwidth_portfolio%%order_class%% .et_pb_portfolio_image';
  398.  
  399. if ( '' !== $zoom_icon_color ) {
  400. ET_Builder_Element::set_style( $render_slug, array(
  401. 'selector' => "{$zoom_and_hover_selector} .et_overlay:before",
  402. 'declaration' => sprintf(
  403. 'color: %1$s !important;',
  404. esc_html( $zoom_icon_color )
  405. ),
  406. ) );
  407. }
  408.  
  409. if ( '' !== $hover_overlay_color ) {
  410. ET_Builder_Element::set_style( $render_slug, array(
  411. 'selector' => "{$zoom_and_hover_selector} .et_overlay",
  412. 'declaration' => sprintf(
  413. 'background-color: %1$s;
  414. border-color: %1$s;',
  415. esc_html( $hover_overlay_color )
  416. ),
  417. ) );
  418. }
  419.  
  420. $args = array();
  421. if ( is_numeric( $posts_number ) && $posts_number > 0 ) {
  422. $args['posts_per_page'] = $posts_number;
  423. } else {
  424. $args['nopaging'] = true;
  425. }
  426.  
  427. if ( '' !== $include_categories ) {
  428. $args['tax_query'] = array(
  429. array(
  430. 'taxonomy' => 'project_category',
  431. 'field' => 'id',
  432. 'terms' => explode( ',', $include_categories ),
  433. 'operator' => 'IN'
  434. )
  435. );
  436. }
  437.  
  438. $projects = self::get_portfolio_item( array(
  439. 'posts_number' => $posts_number,
  440. 'include_categories' => $include_categories,
  441. ) );
  442.  
  443. ob_start();
  444. if( $projects->post_count > 0 ) {
  445. while ( $projects->have_posts() ) {
  446. $projects->the_post();
  447. ?>
  448. <div id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_portfolio_item et_pb_grid_item ' ); ?>>
  449. <?php
  450. $thumb = '';
  451.  
  452. $width = 510;
  453. $width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  454.  
  455. $height = 382;
  456. $height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  457.  
  458. list($thumb_src, $thumb_width, $thumb_height) = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), array( $width, $height ) );
  459.  
  460. $orientation = ( $thumb_height > $thumb_width ) ? 'portrait' : 'landscape';
  461.  
  462. if ( '' !== $thumb_src ) : ?>
  463. <div class="et_pb_portfolio_image ch-item <?php echo esc_attr( $orientation ); ?>">
  464. <div class="ch-info-wrap">
  465. <a href="<?php the_permalink(); ?>">
  466. <div class="ch-info">
  467. <div style="background-image:url(<?php echo esc_attr( $thumb_src ); ?>);" class="ch-info-front"></div>
  468. <div class="ch-info-back">
  469. <?php if ( 'on' === $show_title ) : ?>
  470. <<?php echo et_pb_process_header_level( $header_level, 'h3' ) ?> class="et_pb_module_header"><?php the_title(); ?></<?php echo et_pb_process_header_level( $header_level, 'h3' ) ?>>
  471. <?php endif; ?>
  472.  
  473. <?php if ( 'on' === $show_date ) : ?>
  474. <p class="post-meta"><?php echo get_the_date(); ?></p>
  475. <?php endif; ?>
  476. </div>
  477. </div>
  478. </a>
  479. </div>
  480. </div>
  481. <?php endif; ?>
  482. </div>
  483. <?php
  484. }
  485. }
  486.  
  487. wp_reset_postdata();
  488.  
  489. if ( ! $posts = ob_get_clean() ) {
  490. $posts = '<div class="et_pb_row et_pb_no_results">';
  491. $posts .= self::get_no_results_template();
  492. $posts .= '</div>';
  493. }
  494.  
  495. $video_background = $this->video_background();
  496. $parallax_image_background = $this->get_parallax_image_background();
  497.  
  498. // Images: Add CSS Filters and Mix Blend Mode rules (if set)
  499. if ( isset( $this->advanced_fields['image']['css'] ) ) {
  500. $this->add_classname( $this->generate_css_filters(
  501. $render_slug,
  502. 'child_',
  503. self::$data_utils->array_get( $this->advanced_fields['image']['css'], 'main', '%%order_class%%' )
  504. ) );
  505. }
  506.  
  507. $portfolio_title = sprintf( '<%1$s class="et_pb_portfolio_title">%2$s</%1$s>', et_pb_process_header_level( $portfolio_header, 'h2' ), esc_html( $title ) );
  508.  
  509. // Module classnames
  510. $this->add_classname( "et_pb_bg_layout_{$background_layout}" );
  511.  
  512. if ( 'on' === $fullwidth ) {
  513. $this->add_classname( 'et_pb_fullwidth_portfolio_carousel' );
  514. } else {
  515. $this->add_classname( array(
  516. 'et_pb_fullwidth_portfolio_grid',
  517. 'clearfix',
  518. ) );
  519. }
  520.  
  521. $output = sprintf(
  522. '<div%3$s class="%1$s" data-auto-rotate="%4$s" data-auto-rotate-speed="%5$s">
  523. %8$s
  524. %7$s
  525. %6$s
  526. <div class="et_pb_portfolio_items clearfix" data-portfolio-columns="">
  527. %2$s
  528. </div><!-- .et_pb_portfolio_items -->
  529. </div> <!-- .et_pb_fullwidth_portfolio -->',
  530. $this->module_classname( $render_slug ),
  531. $posts,
  532. $this->module_id(),
  533. ( '' !== $auto && in_array( $auto, array('on', 'off') ) ? esc_attr( $auto ) : 'off' ),
  534. ( '' !== $auto_speed && is_numeric( $auto_speed ) ? esc_attr( $auto_speed ) : '7000' ),
  535. ( '' !== $title ? $portfolio_title : '' ),
  536. $video_background,
  537. $parallax_image_background
  538. );
  539.  
  540. return $output;
  541. }
  542. }
  543.  
  544. new Cu_ET_Builder_Module_Fullwidth_Portfolio;
Add Comment
Please, Sign In to add comment