/**
  * Singleton
  * @return Application_Model_BookmarksMapper
  */
 public static function i()
 {
     if (self::$_instance == null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function deleteAction()
 {
     $request = $this->getRequest();
     $id = $request->getParam('id', null);
     if (!is_null($id)) {
         $bookmark = new Application_Model_Bookmark();
         Application_Model_BookmarksMapper::i()->find($id, $bookmark);
         if (!$bookmark->isNew()) {
             Application_Model_BookmarksMapper::i()->delete($bookmark);
         }
     }
     $this->_helper->redirector('index', 'bookmarks');
 }
 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);
 }
 /**
  * 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']));
 }