Last active
December 18, 2015 21:38
-
-
Save Cerdic/5848618 to your computer and use it in GitHub Desktop.
Permet d'activer des plugins d'un site SPIP depuis la ligne de commande.
Lancer le script depuis la racine du site ou depuis ecrire/ ou plugins/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php | |
<?php | |
$activer = $argv; | |
array_shift($activer); | |
if (!is_dir('ecrire/') AND is_dir('../ecrire/')) chdir('../'); | |
chdir('ecrire/'); | |
if (!defined('_DIR_RESTREINT_ABS')) define('_DIR_RESTREINT_ABS', ''); | |
include_once _DIR_RESTREINT_ABS.'inc_version.php'; | |
$plugins_actifs = unserialize($GLOBALS['meta']['plugin']); | |
#var_dump(array_keys($plugins_actifs)); | |
echo "Plugins actifs : \n".implode(", ",array_map('strtolower',array_keys($plugins_actifs))); | |
echo "\n"; | |
echo "\n"; | |
if (!count($activer)){ | |
echo "Indiquez la liste des plugins a activer par leur prefixe. Par exemple : | |
site-active-plugin.php mailshot newsletters | |
Vous pouvez aussi indiquer l'url d'un site distant en argument pour activer tous les mÍmes plugins. Par exemple : | |
site-active-plugin.php http://blog.nursit.net | |
"; | |
} | |
else { | |
// si on donne une url de site en argument : | |
// recuperer le header de ce site et activer tous les memes plugins | |
if (preg_match(',^https?://,',reset($activer))){ | |
$url = reset($activer); | |
$head = array(); | |
exec("curl -I -L --silent $url",$head); | |
$head = implode("\n",$head); | |
if (preg_match(",^Composed-By:(.*)\n,Uims",$head,$m)){ | |
// virer les numeros de version | |
$liste = preg_replace(",\([^)]+\),","",$m[1]); | |
$liste = explode(",",$liste); | |
array_shift($liste); | |
$activer = $liste; | |
echo "Activer les memes plugins que sur $url : \n".implode(", ",$activer)."\n\n"; | |
} | |
else { | |
echo "Composed-By non trouve dans le head de $url : \n$head\n"; | |
die(); | |
} | |
} | |
$activer = array_map('strtolower',$activer); | |
// enlever les plugins deja actifs (donc y compris les extensions) | |
foreach($activer as $k=>$prefixe){ | |
$prefixeup = strtoupper($prefixe); | |
if (isset($plugins_actifs[$prefixeup])){ | |
echo "Plugin $prefixe deja actif\n"; | |
unset($activer[$k]); | |
} | |
} | |
// chercher dans les plugins dispo | |
include_spip('inc/plugin'); | |
$plugins = liste_plugin_files(); | |
$get_infos = charger_fonction('get_infos','plugins'); | |
$dirs_add = array(); | |
foreach($plugins as $dir){ | |
$infos = $get_infos($dir); | |
$prefix = strtolower($infos['prefix']); | |
if (in_array($prefix,$activer)){ | |
$dirs_add[] = $dir; | |
echo "Activer plugin ".$prefix." (repertoire $dir)\n"; | |
$activer = array_diff($activer, array($prefix)); | |
if (!count($activer)) | |
break; | |
} | |
} | |
if (count($activer)){ | |
echo "\nImpossible de trouver les plugins : ".implode(", ",$activer)."\n"; | |
} | |
if (count($dirs_add)){ | |
ecrire_plugin_actifs($dirs_add,false,'ajoute'); | |
$plugins_actifs = unserialize($GLOBALS['meta']['plugin']); | |
echo "\nPlugins actifs : \n".implode(", ",array_map('strtolower',array_keys($plugins_actifs))); | |
} | |
} | |
echo "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment