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');
     }
 }
Example #2
0
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
         self::$_instance->_table = 'fead';
     }
     return self::$_instance;
 }
Example #3
0
 public function articleAction()
 {
     $key = $this->getParam('public');
     $id = null;
     if (6 >= strlen($key)) {
         $id = Application_Model_ShareRepository::getInstance()->getIdForKey($key);
     }
     if (null !== $id) {
         $this->view->key = $key;
         Application_Model_ShareRepository::getInstance()->increaseKey($key);
         $this->view->article = Application_Model_ArticleRepository::getInstance()->getPublicArticle($id);
         $this->view->fead = Application_Model_FeadRepository::getInstance()->get($this->view->article->getFeadId());
     }
 }
Example #4
0
 public function feadAction()
 {
     $this->isAllowed('view');
     $this->view->feadId = $this->getParam('id');
     if ($this->_getParam('folder')) {
         $this->view->folder = $this->getParam('folder');
         $this->view->feadId = null;
     }
     $form = new Application_Form_FeadAdd();
     $form->setAction('/fead/add');
     $this->view->form = $form;
     if (!is_null($this->view->feadId)) {
         $this->view->feadTitle = Application_Model_FeadRepository::getInstance()->getFeadForId($this->view->feadId);
     } else {
         if (!is_null($this->view->folder)) {
             $this->view->folderTitle = Application_Model_UserFolderRepository::getInstance()->getFolder($this->view->folder)->getTitle();
         }
     }
 }
 public function addAction()
 {
     $this->_helper->layout->disableLayout();
     $url = $this->getParam('u');
     $status = 2;
     if (is_null($this->_session->getSessionId())) {
         $status = 3;
     } else {
         if ($url) {
             $feads = Application_Service_Fead::getInstance()->searchFead($url);
             if (is_null($feads) || 1 !== sizeof($feads)) {
                 $status = 2;
             } else {
                 $fead = new Application_Model_Entity_Fead($feads[0]);
                 $id = Application_Model_FeadRepository::getInstance()->addFead($fead);
                 $status = 1;
             }
         }
     }
     $this->redirect("/img/webimporter/{$status}.png");
 }
Example #6
0
 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;
     }
 }
Example #7
0
 public function renameAction()
 {
     $request = $this->getRequest();
     $form = new Application_Form_FeadRename();
     $feadid = $this->getParam('id');
     if (is_null($feadid)) {
         $this->redirect('fead/manage');
     }
     $id = $this->isLoggedin()->getId();
     $fead = Application_Model_FeadRepository::getInstance()->getFeadsForUser($id, $feadid)[0];
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($request->getPost())) {
             $fead->setTitle($form->getValue('name'));
             Application_Model_UserFeadRepository::getInstance()->update($fead, $id);
             $this->redirect('fead/manage');
         }
     } else {
         $form->getElement('name')->setValue($fead->getTitle());
     }
     $this->view->form = $form;
 }
Example #8
0
 /**
  * get feads for id
  * @return Application_Model_Entity_Fead[]
  */
 public function getFeads()
 {
     return Application_Model_FeadRepository::getInstance()->getFeadsForUser($this->getId());
 }
Example #9
0
 private function printFead($fead)
 {
     $unread = Application_Model_FeadRepository::getInstance()->getUnreadCountForFead($fead->getId());
     if (1 > $unread) {
         $unread = '&nbsp';
     } else {
         if (999 < $unread) {
             $unread = 999;
         }
     }
     echo '<li data-id="' . $fead->getId() . '">
             <div class="element';
     if ('/home/fead/id/' . $fead->getId() === $this->_url) {
         echo ' selected';
     }
     echo '">
                 <p class="grid-85 tablet-grid-85 mobile-grid-85 feadTitle">
                     <a href="/home/fead/id/' . $fead->getId() . '"
                             class="feadTitle">' . $fead->getTitle() . '</a>
                 </p>
                 <p class="grid-15 tablet-grid-15 mobile-grid-15 unread">' . $unread . '</p>
                 <div class="clearfix"></div>
             </div>
         </li>';
 }