Page 1 of 1
Missing hook: frontend_display:html_layout
Posted: Mon Aug 10, 2009 4:53 pm
by praabjerg
Hi, I was wondering if there is any information on this apparently missing hook. It is listed as an event hook in the Plugin API:
http://www.s9y.org/116.html
But it does not appear to exist anywhere in the code. Unfortunately, that list is from 1.0-alpha1, so I guess the hook may have disappeared since.
I was hoping to use it to process the text and titles of sidebar items. Is there any other hook that allows this?
Re: Missing hook: frontend_display:html_layout
Posted: Tue Aug 11, 2009 1:27 pm
by garvinhicking
Hi!
Thanks for mentioning this, it's a glitch in the API documentation. This hook is actually only emitted by the serendipity_plugin_creativecommons plugin, and most possibly a 'spelling' mistake. It got into the documentation because that plugin is part of the core, and when documentation, I simply searched for all occuring event hook calls.
Can you tell what exactly you want to code by manipulating this plugin process? Then I could try to see how to achieve it. There currently is no hook to modify the output like that as an event plugin. There are ways to change this through the sidebar.tpl template, though - but if this is usable depends on the thing you try to achieve.
Regards,
Garvin
Re: Missing hook: frontend_display:html_layout
Posted: Tue Aug 11, 2009 4:36 pm
by praabjerg
Well, I wanted to try and make a simpler plugin for multilingual entries, by using tags instead of storing translations separately in the database.
So an english/danish/swedish entry might look like this in the database (don't mind the weird-looking tags. It's what I came up with at the time):
'title' = {{!en}}Translation test{{--}}{{!da}}Oversættelses-test{{--}}{{!se}}Översättnings-test{{--}}
'body' = {{!en}}This is English version of text.{{--}}
{{!da}}Dette er dansk version af tekst.{{--}}
{{!se}}Detta är svensk version av text.{{--}}
Then it's just a question of stripping out the right translations on the 'entry_display' hook. It may seem hackish, and it may not look particularly nice in the backend, but I prefer doing translated posts this way.
It also occurred to me that, given the right hooks, it would be very simple to extend this approach to other editable parts of the blog interface (the titles, and sometimes content, of the html-nuggets in the sidebar, for instance). Thus my interest in the 'frontend_display:html_layout' hook.
Applying the process to static pages also occurred to me as a possibility. But since static pages are handled by another plugin, I'm not entirely sure if it's possible to do it this way.
A downside to the approach, also, is that RSS and ATOM feeds will give you the uninterpreted version of the entries

Re: Missing hook: frontend_display:html_layout
Posted: Tue Aug 11, 2009 9:56 pm
by garvinhicking
Hi!
That's a nifty idea, and I think you should be able to pursue this.
I have two options for you:
1. I jsut committed a new event hook:
http://svn.berlios.de/viewvc/serendipit ... ision=2563
2. Without patching the core, you could edit the sidebar.tpl template. And instead of:
you could use:
To use a custom smarty modifier. For that, you would need to create a config.inc.php in your template directory with a code like:
Code: Select all
<?php
function languagify($string) {
// do your magic parsing here
return $your_new_string_parsed;
}
$serendipity['smarty']->register_modifier('languagify', 'languagify');
Doing it as a plugin would be the cooler approach, but the template method would be a quick "hack" to do it on your installation. But I think your idea could be a nice contribution to the multilingual plugin?!
Regards,
Garvin
Re: Missing hook: frontend_display:html_layout
Posted: Wed Aug 12, 2009 3:42 am
by Don Chambers
Re: Missing hook: frontend_display:html_layout
Posted: Wed Aug 12, 2009 11:59 am
by praabjerg
Great! Thanks.
I think I'll start by trying the latest Subversion checkout of Serendipity. If that turns out to be broken in some way, I'll make do with the template hack, for now.
Right now, it's just a very small plugin at 45 lines with no configuration options. And I rely on the Language Chooser of the multilingual plugin for language choice. Stripping out languages from the text is just handled by a regular expression. If I want to write an entry where the {{!<lang>}}{{--}} tags should appear in the text, it's probably impossible right now (the regexp devours all...). Also, using it on entries may be annoying with newline to <br/> conversion enabled. If you put newlines between the tagged translations, they will appear in the entry, if converted to <br/>.
The RSS feeds might need to be fixed somehow, too.
I could probably extend the multilingual plugin with only the sidebar tagging functionality. I'm not sure it makes sense to allow both approaches on entries in the same plugin. And as I mentioned above, tag-translation on entries has some problems that I'm not sure I'm going to try and fix for public consumption.
In fact, if I could integrate sidebar tag-translation in the multilingual plugin, I might just do the lazy thing, and use that plugin myself

