From 479add0ec8966aa6d6e11e0b72eb83c29a77b0da Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Fri, 1 Mar 2013 12:14:46 +0100 Subject: [PATCH] - OPML Link implemented - Fix Duplicate 'Twitter' when import - Fix lost errors - Display OPML link for twitter/shaarli, etc. --- 0.3/config.php | 7 ++-- 0.3/functions.php | 6 ++- 0.3/index.php | 93 +++++++++++++++++++++++++++++++++++------------ 3 files changed, 77 insertions(+), 29 deletions(-) diff --git a/0.3/config.php b/0.3/config.php index 443f542..c321a94 100755 --- a/0.3/config.php +++ b/0.3/config.php @@ -47,6 +47,7 @@ function __($str) } } +define( 'ALLOW_FULL_UPDATE', TRUE ); define( 'ALLOW_NEW_AUTOBLOGS', TRUE ); // If you set ALLOW_NEW_AUTOBLOGS to FALSE, the following options do not matter. // Generic RSS @@ -56,9 +57,9 @@ define( 'ALLOW_NEW_AUTOBLOGS_BY_SOCIAL', TRUE ); // Bookmark button define( 'ALLOW_NEW_AUTOBLOGS_BY_BUTTON', TRUE ); // OPML file -define( 'ALLOW_NEW_AUTOBLOGS_BY_OPML', TRUE ); - -define( 'ALLOW_FULL_UPDATE', TRUE ); +define( 'ALLOW_NEW_AUTOBLOGS_BY_OPML_FILE', TRUE ); +// OPML Link +define( 'ALLOW_NEW_AUTOBLOGS_BY_OPML_LINK', TRUE ); // Logo à utiliser diff --git a/0.3/functions.php b/0.3/functions.php index 5f03c28..acc01d6 100755 --- a/0.3/functions.php +++ b/0.3/functions.php @@ -52,8 +52,10 @@ function createAutoblog($type, $sitename, $siteurl, $rssurl, $error = array()) { if( $type == 'generic' || empty( $type )) { $var = updateType( $siteurl ); $type = $var['type']; - if( !empty( $var['name']) ) - $sitename = ucfirst($var['name']) . ' - ' . $sitename; + if( !empty( $var['name']) ) { + if( !stripos($siteurl, $var['name'] === false) ) + $sitename = ucfirst($var['name']) . ' - ' . $sitename; + } } if(folderExists($siteurl)) { diff --git a/0.3/index.php b/0.3/index.php index 1069d9a..cd3ebd4 100755 --- a/0.3/index.php +++ b/0.3/index.php @@ -99,6 +99,23 @@ function check_antibot($number, $text_number) { return ( array_search( $text_number, $letters ) === intval($number) ) ? true : false; } +function create_from_opml($opml) { + global $error, $success; + + foreach( $opml->body->outline as $outline ) { + if ( !empty( $outline['title'] ) && !empty( $outline['xmlUrl']) && !empty( $outline['htmlUrl'] )) { + $siteurl = escape($outline['htmlUrl']); + $rssurl = DetectRedirect(escape( $outline['xmlUrl'])); + $sitename = escape( $outline['title'] ); + + $error = array_merge( $error, createAutoblog( 'generic', $sitename, $siteurl, $rssurl, $error ) ); + + if( empty ( $error )) + $success[] = 'Autoblog "'. $sitename .'" crée avec succès. → afficher l\'autoblog.'; + } + } +} + /** * SVG **/ @@ -295,7 +312,7 @@ if(!empty($_GET['via_button']) && $_GET['number'] === '17' && ALLOW_NEW_AUTOBLOG $sitename = escape($_GET['sitename']); $sitetype = escape($_GET['type']); - $error = createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $error); + $error = array_merge( $error, createAutoblog($sitetype, $sitename, $siteurl, $rssurl, $error)); if( empty($error)) { $form .= ''; $form .= '

