/** * 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'); } }
/** * 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)); }
/** * Test checkDuplicate method * * @return void */ public function testCheckDuplicate() { $duplicate = WpHerissonBookmarksTable::checkDuplicate($this->sampleUrl); $this->assertFalse($duplicate); $f = new WpHerissonBookmarks(); $f->title = $this->sampleName; $f->save(); $duplicate = WpHerissonBookmarksTable::checkDuplicate($this->sampleUrl); $this->assertFalse($duplicate); // Create a sample bookmark $f = new WpHerissonBookmarks(); $f->url = $this->sampleUrl; $f->save(); $duplicate = WpHerissonBookmarksTable::checkDuplicate($this->sampleUrl); $this->assertTrue($duplicate); $bookmarks = WpHerissonBookmarksTable::getWhere("url=?", array($this->sampleUrl)); $this->assertEquals(1, sizeof($bookmarks)); // Delete it and verify it's not there anymore foreach ($bookmarks as $f) { $f->delete(); } $duplicate = WpHerissonBookmarksTable::checkDuplicate($this->sampleUrl); $this->assertFalse($duplicate); }
/** * 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(); }