Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare Endpoint for Checkins #1248

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion IdnoPlugins/Checkin/ContentType.php
Expand Up @@ -7,7 +7,8 @@ class ContentType extends \Idno\Common\ContentType {
public $title = 'Location';
public $category_title = 'Locations';
public $entity_class = 'IdnoPlugins\\Checkin\\Checkin';
public $indieWebContentType = array('checkin');

}

}
}
83 changes: 82 additions & 1 deletion IdnoPlugins/IndiePub/Pages/MicroPub/Endpoint.php
Expand Up @@ -72,6 +72,7 @@ function post()

// Get details
$type = $this->getInput('h', 'entry');
$type = $this->getInput('h');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line repeats the previous one.

$content = $this->getInput('content');
$name = $this->getInput('name');
$in_reply_to = $this->getInput('in-reply-to');
Expand All @@ -80,6 +81,10 @@ function post()
$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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please use spaces for indentation (4-space indent)


if ($type == 'entry') {
$type = 'note';
Expand All @@ -99,6 +104,16 @@ function post()
$type = 'article';
}

if ($type == 'checkin' ) {
$place_name = $this->getInput('place_name');
$location = $this->getInput('location');
$type = 'checkin';
$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 ($type == 'photo' && empty($name) && !empty($content)) {
$name = $content;
$content = '';
Expand All @@ -117,6 +132,24 @@ function post()
$category = trim($category);
if ($category) {
$content .= " #$category";
$categories = $this->getInput('category');
$location = $this->getInput('location');

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;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block seems to have migrated down from above (starting around line 81 in the old file)? maybe git made a mistake merging?

}
}
$title_words = explode(" ", $name);
Expand All @@ -128,6 +161,48 @@ function post()
}
}

// Get an appropriate plugin, given the content type
if ($contentType = ContentType::getRegisteredForIndieWebPostType($type)) {
if ($type == 'photo' && empty($name) && !empty($content)) {
$name = $content;
$content = '';
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a little confused what happened here; this partially duplicates code from line ~102


if (empty($name)) {
$type = 'note';
}
if (!empty($location) ) {
$place_name = $this->getInput('place_name');
$type = 'checkin';
$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($like_of)) {
$type = 'like';
}
if (!empty($repost_of)) {
$type = 'repost';
}
}
$getInput = array($type, $content, $name, $in_reply_to, $syndicate, $posse_link, $like_of, $repost_of, $categories, $location);
// 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()) {
Expand All @@ -151,6 +226,13 @@ function post()
$this->setInput('like-of', $like_of);
$this->setInput('repost-of', $repost_of);
$this->setInput('access', 'PUBLIC');
$this->setInput('lat', $lat);
$this->setInput('long', $long);
$this->setInput('user_address', "");
$this->setInput('placename',$place_name);
$this->setInput('long', $long);
$this->setInput('user_address', "");
$this->setInput('placename',$place_name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you've got these three lines twice.

if ($created = $this->getInput('published')) {
$this->setInput('created', $created);
}
Expand All @@ -160,7 +242,6 @@ function post()
} 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)) {
Expand Down