* phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery
* phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching
*/
class Settings extends \WP_Piwik\Admin {
/**
* Builds and displays the settings page
*/
public function show() {
if ( ! empty( $_GET['sitebrowser'] ) ) {
new \WP_Piwik\Admin\Sitebrowser( self::$wp_piwik );
return;
}
if ( ! empty( $_GET['clear'] ) && check_admin_referer() ) {
$this->clear( 2 === $_GET['clear'] );
self::$wp_piwik->reset_request();
$page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
echo '
';
return;
} elseif ( self::$wp_piwik->is_config_submitted() ) {
$this->show_box( 'updated', 'yes', esc_html__( 'Changes saved.', 'wp-piwik' ) );
self::$wp_piwik->reset_request();
if ( 'php' === self::$settings->get_global_option( 'piwik_mode' ) ) {
self::$wp_piwik->define_piwik_constants();
}
if ( self::$settings->get_global_option( 'auto_site_config' ) && self::$wp_piwik->is_configured() ) {
$site_id = self::$wp_piwik->get_piwik_site_id( null, true );
self::$wp_piwik->update_tracking_code( $site_id );
self::$settings->set_option( 'site_id', $site_id );
} else {
self::$wp_piwik->update_tracking_code();
}
}
global $wp_roles;
?>
get_headline( 1, 'admin-generic', 'Settings', true );
if ( ! empty( $_GET['testscript'] ) ) {
$this->run_testscript();
}
?>
is_configured() ) {
$piwik_version = self::$wp_piwik->request( 'global.getPiwikVersion' );
if ( is_array( $piwik_version ) && isset( $piwik_version['value'] ) ) {
$piwik_version = $piwik_version['value'];
}
}
$page = sanitize_key( wp_unslash( $_GET['page'] ) );
?>
show_input_wrapper(
$id,
$name,
$description,
$is_hidden,
$group_name,
$hide_description,
function () use ( $id, $on_change ) {
?>
get_global_option( $id ) ? ' checked="checked"' : '' ); ?> onchange="jQuery().val(this.checked?1:0);
" />
|
|
show_input_wrapper(
$id,
$name,
$description,
$is_hidden,
$group_name,
$hide_description,
function () use ( $id, $on_change, $rows, $is_readonly, $is_global ) {
?>
%s | ', esc_html( $text ) );
}
/**
* Show an input option
*
* @param string $id option id
* @param string $name descriptive option name
* @param string|false $description option description
* @param boolean $is_hidden set to true to initially hide the option (default: false)
* @param string $group_name define a class name to access a group of option rows by javascript (default: empty)
* @param string|false $row_name define a class name to access the specific option row by javascript (default: empty)
* @param boolean $hide_description $hideDescription set to false to show description initially (default: true)
* @param boolean $wide Create a wide box (default: false)
*/
private function show_input( $id, $name, $description, $is_hidden = false, $group_name = '', $row_name = false, $hide_description = true, $wide = false, $type = false ) {
$this->show_input_wrapper(
$id,
$name,
$description,
$is_hidden,
$group_name,
$hide_description,
function () use ( $id, $type ) {
?>
descriptive name)
* @param string $description option description
* @param string $on_change javascript for onchange event (default: empty)
* @param boolean $is_hidden set to true to initially hide the option (default: false)
* @param string $group_name define a class name to access a group of option rows by javascript (default: empty)
* @param boolean $hide_description $hideDescription set to false to show description initially (default: true)
* @param boolean $is_global set to false if the textarea shows a site-specific option (default: true)
*/
private function show_select( $id, $name, $options = array(), $description = '', $on_change = '', $is_hidden = false, $group_name = '', $hide_description = true, $is_global = true ) {
$default = $is_global ? self::$settings->get_global_option( $id ) : self::$settings->get_option( $id );
$this->show_input_wrapper(
$id,
$name,
$description,
$is_hidden,
$group_name,
$hide_description,
function () use ( $id, $on_change, $options, $default ) {
?>
| ', esc_attr( $type ), esc_attr( $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|bool $add_plugin_name set to true to add the plugin name to the headline (default: false)
*/
private function show_headline( $order, $icon, $headline, $add_plugin_name = false ) {
$this->get_headline( $order, $icon, $headline, $add_plugin_name );
}
/**
* 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 bool $add_plugin_name set to true to add the plugin name to the headline (default: false)
*/
private function get_headline( $order, $icon, $headline, $add_plugin_name = false ) {
echo ( $order > 0 ? '' : '' )
. sprintf(
' %s%s',
esc_attr( $icon ),
esc_html( $add_plugin_name ? self::$settings->get_not_empty_global_option( 'plugin_display_name' ) . ' ' : '' ),
esc_html( $headline )
)
. ( $order > 0 ? '' : '' );
}
/**
* Register admin scripts
*
* @see \WP_Piwik\Admin::print_admin_scripts()
*/
public function print_admin_scripts() {
wp_enqueue_script( 'jquery' );
}
/**
* Extend admin header
*
* @see \WP_Piwik\Admin::extend_admin_header()
*/
public function extend_admin_header() {
}
/**
* Show credits
*/
public function show_credits() {
?>
',
''
);
?>
, !
',
''
);
?>
',
''
);
?>
-
' . ( function_exists( 'curl_init' ) ? '' : esc_html__( 'not', 'wp-piwik' ) ) . ' ';
esc_html_e( 'available', 'wp-piwik' );
?>
.
-
' . ( ini_get( 'allow_url_fopen' ) ? '' : esc_html__( 'not', 'wp-piwik' ) ) . ' ';
esc_html_e( 'enabled', 'wp-piwik' );
?>
.
- get_global_option( 'http_connection' ) ) || ( function_exists( 'curl_init' ) && ! ini_get( 'allow_url_fopen' ) ) ) ? esc_html__( 'cURL', 'wp-piwik' ) : esc_html__( 'fopen', 'wp-piwik' ) ) . ' (' . ( 'post' === self::$settings->get_global_option( 'http_method' ) ? esc_html__( 'POST', 'wp-piwik' ) : esc_html__( 'GET', 'wp-piwik' ) ) . ') ' . esc_html__( 'is used.', 'wp-piwik' ); ?>
get_global_option( 'piwik_mode' ) ) {
?>
-
' . esc_html( self::$settings->get_global_option( 'proxy_url' ) ) . '';
?>
:
read_rss_feed( 'http://wordpress.org/support/rss/plugin/wp-piwik' );
if ( ! empty( $support_threads ) ) {
echo '';
foreach ( $support_threads as $support_thread ) {
echo '- ' . esc_html( $support_thread['title'] ) . '
';
}
echo '
';
}
}
/**
* Read RSS feed
*
* @param string $feed
* feed URL
* @param int $cnt
* item limit
* @return array feed items array[](title, url)
*
*/
private function read_rss_feed( $feed, $cnt = 5 ) {
$result = array();
if ( function_exists( 'simplexml_load_file' ) && ! empty( $feed ) ) {
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$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 ( 0 === $cnt-- ) {
break;
}
$result [] = array(
'title' => $item->title [0],
'url' => $item->link [0],
);
}
}
return $result;
}
/**
* Clear cache and reset settings
*
* @param boolean $clear_settings set to true to reset settings (default: false)
*/
private function clear( $clear_settings = false ) {
if ( $clear_settings ) {
self::$settings->reset_settings();
$this->show_box( 'updated', 'yes', esc_html__( 'Settings cleared (except connection settings).', 'wp-piwik' ) );
}
global $wpdb;
if ( self::$settings->check_network_activation() ) {
$ary_blogs = \WP_Piwik\Settings::get_blog_list();
if ( is_array( $ary_blogs ) ) {
foreach ( $ary_blogs as $ary_blog ) {
switch_to_blog( $ary_blog['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->show_box( 'updated', 'yes', esc_html__( 'Cache cleared.', 'wp-piwik' ) );
}
/**
* Execute test script and display results
*/
private function run_testscript() {
?>
Testscript Result
is_configured() ) {
if ( ! empty( $_GET['testscript_id'] ) ) {
switch_to_blog( intval( wp_unslash( $_GET['testscript_id'] ) ) );
}
?>
Please configure WP-Matomo first.