public static function show($objectId, $jsonLast = null) { $db = Core::getDb(); $user = Core::getUser(); $comments = array(); $qLast = $jsonLast ? "and c.id>" . $db->escape($jsonLast) : ""; $q = $db->buildQuery("SELECT c.id, c.body, o.ctime, u.id as local_user_id, o.user_id, c.user_connection_id, con.service, con.external_id\n FROM comments c\n LEFT JOIN objects o ON o.object_id=c.object_id\n LEFT JOIN connections con ON c.user_connection_id=con.id\n\t\t\tLEFT JOIN users u ON u.id=o.user_id\n WHERE c.in_reply_to_id=%d {$qLast}\n ORDER BY o.ctime ASC", $objectId); $rs = $db->query($q); if ($rs && $db->numrows($rs)) { while ($o = $db->fetchObject($rs)) { $commentAuthor = ObjectCache::getByType('\\Kiki\\User', $o->user_id ? $o->user_id : $o->local_user_id); if ($commentAuthor) { if ($o->external_id) { // HACK: should not always have to load this, but this is quicker than getStoredConnections for User 0 $connection = User\Factory::getInstance($o->service, $o->external_id, 0); // $connection = $commentAuthor->getConnection($o->service. "_". $o->external_id, true); if ($connection) { $serviceName = $connection->serviceName(); $name = $connection->name(); $pic = $connection->picture(); } else { $serviceName = 'None'; // SNH $name = $commentAuthor->name(); $pic = $commentAuthor->picture(); } } else { $serviceName = 'None'; // Kiki $name = $commentAuthor->name(); $pic = $commentAuthor->picture(); } } else { $serviceName = 'None'; $name = "Anonymous"; $pic = null; } if ($jsonLast !== null) { $comments[] = Comments::showSingle($objectId, $o->id, $name, $pic, $serviceName, $o->body, $o->ctime); } else { $comment = array('objectId' => $objectId, 'id' => $o->id, 'name' => $name, 'pic' => $pic, 'type' => $serviceName, 'body' => $o->body, 'ctime' => $o->ctime, 'dateTime' => date("c", strtotime($o->ctime)), 'relTime' => Misc::relativeTime($o->ctime)); $comments[] = $comment; } } } else { if ($jsonLast === null) { $comments[] = Comments::showDummy($objectId); } } if ($jsonLast !== null) { return $comments; } $template = new Template('parts/comments'); $template->assign('objectId', $objectId); $template->assign('comments', $comments); return $template->fetch(); }
public function identifyConnections() { if ($this->identifiedConnections) { Log::debug("not reidentifying, already did it.."); return; } // Identify third party users $this->identifiedConnections = array(); foreach (Config::$connectionServices as $service) { $oldClass = str_replace("Kiki\\User\\", "User_", $service); // Log::debug( "user factory for $service (oldClass: $oldClass)" ); $user = User\Factory::getInstance($service); if (!$user || !$user->externalId()) { continue; } if (!$user->token()) { Log::debug("identified {$service} but no token, don't actually add to identified"); continue; } $this->identifiedConnections[$user->uniqId()] = $user; } }
public final function likes() { $q = $this->db->buildQuery("SELECT external_id AS id FROM likes LEFT JOIN connections ON likes.user_connection_id=connections.id WHERE object_id=%d", $this->objectId); $likeUsers = $this->db->getObjectIds($q); $likes = array(); foreach ($likeUsers as $externalId) { $fbUser = User\Factory::getInstance('Facebook', $externalId); $likes[] = array('userName' => $fbUser->name(), 'serviceName' => 'Facebook', 'pictureUrl' => $fbUser->picture()); } return $likes; }