Permalink
Browse files

changed how Insert queries are constructed to support new keys for in…

…sertUpdate
  • Loading branch information...
1 parent 6c4f963 commit f2f49b3bc27a470541afe9a268182ee023899eb4 @zagraves zagraves committed Jun 1, 2010
Showing with 28 additions and 5 deletions.
  1. +28 −5 lib/Yahoo/YahooOAuthApplication.class.php
@@ -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))
{
@@ -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);
@@ -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.