/wp-content/themes/method/lib/shortcodes/12-toggles.php

https://github.com/Canuckaholic/Pop-Digital · PHP · 248 lines · 197 code · 36 blank · 15 comment · 16 complexity · ccfd571f46b46a2d1cd8940e319983fb MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. */
  5. class mysiteToggles {
  6. /**
  7. *
  8. */
  9. function toggle( $atts = null, $content = null ) {
  10. if( $atts == 'generator' ) {
  11. $numbers = range( 1,10 );
  12. $option = array(
  13. 'name' => __( 'Toggle', MYSITE_ADMIN_TEXTDOMAIN ),
  14. 'value' => 'toggle',
  15. 'options' => array(
  16. array(
  17. 'name' => __( 'Toggle 1 Title', MYSITE_ADMIN_TEXTDOMAIN ),
  18. 'desc' => __( 'Type out the title that will display with your toggle.', MYSITE_ADMIN_TEXTDOMAIN ),
  19. 'id' => 'title',
  20. 'default' => '',
  21. 'type' => 'text',
  22. 'shortcode_multiply' => true
  23. ),
  24. array(
  25. 'name' => __( 'Toggle 1 Content', MYSITE_ADMIN_TEXTDOMAIN ),
  26. 'desc' => __( 'Type out the content that will display with your toggle. Shortcodes are accepted.', MYSITE_ADMIN_TEXTDOMAIN ),
  27. 'id' => 'content',
  28. 'default' => '',
  29. 'type' => 'textarea',
  30. 'shortcode_multiply' => true
  31. ),
  32. array(
  33. 'name' => __( 'Toggle 1 Color Variation <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  34. 'desc' => __( 'Choose one of our predefined color skins to use with your toggle.', MYSITE_ADMIN_TEXTDOMAIN ),
  35. 'id' => 'variation',
  36. 'default' => '',
  37. 'target' => 'color_variations',
  38. 'type' => 'select',
  39. 'shortcode_multiply' => true
  40. ),
  41. array(
  42. 'name' => __( 'Accordion <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  43. 'desc' => __( 'When using an accordian only one toggle can be opened at a time.<br /><br />When clicking on another toggle the previous one will close before opening the next.', MYSITE_ADMIN_TEXTDOMAIN ),
  44. 'id' => 'accordion_group',
  45. 'options' => array( 'true' => __('Group toggles into an accordion set', MYSITE_ADMIN_TEXTDOMAIN )),
  46. 'default' => '',
  47. 'type' => 'checkbox',
  48. 'shortcode_dont_multiply' => true,
  49. 'shortcode_optional_wrap' => true
  50. ),
  51. array(
  52. 'name' => __( 'Total Number of Additional Toggles <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  53. 'desc' => __( 'Select more toggles to display in the group.', MYSITE_ADMIN_TEXTDOMAIN ),
  54. 'id' => 'multiply',
  55. 'default' => '',
  56. 'options' => $numbers,
  57. 'type' => 'select',
  58. 'shortcode_multiplier' => true
  59. ),
  60. 'shortcode_has_atts' => true,
  61. )
  62. );
  63. return $option;
  64. }
  65. extract(shortcode_atts(array(
  66. 'title' => '',
  67. 'variation' => '',
  68. ), $atts));
  69. $variation = ( $variation ) ? ' ' . trim( $variation ) . '_sprite' : '';
  70. $out = '<h6 class="toggle' . $variation . '"><a href="#">' . $title . '</a></h6>';
  71. $out .= '<div class="toggle_content" style="display: none;">';
  72. $out .= '<div class="block">';
  73. $out .= mysite_remove_wpautop( $content );
  74. $out .= '</div>';
  75. $out .= '</div>';
  76. return $out;
  77. }
  78. /**
  79. *
  80. */
  81. function toggle_framed( $atts = null, $content = null ) {
  82. if( $atts == 'generator' ) {
  83. $numbers = range( 1,10 );
  84. $option = array(
  85. 'name' => __( 'Toggle Framed', MYSITE_ADMIN_TEXTDOMAIN ),
  86. 'value' => 'toggle_framed',
  87. 'options' => array(
  88. array(
  89. 'name' => __( 'Toggle 1 Title', MYSITE_ADMIN_TEXTDOMAIN ),
  90. 'desc' => __( 'Type out the title that will display with your toggle.', MYSITE_ADMIN_TEXTDOMAIN ),
  91. 'id' => 'title',
  92. 'default' => '',
  93. 'type' => 'text',
  94. 'shortcode_multiply' => true
  95. ),
  96. array(
  97. 'name' => __( 'Toggle 1 Content', MYSITE_ADMIN_TEXTDOMAIN ),
  98. 'desc' => __( 'Type out the content that will display with your toggle. Shortcodes are accepted.', MYSITE_ADMIN_TEXTDOMAIN ),
  99. 'id' => 'content',
  100. 'default' => '',
  101. 'type' => 'textarea',
  102. 'shortcode_multiply' => true
  103. ),
  104. array(
  105. 'name' => __( 'Toggle 1 Color Variation <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  106. 'desc' => __( 'Choose one of our predefined color skins to use with your toggle.', MYSITE_ADMIN_TEXTDOMAIN ),
  107. 'id' => 'variation',
  108. 'default' => '',
  109. 'target' => 'color_variations',
  110. 'type' => 'select',
  111. 'shortcode_multiply' => true
  112. ),
  113. array(
  114. 'name' => __( 'Accordion <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  115. 'desc' => __( 'When using an accordian only one toggle can be opened at a time.<br /><br />When clicking on another toggle the previous one will close before opening the next.', MYSITE_ADMIN_TEXTDOMAIN ),
  116. 'id' => 'accordion_group',
  117. 'options' => array( 'true' => __('Group toggles into an accordion set', MYSITE_ADMIN_TEXTDOMAIN )),
  118. 'default' => '',
  119. 'type' => 'checkbox',
  120. 'shortcode_dont_multiply' => true,
  121. 'shortcode_optional_wrap' => true
  122. ),
  123. array(
  124. 'name' => __( 'Total Number of Additional Toggles <small>(optional)</small>', MYSITE_ADMIN_TEXTDOMAIN ),
  125. 'desc' => __( 'Select more toggles to display in the group.', MYSITE_ADMIN_TEXTDOMAIN ),
  126. 'id' => 'multiply',
  127. 'default' => '',
  128. 'options' => $numbers,
  129. 'type' => 'select',
  130. 'shortcode_multiplier' => true
  131. ),
  132. 'shortcode_has_atts' => true,
  133. )
  134. );
  135. return $option;
  136. }
  137. extract(shortcode_atts(array(
  138. 'title' => '',
  139. 'variation' => '',
  140. ), $atts));
  141. $variation = ( $variation ) ? ' ' . trim( $variation ) . '_sprite' : '';
  142. $out = '<div class="toggle_frame">';
  143. $out .= '<h6 class="toggle' . $variation . '"><a href="#">' . $title . '</a></h6>';
  144. $out .= '<div class="toggle_content" style="display: none;">';
  145. $out .= '<div class="block">';
  146. $out .= mysite_remove_wpautop( $content );
  147. $out .= '</div>';
  148. $out .= '</div>';
  149. $out .= '</div>';
  150. return $out;
  151. }
  152. /**
  153. *
  154. */
  155. function accordion_group( $atts = null, $content = null ) {
  156. $out = '';
  157. if (!preg_match_all("/(.?)\[(toggle_framed)\b(.*?)(?:(\/))?\](?:(.+?)\[\/toggle_framed\])?(.?)/s", $content, $matches)) {
  158. if (!preg_match_all("/(.?)\[(toggle)\b(.*?)(?:(\/))?\](?:(.+?)\[\/toggle\])?(.?)/s", $content, $matches)){
  159. return mysite_remove_wpautop( $content );
  160. } else {
  161. for($i = 0; $i < count($matches[0]); $i++) {
  162. $matches[3][$i] = shortcode_parse_atts( $matches[3][$i] );
  163. }
  164. for($i = 0; $i < count($matches[0]); $i++) {
  165. $out .= '<h6 class="toggle_accordion"><a href="#">' . $matches[3][$i]['title'] . '</a></h6>';
  166. $out .= '<div class="toggle_content" style="display: none;">';
  167. $out .= '<div class="block">';
  168. $out .= mysite_remove_wpautop( $matches[5][$i] );
  169. $out .= '</div>';
  170. $out .= '</div>';
  171. }
  172. return '<div class="toggle_frame_set">' . $out . '</div>';
  173. }
  174. } else {
  175. for($i = 0; $i < count($matches[0]); $i++) {
  176. $matches[3][$i] = shortcode_parse_atts( $matches[3][$i] );
  177. }
  178. for($i = 0; $i < count($matches[0]); $i++) {
  179. $out .= '<div class="toggle_frame">';
  180. $out .= '<h6 class="toggle_accordion"><a href="#">' . $matches[3][$i]['title'] . '</a></h6>';
  181. $out .= '<div class="toggle_content" style="display: none;">';
  182. $out .= '<div class="block">';
  183. $out .= mysite_remove_wpautop( $matches[5][$i] );
  184. $out .= '</div>';
  185. $out .= '</div>';
  186. $out .= '</div>';
  187. }
  188. return '<div class="toggle_frame_set">' . $out . '</div>';
  189. }
  190. }
  191. /**
  192. *
  193. */
  194. function _options( $class ) {
  195. $shortcode = array();
  196. $class_methods = get_class_methods( $class );
  197. foreach( $class_methods as $method ) {
  198. if( $method[0] != '_' && $method != 'accordion_group' ) {
  199. $shortcode[] = call_user_func(array( &$class, $method ), $atts = 'generator' );
  200. }
  201. }
  202. $options = array(
  203. 'name' => __( 'Toggles', MYSITE_ADMIN_TEXTDOMAIN ),
  204. 'desc' => __( 'Choose which type of toggle you wish to use.', MYSITE_ADMIN_TEXTDOMAIN ),
  205. 'value' => 'toggles',
  206. 'options' => $shortcode,
  207. 'shortcode_has_types' => true
  208. );
  209. return $options;
  210. }
  211. }
  212. ?>