aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/ApplicationUtils.php15
-rw-r--r--application/History.php16
-rw-r--r--application/NetscapeBookmarkUtils.php16
-rw-r--r--application/PageBuilder.php9
-rw-r--r--application/Updater.php4
5 files changed, 51 insertions, 9 deletions
diff --git a/application/ApplicationUtils.php b/application/ApplicationUtils.php
index 123cc0b3..5643f4a0 100644
--- a/application/ApplicationUtils.php
+++ b/application/ApplicationUtils.php
@@ -221,4 +221,19 @@ class ApplicationUtils
221 221
222 return $errors; 222 return $errors;
223 } 223 }
224
225 /**
226 * Returns a salted hash representing the current Shaarli version.
227 *
228 * Useful for assets browser cache.
229 *
230 * @param string $currentVersion of Shaarli
231 * @param string $salt User personal salt, also used for the authentication
232 *
233 * @return string version hash
234 */
235 public static function getVersionHash($currentVersion, $salt)
236 {
237 return hash_hmac('sha256', $currentVersion, $salt);
238 }
224} 239}
diff --git a/application/History.php b/application/History.php
index 116b9264..5e3b1b72 100644
--- a/application/History.php
+++ b/application/History.php
@@ -16,6 +16,7 @@
16 * - UPDATED: link updated 16 * - UPDATED: link updated
17 * - DELETED: link deleted 17 * - DELETED: link deleted
18 * - SETTINGS: the settings have been updated through the UI. 18 * - SETTINGS: the settings have been updated through the UI.
19 * - IMPORT: bulk links import
19 * 20 *
20 * Note: new events are put at the beginning of the file and history array. 21 * Note: new events are put at the beginning of the file and history array.
21 */ 22 */
@@ -42,6 +43,11 @@ class History
42 const SETTINGS = 'SETTINGS'; 43 const SETTINGS = 'SETTINGS';
43 44
44 /** 45 /**
46 * @var string Action key: a bulk import has been processed.
47 */
48 const IMPORT = 'IMPORT';
49
50 /**
45 * @var string History file path. 51 * @var string History file path.
46 */ 52 */
47 protected $historyFilePath; 53 protected $historyFilePath;
@@ -122,6 +128,16 @@ class History
122 } 128 }
123 129
124 /** 130 /**
131 * Add Event: bulk import.
132 *
133 * Note: we don't store links add/update one by one since it can have a huge impact on performances.
134 */
135 public function importLinks()
136 {
137 $this->addEvent(self::IMPORT);
138 }
139
140 /**
125 * Save a new event and write it in the history file. 141 * Save a new event and write it in the history file.
126 * 142 *
127 * @param string $status Event key, should be defined as constant. 143 * @param string $status Event key, should be defined as constant.
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index 2a10ff22..31796367 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -66,6 +66,7 @@ class NetscapeBookmarkUtils
66 * @param int $importCount how many links were imported 66 * @param int $importCount how many links were imported
67 * @param int $overwriteCount how many links were overwritten 67 * @param int $overwriteCount how many links were overwritten
68 * @param int $skipCount how many links were skipped 68 * @param int $skipCount how many links were skipped
69 * @param int $duration how many seconds did the import take
69 * 70 *
70 * @return string Summary of the bookmark import status 71 * @return string Summary of the bookmark import status
71 */ 72 */
@@ -74,14 +75,16 @@ class NetscapeBookmarkUtils
74 $filesize, 75 $filesize,
75 $importCount=0, 76 $importCount=0,
76 $overwriteCount=0, 77 $overwriteCount=0,
77 $skipCount=0 78 $skipCount=0,
79 $duration=0
78 ) 80 )
79 { 81 {
80 $status = 'File '.$filename.' ('.$filesize.' bytes) '; 82 $status = 'File '.$filename.' ('.$filesize.' bytes) ';
81 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) { 83 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) {
82 $status .= 'has an unknown file format. Nothing was imported.'; 84 $status .= 'has an unknown file format. Nothing was imported.';
83 } else { 85 } else {
84 $status .= 'was successfully processed: '.$importCount.' links imported, '; 86 $status .= 'was successfully processed in '. $duration .' seconds: ';
87 $status .= $importCount.' links imported, ';
85 $status .= $overwriteCount.' links overwritten, '; 88 $status .= $overwriteCount.' links overwritten, ';
86 $status .= $skipCount.' links skipped.'; 89 $status .= $skipCount.' links skipped.';
87 } 90 }
@@ -101,6 +104,7 @@ class NetscapeBookmarkUtils
101 */ 104 */
102 public static function import($post, $files, $linkDb, $conf, $history) 105 public static function import($post, $files, $linkDb, $conf, $history)
103 { 106 {
107 $start = time();
104 $filename = $files['filetoupload']['name']; 108 $filename = $files['filetoupload']['name'];
105 $filesize = $files['filetoupload']['size']; 109 $filesize = $files['filetoupload']['size'];
106 $data = file_get_contents($files['filetoupload']['tmp_name']); 110 $data = file_get_contents($files['filetoupload']['tmp_name']);
@@ -184,7 +188,6 @@ class NetscapeBookmarkUtils
184 $linkDb[$existingLink['id']] = $newLink; 188 $linkDb[$existingLink['id']] = $newLink;
185 $importCount++; 189 $importCount++;
186 $overwriteCount++; 190 $overwriteCount++;
187 $history->updateLink($newLink);
188 continue; 191 continue;
189 } 192 }
190 193
@@ -196,16 +199,19 @@ class NetscapeBookmarkUtils
196 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']); 199 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']);
197 $linkDb[$newLink['id']] = $newLink; 200 $linkDb[$newLink['id']] = $newLink;
198 $importCount++; 201 $importCount++;
199 $history->addLink($newLink);
200 } 202 }
201 203
202 $linkDb->save($conf->get('resource.page_cache')); 204 $linkDb->save($conf->get('resource.page_cache'));
205 $history->importLinks();
206
207 $duration = time() - $start;
203 return self::importStatus( 208 return self::importStatus(
204 $filename, 209 $filename,
205 $filesize, 210 $filesize,
206 $importCount, 211 $importCount,
207 $overwriteCount, 212 $overwriteCount,
208 $skipCount 213 $skipCount,
214 $duration
209 ); 215 );
210 } 216 }
211} 217}
diff --git a/application/PageBuilder.php b/application/PageBuilder.php
index 7a42400d..291860ad 100644
--- a/application/PageBuilder.php
+++ b/application/PageBuilder.php
@@ -49,7 +49,7 @@ class PageBuilder
49 49
50 try { 50 try {
51 $version = ApplicationUtils::checkUpdate( 51 $version = ApplicationUtils::checkUpdate(
52 shaarli_version, 52 SHAARLI_VERSION,
53 $this->conf->get('resource.update_check'), 53 $this->conf->get('resource.update_check'),
54 $this->conf->get('updates.check_updates_interval'), 54 $this->conf->get('updates.check_updates_interval'),
55 $this->conf->get('updates.check_updates'), 55 $this->conf->get('updates.check_updates'),
@@ -75,7 +75,11 @@ class PageBuilder
75 } 75 }
76 $this->tpl->assign('searchcrits', $searchcrits); 76 $this->tpl->assign('searchcrits', $searchcrits);
77 $this->tpl->assign('source', index_url($_SERVER)); 77 $this->tpl->assign('source', index_url($_SERVER));
78 $this->tpl->assign('version', shaarli_version); 78 $this->tpl->assign('version', SHAARLI_VERSION);
79 $this->tpl->assign(
80 'version_hash',
81 ApplicationUtils::getVersionHash(SHAARLI_VERSION, $this->conf->get('credentials.salt'))
82 );
79 $this->tpl->assign('scripturl', index_url($_SERVER)); 83 $this->tpl->assign('scripturl', index_url($_SERVER));
80 $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links? 84 $this->tpl->assign('privateonly', !empty($_SESSION['privateonly'])); // Show only private links?
81 $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly'])); 85 $this->tpl->assign('untaggedonly', !empty($_SESSION['untaggedonly']));
@@ -89,6 +93,7 @@ class PageBuilder
89 $this->tpl->assign('feed_type', $this->conf->get('feed.show_atom', true) !== false ? 'atom' : 'rss'); 93 $this->tpl->assign('feed_type', $this->conf->get('feed.show_atom', true) !== false ? 'atom' : 'rss');
90 $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false)); 94 $this->tpl->assign('hide_timestamps', $this->conf->get('privacy.hide_timestamps', false));
91 $this->tpl->assign('token', getToken($this->conf)); 95 $this->tpl->assign('token', getToken($this->conf));
96
92 if ($this->linkDB !== null) { 97 if ($this->linkDB !== null) {
93 $this->tpl->assign('tags', $this->linkDB->linksCountPerTag()); 98 $this->tpl->assign('tags', $this->linkDB->linksCountPerTag());
94 } 99 }
diff --git a/application/Updater.php b/application/Updater.php
index 40a15906..72b2def0 100644
--- a/application/Updater.php
+++ b/application/Updater.php
@@ -398,7 +398,7 @@ class Updater
398 */ 398 */
399 public function updateMethodCheckUpdateRemoteBranch() 399 public function updateMethodCheckUpdateRemoteBranch()
400 { 400 {
401 if (shaarli_version === 'dev' || $this->conf->get('updates.check_updates_branch') === 'latest') { 401 if (SHAARLI_VERSION === 'dev' || $this->conf->get('updates.check_updates_branch') === 'latest') {
402 return true; 402 return true;
403 } 403 }
404 404
@@ -413,7 +413,7 @@ class Updater
413 $latestMajor = $matches[1]; 413 $latestMajor = $matches[1];
414 414
415 // Get current major version digit 415 // Get current major version digit
416 preg_match('/(\d+)\.\d+$/', shaarli_version, $matches); 416 preg_match('/(\d+)\.\d+$/', SHAARLI_VERSION, $matches);
417 $currentMajor = $matches[1]; 417 $currentMajor = $matches[1];
418 418
419 if ($currentMajor === $latestMajor) { 419 if ($currentMajor === $latestMajor) {