- Stuff
- Friday, June 8th, 2007 at 1:20:05pm MDT
- <?php
- class utils {
- function make_slug($text) {
- return $text;
- }
- function get_file_extension($filename) {
- global $allowed_extensions;
- foreach($allowed_extensions as $k=> $extension) {
- $pat_ext .= "(" . $extension . ")";
- }
- else{
- $pat_ext .= "(" . $extension . ")|";
- }
- }
- $pattern = "/^.+\.(" . $pat_ext . ")$/i"; //
- return $ext[0][0];
- }
- else {
- return false;
- }
- }
- function drawSelect($id, $array, $first, $display, $optdisplay, $value, $selected, $attributes) {
- echo "\n<tr><td><label for=\"" . $id . "\">" . $display . ":</label></td><td><select " . $attributes . " id=\"" . $id . "\" name=\"" . $id . "\">";
- foreach($array as $k=> $item) {
- if($item[$value] == $selected) {
- echo "\n<option selected=\"selected\" id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$optdisplay] . "</option>";
- }
- else {
- echo "\n<option id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$optdisplay] . "</option>";
- }
- }
- }
- echo "</td></tr>";
- }
- function drawInput($id, $type, $display, $value = null, $attributes = null, $helper = null) {
- if($value != null) {
- $value = "value=\"" . $value . "\"";
- }
- if($helper != null) {
- $helper = "<br /><span class=\"helper\">" . $helper . "</span>";
- }
- echo "\n<tr><td><label for=\"" . $id . "\">" . $display . ":</label></td><td><input type=\"" . $type . "\" id=\"" . $id . "\" name=\"" . $id . "\" ". $attributes . " " . $value . " />" . $helper . "</td></tr>";
- }
- function drawCheckboxes($data, $selected, $display_text, $display, $dis_value, $name, $attributes) {
- $i=0;
- foreach($data as $field=>$value) {
- echo "\n<input " . $attributes . " checked=\"checked\" type=\"checkbox\" value=\"" . $value[$dis_value] . "\" name=\"" . $name . "\" id=\"". $name ."_". $i ."\" /><label for=\"" . $name . "_" . $i ."\">" . $value[$display] . "</label><br />";
- }
- }
- else {
- echo "\n<input " . $attributes . " type=\"checkbox\" value=\"" . $value[$dis_value] . "\" name=\"" . $name . "\" id=\"". $name ."_". $i ."\" /><label for=\"" . $name . "_" . $i ."\">" . $value[$display] . "</label><br />";
- }
- $i++;
- }
- echo "</p></td></tr>";
- }
- function drawRadios($id, $data, $selected, $display, $value) {
- echo "\n<tr><td colspan=\"2\">";
- foreach($data as $field=>$value) {
- echo "<input type=\"radio\" value=\"" . $data[$value] . "\" id=\"" . $data[$id]. "\" /><label for=\"" . $data[$id] ."\">" . $data[$display] . ":</label><br />";
- }
- echo "</td></tr>";
- }
- function drawTextArea($id, $value, $display, $attributes) {
- echo "\n<tr><td style=\"vertical-align: top\"><label for=\"" . $id . "\">" . $display . ":</label></td><td><textarea " . $attributes . " id=\"" . $id . "\" name=\"" . $id . "\">" . $value . "</textarea>";
- }
- function drawSubmit($id, $value, $attributes = null) {
- echo "\n<tr><td> </td><td><input type=\"submit\" id=\"" . $id . "\" value=\"" . $value . '' . "\"" . $attributes . " /></td></tr>";
- }
- function drawRatings($id, $low_name, $high_name, $scale_start, $scale_end, $name) {
- for($i=$scale_start+1;$i<$scale_end;$i++) {
- }
- echo "\n<tr>";
- for($j=$scale_start;$j<=$scale_end;$j++) {
- echo "\n<td><input type=\"radio\" value=\"" . $j . "\" name=\"" . $name . "\" id=\"" . $name . "_" . $j . "\" /></td>";
- }
- echo "\n</tr>";
- }
- function make_options($array, $display, $value, $selected) {
- foreach($array as $k=> $item) {
- if($item == $selected) {
- $output .= "\n<option selected=\"selected\" id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$display] . "</option>";
- }
- else {
- $output .= "\n<option id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$display] . "</option>";
- }
- }
- }
- return $output;
- }
- function luhn($str) {
- $sum = 0;
- for($i=0;$i<strlen($str);++$i) {
- $n=0+$str[$i];
- $odd=!$odd;
- if($odd) {
- $sum+=$n;
- } else {
- $x=2*$n;
- $sum+=$x>9?$x-9:$x;
- }
- }
- return(($sum%10)==0);
- }
- function get_random_image($image_dir) {
- if ($the_file != "." && $the_file != "..") {
- $my_files[] = $the_file;
- }
- }
- }
- }
- }
- function is_valid_email($email) {
- $addr_spec = '([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
- '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d'.
- '\\x22\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)'.
- '(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e'.
- '\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|'.
- '\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c\\x00'.
- '-\\x7f)*\\x22))*\\x40([^\\x00-\\x20\\x22\\x28'.
- '\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d'.
- '\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff'.
- ']|\\x5c[\\x00-\\x7f])*\\x5d)(\\x2e([^\\x00-\\x20'.
- '\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40'.
- '\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-'.
- '\\x5d\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x5d))*';
- }
- }
- ?>
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.