Advertisement
Guest User

portfolio.php

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