default_videos_content.php
7.12 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/**
* @package JMAP::SITEMAP::components::com_jmap
* @subpackage views
* @subpackage sitemap
* @subpackage tmpl
* @author Joomla! Extensions Store
* @copyright (C) 2015 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$showPageBreaks = $this->cparams->get ( 'show_pagebreaks', 1 );
// Get default menu - home and check if a single article is linked, if so skip to avoid duplicated content
$homeArticleID = false;
$defaultMenu = $this->application->getMenu()->getDefault(JFactory::getLanguage()->getTag());
if( isset($defaultMenu->query['option']) &&
isset($defaultMenu->query['view']) &&
$defaultMenu->query['option'] == 'com_content' &&
$defaultMenu->query['view'] == 'article') {
$homeArticleID = (int)$defaultMenu->query['id'];
}
// Init exclusion
$videoFilterInclude = array();
if(trim($this->sourceparams->get ( 'videos_filter_include', '' ))) {
$this->videoFilterInclude = explode(',', $this->sourceparams->get ( 'videos_filter_include', '' ));
}
$videoFilterExclude = array();
if(trim($this->sourceparams->get ( 'videos_filter_exclude', '' ))) {
$this->videoFilterExclude = explode(',', $this->sourceparams->get ( 'videos_filter_exclude', '' ));
}
// Init and merge global inclusions filters data sources wide
if($globalVideosFilterInclude = trim($this->cparams->get ( 'videos_global_filter_include', '' ))) {
$videoGlobalFilterInclude = explode(',', $globalVideosFilterInclude);
$this->videoFilterInclude = array_merge($videoFilterInclude, $videoGlobalFilterInclude);
}
// Init and merge global exclusions filters data sources wide
if($globalVideosFilterExclude = trim($this->cparams->get ( 'videos_global_filter_exclude', '' ))) {
$videoGlobalFilterExclude = explode(',', $globalVideosFilterExclude);
$this->videoFilterExclude = array_merge($videoFilterExclude, $videoGlobalFilterExclude);
}
if (count ( $this->source->data ) != 0) {
require_once (JPATH_BASE . '/components/com_content/helpers/route.php');
foreach ( $this->source->data as $elm ) {
// Element category empty da right join
if(!$elm->id) {
continue;
}
// Article found as linked to home, skip and avoid duplicate link
if((int)$elm->id === $homeArticleID) {
continue;
}
// Check to ensure is counting valid request
if(!$this->HTTPClient->isValidRequest()) {
break;
}
$elm->slug = $elm->alias ? ($elm->id . ':' . $elm->alias) : $elm->id;
$seflink = JRoute::_ ( ContentHelperRoute::getArticleRoute ( $elm->slug, $elm->catslug, $elm->language ) );
// Skip outputting
if(array_key_exists($seflink, $this->outputtedLinksBuffer)) {
continue;
}
// Else store to prevent duplication
$this->outputtedLinksBuffer[$seflink] = true;
// HTTP Request to remote URL to get videos
$headers = array('Accept'=>'text/html', 'User-Agent'=>'JSitemapbot/1.0');
$HTTPResponse = $this->HTTPClient->get($this->liveSiteCrawler . $seflink, $headers);
$pageHtml = $HTTPResponse->body;
$this->htmlResponseReference = &$pageHtml;
// Videos RegExp extraction
$videosArrayResultsTotal = array();
$videosArrayResultsYoutube = array();
$videosArrayResultsVimeo = array();
$videosArrayResultsDailymotion = array();
preg_match_all ("/(youtube).*.com\/(v\/|watch\?v=|embed\/)([a-zA-Z0-9\-_]*)/", $pageHtml, $videosArrayResultsYoutube, PREG_SET_ORDER);
preg_match_all ("/player.(vimeo).com\/video\/([a-z0-9\-]*)/", $pageHtml, $videosArrayResultsVimeo, PREG_SET_ORDER);
preg_match_all ("/www.(dailymotion).com\/embed\/video\/([a-z0-9\-]*)/", $pageHtml, $videosArrayResultsDailymotion, PREG_SET_ORDER);
$videosArrayResultsTotal = array_merge($videosArrayResultsYoutube, $videosArrayResultsVimeo, $videosArrayResultsDailymotion);
$bufferVideos = null;
ob_start();
foreach ($videosArrayResultsTotal as $index=>$videoElement):
$this->videoID = array_pop($videoElement);
// Prevent duplicated videos, calculate video hash
$videoHash = $videoElement[1] . $this->videoID;
// Skip outputting
if(array_key_exists($videoHash, $this->outputtedVideosBuffer)) {
continue;
}
// Else store to prevent videos duplication
$this->outputtedVideosBuffer[$videoHash] = true;
$videoApiEndpoint = sprintf($this->videoApisEndpoints[$videoElement[1]], $this->videoID);
$HTTPResponse = $this->HTTPClient->get($videoApiEndpoint, array('Accept'=>'application/json'));
if(!$HTTPResponse->code == 200){continue;}
$this->apiJsonResponse = json_decode($HTTPResponse->body);
echo $this->loadTemplate('videos_' . $videoElement[1]);
endforeach;
// Always load html5 video parser at once
echo $this->loadTemplate('videos_html5');
$bufferVideos = ob_get_clean();
// If valid videos have been found and crawled let's build the video sitemap
if(isset($bufferVideos) && !empty($bufferVideos)):
?>
<url>
<loc><?php echo $this->liveSite . $seflink; ?></loc>
<?php echo $bufferVideos; ?>
</url>
<?php
endif;
// Expandible content crawling feature
if(!empty($elm->expandible) && $showPageBreaks) {
foreach ($elm->expandible as $index=>$subPageBreak) {
$seflink = JRoute::_ ( ContentHelperRoute::getArticleRoute ( $elm->slug, $elm->catslug, $elm->language ) . '&limitstart=' . ($index + 1));
// HTTP Request to remote URL to get videos
$HTTPResponse = $this->HTTPClient->get($this->liveSiteCrawler . $seflink, $headers);
$pageHtml = $HTTPResponse->body;
$this->htmlResponseReference = &$pageHtml;
// Videos RegExp extraction
$videosArrayResultsTotal = array();
$videosArrayResultsYoutube = array();
$videosArrayResultsVimeo = array();
$videosArrayResultsDailymotion = array();
preg_match_all ("/(youtube).*.com\/(v\/|watch\?v=|embed\/)([a-zA-Z0-9\-_]*)/", $pageHtml, $videosArrayResultsYoutube, PREG_SET_ORDER);
preg_match_all ("/player.(vimeo).com\/video\/([a-z0-9\-]*)/", $pageHtml, $videosArrayResultsVimeo, PREG_SET_ORDER);
preg_match_all ("/www.(dailymotion).com\/embed\/video\/([a-z0-9\-]*)/", $pageHtml, $videosArrayResultsDailymotion, PREG_SET_ORDER);
$videosArrayResultsTotal = array_merge($videosArrayResultsYoutube, $videosArrayResultsVimeo, $videosArrayResultsDailymotion);
$bufferVideos = null;
ob_start();
foreach ($videosArrayResultsTotal as $index=>$videoElement):
$this->videoID = array_pop($videoElement);
// Prevent duplicated videos, calculate video hash
$videoHash = $videoElement[1] . $this->videoID;
// Skip outputting
if(array_key_exists($videoHash, $this->outputtedVideosBuffer)) {
continue;
}
// Else store to prevent videos duplication
$this->outputtedVideosBuffer[$videoHash] = true;
$videoApiEndpoint = sprintf($this->videoApisEndpoints[$videoElement[1]], $this->videoID);
$HTTPResponse = $this->HTTPClient->get($videoApiEndpoint, array('Accept'=>'application/json'));
if(!$HTTPResponse->code == 200){continue;}
$this->apiJsonResponse = json_decode($HTTPResponse->body);
echo $this->loadTemplate('videos_' . $videoElement[1]);
endforeach;
// Always load html5 video parser at once
echo $this->loadTemplate('videos_html5');
$bufferVideos = ob_get_clean();
// If valid videos have been found and crawled let's build the video sitemap
if(isset($bufferVideos) && !empty($bufferVideos)):
?>
<url>
<loc><?php echo $this->liveSite . $seflink; ?></loc>
<?php echo $bufferVideos; ?>
</url>
<?php
endif;
}
}
}
}