public function addFead(Application_Model_Entity_Fead $fead) { $id = $this->urlExists($fead->getUrl()); if (!$id) { $this->_db->insert($this->_table, ['title' => $fead->getTitle(), 'url' => $fead->getUrl()]); $id = $this->_db->lastInsertId($this->_table); Application_Service_Fead::getInstance()->updateFead($fead->getUrl(), $id); } Application_Model_UserFeadRepository::getInstance()->add($id); return $id; }
public function importAction() { $request = $this->getRequest(); $form = new Application_Form_FeadImport(); if (!is_null($this->getParam('file'))) { $path = realpath(APPLICATION_PATH . '/../data/uploads/import') . '/' . $this->getParam('file') . '.xml'; $document = new DOMDocument(); $document->load($path); foreach ($document->getElementsByTagName('outline') as $element) { $url = $element->getAttributeNode('xmlUrl')->nodeValue; $title = $element->getAttributeNode('title')->nodeValue; echo '<div class="grid-100 tablet-grid-100 mobile-grid-100"><p>'; if (null === $url) { echo '<span class="icon-warning-sign"></span>'; // TODO folders } else { if (!strpos($url, 'www.google.com/reader/public')) { $fead = new Application_Model_Entity_Fead(); $fead->setTitle($title)->setUrl($url); Application_Model_FeadRepository::getInstance()->addFead($fead); echo '<span class="icon-ok-sign"></span>'; } } echo $title . '</p>'; if (null === $url) { echo '<p>' . $this->_translate->_('import_no_folders') . '</p>'; } echo '<hr></div>'; } } else { if ($this->getRequest()->isPost()) { if ($form->isValid($request->getPost())) { $unique = uniqid($this->isLoggedin()->getId() . '-'); $name = $_FILES['opml']['tmp_name']; echo 'from: ' . $name . '<br>'; $dest = realpath(APPLICATION_PATH . '/../data/uploads/import/') . "/{$unique}.xml"; echo 'to: ' . $dest . '<br>'; if (move_uploaded_file($name, $dest)) { chmod($dest, 0777); $this->redirect('/fead/import/file/' . $unique); } } $this->view->form = $form; } else { $this->view->form = $form; } } }
/** * Search the given url for a fead or a link to it * @param $url String the url the fead should be included * @return Array|null */ public function searchFead($url) { $content = $this->getContent($url); if (!$content) { return null; } $data = $content['data']; $url = $content['url']; // rss-fead if (strpos($data, '<rss')) { $titleStart = strpos($data, '>', strpos($data, '<title')) + 1; return [['url' => $content['url'], 'title' => substr($data, $titleStart, strpos($data, '</title>', $titleStart) - $titleStart), 'type' => 'rss']]; } else { if (strpos($data, '<feed')) { $titleStart = strpos($data, '>', strpos($data, '<title')) + 1; return [['url' => $content['url'], 'title' => substr($data, $titleStart, strpos($data, '</title>', $titleStart) - $titleStart), 'type' => 'atom']]; } else { if (strpos(strtolower($data), '<!doctype') || strpos($data, '<html')) { // take only head $data = substr($data, strpos($data, '<head'), strpos($data, '</head>') + 7); $document = new DOMDocument(); $document->loadHTML($data); $feads = []; foreach ($document->getElementsByTagName('link') as $element) { $type = $element->getAttributeNode('rel')->nodeValue; if ('alternate' === $type) { if ('application/rss+xml' === $element->getAttributeNode('type')->nodeValue) { $type = 'rss'; } else { if ('application/atom+xml' === $element->getAttributeNode('type')->nodeValue) { $type = 'atom'; } } $linkUrl = $element->getAttributeNode('href')->nodeValue; if (0 === strpos($linkUrl, '/')) { $realUrl = parse_url($url); if (is_array($realUrl)) { $scheme = $realUrl['scheme']; if (is_null($scheme)) { $scheme = 'http'; } $linkUrl = $scheme . '://' . $realUrl['host'] . $linkUrl; } } $title = $element->getAttributeNode('title')->nodeValue; if (is_null($title) || 0 === strlen($title)) { $title = $type . ' fead'; } $fead = new Application_Model_Entity_Fead(); $fead->setUrl($linkUrl); $fead->setType($type); $fead->setTitle($title); array_push($feads, ['url' => $linkUrl, 'title' => $title, 'type' => $type]); } } if ([] === $feads) { return null; } return $feads; } } } }
public function update(Application_Model_Entity_Fead $fead) { $this->_db->update($this->_table, ['title' => $fead->getTitle(), 'order' => (int) $fead->getOrder(), 'folder' => (int) $fead->getFolder()], [$this->_db->quoteInto('feadid=?', $fead->getId()), $this->_db->quoteInto('userid=?', $this->_userId)]); }