-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.php
70 lines (56 loc) · 2.43 KB
/
index.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
<?php
header('Content-Type: text/xml');
require_once 'vendor/autoload.php';
$domain = "http://localhost";
$_GET['zone'] or die("<error>zone not passed</error>");
$URL = $domain."/www/delivery/fc.php?script=bannerTypeHtml:vastInlineBannerTypeHtml:vastInlineHtml&format=vast&nz=1&zones=pre-roll%3D".intval($_GET['zone']."&".$_SERVER['QUERY_STRING']);
$xml = simplexml_load_file($URL) or die("<error>Cannot create XML object</error>");
$factory = new \Sokil\Vast\Factory();
$document = (new \Sokil\Vast\Factory())->create('2.0');
if(!$xml->Ad) {
return $document;
}
// insert Ad section
$ad1 = $document
->createInLineAdSection()
->setId($xml->Ad['id'])
->setAdSystem($xml->Ad->InLine->AdSystem)
->setAdTitle($xml->Ad->InLine->AdTitle)
->addImpression($xml->Ad->InLine->Impression->URL);
// create creative for ad section
$linearCreative = $ad1
->createLinearCreative()
->setDuration($xml->Ad->InLine->Video->Duration)
->setVideoClicksClickThrough($xml->Ad->InLine->Video->VideoClicks->ClickThrough->URL);
foreach($xml->Ad->InLine->TrackingEvents->Tracking as $TrackingEvent) {
if($TrackingEvent["event"] == "replay") {
$linearCreative->addTrackingEvent("rewind", $TrackingEvent->URL);
}
else if($TrackingEvent["event"] == "stop") {
// $linearCreative->addTrackingEvent("pause", $TrackingEvent->URL);
continue;
}
else {
$linearCreative->addTrackingEvent($TrackingEvent["event"], $TrackingEvent->URL);
}
}
// add 200x200 media file
$linearCreative
->createMediaFile()
->setProgressiveDelivery()
->setType($xml->Ad->InLine->Video->MediaFiles->MediaFile["type"])
->setHeight($xml->Ad->InLine->Video->MediaFiles->MediaFile["height"])
->setWidth($xml->Ad->InLine->Video->MediaFiles->MediaFile["width"])
->setBitrate($xml->Ad->InLine->Video->MediaFiles->MediaFile["bitrate"])
->setUrl($xml->Ad->InLine->Video->MediaFiles->MediaFile->URL);
$companionCreative = $ad1
->createCompanionCreative();
$companion = $companionCreative
->createCompanion()
->setID($xml->Ad->InLine->CompanionAds->Companion['id'])
->setHeight($xml->Ad->InLine->CompanionAds->Companion['height'])
->setWidth($xml->Ad->InLine->CompanionAds->Companion["width"])
->setCompanionClickThrough($xml->Ad->InLine->CompanionAds->Companion->CompanionClickThrough->URL)
->createHTMLResource()
->setHTMLResource($xml->Ad->InLine->CompanionAds->Companion->Code);
echo $document;