public static function getSourceModel($source_id) { if (!isset(SourceModel::$_source_cache[$source_id])) { $sources = new Sources(); $source = $sources->getSource($source_id); $model = SourceModel::newInstance($source['service'], $source); SourceModel::$_source_cache[$source_id] = $model; } return SourceModel::$_source_cache[$source_id]; }
public function keywordAction() { // Action parameters $search = $this->getRequest()->getParam("search"); // A bit of filtering $search = substr($search, 0, 50); // Get all the items; if we are an admin, we also get the hidden one $data = new Data(); $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $items = array(); foreach ($sources as $source) { $s = SourceModel::newInstance($source['service'], $source); $index = $s->getSearchIndex(); $prefix = $s->getServicePrefix(); $id = $s->getID(); if ($index != '') { $r = $data->search($id, $prefix, $index, $search, $this->_admin); if ($r) { $items = array_merge($items, $r); } } } // Sort the result of the search $sorter = new Stuffpress_SortItems(); $sorter->sort($items, 1); // Prepare the common elements $this->common(); // Add specifics entries $this->view->search = $search; $this->view->items = $items; $this->view->models = $this->getModels(); // Set page title $title = $this->_properties->getProperty('title'); $subtitle = $this->_properties->getProperty('subtitle'); $separator = $title ? "|" : ""; $this->view->headTitle("{$title} {$separator} Search results for {$search}"); // Add specific styles and javascripts $this->view->headScript()->appendFile('js/controllers/timeline.js'); $this->view->headLink()->appendStylesheet('style/lightbox.css'); // Render the index $this->render('index'); }
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 all sources configured for that user $sources = new Sources(array(Stuffpress_Db_Table::USER => $widget['user_id'])); $mysources = $sources->getSources(); // If sources are configured, get the links for each source $links = array(); if ($mysources) { foreach ($mysources as $source) { if (!($source['public'] && $source['enabled'])) { continue; } if ($source['service'] == 'stuffpress') { continue; } $model = SourceModel::newInstance($source['service']); $model->setSource($source); $link['prefix'] = $model->getServicePrefix(); $link['url'] = $model->getServiceURL(); $link['name'] = $model->getTitle(); $links[] = $link; } } // Get the widget properties $properties = new WidgetsProperties(array(Properties::KEY => $widget_id)); $title = $properties->getProperty('title'); $this->view->title = $title ? $title : "My 2.0 Life"; // Prepare the view for rendering $this->view->links = $links; }
public function editAction() { // Get the item to edit from the parameters $item_id = $this->_getParam('item'); $source_id = $this->_getParam('source'); //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"); } // Get the source to provide visual feedback $model = SourceModel::newInstance($item->getPrefix()); $this->view->service = $model->getServiceName(); // Prepare the form $form = $this->getForm($item->getType(), true, $item); $this->view->form = $form; $this->view->edit = true; // If it is an image, we display it if ($item->getType() == 'image') { $this->view->image_url = $item->getImageUrl(ImageItem::SIZE_THUMBNAIL); } // If it already has location, tell it if ($item->hasLocation()) { $this->view->has_location = true; $this->view->location = "Lat: " . $item->getLatitude() . " - Lng: " . $item->getLongitude(); } // forward to the appropriate action $this->_forward($item->getType()); }
shuffle($sources); $success = 0; $failure = 0; $total = count($sources); foreach ($sources as $source) { if ($source['service'] == 'stuffpress') { continue; } if (!$source['enabled']) { continue; } if (!is_null($cl_source) && $source['service'] != $cl_source) { continue; } echo "Memory: " . memory_get_usage() . "\r\n"; $model = SourceModel::newInstance($source['service'], $source); try { if ($source['imported']) { echo "Updating source {$source['service']} for user {$user->username} [" . ($success + $failure) . "/{$total}] ({$source['id']})...."; $items = $model->updateData(); $model->onNewItems($items); echo " found " . count($items) . " items\r\n"; } else { echo "Importing source {$source['service']} ({$source['id']}).\r\n"; $items = $model->importData(); } $success++; } catch (Exception $e) { echo "Could not update source {$source['id']}: " . $e->getMessage(); $logger->log("Could not update source {$source['id']}: " . $e->getMessage(), Zend_Log::ERR); echo $e->getTraceAsString();
private function getAvailableSources() { $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $s = array(); if ($sources) { foreach ($sources as $source) { $model = SourceModel::newInstance($source['service']); $model->setSource($source); if ($model->isStoryElement()) { $s[$source['id']] = $model->getServiceName() . "(" . $model->getAccountName() . ")"; } } } return $s; }
private function getAvailableSources() { $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); $s = array(); if ($sources) { foreach ($sources as $source) { $model = SourceModel::newInstance($source['service'], $source); $account = $model->getAccountName() ? "(" . $model->getAccountName() . ")" : ""; $s[$source['id']] = $model->getServiceName() . $account; } } return $s; }
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'); }
public function deleteAction() { // Get the source from the request and initialize the model $id = $this->_getParam('id'); // Get the sources database $sources = new Sources(); // Check if the source exists if (!($source = $sources->getSource($id))) { return $this->_helper->json->sendJson(true); } // Check if we own the source if ($source['user_id'] != $this->_application->user->id) { return $this->_helper->json->sendJson(true); } // Instantiate a model and remove all the data $model = SourceModel::newInstance($source['service']); $model->setSource($source); $model->deleteItems(); // Delete the duplicated from the Data table $data = new Data(); $data->deleteItems($source['id']); // Delete the source settings $properties = new SourcesProperties(array(Properties::KEY => $source['id'])); $properties->deleteAllProperties(); // Delete the tags $tags = new Tags(); $tags->deleteSource($source['id']); // Remove the source $sources->deleteSource($id); // We should also delete the associated comments $comments = new Comments(); $comments->deleteComments($source['id']); // Forward to the list view with a success message return $this->_helper->json->sendJson(false); }
protected function getModels() { $sources = new Sources(); $s = $sources->getSources(); $models = array(); if ($s) { foreach ($s as $source) { $model = SourceModel::newInstance($source['service'], $source); $models[$source['id']] = $model; } } return $models; }
function updateUser($user, &$success, &$failure, &$total) { $this->logger->log("Updating data for " . $user->username, Zend_Log::INFO); // Assign the proper shard id Zend_Registry::set("shard", $user->id); // Get the user sources $sourcesTable = new Sources(); $sources = $sourcesTable->getSources(); if (!$sources) { echo "No sources found to update.\r\n"; $this->logger->log("No sources found to update.", Zend_Log::INFO); die; } // Log an entry $this->logger->log("Updating {$user->username}", Zend_Log::INFO); shuffle($sources); $total = $total + count($sources); foreach ($sources as $source) { if ($source['service'] == 'stuffpress') { continue; } if (!$source['enabled']) { continue; } if (!is_null($this->cl_source) && $source['service'] != $this->cl_source) { continue; } $model = SourceModel::newInstance($source['service'], $source); if (!$model->isActive()) { echo "Skipping unactive source {$source['service']}.\r\n "; continue; } try { if ($source['imported']) { echo "Updating source {$source['service']} for user {$user->username} [" . ($success + $failure) . "/{$total}] ({$source['id']})...."; $items = $model->updateData(); $model->onNewItems($items); echo " found " . count($items) . " items\r\n"; } else { echo "Importing source {$source['service']} ({$source['id']}).\r\n"; $items = $model->importData(); } $success++; } catch (Exception $e) { echo "Could not update source {$source['id']}: " . $e->getMessage(); $this->logger->log("Could not update source {$source['id']}: " . $e->getMessage(), Zend_Log::ERR); echo $e->getTraceAsString(); $failure++; } } }
public function excelAction() { // Get the request parameters $id = $this->_getParam('id'); // Get the requested source $sources = new Sources(); if (!($source = $sources->getSource($id))) { throw new Stuffpress_Exception("Unknown source id {$id}"); } // Are we the owner of the source if ($source['user_id'] != $this->_application->user->id) { throw new Stuffpress_Exception("You are not authorized to download this source"); } // Get the source meta data $model = SourceModel::newInstance($source['service']); $model->setSource($source); $service = $model->getServiceName(); $desc = $model->getServiceDescription(); // Get the actual data to backup $data = new Data(); $items = $data->getAllItems($source['id']); // This is not a layout or rendered page $this->_helper->viewRenderer->setNoRender(); $this->_helper->layout->disableLayout(); // Start the writer to Excel require_once 'PHPExcel.php'; require_once 'PHPExcel/Writer/Excel2007.php'; $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("storytlr.com"); $objPHPExcel->getProperties()->setLastModifiedBy("storytlr.com"); $objPHPExcel->getProperties()->setTitle("Backup of {$this->_application->user->username}'s {$service} account"); //$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription($desc); // Add some data $objPHPExcel->setActiveSheetIndex(0); // Write the column titles $keys = array_keys($items[0]->getBackup()); for ($i = 0; $i < count($keys); $i++) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i, 1, $keys[$i]); } // Write the data for ($i = 0; $i < count($items); $i++) { $item = $items[$i]->getBackup(); for ($j = 0; $j < count($keys); $j++) { $value = $item[$keys[$j]]; if ($value) { $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($j, $i + 2)->setValueExplicit("'{$value}", PHPExcel_Cell_DataType::TYPE_STRING); } } } // Rename sheet $objPHPExcel->getActiveSheet()->setTitle($service); // Save Excel 2007 file $root = Zend_Registry::get("root"); $key = Stuffpress_Token::create(6); $file = "{$service}-{$this->_application->user->username}-[{$key}].xls"; $path = $root . "/public/files/{$file}"; $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $objWriter->save($path); $this->_redirect($this->_base . "/files/{$file}"); }