Autoblog '. $sitename .' ajouté avec succès.
'; @@ -373,7 +390,7 @@ if(!empty($_POST['socialaccount']) && !empty($_POST['socialinstance']) && ALLOW_ $error[] = "Flux inaccessible (compte inexistant ?)"; } if( empty($error) ) { - $error = createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl, $error); + $error = array_merge( $error, createAutoblog($sitetype, ucfirst($socialinstance) .' - '. $socialaccount, $siteurl, $rssurl, $error)); if( empty($error)) $success[] = ''.ucfirst($socialinstance) .' - '. $socialaccount.' ajouté avec succès.'; } @@ -400,7 +417,7 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L $siteurl = escape($_POST['siteurl']); $sitename = get_title_from_feed($rssurl); - $error = createAutoblog('generic', $sitename, $siteurl, $rssurl, $error); + $error = array_merge( $error, createAutoblog('generic', $sitename, $siteurl, $rssurl, $error)); if( empty($error)) $success[] = 'Autoblog '. $sitename .' crée avec succès.afficher l\'autoblog'; @@ -430,9 +447,9 @@ if( !empty($_POST['generic']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_L } /** - * ADD BY OPML + * ADD BY OPML File **/ -if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML) { +if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML_FILE) { if(empty($_POST['number']) || empty($_POST['antibot']) ) {$error[] = "Vous êtes un bot ?";} elseif(! check_antibot($_POST['number'], $_POST['antibot'])) @@ -442,17 +459,7 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML if (is_uploaded_file($_FILES['file']['tmp_name'])) { $opml = null; if( ($opml = simplexml_load_file( $_FILES['file']['tmp_name'])) !== false ) { - foreach( $opml->body->outline as $outline ) { - if ( !empty( $outline['title'] ) && !empty( $outline['xmlUrl']) && !empty( $outline['htmlUrl'] )) { - $siteurl = escape($outline['htmlUrl']); - $rssurl = DetectRedirect(escape( $outline['xmlUrl'])); - $sitename = escape( $outline['title'] ); - - $error = createAutoblog( 'generic', $sitename, $siteurl, $rssurl, $error ); - if( empty ( $error )) - $success[] = 'Autoblog "'. $sitename .'" crée avec succès. → afficher l\'autoblog.'; - } - } + create_from_opml($opml); } else $error[] = "Impossible de lire le contenu du fichier OPML."; @@ -463,6 +470,26 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML } } +/** + * ADD BY OPML Link + **/ + if( !empty($_POST['opml_link']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML_LINK) { + if(empty($_POST['number']) || empty($_POST['antibot']) ) + {$error[] = "Vous êtes un bot ?";} + elseif(! check_antibot($_POST['number'], $_POST['antibot'])) + {$error[] = "Antibot : Ce n'est pas le bon nombre.";} + if( empty( $_POST['opml_url'] )) + {$error[] = 'Le lien est incorrect.';} + + if( empty( $error)) { + if ( ($opml = simplexml_load_file( escape($_POST['opml_url']) )) !== false ) { + create_from_opml($opml); + } + else + $error[] = "Impossible de lire le contenu du fichier OPML ou d'accéder à l'URL donnée."; + } +} + ?> @@ -541,9 +568,10 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML if(ALLOW_NEW_AUTOBLOGS_BY_SOCIAL) $button_list .= 'Compte réseau social Shaarli '; - if(ALLOW_NEW_AUTOBLOGS_BY_OPML) - $button_list .= 'Fichier OPML - Lien vers OPML '; + if(ALLOW_NEW_AUTOBLOGS_BY_OPML_FILE) + $button_list .= 'Fichier OPML '; + if(ALLOW_NEW_AUTOBLOGS_BY_OPML_LINK) + $button_list .= 'Lien vers OPML '; if(ALLOW_NEW_AUTOBLOGS_BY_BUTTON) $button_list .= 'Marque page '; $button_list .= '

'; @@ -582,7 +610,7 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML
-
+

@@ -590,12 +618,12 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML + if(ALLOW_NEW_AUTOBLOGS_BY_OPML_FILE == TRUE) { ?>

Ajouter par fichier OPML

- +

@@ -605,6 +633,21 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML + + +

Marque page

@@ -658,10 +701,11 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML if(!empty($autoblogs)){ foreach ($autoblogs as $key => $autoblog) { - if(escape($autoblog->site_type)=='generic') {$opml_link=' opml';} else $opml_link=''; + //if(escape($autoblog->site_type)=='generic') { + $opml_link='opml'; //} else $opml_link=''; $autoblogs_display .= '
-
config ini'.$opml_link.' | '.escape($autoblog->site_type).' source: '.escape($autoblog->site_url).'
+
config ini '.$opml_link.' | '.escape($autoblog->site_type).' source: '.escape($autoblog->site_url).'
'; } } @@ -684,6 +728,7 @@ if( !empty($_POST['opml']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY_OPML document.getElementById('add_shaarli').style.display = 'none'; document.getElementById('add_opmlfile').style.display = 'none'; document.getElementById('add_bookmark').style.display = 'none'; + document.getElementById('add_opmllink').style.display = 'none'; document.getElementById('button_list').style.display = 'block'; function show_form(str){ document.getElementById('add_'+str).style.display = 'block';