312.patch

jobin dcruz, 06/15/2011 02:18 AM

Download (1.74 MB)

View differences:

detail.php
8 8

  
9 9
require 'init.php';
10 10

  
11
$video_data = YT_GetDetail($_GET['vid']);
12
$video_comment = YT_GetComment($_GET['vid']);
13

  
14
// splitting keywords
15

  
16

  
17
$keywords_raw = explode(',', $video_data[0]['media:group'][0]['media:keywords']);
18

  
19
$i = 0;
20

  
21
foreach ($keywords_raw as $k => $v)
22
{
23
    $keywords[$i]['keyword'] = trim($v);
24
    $i ++;
25
}
26

  
27
//parse xml attributes
28

  
29

  
30
preg_match_all('/<[^>]+>/s', $video_data[1], $tags);
31

  
32
$duration = 0;
33
$view_count = 0;
34
$rating_num_raters = 0;
35
$rating_average = 0;
36

  
37
foreach ($tags[0] as $k => $v)
38
{
39
    
40
    $v = str_replace('"', "\'", $v);
41
    
42
    if (substr($v, 0, 12) == '<yt:duration')
43
    {
44
        preg_match("/seconds='(.*)'/i", $v, $matches);
45
        $duration = $matches[1];
46
    }
47
    
48
    if (substr($v, 0, 14) == '<yt:statistics')
49
    {
50
        preg_match("/viewCount='(.*)'/i", $v, $matches);
51
        $view_count = $matches[1];
52
    }
53
    
54
    if (substr($v, 0, 10) == '<gd:rating')
55
    {
56
        preg_match("/numRaters='(.*?)'/i", $v, $matches);
57
        $rating_num_raters = $matches[1];
58
        
59
        preg_match("/average='(.*?)'/i", $v, $matches);
60
        $rating_average = $matches[1];
61
    }
62
}
11
$video = new video();
12
$yt_video = $video->getVideoById($_GET['vid']);
63 13

  
64 14
// assign template variables
65 15

  
66

  
67 16
$tpl->assign('id', $_GET['vid']);
68
$tpl->assign('published', $video_data[0]['published']);
69
$tpl->assign('updated', $video_data[0]['updated']);
70
$tpl->assign('title', $video_data[0]['title']);
71
$tpl->assign('author', $video_data[0]['author'][0]['name']);
72
$tpl->assign('description', $video_data[0]['media:group'][0]['media:description']);
73
$tpl->assign('category', $video_data[0]['media:group'][0]['media:category']);
74
$tpl->assign('keywords', $keywords);
75
$tpl->assign('duration', $duration);
76
$tpl->assign('view_count', $view_count);
77
$tpl->assign('rating_num_raters', $rating_num_raters);
78
$tpl->assign('rating_average', $rating_average);
79
$tpl->assign('comments', @array_reverse($video_comment[0]['entry']));
80
$tpl->assign('total_comments', $video_comment[0]['opensearch:totalresults']);
17
$tpl->assign('published', $yt_video['published']);
18
$tpl->assign('updated', $yt_video['updated']);
19
$tpl->assign('title', $yt_video['title']);
20
$tpl->assign('author', $yt_video['author']);
21
$tpl->assign('description', $yt_video['description']);
22
$tpl->assign('category', $yt_video['category']);
23
$tpl->assign('keywords', $yt_video['keywords']);
24
$tpl->assign('duration', $yt_video['duration']);
25
$tpl->assign('view_count', $yt_video['view_count']);
26
$tpl->assign('rating_num_raters', $yt_video['rating']['average']);
27
$tpl->assign('rating_average', $yt_video['rating']['numRaters']);
28
$tpl->assign('comments', @array_reverse($yt_video['comments']));
29
$tpl->assign('total_comments', $yt_video['total_comments']);
81 30
$tpl->display('detail.html');
index.php
8 8

  
9 9
include "init.php";
10 10

  
11
$_GET['p'] = 1;
12
$_GET['q'] = $frontpage_keyword;
13

  
14
$video_list = YT_ListByTag($_GET['q'], $_GET['p']);
15

  
16
preg_match_all('/<[^>]+>/s', $video_list[1], $tags);
17

  
18
$i = 0;
19
foreach ($tags[0] as $k => $v)
20
{
21
    
22
    $v = str_replace('"', "\'", $v);
23
    
24
    if (substr($v, 0, 12) == '<yt:duration')
25
    {
26
        preg_match("/seconds='(.*)'/i", $v, $matches);
27
        $video_list[0]['entry'][$i]['duration'] = $matches[1];
28
    }
29
    
30
    if (substr($v, 0, 14) == '<yt:statistics')
31
    {
32
        preg_match("/viewCount='(.*)'/i", $v, $matches);
33
        $video_list[0]['entry'][$i]['view_count'] = $matches[1];
34
    }
35
    
36
    if (substr($v, 0, 10) == '<gd:rating')
37
    {
38
        preg_match("/numRaters='(.*?)'/i", $v, $matches);
39
        $video_list[0]['entry'][$i]['rating_num_raters'] = $matches[1];
40
        
41
        preg_match("/average='(.*?)'/i", $v, $matches);
42
        $video_list[0]['entry'][$i]['rating_average'] = $matches[1];
43
    }
44
    
45
    if (substr($v, 0, 7) == '</entry')
46
    {
47
        $i ++;
48
    }
49
}
50

  
51
// ################# Start construct video data ###############################
52

  
53

  
54
$bad_words = getBadWords();
55

  
56
foreach ($video_list[0]['entry'] as $k => $v)
57
{
58
    if (! preg_match("/$bad_words/i", $v['content']) || empty($bad_words))
59
    {
60
        $id_raw = explode('/', $video_list[0]['entry'][$k]['id']);
61
        
62
        $video_list[0]['entry'][$k]['id'] = array_pop($id_raw);
63
        $video_list[0]['entry'][$k]['author'] = $video_list[0]['entry'][$k]['author'][0]['name'];
64
        $video_list[0]['entry'][$k]['description'] = $video_list[0]['entry'][$k]['media:group'][0]['media:description'];
65
        $video_list[0]['entry'][$k]['category'] = $video_list[0]['entry'][$k]['media:group'][0]['media:category'];
66
        $video_list[0]['entry'][$k]['thumbnail'][0] = "http://img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/0.jpg";
67
        $video_list[0]['entry'][$k]['thumbnail'][1] = "http://img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/1.jpg";
68
        $video_list[0]['entry'][$k]['thumbnail'][2] = "http://img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/2.jpg";
69
        $video_list[0]['entry'][$k]['thumbnail'][3] = "http://img.youtube.com/vi/" . $video_list[0]['entry'][$k]['id'] . "/3.jpg";
70
        
71
        $keywords_raw = explode(',', $video_list[0]['entry'][$k]['media:group'][0]['media:keywords']);
72
        
73
        $i = 0;
74
        foreach ($keywords_raw as $k2 => $v2)
75
        {
76
            $video_list[0]['entry'][$k]['keywords'][$i] = trim($v2);
77
            $i ++;
78
        }
79
    }
80
    else
81
    {
82
        unset($video_list[0]['entry'][$k]);
83
    }
84
}
85

  
86
sort($video_list[0]['entry']);
87

  
11
$video = new video();
12
$yt_videos = $video->getVideos($frontpage_keyword, 1);
13
$page = isset($_GET['p']) ? $_GET['p'] : 1;
88 14
$next_page = 0;
89 15

  
90
if ((($_GET['p'] + 1) * $config['list_per_page']) < $video_list[0]['opensearch:totalresults'])
16
if ((($page + 1) * $config['list_per_page']) < $config['total_videos'])
91 17
{
92
    $next_page = $_GET['p'] + 1;
18
    $next_page = $page + 1;
93 19
}
94 20

  
95
$tpl->assign('total', ceil($video_list[0]['opensearch:totalresults'] / $config['list_per_page']));
96
$tpl->assign('videos', $video_list[0]['entry']);
97
$tpl->assign('keyword', urldecode(stripslashes($_GET['q'])));
21
$tpl->assign('total', ceil($config['total_videos'] / $config['list_per_page']));
22
$tpl->assign('videos', $yt_videos);
23
$tpl->assign('keyword', urldecode(stripslashes($frontpage_keyword)));
98 24
$tpl->assign('next_page', $next_page);
99
$tpl->assign('curr_page', $_GET['p']);
25
$tpl->assign('curr_page', $page);
100 26
$tpl->display('list.html');
init.php
7 7
$config['user_favorites_list_per_page'] = 3;
8 8
$config['display_tags'] = 0;
9 9
$config['link_author'] = 0;
10
$config['total_videos'] = 999;
10 11

  
11 12
$config['website_url'] = 'http://yourdomain.extn/'; // with slash
12 13

  
......
35 36
$tpl->assign('config', $config);
36 37

  
37 38
// error_reporting(E_ERROR | E_PARSE);
39

  
40
set_include_path('.' . PATH_SEPARATOR . BASE_PATH . PATH_SEPARATOR . BASE_PATH . '/lib/' . PATH_SEPARATOR . get_include_path());
41
include_once 'Zend/Loader.php';
42
Zend_Loader::loadClass('Zend_Gdata_YouTube');
43
include_once BASE_PATH . "lib/class.video.php";
44

  
lib/Zend/Exception.php
1
<?php
2
/**
3
 * Zend Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://framework.zend.com/license/new-bsd
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to license@zend.com so we can send you a copy immediately.
14
 *
15
 * @category   Zend
16
 * @package    Zend
17
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
19
 * @version    $Id: Exception.php 23775 2011-03-01 17:25:24Z ralph $
20
 */
