/**
* create a new link with the given data
* @param array $data
+ * @return boolean|int
*/
- public function create($data) {
+ public function create($data,$returnId=false) {
+ $ret = false;
+
+ if(!isset($data['link']) || empty($data['link'])) return false;
+ if(!isset($data['hash']) || empty($data['hash'])) return false;
+ if(!isset($data['title']) || empty($data['title'])) return false;
+
+ $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_link` SET
+ `link` = '".$this->DB->real_escape_string($data['link'])."',
+ `created` = NOW(),
+ `status` = '".$this->DB->real_escape_string($data['status'])."',
+ `description` = '".$this->DB->real_escape_string($data['description'])."',
+ `title` = '".$this->DB->real_escape_string($data['title'])."',
+ `image` = '".$this->DB->real_escape_string($data['image'])."',
+ `hash` = '".$this->DB->real_escape_string($data['hash'])."',
+ `search` = '".$this->DB->real_escape_string($data['search'])."'";
+
+ $this->DB->query($queryStr);
+ if($returnId === true) {
+ $ret = $this->DB->insert_id;
+ }
+
+ return $ret;
}
/**
$honeypotCheck = false;
if((isset($_POST['password']) && !empty($_POST['password'])) || (isset($_POST['username']) && !empty($_POST['username']))) {
- # those are hidden fields. A robot my input these. A valid user does not.
+ # those are hidden fields. A robot may input these. A valid user does not.
$honeypotCheck = true;
}
$search .= ' '.implode(" ",$tagArr);
$search .= ' '.implode(" ",$catArr);
- $queryStr = "INSERT IGNORE INTO `".DB_PREFIX."_link` SET
- `link` = '".$DB->real_escape_string($formData['url'])."',
- `created` = NOW(),
- `status` = '".$DB->real_escape_string($formData['private'])."',
- `description` = '".$DB->real_escape_string($formData['description'])."',
- `title` = '".$DB->real_escape_string($formData['title'])."',
- `image` = '".$DB->real_escape_string($formData['image'])."',
- `hash` = '".$DB->real_escape_string($hash)."',
- `search` = '".$DB->real_escape_string($search)."'";
-
- /*
- var_dump($catArr);
- var_dump($tagArr);
- var_dump($queryStr);
- exit();
- */
-
- $DB->query($queryStr);
- $linkID = $DB->insert_id;
+ $DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
+ $linkObj = new Link($DB);
+ $linkID = $linkObj->create(array(
+ 'hash' => $hash,
+ 'search' => $search,
+ 'link' => $formData['url'],
+ 'status' => $formData['private'],
+ 'description' => $formData['description'],
+ 'title' => $formData['title'],
+ 'image' => $formData['image']
+ ),true);
if(!empty($linkID)) {
}
}
+ $DB->commit();
+
$submitFeedback['message'] = 'Link added successfully.';
$submitFeedback['status'] = 'success';
$TemplateData['refresh'] = 'index.php?p=linkinfo&id='.$hash;
}
else {
+ $DB->rollback();
$submitFeedback['message'] = 'Something went wrong...';
$submitFeedback['status'] = 'error';
$showAddForm = true;