Exemplo n.º 1
0
/**
 * Analyser un arbre xml et extraire les infos concernant les boutons et onglets
 *
 * @param <type> $arbre
 * @return <type> 
 */
function plugins_extraire_boutons_dist($arbre)
{
    $ret = array('bouton' => array(), 'onglet' => array());
    // recuperer les boutons et onglets si necessaire
    spip_xml_match_nodes(",^(bouton|onglet)\\s,", $arbre, $les_boutons);
    if (is_array($les_boutons) && count($les_boutons)) {
        $ret['bouton'] = array();
        $ret['onglet'] = array();
        foreach ($les_boutons as $bouton => $val) {
            $bouton = spip_xml_decompose_tag($bouton);
            $type = reset($bouton);
            $bouton = end($bouton);
            if (isset($bouton['id'])) {
                $id = $bouton['id'];
                $val = reset($val);
                if (is_array($val)) {
                    $ret[$type][$id]['parent'] = isset($bouton['parent']) ? $bouton['parent'] : '';
                    $ret[$type][$id]['position'] = isset($bouton['position']) ? $bouton['position'] : '';
                    $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : '';
                    $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : '';
                    $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : '';
                    $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : '';
                }
            }
        }
    }
    return $ret;
}
Exemplo n.º 2
0
function exec_cs_boite_rss_dist() {
	cs_minipres();
	// Constantes distantes
	include_spip('cout_define');
	if(defined('_CS_PAS_DE_DISTANT')) { ajax_retour(_T('couteauprive:version_distante_off')); return; }
	$p = '';
	// on cherche le flux rss toutes les _CS_RSS_UPDATE minutes
	$force = _request('force')=='oui';
	if(!$force) {
		$lastmodified = @file_exists(_CS_TMP_RSS)?@filemtime(_CS_TMP_RSS):0;
		if(time()-$lastmodified < _CS_RSS_UPDATE) lire_fichier(_CS_TMP_RSS, $p);
	}
	if(strlen($p)) { ajax_retour($p); return; }
	include_spip('inc/filtres');
	include_spip('action/editer_site');
	include_spip('inc/xml');
	$r = spip_xml_load(_CS_RSS_SOURCE);
	if(function_exists('spip_xml_match_nodes')) $c = spip_xml_match_nodes(',^item$,', $r, $r2);
	else {
		$r2 = !is_array($r)?array():array_shift(array_shift(array_shift(array_shift($r))));
		$c = count($r2);
	}
	if($c) {
		$r3 = &$r2['item'];
		$c = count($r3); $p='';
		for($i=0; $i<min($c, _CS_RSS_COUNT); $i++) {
		 $l = $r3[$i]['link'][0];
		 $d = affdate_court(date('Y-m-d', strtotime($r3[$i]['pubDate'][0])));
		 $t = str_replace('&amp;', '&', htmlentities($r3[$i]['title'][0], ENT_NOQUOTES, "UTF-8"));
		 $t = preg_replace(',\s*&#8364;(&brvbar;)?,', '&nbsp;(&hellip;)', $t);
		 $t = preg_replace(',^(.*?):,', "&bull; <a href='$l' class='spip_out' target='_cout'>$1</a> <i>($d)</i><br/>", $t);
			 $p .= "<li style='padding-top:0.6em;'>$t</li>";
		}
	} else {
		// pour cs_lien()
		include_spip('cout_fonctions');
		$p = '<span style="color: red;">'._T('couteauprive:erreur:probleme', array('pb'=>cs_lien(_CS_RSS_SOURCE,_T('couteauprive:erreur:distant')))).'</span>';
	}
	$du = affdate_heure(date('Y-m-d H:i:s',time()));
	$p = '<ul style="list-style-type:none; padding:0; margin:0; ">'.$p
		.'</ul><p class="spip_xx-small" style="border-top:solid gray thin;"><b>'
		._T('couteauprive:rss_edition')."</b><br/>$du</p>"
		.'<p style="text-align:right"><a href="'
		.generer_url_ecrire('admin_couteau_suisse','var_mode=calcul', true).'" onclick="'
		."javascipt:jQuery('div.cs_boite_rss').children().css('opacity', 0.5).parent().load('".generer_url_ecrire('cs_boite_rss', 'force=oui', true).'\');return false;">'
		._T('couteauprive:rss_actualiser').'</a> | <a href="'
		._CS_RSS_SOURCE.'">'
		._T('couteauprive:rss_source').'</a></p>';
	if($c) ecrire_fichier(_CS_TMP_RSS, $p);
	
	ajax_retour($p);
}
Exemplo n.º 3
0
/**
 * Extraire les infos de pipeline
 *
 * @param array $arbre
 */
function plugins_extraire_pipelines_dist(&$arbre)
{
    $pipeline = array();
    if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) {
        foreach ($pipes as $tag => $p) {
            if (!is_array($p[0])) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                $pipeline[] = $att;
            } else {
                foreach ($p as $pipe) {
                    $att = array();
                    if (is_array($pipe)) {
                        foreach ($pipe as $k => $t) {
                            $att[$k] = trim(end($t));
                        }
                    }
                    $pipeline[] = $att;
                }
            }
        }
        unset($arbre[$tag]);
    }
    return $pipeline;
}
Exemplo n.º 4
0
/**
 * Charger les informations contenues dans le xml d'une composition
 *
 * @param string $nom
 * @param string $info
 * @return array|string
 */
function compositions_charger_infos($nom,$info=""){
		// on peut appeller avec le nom du squelette
		$nom = preg_replace(',[.]html$,i','',$nom).".xml";
		include_spip('inc/xml');
		$composition = array();
		if ($xml = spip_xml_load($nom,false)){
			if (count($xml['composition'])){
				$xml = reset($xml['composition']);
				$composition['nom'] = _T_ou_typo(spip_xml_aplatit($xml['nom']));
				$composition['description'] = isset($xml['description'])?_T_ou_typo(spip_xml_aplatit($xml['description'])):'';
				if (isset($xml['icon'])) {
					$icon = chemin_image(reset($xml['icon']));
					if (!$icon) {
						$icon = find_in_path(reset($xml['icon']));
					}
				} else {
					$icon = '';
				}
				$composition['image_exemple'] = isset($xml['image_exemple']) ? find_in_path(reset($xml['image_exemple'])) : '';
				$composition['icon'] = $icon;
				$composition['class'] = isset($xml['class']) ? trim(reset($xml['class'])) : '';
				$composition['configuration'] = isset($xml['configuration']) ? spip_xml_aplatit($xml['configuration']) : '';
				$composition['branche'] = array();
				if (spip_xml_match_nodes(',^branche,', $xml, $branches)){
					foreach (array_keys($branches) as $branche){
						list($balise, $attributs) = spip_xml_decompose_tag($branche);
						$composition['branche'][$attributs['type']] = $attributs['composition'];
					}
				}
			}
		}
		if (!$info)
			return $composition;
		else 
			return isset($composition[$info])?$composition[$info]:"";
}
Exemplo n.º 5
0
function xml2tab_infos($xml, $code_meteo)
{
    $tableau = array();
    $regexp = 'loc id=\\"' . $code_meteo . '\\"';
    $n = spip_xml_match_nodes(",^{$regexp},", $xml, $infos);
    if ($n == 1) {
        $infos = reset($infos['loc id="' . $code_meteo . '"']);
        // recuperer la date de debut des conditions
        $tableau['code_meteo'] = $code_meteo;
        $tableau['ville'] = $infos['dnam'][0];
        $tableau['longitude'] = floatval($infos['lon'][0]);
        $tableau['latitude'] = floatval($infos['lat'][0]);
        $tableau['zone'] = intval($infos['zone'][0]);
    }
    return $tableau;
}
function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS)
{
    static $etats = array('dev', 'experimental', 'test', 'stable');
    $matches = array();
    $silence = false;
    $p = null;
    // chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
    if ($n = spip_xml_match_nodes(",^plugin(\\s|\$),", $arbre, $matches)) {
        // version de SPIP
        $vspip = $GLOBALS['spip_version_branche'];
        foreach ($matches as $tag => $sous) {
            list($tagname, $atts) = spip_xml_decompose_tag($tag);
            if ($tagname == 'plugin' and is_array($sous)) {
                // On rajoute la condition sur $n :
                // -- en effet si $n==1 on a pas plus a choisir la balise que l'on ait
                //    un attribut spip ou pas. Cela permet de traiter tous les cas mono-balise
                //    de la meme facon.
                if (!isset($atts['spip']) or $n == 1 or plugin_version_compatible($atts['spip'], $vspip, 'spip')) {
                    // on prend la derniere declaration avec ce nom
                    $p = end($sous);
                    $compat_spip = isset($atts['spip']) ? $atts['spip'] : '';
                }
            }
        }
    }
    if (is_null($p)) {
        $arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent') . " : {$plug}"));
        $silence = true;
    } else {
        $arbre = $p;
    }
    if (!is_array($arbre)) {
        $arbre = array();
    }
    // verification de la conformite du plugin avec quelques
    // precautions elementaires
    if (!isset($arbre['nom'])) {
        if (!$silence) {
            $arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
        }
        $arbre['nom'] = array("");
    }
    if (!isset($arbre['version'])) {
        if (!$silence) {
            $arbre['erreur'][] = _T('erreur_plugin_version_manquant');
        }
        $arbre['version'] = array("");
    }
    if (!isset($arbre['prefix'])) {
        if (!$silence) {
            $arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
        }
        $arbre['prefix'] = array("");
    } else {
        $prefix = trim(end($arbre['prefix']));
        if (strtoupper($prefix) == 'SPIP' and $plug != "./") {
            $arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
        }
        if (isset($arbre['etat'])) {
            $etat = trim(end($arbre['etat']));
            if (!in_array($etat, $etats)) {
                $arbre['erreur'][] = _T('erreur_plugin_etat_inconnu') . " : '{$etat}'";
            }
        }
        if (isset($arbre['options'])) {
            foreach ($arbre['options'] as $optfile) {
                $optfile = trim($optfile);
                if (!@is_readable($dir_plugins . "{$plug}/{$optfile}")) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : {$optfile}";
                    }
                }
            }
        }
        if (isset($arbre['fonctions'])) {
            foreach ($arbre['fonctions'] as $optfile) {
                $optfile = trim($optfile);
                if (!@is_readable($dir_plugins . "{$plug}/{$optfile}")) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : {$optfile}";
                    }
                }
            }
        }
        $fonctions = array();
        if (isset($arbre['fonctions'])) {
            $fonctions = $arbre['fonctions'];
        }
        $liste_methodes_reservees = array('__construct', '__destruct', 'plugin', 'install', 'uninstall', strtolower($prefix));
        $extraire_pipelines = charger_fonction("extraire_pipelines", "plugins");
        $arbre['pipeline'] = $extraire_pipelines($arbre);
        foreach ($arbre['pipeline'] as $pipe) {
            if (!isset($pipe['nom'])) {
                if (!$silence) {
                    $arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
                }
            }
            if (isset($pipe['action'])) {
                $action = $pipe['action'];
            } else {
                $action = $pipe['nom'];
            }
            // verif que la methode a un nom autorise
            if (in_array(strtolower($action), $liste_methodes_reservees)) {
                if (!$silence) {
                    $arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit") . " : {$action}";
                }
            }
            if (isset($pipe['inclure'])) {
                $inclure = $dir_plugins . "{$plug}/" . $pipe['inclure'];
                if (!@is_readable($inclure)) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : {$inclure}";
                    }
                }
            }
        }
        $necessite = array();
        $spip_trouve = false;
        if (spip_xml_match_nodes(',^necessite,', $arbre, $needs)) {
            foreach (array_keys($needs) as $tag) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                if (!isset($att['id'])) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', array('attribut' => 'id', 'balise' => $att));
                    }
                } else {
                    $necessite[] = $att;
                }
                if (strtolower($att['id']) == 'spip') {
                    $spip_trouve = true;
                }
            }
        }
        if ($compat_spip and !$spip_trouve) {
            $necessite[] = array('id' => 'spip', 'version' => $compat_spip);
        }
        $arbre['necessite'] = $necessite;
        $utilise = array();
        if (spip_xml_match_nodes(',^utilise,', $arbre, $uses)) {
            foreach (array_keys($uses) as $tag) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                if (!isset($att['id'])) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_attribut_balise_manquant', array('attribut' => 'id', 'balise' => $att));
                    }
                } else {
                    $utilise[] = $att;
                }
            }
        }
        $arbre['utilise'] = $utilise;
        $procure = array();
        if (spip_xml_match_nodes(',^procure,', $arbre, $uses)) {
            foreach (array_keys($uses) as $tag) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                $procure[] = $att;
            }
        }
        $arbre['procure'] = $procure;
        $path = array();
        if (spip_xml_match_nodes(',^chemin,', $arbre, $paths)) {
            foreach (array_keys($paths) as $tag) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                $att['path'] = $att['dir'];
                // ancienne syntaxe
                $path[] = $att;
            }
        } else {
            $path = array(array('dir' => ''));
        }
        // initialiser par defaut
        $arbre['path'] = $path;
        // exposer les noisettes
        if (isset($arbre['noisette'])) {
            foreach ($arbre['noisette'] as $k => $nut) {
                $nut = preg_replace(',[.]html$,uims', '', trim($nut));
                $arbre['noisette'][$k] = $nut;
                if (!@is_readable($dir_plugins . "{$plug}/{$nut}.html")) {
                    if (!$silence) {
                        $arbre['erreur'][] = _T('erreur_plugin_fichier_absent') . " : {$nut}";
                    }
                }
            }
        }
        $traduire = array();
        if (spip_xml_match_nodes(',^traduire,', $arbre, $trads)) {
            foreach (array_keys($trads) as $tag) {
                list($tag, $att) = spip_xml_decompose_tag($tag);
                $traduire[] = $att;
            }
        }
        $arbre['traduire'] = $traduire;
    }
}
Exemplo n.º 7
0
/**
 * Recherche dans un arbre XML généré par `spip_xml_parse()` (ou une branche de cet arbre)
 * les clés de l'arbre qui valident la regexp donnée.
 *
 * Les branches qui valident la regexp sont retournées dans le tableau `$matches`.
 *
 * @see spip_xml_parse()
 * @see spip_xml_decompose_tag()
 *
 * @param string $regexp
 *     Expression régulière
 * @param array $arbre
 *     Arbre XML
 * @param array $matches
 *     Branches de l'arbre validant la rexgep
 * @param bool $init ?
 * @return bool
 *     false si aucun élément ne valide l'expression régulière, true sinon.
 **/
