<?php /** * Xoops Functions * * You may not change or alter any portion of this comment or credits * of supporting developers from this source code or any supporting source code * which is considered copyrighted (c) material of the original comment or credit authors. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ * @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) * @package crons * @since 2.5.7 * @version $Id: cron-twits.php XXXXX XXXX-XX-XX XX:XX:XXZ xxxxxx $ */ error_reporting(E_ERROR); set_time_limit(2999); ini_set('display_errors', 1); ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . "errors.txt"); require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "TwitterAPIExchange.php"); /** * Gets a response from a URL with cURL or wGET * @param string $url * @param array $params * @param string $context * @param array $header * @param string $method * @return string|mixed|boolean */ function getURL($url, $params, $context = '', $header = array(), $method = 'GET') { if (!function_exists('curl_init')||$method=='FGC') { $url .= '?'.http_build_query($params); $data = file_get_contents( $url, 0, $context ); return $data; } else { if ($ch = curl_init()) { if (!is_array($header)) $header = explode("n", str_replace("r", "", $header)); if (count($header)>0) curl_setopt($ch,CURLOPT_HTTPHEADER, $header); switch($method) { default: case 'GET': $url .= '?'.http_build_query($params); break; case 'POST': curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); } curl_setopt($ch, CURLOPT_URL, $url); //curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Chronolabs Translation API 1.02 - PHP Version ' . PHP_VERSION.''); $data = curl_exec($ch); curl_close($ch); return $data; } } return false; } error_reporting(E_ERROR); $settings['twitter']['Cipherocity'] = array( 'oauth_access_token' => "----------------------------------------------------", 'oauth_access_token_secret' => ""----------------------------------------------------", 'consumer_key' => ""----------------------------------------------------", 'consumer_secret' => ""----------------------------------------------------" ); define("_REPLY", "@%s topic similar %s this article %s entitled: '%s'"); mt_srand(mt_rand(-microtime(true), microtime(true))); mt_srand(mt_rand(-microtime(true), microtime(true))); mt_srand(mt_rand(-microtime(true), microtime(true))); mt_srand(mt_rand(-microtime(true), microtime(true))); error_reporting(E_ERROR); include_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "web" . DIRECTORY_SEPARATOR . "public_html" . DIRECTORY_SEPARATOR . "mainfile.php"; if (isset($GLOBALS['xoops'])) include_once $GLOBALS['xoops']->path("/class/cache/xoopscache.php"); ini_set('display_errors', 1); ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . "errors.txt"); error_reporting(E_ERROR); foreach ($settings['twitter'] as $key => $setting) { $tweets = array(); foreach(file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'retweet.diz') as $id => $line) { $parts = explode("|", $line); $range = explode("-", $parts[1]); $searchfor[$id][$parts[0]] = mt_rand($range[0], $range[1]); } foreach($searchfor as $term => $count) { if (defined('XOOPS_ROOT_PATH')) if (!$results = XoopsCache:: read('tweetercron_'.str_replace(' ', '_', strtolower($term)))) { $results = array('since_id'=>0); } else $results = array('since_id'=>0); $url = 'https://api.twitter.com/1.1/search/tweets.json'; $getfield = '?q='.urlencode($term).'&'.($result['since_id']!=0?'since_id='.$result['since_id'].'&':'').'result_type=mixed&count='.$count; $postfields = array(); $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($setting); $tweets[] = array_merge(json_decode($twitter ->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(), true), array('count' => $count)); } foreach($tweets as $keyb => $tweet) { if ($tweet['user']['screen_name'] != $key) { if (is_array($tweet)&&!empty($tweet)) { $count = $tweet['count']; $keys = array_keys($tweet); while(count($tweet)>$count) { $key = $keys[mt_rand(0, count($keys)-1)]; unset($tweet[$key]); unset($keys[$key]); } foreach($tweet as $key => $values) { if ($values['user']['screen_name'] != $key) { switch ($key) { case 'statuses': foreach($values as $keyb => $valuesb) { $url = 'https://api.twitter.com/1.1/statuses/retweet/'.$valuesb['id_str'].'.json'; $requestMethod = 'POST'; $postfields = array(); $twitter = new TwitterAPIExchange($setting); $retweets[] = json_decode($twitter ->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest(), true); echo "Retweeted: " . ($last = $valuesb['id_str']) . " :: " . $valuesb['text'] . "</br>"; } if (defined('XOOPS_ROOT_PATH') && class_exists("XoopsCache")) XoopsCache::write('tweetercron_'.str_replace(' ', '_', strtolower($term)), array('since_id'=>$last)); break; case 'search_metadata': if (defined('XOOPS_ROOT_PATH') && class_exists("XoopsCache")) XoopsCache::write('tweetercron_'.str_replace(' ', '_', strtolower($term)), array('since_id'=>$values['since_id'])); break; } } } } } } $tweets = array(); $searchfor = array(); $resulters = array(); foreach(file(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'replies.diz') as $id => $line) { $parts = explode("|", $line); $range = explode("-", $parts[2]); foreach(json_decode(getURL($parts[1]), true) as $term => $data) $searchfor[$term][mt_rand($range[0], $range[1])] = array_merge($data, array("suffix" => $parts[0])); } foreach($searchfor as $tterm => $resource) { $skip = false; foreach($resource as $count => $data) { if ($skip != true) { foreach($data as $identy => $termset) { if ($skip != true) { $secondary = $termidor = array_merge(explode(" ", $termset["title"]), $termset['plus']); shuffle($termidor); shuffle($termidor); shuffle($termidor); shuffle($termidor); shuffle($termidor); shuffle($secondary); shuffle($secondary); shuffle($secondary); shuffle($secondary); shuffle($secondary); foreach($termidor as $tteerm) { foreach($secondary as $stteerm) { if ($skip != true && $stteerm != $tteerm) { $resulters[$term = $tterm . " " . $tteerm . " " . $stteerm] = array('title' => $termset['title'], 'url' => $termset['url'], 'count' => $count); if (defined('XOOPS_ROOT_PATH')) if (!$results = XoopsCache:: read('twitscron_'.str_replace(' ', '_', strtolower($term)))) { $results = array('since_id'=>0); } else $results = array('since_id'=>0); $url = 'https://api.twitter.com/1.1/search/tweets.json'; $getfield = '?q='.urlencode($term).'&'.($result['since_id']!=0?'since_id='.$result['since_id'].'&':'').'result_type=mixed&count='.$count; $postfields = array(); $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($setting); $rrt = $rrt + count($tweets[$term][$termset['suffix']][] = json_decode($twitter ->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(), true)); if ($rrt >= $count) $skip = true; } } } } } } } } $keys = array_keys($resulters); shuffle($keys); shuffle($keys); shuffle($keys); shuffle($keys); shuffle($keys); foreach($keys as $term) { foreach($tweets[$term] as $suffix => $twits) { foreach($twits as $keyb => $tweet) { if ($tweet['user']['screen_name'] != $key) { if (is_array($tweet)&&!empty($tweet)) { $number = 0; $count = $resulters[$term]['count']; $keys = array_keys($tweet); while(count($tweet)>$count) { $key = $keys[mt_rand(0, count($keys)-1)]; unset($tweet[$key]); unset($keys[$key]); } if (!count($tweet['errors'])) { foreach($tweet as $key => $values) { if ($values['user']['screen_name'] != $key) { switch ($key) { case 'statuses': foreach($values as $keyb => $valuesb) { $geoRand = json_decode(getURL("http://places.labs.coop/v1/random/random/json.api"), true); $url = 'https://api.twitter.com/1.1/statuses/update.json'; $requestMethod = 'POST'; $res = sprintf(_REPLY, $valuesb['user']['screen_name'], $suffix, $resulters[$term]['url'], $resulters[$term]['title']); $postfields = array('status' => $res, 'in_reply_to_status_id' => $valuesb['id_str'], 'possibly_sensitive' => 'true', 'lat' => (float)$geoRand['place']["Latitude_Float"], 'long' => (float)$geoRand['place']["Longitude_Float"], 'display_coordinates' => 'true'); $twitter = new TwitterAPIExchange($setting); $retweets[] = json_decode($twitter ->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest(), true); echo "Reply: " . ($last = $valuesb['id_str']) . " :: " . $res . "</br>"; $number++; } if (defined('XOOPS_ROOT_PATH') && class_exists("XoopsCache")) XoopsCache::write('twitscron_'.str_replace(' ', '_', strtolower($term)), array('since_id'=>$last)); break; case 'search_metadata': if (defined('XOOPS_ROOT_PATH') && class_exists("XoopsCache")) XoopsCache::write('twitscron_'.str_replace(' ', '_', strtolower($term)), array('since_id'=>$values['since_id'])); break; } } } } } } } } } $url = 'https://api.twitter.com/1.1/followers/ids.json'; $getfield = 'cursor=-1&screen_name='.$key.'&count=5000'; $requestMethod = 'GET'; $postfields = array(); $twitter = new TwitterAPIExchange($setting); $friends = $twitter ->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); if (isset($friends['ids'])) { foreach($friends['ids'] as $id) { $url = 'https://api.twitter.com/1.1/friendships/create.json '; $requestMethod = 'POST'; $postfields = array('user_id'=>$id, 'follow'=>true); $twitter = new TwitterAPIExchange($setting); $friends = $twitter ->buildOauth($url, $requestMethod) ->setPostfields($postfields) ->performRequest(); } } } ?>