*/
class Settings extends \WP_Piwik\Admin {
	/**
	 * Builds and displays the settings page
	 */
	public function show() {
		if (isset($_GET['sitebrowser']) && $_GET['sitebrowser']) {
			new \WP_Piwik\Admin\Sitebrowser(self::$wpPiwik);
			return;
		}
		if (isset($_GET['clear']) && $_GET['clear'] && check_admin_referer()) {
			$this->clear($_GET['clear'] == 2);
			self::$wpPiwik->resetRequest();
			echo '
';
			return;
		} elseif (self::$wpPiwik->isConfigSubmitted()) {
			$this->showBox ( 'updated', 'yes', __ ( 'Changes saved.' ) );
			self::$wpPiwik->resetRequest();
            if (self::$settings->getGlobalOption('piwik_mode') == 'php') {
                self::$wpPiwik->definePiwikConstants();
            }
            if (self::$settings->getGlobalOption ( 'auto_site_config' ) && self::$wpPiwik->isConfigured ()) {
                $siteId = self::$wpPiwik->getPiwikSiteId (null, true);
                self::$wpPiwik->updateTrackingCode ( $siteId );
                self::$settings->setOption ( 'site_id', $siteId );
            } else {
                self::$wpPiwik->updateTrackingCode();
            }
		}
		global $wp_roles;
		?>
	getHeadline ( 1, 'admin-generic', 'Settings', true );
		if (isset($_GET['testscript']) && $_GET['testscript'])
			$this->runTestscript();
	?>
	isConfigured ()) {
			$piwikVersion = self::$wpPiwik->request ( 'global.getPiwikVersion' );
			if (is_array ( $piwikVersion ) && isset( $piwikVersion['value'] ))
				$piwikVersion = $piwikVersion['value'];
			if (! empty ( $piwikVersion ) && !is_array( $piwikVersion ))
				$this->showDonation();
		}
	?>
	
 
showInputWrapper($id, $name, $description, $isHidden, $groupName, $hideDescription, function() use ($id, $onChange) {
            ?>
            getGlobalOption ( $id ) ? ' checked="checked"' : '')?> onchange="jQuery('#=$id ?>').val(this.checked?1:0); =$onChange ?>" />
            
            
        
            | 
                
                
                
                    
                     
                        = __( $description, 'wp-piwik' ) ?>
                     
                
             | 
        
        showInputWrapper($id, $name, $description, $isHidden, $groupName, $hideDescription, function() use ($id, $onChange, $rows, $isReadonly, $global) {
            ?>
                
            %s  | ', $text );
	}
	/**
	 * Show an input option
	 *
	 * @param string $id option id
	 * @param string $name descriptive option name
	 * @param string $description option description
	 * @param boolean $isHidden set to true to initially hide the option (default: false)
	 * @param string $groupName define a class name to access a group of option rows by javascript (default: empty)
	 * @param string $rowName define a class name to access the specific option row by javascript (default: empty)
	 * @param boolean $hideDescription $hideDescription set to false to show description initially (default: true)
	 * @param boolean $wide Create a wide box (default: false)
	 */
	private function showInput($id, $name, $description, $isHidden = false, $groupName = '', $rowName = false, $hideDescription = true, $wide = false) {
        $this->showInputWrapper($id, $name, $description, $isHidden, $groupName, $hideDescription, function() use ($id) {
            ?>
            
             descriptive name)
	 * @param string $description option description
	 * @param string $onChange javascript for onchange event (default: empty)
	 * @param boolean $isHidden set to true to initially hide the option (default: false)
	 * @param string $groupName define a class name to access a group of option rows by javascript (default: empty)
	 * @param boolean $hideDescription $hideDescription set to false to show description initially (default: true)
	 * @param boolean $global set to false if the textarea shows a site-specific option (default: true)
	 */
	private function showSelect($id, $name, $options = array(), $description = '', $onChange = '', $isHidden = false, $groupName = '', $hideDescription = true, $global = true) {
		$default = $global ? self::$settings->getGlobalOption ( $id ) : self::$settings->getOption ( $id );
        $this->showInputWrapper($id, $name, $description, $isHidden, $groupName, $hideDescription, function() use ($id, $onChange, $options, $default) {
            ?>
            
             | ', $type, $icon, $content );
	}
	/**
	 * Show headline
	 * @param int $order headline order (h?-tag), set to 0 to avoid headline-tagging
	 * @param string $icon headline icon, see https://developer.wordpress.org/resource/dashicons/
	 * @param string $headline headline text
	 * @param string $addPluginName set to true to add the plugin name to the headline (default: false)
	 */
	private function showHeadline($order, $icon, $headline, $addPluginName = false) {
		echo $this->getHeadline ( $order, $icon, $headline, $addPluginName = false );
	}
	/**
	 * Get headline HTML
	 *
	 * @param int $order headline order (h?-tag), set to 0 to avoid headline-tagging
	 * @param string $icon headline icon, see https://developer.wordpress.org/resource/dashicons/
	 * @param string $headline headline text
	 * @param string $addPluginName set to true to add the plugin name to the headline (default: false)
	 */
	private function getHeadline($order, $icon, $headline, $addPluginName = false) {
		echo ($order > 0 ? "" : '') . sprintf ( ' %s%s', $icon, ($addPluginName ? self::$settings->getNotEmptyGlobalOption ( 'plugin_display_name' ) . ' ' : ''), __ ( $headline, 'wp-piwik' ) ) . ($order > 0 ? "" : '');
	}
	/**
	 * Show donation info
	 */
	private function showDonation() {
		?>
        
		Chart.js (MIT License).','wp-piwik'); ?>
		, !
		
		you for using my plugin. It is the best commendation if my piece of code is really used!','wp-piwik'); ?>
		
        
        
        
        
		
		or cURL has to be available:', 'wp-piwik'); ?>
		
			- '.(function_exists('curl_init')?'':__('not','wp-piwik')).' ';
				_e('available','wp-piwik');
			?>.
 
			- '.(ini_get('allow_url_fopen')?'':__('not','wp-piwik')).' ';
				_e('enabled','wp-piwik');
			?>.
 
			- getGlobalOption('http_connection') == 'curl') || (function_exists('curl_init') && !ini_get('allow_url_fopen')))?__('cURL', 'wp-piwik'):__('fopen', 'wp-piwik')).' ('.(self::$settings->getGlobalOption('http_method')=='post'?__('POST','wp-piwik'):__('GET','wp-piwik')).') '.__('is used.', 'wp-piwik'); ?>
 
			getGlobalOption('piwik_mode') == 'php') { ?>- '.(self::$settings->getGlobalOption('proxy_url')).'';
			?>
 
		
		:
		
			 
			 
			 
			 
		
		readRSSFeed('http://wordpress.org/support/rss/plugin/wp-piwik');
		if (!empty($supportThreads)) {
			echo '';
			foreach ($supportThreads as $supportThread)
				echo '- '.$supportThread['title'].'
 ';
			echo '
';
		}
	}
	/**
	 * Read RSS feed
	 *
	 * @param string $feed
	 *        	feed URL
	 * @param int $cnt
	 *        	item limit
	 * @return array feed items array[](title, url)
	 *
	 */
	private function readRSSFeed($feed, $cnt = 5) {
		$result = array ();
		if (function_exists ( 'simplexml_load_file' ) && ! empty ( $feed )) {
			$xml = @simplexml_load_file ( $feed );
			if (! $xml || ! isset ( $xml->channel [0]->item ))
				return array (
						array (
								'title' => 'Can\'t read RSS feed.',
								'url' => $xml
						)
				);
			foreach ( $xml->channel [0]->item as $item ) {
				if ($cnt -- == 0)
					break;
				$result [] = array (
						'title' => $item->title [0],
						'url' => $item->link [0]
				);
			}
		}
		return $result;
	}
	/**
	 * Clear cache and reset settings
	 *
	 * @param boolean $clearSettings set to true to reset settings (default: false)
	 */
	private function clear($clearSettings = false) {
		if ($clearSettings) {
			self::$settings->resetSettings();
			$this->showBox ( 'updated', 'yes', __ ( 'Settings cleared (except connection settings).' ) );
		}
		global $wpdb;
		if (self::$settings->checkNetworkActivation()) {
			$aryBlogs = \WP_Piwik\Settings::getBlogList();
			if (is_array($aryBlogs))
				foreach ($aryBlogs as $aryBlog) {
                    switch_to_blog($aryBlog['blog_id']);
					$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
					$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
					restore_current_blog();
				}
		} else {
			$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wp-piwik_%'");
			$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_wp-piwik_%'");
		}
		$this->showBox ( 'updated', 'yes', __ ( 'Cache cleared.' ) );
	}
	/**
	 * Execute test script and display results
	 */
	private function runTestscript() { ?>
		
		
Testscript Result
		isConfigured()) {
				if (isset($_GET['testscript_id']) && $_GET['testscript_id'])
					switch_to_blog((int) $_GET['testscript_id']);
		?>
		
		Please configure WP-Matomo first.';
		?>