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; } }
function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } if ($new) { if (!\Idno\Core\Idno::site()->triggerEvent("file/upload", [], true)) { return false; } } $body = \Idno\Core\Idno::site()->currentPage()->getInput('body'); if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) { $this->body = $body; $this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title'); $this->description = \Idno\Core\Idno::site()->currentPage()->getInput('description'); if ($time = \Idno\Core\Idno::site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } if (!empty($_FILES['comic']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) { if ($size = getimagesize($_FILES['comic']['tmp_name'])) { $this->width = $size[0]; $this->height = $size[1]; } if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) { $this->attachFile($comic); } } } $this->setAccess(\Idno\Core\Idno::site()->currentPage()->getInput('access', 'PUBLIC')); if ($this->save($new)) { if ($this->getAccess() == 'PUBLIC') { \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription())); } return true; } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('You can\'t save an empty comic.'); } 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 saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $body = \Idno\Core\site()->currentPage()->getInput('body'); if (!empty($_FILES['comic']['tmp_name']) || !empty($this->_id)) { $this->body = $body; $this->title = \Idno\Core\site()->currentPage()->getInput('title'); $this->description = \Idno\Core\site()->currentPage()->getInput('description'); if ($time = \Idno\Core\site()->currentPage()->getInput('created')) { if ($time = strtotime($time)) { $this->created = $time; } } if (!empty($_FILES['comic']['tmp_name'])) { if (\Idno\Entities\File::isImage($_FILES['comic']['tmp_name'])) { if ($size = getimagesize($_FILES['comic']['tmp_name'])) { $this->width = $size[0]; $this->height = $size[1]; } if ($comic = \Idno\Entities\File::createFromFile($_FILES['comic']['tmp_name'], $_FILES['comic']['name'], $_FILES['comic']['type'], true)) { $this->attachFile($comic); } } } $this->setAccess('PUBLIC'); if ($this->save()) { if ($new) { // Add it to the Activity Streams feed $this->addToFeed(); } \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\site()->template()->parseURLs($this->getDescription())); return true; } } else { \Idno\Core\site()->session()->addMessage('You can\'t save an empty comic.'); } return false; }
/** * 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; } }
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; }