Advertisement
Guest User

functions.php

a guest
Sep 30th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1. <?php
  2.  
  3. function strip_zeros_from_date($marked_string = "")
  4. {
  5.     // first remove the marked zeros
  6.     $no_zeros       = str_replace('*0', '', $marked_string);
  7.     // then remove any remaining marks
  8.     $cleaned_string = str_replace('*', '', $no_zeros);
  9.     return $cleaned_string;
  10. }
  11.  
  12. function redirect_to($location = NULL)
  13. {
  14.     if ($location != NULL) {
  15.         header("Location: {$location}");
  16.         exit;
  17.     }
  18. }
  19.  
  20. function output_message($message = "")
  21. {
  22.     if (!empty($message)) {
  23.         return "<p class=\"message\">{$message}</p>";
  24.     } else {
  25.         return "";
  26.     }
  27. }
  28.  
  29. function __autoload($class_name)
  30. {
  31.     //$class_name = strtolower($class_name);
  32.     $path = "{$class_name}.php";
  33.     if (require_once($path)) {
  34.     } else {
  35.         die("The file {$class_name}.php could not be found.");
  36.     }
  37. }
  38.  
  39. function include_layout_template($template = "")
  40. {
  41.     $b = SITE_ROOT;
  42.     include(SITE_ROOT . DS . 'public' . DS . 'layouts' . DS . $template);
  43. }
  44.  
  45. function log_action($action, $message = "")
  46. {
  47.     $logfile = SITE_ROOT . DS . 'logs' . DS . 'log.txt';
  48.     $new     = file_exists($logfile) ? false : true;
  49.     if ($handle = fopen($logfile, 'a')) { // append
  50.         $timestamp = strftime("%Y-%m-%d %H:%M:%S", time());
  51.         $content   = "{$timestamp} | {$action}: {$message}\n";
  52.         fwrite($handle, $content);
  53.         fclose($handle);
  54.         if ($new) {
  55.             chmod($logfile, 0755);
  56.         }
  57.     } else {
  58.         echo "Could not open log file for writing.";
  59.     }
  60. }
  61.  
  62. function datetime_to_text($datetime = "")
  63. {
  64.     $unixdatetime = strtotime($datetime);
  65.     return strftime("%B %d, %Y at %I:%M %p", $unixdatetime);
  66. }
  67.  
  68. function disable_magic_quotes()
  69. {
  70.     $magicStatus = get_magic_quotes_gpc();
  71.     if (get_magic_quotes_gpc()) {
  72.         $process = array(
  73.             &$_GET,
  74.             &$_POST,
  75.             &$_COOKIE,
  76.             &$_REQUEST
  77.         );
  78.         while (list($key, $val) = each($process)) {
  79.             foreach ($val as $k => $v) {
  80.                 unset($process[$key][$k]);
  81.                 if (is_array($v)) {
  82.                     $process[$key][stripslashes($k)] = $v;
  83.                     $process[] =& $process[$key][stripslashes($k)];
  84.                 } else {
  85.                     $process[$key][stripslashes($k)] = stripslashes($v);
  86.                 }
  87.             }
  88.         }
  89.         unset($process);
  90.     }
  91. }
  92.  
  93. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement