function twitter_fetchhometimeline($a, $uid) { $ckey = get_config('twitter', 'consumerkey'); $csecret = get_config('twitter', 'consumersecret'); $otoken = get_pconfig($uid, 'twitter', 'oauthtoken'); $osecret = get_pconfig($uid, 'twitter', 'oauthsecret'); $create_user = get_pconfig($uid, 'twitter', 'create_user'); $mirror_posts = get_pconfig($uid, 'twitter', 'mirror_posts'); logger("twitter_fetchhometimeline: Fetching for user " . $uid, LOGGER_DEBUG); $application_name = get_config('twitter', 'application_name'); if ($application_name == "") { $application_name = $a->get_hostname(); } require_once 'library/twitteroauth.php'; require_once 'include/items.php'; $connection = new TwitterOAuth($ckey, $csecret, $otoken, $osecret); $own_contact = twitter_fetch_own_contact($a, $uid); $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($own_contact), intval($uid)); if (count($r)) { $own_id = $r[0]["nick"]; } else { logger("twitter_fetchhometimeline: Own twitter contact not found for user " . $uid, LOGGER_DEBUG); return; } $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); if (count($r)) { $self = $r[0]; } else { logger("twitter_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); return; } $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); if (!count($u)) { logger("twitter_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } $parameters = array("exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true); //$parameters["count"] = 200; // Fetching timeline $lastid = get_pconfig($uid, 'twitter', 'lasthometimelineid'); $first_time = $lastid == ""; if ($lastid != "") { $parameters["since_id"] = $lastid; } $items = $connection->get('statuses/home_timeline', $parameters); if (!is_array($items)) { logger("twitter_fetchhometimeline: Error fetching home timeline: " . print_r($items, true), LOGGER_DEBUG); return; } $posts = array_reverse($items); logger("twitter_fetchhometimeline: Fetching timeline for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); if (count($posts)) { foreach ($posts as $post) { if ($post->id_str > $lastid) { $lastid = $post->id_str; set_pconfig($uid, 'twitter', 'lasthometimelineid', $lastid); } if ($first_time) { continue; } if (stristr($post->source, $application_name) && $post->user->screen_name == $own_id) { logger("twitter_fetchhometimeline: Skip previously sended post", LOGGER_DEBUG); continue; } if ($mirror_posts && $post->user->screen_name == $own_id && $post->in_reply_to_status_id_str == "") { logger("twitter_fetchhometimeline: Skip post that will be mirrored", LOGGER_DEBUG); continue; } if ($post->in_reply_to_status_id_str != "") { twitter_fetchparentposts($a, $uid, $post, $connection, $self, $own_id); } $postarray = twitter_createpost($a, $uid, $post, $self, $create_user, true); if (trim($postarray['body']) == "") { continue; } $item = item_store($postarray); $postarray["id"] = $item; logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); if ($item and !function_exists("check_item_notification")) { twitter_checknotification($a, $uid, $own_id, $item, $postarray); } } } set_pconfig($uid, 'twitter', 'lasthometimelineid', $lastid); // Fetching mentions $lastid = get_pconfig($uid, 'twitter', 'lastmentionid'); $first_time = $lastid == ""; if ($lastid != "") { $parameters["since_id"] = $lastid; } $items = $connection->get('statuses/mentions_timeline', $parameters); if (!is_array($items)) { logger("twitter_fetchhometimeline: Error fetching mentions: " . print_r($items, true), LOGGER_DEBUG); return; } $posts = array_reverse($items); logger("twitter_fetchhometimeline: Fetching mentions for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); if (count($posts)) { foreach ($posts as $post) { if ($post->id_str > $lastid) { $lastid = $post->id_str; } if ($first_time) { continue; } if ($post->in_reply_to_status_id_str != "") { twitter_fetchparentposts($a, $uid, $post, $connection, $self, $own_id); } $postarray = twitter_createpost($a, $uid, $post, $self, false, false); if (trim($postarray['body']) == "") { continue; } $item = item_store($postarray); $postarray["id"] = $item; if ($item and function_exists("check_item_notification")) { check_item_notification($item, $uid, NOTIFY_TAGSELF); } if (!isset($postarray["parent"]) or $postarray["parent"] == 0) { $postarray["parent"] = $item; } logger('twitter_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item); if ($item == 0) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), intval($uid)); if (count($r)) { $item = $r[0]['id']; $parent_id = $r[0]['parent']; } } else { $parent_id = $postarray['parent']; } if ($item != 0 and !function_exists("check_item_notification")) { require_once 'include/enotify.php'; notification(array('type' => NOTIFY_TAGSELF, 'notify_flags' => $u[0]['notify-flags'], 'language' => $u[0]['language'], 'to_name' => $u[0]['username'], 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], 'item' => $postarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $parent_id)); } } } set_pconfig($uid, 'twitter', 'lastmentionid', $lastid); }
function appnet_fetchstream($a, $uid) { require_once "addon/appnet/AppDotNet.php"; require_once 'include/items.php'; $token = get_pconfig($uid, 'appnet', 'token'); $clientId = get_pconfig($uid, 'appnet', 'clientid'); $clientSecret = get_pconfig($uid, 'appnet', 'clientsecret'); $app = new AppDotNet($clientId, $clientSecret); $app->setAccessToken($token); $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); if (count($r)) { $me = $r[0]; } else { logger("appnet_fetchstream: Own contact not found for user " . $uid, LOGGER_DEBUG); return; } $user = q("SELECT * FROM `user` WHERE `uid` = %d AND `account_expired` = 0 LIMIT 1", intval($uid)); if (count($user)) { $user = $user[0]; } else { logger("appnet_fetchstream: Own user not found for user " . $uid, LOGGER_DEBUG); return; } $ownid = get_pconfig($uid, 'appnet', 'ownid'); // Fetch stream $param = array("count" => 200, "include_deleted" => false, "include_directed_posts" => true, "include_html" => false, "include_post_annotations" => true); $lastid = get_pconfig($uid, 'appnet', 'laststreamid'); if ($lastid != "") { $param["since_id"] = $lastid; } try { $stream = $app->getUserStream($param); } catch (AppDotNetException $e) { logger("appnet_fetchstream: Error fetching stream for user " . $uid . " " . appnet_error($e->getMessage())); return; } if (!is_array($stream)) { $stream = array(); } $stream = array_reverse($stream); foreach ($stream as $post) { $postarray = appnet_createpost($a, $uid, $post, $me, $user, $ownid, true); $item = item_store($postarray); $postarray["id"] = $item; logger('appnet_fetchstream: User ' . $uid . ' posted stream item ' . $item); $lastid = $post["id"]; if ($item != 0 and $postarray['contact-id'] != $me["id"] and !function_exists("check_item_notification")) { $r = q("SELECT `thread`.`iid` AS `parent` FROM `thread`\n\t\t\t\tINNER JOIN `item` ON `thread`.`iid` = `item`.`parent` AND `thread`.`uid` = `item`.`uid`\n\t\t\t\tWHERE `item`.`id` = %d AND `thread`.`mention` LIMIT 1", dbesc($item)); if (count($r)) { require_once 'include/enotify.php'; notification(array('type' => NOTIFY_COMMENT, 'notify_flags' => $user['notify-flags'], 'language' => $user['language'], 'to_name' => $user['username'], 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $postarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_POST, 'otype' => 'item', 'parent' => $r[0]["parent"])); } } } set_pconfig($uid, 'appnet', 'laststreamid', $lastid); // Fetch mentions $param = array("count" => 200, "include_deleted" => false, "include_directed_posts" => true, "include_html" => false, "include_post_annotations" => true); $lastid = get_pconfig($uid, 'appnet', 'lastmentionid'); if ($lastid != "") { $param["since_id"] = $lastid; } try { $mentions = $app->getUserMentions("me", $param); } catch (AppDotNetException $e) { logger("appnet_fetchstream: Error fetching mentions for user " . $uid . " " . appnet_error($e->getMessage())); return; } if (!is_array($mentions)) { $mentions = array(); } $mentions = array_reverse($mentions); foreach ($mentions as $post) { $postarray = appnet_createpost($a, $uid, $post, $me, $user, $ownid, false); if (isset($postarray["id"])) { $item = $postarray["id"]; $parent_id = $postarray['parent']; } elseif (isset($postarray["body"])) { $item = item_store($postarray); $postarray["id"] = $item; $parent_id = 0; logger('appnet_fetchstream: User ' . $uid . ' posted mention item ' . $item); if ($item and function_exists("check_item_notification")) { check_item_notification($item, $uid, NOTIFY_TAGSELF); } } else { $item = 0; $parent_id = 0; } // Fetch the parent and id if ($parent_id == 0 and $postarray['uri'] != "") { $r = q("SELECT `id`, `parent` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), intval($uid)); if (count($r)) { $item = $r[0]['id']; $parent_id = $r[0]['parent']; } } $lastid = $post["id"]; //if (($item != 0) AND ($postarray['contact-id'] != $me["id"])) { if ($item != 0 and !function_exists("check_item_notification")) { require_once 'include/enotify.php'; notification(array('type' => NOTIFY_TAGSELF, 'notify_flags' => $user['notify-flags'], 'language' => $user['language'], 'to_name' => $user['username'], 'to_email' => $user['email'], 'uid' => $user['uid'], 'item' => $postarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $parent_id)); } } set_pconfig($uid, 'appnet', 'lastmentionid', $lastid); /* To-Do $param = array("interaction_actions" => "star"); $interactions = $app->getMyInteractions($param); foreach ($interactions AS $interaction) appnet_dolike($a, $uid, $interaction); */ }
function statusnet_fetchhometimeline($a, $uid, $mode = 1) { $conversations = array(); $ckey = get_pconfig($uid, 'statusnet', 'consumerkey'); $csecret = get_pconfig($uid, 'statusnet', 'consumersecret'); $api = get_pconfig($uid, 'statusnet', 'baseapi'); $otoken = get_pconfig($uid, 'statusnet', 'oauthtoken'); $osecret = get_pconfig($uid, 'statusnet', 'oauthsecret'); $create_user = get_pconfig($uid, 'statusnet', 'create_user'); // "create_user" is deactivated, since currently you cannot add users manually by now $create_user = true; logger("statusnet_fetchhometimeline: Fetching for user " . $uid, LOGGER_DEBUG); require_once 'library/twitteroauth.php'; require_once 'include/items.php'; $connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret); $own_contact = statusnet_fetch_own_contact($a, $uid); $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($own_contact), intval($uid)); if (count($r)) { $nick = $r[0]["nick"]; } else { logger("statusnet_fetchhometimeline: Own GNU Social contact not found for user " . $uid, LOGGER_DEBUG); return; } $r = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1", intval($uid)); if (count($r)) { $self = $r[0]; } else { logger("statusnet_fetchhometimeline: Own contact not found for user " . $uid, LOGGER_DEBUG); return; } $u = q("SELECT * FROM user WHERE uid = %d LIMIT 1", intval($uid)); if (!count($u)) { logger("statusnet_fetchhometimeline: Own user not found for user " . $uid, LOGGER_DEBUG); return; } $parameters = array("exclude_replies" => false, "trim_user" => false, "contributor_details" => true, "include_rts" => true); //$parameters["count"] = 200; if ($mode == 1) { // Fetching timeline $lastid = get_pconfig($uid, 'statusnet', 'lasthometimelineid'); //$lastid = 1; $first_time = $lastid == ""; if ($lastid != "") { $parameters["since_id"] = $lastid; } $items = $connection->get('statuses/home_timeline', $parameters); if (!is_array($items)) { if (is_object($items) and isset($items->error)) { $errormsg = $items->error; } elseif (is_object($items)) { $errormsg = print_r($items, true); } elseif (is_string($items) or is_float($items) or is_int($items)) { $errormsg = $items; } else { $errormsg = "Unknown error"; } logger("statusnet_fetchhometimeline: Error fetching home timeline: " . $errormsg, LOGGER_DEBUG); return; } $posts = array_reverse($items); logger("statusnet_fetchhometimeline: Fetching timeline for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); if (count($posts)) { foreach ($posts as $post) { if ($post->id > $lastid) { $lastid = $post->id; } if ($first_time) { continue; } if (isset($post->statusnet_conversation_id)) { if (!isset($conversations[$post->statusnet_conversation_id])) { statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $post->statusnet_conversation_id); $conversations[$post->statusnet_conversation_id] = $post->statusnet_conversation_id; } } else { $postarray = statusnet_createpost($a, $uid, $post, $self, $create_user, true); if (trim($postarray['body']) == "") { continue; } $item = item_store($postarray); $postarray["id"] = $item; logger('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted home timeline item ' . $item); if ($item and !function_exists("check_item_notification")) { statusnet_checknotification($a, $uid, $nick, $item, $postarray); } } } } set_pconfig($uid, 'statusnet', 'lasthometimelineid', $lastid); } // Fetching mentions $lastid = get_pconfig($uid, 'statusnet', 'lastmentionid'); $first_time = $lastid == ""; if ($lastid != "") { $parameters["since_id"] = $lastid; } $items = $connection->get('statuses/mentions_timeline', $parameters); if (!is_array($items)) { logger("statusnet_fetchhometimeline: Error fetching mentions: " . print_r($items, true), LOGGER_DEBUG); return; } $posts = array_reverse($items); logger("statusnet_fetchhometimeline: Fetching mentions for user " . $uid . " " . sizeof($posts) . " items", LOGGER_DEBUG); if (count($posts)) { foreach ($posts as $post) { if ($post->id > $lastid) { $lastid = $post->id; } if ($first_time) { continue; } $postarray = statusnet_createpost($a, $uid, $post, $self, false, false); if (isset($post->statusnet_conversation_id)) { if (!isset($conversations[$post->statusnet_conversation_id])) { statusnet_complete_conversation($a, $uid, $self, $create_user, $nick, $post->statusnet_conversation_id); $conversations[$post->statusnet_conversation_id] = $post->statusnet_conversation_id; } } else { if (trim($postarray['body']) != "") { continue; $item = item_store($postarray); $postarray["id"] = $item; logger('statusnet_fetchhometimeline: User ' . $self["nick"] . ' posted mention timeline item ' . $item); if ($item and function_exists("check_item_notification")) { check_item_notification($item, $uid, NOTIFY_TAGSELF); } } } $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), intval($uid)); if (count($r)) { $item = $r[0]['id']; $parent_id = $r[0]['parent']; } if ($item != 0 and !function_exists("check_item_notification")) { require_once 'include/enotify.php'; notification(array('type' => NOTIFY_TAGSELF, 'notify_flags' => $u[0]['notify-flags'], 'language' => $u[0]['language'], 'to_name' => $u[0]['username'], 'to_email' => $u[0]['email'], 'uid' => $u[0]['uid'], 'item' => $postarray, 'link' => $a->get_baseurl() . '/display/' . urlencode(get_item_guid($item)), 'source_name' => $postarray['author-name'], 'source_link' => $postarray['author-link'], 'source_photo' => $postarray['author-avatar'], 'verb' => ACTIVITY_TAG, 'otype' => 'item', 'parent' => $parent_id)); } } } set_pconfig($uid, 'statusnet', 'lastmentionid', $lastid); }