Example #1
0
function ostatnie()
{
    //połączenie z bazą
    $servername = "localhost";
    $username = "******";
    $password = "******";
    $dbname = "xxxxxx";
    // Otworzenie połączenia z bazą
    $conn = new mysqli($servername, $username, $password, $dbname);
    // sprawdzenie połączenia
    if ($conn->connect_error) {
        die("Błąd połączenia z bazą danych: " . $conn->connect_error);
    }
    //połączenie z allegro
    $client = new SoapClient('https://webapi.allegro.pl/service.php?wsdl', array('trace' => true));
    $id = xxxxxxxxx;
    settype($numer, 'string');
    //filtry
    $options = array('filterId' => 'userId', 'filterValueId' => array($id));
    $options2 = array('filterId' => 'department', 'filterValueId' => array('electronics'));
    $options3 = array('filterId' => 'departmentPage', 'filterValueId' => array(0));
    $options4 = array('filterId' => 'category', 'filterValueId' => array('2'));
    $filters = array($options, $options3, $options2, $options4);
    $request = array('webapiKey' => 'xxxxxxxxxx', 'countryId' => '1', 'filterOptions' => $filters, 'resultScope' => '3');
    try {
        $array = $client->doGetItemsList($request);
    } catch (SoapFault $e) {
        echo $e->faultcode . '<br />';
        echo $e->faultstring;
    }
    //generowanie kodu aukcji
    //ustawienie ilosci okienek z aukcjami
    for ($i = 0; $i < 10; $i++) {
        //dane z allegro
        $text = $array->itemsList->item[$i]->itemTitle;
        //tytuł aukcji
        $id_aukcji = $array->itemsList->item[$i]->itemId;
        //pobranie numeru aukcji
        $url = $array->itemsList->item[$i]->photosInfo->item[1]->photoUrl;
        //link do obrazka z miniaturką UWAGA nie zawsze pierwszy obrazek jest najweikszej rozdzielczosci
        //zmienne
        $font = 'DroidSans.ttf';
        //czasmi trzeba ustawić cieżk bezwzgldna dla pliku
        $fontSize = 10;
        $lineHeight = 17;
        $polozenieNapisuOdGory = 100;
        $width = 128;
        //szerokość obrazka
        $height = 250;
        //wysokość obrazka
        $padding = 15;
        //padding tekstu jednostronny
        $kupTerazImg = 'teraz.jpg';
        //czasmi trzeba ustawić cieżk bezwzgldna dla pliku
        $fontSizeCena = 15;
        $cena = $array->itemsList->item[$i]->priceInfo->item[0]->priceValue . ' zł';
        $kupTeraz = 1;
        $kupTerazObraz = imageCreateFromjpeg($kupTerazImg);
        $polozenieCenyOdGory = 210;
        $polozenieCenyOdLewej = 40;
        $miniaturka = imageCreateFromjpeg($url);
        //miniaturka aukcji
        $filename = '/images/' . $i . '.jpg';
        //sciezka do pliku czasmi trzeba ustawić cieżk bezwzgldna
        //KONIEC ZMIENNYCH
        $obrazek_aukcji = imagecreatetruecolor($width, $height);
        //główny obrazek
        $white = imagecolorallocate($obrazek_aukcji, 255, 255, 255);
        $black = imagecolorallocate($obrazek_aukcji, 0, 0, 0);
        imagefill($obrazek_aukcji, 0, 0, $white);
        //wypełnienie obrazka białym tłem
        //wklejenie do głownego obrazka miniaturki aukcji (128 dotyczy standardowej miniaturki allegro)
        imagecopyresized($obrazek_aukcji, $miniaturka, 0, 0, 0, 0, 128, 96, 128, 96);
        $words = explode(' ', $text);
        $lines = array($words[0]);
        $currentLine = 0;
        // DODANIE TEKSTU AUKCJI DO OBRAZKA
        for ($x = 1; $x < count($words); $x++) {
            $titleLinesize = imagettfbbox($fontSize, 0, $font, $lines[$currentLine] . ' ' . $words[$x]);
            if ($titleLinesize[2] - $titleLinesize[0] <= $width - $padding * 2) {
                $lines[$currentLine] .= ' ' . $words[$x];
            } else {
                $currentLine++;
                $lines[$currentLine] = $words[$x];
            }
        }
        $whichLine = 1;
        foreach ($lines as $line) {
            $lineBoundBox = imagettfbbox($fontSize, 0, $font, "{$line}");
            $lineWidth = $lineBoundBox[0] + $lineBoundBox[2];
            $line_margin = round(($width - $lineWidth - $padding * 2) / 2);
            $linePositionY = $lineHeight * $whichLine;
            imagettftext($obrazek_aukcji, $fontSize, 0, $line_margin + $padding, $linePositionY + $polozenieNapisuOdGory, $black, $font, $line);
            $whichLine++;
        }
        //dodanie ceny
        imagettftext($obrazek_aukcji, $fontSizeCena, 0, $polozenieCenyOdLewej, $polozenieCenyOdGory, $black, $font, $cena);
        //dodanie obrazka jeśli kup teraz
        imagecopyresized($obrazek_aukcji, $kupTerazObraz, 0, 220, 0, 0, 128, 28, 128, 28);
        //finalne zapisanie obrazka na serwerze
        imagejpeg($obrazek_aukcji, $filename, 100);
        //przekazanie danych do bazy
        $sql = "UPDATE aukcje_allegro SET id_aukcji=" . $id_aukcji . " WHERE id_obrazka=" . $i;
        if ($conn->query($sql) === TRUE) {
        } else {
            echo "Error: " . $conn->error;
        }
    }
    //end of FOR
}