Skip to content

Issues-226 #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
227 changes: 210 additions & 17 deletions config/vanilla/bootstrap.before.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,21 +410,17 @@ function updateRolePermissions($roleType, $roles) {
* ** 'param': URL parameter associated with the filter.
* ** 'value': A value for the URL parameter.
* @param string $extraClasses any extra classes you add to the drop down
* @param string|null $default The default label for when no filter is active. If `null`, the default label is "All".
* @param string|null $default The default label for when no filter is active. If `null`, the default label is not added
* @param string|null $defaultURL URL override to return to the default, unfiltered state.
* @param string $label Text for the label to attach to the cont
* @return string
*/
function sortsDropDown($baseUrl, array $filters = [], $extraClasses = '', $default = null, $defaultUrl = null, $label = 'Sort') {
if ($default === null) {
$default = t('All');
}

$links = [];
$active = paramPreference(
'sort',
'CategorySort',
null,//'Vanilla.SaveCategorySortPreference',
null,
null,
false
);
Expand Down Expand Up @@ -462,12 +458,15 @@ function sortsDropDown($baseUrl, array $filters = [], $extraClasses = '', $defau
$links[] = $link;
}

// Add the default link to the top of the list.
array_unshift($links, [
'active' => $active === null,
'name' => $default,
'url' => $defaultUrl ?: $baseUrl
]);
if ($default !== null) {
$default = t('All');
// Add the default link to the top of the list.
array_unshift($links, [
'active' => $active === null,
'name' => $default,
'url' => $defaultUrl ?: $baseUrl
]);
}

// Generate the markup for the drop down menu.
$output = linkDropDown($links, 'selectBox-following ' . trim($extraClasses), t($label) . ': ');
Expand All @@ -487,7 +486,8 @@ function categorySorts($extraClasses = '') {
return;
}

$baseUrl = Gdn::request()->path();
$baseUrl = Gdn::request()->getFullPath();

$transientKey = Gdn::session()->transientKey();
$filters = [
[
Expand Down Expand Up @@ -520,7 +520,7 @@ function categorySorts($extraClasses = '') {
$baseUrl,
$filters,
$extraClasses,
t('All'),
null,
$defaultUrl,
'Sort'
);
Expand All @@ -539,7 +539,7 @@ function discussionSorts($extraClasses = '') {
return;
}

$baseUrl = Gdn::request()->path();
$baseUrl = Gdn::request()->getFullPath();
$transientKey = Gdn::session()->transientKey();

$filters = [
Expand All @@ -560,7 +560,7 @@ function discussionSorts($extraClasses = '') {

$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
if (Gdn::request()->get('sort')) {
$defaultParams['sort'] = Gdn::request()->get('sort');
$defaultParams['sort'] = '';
}

if (!empty($defaultParams)) {
Expand All @@ -573,11 +573,204 @@ function discussionSorts($extraClasses = '') {
$baseUrl,
$filters,
$extraClasses,
t('All'),
null,
$defaultUrl,
'Sort'
);
}
}

if (!function_exists('discussionFilters')) {
/**
*
* FIX: https://github.com/topcoder-platform/forums/issues/226
* The source is package/library/core/functions.render.php
* Returns discussions filtering.
*
* @param string $extraClasses any extra classes you add to the drop down
* @return string
*/
function discussionFilters($extraClasses = '') {
if (!Gdn::session()->isValid()) {
return;
}

$baseUrl = Gdn::request()->getFullPath();
$transientKey = Gdn::session()->transientKey();
$filters = [
[
'name' => t('All'),
'param' => 'followed',
'value' => 0,
'extra' => ['save' => 1, 'TransientKey' => $transientKey]
],
[
'name' => t('Following'),
'param' => 'followed',
'value' => 1,
'extra' => ['save' => 1, 'TransientKey' => $transientKey]
]
];

$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
if (Gdn::request()->get('followed')) {
$defaultParams['followed'] = '';
}

if (!empty($defaultParams)) {
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
} else {
$defaultUrl = $baseUrl;
}

return filtersDropDown(
$baseUrl,
$filters,
$extraClasses,
null,
$defaultUrl,
'View'
);
}
}

if (!function_exists('categoryFilters')) {
/**
*
* FIX: https://github.com/topcoder-platform/forums/issues/226
* The source is package/library/core/functions.render.php
*
* Returns category filtering.
*
* @param string $extraClasses any extra classes you add to the drop down
* @return string
*/
function categoryFilters($extraClasses = '') {
if (!Gdn::session()->isValid()) {
return;
}

$baseUrl = Gdn::request()->getFullPath();
$transientKey = Gdn::session()->transientKey();
$filters = [
[
'name' => t('All'),
'param' => 'followed',
'value' => 0,
'extra' => ['save' => 1, 'TransientKey' => $transientKey]
],

[
'name' => t('Following'),
'param' => 'followed',
'value' => 1,
'extra' => ['save' => 1, 'TransientKey' => $transientKey]
]
];

$defaultParams = ['save' => 1, 'TransientKey' => $transientKey];
if (Gdn::request()->get('followed')) {
$defaultParams['followed'] = '';
}

if (!empty($defaultParams)) {
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
} else {
$defaultUrl = $baseUrl;
}

return filtersDropDown(
$baseUrl,
$filters,
$extraClasses,
null,
$defaultUrl,
'View'
);
}
}

if (!function_exists('filtersDropDown')) {
/**
* FIX: https://github.com/topcoder-platform/forums/issues/226
* The source is package/library/core/functions.render.php
*
* Returns a filtering drop-down menu.
*
* @param string $baseUrl Target URL with no query string applied.
* @param array $filters A multidimensional array of rows with the following properties:
* ** 'name': Friendly name for the filter.
* ** 'param': URL parameter associated with the filter.
* ** 'value': A value for the URL parameter.
* @param string $extraClasses any extra classes you add to the drop down
* @param string|null $default The default label for when no filter is active. If `null`, the default label is "All".
* @param string|null $defaultURL URL override to return to the default, unfiltered state.
* @param string $label Text for the label to attach to the cont
* @return string
*/
function filtersDropDown($baseUrl, array $filters = [], $extraClasses = '', $default = null, $defaultUrl = null, $label = 'View') {

$output = '';

if (c('Vanilla.EnableCategoryFollowing')) {
$links = [];
$active = paramPreference(
'followed',
'FollowedCategories',
'Vanilla.SaveFollowingPreference',
null,
false
);

// Translate filters into links.
foreach ($filters as $filter) {
// Make sure we have the bare minimum: a label and a URL parameter.
if (!array_key_exists('name', $filter)) {
throw new InvalidArgumentException('Filter does not have a name field.');
}
if (!array_key_exists('param', $filter)) {
throw new InvalidArgumentException('Filter does not have a param field.');
}

// Prepare for consumption by linkDropDown.
$value = $filter['value'];
$query = [$filter['param'] => $value];
if (array_key_exists('extra', $filter) && is_array($filter['extra'])) {
$query += $filter['extra'];
}
$url = url($baseUrl.'?'.http_build_query($query));
$link = [
'name' => $filter['name'],
'url' => $url
];

// If we don't already have an active link, and this parameter and value match, this is the active link.
if ($active === null && Gdn::request()->get($filter['param']) == $filter['value']) {
$active = $filter['value'];
$link['active'] = true;
} else if ($active == $filter['value']){
$link['active'] = true;
$active = $filter['value'];
}

// Queue up another filter link.
$links[] = $link;
}

if ($default !== null) {
$default = t('All');

// Add the default link to the top of the list.
array_unshift($links, [
'active' => $active === null,
'name' => $default,
'url' => $defaultUrl ?: $baseUrl
]);
}
// Generate the markup for the drop down menu.
$output = linkDropDown($links, 'selectBox-following '.trim($extraClasses), t($label).': ');
}

return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,18 @@ private function getOptions($category) {
public function index($categoryIdentifier = '', $page = '0') {
// Figure out which category layout to choose (Defined on "Homepage" settings page).
$layout = c('Vanilla.Categories.Layout');
$this->log('index: $categoryIdentifier='.$categoryIdentifier, []);
if ($this->CategoryModel->followingEnabled()) {

$followingEnabled = true;//$this->CategoryModel->followingEnabled();
if ($followingEnabled) {
// Only use the following filter on the root category level.
// Show always
// The view filter is shown always
$this->enableFollowingFilter = true;//$categoryIdentifier === '';
$this->fireEvent('EnableFollowingFilter', [
'CategoryIdentifier' => $categoryIdentifier,
'EnableFollowingFilter' => &$this->enableFollowingFilter
]);

$saveFollowing = Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));
$saveFollowing = Gdn::request()->get('followed') && Gdn::request()->get('save') && Gdn::session()->validateTransientKey(Gdn::request()->get('TransientKey', ''));

$followed = paramPreference(
'followed',
Expand All @@ -300,7 +301,6 @@ public function index($categoryIdentifier = '', $page = '0') {
$saveSorting
);

$this->log('index: sorts: after', ['$sort' => $sort, '$saveSorting'=>$saveSorting]);
$this->setData('CategorySort', $sort);

if ($categoryIdentifier == '') {
Expand Down Expand Up @@ -528,7 +528,6 @@ public function index($categoryIdentifier = '', $page = '0') {
* @access public
*/
public function all($Category = '', $displayAs = '') {
$this->log('all:args($Category='.$Category.')');
// Setup head.
$this->Menu->highlightRoute('/discussions');
if (!$this->title()) {
Expand Down
Loading