function post() { $this->gatekeeper(); // Logged-in users only $lat = $this->getInput('lat'); $long = $this->getInput('long'); if (!empty($lat) && !empty($long)) { echo json_encode(\IdnoPlugins\Checkin\Checkin::queryLatLong($lat, $long)); } }
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; } }