/** * @param ActivityTable $row * @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 showAttachments( $row, $stream, $output, $user, $viewer, $plugin ) { global $_PLUGINS; if ( ! $stream->get( 'links', 1 ) ) { return null; } $links = $row->attachments(); $_PLUGINS->trigger( 'activity_onDisplayActivityAttachments', array( &$row, &$links, $stream, $output ) ); if ( ! $links ) { return null; } $cbModerator = CBActivity::isModerator( (int) $viewer->get( 'id' ) ); $isStatus = ( ( $row->get( 'type' ) == 'status' ) || ( $row->get( 'subtype' ) == 'status' ) ); $rowOwner = ( $viewer->get( 'id' ) == $row->get( 'user_id' ) ); $count = count( $links ); $return = '<div class="streamItemScroll">' . '<div class="streamItemScrollLeft' . ( $count > 1 ? null : ' hidden' ) . '">' . '<table>' . '<tr>' . '<td>' . '<span class="streamItemScrollLeftIcon fa fa-chevron-left"></span>' . '</td>' . '</tr>' . '</table>' . '</div>'; foreach ( $links as $i => $link ) { $hasMedia = ( ( $link['type'] == 'custom' ) || ( ( $link['type'] != 'url' ) && $link['media']['url'] ) || ( ( $link['type'] == 'url' ) && $link['media']['url'] && $link['thumbnail'] ) ); $return .= '<div class="activityContainerAttachment streamItemScrollContent ' . ( $link['type'] == 'url' ? 'streamMedia media' : 'streamPanel panel' ) . ( $i != 0 ? ' hidden' : null ) . '">'; if ( $hasMedia ) { $return .= '<div class="activityContainerAttachmentMedia ' . ( $link['type'] == 'url' ? 'streamMediaLeft media-left' : 'streamPanelBody panel-body' ) . ' text-center">'; switch ( $link['type'] ) { case 'custom': $return .= $link['media']['custom']; break; case 'video': $return .= '<video width="640" height="360" style="width: 100%; height: 100%;" src="' . htmlspecialchars( $link['media']['url'] ) . '" type="' . htmlspecialchars( $link['media']['mimetype'] ) . '" class="streamItemVideo" preload="none" controls></video>'; break; case 'audio': $return .= '<audio width="640" style="width: 100%;" src="' . htmlspecialchars( $link['media']['url'] ) . '" type="' . htmlspecialchars( $link['media']['mimetype'] ) . '" class="streamItemAudio" preload="none" controls></audio>'; break; case 'image': $return .= '<a href="' . htmlspecialchars( $link['url'] ) . '" rel="nofollow" target="_blank">' . '<img src="' . htmlspecialchars( $link['media']['url'] ) . '" class="img-responsive streamItemImage" />' . '</a>'; break; case 'url': default: $return .= '<a href="' . htmlspecialchars( $link['url'] ) . '" rel="nofollow" target="_blank">' . '<img src="' . htmlspecialchars( $link['media']['url'] ) . '" class="img-responsive streamItemImage" />' . '</a>'; break; } $return .= '</div>'; } if ( $link['title'] || $link['description'] || ( ( ! $link['internal'] ) && ( ( ! $link['title'] ) || $link['text'] ) ) || ( $count > 1 ) ) { $hypertext = ( $link['text'] ? CBTxt::T( $link['text'] ) : $link['url'] ); $return .= '<div class="streamPanelFooter streamItemDisplay activityContainerAttachmentInfo panel-footer' . ( $link['type'] == 'url' ? ' streamMediaBody media-body' : null ) . '">' . '<div class="cbMoreLess">' . '<div class="cbMoreLessContent">' . ( $link['title'] ? '<div><strong><a href="' . htmlspecialchars( $link['url'] ) . '" rel="nofollow" target="_blank">' . ( $isStatus ? htmlspecialchars( CBTxt::T( $link['title'] ) ) : CBTxt::T( $link['title'] ) ) . '</a></strong></div>' : null ) . ( $isStatus ? htmlspecialchars( CBTxt::T( $link['description'] ) ) : CBTxt::T( $link['description'] ) ) . '</div>' . '<div class="activityContainerAttachmentUrl small">' . ( ( ! $link['internal'] ) && ( ( ! $link['title'] ) || $link['text'] ) ? '<a href="' . htmlspecialchars( $link['url'] ) . '" rel="nofollow" target="_blank">' . ( $isStatus ? htmlspecialchars( $hypertext ) : $hypertext ) . '</a>' : null ) . ( $count > 1 ? '<div class="activityContainerAttachmentCount text-muted">' . ( $i + 1 ) . ' - ' . $count . '</div>' : null ) . '</div>' . '<div class="cbMoreLessOpen fade-edge hidden">' . '<a href="javascript: void(0);" class="cbMoreLessButton">' . CBTxt::T( 'See More' ) . '</a>' . '</div>' . '</div>' . '</div>'; } if ( $isStatus && ( $cbModerator || $rowOwner ) ) { $return .= '<div class="streamPanelFooter streamItemEdit activityContainerAttachmentInfo panel-footer' . ( $link['type'] == 'url' ? ' streamMediaBody media-body' : null ) . ' hidden">' . '<input type="text" id="' . $stream->id() . '_links_title_edit_' . (int) $row->get( 'id' ) . '_' . ( $i + 1 ) . '" name="links[' . $i . '][title]" value="' . htmlspecialchars( $link['title'] ) . '" class="streamInput streamInputLinkTitle form-control" placeholder="' . htmlspecialchars( CBTxt::T( 'Title' ) ) . '" />' . '<textarea id="' . $stream->id() . '_links_description_edit_' . (int) $row->get( 'id' ) . '_' . ( $i + 1 ) . '" name="links[' . $i . '][description]" rows="1" class="streamInput streamInputAutosize streamInputLinkDescription form-control" placeholder="' . htmlspecialchars( CBTxt::T( 'Description' ) ) . '">' . htmlspecialchars( $link['description'] ) . '</textarea>'; if ( $link['type'] == 'url' ) { $return .= '<div class="streamInput">' . '<label class="checkbox-inline">' . '<input type="checkbox" id="' . $stream->id() . '_links_thumbnail_edit_' . (int) $row->get( 'id' ) . '_' . ( $i + 1 ) . '" name="links[' . $i . '][thumbnail]" value="0"' . ( ! $link['thumbnail'] ? ' checked="checked"' : null ) . '> ' . CBTxt::T( 'Do not display thumbnail' ) . '</label>' . '</div>'; } $return .= '</div>'; } $return .= '</div>'; } $return .= '<div class="streamItemScrollRight' . ( $count > 1 ? null : ' hidden' ) . '">' . '<table>' . '<tr>' . '<td>' . '<span class="streamItemScrollRightIcon fa fa-chevron-right"></span>' . '</td>' . '</tr>' . '</table>' . '</div>' . '</div>'; return $return; }
/** * Returns an options array of available user tags with optional activity specific * * @param null|int|ActivityTable $activityId * @param null|int $userId * @return array */ static public function loadTagOptions( $activityId = null, $userId = null ) { global $_CB_database; /** @var ActivityTable[] $cache */ static $cache = array(); if ( $activityId && ( $userId === null ) ) { if ( $activityId instanceof ActivityTable ) { $activity = $activityId; $activityId = (int) $activity->get( 'id' ); } else { if ( ! isset( $cache[$activityId] ) ) { $activity = new ActivityTable(); $activity->load( (int) $activityId ); $cache[$activityId] = $activity; } $activity = $cache[$activityId]; } $userId = (int) $activity->get( 'user_id' ); } elseif ( $userId === null ) { $userId = Application::MyUser()->getUserId(); } static $connections = array(); static $custom = array(); static $options = array(); if ( ! isset( $options[$userId][$activityId] ) ) { if ( ! isset( $connections[$userId] ) ) { $connectionOptions = array(); if ( Application::Config()->get( 'allowConnections' ) ) { $cbConnection = new \cbConnection( $userId ); foreach( $cbConnection->getConnectedToMe( $userId ) as $connection ) { $connectionOptions[] = \moscomprofilerHTML::makeOption( (string) $connection->id, getNameFormat( $connection->name, $connection->username, Application::Config()->get( 'name_format', 3 ) ) ); } } $connections[$userId] = $connectionOptions; } if ( ! isset( $custom[$activityId] ) ) { $activityOptions = array(); if ( $activityId ) { $exclude = array(); foreach ( $connections[$userId] as $connection ) { $exclude[] = $connection->value; } $query = 'SELECT *' . "\n FROM " . $_CB_database->NameQuote( '#__comprofiler_plugin_activity_tags' ) . "\n WHERE " . $_CB_database->NameQuote( 'type' ) . " = " . $_CB_database->Quote( 'activity' ) . "\n AND " . $_CB_database->NameQuote( 'item' ) . " = " . (int) $activityId . "\n ORDER BY " . $_CB_database->NameQuote( 'date' ) . " ASC"; $_CB_database->setQuery( $query ); $tags = $_CB_database->loadObjectList( null, '\CB\Plugin\Activity\Table\TagTable', array( $_CB_database ) ); /** @var TagTable[] $tags */ foreach ( $tags as $tag ) { if ( ! in_array( $tag->get( 'user' ), $exclude ) ) { $activityOptions[] = \moscomprofilerHTML::makeOption( (string) $tag->get( 'user' ), $tag->get( 'user' ) ); } } } $custom[$activityId] = $activityOptions; } $options[$userId][$activityId] = array_merge( $connections[$userId], $custom[$activityId] ); } return $options[$userId][$activityId]; }
/** * Hides activity * * @param int $id * @param Activity $stream * @param UserTable $user * @param UserTable $viewer * @param bool $silent */ private function hideActivity( $id, $stream, $user, $viewer, $silent = false ) { $item = new ActivityTable(); $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' => 'activity', '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', 'activity' ); $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="activityContainerUnhide streamItemAction streamItemNoticeRevert">' . CBTxt::T( 'Unhide' ) . '</a>'; echo CBTxt::T( 'ACTIVITY_HIDDEN_UNHIDE', 'This activity has been hidden. [unhide]', array( '[unhide]' => $unhide ) ); } header( 'HTTP/1.0 200 OK' ); exit(); }
/** * @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; }