public function showAction() { $articleId = $this->getParam('id'); $feadId = $this->getParam('fead'); if (is_null($articleId) || is_null($feadId)) { $this->redirect('home/notprivileged'); } $this->view->article = Application_Model_ArticleRepository::getInstance()->getArticle($articleId, $feadId); if (!is_null($this->view->article)) { $this->view->fead = Application_Model_FeadRepository::getInstance()->getFeadsForUser($this->isLoggedin()->getId(), $feadId)[0]; $meta = Application_Model_UserArticleRepository::getInstance()->getArticleMeta($this->view->article->getId()); $article = new Application_Model_Entity_UserArticle(['articleId' => $this->view->article->getId(), 'feadId' => $this->view->article->getFeadId(), 'unread' => 0, 'favorite' => 0]); $this->view->article->setUnread(0); if (is_null($meta)) { Application_Model_UserArticleRepository::getInstance()->add($article); Application_Model_UserFeadRepository::getInstance()->clickIncrease($feadId); } else { $this->view->article->setFavorite($meta->isFavorite()); $article->setFavorite($meta->isFavorite()); if ($meta->isUnread()) { Application_Model_UserFeadRepository::getInstance()->clickIncrease($feadId); } Application_Model_UserArticleRepository::getInstance()->update($article); } } else { $this->redirect('home/notprivileged'); } }
private function generateKey() { $id = $this->getParam('id'); $id = intval($id); $article = Application_Model_ArticleRepository::getInstance()->getArticle($id); if (!is_int($id)) { return null; } else { if (!$article) { return null; } else { $key = Application_Model_ShareRepository::getInstance()->getKeyForId($id); if (is_null($key)) { $key = Application_Model_ShareRepository::getInstance()->addArticle($id); } return ['key' => $key, 'article' => $article]; } } }
public function updateFead($id, $debug = null) { $frontendOptions = ['lifetime' => 60, 'automatic_serialization' => true]; $backendOptions = ['cache_dir' => substr(APPLICATION_PATH, 0, strrpos(APPLICATION_PATH, '/')) . '/data/cache/']; $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); $output = ''; Zend_Registry::set('Zend_Locale', new Zend_Locale('de')); Zend_Locale::setCache($cache); $repository = Application_Model_ArticleRepository::getInstance(); $feadData = Application_Model_FeadRepository::getInstance()->get($id); $date = $repository->getLatestDateForFead($id); // close db connections Application_Model_ArticleRepository::getInstance()->closeConnection(); try { $fead = Application_Service_Fead::import(strtolower($feadData->getUrl())); } catch (Exception $e) { if ($debug) { $output .= $feadData->getTitle() . ': ' . $e->getMessage() . '<br>'; } try { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $feadData->getUrl()); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); $data = curl_exec($curl); curl_close($curl); $fead = Application_Service_Fead::importString($data); } catch (Exception $e) { $output .= $feadData->getTitle() . ': ' . $e->getMessage() . '<br>'; echo $feadData->getTitle() . ': ' . $e->getMessage(); return; } } if ($debug) { $output .= $feadData->getTitle() . '<br>'; } $articles = []; foreach ($fead as $i => $article) { $articleDate = $article->getDateModified(); $now = new Zend_Date(); $now = $now->toString('YYYY-MM-dd HH:mm:ss'); if (!is_null($articleDate) && $now > $articleDate->toString('YYYY-MM-dd HH:mm:ss')) { $articleDate = $articleDate->toString('YYYY-MM-dd HH:mm:ss'); } else { $articleDate = $now; } if ($debug) { $output .= $articleDate . ' > ' . $date . '?<br>'; } if ($articleDate <= $date) { break; } if ($debug) { $output .= '.'; } $content = trim($article->getDescription(), ['script']); $preview = substr(trim(strip_tags($content, ['a', 'img', 'script'])), 0, 255); $url = $article->getLink(); $thumb = strpos($article->getContent(), '<img'); if ($thumb) { $thumb = strpos($article->getContent(), 'src="http', $thumb); $end = strpos($article->getContent(), '"', $thumb + 5); $thumb = substr($article->getContent(), $thumb + 5, $end - $thumb - 5); } else { $thumb = null; } $articles[$i] = new Application_Model_Entity_Article(['feadId' => $feadData->getId(), 'title' => substr($article->getTitle(), 0, 255), 'preview' => $preview, 'url' => $url, 'thumb' => $thumb, 'dateCreated' => $article->getDateCreated()->toString('YYYY-MM-dd HH:mm:ss'), 'dateModified' => $articleDate, 'content' => $content]); } Application_Model_ArticleRepository::getInstance()->openConnection(); // import from oldest to youngest for ($i = sizeof($articles) - 1; $i >= 0; $i--) { Application_Model_ArticleRepository::getInstance()->addArticle($articles[$i]); } if ($debug) { echo $output; } }
public function loadAction() { $this->_helper->layout()->disableLayout(); $this->isAllowed('view'); $page = $this->getParam('page'); $latest = $this->getParam('latest'); $feadId = null; if (null === $this->getParam('type')) { $feadId = $this->getParam('id'); $folderId = $this->getParam('folder'); if (!is_null($folderId) || '0' === $feadId) { $feadId = null; $this->view->displayFeadTitle = true; } $articles = Application_Model_ArticleRepository::getInstance()->getArticlesForUser($feadId, $page, $latest, $folderId); } else { if ('unread' === $this->getParam('type')) { $this->view->displayFeadTitle = true; $articles = Application_Model_ArticleRepository::getInstance()->getUnreadArticlesForUser($page, $latest); } else { if ('favorites' === $this->getParam('type')) { $this->view->displayFeadTitle = true; $articles = Application_Model_ArticleRepository::getInstance()->getFavoritesForUser($page, $latest); } } } $this->view->articles = $articles; }
/** * update the given fead * @param $url String the url of the fead * @param $id int the fead's id if available */ public function updateFead($url, $id) { $parser = null; $data = $this->getContent($url); if (!$data) { return; } $data = $data['data']; // rss-fead if (strpos($data, '<rss')) { $parser = new Application_Model_RssParser($data); } else { if (strpos($data, '<feed')) { $parser = new Application_Model_AtomParser($data); } else { return; } } $parser->setFeadId($id); $parser->parseWithMinDate(); $articleRepo = Application_Model_ArticleRepository::getInstance(); while ($article = $parser->nextArticle()) { $articleRepo->addArticle($article); } }