PageRenderTime 26ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/master-slider/admin/includes/msp-admin-functions.php

https://gitlab.com/stevie007/cinostaging
PHP | 141 lines | 70 code | 41 blank | 30 comment | 8 complexity | f339acb86e2d94f47d4815cff794113c MD5 | raw file
  1. <?php // admin related functions
  2. /**
  3. * Get all master slider admin screen ids
  4. *
  5. * @return array
  6. */
  7. function msp_get_screen_ids() {
  8. $the_screen_id = sanitize_title( MSWP_SLUG );
  9. return apply_filters( 'masterslider_admin_screen_ids', array(
  10. 'toplevel_page_' . $the_screen_id
  11. ) );
  12. }
  13. function msp_get_sliders_custom_css( $slider_status = 'published' ) {
  14. global $mspdb;
  15. $slider_status = sprintf( "status='%s'", $slider_status );
  16. $sliders_result = $mspdb->get_sliders( 0, 0, 'ID', 'DESC', $slider_status );
  17. $sliders_custom_css = array();
  18. if( $sliders_result ) {
  19. foreach ( $sliders_result as $slider ) {
  20. $sliders_custom_css[] = msp_get_slider_background_css( $slider['ID'] );
  21. $sliders_custom_css[] = $slider['custom_styles'];
  22. }
  23. // remove empty records from array
  24. $sliders_custom_css = array_filter( $sliders_custom_css );
  25. }
  26. return apply_filters( 'masterslider_get_sliders_custom_css', implode( "\n", $sliders_custom_css ), $sliders_custom_css, $sliders_result );
  27. }
  28. // get stored slider's custom css code from database
  29. function msp_get_slider_custom_css( $slider_id ) {
  30. global $mspdb;
  31. $slider_custom_css = $mspdb->get_slider_field_val( $slider_id, 'custom_styles' );
  32. return $slider_custom_css ? $slider_custom_css : '';
  33. }
  34. function msp_get_slider_background_css( $slider_id ) {
  35. $slider_data = get_masterslider_parsed_data( $slider_id );
  36. $the_slider_bg = empty( $slider_data['setting']['bg_color'] ) ? '' : $slider_data['setting']['bg_color'];
  37. $the_slider_bg .= empty( $slider_data['setting']['bg_image'] ) ? '' : sprintf( ' url( %s ) repeat top left', msp_get_the_absolute_media_url( $slider_data['setting']['bg_image'] ) );
  38. $the_slider_bg = empty( $the_slider_bg ) ? '' : 'background:' . $the_slider_bg . ";";
  39. return empty( $the_slider_bg ) ? '' : sprintf( ".ms-parent-id-%d > .master-slider{ %s }", $slider_id, $the_slider_bg );
  40. }
  41. function msp_get_all_custom_css () {
  42. return apply_filters( 'masterslider_get_all_custom_css', msp_get_sliders_custom_css() );
  43. }
  44. /*-----------------------------------------------------------------------------------*/
  45. /**
  46. * Get custom styles and store them in custom.css file or use inline css fallback
  47. * This function will be called by masterslider save handler
  48. *
  49. * @return void
  50. */
  51. function msp_save_custom_styles() {
  52. $uploads = wp_upload_dir();
  53. $css_dir = apply_filters( 'masterslider_custom_css_dir', $uploads['basedir'] . '/' . MSWP_SLUG );
  54. $css_file = $css_dir . '/custom.css';
  55. $css_terms = "/*
  56. ===============================================================
  57. # CUSTOM CSS
  58. - Please do not edit this file. this file is generated by server-side code
  59. - Every changes here will be overwritten
  60. ===============================================================*/\n
  61. ";
  62. // Get all custom css styles
  63. $css = msp_get_all_custom_css();
  64. /**
  65. * Initialize the WP_Filesystem
  66. */
  67. global $wp_filesystem;
  68. if ( empty( $wp_filesystem ) ) {
  69. require_once ( ABSPATH.'/wp-admin/includes/file.php' );
  70. WP_Filesystem();
  71. }
  72. if ( wp_mkdir_p( $css_dir ) && ! $wp_filesystem->put_contents( $css_file, $css_terms.$css, 0644 ) ) {
  73. // if the directory is not writable, try inline css fallback
  74. msp_update_option( 'custom_inline_style' , $css ); // save css rules as option to print as inline css
  75. } else {
  76. $custom_css_ver = msp_get_option( 'masterslider_custom_css_ver', '1.0' );
  77. $custom_css_ver = (float)$custom_css_ver + 0.1;
  78. msp_update_option( 'masterslider_custom_css_ver' , $custom_css_ver ); // disable inline css output
  79. msp_update_option( 'custom_inline_style' , '' );
  80. }
  81. }
  82. /**
  83. * Prints Pretty human-readable information about a variable (developer debug tool)
  84. * @param mixed The expression to be printed.
  85. * @param boolean $dump Whether to dump information about a variable or not
  86. * @param boolean $return When this parameter is set to TRUE, it will return the information rather than print it.
  87. * @return bool When the return parameter is TRUE, this function will return a string. Otherwise, the return value is TRUE.
  88. */
  89. if ( ! function_exists( 'axpp' ) ) {
  90. function axpp ( $expression, $dump = false, $return = false ) {
  91. if ( $return ) {
  92. return '<pre>' . print_r( $expression , true ) . '</pre>';
  93. } elseif ( $dump ) {
  94. echo '<pre>'; var_dump( $expression ); echo '</pre>';
  95. } else {
  96. echo '<pre>'; print_r ( $expression ); echo '</pre>';
  97. }
  98. return true;
  99. }
  100. }