PageRenderTime 39ms CodeModel.GetById 20ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-content/plugins/really-simple-ssl/class-multisite.php

https://bitbucket.org/carloskikea/helpet
PHP | 786 lines | 523 code | 140 blank | 123 comment | 63 complexity | 54409f830f6ae3639e669eccdef5818f MD5 | raw file
  1<?php
  2
  3defined('ABSPATH') or die("you do not have access to this page!");
  4
  5if ( ! class_exists( 'rsssl_multisite' ) ) {
  6  class rsssl_multisite {
  7    private static $_this;
  8
  9    public $option_group = "rsssl_network_options";
 10    public $page_slug = "really-simple-ssl";
 11    public $section = "rsssl_network_options_section";
 12    public $ssl_enabled_networkwide;
 13    public $selected_networkwide_or_per_site;
 14
 15    public $wp_redirect;
 16    public $htaccess_redirect;
 17    public $do_not_edit_htaccess;
 18    public $autoreplace_mixed_content;
 19    public $javascript_redirect;
 20    public $hsts;
 21    public $mixed_content_admin;
 22    public $cert_expiration_warning;
 23    public $hide_menu_for_subsites;
 24
 25    private $pro_url = "https://www.really-simple-ssl.com/pro-multisite";
 26
 27  function __construct() {
 28    if ( isset( self::$_this ) )
 29        wp_die( sprintf( __( '%s is a singleton class and you cannot create a second instance.','really-simple-ssl' ), get_class( $this ) ) );
 30
 31    self::$_this = $this;
 32
 33    $this->load_options();
 34    register_activation_hook(  dirname( __FILE__ )."/".rsssl_plugin, array($this,'activate') );
 35
 36    /*filters to make sure WordPress returns the correct protocol */
 37    add_filter("admin_url", array($this, "check_admin_protocol"), 20, 3 );
 38    add_filter('home_url', array($this, 'check_site_protocol') , 20,4);
 39    add_filter('site_url', array($this, 'check_site_protocol') , 20,4);
 40
 41    add_action("plugins_loaded", array($this, "process_networkwide_choice"), 10, 0);
 42    add_action("plugins_loaded", array($this, "networkwide_choice_notice"), 20, 0);
 43
 44    add_action('network_admin_menu', array( &$this, 'add_multisite_menu' ) );
 45    add_action('network_admin_edit_rsssl_update_network_settings',  array($this,'update_network_options'));
 46
 47    if (is_network_admin()) {
 48      add_action('network_admin_notices', array($this, 'show_notices'), 10);
 49      add_action('admin_print_footer_scripts', array($this, 'insert_dismiss_success'));
 50    }
 51
 52    add_action('wp_ajax_dismiss_success_message_multisite', array($this,'dismiss_success_message_callback') );
 53
 54    add_action('wp_ajax_rsssl_pro_dismiss_pro_option_notice', array($this,'dismiss_pro_option_notice') );
 55    add_action("network_admin_notices", array($this, 'show_pro_option_notice'));
 56
 57    add_action("rsssl_show_network_tab_settings", array($this, 'settings_tab'));
 58
 59    add_action( 'wpmu_new_blog', array($this, 'maybe_activate_ssl_in_new_blog'), 10, 6 );
 60
 61  }
 62
 63  static function this() {
 64    return self::$_this;
 65  }
 66
 67  /*
 68
 69      When a new site is added, maybe activate SSL as well.
 70
 71  */
 72
 73  public function maybe_activate_ssl_in_new_blog( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
 74    if ($this->ssl_enabled_networkwide) {
 75        $site = get_blog_details($blog_id);
 76        $this->switch_to_blog_bw_compatible($site);
 77        RSSSL()->really_simple_ssl->activate_ssl();
 78        restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
 79      }
 80  }
 81
 82
 83
 84
 85  public function networkwide_choice_notice(){
 86
 87    if ($this->plugin_network_wide_active() && !$this->selected_networkwide_or_per_site) {
 88      add_action('network_admin_notices', array($this, 'show_notice_activate_networkwide'), 10);
 89    }
 90  }
 91
 92  public function load_options(){
 93    $options = get_site_option('rlrsssl_network_options');
 94    $this->selected_networkwide_or_per_site = isset($options["selected_networkwide_or_per_site"]) ? $options["selected_networkwide_or_per_site"] : false;
 95    $this->ssl_enabled_networkwide = isset($options["ssl_enabled_networkwide"]) ? $options["ssl_enabled_networkwide"] : false;
 96    $this->wp_redirect  = isset($options["wp_redirect"]) ? $options["wp_redirect"] : false;
 97    $this->htaccess_redirect = isset($options["htaccess_redirect"]) ? $options["htaccess_redirect"] : false;
 98    $this->do_not_edit_htaccess = isset($options["do_not_edit_htaccess"]) ? $options["do_not_edit_htaccess"] : false;
 99    $this->autoreplace_mixed_content = isset($options["autoreplace_mixed_content"]) ? $options["autoreplace_mixed_content"] : false;
100    $this->javascript_redirect = isset($options["javascript_redirect"]) ? $options["javascript_redirect"] : false;
101    $this->hsts = isset($options["hsts"]) ? $options["hsts"] : false;
102    $this->mixed_content_admin = isset($options["mixed_content_admin"]) ? $options["mixed_content_admin"] : false;
103    $this->cert_expiration_warning = isset($options["cert_expiration_warning"]) ? $options["cert_expiration_warning"] : false;
104    $this->hide_menu_for_subsites = isset($options["hide_menu_for_subsites"]) ? $options["hide_menu_for_subsites"] : false;
105  }
106
107
108  /**
109   * On plugin activation, we can check if it is networkwide or not.
110   *
111   * @since  2.1
112   *
113   * @access public
114   *
115   */
116
117  public function activate($networkwide) {
118    //if networkwide, we ask, if not, we set it as selected.
119    if (!$networkwide) {
120        $this->selected_networkwide_or_per_site = true;
121        $this->ssl_enabled_networkwide = false;
122        $this->save_options();
123    }
124
125  }
126
127  /*
128
129      Add network menu for SSL
130      Only when plugin is network activated.
131
132  */
133
134  public function add_multisite_menu(){
135    if (!$this->plugin_network_wide_active()) return;
136
137    register_setting( $this->option_group, 'rsssl_options');
138    add_settings_section('rsssl_network_settings', __("Settings","really-simple-ssl"), array($this,'section_text'), $this->page_slug);
139    
140    //if (RSSSL()->really_simple_ssl->site_has_ssl) {
141        add_settings_field('id_ssl_enabled_networkwide', __("Enable SSL", "really-simple-ssl"), array($this,'get_option_enable_multisite'), $this->page_slug, 'rsssl_network_settings');
142        //if ($this->selected_networkwide_or_per_site) {
143        RSSSL()->rsssl_network_admin_page = add_submenu_page('settings.php', "SSL", "SSL", 'manage_options', $this->page_slug, array( &$this, 'multisite_menu_page' ) );
144        //}
145     // }
146    }
147
148  /*
149      Shows the content of the multisite menu page
150  */
151
152  public function section_text(){
153    if (!RSSSL()->really_simple_ssl->site_has_ssl) {
154      ?>
155      <p>
156        <?php _e("No SSL was detected. If you do have an SSL certificate, try to reload this page over https by clicking this link:","really-simple-ssl");?>&nbsp;<a href="<?php echo $current_url?>"><?php _e("reload over https.","really-simple-ssl");?></a>
157        <?php _e("You can check your certificate on","really-simple-ssl");?>&nbsp;<a target="_blank" href="https://www.ssllabs.com/ssltest/">Qualys SSL Labs</a>
158      </p>
159      <?php
160    } else {
161      _e("Below you can set the multisite options for Really Simple SSL","really-simple-ssl");
162    }
163  }
164
165  public function get_option_enable_multisite(){
166      ?>
167      <select name="rlrsssl_network_options[ssl_enabled_networkwide]">
168        <?php if (!$this->selected_networkwide_or_per_site) {?>
169        <option value="-1" <?php if (!$this->selected_networkwide_or_per_site) echo "selected";?>><?php _e("No selection was made", "really-simple-ssl")?>
170        <?php }?>
171        <option value="1" <?php if ($this->ssl_enabled_networkwide) echo "selected";?>><?php _e("networkwide", "really-simple-ssl")?>
172        <option value="0" <?php if (!$this->ssl_enabled_networkwide) echo "selected";?>><?php _e("per site", "really-simple-ssl")?>
173      </select>
174      <?php
175
176      //echo '<input id="rlrsssl_options" name="rlrsssl_network_options[ssl_enabled_networkwide]" size="40" type="checkbox" value="1"' . checked( 1, $this->ssl_enabled_networkwide, false ) ." />";
177      rsssl_help::this()->get_help_tip(__("Select to enable SSL networkwide or per site.", "really-simple-ssl"));
178  }
179
180
181/**
182 * Displays the options page. The big difference here is where you post the data
183 * because, unlike for normal option pages, there is nowhere to process it by
184 * default so we have to create our own hook to process the saving of our options.
185 */
186
187 public function multisite_menu_page() {
188   $tab = "settings";
189  if ( isset ( $_GET['tab'] ) ) $tab = $_GET['tab'];
190  $this->admin_tabs($tab);
191
192  do_action("rsssl_show_network_tab_{$tab}");
193}
194
195
196public function settings_tab(){
197  if (isset($_GET['updated'])): ?>
198   <div id="message" class="updated notice is-dismissible"><p><?php _e('Options saved.', 'really-simple-ssl') ?></p></div>
199  <?php endif; ?>
200  <div class="wrap">
201    <h1><?php _e('Really Simple SSL multisite options', 'really-simple-ssl'); ?></h1>
202    <form method="POST" action="edit.php?action=rsssl_update_network_settings">
203      <?php
204
205          settings_fields($this->option_group);
206          do_settings_sections($this->page_slug);
207          submit_button();
208      ?>
209    </form>
210  </div>
211  <?php
212}
213
214
215/**
216 * Save network settings
217 */
218
219 public function update_network_options() {
220  check_admin_referer($this->option_group.'-options');
221
222  if (isset($_POST["rlrsssl_network_options"])) {
223    $prev_ssl_enabled_networkwide = $this->ssl_enabled_networkwide;
224    $options = array_map(array($this, "sanitize_boolean"), $_POST["rlrsssl_network_options"]);
225    $options["selected_networkwide_or_per_site"] = true;
226
227    $this->ssl_enabled_networkwide = isset($options["ssl_enabled_networkwide"]) ? $options["ssl_enabled_networkwide"] : false;
228
229    $this->wp_redirect  = isset($options["wp_redirect"]) ? $options["wp_redirect"] : false;
230    $this->htaccess_redirect = isset($options["htaccess_redirect"]) ? $options["htaccess_redirect"] : false;
231
232    $this->do_not_edit_htaccess = isset($options["do_not_edit_htaccess"]) ? $options["do_not_edit_htaccess"] : false;
233    $this->autoreplace_mixed_content = isset($options["autoreplace_mixed_content"]) ? $options["autoreplace_mixed_content"] : false;
234    $this->javascript_redirect = isset($options["javascript_redirect"]) ? $options["javascript_redirect"] : false;
235    $this->hsts = isset($options["hsts"]) ? $options["hsts"] : false;
236    $this->mixed_content_admin = isset($options["mixed_content_admin"]) ? $options["mixed_content_admin"] : false;
237    $this->cert_expiration_warning = isset($options["cert_expiration_warning"]) ? $options["cert_expiration_warning"] : false;
238    $this->hide_menu_for_subsites = isset($options["hide_menu_for_subsites"]) ? $options["hide_menu_for_subsites"] : false;
239
240
241    $this->selected_networkwide_or_per_site = isset($options["selected_networkwide_or_per_site"]) ? $options["selected_networkwide_or_per_site"] : false;
242  }
243
244  $this->save_options();
245
246  if ($this->ssl_enabled_networkwide) {
247    //enable SSL on all  sites on the network
248    $this->activate_ssl_networkwide();
249  } elseif ($prev_ssl_enabled_networkwide!=$this->ssl_enabled_networkwide) {
250    //if we switch to per page, we deactivate SSL on all pages first, but only if the setting was changed.
251    $sites = $this->get_sites_bw_compatible();
252    foreach ( $sites as $site ) {
253      $this->switch_to_blog_bw_compatible($site);
254      RSSSL()->really_simple_ssl->deactivate_ssl();
255      restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
256    }
257  }
258
259
260  // At last we redirect back to our options page.
261  wp_redirect(add_query_arg(array('page' => $this->page_slug, 'updated' => 'true'), network_admin_url('settings.php')));
262  exit;
263}
264
265  public function sanitize_boolean($value)
266{
267  if ($value == true) {
268    return true;
269  } else {
270    return false;
271  }
272}
273
274
275/**
276 * Give the user an option to activate network wide or not.
277 * Needs to be called after detect_configuration function
278 *
279 * @since  2.3
280 *
281 * @access public
282 *
283 */
284
285 public function show_notice_activate_networkwide(){
286  //if no SSL was detected, don't activate it yet.
287  if (!RSSSL()->really_simple_ssl->site_has_ssl) {
288    global $wp;
289    $current_url = "https://".$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]
290    ?>
291    <div id="message" class="error fade notice activate-ssl">
292    <p><?php _e("No SSL was detected. If you do have an SSL certificate, try to reload this page over https by clicking this link:","really-simple-ssl");?>&nbsp;<a href="<?php echo $current_url?>"><?php _e("reload over https.","really-simple-ssl");?></a>
293      <?php _e("You can check your certificate on","really-simple-ssl");?>&nbsp;<a target="_blank" href="https://www.ssllabs.com/ssltest/">Qualys SSL Labs</a>
294    </p>
295  </div>
296  <?php } ?>
297
298  <?php if (RSSSL()->really_simple_ssl->site_has_ssl) {
299    if (is_main_site(get_current_blog_id()) && RSSSL()->really_simple_ssl->wpconfig_ok()) {
300      ?>
301      <div id="message" class="updated fade notice activate-ssl">
302        <h1><?php _e("Choose your preferred setup","really-simple-ssl");?></h1>
303        <?php _e("Some things can't be done automatically. Before you migrate, please check for: ",'really-simple-ssl');?>
304        <p>
305          <ul>
306            <li><?php _e('Http references in your .css and .js files: change any http:// into //','really-simple-ssl');?></li>
307            <li><?php _e('Images, stylesheets or scripts from a domain without an SSL certificate: remove them or move to your own server.','really-simple-ssl');?></li>
308          </ul>
309        </p>
310        <?php $this->show_pro(); ?>
311      <p>
312        <form action="" method="post">
313          <?php wp_nonce_field( 'rsssl_nonce', 'rsssl_nonce' );?>
314          <input type="submit" class='button button-primary' value="<?php _e("Activate SSL networkwide","really-simple-ssl");?>" id="rsssl_do_activate_ssl_networkwide" name="rsssl_do_activate_ssl_networkwide">
315          <input type="submit" class='button button-primary' value="<?php _e("Activate SSL per site","really-simple-ssl");?>" id="rsssl_do_activate_ssl_per_site" name="rsssl_do_activate_ssl_per_site">
316        </form>
317      </p>
318      <p>
319        <?php _e("Networkwide activation does not check if a site has an SSL certificate. It just migrates all sites to SSL.","really-simple-ssl");?>
320      </p>
321      </div>
322      <?php
323    }
324  }
325}
326/**
327  * @since 2.3
328  * Shows option to buy pro
329
330*/
331
332  public function show_pro(){
333    ?>
334    <p><?php _e('You can also let the automatic scan of the pro version handle this for you, and get premium support and increased security with HSTS included.','really-simple-ssl');?>&nbsp;<a target="_blank" href="<?php echo $this->pro_url;?>"><?php _e("Check out Really Simple SSL Premium","really-simple-ssl");?></a></p>
335    <?php
336  }
337
338
339
340/*
341
342    Check if the plugin is network activated.
343
344*/
345
346
347    public function plugin_network_wide_active(){
348      if ( ! function_exists( 'is_plugin_active_for_network' ) )
349        require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
350
351      if ( is_plugin_active_for_network(rsssl_plugin) ){
352        return true;
353      } else {
354        return false;
355      }
356    }
357
358
359
360  public function process_networkwide_choice(){
361
362    if (!$this->plugin_network_wide_active()) return;
363
364
365    if ( isset($_POST['rsssl_do_activate_ssl_networkwide'])) {
366
367      $this->selected_networkwide_or_per_site = true;
368      $this->ssl_enabled_networkwide = true;
369      $this->wp_redirect = true;
370      $this->save_options();
371
372      //enable SSL on all sites on the network
373      $this->activate_ssl_networkwide();
374
375    }
376
377    if (isset($_POST['rsssl_do_activate_ssl_per_site'])) {
378
379      $this->selected_networkwide_or_per_site = true;
380      $this->ssl_enabled_networkwide = false;
381      $this->save_options();
382    }
383
384  }
385
386
387  public function save_options(){
388    $options = get_site_option("rlrsssl_network_options");
389    if (!is_array($options)) $options = array();
390
391    $options["selected_networkwide_or_per_site"] = $this->selected_networkwide_or_per_site;
392    $options["ssl_enabled_networkwide"] = $this->ssl_enabled_networkwide;
393    $options["wp_redirect"] = $this->wp_redirect;
394    $options["htaccess_redirect"] = $this->htaccess_redirect;
395    $options["do_not_edit_htaccess"] = $this->do_not_edit_htaccess;
396    $options["autoreplace_mixed_content"] = $this->autoreplace_mixed_content;
397    $options["javascript_redirect"] = $this->javascript_redirect;
398    $options["hsts"] = $this->hsts;
399    $options["mixed_content_admin"] = $this->mixed_content_admin;
400    $options["cert_expiration_warning"] = $this->cert_expiration_warning;
401    $options["hide_menu_for_subsites"] = $this->hide_menu_for_subsites;
402
403    update_site_option("rlrsssl_network_options", $options);
404  }
405
406
407  public function activate_ssl_networkwide(){
408
409    //set all sites as enabled
410    $sites = $this->get_sites_bw_compatible();
411
412    foreach ( $sites as $site ) {
413      $this->switch_to_blog_bw_compatible($site);
414      RSSSL()->really_simple_ssl->activate_ssl();
415      restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
416    }
417
418  }
419
420
421
422
423  //change deprecated function depending on version.
424
425  public function get_sites_bw_compatible(){
426    global $wp_version;
427    $sites = ($wp_version >= 4.6 ) ? get_sites() : wp_get_sites();
428    return $sites;
429  }
430
431  /*
432        The new get_sites function returns an object.
433
434  */
435
436  public function switch_to_blog_bw_compatible($site){
437    global $wp_version;
438    if ($wp_version >= 4.6 ) {
439      switch_to_blog( $site->blog_id );
440    } else {
441      switch_to_blog( $site[ 'blog_id' ] );
442    }
443  }
444
445  public function deactivate(){
446
447    $options = get_site_option("rlrsssl_network_options");
448    $options["selected_networkwide_or_per_site"] = false;
449    $options["wp_redirect"] = false;
450    $options["htaccess_redirect"] = false;
451    $options["do_not_edit_htaccess"] = false;
452    $options["autoreplace_mixed_content"] = false;
453    $options["javascript_redirect"] = false;
454    $options["hsts"] = false;
455    $options["mixed_content_admin"] = false;
456    $options["cert_expiration_warning"] = false;
457    $options["hide_menu_for_subsites"] = false;
458
459    unset($options["ssl_enabled_networkwide"]);
460    update_site_option("rlrsssl_network_options", $options);
461
462    $sites = $this->get_sites_bw_compatible();
463    foreach ( $sites as $site ) {
464      $this->switch_to_blog_bw_compatible($site);
465      RSSSL()->really_simple_ssl->deactivate_ssl();
466      restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
467    }
468
469}
470
471
472/**
473* filters the get_admin_url function to correct the false https urls wordpress returns for non SSL websites.
474*
475* @since 2.3.10
476*
477*/
478
479public function check_admin_protocol($url, $path, $blog_id){
480  if (!$blog_id) $blog_id = get_current_blog_id();
481
482  //if the force_ssl_admin is defined, the admin_url should not be forced back to http: all admin panels should be https.
483  if (defined('FORCE_SSL_ADMIN')) return $url;
484
485  //do not force to http if the request is made for an url of the current blog.
486  //if a site is loaded over https, it should return https links, unless the url is requested for another blog.
487  //In that case, we only return a https link if the site_url is https, and http otherwise.
488  if (get_current_blog_id()==$blog_id) return $url;
489
490  //now check if the blog is http or https, and change the url accordingly
491  if (!$this->ssl_enabled_networkwide) {
492    $home_url = get_blog_option($blog_id, 'home');
493    if (strpos($home_url, "https://")===false) {
494      $url = str_replace("https://","http://",$url);
495    }
496  }
497
498
499  return $url;
500}
501
502/**
503* filters the home_url and/or site_url function to correct the false https urls wordpress returns for non SSL websites.
504*
505* @since 2.3.17
506*
507*/
508
509public function check_site_protocol($url, $path, $orig_scheme, $blog_id){
510  if (!$blog_id) $blog_id = get_current_blog_id();
511
512  if (get_current_blog_id()==$blog_id) return $url;
513
514  if (!$this->ssl_enabled_networkwide) {
515    $home_url = get_blog_option($blog_id, 'home');
516    if (strpos($home_url, "https://")===false) {
517      $url = str_replace("https://","http://",$url);
518    }
519  }
520  return $url;
521}
522
523
524
525/*
526 * Checks if we are on a subfolder install. (domain.com/site1 )
527 *
528 * @since  2.2
529 *
530 * @access public
531 *
532 **/
533
534public function is_multisite_subfolder_install() {
535  if (!is_multisite()) return FALSE;
536  //we check this manually, as the SUBDOMAIN_INSTALL constant of wordpress might return false for domain mapping configs
537  $is_subfolder = FALSE;
538  $sites = $this->get_sites_bw_compatible();
539  foreach ( $sites as $site ) {
540    $this->switch_to_blog_bw_compatible($site);
541    if ($this->is_subfolder(home_url())) {
542      $is_subfolder=TRUE;
543    }
544    restore_current_blog(); //switches back to previous blog, not current, so we have to do it each loop
545    if ($is_subfolder) return true;
546  }
547
548  return $is_subfolder;
549}
550
551/**
552 * Test if a domain has a subfolder structure
553 *
554 * @since  2.2
555 *
556 * @param string $domain
557 *
558 * @access private
559 *
560 */
561
562public function is_subfolder($domain) {
563
564    //remove slashes of the http(s)
565    $domain = preg_replace("/(http:\/\/|https:\/\/)/","",$domain);
566    if (strpos($domain,"/")!==FALSE) {
567      return true;
568    }
569    return false;
570}
571
572public function is_per_site_activated_multisite_subfolder_install() {
573  if (is_multisite() && $this->is_multisite_subfolder_install() && !$this->ssl_enabled_networkwide){
574    return true;
575  }
576
577  return false;
578}
579
580  /**
581   * Show notices
582   *
583   * @since  2.0
584   *
585   * @access public
586   *
587   */
588
589public function show_notices()
590{
591
592  if (isset(RSSSL()->really_simple_ssl->errors["DEACTIVATE_FILE_NOT_RENAMED"])) {
593    ?>
594    <div id="message" class="error fade notice is-dismissible rlrsssl-fail">
595      <h1>
596        <?php _e("Major security issue!","really-simple-ssl");?>
597      </h1>
598      <p>
599    <?php _e("The 'force-deactivate.php' file has to be renamed to .txt. Otherwise your ssl can be deactived by anyone on the internet.","really-simple-ssl");?>
600    </p>
601    <a href="options-general.php?page=rlrsssl_really_simple_ssl"><?php echo __("Check again","really-simple-ssl");?></a>
602    </div>
603    <?php
604  }
605
606  /*
607      SSL success message
608  */
609
610  if ($this->selected_networkwide_or_per_site && !get_site_option("rsssl_success_message_shown")) {
611
612        ?>
613        <div id="message" class="updated fade notice is-dismissible rlrsssl-multisite-success">
614          <p>
615            <?php _e("SSL activated!","really-simple-ssl");?>&nbsp;
616            <?php
617              if ($this->ssl_enabled_networkwide)
618                _e("SSL was activated on your entire network.", "really-simple-ssl");
619              else
620                _e("SSL was activated per site.", "really-simple-ssl");
621              ?>
622            <?php _e("Don't forget to change your settings in Google Analytics and Webmaster tools.","really-simple-ssl");?>&nbsp;
623            <a target="_blank" href="https://really-simple-ssl.com/knowledge-base/how-to-setup-google-analytics-and-google-search-consolewebmaster-tools/"><?php _e("More info.","really-simple-ssl");?></a>
624          </p>
625        </div>
626        <?php
627  }
628
629  if (!$this->ssl_enabled_networkwide && $this->selected_networkwide_or_per_site && $this->is_multisite_subfolder_install()) {
630    //with no server variables, the website could get into a redirect loop.
631    if (RSSSL()->really_simple_ssl->no_server_variable) {
632      ?>
633        <div id="message" class="error fade notice">
634          <p>
635            <?php _e('You run a Multisite installation with subfolders, which prevents this plugin from fixing your missing server variable in the wp-config.php.','really-simple-ssl');?>
636            <?php _e('Because the $_SERVER["HTTPS"] variable is not set, your website may experience redirect loops.','really-simple-ssl');?>
637            <?php _e('Activate networkwide to fix this.','really-simple-ssl');?>
638          </p>
639        </div>
640      <?php
641    }
642  }
643}
644
645
646/**
647 * Insert some ajax script to dismis the SSL success message, and stop nagging about it
648 *
649 * @since  2.0
650 *
651 * @access public
652 *
653 */
654
655public function insert_dismiss_success() {
656if ($this->selected_networkwide_or_per_site && !get_site_option("rsssl_success_message_shown")) {
657$ajax_nonce = wp_create_nonce( "really-simple-ssl-dismiss" );
658?>
659<script type='text/javascript'>
660  jQuery(document).ready(function($) {
661    $(".rlrsssl-multisite-success.notice.is-dismissible").on("click", ".notice-dismiss", function(event){
662
663          var data = {
664            'action': 'dismiss_success_message_multisite',
665            'security': '<?php echo $ajax_nonce; ?>'
666          };
667
668          $.post(ajaxurl, data, function(response) {
669
670          });
671      });
672  });
673</script>
674<?php
675}
676}
677
678/**
679 * Process the ajax dismissal of the success message.
680 *
681 * @since  2.0
682 *
683 * @access public
684 *
685 */
686
687public function dismiss_success_message_callback() {
688//nonce check fails if url is changed to SSL.
689//check_ajax_referer( 'really-simple-ssl-dismiss', 'security' );
690update_site_option("rsssl_success_message_shown", true);
691wp_die();
692}
693
694
695public function dismiss_pro_option_notice() {
696	check_ajax_referer( 'rsssl-pro-dismiss-pro-option-notice', 'nonce' );
697	update_option( 'rsssl_pro_pro_option_notice_dismissed', true);
698	wp_die();
699}
700
701public function dismiss_pro_option_script() {
702  $ajax_nonce = wp_create_nonce( "rsssl-pro-dismiss-pro-option-notice" );
703  ?>
704  <script type='text/javascript'>
705    jQuery(document).ready(function($) {
706
707      $(".rsssl-pro-dismiss-notice.notice.is-dismissible").on("click", ".notice-dismiss", function(event){
708            var data = {
709              'action': 'rsssl_pro_dismiss_pro_option_notice',
710              'nonce': '<?php echo $ajax_nonce; ?>'
711            };
712
713            $.post(ajaxurl, data, function(response) {
714
715            });
716        });
717    });
718  </script>
719  <?php
720}
721
722
723public function show_pro_option_notice(){
724  if (!$this->is_settings_page()) return;
725
726  $dismissed	= get_option( 'rsssl_pro_pro_option_notice_dismissed' );
727  if (!$dismissed) {
728
729   if (defined('rsssl_pro_version')) {
730     if (!defined('rsssl_pro_ms_version')) {
731       add_action('admin_print_footer_scripts', array($this, 'dismiss_pro_option_script'));
732           ?>
733           <div id="message" class="updated fade notice is-dismissible rsssl-pro-dismiss-notice">
734             <p>
735               <?php echo sprintf( __( 'You are running Really Simple SSL pro. A dedicated add-on for multisite has been released. If you want more options to have full control over your multisite network, you can ask for a discount code to %supgrade%s your license to a multisite license.', 'really-simple-ssl' ), '<a href="https://really-simple-ssl.com/contact" title="Really Simple SSL">', '</a>' )?>
736             </p>
737           </p></div>
738           <?php
739           }
740   } else {
741     ?>
742     <div id="message" class="updated fade notice is-dismissible rsssl-pro-dismiss-notice">
743       <p>
744         <?php echo sprintf( __( 'If you want more options to have full control over your multisite network, you can %supgrade%s your license to a multisite license, or dismiss this message', 'really-simple-ssl' ), '<a href="https://really-simple-ssl.com/pro-multisite" title="Really Simple SSL">', '</a>' )?>
745       </p>
746     </p></div>
747     <?php
748   }
749  }
750}
751
752public function is_settings_page(){
753  return ( isset( $_GET['page'] ) && $_GET['page'] == 'really-simple-ssl' ) ? true : false;
754}
755
756
757
758/**
759 * Create tabs on the settings page
760 *
761 * @since  1.0.0
762 *
763 * @access public
764 *
765 */
766
767public function admin_tabs( $current = 'settings' ) {
768    $tabs = array(
769      'settings'=>__("Settings","really-simple-ssl"),
770    );
771
772    $tabs = apply_filters("rsssl_network_tabs", $tabs);
773
774    if (count($tabs)>1) {
775      echo '<h2 class="nav-tab-wrapper">';
776
777      foreach( $tabs as $tab => $name ){
778          $class = ( $tab == $current ) ? ' nav-tab-active' : '';
779          echo "<a class='nav-tab$class' href='?page=really-simple-ssl&tab=$tab'>$name</a>";
780      }
781      echo '</h2>';
782    }
783}
784
785} //class closure
786}