21

  
22
/**
23
* @category   Zend
24
* @package    Zend
25
* @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
26
* @license    http://framework.zend.com/license/new-bsd     New BSD License
27
*/
28
class Zend_Exception extends Exception
29
{
30
    /**
31
     * @var null|Exception
32
     */
33
    private $_previous = null;
34

  
35
    /**
36
     * Construct the exception
37
     *
38
     * @param  string $msg
39
     * @param  int $code
40
     * @param  Exception $previous
41
     * @return void
42
     */
43
    public function __construct($msg = '', $code = 0, Exception $previous = null)
44
    {
45
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
46
            parent::__construct($msg, (int) $code);
47
            $this->_previous = $previous;
48
        } else {
49
            parent::__construct($msg, (int) $code, $previous);
50
        }
51
    }
52

  
53
    /**
54
     * Overloading
55
     *
56
     * For PHP < 5.3.0, provides access to the getPrevious() method.
57
     *
58
     * @param  string $method
59
     * @param  array $args
60
     * @return mixed
61
     */
62
    public function __call($method, array $args)
63
    {
64
        if ('getprevious' == strtolower($method)) {
65
            return $this->_getPrevious();
66
        }
67
        return null;
68
    }
69

  
70
    /**
71
     * String representation of the exception
72
     *
73
     * @return string
74
     */
