/** * checks whether a feed exists or not * * @return boolean * @param int $value feed id */ public function isValid($value) { $feeds = new application_models_feeds(); if ($feeds->fetchAll($feeds->select()->where("id=?", $value))->count() == 0) { $this->_error(application_validate_feedid::NOT_EXISTS); return false; } return true; }
/** * checks whether a feed entry already exists or not * * @return boolean * @param string $value url */ public function isValid($value) { $feeds = new application_models_feeds(); $select = $feeds->select()->where("url=?", $value)->where("source=?", $this->source); if ($this->id) { $select->where("id!=?", $this->id); } if ($feeds->fetchAll($select)->count() > 0) { $this->_error(application_validate_duplicatefeed::ALREADY_EXISTS); return false; } return true; }
/** * set feedlist data for the current view * * @return void */ protected function feedlistData() { // check whether uncategorized exists or not (add it if not) $categoriesModel = new application_models_categories(); $categoriesModel->checkUncategorized(); // categories and feeds (target template param) $this->view->categories = array(); // load unread items $itemCounter = Zend_Controller_Action_HelperBroker::getStaticHelper('itemcounter'); $unreadCategory = $itemCounter->unreadItemsCategories(); $unreadFeed = $itemCounter->unreadItemsFeeds(); // get open categories if (Zend_Registry::get('session')->saveOpenCategories == 1) { $open = explode(',', Zend_Registry::get('session')->openCategories); } else { $open = array(); } // load categories $categoriesDb = $categoriesModel->fetchAll($categoriesModel->select()->order('position ASC')); $feedPositions = Zend_Controller_Action_HelperBroker::getStaticHelper('icon')->getFeedsIconPosition(); // read feeds and count items of the loaded categories $feedsModel = new application_models_feeds(); foreach ($categoriesDb as $cat) { $newcat = $cat->toArray(); // get feeds of cat $feedRowset = $cat->findDependentRowset('application_models_feeds', null, $feedsModel->select()->order('position ASC')); $newcat['feeds'] = array(); foreach ($feedRowset as $feed) { $newfeed = $feed->toArray(); $newfeed['unread'] = isset($unreadFeed[$feed->id]) ? $unreadFeed[$feed->id] : 0; $newfeed['iconposition'] = $feedPositions[$feed->id]; $newcat['feeds'][] = $newfeed; } // get unread items of cat $newcat['unread'] = isset($unreadCategory[$cat->id]) ? $unreadCategory[$cat->id] : 0; // set open (feeds visible) or not if (in_array($cat->id, $open)) { $newcat['open'] = true; } else { $newcat['open'] = false; } // append category $this->view->categories[] = $newcat; } // count starred items $this->view->starred = $itemCounter->starredItems(); // count unread items $this->view->unread = $unreadCategory[0]; // count all items $this->view->all = $itemCounter->allItems(); // count read items $this->view->read = $this->view->all - $this->view->unread; // count feeds $this->view->amountfeeds = $feedsModel->count(Zend_Registry::get('session')->currentPriorityStart, Zend_Registry::get('session')->currentPriorityEnd, Zend_Registry::get('session')->view); }
/** * return feed positions * * @return array of feed positions */ public function getFeedsIconPosition() { if ($this->iconPositions == false) { $feedsModel = new application_models_feeds(); $feeds = $feedsModel->fetchAll($feedsModel->select()->order('id ASC')); $feedPositions = array(); $count = 0; foreach ($feeds as $feed) { $feedPositions[$feed->id] = $count++; } $this->iconPositions = $feedPositions; } return $this->iconPositions; }
/** * insert given feeds * * @return void * @param int $category id * @param array $feeds as array */ protected function insertFeeds($category, $feeds) { $feedsModel = new application_models_feeds(); // insert unkown feeds foreach ($feeds as $feed) { // search existing feed $moreFeeds = $feedsModel->fetchAll($feedsModel->select()->where($feedsModel->getAdapter()->quoteInto('url=?', trim($feed['link'])))); // if feed doesn't exists if ($moreFeeds->count() == 0) { $feedsModel->add(array('name' => trim($feed['title']), 'url' => trim($feed['link']), 'category' => $category, 'priority' => 1, 'source' => 'plugins_rss_feed')); } } // fix positions $categoriesModel = new application_models_categories(); $categoriesModel->fixPositions($categoriesModel->find($category)->current()); }