/** * 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; } }
/** * 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 video if ($new) { if (!empty($_FILES['video']['tmp_name'])) { if (true) { if ($video = \Idno\Entities\File::createFromFile($_FILES['video']['tmp_name'], $_FILES['video']['name'], $_FILES['video']['type'], true)) { $this->attachFile($video); } else { \Idno\Core\site()->session()->addMessage('Video wasn\'t attached.'); } } else { \Idno\Core\site()->session()->addMessage('This doesn\'t seem to be a video ..'); } } else { \Idno\Core\site()->session()->addMessage('We couldn\'t access your video. 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 video was successfully saved.'); 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; } 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; } } // This flag will tell us if it's safe to save the object later on if ($new) { $ok = false; } else { $ok = true; } // Get media if ($new) { // This is awful, but unfortunately, browsers can't be trusted to send the right mimetype. $ext = pathinfo($_FILES['media']['name'], PATHINFO_EXTENSION); if (!empty($ext)) { if (in_array($ext, array('mp4', 'mov', 'webm', 'ogg', 'mpeg', 'mp3', 'vorbis'))) { $media_file = $_FILES['media']; if ($media_file['type'] == 'application/octet-stream') { switch ($ext) { case 'mp4': $media_file['type'] = 'video/mp4'; break; case 'mov': $media_file['type'] = 'video/mov'; break; case 'webm': $media_file['type'] = 'video/webm'; break; case 'ogg': $media_file['type'] = 'audio/ogg'; break; case 'mp3': $media_file['type'] = 'audio/mpeg'; break; case 'mpeg': $media_file['type'] = 'video/mpeg'; break; case 'ogv': $media_file['type'] = 'audio/ogv'; break; } } $this->media_type = $media_file['type']; if ($media = \Idno\Entities\File::createFromFile($media_file['tmp_name'], $media_file['name'], $media_file['type'], true)) { $this->attachFile($media); $ok = true; } else { \Idno\Core\Idno::site()->session()->addErrorMessage('Media wasn\'t attached.'); } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('This doesn\'t seem to be a media file .. ' . $_FILES['media']['type']); } } else { \Idno\Core\Idno::site()->session()->addErrorMessage('We couldn\'t access your media. Please try again.'); return false; } } // If a media file wasn't attached, don't save the file. if (!$ok) { 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 deleteData() { if ($this->getAccess() == 'PUBLIC') { \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getDescription())); } }
function deleteData() { \Idno\Core\Webmention::pingMentions($this->getURL(), \Idno\Core\Idno::site()->template()->parseURLs($this->getTitle() . ' ' . $this->getDescription())); }
/** * 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; } }
/** * 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; } }