public function bookmarkAction() { $csrf = new Zend_Form_Element_Hash('csrf', array('salt' => __CLASS__)); $validCheck = $csrf->isValid($this->getRequest()->getParam('csrf', false)); $csrf->initCsrfToken(); $hash = $csrf->getHash(); $return = array('success' => true, 'api' => array('resolver' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'resolver', 'csrf' => $hash)), 'adder' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'add', 'csrf' => $hash)), 'bookmark' => $this->_helper->url->url(array('controller' => 'bookmarklets', 'action' => 'bookmark', 'csrf' => $hash)))); if ($validCheck) { $url = $this->getRequest()->getParam("url", false); $title = strip_tags($this->getRequest()->getParam("title", false)); $description = strip_tags($this->getRequest()->getParam("description", false)); $thumbnail = $this->getRequest()->getParam("thumbnail", false); $ua = $this->getRequest()->getParam("ua", false); $cookies = $this->getRequest()->getParam("cookies", false); if ($url && $title) { $model = new Application_Model_Bookmark(); $model->setUrl($url); $model->setTitle($title); if ($thumbnail) { $model->setThumbnail($thumbnail); } if ($description) { $model->setDescription($description); } if ($ua) { $model->setUa($ua); } if ($cookies) { $model->setCookies($cookies); } try { Application_Model_BookmarksMapper::i()->save($model); } catch (Exception $e) { X_Debug::e("DB Error: {$e->getMessage()}"); $return['success'] = false; } } else { X_Debug::e("Missing data"); $return['success'] = false; } } else { X_Debug::e("Invalid CSRF"); $return['success'] = false; } $this->_helper->json($return, true, false); }
public function delete(Application_Model_Bookmark $model) { $this->getDbTable()->delete(array('id = ?' => $model->getId())); }
/** * Restore backupped videos * This is not a trigger of plugin API. It's called by Backupper plugin */ function restoreItems($items) { $models = Application_Model_BookmarksMapper::i()->fetchAll(); // cleaning up all shares foreach ($models as $model) { Application_Model_BookmarksMapper::i()->delete($model); } foreach (@$items['pages'] as $modelInfo) { $model = new Application_Model_Bookmark(); $model->setOptions($modelInfo); $model->setId(false); // i don't set id, or db adapter will try to update old data that i cleaned Application_Model_BookmarksMapper::i()->save($model); } return X_Env::_('p_bookmarks_backupper_restoreditems', count($items['pages'])); }