/** * * function called by scripts (eg:a cron job or scheduled task) to upate the Tweets. */ function perch_twitter_update_tweets() { $found = 0; $API = new PerchAPI(1.0, 'perch_twitter'); PerchUtil::debug('Updating'); $TwitterSettings = new PerchTwitter_Settings($API); $CurrentSettings = $TwitterSettings->find(); if (is_object($CurrentSettings)) { $details = $CurrentSettings->to_array(); $Twitter = new PerchTwitter(); //update tweets $twitter_id_str = $details['settingTwitterID']; $twitter_id_array = explode(',', $twitter_id_str); for ($i = 0; $i < sizeOf($twitter_id_array); $i++) { $twitter_id = trim($twitter_id_array[$i]); $found += $Twitter->get_tweets('favorites', $twitter_id); $found += $Twitter->get_tweets('mine', $twitter_id); } } return $found; }
<?php require '../tmhOAuth/tmhOAuth.php'; require '../tmhOAuth/tmhUtilities.php'; $HTML = $API->get('HTML'); $Form = $API->get('Form'); $TwitterSettings = new PerchTwitter_Settings($API); $message = false; $CurrentSettings = $TwitterSettings->find(); if (!is_object($CurrentSettings)) { $TwitterSettings->attempt_install(); $CurrentSettings = $TwitterSettings->find(); } if (is_object($CurrentSettings) && $CurrentSettings->settingTwitterKey()) { $tmhOAuth = new tmhOAuth(array('consumer_key' => $CurrentSettings->settingTwitterKey(), 'consumer_secret' => $CurrentSettings->settingTwitterSecret())); if (isset($_REQUEST['oauth_verifier'])) { access_token($tmhOAuth); } elseif (isset($_REQUEST['verify'])) { verify_credentials($tmhOAuth); } elseif (isset($_REQUEST['wipe'])) { wipe(); } } else { $tmhOAuth = false; } if (isset($_SESSION['access_token'])) { $data = array(); $data['settingTwitterToken'] = $_SESSION['access_token']['oauth_token']; $data['settingTwitterTokenSecret'] = $_SESSION['access_token']['oauth_token_secret']; $CurrentSettings->update($data); //print_r($_SESSION);
public function post_scheduled_tweets() { if (!class_exists('tmhOAuth')) { require 'tmhOAuth/tmhOAuth.php'; require 'tmhOAuth/tmhUtilities.php'; } $Tweets = new PerchTwitter_Tweets(); $tweets = $Tweets->get_scheduled_tweets(); $sent = 0; if (PerchUtil::count($tweets)) { $TwitterSettings = new PerchTwitter_Settings(); $CurrentSettings = $TwitterSettings->find(); $tmhOAuth = new tmhOAuth(array('consumer_key' => $CurrentSettings->settingTwitterKey(), 'consumer_secret' => $CurrentSettings->settingTwitterSecret(), 'user_token' => $CurrentSettings->settingTwitterToken(), 'user_secret' => $CurrentSettings->settingTwitterTokenSecret())); foreach ($tweets as $tweet) { $code = $tmhOAuth->request('POST', $tmhOAuth->url('1.1/statuses/update.json'), array('status' => $tweet['tweetStatus'])); if ($code == 200) { $sent++; $Tweets->mark_scheduled_as_sent($tweet['tweetID']); } else { PerchUtil::debug(PerchUtil::json_safe_decode($tmhOAuth->response['response'])); } } } return $sent; }
/** * Get the individual status using the ID * * @param string $statusID A Twitter Status ID * @return array Assoc array of status details * @author Rachel Andrew */ private function get_status($statusID) { if (!class_exists('tmhOAuth')) { require PERCH_PATH . '/addons/apps/perch_twitter/tmhOAuth/tmhOAuth.php'; require PERCH_PATH . '/addons/apps/perch_twitter/tmhOAuth/tmhUtilities.php'; } if (!class_exists('TwitterSettings')) { require PERCH_PATH . '/addons/apps/perch_twitter/PerchTwitter_Settings.class.php'; require PERCH_PATH . '/addons/apps/perch_twitter/PerchTwitter_Setting.class.php'; } $TwitterSettings = new PerchTwitter_Settings(); $CurrentSettings = $TwitterSettings->find(); $tmhOAuth = new tmhOAuth(array('consumer_key' => $CurrentSettings->settingTwitterKey(), 'consumer_secret' => $CurrentSettings->settingTwitterSecret(), 'user_token' => $CurrentSettings->settingTwitterToken(), 'user_secret' => $CurrentSettings->settingTwitterTokenSecret())); $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/show.json'), array('id' => $statusID)); if ($code == 200) { $tweet = PerchUtil::json_safe_decode($tmhOAuth->response['response']); return $tweet; } return false; }
<?php $API = new PerchAPI(1.0, 'perch_twitter'); if (!class_exists('PerchTwitter_Settings')) { include 'PerchTwitter_Settings.class.php'; include 'PerchTwitter_Setting.class.php'; } $TwitterSettings = new PerchTwitter_Settings($API); $CurrentSettings = $TwitterSettings->find(); PerchScheduledTasks::register_task('perch_twitter', 'post_tweets', 1, 'scheduled_post_tweets'); if ((int) $CurrentSettings->settingUpdateInterval() != 0) { $interval = (int) $CurrentSettings->settingUpdateInterval(); PerchScheduledTasks::register_task('perch_twitter', 'update_tweets', $interval, 'scheduled_get_tweets'); } function scheduled_get_tweets($last_run) { $count = perch_twitter_update_tweets(); if ($count == 1) { $tweets = 'tweet'; } else { $tweets = 'tweets'; } return array('result' => 'OK', 'message' => $count . ' new ' . $tweets . ' fetched.'); } function scheduled_post_tweets($last_run) { $count = perch_twitter_post_tweets(); if ($count == 1) { $tweets = 'tweet'; } else { $tweets = 'tweets';