75
    public function __toString()
76
    {
77
        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
78
            if (null !== ($e = $this->getPrevious())) {
79
                return $e->__toString()
80
                       . "\n\nNext "
81
                       . parent::__toString();
82
            }
83
        }
84
        return parent::__toString();
85
    }
86

  
87
    /**
88
     * Returns previous Exception
89
     *
90
     * @return Exception|null
91
     */
92
    protected function _getPrevious()
93
    {
94
        return $this->_previous;
95
    }
96
}
lib/Zend/Gdata.php
1
<?php
2

  
3
/**
4
 * Zend Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://framework.zend.com/license/new-bsd
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to license@zend.com so we can send you a copy immediately.
15
 *
16
 * @category   Zend
17
 * @package    Zend_Gdata
18
 * @subpackage Gdata
19
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21
 * @version    $Id: Gdata.php 23775 2011-03-01 17:25:24Z ralph $
22
 */
23

  
24
/**
25
 * Zend_Gdata_App
26
 */
27
require_once 'Zend/Gdata/App.php';
28

  
29
/**
30
 * Provides functionality to interact with Google data APIs
31
 * Subclasses exist to implement service-specific features
32
 *
33
 * As the Google data API protocol is based upon the Atom Publishing Protocol
34
 * (APP), Gdata functionality extends the appropriate Zend_Gdata_App classes
35
 *
36
 * @link http://code.google.com/apis/gdata/overview.html
37
 *
38
 * @category   Zend
39
 * @package    Zend_Gdata
40
 * @subpackage Gdata
41
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
42
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
43
 */
