function getContent() { if (!\Idno\Core\site()->session()->isLoggedIn()) { $this->setResponse(401); $this->forward('/session/login'); } $url = $this->getInput('share_url'); $title = $this->getInput('share_title'); $share_type = 'note'; if ($content = \Idno\Core\Webmention::getPageContent($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) { if (substr_count($content['content'], 'h-entry') == 1) { $share_type = 'reply'; if (substr_count($content['content'], 'h-event') == 1) { $share_type = 'rsvp'; } } } } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); if (!empty($content_type)) { if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) { if ($share_type == 'note' && !substr_count($url, 'twitter.com')) { $page->setInput('body', $title . ' ' . $url); } else { $page->setInput('url', $url); if (substr_count($url, 'twitter.com')) { preg_match("|https?://(www\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches); if (!empty($matches[3])) { $page->setInput('body', '@' . $matches[3] . ' '); } } } $page->setInput('hidenav', true); $page->get(); } } else { $t = \Idno\Core\site()->template(); $body = $t->__(['share_type' => $share_type, 'content_type' => $content_type])->draw('firefox/share'); $t->__(['title' => 'Share', 'body' => $body, 'hidenav' => true])->drawPage(); } }
function post() { $headers = $this->getallheaders(); $user = \Idno\Entities\User::getOne(array('admin' => true)); \Idno\Core\site()->session()->refreshSessionUser($user); $indieauth_tokens = $user->indieauth_tokens; if (!empty($headers['Authorization'])) { $token = $headers['Authorization']; $token = trim(str_replace('Bearer', '', $token)); } else { if ($token = $this->getInput('access_token')) { $token = trim($token); } } $user_token = $user->getAPIkey(); if (!empty($indieauth_tokens[$token]) || $token == $user_token) { // If we're here, we're authorized // Get details $type = $this->getInput('h'); $content = $this->getInput('content'); $name = $this->getInput('name'); $in_reply_to = $this->getInput('in-reply-to'); $syndicate = $this->getInput('syndicate-to'); if ($type == 'entry') { if (!empty($_FILES['photo'])) { $type = 'photo'; if (empty($name) && !empty($content)) { $name = $content; $content = ''; } } else { if (empty($name)) { $type = 'note'; } else { $type = 'article'; } } } // Get an appropriate plugin, given the content type if ($contentType = ContentType::getRegisteredForIndieWebPostType($type)) { if ($entity = $contentType->createEntity()) { $this->setInput('title', $name); $this->setInput('body', $content); $this->setInput('inreplyto', $in_reply_to); if ($created = $this->getInput('published')) { $this->setInput('created', $created); } if (!empty($syndicate)) { $syndication = array(trim(str_replace('.com', '', $syndicate))); $this->setInput('syndication', $syndication); } if ($entity->saveDataFromInput()) { //$this->setResponse(201); header('Location: ' . $entity->getURL()); exit; } else { $this->setResponse(500); echo "Couldn't create {$type}"; exit; } } } else { $this->setResponse(500); echo "Couldn't find content type {$type}"; exit; } } $this->setResponse(403); echo 'Bad token'; }
function getContent() { $this->gatekeeper(); $url = $this->getInput('share_url'); $title = $this->getInput('share_title'); $type = $this->getInput('share_type'); // Provide a hook to a URL shortener (TODO: Tidy this up when #237 is merged) $event = new \Idno\Core\Event(); $event->setResponse($url); \Idno\Core\site()->events()->dispatch('url/shorten', $event); $url = $event->response(); if (!in_array($type, ['note', 'reply', 'rsvp', 'like'])) { $share_type = 'note'; if ($content = \Idno\Core\Webservice::get($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) { if (!empty($mf2['items'])) { foreach ($mf2['items'] as $item) { if (!empty($item['type'])) { if (in_array('h-entry', $item['type'])) { $share_type = 'reply'; } if (in_array('h-event', $item['type'])) { $share_type = 'rsvp'; } } } } } } } else { $share_type = $type; } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); $hide_nav = false; if ($this->getInput('via') == 'ff_social') { $hide_nav = true; } if (!empty($content_type)) { if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) { if ($share_type == 'note') { $page->setInput('body', $title . ' ' . $url); } else { $page->setInput('url', $url); if (substr_count($url, 'twitter.com')) { preg_match("|https?://(www\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches); if (!empty($matches[3])) { $page->setInput('body', '@' . $matches[3] . ' '); } } } $page->setInput('hidenav', $hide_nav); $page->setInput('sharing', true); $page->setInput('share_type', $share_type); $page->get(); } } else { $t = \Idno\Core\site()->template(); $body = $t->__(['share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true])->draw('entity/share'); $t->__(['title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav])->drawPage(); } }
function post() { $this->gatekeeper(); // If we're here, we're authorized // Get details $type = $this->getInput('h'); $content = $this->getInput('content'); $name = $this->getInput('name'); $in_reply_to = $this->getInput('in-reply-to'); $syndicate = $this->getInput('mp-syndicate-to', $this->getInput('syndicate-to')); $like_of = $this->getInput('like-of'); $repost_of = $this->getInput('repost-of'); if ($type == 'entry') { $type = 'article'; if (!empty($_FILES['photo'])) { $type = 'photo'; if (empty($name) && !empty($content)) { $name = $content; $content = ''; } } if (empty($name)) { $type = 'note'; } if (!empty($like_of)) { $type = 'like'; } if (!empty($repost_of)) { $type = 'repost'; } } // Get an appropriate plugin, given the content type if ($contentType = ContentType::getRegisteredForIndieWebPostType($type)) { if ($entity = $contentType->createEntity()) { error_log(var_export($entity, true)); if (is_array($content)) { $content_value = ''; if (!empty($content['html'])) { $content_value = $content['html']; } else { if (!empty($content['value'])) { $content_value = $content['value']; } } } else { $content_value = $content; } $this->setInput('title', $name); $this->setInput('body', $content_value); $this->setInput('inreplyto', $in_reply_to); $this->setInput('like-of', $like_of); $this->setInput('repost-of', $repost_of); $this->setInput('access', 'PUBLIC'); if ($created = $this->getInput('published')) { $this->setInput('created', $created); } if (!empty($syndicate)) { if (is_array($syndicate)) { $syndication = $syndicate; } else { $syndication = array(trim(str_replace('.com', '', $syndicate))); } \Idno\Core\Idno::site()->logging()->log("Setting syndication: {$syndication}"); $this->setInput('syndication', $syndication); } if ($entity->saveDataFromInput()) { $this->setResponse(201); header('Location: ' . $entity->getURL()); exit; } else { $this->setResponse(500); echo "Couldn't create {$type}"; exit; } } } else { $this->setResponse(500); echo "Couldn't find content type {$type}"; exit; } }
function getContent() { $this->gatekeeper(); $url = $this->getInput('share_url', $this->getInput('url')); $title = $this->getInput('share_title', $this->getInput('title')); $type = $this->getInput('share_type'); $syndicatedto = []; // remove cruft added by mobile apps if (preg_match('~\\b(?:f|ht)tps?://[^\\s]+\\b~i', $url, $matches)) { $url = $matches[0]; } $event = new \Idno\Core\Event(); $event->setResponse($url); \Idno\Core\Idno::site()->events()->dispatch('url/shorten', $event); $short_url = $event->response(); if (!$type || !\Idno\Common\ContentType::getRegisteredForIndieWebPostType($type)) { $share_type = 'note'; // Probe to see if this is something we can MF2 parse, before we do $headers = []; if ($head = \Idno\Core\Webservice::head($url)) { $headers = http_parse_headers($head['header']); } // Only MF2 Parse supported types if (isset($headers['Content-Type']) && preg_match('/text\\/(html|plain)+/', $headers['Content-Type'])) { if ($response = \Idno\Core\Webservice::get($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($response['content'])) { if (!empty($mf2['items'])) { foreach ($mf2['items'] as $item) { if (!empty($item['type'])) { if (in_array('h-entry', $item['type'])) { $share_type = 'reply'; } if (in_array('h-event', $item['type'])) { $share_type = 'rsvp'; } } } } } $syndicatedto = \Idno\Core\Webmention::addSyndicatedReplyTargets($url, $syndicatedto, $response); } } } else { $share_type = $type; } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); $hide_nav = false; if ($this->getInput('via') == 'ff_social') { $hide_nav = true; } if (!empty($content_type)) { if ($page = \Idno\Core\Idno::site()->getPageHandler($content_type->getEditURL())) { if ($share_type == 'note') { $page->setInput('body', $title . ' ' . $short_url); } else { $page->setInput('short-url', $short_url); $page->setInput('url', $url); $page->setInput('syndicatedto', $syndicatedto); // prefill the @-name of the person we're replying to $atusers = []; foreach (array_merge((array) $url, (array) $syndicatedto) as $tweeturl) { if (strstr($tweeturl, 'twitter.com') !== false) { if (preg_match("|https?://([a-z]+\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $tweeturl, $matches) && !empty($matches[3])) { $atusers[] = '@' . $matches[3]; } if (preg_match_all("|@([^\\s^\\)]+)|", $title, $matches)) { $atusers = array_merge($atusers, $matches[0]); } } } if ($atusers) { // See if one of your registered twitter handles is present, if so remove it. $user = \Idno\Core\Idno::site()->session()->currentUser(); if (!empty($user->twitter) && is_array($user->twitter)) { $me = []; foreach ($user->twitter as $k => $v) { $me[] = '@' . $k; } $atusers = array_diff($atusers, $me); } } if ($atusers) { $atusers = array_unique($atusers); $page->setInput('body', implode(' ', $atusers) . ' '); } } $page->setInput('hidenav', $hide_nav); $page->setInput('sharing', true); $page->setInput('share_type', $share_type); $page->get(); } } else { $t = \Idno\Core\Idno::site()->template(); $body = $t->__(array('share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true))->draw('entity/share'); $t->__(array('title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav))->drawPage(); } }
function post() { $this->gatekeeper(); // If we're here, we're authorized \Idno\Core\Idno::site()->triggerEvent('indiepub/post/start', ['page' => $this]); // Get details $type = $this->getInput('h', 'entry'); $content = $this->getInput('content'); $name = $this->getInput('name'); $in_reply_to = $this->getInput('in-reply-to'); $syndicate = $this->getInput('mp-syndicate-to', $this->getInput('syndicate-to')); $posse_link = $this->getInput('syndication'); $like_of = $this->getInput('like-of'); $repost_of = $this->getInput('repost-of'); $categories = $this->getInput('category'); $mp_type = $this->getInput('mp-type'); if (!empty($mp_type)) { $type = $mp_type; } if ($type == 'entry') { $type = 'note'; if (!empty($_FILES['photo'])) { $type = 'photo'; } else { if ($photo_url = $this->getInput('photo')) { $type = 'photo'; $success = $this->uploadFromUrl($photo_url); if (!$success) { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Failed uploading photo from {$photo_url}"; exit; } } else { if (!empty($name)) { $type = 'article'; } } } } if ($type == 'checkin') { $place_name = $this->getInput('place_name'); $location = $this->getInput('location'); $photo = $this->getInput('photo'); $latlong = explode(",", $location); $lat = str_ireplace("geo:", "", $latlong[0]); $long = $latlong[1]; $q = \IdnoPlugins\Checkin\Checkin::queryLatLong($lat, $long); $user_address = $q['display_name']; if (!empty($_FILES['photo'])) { $id = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type']); $photo = \Idno\Core\Idno::site()->config()->url . 'file/' . $id; } if (!empty($photo)) { $htmlPhoto = '<p><img style="display: block; margin-left: auto; margin-right: auto;" src="' . $photo . '" alt="' . $place_name . '" /></p>'; } } if ($type == 'photo' && empty($name) && !empty($content)) { $name = $content; $content = ''; } if (!empty($like_of)) { $type = 'like'; } if (!empty($repost_of)) { $type = 'repost'; } // setting all categories as hashtags into content field if (is_array($categories)) { $hashtags = ""; foreach ($categories as $category) { $category = trim($category); if ($category) { if (str_word_count($category) > 1) { $category = str_replace("'", " ", $category); $category = ucwords($category); $category = str_replace(" ", "", $category); } $hashtags .= " #{$category}"; } } $title_words = explode(" ", $name); $name = ""; foreach ($title_words as $word) { if (substr($word, 0, 1) !== "#") { $name .= "{$word} "; } } } // Get an appropriate plugin, given the content type if ($contentType = ContentType::getRegisteredForIndieWebPostType($type)) { if ($entity = $contentType->createEntity()) { if (is_array($content)) { $content_value = ''; if (!empty($content['html'])) { $content_value = $content['html']; } else { if (!empty($content['value'])) { $content_value = $content['value']; } } } else { $content_value = $content; } if (!empty($posse_link)) { $posse_service = parse_url($posse_link, PHP_URL_HOST); $entity->setPosseLink(str_replace('.com', '', $posse_service), $posse_link, '', ''); } $hashtags = empty($hashtags) ? "" : "<p>" . $hashtags . "</p>"; $htmlPhoto = empty($htmlPhoto) ? "" : "<p>" . $htmlPhoto . "</p>"; $this->setInput('title', $name); $this->setInput('body', $htmlPhoto . $content_value . $hashtags); $this->setInput('inreplyto', $in_reply_to); $this->setInput('like-of', $like_of); $this->setInput('repost-of', $repost_of); $this->setInput('access', 'PUBLIC'); if ($type == 'checkin') { $this->setInput('lat', $lat); $this->setInput('long', $long); $this->setInput('user_address', $user_address); $this->setInput('placename', $place_name); } if ($created = $this->getInput('published')) { $this->setInput('created', $created); } if (!empty($syndicate)) { if (is_array($syndicate)) { $syndication = $syndicate; } else { $syndication = array(trim(str_replace('.com', '', $syndicate))); } \Idno\Core\Idno::site()->logging()->info("Setting syndication: {$syndication}"); $this->setInput('syndication', $syndication); } if ($entity->saveDataFromInput()) { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/success', ['page' => $this, 'object' => $entity]); $this->setResponse(201); header('Location: ' . $entity->getURL()); exit; } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't create {$type}"; exit; } } } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't find content type {$type}"; exit; } }
<?php if ($page = \Idno\Core\site()->currentPage()) { if ($page->getInput('sharing')) { $share_type = $page->getInput('share_type'); if (empty($share_type)) { $share_type = 'note'; } ?> <div class="row"> <div class="col-md-10 col-md-offset-1"> <ul class="nav nav-tabs"> <?php foreach (array('note' => 'Share', 'reply' => 'Reply', 'bookmark' => 'Bookmark', 'like' => 'Like', 'rsvp' => 'RSVP') as $variable => $label) { if ($content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($variable)) { ?> <li <?php if ($variable == $share_type) { ?> class="active"<?php } ?> > <a href="<?php echo $this->getURLWithVar('share_type', $variable); ?> "><?php echo $label; ?> </a>
function getContent() { $this->gatekeeper(); $url = $this->getInput('share_url', $this->getInput('url')); $title = $this->getInput('share_title', $this->getInput('title')); $type = $this->getInput('share_type'); $event = new \Idno\Core\Event(); $event->setResponse($url); \Idno\Core\site()->events()->dispatch('url/shorten', $event); $short_url = $event->response(); if (!in_array($type, array('note', 'reply', 'rsvp', 'like', 'bookmark'))) { $share_type = 'note'; if ($content = \Idno\Core\Webservice::get($url)) { if ($mf2 = \Idno\Core\Webmention::parseContent($content['content'])) { if (!empty($mf2['items'])) { foreach ($mf2['items'] as $item) { if (!empty($item['type'])) { if (in_array('h-entry', $item['type'])) { $share_type = 'reply'; } if (in_array('h-event', $item['type'])) { $share_type = 'rsvp'; } } } } } } } else { $share_type = $type; } $content_type = \Idno\Common\ContentType::getRegisteredForIndieWebPostType($share_type); $hide_nav = false; if ($this->getInput('via') == 'ff_social') { $hide_nav = true; } if (!empty($content_type)) { if ($page = \Idno\Core\site()->getPageHandler('/' . $content_type->camelCase($content_type->getEntityClassName()) . '/edit')) { if ($share_type == 'note') { $page->setInput('body', $title . ' ' . $short_url); } else { $page->setInput('short-url', $short_url); $page->setInput('url', $url); if (substr_count($url, 'twitter.com')) { $atusers = []; preg_match("|https?://([a-z]+\\.)?twitter\\.com/(#!/)?@?([^/]*)|", $url, $matches); if (!empty($matches[3])) { $atusers[] = '@' . $matches[3]; // $page->setInput('body', '@' . $matches[3] . ' '); } if (preg_match_all("|@([^\\s^\\)]+)|", $title, $matches)) { $atusers = array_merge($atusers, $matches[0]); } // See if one of your registered twitter handles is present, if so remove it. $user = \Idno\Core\site()->session()->currentUser(); if (!empty($user->twitter) && is_array($user->twitter)) { $me = []; foreach ($user->twitter as $k => $v) { $me[] = "@{$k}"; } $atusers = array_diff($atusers, $me); } $atusers = array_unique($atusers); $page->setInput('body', implode(' ', $atusers) . ' '); } } $page->setInput('hidenav', $hide_nav); $page->setInput('sharing', true); $page->setInput('share_type', $share_type); $page->get(); } } else { $t = \Idno\Core\site()->template(); $body = $t->__(array('share_type' => $share_type, 'content_type' => $content_type, 'sharing' => true))->draw('entity/share'); $t->__(array('title' => 'Share', 'body' => $body, 'hidenav' => $hide_nav))->drawPage(); } }
function post() { $this->gatekeeper(); // If we're here, we're authorized \Idno\Core\Idno::site()->triggerEvent('indiepub/post/start', ['page' => $this]); // Get details $type = $this->getInput('h'); $content = $this->getInput('content'); $name = $this->getInput('name'); $in_reply_to = $this->getInput('in-reply-to'); $syndicate = $this->getInput('mp-syndicate-to', $this->getInput('syndicate-to')); $posse_link = $this->getInput('syndication'); $like_of = $this->getInput('like-of'); $repost_of = $this->getInput('repost-of'); $categories = $this->getInput('category'); if ($type == 'entry') { $type = 'article'; if (!empty($_FILES['photo'])) { $type = 'photo'; } else { $photo_url = $this->getInput('photo'); if ($photo_url) { $type = 'photo'; $success = $this->uploadFromUrl($photo_url); if (!$success) { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Failed uploading photo from {$photo_url}"; exit; } } } if ($type == 'photo' && empty($name) && !empty($content)) { $name = $content; $content = ''; } if (empty($name)) { $type = 'note'; } if (!empty($like_of)) { $type = 'like'; } if (!empty($repost_of)) { $type = 'repost'; } } // setting all categories as hashtags into content field if (is_array($categories)) { foreach ($categories as $category) { $content .= " #{$category}"; } $title_words = explode(" ", $name); $name = ""; foreach ($title_words as $word) { if (substr($word, 0, 1) !== "#") { $name .= "{$word} "; } } } // Get an appropriate plugin, given the content type if ($contentType = ContentType::getRegisteredForIndieWebPostType($type)) { if ($entity = $contentType->createEntity()) { if (is_array($content)) { $content_value = ''; if (!empty($content['html'])) { $content_value = $content['html']; } else { if (!empty($content['value'])) { $content_value = $content['value']; } } } else { $content_value = $content; } $posse_url = parse_url($posse_link); $posse_service = $posse_url['host']; $entity->setPosseLink($posse_service, $posse_link, '', ''); $this->setInput('title', $name); $this->setInput('body', $content_value); $this->setInput('inreplyto', $in_reply_to); $this->setInput('like-of', $like_of); $this->setInput('repost-of', $repost_of); $this->setInput('access', 'PUBLIC'); if ($created = $this->getInput('published')) { $this->setInput('created', $created); } if (!empty($syndicate)) { if (is_array($syndicate)) { $syndication = $syndicate; } else { $syndication = array(trim(str_replace('.com', '', $syndicate))); } \Idno\Core\Idno::site()->logging()->log("Setting syndication: {$syndication}"); $this->setInput('syndication', $syndication); } if ($entity->saveDataFromInput($this)) { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/success', ['page' => $this, 'object' => $entity]); $this->setResponse(201); header('Location: ' . $entity->getURL()); exit; } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't create {$type}"; exit; } } } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't find content type {$type}"; exit; } }