public function save_category_form($term_id) { // Run this method only once if ($this->save_count < 1) { $id = $this->args['id']; $data = Database::get_row($this->args['table'], 'cat_id', $term_id); foreach ($this->args['table']['structure'] as $name => $args) { $data[$name] = isset($_POST[$name]) ? $_POST[$name] : $data[$name]; } if (empty($data['cat_id'])) { $data['cat_id'] = $term_id; Database::insert_row($this->args['table'], $data); } else { Database::update_row($this->args['table'], 'cat_id', $term_id, $data); } $this->save_count++; } }
public function add() { $fields = $this->fields; unset($fields['id']); $this->id = Database::insert_row($this->getTable(), $fields); }
public static function new_key($name) { $data = Database::get_row(static::$table, 'name', strtolower(str_replace(' ', '_', $name))); return empty($data['name']) ? Database::insert_row(static::$table, array('name' => $name, 'api_key' => static::keygen())) : false; }
protected static function save_to_database($email) { $email = strtolower($email); $data = Database::get_row(static::$table, 'email', $email); $status = 'error'; if (!empty($data['email'])) { $status = 'duplicate'; } else { $data['email'] = $email; $data['create_date'] = date('Y-m-d', time()); $data['create_time'] = date('H:i:s', time()); $email = ['sender' => !empty(get_option('mailing_list_settings_sender')) ? get_option('mailing_list_settings_sender') : get_bloginfo('admin_email'), 'recipient' => $email, 'subject' => 'Thanks for Subscribing!', 'template' => 'subscribe.php']; new Email($email); $status = Database::insert_row(static::$table, $data) ? 'success' : 'error'; } return $status; }
public function save_meta_box() { // Run this method only once if ($this->save_count < 1) { if (in_array(get_post_type(), $this->args['post_type'])) { $prefix = $this->args['table']['prefix'] . '_'; $total = isset($_POST[$prefix . 'id']) ? count($_POST[$prefix . 'id']) : 1; $num = 0; if ($this->args['recursive']) { $num = 1; } if ($this->args['admin_menu']) { $num = 1; } // Loop through the posted data for ($i = $num; $i < $total; $i++) { // Delete data if (isset($_POST[$prefix . 'id']) && $_POST[$prefix . 'id'][$i] < 0) { $row_id = str_replace('-', '', $_POST[$prefix . 'id'][$i]); Database::delete_row($this->args['table'], 'id', $row_id); // Save data } else { $data = array(); foreach ($this->args['table']['structure'] as $column => $value) { $data[$column] = isset($_POST[$prefix . $column][$i]) ? $_POST[$prefix . $column][$i] : ''; } if (isset($_POST[$prefix . 'id'])) { $row_id = $_POST[$prefix . 'id'][$i]; if (!empty($row_id)) { Database::update_row($this->args['table'], 'id', $row_id, $data); } else { Database::insert_row($this->args['table'], $data); } } } } } } $this->save_count++; }
} } elseif ($action == "edit") { if (isset($_POST["body"])) { // Perform mysql_real_escape_string on all values $arraytoinsert = array_map("mysql_real_escape_string", array("slug" => $page, "title" => stripslashes($_POST["title"]), "body" => stripslashes($_POST["body"]), "excerpt" => stripslashes($_POST["excerpt"]))); // Non blog posts have a last update time if (!$page_array["isblog"]) { $arraytoinsert["lastupdate"] = time(); } else { if (!$page_array["isreal"]) { $arraytoinsert["created"] = time(); } } // Update or insert depends on if page is in database. // Hope to god database hasn't changed. $result = $page_array["isreal"] ? $db->update_rows("UPDATE {$table} SET %s WHERE slug='{$page_escape}'", $arraytoinsert) : $db->insert_row("INSERT INTO {$table} %s VALUES %s", $arraytoinsert); if (!$result) { $messages[] = "<small>" . mysql_error() . "</small>"; } else { // Page has been updated/created successfull, // Add tags // Strip, explode, trim and remove empties // This makes string " tag1, tag2, , , tag3" into // array("tag1", "tag2", "tag3") $newtags = array_filter(array_map("trim", explode(",", stripslashes($_POST["tags"])))); // Use old tag array or an empty one $oldtags = $page_array["tags"] ? array_filter($page_array["tags"]) : array(); // Collect all of $newtags which aren't in $oldtags $tagstoinsert = array_diff($newtags, $oldtags); // Collect all of $oldtags which aren't in $newtags $tagstodelete = array_diff($oldtags, $newtags);