PageRenderTime 51ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/themes/smartbox-theme-1.01/inc/options/shortcodes/shortcodes.php

https://github.com/bfay/maniacal-kitten
PHP | 1117 lines | 852 code | 156 blank | 109 comment | 107 complexity | f427dd558242a9c153223c268c2972da MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Themes shortcode functions go here
  4. *
  5. * @package Smartbox
  6. * @subpackage Core
  7. * @since 1.0
  8. *
  9. * @copyright (c) 2013 Oxygenna.com
  10. * @license http://wiki.envato.com/support/legal-terms/licensing-terms/
  11. * @version 1.01
  12. */
  13. /* ---------- TESTIMONIALS SHORTCODE ---------- */
  14. function oxy_shortcode_testimonials($atts, $content = '') {
  15. // setup options
  16. extract(shortcode_atts(array(
  17. 'title' => '',
  18. 'count' => 3,
  19. 'layout' => 'big',
  20. 'columns' => 3,
  21. 'style' => '',
  22. ), $atts));
  23. $query_options = array(
  24. 'post_type' => 'oxy_testimonial',
  25. 'numberposts' => $count
  26. );
  27. // fetch posts
  28. $span = $columns == 3 ? 'span4' : 'span3';
  29. $items = get_posts($query_options);
  30. $items_count = count($items);
  31. $output = '';
  32. if ($items_count > 0):
  33. $item_num = 1;
  34. if ($layout == 'big') {
  35. ?>
  36. <?php
  37. foreach ($items as $item) :
  38. global $post;
  39. $post = $item;
  40. setup_postdata($post);
  41. $custom_fields = get_post_custom($post->ID);
  42. $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  43. $class = ($item_num % 2 == 0) ? ' class="pull-right"' : '';
  44. $cite = (isset($custom_fields[THEME_SHORT . '_citation'])) ? $custom_fields[THEME_SHORT . '_citation'][0] : '';
  45. $hr = ($item_num !== $items_count) ? '<hr>' : '';
  46. $output .='<div class="row-fluid">';
  47. if ($item_num % 2 == 1) {
  48. $output.='<div class="span3"><div class="round-box box-big"><span class="box-inner">';
  49. $output.='<img alt="' . get_the_title() . '" class="img-circle" src="' . $img[0] . '" ></span></div></div>';
  50. }
  51. $output.='<div class="span9"><blockquote' . $class . '>' . '<p class="lead">' . get_the_content();
  52. $output.='</p><small>' . get_the_title() . '<cite title="Source Title"> ' . $cite . '</cite></small></blockquote></div>';
  53. if ($item_num % 2 == 0) {
  54. $output.='<div class="span3"><div class="round-box box-big"><span class="box-inner">';
  55. $output.='<img alt="' . get_the_title() . '" class="img-circle" src="' . $img[0] . '"></span></div></div>';
  56. }
  57. $output .='</div>' . $hr;
  58. $item_num++;
  59. endforeach;
  60. } else { // Calculate how many items we will render before we need another row
  61. $items_per_row = ($span == 'span4') ? 3 : 4;
  62. $item_num = 1;
  63. $output .='<ul class="inline row-fluid">';
  64. foreach ($items as $item) :
  65. global $post;
  66. $post = $item;
  67. setup_postdata($post);
  68. $custom_fields = get_post_custom($post->ID);
  69. $cite = (isset($custom_fields[THEME_SHORT . '_citation'])) ? $custom_fields[THEME_SHORT . '_citation'][0] : '';
  70. $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  71. if ($item_num > $items_per_row) {
  72. $output.= '</ul><ul class="inline row-fluid">';
  73. $item_num = 1;
  74. }
  75. $output.='<li class="' . $span . '"><div class="well blockquote-well"><blockquote><p>' . get_the_content() . '</p>';
  76. $output.='<small>' . get_the_title() . '<cite title="Source Title"> ' . $cite . '</cite></small></blockquote>';
  77. $output.='<div class="round-box box-medium"><span class="box-inner"><img alt="' . get_the_title() . '" class="img-circle" src="' . $img[0] . '"></span></div></div></li>';
  78. $item_num++;
  79. endforeach;
  80. $output.='</ul>';
  81. }
  82. wp_reset_postdata();
  83. endif;
  84. return oxy_shortcode_section($atts, $output);
  85. }
  86. add_shortcode('testimonials', 'oxy_shortcode_testimonials');
  87. /* ---- BOOTSTRAP BUTTON SHORTCODE ----- */
  88. function oxy_shortcode_button($atts, $content = '') {
  89. // setup options
  90. extract(shortcode_atts(array(
  91. 'type' => 'default',
  92. 'size' => 'default',
  93. 'xclass' => '',
  94. 'link' => '#',
  95. 'label' => 'button',
  96. 'icon' => '',
  97. 'place' => 'left',
  98. ), $atts));
  99. if($place == 'left'){
  100. return '<a href="' . $link . '" class="btn btn-' . $type . ' ' . $size . ' ' . $xclass . '"><i class="' . $icon . '"></i> ' . $label . '</a>';
  101. }
  102. else {
  103. return '<a href="' . $link . '" class="btn btn-' . $type . ' ' . $size . ' ' . $xclass . '"> ' . $label . ' <i class="' . $icon . ' icon_right"></i></a>';
  104. }
  105. }
  106. add_shortcode('button', 'oxy_shortcode_button');
  107. /* ---- BOOTSTRAP ALERT SHORTCODE ----- */
  108. function oxy_shortcode_alert($atts, $content = '') {
  109. // setup options
  110. extract(shortcode_atts(array(
  111. 'type' => 'default',
  112. 'label' => 'warning!',
  113. 'description' => 'something is wrong!',
  114. ), $atts));
  115. return '<div class="alert ' . $type . '"><button type="button" class="close" data-dismiss="alert">&times;</button><h4>' . $label . '</h4>' . $description . '</div>';
  116. }
  117. add_shortcode('alert', 'oxy_shortcode_alert');
  118. /* ----------------- BOOTSTRAP ACCORDION SHORTCODES --------------- */
  119. function oxy_shortcode_accordions($atts, $content = '') {
  120. // setup options
  121. /* extract( shortcode_atts( array(
  122. 'type' => 'primary',
  123. 'size' => 'default',
  124. 'xclass' => '',
  125. 'link' => '#',
  126. 'label' => 'button'
  127. ), $atts ) ); */
  128. $id = 'accordion_' . rand(100, 999);
  129. $pattern = get_shortcode_regex();
  130. $count = preg_match_all('/' . $pattern . '/s', $content, $matches);
  131. //var_dump($matches);
  132. if (is_array($matches) && array_key_exists(2, $matches) && in_array('accordion', $matches[2])) {
  133. $lis = array();
  134. for ($i = 0; $i < $count; $i++) {
  135. $group_id = 'group_' . rand(100, 999);
  136. // is it a tab?
  137. if ('accordion' == $matches[2][$i]) {
  138. $accordion_atts = wp_parse_args($matches[3][$i]);
  139. $lis[] = '<div class="accordion-group"><div class="accordion-heading">';
  140. $lis[].='<a class="accordion-toggle collapsed" data-parent="#' . $id . '" data-toggle="collapse" href="#' . $group_id . '">' .
  141. substr($accordion_atts['title'], 1, -1) . '</a></div>';
  142. $lis[].='<div class="accordion-body collapse" id="' . $group_id . '"><div class="accordion-inner">' . do_shortcode($matches[5][$i]) . '</div></div></div>';
  143. }
  144. }
  145. }
  146. return '<div class="accordion" id="' . $id . '">' . implode($lis) . '</div>';
  147. }
  148. add_shortcode('accordions', 'oxy_shortcode_accordions');
  149. function oxy_shortcode_accordion($atts, $content = '') {
  150. return do_shortcode($content);
  151. }
  152. add_shortcode('accordion', 'oxy_shortcode_accordion');
  153. /* ----------- BOOTSTRAP TABS AND TAB PANES SHORTCODES --------- */
  154. function oxy_shortcode_tab($atts, $content = '') {
  155. $pattern = get_shortcode_regex();
  156. $count = preg_match_all('/' . $pattern . '/s', $content, $matches);
  157. if (is_array($matches) && array_key_exists(2, $matches) && in_array('tab', $matches[2])) {
  158. $lis = array();
  159. $divs = array();
  160. $extraclass = ' active';
  161. for ($i = 0; $i < $count; $i++) {
  162. $pane_id = 'group_' . rand(100, 999);
  163. // is it a tab?
  164. if ('tab' == $matches[2][$i]) {
  165. $tab_atts = wp_parse_args($matches[3][$i]);
  166. $lis[] = '<li class="' . $extraclass . '"><a data-toggle="tab" href="#' . $pane_id . '">' . substr($tab_atts['title'], 1, -1) . '</a></li>';
  167. $divs[] = '<div class="tab-pane' . $extraclass . '" id="' . $pane_id . '">' . do_shortcode($matches[5][$i]) . '</div>';
  168. $extraclass = '';
  169. }
  170. }
  171. }
  172. return '<ul class="nav nav-tabs" data-tabs="tabs">' . implode($lis) . '</ul><div class="tab-content">' . implode($divs) . '</div>';
  173. }
  174. add_shortcode('tabs', 'oxy_shortcode_tab');
  175. function oxy_shortcode_tab_pane($atts, $content = '') {
  176. return do_shortcode($content);
  177. }
  178. add_shortcode('tab', 'oxy_shortcode_tab_pane');
  179. /* ------------------ PROGRESS BAR SHORTCODE -------------------- */
  180. function oxy_shortcode_progress_bar($atts, $content = '') {
  181. // setup options
  182. extract(shortcode_atts(array(
  183. 'percentage' => 50,
  184. 'type' => 'progress',
  185. 'style' => 'progress-info',
  186. ), $atts));
  187. return '<div class="' . $type . ' ' . $style . '"><div class="bar" style="width: ' . $percentage . '%"></div></div>';
  188. }
  189. add_shortcode('progress', 'oxy_shortcode_progress_bar');
  190. /* --------------------- PRICING SHORTCODE ---------------------- */
  191. function oxy_shortcode_pricing($atts, $content = '') {
  192. extract(shortcode_atts(array(
  193. 'heading' => 'standard',
  194. 'price' => 10,
  195. 'per' => 'month',
  196. 'featured' => 'no',
  197. ), $atts));
  198. $featured_class = ($featured == 'yes') ? '<span class="tag"><i class="icon-star"></i></span>' : '';
  199. $output = '<div class="span4"><div class="well well-package"><h3 class="well-package-heading">';
  200. $output.= $heading . $featured_class . '</h3>';
  201. $output.= '<div class="well-package-price"><small>$</small>' . $price . '<small>/' . $per . '</small></div>';
  202. return $output . do_shortcode($content) . '</div></div>';
  203. }
  204. add_shortcode('pricing', 'oxy_shortcode_pricing');
  205. /* ------------------------ IMAGE SHORTCODE ------------------------ */
  206. function oxy_shortcode_image($atts, $content = '') {
  207. // setup options
  208. extract(shortcode_atts(array(
  209. 'size' => 'box-medium',
  210. 'rounded' => 'yes',
  211. 'polaroid' => 'no',
  212. 'source' => '',
  213. 'icon' => '',
  214. 'link' => ''
  215. ), $atts));
  216. $iconclass = ($icon != '') ? '<i class="' . $icon . '"></i>' : '';
  217. $polaroidclss = ( $polaroid == 'yes') ? 'img-polaroid' : '';
  218. $extraclass = ($rounded == 'no') ? ' no-rounded' : '';
  219. $tag = ($link != '') ? 'a' : 'span';
  220. $ref = ($tag == 'a') ? ' href="' . $link . '"' : '';
  221. $output = '<div class="round-box' . $extraclass . ' ' . $size . '"> <' . $tag . ' class="box-inner"' . $ref . '>';
  222. $output.= '<img class="img-circle ' . $polaroidclss . '" src="' . $source . '">' . $iconclass . '</' . $tag . '></div>';
  223. return $output;
  224. }
  225. add_shortcode('image', 'oxy_shortcode_image');
  226. /* --------------------- PORTFOLIO SHORTCODES --------------------- */
  227. function oxy_shortcode_portfolio($atts, $content = '') {
  228. // setup options
  229. extract(shortcode_atts(array(
  230. 'title' => '',
  231. 'count' => 3,
  232. 'columns' => 3,
  233. 'cat' => '',
  234. 'style' => '',
  235. 'img_style' => '',
  236. ), $atts));
  237. $query_options = array(
  238. 'post_type' => 'oxy_portfolio_image',
  239. 'numberposts' => $count,
  240. 'orderby' => 'menu_order',
  241. 'order' => 'ASC'
  242. );
  243. $span = $columns == 3 ? 'span4' : 'span3';
  244. $box_size = $columns == 3 ? 'box-huge' : 'box-big';
  245. // fetch posts
  246. $projects = get_posts($query_options);
  247. $projects_count = count($projects);
  248. $output = '';
  249. if ($projects_count > 0) {
  250. $projects_per_row = ($span == 'span4') ? 3 : 4;
  251. $project_num = 1;
  252. $filters = get_terms('oxy_portfolio_categories', array('hide_empty' => 1));
  253. $output.='<div class="portfolio-filters"><h5 class="text-center"><a class="active" data-filter="all" href="#">all</a>';
  254. foreach ($filters as $filter) {
  255. $output.=' / <a href="#" data-filter="' . $filter->slug . '">' . $filter->name . '</a>';
  256. }
  257. $output.='</h5></div><div class="row-fluid"><ul class="thumbnails portfolio">';
  258. foreach ($projects as $project) {
  259. global $post;
  260. $post = $project;
  261. setup_postdata($post);
  262. $item_link = '<a class="box-inner" href="' . get_permalink() . '">';
  263. $extra_gallery_images = array();
  264. $format = get_post_format($post->ID);
  265. if (false === $format) {
  266. $format = 'standard';
  267. }
  268. $use_fancybox = get_post_meta($post->ID, THEME_SHORT . '_open_fancybox', true);
  269. if ($use_fancybox) {
  270. switch ($format) {
  271. case 'standard':
  272. $image_link = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  273. $item_link = '<a class="box-inner fancybox" href="' . $image_link[0] . '">';
  274. break;
  275. case 'gallery':
  276. $gallery_ids = oxy_get_content_gallery($post);
  277. if ($gallery_ids !== null) {
  278. if (count($gallery_ids) > 0) {
  279. // ok lets create a gallery
  280. $gallery_rel = 'rel="gallery' . $post->ID . '"';
  281. $gallery_image = wp_get_attachment_image_src($gallery_ids[0], 'full');
  282. $item_link = '<a class="box-inner fancybox" href="' . $gallery_image[0] . '" ' . $gallery_rel . '>';
  283. // remove first gallery image from array
  284. array_shift($gallery_ids);
  285. foreach ($gallery_ids as $gallery_image_id) {
  286. $gallery_image = wp_get_attachment_image_src($gallery_image_id, 'full');
  287. $extra_gallery_images[] = '<a class="fancybox" href="' . $gallery_image[0] . '" ' . $gallery_rel . '></a>';
  288. }
  289. }
  290. }
  291. break;
  292. case 'video':
  293. $video_shortcode = oxy_get_content_shortcode($post, 'embed');
  294. if ($video_shortcode !== null) {
  295. if (isset($video_shortcode[5])) {
  296. $video_shortcode = $video_shortcode[5];
  297. if (isset($video_shortcode[0])) {
  298. $item_link = '<a href="' . $video_shortcode[0] . '" class="box-inner fancybox-media">';
  299. }
  300. }
  301. }
  302. break;
  303. }
  304. }
  305. $filter_tags = get_the_terms($post->ID, 'oxy_portfolio_categories');
  306. $author_id = get_the_author_meta('ID');
  307. $post_filters = array();
  308. if ($filter_tags && !is_wp_error($filter_tags)) {
  309. foreach ($filter_tags as $tag) {
  310. $post_filters[] = 'filter-' . $tag->slug;
  311. }
  312. }
  313. $output .= '<li class=" ' . $span . ' ' . implode(',', $post_filters) . '" >';
  314. $output .= '<figure class="round-box ' . $box_size . ' ' . $img_style . '">';
  315. $output .= $item_link;
  316. $output .= get_the_post_thumbnail($post->ID, 'portfolio-thumb', array('class' => 'img-circle', 'alt' => get_the_title())) . '<i class="plus-icon"></i>';
  317. $output .= '</a>';
  318. $output .= '<figcaption><h4><a href="' . get_permalink() . '">' . get_the_title() . '</a></h4>';
  319. $output .= '<p>' . oxy_limit_excerpt(get_the_excerpt(), oxy_get_option('portfolio_excerpt_words')) . '</p></figcaption></figure>';
  320. foreach ($extra_gallery_images as $extra_image) {
  321. $output .= $extra_image;
  322. }
  323. $output .= '</li>';
  324. }
  325. $output .= '</ul></div>';
  326. }
  327. wp_reset_postdata();
  328. return oxy_shortcode_section($atts, $output);
  329. }
  330. add_shortcode('portfolio', 'oxy_shortcode_portfolio');
  331. /* ------------------ LAYOUT SHORTCODES ------------------- */
  332. /* ------------------ COLUMNS SHORTCODES ------------------- */
  333. function oxy_shortcode_row($atts, $content = null, $code) {
  334. return '<div class="row-fluid">' . do_shortcode($content) . '</div>';
  335. }
  336. add_shortcode('row', 'oxy_shortcode_row');
  337. function oxy_shortcode_layout($atts, $content = null, $code) {
  338. return '<div class="' . $code . '">' . do_shortcode($content) . '</div>';
  339. }
  340. add_shortcode('span1', 'oxy_shortcode_layout');
  341. add_shortcode('span2', 'oxy_shortcode_layout');
  342. add_shortcode('span3', 'oxy_shortcode_layout');
  343. add_shortcode('span4', 'oxy_shortcode_layout');
  344. add_shortcode('span5', 'oxy_shortcode_layout');
  345. add_shortcode('span6', 'oxy_shortcode_layout');
  346. add_shortcode('span7', 'oxy_shortcode_layout');
  347. add_shortcode('span8', 'oxy_shortcode_layout');
  348. add_shortcode('span9', 'oxy_shortcode_layout');
  349. add_shortcode('span10', 'oxy_shortcode_layout');
  350. add_shortcode('span11', 'oxy_shortcode_layout');
  351. add_shortcode('span12', 'oxy_shortcode_layout');
  352. /* ---------- LEAD SHORTCODE ---------- */
  353. function oxy_shortcode_lead($atts, $content) {
  354. extract(shortcode_atts(array(
  355. 'centered' => 'yes'
  356. ), $atts));
  357. $extraclass = ( $centered == 'yes') ? ' text-center' : '';
  358. return '<p class="lead' . $extraclass . '">' . do_shortcode($content) . '</p>';
  359. }
  360. add_shortcode('lead', 'oxy_shortcode_lead');
  361. function oxy_shortcode_donothing() {
  362. return '';
  363. }
  364. add_shortcode('gallery', 'oxy_shortcode_donothing');
  365. add_shortcode('link', 'oxy_shortcode_donothing');
  366. /* ------------ BLOCKQUOTE SHORTCODE ------------ */
  367. /**
  368. * @return type
  369. * @version 1.1 add id and class to Blockquote + ifelse-Anweisung
  370. */
  371. function oxy_shortcode_blockquote($atts, $content) {
  372. extract(shortcode_atts(array(
  373. 'who' => '',
  374. 'cite' => '',
  375. 'class' => '',
  376. ), $atts));
  377. return '<blockquote id="' . $id . '" class="' . $class . '">"' . do_shortcode($content) . '"<small>' . $who . ' <cite title="source title">' . $cite . '</cite></small></blockquote>';
  378. }
  379. add_shortcode('blockquote', 'oxy_shortcode_blockquote');
  380. /* * ********************************** SECTIONS ******************************* */
  381. /* Basic Section */
  382. function oxy_shortcode_section($atts, $content = '') {
  383. extract(shortcode_atts(array(
  384. 'style' => '',
  385. 'title' => '',
  386. ), $atts));
  387. switch ($style) {
  388. case 'gray':
  389. $style = 'section-alt';
  390. break;
  391. case 'dark':
  392. $style = 'section-alt section-dark';
  393. break;
  394. }
  395. $section_title = ( $title != '' ) ? '<div class="section-header"><h1>' . oxy_filter_title($title) . '</h1></div>' : '';
  396. return '<section class="section section-padded ' . $style . '"><div class="container-fluid">' . $section_title . '<div class="row-fluid">' . do_shortcode($content) . '</div></div></section>';
  397. }
  398. add_shortcode('section', 'oxy_shortcode_section');
  399. /* Services Section */
  400. function oxy_shortcode_services($atts) {
  401. extract(shortcode_atts(array(
  402. 'count' => 3,
  403. 'columns' => 3,
  404. 'links' => 'hide',
  405. 'lead' => 'hide',
  406. 'title' => '',
  407. 'style' => '',
  408. ), $atts));
  409. $query = array(
  410. 'post_type' => 'oxy_service',
  411. 'numberposts' => $count,
  412. 'orderby' => 'menu_order',
  413. 'order' => 'ASC'
  414. );
  415. global $post;
  416. $tmp_post = $post;
  417. $services = get_posts($query);
  418. $output = '';
  419. if (count($services > 0)) {
  420. $output .= '<ul class="unstyled row-fluid">';
  421. $header = ($columns == 4) ? 'h3' : 'h2';
  422. $size = ($columns == 4) ? 'round-medium' : 'box-big';
  423. $text_class = ($lead == 'show') ? ' class="lead text-center"' : '';
  424. $services_per_row = ($columns == 3) ? 3 : 4;
  425. $span = ($columns == 4) ? 'span3' : 'span4';
  426. $service_num = 1;
  427. foreach ($services as $post) {
  428. setup_postdata($post);
  429. if ($service_num > $services_per_row) {
  430. $output .='</ul><ul class="unstyled row-fluid">';
  431. $service_num = 1;
  432. }
  433. $icon = get_post_meta($post->ID, THEME_SHORT . '_icon', true);
  434. $output .= '<li class="' . $span . '">';
  435. $output .= '<div class="round-box ' . $size . '">';
  436. $output .= '<span class="box-inner">';
  437. $output .= get_the_post_thumbnail($post->ID, 'portfolio-thumb', array('class' => 'img-circle', 'alt' => get_the_title()));
  438. if ($icon != '') {
  439. $output .= '<i class="' . $icon . '"></i>';
  440. }
  441. $output .= '</span>';
  442. $output .= '</div>';
  443. $output .= '<' . $header . ' class="text-center">' . get_the_title() . '</' . $header . '>';
  444. $output .= '<p' . $text_class . '>' . get_the_content() . '</p>';
  445. // $output .= ( $links == 'show' )?'<a class="more-link" href="'.get_permalink().'"><strong>Read</strong>More</a>':'';
  446. $output .= '</li>';
  447. $service_num++;
  448. }
  449. $output .= '</ul>';
  450. }
  451. $post = $tmp_post;
  452. return oxy_shortcode_section($atts, $output);
  453. }
  454. add_shortcode('services', 'oxy_shortcode_services');
  455. /* Recent Posts */
  456. function oxy_get_recent_posts($count, $category = null, $authors = null, $post_formats = null) {
  457. $query = array();
  458. // set post count
  459. $query['numberposts'] = $count;
  460. // set category if selected
  461. if (!empty($category)) {
  462. $query['category_name'] = $category;
  463. }
  464. // set author if selected
  465. if (!empty($authors)) {
  466. $query['author'] = implode(',', $authors);
  467. }
  468. // set post format if selected
  469. if (!empty($post_formats)) {
  470. foreach ($post_formats as $key => $value) {
  471. $post_formats[$key] = 'post-format-' . $value;
  472. }
  473. $query['tax_query'] = array();
  474. $query['tax_query'][] = array(
  475. 'taxonomy' => 'post_format',
  476. 'field' => 'slug',
  477. 'terms' => $post_formats
  478. );
  479. }
  480. // fetch posts
  481. return get_posts($query);
  482. }
  483. function oxy_shortcode_recent_posts($atts, $content = '') {
  484. // setup options
  485. extract(shortcode_atts(array(
  486. 'title' => '',
  487. 'cat' => null,
  488. 'count' => 3,
  489. 'style' => '',
  490. 'columns' => 3
  491. ), $atts));
  492. $span = $columns == 3 ? 'span4' : 'span3';
  493. $posts = oxy_get_recent_posts($count, $cat);
  494. $output = '';
  495. if (!empty($posts)) :
  496. $output .='<ul class="unstyled row-fluid">';
  497. global $post;
  498. $item_num = 1;
  499. $items_per_row = $columns;
  500. foreach ($posts as $post) :
  501. setup_postdata($post);
  502. if ($item_num > $items_per_row) {
  503. $output.= '</ul><ul class="unstyled row-fluid">';
  504. $item_num = 1;
  505. }
  506. $output .='<li class="' . $span . '"><div class="row-fluid"><div class="span4">';
  507. $output .='<div class="round-box box-small box-colored"><a href="' . get_permalink() . '" class="box-inner">';
  508. if (has_post_thumbnail($post->ID)) {
  509. $output .=get_the_post_thumbnail($post->ID, array(128, 128), array('title' => $post->post_title, 'alt' => $post->post_title, 'class' => 'img-circle'));
  510. $output .= oxy_post_icon($post->ID, false);
  511. } else {
  512. $output .= '<img class="img-circle" src="' . IMAGES_URI . 'box-empty.gif">';
  513. $output .= oxy_post_icon($post->ID, false);
  514. }
  515. $output.='</a></div><h5 class="text-center light">' . get_the_date() . '</h5>';
  516. $output.='</div><div class="span8"><h3><a href="' . get_permalink() . '">' . get_the_title() . '</a>';
  517. $output.='</h3><p>' . oxy_limit_excerpt(get_the_excerpt(), 15) . '</p></div></div></li>';
  518. $item_num++;
  519. endforeach;
  520. $output .= '</ul>';
  521. endif;
  522. // reset post data
  523. wp_reset_postdata();
  524. return oxy_shortcode_section($atts, $output);
  525. }
  526. add_shortcode('recent_posts', 'oxy_shortcode_recent_posts');
  527. /* Content Featured */
  528. function oxy_shortcode_content_featured($atts, $content = '') {
  529. // setup options
  530. extract(shortcode_atts(array(
  531. 'title' => '',
  532. 'member' => '',
  533. 'style' => ''
  534. ), $atts));
  535. $output = '';
  536. if ($member !== ''):
  537. $item = get_post($member);
  538. $custom_fields = get_post_custom($item->ID);
  539. $img = wp_get_attachment_image_src(get_post_thumbnail_id($item->ID), 'full');
  540. $icon = (isset($custom_fields[THEME_SHORT . '_icon'])) ? $custom_fields[THEME_SHORT . '_icon'][0] : '';
  541. $skills = wp_get_post_terms($item->ID, 'oxy_content_skills');
  542. $output.='<div class="row-fluid"><div class="span6"><img alt="' . $item->post_title . '" class="push-bottom" src="' . $img[0] . '"></div>';
  543. $output.='<div class="span6"><p class="lead">' . $item->post_content . '</p>';
  544. if (!empty($skills)) {
  545. $output.='<ul class="lead icons icons-small">';
  546. foreach ($skills as $skill) {
  547. $output.='<li><i class="icon-ok"></i>' . $skill->name . '</li>';
  548. }
  549. $output.='</ul>';
  550. }
  551. $output.='</div></div>';
  552. wp_reset_postdata();
  553. endif;
  554. return oxy_shortcode_section($atts, $output);
  555. }
  556. add_shortcode('content_featured', 'oxy_shortcode_content_featured');
  557. /* Content List */
  558. function oxy_shortcode_content_list($atts, $content = '') {
  559. // setup options
  560. extract(shortcode_atts(array(
  561. 'title' => '',
  562. 'count' => 3,
  563. 'columns' => 3,
  564. 'style' => '',
  565. 'category' => '',
  566. 'orderby' => ''
  567. ), $atts));
  568. $query_options = array(
  569. 'post_type' => 'oxy_content',
  570. 'numberposts' => $count,
  571. 'orderby' => $orderby
  572. );
  573. //andrey: shortcode staff changed, column for value 1 added
  574. switch ($columns) {
  575. case 1:
  576. $span = 'span8';
  577. break;
  578. case 3:
  579. $span = 'span4';
  580. break;
  581. case 4:
  582. $span = 'span3';
  583. break;
  584. default:
  585. break;
  586. }
  587. if (!empty($category)) {
  588. $query_options['tax_query'] = array(
  589. array(
  590. 'taxonomy' => 'oxy_content_category',
  591. 'field' => 'slug',
  592. 'terms' => $category
  593. )
  594. );
  595. }
  596. // fetch posts
  597. $items = get_posts($query_options);
  598. $items_count = count($items);
  599. $output = '';
  600. if ($items_count > 0):
  601. $items_per_row = $columns;
  602. $member_num = 1;
  603. $output .= '<ul class="unstyled row-fluid">';
  604. foreach ($items as $member) :
  605. global $post;
  606. $post = $member;
  607. setup_postdata($post);
  608. $custom_fields = get_post_custom($post->ID);
  609. $icon = (isset($custom_fields[THEME_SHORT . '_icon'])) ? $custom_fields[THEME_SHORT . '_icon'][0] : '';
  610. $facebook = (isset($custom_fields[THEME_SHORT . '_facebook'])) ? $custom_fields[THEME_SHORT . '_facebook'][0] : '';
  611. $twitter = (isset($custom_fields[THEME_SHORT . '_twitter'])) ? $custom_fields[THEME_SHORT . '_twitter'][0] : '';
  612. $linkedin = (isset($custom_fields[THEME_SHORT . '_linkedin'])) ? $custom_fields[THEME_SHORT . '_linkedin'][0] : '';
  613. $pinterest = (isset($custom_fields[THEME_SHORT . '_pinterest'])) ? $custom_fields[THEME_SHORT . '_pinterest'][0] : '';
  614. $googleplus = (isset($custom_fields[THEME_SHORT . '_googleplus'])) ? $custom_fields[THEME_SHORT . '_googleplus'][0] : '';
  615. $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  616. if ($member_num > $items_per_row) {
  617. $output.='</ul><ul class="unstyled row-fluid">';
  618. $member_num = 1;
  619. }
  620. $output.='<li class="' . $span . '"><div class="round-box box-big"><span class="box-inner"><img alt="' . get_the_title() . '" class="img-circle" src="' . $img[0] . '">';
  621. $output.='</span></div><h3 class="text-center">' . get_the_title() . '<small class="block">' . $icon . '</small></h3>';
  622. $output.='<p class="no_li">' . get_the_content() . '</p>';
  623. $output.='<ul class="inline text-center big social-icons">';
  624. // must render
  625. $output.=($facebook !== '') ? '<li><a data-iconcolor="#3b5998" href="' . $facebook . '" style="color: rgb(66, 87, 106);"><i class="icon-facebook"></i></a></li>' : '';
  626. $output.=($twitter !== '') ? '<li><a data-iconcolor="#00a0d1" href="' . $twitter . '" style="color: rgb(66, 87, 106);"><i class="icon-twitter"></i></a></li>' : '';
  627. $output.=($pinterest !== '') ? '<li><a data-iconcolor="#910101" href="' . $pinterest . '" style="color: rgb(66, 87, 106);"><i class="icon-pinterest"></i></a></li>' : '';
  628. $output.=($googleplus !== '') ? '<li><a data-iconcolor="#E45135" href="' . $googleplus . '" style="color: rgb(66, 87, 106);"><i class="icon-google-plus"></i></a></li>' : '';
  629. $output.=($linkedin !== '') ? '<li><a data-iconcolor="#5FB0D5" href="' . $linkedin . '" style="color: rgb(66, 87, 106);"><i class="icon-linkedin"></i></a></li>' : '';
  630. $output.='</ul>';
  631. $output.='</li>';
  632. $member_num++;
  633. endforeach;
  634. $output .= '</ul>';
  635. endif;
  636. wp_reset_postdata();
  637. return oxy_shortcode_section($atts, $output);
  638. }
  639. add_shortcode('content_list', 'oxy_shortcode_content_list');
  640. function oxy_content_taxonomy_topic($atts, $content = '') {
  641. // setup options
  642. extract(shortcode_atts(array(
  643. 'title' => '',
  644. 'topic' => '',
  645. 'style' => '',
  646. 'title' => '',
  647. 'excerpt_length' => ''
  648. ), $atts));
  649. //verify that term exists and get term id in order to get fields(description, video) value
  650. $taxonomy_name = 'teaching_topics';
  651. $term_details = term_exists($topic, $taxonomy_name);
  652. if ( is_array($term_details) ){
  653. $term_id = $term_details['term_id'];
  654. $termDiscription = term_description( $term_id, $taxonomy_name );
  655. }else{
  656. return 'Темы('. $topic . '), которую ты указал в shortcode не существует, используй существующую тему';
  657. }
  658. //in order to get custom field 'main_video' from taxonomy we have
  659. //to call advanced custom fields plugin api and provide id of post which
  660. //is combination of taxonomy name and id of term e.g. term 'god' => id = 39
  661. $video = get_field('main_video', 'teaching_topics_' . $term_id);
  662. if(is_array($video)){
  663. global $wp_embed;
  664. $video_content = $video[0]->post_content;
  665. $video_content = $wp_embed->run_shortcode( $video_content );
  666. } else {
  667. return 'Ты не указал видео для это темы. Укажи видео в таксономии: ' . $taxonomy_name;
  668. }
  669. //add video to taxonomy topic and related links
  670. $content .= '[row]';
  671. $content .= '[span1]';
  672. $content .= '[/span1]';
  673. $content .= '[span7]';
  674. $content .= $video_content;
  675. $content .= '[/span7]';
  676. $content .= '[span1]';
  677. $content .= '[/span1]';
  678. $content .= '[span3]';
  679. $content .= '[iconlist id="blockRigthBlack"]';
  680. $content .= '<h3>а также по теме...</h3>';
  681. $content .= '[iconitem icon="icon-facetime-video" title="null"]<a href="/oxy_content_category?topic='. $taxonomy_name .'">Видео</a>[/iconitem]';
  682. $content .= '[iconitem icon="icon-book" title="null"]<a href="/oxy_content_category?topic='. $taxonomy_name .'">Текстовые проповеди</a>[/iconitem]';
  683. $content .= '[iconitem icon="icon-headphones" title="null"]<a href="/oxy_content_category?topic='. $taxonomy_name .'">Аудиопроповеди</a>[/iconitem]';
  684. $content .= '[iconitem icon="icon-music" title="null"]<a href="/oxy_content_category?topic='. $taxonomy_name .'">Псалмы</a>[/iconitem]';
  685. $content .= '[/iconlist]';
  686. $content .= '[iconlist id="blockRigthBlack"]';
  687. $content .= '[/span3]';
  688. $content .= '[/row]';
  689. //add description of taxonomy
  690. $content .= '[row]';
  691. $content .= '[span11]';
  692. $content .= '[blockquote class="block"]';
  693. $content .= $termDiscription;
  694. $content .= '[/blockquote]';
  695. $content .= '[/span11]';
  696. $content .= '[/row]';
  697. $atts[title] = $title;
  698. if(empty($style)){
  699. $atts[style] = 'dark';
  700. }else{
  701. $atts[style] = $style;
  702. }
  703. //add related posts; query for all related posts except main video which is already shown
  704. $wp_query = new WP_Query;
  705. $args = array(
  706. // post basics
  707. 'post_type' => 'oxy_content', // check capitalization, make sure this matches your post type slug
  708. 'post_status' => 'publish', // you may not need this line.
  709. 'posts_per_page' => 3, // set this yourself, 10 is a placeholder
  710. 'post__not_in' => array( $video[0]->ID ),
  711. // taxonomy
  712. 'tax_query' => array(
  713. array(
  714. 'taxonomy' => 'teaching_topics', // slug for desired tag goes here
  715. 'field' => 'slug',
  716. 'terms' => 'god', // should work without a slug, try it both ways...and use a variable, don't hardcode
  717. )
  718. )
  719. );
  720. $span = 'span4';
  721. $my_query = new wp_query($args);
  722. if ($my_query->have_posts()) {
  723. $content .= '[row]';
  724. $content .= '[span11]';
  725. $content .= '<ul class="unstyled row-fluid">';
  726. while ($my_query->have_posts()) :
  727. $post = $my_query->the_post();
  728. $img = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  729. $content .='<li class="' . $span . '"><div class="round-box box-big"><span class="box-inner"><img alt="' . get_the_title() . '" class="img-circle" src="' . $img[0] . '">';
  730. $content .='</span></div><h3 class="text-center">' . get_the_title() . '<small class="block">' . $icon . '</small></h3>';
  731. $post_content = get_the_content();
  732. $content_more = apply_filters('summary_more', ' ' . '[...]');
  733. $content_more = '<a href="' . get_permalink() . '">' . $content_more . '</a>';
  734. $excerpt_length = empty($excerpt_length) ? 50 : $excerpt_length;
  735. $text = wp_trim_words($post_content, $excerpt_length);
  736. $text = $text . $content_more;
  737. $content .='<p class="no_li">' . $text . '</p>';
  738. $content .='<ul class="inline text-center big social-icons">';
  739. $content .= '</p>';
  740. $content .='</ul>';
  741. $content .='</li>';
  742. //$content .= '<li><a href="' . the_permalink() . '" rel="bookmark" title="Permanent Link to ' . the_title_attribute() . '">' . the_title() . ' </a></li>';
  743. endwhile;
  744. $content .= '</ul>';
  745. $content .= '[/span11]';
  746. $content .= '[/row]';
  747. }
  748. wp_reset_query();
  749. $content .= '[row][span10][/span10][span2][button icon="icon-share-alt" type="warning" size="btn-default" label="далее к теме" link="/oxy_content_taxonomy?topic='.$topic.'" place="right"]';
  750. $content .= '[/span2][/row]';
  751. $output = oxy_shortcode_section($atts, $content);
  752. return $output;
  753. }
  754. add_shortcode('content_taxonomy_topic', 'oxy_content_taxonomy_topic');
  755. /* Content List */
  756. function oxy_content_itemlist_enhanced($atts, $content = '') {
  757. // setup options
  758. extract(shortcode_atts(array(
  759. 'title' => '',
  760. 'count' => 3,
  761. 'contenttype' => '',
  762. 'columns' => 3,
  763. 'style' => '',
  764. 'category' => '',
  765. 'orderby' => '',
  766. 'excerpt_length' => 5,
  767. 'addicon' => '',
  768. 'addtitle' => '',
  769. 'style' => ''
  770. ), $atts));
  771. //andrey: shortcode staff changed, column for value 1 added
  772. switch ($columns) {
  773. case 1:
  774. $span = 'span8';
  775. break;
  776. case 3:
  777. $span = 'span4';
  778. break;
  779. case 4:
  780. $span = 'span3';
  781. break;
  782. default:
  783. break;
  784. }
  785. //it is possible to provide several categories, split them and do array
  786. $category = trim( preg_replace( "/[\n\r\t ]+/", '', $category ), '' );
  787. $category = empty($category) ? '' : explode(',', $category) ;
  788. $query_options = array(
  789. 'post_type' => 'oxy_content',
  790. 'numberposts' => $count,
  791. 'orderby' => $orderby
  792. );
  793. //add taxonomy for query if needed
  794. if (!empty($category)) {
  795. $query_options['tax_query'] = array(
  796. array(
  797. 'taxonomy' => 'oxy_content_category',
  798. 'field' => 'slug',
  799. 'terms' => $category
  800. )
  801. );
  802. }
  803. // fetch posts
  804. $items = get_posts($query_options);
  805. $items_count = count($items);
  806. $output = '';
  807. if ($items_count > 0):
  808. if(!empty($style)) $output .= '<div id="'.$style.'">';
  809. if($addicon) $output .= '<ul class="icons " id="">';
  810. foreach ($items as $member) :
  811. global $post;
  812. $post = $member;
  813. setup_postdata($post);
  814. if($contenttype != 'content') $output .= '<li>';
  815. //add icon which refers to category
  816. if ($addicon) {
  817. $assignedCategory = wp_get_post_terms( $post->ID, 'oxy_content_category', array("fields" => "slugs") );
  818. switch ($assignedCategory[0]) {
  819. case 'video':
  820. $icon = 'icon-facetime-video';
  821. break;
  822. case 'music':
  823. $icon = 'icon-music';
  824. break;
  825. case 'text':
  826. $icon = 'icon-book';
  827. break;
  828. default:
  829. break;
  830. }
  831. $output .= '<h4>';
  832. $output .= '<i class="' . $icon . '"></i>';
  833. if(!$addtitle) $output .= '</h4>';
  834. }
  835. if($addtitle) {
  836. if (!$addicon) $output .= '<h4>';
  837. $output .= get_the_title() . " : ";
  838. $output .= '</h4>';
  839. }
  840. if ($contenttype == 'excerpt') {
  841. $text = get_the_excerpt();
  842. $excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
  843. $excerpt_more = '<a href="' . get_permalink() . '">' . $excerpt_more . '</a>';
  844. $excerpt_length = $excerpt_length == 0 ? 999 : $excerpt_length;
  845. $text = wp_trim_words($text, $excerpt_length, $excerpt_more);
  846. $output .= $text;
  847. } else if($contenttype == 'summary') {
  848. $output .= '<p>';
  849. $custom_fields = get_post_custom($post->ID);
  850. $summary = (isset($custom_fields[THEME_SHORT . '_summary'])) ? $custom_fields[THEME_SHORT . '_summary'][0] : '';
  851. $summary_more = apply_filters('summary_more', ' ' . '[...]');
  852. $summary_more = '<a href="' . get_permalink() . '">' . $summary_more . '</a>';
  853. $excerpt_length = empty($excerpt_length) ? 999 : $excerpt_length;
  854. $text = wp_trim_words($summary, $excerpt_length);
  855. $output .= $text . $summary_more;
  856. $output .= '</p>';
  857. } else if($contenttype == 'content'){
  858. $output .= get_the_content();
  859. }
  860. $member_num++;
  861. if($contenttype != 'content') $output .= '</li>';
  862. endforeach;
  863. if ($addicon) $output .= '</ul>';
  864. if(!empty($style)) $output .= '</div>';
  865. endif;
  866. wp_reset_postdata();
  867. return $output;
  868. }
  869. add_shortcode('content_itemlist_enhanced', 'oxy_content_itemlist_enhanced');
  870. /* * **************************************** COMPONENTS ************************************ */
  871. /* Slideshow Shortcode */
  872. function oxy_shortcode_flexslider($atts, $content = null) {
  873. $params = shortcode_atts(array(
  874. 'slideshow' => '',
  875. 'animation' => 'slide',
  876. 'speed' => 7000,
  877. 'duration' => 600,
  878. 'directionnav' => 'hide',
  879. 'directionnavpos' => 'outside',
  880. 'controlsposition' => 'inside',
  881. 'itemwidth' => '',
  882. 'showcontrols' => 'show',
  883. 'captions' => 'show',
  884. 'captionsize' => 'super',
  885. 'captionanimation' => 'animated'
  886. ), $atts);
  887. return oxy_create_flexslider($params['slideshow'], $params, false);
  888. }
  889. add_shortcode('flexslider', 'oxy_shortcode_flexslider');
  890. /**
  891. * Icon List Shortcode
  892. *
  893. * @return Icon List
  894. * @version 1.1 add id and class to iconlist
  895. * */
  896. function oxy_shortcode_iconlist($atts, $content = null) {
  897. extract(shortcode_atts(array(
  898. 'id' => '',
  899. 'class' => '',
  900. ), $atts));
  901. $output = '<ul class="icons ' . $class . '" id="' . $id . '">';
  902. $output .= do_shortcode($content);
  903. $output .= '</ul>';
  904. return $output;
  905. }
  906. add_shortcode('iconlist', 'oxy_shortcode_iconlist');
  907. /**
  908. * Icon Item Shortcode - for use inside an iconlist shortcode
  909. *
  910. * @return Icon Item HTML
  911. * */
  912. function oxy_shortcode_iconitem($atts, $content = null) {
  913. extract(shortcode_atts(array(
  914. 'title' => '',
  915. 'icon' => '',
  916. ), $atts));
  917. if ($title != 'null') {
  918. $output = '<li>';
  919. $output .= '<h4>';
  920. $output .= '<i class="' . $icon . '"></i>';
  921. $output .= $title;
  922. $output .= '</h4>';
  923. $output .= '<p>';
  924. $output .= $content;
  925. $output .= '</p>';
  926. $output .= '</li>';
  927. } else {
  928. $output = '<li>';
  929. $output .= '<i class="' . $icon . '"></i>';
  930. $output .= $content;
  931. $output .= '</li>';
  932. }
  933. return $output;
  934. }
  935. add_shortcode('iconitem', 'oxy_shortcode_iconitem');
  936. /**
  937. * DIV
  938. *
  939. * @return DIV HTML
  940. * */
  941. function oxy_shortcode_div($atts, $content = null) {
  942. extract(shortcode_atts(array(
  943. 'class' => '',
  944. 'id' => '',
  945. 'style' => '',
  946. ), $atts));
  947. $output = '<div id="' . $id . '" class="' . $class . '" style="' . $style . '">';
  948. $output .= do_shortcode($content);
  949. $output .= '</div>';
  950. return $output;
  951. }
  952. add_shortcode('div', 'oxy_shortcode_div');
  953. /**
  954. * Code shortcode - for showing code!
  955. *
  956. * @return Code html
  957. * */
  958. function oxy_shortcode_code($atts, $content = null) {
  959. return '<pre>' . htmlentities($content) . '</pre>';
  960. }
  961. add_shortcode('code', 'oxy_shortcode_code');