<?php



defined( 'ABSPATH' ) OR exit;



class wpSEOde_Feedback {


	

	public static function rules() {
		$options = wpSEOde_Options::get();

		
		$mu_note = ( is_multisite() ? esc_html__( 'For multisite installations only a DELUXE or PREMIUM license qualifies.',
			'wpseo' ) : '' );

		
		if ( $status = wpSEOde_License::trial() ) {
			self::add(
				'notice',
				sprintf(
					'%s <a href="https://wpseo.de/license/%s" target="_blank">%s</a> %s %s',
					sprintf(
						esc_html__( 'You have %s ' . _n( 'day', 'days', $status ) . ' to test wpSEO.', 'wpseo' ),
						$status,
						_n( 'day', 'days', $status, 'wpseo' )
					),
					( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' ),
					sprintf(
						__( "<a href='https://wpseo.de/license/%s'>Buy your license</a>.", 'wpseo' ),
						( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' )
					),
					'<br>' . __( 'When your trial expires your WordPress will change back to standard behaviour. Description, title etc. generated by wpSEO / set by you will not get published anymore.<br>After activation all your settings and data of wpSEO get recovered.',
						'wpseo' ),
					$mu_note
				)
			);

			
		} elseif ( wpSEOde_License::expired() ) {
			self::add(
				'critical',
				sprintf(
					'%s<br>%s<br><a href="https://wpseo.de/license/%s" target="_blank">%s</a> %s<br>%s<br>%s',
					esc_html__( 'The trial period of wpSEO has expired.', 'wpseo' ),
					__( 'WordPress changed back to standard behaviour. Description, title etc. generated by wpSEO / set by you are published anymore.',
						'wpseo' ),
					( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' ),
					sprintf(
						__( "<a href='https://wpseo.de/license/%s'>Buy your license</a>.", 'wpseo' ),
						( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' )
					),
					sprintf(
						__( 'To activate your license select the "Licensing" tab in the wpSEO menu or click <a href="%s">here</a>.',
							'wpseo' ),
						admin_url( 'admin.php?page=wpseode_licensing' )
					),
					__( 'After activation all your settings and data of wpSEO get recovered.', 'wpseo' ),
					$mu_note
				)
			);
		}

		
		switch ( wpSEOde::current_page() ) {
			
			case 'plugins':
				
				if ( ! wpSEOde::is_min_wp( '3.3' ) ) {
					self::add(
						'critical',
						sprintf(
							'%s: %s %s %s',
							esc_html__( 'Attention', 'wpseo' ),
							esc_html__( 'wpSEO requires at least WordPress', 'wpseo' ),
							'3.3',
							wpSEOde::help_icon( 64, true )
						)
					);

					
				} elseif ( ! wpSEOde::is_min_php( '5.2.4' ) ) {
					self::add(
						'critical',
						sprintf(
							'%s: %s %s',
							esc_html__( 'Attention', 'wpseo' ),
							esc_html__( 'wpSEO requires at least PHP 5.2.4', 'wpseo' ),
							wpSEOde::help_icon( 64, true )
						)
					);

					
				} elseif ( ! extension_loaded( 'mbstring' ) ) {
					self::add(
						'critical',
						sprintf(
							'%s: %s %s',
							esc_html__( 'Attention', 'wpseo' ),
							esc_html__( 'wpSEO requires multibyte string functions.', 'wpseo' ),
							wpSEOde::help_icon( 64, true )
						)
					);

					
				} elseif ( isset( $_GET['licensed'] ) ) {
					if ( $_GET['licensed'] ) {
						self::add(
							'notice',
							sprintf(
								'%s %s <a href="http://helpdesk.wpseo.de" target="_blank">%s</a>, %s <a href="https://plus.google.com/+wpSEO" target="_blank">Google+</a> / <a href="https://twitter.com/wpSEO" target="_blank">Twitter</a>.',
								__( 'wpSEO successfully activated.', 'wpseo' ),
								__( 'Help and manual in the', 'wpseo' ),
								__( 'wpSEO Helpdesk', 'wpseo' ),
								__( 'more about the plugin and updates on', 'wpseo' )
							)
						);
					} else {
						self::add(
							'critical',
							sprintf(
								'%s %s %s',
								__( 'wpSEO activation failed.', 'wpseo' ),
								__( 'Invalid license or system requirements.', 'wpseo' ),
								wpSEOde::help_icon( 15, true )
							)
						);
					}


					
				} elseif ( $status = wpSEOde_License::trial() ) {
					self::add(
						'notice',
						sprintf(
							'%s <a href="https://wpseo.de/license/%s" target="_blank">%s</a>%s',
							sprintf(
								esc_html__( 'You have %s ' . _n( 'day', 'days', $status ) . ' to test wpSEO.',
									'wpseo' ),
								$status
							),
							( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' ),
							sprintf(
								__( "<a href='https://wpseo.de/license/%s'>Buy your license</a>.", 'wpseo' ),
								( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' )
							),
							$mu_note
						)
					);

					
				} elseif ( wpSEOde_License::expired() ) {
					self::add(
						'critical',
						sprintf(
							'%s <a href="https://wpseo.de/license/%s" target="_blank">%s</a>%s',
							esc_html__( 'The trial period of wpSEO has expired.', 'wpseo' ),
							( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' ),
							sprintf(
								__( "<a href='https://wpseo.de/license/%s'>Buy your license</a>.", 'wpseo' ),
								( get_site_option( strrev( 'rentrap_edoespw' ) ) ? '?partner=' . urlencode( get_site_option( strrev( 'rentrap_edoespw' ) ) ) : '' )
							),
							$mu_note
						)
					);
				}
				break;


			
			case 'admin':
				
				if ( current_user_can( 'manage_options' ) && ! (bool) get_option( 'blog_public' ) ) {
					self::add(
						'notice',
						sprintf(
							'%s: <a href="%s">%s</a>.',
							esc_html__( 'Attention', 'wpseo' ),
							admin_url( 'options-reading.php' ),
							esc_html__( 'Search engines blocked', 'wpseo' )
						)
					);
				}


				
				if ( class_exists( 'All_in_One_SEO_Pack' ) OR class_exists( 'HeadSpace_Plugin' ) OR class_exists( 'Platinum_SEO_Pack' ) ) {
					self::add(
						'notice',
						sprintf(
							'%s: <a href="%s">%s</a>.',
							esc_html__( 'Attention', 'wpseo' ),
							network_admin_url( 'plugins.php' ),
							esc_html__( 'Several SEO plugins in use', 'wpseo' )
						)
					);
				}
				break;

			default:
				break;
		}
		if ( wpSEOde_Transients::getDefault( 'wpseo-upgrade', false ) ) {
			self::add(
				'wpseo-upgrade',
				sprintf(
					'%s <a href="https://wpseo.de/upgrade/?utm_source=plugin&utm_medium=upgrdmsg&utm_campaign=upgrdmsg" target="_blank">%s</a>',
					esc_html__( 'You\'re using a wpSEO Classic License. Did you know that you can upgrade your License to use wpSEO on multiple Domains and Multisite installations?',
						'wpseo' ),
					__( 'Upgrade your license.', 'wpseo' )
				)
			);
		}
		if ( ( $sInfo = wpSEOde_Transients::getDefault( 'wpseo-infomsg', false ) ) !== false ) {
			self::add(
				'wpseo-infomsg',
				$sInfo
			);
		}

		if ( $options['sitemap'] && wpSEOde_Sitemap::exists() ) {
			self::add(
				'critical',
				sprintf( __( 'Warning: One of the files <a href="%s" target="_blank">sitemap.xml</a>, <a href="%s" target="_blank">sitemap-page.xml</a>, <a href="%s" target="_blank">sitemap-post.xml</a> or <a href="%s" target="_blank">sitemap-custom.xml</a> exists on this Installation, you have to delete those in order to use the sitemap-feature of wpSEO!',
					'wpseo' ), home_url( '/sitemap.xml' ), home_url( '/sitemap-page.xml' ),
					home_url( '/sitemap-post.xml' ), home_url( '/sitemap-custom.xml' ) )
			);
		}
	}


	

	public static function add( $type, $msg ) {
		
		if ( empty( $type ) OR empty( $msg ) OR ! in_array( $type,
				array( 'critical', 'notice', 'wpseo-upgrade', 'wpseo-infomsg' ) ) ) {
			return false;
		}

		
		$data = (array) wpSEOde_Cache::get( 'feedback' );

		
		$data[ $type ] = $msg;

		
		wpSEOde_Cache::set( 'feedback', $data );
	}


	

	public static function get( $type = '' ) {
		
		$data = (array) wpSEOde_Cache::get( 'feedback' );

		
		if ( empty( $data ) ) {
			return false;
		}

		
		if ( empty( $type ) ) {
			return $data;
		}

		
		if ( in_array( $type,
				array( 'critical', 'notice', 'wpseo-upgrade', 'wpseo-infomsg' ) ) && ! empty( $data[ $type ] ) ) {
			return $data[ $type ];
		}

		return false;
	}


	

	public static function network() {
		self::_display();
	}


	

	public static function admin() {
		self::_display();
	}


	

	private static function _display() {
		
		if ( ! $errors = self::get() ) {
			return false;
		}

		
		$matrix = array(
			'critical'      => 'error',
			'notice'        => 'success',
			'wpseo-upgrade' => 'success',
			'wpseo-infomsg' => 'success'
		);

		
		foreach ( $errors as $type => $msg ) {
			echo sprintf(
				'<div class="notice notice-%s is-dismissible"' . ( in_array( $type, array(
					'wpseo-upgrade',
					'wpseo-infomsg'
				) ) ? ' data-wpseo="' . esc_attr( $type ) . '"' : '' ) . '><p>wpSEO: %s</p></div>',
				esc_attr( $matrix[ $type ] ),
				$msg
			);
		}
	}
}