function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true)
{
    if ($init) {
        $matches = array();
    }
    if (is_array($arbre) && count($arbre)) {
        foreach (array_keys($arbre) as $tag) {
            if (preg_match($regexp, $tag)) {
                $matches[$tag] =& $arbre[$tag];
            }
            if (is_array($arbre[$tag])) {
                foreach (array_keys($arbre[$tag]) as $occurences) {
                    spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false);
                }
            }
        }
    }
    return count($matches);
}
Exemplo n.º 8
0
Arquivo: xml.php Projeto: rhertzog/lcs
function spip_xml_match_nodes($regexp,&$arbre,&$matches){
	if(is_array($arbre) && count($arbre))
		foreach(array_keys($arbre) as $tag){
			if (preg_match($regexp,$tag))
				$matches[$tag] = &$arbre[$tag];
			if (is_array($arbre[$tag]))
				foreach(array_keys($arbre[$tag]) as $occurences)
					spip_xml_match_nodes($regexp,$arbre[$tag][$occurences],$matches);
		}
	return (count($matches));
}
Exemplo n.º 9
0
function plugins_verifie_conformite_dist($plug, &$arbre, $dir_plugins = _DIR_PLUGINS){
	static $etats = array('dev','experimental','test', 'stable');

	$matches = array();
	$silence = false;
	$p = null;
	// chercher la declaration <plugin spip='...'> a prendre pour cette version de SPIP
	if ($n = spip_xml_match_nodes(",^plugin(\s|$),", $arbre, $matches)){
		// version de SPIP
		$vspip = $GLOBALS['spip_version_branche'];
		foreach($matches as $tag=>$sous){
			list($tagname,$atts) = spip_xml_decompose_tag($tag);
			if ($tagname=='plugin' AND is_array($sous)){
				if (!isset($atts['spip'])
					OR plugin_version_compatible($atts['spip'],$vspip)) {
					// on prend la derniere declaration avec ce nom
					$p = end($sous);
					$compat_spip = isset($atts['spip']) ? $atts['spip'] : '';
				}
			}
		}
	}
	if (is_null($p)){
		$arbre = array('erreur' => array(_T('erreur_plugin_tag_plugin_absent')." : $plug"));
		$silence = true;
	}
	else
		$arbre = $p;
	if (!is_array($arbre)) $arbre = array();
  // verification de la conformite du plugin avec quelques
  // precautions elementaires
	if (!isset($arbre['nom'])){
		if (!$silence)
			$arbre['erreur'][] = _T('erreur_plugin_nom_manquant');
		$arbre['nom'] = array("");
	}
	if (!isset($arbre['version'])){
	  	if (!$silence)
			$arbre['erreur'][] = _T('erreur_plugin_version_manquant');
		$arbre['version'] = array("");
	}
	if (!isset($arbre['prefix'])){
	  	if (!$silence)
			$arbre['erreur'][] = _T('erreur_plugin_prefix_manquant');
		$arbre['prefix'] = array("");
	} else{
		$prefix = trim(end($arbre['prefix']));
		if (strtoupper($prefix)=='SPIP'){
			$arbre['erreur'][] = _T('erreur_plugin_prefix_interdit');
		}
		if (isset($arbre['etat'])){
			$etat = trim(end($arbre['etat']));
			if (!in_array($etat, $etats))
				$arbre['erreur'][] = _T('erreur_plugin_etat_inconnu')." : '$etat'";
		}
		if (isset($arbre['options'])){
			foreach($arbre['options'] as $optfile){
				$optfile = trim($optfile);
				if (!@is_readable($dir_plugins."$plug/$optfile"))
  				if (!$silence)
						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
			}
		}
		if (isset($arbre['fonctions'])){
			foreach($arbre['fonctions'] as $optfile){
				$optfile = trim($optfile);
				if (!@is_readable($dir_plugins."$plug/$optfile"))
  				if (!$silence)
						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $optfile";
			}
		}
		$fonctions = array();
		if (isset($arbre['fonctions']))
			$fonctions = $arbre['fonctions'];
	    $liste_methodes_reservees = array('__construct','__destruct','plugin','install','uninstall',strtolower($prefix));

		$extraire_pipelines = charger_fonction("extraire_pipelines","plugins");
	    $arbre['pipeline'] = $extraire_pipelines($arbre);
		foreach($arbre['pipeline'] as $pipe){
			if (!isset($pipe['nom']))
				if (!$silence)
					$arbre['erreur'][] = _T("erreur_plugin_nom_pipeline_non_defini");
			if (isset($pipe['action'])) $action = $pipe['action'];
			else $action = $pipe['nom'];
			// verif que la methode a un nom autorise
			if (in_array(strtolower($action),$liste_methodes_reservees)){
				if (!$silence)
					$arbre['erreur'][] = _T("erreur_plugin_nom_fonction_interdit")." : $action";
			}
			if (isset($pipe['inclure'])) {
				$inclure = $dir_plugins."$plug/".$pipe['inclure'];
				if (!@is_readable($inclure))
	  			if (!$silence)
						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $inclure";
			}
		}
		$necessite = array();
		$spip_trouve = false;
		if (spip_xml_match_nodes(',^necessite,',$arbre,$needs)){
			foreach(array_keys($needs) as $tag){
				list($tag,$att) = spip_xml_decompose_tag($tag);
				$necessite[] = $att;
				if (strtolower($att['id']) == 'spip')
					$spip_trouve = true;
			}
		}
		if ($compat_spip AND !$spip_trouve)
				$necessite[] = array('id' => 'spip', 'version' => $compat_spip);
		$arbre['necessite'] = $necessite;
		$utilise = array();
		if (spip_xml_match_nodes(',^utilise,',$arbre,$uses)){
			foreach(array_keys($uses) as $tag){
				list($tag,$att) = spip_xml_decompose_tag($tag);
				$utilise[] = $att;
			}
		}
		$arbre['utilise'] = $utilise;
		$path = array();
		if (spip_xml_match_nodes(',^chemin,',$arbre,$paths)){
			foreach(array_keys($paths) as $tag){
				list($tag,$att) = spip_xml_decompose_tag($tag);
				$path[] = $att;
			}
		}
		else
			$path = array(array('dir'=>'')); // initialiser par defaut
		$arbre['path'] = $path;
		// exposer les noisettes
		if (isset($arbre['noisette'])){
			foreach($arbre['noisette'] as $k=>$nut){
				$nut = preg_replace(',[.]html$,uims','',trim($nut));
				$arbre['noisette'][$k] = $nut;
				if (!@is_readable($dir_plugins."$plug/$nut.html"))
  				if (!$silence)
						$arbre['erreur'][] = _T('erreur_plugin_fichier_absent')." : $nut";
			}
		}
		$traduire = array();
		if (spip_xml_match_nodes(',^traduire,',$arbre,$trads)){
			foreach(array_keys($trads) as $tag){
				list($tag,$att) = spip_xml_decompose_tag($tag);
				$traduire[] = $att;
			}
		}
		$arbre['traduire'] = $traduire;
	}
}