Initial commit
This commit is contained in:
107
system/SuperSmash/library/cache.php
Normal file
107
system/SuperSmash/library/cache.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
|
||||
/**************************************/
|
||||
/**** SuperSmash Framework ****/
|
||||
/**** Created By SuperSmash ****/
|
||||
/**** Started on: 25-04-2012 ****/
|
||||
/**************************************/
|
||||
|
||||
namespace system\library;
|
||||
use settings\settings;
|
||||
|
||||
if (!defined("SUPERSMASH_FRAMEWORK")){die("You cannot access this page directly!");}
|
||||
|
||||
class Cache
|
||||
{
|
||||
protected $path;
|
||||
|
||||
// Create the contructor
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = settings::getFilePath() . DS . settings::getApp() . DS . 'cache';
|
||||
}
|
||||
|
||||
// This function will set the cache path
|
||||
public function set_path($path)
|
||||
{
|
||||
// Remove any trailing slashes
|
||||
$path = rtrim($path, '/');
|
||||
$this->path = str_replace( array('\\', '/'), DS, $path );
|
||||
}
|
||||
|
||||
// This function will read and returns the contents of the cached file
|
||||
public function get($id)
|
||||
{
|
||||
// Define a file path
|
||||
$file = $this->path . DS . $id . '.cache';
|
||||
|
||||
// check if our file exists
|
||||
if(file_exists($file))
|
||||
{
|
||||
// Get our file contents and Unserialize our data
|
||||
$data = file_get_contents($file);
|
||||
$data = unserialize($data);
|
||||
|
||||
// Check out expire time, if expired, remove the file
|
||||
if($data['expire_time'] < time())
|
||||
{
|
||||
unlink($file);
|
||||
return false;
|
||||
}
|
||||
return $data['data'];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// This function will save the contents into the given file id.
|
||||
public function save($id, $contents, $expire = 86400)
|
||||
{
|
||||
// Define a file path
|
||||
$file = $this->path . DS . $id . '.cache';
|
||||
|
||||
// Create the files contents
|
||||
$data = array(
|
||||
'expire_time' => (time() + $expire),
|
||||
'data' => $contents
|
||||
);
|
||||
|
||||
// Save file and contents
|
||||
if(file_put_contents( $file, serialize($data) ))
|
||||
{
|
||||
// Try to put read/write permissions on the new file
|
||||
@chmod($file, 0777);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// This function will delete a cached file
|
||||
public function delete($id)
|
||||
{
|
||||
// Define a file path
|
||||
$file = $this->path . DS . $id . '.cache';
|
||||
|
||||
// Return the direct result of the deleting
|
||||
return unlink($file);
|
||||
}
|
||||
|
||||
// This function will delete all the cached files
|
||||
public function clear()
|
||||
{
|
||||
// get a list of all files and directories
|
||||
$files = scandir($this->path);
|
||||
foreach($files as $file)
|
||||
{
|
||||
// Define a file path
|
||||
$file = $this->path . DS . $file;
|
||||
|
||||
// We only want to delete the the cache files, not subfolders
|
||||
if($file[0] != "." && $file != 'index.html')
|
||||
{
|
||||
unlink($file); //Remove the file
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
280
system/SuperSmash/library/email.php
Normal file
280
system/SuperSmash/library/email.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
|
||||
/**************************************/
|
||||
/**** SuperSmash Framework ****/
|
||||
/**** Created By SuperSmash ****/
|
||||
/**** Started on: 25-04-2012 ****/
|
||||
/**************************************/
|
||||
|
||||
namespace system\library;
|
||||
|
||||
if (!defined("SUPERSMASH_FRAMEWORK")){die("You cannot access this page directly!");}
|
||||
|
||||
class Email
|
||||
{
|
||||
// This variable will hold the email recipient
|
||||
protected $to = '';
|
||||
|
||||
// This variable will hold an Array of carbon copy's
|
||||
protected $cc = array();
|
||||
|
||||
// This variable will hold an array of blind carbon copy's
|
||||
protected $bcc = array();
|
||||
|
||||
// This variable will hold the email subject
|
||||
protected $subject = '';
|
||||
|
||||
// This variable will hold the email message
|
||||
protected $message = '';
|
||||
|
||||
// This variable will hold an array of attachment data
|
||||
protected $attachment = array();
|
||||
|
||||
// This variable will hold the email character Set
|
||||
protected $charset = 'ISO-8859-1';
|
||||
|
||||
// This variable will hold the email boundary
|
||||
protected $boundary = '';
|
||||
|
||||
// This variable will hold the email header data
|
||||
protected $header = '';
|
||||
|
||||
// This variable will hold the textHeader
|
||||
protected $textheader = '';
|
||||
|
||||
// This variable will hold an array of errors
|
||||
public $errors = array();
|
||||
|
||||
// Create the contructor
|
||||
public function __construct()
|
||||
{
|
||||
// Set our email boundary
|
||||
$this->boundary = uniqid(time());
|
||||
}
|
||||
|
||||
// This function will send the email
|
||||
public function send()
|
||||
{
|
||||
$this->build_header();
|
||||
return mail($this->to, $this->subject, $this->message, $this->header);
|
||||
}
|
||||
|
||||
// This function will add a to recipient to the email message
|
||||
public function to($email, $name = null)
|
||||
{
|
||||
// Check if the email is valid before adding it
|
||||
if(!$this->validate($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($name == null)
|
||||
{
|
||||
$this->to = $email;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->to = $name." <".$email.">";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will add a to sender to the email message
|
||||
public function from($email, $name = null)
|
||||
{
|
||||
// Check if the email is valid before adding it
|
||||
if(!$this->validate($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($name == null)
|
||||
{
|
||||
$this->header .= "From: ".$email."\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->header .= "From: ".$name." <".$email.">\r\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will add a reply to to the email message
|
||||
public function reply_to($email, $name = null)
|
||||
{
|
||||
// Check if the email is valid before adding it
|
||||
if(!$this->validate($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if($name == null)
|
||||
{
|
||||
$this->header .= "Reply-to: ".$email."\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->header .= "Reply-to: ".$name." <".$email.">\r\n";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will add a cc to to the email message
|
||||
public function cc($email)
|
||||
{
|
||||
// Check if the email is valid before adding it
|
||||
if(!$this->validate($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->cc[] = $email;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will add a bcc to to the email message
|
||||
public function bcc($email)
|
||||
{
|
||||
// Check if the email is valid before adding it
|
||||
if(!$this->validate($email))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->bcc[] = $email;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will set the email subject
|
||||
public function subject($subject)
|
||||
{
|
||||
$this->subject = strip_tags(trim($subject));
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will add the message to the headers so we can actually send the email
|
||||
public function message($message = '', $type = 'html')
|
||||
{
|
||||
$textboundary = uniqid('textboundary');
|
||||
$this->textheader = "Content-Type: multipart/alternative; boundary=\"".$textboundary."\"\r\n\r\n";
|
||||
$this->message .= "--". $textboundary ."\r\n";
|
||||
$this->message .= "Content-Type: text/plain; charset=\"". $this->charset ."\"\r\n";
|
||||
$this->message .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
|
||||
$this->message .= strip_tags($message) ."\r\n\r\n";
|
||||
$this->message .= "--". $textboundary ."\r\n";
|
||||
$this->message .= "Content-Type: text/html; charset=\"".$this->charset ."\"\r\n";
|
||||
$this->message .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
|
||||
$this->message .= $message ."\r\n\r\n";
|
||||
$this->message .= "--". $textboundary ."--\r\n\r\n";
|
||||
}
|
||||
|
||||
// This function will add an attachment to the email message
|
||||
public function attachment($file)
|
||||
{
|
||||
// Make sure we are dealing with a real file here
|
||||
if(is_file($file))
|
||||
{
|
||||
$basename = basename($file);
|
||||
$attachmentheader = "--". $this->boundary ."\r\n";
|
||||
$attachmentheader .= "Content-Type: ".$this->mime_type($file)."; name=\"".$basename."\"\r\n";
|
||||
$attachmentheader .= "Content-Transfer-Encoding: base64\r\n";
|
||||
$attachmentheader .= "Content-Disposition: attachment; filename=\"".$basename."\"\r\n\r\n";
|
||||
$attachmentheader .= chunk_split(base64_encode(fread(fopen($file,"rb"),filesize($file))),72)."\r\n";
|
||||
$this->attachment[] = $attachmentheader;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// This function builds the email header before being sent
|
||||
protected function build_header()
|
||||
{
|
||||
// Add out Cc's
|
||||
$count = count($this->cc);
|
||||
if($count > 0)
|
||||
{
|
||||
$this->header .= "Cc: ";
|
||||
for($i=0; $i < $count; $i++)
|
||||
{
|
||||
// Add a comma if we are not on our first!
|
||||
if($i > 0)
|
||||
{
|
||||
$this->header .= ',';
|
||||
}
|
||||
$this->header .= $this->cc[$i];
|
||||
}
|
||||
$this->header .= "\r\n";
|
||||
}
|
||||
|
||||
// Add out Bcc's
|
||||
$count = count($this->bcc);
|
||||
if($count > 0)
|
||||
{
|
||||
$this->header .= "Bcc: ";
|
||||
for($i=0; $i < $count; $i++)
|
||||
{
|
||||
// Add comma if we are not on our first!
|
||||
if($i > 0)
|
||||
{
|
||||
$this->header .= ',';
|
||||
}
|
||||
$this->header .= $this->bcc[$i];
|
||||
}
|
||||
$this->header .= "\r\n";
|
||||
}
|
||||
|
||||
// Add our MINE version and X-Mailer
|
||||
$this->header .= "X-Mailer: SuperSmash Framework\r\n";
|
||||
$this->header .= "MIME-Version: 1.0\r\n";
|
||||
|
||||
// Add attachments
|
||||
$attachcount = count($this->attachment);
|
||||
if($attachcount > 0)
|
||||
{
|
||||
$this->header .= "Content-Type: multipart/mixed; boundary=\"". $this->boundary ."\"\r\n\r\n";
|
||||
$this->header .= "--". $this->boundary ."\r\n";
|
||||
$this->header .= $this->textheader;
|
||||
|
||||
if($attachcount > 0)
|
||||
{
|
||||
$this->header .= implode("", $this->attachment);
|
||||
}
|
||||
$this->header .= "--". $this->boundary ."--\r\n\r\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->header .= $this->textheader;
|
||||
}
|
||||
}
|
||||
|
||||
// This function will check if the emailAddress specified is a valid email address
|
||||
public function validate($email)
|
||||
{
|
||||
// Use PHP's built in email validator
|
||||
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
|
||||
{
|
||||
$this->errors[] = "Invalid Email: <". $email .">";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will get the mime type of a file for attachments
|
||||
public function mime_type($file)
|
||||
{
|
||||
$fileInfo = new finfo();
|
||||
return $fileInfo->file($file, FILEINFO_MIME);
|
||||
}
|
||||
|
||||
// This function will clear the current email
|
||||
public function clear()
|
||||
{
|
||||
$this->header = null;
|
||||
$this->to = null;
|
||||
$this->subject = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
193
system/SuperSmash/library/validation.php
Normal file
193
system/SuperSmash/library/validation.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/**************************************/
|
||||
/**** SuperSmash Framework ****/
|
||||
/**** Created By SuperSmash ****/
|
||||
/**** Started on: 25-04-2012 ****/
|
||||
/**************************************/
|
||||
|
||||
namespace system\library;
|
||||
|
||||
if (!defined("SUPERSMASH_FRAMEWORK")){die("You cannot access this page directly!");}
|
||||
|
||||
class Validation
|
||||
{
|
||||
// Our fields
|
||||
protected $fields;
|
||||
|
||||
// Our field rules
|
||||
protected $field_rules;
|
||||
|
||||
// A bool of whether we are debugging
|
||||
protected $debug;
|
||||
|
||||
// Our running list of errors
|
||||
protected $errors;
|
||||
|
||||
// Create the constructor
|
||||
public function __construct()
|
||||
{
|
||||
// Init the default values
|
||||
$this->fields = $_POST;
|
||||
$this->field_rules = array();
|
||||
$this->errors = array();
|
||||
}
|
||||
|
||||
// This function is used to set the rules of certain $_POST vars
|
||||
public function set($rules)
|
||||
{
|
||||
if(!is_array($rules))
|
||||
{
|
||||
showError('no_array', array('rules', 'Validation::set'), E_ERROR);
|
||||
}
|
||||
|
||||
// Add the current rules
|
||||
$this->field_rules = array_merge($this->field_rules, $rules);
|
||||
|
||||
// Allow chaining here
|
||||
return $this;
|
||||
}
|
||||
|
||||
// This function validates all the POST data that has rules set
|
||||
public function validate($debug = false)
|
||||
{
|
||||
// before we begin, make sure we have post data
|
||||
if(!empty($this->field_rules))
|
||||
{
|
||||
// Set our debugging
|
||||
$this->debug = $debug;
|
||||
|
||||
// Validate each of the fields that have rules
|
||||
foreach($this->field_rules as $field => $rules)
|
||||
{
|
||||
// Get our array of rules to process
|
||||
$rules = explode('|', $rules);
|
||||
|
||||
// Make sure that the field we are looking at exists
|
||||
if(isset($this->fields[$field]))
|
||||
{
|
||||
// Process each rule for this post var
|
||||
foreach($rules as $rule)
|
||||
{
|
||||
$result = null;
|
||||
|
||||
// We will define the param as false, if preg_match
|
||||
// finds a second value, then it will overwrite this
|
||||
$param = false;
|
||||
|
||||
if (preg_match("/^(.*?)\[(.*?)\]$/", $rule, $match))
|
||||
{
|
||||
$rule = $match[1];
|
||||
$param = $match[2];
|
||||
}
|
||||
|
||||
// Call the function that corresponds to the rule
|
||||
if (!empty($rule))
|
||||
{
|
||||
$result = $this->$rule($this->fields[$field], $param);
|
||||
}
|
||||
|
||||
// Handle errors
|
||||
if ($result === false)
|
||||
{
|
||||
$this->set_error($field, $rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (empty($this->errors));
|
||||
}
|
||||
}
|
||||
|
||||
// This function returns an array of all the errors by field name
|
||||
public function get_errors() {
|
||||
if(count($this->errors) == 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
return $this->errors;
|
||||
}
|
||||
|
||||
// This function sets an error for the $field
|
||||
protected function set_error($field, $rule)
|
||||
{
|
||||
// If debugging, we want an array of all failed validations
|
||||
if($this->debug)
|
||||
{
|
||||
if(isset($this->errors[$field]))
|
||||
{
|
||||
$this->errors[$field] .= "|".$rule;
|
||||
return;
|
||||
}
|
||||
$this->errors[$field] = $rule;
|
||||
return;
|
||||
}
|
||||
$this->errors[$field] = true;
|
||||
}
|
||||
|
||||
// This function determines if the string passed has any values
|
||||
public function required($string, $value = false)
|
||||
{
|
||||
if (!is_array($string))
|
||||
{
|
||||
// Trim white space and see if its still empty
|
||||
$string = trim($string);
|
||||
}
|
||||
return (!empty($string));
|
||||
}
|
||||
|
||||
// This function determines if the string is a valid email
|
||||
public function email($string)
|
||||
{
|
||||
if(filter_var($string, FILTER_VALIDATE_EMAIL))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// This function determines if the string passed is numeric
|
||||
public function number($string)
|
||||
{
|
||||
return (is_numeric($string));
|
||||
}
|
||||
|
||||
// This function determines if the string passed is valid URL
|
||||
public function url($string)
|
||||
{
|
||||
return (!preg_match('@^(mailto|ftp|http(s)?)://(.*)$@i', $string)) ? false : true;
|
||||
}
|
||||
|
||||
// This function determines if the string passed is a float
|
||||
public function float($string)
|
||||
{
|
||||
return (is_float($string));
|
||||
}
|
||||
|
||||
// This function determines if the string passed has a minimum value of $value
|
||||
public function min($string, $value)
|
||||
{
|
||||
if(!is_numeric($string))
|
||||
{
|
||||
return (strlen($string) >= $value);
|
||||
}
|
||||
return ($string >= $value);
|
||||
}
|
||||
|
||||
// This function determines if the string passed has a maximum value of $value
|
||||
public function max($string, $value)
|
||||
{
|
||||
if(!is_numeric($string))
|
||||
{
|
||||
return (strlen($string) <= $value);
|
||||
}
|
||||
return ($string <= $value);
|
||||
}
|
||||
|
||||
// This function determines if the string passed contains the specified pattern
|
||||
public function pattern($string, $pattern)
|
||||
{
|
||||
return (!preg_match("/".$pattern."/", $string)) ? false : true;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user