Skip to content
This repository
Browse code

Merge pull request #126 from specialbrand/master

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...
commit 8ffe68efd08cbcf781456c993e3f49d95edd7535 2 parents 18faa92 + 90b44f6
David McReynolds authored
28 fuel/application/helpers/MY_date_helper.php
@@ -311,6 +311,34 @@ function date_range_string($date1, $date2)
311 311 }
312 312
313 313
  314 +// --------------------------------------------------------------------
  315 +
  316 +/**
  317 + * Creates an array containing a date range
  318 + *
  319 + * @access public
  320 + * @param string $start, any format that strtotime accepts
  321 + * @param string $end, any format that strtotime accepts
  322 + * @param string $increments, any format that strtotime accepts
  323 + * @param string $output_format, default output format is YYYY-MM-DD
  324 + * @return array
  325 + */
  326 +function date_range_array($start = 'now', $end = '+1 year', $output_format = 'Y-m-d', $increments = '+1 month')
  327 +{
  328 + if (isset($start, $end, $output_format, $increments))
  329 + {
  330 + $current = strtotime($start);
  331 + $end = strtotime($end);
  332 + $date_range_array = array();
  333 + while ($current <= $end)
  334 + {
  335 + $date_range_array[] = date($output_format, $current);
  336 + $current = strtotime($increments, $current);
  337 + }
  338 + return $date_range_array;
  339 + }
  340 +}
  341 +
314 342
315 343 // --------------------------------------------------------------------
316 344
58 fuel/modules/fuel/controllers/module.php
@@ -672,46 +672,46 @@ protected function _process()
672 672 // loop through uploaded files
673 673 if (!empty($_FILES))
674 674 {
675   - foreach($_FILES as $file => $file_info)
  675 + foreach ($_FILES as $file => $file_info)
676 676 {
677 677 if ($file_info['error'] == 0)
678 678 {
679 679 $posted[$file] = $file_info['name'];
680 680
681 681 $file_tmp = current(explode('___', $file));
  682 + $field_name = $file_tmp;
682 683
683 684 // if there is a field with the suffix of _upload, then we will overwrite that posted value with this value
684   - if (substr($file_tmp, ($file_tmp - 7)) == '_upload')
685   - {
  685 + if (substr($file_tmp, ($file_tmp - 7)) == '_upload') {
686 686 $field_name = substr($file_tmp, 0, ($file_tmp - 7));
  687 + }
687 688
688   - if (isset($posted[$file_tmp.'_filename']))
689   - {
690   - // get file extension
691   - $path_info = pathinfo($file_info['name']);
692   - $field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension'];
693   - }
694   - else
695   - {
696   - $field_value = $file_info['name'];
697   - }
698   - // FIX ME....
699   - // foreach($_POST as $key => $val)
700   - // {
701   - // $tmp_key = end(explode('--', $key));
702   - // $_POST[$tmp_key] = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$_POST['\\2'].'\\3'", $val);
703   - // }
704   -
705   - if (strpos($field_value, '{') !== FALSE )
706   - {
707   - $field_value = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$posted['\\2'].'\\3'", $field_value);
708   - }
709   -
710   - // set both values for the namespaced and non-namespaced... make them underscored and lower cased
711   - $tmp_field_name = end(explode('--', $field_name));
712   - $posted[$tmp_field_name] = url_title($field_value, 'underscore', TRUE);
713   - $posted[$field_name] = url_title($field_value, 'underscore', TRUE);
  689 + if (isset($posted[$file_tmp.'_filename']))
  690 + {
  691 + // get file extension
  692 + $path_info = pathinfo($file_info['name']);
  693 + $field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension'];
  694 + }
  695 + else
  696 + {
  697 + $field_value = $file_info['name'];
714 698 }
  699 + // FIX ME....
  700 + // foreach($_POST as $key => $val)
  701 + // {
  702 + // $tmp_key = end(explode('--', $key));
  703 + // $_POST[$tmp_key] = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$_POST['\\2'].'\\3'", $val);
  704 + // }
  705 +
  706 + if (strpos($field_value, '{') !== FALSE )
  707 + {
  708 + $field_value = preg_replace('#(.*){(.+)\}(.*)#e', "'\\1'.\$posted['\\2'].'\\3'", $field_value);
  709 + }
  710 +
  711 + // set both values for the namespaced and non-namespaced... make them underscored and lower cased
  712 + $tmp_field_name = end(explode('--', $field_name));
  713 + $posted[$tmp_field_name] = url_title($field_value, 'underscore', TRUE);
  714 + $posted[$field_name] = url_title($field_value, 'underscore', TRUE);
715 715 }
716 716 }
717 717 }
15 fuel/modules/user_guide/views/helpers/my_date_helper.php
@@ -97,6 +97,21 @@
97 97 // returns <?=date_range_string((time() - (24*60*60)), time())?>
98 98 </pre>
99 99
  100 +<h2>date_range_array(<var>start_date</var>, <var>end_date</var>, <var>[output_format]</var>, <var>[increment]</var>)</h2>
  101 +<p>Creates a date range array (e.g. array('2011-01-01', '2011-02-01', '2011-03-01', ...)).</p>
  102 +
  103 +<h3>Example #1 date_range_array() example without extra params set</h3>
  104 +<pre class="brush: php">
  105 +date_range_array('2011-01-01', '2011-04-01');
  106 +// returns array('2011-01-01', '2011-02-01', '2011-03-01', '2011-04-01')
  107 +</pre>
  108 +
  109 +<h3>Example #2 date_range_array() example with all params set</h3>
  110 +<pre class="brush: php">
  111 +date_range_array('2005-01-01', '2008-01-01', 'M Y', '+1 year');
  112 +// returns array('Jan 2005', 'Jan 2006', 'Jan 2007', 'Jan 2008')
  113 +</pre>
  114 +
100 115
101 116 <h2>pretty_date(<var>timestamp</var>, <var>use_gmt</var>)</h2>
102 117 <p>Creates a string based on how long from the current time the date provided.</p>

0 comments on commit 8ffe68e

Please sign in to comment.
Something went wrong with that request. Please try again.