mistergraphx
1/4/2018 - 12:04 PM

SPIP Déclarer une nouvelle wheel à TextWheel

SPIP Déclarer une nouvelle wheel à TextWheel

<?php

if (!defined('_ECRIRE_INC_VERSION')) {
	return;
}

// Ajout des raccourcis dans la liste des wheels
$GLOBALS['spip_wheels']['raccourcis'][] = 'box.yaml';
<paquet
	prefix="fragments_core"
	categorie="divers"
	version="1.1.2"
	schema="1.0.0"
	etat="dev"
	compatibilite="[3.1.0;3.2.*]"
	logo="fragments_core.png"
>
	<nom>Fragments : core</nom>

  <auteur>Arnaud B. (Mist. GraphX)</auteur>
	<copyright>2016-2017</copyright>
	<licence>GPL v3</licence>
	
	<!-- Déclarer que l'on utilise textwheel -->
	<necessite nom="tw" compatibilite="[0.3.1;[" /> <!--TextWheel-->
	
	
</paquet>
--- # Syntaxe des raccourcis SPIP, version 0.0.1
    #
    # Si on nomme une regle, elle devient surchargeable
box:
  # raccourcis <box>
  # box
  match: "#^([<box].*?[>])(.*?)(</box>)#ms"
  is_callback: Y
  replace: box
  if_str: '<box'
  priority: -100
<?php

if (!defined('_ECRIRE_INC_VERSION')) {
	return;
}

// @see http://zone.spip.org/trac/spip-zone/browser/_plugins_/todo/trunk/wheels/todo.php
// test : http://lumadis.be/regex/test_regex.php?id=3254
// Extraction de lignes du texte
// La wheel renvoie un tableau à cette callback qui est le résultat d'un preg_match_all.
// Le contenu du tableau est le suivant :
// 0 - la chaine complète
// 1 - uverture de la boite
// 2 - Contenu
// 3 - balise fermante

function box($t){
	// recuperer les css
	$reg = '/class="(.*?)"/s';
	if(preg_match_all($reg,$t[1],$styles)){
		$css = $styles[1][0];
	}
	$box_content= $t[2];

	$html = "<div class=\"$css\">".$box_content."<div>" ;

	return $html;
}