Initial commit — Rosary Presenter App
Full source for loveandrosary.com: slide-based Rosary/novena/Divine Mercy Chaplet presentation tool with multi-user roles, SVG bead ring, audio uploads, donate strip, and public session profiles. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
// Copy this file to config/db.php and fill in your values.
|
||||
// Never commit config/db.php — it is listed in .gitignore.
|
||||
|
||||
define('DB_HOST', 'localhost');
|
||||
define('DB_NAME', 'your_db_name');
|
||||
define('DB_USER', 'your_db_user');
|
||||
define('DB_PASS', 'your_db_password');
|
||||
define('DB_CHARSET', 'utf8mb4');
|
||||
|
||||
// App constants
|
||||
define('UPLOADS_DIR', __DIR__ . '/../uploads/');
|
||||
define('UPLOADS_URL', '/uploads/');
|
||||
define('APP_NAME', 'Rosary Presenter');
|
||||
|
||||
// Base URL path — leave empty for domain root, set to '/subdir' for subdirectory deployment
|
||||
// Example: define('BASE_URL', '/rosary');
|
||||
define('BASE_URL', '');
|
||||
|
||||
/**
|
||||
* Return a PDO connection, creating it on first call.
|
||||
*/
|
||||
function get_pdo(): PDO {
|
||||
static $pdo = null;
|
||||
if ($pdo === null) {
|
||||
$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=' . DB_CHARSET;
|
||||
$options = [
|
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||
PDO::ATTR_EMULATE_PREPARES => false,
|
||||
];
|
||||
$pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
|
||||
}
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a value from site_settings table.
|
||||
*/
|
||||
function get_setting(string $key, string $default = ''): string {
|
||||
static $cache = [];
|
||||
if (isset($cache[$key])) return $cache[$key];
|
||||
try {
|
||||
$st = get_pdo()->prepare('SELECT val FROM site_settings WHERE key_name = ?');
|
||||
$st->execute([$key]);
|
||||
$row = $st->fetch();
|
||||
$cache[$key] = $row ? (string)$row['val'] : $default;
|
||||
} catch (PDOException $e) {
|
||||
$cache[$key] = $default;
|
||||
}
|
||||
return $cache[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a value to site_settings table.
|
||||
*/
|
||||
function set_setting(string $key, string $value): void {
|
||||
get_pdo()->prepare('INSERT INTO site_settings (key_name, val) VALUES (?,?) ON DUPLICATE KEY UPDATE val=?')
|
||||
->execute([$key, $value, $value]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slugify a string for use in URLs.
|
||||
*/
|
||||
function slugify(string $text): string {
|
||||
$text = mb_strtolower(trim($text));
|
||||
$text = preg_replace('/[^a-z0-9\s-]/', '', $text);
|
||||
$text = preg_replace('/[\s-]+/', '-', $text);
|
||||
return trim($text, '-') ?: 'session';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a slug unique for a given user_id in sessions/novena_groups.
|
||||
* $table: 'sessions' or 'novena_groups', $exclude_id: ID to exclude (for edits)
|
||||
*/
|
||||
function unique_slug(string $base, int $user_id, string $table = 'sessions', ?int $exclude_id = null): string {
|
||||
$slug = slugify($base);
|
||||
$pdo = get_pdo();
|
||||
$candidate = $slug;
|
||||
$n = 2;
|
||||
while (true) {
|
||||
$sql = "SELECT COUNT(*) FROM {$table} WHERE slug = ? AND user_id = ?";
|
||||
$params = [$candidate, $user_id];
|
||||
if ($exclude_id !== null) {
|
||||
$sql .= ' AND id != ?';
|
||||
$params[] = $exclude_id;
|
||||
}
|
||||
$st = $pdo->prepare($sql);
|
||||
$st->execute($params);
|
||||
if ((int)$st->fetchColumn() === 0) break;
|
||||
$candidate = $slug . '-' . ($n++);
|
||||
if ($n > 999) { $candidate = $slug . '-' . uniqid(); break; }
|
||||
}
|
||||
return $candidate;
|
||||
}
|
||||
Reference in New Issue
Block a user