function postADNLink($post) { $adn = new AppDotNet(AdnCredentials::$client_id, AdnCredentials::$client_secret); if (isset($post['link'])) { $intro = "→ "; } else { $intro = ""; } $title = $post['post-title']; $data = array("entities" => array("links" => array(array("text" => $title, "url" => $post['post-absolute-permalink'], "pos" => mb_strlen($intro, 'UTF-8'), "len" => mb_strlen($title, 'UTF-8'))))); $params = array('access_token' => AdnCredentials::$access_token); $adn->createPost($intro . $title, $data, $params); error_log("Created post: " . $intro . $title); }
public function getAuthUrl($redirectUri = null, $scope = null) { global $app_redirectUri, $app_scope; if (is_null($redirectUri)) { $redirectUri = $app_redirectUri; } if (is_null($scope)) { $scope = $app_scope; } return parent::getAuthUrl($redirectUri, $scope); }
<?php require_once 'AppDotNet.php'; $app = new AppDotNet(); // log in user $code = $app->setSession(); // redirect user after logging in header('Location: index.php');
function appnet_createpost($a, $uid, $post, $me, $user, $ownid, $createuser, $threadcompletion = true, $nodupcheck = false) { require_once 'include/items.php'; if ($post["machine_only"]) { return; } if ($post["is_deleted"]) { return; } $postarray = array(); $postarray['gravity'] = 0; $postarray['uid'] = $uid; $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; $postarray['network'] = dbesc(NETWORK_APPNET); if (is_array($post["repost_of"])) { // You can't reply to reposts. So use the original id and thread-id $postarray['uri'] = "adn::" . $post["repost_of"]["id"]; $postarray['parent-uri'] = "adn::" . $post["repost_of"]["thread_id"]; } else { $postarray['uri'] = "adn::" . $post["id"]; $postarray['parent-uri'] = "adn::" . $post["thread_id"]; } if (!$nodupcheck) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), intval($uid)); if (count($r)) { return $r[0]; } $r = q("SELECT * FROM `item` WHERE `extid` = '%s' AND `uid` = %d LIMIT 1", dbesc($postarray['uri']), intval($uid)); if (count($r)) { return $r[0]; } } if (isset($post["reply_to"]) and $post["reply_to"] != "") { $postarray['thr-parent'] = "adn::" . $post["reply_to"]; // Complete the thread (if the parent doesn't exists) if ($threadcompletion) { //$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", // dbesc($postarray['thr-parent']), // intval($uid) // ); //if (!count($r)) { logger("appnet_createpost: completing thread " . $post["thread_id"] . " for user " . $uid, LOGGER_DEBUG); require_once "addon/appnet/AppDotNet.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); $param = array("count" => 200, "include_deleted" => false, "include_directed_posts" => true, "include_html" => false, "include_post_annotations" => true); try { $thread = $app->getPostReplies($post["thread_id"], $param); } catch (AppDotNetException $e) { logger("appnet_createpost: Error fetching thread for user " . $uid . " " . appnet_error($e->getMessage())); } $thread = array_reverse($thread); logger("appnet_createpost: fetched " . count($thread) . " items for thread " . $post["thread_id"] . " for user " . $uid, LOGGER_DEBUG); foreach ($thread as $tpost) { $threadpost = appnet_createpost($a, $uid, $tpost, $me, $user, $ownid, false, false); $item = item_store($threadpost); $threadpost["id"] = $item; logger("appnet_createpost: stored post " . $post["id"] . " thread " . $post["thread_id"] . " in item " . $item, LOGGER_DEBUG); } //} } // Don't create accounts of people who just comment something $createuser = false; $postarray['object-type'] = ACTIVITY_OBJ_COMMENT; } else { $postarray['thr-parent'] = $postarray['uri']; $postarray['object-type'] = ACTIVITY_OBJ_NOTE; } if ($post["user"]["id"] != $ownid or $postarray['thr-parent'] == $postarray['uri']) { $postarray['owner-name'] = $post["user"]["name"]; $postarray['owner-link'] = $post["user"]["canonical_url"]; $postarray['owner-avatar'] = $post["user"]["avatar_image"]["url"]; $postarray['contact-id'] = appnet_fetchcontact($a, $uid, $post["user"], $me, $createuser); } else { $postarray['owner-name'] = $me["name"]; $postarray['owner-link'] = $me["url"]; $postarray['owner-avatar'] = $me["thumb"]; $postarray['contact-id'] = $me["id"]; } $links = array(); if (is_array($post["repost_of"])) { $postarray['author-name'] = $post["repost_of"]["user"]["name"]; $postarray['author-link'] = $post["repost_of"]["user"]["canonical_url"]; $postarray['author-avatar'] = $post["repost_of"]["user"]["avatar_image"]["url"]; $content = $post["repost_of"]; } else { $postarray['author-name'] = $postarray['owner-name']; $postarray['author-link'] = $postarray['owner-link']; $postarray['author-avatar'] = $postarray['owner-avatar']; $content = $post; } $postarray['plink'] = $content["canonical_url"]; if (is_array($content["entities"])) { $converted = appnet_expand_entities($a, $content["text"], $content["entities"]); $postarray['body'] = $converted["body"]; $postarray['tag'] = $converted["tags"]; } else { $postarray['body'] = $content["text"]; } if (sizeof($content["entities"]["links"])) { foreach ($content["entities"]["links"] as $link) { $url = normalise_link($link["url"]); $links[$url] = $link["url"]; } } /* if (sizeof($content["annotations"])) foreach($content["annotations"] AS $annotation) { if ($annotation[type] == "net.app.core.oembed") { if (isset($annotation["value"]["embeddable_url"])) { $url = normalise_link($annotation["value"]["embeddable_url"]); if (isset($links[$url])) unset($links[$url]); } } elseif ($annotation[type] == "com.friendica.post") { //$links = array(); //if (isset($annotation["value"]["post-title"])) // $postarray['title'] = $annotation["value"]["post-title"]; //if (isset($annotation["value"]["post-body"])) // $postarray['body'] = $annotation["value"]["post-body"]; //if (isset($annotation["value"]["post-tag"])) // $postarray['tag'] = $annotation["value"]["post-tag"]; if (isset($annotation["value"]["author-name"])) $postarray['author-name'] = $annotation["value"]["author-name"]; if (isset($annotation["value"]["author-link"])) $postarray['author-link'] = $annotation["value"]["author-link"]; if (isset($annotation["value"]["author-avatar"])) $postarray['author-avatar'] = $annotation["value"]["author-avatar"]; } } */ $page_info = ""; if (is_array($content["annotations"])) { $photo = appnet_expand_annotations($a, $content["annotations"]); if ($photo["large"] != "" and $photo["url"] != "") { $page_info = "\n[url=" . $photo["url"] . "][img]" . $photo["large"] . "[/img][/url]"; } elseif ($photo["url"] != "") { $page_info = "\n[img]" . $photo["url"] . "[/img]"; } if ($photo["url"] != "") { $postarray['object-type'] = ACTIVITY_OBJ_IMAGE; } } else { $photo = array("url" => "", "large" => ""); } if (sizeof($links)) { $link = array_pop($links); $url = str_replace(array('/', '.'), array('\\/', '\\.'), $link); $page_info = add_page_info($link, false, $photo["url"]); if (trim($page_info) != "") { $removedlink = preg_replace("/\\[url\\=" . $url . "\\](.*?)\\[\\/url\\]/ism", '', $postarray['body']); if ($removedlink == "" or strstr($postarray['body'], $removedlink)) { $postarray['body'] = $removedlink; } } } $postarray['body'] .= $page_info; $postarray['created'] = datetime_convert('UTC', 'UTC', $post["created_at"]); $postarray['edited'] = datetime_convert('UTC', 'UTC', $post["created_at"]); $postarray['app'] = $post["source"]["name"]; return $postarray; }
<?php require_once 'AppDotNet.php'; $app = new AppDotNet(); // check that the user is signed in if ($app->getSession()) { // get the current user as JSON $data = $app->getUser(); // accessing the user's cover image echo '<body style="background:url(' . $data['cover_image']['url'] . ')">'; echo '<div style="background:#fff;opacity:0.8;padding:20px;margin:10px;border-radius:15px;">'; echo '<h1>Welcome to <a target="_blank" href="https://github.com/jdolitsky/AppDotNetPHP">'; echo 'AppDotNetPHP</a></h1>'; // accessing the user's name echo '<h3>' . $data['name'] . '</h3>'; // accessing the user's avatar image echo '<img style="border:2px solid #000;" src="' . $data['avatar_image']['url'] . '" /><br>'; // try posting to ADN if (isset($_POST['run_tests'])) { print "<hr />"; print "<h3>Testing ADN functionality</h3>"; print '<pre>'; print "<b>Attempting to post a test message to app.net...</b>\n"; print "<blockquote>"; $sampleText = "Testing posting to app.net using AppDotNetPHP - " . uniqid(mt_rand(0, 100000)); $create = $app->createPost($sampleText); // we should now have a post ID and the text should be the same as above if (!$create || !$create['id'] || $create['text'] != $sampleText) { print "Error posting sample text to ADN\n"; var_dump($create); exit;
<?php require_once 'AppDotNet.php'; require_once 'EZsettings.php'; $app = new AppDotNet($app_clientId, $app_clientSecret); // You need an app token to consume the stream, get the token returned by App.net // (this also sets the token) $token = $app->getAppAccessToken(); // getting a 400 error // 1. first check to make sure you set your app_clientId & app_clientSecret correctly // if that doesn't fix it, try this // 2. It's possible you have hit your stream limit (5 stream per app) // uncomment this to clear all the streams you've previously created //$app->deleteAllStreams(); // create a stream // if you already have a stream you can skip this step // this stream is going to consume posts and stars (but not follows) $stream = $app->createStream(array('post', 'star', 'user_follow')); // you might want to save $stream['endpoint'] or $stream['id'] for later so // you don't have to re-create the stream print "stream id [" . $stream['id'] . "]\n"; //$stream = $app->getStream(XXX); // we need to create a callback function that will do something with posts/stars // when they're received from the stream. This function should accept one single // parameter that will be the php object containing the meta / data for the event. /* [meta] => Array ( [timestamp] => 1352147672891 [type] => post/star/etc... [id] => 1399341
<?php require_once 'AppDotNet.php'; $app = new AppDotNet(); // log out user $code = $app->deleteSession(); // redirect user after logging out header('Location: index.php');