public function indexAction()
 {
     // Get, check and setup the parameters
     if (!($widget_id = $this->getRequest()->getParam("id"))) {
         throw new Stuffpress_Exception("No widget id provided to the widget controller");
     }
     // Verify if the requested widget exist and get its data
     $widgets = new Widgets();
     if (!($widget = $widgets->getWidget($widget_id))) {
         throw new Stuffpress_Exception("Invalid widget id");
     }
     // Get the last comments
     $comments = new Comments(array(Stuffpress_Db_Table::USER => $widget['user_id']));
     $mycomments = $comments->getLastComments();
     $data = new Data();
     // Prepare the comments for output
     foreach ($mycomments as &$comment) {
         $time = strtotime($comment['timestamp']);
         $item = $data->getItem($comment['source_id'], $comment['item_id']);
         $comment['item'] = $item;
         $comment['when'] = Stuffpress_Date::ago($time, "j M y");
         $comment['comment'] = str_replace("\n", " ", $comment['comment']);
         if (strlen($comment['comment']) > 50) {
             $comment['comment'] = mb_substr($comment['comment'], 0, 47) . "...";
         }
     }
     // Get the widget properties
     $properties = new WidgetsProperties(array(Properties::KEY => $widget_id));
     $title = $properties->getProperty('title');
     $this->view->title = $title ? $title : "Latest comments";
     // Prepare the view for rendering
     $this->view->comments = $mycomments;
 }
Example #2
0
	private function getFormCommon($source_id = 0, $item_id=0, $type='text', $date=false, $edit=false, $tags=false, $lat=false, $long=false, $elev=false) {
		// Create the basic form		
		$form = new Stuffpress_Form();

		// Add the form element details
		$form->setAction('admin/post/submit');
		$form->setMethod('post');
		$form->setName("formPost");
		
		// Create and configure tags element:
		$element = $form->createElement('text', 'tags',  array('label' => 'Tags:', 'decorators' => array('ViewHelper', 'Errors')));
		$element->addValidator('stringLength', false, array(0, 256));
		$element->addFilter('StripTags');
		$element->setValue($tags);
		$element->setRequired(false);
		$form->addElement($element);
		
		// Create and configure latitude element:
		$element = $form->createElement('hidden', 'latitude',  array('label' => 'Latitude:', 'decorators' => array('ViewHelper', 'Errors')));
		$element->addValidator('between', false, array(-180.0, 180.0));
		$element->setValue($lat);
		$element->setRequired(false);
		$form->addElement($element);

		// Create and configure longitude element:
		$element = $form->createElement('hidden', 'longitude',  array('label' => 'Longitude:', 'decorators' => array('ViewHelper', 'Errors')));
		$element->addValidator('between', false, array(-180.0, 180.0));
		$element->setValue($long);
		$element->setRequired(false);
		$form->addElement($element);
		
		// Add a radio button element for the date_type
		$element = $form->createElement('hidden', 'date_type');
		$element->setRequired(false);
		$element->setDecorators(array('ViewHelper'));
		$form->addElement($element);
				
		if ($date) {
			$timestamp = $date;
			$this->view->date_text = Stuffpress_Date::date("F d, Y h:i A", $timestamp, $this->_properties->getProperty('timezone'));
			$element->setValue('other');
		} else {
			$timestamp = time();
			$this->view->date_text = "Now";
			$element->setValue('now');
		}		
				
		$form->addElement($element);
		
		// Create and configure date element:
		$element = $form->createElement('hidden', 'date');
		$element->setRequired(false);
		$element->setDecorators(array('ViewHelper'));
		$element->setValue(Stuffpress_Date::date("F d, Y h:i A", $timestamp, $this->_properties->getProperty('timezone')));
		$form->addElement($element);
		
		// Add a twitter element if required
		if ($this->_properties->getProperty('twitter_auth')) {
			$checked = (!$item_id && in_array($source_id, unserialize($this->_properties->getProperty('twitter_services')))) ? true : false;
			$element = $form->createElement('checkbox', 'twitter_notify',  array('label' => 'Twitter:', 'decorators' => array('ViewHelper', 'Errors'), 'class' => 'css'));
			$element->setValue($checked);
			$element->setRequired(true);
			$form->addElement($element);		
		}
		
		// Add a hidden element with the item id
		$element = $form->createElement('hidden', 'item');
		$element->setDecorators(array(array('ViewHelper')));
		$element->setValue($item_id);
		$form->addElement($element);

		// Add a hidden element with the item id
		$element = $form->createElement('hidden', 'source');
		$element->setDecorators(array(array('ViewHelper')));
		$element->setValue($source_id);
		$form->addElement($element);		
		
		// Add a hidden element with the type
		$element = $form->createElement('hidden', 'type');
		$element->setDecorators(array(array('ViewHelper')));
		$element->setValue($type);
		$form->addElement($element);
		
		// If a bookmarklet, we also need to remember it
		$element = $form->createElement('hidden', 'bookmarklet');
		$element->setDecorators(array(array('ViewHelper')));
		$element->setValue($this->_bookmarklet);
		$form->addElement($element);
		
		// Add a hidden element with action
		$element = $form->createElement('hidden', 'mode');
		$element->setDecorators(array(array('ViewHelper')));
		$element->setValue($edit ? 'edit' : 'create');
		$form->addElement($element);

		// use addElement() as a factory to create 'Post' button:
		$form->addElement('button', 'post', array('label' => ($edit ? 'Save' : 'Post'), 'onclick' => "submitFormPost();", 'decorators' => $form->buttonDecorators));

		return $form;
	}
Example #3
0
 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);
 }
Example #4
0
 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 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');
 }