Exemple #1
0
function tguy_sm_options_page()
{
    if (isset($_POST['submitted'])) {
        check_admin_referer('search-meter-update-options_all');
        $options = get_option('tguy_search_meter');
        $options['sm_view_stats_capability'] = $_POST['sm_view_stats_capability'];
        $sm_filter_words = $_POST['sm_filter_words'];
        if (get_magic_quotes_gpc()) {
            $sm_filter_words = stripslashes($sm_filter_words);
        }
        $options['sm_filter_words'] = preg_replace('/\\s+/', ' ', trim($sm_filter_words));
        $options['sm_ignore_admin_search'] = (bool) $_POST['sm_ignore_admin_search'];
        $options['sm_details_verbose'] = (bool) $_POST['sm_details_verbose'];
        $options['sm_disable_donation'] = (bool) $_POST['sm_disable_donation'];
        update_option('tguy_search_meter', $options);
        echo '<div id="message" class="updated fade"><p><strong>Plugin settings saved.</strong></p></div>';
    } else {
        if (isset($_POST['tguy_sm_reset'])) {
            check_admin_referer('search-meter-reset-stats');
            tguy_sm_reset_stats();
            echo '<div id="message" class="updated fade"><p><strong>Statistics have been reset.</strong></p></div>';
        }
    }
    $options = get_option('tguy_search_meter');
    $view_stats_capability = tguy_sm_array_value($options, 'sm_view_stats_capability');
    if ($view_stats_capability == '') {
        $view_stats_capability = TGUY_SM_DEFAULT_VIEW_STATS_CAPABILITY;
    }
    ?>
	<div class="wrap">

		<h2>Search Meter Settings</h2>

		<form name="searchmeter" action="" method="post">
			<?php 
    if (function_exists('wp_nonce_field')) {
        wp_nonce_field('search-meter-update-options_all');
    }
    ?>

			<input type="hidden" name="submitted" value="1" />

			<table class="form-table">
				<tr>
					<th scope="row">Show statistics to</th>
					<td>
						<fieldset>
						<label title='Users with "read" capability'>
							<input type="radio" name="sm_view_stats_capability" value="read"
								<?php 
    echo $view_stats_capability == 'read' ? "checked=\"checked\"" : "";
    ?>
 />
							All logged-in users</label><br>
						<label title='Users with "publish_posts" capability'>
							<input type="radio" name="sm_view_stats_capability" value="publish_posts" 
								<?php 
    echo $view_stats_capability == 'publish_posts' ? "checked=\"checked\"" : "";
    ?>
 />
							Post authors and administrators</label><br>
						<label title='Users with "manage_options" capability'>
							<input type="radio" name="sm_view_stats_capability" value="manage_options" 
								<?php 
    echo $view_stats_capability == 'manage_options' ? "checked=\"checked\"" : "";
    ?>
 />
							Administrators only</label>
						</fieldset>
					</td>
				</tr>
				<tr valign="top">
					<th scope="row">Search filter</th>
					<td>
						<fieldset>
						<label for="sm_filter_words">When a search term contains any of these words, it will be filtered 
						and will not show up in the Recent Searches or Popular Searches widgets. This will match inside words, 
						so &#8220;press&#8221; will match &#8220;WordPress&#8221;.</label>
						<textarea name="sm_filter_words" rows="3" cols="40" id="sm_filter_words" class="large-text code"><?php 
    echo esc_html(tguy_sm_array_value($options, 'sm_filter_words'));
    ?>
</textarea>
						</fieldset>
					</td>
				</tr>
				<tr>
					<th class="th-full" scope="row" colspan="2">
						<label for="sm_ignore_admin_search" title='Administrators are users with "manage_options" capability'>
							<input type="checkbox" id="sm_ignore_admin_search" name="sm_ignore_admin_search" <?php 
    echo tguy_sm_array_value($options, 'sm_ignore_admin_search') ? 'checked="checked"' : '';
    ?>
 />
							Ignore searches made by logged-in administrators
						</label>
					</th>
				</tr>
				<tr>
					<th class="th-full" scope="row" colspan="2">
						<label for="sm_details_verbose">
							<input type="checkbox" id="sm_details_verbose" name="sm_details_verbose" <?php 
    echo tguy_sm_array_value($options, 'sm_details_verbose') ? 'checked="checked"' : '';
    ?>
 />
							Keep detailed information about recent searches (taken from HTTP headers)
						</label>
					</th>
				</tr>
				<tr>
					<th class="th-full" scope="row" colspan="2">
						<label for="sm_disable_donation">
							<input type="checkbox" id="sm_disable_donation" name="sm_disable_donation" <?php 
    echo tguy_sm_array_value($options, 'sm_disable_donation') ? 'checked="checked"' : '';
    ?>
 />
							Hide the &#8220;Do you find this plugin useful?&#8221; box
						</label>
					</th>
				</tr>
			</table>

			<p class="submit">
				<input name="Submit" class="button-primary" value="Save Changes" type="submit">
			</p>
		</form>

		<h3>Reset statistics</h3>

		<p>Click this button to reset all search statistics. This will delete all information about previous searches.</p>

		<form name="tguy_sm_admin" action="" method="post">
			<?php 
    if (function_exists('wp_nonce_field')) {
        wp_nonce_field('search-meter-reset-stats');
    }
    ?>
			<p class="submit">
				<input name="tguy_sm_reset" class="button-secondary delete" value="Reset Statistics" type="submit" onclick="return confirm('You are about to delete all saved search statistics.\n  \'Cancel\' to stop, \'OK\' to delete.');" />
			</p>
		</form>

		<h3>Notes</h3>

		<p>To see your search statistics, go to the <a href="index.php?page=<?php 
    echo plugin_basename(__FILE__);
    ?>
">Search Meter Dashboard</a>.</p>

		<p>For information and updates, see the <a href="http://thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. At that page, you can also offer suggestions, request new features or report problems.</p>

		<?php 
    if (!tguy_sm_array_value($options, 'sm_disable_donation')) {
        tguy_sm_show_donation_message();
    }
    ?>

	</div>
	<?php 
}
function tguy_sm_options_page()
{
    if (isset($_POST['submitted'])) {
        check_admin_referer('search-meter-update-options_all');
        $options = get_option('tguy_search_meter');
        $options['sm_details_verbose'] = (bool) $_POST['sm_details_verbose'];
        $options['sm_disable_donation'] = (bool) $_POST['sm_disable_donation'];
        update_option('tguy_search_meter', $options);
        echo '<div id="message" class="updated fade"><p><strong>Plugin settings saved.</strong></p></div>';
    } else {
        if (isset($_POST['tguy_sm_reset'])) {
            check_admin_referer('search-meter-reset-stats');
            tguy_sm_reset_stats();
            echo '<div id="message" class="updated fade"><p><strong>Statistics have been reset.</strong></p></div>';
        }
    }
    $options = get_option('tguy_search_meter');
    ?>
	<div class="wrap">

		<h2>Search Meter Options</h2>

		<form name="searchmeter" action="" method="post">
			<?php 
    if (function_exists('wp_nonce_field')) {
        wp_nonce_field('search-meter-update-options_all');
    }
    ?>

			<input type="hidden" name="submitted" value="1" />

			<table class="form-table">
				<tr>
					<th class="th-full" scope="row">
						<label for="sm_details_verbose">
							<input type="checkbox" id="sm_details_verbose" name="sm_details_verbose" <?php 
    echo $options['sm_details_verbose'] == true ? "checked=\"checked\"" : "";
    ?>
 />
							Keep detailed information about recent searches (taken from HTTP headers)
						</label>
					</th>
				</tr>
				<tr>
					<th class="th-full" scope="row">
						<label for="sm_disable_donation">
							<input type="checkbox" id="sm_disable_donation" name="sm_disable_donation" <?php 
    echo $options['sm_disable_donation'] == true ? "checked=\"checked\"" : "";
    ?>
 />
							Hide the &#8220;Do you find this plugin useful?&#8221; box
						</label>
					</th>
				</tr>
			</table>

			<p class="submit">
				<input name="Submit" class="button-primary" value="Save Changes" type="submit">
			</p>
		</form>

		<h3>Reset statistics</h3>

		<p>Click this button to reset all search statistics. This will delete all information about previous searches.</p>

		<form name="tguy_sm_admin" action="" method="post">
			<?php 
    if (function_exists('wp_nonce_field')) {
        wp_nonce_field('search-meter-reset-stats');
    }
    ?>
			<p class="submit">
				<input name="tguy_sm_reset" class="button-secondary delete" value="Reset Statistics" type="submit" onclick="return confirm('You are about to delete all saved search statistics.\n  \'Cancel\' to stop, \'OK\' to delete.');" />
			</p>
		</form>

		<h3>Notes</h3>

		<p>To see your search statistics, go to the <strong>Dashboard</strong> and choose <strong>Search Meter</strong>.</p>

		<p>For information and updates, see the <a href="http://www.thunderguy.com/semicolon/wordpress/search-meter-wordpress-plugin/">Search Meter home page</a>. At that page, you can also offer suggestions, request new features or report problems.</p>

		<?php 
    if (!$options['sm_disable_donation']) {
        tguy_sm_show_donation_message();
    }
    ?>

	</div>
	<?php 
}