public function save_admin_menu() { $data = array(); $p = static::$table['prefix'] . '_'; if (!empty($_POST)) { for ($i = 1; $i < count($_POST[$p . 'id']); $i++) { $data['id'] = $_POST[$p . 'id'][$i]; $data['param'] = $_POST[$p . 'param'][$i]; $data['value'] = $_POST[$p . 'value'][$i]; if (!empty($data['param'])) { Database::save_data(static::$table, $data); } else { Database::delete_row(static::$table, 'id', $data['id']); } } } }
public static function add_share($post_id, $network) { $network = strtolower($network); $networks = array(); $resp = array(); foreach (static::$networks as $name => $value) { array_push($networks, $name); } $resp['status'] = 'error'; $resp['type'] = 'invalid-format'; $resp['message'] = 'The submitted post ID does not match the required format.'; // Scrub out invalid post_id's if (preg_match('/^[0-9]+$/', $post_id)) { $resp['type'] = 'invalid-network'; $resp['message'] = 'The submitted network name is not supported'; // Scrub out invalid network names if (in_array($network, $networks)) { $data = Database::get_row(static::$table, 'post_id', $post_id); $data[$network . '_shares'] = (int) $data[$network . '_shares'] + 1; if (Database::save_data(static::$table, $data)) { $resp['status'] = 'success'; $resp['type'] = 'success'; $resp['message'] = 'The share was successfully recorded'; } else { $resp['type'] = 'database-error'; $resp['message'] = 'An error occured connecting to the database. Try again later.'; } } } return $resp; }
public static function add_page_like($post_id) { $resp = array(); $resp['status'] = 'error'; $resp['type'] = 'invalid-format'; $resp['message'] = 'The submitted post ID does not match the required format'; // Scrub out invalid post_id's if (preg_match('/^[0-9]+$/', $post_id)) { $data = Database::get_row(static::$table, 'post_id', $post_id); $data['likes'] = (int) $data['likes'] + 1; if (Database::save_data(static::$table, $data)) { $resp['status'] = 'success'; $resp['type'] = 'success'; $resp['message'] = 'The like was successfully recorded'; } else { $resp['type'] = 'database-error'; $resp['message'] = 'An error occured connecting to the database. Try again later.'; } } return $resp; }