Plugin rename
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/* Styles for WordPress Activity Stats Plugin - Admin Area */
|
||||
|
||||
/* Infografika */
|
||||
.mystat-infographic-grid {
|
||||
.statpress-infographic-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
}
|
||||
.mystat-infographic-card {
|
||||
.statpress-infographic-card {
|
||||
background: #fff;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 5px;
|
||||
@@ -14,12 +14,12 @@
|
||||
text-align: center;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||
}
|
||||
.mystat-infographic-card h3 {
|
||||
.statpress-infographic-card h3 {
|
||||
margin-top: 0;
|
||||
color: #555;
|
||||
font-size: 1.1em;
|
||||
}
|
||||
.mystat-infographic-card p {
|
||||
.statpress-infographic-card p {
|
||||
font-size: 1.8em;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
@@ -27,19 +27,19 @@
|
||||
}
|
||||
|
||||
/* Kontener dla szczegółów aktywności */
|
||||
#mystat-details-container {
|
||||
#statpress-details-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2%;
|
||||
}
|
||||
/* Szczegóły aktywności */
|
||||
.mystat-details-col {
|
||||
.statpress-details-col {
|
||||
flex: 1 1 48%; /* Pozwala na elastyczne dopasowanie, z bazową szerokością 48% */
|
||||
min-width: 300px; /* Zapobiega zbytniemu ściskaniu kolumn na mniejszych ekranach */
|
||||
}
|
||||
|
||||
/* Chart Controls */
|
||||
.mystat-chart-controls {
|
||||
.statpress-chart-controls {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
@@ -49,12 +49,12 @@
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.mystat-chart-tabs.nav-tab-wrapper {
|
||||
.statpress-chart-tabs.nav-tab-wrapper {
|
||||
border-bottom: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.mystat-xaxis-switcher {
|
||||
.statpress-xaxis-switcher {
|
||||
padding-top: 5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_add_new_page() {
|
||||
function statpress_add_new_page() {
|
||||
echo '<div class="wrap"><h1>Dodaj Nowy Trening</h1>';
|
||||
// Obsługa zapisu formularza (musi być przed renderowaniem, aby wyświetlić komunikat)
|
||||
mystat_handle_activity_form_submission();
|
||||
statpress_handle_activity_form_submission();
|
||||
// Formularz dodawania
|
||||
mystat_render_add_form();
|
||||
statpress_render_add_form();
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function mystat_edit_activity_page() {
|
||||
function statpress_edit_activity_page() {
|
||||
global $wpdb;
|
||||
$activity_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
|
||||
|
||||
@@ -22,9 +22,9 @@ function mystat_edit_activity_page() {
|
||||
}
|
||||
|
||||
// Handle form submission for update
|
||||
mystat_handle_activity_form_submission();
|
||||
statpress_handle_activity_form_submission();
|
||||
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$activity = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_activities WHERE id = %d", $activity_id ) );
|
||||
|
||||
if ( ! $activity ) {
|
||||
@@ -33,23 +33,23 @@ function mystat_edit_activity_page() {
|
||||
}
|
||||
|
||||
echo '<div class="wrap"><h1>Edytuj Trening</h1>';
|
||||
mystat_render_add_form( $activity );
|
||||
statpress_render_add_form( $activity );
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Obsługa zapisu nowego lub edytowanego wpisu do bazy danych
|
||||
*/
|
||||
function mystat_handle_activity_form_submission() {
|
||||
function statpress_handle_activity_form_submission() {
|
||||
global $wpdb;
|
||||
|
||||
// Sprawdź czy formularz został wysłany
|
||||
if ( ! isset( $_POST['mystat_submit_activity'] ) ) {
|
||||
if ( ! isset( $_POST['statpress_submit_activity'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$activity_id = isset( $_POST['activity_id'] ) ? intval( $_POST['activity_id'] ) : 0;
|
||||
$nonce_action = $activity_id > 0 ? 'mystat_edit_entry_' . $activity_id : 'mystat_add_entry';
|
||||
$nonce_action = $activity_id > 0 ? 'statpress_edit_entry_' . $activity_id : 'statpress_add_entry';
|
||||
|
||||
// Weryfikacja bezpieczeństwa (Nonce)
|
||||
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], $nonce_action ) ) {
|
||||
@@ -59,7 +59,7 @@ function mystat_handle_activity_form_submission() {
|
||||
|
||||
// Use the refactored function to save data.
|
||||
// We can pass $_POST directly as the function will sanitize it.
|
||||
$result = mystat_save_activity_data( $_POST, $activity_id );
|
||||
$result = statpress_save_activity_data( $_POST, $activity_id );
|
||||
|
||||
if ( $activity_id > 0 ) {
|
||||
$message = 'Trening zaktualizowany pomyślnie!';
|
||||
@@ -77,20 +77,20 @@ function mystat_handle_activity_form_submission() {
|
||||
/**
|
||||
* Renderowanie formularza HTML
|
||||
*/
|
||||
function mystat_render_add_form( $activity = null ) {
|
||||
function statpress_render_add_form( $activity = null ) {
|
||||
// Enqueue media scripts for the uploader
|
||||
wp_enqueue_media();
|
||||
|
||||
global $wpdb;
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_event_types = $wpdb->prefix . 'mystat_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'mystat_equipment';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
$table_event_types = $wpdb->prefix . 'statpress_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'statpress_equipment';
|
||||
$categories = $wpdb->get_results( "SELECT * FROM $table_categories ORDER BY name ASC" );
|
||||
$event_types = $wpdb->get_results( "SELECT * FROM $table_event_types ORDER BY name ASC" );
|
||||
$equipment_list = $wpdb->get_results( "SELECT * FROM $table_equipment ORDER BY name ASC" );
|
||||
|
||||
$is_edit_mode = ! is_null( $activity );
|
||||
$nonce_action = $is_edit_mode ? 'mystat_edit_entry_' . $activity->id : 'mystat_add_entry';
|
||||
$nonce_action = $is_edit_mode ? 'statpress_edit_entry_' . $activity->id : 'statpress_add_entry';
|
||||
$form_title = $is_edit_mode ? 'Edytuj Aktywność' : 'Dodaj Nową Aktywność';
|
||||
$button_text = $is_edit_mode ? 'Zaktualizuj Trening' : 'Zapisz Trening';
|
||||
|
||||
@@ -218,7 +218,7 @@ function mystat_render_add_form( $activity = null ) {
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" name="mystat_submit_activity" id="submit" class="button button-primary" value="<?php echo esc_attr( $button_text ); ?>">
|
||||
<input type="submit" name="statpress_submit_activity" id="submit" class="button button-primary" value="<?php echo esc_attr( $button_text ); ?>">
|
||||
</p>
|
||||
</form>
|
||||
<script>
|
||||
|
||||
@@ -3,7 +3,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_view_activity_page() {
|
||||
function statpress_view_activity_page() {
|
||||
global $wpdb;
|
||||
|
||||
$activity_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
|
||||
@@ -13,10 +13,10 @@ function mystat_view_activity_page() {
|
||||
return;
|
||||
}
|
||||
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_event_types = $wpdb->prefix . 'mystat_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'mystat_equipment';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
$table_event_types = $wpdb->prefix . 'statpress_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'statpress_equipment';
|
||||
|
||||
$sql = $wpdb->prepare(
|
||||
"
|
||||
@@ -51,7 +51,7 @@ function mystat_view_activity_page() {
|
||||
$gpx_data = array();
|
||||
$has_gpx_data = false;
|
||||
if ( ! empty( $activity->gpx_url ) ) {
|
||||
$gpx_data = mystat_parse_gpx_data( $activity->gpx_url );
|
||||
$gpx_data = statpress_parse_gpx_data( $activity->gpx_url );
|
||||
$has_gpx_data = ! empty( $gpx_data['points'] );
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ function mystat_view_activity_page() {
|
||||
wp_enqueue_script( 'leaflet-js', 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js', array(), '1.9.4', true );
|
||||
wp_enqueue_script( 'chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', array(), null, true );
|
||||
|
||||
wp_register_script( 'mystat-details-loader', false );
|
||||
wp_enqueue_script( 'mystat-details-loader' );
|
||||
wp_register_script( 'statpress-details-loader', false );
|
||||
wp_enqueue_script( 'statpress-details-loader' );
|
||||
|
||||
// Check which profiles have data
|
||||
$available_profiles = array();
|
||||
@@ -82,7 +82,7 @@ function mystat_view_activity_page() {
|
||||
let activeChart = null;
|
||||
|
||||
if (typeof L !== "undefined" && track_points.length > 0) {
|
||||
const map = L.map("mystat-activity-map");
|
||||
const map = L.map("statpress-activity-map");
|
||||
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { attribution: \'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>\' }).addTo(map);
|
||||
const polyline = L.polyline(track_points, {color: "' . esc_js( $activity->color ) . '"}).addTo(map);
|
||||
map.fitBounds(polyline.getBounds().pad(0.1));
|
||||
@@ -106,8 +106,8 @@ function mystat_view_activity_page() {
|
||||
|
||||
function renderChart() {
|
||||
if (activeChart) activeChart.destroy();
|
||||
const chartType = document.querySelector(".mystat-chart-tabs .nav-tab-active").getAttribute("href").substring(1);
|
||||
const xAxisType = document.querySelector(\'input[name="mystat_xaxis"]:checked\').value;
|
||||
const chartType = document.querySelector(".statpress-chart-tabs .nav-tab-active").getAttribute("href").substring(1);
|
||||
const xAxisType = document.querySelector(\'input[name="statpress_xaxis"]:checked\').value;
|
||||
|
||||
const yData = profiles[chartType], xData = xAxisConfigs[xAxisType].data;
|
||||
const filteredY = [], filteredX = [];
|
||||
@@ -120,7 +120,7 @@ function mystat_view_activity_page() {
|
||||
}
|
||||
}
|
||||
|
||||
const ctx = document.getElementById("mystat-details-chart").getContext("2d");
|
||||
const ctx = document.getElementById("statpress-details-chart").getContext("2d");
|
||||
activeChart = new Chart(ctx, {
|
||||
type: "line",
|
||||
data: {
|
||||
@@ -143,34 +143,34 @@ function mystat_view_activity_page() {
|
||||
});
|
||||
}
|
||||
|
||||
document.querySelectorAll(".mystat-chart-tabs .nav-tab").forEach(t => t.addEventListener("click", e => {
|
||||
document.querySelectorAll(".statpress-chart-tabs .nav-tab").forEach(t => t.addEventListener("click", e => {
|
||||
e.preventDefault();
|
||||
document.querySelector(".mystat-chart-tabs .nav-tab-active").classList.remove("nav-tab-active");
|
||||
document.querySelector(".statpress-chart-tabs .nav-tab-active").classList.remove("nav-tab-active");
|
||||
e.target.classList.add("nav-tab-active");
|
||||
renderChart();
|
||||
}));
|
||||
document.querySelectorAll(\'input[name="mystat_xaxis"]\').forEach(r => r.addEventListener("change", renderChart));
|
||||
if (document.querySelector(".mystat-chart-tabs .nav-tab")) renderChart();
|
||||
document.querySelectorAll(\'input[name="statpress_xaxis"]\').forEach(r => r.addEventListener("change", renderChart));
|
||||
if (document.querySelector(".statpress-chart-tabs .nav-tab")) renderChart();
|
||||
';
|
||||
wp_add_inline_script( 'mystat-details-loader', 'document.addEventListener("DOMContentLoaded", function() {' . $chart_js . '});' );
|
||||
wp_add_inline_script( 'statpress-details-loader', 'document.addEventListener("DOMContentLoaded", function() {' . $chart_js . '});' );
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
Szczegóły treningu: <?php echo esc_html( $activity->title ); ?>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'mystat-edit-activity', 'id' => $activity->id ), admin_url( 'admin.php' ) ) ); ?>" class="page-title-action">
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'page' => 'statpress-edit-activity', 'id' => $activity->id ), admin_url( 'admin.php' ) ) ); ?>" class="page-title-action">
|
||||
Edytuj
|
||||
</a>
|
||||
</h1>
|
||||
|
||||
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=moje-statystyki' ) ); ?>">← Powrót do listy aktywności</a></p>
|
||||
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=statpress-dashboard' ) ); ?>">← Powrót do listy aktywności</a></p>
|
||||
|
||||
<div class="postbox" style="margin-top: 20px;">
|
||||
<div class="postbox-header"><h2 class="hndle">Podsumowanie</h2></div>
|
||||
<div class="inside">
|
||||
<div id="mystat-details-container">
|
||||
<div class="mystat-details-col">
|
||||
<div id="statpress-details-container">
|
||||
<div class="statpress-details-col">
|
||||
<h3>Główne dane</h3>
|
||||
<table class="form-table">
|
||||
<?php $render_row( 'Kategoria', $activity->category_name ); ?>
|
||||
@@ -182,7 +182,7 @@ function mystat_view_activity_page() {
|
||||
<?php $render_row( 'Sprzęt', $activity->equipment_name ); ?>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mystat-details-col">
|
||||
<div class="statpress-details-col">
|
||||
<h3>Dane szczegółowe</h3>
|
||||
<table class="form-table">
|
||||
<?php $render_row( 'Średnia prędkość', number_format( $activity->avg_speed, 1, ',', ' ' ), 'km/h' ); ?>
|
||||
@@ -213,13 +213,13 @@ function mystat_view_activity_page() {
|
||||
<?php if ( $has_gpx_data ) : ?>
|
||||
<hr>
|
||||
<h3>Mapa Trasy</h3>
|
||||
<div id="mystat-activity-map" style="height: 450px; width: 100%; border: 1px solid #ddd; margin-bottom: 20px;"></div>
|
||||
<div id="statpress-activity-map" style="height: 450px; width: 100%; border: 1px solid #ddd; margin-bottom: 20px;"></div>
|
||||
|
||||
<?php if ( ! empty( $available_profiles ) ) : ?>
|
||||
<h3>Wykresy</h3>
|
||||
<div class="mystat-charts-container">
|
||||
<div class="mystat-chart-controls">
|
||||
<nav class="nav-tab-wrapper mystat-chart-tabs">
|
||||
<div class="statpress-charts-container">
|
||||
<div class="statpress-chart-controls">
|
||||
<nav class="nav-tab-wrapper statpress-chart-tabs">
|
||||
<?php
|
||||
$is_first = true;
|
||||
foreach ( $available_profiles as $key => $label ) :
|
||||
@@ -233,18 +233,18 @@ function mystat_view_activity_page() {
|
||||
<?php endforeach; ?>
|
||||
</nav>
|
||||
<?php if ( $has_time_data ) : ?>
|
||||
<div class="mystat-xaxis-switcher">
|
||||
<div class="statpress-xaxis-switcher">
|
||||
<strong>Oś X:</strong>
|
||||
<label><input type="radio" name="mystat_xaxis" value="distance" checked> Dystans</label>
|
||||
<label><input type="radio" name="statpress_xaxis" value="distance" checked> Dystans</label>
|
||||
|
||||
<label><input type="radio" name="mystat_xaxis" value="time"> Czas</label>
|
||||
<label><input type="radio" name="statpress_xaxis" value="time"> Czas</label>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<input type="hidden" name="mystat_xaxis" value="distance" checked>
|
||||
<input type="hidden" name="statpress_xaxis" value="distance" checked>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div style="position: relative; height:250px; width:100%;">
|
||||
<canvas id="mystat-details-chart"></canvas>
|
||||
<canvas id="statpress-details-chart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -3,27 +3,27 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_dashboard_page() {
|
||||
echo '<div class="wrap"><h1>Moje Statystyki Sportowe</h1>';
|
||||
mystat_render_history_table();
|
||||
function statpress_dashboard_page() {
|
||||
echo '<div class="wrap"><h1>StatPress Dashboard</h1>';
|
||||
statpress_render_history_table();
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function mystat_render_history_table() {
|
||||
function statpress_render_history_table() {
|
||||
global $wpdb;
|
||||
|
||||
// Definicje nazw tabel (z uwzględnieniem prefixu WP, jeśli był użyty przy tworzeniu)
|
||||
// Zakładam, że tabele nazywają się dokładnie tak jak w dokumentacji, ale dobrą praktyką jest $wpdb->prefix
|
||||
// Jeśli tabele są "sztywne" (bez prefixu wp_), usuń $wpdb->prefix.
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
|
||||
// --- 1. OBSŁUGA USUWANIA (DELETE) ---
|
||||
if ( isset( $_GET['action'], $_GET['id'], $_GET['_wpnonce'] ) && 'mystat_delete' === $_GET['action'] ) {
|
||||
if ( isset( $_GET['action'], $_GET['id'], $_GET['_wpnonce'] ) && 'statpress_delete' === $_GET['action'] ) {
|
||||
$activity_id = intval( $_GET['id'] );
|
||||
|
||||
// Weryfikacja bezpieczeństwa (Nonce)
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'mystat_delete_' . $activity_id ) ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'statpress_delete_' . $activity_id ) ) {
|
||||
$result = $wpdb->delete(
|
||||
$table_activities,
|
||||
array( 'id' => $activity_id ),
|
||||
@@ -56,8 +56,8 @@ function mystat_render_history_table() {
|
||||
SELECT a.*, c.name as category_name, c.icon, c.color, et.name as event_type_name, eq.name as equipment_name
|
||||
FROM $table_activities a
|
||||
LEFT JOIN $table_categories c ON a.category_id = c.id
|
||||
LEFT JOIN {$wpdb->prefix}mystat_event_types et ON a.event_type_id = et.id
|
||||
LEFT JOIN {$wpdb->prefix}mystat_equipment eq ON a.equipment_id = eq.id
|
||||
LEFT JOIN {$wpdb->prefix}statpress_event_types et ON a.event_type_id = et.id
|
||||
LEFT JOIN {$wpdb->prefix}statpress_equipment eq ON a.equipment_id = eq.id
|
||||
ORDER BY a.date DESC, a.id DESC
|
||||
LIMIT %d OFFSET %d
|
||||
",
|
||||
@@ -115,16 +115,16 @@ function mystat_render_history_table() {
|
||||
$delete_url = wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'mystat_delete',
|
||||
'action' => 'statpress_delete',
|
||||
'id' => $row->id,
|
||||
)
|
||||
),
|
||||
'mystat_delete_' . $row->id
|
||||
'statpress_delete_' . $row->id
|
||||
);
|
||||
|
||||
$edit_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'mystat-edit-activity',
|
||||
'page' => 'statpress-edit-activity',
|
||||
'id' => $row->id,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
@@ -132,7 +132,7 @@ function mystat_render_history_table() {
|
||||
|
||||
$details_url = add_query_arg(
|
||||
array(
|
||||
'page' => 'mystat-view-activity',
|
||||
'page' => 'statpress-view-activity',
|
||||
'id' => $row->id,
|
||||
),
|
||||
admin_url( 'admin.php' )
|
||||
|
||||
@@ -3,14 +3,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_equipment_page() {
|
||||
function statpress_equipment_page() {
|
||||
global $wpdb;
|
||||
$table_equipment = $wpdb->prefix . 'mystat_equipment';
|
||||
$table_equipment = $wpdb->prefix . 'statpress_equipment';
|
||||
$message = '';
|
||||
$notice_class = '';
|
||||
|
||||
// Handle POST requests (add/update)
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'mystat_manage_equipment' ) ) {
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'statpress_manage_equipment' ) ) {
|
||||
$item_id = isset( $_POST['equipment_id'] ) ? intval( $_POST['equipment_id'] ) : 0;
|
||||
$data = array(
|
||||
'name' => sanitize_text_field( $_POST['equipment_name'] ),
|
||||
@@ -49,13 +49,13 @@ function mystat_equipment_page() {
|
||||
|
||||
// Handle GET requests (delete)
|
||||
if ( isset( $_GET['action'], $_GET['id'], $_GET['_wpnonce'] ) && 'delete' === $_GET['action'] ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'mystat_delete_equipment_' . $_GET['id'] ) ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'statpress_delete_equipment_' . $_GET['id'] ) ) {
|
||||
// Sprawdź, czy sprzęt nie jest używany
|
||||
$usage_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}mystat_activities WHERE equipment_id = %d", intval( $_GET['id'] ) ) );
|
||||
$usage_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}statpress_activities WHERE equipment_id = %d", intval( $_GET['id'] ) ) );
|
||||
if ( 0 == $usage_count ) {
|
||||
$wpdb->delete( $table_equipment, array( 'id' => intval( $_GET['id'] ) ) );
|
||||
// Usuń również powiązane wpisy w dzienniku
|
||||
$wpdb->delete( $wpdb->prefix . 'mystat_equipment_log', array( 'equipment_id' => intval( $_GET['id'] ) ) );
|
||||
$wpdb->delete( $wpdb->prefix . 'statpress_equipment_log', array( 'equipment_id' => intval( $_GET['id'] ) ) );
|
||||
$message = 'Sprzęt usunięty.';
|
||||
$notice_class = 'notice-success';
|
||||
} else {
|
||||
@@ -72,7 +72,7 @@ function mystat_equipment_page() {
|
||||
$item_to_edit = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table_equipment WHERE id = %d", intval( $_GET['id'] ) ) );
|
||||
}
|
||||
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$equipment_list = $wpdb->get_results("
|
||||
SELECT
|
||||
eq.id,
|
||||
@@ -104,7 +104,7 @@ function mystat_equipment_page() {
|
||||
<h2><?php echo $item_to_edit ? 'Edytuj pozycję' : 'Dodaj nowy sprzęt'; ?></h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="equipment_id" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->id ) : '0'; ?>">
|
||||
<?php wp_nonce_field( 'mystat_manage_equipment' ); ?>
|
||||
<?php wp_nonce_field( 'statpress_manage_equipment' ); ?>
|
||||
<div class="form-field form-required"><label for="equipment_name">Nazwa</label><input type="text" name="equipment_name" id="equipment_name" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->name ) : ''; ?>" required></div>
|
||||
<div class="form-field"><label for="equipment_type">Typ</label><input type="text" name="equipment_type" id="equipment_type" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->type ) : 'Rower'; ?>"></div>
|
||||
<div class="form-field"><label for="purchase_date">Data zakupu</label><input type="date" name="purchase_date" id="purchase_date" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->purchase_date ) : ''; ?>"></div>
|
||||
@@ -124,7 +124,7 @@ function mystat_equipment_page() {
|
||||
<tbody>
|
||||
<?php foreach ( $equipment_list as $item ) : ?>
|
||||
<?php
|
||||
$details_url = admin_url( 'admin.php?page=mystat-equipment-details&id=' . $item->id );
|
||||
$details_url = admin_url( 'admin.php?page=statpress-equipment-details&id=' . $item->id );
|
||||
?>
|
||||
<tr>
|
||||
<td><strong><a href="<?php echo esc_url( $details_url ); ?>"><?php echo esc_html( $item->name ); ?></a></strong><br><small><?php echo esc_html( $item->type ); ?></small></td>
|
||||
@@ -134,7 +134,7 @@ function mystat_equipment_page() {
|
||||
<td>
|
||||
<a href="<?php echo esc_url( $details_url ); ?>" class="button button-small">Dziennik / Serwis</a>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'id' => $item->id ) ) ); ?>" class="button button-small">Edytuj</a>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $item->id ) ), 'mystat_delete_equipment_' . $item->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten sprzęt?')" class="button button-small button-link-delete">Usuń</a>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $item->id ) ), 'statpress_delete_equipment_' . $item->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten sprzęt?')" class="button button-small button-link-delete">Usuń</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -147,7 +147,7 @@ function mystat_equipment_page() {
|
||||
<?php
|
||||
}
|
||||
|
||||
function mystat_equipment_details_page() {
|
||||
function statpress_equipment_details_page() {
|
||||
global $wpdb;
|
||||
$equipment_id = isset( $_GET['id'] ) ? intval( $_GET['id'] ) : 0;
|
||||
|
||||
@@ -156,14 +156,14 @@ function mystat_equipment_details_page() {
|
||||
return;
|
||||
}
|
||||
|
||||
$table_equipment = $wpdb->prefix . 'mystat_equipment';
|
||||
$table_equipment_log = $wpdb->prefix . 'mystat_equipment_log';
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_equipment = $wpdb->prefix . 'statpress_equipment';
|
||||
$table_equipment_log = $wpdb->prefix . 'statpress_equipment_log';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$message = '';
|
||||
$notice_class = '';
|
||||
|
||||
// --- Handle Service Log form submissions (add/update/delete) ---
|
||||
if ( isset( $_POST['submit_log'] ) && check_admin_referer( 'mystat_manage_equipment_log' ) ) {
|
||||
if ( isset( $_POST['submit_log'] ) && check_admin_referer( 'statpress_manage_equipment_log' ) ) {
|
||||
$log_id = isset( $_POST['log_id'] ) ? intval( $_POST['log_id'] ) : 0;
|
||||
$log_data = array(
|
||||
'equipment_id' => $equipment_id,
|
||||
@@ -190,7 +190,7 @@ function mystat_equipment_details_page() {
|
||||
}
|
||||
|
||||
if ( isset( $_GET['action'], $_GET['log_id'], $_GET['_wpnonce'] ) && 'delete_log' === $_GET['action'] ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'mystat_delete_log_' . $_GET['log_id'] ) ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'statpress_delete_log_' . $_GET['log_id'] ) ) {
|
||||
$wpdb->delete( $table_equipment_log, array( 'id' => intval( $_GET['log_id'] ) ) );
|
||||
$message = 'Wpis z dziennika usunięty.';
|
||||
$notice_class = 'notice-success';
|
||||
@@ -217,7 +217,7 @@ function mystat_equipment_details_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Dziennik serwisowy: <?php echo esc_html( $equipment->name ); ?></h1>
|
||||
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=mystat-equipment' ) ); ?>">← Powrót do listy sprzętu</a></p>
|
||||
<p><a href="<?php echo esc_url( admin_url( 'admin.php?page=statpress-equipment' ) ); ?>">← Powrót do listy sprzętu</a></p>
|
||||
|
||||
<?php if ( ! empty( $message ) ) : ?>
|
||||
<div class="notice <?php echo esc_attr( $notice_class ); ?> is-dismissible"><p><?php echo esc_html( $message ); ?></p></div>
|
||||
@@ -246,7 +246,7 @@ function mystat_equipment_details_page() {
|
||||
<h2><?php echo $log_to_edit ? 'Edytuj wpis' : 'Dodaj wpis do dziennika'; ?></h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="log_id" value="<?php echo $log_to_edit ? esc_attr( $log_to_edit->id ) : '0'; ?>">
|
||||
<?php wp_nonce_field( 'mystat_manage_equipment_log' ); ?>
|
||||
<?php wp_nonce_field( 'statpress_manage_equipment_log' ); ?>
|
||||
<div class="form-field form-required"><label for="log_date">Data</label><input type="date" name="log_date" id="log_date" value="<?php echo $log_to_edit ? esc_attr( $log_to_edit->log_date ) : current_time( 'Y-m-d' ); ?>" required></div>
|
||||
<div class="form-field form-required"><label for="log_type">Typ</label><select name="log_type" id="log_type" required><?php foreach ( $log_types as $type ) : ?><option value="<?php echo esc_attr( $type ); ?>" <?php if ( $log_to_edit ) {
|
||||
selected( $log_to_edit->log_type, $type );} ?>><?php echo esc_html( $type ); ?></option><?php endforeach; ?></select></div>
|
||||
@@ -282,7 +282,7 @@ function mystat_equipment_details_page() {
|
||||
<td><?php echo $log->mileage ? number_format( $log->mileage, 0, '', ' ' ) . ' km' : '-'; ?></td>
|
||||
<td>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit_log', 'log_id' => $log->id ) ) ); ?>">Edytuj</a> |
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete_log', 'log_id' => $log->id ) ), 'mystat_delete_log_' . $log->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten wpis?')" style="color: #a00;">Usuń</a>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete_log', 'log_id' => $log->id ) ), 'statpress_delete_log_' . $log->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten wpis?')" style="color: #a00;">Usuń</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -3,14 +3,14 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_event_types_page() {
|
||||
function statpress_event_types_page() {
|
||||
global $wpdb;
|
||||
$table_event_types = $wpdb->prefix . 'mystat_event_types';
|
||||
$table_event_types = $wpdb->prefix . 'statpress_event_types';
|
||||
$message = '';
|
||||
$notice_class = '';
|
||||
|
||||
// Handle POST requests (add/update)
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'mystat_manage_event_type' ) ) {
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'statpress_manage_event_type' ) ) {
|
||||
$name = sanitize_text_field( $_POST['event_type_name'] );
|
||||
$type_id = isset( $_POST['event_type_id'] ) ? intval( $_POST['event_type_id'] ) : 0;
|
||||
|
||||
@@ -32,7 +32,7 @@ function mystat_event_types_page() {
|
||||
|
||||
// Handle GET requests (delete)
|
||||
if ( isset( $_GET['action'], $_GET['id'], $_GET['_wpnonce'] ) && 'delete' === $_GET['action'] ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'mystat_delete_event_type_' . $_GET['id'] ) ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'statpress_delete_event_type_' . $_GET['id'] ) ) {
|
||||
$wpdb->delete( $table_event_types, array( 'id' => intval( $_GET['id'] ) ) );
|
||||
$message = 'Typ wydarzenia usunięty.';
|
||||
$notice_class = 'notice-success';
|
||||
@@ -60,7 +60,7 @@ function mystat_event_types_page() {
|
||||
<h2><?php echo $item_to_edit ? 'Edytuj typ wydarzenia' : 'Dodaj nowy typ wydarzenia'; ?></h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="event_type_id" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->id ) : '0'; ?>">
|
||||
<?php wp_nonce_field( 'mystat_manage_event_type' ); ?>
|
||||
<?php wp_nonce_field( 'statpress_manage_event_type' ); ?>
|
||||
<div class="form-field">
|
||||
<label for="event_type_name">Nazwa</label>
|
||||
<input type="text" name="event_type_name" id="event_type_name" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->name ) : ''; ?>" required>
|
||||
@@ -76,7 +76,7 @@ function mystat_event_types_page() {
|
||||
<thead><tr><th>Nazwa</th><th style="width: 100px;">Akcje</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ( $event_types as $type ) : ?>
|
||||
<tr><td><?php echo esc_html( $type->name ); ?></td><td><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'id' => $type->id ) ) ); ?>">Edytuj</a> | <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $type->id ) ), 'mystat_delete_event_type_' . $type->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten typ?')" style="color: #a00;">Usuń</a></td></tr>
|
||||
<tr><td><?php echo esc_html( $type->name ); ?></td><td><a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'id' => $type->id ) ) ); ?>">Edytuj</a> | <a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $type->id ) ), 'statpress_delete_event_type_' . $type->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten typ?')" style="color: #a00;">Usuń</a></td></tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -9,9 +9,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @param object $goal The goal object from the database.
|
||||
* @return array An array containing 'current_value' and 'percentage'.
|
||||
*/
|
||||
function mystat_get_goal_progress( $goal ) {
|
||||
function statpress_get_goal_progress( $goal ) {
|
||||
global $wpdb;
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
|
||||
$sql_select = '';
|
||||
switch ( $goal->goal_type ) {
|
||||
@@ -52,15 +52,15 @@ function mystat_get_goal_progress( $goal ) {
|
||||
);
|
||||
}
|
||||
|
||||
function mystat_goals_page() {
|
||||
function statpress_goals_page() {
|
||||
global $wpdb;
|
||||
$table_goals = $wpdb->prefix . 'mystat_goals';
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_goals = $wpdb->prefix . 'statpress_goals';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
$message = '';
|
||||
$notice_class = '';
|
||||
|
||||
// Handle POST requests (add/update)
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'mystat_manage_goal' ) ) {
|
||||
if ( isset( $_POST['submit'] ) && check_admin_referer( 'statpress_manage_goal' ) ) {
|
||||
$goal_id = isset( $_POST['goal_id'] ) ? intval( $_POST['goal_id'] ) : 0;
|
||||
|
||||
// Convert hours to seconds for duration goal type before saving
|
||||
@@ -96,7 +96,7 @@ function mystat_goals_page() {
|
||||
|
||||
// Handle GET requests (delete)
|
||||
if ( isset( $_GET['action'], $_GET['id'], $_GET['_wpnonce'] ) && 'delete' === $_GET['action'] ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'mystat_delete_goal_' . $_GET['id'] ) ) {
|
||||
if ( wp_verify_nonce( $_GET['_wpnonce'], 'statpress_delete_goal_' . $_GET['id'] ) ) {
|
||||
$wpdb->delete( $table_goals, array( 'id' => intval( $_GET['id'] ) ) );
|
||||
$message = 'Cel usunięty.';
|
||||
$notice_class = 'notice-success';
|
||||
@@ -125,7 +125,7 @@ function mystat_goals_page() {
|
||||
<h2><?php echo $item_to_edit ? 'Edytuj cel' : 'Dodaj nowy cel'; ?></h2>
|
||||
<form method="post">
|
||||
<input type="hidden" name="goal_id" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->id ) : '0'; ?>">
|
||||
<?php wp_nonce_field( 'mystat_manage_goal' ); ?>
|
||||
<?php wp_nonce_field( 'statpress_manage_goal' ); ?>
|
||||
<div class="form-field form-required"><label for="goal_name">Nazwa celu</label><input type="text" name="goal_name" id="goal_name" value="<?php echo $item_to_edit ? esc_attr( $item_to_edit->name ) : ''; ?>" required></div>
|
||||
<div class="form-field form-required"><label for="goal_type">Typ celu</label><select name="goal_type" id="goal_type" required><option value="distance" <?php if ( $item_to_edit ) { selected( $item_to_edit->goal_type, 'distance' ); } ?>>Dystans (km)</option><option value="duration_sec" <?php if ( $item_to_edit ) { selected( $item_to_edit->goal_type, 'duration_sec' ); } ?>>Czas (w godzinach)</option><option value="count" <?php if ( $item_to_edit ) { selected( $item_to_edit->goal_type, 'count' ); } ?>>Liczba aktywności</option></select></div>
|
||||
<div class="form-field form-required"><label for="target_value">Wartość docelowa</label><input type="text" name="target_value" id="target_value" value="<?php echo $item_to_edit ? esc_attr( 'duration_sec' === $item_to_edit->goal_type ? $item_to_edit->target_value / 3600 : $item_to_edit->target_value ) : ''; ?>" required><p>Dla czasu podaj wartość w godzinach (np. 100.5).</p></div>
|
||||
@@ -147,7 +147,7 @@ function mystat_goals_page() {
|
||||
<?php else : ?>
|
||||
<?php foreach ( $goals as $goal ) : ?>
|
||||
<?php
|
||||
$progress = mystat_get_goal_progress( $goal );
|
||||
$progress = statpress_get_goal_progress( $goal );
|
||||
$percentage = min( 100, $progress['percentage'] );
|
||||
|
||||
$target_formatted = '';
|
||||
@@ -173,14 +173,14 @@ function mystat_goals_page() {
|
||||
</small>
|
||||
</td>
|
||||
<td>
|
||||
<div class="mystat-progress-bar-container">
|
||||
<div class="mystat-progress-bar" style="width: <?php echo esc_attr( $percentage ); ?>%;"></div>
|
||||
<div class="statpress-progress-bar-container">
|
||||
<div class="statpress-progress-bar" style="width: <?php echo esc_attr( $percentage ); ?>%;"></div>
|
||||
</div>
|
||||
<small><?php echo $current_formatted; ?> z <?php echo $target_formatted; ?> (<?php echo round( $percentage, 1 ); ?>%)</small>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'id' => $goal->id ) ) ); ?>">Edytuj</a> |
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $goal->id ) ), 'mystat_delete_goal_' . $goal->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten cel?')" style="color: #a00;">Usuń</a>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => $goal->id ) ), 'statpress_delete_goal_' . $goal->id ) ); ?>" onclick="return confirm('Czy na pewno chcesz usunąć ten cel?')" style="color: #a00;">Usuń</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
@@ -192,8 +192,8 @@ function mystat_goals_page() {
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
.mystat-progress-bar-container { background: #eee; border-radius: 4px; height: 12px; width: 100%; overflow: hidden; margin-bottom: 4px; }
|
||||
.mystat-progress-bar { background: #3498db; height: 100%; border-radius: 4px; transition: width 0.5s ease-in-out; }
|
||||
.statpress-progress-bar-container { background: #eee; border-radius: 4px; height: 12px; width: 100%; overflow: hidden; margin-bottom: 4px; }
|
||||
.statpress-progress-bar { background: #3498db; height: 100%; border-radius: 4px; transition: width 0.5s ease-in-out; }
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
@@ -3,12 +3,12 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_import_csv_page() {
|
||||
function statpress_import_csv_page() {
|
||||
echo '<div class="wrap"><h1>Importuj aktywności z pliku CSV</h1>';
|
||||
|
||||
// Handle the form submission
|
||||
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['mystat_csv_import_nonce_field'] ) ) {
|
||||
mystat_handle_csv_import();
|
||||
if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['statpress_csv_import_nonce_field'] ) ) {
|
||||
statpress_handle_csv_import();
|
||||
}
|
||||
|
||||
// Display the form
|
||||
@@ -28,15 +28,15 @@ function mystat_import_csv_page() {
|
||||
</p>
|
||||
<hr>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<?php wp_nonce_field( 'mystat_csv_import_nonce', 'mystat_csv_import_nonce_field' ); ?>
|
||||
<?php wp_nonce_field( 'statpress_csv_import_nonce', 'statpress_csv_import_nonce_field' ); ?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><label for="mystat_csv_file">Opcja 1: Wgraj plik CSV</label></th>
|
||||
<td><input type="file" id="mystat_csv_file" name="mystat_csv_file" accept=".csv,text/csv" /></td>
|
||||
<th scope="row"><label for="statpress_csv_file">Opcja 1: Wgraj plik CSV</label></th>
|
||||
<td><input type="file" id="statpress_csv_file" name="statpress_csv_file" accept=".csv,text/csv" /></td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><label for="mystat_csv_data">Opcja 2: Wklej dane CSV</label></th>
|
||||
<td><textarea name="mystat_csv_data" id="mystat_csv_data" rows="15" class="large-text" placeholder="Wklej tutaj zawartość swojego pliku CSV... Typ aktywności,Data,Tytuł,Dystans,... Rower,2025-01-01,Nowy Rok,10.5,..."></textarea></td>
|
||||
<th scope="row"><label for="statpress_csv_data">Opcja 2: Wklej dane CSV</label></th>
|
||||
<td><textarea name="statpress_csv_data" id="statpress_csv_data" rows="15" class="large-text" placeholder="Wklej tutaj zawartość swojego pliku CSV... Typ aktywności,Data,Tytuł,Dystans,... Rower,2025-01-01,Nowy Rok,10.5,..."></textarea></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php submit_button( 'Importuj' ); ?>
|
||||
@@ -47,10 +47,10 @@ function mystat_import_csv_page() {
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
function mystat_handle_csv_import() {
|
||||
function statpress_handle_csv_import() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! isset( $_POST['mystat_csv_import_nonce_field'] ) || ! wp_verify_nonce( $_POST['mystat_csv_import_nonce_field'], 'mystat_csv_import_nonce' ) ) {
|
||||
if ( ! isset( $_POST['statpress_csv_import_nonce_field'] ) || ! wp_verify_nonce( $_POST['statpress_csv_import_nonce_field'], 'statpress_csv_import_nonce' ) ) {
|
||||
echo '<div class="notice notice-error"><p>Błąd weryfikacji bezpieczeństwa.</p></div>';
|
||||
return;
|
||||
}
|
||||
@@ -62,10 +62,10 @@ function mystat_handle_csv_import() {
|
||||
|
||||
// Unify input source: prefer textarea, fall back to file upload.
|
||||
$csv_content = '';
|
||||
if ( ! empty( $_POST['mystat_csv_data'] ) ) {
|
||||
$csv_content = stripslashes( $_POST['mystat_csv_data'] );
|
||||
} elseif ( ! empty( $_FILES['mystat_csv_file']['tmp_name'] ) && UPLOAD_ERR_OK === $_FILES['mystat_csv_file']['error'] ) {
|
||||
$csv_content = file_get_contents( $_FILES['mystat_csv_file']['tmp_name'] );
|
||||
if ( ! empty( $_POST['statpress_csv_data'] ) ) {
|
||||
$csv_content = stripslashes( $_POST['statpress_csv_data'] );
|
||||
} elseif ( ! empty( $_FILES['statpress_csv_file']['tmp_name'] ) && UPLOAD_ERR_OK === $_FILES['statpress_csv_file']['error'] ) {
|
||||
$csv_content = file_get_contents( $_FILES['statpress_csv_file']['tmp_name'] );
|
||||
}
|
||||
|
||||
if ( empty( trim( $csv_content ) ) ) {
|
||||
@@ -120,9 +120,9 @@ function mystat_handle_csv_import() {
|
||||
);
|
||||
|
||||
// --- START: Robust, case-insensitive lookup ---
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_event_types = $wpdb->prefix . 'mystat_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'mystat_equipment';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
$table_event_types = $wpdb->prefix . 'statpress_event_types';
|
||||
$table_equipment = $wpdb->prefix . 'statpress_equipment';
|
||||
|
||||
$create_lookup = function( $table_name ) use ( $wpdb ) {
|
||||
$items = $wpdb->get_results( "SELECT id, name FROM {$table_name}" );
|
||||
@@ -143,7 +143,7 @@ function mystat_handle_csv_import() {
|
||||
// --- END: Robust, case-insensitive lookup ---
|
||||
|
||||
// Process the CSV file
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$imported_count = 0;
|
||||
$skipped_details = array();
|
||||
$row_number = 1; // Header is row 1
|
||||
|
||||
@@ -3,10 +3,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_infographic_page() {
|
||||
function statpress_infographic_page() {
|
||||
global $wpdb;
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_categories = $wpdb->prefix . 'mystat_categories';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
$table_categories = $wpdb->prefix . 'statpress_categories';
|
||||
|
||||
$current_year = isset( $_GET['year'] ) ? intval( $_GET['year'] ) : current_time( 'Y' );
|
||||
|
||||
@@ -71,13 +71,13 @@ function mystat_infographic_page() {
|
||||
|
||||
// Włączenie skryptów dla Chart.js
|
||||
wp_enqueue_script( 'chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', array(), null, true );
|
||||
wp_register_script( 'mystat-infographic-chart-loader', false );
|
||||
wp_enqueue_script( 'mystat-infographic-chart-loader' );
|
||||
wp_register_script( 'statpress-infographic-chart-loader', false );
|
||||
wp_enqueue_script( 'statpress-infographic-chart-loader' );
|
||||
wp_add_inline_script(
|
||||
'mystat-infographic-chart-loader',
|
||||
'statpress-infographic-chart-loader',
|
||||
'
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const ctx = document.getElementById("mystatCategoryPieChart");
|
||||
const ctx = document.getElementById("statpressCategoryPieChart");
|
||||
if (!ctx) return;
|
||||
new Chart(ctx, {
|
||||
type: "pie",
|
||||
@@ -114,7 +114,7 @@ function mystat_infographic_page() {
|
||||
<div class="tablenav top">
|
||||
<div class="alignleft actions">
|
||||
<form method="get" style="display: flex; gap: 5px; align-items: center;">
|
||||
<input type="hidden" name="page" value="mystat-infographic">
|
||||
<input type="hidden" name="page" value="statpress-infographic">
|
||||
<label for="filter-by-year" class="screen-reader-text">Filtruj według roku</label>
|
||||
<select name="year" id="filter-by-year">
|
||||
<?php foreach ( $available_years as $year_option ) : ?>
|
||||
@@ -128,21 +128,21 @@ function mystat_infographic_page() {
|
||||
|
||||
<div class="postbox" style="margin-bottom: 20px;">
|
||||
<div class="postbox-header"><h2 class="hndle">Statystyki Ogólne (wszystkie lata)</h2></div>
|
||||
<div class="inside mystat-infographic-grid">
|
||||
<div class="mystat-infographic-card"><h3>Dystans</h3><p><?php echo number_format( $overall_stats->total_distance, 2, ',', ' ' ); ?> km</p></div>
|
||||
<div class="mystat-infographic-card"><h3>Czas</h3><p><?php echo esc_html( $overall_stats->total_duration ); ?></p></div>
|
||||
<div class="mystat-infographic-card"><h3>Wznios</h3><p><?php echo number_format( $overall_stats->total_elevation_gain, 0, ',', ' ' ); ?> m</p></div>
|
||||
<div class="mystat-infographic-card"><h3>Aktywności</h3><p><?php echo number_format( $overall_stats->total_activities, 0, ',', ' ' ); ?></p></div>
|
||||
<div class="inside statpress-infographic-grid">
|
||||
<div class="statpress-infographic-card"><h3>Dystans</h3><p><?php echo number_format( $overall_stats->total_distance, 2, ',', ' ' ); ?> km</p></div>
|
||||
<div class="statpress-infographic-card"><h3>Czas</h3><p><?php echo esc_html( $overall_stats->total_duration ); ?></p></div>
|
||||
<div class="statpress-infographic-card"><h3>Wznios</h3><p><?php echo number_format( $overall_stats->total_elevation_gain, 0, ',', ' ' ); ?> m</p></div>
|
||||
<div class="statpress-infographic-card"><h3>Aktywności</h3><p><?php echo number_format( $overall_stats->total_activities, 0, ',', ' ' ); ?></p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="postbox" style="margin-bottom: 20px;">
|
||||
<div class="postbox-header"><h2 class="hndle">Statystyki dla <?php echo esc_html( $current_year ); ?></h2></div>
|
||||
<div class="inside mystat-infographic-grid">
|
||||
<div class="mystat-infographic-card"><h3>Dystans</h3><p><?php echo number_format( $yearly_stats->total_distance, 2, ',', ' ' ); ?> km</p></div>
|
||||
<div class="mystat-infographic-card"><h3>Czas</h3><p><?php echo esc_html( $yearly_stats->total_duration ); ?></p></div>
|
||||
<div class="mystat-infographic-card"><h3>Wznios</h3><p><?php echo number_format( $yearly_stats->total_elevation_gain, 0, ',', ' ' ); ?> m</p></div>
|
||||
<div class="mystat-infographic-card"><h3>Aktywności</h3><p><?php echo number_format( $yearly_stats->total_activities, 0, ',', ' ' ); ?></p></div>
|
||||
<div class="inside statpress-infographic-grid">
|
||||
<div class="statpress-infographic-card"><h3>Dystans</h3><p><?php echo number_format( $yearly_stats->total_distance, 2, ',', ' ' ); ?> km</p></div>
|
||||
<div class="statpress-infographic-card"><h3>Czas</h3><p><?php echo esc_html( $yearly_stats->total_duration ); ?></p></div>
|
||||
<div class="statpress-infographic-card"><h3>Wznios</h3><p><?php echo number_format( $yearly_stats->total_elevation_gain, 0, ',', ' ' ); ?> m</p></div>
|
||||
<div class="statpress-infographic-card"><h3>Aktywności</h3><p><?php echo number_format( $yearly_stats->total_activities, 0, ',', ' ' ); ?></p></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -150,7 +150,7 @@ function mystat_infographic_page() {
|
||||
<div class="postbox-header"><h2 class="hndle">Rozkład Dystansu wg Kategorii w <?php echo esc_html( $current_year ); ?></h2></div>
|
||||
<div class="inside">
|
||||
<div style="position: relative; height:40vh; width:100%; max-width: 600px; margin: 0 auto;">
|
||||
<canvas id="mystatCategoryPieChart"></canvas>
|
||||
<canvas id="statpressCategoryPieChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -3,16 +3,16 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_settings_page() {
|
||||
function statpress_settings_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>Ustawienia Wtyczki Statystyk</h1>
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
settings_fields( 'mystat_privacy_settings' );
|
||||
do_settings_sections( 'mystat-privacy-section' );
|
||||
settings_fields( 'mystat_api_settings' );
|
||||
do_settings_sections( 'mystat-api-section' );
|
||||
settings_fields( 'statpress_privacy_settings' );
|
||||
do_settings_sections( 'statpress-privacy-section' );
|
||||
settings_fields( 'statpress_api_settings' );
|
||||
do_settings_sections( 'statpress-api-section' );
|
||||
submit_button();
|
||||
?>
|
||||
</form>
|
||||
@@ -20,91 +20,91 @@ function mystat_settings_page() {
|
||||
<?php
|
||||
}
|
||||
|
||||
function mystat_register_settings() {
|
||||
function statpress_register_settings() {
|
||||
register_setting(
|
||||
'mystat_privacy_settings',
|
||||
'mystat_privacy_options',
|
||||
'mystat_sanitize_privacy_options'
|
||||
'statpress_privacy_settings',
|
||||
'statpress_privacy_options',
|
||||
'statpress_sanitize_privacy_options'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'mystat_privacy_zone_section',
|
||||
'statpress_privacy_zone_section',
|
||||
'Strefa Prywatności GPX',
|
||||
'mystat_privacy_section_callback',
|
||||
'mystat-privacy-section'
|
||||
'statpress_privacy_section_callback',
|
||||
'statpress-privacy-section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_latitude',
|
||||
'statpress_privacy_latitude',
|
||||
'Szerokość geograficzna (Latitude)',
|
||||
'mystat_render_lat_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
'statpress_render_lat_field',
|
||||
'statpress-privacy-section',
|
||||
'statpress_privacy_zone_section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_longitude',
|
||||
'statpress_privacy_longitude',
|
||||
'Długość geograficzna (Longitude)',
|
||||
'mystat_render_lon_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
'statpress_render_lon_field',
|
||||
'statpress-privacy-section',
|
||||
'statpress_privacy_zone_section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_privacy_radius',
|
||||
'statpress_privacy_radius',
|
||||
'Promień strefy (w metrach)',
|
||||
'mystat_render_radius_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
'statpress_render_radius_field',
|
||||
'statpress-privacy-section',
|
||||
'statpress_privacy_zone_section'
|
||||
);
|
||||
|
||||
// API Settings
|
||||
register_setting(
|
||||
'mystat_api_settings',
|
||||
'mystat_api_options',
|
||||
'mystat_sanitize_api_options'
|
||||
'statpress_api_settings',
|
||||
'statpress_api_options',
|
||||
'statpress_sanitize_api_options'
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'mystat_api_section',
|
||||
'statpress_api_section',
|
||||
'Ustawienia API',
|
||||
'mystat_api_section_callback',
|
||||
'mystat-api-section'
|
||||
'statpress_api_section_callback',
|
||||
'statpress-api-section'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'mystat_enable_api',
|
||||
'statpress_enable_api',
|
||||
'REST API',
|
||||
'mystat_render_enable_api_field',
|
||||
'mystat-privacy-section',
|
||||
'mystat_privacy_zone_section'
|
||||
'statpress_render_enable_api_field',
|
||||
'statpress-privacy-section',
|
||||
'statpress_privacy_zone_section'
|
||||
);
|
||||
}
|
||||
|
||||
function mystat_privacy_section_callback() {
|
||||
function statpress_privacy_section_callback() {
|
||||
echo '<p>Zdefiniuj strefę prywatności, aby ukryć początek i koniec swoich tras GPX. Punkty wewnątrz tego okręgu nie będą wyświetlane na mapie.</p>';
|
||||
echo '<p>Aby znaleźć swoje współrzędne, kliknij prawym przyciskiem myszy na mapie Google w wybranym miejscu - współrzędne pojawią się jako pierwsza pozycja w menu.</p>';
|
||||
}
|
||||
|
||||
function mystat_render_lat_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
function statpress_render_lat_field() {
|
||||
$options = get_option( 'statpress_privacy_options' );
|
||||
$latitude = isset( $options['latitude'] ) ? esc_attr( $options['latitude'] ) : '';
|
||||
echo "<input type='text' name='mystat_privacy_options[latitude]' value='{$latitude}' placeholder='np. 52.2297' class='regular-text' />";
|
||||
echo "<input type='text' name='statpress_privacy_options[latitude]' value='{$latitude}' placeholder='np. 52.2297' class='regular-text' />";
|
||||
}
|
||||
|
||||
function mystat_render_lon_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
function statpress_render_lon_field() {
|
||||
$options = get_option( 'statpress_privacy_options' );
|
||||
$longitude = isset( $options['longitude'] ) ? esc_attr( $options['longitude'] ) : '';
|
||||
echo "<input type='text' name='mystat_privacy_options[longitude]' value='{$longitude}' placeholder='np. 21.0122' class='regular-text' />";
|
||||
echo "<input type='text' name='statpress_privacy_options[longitude]' value='{$longitude}' placeholder='np. 21.0122' class='regular-text' />";
|
||||
}
|
||||
|
||||
function mystat_render_radius_field() {
|
||||
$options = get_option( 'mystat_privacy_options' );
|
||||
function statpress_render_radius_field() {
|
||||
$options = get_option( 'statpress_privacy_options' );
|
||||
$radius = isset( $options['radius'] ) ? esc_attr( $options['radius'] ) : '500';
|
||||
echo "<input type='number' name='mystat_privacy_options[radius]' value='{$radius}' class='small-text' /> metrów";
|
||||
echo "<input type='number' name='statpress_privacy_options[radius]' value='{$radius}' class='small-text' /> metrów";
|
||||
}
|
||||
|
||||
function mystat_sanitize_privacy_options( $input ) {
|
||||
function statpress_sanitize_privacy_options( $input ) {
|
||||
$sanitized_input = array();
|
||||
if ( isset( $input['latitude'] ) ) {
|
||||
$sanitized_input['latitude'] = floatval( str_replace( ',', '.', $input['latitude'] ) );
|
||||
@@ -118,18 +118,18 @@ function mystat_sanitize_privacy_options( $input ) {
|
||||
return $sanitized_input;
|
||||
}
|
||||
|
||||
function mystat_api_section_callback() {
|
||||
function statpress_api_section_callback() {
|
||||
echo '<p>Ustawienia związane z integracją wtyczki z zewnętrznymi aplikacjami, np. mobilnymi.</p>';
|
||||
}
|
||||
|
||||
function mystat_render_enable_api_field() {
|
||||
$options = get_option( 'mystat_api_options' );
|
||||
function statpress_render_enable_api_field() {
|
||||
$options = get_option( 'statpress_api_options' );
|
||||
$checked = isset( $options['enable_api'] ) && $options['enable_api'] ? 'checked' : '';
|
||||
echo "<label><input type='checkbox' name='mystat_api_options[enable_api]' value='1' {$checked} /> Włącz REST API</label>";
|
||||
echo "<label><input type='checkbox' name='statpress_api_options[enable_api]' value='1' {$checked} /> Włącz REST API</label>";
|
||||
echo '<p class="description">Umożliwia zewnętrznym aplikacjom (np. na Androida) komunikację z wtyczką w celu dodawania i odczytywania aktywności. Jeśli nie korzystasz z takich integracji, możesz to wyłączyć dla większego bezpieczeństwa.</p>';
|
||||
}
|
||||
|
||||
function mystat_sanitize_api_options( $input ) {
|
||||
function statpress_sanitize_api_options( $input ) {
|
||||
$sanitized_input = array();
|
||||
// If the checkbox is not checked, it won't be in the $input array.
|
||||
// So we check for its existence to determine if it's on or off.
|
||||
|
||||
@@ -3,9 +3,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function mystat_yearly_summary_page() {
|
||||
function statpress_yearly_summary_page() {
|
||||
global $wpdb;
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
|
||||
$current_year = isset( $_GET['year'] ) ? intval( $_GET['year'] ) : current_time( 'Y' );
|
||||
|
||||
@@ -16,7 +16,7 @@ function mystat_yearly_summary_page() {
|
||||
}
|
||||
|
||||
// --- GOALS SECTION ---
|
||||
$table_goals = $wpdb->prefix . 'mystat_goals';
|
||||
$table_goals = $wpdb->prefix . 'statpress_goals';
|
||||
$goals_for_year = $wpdb->get_results(
|
||||
$wpdb->prepare(
|
||||
"SELECT * FROM {$table_goals} WHERE year = %d ORDER BY name ASC",
|
||||
@@ -103,8 +103,8 @@ function mystat_yearly_summary_page() {
|
||||
|
||||
// Włączenie skryptów dla Chart.js
|
||||
wp_enqueue_script( 'chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', array(), null, true );
|
||||
wp_register_script( 'mystat-chart-loader', false );
|
||||
wp_enqueue_script( 'mystat-chart-loader' );
|
||||
wp_register_script( 'statpress-chart-loader', false );
|
||||
wp_enqueue_script( 'statpress-chart-loader' );
|
||||
|
||||
$chart_configs = array(
|
||||
'distance' => array(
|
||||
@@ -138,7 +138,7 @@ function mystat_yearly_summary_page() {
|
||||
);
|
||||
|
||||
wp_add_inline_script(
|
||||
'mystat-chart-loader',
|
||||
'statpress-chart-loader',
|
||||
'
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const chartLabels = ' . json_encode( $chart_labels_js ) . ';
|
||||
@@ -162,7 +162,7 @@ function mystat_yearly_summary_page() {
|
||||
activeChart.destroy();
|
||||
}
|
||||
const config = chartConfigs[type];
|
||||
const ctx = document.getElementById("mystatYearlyChart").getContext("2d");
|
||||
const ctx = document.getElementById("statpressYearlyChart").getContext("2d");
|
||||
activeChart = new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: {
|
||||
@@ -198,7 +198,7 @@ function mystat_yearly_summary_page() {
|
||||
<div class="alignleft actions">
|
||||
<label for="filter-by-year" class="screen-reader-text">Filtruj według roku</label>
|
||||
<form method="get" style="display: flex; gap: 5px; align-items: center;">
|
||||
<input type="hidden" name="page" value="mystat-yearly-summary">
|
||||
<input type="hidden" name="page" value="statpress-yearly-summary">
|
||||
<select name="year" id="filter-by-year">
|
||||
<?php foreach ( $available_years as $year_option ) : ?>
|
||||
<option value="<?php echo esc_attr( $year_option ); ?>" <?php selected( $current_year, $year_option ); ?>><?php echo esc_html( $year_option ); ?></option>
|
||||
@@ -213,10 +213,10 @@ function mystat_yearly_summary_page() {
|
||||
<div class="postbox" style="margin-bottom: 20px;">
|
||||
<div class="postbox-header"><h2 class="hndle">Cele na <?php echo esc_html( $current_year ); ?></h2></div>
|
||||
<div class="inside">
|
||||
<ul class="mystat-goals-list">
|
||||
<ul class="statpress-goals-list">
|
||||
<?php
|
||||
foreach ( $goals_for_year as $goal ) :
|
||||
$progress = mystat_get_goal_progress( $goal );
|
||||
$progress = statpress_get_goal_progress( $goal );
|
||||
$percentage = min( 100, $progress['percentage'] );
|
||||
|
||||
$target_formatted = '';
|
||||
@@ -232,13 +232,13 @@ function mystat_yearly_summary_page() {
|
||||
$current_formatted = (int) $progress['current_value'];
|
||||
}
|
||||
?>
|
||||
<li class="mystat-goal-item">
|
||||
<div class="mystat-goal-info">
|
||||
<li class="statpress-goal-item">
|
||||
<div class="statpress-goal-info">
|
||||
<strong><?php echo esc_html( $goal->name ); ?></strong>
|
||||
<small><?php echo $current_formatted; ?> / <?php echo $target_formatted; ?> (<?php echo round( $percentage, 1 ); ?>%)</small>
|
||||
</div>
|
||||
<div class="mystat-progress-bar-container">
|
||||
<div class="mystat-progress-bar" style="width: <?php echo esc_attr( $percentage ); ?>%;"></div>
|
||||
<div class="statpress-progress-bar-container">
|
||||
<div class="statpress-progress-bar" style="width: <?php echo esc_attr( $percentage ); ?>%;"></div>
|
||||
</div>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
@@ -246,8 +246,8 @@ function mystat_yearly_summary_page() {
|
||||
</div>
|
||||
</div>
|
||||
<style>
|
||||
.mystat-goals-list { list-style: none; margin: 0; padding: 0; } .mystat-goal-item { margin-bottom: 15px; } .mystat-goal-info { display: flex; justify-content: space-between; margin-bottom: 5px; }
|
||||
.mystat-progress-bar-container { background: #eee; border-radius: 4px; height: 18px; width: 100%; overflow: hidden; } .mystat-progress-bar { background: #3498db; height: 100%; border-radius: 4px; transition: width 0.5s ease-in-out; text-align: center; color: white; font-size: 11px; line-height: 18px; }
|
||||
.statpress-goals-list { list-style: none; margin: 0; padding: 0; } .statpress-goal-item { margin-bottom: 15px; } .statpress-goal-info { display: flex; justify-content: space-between; margin-bottom: 5px; }
|
||||
.statpress-progress-bar-container { background: #eee; border-radius: 4px; height: 18px; width: 100%; overflow: hidden; } .statpress-progress-bar { background: #3498db; height: 100%; border-radius: 4px; transition: width 0.5s ease-in-out; text-align: center; color: white; font-size: 11px; line-height: 18px; }
|
||||
</style>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -261,7 +261,7 @@ function mystat_yearly_summary_page() {
|
||||
<a href="#activities" class="nav-tab">Aktywności</a>
|
||||
</nav>
|
||||
<div style="position: relative; height:40vh; width:100%;">
|
||||
<canvas id="mystatYearlyChart"></canvas>
|
||||
<canvas id="statpressYearlyChart"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,8 +12,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
/**
|
||||
* Register REST API routes.
|
||||
*/
|
||||
function mystat_register_rest_routes() {
|
||||
$namespace = 'mystat/v1';
|
||||
function statpress_register_rest_routes() {
|
||||
$namespace = 'statpress/v1';
|
||||
|
||||
// Route for getting a collection of activities
|
||||
register_rest_route(
|
||||
@@ -22,8 +22,8 @@ function mystat_register_rest_routes() {
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => 'mystat_get_activities_api',
|
||||
'permission_callback' => 'mystat_api_permissions_check',
|
||||
'callback' => 'statpress_get_activities_api',
|
||||
'permission_callback' => 'statpress_api_permissions_check',
|
||||
'args' => array(
|
||||
'page' => array(
|
||||
'validate_callback' => 'is_numeric',
|
||||
@@ -35,8 +35,8 @@ function mystat_register_rest_routes() {
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => 'mystat_create_activity_api',
|
||||
'permission_callback' => 'mystat_api_permissions_check',
|
||||
'callback' => 'statpress_create_activity_api',
|
||||
'permission_callback' => 'statpress_api_permissions_check',
|
||||
),
|
||||
)
|
||||
);
|
||||
@@ -48,18 +48,18 @@ function mystat_register_rest_routes() {
|
||||
array(
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => 'mystat_get_activity_api',
|
||||
'permission_callback' => 'mystat_api_permissions_check',
|
||||
'callback' => 'statpress_get_activity_api',
|
||||
'permission_callback' => 'statpress_api_permissions_check',
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => 'mystat_update_activity_api',
|
||||
'permission_callback' => 'mystat_api_permissions_check',
|
||||
'callback' => 'statpress_update_activity_api',
|
||||
'permission_callback' => 'statpress_api_permissions_check',
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => 'mystat_delete_activity_api',
|
||||
'permission_callback' => 'mystat_api_permissions_check',
|
||||
'callback' => 'statpress_delete_activity_api',
|
||||
'permission_callback' => 'statpress_api_permissions_check',
|
||||
),
|
||||
)
|
||||
);
|
||||
@@ -70,7 +70,7 @@ function mystat_register_rest_routes() {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function mystat_api_permissions_check() {
|
||||
function statpress_api_permissions_check() {
|
||||
return current_user_can( 'manage_options' );
|
||||
}
|
||||
|
||||
@@ -80,9 +80,9 @@ function mystat_api_permissions_check() {
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
function mystat_get_activities_api( WP_REST_Request $request ) {
|
||||
function statpress_get_activities_api( WP_REST_Request $request ) {
|
||||
global $wpdb;
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
|
||||
$per_page = $request->get_param( 'per_page' ) ? (int) $request->get_param( 'per_page' ) : 20;
|
||||
$page = $request->get_param( 'page' ) ? (int) $request->get_param( 'page' ) : 1;
|
||||
@@ -91,9 +91,9 @@ function mystat_get_activities_api( WP_REST_Request $request ) {
|
||||
$sql = $wpdb->prepare(
|
||||
"SELECT a.*, c.name as category_name, et.name as event_type_name, eq.name as equipment_name
|
||||
FROM $table_activities a
|
||||
LEFT JOIN {$wpdb->prefix}mystat_categories c ON a.category_id = c.id
|
||||
LEFT JOIN {$wpdb->prefix}mystat_event_types et ON a.event_type_id = et.id
|
||||
LEFT JOIN {$wpdb->prefix}mystat_equipment eq ON a.equipment_id = eq.id
|
||||
LEFT JOIN {$wpdb->prefix}statpress_categories c ON a.category_id = c.id
|
||||
LEFT JOIN {$wpdb->prefix}statpress_event_types et ON a.event_type_id = et.id
|
||||
LEFT JOIN {$wpdb->prefix}statpress_equipment eq ON a.equipment_id = eq.id
|
||||
ORDER BY a.date DESC, a.id DESC
|
||||
LIMIT %d OFFSET %d",
|
||||
$per_page,
|
||||
@@ -111,11 +111,11 @@ function mystat_get_activities_api( WP_REST_Request $request ) {
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
function mystat_get_activity_api( WP_REST_Request $request ) {
|
||||
function statpress_get_activity_api( WP_REST_Request $request ) {
|
||||
global $wpdb;
|
||||
$id = (int) $request['id'];
|
||||
|
||||
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}mystat_activities WHERE id = %d", $id );
|
||||
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}statpress_activities WHERE id = %d", $id );
|
||||
$activity = $wpdb->get_row( $sql );
|
||||
|
||||
if ( ! $activity ) {
|
||||
@@ -131,15 +131,15 @@ function mystat_get_activity_api( WP_REST_Request $request ) {
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
function mystat_create_activity_api( WP_REST_Request $request ) {
|
||||
function statpress_create_activity_api( WP_REST_Request $request ) {
|
||||
$params = $request->get_json_params();
|
||||
$activity_id = mystat_save_activity_data( $params );
|
||||
$activity_id = statpress_save_activity_data( $params );
|
||||
|
||||
if ( ! $activity_id ) {
|
||||
return new WP_Error( 'cant-create', 'Error creating activity', array( 'status' => 500 ) );
|
||||
}
|
||||
|
||||
$response = mystat_get_activity_api( new WP_REST_Request( 'GET', "/mystat/v1/activities/{$activity_id}" ) );
|
||||
$response = statpress_get_activity_api( new WP_REST_Request( 'GET', "/statpress/v1/activities/{$activity_id}" ) );
|
||||
$response->set_status( 201 ); // 201 Created
|
||||
return $response;
|
||||
}
|
||||
@@ -150,16 +150,16 @@ function mystat_create_activity_api( WP_REST_Request $request ) {
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
function mystat_update_activity_api( WP_REST_Request $request ) {
|
||||
function statpress_update_activity_api( WP_REST_Request $request ) {
|
||||
$id = (int) $request['id'];
|
||||
$params = $request->get_json_params();
|
||||
$activity_id = mystat_save_activity_data( $params, $id );
|
||||
$activity_id = statpress_save_activity_data( $params, $id );
|
||||
|
||||
if ( ! $activity_id ) {
|
||||
return new WP_Error( 'cant-update', 'Error updating activity', array( 'status' => 500 ) );
|
||||
}
|
||||
|
||||
return mystat_get_activity_api( $request );
|
||||
return statpress_get_activity_api( $request );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,11 +168,11 @@ function mystat_update_activity_api( WP_REST_Request $request ) {
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response|WP_Error
|
||||
*/
|
||||
function mystat_delete_activity_api( WP_REST_Request $request ) {
|
||||
function statpress_delete_activity_api( WP_REST_Request $request ) {
|
||||
global $wpdb;
|
||||
$id = (int) $request['id'];
|
||||
|
||||
$result = $wpdb->delete( $wpdb->prefix . 'mystat_activities', array( 'id' => $id ), array( '%d' ) );
|
||||
$result = $wpdb->delete( $wpdb->prefix . 'statpress_activities', array( 'id' => $id ), array( '%d' ) );
|
||||
|
||||
if ( ! $result ) {
|
||||
return new WP_Error( 'cant-delete', 'Error deleting activity', array( 'status' => 500 ) );
|
||||
|
||||
@@ -16,10 +16,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @param int $activity_id The ID of the activity to update. 0 for new activity.
|
||||
* @return int|false The ID of the saved/updated activity, or false on failure.
|
||||
*/
|
||||
function mystat_save_activity_data( array $data, int $activity_id = 0 ) {
|
||||
function statpress_save_activity_data( array $data, int $activity_id = 0 ) {
|
||||
global $wpdb;
|
||||
|
||||
$table_activities = $wpdb->prefix . 'mystat_activities';
|
||||
$table_activities = $wpdb->prefix . 'statpress_activities';
|
||||
|
||||
// Helper to convert empty strings to NULL for the database.
|
||||
$null_if_empty = function( $value ) {
|
||||
|
||||
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @param string $gpx_url The URL of the GPX file.
|
||||
* @return array An array containing 'points' for the map and 'elevation_profile'.
|
||||
*/
|
||||
function mystat_parse_gpx_data( $gpx_url ) {
|
||||
function statpress_parse_gpx_data( $gpx_url ) {
|
||||
if ( empty( $gpx_url ) ) {
|
||||
return array();
|
||||
}
|
||||
@@ -26,7 +26,7 @@ function mystat_parse_gpx_data( $gpx_url ) {
|
||||
}
|
||||
|
||||
// --- Privacy Zone ---
|
||||
$privacy_options = get_option( 'mystat_privacy_options' );
|
||||
$privacy_options = get_option( 'statpress_privacy_options' );
|
||||
$privacy_enabled = ! empty( $privacy_options['latitude'] ) && ! empty( $privacy_options['longitude'] ) && ! empty( $privacy_options['radius'] );
|
||||
$privacy_center_lat = $privacy_enabled ? (float) $privacy_options['latitude'] : 0;
|
||||
$privacy_center_lon = $privacy_enabled ? (float) $privacy_options['longitude'] : 0;
|
||||
|
||||
@@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* @param array $mimes Allowed mime types.
|
||||
* @return array Modified mime types.
|
||||
*/
|
||||
function mystat_add_gpx_mime_type( $mimes ) {
|
||||
function statpress_add_gpx_mime_type( $mimes ) {
|
||||
$mimes['gpx'] = 'application/gpx+xml';
|
||||
return $mimes;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ function mystat_add_gpx_mime_type( $mimes ) {
|
||||
* @param array $mimes Mime types.
|
||||
* @return array Modified file data.
|
||||
*/
|
||||
function mystat_fix_gpx_upload_permission( $data, $file, $filename, $mimes ) {
|
||||
function statpress_fix_gpx_upload_permission( $data, $file, $filename, $mimes ) {
|
||||
if ( strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) ) === 'gpx' ) {
|
||||
$data['ext'] = 'gpx';
|
||||
$data['type'] = 'application/gpx+xml';
|
||||
|
||||
+31
-34
@@ -1,58 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: WordPress Activity Stats
|
||||
* Plugin Name: StatPress
|
||||
* Description: Wtyczka do śledzenia statystyk sportowych (Rower, Bieganie, itp.).
|
||||
* Version: 1.0
|
||||
* Author: Jacek Fefliński
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
// Definicja stałych
|
||||
define( 'MYSTAT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||
define( 'MYSTAT_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
define( 'STATPRESS_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
||||
define( 'STATPRESS_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
||||
|
||||
// --- 1. PLIKI RDZENNE I AKTYWACJA ---
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/activation.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/core/gpx-parser.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/core/crud-activity.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/core/gpx-upload.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/activation.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/core/gpx-parser.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/core/crud-activity.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/core/gpx-upload.php';
|
||||
|
||||
register_activation_hook( __FILE__, 'mystat_activate' );
|
||||
register_activation_hook( __FILE__, 'statpress_activate' );
|
||||
|
||||
// --- 2. PLIKI I HOOKI PANELU ADMINA ---
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/hooks.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/menu.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-dashboard.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-activity-form.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-activity-view.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-event-types.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-equipment.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-goals.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-settings.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-yearly-summary.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-infographic.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/page-import-csv.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/hooks.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/menu.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-dashboard.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-activity-form.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-activity-view.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-event-types.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-equipment.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-goals.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-settings.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-yearly-summary.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-infographic.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/page-import-csv.php';
|
||||
|
||||
|
||||
$mystat_plugin_hooks = [];
|
||||
|
||||
add_action( 'admin_menu', 'mystat_add_admin_menu' );
|
||||
add_action( 'admin_init', 'mystat_admin_init_setup' );
|
||||
add_action( 'admin_enqueue_scripts', 'mystat_enqueue_admin_styles' );
|
||||
add_action( 'admin_menu', 'statpress_add_admin_menu' );
|
||||
add_action( 'admin_init', 'statpress_admin_init_setup' );
|
||||
add_action( 'admin_enqueue_scripts', 'statpress_enqueue_admin_styles' );
|
||||
|
||||
// --- 3. REST API ---
|
||||
$api_options = get_option( 'mystat_api_options' );
|
||||
$api_options = get_option( 'statpress_api_options' );
|
||||
if ( ! empty( $api_options['enable_api'] ) ) {
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/admin/pages/routes.php';
|
||||
add_action( 'rest_api_init', 'mystat_register_rest_routes' );
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/admin/pages/routes.php';
|
||||
add_action( 'rest_api_init', 'statpress_register_rest_routes' );
|
||||
}
|
||||
|
||||
// --- 4. SHORTCODE DO WYŚWIETLANIA NA FRONCIE ---
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/frontend/assets.php';
|
||||
require_once MYSTAT_PLUGIN_DIR . 'includes/frontend/shortcodes.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/frontend/assets.php';
|
||||
require_once STATPRESS_PLUGIN_DIR . 'includes/frontend/shortcodes.php';
|
||||
|
||||
add_action( 'wp_enqueue_scripts', 'mystat_enqueue_frontend_assets' );
|
||||
add_action( 'init', 'mystat_register_shortcode' );
|
||||
add_action( 'wp_enqueue_scripts', 'statpress_enqueue_frontend_assets' );
|
||||
add_action( 'init', 'statpress_register_shortcode' );
|
||||
|
||||
Reference in New Issue
Block a user