public static function renderFile($file) { $string = Files::getFile($file); $variables = Files::getData(Dir::getCore('Engine/Variables.php'), true); foreach ($variables as $value) { $value = (array) $value; $value[0] = str_replace(['(', ')'], ['\\(', '\\)'], $value[0]); $value[0] = str_replace(['*'], ['(.*)'], $value[0]); $value[0] = "/({$value[0]})/" . (isset($value[2]) ? '' : 'U'); $string = preg_replace($value[0], $value[1], $string); } return $string; }
private function newItem($values) { // Local variables $files = new Files(); // If an image and the URL was given, we download the image and store it if ((@$values['type'] == 'image') && ($url = @$values['url']) && (strlen($url) > 0)) { $file_id = $files->downloadFile($url, "download"); $file = $files->getFile($file_id); $key = $file->key; } // If a file was uploaded, we process it else if (@$_FILES['file']['tmp_name']) { try { $file_id = $files->processFile($values['file'], $_FILES['file'], 'Posted file'); $file = $files->getFile($file_id); $key = $file->key; } catch(Exception $e) { $this->addErrorMessage("Unknown error occured"); return $this->_forward(@$values['type']); } } // If an image and file available, resize if ((@$values['type'] == 'image') && ($file_id > 0)) { $files->fitWidth($file_id, 240, 'small'); $files->fitWidth($file_id, 500, 'medium'); $files->fitWidth($file_id, 1024, 'large'); $files->fitSquare($file_id, 75, 'thumbnails'); $exif = $files->readExif($file_id); } // Process the date if available $date_type = @$values['date_type']; if ($date_type == 'other') { $timestamp = Stuffpress_Date::strToTimezone($values['date'], $this->_properties->getProperty('timezone')); } else if ($date_type == 'taken' && $exif) { if (isset($exif['DateTimeOriginal'])) { $timestamp = Stuffpress_Date::strToTimezone($exif['DateTimeOriginal'], $this->_properties->getProperty('timezone')); } else { $timestamp = time(); } } else { $timestamp = time(); } // Process the tags if available $tags = @explode(',', $values['tags']); // Prepare the values for the database $data = array(); $data['published'] = @$timestamp; $data['type'] = @$values['type']; $data['file'] = @$key; $data['url'] = @$values['url']; $data['title'] = @$values['title']; $data['link'] = @$values['link']; $data['embed'] = @$values['embed']; $data['text'] = @$values['text']; // Add or update the item $source = StuffpressModel::forUser($this->_application->user->id); $data_table = new Data(); $item_id = $source->addItem($data, $data['published'], $data['type'], $tags, false, false, $data['title']); $source_id = $source->getID(); // fetch the new item $item = $data_table->getItem($source_id, $item_id); // Get longitude if provided if (!empty($exif['GPSLongitude']) && count($exif['GPSLongitude']) == 3 && !empty($exif['GPSLongitudeRef'])) { $longitude = ($exif['GPSLongitudeRef']== 'W' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert( $exif['GPSLongitude'] ); } else { $longitude = @$values['longitude']; } // Get latitude if (!empty($exif['GPSLatitude']) && count($exif['GPSLatitude']) == 3 && !empty($exif['GPSLatitudeRef'])) { $latitude = ($exif['GPSLatitudeRef']== 'S' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert( $exif['GPSLatitude'] ); } else { $latitude = @$values['latitude']; } // Set it if ($latitude && $longitude) { $data_table->setLocation($source_id, $item_id, $latitude, $longitude, 0); } // Send notification if twitter post is enabled if ($this->_properties->getProperty('twitter_auth') && $values['twitter_notify']) { $this->notifyTwitter($item); } // Ping blog search engines $this->ping(); // Redirect to the timeline $username = $this->_application->user->username; $url = $this->getUrl($username, "/entry/" . $item->getSlug()); // If a bookmarklet, we show the 'done screen' if ($this->_bookmarklet) { $this->view->user_url = $url; return $this->_forward('done'); } return $this->_redirect($url); }
public function execute() { // get a logger $logger = Zend_Registry::get("logger"); echo "Memory usage on startup: " . memory_get_usage() . "\r\n"; // Access the email $mail = new Zend_Mail_Storage_Pop3(array('host' => 'xxxxxx', 'user' => 'xxxxxx', 'password' => 'xxxxxx', 'ssl' => 'SSL')); // If no new email, goodbye if ($mail->countMessages() == 0) { $log = "No new emails to process."; echo "{$log}\r\n"; $logger->log($log, Zend_Log::INFO); exit; } $email_count = 0; foreach ($mail as $messageNum => $message) { // A bit of feedback $log = "Message to {$message->to}.. (mem: " . memory_get_usage() . ")..."; echo "{$log}"; $logger->log($log, Zend_Log::INFO); // Get the user, if not we continue if (!($user = $this->getUser($message->to))) { $log = "skipped."; echo "{$log}\r\n"; $logger->log($log, Zend_Log::INFO); $mail->removeMessage($messageNum); continue; } // Assign the shard value Zend_Registry::set("shard", $user['id']); $this->_user = $user; $this->_properties = new Properties(array(Stuffpress_Db_Properties::KEY => $user['id'])); // Get the subject try { $subject = $this->mimeWordDecode(trim($message->subject)); } catch (Exception $e) { $subject = ""; } // Get the content $foundPart = null; $plain_text = ""; $html_text = ""; $latitude = false; $longitude = false; $image = false; $audio = false; $files = new Files(); $timestamp = time(); foreach (new RecursiveIteratorIterator($message) as $part) { try { $part_type = strtok($part->contentType, ';'); if ($part_type == 'text/plain') { $charset = $this->getCharset($part->contentType); $plain_text = $this->recode(trim($part->getContent()), $charset); } else { if ($part_type == 'text/html') { $charset = $this->getCharset($part->contentType); $html_text = $this->recode(trim($part->getContent()), $charset); } else { if (substr_compare($part_type, 'image', 0, 5) == 0) { if ($details = $this->getFileDetails($part->contentType)) { if ($content = base64_decode($part->getContent())) { $file_id = $files->saveFile($content, $details['name'], $details['mime'], "Email upload"); $file = $files->getFile($file_id); $key = $file->key; $files->fitWidth($file_id, 240, 'small'); $files->fitWidth($file_id, 500, 'medium'); $files->fitWidth($file_id, 1024, 'large'); $files->fitSquare($file_id, 75, 'thumbnails'); $exif = $files->readExif($file_id); // Retrieve the picture date/time if (isset($exif['DateTimeOriginal'])) { $timestamp = Stuffpress_Date::strToTimezone($exif['DateTimeOriginal'], $this->_properties->getProperty('timezone')); } // Get longitude if provided if (!empty($exif['GPSLongitude']) && count($exif['GPSLongitude']) == 3 && !empty($exif['GPSLongitudeRef'])) { $longitude = ($exif['GPSLongitudeRef'] == 'W' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert($exif['GPSLongitude']); } // Get latitude if (!empty($exif['GPSLatitude']) && count($exif['GPSLatitude']) == 3 && !empty($exif['GPSLatitudeRef'])) { $latitude = ($exif['GPSLatitudeRef'] == 'S' ? '-' : '') . Stuffpress_Exif::exif_gpsconvert($exif['GPSLatitude']); } $image = $key; } } } else { if (substr_compare($part_type, 'audio', 0, 5) == 0) { if ($details = $this->getFileDetails($part->contentType)) { if ($content = base64_decode($part->getContent())) { $file_id = $files->saveFile($content, $details['name'], $details['mime'], "Email upload"); $file = $files->getFile($file_id); $audio = $file->key; } } } } } } } catch (Zend_Mail_Exception $e) { // ignore } } $body = strlen($html_text) > 0 ? $html_text : $plain_text; // Post the content // 1 - a status message if (!$image && !$audio && strlen($subject) == 0) { $item_id = $this->postStatus($user['id'], $timestamp, $body); } else { if (!$image && !$audio) { $item_id = $this->postBlog($user['id'], $timestamp, $subject, $body); } else { if ($image) { $item_id = $this->postImage($user['id'], $timestamp, $subject, $body, $image); } else { if ($audio) { $item_id = $this->postAudio($user['id'], $timestamp, $subject, $body, $audio); } else { echo "Unsupported fotmat\r\n"; } } } } // Set the location of the item if provided if ($latitude && $longitude) { $source = StuffpressModel::forUser($this->_user->id); $source_id = $source->getID(); $data = new Data(); $data->setLocation($source_id, $item_id, $latitude, $longitude, 0); } $email_count++; // Delete the email $mail->removeMessage($messageNum); echo "processed.\r\n"; $logger->log("Message delivered to {$user['username']}.", Zend_Log::INFO); // Clean up before the loop unset($content); } $logger->log("Processed {$email_count} emails. (max mem: " . memory_get_peak_usage() . ").", Zend_Log::INFO); }
private function setKeyImage($story_id, $url) { $stories = new Stories(); $files = new Files(); $file_id = $files->downloadFile($url, ""); $files->fitSquare($file_id, 50, 'thumbnails'); $file = $files->getFile($file_id); $stories->setThumbnail($story_id, $file->key); }
echo $docRequest->deleteDoc('7a6a7f74-3b82-e511-bf04-008cfa482110'); echo $docRequest->getDoc('name%20eq%20%27test%20-2%20-%20test%27'); echo $docRequest->getDocId('e10f2106-8c72-e511-befe-98991b71acc0'); echo $docRequest->getDocIdRev('3c7168e7-4b82-e511-bf04-008cfa482110'); echo $docRequest->getDocIdRevId('e10f2106-8c72-e511-befe-98991b71acc0', 'b5d82c06-8c72-e511-befe-98991b71acc0'); echo $docRequest->getDocIndexFields('3c7168e7-4b82-e511-bf04-008cfa482110'); echo $docRequest->getDocIndexFieldsId('3c7168e7-4b82-e511-bf04-008cfa482110', '6684bdbe-4f82-e511-bf04-008cfa482110'); echo $docRequest->getDocRevIndexFields('3c7168e7-4b82-e511-bf04-008cfa482110', '8767a182-5282-e511-bf04-008cfa482110'); echo $docRequest->getDocRevIndexFieldsId('3c7168e7-4b82-e511-bf04-008cfa482110', '8767a182-5282-e511-bf04-008cfa482110', '6684bdbe-4f82-e511-bf04-008cfa482110'); echo $docRequest->putDocIndexFieldsId('3c7168e7-4b82-e511-bf04-008cfa482110', '9112ae85-b481-e511-bf03-008cfa482110', 'pizzas'); echo $docRequest->putDocIndexFields('3c7168e7-4b82-e511-bf04-008cfa482110', "{\"cool index field\":\"change you\",\"favorite foods\":\"mountain dew\"}"); echo $docRequest->postDoc('10000000-1000-2000-1111-100000000010', 1, 'file54.txt', 'a test file', 'file53.txt', '{}'); // EMAILS echo $emailRequest->postEmails('example@gmail.com,example2@gmail.com', '', 'php email subject', 'this was sent from php. this is the body.'); // FILES $filesRequest->getFile('6db0b14a-a781-e511-bf03-008cfa482110', '/home/jr/Desktop/hello2.txt'); $filesRequest->postFile('/home/jr/Desktop/hello2.txt', 'text/plain', 'helloWorld2.txt', '3c7168e7-4b82-e511-bf04-008cfa482110', 'GEN-15', '5', 'Released', "{\"index field label\":\"the value\"}"); // FOLDERS echo $foldersRequest->getFolder('test%20folder'); echo $foldersRequest->getFolderId('10000000-1000-2000-1111-100000000010'); echo $foldersRequest->getSubFolders('10000000-1000-2000-1111-100000000010'); echo $foldersRequest->getFolderDocs('10000000-1000-2000-1111-100000000010'); echo $foldersRequest->getFolderIndexFields('40ac2b37-9a72-e511-befe-98991b71acc0'); echo $foldersRequest->getFolderIndexFieldsId('40ac2b37-9a72-e511-befe-98991b71acc0', '9febe65a-6d82-e511-bf04-008cfa482110'); echo $foldersRequest->getSelectOptions('40ac2b37-9a72-e511-befe-98991b71acc0', '9febe65a-6d82-e511-bf04-008cfa482110'); echo $foldersRequest->postFolder('folder3', 'folder description', true); echo $foldersRequest->postSubFolder('52fdb979-7282-e511-bf04-008cfa482110', 'folder4', 'folder description', true); echo $foldersRequest->putFolderIndexFields('40ac2b37-9a72-e511-befe-98991b71acc0', '9febe65a-6d82-e511-bf04-008cfa482110', '75646376-697e-e511-bf02-008cfa482110', '75646376-697e-e511-bf02-008cfa482110', false, 'KQ'); // FORM INSTANCE echo $formInstanceRequest->relateForm('b6d45f3c-1183-e511-bf05-9c4e36b08790', 'bb6c2903-1383-e511-bf05-9c4e36b08790'); echo $formInstanceRequest->relateDoc('b6d45f3c-1183-e511-bf05-9c4e36b08790', '23b654e5-9b76-e511-beff-da1558d6bba3');
public function getBackground($size = 'cover') { if ($size != '') { $size = $size . '/'; } if ($this->background != null && NULL != ($file = Files::getFile($this->background))) { return '/images/' . $size . $file; } return '/images/cover/bg.png'; }
protected function _saveFileToDb($type, $url, $file = null) { $files = new Files(); // the audio file should be handled as well if (($type == SourceItem::IMAGE_TYPE || $type == SourceItem::AUDIO_TYPE) && strlen($url) > 0) { $file_id = $files->downloadFile($url, "download"); $file = $files->getFile($file_id); $key = $file->key; // There should be an exception handle here // to handle any possible exception from the processes above } else { if ($file) { try { // Process new file $file_id = $files->processFile($file['name'], $file, 'Posted file'); $file = $files->getFile($file_id); $key = $file->key; } catch (Exception $e) { $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Failed to process the data'); return false; } } else { $this->_buildResponse(Api_BaseController::HTTP_FAILED, 'Failed to process the data'); return false; } } // If an image and file available, resize if ($type == SourceItem::IMAGE_TYPE && $file_id > 0) { $this->_ResizeFile($files, $file_id); //$exif = $files->readExif($file_id); } return $key; }
public function getBackground($size = 'cover') { if ($size != '') { $size = $size . '/'; } if ($this->background != null && NULL != ($file = Files::getFile($this->background))) { return $file; } return '/static/css/officeTestBG.png'; }