Advertisement
Guest User

gallery_horizontal.php

a guest
Apr 29th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.85 KB | None | 0 0
  1. <?php
  2.  
  3. //return; //beta element to be tested
  4.  
  5. if ( !class_exists( 'avia_sc_gallery_horizontal' ) )
  6. {
  7. class avia_sc_gallery_horizontal extends aviaShortcodeTemplate
  8. {
  9. static $hor_gallery = 0;
  10.  
  11. /**
  12. * Create the config array for the shortcode button
  13. */
  14. function shortcode_insert_button()
  15. {
  16. $this->config['name'] = __('Horizontal Gallery', 'avia_framework' );
  17. $this->config['tab'] = __('Media Elements', 'avia_framework' );
  18. $this->config['icon'] = AviaBuilder::$path['imagesURL']."sc-gallery.png";
  19. $this->config['order'] = 7;
  20. $this->config['target'] = 'avia-target-insert';
  21. $this->config['shortcode'] = 'av_horizontal_gallery';
  22. $this->config['tooltip'] = __('Creates a horizontal scrollable gallery ', 'avia_framework' );
  23. $this->config['preview'] = false;
  24. $this->config['drag-level'] = 3;
  25. }
  26.  
  27. /**
  28. * Popup Elements
  29. *
  30. * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  31. * opens a modal window that allows to edit the element properties
  32. *
  33. * @return void
  34. */
  35. function popup_elements()
  36. {
  37. $this->elements = array(
  38.  
  39. array(
  40. "name" => __("Edit Gallery",'avia_framework' ),
  41. "desc" => __("Create a new Gallery by selecting existing or uploading new images",'avia_framework' ),
  42. "id" => "ids",
  43. "type" => "gallery",
  44. "modal_class" => 'av-show-image-custom-link',
  45. "title" => __("Add/Edit Gallery",'avia_framework' ),
  46. "button" => __("Insert Images",'avia_framework' ),
  47. "std" => ""),
  48.  
  49. array(
  50. "name" => __("Gallery Height", 'avia_framework' ),
  51. "desc" => __("Set the gallery height in relation to the gallery container width", 'avia_framework' ),
  52. "id" => "height",
  53. "type" => "select",
  54. "std" => "25",
  55. "subtype" => AviaHtmlHelper::number_array(0,50,5, array() ,'%')
  56. ),
  57.  
  58.  
  59. array(
  60. "name" => __("Image Size", 'avia_framework' ),
  61. "desc" => __("Choose size for each image", 'avia_framework' ),
  62. "id" => "size",
  63. "type" => "select",
  64. "std" => "large",
  65. "subtype" => AviaHelper::get_registered_image_sizes(array('logo'))
  66. ),
  67.  
  68. array(
  69. "name" => __("Image Link", 'avia_framework' ),
  70. "desc" => __("By default images got a small link to a larger image version in a lightbox. You can deactivate that link. You can also set custom links when editing the images in the gallery", 'avia_framework' ),
  71. "id" => "links",
  72. "type" => "select",
  73. "std" => "active",
  74. "subtype" => array(
  75. __('Lightbox linking active', 'avia_framework' ) =>'active',
  76. __('Lightbox linking deactivated', 'avia_framework' ) =>'',
  77. )),
  78.  
  79. array(
  80. "name" => __("Gap between images", 'avia_framework' ),
  81. "desc" => __("Select the gap between the images", 'avia_framework' ),
  82. "id" => "gap",
  83. "type" => "select",
  84. "std" => "large",
  85. "subtype" => array(
  86. __('No Gap', 'avia_framework' ) =>'no',
  87. __('1 Pixel Gap', 'avia_framework' ) =>'1px',
  88. __('Large Gap', 'avia_framework' ) =>'large',
  89. )),
  90.  
  91.  
  92. array(
  93. "name" => __("Active Image Style", 'avia_framework' ),
  94. "desc" => __("How do you want to display the active image", 'avia_framework' ),
  95. "id" => "active",
  96. "type" => "select",
  97. "std" => "enlarge",
  98. "subtype" => array(
  99. __('No effect', 'avia_framework' ) =>'',
  100. __('Enlarge Image', 'avia_framework' ) =>'enlarge',
  101. )),
  102.  
  103. array(
  104. "name" => __("Initial Active Image", 'avia_framework' ),
  105. "desc" => __("Enter the Number of the image that should be open initially.", 'avia_framework' ),
  106. "id" => "initial",
  107. "std" => "",
  108. "type" => "input"),
  109.  
  110.  
  111. array(
  112. "name" => __("Gallery control styling?",'avia_framework' ),
  113. "desc" => __("Here you can select if and how to display the slideshow controls",'avia_framework' ),
  114. "id" => "control_layout",
  115. "type" => "select",
  116. "std" => "",
  117. "subtype" => array(__('Default','avia_framework' ) =>'av-control-default',__('Minimal White','avia_framework' ) =>'av-control-minimal', __('Minimal Black','avia_framework' ) =>'av-control-minimal av-control-minimal-dark',__('Hidden','avia_framework' ) =>'av-control-hidden')),
  118.  
  119.  
  120. );
  121.  
  122. }
  123.  
  124. /**
  125. * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  126. * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  127. * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  128. *
  129. *
  130. * @param array $params this array holds the default values for $content and $args.
  131. * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  132. */
  133. function editor_element($params)
  134. {
  135. $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  136. $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  137.  
  138.  
  139. $params['innerHtml'].= "<div class='avia-flex-element'>";
  140. $params['innerHtml'].= __('This element will stretch across the whole screen by default.','avia_framework')."<br/>";
  141. $params['innerHtml'].= __('If you put it inside a color section or column it will only take up the available space','avia_framework');
  142. $params['innerHtml'].= " <div class='avia-flex-element-2nd'>".__('Currently:','avia_framework');
  143. $params['innerHtml'].= " <span class='avia-flex-element-stretched'>&laquo; ".__('Stretch fullwidth','avia_framework')." &raquo;</span>";
  144. $params['innerHtml'].= " <span class='avia-flex-element-content'>| ".__('Adjust to content width','avia_framework')." |</span>";
  145. $params['innerHtml'].= "</div></div>";
  146.  
  147. return $params;
  148. }
  149.  
  150.  
  151.  
  152.  
  153. protected function slide_navigation_arrows()
  154. {
  155. $html = "";
  156. $html .= "<div class='avia-slideshow-arrows avia-slideshow-controls'>";
  157. $html .= "<a href='#prev' class='prev-slide av-horizontal-gallery-prev' ".av_icon_string('prev_big').">".__('Previous','avia_framework' )."</a>";
  158. $html .= "<a href='#next' class='next-slide av-horizontal-gallery-next' ".av_icon_string('next_big').">".__('Next','avia_framework' )."</a>";
  159. $html .= "</div>";
  160.  
  161. return $html;
  162. }
  163.  
  164.  
  165. /**
  166. * Frontend Shortcode Handler
  167. *
  168. * @param array $atts array of attributes
  169. * @param string $content text within enclosing form of shortcode element
  170. * @param string $shortcodename the shortcode found, when == callback name
  171. * @return string $output returns the modified html string
  172. */
  173. function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  174. {
  175. $output = "";
  176.  
  177. extract(shortcode_atts(array(
  178. 'height' => '400',
  179. 'size' => 'large',
  180. 'links' => 'active',
  181. 'gap' => 'large',
  182. 'ids' => '',
  183. 'active' => 'enlarge',
  184. 'control_layout' => 'av-control-default',
  185. 'initial' => 'initial'
  186.  
  187. ), $atts, $this->config['shortcode']));
  188.  
  189.  
  190. $attachments = get_posts(array(
  191. 'include' => $ids,
  192. 'post_status' => 'inherit',
  193. 'post_type' => 'attachment',
  194. 'post_mime_type' => 'image',
  195. 'order' => 'DESC',
  196. 'orderby' => 'post__in')
  197. );
  198.  
  199. $display_char = av_icon('ue869', 'entypo-fontello');
  200. $padding = "";
  201.  
  202. if($active == "enlarge")
  203. {
  204. $enlarge_by = 1.3;
  205. $padding = (( $height * $enlarge_by ) - $height ) / 2;
  206. $padding = "style='padding: {$padding}% 0px;' data-av-enlarge='{$enlarge_by}' ";
  207. }
  208.  
  209. if(!empty($initial))
  210. {
  211. $initial = "data-av-initial='{$initial}' ";
  212. }
  213.  
  214.  
  215. if(!empty($attachments) && is_array($attachments))
  216. {
  217. self::$hor_gallery++;
  218.  
  219. $counter = 0;
  220. $markup = avia_markup_helper(
  221. array('context' => 'image','echo'=>false, 'custom_markup'=>$meta['custom_markup'])
  222. );
  223.  
  224. $output .= "<div class='av-horizontal-gallery av-horizontal-gallery-{$gap}-gap av-horizontal-gallery-{$active}-effect av-horizontal-gallery-".self::$hor_gallery." ".$meta['el_class']." {$control_layout}' {$markup} {$padding} {$initial}>";
  225.  
  226. $output .= $this->slide_navigation_arrows();
  227.  
  228.  
  229. $output .= "<div class='av-horizontal-gallery-inner' style='padding-bottom:{$height}%' data-av-height='{$height}'>";
  230. $output .= "<div class='av-horizontal-gallery-slider'>";
  231.  
  232. foreach($attachments as $attachment)
  233. {
  234. $counter ++;
  235. $img = wp_get_attachment_image_src($attachment->ID, $size);
  236. $lightbox = wp_get_attachment_image_src($attachment->ID, 'large');
  237. $lightbox = $lightbox[0];
  238.  
  239. $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
  240. $alt = !empty($alt) ? esc_attr($alt) : '';
  241. $title = trim($attachment->post_title) ? esc_attr($attachment->post_title) : "";
  242. $description = trim($attachment->post_content) ? esc_attr($attachment->post_content) : esc_attr(trim($attachment->post_excerpt));
  243.  
  244.  
  245. $output .= "<div class='av-horizontal-gallery-wrap noHover'>";
  246.  
  247.  
  248. $output .= "<img class='av-horizontal-gallery-img' ";
  249. $output .= "width='".$img[1]."' height='".$img[2]."' src='".$img[0]."' title='".$title."' alt='".$alt."' />";
  250.  
  251. if($links != ""){
  252. $output .= "<a href='{$lightbox}' class='av-horizontal-gallery-link' {$display_char}>";
  253. $output .= "</a>";
  254. }
  255. $output .= "</div>";
  256.  
  257. }
  258.  
  259. $output .= "</div>";
  260. $output .= "</div>";
  261. $output .= "</div>";
  262.  
  263. }
  264.  
  265. if(!ShortcodeHelper::is_top_level()) return $output;
  266. $params = array();
  267. $params['class'] = "main_color av-horizontal-gallery-fullwidth avia-no-border-styling ".$meta['el_class'];
  268. $params['open_structure'] = false;
  269. $params['id'] = !empty($atts['id']) ? AviaHelper::save_string($atts['id'],'-') : "";
  270. $params['custom_markup'] = $meta['custom_markup'];
  271. if($meta['index'] == 0) $params['class'] .= " avia-no-border-styling";
  272.  
  273. //we dont need a closing structure if the element is the first one or if a previous fullwidth element was displayed before
  274. if($meta['index'] == 0) $params['close'] = false;
  275. if(!empty($meta['siblings']['prev']['tag']) && in_array($meta['siblings']['prev']['tag'], AviaBuilder::$full_el_no_section )) $params['close'] = false;
  276.  
  277. $html = $output;
  278.  
  279. $output = avia_new_section($params);
  280. $output .= $html;
  281. $output .= "</div><!-- close section -->"; //close section
  282.  
  283.  
  284. //if the next tag is a section dont create a new section from this shortcode
  285. if(!empty($meta['siblings']['next']['tag']) && in_array($meta['siblings']['next']['tag'], AviaBuilder::$full_el ))
  286. {
  287. $skipSecond = true;
  288. }
  289.  
  290. //if there is no next element dont create a new section.
  291. if(empty($meta['siblings']['next']['tag']))
  292. {
  293. $skipSecond = true;
  294. }
  295.  
  296. if(empty($skipSecond)) {
  297.  
  298. $output .= avia_new_section(array('close'=>false, 'id' => "after_horizontal_gallery"));
  299.  
  300. }
  301.  
  302. return $output;
  303.  
  304.  
  305.  
  306. }
  307.  
  308.  
  309. }
  310. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement