function getContent() { $this->createGatekeeper(); // This functionality is for logged-in users only // Are we loading an entity? if (!empty($this->arguments)) { $object = \IdnoPlugins\Text\Entry::getByID($this->arguments[0]); } else { $object = new \IdnoPlugins\Text\Entry(); $autosave = new \Idno\Core\Autosave(); foreach (array('title', 'body') as $field) { $object->{$field} = $autosave->getValue('entry', $field); } } if ($owner = $object->getOwner()) { $this->setOwner($owner); } $t = \Idno\Core\Idno::site()->template(); $edit_body = $t->__(array('object' => $object))->draw('entity/Entry/edit'); $body = $t->__(['body' => $edit_body])->draw('entity/editwrapper'); if (empty($object->_id)) { $title = 'Write an entry'; } else { $title = 'Edit entry'; } if (!empty($this->xhr)) { echo $body; } else { $t->__(array('body' => $body, 'title' => $title))->drawPage(); } }
function saveDataFromInput() { if (empty($this->_id)) { $new = true; } else { $new = false; } $body = \Idno\Core\Idno::site()->currentPage()->getInput('body'); if (!empty($body)) { $this->body = $body; $this->title = \Idno\Core\Idno::site()->currentPage()->getInput('title'); $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; } } if ($this->publish($new)) { $autosave = new Autosave(); $autosave->clearContext('entry'); if ($this->getAccess() == 'PUBLIC') { \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription())); } return true; } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('You can\'t save an empty entry.'); } 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; }