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 templateData() { $uAuthor = ObjectCache::getByType('\\Kiki\\User', $this->userId); $data = array('id' => $this->id, 'url' => $this->url(), 'ctime' => strtotime($this->ctime), 'relTime' => Misc::relativeTime($this->ctime), 'title' => $this->title(), 'body' => $this->body, 'author' => $uAuthor->name(), 'publications' => array(), 'likes' => $this->likes(), 'comments' => Comments::count($this->objectId), 'html' => array('comments' => Comments::show($this->objectId))); $publications = $this->publications(); foreach ($publications as $publication) { $data['publications'][] = $publication->templateData(); } return $data; }
public function templateData() { $uAuthor = ObjectCache::getByType('\\Kiki\\User', $this->userId); $prevArticle = $this->getPrev(); $nextArticle = $this->getNext(); $data = array('id' => $this->id, 'url' => $this->url(), 'ctime' => strtotime($this->ctime), 'relTime' => Misc::relativeTime($this->ctime), 'title' => $this->title, 'body' => $this->body, 'author' => $uAuthor->name(), 'images' => array(), 'publications' => array(), 'likes' => $this->likes(), 'comments' => Comments::count($this->objectId), 'html' => array('comments' => Comments::show($this->objectId), 'editform' => $this->form(true, 'articles'))); if ($nextArticle = $this->getNext()) { $data['next'] = array('id' => $nextArticle->id(), 'url' => $nextArticle->url(), 'title' => $nextArticle->title()); } if ($prevArticle = $this->getPrev()) { $data['prev'] = array('id' => $prevArticle->id(), 'url' => $prevArticle->url(), 'title' => $prevArticle->title()); } $publications = $this->publications(); foreach ($publications as $publication) { $data['publications'][] = $publication->templateData(); } $images = $this->images(); foreach ($images as $image) { $data['images'][] = Storage::url($image); } // print_r( $data['images'] ); return $data; }