13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Service |
16 * @package Zend_Service |
17 * @subpackage SlideShare |
17 * @subpackage SlideShare |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: SlideShare.php 25283 2013-03-09 10:07:13Z frosch $ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * Zend_Http_Client |
24 * Zend_Http_Client |
25 */ |
25 */ |
32 |
32 |
33 /** |
33 /** |
34 * Zend_Service_SlideShare_SlideShow |
34 * Zend_Service_SlideShare_SlideShow |
35 */ |
35 */ |
36 require_once 'Zend/Service/SlideShare/SlideShow.php'; |
36 require_once 'Zend/Service/SlideShare/SlideShow.php'; |
|
37 |
|
38 /** Zend_Xml_Security */ |
|
39 require_once 'Zend/Xml/Security.php'; |
37 |
40 |
38 /** |
41 /** |
39 * The Zend_Service_SlideShare component is used to interface with the |
42 * The Zend_Service_SlideShare component is used to interface with the |
40 * slideshare.net web server to retrieve slide shows hosted on the web site for |
43 * slideshare.net web server to retrieve slide shows hosted on the web site for |
41 * display or other processing. |
44 * display or other processing. |
42 * |
45 * |
43 * @category Zend |
46 * @category Zend |
44 * @package Zend_Service |
47 * @package Zend_Service |
45 * @subpackage SlideShare |
48 * @subpackage SlideShare |
46 * @throws Zend_Service_SlideShare_Exception |
49 * @throws Zend_Service_SlideShare_Exception |
47 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
50 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
48 * @license http://framework.zend.com/license/new-bsd New BSD License |
51 * @license http://framework.zend.com/license/new-bsd New BSD License |
49 */ |
52 */ |
50 class Zend_Service_SlideShare |
53 class Zend_Service_SlideShare |
51 { |
54 { |
52 /** |
55 /** |
123 * @var Zend_Cache_Core |
126 * @var Zend_Cache_Core |
124 */ |
127 */ |
125 protected $_cacheobject; |
128 protected $_cacheobject; |
126 |
129 |
127 /** |
130 /** |
128 * Sets the Zend_Http_Client object to use in requests. If not provided a default will |
131 * Sets the Zend_Http_Client object to use in requests. If not provided a |
129 * be used. |
132 * default will be used. |
130 * |
133 * |
131 * @param Zend_Http_Client $client The HTTP client instance to use |
134 * @param Zend_Http_Client $client The HTTP client instance to use |
132 * @return Zend_Service_SlideShare |
135 * @return Zend_Service_SlideShare |
133 */ |
136 */ |
134 public function setHttpClient(Zend_Http_Client $client) |
137 public function setHttpClient(Zend_Http_Client $client) |
174 $this->_cacheobject = $cacheobject; |
177 $this->_cacheobject = $cacheobject; |
175 return $this; |
178 return $this; |
176 } |
179 } |
177 |
180 |
178 /** |
181 /** |
179 * Gets the Zend_Cache object which will be used to cache API queries. If no cache object |
182 * Gets the Zend_Cache object which will be used to cache API queries. If no |
180 * was previously set the the default will be used (Filesystem caching in /tmp with a life |
183 * cache object was previously set the the default will be used (Filesystem |
181 * time of 43200 seconds) |
184 * caching in /tmp with a life time of 43200 seconds) |
182 * |
185 * |
183 * @return Zend_Cache_Core The object used in caching |
186 * @return Zend_Cache_Core The object used in caching |
184 */ |
187 */ |
185 public function getCacheObject() |
188 public function getCacheObject() |
186 { |
189 { |
311 } |
314 } |
312 |
315 |
313 /** |
316 /** |
314 * Uploads the specified Slide show the the server |
317 * Uploads the specified Slide show the the server |
315 * |
318 * |
316 * @param Zend_Service_SlideShare_SlideShow $ss The slide show object representing the slide show to upload |
319 * @param Zend_Service_SlideShare_SlideShow $ss The slide show |
317 * @param boolean $makeSrcPublic Determines if the the slide show's source file is public or not upon upload |
320 * object representing the |
318 * @return Zend_Service_SlideShare_SlideShow The passed Slide show object, with the new assigned ID provided |
321 * slide show to upload |
|
322 * @param boolean $makeSrcPublic Determines if the slide |
|
323 * show's source file is public |
|
324 * or not upon upload |
|
325 * @return Zend_Service_SlideShare_SlideShow The passed Slide show object, |
|
326 * with the new assigned ID |
|
327 * provided |
319 * @throws Zend_Service_SlideShare_Exception |
328 * @throws Zend_Service_SlideShare_Exception |
320 */ |
329 */ |
321 public function uploadSlideShow( |
330 public function uploadSlideShow( |
322 Zend_Service_SlideShare_SlideShow $ss, $makeSrcPublic = true |
331 Zend_Service_SlideShare_SlideShow $ss, $makeSrcPublic = true |
323 ) |
332 ) |
374 throw new Zend_Service_SlideShare_Exception( |
383 throw new Zend_Service_SlideShare_Exception( |
375 "Service Request Failed: {$e->getMessage()}", 0, $e |
384 "Service Request Failed: {$e->getMessage()}", 0, $e |
376 ); |
385 ); |
377 } |
386 } |
378 |
387 |
379 $sxe = simplexml_load_string($response->getBody()); |
388 $sxe = Zend_Xml_Security::scan($response->getBody()); |
380 |
389 |
381 if ($sxe->getName() == "SlideShareServiceError") { |
390 if ($sxe->getName() == "SlideShareServiceError") { |
382 $message = (string)$sxe->Message[0]; |
391 $message = (string)$sxe->Message[0]; |
383 list($code, $error_str) = explode(':', $message); |
392 list($code, $errorStr) = explode(':', $message); |
384 require_once 'Zend/Service/SlideShare/Exception.php'; |
393 require_once 'Zend/Service/SlideShare/Exception.php'; |
385 throw new Zend_Service_SlideShare_Exception(trim( |
394 throw new Zend_Service_SlideShare_Exception( |
386 $error_str |
395 trim($errorStr), |
387 ), $code); |
396 $code |
|
397 ); |
388 } |
398 } |
389 |
399 |
390 if (!$sxe->getName() == "SlideShowUploaded") { |
400 if (!$sxe->getName() == "SlideShowUploaded") { |
391 require_once 'Zend/Service/SlideShare/Exception.php'; |
401 require_once 'Zend/Service/SlideShare/Exception.php'; |
392 throw new Zend_Service_SlideShare_Exception( |
402 throw new Zend_Service_SlideShare_Exception( |
400 } |
410 } |
401 |
411 |
402 /** |
412 /** |
403 * Retrieves a slide show's information based on slide show ID |
413 * Retrieves a slide show's information based on slide show ID |
404 * |
414 * |
405 * @param int $ss_id The slide show ID |
415 * @param int $ssId The slide show ID |
406 * @return Zend_Service_SlideShare_SlideShow the Slideshow object |
416 * @return Zend_Service_SlideShare_SlideShow the Slideshow object |
407 * @throws Zend_Service_SlideShare_Exception |
417 * @throws Zend_Service_SlideShare_Exception |
408 */ |
418 */ |
409 public function getSlideShow($ss_id) |
419 public function getSlideShow($ssId) |
410 { |
420 { |
411 $timestamp = time(); |
421 $timestamp = time(); |
412 |
422 |
413 $params = array( |
423 $params = array( |
414 'api_key' => $this->getApiKey(), |
424 'api_key' => $this->getApiKey(), |
415 'ts' => $timestamp, |
425 'ts' => $timestamp, |
416 'hash' => sha1($this->getSharedSecret() . $timestamp), |
426 'hash' => sha1($this->getSharedSecret() . $timestamp), |
417 'slideshow_id' => $ss_id |
427 'slideshow_id' => $ssId |
418 ); |
428 ); |
419 |
429 |
420 $cache = $this->getCacheObject(); |
430 $cache = $this->getCacheObject(); |
421 |
431 $cacheKey = md5("__zendslideshare_cache_$ssId"); |
422 $cache_key = md5("__zendslideshare_cache_$ss_id"); |
432 |
423 |
433 if (!$retval = $cache->load($cacheKey)) { |
424 if (!$retval = $cache->load($cache_key)) { |
|
425 $client = $this->getHttpClient(); |
434 $client = $this->getHttpClient(); |
426 |
435 |
427 $client->setUri(self::SERVICE_GET_SHOW_URI); |
436 $client->setUri(self::SERVICE_GET_SHOW_URI); |
428 $client->setParameterPost($params); |
437 $client->setParameterPost($params); |
429 |
438 |
435 throw new Zend_Service_SlideShare_Exception( |
444 throw new Zend_Service_SlideShare_Exception( |
436 "Service Request Failed: {$e->getMessage()}", 0, $e |
445 "Service Request Failed: {$e->getMessage()}", 0, $e |
437 ); |
446 ); |
438 } |
447 } |
439 |
448 |
440 $sxe = simplexml_load_string($response->getBody()); |
449 $sxe = Zend_Xml_Security::scan($response->getBody()); |
441 |
450 |
442 if ($sxe->getName() == "SlideShareServiceError") { |
451 if ($sxe->getName() == "SlideShareServiceError") { |
443 $message = (string)$sxe->Message[0]; |
452 $message = (string)$sxe->Message[0]; |
444 list($code, $error_str) = explode(':', $message); |
453 list($code, $errorStr) = explode(':', $message); |
445 require_once 'Zend/Service/SlideShare/Exception.php'; |
454 require_once 'Zend/Service/SlideShare/Exception.php'; |
446 throw new Zend_Service_SlideShare_Exception(trim( |
455 throw new Zend_Service_SlideShare_Exception( |
447 $error_str |
456 trim($errorStr), |
448 ), $code); |
457 $code |
|
458 ); |
449 } |
459 } |
450 |
460 |
451 if (!($sxe->getName() == 'Slideshow')) { |
461 if (!($sxe->getName() == 'Slideshow')) { |
452 require_once 'Zend/Service/SlideShare/Exception.php'; |
462 require_once 'Zend/Service/SlideShare/Exception.php'; |
453 throw new Zend_Service_SlideShare_Exception( |
463 throw new Zend_Service_SlideShare_Exception( |
454 'Unknown XML Repsonse Received' |
464 'Unknown XML Repsonse Received' |
455 ); |
465 ); |
456 } |
466 } |
457 $retval = $this->_slideShowNodeToObject(clone $sxe); |
467 $retval = $this->_slideShowNodeToObject(clone $sxe); |
458 |
468 |
459 $cache->save($retval, $cache_key); |
469 $cache->save($retval, $cacheKey); |
460 } |
470 } |
461 |
471 |
462 return $retval; |
472 return $retval; |
463 } |
473 } |
464 |
474 |
524 * @param int $offset The offset of the list to start retrieving from |
534 * @param int $offset The offset of the list to start retrieving from |
525 * @param int $limit The maximum number of slide shows to retrieve |
535 * @param int $limit The maximum number of slide shows to retrieve |
526 * @return array An array of Zend_Service_SlideShare_SlideShow objects |
536 * @return array An array of Zend_Service_SlideShare_SlideShow objects |
527 * @throws Zend_Service_SlideShare_Exception |
537 * @throws Zend_Service_SlideShare_Exception |
528 */ |
538 */ |
529 protected function _getSlideShowsByType($key, $value, $offset = null, $limit = null) |
539 protected function _getSlideShowsByType( |
|
540 $key, $value, $offset = null, $limit = null |
|
541 ) |
530 { |
542 { |
531 $key = strtolower($key); |
543 $key = strtolower($key); |
532 |
544 |
533 switch ($key) { |
545 switch ($key) { |
534 case 'username_for': |
546 case 'username_for': |
550 ); |
562 ); |
551 } |
563 } |
552 |
564 |
553 $timestamp = time(); |
565 $timestamp = time(); |
554 |
566 |
555 $params = array('api_key' => $this->getApiKey(), |
567 $params = array( |
556 'ts' => $timestamp, |
568 'api_key' => $this->getApiKey(), |
557 'hash' => sha1($this->getSharedSecret().$timestamp), |
569 'ts' => $timestamp, |
558 $key => $value); |
570 'hash' => sha1($this->getSharedSecret() . $timestamp), |
|
571 $key => $value |
|
572 ); |
559 |
573 |
560 if ($offset !== null) { |
574 if ($offset !== null) { |
561 $params['offset'] = (int)$offset; |
575 $params['offset'] = (int)$offset; |
562 } |
576 } |
563 |
577 |
564 if ($limit !== null) { |
578 if ($limit !== null) { |
565 $params['limit'] = (int)$limit; |
579 $params['limit'] = (int)$limit; |
566 } |
580 } |
567 |
581 |
568 $cache = $this->getCacheObject(); |
582 $cache = $this->getCacheObject(); |
569 |
583 $cacheKey = md5($key . $value . $offset . $limit); |
570 $cache_key = md5($key.$value.$offset.$limit); |
584 |
571 |
585 if (!$retval = $cache->load($cacheKey)) { |
572 if (!$retval = $cache->load($cache_key)) { |
|
573 $client = $this->getHttpClient(); |
586 $client = $this->getHttpClient(); |
574 |
587 |
575 $client->setUri($queryUri); |
588 $client->setUri($queryUri); |
576 $client->setParameterPost($params); |
589 $client->setParameterPost($params); |
577 |
590 |
583 throw new Zend_Service_SlideShare_Exception( |
596 throw new Zend_Service_SlideShare_Exception( |
584 "Service Request Failed: {$e->getMessage()}", 0, $e |
597 "Service Request Failed: {$e->getMessage()}", 0, $e |
585 ); |
598 ); |
586 } |
599 } |
587 |
600 |
588 $sxe = simplexml_load_string($response->getBody()); |
601 $sxe = Zend_Xml_Security::scan($response->getBody()); |
589 |
602 |
590 if ($sxe->getName() == "SlideShareServiceError") { |
603 if ($sxe->getName() == "SlideShareServiceError") { |
591 $message = (string)$sxe->Message[0]; |
604 $message = (string)$sxe->Message[0]; |
592 list($code, $error_str) = explode(':', $message); |
605 list($code, $errorStr) = explode(':', $message); |
593 require_once 'Zend/Service/SlideShare/Exception.php'; |
606 require_once 'Zend/Service/SlideShare/Exception.php'; |
594 throw new Zend_Service_SlideShare_Exception( |
607 throw new Zend_Service_SlideShare_Exception( |
595 trim($error_str), $code |
608 trim($errorStr), $code |
596 ); |
609 ); |
597 } |
610 } |
598 |
611 |
599 if (!$sxe->getName() == $responseTag) { |
612 if (!$sxe->getName() == $responseTag) { |
600 require_once 'Zend/Service/SlideShare/Exception.php'; |
613 require_once 'Zend/Service/SlideShare/Exception.php'; |
609 if ($node->getName() == 'Slideshow') { |
622 if ($node->getName() == 'Slideshow') { |
610 $retval[] = $this->_slideShowNodeToObject($node); |
623 $retval[] = $this->_slideShowNodeToObject($node); |
611 } |
624 } |
612 } |
625 } |
613 |
626 |
614 $cache->save($retval, $cache_key); |
627 $cache->save($retval, $cacheKey); |
615 } |
628 } |
616 |
629 |
617 return $retval; |
630 return $retval; |
618 } |
631 } |
619 |
632 |
620 /** |
633 /** |
621 * Converts a SimpleXMLElement object representing a response from the service |
634 * Converts a SimpleXMLElement object representing a response from the service |
622 * into a Zend_Service_SlideShare_SlideShow object |
635 * into a Zend_Service_SlideShare_SlideShow object |
|
636 * |
|
637 * @see http://www.slideshare.net/developers/documentation#get_slideshow |
623 * |
638 * |
624 * @param SimpleXMLElement $node The input XML from the slideshare.net service |
639 * @param SimpleXMLElement $node The input XML from the slideshare.net service |
625 * @return Zend_Service_SlideShare_SlideShow The resulting object |
640 * @return Zend_Service_SlideShare_SlideShow The resulting object |
626 * @throws Zend_Service_SlideShare_Exception |
641 * @throws Zend_Service_SlideShare_Exception |
627 */ |
642 */ |
628 protected function _slideShowNodeToObject(SimpleXMLElement $node) |
643 protected function _slideShowNodeToObject(SimpleXMLElement $node) |
629 { |
644 { |
630 |
645 |
631 if($node->getName() == 'Slideshow') { |
646 if ($node->getName() == 'Slideshow') { |
632 $ss = new Zend_Service_SlideShare_SlideShow(); |
647 $ss = new Zend_Service_SlideShare_SlideShow(); |
633 |
648 |
634 $ss->setId((string)$node->ID); |
649 $ss->setId((string)$node->ID); |
635 $ss->setDescription((string)$node->Description); |
650 $ss->setDescription((string)$node->Description); |
636 $ss->setEmbedCode((string)$node->EmbedCode); |
651 $ss->setEmbedCode((string)$node->Embed); |
637 $ss->setNumViews((string)$node->Views); |
652 $ss->setNumViews((string)$node->Views); |
638 $ss->setPermaLink((string)$node->Permalink); |
653 $ss->setUrl((string)$node->URL); |
639 $ss->setStatus((string)$node->Status); |
654 $ss->setStatus((string)$node->Status); |
640 $ss->setStatusDescription((string)$node->StatusDescription); |
655 $ss->setStatusDescription((string)$node->StatusDescription); |
641 |
656 |
642 foreach (explode(",", (string)$node->Tags) as $tag) { |
657 foreach (explode(",", (string)$node->Tags) as $tag) { |
643 if (!in_array($tag, $ss->getTags())) { |
658 if (!in_array($tag, $ss->getTags())) { |
644 $ss->addTag($tag); |
659 $ss->addTag($tag); |
645 } |
660 } |
646 } |
661 } |
647 |
662 |
648 $ss->setThumbnailUrl((string)$node->Thumbnail); |
663 $ss->setThumbnailUrl((string)$node->ThumbnailURL); |
649 $ss->setTitle((string)$node->Title); |
664 $ss->setTitle((string)$node->Title); |
650 $ss->setLocation((string)$node->Location); |
665 $ss->setLocation((string)$node->Location); |
651 $ss->setTranscript((string)$node->Transcript); |
666 $ss->setTranscript((string)$node->Transcript); |
652 |
667 |
653 return $ss; |
668 return $ss; |