Hallo!
Ich würde gern die Extension mbit_gallery so erweitern, daß man zu jedem Bild eine Bildüberschrift ausgeben kann.
Ich habe mir auch schon etwas überlegt, wie das funktionieren könnte. Leider scheitere ich jetzt an zwei Problemen.
Original Datei "class.tx_mbitgallery_pi1.php":
PHP-Code:
require_once(PATH_tslib.'class.tslib_pibase.php');
class tx_mbitgallery_pi1 extends tslib_pibase {
var $prefixId = 'tx_mbitgallery_pi1'; // Same as class name
var $scriptRelPath = 'pi1/class.tx_mbitgallery_pi1.php'; // Path to this script relative to the extension dir.
var $extKey = 'mbit_gallery'; // The extension key.
var $pi_checkCHash = TRUE;
function main($content,$conf) {
$this->conf=$conf;
$this->pi_setPiVarDefaults();
$this->pi_loadLL();
$i = $a = 0;
$output = "";
$error = false;
$gallerypath = trim($this->conf['gallerypath']); // Path to the Gallery
$piccount = trim($this->conf['piccount']); // show amount of Pics of each Gallery
$gallerycount = trim($this->conf['gallerycount']); // show amount of all Pics in the Gallery
$yearsplit = trim($this->conf['yearsplit']); // Split the List in Year Blocks
$openpid = trim($this->conf['openpid']); // PID of Site for Show
$open = trim($this->conf['open']); // Target for Show
$templatefile = trim($this->conf['templatefile']); // Path to the Template
$popupwidth = trim($this->conf['popupwidth']); // width of the Popup
$popupheight = trim($this->conf['popupheight']); // height of the Popup
$popupresize = trim($this->conf['popupresize']); // resize the Popup
$popupscrollbar = trim($this->conf['popupscrollbar']); // scrollbars in the Template
if (array_key_exists("unter", $this->piVars)) {
$folder = dir($gallerypath . "/" . $this->piVars["unter"]);
$zeichenkette = ereg_replace('_', ' ', $this->piVars["unter"]);
$header = substr ($zeichenkette,8);
while ($file=$folder->read()) {
if (substr("$file",-3) == "jpg" || substr("$file",-3) == "JPG" || substr("$file",-4) == "JPEG" || substr("$file",-4) == "jpeg" || substr("$file",-3) == "gif" || substr("$file",-3) == "GIF" || substr("$file",-3) == "png" || substr("$file",-3) == "PNG") {
$bild[$i]=$file;
$i++;
}
}
if ($i > 0) {
sort ($bild);
$extraJS = "wo = 0;\nbild = Array();\n";
for($i=0;$bild[$i];$i++) {
$extraJS.= "bild[$i]='$bild[$i]';\n";
}
$extraJS.= "function mbit_wo() {
if (wo <= 0) {
prev = 0;
} else {
prev = -1;
}
if (wo >= ";
$extraJS.= $i-1;
$extraJS.= ") {
next = 0;
} else {
next = 1;
}
}
function mbit_changepic(to) {
document.getElementById('pic').src = '" . $gallerypath . $this->piVars["unter"] . "/' + bild[wo+to];
wo = wo + to;
mbit_wo();
document.getElementById(\"wobin\").childNodes[0].nodeValue = wo+1;
// document.getElementById('wobin').innerText = wo+1;
}
mbit_wo();";
} else {
$output = "Folder '" . $gallerypath . "/" . $this->piVars["unter"] . "' is empty.";
$error = true;
}
$this->templateCode = $this->cObj->fileResource($templatefile);
$meintemplate = $this->templateCode;
$markerArray = array();
$markerArray['###PICTOTAL###'] = "<span class='tx_mbitgallery_total'>" . htmlspecialchars($this->pi_getLL('pic')) . " <span id=\"wobin\">1</span> " . htmlspecialchars($this->pi_getLL('of')) . " " . $i . "</span>";
$markerArray['###HEADLINE###'] = "<span class='tx_mbitgallery_header'>" . $header . "</span>";
$markerArray['###PIC###'] = "<img class='tx_mbitgallery_pic' src=\"" . $gallerypath . "/" . $this->piVars["unter"] . "/" . $bild[0] . "\" border=\"0\" id=\"pic\">";
$markerArray['###NEXT###'] = "<a class='tx_mbitgallery_prev' href=\"javascript:\" onClick=\"mbit_changepic(next,'" . $this->piVars["unter"] . "/" . $bild[0] . "/');return false\">" . $this->pi_getLL('next') . "</a>";
$markerArray['###PREV###'] = "<a class='tx_mbitgallery_next' href=\"javascript:\" onClick=\"mbit_changepic(prev,'" . $this->piVars["unter"] . "/" . $bild[0] . "/');return false\">" . $this->pi_getLL('prev') . "</a>";
$output.= $this->cObj->substituteMarkerArrayCached($meintemplate, $markerArray, array(), array());
} else {
if ($folder = @dir($gallerypath)) {
while($file=$folder->read()) {
if ($file != "." && $file != "..") {
$folder2 = dir($gallerypath . "/" . $file);
$filess = -2;
while($file2 = $folder2->read()) {
$filess++;
}
$allfiles += $filess;
$zeichenkette = ereg_replace('_', ' ', $file);
$tok = substr ($zeichenkette,8);
$toknow[$i] = substr ($zeichenkette,0,4);
$i++;
$out[$i] = $this->pi_linkToPage($tok, $openpid, $open, array($this->prefixId.'[unter]' => $file));
if ($open == "mbitgallery_popup") {
$out[$i] = $this->pi_openAtagHrefInJSwindow(html_entity_decode($out[$i]), popup, "width=" . $popupwidth . ",height=" . $popupheight . ",status=yes,resizable=" . $popupresize . ",dependent=yes,scrollbars=" . $popupscrollbar . "");
}
if ($piccount == 1) {
$out[$i].= " (" . $filess . ")";
}
$out[$i].= "<br />";
}
}
$folder->close();
if (count($out) != 0) {
rsort($out);
while($a<$i) {
if (!isset($last) && $yearsplit == 1) {
$output.= "<span class='tx_mbitgallery_year'>" . $toknow[$a] . "</span><br />"; $last = $toknow[$a];
}
if ($toknow[$a] != $last && $yearsplit == 1) {
$output.= "<span class='tx_mbitgallery_year'>" . $toknow[$a] . "</span><br />";
}
$output.= $out[$a];
$a++;
$last = $toknow[$a];
}
if ($gallerycount == 1) {
$output.= "<span class='tx_mbitgallery_count'>" . htmlspecialchars($this->pi_getLL('total')) . $allfiles . htmlspecialchars($this->pi_getLL('pics')) . "</span><br />";
}
} else { // Folder is empty
$output.= "Folder '" . $gallerypath . "' is empty.";
$error = true;
}
} else { // Folder does not exist
$output.= "Folder '" . $gallerypath . "' does not exist.";
$error = true;
}
}
$GLOBALS['TSFE']->setJS('myext_js', $extraJS);
if ($error == true) {
return "<div style='border: 3px solid red; padding: 3px;'>" . $this->pi_wrapInBaseClass($output) . "</div>";
} else {
return $this->pi_wrapInBaseClass($output);
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mbit_gallery/pi1/class.tx_mbitgallery_pi1.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/mbit_gallery/pi1/class.tx_mbitgallery_pi1.php']);
}
?>
Meine Idee:
Ich benenne meine Bilddateien nummer_text.jpg. Die Nummer sorgt dafür, daß die Reihenfolge erhalten bleibt. Der Text soll ausgelesen werden und unter dem Bild ausgegeben werden.
Ich habe zwischen zeile 78 und 79 folgendes eingefügt:
PHP-Code:
$dateiname_jck = ereg_replace('_', ' ', $bild[0]);
$bild_kommentar = substr ($dateiname_jck,3);
$markerArray['###BILDTEXT_JCK###'] = "<P>$bild_kommentar</p>";
Der Marker muß natürlich noch im template eingefügt werden. Dann funktioniert es so halb. Der Dateiname wird ausgelesen und die Nummer wird weggeschnitten. Nun zu meinen Problemen:
1) Wenn man unter dem Bild auf Next oder Prev klickt, läd er korrekt das nächste Bild. Der Text bleibt aber immer der aus dem Dateinamen der ersten Datei. Meine Versuche die Funktion mbit_changepic entsprechend zu ändern, haben nicht funktioniert.
2) Wie schneidet man beim Einlesen des Dateinamens die Endung .jpg weg.
Ein funktionierendes Beispiel der Extension findet Ihr hier.
http://jancaspar.ja.funpic.de/index.php?id=55
Das ist allerdings das Original ohne die oben beschriebenen Versuche Bildtexte einzufügen.