Blame view

sources/apps/bookmarks/export.php 1.65 KB
923852aa1   Kload   Official Owncloud...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  <?php
  /**
   * Copyright (c) 2012 Brice Maron < brice __At__ bmaron dot net >
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  // Check if we are a user
  OCP\User::checkLoggedIn();
  OCP\App::checkAppEnabled('bookmarks');
  
  function getDomainWithoutExt($name){
      $pos = strripos($name, '.');
      if($pos === false){
          return $name;
      }else{
          return substr($name, 0, $pos);
      }
  }
  
  $file = <<<EOT
  <!DOCTYPE NETSCAPE-Bookmark-file-1>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
  <!-- This is an automatically generated file.
  It will be read and overwritten.
  Do Not Edit! -->
  <TITLE>Bookmarks</TITLE>
  <H1>Bookmarks</H1>
  <DL><p>
  EOT;
  $bookmarks = OC_Bookmarks_Bookmarks::findBookmarks(0, 'id', array(), true, -1);
  foreach($bookmarks as $bm) {
  	$title = $bm['title'];
  	if(trim($title) ===''){
  		$url_parts = parse_url($bm['url']);
  		$title = isset($url_parts['host']) ? getDomainWithoutExt($url_parts['host']) : $bm['url'];
  	}
  	$file .= '<DT><A HREF="'.$bm['url'].'" TAGS="'.implode(',', $bm['tags']).'">';
  	$file .= htmlspecialchars($title, ENT_QUOTES, 'UTF-8').'</A>';
  	if($bm['description'])
  		$file .= '<DD>'.htmlspecialchars($bm['description'], ENT_QUOTES, 'UTF-8');
  	$file .= "
  ";
  }
  $user_name = trim(OCP\User::getDisplayName()) != '' ?
  					OCP\User::getDisplayName() : OCP\User::getUser();
  $export_name = '"ownCloud Bookmarks ('.$user_name.') ('.date('Y-m-d').').html"';
  header("Cache-Control: private");
  header("Content-Type: application/stream");
  header("Content-Length: ".strlen($file));
  header("Content-Disposition: attachment; filename=".$export_name);
  
  echo $file;
  exit;