-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1google_video_sitemap_test.php
99 lines (81 loc) · 4.8 KB
/
1google_video_sitemap_test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
use Dialeleven\PhpGoogleSitemap;
include_once $_SERVER['DOCUMENT_ROOT'] . '/src/GoogleVideoSitemap.php';
/*
Instantiate the PHP Google Video Sitemap Class. Pass your hostname below as an
argument using PHP's $_SERVER['HTTP_HOST'] or you can hard code your hostname
such as 'https://www.yourdomain.com' for example.
*** DO NOT INCLUDE A TRAILING SLASH AT THE END OF YOUR HOSTNAME! ***
*/
$my_sitemap = new Dialeleven\PhpGoogleSitemap\GoogleVideoSitemap($sitemap_type = 'video',
$http_hostname = 'www.testdomain.com',
$xml_files_dir = $_SERVER['DOCUMENT_ROOT'] . '/public/sitemaps');
/*
Some configuration methods for your sitemap file(s) to be generated.
*/
#$my_sitemap->setXmlMode($mode = 'file'); // For development purposes. mode = memory (browser), mode = file (save to XML file)
$my_sitemap->setUseHttpsUrls(true); // use "https" mode for your URLs or plain "http"
$my_sitemap->setSitemapFilenamePrefix('myvideo_sitemap'); // set name of sitemap file minus ".xml" (e.g. mysitemap.xml)
$my_sitemap->setUseGzip($use_gzip = true); // gzip the urlset files to reduce file sizes (true/false). NOTE: using gzip will unlink() (i.e. delete) the original XML file(s) after.
// Start adding your URLs and video items
for ($i = 1; $i <= 100001; ++$i)
{
echo $i . ' - ';
/*
Add URLs from your database or array (if preferred)
1. $loc - Should not include the hostname. For example if the URL is https://www.yourdomain.com/somepath/, then
the $loc should be "somepath/" if you want the trailing slash. Trailing slash is not enforced for
flexibility as some sites may not use a trailing slash.
2. $tags_arr - Here pass an array of the video URL tags including the following:
- thumbnail_loc (required)
- title (required)
- description (required)
- content_loc (required)
- player_loc (required)
- thumbnail_loc
- title
- description
- content_loc
- player_loc
- duration
- rating
- view_count
- publication_date
- family_friendly
- requires_subscription
- live
3. $special_tags_arr - Additional optional video tags which require passing 4 values instead of the usual 2 (name => value).
Allowed tags include:
- restriction
- price
- uploader
The class will create a new 'urlset' file if you reach the 50,000 URL limit and create
the 'sitemapindex' file listing each urlset file that was generated.
*/
$my_sitemap->addUrl(
$loc = "url-$i/",
$tags_arr = array(
// required tags
'thumbnail_loc' => "https://example.com/thumbs/$i.jpg",
'title' => "Video Title #$i",
'description' => "Video description #$i",
'content_loc' => "http://streamserver.example.com/video$1.mp4",
'player_loc' => "https://example.com/videoplayer.php?video=$i"
// optional tags
/*
'duration', 'rating', 'view_count', 'publication_date', 'family_friendly',
'requires_subscription', 'live'
*/
),
// optional tags - each must be an array with four values to pass
$special_tags_arr = array(
array('restriction', 'relationship', 'allow', 'IE GB US CA'),
array('price', 'currency', 'EUR', '1.99'),
array('uploader', 'info', "https://example.com/users/user$i", "Username$i")
)
);
}
// signal when done adding URLs, so we can generate the sitemap index file (table of contents)
$my_sitemap->endXmlDoc();
#throw new Exception('Test exception here');
#throw new InvalidArgumentException('test');