/** * Updates the Authors list executing a Twitter search for the parameters * configured */ public function updateAuthors() { $results = Tweester_Twitter::getMaxSearchResults($this->coreManager->getSettingsManager()->getOption('query')->getValue(), 15); //Get list of excludes $excludes = $this->coreManager->getSettingsManager()->getOption('excludes')->getValue(); $excludedArray = explode(',', $excludes); $excludedArray = array_map('trim', $excludedArray); if ($results != false) { //Process, store supporters foreach ($results as $tweet) { //Get Username $username = $tweet->from_user; //Skip if in excluded if (in_array($username, $excludedArray)) { continue; } //Check if already in base $data = $this->coreManager->getDbManager()->get_row("SELECT * FROM " . $this->coreManager->getDbManager()->getTableNameFor('authors') . " WHERE twitter = '" . $username . "'"); //Add to base if not if ($data == null) { $this->coreManager->getDbManager()->insert($this->coreManager->getDbManager()->getTableNameFor('authors'), array('twitter' => $username, 'added_on' => date('Y-m-d H:i:s')), array('%s', '%s')); } } } //Update execution time $this->coreManager->getSettingsManager()->getOption('cron_run_time')->setValue(time()); }
public function getMaxSearchResults($query, $maxPages = 15) { $p = 1; $results = array(); while ($p < $maxPages) { $pResults = Tweester_Twitter::getSearchResults($query, $p); $results = array_merge($results, $pResults); $p++; } return $results; }
/** * Retrieves User Data. * * Thie method first checks the local cache database and if needed calls * twitter for more information * * @param string $username * @return stdClass */ private function getUserData($username) { $reCacheCutoff = new DateTime(); $reCacheCutoff->modify("-15 days"); //Check cache $data = $this->dbManager->get_row("SELECT *, DATE_FORMAT(cached_on, '%Y%m%d%h%i%s') AS cacheint FROM " . $this->dbManager->getTableNameFor('user_data_cache') . " WHERE twitter = '" . $username . "'"); if ($data === null || $data->cacheint < $reCacheCutoff->format('YmdHis')) { //Get From Twitter $twData = Tweester_Twitter::getUserData($username); //Clear previous cache $this->dbManager->query("DELETE FROM " . $this->coreManager->getDbManager()->getTableNameFor('user_data_cache') . " WHERE twitter = '" . $username . "'"); //Cache $this->dbManager->insert($this->dbManager->getTableNameFor('user_data_cache'), array('twitter' => $username, 'data' => json_encode($twData), 'cached_on' => date('Y-m-d H:i:s')), array('%s', '%s', '%s')); $userData = $twData; } else { $userData = json_decode($data->data); } return $userData; }