public
Description: PHP Framework
Homepage: http://phpcomodo.com
Clone URL: git://github.com/ecentinela/comodo.git
Reestructuration done.
All active support files has documentation and has been revised to not use any 
past plugin.
ecentinela (author)
Sun Jul 13 02:56:09 -0700 2008
commit  193614c0eafc9f0c98773c16eff3ca8d987bd517
tree    5f3187de603885579330fee7628d898793e58c9c
parent  1ccc469206a91169de2b5945e42f63e8af40d302
...
361
362
363
364
 
365
366
367
...
584
585
586
587
 
588
589
590
...
361
362
363
 
364
365
366
367
...
584
585
586
 
587
588
589
590
0
@@ -361,7 +361,7 @@ class Controller {
0
   final static function get_instance($controller = false, $action = false, $respond_type, $parameters) {
0
     static $_this = false;
0
     if (empty($_this)) {
0
-      $controller_class = camelize($controller) . 'Controller';
0
+      $controller_class = Inflector::camelize($controller) . 'Controller';
0
       if (!class_exists($controller_class))
0
         die('<h1>Unknown controller</h1>No controller responded to ' . $controller);
0
       $_this = new $controller_class($controller, $action, $respond_type, $parameters);
0
@@ -584,7 +584,7 @@ class Controller {
0
   # * message: the message to save on the log file.
0
   final private function to_log($message) {
0
     if ($this->_log || Environment::environment == 'development')
0
-      Logger::save($message);
0
+      app_log($message);
0
   }
0
 
0
   # before_controller
...
166
167
168
169
 
170
171
172
173
 
174
175
176
...
264
265
266
267
 
268
269
270
271
272
 
273
274
275
...
166
167
168
 
169
170
171
172
 
173
174
175
176
...
264
265
266
 
267
268
269
270
271
 
272
273
274
275
0
@@ -166,11 +166,11 @@ abstract class Route {
0
         if (count($named_routes) == 0)
0
           trigger_error('Named route: ' . $params . ' not found', E_USER_ERROR);
0
         else
0
-          return array_first(array_keys($named_routes));
0
+          return array_shift(array_keys($named_routes));
0
       }
0
     }
0
     else {
0
-      $name = array_first(array_keys($params));
0
+      $name = array_shift(array_keys($params));
0
       if (is_array($params[$name])) {
0
         $params = $params[$name];
0
         $map_connections = self::get_named_routes($name);
0
@@ -264,12 +264,12 @@ abstract class Route {
0
         $url = array();
0
         $short_index = true;
0
         foreach (array_reverse($url_params) as $i => $param)
0
-          if (!$short_index || $param != 'index' || ($params['anchor'] && $i > 0)) {
0
+          if (!$short_index || $param != 'index' || (isset($params['anchor']) && $i > 0)) {
0
             $url[] = $param;
0
             $short_index = false;
0
           }
0
         $url = array_reverse($url);
0
-        return (isset($params['subdomain']) ? 'http://' . $params['subdomain'] . '.' . $_SERVER['server_addr'] : '') . '/' . implode('/', $url) . (isset($params['params']) ? '?' . http_build_query($params['params']) : '') . (isset($params['anchor']) ? '#' . $params['anchor'] : '');
0
+        return (isset($params['subdomain']) ? 'http://' . $params['subdomain'] . '.' . $_SERVER['SERVER_ADDR'] : '') . '/' . implode('/', $url) . (isset($params['params']) ? '?' . http_build_query($params['params']) : '') . (isset($params['anchor']) ? '#' . $params['anchor'] : '');
0
       }
0
     }
0
     trigger_error('Can\'t create a route from the given parameters', E_USER_WARNING);
...
39
40
41
42
 
43
44
45
46
47
 
48
49
50
...
39
40
41
 
42
43
44
45
46
 
47
48
49
50
0
@@ -39,12 +39,12 @@ class Database {
0
     foreach ($this->database->cache as $cache)
0
       if ($cache['query'] == $query && $cache['values'] == $values) {
0
         if (Environment::environment != 'production')
0
-          Logger::save('   Recovered from database cache:   ' . $query . ' ' . json_encode($values));
0
+          app_log('   Recovered from database cache:   ' . $query . ' ' . json_encode($values));
0
         return $cache['data'];
0
       }
0
     $time = microtime(true);
0
     if (Environment::environment != 'production')
0
-      Logger::save('   ' . $query . ' ' . json_encode($values));
0
+      app_log('   ' . $query . ' ' . json_encode($values));
0
 
0
     $data = $this->database->_query($query, $values);
0
     $this->database->time += microtime(true) - $time;
...
6
7
8
9
 
10
11
12
...
328
329
330
331
 
332
333
334
...
418
419
420
421
 
422
423
424
...
769
770
771
772
773
774
775
776
...
6
7
8
 
9
10
11
12
...
328
329
330
 
331
332
333
334
...
418
419
420
 
421
422
423
424
...
769
770
771
 
 
 
772
773
0
@@ -6,7 +6,7 @@ abstract class activeRecordBase extends activeRecordBelongsTo {
0
   # __call($method, $args)
0
   # ======================
0
   #
0
-  # **__call** is a *magic method* included in [PHP5][PHP].
0
+  # **__call** is a *magic method* included in PHP5.
0
   #
0
   # If you call a method on an object and this method doesn't exist, **PHP** will fail
0
   # to find the function and check whether you have defined a **__call()** function.
0
@@ -328,7 +328,7 @@ abstract class activeRecordBase extends activeRecordBelongsTo {
0
     $this->establish_connection();
0
     $this->_class_name = get_class($this);
0
     if (empty($this->_table_name))
0
-      $this->_table_name = Inflector::table_of($this->_class_name);
0
+      $this->_table_name = Inflector::tableize($this->_class_name);
0
     foreach (array_diff($this->columns(), array_keys($attributes)) as $field)
0
       $this->_attributes[$field] = $this->default_of_attribute($field);
0
     $this->attributes($attributes, $avoid_protected_attributes);
0
@@ -418,7 +418,7 @@ abstract class activeRecordBase extends activeRecordBelongsTo {
0
   # ===================================
0
   #
0
   # Updates the attribute with the specified value.
0
-  # This and set_<attribute> are the way to set attributes on [protected_attributes][_attr_protected].
0
+  # This and set_<attribute> are the way to set attributes on protected_attributes.
0
   #
0
   #
0
   #
0
@@ -769,7 +769,4 @@ abstract class activeRecordBase extends activeRecordBelongsTo {
0
 
0
 }
0
 
0
-# [PHP]: http://php.net "PHP site"
0
-# [_attr_protected]: /documentation/show/active_record#_attr_protected "Attr. protected"
0
-
0
 ?>
0
\ No newline at end of file
...
76
77
78
79
 
80
81
82
...
76
77
78
 
79
80
81
82
0
@@ -76,7 +76,7 @@ abstract class activeRecordCalculations extends activeRecordCallbacks {
0
       return $this->_connection->query($query, $values);
0
     }
0
     $query = $this->construct_calculation_sql($operation, $column_name, $options, $values);
0
-    return array_first(array_first($this->_connection->query($query, $values)));
0
+    return array_shift(array_shift($this->_connection->query($query, $values)));
0
   }
0
 
0
   # USED INTERNALLY
...
227
228
229
230
 
231
232
233
...
500
501
502
503
 
504
505
506
...
227
228
229
 
230
231
232
233
...
500
501
502
 
503
504
505
506
0
@@ -227,7 +227,7 @@ abstract class activeRecordFind extends activeRecordHasAndBelonsToMany {
0
     $action = $coincidences[1];
0
     foreach (explode('_and_', $coincidences[2]) as $index => $field)
0
       $by_arguments['conditions'][$field] = $args[$index];
0
-    $arguments = count($args) == count($by_arguments['conditions']) ? $by_arguments : array_merge(array_last($args), $by_arguments);
0
+    $arguments = count($args) == count($by_arguments['conditions']) ? $by_arguments : array_merge(array_pop($args), $by_arguments);
0
     if ($action == 'find_all_by_')
0
       return $this->find('all', $arguments);
0
     else {
0
@@ -500,7 +500,7 @@ abstract class activeRecordFind extends activeRecordHasAndBelonsToMany {
0
   # stringify_ids_conditions($ids, $fields, $sql, $values)
0
   # ======================================================
0
   final protected function stringify_ids_conditions($ids, $field, &$conditions, &$values) {
0
-    $ids = splat($ids);
0
+    $ids = (array)$ids;
0
     $i = count($ids);
0
     if ($i > 0) {
0
       $conditions[] = $field . ($i == 1 ? ' = ?' : ' IN (?' . str_repeat(', ?', $i - 1) . ')');
...
67
68
69
70
 
71
72
73
...
67
68
69
 
70
71
72
73
0
@@ -67,7 +67,7 @@ abstract class activeRecordHasMany extends activeRecordHasOne {
0
   # * An associative array with all posible options.
0
   final protected function get_options_for_has_many($key) {
0
     $lower_class_name = strtolower($this->_class_name);
0
-    $base_options = array('class_name' => Inflector::class_of($key), 'foreign_key' => $lower_class_name . '_id', 'through' => false, 'as' => false, 'source' => false, 'source_type' => $lower_class_name, 'dependent' => 'nullify', 'finder_sql' => false, 'select' => false, 'include' => array(), 'joins' => false, 'conditions' => false, 'order' => false, 'group' => false, 'having' => false, 'limit' => false, 'offset' => false, 'lock' => false);
0
+    $base_options = array('class_name' => Inflector::classify($key), 'foreign_key' => $lower_class_name . '_id', 'through' => false, 'as' => false, 'source' => false, 'source_type' => $lower_class_name, 'dependent' => 'nullify', 'finder_sql' => false, 'select' => false, 'include' => array(), 'joins' => false, 'conditions' => false, 'order' => false, 'group' => false, 'having' => false, 'limit' => false, 'offset' => false, 'lock' => false);
0
     foreach ($this->_has_many as $relation => $options)
0
       if ($options == $key)    return $base_options;
0
       elseif ($relation === $key)  return array_merge($base_options, $options);
...
65
66
67
68
 
69
70
71
...
65
66
67
 
68
69
70
71
0
@@ -65,7 +65,7 @@ abstract class activeRecordHasOne extends activeRecordRelations {
0
   # * An associative array with all posible options.
0
   final protected function get_options_for_has_one($key) {
0
     $lower_class_name = strtolower($this->_class_name);
0
-    $base_options = array('class_name' => Inflector::class_of($key), 'foreign_key' => $lower_class_name . '_id', 'through' => false, 'as' => false, 'source' => false, 'source_type' => $lower_class_name, 'dependent' => 'nullify', 'finder_sql' => false, 'select' => false, 'include' => array(), 'joins' => false, 'conditions' => false, 'order' => false, 'group' => false, 'having' => false, 'limit' => false, 'offset' => false, 'lock' => false);
0
+    $base_options = array('class_name' => Inflector::classify($key), 'foreign_key' => $lower_class_name . '_id', 'through' => false, 'as' => false, 'source' => false, 'source_type' => $lower_class_name, 'dependent' => 'nullify', 'finder_sql' => false, 'select' => false, 'include' => array(), 'joins' => false, 'conditions' => false, 'order' => false, 'group' => false, 'having' => false, 'limit' => false, 'offset' => false, 'lock' => false);
0
     foreach ($this->_has_one as $relation => $options)
0
       if ($options == $key)    return $base_options;
0
       elseif ($relation === $key)  return array_merge($base_options, $options);
...
18
19
20
21
 
22
23
24
...
40
41
42
 
43
44
45
...
71
72
73
 
 
74
75
76
...
81
82
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
85
86
...
142
143
144
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
147
148
149
150
151
152
 
153
154
155
156
157
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
163
 
164
165
166
...
18
19
20
 
21
22
23
24
...
40
41
42
43
44
45
46
...
72
73
74
75
76
77
78
79
...
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
...
161
162
163
 
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
 
185
186
187
188
189
190
191
 
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
 
211
212
213
214
0
@@ -18,7 +18,7 @@
0
 # Arguments
0
 # ---------
0
 #
0
-# * object: the object to convert to an array
0
+# * object: the object to convert to an array.
0
 # * fields: the fields to get back. If no fields are given all valid fields on the object will be returned.
0
 #
0
 #
0
@@ -40,6 +40,7 @@
0
 #
0
 #  Array
0
 #  (
0
+#    'id' => 5,
0
 #    'name' => 'John',
0
 #    'surname' => 'Smith',
0
 #    'age' => 24
0
@@ -71,6 +72,8 @@ function object_to_array() {
0
   $object = array_shift($fields);
0
   if (count($fields) == 0)
0
     $fields = $object->columns();
0
+  elseif (is_array($fields[0]))
0
+    $fields = $fields[0];
0
   $data = array();
0
   foreach ($fields as $field)
0
     $data[$field] = $object->$field;
0
@@ -81,6 +84,22 @@ function object_to_array() {
0
 # ==================
0
 #
0
 # Converts the given array of objects to an array of associative arrays.
0
+# It works like object_to_array() but receives an array of objects and returns an array of arrays.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * objects: an array of objects to convert to an array.
0
+# * fields: the fields to get back. If no fields are given all valid fields on the object will be returned.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * an array filled with arrays with the given or all object's fields.
0
 function objects_to_array() {
0
   $fields = func_get_args();
0
   $objects = array_shift($fields);
0
@@ -142,25 +161,54 @@ function valid_fields($object) {
0
 # error_messages_for($object)
0
 # ===========================
0
 #
0
-# Prints the errors on the given object after a save.
0
+# Prints HTML formatted errors on the given object after a save.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The object to extract the errors.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string containing all html data about the object or false if no errors exists.
0
 function error_messages_for($object) {
0
   $i = $object->count_validation_errors();
0
   if (!$i) return false;
0
   $content = '<div class="error_messages"><h2>' . $i . ' errors prohibited this ' . $object->_class_name . ' of being saved</h2><ul>';
0
   foreach ($object->get_validation_errors() as $field => $errors)
0
     foreach ($errors as $error_message)
0
-      $content .= '<li>' . humanize($field) . ' ' . $error_message . '</li>';
0
+      $content .= '<li>' . ($field) . ' ' . $error_message . '</li>';
0
   return $content .= '</ul></div>';
0
 }
0
 
0
 # error_messages_on($object, $field)
0
 # ==================================
0
 #
0
-# Prints the errors on the specified field after a save.
0
+# Prints HTML formatted errors on the specified object's field after a save.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The object to extract the errors.
0
+# * field: The object's field to extract the errors.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string containing all html data about the object or false if no errors exists.
0
 function error_messages_on($object, $field) {
0
   $i = $object->count_validation_errors_on($field);
0
   if (!$i) return false;
0
-  $content = '<div class="error_messages"><h2>' . $i . ' errors on field ' . humanize($field) . '</h2><ul>';
0
+  $content = '<div class="error_messages"><h2>' . $i . ' errors on field ' . ($field) . '</h2><ul>';
0
   foreach ($object->get_validation_errors_on($field) as $error)
0
     foreach ($error as $error_message)
0
       $content .= '<li>' . capitalize($error_message) . '</li>';
...
11
12
13
14
15
 
 
16
17
18
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
85
86
87
88
89
90
91
92
 
 
 
 
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
...
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
110
111
112
113
114
115
 
116
117
118
119
120
121
122
123
124
...
11
12
13
 
 
14
15
16
17
18
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
 
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
 
 
 
 
 
 
 
 
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
 
189
190
191
192
 
 
 
 
193
194
0
@@ -11,8 +11,8 @@
0
 # ---------
0
 #
0
 # * char: The character to join the element fields.
0
-# * array: The input array.
0
-# * field: The field to join on every array element.
0
+# * array: The input array. It can be an array of arrays or an array of objects.
0
+# * field: The field to join on every array or object element.
0
 #
0
 #
0
 #
0
@@ -26,72 +26,128 @@ function field_implode($char, $array, $field) {
0
   return implode($char, $string);
0
 }
0
 
0
-function array_include($value, $data) {
0
-  if (!in_array($value, $data))
0
-    array_push($data, $value);
0
-  return $data;
0
-}
0
-
0
-function array_remove($value, $data) {
0
-  $i = array_search($value, $data);
0
-  if ($i !== false)
0
-    array_splice($data, $i, 1);
0
-  return $data;
0
-}
0
-
0
-function array_without($values, $array, $reconstruct = false) {
0
-  if (!is_array($values) || !isset($values[0]))
0
-    $values = array($values);
0
-  if ($reconstruct) {
0
-    $data = array();
0
-    foreach ($array as $val)
0
-      if (!in_array($val, $values))
0
-        $data[] = $val;
0
-  }
0
-  else $data = array_diff($array, $values);
0
-  return $data;
0
-}
0
-
0
-function array_with_keys($keys, $array, $reconstruct = false) {
0
-  if (!is_array($keys) || !isset($keys[0]))
0
-    $keys = array($keys);
0
-  $data = array();
0
-  foreach ($array as $fld => $val)
0
-    if (in_array($fld, $keys))
0
-      if ($reconstruct)  $data[] = $val;
0
-      else         $data[$fld] = $val;
0
-  return $data;
0
-}
0
-
0
-function array_without_keys($keys, $array, $reconstruct = false) {
0
-  $keys = is_array($keys) ? $keys : array($keys);
0
-  $data = array();
0
-  foreach ($array as $fld => $val)
0
-    if (!in_array($fld, $keys))
0
-      if ($reconstruct)  $data[] = $val;
0
-      else         $data[$fld] = $val;
0
-  return $data;
0
+# array_include($value, $array)
0
+# =============================
0
+#
0
+# Includes the given value on the given array if not exists yet.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value to include if it doesn't exists in the array yet.
0
+# * array: The array where to include the value.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * the array with the value included or the source array if the value exists already.
0
+function array_include($value, $array) {
0
+  if (!in_array($value, $array))
0
+    $array[] = $value;
0
+  return $array;
0
 }
0
 
0
-function array_first($array) {
0
-  return array_shift($array);
0
+# array_remove($value, $array)
0
+# ============================
0
+#
0
+# Removes all ocurrences of the given value on the given array.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value to search on the array.
0
+# * array: The input array where to search for the value.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * the array without all $value ocurrences.
0
+function array_remove($value, $array) {
0
+  while (($i = array_search($value, $array)) !== false)
0
+    array_splice($array, $i, 1);
0
+  return $array;
0
 }
0
 
0
-function array_last($array) {
0
-  return array_pop($array);
0
+# array_replace($value, $new_value, $array)
0
+# =========================================
0
+#
0
+# Replaces all ocurrences of the given value for the given new_value on the given array.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value to search on the array.
0
+# * new_value: The new value to replace the given value.
0
+# * array: The input array where to search for the value.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * the array with all $value ocurrences replaced by the $new_value.
0
+function array_replace($value, $new_value, $array) {
0
+  while (($i = array_search($value, $array)) !== false)
0
+    array_splice($array, $i, 1, $new_value);
0
+  return $array;
0
 }
0
 
0
+# array_range($array, $from, $to = false)
0
+# =======================================
0
+#
0
+# Get an array range of the given array.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * array: The input array to create the range.
0
+# * from: The index where to start the array.
0
+# * to: The index where to stop the array range.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * The range array .
0
 function array_range($array, $from, $to = false) {
0
-  if (count($array) == 0)
0
-    return $array;
0
-  if (!$to)
0
-    $to = count($array) - 1;
0
-  $data = array();
0
-  for ($i = $from; $i <= $to; $i++)
0
-    $data[] = $array[$i];
0
-  return $data;
0
+  array_splice($array, 0, $from);
0
+  if ($to)
0
+    array_splice($array, ++$to - $from);
0
+  return $array;
0
 }
0
 
0
+# array_split_by($value, $array)
0
+# ==============================
0
+#
0
+# Splits the given array in many arrays splitted by the given value.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value to search on the array and split it.
0
+# * array: The input array to split.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * an array of arrays.
0
 function array_split_by($value, $array) {
0
   $data = array();
0
   $i = $x = 0;
0
@@ -106,18 +162,32 @@ function array_split_by($value, $array) {
0
   return $data;
0
 }
0
 
0
+# unidimensionalize($array)
0
+# =========================
0
+#
0
+# Convert the given array in one array unidimensional.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * array: The input array. It can be a unidimensional, multidimensional or nested multidimensional array.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * the array unidimensionalized.
0
 function unidimensionalize($array) {
0
   $data = array();
0
   foreach ($array as $value)
0
     if (is_array($value))
0
       $data = array_merge($data, unidimensionalize($value));
0
     else
0
-      array_push($data, $value);
0
+      $data[] = $value;
0
   return $data;
0
 }
0
 
0
-function splat($array) {
0
-  return is_array($array) ? $array : array($array);
0
-}
0
-
0
 ?>
0
\ No newline at end of file
...
3
4
5
6
 
7
8
9
10
11
12
13
 
14
15
16
...
38
39
40
 
 
 
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
51
52
53
54
55
56
57
58
59
 
 
 
 
 
 
60
61
 
62
63
64
65
66
67
68
69
70
71
 
 
 
 
 
 
 
 
 
72
73
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
76
77
78
79
 
80
81
 
 
 
82
83
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
106
 
 
 
107
108
109
110
111
112
113
114
115
116
 
 
 
 
 
 
 
 
 
 
 
 
 
117
118
119
120
...
3
4
5
 
6
7
8
9
10
11
12
 
13
14
15
16
...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
70
71
72
 
 
 
 
 
 
73
74
75
76
77
78
79
 
80
81
 
 
 
 
 
 
 
 
 
82
83
84
85
86
87
88
89
90
91
92
 
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
116
117
118
119
120
121
122
 
 
 
 
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
 
 
 
 
 
 
 
 
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
0
@@ -3,14 +3,14 @@
0
 # now()
0
 # =====
0
 #
0
-# Get the current time as integer.
0
+# Get the current time as integer (time without date).
0
 #
0
 #
0
 #
0
 # Returns
0
 # -------
0
 #
0
-# * an integer with the current time.
0
+# * an integer with the current time (not date).
0
 function now() {
0
   return time() - mktime(0, 0, 0, date('m'), date('d'), date('Y'));
0
 }
0
@@ -38,7 +38,26 @@ function time_ago_in_words($from_time, $include_seconds = true) {
0
   return distance_of_time_in_words($from_time, time(), $include_seconds);
0
 }
0
 
0
+# distance_of_time_in_words($from_time, $to_time = false, $include_seconds = true)
0
+# ================================================================================
0
+#
0
 # Prints the distance of time into to times in words.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * from_time: The time where to start to calculate.
0
+# * to_time: The time where to stop the calculation. If no value is given the actual time will be assigned.
0
+# * include_seconds: If include seconds on the string.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string containing the distance of time in words.
0
 function distance_of_time_in_words($from_time, $to_time = false, $include_seconds = true) {
0
   if (!is_numeric($from_time)) {
0
     get_datetime($from_time, $year, $month, $day, $hour, $minute, $second);
0
@@ -51,69 +70,150 @@ function distance_of_time_in_words($from_time, $to_time = false, $include_second
0
 
0
   if ($distance_in_minutes < 2) {
0
     if ($include_seconds) {
0
-      if ($distance_in_seconds < 5)     return t('less than %d seconds', 5);
0
-      elseif ($distance_in_seconds < 10)   return t('less than %d seconds', 10);
0
-      elseif ($distance_in_seconds < 20)   return t('less than %d seconds', 20);
0
-      elseif ($distance_in_seconds < 40)   return t('half a minute');
0
-      elseif ($distance_in_seconds < 60)   return t('less than a minute');
0
-      else                return '1 ' . t('minute');
0
+      if ($distance_in_seconds < 5)     return 'less than 5 seconds';
0
+      elseif ($distance_in_seconds < 10)   return 'less than 10 seconds';
0
+      elseif ($distance_in_seconds < 20)   return 'less than 20 seconds';
0
+      elseif ($distance_in_seconds < 40)   return 'half a minute';
0
+      elseif ($distance_in_seconds < 60)   return 'less than a minute';
0
+      else                return '1 minute';
0
     }
0
-    else                  return $distance_in_minutes == 0 ? t('less than a minute') : '1 ' . t('minute');
0
+    else                  return $distance_in_minutes == 0 ? 'less than a minute' : '1 minute';
0
   }
0
-  elseif ($distance_in_minutes < 45)      return $distance_in_minutes . ' ' . t('minutes');
0
-  elseif ($distance_in_minutes < 90)      return t('about a hour');
0
-  elseif ($distance_in_minutes < 1440)      return t('about %d hours', round($distance_in_minutes/60));
0
-  elseif ($distance_in_minutes < 2880)      return '1 ' . t('day');
0
-  elseif ($distance_in_minutes < 43200)    return round($distance_in_minutes/1440) . ' ' . t('days');
0
-  elseif ($distance_in_minutes < 86400)    return t('about a month');
0
-  elseif ($distance_in_minutes < 525960)    return t('about %d months', round($distance_in_minutes/43200));
0
-  elseif ($distance_in_minutes < 1051920)    return t('about a year');
0
-  else                    return t('about %d years', round($distance_in_minutes/525960));
0
+  elseif ($distance_in_minutes < 45)      return $distance_in_minutes . ' minutes';
0
+  elseif ($distance_in_minutes < 90)      return 'about a hour';
0
+  elseif ($distance_in_minutes < 1440)    return 'about ' . round($distance_in_minutes/60) . ' hours';
0
+  elseif ($distance_in_minutes < 2880)    return '1 day';
0
+  elseif ($distance_in_minutes < 43200)    return round($distance_in_minutes/1440) . ' days';
0
+  elseif ($distance_in_minutes < 86400)    return 'about a month';
0
+  elseif ($distance_in_minutes < 525960)    return 'about ' . round($distance_in_minutes/43200) . ' months';
0
+  elseif ($distance_in_minutes < 1051920)    return 'about a year';
0
+  else                    return 'about ' . round($distance_in_minutes/525960) . ' years';
0
 }
0
 
0
-# Return the number of days in the given month.
0
+# days_in_month($month, $year = false)
0
+# ====================================
0
+#
0
+# Get the number of days in the given month. Useful for leap years.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * month: The month to return the number of days. Starting with 0 => January.
0
+# * year: Specify a year. If no year is given, the actual year will be assigned.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * an integer with the number of days on the given month and year.
0
 function days_in_month($month, $year = false) {
0
   if (empty($year)) $year = date('Y');
0
   if ($month == 2)    return !empty($year) && (fmod($year, 4) == 0) && ((fmod($year, 100) != 0) || (fmod($year, 400) == 0)) ?  29 : 28;
0
   elseif ($month <= 7)  return fmod($month, 2) == 0 ? 30 : 31;
0
-  else        return fmod($month, 2) == 0 ? 31 : 30;
0
+  else          return fmod($month, 2) == 0 ? 31 : 30;
0
 }
0
 
0
+# get_datetime($value, &$year, &$month, &$day, &$hour, &$minute, &$second)
0
+# ========================================================================
0
+#
0
 # Gets the values for the datetime value in a separate way.
0
-# Return every value by reference.
0
-function get_datetime($value, &$year, &$month, &$day, &$hour, &$minute, &$second) {
0
-  if (!get_date($value, $year, $month, $day))     return false;
0
-  if (!get_time($value, $hour, $minute, $second))  return false;
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * date: The date to parse.
0
+# * year: A variable to store the year (by reference).
0
+# * month: A variable to store the month (by reference).
0
+# * day: A variable to store the day (by reference).
0
+# * hour: A variable to store the hours (by reference).
0
+# * minute: A variable to store the minutes (by reference).
0
+# * second: A variable to store the seconds (by reference).
0
+# * date_format: The format of the date string.
0
+function get_datetime($value, &$year, &$month, &$day, &$hour, &$minute, &$second, $date_format = '%Y/%m/%d') {
0
+  get_date($value, $year, $month, $day, $date_format);
0
+  get_time($value, $hour, $minute, $second);
0
 }
0
 
0
+# strToDate($date, $format = '%Y/%m/%d')
0
+# ======================================
0
+#
0
+# Convert the given date in the given format to an array containing every date value (year/month/day).
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * date: The date string to parse.
0
+# * format: The format of the date string.
0
+function strToDate($date, $format = '%Y/%m/%d') {
0
+  $search = array('%d', '%D', '%j', '%m', '%M', '%n', '%Y', '%y');
0
+  $replace = array('(\d{2})', '(\w{3})', '(\d{1,2})', '(\d{2})', '(\w{3})', '(\d{1,2})', '(\d{4})', '(\d{2})');
0
+
0
+  $pattern = str_replace($search, $replace, $format);
0
+
0
+  preg_match("#$pattern#", $date, $matches);
0
+  $dp = $matches;
0
+
0
+  preg_match_all('#%(\w)#', $format, $matches);
0
+  $id = $matches['1'];
0
+
0
+  $ret = array();
0
+  for ($i = 0, $j = count($id); $i < $j; $i++)
0
+    $ret[$id[$i]] = $dp[$i + 1];
0
+
0
+  return $ret;
0
+}
0
+
0
+# get_date($date, &$year, &$month, &$day, $date_format = '%Y/%m/%d')
0
+# ==================================================================
0
+#
0
 # Gets the values for the date value in a separate way.
0
-# Return every value by reference.
0
-function get_date($value, &$year, &$month, &$day) {
0
-  if (ereg('([0-9]{4})-([0-9]{2})-([0-9]{2})', $value, $data)) {
0
-    $year = $data[1];
0
-    $month = $data[2];
0
-    $day = $data[3];
0
-    return true;
0
-  }
0
-  elseif (ereg('([0-9]{2})/([0-9]{2})/([0-9]{2})', $value, $data)) {
0
-    $year = $data[3];
0
-    $month = $data[2];
0
-    $day = $data[1];
0
-    return true;
0
-  }
0
-  else return false;
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * date: The date to parse.
0
+# * year: A variable to store the year (by reference).
0
+# * month: A variable to store the month (by reference).
0
+# * day: A variable to store the day (by reference).
0
+# * date_format: The format of the date string. If no value is given the format is '%Y/%m/%d'.
0
+function get_date($date, &$year, &$month, &$day, $date_format = '%Y/%m/%d') {
0
+  $date = strToDate($date, $date_format);
0
+  foreach ($date as $key => $val)
0
+    switch ($key) {
0
+      case 'd': case 'j': $day = intval($val); break;
0
+      case 'D': $day = intval(date('j', $val)); break;
0
+      case 'm': case 'n': $month = intval($val); break;
0
+      case 'M': $month = intval(date('n', $val)); break;
0
+      case 'Y': $year = intval($val); break;
0
+      case 'y': $year = intval($val)+2000; break;
0
+    }
0
 }
0
 
0
+# get_time($value, &$hour, &$minute, &$second)
0
+# ============================================
0
+#
0
 # Gets the values for the time value in a separate way.
0
-# Return every value by reference.
0
-function get_time($value, &$hour, &$minute, &$second) {
0
-  if (ereg('([0-9]{2}):([0-9]{2}):([0-9]{2})', $value, $data)) {
0
-    $hour = $data[1];
0
-    $minute = $data[2];
0
-    $second = $data[3];
0
-    return true;
0
-  }
0
-  else return false;
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value where to search for the time.
0
+# * hour: A variable to store the hours (by reference).
0
+# * minute: A variable to store the minutes (by reference).
0
+# * second: A variable to store the seconds (by reference).
0
+function get_time($value, &$hours, &$minutes, &$seconds) {
0
+  preg_match('/([0-9]{2}):([0-9]{2}):([0-9]{2})/', $value, $data);
0
+  list(, $hours, $minutes, $seconds) = $data;
0
 }
0
 
0
 ?>
0
\ No newline at end of file
...
1
2
3
4
5
6
7
8
9
10
11
12
...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
96
97
98
99
 
 
100
101
102
...
104
105
106
107
 
 
108
109
 
110
111
112
 
 
113
114
115
 
 
116
117
118
119
 
 
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
...
266
267
268
269
270
271
272
273
274
 
 
275
 
 
276
 
277
 
278
279
280
 
 
 
 
281
 
 
282
283
 
 
 
 
 
 
 
 
284
285
286
287
288
 
289
290
291
 
 
292
293
294
295
296
297
 
 
 
298
 
 
299
300
301
...
303
304
305
 
 
 
306
307
308
309
310
311
 
 
 
 
312
313
314
 
 
315
316
317
318
319
320
 
321
322
323
 
 
 
 
 
324
325
326
 
 
 
 
 
 
 
327
 
 
 
 
 
328
329
330
 
 
331
 
 
 
332
333
 
 
 
 
 
 
 
 
 
 
 
 
334
 
 
335
336
337
...
341
342
343
 
 
 
344
 
 
 
345
346
 
 
347
 
348
349
350
351
352
 
353
354
355
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
358
 
 
 
 
 
 
 
359
 
 
 
360
361
362
 
 
 
363
364
365
...
369
370
371
 
 
 
 
 
 
 
 
 
 
372
 
 
 
373
374
375
 
376
377
378
 
 
379
 
 
380
381
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
384
385
 
386
387
388
389
 
 
 
390
391
392
393
394
395
396
397
398
 
 
 
 
399
 
 
 
400
401
 
 
 
 
 
 
 
 
 
 
402
 
 
403
 
404
405
406
 
 
 
 
407
408
409
 
 
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
412
413
414
 
 
 
 
 
 
415
416
 
417
418
 
419
 
 
 
 
420
 
 
 
 
421
422
423
424
425
426
427
...
433
434
435
436
437
 
438
439
440
441
442
443
444
445
446
447
448
449
...
451
452
453
454
455
456
457
...
472
473
474
475
 
 
 
 
 
 
 
476
477
 
 
478
479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
480
481
482
 
 
 
483
484
485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
486
 
 
487
488
489
 
 
490
491
492
 
 
 
493
494
495
496
 
 
 
497
498
499
...
503
504
505
 
 
 
506
507
 
 
 
 
508
509
 
510
 
 
 
 
 
 
511
512
513
514
515
 
516
517
518
...
528
529
530
 
 
 
531
532
533
534
535
536
 
 
 
 
 
 
 
 
537
538
539
...
549
550
551
 
 
552
553
554
 
 
 
555
556
557
558
559
560
561
562
563
 
564
565
566
567
 
 
 
568
569
570
 
 
571
572
573
 
 
 
 
 
 
574
575
576
577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
579
580
 
 
 
581
582
 
 
583
584
 
 
 
 
585
586
587
588
589
590
 
591
592
593
...
1
2
 
 
 
 
 
 
 
3
4
5
...
64
65
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
 
103
104
105
106
107
...
109
110
111
 
112
113
114
 
115
116
117
 
118
119
120
121
 
122
123
124
125
126
 
127
128
129
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
...
201
202
203
 
 
 
204
205
 
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
 
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
 
 
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
 
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
...
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
 
 
 
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
 
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
 
 
 
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
 
 
 
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
 
550
551
552
...
558
559
560
 
 
561
562
563
 
 
 
 
 
 
 
564
565
566
...
568
569
570
 
571
572
573
...
588
589
590
 
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
 
 
669
670
671
672
673
 
 
674
675
676
677
678
679
...
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
...
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
...
755
756
757
758
759
760
761
762
763
764
765
766
767
 
768
769
770
771
772
773
774
775
776
777
 
778
779
780
781
782
783
784
785
786
 
 
787
788
789
790
791
792
793
794
795
 
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
 
 
 
831
832
833
834
0
@@ -1,12 +1,5 @@
0
 <?php
0
 
0
-function file_to_array($file, $format = false) {
0
-  $data = file_get_contents($file);
0
-  if (!$format)
0
-    $format = extension_of_file($file);
0
-  return call_user_func($format . '_decode', $data, true);
0
-}
0
-
0
 # files_on($path, $options = array())
0
 # ===================================
0
 #
0
@@ -71,32 +64,44 @@ function files_on($path, $options = array()) {
0
   return $data;
0
 }
0
 
0
-/*
0
-Function: path
0
-  creates a path to the given public resource
0
-
0
-Arguments:
0
-  where: the path relative to the public folder
0
-
0
-Returns:
0
-  a string with the path
0
-*/
0
-function path($where) {
0
-  return root . 'public' . DIRECTORY_SEPARATOR . $where;
0
-}
0
-
0
-/*
0
-Sends the file specified by the path
0
-
0
-Options:
0
-  data => the data or the filename path
0
-    options => array that specifies the sending process
0
- */
0
+# send_file($data, $options = array())
0
+# ====================================
0
+#
0
+# Sends the given content to the browser.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * data: The data or a filesystem path where retrieve the content to send to the browser.
0
+# * options: Options for the sending operation.
0
+#
0
+#
0
+#
0
+# Options
0
+# -------
0
+#
0
+# * filename: The filename to give to the browser when sending the content.
0
+# * type: The mime type to send to the browser.
0
+# * destination: The destination type of the sending operation. <inline> and <attachment> will send the file to the
0
+# browser to download. <file> will send the content to the filesystem. <string> will return the content data.
0
+# * cache: A boolean to tell the browser to cache the file.
0
+# * etag: etag to tell the browser.
0
+# * encoding: File download encoding.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * on string destination type, will return the content data.
0
 function send_file($data, $options = array()) {
0
   $options = array_merge(array('filename' => name_of_file($data), 'type' => 'application/octet-stream', 'destination' => 'attachment', 'cache' => true, 'etag' => false, 'encoding' => 'utf-8'), $options);
0
   switch ($options['destination']) {
0
     case 'inline': case 'attachment':
0
-      if (file_exists($data)) $data = file_get_contents($data);
0
+      if (file_exists($data))
0
+        $data = file_get_contents($data);
0
       header('Content-type: ' . $options['type'] . '; charset=' . $options['encoding']);
0
       header('Content-Disposition: ' . $options['destination'] . '; filename="' . $options['filename'] . '"');
0
       if (empty($options['cache'])) {
0
@@ -104,97 +109,27 @@ function send_file($data, $options = array()) {
0
         header('Cache-Control: must-revalidate, post-check=0,pre-check=0');
0
         header('Pragma: public');
0
       }
0
-      if ($options['etag']) header('ETag: "' . $options['etag'] . '"');
0
+      if ($options['etag'])
0
+        header('ETag: "' . $options['etag'] . '"');
0
       if (preg_match('/^(\/|http|www|\?)/', $data)) {
0
-        $fp = fopen('http://' . $_SERVER['SERVER_NAME'] . '/' .$path, 'r');
0
+        $fp = fopen(url . $path, 'r');
0
         fpassthru($fp);
0
       }
0
-      else die($data);
0
+      else
0
+        die($data);
0
       break;
0
     case 'file':
0
-      if (preg_match('/^(\/|http|www|\?)/', $data)) $data = file_get_contents($data);
0
+      if (preg_match('/^(\/|http|www|\?)/', $data))
0
+        $data = file_get_contents($data);
0
       file_put_contents($options['filename'], $data);
0
       break;
0
     case 'string':
0
-      if (preg_match('/^(\/|http|www|\?)/', $data)) return file_get_contents($data);
0
+      if (preg_match('/^(\/|http|www|\?)/', $data))
0
+        return file_get_contents($data);
0
       return $data;
0
   }
0
 }
0
 
0
-/*
0
-Function: asset_path
0
-  get the path to the given source
0
-
0
-Arguments:
0
-  source: the file to get
0
-  type: the type of file to get (css/js/img)
0
-
0
-Returns:
0
-  the path (absolute or relative)
0
-*/
0
-function asset_path($source, $type) {
0
-  if ($type == 'css')    $pre_path = path('stylesheets');
0
-  elseif ($type == 'js')  $pre_path = path('javascripts');
0
-  else          $pre_path = path('images');
0
-
0
-  $data = is_absolute_url($source) ? $source : $pre_path . DIRECTORY_SEPARATOR . $source;
0
-  $outside = is_outside_the_web($source);
0
-  if (!$outside && $type != 'img' && strpos($source, '.' . $type) === false) $data .= '.' . $type;
0
-  return $data;
0
-}
0
-
0
-/*
0
-Function: asset_url
0
-  get the url to the given source
0
-
0
-Arguments:
0
-  source: the file to get
0
-  type: the type of file to get (css/js/img)
0
-
0
-Returns:
0
-  the url (absolute or relative)
0
-*/
0
-function asset_url($source, $type) {
0
-  if ($type == 'css')    $pre_path = '/stylesheets/';
0
-  elseif ($type == 'js')  $pre_path = '/javascripts/';
0
-  else          $pre_path = '/images/';
0
-
0
-  $data = is_absolute_url($source) ? $source : $pre_path . $source;
0
-
0
-  $outside = is_outside_the_web($source);
0
-  if (!$outside && $type != 'img' && strpos($source, '.' . $type) === false) $data .= '.' . $type;
0
-  if (Environment::environment == 'development' && !$outside) $data .= '?' . create_hash();
0
-  return $data;
0
-}
0
-
0
-/*
0
-Function: is_absolute_url
0
-  says if a file url is absolute
0
-
0
-Arguments:
0
-  file: the file to test
0
-
0
-Returns:
0
-  true if it is an absolute url, false otherwise
0
-*/
0
-function is_absolute_url($file) {
0
-  return preg_match('/^(\/|http|www)/', $file);
0
-}
0
-
0
-/*
0
-Function: is_outside_the_web
0
-  says if a file is outside of the web
0
-
0
-Arguments:
0
-  file: the file to test
0
-
0
-Returns:
0
-  true if it is outside of the web, false otherwise
0
-*/
0
-function is_outside_the_web($file) {
0
-  return preg_match('/^(http|www)/', $file);
0
-}
0
-
0
 # name_of_file($file)
0
 # ===================
0
 # 
0
@@ -266,36 +201,60 @@ function get_mime($extension) {
0
   static $types = array();
0
   if (empty($types))
0
     $types = array(
0
-      '' => 'application/EDI-Consent',
0
-      '' => 'application/EDI-X12',
0
-      '' => 'application/EDIFACT',
0
       '' => 'application/activemessage',
0
       'ez' => 'application/andrew-inset',
0
-      '' => 'application/applefile',
0
+      'application/applefile',
0
+      'atom' => 'application/atom+xml',
0
       '' => 'application/atomicmail',
0
+      '' => 'application/batch-smtp',
0
+      '' => 'application/beep+xml',
0
       '' => 'application/cals-1840',
0
+      '' => 'application/cnrp+xml',
0
       '' => 'application/commonground',
0
+      '' => 'application/cpl+xml',
0
       '' => 'application/cybercash',
0
       '' => 'application/dca-rft',
0
       '' => 'application/dec-dx',
0
+      '' => 'application/dvcs',
0
+      '' => 'application/edi-consent',
0
+      '' => 'application/edifact',
0
+      '' => 'application/edi-x12',
0
       '' => 'application/eshop',
0
+      '' => 'application/font-tdpfr',
0
+      '' => 'application/http',
0
       '' => 'application/hyperstudio',
0
       '' => 'application/iges',
0
+      '' => 'application/index',
0
+      '' => 'application/index.cmd',
0
+      '' => 'application/index.obj',
0
+      '' => 'application/index.response',
0
+      '' => 'application/index.vnd',
0
+      '' => 'application/iotp',
0
+      '' => 'application/ipp',
0
+      '' => 'application/isup',
0
       'hqx' => 'application/mac-binhex40',
0
       'cpt' => 'application/mac-compactpro',
0
       '' => 'application/macwriteii',
0
       '' => 'application/marc',
0
       '' => 'application/mathematica',
0
+      'mathml' => 'application/mathml+xml',
0
       'doc' => 'application/msword',
0
       '' => 'application/news-message-id',
0
       '' => 'application/news-transmission',
0
+      '' => 'application/ocsp-request',
0
+      '' => 'application/ocsp-response',
0
       'bin' => 'application/octet-stream',
0
       'dms' => 'application/octet-stream',
0
       'lha' => 'application/octet-stream',
0
       'lzh' => 'application/octet-stream',
0
       'exe' => 'application/octet-stream',
0
       'class' => 'application/octet-stream',
0
+      'so' => 'application/octet-stream',
0
+      'dll' => 'application/octet-stream',
0
+      'dmg' => 'application/octet-stream',
0
       'oda' => 'application/oda',
0
+      'ogg' => 'application/ogg',
0
+      'application/parityfec',
0
       'pdf' => 'application/pdf',
0
       '' => 'application/pgp-encrypted',
0
       '' => 'application/pgp-keys',
0
@@ -303,35 +262,77 @@ function get_mime($extension) {
0
       '' => 'application/pkcs10',
0
       '' => 'application/pkcs7-mime',
0
       '' => 'application/pkcs7-signature',
0
+      '' => 'application/pkix-cert',
0
+      '' => 'application/pkix-crl',
0
+      '' => 'application/pkixcmp',
0
       'ai' => 'application/postscript',
0
       'eps' => 'application/postscript',
0
       'ps' => 'application/postscript',
0
       '' => 'application/prs.alvestrand.titrax-sheet',
0
       '' => 'application/prs.cww',
0
       '' => 'application/prs.nprend',
0
+      '' => 'application/prs.plucker',
0
+      '' => 'application/qsig',
0
+      'rdf' => 'application/rdf+xml',
0
+      '' => 'application/reginfo+xml',
0
       '' => 'application/remote-printing',
0
       '' => 'application/riscos',
0
-      'rtf' => 'application/rtf',
0
+      '' => 'application/rtf',
0
+      '' => 'application/sdp',
0
       '' => 'application/set-payment',
0
       '' => 'application/set-payment-initiation',
0
       '' => 'application/set-registration',
0
       '' => 'application/set-registration-initiation',
0
       '' => 'application/sgml',
0
       '' => 'application/sgml-open-catalog',
0
+      '' => 'application/sieve',
0
       '' => 'application/slate',
0
       'smi' => 'application/smil',
0
       'smil' => 'application/smil',
0
+      'gram' => 'application/srgs',
0
+      'grxml' => 'application/srgs+xml',
0
+      '' => 'application/timestamp-query',
0
+      '' => 'application/timestamp-reply',
0
+      '' => 'application/tve-trigger',
0
       '' => 'application/vemmi',
0
-      '' => 'application/vnd.3M.Post-it-Notes',
0
-      '' => 'application/vnd.FloGraphIt',
0
+      '' => 'application/vnd.3gpp.pic-bw-large',
0
+      '' => 'application/vnd.3gpp.pic-bw-small',
0
+      '' => 'application/vnd.3gpp.pic-bw-var',
0
+      '' => 'application/vnd.3gpp.sms',
0
+      '' => 'application/vnd.3m.post-it-notes',
0
+      '' => 'application/vnd.accpac.simply.aso',
0
+      '' => 'application/vnd.accpac.simply.imp',
0
       '' => 'application/vnd.acucobol',
0
+      '' => 'application/vnd.acucorp',
0
+      'air' => 'application/vnd.adobe.air-application-installer-package+zip air',
0
+      '' => 'application/vnd.adobe.xfdf',
0
+      '' => 'application/vnd.aether.imp',
0
+      '' => 'application/vnd.amiga.ami',
0
       '' => 'application/vnd.anser-web-certificate-issue-initiation',
0
       '' => 'application/vnd.anser-web-funds-transfer-initiation',
0
       '' => 'application/vnd.audiograph',
0
+      '' => 'application/vnd.blueice.multipass',
0
+      '' => 'application/vnd.bmi',
0
       '' => 'application/vnd.businessobjects',
0
+      '' => 'application/vnd.canon-cpdl',
0
+      '' => 'application/vnd.canon-lips',
0
+      '' => 'application/vnd.cinderella',
0
       '' => 'application/vnd.claymore',
0
-      '' => 'application/vnd.comsocaller',
0
+      '' => 'application/vnd.commerce-battelle',
0
+      '' => 'application/vnd.commonspace',
0
+      '' => 'application/vnd.contact.cmsg',
0
+      '' => 'application/vnd.cosmocaller',
0
+      '' => 'application/vnd.criticaltools.wbs+xml',
0
+      '' => 'application/vnd.ctc-posml',
0
+      '' => 'application/vnd.cups-postscript',
0
+      '' => 'application/vnd.cups-raster',
0
+      '' => 'application/vnd.cups-raw',
0
+      '' => 'application/vnd.curl',
0
+      '' => 'application/vnd.cybank',
0
+      '' => 'application/vnd.data-vision.rdz',
0
       '' => 'application/vnd.dna',
0
+      '' => 'application/vnd.dpgraph',
0
+      '' => 'application/vnd.dreamfactory',
0
       '' => 'application/vnd.dxr',
0
       '' => 'application/vnd.ecdis-update',
0
       '' => 'application/vnd.ecowin.chart',
0
@@ -341,25 +342,58 @@ function get_mime($extension) {
0
       '' => 'application/vnd.ecowin.seriesrequest',
0
       '' => 'application/vnd.ecowin.seriesupdate',
0
       '' => 'application/vnd.enliven',
0
+      '' => 'application/vnd.epson.esf',
0
+      '' => 'application/vnd.epson.msf',
0
+      '' => 'application/vnd.epson.quickanime',
0
       '' => 'application/vnd.epson.salt',
0
+      '' => 'application/vnd.epson.ssf',
0
+      '' => 'application/vnd.ericsson.quickcall',
0
+      '' => 'application/vnd.eudora.data',
0
       '' => 'application/vnd.fdf',
0
       '' => 'application/vnd.ffsns',
0
+      '' => 'application/vnd.fints',
0
+      '' => 'application/vnd.flographit',
0
       '' => 'application/vnd.framemaker',
0
+      '' => 'application/vnd.fsc.weblaunch',
0
       '' => 'application/vnd.fujitsu.oasys',
0
       '' => 'application/vnd.fujitsu.oasys2',
0
       '' => 'application/vnd.fujitsu.oasys3',
0
       '' => 'application/vnd.fujitsu.oasysgp',
0
       '' => 'application/vnd.fujitsu.oasysprs',
0
+      '' => 'application/vnd.fujixerox.ddd',
0
       '' => 'application/vnd.fujixerox.docuworks',
0
-      '' => 'application/vnd.hp-HPGL',
0
-      '' => 'application/vnd.hp-PCL',
0
-      '' => 'application/vnd.hp-PCLXL',
0
+      '' => 'application/vnd.fujixerox.docuworks.binder',
0
+      '' => 'application/vnd.fut-misnet',
0
+      '' => 'application/vnd.grafeq',
0
+      '' => 'application/vnd.groove-account',
0
+      '' => 'application/vnd.groove-help',
0
+      '' => 'application/vnd.groove-identity-message',
0
+      '' => 'application/vnd.groove-injector',
0
+      '' => 'application/vnd.groove-tool-message',
0
+      '' => 'application/vnd.groove-tool-template',
0
+      '' => 'application/vnd.groove-vcard',
0
+      '' => 'application/vnd.hbci',
0
+      '' => 'application/vnd.hhe.lesson-player',
0
+      '' => 'application/vnd.hp-hpgl',
0
+      '' => 'application/vnd.hp-hpid',
0
       '' => 'application/vnd.hp-hps',
0
-      '' => 'application/vnd.ibm.MiniPay',
0
+      '' => 'application/vnd.hp-pcl',
0
+      '' => 'application/vnd.hp-pclxl',
0
+      '' => 'application/vnd.httphone',
0
+      '' => 'application/vnd.hzn-3d-crossword',
0
+      '' => 'application/vnd.ibm.afplinedata',
0
+      '' => 'application/vnd.ibm.electronic-media',
0
+      '' => 'application/vnd.ibm.minipay',
0
       '' => 'application/vnd.ibm.modcap',
0
+      '' => 'application/vnd.ibm.rights-management',
0
+      '' => 'application/vnd.ibm.secure-container',
0
+      '' => 'application/vnd.informix-visionary',
0
       '' => 'application/vnd.intercon.formnet',
0
       '' => 'application/vnd.intertrust.digibox',
0
       '' => 'application/vnd.intertrust.nncp',
0
+      '' => 'application/vnd.intu.qbo',
0
+      '' => 'application/vnd.intu.qfx',
0
+      '' => 'application/vnd.irepository.package+xml',
0
       '' => 'application/vnd.is-xpr',
0
       '' => 'application/vnd.japannet-directory-service',
0
       '' => 'application/vnd.japannet-jpnstore-wakeup',
0
@@ -369,59 +403,150 @@ function get_mime($extension) {
0
       '' => 'application/vnd.japannet-setstore-wakeup',
0
       '' => 'application/vnd.japannet-verification',
0
       '' => 'application/vnd.japannet-verification-wakeup',
0
+      '' => 'application/vnd.jisp',
0
+      '' => 'application/vnd.kde.karbon',
0
+      '' => 'application/vnd.kde.kchart',
0
+      '' => 'application/vnd.kde.kformula',
0
+      '' => 'application/vnd.kde.kivio',
0
+      '' => 'application/vnd.kde.kontour',
0
+      '' => 'application/vnd.kde.kpresenter',
0
+      '' => 'application/vnd.kde.kspread',
0
+      '' => 'application/vnd.kde.kword',
0
+      '' => 'application/vnd.kenameaapp',
0
       '' => 'application/vnd.koan',
0
+      '' => 'application/vnd.liberty-request+xml',
0
+      '' => 'application/vnd.llamagraphics.life-balance.desktop',
0
+      '' => 'application/vnd.llamagraphics.life-balance.exchange+xml',
0
       '' => 'application/vnd.lotus-1-2-3',
0
       '' => 'application/vnd.lotus-approach',
0
       '' => 'application/vnd.lotus-freelance',
0
+      '' => 'application/vnd.lotus-notes',
0
       '' => 'application/vnd.lotus-organizer',
0
       '' => 'application/vnd.lotus-screencam',
0
       '' => 'application/vnd.lotus-wordpro',
0
+      '' => 'application/vnd.mcd',
0
+      '' => 'application/vnd.mediastation.cdkey',
0
       '' => 'application/vnd.meridian-slingshot',
0
+      '' => 'application/vnd.micrografx.flo',
0
+      '' => 'application/vnd.micrografx.igx',
0
       'mif' => 'application/vnd.mif',
0
       '' => 'application/vnd.minisoft-hp3000-save',
0
       '' => 'application/vnd.mitsubishi.misty-guard.trustweb',
0
+      '' => 'application/vnd.mobius.daf',
0
+      '' => 'application/vnd.mobius.dis',
0
+      '' => 'application/vnd.mobius.mbk',
0
+      '' => 'application/vnd.mobius.mqy',
0
+      '' => 'application/vnd.mobius.msl',
0
+      '' => 'application/vnd.mobius.plc',
0
+      '' => 'application/vnd.mobius.txf',
0
+      '' => 'application/vnd.mophun.application',
0
+      '' => 'application/vnd.mophun.certificate',
0
+      '' => 'application/vnd.motorola.flexsuite',
0
+      '' => 'application/vnd.motorola.flexsuite.adsi',
0
+      '' => 'application/vnd.motorola.flexsuite.fis',
0
+      '' => 'application/vnd.motorola.flexsuite.gotap',
0
+      '' => 'application/vnd.motorola.flexsuite.kmr',
0
+      '' => 'application/vnd.motorola.flexsuite.ttc',
0
+      '' => 'application/vnd.motorola.flexsuite.wem',
0
+      'xul' => 'application/vnd.mozilla.xul+xml',
0
       '' => 'application/vnd.ms-artgalry',
0
       '' => 'application/vnd.ms-asf',
0
       'xls' => 'application/vnd.ms-excel',
0
+      '' => 'application/vnd.ms-lrm',
0
       'ppt' => 'application/vnd.ms-powerpoint',
0
       '' => 'application/vnd.ms-project',
0
       '' => 'application/vnd.ms-tnef',
0
       '' => 'application/vnd.ms-works',
0
+      '' => 'application/vnd.ms-wpl',
0
+      '' => 'application/vnd.mseq',
0
+      '' => 'application/vnd.msign',
0
       '' => 'application/vnd.music-niff',
0
       '' => 'application/vnd.musician',
0
       '' => 'application/vnd.netfpx',
0
       '' => 'application/vnd.noblenet-directory',
0
       '' => 'application/vnd.noblenet-sealer',
0
       '' => 'application/vnd.noblenet-web',
0
-      '' => 'application/vnd.novadigm.EDM',
0
-      '' => 'application/vnd.novadigm.EDX',
0
-      '' => 'application/vnd.novadigm.EXT',
0
+      '' => 'application/vnd.novadigm.edm',
0
+      '' => 'application/vnd.novadigm.edx',
0
+      '' => 'application/vnd.novadigm.ext',
0
+      '' => 'application/vnd.obn',
0
       '' => 'application/vnd.osa.netdeploy',
0
+      '' => 'application/vnd.palm',
0
+      '' => 'application/vnd.pg.format',
0
+      '' => 'application/vnd.pg.osasli',
0
       '' => 'application/vnd.powerbuilder6',
0
       '' => 'application/vnd.powerbuilder6-s',
0
+      '' => 'application/vnd.powerbuilder7',
0
+      '' => 'application/vnd.powerbuilder7-s',
0
+      '' => 'application/vnd.powerbuilder75',
0
+      '' => 'application/vnd.powerbuilder75-s',
0
+      '' => 'application/vnd.previewsystems.box',
0
+      '' => 'application/vnd.publishare-delta-tree',
0
+      '' => 'application/vnd.pvi.ptid1',
0
+      '' => 'application/vnd.pwg-multiplexed',
0
+      '' => 'application/vnd.pwg-xhtml-print+xml',
0
+      '' => 'application/vnd.quark.quarkxpress',
0
       '' => 'application/vnd.rapid',
0
+      '' => 'application/vnd.s3sms',
0
+      '' => 'application/vnd.sealed.net',
0
       '' => 'application/vnd.seemail',
0
+      '' => 'application/vnd.shana.informed.formdata',
0
       '' => 'application/vnd.shana.informed.formtemplate',
0
       '' => 'application/vnd.shana.informed.interchange',
0
       '' => 'application/vnd.shana.informed.package',
0
+      '' => 'application/vnd.smaf',
0
+      '' => 'application/vnd.sss-cod',
0
+      '' => 'application/vnd.sss-dtf',
0
+      '' => 'application/vnd.sss-ntf',
0
       '' => 'application/vnd.street-stream',
0
       '' => 'application/vnd.svd',
0
       '' => 'application/vnd.swiftview-ics',
0
+      '' => 'application/vnd.triscape.mxs',
0
+      '' => 'application/vnd.trueapp',
0
       '' => 'application/vnd.truedoc',
0
+      '' => 'application/vnd.ufdl',
0
+      '' => 'application/vnd.uplanet.alert',
0
+      '' => 'application/vnd.uplanet.alert-wbxml',
0
+      '' => 'application/vnd.uplanet.bearer-choice',
0
+      '' => 'application/vnd.uplanet.bearer-choice-wbxml',
0
+      '' => 'application/vnd.uplanet.cacheop',
0
+      '' => 'application/vnd.uplanet.cacheop-wbxml',
0
+      '' => 'application/vnd.uplanet.channel',
0
+      '' => 'application/vnd.uplanet.channel-wbxml',
0
+      '' => 'application/vnd.uplanet.list',
0
+      '' => 'application/vnd.uplanet.list-wbxml',
0
+      '' => 'application/vnd.uplanet.listcmd',
0
+      '' => 'application/vnd.uplanet.listcmd-wbxml',
0
+      '' => 'application/vnd.uplanet.signal',
0
+      '' => 'application/vnd.vcx',
0
+      '' => 'application/vnd.vectorworks',
0
+      '' => 'application/vnd.vidsoft.vidconference',
0
       '' => 'application/vnd.visio',
0
-      '' => 'application/vnd.webturbo',
0
-      'slc' => 'application/vnd.wap.slc',
0
-      'sic' => 'application/vnd.wap.sic',
0
+      '' => 'application/vnd.visionary',
0
+      '' => 'application/vnd.vividence.scriptfile',
0
+      '' => 'application/vnd.vsf',
0
+      '' => 'application/vnd.wap.sic',
0
+      '' => 'application/vnd.wap.slc',
0
+      'wbxml' => 'application/vnd.wap.wbxml',
0
       'wmlc' => 'application/vnd.wap.wmlc',
0
       'wmlsc' => 'application/vnd.wap.wmlscriptc',
0
+      '' => 'application/vnd.webturbo',
0
       '' => 'application/vnd.wrq-hp3000-labelled',
0
       '' => 'application/vnd.wt.stf',
0
+      '' => 'application/vnd.wv.csp+wbxml',
0
       '' => 'application/vnd.xara',
0
+      '' => 'application/vnd.xfdl',
0
+      '' => 'application/vnd.yamaha.hv-dic',
0
+      '' => 'application/vnd.yamaha.hv-script',
0
+      '' => 'application/vnd.yamaha.hv-voice',
0
       '' => 'application/vnd.yellowriver-custom-menu',
0
+      'vxml' => 'application/voicexml+xml',
0
+      '' => 'application/watcherinfo+xml',
0
+      '' => 'application/whoispp-query',
0
+      '' => 'application/whoispp-response',
0
       '' => 'application/wita',
0
       '' => 'application/wordperfect5.1',
0
       'bcpio' => 'application/x-bcpio',
0
-      'bz2' => 'application/x-bzip2',
0
       'vcd' => 'application/x-cdlink',
0
       'pgn' => 'application/x-chess-pgn',
0
       '' => 'application/x-compress',
0
@@ -433,17 +558,9 @@ function get_mime($extension) {
0
       'dvi' => 'application/x-dvi',
0
       'spl' => 'application/x-futuresplash',
0
       'gtar' => 'application/x-gtar',
0
-      'gz' => 'application/x-gzip',
0
-      'tgz' => 'application/x-gzip',
0
+      '' => 'application/x-gzip',
0
       'hdf' => 'application/x-hdf',
0
       'js' => 'application/x-javascript',
0
-      'kwd' => 'application/x-kword',
0
-      'kwt' => 'application/x-kword',
0
-      'ksp' => 'application/x-kspread',
0
-      'kpr' => 'application/x-kpresenter',
0
-      'kpt' => 'application/x-kpresenter',
0
-      'chrt' => 'application/x-kchart',
0
-      'kil' => 'application/x-killustrator',
0
       'skp' => 'application/x-koan',
0
       'skd' => 'application/x-koan',
0
       'skt' => 'application/x-koan',
0
@@ -451,7 +568,6 @@ function get_mime($extension) {
0
       'latex' => 'application/x-latex',
0
       'nc' => 'application/x-netcdf',
0
       'cdf' => 'application/x-netcdf',
0
-      'rpm' => 'application/x-rpm',
0
       'sh' => 'application/x-sh',
0
       'shar' => 'application/x-shar',
0
       'swf' => 'application/x-shockwave-flash',
0
@@ -472,28 +588,92 @@ function get_mime($extension) {
0
       'ustar' => 'application/x-ustar',
0
       'src' => 'application/x-wais-source',
0
       '' => 'application/x400-bp',
0
-      '' => 'application/xml',
0
+      'xhtml' => 'application/xhtml+xml',
0
+      'xht' => 'application/xhtml+xml',
0
+      'xslt' => 'application/xslt+xml',
0
+      'xml' => 'application/xml',
0
+      'xsl' => 'application/xml',
0
+      'dtd' => 'application/xml-dtd',
0
+      '' => 'application/xml-external-parsed-entity',
0
       'zip' => 'application/zip',
0
       '' => 'audio/32kadpcm',
0
+      '' => 'audio/amr',
0
+      '' => 'audio/amr-wb',
0
       'au' => 'audio/basic',
0
       'snd' => 'audio/basic',
0
+      '' => 'audio/cn',
0
+      '' => 'audio/dat12',
0
+      '' => 'audio/dsr-es201108',
0
+      '' => 'audio/dvi4',
0
+      '' => 'audio/evrc',
0
+      '' => 'audio/evrc0',
0
+      '' => 'audio/g722',
0
+      '' => 'audio/g.722.1',
0
+      '' => 'audio/g723',
0
+      '' => 'audio/g726-16',
0
+      '' => 'audio/g726-24',
0
+      '' => 'audio/g726-32',
0
+      '' => 'audio/g726-40',
0
+      '' => 'audio/g728',
0
+      '' => 'audio/g729',
0
+      '' => 'audio/g729D',
0
+      '' => 'audio/g729E',
0
+      '' => 'audio/gsm',
0
+      '' => 'audio/gsm-efr',
0
+      '' => 'audio/l8',
0
+      '' => 'audio/l16',
0
+      '' => 'audio/l20',
0
+      '' => 'audio/l24',
0
+      '' => 'audio/lpc',
0
       'mid' => 'audio/midi',
0
       'midi' => 'audio/midi',
0
       'kar' => 'audio/midi',
0
+      '' => 'audio/mpa',
0
+      '' => 'audio/mpa-robust',
0
+      '' => 'audio/mp4a-latm',
0
       'mpga' => 'audio/mpeg',
0
       'mp2' => 'audio/mpeg',
0
       'mp3' => 'audio/mpeg',
0
+      '' => 'audio/parityfec',
0
+      '' => 'audio/pcma',
0
+      '' => 'audio/pcmu',
0
+      '' => 'audio/prs.sid',
0
+      '' => 'audio/qcelp',
0
+      '' => 'audio/red',
0
+      '' => 'audio/smv',
0
+      '' => 'audio/smv0',
0
+      '' => 'audio/telephone-event',
0
+      '' => 'audio/tone',
0
+      '' => 'audio/vdvi',
0
+      '' => 'audio/vnd.3gpp.iufp',
0
+      '' => 'audio/vnd.cisco.nse',
0
+      '' => 'audio/vnd.cns.anp1',
0
+      '' => 'audio/vnd.cns.inf1',
0
+      '' => 'audio/vnd.digital-winds',
0
+      '' => 'audio/vnd.everad.plj',
0
+      '' => 'audio/vnd.lucent.voice',
0
+      '' => 'audio/vnd.nortel.vbk',
0
+      '' => 'audio/vnd.nuera.ecelp4800',
0
+      '' => 'audio/vnd.nuera.ecelp7470',
0
+      '' => 'audio/vnd.nuera.ecelp9600',
0
+      '' => 'audio/vnd.octel.sbc',
0
       '' => 'audio/vnd.qcelp',
0
+      '' => 'audio/vnd.rhetorex.32kadpcm',
0
+      '' => 'audio/vnd.vmx.cvsd',
0
       'aif' => 'audio/x-aiff',
0
       'aiff' => 'audio/x-aiff',
0
       'aifc' => 'audio/x-aiff',
0
+      '' => 'audio/x-alaw-basic',
0
+      'm3u' => 'audio/x-mpegurl',
0
       'ram' => 'audio/x-pn-realaudio',
0
-      'rm' => 'audio/x-pn-realaudio',
0
-      'ra' => 'audio/x-realaudio',
0
+      'ra' => 'audio/x-pn-realaudio',
0
+      '' => 'audio/x-pn-realaudio-plugin',
0
+      'rm' => 'application/vnd.rn-realmedia',
0
       'wav' => 'audio/x-wav',
0
       'pdb' => 'chemical/x-pdb',
0
-      'xyz' => 'chemical/x-pdb',
0
-      '' => 'image/cgm',
0
+      'xyz' => 'chemical/x-xyz',
0
+      'bmp' => 'image/bmp',
0
+      'cgm' => 'image/cgm',
0
       '' => 'image/g3fax',
0
       'gif' => 'image/gif',
0
       'ief' => 'image/ief',
0
@@ -503,16 +683,31 @@ function get_mime($extension) {
0
       '' => 'image/naplps',
0
       'png' => 'image/png',
0
       '' => 'image/prs.btif',
0
+      '' => 'image/prs.pti',
0
+      'svg' => 'image/svg+xml',
0
+      '' => 'image/t38',
0
       'tiff' => 'image/tiff',
0
       'tif' => 'image/tiff',
0
+      '' => 'image/tiff-fx',
0
+      '' => 'image/vnd.cns.inf2',
0
+      'djvu' => 'image/vnd.djvu',
0
+      'djv' => 'image/vnd.djvu',
0
       '' => 'image/vnd.dwg',
0
       '' => 'image/vnd.dxf',
0
+      '' => 'image/vnd.fastbidsheet',
0
       '' => 'image/vnd.fpx',
0
+      '' => 'image/vnd.fst',
0
+      '' => 'image/vnd.fujixerox.edmics-mmr',
0
+      '' => 'image/vnd.fujixerox.edmics-rlc',
0
+      '' => 'image/vnd.globalgraphics.pgb',
0
+      '' => 'image/vnd.mix',
0
+      '' => 'image/vnd.ms-modi',
0
       '' => 'image/vnd.net-fpx',
0
       '' => 'image/vnd.svf',
0
       'wbmp' => 'image/vnd.wap.wbmp',
0
       '' => 'image/vnd.xiff',
0
       'ras' => 'image/x-cmu-raster',
0
+      'ico' => 'image/x-icon',
0
       'pnm' => 'image/x-portable-anymap',
0
       'pbm' => 'image/x-portable-bitmap',
0
       'pgm' => 'image/x-portable-graymap',
0
@@ -528,12 +723,23 @@ function get_mime($extension) {
0
       '' => 'message/news',
0
       '' => 'message/partial',
0
       '' => 'message/rfc822',
0
+      '' => 'message/s-http',
0
+      '' => 'message/sip',
0
+      '' => 'message/sipfrag',
0
       'igs' => 'model/iges',
0
       'iges' => 'model/iges',
0
       'msh' => 'model/mesh',
0
       'mesh' => 'model/mesh',
0
       'silo' => 'model/mesh',
0
       '' => 'model/vnd.dwf',
0
+      '' => 'model/vnd.flatland.3dml',
0
+      '' => 'model/vnd.gdl',
0
+      '' => 'model/vnd.gs-gdl',
0
+      '' => 'model/vnd.gtw',
0
+      '' => 'model/vnd.mts',
0
+      '' => 'model/vnd.parasolid.transmit.binary',
0
+      '' => 'model/vnd.parasolid.transmit.text',
0
+      '' => 'model/vnd.vtu',
0
       'wrl' => 'model/vrml',
0
       'vrml' => 'model/vrml',
0
       '' => 'multipart/alternative',
0
@@ -549,45 +755,80 @@ function get_mime($extension) {
0
       '' => 'multipart/report',
0
       '' => 'multipart/signed',
0
       '' => 'multipart/voice-message',
0
+      'ics' => 'text/calendar',
0
+      'ifb' => 'text/calendar',
0
       'css' => 'text/css',
0
       '' => 'text/directory',
0
       '' => 'text/enriched',
0
+      'html' => 'text/html',
0
+      'htm' => 'text/html',
0
+      '' => 'text/parityfec',
0
       'asc' => 'text/plain',
0
       'txt' => 'text/plain',
0
-      'yml' => 'text/plain',
0
       '' => 'text/prs.lines.tag',
0
       '' => 'text/rfc822-headers',
0
       'rtx' => 'text/richtext',
0
       'rtf' => 'text/rtf',
0
       'sgml' => 'text/sgml',
0
       'sgm' => 'text/sgml',
0
+      '' => 'text/t140',
0
       'tsv' => 'text/tab-separated-values',
0
       '' => 'text/uri-list',
0
       '' => 'text/vnd.abc',
0
-      '' => 'text/vnd.flatland.3dml',
0
+      '' => 'text/vnd.curl',
0
+      '' => 'text/vnd.dmclientscript',
0
+      '' => 'text/vnd.fly',
0
       '' => 'text/vnd.fmi.flexstor',
0
       '' => 'text/vnd.in3d.3dml',
0
       '' => 'text/vnd.in3d.spot',
0
+      '' => 'text/vnd.iptc.nitf',
0
+      '' => 'text/vnd.iptc.newsml',
0
       '' => 'text/vnd.latex-z',
0
-      'sl' => 'text/vnd.wap.sl',
0
-      'si' => 'text/vnd.wap.si',
0
+      '' => 'text/vnd.motorola.reflex',
0
+      '' => 'text/vnd.ms-mediapackage',
0
+      '' => 'text/vnd.net2phone.commcenter.command',
0
+      '' => 'text/vnd.sun.j2me.app-descriptor',
0
+      '' => 'text/vnd.wap.si',
0
+      '' => 'text/vnd.wap.sl',
0
       'wml' => 'text/vnd.wap.wml',
0
       'wmls' => 'text/vnd.wap.wmlscript',
0
       'etx' => 'text/x-setext',
0
-      'xml' => 'text/xml',
0
+      '' => 'text/xml',
0
+      '' => 'text/xml-external-parsed-entity',
0
+      '' => 'video/bmpeg',
0
+      '' => 'video/bt656',
0
+      '' => 'video/celb',
0
+      '' => 'video/dv',
0
+      '' => 'video/h261',
0
+      '' => 'video/h263',
0
+      '' => 'video/h263-1998',
0
+      '' => 'video/h263-2000',
0
+      '' => 'video/jpeg',
0
+      '' => 'video/mp1s',
0
+      '' => 'video/mp2p',
0
+      '' => 'video/mp2t',
0
+      '' => 'video/mp4v-es',
0
+      '' => 'video/mpv',
0
       'mpeg' => 'video/mpeg',
0
       'mpg' => 'video/mpeg',
0
       'mpe' => 'video/mpeg',
0
+      '' => 'video/nv',
0
+      '' => 'video/parityfec',
0
+      '' => 'video/pointer',
0
       'qt' => 'video/quicktime',
0
       'mov' => 'video/quicktime',
0
+      '' => 'video/smpte292m',
0
+      '' => 'video/vnd.fvt',
0
       '' => 'video/vnd.motorola.video',
0
       '' => 'video/vnd.motorola.videop',
0
+      'mxu' => 'video/vnd.mpegurl',
0
+      'm4u' => 'video/vnd.mpegurl',
0
+      '' => 'video/vnd.nokia.interleaved-multimedia',
0
+      '' => 'video/vnd.objectvideo',
0
       '' => 'video/vnd.vivo',
0
       'avi' => 'video/x-msvideo',
0
       'movie' => 'video/x-sgi-movie',
0
-      'ice' => 'x-conference/x-cooltalk',
0
-      'html' => 'text/html',
0
-      'htm' => 'text/html'
0
+      'ice' => 'x-conference/x-cooltalk'
0
     );
0
   return array_key_exists($extension, $types) ? $types[$extension] : false;
0
 }
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
25
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
39
40
41
 
 
 
 
 
 
42
43
44
45
 
 
46
47
48
49
 
 
50
51
52
53
 
 
54
55
56
57
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
63
64
 
65
66
67
68
69
70
71
72
73
74
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
77
78
79
80
81
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
84
 
 
 
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
121
122
123
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
128
129
130
131
132
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
135
136
137
138
139
140
141
142
143
144
145
146
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170
171
172
173
174
175
176
177
178
179
180
181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
183
184
185
186
187
188
189
190
191
192
193
194
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
197
198
199
200
201
202
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
204
205
 
 
206
207
208
209
210
211
212
213
214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
215
216
217
 
 
 
 
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
233
234
235
 
 
 
 
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
273
274
275
276
277
278
279
280
281
282
283
284
285
 
 
 
 
 
 
286
287
288
289
290
 
 
291
292
293
294
295
296
297
298
299
300
301
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
324
325
 
 
 
 
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
343
344
345
346
347
348
349
350
351
352
 
 
 
 
 
353
354
355
356
357
 
358
359
360
361
362
363
 
364
365
366
367
368
369
370
371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
373
374
375
376
377
378
379
380
381
382
 
 
 
 
 
383
384
385
386
387
 
 
388
389
390
391
392
393
394
395
396
397
398
399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
401
402
403
404
405
406
407
408
409
410
411
 
 
 
 
 
412
413
414
415
416
 
 
417
418
419
420
421
422
423
 
 
 
424
425
426
427
...
1
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
 
 
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
98
 
 
 
99
100
101
102
103
104
105
 
 
 
106
107
108
 
 
 
109
110
111
 
 
 
112
113
114
 
115
116
 
 
 
 
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
 
 
139
140
 
 
 
 
 
 
 
 
 
 
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
 
 
 
 
 
 
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
 
193
194
195
196
197
198
 
 
 
 
 
 
 
 
 
 
 
 
 
199
 
 
 
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
 
 
 
 
 
 
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
 
 
 
 
 
 
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
 
 
 
 
 
 
 
 
 
 
 
 
 
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
 
 
 
 
 
 
 
 
 
 
 
 
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
 
 
 
 
 
 
 
 
 
 
 
 
 
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
 
 
 
 
 
 
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
 
621
622
623
624
 
 
 
 
 
 
 
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
 
 
651
652
653
654
655
656
 
 
 
 
 
 
 
 
 
 
 
 
 
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
 
 
685
686
687
688
689
690
 
 
 
 
 
 
 
 
 
 
 
 
 
 
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
 
 
 
 
 
 
 
 
 
 
 
 
 
753
754
755
756
757
758
759
 
 
 
 
760
761
762
 
 
 
 
 
 
 
 
 
 
 
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
 
 
827
828
829
830
831
832
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
 
 
 
 
 
 
 
 
 
 
860
861
862
863
864
865
866
867
868
 
869
870
871
872
873
874
 
875
876
 
 
 
 
 
 
 
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
 
 
 
 
 
 
 
 
 
 
901
902
903
904
905
906
 
 
 
 
907
908
909
 
 
 
 
 
 
 
 
 
 
 
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
 
 
 
 
 
 
 
 
 
 
 
936
937
938
939
940
941
 
 
 
 
942
943
944
 
 
 
 
 
 
945
946
947
948
949
950
951
0
@@ -1,426 +1,950 @@
0
 <?php
0
 
0
-/*
0
-Creates a form for the specified object
0
-*/
0
-function form($object, $url_options = array(), $html_options = array()) {
0
-  $data = start_form_tag($url_options, $html_options);
0
-  foreach (valid_fields($object) as $field => $value) {
0
-    $data .= '<p><label>' . humanize($field) . '</label>';
0
-    $data .= input($object, $field);
0
-    $data .= '</p>';
0
-  }
0
-  $data .= empty($url_options['id']) ? submit_tag('Create') : submit_tag('Update');
0
-  $data .= end_form_tag();
0
-  return $data;
0
-}
0
-
0
-/*
0
-Prints a start form tag to the url specified
0
-*/
0
-function start_form_tag($url_options, $html_options = array()) {
0
+# form($object, $url_parameters, $html_options = array(), $submit_button_value = false)
0
+# =====================================================================================
0
+#
0
+# Generates the html to create a form for the specified active record object.
0
+# The function creates the appropiate field tag for every object field (textarea for text field, textfield for string, etc.).
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * url_parameters: Array with information to generate the url.
0
+# * html_options: An array with optional information to create the form tag.
0
+# * submit_button_value: The value for the form submit button.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function form($object, $url_parameters, $html_options = array(), $button_text = false) {
0
+  $data = start_form_tag($url_parameters, $html_options);
0
+  foreach (valid_fields($object) as $field => $value)
0
+    $data .= '<p><label for="' . $object->_class_name . '[' . $field . ']">' . ($field) . '</label>' . input($object, $field) . '</p>';
0
+  return $data . submit_tag(pick($submit_button_value, $object->new_record() ? 'Create' : 'Update')) . end_form_tag();
0
+}
0
+
0
+# start_form_tag($url_parameters, $html_options = array())
0
+# ========================================================
0
+#
0
+# Generates the html to create a start form tag to pointing to the generated url for the given url parameters.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * url_parameters: Array with information to generate the url.
0
+# * html_options: An array with optional information to create the form tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function start_form_tag($url_parameters, $html_options = array()) {
0
   $html_options = array_merge(array('multipart' => false, 'method' => 'post'), $html_options);
0
-  return '<form action="' . url_for($url_options) . '"' . ($html_options['multipart'] ? ' enctype="multipart/form-data" ' : '') . construct_attributes($html_options) . '>';
0
-}
0
-
0
-/*
0
-Prints a end form tag
0
-*/
0
+  return '<form action="' . url_for($url_parameters) . '"' . ($html_options['multipart'] ? ' enctype="multipart/form-data" ' : '') . construct_attributes($html_options) . '>';
0
+}
0
+
0
+# end_form_tag()
0
+# ==============
0
+#
0
+# Generates the html to create the code for a end form tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function end_form_tag() {
0
   return '</form>';
0
 }
0
 
0
-/*
0
-Returns a default input tag for the type of object returned by the method
0
-*/
0
+# input($object, $attribute, $html_options = array())
0
+# ===================================================
0
+#
0
+# Generates the html to create an input tag for the given attribute on the given object.
0
+# The tag type is created appropiately for the given attribute type.
0
+# Boolean => check_box.
0
+# Integer, Decimal, String => text_field.
0
+# Text => text_area.
0
+# Date, Time => Select.
0
+# DateTime => 2 selects.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute on the object for the creation of the tag.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function input($object, $attribute, $html_options = array()) {
0
-  $data = '';
0
   switch ($object->type_of_attribute($attribute)) {
0
-    case 'boolean':                  $data .= check_box($object, $attribute, $html_options); break;
0
-    case 'integer': case 'decimal': case 'string':   $data .= text_field($object, $attribute, $html_options); break;
0
-    case 'text':                   $data .= text_area($object, $attribute, $html_options); break;
0
+    case 'boolean':
0
+      return check_box($object, $attribute, $html_options);
0
+    case 'integer': case 'decimal': case 'string':
0
+      return text_field($object, $attribute, $html_options);
0
+    case 'text':
0
+      return text_area($object, $attribute, $html_options);
0
     case 'date':
0
-      $data .= get_date($object->$attribute, $year, $month, $day);
0
-      $data .= select_date(array('year' => $year, 'month' => $month, 'day' => $day), array(), array(), $html_options);
0
-      break;
0
+      $data = get_date($object->$attribute, $year, $month, $day);
0
+      return $data . select_date(array('year' => $year, 'month' => $month, 'day' => $day), array(), array(), $html_options);
0
     case 'time':
0
-      $data .= get_time($object->$attribute, $hour, $minute, $second);
0
-      $data .= select_time(array('hour' => $hour, 'minute' => $minute, 'second' => $second), array(), array(), $html_options);
0
-      break;
0
+      $data = get_time($object->$attribute, $hour, $minute, $second);
0
+      return $data . select_time(array('hour' => $hour, 'minute' => $minute, 'second' => $second), array(), array(), $html_options);
0
     case 'datetime':
0
-      $data .= get_datetime($object->$attribute, $year, $month, $day, $hour, $minute, $second);
0
-      $data .= select_datetime(array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second), array(), array(), $html_options);
0
-      break;
0
+      $data = get_datetime($object->$attribute, $year, $month, $day, $hour, $minute, $second);
0
+      return $data . select_datetime(array('year' => $year, 'month' => $month, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second), array(), array(), $html_options);
0
   }
0
-  return $data;
0
 }
0
 
0
-/*
0
-Generates a form containing a single button that submits to the URL created by the set of options
0
-*/
0
-function button_to($name, $options = array(), $html_options = array()) {
0
+# button_to($value, $url_parameters, $html_options = array())
0
+# ===========================================================
0
+#
0
+# Generates the html to create a form containing a single button that submits to the URL created by the set of parameters.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value for the submit button.
0
+# * url_parameters: Array with information to generate the url.
0
+# * html_options: An array with optional information to create the tag (multipart, method) and the input tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function button_to($value, $url_parameters, $html_options = array()) {
0
   $html_options = array_merge(array('multipart' => false, 'method' => 'post'), $html_options);
0
-
0
-  $content = '<input type="submit" value="' . $name . '"';
0
+  $content = '<input type="submit" value="' . $value . '"';
0
   foreach ($html_options as $option => $value)
0
-    if ($option != 'multipart' && $option != 'method' && $option != 'confirm')   $content .= ' ' . $option . '="' . $value . '"';
0
-    elseif ($option == 'confirm')                        $content .= ' onClick="if (!confirm(\'' . $value . '\')){return false}" ';
0
-  $content .= ' />';
0
-
0
-  return content_tag('form', $content, array_merge(array('action' => url_for($options), 'method' => $html_options['method'])), ($html_options['multipart'] ? array('enctype' =>'multipart/form-data') : array()));
0
-}
0
-
0
-/*
0
-Returns a button that trigger a JavaScript function using the onclick handler
0
-*/
0
+    if ($option != 'multipart' && $option != 'method' && $option != 'confirm')
0
+      $content .= ' ' . $option . '="' . $value . '"';
0
+    elseif ($option == 'confirm')
0
+      $content .= ' onclick="if (!confirm(\'' . $value . '\')){return false}" ';
0
+  return content_tag('form', $content . ' />', array_merge(array('action' => url_for($url_parameters), 'method' => $html_options['method'])), ($html_options['multipart'] ? array('enctype' =>'multipart/form-data') : array()));
0
+}
0
+
0
+# button_to_function($value, $function)
0
+# =====================================
0
+#
0
+# Generates the html to create button that trigger a JavaScript function using the onclick handler.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value for the button.
0
+# * function: The name of the javascript function.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function button_to_function($value, $function) {
0
-  return tag('input', array('type' => 'button', 'value' => $value, 'onclick' => parse_javascript_function_parameter($function)));
0
-}
0
-
0
-/*
0
-Creates a submit button with the text value as the caption
0
-*/
0
+  return tag('input', array('type' => 'button', 'value' => $value, 'onclick' => $function));
0
+}
0
+
0
+# submit_tag($value = 'Save changes', $options = array())
0
+# =======================================================
0
+#
0
+# Generates the html to create a submit button with the text value as the caption.
0
+# A special value on the options array is the <disable_with> value, that will disable the button and set the given value
0
+# on it when the user click it.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * value: The value for the submit button.
0
+# * options: An array with optional information to create the tag (multipart, method) and the input tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function submit_tag($value = 'Save changes', $options = array()) {
0
-  $options['onclick'] = empty($options['disable_with']) ? false : 'this.disabled=true;this.value="' . $options['disable_with'] . '";this.form.submit();' . $options['onclick'];
0
+  $options = array_merge(array('disable_with' => false), $options);
0
+  $options['onclick'] = $options['disable_with'] ? 'this.disabled=true;this.value="' . $options['disable_with'] . '";this.form.submit();' . $options['onclick'] : false;
0
+  $options['disable_with'] = false;
0
   return tag('input', array_merge(array('type' => 'submit', 'value' => $value, 'onclick' => $options['onclick']), $options));
0
 }
0
 
0
-/*
0
-Prints a text_field relationed with the object passed
0
-*/
0
-function text_field($object, $attribute, $html_options = array()) {
0
-  return text_field_tag(get_class($object) . '[' . $attribute . ']', $object->$attribute, $html_options);
0
-}
0
-
0
-/*
0
-Prints a text field with the content on $content var
0
-*/
0
-function text_field_tag($name, $content = false, $html_options = array()) {
0
-  return tag('input', array_merge(array('type' => 'text', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name']), 'value' => $content), $html_options));
0
-}
0
 
0
-/*
0
-Prints a textarea relationed with the object passed
0
-*/
0
+# text_field($object, $attribute, $html_options = array())
0
+# ========================================================
0
+#
0
+# Generates the html to create a text field relationed with the given attribute object.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the textfield for.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function text_field($object, $attribute, $html_options = array()) {
0
+  return text_field_tag($object->_class_name . '[' . $attribute . ']', $object->$attribute, $html_options);
0
+}
0
+
0
+# text_field_tag($name, $value = false, $html_options = array())
0
+# ==============================================================
0
+#
0
+# Generates the html to createa a text field.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * name: The name for the field.
0
+# * value: The value for the field.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function text_field_tag($name, $value = false, $html_options = array()) {
0
+  $html_options = array_merge(array('name' => false), $html_options);
0
+  $name = pick($html_options['name'], $name);
0
+  return tag('input', array_merge(array('type' => 'text', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', $name), 'value' => $value), $html_options));
0
+}
0
+
0
+# text_area($object, $attribute, $html_options = array())
0
+# =======================================================
0
+#
0
+# Generates the html to create a textarea relationed with the given attribute object.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the textarea for.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function text_area($object, $attribute, $html_options = array()) {
0
-  return text_area_tag(get_class($object) . '[' . $attribute . ']', $object->$attribute, $html_options);
0
-}
0
-
0
-/*
0
-Prints a textarea field with the content on $content var
0
-*/
0
-function text_area_tag($name, $content = false, $html_options = array()) {
0
-  $html_options = array_merge(array('rows' => 8, 'cols' => 28), $html_options);
0
-  return content_tag('textarea', $content, array_merge(array('name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name'])), $html_options));
0
-}
0
-
0
-/*
0
-Prints a radiobutton relationed with the object passed
0
-*/
0
+  return text_area_tag($object->_class_name . '[' . $attribute . ']', $object->$attribute, $html_options);
0
+}
0
+
0
+# text_area_tag($name, $value = false, $html_options = array())
0
+# =============================================================
0
+#
0
+# Generates the html to createa a textarea control.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * name: The name for the field.
0
+# * value: The value for the field.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function text_area_tag($name, $value = false, $html_options = array()) {
0
+  $html_options = array_merge(array('rows' => 8, 'cols' => 28, 'name' => false), $html_options);
0
+  $name = pick($html_options['name'], $name);
0
+  return content_tag('textarea', $value, array_merge(array('name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', $name)), $html_options));
0
+}
0
+
0
+# radio_button($object, $attribute, $tag_value, $html_options = array())
0
+# ======================================================================
0
+#
0
+# Generates the html to create a radio button field relationed with the given attribute object.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the textfield for.
0
+# * tag_value: The value for the radio field tag.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function radio_button($object, $attribute, $tag_value, $html_options = array()) {
0
-  return radio_button_tag(get_class($object) . '[' . $attribute . ']"', $object->$attribute, ($tag_value == $object->$attribute ? true : false), $html_options);
0
-}
0
-
0
-/*
0
-Creates a radio button
0
-*/
0
+  return radio_button_tag($object->_class_name . '[' . $attribute . ']"', $object->$attribute, ($tag_value == $object->$attribute ? true : false), $html_options);
0
+}
0
+
0
+# radio_button_tag($name, $value = false, $html_options = array())
0
+# ================================================================
0
+#
0
+# Generates the html to createa a radio button control.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * name: The name for the field.
0
+# * value: The value for the field.
0
+# * checked: A boolean to determine if the radio button is checked.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function radio_button_tag($name, $value, $checked = false, $options = array()) {
0
-  return tag('input', array_merge(array('type' => 'radio', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name']), 'value' => $value, 'checked' => $checked), $options));
0
-}
0
-
0
-/*
0
-Works just like text_field, but returns an input tag of the "file" type instead
0
-*/
0
+  $html_options = array_merge(array('name' => false), $html_options);
0
+  $name = pick($html_options['name'], $name);
0
+  return tag('input', array_merge(array('type' => 'radio', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', $name), 'value' => $value, 'checked' => $checked), $options));
0
+}
0
+
0
+# file_field($object, $attribute, $html_options = array())
0
+# ========================================================
0
+#
0
+# Generates the html to create a file field relationed with the given attribute object.
0
+# Works just like text_field, but returns an input tag of the "file" type instead.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the file field for.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function file_field($object, $attribute, $html_options = array()) {
0
-  return file_field_tag(get_class($object) . '[' . $attribute . ']', $html_options);
0
-}
0
-
0
-/*
0
-Creates a file upload field
0
-*/
0
-function file_field_tag($name, $options = array()) {
0
-  return tag('input', array_merge(array('type' => 'file', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name'])), $options));
0
-}
0
-
0
-/*
0
-Creates a password field associated with the attribute on the object
0
-*/
0
+  return file_field_tag($object->_class_name . '[' . $attribute . ']', $html_options);
0
+}
0
+
0
+# file_field_tag($name, $html_options = array())
0
+# ==============================================
0
+#
0
+# Generates the html to createa a file field control.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * name: The name for the field.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function file_field_tag($name, $html_options = array()) {
0
+  $html_options = array_merge(array('name' => false), $html_options);
0
+  $name = pick($html_options['name'], $name);
0
+  return tag('input', array_merge(array('type' => 'file', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', $name)), $html_options));
0
+}
0
+
0
+# password_field($object, $attribute, $html_options = array())
0
+# ============================================================
0
+#
0
+# Generates the html to create a password field relationed with the given object.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the password field for.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function password_field($object, $attribute, $html_options = array()) {
0
-  return password_field_tag(get_class($object) . '[' . $attribute . ']', $object->$attribute, $html_options);
0
-}
0
-
0
-/*
0
-Creates a password field
0
-*/
0
-function password_field_tag($name = 'password', $value = null, $options = array()) {
0
-  return tag('input', array_merge(array('type' => 'password', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name']), 'value' => $value), $options));
0
-}
0
-
0
-/*
0
-Displays an image which when clicked will submit the form
0
-*/
0
-function image_submit_tag($source, $options = array()) {
0
-  return tag('input', array_merge(array('type' => 'image', 'src' => image_path($source)), $options));
0
-}
0
-
0
-/*
0
-Works just like text_field, but returns an input tag of the "hidden" type instead
0
-*/
0
+  return password_field_tag($object->_class_name . '[' . $attribute . ']', $object->$attribute, $html_options);
0
+}
0
+
0
+# password_field_tag($name, $value = false, $html_options = array())
0
+# ==================================================================
0
+#
0
+# Generates the html to createa a file field field.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * name: The name for the field.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function password_field_tag($name = 'password', $value = false, $options = array()) {
0
+  $html_options = array_merge(array('name' => false), $html_options);
0
+  $name = pick($html_options['name'], $name);
0
+  return tag('input', array_merge(array('type' => 'password', 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', $name), 'value' => $value), $options));
0
+}
0
+
0
+# image_submit_tag($source, $html_options = array())
0
+# ==================================================
0
+#
0
+# Generates the html to create an image which when clicked will submit a form.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * source: The source path for the image.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
+function image_submit_tag($source, $html_options = array()) {
0
+  return tag('input', array_merge(array('type' => 'image', 'src' => image_path($source)), $html_options));
0
+}
0
+
0
+# hidden_field($object, $attribute, $html_options = array())
0
+# ==========================================================
0
+#
0
+# Generates the html to create a hidden field relationed with the given attribute object.
0
+#
0
+#
0
+#
0
+# Arguments
0
+# ---------
0
+#
0
+# * object: The active record object.
0
+# * attribute: The attribute to create the hidden field for.
0
+# * html_options: An array with optional information to create the tag.
0
+#
0
+#
0
+#
0
+# Returns
0
+# -------
0
+#
0
+# * a string with the generated html code.
0
 function hidden_field($object, $attribute, $html_options = array()) {
0
-  return hidden_field_tag(get_class($object) . '[' . $attribute . ']', $object->$attribute, $html_options);
0
-}
0
-/*
0
-Creates a hidden field
0
-*/
0
-function hidden_field_tag($name = 'hidden', $value = null, $options = array()) {
0
-  return tag('input', array_merge(array('type' => 'hidden', 'value' => $value, 'name' => $name, 'id' => ereg_replace('\[([[:alnum:]_-]*)\]', '_\\1', empty($html_options['name']) ? $name : $html_options['name'])), $options));
0
-}
0
-
0