Add a persistent 'shorturl' key to all links

All existing link will keep their permalinks.
New links will have smallhash generated with date+id.

The purpose of this is to avoid collision between links due to their creation date.
This commit is contained in:
ArthurHoaro 2016-11-28 18:24:15 +01:00
parent c3dfd89959
commit d592daea83
15 changed files with 115 additions and 91 deletions

View file

@ -143,7 +143,7 @@ public function buildData()
*/
protected function buildItem($link, $pageaddr)
{
$link['guid'] = $pageaddr .'?'. smallHash($link['created']->format('Ymd_His'));
$link['guid'] = $pageaddr .'?'. $link['shorturl'];
// Check for both signs of a note: starting with ? and 7 chars long.
if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
$link['url'] = $pageaddr . $link['url'];

View file

@ -22,6 +22,7 @@
* Can be absolute or relative.
* Relative URLs are permalinks (e.g.'?m-ukcw')
* - real_url Absolute processed URL.
* - shorturl Permalink smallhash
*
* Implements 3 interfaces:
* - ArrayAccess: behaves like an associative array;
@ -264,6 +265,7 @@ private function check()
'created'=> new DateTime(),
'tags'=>'opensource software'
);
$link['shorturl'] = link_small_hash($link['created'], $link['id']);
$this->links[1] = $link;
$link = array(
@ -273,8 +275,9 @@ private function check()
'description'=>'Shhhh! I\'m a private link only YOU can see. You can delete me too.',
'private'=>1,
'created'=> new DateTime('1 minute ago'),
'tags'=>'secretstuff'
'tags'=>'secretstuff',
);
$link['shorturl'] = link_small_hash($link['created'], $link['id']);
$this->links[0] = $link;
// Write database to disk
@ -335,10 +338,11 @@ private function read()
// To be able to load links before running the update, and prepare the update
if (! isset($link['created'])) {
$link['id'] = $link['linkdate'];
$link['created'] = DateTime::createFromFormat('Ymd_His', $link['linkdate']);
$link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']);
if (! empty($link['updated'])) {
$link['updated'] = DateTime::createFromFormat('Ymd_His', $link['updated']);
$link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']);
}
$link['shorturl'] = smallHash($link['linkdate']);
}
}
@ -558,7 +562,7 @@ public function getNextId()
*
* @param int $id Persistent ID of a link.
*
* @return int Real offset in local array, or null if doesn't exists.
* @return int Real offset in local array, or null if doesn't exist.
*/
protected function getLinkOffset($id)
{

View file

@ -120,7 +120,7 @@ private function filterSmallHash($smallHash)
{
$filtered = array();
foreach ($this->links as $key => $l) {
if ($smallHash == smallHash($l['created']->format('Ymd_His'))) {
if ($smallHash == $l['shorturl']) {
// Yes, this is ugly and slow
$filtered[$key] = $l;
return $filtered;

View file

@ -169,3 +169,16 @@ function space2nbsp($text)
function format_description($description, $redirector = '', $indexUrl = '') {
return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl)));
}
/**
* Generate a small hash for a link.
*
* @param DateTime $date Link creation date.
* @param int $id Link ID.
*
* @return string the small hash generated from link data.
*/
function link_small_hash($date, $id)
{
return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id);
}

View file

@ -174,6 +174,7 @@ public static function import($post, $files, $linkDb, $pagecache)
$newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
$newLink['created'] = $newLinkDate;
$newLink['id'] = $linkDb->getNextId();
$newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']);
$linkDb[$newLink['id']] = $newLink;
$importCount++;
}

View file

@ -223,6 +223,9 @@ public function updateMethodEscapeUnescapedConfig()
* Since this update is very sensitve (changing the whole database), the datastore will be
* automatically backed up into the file datastore.<datetime>.php.
*
* LinkDB also adds the field 'shorturl' with the precedent format (linkdate smallhash),
* which will be saved by this method.
*
* @return bool true if the update is successful, false otherwise.
*/
public function updateMethodDatastoreIds()

View file

