Page 1 of 2

Theme option: select from available extended fields

Posted: Sun Feb 10, 2008 11:02 pm
by Don Chambers
I'm sure YL is going to want the answer to this one as well!! In this entry: http://board.s9y.org/viewtopic.php?t=11764, Garvin provided the code that lets us set a template option for available categories.

What would the equivalent be for selecting from a list of available extended entry fields? (ie $entry.properties.ep_Listening)

Additionally, is it setting it to an ID, or to the exact field name, so that if the name changes (ie "listening") we have a problem?

Part 2 to this request: I do not use a wysiwyg editor, so I do not know if there is a difference... however, when I want to use the "media" manager button to insert an image into an extended entry field, ultimately all that is inserted is the path to the image, not the <img> tag with all the additional info. Is this intentional, or does that functionality need to get updated to match the code used when inserting media into an entry? An additional reason to do this could be related to a recent request to know when an image is not used anywhere by detecting the <!--s9ymdb-->comment.

Re: Theme option: select from available extended fields

Posted: Mon Feb 11, 2008 4:11 pm
by garvinhicking
Hi!
Additionally, is it setting it to an ID, or to the exact field name, so that if the name changes (ie "listening") we have a problem?
The name is the ID. If you change the name, you change the ID.
Part 2 to this request: I do not use a wysiwyg editor, so I do not know if there is a difference... however, when I want to use the "media" manager button to insert an image into an extended entry field, ultimately all that is inserted is the path to the image, not the <img> tag with all the additional info. Is this intentional, or does that functionality need to get updated to match the code used when inserting media into an entry? An additional reason to do this could be related to a recent request to know when an image is not used anywhere by detecting the <!--s9ymdb-->comment.
This is not intentional. The serendipity_editor.js file should always take care to insert the full <img src...> stuff. It works for me in current s9y with untampered files. So there seems to be a bug in your installation, maybe serendipity_editor.js is broken?

In the media popup, do you get the screen where you choose the image alignment?

Regards,
Garvin

Posted: Mon Feb 11, 2008 5:46 pm
by Don Chambers
I have just tried it in 2 sandbox installs, and 4 live sites. It does not work in any of them... Some are running 1.2.1, others 1.3 alpha.

All I get is the choice of larger/thumbnail and then it inserts the path to the image in /uploads/.

Posted: Mon Feb 11, 2008 7:09 pm
by garvinhicking
Hi!

But that would mean that on no installation of yours you simply can insert an image, you always have to manually add <img>?! I hear this for the first time, every s9y user can insert images without manual modifications.

