Browse Source

code mort et coding standards

svn/root
james@rezo.net 2 years ago
parent
commit
716becdae9
19 changed files with 432 additions and 556 deletions
  1. +1
    -5
      .gitattributes
  2. +2
    -0
      .gitignore
  3. +78
    -61
      base/univers.php
  4. +14
    -18
      exec/universparse.php
  5. +0
    -16
      genie/univers_boss.php
  6. +34
    -12
      genie/univers_check.php
  7. +0
    -21
      genie/univers_check_1.php
  8. +0
    -21
      genie/univers_check_2.php
  9. +0
    -21
      genie/univers_check_3.php
  10. +3
    -3
      genie/univers_feed.php
  11. +0
    -16
      genie/univers_google.php
  12. +4
    -4
      genie/univers_referers.php
  13. +16
    -19
      genie/univers_statsv.php
  14. +115
    -211
      inc/univers.php
  15. +104
    -85
      inc/univers_analyser.php
  16. +50
    -0
      phpcs.xml.dist
  17. +0
    -16
      stats-tout.html
  18. +0
    -16
      stats-v.html
  19. +11
    -11
      univers_pipelines.php

+ 1
- 5
.gitattributes View File

@ -3,13 +3,8 @@ base/univers.php -text
/content_bg.gif -text
css/version.tree.css -text
exec/universparse.php -text
genie/univers_boss.php -text
genie/univers_check.php -text
genie/univers_check_1.php -text
genie/univers_check_2.php -text
genie/univers_check_3.php -text
genie/univers_feed.php -text
genie/univers_google.php -text
genie/univers_referers.php -text
genie/univers_statsv.php -text
geoip/GeoIP.dat -text
@ -31,6 +26,7 @@ javascript/treemap.js -text
javascript/version.tree.js -text
json/stats-tout.html -text
json/stats-v.html -text
/phpcs.xml.dist -text
/plugin.xml -text
/saturn.png -text
/stats-tout.html -text


+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
/.php_cs.cache
/phpcs.xml

+ 78
- 61
base/univers.php View File

