Advertisement
rdusnr

Untitled

Jul 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.27 KB | None | 0 0
  1. <?php
  2. /* Modules config file */
  3.  
  4. add_filter( 'k_elements_shortcodes', array( 'Modules_Data', 'remove_shortcodes' ) );
  5.  
  6. class Modules_Data {
  7. static $shortcodes = array(
  8. 'kleo_grid' => array(
  9. 'option_name' => 'sh_feature_item',
  10. 'css_file' => 'feature_item',
  11. ),
  12. 'kleo_feature_item' => array(
  13. 'option_name' => 'sh_feature_item',
  14. 'css_file' => 'feature_item',
  15. ),
  16. 'kleo_register' => array(
  17. 'option_name' => 'sh_kleo_register',
  18. 'css_file' => 'kleo_register',
  19. ),
  20. 'kleo_news_focus' => array(
  21. 'option_name' => 'sh_news_focus',
  22. 'css_file' => 'news_focus',
  23. ),
  24. 'kleo_news_highlight' => array(
  25. 'option_name' => 'sh_news_highlight',
  26. 'css_file' => 'news_highlight',
  27. ),
  28. 'kleo_news_ticker' => array(
  29. 'option_name' => 'sh_news_ticker',
  30. 'css_file' => 'news_ticker',
  31. ),
  32. 'kleo_news_puzzle' => array(
  33. 'option_name' => 'sh_news_puzzle',
  34. 'css_file' => 'news_puzzle',
  35. ),
  36. 'kleo_pin' => array(
  37. 'option_name' => 'sh_poi',
  38. 'css_file' => 'poi_pins',
  39. ),
  40. 'kleo_pricing_table' => array(
  41. 'option_name' => 'sh_pricing_table',
  42. 'css_file' => 'pricing_table',
  43. ),
  44. 'kleo_pricing_table_item' => array(
  45. 'option_name' => 'sh_pricing_table',
  46. 'css_file' => 'pricing_table',
  47. ),
  48. );
  49.  
  50. /**
  51. * Modules that can be disabled from theme options
  52. * @var array
  53. */
  54. static $modules = array(
  55. 'kleo_clients' => array(
  56. 'option_name' => 'module_clients',
  57. ),
  58. 'kleo_testimonials' => array(
  59. 'option_name' => 'module_testimonials',
  60. ),
  61. 'kleo_portfolio' => array(
  62. 'option_name' => 'module_portfolio',
  63. ),
  64. );
  65.  
  66. public static function remove_shortcodes( $shortcodes ) {
  67. if ( ! empty( self::$modules ) ) {
  68. foreach ( self::$modules as $k => $module ) {
  69. if ( sq_option( $module['option_name'], 1 ) == 0 ) {
  70. unset( $shortcodes[ $k ] );
  71. }
  72. }
  73. }
  74.  
  75. if ( ! empty( self::$shortcodes ) ) {
  76. foreach ( self::$shortcodes as $k => $shortcode ) {
  77. if ( sq_option( $shortcode['option_name'], 1 ) == 0 ) {
  78. unset( $shortcodes[ $k ] );
  79. }
  80. }
  81. }
  82.  
  83. return $shortcodes;
  84. }
  85. }
  86.  
  87.  
  88. class SQ_Modules_Config {
  89.  
  90. public $sq_modules;
  91. public $shortcodes_list = array();
  92. public $modules_list = array();
  93.  
  94. public function __construct() {
  95.  
  96. $this->set_data();
  97.  
  98. /* Get modules instance */
  99. $this->sq_modules = SQ_Modules::getInstance();
  100.  
  101. /* If remove query option is ON */
  102. if ( sq_option( 'perf_remove_query', 0 ) == 1 ) {
  103. $this->sq_modules->query_string = null;
  104. }
  105. $this->define_scopes();
  106. $this->register_modules();
  107. $this->register_shortcodes();
  108.  
  109. //remove modules files on theme options save
  110. add_action( 'kleo-opts-saved', array( $this, 'remove_files' ), 10, 2 );
  111.  
  112. //replace default theme files
  113. add_action( 'wp_enqueue_scripts', array( $this, 'replace_assets' ), 30 );
  114.  
  115. //plugins file
  116. add_action( 'init', array( $this, 'register_plugins' ), 12 );
  117. add_action( 'activated_plugin', array( $this, 'detect_plugin_change' ), 10 );
  118. add_action( 'deactivated_plugin', array( $this, 'detect_plugin_change' ), 10 );
  119.  
  120. }
  121.  
  122. public function set_data() {
  123. $this->modules_list = Modules_Data::$modules;
  124. $this->shortcodes_list = Modules_Data::$shortcodes;
  125. }
  126.  
  127.  
  128. public function define_scopes() {
  129.  
  130. global $kleo_config;
  131.  
  132. $app = new Modules_Scope(
  133. 'app',
  134. 'app.css',
  135. trailingslashit( THEME_DIR ) . 'assets/css/modules/',
  136. trailingslashit( $kleo_config['custom_style_path'] ),
  137. trailingslashit( $kleo_config['custom_style_url'] )
  138. );
  139. $shortcodes = new Modules_Scope(
  140. 'shortcodes',
  141. 'shortcodes.css',
  142. trailingslashit( THEME_DIR ) . 'assets/css/shortcodes/',
  143. trailingslashit( $kleo_config['custom_style_path'] ),
  144. trailingslashit( $kleo_config['custom_style_url'] )
  145. );
  146. $plugins = new Modules_Scope(
  147. 'plugins',
  148. 'plugins.css',
  149. trailingslashit( THEME_DIR ) . 'assets/css/plugins/',
  150. trailingslashit( $kleo_config['custom_style_path'] ),
  151. trailingslashit( $kleo_config['custom_style_url'] )
  152. );
  153. $combined = new Modules_Scope(
  154. 'combined',
  155. 'combined.css',
  156. trailingslashit( THEME_DIR ) . 'assets/css/',
  157. trailingslashit( $kleo_config['custom_style_path'] ),
  158. trailingslashit( $kleo_config['custom_style_url'] )
  159. );
  160.  
  161. $this->sq_modules->add_scope( $app );
  162. $this->sq_modules->add_scope( $shortcodes );
  163. $this->sq_modules->add_scope( $plugins );
  164. $this->sq_modules->add_scope( $combined );
  165. }
  166.  
  167. public function register_modules() {
  168.  
  169. $app = $this->sq_modules->get_scope_data( 'app' );
  170. $combined = $this->sq_modules->get_scope_data( 'combined' );
  171.  
  172. //main css theme structure
  173. $this->sq_modules->add_mod( $app, 'base' );
  174.  
  175. // Contact form functionality
  176. if ( sq_option( 'contact_form', 1 ) == 1 ) {
  177. $this->sq_modules->add_mod( $app, 'quick-contact-form' );
  178. SQ_Modules::add_option( 'contact_form' );
  179. }
  180.  
  181. // Portfolio
  182. if( sq_option( 'module_portfolio', 1 ) == 1 ) {
  183. $this->sq_modules->add_mod( $app, 'portfolio' );
  184. SQ_Modules::add_option( 'module_portfolio' );
  185. }
  186.  
  187. // Sidemenu functionality
  188. if( sq_option( 'side_menu', 1 ) == 1 ) {
  189. $this->sq_modules->add_mod( $app, 'sidemenu' );
  190. SQ_Modules::add_option( 'side_menu' );
  191. }
  192.  
  193. //combined extra css
  194. if ( sq_option( 'perf_combine_css', 0 ) == 1 ) {
  195. $this->sq_modules->add_mod( $combined, 'bootstrap', array('path' => trailingslashit( THEME_DIR ) . 'assets/css/bootstrap.min.css' ) );
  196. $this->sq_modules->add_mod( $app, 'magnific', array( 'path' => trailingslashit( THEME_DIR ) . 'assets/js/plugins/magnific-popup/magnific.css' ) );
  197. }
  198. }
  199.  
  200. public function register_shortcodes() {
  201.  
  202. $shortcodes = $this->sq_modules->get_scope_data( 'shortcodes' );
  203.  
  204. if ( ! empty($this->shortcodes_list )) {
  205. foreach ( $this->shortcodes_list as $k => $shortcode ) {
  206.  
  207. if( sq_option( $shortcode['option_name'], 1 ) == 1 ) {
  208. $this->sq_modules->add_mod( $shortcodes, $shortcode['css_file'] );
  209. }
  210. SQ_Modules::add_option( $shortcode['option_name'] );
  211.  
  212. }
  213. }
  214.  
  215. //popovers & tooltips always enabled
  216. $this->sq_modules->add_mod( $shortcodes, 'popover_tooltips' );
  217.  
  218. }
  219.  
  220.  
  221. function register_plugins() {
  222.  
  223. if ( $this->sq_modules->file_needs_generation( 'plugins' ) ) {
  224.  
  225. $plugins_scope = $this->sq_modules->get_scope_data( 'plugins' );
  226.  
  227. /* badgeOS */
  228. if ( class_exists( 'BadgeOS' ) ) {
  229. $this->sq_modules->add_mod( $plugins_scope ,'badgeos' );
  230. }
  231.  
  232. /* BP Cover Photo || BUDDYPRESS */
  233. if ( function_exists( 'bp_is_active' ) || function_exists( 'sq_bp_cover_photo_init' ) ) {
  234. $this->sq_modules->add_mod( $plugins_scope ,'bp-cover-photo' );
  235. }
  236.  
  237. /* BP Profile Search */
  238. if ( defined( 'BPS_VERSION' ) ) {
  239. $this->sq_modules->add_mod( $plugins_scope ,'bp-profile-search' );
  240. }
  241.  
  242. /* Contact Form 7 */
  243. if ( defined( 'WPCF7_VERSION' ) ) {
  244. $this->sq_modules->add_mod( $plugins_scope ,'contact-form-7' );
  245. }
  246.  
  247. /* Events Manager */
  248. if ( defined( 'EM_VERSION' ) ) {
  249. $this->sq_modules->add_mod( $plugins_scope ,'events-manager' );
  250. }
  251.  
  252. /* Geo My WP */
  253. if ( class_exists( 'GEO_my_WP' ) ) {
  254. $this->sq_modules->add_mod( $plugins_scope ,'geo-my-wp' );
  255. }
  256.  
  257. /* Mailchimp 4 WP */
  258. if ( defined( 'MC4WP_VERSION' ) ) {
  259. $this->sq_modules->add_mod( $plugins_scope ,'mc4wp' );
  260. }
  261. /* MyCred */
  262. if ( defined( 'myCRED_VERSION' ) ) {
  263. $this->sq_modules->add_mod( $plugins_scope ,'mycred' );
  264. }
  265.  
  266. /* PMPRO */
  267. if ( defined( 'PMPRO_VERSION' ) ) {
  268. $this->sq_modules->add_mod( $plugins_scope ,'pmpro' );
  269. }
  270.  
  271. /* Revslider */
  272. /*if ( class_exists( 'RevSliderBase' ) ) {
  273. $this->sq_modules->add_mod( $plugins_scope ,'revslider' );
  274. }*/
  275.  
  276. /* RtMedia */
  277. if ( class_exists( 'RTMedia' ) ) {
  278. $this->sq_modules->add_mod( $plugins_scope ,'rtmedia' );
  279. }
  280.  
  281. /* Social Articles */
  282. if ( class_exists( 'SocialArticles' ) ) {
  283. $this->sq_modules->add_mod( $plugins_scope ,'social-articles' );
  284. }
  285.  
  286. /* Visual composer */
  287. $this->sq_modules->add_mod( $plugins_scope ,'visual-composer' );
  288.  
  289. /* WPML */
  290. if( defined('ICL_SITEPRESS_VERSION') ) {
  291. $this->sq_modules->add_mod( $plugins_scope ,'wpml' );
  292. }
  293.  
  294. /* YITH Wishlist */
  295. if( defined('YITH_WCWL') ) {
  296. $this->sq_modules->add_mod( $plugins_scope ,'yith-wcwl' );
  297. }
  298.  
  299. /* BP Group Email Subscription */
  300. if ( function_exists( 'ass_loader' ) ) {
  301. $this->sq_modules->add_mod( $plugins_scope ,'bp-group-email-subscription' );
  302. }
  303.  
  304. /* Cometchat */
  305. $this->sq_modules->add_mod( $plugins_scope ,'cometchat' );
  306.  
  307. //Mediaelement styling
  308. $this->sq_modules->add_mod( $plugins_scope, 'mediaelement' );
  309.  
  310. //GDPR
  311. if ( defined( 'GDPR_VERSION' ) ) {
  312. $this->sq_modules->add_mod( $plugins_scope, 'gdpr' );
  313. }
  314.  
  315. }
  316. }
  317.  
  318.  
  319. /**
  320. * Replace theme assets with dynamically generated ones
  321. */
  322. public function replace_assets() {
  323.  
  324. /* Combined assets check */
  325. if ( sq_option( 'perf_combine_css', 0 ) == 1 ) {
  326.  
  327. $combined_content = $this->sq_modules->get_content( 'combined' );
  328. $combined_content .= $this->sq_modules->get_content( 'app' );
  329. $combined_content .= $this->sq_modules->get_content( 'shortcodes' );
  330. $combined_content .= $this->sq_modules->get_content( 'plugins' );
  331.  
  332. if ( $this->sq_modules->file_exists_and_check_generation( 'combined', $combined_content ) ) {
  333. wp_deregister_style( 'kleo-combined' );
  334. wp_register_style( 'kleo-combined', $this->sq_modules->mods->combined->output_url . $this->sq_modules->mods->combined->filename, array(), $this->sq_modules->query_string, 'all' );
  335.  
  336. //make sure fonts are loaded
  337. wp_enqueue_style( 'kleo-fonts' );
  338. }
  339. } else {
  340. $app_content = $this->sq_modules->get_content( 'app' );
  341. $app_content .= $this->sq_modules->get_content( 'shortcodes' );
  342.  
  343. if ( $this->sq_modules->file_exists_and_check_generation( 'app', $app_content ) ) {
  344. wp_deregister_style( 'kleo-app' );
  345. wp_register_style( 'kleo-app', $this->sq_modules->mods->app->output_url . $this->sq_modules->mods->app->filename, array(), $this->sq_modules->query_string, 'all' );
  346. }
  347.  
  348. if ( $this->sq_modules->file_exists_and_check_generation( 'plugins' ) ) {
  349. wp_deregister_style( 'kleo-plugins' );
  350. wp_register_style( 'kleo-plugins', $this->sq_modules->mods->plugins->output_url . $this->sq_modules->mods->plugins->filename, array(), $this->sq_modules->query_string, 'all' );
  351. }
  352. }
  353. }
  354.  
  355. /**
  356. * Remove dynamically generated app.css if a module setting has changed
  357. * @param $value
  358. * @param array $changed_values
  359. */
  360. public function remove_files( $value, $changed_values ) {
  361.  
  362. if ( is_array( $changed_values ) ) {
  363. foreach ( $changed_values as $k => $v ) {
  364. if ( in_array( $k, SQ_Modules::$options ) || $k == 'performance' || $k == 'perf_combine_css' ) {
  365. $this->sq_modules->remove_file( 'app' );
  366. $this->sq_modules->remove_file( 'combined' );
  367. $this->sq_modules->remove_file( 'plugins' );
  368. break;
  369. }
  370. }
  371. }
  372. }
  373.  
  374. /**
  375. * Regenerate theme css on plugin activate/deactivate
  376. */
  377. function detect_plugin_change( $plugin ) {
  378. $this->sq_modules->remove_file( 'plugins' );
  379. $this->sq_modules->remove_file( 'combined' );
  380. if(kleo_write_dynamic_css_file()) {
  381. kleo_write_dynamic_css_file();
  382. }
  383. }
  384.  
  385. }
  386.  
  387. if ( sq_option( 'performance', 0 ) == 1 ) {
  388. new SQ_Modules_Config();
  389. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement