Commit 6529a24d authored by Mindiell's avatar Mindiell
Browse files

First commit

parents
config.php
configuration.sh
Outil de revue de presse
GPL v2
2006-2009
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
require_once("config.php");
$id=intval($_REQUEST["id"]);
$c=@mysql_fetch_array(mysql_query("SELECT * FROM presse WHERE id='$id';"));
?>
<a href="<?=$c["url"]; ?>" target="_blank"><?=substr($c["url"],0,80); ?></a><br />
<h2><?=$c["title"]; ?></h2>
<?php if (is_file("ssc/".$id.".jpg")) { ?>
<img src="/rp/ssc/<?=$id; ?>.jpg" alt="" title="" id="ssc<?=$id; ?>"/><a href="javascript:regenerate('<?=$id; ?>');" title="Cliquer ici pour supprimer la vignette actuelle" accesskey="x">X</a><br />
<?php } ?>
<?php if (is_file("txt/".$id.".txt")) {
echo str_replace("\n\n","\n<br /><br />\n",iconv("ISO-8859-1","UTF-8",file_get_contents("txt/".$id.".txt")));
} ?>
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
require_once("config.php");
$action=trim($_REQUEST["action"]);
$id=intval($_REQUEST["id"]);
$HOME="/html/p/pi/site/rp/";
if ($action=="regenerate") {
@unlink($HOME."sc/".$id.".jpg");
@unlink($HOME."ssc/".$id.".jpg");
mysql_query("UPDATE presse SET screenshot=0 WHERE id='$id';");
exit();
}
if ($action=="note") {
mysql_query("UPDATE presse SET note=note+ '".intval($_REQUEST["note"])."' WHERE id='$id';");
list($note)=@mysql_fetch_array(mysql_query("SELECT note FROM presse WHERE id='$id';"));
echo $note;
exit();
}
$field=trim($_REQUEST["field"]);
if ($field!="published" && $field!="cite") {
echo "-1"; exit();
}
$status=intval($_REQUEST["status"]);
list($res)=@mysql_fetch_array(mysql_query("SELECT $field FROM presse WHERE id = $id ;"));
if ($res==$status) {
$status=0;
}
mysql_query("UPDATE presse SET $field = $status WHERE id = $id ;");
echo mysql_error();
list($res)=@mysql_fetch_array(mysql_query("SELECT $field FROM presse WHERE id = $id ;"));
echo $res;
?>
\ No newline at end of file
<?php
mysql_connect("localhost","root","password");
mysql_select_db("pi");
require_once("functions.php");
$HOME="/html/p/pi/site/rp/";
?>
\ No newline at end of file
#!/bin/bash
HTTP_USER=""
HTTP_PWD=""
en.png

319 Bytes

exec.png

854 Bytes

fr.png

267 Bytes

This diff is collapsed.
ham.gif

551 Bytes

ham2.gif

348 Bytes

