ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 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
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 40 of file class.ilBookmarkImportExport.php.

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

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
static _convertCharset($string, $from_charset='', $to_charset='UTF-8')
converts charset of given string
$url
Definition: shib_logout.php:72
Create styles array
The data for the language used.
static _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()

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

Referenced by __parseNetscape().

216  {
217  if (extension_loaded("mbstring"))
218  {
219  if (!$from_charset)
220  {
221  // try to detect charset
222  mb_detect_order("ASCII, JIS, UTF-8, EUC-JP, SJIS, ISO-8859-15, Windows-1252");
223  $from_charset=mb_detect_encoding ($string);
224  }
225  if (strtoupper($from_charset)!=$to_charset)
226  {
227  return @mb_convert_encoding($string,$to_charset,$from_charset);
228  }
229  }
230  return $string;
231  }
+ 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 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_callback(
192  '/&#(\d+);/m',
193  function($hit){
194  return chr($hit[1]);
195  },
196  $string
197  ); #decimal notation
198  $string= preg_replace_callback(
199  '/&#x([a-f0-9]+);/mi',
200  function($hit) {
201  return chr(hexdec($hit[1]));
202  },
203  $string
204  ); #hex notation
205  return $string;
206  }
+ 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 113 of file class.ilBookmarkImportExport.php.

References $title, __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  }
static getObject($a_id)
static
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  {
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  }
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: