/** * returns a cached post object or adds existing posts to the cache * * @param int|WallTable[] $id * @return WallTable|null */ static public function getPost( $id ) { static $cache = array(); if ( is_array( $id ) ) { foreach ( $id as $row ) { /** @var WallTable $row */ $rowId = (int) $row->get( 'id' ); if ( ! $rowId ) { continue; } $cache[$rowId] = $row; } return null; } elseif ( ! $id ) { return new WallTable(); } elseif ( ! isset( $cache[$id] ) ) { $row = new WallTable(); $row->load( (int) $id ); $cache[$id] = $row; } return $cache[$id]; }
/** * render frontend wall activity * * @param CB\Plugin\Activity\Table\ActivityTable $row * @param string $title * @param string $message * @param CB\Plugin\Activity\Activity $stream * @param WallTable $post * @param cbgjWallPlugin $plugin * @return string */ static function showWallActivity( $row, &$title, &$message, $stream, $post, $plugin ) { global $_CB_framework; $title = CBTxt::T( 'GROUP_WALL_ACTIVITY_TITLE', 'posted in [group]', array( '[group]' => '<strong><a href="' . $_CB_framework->pluginClassUrl( $plugin->_gjPlugin->element, true, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $post->group()->get( 'id' ) ) ) . '">' . htmlspecialchars( CBTxt::T( $post->group()->get( 'name' ) ) ) . '</a></strong>' ) ); $message = $post->post(); return null; }
/** * render frontend wall edit * * @param WallTable $row * @param array $input * @param GroupTable $group * @param UserTable $user * @param CBplug_cbgroupjivewall $plugin * @return string */ static function showWallEdit( $row, $input, $group, $user, $plugin ) { global $_CB_framework, $_PLUGINS; $pageTitle = ( $row->get( 'id' ) ? CBTxt::T( 'Edit Post' ) : CBTxt::T( 'New Post' ) ); $_CB_framework->setPageTitle( $pageTitle ); cbValidator::loadValidation(); initToolTip(); $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $canModerate = ( CBGroupJive::getGroupStatus( $user, $group ) >= 2 ); $return = null; $_PLUGINS->trigger( 'gj_onBeforeDisplayWallEdit', array( &$return, &$row, &$input, $group, $user ) ); $return .= '<div class="gjWallEdit">' . '<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'wall', 'func' => 'save', 'id' => (int) $row->get( 'id' ) ) ) . '" method="post" enctype="multipart/form-data" name="gjWallEditForm" id="gjWallEditForm" class="cb_form gjWallEditForm form-auto cbValidation">' . ( $pageTitle ? '<div class="gjWallEditTitle page-header"><h3>' . $pageTitle . '</h3></div>' : null ); if ( $isModerator || $canModerate || ( $row->get( 'id' ) && ( $row->get( 'published' ) != -1 ) ) || ( $group->params()->get( 'wall', 1 ) != 2 ) ) { $return .= '<div class="cbft_select cbtt_select form-group cb_form_line clearfix">' . '<label for="published" class="col-sm-3 control-label">' . CBTxt::T( 'Published' ) . '</label>' . '<div class="cb_field col-sm-9">' . $input['published'] . getFieldIcons( null, 0, null, CBTxt::T( 'Select publish state of this post. Unpublished posts will not be visible to the public.' ) ) . '</div>' . '</div>'; } if ( $row->reply()->get( 'id' ) ) { $return .= '<div class="cbft_delimiter form-group cb_form_line clearfix">' . '<label class="col-sm-3 control-label">' . CBTxt::T( 'Reply' ) . '</label>' . '<div class="cb_field col-sm-9">' . $row->reply()->post() . '</div>' . '</div>'; } $return .= '<div class="cbft_textarea cbtt_textarea form-group cb_form_line clearfix">' . '<label for="post" class="col-sm-3 control-label">' . CBTxt::T( 'Post' ) . '</label>' . '<div class="cb_field col-sm-9">' . $input['post'] . getFieldIcons( null, 1, null, CBTxt::T( 'Input the post to share.' ) ) . '</div>' . '</div>'; if ( $isModerator ) { $return .= '<div class="cbft_text cbtt_input form-group cb_form_line clearfix">' . '<label for="user_id" class="col-sm-3 control-label">' . CBTxt::T( 'Owner' ) . '</label>' . '<div class="cb_field col-sm-9">' . $input['user_id'] . getFieldIcons( null, 1, null, CBTxt::T( 'Input the post owner id. Post owner determines the creator of the post specified as User ID.' ) ) . '</div>' . '</div>'; } $return .= '<div class="form-group cb_form_line clearfix cbtwolines">' . '<div class="col-sm-offset-3 col-sm-9">' . '<input type="submit" value="' . htmlspecialchars( ( $row->get( 'id' ) ? CBTxt::T( 'Update Post' ) : CBTxt::T( 'Post' ) ) ) . '" class="gjButton gjButtonSubmit btn btn-primary" ' . cbValidator::getSubmitBtnHtmlAttributes() . ' />' . ' <input type="button" value="' . htmlspecialchars( CBTxt::T( 'Cancel' ) ) . '" class="gjButton gjButtonCancel btn btn-default" onclick="cbjQuery.cbconfirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to cancel? All unsaved data will be lost!' ) ) . '\' ).done( function() { window.location.href = \'' . $_CB_framework->pluginClassUrl( $plugin->_gjPlugin->element, false, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '\'; })" />' . '</div>' . '</div>' . ( ! $row->get( 'id' ) ? '<input type="hidden" id="group" name="group" value="' . (int) $group->get( 'id' ) . '" />' : null ) . cbGetSpoofInputTag( 'plugin' ) . '</form>' . '</div>'; $_PLUGINS->trigger( 'gj_onAfterDisplayWallEdit', array( &$return, $row, $input, $group, $user ) ); $_CB_framework->setMenuMeta(); echo $return; }
/** * prepare frontend wall replies render * * @param WallTable $reply * @param GroupTable $group * @param UserTable $user * @return array|null */ public function showReplies( $reply, $group, $user ) { global $_CB_framework, $_CB_database; CBGroupJive::getTemplate( 'replies', true, true, $this->element ); $canModerate = ( CBGroupJive::isModerator( $user->get( 'id' ) ) || ( CBGroupJive::getGroupStatus( $user, $group ) >= 2 ) ); $limit = (int) $this->params->get( 'groups_wall_replies_limit', 15 ); $limitstart = $_CB_framework->getUserStateFromRequest( 'gj_group_wall_replies_limitstart{com_comprofiler}', 'gj_group_wall_replies_limitstart' ); if ( $reply->get( '_replies' ) ) { $query = 'SELECT COUNT(*)' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_wall' ) . " AS r" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = r.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE r." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND r." . $_CB_database->NameQuote( 'reply' ) . " = " . (int) $reply->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( r." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR r.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $_CB_database->setQuery( $query ); $total = (int) $_CB_database->loadResult(); } else { $total = 0; } if ( ( ! $total ) && ( ! CBGroupJive::canCreateGroupContent( $user, $group, 'wall' ) ) ) { return null; } $pageNav = new cbPageNav( $total, $limitstart, $limit ); $pageNav->setClasses( array( 'cbPaginationLinks' => 'cbPaginationLinks pagination pagination-sm' ) ); $pageNav->setInputNamePrefix( 'gj_group_wall_replies_' ); if ( $reply->get( '_replies' ) ) { switch( (int) $this->params->get( 'groups_wall_replies_orderby', 2 ) ) { case 1: $orderBy = 'r.' . $_CB_database->NameQuote( 'date' ) . ' ASC'; break; case 2: default: $orderBy = 'r.' . $_CB_database->NameQuote( 'date' ) . ' DESC'; break; } $query = 'SELECT r.*' . "\n FROM " . $_CB_database->NameQuote( '#__groupjive_plugin_wall' ) . " AS r" . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__comprofiler' ) . " AS cb" . ' ON cb.' . $_CB_database->NameQuote( 'id' ) . ' = r.' . $_CB_database->NameQuote( 'user_id' ) . "\n LEFT JOIN " . $_CB_database->NameQuote( '#__users' ) . " AS j" . ' ON j.' . $_CB_database->NameQuote( 'id' ) . ' = cb.' . $_CB_database->NameQuote( 'id' ) . "\n WHERE r." . $_CB_database->NameQuote( 'group' ) . " = " . (int) $group->get( 'id' ) . "\n AND r." . $_CB_database->NameQuote( 'reply' ) . " = " . (int) $reply->get( 'id' ) . "\n AND cb." . $_CB_database->NameQuote( 'approved' ) . " = 1" . "\n AND cb." . $_CB_database->NameQuote( 'confirmed' ) . " = 1" . "\n AND j." . $_CB_database->NameQuote( 'block' ) . " = 0"; if ( ! $canModerate ) { $query .= "\n AND ( r." . $_CB_database->NameQuote( 'user_id' ) . " = " . (int) $user->get( 'id' ) . ' OR r.' . $_CB_database->NameQuote( 'published' ) . ' = 1 )'; } $query .= "\n ORDER BY " . $orderBy; if ( $this->params->get( 'groups_wall_replies_paging', 1 ) ) { $_CB_database->setQuery( $query, $pageNav->limitstart, $pageNav->limit ); } else { $_CB_database->setQuery( $query ); } $rows = $_CB_database->loadObjectList( null, '\CB\Plugin\GroupJiveWall\Table\WallTable', array( $_CB_database ) ); CBGroupJiveWall::getPost( $rows ); CBGroupJive::preFetchUsers( $rows ); } else { $rows = array(); } return HTML_groupjiveWallReplies::showReplies( $reply, $rows, $pageNav, $group, $user, $this ); }
/** * render frontend replies * * @param WallTable $reply * @param WallTable[] $rows * @param cbPageNav $pageNav * @param GroupTable $group * @param UserTable $user * @param cbgjWallPlugin $plugin * @return string */ static function showReplies( $reply, $rows, $pageNav, $group, $user, $plugin ) { global $_CB_framework, $_PLUGINS; $isModerator = CBGroupJive::isModerator( $user->get( 'id' ) ); $messageLimit = ( ! $isModerator ? (int) $plugin->params->get( 'groups_wall_character_limit', 0 ) : 0 ); $js = "$( '.gjGroupWallNewReply:not(.gjGroupWallNewReplyOpen)' ).on( 'click', function() {" . "$( this ).find( '.gjGroupWallLimit,.gjGroupWallNewReplyFooter' ).removeClass( 'hidden' );" . "$( this ).addClass( 'gjGroupWallNewReplyOpen' );" . "$( this ).find( 'textarea' ).autosize({" . "append: ''," . "resizeDelay: 0," . "placeholder: false" . "});" . "});" . "$( '.gjGroupWallReplies .cbMoreLess' ).cbmoreless();"; if ( $messageLimit ) { $js .= "$( '.gjGroupWallNewReply textarea' ).on( 'keyup input change', function() {" . "var inputLength = $( this ).val().length;" . "if ( inputLength > " . (int) $messageLimit . " ) {" . "$( this ).val( $( this ).val().substr( 0, " . (int) $messageLimit . " ) );" . "} else {" . "$( this ).siblings( '.gjGroupWallLimit' ).find( '.gjGroupWallLimitCurrent' ).html( $( this ).val().length );" . "}" . "});"; } $_CB_framework->outputCbJQuery( $js, array( 'cbmoreless', 'autosize' ) ); $isOwner = ( $user->get( 'id' ) == $group->get( 'user_id' ) ); $userStatus = CBGroupJive::getGroupStatus( $user, $group ); $canCreate = CBGroupJive::canCreateGroupContent( $user, $group, 'wall' ); $return = null; $_PLUGINS->trigger( 'gj_onBeforeDisplayWall', array( &$return, &$rows, $group, $user ) ); $return .= '<div class="gjGroupWallReplies">' . '<div class="gjGroupWallRows">'; if ( $rows ) foreach ( $rows as $row ) { $menu = array(); $integrations = $_PLUGINS->trigger( 'gj_onDisplayWall', array( &$row, &$menu, $group, $user ) ); $cbUser = CBuser::getInstance( (int) $row->get( 'user_id' ), false ); $return .= '<div class="gjGroupWallRow">' . '<div class="gjGroupWallHeader media clearfix">' . '<div class="gjGroupWallAvatar media-left">' . $cbUser->getField( 'avatar', null, 'html', 'none', 'list', 0, true ) . '</div>' . '<div class="gjGroupWallDetails media-body">' . '<div class="cbMoreLess">' . '<div class="cbMoreLessContent">' . '<strong>' . $cbUser->getField( 'formatname', null, 'html', 'none', 'list', 0, true ) . '</strong> ' . $row->post() . '</div>' . '<div class="cbMoreLessOpen fade-edge hidden">' . '<a href="javascript: void(0);" class="cbMoreLessButton">' . CBTxt::T( 'See More' ) . '</a>' . '</div>' . '</div>' . '<div class="gjGroupWallDate text-muted small">' . cbFormatDate( $row->get( 'date' ), true, 'timeago' ) . '</div>' . '</div>' . '</div>' . ( is_array( $integrations ) && $integrations ? '<div class="gjGroupWallFooter panel-footer">' . implode( '', $integrations ) . '</div>' : null ); if ( $isModerator || $isOwner || ( $user->get( 'id' ) == $row->get( 'user_id' ) ) || ( $userStatus >= 2 ) || $menu ) { $menuItems = '<ul class="gjWallMenuItems dropdown-menu" style="display: block; position: relative; margin: 0;">'; if ( $isModerator || $isOwner || ( $user->get( 'id' ) == $row->get( 'user_id' ) ) || ( $userStatus >= 2 ) ) { $menuItems .= '<li class="gjWallMenuItem"><a href="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'wall', 'func' => 'edit', 'id' => (int) $row->get( 'id' ) ) ) . '"><span class="fa fa-edit"></span> ' . CBTxt::T( 'Edit' ) . '</a></li>'; if ( ( $row->get( 'published' ) == -1 ) && ( $group->params()->get( 'wall', 1 ) == 2 ) ) { if ( $isModerator || $isOwner || ( $userStatus >= 2 ) ) { $menuItems .= '<li class="gjWallMenuItem"><a href="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'wall', 'func' => 'publish', 'id' => (int) $row->get( 'id' ) ) ) . '"><span class="fa fa-check"></span> ' . CBTxt::T( 'Approve' ) . '</a></li>'; } } elseif ( $row->get( 'published' ) == 1 ) { $menuItems .= '<li class="gjWallMenuItem"><a href="javascript: void(0);" onclick="cbjQuery.cbconfirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to unpublish this Post?' ) ) . '\' ).done( function() { window.location.href = \'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'wall', 'func' => 'unpublish', 'id' => (int) $row->get( 'id' ) ) ) . '\'; })"><span class="fa fa-times-circle"></span> ' . CBTxt::T( 'Unpublish' ) . '</a></li>'; } else { $menuItems .= '<li class="gjWallMenuItem"><a href="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'wall', 'func' => 'publish', 'id' => (int) $row->get( 'id' ) ) ) . '"><span class="fa fa-check"></span> ' . CBTxt::T( 'Publish' ) . '</a></li>'; } } if ( $menu ) { $menuItems .= '<li class="gjWallMenuItem">' . implode( '</li><li class="gjWallMenuItem">', $menu ) . '</li>'; } if ( $isModerator || $isOwner || ( $user->get( 'id' ) == $row->get( 'user_id' ) ) || ( $userStatus >= 2 ) ) { $menuItems .= '<li class="gjWallMenuItem"><a href="javascript: void(0);" onclick="cbjQuery.cbconfirm( \'' . addslashes( CBTxt::T( 'Are you sure you want to delete this Post?' ) ) . '\' ).done( function() { window.location.href = \'' . $_CB_framework->pluginClassUrl( $plugin->element, false, array( 'action' => 'wall', 'func' => 'delete', 'id' => (int) $row->get( 'id' ) ) ) . '\'; })"><span class="fa fa-trash-o"></span> ' . CBTxt::T( 'Delete' ) . '</a></li>'; } $menuItems .= '</ul>'; $menuAttr = cbTooltip( 1, $menuItems, null, 'auto', null, null, null, 'class="btn btn-default btn-xs" data-cbtooltip-menu="true" data-cbtooltip-classes="qtip-nostyle"' ); $return .= '<div class="gjWallMenu btn-group">' . '<button type="button" ' . trim( $menuAttr ) . '><span class="fa fa-cog"></span> <span class="fa fa-caret-down"></span></button>' . '</div>'; } $return .= '</div>'; } if ( $plugin->params->get( 'groups_wall_paging', 1 ) && ( $pageNav->total > $pageNav->limit ) ) { $return .= '<div class="gjGroupWallRow gjGroupWallPaging text-center">' . '<form action="' . $_CB_framework->pluginClassUrl( $plugin->_gjPlugin->element, true, array( 'action' => 'groups', 'func' => 'show', 'id' => (int) $group->get( 'id' ) ) ) . '" method="post" name="gjGroupWallFormPaging" id="gjGroupWallFormPaging" class="gjGroupWallForm">' . $pageNav->getListLinks() . $pageNav->getLimitBox( false ) . '</form>' . '</div>'; } if ( $canCreate ) { $return .= '<div class="gjGroupWallRow gjGroupWallNewReply">' . '<form action="' . $_CB_framework->pluginClassUrl( $plugin->element, true, array( 'action' => 'wall', 'func' => 'save' ) ) . '" method="post" name="gjGroupWallFormNewReply' . (int) $reply->get( 'id' ) . '" id="gjGroupWallFormNewReply' . (int) $reply->get( 'id' ) . '" class="gjGroupWallForm cbValidation">'; if ( $messageLimit ) { $return .= '<div class="gjGroupWallLimit small hidden">' . '<div class="gjGroupWallLimitCurrent">0</div>' . ' / <div class="gjGroupWallLimitMax">' . (int) $messageLimit . '</div>' . '</div>'; } $return .= '<textarea name="post" rows="1" class="form-control required" placeholder="' . htmlspecialchars( CBTxt::T( 'Write a reply...' ) ) . '"' . ( $messageLimit ? ' maxlength="' . (int) $messageLimit . '"' : null ) . '></textarea>' . '<div class="gjGroupWallNewReplyFooter text-right hidden">' . '<button type="submit" class="gjButton gjButtonSubmit btn btn-primary btn-xs" ' . cbValidator::getSubmitBtnHtmlAttributes() . '>' . CBTxt::T( 'Reply' ) . '</button>' . '</div>' . '<input type="hidden" name="group" value="' . (int) $group->get( 'id' ) . '" />' . '<input type="hidden" name="reply" value="' . (int) $reply->get( 'id' ) . '" />' . cbGetSpoofInputTag( 'plugin' ) . '</form>' . '</div>'; } $return .= '</div>' . '</div>'; $_PLUGINS->trigger( 'gj_onAfterDisplayWall', array( &$return, $rows, $group, $user ) ); return $return; }