ILIAS  release_4-4 Revision
ilBookmarkImportExport Class Reference

bookmark import export More...

+ Collaboration diagram for ilBookmarkImportExport:

Public Member Functions

 _parseFile ($file)
 parse Bookmark file static method returns 3 dimensional array of bookmarks and folders More...
 
 __parseNetscape (&$fp)
 parse Netscape bookmark file More...
 
 _exportBookmark ($obj_ids, $recursive=true, $title='')
 export bookmarks static method return html string More...
 
 __parseExport ($object, $depth=1, $recursive=true)
 recursive methode generates bookmark output for export More...
 
 _decodeEntities ($string)
 decode html entities of given string More...
 
 _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()

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

recursive methode generates bookmark output for export

Parameters
arraynode date
intdepth of recursion
booltrue for recursive export private

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

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

Referenced by _exportBookmark().

139  {
140  switch ($object['type'])
141  {
142  case 'bm':
143  $result.=str_repeat("\t",$depth);
144  $result.='<DT><A HREF="'.ilUtil::prepareFormOutput($object['target']).'" ';
145  $result.='ADD_DATE="'.intval(0).'" ';
146  $result.='LAST_VISIT="'.intval(0).'" ';
147  $result.='LAST_MODIFIED="'.intval(0).'">';
148  $result.=ilUtil::prepareFormOutput($object['title']).'</A>'."\n";
149  if ($object['description']) $result.='<DD>'.
150  ilUtil::prepareFormOutput($object['description'])."\n";
151  break;
152  case 'bmf':
153  $result.=str_repeat("\t",$depth).'<DT><H3 ADD_DATE="0">'.
154  ilUtil::prepareFormOutput($object['title']).'</H3>'."\n";
155  if ($object['description']) $result.='<DD>'.
156  ilUtil::prepareFormOutput($object['description'])."\n";
157  $result.=str_repeat("\t",$depth).'<DL><p>'."\n";
158  if ($recursive)
159  {
160  $depth++;
161  $sub_objects=ilBookmarkFolder::getObjects($object['child']);
162  foreach ($sub_objects as $sub_object)
163  {
165  $depth,$recursive);
166  }
167  $depth--;
168  }
169  $result.=str_repeat("\t",$depth).'</DL><p>'."\n";
170  break;
171  }
172  return $result;
173  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
$result
__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:

◆ __parseNetscape()

ilBookmarkImportExport::__parseNetscape ( $fp)

parse Netscape bookmark file

Parameters
intfilepointer private

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

References $ok, $result, _convertCharset(), and _decodeEntities().

Referenced by _parseFile().

41  {
42  $result=array();
43  $parent=array();
44  $start_id=0;
45  $id=0;
46  $ok=false;
47  while ($line=fgets($fp))
48  {
49  $line=trim($line);
50  if (preg_match('/<DL>/i',$line))
51  {
52  $parent_id=$id;
53  }
54  elseif (preg_match('/<\/DL>/i',$line))
55  {
56  $parent_id=array_pop($parent);
57  }
58  elseif (preg_match('/<DD>(.+)$/i',$line,$match))
59  {
60  // extract description
61  $desc=ilBookmarkImportExport::_convertCharset(trim($match[1]),$charset);
63  $result[$parent_id][$id]['description']=strip_tags($desc);
64  }
65  elseif (preg_match('/<DT><H3[^>]*>(.*)<\/H3>/i',$line,$match))
66  {
67  //bookmark folder
68  array_push($parent,$parent_id);
69  $name=ilBookmarkImportExport::_convertCharset(trim($match[1]),$charset);
71  $id++;
72  $result[$parent_id][$id]=array(
73  'type'=>'bmf',
74  'title'=>strip_tags($name),
75  );
76  }
77  elseif (preg_match('/<DT><A HREF="([^"]*)[^>]*>(.*)<\/A>/i', $line, $match))
78  {
79  $id++;
80  // extract url and title
81  $url=ilBookmarkImportExport::_convertCharset(trim($match[1]),$charset);
83  $name=ilBookmarkImportExport::_convertCharset(trim($match[2]),$charset);
85  // extract dates
86  if (preg_match("/ADD_DATE=\"([^\"]*)/i", $line, $match)) $add_date = $match[1]; else $add_date=0;
87  if (preg_match("/LAST_VISIT=\"([^\"]*)/i", $line, $match)) $visited = $match[1]; else $visited=0;
88  if (preg_match("/LAST_MODIFIED=\"([^\"]*)/i", $line, $match)) $modified = $match[1]; else $modified=0;
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  }
98  elseif (preg_match("/<META\s+HTTP-EQUIV=\"Content-Type\".+CONTENT=\"([^\"]*)\"/i", $line, $match))
99  {
100  preg_match("/charset=([^ ]+)/", $match[1], $match);
101  $charset=$match[1];
102  }
103  }
104  return $result;
105  }
$result
_convertCharset($string, $from_charset='', $to_charset='UTF-8')
converts charset of given string
_decodeEntities($string)
decode html entities of given string
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertCharset()

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

