/** * @param string $source * @param null|UserTable $user * @param int $direction * @return Comments|null */ public function replies( $source = 'stream', $user = null, $direction = 1 ) { $params = $this->params()->subTree( 'replies' ); if ( ! $params->get( 'display', 1 ) ) { return null; } /** @var Comments[] $cache */ static $cache = array(); $id = md5( $this->get( 'id' ) . $source . ( $user ? $user->get( 'id' ) : null ) . $direction . Application::MyUser()->getUserId() ); if ( ! isset( $cache[$id] ) ) { $stream = new Comments( $source, $user, $direction ); $stream->set( 'type', 'comment' ); $stream->set( 'item', (int) $this->get( 'id' ) ); $object = array( 'source' => 'comment', 'id' => (int) $this->get( 'id' ), 'user_id' => (int) $this->get( 'user_id' ), 'type' => $this->get( 'type' ), 'subtype' => $this->get( 'subtype' ), 'item' => $this->get( 'item' ), 'parent' => $this->get( 'parent' ) ); $stream->set( 'object', $object ); $cache[$id] = $stream; } return $cache[$id]; }
/** * Accessor: * Returns a field in specified format * * @param FieldTable $field * @param UserTable $user * @param string $output 'html', 'xml', 'json', 'php', 'csvheader', 'csv', 'rss', 'fieldslist', 'htmledit' * @param string $reason 'profile' for user profile view, 'edit' for profile edit, 'register' for registration, 'search' for searches * @param int $list_compare_types IF reason == 'search' : 0 : simple 'is' search, 1 : advanced search with modes, 2 : simple 'any' search * @return mixed */ public function getField( &$field, &$user, $output, $reason, $list_compare_types ) { $return = null; if ( $field->get( 'type' ) == 'comments' ) { $comments = new Comments( 'field', $user, (int) $field->params->get( 'field_comments_direction', 0 ) ); $comments->set( 'type', 'field' ); $comments->set( 'item', (int) $field->get( 'fieldid' ) ); $comments->set( 'parent', (int) $user->get( 'id' ) ); CBActivity::loadStreamDefaults( $comments, $field->params, 'field_comments_' ); $return = $comments->stream( false ); } else { $activity = new Activity( 'field', $user, (int) $field->params->get( 'field_activity_direction', 0 ) ); $activity->set( 'type', 'field' ); $activity->set( 'subtype', 'status' ); $activity->set( 'item', (int) $field->get( 'fieldid' ) ); $activity->set( 'parent', (int) $user->get( 'id' ) ); CBActivity::loadStreamDefaults( $activity, $field->params, 'field_activity_' ); $return = $activity->stream( false ); } if ( ! ( ( $output == 'html' ) && ( $reason == 'profile' ) ) ) { return null; } return $this->formatFieldValueLayout( $this->_formatFieldOutput( $field->get( 'name' ), $return, $output, false ), $reason, $field, $user ); }
/** * Displays comments stream * * @param int $id * @param Comments $stream * @param int $output * @param bool $data * @param UserTable $user * @param UserTable $viewer */ private function showComments( $id, $stream, $output, $data, $user, $viewer ) { CBActivity::getTemplate( 'comments', false, false ); if ( $id ) { $stream->set( 'id', $id ); $stream->set( 'limitstart', 0 ); $stream->set( 'limit', 0 ); $stream->set( 'paging', 0 ); $rows = $stream->data(); } else { if ( $data ) { $count = $stream->data( true ); if ( ! $count ) { $rows = array(); } else { $rows = $stream->data(); if ( $count <= ( $stream->get( 'limitstart' ) + $stream->get( 'limit' ) ) ) { $stream->set( 'paging', 0 ); } } } else { $rows = array(); } } if ( $rows ) { if ( $stream->get( 'replies' ) ) { CBActivity::preFetchComments( $rows, 'comment' ); } CBActivity::preFetchUsers( $rows ); } echo HTML_cbactivityComments::showComments( $rows, $stream, $output, $user, $viewer, $this ); }