Could your browser be the single point of failure`?

Regards,
Garvin

Posted: Mon Feb 11, 2008 7:15 pm
by Don Chambers
I normally use FF.. but just tried with Opera... same result. I only receive the choice to select the large image or thumbnail, then the path is inserted. No alignment choices, no captions, no <img> tag.

Also - regarding part 1 of my question, can you make a code suggestion for how I can select from a list of available extended fields in theme options like you provided for selecting from a list of available categories?

Posted: Mon Feb 11, 2008 7:28 pm
by garvinhicking
Hi!

That's strange, it should have never behaved like this in any Serendipity version of the past 4 years.

This is a video of how it has always been for me:

http://blog.s9y.org/uploads/clip1.avi

This is how it's on every installation I've made and visited in the past few years, that should be a couple of hundred...maybe others here can tell me if they've ever experienced what you did? Maybe you can make a video, too? And really make sure the serendipity_editor.js file looks how distributed with the serendipity archive?

(as for q1, I cannot currently help. It involves SQL code and precise database access, nothing there is an API for. It's definitely possible for a programmer, though.)

Regards,
Garvin

Posted: Mon Feb 11, 2008 7:39 pm
by Don Chambers
Garvin - that video shows inserting media into an entry... and that works just fine for me. The behavior is not like that though for the extended fields. This isn't just a single s9y install either - I've checked in both of my local sandboxes, and a number of other live sites. The behavior is the same across them all.

Regarding selecting from a list of possible extended fields, wouldn't it be just like the categories, only opening the appropriate table that contains those fields and choosing from a list?

Posted: Mon Feb 11, 2008 7:46 pm
by garvinhicking
Hi!

Afh, you were talking about that! You were talking about extended field, and I took the extended entry for it. The things you refer to I describe as "Entry Properties fields". ;)

But now that's clear. The media button of those are only supposed to return a path, because you can stich <img> etc. around it yourself inside the template.
Regarding selecting from a list of possible extended fields, wouldn't it be just like the categories, only opening the appropriate table that contains those fields and choosing from a list?
Yeah, exactly. There needs to be a whole substituion for serendipity_fetchCategories. It's not hard, but I simply do not have the time for that rightnow.

Regards,
Garvin

Posted: Mon Feb 11, 2008 8:22 pm
by Don Chambers
Yes, I can add the appropriate <img.....> stuff in, say entries.tpl. And, on one hand, that is somewhat desireable.

However, what you cannot do is a)choose alignment b)add comments or use the image to link to something at the time the image is inserted into the extended field. Only the comment thing is a potential issue for me at the moment, and I'm not so sure it will continue to be a concern.

I guess you should decide how important it might be to insert media into these fields EXACTLY the same way it works everywhere else, or if this will ALWAYS be just a path.

I suppose a possibility could exist to have some sort of choice to "insert path only" (which is what it is doing now) AND have the normal <img src=blah blah>?

Posted: Mon Feb 11, 2008 10:05 pm
by garvinhicking
Hi!

Yes, conceptually it's not meant to provide full HTML, because you want full abstraction and alignment within the template, usually. Comments could be fetched from the database with custom smarty functions, so the entryproperties are really meant to provide RAW data.

In the bottom line, you can create your own input fields. Edit the templates/default/admin/entries.tpl thing and place your own input fields there with the entryproperties name,I think that could work. There you can place your own "media" button with custom ?serendipity URL variables, which then allow you to put formatted HTML into a field.
I suppose a possibility could exist to have some sort of choice to "insert path only" (which is what it is doing now) AND have the normal <img src=blah blah>?
Where would one specify this? There's no interface for that really, in the configuration screen of the plugin you can only enter commaseperated names without options. I somewhat refuse to add "var1:option1:option2,var2:option2:..." syntax to the plugin, this simply looks ugly and I do not want to discourage use of the entryproperties plugin.

Regards,
Garvin

Posted: Mon Feb 11, 2008 11:23 pm
by judebert
Don, you can find all the extended properties fields -- but it's real programming inside the template config.inc.php. No more nancy-pants stuff for you!

There are two problems: first off, you're accessing a plugin that might not be installed. Second, you're getting the value of a plugin's config values, which aren't stored in the database in a way that you can access them easily.

The following code will load the serendipity_event_entryproperties plugin, then get its 'customfields' value, and expand it into an array for you to use later (presumably in a listing of all custom properties fields). I check for all the errors that I can see occurring (except for an SQL error that causes a return that isn't an array).

Code: Select all

    $ep_plug = serendipity_plugin_api::enum_plugins('event', false, 'serendipity_event_entryproperties');
    if ($ep_plug) {
        $ep_plug = $ep_plug[0]['name'];
        $plug =& serendipity_plugin_api::load_plugin($ep_plug);
        if ($plug) {
            $fields = $plug->get_config('customfields');
            if ($fields) {
                $ep_selections = explode(',', $fields);
            } else {
                $ep_selections = array(0 => 'No custom fields are defined!');
            }
        } else {
            $ep_selections = array(0 => 'The extended properties plugin is not installed!');
        }
    } else {
        $ep_selections = array(0 => 'Extended properties plugin does not exist!');
    }
I tried to do the same sort of thing without loading the plugin, but apparently the templates are loaded before the functions. Or something; it blew up on me in nasty ways. This works, though.

If anybody has an easier way, let us know!

Posted: Tue Feb 12, 2008 5:00 am
by judebert
Of course, I'm not sure if you can actually use that. Wouldn't the Smarty wind up looking like {$entry.properties.{$name}}? Can you even do that?

Here's a snippet that actually sets the config value of the custom fields in the extended properties plugin so it includes three known values:

Code: Select all

if ($serendipity['GET']['adminModule'] == 'templates') {
    // Get the extended property plugin data
    $msg = '<span class="serendipityAdminMsgSuccess">Required properties added to custom entry properties.</span>';
    $epid = serendipity_plugin_api::enum_plugins('event', false, 'serendipity_event_entryproperties');
    if ($epid) {
        // Get the ID from the data
	    $epid = $epid[0]['name'];
        // Retrieve the actual extended properties plugin
        $plug =& serendipity_plugin_api::load_plugin($epid);
        if ($plug) {
            // Get the custom field config item
            $fieldstr = $plug->get_config('customfields');
            // Turn it into an array
            $fields = explode(',', $fieldstr);
            // Set first required extended property, if not defined
            if (!in_array('required_prop1', $fields)) {
            $fields[] = 'required_prop1';
            }
            // Set second required extended property, if not defined
            if (!in_array('required_prop2', $fields)) {
            $fields[] = 'required_prop2';   
            }
            // Set third required extended property, if not defined
            if (!in_array('required_prop3', $fields)) {
            $fields[] = 'required_prop3';   
            }
            // Turn it back into a string (with our new properties)
            $fieldstr = implode(',', $fields);                   
            // Set the new property string in the extended properties plugin
            $plug->set_config('customfields', $fieldstr);
        } else {
            $msg = '<span class="serendipityAdminMsgError">The extended properties plugin is not installed!</span>';
        }
    } else {
        $msg = '<span class="serendipityAdminMsgError">Extended properties plugin does not exist!</span>';
    }
}
To display that $msg status variable, you'll want to add something to your template options. I used this, as the first item in my template_options array:

Code: Select all

    array(
        'var'           => 'error_msg',
        'name'          => 'Required',
        'type'          => 'content',
        'default'       => $msg,
    ),

Posted: Tue Feb 12, 2008 3:41 pm
by Don Chambers
So Garvin - what is your opinion of Judebert's methods to a)select from a list of available extended fields and b) actually create a desired extended field that the template then relies on?

Posted: Tue Feb 12, 2008 3:48 pm
by garvinhicking
Hi!

Judeberts solution is great from a developer's standpoint. However it might suffer performance issues, it might be better to pick and fetch entryproperties and keys from the database directly.

you cannot use {$entry.properties.{$name}} but a s9y smarty modifies can do something like that: {$entry.properties|pickKey:$name}.

Regards,
Garvin

Posted: Tue Feb 12, 2008 4:22 pm
by judebert
We'd have to program the pickKey modifier ourselves, wouldn't we? I can't find it in the Smarty docs.