/** * @param ActivityTable[] $rows * @param Activity $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 showActivity( $rows, $stream, $output, $user, $viewer, $plugin ) { global $_CB_framework, $_PLUGINS; $showActions = (int) $stream->get( 'actions', 1 ); $showLocations = (int) $stream->get( 'locations', 1 ); $showLinks = (int) $stream->get( 'links', 1 ); $showTags = (int) $stream->get( 'tags', 1 ); CBActivity::loadHeaders( $output ); $_CB_framework->outputCbJQuery( "$( '.activityStream' ).cbactivity();" ); $canCreate = CBActivity::canCreate( $user, $viewer, $stream ); $cbModerator = CBActivity::isModerator( (int) $viewer->get( 'id' ) ); $sourceClean = htmlspecialchars( $stream->source() ); $newForm = null; $moreButton = null; if ( ( $output != 4 ) && $stream->get( 'paging' ) && $stream->get( 'limit' ) && $rows ) { $moreButton = '<a href="' . $stream->endpoint( 'show', array( 'limitstart' => ( $stream->get( 'limitstart' ) + $stream->get( 'limit' ) ), 'limit' => $stream->get( 'limit' ) ) ) . '" class="activityButton activityButtonMore streamMore btn btn-primary btn-sm btn-block">' . CBTxt::T( 'More' ) . '</a>'; } $return = null; $_PLUGINS->trigger( 'activity_onBeforeDisplayActivity', array( &$return, &$rows, $stream, $output ) ); if ( ! in_array( $output, array( 1, 4 ) ) ) { $return .= '<div class="' . $sourceClean . 'Activity activityStream streamContainer ' . ( $stream->direction() ? 'streamContainerUp' : 'streamContainerDown' ) . '" data-cbactivity-direction="' . (int) $stream->direction() . '">'; if ( ( $stream->source() != 'hidden' ) && ( ! $stream->get( 'id' ) ) && ( ! $stream->get( 'filter' ) ) ) { $newForm = self::showNew( $stream, $output, $user, $viewer, $plugin ); } } $return .= ( $stream->direction() ? $moreButton : $newForm ) . ( ! in_array( $output, array( 1, 4 ) ) ? '<div class="' . $sourceClean . 'ActivityItems activityStreamItems streamItems">' : null ); if ( $rows ) foreach ( $rows as $row ) { $rowId = $stream->id() . '_' . (int) $row->get( 'id' ); $rowOwner = ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ); $typeClass = ( $row->get( 'type' ) ? ucfirst( strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', $row->get( 'type' ) ) ) ) : null ); $subTypeClass = ( $row->get( 'subtype' ) ? ucfirst( strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', $row->get( 'subtype' ) ) ) ) : null ); $isStatus = ( ( $row->get( 'type' ) == 'status' ) || ( $row->get( 'subtype' ) == 'status' ) ); $cbUser = CBuser::getInstance( (int) $row->get( 'user_id' ), false ); $title = ( $row->get( 'title' ) ? ( $isStatus ? htmlspecialchars( $row->get( 'title' ) ) : CBTxt::T( $row->get( 'title' ) ) ) : null ); $message = ( $row->get( 'message' ) ? ( $isStatus ? htmlspecialchars( $row->get( 'message' ) ) : CBTxt::T( $row->get( 'message' ) ) ) : null ); $date = null; $insert = null; $footer = null; $menu = array(); $extras = array(); $_PLUGINS->trigger( 'activity_onDisplayActivity', array( &$row, &$title, &$date, &$message, &$insert, &$footer, &$menu, &$extras, $stream, $output ) ); $title = $stream->parser( $title )->parse( array( 'linebreaks' ) ); $message = $stream->parser( $message )->parse(); if ( $isStatus ) { if ( ( in_array( $row->get( 'type' ), array( 'status', 'field' ) ) ) && $row->get( 'parent' ) && ( $row->get( 'parent' ) != $_CB_framework->displayedUser() ) && ( $row->get( 'parent' ) != $row->get( 'user_id' ) ) ) { $targetUser = CBuser::getInstance( (int) $row->get( 'parent' ) ); if ( $targetUser !== null ) { $title = ' <span class="fa fa-caret-right"></span> <strong>' . $targetUser->getField( 'formatname', null, 'html', 'none', 'list', 0, true ) . '</strong>'; } } $action = ( $showActions ? $stream->parser( $row->action() )->parse( array( 'linebreaks' ) ) : null ); $location = ( $showLocations ? $row->location() : null ); $tags = null; if ( $showTags && $row->get( '_tags' ) ) { $tagsStream = $row->tags( $stream->source() ); if ( $tagsStream && $tagsStream->data( true ) ) { $tags = trim( CBTxt::T( 'ACTIVITY_STATUS_TAGS', 'with [tags]', array( '[tags]' => $tagsStream->stream( true ) ) ) ); } } if ( $action || $location || $tags ) { $subContent = ( $action ? $action : null ) . ( $location ? ( $action ? ' ' : null ) . $location : null ) . ( $tags ? ( $action || $location ? ' ' : null ) . $tags : null ); if ( $title ) { $message .= '<div class="streamItemSubContent">— ' . $subContent . '</div>'; } else { $title = $subContent; } } } elseif ( $row->get( 'type' ) == 'activity' ) { if ( ! $row->get( 'item' ) ) { continue; } $row->set( '_comments', false ); $row->set( '_tags', false ); $row->set( '_links', false ); $title = CBTxt::T( 'ACTIVITY_OF_ACTIVITY_TITLE', '[title] [date]', array( '[title]' => $title, '[date]' => cbFormatDate( $row->get( 'date' ), true, 'timeago' ) ) ); $message = null; $footer = null; $subActivity = new Activity( 'activity', $cbUser->getUserData() ); CBActivity::loadStreamDefaults( $subActivity, $stream ); $subActivity->set( 'id', $row->get( 'item' ) ); if ( $row->get( 'subtype' ) == 'comment' ) { $subActivity->set( 'comments', 1 ); } elseif ( $row->get( 'subtype' ) == 'tag' ) { $subActivity->set( 'tags', 1 ); } $insert = $subActivity->stream( true ); if ( ! $insert ) { continue; } } else { $title = ( $title ? $cbUser->replaceUserVars( $title, false, false, $extras, false ) : null ); $message = ( $message ? $cbUser->replaceUserVars( $message, false, false, $extras, false ) : null ); } $links = array(); if ( ( ( $isStatus && $showLinks ) || ( ! $isStatus ) ) && ( $row->get( '_links' ) !== false ) ) { $links = $row->attachments(); } if ( ( $stream->source() != 'hidden' ) && $stream->get( 'comments' ) && ( $row->get( '_comments' ) !== false ) ) { $comments = $row->comments( 'activity', $cbUser->getUserData() ); if ( $comments ) { CBActivity::loadStreamDefaults( $comments, $stream, 'comments_' ); $footer .= $comments->stream( true, ( $row->get( '_comments' ) ? true : false ) ); } } $return .= '<div id="' . $rowId . '" class="streamItem streamPanel activityContainer' . ( $typeClass ? ' activityContainer' . $typeClass : null ) . ( $subTypeClass ? ' activityContainer' . $typeClass . $subTypeClass : null ) . ' panel panel-default" data-cbactivity-id="' . (int) $row->get( 'id' ) . '">' . '<div class="streamItemInner">' . '<div class="streamMedia streamPanelHeading activityContainerHeader media panel-heading clearfix">' . '<div class="streamMediaLeft activityContainerLogo media-left">' . $cbUser->getField( 'avatar', null, 'html', 'none', 'list', 0, true ) . '</div>' . '<div class="streamMediaBody activityContainerTitle media-body">' . '<div class="activityContainerTitleTop text-muted">' . '<strong>' . $cbUser->getField( 'formatname', null, 'html', 'none', 'list', 0, true ) . '</strong>' . ( $title ? ' ' . $title : null ) . '</div>' . '<div class="activityContainerTitleBottom text-muted small">' . cbFormatDate( $row->get( 'date' ), true, 'timeago' ) . ( $row->params()->get( 'modified' ) ? ' <span class="streamIconEdited fa fa-edit" title="' . htmlspecialchars( CBTxt::T( 'Edited' ) ) . '"></span>' : null ) . ( $date ? ' ' . $date : null ) . '</div>' . '</div>' . '</div>'; if ( $message ) { $return .= '<div class="streamPanelBody streamItemDisplay activityContainerContent panel-body">' . '<div class="activityContainerContentInner cbMoreLess">' . '<div class="streamItemContent cbMoreLessContent">' . $message . '</div>' . '<div class="cbMoreLessOpen fade-edge hidden">' . '<a href="javascript: void(0);" class="cbMoreLessButton">' . CBTxt::T( 'See More' ) . '</a>' . '</div>' . '</div>' . '</div>'; } $return .= ( $insert ? '<div class="streamItemDisplay streamItemDivider activityContainerInsert border-default">' . $insert . '</div>' : null ); if ( $links ) { $return .= '<div class="streamPanelBody streamItemDisplay streamItemDivider activityContainerAttachments panel-body border-default">' . '<div class="activityContainerAttachmentsInner">' . self::showAttachments( $row, $stream, $output, $user, $viewer, $plugin ) . '</div>' . '</div>'; } $return .= ( $footer ? '<div class="streamPanelFooter streamItemDisplay activityContainerFooter panel-footer">' . $footer . '</div>' : null ); if ( $isStatus && ( $cbModerator || $rowOwner ) && $canCreate ) { $return .= self::showEdit( $row, $stream, $output, $user, $viewer, $plugin ); } if ( $cbModerator || $rowOwner || ( $viewer->get( 'id' ) && ( ! $rowOwner ) ) || $menu ) { $menuItems = '<ul class="streamItemMenuItems activityMenuItems dropdown-menu" style="display: block; position: relative; margin: 0;">'; if ( $isStatus && ( $cbModerator || $rowOwner ) && $canCreate ) { $menuItems .= '<li class="streamItemMenuItem activityMenuItem"><a href="javascript: void(0);" class="activityMenuItemEdit streamItemEditDisplay" data-cbactivity-container="#' . $rowId . '"><span class="fa fa-edit"></span> ' . CBTxt::T( 'Edit' ) . '</a></li>'; } if ( $viewer->get( 'id' ) && ( ! $rowOwner ) ) { if ( $stream->source() == 'hidden' ) { $menuItems .= '<li class="streamItemMenuItem activityMenuItem"><a href="' . $stream->endpoint( 'unhide', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="activityMenuItemUnhide streamItemAction" data-cbactivity-container="#' . $rowId . '"><span class="fa fa-check"></span> ' . CBTxt::T( 'Unhide' ) . '</a></li>'; } else { $menuItems .= '<li class="streamItemMenuItem activityMenuItem"><a href="' . $stream->endpoint( 'hide', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="activityMenuItemHide streamItemAction" data-cbactivity-container="#' . $rowId . '" data-cbactivity-confirm="' . htmlspecialchars( CBTxt::T( 'Are you sure you want to hide this Activity?' ) ) . '" data-cbactivity-confirm-button="' . htmlspecialchars( CBTxt::T( 'Hide Activity' ) ) . '"><span class="fa fa-times"></span> ' . CBTxt::T( 'Hide' ) . '</a></li>'; } } if ( $cbModerator || $rowOwner ) { $menuItems .= '<li class="streamItemMenuItem activityMenuItem"><a href="' . $stream->endpoint( 'delete', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="activityMenuItemDelete streamItemAction" data-cbactivity-container="#' . $rowId . '" data-cbactivity-confirm="' . htmlspecialchars( CBTxt::T( 'Are you sure you want to delete this Activity?' ) ) . '" data-cbactivity-confirm-button="' . htmlspecialchars( CBTxt::T( 'Delete Activity' ) ) . '"><span class="fa fa-trash-o"></span> ' . CBTxt::T( 'Delete' ) . '</a></li>'; } if ( $menu ) { $menuItems .= '<li class="streamItemMenuItem activityMenuItem">' . implode( '</li><li class="streamItemMenuItem activityMenuItem">', $menu ) . '</li>'; } $menuItems .= '</ul>'; $menuAttr = cbTooltip( 1, $menuItems, null, 'auto', null, null, null, 'class="fa fa-chevron-down text-muted" data-cbtooltip-menu="true" data-cbtooltip-classes="qtip-nostyle" data-cbtooltip-open-classes="open"' ); $return .= '<div class="streamItemMenu activityContainerMenu">' . '<span ' . trim( $menuAttr ) . '></span>' . '</div>'; } $return .= '</div>' . '</div>'; } elseif ( $output != 2 ) { $return .= '<div class="streamItemEmpty text-center text-muted small">'; if ( $output == 1 ) { $return .= CBTxt::T( 'No more activity to display.' ); } else { $return .= CBTxt::T( 'No activity to display.' ); } $return .= '</div>'; } elseif ( ( $output == 2 ) && ( ! $newForm ) ) { return null; } $return .= ( ! in_array( $output, array( 1, 4 ) ) ? '</div>' : null ) . ( ! $stream->direction() ? $moreButton : $newForm ) . ( ! in_array( $output, array( 1, 4 ) ) ? '</div>' : null ) . CBActivity::reloadHeaders( $output ); $_PLUGINS->trigger( 'activity_onAfterDisplayActivity', array( &$return, $rows, $stream, $output ) ); return $return; }
/** * @param CommentTable[] $rows * @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 showComments( $rows, $stream, $output, $user, $viewer, $plugin ) { global $_CB_framework, $_PLUGINS; CBActivity::loadHeaders( $output ); $_CB_framework->outputCbJQuery( "$( '.commentsStream' ).cbactivity();" ); $canCreate = CBActivity::canCreate( $user, $viewer, $stream ); $cbModerator = CBActivity::isModerator( (int) $viewer->get( 'id' ) ); $sourceClean = htmlspecialchars( $stream->source() ); $newForm = null; $moreButton = null; if ( ( $output != 4 ) && $stream->get( 'paging' ) && $stream->get( 'limit' ) && $rows ) { $moreButton = '<a href="' . $stream->endpoint( 'show', array( 'limitstart' => ( $stream->get( 'limitstart' ) + $stream->get( 'limit' ) ), 'limit' => $stream->get( 'limit' ) ) ) . '" class="commentButton commentButtonMore streamMore">' . ( $stream->get( 'type' ) == 'comment' ? CBTxt::T( 'Show more replies' ) : CBTxt::T( 'Show more comments' ) ) . '</a>'; } $return = null; $_PLUGINS->trigger( 'activity_onBeforeDisplayComments', array( &$return, &$rows, $stream, $output ) ); if ( ! in_array( $output, array( 1, 4 ) ) ) { $return .= '<div class="' . $sourceClean . 'Comments commentsStream streamContainer ' . ( $stream->direction() ? 'streamContainerUp' : 'streamContainerDown' ) . '" data-cbactivity-stream="' . base64_encode( (string) $stream ) . '" data-cbactivity-direction="' . (int) $stream->direction() . '">'; if ( ( $stream->source() != 'hidden' ) && ( ! $stream->get( 'id' ) ) && ( ! $stream->get( 'filter' ) ) ) { $newForm = self::showNew( $stream, $output, $user, $viewer, $plugin ); } } $return .= ( $stream->direction() ? $moreButton : $newForm ) . ( ! in_array( $output, array( 1, 4 ) ) ? '<div class="' . $sourceClean . 'CommentsItems commentsStreamItems streamItems">' : null ); if ( $rows ) foreach ( $rows as $row ) { $rowId = $stream->id() . '_' . (int) $row->get( 'id' ); $rowOwner = ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ); $typeClass = ( $row->get( 'type' ) ? ucfirst( strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', $row->get( 'type' ) ) ) ) : null ); $subTypeClass = ( $row->get( 'subtype' ) ? ucfirst( strtolower( preg_replace( '/[^-a-zA-Z0-9_]/', '', $row->get( 'subtype' ) ) ) ) : null ); $cbUser = CBuser::getInstance( (int) $row->get( 'user_id' ), false ); $message = ( $row->get( 'message' ) ? htmlspecialchars( $row->get( 'message' ) ) : null ); $date = null; $insert = null; $footer = null; $menu = array(); $extras = array(); $_PLUGINS->trigger( 'activity_onDisplayComment', array( &$row, &$message, &$insert, &$date, &$footer, &$menu, &$extras, $stream, $output ) ); $message = $stream->parser( $message )->parse( array( 'linebreaks' ) ); if ( ( $stream->source() != 'hidden' ) && $stream->get( 'replies' ) && ( $row->get( '_comments' ) !== false ) ) { if ( $newForm ) { $date .= ( $date ? ' ' : null ) . '<span class="streamToggle streamToggleReplies" data-cbactivity-toggle-target=".commentContainerNew" data-cbactivity-toggle-close="false" data-cbactivity-toggle-filter="false" data-cbactivity-toggle-active-classes="hidden">- <a href="javascript: void(0);">' . CBTxt::T( 'Reply' ) . '</a></span>'; } $replies = $row->replies( $stream->source(), $stream->user() ); if ( $replies ) { CBActivity::loadStreamDefaults( $replies, $stream ); $replies->set( 'replies', 0 ); $footer .= $replies->stream( true, ( $row->get( '_comments' ) ? true : false ) ); } } $return .= '<div id="' . $rowId . '" class="streamItem streamItemInline commentContainer' . ( $typeClass ? ' commentContainer' . $typeClass : null ) . ( $subTypeClass ? ' commentContainer' . $typeClass . $subTypeClass : null ) . '" data-cbactivity-id="' . (int) $row->get( 'id' ) . '">' . '<div class="streamItemInner streamMedia media clearfix">' . '<div class="streamMediaLeft commentContainerLogo media-left">' . $cbUser->getField( 'avatar', null, 'html', 'none', 'list', 0, true ) . '</div>' . '<div class="streamMediaBody streamItemDisplay commentContainerContent media-body">' . '<div class="commentContainerContentInner cbMoreLess text-small" data-cbmoreless-height="50">' . '<div class="streamItemContent cbMoreLessContent">' . '<strong>' . $cbUser->getField( 'formatname', null, 'html', 'none', 'list', 0, true ) . '</strong>' . ( $message ? ' ' . $message : null ) . '</div>' . '<div class="cbMoreLessOpen fade-edge hidden">' . '<a href="javascript: void(0);" class="cbMoreLessButton">' . CBTxt::T( 'See More' ) . '</a>' . '</div>' . '</div>' . ( $insert ? '<div class="commentContainerContentInsert">' . $insert . '</div>' : null ) . '<div class="commentContainerContentDate text-muted text-small">' . cbFormatDate( $row->get( 'date' ), true, 'timeago' ) . ( $row->params()->get( 'modified' ) ? ' <span class="streamIconEdited fa fa-edit" title="' . htmlspecialchars( CBTxt::T( 'Edited' ) ) . '"></span>' : null ) . ( $date ? ' ' . $date : null ) . '</div>' . ( $footer ? '<div class="commentContainerContentFooter">' . $footer . '</div>' : null ) . '</div>'; if ( ( $cbModerator || $rowOwner ) && $canCreate ) { $return .= self::showEdit( $row, $stream, $output, $user, $viewer, $plugin ); } if ( $cbModerator || $rowOwner || ( $viewer->get( 'id' ) && ( ! $rowOwner ) ) || $menu ) { $menuItems = '<ul class="streamItemMenuItems commentMenuItems dropdown-menu" style="display: block; position: relative; margin: 0;">'; if ( ( $cbModerator || $rowOwner ) && $canCreate ) { $menuItems .= '<li class="streamItemMenuItem commentMenuItem"><a href="javascript: void(0);" class="commentMenuItemEdit streamItemEditDisplay" data-cbactivity-container="#' . $rowId . '"><span class="fa fa-edit"></span> ' . CBTxt::T( 'Edit' ) . '</a></li>'; } if ( $viewer->get( 'id' ) && ( ! $rowOwner ) ) { if ( $stream->source() == 'hidden' ) { $menuItems .= '<li class="streamItemMenuItem commentMenuItem"><a href="' . $stream->endpoint( 'unhide', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="commentMenuItemUnhide streamItemAction" data-cbactivity-container="#' . $rowId . '"><span class="fa fa-check"></span> ' . CBTxt::T( 'Unhide' ) . '</a></li>'; } else { $menuItems .= '<li class="streamItemMenuItem commentMenuItem"><a href="' . $stream->endpoint( 'hide', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="commentMenuItemHide streamItemAction" data-cbactivity-container="#' . $rowId . '" data-cbactivity-confirm="' . htmlspecialchars( CBTxt::T( 'Are you sure you want to hide this Comment?' ) ) . '" data-cbactivity-confirm-button="' . htmlspecialchars( CBTxt::T( 'Hide Comment' ) ) . '"><span class="fa fa-times"></span> ' . CBTxt::T( 'Hide' ) . '</a></li>'; } } if ( $cbModerator || $rowOwner ) { $menuItems .= '<li class="streamItemMenuItem commentMenuItem"><a href="' . $stream->endpoint( 'delete', array( 'id' => (int) $row->get( 'id' ) ) ) . '" class="commentMenuItemDelete streamItemAction" data-cbactivity-container="#' . $rowId . '" data-cbactivity-confirm="' . htmlspecialchars( CBTxt::T( 'Are you sure you want to delete this Comment?' ) ) . '" data-cbactivity-confirm-button="' . htmlspecialchars( CBTxt::T( 'Delete Comment' ) ) . '"><span class="fa fa-trash-o"></span> ' . CBTxt::T( 'Delete' ) . '</a></li>'; } if ( $menu ) { $menuItems .= '<li class="streamItemMenuItem commentMenuItem">' . implode( '</li><li class="streamItemMenuItem commentMenuItem">', $menu ) . '</li>'; } $menuItems .= '</ul>'; $menuAttr = cbTooltip( 1, $menuItems, null, 'auto', null, null, null, 'class="fa fa-chevron-down text-muted" data-cbtooltip-menu="true" data-cbtooltip-classes="qtip-nostyle" data-cbtooltip-open-classes="open"' ); $return .= '<div class="streamItemMenu commentContainerMenu small">' . '<span ' . trim( $menuAttr ) . '></span>' . '</div>'; } $return .= '</div>' . '</div>'; } elseif ( $output != 2 ) { $return .= '<div class="streamItemEmpty text-center text-muted small">'; if ( $output == 1 ) { $return .= CBTxt::T( 'No more comments to display.' ); } else { $return .= CBTxt::T( 'No comments to display.' ); } $return .= '</div>'; } elseif ( ( $output == 2 ) && ( ! $newForm ) ) { return null; } $return .= ( ! in_array( $output, array( 1, 4 ) ) ? '</div>' : null ) . ( ! $stream->direction() ? $moreButton : $newForm ) . ( ! in_array( $output, array( 1, 4 ) ) ? '</div>' : null ) . CBActivity::reloadHeaders( $output ); $_PLUGINS->trigger( 'activity_onAfterDisplayComments', array( &$return, $rows, $stream, $output ) ); return $return; }
/** * @param TabTable $tab Current tab * @param UserTable $user Current user * @param int $ui 1 front, 2 admin UI * @param array $postdata Raw unfiltred POST data * @return string HTML */ public function getCBpluginComponent( $tab, $user, $ui, $postdata ) { global $_CB_framework; $format = $this->input( 'format', null, GetterInterface::STRING ); $raw = ( $format == 'raw' ); if ( ! $raw ) { outputCbJs(); outputCbTemplate(); } $action = null; $function = null; $id = null; $viewer = CBuser::getMyUserDataInstance(); $user = $viewer; $stream = null; $inline = false; $data = true; if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof StreamInterface ) ) { $stream = $postdata['stream']; if ( $stream instanceof ActivityInterface ) { $action = 'activity'; $function = 'show'; } elseif ( $stream instanceof CommentsInterface ) { $action = 'comments'; $function = 'show'; } elseif ( $stream instanceof TagsInterface ) { $action = 'tags'; $function = 'show'; } if ( isset( $postdata['inline'] ) ) { $inline = $postdata['inline']; } if ( isset( $postdata['data'] ) ) { $data = $postdata['data']; } $user = $stream->user(); } else { $action = $this->input( 'action', null, GetterInterface::STRING ); $function = $this->input( 'func', null, GetterInterface::STRING ); if ( $action == 'recentactivity' ) { $action = 'activity'; $function = 'recent'; } elseif ( $action == 'myactivity' ) { $action = 'activity'; $function = 'my'; } elseif ( $action == 'hiddenactivity' ) { $action = 'hidden'; $function = 'activity'; } elseif ( $action == 'hiddencomments' ) { $action = 'hidden'; $function = 'comments'; } if ( ( $action == 'activity' ) || ( $function == 'activity' ) ) { $stream = new Activity(); } elseif ( ( $action == 'comments' ) || ( $function == 'comments' ) ) { $stream = new Comments(); } elseif ( ( $action == 'tags' ) || ( $function == 'tags' ) ) { $stream = new Tags(); } if ( $stream && $raw ) { $token = $this->input( 'token', null, GetterInterface::STRING ); $post = new Registry( base64_decode( $this->input( 'stream', null, GetterInterface::BASE64 ) ) ); $source = $post->get( 'source', null, GetterInterface::STRING ); $userId = $post->get( 'user', null, GetterInterface::INT ); $direction = $post->get( 'direction', null, GetterInterface::INT ); if ( $source !== null ) { $stream->source( $source ); } if ( $userId !== null ) { $user = CBuser::getUserDataInstance( (int) $userId ); $stream->user( $user ); } if ( ! ( $stream instanceof TagsInterface ) ) { if ( $direction !== null ) { $stream->direction( $direction ); } } $stream->load( $post ); if ( ( $stream->token() != $token ) || ( ! $token ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } $id = $stream->get( 'id', null, GetterInterface::INT ); } } if ( $stream && ( ! ( ( $stream instanceof CommentsInterface ) || ( $stream instanceof TagsInterface ) ) ) ) { $hashtag = $this->input( 'hashtag', null, GetterInterface::STRING ); if ( $hashtag !== null ) { $stream->set( 'filter', '#' . $hashtag ); } } if ( ! $raw ) { ob_start(); } switch ( $action ) { case 'comments': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'new': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveComment( null, $stream, $user, $viewer ); break; case 'save': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveComment( $id, $stream, $user, $viewer ); break; case 'delete': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->deleteComment( $id, $stream, $user, $viewer ); break; case 'hide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->hideComment( $id, $stream, $user, $viewer ); break; case 'unhide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->unhideComment( $id, $stream, $user, $viewer ); break; case 'load': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->showComments( $id, $stream, 3, true, $user, $viewer ); break; case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof CommentsInterface ) ) { $this->showComments( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showComments( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'activity': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'new': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveActivity( null, $stream, $user, $viewer ); break; case 'save': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->saveActivity( $id, $stream, $user, $viewer ); break; case 'delete': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->deleteActivity( $id, $stream, $user, $viewer ); break; case 'hide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->hideActivity( $id, $stream, $user, $viewer ); break; case 'unhide': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->unhideActivity( $id, $stream, $user, $viewer ); break; case 'load': if ( ! $raw ) { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } $this->showActivity( $id, $stream, 3, true, $user, $viewer ); break; case 'recent': $stream->source( 'recent' ); $menu = JFactory::getApplication()->getMenu()->getActive(); if ( $menu && isset( $menu->id ) ) { CBActivity::loadStreamDefaults( $stream, $menu->params, 'activity_' ); } $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); $_CB_framework->setMenuMeta(); break; case 'my': $tab = new TabTable(); $tab->load( array( 'pluginclass' => 'cbactivityTab' ) ); if ( ! ( $tab->get( 'enabled' ) && CBActivity::canAccess( (int) $tab->get( 'viewaccesslevel' ), (int) $viewer->get( 'id' ) ) ) ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( $_CB_framework->userProfileUrl( (int) $user->get( 'id' ), false, 'cbactivityTab' ), CBTxt::T( 'Not authorized.' ), 'error' ); } } if ( ! ( $tab->params instanceof ParamsInterface ) ) { $tab->params = new Registry( $tab->params ); } $stream->source( 'profile' ); CBActivity::loadStreamDefaults( $activity, $tab->params, 'tab_activity_' ); $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); $_CB_framework->setMenuMeta(); break; case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof ActivityInterface ) ) { $this->showActivity( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showActivity( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'hidden': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'users': break; case 'types': break; case 'comments': $stream->source( 'hidden' ); $stream->set( 'create_access', -1 ); $stream->set( 'replies', 0 ); $this->showComments( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); break; case 'activity': $stream->source( 'hidden' ); $stream->set( 'create_access', -1 ); $stream->set( 'comments', 0 ); $this->showActivity( $id, $stream, ( $raw ? 1 : 0 ), true, $user, $viewer ); break; } $_CB_framework->setMenuMeta(); break; case 'tags': if ( ! $stream ) { if ( $raw ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } else { cbRedirect( 'index.php', CBTxt::T( 'Not authorized.' ), 'error' ); } } switch ( $function ) { case 'show': default: if ( isset( $postdata['stream'] ) && ( $postdata['stream'] instanceof TagsInterface ) ) { $this->showTags( $id, $stream, ( $inline ? 2 : 0 ), $data, $user, $viewer ); } else { $this->showTags( $id, $stream, ( $inline ? 2 : ( $raw ? 1 : 0 ) ), true, $user, $viewer ); } break; } break; case 'cleanup': if ( ( ! $raw ) || ( $this->input( 'token', null, GetterInterface::STRING ) != md5( $_CB_framework->getCfg( 'secret' ) ) ) ) { header( 'HTTP/1.0 401 Unauthorized' ); exit(); } $this->cleanUp(); break; } if ( ! $raw ) { $html = ob_get_contents(); ob_end_clean(); if ( ! $inline ) { $class = $this->params->get( 'general_class', null ); $html = '<div id="cbActivity" class="cbActivity' . ( $class ? ' ' . htmlspecialchars( $class ) : null ) . '">' . '<div id="cbActivityInner" class="cbActivityInner">' . $html . '</div>' . '</div>'; } echo $html; } }
/** * 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 ); }
/** * @param cbautoactionsActionTable $trigger * @param UserTable $user * @return null|string */ public function execute( $trigger, $user ) { global $_CB_framework, $_CB_database; if ( ! $this->installed() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_ACTIVITY_NOT_INSTALLED', ':: Action [action] :: CB Activity is not installed', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } return null; } $return = null; foreach ( $trigger->getParams()->subTree( 'activity' ) as $row ) { /** @var ParamsInterface $row */ $mode = $row->get( 'mode', 'activity', GetterInterface::STRING ); $method = $row->get( 'method', 'create', GetterInterface::STRING ); $owner = $row->get( 'owner', null, GetterInterface::STRING ); if ( ! $owner ) { $owner = (int) $user->get( 'id' ); } else { $owner = (int) $trigger->getSubstituteString( $owner ); } $type = $trigger->getSubstituteString( $row->get( 'type', null, GetterInterface::STRING ) ); $subtype = $trigger->getSubstituteString( $row->get( 'subtype', null, GetterInterface::STRING ) ); $item = $trigger->getSubstituteString( $row->get( 'item', null, GetterInterface::STRING ) ); $parent = $trigger->getSubstituteString( $row->get( 'parent', null, GetterInterface::STRING ) ); if ( $mode == 'stream' ) { if ( $owner ) { $streamUser = CBuser::getUserDataInstance( (int) $owner ); } else { $streamUser = CBuser::getMyUserDataInstance(); } $source = $trigger->getSubstituteString( $row->get( 'source', null, GetterInterface::STRING ) ); $direction = (int) $row->get( 'direction', 0, GetterInterface::INT ); if ( $row->get( 'stream', 'activity', GetterInterface::STRING ) == 'comments' ) { $object = new Comments( $source, $streamUser, $direction ); CBActivity::loadStreamDefaults( $object, $row->subTree( 'comments_stream' ), 'comments_' ); } else { $object = new Activity( $source, $streamUser, $direction ); CBActivity::loadStreamDefaults( $object, $row->subTree( 'activity_stream' ), 'activity_' ); } if ( $type ) { $object->set( 'type', $type ); } if ( $subtype ) { $object->set( 'subtype', $subtype ); } if ( $item ) { $object->set( 'item', $item ); } if ( $parent ) { $object->set( 'parent', $parent ); } if ( $row->get( 'output', 'echo', GetterInterface::STRING ) == 'echo' ) { echo $object->stream( false ); } else { $return .= $object->stream( false ); } } elseif ( $method == 'delete' ) { $where = array(); if ( $owner ) { $where[] = $_CB_database->NameQuote( 'user_id' ) . ' = ' . (int) $owner; } if ( $type ) { $where[] = $_CB_database->NameQuote( 'type' ) . ( strpos( $type, '%' ) !== false ? ' LIKE ' : ' = ' ) . $_CB_database->Quote( $type ); } if ( $item ) { $where[] = $_CB_database->NameQuote( 'item' ) . ' = ' . $_CB_database->Quote( $item ); } if ( $mode != 'hidden' ) { if ( $subtype ) { $where[] = $_CB_database->NameQuote( 'subtype' ) . ( strpos( $type, '%' ) !== false ? ' LIKE ' : ' = ' ) . $_CB_database->Quote( $subtype ); } if ( $parent ) { $where[] = $_CB_database->NameQuote( 'parent' ) . ' = ' . $_CB_database->Quote( $parent ); } } switch ( $mode ) { case 'hidden': $table = '#__comprofiler_plugin_activity_hidden'; $class = '\CB\Plugin\Activity\Table\HiddenTable'; break; case 'tag': $table = '#__comprofiler_plugin_activity_tags'; $class = '\CB\Plugin\Activity\Table\TagTable'; break; case 'comment': $table = '#__comprofiler_plugin_activity_comments'; $class = '\CB\Plugin\Activity\Table\CommentTable'; break; case 'activity': default: $table = '#__comprofiler_plugin_activity'; $class = '\CB\Plugin\Activity\Table\ActivityTable'; break; } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( $table ) . ( $where ? "\n WHERE " . implode( "\n AND ", $where ) : null ); $_CB_database->setQuery( $query ); $objects = $_CB_database->loadObjectList( null, $class, array( $_CB_database ) ); /** @var TableInterface[] $objects */ foreach ( $objects as $object ) { $object->delete(); } } else { if ( ! $owner ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_ACTIVITY_NO_OWNER', ':: Action [action] :: CB Activity skipped due to missing owner', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } if ( ! $type ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_ACTIVITY_NO_TYPE', ':: Action [action] :: CB Activity skipped due to missing type', array( '[action]' => (int) $trigger->get( 'id' ) ) ) ); } continue; } switch ( $mode ) { case 'hidden': $object = new HiddenTable( $_CB_database ); break; case 'tag': $object = new TagTable( $_CB_database ); break; case 'comment': $object = new CommentTable( $_CB_database ); break; case 'activity': default: $object = new ActivityTable( $_CB_database ); break; } if ( $item ) { $load = array( 'user_id' => $owner, 'type' => $type, 'item' => $item ); if ( $mode != 'hidden' ) { if ( $subtype ) { $load['subtype'] = $subtype; } if ( $parent ) { $load['parent'] = $parent; } } $object->load( $load ); } $object->set( 'user_id', $owner ); if ( $type ) { $object->set( 'type', $type ); } if ( $mode != 'hidden' ) { if ( $subtype ) { $object->set( 'subtype', $subtype ); } if ( $parent ) { $object->set( 'parent', $parent ); } } if ( $item ) { $object->set( 'item', $item ); } if ( $mode == 'activity' ) { $title = $trigger->getSubstituteString( $row->get( 'title', null, GetterInterface::RAW ) ); if ( $title ) { $object->set( 'title', $title ); } $date = $trigger->getSubstituteString( $row->get( 'date', null, GetterInterface::STRING ) ); if ( $date ) { $object->set( 'date', $_CB_framework->getUTCDate( 'Y-m-d H:i:s', $date ) ); } $action = $row->subTree( 'action' ); $actionId = $action->get( 'id', null, GetterInterface::INT ); if ( $actionId ) { $actionMessage = $trigger->getSubstituteString( $action->get( 'message', null, GetterInterface::STRING ) ); if ( $actionMessage ) { $newAction = array( 'id' => $actionId, 'message' => $actionMessage, 'emote' => $action->get( 'emote', '', GetterInterface::STRING ) ); $object->params()->set( 'action', $newAction ); } } $location = $row->subTree( 'location' ); $locationId = $location->get( 'id', null, GetterInterface::INT ); if ( $locationId ) { $locationPlace = $trigger->getSubstituteString( $location->get( 'place', null, GetterInterface::STRING ) ); if ( $locationPlace ) { $newLocation = array( 'id' => $locationId, 'place' => $locationPlace, 'address' => $trigger->getSubstituteString( $location->get( 'address', null, GetterInterface::STRING ) ) ); $object->params()->set( 'location', $newLocation ); } } $newLinks = array(); foreach ( $row->subTree( 'links' ) as $link ) { /** @var ParamsInterface $link */ $linkType = $trigger->getSubstituteString( $link->get( 'type', null, GetterInterface::STRING ) ); $linkUrl = $trigger->getSubstituteString( $link->get( 'url', null, GetterInterface::STRING ) ); if ( ( ! $linkType ) || ( ! $linkUrl ) ) { continue; } $linkMedia = $link->subTree( 'media' ); $newLinks[] = array( 'url' => $linkUrl, 'text' => $trigger->getSubstituteString( $link->get( 'text', null, GetterInterface::STRING ) ), 'title' => $trigger->getSubstituteString( $link->get( 'title', null, GetterInterface::STRING ) ), 'description' => $trigger->getSubstituteString( $link->get( 'description', null, GetterInterface::RAW ) ), 'media' => array( 'url' => $trigger->getSubstituteString( $linkMedia->get( 'url', null, GetterInterface::STRING ) ), 'mimetype' => $trigger->getSubstituteString( $linkMedia->get( 'mimetype', null, GetterInterface::STRING ) ), 'extension' => $trigger->getSubstituteString( $linkMedia->get( 'extension', null, GetterInterface::STRING ) ), 'custom' => $trigger->getSubstituteString( $linkMedia->get( 'custom', null, GetterInterface::RAW ) ) ), 'type' => $linkType, 'thumbnail' => $link->get( 'thumbnail', 1, GetterInterface::INT ), 'internal' => $link->get( 'internal', 0, GetterInterface::INT ) ); } if ( $newLinks ) { $object->params()->set( 'links', $newLinks ); } $comments = $row->subTree( 'comments' ); $object->params()->set( 'comments', array( 'display' => (int) $comments->get( 'display', 1, GetterInterface::INT ), 'source' => (int) $comments->get( 'source', 1, GetterInterface::INT ) )); $tags = $row->subTree( 'tags' ); $object->params()->set( 'tags', array( 'display' => (int) $tags->get( 'display', 1, GetterInterface::INT ), 'source' => (int) $tags->get( 'source', 1, GetterInterface::INT ) )); $object->set( 'params', $object->params()->asJson() ); } elseif ( $mode == 'comment' ) { $tags = $row->subTree( 'replies' ); $object->params()->set( 'replies', array( 'display' => (int) $tags->get( 'display', 1, GetterInterface::INT ) )); $object->set( 'params', $object->params()->asJson() ); } if ( in_array( $mode, array( 'activity', 'comment' ) ) ) { $message = $trigger->getSubstituteString( $row->get( 'message', null, GetterInterface::RAW ), false ); if ( $message ) { $object->set( 'message', $message ); } } if ( ! $object->store() ) { if ( $trigger->getParams()->get( 'debug', false, GetterInterface::BOOLEAN ) ) { var_dump( CBTxt::T( 'AUTO_ACTION_ACTIVITY_CREATE_FAILED', ':: Action [action] :: CB Activity failed to save. Error: [error]', array( '[action]' => (int) $trigger->get( 'id' ), '[error]' => $object->getError() ) ) ); } continue; } } } return $return; }