Share Code get link picasa 2015

Share Code get link picasa 2015

<form action="" method="post">
<input type="url" name="link" placeholder="Paste link picasa vao day">
<input type="submit" value="Get link">
</form>
<?php
error_reporting(E_ERROR | E_PARSE);
// Code ko phải của mình làm mình copy của bạn Bảo Sora và thêm vào 1 đoạn để get đc link upload bên photos
$url = $_POST[link];
//cURL để view mã nguồn của trang
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; rv:27.3) Gecko/20130101 Firefox/27.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
return curl_exec($ch);
}
function GetPicasa($url) {
$is_aut = explode('#',$url);
$id_ep=$is_aut[1];
$url=curl($url);
if($id_ep) {
$url=explode('"gphoto$id":"'.$id_ep,$url);
$url = explode('"media":{"content":[', $url[1]);
}
else {
$url = explode('"media":{"content":[', $url);
}
$url = explode('],"', $url[1]); $url =$url[0];
return $url;
}
$url = GetPicasa($url);
if(isset($url)) {
$gach = explode('{"url":"', ($id)?$gach[7]:$url);
$v360p = urldecode(reset(explode('"', $gach[2])));
$v720p = urldecode(reset(explode('"', $gach[3])));
$v1080p = urldecode(reset(explode('"', $gach[4])));
if(strpos($v1080p, 'itag=37') || strpos($v1080p, '=m37')){
echo '<br><font color="red">1080p:</font> '.$v1080p.'<br><font color="red">720p:</font> '.$v720p.'<br><font color="red">360p:</font> '.$v360p;
} elseif(strpos($v720p, 'itag=22') || strpos($v720p, '=m22')){
echo '<br><font color="red">720p:</font> '.$v720p.'<br><font color="red">360p:</font> '.$v360p;
} else {
echo '<br><font color="red">360p:</font> '.$v360p;
}
}
?>

Download ZIP

Thêm nữa nè
<?php
// $Id$
/**
 * @file
 * The picasa photo module for picasa web albums and Drupal integration.  This
 * module Handles creating, editing, updating, deleting and importing photo
 * content from picasa.
 */
/**
* Builds the XML string that gets submitted to the Picasa API when inserting and
* updating an album.
*
* @param object $node
* @param object $existing
*/
function _picasa_photo_build_entry($node, $existing = NULL) {
  $xml = "<?xml version='1.0' encoding='UTF-8'?>";
  $xml .= "<entry xmlns='http://www.w3.org/2005/Atom' ".
    "xmlns:exif='http://schemas.google.com/photos/exif/2007' ".
    "xmlns:geo='http://www.w3.org/2003/01/geo/wgs84_pos#' ".
    "xmlns:gml='http://www.opengis.net/gml' ".
    "xmlns:georss='http://www.georss.org/georss' ".
    "xmlns:batch='http://schemas.google.com/gdata/batch' ".
    "xmlns:media='http://search.yahoo.com/mrss/' ".
    "xmlns:gphoto='http://schemas.google.com/photos/2007'>";
  $xml .= "<title type='text'>$node->title</title>";
  $xml .= "<summary type='text'>$node->summary</summary>";
  $xml .= "<category scheme='http://schemas.google.com/g/2005#kind' ".
    "term='http://schemas.google.com/photos/2007#photo'></category>";
  // If we are dealing with an update then an existing gphoto:id needs to be
  // passed in
  if(!empty($existing)) {
    $xml .= '<gphoto:id>'. $existing->gphoto['id'] .'</gphoto:id>';
  }
  if(isset($node->place)) {
    $xml .= "<gphoto:location>$node->place</gphoto:location>";
  }
  $xml .= "<gphoto:access>$node->gphoto_access</gphoto:access>";
  $xml .= "<gphoto:timestamp>".
    _picasa_time($node->gphoto_timestamp, 'milliseconds') ."</gphoto:timestamp>";
  if ($node->comment == 2) {
    $commenting_enabled = 'true';
  }
  else {
    $commenting_enabled = 'false';
  }
  $xml .= "<gphoto:commentingEnabled>$commenting_enabled</gphoto:commentingEnabled>";
  if (!empty($node->lat) && !empty($node->lng)) {
      $xml .= "<georss:where><gml:Point><gml:pos>$node->lat $node->lng".
        "</gml:pos></gml:Point></georss:where>";
  }
  $xml .= "</entry>";
/*  $xml = '<entry xmlns=\'http://www.w3.org/2005/Atom\'><title>'. $node->title
    .'</title><summary>'. $node->summary .'</summary>'
    .'<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo"/></entry>';
*/  return $xml;
}

/**
 * Implementation of hook_node_info().
 */
