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;
	}
Example #2
0
	/**
	 * @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];
	}
Example #3
0
	/**
	 * 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 );
	}