44
class Zend_Gdata extends Zend_Gdata_App
45
{
46

  
47
    /**
48
     * Service name for use with Google's authentication mechanisms
49
     *
50
     * @var string
51
     */
52
    const AUTH_SERVICE_NAME = 'xapi';
53

  
54
    /**
55
     * Default URI to which to POST.
56
     *
57
     * @var string
58
     */
59
    protected $_defaultPostUri = null;
60

  
61
    /**
62
     * Packages to search for classes when using magic __call method, in order.
63
     *
64
     * @var array
65
     */
66
    protected $_registeredPackages = array(
67
            'Zend_Gdata_Kind',
68
            'Zend_Gdata_Extension',
69
            'Zend_Gdata',
70
            'Zend_Gdata_App_Extension',
71
            'Zend_Gdata_App');
72

  
73
    /**
74
     * Namespaces used for Gdata data
75
     *
76
     * @var array
77
     */
78
    public static $namespaces = array(
79
        array('gd', 'http://schemas.google.com/g/2005', 1, 0),
80
        array('openSearch', 'http://a9.com/-/spec/opensearchrss/1.0/', 1, 0),
81
        array('openSearch', 'http://a9.com/-/spec/opensearch/1.1/', 2, 0),
82
        array('rss', 'http://blogs.law.harvard.edu/tech/rss', 1, 0)
83
    );
84

  
85
    /**
86
     * Client object used to communicate
87
     *
88
     * @var Zend_Gdata_HttpClient
89
     */
90
    protected $_httpClient;
91

  
92
    /**
93
     * Client object used to communicate in static context
94
     *
95
     * @var Zend_Gdata_HttpClient
96
     */
97
    protected static $_staticHttpClient = null;
98

  
99
    /**
100
     * Create Gdata object
101
     *
102
     * @param Zend_Http_Client $client
103
     * @param string $applicationId The identity of the app in the form of
104
     *          Company-AppName-Version
105
     */
106
    public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
107
    {
108
        parent::__construct($client, $applicationId);
109
    }
110

  
111
    /**
112
     * Imports a feed located at $uri.
113
     *
114
     * @param  string $uri
115
     * @param  Zend_Http_Client $client The client used for communication
116
     * @param  string $className The class which is used as the return type
117
     * @throws Zend_Gdata_App_Exception
118
     * @return string|Zend_Gdata_App_Feed Returns string only if the object
119
     *                                    mapping has been disabled explicitly
120
     *                                    by passing false to the
121
     *                                    useObjectMapping() function.
122
     */
123
    public static function import($uri, $client = null,
124
        $className='Zend_Gdata_Feed')
125
    {
126
        $app = new Zend_Gdata($client);
127
        $requestData = $app->decodeRequest('GET', $uri);
128
        $response = $app->performHttpRequest($requestData['method'], $requestData['url']);
129

  
130
        $feedContent = $response->getBody();
131

  
132
        $feed = self::importString($feedContent, $className);
133
        if ($client != null) {
134
            $feed->setHttpClient($client);
135
        }
136
        return $feed;
137
    }
138

  
139
    /**
140
     * Retrieve feed as string or object
141
     *
142
     * @param mixed $location The location as string or Zend_Gdata_Query
143
     * @param string $className The class type to use for returning the feed
144
     * @throws Zend_Gdata_App_InvalidArgumentException
145
     * @return string|Zend_Gdata_App_Feed Returns string only if the object
146
     *                                    mapping has been disabled explicitly
147
     *                                    by passing false to the
148
     *                                    useObjectMapping() function.
149
     */
150
    public function getFeed($location, $className='Zend_Gdata_Feed')
151
    {
152
        if (is_string($location)) {
153
            $uri = $location;
154
        } elseif ($location instanceof Zend_Gdata_Query) {
155
            $uri = $location->getQueryUrl();
156
        } else {
157
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
158
            throw new Zend_Gdata_App_InvalidArgumentException(
159
                    'You must specify the location as either a string URI ' .
160
                    'or a child of Zend_Gdata_Query');
161
        }
162
        return parent::getFeed($uri, $className);
163
    }
164

  
165
    /**
166
     * Retrieve entry as string or object
167
     *
168
     * @param mixed $location The location as string or Zend_Gdata_Query
169
     * @throws Zend_Gdata_App_InvalidArgumentException
170
     * @return string|Zend_Gdata_App_Entry Returns string only if the object
171
     *                                     mapping has been disabled explicitly
172
     *                                     by passing false to the
173
     *                                     useObjectMapping() function.
174
     */
175
    public function getEntry($location, $className='Zend_Gdata_Entry')
176
    {
177
        if (is_string($location)) {
178
            $uri = $location;
179
        } elseif ($location instanceof Zend_Gdata_Query) {
180
            $uri = $location->getQueryUrl();
181
        } else {
182
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
183
            throw new Zend_Gdata_App_InvalidArgumentException(
184
                    'You must specify the location as either a string URI ' .
185
                    'or a child of Zend_Gdata_Query');
186
        }
187
        return parent::getEntry($uri, $className);
188
    }
189

  
190
    /**
191
     * Performs a HTTP request using the specified method.
192
     *
193
     * Overrides the definition in the parent (Zend_Gdata_App)
194
     * and uses the Zend_Gdata_HttpClient functionality
195
     * to filter the HTTP requests and responses.
196
     *
197
     * @param string $method The HTTP method for the request -
198
     *                       'GET', 'POST', 'PUT', 'DELETE'
199
     * @param string $url The URL to which this request is being performed,
200
     *                    or null if found in $data
201
     * @param array $headers An associative array of HTTP headers
202
     *                       for this request
203
     * @param string $body The body of the HTTP request
204
     * @param string $contentType The value for the content type of the
205
     *                            request body
206
     * @param int $remainingRedirects Number of redirects to follow
207
     *                                if requests results in one
208
     * @return Zend_Http_Response The response object
209
     */
210
    public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
211
    {
212
        if ($this->_httpClient instanceof Zend_Gdata_HttpClient) {
213
            $filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType);
214
            $method = $filterResult['method'];
215
            $url = $filterResult['url'];
216
            $body = $filterResult['body'];
217
            $headers = $filterResult['headers'];
218
            $contentType = $filterResult['contentType'];
219
            return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
220
        } else {
221
            return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
222
        }
223
    }
