Beispiel #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;
	}
	/**
	 * Hides comment
	 *
	 * @param int       $id
	 * @param Activity  $stream
	 * @param UserTable $user
	 * @param UserTable $viewer
	 * @param bool      $silent
	 */
	private function hideComment( $id, $stream, $user, $viewer, $silent = false )
	{
		$item		=	new CommentTable();

		$item->load( (int) $id );

		if ( ( ! $item->get( 'id' ) ) || ( ! $viewer->get( 'id' ) ) || ( $viewer->get( 'id' ) == $item->get( 'user_id' ) ) ) {
			header( 'HTTP/1.0 404 Not Found' );
			exit();
		}

		$row		=	new HiddenTable();

		$row->load( array( 'user_id' => (int) $viewer->get( 'id' ), 'type' => 'comment', 'item' => (int) $item->get( 'id' ) ) );

		if ( $row->get( 'id' ) ) {
			header( 'HTTP/1.0 200 OK' );
			exit();
		}

		$row->set( 'user_id', (int) $viewer->get( 'id' ) );
		$row->set( 'type', 'comment' );
		$row->set( 'item', (int) $item->get( 'id' ) );

		if ( ! $row->check() ) {
			header( 'HTTP/1.0 401 Unauthorized' );
			exit();
		}

		if ( ! $row->store() ) {
			header( 'HTTP/1.0 500 Internal Server Error' );
			exit();
		}

		if ( ! $silent ) {
			$unhide		=	'<a href="' . $stream->endpoint( 'unhide', array( 'id' => (int) $item->get( 'id' ) ) ) . '" class="commentsContainerUnhide streamItemAction streamItemNoticeRevert">' . CBTxt::T( 'Unhide' ) . '</a>';

			if ( $stream->get( 'type' ) == 'comment' ) {
				echo CBTxt::T( 'COMMENT_REPLY_HIDDEN_UNHIDE', 'This reply has been hidden. [unhide]', array( '[unhide]' => $unhide ) );
			} else {
				echo CBTxt::T( 'COMMENT_HIDDEN_UNHIDE', 'This comment has been hidden. [unhide]', array( '[unhide]' => $unhide ) );
			}
		}

		header( 'HTTP/1.0 200 OK' );
		exit();
	}