/** * set all categories with given data * * @return array|bool error messages as array or true on success * @param array $categories new categories as array */ public function setCategories($categories) { // validate given categories $validationResult = $this->validate($categories); if ($validationResult !== true) { return $validationResult; } // error found // delete all categories parent::delete('id!=0'); // insert all categories foreach ($categories as $cat) { parent::insert($cat); } // remove feeds from deleted categories $db = Zend_Registry::get('bootstrap')->getPluginResource('db')->getDbAdapter(); $p = Zend_Registry::get('config')->resources->db->prefix; $db->query("UPDATE " . $p . "feeds \r\n SET category=-1 \r\n WHERE category NOT IN (\r\n SELECT id FROM " . $p . "categories\r\n )"); // return success return true; }
/** * will be executed by the javascript ajax call * and signals that it finished successfully a complete * update using ajax * * @return void */ public function finishAction() { $logger = Zend_Registry::get('logger'); // set lastrefresh if timeout is already 0 $updater = Zend_Controller_Action_HelperBroker::getStaticHelper('updater'); if ($updater->timeout() == 0) { // save last refresh (current session will also be updated by models save) $lastrefresh = Zend_Date::now()->get(Zend_Date::TIMESTAMP); $settingsModel = new application_models_settings(); $settingsModel->save(array('lastrefresh' => $lastrefresh)); // delete orphaned thumbnails $updater->cleanupThumbnails(); $logger->log('delete orphaned thumbnails', Zend_Log::DEBUG); // optimize database application_models_base::optimizeDatabase(); $logger->log('database successfully optimized', Zend_Log::DEBUG); $logger->log('finished ajax update', Zend_Log::DEBUG); } // return new timeout and unread items $itemCounter = Zend_Controller_Action_HelperBroker::getStaticHelper('itemcounter'); $this->_helper->json(array('timeout' => $updater->timeout(), 'lastrefresh' => isset($lastrefresh) ? $lastrefresh : Zend_Registry::get('session')->lastrefresh, 'categories' => $itemCounter->unreadItemsCategories(), 'feeds' => $itemCounter->unreadItemsFeeds())); }
/** * returns an validator for settings params or error array * * @return Zend_Filter_Input|array on success data on error message array * @param array $data current data for validation */ public function validate($data) { // define filter $filterTrim = new Zend_Filter_StringTrim(); $filter = array('deleteItems' => $filterTrim, 'imagesPosition' => $filterTrim, 'imagesHeight' => $filterTrim, 'language' => $filterTrim, 'refresh' => $filterTrim, 'lastrefresh' => $filterTrim, 'view' => $filterTrim, 'offset' => $filterTrim, 'itemsperpage' => $filterTrim, 'selected' => $filterTrim, 'dateFilter' => $filterTrim, 'dateStart' => $filterTrim, 'dateEnd' => $filterTrim, 'search' => $filterTrim, 'unread' => $filterTrim, 'starred' => $filterTrim, 'currentPriorityStart' => $filterTrim, 'currentPriorityEnd' => $filterTrim, 'saveOpenCategories' => $filterTrim, 'openCategories' => $filterTrim, 'firstUnread' => $filterTrim, 'newWindow' => $filterTrim, 'public' => $filterTrim, 'anonymizer' => $filterTrim, 'sort' => $filterTrim, 'openitems' => $filterTrim, 'iconcache' => $filterTrim); // define validators $validatorType = new Zend_Validate_InArray(array("both", "multimedia", "messages")); $validatorType->setMessage(Zend_Registry::get('language')->translate('Only both, multimedia, message allowed'), Zend_Validate_InArray::NOT_IN_ARRAY); $validatorNotEmpty = new Zend_Validate_NotEmpty(); $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY); $validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language); $validatorNum->setLocale(Zend_Registry::get('session')->language); $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT); $validatorInArray = new Zend_Validate_InArray(array("top", "bottom")); $validatorInArray->setMessage(Zend_Registry::get('language')->translate('Only top or bottom allowed'), Zend_Validate_InArray::NOT_IN_ARRAY); $validatorLanguage = new Zend_Validate_InArray(Zend_Registry::get('language')->getList()); $validatorLanguage->setMessage(Zend_Registry::get('language')->translate('Language is not available'), Zend_Validate_InArray::NOT_IN_ARRAY); $validatorDate = new Zend_Validate_Date(); $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::INVALID); $validatorDate->setMessage(Zend_Registry::get('language')->translate('No valid date given'), Zend_Validate_Date::FALSEFORMAT); $validatorBiggerThanZero = new Zend_Validate_GreaterThan(0); $validatorBiggerThanZero->setMessage(Zend_Registry::get('language')->translate('Value must be bigger than 0'), Zend_Validate_GreaterThan::NOT_GREATER); $validatorBetweenDays = new Zend_Validate_Between(0, 2000); $validatorBetweenDays->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 2000 days'), Zend_Validate_Between::NOT_BETWEEN); $validatorBetweenItemsperpage = new Zend_Validate_Between(0, 200); $validatorBetweenItemsperpage->setMessage(Zend_Registry::get('language')->translate('Please choose a value between 0 and 200 items per page'), Zend_Validate_Between::NOT_BETWEEN); $validatorSort = new Zend_Validate_InArray(array("date", "dateasc", "priority", "priorityasc")); $validatorSort->setMessage(Zend_Registry::get('language')->translate('Only date or rating allowed'), Zend_Validate_InArray::NOT_IN_ARRAY); $validators = array('deleteItems' => array($validatorNum, $validatorBetweenDays, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'imagesPosition' => array($validatorInArray, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'language' => array($validatorLanguage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'refresh' => array($validatorNum, $validatorBiggerThanZero, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'lastrefresh' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'view' => array($validatorType, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'offset' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'itemsperpage' => array($validatorNum, $validatorBetweenItemsperpage, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'selected' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'dateFilter' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'search' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'unread' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'starred' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityStart' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'currentPriorityEnd' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'saveOpenCategories' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'openCategories' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'firstUnread' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'newWindow' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'public' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'anonymizer' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'sort' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, $validatorSort), 'openitems' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'iconcache' => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL)); // optional check date if (isset($data['dateFilter']) && $data['dateFilter'] == 1) { $validators['dateStart'] = $validatorDate; $validators['dateEnd'] = $validatorDate; } else { $validators['dateStart'] = array(Zend_Filter_Input::ALLOW_EMPTY => true); $validators['dateEnd'] = array(Zend_Filter_Input::ALLOW_EMPTY => true); $data['dateStart'] = ''; $data['dateEnd'] = ''; } // create validation main object $validator = new Zend_Filter_Input($filter, $validators, $data, array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false)); // return filter input object return parent::validate($validator); }
/** * validates feed input * * @return Zend_Filter_Input|array validator or error message array * @param array $data for validating * @param int $validateid (optional) indicates whether id has to be validated */ protected function validate($data, $validateId = false) { // define filter $filterTrim = new Zend_Filter_StringTrim(); $filter = array('name' => $filterTrim, 'url' => $filterTrim, 'category' => $filterTrim, 'priority' => $filterTrim, 'favicon' => $filterTrim, 'filter' => $filterTrim, 'source' => $filterTrim); if (!isset($data['source'])) { $data['source'] = ''; } // define validators $validatorNotEmpty = new Zend_Validate_NotEmpty(); $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY); $validatorCategoryId = new application_validate_categoryid(); $validatorCategoryId->setMessage(Zend_Registry::get('language')->translate("category doesn't exists"), application_validate_categoryid::NOT_EXISTS); $validatorSource = new application_validate_source(); $validatorSource->setMessage(Zend_Registry::get('language')->translate("source doesn't exists"), application_validate_source::NOT_EXISTS); $validatorNum = new Zend_Validate_Int(Zend_Registry::get('session')->language); $validatorNum->setLocale(Zend_Registry::get('session')->language); $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::NOT_INT); $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Int::INVALID); $validatorDuplicateFeed = new application_validate_duplicatefeed($data['source'], $validateId ? $data['id'] : false); $validatorDuplicateFeed->setMessage(Zend_Registry::get('language')->translate("feed already exists"), application_validate_duplicatefeed::ALREADY_EXISTS); $validators = array('name' => array($validatorNotEmpty, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'url' => array($validatorDuplicateFeed, Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'category' => array($validatorNum, $validatorCategoryId, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'priority' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'favicon' => array(Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, Zend_Filter_Input::ALLOW_EMPTY => true), 'filter' => array(Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL, Zend_Filter_Input::ALLOW_EMPTY => true), 'source' => array($validatorNotEmpty, $validatorSource, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED)); // read from source whether url is optional or not if ($validatorSource->isValid($data['source'])) { $plugin = Zend_Controller_Action_HelperBroker::getStaticHelper('pluginloader')->getPlugin($data['source']); if (!$plugin->sourceOptional && $plugin->source !== false) { $validators['url'] = array($validatorNotEmpty, $validatorDuplicateFeed, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED); } } // insert filter and validate rules for id if ($validateId !== false) { $validatorFeedId = new application_validate_feedid(); $validatorFeedId->setMessage(Zend_Registry::get('language')->translate("feed doesn't exists"), application_validate_feedid::NOT_EXISTS); $filter['id'] = $filterTrim; $validators['id'] = array($validatorNum, $validatorFeedId, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED); } // create validation main object $validator = new Zend_Filter_Input($filter, $validators, $data, array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false)); // return filter input object return parent::validate($validator); }
/** * set up metadata as other reference table objects * and dependend table objects * * @return void */ protected function _setupMetadata() { $this->_dependentTables = array(); parent::_setupMetadata(); }
/** * set up metadata as other reference table objects * and dependend table objects * * @return void */ protected function _setupMetadata() { $this->_referenceMap = array('messages' => array('columns' => 'feed', 'refTableClass' => 'application_models_feeds', 'refColumn' => 'id')); parent::_setupMetadata(); }