PHP Shopconector Class 3.0

Für den Einsatz mit Webshops ab Version 12.0

Code

<?php

error_reporting(E_ERROR);

class shopconector {
# Rahmeneinstellungen
private $webshop_version = 12;// Versionsnummer des Shops
private $wbo_domain = "https://nephele-s4.de/"; // Die Domain von WBO

private $imagefile = "bild.php"; // so heißt die Datei, die die Bilder anzeigt
private $core_path = "shop_core.php"; // Std-Corepath der XML
private $shop_path = ""; // Wird später initialisiert
private $domain = "https://meineSeite.de/"; # Ordner in dem der Shop liegt

private $PayPalBase = $this->domain.$this->core_path # Bekommt die action "?action=paypal_return" bei erfolg und "paypal_error" bei einem Fehler seitens Paypal

# Authentifizierungsvariablen # Blowed
private $shop_id = ""; // SHOP
private $user_id = ""; // USER

// Komma oder Punkt als Dezimaltrenner ?
private $komma = true;

// So heißt die Datei, die den Shop aufruft -> individuell der Seite
private $rootpath = "arbeiten.php";

// konstruktor
function __construct($version,$user_id,$shop_id,$rootpath) {
error_reporting(E_ERROR);
$this->webshop_version = $version;
$this->shop_path = $this->wbo_domain."webshop/".$this->webshop_version.".0/".$this->core_path;
$this->user_id = $user_id;
$this->shop_id = $shop_id;
$this->rootpath = $rootpath;
}

// mache die Seite für die Bildausgabe
# Popup oder "Fake" Bild möglich
function bild($path="") {
$path = $_GET["path"]; // Hier der Pfad für ein engebundenes Bild
// Im Popup oder nur für SEO ?
if($path=="") {
# ok: wir arbeiten also in einem Poup!
$bild = $_GET["bild"];
$bild = str_replace("small","big",$bild);
// Das brauche ich nur einmal gerade um die Größe zu kalkulieren -> das geht nicht auf dem Fake-Bild
$calcbild = str_replace($this->imagefile."?path=",$this->wbo_domain,$bild);
$size = @getimagesize($calcbild);
$width = $size[0];
$height = $size[1];

// leeres Bild abfangen
if($height=="" && $width=="") {
?>
<script language="javascript">
window.close();
</script>
<?
} else {
# TODO: Hier mal etwas verbessern
# Hier rufe ich mich rekursiv wieder auf und tue so, als wäre ich das Bild!
?>
<script language="javascript">
window.onload = function () {
window.resizeTo(<? echo $width+20; ?>,<? echo $height+100; ?>);
window.focus();
}
</script>
<html>
<head>
<title>Abbildung kann abweichen!</title>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<body style="padding:0px; margin:0px;">
<img src="<? echo $bild; ?>" style="margin-top:0px; cursor:pointer;" onClick="window.close();" title="Hier klicken zum Schliessen">
</body>
</html>
<?

}
} else {
// Daten abholen
$path = $this->wbo_domain.$path;
$imageString = file_get_contents($path);

header('Content-Type: image/jpeg');
echo $imageString;

}
}

// Gebe alle Inhalte aus. | Hauptmethode
function gebe_aus() {
$param="";
// Parameter abholen und durchreichen
foreach (array_keys($_GET) as $key) $param .= "&".$key."=".$_GET[$key];
foreach (array_keys($_POST) as $key) $param .= "&".$key."=".$_POST[$key];

// Connection URL erstellen
$url = $this->shop_path;
$url.="?user_id=".$this->user_id;
$url.="&shop_id=".$this->shop_id;
$url.="&webshop_version=".$this->webshop_version;
$url.="&komma=".$this->komma;
$url.="&session_nr=".session_id();
$url.="&session_nr_check=".md5(session_id());
$url.="&PayPalBase=".$this->PayPalBase;
$url.=$param;

return $this->perform_xml_request($this->decode_url($url));


}

// kritische Zeichen ersetzen um Encoding Probleme zu umgehen
function decode_url ($url) {
$url = str_replace("ä", "%E4", $url);
$url = str_replace("Ä", "%C4", $url);
$url = str_replace("ö", "%F6", $url);
$url = str_replace("Ö", "%D6", $url);
$url = str_replace("ü", "%FC", $url);
$url = str_replace("Ü", "%DC", $url);
$url = str_replace("ß", "%DF", $url);
$url = str_replace(" ", "%20", $url);
return $url;
}

// Perform a XML Request - Daten abrugen
function perform_xml_request($url){
// Connect to URL und Stream abholen

$auftrag = fopen($url, "r");
$antwort = "";
while(!feof($auftrag)){ $antwort .= fgets($auftrag); }
fclose($auftrag);

// Austauschen des Standard-Aufrufs
$antwort = str_replace($this->core_path,$this->rootpath,$antwort);

// Austauschen von Bildquellen
$antwort = str_replace($this->wbo_domain,$this->imagefile."?path=",$antwort);
$antwort = str_replace("window.location.href=HOMEPAGE_SHOP","//window.location.href=HOMEPAGE_SHOP",$antwort);
$antwort = str_replace("window.location.href=loc","//window.location.href=loc",$antwort);
return ($antwort);
}
}
?>

 

Einsatzbeispiele:

Einbinden des Shops in eine Seite "arbeiten.php" mit der Version 12.0:

<?
require_once("class.shopconector.php");
$con = new shopconector(12,"XXX","YYY","arbeiten.php");
echo $con->gebe_aus();
?>

Bild.php Seite, die neben der Webshop-PHP Seite benötigt wird:

<? # ich muss in einer Datei "bild.php" stehen!
# Vor und nach mir dürfen keine Leerzeichen sein! Achtung!!
require_once("class.shopconector.php");
$con = new shopconector(12,"XXX","YYY","arbeiten.php");
echo $con->bild();
?>