PageRenderTime 58ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/White Rock - Main/White-Rock-Theme/white-rock/shortcodes.php

https://gitlab.com/hop23typhu/list-theme
PHP | 267 lines | 180 code | 54 blank | 33 comment | 36 complexity | 4b3ab922c182960492106f3809604662 MD5 | raw file
  1. <?php
  2. //////////////////////////////////////////////////////////////////
  3. // Button shortcode
  4. //////////////////////////////////////////////////////////////////
  5. add_shortcode('button', 'shortcode_button');
  6. function shortcode_button($atts, $content = null) {
  7. $atts = shortcode_atts(
  8. array(
  9. 'size' => '',
  10. 'link' => '#',
  11. 'target' => '',
  12. 'color' => '',
  13. ), $atts);
  14. return '<span><a href="' . $atts['link'] . '" target="' . $atts['target'] . '" class="' . $atts['size'] .' '. $atts['color'] . '">' .do_shortcode($content). '</a></span>';
  15. }
  16. add_shortcode('button_progression', 'shortcode_button_progression');
  17. function shortcode_button_progression($atts, $content = null) {
  18. $atts = shortcode_atts(
  19. array(
  20. 'size' => '',
  21. 'link' => '#',
  22. 'target' => '',
  23. 'color' => '',
  24. ), $atts);
  25. return '<span><a href="' . $atts['link'] . '" target="' . $atts['target'] . '" class="' . $atts['size'] .' '. $atts['color'] . '">' .do_shortcode($content). '</a></span>';
  26. }
  27. //////////////////////////////////////////////////////////////////
  28. // Background shortcode
  29. //////////////////////////////////////////////////////////////////
  30. add_shortcode('background', 'shortcode_background');
  31. function shortcode_background($atts, $content = null) {
  32. $atts = shortcode_atts(
  33. array(
  34. 'heading' => ''
  35. ), $atts);
  36. return '<span></div><!-- close .container -->
  37. <div class="clearfix"></div>
  38. <div class="content-highlight">
  39. <div class="container"><h3>' . $atts['heading'] . '</h3>' .do_shortcode($content). '</div>
  40. </div><!-- close .content-highlight -->
  41. <div class="container"></span>';
  42. }
  43. //////////////////////////////////////////////////////////////////
  44. // Divider shortcode
  45. //////////////////////////////////////////////////////////////////
  46. add_shortcode('divider', 'shortcode_divider');
  47. function shortcode_divider($atts, $html = null) {
  48. $html .= '<hr class="progression-hr"></hr>';
  49. return $html;
  50. }
  51. //////////////////////////////////////////////////////////////////
  52. // Column one_half shortcode
  53. //////////////////////////////////////////////////////////////////
  54. add_shortcode('one_half', 'shortcode_one_half');
  55. function shortcode_one_half($atts, $content = null) {
  56. $atts = shortcode_atts(
  57. array(
  58. 'last' => 'no',
  59. ), $atts);
  60. if($atts['last'] == 'yes') {
  61. return '<div class="grid2column lastcolumn">' .do_shortcode($content). '</div><div class="clearfix"></div>';
  62. } else {
  63. return '<div class="grid2column">' .do_shortcode($content). '</div>';
  64. }
  65. }
  66. //////////////////////////////////////////////////////////////////
  67. // Column one_third shortcode
  68. //////////////////////////////////////////////////////////////////
  69. add_shortcode('one_third', 'shortcode_one_third');
  70. function shortcode_one_third($atts, $content = null) {
  71. $atts = shortcode_atts(
  72. array(
  73. 'last' => 'no',
  74. ), $atts);
  75. if($atts['last'] == 'yes') {
  76. return '<div class="grid3column lastcolumn">' .do_shortcode($content). '</div><div class="clearfix"></div>';
  77. } else {
  78. return '<div class="grid3column">' .do_shortcode($content). '</div>';
  79. }
  80. }
  81. //////////////////////////////////////////////////////////////////
  82. // Column two_third shortcode
  83. //////////////////////////////////////////////////////////////////
  84. add_shortcode('two_third', 'shortcode_two_third');
  85. function shortcode_two_third($atts, $content = null) {
  86. $atts = shortcode_atts(
  87. array(
  88. 'last' => 'no',
  89. ), $atts);
  90. if($atts['last'] == 'yes') {
  91. return '<div class="grid3columnbig lastcolumn">' .do_shortcode($content). '</div><div class="clearfix"></div>';
  92. } else {
  93. return '<div class="grid3columnbig">' .do_shortcode($content). '</div>';
  94. }
  95. }
  96. //////////////////////////////////////////////////////////////////
  97. // Column one_fourth shortcode
  98. //////////////////////////////////////////////////////////////////
  99. add_shortcode('one_fourth', 'shortcode_one_fourth');
  100. function shortcode_one_fourth($atts, $content = null) {
  101. $atts = shortcode_atts(
  102. array(
  103. 'last' => 'no',
  104. ), $atts);
  105. if($atts['last'] == 'yes') {
  106. return '<div class="grid4column lastcolumn">' .do_shortcode($content). '</div><div class="clearfix"></div>';
  107. } else {
  108. return '<div class="grid4column">' .do_shortcode($content). '</div>';
  109. }
  110. }
  111. //////////////////////////////////////////////////////////////////
  112. // Column three_fourth shortcode
  113. //////////////////////////////////////////////////////////////////
  114. add_shortcode('three_fourth', 'shortcode_three_fourth');
  115. function shortcode_three_fourth($atts, $content = null) {
  116. $atts = shortcode_atts(
  117. array(
  118. 'last' => 'no',
  119. ), $atts);
  120. if($atts['last'] == 'yes') {
  121. return '<div class="grid4columnbig lastcolumn">' .do_shortcode($content). '</div><div class="clearfix"></div>';
  122. } else {
  123. return '<div class="grid4columnbig">' .do_shortcode($content). '</div>';
  124. }
  125. }
  126. //////////////////////////////////////////////////////////////////
  127. // toggle shortcode
  128. //////////////////////////////////////////////////////////////////
  129. add_shortcode('toggle', 'shortcode_toggle');
  130. function shortcode_toggle($atts, $content = null) {
  131. $atts = shortcode_atts(
  132. array(
  133. 'status' => '',
  134. 'title' => '',
  135. 'target' => '',
  136. 'color' => '',
  137. ), $atts);
  138. return '<span><ul class="progression-toggle"><li class="progression_active">' . $atts['title'] . '</li><div class="div_progression_toggle ' . $atts['status'] . '">' .do_shortcode($content). '</div></ul></span>';
  139. }
  140. //////////////////////////////////////////////////////////////////
  141. // Add Tabs shortcode
  142. //////////////////////////////////////////////////////////////////
  143. add_shortcode( 'tabgroup', 'jqtools_tab_group' );
  144. function jqtools_tab_group( $atts, $content ){
  145. $GLOBALS['tab_count'] = 0;
  146. do_shortcode( $content );
  147. if( is_array( $GLOBALS['tabs'] ) ){
  148. $counter=1;
  149. $panes[] = '';
  150. foreach( $GLOBALS['tabs'] as $tab ){
  151. if($counter == 1) {
  152. $tabs[] = '<li class="progression-tab"><a href="#tab'.$counter.'">'.$tab['title'].'</a></li>';
  153. } else {
  154. $tabs[] = '<li class="progression-tab"><a href="#tab'.$counter.'">'.$tab['title'].'</a></li>';
  155. }
  156. if($counter == 1) {
  157. $panes[] = '<div id="tab'.$counter.'">'.$tab['content'].'</div>';
  158. } else {
  159. $panes[] = '<div id="tab'.$counter.'">'.$tab['content'].'</div>';
  160. }
  161. $counter++;
  162. }
  163. $panes[] = '';
  164. $return = "".'<!-- the tabs --><div class="progression-tab-container"><ul class="progression-etabs">'.implode( "\n", $tabs ).'</ul>'."\n".'<!-- tab "panes" -->'.implode( "\n", $panes ).''."\n</div>";
  165. }
  166. return $return;
  167. }
  168. add_shortcode( 'tab', 'jqtools_tab' );
  169. function jqtools_tab( $atts, $content ){
  170. extract(shortcode_atts(array(
  171. 'title' => 'Tab %d'
  172. ), $atts));
  173. $x = $GLOBALS['tab_count'];
  174. $GLOBALS['tabs'][$x] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' => $content );
  175. $GLOBALS['tab_count']++;
  176. }
  177. //////////////////////////////////////////////////////////////////
  178. // Add buttons to tinyMCE
  179. //////////////////////////////////////////////////////////////////
  180. add_action('init', 'add_button');
  181. function add_button() {
  182. if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages')){
  183. return;
  184. }
  185. if ( get_user_option('rich_editing') == 'true' ) {
  186. global $typenow;
  187. if (empty($typenow) && !empty($_GET['post'])) {
  188. $post = get_post($_GET['post']);
  189. $typenow = $post->post_type;
  190. }
  191. if ("portfolio" == $typenow || "product" == $typenow || "post" == $typenow || "page" == $typenow){
  192. add_filter('mce_external_plugins', 'add_plugin');
  193. add_filter('mce_buttons_3', 'register_button');
  194. }
  195. }
  196. }
  197. function register_button($buttons) {
  198. array_push($buttons, "button", "button_progression", "one_half", "one_third", "two_third", "one_fourth", "three_fourth", "toggle", "tabs", "divider");
  199. return $buttons;
  200. }
  201. function add_plugin($plugin_array) {
  202. $plugin_array['button'] = get_template_directory_uri().'/tinymce/customcodes.js';
  203. $plugin_array['button_progression'] = get_template_directory_uri().'/tinymce/customcodes.js';
  204. $plugin_array['one_half'] = get_template_directory_uri().'/tinymce/customcodes.js';
  205. $plugin_array['one_third'] = get_template_directory_uri().'//tinymce/customcodes.js';
  206. $plugin_array['two_third'] = get_template_directory_uri().'/tinymce/customcodes.js';
  207. $plugin_array['one_fourth'] = get_template_directory_uri().'/tinymce/customcodes.js';
  208. $plugin_array['three_fourth'] = get_template_directory_uri().'/tinymce/customcodes.js';
  209. $plugin_array['toggle'] = get_template_directory_uri().'/tinymce/customcodes.js';
  210. $plugin_array['tabs'] = get_template_directory_uri().'/tinymce/customcodes.js';
  211. $plugin_array['divider'] = get_template_directory_uri().'/tinymce/customcodes.js';
  212. return $plugin_array;
  213. }