Sync PHP API files

This commit is contained in:
Bane Stojkovic
2022-09-21 15:41:39 +02:00
parent f422e0fdf9
commit d2adb49ccf
4 changed files with 4269 additions and 2 deletions
+41 -2
View File
@@ -1,3 +1,42 @@
{"list":{"org.diylc.announcements.Announcement":[
{"title":"Welcome note","date":"2016-11-12","text":"Thank you for trying out the latest and greatest DIYLC.<br>The new version brings \"Project Cloud\" feature I worked on over the last few months.<br>Enjoy surfing the cloud and please send your feedback to bancika@gmail.com"},
<?php
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
function ip_details($IPaddress)
{
$json = file_get_contents("http://ip-api.com/json/{$IPaddress}");
$details = json_decode($json);
return $details;
}
$ip = $_SERVER["REMOTE_ADDR"];
$location = ip_details($ip);
$sql= "INSERT INTO diylc_usage_log (ip, country) VALUES ('".$ip."', '".$location->country."')";
$mysqli->query($sql);
$userId=$_REQUEST["userId"];
if ($userId) {
$sql= "INSERT INTO diylc_user_stats (id, country) VALUES ('".$userId."', '".$location->country."') ON DUPLICATE KEY UPDATE last_seen = CURRENT_TIMESTAMP, counter = counter + 1";
$mysqli->query($sql);
}
$mysqli->close();
?>
{"list":{"org.diylc.announcements.Announcement":[{"title":"Greetings, fellow DIY'ers!","text":"If you need a custom component or feature implemented in DIYLC, do not hesitate to get in touch.<br>I can implement custom components for a reasonable fee and paid component requests will be<br>automatically put on the top of the queue for the next version.<br><br>Write to <font color='blue'>bancika@gmail.com</font>.<br><br>Cheers! ","date":"2019-03-04"},
{"title":"Calling translators","text":"If you wish to contribute by translating DIYLC interface to your language, please get in touch through <font color='blue'>bancika@gmail.com</font>. Thanks!","date":"2020-04-22"},
{"title":"Configuration issues!","text":"In case you recently experienced any issues with losing configuration (variants, recent files, etc), you may be affected by a bug that was discovered and fixed today.<br>DIYLC was using .diylc and diylc user directories simultaneously which caused issues with persistence of the configuration.<br>If you are affected, please upgrade to DIYLC v4.21.3 and then try copying config.xml file from .diylc to diylc directory in your user directory.<br><b>Note:</b> make sure to backup existing files prior to overwriting!<br><br>Sorry for inconvenience and stay safe!","date":"2022-02-22"},
{"title":"Your DIY files are needed :)","text":"In order to increase reliability and decrease the number of regression bugs in DIYLC, I have started building a regression test suite.<br>The idea is to build a framework that would automatically run any future release candidate version against a base of known DIY files,<br>trying to open each file, export it to PNG, save it back to another file and then validate that the outputs are as expected.<br>In order for this to be effective, we need a decent number of DIY files - old and new.<br>Ideally, we should cover all the use cases - guitar pedals, schematics, guitar wirings, amplifiers, tube stuff, etc. More is more here.<br>If you wish to contribute some of your cool projects, please send them over to <font color='blue'>bancika@gmail.com</font>.<br>Thanks in advance!","date":"2022-03-02"},
{"title":"Good news, everyone!","text":"As we are approaching DIYLC's sweet sixteen birthday, I'm happy to say that DIYLC is still growing - both in terms of features and the the user base.<br>By examining traffic statistics of DIYLC back-end, I can roughly estimate that we have more than doubled DIYLC user base in the last 5 years!<br>And growth trends are still pointing up. Thank you all for your ever growing support. DIYLC is still very much alive and I'm adding cool new features.<br><br>All the best!","date":"2022-03-24"}
]}}
File diff suppressed because it is too large Load Diff
+287
View File
@@ -0,0 +1,287 @@
<html>
<body>
<?php
// Load help class
require_once("properties.php");
// Load properties
$dbProperties = new Properties();
$propertiesFile = fopen("db.properties", "rb");
$dbProperties->load($propertiesFile);
// Connect to the DB
$username=$dbProperties->getProperty("user");
$password=$dbProperties->getProperty("pass");
$database=$dbProperties->getProperty("db");
$mysqli = new mysqli(localhost,$username,$password,$database);
echo "<h4>Registered users</h4>";
$sql = "
SELECT COUNT(*) as counter FROM `diylc_user_stats`
WHERE last_seen > DATE_ADD(NOW() ,INTERVAL -24 HOUR)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Today: " . $count . "<br>";
}
$sql = "
SELECT COUNT(*) as counter FROM `diylc_user_stats`
WHERE last_seen > DATE_ADD(NOW() ,INTERVAL -7 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last week: " . $count . "<br>";
}
$sql = "
SELECT COUNT(*) as counter FROM `diylc_user_stats`
WHERE last_seen > DATE_ADD(NOW() ,INTERVAL -30 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last month: " . $count . "<br>";
}
$sql = "
SELECT COUNT(*) as counter FROM `diylc_user_stats`";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "All time: " . $count . "<br>";
}
echo "<h4>Active users by IP</h4>";
$sql = "
SELECT COUNT(distinct ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -24 HOUR)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Today: " . $count . "<br>";
}
$sql = "
SELECT COUNT(distinct ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -7 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last week: " . $count . "<br>";
}
$sql = "
SELECT COUNT(distinct ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -30 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last month: " . $count . "<br>";
}
$sql = "
SELECT COUNT(distinct ip) as counter
FROM diylc_usage_log";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "All time: " . $count . "<br>";
}
echo "<h4>Sessions started</h4>";
$sql = "
SELECT COUNT(ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -24 HOUR)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Today: " . $count . "<br>";
}
$sql = "
SELECT COUNT(ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -7 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last week: " . $count . "<br>";
}
$sql = "
SELECT COUNT(ip) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -30 DAY)";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "Last month: " . $count . "<br>";
}
$sql = "
SELECT COUNT(ip) as counter
FROM diylc_usage_log";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$count = $row["counter"];
echo "All time: " . $count . "<br>";
}
echo "<h4>Usage by country (last week)</h4>";
$sql = "
SELECT country, COUNT(*) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -7 DAY)
GROUP BY country
ORDER BY COUNT(*) DESC";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$country = $row["country"];
$count = $row["counter"];
echo $country . ": " . $count . "<br>";
}
echo "<h4>Usage by country (last month)</h4>";
$sql = "
SELECT country, COUNT(*) as counter
FROM diylc_usage_log
WHERE timestamp > DATE_ADD(NOW() ,INTERVAL -30 DAY)
GROUP BY country
ORDER BY COUNT(*) DESC";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$country = $row["country"];
$count = $row["counter"];
echo $country . ": " . $count . "<br>";
}
echo "<h4>Usage by country (all time)</h4>";
$sql = "
SELECT country, COUNT(*) as counter
FROM diylc_usage_log
GROUP BY country
ORDER BY COUNT(*) DESC";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$country = $row["country"];
$count = $row["counter"];
echo $country . ": " . $count . "<br>";
}
echo "<h4>Usage by month (all time)</h4>";
$sql = "
SELECT year(timestamp) as y, month(timestamp) as m, COUNT(*) as counter
FROM diylc_usage_log
GROUP BY year(timestamp), month(timestamp)
ORDER BY year(timestamp) desc, month(timestamp) DESC";
if (!$result = $mysqli->query($sql)) {
echo "Error:".$mysqli->error;
exit;
}
while ($row = $result->fetch_assoc()) {
$y = $row["y"];
$m = $row["m"];
$count = $row["counter"];
echo $y ."." . $m . ": " . $count . "<br>";
}
$result->free();
$mysqli->close();
?>
</body>
</html>
Binary file not shown.