224

  
225
    /**
226
     * Determines whether service object is authenticated.
227
     *
228
     * @return boolean True if service object is authenticated, false otherwise.
229
     */
230
    public function isAuthenticated()
231
    {
232
        $client = parent::getHttpClient();
233
        if ($client->getClientLoginToken() ||
234
            $client->getAuthSubToken()) {
235
                return true;
236
        }
237

  
238
        return false;
239
    }
240

  
241
}
lib/Zend/Gdata/App.php
1
<?php
2

  
3
/**
4
 * Zend Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.txt.
10
 * It is also available through the world-wide-web at this URL:
11
 * http://framework.zend.com/license/new-bsd
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to license@zend.com so we can send you a copy immediately.
15
 *
16
 * @category   Zend
17
 * @package    Zend_Gdata
18
 * @subpackage App
19
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
20
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
21
 * @version    $Id: App.php 23775 2011-03-01 17:25:24Z ralph $
22
 */
23

  
24
/**
25
 * Zend_Gdata_Feed
26
 */
27
require_once 'Zend/Gdata/App/Feed.php';
28

  
29
/**
30
 * Zend_Gdata_Http_Client
31
 */
32
require_once 'Zend/Http/Client.php';
33

  
34
/**
35
 * Zend_Version
36
 */
37
require_once 'Zend/Version.php';
38

  
39
/**
40
 * Zend_Gdata_App_MediaSource
41
 */
42
require_once 'Zend/Gdata/App/MediaSource.php';
43

  
44
/**
45
 * Provides Atom Publishing Protocol (APP) functionality.  This class and all
46
 * other components of Zend_Gdata_App are designed to work independently from
47
 * other Zend_Gdata components in order to interact with generic APP services.
48
 *
49
 * @category   Zend
50
 * @package    Zend_Gdata
51
 * @subpackage App
52
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
53
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
54
 */
55
class Zend_Gdata_App
56
{
57

  
58
    /** Default major protocol version.
59
      *
60
      * @see _majorProtocolVersion
61
      */
62
    const DEFAULT_MAJOR_PROTOCOL_VERSION = 1;
63

  
64
    /** Default minor protocol version.
65
      *
66
      * @see _minorProtocolVersion
67
      */
68
    const DEFAULT_MINOR_PROTOCOL_VERSION = null;
69

  
70
    /**
71
     * Client object used to communicate
72
     *
73
     * @var Zend_Http_Client
74
     */
75
    protected $_httpClient;
76

  
77
    /**
78
     * Client object used to communicate in static context
79
     *
80
     * @var Zend_Http_Client
81
     */
82
    protected static $_staticHttpClient = null;
83

  
84
    /**
85
     * Override HTTP PUT and DELETE request methods?
86
     *
87
     * @var boolean
88
     */
89
    protected static $_httpMethodOverride = false;
90

  
91
    /**
92
     * Enable gzipped responses?
93
     *
94
     * @var boolean
95
     */
96
    protected static $_gzipEnabled = false;
97

  
98
    /**
99
     * Use verbose exception messages.  In the case of HTTP errors,
100
     * use the body of the HTTP response in the exception message.
101
     *
102
     * @var boolean
103
     */
104
    protected static $_verboseExceptionMessages = true;
105

  
106
    /**
107
     * Default URI to which to POST.
108
     *
109
     * @var string
110
     */
111
    protected $_defaultPostUri = null;
112

  
113
    /**
114
     * Packages to search for classes when using magic __call method, in order.
115
     *
116
     * @var array
117
     */
118
    protected $_registeredPackages = array(
119
            'Zend_Gdata_App_Extension',
120
            'Zend_Gdata_App');
121

  
122
    /**
123
     * Maximum number of redirects to follow during HTTP operations
124
     *
125
     * @var int
126
     */
127
    protected static $_maxRedirects = 5;
128

  
129
    /**
130
      * Indicates the major protocol version that should be used.
131
      * At present, recognized values are either 1 or 2. However, any integer
132
      * value >= 1 is considered valid.
133
      *
134
      * Under most circumtances, this will be automatically set by
135
      * Zend_Gdata_App subclasses.
136
      *
137
      * @see setMajorProtocolVersion()
138
      * @see getMajorProtocolVersion()
139
      */
140
    protected $_majorProtocolVersion;
141

  
142
    /**
143
      * Indicates the minor protocol version that should be used. Can be set
144
      * to either an integer >= 0, or NULL if no minor version should be sent
145
      * to the server.
146
      *
147
      * At present, this field is not used by any Google services, but may be
148
      * used in the future.
149
      *
150
      * Under most circumtances, this will be automatically set by
151
      * Zend_Gdata_App subclasses.
152
      *
153
      * @see setMinorProtocolVersion()
154
      * @see getMinorProtocolVersion()
155
      */
156
    protected $_minorProtocolVersion;
157

  
158
    /**
159
     * Whether we want to use XML to object mapping when fetching data.
160
     *
161
     * @var boolean
162
     */
163
    protected $_useObjectMapping = true;
164

  
165
    /**
166
     * Create Gdata object
167
     *
168
     * @param Zend_Http_Client $client
169
     * @param string $applicationId
170
     */
171
    public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
172
    {
173
        $this->setHttpClient($client, $applicationId);
174
        // Set default protocol version. Subclasses should override this as
175
        // needed once a given service supports a new version.
176
        $this->setMajorProtocolVersion(self::DEFAULT_MAJOR_PROTOCOL_VERSION);
177
        $this->setMinorProtocolVersion(self::DEFAULT_MINOR_PROTOCOL_VERSION);
178
    }
179

  
180
    /**
181
     * Adds a Zend Framework package to the $_registeredPackages array.
182
     * This array is searched when using the magic __call method below
183
     * to instantiante new objects.
184
     *
185
     * @param string $name The name of the package (eg Zend_Gdata_App)
186
     * @return void
187
     */
188
    public function registerPackage($name)
189
    {
190
        array_unshift($this->_registeredPackages, $name);
191
    }
192

  
193
    /**
194
     * Retrieve feed as string or object
195
     *
196
     * @param string $uri The uri from which to retrieve the feed
197
     * @param string $className The class which is used as the return type
198
     * @return string|Zend_Gdata_App_Feed Returns string only if the object
199
     *                                    mapping has been disabled explicitly
200
     *                                    by passing false to the
201
     *                                    useObjectMapping() function.
202
     */
203
    public function getFeed($uri, $className='Zend_Gdata_App_Feed')
204
    {
205
        return $this->importUrl($uri, $className, null);
206
    }
207

  
208
    /**
209
     * Retrieve entry as string or object
210
     *
211
     * @param string $uri
212
     * @param string $className The class which is used as the return type
213
     * @return string|Zend_Gdata_App_Entry Returns string only if the object
214
     *                                     mapping has been disabled explicitly
215
     *                                     by passing false to the
216
     *                                     useObjectMapping() function.
217
     */
218
    public function getEntry($uri, $className='Zend_Gdata_App_Entry')
219
    {
220
        return $this->importUrl($uri, $className, null);
221
    }
222

  
223
    /**
224
     * Get the Zend_Http_Client object used for communication
225
     *
226
     * @return Zend_Http_Client
227
     */
228
    public function getHttpClient()
229
    {
230
        return $this->_httpClient;
231
    }
232

  
233
    /**
234
     * Set the Zend_Http_Client object used for communication
235
     *
236
     * @param Zend_Http_Client $client The client to use for communication
237
     * @throws Zend_Gdata_App_HttpException
238
     * @return Zend_Gdata_App Provides a fluent interface
239
     */
240
    public function setHttpClient($client,
241
        $applicationId = 'MyCompany-MyApp-1.0')
242
    {
243
        if ($client === null) {
244
            $client = new Zend_Http_Client();
245
        }
246
        if (!$client instanceof Zend_Http_Client) {
247
            require_once 'Zend/Gdata/App/HttpException.php';
248
            throw new Zend_Gdata_App_HttpException(
249
                'Argument is not an instance of Zend_Http_Client.');
250
        }
251
        $userAgent = $applicationId . ' Zend_Framework_Gdata/' .
252
            Zend_Version::VERSION;
253
        $client->setHeaders('User-Agent', $userAgent);
254
        $client->setConfig(array(
255
            'strictredirects' => true
256
            )
257
        );
258
        $this->_httpClient = $client;
259
        self::setStaticHttpClient($client);
260
        return $this;
261
    }
262

  
263
    /**
264
     * Set the static HTTP client instance
265
     *
266
     * Sets the static HTTP client object to use for retrieving the feed.
267
     *
268
     * @param  Zend_Http_Client $httpClient
269
     * @return void
270
     */
271
    public static function setStaticHttpClient(Zend_Http_Client $httpClient)
272
    {
273
        self::$_staticHttpClient = $httpClient;
274
    }
275

  
276

  
277
    /**
278
     * Gets the HTTP client object. If none is set, a new Zend_Http_Client will be used.
279
     *
280
     * @return Zend_Http_Client
281
     */
282
    public static function getStaticHttpClient()
283
    {
284
        if (!self::$_staticHttpClient instanceof Zend_Http_Client) {
285
            $client = new Zend_Http_Client();
286
            $userAgent = 'Zend_Framework_Gdata/' . Zend_Version::VERSION;
287
            $client->setHeaders('User-Agent', $userAgent);
288
            $client->setConfig(array(
289
                'strictredirects' => true
290
                )
291
            );
292
            self::$_staticHttpClient = $client;
293
        }
294
        return self::$_staticHttpClient;
295
    }
296

  
297
    /**
298
     * Toggle using POST instead of PUT and DELETE HTTP methods
299
     *
300
     * Some feed implementations do not accept PUT and DELETE HTTP
301
     * methods, or they can't be used because of proxies or other
302
     * measures. This allows turning on using POST where PUT and
303
     * DELETE would normally be used; in addition, an
304
     * X-Method-Override header will be sent with a value of PUT or
305
     * DELETE as appropriate.
306
     *
307
     * @param  boolean $override Whether to override PUT and DELETE with POST.
308
     * @return void
309
     */
310
    public static function setHttpMethodOverride($override = true)
311
    {
312
        self::$_httpMethodOverride = $override;
313
    }
314

  
315
    /**
316
     * Get the HTTP override state
317
     *
318
     * @return boolean
319
     */
320
    public static function getHttpMethodOverride()
321
    {
322
        return self::$_httpMethodOverride;
323
    }
324

  
325
    /**
326
     * Toggle requesting gzip encoded responses
327
     *
328
     * @param  boolean $enabled Whether or not to enable gzipped responses
329
     * @return void
330
     */
331
    public static function setGzipEnabled($enabled = false)
332
    {
333
        if ($enabled && !function_exists('gzinflate')) {
334
            require_once 'Zend/Gdata/App/InvalidArgumentException.php';
335
            throw new Zend_Gdata_App_InvalidArgumentException(
336
                    'You cannot enable gzipped responses if the zlib module ' .
337
                    'is not enabled in your PHP installation.');
338

  
339
        }
340
        self::$_gzipEnabled = $enabled;
341
    }
342

  
343
    /**
344
     * Get the HTTP override state
345
     *
346
     * @return boolean
347
     */
348
    public static function getGzipEnabled()
349
    {
350
        return self::$_gzipEnabled;
351
    }
352

  
353
    /**
354
     * Get whether to use verbose exception messages
355
     *
356
     * In the case of HTTP errors,  use the body of the HTTP response
357
     * in the exception message.
358
     *
359
     * @return boolean
360
     */
361
    public static function getVerboseExceptionMessages()
362
    {
363
        return self::$_verboseExceptionMessages;
364
    }
365

  
366
    /**
367
     * Set whether to use verbose exception messages
368
     *
369
     * In the case of HTTP errors, use the body of the HTTP response
370
     * in the exception message.
371
     *
372
     * @param boolean $verbose Whether to use verbose exception messages
373
     */
374
    public static function setVerboseExceptionMessages($verbose)
375
    {
376
        self::$_verboseExceptionMessages = $verbose;
377
    }
378

  
379
    /**
380
     * Set the maximum number of redirects to follow during HTTP operations
381
     *
382
     * @param int $maxRedirects Maximum number of redirects to follow
383
     * @return void
384
     */
385
    public static function setMaxRedirects($maxRedirects)
386
    {
387
        self::$_maxRedirects = $maxRedirects;
388
    }
389

  
390
    /**
391
     * Get the maximum number of redirects to follow during HTTP operations
392
     *
393
     * @return int Maximum number of redirects to follow
394
     */
395
    public static function getMaxRedirects()
396
    {
397
        return self::$_maxRedirects;
398
    }
399

  
400
    /**
401
     * Set the major protocol version that should be used. Values < 1 will
402
     * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
403
     *
404
     * @see _majorProtocolVersion
405
     * @param int $value The major protocol version to use.
406
     * @throws Zend_Gdata_App_InvalidArgumentException
407
     */
408
    public function setMajorProtocolVersion($value)
409
    {
410
        if (!($value >= 1)) {
411
            require_once('Zend/Gdata/App/InvalidArgumentException.php');
412
            throw new Zend_Gdata_App_InvalidArgumentException(
413
                    'Major protocol version must be >= 1');
414
        }
415
        $this->_majorProtocolVersion = $value;
416
    }
417

  
418
    /**
419
     * Get the major protocol version that is in use.
420
     *
421
     * @see _majorProtocolVersion
422
     * @return int The major protocol version in use.
423
     */
424
    public function getMajorProtocolVersion()
425
    {
426
        return $this->_majorProtocolVersion;
427
    }
428

  
429
    /**
430
     * Set the minor protocol version that should be used. If set to NULL, no
431
     * minor protocol version will be sent to the server. Values < 0 will
432
     * cause a Zend_Gdata_App_InvalidArgumentException to be thrown.
433
     *
434
     * @see _minorProtocolVersion
435
     * @param (int|NULL) $value The minor protocol version to use.
436
     * @throws Zend_Gdata_App_InvalidArgumentException
437
     */
438
    public function setMinorProtocolVersion($value)
439
    {
440
        if (!($value >= 0)) {
441
            require_once('Zend/Gdata/App/InvalidArgumentException.php');
442
            throw new Zend_Gdata_App_InvalidArgumentException(
443
                    'Minor protocol version must be >= 0');
444
        }
445
        $this->_minorProtocolVersion = $value;
... This diff was truncated because it exceeds the maximum size that can be displayed.