private function editItem($source_id, $item_id, $values) { //Verify if the requested item exist $data = new Data(); if (!($item = $data->getItem($source_id, $item_id))) { throw new Stuffpress_NotFoundException("This item does not exist."); } // Get the user $users = new Users(); $attributes = $item->getAttributes(); $user = $users->getUser($attributes['user_id']); // Check if we are the owner if ($this->_application->user->id != $user->id) { throw new Stuffpress_NotFoundException("Not the owner"); } // Process the date if available if (@$values['date_type'] == 'other') { $timestamp = Stuffpress_Date::strToTimezone($values['date'], $this->_properties->getProperty('timezone')); } else { $timestamp = time(); } // Process the tags if available $tag_input = @$values['tags']; $tags = explode(',',$tag_input); $data->setTags($source_id, $item_id, $tags); // Process the location if available $latitude = @$values['latitude']; $longitude = @$values['longitude']; if ($latitude && $longitude) { $data->setLocation($source_id, $item_id, $latitude, $longitude, 0); } // Update the item data $data->setTimestamp($source_id, $item_id, $timestamp); switch ($item->getType()) { case SourceItem::STATUS_TYPE: $status = html_entity_decode(@$values['title']); $item->setStatus($status); break; case SourceItem::BLOG_TYPE: $title = @$values['title']; $text = @$values['text']; $item->setTitle($title); $item->setContent($text); break; case SourceItem::LINK_TYPE: $title = @$values['title']; $link = @$values['link']; $desc = @$values['text']; $item->setTitle($title); $item->setLink($link); $item->setDescription($desc); break; case SourceItem::IMAGE_TYPE: $title = @$values['title']; $desc = @$values['text']; $item->setTitle($title); $item->setDescription($desc); break; case SourceItem::AUDIO_TYPE: $title = @$values['title']; $desc = @$values['text']; $item->setTitle($title); $item->setDescription($desc); break; case SourceItem::VIDEO_TYPE: $title = @$values['title']; $desc = @$values['text']; $item->setTitle($title); $item->setDescription($desc); break; } // Send notification if twitter post is enabled if ($this->_properties->getProperty('twitter_auth') && $values['twitter_notify']) { $this->notifyTwitter($item); } // Redirect to the timeline $host = $this->getHostname(); $username = $this->_application->user->username; $url = $this->getUrl($username, "/entry/" . $item->getSlug()); return $this->_redirect($url); }
public function submitAction() { // Is the form correctly posted ? if (!$this->getRequest()->isPost()) { return $this->_forward('index'); } // Is the form valid ? $form = $this->getForm($this->getAvailableSources()); if (!$form->isValid($_POST)) { $this->view->form = $form; $this->addErrorMessage("Please check your input and try again."); return $this->_forward('index'); } // Get the values // TODO SECURE THIS ! Especially verify that the user // has access to the given sources ! $values = $form->getValues(); $title = $values['title']; $subtitle = $values['subtitle']; $date_from = Stuffpress_Date::strToTimezone($values['date_from'], $this->_properties->getProperty("timezone")); $date_to = Stuffpress_Date::strToTimezone($values['date_to'], $this->_properties->getProperty("timezone")) + 86400; $sources = $values['sources']; if (count($sources) == 0) { $this->view->form = $form; $this->addErrorMessage("You must select at least one source to build a story."); return $this->_forward('index'); } // Fetch the items $data = new Data(); $storyItems = new StoryItems(); $items = array(); foreach ($sources as $source_id) { $i = $data->getItemsByDate($date_from, $date_to, $source_id, true); foreach ($i as $item) { $type = $item->getType(); $items[] = $item; } } // If no items, we have an error if (!$items || count($items) == 0) { $this->view->form = $form; $this->addErrorMessage("Your story does not contain any items."); return $this->_forward('index'); } // Create the new story $stories = new Stories(); $story_id = $stories->addStory($date_from, $date_to, $title, $subtitle, serialize($sources)); // Add the story items $images = array(); foreach ($items as $item) { if ($item->getType() == SourceItem::IMAGE_TYPE) { $images[] = $item->getImageUrl(ImageItem::SIZE_MEDIUM); } $storyItems->addItem($story_id, $item->getSource(), $item->getID(), $item->getPrefix(), $item->getTimestamp(), $item->ishidden()); } // Pick an image randomly and save it if (count($images) > 0) { $image = $images[rand(0, count($images) - 1)]; $this->setKeyImage($story_id, $image); } // Forward to the story page $config = Zend_Registry::get('configuration'); $host = $config->web->host; $url = $this->getUrl($this->_application->user->username, "/story/edit/id/{$story_id}"); 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); }
public function settimestampAction() { // Get, check and setup the parameters $source_id = $this->getRequest()->getParam("source"); $item_id = $this->getRequest()->getParam("item"); $timestamp = $this->getRequest()->getParam("timestamp"); //Verify if the requested source exist $sources = new Sources(); if (!($source = $sources->getSource($source_id))) { throw new Stuffpress_Exception("Error updating timestamp for source {$source} - Invalid source"); } // Get the user $users = new Users(); $user = $users->getUser($source['user_id']); // Check if we are the owner if ($this->_application->user->id != $user->id) { throw new Stuffpress_Exception("Error updating timestamp for source {$source} - Not the owner"); } // Get the user properties $properties = new Properties($user->id); // Check if the date is valid if (!($date = Stuffpress_Date::strToTimezone($timestamp, $properties->getProperty('timezone')))) { $this->addErrorMessage("Could not understand the provided date/time"); return $this->_forward('index'); } // Ok, we can change the title of the item $model = SourceModel::newInstance($source['service'], $source); $model->setTimestamp($item_id, $date); $this->addStatusMessage("Life is cool"); // We redirect to the stream $this->_forward('index'); }