$lang_upload_php['upload_swf'],
'html_single' => $lang_upload_php['upload_single'],
);
// Filter upload choices to allow plugins to add upload methods
$upload_choices = CPGPluginAPI::filter('upload_options',$upload_choices);
// Default upload method set by the gallery administrator
$upload_form = $CONFIG['upload_mechanism'];
// Populate Icon array
$icon_array = array();
$icon_array['continue'] = cpg_fetch_icon('right', 2);
$icon_array['ok'] = cpg_fetch_icon('ok', 0);
$icon_array['cancel'] = cpg_fetch_icon('cancel', 2);
$icon_array['upload'] = cpg_fetch_icon('upload', 2);
$icon_array['info'] = cpg_fetch_icon('info', 2);
// If we have "single" key in GET then we will force the upload form mechanism to single file upload
// This acts as a fallback if js or flash is disabled
if ($superCage->get->keyExists('single')) {
$upload_form = 'html_single';
} elseif ($CONFIG['allow_user_upload_choice'] && $superCage->get->keyExists('method')) {
// pull in upload method from GET parameter 'method'
$matches = $superCage->get->getMatched('method','/^[0-9A-Za-z_]+$/');
$upload_form = $matches[0];
$USER['upload_method'] = $upload_form;
} elseif ($superCage->post->keyExists('method')) {
// pull in upload method from POST parameter 'method'
$matches = $superCage->post->getMatched('method','/^[0-9A-Za-z_]+$/');
$upload_form = $matches[0];
} elseif ($CONFIG['allow_user_upload_choice'] && isset($USER['upload_method'])) {
$upload_form = $USER['upload_method'];
}
// Confirm that upload method chosen is one of the available choices
if (!in_array($upload_form, array_keys($upload_choices))) {
// Try gallery default upload method
$upload_form = $CONFIG['upload_mechanism'];
if (!in_array($upload_form, array_keys($upload_choices))) {
$upload_form = 'html_single';
}
unset($USER['upload_method']);
}
// If upload method is swf then only include the JS files and other code for it
if ('swfupload' == $upload_form) {
js_include('js/swfupload/swfupload.js');
js_include('js/swfupload/swfupload.swfobject.js');
js_include('js/swfupload/swfupload.queue.js');
js_include('js/swfupload/fileprogress.js');
js_include('js/swfupload/handlers.js');
js_include('js/setup_swf_upload.js');
// Set the lang_upload_swf_php language array for use in js
set_js_var('lang_upload_swf_php', $lang_upload_swf_php);
set_js_var('notify_admin', $CONFIG['upl_notify_admin_email']);
set_js_var('max_upl_size', $CONFIG['max_upl_size']);
list($timestamp, $form_token) = getFormToken();
set_js_var('timestamp', $timestamp);
set_js_var('form_token', $form_token);
}
js_include('js/upload.js');
//___________________________________Function Block_______________________________________
// The text box form input function. Takes the text label for the box, the input name, the maximum length for text boxes,
// and the number of iterations.
function text_box_input($text, $name, $max_length, $iterations, $default='')
{
global $CONFIG, $LINEBREAK;
$ordinal = '';
if (($text == '') and ($iterations == '')) {
echo ' ' . $LINEBREAK;
return;
}
// Begin loop
for ($counter=0; $counter<$iterations; $counter++) {
// Create a numbering system when necessary.
if ($text == '') {
$cardinal = $counter + 1;
$ordinal = "".$cardinal.". ";
}
// Create a text box.
echo <<
$text $ordinal
EOT;
}
}
// The file input function. Takes the label, field name, and number of iterations as arguments.
function file_input($text, $name, $iterations)
{
$ordinal = '';
// Begin loop
for ($counter=0; $counter<$iterations; $counter++) {
// Create a numbering system when necessary.
if ($text == '') {
$cardinal = $counter + 1;
$ordinal = "".$cardinal.". ";
}
// Create the file input box.
echo <<
$text $ordinal
EOT;
}
}
// The function for text areas on forms. Takes the label, field name, and maximum length as arguments.
function text_area_input($text, $name, $max_length,$default='')
{
// Create the text area.
echo <<
$text
EOT;
}
// The hidden form input function. Takes the hidden input field name and value.
function hidden_input($name, $value)
{
echo <<
EOT;
}
// The form label creation function. Takes a non-array element form $data as its argument.
function form_label($text)
{
echo <<
$text
EOT;
}
// Creates the album list drop down
function form_alb_list_box($text, $name)
{
global $lang_common;
$superCage = Inspekt::makeSuperCage();
if ($superCage->get->keyExists('album')) {
$sel_album = $superCage->get->getInt('album');
} elseif ($superCage->post->keyExists('album')) {
$sel_album = $superCage->post->getInt('album');
} else {
$sel_album = 0;
}
$options = album_selection_options($sel_album);
if (function_exists('hidden_features_only_empty_albums_button')) {
$only_empty_albums = hidden_features_only_empty_albums_button();
} else {
$only_empty_albums = '';
}
echo <<
$text
$only_empty_albums
EOT;
}
function form_instructions()
{
global $lang_upload_php, $max_file_size;
$max_fsize = sprintf($lang_upload_php['max_fsize'], cpg_format_bytes($max_file_size));
echo <<< EOT
EOT;
}
// The create form function for simple uploading, one file at a time.
// Takes the $data array as its object.
// Type:
// 0 => text box input
// 1 => file input
// 2 => album list
// 3 => text area input
// 4 => hidden input
function create_form_simple(&$data)
{
global $CONFIG, $lang_upload_php;
// Cycle through the elements in the data array.
foreach($data as $element) {
// If the element is another array, parse the definition contained within the array.
if ((is_array($element))) {
$element[2] = (isset($element[2])) ? $element[2] : '';
$element[3] = (isset($element[3])) ? $element[3] : '';
$element[4] = (isset($element[4])) ? $element[4] : '';
// Based on the type declared in the data array's third position, create a different form input.
switch ($element[2]) {
// If the type is a text box input
case 0 :
//Call the form input function.
text_box_input($element[0], $element[1], $element[3], $element[4], (isset($element[5])) ? $element[5] : '');
break;
// If the type is a file input.
case 1 :
// Call the file input function.
file_input($element[0], $element[1], $element[3]);
break;
// If the type is an album list dropdown.
case 2 :
// Call the album list function.
form_alb_list_box($element[0], $element[1]);
break;
// If the type is a text area
case 3 :
// Call the text area function.
text_area_input($element[0], $element[1], $element[3], (isset($element[4])) ? $element[4] : '');
break;
// If the type is a hidden form
case 4 :
// Call the hidden input funtion.
hidden_input($element[0], $element[1]);
break;
// If the type is not present, kill the script.
default:
cpg_die(ERROR, $lang_upload_php['reg_instr_1'], __FILE__, __LINE__);
} // switch
} else {
// If the element is not an array, it is a label, so call the label function.
form_label($element);
}
}
}
// Function to create the swfupload form
function create_form_swfupload()
{
global $lang_common, $lang_upload_swf_php, $icon_array;
form_alb_list_box($lang_common['album'], 'album');
echo <<
{$lang_upload_swf_php['upload_queue']}
0 {$lang_upload_swf_php['files_uploaded']}:
EOT;
}
// Creates Javascript verification code and opening form tags
// $path --> path to the form action script
function open_form($path)
{
global $upload_form;
$on_submit = '';
if ('swfupload' == $upload_form) {
$on_submit = 'onsubmit="cpgUploadToggleProgressBar();"';
}
echo <<
function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}