1 | <?php
|
---|
2 | /**
|
---|
3 | * Copyright 2006, 2007, 2008, 2009 Eric D. Hough (http://ehough.com)
|
---|
4 | *
|
---|
5 | * This file is part of TubePress (http://tubepress.org)
|
---|
6 | *
|
---|
7 | * TubePress is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * TubePress is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with TubePress. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | function_exists('tubepress_load_classes')
|
---|
23 | || require(dirname(__FILE__) . '/../../../tubepress_classloader.php');
|
---|
24 | tubepress_load_classes(array('org_tubepress_url_UrlBuilder',
|
---|
25 | 'org_tubepress_options_category_Gallery',
|
---|
26 | 'org_tubepress_gallery_Gallery',
|
---|
27 | 'org_tubepress_options_manager_OptionsManager',
|
---|
28 | 'org_tubepress_options_category_Advanced',
|
---|
29 | 'org_tubepress_options_category_Display',
|
---|
30 | 'org_tubepress_options_category_Embedded',
|
---|
31 | 'org_tubepress_options_category_Meta',
|
---|
32 | 'net_php_pear_Net_URL2',
|
---|
33 | 'org_tubepress_options_category_Feed'));
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Builds URLs to send out to YouTube for gdata
|
---|
37 | *
|
---|
38 | */
|
---|
39 | class org_tubepress_url_SimpleUrlBuilder implements org_tubepress_url_UrlBuilder
|
---|
40 | {
|
---|
41 | private $_tpom;
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Builds a gdata request url for a list of videos
|
---|
45 | *
|
---|
46 | * @return string The gdata request URL for this gallery
|
---|
47 | */
|
---|
48 | public function buildGalleryUrl($currentPage)
|
---|
49 | {
|
---|
50 | $url = "";
|
---|
51 |
|
---|
52 | switch ($this->_tpom->get(org_tubepress_options_category_Gallery::MODE)) {
|
---|
53 |
|
---|
54 | case org_tubepress_gallery_Gallery::USER:
|
---|
55 | $url = "users/" . $this->_tpom->get(org_tubepress_options_category_Gallery::USER_VALUE) .
|
---|
56 | "/uploads";
|
---|
57 | break;
|
---|
58 |
|
---|
59 | case org_tubepress_gallery_Gallery::TOP_RATED:
|
---|
60 | $url = "standardfeeds/top_rated?time=" .
|
---|
61 | $this->_tpom->get(org_tubepress_options_category_Gallery::TOP_RATED_VALUE);
|
---|
62 | break;
|
---|
63 |
|
---|
64 | case org_tubepress_gallery_Gallery::POPULAR:
|
---|
65 | $url = "standardfeeds/most_viewed?time=" .
|
---|
66 | $this->_tpom->get(org_tubepress_options_category_Gallery::MOST_VIEWED_VALUE);
|
---|
67 | break;
|
---|
68 |
|
---|
69 | case org_tubepress_gallery_Gallery::PLAYLIST:
|
---|
70 | $url = "playlists/" .
|
---|
71 | $this->_tpom->get(org_tubepress_options_category_Gallery::PLAYLIST_VALUE);
|
---|
72 | break;
|
---|
73 |
|
---|
74 | case org_tubepress_gallery_Gallery::MOST_RESPONDED:
|
---|
75 | $url = "standardfeeds/most_responded";
|
---|
76 | break;
|
---|
77 |
|
---|
78 | case org_tubepress_gallery_Gallery::MOST_RECENT:
|
---|
79 | $url = "standardfeeds/most_recent";
|
---|
80 | break;
|
---|
81 |
|
---|
82 | case org_tubepress_gallery_Gallery::MOST_LINKED:
|
---|
83 | $url = "standardfeeds/most_linked";
|
---|
84 | break;
|
---|
85 |
|
---|
86 | case org_tubepress_gallery_Gallery::MOST_DISCUSSESD:
|
---|
87 | $url = "standardfeeds/most_discussed";
|
---|
88 | break;
|
---|
89 |
|
---|
90 | case org_tubepress_gallery_Gallery::MOBILE:
|
---|
91 | $url = "standardfeeds/watch_on_mobile";
|
---|
92 | break;
|
---|
93 |
|
---|
94 | case org_tubepress_gallery_Gallery::FAVORITES:
|
---|
95 | $url = "users/" . $this->_tpom->get(org_tubepress_options_category_Gallery::FAVORITES_VALUE) .
|
---|
96 | "/favorites";
|
---|
97 | break;
|
---|
98 |
|
---|
99 | case org_tubepress_gallery_Gallery::TAG:
|
---|
100 | $tags = $this->_tpom->get(org_tubepress_options_category_Gallery::TAG_VALUE);
|
---|
101 | $tags = explode(" ", $tags);
|
---|
102 | $url = "videos?q=" . implode("+", $tags);
|
---|
103 | break;
|
---|
104 |
|
---|
105 | default:
|
---|
106 | $url = "standardfeeds/recently_featured";
|
---|
107 | break;
|
---|
108 | }
|
---|
109 |
|
---|
110 | $request = "http://gdata.youtube.com/feeds/api/$url";
|
---|
111 | $this->_urlPostProcessing($request, $currentPage);
|
---|
112 | return $request;
|
---|
113 | //return str_replace("&", "&", $request);
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Appends some global query parameters on the request
|
---|
118 | * before we fire it off to YouTube
|
---|
119 | *
|
---|
120 | * @param string &$request The request to be manipulated
|
---|
121 | *
|
---|
122 | * @return void
|
---|
123 | */
|
---|
124 | private function _urlPostProcessing(&$request, $currentPage)
|
---|
125 | {
|
---|
126 |
|
---|
127 | $perPage = $this->_tpom->get(org_tubepress_options_category_Display::RESULTS_PER_PAGE);
|
---|
128 | $filter = $this->_tpom->get(org_tubepress_options_category_Feed::FILTER);
|
---|
129 | $order = $this->_tpom->get(org_tubepress_options_category_Display::ORDER_BY);
|
---|
130 | $mode = $this->_tpom->get(org_tubepress_options_category_Gallery::MODE);
|
---|
131 | $embedOnly = $this->_tpom->get(org_tubepress_options_category_Feed::EMBEDDABLE_ONLY);
|
---|
132 |
|
---|
133 | /* start index of the videos */
|
---|
134 | $start = ($currentPage * $perPage) - $perPage + 1;
|
---|
135 |
|
---|
136 | $requestURL = new net_php_pear_Net_URL2($request);
|
---|
137 | $requestURL->setQueryVariable("v", 2);
|
---|
138 | $requestURL->setQueryVariable("start-index", $start);
|
---|
139 | $requestURL->setQueryVariable("max-results", $perPage);
|
---|
140 |
|
---|
141 | $requestURL->setQueryVariable("safeSearch", $filter);
|
---|
142 |
|
---|
143 | if ($order != "random") {
|
---|
144 | $requestURL->setQueryVariable("orderby", $order);
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* YouTube API client ID and developer keys */
|
---|
148 | $requestURL->setQueryVariable("client", $this->_tpom->get(org_tubepress_options_category_Feed::CLIENT_KEY));
|
---|
149 | $requestURL->setQueryVariable("key", $this->_tpom->get(org_tubepress_options_category_Feed::DEV_KEY));
|
---|
150 |
|
---|
151 | if ($embedOnly) {
|
---|
152 | $requestURL->setQueryVariable("format", "5");
|
---|
153 | }
|
---|
154 |
|
---|
155 | $request = $requestURL->getURL();
|
---|
156 | }
|
---|
157 |
|
---|
158 | public function buildSingleVideoUrl($id)
|
---|
159 | {
|
---|
160 | $requestURL = new net_php_pear_Net_URL2("http://gdata.youtube.com/feeds/api/videos");
|
---|
161 | $requestURL->setQueryVariable("q", $id);
|
---|
162 | $requestURL->setQueryVariable("max-results", 1);
|
---|
163 |
|
---|
164 | return $requestURL->getURL();
|
---|
165 | }
|
---|
166 |
|
---|
167 | public function setOptionsManager(org_tubepress_options_manager_OptionsManager $tpom)
|
---|
168 | {
|
---|
169 | $this->_tpom = $tpom;
|
---|
170 | }
|
---|
171 | }
|
---|