Skip to content

Commit

Permalink
Merge pull request #126 from specialbrand/master
Browse files Browse the repository at this point in the history
Fix for uploaded files with field names that don't match the "*_upload" suffix.
Added new date_range_array() helper method & docs update.
  • Loading branch information
David McReynolds committed Mar 3, 2012
2 parents 18faa92 + 90b44f6 commit 8ffe68e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 29 deletions.
28 changes: 28 additions & 0 deletions fuel/application/helpers/MY_date_helper.php
Expand Up @@ -311,6 +311,34 @@ function date_range_string($date1, $date2)
} }




// --------------------------------------------------------------------

/**
* Creates an array containing a date range
*
* @access public
* @param string $start, any format that strtotime accepts
* @param string $end, any format that strtotime accepts
* @param string $increments, any format that strtotime accepts
* @param string $output_format, default output format is YYYY-MM-DD
* @return array
*/
function date_range_array($start = 'now', $end = '+1 year', $output_format = 'Y-m-d', $increments = '+1 month')
{
if (isset($start, $end, $output_format, $increments))
{
$current = strtotime($start);
$end = strtotime($end);
$date_range_array = array();
while ($current <= $end)
{
$date_range_array[] = date($output_format, $current);
$current = strtotime($increments, $current);
}
return $date_range_array;
}
}



// -------------------------------------------------------------------- // --------------------------------------------------------------------


Expand Down
58 changes: 29 additions & 29 deletions fuel/modules/fuel/controllers/module.php
Expand Up @@ -672,46 +672,46 @@ protected function _process()
// loop through uploaded files // loop through uploaded files
if (!empty($_FILES)) if (!empty($_FILES))
{ {
foreach($_FILES as $file => $file_info) foreach ($_FILES as $file => $file_info)
{ {
if ($file_info['error'] == 0) if ($file_info['error'] == 0)
{ {
$posted[$file] = $file_info['name']; $posted[$file] = $file_info['name'];


$file_tmp = current(explode('___', $file)); $file_tmp = current(explode('___', $file));
$field_name = $file_tmp;


// if there is a field with the suffix of _upload, then we will overwrite that posted value with this value // if there is a field with the suffix of _upload, then we will overwrite that posted value with this value
if (substr($file_tmp, ($file_tmp - 7)) == '_upload') if (substr($file_tmp, ($file_tmp - 7)) == '_upload') {
{
$field_name = substr($file_tmp, 0, ($file_tmp - 7)); $field_name = substr($file_tmp, 0, ($file_tmp - 7));
}


if (isset($posted[$file_tmp.'_filename'])) if (isset($posted[$file_tmp.'_filename']))
{ {
// get file extension // get file extension
$path_info = pathinfo($file_info['name']); $path_info = pathinfo($file_info['name']);
$field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension']; $field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension'];
} }
else else
{ {
$field_value = $file_info['name']; $field_value = $file_info['name'];
}
// FIX ME....
// foreach($_POST as $key => $val)
// {
// $tmp_key = end(explode('--', $key));
// $_POST[$tmp_key] = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$_POST['\\2'].'\\3'", $val);
// }

if (strpos($field_value, '{') !== FALSE )
{
$field_value = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$posted['\\2'].'\\3'", $field_value);
}

// set both values for the namespaced and non-namespaced... make them underscored and lower cased
$tmp_field_name = end(explode('--', $field_name));
$posted[$tmp_field_name] = url_title($field_value, 'underscore', TRUE);
$posted[$field_name] = url_title($field_value, 'underscore', TRUE);
} }
// FIX ME....
// foreach($_POST as $key => $val)
// {
// $tmp_key = end(explode('--', $key));
// $_POST[$tmp_key] = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$_POST['\\2'].'\\3'", $val);
// }

if (strpos($field_value, '{') !== FALSE )
{
$field_value = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$posted['\\2'].'\\3'", $field_value);
}

// set both values for the namespaced and non-namespaced... make them underscored and lower cased
$tmp_field_name = end(explode('--', $field_name));
$posted[$tmp_field_name] = url_title($field_value, 'underscore', TRUE);
$posted[$field_name] = url_title($field_value, 'underscore', TRUE);
} }
} }
} }
Expand Down
15 changes: 15 additions & 0 deletions fuel/modules/user_guide/views/helpers/my_date_helper.php
Expand Up @@ -97,6 +97,21 @@
// returns <?=date_range_string((time() - (24*60*60)), time())?> // returns <?=date_range_string((time() - (24*60*60)), time())?>
</pre> </pre>


<h2>date_range_array(<var>start_date</var>, <var>end_date</var>, <var>[output_format]</var>, <var>[increment]</var>)</h2>
<p>Creates a date range array (e.g. array('2011-01-01', '2011-02-01', '2011-03-01', ...)).</p>

<h3>Example #1 date_range_array() example without extra params set</h3>
<pre class="brush: php">
date_range_array('2011-01-01', '2011-04-01');
// returns array('2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01')
</pre>

<h3>Example #2 date_range_array() example with all params set</h3>
<pre class="brush: php">
date_range_array('2005-01-01', '2008-01-01', 'M Y', '+1 year');
// returns array('Jan 2005', 'Jan 2006', 'Jan 2007', 'Jan 2008')
</pre>



<h2>pretty_date(<var>timestamp</var>, <var>use_gmt</var>)</h2> <h2>pretty_date(<var>timestamp</var>, <var>use_gmt</var>)</h2>
<p>Creates a string based on how long from the current time the date provided.</p> <p>Creates a string based on how long from the current time the date provided.</p>
Expand Down

0 comments on commit 8ffe68e

Please sign in to comment.