Page 2 of 2
Posted: Wed Feb 13, 2008 10:48 am
by garvinhicking
Hi!
We have, its in include/functions_smarty.inc.php registered. might be defined in functions_config.
regards,
Garvin
Posted: Wed Feb 13, 2008 3:00 pm
by judebert
Ah! That's perfect, then. It makes more sense to me to allow the user to pick his own custom property names, since he's going to be the one filling them in anyway. Language differences and personal preferences could make the names that we choose completely incomprehensible.
Don, I'd go with the code that finds the list of available custom property names and presents them to the user. It's longer, but it gets the right job done. For completeness, you could add a default that only gets included if the user hasn't saved the template config yet.
Posted: Mon Feb 18, 2008 10:52 pm
by judebert
Okay, here's the streamlined version of code to present a user with a choice from existing extended properties:
Code: Select all
$ep_plug = serendipity_plugin_api::enum_plugins('event', false, 'serendipity_event_entryproperties');
if ($ep_plug) {
$ep_id = $ep_plug[0]['name'];
$plug =& serendipity_plugin_api::load_plugin($ep_id);
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!');
}
And in your template_options array, you'll want to include this:
Code: Select all
array(
'var' => 'ep_name',
'name' => 'Extended Property to Use',
'type' => 'select',
'default' => '',
'select_values' => $ep_selections,
),
Of course, you'll want to turn all those strings into language constants.
The only other objection to this code is that it puts the error messages into the select drop-down. That's no problem in and of itself, but it can result in a VERY long drop-down. Here's a version that puts the message above the drop-down, allowing for longer error messages. I've replaced the strings with constants, too; you'll need to define them in your template language file.
Code: Select all
$ep_msg = '';
$ep_selections = array();
$ep_plug = serendipity_plugin_api::enum_plugins('event', false, 'serendipity_event_entryproperties');
if ($ep_plug) {
$ep_id = $ep_plug[0]['name'];
$plug =& serendipity_plugin_api::load_plugin($ep_id);
if ($plug) {
$fields = $plug->get_config('customfields');
if ($fields) {
$ep_selections = explode(',', $fields);
} else {
$ep_msg = THEME_ERROR_NO_CUSTOM_FIELDS;
}
} else {
$ep_msg = THEME_ERROR_INSTALL_EP_PLUGIN;
}
} else {
$ep_msg = THEME_ERROR_NONEXISTENT_EP_PLUGIN;
}
And here's the easy way to add it to your template options:
Code: Select all
array(
'var' => 'ep_msg',
'type' => 'content',
'default' => "<span class='serendipityAdmin_error'>$ep_msg</span>",
),
array(
'var' => 'ep_name',
'name' => 'Extended Property to Use',
'type' => 'select',
'default' => '',
'select_values' => $ep_selections,
),
We could get fancy and add both items to a single 'custom' option, but this is most understandable, I think. If you're interested in the single option thing, let me know.
Posted: Tue Feb 19, 2008 1:42 am
by Don Chambers
I tried:
Code: Select all
{$entry.properties|pickKey:$template_option.ep_name}
And received the following error:
Code: Select all
Fatal error: Smarty error: [in file:F:/mypath/my-smarty-file.tpl line 16]: [plugin] (secure mode) modifier 'pickKey' is not allowed (core.load_plugins.php, line 118) in F:\mypath\bundled-libs\Smarty\libs\Smarty.class.php on line 1095.
Posted: Tue Feb 19, 2008 11:51 am
by garvinhicking
Hi Don!
you need to disable smarty security through your config.inc.php file:
Code: Select all
$serendipity['smarty']->security = false;
so that you can use the pickKey modifier.
HTH,
Garvin
Posted: Tue Feb 19, 2008 3:57 pm
by Don Chambers
1) What risk, if any, comes from disabling security?
2) Still get an error, this time:
Code: Select all
Fatal error: Smarty error: [in file:F:/mypath/entries.tpl line 12]: [plugin] modifier 'pickKey' is not implemented (core.load_plugins.php, line 118) in F:\mypath\bundled-libs\Smarty\libs\Smarty.class.php on line 1095
Posted: Tue Feb 19, 2008 4:01 pm
by garvinhicking
Hi!
1) This means that .tpl templates can access every PHP function
2) There's something wrong in your install. You are using s9y 1.2.1? This one definitely has the "pickKey" smarty modifier implemented. Your installation does not seem to have it in include/functions_smarty.inc.php. This also fixes 1.) because you will not need to disable the security, sorry.
Regards,
Garvin
Posted: Tue Feb 19, 2008 4:14 pm
by Don Chambers
This install is 1.3a.... (localhost) and a fairly recent one too.....
Beginning on line 616:
Code: Select all
/**
* Smarty Function: Picks a specified key from an array and returns it
*
* @access public
* @param array Smarty parameter input array:
* array: The array you want to check
* key: The keyname
* default: What (string) to return when array does not contain the key.
* @param object Smarty object
* @return string The requested filename with full path
*/
function serendipity_smarty_pickKey($params, &$smarty) {
if ( !isset($params['array']) ) {
$smarty->trigger_error(__FUNCTION__ .": missing 'array' parameter");
return;
}
if ( !isset($params['key']) ) {
$smarty->trigger_error(__FUNCTION__ .": missing 'key' parameter");
return;
}
return serendipity_pickKey($params['array'], $params['key'], $params['default']);
}
Posted: Tue Feb 19, 2008 5:32 pm
by judebert
Yeah, the problem is that there's no such modifier. It's called through register_function, not register_modifier.
You'll need to call it as a Smarty function: {pickKey array="whatever" key="whatever"}