-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchesstable.php
308 lines (280 loc) · 10.2 KB
/
chesstable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');
/**
* Contao Open Source CMS
*
* Copyright (C) 2005-2013 Leo Feyer
*
* @package chesstable
* Version 1.0.0
* @author Frank Hoppe
* @license GNU/LGPL
* @copyright Frank Hoppe 2013
*/
class chesstable extends \ContentElement
{
/**
* Template
* @var string
*/
protected $strTemplate = 'ce_chesstable';
protected $strTemplateLightbox = 'ce_chesstable_lightbox';
/**
* Generate the module
*/
protected function compile()
{
//global $objPage,$objArticle;
//print_r($GLOBALS);
//echo "ID=".$objPage->id;
// Parameter zuweisen
$csv = $this->chesstable_csv;
$file = $this->chesstable_file;
$aufsteiger = explode(",",$this->chesstable_aufsteiger);
$absteiger = explode(",",$this->chesstable_absteiger);
$markieren = explode(",",$this->chesstable_markieren);
$namendrehen = $this->chesstable_namendrehen;
$lightbox = $this->chesstable_lightbox;
$linktext = $this->chesstable_linktext;
$flagge = $this->chesstable_flaggen;
// Array-Werte wie z.B. "1-5" weiter auflösen in 1,2,3,4,5
$aufsteiger = $this->ArrayAufloesen($aufsteiger);
$absteiger = $this->ArrayAufloesen($absteiger);
$markieren = $this->ArrayAufloesen($markieren);
// Aktualisierungsdatum
($this->chesstable_date) ? $aktdatum = $this->tstamp : $aktdatum = 0;
if(!$linktext) $linktext = "Alternativtabelle";
// Konfiguration der Tabellenköpfe einlesen (als Kleinschreibung)
$blindfelder = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_blindfelder']));
$spaltenkopf = array();
$spaltenkopf[1] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_nationfelder']));
$spaltenkopf[2] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_platzfelder']));
$spaltenkopf[3] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_vereinfelder']));
$spaltenkopf[4] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_namenfelder']));
$spaltenkopf[5] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_punktefelder']));
$spaltenkopf[6] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_wertungfelder']));
$spaltenkopf[7] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_ratingfelder']));
$spaltenkopf[8] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_ergebnisfelder']));
$spaltenkopf[9] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_farbfelder']));
$spaltenkopf[10] = array_map(array($this,"kleinschreibung"),explode(",",$GLOBALS['TL_CONFIG']['chesstable_steuerfelder']));
$klassen = array("text","nation","place","club","name","points","rating","elo","result","color","control");
// CSV-Daten in Tabellen-Array übertragen
$steuerspalte = 0;
$tabelle = array();
$eigenklasse = array(); // Array, um die eigenen Klassennamen zu speichern
$spaltenart = array();
$zeile = explode("\n",$csv); // Zeilen trennen
for($x=0;$x<count($zeile);$x++)
{
$spalte = explode(";",$zeile[$x]); // Spalten trennen
for($y=0;$y<count($spalte);$y++)
{
$temp = trim($spalte[$y]); // Feldinhalt trimmen
list($tabelle[$x][$y], $eigenklasse[$x][$y]) = $this->ExtractClass($temp); // Eigene Klasse finden
// Wenn oberste Zeile, dann Spaltenart feststellen
if($x == 0)
{
$spaltenart[$y+1] = 0; // Standardkopf
for($z=1;$z<=count($spaltenkopf);$z++)
{
// Spaltentitel in definierten Spaltenköpfen suchen
// Bsp. Suche nach "name" im Array("1","2","3")
if(in_array(strtolower($tabelle[$x][$y]),$spaltenkopf[$z]))
{
$spaltenart[$y+1] = $z; // Anderen Spaltenkopf gefunden
if($klassen[$spaltenart[$y+1]] == "control") $steuerspalte = $y+1; // Steuerspalte sichern
break;
}
}
}
}
}
//echo "<pre>";
//print_r($tabelle);
//echo "<pre>";
// Tabelle generieren
$content = "<table class=\"chesstable\">\n";
// Zuerst Zeilen durchlaufen
for($x=0;$x<count($tabelle);$x++)
{
$ze = $x + 1; // Zeilennummer ab 1 statt 0
// Wenn Steuerspalte den Wert "team" enthält, dann CSS-Klasse in Zeile eintragen
($steuerspalte && $tabelle[$x][$steuerspalte-1] == "team") ? $trcss = "row$ze team" : $trcss = "row$ze";
// Zeilen mit Auf- und Absteigern markieren
if(in_array($ze, $aufsteiger)) $trcss .= " up";
if(in_array($ze, $absteiger)) $trcss .= " down";
if(in_array($ze, $markieren)) $trcss .= " high";
// Ist ein Befehl in Spalte 1?
if($tabelle[$x][0] == '~')
{
// Leerzeile erzeugen und nächste Zeile als Kopfzeile (th) formatieren
$content .= "<tr class=\"leerzeile\">\n";
$content .= " <td colspan=\"" . $spaltenzahl . "\"></td>\n";
$content .= "</tr>\n";
$kopfzeile = true;
continue;
}
elseif($tabelle[$x][0] == '[TEXT]')
{
// Textzeile erzeugen
$content .= "<tr class=\"textzeile\">\n";
$content .= " <td colspan=\"" . $spaltenzahl . "\">" . $tabelle[$x][1] . "</td>\n";
$content .= "</tr>\n";
continue;
}
$content .= "<tr class=\"$trcss\">\n";
// Jetzt Spalten durchlaufen
for($y=0;$y<count($tabelle[$x]);$y++)
{
$sp = $y+1; // Spaltennummer ab 1 statt 0
$wert = $tabelle[$x][$y]; // Wert aus Tabelle zuweisen
$ownclass = $eigenklasse[$x][$y]; // Klasse aus Tabelle zuweisen
$wert = \Controller::replaceInsertTags($wert); // Inserttags ersetzen
// Zeilenart td oder th einstellen
if($ze == 1 || $kopfzeile)
{
$td = "th";
}
else $td = "td"; // th statt td in Zeile 1
$klasse = $klassen[$spaltenart[$sp]]; // CSS-Klasse für Spaltenart
// Name drehen, wenn gefordert
if($namendrehen && $klasse == "name" && $ze > 1)
{
$wert = $this->NameDrehen($wert);
}
if(in_array(strtolower($wert),$blindfelder))
$content .= "<$td class=\"row$ze col$sp blindfield $klasse$ownclass\">".$wert."</$td>\n";
else if($klasse == "control") // Spalte 'control' nicht anzeigen
$content .= "";
else if($td == "td" && $klasse == "nation") // wenn Spalte 'nation'
{
if($flagge)
{
// Flagge anzeigen, wenn vorhanden
$flaggenurl = "system/modules/chesstable/assets/images/flags/".strtolower($wert).".jpg";
$flaggendatei = $_SERVER["DOCUMENT_ROOT"]."/".$flaggenurl;
if(file_exists($flaggendatei))
$content .= "<$td title=\"".$wert."\" class=\"row$ze col$sp $klasse$ownclass\"><img src=\"".$flaggenurl."\" width=\"23\" height=\"15\" /></$td>\n";
else
$content .= "<$td title=\"".$wert."\" class=\"row$ze col$sp $klasse$ownclass ".strtolower($wert)." \">".$wert."</$td>\n"; // Nationenname als title und class einfügen
}
else
{
// Länderkürzel oder Flagge mit CSS
$content .= "<$td title=\"".$wert."\" class=\"row$ze col$sp $klasse$ownclass ".strtolower($wert)."\">".$wert."</$td>\n"; // Nationenname als title und class einfügen
}
}
else if($td == "th" && $klasse == "color") // wenn Spaltenkopf 'farbe'
$content .= "<$td title=\"".$wert."\" class=\"row$ze $klasse$ownclass\"> </$td>\n"; // Farbspalte ohne Inhalt in th
else if($td == "td" && $klasse == "color") // wenn Spalte 'farbe'
{
// Farbe feststellen und CSS-Klasse entsprechend modifizieren
if(strtolower($wert) == "w") $klasse .= "_w";
if(strtolower($wert) == "b") $klasse .= "_b";
$content .= "<$td title=\"".$wert."\" class=\"row$ze $klasse$ownclass\"> </$td>\n"; // Farbspalte
}
else
$content .= "<$td class=\"row$ze col$sp $klasse$ownclass\">".$wert."</$td>\n";
}
$content .= "</tr>\n";
$kopfzeile = false;
$spaltenzahl = count($tabelle[$x]); // Anzahl der Spalten für nächsten Schleifenlauf merken
}
$content .= "</table>\n";
// Lightbox-Modus?
if($lightbox)
{
// Template ausgeben
$this->Template = new \FrontendTemplate($this->strTemplateLightbox);
$this->Template->id = $this->id;
$this->Template->linktext = $linktext;
$this->Template->class = "ce_chesstable";
$this->Template->tabelle = $content;
$this->Template->datum = $aktdatum;
$this->Template->turnierende = $this->chesstable_ende;
$this->Template->hinweis = $this->chesstable_note;
}
else
{
// Template ausgeben
$this->Template = new \FrontendTemplate($this->strTemplate);
$this->Template->class = "ce_chesstable";
$this->Template->tabelle = $content;
$this->Template->datum = $aktdatum;
$this->Template->turnierende = $this->chesstable_ende;
$this->Template->hinweis = $this->chesstable_note;
}
return;
}
/**
* Funktion ArrayAufloesen
*
* @param array Bsp.: array('1','3-7','8-9','34')
*
* @return array Bsp.: array('1','3','4','5','6','7','8','9','34')
*/
protected function ArrayAufloesen($array)
{
$newArray = array();
foreach($array as $item)
{
if(ctype_digit($item))
{
// Integerzahl direkt übernehmen
$newArray[] = $item;
}
else
{
// String in der Form "Zahl-Zahl" auflösen
$temp = explode("-", $item);
for($x = $temp[0]; $x <= $temp[1]; $x++)
{
$newArray[] = $x;
}
}
}
return $newArray;
}
protected function kleinschreibung($wert)
{
return strtolower($wert);
}
protected function NameDrehen($intext)
{
// Konvertiert Namen der Form Nachname,Vorname,Titel nach Titel Vorname Name
$array = explode(",",$intext);
$teile = count($array);
$result = "";
for($x=$teile-1;$x>=0;$x--)
{
$result .= " ".$array[$x];
}
return $result;
}
protected function ExtractClass($wert)
{
$pos1 = strpos($wert, '{');
if($pos1 === false)
{
// Startzeichen nicht vorhanden
return array($wert, '');
}
else
{
$pos2 = strpos($wert, '}');
if($pos2 === false)
{
// Endezeichen nicht vorhanden
return array($wert, '');
}
else
{
$pos2 = strpos($wert, '}');
// Werte trennen
$class = ' own_' . substr($wert, $pos1 + 1, $pos2 - $pos1 - 1);
$value = substr($wert, 0, $pos1) . substr($wert, $pos2 + 1);
return array($value, $class);
}
}
}
}
?>