ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilBookmarkImportExport Class Reference

bookmark import export More...

+ Collaboration diagram for ilBookmarkImportExport:

Static Public Member Functions

static _parseFile ($file)
 parse Bookmark file static method returns 3 dimensional array of bookmarks and folders More...
 
static __parseNetscape (&$fp)
 parse Netscape bookmark file More...
 
static _exportBookmark ($obj_ids, $recursive=true, $title='')
 export bookmarks static method return html string More...
 
static __parseExport ($object, $depth=1, $recursive=true)
 recursive methode generates bookmark output for export More...
 
static _decodeEntities ($string)
 decode html entities of given string More...
 
static _convertCharset ($string, $from_charset='', $to_charset='UTF-8')
 converts charset of given string More...
 

Detailed Description

bookmark import export

Author
Manfred Thaler manfr.nosp@m.ed.t.nosp@m.haler.nosp@m.@end.nosp@m.o7.co.nosp@m.m
Version
$Id$

Definition at line 12 of file class.ilBookmarkImportExport.php.

Member Function Documentation

◆ __parseExport()

static ilBookmarkImportExport::__parseExport (   $object,
  $depth = 1,
  $recursive = true 
)
static

recursive methode generates bookmark output for export

Parameters
arraynode date
intdepth of recursion
booltrue for recursive export private

Definition at line 136 of file class.ilBookmarkImportExport.php.

References $result, ilBookmarkFolder\getObjects(), and ilUtil\prepareFormOutput().

Referenced by _exportBookmark().

137  {
138  switch ($object['type']) {
139  case 'bm':
140  $result.=str_repeat("\t", $depth);
141  $result.='<DT><A HREF="' . ilUtil::prepareFormOutput($object['target']) . '" ';
142  $result.='ADD_DATE="' . intval(0) . '" ';
143  $result.='LAST_VISIT="' . intval(0) . '" ';
144  $result.='LAST_MODIFIED="' . intval(0) . '">';
145  $result.=ilUtil::prepareFormOutput($object['title']) . '</A>' . "\n";
146  if ($object['description']) {
147  $result.='<DD>' .
148  ilUtil::prepareFormOutput($object['description']) . "\n";
149  }
150  break;
151  case 'bmf':
152  $result.=str_repeat("\t", $depth) . '<DT><H3 ADD_DATE="0">' .
153  ilUtil::prepareFormOutput($object['title']) . '</H3>' . "\n";
154  if ($object['description']) {
155  $result.='<DD>' .
156  ilUtil::prepareFormOutput($object['description']) . "\n";
157  }
158  $result.=str_repeat("\t", $depth) . '<DL><p>' . "\n";
159  if ($recursive) {
160  $depth++;
161  $sub_objects=ilBookmarkFolder::getObjects($object['child']);
162  foreach ($sub_objects as $sub_object) {
164  $sub_object,
165  $depth,
166  $recursive
167  );
168  }
169  $depth--;
170  }
171  $result.=str_repeat("\t", $depth) . '</DL><p>' . "\n";
172  break;
173  }
174  return $result;
175  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
$result
static __parseExport($object, $depth=1, $recursive=true)
recursive methode generates bookmark output for export
static getObjects($a_id)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __parseNetscape()

static ilBookmarkImportExport::__parseNetscape ( $fp)
static

parse Netscape bookmark file

Parameters
intfilepointer private

Definition at line 38 of file class.ilBookmarkImportExport.php.

References $id, $name, $ok, $result, $url, _convertCharset(), _decodeEntities(), and array.

Referenced by _parseFile().

39  {
40  $result=array();
41  $parent=array();
42  $start_id=0;
43  $id=0;
44  $ok=false;
45  while ($line=fgets($fp)) {
46  $line=trim($line);
47  if (preg_match('/<DL>/i', $line)) {
48  $parent_id=$id;
49  } elseif (preg_match('/<\/DL>/i', $line)) {
50  $parent_id=array_pop($parent);
51  } elseif (preg_match('/<DD>(.+)$/i', $line, $match)) {
52  // extract description
53  $desc=ilBookmarkImportExport::_convertCharset(trim($match[1]), $charset);
55  $result[$parent_id][$id]['description']=strip_tags($desc);
56  } elseif (preg_match('/<DT><H3[^>]*>(.*)<\/H3>/i', $line, $match)) {
57  //bookmark folder
58  array_push($parent, $parent_id);
59  $name=ilBookmarkImportExport::_convertCharset(trim($match[1]), $charset);
61  $id++;
62  $result[$parent_id][$id]=array(
63  'type'=>'bmf',
64  'title'=>strip_tags($name),
65  );
66  } elseif (preg_match('/<DT><A HREF="([^"]*)[^>]*>(.*)<\/A>/i', $line, $match)) {
67  $id++;
68  // extract url and title
69  $url=ilBookmarkImportExport::_convertCharset(trim($match[1]), $charset);
71  $name=ilBookmarkImportExport::_convertCharset(trim($match[2]), $charset);
73  // extract dates
74  if (preg_match("/ADD_DATE=\"([^\"]*)/i", $line, $match)) {
75  $add_date = $match[1];
76  } else {
77  $add_date=0;
78  }
79  if (preg_match("/LAST_VISIT=\"([^\"]*)/i", $line, $match)) {
80  $visited = $match[1];
81  } else {
82  $visited=0;
83  }
84  if (preg_match("/LAST_MODIFIED=\"([^\"]*)/i", $line, $match)) {
85  $modified = $match[1];
86  } else {
87  $modified=0;
88  }
89  $result[$parent_id][$id]=array(
90  'type'=>'bm',
91  'target'=>strip_tags($url),
92  'title'=>strip_tags($name),
93  'add_date'=>$add_date,
94  'visited'=>$visited,
95  'modified'=>$modified,
96  );
97  } elseif (preg_match("/<META\s+HTTP-EQUIV=\"Content-Type\".+CONTENT=\"([^\"]*)\"/i", $line, $match)) {
98  preg_match("/charset=([^ ]+)/", $match[1], $match);
99  $charset=$match[1];
100  }
101  }
102  return $result;
103  }
$result
static _convertCharset($string, $from_charset='', $to_charset='UTF-8')
converts charset of given string
if(!array_key_exists('StateId', $_REQUEST)) $id
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
static _decodeEntities($string)
decode html entities of given string
$url
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertCharset()

