Example #1
0
	/**
	 * @param CommentTable    $row
	 * @param Comments        $stream
	 * @param int             $output 0: Normal, 1: Raw, 2: Inline, 3: Load, 4: Save
	 * @param UserTable       $user
	 * @param UserTable       $viewer
	 * @param cbPluginHandler $plugin
	 * @return null|string
	 */
	static public function showEdit( $row, $stream, $output, $user, $viewer, $plugin )
	{
		global $_PLUGINS;

		$cbModerator	=	CBActivity::isModerator( (int) $viewer->get( 'id' ) );
		$messageLimit	=	( $cbModerator ? 0 : (int) $stream->get( 'message_limit', 400 ) );

		$rowId			=	$stream->id() . '_edit_' . (int) $row->get( 'id' );

		$editBody		=	null;
		$editFooter		=	null;

		$_PLUGINS->trigger( 'activity_onDisplayCommentEdit', array( &$row, &$editBody, &$editFooter, $stream, $output ) );

		$return			=	'<div class="streamMediaBody streamItemEdit commentContainerContentEdit media-body text-small hidden">'
						.		'<form action="' . $stream->endpoint( 'save', array( 'id' => (int) $row->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="' . $rowId . 'Form" id="' . $rowId . 'Form" class="cb_form streamItemForm form">'
						.			'<textarea id="' . $stream->id() . '_message_edit_' . (int) $row->get( 'id' ) . '" name="message" rows="1" class="streamInput streamInputAutosize streamInputMessage form-control" placeholder="' . htmlspecialchars( ( $stream->get( 'type' ) == 'comment' ? CBTxt::T( 'Write a reply...' ) : CBTxt::T( 'Write a comment...' ) ) ) . '"' . ( $messageLimit ? ' data-cbactivity-input-limit="' . (int) $messageLimit . '" maxlength="' . (int) $messageLimit . '"' : null ) . '>' . htmlspecialchars( $row->get( 'message' ) ) . '</textarea>'
						.			$editBody
						.			'<div class="commentContainerFooter">'
						.				'<div class="commentContainerFooterRow clearfix">'
						.					'<div class="commentContainerFooterRowLeft pull-left">'
						.						$editFooter
						.					'</div>'
						.					'<div class="commentContainerFooterRowRight pull-right text-right">'
						.						'<button type="submit" class="commentButton commentButtonEditSave streamItemEditSave btn btn-primary btn-xs">' . CBTxt::T( 'Done Editing' ) . '</button>'
						.						' <button type="button" class="commentButton commentButtonEditCancel streamItemEditCancel btn btn-default btn-xs">' . CBTxt::T( 'Cancel' ) . '</button>'
						.					'</div>'
						.				'</div>'
						.			'</div>'
						.		'</form>'
						.	'</div>';

		return $return;
	}
	/**
	 * 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 );
	}