Sonntag, 11. November 2018

Shirtee-Shop für die eigene Webseite

Ein Tutorial mit dem ein Shirtee-Shop/Store in die eigene Webseite eingebunden werden kann.

Stand: 11/2018

Den folgenden PHP Code in eine Datei schreiben und diese per Kommandozeile aufrufen und dabei das Ergebnis in eine Datei schreiben. Beispiel:
[user@server ~]$ cd /path/to/the/phpcodefile/
[user@server phpcodefile]$ cd /path/to/the/phpcodefile/
[user@server phpcodefile]$ php phpcodefile.php >shirteeshop.txt
Danach das Ergebnis in der Datei in die eigene Webseite per include einbinden. Beispiel:
<?php
include __DIR__ . ("/shirteeshop.txt");
?>
Danach noch das zugehörige CSS in eine Datei schreiben und im Webseite <head> einbinden. Beispiel:
<link rel="stylesheet" type="text/css" href="shirteeshopstyle.css">

PHP Code:
1.) die URL vom Shop eintragen.
2.) die Anzahl der Shopseiten eintragen.
3.) eine Bild-Datei als "shirteebrokenimage.png" in das gleiche Verzeichnis wie die PHP Code Datei speichern.
4.) eventuell: den Namen vom Pfad für die Image-Dateien anpassen.
<?php
// YOUR SHIRTEE store URL
$shirteestoreurl = "https://www.shirtee.com/de/store/shopname/";
//
// THE LIMIT FOR STORE PAGES
$shirteestorelimitpages = "4";
//
// THE FOLDER-NAME FOR IMAGE SAVING ON YOUR WEBHOST
$shirteestoreimagesdir = "shirteeimages"; // relative path
//
// Extract the Store Name for the URL Query String
$shirteestoreurlexplode = explode("/", $shirteestoreurl);
$shirteestorename = $shirteestoreurlexplode[5];
//
$shirtee_mkdir = __DIR__ . "/" . $shirteestoreimagesdir;
if (file_exists($shirtee_mkdir)) {
$shirteestoreimagesscandir = scandir($shirtee_mkdir);
foreach (array_slice($shirteestoreimagesscandir, 2) as $unlinkshirteeimages) {
unlink($shirtee_mkdir . "/" . $unlinkshirteeimages);
}
}
//
if (!file_exists($shirteestoreimagesdir)) {
mkdir($shirteestoreimagesdir, 0755);
}
//
// The PAGES for while
$shirteestorenewarray = [];
for ($p = 1; $p <= $shirteestorelimitpages; $p++) {
//
$shirteestoreurllimitpages = $shirteestoreurl . "?p=" . $p;
//
$shirteestore = file_get_contents($shirteestoreurllimitpages);
//
if (((bool) $shirteestore === true)) {
$shirteestoreexplodeone = explode('<ul class="products-grid-campaigns products-grid products-grid--max-4-col">', $shirteestore);
$shirteestoreexplode = explode('</div></div></div></div></li></ul>', $shirteestoreexplodeone[1]);
$shirteestoreold = $shirteestoreexplode[0] . '</div></div></div></div></li>';
//
// match all img src="" in the original sourcecode
preg_match_all("/(src=(.*?) )/", $shirteestoreold, $shirteestoreimgsrcmatches, PREG_PATTERN_ORDER);
//
//
// the IMAGE for while
$shirteestoreimagesrcurlarray = [];
$shirteestorenewimagessourcepatharray = [];
for ($i = 0; $i < count($shirteestoreimgsrcmatches[2]); $i++ ) {
//
array_push($shirteestoreimagesrcurlarray, $shirteestoreimgsrcmatches[2][$i]);
//
$shirteestoreimagesrcurlpreview = urldecode(str_replace('"', '', $shirteestoreimgsrcmatches[2][$i]));
//
if (strpos($shirteestoreimgsrcmatches[2][$i], "shirtee.com/preview")) {
//
$file_get_contents_opts = array(
'http' => array(
'follow_location' => false,
'timeout' => 60,
)
);
$file_get_contents_context = stream_context_create($file_get_contents_opts);
//
if (false !== ($file_get_contents_content = @file_get_contents($shirteestoreimagesrcurlpreview, false, $file_get_contents_context))) {
//$shirteestoreimgurlpreviewcontent = $file_get_contents_content;
preg_match_all("/(content=\"0;url=(.*?)\")/", $file_get_contents_content, $shirteestoreimgsrcpreviewmatches, PREG_PATTERN_ORDER);
$shirteestoreimgsrcmatchesnew[2][$i] = $shirteestoreimgsrcpreviewmatches[2][0];
} elseif ((bool)$file_get_contents_content === false) {
// BROKEN image elseif
// extract img filename from preview-url
$shirteestoreimagesrcurlpreviewpur = urldecode(str_replace('"', '', str_replace('&s=i320', '', $shirteestoreimgsrcmatches[2][$i])));
$shirteestoreimagesrcurlpreviewpurexplode = explode("/", $shirteestoreimagesrcurlpreviewpur);
$shirteestoreimagespreviewfilenameend = end($shirteestoreimagesrcurlpreviewpurexplode);
//
// BROKEN img copy and rename to /shirteeimages
copy(__DIR__ . "/shirteebrokenimage.png", __DIR__ . "/" . $shirteestoreimagesdir . "/" . $shirteestoreimagespreviewfilenameend);
//
$shirteestoreimgsrcmatchesnew[2][$i] = $shirteestoreimagesrcurlpreviewpur;
}
}
else {
$shirteestoreimgsrcmatchesnew[2][$i] = $shirteestoreimgsrcmatches[2][$i];
}
//
// extract the img file name
$shirteestoreimagesrcurlexplode = explode("/", $shirteestoreimgsrcmatchesnew[2][$i]);
$shirteestoreimagesfilenameend = end($shirteestoreimagesrcurlexplode);
//
$shirteestoreimagesdirfilename = $shirteestoreimagesdir . "/" . $shirteestoreimagesfilenameend;
//
// create the img file
if (file_exists($shirteestoreimagesdirfilename) === false) {
if (!strpos($shirteestoreimgsrcmatchesnew[2][$i], "shirtee.com/preview")) {
$shirteestoreimagecreatefrompng = imagecreatefrompng($shirteestoreimgsrcmatchesnew[2][$i]);
imagealphablending($shirteestoreimagecreatefrompng, false);
imagesavealpha($shirteestoreimagecreatefrompng, true);
imagepng($shirteestoreimagecreatefrompng, $shirteestoreimagesdirfilename, 9, PNG_ALL_FILTERS);
}
}
//
// YOUR ABSOLUTE OR RELATIVE PATH TO THE SAVED IMAGES (for the source code <img src="...">)
$shirteestorenewimagessourcepath = '"' . "/" . $shirteestoreimagesdirfilename . '"';
array_push($shirteestorenewimagessourcepatharray, $shirteestorenewimagessourcepath);
//
}
$shirteestoreold = str_replace($shirteestoreimagesrcurlarray, $shirteestorenewimagessourcepatharray, $shirteestoreold);
//
// Extract the Shirtee Store Campaign URLs
preg_match_all("/(href=\"(.*?)\")/", $shirteestoreold, $shirteestorecampaignhrefmatches, PREG_PATTERN_ORDER);
//
// Put the URL Querystring at the campaign URLs START
$shirteestorecampaignhrefarray = [];
$shirteestorecampaignhrefnewarray = [];
$shirteestorecampaignhrefmatchesunique = array_unique($shirteestorecampaignhrefmatches[2]);
$shirteestorecampaignhrefmatchesuniquenew = array_values($shirteestorecampaignhrefmatchesunique);
//
for ($i = 0; $i < count($shirteestorecampaignhrefmatchesuniquenew); $i++ ) {
//
$shirteestorecampaignhref = $shirteestorecampaignhrefmatchesuniquenew[$i];
array_push($shirteestorecampaignhrefarray, $shirteestorecampaignhref);
//
if (strpos($shirteestorecampaignhref, "?")) {
$shirteestorecampaignhrefnew = $shirteestorecampaignhref . '&amp;shop=' . $shirteestorename;
} else {
$shirteestorecampaignhrefnew = $shirteestorecampaignhref . '?shop=' . $shirteestorename;
}
//
array_push($shirteestorecampaignhrefnewarray, $shirteestorecampaignhrefnew);
//
}
$shirteestoreold = str_replace($shirteestorecampaignhrefarray, $shirteestorecampaignhrefnewarray, $shirteestoreold);
//
//
$shirteestorenewline = preg_replace("/>\s</", ">\n<", $shirteestoreold);
$shirteestorelidiv = preg_replace("/<\/li><li/", "</div>\n\n<div", $shirteestorenewline);
$shirteestorelidiv = str_replace("<li", "\n\n<div", $shirteestorelidiv);
$shirteestorelidiv = str_replace("li>", "div>\n\n", $shirteestorelidiv);
$shirteestorenewarray[$p] = str_replace('href="', 'target="_blank" href="', $shirteestorelidiv);
//
}
//
}
//
echo '<div class="products-grid-campaigns products-grid products-grid--max-4-col">';
echo implode("", $shirteestorenewarray);
echo '</div>';
//
?>

