function insert($force_validation = false) { if (!$this->report_key) { $this->report_key = uniqid(); } // insert feed into database parent::insert(); }
static function create($user_id, $payment_hash, $days, $amount) { $dbInsert = new DBObject("premium_order", array("user_id", "payment_hash", "days", "amount", "order_status", "date_created")); $dbInsert->user_id = $user_id; $dbInsert->payment_hash = $payment_hash; $dbInsert->days = $days; $dbInsert->amount = $amount; $dbInsert->order_status = 'pending'; $dbInsert->date_created = date("Y-m-d H:i:s", time()); if ($dbInsert->insert()) { return $dbInsert; } return false; }
static function create($username, $password, $email, $title, $firstname, $lastname, $accType = 'user') { $dbInsert = new DBObject("users", array("username", "password", "email", "title", "firstname", "lastname", "datecreated", "createdip", "status", "level", "paymentTracker")); $dbInsert->username = $username; $dbInsert->password = MD5($password); $dbInsert->email = $email; $dbInsert->title = $title; $dbInsert->firstname = $firstname; $dbInsert->lastname = $lastname; $dbInsert->datecreated = sqlDateTime(); $dbInsert->createdip = getUsersIPAddress(); $dbInsert->status = 'active'; $dbInsert->level = 'free user'; $dbInsert->paymentTracker = MD5(time() . $username); if ($dbInsert->insert()) { return $dbInsert; } return false; }
static function getTranslation($key, $defaultContent = '') { /* are we in language debug mode */ if (SITE_CONFIG_LANGUAGE_SHOW_KEY == "key") { return strlen($defaultContent) ? $defaultContent : $key; } /* return the language translation if we can find it */ $constantName = "LANGUAGE_" . strtoupper($key); if (!defined($constantName)) { if (strlen($defaultContent)) { $db = Database::getDatabase(); $languageId = $db->getValue("SELECT id FROM language WHERE languageName = " . $db->quote(SITE_CONFIG_SITE_LANGUAGE)); if (!(int) $languageId) { return false; } // insert default key value $dbInsert = new DBObject("language_key", array("languageKey", "defaultContent", "isAdminArea")); $dbInsert->languageKey = $key; $dbInsert->defaultContent = $defaultContent; $dbInsert->isAdminArea = 0; $dbInsert->insert(); // set constant define("LANGUAGE_" . strtoupper($key), $defaultContent); return $defaultContent; } return "<font style='color:red;'>SITE ERROR: MISSING TRANSLATION *** <strong>" . $key . "</strong> ***</font>"; } return constant($constantName); }
$userId = $order->user_id; // log in payment_log $paypal_vars = ""; foreach ($_REQUEST as $k => $v) { $paypal_vars .= $k . " => " . $v . "\n"; } $dbInsert = new DBObject("payment_log", array("user_id", "date_created", "amount", "currency_code", "from_email", "to_email", "description", "request_log")); $dbInsert->user_id = $userId; $dbInsert->date_created = date("Y-m-d H:i:s", time()); $dbInsert->amount = $_REQUEST['mc_gross']; $dbInsert->currency_code = $_REQUEST['mc_currency']; $dbInsert->from_email = $_REQUEST['payer_email']; $dbInsert->to_email = $_REQUEST['business']; $dbInsert->description = $extendedDays . ' days extension'; $dbInsert->request_log = $paypal_vars; $dbInsert->insert(); // make sure the amount paid matched what we expect if ($_REQUEST['mc_gross'] != $order->amount) { // order amounts did not match die; } // make sure the order is pending if ($order->order_status == 'completed') { // order has already been completed die; } // update order status to paid $dbUpdate = new DBObject("premium_order", array("order_status"), 'id'); $dbUpdate->order_status = 'completed'; $dbUpdate->id = $order->id; $effectedRows = $dbUpdate->update();
require_once 'ajax_auth.inc.php'; $db = Database::getDatabase(); /* get vars */ $params = json_decode($_REQUEST['value']); $language_name = trim($params->group1->language_name); $response = array(); $response['content'] = ""; $response['javascript'] = ""; $response['errors'] = array(); $response['success'] = 1; /* validate submission */ /* check to see if it exists in db */ $db = Database::getDatabase(true); $row = $db->getRow('SELECT id FROM language WHERE languageName = ' . $db->quote($language_name)); if (is_array($row)) { $response['errors']['language_name'] = array(t("language_already_in_system")); } /* insert/update db */ if (COUNT($response['errors']) == 0) { /* create the intial record */ $dbInsert = new DBObject("language", array("languageName")); $dbInsert->languageName = $language_name; if (!$dbInsert->insert()) { $response['errors']['language_name'] = array(t("error_problem_record")); } } if (COUNT($response['errors']) > 0) { $response['success'] = 0; } echo json_encode($response);
private function handle_file_upload($uploaded_file, $name, $size, $type, $error) { $fileUpload = new stdClass(); $fileUpload->name = basename(stripslashes($name)); $fileUpload->size = intval($size); $fileUpload->type = $type; $fileUpload->error = null; $extension = end(explode(".", $fileUpload->name)); $fileUpload->error = $this->has_error($uploaded_file, $fileUpload, $error); if (!$fileUpload->error) { if (strlen(trim($fileUpload->name)) == 0) { $fileUpload->error = 'Filename not found.'; } } elseif (intval($size) == 0) { $fileUpload->error = 'File received has zero size.'; } elseif (intval($size) > $this->options['max_file_size']) { $fileUpload->error = 'File received is larger than permitted.'; } if (!$fileUpload->error && $fileUpload->name) { if ($fileUpload->name[0] === '.') { $fileUpload->name = substr($fileUpload->name, 1); } $newFilename = MD5(microtime()); // figure out upload type $file_size = 0; // select server from pool $uploadServerId = getAvailableServerId(); $db = Database::getDatabase(true); $uploadServerDetails = $db->getRow('SELECT * FROM file_server WHERE id = ' . $db->quote($uploadServerId)); // override storage path if (strlen($uploadServerDetails['storagePath'])) { $this->options['upload_dir'] = $uploadServerDetails['storagePath']; if (substr($this->options['upload_dir'], strlen($this->options['upload_dir']) - 1, 1) == '/') { $this->options['upload_dir'] = substr($this->options['upload_dir'], 0, strlen($this->options['upload_dir']) - 1); } $this->options['upload_dir'] .= '/'; } // move remotely via ftp if ($uploadServerDetails['serverType'] == 'remote') { // connect ftp $conn_id = ftp_connect($uploadServerDetails['ipAddress'], $uploadServerDetails['ftpPort'], 30); if ($conn_id === false) { $fileUpload->error = 'Could not connect to file server ' . $uploadServerDetails['ipAddress']; } // authenticate if (!$fileUpload->error) { $login_result = ftp_login($conn_id, $uploadServerDetails['ftpUsername'], $uploadServerDetails['ftpPassword']); if ($login_result === false) { $fileUpload->error = 'Could not authenticate with file server ' . $uploadServerDetails['ipAddress']; } } // create the upload folder if (!$fileUpload->error) { $uploadPathDir = $this->options['upload_dir'] . substr($newFilename, 0, 2); if (!ftp_mkdir($conn_id, $uploadPathDir)) { // Error reporting removed for now as it causes issues with existing folders. Need to add a check in before here // to see if the folder exists, then create if not. // $fileUpload->error = 'There was a problem creating the storage folder on '.$uploadServerDetails['ipAddress']; } } // upload via ftp if (!$fileUpload->error) { $file_path = $uploadPathDir . '/' . $newFilename; clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { // initiate ftp $ret = ftp_nb_put($conn_id, $file_path, $uploaded_file, FTP_BINARY, FTP_AUTORESUME); while ($ret == FTP_MOREDATA) { // continue uploading $ret = ftp_nb_continue($conn_id); } if ($ret != FTP_FINISHED) { $fileUpload->error = 'There was a problem uploading the file to ' . $uploadServerDetails['ipAddress']; } else { $file_size = filesize($uploaded_file); @unlink($uploaded_file); } } } // close ftp connection ftp_close($conn_id); } else { // create the upload folder $uploadPathDir = $this->options['upload_dir'] . substr($newFilename, 0, 2); @mkdir($uploadPathDir); $file_path = $uploadPathDir . '/' . $newFilename; clearstatcache(); if ($uploaded_file && is_uploaded_file($uploaded_file)) { move_uploaded_file($uploaded_file, $file_path); } $file_size = filesize($file_path); } // check filesize uploaded matches tmp uploaded if ($file_size === $fileUpload->size) { $fileUpload->url = $this->options['upload_url'] . rawurlencode($fileUpload->name); // insert into the db $fileUpload->size = $file_size; $fileUpload->delete_url = '~d?' . $this->options['delete_hash']; $fileUpload->info_url = '~i?' . $this->options['delete_hash']; $fileUpload->delete_type = 'DELETE'; // create delete hash, make sure it's unique $deleteHash = md5($fileUpload->name . getUsersIPAddress() . microtime()); $existingFile = file::loadByDeleteHash($deleteHash); while ($existingFile != false) { $deleteHash = md5($fileUpload->name . getUsersIPAddress() . microtime()); $existingFile = file::loadByDeleteHash($deleteHash); } // store in db $db = Database::getDatabase(true); $dbInsert = new DBObject("file", array("originalFilename", "shortUrl", "fileType", "extension", "fileSize", "localFilePath", "userId", "totalDownload", "uploadedIP", "uploadedDate", "statusId", "deleteHash", "serverId")); $dbInsert->originalFilename = $fileUpload->name; $dbInsert->shortUrl = 'temp'; $dbInsert->fileType = $fileUpload->type; $dbInsert->extension = $extension; $dbInsert->fileSize = $fileUpload->size; $dbInsert->localFilePath = substr($file_path, strlen($this->options['upload_dir']), 99999); // add user id if user is logged in $dbInsert->userId = NULL; $Auth = Auth::getAuth(); if ($Auth->loggedIn()) { $dbInsert->userId = (int) $Auth->id; } $dbInsert->totalDownload = 0; $dbInsert->uploadedIP = getUsersIPAddress(); $dbInsert->uploadedDate = sqlDateTime(); $dbInsert->statusId = 1; $dbInsert->deleteHash = $deleteHash; $dbInsert->serverId = $uploadServerId; if (!$dbInsert->insert()) { $fileUpload->error = 'abort'; } // create short url $tracker = 1; $shortUrl = file::createShortUrlPart($tracker . $dbInsert->id); $fileTmp = file::loadByShortUrl($shortUrl); while ($fileTmp) { $shortUrl = file::createShortUrlPart($tracker . $dbInsert->id); $fileTmp = file::loadByShortUrl($shortUrl); $tracker++; } // update short url file::updateShortUrl($dbInsert->id, $shortUrl); // update fileUpload with file location $file = file::loadByShortUrl($shortUrl); $fileUpload->url = $file->getFullShortUrl(); $fileUpload->delete_url = $file->getDeleteUrl(); $fileUpload->info_url = $file->getInfoUrl(); $fileUpload->stats_url = $file->getStatisticsUrl(); $fileUpload->short_url = $shortUrl; } else { if ($this->options['discard_aborted_uploads']) { //@TODO - made ftp compatible @unlink($file_path); @unlink($uploaded_file); if (!isset($fileUpload->error)) { $fileUpload->error = 'maxFileSize'; } } } } return $fileUpload; }