-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadbookmark.php
75 lines (65 loc) · 2.53 KB
/
readbookmark.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
if( php_sapi_name() != 'cli' ){
$enter = '<br />';
$space = ' ';
}else{
$enter = "\n";
$space = ' ';
}
$file = file_get_contents('bookmarks.json');
$bookmark = json_decode($file);
/*
foreach($bookmark->children as $child){
echo $enter . $child->title;
echo $enter . $child->root;
}
*/
echo read($bookmark);
function read( $children, $node = 1, $result = '' ) {
$space = '';
for( $i=1; $i <= $node; $i++ ){
$space .= $GLOBALS['space'];
}
if( gettype($children) == 'object' || @$children->type ){
if( $result == '' )
$result .= "** This is a firefox json bookmark export file.**" . $GLOBALS['enter'] . $GLOBALS['enter'];
//if( @$children->children && $node <= 3 ){
if( @$children->children ){
$node++;
$result .= ($space . $children->title . '(' . $children->id . ' ' .$children->type . ')');
$result .= $GLOBALS['enter'];
foreach( $children->children as $key => $child ){
$result = read( $child, $node, $result );
if( $key == (count($children->children)-1) ){
$result .= $GLOBALS['enter'];
}
}
}else{
//$result .= ($space . $children->title . '(' . $children->id . ')');
//$result .= ' -> ' . @$children->uri . $GLOBALS['enter'];
$result .= echoresult( ($children->title.'('.$children->id.' '.$children->type.')'), @$children->uri, $space, $children->type );
$node--;
}
}else{
$result .= "This is not a json firefox bookmark file" . $GLOBALS['enter'] . $GLOBALS['enter'];
}
return $result;
}
function echoresult( $title, $href, $space, $var1 = '', $var2 = '' ){
if( php_sapi_name() != 'cli' ){
if( $href ){
$link = $space . '<a href="' . $href . '" target="_blank">' . $title . '</a>' . $GLOBALS['enter'];
}else{
$link = $space . '<a href="javascript:void(0)" style="color:#ccc">' . $title . '</a>' . $GLOBALS['enter'];
}
}else{
$link = $space . $title;
if( $href )
$link .= ' -> ' . $href;
$link .= $GLOBALS['enter'];
}
if( $var1 == 'text/x-moz-place-container' )
$link .= $GLOBALS['enter'];
return $link;
}
echo $GLOBALS['enter']; ?>