@ -7,41 +7,42 @@
*/
if (!defined("_ECRIRE_INC_VERSION")) return;
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
function univers_declarer_tables_interfaces($interface){
function univers_declarer_tables_interfaces($interface) {
// 'spip_' dans l'index de $tables_principales
$interface['table_des_tables']['websites']='websites';
return $interface;
}
function univers_declarer_tables_principales($tables_principales){
function univers_declarer_tables_principales($tables_principales) {
$spip_websites = array(
"id_website" => "bigint(21) NOT NULL",
"url" => "varchar(255) default '' NOT NULL",
"titre" => "text DEFAULT '' NOT NULL",
"descriptif" => "text DEFAULT '' NOT NULL",
"ip" => "varchar(255) default '' NOT NULL",
"spip" => "varchar(255) default '' NOT NULL",
"server" => "varchar(255) default '' NOT NULL",
"php" => "varchar(255) default '' NOT NULL",
"gzip" => "varchar(3) default '' NOT NULL",
"length" => "bigint(21) NOT NULL",
"size" => "bigint(21) NOT NULL",
"plugins" => "bigint(21) default NULL",
"pays" => "char(3) default '' NOT NULL",
"date" => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
"statut" => "varchar(10) default 'prop' NOT NULL",
"retry" => "int(5) default 0 NOT NULL",
"status" => "varchar(10) default '' NOT NULL",
'id_website' => 'bigint(21) NOT NULL',
'url' => "varchar(255) default '' NOT NULL",
'titre' => "text DEFAULT '' NOT NULL",
'descriptif' => "text DEFAULT '' NOT NULL",
'ip' => "varchar(255) default '' NOT NULL",
'spip' => "varchar(255) default '' NOT NULL",
'server' => "varchar(255) default '' NOT NULL",
'php' => "varchar(255) default '' NOT NULL",
'gzip' => "varchar(3) default '' NOT NULL",
'length' => 'bigint(21) NOT NULL',
'size' => 'bigint(21) NOT NULL',
'plugins' => 'bigint(21) default NULL',
'pays' => "char(3) default '' NOT NULL",
'date' => "datetime DEFAULT '0000-00-00 00:00:00' NOT NULL",
'statut' => "varchar(10) default 'prop' NOT NULL",
'retry' => 'int(5) default 0 NOT NULL',
'status' => "varchar(10) default '' NOT NULL",
);
$spip_websites_key = array(
"PRIMARY KEY" => "id_website",
'PRIMARY KEY' => 'id_website',
);
$tables_principales['spip_websites'] = array(
@ -52,15 +53,15 @@ function univers_declarer_tables_principales($tables_principales){
}
function univers_declarer_tables_auxiliaires($tables_auxiliaires){
function univers_declarer_tables_auxiliaires($tables_auxiliaires) {
$spip_websites_plugins = array(
"id_website" => "bigint(21) NOT NULL",
"plugin" => "varchar(64) default '' NOT NULL",
"version" => "varchar(255) default '' NOT NULL",
'id_website' => 'bigint(21) NOT NULL',
'plugin' => "varchar(64) default '' NOT NULL",
'version' => "varchar(255) default '' NOT NULL",
);
$spip_websites_plugins_key = array(
"PRIMARY KEY" => "id_website, plugin",
'PRIMARY KEY' => 'id_website, plugin',
);
$tables_auxiliaires['spip_websites_plugins'] = array(
@ -70,66 +71,82 @@ function univers_declarer_tables_auxiliaires($tables_auxiliaires){
return $tables_auxiliaires;
}
function univers_upgrade($nom_meta_base_version,$version_cible){
function univers_upgrade($nom_meta_base_version, $version_cible) {
$current_version = 0.0;
if ( (!isset($GLOBALS['meta'][$nom_meta_base_version]) )
|| (($current_version = $GLOBALS['meta'][$nom_meta_base_version])!=$version_cible)){
if ((!isset($GLOBALS['meta'][$nom_meta_base_version]))
|| (($current_version = $GLOBALS['meta'][$nom_meta_base_version])!=$version_cible)) {
include_spip('base/abstract_sql');
if (version_compare($current_version,"0.1.2",'<')){
echo "Creation des tables";
if (version_compare($current_version, '0.1.2', '<')) {
echo 'Creation des tables';
include_spip('base/serial');
include_spip('base/auxiliaires');
include_spip('base/create');
creer_base();
ecrire_meta($nom_meta_base_version,$current_version=$version_cible,'non');
ecrire_meta($nom_meta_base_version, $current_version = $version_cible, 'non');
}
if (version_compare($current_version,"0.1.4",'<')){
if (version_compare($current_version, '0.1.4', '<')) {
include_spip('inc/univers');
$res = sql_select('referer','spip_referers',"referer LIKE '%spip.php%' AND referer NOT LIKE 'https://contrib.spip.net%' AND referer NOT LIKE '%localhost%'");
echo "Import depuis les referer %spip.php% : ".sql_count($res)." <br />";
while ($row = sql_fetch($res))
$res = sql_select(
'referer',
'spip_referers',
"referer LIKE '%spip.php%' AND referer NOT LIKE 'https://contrib.spip.net%'".
" AND referer NOT LIKE '%localhost%'"
);
echo 'Import depuis les referer %spip.php% : '.sql_count($res).' <br />';
while ($row = sql_fetch($res)) {
univers_proposer_site($row['referer']);
ecrire_meta($nom_meta_base_version,$current_version="0.1.4",'non');
}
ecrire_meta($nom_meta_base_version, $current_version = '0.1.4', 'non');
}
if (version_compare($current_version,"0.1.5",'<')){
$res = sql_select('referer','spip_referers',"referer LIKE '%/ecrire/%' AND referer NOT LIKE 'https://contrib.spip.net%' AND referer NOT LIKE '%localhost%'");
echo "Import depuis les referer %/ecrire/% : ".sql_count($res)." <br />";
while ($row = sql_fetch($res))
univers_proposer_site(preg_replace(',/ecrire/.*$,Uims','/spip.php',$row['referer']));
ecrire_meta($nom_meta_base_version,$current_version="0.1.5",'non');
if (version_compare($current_version, '0.1.5', '<')) {
$res = sql_select(
'referer',
'spip_referers',
"referer LIKE '%/ecrire/%' AND referer NOT LIKE 'https://contrib.spip.net%'".
" AND referer NOT LIKE '%localhost%'"
);
echo 'Import depuis les referer %/ecrire/% : '.sql_count($res).' <br />';
while ($row = sql_fetch($res)) {
univers_proposer_site(preg_replace(',/ecrire/.*$,Uims', '/spip.php', $row['referer']));
}
ecrire_meta($nom_meta_base_version, $current_version = '0.1.5', 'non');
}
if (version_compare($current_version,"0.1.8",'<')){
if (version_compare($current_version, '0.1.8', '<')) {
include_spip('base/serial');
include_spip('base/auxiliaires');
include_spip('base/create');
maj_tables(array('spip_websites','spip_websites_plugins'));
sql_updateq("spip_websites", array('plugins'=>0),"statut='publie'");
$res = sql_select("id_website, count(plugin) AS nb", "spip_websites_plugins", "", "id_website");
while($row = sql_fetch($res))
sql_updateq("spip_websites", array('plugins'=>$row['nb']),'id_website='.intval($row['id_website']));
ecrire_meta($nom_meta_base_version,$current_version="0.1.8",'non');
sql_updateq('spip_websites', array('plugins'=>0), "statut='publie'");
$res = sql_select('id_website, count(plugin) AS nb', 'spip_websites_plugins', '', 'id_website');
while ($row = sql_fetch($res)) {
sql_updateq('spip_websites', array('plugins'=>$row['nb']), 'id_website='.intval($row['id_website']));
}
ecrire_meta($nom_meta_base_version, $current_version = '0.1.8', 'non');
}
if (version_compare($current_version,"0.1.9",'<')){
if (version_compare($current_version, '0.1.9', '<')) {
include_spip('base/serial');
include_spip('base/auxiliaires');
include_spip('base/create');
// ajout du champ pays
maj_tables(array('spip_websites','spip_websites_plugins'));
include_spip('inc/univers_analyser');
$c = sql_countsel("spip_websites", "pays='' AND IP<>''");
$c = sql_countsel('spip_websites', "pays='' AND IP<>''");
echo "MAJ 0.1.9 : $c pays a renseigner<br />";
$res = sql_select("id_website, ip","spip_websites", "pays='' AND IP<>''");
while($row = sql_fetch($res)) {
sql_updateq("spip_websites",
array('pays'=>univers_geoip($row['ip'])),'id_website='.intval($row['id_website']));
$res = sql_select('id_website, ip', 'spip_websites', "pays='' AND IP<>''");
while ($row = sql_fetch($res)) {
sql_updateq(
'spip_websites',
array('pays'=>univers_geoip($row['ip'])),
'id_website='.intval($row['id_website'])
);
}
ecrire_meta($nom_meta_base_version,$current_version="0.1.9",'non');
ecrire_meta($nom_meta_base_version, $current_version = '0.1.9', 'non');
}
}
}
function univers_vider_tables($nom_meta_base_version) {
effacer_meta($nom_meta_base_version);
sql_drop_table("spip_websites_plugins");
sql_drop_table("spip_websites");
sql_drop_table('spip_websites_plugins');
sql_drop_table('spip_websites');
}

+ 14
- 18
exec/universparse.php View File

@ -1,33 +1,29 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function exec_universparse_dist(){
#$encore = univers_google_parse_one_step(true);
#univers_feed_watch(true);
#univers_boss_explore();
$url = "";
#include_spip('inc/univers');
#var_dump(univers_twitter_extraire_feed_urls("http://search.twitter.com/search.atom?q=spip.php"));
function exec_universparse_dist() {
$url = '';
include_spip('inc/univers_analyser');
if ($id = _request('id')) {
$res = sql_select("*", "spip_websites", "id_website=".intval($id)/*." AND statut='prop'"*/, "", "id_website","0,1");
$res = sql_select(
'*',
'spip_websites',
'id_website='.intval($id),
'',
'id_website',
'0,1'
);
while ($row = sql_fetch($res)) {
univers_analyser_un($row, true);
}
}
elseif($url = _request('url')){
} elseif ($url = _request('url')) {
var_dump($url);
var_dump(univers_analyser($url, true));
}
}

+ 0
- 16
genie/univers_boss.php View File

@ -1,16 +0,0 @@
<?php
/*
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_boss_dist($t) {
include_spip('inc/univers');
univers_boss_explore();
return 0;
}
?>

+ 34
- 12
genie/univers_check.php View File

@ -1,44 +1,66 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_check_dist($t) {
include_spip('inc/univers_analyser');
$il_y_a_une_heure = date('Y-m-d H:i:s',time()-3600);
$il_y_a_une_heure = date('Y-m-d H:i:s', time()-3600);
// 2 sites en attente de validation
$res = sql_select("*", "spip_websites", "statut='prop' AND (retry=0 OR date<".sql_quote($il_y_a_une_heure).")", "", "date,retry","0,2");
$res = sql_select(
'*',
'spip_websites',
"statut='prop' AND (retry=0 OR date<".sql_quote($il_y_a_une_heure).')',
'',
'date,retry',
'0,2'
);
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
$il_y_a_quatre_heure = date('Y-m-d H:i:s',time()-4*3600);
$il_y_a_quatre_heure = date('Y-m-d H:i:s', time()-4*3600);
// revisiter 5 sites deja vu, en commencant par les plus anciens
$res = sql_select("*", "spip_websites", "statut='publie' AND (retry=0 OR date<".sql_quote($il_y_a_quatre_heure).")", "", "date,retry","0,5");
$res = sql_select(
'*',
'spip_websites',
"statut='publie' AND (retry=0 OR date<".sql_quote($il_y_a_quatre_heure).')',
'',
'date,retry',
'0,5'
);
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
// revisiter un site publie, en retry de plus de 4 heures
$res = sql_select("*", "spip_websites", "statut='publie' AND (retry>0 AND date<".sql_quote($il_y_a_quatre_heure).")", "", "date,retry","0,1");
$res = sql_select(
'*',
'spip_websites',
"statut='publie' AND (retry>0 AND date<".sql_quote($il_y_a_quatre_heure).')',
'',
'date,retry',
'0,1'
);
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
// passer a la poubelle les sites proposes sans DNS et essayes au moins 5 fois
sql_updateq("spip_websites",array('statut'=>'poub'),"statut='prop' AND status='no-dns' AND retry>=5");
sql_updateq('spip_websites', array('statut'=>'poub'), "statut='prop' AND status='no-dns' AND retry>=5");
// passer a la poubelle les sites morts et essayes au moins 10 fois
// soit un propose pas vu vivant dans les 10 dernieres heures
// soit un publie (donc vu vivant un jour) pas vu vivant dans les 40 dernieres heures
sql_updateq("spip_websites",array('statut'=>'poub'),"statut IN ('prop','publie') AND status='dead' AND retry>=10");
sql_updateq(
'spip_websites',
array('statut'=>'poub'),
"statut IN ('prop','publie') AND status='dead' AND retry>=10"
);
return 0;
}
?>

+ 0
- 21
genie/univers_check_1.php View File

@ -1,21 +0,0 @@
<?php
/*
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_check_1_dist($t) {
include_spip('inc/univers_analyser');
// les sites en attente de validation
$res = sql_select("*", "spip_websites", "statut='prop' AND (retry=0 OR date<".sql_quote(date('Y-m-d H:i:s',time()-3600)).")", "", "date,retry","10,10");
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
return 0;
}
?>

+ 0
- 21
genie/univers_check_2.php View File

@ -1,21 +0,0 @@
<?php
/*
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_check_2_dist($t) {
include_spip('inc/univers_analyser');
// les sites en attente de validation
$res = sql_select("*", "spip_websites", "statut='prop' AND (retry=0 OR date<".sql_quote(date('Y-m-d H:i:s',time()-3600)).")", "", "date,retry","20,10");
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
return 0;
}
?>

+ 0
- 21
genie/univers_check_3.php View File

@ -1,21 +0,0 @@
<?php
/*
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_check_3_dist($t) {
include_spip('inc/univers_analyser');
// les sites en attente de validation
$res = sql_select("*", "spip_websites", "statut='prop' AND (retry=0 OR date<".sql_quote(date('Y-m-d H:i:s',time()-3600)).")", "", "date,retry","30,10");
while ($row = sql_fetch($res)) {
univers_analyser_un($row);
}
return 0;
}
?>

+ 3
- 3
genie/univers_feed.php View File

@ -1,14 +1,14 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_feed_dist($t) {
include_spip('inc/univers');
univers_feed_watch();
return 0;
}

+ 0
- 16
genie/univers_google.php View File

@ -1,16 +0,0 @@
<?php
/*
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_google_dist($t) {
include_spip('inc/univers');
univers_google_parse_one_step();
return 0;
}
?>

+ 4
- 4
genie/univers_referers.php View File

@ -1,14 +1,14 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_referers_dist($t) {
include_spip('inc/univers');
univers_rechercher_referers(date("Y-m-d",time()-24*3600));
univers_rechercher_referers(date('Y-m-d', time()-24*3600));
return 0;
}

+ 16
- 19
genie/univers_statsv.php View File

@ -1,41 +1,38 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function genie_univers_statsv_dist($t) {
include_spip('inc/univers');
$versions = array(
"3.3",
"3.2",
"3.1",
"3.0",
"2.1",
"2.0",
"1.9.3",
"1.9.2",
"1.9.1",
'3.3',
'3.2',
'3.1',
'3.0',
'2.1',
'2.0',
'1.9.3',
'1.9.2',
'1.9.1',
);
$stats = array("date" => date('Y-m-d H:i:s'));
$stats = array('date' => date('Y-m-d H:i:s'));
foreach ($versions as $version){
$n = sql_countsel("spip_websites","statut='publie' AND spip LIKE ".sql_quote("$version%"));
foreach ($versions as $version) {
$n = sql_countsel('spip_websites', "statut='publie' AND spip LIKE ".sql_quote("$version%"));
$stats[$version] = $n;
}
// jsonencodons
$stats = json_encode($stats);
$filename = _DIR_VAR.(defined('_UNIVERS_STATSV_FILE')?_UNIVERS_STATSV_FILE:"histostats.json.txt");
ecrire_fichier($filename,"$stats\n",false,false);
$filename = _DIR_VAR.(defined('_UNIVERS_STATSV_FILE')?_UNIVERS_STATSV_FILE:'histostats.json.txt');
ecrire_fichier($filename, "$stats\n", false, false);
return 0;
}
?>

+ 115
- 211
inc/univers.php View File

@ -1,47 +1,52 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
include_spip('inc/filtres');
include_spip('inc/distant');
include_spip('inc/meta');
function univers_proposer_site($url, $desc=""){
function univers_proposer_site($url, $desc = '') {
$parts = parse_url($url);
// pas d'IP fixe !
if (preg_match(";^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$;",$parts['host']))
if (preg_match(';^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$;', $parts['host'])) {
return false;
}
// pas de fausse url venant de feedburner ou google !
// on pourrait faire mieux en suivant la redirection pour
// attraper le vrai nom du site
if (preg_match(",(feeds\.feedburner\.com|feedproxy\.google\.com),i",$parts['host']))
if (preg_match(',(feeds\.feedburner\.com|feedproxy\.google\.com),i', $parts['host'])) {
return false;
}
#if (is_utf8($parts['host']))
# return false;
#$parts['path'] = preg_replace(",(IMG|local)/cache.+spip[.]php,","spip.php",$parts['path']);
$base = $parts['scheme'] . "://" . $parts['host'] . $parts['path'];
$base = $parts['scheme'] . '://' . $parts['host'] . $parts['path'];
$base = univers_nettoyer_url($base);
$base = preg_replace(",(spip[.]php3?).*$,i",'\\1',$base);
$base_short = preg_replace(",spip[.]php.*$,i",'',$base);
if ($id_website = sql_getfetsel('id_website', "spip_websites", "url=".sql_quote($base))
OR
($base_short!==$base AND $id_website = sql_getfetsel('id_website', "spip_websites", "url=".sql_quote($base_short))))
return $id_website;
$base = preg_replace(',(spip[.]php3?).*$,i', '\\1', $base);
$base_short = preg_replace(',spip[.]php.*$,i', '', $base);
if ($id_website = sql_getfetsel('id_website', 'spip_websites', 'url='.sql_quote($base)) or
($base_short!==$base and
$id_website = sql_getfetsel('id_website', 'spip_websites', 'url='.sql_quote($base_short))
)
) {
return $id_website;
}
$id_website = sql_insertq("spip_websites", array('url'=>$base,'descriptif'=>$desc,'date'=>date('Y-m-d H:i:s')));
$id_website = sql_insertq('spip_websites', array('url'=>$base,'descriptif'=>$desc,'date'=>date('Y-m-d H:i:s')));
// relire et verifier
$url = sql_getfetsel("url","spip_websites","id_website=".intval($id_website));
$url = sql_getfetsel('url', 'spip_websites', 'id_website='.intval($id_website));
if ($url !== $base) {
// il y a eu un caractere exotique dans l'url, on la vire
sql_delete('spip_websites',"id_website=".intval($id_website));
sql_delete('spip_websites', 'id_website='.intval($id_website));
return false;
}
@ -49,207 +54,122 @@ function univers_proposer_site($url, $desc=""){
}
// reparer les urls mal formees
function univers_nettoyer_url($url){
$url = preg_replace(",(IMG|local)/cache.+spip[.]php,","spip.php",$url);
$url = preg_replace(",(index|spip)[.]php/.+,i","spip.php",$url);
$url = preg_replace(",(index|spip|forum|article)[.]php3/.+,i","",$url);
$url = preg_replace(",/(plugins|ecrire|IMG|local|squelettes)/.+[.]php,i","",$url);
function univers_nettoyer_url($url) {
$url = preg_replace(',(IMG|local)/cache.+spip[.]php,', 'spip.php', $url);
$url = preg_replace(',(index|spip)[.]php/.+,i', 'spip.php', $url);
$url = preg_replace(',(index|spip|forum|article)[.]php3/.+,i', '', $url);
$url = preg_replace(',/(plugins|ecrire|IMG|local|squelettes)/.+[.]php,i', '', $url);
return $url;
}
function univers_nettoyer_urls(){
function univers_nettoyer_urls() {
// urls mal formees
$res = sql_select("id_website,url", "spip_websites",
"url REGEXP '(index|spip)[.]php/.+'"
$res = sql_select(
'id_website,url',
'spip_websites',
"url REGEXP '(index|spip)[.]php/.+'"
." OR url REGEXP '/(plugins|ecrire|IMG|local|squelettes)/.+[.]php$'"
);
while ($row = sql_fetch($res)){
);
while ($row = sql_fetch($res)) {
$url = univers_nettoyer_url($row['url']);
if ($url!=$row['url']){
spip_log("nettoyage ".$row['id_website'].":".$row['url']." => $url",'universclean');
sql_updateq("spip_websites", array('url'=>$url),"id_website=".intval($row['id_website']));
if ($url!=$row['url']) {
spip_log('nettoyage '.$row['id_website'].':'.$row['url']." => $url", 'universclean');
sql_updateq('spip_websites', array('url'=>$url), 'id_website='.intval($row['id_website']));
}
}
// urls refusees (feed google/feedburner)
sql_delete('spip_websites','url LIKE'.sql_quote('http://feeds.feedburner.com%'));
sql_delete('spip_websites','url LIKE'.sql_quote('http://feedproxy.google.com%'));
sql_delete('spip_websites', 'url LIKE'.sql_quote('http://feeds.feedburner.com%'));
sql_delete('spip_websites', 'url LIKE'.sql_quote('http://feedproxy.google.com%'));
// nettoyage des liens morts (suite a delete ci-dessus)
$res = sql_select('P.id_website','spip_websites_plugins AS P LEFT JOIN spip_websites AS W ON P.id_website = W.id_website','W.id_website IS NULL');
while ($row = sql_fetch($res)){
sql_delete('spip_websites_plugins','id_website='.intval($row['id_website']));
$res = sql_select(
'P.id_website',
'spip_websites_plugins AS P LEFT JOIN spip_websites AS W ON P.id_website = W.id_website',
'W.id_website IS NULL'
);
while ($row = sql_fetch($res)) {
sql_delete('spip_websites_plugins', 'id_website='.intval($row['id_website']));
}
}
function univers_rechercher_referers($date){
$res = sql_select('referer','spip_referers',"date=".sql_quote($date)." AND referer LIKE '%spip.php%' AND referer NOT LIKE 'https://contrib.spip.net%' AND referer NOT LIKE '%localhost%'");
spip_log("Import depuis les referer du $date : %spip.php% , ".sql_count($res),"universreferers");
function univers_rechercher_referers($date) {
$res = sql_select(
'referer',
'spip_referers',
'date='.
sql_quote($date).
" AND referer LIKE '%spip.php%' AND referer NOT LIKE 'https://contrib.spip.net%'".
" AND referer NOT LIKE '%localhost%'"
);
spip_log("Import depuis les referer du $date : %spip.php% , ".sql_count($res), 'universreferers');
while ($row = sql_fetch($res)) {
spip_log("Import referer : ".$row['referer'],"universreferers");
spip_log('Import referer : '.$row['referer'], 'universreferers');
univers_proposer_site($row['referer']);
}
$res = sql_select('referer','spip_referers',"date=".sql_quote($date)." AND referer LIKE '%/ecrire/%' AND referer NOT LIKE 'https://contrib.spip.net%' AND referer NOT LIKE '%localhost%'");
spip_log("Import depuis les referer du $date : %/ecrire/% , ".sql_count($res),"universreferers");
while ($row = sql_fetch($res)) {
spip_log("Import referer : ".$row['referer'],"universreferers");
univers_proposer_site(preg_replace(',/ecrire/.*$,Uims','/spip.php',$row['referer']));
}
}
# 21 dec 2012 : fin du monde , plus de yahoo boss
/*
function univers_boss_request($query, $args=array()){
$apiid = "vKArhavV34HzXT9wvczrzUX58tMbO_TDOyDZqoi6o243vTtNPSZXW0GOYuuP4NxqUA--";
$uri = "http://boss.yahooapis.com/ysearch/web/v1/$query?appid=$apiid";
$params = array_merge(array(
'format' => 'xml',
'start' => 0,
'count' => 50,
'lang' => 'fr',
'region' => 'fr',
'style' => 'raw',
),$args);
foreach($params as $k=>$v)
$uri = parametre_url($uri, $k, $v,'&');
include_spip('inc/distant');
$res = recuperer_page($uri);
return $res;
}
function univers_boss_explore($echo=false){
$explore = array(
0=>array('"spip.php"',array()),
1=>array('"spip.php?page=backend"',array()),
2=>array('"spip.php?page=plan"',array()),
3=>array('"spip.php?page=sommaire"',array()),
4=>array("Si votre message se réfère à un article publié sur le Web, ou à une page fournissant plus d'informations, vous pouvez indiquer ci-après le titre de la page et son adresse",array())
$res = sql_select(
'referer',
'spip_referers',
'date='.
sql_quote($date).
" AND referer LIKE '%/ecrire/%' AND referer NOT LIKE 'https://contrib.spip.net%'".
" AND referer NOT LIKE '%localhost%'"
);
$regions = array(
array('ar','es'),
array('at','de'),
array('au','en'),
array('br','pt'),
array('ca','en'),
array('ca','fr'),
array('ct','ca'),
array('cl','es'),
array('co','es'),
array('cz','cs'),
array('dk','da'),
array('fi','fi'),
array('fr','fr'),
array('de','de'),
array('hk','tzh'),
array('hu','hu'),
array('id','en'),
array('id','id'),
array('in','en'),
array('il','he'),
array('it','it'),
array('jp','jp'),
array('kr','kr'),
array('my','en'),
array('my','ms'),
array('mx','es'),
array('nl','nl'),
array('nz','en'),
array('no','no'),
array('pe','es'),
array('ph','tl'),
array('ph','en'),
array('ro','ro'),
array('ru','ru'),
array('sg','en'),
array('es','es'),
array('se','sv'),
array('ch','fr'),
array('ch','de'),
array('ch','it'),
array('th','th'),
array('tw','tzh'),
array('tr','tr'),
array('uk','en'),
array('us','en'),
array('us','es'),
array('ve','es'),
array('vn','vi'),
);
$start = rand(0,19)*50;
$region = $regions[rand(0,count($regions)-1)];
$ex = $explore[rand(0,3)];
spip_log("BOSS $ex[0]/$start/".implode(',',$region),'univers');
$res = univers_boss_request($ex[0],array_merge($ex[1],array('start'=>$start,'region'=>$region[0],'lang'=>$region[1])));
$links = extraire_balises($res,'url');
foreach($links as $link)
if (preg_match(",<url>(.*)</url>,Uims", $link,$reg)
AND preg_match(",http://[^?\"'#;:]*(spip|forum|article)[.]php3?,Uims", $reg[1]))
$urls[] = trim($reg[1]);
$urls = array_unique($urls);
foreach($urls as $url){
spip_log("$url",'univers');
univers_proposer_site($url);
spip_log("Import depuis les referer du $date : %/ecrire/% , ".sql_count($res), 'universreferers');
while ($row = sql_fetch($res)) {
spip_log('Import referer : '.$row['referer'], 'universreferers');
univers_proposer_site(preg_replace(',/ecrire/.*$,Uims', '/spip.php', $row['referer']));
}
}
*/
function univers_rechercher_sites_spip($req,$start=0,$max=10,$step=10,$var='start'){
function univers_rechercher_sites_spip($req, $start = 0, $max = 10, $step = 10, $var = 'start') {
$urls = array();
while ($start<$max){
while ($start<$max) {
$url = parametre_url($req, $var, $start, '&');
$page = recuperer_page($url);
$h3 = extraire_balises($page,'h3');
foreach($h3 as $h){
$a = extraire_balise($h,'a');
$href = extraire_attribut($a, "href");
if (preg_match(";^([a-z]{3,5})://;i",$href)
AND strpos($href,'inurl:')===FALSE
AND strpos($href,'google')===FALSE
AND strpos($href,'spip.php')!==FALSE){
$href = preg_replace(",spip[.]php?.*$,i", "spip.php", $href);
$h3 = extraire_balises($page, 'h3');
foreach ($h3 as $h) {
$a = extraire_balise($h, 'a');
$href = extraire_attribut($a, 'href');
if (preg_match(';^([a-z]{3,5})://;i', $href)
and strpos($href, 'inurl:')===false
and strpos($href, 'google')===false
and strpos($href, 'spip.php')!==false) {
$href = preg_replace(',spip[.]php?.*$,i', 'spip.php', $href);
$urls[$href] = textebrut($a);
}
}
$start+=$step;
#sleep(1);
}
return $urls;
}
function univers_twitter_extraire_feed_urls($url, $enlarge=true){
function univers_twitter_extraire_feed_urls($url, $enlarge = true) {
$long = array();
$urls = array();
$page = recuperer_page($url);
$page = str_replace("&lt;b&gt;","",$page);
$page = str_replace("&lt;/b&gt;","",$page);
$page = str_replace('&lt;b&gt;', '', $page);
$page = str_replace('&lt;/b&gt;', '', $page);
$titles = extraire_balises($page,"title");
$page = preg_replace(",</?title>,ims","\n",implode($titles));
$titles = extraire_balises($page, 'title');
$page = preg_replace(',</?title>,ims', "\n", implode($titles));
preg_match_all(",https?://[^?\"'#;:\s]*,ims", $page, $regs, PREG_SET_ORDER);
$urls = array_map('reset',$regs);
foreach($urls as $k=>$url) {
if (!preg_match(",https?://[^?\"'#;:]*spip[.]php3?,Uims", $url)){
$urls = array_map('reset', $regs);
foreach ($urls as $k => $url) {
if (!preg_match(",https?://[^?\"'#;:]*spip[.]php3?,Uims", $url)) {
// essayer de l'elargir
if (!isset($long[$url])){
#var_dump($url);
$long[$url] = recuperer_lapage($url,false,'GET',100000);
if (!isset($long[$url])) {
$long[$url] = recuperer_lapage($url, false, 'GET', 100000);
$long[$url] = (is_string($long[$url])?$long[$url]:false);
}
if ($long[$url]){
#var_dump("$url > ".$long[$url]);
if ($long[$url]) {
$urls[$k] = $url = $long[$url];
}
}
if (!preg_match(",https?://[^?\"'#;:]*spip[.]php3?,Uims", $url)){
if (!preg_match(",https?://[^?\"'#;:]*spip[.]php3?,Uims", $url)) {
unset($urls[$k]);
}
}
@ -257,76 +177,60 @@ function univers_twitter_extraire_feed_urls($url, $enlarge=true){
return $urls;
}
function univers_googlenews_extraire_feed_urls($url){
return univers_identica_extraire_feed_urls($url, false);
}
function univers_identica_extraire_feed_urls($url){
$urls = array();
$page = recuperer_page($url);
$page = str_replace("&lt;b&gt;","",$page);
$page = str_replace("&lt;/b&gt;","",$page);
preg_match_all(",http://[^?\"'#;:]*spip[.]php3?,Uims", $page, $regs, PREG_SET_ORDER);
$urls = array_map('reset',$regs);
$urls = array_unique($urls);
return $urls;
}
function univers_spipnet_extraire_feed_urls($url){
function univers_spipnet_extraire_feed_urls($url) {
$urls = array();
$page = recuperer_page($url);
$links = extraire_balises($page,'link');
foreach($links as $link)
if (preg_match(",<link>(.*)</link>,Uims", $link,$reg))
$links = extraire_balises($page, 'link');
foreach ($links as $link) {
if (preg_match(',<link>(.*)</link>,Uims', $link, $reg)) {
$urls[] = trim($reg[1]);
}
}
$urls = array_unique($urls);
return $urls;
}
function univers_delisarka_extraire_feed_urls($url){
return univers_spipnet_extraire_feed_urls($url);
}
function univers_feed_watch($echo=false){
function univers_feed_watch($echo = false) {
$explore = array(
//MORT 'twitter'=>"http://search.twitter.com/search.atom?q=spip.php",
'twitter' => 'https://blog.spip.net/?page=backend-twitter-spip',
'spipnet'=>"https://www.spip.net/?page=backend-sites-sous-spip&id_article=884",
//MORT 'googlenews'=>"http://news.google.fr/news?pz=1&cf=all&ned=fr&hl=fr&q=%22spip.php%22&cf=all&output=rss",
//MORT 'delisarka'=>'http://feeds.delicious.com/v2/rss/sarkaspip?count=10',
//MORT 'identica'=>"http://identi.ca/search/notice/rss?q=spip.php",
'spipnet'=>'https://www.spip.net/?page=backend-sites-sous-spip&id_article=884',
);
$feed = 0;
if (isset($GLOBALS['meta']['univers_feedwatch']))
if (isset($GLOBALS['meta']['univers_feedwatch'])) {
$feed = $GLOBALS['meta']['univers_feedwatch'];
}
$i = 0;
while ($i++<$feed)
list($type,$url) = each($explore);
while ($i++<$feed) {
list($type, $url) = each($explore);
}
list($type,$url) = each($explore);
if (function_exists($f="univers_$type"."_extraire_feed_urls")) {
spip_log($s="Analyse Feed $url",'univers');
if ($echo)
list($type, $url) = each($explore);
if (function_exists($f = "univers_$type".'_extraire_feed_urls')) {
spip_log($s = "Analyse Feed $url", 'univers');
if ($echo) {
echo "$s<br />";
}
$liste = $f($url);
foreach($liste as $url){
spip_log($s="$url",'univers');
if ($echo)
foreach ($liste as $url) {
spip_log($s = "$url", 'univers');
if ($echo) {
echo "$s<br />";
}
univers_proposer_site($url);
}
}
$feed++;
if ($feed>=count($explore))
if ($feed>=count($explore)) {
$feed = 0;
}
ecrire_meta('univers_feedwatch', $feed);
// un coup de netoyage sur les urls mal formees
univers_nettoyer_urls();
}
?>

+ 104
- 85
inc/univers_analyser.php View File

@ -1,21 +1,26 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
// User agent used to load the page
@define('_INC_DISTANT_USER_AGENT', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9');
@define('_INC_DISTANT_VERSION_HTTP', "HTTP/1.0");
@define(
'_INC_DISTANT_USER_AGENT',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9'
);
@define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0');
if (!defined('_ECRIRE_INC_VERSION')) {
return;
}
include_spip('inc/filtres');
include_spip('inc/distant');
include_spip('inc/meta');
if (!defined("_ECRIRE_INC_VERSION")) return;
/**
* Get the complete page.
* Should be sub.something.tld/spip.php
@ -27,42 +32,37 @@ if (!defined("_ECRIRE_INC_VERSION")) return;
* @param string $cookie
*
*/
function univers_recuperer_lapage($url,$cookie="") {
$ref = $GLOBALS['meta']["adresse_site"];
function univers_recuperer_lapage($url, $cookie = '') {
$ref = $GLOBALS['meta']['adresse_site'];
// let's say we're coming from google, after all...
$GLOBALS['meta']["adresse_site"] = "http://www.google.fr";
$datas = ""
# ."Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
# ."Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
# ."Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
# ."Keep-Alive: 300\r\n"
# ."Connection: keep-alive\r\n"
$GLOBALS['meta']['adresse_site'] = 'http://www.google.fr';
$datas = ''
."Cookie: $cookie\r\n"
# ."If-Modified-Since: Sat, 08 May 2010 20:49:37 GMT\r\n"
# ."Cache-Control: max-age=0\r\n"
."\r\n"
;
$site = $url;
$max_redir = 10;
while ($site AND is_string($site) AND $max_redir--) {
while ($site and is_string($site) and $max_redir--) {
$url = $site;
$site = recuperer_lapage($url,false,'GET',1048576,$datas);
$site = recuperer_lapage($url, false, 'GET', 1048576, $datas);
}
$GLOBALS['meta']["adresse_site"] = $ref;
if (!$site)
$GLOBALS['meta']['adresse_site'] = $ref;
if (!$site) {
return $site;
if (is_string($site) AND !$max_redir)
}
if (is_string($site) and !$max_redir) {
return false;
}
list($header, $page) = $site;
// if a cookie set, accept it an retry with it
if (preg_match(",Set-Cookie: (.*)(;.*)?$,Uims",$header,$r)) {
if (preg_match(',Set-Cookie: (.*)(;.*)?$,Uims', $header, $r)) {
//ne pas relancer si le cookie est déjà présent
if (strpos($cookie,$r[1])===FALSE ) {
$cookie .= $r[1] . ";";
spip_log("Cookie : $cookie on repart pour un tour ", "univers_check");
if (strpos($cookie, $r[1])===false) {
$cookie .= $r[1] . ';';
spip_log("Cookie : $cookie on repart pour un tour ", 'univers_check');
return univers_recuperer_lapage($url, $cookie);
}
}
@ -85,7 +85,7 @@ function univers_getaddrbyhost($host, $timeout = 3) {
if (is_callable('shell_exec') && false === stripos(ini_get('disable_functions'), 'shell_exec')) {
$query = `nslookup -timeout=$timeout -retry=1 $host`;
if(preg_match('/\nAddress: (.*)\n/', $query, $matches)) {
if (preg_match('/\nAddress: (.*)\n/', $query, $matches)) {
return trim($matches[1]);
}
}
@ -100,14 +100,15 @@ function univers_getaddrbyhost($host, $timeout = 3) {
* @param bool $debug
* @return boolean
*/
function univers_analyser($url, $debug=false) {
function univers_analyser($url, $debug = false) {
$res = array();
spip_log("analyse version : $url ","univers_check");
spip_log("analyse version : $url ", 'univers_check');
$path = parse_url($url);
$ip = univers_getaddrbyhost($path['host']);
if (!$ip OR $ip==$path['host'])
if (!$ip or $ip==$path['host']) {
return false; // pas d'ip, pas de site, rien a faire
}
$res['ip'] = $ip;
@ -119,7 +120,9 @@ function univers_analyser($url, $debug=false) {
}
list($header, $page) = $site;
if ($debug) var_dump($header);
if ($debug) {
var_dump($header);
}
// get some generic informations (server, php, gzip, length)
if (preg_match(',Server: (.*)$,m', $header, $r)) {
@ -138,81 +141,88 @@ function univers_analyser($url, $debug=false) {
// check if the header says "Hey, i'm made with SPIP"
if (preg_match($regexp = ',Composed-By: (.*)( @ www.spip.net)( ?\+ ?(.*))?$,m', $header, $r)) {
// essayer de choper local/config.txt si il est la car plus complet si le header semble coupe
if (substr($header,-1)!==")"){
$url_config = suivre_lien($url,"local/config.txt");
if (substr($header, -1)!==')') {
$url_config = suivre_lien($url, 'local/config.txt');
$config = univers_recuperer_lapage($url_config);
if (!$config) {
$url_mutu = str_replace('ww2.', '', str_replace('www.', '', $path['host']));
$url_config = suivre_lien($url,"sites/$url_mutu/local/config.txt");
$url_config = suivre_lien($url, "sites/$url_mutu/local/config.txt");
$config = univers_recuperer_lapage($url_config);
}
if ($config AND preg_match($regexp, $config[1], $rc))
if ($config and preg_match($regexp, $config[1], $rc)) {
$r = $rc;
}
}
$res['spip'] = trim(preg_replace(',^[^0-9]*,','',$r[1]));
if (!$res['spip'])
$res['spip'] = trim(preg_replace(',^[^0-9]*,', '', $r[1]));
if (!$res['spip']) {
$res['spip'] = '?';
}
$res['plugins'] = array();
if ($p = array_filter(explode(',', $r[4]))) {
foreach ($p as $plugin) {
$plugin = trim($plugin);
$res['plugins'][preg_replace(',[(].*,','', $plugin)] = $plugin;
$res['plugins'][preg_replace(',[(].*,', '', $plugin)] = $plugin;
}
}
}
// else, find another clue
// if 'spip' is in the html, there are some chance that it is a SPIP site
if (!isset($res['spip']))
if (preg_match(',spip,i', $page))
if (!isset($res['spip'])) {
if (preg_match(',spip,i', $page)) {
$res['spip'] = '';
}
}
// if maybe but not sure, try to get the login page
// it should have some information that says "SPIP"
if (isset($res['spip']) AND (!$res['spip'] OR $res['spip']=='?')){
if (isset($res['spip']) and (!$res['spip'] or $res['spip']=='?')) {
// recuperer la page de login
$login = preg_replace(",spip[.]php.*$,","",$url)."ecrire/";
if ($login = univers_recuperer_lapage($login)){
$login = preg_replace(',spip[.]php.*$,', '', $url).'ecrire/';
if ($login = univers_recuperer_lapage($login)) {
list(, $login) = $login;
if (preg_match(',<meta name=[\'"]generator["\'][^>]*>,Uims',$login,$r)
AND $v = extraire_attribut($r[0], 'content')
AND preg_match(",SPIP ([^\[]+),",$v,$r))
if (preg_match(',<meta name=[\'"]generator["\'][^>]*>,Uims', $login, $r)
and $v = extraire_attribut($r[0], 'content')
and preg_match(',SPIP ([^\[]+),', $v, $r)) {
$res['spip'] = trim($r[1]);
}
}
}
// if we did'nt found login page, or there whas no information
// try to get the htaccess.txt delivered with SPIP,
// it has some extra informations
if (isset($res['spip']) AND (!$res['spip'] OR $res['spip']=='?')){
if (isset($res['spip']) and (!$res['spip'] or $res['spip']=='?')) {
// tenter de recup le htaccess.txt qui contient un numero de version
$ht = preg_replace(",spip[.]php.*$,","",$url)."htaccess.txt";
$ht = preg_replace(',spip[.]php.*$,', '', $url).'htaccess.txt';
if ($ht = univers_recuperer_lapage($ht)) {
list(, $htpage) = $ht;
if (preg_match(",SPIP v\s*([0-9.]+),",$htpage,$r))
if (preg_match(',SPIP v\s*([0-9.]+),', $htpage, $r)) {
$res['spip'] = $r[1];
}
}
// if we did'nt found a confirmation and there was only 'spip' in the html
// maybe it's an old spip site, but whe mark it apart as it is suspect
if (!$res['spip'])
if (!$res['spip']) {
$res['spip'] = '<1.8?';
}
}
// if it is a 404, that was a bad adress
if (count($res)==1 AND preg_match(',404 ,', $header)){
if (count($res)==1 and preg_match(',404 ,', $header)) {
$res['response'] = '404';
}
else {
} else {
// else record the page size and so on
$res['size'] = strlen($page);
$res['response'] = true;
if (preg_match(',<title>(.*)</title>,Uims', $page, $r))
if (preg_match(',<title>(.*)</title>,Uims', $page, $r)) {
$res['title'] = $r[1];
if (preg_match(',<meta name=[\'"]description["\'][^>]*>,Uims',$page,$r))
}
if (preg_match(',<meta name=[\'"]description["\'][^>]*>,Uims', $page, $r)) {
$res['description'] = extraire_attribut($r[0], 'content');
}
}
return $res;
}
/**
@ -221,29 +231,35 @@ function univers_analyser($url, $debug=false) {
* @param array $row
* @param bool $debug
*/
function univers_analyser_un($row,$debug = false){
if ($debug) var_dump($row);
function univers_analyser_un($row, $debug = false) {
if ($debug) {
var_dump($row);
}
$id = $row['id_website'];
$url = $row['url'];
// incrementer le retry et la date avant tout pour ne pas tourner en rond
// sur ce site si il timeout
sql_updateq("spip_websites", array('retry'=>$row['retry']+1,'date'=>date('Y-m-d H:i:s'),'status'=>'timeout?'), "id_website=".intval($id));
sql_updateq(
'spip_websites',
array('retry'=>$row['retry']+1,'date'=>date('Y-m-d H:i:s'),'status'=>'timeout?'),
'id_website='.intval($id)
);
$res = univers_analyser($url, $debug);
if ($debug) var_dump($res);
if ($debug) {
var_dump($res);
}
$set = array();
if ($res===false) {
$set['retry'] = ++$row['retry'];
$set['status'] = 'no-dns';
}
elseif ($res['response']===false OR $res['response']==='404'){
} elseif ($res['response']===false or $res['response']==='404') {
$set['ip'] = $res['ip'];
$set['retry'] = ++$row['retry'];
$set['status'] = ($res['response']?$res['response']:'dead');
}
elseif ($res['response']===true) {
} elseif ($res['response']===true) {
$set['ip'] = $res['ip'];
$set['server'] = !empty($res['server'])?$res['server']:'';
$set['php'] = !empty($res['php'])?$res['php']:'';
@ -251,46 +267,49 @@ function univers_analyser_un($row,$debug = false){
$set['length'] = !empty($res['length'])?$res['length']:0;
$set['size'] = !empty($res['size'])?$res['size']:0;
if (isset($res['spip'])){
if (isset($res['spip'])) {
$set['pays'] = univers_geoip($set['ip']);
// c'estun SPIP !
$set['spip'] = $res['spip'];
$set['statut'] = 'publie';
if ($res['title'])
if ($res['title']) {
$set['titre'] = $res['title'];
if ($res['description'])
}
if ($res['description']) {
$set['descriptif'] = $res['description'];
}
$set['plugins'] = count($res['plugins']);
// mettre a jour les plugins
sql_delete('spip_websites_plugins',"id_website=".intval($id));
if (is_array($res['plugins'])) {
foreach($res['plugins'] as $p=>$v) {
sql_delete('spip_websites_plugins', 'id_website='.intval($id));
if (is_array($res['plugins'])) {
foreach ($res['plugins'] as $p => $v) {
sql_insertq('spip_websites_plugins', array('id_website'=>$id,'plugin'=>$p,'version'=>$v));
}
}
if ($debug) var_dump(univers_geoip($set['ip']));
}
else {
if ($debug) {
var_dump(univers_geoip($set['ip']));
}
} else {
// c'en est pas un !
$set['statut'] = 'refuse';
}
$set['status'] = '';
$set['retry'] = 0;
}
else {
} else {
// ???
$set['retry'] = ++$row['retry'];
$set['status'] = $res['response'];
}
$set['date'] = date('Y-m-d H:i:s');
if ($debug) var_dump($set);
sql_updateq("spip_websites", $set, "id_website=".intval($id));
if ($debug) {
var_dump($set);
}
sql_updateq('spip_websites', $set, 'id_website='.intval($id));
}
/**
* Find state information from IP adress with GeoIP tool
*
@ -298,17 +317,17 @@ function univers_analyser_un($row,$debug = false){
* @param string $ip
* @return string
*/
function univers_geoip($ip=null){
function univers_geoip($ip = null) {
static $gi = null;
if (is_null($ip)){
include_spip("geoip/geoip");
if (is_null($ip)) {
include_spip('geoip/geoip');
geoip_close($gi);
return;
}
if (is_null($gi)){
include_spip("geoip/geoip");
$gi = geoip_open(find_in_path("geoip/GeoIP.dat"),GEOIP_STANDARD);
if (is_null($gi)) {
include_spip('geoip/geoip');
$gi = geoip_open(find_in_path('geoip/GeoIP.dat'), GEOIP_STANDARD);
}
return geoip_country_code_by_addr($gi,$ip);
return geoip_country_code_by_addr($gi, $ip);
}

+ 50
- 0
phpcs.xml.dist View File

@ -0,0 +1,50 @@
<?xml version="1.0"?>
<ruleset name="SPIP">
<description>Coding rules for SPIP</description>
<file>./</file>
<exclude-pattern>geoip/*</exclude-pattern>
<exclude-pattern>javascript/*</exclude-pattern>
<exclude-pattern>css/*</exclude-pattern>
<!-- Appliquer PSR-2 moins nos exceptions -->
<rule ref="PSR2" >
<!-- Désactiver la vérification sur les noms de classes/fonctions -->
<exclude name="Squiz.Classes.ValidClassName" />
<!-- Désactiver la vérification sur l'indentation -->
<exclude name="Generic.WhiteSpace.ScopeIndent" />
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
<!-- Désactiver la vérification sur les accolades -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
</rule>
<!-- Tabulations pour l'indentation -->
<arg name="tab-width" value="4"/>
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="true"/>
</properties>
</rule>
<!-- Accolades -->
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie"/>
<rule ref="Generic.ControlStructures.InlineControlStructure" />
<rule ref="Squiz.ControlStructures.ControlSignature" />
<rule ref="Squiz.ControlStructures.ControlSignature.NewlineAfterOpenBrace">
<severity>0</severity>
</rule>
<!-- Guillemets doubles -->
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
<severity>0</severity>
</rule>
<!-- Constantes en majuscules -->
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
</ruleset>

+ 0
- 16
stats-tout.html View File

@ -86,22 +86,6 @@
</table>
</B_plugins>
<!--
<B_pluginsv>
<h3>Plugins, versionn&#233;s</h3>
<table>
<thead>
<tr><th>Version de plugin</th><th>Nombre de sites</th></tr>
</thead>
<tbody>
<BOUCLE_pluginsv(websites_plugins){fusion version}{!par compte_version}{compte version}>
<tr><td>#VERSION</td><td>#COMPTE{version}</td></tr>
</BOUCLE_pluginsv>
</tbody>
</table>
</B_pluginsv>
-->
<B_pays>
<h3>Pays</h3>
<table>


+ 0
- 16
stats-v.html View File

@ -48,22 +48,6 @@
</table>
</B_plugins>
<!--
<B_pluginsv>
<h3>Plugins, versionn&#233;s</h3>
<table>
<thead>
<tr><th>Version de plugin</th><th>Nombre de sites</th></tr>
</thead>
<tbody>
<BOUCLE_pluginsv(websites_plugins websites){websites.spip like #GET{likev}}{fusion version}{!par compte_version}{compte version}>
<tr><td>#VERSION</td><td>#COMPTE{version}</td></tr>
</BOUCLE_pluginsv>
</tbody>
</table>
</B_pluginsv>
-->
<B_pays>
<h3>Pays</h3>
<table>


+ 11
- 11
univers_pipelines.php View File

@ -1,23 +1,23 @@
<?php
/*
/**
* Plugin Univers SPIP
* (c) 2010 Cedric
* Distribue sous licence GPL
*
*/
function univers_taches_generales_cron($taches_generales){
/**
* Taches periodiques de verification des sites en SPIP.
*
* @param array $taches_generales Les taches generales
*
* @return array Les nouvelles taches generales
*/
function univers_taches_generales_cron(array $taches_generales) {
$taches_generales['univers_feed'] = 240;
#$taches_generales['univers_google'] = 77;
$taches_generales['univers_referers'] = 12*3600;
$taches_generales['univers_statsv'] = 3*24*3600;
# 21 dec 2012 : fin du monde , plus de yahoo boss
#$taches_generales['univers_boss'] = 173;
$taches_generales['univers_check'] = 97;
#$taches_generales['univers_check_1'] = 41;
#$taches_generales['univers_check_2'] = 37;
#$taches_generales['univers_check_3'] = 31;
return $taches_generales;
}

Loading…
Cancel
Save