function picasa_photo_node_info() {
  return array(
    'picasa_photo' => array(
      'name' => t('Picasa Photo'),
      'module' => 'picasa_photo',
      'description' => t("The Picasa Photo is an image that is stored in Picasa Albums."),
      'has_title' => TRUE,
      'title_label' => t('Title'),
      'has_body' => TRUE,
      'body_label' => t('Summary'),
    )
  );
}
/**
 * Implementation of hook_access().
 */
function picasa_photo_access($op, $node, $account) {
  if ($op == 'create') {
    return user_access('create picasa photo', $account);
  }
  if ($op == 'update') {
    if (user_access('edit any picasa photo', $account) || (user_access('edit own picasa photo', $account) && ($account->uid == $node->uid))) {
      return TRUE;
    }
  }
  if ($op == 'delete') {
    if (user_access('delete any picasa photo', $account) || (user_access('delete own picasa photo', $account) && ($account->uid == $node->uid))) {
      return TRUE;
    }
  }
}
/**
 * Implementation of hook_perm().
 */
function picasa_photo_perm() {
  return array(
    'create picasa photo',
    'delete own picasa photo',
    'delete any picasa photo',
    'edit own picasa photo',
    'edit any picasa photo',
  );
}
/**
 * Implementation of hook_form().
 */
