aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/FeedBuilder.php2
-rw-r--r--application/LinkDB.php12
-rw-r--r--application/LinkFilter.php2
-rw-r--r--application/LinkUtils.php13
-rw-r--r--application/NetscapeBookmarkUtils.php1
-rw-r--r--application/Updater.php3
-rw-r--r--application/Utils.php6
7 files changed, 32 insertions, 7 deletions
diff --git a/application/FeedBuilder.php b/application/FeedBuilder.php
index bfdf2fd3..fedd90e6 100644
--- a/application/FeedBuilder.php
+++ b/application/FeedBuilder.php
@@ -143,7 +143,7 @@ class FeedBuilder
143 */ 143 */
144 protected function buildItem($link, $pageaddr) 144 protected function buildItem($link, $pageaddr)
145 { 145 {
146 $link['guid'] = $pageaddr .'?'. smallHash($link['created']->format('Ymd_His')); 146 $link['guid'] = $pageaddr .'?'. $link['shorturl'];
147 // Check for both signs of a note: starting with ? and 7 chars long. 147 // Check for both signs of a note: starting with ? and 7 chars long.
148 if ($link['url'][0] === '?' && strlen($link['url']) === 7) { 148 if ($link['url'][0] === '?' && strlen($link['url']) === 7) {
149 $link['url'] = $pageaddr . $link['url']; 149 $link['url'] = $pageaddr . $link['url'];
diff --git a/application/LinkDB.php b/application/LinkDB.php
index e429ab4f..1e13286a 100644
--- a/application/LinkDB.php
+++ b/application/LinkDB.php
@@ -22,6 +22,7 @@
22 * Can be absolute or relative. 22 * Can be absolute or relative.
23 * Relative URLs are permalinks (e.g.'?m-ukcw') 23 * Relative URLs are permalinks (e.g.'?m-ukcw')
24 * - real_url Absolute processed URL. 24 * - real_url Absolute processed URL.
25 * - shorturl Permalink smallhash
25 * 26 *
26 * Implements 3 interfaces: 27 * Implements 3 interfaces:
27 * - ArrayAccess: behaves like an associative array; 28 * - ArrayAccess: behaves like an associative array;
@@ -264,6 +265,7 @@ You use the community supported version of the original Shaarli project, by Seba
264 'created'=> new DateTime(), 265 'created'=> new DateTime(),
265 'tags'=>'opensource software' 266 'tags'=>'opensource software'
266 ); 267 );
268 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
267 $this->links[1] = $link; 269 $this->links[1] = $link;
268 270
269 $link = array( 271 $link = array(
@@ -273,8 +275,9 @@ You use the community supported version of the original Shaarli project, by Seba
273 'description'=>'Shhhh! I\'m a private link only YOU can see. You can delete me too.', 275 'description'=>'Shhhh! I\'m a private link only YOU can see. You can delete me too.',
274 'private'=>1, 276 'private'=>1,
275 'created'=> new DateTime('1 minute ago'), 277 'created'=> new DateTime('1 minute ago'),
276 'tags'=>'secretstuff' 278 'tags'=>'secretstuff',
277 ); 279 );
280 $link['shorturl'] = link_small_hash($link['created'], $link['id']);
278 $this->links[0] = $link; 281 $this->links[0] = $link;
279 282
280 // Write database to disk 283 // Write database to disk
@@ -335,10 +338,11 @@ You use the community supported version of the original Shaarli project, by Seba
335 // To be able to load links before running the update, and prepare the update 338 // To be able to load links before running the update, and prepare the update
336 if (! isset($link['created'])) { 339 if (! isset($link['created'])) {
337 $link['id'] = $link['linkdate']; 340 $link['id'] = $link['linkdate'];
338 $link['created'] = DateTime::createFromFormat('Ymd_His', $link['linkdate']); 341 $link['created'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['linkdate']);
339 if (! empty($link['updated'])) { 342 if (! empty($link['updated'])) {
340 $link['updated'] = DateTime::createFromFormat('Ymd_His', $link['updated']); 343 $link['updated'] = DateTime::createFromFormat(self::LINK_DATE_FORMAT, $link['updated']);
341 } 344 }
345 $link['shorturl'] = smallHash($link['linkdate']);
342 } 346 }
343 } 347 }
344 348
@@ -558,7 +562,7 @@ You use the community supported version of the original Shaarli project, by Seba
558 * 562 *
559 * @param int $id Persistent ID of a link. 563 * @param int $id Persistent ID of a link.
560 * 564 *
561 * @return int Real offset in local array, or null if doesn't exists. 565 * @return int Real offset in local array, or null if doesn't exist.
562 */ 566 */
563 protected function getLinkOffset($id) 567 protected function getLinkOffset($id)
564 { 568 {
diff --git a/application/LinkFilter.php b/application/LinkFilter.php
index 7bab46ba..daa6d9cc 100644
--- a/application/LinkFilter.php
+++ b/application/LinkFilter.php
@@ -120,7 +120,7 @@ class LinkFilter
120 { 120 {
121 $filtered = array(); 121 $filtered = array();
122 foreach ($this->links as $key => $l) { 122 foreach ($this->links as $key => $l) {
123 if ($smallHash == smallHash($l['created']->format('Ymd_His'))) { 123 if ($smallHash == $l['shorturl']) {
124 // Yes, this is ugly and slow 124 // Yes, this is ugly and slow
125 $filtered[$key] = $l; 125 $filtered[$key] = $l;
126 return $filtered; 126 return $filtered;
diff --git a/application/LinkUtils.php b/application/LinkUtils.php
index 9d9ae3cb..cf58f808 100644
--- a/application/LinkUtils.php
+++ b/application/LinkUtils.php
@@ -169,3 +169,16 @@ function space2nbsp($text)
169function format_description($description, $redirector = '', $indexUrl = '') { 169function format_description($description, $redirector = '', $indexUrl = '') {
170 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl))); 170 return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl)));
171} 171}
172
173/**
174 * Generate a small hash for a link.
175 *
176 * @param DateTime $date Link creation date.
177 * @param int $id Link ID.
178 *
179 * @return string the small hash generated from link data.
180 */
181function link_small_hash($date, $id)
182{
183 return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id);
184}
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index 8a939adb..e7148d00 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -174,6 +174,7 @@ class NetscapeBookmarkUtils
174 $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get())); 174 $newLinkDate->setTimezone(new DateTimeZone(date_default_timezone_get()));
175 $newLink['created'] = $newLinkDate; 175 $newLink['created'] = $newLinkDate;
176 $newLink['id'] = $linkDb->getNextId(); 176 $newLink['id'] = $linkDb->getNextId();
177 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']);
177 $linkDb[$newLink['id']] = $newLink; 178 $linkDb[$newLink['id']] = $newLink;
178 $importCount++; 179 $importCount++;
179 } 180 }
diff --git a/application/Updater.php b/application/Updater.php
index 16c8c376..f0d02814 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -223,6 +223,9 @@ class Updater
223 * Since this update is very sensitve (changing the whole database), the datastore will be 223 * Since this update is very sensitve (changing the whole database), the datastore will be
224 * automatically backed up into the file datastore.<datetime>.php. 224 * automatically backed up into the file datastore.<datetime>.php.
225 * 225 *
226 * LinkDB also adds the field 'shorturl' with the precedent format (linkdate smallhash),
227 * which will be saved by this method.
228 *
226 * @return bool true if the update is successful, false otherwise. 229 * @return bool true if the update is successful, false otherwise.
227 */ 230 */
228 public function updateMethodDatastoreIds() 231 public function updateMethodDatastoreIds()
diff --git a/application/Utils.php b/application/Utils.php
index 0166ee2a..0a5b476e 100644
--- a/application/Utils.php
+++ b/application/Utils.php
@@ -31,7 +31,11 @@ function logm($logFile, $clientIp, $message)
31 * - are NOT cryptographically secure (they CAN be forged) 31 * - are NOT cryptographically secure (they CAN be forged)
32 * 32 *
33 * In Shaarli, they are used as a tinyurl-like link to individual entries, 33 * In Shaarli, they are used as a tinyurl-like link to individual entries,
34 * e.g. smallHash('20111006_131924') --> yZH23w 34 * built once with the combination of the date and item ID.
35 * e.g. smallHash('20111006_131924' . 142) --> eaWxtQ
36 *
37 * @warning before v0.8.1, smallhashes were built only with the date,
38 * and their value has been preserved.
35 * 39 *
36 * @param string $text Create a hash from this text. 40 * @param string $text Create a hash from this text.
37 * 41 *