@ -31,7 +31,11 @@ function logm($logFile, $clientIp, $message)
* - are NOT cryptographically secure (they CAN be forged)
*
* In Shaarli, they are used as a tinyurl-like link to individual entries,
* e.g. smallHash('20111006_131924') --> yZH23w
* built once with the combination of the date and item ID.
* e.g. smallHash('20111006_131924' . 142) --> eaWxtQ
*
* @warning before v0.8.1, smallhashes were built only with the date,
* and their value has been preserved.
*
* @param string $text Create a hash from this text.
*

View file

@ -566,21 +566,17 @@ function showDailyRSS($conf) {
/* Some Shaarlies may have very few links, so we need to look
back in time until we have enough days ($nb_of_days).
*/
$ids = array();
foreach ($LINKSDB as $id => $value) {
$ids[] = $id;
}
$nb_of_days = 7; // We take 7 days.
$today = date('Ymd');
$days = array();
foreach ($ids as $id) {
$day = $LINKSDB[$id]['created']->format('Ymd'); // Extract day (without time)
foreach ($LINKSDB as $link) {
$day = $link['created']->format('Ymd'); // Extract day (without time)
if (strcmp($day, $today) < 0) {
if (empty($days[$day])) {
$days[$day] = array();
}
$days[$day][] = $id;
$days[$day][] = $link;
}
if (count($days) > $nb_of_days) {
@ -600,23 +596,18 @@ function showDailyRSS($conf) {
echo '<copyright>'. $pageaddr .'</copyright>'. PHP_EOL;
// For each day.
foreach ($days as $day => $ids) {
foreach ($days as $day => $links) {
$dayDate = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $day.'_000000');
$absurl = escape(index_url($_SERVER).'?do=daily&day='.$day); // Absolute URL of the corresponding "Daily" page.
// Build the HTML body of this RSS entry.
$links = array();
// We pre-format some fields for proper output.
foreach ($ids as $id) {
$l = $LINKSDB[$id];
$l['formatedDescription'] = format_description($l['description'], $conf->get('redirector.url'));
$l['thumbnail'] = thumbnail($conf, $l['url']);
$l['timestamp'] = $l['created']->getTimestamp();
if (startsWith($l['url'], '?')) {
$l['url'] = index_url($_SERVER) . $l['url']; // make permalink URL absolute
foreach ($links as &$link) {
$link['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url'));
$link['thumbnail'] = thumbnail($conf, $link['url']);
$link['timestamp'] = $link['created']->getTimestamp();
if (startsWith($link['url'], '?')) {
$link['url'] = index_url($_SERVER) . $link['url']; // make permalink URL absolute
}
$links[$id] = $l;
}
// Then build the HTML for this day:
@ -675,7 +666,6 @@ function showDaily($pageBuilder, $LINKSDB, $conf, $pluginManager)
$taglist = explode(' ',$link['tags']);
uasort($taglist, 'strcasecmp');
$linksToDisplay[$key]['shorturl'] = smallHash($link['created']->format('Ymd_His'));
$linksToDisplay[$key]['taglist']=$taglist;
$linksToDisplay[$key]['formatedDescription'] = format_description($link['description'], $conf->get('redirector.url'));
$linksToDisplay[$key]['thumbnail'] = thumbnail($conf, $link['url']);
@ -829,7 +819,7 @@ function renderPage($conf, $pluginManager)
// Get only links which have a thumbnail.
foreach($links as $link)
{
$permalink='?'.escape(smallHash($link['created']->format('Ymd_His')));
$permalink='?'.$link['shorturl'];
$thumb=lazyThumbnail($conf, $link['url'],$permalink);
if ($thumb!='') // Only output links which have a thumbnail.
{
@ -1249,7 +1239,7 @@ function renderPage($conf, $pluginManager)
}
// lf_id should only be present if the link exists.
$id = !empty($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : $LINKSDB->getNextId();
$id = !empty($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : $LINKSDB->getNextId();
// Linkdate is kept here to:
// - use the same permalink for notes as they're displayed when creating them
// - let users hack creation date of their posts
@ -1257,11 +1247,11 @@ function renderPage($conf, $pluginManager)
$linkdate = escape($_POST['lf_linkdate']);
if (isset($LINKSDB[$id])) {
// Edit
$created = DateTime::createFromFormat('Ymd_His', $linkdate);
$created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
$updated = new DateTime();
} else {
// New link
$created = DateTime::createFromFormat('Ymd_His', $linkdate);
$created = DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $linkdate);
$updated = null;
}
@ -1288,7 +1278,8 @@ function renderPage($conf, $pluginManager)
'private' => (isset($_POST['lf_private']) ? 1 : 0),
'created' => $created,
'updated' => $updated,
'tags' => str_replace(',', ' ', $tags)
'tags' => str_replace(',', ' ', $tags),
'shorturl' => link_small_hash($created, $id),
);
// If title is empty, use the URL as title.
@ -1311,7 +1302,7 @@ function renderPage($conf, $pluginManager)
$returnurl = !empty($_POST['returnurl']) ? $_POST['returnurl'] : '?';
$location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
// Scroll to the link which has been edited.
$location .= '#' . smallHash($created->format('Ymd_His'));
$location .= '#' . $link['shorturl'];
// After saving the link, redirect to the page the user was on.
header('Location: '. $location);
exit;
@ -1325,7 +1316,7 @@ function renderPage($conf, $pluginManager)
$link = $LINKSDB[(int) escape($_POST['lf_id'])];
$returnurl = ( isset($_POST['returnurl']) ? $_POST['returnurl'] : '?' );
// Scroll to the link which has been edited.
$returnurl .= '#'.smallHash($link['created']->format('Ymd_His'));
$returnurl .= '#'. $link['shorturl'];
$returnurl = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
header('Location: '.$returnurl); // After canceling, redirect to the page the user was on.
exit;
@ -1341,7 +1332,7 @@ function renderPage($conf, $pluginManager)
// - we are protected from XSRF by the token.
// FIXME! We keep `lf_linkdate` for consistency before a proper API. To be removed.
$id = isset($_POST['lf_id']) ? (int) escape($_POST['lf_id']) : (int) escape($_POST['lf_linkdate']);
$id = isset($_POST['lf_id']) ? intval(escape($_POST['lf_id'])) : intval(escape($_POST['lf_linkdate']));
$pluginManager->executeHooks('delete_link', $LINKSDB[$id]);
@ -1387,7 +1378,7 @@ function renderPage($conf, $pluginManager)
$id = (int) escape($_GET['edit_link']);
$link = $LINKSDB[$id]; // Read database
if (!$link) { header('Location: ?'); exit; } // Link not found in database.
$link['linkdate'] = $link['created']->format('Ymd_His');
$link['linkdate'] = $link['created']->format(LinkDB::LINK_DATE_FORMAT);
$data = array(
'link' => $link,
'link_is_new' => false,
@ -1414,7 +1405,7 @@ function renderPage($conf, $pluginManager)
if (! $link)
{
$link_is_new = true;
$linkdate = strval(date('Ymd_His'));
$linkdate = strval(date(LinkDB::LINK_DATE_FORMAT));
// Get title if it was provided in URL (by the bookmarklet).
$title = empty($_GET['title']) ? '' : escape($_GET['title']);
// Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
@ -1438,7 +1429,7 @@ function renderPage($conf, $pluginManager)
}
if ($url == '') {
$url = '?' . smallHash($linkdate);
$url = '?' . smallHash($linkdate . $LINKSDB->getNextId());
$title = 'Note: ';
}
$url = escape($url);
@ -1453,7 +1444,7 @@ function renderPage($conf, $pluginManager)
'private' => $private
);
} else {
$link['linkdate'] = $link['created']->format('Ymd_His');
$link['linkdate'] = $link['created']->format(LinkDB::LINK_DATE_FORMAT);
}
$data = array(
@ -1668,7 +1659,6 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
$taglist = explode(' ', $link['tags']);
uasort($taglist, 'strcasecmp');
$link['taglist'] = $taglist;
$link['shorturl'] = smallHash($link['created']->format('Ymd_His'));
// Check for both signs of a note: starting with ? and 7 chars long.
if ($link['url'][0] === '?' &&
strlen($link['url']) === 7) {

View file

@ -43,9 +43,7 @@ function hook_isso_render_linklist($data, $conf)
$link = reset($data['links']);
$issoHtml = file_get_contents(PluginManager::$PLUGINS_PATH . '/isso/isso.html');
// FIXME! KO thread unique si même date
$linkDate = $link['created']->format('Ymd_His');
$isso = sprintf($issoHtml, $issoUrl, $issoUrl, $linkDate, $linkDate);
$isso = sprintf($issoHtml, $issoUrl, $issoUrl, $link['id'], $link['id']);
$data['plugin_end_zone'][] = $isso;
// Hackish way to include this CSS file only when necessary.

View file

@ -86,7 +86,7 @@ public function testRSSBuildData()
// Test first link (note link)
$link = reset($data['links']);
$this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
$this->assertRegExp('/Tue, 10 Mar 2015 11:46:51 \+\d{4}/', $link['pub_iso_date']);
@ -140,7 +140,7 @@ public function testBuildDataFiltered()
$this->assertEquals(1, count($data['links']));
$link = array_shift($data['links']);
$this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
}
/**
@ -157,7 +157,7 @@ public function testBuildDataCount()
$this->assertEquals(1, count($data['links']));
$link = array_shift($data['links']);
$this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
}
/**
@ -174,7 +174,7 @@ public function testBuildDataPermalinks()
// First link is a permalink
$link = array_shift($data['links']);
$this->assertEquals(41, $link['id']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114651'), $link['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'), $link['created']);
$this->assertEquals('http://host.tld/?WDWyig', $link['guid']);
$this->assertEquals('http://host.tld/?WDWyig', $link['url']);
$this->assertContains('Direct link', $link['description']);
@ -182,7 +182,7 @@ public function testBuildDataPermalinks()
// Second link is a direct link
$link = array_shift($data['links']);
$this->assertEquals(8, $link['id']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20150310_114633'), $link['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'), $link['created']);
$this->assertEquals('http://host.tld/?RttfEw', $link['guid']);
$this->assertEquals('https://static.fsf.org/nosvn/faif-2.0.pdf', $link['url']);
$this->assertContains('Direct link', $link['description']);

View file

@ -191,7 +191,7 @@ public function testSave()
'url'=>'http://dum.my',
'description'=>'One more',
'private'=>0,
'created'=> DateTime::createFromFormat('Ymd_His', '20150518_190000'),
'created'=> DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150518_190000'),
'tags'=>'unit test'
);
$testDB[$link['id']] = $link;
@ -447,17 +447,17 @@ public function testFilterHashInValid()
*/
public function testReorderLinksDesc()
{
self::$publicLinkDB->reorder('ASC');
$linkIdToTest = 42;
foreach (self::$publicLinkDB as $key => $value) {
$this->assertEquals($linkIdToTest, $key);
break;
self::$privateLinkDB->reorder('ASC');
$linkIds = array(42, 4, 1, 0, 7, 6, 8, 41);
$cpt = 0;
foreach (self::$privateLinkDB as $key => $value) {
$this->assertEquals($linkIds[$cpt++], $key);
}
self::$publicLinkDB->reorder('DESC');
$linkIdToTest = 41;
foreach (self::$publicLinkDB as $key => $value) {
$this->assertEquals($linkIdToTest, $key);
break;
self::$privateLinkDB->reorder('DESC');
$linkIds = array_reverse($linkIds);
$cpt = 0;
foreach (self::$privateLinkDB as $key => $value) {
$this->assertEquals($linkIds[$cpt++], $key);
}
}
}

View file

@ -116,7 +116,7 @@ public function testImportInternetExplorerEncoding()
$this->assertEquals(
array(
'id' => 0,
'created' => DateTime::createFromFormat('Ymd_His', '20160618_203944'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160618_203944'),
'title' => 'Hg Init a Mercurial tutorial by Joel Spolsky',
'url' => 'http://hginit.com/',
'description' => '',
@ -145,7 +145,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 0,
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235541'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235541'),
'title' => 'Nested 1',
'url' => 'http://nest.ed/1',
'description' => '',
@ -158,7 +158,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 1,
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235542'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235542'),
'title' => 'Nested 1-1',
'url' => 'http://nest.ed/1-1',
'description' => '',
@ -171,7 +171,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 2,
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235547'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235547'),
'title' => 'Nested 1-2',
'url' => 'http://nest.ed/1-2',
'description' => '',
@ -184,7 +184,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 3,
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
'title' => 'Nested 2-1',
'url' => 'http://nest.ed/2-1',
'description' => 'First link of the second section',
@ -197,7 +197,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 4,
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
'title' => 'Nested 2-2',
'url' => 'http://nest.ed/2-2',
'description' => 'Second link of the second section',
@ -210,7 +210,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 5,
'created' => DateTime::createFromFormat('Ymd_His', '20160202_202222'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160202_202222'),
'title' => 'Nested 3-1',
'url' => 'http://nest.ed/3-1',
'description' => '',
@ -223,7 +223,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 6,
'created' => DateTime::createFromFormat('Ymd_His', '20160119_230227'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160119_230227'),
'title' => 'Nested 3-2',
'url' => 'http://nest.ed/3-2',
'description' => '',
@ -236,7 +236,7 @@ public function testImportNested()
$this->assertEquals(
array(
'id' => 7,
'created' => DateTime::createFromFormat('Ymd_His', '20160229_111541'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160229_111541'),
'title' => 'Nested 2',
'url' => 'http://nest.ed/2',
'description' => '',
@ -269,7 +269,7 @@ public function testImportDefaultPrivacyNoPost()
array(
'id' => 0,
// Old link - UTC+4 (note that TZ in the import file is ignored).
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
'title' => 'Secret stuff',
'url' => 'https://private.tld',
'description' => "Super-secret stuff you're not supposed to know about",
@ -282,7 +282,7 @@ public function testImportDefaultPrivacyNoPost()
$this->assertEquals(
array(
'id' => 1,
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
'title' => 'Public stuff',
'url' => 'http://public.tld',
'description' => '',
@ -313,7 +313,7 @@ public function testImportKeepPrivacy()
array(
'id' => 0,
// Note that TZ in the import file is ignored.
'created' => DateTime::createFromFormat('Ymd_His', '20001010_135536'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20001010_135536'),
'title' => 'Secret stuff',
'url' => 'https://private.tld',
'description' => "Super-secret stuff you're not supposed to know about",
@ -326,7 +326,7 @@ public function testImportKeepPrivacy()
$this->assertEquals(
array(
'id' => 1,
'created' => DateTime::createFromFormat('Ymd_His', '20160225_235548'),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160225_235548'),
'title' => 'Public stuff',
'url' => 'http://public.tld',
'description' => '',

View file

@ -352,20 +352,20 @@ public function testDatastoreIds()
$this->assertEquals('Naming conventions... #private', $linkDB[0]['description']);
$this->assertEquals('samba cartoon web', $linkDB[0]['tags']);
$this->assertTrue($linkDB[0]['private']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_142300'), $linkDB[0]['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'), $linkDB[0]['created']);
$this->assertTrue(isset($linkDB[1]));
$this->assertFalse(isset($linkDB[1]['linkdate']));
$this->assertEquals(1, $linkDB[1]['id']);
$this->assertEquals('UserFriendly - Samba', $linkDB[1]['title']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_172539'), $linkDB[1]['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'), $linkDB[1]['created']);
$this->assertTrue(isset($linkDB[2]));
$this->assertFalse(isset($linkDB[2]['linkdate']));
$this->assertEquals(2, $linkDB[2]['id']);
$this->assertEquals('Geek and Poke', $linkDB[2]['title']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_182539'), $linkDB[2]['created']);
$this->assertEquals(DateTime::createFromFormat('Ymd_His', '20121206_190301'), $linkDB[2]['updated']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'), $linkDB[2]['created']);
$this->assertEquals(DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_190301'), $linkDB[2]['updated']);
}
/**

View file

@ -52,8 +52,9 @@ function testIssoDisplayed()
'title' => $str,
'links' => array(
array(
'id' => 12,
'url' => $str,
'created' => DateTime::createFromFormat('Ymd_His', $date),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
)
)
);
@ -66,7 +67,14 @@ function testIssoDisplayed()
// plugin data
$this->assertEquals(1, count($data['plugin_end_zone']));
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], $date));
$this->assertNotFalse(strpos(
$data['plugin_end_zone'][0],
'data-isso-id="'. $data['links'][0]['id'] .'"'
));
$this->assertNotFalse(strpos(
$data['plugin_end_zone'][0],
'data-title="'. $data['links'][0]['id'] .'"'
));
$this->assertNotFalse(strpos($data['plugin_end_zone'][0], 'embed.min.js'));
}
@ -85,12 +93,14 @@ function testIssoMultipleLinks()
'title' => $str,
'links' => array(
array(
'id' => 12,
'url' => $str,
'created' => DateTime::createFromFormat('Ymd_His', $date1),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date1),
),
array(
'id' => 13,
'url' => $str . '2',
'created' => DateTime::createFromFormat('Ymd_His', $date2),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date2),
),
)
);
@ -114,8 +124,9 @@ function testIssoNotDisplayedWhenSearch()
'title' => $str,
'links' => array(
array(
'id' => 12,
'url' => $str,
'created' => DateTime::createFromFormat('Ymd_His', $date),
'created' => DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, $date),
)
),
'search_term' => $str

View file

@ -21,7 +21,7 @@ public function __construct()
'?WDWyig',
'Stallman has a beard and is part of the Free Software Foundation (or not). Seriously, read this. #hashtag',
0,
DateTime::createFromFormat('Ymd_His', '20150310_114651'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114651'),
'sTuff',
null,
'WDWyig'
@ -33,7 +33,7 @@ public function __construct()
'?WDWyig',
'Used to test links reordering.',
0,
DateTime::createFromFormat('Ymd_His', '20100310_101010'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20100310_101010'),
'ut'
);
@ -43,9 +43,9 @@ public function __construct()
'https://static.fsf.org/nosvn/faif-2.0.pdf',
'Richard Stallman and the Free Software Revolution. Read this. #hashtag',
0,
DateTime::createFromFormat('Ymd_His', '20150310_114633'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20150310_114633'),
'free gnu software stallman -exclude stuff hashtag',
DateTime::createFromFormat('Ymd_His', '20160803_093033')
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20160803_093033')
);
$this->addLink(
@ -54,7 +54,7 @@ public function __construct()
'http://mediagoblin.org/',
'A free software media publishing platform #hashtagOther',
0,
DateTime::createFromFormat('Ymd_His', '20130614_184135'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20130614_184135'),
'gnu media web .hidden hashtag',
null,
'IuWvgA'
@ -66,7 +66,7 @@ public function __construct()
'https://dvcs.w3.org/hg/markup-validator/summary',
'Mercurial repository for the W3C Validator #private',
1,
DateTime::createFromFormat('Ymd_His', '20141125_084734'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20141125_084734'),
'css html w3c web Mercurial'
);
@ -76,7 +76,7 @@ public function __construct()
'http://ars.userfriendly.org/cartoons/?id=20121206',
'Naming conventions... #private',
0,
DateTime::createFromFormat('Ymd_His', '20121206_142300'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_142300'),
'dev cartoon web'
);
@ -86,7 +86,7 @@ public function __construct()
'http://ars.userfriendly.org/cartoons/?id=20010306',
'Tropical printing',
0,
DateTime::createFromFormat('Ymd_His', '20121206_172539'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_172539'),
'samba cartoon web'
);
@ -96,7 +96,7 @@ public function __construct()
'http://geek-and-poke.com/',
'',
1,
DateTime::createFromFormat('Ymd_His', '20121206_182539'),
DateTime::createFromFormat(LinkDB::LINK_DATE_FORMAT, '20121206_182539'),
'dev cartoon tag1 tag2 tag3 tag4 '
);
}
@ -115,7 +115,7 @@ protected function addLink($id, $title, $url, $description, $private, $date, $ta
'tags' => $tags,
'created' => $date,
'updated' => $updated,
'shorturl' => $shorturl ? $shorturl : smallHash($date->format('Ymd_His') . $id),
'shorturl' => $shorturl ? $shorturl : smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id),
);
$this->_links[$id] = $link;