PageRenderTime 43ms CodeModel.GetById 2ms app.highlight 36ms RepoModel.GetById 1ms app.codeStats 0ms

/shared/shortcodes/shortcodes/teaser.php

https://github.com/deltafactory/leads
PHP | 255 lines | 225 code | 21 blank | 9 comment | 20 complexity | 74f93aae07c8d93d0d47bbf5fb97bd06 MD5 | raw file
  1<?php
  2/**
  3*	Teaser Shortcode
  4*/
  5
  6/* 	Shortcode generator config
  7 * 	----------------------------------------------------- */
  8	$shortcodes_config['teaser'] = array(
  9		'no_preview' => true,
 10		'options' => array(
 11			'heading' => array(
 12				'name' => __('Heading', 'leads'),
 13				'desc' => __('Enter the heading text', 'leads'),
 14				'type' => 'text',
 15				'std' => ''
 16			),
 17			'style' => array(
 18				'name' => __('Style', 'leads'),
 19				'desc' => __('Select the style.', 'leads'),
 20				'type' => 'select',
 21				'options' => array(
 22					'' => __('Default', 'leads'),
 23					'nested' => __('Nested', 'leads'),
 24					'centered' => __('Centered', 'leads')
 25				),
 26				'std' => ''
 27			),
 28			'column' => array(
 29				'name' => __('Column', 'leads'),
 30				'desc' => __('Select the number of column(s).', 'leads'),
 31				'type' => 'select',
 32				'options' => array(
 33					'1' => __('1 Column', 'leads'),
 34					'2' => __('2 Columns', 'leads'),
 35					'3' => __('3 Columns', 'leads'),
 36					'4' => __('4 Columns', 'leads'),
 37					'5' => __('5 Columns', 'leads')
 38				),
 39				'std' => '3'
 40			)
 41		),
 42		'child' => array(
 43			'options' => array(
 44				'title' => array(
 45					'name' => __('Title', 'leads'),
 46					'desc' => __('Enter the title.', 'leads'),
 47					'type' => 'text',
 48					'std' => ''
 49				),
 50				'subtitle' => array(
 51					'name' => __('Sub Title', 'leads'),
 52					'desc' => __('Enter the sub title.', 'leads'),
 53					'type' => 'text',
 54					'std' => ''
 55				),
 56				'icon' => array(
 57					'name' => __('Icon', 'leads'),
 58					'desc' => __('Select an icon.', 'leads'),
 59					'type' => 'select',
 60					'options' => $fontawesome,
 61					'std' => ''
 62				),
 63				'image' => array(
 64					'name' => __('Image URL', 'leads'),
 65					'desc' => __('Enter your image url, it will override the icon above', 'leads'),
 66					'type' => 'text',
 67					'std' => '',
 68					'class' => ''
 69				),
 70				'link' => array(
 71					'name' => __('Link', 'leads'),
 72					'desc' => __('The title link destination URL.', 'leads'),
 73					'type' => 'text',
 74					'std' => ''
 75				),
 76				'content' => array(
 77					'name' => __('Teaser Content', 'leads'),
 78					'desc' => __('Enter the content.', 'leads'),
 79					'type' => 'textarea',
 80					'std' => ''
 81				)
 82			),
 83			'shortcode' => '[block title="{{title}}" subtitle="{{subtitle}}" icon="{{icon}}" link="{{link}}" ]{{content}}[/block]',
 84			'clone' => __('Add More Block',	'leads' )
 85		),
 86		'shortcode' => '[teaser heading="{{heading}}" style="{{style}}" column="{{column}}"]{{child}}[/teaser]',
 87		'popup_title' => 'Insert Teaser Shortcode'
 88	);
 89
 90/* 	Page builder module config
 91 * 	----------------------------------------------------- */
 92	$freshbuilder_modules['teaser'] = array(
 93		'name' => __('Teaser', 'leads'),
 94		'size' => 'one_full',
 95		'options' => array(
 96			'heading' => array(
 97				'name' => __('Heading', 'leads'),
 98				'desc' => __('Enter the heading text.', 'leads'),
 99				'type' => 'text',
100				'std' => '',
101				'class' => '',
102				'is_content' => 0
103			),
104			'style' => array(
105				'name' => __('Style', 'leads'),
106				'desc' => __('Select the style.', 'leads'),
107				'type' => 'select',
108				'options' => array(
109					'' => __('Default', 'leads'),
110					'nested' => __('Nested', 'leads'),
111					'centered' => __('Centered', 'leads')
112				),
113				'std' => '',
114				'class' => '',
115				'is_content' => 0
116			),
117			'column' => array(
118				'name' => __('Column', 'leads'),
119				'desc' => __('Select the column.', 'leads'),
120				'type' => 'select',
121				'options' => array(
122					'1' => __('1 Column', 'leads'),
123					'2' => __('2 Columns', 'leads'),
124					'3' => __('3 Columns', 'leads'),
125					'4' => __('4 Columns', 'leads'),
126					'5' => __('5 Columns', 'leads')
127				),
128				'std' => '3',
129				'class' => '',
130				'is_content' => 0
131			)
132		),
133		'child' => array(
134			'icon' => array(
135				'name' => __('Icon', 'leads'),
136				'desc' => __('Select an icon.', 'leads'),
137				'type' => 'select',
138				'options' => $fontawesome,
139				'std' => 'none',
140				'class' => '',
141				'is_content' => 0
142			),
143			'image' => array(
144				'name' => __('Image URL', 'leads'),
145				'desc' => __('Enter your image url, it will override the icon above', 'leads'),
146				'type' => 'text',
147				'std' => '',
148				'class' => '',
149				'is_content' => 0
150			),
151			'title' => array(
152				'name' => __('Title', 'leads'),
153				'desc' => __('Enter the heading text.', 'leads'),
154				'type' => 'text',
155				'class' => '',
156				'is_content' => 0
157			),
158			'subtitle' => array(
159				'name' => __('Sub Title', 'leads'),
160				'desc' => __('Enter the sub title.', 'leads'),
161				'type' => 'text',
162				'class' => '',
163				'is_content' => 0
164			),
165			'link' => array(
166				'name' => __('Link', 'leads'),
167				'desc' => __('The title link destination URL.', 'leads'),
168				'type' => 'text',
169				'class' => '',
170				'is_content' => 0
171			),
172			'content' => array(
173				'name' => __('Content', 'leads'),
174				'desc' => __('Enter the content.', 'leads'),
175				'type' => 'textarea',
176				'std' => '',
177				'class' => '',
178				'is_content' => 1
179			)
180		),
181		'child_code' => 'block'
182	);
183
184/* 	Add shortcode
185 * 	----------------------------------------------------- */
186	add_shortcode('teaser', 'inbound_shortcode_teaser');
187
188	function inbound_shortcode_teaser( $atts, $content = null ) {
189		extract(shortcode_atts(array(
190			'heading' => '',
191			'style' => '',
192			'column' => '4'
193		), $atts));
194
195		$out = '';
196
197		$grid = ' grid full';
198		if ($column == '2') $grid = ' grid one-half';
199		if ($column == '3') $grid = ' grid one-third';
200		if ($column == '4') $grid = ' grid one-fourth';
201		if ($column == '5') $grid = ' grid one-fifth';
202
203		$style = ($style != '') ? ' '. $style : '';
204
205		if (!preg_match_all("/(.?)\[(block)\b(.*?)(?:(\/))?\](?:(.+?)\[\/block\])?(.?)/s", $content, $matches)) {
206			return do_shortcode($content);
207		}
208		else {
209
210			for($i = 0; $i < count($matches[0]); $i++) {
211				$matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
212			}
213
214			$out .= '<div class="row">';
215
216				if ($heading != '') {
217					$out .= '<div class="grid full"><div class="heading"><h3>'.$heading.'</h3><div class="sep"></div></div></div>';
218				}
219
220				for($i = 0; $i < count($matches[0]); $i++) {
221					$title = ( $matches[3][$i]['link'] ) ? '<a class="reserve" href="'. $matches[3][$i]['link'] .'">'. $matches[3][$i]['title'] .'</a>' : $matches[3][$i]['title'];
222
223					$out .= '<aside class="teaser'. $grid . $style .'">';
224
225						if( $matches[3][$i]['image'] ) {
226							$out .= '<div class="teaser-image"><img src="'. $matches[3][$i]['image'] .'" alt="" /></div>';
227						}
228						elseif ( $matches[3][$i]['icon'] ) {
229							$out .= '<div class="teaser-icon"><i class="icon-'. $matches[3][$i]['icon'] .'"></i></div>';
230						}
231
232						$out .= '<header class="teaser-header">';
233
234							$out .= '<h3 class="teaser-title">'.$title.'</h3>';
235
236							if( $matches[3][$i]['subtitle'] ) {
237								$out .= '<div class="teaser-subtitle">'. $matches[3][$i]['subtitle'] .'</div>';
238							}
239						$out .= '</header>';
240
241						if( $matches[5][$i] ) {
242							$out .= '<div class="teaser-content">'.do_shortcode( trim($matches[5][$i]) ).'</div>';
243						}
244					$out .= '</aside>';
245				}
246
247				if( $i == $column - 1 ) {
248					$out .= '<div class="clear"></div>';
249				}
250
251			$out .= '</div>';
252		}
253
254		return $out;
255	}