function post() { if (\Idno\Core\Idno::site()->session()->isLoggedOn()) { if (!empty($_FILES['file']['tmp_name'])) { if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) { exit; } if (\Idno\Entities\File::isImage($_FILES['file']['tmp_name'])) { $return = false; $file = false; if ($file = \Idno\Entities\File::createThumbnailFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], 1024)) { $return = true; $returnfile = new \stdClass(); $returnfile->file = ['_id' => $file]; $file = $returnfile; } else { if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) { $return = true; } } if ($return) { $t = \Idno\Core\Idno::site()->template(); $t->file = $file; echo $t->draw('file/picker/donejs'); exit; } } else { Idno::site()->session()->addErrorMessage("You can only upload images."); } } $this->forward($_SERVER['HTTP_REDIRECT']); } }
/** * Saves changes to this object based on user input * @return bool */ function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $this->title = \Idno\Core\site()->currentPage()->getInput('title'); $this->body = \Idno\Core\site()->currentPage()->getInput('body'); $this->tags = \Idno\Core\site()->currentPage()->getInput('tags'); $this->setAccess('PUBLIC'); if ($time = \Idno\Core\site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } // Get photo if ($new) { if (!empty($_FILES['photo']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) { if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) { $this->attachFile($photo); // Now get some smaller thumbnails, with the option to override sizes $sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => ['large' => 800, 'medium' => 400, 'small' => 200]))); foreach ($sizes->data()['sizes'] as $label => $size) { $filename = $_FILES['photo']['name']; // Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting. if ($_FILES['photo']['type'] != 'image/gif') { if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size)) { $varname = "thumbnail_{$label}"; $this->{$varname} = \Idno\Core\site()->config()->url . 'file/' . $thumbnail; $varname = "thumbnail_{$label}_id"; $this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/')); } } } } else { \Idno\Core\site()->session()->addMessage('Image wasn\'t attached.'); } } else { \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..'); } } else { \Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.'); return false; } } if ($this->save()) { if ($new) { $this->addToFeed(); } // Add it to the Activity Streams feed \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription())); return true; } else { return false; } }
/** * Saves changes to this object based on user input * @return bool */ function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $this->title = \Idno\Core\site()->currentPage()->getInput('title'); $this->body = \Idno\Core\site()->currentPage()->getInput('body'); $this->setAccess('PUBLIC'); // Get photo if ($new) { if (!empty($_FILES['photo']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) { if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true)) { $this->attachFile($photo); if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) { $this->thumbnail = \Idno\Core\site()->config()->url . 'file/' . $thumbnail; $this->thumbnail_id = substr($thumbnail, 0, strpos($thumbnail, '/')); } } else { \Idno\Core\site()->session()->addMessage('Image wasn\'t attached.'); } } else { \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be an image ..'); } } else { \Idno\Core\site()->session()->addMessage('We couldn\'t access your image. Please try again.'); return false; } } if ($this->save()) { if ($new) { $this->addToFeed(); } // Add it to the Activity Streams feed \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription())); \Idno\Core\site()->session()->addMessage('Your photo was successfully saved.'); return true; } else { return false; } }
function postContent() { $this->gatekeeper(); // Logged-in only please $user = \Idno\Core\site()->session()->currentUser(); $name = $this->getInput('name'); //$handle = $this->getInput('handle'); $email = $this->getInput('email'); $password = $this->getInput('password'); $password2 = $this->getInput('password2'); if (!empty($name)) { $user->setTitle($name); } if (!empty($email) && $email != $user->email && filter_var($email, FILTER_VALIDATE_EMAIL)) { if (!\Idno\Entities\User::getByEmail($email)) { $user->email = $email; } else { \Idno\Core\site()->session()->addMessage('Someone is already using ' . $email . ' as their email address.', 'alert-error'); } } if (!empty($password) && $password == $password2) { $user->setPassword($password); } if (!empty($_FILES['avatar'])) { if (in_array($_FILES['avatar']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) { if (getimagesize($_FILES['avatar']['tmp_name'])) { if ($icon = \Idno\Entities\File::createThumbnailFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'], 300)) { $user->icon = (string) $icon; } else { if ($icon = \Idno\Entities\File::createFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'])) { $user->icon = (string) $icon; } } } } } if ($user->save()) { \Idno\Core\site()->session()->addMessage("Your details were saved."); } $this->forward($_SERVER['HTTP_REFERER']); }
/** * Recursive helper function for parsing webmentions. * * @param $item * @param $mentions * @return array */ function addWebmentionItem($item, $mentions, $source, $target, $title = '') { if (!empty($item['properties']['author'])) { foreach ($item['properties']['author'] as $author) { if (!empty($author['type'])) { foreach ($author['type'] as $type) { if ($type == 'h-card') { if (!empty($author['properties']['name'])) { $mentions['owner']['name'] = $author['properties']['name'][0]; } if (!empty($author['properties']['url'])) { $mentions['owner']['url'] = $author['properties']['url'][0]; } if (!empty($author['properties']['photo'])) { //$mentions['owner']['photo'] = $author['properties']['photo'][0]; $tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar'); file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($author['properties']['photo'][0])); $name = md5($author['properties']['url'][0]); // TODO: Don't update the cache image for every webmention if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) { $mentions['owner']['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } else { if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) { $mentions['owner']['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } } unlink($tmpfname); } } } } } } if (!empty($item['type'])) { if (in_array('h-entry', $item['type'])) { $mention = array(); if (!empty($item['properties'])) { if (!empty($item['properties']['content'])) { $mention['content'] = ''; if (is_array($item['properties']['content'])) { foreach ($item['properties']['content'] as $content) { if (!empty($content['value'])) { $parsed_content = \Idno\Core\Idno::site()->template()->sanitize_html($content['value']); if (!substr_count($mention['content'], $parsed_content)) { $mention['content'] .= $parsed_content; } } } } else { $mention['content'] = $item['properties']['content']; } } else { if (!empty($item['properties']['summary'])) { if (is_array($item['properties']['summary'])) { $mention['content'] = \Idno\Core\Idno::site()->template()->sanitize_html(implode(' ', $item['properties']['summary'])); } else { $mention['content'] = $item['properties']['summary']; } } else { if (!empty($item['properties']['name'])) { if (is_array($item['properties']['name'])) { $mention['content'] = \Idno\Core\Idno::site()->template()->sanitize_html(implode(' ', $item['properties']['name'])); } else { $mention['content'] = $item['properties']['name']; } } } } if (!empty($item['properties']['published'])) { if (is_array($item['properties']['published'])) { $mention['created'] = @strtotime(array_shift(array_pop($item['properties']['published']))); } else { $mention['created'] = @strtotime($item['properties']['content']); } } if (empty($mention['created'])) { $mention['created'] = time(); } if (!empty($item['properties']['url'])) { if (!empty($item['properties']['uid'])) { $mention['url'] = array_intersect($item['properties']['uid'], $item['properties']['url']); } if (empty($mention['url'])) { $mention['url'] = $item['properties']['url']; } } if (!empty($item['properties']['like']) && is_array($item['properties']['like'])) { if (in_array($target, static::getStringURLs($item['properties']['like']))) { $mention['type'] = 'like'; } } if (!empty($item['properties']['like-of']) && is_array($item['properties']['like-of'])) { if (in_array($target, static::getStringURLs($item['properties']['like-of']))) { $mention['type'] = 'like'; } } if (!empty($item['properties']['rsvp']) && is_array($item['properties']['rsvp'])) { $mention['type'] = 'rsvp'; $mention['content'] = implode(' ', $item['properties']['rsvp']); } foreach (array('share', 'repost', 'repost-of') as $verb) { if (!empty($item['properties'][$verb]) && is_array($item['properties'][$verb])) { if (in_array($target, static::getStringURLs($item['properties'][$verb]))) { $mention['type'] = 'share'; } } } if (!empty($item['properties']['in-reply-to']) && is_array($item['properties']['in-reply-to'])) { if (in_array($target, static::getStringURLs($item['properties']['in-reply-to']))) { $mention['type'] = 'reply'; } } if (empty($mention['type'])) { $mention['type'] = 'mention'; } } if (empty($mention['content'])) { $mention['content'] = ''; } $mention['title'] = $title; if (!empty($mention['type'])) { $mentions['mentions'][] = $mention; } } } if (in_array('h-feed', $item['type'])) { if (!empty($item['children'])) { foreach ($item['children'] as $child) { $mentions = $this->addWebmentionItem($child, $mentions, $source, $target, $title); } } } return $mentions; }
/** * Save form input * @param \Idno\Common\Page $page * @return bool|\Idno\Common\false|\Idno\Common\true|\Idno\Core\false|\Idno\Core\MongoID|null */ function saveDataFromInput() { if (!$this->canEdit()) { return false; } $profile = \Idno\Core\Idno::site()->currentPage()->getInput('profile'); if (!empty($profile)) { $this->profile = $profile; } if ($name = \Idno\Core\Idno::site()->currentPage()->getInput('name')) { $this->setName($name); } if (!empty($_FILES['avatar'])) { if (in_array($_FILES['avatar']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) { if (getimagesize($_FILES['avatar']['tmp_name'])) { if ($icon = \Idno\Entities\File::createThumbnailFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'], 300, true)) { $this->icon = (string) $icon; } else { if ($icon = \Idno\Entities\File::createFromFile($_FILES['avatar']['tmp_name'], $_FILES['avatar']['name'])) { $this->icon = (string) $icon; } } } } } return $this->save(); }
/** * Saves changes to this object based on user input * @return bool */ function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } if ($new) { if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) { return false; } } $this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title'); $this->body = \Idno\Core\Idno::site()->currentPage()->getInput('body'); $this->tags = \Idno\Core\Idno::site()->currentPage()->getInput('tags'); $access = \Idno\Core\Idno::site()->currentPage()->getInput('access'); $this->setAccess($access); if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } // Get photo if ($new) { if (!empty($_FILES['photo']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name']) || \Idno\Entities\File::isSVG($_FILES['photo']['tmp_name'], $_FILES['photo']['name'])) { // Extract exif data so we can rotate if (is_callable('exif_read_data') && $_FILES['photo']['type'] == 'image/jpeg') { try { if (function_exists('exif_read_data')) { if ($exif = exif_read_data($_FILES['photo']['tmp_name'])) { $this->exif = base64_encode(serialize($exif)); // Yes, this is rough, but exif contains binary data that can not be saved in mongo } } } catch (\Exception $e) { $exif = false; } } else { $exif = false; } if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true, true)) { $this->attachFile($photo); // Now get some smaller thumbnails, with the option to override sizes $sizes = \Idno\Core\Idno::site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => array('large' => 800, 'medium' => 400, 'small' => 200)))); $eventdata = $sizes->data(); foreach ($eventdata['sizes'] as $label => $size) { $filename = $_FILES['photo']['name']; // Experiment: let's not save thumbnails for GIFs, in order to enable animated GIF posting. if ($_FILES['photo']['type'] != 'image/gif') { if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size, false)) { $varname = "thumbnail_{$label}"; $this->{$varname} = \Idno\Core\Idno::site()->config()->url . 'file/' . $thumbnail; $varname = "thumbnail_{$label}_id"; $this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/')); } } } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('Image wasn\'t attached.'); } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('This doesn\'t seem to be an image ..'); } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('We couldn\'t access your image. Please try again.'); return false; } } if ($this->save($new)) { \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription())); return true; } else { return false; } }
/** * Retrieve a user's icon from a given homepage * @param $content The content of the page * @param $url The URL of the page * @return $icon_url */ static function getIconFromWebsiteContent($content, $url) { if ($mf2 = self::parseContent($content, $url)) { $mf2 = (array) $mf2; foreach ($mf2['items'] as $item) { // Figure out what kind of Microformats 2 item we have if (!empty($item['type']) && is_array($item['type'])) { foreach ($item['type'] as $type) { switch ($type) { case 'h-card': if (!empty($item['properties'])) { if (!empty($item['properties']['name'])) { $mentions['owner']['name'] = $item['properties']['name'][0]; } if (!empty($item['properties']['url'])) { $mentions['owner']['url'] = $item['properties']['url'][0]; } if (!empty($item['properties']['photo'])) { //$mentions['owner']['photo'] = $item['properties']['photo'][0]; $tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar'); file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($item['properties']['photo'][0])); $name = md5($item['properties']['url'][0]); // TODO: Don't update the cache image for every webmention if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) { return \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } else { if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) { return \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } } unlink($tmpfname); } } break; } } } } } return false; }
private function parseHCard($hcard) { $owner = []; if (!empty($hcard['properties']['name'])) { $owner['name'] = $hcard['properties']['name'][0]; } if (!empty($hcard['properties']['url'])) { $owner['url'] = $hcard['properties']['url'][0]; } if (!empty($hcard['properties']['photo'])) { //$owner['photo'] = $hcard['properties']['photo'][0]; $tmpfname = tempnam(sys_get_temp_dir(), 'webmention_avatar'); file_put_contents($tmpfname, \Idno\Core\Webservice::file_get_contents($hcard['properties']['photo'][0])); $name = md5($hcard['properties']['url'][0]); // TODO: Don't update the cache image for every webmention if ($icon = \Idno\Entities\File::createThumbnailFromFile($tmpfname, $name, 300)) { $owner['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } else { if ($icon = \Idno\Entities\File::createFromFile($tmpfname, $name)) { $owner['photo'] = \Idno\Core\Idno::site()->config()->url . 'file/' . (string) $icon; } } unlink($tmpfname); } return $owner; }
function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $body = \Idno\Core\site()->currentPage()->getInput('body'); if (!empty($body)) { $this->body = $body; $this->title = \Idno\Core\site()->currentPage()->getInput('title'); $this->rating = \Idno\Core\site()->currentPage()->getInput('rating'); $this->productName = \Idno\Core\site()->currentPage()->getInput('productName'); $this->productCategory = \Idno\Core\site()->currentPage()->getInput('productCategory'); $this->productLink = \Idno\Core\site()->currentPage()->getInput('productLink'); $access = \Idno\Core\site()->currentPage()->getInput('access'); $this->setAccess($access); if ($time = \Idno\Core\site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } if ($new) { if (!empty($_FILES['photo']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['photo']['tmp_name'])) { // Extract exif data so we can rotate if (is_callable('exif_read_data') && $_FILES['photo']['type'] == 'image/jpeg') { try { if (function_exists('exif_read_data')) { if ($exif = exif_read_data($_FILES['photo']['tmp_name'])) { $this->exif = base64_encode(serialize($exif)); // Yes, this is rough, but exif contains binary data that can not be saved in mongo } } } catch (\Exception $e) { $exif = false; } } else { $exif = false; } if ($photo = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type'], true, true)) { $this->attachFile($photo); // Now get some smaller thumbnails, with the option to override sizes $sizes = \Idno\Core\site()->events()->dispatch('photo/thumbnail/getsizes', new \Idno\Core\Event(array('sizes' => array('large' => 800, 'medium' => 400, 'small' => 200)))); $eventdata = $sizes->data(); foreach ($eventdata['sizes'] as $label => $size) { $filename = $_FILES['photo']['name']; if ($thumbnail = \Idno\Entities\File::createThumbnailFromFile($_FILES['photo']['tmp_name'], "{$filename}_{$label}", $size, false)) { $varname = "thumbnail_{$label}"; $this->{$varname} = \Idno\Core\site()->config()->url . 'file/' . $thumbnail; $varname = "thumbnail_{$label}_id"; $this->{$varname} = substr($thumbnail, 0, strpos($thumbnail, '/')); } } } } else { \Idno\Core\site()->session()->addErrorMessage('This doesn\'t seem to be an image ..'); } } } if ($this->save($new)) { $autosave = new Autosave(); $autosave->clearContext('review'); \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription())); return true; } } else { \Idno\Core\site()->session()->addErrorMessage('You can\'t save an empty entry.'); } return false; }