Advertisement
Guest User

portfolio.php

a guest
Aug 21st, 2018
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.49 KB | None | 0 0
  1. <?php
  2. /**
  3. * Portfolio Grid
  4. *
  5. * Creates a grid of portfolio excerpts
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
  8.  
  9.  
  10. if ( !class_exists( 'avia_sc_portfolio' ) )
  11. {
  12. class avia_sc_portfolio extends aviaShortcodeTemplate
  13. {
  14. /**
  15. * Create the config array for the shortcode button
  16. */
  17. function shortcode_insert_button()
  18. {
  19. $this->config['self_closing'] = 'yes';
  20.  
  21. $this->config['name'] = __('Portfolio Grid', 'avia_framework' );
  22. $this->config['tab'] = __('Content Elements', 'avia_framework' );
  23. $this->config['icon'] = AviaBuilder::$path['imagesURL']."sc-portfolio.png";
  24. $this->config['order'] = 38;
  25. $this->config['target'] = 'avia-target-insert';
  26. $this->config['shortcode'] = 'av_portfolio';
  27. $this->config['tooltip'] = __('Creates a grid of portfolio excerpts', 'avia_framework' );
  28. }
  29.  
  30. function extra_assets()
  31. {
  32. if(!is_admin() && !current_theme_supports('avia_no_session_support') && !session_id()) session_start();
  33. }
  34.  
  35. /**
  36. * Popup Elements
  37. *
  38. * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  39. * opens a modal window that allows to edit the element properties
  40. *
  41. * @return void
  42. */
  43. function popup_elements()
  44. {
  45. $this->elements = array(
  46.  
  47. array(
  48. "type" => "tab_container", 'nodescription' => true
  49. ),
  50.  
  51. array(
  52. "type" => "tab",
  53. "name" => __("Content" , 'avia_framework'),
  54. 'nodescription' => true
  55. ),
  56.  
  57.  
  58. array( "name" => __("Which categories should be used for the portfolio?", 'avia_framework' ),
  59. "desc" => __("You can select multiple categories here. The Page will then show posts from only those categories.", 'avia_framework' ),
  60. "id" => "categories",
  61. "type" => "select",
  62. "multiple" => 6,
  63. "taxonomy" => "portfolio_entries",
  64. "subtype" => "cat"),
  65. /*
  66. array(
  67. "name" => __("Style?", 'avia_framework' ),
  68. "desc" => __("Choose the style of the entries here", 'avia_framework' ),
  69. "id" => "style",
  70. "type" => "select",
  71. "std" => "",
  72. "subtype" => array( __('Default Style', 'avia_framework' ) => '',
  73. __('Circle Image Stlye', 'avia_framework' )=>'grid-circle')),
  74. */
  75.  
  76. array(
  77. "name" => __("Columns", 'avia_framework' ),
  78. "desc" => __("How many columns should be displayed?", 'avia_framework' ),
  79. "id" => "columns",
  80. "type" => "select",
  81. "std" => "4",
  82. "subtype" => array( __('1 Column', 'avia_framework' )=>'1',
  83. __('2 Columns', 'avia_framework' )=>'2',
  84. __('3 Columns', 'avia_framework' )=>'3',
  85. __('4 Columns', 'avia_framework' )=>'4',
  86. __('5 Columns', 'avia_framework' )=>'5',
  87. __('6 Columns', 'avia_framework' )=>'6',
  88. )),
  89.  
  90. array(
  91. "name" => __("1 Column layout", 'avia_framework' ),
  92. "desc" => __("Choose the 1 column layout", 'avia_framework' ),
  93. "id" => "one_column_template",
  94. "type" => "select",
  95. "required" => array('columns','equals','1'),
  96. "std" => "special",
  97. "subtype" => array(
  98. __('Use special 1 column layout (side by side)', 'avia_framework' ) =>'special',
  99. __('Use default portfolio layout', 'avia_framework' ) =>'default')),
  100.  
  101. array(
  102. "name" => __("Post Number", 'avia_framework' ),
  103. "desc" => __("How many items should be displayed per page?", 'avia_framework' ),
  104. "id" => "items",
  105. "type" => "select",
  106. "std" => "16",
  107. "subtype" => AviaHtmlHelper::number_array(1,100,1, array('All'=>'-1'))),
  108.  
  109. array(
  110. "name" => __("Excerpt", 'avia_framework' ),
  111. "desc" => __("Display Excerpt and Title below the preview image?", 'avia_framework' ),
  112. "id" => "contents",
  113. "type" => "select",
  114. "std" => "yes",
  115. "subtype" => array(
  116. __('Title and Excerpt', 'avia_framework' ) =>'excerpt',
  117. __('Only Title', 'avia_framework' ) =>'title',
  118. __('Only excerpt', 'avia_framework' ) =>'only_excerpt',
  119. __('No Title and no excerpt', 'avia_framework' ) =>'no')),
  120.  
  121. array(
  122. "name" => __("Portfolio Grid Image Size", 'avia_framework' ),
  123. "desc" => __("Set the image size of the Portfolio Grid images", 'avia_framework' ),
  124. "id" => "preview_mode",
  125. "type" => "select",
  126. "std" => "auto",
  127. "subtype" => array(__('Set the Portfolio Grid image size automatically based on column or layout width','avia_framework' ) =>'auto',__('Choose the Portfolio Grid image size manually (select thumbnail size)','avia_framework' ) =>'custom')),
  128.  
  129. array(
  130. "name" => __("Select custom image size", 'avia_framework' ),
  131. "desc" => __("Choose image size for Portfolio Grid Images", 'avia_framework' ) . "<br/><small>" . __("(Note: Images will be scaled to fit for the amount of columns chosen above)", 'avia_framework' )."</small>",
  132. "id" => "image_size",
  133. "type" => "select",
  134. "required" => array('preview_mode','equals','custom'),
  135. "std" => "portfolio",
  136. "subtype" => AviaHelper::get_registered_image_sizes(array('logo','thumbnail','widget'))
  137. ),
  138.  
  139. array(
  140. "name" => __("Link Handling", 'avia_framework' ),
  141. "desc" => __("When clicking on a portfolio item you can choose to open the link to the single entry, open a preview (aka AJAX Portfolio) or show a bigger version of the image in a lightbox overlay", 'avia_framework' ),
  142. "id" => "linking",
  143. "type" => "select",
  144. "std" => "",
  145. "subtype" => array(
  146. __('Open the entry on a new page', 'avia_framework' ) =>'',
  147. __('Open a preview of the entry (known as AJAX Portfolio)', 'avia_framework' ) =>'ajax',
  148. __('Display the big image in a lightbox', 'avia_framework' ) =>'lightbox')),
  149.  
  150. array(
  151. "name" => __("Sortable?", 'avia_framework' ),
  152. "desc" => __("Should the sorting options based on categories be displayed?", 'avia_framework' ),
  153. "id" => "sort",
  154. "type" => "select",
  155. "std" => "yes",
  156. "subtype" => array(
  157. __('Yes, display sort options', 'avia_framework' ) => 'yes',
  158. __('Yes, display sort options and currently active categories', 'avia_framework' ) => 'yes-tax',
  159. __('No, do not display sort options', 'avia_framework' ) => 'no')),
  160.  
  161. array(
  162. "name" => __("Pagination", 'avia_framework' ),
  163. "desc" => __("Should a pagination be displayed?", 'avia_framework' ),
  164. "id" => "paginate",
  165. "type" => "select",
  166. "std" => "yes",
  167. "subtype" => array(
  168. __('yes', 'avia_framework' ) =>'yes',
  169. __('no', 'avia_framework' ) =>'no')),
  170.  
  171. array(
  172. "name" => __("Order by",'avia_framework' ),
  173. "desc" => __("You can order the result by various attributes like creation date, title, author etc", 'avia_framework' ),
  174. "id" => "query_orderby",
  175. "type" => "select",
  176. "std" => "date",
  177. "subtype" => array(
  178. __('Date', 'avia_framework' ) =>'date',
  179. __('Title', 'avia_framework' ) =>'title',
  180. __('Random', 'avia_framework' ) =>'rand',
  181. __('Author', 'avia_framework' ) =>'author',
  182. __('Name (Post Slug)', 'avia_framework' ) =>'name',
  183. __('Last modified', 'avia_framework' ) =>'modified',
  184. __('Comment Count', 'avia_framework' ) =>'comment_count',
  185. __('Page Order', 'avia_framework' ) =>'menu_order')
  186. ),
  187.  
  188. array(
  189. "name" => __("Display order",'avia_framework' ),
  190. "desc" => __("Display the results either in ascending or descending order", 'avia_framework' ),
  191. "id" => "query_order",
  192. "type" => "select",
  193. "std" => "DESC",
  194. "subtype" => array(
  195. __('Ascending Order', 'avia_framework' ) =>'ASC',
  196. __('Descending Order', 'avia_framework' ) =>'DESC')
  197. ),
  198.  
  199. array(
  200. "type" => "close_div",
  201. 'nodescription' => true
  202. ),
  203.  
  204.  
  205. array(
  206. "type" => "tab",
  207. "name" => __("Screen Options",'avia_framework' ),
  208. 'nodescription' => true
  209. ),
  210.  
  211.  
  212. array(
  213. "name" => __("Element Visibility",'avia_framework' ),
  214. "desc" => __("Set the visibility for this element, based on the device screensize.", 'avia_framework' ),
  215. "type" => "heading",
  216. "description_class" => "av-builder-note av-neutral",
  217. ),
  218.  
  219. array(
  220. "desc" => __("Hide on large screens (wider than 990px - eg: Desktop)", 'avia_framework'),
  221. "id" => "av-desktop-hide",
  222. "std" => "",
  223. "container_class" => 'av-multi-checkbox',
  224. "type" => "checkbox"),
  225.  
  226. array(
  227.  
  228. "desc" => __("Hide on medium sized screens (between 768px and 989px - eg: Tablet Landscape)", 'avia_framework'),
  229. "id" => "av-medium-hide",
  230. "std" => "",
  231. "container_class" => 'av-multi-checkbox',
  232. "type" => "checkbox"),
  233.  
  234. array(
  235.  
  236. "desc" => __("Hide on small screens (between 480px and 767px - eg: Tablet Portrait)", 'avia_framework'),
  237. "id" => "av-small-hide",
  238. "std" => "",
  239. "container_class" => 'av-multi-checkbox',
  240. "type" => "checkbox"),
  241.  
  242. array(
  243.  
  244. "desc" => __("Hide on very small screens (smaller than 479px - eg: Smartphone Portrait)", 'avia_framework'),
  245. "id" => "av-mini-hide",
  246. "std" => "",
  247. "container_class" => 'av-multi-checkbox',
  248. "type" => "checkbox"),
  249.  
  250. array(
  251. "name" => __("Element Columns",'avia_framework' ),
  252. "desc" =>
  253. __("Set the column count for this element, based on the device screensize.", 'avia_framework' )
  254. ,
  255. "type" => "heading",
  256. "description_class" => "av-builder-note av-neutral",
  257. ),
  258.  
  259.  
  260. array( "name" => __("Column count for medium sized screens", 'avia_framework' ),
  261. "id" => "av-medium-columns",
  262. "type" => "select",
  263. "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  264. "std" => ""),
  265.  
  266. array( "name" => __("Column count for small screens", 'avia_framework' ),
  267. "id" => "av-small-columns",
  268. "type" => "select",
  269. "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  270. "std" => ""),
  271.  
  272. array( "name" => __("Column count for very small screens", 'avia_framework' ),
  273. "id" => "av-mini-columns",
  274. "type" => "select",
  275. "subtype" => AviaHtmlHelper::number_array(1,4,1, array( __("Default", 'avia_framework' )=>'')),
  276. "std" => ""),
  277.  
  278.  
  279.  
  280.  
  281. array(
  282. "type" => "close_div",
  283. 'nodescription' => true
  284. ),
  285.  
  286.  
  287.  
  288.  
  289. array(
  290. "type" => "close_div",
  291. 'nodescription' => true
  292. ),
  293.  
  294.  
  295. );
  296.  
  297.  
  298. if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  299. {
  300. $this->elements[2] = array(
  301. "name" => __("Which Entries?", 'avia_framework' ),
  302. "desc" => __("Select which entries should be displayed by selecting a taxonomy", 'avia_framework' ),
  303. "id" => "link",
  304. "fetchTMPL" => true,
  305. "type" => "linkpicker",
  306. "subtype" => array( __('Display Entries from:', 'avia_framework' )=>'taxonomy'),
  307. "multiple" => 6,
  308. "std" => "category");
  309.  
  310.  
  311. if(current_theme_supports('add_avia_builder_post_type_option'))
  312. {
  313. $element = array(
  314. "name" => __("Select Post Type", 'avia_framework' ),
  315. "desc" => __("Select which post types should be used. Note that your taxonomy will be ignored if you do not select an assign post type.
  316. If yo don't select post type all registered post types will be used", 'avia_framework' ),
  317. "id" => "post_type",
  318. "type" => "select",
  319. "multiple" => 6,
  320. "std" => "",
  321. "subtype" => AviaHtmlHelper::get_registered_post_type_array()
  322. );
  323.  
  324. array_splice($this->elements, 2, 0, array($element));
  325.  
  326. }
  327. }
  328.  
  329.  
  330.  
  331. }
  332.  
  333.  
  334.  
  335. /**
  336. * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  337. * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  338. * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  339. *
  340. *
  341. * @param array $params this array holds the default values for $content and $args.
  342. * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  343. */
  344. function editor_element($params)
  345. {
  346. $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  347. $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  348. $params['innerHtml'].= "<div class='avia-flex-element'>";
  349. $params['innerHtml'].= __('This element will stretch across the whole screen by default.','avia_framework')."<br/>";
  350. $params['innerHtml'].= __('If you put it inside a color section or column it will only take up the available space','avia_framework');
  351. $params['innerHtml'].= " <div class='avia-flex-element-2nd'>".__('Currently:','avia_framework');
  352. $params['innerHtml'].= " <span class='avia-flex-element-stretched'>&laquo; ".__('Stretch fullwidth','avia_framework')." &raquo;</span>";
  353. $params['innerHtml'].= " <span class='avia-flex-element-content'>| ".__('Adjust to content width','avia_framework')." |</span>";
  354. $params['innerHtml'].= "</div></div>";
  355.  
  356. $params['content'] = NULL; //remove to allow content elements
  357.  
  358. return $params;
  359. }
  360.  
  361.  
  362.  
  363. /**
  364. * Frontend Shortcode Handler
  365. *
  366. * @param array $atts array of attributes
  367. * @param string $content text within enclosing form of shortcode element
  368. * @param string $shortcodename the shortcode found, when == callback name
  369. * @return string $output returns the modified html string
  370. */
  371. function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  372. {
  373. extract(AviaHelper::av_mobile_sizes($atts)); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  374.  
  375. $atts['class'] = !empty($meta['custom_class']) ? $meta['custom_class'] : "";
  376.  
  377. if(current_theme_supports('avia_template_builder_custom_post_type_grid'))
  378. {
  379. if(isset($atts['link']))
  380. {
  381. $atts['link'] = explode(',', $atts['link'], 2 );
  382. $atts['taxonomy'] = $atts['link'][0];
  383.  
  384. if(isset($atts['link'][1]))
  385. {
  386. $atts['categories'] = $atts['link'][1];
  387. }
  388. }
  389.  
  390. if(empty($atts['post_type']) || !current_theme_supports('add_avia_builder_post_type_option'))
  391. {
  392. $atts['post_type'] = get_post_types();
  393. }
  394.  
  395. if(is_string($atts['post_type'])) $atts['post_type'] = explode(',', $atts['post_type']);
  396. }
  397.  
  398. $atts['fullscreen'] = ShortcodeHelper::is_top_level();
  399.  
  400. $grid = new avia_post_grid($atts);
  401. $grid->query_entries();
  402. $portfolio_html = $grid->html();
  403.  
  404. if(!ShortcodeHelper::is_top_level())
  405. return $portfolio_html;
  406.  
  407.  
  408. $params['class'] = "main_color avia-no-border-styling avia-fullwidth-portfolio {$av_display_classes} ".$meta['el_class'];
  409. $params['open_structure'] = false;
  410. $params['id'] = !empty($atts['id']) ? AviaHelper::save_string($atts['id'],'-') : "";
  411. $params['custom_markup'] = $meta['custom_markup'];
  412.  
  413. //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  414. if(isset($meta['index']) && $meta['index'] == 0) $params['close'] = false;
  415. if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  416.  
  417. $output = avia_new_section($params);
  418. $output .= $portfolio_html;
  419. $output .= avia_section_after_element_content( $meta , 'after_portfolio' );
  420.  
  421. return $output;
  422. }
  423.  
  424. public function use_search_and_filter_query($query)
  425. {
  426. $this->entries = $query;
  427. }
  428.  
  429. }
  430. }
  431.  
  432.  
  433.  
  434.  
  435. if ( !class_exists( 'avia_post_grid' ) )
  436. {
  437. class avia_post_grid
  438. {
  439. static $grid = 0;
  440. static $preview_template = array();
  441. protected $atts;
  442. protected $entries;
  443.  
  444. function __construct($atts = array())
  445. {
  446. $this->screen_options = AviaHelper::av_mobile_sizes($atts);
  447.  
  448. $this->atts = shortcode_atts(array( 'style' => '',
  449. 'linking' => '',
  450. 'columns' => '4',
  451. 'items' => '16',
  452. 'contents' => 'title',
  453. 'sort' => 'yes',
  454. 'paginate' => 'yes',
  455. 'categories'=> '',
  456. 'preview_mode' => 'auto',
  457. 'image_size' => 'portfolio',
  458. 'post_type' => 'portfolio',
  459. 'taxonomy' => 'portfolio_entries',
  460. 'one_column_template' => 'special',
  461. 'set_breadcrumb' => true, //no shortcode option for this, modifies the breadcrumb nav, must be false on taxonomy overview
  462. 'class' => "",
  463. 'custom_markup' => '',
  464. 'fullscreen' => false,
  465. 'query_orderby' => 'date',
  466. 'query_order' => 'DESC',
  467. ), $atts, 'av_portfolio');
  468.  
  469.  
  470.  
  471. if($this->atts['linking'] == 'ajax')
  472. add_action('wp_footer' , array($this, 'print_preview_templates'));
  473. }
  474.  
  475. //generates the html of the post grid
  476. public function html()
  477. {
  478. if(empty($this->entries) || empty($this->entries->posts)) return;
  479.  
  480. avia_post_grid::$grid ++;
  481. extract($this->atts);
  482. extract($this->screen_options); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  483.  
  484. $container_id = avia_post_grid::$grid;
  485. $extraClass = 'first';
  486. $grid = 'one_fourth';
  487. if($preview_mode == 'auto') $image_size = 'portfolio';
  488. $post_loop_count = 1;
  489. $loop_counter = 1;
  490. $output = "";
  491. $style_class = empty($style) ? 'no_margin' : $style;
  492. $total = $this->entries->post_count % 2 ? "odd" : "even";
  493.  
  494. if($set_breadcrumb && is_page())
  495. {
  496. $_SESSION["avia_{$post_type}"] = get_the_ID();
  497. }
  498.  
  499. switch($columns)
  500. {
  501. case "1": $grid = 'av_fullwidth'; if($preview_mode == 'auto') $image_size = 'featured'; break;
  502. case "2": $grid = 'av_one_half'; break;
  503. case "3": $grid = 'av_one_third'; break;
  504. case "4": $grid = 'av_one_fourth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  505. case "5": $grid = 'av_one_fifth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  506. case "6": $grid = 'av_one_sixth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  507. }
  508.  
  509. if($fullscreen && $preview_mode =='auto' && $image_size == "portfolio_small") $image_size = 'portfolio';
  510.  
  511. $output .= $sort != "no" ? $this->sort_buttons($this->entries->posts, $this->atts) : "";
  512.  
  513. if($linking == "ajax")
  514. {
  515. global $avia_config;
  516.  
  517. $container_class = $fullscreen ? "container" : "";
  518.  
  519. $output .= "<div class='portfolio_preview_container {$container_class}' data-portfolio-id='{$container_id}'>
  520. <div class='ajax_controlls iconfont'>
  521. <a href='#prev' class='ajax_previous' ".av_icon_string('prev')."></a>
  522. <a href='#next' class='ajax_next' ".av_icon_string('next')."></a>
  523. <a class='avia_close' href='#close' ".av_icon_string('close')."></a>
  524. </div>
  525. <div class='portfolio-details-inner'></div>
  526. </div>";
  527. }
  528. $output .= "<div class='{$class} grid-sort-container isotope {$av_display_classes} {$av_column_classes} {$style_class}-container with-{$contents}-container grid-total-{$total} grid-col-{$columns} grid-links-{$linking}' data-portfolio-id='{$container_id}'>";
  529.  
  530. foreach ($this->entries->posts as $entry)
  531. {
  532. $the_id = $entry->ID;
  533. $parity = $post_loop_count % 2 ? 'odd' : 'even';
  534. $last = $this->entries->post_count == $post_loop_count ? " post-entry-last " : "";
  535. $post_class = "post-entry post-entry-{$the_id} grid-entry-overview grid-loop-{$post_loop_count} grid-parity-{$parity} {$last}";
  536. $sort_class = $this->sort_cat_string($the_id, $this->atts);
  537.  
  538. switch($linking)
  539. {
  540. case "lightbox": $link = aviaHelper::get_url('lightbox', get_post_thumbnail_id($the_id)); break;
  541. default: $link = get_permalink($the_id); break;
  542. }
  543.  
  544. $title_link = get_permalink($the_id);
  545. $custom_link = get_post_meta( $the_id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $the_id ,'_portfolio_custom_link_url', true) : false;
  546.  
  547. if($custom_link)
  548. {
  549. $title_link = "";
  550. $link = $custom_link;
  551. }
  552.  
  553. $excerpt = '';
  554. $title = '';
  555.  
  556. switch($contents)
  557. {
  558. case "excerpt": $excerpt = $entry->post_excerpt; $title = $entry->post_title; break;
  559. case "title": $excerpt = ''; $title = $entry->post_title; break;
  560. case "only_excerpt": $excerpt = $entry->post_excerpt; $title = ''; break;
  561. case "no": $excerpt = ''; $title = ''; break;
  562. }
  563.  
  564. $custom_overlay = apply_filters('avf_portfolio_custom_overlay', "", $entry);
  565. $link_markup = apply_filters('avf_portfolio_custom_image_container', array("a href='{$link}' title='".esc_attr(strip_tags($title))."' ",'a'), $entry);
  566.  
  567. $title = apply_filters('avf_portfolio_title', $title, $entry);
  568. $title_link = apply_filters('avf_portfolio_title_link', $title_link, $entry);
  569. $image_attrs = apply_filters('avf_portfolio_image_attrs', array(), $entry);
  570.  
  571.  
  572.  
  573. if($columns == "1" && $one_column_template == 'special')
  574. {
  575. $extraClass .= ' special_av_fullwidth ';
  576.  
  577. $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  578. $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  579. $output .= apply_filters('avf_portfolio_extra', "", $entry);
  580.  
  581. $output .= "<div class='av_table_col first portfolio-entry grid-content'>";
  582.  
  583. if(!empty($title))
  584. {
  585. $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  586. $output .= '<header class="entry-content-header">';
  587. $output .= "<h2 class='portfolio-grid-title entry-title' $markup>";
  588.  
  589. if(!empty($title_link))
  590. {
  591. $output .= "<a href='{$title_link}'>".$title."</a>";
  592. }
  593. else
  594. {
  595. $output .= "".$title."";
  596. }
  597. $output .= '</h2></header>';
  598. }
  599.  
  600. if(!empty($excerpt))
  601. {
  602. $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  603.  
  604. $output .= "<div class='entry-content-wrapper'>";
  605. $output .= "<div class='grid-entry-excerpt entry-content' $markup>".$excerpt."</div>";
  606. $output .= "</div>";
  607. }
  608. $output .= '<div class="avia-arrow"></div>';
  609. $output .= "</div>";
  610.  
  611. $image = get_the_post_thumbnail( $the_id, $image_size, $image_attrs );
  612. if(!empty($image))
  613. {
  614. $output .= "<div class='av_table_col portfolio-grid-image'>";
  615. $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx'>".$custom_overlay.$image."</".$link_markup[1].">";
  616. $output .= "</div>";
  617. }
  618. $output .= '<footer class="entry-footer"></footer>';
  619. $output .= "</article>";
  620. $output .= "</div>";
  621. }
  622. else
  623. {
  624. $extraClass .= ' default_av_fullwidth ';
  625.  
  626. $output .= "<div data-ajax-id='{$the_id}' class=' grid-entry flex_column isotope-item all_sort {$style_class} {$post_class} {$sort_class} {$grid} {$extraClass}'>";
  627. $output .= "<article class='main_color inner-entry' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">";
  628. $output .= apply_filters('avf_portfolio_extra', "", $entry);
  629. $output .= "<".$link_markup[0]." data-rel='grid-".avia_post_grid::$grid."' class='grid-image avia-hover-fx'>".$custom_overlay.get_the_post_thumbnail( $the_id, $image_size, $image_attrs )."</".$link_markup[1].">";
  630. $output .= !empty($title) || !empty($excerpt) ? "<div class='grid-content'><div class='avia-arrow'></div>" : '';
  631.  
  632. if(!empty($title))
  633. {
  634. $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  635. $output .= '<header class="entry-content-header">';
  636. $output .= "<h3 class='grid-entry-title entry-title' $markup>";
  637.  
  638. if(!empty($title_link))
  639. {
  640. $output .= "<a href='{$title_link}' title='".esc_attr(strip_tags($title))."'>".$title."</a>";
  641. }
  642. else
  643. {
  644. $output .= "".$title."";
  645. }
  646.  
  647. $output .= '</h3></header>';
  648. }
  649. $output .= !empty($excerpt) ? "<div class='grid-entry-excerpt entry-content' ".avia_markup_helper(array('context'=>'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup)).">".$excerpt."</div>" : '';
  650. $output .= !empty($title) || !empty($excerpt) ? "</div>" : '';
  651. $output .= '<footer class="entry-footer"></footer>';
  652. $output .= "</article>";
  653. $output .= "</div>";
  654. }
  655.  
  656.  
  657. $loop_counter ++;
  658. $post_loop_count ++;
  659. $extraClass = "";
  660.  
  661. if($loop_counter > $columns)
  662. {
  663. $loop_counter = 1;
  664. $extraClass = 'first';
  665. }
  666. }
  667.  
  668. $output .= "</div>";
  669.  
  670. //append pagination
  671. if($paginate == "yes" && $avia_pagination = avia_pagination($this->entries->max_num_pages, 'nav')) $output .= "<div class='pagination-wrap pagination-{$post_type}'>{$avia_pagination}</div>";
  672.  
  673. return $output;
  674. }
  675.  
  676. //generates the html for the sort buttons
  677. protected function sort_buttons($entries, $params)
  678. {
  679. //get all categories that are actually listed on the page
  680. $categories = get_categories(array(
  681. 'taxonomy' => $params['taxonomy'],
  682. 'hide_empty'=> 0
  683. ));
  684.  
  685. $current_page_cats = array();
  686. $cat_count = array();
  687. $display_cats = is_array($params['categories']) ? $params['categories'] : array_filter(explode(',',$params['categories']));
  688.  
  689. foreach ($entries as $entry)
  690. {
  691. if($current_item_cats = get_the_terms( $entry->ID, $params['taxonomy'] ))
  692. {
  693. if(!empty($current_item_cats))
  694. {
  695. foreach($current_item_cats as $current_item_cat)
  696. {
  697. if(empty($display_cats) || in_array($current_item_cat->term_id, $display_cats))
  698. {
  699. $current_page_cats[$current_item_cat->term_id] = $current_item_cat->term_id;
  700.  
  701. if(!isset($cat_count[$current_item_cat->term_id] ))
  702. {
  703. $cat_count[$current_item_cat->term_id] = 0;
  704. }
  705.  
  706. $cat_count[$current_item_cat->term_id] ++;
  707. }
  708. }
  709. }
  710. }
  711. }
  712.  
  713. extract($this->screen_options); //return $av_font_classes, $av_title_font_classes and $av_display_classes
  714.  
  715. $output = "<div class='sort_width_container {$av_display_classes} av-sort-".$this->atts['sort']."' data-portfolio-id='".avia_post_grid::$grid."' ><div id='js_sort_items' >";
  716. $hide = count($current_page_cats) <= 1 ? "hidden" : "";
  717.  
  718.  
  719. $first_item_name = apply_filters('avf_portfolio_sort_first_label', __('All','avia_framework' ), $params);
  720. $first_item_html = '<span class="inner_sort_button"><span>'.$first_item_name.'</span><small class="av-cat-count"> '.count($entries).' </small></span>';
  721. $output .= apply_filters('avf_portfolio_sort_heading', "", $params);
  722.  
  723.  
  724. if(strpos($this->atts['sort'], 'tax') !== false) $output .= "<div class='av-current-sort-title'>{$first_item_html}</div>";
  725. $output .= "<div class='sort_by_cat {$hide} '>";
  726. $output .= '<a href="#" data-filter="all_sort" class="all_sort_button active_sort">'.$first_item_html.'</a>';
  727.  
  728.  
  729. foreach($categories as $category)
  730. {
  731. if(in_array($category->term_id, $current_page_cats))
  732. {
  733. //fix for cyrillic, etc. characters - isotope does not support the % char
  734. $category->category_nicename = str_replace('%', '', $category->category_nicename);
  735.  
  736. $output .= "<span class='text-sep ".$category->category_nicename."_sort_sep'>/</span>";
  737. $output .= '<a href="#" data-filter="'.$category->category_nicename.'_sort" class="'.$category->category_nicename.'_sort_button" ><span class="inner_sort_button">';
  738. $output .= "<span>".esc_html(trim($category->cat_name))."</span>";
  739. $output .= "<small class='av-cat-count'> ".$cat_count[$category->term_id]." </small></span>";
  740. $output .= "</a>";
  741. }
  742. }
  743.  
  744. $output .= "</div></div></div>";
  745.  
  746. return $output;
  747. }
  748.  
  749.  
  750. //get the categories for each post and create a string that serves as classes so the javascript can sort by those classes
  751. protected function sort_cat_string($the_id, $params)
  752. {
  753. $sort_classes = "";
  754. $item_categories = get_the_terms( $the_id, $params['taxonomy']);
  755.  
  756. if(is_object($item_categories) || is_array($item_categories))
  757. {
  758. foreach ($item_categories as $cat)
  759. {
  760. //fix for cyrillic, etc. characters - isotope does not support the % char
  761. $cat->slug = str_replace('%', '', $cat->slug);
  762.  
  763. $sort_classes .= $cat->slug.'_sort ';
  764. }
  765. }
  766.  
  767. return $sort_classes;
  768. }
  769.  
  770. protected function build_preview_template( $entry )
  771. {
  772. if(isset(avia_post_grid::$preview_template[$entry->ID])) return;
  773. avia_post_grid::$preview_template[$entry->ID] = true;
  774.  
  775. $id = $entry->ID;
  776. $output = "";
  777. $defaults = array( 'ids' => get_post_thumbnail_id( $id ), 'text' => apply_filters( 'get_the_excerpt', $entry->post_excerpt) , "method" => 'gallery' , "auto" => "", "columns" => 5);
  778. $params['ids'] = get_post_meta( $id ,'_preview_ids', true);
  779. $params['text'] = get_post_meta( $id ,'_preview_text', true);
  780. $params['method'] = get_post_meta( $id ,'_preview_display', true);
  781. $params['interval'] = get_post_meta( $id ,'_preview_autorotation', true);
  782. $params['columns'] = get_post_meta( $id ,'_preview_columns', true);
  783. $params['preview_size'] = apply_filters('avf_ajax_preview_image_size',"gallery");
  784. $params['autoplay'] = is_numeric($params['interval']) ? "true" : "false";
  785.  
  786. $link = get_post_meta( $id ,'_portfolio_custom_link', true) != "" ? get_post_meta( $id ,'_portfolio_custom_link_url', true) : get_permalink($id);
  787.  
  788.  
  789. //merge default and params array. remove empty params with array_filter
  790. $params = array_merge($defaults, array_filter($params));
  791.  
  792. $params = apply_filters('avf_portfolio_preview_template_params', $params, $entry);
  793.  
  794. //set the content
  795. $content = str_replace(']]>', ']]&gt;', apply_filters('the_content', $params['text'] )); unset($params['text']);
  796.  
  797. //set images
  798. $string = "";
  799.  
  800. //set first class if preview images are deactivated
  801. $nogalleryclass = '';
  802. $params['ajax_request'] = true;
  803. switch($params['method'])
  804. {
  805. case 'gallery':
  806.  
  807. $params['style'] = "big_thumb";
  808. $params['thumb_size'] = "square";
  809. foreach($params as $key => $param) $string .= $key."='".$param."' ";
  810. $images = do_shortcode("[av_gallery {$string}]");
  811. break;
  812.  
  813. case 'slideshow':
  814. $params['size'] = $params['preview_size'];
  815. foreach($params as $key => $param) $string .= $key."='".$param."' ";
  816. $images = do_shortcode("[av_slideshow {$string}]");
  817. break;
  818.  
  819. case 'list':
  820. $images = $this->post_images($params['ids']);
  821. break;
  822.  
  823. case 'no':
  824. $images = false;
  825. $nogalleryclass = ' no_portfolio_preview_gallery ';
  826. break;
  827. }
  828.  
  829. $output .= "<div class='ajax_slide ajax_slide_{$id}' data-slide-id='{$id}' >";
  830.  
  831. $output .= "<article class='inner_slide $nogalleryclass' ".avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";
  832.  
  833. if(!empty($images))
  834. {
  835. $output .= "<div class='av_table_col first portfolio-preview-image'>";
  836. $output .= $images;
  837. $output .= "</div>";
  838. }
  839.  
  840. if(!empty($nogalleryclass)) $nogalleryclass .= ' first ';
  841.  
  842. $output .= "<div class='av_table_col $nogalleryclass portfolio-entry portfolio-preview-content'>";
  843.  
  844. $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup']));
  845. $output .= '<header class="entry-content-header">';
  846. $output .= "<h2 class='portfolio-preview-title entry-title' $markup><a href='{$link}'>".$entry->post_title."</a></h2>";
  847. $output .= '</header>';
  848.  
  849. $output .= "<div class='entry-content-wrapper entry-content' ".avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$id, 'custom_markup'=>$this->atts['custom_markup'])).">";
  850. $output .= $content;
  851. $output .= "</div>";
  852. $output .= "<span class='avia-arrow'></span>";
  853. $output .= "</div>";
  854.  
  855. $output .= '<footer class="entry-footer"></footer>';
  856. $output .= "</article>";
  857.  
  858. $output .= "</div>";
  859.  
  860. return "<script type='text/html' id='avia-tmpl-portfolio-preview-{$id}'>\n{$output}\n</script>\n\n";
  861.  
  862. }
  863.  
  864. protected function post_images($ids)
  865. {
  866. if(empty($ids)) return;
  867.  
  868. $attachments = get_posts(array(
  869. 'include' => $ids,
  870. 'post_status' => 'inherit',
  871. 'post_type' => 'attachment',
  872. 'post_mime_type' => 'image',
  873. 'order' => 'ASC',
  874. 'orderby' => 'post__in')
  875. );
  876.  
  877. $output = "";
  878.  
  879. foreach($attachments as $attachment)
  880. {
  881. $img = wp_get_attachment_image_src($attachment->ID, 'large');
  882.  
  883. $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  884. $alt = !empty($alt) ? esc_attr($alt) : '';
  885. $title = trim($attachment->post_title) ? esc_attr($attachment->post_title) : "";
  886. $description = trim($attachment->post_content) ? esc_attr($attachment->post_content) : "";
  887.  
  888. $output .= " <a href='".$img[0]."' class='portolio-preview-list-image' title='".$description."' ><img src='".$img[0]."' title='".$title."' alt='".$alt."' /></a>";
  889. }
  890.  
  891. return $output;
  892. }
  893.  
  894.  
  895.  
  896.  
  897. public function print_preview_templates()
  898. {
  899. foreach ($this->entries->posts as $entry)
  900. {
  901. echo $this->build_preview_template( $entry );
  902. }
  903. }
  904.  
  905.  
  906.  
  907. //fetch new entries
  908. public function query_entries($params = array())
  909. {
  910.  
  911.  
  912. $query = array();
  913. if(empty($params)) $params = $this->atts;
  914.  
  915. if(!empty($params['categories']))
  916. {
  917. //get the portfolio categories
  918. $terms = explode(',', $params['categories']);
  919. }
  920.  
  921. $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  922. if(!$page || $params['paginate'] == 'no') $page = 1;
  923.  
  924. //if we find categories perform complex query, otherwise simple one
  925. if(isset($terms[0]) && !empty($terms[0]) && !is_null($terms[0]) && $terms[0] != "null")
  926. {
  927. $query = array( 'orderby' => $params['query_orderby'],
  928. 'order' => $params['query_order'],
  929. 'paged' => $page,
  930. 'posts_per_page' => $params['items'],
  931. 'post_type' => $params['post_type'],
  932. 'tax_query' => array( array( 'taxonomy' => $params['taxonomy'],
  933. 'field' => 'id',
  934. 'terms' => $terms,
  935. 'operator' => 'IN')));
  936. }
  937. else
  938. {
  939. $query = array( 'orderby' => $params['query_orderby'],
  940. 'order' => $params['query_order'],
  941. 'paged' => $page,
  942. 'posts_per_page' => $params['items'],
  943. 'post_type' => $params['post_type']);
  944. }
  945.  
  946. $query = apply_filters('avia_post_grid_query', $query, $params);
  947.  
  948. $this->entries = new WP_Query( $query );
  949.  
  950. }
  951.  
  952.  
  953. //function that allows to set the query to an existing post query. usually only needed on pages that already did a query for the entries, like taxonomy archive pages.
  954. //Shortcode uses the query_entries function above
  955. public function use_global_query()
  956. {
  957. global $wp_query;
  958. $this->entries = $wp_query;
  959. }
  960.  
  961.  
  962.  
  963. }
  964. }
  965.  
  966.  
  967. /*
  968. Example: how to order posts randomly on page load. put this into functions.php
  969.  
  970. add_filter('avia_post_grid_query','avia_order_by_random');
  971. function avia_order_by_random($query)
  972. {
  973. $query['orderby'] = 'rand';
  974. return $query;
  975. }
  976. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement