Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@daylightstudio authored
View
28 fuel/application/helpers/MY_date_helper.php
@@ -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;
+ }
+}
+
// --------------------------------------------------------------------
View
58 fuel/modules/fuel/controllers/module.php
@@ -672,46 +672,46 @@ protected function _process()
// loop through uploaded files
if (!empty($_FILES))
{
- foreach($_FILES as $file => $file_info)
+ foreach ($_FILES as $file => $file_info)
{
if ($file_info['error'] == 0)
{
$posted[$file] = $file_info['name'];
$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 (substr($file_tmp, ($file_tmp - 7)) == '_upload')
- {
+ if (substr($file_tmp, ($file_tmp - 7)) == '_upload') {
$field_name = substr($file_tmp, 0, ($file_tmp - 7));
+ }
- if (isset($posted[$file_tmp.'_filename']))
- {
- // get file extension
- $path_info = pathinfo($file_info['name']);
- $field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension'];
- }
- else
- {
- $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);
+ if (isset($posted[$file_tmp.'_filename']))
+ {
+ // get file extension
+ $path_info = pathinfo($file_info['name']);
+ $field_value = $posted[$file_tmp.'_filename'].'.'.$path_info['extension'];
+ }
+ else
+ {
+ $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);
}
}
}
View
15 fuel/modules/user_guide/views/helpers/my_date_helper.php
@@ -97,6 +97,21 @@
// returns <?=date_range_string((time() - (24*60*60)), time())?>
</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>
<p>Creates a string based on how long from the current time the date provided.</p>
Please sign in to comment.
Something went wrong with that request. Please try again.