| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCommunity\App\Http\Controllers; |
| 4 |
|
| 5 |
use FluentCommunity\App\Functions\Utility; |
| 6 |
use FluentCommunity\App\Hooks\Handlers\PortalHandler; |
| 7 |
use FluentCommunity\App\Models\BaseSpace; |
| 8 |
use FluentCommunity\App\Services\FeedsHelper; |
| 9 |
use FluentCommunity\App\Services\LockscreenService; |
| 10 |
use FluentCommunity\Framework\Http\Request\Request; |
| 11 |
|
| 12 |
class OptionController extends Controller |
| 13 |
{ |
| 14 |
|
| 15 |
public function getAppVars() |
| 16 |
{ |
| 17 |
$appVars = (new PortalHandler())->appVars(); |
| 18 |
unset($appVars['rest']); |
| 19 |
|
| 20 |
$data = [ |
| 21 |
'appVars' => $appVars, |
| 22 |
'menu_links_groups' => Utility::getPortalSidebarData('sidebar') |
| 23 |
]; |
| 24 |
|
| 25 |
return apply_filters('fluent_community/app_vars_api_response', $data, $this->request->all()); |
| 26 |
} |
| 27 |
|
| 28 |
public function getMenuItems() |
| 29 |
{ |
| 30 |
$data = Utility::getPortalSidebarData('sidebar'); |
| 31 |
return apply_filters('fluent_community/menu_items_api_response', $data, $this->request->all()); |
| 32 |
} |
| 33 |
|
| 34 |
public function getSidebarMenuHtml(Request $request) |
| 35 |
{ |
| 36 |
ob_start(); |
| 37 |
do_action('fluent_community/portal_sidebar', 'ajax'); |
| 38 |
|
| 39 |
$html = ob_get_clean(); |
| 40 |
|
| 41 |
$userModel = $this->getUser(); |
| 42 |
$userSpaces = []; |
| 43 |
if ($userModel) { |
| 44 |
if ($userModel->isCommunityModerator()) { |
| 45 |
$userSpaces = BaseSpace::orderBy('title', 'ASC') |
| 46 |
->get(); |
| 47 |
} else { |
| 48 |
$userSpaces = BaseSpace::orderBy('title', 'ASC') |
| 49 |
->whereHas('members', function ($q) { |
| 50 |
$q->where('user_id', get_current_user_id()) |
| 51 |
->where('status', 'active'); |
| 52 |
}) |
| 53 |
->get(); |
| 54 |
} |
| 55 |
|
| 56 |
BaseSpace::preloadMemberships($userSpaces, $userModel->ID); |
| 57 |
|
| 58 |
$userSpaces->each(function ($space) use ($userModel) { |
| 59 |
$space->permissions = $userModel->getSpacePermissions($space); |
| 60 |
$space->membership = $space->getMembership($userModel->ID); |
| 61 |
$space->description_rendered = wp_kses_post(FeedsHelper::mdToHtml($space->description)); |
| 62 |
if ($space->privacy == 'private' && !$space->membership) { |
| 63 |
$space->lockscreen_config = LockscreenService::getLockscreenConfig($space); |
| 64 |
} |
| 65 |
$space->topics = Utility::getTopicsBySpaceId($space->id); |
| 66 |
}); |
| 67 |
$userSpaces = $userSpaces->keyBy('slug'); |
| 68 |
} else { |
| 69 |
$userSpaces = (object)[]; |
| 70 |
} |
| 71 |
|
| 72 |
$data = [ |
| 73 |
'sidebar_html' => $html, |
| 74 |
'auth_spaces' => $userSpaces |
| 75 |
]; |
| 76 |
return apply_filters('fluent_community/sidebar_menu_html_api_response', $data, $request->all()); |
| 77 |
} |
| 78 |
} |
| 79 |
|