Hi Yaron,
On 2009-07-25 01:39, Yaron Koren wrote:
[...]
> I would recommend instead following the code in SF itself, such as, as
> you note, the function dateEntryHTML() in /includes/SF_FormInputs.inc.
> If you use that as the model for your function, you should be alright.
> Note that global variables will still be accessible in your function,
> even though it's in a different extension.
Ok, that pointed me into the right direction, thanks!
I have now created my own SFCustomDateInput mini-extension which provides
'input type=customdate' (which adds Today and Yesterday buttons to 'input
type=date'). While I was at it, I also made a 'customdatetime' which reuses the
customdate code and removes the input field for seconds, since we never will
have to input such a precise point in time.
I have attached the extension as it is now. I guess its functionality won't be
very useful to anybody, but it may be useful as a sample for people who want to
create similar mini-extensions. It contains a lot of duplicated code from
includes/SF_FormInputs.inc.
Patrick.
--
Key ID: 0x86E346D4 http://patrick-nagel.net/key.asc
Fingerprint: 7745 E1BE FA8B FBAD 76AB 2BFC C981 E686 86E3 46D4
__FILE__,
'name' => 'SFCustomDateInput',
'version' => '0.1',
'author' => array( 'Patrick Nagel' ),
'description' => 'Provides a custom date (customdate) and a custom datetime (customdatetime) input for Semantic Forms',
'descriptionmsg' => 'SFCustomDateInput-desc',
);
$wgExtensionFunctions[] = 'sfCustomDateInputSetup';
function sfCustomDateInputSetup() {
global $wgParser, $wgExtensionCredits;
// add the 'customdate' and 'customdatetime' form input types, if Semantic Forms is installed
global $sfgFormPrinter;
if ($sfgFormPrinter) {
$sfgFormPrinter->setInputTypeHook('customdate', 'sfCustomDateInputHTML', array());
$sfgFormPrinter->setInputTypeHook('customdatetime', 'sfCustomDateTimeInputHTML', array());
}
}
function sfCustomDateInputHTML($date, $input_name, $is_mandatory, $is_disabled, $field_args) {
global $sfgTabIndex, $sfgFieldNum, $sfgJSValidationCalls, $wgAmericanDates;
// Use the normal dateEntryHTML function
$normalDateEntryHTML = SFFormInputs::dateEntryHTML($date, $input_name, $is_mandatory, $is_disabled, $field_args);
// Now add our customisations
$input_id = "input_$sfgFieldNum";
$disabled_text = ($is_disabled) ? "disabled" : "";
// Today button
$sfgTabIndex++;
$normalDateEntryHTML[0] .= ' " . "\n";
// Yesterday button
$normalDateEntryHTML[0] .= ' " . "\n";
return $normalDateEntryHTML;
}
function sfCustomDateTimeInputHTML($datetime, $input_name, $is_mandatory, $is_disabled, $field_args) {
global $sfgTabIndex, $sfg24HourTime;
// The following code is mostly copied from dateTimeEntryHTML (SF version 1.8, 2009-07-27)
$include_timezone = $other_args['include_timezone'];
if ($datetime) {
// can show up here either as an array or a string, depending on
// whether it came from user input or a wiki page
if (is_array($datetime)) {
if (isset($datetime['hour'])) $hour = $datetime['hour'];
if (isset($datetime['minute'])) $minute = $datetime['minute'];
if (! $sfg24HourTime) {
if (isset($datetime['ampm24h'])) $ampm24h = $datetime['ampm24h'];
}
if (isset($datetime['timezone'])) $timezone = $datetime['timezone'];
} else {
$actual_date = strtotime($datetime);
if ($sfg24HourTime) {
$hour = date("G", $actual_date);
} else {
$hour = date("g", $actual_date);
}
$minute = date("i", $actual_date);
if (! $sfg24HourTime) {
$ampm24h = date("A", $actual_date);
}
$timezone = date("T", $actual_date);
}
} else {
$cur_date = getdate();
$hour = null;
$minute = null;
$ampm24h = "";
$timezone = "";
}
list($text, $_javascript__text) = sfCustomDateInputHTML($datetime, $input_name, $is_mandatory, $is_disabled, $other_args);
$disabled_text = ($is_disabled) ? "disabled" : "";
$text .= ' ';
$sfgTabIndex++;
$text .= ' :';
if (! $sfg24HourTime) {
$sfgTabIndex++;
$text .= ' \n";
$ampm24h_options = array('', 'AM', 'PM');
foreach ($ampm24h_options as $value) {
$text .= " $value\n";
}
$text .= " \n";
}
if ($include_timezone) {
$sfgTabIndex++;
$text .= ' ' . "\n";
}
return array($text, $_javascript__text);
}
------------------------------------------------------------------------------
_______________________________________________
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel