PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/auto-repair/vamtam/classes/shortcode-overrides.php

https://gitlab.com/adwait.rise/guruautolines
PHP | 285 lines | 143 code | 52 blank | 90 comment | 20 complexity | d969020facae81f9bb2e2f00dfa75c09 MD5 | raw file
  1. <?php
  2. /**
  3. * Various filters and actions configuring some of the shortcodes
  4. *
  5. * @package wpv
  6. */
  7. /**
  8. * class WpvShortcodeOverrides
  9. */
  10. class WpvShortcodeOverrides {
  11. /**
  12. * add filters
  13. */
  14. public static function filters() {
  15. add_filter( 'wpv_multiwidget_tab_title', array( __CLASS__, 'multiwidget_tab_title' ), 10, 3 );
  16. add_action( 'wpv_multiwidget_single_title', array( __CLASS__, 'multiwidget_single_title' ), 10, 2 );
  17. add_filter( 'wpv_posts_widget_thumbnail_name', array( __CLASS__, 'posts_widget_thumbnail_name' ), 10, 2 );
  18. add_filter( 'wpv_posts_widget_img_size', array( __CLASS__, 'posts_widget_img_size' ), 10, 2 );
  19. add_filter( 'wpv_column_title', array( __CLASS__, 'column_title' ), 10, 2 );
  20. add_filter( 'excerpt_length', array( __CLASS__, 'excerpt_length' ) );
  21. add_filter( 'excerpt_more', array( __CLASS__, 'excerpt_more' ) );
  22. add_filter( 'wp_trim_excerpt', array( __CLASS__, 'prepare_excerpt' ), 1, 2 );
  23. add_filter( 'wp_title', array( __CLASS__, 'wp_title') );
  24. remove_filter( 'the_content', 'li_display_love_link', 100 );
  25. wp_embed_register_handler( 'wpv-swf', '#https?://[^\s]+?.swf$#i', array( __CLASS__, 'embed_handler_swf' ) );
  26. add_filter( 'pre_option_page_for_posts', create_function( '$value', 'return 0;' ) );
  27. add_filter( 'oembed_dataparse', array( __CLASS__, 'oembed_dataparse' ), 90, 3 );
  28. add_filter( 'nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 10, 2 );
  29. add_filter( 'nav_menu_css_class', array( __CLASS__, 'nav_menu_css_class' ), 11, 2 );
  30. add_action( 'wpv_body', array( __CLASS__, 'wpv_splash_screen' ) );
  31. add_filter( 'wpcf7_form_elements', array( __CLASS__, 'shortcodes_in_cf7' ) );
  32. add_filter( 'pre_option_wpv_header-layout', array( __CLASS__, 'header_layout' ) );
  33. }
  34. public static function prepare_excerpt( $text = '', $raw_excerpt ) {
  35. if ( '' == $raw_excerpt ) {
  36. $text = get_the_content('');
  37. $text = preg_replace( '/\[column.*?\]/', '', $text );
  38. $text = preg_replace( '/\[\/column\]/', '', $text );
  39. $text = strip_shortcodes( $text );
  40. /** This filter is documented in wp-includes/post-template.php */
  41. $text = apply_filters( 'the_content', $text );
  42. $text = str_replace(']]>', ']]&gt;', $text);
  43. $excerpt_length = apply_filters( 'excerpt_length', 55 );
  44. $excerpt_more = apply_filters( 'excerpt_more', ' ' . '[&hellip;]' );
  45. $text = wp_trim_words( $text, $excerpt_length, $excerpt_more );
  46. }
  47. return $text;
  48. }
  49. public static function header_layout( $layout ) {
  50. $logo_type = wpv_get_option( 'header-logo-type' );
  51. if ( $logo_type === 'names' ) {
  52. return 'standard';
  53. }
  54. return $layout;
  55. }
  56. public static function wp_title( $title ) {
  57. if ( empty( $title ) && ( is_home() || is_front_page() ) ) {
  58. $description = get_bloginfo( 'description' );
  59. return get_bloginfo( 'name' ) . ( ! empty( $description ) ? ' | ' . $description : '' );
  60. }
  61. return $title;
  62. }
  63. /**
  64. * enable any shortcodes in CF7
  65. * @param string $form original html
  66. * @return string parsed with do_shortcode
  67. */
  68. public static function shortcodes_in_cf7( $form ) {
  69. return do_shortcode( wpv_fix_shortcodes( $form ) );
  70. }
  71. /**
  72. * Show a splash screen on some pages
  73. */
  74. public static function wpv_splash_screen() {
  75. if ( wpv_post_meta( null, 'show-splash-screen', true ) !== 'true' ) {
  76. return;
  77. }
  78. echo '<div class="wpv-splash-screen">
  79. <div class="wpv-splash-screen-logo"></div>
  80. </div>';
  81. }
  82. /**
  83. * Remove unnecessary menu item classes
  84. *
  85. * @param array $classes current menu item classes
  86. * @param object $item menu item
  87. * @param object $args menu item args
  88. * @return array filtered classes
  89. */
  90. public static function nav_menu_css_class( $classes, $item ) {
  91. if ( strpos( $item->url, '#' ) !== false && ( $key = array_search( 'current-menu-item', $classes ) ) !== false ) {
  92. unset( $classes[$key] );
  93. $classes[] = 'maybe-current-menu-item';
  94. $GLOBALS['wpv_menu_had_hash'] = true;
  95. }
  96. if ( isset( $GLOBALS['wpv_menu_had_hash'] ) && $GLOBALS['wpv_menu_had_hash'] ) {
  97. $classes = array_diff( $classes, array( 'current-menu-item', 'current-menu-ancestor', 'current-menu-parent' ) );
  98. }
  99. return $classes;
  100. }
  101. /**
  102. * Wrap oEmbeds in .wpv-video-frame
  103. *
  104. * @param string $output original oembed output
  105. * @param object $data data from the oEmbed provider
  106. * @param string $url original embed url
  107. * @return string $output wrapped in additional html
  108. */
  109. public static function oembed_dataparse( $output, $data, $url ) {
  110. if ( $data->type == 'video' )
  111. return '<div class="wpv-video-frame">'.$output.'</div>';
  112. return $output;
  113. }
  114. /**
  115. * Returns the HTML for the column titles, based on their type
  116. *
  117. * @param string $title title text
  118. * @param string $type title type
  119. * @return string column title html
  120. */
  121. public static function column_title( $title, $type ) {
  122. if ( $type === 'no-divider' )
  123. return "<h2 class='column-title'>$title</h2>";
  124. return WPV_Text_Divider::shortcode(
  125. array(
  126. 'more' => '',
  127. 'type' => $type,
  128. ), $title
  129. );
  130. }
  131. /**
  132. * Implements .swf oEmbeds
  133. *
  134. * @param array $matches preg_match matches
  135. * @param array $attr embed attributes
  136. * @param string $url embed url
  137. * @param array $rawattr raw attributes
  138. * @return string output html
  139. */
  140. public static function embed_handler_swf( $matches, $attr, $url, $rawattr ) {
  141. $embed = sprintf(
  142. '
  143. <div class="wpv-video-frame">
  144. <object width="%2$s" height="%3$s" type="application/x-shockwave-flash" data="%1$s">
  145. <param name="movie" value="%1$s" />
  146. <param name="allowFullScreen" value="true" />
  147. <param name="allowscriptaccess" value="always" />
  148. <param name="wmode" value="transparent" />
  149. <embed src="%1$s" type="application/x-shockwave-flash" wmode="transparent" allowscriptaccess="always" allowfullscreen="true" width="%2$s" height="%3$s" />
  150. </object>
  151. </div>',
  152. esc_attr( $matches[0] ),
  153. esc_attr( $attr['width'] ),
  154. esc_attr( $attr['height'] )
  155. );
  156. return apply_filters( 'wpv_embed_swf', $embed, $matches, $attr, $url, $rawattr );
  157. }
  158. /**
  159. * Correct image size for the multiwidget images
  160. *
  161. * @param int $img_size original image size
  162. * @param array $args widget arguments
  163. * @return int image size
  164. */
  165. public static function posts_widget_img_size( $img_size, $args ) {
  166. if ( strpos( $args['id'], 'footer-sidebar' ) !== false )
  167. return 43;
  168. return 350;
  169. }
  170. /**
  171. * Correct thumbnail name for the multiwidget images
  172. *
  173. * @param string $img_size original thumbnail
  174. * @param array $args widget arguments
  175. * @return string thumbnail name
  176. */
  177. public static function posts_widget_thumbnail_name( $img_size, $args ) {
  178. if ( strpos( $args['id'], 'footer-sidebar' ) !== false )
  179. return 'posts-widget-thumb-small';
  180. return 'posts-widget-thumb';
  181. }
  182. /**
  183. * Sets the excerpt length
  184. *
  185. * @param int $length original length
  186. * @return int excerpt length
  187. */
  188. public static function excerpt_length( $length ) {
  189. global $wpv_loop_vars;
  190. if ( isset( $wpv_loop_vars ) && $wpv_loop_vars['news'] )
  191. return 15;
  192. return $length;
  193. }
  194. /**
  195. * Sets the excerpt ending
  196. *
  197. * @param string $more original ending
  198. * @return string excerpt ending
  199. */
  200. public static function excerpt_more( $more ) {
  201. return '...';
  202. }
  203. /**
  204. * Add the tabbed widget icons
  205. * @param string $title current tab title
  206. * @param string $slug current tab slug
  207. * @param string $single if this is the only tab shown
  208. * @return string current tab title with icon
  209. */
  210. public static function multiwidget_tab_title( $title, $slug, $single ) {
  211. if ( $single )
  212. return '';
  213. $icons = array(
  214. 'comment_count' => 'theme-heart',
  215. 'date' => 'theme-pencil',
  216. 'comments' => 'theme-comment',
  217. 'tags' => 'theme-tag',
  218. );
  219. if ( isset( $icons[$slug] ) ) {
  220. $title = esc_attr( $title );
  221. return "<span title='$title'>".do_shortcode( '[icon name="'.$icons[$slug].'"]' ).'</span>';
  222. }
  223. return $title;
  224. }
  225. /**
  226. * Show the tab title if only one tab is to be displayed
  227. * @param string $only tab slug
  228. * @param string $title tab title
  229. */
  230. public static function multiwidget_single_title( $only, $title ) {
  231. echo wp_kses_post( $title );
  232. }
  233. }