function picasa_photo_form(&$node) {
  // Require the user to be authenticated with google
  google_auth_required();
  $form['#attributes'] = array('enctype' => "multipart/form-data");

  $form['picasa'] = array(
    '#type' => 'fieldset',
    '#title' => t('Picasa Album'),
    '#weight' => -5,
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  // Get available albums
  _picasa_album_get_select($form);
  $form['picasa']['upload'] = array(
    '#type' => 'file',
    '#title' => t('Select photo to upload'),
    '#size' => 40,
  );
  $type = node_get_types('type', $node);
  $form['picasa']['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
  );
  $form['picasa']['summary'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($type->body_label),
    '#description' => t('A description of the image'),
    '#required' => FALSE,
    '#default_value' => $node->summary,
  );
    $form['picasa']['place'] = array('#type' => 'hidden', '#default_value' => $node->gphoto['location'] );
    // Set default latitude and longitude if they exist on the node use their values.
    // The following fields are primarily used to interact with the google map on
    // the entry and edit forms
    $msg = t("Please enter a location in the 'Place Taken' field and press the 'Search' button.  Click on the search results to set your position on the map.  Once positioned, you can drag the pointer for greater accuracy.");
    $output = '<div id="edit-where-wrapper" class="form-item"><label for="edit-where">';
    $output .= t('Place Taken') .': <span id="picasa_place_title"></div></label><div id="searchform"></div><div id="picasa_gmap">';
    $output .= '</div><div id="placelist"><div id="results"><div id="searchwell">'. $msg;
    $output .= '</div></div><div id="map"></div></div>';
    $form['picasa']['search'] = array(
      '#value' => $output
      );
    $lat = NULL;
    $lng = NULL;
    if (isset($node->geo_rss) && !empty($node->geo_rss)) {
      $coords = explode(' ', $node->geo_rss['point']);
      $lat = $coords[0];
      $lng = $coords[1];
    }
    $form['picasa']['lat'] = array('#type' => 'hidden', '#default_value' => $lat);
    $form['picasa']['lng'] = array('#type' => 'hidden', '#default_value' => $lng);
    $form['picasa']['request'] = array('#type' => 'hidden');
  _picasa_delete_buttons($form, $node);
  return $form;
}
/**
 * Implementation of hook_insert()
 */
function picasa_photo_insert($node) {
  if(isset($node->upload)) {
    $file = file_save_upload('upload');
    $xml = _picasa_photo_build_entry($node);
    $feed = "http://picasaweb.google.com/data/feed/api/user/default/albumid/$node->album";
    $data = "Media multipart posting\r\n";
    $data .= "--END_OF_PART\r\n";
    $data .= "Content-Type: application/atom+xml\r\n";
    $data .= "\r\n";
    $data .= "$xml\r\n";
    $data .= "--END_OF_PART\r\n";
    $data .= "Content-Type: $file->filemime\r\n";
    $data .= "\r\n";
    $fr = fopen($file->filepath, 'rb');
    while (!feof($fr)) {
      $data .= fread($fr, 8192);
    }
    $data .= "\r\n";
    $data .= "--END_OF_PART--";
    $headers['Authorization'] = 'AuthSub token="'. $_SESSION['google_auth_token'] .'"';
    $headers['Slug'] = $node->title;
    $headers['Content-Type'] = 'multipart/related; boundary="END_OF_PART"';
    $node->request = drupal_http_request($feed, $headers, 'POST', $data);
    file_delete($file->filepath);
    $data = (object)_picasa_parse($node->request->data);
  }
  else {
    $headers['Authorization'] = 'AuthSub token="'. $_SESSION['google_auth_token'] .'"';
    $headers['Content-Type'] = 'application/atom+xml; charset=UTF-8';
    $request = drupal_http_request($node->id, $headers, 'GET');
    $data = (object)_picasa_parse($request->data);
  }
  _picasa_insert($node, $data);
  _picasa_insert_link($node, $data);
  _picasa_insert_media($node, $data);
  _picasa_insert_georss($node, $data);
  _picasa_insert_gphoto($node, $data);
}
/**
 * Implementation of hook_delete().
 */
function picasa_photo_delete($node) {
  db_query("DELETE from {picasa} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_link} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_media} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_geo_rss} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_gphoto} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_thumbnail} WHERE nid = %d", $node->nid);
}
/**
 * Implementation of hook_theme().
 */
function picasa_photo_theme($existing, $type, $theme, $path) {
  return array(
    'picasa_photo_node_form' => array(
      'function' => 'theme_picasa_photo_node_form',
      'arguments' => array('form' => NULL),
    ),
    'picasa_photo' => array(
      'template' => 'picasa-photo',
      'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
    ),
  );
}
/**
 * Themes the node add and edit form.  Primarily adds the necessary JavaScript
 * and data to display a gui to allow for geotagging and searching of georss
 * data.
 * @param array $form (required) Contains the form that is being themed.
 * @return string The themed form.
*/
function theme_picasa_photo_node_form(&$form) {
  global $albums;
  if(count($albums) == 0) {
    $albums = _picasa_album_request();
    foreach ($albums['entry'] as $id => $entry) {
      $existing = db_fetch_object(db_query("SELECT id FROM {picasa} WHERE id LIKE '%%%s'", $id));
      if (isset($existing->id)) {
        unset($albums['entry'][$id]);
      }
    }
  }
  $output = '';
  if(arg(3) != 'import') {
    drupal_set_html_head("<script src=\"http://www.google.com/jsapi?key=". variable_get('google_ajaxfeeds_key', '') ."\" type=\"text/javascript\"></script>");
    drupal_add_js(drupal_get_path('module', 'picasa_album') .'/picasa_album_gmap.js');
    drupal_add_css(drupal_get_path('module', 'picasa_album') .'/picasa_album_gmap.css');
  }
  else {
    $output .= drupal_render($form['create']);
    $entries = $albums['entry'];
    $header = array(
        array(),
        array('data' => t('Thumbnail'), 'style' => 'text-align: center;'),
        array('data' => t('Album Information'), 'style' => 'text-align: center; width: 100%')
    );
    $rows = array();
    foreach ($entries as $k => $entry) {
        $row = array(
            drupal_render($form['albums'][$k]),
            array('data' => theme('picasa_image', $entry['media'][0]['thumbnail'][0])),
            array('data' => theme('picasa_album_admin_data', $entry), 'style' => 'width: 100%;')
        );
        $rows[] = $row;
    }
    $output .= theme('table', $header, $rows);
  }
  unset($form['buttons']['delete']);
  unset($form['buttons']['preview']);
  $output .= drupal_render($form);
  return $output;
}
function picasa_photo_load($node) {
  $picasa_photo =  _picasa_load($node);
  preg_match('/(.*?)\/photoid/', $picasa_photo->id, $matches);
  $album = db_fetch_object(db_query("SELECT nid from {picasa} WHERE id = '%s'", $matches[1]));
  $picasa_photo->album_nid = $album->nid;
  return $picasa_photo;
}
/**
* Process variables for picasa-user.tpl.php.
*
* @see picasa-user.tpl.php
* @see theme_comment_folded()
*/
function template_preprocess_picasa_photo(&$variables) {
  drupal_add_css(drupal_get_path('module', 'picasa_photo') .'/picasa_photo.css');
  $node = $variables['node'];
  $variables['id'] = check_plain($node->id);
  $variables['published'] = check_plain($node->published);
  $variables['updated'] = format_date($node->updated);
  $variables['title'] = check_plain($node->title);
  $variables['summary'] = check_plain($node->summary);
  $variables['self'] = NULL;
  $variables['alternate'] = NULL;
  $variables['feed'] = NULL;
  if(is_array($node->link)) {
    foreach ($node->link as $link) {
      switch($link['rel']) {
        case 'self':
          $variables['self'] = check_plain($link['href']);
          break;
        case 'alternate':
          $variables['alternate'] = check_plain($link['href']);
          break;
        case 'http://schemas.google.com/g/2005#feed':
          $variables['feed'] = check_plain($link['href']);
          break;
      }
    }
  }
  $variables['thumbnail']['small'] = l(theme('picasa_image', $node->media[0]['thumbnail'][0]), "node/$node->nid", array('html' => TRUE));
  $variables['thumbnail']['medium'] = l(theme('picasa_image', $node->media[0]['thumbnail'][1]), "node/$node->nid", array('html' => TRUE));
  $variables['thumbnail']['large'] = l(theme('picasa_image', $node->media[0]['thumbnail'][2]), "node/$node->nid", array('html' => TRUE));
  $variables['keywords'] = check_plain($node->media[0]['keywords']);
  $variables['photo'] = theme('picasa_image', preg_replace('/entry/', 'media', $variables['id']));
  $variables['content_url'] = $node->media[0]['content_url'];
  $variables['content_type'] = $node->media[0]['content_type'];
  $variables['content_medium'] = $node->media[0]['content_medium'];
  $variables['credit'] = $node->media[0]['credit'];
  if(variable_get('picasa_slideshow', '') != 'hidden') {
    $album = node_load($node->album_nid);
    if(is_array($album->link)) {
      foreach ($album->link as $link) {
        switch($link['rel']) {
          case 'alternate':
            $album_alternate = check_plain($link['href']);
            break;
        }
      }
    }
    if(variable_get('picasa_slideshow', '') == 'embedded') {
      $variables['slideshow'] = l(t('View Slideshow'), $album_alternate .'#slideshow/'. $node->gphoto['id']);
    }
    else {
      $variables['slideshow'] = l(t('View Slideshow in new window'), $album_alternate .'#slideshow/'. $node->gphoto['id'], array('attributes' => array('target' => '_blank')));
    }
  }
  $variables['album_link'] = l(t('View Album'), 'node/'. $album->nid);
  $variables['geo_rss'] = $node->geo_rss;
}
/**
 * Implementation of hook_view().
 */
function picasa_photo_view($node, $teaser = FALSE, $page = FALSE) {
  $node = node_prepare($node, $teaser);
  $node->content['picasa_photo'] = array(
    '#value' => theme('picasa_photo', $node, $teaser, $page),
    '#weight' => 1,
  );
  return $node;
}
function _picasa_photo_synchronize($photo) {
  global $user;
  // Create a node if one does not already exist
  $node = new stdClass();
  $node = db_fetch_object(db_query("SELECT nid from {picasa} WHERE id = '%s'", $photo['id']));
  if(isset($node->nid)) {
    $node = node_load(array('nid' => $node->nid));
  }
  else {
     $node->type = 'picasa_photo';
     $node->uid = $user->uid;
     $node->title = $photo['title'];
     $node->id = $photo['id'];
  }
  node_save($node);
}


Tiếp

<?php
/**
 * @file
 * The picasa photo module for picasa web albums and Drupal integration.  This
 * module Handles creating, editing, updating, deleting and importing photo
 * content from picasa.
 */
/**
* Builds the XML string that gets submitted to the Picasa API when inserting and
* updating an album.
*
* @param object $node
* @param object $existing
*/
function _picasa_photo_build_entry($node, $existing = NULL) {
  $xml = "<?xml version='1.0' encoding='UTF-8'?>";
  $xml .= "<entry xmlns='http://www.w3.org/2005/Atom' ".
    "xmlns:exif='http://schemas.google.com/photos/exif/2007' ".
    "xmlns:geo='http://www.w3.org/2003/01/geo/wgs84_pos#' ".
    "xmlns:gml='http://www.opengis.net/gml' ".
    "xmlns:georss='http://www.georss.org/georss' ".
    "xmlns:batch='http://schemas.google.com/gdata/batch' ".
    "xmlns:media='http://search.yahoo.com/mrss/' ".
    "xmlns:gphoto='http://schemas.google.com/photos/2007'>";
  $xml .= "<title type='text'>$node->title</title>";
  $xml .= "<summary type='text'>$node->summary</summary>";
  $xml .= "<category scheme='http://schemas.google.com/g/2005#kind' ".
    "term='http://schemas.google.com/photos/2007#photo'></category>";
  // If we are dealing with an update then an existing gphoto:id needs to be
  // passed in
  if(!empty($existing)) {
    $xml .= '<gphoto:id>'. $existing->gphoto['id'] .'</gphoto:id>';
  }
  if(isset($node->place)) {
    $xml .= "<gphoto:location>$node->place</gphoto:location>";
  }
  $xml .= "<gphoto:access>$node->gphoto_access</gphoto:access>";
  $xml .= "<gphoto:timestamp>".
    _picasa_time($node->gphoto_timestamp, 'milliseconds') ."</gphoto:timestamp>";
  if ($node->comment == 2) {
    $commenting_enabled = 'true';
  }
  else {
    $commenting_enabled = 'false';
  }
  $xml .= "<gphoto:commentingEnabled>$commenting_enabled</gphoto:commentingEnabled>";
  if (!empty($node->lat) && !empty($node->lng)) {
      $xml .= "<georss:where><gml:Point><gml:pos>$node->lat $node->lng".
        "</gml:pos></gml:Point></georss:where>";
  }
  $xml .= "</entry>";
  return $xml;
}

/**
 * Implementation of hook_node_info().
 */
function picasa_photo_node_info() {
  return array(
    'picasa_photo' => array(
      'name' => t('Picasa Photo'),
      'module' => 'picasa_photo',
      'description' => t("The Picasa Photo is an image that is stored in Picasa Albums."),
      'has_title' => TRUE,
      'title_label' => t('Title'),
      'has_body' => TRUE,
      'body_label' => t('Summary'),
    )
  );
}
/**
 * Implementation of hook_access().
 */
function picasa_photo_access($op, $node, $account) {
  if ($op == 'create') {
    return user_access('create picasa photo', $account);
  }
  if ($op == 'update') {
    if (user_access('edit any picasa photo', $account) || (user_access('edit own picasa photo', $account) && ($account->uid == $node->uid))) {
      return TRUE;
    }
  }
  if ($op == 'delete') {
    if (user_access('delete any picasa photo', $account) || (user_access('delete own picasa photo', $account) && ($account->uid == $node->uid))) {
      return TRUE;
    }
  }
}
/**
 * Implementation of hook_perm().
 */
function picasa_photo_perm() {
  return array(
    'create picasa photo',
    'delete own picasa photo',
    'delete any picasa photo',
    'edit own picasa photo',
    'edit any picasa photo',
  );
}
/**
 * Implementation of hook_form().
 */
function picasa_photo_form(&$node) {
  // Require the user to be authenticated with google
  $google_auth->scope = 'http://picasaweb.google.com/data/';
  google_auth_required($google_auth);
  $form['#attributes'] = array('enctype' => "multipart/form-data");
  $form['picasa'] = array(
    '#type' => 'fieldset',
    '#title' => t('Picasa Photo'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  // Get available albums
  _picasa_album_get_select($form);
  $form['picasa']['upload'] = array(
    '#type' => 'file',
    '#title' => t('Select photo to upload'),
    '#size' => 40,
  );
  if(isset($node->media)) {
    $form['picasa']['upload_preview'] = array(
      '#value' => '<img src="'. $node->media[0]['thumbnail'][1]['url'].'" width="'. $node->media[0]['thumbnail'][1]['width'].'" height="'. $node->media[0]['thumbnail'][1]['height'].'" />',
      '#weight' => -4,
    );
  }
  $type = node_get_types('type', $node);
  $form['picasa']['title'] = array(
    '#type' => 'textfield',
    '#title' => check_plain($type->title_label),
    '#required' => TRUE,
    '#default_value' => $node->title,
  );
  $form['picasa']['summary'] = array(
    '#type' => 'textarea',
    '#title' => check_plain($type->body_label),
    '#description' => t('A description of the image'),
    '#required' => FALSE,
    '#default_value' => $node->summary,
  );
    $form['picasa']['place'] = array('#type' => 'hidden', '#default_value' => $node->gphoto['location'] );
    // Set default latitude and longitude if they exist on the node use their values.
    // The following fields are primarily used to interact with the google map on
    // the entry and edit forms
    $msg = t("Please enter a location in the 'Place Taken' field and press the 'Search' button.  Click on the search results to set your position on the map.  Once positioned, you can drag the pointer for greater accuracy.");
    $output = '<div id="edit-where-wrapper" class="form-item"><label for="edit-where">';
    $output .= t('Place Taken') .': <span id="picasa_place_title"></div></label><div id="searchform"></div><div id="picasa_gmap">';
    $output .= '</div><div id="placelist"><div id="results"><div id="searchwell">'. $msg;
    $output .= '</div></div><div id="map"></div></div>';
    $form['picasa']['search'] = array(
      '#value' => $output
      );
    $lat = NULL;
    $lng = NULL;
    if (isset($node->geo_rss) && !empty($node->geo_rss)) {
      $coords = explode(' ', $node->geo_rss['point']);
      $lat = $coords[0];
      $lng = $coords[1];
    }
    $form['picasa']['lat'] = array('#type' => 'hidden', '#default_value' => $lat);
    $form['picasa']['lng'] = array('#type' => 'hidden', '#default_value' => $lng);
    $form['picasa']['request'] = array('#type' => 'hidden');
  _picasa_delete_buttons($form, $node);
  return $form;
}
/**
 * Implementation of hook_insert()
 */
function picasa_photo_insert($node) {
  if(isset($node->upload)) {
    $file = file_save_upload('upload');
    $xml = _picasa_photo_build_entry($node);
    $feed = "http://picasaweb.google.com/data/feed/api/user/default/albumid/$node->album";
    $data = "Media multipart posting\r\n";
    $data .= "--END_OF_PART\r\n";
    $data .= "Content-Type: application/atom+xml\r\n";
    $data .= "\r\n";
    $data .= "$xml\r\n";
    $data .= "--END_OF_PART\r\n";
    $data .= "Content-Type: $file->filemime\r\n";
    $data .= "\r\n";
    $fr = fopen($file->filepath, 'rb');
    while (!feof($fr)) {
      $data .= fread($fr, 8192);
    }
    $data .= "\r\n";
    $data .= "--END_OF_PART--";
    $headers['Authorization'] = 'AuthSub token="'. $_SESSION['google_auth_token'] .'"';
    $headers['Slug'] = $node->title;
    $headers['Content-Type'] = 'multipart/related; boundary="END_OF_PART"';
    $node->request = drupal_http_request($feed, $headers, 'POST', $data);
    file_delete($file->filepath);
    $data = (object)_picasa_parse($node->request->data);
  }
  else {
    $headers['Authorization'] = 'AuthSub token="'. $_SESSION['google_auth_token'] .'"';
    $headers['Content-Type'] = 'application/atom+xml; charset=UTF-8';
    $request = drupal_http_request($node->id, $headers, 'GET');
    $data = (object)_picasa_parse($request->data);
  }
  _picasa_insert($node, $data);
  _picasa_insert_link($node, $data);
  _picasa_insert_media($node, $data);
  _picasa_insert_georss($node, $data);
  _picasa_insert_gphoto($node, $data);
}
/**
 * Implementation of hook_delete().
 */
function picasa_photo_delete($node) {
  db_query("DELETE from {picasa} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_link} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_media} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_geo_rss} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_gphoto} WHERE nid = %d", $node->nid);
  db_query("DELETE from {picasa_thumbnail} WHERE nid = %d", $node->nid);
}
/**
 * Implementation of hook_theme().
 */
function picasa_photo_theme($existing, $type, $theme, $path) {
  return array(
    'picasa_photo_node_form' => array(
      'function' => 'theme_picasa_photo_node_form',
      'arguments' => array('form' => NULL),
    ),
    'picasa_photo' => array(
      'template' => 'picasa-photo',
      'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
    ),
  );
}
/**
 * Themes the node add and edit form.  Primarily adds the necessary JavaScript
 * and data to display a gui to allow for geotagging and searching of georss
 * data.
 * @param array $form (required) Contains the form that is being themed.
 * @return string The themed form.
*/
function theme_picasa_photo_node_form(&$form) {
  global $albums;
  if(count($albums) == 0) {
    $albums = _picasa_album_request();
    foreach ($albums['entry'] as $id => $entry) {
      $existing = db_fetch_object(db_query("SELECT id FROM {picasa} WHERE id LIKE '%%%s'", $id));
      if (isset($existing->id)) {
        unset($albums['entry'][$id]);
      }
    }
  }
  $output = '';
    drupal_set_html_head("<script src=\"http://www.google.com/jsapi?key=". variable_get('google_ajaxfeeds_key', '') ."\" type=\"text/javascript\"></script>");
    drupal_add_js(drupal_get_path('module', 'picasa_album') .'/picasa_album_gmap.js');
    drupal_add_css(drupal_get_path('module', 'picasa_album') .'/picasa_album_gmap.css');
  unset($form['buttons']['delete']);
  unset($form['buttons']['preview']);
  $output .= drupal_render($form);
  return $output;
}
function picasa_photo_load($node) {
  $picasa_photo =  _picasa_load($node);
  preg_match('/(.*?)\/photoid/', $picasa_photo->id, $matches);
  $album = db_fetch_object(db_query("SELECT nid from {picasa} WHERE id = '%s'", $matches[1]));
  $picasa_photo->album_nid = $album->nid;
  return $picasa_photo;
}
/**
* Process variables for picasa-user.tpl.php.
*
* @see picasa-user.tpl.php
* @see theme_comment_folded()
*/
function template_preprocess_picasa_photo(&$variables) {
  drupal_add_css(drupal_get_path('module', 'picasa_photo') .'/picasa_photo.css');
  $node = $variables['node'];
  $variables['id'] = check_plain($node->id);
  $variables['published'] = check_plain($node->published);
  $variables['updated'] = format_date($node->updated);
  $variables['title'] = check_plain($node->title);
  $variables['summary'] = check_plain($node->summary);
  $variables['self'] = NULL;
  $variables['alternate'] = NULL;
  $variables['feed'] = NULL;
  if(is_array($node->link)) {
    foreach ($node->link as $link) {
      switch($link['rel']) {
        case 'self':
          $variables['self'] = check_plain($link['href']);
          break;
        case 'alternate':
          $variables['alternate'] = check_plain($link['href']);
          break;
        case 'http://schemas.google.com/g/2005#feed':
          $variables['feed'] = check_plain($link['href']);
          break;
      }
    }
  }
//  $variables['thumbnail']['small'] = l(theme('picasa_image', $node->media[0]['thumbnail'][0]), "node/$node->nid", array('html' => TRUE));
//  $variables['thumbnail']['medium'] = l(theme('picasa_image', $node->media[0]['thumbnail'][1]), "node/$node->nid", array('html' => TRUE));
//  $variables['thumbnail']['large'] = l(theme('picasa_image', $node->media[0]['thumbnail'][2]), "node/$node->nid", array('html' => TRUE));
  $variables['keywords'] = check_plain($node->media[0]['keywords']);
//  if (isset($_GET['imgmax']) && _picasa_photo_validate_imgmax($_GET['imgmax'])) {
//    if ($_GET['imgmax'] != 'max') {
//      $variables['photo'] = $variables['images'][$_GET['imgmax']];
//    }
//  }
  if($variables['teaser']) {
    $variables['photo'] = l(theme('picasa_image', $node->media[0]['content_url']. '?imgmax='. variable_get('picasa_default_thumbnail_size', array('144'))), "node/$node->nid", array('html' => TRUE));
  }
  else {
    $variables['photo'] = theme('picasa_image', $node->media[0]['content_url']. '?imgmax='. variable_get('picasa_default_photo_size', array('640')));
  }
  $variables['content_url'] = $node->media[0]['content_url'];
  $variables['content_type'] = $node->media[0]['content_type'];
  $variables['content_medium'] = $node->media[0]['content_medium'];
  $variables['credit'] = $node->media[0]['credit'];
  if(variable_get('picasa_slideshow', '') != 'hidden') {
    $album = node_load($node->album_nid);
    if(is_array($album->link)) {
      foreach ($album->link as $link) {
        switch($link['rel']) {
          case 'alternate':
            $album_alternate = check_plain($link['href']);
            break;
        }
      }
    }
    if(variable_get('picasa_slideshow', '') == 'embedded') {
      $variables['slideshow'] = l(t('View Slideshow'), $album_alternate .'#slideshow/'. $node->gphoto['id']);
    }
    else {
      $variables['slideshow'] = l(t('View Slideshow in new window'), $album_alternate .'#slideshow/'. $node->gphoto['id'], array('attributes' => array('target' => '_blank')));
    }
  }
  $variables['album_link'] = l(t('View Album'), 'node/'. $album->nid);
  $variables['geo_rss'] = $node->geo_rss;
}
/**
 * Implementation of hook_view().
 */
function picasa_photo_view($node, $teaser = FALSE, $page = FALSE) {
  $node = node_prepare($node, $teaser);
  $node->content['picasa_photo'] = array(
    '#value' => theme('picasa_photo', $node, $teaser, $page),
    '#weight' => 1,
  );
  return $node;
}
function _picasa_photo_synchronize($photo) {
  global $user;
  // Create a node if one does not already exist
  $node = new stdClass();
  $node = db_fetch_object(db_query("SELECT nid from {picasa} WHERE id = '%s'", $photo['id']));
  if(isset($node->nid)) {
    $node = node_load(array('nid' => $node->nid));
  }
  else {
     $node->type = 'picasa_photo';
     $node->uid = $user->uid;
     $node->title = $photo['title'];
     $node->id = $photo['id'];
  }
  node_save($node);
}
function picasa_photo_display_size_form() {
  $form['#method'] = 'get';
  $form['imgmax'] = array(
    '#type' => 'select',
    '#title' => t('Image Size'),
    '#default_value' => $_GET['imgmax'],
    '#options' => array(
      '32' => t('32'),
      '48' => t('48'),
      '64' => t('64'),
      '72' => t('72'),
      '144' => t('144'),
      '160' => t('160'),
      '200' => t('200'),
      '288' => t('288'),
      '320' => t('320'),
      '400' => t('400'),
      '512' => t('512'),
      '576' => t('576'),
      '640' => t('640'),
      '720' => t('720'),
      '800' => t('800'),
      'max' => t('Original Size'),
    ),
  );
  $form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
  return $form;
}
function _picasa_photo_validate_imgmax($imgmax) {
  $valid_sizes = array(
    '32' => t('32'),
    '48' => t('48'),
    '64' => t('64'),
    '72' => t('72'),
    '144' => t('144'),
    '160' => t('160'),
    '200' => t('200'),
    '288' => t('288'),
    '320' => t('320'),
    '400' => t('400'),
    '512' => t('512'),
    '576' => t('576'),
    '640' => t('640'),
    '720' => t('720'),
    '800' => t('800'),
    'max' => t('Original Size'),
  );
  if (array_key_exists($imgmax, $valid_sizes)) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}

Get album

<?
function getPicasaAlbumList($user) {
$rss = "http://picasaweb.google.com/data/feed/api/user/$user/?kind=album&access=public&alt=rss";
$albums = array();
$file = implode('', file($rss));
$start = strpos($file, "<item>");
$end = strrpos($file, "</item>");
$substr = substr($file, $start, $end-$start+1);
$items = explode("<item>", $substr);
if(is_array($items) && count($items)>0) {
foreach($items as $tmp) {
if(trim($tmp) != "") {
$pubdate = getTagContent($tmp, "pubDate");
$title = getTagContent($tmp, "title");
$nums = getTagContent($tmp, "gphoto:numphotos");
$albumId = getTagContent($tmp, "gphoto:id");
$album['desc'] = getTagContent($tmp, "description");
$mediagroup = getTagContent($tmp, "media:group");
$thumbnail = getTagContent($mediagroup, "media:thumbnail");
$album['pubdate'] = $pubdate;
$album['title'] = $title;
$album['nums'] = $nums;
$album['albumId'] = $albumId;
$album['thumbnail'] = $thumbnail['url'];
array_push($albums, $album);
}
}
}
return $albums;
}
function getPicasaAlbum($user, $albumid) {
$rss = "http://picasaweb.google.com/data/feed/api/user/$user/albumid/$albumid?kind=photo&alt=rss&access=public&thumbsize=144c";
$album = array();
$file = implode('', file($rss));
$title = getTagContent($file, "title");
$date = getTagContent($file, "lastBuildDate");
$nums = getTagContent($file, "openSearch:totalResults");
$album['title'] = $title;
$album['date'] = $date;
$album['nums'] = $nums;
$album['desc'] = getTagContent($file, "description");
$photos = array();
$start = strpos($file, "<item>");
$end = strrpos($file, "</item>");
$substr = substr($file, $start, $end-$start+1);
$items = explode("<item>", $substr);
if(is_array($items) && count($items)>0) {
foreach($items as $tmp) {
if(trim($tmp) != "") {
$title = getTagContent($tmp, "title");
$photoid = getTagContent($tmp, "gphoto:id");
$mediagroup = getTagContent($tmp, "media:group");
$thumbnail = getTagContent($mediagroup, "media:thumbnail");
$photo['title'] = $title;
$photo['photoid'] = $photoid;
$photo['thumbnail'] = $thumbnail['url'];
array_push($photos, $photo);
}
}
}
$album['photos'] = $photos;
return $album;
}
function getPicasaPhoto($user, $albumid, $photoid) {
$rss = "http://picasaweb.google.com/data/feed/api/user/$user/albumid/$albumid/photoid/$photoid?alt=rss&thumbsize=288";
$photo = array();
$file = implode('', file($rss));
$photo['title'] = getTagContent($file, "title");;
$photo['date'] = getTagContent($file, "lastBuildDate");
$photo['desc'] = getTagContent($file, "description");
$photo['width'] = getTagContent($file, "gphoto:width");
$photo['height'] = getTagContent($file, "gphoto:height");
$photo['size'] = getTagContent($file, "gphoto:size");
$mediagroup = getTagContent($file, "media:group");
$image = getTagContent($mediagroup, "media:content");
$thumbnail = getTagContent($mediagroup, "media:thumbnail");
$photo['thumbnail'] = $thumbnail['url'];
$photo['url'] = $image['url']."?imgmax=720";
return $photo;
}
function getTagContent($src, $tag) {
$start = mb_strpos($src, "<".$tag.">");// + strlen($tag)+2;
if($start === false) {
$start = mb_strpos($src, "<".$tag) + strlen($tag)+1;
$end = mb_strpos($src, "/>", $start)-1;
$content = substr($src, $start, $end-$start+1);
$return = array();
$tmp = explode(' ', $content);
if(is_array($tmp) && count($tmp)>0) {
foreach($tmp as $line) {
if(trim($line)!="") {
$a = explode("=", $line);
$return[$a[0]] = str_replace("'", "", trim($a[1]));
}
}
}
} else {
$start+= strlen($tag)+2;
$end = mb_strpos($src, "</".$tag.">")-1;
$return = substr($src, $start, $end-$start+1);
}
return $return;
}
?> 

Đăng nhận xét

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
Site is Blocked
Sorry! This site is not available in your country.