/** * Automatically registers content types associated with plugins, * as long as they're called IdnoPlugins\PLUGIN-NAME\ContentType */ function registerContentTypes() { $namespace = $this->getNamespace(); if (class_exists($namespace . '\\ContentType')) { if (is_subclass_of($namespace . '\\ContentType', 'Idno\\Common\\ContentType')) { \Idno\Common\ContentType::register($namespace . '\\ContentType'); } } }
function getContent() { $this->createGatekeeper(); // Logged-in only please $t = \Idno\Core\site()->template(); $t->content_types = \Idno\Common\ContentType::getRegistered(); $t->default_content_types = \Idno\Core\site()->session()->currentUser()->settings['default_feed_content']; $t->body = $t->draw('account/settings/homepage'); $t->title = 'Homepage settings'; $t->drawPage(); }
function getContent() { $this->createGatekeeper(); // Logged-in only please $t = \Idno\Core\Idno::site()->template(); $t->content_types = \Idno\Common\ContentType::getRegistered(); $default_content_types = \Idno\Core\Idno::site()->config()->getHomepageContentTypes(); //\Idno\Core\Idno::site()->session()->currentUser()->settings['default_feed_content']; if (empty($default_content_types)) { foreach ($t->content_types as $content_type) { $default_content_types[] = $content_type->getEntityClass(); } } $t->default_content_types = $default_content_types; $t->body = $t->draw('admin/homepage'); $t->title = 'Homepage'; $t->drawPage(); }
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 getContent() { $offset = (int) $this->getInput('offset'); $types = $this->getInput('types'); if (!empty($this->arguments[0])) { // If we're on the friendly content-specific URL if ($friendly_types = explode('/', $this->arguments[0])) { $types = []; // Run through the URL parameters and set content types appropriately foreach ($friendly_types as $friendly_type) { if ($content_type_class = \Idno\Common\ContentType::categoryTitleToClass($friendly_type)) { $types[] = $content_type_class; } } } } if (empty($types)) { $types = 'Idno\\Entities\\ActivityStreamPost'; $search = ['verb' => 'post']; } else { if (!is_array($types)) { $types = [$types]; } $types[] = '!Idno\\Entities\\ActivityStreamPost'; $search = []; } $count = \Idno\Entities\ActivityStreamPost::countFromX($types, []); $feed = \Idno\Entities\ActivityStreamPost::getFromX($types, $search, [], \Idno\Core\site()->config()->items_per_page, $offset); if (\Idno\Core\site()->session()->isLoggedIn()) { $create = \Idno\Common\ContentType::getRegistered(); } else { $create = false; } if (!empty(\Idno\Core\site()->config()->description)) { $description = \Idno\Core\site()->description; } else { $description = 'An independent social website, powered by idno.'; } $t = \Idno\Core\site()->template(); $t->__(array('title' => \Idno\Core\site()->config()->title, 'description' => $description, 'body' => $t->__(array('items' => $feed, 'contentTypes' => $create, 'offset' => $offset, 'count' => $count))->draw('pages/home')))->drawPage(); }
function getContent() { if (!empty($this->arguments[0])) { $user = \Idno\Entities\User::getByHandle($this->arguments[0]); } if (empty($user)) { $this->noContent(); } // Users own their own profiles $this->setOwner($user); $types = \Idno\Common\ContentType::getRegisteredClasses(); $offset = (int) $this->getInput('offset'); $count = \Idno\Common\Entity::countFromX($types, array('owner' => $user->getUUID())); $feed = \Idno\Common\Entity::getFromX($types, array('owner' => $user->getUUID()), array(), \Idno\Core\Idno::site()->config()->items_per_page, $offset); $last_modified = $user->updated; if (!empty($feed) && is_array($feed)) { if ($feed[0]->updated > $last_modified) { $last_modified = $feed[0]->updated; } } $this->setLastModifiedHeader($last_modified); $t = \Idno\Core\Idno::site()->template(); $t->__(array('title' => $user->getTitle(), 'body' => $t->__(array('user' => $user, 'items' => $feed, 'count' => $count, 'offset' => $offset))->draw('entity/User/profile'), 'description' => 'The ' . \Idno\Core\Idno::site()->config()->title . ' profile for ' . $user->getTitle()))->drawPage(); }
<ul class="nav navbar-nav"> <?php $content_types = \Idno\Common\ContentType::getRegistered(); if (!empty($content_types)) { if (!empty($vars['subject'])) { $search = '?q=' . urlencode($vars['subject']); } else { $search = ''; } ?> <li class="dropdown" tabindex="3"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> <?php if (!empty($vars['content'])) { echo \Idno\Common\ContentType::categoryTitleSlugsToFriendlyName($vars['content']); } else { echo 'Filter content'; } ?> <span class="caret"></span> </a> <ul class="dropdown-menu" role="menu"> <li><a href="<?php echo \Idno\Core\site()->config()->getDisplayURL() . $search; ?> "><span class="dropdown-menu-icon"> </span> Default content</a></li> <li><a href="<?php echo \Idno\Core\site()->config()->getDisplayURL() . 'content/all/' . $search; ?>
function registerContentTypes() { parent::registerContentTypes(); \Idno\Common\ContentType::register($this->getNamespace() . '\\RepliesContentType'); }
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 getContent() { $query = $this->getInput('q'); $offset = (int) $this->getInput('offset'); $types = $this->getInput('types'); $friendly_types = array(); // Check for an empty site if (!\Idno\Entities\User::get()) { $this->forward(\Idno\Core\Idno::site()->config()->getURL() . 'begin/'); } if (!empty($this->arguments[0])) { // If we're on the friendly content-specific URL if ($friendly_types = explode('/', $this->arguments[0])) { $friendly_types = array_filter($friendly_types); if (empty($friendly_types) && !empty($query)) { $friendly_types = array('all'); } $types = array(); // Run through the URL parameters and set content types appropriately foreach ($friendly_types as $friendly_type) { if ($friendly_type == 'all') { $types = \Idno\Common\ContentType::getRegisteredClasses(); break; } if ($content_type_class = \Idno\Common\ContentType::categoryTitleToClass($friendly_type)) { $types[] = $content_type_class; } } } } else { // If user has content-specific preferences, do something with $friendly_types if (empty($query)) { $types = \Idno\Core\Idno::site()->config()->getHomepageContentTypes(); } } $search = array(); if (!empty($query)) { $search = \Idno\Core\Idno::site()->db()->createSearchArray($query); } if (empty($types)) { $types = \Idno\Common\ContentType::getRegisteredClasses(); } else { if (!is_array($types)) { $types = array($types); } $types[] = '!Idno\\Entities\\ActivityStreamPost'; } $count = \Idno\Entities\ActivityStreamPost::countFromX($types, array()); $feed = \Idno\Entities\ActivityStreamPost::getFromX($types, $search, array(), \Idno\Core\Idno::site()->config()->items_per_page, $offset); if (\Idno\Core\Idno::site()->session()->isLoggedIn()) { $create = \Idno\Common\ContentType::getRegistered(); // If we can't create an object of this type, hide from the button bar foreach ($create as $key => $obj) { if (!$obj->createable) { unset($create[$key]); } } } else { $create = false; } if (!empty(\Idno\Core\Idno::site()->config()->description)) { $description = \Idno\Core\Idno::site()->config()->description; } else { $description = 'An independent social website, powered by Known.'; } // If we have a feed, set our last modified flag to the time of the latest returned entry if (!empty($feed)) { if (is_array($feed)) { $feed = array_filter($feed); $this->setLastModifiedHeader(reset($feed)->updated); } } if (!empty(\Idno\Core\Idno::site()->config()->homepagetitle)) { $title = \Idno\Core\Idno::site()->config()->homepagetitle; } else { $title = \Idno\Core\Idno::site()->config()->title; } $t = \Idno\Core\Idno::site()->template(); $t->__(array('title' => $title, 'description' => $description, 'content' => $friendly_types, 'body' => $t->__(array('items' => $feed, 'contentTypes' => $create, 'offset' => $offset, 'count' => $count, 'subject' => $query, 'content' => $friendly_types))->draw('pages/home')))->drawPage(); }
/** * Retrieve all posts as an RSS feed * @param bool|true $hide_private Should we hide private posts? Default: true. * @param string $user_uuid User UUID to export for. Default: all users. * @return bool|false|string */ static function getExportRSS($hide_private = true, $user_uuid = '') { $types = \Idno\Common\ContentType::getRegisteredClasses(); if ($hide_private) { $groups = ['PUBLIC']; } else { $groups = []; } if (!empty($user_uuid)) { $search = ['owner' => $user_uuid]; if ($user = User::getByUUID($user_uuid)) { $title = $user->getTitle(); $description = $user->getDescription(); $base_url = $user_uuid; } } else { $search = []; $title = Idno::site()->config()->getTitle(); $description = Idno::site()->config()->getDescription(); $base_url = Idno::site()->config()->getDisplayURL(); } if ($feed = \Idno\Common\Entity::getFromX($types, $search, array(), PHP_INT_MAX - 1, 0, $groups)) { $rss_theme = new Template(); $rss_theme->setTemplateType('rss'); return $rss_theme->__(array('title' => $title, 'description' => $description, 'body' => $rss_theme->__(array('items' => $feed, 'offset' => 0, 'count' => sizeof($feed), 'subject' => [], 'nocdata' => true, 'base_url' => $base_url))->draw('pages/home')))->drawPage(false); } return false; }
/** * Retrieves the content type object associated with this class; * @return bool|ContentType */ function getContentType() { return \Idno\Common\ContentType::getContentTypeObjectFromClass($this->getClass()); }
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() { $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 registerContentTypes() { \Idno\Common\ContentType::register('\\IdnoPlugins\\Event\\ContentType'); \Idno\Common\ContentType::register('\\IdnoPlugins\\Event\\RSVPContentType'); }
/** * Get a user's settings for default content types on their homepage (or all the content types registered * if none have been listed). * * THIS IS A LEGACY FUNCTION AND DUE FOR REMOVAL. * @deprecated * * @return array */ function getDefaultContentTypes() { $friendly_types = array(); if ($temp_types = $this->settings['default_feed_content']) { if (is_array($temp_types)) { foreach ($temp_types as $temp_type) { if ($content_type_class = \Idno\Common\ContentType::categoryTitleToClass($temp_type)) { $friendly_types[] = $content_type_class; } } } } return $friendly_types; }
<?php $content_types = \Idno\Common\ContentType::getRegistered(); if (!empty($content_types)) { ?> <ul class="nav"> <li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> Content <b class="caret"></b> </a> <ul class="dropdown-menu"> <li><a href="<?php echo \Idno\Core\site()->config()->url; ?> "><span class="dropdown-menu-icon"> </span> Everything</a></li> <?php foreach ($content_types as $content_type) { if (empty($content_type->hide)) { /* @var Idno\Common\ContentType $content_type */ ?> <li><a href="<?php echo \Idno\Core\site()->config()->url; ?> content/<?php echo urlencode(strtolower(str_replace(' ', '', $content_type->getCategoryTitle()))); ?> "><span class="dropdown-menu-icon" ><?php echo $content_type->getIcon(); ?>
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 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; } }