PageRenderTime 45ms CodeModel.GetById 8ms RepoModel.GetById 1ms app.codeStats 0ms

/icarostore/functions/extended/shortcodes.php

https://gitlab.com/hop23typhu/list-theme
PHP | 628 lines | 417 code | 161 blank | 50 comment | 74 complexity | cc3c46ff14abc788bd0dd8aad2c1a900 MD5 | raw file
  1. <?php
  2. /* ----------------------------------------------------- */
  3. /* Shortcodes */
  4. /* ----------------------------------------------------- */
  5. /* Dropcap */
  6. function tf_dropcap($atts, $content = null) {
  7. extract(shortcode_atts(array(), $atts));
  8. $out = "<span class='dropcap' >" . $content . "</span>";
  9. return $out;
  10. }
  11. add_shortcode('dropcap', 'tf_dropcap');
  12. /* Accordion Shortcode */
  13. function tf_accordion($atts, $content, $code) {
  14. extract(shortcode_atts(array(
  15. 'style' => false
  16. ), $atts));
  17. if (!preg_match_all("/(.?)\[(tab)\b(.*?)(?:(\/))?\](?:(.+?)\[\/tab\])?(.?)/s", $content, $matches)) {
  18. return do_shortcode($content);
  19. } else {
  20. $output = '';
  21. for ($i = 0; $i < count($matches[0]); $i++) {
  22. $matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
  23. if ($i == 0) {
  24. $first = 'class="firsttitle"';
  25. } else {
  26. $first = '';
  27. }
  28. $output .= '<div class="title"><a href="#acc-' . $i . '" ' . $first . '>' . $matches[3][$i]['title'] . '</a></div><div class="inner" id="acc-' . $i . '">' . do_shortcode(trim($matches[5][$i])) . '</div>';
  29. }
  30. return '<div class="accordion">' . $output . '</div>';
  31. }
  32. }
  33. add_shortcode('accordion', 'tf_accordion');
  34. /* ----------------------------------------------------- */
  35. /* Alter Block */
  36. function tf_alert($atts, $content = null) {
  37. extract(shortcode_atts(array(
  38. 'type' => 'warning'
  39. ), $atts));
  40. //return '<a href="' . $link . '" class="button ' . $color . ' ' . $align . '">' . $content . '</a>';
  41. return '<div class="alert-message ' . $type . '"><p>' . tf_remove_autop($content) . '</p></div>';
  42. }
  43. add_shortcode('alert', 'tf_alert');
  44. /* ----------------------------------------------------- */
  45. /* Responsive */
  46. function tf_responsive($atts, $content = null) {
  47. extract(shortcode_atts(array(
  48. 'show' => 'desktop'
  49. ), $atts));
  50. //return '<a href="' . $link . '" class="button ' . $color . ' ' . $align . '">' . $content . '</a>';
  51. return '<div class="show-' . $show . '">' . tf_remove_autop($content) . '</div>';
  52. }
  53. add_shortcode('responsive', 'tf_responsive');
  54. /* ----------------------------------------------------- */
  55. /* List Shortcodes */
  56. function tf_list($atts, $content = null) {
  57. extract(shortcode_atts(array(
  58. 'type' => 'check'
  59. ), $atts));
  60. $out = '<ul class="list">' . tf_remove_autop($content) . '</ul>';
  61. return $out;
  62. }
  63. add_shortcode('list', 'tf_list');
  64. function tf_item($atts, $content = null) {
  65. extract(shortcode_atts(array(
  66. 'icon' => 'ok'
  67. ), $atts));
  68. $out = '<li class="icon-' . $icon . '">' . tf_remove_autop($content) . '</li>';
  69. return $out;
  70. }
  71. add_shortcode('item', 'tf_item');
  72. function tf_icon($atts, $content = null) {
  73. extract(shortcode_atts(array(
  74. 'icon' => 'ok',
  75. 'size' => 'default',
  76. 'color' => '',
  77. 'circle' => false,
  78. 'type' => 'h1'
  79. ), $atts));
  80. if ($size == 'large') {
  81. $return = " large";
  82. } else {
  83. $return = " default";
  84. }
  85. if ($circle == true) {
  86. $return2 = " circle";
  87. } else {
  88. $return2 = "";
  89. }
  90. if ($circle == true && $color != '') {
  91. $return4 = ' style="background-color:' . $color . ' !important; color: #ffffff !important;"';
  92. }
  93. if ($circle == false && $color != '') {
  94. $return4 = ' style="color: ' . $color . ' !important;"';
  95. }
  96. if ($circle != true && $color != '') {
  97. $return4 = ' style="color: ' . $color . ' !important;"';
  98. }
  99. if ($type == 'h1') {
  100. $return3 = "h1";
  101. } elseif ($type == 'h2') {
  102. $return3 = "h2";
  103. } elseif ($type == 'h3') {
  104. $return3 = "h3";
  105. } elseif ($type == 'h4') {
  106. $return3 = "h4";
  107. } elseif ($type == 'h5') {
  108. $return3 = "h5";
  109. } elseif ($type == 'h6') {
  110. $return3 = "h6";
  111. } else {
  112. $return3 = "h1";
  113. }
  114. $out = '<' . $return3 . ' class="tficon' . $return . '' . $return2 . '"><span class="icon-' . $icon . '"' . $return4 . '></span>' . tf_remove_autop($content) . '</' . $return3 . '>';
  115. return $out;
  116. }
  117. add_shortcode('icon', 'tf_icon');
  118. /* ----------------------------------------------------- */
  119. /* Video Shortcodes */
  120. function tf_video($atts, $content=null) {
  121. extract(shortcode_atts(array(
  122. 'type' => '',
  123. 'id' => '',
  124. 'width' => false,
  125. 'height' => false,
  126. 'autoplay' => ''
  127. ), $atts));
  128. if ($height && !$width)
  129. $width = intval($height * 16 / 9);
  130. if (!$height && $width)
  131. $height = intval($width * 9 / 16) + 25;
  132. if (!$height && !$width) {
  133. $height = 320;
  134. $width = 480;
  135. }
  136. //$link = $link?' href="'.$link.'"':'';
  137. $autoplay = ($autoplay == 'yes' ? '1' : false);
  138. if ($type == "vimeo")
  139. $return = "<div class='video-embed'><iframe src='http://player.vimeo.com/video/$id?autoplay=$autoplay&amp;title=0&amp;byline=0&amp;portrait=0' width='$width' height='$height' class='iframe'></iframe></div>";
  140. else if ($type == "youtube")
  141. $return = "<div class='video-embed'><iframe src='http://www.youtube.com/embed/$id?HD=1;rel=0;showinfo=0' width='$width' height='$height' class='iframe'></iframe></div>";
  142. if (!empty($id)) {
  143. return $return;
  144. }
  145. }
  146. add_shortcode('video', 'tf_video');
  147. /* ----------------------------------------------------- */
  148. /* HR */
  149. function tf_hr() {
  150. return '<div class="hr"></div>';
  151. }
  152. add_shortcode('hr', 'tf_hr');
  153. function tf_hr2() {
  154. return '<div class="hr2"></div>';
  155. }
  156. add_shortcode('hr2', 'tf_hr2');
  157. function tf_hr3() {
  158. return '<div class="hr3"></div>';
  159. }
  160. add_shortcode('hr3', 'tf_hr3');
  161. function tf_clear() {
  162. return '<div class="clear"></div>';
  163. }
  164. add_shortcode('clear', 'tf_clear');
  165. function tf_hr4() {
  166. return '<div class="hr4"><span class="seperator"></span><span class="lightborder"></span></div>';
  167. }
  168. add_shortcode('hr4', 'tf_hr4');
  169. function tf_spacer() {
  170. return '<div class="spacer"></div>';
  171. }
  172. add_shortcode('spacer', 'tf_spacer');
  173. /* ----------------------------------------------------- */
  174. /* Buttons */
  175. function tf_buttons($atts, $content = null) {
  176. extract(shortcode_atts(array(
  177. 'link' => '#',
  178. 'target' => '_self',
  179. 'size' => 'normal',
  180. 'style' => 'default', //light, dark, normal
  181. 'align' => '',
  182. 'icon' => ''
  183. ), $atts));
  184. if ($icon != '') {
  185. $return = "icon-" . $icon;
  186. } else {
  187. $return = "";
  188. }
  189. $out = "<a href=\"" . $link . "\" target=\"" . $target . "\" class=\"button " . $style . " " . $size . " " . $align . " " . $return . "\">" . do_shortcode($content) . "</a>";
  190. return $out;
  191. }
  192. add_shortcode('button', 'tf_buttons');
  193. /* ----------------------------------------------------- */
  194. /* Responsive Images */
  195. function tf_image($atts, $content = null) {
  196. extract(shortcode_atts(array(
  197. 'src' => '#',
  198. 'responsive' => true,
  199. 'lightbox' => false
  200. ), $atts));
  201. if ($responsive == true) {
  202. $return = "responsive";
  203. } else {
  204. $return = "";
  205. }
  206. if ($lightbox == true) {
  207. $return2 = '<a href="' . $src . '">';
  208. $return3 = '</a>';
  209. }
  210. $out = $return2 . '<img src="' . $src . '" class="' . $return . '">' . $return3;
  211. return $out;
  212. }
  213. add_shortcode('image', 'tf_image');
  214. /* ----------------------------------------------------- */
  215. /* Toggle Shortcode */
  216. function tf_toggle($atts, $content = null) {
  217. extract(shortcode_atts(array(
  218. 'title' => '',
  219. ), $atts));
  220. return '<div class="toggle"><div class="title">' . $title . '<span></span></div><div class="inner"><div>' . tf_remove_autop($content) . '</div></div></div>';
  221. }
  222. add_shortcode('toggle', 'tf_toggle');
  223. /* ----------------------------------------------------- */
  224. /* Tabs Shortcode */
  225. function tf_tabs($atts, $content = null, $code) {
  226. extract(shortcode_atts(array(
  227. ), $atts));
  228. if (!preg_match_all("/(.?)\[(tab)\b(.*?)(?:(\/))?\](?:(.+?)\[\/tab\])?(.?)/s", $content, $matches)) {
  229. return do_shortcode($content);
  230. } else {
  231. for ($i = 0; $i < count($matches[0]); $i++) {
  232. $matches[3][$i] = shortcode_parse_atts($matches[3][$i]);
  233. }
  234. $output = '<ul class="tabNavigation clearfix">';
  235. for ($i = 0; $i < count($matches[0]); $i++) {
  236. $output .= '<li><a title="' . $matches[3][$i]['title'] . '" href="#tab-' . $i . '">' . $matches[3][$i]['title'] . '</a></li>';
  237. }
  238. $output .= '</ul><div class="clearnav"></div>';
  239. for ($i = 0; $i < count($matches[0]); $i++) {
  240. $output .= '<div id="tab-' . $i . '">' . do_shortcode(trim($matches[5][$i])) . '</div>';
  241. }
  242. return '<div class="tabs">' . $output . '</div>';
  243. }
  244. }
  245. add_shortcode('tabs', 'tf_tabs');
  246. /* ----------------------------------------------------- */
  247. /* Pricing Table */
  248. function tf_plan($atts, $content = null) {
  249. extract(shortcode_atts(array(
  250. 'name' => 'Premium',
  251. 'link' => 'http://www.google.de',
  252. 'linkname' => 'Sign Up',
  253. 'price' => '39.00$',
  254. 'per' => false,
  255. 'color' => false, // grey, green, red, blue
  256. 'featured' => false
  257. ), $atts));
  258. if ($featured == true) {
  259. $return = " featured";
  260. $return2 = "";
  261. } else {
  262. $return = "";
  263. $return2 = "light";
  264. }
  265. if ($per != false) {
  266. $return3 = "" . $per . "";
  267. } else {
  268. $return3 = "";
  269. }
  270. $return5 = "";
  271. if ($color != false) {
  272. if ($featured == true) {
  273. $return5 = "style='color:" . $color . ";' ";
  274. }
  275. $return4 = "style='color:" . $color . ";' ";
  276. } else {
  277. $return4 = "";
  278. }
  279. $out = "
  280. <div class='plan" . $return . "' " . $return5 . ">
  281. <div class='plan-head'><h3 " . $return4 . ">" . $name . "</h3>
  282. <div class='price' " . $return4 . ">" . $price . " <span>" . $return3 . "</span></div></div>
  283. <ul>" . do_shortcode($content) . "</ul><div class='signup'><a class='button " . $return2 . "' href='" . $link . "'>" . $linkname . "<span></span></a></div>
  284. </div>";
  285. return $out;
  286. }
  287. add_shortcode('plan', 'tf_plan');
  288. /* ----------------------------------------------------- */
  289. /* Pricing Table */
  290. function tf_pricing($atts, $content = null) {
  291. extract(shortcode_atts(array(
  292. 'col' => '3'
  293. ), $atts));
  294. $out = "<div class='pricing-table col-" . $col . "'>" . do_shortcode($content) . "</div><div class='clear'></div>";
  295. return $out;
  296. }
  297. add_shortcode('pricing-table', 'tf_pricing');
  298. /* ----------------------------------------------------- */
  299. /* Columns */
  300. function tf_one_third($atts, $content = null) {
  301. return '<div class="one_third">' . tf_remove_autop($content) . '</div>';
  302. }
  303. add_shortcode('one_third', 'tf_one_third');
  304. function tf_one_third_first($atts, $content = null) {
  305. return '<div class="one_third first">' . tf_remove_autop($content) . '</div>';
  306. }
  307. add_shortcode('one_third_first', 'tf_one_third_first');
  308. function tf_one_third_last($atts, $content = null) {
  309. return '<div class="one_third last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  310. }
  311. add_shortcode('one_third_last', 'tf_one_third_last');
  312. function tf_two_third($atts, $content = null) {
  313. return '<div class="two_third">' . tf_remove_autop($content) . '</div>';
  314. }
  315. add_shortcode('two_third', 'tf_two_third');
  316. function tf_two_third_first($atts, $content = null) {
  317. return '<div class="two_third first">' . tf_remove_autop($content) . '</div>';
  318. }
  319. add_shortcode('two_third_first', 'tf_two_third_first');
  320. function tf_two_third_last($atts, $content = null) {
  321. return '<div class="two_third last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  322. }
  323. add_shortcode('two_third_last', 'tf_two_third_last');
  324. function tf_one_half($atts, $content = null) {
  325. return '<div class="one_half">' . tf_remove_autop($content) . '</div>';
  326. }
  327. add_shortcode('one_half', 'tf_one_half');
  328. function tf_one_half_first($atts, $content = null) {
  329. return '<div class="one_half first">' . wpautop(tf_remove_autop($content)) . '</div>';
  330. }
  331. add_shortcode('one_half_first', 'tf_one_half_first');
  332. function tf_one_half_last($atts, $content = null) {
  333. return '<div class="one_half last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  334. }
  335. add_shortcode('one_half_last', 'tf_one_half_last');
  336. function tf_one_fourth($atts, $content = null) {
  337. return '<div class="one_fourth">' . tf_remove_autop($content) . '</div>';
  338. }
  339. add_shortcode('one_fourth', 'tf_one_fourth');
  340. function tf_one_fourth_first($atts, $content = null) {
  341. return '<div class="one_fourth first">' . tf_remove_autop($content) . '</div>';
  342. }
  343. add_shortcode('one_fourth_first', 'tf_one_fourth_first');
  344. function tf_one_fourth_last($atts, $content = null) {
  345. return '<div class="one_fourth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  346. }
  347. add_shortcode('one_fourth_last', 'tf_one_fourth_last');
  348. function tf_three_fourth($atts, $content = null) {
  349. return '<div class="three_fourth">' . tf_remove_autop($content) . '</div>';
  350. }
  351. add_shortcode('three_fourth', 'tf_three_fourth');
  352. function tf_three_fourth_first($atts, $content = null) {
  353. return '<div class="three_fourth first">' . tf_remove_autop($content) . '</div>';
  354. }
  355. add_shortcode('three_fourth_first', 'tf_three_fourth_first');
  356. function tf_three_fourth_last($atts, $content = null) {
  357. return '<div class="three_fourth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  358. }
  359. add_shortcode('three_fourth_last', 'tf_three_fourth_last');
  360. function tf_one_fifth($atts, $content = null) {
  361. return '<div class="one_fifth">' . tf_remove_autop($content) . '</div>';
  362. }
  363. add_shortcode('one_fifth', 'tf_one_fifth');
  364. function tf_one_fifth_first($atts, $content = null) {
  365. return '<div class="one_fifth first">' . tf_remove_autop($content) . '</div>';
  366. }
  367. add_shortcode('one_fifth_first', 'tf_one_fifth_first');
  368. function tf_one_fifth_last($atts, $content = null) {
  369. return '<div class="one_fifth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  370. }
  371. add_shortcode('one_fifth_last', 'tf_one_fifth_last');
  372. function tf_two_fifth($atts, $content = null) {
  373. return '<div class="two_fifth">' . tf_remove_autop($content) . '</div>';
  374. }
  375. add_shortcode('two_fifth', 'tf_two_fifth');
  376. function tf_two_fifth_first($atts, $content = null) {
  377. return '<div class="two_fifth first">' . tf_remove_autop($content) . '</div>';
  378. }
  379. add_shortcode('two_fifth_first', 'tf_two_fifth_first');
  380. function tf_two_fifth_last($atts, $content = null) {
  381. return '<div class="two_fifth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  382. }
  383. add_shortcode('two_fifth_last', 'tf_two_fifth_last');
  384. function tf_three_fifth($atts, $content = null) {
  385. return '<div class="three_fifth">' . tf_remove_autop($content) . '</div>';
  386. }
  387. add_shortcode('three_fifth', 'tf_three_fifth');
  388. function tf_three_fifth_first($atts, $content = null) {
  389. return '<div class="three_fifth first">' . tf_remove_autop($content) . '</div>';
  390. }
  391. add_shortcode('three_fifth_first', 'tf_three_fifth_first');
  392. function tf_three_fifth_last($atts, $content = null) {
  393. return '<div class="three_fifth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  394. }
  395. add_shortcode('three_fifth_last', 'tf_three_fifth_last');
  396. function tf_four_fifth($atts, $content = null) {
  397. return '<div class="four_fifth">' . tf_remove_autop($content) . '</div>';
  398. }
  399. add_shortcode('four_fifth', 'tf_four_fifth');
  400. function tf_four_fifth_first($atts, $content = null) {
  401. return '<div class="four_fifth first">' . tf_remove_autop($content) . '</div>';
  402. }
  403. add_shortcode('four_fifth_first', 'tf_four_fifth_first');
  404. function tf_four_fifth_last($atts, $content = null) {
  405. return '<div class="four_fifth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  406. }
  407. add_shortcode('four_fifth_last', 'tf_four_fifth_last');
  408. function tf_one_sixth($atts, $content = null) {
  409. return '<div class="one_sixth">' . tf_remove_autop($content) . '</div>';
  410. }
  411. add_shortcode('one_sixth', 'tf_one_sixth');
  412. function tf_one_sixth_first($atts, $content = null) {
  413. return '<div class="one_sixth first">' . tf_remove_autop($content) . '</div>';
  414. }
  415. add_shortcode('one_sixth_first', 'tf_one_sixth_first');
  416. function tf_one_sixth_last($atts, $content = null) {
  417. return '<div class="one_sixth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  418. }
  419. add_shortcode('one_sixth_last', 'tf_one_sixth_last');
  420. function tf_five_sixth($atts, $content = null) {
  421. return '<div class="five_sixth">' . tf_remove_autop($content) . '</div>';
  422. }
  423. add_shortcode('five_sixth', 'tf_five_sixth');
  424. function tf_five_sixth_first($atts, $content = null) {
  425. return '<div class="five_sixth first">' . tf_remove_autop($content) . '</div>';
  426. }
  427. add_shortcode('five_sixth_first', 'tf_five_sixth_first');
  428. function tf_five_sixth_last($atts, $content = null) {
  429. return '<div class="five_sixth last">' . tf_remove_autop($content) . '</div><div class="clear"></div>';
  430. }
  431. add_shortcode('five_sixth_last', 'tf_five_sixth_last');
  432. /**
  433. * Removes wordpress autop and invalid nesting of p tags, as well as br tags
  434. *
  435. * @param string $content html content by the wordpress editor
  436. * @return string $content
  437. */
  438. if (!function_exists("tf_remove_autop")) {
  439. function tf_remove_autop($content) {
  440. $content = do_shortcode(shortcode_unautop($content));
  441. $content = preg_replace('#^<\/p>|^<br\s?\/?>|<p>$|<p>\s*(&nbsp;)?\s*<\/p>#', '', $content);
  442. return $content;
  443. }
  444. }
  445. function tf_parse_shortcode_content($content) {
  446. /* Parse nested shortcodes and add formatting. */
  447. $content = trim(do_shortcode(shortcode_unautop($content)));
  448. /* Remove '' from the start of the string. */
  449. if (substr($content, 0, 4) == '')
  450. $content = substr($content, 4);
  451. /* Remove '' from the end of the string. */
  452. if (substr($content, -3, 3) == '')
  453. $content = substr($content, 0, -3);
  454. /* Remove any instances of ''. */
  455. $content = str_replace(array('<p></p>'), '', $content);
  456. $content = str_replace(array('<p> </p>'), '', $content);
  457. return $content;
  458. }
  459. // add_filter('tf_shortcode_out_filter', 'tf_clear_autop');
  460. // function tf_clear_autop($content)
  461. // {
  462. // $content = str_ireplace('<p>', '', $content);
  463. // $content = str_ireplace('</p>', '', $content);
  464. // $content = str_ireplace('<br />', '', $content);
  465. // return $content;
  466. // }
  467. ?>