parent
63bf2ce327
commit
70e7f74a1a
16
action.php
16
action.php
@ -133,7 +133,23 @@ switch ($VARS['action']) {
|
|||||||
$database->insert('pages', ["slug" => "index", "siteid" => $siteid, "title" => "Home", "nav" => "Home", "navorder" => 1, "template" => $template]);
|
$database->insert('pages', ["slug" => "index", "siteid" => $siteid, "title" => "Home", "nav" => "Home", "navorder" => 1, "template" => $template]);
|
||||||
} else {
|
} else {
|
||||||
$database->update('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color], ["siteid" => $VARS['siteid']]);
|
$database->update('sites', ["sitename" => $VARS['name'], "url" => $url, "theme" => $theme, "color" => $color], ["siteid" => $VARS['siteid']]);
|
||||||
|
$siteid = $VARS['siteid'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($VARS['settings'] as $key => $value) {
|
||||||
|
if ($database->has('settings', ["AND" => ["siteid" => $siteid, "key" => $key]])) {
|
||||||
|
if ($value == "") {
|
||||||
|
//echo "deleting $key => $value\n";
|
||||||
|
$database->delete('settings', ["AND" => ["siteid" => $siteid, "key" => $key]]);
|
||||||
|
} else {
|
||||||
|
//echo "updating $key => $value\n";
|
||||||
|
$database->update('settings', ["value" => $value], ["AND" => ["siteid" => $siteid, "key" => $key]]);
|
||||||
|
}
|
||||||
|
} else if ($value != "") {
|
||||||
|
$database->insert('settings', ["siteid" => $siteid, "key" => $key, "value" => $value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
returnToSender("settings_saved");
|
returnToSender("settings_saved");
|
||||||
break;
|
break;
|
||||||
case "saveedits":
|
case "saveedits":
|
||||||
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -84,5 +84,8 @@ define("STRINGS", [
|
|||||||
"views per visit" => "views per visit",
|
"views per visit" => "views per visit",
|
||||||
"visits over time" => "Visits Over Time",
|
"visits over time" => "Visits Over Time",
|
||||||
"no data" => "No data.",
|
"no data" => "No data.",
|
||||||
"visitor map" => "Visitor Map"
|
"visitor map" => "Visitor Map",
|
||||||
|
"enable built-in analytics" => "Enable built-in analytics",
|
||||||
|
"disable built-in analytics" => "Disable built-in analytics",
|
||||||
|
"extra code" => "Extra code (inserted in site head)"
|
||||||
]);
|
]);
|
@ -11,93 +11,95 @@ use GeoIp2\Database\Reader;
|
|||||||
// Override with a valid public IP when testing on localhost
|
// Override with a valid public IP when testing on localhost
|
||||||
//$_SERVER['REMOTE_ADDR'] = "206.127.96.82";
|
//$_SERVER['REMOTE_ADDR'] = "206.127.96.82";
|
||||||
|
|
||||||
try {
|
require_once __DIR__ . "/requiredpublic.php";
|
||||||
|
|
||||||
require_once __DIR__ . "/requiredpublic.php";
|
if (!$database->has("settings", ["AND" => ["siteid" => getsiteid(), "key" => "analytics", "value" => "off"]])) {
|
||||||
|
try {
|
||||||
|
|
||||||
$time = date("Y-m-d H:i:s");
|
$time = date("Y-m-d H:i:s");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://stackoverflow.com/a/2040279
|
* https://stackoverflow.com/a/2040279
|
||||||
*/
|
*/
|
||||||
function gen_uuid() {
|
function gen_uuid() {
|
||||||
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
||||||
// 32 bits for "time_low"
|
// 32 bits for "time_low"
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
||||||
// 16 bits for "time_mid"
|
// 16 bits for "time_mid"
|
||||||
mt_rand(0, 0xffff),
|
mt_rand(0, 0xffff),
|
||||||
// 16 bits for "time_hi_and_version",
|
// 16 bits for "time_hi_and_version",
|
||||||
// four most significant bits holds version number 4
|
// four most significant bits holds version number 4
|
||||||
mt_rand(0, 0x0fff) | 0x4000,
|
mt_rand(0, 0x0fff) | 0x4000,
|
||||||
// 16 bits, 8 bits for "clk_seq_hi_res",
|
// 16 bits, 8 bits for "clk_seq_hi_res",
|
||||||
// 8 bits for "clk_seq_low",
|
// 8 bits for "clk_seq_low",
|
||||||
// two most significant bits holds zero and one for variant DCE1.1
|
// two most significant bits holds zero and one for variant DCE1.1
|
||||||
mt_rand(0, 0x3fff) | 0x8000,
|
mt_rand(0, 0x3fff) | 0x8000,
|
||||||
// 48 bits for "node"
|
// 48 bits for "node"
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Read/set the cookie
|
// Read/set the cookie
|
||||||
//
|
//
|
||||||
|
|
||||||
if (isset($_COOKIE['sw-uuid'])) {
|
if (isset($_COOKIE['sw-uuid'])) {
|
||||||
$uuid = $_COOKIE['sw-uuid'];
|
$uuid = $_COOKIE['sw-uuid'];
|
||||||
} else {
|
} else {
|
||||||
$uuid = gen_uuid();
|
$uuid = gen_uuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
setcookie("sw-uuid", $uuid, time() + 60 * 60 * 1, "/", $_SERVER['HTTP_HOST'], false, true);
|
setcookie("sw-uuid", $uuid, time() + 60 * 60 * 1, "/", $_SERVER['HTTP_HOST'], false, true);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get the user's IP address
|
// Get the user's IP address
|
||||||
//
|
//
|
||||||
|
|
||||||
$clientip = $_SERVER['REMOTE_ADDR'];
|
$clientip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
// Check if we're behind CloudFlare and adjust accordingly
|
// Check if we're behind CloudFlare and adjust accordingly
|
||||||
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) && validateCloudflare()) {
|
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) && validateCloudflare()) {
|
||||||
$clientip = $_SERVER["HTTP_CF_CONNECTING_IP"];
|
$clientip = $_SERVER["HTTP_CF_CONNECTING_IP"];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lookup IP address
|
// Lookup IP address
|
||||||
//
|
//
|
||||||
|
|
||||||
$reader = new Reader(GEOIP_DB);
|
$reader = new Reader(GEOIP_DB);
|
||||||
|
|
||||||
$record = $reader->city($clientip);
|
$record = $reader->city($clientip);
|
||||||
|
|
||||||
$country = $record->country->name;
|
$country = $record->country->name;
|
||||||
$region = $record->mostSpecificSubdivision->name;
|
$region = $record->mostSpecificSubdivision->name;
|
||||||
$city = $record->city->name;
|
$city = $record->city->name;
|
||||||
$countrycode = $record->country->isoCode;
|
$countrycode = $record->country->isoCode;
|
||||||
$regioncode = $record->mostSpecificSubdivision->isoCode;
|
$regioncode = $record->mostSpecificSubdivision->isoCode;
|
||||||
$lat = $record->location->latitude;
|
$lat = $record->location->latitude;
|
||||||
$lon = $record->location->longitude;
|
$lon = $record->location->longitude;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Save the page visit
|
// Save the page visit
|
||||||
//
|
//
|
||||||
|
|
||||||
$database->insert("analytics", [
|
$database->insert("analytics", [
|
||||||
"siteid" => getsiteid(),
|
"siteid" => getsiteid(),
|
||||||
"pageid" => getpageid(),
|
"pageid" => getpageid(),
|
||||||
"uuid" => $uuid,
|
"uuid" => $uuid,
|
||||||
"country" => $country,
|
"country" => $country,
|
||||||
"region" => $region,
|
"region" => $region,
|
||||||
"city" => $city,
|
"city" => $city,
|
||||||
"countrycode" => $countrycode,
|
"countrycode" => $countrycode,
|
||||||
"regioncode" => $regioncode,
|
"regioncode" => $regioncode,
|
||||||
"lat" => $lat,
|
"lat" => $lat,
|
||||||
"lon" => $lon,
|
"lon" => $lon,
|
||||||
"time" => $time
|
"time" => $time
|
||||||
]);
|
]);
|
||||||
} catch (GeoIp2\Exception\AddressNotFoundException $e) {
|
} catch (GeoIp2\Exception\AddressNotFoundException $e) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
echo "<!-- The client IP was not found in the GeoIP database. -->";
|
echo "<!-- The client IP was not found in the GeoIP database. -->";
|
||||||
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// Silently fail so the rest of the site still works
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
|
||||||
// Silently fail so the rest of the site still works
|
|
||||||
}
|
}
|
@ -192,7 +192,11 @@ function get_page_content($slug = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_header() {
|
function get_header() {
|
||||||
|
$db = getdatabase();
|
||||||
|
$siteid = getsiteid();
|
||||||
|
if ($db->has('settings', ["AND" => ['siteid' => $siteid, 'key' => "extracode"]])) {
|
||||||
|
echo $db->get('settings', "value", ["AND" => ['siteid' => $siteid, 'key' => "extracode"]]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_theme_url($echo = true) {
|
function get_theme_url($echo = true) {
|
||||||
|
@ -11,7 +11,7 @@ $editing = true;
|
|||||||
|
|
||||||
$siteid = "";
|
$siteid = "";
|
||||||
$sitedata = [];
|
$sitedata = [];
|
||||||
|
$settings = [];
|
||||||
|
|
||||||
if (!is_empty($VARS['siteid'])) {
|
if (!is_empty($VARS['siteid'])) {
|
||||||
if ($database->has('sites', ['siteid' => $VARS['siteid']])) {
|
if ($database->has('sites', ['siteid' => $VARS['siteid']])) {
|
||||||
@ -26,6 +26,17 @@ if (!is_empty($VARS['siteid'])) {
|
|||||||
], [
|
], [
|
||||||
'siteid' => $siteid
|
'siteid' => $siteid
|
||||||
])[0];
|
])[0];
|
||||||
|
$dbsett = $database->select(
|
||||||
|
'settings', [
|
||||||
|
'key',
|
||||||
|
'value'
|
||||||
|
], [
|
||||||
|
'siteid' => $siteid
|
||||||
|
]);
|
||||||
|
// Format as ["key"=>"value","key"=>"value"], not [["key", "value"],["key", "value"]]
|
||||||
|
foreach ($dbsett as $s) {
|
||||||
|
$settings[$s['key']] = $s['value'];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
header('Location: app.php?page=sites');
|
header('Location: app.php?page=sites');
|
||||||
die();
|
die();
|
||||||
@ -141,6 +152,30 @@ if (!is_empty($VARS['siteid'])) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<i class="fas fa-chart-bar"></i> <?php lang("analytics"); ?>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="settings[analytics]" value="" id="analytics_on" <?php echo ($settings["analytics"] === "off" ? "" : "checked") ?>>
|
||||||
|
<label class="form-check-label" for="analytics_on">
|
||||||
|
<?php lang("enable built-in analytics"); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="settings[analytics]" value="off" id="analytics_off" <?php echo ($settings["analytics"] === "off" ? "checked" : "") ?>>
|
||||||
|
<label class="form-check-label" for="analytics_off">
|
||||||
|
<?php lang("disable built-in analytics"); ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-6">
|
||||||
|
<label for="extracode"><i class="fas fa-code"></i> <?php lang("extra code"); ?></label>
|
||||||
|
<textarea class="form-control" name="settings[extracode]" id="extracode" placeholder="<script></script>"><?php echo $settings["extracode"]; ?></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input type="hidden" name="siteid" value="<?php echo $siteid; ?>" />
|
<input type="hidden" name="siteid" value="<?php echo $siteid; ?>" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user