From 0c20d35928f3f73b2f4d03ebc80f21ba10856849 Mon Sep 17 00:00:00 2001 From: Olivier Berten Date: Wed, 3 Mar 2021 21:59:46 +0100 Subject: [PATCH] Redirect duplicates --- chant.php | 10 ++++++++++ feed.php | 9 ++++++--- gregobase_structure.sql | 7 ++++--- incipit.php | 4 ++-- include/db.php | 3 ++- pleasefix.php | 15 +++++++++------ scores.php | 7 +++++-- source.php | 28 ++++++++++++++++------------ updates.php | 9 ++++++--- usage.php | 2 +- 10 files changed, 61 insertions(+), 33 deletions(-) diff --git a/chant.php b/chant.php index 30f53ae..1a232af 100644 --- a/chant.php +++ b/chant.php @@ -15,6 +15,16 @@ if(!$c) { die('Wrong id'); } +if($c['duplicateof'] > 0) { + header('HTTP/1.1 301 Moved Permanently'); + header('Location: '.$_SERVER['PHP_SELF'].'?id='.$c['duplicateof']); + header('Connection: close'); +} elseif($c['duplicateof']) { + header('HTTP/1.1 301 Moved Permanently'); + header('Location: ./scores.php'); + header('Connection: close'); +} + $title = $c['incipit']?$c['incipit']:'░░'.$c['id'].'░░'; $custom_header = <<
diff --git a/feed.php b/feed.php index 1e585fe..33a4d87 100644 --- a/feed.php +++ b/feed.php @@ -39,9 +39,11 @@ echo ' '; while($m = $req1->fetch_assoc()) { - $user_info = get_userdata($m['user_id']); - echo ' - '.chant_from_id($m['chant_id'])[1].' + $t = chant_from_id($m['chant_id']); + if($t) { + $user_info = get_userdata($m['user_id']); + echo ' + '.$t[1].' '.htmlspecialchars($m['comment']).' '.date(DATE_ATOM,$m['time']).' @@ -51,6 +53,7 @@ while($m = $req1->fetch_assoc()) { '.$dir.'history.php?changeset='.$m['time'].'%7C'.$m['chant_id'].'%7C'.$m['user_id'].' '; + } } echo ''; ?> diff --git a/gregobase_structure.sql b/gregobase_structure.sql index 0064bd4..7d110f2 100644 --- a/gregobase_structure.sql +++ b/gregobase_structure.sql @@ -1,9 +1,9 @@ -- phpMyAdmin SQL Dump --- version 5.1.0-rc2 +-- version 5.1.0 -- https://www.phpmyadmin.net/ -- -- Hôte : localhost --- Généré le : dim. 21 fév. 2021 à 19:10 +-- Généré le : mer. 03 mars 2021 à 21:48 -- Version du serveur : 10.4.17-MariaDB-1:10.4.17+maria~xenial -- Version de PHP : 7.4.15 @@ -67,7 +67,8 @@ CREATE TABLE `gregobase_chants` ( `gabc_verses` text COLLATE utf8_unicode_ci DEFAULT NULL, `tex_verses` text COLLATE utf8_unicode_ci DEFAULT NULL, `remarks` text COLLATE utf8_unicode_ci DEFAULT NULL, - `copyrighted` tinyint(1) NOT NULL DEFAULT 0 + `copyrighted` tinyint(1) NOT NULL DEFAULT 0, + `duplicateof` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -------------------------------------------------------- diff --git a/incipit.php b/incipit.php index 9f0c33b..8890c73 100644 --- a/incipit.php +++ b/incipit.php @@ -11,9 +11,9 @@ include('include/header.php'); echo "

$title

\n"; if($l) { - $sql1 = 'SELECT * FROM '.db('chants').' WHERE `incipit` LIKE "'.$l.'%" ORDER BY incipit ASC'; + $sql1 = 'SELECT * FROM '.db('chants').' WHERE `duplicateof` IS NULL AND `incipit` LIKE "'.$l.'%" ORDER BY incipit ASC'; } else { - $sql1 = 'SELECT * FROM '.db('chants')." WHERE `incipit` LIKE '' OR UPPER(incipit) REGEXP '^[^A-Zƌ].*' ORDER BY incipit ASC"; + $sql1 = 'SELECT * FROM '.db('chants')." WHERE `duplicateof` IS NULL AND (`incipit` LIKE '' OR UPPER(incipit) REGEXP '^[^A-Zƌ].*') ORDER BY incipit ASC"; } $req1 = $mysqli->query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error); $chants = array(); diff --git a/include/db.php b/include/db.php index b6f6379..9b8825a 100644 --- a/include/db.php +++ b/include/db.php @@ -2,10 +2,11 @@ function chant_from_id($c) { global $mysqli; - $sql1 = 'SELECT `office-part`,incipit,gabc,version FROM '.db('chants').' WHERE id = '.$c; + $sql1 = 'SELECT `office-part`,incipit,gabc,version,duplicateof FROM '.db('chants').' WHERE id = '.$c; $req1 = $mysqli->query($sql1) or die('Erreur SQL !
'.$sql1.'
'.$mysqli->error); $chants = array(); $ch = $req1->fetch_assoc(); + if($ch['duplicateof']) return false; return array($ch['office-part'], $ch['incipit'] > ''?$ch['incipit']:'░░'.$c.'░░', $ch['gabc'] > '', $ch['version']); } diff --git a/pleasefix.php b/pleasefix.php index 8bfc432..7b9f6c1 100644 --- a/pleasefix.php +++ b/pleasefix.php @@ -8,13 +8,16 @@ $sql = 'SELECT * FROM '.db('pleasefix').' WHERE fixed = 0 ORDER BY `time`'; $req = $mysqli->query($sql) or die('Erreur SQL !
'.$sql.'
'.$mysqli->error); if($req->num_rows > 0) { while($fix = $req->fetch_assoc()) { - echo '

'.format_incipit(chant_from_id($fix['chant_id'])[1])."

\n"; - echo "

".nl2br(htmlspecialchars($fix['pleasefix'])).' (Reported on '.date("Y-m-d",$fix['time']); - if($fix['user_id']) { - $user_info = get_userdata($fix['user_id']); - echo ' by '.$user_info->display_name; + $t = chant_from_id($fix['chant_id']); + if($t) { + echo '

'.format_incipit($t[1])."

\n"; + echo "

".nl2br(htmlspecialchars($fix['pleasefix'])).' (Reported on '.date("Y-m-d",$fix['time']); + if($fix['user_id']) { + $user_info = get_userdata($fix['user_id']); + echo ' by '.$user_info->display_name; + } + echo ")

\n"; } - echo ")

