Create spip_documents programmatically and routing pretty URls

Hello dear community,

Im working on an interesting project posting some new questions.

First, is there a « SPIP » way to register a route? E.g. if I want to have a pretty URl /somepage, and I want a php file to evaluate it, is there a function I can call like

new_route(« Url », function)

to evaluate it? If not, I would use htaccess, but I was wondering if SPIP can already do this.

Secondly, I’m struggling to create a formulaire for uploading images to my SPIP site.

For articles this is easy, for example simply take the $_POST[‹ title ›] variable and execute

article_inserer( $id_rubrique , array(« titre » => $_POST[‹ title ›] );

But for documents, how do I process a file? I can access the file with $_POST[‹ file ›]

But I find the

ajouter_documents($id_document, $files, $objet, $id_objet, $mode);

function does not take the $_POST[‹ file ›] variable but expects an array created by function

$files = joindre_trouver_fichier_envoye();

However, I struggle to create a form that complies with this function. Is there a simple way?

Thanks,

Urs

Hello

i'll answer the last part of your query :slight_smile:

Le 01/02/2018 à 17:37, Urs Riggenbach via spip-en a écrit :

I struggle to create a form that complies with this function. Is there a simple way?

Simply use plugins :

https://plugins.spip.net/uploadhtml5.html
https://plugins.spip.net/formulaireupload.html

JLuc

And now for the first part.

Le 01/02/2018 à 17:37, Urs Riggenbach via spip-en a écrit :

First, is there a "SPIP" way to register a route? E.g. if I want to have a pretty URl /somepage, and I want a php file to evaluate it, is there a function I can call like
new_route("Url", function)
to evaluate it? If not, I would use htaccess, but I was wondering if SPIP can already do this.

AFAIK SPIP way is to tweak the htaccess
AND define a dedicated new file in the 'url' subfolder
of your skelettons or plugin folder.

This file contains a set of `generer_url_article($id_article)` functions
and other used object url_functions,
along with a `function recuperer_parametres_url(&$fond, $url)` definition.

The new set of routing rules is then declared in the site's configuration page.

Not sure this fits your expectation though...

JL