| @@ -9,596 +9,601 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace MainWP\Dashboard; |
| 12 | 12 | |
| 13 | +// Exit if accessed directly. | |
| 14 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 15 | + exit; | |
| 16 | +} | |
| 17 | + | |
| 13 | 18 | /** |
| 14 | 19 | * Class MainWP_Settings |
| 15 | 20 | * |
| 16 | 21 | * @package MainWP\Dashboard |
| 17 | 22 | */ |
| 18 | -class MainWP_Demo_Handle { | |
| 23 | +class MainWP_Demo_Handle { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 19 | 24 | |
| 20 | - //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 25 | + //phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery | |
| 21 | 26 | |
| 22 | - /** | |
| 23 | - * Protected static variable to hold the single instance of the class. | |
| 24 | - * | |
| 25 | - * @var mixed Default null | |
| 26 | - */ | |
| 27 | - protected static $instance = null; | |
| 27 | + /** | |
| 28 | + * Protected static variable to hold the single instance of the class. | |
| 29 | + * | |
| 30 | + * @var mixed Default null | |
| 31 | + */ | |
| 32 | + protected static $instance = null; | |
| 28 | 33 | |
| 29 | - /** | |
| 30 | - * Protected static variable to hold the single instance of the demo website ids. | |
| 31 | - * | |
| 32 | - * @var mixed Default array(). | |
| 33 | - */ | |
| 34 | - protected static $demo_website_ids = array(); | |
| 35 | - /** | |
| 36 | - * Get Class Name | |
| 37 | - * | |
| 38 | - * @return __CLASS__ | |
| 39 | - */ | |
| 40 | - public static function get_class_name() { | |
| 41 | - return __CLASS__; | |
| 42 | - } | |
| 34 | + /** | |
| 35 | + * Protected static variable to hold the single instance of the demo website ids. | |
| 36 | + * | |
| 37 | + * @var mixed Default array(). | |
| 38 | + */ | |
| 39 | + protected static $demo_website_ids = array(); | |
| 40 | + /** | |
| 41 | + * Get Class Name | |
| 42 | + * | |
| 43 | + * @return __CLASS__ | |
| 44 | + */ | |
| 45 | + public static function get_class_name() { | |
| 46 | + return __CLASS__; | |
| 47 | + } | |
| 43 | 48 | |
| 44 | - /** | |
| 45 | - * Return the single instance of the class. | |
| 46 | - * | |
| 47 | - * @return mixed $instance The single instance of the class. | |
| 48 | - */ | |
| 49 | - public static function get_instance() { | |
| 50 | - if ( is_null( self::$instance ) ) { | |
| 51 | - self::$instance = new self(); | |
| 52 | - } | |
| 53 | - if ( empty( self::$demo_website_ids ) ) { | |
| 54 | - $added_demo = get_option( 'mainwp_demo_mode_added_ids', array() ); | |
| 55 | - if ( is_array( $added_demo ) && ! empty( $added_demo['sites_ids'] ) ) { | |
| 56 | - self::$demo_website_ids = $added_demo['sites_ids']; | |
| 57 | - } | |
| 49 | + /** | |
| 50 | + * Return the single instance of the class. | |
| 51 | + * | |
| 52 | + * @return mixed $instance The single instance of the class. | |
| 53 | + */ | |
| 54 | + public static function get_instance() { | |
| 55 | + if ( is_null( static::$instance ) ) { | |
| 56 | + static::$instance = new self(); | |
| 57 | + } | |
| 58 | + if ( empty( static::$demo_website_ids ) ) { | |
| 59 | + $added_demo = get_option( 'mainwp_demo_mode_added_ids', array() ); | |
| 60 | + if ( is_array( $added_demo ) && ! empty( $added_demo['sites_ids'] ) ) { | |
| 61 | + static::$demo_website_ids = $added_demo['sites_ids']; | |
| 62 | + } | |
| 58 | 63 | |
| 59 | - if ( empty( self::$demo_website_ids ) || ! array( self::$demo_website_ids ) ) { | |
| 60 | - self::$demo_website_ids = array( -1 ); // for single assign. | |
| 61 | - } | |
| 62 | - } | |
| 63 | - return self::$instance; | |
| 64 | - } | |
| 64 | + if ( empty( static::$demo_website_ids ) || ! is_array( static::$demo_website_ids ) ) { | |
| 65 | + static::$demo_website_ids = array( -1 ); // for single assign. | |
| 66 | + } | |
| 67 | + } | |
| 68 | + return static::$instance; | |
| 69 | + } | |
| 65 | 70 | |
| 66 | - /** | |
| 67 | - * Method init_data_demo() | |
| 68 | - * | |
| 69 | - * Handle init data mode. | |
| 70 | - */ | |
| 71 | - public function init_data_demo() { | |
| 72 | - if ( isset( $_GET['enable_demo_mode'] ) && 'yes' === $_GET['enable_demo_mode'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized.Recommended | |
| 73 | - $this->import_data_demo(); | |
| 74 | - MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 ); | |
| 75 | - ?> | |
| 76 | - <script type="text/javascript"> | |
| 77 | - jQuery( document ).ready( function( $ ) { | |
| 78 | - setTimeout(function () { | |
| 79 | - location.href = 'admin.php?page=mainwp_tab&message=enable-demo-mode'; | |
| 80 | - }, 100); | |
| 81 | - }); | |
| 82 | - </script> | |
| 83 | - <?php | |
| 84 | - } | |
| 85 | - } | |
| 71 | + /** | |
| 72 | + * Method init_data_demo() | |
| 73 | + * | |
| 74 | + * Handle init data mode. | |
| 75 | + */ | |
| 76 | + public function init_data_demo() { | |
| 77 | + if ( isset( $_GET['enable_demo_mode'] ) && 'yes' === $_GET['enable_demo_mode'] ) { // phpcs:ignore WordPress.Security.NonceVerification,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized.Recommended | |
| 78 | + $this->import_data_demo(); | |
| 79 | + MainWP_Utility::update_option( 'mainwp_enable_guided_tours', 1 ); | |
| 80 | + ?> | |
| 81 | + <script type="text/javascript"> | |
| 82 | + jQuery( document ).ready( function( $ ) { | |
| 83 | + setTimeout(function () { | |
| 84 | + location.href = 'admin.php?page=mainwp_tab&message=enable-demo-mode'; | |
| 85 | + }, 100); | |
| 86 | + }); | |
| 87 | + </script> | |
| 88 | + <?php | |
| 89 | + } | |
| 90 | + } | |
| 86 | 91 | |
| 87 | - /** | |
| 88 | - * | |
| 89 | - * Handle detect if it's instawp site. | |
| 90 | - */ | |
| 91 | - public static function is_instawp_site() { | |
| 92 | - $urlparts = wp_parse_url( home_url() ); | |
| 93 | - $domain = $urlparts['host']; | |
| 94 | - return false !== stripos( $domain, 'instawp.xyz' ); | |
| 95 | - } | |
| 92 | + /** | |
| 93 | + * | |
| 94 | + * Handle detect if it's instawp site. | |
| 95 | + */ | |
| 96 | + public static function is_instawp_site() { | |
| 97 | + $urlparts = wp_parse_url( home_url() ); | |
| 98 | + $domain = $urlparts['host']; | |
| 99 | + return false !== stripos( $domain, 'instawp.xyz' ); | |
| 100 | + } | |
| 96 | 101 | |
| 97 | - /** | |
| 98 | - * Method import_data_demo() | |
| 99 | - * | |
| 100 | - * Handle import data demo. | |
| 101 | - * | |
| 102 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system() | |
| 103 | - * @uses \MainWP\Dashboard\MainWP_Utility::starts_with() | |
| 104 | - */ | |
| 105 | - public function import_data_demo() { //phpcs:ignore -- complex method. | |
| 102 | + /** | |
| 103 | + * Method import_data_demo() | |
| 104 | + * | |
| 105 | + * Handle import data demo. | |
| 106 | + * | |
| 107 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system() | |
| 108 | + * @uses \MainWP\Dashboard\MainWP_Utility::starts_with() | |
| 109 | + */ | |
| 110 | + public function import_data_demo() { //phpcs:ignore -- NOSONAR - complex method. | |
| 106 | 111 | |
| 107 | - $errors = array(); | |
| 112 | + $demo_files = array( | |
| 113 | + 'demo_mainwp_wp', | |
| 114 | + 'demo_mainwp_wp_clients', | |
| 115 | + 'demo_mainwp_wp_clients_contacts', | |
| 116 | + 'demo_mainwp_wp_options', | |
| 117 | + 'demo_mainwp_wp_actions', | |
| 118 | + ); | |
| 108 | 119 | |
| 109 | - $demo_files = array( | |
| 110 | - 'demo_mainwp_wp', | |
| 111 | - 'demo_mainwp_wp_clients', | |
| 112 | - 'demo_mainwp_wp_clients_contacts', | |
| 113 | - 'demo_mainwp_wp_options', | |
| 114 | - 'demo_mainwp_wp_actions', | |
| 115 | - ); | |
| 120 | + $wp_data_rows = array(); | |
| 121 | + $clients_data_rows = array(); | |
| 122 | + $contacts_data_rows = array(); | |
| 123 | + $wp_options_data_rows = array(); | |
| 124 | + $wp_action_data_rows = array(); | |
| 116 | 125 | |
| 117 | - $wp_data_rows = array(); | |
| 118 | - $clients_data_rows = array(); | |
| 119 | - $contacts_data_rows = array(); | |
| 120 | - $wp_options_data_rows = array(); | |
| 121 | - $wp_action_data_rows = array(); | |
| 126 | + foreach ( $demo_files as $file ) { | |
| 127 | + $file_path = MAINWP_PLUGIN_DIR . 'assets' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'demo' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . $file . '.json'; | |
| 128 | + $json_content = ''; | |
| 122 | 129 | |
| 123 | - foreach ( $demo_files as $file ) { | |
| 124 | - $file_path = MAINWP_PLUGIN_DIR . 'assets' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'demo' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . $file . '.json'; | |
| 125 | - $json_content = ''; | |
| 130 | + if ( file_exists( $file_path ) ) { | |
| 131 | + ob_start(); | |
| 132 | + include_once $file_path; // NOSONAR - WP compatible. | |
| 133 | + $json_content = ob_get_clean(); | |
| 134 | + } | |
| 126 | 135 | |
| 127 | - if ( file_exists( $file_path ) ) { | |
| 128 | - ob_start(); | |
| 129 | - include $file_path; | |
| 130 | - $json_content = ob_get_clean(); | |
| 131 | - } | |
| 136 | + if ( ! empty( $json_content ) ) { | |
| 137 | + $json_content = json_decode( $json_content, true ); | |
| 138 | + } | |
| 132 | 139 | |
| 133 | - if ( ! empty( $json_content ) ) { | |
| 134 | - $json_content = json_decode( $json_content, true ); | |
| 135 | - } | |
| 140 | + if ( ! is_array( $json_content ) || ! isset( $json_content['data'] ) ) { | |
| 141 | + continue; | |
| 142 | + } | |
| 136 | 143 | |
| 137 | - if ( ! is_array( $json_content ) || ! isset( $json_content['data'] ) ) { | |
| 138 | - continue; | |
| 139 | - } | |
| 144 | + if ( 'demo_mainwp_wp_clients' === $file ) { | |
| 145 | + $clients_data_rows = $json_content['data']; | |
| 146 | + } elseif ( 'demo_mainwp_wp' === $file ) { | |
| 147 | + $wp_data_rows = $json_content['data']; | |
| 148 | + } elseif ( 'demo_mainwp_wp_clients_contacts' === $file ) { | |
| 149 | + $contacts_data_rows = $json_content['data']; | |
| 150 | + } elseif ( 'demo_mainwp_wp_options' === $file ) { | |
| 151 | + $wp_options_data_rows = $json_content['data']; | |
| 152 | + } elseif ( 'demo_mainwp_wp_actions' === $file ) { | |
| 153 | + $wp_action_data_rows = $json_content['data']; | |
| 154 | + } | |
| 155 | + } | |
| 140 | 156 | |
| 141 | - if ( 'demo_mainwp_wp_clients' === $file ) { | |
| 142 | - $clients_data_rows = $json_content['data']; | |
| 143 | - } elseif ( 'demo_mainwp_wp' === $file ) { | |
| 144 | - $wp_data_rows = $json_content['data']; | |
| 145 | - } elseif ( 'demo_mainwp_wp_clients_contacts' === $file ) { | |
| 146 | - $contacts_data_rows = $json_content['data']; | |
| 147 | - } elseif ( 'demo_mainwp_wp_options' === $file ) { | |
| 148 | - $wp_options_data_rows = $json_content['data']; | |
| 149 | - } elseif ( 'demo_mainwp_wp_options' === $file ) { | |
| 150 | - $wp_options_data_rows = $json_content['data']; | |
| 151 | - } elseif ( 'demo_mainwp_wp_actions' === $file ) { | |
| 152 | - $wp_action_data_rows = $json_content['data']; | |
| 153 | - } | |
| 154 | - } | |
| 157 | + $count_inserted = 0; | |
| 158 | + $index = 0; | |
| 159 | + $demo_added_ids = array( | |
| 160 | + 'sites_ids' => array(), | |
| 161 | + 'clients_ids' => array(), | |
| 162 | + 'contacts_ids' => array(), | |
| 163 | + ); | |
| 164 | + if ( is_array( $wp_data_rows ) && ! empty( $wp_data_rows ) ) { | |
| 165 | + foreach ( $wp_data_rows as $row ) { | |
| 166 | + $websiteid = $this->add_demo_website( $row ); | |
| 167 | + if ( $websiteid ) { | |
| 168 | + ++$count_inserted; | |
| 169 | + $client_id = 0; | |
| 170 | + if ( isset( $clients_data_rows[ $index ] ) ) { | |
| 171 | + $client_id = $this->add_demo_client( $clients_data_rows[ $index ], array( $websiteid ) ); | |
| 155 | 172 | |
| 156 | - $count_inserted = 0; | |
| 157 | - $index = 0; | |
| 158 | - $demo_added_ids = array( | |
| 159 | - 'sites_ids' => array(), | |
| 160 | - 'clients_ids' => array(), | |
| 161 | - 'contacts_ids' => array(), | |
| 162 | - ); | |
| 163 | - if ( is_array( $wp_data_rows ) && ! empty( $wp_data_rows ) ) { | |
| 164 | - foreach ( $wp_data_rows as $row ) { | |
| 165 | - $websiteid = $this->add_demo_website( $row ); | |
| 166 | - if ( $websiteid ) { | |
| 167 | - ++$count_inserted; | |
| 168 | - $client_id = 0; | |
| 169 | - if ( isset( $clients_data_rows[ $index ] ) ) { | |
| 170 | - $client_id = $this->add_demo_client( $clients_data_rows[ $index ], array( $websiteid ) ); | |
| 173 | + if ( $client_id && isset( $contacts_data_rows[ $index ] ) ) { | |
| 174 | + $this->add_demo_contact( $contacts_data_rows[ $index ], $client_id ); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + $this->add_demo_wp_option( $wp_options_data_rows, $index, $websiteid ); | |
| 178 | + $this->add_demo_none_mainwp_action( $wp_action_data_rows, $index, $websiteid ); | |
| 179 | + // saved import ids to clear. | |
| 180 | + $demo_added_ids['sites_ids'][] = $websiteid; | |
| 181 | + if ( $client_id ) { | |
| 182 | + $demo_added_ids['clients_ids'][] = $client_id; | |
| 183 | + } | |
| 184 | + } | |
| 185 | + ++$index; | |
| 186 | + } | |
| 187 | + $data['count'] = $index; | |
| 188 | + $data['inserted'] = $count_inserted; | |
| 189 | + update_option( 'mainwp_demo_mode_added_ids', $demo_added_ids ); | |
| 190 | + MainWP_Utility::update_option( 'mainwp_setting_demo_mode_enabled', 1 ); | |
| 191 | + } | |
| 171 | 192 | |
| 172 | - if ( $client_id && isset( $contacts_data_rows[ $index ] ) ) { | |
| 173 | - $this->add_demo_contact( $contacts_data_rows[ $index ], $client_id ); | |
| 174 | - } | |
| 175 | - } | |
| 176 | - $this->add_demo_wp_option( $wp_options_data_rows, $index, $websiteid ); | |
| 177 | - $this->add_demo_none_mainwp_action( $wp_action_data_rows, $index, $websiteid ); | |
| 178 | - // saved import ids to clear. | |
| 179 | - $demo_added_ids['sites_ids'][] = $websiteid; | |
| 180 | - if ( $client_id ) { | |
| 181 | - $demo_added_ids['clients_ids'][] = $client_id; | |
| 182 | - } | |
| 183 | - } | |
| 184 | - ++$index; | |
| 185 | - } | |
| 186 | - $data['count'] = $index; | |
| 187 | - $data['inserted'] = $count_inserted; | |
| 188 | - update_option( 'mainwp_demo_mode_added_ids', $demo_added_ids ); | |
| 189 | - MainWP_Utility::update_option( 'mainwp_setting_demo_mode_enabled', 1 ); | |
| 190 | - } | |
| 193 | + if ( ! $index ) { | |
| 194 | + $data['error'] = esc_html__( 'Invalid demo data.', 'mainwp' ); | |
| 195 | + } | |
| 191 | 196 | |
| 192 | - if ( ! $index ) { | |
| 193 | - $data['error'] = esc_html__( 'Invalid demo data.', 'mainwp' ); | |
| 194 | - } | |
| 197 | + return $data; | |
| 198 | + } | |
| 195 | 199 | |
| 196 | - return $data; | |
| 197 | - } | |
| 198 | 200 | |
| 201 | + /** | |
| 202 | + * Method add_demo_client() | |
| 203 | + * | |
| 204 | + * Handle to add demo Client. | |
| 205 | + * | |
| 206 | + * @param array $params Array of data. | |
| 207 | + * @param array $selected_sites client sites ids. | |
| 208 | + */ | |
| 209 | + private function add_demo_client( $params, $selected_sites ) { | |
| 199 | 210 | |
| 200 | - /** | |
| 201 | - * Method add_demo_client() | |
| 202 | - * | |
| 203 | - * Handle to add demo Client. | |
| 204 | - * | |
| 205 | - * @param array $params Array of data. | |
| 206 | - * @param array $selected_sites client sites ids. | |
| 207 | - */ | |
| 208 | - private function add_demo_client( $params, $selected_sites ) { | |
| 211 | + if ( isset( $params['client_id'] ) ) { | |
| 212 | + unset( $params['client_id'] ); | |
| 213 | + } | |
| 214 | + $params['primary_contact_id'] = 0; | |
| 209 | 215 | |
| 210 | - if ( isset( $params['client_id'] ) ) { | |
| 211 | - unset( $params['client_id'] ); | |
| 212 | - } | |
| 213 | - $params['primary_contact_id'] = 0; | |
| 216 | + if ( empty( $params['created'] ) ) { | |
| 217 | + $params['created'] = time(); | |
| 218 | + } | |
| 214 | 219 | |
| 215 | - if ( empty( $params['created'] ) ) { | |
| 216 | - $params['created'] = time(); | |
| 217 | - } | |
| 220 | + $clientid = 0; | |
| 221 | + try { | |
| 222 | + $inserted = MainWP_DB_Client::instance()->update_client( $params ); | |
| 223 | + if ( $inserted ) { | |
| 224 | + $clientid = $inserted->client_id; | |
| 225 | + } | |
| 226 | + } catch ( \Exception $e ) { | |
| 227 | + $clientid = 0; | |
| 228 | + } | |
| 218 | 229 | |
| 219 | - $clientid = 0; | |
| 220 | - try { | |
| 221 | - $inserted = MainWP_DB_Client::instance()->update_client( $params ); | |
| 222 | - if ( $inserted ) { | |
| 223 | - $clientid = $inserted->client_id; | |
| 224 | - } | |
| 225 | - } catch ( \Exception $e ) { | |
| 226 | - $clientid = 0; | |
| 227 | - } | |
| 230 | + if ( $clientid && $selected_sites ) { | |
| 231 | + MainWP_DB_Client::instance()->update_selected_sites_for_client( $clientid, $selected_sites ); | |
| 232 | + } | |
| 233 | + return $clientid; | |
| 234 | + } | |
| 228 | 235 | |
| 229 | - if ( $clientid && $selected_sites ) { | |
| 230 | - MainWP_DB_Client::instance()->update_selected_sites_for_client( $clientid, $selected_sites ); | |
| 231 | - } | |
| 232 | - return $clientid; | |
| 233 | - } | |
| 236 | + /** | |
| 237 | + * Method add_demo_contact() | |
| 238 | + * | |
| 239 | + * Handle to add demo contact. | |
| 240 | + * | |
| 241 | + * @param array $params Array of data. | |
| 242 | + * @param int $client_id client id. | |
| 243 | + */ | |
| 244 | + private function add_demo_contact( $params, $client_id ) { | |
| 245 | + if ( isset( $params['contact_id'] ) ) { | |
| 246 | + unset( $params['contact_id'] ); | |
| 247 | + } | |
| 248 | + $params['contact_client_id'] = $client_id; | |
| 249 | + $contact_int = MainWP_DB_Client::instance()->update_client_contact( $params ); | |
| 250 | + if ( $contact_int ) { | |
| 251 | + $update = array( | |
| 252 | + 'client_id' => $client_id, | |
| 253 | + 'primary_contact_id' => $contact_int->contact_id, | |
| 254 | + ); | |
| 255 | + MainWP_DB_Client::instance()->update_client( $update ); | |
| 256 | + return $contact_int->contact_id; | |
| 257 | + } | |
| 258 | + return false; | |
| 259 | + } | |
| 234 | 260 | |
| 235 | - /** | |
| 236 | - * Method add_demo_contact() | |
| 237 | - * | |
| 238 | - * Handle to add demo contact. | |
| 239 | - * | |
| 240 | - * @param array $params Array of data. | |
| 241 | - * @param int $client_id client id. | |
| 242 | - */ | |
| 243 | - private function add_demo_contact( $params, $client_id ) { | |
| 244 | - if ( isset( $params['contact_id'] ) ) { | |
| 245 | - unset( $params['contact_id'] ); | |
| 246 | - } | |
| 247 | - $params['contact_client_id'] = $client_id; | |
| 248 | - $contact_int = MainWP_DB_Client::instance()->update_client_contact( $params ); | |
| 249 | - if ( $contact_int ) { | |
| 250 | - $update = array( | |
| 251 | - 'client_id' => $client_id, | |
| 252 | - 'primary_contact_id' => $contact_int->contact_id, | |
| 253 | - ); | |
| 254 | - MainWP_DB_Client::instance()->update_client( $update ); | |
| 255 | - return $contact_int->contact_id; | |
| 256 | - } | |
| 257 | - return false; | |
| 258 | - } | |
| 259 | 261 | |
| 260 | 262 | |
| 263 | + /** | |
| 264 | + * Method add_demo_website() | |
| 265 | + * | |
| 266 | + * Handle add demo website data. | |
| 267 | + * | |
| 268 | + * @param array $params Array of demo Site to add. | |
| 269 | + */ | |
| 270 | + private function add_demo_website( $params ) { | |
| 271 | + global $wpdb; | |
| 272 | + $userid = get_current_user_id(); | |
| 261 | 273 | |
| 262 | - /** | |
| 263 | - * Method add_demo_website() | |
| 264 | - * | |
| 265 | - * Handle add demo website data. | |
| 266 | - * | |
| 267 | - * @param array $params Array of demo Site to add. | |
| 268 | - */ | |
| 269 | - private function add_demo_website( $params ) { | |
| 270 | - global $wpdb; | |
| 271 | - $userid = get_current_user_id(); | |
| 274 | + if ( MainWP_Utility::ctype_digit( $userid ) && is_array( $params ) && isset( $params['url'] ) && ! empty( $params['url'] ) && isset( $params['adminname'] ) && ! empty( $params['adminname'] ) ) { | |
| 272 | 275 | |
| 273 | - if ( MainWP_Utility::ctype_digit( $userid ) && is_array( $params ) && isset( $params['url'] ) && ! empty( $params['url'] ) && isset( $params['adminname'] ) && ! empty( $params['adminname'] ) ) { | |
| 276 | + $existed = MainWP_DB::instance()->get_websites_by_url( $params['url'] ); | |
| 274 | 277 | |
| 275 | - $existed = MainWP_DB::instance()->get_websites_by_url( $params['url'] ); | |
| 278 | + if ( ! empty( $existed ) ) { | |
| 279 | + return false; | |
| 280 | + } | |
| 276 | 281 | |
| 277 | - if ( ! empty( $existed ) ) { | |
| 278 | - return false; | |
| 279 | - } | |
| 282 | + if ( isset( $params['id'] ) ) { | |
| 283 | + unset( $params['id'] ); | |
| 284 | + } | |
| 280 | 285 | |
| 281 | - if ( isset( $params['id'] ) ) { | |
| 282 | - unset( $params['id'] ); | |
| 283 | - } | |
| 286 | + $url = $params['url']; | |
| 284 | 287 | |
| 285 | - $url = $params['url']; | |
| 288 | + if ( '/' !== substr( $url, - 1 ) ) { | |
| 289 | + $url .= '/'; | |
| 290 | + } | |
| 286 | 291 | |
| 287 | - if ( '/' !== substr( $url, - 1 ) ) { | |
| 288 | - $url .= '/'; | |
| 289 | - } | |
| 292 | + $params['url'] = $url; | |
| 293 | + $params['userid'] = $userid; | |
| 294 | + $params['client_id'] = 0; // set: 0. | |
| 290 | 295 | |
| 291 | - $params['url'] = $url; | |
| 292 | - $params['userid'] = $userid; | |
| 293 | - $params['adminname'] = $params['adminname']; | |
| 294 | - $params['client_id'] = 0; // set: 0. | |
| 296 | + $syncValues = array( | |
| 297 | + 'dtsSync' => 0, | |
| 298 | + 'dtsSyncStart' => 0, | |
| 299 | + 'dtsAutomaticSync' => 0, | |
| 300 | + 'dtsAutomaticSyncStart' => 0, | |
| 301 | + 'totalsize' => 0, | |
| 302 | + 'extauth' => '', | |
| 303 | + 'sync_errors' => '', | |
| 304 | + ); | |
| 295 | 305 | |
| 296 | - $syncValues = array( | |
| 297 | - 'dtsSync' => 0, | |
| 298 | - 'dtsSyncStart' => 0, | |
| 299 | - 'dtsAutomaticSync' => 0, | |
| 300 | - 'dtsAutomaticSyncStart' => 0, | |
| 301 | - 'totalsize' => 0, | |
| 302 | - 'extauth' => '', | |
| 303 | - 'sync_errors' => '', | |
| 304 | - ); | |
| 306 | + if ( $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp' ), $params ) ) { | |
| 307 | + $websiteid = $wpdb->insert_id; | |
| 308 | + $syncValues['wpid'] = $websiteid; | |
| 309 | + $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_sync' ), $syncValues ); | |
| 310 | + $wpdb->insert( | |
| 311 | + MainWP_DB::instance()->get_table_name( 'wp_settings_backup' ), | |
| 312 | + array( | |
| 313 | + 'wpid' => $websiteid, | |
| 314 | + 'archiveFormat' => 'global', | |
| 315 | + ) | |
| 316 | + ); | |
| 305 | 317 | |
| 306 | - if ( $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp' ), $params ) ) { | |
| 307 | - $websiteid = $wpdb->insert_id; | |
| 308 | - $syncValues['wpid'] = $websiteid; | |
| 309 | - $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_sync' ), $syncValues ); | |
| 310 | - $wpdb->insert( | |
| 311 | - MainWP_DB::instance()->get_table_name( 'wp_settings_backup' ), | |
| 312 | - array( | |
| 313 | - 'wpid' => $websiteid, | |
| 314 | - 'archiveFormat' => 'global', | |
| 315 | - ) | |
| 316 | - ); | |
| 318 | + $website = new \stdClass(); | |
| 319 | + $website->id = $websiteid; | |
| 317 | 320 | |
| 318 | - $website = new \stdClass(); | |
| 319 | - $website->id = $websiteid; | |
| 321 | + $added = time(); | |
| 322 | + MainWP_DB::instance()->update_website_option( $website, 'added_timestamp', $added ); | |
| 320 | 323 | |
| 321 | - $added = time(); | |
| 322 | - MainWP_DB::instance()->update_website_option( $website, 'added_timestamp', $added ); | |
| 324 | + return $websiteid; | |
| 325 | + } | |
| 326 | + } | |
| 323 | 327 | |
| 324 | - return $websiteid; | |
| 325 | - } | |
| 326 | - } | |
| 328 | + return false; | |
| 329 | + } | |
| 327 | 330 | |
| 328 | - return false; | |
| 329 | - } | |
| 331 | + /** | |
| 332 | + * Method add_demo_wp_option() | |
| 333 | + * | |
| 334 | + * Handle add demo website options data. | |
| 335 | + * | |
| 336 | + * @param array $data_rows Array of Site options. | |
| 337 | + * @param index $index index of data. | |
| 338 | + * @param index $websiteid website id. | |
| 339 | + */ | |
| 340 | + private function add_demo_wp_option( $data_rows, $index, $websiteid ) { | |
| 341 | + global $wpdb; | |
| 342 | + if ( ! is_array( $data_rows ) || empty( $websiteid ) ) { | |
| 343 | + return; | |
| 344 | + } | |
| 330 | 345 | |
| 331 | - /** | |
| 332 | - * Method add_demo_wp_option() | |
| 333 | - * | |
| 334 | - * Handle add demo website options data. | |
| 335 | - * | |
| 336 | - * @param array $data_rows Array of Site options. | |
| 337 | - * @param index $index index of data. | |
| 338 | - * @param index $websiteid website id. | |
| 339 | - */ | |
| 340 | - private function add_demo_wp_option( $data_rows, $index, $websiteid ) { | |
| 341 | - global $wpdb; | |
| 342 | - if ( ! is_array( $data_rows ) || empty( $websiteid ) ) { | |
| 343 | - return; | |
| 344 | - } | |
| 346 | + $opt_names = array( | |
| 347 | + 'recent_posts', | |
| 348 | + 'recent_pages', | |
| 349 | + ); | |
| 345 | 350 | |
| 346 | - $opt_names = array( | |
| 347 | - 'recent_posts', | |
| 348 | - 'recent_pages', | |
| 349 | - ); | |
| 351 | + foreach ( $opt_names as $opt_name ) { | |
| 352 | + if ( isset( $data_rows[ $opt_name ] ) && ! empty( $data_rows[ $opt_name ][ $index ] ) ) { | |
| 353 | + $row = $data_rows[ $opt_name ][ $index ]; | |
| 354 | + if ( isset( $row['opt_id'] ) ) { | |
| 355 | + unset( $row['opt_id'] ); | |
| 356 | + $row['wpid'] = $websiteid; | |
| 357 | + $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_options' ), $row ); | |
| 358 | + } | |
| 359 | + } | |
| 360 | + } | |
| 361 | + } | |
| 350 | 362 | |
| 351 | - foreach ( $opt_names as $opt_name ) { | |
| 352 | - if ( isset( $data_rows[ $opt_name ] ) && ! empty( $data_rows[ $opt_name ][ $index ] ) ) { | |
| 353 | - $row = $data_rows[ $opt_name ][ $index ]; | |
| 354 | - if ( isset( $row['opt_id'] ) ) { | |
| 355 | - unset( $row['opt_id'] ); | |
| 356 | - $row['wpid'] = $websiteid; | |
| 357 | - $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_options' ), $row ); | |
| 358 | - } | |
| 359 | - } | |
| 360 | - } | |
| 361 | - } | |
| 363 | + /** | |
| 364 | + * Method add_demo_none_mainwp_action() | |
| 365 | + * | |
| 366 | + * Handle add demo none mainwp actions. | |
| 367 | + * | |
| 368 | + * @param array $data_rows Array of actions. | |
| 369 | + * @param index $index index of data. | |
| 370 | + * @param index $websiteid website id. | |
| 371 | + */ | |
| 372 | + private function add_demo_none_mainwp_action( $data_rows, $index, $websiteid ) { | |
| 373 | + global $wpdb; | |
| 374 | + } | |
| 362 | 375 | |
| 363 | - /** | |
| 364 | - * Method add_demo_none_mainwp_action() | |
| 365 | - * | |
| 366 | - * Handle add demo none mainwp actions. | |
| 367 | - * | |
| 368 | - * @param array $data_rows Array of actions. | |
| 369 | - * @param index $index index of data. | |
| 370 | - * @param index $websiteid website id. | |
| 371 | - */ | |
| 372 | - private function add_demo_none_mainwp_action( $data_rows, $index, $websiteid ) { | |
| 373 | - global $wpdb; | |
| 374 | - if ( ! is_array( $data_rows ) || empty( $websiteid ) ) { | |
| 375 | - return; | |
| 376 | - } | |
| 377 | - foreach ( $data_rows as $row ) { | |
| 378 | - if ( isset( $row['action_id'] ) && isset( $row['wpid'] ) && (int) $index === (int) $row['wpid'] ) { | |
| 379 | - unset( $row['action_id'] ); | |
| 380 | - $row['wpid'] = $websiteid; | |
| 381 | - $wpdb->insert( MainWP_DB::instance()->get_table_name( 'wp_actions' ), $row ); | |
| 382 | - } | |
| 383 | - } | |
| 384 | - } | |
| 376 | + /** | |
| 377 | + * Method delete_data_demo() | |
| 378 | + * | |
| 379 | + * Handle delete demo data . | |
| 380 | + */ | |
| 381 | + public function delete_data_demo() { | |
| 382 | + global $wpdb; | |
| 383 | + $demo_data_ids = get_option( 'mainwp_demo_mode_added_ids' ); | |
| 385 | 384 | |
| 386 | - /** | |
| 387 | - * Method delete_data_demo() | |
| 388 | - * | |
| 389 | - * Handle delete demo data . | |
| 390 | - */ | |
| 391 | - public function delete_data_demo() { | |
| 392 | - global $wpdb; | |
| 393 | - $demo_data_ids = get_option( 'mainwp_demo_mode_added_ids' ); | |
| 385 | + if ( is_array( $demo_data_ids ) ) { | |
| 386 | + if ( ! empty( $demo_data_ids['sites_ids'] ) ) { | |
| 387 | + foreach ( $demo_data_ids['sites_ids'] as $itemid ) { | |
| 388 | + MainWP_Manage_Sites_Handler::remove_website( $itemid ); | |
| 389 | + } | |
| 390 | + } | |
| 391 | + // to fix issue: change clients of demo site. | |
| 392 | + if ( ! empty( $demo_data_ids['clients_ids'] ) ) { | |
| 393 | + foreach ( $demo_data_ids['clients_ids'] as $itemid ) { | |
| 394 | + MainWP_DB_Client::instance()->delete_client( $itemid ); | |
| 395 | + } | |
| 396 | + } | |
| 397 | + } | |
| 398 | + MainWP_Utility::update_option( 'mainwp_setting_demo_mode_enabled', 0 ); | |
| 399 | + $this->clear_session_cached_demo_data(); | |
| 400 | + return array( | |
| 401 | + 'success' => 1, | |
| 402 | + ); | |
| 403 | + } | |
| 394 | 404 | |
| 395 | - if ( is_array( $demo_data_ids ) ) { | |
| 396 | - if ( ! empty( $demo_data_ids['sites_ids'] ) ) { | |
| 397 | - foreach ( $demo_data_ids['sites_ids'] as $itemid ) { | |
| 398 | - MainWP_Manage_Sites_Handler::remove_website( $itemid ); | |
| 399 | - } | |
| 400 | - } | |
| 401 | - // to fix issue: change clients of demo site. | |
| 402 | - if ( ! empty( $demo_data_ids['clients_ids'] ) ) { | |
| 403 | - foreach ( $demo_data_ids['clients_ids'] as $itemid ) { | |
| 404 | - MainWP_DB_Client::instance()->delete_client( $itemid ); | |
| 405 | - } | |
| 406 | - } | |
| 407 | - } | |
| 408 | - MainWP_Utility::update_option( 'mainwp_setting_demo_mode_enabled', 0 ); | |
| 409 | - $this->clear_session_cached_demo_data(); | |
| 410 | - return array( | |
| 411 | - 'success' => 1, | |
| 412 | - ); | |
| 413 | - } | |
| 405 | + /** | |
| 406 | + * Method delete_data_demo() | |
| 407 | + * | |
| 408 | + * Handle delete demo data . | |
| 409 | + */ | |
| 410 | + public function is_new_instance() { | |
| 411 | + global $wpdb; | |
| 412 | + $cache_key = 'mainwp_is_new_instance'; | |
| 413 | + $cached = wp_cache_get( $cache_key ); | |
| 414 | 414 | |
| 415 | - /** | |
| 416 | - * Method delete_data_demo() | |
| 417 | - * | |
| 418 | - * Handle delete demo data . | |
| 419 | - */ | |
| 420 | - public function is_new_instance() { | |
| 421 | - global $wpdb; | |
| 422 | - $count = $wpdb->get_var( 'SELECT count(id) FROM ' . MainWP_DB::instance()->get_table_name( 'wp' ) ); //phpcs:ignore WordPress.DB.PreparedSQL -- ok. | |
| 423 | - if ( $count ) { | |
| 424 | - return false; | |
| 425 | - } | |
| 426 | - $count = $wpdb->get_var( 'SELECT count(client_id) FROM ' . MainWP_DB::instance()->get_table_name( 'wp_clients' ) ); //phpcs:ignore WordPress.DB.PreparedSQL -- ok. | |
| 427 | - if ( $count ) { | |
| 428 | - return false; | |
| 429 | - } | |
| 415 | + if ( false !== $cached ) { | |
| 416 | + return $cached; | |
| 417 | + } | |
| 430 | 418 | |
| 431 | - $extensions_disabled = MainWP_Extensions_Handler::get_extensions_disabled(); | |
| 432 | - $extensions = MainWP_Extensions_Handler::get_extensions(); | |
| 433 | - if ( 0 < count( $extensions ) && $extensions !== $extensions_disabled ) { | |
| 434 | - return false; | |
| 435 | - } | |
| 419 | + $table_wp = esc_sql( MainWP_DB::instance()->get_table_name( 'wp' ) ); | |
| 420 | + $count = $wpdb->get_var( "SELECT count(id) FROM {$table_wp}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Table name cannot be parameterized. | |
| 421 | + if ( $count ) { | |
| 422 | + wp_cache_set( $cache_key, false ); | |
| 423 | + return false; | |
| 424 | + } | |
| 436 | 425 | |
| 437 | - return true; | |
| 438 | - } | |
| 426 | + $table_clients = esc_sql( MainWP_DB::instance()->get_table_name( 'wp_clients' ) ); | |
| 427 | + $count = $wpdb->get_var( "SELECT count(client_id) FROM {$table_clients}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Table name cannot be parameterized. | |
| 428 | + if ( $count ) { | |
| 429 | + wp_cache_set( $cache_key, false ); | |
| 430 | + return false; | |
| 431 | + } | |
| 439 | 432 | |
| 440 | - /** | |
| 441 | - * Method is_demo_website() | |
| 442 | - * | |
| 443 | - * Check if website is demo data. | |
| 444 | - * | |
| 445 | - * @param array $website Site to check. | |
| 446 | - */ | |
| 447 | - public function is_demo_website( $website ) { | |
| 448 | - if ( is_numeric( $website ) ) { | |
| 449 | - if ( in_array( $website, self::$demo_website_ids ) ) { | |
| 450 | - return true; | |
| 451 | - } | |
| 452 | - } elseif ( is_object( $website ) && property_exists( $website, 'id' ) && in_array( $website->id, self::$demo_website_ids ) ) { | |
| 453 | - return true; | |
| 454 | - } | |
| 455 | - return false; | |
| 456 | - } | |
| 433 | + $extensions_disabled = MainWP_Extensions_Handler::get_extensions_disabled(); | |
| 434 | + $extensions = MainWP_Extensions_Handler::get_extensions(); | |
| 435 | + if ( ! empty( $extensions ) && $extensions !== $extensions_disabled ) { | |
| 436 | + wp_cache_set( $cache_key, false ); | |
| 437 | + return false; | |
| 438 | + } | |
| 457 | 439 | |
| 440 | + wp_cache_set( $cache_key, true ); | |
| 441 | + return true; | |
| 442 | + } | |
| 458 | 443 | |
| 459 | - /** | |
| 460 | - * Method get_open_site_demo_url() | |
| 461 | - * | |
| 462 | - * Render open site demo url. | |
| 463 | - * | |
| 464 | - * @param mixed $website Site. | |
| 465 | - */ | |
| 466 | - public function get_open_site_demo_url( $website ) { | |
| 467 | - $open_url = ''; | |
| 468 | - if ( is_numeric( $website ) ) { | |
| 469 | - $website = MainWP_DB::instance()->get_website_by_id( $website ); | |
| 470 | - } | |
| 471 | - if ( is_object( $website ) && property_exists( $website, 'url' ) ) { | |
| 472 | - $open_url = $website->url . 'wp-admin.html'; | |
| 473 | - } | |
| 474 | - return $open_url; | |
| 475 | - } | |
| 444 | + /** | |
| 445 | + * Method is_demo_website() | |
| 446 | + * | |
| 447 | + * Check if website is demo data. | |
| 448 | + * | |
| 449 | + * @param array $website Site to check. | |
| 450 | + */ | |
| 451 | + public function is_demo_website( $website ) { | |
| 452 | + if ( is_numeric( $website ) ) { | |
| 453 | + if ( in_array( $website, static::$demo_website_ids ) ) { | |
| 454 | + return true; | |
| 455 | + } | |
| 456 | + } elseif ( is_object( $website ) && property_exists( $website, 'id' ) && in_array( $website->id, static::$demo_website_ids ) ) { | |
| 457 | + return true; | |
| 458 | + } | |
| 459 | + return false; | |
| 460 | + } | |
| 476 | 461 | |
| 477 | 462 | |
| 478 | - /** | |
| 479 | - * Method is_demo_mode() | |
| 480 | - * | |
| 481 | - * Check if mainwp is demo mode. | |
| 482 | - * | |
| 483 | - * @return bool True if demo mode, else False. | |
| 484 | - */ | |
| 485 | - public static function is_demo_mode() { | |
| 486 | - return defined( 'MAINWP_DEMO_MODE' ) && MAINWP_DEMO_MODE; | |
| 487 | - } | |
| 463 | + /** | |
| 464 | + * Method get_open_site_demo_url() | |
| 465 | + * | |
| 466 | + * Render open site demo url. | |
| 467 | + * | |
| 468 | + * @param mixed $website Site. | |
| 469 | + */ | |
| 470 | + public function get_open_site_demo_url( $website ) { | |
| 471 | + $open_url = ''; | |
| 472 | + if ( is_numeric( $website ) ) { | |
| 473 | + $website = MainWP_DB::instance()->get_website_by_id( $website ); | |
| 474 | + } | |
| 475 | + if ( is_object( $website ) && property_exists( $website, 'url' ) ) { | |
| 476 | + $open_url = $website->url . 'wp-admin.html'; | |
| 477 | + } | |
| 478 | + return $open_url; | |
| 479 | + } | |
| 488 | 480 | |
| 489 | - /** | |
| 490 | - * Method render_demo_disable_button() | |
| 491 | - * | |
| 492 | - * Handle render disable demo buttons. | |
| 493 | - * | |
| 494 | - * @param string $content html content. | |
| 495 | - * @param bool $echo_out to echo or return. | |
| 496 | - * | |
| 497 | - * @return mixed Button or echo. | |
| 498 | - */ | |
| 499 | - public function render_demo_disable_button( $content, $echo_out = true ) { | |
| 500 | - $button = '<div style="display:inline-block;" data-tooltip="' . $this->get_demo_tooltip() . '" data-inverted="" data-variation="mini" data-position="top right">' . $content . '</div>'; | |
| 501 | - if ( $echo_out ) { | |
| 502 | - echo $button; //phpcs:ignore WordPress.Security.EscapeOutput | |
| 503 | - } | |
| 504 | - return $button; | |
| 505 | - } | |
| 506 | 481 | |
| 507 | - /** | |
| 508 | - * Method get_markup_str() | |
| 509 | - * | |
| 510 | - * Get demo markup string. | |
| 511 | - * | |
| 512 | - * @return string markup string. | |
| 513 | - */ | |
| 514 | - public function get_markup_str() { | |
| 515 | - return '::[adminwebsitedemo]'; | |
| 516 | - } | |
| 482 | + /** | |
| 483 | + * Method is_demo_mode() | |
| 484 | + * | |
| 485 | + * Check if mainwp is demo mode. | |
| 486 | + * | |
| 487 | + * @return bool True if demo mode, else False. | |
| 488 | + */ | |
| 489 | + public static function is_demo_mode() { | |
| 490 | + return defined( 'MAINWP_DEMO_MODE' ) && MAINWP_DEMO_MODE; | |
| 491 | + } | |
| 517 | 492 | |
| 518 | - /** | |
| 519 | - * Method get_demo_notice() | |
| 520 | - * | |
| 521 | - * Get demo message to notice. | |
| 522 | - */ | |
| 523 | - public function get_demo_tooltip() { | |
| 524 | - return esc_html__( 'This function does not work in the demo mode!', 'mainwp' ); | |
| 525 | - } | |
| 493 | + /** | |
| 494 | + * Method render_demo_disable_button() | |
| 495 | + * | |
| 496 | + * Handle render disable demo buttons. | |
| 497 | + * | |
| 498 | + * @param string $content html content. | |
| 499 | + * @param bool $echo_out to echo or return. | |
| 500 | + * | |
| 501 | + * @return mixed Button or echo. | |
| 502 | + */ | |
| 503 | + public function render_demo_disable_button( $content, $echo_out = true ) { | |
| 504 | + $button = '<div style="display:inline-block;" data-tooltip="' . $this->get_demo_tooltip() . '" data-inverted="" data-variation="mini" data-position="top right">' . $content . '</div>'; | |
| 505 | + if ( $echo_out ) { | |
| 506 | + echo $button; //phpcs:ignore WordPress.Security.EscapeOutput | |
| 507 | + } | |
| 508 | + return $button; | |
| 509 | + } | |
| 526 | 510 | |
| 527 | - /** | |
| 528 | - * Method get_demo_notice() | |
| 529 | - * | |
| 530 | - * Get demo message to notice. | |
| 531 | - */ | |
| 532 | - public function get_demo_notice() { | |
| 533 | - return '[Demo Website]'; | |
| 534 | - } | |
| 511 | + /** | |
| 512 | + * Method get_markup_str() | |
| 513 | + * | |
| 514 | + * Get demo markup string. | |
| 515 | + * | |
| 516 | + * @return string markup string. | |
| 517 | + */ | |
| 518 | + public function get_markup_str() { | |
| 519 | + return '::[adminwebsitedemo]'; | |
| 520 | + } | |
| 535 | 521 | |
| 536 | - /** | |
| 537 | - * Method handle_action_demo() | |
| 538 | - * | |
| 539 | - * Handle action for demo website. | |
| 540 | - * | |
| 541 | - * @param object $pWebsite The demo site. | |
| 542 | - * @param string $what action. | |
| 543 | - */ | |
| 544 | - public function handle_action_demo( $pWebsite, $what ) { | |
| 545 | - $output = array( | |
| 546 | - 'error' => $this->get_demo_notice(), | |
| 547 | - ); | |
| 548 | - if ( 'stats' === $what || 'sync_site' === $what ) { | |
| 549 | - $update_dm = array( | |
| 550 | - 'dtsSync' => time(), | |
| 551 | - 'sync_errors' => '', | |
| 552 | - ); | |
| 553 | - MainWP_DB::instance()->update_website_sync_values( $pWebsite->id, $update_dm ); | |
| 554 | - return true; | |
| 555 | - } elseif ( 'perform_install' === $what || 'perform_upload' === $what ) { | |
| 556 | - wp_die( wp_send_json( $output ) ); //phpcs:ignore WordPress.Security.EscapeOutput | |
| 557 | - } | |
| 558 | - return $output; | |
| 559 | - } | |
| 522 | + /** | |
| 523 | + * Method get_demo_notice() | |
| 524 | + * | |
| 525 | + * Get demo message to notice. | |
| 526 | + */ | |
| 527 | + public function get_demo_tooltip() { | |
| 528 | + return esc_html__( 'This function does not work in the demo mode!', 'mainwp' ); | |
| 529 | + } | |
| 560 | 530 | |
| 561 | - /** | |
| 562 | - * Method handle_fetch_urls_demo() | |
| 563 | - * | |
| 564 | - * Handle action for demo website. | |
| 565 | - * | |
| 566 | - * @param mixed $data action. | |
| 567 | - * @param object $website The demo site. | |
| 568 | - * @param mixed $output output. | |
| 569 | - */ | |
| 570 | - public function handle_fetch_urls_demo( $data, $website, &$output ) { | |
| 571 | - if ( $this->is_demo_website( $website ) ) { | |
| 572 | - $output->errors[ $website->id ] = $this->get_demo_notice(); | |
| 573 | - } | |
| 574 | - } | |
| 531 | + /** | |
| 532 | + * Method get_demo_notice() | |
| 533 | + * | |
| 534 | + * Get demo message to notice. | |
| 535 | + */ | |
| 536 | + public function get_demo_notice() { | |
| 537 | + return '[Demo Website]'; | |
| 538 | + } | |
| 575 | 539 | |
| 576 | - /** | |
| 577 | - * Method clear_session_cached_demo_data() | |
| 578 | - * | |
| 579 | - * Handle clear session cached demo data. | |
| 580 | - */ | |
| 581 | - public function clear_session_cached_demo_data() { | |
| 582 | - MainWP_Cache::init_session(); | |
| 583 | - $clear = array( | |
| 584 | - 'SNThemesAll', | |
| 585 | - 'SNThemesAllStatus', | |
| 586 | - 'MainWP_PluginsActiveStatus', | |
| 587 | - 'MainWP_PluginsActive', | |
| 588 | - 'MainWPPluginsSearchResult', | |
| 589 | - 'MainWPPluginsSearchContext', | |
| 590 | - 'MainWPPluginsSearch', | |
| 591 | - 'MainWPThemesSearchResult', | |
| 592 | - 'MainWPThemesSearchContext', | |
| 593 | - 'MainWPThemesSearch', | |
| 594 | - 'MainWPUsersSearchResult', | |
| 595 | - 'MainWPUsersSearchContext', | |
| 596 | - 'MainWPUsersSearch', | |
| 597 | - ); | |
| 598 | - foreach ( $clear as $cl ) { | |
| 599 | - if ( isset( $_SESSION[ $cl ] ) ) { | |
| 600 | - unset( $_SESSION[ $cl ] ); | |
| 601 | - } | |
| 602 | - } | |
| 603 | - } | |
| 540 | + /** | |
| 541 | + * Method handle_action_demo() | |
| 542 | + * | |
| 543 | + * Handle action for demo website. | |
| 544 | + * | |
| 545 | + * @param object $pWebsite The demo site. | |
| 546 | + * @param string $what action. | |
| 547 | + */ | |
| 548 | + public function handle_action_demo( $pWebsite, $what ) { | |
| 549 | + $output = array( | |
| 550 | + 'error' => $this->get_demo_notice(), | |
| 551 | + ); | |
| 552 | + if ( 'stats' === $what || 'sync_site' === $what ) { | |
| 553 | + $update_dm = array( | |
| 554 | + 'dtsSync' => time(), | |
| 555 | + 'sync_errors' => '', | |
| 556 | + ); | |
| 557 | + MainWP_DB::instance()->update_website_sync_values( $pWebsite->id, $update_dm ); | |
| 558 | + return true; | |
| 559 | + } elseif ( 'perform_install' === $what || 'perform_upload' === $what ) { | |
| 560 | + wp_die( wp_send_json( $output ) ); //phpcs:ignore WordPress.Security.EscapeOutput | |
| 561 | + } | |
| 562 | + return $output; | |
| 563 | + } | |
| 564 | + | |
| 565 | + /** | |
| 566 | + * Method handle_fetch_urls_demo() | |
| 567 | + * | |
| 568 | + * Handle action for demo website. | |
| 569 | + * | |
| 570 | + * @param mixed $data action. | |
| 571 | + * @param object $website The demo site. | |
| 572 | + * @param mixed $output output. | |
| 573 | + */ | |
| 574 | + public function handle_fetch_urls_demo( $data, $website, &$output ) { | |
| 575 | + unset( $data ); | |
| 576 | + if ( $this->is_demo_website( $website ) ) { | |
| 577 | + $output->errors[ $website->id ] = $this->get_demo_notice(); | |
| 578 | + } | |
| 579 | + } | |
| 580 | + | |
| 581 | + /** | |
| 582 | + * Method clear_session_cached_demo_data() | |
| 583 | + * | |
| 584 | + * Handle clear session cached demo data. | |
| 585 | + */ | |
| 586 | + public function clear_session_cached_demo_data() { | |
| 587 | + MainWP_Cache::init_session(); | |
| 588 | + $clear = array( | |
| 589 | + 'SNThemesAll', | |
| 590 | + 'SNThemesAllStatus', | |
| 591 | + 'MainWP_PluginsActiveStatus', | |
| 592 | + 'MainWP_PluginsActive', | |
| 593 | + 'MainWPPluginsSearchResult', | |
| 594 | + 'MainWPPluginsSearchContext', | |
| 595 | + 'MainWPPluginsSearch', | |
| 596 | + 'MainWPThemesSearchResult', | |
| 597 | + 'MainWPThemesSearchContext', | |
| 598 | + 'MainWPThemesSearch', | |
| 599 | + 'MainWPUsersSearchResult', | |
| 600 | + 'MainWPUsersSearchContext', | |
| 601 | + 'MainWPUsersSearch', | |
| 602 | + ); | |
| 603 | + foreach ( $clear as $cl ) { | |
| 604 | + if ( isset( $_SESSION[ $cl ] ) ) { | |
| 605 | + unset( $_SESSION[ $cl ] ); | |
| 606 | + } | |
| 607 | + } | |
| 608 | + } | |
| 604 | 609 | } |