status SVG; twitter2feed

- status SVG plus discret quand c'est ok
- support twitter2feed en test (valeur par défaut: LOCAL)
This commit is contained in:
Mitsukarenai 2013-07-01 19:25:30 +02:00
parent 7c5fa0f73f
commit e13089514c
3 changed files with 41 additions and 22 deletions

View file

@ -28,10 +28,11 @@
// define( 'ALLOW_NEW_AUTOBLOGS_BY_XSAF', TRUE ); // define( 'ALLOW_NEW_AUTOBLOGS_BY_XSAF', TRUE );
/** /**
* More about TwitterBridge : https://github.com/mitsukarenai/twitterbridge * More about TwitterBridge : https://github.com/mitsukarenai/twitterbridge and twitter2feed: https://github.com/mitsukarenai/twitter2feed
* replace FALSE with the twitterbridge request URL (example: 'http://www.suumitsu.eu/twitter/?u=' ) * replace LOCAL with the twitterbridge request URL (example: 'http://www.suumitsu.eu/twitter/?u=' ) or leave LOCAL to use the included twitter2feed.php.
* set to FALSE if you want to fully disable Twitter support
**/ **/
// define( 'API_TWITTER', FALSE ); // define( 'API_TWITTER', LOCAL );
/** /**
* Import autoblogs from friend's autoblog farm - Add a link to the JSON export * Import autoblogs from friend's autoblog farm - Add a link to the JSON export

View file

@ -232,15 +232,15 @@ if (isset($_GET['check']))
/* SVG minimalistes */ /* SVG minimalistes */
function svg_status($fill, $stroke, $text) function svg_status($fill, $text, $back)
{ {
$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15"><g><rect width="15" height="15" x="0" y="0" style="fill:'.$fill.';stroke:'.$stroke.'"/></g><text style="font-size:10px;font-weight:bold;text-anchor:middle;font-family:Arial"><tspan x="7" y="11">'.$text.'</tspan></text></svg>'; $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="15" height="15">'.$back.'<text style="font-size:10px;font-weight:bold;text-anchor:middle;font-family:Arial;fill:'.$fill.';"><tspan x="8" y="14">'.$text.'</tspan></text></svg>';
return $svg; return $svg;
} }
$svg_vert=svg_status('#00ff00', '#008000', 'OK'); $svg_ok=svg_status('#008000', 'ok', '');
$svg_jaune=svg_status('#ffff00', '#ffcc00', 'mv'); $svg_mv=svg_status('#0000ff', 'mv', '<rect width="100%" height="100%" fill="#ffd800"/>');
$svg_rouge=svg_status('#ff0000', '#800000', 'err'); $svg_err=svg_status('#000000', 'err', '<rect width="100%" height="100%" fill="#ff0000"/>');
$errorlog="./".escape( $_GET['check'] ) ."/error.log"; $errorlog="./".escape( $_GET['check'] ) ."/error.log";
@ -249,9 +249,9 @@ function svg_status($fill, $stroke, $text)
if(file_exists($errorlog) && filemtime($errorlog) < $expire) { unlink($errorlog); } /* errorlog périmé ? Suppression. */ if(file_exists($errorlog) && filemtime($errorlog) < $expire) { unlink($errorlog); } /* errorlog périmé ? Suppression. */
if(file_exists($errorlog)) /* errorlog existe encore ? se contenter de lire sa taille pour avoir le statut */ if(file_exists($errorlog)) /* errorlog existe encore ? se contenter de lire sa taille pour avoir le statut */
{ {
if(filesize($errorlog) == "0") {die($svg_vert);} if(filesize($errorlog) == "0") {die($svg_ok);}
else if(filesize($errorlog) == "1") {die($svg_jaune);} else if(filesize($errorlog) == "1") {die($svg_mv);}
else {die($svg_rouge);} else {die($svg_err);}
} }
else /* ..sinon, lancer la procédure de contrôle */ else /* ..sinon, lancer la procédure de contrôle */
{ {
@ -263,7 +263,7 @@ function svg_status($fill, $stroke, $text)
updateXML('unavailable', 'nxdomain', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); updateXML('unavailable', 'nxdomain', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
} }
file_put_contents($errorlog, '..'); file_put_contents($errorlog, '..');
die($svg_rouge); die($svg_err);
} }
$code=explode(" ", $headers[0]); $code=explode(" ", $headers[0]);
/* code retour 200: flux disponible */ /* code retour 200: flux disponible */
@ -272,7 +272,7 @@ function svg_status($fill, $stroke, $text)
updateXML('available', '200', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); updateXML('available', '200', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
} }
file_put_contents($errorlog, ''); file_put_contents($errorlog, '');
die($svg_vert); die($svg_ok);
} }
/* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */ /* autre code retour: un truc a changé (redirection, changement de CMS, .. bref vvb.ini doit être corrigé) */
else { else {
@ -280,7 +280,7 @@ function svg_status($fill, $stroke, $text)
updateXML('moved', '3xx', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']); updateXML('moved', '3xx', escape($_GET['check']), $ini['SITE_TITLE'], $ini['SITE_URL'], $ini['FEED_URL']);
} }
file_put_contents($errorlog, '.'); file_put_contents($errorlog, '.');
die($svg_jaune); die($svg_mv);
} }
} }
} }
@ -554,10 +554,15 @@ if( !empty($_POST['socialinstance']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLO
if( API_TWITTER !== FALSE ) { if( API_TWITTER !== FALSE ) {
$sitetype = 'twitter'; $sitetype = 'twitter';
$siteurl = 'http://twitter.com/'. $socialaccount; $siteurl = 'http://twitter.com/'. $socialaccount;
$rssurl = API_TWITTER.$socialaccount; if ( API_TWITTER === 'LOCAL' ) {
$rssurl = serverUrl(true).'twitter2feed.php?u='.$socialaccount;
}
else {
$rssurl = API_TWITTER.$socialaccount;
// check // check
$twitterbridge = get_headers($rssurl, 1); $twitterbridge = get_headers($rssurl, 1);
if ($twitterbridge['0'] == 'HTTP/1.1 403 Forbidden') { $error[] = "La twitterbridge a refusé ce nom d'utilisateur: <br>\n<pre>".htmlentities($twitterbridge['X-twitterbridge']).'</pre>'; } if ($twitterbridge['0'] == 'HTTP/1.1 403 Forbidden') { $error[] = "La twitterbridge a refusé ce nom d'utilisateur: <br>\n<pre>".htmlentities($twitterbridge['X-twitterbridge']).'</pre>'; }
}
} }
else else
$error[] = 'Vous devez définir une API Twitter -> RSS dans votre fichier de configuration (see <a href="https://github.com/mitsukarenai/twitterbridge">TwitterBridge</a>).'; $error[] = 'Vous devez définir une API Twitter -> RSS dans votre fichier de configuration (see <a href="https://github.com/mitsukarenai/twitterbridge">TwitterBridge</a>).';
@ -825,7 +830,12 @@ if( !empty($_POST['opml_file']) && ALLOW_NEW_AUTOBLOGS && ALLOW_NEW_AUTOBLOGS_BY
<input placeholder="Identifiant du compte" type="text" name="socialaccount" id="socialaccount"><br> <input placeholder="Identifiant du compte" type="text" name="socialaccount" id="socialaccount"><br>
<?php <?php
if( API_TWITTER !== FALSE ) if( API_TWITTER !== FALSE )
echo '<input type="radio" name="socialinstance" value="twitter">Twitter (via <a href="'.substr(API_TWITTER, 0, -2).'status">twitterbridge</a>)<br>'; {
if( API_TWITTER === 'LOCAL' )
echo '<input type="radio" name="socialinstance" value="twitter">Twitter (local)<br>';
else
echo '<input type="radio" name="socialinstance" value="twitter">Twitter (via <a href="'.substr(API_TWITTER, 0, -2).'status">twitterbridge</a>)<br>';
}
else echo '<s>Twitter</s><br>'; ?> else echo '<s>Twitter</s><br>'; ?>
<input type="radio" name="socialinstance" value="identica">Identica<br> <input type="radio" name="socialinstance" value="identica">Identica<br>
<input type="radio" name="socialinstance" value="statusnet"> <input type="radio" name="socialinstance" value="statusnet">

View file

@ -3,13 +3,21 @@
* Récupération du flux RSS d'un compte Twitter * Récupération du flux RSS d'un compte Twitter
* Passez le nom du compte en Paramètre. Exemple: http://monsite.com/twit2rss.php?name=Craftbukkit * Passez le nom du compte en Paramètre. Exemple: http://monsite.com/twit2rss.php?name=Craftbukkit
* 2013 - by Tronics * 2013 - by Tronics
* -- ajout exclusion de réponses par Mitsu >> suggéré pour Projet Autoblog
*/ */
if (!isset($_GET["name"])) // ----------------------------
die (); // Autoblog Project inclusion
// ----------------------------
if(file_exists("config.php")) require_once "config.php";
if( !defined('API_TWITTER')) {header("HTTP/1.1 404 Not Found"); die('API_TWITTER is undefined: make it LOCAL in "config.php" if you want me to work for you.');}
if ('API_TWITTER' === FALSE) {header("HTTP/1.1 404 Not Found"); die('Twitter support disabled in "config.php". Sorry.');}
if ('API_TWITTER' !== 'LOCAL') {header("HTTP/1.1 404 Not Found"); die('Custom twitterbridge defined in "config.php": leave me alone.');}
if(!isset($_GET['u'])) {header("HTTP/1.1 404 Not Found"); die('no username provided');}
$exclude_reply = '@'; // if you want twitter2feed to return replies too: $exclude_reply = '';
// ----------------------------
// Let's rock !
$name = $_GET["name"]; $name = $_GET["u"];
$str = file_get_contents("https://twitter.com/$name"); $str = file_get_contents("https://twitter.com/$name");
$nb = preg_match_all('%<div class="tweet original-tweet(.*)'. $nb = preg_match_all('%<div class="tweet original-tweet(.*)'.
@ -90,7 +98,7 @@
$footer = "<br/>\r\n<a href=\"https://twitter.com/$mname/status/$id\">Afficher la conversation</a>"; $footer = "<br/>\r\n<a href=\"https://twitter.com/$mname/status/$id\">Afficher la conversation</a>";
$message = "$header$rt$message$footer"; $message = "$header$rt$message$footer";
$message = htmlspecialchars($message); $message = htmlspecialchars($message);
if(substr($title, 0, 1) !== '@') { // exclude response if(substr($title, 0, 1) !== $exclude_reply) {
echo <<<HTML echo <<<HTML
<entry> <entry>
<title>$title</title> <title>$title</title>
@ -106,7 +114,7 @@
</author> </author>
</entry> </entry>
HTML; HTML;
} // end exclude response }
} }
} }