Re: Missing hook: frontend_display:html_layout
Posted: Wed Aug 12, 2009 12:07 pm
by onli
Hi
You could probably use the same regexp on the rss-hook to print only one language. Why converts the plugin newlines to br? If you want to be able to print {{!<lang>}}{{--}}-tags in the text (what should be useful if you want to explain the plugin in your blog): it's possible to enable escaping via \, I think in the s9ymarkup-plugin is an example for that.
sincerely
Re: Missing hook: frontend_display:html_layout
Posted: Wed Aug 12, 2009 12:52 pm
by praabjerg
Ah. Thanks for the tip. I'm not entirely sure how I overlooked the rss hooks, and I will take a look at enabling escaping. Maybe I can work it all out somehow, anyway, even if I am a bit lazy.

Newlines to br conversion is enabled for entries by default in the plugin Markup: NL2BR, which is included from the beginning in a new Serendipity install. Which makes sense in a way. It just doesn't work very well together with the way I implement the language tags, i.e. by stripping out any tagged blocks that are not the current language. Any text or newlines in-between are still included in the processed text. Another possibility is to do the opposite, and only include whatever is inside the block for the current language. You wont be able to include any "language-agnostic" text in the entry, but it would solve any problems there might be with using newline conversions.
Re: Missing hook: frontend_display:html_layout
Posted: Fri Aug 14, 2009 12:29 am
by praabjerg
There we go. RSS feeds and sidebar items are translated. Escaping the brackets will exclude them from the processing. You can see the result here:
http://struntprat.dk
There are still two quirks I haven't been able to work out, though:
1. Date name translations (in the archive sidebar item, for instance). These dates are taken from the strftime() function (through serendipity_strftime() in functions.inc.php). The localization of those should, theoretically, be possible using the setlocale() function:
setlocale(LC_ALL, 'da_DK.UTF-8') for instance. This changes the strftime output correctly when I try it in interactive mode, but strangely doesn't work, even if I try to write it directly into the serendipity_strftime() function. Calling setlocale() just before the $out = strftime($format, $timestamp); line does nothing, apparently.
2. Check
http://struntprat.dk/index.php?/archive ... -test.html
The title of the entry, all the way at the top of the page, stays unprocessed. And I haven't found a hook that's able to grab it.
Neither issue is a showstopper for me, personally. But it would be nice to find a solution, at least to the second one.

Re: Missing hook: frontend_display:html_layout
Posted: Fri Aug 14, 2009 1:23 pm
by garvinhicking
Hi!
The s9y locales are set in the serendipity_config.inc.php file - we use setlocale(LC_TIME) only. Maybe if you use LC_ALL instead, it will not override LC_TIME?
The full title of the blog is stored in $serendipity['blogTitle'], which is filled with an entry title. $serendpity is a global variable, so you should be able to change that at any place before smarty gets a hold of it; after that, you can overwrite it through $serendipity['smarty']->assign('blogTitle', 'my title')?
HTH,
Garvin
Re: Missing hook: frontend_display:html_layout
Posted: Fri Aug 14, 2009 5:40 pm
by praabjerg
Thanks. There we go. Stuff works.
Strangely, the date localization issue fixed itself magically somehow. I'm not entirely sure how that happen, it just started working suddenly, while I was fixing the entry title processing

I'm guessing it could be because the server finally registered the new locales I had installed. I hadn't actually considered restarting it after installing them yesterday. Silly me.
If you want this tagged translation functionality integrated into the multilingual plugin, I'll see if I can put together a patch for it, making it an option in the plugin configuration. Of course, the sidebar item translation will only work with the new hook you provided in the repository.
Re: Missing hook: frontend_display:html_layout
Posted: Sun Aug 16, 2009 12:21 am
by garvinhicking
Hi!
A patch with an option for that would be nice, maybe you could also find the time for a few sentences inside a documentation_en.html file todescribe how to use it? That would be great!
Regards,
Garvin
Re: Missing hook: frontend_display:html_layout
Posted: Sun Aug 16, 2009 2:22 pm
by praabjerg
Here you go. There's a patch for lang_en.inc.php and one for serendipity_event_multilingual.php, and a short documentation text in documentation_en.html. Both patch files are diffs against the files currently available through Spartacus.
I'm not sure I conform entirely to conventions. For instance, there is a &getLang($id, &$properties) function that I'm not using for anything. I just extract the current language from $serendipity and leave it at that.
But it's a relatively small patch, at least. Enjoy!

Re: Missing hook: frontend_display:html_layout
Posted: Sun Aug 16, 2009 2:50 pm
by garvinhicking
Hi!
Great, that looks good. I've committed your patch, only added some serendipity_db_bool() calls around your get_config methods to be able to easily support postgresql with its differently true/boolean handling.
Thanksl
Garvin