示例#1
0
function gravatar_cron_set_refresh($rate = '')
{
    global $gravatar_cron_options;
    if (!isset($gravatar_cron_options)) {
        $gravatar_cron_options = gravatar_cron_options();
    }
    if (!isset($gravatar_cron_times)) {
        $gravatar_cron_times = gravatar_cron_times();
    }
    if (!isset($gravatar_cron_timekeys)) {
        $gravatar_cron_timekeys = array_keys($gravatar_cron_times);
    }
    if (empty($rate)) {
        $rate = $gravatar_cron_options['refresh_rate'];
    }
    if (!in_array($rate, $gravatar_cron_timekeys)) {
        $rate = 'daily';
    }
    foreach ($gravatar_cron_timekeys as $timekey) {
        $action = 'wp_cron_' . $timekey;
        remove_action($action, 'gravatar_cron_run');
    }
    $action = 'wp_cron_' . $rate;
    add_action($action, 'gravatar_cron_run');
    $gravatar_cron_options['refresh_rate'] = $rate;
    update_option('gravatar_cron_options', $gravatar_cron_options);
}
示例#2
0
function gravatar_manage_options()
{
    load_plugin_textdomain('gravatars');
    global $wpdb, $gravatar_expire, $gravatar_options;
    gravatar_default_options();
    $gravatar_options = get_option('gravatar_options');
    $gravatar_expire = get_option('gravatar_expire');
    // check to see if we can cache gravatars
    $CANCACHE = gravatar_cache_capable(1);
    // check to see if wp-cron-gravatars is enabled
    $CRONENABLED = gravatar_cron_enabled();
    if (isset($_POST['reset']) && 'RESET' == $_POST['reset']) {
        // reset the defaults
        gravatar_default_options('reset');
        $gravatar_options = get_option('gravatar_options');
        if (isset($_POST['cron_refresh_rate'])) {
            gravatar_cron_set_refresh('default');
        }
        gravatar_message("Gravatar Options Reset");
    } elseif (isset($_POST['gravatar_options']) && 'update' == $_POST['gravatar_options']) {
        // update the defaults
        gravatar_default_options('update', $_POST['rating'], $_POST['size'], $_POST['gravatar_border'], $_POST['default'], $_POST['rcache_method'], $_POST['use_rest'], $_POST['info_timeout'], $_POST['copy_timeout'], $_POST['pos_expire'], $_POST['neg_expire'], $_POST['err_expire'], $_POST['gravatar_in_posts'], $_POST['gravatar_allow_local'], $_POST['local_ulevel'], $_POST['gravatar_cache'], $_POST['gravatar_auto_cache_check']);
        $gravatar_options = get_option('gravatar_options');
        if (isset($_POST['cron_refresh_rate'])) {
            gravatar_cron_set_refresh($_POST['cron_refresh_rate']);
        }
        gravatar_message("Gravatar Options Updated");
    }
    echo "<div class='wrap'>";
    echo "<table width='100%' cellpadding='0' cellspacing='0'><tr><td><h2>";
    _e('Gravatar Options', 'gravatars');
    echo "</h2></td>";
    echo "<td align='right'><h2><span style='font-size: 75%;'><a href='./edit.php?page=gravatars2.php'>Gravatar Cache</a></span></h2></td>";
    echo "</tr></table>";
    echo "<fieldset class='options'>";
    echo "<table width='100%' cellspacing='2' cellpadding='5' class='editform'>";
    echo "<tr><td align='center'>";
    echo "<form method='POST'>";
    echo "<input type='hidden' name='gravatar_options' value='update'>";
    _e('Default gravatar rating', 'gravatars');
    echo ":<br /> <select name='rating'>";
    $ratings = array("G", "PG", "R", "X");
    foreach ($ratings as $r) {
        echo "<option value='{$r}'";
        if ($r == $gravatar_options['gravatar_rating']) {
            echo " selected";
        }
        echo ">{$r}</option>";
    }
    echo "</select></td>\r\n";
    echo "<td align='center'>";
    _e('Default gravatar size', 'gravatars');
    echo ": <br /> <select name='size'>";
    for ($i = 1; $i <= 80; $i++) {
        echo "<option value='{$i}'";
        if ($i == $gravatar_options['gravatar_size']) {
            echo " selected";
        }
        echo ">{$i}</option>";
    }
    echo "</select></td>\r\n";
    echo "<td></td></tr>";
    //echo "<td align='center'>";
    //_e('Border Color', 'gravatars');
    //echo ":<br /> <input type='text' name='gravatar_border' size='10' value='" . $gravatar_options['gravatar_border'] . "' /></td></tr>";
    echo "<tr class='alternate'>";
    echo "<td colspan='3' align='left' class='alternate'>";
    _e('Default gravatar image', 'gravatars');
    echo " (<em>relative to website document root path</em>):<br />";
    echo "<strong>" . $_SERVER['DOCUMENT_ROOT'] . "</strong>";
    echo "<input type='text' name='default' value='" . $gravatar_options['gravatar_default'] . "' size='70' /><br />";
    _e('You may enter: ', 'gravatars');
    echo '<br /><ul><li>';
    _e('a local filename: ', 'gravatars');
    echo '(<code>/images/foo.png</code>)';
    echo ',</li><li>';
    _e('a directory containing a collection of gravatars from which to randomly select: ', 'gravatars');
    echo '(<code>/wp-content/gravatars/random/</code>)</li><li>';
    _e('or a remote URI ', 'gravatars');
    echo '(<code>http://example.com/foo.png</code>)</li></ul>';
    _e('<strong>Please read the documentation for more information about valid options.</strong>', 'gravatars');
    echo '</td></tr>';
    echo "<tr><td align='center'>";
    _e('Cache gravatars', 'gravatars');
    echo '?<br />';
    if (!$CANCACHE) {
        _e('<strong>DISABLED</strong>');
    } else {
        echo "<input type='radio' name='gravatar_cache' value='1'";
        if ('1' == $gravatar_options['gravatar_cache']) {
            echo " checked='checked'";
        }
        echo '>';
        _e('Yes', 'gravatars');
        echo "&nbsp;<input type='radio' name='gravatar_cache' value='0'";
        if ('0' == $gravatar_options['gravatar_cache']) {
            echo " checked='checked'";
        }
        echo ">";
        _e('No', 'gravatars');
        echo "<br />";
        echo "<br />";
        _e('Use REST API', 'gravatars');
        echo '?<br />';
        echo "<input type='radio' name='use_rest' value='1'";
        if ('1' == $gravatar_options['gravatar_use_rest']) {
            echo " checked='checked'";
        }
        echo '>';
        _e('Yes', 'gravatars');
        echo "&nbsp;<input type='radio' name='use_rest' value='0'";
        if ('0' == $gravatar_options['gravatar_use_rest']) {
            echo " checked='checked'";
        }
        echo ">";
        _e('No', 'gravatars');
    }
    echo "</td>";
    if (!$CRONENABLED) {
        echo "<td>&nbsp;</td>";
        echo "<td align='center'>";
        _e('Automatic Cache Checking', 'gravatars');
        echo ":<br /> <input type='radio' name='gravatar_auto_cache_check' value='1'";
        if ('1' == $gravatar_options['gravatar_auto_cache_check']) {
            echo " checked='checked'";
        }
        echo ">";
        _e('Enabled', 'gravatars');
        echo "&nbsp;<input type='radio' name='gravatar_auto_cache_check' value='0'";
        if ('0' == $gravatar_options['gravatar_auto_cache_check']) {
            echo " checked='checked'";
        }
        echo '> ';
        _e('Disabled', 'gravatars');
    } else {
        $gravatar_cron_options = gravatar_cron_options();
        $lastrun = date(DATE_W3C, $gravatar_cron_options['last_run']);
        $refresh_rate = $gravatar_cron_options['refresh_rate'];
        echo "<td align='center'><strong>WP-CRON ENABLED</strong><br />";
        echo "Last Run: {$lastrun} </td>";
        echo "<td align='center'>";
        _e('Cron Refresh Rate (Once Every:)', 'gravatars');
        echo ":<br /> <select name='cron_refresh_rate'>";
        $cron_refresh_rates = gravatar_cron_times();
        $cron_refresh_ratekeys = array_keys($cron_refresh_rates);
        foreach ($cron_refresh_ratekeys as $ratekey) {
            echo "<option value='{$ratekey}'";
            if ($ratekey == $gravatar_cron_options['refresh_rate']) {
                echo " selected";
            }
            echo ">{$cron_refresh_rates[$ratekey]}</option>";
        }
        echo "</select></td>\r\n";
    }
    echo '</td></tr>';
    echo "<tr><td align='center'>";
    _e('Remote Caching Method', 'gravatars');
    echo ":<br /> <select name='rcache_method'>";
    $rcache_methods = gravatar_rcache_methods();
    $rcache_methods_keys = array_keys($rcache_methods);
    foreach ($rcache_methods_keys as $method_key) {
        echo "<option value='{$method_key}'";
        if ($method_key == $gravatar_options['gravatar_rcache_method']) {
            echo " selected";
        }
        echo ">{$rcache_methods[$method_key]}</option>";
    }
    echo "</select></td>\n";
    echo "<td>";
    _e('Remote Info Timeout', 'gravatars');
    echo ":<br /> <input type='text' size='2' name='info_timeout' value='" . $gravatar_options['gravatar_info_timeout'] . "' /> ";
    _e('seconds', 'gravatars');
    echo "</td>\n";
    echo "<td>";
    _e('Remote Copy Timeout', 'gravatars');
    echo ":<br /> <input type='text' size='2' name='copy_timeout' value='" . $gravatar_options['gravatar_copy_timeout'] . "' /> ";
    _e('seconds', 'gravatars');
    echo "</td>\n";
    echo "</tr>";
    echo "<tr><td class='alternate' align='left' colspan='3'>";
    _e('Enter Cache Time (in seconds) for Successful Image cache (positive), No Image Cached (negative), and Failed Cache Attempt (error)', 'gravatars');
    echo "</td></tr>";
    echo "<tr><td class='alternate' align='center'>";
    _e('Cached Image (positive)', 'gravatars');
    echo ":<br /> <input type='text' size='10' name='pos_expire' value='" . $gravatar_options['gravatar_pos_expire_time'] . "' /></td>";
    echo "<td class='alternate' align='center'>";
    _e('No Image (negative)', 'gravatars');
    echo ":<br /> <input type='text' size='10' name='neg_expire' value='" . $gravatar_options['gravatar_neg_expire_time'] . "' /></td>";
    echo "<td class='alternate' align='center'>";
    _e('Failure (error)', 'gravatars');
    echo ":<br /> <input type='text' size='10' name='err_expire' value='" . $gravatar_options['gravatar_err_expire_time'] . "' /></td>";
    echo "</tr>";
    echo "<tr><td align='center'>";
    _e('Allow local gravatars', 'gravatars');
    echo "?<br /> <input type='radio' name='gravatar_allow_local' value='1'";
    if ('1' == $gravatar_options['gravatar_allow_local']) {
        echo " checked='checked'";
    }
    echo ">";
    _e('Yes', 'gravatars');
    echo "&nbsp;<input type='radio' name='gravatar_allow_local' value='0'";
    if ('0' == $gravatar_options['gravatar_allow_local']) {
        echo " checked='checked'";
    }
    echo '> ';
    _e('No', 'gravatars');
    echo '</td>';
    echo "<td align='center'>";
    _e('Local Grav ', 'gravatars');
    echo "<a href='http://codex.wordpress.org/User_Levels' target='_blank'>";
    _e('User Level', 'gravatars');
    echo "</a>";
    echo ": <br /> <select name='local_ulevel'>";
    for ($i = 0; $i <= 10; $i++) {
        echo "<option value='{$i}'";
        if ($i == $gravatar_options['gravatar_local_ulevel']) {
            echo " selected";
        }
        echo ">{$i}</option>";
    }
    echo "</select></td>\r\n";
    echo "<td align='center'>";
    _e('Replace <code>&lt;gravatar foo@bar.com&gt;</code> in posts', 'gravatars');
    echo "<br />";
    echo "? <input type='radio' name='gravatar_in_posts' value='1'";
    if ('1' == $gravatar_options['gravatar_in_posts']) {
        echo " checked='checked'";
    }
    echo '>';
    _e('Yes', 'gravatars');
    echo " &nbsp;<input type='radio' name='gravatar_in_posts' value='0'";
    if ('0' == $gravatar_options['gravatar_in_posts']) {
        echo " checked='checked'";
    }
    echo '> ';
    _e('No', 'gravatars');
    echo '</td></tr>';
    echo "<tr'><td align='left' colspan='2'><input type='submit' name='submit' value='" . __('Submit', 'gravatars') . "'</td>\r\n";
    echo "<td align='right'><input type='submit' name='reset' value='RESET'></td></tr>\r\n";
    echo "</table></form>\r\n";
    echo "</fieldset>\r\n";
    echo "<div style='width: 100%; text-align: center;'>" . gravatar_version("html") . "</div>";
    echo "</div>";
    include ABSPATH . 'wp-admin/admin-footer.php';
    // just to be sure
    die;
}