aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/NetscapeBookmarkUtils.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/NetscapeBookmarkUtils.php')
-rw-r--r--application/NetscapeBookmarkUtils.php27
1 files changed, 16 insertions, 11 deletions
diff --git a/application/NetscapeBookmarkUtils.php b/application/NetscapeBookmarkUtils.php
index 2a10ff22..dd7057f8 100644
--- a/application/NetscapeBookmarkUtils.php
+++ b/application/NetscapeBookmarkUtils.php
@@ -32,11 +32,10 @@ class NetscapeBookmarkUtils
32 { 32 {
33 // see tpl/export.html for possible values 33 // see tpl/export.html for possible values
34 if (! in_array($selection, array('all', 'public', 'private'))) { 34 if (! in_array($selection, array('all', 'public', 'private'))) {
35 throw new Exception('Invalid export selection: "'.$selection.'"'); 35 throw new Exception(t('Invalid export selection:') .' "'.$selection.'"');
36 } 36 }
37 37
38 $bookmarkLinks = array(); 38 $bookmarkLinks = array();
39
40 foreach ($linkDb as $link) { 39 foreach ($linkDb as $link) {
41 if ($link['private'] != 0 && $selection == 'public') { 40 if ($link['private'] != 0 && $selection == 'public') {
42 continue; 41 continue;
@@ -66,6 +65,7 @@ class NetscapeBookmarkUtils
66 * @param int $importCount how many links were imported 65 * @param int $importCount how many links were imported
67 * @param int $overwriteCount how many links were overwritten 66 * @param int $overwriteCount how many links were overwritten
68 * @param int $skipCount how many links were skipped 67 * @param int $skipCount how many links were skipped
68 * @param int $duration how many seconds did the import take
69 * 69 *
70 * @return string Summary of the bookmark import status 70 * @return string Summary of the bookmark import status
71 */ 71 */
@@ -74,16 +74,18 @@ class NetscapeBookmarkUtils
74 $filesize, 74 $filesize,
75 $importCount=0, 75 $importCount=0,
76 $overwriteCount=0, 76 $overwriteCount=0,
77 $skipCount=0 77 $skipCount=0,
78 $duration=0
78 ) 79 )
79 { 80 {
80 $status = 'File '.$filename.' ('.$filesize.' bytes) '; 81 $status = sprintf(t('File %s (%d bytes) '), $filename, $filesize);
81 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) { 82 if ($importCount == 0 && $overwriteCount == 0 && $skipCount == 0) {
82 $status .= 'has an unknown file format. Nothing was imported.'; 83 $status .= t('has an unknown file format. Nothing was imported.');
83 } else { 84 } else {
84 $status .= 'was successfully processed: '.$importCount.' links imported, '; 85 $status .= vsprintf(
85 $status .= $overwriteCount.' links overwritten, '; 86 t('was successfully processed in %d seconds: %d links imported, %d links overwritten, %d links skipped.'),
86 $status .= $skipCount.' links skipped.'; 87 [$duration, $importCount, $overwriteCount, $skipCount]
88 );
87 } 89 }
88 return $status; 90 return $status;
89 } 91 }
@@ -101,6 +103,7 @@ class NetscapeBookmarkUtils
101 */ 103 */
102 public static function import($post, $files, $linkDb, $conf, $history) 104 public static function import($post, $files, $linkDb, $conf, $history)
103 { 105 {
106 $start = time();
104 $filename = $files['filetoupload']['name']; 107 $filename = $files['filetoupload']['name'];
105 $filesize = $files['filetoupload']['size']; 108 $filesize = $files['filetoupload']['size'];
106 $data = file_get_contents($files['filetoupload']['tmp_name']); 109 $data = file_get_contents($files['filetoupload']['tmp_name']);
@@ -184,7 +187,6 @@ class NetscapeBookmarkUtils
184 $linkDb[$existingLink['id']] = $newLink; 187 $linkDb[$existingLink['id']] = $newLink;
185 $importCount++; 188 $importCount++;
186 $overwriteCount++; 189 $overwriteCount++;
187 $history->updateLink($newLink);
188 continue; 190 continue;
189 } 191 }
190 192
@@ -196,16 +198,19 @@ class NetscapeBookmarkUtils
196 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']); 198 $newLink['shorturl'] = link_small_hash($newLink['created'], $newLink['id']);
197 $linkDb[$newLink['id']] = $newLink; 199 $linkDb[$newLink['id']] = $newLink;
198 $importCount++; 200 $importCount++;
199 $history->addLink($newLink);
200 } 201 }
201 202
202 $linkDb->save($conf->get('resource.page_cache')); 203 $linkDb->save($conf->get('resource.page_cache'));
204 $history->importLinks();
205
206 $duration = time() - $start;
203 return self::importStatus( 207 return self::importStatus(
204 $filename, 208 $filename,
205 $filesize, 209 $filesize,
206 $importCount, 210 $importCount,
207 $overwriteCount, 211 $overwriteCount,
208 $skipCount 212 $skipCount,
213 $duration
209 ); 214 );
210 } 215 }
211} 216}