/** * Test import method * * @return void */ public function testImport() { WpHerissonBookmarksTable::truncate(); $_FILES['import_file']['tmp_name'] = $this->sampleFile; $bookmarks = $this->format->import(); $this->assertCount(20, $bookmarks); }
/** * Method to get bookmarks * * @return void */ protected function getBookmarks() { $bookmarks = WpHerissonBookmarksTable::getAll(true); $this->assertTrue(is_array($bookmarks->toArray())); $this->assertCount(20, $bookmarks); return $bookmarks; }
/** * Action to export this site's bookmarks to a file * * Redirects to indexAction() if format is not supplied * Redirects to indexAction() if an unknown format is supplied * Dispatch to an Herisson\Export method according to given format * * @see Herisson\Format * * @throws Herisson\FormatException if given export_format is unknown * * @return void */ function exportAction() { $export_format = strtolower(post('export_format')); if (!$export_format) { $this->indexAction(); $this->setView('index'); return; } try { include_once __DIR__ . "/../../Export.php"; $options = post('exportOptions'); $where = array(); $params = array(); if (isset($options['private']) && !$options['private']) { $where[] = "is_public=?"; $params[] = 1; } if (isset($options['keyword']) && $options['keyword']) { $where[] = '(t.name LIKE ? OR b.title LIKE ? OR b.url LIKE ?)'; $params[] = "%" . $options['keyword'] . "%"; $params[] = "%" . $options['keyword'] . "%"; $params[] = "%" . $options['keyword'] . "%"; } $where = implode(' AND ', $where); $bookmarks = WpHerissonBookmarksTable::getWhere($where, $params); $format = Format::getFormatByKey($export_format); $format->export($bookmarks); } catch (Format\Exception $e) { Message::i()->addError($e->getMessage()); $this->indexAction(); $this->setView('index'); } }
/** * Create a new bookmark based on an url and options * * @param array $fields the fields parameters * * @throws Herisson\Model\Exception if bookmark is duplicate * * @return the id of the bookmark created */ public static function createBookmark($fields = array()) { if (!isset($fields['url'])) { throw new Exception(__("Missing Url. Can't create bookmark")); } $url = $fields['url']; if (WpHerissonBookmarksTable::checkDuplicate($url)) { throw new Exception(__("Ignoring duplicate entry : {$url}")); } $bookmark = new WpHerissonBookmarks(); $bookmark->setProperties($fields); $bookmark->save(); if (array_key_exists('tags', $fields) && $fields['tags']) { $bookmark->setTags($fields['tags']); } return $bookmark->id; }
/** * Display import and maintenance options page * * This is the default Action * * @return void */ function indexAction() { if (post('maintenance')) { $condition = "\n LENGTH(favicon_url)=? or favicon_url is null or\n LENGTH(favicon_image)=? or favicon_image is null or\n LENGTH(content)=? or content is null or\n LENGTH(content_image)=? or content_image is null"; $bookmarks_errors = WpHerissonBookmarksTable::getWhere($condition, array(0, 0, 0, 0)); foreach ($bookmarks_errors as $b) { $b->maintenance(false); //$b->captureFromUrl(); $b->save(); } } // TODO Check for correct backups $bookmarks = WpHerissonBookmarksTable::getAll(); $this->view->total = sizeof($bookmarks); $favicon = WpHerissonBookmarksTable::getWhere("LENGTH(favicon_image)=? or favicon_image is null", array(0)); $html_content = WpHerissonBookmarksTable::getWhere("LENGTH(content)=? or content is null", array(0)); $full_content = WpHerissonBookmarksTable::getWhere("LENGTH(content)=? or content is null", array(0)); $screenshot = WpHerissonBookmarksTable::getWhere("LENGTH(content_image)=? or content_image is null", array(0)); $this->view->stats = array('favicon' => sizeof($favicon), 'html_content' => sizeof($html_content), 'full_content' => sizeof($full_content), 'screenshot' => sizeof($screenshot)); }
/** * Action to display homepage of Herisson site * * This is the default action * * @return void */ function indexAction() { $tag = get('tag'); $search = get('search'); if ($tag) { $bookmarks = WpHerissonBookmarksTable::getTag(array($tag), true); } else { if ($search) { $bookmarks = WpHerissonBookmarksTable::getSearch($search, true); } else { $bookmarks = WpHerissonBookmarksTable::getAll(true); } } $this->view->bookmarks = $bookmarks; $this->view->title = $this->options['sitename']; $this->view->friends = WpHerissonFriendsTable::getWhere("is_active=1"); foreach ($this->view->friends as $friendId => $friend) { $this->view->friendBookmarks[$friend->id] = $friend->retrieveBookmarks($_GET); } }
/** * Generate bookmarks data * * @param array $params the optional parameters to specify which bookmarks to retrieve * * @return string the json encode data for friend's bookmarks */ public function generateBookmarksData($params = array()) { $options = get_option('HerissonOptions'); $my_private_key = $options['privateKey']; $bookmarks = WpHerissonBookmarksTable::getBookmarksData($params, 1); $data_bookmarks = array(); foreach ($bookmarks as $bookmark) { $data_bookmarks[] = $bookmark->toSmallArray(); } $json_data = json_encode($data_bookmarks); try { $json_display = Encryption::i()->publicEncryptLongData($json_data, $this->public_key); } catch (Encryption\Exception $e) { Network::reply(417); echo $e->getMessage(); } return json_encode($json_display); }
/** * Test adding a new bookmark and delete it * * @return void */ public function testSearch() { // Check it's saved in the DB $bookmarks = WpHerissonBookmarksTable::getSearch('example'); $this->assertEquals(0, sizeof($bookmarks)); // Create a sample bookmark $f = new WpHerissonBookmarks(); $f->url = $this->sampleUrl; $f->save(); $f = new WpHerissonBookmarks(); $f->title = $this->sampleName; $f->save(); $f = new WpHerissonBookmarks(); $f->description = $this->sampleDescription; $f->save(); // Check it's saved in the DB $bookmarks = WpHerissonBookmarksTable::getSearch('example'); $this->assertEquals(3, sizeof($bookmarks)); // Delete it and verify it's not there anymore foreach ($bookmarks as $f) { $f->delete(); } $bookmarks = WpHerissonBookmarksTable::getSearch('example'); $this->assertEquals(0, sizeof($bookmarks)); }
/** * Action to display a bookmark content * * @return void */ function viewAction() { $id = intval(get('id')); if (!$id) { echo __("Error : Missing id\n", HERISSON_TD); exit; } $bookmark = WpHerissonBookmarksTable::get($id); if ($bookmark && $bookmark->content) { echo $bookmark->content; } else { echo sprintf(__("Error : Missing content for bookmark %s\n", HERISSON_TD), $bookmark->id); } exit; }
/** * Test setting and retrieving data * * @return void */ public function testCreateSaveAndRetrieve() { $datas = $this->fakeFields; $b = $this->_getBookmark($datas); $sql = array(); foreach ($datas as $key => $value) { $sql[] = "{$key}=?"; } // Check it's saved in the DB, with all parameters $bookmarks = WpHerissonBookmarksTable::getWhere(implode(' AND ', $sql), array_values($datas)); $this->assertEquals(1, sizeof($bookmarks)); // Retrieve the id $g = WpHerissonBookmarksTable::get($b->id); foreach ($datas as $key => $value) { $this->assertEquals($value, $g->{$key}); } // Cleanup $g->delete(); }
/** * Action to list existing backups * * This is the default action * * @return void */ function indexAction() { $this->view->backups = \Doctrine_Query::create()->from('Herisson\\Model\\WpHerissonBackups b')->execute(); $this->view->localbackups = \Doctrine_Query::create()->from('Herisson\\Model\\WpHerissonLocalbackups b')->execute(); $this->view->nbBookmarks = WpHerissonBookmarksTable::countAll(); $this->view->sizeBookmarks = WpHerissonBookmarksTable::getTableSize(); $friends = \Doctrine_Query::create()->from('Herisson\\Model\\WpHerissonFriends f')->orderby('name')->execute(); $this->view->friends = array(); foreach ($friends as $friend) { $this->view->friends[$friend->id] = $friend; } }