/** * Submit Feed to website * * @return */ public function submitAction() { $this->view->keywords = implode('', array('ifphp', 'news aggragator', 'submit rss feed')); $form = $this->getSubmitForm(); //setup the available categories $categories = new Categories(); $this->view->categories = $categories->getAll(); foreach ($this->view->categories as $category) { $form->category->addMultiOptions(array($category->id => $category->title)); } //setup the available languages $languages = new Languages(); $this->view->languages = $languages->getAll(); foreach ($this->view->languages as $language) { $form->language->addMultiOptions(array($language->id => $language->title)); } //if it's a post submit let's save the information if ($this->getRequest()->isPost() && $form->isValid($_POST)) { //TODO this shoudl be wrapped in a transaction //create user $users = new Users(); //check for existance of a user $user = $users->getByEmail($form->email->getValue()); if (!$user) { $user = $users->createRow(); $user->email = $form->email->getValue(); $user->fullName = $form->fullname->getValue(); $user->username = '******'; //TODO put real username here eventually $user->password = ''; $user->roleId = Role::SUBMITTER; $user->statusId = Status::ACTIVE; $user->save(); } try { $feedSource = Zend_Feed_Reader::import($form->url->getValue()); //convert/parse feed to strongly typed objects $defaultFilterChain = new Zend_Filter(); $defaultFilterChain->addFilter(new Ifphp_Filter_XSSClean()); $defaultFilterChain->addFilter(new Zend_Filter_StringTrim()); $defaultFilterChain->addFilter(new Zend_Filter_StripTags()); $feeds = new Feeds(); $feed = $feeds->createRow(); $feed->token = md5(uniqid($user->id)); $feed->url = $defaultFilterChain->filter($form->url->getValue()); $feed->title = $defaultFilterChain->filter($feedSource->getTitle()); $inflector = new Zend_Filter_Inflector(':title'); $inflector->setRules(array(':title' => array('Word_SeparatorToDash', 'StringToLower', 'HtmlEntities'))); $feed->slug = $inflector->filter(array('title' => $feed->title)); $feed->description = $defaultFilterChain->filter($feedSource->getDescription()); $feed->categoryId = $form->category->getValue(); $feed->languageId = $form->language->getValue(); $feed->siteUrl = $form->siteUrl->getValue(); $feed->statusId = Status::PENDING; $feed->userId = $user->id; $feed->refreshRate = 120; //TODO this is sometimes stored in the feed $feed->save(); //parse feed $posts = new Posts(); foreach ($feedSource as $feedEntry) { $post = $posts->createRow(); $post->title = $defaultFilterChain->filter($feedEntry->getTitle()); $post->description = $defaultFilterChain->filter($feedEntry->getDescription()); $post->link = $defaultFilterChain->filter($feedEntry->getPermaLink()); $post->feedId = $feed->id; $date = new Zend_Date($feedEntry->getDateModified()); $post->publishDate = $date->toValue(); $post->save(); } // $this->_flashMessenger->addMessage('Your feed has been added to the site. Your ping back url is http://ifphp.com/feed/ping-back/'.$feed->token); $this->sendActivationEmail($feed, $user); $this->_forward('submit-thank-you'); } catch (Zend_Feed_Exception $error) { $form->url->markAsError(); Zend_Registry::getInstance()->logger->err($error); return; } } $this->view->form = $form; }