Sessions for anonymous users; private area interface things; and licences for plug-in

Hi folks,

I'm still working on my plug-in (a catalogue and shopping cart for SPIP) and have a few questions to ask. All of the below is with respect to 1.9.2e, but I'll be moving to 2.0.0 when it's stable. Thanks to everyone who's already answered my previous questions (Fil, Pierre, Gilles, and everyone else) and in advance to anyone who responds to this lot. My questions are below, easy ones first.

SPIP plug-ins should be under GPLv2 as they're derivative works, shouldn't they?

My notes on writing this plug-in are reasonably incomplete (it's mostly a list of stuff that *doesn't* work), but its about 9 A4 pages or so currently. Where's the best place to make it public: spip.net, plugins.spip.net, spip-contrib.net, doc.spip.org, our company web-site, or my personal blog (or some combination)?

Is there a block diagram or flow chart or something that explains SPIP's architecture? Writing this plug-in (or, more correctly, trying to figure out how to write this plug-in) has given me a much better understanding of SPIP, but it's also been extremely frustrating, not particularly elucidating and I can't imagine that it'll be a popular way to learn. :slight_smile:

Now for the harder, technical questions.

I've looked through the code in inc/session.php and inc/utils.php and I get the impression that SPIP's session handling is for authenticated users (accounts in `spip_auteurs`). Is this true? If I want to store session information for anonymous users, is there a proper way to go about it (from PHP in a plug-in, not a template)? In particular, I want to maintain a shopping cart in a session without forcing users to log-in first (indeed, I'd rather they not login at all). Can I do this with SPIP's session handling? Or will I need to fall back on session_start() and $_SESSION?

My plug-in adds support for products along side the articles, breves, and sites that are built in to SPIP. I'd really like to support all the same functionality as the built in things -- logos, authors, documents, and keywords -- but getting this to work has been (for me, at least) something of a nightmare. Even using the code for articles and breves as an example, some things work, others work poorly, and some don't work at all. I'll describe the main issues I've encountered below.

Adding logos to products was relatively simple. I just based my code on that in exec/articles.php (calling inc/iconifier.php). inc_iconifier_dist uses a global array to determine the heading for the logo block, so I had to use the second line below to add the correct title.

        $iconifier = charger_fonction('iconifier', 'inc');
        $GLOBALS['logo_libelles']['id_product'] = _T('yobbo:logo_product');
        $info .= $iconifier('id_product', $id_product, 'products', $flag_editable);

I added logos after wrestling with documents, keywords, authors, etc. so I was, frankly, surprised that it worked so well. Indeed, the only problem is that the widget is re-loaded using AJAX whenever the user adds or deletes a logo and that the AJAX action doesn't know about the heading that I added on line 2 above. How should I add my own headings to this array so that it is available to the AJAX action as well as to my call point?

Supporting documents attached to products was also relatively simple but, again, the AJAX doesn't work properly. I based my code on that for the article documents and wound up with:

        $documenter = charger_fonction('documenter', 'inc');
  $r .= "..."
  . $joindre('products', "id_product=$id&var_ajaxcharset=utf-8", $id, _T('info_telecharger_ordinateur'), 'document', 'product', '', 0,
      generer_url_ecrire('documenter', "id_product=$id&type=$type&var_ajaxcharset=utf-8", true))
  . "...";
        $r = '<div id="portfolio">' . $documenter($id, 'product', 'portfolio', $flag_editable). "</div>\n"
        . '<div id="documents">' . $documenter($id, 'product', 'documents', $flag_editable). "</div>\n"
        . $r;

(where $r is the string returned by `products_documents` called by my `products_affiche` in exec/products.php) I can add and delete documents and can change the fields of the documents as well. The only problem is that the AJAX update when I upload a new document doesn't return anything. It does upload the document and attach it to the product (I can refresh the page and it's there), it does put the AJAX response in an iframe (like iframe#upload_frame2) and the iframe does contain a response document (html > body > div.upload_answer.upload_document_added), it's just empty.

I also get JavaScript errors in the WebKit console ("TypeError: Result of expression 'this.iframeload' [undefined] is not a function."), but these are present on exec=articles and it works fine there, so this isn't problem I've got.

Is there something special I need to do to get the AJAX to work properly when attaching documents to non-SPIP objects?

The interface to change the dates of a product outputs fine (and even has the correct value), but I couldn't get it to update my products table. I used the following code, again based on that for articles):

  $dater = charger_fonction('dater', 'inc');
  $bd = $dater($id_product, $flag_editable, $statut_product, 'product', 'products', $date, $date_redac);

The variables have the same contents as in the articles script, and $bd gets join()ed with "\n"s and echo()ed. Alas, this outputs the widget with the correct date, but won't save. A quick look at the code of action/dater.php (the form output by the code above is hard-coded to submit to this action) shows that it is hard-coded to update `spip_articles`, `spip_breves` or `spip_syndic`. I've checked r13010 and, unless I've missed something, this function is still be hard-coded for these three tables. Is there a way to use the standard widget from inc/dater.php for my own objects?

Similarly for the keywords widget:

  $editer_mot = charger_fonction('editer_mot', 'inc');
  $bd = $editer_mot('product', $id_product, $cherche_mot, $select_groupe, $flag_editable);

The function that generates the widget (inc_editer_mot) is hard-coded to attach keywords to articles, news items, sections, and sites only.

The widgets to update a product's status were pretty easy and worked properly, as did the "the authors" widget. (I attempted to implement the features in this order: status, dater, authors, keywords, documents, logos.)

Developing my first SPIP plug-in has been (and, I have no doubt, will continue to be) an interesting experience: I've learned a lot about SPIP, but it's also been incredibly frustrating.

Thanks for reading,

Thomas Sutton

Web Developer
bouncingorange
graphic + web design

P.S: I've just posted a forum message (translated for me by Geraldine) on plugins.spip.net requesting that English translations be created for some of the rubriques. I'd like to post this plug-in and another I'll be developing (probably in December) there, when finished.

P.P.S: It's been a long day, so please accept my apologies if the above makes little sense.

Thomas Sutton a écrit :

Hi folks,

Didn't see the answer of Gilles. Sorry for "the noise" :wink:

--
Suske

Thomas, since you have a lot of dev questions, you could use
spip-dev@rezo.net mailing list.
It's usually a french mailing list but english is welcome as well.

Ben.

On Wed, Oct 22, 2008 at 1:09 PM, Thomas Sutton
<thomas@bouncingorange.com> wrote:

Hi folks,

I'm still working on my plug-in (a catalogue and shopping cart for SPIP) and
have a few questions to ask. All of the below is with respect to 1.9.2e, but
I'll be moving to 2.0.0 when it's stable. Thanks to everyone who's already
answered my previous questions (Fil, Pierre, Gilles, and everyone else) and
in advance to anyone who responds to this lot. My questions are below, easy
ones first.

SPIP plug-ins should be under GPLv2 as they're derivative works, shouldn't
they?

My notes on writing this plug-in are reasonably incomplete (it's mostly a
list of stuff that *doesn't* work), but its about 9 A4 pages or so
currently. Where's the best place to make it public: spip.net,
plugins.spip.net, spip-contrib.net, doc.spip.org, our company web-site, or
my personal blog (or some combination)?

Is there a block diagram or flow chart or something that explains SPIP's
architecture? Writing this plug-in (or, more correctly, trying to figure out
how to write this plug-in) has given me a much better understanding of SPIP,
but it's also been extremely frustrating, not particularly elucidating and I
can't imagine that it'll be a popular way to learn. :slight_smile:

Now for the harder, technical questions.

I've looked through the code in inc/session.php and inc/utils.php and I get
the impression that SPIP's session handling is for authenticated users
(accounts in `spip_auteurs`). Is this true? If I want to store session
information for anonymous users, is there a proper way to go about it (from
PHP in a plug-in, not a template)? In particular, I want to maintain a
shopping cart in a session without forcing users to log-in first (indeed,
I'd rather they not login at all). Can I do this with SPIP's session
handling? Or will I need to fall back on session_start() and $_SESSION?

My plug-in adds support for products along side the articles, breves, and
sites that are built in to SPIP. I'd really like to support all the same
functionality as the built in things -- logos, authors, documents, and
keywords -- but getting this to work has been (for me, at least) something
of a nightmare. Even using the code for articles and breves as an example,
some things work, others work poorly, and some don't work at all. I'll
describe the main issues I've encountered below.

Adding logos to products was relatively simple. I just based my code on that
in exec/articles.php (calling inc/iconifier.php). inc_iconifier_dist uses a
global array to determine the heading for the logo block, so I had to use
the second line below to add the correct title.

       $iconifier = charger_fonction('iconifier', 'inc');
       $GLOBALS['logo_libelles']['id_product'] = _T('yobbo:logo_product');
       $info .= $iconifier('id_product', $id_product, 'products',
$flag_editable);

I added logos after wrestling with documents, keywords, authors, etc. so I
was, frankly, surprised that it worked so well. Indeed, the only problem is
that the widget is re-loaded using AJAX whenever the user adds or deletes a
logo and that the AJAX action doesn't know about the heading that I added on
line 2 above. How should I add my own headings to this array so that it is
available to the AJAX action as well as to my call point?

Supporting documents attached to products was also relatively simple but,
again, the AJAX doesn't work properly. I based my code on that for the
article documents and wound up with:

       $documenter = charger_fonction('documenter', 'inc');
       $r .= "..."
       . $joindre('products',
"id_product=$id&var_ajaxcharset=utf-8", $id,
_T('info_telecharger_ordinateur'), 'document', 'product', '', 0,
                       generer_url_ecrire('documenter',
"id_product=$id&type=$type&var_ajaxcharset=utf-8", true))
       . "...";
       $r = '<div id="portfolio">' . $documenter($id, 'product',
'portfolio', $flag_editable). "</div>\n"
       . '<div id="documents">' . $documenter($id, 'product',
'documents', $flag_editable). "</div>\n"
       . $r;

(where $r is the string returned by `products_documents` called by my
`products_affiche` in exec/products.php) I can add and delete documents and
can change the fields of the documents as well. The only problem is that the
AJAX update when I upload a new document doesn't return anything. It does
upload the document and attach it to the product (I can refresh the page and
it's there), it does put the AJAX response in an iframe (like
iframe#upload_frame2) and the iframe does contain a response document (html

body > div.upload_answer.upload_document_added), it's just empty.

I also get JavaScript errors in the WebKit console ("TypeError: Result of
expression 'this.iframeload' [undefined] is not a function."), but these are
present on exec=articles and it works fine there, so this isn't problem I've
got.

Is there something special I need to do to get the AJAX to work properly
when attaching documents to non-SPIP objects?

The interface to change the dates of a product outputs fine (and even has
the correct value), but I couldn't get it to update my products table. I
used the following code, again based on that for articles):

       $dater = charger_fonction('dater', 'inc');
       $bd = $dater($id_product, $flag_editable, $statut_product,
'product', 'products', $date, $date_redac);

The variables have the same contents as in the articles script, and $bd gets
join()ed with "\n"s and echo()ed. Alas, this outputs the widget with the
correct date, but won't save. A quick look at the code of action/dater.php
(the form output by the code above is hard-coded to submit to this action)
shows that it is hard-coded to update `spip_articles`, `spip_breves` or
`spip_syndic`. I've checked r13010 and, unless I've missed something, this
function is still be hard-coded for these three tables. Is there a way to
use the standard widget from inc/dater.php for my own objects?

Similarly for the keywords widget:

       $editer_mot = charger_fonction('editer_mot', 'inc');
       $bd = $editer_mot('product', $id_product, $cherche_mot,
$select_groupe, $flag_editable);

The function that generates the widget (inc_editer_mot) is hard-coded to
attach keywords to articles, news items, sections, and sites only.

The widgets to update a product's status were pretty easy and worked
properly, as did the "the authors" widget. (I attempted to implement the
features in this order: status, dater, authors, keywords, documents, logos.)

Developing my first SPIP plug-in has been (and, I have no doubt, will
continue to be) an interesting experience: I've learned a lot about SPIP,
but it's also been incredibly frustrating.

Thanks for reading,

Thomas Sutton

Web Developer
bouncingorange
graphic + web design

P.S: I've just posted a forum message (translated for me by Geraldine) on
plugins.spip.net requesting that English translations be created for some of
the rubriques. I'd like to post this plug-in and another I'll be developing
(probably in December) there, when finished.

P.P.S: It's been a long day, so please accept my apologies if the above
makes little sense.
_______________________________________________
spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

Hi Thomas,

2008/10/23 Suske <suske@brubel.net>

Thomas Sutton a écrit :

Hi folks,

Didn’t see the answer of Gilles. Sorry for « the noise » :wink:

In fact the « problem » of the licence distribution for the plugin isn’t fixed yet.
There is a discussion on spip-dev about it. My answer was only my opinion in fact.
(http://thread.gmane.org/gmane.comp.web.spip.devel/50507)

Some core devs do not agree with me, so you can have a little hope to avoid GPL :slight_smile:
http://article.gmane.org/gmane.comp.web.spip.devel/50510

and http://article.gmane.org/gmane.comp.web.spip.devel/50520

Until now, there is a non-official concensus that states that anybody can do whatever he wants with the distribution of it’s work.
(and some web agencies actualy crypt their work with Zend Guard)

Your opinion would be really appreciated, as you are concerned by this question. I really suggest you to take part to the discussion.

I haven’t answered to the more technical part of your message, because I’m lacking time to do it.
But I’ll try to do my best rapidly…

.Gilles


Suske


spip-en@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-en

* Thomas Sutton tapuscrivait, le 22/10/2008 13:09:

Hi folks,

I'm still working on my plug-in (a catalogue and shopping cart for SPIP)

Have you seen Echoppe ? Échoppe - SPIP-Contrib
And Thelia ? Interface Thélia - SPIP-Contrib

--
RealET