\n"; } } else { echo "

No problem reported

\n"; diff --git a/scores.php b/scores.php index aeb88e5..e57a8be 100644 --- a/scores.php +++ b/scores.php @@ -71,8 +71,11 @@ foreach($mod as $d => $ml) { echo $d; echo "
\n"; } diff --git a/source.php b/source.php index 2d277a0..682df44 100644 --- a/source.php +++ b/source.php @@ -52,13 +52,15 @@ if(array_key_exists('images', $_GET) && $_GET['images'] == '1') { $ch = $chants[$p]; foreach($ch as $c) { $t = chant_from_id($c[0]); - echo '
  • '; - if($t[2]) { - echo ''.format_incipit($t[1]).""; - } else { - echo ''.format_incipit($t[1]).' (TODO)'; + if($t) { + echo '
  • '; + if($t[2]) { + echo ''.format_incipit($t[1]).""; + } else { + echo ''.format_incipit($t[1]).' (TODO)'; + } + echo "
  • \n"; } - echo "\n"; } } echo '
  • Add chant
  • '."\n"; @@ -89,13 +91,15 @@ if(array_key_exists('images', $_GET) && $_GET['images'] == '1') { unset($chants[$p]); foreach($ch as $c) { $t = chant_from_id($c[0]); - echo '
  • '; - if($t[2]) { - echo ''.format_incipit($t[1]).""; - } else { - echo ''.format_incipit($t[1]).''; + if($t) { + echo '
  • '; + if($t[2]) { + echo ''.format_incipit($t[1]).""; + } else { + echo ''.format_incipit($t[1]).''; + } + echo "
  • \n"; } - echo "\n"; } echo "\n"; echo "\n"; diff --git a/updates.php b/updates.php index 50bdb22..ce61002 100644 --- a/updates.php +++ b/updates.php @@ -22,9 +22,12 @@ foreach($mod as $d => $ml) { echo "

    ".$d."

    \n"; echo "\n"; } diff --git a/usage.php b/usage.php index d40235b..cf1b639 100644 --- a/usage.php +++ b/usage.php @@ -13,7 +13,7 @@ if(!array_key_exists($id,$txt['usage'])) { $title = 'Usage - '.$txt['usage'][$id]; include('include/header.php'); echo "

    $title

    \n"; -$sql1 = 'SELECT * FROM '.db('chants').' WHERE `office-part` = "'.$id.'" ORDER BY incipit ASC'; +$sql1 = 'SELECT * FROM '.db('chants').' WHERE `duplicateof` IS NULL AND `office-part` = "'.$id.'" ORDER BY incipit ASC'; $req1 = $mysqli->query($sql1) or die('Erreur SQL !
    '.$sql1.'
    '.$mysqli->error); $chants = array(); while($c = $req1->fetch_assoc()) {