<?php
require_once("config.php");
function is_utf8($string) {
// From http://w3.org/International/questions/qa-forms-utf-8.html
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string);
}
if(!function_exists('mb_detect_encoding')) {
function mb_detect_encoding($string, $enc=null) {
static $list = array('utf-8', 'iso-8859-1', 'windows-1251');
foreach ($list as $item) {
$sample = iconv($item, $item, $string);
if (md5($sample) == md5($string)) {
if ($enc == $item) { return true; } else { return $item; }
}
}
return false;
}
}
function extractURL($url)
{
// On set le titre avec la fin de l'url
$cleanUrl = $url;
$cleanUrl = str_replace(".html", "", $cleanUrl);
$cleanUrl = str_replace(".htm", "", $cleanUrl);
$cleanUrl = str_replace(".asp", "", $cleanUrl);
$cleanUrl = str_replace(".aspx", "", $cleanUrl);
$cleanUrl = str_replace(".php", "", $cleanUrl);
return substr($cleanUrl, -60);
}
function importTitre()
{
$mysqli = LQDNConnect();
// Requête d'un seul article sans titre en commençant par le plus récent
// On ne récupère pas les pdf, ni les webm, ni les mp3 qu'on ne sait pas lire
// TODO: S'il y en a plusieurs, on ne crée les titres d'article qu'un par un...
$lineWithoutTitle = "SELECT * FROM `presse` WHERE `url` NOT REGEXP '(webm|pdf|mp3)$' AND `title` = '' ORDER BY `id` DESC LIMIT 0, 1";
$result = $mysqli->query($lineWithoutTitle);
$row = $result->fetch_assoc();
$url = $row['url'];
// Ouverture de l'url
// TODO: pour éviter les blocages, il faudrait avoir un timeout là-dessus
$handle = fopen($url, "r");
if ($handle)
{
//echo "fopen ok<br>";
while(!feof($handle))
$data .= fgets($handle, 5000000);
if ($data)
{
$DOM = new DOMDocument;
$DOM->loadHTML($data);
$items = $DOM->getElementsByTagName('title');
if ($items->length > 0)
$title = $items->item(0)->nodeValue;
}
if($title == "")
$title = extractURL($url);
// Si le titre est trouvé, on préfixe par le nom du média
// TODO: Pourquoi on ne fait pas la même chose lors des erreurs d'ouverture plus bas ?
if ($title != "")
{
// grab the website uri then split it on "."
eregi("https?://([^/]*)/", $url, $tabreponse);
$split_response = explode(".", $tabreponse[1]);
// TODO: Cette partie passe la première lettre de chaque mot en majuscule de manière crade...
// remove "www" and "com"
// this piece of code is a crape
$working_array = array();
for ($i = 0; $i < sizeof($split_response); ++$i)
if ($split_response[$i] != "www" and $split_response[$i] != "com")
array_push($working_array, $split_response[$i]);
$result = "";
for ($i = 0; $i < sizeof($working_array); ++$i)
{
// ucfirst to upper the first char of the string
$result = $result . ucfirst($working_array[$i]);
// if this isn't the last element add a "." (ie: Elpais.Es)
if ($i < sizeof($working_array) - 1)
$result = $result . ".";
}
// format
$title = "[" . $result . "] " . $title;// . "\r\n";
}
// TODO: Ici, on finit avec un titre vide, on va donc bloquer sur cet article indéfiniment...
else
$title = "";
}
else
{
// Dans les cas non fonctionnels (erreur 404 par exemple),
// on remplit le titre avec la fin de l'url
$title = extractURL($url);
// TODO: Pourquoi faire un echo ici ? Ça finit par s'afficher sur la page web...
echo $title."<br>";
}
$title = str_replace(array("\r","\n"), "", $title);
$title = addslashes($title);
// On affecte le titre à l'article
$sqlUpdate = "UPDATE `presse` set `title` = '".$title."' WHERE `id` = '".$row["id"]."'";
$mysqli->query($sqlUpdate);
}
?>
<?php
require_once("config.php");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
// On importe dans drupal l'article demande. On ne cree pas d'alias : il faudra le recreer d'apres le titre...
$error=array();
$id=intval($_REQUEST["id"]);
if (!$id) {
$error[]="Please tell us which link we should import into Drupal";
include("index.php");
exit();
}
$c=@mysql_fetch_array(mysql_query("SELECT * FROM presse WHERE id='$id';"));
if (!$c) {
$error[]="The requested url does not exist, please check";
include("index.php");
exit();
}
if ($c["node"]!=0) {
$error[]="This url has already been imported into drupal";
include("index.php");
exit();
}
function new_seq($name) {
mysql_query("LOCK TABLE `sequences`");
mysql_query("UPDATE `sequences` SET id=id+1 WHERE name='$name';");
list($id)=@mysql_fetch_array(mysql_query("SELECT id FROM `sequences` WHERE name='$name';"));
mysql_query("UNLOCK TABLE `sequences`");
return $id;
}
function dblbr($str) {
$str=str_replace("\n\n","<br />",$str);
$str=str_replace("\n"," ",$str);
return str_replace("<br />","\r\n\r\n",$str);
}
#$nrid=new_seq("node_revisions_vid");
#$nid=new_seq("node_nid");
$hasfile=false;
if (is_file($HOME."/ssc/".$c["id"].".jpg")) {
copy($HOME."/ssc/".$c["id"].".jpg",$DRUPALDIR."/files/rp/".$c["id"].".jpg");
$hasfile=true;
# $fid=new_seq("files_fid");
}
if ($_REQUEST["lang"]=="1") $lang="en"; else $lang="fr";
if ($hasfile) {
$sqlplus="<img src=\"/files/rp/".$c["id"].".jpg\" class=\"l\" />\r\n\r\n";
}
// rp patch to fetch future rp node informations from the website
function clean($entete)
{
$entete = str_replace("’", "'", $entete);
$entete = str_replace("…", "...", $entete);
return $entete;
}
$title = "";
$entete = "";
$date = "";
try {
if (eregi("http://www.ecrans.fr", $c["url"]) or eregi("http://ecrans.fr", $c["url"]))
{
$handle = @fopen($c["url"], "r");
if ($handle)
{
while(!feof($handle))
{
$data = fgets($handle, 5000000);
//echo $data;
if ($data)
{
if ($title == "" and eregi("<h3>(.*)</h3>", $data, $tabreponse))
$title = "[Ecrans.Fr] " . $tabreponse[1];
if ($title == "" and eregi("<h1>(.*)</h1>", $data, $tabreponse))
$title = "[Ecrans.Fr] " . $tabreponse[1];
if ($date == "" and eregi("<p class=\"date\"> *(.*)", $data, $tabreponse))
$date = $tabreponse[1];
if ($entete == "" and eregi("<p class=\"spip\"> *(.*)", $data, $tabreponse))
$entete = "<p>" . $tabreponse[1] . "</p>";
}
}
if ($title != "")
{
html_entity_decode($title, ENT_COMPAT, 'UTF-8') . "\r\n";
$title = clean($title);
$title = iconv("UTF-8", "ISO-8859-1", $title);
}
else
$title = "[Ecrans.Fr]";
if ($date != "")
{
$date = html_entity_decode($date, ENT_COMPAT, 'UTF-8');
$mois = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
$month = array("january", "february", "march", "april", "may", "june", "jully", "august", "september", "october", "november", "december");
$date = str_replace($mois, $month, $date);
$jours = array("lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche");
$days = array("monday", "tuesday", "wednesday", "thursday", "saturday", "sunday");
$date = str_replace($jours, $days, $date);
$date = strtotime($date);
}
else
$date = time();
if ($entete != "")
{
html_entity_decode($entete, ENT_COMPAT, 'UTF-8');
$entete = clean($entete);
$entete = iconv("UTF-8", "ISO-8859-1", $entete);
}
else
$entete = "Pas réussit à choper l'entête.\r\n";
}
fclose($handle);
}
else if (eregi("http://www.pcinpact.com/", $c["url"]))
{
$handle = @fopen($c["url"], "r");
if ($handle)
{
$news = false;
while(!feof($handle))
{
$data = fgets($handle, 5000000);
//echo $data;
if ($data)
{
if ($title == "" and eregi("<span class=\"news_titre_or\">(.*)</span><", $data, $tabreponse))
$title = $tabreponse[1];
if ($date == "" and eregi("</strong> le (.*)\(<span", $data, $tabreponse))
$date = $tabreponse[1];
if (eregi("<div class=\"corps_news_texte\" id=\"intelliTXT\">", $data, $tabreponse))
$news = true;
if ($entete == "" and $news and eregi("<strong>(.*)</strong>", $data, $tabreponse))
$entete = $tabreponse[1];
}
}
if ($title != "")
{
$title = iconv("ISO-8859-1", "UTF-8", $title);
$title = "[PCInpact]" . trim(html_entity_decode($title, ENT_NOQUOTES, 'UTF-8')) . "\r\n";
$title = iconv("UTF-8", "ISO-8859-1", $title);
}
else
$title = "[PCInpact]\r\n";
//stupid strtotime fail
//if ($date != "")
//{
//$date = iconv("ISO-8859-1", "UTF-8", $date);
//$date = html_entity_decode($date, ENT_COMPAT, 'UTF-8');
//$mois = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
//$month = array("january", "february", "march", "april", "may", "june", "jully", "august", "september", "october", "november", "december");
//$date = str_replace($mois, $month, $date);
//$jours = array("lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche");
//$days = array("monday", "tuesday", "wednesday", "thursday", "saturday", "sunday");
//$date = str_replace($jours, $days, $date);
//$date = str_replace("à ", "", $date);
//echo $date . "\n";
//$date = strtotime($date);
//echo $date . "\n";
//}
//else
$date = time();
if ($entete != "")
{
$entete = iconv("ISO-8859-1", "UTF-8", $entete);
$entete = "<p>" . trim(html_entity_decode($entete, ENT_COMPAT, 'ISO-8859-1')) . "</p>" . "\r\n";
$entete = clean($entete);
$entete = iconv("UTF-8", "ISO-8859-1", $entete);
}
else
$entete = "Pas réussit à choper l'entête.\r\n";
}
}
else if (eregi("http://www.zdnet.fr/", $c["url"]))
{
$handle = @fopen($c["url"], "r");
if ($handle)
{
while(!feof($handle))
{
$data = fgets($handle, 5000000);
//echo $data;
if ($data)
{
if ($title == "" and eregi("<title>(.*)</title>", $data, $tabreponse))
$title = $tabreponse[1];
if ($date == "" and eregi("<span class=\"date\">(.*)</span>", $data, $tabreponse))
$date = $tabreponse[1];
if (eregi("<div id=\"storytext\">", $data, $tabreponse))
$youplai = 1;
// y a un double cas car les blogs et le site principale ont pas la même mise en forme
if ($entete == "" and (eregi("<em class=\"keyword\">.*</em> - (.*)</strong>", $data, $tabreponse) or ($youplai and eregi("<p>(.*)", $data, $tabreponse))))
$entete = $tabreponse[1];
//if (!eregi("<div class=\"span-16 last contentzone wide classic\">", $data, $tabreponse))
//$youplai = 0;
}
}
if ($title != "")
{
//$title = iconv("ISO-8859-1", "UTF-8", $title);
$title = "[ZDNet.Fr] " . $title . "\r\n";
}
else
$title = "[ZDNet.Fr] " . "\r\n";
//if ($date != "")
//{
//$date = iconv("ISO-8859-1", "UTF-8", $date);
//$date = html_entity_decode($date, ENT_COMPAT, 'UTF-8');
//$mois = array("janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre");
//$month = array("january", "february", "march", "april", "may", "june", "jully", "august", "september", "october", "november", "december");
//$date = str_replace($mois, $month, $date);
//$jours = array("lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche");
//$days = array("monday", "tuesday", "wednesday", "thursday", "saturday", "sunday");
//$date = str_replace($jours, $days, $date);
//$date = strtotime($date);
//}
if ($entete != "")
{
//$entete = iconv("ISO-8859-1", "UTF-8", $entete);
$entete = "<p>" . trim(html_entity_decode($entete, ENT_COMPAT, 'UTF-8')) . "</p>" . "\r\n";
}
}
}
else if (eregi("http://owni.fr/", $c["url"]) or eregi("http://ownilive.com", $c["url"]))
{
$handle = @fopen($c["url"], "r");
if ($handle)
{
while(!feof($handle))
{
$data = fgets($handle, 5000000);
//echo $data;
if ($data)
{
if ($title == "" and eregi("<meta name=\"title\" content=\"(.*)\" />", $data, $tabreponse))
$title = $tabreponse[1];
//if ($date == "" and eregi("<span class=\"date\">le (.*)</span>", $data, $tabreponse))
//$date = $tabreponse[1];
if (eregi("<div class=\"span-16 last contentzone wide classic\">", $data, $tabreponse))
$youplai = 1;
if ($entete == "" and $youplai and eregi("<p>(.*)</p>", $data, $tabreponse))
$entete = $tabreponse[1];
if (!eregi("<div class=\"span-16 last contentzone wide classic\">", $data, $tabreponse))
$youplai = 0;
}
}
if ($title != "")
{
//$title = iconv("ISO-8859-1", "UTF-8", $title);
$title = "[Owni] " . $title . "\r\n";
$title = clean($title);
$title = iconv("UTF-8", "ISO-8859-1", $title);
}
else
$title = "[Owni]\r\n";
//if ($date != "")
//{
//$date = date("Y-m-d ", strtotime($date)) . "13:37:42" . "\n";
//}
if ($entete != "")
{
//$entete = iconv("ISO-8859-1", "UTF-8", $entete);
$entete = "<p>" . trim(html_entity_decode($entete, ENT_COMPAT, 'UTF-8')) . "</p>" . "\r\n";
$entete = clean($entete);
$entete = iconv("UTF-8", "ISO-8859-1", $entete);
}
else
$entete = "J'ai pas réussit à trouver l'entête.\r\n";
}
}
// we don't know this website, so we are going to take his <title></title> and format his url into [] in CamelCase style
else
{
$handle = @fopen($c["url"], "r");
if ($handle)
{
while(!feof($handle))
{
$data = fgets($handle, 5000000);
//echo $data;
if ($data)
{
if ($title == "" and eregi("<title>(.*)</title>", $data, $tabreponse))
$title = $tabreponse[1];
}
}
if ($title != "")
{
// grab the website uri then split it on "."
eregi("https?://([^/]*)/", $c["url"], $tabreponse);
$split_response = explode(".", $tabreponse[1]);
// remove "www" and "com"
// this piece of code is a crape
$working_array = array();
for ($i = 0; $i < sizeof($split_response); ++$i)
if ($split_response[$i] != "www" and $split_response[$i] != "com")
array_push($working_array, $split_response[$i]);
$result = "";
for ($i = 0; $i < sizeof($working_array); ++$i)
{
// ucfirst to upper the first char of the string
$result = $result . ucfirst($working_array[$i]);
// if this isn't the last element add a "." (ie: Elpais.Es)
if ($i < sizeof($working_array) - 1)
$result = $result . ".";
}
// format
$title = "[" . $result . "] " . $title . "\r\n";
}
else
$title = "";
}
}
// dates won't work for the moment :(
//else
//{
$date = time();
//}
}
catch (Exception $e)
{
$date = time();
$title = "Fail :(, here is the exception for Bram:" . $e;
}
if ($entete != "")
mysql_query("INSERT INTO `node_revisions` VALUES (0,NULL,2,'".addslashes($title).addslashes($c["title"])."','".$sqlplus.addslashes($content)."\r\n\r\n".$sqlplus.addslashes($entete)."\r\n\r\n".$c["url"]."\r\n','','',".$date.",3);");
else
mysql_query("INSERT INTO `node_revisions` VALUES (0,NULL,2,'".addslashes($title).addslashes($c["title"])."','".$sqlplus.addslashes($content)."\r\n\r\n".$c["url"]."\r\n','','',".time().",3);");
// old sql injection
//mysql_query("INSERT INTO `node_revisions` VALUES (0,NULL,2,'".addslashes($c["title"])."','".$sqlplus.addslashes($content)."\r\n\r\n".$c["url"]."\r\n','','',".time().",3);");
// end of rp patch
if (mysql_errno()) echo "1:".mysql_error()."<br>\n";
$nrid=mysql_insert_id();
mysql_query("INSERT INTO `node` VALUES (NULL,$nrid,'revue_de_presse','".addslashes($c["title"])."',2,0,".time().",".time().",0,0,0,0,'$lang',0,0);");
if (mysql_errno()) echo "2:".mysql_error()."<br>\n";
$nid=mysql_insert_id();
mysql_query("INSERT INTO `node_access` VALUES ($nid,0,'all',1,0,0);");
if (mysql_errno()) echo "3:".mysql_error()."<br>\n";
mysql_query("INSERT INTO `node_comment_statistics` VALUES ($nid,".time().",NULL,2,0);");