Browse Source

Add DB stuffs

master
Chimo 6 years ago
parent
commit
4eb5abb254
4 changed files with 73 additions and 5 deletions
  1. +3
    -0
      .gitignore
  2. +13
    -0
      config.dist.php
  3. +45
    -5
      index.php
  4. +12
    -0
      schema.sql

+ 3
- 0
.gitignore View File

@ -0,0 +1,3 @@
config.php
vendor
*.log

+ 13
- 0
config.dist.php View File

@ -0,0 +1,13 @@
<?php
$config = array(
"site" => array(
"host" => "example.org"
),
"db" => array(
"host" => "localhost",
"name" => "webmentions",
"username" => "webmentions",
"password" => ""
)
);

+ 45
- 5
index.php View File

@ -70,11 +70,51 @@ if (stristr($sourceHTML, $targetURL)) {
$on = '<a href="' . $entry_url . '">' . $entry_name . '</a>' ;
error_log(
sprintf('This page has been mentioned %s on %s',
$by,
$on
),
/*************
* DB Stuffs *
*************/
$dsn = 'mysql:dbname=' . $config['db']['name'] . ';host=' . $config['db']['host'];
$user = $config['db']['username'];
$password = $config['db']['password'];
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
error_log('Connection failed: ' . $e->getMessage(), 4);
exit("Err");
}
$rendered = 'This page has been mentioned ' . $by . ' on ' . $on;
$sth = $dbh->prepare(
'INSERT INTO webmentions (local_url, remote_url, remote_name, remote_author, remote_author_url, rendered) ' .
'VALUES(?, ?, ?, ?, ?, ?)'
);
if ($sth === false) {
error_log("Could not prepare SQL statement.");
error_log("Error code: " . $dbh->errorCode());
error_log("Error info: " . $dbh->errorInfo());
}
$res = $sth->execute(array(
$target_url,
$entry_url,
$entry_name,
$author_name,
$author_url,
$rendered
));
if ($res === false) {
error_log("Could not execute SQL query.");
error_log("Error code: " . $dbh->errorCode());
error_log("Error info: " . $dbh->errorInfo());
}
error_log(
$rendered,
4
);


+ 12
- 0
schema.sql View File

@ -0,0 +1,12 @@
CREATE TABLE `webmentions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`local_url` text NOT NULL,
`remote_url` text NOT NULL,
`remote_name` varchar(255) NOT NULL,
`remote_author` varchar(255),
`remote_author_url` text,
`rendered` text NOT NULL,
`created` datetime NOT NULL DEFAULT NOW(),
`last_checked` datetime NOT NULL DEFAULT NOW(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Loading…
Cancel
Save