Example #1
0
function spyropress_twitter_tweets()
{
    $defaults = array('lang' => substr(strtoupper(get_locale()), 0, 2), 'post_count' => isset($_GET['notweets']) ? $_GET['notweets'] : 10, 'username' => isset($_GET['twitteruser']) ? $_GET['twitteruser'] : get_setting('twitter_username'), 'key' => '_spyropress_footer_tweets_', 'consumer_key' => get_setting('twitter_consumer_key'), 'consumer_secret' => get_setting('twitter_consumer_secret'), 'access_token' => get_setting('twitter_access_token'), 'access_token_secret' => get_setting('twitter_access_token_secret'));
    extract($defaults);
    if (!$consumer_key || !$consumer_secret || !$access_token || !$access_token_secret) {
        _e('No oAuth setting provided.', 'spyropress');
        exit;
    }
    $tweets = array();
    if (false === ($tweets = get_transient($key . $username))) {
        require_once 'utilities/twitteroauth/twitteroauth.php';
        $twitterConnection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
        $tweets = $twitterConnection->get('statuses/user_timeline', array('screen_name' => $username, 'count' => $post_count));
        if ($twitterConnection->http_code != 200) {
            $tweets = get_transient($key . $username);
        }
        // Cache
        set_transient($key . $username, $tweets, spyropress_get_seconds(0.1));
    }
    echo json_encode($tweets);
    exit;
}
Example #2
0
/**
 * Pluralize String
 */
function spyropress_pluralize($str)
{
    // Key
    $key = '_spyropress_pluralize_' . $str;
    // Getting from cache
    if ($plural = get_transient($key)) {
        return $plural;
    }
    $plural_patterns = array('/(s)tatus$/i' => '\\1\\2tatuses', '/(quiz)$/i' => '\\1zes', '/^(ox)$/i' => '\\1\\2en', '/([m|l])ouse$/i' => '\\1ice', '/(matr|vert|ind)(ix|ex)$/i' => '\\1ices', '/(x|ch|ss|sh)$/i' => '\\1es', '/([^aeiouy]|qu)y$/i' => '\\1ies', '/(hive)$/i' => '\\1s', '/(?:([^f])fe|([lr])f)$/i' => '\\1\\2ves', '/sis$/i' => 'ses', '/([ti])um$/i' => '\\1a', '/(p)erson$/i' => '\\1eople', '/(m)an$/i' => '\\1en', '/(c)hild$/i' => '\\1hildren', '/(buffal|tomat)o$/i' => '\\1\\2oes', '/(alumn|bacill|cact|foc|fung|nucle|radi|stimul|octop|syllab|termin|vir)us$/i' => '\\1i', '/us$/i' => 'uses', '/(alias)$/i' => '\\1es', '/(ax|cris|test)is$/i' => '\\1es', '/s$/' => 's', '/^$/' => '', '/$/' => 's');
    $irregular = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers', 'cafe' => 'cafes', 'child' => 'children', 'cookie' => 'cookies', 'corpus' => 'corpuses', 'cow' => 'cows', 'ganglion' => 'ganglions', 'genie' => 'genies', 'genus' => 'genera', 'graffito' => 'graffiti', 'hoof' => 'hoofs', 'loaf' => 'loaves', 'man' => 'men', 'money' => 'monies', 'mongoose' => 'mongooses', 'move' => 'moves', 'mythos' => 'mythoi', 'niche' => 'niches', 'numen' => 'numina', 'occiput' => 'occiputs', 'octopus' => 'octopuses', 'opus' => 'opuses', 'ox' => 'oxen', 'penis' => 'penises', 'person' => 'people', 'sex' => 'sexes', 'soliloquy' => 'soliloquies', 'testis' => 'testes', 'trilby' => 'trilbys', 'turf' => 'turfs');
    $uncountable = array('equipment', 'fish', 'information', 'money', 'rice', 'series', 'sheep', 'species');
    $plural = '';
    $lowercase_str = strtolower($str);
    // save some time in the case that singular and plural are the same
    if (in_array($lowercase_str, $uncountable)) {
        $plural = $str;
    }
    // check for irregular singular forms
    if (array_key_exists($lowercase_str, $irregular)) {
        $plural = $irregular[$lowercase_str];
    }
    // check for matches using regular expressions
    foreach ($plural_patterns as $pattern => $replace) {
        if (preg_match($pattern, $str)) {
            $plural = preg_replace($pattern, $replace, $str);
            break;
        }
    }
    // save to cache
    set_transient($key, $plural, spyropress_get_seconds(10));
    return $plural;
}
Example #3
0
 function api_get($action = '', $url_part = '', $query = array(), $args = array(), $cache = true, $expires = 1)
 {
     // Cache key
     $key = '_spyropress_api_' . $action;
     // Return from Cache
     if ($cache && ($response = get_transient($key))) {
         return $response;
     }
     // Generating URL
     $query['action'] = $action;
     $query = http_build_query($query);
     $url = $this->url . $url_part . '?' . $query;
     $response = wp_remote_get($url, $args);
     $response = wp_remote_retrieve_body($response);
     // Save into Cache
     if ($cache && !empty($response)) {
         set_transient($key, $response, spyropress_get_seconds($expires));
     }
     return $response;
 }
function spyropress_set_post_views_cookies()
{
    // only run on posts and not pages
    if (!isset($_COOKIE['spyropress_post_view_done']) && is_single() && !is_page()) {
        setcookie('spyropress_post_view_done', get_the_ID(), time() + spyropress_get_seconds(1));
    }
}