Example #1
0
function wp_statistics_not_enable()
{
    global $WP_Statistics;
    // If the user had told us to be quite, do so.
    if (!$WP_Statistics->get_option('hide_notices')) {
        $get_bloginfo_url = get_admin_url() . "admin.php?page=wp-statistics/settings";
        if (!$WP_Statistics->get_option('useronline')) {
            echo '<div class="update-nag"><p>' . sprintf(__('Online user tracking in WP Statistics is not enabled, please go to %s and enable it.', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '">' . __('setting page', 'wp_statistics') . '</a>') . '</p></div>';
        }
        if (!$WP_Statistics->get_option('visits')) {
            echo '<div class="update-nag"><p>' . sprintf(__('Hit tracking in WP Statistics is not enabled, please go to %s and enable it.', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '">' . __('setting page', 'wp_statistics') . '</a>') . '</p></div>';
        }
        if (!$WP_Statistics->get_option('visitors')) {
            echo '<div class="update-nag"><p>' . sprintf(__('Visitor tracking in WP Statistics is not enabled, please go to %s and enable it.', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '">' . __('setting page', 'wp_statistics') . '</a>') . '</p></div>';
        }
        if (!$WP_Statistics->get_option('geoip') && wp_statistics_geoip_supported()) {
            echo '<div class="update-nag"><p>' . sprintf(__('GeoIP collection is not active, please go to %s and enable this feature.', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '&tab=geoip">' . __('Setting page > GeoIP', 'wp_statistics') . '</a>') . '</p></div>';
        }
    }
}
Example #2
0
			<th scope="row" colspan="2"><h3><?php 
_e('GeoIP settings', 'wp_statistics');
?>
</h3></th>
		</tr>

		<tr valign="top">
			<th scope="row" colspan="2">
				<?php 
echo sprintf(__('IP location services provided by GeoLite2 data created by MaxMind, available from %s.', 'wp_statistics'), '<a href="http://www.maxmind.com" target=_blank>http://www.maxmind.com</a>');
?>
			</th>
		</tr>
		
		<?php 
if (wp_statistics_geoip_supported()) {
    ?>
		<tr valign="top">
			<th scope="row">
				<label for="geoip-enable"><?php 
    _e('GeoIP collection', 'wp_statistics');
    ?>
:</label>
			</th>
			
			<td>
				<input id="geoip-enable" type="checkbox" name="wps_geoip" <?php 
    echo $WP_Statistics->get_option('geoip') == true ? "checked='checked'" : '';
    ?>
>
				<label for="geoip-enable"><?php 
Example #3
0
function wp_statistics_not_enable()
{
    global $WP_Statistics;
    // If the user had told us to be quite, do so.
    if (!$WP_Statistics->get_option('hide_notices')) {
        // Check to make sure the current user can manage WP Statistics, if not there's no point displaying the warnings.
        $manage_cap = wp_statistics_validate_capability($WP_Statistics->get_option('manage_capability', 'manage_options'));
        if (!current_user_can($manage_cap)) {
            return;
        }
        $get_bloginfo_url = get_admin_url() . "admin.php?page=" . WP_STATISTICS_SETTINGS_PAGE;
        $itemstoenable = array();
        if (!$WP_Statistics->get_option('useronline')) {
            $itemstoenable[] = __('online user tracking', 'wp_statistics');
        }
        if (!$WP_Statistics->get_option('visits')) {
            $itemstoenable[] = __('hit tracking', 'wp_statistics');
        }
        if (!$WP_Statistics->get_option('visitors')) {
            $itemstoenable[] = __('visitor tracking', 'wp_statistics');
        }
        if (!$WP_Statistics->get_option('geoip') && wp_statistics_geoip_supported()) {
            $itemstoenable[] = __('geoip collection', 'wp_statistics');
        }
        if (count($itemstoenable) > 0) {
            echo '<div class="update-nag">' . sprintf(__('The following features are disabled, please go to %s and enable them: %s', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '">' . __('settings page', 'wp_statistics') . '</a>', implode(__(',', 'wp_statistics'), $itemstoenable)) . '</div>';
        }
        $get_bloginfo_url = get_admin_url() . "admin.php?page=" . WP_STATISTICS_OPTIMIZATION_PAGE . "&tab=database";
        $dbupdatestodo = array();
        if (!$WP_Statistics->get_option('search_converted')) {
            $dbupdatestodo[] = __('search table', 'wp_statistics');
        }
        // Check to see if there are any database changes the user hasn't done yet.
        $dbupdates = $WP_Statistics->get_option('pending_db_updates', false);
        // The database updates are stored in an array so loop thorugh it and output some notices.
        if (is_array($dbupdates)) {
            $dbstrings = array('date_ip_agent' => __('countries database index', 'wp_statistics'), 'unique_date' => __('visit database index', 'wp_statistics'));
            foreach ($dbupdates as $key => $update) {
                if ($update == true) {
                    $dbupdatestodo[] = $dbstrings[$key];
                }
            }
            if (count($dbupdatestodo) > 0) {
                echo '<div class="update-nag">' . sprintf(__('Database updates are required, please go to %s and update the following: %s', 'wp_statistics'), '<a href="' . $get_bloginfo_url . '">' . __('optimization page', 'wp_statistics') . '</a>', implode(__(',', 'wp_statistics'), $dbupdatestodo)) . '</div>';
            }
        }
    }
}
	function wp_statistics_download_geoip() {

		GLOBAL $WP_Statistics;

		// We need the download_url() and gzopen() functions, it should exists on virtually all installs of PHP, but if it doesn't for some reason, bail out.
		// Also stop trying to update the database as it just won't work :)
		if( false === function_exists( 'download_url' ) || false === function_exists( 'gzopen' ) ) { 
				$WP_Statistics->update_option('update_geoip', false);
				
				$result = "<div class='updated settings-error'><p><strong>" . __('Error the download_url() or gzopen() functions do not exist!', 'wp_statistics') . "</strong></p></div>";
				return $result;
		}

		// If GeoIP is disabled, bail out.
		if( $WP_Statistics->get_option('geoip') == false ) { return '';}

		// This is the location of the file to download.
		$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz';

		// Get the upload directory from WordPRess.
		$upload_dir = wp_upload_dir();

		// Create a variable with the name of the database file to download.
		$DBFile = $upload_dir['basedir'] . '/wp-statistics/GeoLite2-Country.mmdb';

		// Check to see if the subdirectory we're going to upload to exists, if not create it.
		if( !file_exists($upload_dir['basedir'] . '/wp-statistics') ) {
			if( !@mkdir($upload_dir['basedir'] . '/wp-statistics', 0755 ) ) {
				$WP_Statistics->update_option('update_geoip', false);
				
				$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error creating GeoIP database directory, make sure your web server has permissions to create directories in : %s', 'wp_statistics'), $upload_dir['basedir'] ) . "</strong></p></div>";
				return $result;
			}
		}

		if( !is_writable( $upload_dir['basedir'] . '/wp-statistics' ) ) {
			$WP_Statistics->update_option('update_geoip', false);

			$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error setting permissions of the GeoIP database directory, make sure your web server has permissions to write to directories in : %s', 'wp_statistics'), $upload_dir['basedir'] ) . "</strong></p></div>";
			return $result;
		}
		
		// Download the file from MaxMind, this places it in a temporary location.
		$TempFile = download_url( $download_url );

		// If we failed, through a message, otherwise proceed.
		if (is_wp_error( $TempFile ) ) {
			$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error downloading GeoIP database from: %s - %s', 'wp_statistics'), $download_url, $TempFile->get_error_message() ) . "</strong></p></div>";
		}
		else {
			// Open the downloaded file to unzip it.
			$ZipHandle = gzopen( $TempFile, 'rb' );

			// Create th new file to unzip to.
			$DBfh = fopen( $DBFile, 'wb' );

			// If we failed to open the downloaded file, through an error and remove the temporary file.  Otherwise do the actual unzip.
			if( ! $ZipHandle ) {
				$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error could not open downloaded GeoIP database for reading: %s', 'wp_statistics'), $TempFile) . "</strong></p></div>";

				unlink( $TempFile );
			}
			else {
				// If we failed to open the new file, throw and error and remove the temporary file.  Otherwise actually do the unzip.
				if( !$DBfh ) {
					$result = "<div class='updated settings-error'><p><strong>" . sprintf(__('Error could not open destination GeoIP database for writing %s', 'wp_statistics'), $DBFile) . "</strong></p></div>";
					unlink( $TempFile );
				}
				else {
					while( ( $data = gzread( $ZipHandle, 4096 ) ) != false ) {
						fwrite( $DBfh, $data );
					}

					// Close the files.
					gzclose( $ZipHandle );
					fclose( $DBfh );

					// Delete the temporary file.
					unlink( $TempFile );

					// Display the success message.
					$result = "<div class='updated settings-error'><p><strong>" . __('GeoIP Database updated successfully!', 'wp_statistics') . "</strong></p></div>";

					// Update the options to reflect the new download.
					$WP_Statistics->update_option('last_geoip_dl', time());
					$WP_Statistics->update_option('update_geoip', false);

					// Populate any missing GeoIP information if the user has selected the option.
					if( $WP_Statistics->get_option('geoip') && wp_statistics_geoip_supported() && $WP_Statistics->get_option('auto_pop')) {
						include_once dirname( __FILE__ ) . '/includes/functions/geoip-populate.php';
						$result .= wp_statistics_populate_geoip_info();
					}
				}
			}
		}

		if( $WP_Statistics->get_option('geoip_report') == true ) {
			$blogname = get_bloginfo('name');
			$blogemail = get_bloginfo('admin_email');

			$headers[] = "From: $blogname <$blogemail>";
			$headers[] = "MIME-Version: 1.0";
			$headers[] = "Content-type: text/html; charset=utf-8";

			if( $WP_Statistics->get_option('email_list') == '' ) { $WP_Statistics->update_option( 'email_list', $blogemail ); }

			wp_mail( $WP_Statistics->get_option('email_list'), __('GeoIP update on', 'wp_statistics') . ' ' . $blogname, $result, $headers );
		}

		// All of the messages displayed above are stored in a stirng, now it's time to actually output the messages.
		return $result;
	}