converts charset of given string

Parameters
stringstring to converte
stringfrom charset
stringto charset public

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

Referenced by __parseNetscape().

204  {
205  if (extension_loaded("mbstring"))
206  {
207  if (!$from_charset)
208  {
209  // try to detect charset
210  mb_detect_order("ASCII, JIS, UTF-8, EUC-JP, SJIS, ISO-8859-15, Windows-1252");
211  $from_charset=mb_detect_encoding ($string);
212  }
213  if (strtoupper($from_charset)!=$to_charset)
214  {
215  return @mb_convert_encoding($string,$to_charset,$from_charset);
216  }
217  }
218  return $string;
219  }
+ Here is the caller graph for this function:

◆ _decodeEntities()

ilBookmarkImportExport::_decodeEntities (   $string)

decode html entities of given string

Parameters
stringstring to decode public

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

Referenced by __parseNetscape().

181  {
182  if (function_exists('html_entity_decode'))
183  {
184  $string= html_entity_decode($string,ENT_QUOTES,"ISO-8859-15"); #NOTE: UTF-8 does not work!
185  }
186  else
187  {
188  $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES));
189  $string = strtr($string, $trans_table );
190  }
191  $string= preg_replace('/&#(\d+);/me',"chr(\\1)",$string); #decimal notation
192  $string= preg_replace('/&#x([a-f0-9]+);/mei',"chr(0x\\1)",$string); #hex notation
193  return $string;
194  }
+ Here is the caller graph for this function:

◆ _exportBookmark()

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

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 113 of file class.ilBookmarkImportExport.php.

References __parseExport(), and ilBookmarkFolder\getObject().

Referenced by ilBookmarkAdministrationGUI\export().

114  {
115  $htmlCont='<!DOCTYPE NETSCAPE-Bookmark-file-1>'."\n";
116  $htmlCont.='<!-- Created by ilias - www.ilias.de -->'."\n";
117  $htmlCont.='<!-- on '.date('r').' -->'."\n\n";
118  $htmlCont.='<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">'."\n";
119  $htmlCont.='<TITLE>'.ilUtil::prepareFormOutput($title).'</TITLE>'."\n";
120  $htmlCont.='<H1>'.ilUtil::prepareFormOutput($title).'</H1>'."\n\n";
121  $htmlCont.='<DL><p>'."\n";
122  foreach ($obj_ids as $obj_id) {
123  $object = ilBookmarkFolder::getObject($obj_id);
124  $htmlCont.=ilBookmarkImportExport::__parseExport($object,1,$recursive);
125  }
126  $htmlCont.='</DL><p>'."\n";
127 //echo htmlentities($htmlCont); exit;
128  return $htmlCont;
129  }
__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()

ilBookmarkImportExport::_parseFile (   $file)

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  {
23  $fp = fopen($file, "r-");
24  while ($line=fgets($fp))
25  {
26  $line=trim($line);
27  if (preg_match('/<!DOCTYPE NETSCAPE-Bookmark-file-1>/i', $line)) {
29  }
30  }
31  }
32  return false;
33  }
print $file
__parseNetscape(&$fp)
parse Netscape bookmark 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: