a pastebin project

Stuff

  1. <?php
  2.  
  3. class utils {
  4.         function make_slug($text) {
  5.                 $text = preg_replace("/[^(-)(_)a-zA-Z0-9\\.\s]/i","", $text);
  6.                 $text = preg_replace("/[\s]/i", "-", $text);
  7.                 $text = strtolower($text);
  8.                 return $text;
  9.         }
  10.  
  11.  
  12.         function get_file_extension($filename) {
  13.                 global $allowed_extensions;
  14.                 foreach($allowed_extensions as $k=> $extension) {
  15.                         if($k == count($allowed_extensions) - 1){
  16.                                 $pat_ext .= "(" . $extension . ")";
  17.                         }
  18.                         else{
  19.                                 $pat_ext .= "(" . $extension . ")|";
  20.                         }
  21.                 }
  22.  
  23.                 $pattern = "/^.+\.(" . $pat_ext . ")$/i"; //
  24.                 if(preg_match($pattern, $filename, $ext)) {
  25.                         return $ext[0][0];
  26.                 }
  27.                 else {
  28.                         return false;
  29.                 }
  30.         }
  31.  
  32.         function drawSelect($id, $array, $first, $display, $optdisplay, $value, $selected, $attributes) {
  33.                 echo "\n<tr><td><label for=\"" . $id . "\">" . $display . ":</label></td><td><select " . $attributes . " id=\"" . $id . "\" name=\"" . $id . "\">";
  34.                 echo "\n<option value=\"-777\">" . $first . "</option>";
  35.                 if(count($array) > 0) {
  36.                         foreach($array as $k=> $item) {
  37.                                 if($item[$value] == $selected) {
  38.                                         echo "\n<option selected=\"selected\" id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$optdisplay] . "</option>";
  39.                                 }
  40.                                 else {
  41.                                         echo "\n<option id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$optdisplay] . "</option>";
  42.                                 }
  43.                         }
  44.                 }
  45.                 echo "</td></tr>";
  46.         }
  47.  
  48.         function drawInput($id, $type, $display, $value = null, $attributes = null, $helper = null) {
  49.                 if($value != null) {
  50.                         $value = "value=\"" . $value . "\"";
  51.                 }
  52.                 if($helper != null) {
  53.                         $helper = "<br /><span class=\"helper\">" . $helper . "</span>";
  54.                 }
  55.         echo "\n<tr><td><label for=\"" . $id . "\">" . $display . ":</label></td><td><input type=\"" . $type . "\" id=\"" . $id . "\" name=\"" . $id . "\" ". $attributes . " " . $value . " />" . $helper . "</td></tr>";
  56.     }
  57.  
  58.         function drawCheckboxes($data, $selected, $display_text, $display, $dis_value, $name, $attributes) {
  59.                 $i=0;
  60.                 echo "\n<tr><td style=\"vertical-align: top\">" . $display_text . "</td><td>";
  61.                 foreach($data as $field=>$value) {
  62.                         if(is_array($selected)) {
  63.                                 if(in_array($value[$dis_value], $selected)) {
  64.                                         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 />";
  65.                                 }
  66.                         }
  67.                         else {
  68.                                 echo "\n<input " . $attributes . " type=\"checkbox\" value=\"" . $value[$dis_value] . "\" name=\"" . $name . "\" id=\"". $name ."_". $i ."\" /><label for=\"" . $name . "_" . $i ."\">" . $value[$display] . "</label><br />";
  69.                         }
  70.                         $i++;
  71.                 }
  72.                 echo "</p></td></tr>";
  73.         }
  74.  
  75.         function drawRadios($id, $data, $selected, $display, $value) {
  76.                 echo "\n<tr><td colspan=\"2\">";
  77.                 foreach($data as $field=>$value) {
  78.                         echo "<input type=\"radio\" value=\"" . $data[$value] . "\" id=\"" . $data[$id]. "\" /><label for=\"" . $data[$id] ."\">" . $data[$display] . ":</label><br />";
  79.                 }
  80.                 echo "</td></tr>";
  81.         }
  82.  
  83.         function drawTextArea($id, $value, $display, $attributes) {
  84.                 echo "\n<tr><td style=\"vertical-align: top\"><label for=\"" . $id . "\">" . $display . ":</label></td><td><textarea " . $attributes . " id=\"" . $id . "\" name=\"" . $id . "\">" . $value . "</textarea>";
  85.         }
  86.  
  87.         function drawSubmit($id, $value, $attributes = null) {
  88.                 echo "\n<tr><td>&nbsp;</td><td><input type=\"submit\" id=\"" . $id . "\" value=\"" . $value . '' . "\"" . $attributes . " /></td></tr>";
  89.         }
  90.  
  91.         function drawRatings($id, $low_name, $high_name, $scale_start, $scale_end, $name) {
  92.                 echo "\n<tr><td>" .$scale_start . "<br />". $low_name . "</td>";
  93.                 for($i=$scale_start+1;$i<$scale_end;$i++) {
  94.                         echo "\n<td>" . $i . "</td>";
  95.                 }
  96.                 echo "\n<td>" .$scale_end . "<br />". $high_name . "</td></tr>";
  97.                 echo "\n<tr>";
  98.                 for($j=$scale_start;$j<=$scale_end;$j++) {
  99.                         echo "\n<td><input type=\"radio\" value=\"" . $j . "\" name=\"" . $name . "\" id=\"" . $name . "_" . $j . "\" /></td>";
  100.                 }
  101.                 echo "\n</tr>";
  102.         }
  103.  
  104.         function make_options($array, $display, $value, $selected) {
  105.                 if(count($array) > 0) {
  106.                         foreach($array as $k=> $item) {
  107.                                 if($item == $selected) {
  108.                                         $output .= "\n<option selected=\"selected\" id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$display] . "</option>";
  109.                                 }
  110.                                 else {
  111.                                         $output .= "\n<option id=\"" . $item[$value] . "\" value=\"" . $item[$value] . "\">" . $item[$display] . "</option>";
  112.                                 }
  113.                         }
  114.                 }
  115.                 return $output;
  116.         }
  117.  
  118.         function luhn($str) {
  119.                 $odd = !strlen($str)%2;
  120.                 $sum = 0;
  121.                 for($i=0;$i<strlen($str);++$i) {
  122.                         $n=0+$str[$i];
  123.                         $odd=!$odd;
  124.                         if($odd) {
  125.                                 $sum+=$n;
  126.                         } else {
  127.                                 $x=2*$n;
  128.                                 $sum+=$x>9?$x-9:$x;
  129.                         }
  130.                 }
  131.                 return(($sum%10)==0);
  132.         }
  133.  
  134.         function get_random_image($image_dir) {
  135.                 if (is_dir($image_dir)) {
  136.                         if ($dh = opendir($image_dir)) {
  137.                                 while (($the_file = readdir($dh)) !== false) {
  138.                                         if ($the_file != "." && $the_file != "..") {
  139.                                                 $my_files[] = $the_file;
  140.                                         }
  141.                                 }
  142.                         }
  143.                 }
  144.  
  145.                 return $my_files[array_rand($my_files)];
  146.         }
  147.  
  148.  
  149.         function is_valid_email($email) {
  150.                 $addr_spec = '([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'.
  151.                                         '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|\\x22([^\\x0d'.
  152.                                         '\\x22\\x5c\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x22)'.
  153.                                         '(\\x2e([^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e'.
  154.                                         '\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+|'.
  155.                                         '\\x22([^\\x0d\\x22\\x5c\\x80-\\xff]|\\x5c\\x00'.
  156.                                         '-\\x7f)*\\x22))*\\x40([^\\x00-\\x20\\x22\\x28'.
  157.                                         '\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d'.
  158.                                         '\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-\\x5d\\x80-\\xff'.
  159.                                         ']|\\x5c[\\x00-\\x7f])*\\x5d)(\\x2e([^\\x00-\\x20'.
  160.                                         '\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40'.
  161.                                         '\\x5b-\\x5d\\x7f-\\xff]+|\\x5b([^\\x0d\\x5b-'.
  162.                                         '\\x5d\\x80-\\xff]|\\x5c[\\x00-\\x7f])*\\x5d))*';
  163.                 return preg_match("!^$addr_spec$!", $email);
  164.         }
  165.  
  166. }
  167.  
  168.  
  169. ?>

advertising

Create a Paste

Please enter your new post below (or upload a file instead):





Please note that information posted here will not expire by default. If you 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.

fantasy-obligation