Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Bulk insert for links
Ah, sorry, yes. There’s no save
step on this panel. It’s a fudge.
When the save routine was refactored to do everything in one function, we now choose between the states based on the value of save
or publish
POST variables and the status
. The step is always a fixed value: edit
.
So:
public function __construct()
{
register_callback(array(__CLASS__, "bulkInsert"), "article", "edit", 1);
}
should work. Then just just decide in your routine whether you want to act on ps('save')
or ps('publish')
accordingly.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Bulk insert for links
Sorry for the late reply.
I had it working with register_callback(array(__CLASS__, "bulkInsert"), "article_saved");
But only when clicking the “save” button.
I’ve just changed for register_callback(array(__CLASS__, "bulkInsert"), "article","edit", 1);
with public static function bulkInsert($event, $step, $data, $rs)
Which produce the following error message :
Fatal error: Uncaught ArgumentCountError:
Too few arguments to function plh_link_bulkinsert::bulkInsert(), 2 passed in extpattern/lib/txplib_misc.php on line 1589
and exactly 4 expected in plh_link_bulkinsert/plh_link_bulkinsert.php:36
Not sure what is wrong ^^
Offline
Re: Bulk insert for links
You don’t get $data
and $rs
passed from panel-level callbacks. So remove those two params from your function signature and you should be golden.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Bulk insert for links
Thanks. I missed this bit in the doc :/
The fist part is pretty much done: I can retrieve the content of my textarea, parse it as CSV and do my bulk insert and get back the IDs of the links.
Now, I want to append <txp:linkist ... />
the the Body inside the write panel.
I tried to append it directly to the $_POST['Body']
but if I understand correctly, the plugin is called after the save.
How could I achieve that ?
Other question: as these links are references for the article, I’d like them to be footnotes.
Below is the block I want to append to the body.
h3(ref-links). Références
<txp:variable name="linkids" value="1,2,3"/>
<txp:linklist id="1,2,3"
sort='FIELD(id, <txp:variable name="linkids" breakby="," escape="trim, quote" break="," />)'
break="br" escape="textile">
fn<txp:variable name="note_nbr" add="1" escape="tidy" output />. %(type-date)<txp:jcr_link_custom name="type_publication" /><txp:jcr_link_custom name="date_publication" />%
<txp:jcr_link_custom name="auteur" wraptag="span" class="auteur"/>
<txp:link_description wraptag="span" class="title-description"/>
<txp:link_name wraptag="span" class="éditeur-publication"/>
<a class="ref-link" href="<txp:link_url />">
voir lien
</a>
</txp:linklist>
All is fine except that the fn<x>.
part is not parsed by textile to become a footnote link.
Is it even possible to do that ?
And last but least: what is the magical incantation to syntax-colour a textpattern bc.. :)
Last edited by planeth (2024-08-30 12:46:34)
Offline
Re: Bulk insert for links
planeth wrote #337752:
Other question: as these links are references for the article, I’d like them to be footnotes.
Below is the block I want to append to the body.
h3(ref-links). Références...
All is fine except that the
fn<x>.
part is not parsed by textile to become a footnote link.
Is it even possible to do that ?
These fn#.
tokens must start a line, so escape="trim, textile"
should work.
And last but least: what is the magical incantation to syntax-colour a textpattern bc.. :)
bc.. txp
perhaps?
Unrelated, but break="br"
and quoting link ids do not seem necessary here.
Offline
Re: Bulk insert for links
Almost there !
escape="trim, textile"
plus you need break="p"
to generate the footnote’s id.
The snag is that while the footnote’s id is generated, it does not matches the href link generated for the content above
Below, an example :
<p>some content<sup class="footnote" id="fnrev3292214966d1c053e5360-1"><a href="#fn3292214966d1c053e5360-1">1</a></sup></p>
<p class="footnote" id="fn128403068966d1c128ad080-1"><sup>1</sup>
here goes the footnote content
</p>
Offline
Re: Bulk insert for links
Thanks Oleg and Stef !
I’ve found that the textiled footnote works if I append directly the footnote content to the Body:
fn1. %(type)article 2019%, %(auteur)somebody%, %(title-description)Some description%, %(éditeur-publication)editor%
<a class=refLink href="http://somelink" data-link-id=98>Voir le lien</a>
The plugin run before article_save
does its things.
To update the body and clear the reference_links
field use
$response[] = '$("#body").val("'.escape_js($_POST['Body']).'").css("overflow", "auto")';
$response[] = '$("#plh-reference-links").val("")';
send_script_response(join("\n", $response));
If anyone is interested in the code, let me know ;)
edited for future reference
Last edited by planeth (2024-09-03 10:03:15)
Offline
Re: Bulk insert for links
Glad you have nailed it. What callback are you using? We have recently introduced two ‘pre-save’ callbacks in dev, but, probably, they are not really needed?
Offline