Shirteeshop CSS:
/* Shirteeshop CSS BEGIN */
.shirteeshopdiv {
max-width: 970px;
margin: 0 auto;
text-align: center;
padding-bottom: 20px;
}
.shirteeshopheader {
font-size: 3em;
font-weight: bold;
margin-top: 20px;
margin-bottom: 20px;
}
.shirteeshopdescription {
font-size: 1.4em;
margin-bottom: 20px;
}
/* Shirteeshop Original CSS BEGIN */
.shirteeshopdiv .products-grid {
max-width: 970px;
margin: 0 auto;
padding: 0;
text-align: center;
}
.shirteeshopdiv .products-grid > li {
text-align: center;
}
.shirteeshopdiv .products-grid .item {
width: 23%;
margin: 0.5%;
display: inline-block;
}
.shirteeshopdiv .products-grid-campaigns .item {
margin-bottom: 12px;
background: #fff;
border-radius: 1px;
border: 1px solid #ccc;
-webkit-transition: transform .2s linear 0s;
-moz-transition: transform .2s linear 0s;
-o-transition: transform .2s linear 0s;
transition: transform .2s linear 0s;
z-index: 1;
vertical-align: top;
}
.shirteeshopdiv .products-grid-campaigns .product-image .product-image-zoom {
-webkit-transition: all .2s linear 0s;
-moz-transition: all .2s linear 0s;
-o-transition: all .2s linear 0s;
transition: all .2s linear 0s;
}
.shirteeshopdiv .products-grid .product-image img {
width: 100%;
height: auto;
}
.shirteeshopdiv .products-grid .product-image {
position: relative;
padding: 0;
margin: 10px;
display: block;
overflow: hidden;
width: calc(100% - 20px);
}
.shirteeshopdiv .products-grid .product-info {
position: relative;
padding-bottom: 95px;
}
.shirteeshopdiv .products-grid .product-info {
padding: 10px 18px 10px;
padding: 10px 18px 10px;
padding-bottom: 10px;
background: #f0f0f0;
border-top: 1px solid #b5b5b5;
}
.shirteeshopdiv .products-grid .product-name, .products-list .product-name {
text-transform: uppercase;
margin-bottom: 5px;
font-size: 14px;
font-family: "Raleway","Helvetica Neue",Verdana,Arial,sans-serif;
}
.shirteeshopdiv .products-grid .product-name {
font-weight: normal;
color: #000;
margin: 0 0 7px;
line-height: 1.4em;
}
.shirteeshopdiv .products-grid .product-name a {
display: block;
font-family: 'Open Sans',sans-serif;
text-transform: initial;
text-overflow: ellipsis;
text-decoration: none;
font-weight: 600;
color: #333c4e;
}
.shirteeshopdiv .products-grid .price-box-text {
display: none;
}
.shirteeshopdiv .products-grid .price-box {
margin: 7px 0;
font-family: "Helvetica Neue",Verdana,Arial,sans-serif;
}
.shirteeshopdiv .products-grid .price-box .price {
font-weight: 700;
font-family: 'Open Sans',sans-serif;
font-size: 16px;
color: #333c4e;
line-height: 22px;
}
.shirteeshopdiv .products-grid .item:hover {
-webkit-box-shadow: 0 2px 30px 0 rgba(0,0,0,.2);
box-shadow: 0 2px 30px 0 rgba(0,0,0,.2);
}
.shirteeshopdiv .products-grid .item:hover .product-image-zoom {
-webkit-transform: scale(1.4);
-moz-transform: scale(1.4);
-ms-transform: scale(1.4);
-o-transform: scale(1.4);
transform: scale(1.4);
}
.shirteeshopdiv .products-grid .item:hover .product-name {
height: auto;
white-space: normal;
}
.shirteeshopdiv .products-grid h2.product-name a:hover, h3.product-name a:hover, h4.product-name a:hover, h5.product-name a:hover, p.product-name a:hover {
color: #39c;
text-decoration: none;
}
/* Shirteeshop Original CSS END */

Keine Garantie. Keine Gewährleistung. Kein Support.
Verwendung auf eigenes Risiko.