コード例 #1
0
function ppl_options_from_post($options, $args)
{
    foreach ($args as $arg) {
        switch ($arg) {
            case 'limit':
            case 'skip':
                $options[$arg] = ppl_check_cardinal($_POST[$arg]);
                break;
            case 'excluded_cats':
            case 'included_cats':
                if (isset($_POST[$arg])) {
                    // get the subcategories too
                    if (function_exists('get_term_children')) {
                        $catarray = $_POST[$arg];
                        foreach ($catarray as $cat) {
                            $catarray = array_merge($catarray, get_term_children($cat, 'category'));
                        }
                        $_POST[$arg] = array_unique($catarray);
                    }
                    $options[$arg] = implode(',', $_POST[$arg]);
                } else {
                    $options[$arg] = '';
                }
                break;
            case 'excluded_authors':
            case 'included_authors':
                if (isset($_POST[$arg])) {
                    $options[$arg] = implode(',', $_POST[$arg]);
                } else {
                    $options[$arg] = '';
                }
                break;
            case 'excluded_posts':
            case 'included_posts':
                $check = explode(',', rtrim($_POST[$arg]));
                $ids = array();
                foreach ($check as $id) {
                    $id = ppl_check_cardinal($id);
                    if ($id !== 0) {
                        $ids[] = $id;
                    }
                }
                $options[$arg] = implode(',', array_unique($ids));
                break;
            case 'stripcodes':
                $st = explode("\n", trim($_POST['starttags']));
                $se = explode("\n", trim($_POST['endtags']));
                if (count($st) != count($se)) {
                    $options['stripcodes'] = array(array());
                } else {
                    $num = count($st);
                    for ($i = 0; $i < $num; $i++) {
                        $options['stripcodes'][$i]['start'] = $st[$i];
                        $options['stripcodes'][$i]['end'] = $se[$i];
                    }
                }
                break;
            case 'age':
                $options['age']['direction'] = $_POST['age-direction'];
                $options['age']['length'] = ppl_check_cardinal($_POST['age-length']);
                $options['age']['duration'] = $_POST['age-duration'];
                break;
            case 'custom':
                $options['custom']['key'] = $_POST['custom-key'];
                $options['custom']['op'] = $_POST['custom-op'];
                $options['custom']['value'] = $_POST['custom-value'];
                break;
            case 'num_terms':
                $options['num_terms'] = $_POST['num_terms'];
                if ($options['num_terms'] < 1) {
                    $options['num_terms'] = 20;
                }
                break;
            default:
                $options[$arg] = $_POST[$arg];
        }
    }
    return $options;
}
コード例 #2
0
function similar_posts_index_options_subpage()
{
    if (isset($_POST['reindex_all'])) {
        check_admin_referer('similar-posts-manage-update-options');
        if (defined('POC_CACHE_4')) {
            poc_cache_flush();
        }
        $options = get_option('similar-posts');
        $options['utf8'] = $_POST['utf8'];
        if (!function_exists('mb_split')) {
            $options['utf8'] = 'false';
        }
        $options['use_stemmer'] = $_POST['use_stemmer'];
        $options['batch'] = ppl_check_cardinal($_POST['batch']);
        if ($options['batch'] === 0) {
            $options['batch'] = 100;
        }
        flush();
        $termcount = save_index_entries($options['utf8'] === 'true', $options['use_stemmer'] === 'true', $options['batch']);
        update_option('similar-posts', $options);
        //show a message
        printf(__('<div class="updated fade"><p>Indexed %d posts.</p></div>'), $termcount);
    } else {
        $options = get_option('similar-posts');
    }
    ?>
    <div class="wrap"> 
		<?php 
    _e('<h2>Manage Index</h2>', 'post_plugins');
    _e('<p><strong>Similar Posts</strong> maintains a special index to help search for related posts. 
			The index is created when the plugin is activated and then kept up-to-date 
			automatically when posts are added, edited, or deleted.</p>
			<p>The two options that affect the index can be set below.</p>', 'post_plugins');
    _e('<p>If you are using a language other than english you may find that the plugin 
			mangles some characters since PHP is normally blind to multibyte characters. You 
			can force the plugin to interpret extended characters as UTF-8 at the expense 
			of a little speed. <em>This facility is only available if your 
			installation of PHP supports the mbstring functions.</em></p>', 'post_plugins');
    _e('<p>Some related word forms should really be counted together, e.g., "follow", 
			"follows", and "following". The plugin can use a <em>stemming</em> algorithm to
			reduce related forms to their root stem. It is worth experimenting to see if this
			improves the similarity of posts in your particular circumstances. Stemming algorithms are provided
			for english, german, spanish, french and italian but stemmers for other languages 
			can be created: see the help for instructions. <em>Stemming slows down the 
			indexing more than a little.</em></p>', 'post_plugins');
    _e('<p>The indexing routine processes posts in batches of 100 by default. If you run into
			problems with limited memory you can opt to make the batches smaller.</p>', 'post_plugins');
    _e('<p><strong>Note</strong>: The process of indexing may take a little while. On my
			modest machine 500 posts take between 5 seconds and 20 seconds (with stemming and
			utf-8 support). <strong>Don\'t worry if the screen fails to update until finished</strong>.</p>', 'post_plugins');
    ?>
		<form method="post" action="">		
		<table class="optiontable form-table">
			<tr valign="top">
				<th scope="row"><?php 
    _e('Handle extended characters?', 'post_plugins');
    ?>
</th>
				<td>
					<select name="utf8" id="utf8" <?php 
    if (!function_exists('mb_split')) {
        echo 'disabled="true"';
    }
    ?>
 >
					<option <?php 
    if ($options['utf8'] == 'false') {
        echo 'selected="selected"';
    }
    ?>
 value="false">No</option>
					<option <?php 
    if ($options['utf8'] == 'true') {
        echo 'selected="selected"';
    }
    ?>
 value="true">Yes</option>
					</select>
				</td> 
			</tr>
			<tr valign="top">
				<th scope="row"><?php 
    _e('Use a stemming algorithm?', 'post_plugins');
    ?>
</th>
				<td>
					<select name="use_stemmer" id="use_stemmer">
					<option <?php 
    if ($options['use_stemmer'] == 'false') {
        echo 'selected="selected"';
    }
    ?>
 value="false">No</option>
					<option <?php 
    if ($options['use_stemmer'] == 'true') {
        echo 'selected="selected"';
    }
    ?>
 value="true">Yes</option>
					</select>
				</td> 
			</tr>
			<tr valign="top">
				<th scope="row"><?php 
    _e('Batch size:', 'post_plugins');
    ?>
</th>
				<td><input name="batch" type="text" id="batch" value="<?php 
    echo $options['batch'];
    ?>
" size="3" /></td>
			</tr>
		</table>
		<div class="submit">
		<input type="submit" name="reindex_all" value="<?php 
    _e('Recreate Index', 'post_plugins');
    ?>
" />
		<?php 
    if (function_exists('wp_nonce_field')) {
        wp_nonce_field('similar-posts-manage-update-options');
    }
    ?>
		</div>   
		</form>       
    </div>
	<?php 
}