public function submitAction() { if (!$this->getRequest()->isPost()) { return $this->_forward('index'); } $form = $this->getForm(); // Validate the form itself if (!$form->isValid($_POST)) { $this->view->form = $form; return $this->render('index'); } // Get the form data $values = $form->getValues(); $email = $values['email']; // Find the user $users = new Users(); if (!($user = $users->getUserFromEmail($email))) { $this->view->failedRecovery = true; return $this->_forward('index'); } // Change the password $password = Stuffpress_Token::create(8); $users->setPassword($user->id, $password); // Send the user an email with the new password Stuffpress_Emails::sendRecoveryEmail($email, $user->username, $password); // Done ! $this->view->email = $email; $this->render('success'); }
public function addAction() { if (!$this->getRequest()->isPost()) { return $this->_helper->json->sendJson(true); } $form = $this->getForm(); if (!$form->isValid($_POST)) { return $this->_helper->json->sendJson($form->getErrorArray()); } // Get the values and proceed $values = $form->getValues(); $source_id = $values['source']; $item_id = $values['item']; $name = $values['name']; $email = $values['email']; $website = $values['website']; $comment = $values['comment']; $options = $values['options']; $timestamp = time(); $notify = @in_array('notify', $options) ? 1 : 0; // Get the source and the user owning it $data = new Data(); $sources = new Sources(); $users = new Users(); // Does the source exist ? if (!($source = $sources->getSource($source_id))) { return $this->_helper->json->sendJson(true); } // Does the item exists? if (!($item = $data->getItem($source_id, $item_id))) { return $this->_helper->json->sendJson(true); } // Does the user exist ? if (!($user = $users->getUser($source['user_id']))) { return $this->_helper->json->sendJson(true); } // Validate the website URL $matches = array(); if (!preg_match_all("/^http/", $website, $matches)) { $website = "http://{$website}"; } // Add the comment to the database $comments = new Comments(); $comments->addComment($source_id, $item_id, $comment, $name, $email, $website, $timestamp, $notify); // Send an email alert to owner $on_comment = $this->_properties->getProperty('on_comment'); $owner = $this->_application->user && $this->_application->user->email == $email ? true : false; if ($on_comment && !$owner) { $slug = $item->getSlug(); Stuffpress_Emails::sendCommentEmail($user->email, $user->username, $name, $email, $comment, $slug); } // Send email alerts to everyone else (skip owner and current submiter) $subscribers = $comments->getSubscriptions($source_id, $item_id); foreach ($subscribers as $subscriber) { if ($subscriber['email'] == $user->email || $subscriber['email'] == $email) { continue; } Stuffpress_Emails::sendCommentNotifyEmail($subscriber['email'], $subscriber['name'], $name, $comment, $source_id, $item_id); } // Ok send the result return $this->_helper->json->sendJson(false); }
private function process($source, $target) { $this->_logger->log("Processing pingback from {$source} for {$target}", Zend_Log::INFO); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $source); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_USERAGENT, 'Storytlr/1.0'); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); $response = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); if ($http_code != 200) { $this->_logger->log("Failed to get content for {$source}", Zend_Log::DEBUG); return; } // Parse the source page for microformats content $parser = new Parser($response); $output = $parser->parse(); $this->_logger->log("Parsed output: " . var_export($output, true), Zend_Log::DEBUG); // Extract relevant data $hcards = array(); $hentries = array(); $this->processItems($output["items"], $hcards, $hentries); $this->_logger->log("Extracted hcards: " . var_export($hcards, true), Zend_Log::DEBUG); $this->_logger->log("Extracted hentries: " . var_export($hentries, true), Zend_Log::DEBUG); // Lookup if existing entry preg_match('/(?P<source>\\d+)\\-(?P<item>\\d+)\\.html$/', $target, $matches); $this->_logger->log("Matches: " . var_export($matches, true), Zend_Log::DEBUG); $source_id = $matches["source"]; $item_id = $matches["item"]; // Get the source and the user owning it $data = new Data(); $sources = new Sources(); $users = new Users(); // Does it relate to an item ? if ($source_id && $item_id) { $s = $sources->getSource($source_id); $i = $data->getItem($source_id, $item_id); if ($s && $i) { $user = $users->getUser($s['user_id']); } } // Otherwise, can we relate to a user ? if (!$user) { $user = $this->lookupUser($target); } // No user ? We have to giveup if (!$user) { throw new Exception('Failed to find corresponding storytlr user.'); } // Is this a h-entry ? if (count($hentries) > 0) { $hentry = $hentries[0]; if (count($hentry["author"]) > 0) { $hcard = $hentry["author"][0]; } } // If no hcard yet (maybe there was no h-entry, we grab the top-level one if (!$hcard && count($hcards) > 0) { $hcard = $hcards[0]; } // Find the published date if ($hentry && $hentry["published"]) { $timestamp = strtotime($hentry["published"]); } // If no timestamp, we fallback to now if (!$timestamp) { $timestamp = time(); } // Add the mention to the database try { $mentions = new Mentions(); $mentions->addMention($source_id, $item_id, $user->id, $source, $hentry["title"], $hcard["name"], $hcard["url"], "", $hcard["avatar"], $timestamp); } catch (Exception $e) { $this->_logger->log("Exception when storing mention: " . $e->getMessage(), Zend_Log::ERR); return; } // Send an email alert to owner try { $on_comment = $this->_properties->getProperty('on_comment'); if ($on_comment) { Stuffpress_Emails::sendMentionEmail($user->email, $user->username, $hcard["name"], $hcard["url"], $hentry["title"], $source, $target); } } catch (Exception $e) { $this->_logger->log("Sending mention notification exception: " . $e->getMessage(), Zend_Log::ERR); } }
public function signupAction() { if (!$this->getRequest()->isPost()) { $this->addErrorMessage("Form was not properly posted."); $this->_forward('index'); } // Retrieve the form values and its values $form = $this->getForm(); $valid = $form->isValid($_POST); $values = $form->getValues(); $username = $values['username']; $email = $values['email']; $password = $values['password']; // Validate the form itself if (!$form->isValid($_POST)) { // Failed validation; redisplay form $this->view->form = $form; $this->addErrorMessage("Your form contains some errors, please correct them and submit this form again"); return $this->_forward('register'); } // Register user $users = new Users(); $user = $users->addUser($username, $password, $email); // Add some default widgets to the user $widgets = new Widgets(array(Stuffpress_Db_Table::USER => $user->id)); $widgets->addWidget('search'); $widgets->addWidget('rsslink'); $widgets->addWidget('links'); $widgets->addWidget('lastcomments'); $widgets->addWidget('archives'); $widgets->addWidget('logo'); // Add some default properties $properties = new Properties(array(Stuffpress_Db_Properties::KEY => $user->id)); $properties->setProperty('theme', 'clouds'); $properties->setProperty('title', ucfirst($username)); $properties->setProperty('subtitle', "my life online"); // Add the storytlr data source StuffpressModel::forUser($user->id); // Add default pages $pages = new Pages(array(Stuffpress_Db_Table::USER => $user->id)); //$pages->addPage('dashboard', 'Home'); $pages->addPage('lifestream', 'Stream'); $pages->addPage('stories', 'Stories'); // Send the user a verification email Stuffpress_Emails::sendWelcomeEmail($email, $username, $password, $user->token); // Done ! $this->view->username = $username; $this->view->email = $email; $this->render('success'); }