Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

Raw Paste Créer un nouveau Paste

bookmark - #5D994C3D92

  1. <?php
  2.  
  3. // nom du fichier a lire >> A MODIFIER
  4. $files="data/medias/bookmarks_shaarli.html";
  5. $data=file_get_contents($files);
  6. // echo $data; // affiche le contenu du fichier
  7.  
  8.  
  9. // Tells if a string start with a substring or not.
  10. function startsWith($haystack,$needle,$case=true)
  11. {
  12. if($case){return (strcmp(substr($haystack, 0, strlen($needle)),$needle)===0);}
  13. return (strcasecmp(substr($haystack, 0, strlen($needle)),$needle)===0);
  14. }
  15.  
  16. // Tells if a string ends with a substring or not.
  17. function endsWith($haystack,$needle,$case=true)
  18. {
  19. if($case){return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);}
  20. return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)),$needle)===0);
  21. }
  22.  
  23.  
  24.  
  25. $type='unknown';
  26. if (startsWith($data,'<!DOCTYPE NETSCAPE-Bookmark-file-1>')) $type='netscape'; // Netscape bookmark file (aka Firefox).
  27.  
  28. // Then import the bookmarks.
  29. if ($type=='netscape') // le format est OK et on peut importer
  30. { // echo "Le format est OK (type=netscape) et on peut importer.";
  31.  
  32. $url="static4/shaarli?page";
  33. $nb_elem_per_page = 3;
  34. $page = isset($_GET['static4/shaarli?page'])?intval($_GET['static4/shaarli?page']-1):0;
  35. $data = (explode('<DT>',$data)) ;
  36. $number_of_pages = intval(count($data)/$nb_elem_per_page)+1;
  37.  
  38. // This format is supported by all browsers (except IE, of course), also delicious, diigo and others.
  39. // foreach(explode('<DT>',$data) as $html) // explode is very fast
  40.  
  41. foreach (array_slice ($data, $page*$nb_elem_per_page, $nb_elem_per_page) as $html)
  42. {
  43. // echo "$html <hr />";
  44. // if (startswith($html,'<A ')) { echo "$html <hr />"; }
  45.  
  46. $link = array('linkdate'=>'','title'=>'','url'=>'','description'=>'','tags'=>'','private'=>0);
  47. $d = explode('<DD>',$html);
  48. if (startswith($d[0],'<A '))
  49. {
  50. $link['description'] = (isset($d[1]) ? nl2br (html_entity_decode(trim($d[1]),ENT_QUOTES,'UTF-8')) : ''); // Get description (optional)
  51. // echo "Description : ".$link['description']; // affiche la description de l'item
  52.  
  53. preg_match('!<A .*?>(.*?)</A>!i',$d[0],$matches);
  54.  
  55. $link['title'] = (isset($matches[1]) ? trim($matches[1]) : ''); // Get title
  56. // echo "Title : ".$link['title']." <hr />"; // affiche le titre de l'item
  57. $link['title'] = html_entity_decode($link['title'],ENT_QUOTES,'UTF-8');
  58. // echo "<br><span style=\"color:brown\">Title : ".$link['title']." </span>"; // affiche le titre de l'item
  59.  
  60. preg_match_all('! ([A-Z_]+)=\"(.*?)"!i',$html,$matches,PREG_SET_ORDER); // Get all other attributes
  61. // echo "matches : "; var_dump ($matches) ; echo " <hr />";
  62.  
  63. $raw_add_date=0;
  64.  
  65.  
  66. foreach($matches as $m)
  67. {
  68. $attr=$m[1]; $value=$m[2];
  69. if ($attr=='HREF') $link['url']=html_entity_decode($value,ENT_QUOTES,'UTF-8');
  70. // echo 'url : '.$link['url'].'<hr />';
  71.  
  72. elseif ($attr=='TAGS') $link['tags']=html_entity_decode(str_replace(',',' ',$value),ENT_QUOTES,'UTF-8');
  73. // echo "tags : ".$link['tags']." <hr />";
  74. elseif ($attr=='PRIVATE') $link['private']=($value=='0'?0:1);
  75. // echo "private : ".$link['private']." <hr />";
  76. elseif ($attr=='ADD_DATE') $raw_add_date=intval($value); $link['linkdate']=date('d/m/Y',$raw_add_date);
  77. // echo "linkdate : ".$link['linkdate']." <hr />";
  78.  
  79. }
  80.  
  81. echo "<br><span style=\"color:brown\">Title : ".$link['title']." </span>"; // affiche le titre de l'item
  82. echo "<br>Description : ".$link['description']; // affiche la description de l'item
  83. echo "<br><span style=\"color:green\">url : ".$link['url']." </span>";
  84. echo "<br><span style=\"color:red\">tags : ".$link['tags']." </span>";
  85. echo "<br><span style=\"color:blue\">private : ".$link['private']." </span>";
  86. echo "<br><span style=\"color:silver\">linkdate : ".$link['linkdate']." </span><hr />";
  87.  
  88.  
  89.  
  90. } $i++;
  91. }
  92. }
  93.  
  94. else { echo " has an unknown file format. Nothing was imported."; }
  95. ?>
  96.  
  97. <ul id='paginator'>
  98. <?php
  99. for($i=1;$i<$number_of_pages;$i++){ ?>
  100. <li><a href="index.php?<?php echo $url.'='.$i ; ?>"><?php echo $i ; ?></a></li>
  101. <?php } ?>
  102. </ul>

Pied de page des forums

Propulsé par FluxBB