Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
changed how Insert queries are constructed to support new keys for in…
Browse files Browse the repository at this point in the history
…sertUpdate
  • Loading branch information
zagraves committed Jun 1, 2010
1 parent 6c4f963 commit f2f49b3
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions lib/Yahoo/YahooOAuthApplication.class.php
Expand Up @@ -372,7 +372,7 @@ public function getUpdates($guid = null, $offset = 0, $limit = 10)
return isset($rsp->query->results) ? $rsp->query->results : false;
}

public function insertUpdate($guid = null, $description, $title, $link, &$suid = null)
public function insertUpdate($guid = null, $description, $title, $link, $image = null, &$suid = null)
{
if($guid == null && !is_null($this->token))
{
Expand All @@ -382,14 +382,33 @@ public function insertUpdate($guid = null, $description, $title, $link, &$suid =
if($suid == null)
{
// $suid = 'ugc'.rand(0, 1000);
$suid = sha1(uniqid(mt_rand()));
$suid = uniqid(mt_rand());
}

$source = 'APP.'.$this->application_id;
$pubDate = time();

$query = 'INSERT INTO social.updates (guid, title, description, link, pubDate, source, suid) VALUES ("%s", "%s", "%s", "%s", "%s", "%s", "%s");';
$query = sprintf($query, $guid, $title, $description, $link, $pubDate, $source, $suid);
$update = array(
'guid' => $guid,
'title' => $title,
'description' => $description,
'link' => $link,
'pubDate' => $pubDate,
'source' => $source,
'suid' => $suid
);

if($image) {
$update['imageURL'] = $image['url'];
$update['imageWidth'] = $image['width'];
$update['imageHeight'] = $image['height'];
}

$keys = implode(",", array_keys($update));
$values = implode(",", array_map('_yql_insert_quotes', array_values($update)));

$query = 'INSERT INTO social.updates (%s) VALUES (%s);';
$query = sprintf($query, $keys, $values);

$rsp = $this->yql($query, array(), YahooCurl::PUT);

Expand Down Expand Up @@ -455,5 +474,9 @@ public function yql($query, $parameters = array(), $method = YahooCurl::GET)

return json_decode($this->client->access_resource($oauth_request));
}

}

function _yql_insert_quotes($value)
{
return "'$value'";
}

0 comments on commit f2f49b3

Please sign in to comment.