Guest User

Untitled

a guest
Dec 5th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tagdiv
  5. * Date: 07.09.2017
  6. * Time: 11:32
  7. */
  8.  
  9.  
  10. include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  11.  
  12. global $main_theme_stylesheet_directory_path;
  13.  
  14. if ( is_plugin_active( 'td-mobile-plugin/td-mobile-plugin.php' ) && class_exists( 'td_mobile_theme' ) && td_mobile_theme::is_mobile() ) {
  15.  
  16. add_filter( 'theme_root', 'get_main_theme_root', 998, 1);
  17. function get_main_theme_root( $theme_root ) {
  18. global $main_theme_stylesheet_directory_path;
  19. $main_theme_stylesheet_directory_path = $theme_root;
  20. return $theme_root;
  21. }
  22. }
  23.  
  24. $theme_path = get_template_directory();
  25.  
  26. if ( empty( $main_theme_stylesheet_directory_path ) ) {
  27. $main_theme_stylesheet_directory_path = $theme_path;
  28. } else {
  29. $main_theme_stylesheet_directory_path .= $theme_path;
  30. }
  31.  
  32. require_once( $main_theme_stylesheet_directory_path . '/includes/wp_booster/td_api.php');
  33. require_once( $main_theme_stylesheet_directory_path . '/includes/wp_booster/td_fonts.php');
  34.  
  35.  
  36. abstract class tds_api extends td_api_base {
  37.  
  38. static function add($template_id, $params_array = '') {
  39. parent::add_component(__CLASS__, $template_id, $params_array);
  40. }
  41.  
  42. static function update($template_id, $params_array = '') {
  43. parent::update_component(__CLASS__, $template_id, $params_array);
  44. }
  45.  
  46. static function get_all() {
  47. return parent::get_all_components_metadata(__CLASS__);
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54. protected abstract function get_style_att( $att_name );
  55.  
  56. protected abstract function render( $index_style = '' );
  57.  
  58. static function get_style_group_params( $group, $index_style = '' ) {
  59. $params = array();
  60. $styles = self::get_all();
  61.  
  62. foreach ( $styles as $style_id => $style ) {
  63. if ( $style['group'] === $group ) {
  64. foreach ( $style['params'] as $param ) {
  65.  
  66. $key = $style_id . '-' . $param['param_name'];
  67. if ( '' !== $index_style ) {
  68. $key .= '-' . $index_style;
  69. }
  70.  
  71. if ( is_array( $param['value'] ) && count( $param['value'] ) ) {
  72. reset( $param['value'] );
  73. $params[ $key ] = current( $param['value'] );
  74. } else {
  75. $params[ $key ] = $param['value'];
  76. }
  77. }
  78. }
  79. }
  80. return $params;
  81. }
  82.  
  83. static function get_styles_for_panel( $group, $default_value = '' ) {
  84. $styles = array();
  85.  
  86. foreach ( self::get_all() as $style_id => $style ) {
  87. if ( $style['group'] === $group ) {
  88. if ( ! empty( $default_value ) && $default_value === $style_id ) {
  89. $style_id = '';
  90. }
  91.  
  92. $styles[] = array(
  93. 'text' => $style['title'],
  94. 'val' => $style_id
  95. );
  96. }
  97. }
  98. return $styles;
  99. }
  100.  
  101. static function get_styles_by_group( $group ) {
  102. $styles = array();
  103.  
  104. foreach ( self::get_all() as $style_id => $style ) {
  105. if ( $style['group'] === $group ) {
  106. $styles[ $style_id ] = $style;
  107. }
  108. }
  109. return $styles;
  110. }
  111.  
  112. static function get_styles_for_mapping( $group, $use_global = true ) {
  113. $styles = array();
  114.  
  115. foreach ( self::get_all() as $style_id => $style ) {
  116. if ( $style['group'] === $group ) {
  117. $styles[$style['title']] = $style_id;
  118. }
  119. }
  120. if ( $use_global ) {
  121. return array_merge( array( '- Global Style -' => ''), $styles );
  122. }
  123. return $styles;
  124. }
  125.  
  126. protected function get_shortcode_att( $att_name, $index_style = '' ) {
  127. return $this->get_att( $att_name, '', $index_style );
  128. }
  129.  
  130. protected function get_att_name( $att_name, $style_class = '', $index_style = '' ) {
  131. if ( ! empty( $style_class ) ) {
  132. $att_name = $style_class . '-' . $att_name;
  133. }
  134. if ( ! empty( $index_style ) ) {
  135. $att_name .= '-' . $index_style;
  136. }
  137. return $att_name;
  138. }
  139.  
  140. protected function get_att( $att_name, $style_class = '', $index_style = '' ) {
  141. $atts = $this->get_atts();
  142. if ( empty( $atts ) ) {
  143. td_util::error(__FILE__, get_class($this) . '->get_att(' . $att_name . ') Internal error: The atts are not set yet(AKA: the render template method was called without atts)');
  144. die;
  145. }
  146.  
  147. $key = $this->get_att_name( $att_name, $style_class, $index_style );
  148.  
  149. if ( ! isset( $atts[ $key ] ) ) {
  150. var_dump( $atts );
  151. td_util::error(__FILE__, 'Internal error: The system tried to use an att that does not exists! class_name: ' . get_class($this) . ' Att name: "' . $att_name . '" as "' . $key . '" The list with available atts is in td-multi-purpose.php register_templates()');
  152. die;
  153. }
  154.  
  155. return $atts[ $key ];
  156. }
  157.  
  158. static function get_class_style( $class ) {
  159. return str_replace( '_', '-', $class );
  160. }
  161.  
  162. static function get_group_style( $class ) {
  163. $styles = self::get_all();
  164. return str_replace( '_', '-', $styles[$class]['group'] );
  165. }
  166.  
  167. /**
  168. * A complete check must be done on template params.
  169. * Errors should be saved in $params and rendered all from there.
  170. *
  171. * @param $params
  172. *
  173. * @return bool
  174. */
  175. protected function check_params( $params ) {
  176. if ( !array_key_exists( 'title', $params ) ||
  177. !array_key_exists( 'params', $params ) ||
  178. !is_array( $params['params'] )) {
  179.  
  180. // @todo Warning here!
  181. return false;
  182. }
  183. foreach ( $params['params'] as $param ) {
  184. if ( !array_key_exists( 'param_name', $param ) ||
  185. !array_key_exists( 'type', $param ) ||
  186. !array_key_exists( 'value', $param ) ) {
  187.  
  188. // @todo Warning here!
  189. return false;
  190. }
  191. }
  192. return true;
  193. }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment