/**
  * Creates a You Tube Playlist.
  *
  * @param array $data See Model::save()
  * @param boolean $validate See Model::save()
  * @param array $fieldList See Model::save()
  * @return boolean
  */
 public function save($data = null, $validate = true, $fieldList = array())
 {
     // Create the XML payload
     $doc = new DOMDocument('1.0', 'utf-8');
     $entry = $doc->createElementNS('http://www.w3.org/2005/Atom', 'entry');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:yt', 'http://gdata.youTube.com/schemas/2007');
     $doc->appendChild($entry);
     if (isset($data[$this->alias]['title'])) {
         $title = $doc->createElement('title', $data[$this->alias]['title']);
         $title->setAttribute('type', 'text');
     }
     $entry->appendChild($title);
     if (isset($data[$this->alias]['summary'])) {
         $summary = $doc->createElement('summary', $data[$this->alias]['summary']);
     }
     $entry->appendChild($summary);
     if (!empty($data[$this->alias]['private'])) {
         $private = $doc->createElementNS('http://gdata.youtube.com/schemas/2007', 'yt:private');
         $entry->appendChild($private);
     }
     // Add the content type in so OAuth won't use the body in the signature
     $this->request = array('uri' => array('path' => 'feeds/api/users/default/playlists'), 'header' => array('Content-Type' => 'application/atom+xml'), 'auth' => true, 'body' => $doc->saveXML());
     $result = parent::save($data, $validate, $fieldList);
     if ($result) {
         $this->setInsertID($this->response['entry']['playlistId']);
     }
     return $result;
 }
예제 #2
0
 /**
 * Imports the datasources from the plugin and adds to the connection manager
 */
 public function __construct()
 {
     App::import(array('type' => 'File', 'name' => 'Gdata.GDATA_CONFIG', 'file' => 'config' . DS . 'gdata_config.php'));
     App::import(array('type' => 'File', 'name' => 'Gdata.GdataSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata_source.php'));
     App::import(array('type' => 'File', 'name' => 'Gdata.GdataPicasa', 'file' => 'models' . DS . 'datasources' . DS . 'gdata' . DS . 'gdata_picasa.php'));
     $config =& new GDATA_CONFIG();
     ConnectionManager::create('picasa', $config->picasa);
     parent::__construct();
 }
예제 #3
0
 /**
  * Imports the datasources from the plugin and adds to the connection manager
  */
 function __construct()
 {
     App::import(array('type' => 'File', 'name' => 'Gdata.GDATA_CONFIG', 'file' => 'config' . DS . 'gdata_config.php'));
     App::import(array('type' => 'File', 'name' => 'Gdata.GdataSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata_source.php'));
     App::import(array('type' => 'File', 'name' => 'Gdata.GdataAnalyticsSource', 'file' => 'models' . DS . 'datasources' . DS . 'gdata' . DS . 'gdata_analytics.php'));
     $config =& new GDATA_CONFIG();
     ConnectionManager::create('analytics', $config->analytics);
     parent::__construct();
 }
 /**
  * Creates a comment on a You Tube Video.
  *
  * @param array $data See Model::save()
  * @param boolean $validate See Model::save()
  * @param array $fieldList See Model::save()
  * @return boolean
  */
 public function save($data = null, $validate = true, $fieldList = array())
 {
     // Create the XML payload
     $doc = new DOMDocument('1.0', 'utf-8');
     $entry = $doc->createElementNS('http://www.w3.org/2005/Atom', 'entry');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:yt', 'http://gdata.youTube.com/schemas/2007');
     $doc->appendChild($entry);
     if (isset($data[$this->alias]['content'])) {
         $content = $doc->createElement('content', $data[$this->alias]['content']);
     }
     $entry->appendChild($content);
     // Add the content type in so OAuth won't use the body in the signature
     $this->request = array('header' => array('Content-Type' => 'application/atom+xml'), 'auth' => true, 'body' => $doc->saveXML());
     if (isset($data[$this->alias]['video_id'])) {
         $this->request['uri']['path'] = '/feeds/api/videos/' . $data[$this->alias]['video_id'] . '/comments';
     }
     $result = parent::save($data, $validate, $fieldList);
     return $result;
 }
 /**
 * Creates the API XML request containing the meta data and adds it to the
 * request body along with the file as multipart data, and sets other values
 * in the request array required for uploading a video to YouTube.
 *
 * ClassRegistry::init('Gdata.YouTubeVideo')->save(array(
   'YouTubeVideo' => array(
  'title' => 'Flying into Chicago Airport',
  'description' => 'Filmed through the plane window, shows coming in over the lake',
  'category' => 'Travel',
  'keywords' => 'Chicago, Plane, Lake, Skyline',
  'rate' => 'allowed',
  'comment' => 'allowed',
  'commentVote' => 'allowed',
  'videoRespond' => 'allowed',
  'embed' => 'allowed',
  'syndicate' => 'allowed',
  'private' => 1,
  'file' => array(
    'name' => 'chicago 1 060.AVI',
    'type' => 'video/avi',
    'tmp_name' => 'C:\Windows\Temp\php6D66.tmp',
    'error' => 0,
    'size' => 5863102))));
 *
 * @param array $data See Model::save()
 * @param boolean $validate See Model::save()
 * @param array $fieldList See Model::save()
 * @return boolean
 */
 public function save($data = null, $validate = true, $fieldList = array())
 {
     // Create the XML containing the meta data about the video
     $doc = new DOMDocument('1.0', 'utf-8');
     $entry = $doc->createElementNS('http://www.w3.org/2005/Atom', 'entry');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:media', 'http://search.yahoo.com/mrss/');
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:yt', 'http://gdata.youtube.com/schemas/2007');
     $doc->appendChild($entry);
     $media = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:group');
     $entry->appendChild($media);
     if (!empty($data[$this->alias]['title'])) {
         $title = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:title', $data[$this->alias]['title']);
         $title->setAttribute('type', 'plain');
         $media->appendChild($title);
     }
     if (!empty($data[$this->alias]['description'])) {
         $description = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:description', $data[$this->alias]['description']);
         $description->setAttribute('type', 'plain');
         $media->appendChild($description);
     }
     if (!empty($data[$this->alias]['category'])) {
         $category = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:category', $data[$this->alias]['category']);
         $category->setAttribute('scheme', 'http://gdata.youtube.com/schemas/2007/categories.cat');
         $media->appendChild($category);
     }
     if (!empty($data[$this->alias]['developertag'])) {
         $category = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:category', $data[$this->alias]['developertag']);
         $category->setAttribute('scheme', 'http://gdata.youtube.com/schemas/2007/developertags.cat');
         $media->appendChild($category);
     }
     if (!empty($data[$this->alias]['keywords'])) {
         $keywords = $doc->createElementNS('http://search.yahoo.com/mrss/', 'media:keywords', $data[$this->alias]['keywords']);
         $media->appendChild($keywords);
     }
     foreach ($this->accessControls as $action => $permissions) {
         if (empty($data[$this->alias][$action])) {
             continue;
         }
         $accessControl = $doc->createElementNS('http://gdata.youtube.com/schemas/2007', 'yt:accessControl');
         $accessControl->setAttribute('action', $action);
         $accessControl->setAttribute('permission', $data[$this->alias][$action]);
         $entry->appendChild($accessControl);
     }
     if (!empty($data[$this->alias]['private'])) {
         $private = $doc->createElementNS('http://gdata.youtube.com/schemas/2007', 'yt:private');
         $media->appendChild($private);
     }
     // The boundary string is used to identify the different parts of a
     // multipart http request
     $boundaryString = 'Next_Part_' . String::uuid();
     // Build the multipart body of the http request
     $body = "--{$boundaryString}\r\n";
     $body .= "Content-Type: application/atom+xml; charset=UTF-8\r\n";
     $body .= "\r\n";
     $body .= $doc->saveXML() . "\r\n";
     $body .= "--{$boundaryString}\r\n";
     $body .= "Content-Type: {$data[$this->alias]['file']['type']}\r\n";
     $body .= "Content-Transfer-Encoding: binary\r\n";
     $body .= "\r\n";
     $body .= file_get_contents($data[$this->alias]['file']['tmp_name']) . "\r\n";
     $body .= "--{$boundaryString}--\r\n";
     $this->request = array('uri' => array('host' => 'uploads.gdata.youtube.com', 'path' => '/feeds/api/users/default/uploads'), 'header' => array('Content-Type' => 'multipart/related; boundary="' . $boundaryString . '"', 'Slug' => $data[$this->alias]['file']['name']), 'auth' => array('method' => 'OAuth'), 'body' => $body);
     return parent::save($data, $validate, $fieldList);
 }
 /**
  * Creates the API XML request containing the meta data and adds it to the
  * request body.
  * 
  * If a 'file' key contains a file upload array, then the request is set to
  * multipart mode and the file attached to send the upload to Google.
  *
  * If there is no 'file' key then a blank document is created, using the 'title'
  * key as its name. A 'type' key may also be supplied containing 'document' or
  * 'spreadsheet'. Other types are not tested yet. 
  * 
  * Note that the 'type' key is not necessary when uploading a file, as google
  * seems to work that out for itself.
  *
  * ClassRegistry::init('Gdata.GoogleDocument')->save(array(
  *	 'GoogleDocument' => array(
  *		 'file' => array(
  *			 'name' => 'my text document.doc',
  *			 'type' => 'application/msword',
  *			 'tmp_name' => '/tmp/asdkjhkjhkj',
  *			 'error' => 0,
  *			 'size' => 863102))));
  *
  * @param array $data See Model::save()
  * @param boolean $validate See Model::save()
  * @param array $fieldList See Model::save()
  * @return boolean
  */
 public function save($data = null, $validate = true, $fieldList = array())
 {
     // Create the XML containing the meta data about the video
     $doc = new DOMDocument('1.0', 'utf-8');
     $entry = $doc->createElementNS('http://www.w3.org/2005/Atom', 'atom:entry');
     $doc->appendChild($entry);
     $type = 'document';
     if (!empty($data[$this->alias]['type'])) {
         $type = $data[$this->alias]['type'];
     }
     $category = $doc->createElement('atom:category');
     $category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
     $category->setAttribute('term', 'http://schemas.google.com/docs/2007#' . $type);
     $category->setAttribute('label', $type);
     $entry->appendChild($category);
     $category = $doc->createElementNS('http://www.w3.org/2005/Atom', 'atom:title', $data[$this->alias]['title']);
     $entry->appendChild($category);
     $body = '';
     $mainContentType = 'application/atom+xml';
     $hasFileUpload = !empty($data[$this->alias]['file']);
     if ($hasFileUpload) {
         $boundaryString = 'Next_Part_' . String::uuid();
         $mainContentType = 'multipart/related; boundary="' . $boundaryString . '"';
         $body .= "--{$boundaryString}\r\n";
         $body .= "Content-Type: application/atom+xml; charset=UTF-8\r\n";
         $body .= "\r\n";
     }
     $body .= $doc->saveXML() . "\r\n";
     if ($hasFileUpload) {
         $body .= "--{$boundaryString}\r\n";
         $body .= "Content-Type: {$data[$this->alias]['file']['type']}\r\n";
         $body .= "Content-Transfer-Encoding: binary\r\n";
         $body .= "\r\n";
         $body .= file_get_contents($data[$this->alias]['file']['tmp_name']) . "\r\n";
         $body .= "\r\n";
         $body .= "--{$boundaryString}--\r\n";
     }
     $this->request = array('uri' => array('host' => 'docs.google.com', 'path' => '/feeds/documents/private/full'), 'header' => array('Content-Type' => $mainContentType, 'Slug' => $data[$this->alias]['title']), 'auth' => array('method' => 'OAuth'), 'body' => $body);
     $result = parent::save($data, $validate, $fieldList);
     if ($result) {
         // In Google's documentation it looks like there should be a gd:resourceId node, but it appears
         // as simply resourceId to us. Keep an eye on this.
         if (empty($this->response['entry']['resourceId'])) {
             trigger_error('No resourceId from google.');
             return false;
         }
         $this->setInsertID($this->response['entry']['resourceId']);
     }
     return $result;
 }
 public function save($data = null, $validate = true, $fieldList = array())
 {
     $contact = new DOMDocument('1.0', 'utf-8');
     $entry = $contact->createElementNS('http://www.w3.org/2005/Atom', 'atom:entry');
     $entry->setAttribute('gd:etag', $data['entry']['gd:etag']);
     $entry->setAttribute('xmlns:gContact', 'http://schemas.google.com/contact/2008');
     $id = $contact->createElement('id', $data['entry']['id']);
     $entry->appendChild($id);
     $category = $contact->createElement('atom:category');
     $category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
     $category->setAttribute('term', 'http://schemas.google.com/docs/2007#contact');
     $entry->appendChild($category);
     if (isset($data['entry']['email'])) {
         $emails = $data['entry']['email'];
         if (!isset($emails['0'])) {
             $emails = array($emails);
         }
         // title
         $title = $contact->createElement('atom:title', $data['entry']['title']);
         $entry->appendChild($title);
         // name
         $name = $contact->createElement('gd:name');
         $fullName = $contact->createElement('gd:fullName', $data['entry']['title']);
         $name->appendChild($fullName);
         $entry->appendChild($name);
         // organization
         if (!empty($data['entry']['organization'])) {
             $organization = $contact->createElement('gd:organization');
             $organization->setAttribute('rel', 'http://schemas.google.com/g/2005#other');
             if (isset($data['entry']['organization']['orgName'])) {
                 $orgName = $contact->createElement('gd:orgName', $data['entry']['organization']['orgName']);
                 $organization->appendChild($orgName);
             }
             if (isset($data['entry']['organization']['orgTitle'])) {
                 $orgTitle = $contact->createElement('gd:orgTitle', $data['entry']['organization']['orgTitle']);
                 $organization->appendChild($orgTitle);
             }
             $entry->appendChild($organization);
         }
         // emails
         foreach ($emails as $email) {
             $element = $contact->createElementNS('http://schemas.google.com/g/2005', 'gd:email');
             //$contact->createElement('gd:email');
             // address
             $element->setAttribute('address', $email['address']);
             // rel
             if (isset($email['rel'])) {
                 $element->setAttribute('rel', $email['rel']);
             } else {
                 $element->setAttribute('rel', 'http://schemas.google.com/g/2005#other');
             }
             // primary
             if (!empty($email['primary'])) {
                 $element->setAttribute('primary', true);
             }
             $entry->appendChild($element);
         }
         // phoneNumbers
         if (!empty($data['entry']['phoneNumber'])) {
             $phoneNumbers = $data['entry']['phoneNumber'];
             foreach ($phoneNumbers as $phoneNumber) {
                 $element = $contact->createElement('gd:phoneNumber', $phoneNumber['value']);
                 // rel
                 if (isset($phoneNumber['rel'])) {
                     $element->setAttribute('rel', $phoneNumber['rel']);
                 } else {
                     $element->setAttribute('rel', 'http://schemas.google.com/g/2005#other');
                 }
                 $entry->appendChild($element);
             }
         }
         // IMs
         if (!empty($data['entry']['im'])) {
             $ims = $data['entry']['im'];
             foreach ($ims as $im) {
                 $element = $contact->createElement('gd:im');
                 if (isset($im['rel'])) {
                     $element->setAttribute('rel', $im['rel']);
                 }
                 if (isset($im['address'])) {
                     $element->setAttribute('address', $im['address']);
                 }
                 if (isset($im['protocol'])) {
                     $element->setAttribute('protocol', $im['protocol']);
                 }
                 $entry->appendChild($element);
             }
         }
         // groups
         if (!empty($data['entry']['groupMembershipInfo'])) {
             $groupMembershipInfo = $data['entry']['groupMembershipInfo'];
             foreach ($groupMembershipInfo as $group) {
                 $element = $contact->createElement('gContact:groupMembershipInfo');
                 // deleted
                 $element->setAttribute('deleted', 'false');
                 // href
                 if (isset($group['href'])) {
                     $element->setAttribute('href', $group['href']);
                 }
                 $entry->appendChild($element);
             }
         }
     }
     $contact->appendChild($entry);
     $body = $contact->saveXML();
     $entryIdE = explode('base/', $data['entry']['id']);
     $contactId = $entryIdE['1'];
     $this->request = array('uri' => array('host' => 'www.google.com', 'path' => 'm8/feeds/contacts/default/full/' . $contactId), 'method' => 'PUT', 'header' => array('Content-Type' => 'application/atom+xml', 'Slug' => $data['entry']['title'], 'If-Match' => $data['entry']['gd:etag']), 'auth' => array('method' => 'OAuth'), 'body' => $body);
     $result = parent::save($data, $validate, $fieldList);
     /*if ($result){
     			// In Google's documentation it looks like there should be a gd:resourceId node, but it appears
     			// as simply resourceId to us. Keep an eye on this.
     			if(empty($this->response['entry']['id'])) {
     				trigger_error('No contact id from google.');
     				return false;
     			}
     			$this->setInsertID($this->response['entry']['id']);
     		}*/
     return $result;
 }
 public function save($data = null, $validate = true, $fieldList = array())
 {
     $contactGroup = new DOMDocument('1.0', 'utf-8');
     $entry = $contactGroup->createElementNS('http://www.w3.org/2005/Atom', 'atom:entry');
     if (isset($data['entry']['gd:etag'])) {
         $entry->setAttribute('gd:etag', $data['entry']['gd:etag']);
     }
     if (isset($data['entry']['id'])) {
         $idEl = $contactGroup->createElement('id', $data['entry']['id']);
         $entry->append($idEl);
     }
     $category = $contactGroup->createElement('atom:category');
     $category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
     $category->setAttribute('term', 'http://schemas.google.com/contact/2008#group');
     $entry->appendChild($category);
     $title = $contactGroup->createElement('atom:title', $data['entry']['title']);
     $title->setAttribute('type', 'text');
     $entry->appendChild($title);
     if (isset($data['entry']['content'])) {
         $content = $contactGroup->createElement('content', $data['entry']['content']);
         $content->setAttribute('type', 'text');
         $entry->appendChild($content);
     }
     $path = null;
     $method = null;
     $header = array('Content-Type' => 'application/atom+xml', 'Slug' => $data['entry']['title']);
     if (isset($data['entry']['link'])) {
         foreach ($data['entry']['link'] as $link) {
             if (isset($link['rel']) && $link['rel'] == 'edit') {
                 $path = $link['href'];
                 $method = 'PUT';
                 $header['If-Match'] = $data['gd:etag'];
             }
             $linkEl = $contactGroup->createElement('link');
             $linkEl->setAttribute('rel', $link['rel']);
             $linkEl->setAttribute('type', $link['type']);
             $linkEl->setAttribute('href', $link['href']);
             $entry->appendChild($linkEl);
         }
     }
     $contactGroup->appendChild($entry);
     $body = $contactGroup->saveXML();
     if (!$path) {
         $path = 'm8/feeds/groups/' . $data['email'] . '/full';
         $method = 'POST';
     }
     $this->request = array('uri' => array('host' => 'www.google.com', 'path' => $path), 'method' => $method, 'header' => $header, 'auth' => array('method' => 'OAuth'), 'body' => $body);
     $result = parent::save($data, $validate, $fieldList);
     return $result;
 }