static ilBookmarkImportExport::_convertCharset (   $string,
  $from_charset = '',
  $to_charset = 'UTF-8' 
)
static

converts charset of given string

Parameters
stringstring to converte
stringfrom charset
stringto charset public

Definition at line 214 of file class.ilBookmarkImportExport.php.

Referenced by __parseNetscape().

215  {
216  if (extension_loaded("mbstring")) {
217  if (!$from_charset) {
218  // try to detect charset
219  mb_detect_order("ASCII, JIS, UTF-8, EUC-JP, SJIS, ISO-8859-15, Windows-1252");
220  $from_charset=mb_detect_encoding($string);
221  }
222  if (strtoupper($from_charset)!=$to_charset) {
223  return @mb_convert_encoding($string, $to_charset, $from_charset);
224  }
225  }
226  return $string;
227  }
+ Here is the caller graph for this function:

◆ _decodeEntities()

static ilBookmarkImportExport::_decodeEntities (   $string)
static

decode html entities of given string

Parameters
stringstring to decode public

Definition at line 182 of file class.ilBookmarkImportExport.php.

Referenced by __parseNetscape().

183  {
184  if (function_exists('html_entity_decode')) {
185  $string= html_entity_decode($string, ENT_QUOTES, "ISO-8859-15"); #NOTE: UTF-8 does not work!
186  } else {
187  $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
188  $string = strtr($string, $trans_table);
189  }
190  $string= preg_replace_callback(
191  '/&#(\d+);/m',
192  function ($hit) {
193  return chr($hit[1]);
194  },
195  $string
196  ); #decimal notation
197  $string= preg_replace_callback(
198  '/&#x([a-f0-9]+);/mi',
199  function ($hit) {
200  return chr(hexdec($hit[1]));
201  },
202  $string
203  ); #hex notation
204  return $string;
205  }
+ Here is the caller graph for this function:

◆ _exportBookmark()

static ilBookmarkImportExport::_exportBookmark (   $obj_ids,
  $recursive = true,
  $title = '' 
)
static

export bookmarks static method return html string

Parameters
arrayarray of bookmark ids to export
booltrue for recursive export
stringtitle of html page

Definition at line 111 of file class.ilBookmarkImportExport.php.

References $title, __parseExport(), date, ilBookmarkFolder\getObject(), and ilUtil\prepareFormOutput().

Referenced by ilBookmarkAdministrationGUI\export().

112  {
113  $htmlCont='<!DOCTYPE NETSCAPE-Bookmark-file-1>' . "\n";
114  $htmlCont.='<!-- Created by ilias - www.ilias.de -->' . "\n";
115  $htmlCont.='<!-- on ' . date('r') . ' -->' . "\n\n";
116  $htmlCont.='<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">' . "\n";
117  $htmlCont.='<TITLE>' . ilUtil::prepareFormOutput($title) . '</TITLE>' . "\n";
118  $htmlCont.='<H1>' . ilUtil::prepareFormOutput($title) . '</H1>' . "\n\n";
119  $htmlCont.='<DL><p>' . "\n";
120  foreach ($obj_ids as $obj_id) {
121  $object = ilBookmarkFolder::getObject($obj_id);
122  $htmlCont.=ilBookmarkImportExport::__parseExport($object, 1, $recursive);
123  }
124  $htmlCont.='</DL><p>' . "\n";
125  //echo htmlentities($htmlCont); exit;
126  return $htmlCont;
127  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static getObject($a_id)
static
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
static __parseExport($object, $depth=1, $recursive=true)
recursive methode generates bookmark output for export
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _parseFile()

static ilBookmarkImportExport::_parseFile (   $file)
static

parse Bookmark file static method returns 3 dimensional array of bookmarks and folders

Parameters
stringfile

Definition at line 19 of file class.ilBookmarkImportExport.php.

References $file, and __parseNetscape().

Referenced by ilBookmarkAdministrationGUI\importFile().

20  {
21  if (file_exists($file) && is_file($file)) {
22  $fp = fopen($file, "r-");
23  while ($line=fgets($fp)) {
24  $line=trim($line);
25  if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/i', $line)) {
27  }
28  }
29  }
30  return false;
31  }
static __parseNetscape(&$fp)
parse Netscape bookmark file
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: