function registerEventHooks() { \Idno\Core\site()->syndication()->registerService('soundcloud', function () { return $this->hasSoundcloud(); }, array('media')); \Idno\Core\site()->addEventHook('user/auth/success', function (\Idno\Core\Event $event) { if ($this->hasSoundcloud()) { if (is_array(\Idno\Core\site()->session()->currentUser()->soundcloud)) { foreach (\Idno\Core\site()->session()->currentUser()->soundcloud as $username => $details) { if (!in_array($username, ['username', 'access_token'])) { \Idno\Core\site()->syndication()->registerServiceAccount('soundcloud', $username, $username); } } } } }); // Push "media" to Soundcloud \Idno\Core\site()->addEventHook('post/media/soundcloud', function (\Idno\Core\Event $event) { $eventdata = $event->data(); $object = $eventdata['object']; if ($attachments = $object->getAttachments()) { foreach ($attachments as $attachment) { if ($this->hasSoundcloud()) { if (!empty($eventdata['syndication_account'])) { $soundcloudAPI = $this->connect($eventdata['syndication_account']); $user_details = \Idno\Core\site()->session()->currentUser()->soundcloud[$eventdata['syndication_account']]; if (!empty($user_details['username'])) { $name = $user_details['username']; } } else { $soundcloudAPI = $this->connect(); $user_details = \Idno\Core\site()->session()->currentUser()->soundcloud['access_token']; } if (empty($name)) { $name = 'SoundCloud'; } if ($soundcloudAPI && !empty($user_details)) { $soundcloudAPI->setAccessToken($user_details['access_token']); if ($bytes = \Idno\Entities\File::getFileDataFromAttachment($attachment)) { $media = ''; $filename = tempnam(sys_get_temp_dir(), 'knownsoundcloud') . '.' . pathinfo($attachment['url'], PATHINFO_EXTENSION); file_put_contents($filename, $bytes); if (version_compare(phpversion(), '5.5', '>=')) { $media = new \CURLFile($filename); if (!empty($attachment['mime_type'])) { $media->setMimeType($attachment['mime_type']); } if (!empty($attachment['filename'])) { $media->setPostFilename($attachment['filename']); } } else { $media .= "@{$filename}"; //;type=" . $attachment['mime_type'] . ';filename=' . $attachment['filename']; } } $message = strip_tags($object->getDescription()); $message .= "\n\nOriginal: " . $object->getURL(); try { $track = json_decode($soundcloudAPI->post('tracks', array('track[title]' => $object->getTitle(), 'track[asset_data]' => $media, 'track[description]' => $message))); if (!empty($track->permalink_url)) { $result['id'] = $track->id; $object->setPosseLink('soundcloud', $track->permalink_url, $name); $object->save(); } } catch (\Exception $e) { \Idno\Core\site()->session()->addMessage('Could not post sound to SoundCloud: ' . $e->getMessage()); } @unlink($filename); } } } } }); }
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']); } }
function getContent() { if (!empty($this->arguments[0])) { $object = \Idno\Entities\File::getByID($this->arguments[0]); } if (empty($object)) { $this->forward(); } // TODO: 404 $headers = apache_request_headers(); if (isset($headers['If-Modified-Since'])) { if (strtotime($headers['If-Modified-Since']) < time() - 600) { header('HTTP/1.1 304 Not Modified'); exit; } } header("Pragma: public"); header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 365)); // Cache files for a year! if (!empty($object->file['mime_type'])) { header('Content-type: ' . $object->file['mime_type']); } else { header('Content-type: application/data'); } echo $object->getBytes(); }
/** * 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 getContent() { // Check modified ts if ($cache = \Idno\Core\Idno::site()->cache()) { if ($modifiedts = $cache->load("{$this->arguments[0]}_modified_ts")) { $this->lastModifiedGatekeeper($modifiedts); // Set 304 and exit if we've not modified this object } } if (!empty($this->arguments[0])) { $object = \Idno\Entities\File::getByID($this->arguments[0]); } if (empty($object)) { $this->noContent(); } session_write_close(); // Close the session early //header("Pragma: public"); // Determine uploaded timestamp if ($object instanceof \MongoGridFSFile) { $upload_ts = $object->file['uploadDate']->sec; } else { if (!empty($object->updated)) { $upload_ts = $object->updated; } else { if (!empty($object->created)) { $upload_ts = $object->created; } else { $upload_ts = time(); } } } header("Pragma: public"); header("Cache-Control: public"); header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30)); // Cache files for 30 days! $this->setLastModifiedHeader($upload_ts); if ($cache = \Idno\Core\Idno::site()->cache()) { $cache->store("{$this->arguments[0]}_modified_ts", $upload_ts); } if (!empty($object->file['mime_type'])) { header('Content-type: ' . $object->file['mime_type']); } else { header('Content-type: application/data'); } //header('Accept-Ranges: bytes'); //header('Content-Length: ' . filesize($object->getSize())); if (is_callable(array($object, 'passThroughBytes'))) { $object->passThroughBytes(); } else { if ($stream = $object->getResource()) { while (!feof($stream)) { echo fread($stream, 8192); } } } }
function getContent() { if (!empty($this->arguments[0])) { $object = \Idno\Entities\File::getByID($this->arguments[0]); } if (empty($object)) { $this->forward(); } // TODO: 404 session_write_close(); // Close the session early //header("Pragma: public"); // Determine uploaded timestamp if ($object instanceof \MongoGridFSFile) { $upload_ts = $object->file['uploadDate']->sec; } else { if (!empty($object->updated)) { $upload_ts = $object->updated; } else { if (!empty($object->created)) { $upload_ts = $object->created; } else { $upload_ts = time(); } } } header("Pragma: public"); header("Cache-Control: public"); header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30)); // Cache files for 30 days! $this->setLastModifiedHeader($upload_ts); if (!empty($object->file['mime_type'])) { header('Content-type: ' . $object->file['mime_type']); } else { header('Content-type: application/data'); } //header('Accept-Ranges: bytes'); //header('Content-Length: ' . filesize($object->getSize())); $headers = $this->getallheaders(); if (isset($headers['If-Modified-Since'])) { if (strtotime($headers['If-Modified-Since']) <= $upload_ts) { //> time() - (86400 * 30)) { header('HTTP/1.1 304 Not Modified'); exit; } } if (is_callable(array($object, 'passThroughBytes'))) { $object->passThroughBytes(); } else { if ($stream = $object->getResource()) { while (!feof($stream)) { echo fread($stream, 8192); } } } }
function postContent() { $this->adminGatekeeper(); // Flag that a site export has been requested \Idno\Core\Idno::site()->config()->export_last_requested = time(); \Idno\Core\Idno::site()->config()->export_in_progress = 1; \Idno\Core\Idno::site()->config()->save(); $this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/export/', false); ignore_user_abort(true); // This is dangerous, but we need export to continue session_write_close(); header('Connection: close'); header('Content-length: ' . (string) ob_get_length()); @ob_end_flush(); // Return output to the browser @ob_end_clean(); @flush(); sleep(10); // Pause set_time_limit(0); // Eliminate time limit - this could take a while // Remove the previous export file if (!empty(\Idno\Core\Idno::site()->config()->export_file_id)) { if ($file = File::getByID(\Idno\Core\Idno::site()->config()->export_file_id)) { $file->remove(); \Idno\Core\Idno::site()->config()->export_file_id = false; \Idno\Core\Idno::site()->config()->export_filename = false; \Idno\Core\Idno::site()->config()->save(); } } if ($path = Migration::createCompressedArchive()) { $filename = \Idno\Core\Idno::site()->config()->host . '.zip'; /* header('Content-disposition: attachment;filename=' . $filename); if ($fp = fopen($path, 'r')) { while ($content = fread($fp, 4096)) { echo $content; } } fclose($fp);*/ if ($file = File::createFromFile($path, $filename)) { @unlink($path); \Idno\Core\Idno::site()->config()->export_filename = $filename; \Idno\Core\Idno::site()->config()->export_file_id = $file; \Idno\Core\Idno::site()->config()->export_in_progress = 0; \Idno\Core\Idno::site()->config()->save(); $mail = new Email(); $mail->setHTMLBodyFromTemplate('admin/export'); $mail->setTextBodyFromTemplate('admin/export'); $mail->addTo(\Idno\Core\Idno::site()->session()->currentUser()->email); $mail->setSubject("Your data export is ready"); $mail->send(); } exit; } }
function post() { if (\Idno\Core\site()->session()->isLoggedOn()) { if (!empty($_FILES['file']['tmp_name'])) { if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) { echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']); error_log(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']); } } } }
function post() { if (\Idno\Core\site()->session()->isLoggedOn()) { if (!empty($_FILES['file']['tmp_name'])) { if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) { exit; } if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true, true)) { echo json_encode(\Idno\Core\site()->config()->url . 'file/' . $file->file['_id']); } } } }
function postContent() { $this->adminGatekeeper(); // Admins only if ($profile_user = $this->getInput('profile_user')) { \Idno\Core\Idno::site()->config->config['cherwell']['profile_user'] = $profile_user; } if (!empty($_FILES['background']) && $this->getInput('action') != 'clear') { if (in_array($_FILES['background']['type'], array('image/png', 'image/jpg', 'image/jpeg', 'image/gif'))) { if (getimagesize($_FILES['background']['tmp_name'])) { if ($background = \Idno\Entities\File::createFromFile($_FILES['background']['tmp_name'], $_FILES['background']['name'])) { // Remove previous bg if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) { if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) { if (is_callable([$file, 'delete'])) { // TODO: really need some abstraction here. $file->delete(); } else { if (is_callable([$file, 'remove'])) { $file->remove(); } } } } \Idno\Core\Idno::site()->config->config['cherwell']['bg_id'] = $background; $background = \Idno\Core\Idno::site()->config()->getDisplayURL() . 'file/' . $background; \Idno\Core\Idno::site()->config->config['cherwell']['bg'] = $background; } } } } else { // Remove previous bg if (!empty(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) { if ($file = File::getByID(\Idno\Core\Idno::site()->config()->cherwell['bg_id'])) { if (is_callable([$file, 'delete'])) { $file->delete(); } else { if (is_callable([$file, 'remove'])) { $file->remove(); } } } } \Idno\Core\Idno::site()->config->cherwell = []; } \Idno\Core\Idno::site()->config->save(); $this->forward(\Idno\Core\Idno::site()->config()->getDisplayURL() . 'admin/cherwell/'); }
function post() { if (\Idno\Core\site()->session()->isLoggedOn()) { if (!empty($_FILES['file']['tmp_name'])) { if (!\Idno\Core\site()->triggerEvent("file/upload", [], true)) { exit; } if ($file = \Idno\Entities\File::createFromFile($_FILES['file']['tmp_name'], $_FILES['file']['name'], $_FILES['file']['type'], true)) { $t = \Idno\Core\site()->template(); $t->file = $file; echo $t->draw('file/picker/donejs'); exit; } } } }
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; }
function getContent() { if (!empty($this->arguments[0])) { $object = \Idno\Entities\File::getByID($this->arguments[0]); } if (empty($object)) { $this->forward(); } // TODO: 404 if (!function_exists('getallheaders')) { function getallheaders() { $headers = ''; foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value; } } return $headers; } } $headers = getallheaders(); if (isset($headers['If-Modified-Since'])) { if (strtotime($headers['If-Modified-Since']) < time() - 600) { header('HTTP/1.1 304 Not Modified'); exit; } } //header("Pragma: public"); header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30)); // Cache files for 30 days! if (!empty($object->file['mime_type'])) { header('Content-type: ' . $object->file['mime_type']); } else { header('Content-type: application/data'); } //header('Accept-Ranges: bytes'); //header('Content-Length: ' . filesize($object->getSize())); if (is_callable([$object, 'passThroughBytes'])) { $object->passThroughBytes(); } else { echo $object->getBytes(); } }
/** * 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; }
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']); }
/** * 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; } }
function post() { $this->gatekeeper(); // If we're here, we're authorized \Idno\Core\Idno::site()->triggerEvent('indiepub/post/start', ['page' => $this]); // Get details $type = $this->getInput('h', 'entry'); $content = $this->getInput('content'); $name = $this->getInput('name'); $in_reply_to = $this->getInput('in-reply-to'); $syndicate = $this->getInput('mp-syndicate-to', $this->getInput('syndicate-to')); $posse_link = $this->getInput('syndication'); $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; } if ($type == 'entry') { $type = 'note'; if (!empty($_FILES['photo'])) { $type = 'photo'; } else { if ($photo_url = $this->getInput('photo')) { $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; } } else { if (!empty($name)) { $type = 'article'; } } } } if ($type == 'checkin') { $place_name = $this->getInput('place_name'); $location = $this->getInput('location'); $photo = $this->getInput('photo'); $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($_FILES['photo'])) { $id = \Idno\Entities\File::createFromFile($_FILES['photo']['tmp_name'], $_FILES['photo']['name'], $_FILES['photo']['type']); $photo = \Idno\Core\Idno::site()->config()->url . 'file/' . $id; } if (!empty($photo)) { $htmlPhoto = '<p><img style="display: block; margin-left: auto; margin-right: auto;" src="' . $photo . '" alt="' . $place_name . '" /></p>'; } } if ($type == 'photo' && empty($name) && !empty($content)) { $name = $content; $content = ''; } if (!empty($like_of)) { $type = 'like'; } if (!empty($repost_of)) { $type = 'repost'; } // setting all categories as hashtags into content field if (is_array($categories)) { $hashtags = ""; foreach ($categories as $category) { $category = trim($category); if ($category) { if (str_word_count($category) > 1) { $category = str_replace("'", " ", $category); $category = ucwords($category); $category = str_replace(" ", "", $category); } $hashtags .= " #{$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()) { if (is_array($content)) { $content_value = ''; if (!empty($content['html'])) { $content_value = $content['html']; } else { if (!empty($content['value'])) { $content_value = $content['value']; } } } else { $content_value = $content; } if (!empty($posse_link)) { $posse_service = parse_url($posse_link, PHP_URL_HOST); $entity->setPosseLink(str_replace('.com', '', $posse_service), $posse_link, '', ''); } $hashtags = empty($hashtags) ? "" : "<p>" . $hashtags . "</p>"; $htmlPhoto = empty($htmlPhoto) ? "" : "<p>" . $htmlPhoto . "</p>"; $this->setInput('title', $name); $this->setInput('body', $htmlPhoto . $content_value . $hashtags); $this->setInput('inreplyto', $in_reply_to); $this->setInput('like-of', $like_of); $this->setInput('repost-of', $repost_of); $this->setInput('access', 'PUBLIC'); if ($type == 'checkin') { $this->setInput('lat', $lat); $this->setInput('long', $long); $this->setInput('user_address', $user_address); $this->setInput('placename', $place_name); } if ($created = $this->getInput('published')) { $this->setInput('created', $created); } if (!empty($syndicate)) { if (is_array($syndicate)) { $syndication = $syndicate; } else { $syndication = array(trim(str_replace('.com', '', $syndicate))); } \Idno\Core\Idno::site()->logging()->info("Setting syndication: {$syndication}"); $this->setInput('syndication', $syndication); } if ($entity->saveDataFromInput()) { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/success', ['page' => $this, 'object' => $entity]); $this->setResponse(201); header('Location: ' . $entity->getURL()); exit; } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't create {$type}"; exit; } } } else { \Idno\Core\Idno::site()->triggerEvent('indiepub/post/failure', ['page' => $this]); $this->setResponse(500); echo "Couldn't find content type {$type}"; exit; } }
/** * 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; } }
/** * 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(); }
/** * 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; }
/** * Given a path to an image on disk, generates and saves a thumbnail with maximum dimension $max_dimension. * @param string $file_path Path to the file. * @param string $filename Filename that the file should have on download. * @param int $max_dimension The maximum number of pixels the thumbnail image should be along its longest side. * @param bool $square If this is set to true, the thumbnail will be made square. * @return bool|id */ public static function createThumbnailFromFile($file_path, $filename, $max_dimension = 800, $square = false) { $thumbnail = false; if ($photo_information = getimagesize($file_path)) { if ($photo_information[0] > $max_dimension || $photo_information[1] > $max_dimension) { switch ($photo_information['mime']) { case 'image/jpeg': $image = imagecreatefromjpeg($file_path); break; case 'image/png': $image = imagecreatefrompng($file_path); $background = imagecolorallocatealpha($image, 0, 0, 0, 127); imagecolortransparent($image, $background); break; case 'image/gif': $image = imagecreatefromgif($file_path); $background = imagecolorallocatealpha($image, 0, 0, 0, 127); imagecolortransparent($image, $background); break; } if (!empty($image)) { if ($photo_information[0] > $photo_information[1]) { $width = $max_dimension; $height = round($photo_information[1] * ($max_dimension / $photo_information[0])); } else { $height = $max_dimension; $width = round($photo_information[0] * ($max_dimension / $photo_information[1])); } if ($square) { if ($width > $height) { $new_height = $max_dimension; $new_width = $max_dimension; $original_height = $photo_information[1]; $original_width = $photo_information[1]; $offset_x = round(($photo_information[0] - $photo_information[1]) / 2); $offset_y = 0; } else { $new_height = $max_dimension; $new_width = $max_dimension; $original_height = $photo_information[0]; $original_width = $photo_information[0]; $offset_x = 0; $offset_y = round(($photo_information[1] - $photo_information[0]) / 2); } } else { $new_height = $height; $new_width = $width; $original_height = $photo_information[1]; $original_width = $photo_information[0]; $offset_x = 0; $offset_y = 0; } $image_copy = imagecreatetruecolor($new_width, $new_height); imagealphablending($image_copy, false); imagesavealpha($image_copy, true); imagecopyresampled($image_copy, $image, 0, 0, $offset_x, $offset_y, $new_width, $new_height, $original_width, $original_height); $tmp_dir = dirname($file_path); switch ($photo_information['mime']) { case 'image/jpeg': imagejpeg($image_copy, $tmp_dir . '/' . $filename . '.jpg', 85); $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.jpg', "thumb_{$max_dimension}.jpg", 'image/jpeg') . '/thumb.jpg'; @unlink($tmp_dir . '/' . $filename . '.jpg'); break; case 'image/png': imagepng($image_copy, $tmp_dir . '/' . $filename . '.png'); $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.png', "thumb_{$max_dimension}.png", 'image/png') . '/thumb.png'; @unlink($tmp_dir . '/' . $filename . '.png'); break; case 'image/gif': imagegif($image_copy, $tmp_dir . '/' . $filename . '.gif'); $thumbnail = \Idno\Entities\File::createFromFile($tmp_dir . '/' . $filename . '.gif', "thumb_{$max_dimension}.gif", 'image/gif') . '/thumb.gif'; @unlink($tmp_dir . '/' . $filename . '.gif'); break; } } } else { } return $thumbnail; } return false; }
static function importImagesFromBodyHTML($body, $src_url) { $doc = new \DOMDocument(); if (@$doc->loadHTML($body)) { if ($images = $doc->getElementsByTagName('img')) { foreach ($images as $image) { $src = $image->getAttribute('src'); if (substr_count($src, $src_url)) { $dir = site()->config()->getTempDir(); $name = md5($src); $newname = $dir . $name . basename($src); if (@file_put_contents($newname, fopen($src, 'r'))) { switch (strtolower(pathinfo($src, PATHINFO_EXTENSION))) { case 'jpg': case 'jpeg': $mime = 'image/jpg'; break; case 'gif': $mime = 'image/gif'; break; case 'png': $mime = 'image/png'; break; default: $mime = 'application/octet-stream'; } if ($file = File::createFromFile($newname, basename($src), $mime, true)) { $newsrc = \Idno\Core\site()->config()->getURL() . 'file/' . $file->file['_id']; $body = str_replace($src, $newsrc, $body); @unlink($newname); } } } } } } }
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 getContent() { // Check modified ts if ($cache = \Idno\Core\Idno::site()->cache()) { if ($modifiedts = $cache->load("{$this->arguments[0]}_modified_ts")) { $this->lastModifiedGatekeeper($modifiedts); // Set 304 and exit if we've not modified this object } } if (!empty($this->arguments[0])) { $object = \Idno\Entities\File::getByID($this->arguments[0]); } if (empty($object)) { $this->noContent(); } session_write_close(); // Close the session early //header("Pragma: public"); // Determine uploaded timestamp if ($object instanceof \MongoGridFSFile) { $upload_ts = $object->file['uploadDate']->sec; } else { if (!empty($object->updated)) { $upload_ts = $object->updated; } else { if (!empty($object->created)) { $upload_ts = $object->created; } else { $upload_ts = time(); } } } header("Pragma: public"); header("Cache-Control: public"); header('Expires: ' . date(\DateTime::RFC1123, time() + 86400 * 30)); // Cache files for 30 days! $this->setLastModifiedHeader($upload_ts); if ($cache = \Idno\Core\Idno::site()->cache()) { $cache->store("{$this->arguments[0]}_modified_ts", $upload_ts); } if (!empty($object->file['mime_type'])) { header('Content-type: ' . $object->file['mime_type']); } else { header('Content-type: application/data'); } header('Accept-Ranges: bytes'); // Partial content if (isset($_SERVER['HTTP_RANGE'])) { $size = $object->getSize(); $start = 0; $end = $size - 1; $c_start = $start; $c_end = $end; // Parse range list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2); if ($range[0] == '-') { // Range form "-123" $c_start = (int) ($size - (int) substr($range, 1)); } else { // Range form "123-" or "123-345" $range = explode('-', $range); $c_start = (int) $range[0]; if (isset($range[1]) && is_numeric($range[1])) { $c_end = (int) $range[1]; } } \Idno\Core\Idno::site()->logging()->debug("Partial content request for {$c_start} - {$c_end} bytes from {$size} available bytes"); // Validate range if ($c_start > $c_end || $c_end > $size || $c_start < 0) { $this->setResponse(416); header('HTTP/1.1 416 Requested Range Not Satisfiable'); exit; } // Now output headers and partial content $this->setResponse(206); header('Content-Length: ' . ($c_end - $c_start)); header("Content-Range: bytes {$c_start}-{$c_end}/{$size}"); if ($stream = $object->getResource()) { fseek($stream, $c_start); echo fread($stream, $c_end - $c_start); } } else { header('Content-Length: ' . $object->getSize()); if (is_callable(array($object, 'passThroughBytes'))) { $object->passThroughBytes(); } else { if ($stream = $object->getResource()) { while (!feof($stream)) { echo fread($stream, 8192); } } } } }
function registerEventHooks() { parent::registerEventHooks(); Idno::site()->syndication()->registerService('indiesyndicate', function () { return true; }, ['note', 'article', 'image', 'like', 'share']); Idno::site()->addEventHook('user/auth/success', function (Event $event) { $is = (array) Idno::site()->session()->currentUser()->indiesyndicate; foreach ($is as $url => $details) { Idno::site()->syndication()->registerServiceAccount('indiesyndicate', $url, $details['name'], $details); } }); Idno::site()->addEventHook('post/note/indiesyndicate', function (Event $event) { $eventdata = $event->data(); $sa = $eventdata['syndication_account']; $object = $eventdata['object']; if ($this->doWebmention($sa, $object)) { return; } $details = $this->getAccountDetails($sa); $style = isset($details['style']) ? $details['style'] : 'default'; $params = ['h' => 'entry', 'content' => $object->body, 'url' => $object->getSyndicationURL()]; if (is_array($object->inreplyto) && !empty($object->inreplyto)) { $params['in-reply-to'] = $object->inreplyto[0]; } $this->doMicropub($sa, $object, $params); }); Idno::site()->addEventHook('post/image/indiesyndicate', function (Event $event) { $eventdata = $event->data(); $sa = $eventdata['syndication_account']; $object = $eventdata['object']; if ($this->doWebmention($sa, $object)) { return; } $details = $this->getAccountDetails($sa); $style = isset($details['style']) ? $details['style'] : 'default'; if ($style === 'microblog') { // combine name and content for twitter $content = ''; if ($object->title) { $content .= strip_tags($object->title); } if ($object->body) { if (!empty($content)) { $content .= "\n"; } $content .= trim(strip_tags($object->body)); } $params = ['h' => 'entry', 'content' => $content, 'url' => $object->getSyndicationURL()]; } else { $params = ['h' => 'entry', 'name' => $object->title ? strip_tags($object->title) : '', 'content' => $object->body ? strip_tags($object->body) : '', 'url' => $object->getSyndicationURL()]; } foreach ($object->getAttachments() as $attachment) { if ($file = \Idno\Entities\File::getByID($attachment['_id'])) { $photofile = tempnam(sys_get_temp_dir(), 'indiesyndicate_photo'); $file->write($photofile); $params['photo'] = '@' . $photofile; break; } } $this->doMicropub($sa, $object, $params); if (isset($photofile)) { unlink($photofile); } }); Idno::site()->addEventHook('post/article/indiesyndicate', function (Event $event) { $eventdata = $event->data(); $sa = $eventdata['syndication_account']; $object = $eventdata['object']; if ($this->doWebmention($sa, $object)) { return; } $details = $this->getAccountDetails($sa); $style = isset($details['style']) ? $details['style'] : 'default'; if ($style === 'microblog') { $params = ['h' => 'entry', 'content' => strip_tags($object->title) . ': ' . $object->getSyndicationURL(), 'url' => $object->getSyndicationURL()]; } else { $params = ['h' => 'entry', 'name' => strip_tags($object->title), 'content' => strip_tags($object->body), 'url' => $object->getSyndicationURL()]; } $this->doMicropub($sa, $object, $params); }); Idno::site()->addEventHook('post/like/indiesyndicate', function (Event $event) { $eventdata = $event->data(); $sa = $eventdata['syndication_account']; $object = $eventdata['object']; if ($this->doWebmention($sa, $object)) { return; } $details = $this->getAccountDetails($sa); $style = isset($details['style']) ? $details['style'] : 'default'; $params = ['h' => 'entry', 'like-of' => $object->likeof, 'url' => $object->getSyndicationURL()]; $this->doMicropub($sa, $object, $params); }); Idno::site()->addEventHook('post/repost/indiesyndicate', function (Event $event) { $eventdata = $event->data(); $sa = $eventdata['syndication_account']; $object = $eventdata['object']; if ($this->doWebmention($sa, $object)) { return; } $details = $this->getAccountDetails($sa); $style = isset($details['style']) ? $details['style'] : 'default'; $params = ['h' => 'entry', 'repost-of' => $object->repostof, 'url' => $object->getSyndicationURL()]; $this->doMicropub($sa, $object, $params); }); }
/** * 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; } }
<?php $opengraph = array('og:type' => 'website', 'og:title' => htmlspecialchars(strip_tags($vars['title'])), 'og:site_name' => htmlspecialchars(strip_tags(\Idno\Core\Idno::site()->config()->title)), 'og:image' => Idno\Core\site()->currentPage()->getIcon()); if (\Idno\Core\Idno::site()->currentPage() && \Idno\Core\Idno::site()->currentPage()->isPermalink()) { $opengraph['og:url'] = \Idno\Core\Idno::site()->currentPage()->currentUrl(); if (!empty($vars['object'])) { $owner = $vars['object']->getOwner(); $object = $vars['object']; $opengraph['og:title'] = htmlspecialchars(strip_tags($vars['object']->getTitle())); $opengraph['og:description'] = htmlspecialchars($vars['object']->getShortDescription()); $opengraph['og:type'] = 'article'; //htmlspecialchars($vars['object']->getActivityStreamsObjectType()); $opengraph['og:image'] = $vars['object']->getIcon(); //$owner->getIcon(); //Icon, for now set to being the author profile pic if ($icon = $vars['object']->getIcon()) { if ($icon_file = \Idno\Entities\File::getByURL($icon)) { if (!empty($icon_file->metadata['width'])) { $opengraph['og:image:width'] = $icon_file->metadata['width']; } if (!empty($icon_file->metadata['height'])) { $opengraph['og:image:height'] = $icon_file->metadata['height']; } } } if ($url = $vars['object']->getDisplayURL()) { $opengraph['og:url'] = $vars['object']->getDisplayURL(); } } } foreach ($opengraph as $key => $value) { echo "<meta property=\"{$key}\" content=\"{$value}\" />\n";
/** * Delete any files associated with this entity */ function deleteAttachments() { if ($attachments = $this->getAttachments()) { foreach ($attachments as $attachment) { if ($file = \Idno\Entities\File::getByID($attachment['_id'])) { $file->delete(); } } } }
/** * 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; }