<commit_before><?php
namespace Podlove;

class SystemReport {

	private $fields = array();
	private $notices = array();
	private $errors = array();

	public function __construct() {

		$errors =& $this->errors;
		
		$this->fields = array(
			'site'        => array( 'title' => 'Website',           'callback' => function() { return get_site_url(); } ),
			'php_version' => array( 'title' => 'PHP Version',       'callback' => function() { return phpversion(); } ),
			'wp_version'  => array( 'title' => 'WordPress Version', 'callback' => function() { return get_bloginfo('version'); } ),
			'curl'        => array( 'title' => 'curl Version',      'callback' => function() use ( &$errors ) {
				$module_loaded = in_array( 'curl', get_loaded_extensions() );
				$function_disabled = stripos( ini_get( 'disable_functions' ), 'curl_exec' ) !== false;
				$out = '';

				if ( $module_loaded ) {
					$curl = curl_version();
					$out .= $curl['version'];
				} else {
					$out .= 'EXTENSION MISSING';
					$errors[] = 'curl extension is not loaded';
				}

				if ( $function_disabled ) {
					$out .= ' | curl_exec is disabled';
					$errors[] = 'curl_exec is disabled';
				}

				return $out;
			} ),
			'iconv' => array( 'callback' => function() {	
				$iconv_available = function_exists( 'iconv' );

				if ( ! $iconv_available ) {
					$errors[] = 'You need to install/activate php5-iconv';
				}

				return $iconv_available ? "available" : "MISSING";
			} ),
			'allow_url_fopen'     => array( 'callback' => function() {

				if ( ! $allow_url_fopen = ini_get( 'allow_url_fopen' ) )
					$errors[] = 'allow_url_fopen must be activated in your php.ini';

				return $allow_url_fopen;
			} ),
			'max_execution_time'  => array( 'callback' => function() { return ini_get( 'max_execution_time' ); } ),
			'upload_max_filesize' => array( 'callback' => function() { return ini_get( 'upload_max_filesize' ); } ),
			'memory_limit'        => array( 'callback' => function() { return ini_get( 'memory_limit' ); } ),
			'disable_classes'     => array( 'callback' => function() { return ini_get( 'disable_classes' ); } ),
			'disable_functions'   => array( 'callback' => function() { return ini_get( 'disable_functions' ); } )
		);

		$this->run();
	}

	public function run() {

		$this->errors = array();
		$this->notices = array();

		foreach ( $this->fields as $field_key => $field ) {
			$this->fields[ $field_key ]['value'] = call_user_func( $field['callback'] );
		}

		update_option( 'podlove_global_messages', array( 'errors' => $this->errors, 'notices' => $this->notices ) );
	}

	public function render() {

		$rfill = function ( $string, $length, $fillchar = ' ' ) {
			while ( strlen( $string ) < $length ) {
				$string .= $fillchar;
			}
			return $string;
		};

		$fill_length = 1 + max( array_map( function($k) { return strlen($k); }, array_keys( $this->fields ) ) );
<commit_msg>add system report check for permalink setting<commit_after><?php
namespace Podlove;

class SystemReport {

	private $fields = array();
	private $notices = array();
	private $errors = array();

	public function __construct() {

		$errors =& $this->errors;
		
		$this->fields = array(
			'site'        => array( 'title' => 'Website',           'callback' => function() { return get_site_url(); } ),
			'php_version' => array( 'title' => 'PHP Version',       'callback' => function() { return phpversion(); } ),
			'wp_version'  => array( 'title' => 'WordPress Version', 'callback' => function() { return get_bloginfo('version'); } ),
			'curl'        => array( 'title' => 'curl Version',      'callback' => function() use ( &$errors ) {
				$module_loaded = in_array( 'curl', get_loaded_extensions() );
				$function_disabled = stripos( ini_get( 'disable_functions' ), 'curl_exec' ) !== false;
				$out = '';

				if ( $module_loaded ) {
					$curl = curl_version();
					$out .= $curl['version'];
				} else {
					$out .= 'EXTENSION MISSING';
					$errors[] = 'curl extension is not loaded';
				}

				if ( $function_disabled ) {
					$out .= ' | curl_exec is disabled';
					$errors[] = 'curl_exec is disabled';
				}

				return $out;
			} ),
			'iconv' => array( 'callback' => function() {	
				$iconv_available = function_exists( 'iconv' );

				if ( ! $iconv_available ) {
					$errors[] = 'You need to install/activate php5-iconv';
				}

				return $iconv_available ? "available" : "MISSING";
			} ),
			'allow_url_fopen' => array( 'callback' => function() {

				if ( ! $allow_url_fopen = ini_get( 'allow_url_fopen' ) )
					$errors[] = 'allow_url_fopen must be activated in your php.ini';

				return $allow_url_fopen;
			} ),
			'max_execution_time'  => array( 'callback' => function() { return ini_get( 'max_execution_time' ); } ),
			'upload_max_filesize' => array( 'callback' => function() { return ini_get( 'upload_max_filesize' ); } ),
			'memory_limit'        => array( 'callback' => function() { return ini_get( 'memory_limit' ); } ),
			'disable_classes'     => array( 'callback' => function() { return ini_get( 'disable_classes' ); } ),
			'disable_functions'   => array( 'callback' => function() { return ini_get( 'disable_functions' ); } ),
			'permalinks' => array( 'callback' => function() use ( &$errors ) {

				if ( \Podlove\get_setting( 'use_post_permastruct' ) == 'on' )
					return 'ok';

				if ( stristr( \Podlove\get_setting( 'custom_episode_slug' ), '%podcast%' ) === FALSE ) {
					$errors[] = 'The episode permastruct is missing the "%podcast%" segment!';
					return '%podcast% placeholder missing!';
				}

				return 'ok';
			} )
		);

		$this->run();
	}

	public function run() {

		$this->errors = array();
		$this->notices = array();

		foreach ( $this->fields as $field_key => $field ) {
			$this->fields[ $field_key ]['value'] = call_user_func( $field['callback'] );
		}

		update_option( 'podlove_global_messages', array( 'errors' => $this->errors, 'notices' => $this->notices ) );
	}

	public function render() {

		$rfill = function ( $string, $length, $fillchar = ' ' ) {
			while ( strlen( $string ) < $length ) {
				$string .= $fillchar;
			}
			return $string;
		};

		$fill_length = 1 + max( array_map( function($k) { return strlen($k); }, array_keys( $this->fields ) ) );

{'fraction_non_alphanumeric': 0.18578092327489143, 'fraction_numerical': 0.0006433971368827409, 'mean_word_length': 3.4068036853295536, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843169', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2032, 'n_words': 473}