Skip navigation.

SPIP commits

Posts tagged with "trick"

[11582] Howto redefine a single function

, ,

This commit introduced a functionality that is used everywhere, especially with CVT forms :

Every functions xxx_yyy_zzz() can be defined in a unique file xxx/yyy.php.

Application in CVT : formulaires_yyy_charger(), formulaires_yyy_verifier(), and formulaires_yyy_traiter() can be defined in a unique file formulaires/yyy.php (which uses the template formulaires/yyy.html)

What I've discovered is that the functions can be independently overwritten by the same function defined in xxx/yyy/zzz.php !

Used with the function search path, this can be really usefull when you want to override a general plugin (such as Agenda).

Read more...

A small list of code tips for SPIP

, ,

Howto detect if a plugin is activated :
1. PHP : if (defined('_DIR_PLUGIN_XXX')){ /* My action for this plugin */ }
2. SPIP1.9.2 : [(#EVAL{DIR_PLUGIN_PREFIX}|?{' ',”}) My action for this plugin ]
3. SPIP2.0 : [(#PLUGIN{XXX}) My action for this plugin ]

Howto do not display the admin toolbar in the public area :
Put at the first line (with #CACHE) : [(#HTTP_HEADER{Content-type: text/html[; charset=(#CHARSET)]})]

Howto replace any text with an image :
[(#REM|=={''}|?{My beautifull text}|image_typo{police=Victor.ttf,taille=14,largeur=150})]

Howto directly link an element :
<a href="#URL_ARTICLE{54}">Link</a>

Howto get the articles that are tagged with a keyword :
Instead of using the keword id, you can directly refere to it's value :
<BOUCLE(ARTICLES){titre_mot=we love America}>#TITRE</BOUCLE>

And you :
Which are the best code tips that you use ?

[11435] MySQL views can be used in SPIP loops

, , ,

SQL views are known to be used like tables.
They enable to :
- mask the schema complexity ( -> simplification of queries)
- give access to a limited number of fields ( -> security)
- manipulate calculated fields (sum(), max(), avg(), ..)

Now you can avoid writing complexe loops by using views :

Example :
mysql> create view v AS 
         SELECT a.titre,a.id_article,b.id_rubrique,b.titre AS titre_rub 
         FROM spip_articles AS a 
         LEFT JOIN spip_rubriques AS b ON(a.id_rubrique=b.id_rubrique)
         WHERE b.titre REGEXP '^A'
         ORDER BY a.titre DESC;


template :
<BOUCLE_n(V)>
 <div>#TITRE : #TITRE_RUB</div>
</BOUCLE_n>


SPIP implements this for MySQL and sqlite
(for sqlite you must explicit the name of the fields used in the view)


Fantastic, no ?


(PS.: note that views do not improve the performance of your queries, so use them sparingly)

[11415] 3 new filters for boolean operators

, , , ...

These filters are 'et', 'ou', and 'xou' (for 'and', 'not', and 'xor').
They work like |?{' ',} :

each filter returns a space char if the condition is verified, elsewhere it returns an empty string



For example this PHP code
if ($a=='testA' OR ($b=='testB' AND $c=='testC')) {echo "OK";}

Can be translated in a template like this :
[(#A|=={testA} 
    |ou{[(#B|=={testB}
            |et{[(#C|=={testC})]})]}) OK ]

Or better
[(#B|=={testB} 
    |et{[(#C|=={testC})] 
    |ou{[(#A|=={testA})]}) OK ]

Easter egg on the private area

, ,

"You can even create a specific template in the private area.
For exemple, this template

/squelette/prive/editer/article-23.html

is used to edit articles which are in the section number 23 (and it's subsections)
(works also to display them)"

from http://thread.gmane.org/gmane.comp.web.spip.devel/46774/focus=46786

FAQ : I want to update the url value after having changed the title of my article

, , ,

Long title for a frequent problem :wink: .

when a title of an article is changed, the url isn't automatically recalculated.

It's interresting if you don't want to lost backlinks, but it can be disturbing because the url may not correspond to the content of the linked page.

Here is the trick : Just clic on the link 'See online' when you display the article inside the private area. It will not only clear the cached content for this page, but it will also force the url to be recalculated according to the title field.

Howto detect if a plugin is activated ?

, , ,

in PHP :
Each plugin defines a constant corresponding to it's execution path
if (defined('_DIR_PLUGIN_XXX')){ ... }


inside a template :
#PLUGIN and conditionnal evaluation does your job !
[(#PLUGIN{XXX}) doSomething ]

A lot of arguments for a tag

,

They can sometimes be concatenated into a unique argument list :

[(#MODELE{emb}{autostart=true}{this=1}{that=anything})]
#MODELE{emb}{autostart=true,this=1,that=anything}
[(#INCLURE{something}{id_xx=0}{env}{truc=toto})]


All these sentences are corrects. But you can't write :

#INCLURE{something}{id_xx=0,env,truc=toto}


because it's inherited from syntax of the <INCLURE>
Note that the first argument of a tag can't be a list.

Howto declare an empty array in SPIP ?

, ,

The only solution is to use
#SET{rubriques, #ARRAY}

If the array is initialised, there is always a default element inside :
#SET{liste_membres,#ARRAY{0}}
creates a PHP array(0=>'0')