0) { $current['cacheLength'] = (int)$data['cacheLength']; } if (isset($data['tweetCount']) && (int)$data['tweetCount'] > 0) { $current['tweetCount'] = (int)$data['tweetCount']; } if ($current['useCache'] == 'on') { $current['useCache'] = true; } if ($current['newWindow'] == 'on') { $current['newWindow'] == true; } if (isset($data['defaultAccount'])) { $current['defaultAccount'] = trim($data['defaultAccount']); } if (isset($data['htmlBefore'])) { $current['htmlBefore'] = trim($data['htmlBefore']); } if (isset($data['htmlAfter'])) { $current['htmlAfter'] = trim($data['htmlAfter']); } /* Check for the checkbox values. We'll assume that if tweetCount * and defaultAccount are set in $data then it's coming from * the options page admin-side and the checkbox values need to * be updated. */ if (isset($data['defaultAccount']) && isset($data['tweetCount'])) { $current['useCache'] = (bool)$data['useCache']; $current['newWindow'] = (bool)$data['newWindow']; $current['loadCSS'] = (bool)$data['loadCSS']; if (isset($_POST['rtwit-clear-cache']) && $_POST['rtwit-clear-cache']==1) { $current['cache'] = array(); } } return $current; } /** * Callback to handle the short codes. * * This function is pretty much a cleanup. The actual output is handed off to * rtwit_get_code. */ function rtwit_shortcode_handler($atts, $content=null, $code = '') { /* Get the default options. We'll overridge them if the appropriate * tags are available in $atts */ $opts = get_option('rtwit_options'); $opts['account'] = strtolower((isset($atts['account'])) ? $atts['account'] : $opts['defaultAccount']); $opts['useCache'] = (isset($atts['cache'])) ? (bool)$atts['cache']: $opts['useCache']; $opts['tweetCount'] = (isset($atts['count']) && (int)$atts['count'] > 0) ? (int)$atts['count'] : $opts['tweetCount']; $opts['cacheLength'] = (isset($atts['cache_length']) && (int)$atts['cache_length'] > 0) ? (int)$atts['cache_length'] : $opts['cacheLength']; $opts['newWindow'] = (isset($atts['new_window'])) ? (bool)$atts['new_window'] : $opts['newWindow']; $opts['htmlBefore'] = (isset($atts['html_before'])) ? $atts['html_before'] : $opts['htmlBefore']; $opts['htmlAfter'] = (isset($atts['html_after'])) ? $atts['html_after'] : $opts['htmlAfter']; // We need to clean up a few things $opts['account'] = trim($opts['account']); $opts['account'] = preg_replace('/^@/', '', $opts['account']); /* If there still isn't an account available we'll just return * a message as an HTML comment so nothing shows on the screen * but the owner can still see what's going on. */ if ($opts['account'] == '') { return "\n"; } return rtwit_get_code($opts); } function rtwit_add_css($posts) { $opts = get_option('rtwit_options'); if ($opts['loadCSS']) { if (empty($posts)) { return $posts; } $found = false; foreach ($posts as $post) { //var_dump($post->post_content); echo "\n"; if (stripos($post->post_content, '[rtwit') !== false) { $found = true; break; } } if ($found) { wp_register_style('rtwit-css', plugins_url('rTwit.css', __FILE__)); wp_enqueue_style('rtwit-css'); } } return $posts; } /** * Build and return the code needed to display the plugin * * Calls itself recursively with $useCache=false if the cache is on but * has expired. */ function rtwit_get_code($opts, $cache=true) { if ($opts['useCache'] == false || !$cache) { $url = 'http://twitter.com/statuses/user_timeline.json?screen_name=' . $opts['account'] . '&count=' . $opts['tweetCount']; if (!class_exists('WP_Http')) { include_once(ABSPATH . WPINC . '/class-http.php'); } $req = new WP_Http; $result = $req->request($url); if (!isset($result['response']['code']) || $result['response']['code'] != 200) { $cacheData = ''; } else { $json = json_decode($result['body'], true); if (!$json || !is_array($json)) { $cacheData = ''; } else if (count($json) < 1) { $cacheData = ''; } else { $cacheData = ''; if ($opts['htmlBefore']) { $cacheData .= $opts['htmlBefore']; } $cacheData .= '