2a4527c3564b7a1639a1dc136b0bb6645ca612c0
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2016 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
9 * Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
10 * Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
11 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) {
17 function action_importer_bookmarks_opml_dist($fichier_ok, $id_parent, $importer_statut_publie, $importer_tags) {
19 if (autoriser('importer', '_sites')) {
20 $out = bookmarks_opml_parse($fichier_ok['contenu']);
21 $nb = bookmarks_opml_insert($out, $id_parent, $importer_statut_publie, $importer_tags);
28 // http://www.stargeek.com/php_scripts.php?script=20&cat=blog
29 function bookmarks_opml_parse(&$contenu) {
30 global $blogs, $folder, $inOpmlfolder, $inOpmlItem;
32 $inOpmlfolder = $inOpmlItem = false;
34 $xp = xml_parser_create();
36 xml_set_element_handler($xp, 'opml_startElement', 'opml_endElement');
38 xml_parse($xp, $contenu, true);
44 function opml_startElement($xp, $element, $attr) {
45 global $blogs, $folder, $inOpmlfolder, $inOpmlItem;
46 if (strcasecmp('outline', $element)) {
49 if (!array_key_exists('XMLURL', $attr) && (array_key_exists('TEXT', $attr) ||
array_key_exists('TITLE', $attr))) {
50 //some opml use title instead of text to define a folder (ex: newzcrawler)
51 $folder = $attr['TEXT'] ?
$attr['TEXT'] : $attr['TITLE'];
57 $blogs[$folder][] = $attr;
64 function opml_endElement($xp, $element) {
65 global $blogs, $folder, $inOpmlfolder, $inOpmlItem;
66 if (strcasecmp($element, "outline") === 0) {
67 if (!$inOpmlItem && $inOpmlfolder) {
68 // end of folder element!
69 $inOpmlfolder = false;
71 // end of item element
79 function bookmarks_opml_insert($tree, $id_parent, $importer_statut_publie, $importer_tags) {
80 include_spip('action/editer_rubrique');
81 include_spip('action/editer_site');
86 foreach ($tree as $key => $item) {
88 if (array_key_exists('XMLURL', $item)) {
90 if ($importer_statut_publie and autoriser('publierdans', 'rubrique', $id_parent)) {
94 if (!$id_syndic = sql_getfetsel('id_syndic', 'spip_syndic',
95 'id_rubrique=' . intval($id_parent) . " AND url_site=" . sql_quote($item['HTMLURL']))
97 $id_syndic = site_inserer($id_parent);
99 'url_site' => $item['HTMLURL'],
100 'nom_site' => $item['TITLE'],
101 'url_syndic' => $item['XMLURL'],
102 'syndication' => 'oui',
104 'date' => date('Y-m-d H:i:s', $now),
107 site_modifier($id_syndic, $set);
115 $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques',
116 'id_parent=' . intval($id_parent) . " AND titre=" . sql_quote($titre));
117 if (!$id_rubrique and $id_rubrique = rubrique_inserer($id_parent)) {
118 rubrique_modifier($id_rubrique, array('titre' => $titre));
121 $nb +
= bookmarks_opml_insert($item, $id_rubrique, $importer_statut_publie, $importer_tags);