/** * */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new Error(); } return self::$instance; }
public function create_user() { // If there are no users then let's create one. $db = Database::get_instance(); $db->query('SELECT * FROM `users` LIMIT 1'); if ($db->has_rows() && !Auth::get_instance()->logged_in()) { Flash::set('<p class="flash validation">Sorry but to create new users, you must be logged in.</p>'); Core_Helpers::redirect(WEB_ROOT . 'login/'); } $validator = Error::instance(); if (isset($_POST['email'])) { $validator->email($_POST['email'], 'email'); $validator->blank($_POST['username'], 'username'); $validator->blank($_POST['password'], 'password'); $validator->passwords($_POST['password'], $_POST['confirm_password'], 'confirm_password'); $user = new Users(); if ($user->select(array('username' => $_POST['username']))) { $validator->add('username', 'The username <strong>' . htmlspecialchars($_POST['username']) . '</strong> is already taken.'); } if ($validator->ok()) { $user = new Users(); $user->load($_POST); $user->level = 'admin'; $user->insert(); Flash::set('<p class="flash success">User created successfully.</p>'); Core_Helpers::redirect(WEB_ROOT . 'login/'); } } $this->data['error'] = $validator; $this->load_template('create_user'); }
/** * Static getter for the singleton instnace * @return Error */ public static function getInstance() { if (self::$instance == null) { self::$instance = new self(); } return self::$instance; }
/** * Singleton function * * @access public * @return object instance of the class */ public static function singleton() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public static function getInstance() { if (!self::$instance) { // If no instance then make one self::$instance = new self(); } return self::$instance; }
public static function init($args = null) { if (is_null(self::$instance)) { self::$instance = new Error($args); } return self::$instance; }
public function validate() { $field_output = ''; foreach ($this->fields as $fields) { foreach ($fields as $name => $info) { if (isset($info['validation'])) { $validation = explode(',', $info['validation']); foreach ($validation as $validator) { // TODO: Make this more robust, right now, only handles very basic error methods if (!empty($validator)) { Error::instance()->{$validator}($info['value'], $info['name'], $info['display']); } } } } } }
public function save_object() { $this->validate(); $validator = Error::instance(); if ($validator->ok()) { // Loop through iterations and build new field names for ($i = 0; $i < $this->iterations; $i++) { $object_copy = $this->current_object; foreach ($this->fields[$i] as $object_name => $field) { // Make directories, TODO: Find more efficient way to do this @mkdir('./files/uploads/'); @mkdir('./files/uploads/original/'); @mkdir('./files/uploads/large/'); @mkdir('./files/uploads/medium/'); @mkdir('./files/uploads/small/'); @mkdir('./files/uploads/cropped/'); if ($field['type'] === 'file') { // Check if a session of images to crop already exists, if so we need to overwrite it if (isset($_SESSION['crop_images'])) { unset($_SESSION['crop_images']); } if (!empty($_FILES[$field['name']]['name'])) { $gd = new Gd_Image(); // Check if file is already existing and start deleting if (strlen($object_copy->{$object_name}) > 0) { @unlink('./files/uploads/original/' . $object_copy->{$field}['name']); @unlink('./files/uploads/large/' . $object_copy->{$field}['name']); @unlink('./files/uploads/medium/' . $object_copy->{$field}['name']); @unlink('./files/uploads/small/' . $object_copy->{$field}['name']); } // If a file of that name already exists add random string to begining else keep same name if (file_exists('./files/uploads/original/' . $_FILES[$field['name']]['name'])) { // rand_string() is located in core/extfunctions.inc.php $newname = $object_copy->{$object_name} = str_replace(' ', '', rand_string() . '_' . $_FILES[$field['name']]['name']); } else { $newname = $object_copy->{$object_name} = str_replace(' ', '', $_FILES[$field['name']]['name']); } $newname = str_replace(' ', '', $newname); // TODO: There should be a way in options to pass multiple image locations and sizes if ($gd->loadFile($_FILES[$field['name']]['tmp_name'])) { $gd->scale_safe('1800', '1800'); $gd->save_as('./files/uploads/original/' . $newname); $gd->scale_safe('700', '700'); $gd->save_as('./files/uploads/large/' . $newname); $gd->scale_safe('300', '300'); $gd->save_as('./files/uploads/medium/' . $newname); $gd->scale_crop('200', '200'); $gd->save_as('./files/uploads/cropped/' . $newname); $gd->load_file($_FILES[$field['name']]['tmp_name']); $gd->scale_safe('150', '150'); $gd->save_as('./files/uploads/small/' . $newname); $_SESSION['crop_images'][str_replace(array('.', ' '), '', $newname)] = $newname; } else { move_uploaded_file($_FILES[$field['name']]['tmp_name'], './files/uploads/original/' . $newname); } } } elseif ($field['type'] === 'timestamp') { $object_copy->{$object_name} = date('Y-m-d H:i:s', strtotime(str_replace('@', '', $field['value']))); } elseif ($field['type'] === 'time_range') { $object_copy->{$object_name} = $field['value'] . ' to ' . $_POST['second_' . $field['name']]; } else { $object_copy->{$object_name} = $field['value']; } } $this->current_id = $object_copy->save(); $this->current_object = $object_copy; unset($object_copy); } return true; // passed validation } else { return false; // didn't pass validation } }
define('CACHE', DIR . '/storage/cache'); /** * Log directory for current domain */ define('LOGS', DIR . '/storage/logs'); /** * Temp directory for current domain */ define('TEMP', DIR . '/storage/temp'); /** * Directory with public cache (available from the outside) */ define('PCACHE', DIR . '/storage/pcache'); /** * Themes dir */ define('THEMES', DIR . '/themes'); /** * Including of custom user files */ foreach (glob(CUSTOM . '/*.php') ?: [] as $custom) { include $custom; } unset($custom); /** * System running */ Core::instance(); Language::instance(); defined('CS_ERROR_HANDLER') && CS_ERROR_HANDLER && Error::instance(); Index::instance();