Hi!
We have, its in include/functions_smarty.inc.php registered. might be defined in functions_config.
regards,
Garvin
Theme option: select from available extended fields
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
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.
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.
Okay, here's the streamlined version of code to present a user with a choice from existing extended properties:
And in your template_options array, you'll want to include this:
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.
And here's the easy way to add it to your template options:
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.
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!');
}
Code: Select all
array(
'var' => 'ep_name',
'name' => 'Extended Property to Use',
'type' => 'select',
'default' => '',
'select_values' => $ep_selections,
),
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;
}
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,
),
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
I tried:
And received the following error:
Code: Select all
{$entry.properties|pickKey:$template_option.ep_name}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.=Don=
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
Hi Don!
you need to disable smarty security through your config.inc.php file:
so that you can use the pickKey modifier.
HTH,
Garvin
you need to disable smarty security through your config.inc.php file:
Code: Select all
$serendipity['smarty']->security = false;
HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
1) What risk, if any, comes from disabling security?
2) Still get an error, this time:
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=Don=
-
garvinhicking
- Core Developer
- Posts: 30022
- Joined: Tue Sep 16, 2003 9:45 pm
- Location: Cologne, Germany
- Contact:
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
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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
-
Don Chambers
- Regular
- Posts: 3657
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
This install is 1.3a.... (localhost) and a fairly recent one too.....
Beginning on line 616:
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']);
}=Don=