diff --git a/add.php b/add.php new file mode 100644 index 0000000..7bf0138 --- /dev/null +++ b/add.php @@ -0,0 +1,77 @@ +query( + 'SELECT c.username, u.link FROM `contact` c + LEFT JOIN `url` u ON u.id = c.topic_id + WHERE c.username = "'.$username.'" AND u.link = "'.$url.'"' +); +if($stmt->rowCount() > 0) +{ + die("Exist"); +} + +// trying to find same url in db +$stmt = $dbh->query( + 'SELECT id FROM `url` + WHERE link = "'.$url.'"' +); +if($stmt->rowCount() > 0) +{ + // make notify for new user using presented url id + $id = $stmt->fetch(); + $stmt = $dbh->query( + 'INSERT into contact (username, topic_id) + VALUES ("'.$username.'","'.$id['id'].'")' + ); +}else{ + // insert new url and user in db + $json = file_get_contents( + 'http://api.rutracker.org/v1/get_tor_topic_data?by=topic_id&val='.$url + ); + $obj = json_decode($json); + + $stmt = $dbh->query( + 'INSERT into url (link,u_date) + VALUES ("'.$url.'","'.gmdate("Y-m-d H:i:s", $obj->result->{$url}->reg_time).'")' + ); + $stmt = $dbh->query( + 'SELECT id FROM url WHERE link="'.$url.'"' + ); + $new_topic_id = $stmt->fetch(); + $stmt = $dbh->query( + 'INSERT into contact (username, topic_id) + VALUES ("'.$username.'","'.$new_topic_id['id'].'")' + ); +} + +/* +while ($row = $stmt->fetch()) +{ + echo $row['link'] . "\n"; +} +*/ +?> diff --git a/index.php b/index.php new file mode 100644 index 0000000..96e14e5 --- /dev/null +++ b/index.php @@ -0,0 +1,22 @@ + + + + + +
+ +