From 2a62d937b335b34eda2335603d027dfb53fbeeae Mon Sep 17 00:00:00 2001 From: Md Biplob Hossain Date: Fri, 16 Feb 2024 15:26:52 +0900 Subject: [PATCH 1/7] Fix validate method conflict --- src/Traits/RatingTrait.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Traits/RatingTrait.php b/src/Traits/RatingTrait.php index 5311e74..c414fe2 100644 --- a/src/Traits/RatingTrait.php +++ b/src/Traits/RatingTrait.php @@ -21,7 +21,7 @@ public function action_rate(int $bID) { $this->token = $this->app->make('helper/validation/token'); $uID = (int) $this->post('uID'); - if ($this->validate('rating', $this->post('token'), $uID)) { + if ($this->validateToken('rating', $this->post('token'), $uID)) { $cID = (int) $this->post('cID'); $ratedValue = $this->post('ratedValue'); $this->addRating($uID, $cID, $bID, $ratedValue); @@ -36,7 +36,7 @@ public function action_get_ratings(int $bID) { $this->token = $this->app->make('helper/validation/token'); $uID = (int) $this->post('uID'); - if ($this->validate('rating', $this->post('token'), $uID)) { + if ($this->validateToken('rating', $this->post('token'), $uID)) { $cID = (int) $this->post('cID'); return JsonResponse::create($this->getRatings($cID, $uID)); @@ -64,7 +64,7 @@ public function generate($action = '', $time = null, $uID = 0): string return $time . ':' . md5($time . ':' . $uID . ':' . $action . ':' . $config->get('concrete.security.token.validation')); } - public function validate($action = '', $token = null, $uID = 0): bool + public function validateToken($action = '', $token = null, $uID = 0): bool { $app = Application::getFacadeApplication(); if ($token === null) { From 5b78eec20f8e7c3705381fcdb7fd18413bac12b7 Mon Sep 17 00:00:00 2001 From: Md Biplob Hossain Date: Fri, 16 Feb 2024 17:20:45 +0900 Subject: [PATCH 2/7] Adopt changes from core page list block --- blocks/c5j_rating_page_list/controller.php | 8 + .../c5j_rating_page_list/page_list_form.php | 459 ++++++++++-------- 2 files changed, 256 insertions(+), 211 deletions(-) diff --git a/blocks/c5j_rating_page_list/controller.php b/blocks/c5j_rating_page_list/controller.php index 1fc6790..0bd18af 100644 --- a/blocks/c5j_rating_page_list/controller.php +++ b/blocks/c5j_rating_page_list/controller.php @@ -143,6 +143,7 @@ public function on_start() $this->list = new PageList(); $this->list->disableAutomaticSorting(); $this->list->setNameSpace('b' . $this->bID); + $expr = $this->list->getQueryObject()->expr(); // Get Query Expression Object $cArray = []; @@ -238,9 +239,16 @@ public function on_start() if ($this->displayAliases) { $this->list->includeAliases(); } + if ($this->displaySystemPages) { + $this->list->includeSystemPages(); + } if (isset($this->ignorePermissions) && $this->ignorePermissions) { $this->list->ignorePermissions(); } + if ($this->excludeCurrentPage) { + $ID = Page::getCurrentPage()->getCollectionID(); + $this->list->getQueryObject()->andWhere($expr->neq('p.cID', $ID)); + } $this->list->filter('cvName', '', '!='); diff --git a/blocks/c5j_rating_page_list/page_list_form.php b/blocks/c5j_rating_page_list/page_list_form.php index a9af7e0..dd5f0d7 100644 --- a/blocks/c5j_rating_page_list/page_list_form.php +++ b/blocks/c5j_rating_page_list/page_list_form.php @@ -1,10 +1,13 @@ get('concrete.version'); +$isV9 = version_compare($cmsVersion, '9.0.0', '>='); if (!isset($filterDateDays)) { $filterDateDays = false; @@ -105,6 +117,8 @@ $pageSelector = $app->make(PageSelector::class); /** @var UserInterface $userInterface */ $userInterface = $app->make(UserInterface::class); +/** @var Urls $urlService */ +$urlService = $app->make(Urls::class); /** @var Form $form */ $form = $app->make(Form::class); /** @var DateTime $dateTime */ @@ -119,23 +133,24 @@
+
label('num', t('Number of Pages to Display')); ?> - number("num", $num); ?> + number("num", $num, ['min' => 0]); ?>
t('** All')]; - /** @noinspection PhpUndefinedClassInspection */ - foreach (PageType::getList(false, $siteType) as $pageType) { - /** @var Type $pageType */ - $pageTypes[$pageType->getPageTypeID()] = $pageType->getPageTypeDisplayName(); - } + $pageTypes = ['0' => t('** All')]; + /** @noinspection PhpUndefinedClassInspection */ + foreach (PageType::getList(false, $siteType) as $pageType) { + /** @var Type $pageType */ + $pageTypes[$pageType->getPageTypeID()] = $pageType->getPageTypeDisplayName(); + } - echo $form->label('ptID', t('Page Type')); - echo $form->select("ptID", $pageTypes, $ptID); + echo $form->label('ptID', t('Page Type')); + echo $form->select("ptID", $pageTypes, $ptID); ?>
@@ -143,14 +158,17 @@
label('', t('Topics')); ?> +
radio("topicFilter", "", $topicFilter, ["id" => "topicFilter", "name" => "topicFilter"]); ?> label("topicFilter", t("No topic filtering"), ["class" => "form-check-label"]); ?>
+
radio("topicFilter", "custom", $topicFilter, ["id" => "topicFilterCustom", "name" => "topicFilter"]); ?> label("topicFilterCustom", t("Custom Topic"), ["class" => "form-check-label"]); ?>
+
radio("topicFilter", "related", $topicFilter, ["id" => "topicFilterRelated", "name" => "topicFilter"]); ?> label("topicFilterRelated", t("Related Topic"), ["class" => "form-check-label"]); ?> @@ -181,25 +199,26 @@ t('Choose topics attribute.') - ]; + $relatedTopicAttributeKeyHandles = [ + "" => t('Choose topics attribute.') + ]; - foreach ($attributeKeys as $attributeKey) { - $relatedTopicAttributeKeyHandles[$attributeKey->getAttributeKeyHandle()] = $attributeKey->getAttributeKeyDisplayName(); - } + foreach ($attributeKeys as $attributeKey) { + $relatedTopicAttributeKeyHandles[$attributeKey->getAttributeKeyHandle()] = $attributeKey->getAttributeKeyDisplayName(); + } - echo $form->select("relatedTopicAttributeKeyHandle", $relatedTopicAttributeKeyHandles, $relatedTopicAttributeKeyHandle); + echo $form->select("relatedTopicAttributeKeyHandle", $relatedTopicAttributeKeyHandles, $relatedTopicAttributeKeyHandle); ?> -
-
- + + t('Show All'), @@ -209,37 +228,49 @@ 'between' => t('Between'), ]; $i = 0; + ?> + + $filterDateOptionLabel) { ?> - foreach ($filterDateOptions as $filterDateOptionHandle => $filterDateOptionLabel) { - $isChecked = ($filterDateOption == $filterDateOptionHandle) ? 'checked' : ''; ?>
radio("filterDateOption", $filterDateOptionHandle, $filterDateOption, ["id" => $id, "name" => "filterDateOption", "class" => "form-check-input filterDateOption"]); ?> label($id, $filterDateOptionLabel, ["class" => "form-check-label"]); ?>
- +
- + + text("filterDatePast", $filterDateDays ? $filterDateDays : 0); ?>
- + + text("filterDateFuture", $filterDateDays ? $filterDateDays : 0); ?>
- date('filterDateStart', $filterDateStart); - echo '

' . t('and') . '

'; - echo $dateTime->date('filterDateEnd', $filterDateEnd); - ?> + date('filterDateStart', $filterDateStart); ?> + +

+ +

+ + date('filterDateEnd', $filterDateEnd); ?>
@@ -256,9 +287,7 @@
make('config'); - $codeVersion = $config->get('concrete.version'); - if (version_compare($codeVersion, '9.0.0', '<')) { + if ($isV9) { ?>
@@ -332,24 +361,39 @@
Note: You must create the "is_featured" page attribute first.)'); + '(Note: You must create the "is_featured" page attribute first.)'); ?>
+
checkbox("displayAliases", "1", $displayAliases); ?> label("displayAliases", t("Display page aliases."), ["class" => "form-check-label"]); ?>
+ +
+ checkbox("displaySystemPages", "1", $displaySystemPages); ?> + label("displaySystemPages", t("Display system pages."), ["class" => "form-check-label"]); ?> +
+
checkbox("ignorePermissions", "1", $ignorePermissions); ?> label("ignorePermissions", t("Ignore page permissions."), ["class" => "form-check-label"]); ?>
+
checkbox("enableExternalFiltering", "1", $enableExternalFiltering); ?> label("enableExternalFiltering", t("Enable Other Blocks to Filter This Page List."), ["class" => "form-check-label"]); ?> +
+
+ checkbox("excludeCurrentPage", "1", $excludeCurrentPage); ?> + label("excludeCurrentPage", t("Exclude Current Page"), ["class" => "form-check-label"]); ?> + +
+
@@ -362,6 +406,7 @@
+
label('', t('Location')); ?> @@ -403,233 +448,222 @@
+
label("orderBy", t('Sort')); - echo $form->select("orderBy", [ - "display_asc" => t('Sitemap order'), - "display_desc" => t('Reverse sitemap order'), - "chrono_desc" => t('Most recent first'), - "chrono_asc" => t('Earliest first'), - "alpha_asc" => t('Alphabetical order'), - "alpha_desc" => t('Reverse alphabetical order'), - "modified_desc" => t('Most recently modified first'), - "rated_desc" => t('Most rated first'), - "recently_rated_desc" => t('Most recently rated first'), - "random" => t('Random') - ], $orderBy); + echo $form->label("orderBy", t('Sort')); + echo $form->select("orderBy", [ + "display_asc" => t('Sitemap order'), + "display_desc" => t('Reverse sitemap order'), + "chrono_desc" => t('Most recent first'), + "chrono_asc" => t('Earliest first'), + "alpha_asc" => t('Alphabetical order'), + "alpha_desc" => t('Reverse alphabetical order'), + "modified_desc" => t('Most recently modified first'), + "rated_desc" => t('Most rated first'), + "recently_rated_desc" => t('Most recently rated first'), + "random" => t('Random') + ], $orderBy); ?>
+
+ + + -
- - - - -
- label("btnType", t('Button Type')); - echo $form->select("btnType", [ - "clap" => t('Clap'), - "heart" => t('Heart'), - "like" => t('Like') - ], $btnType); - ?> -
-
- -
- +
+ label("btnType", t('Button Type')); + echo $form->select("btnType", [ + "clap" => t('Clap'), + "heart" => t('Heart'), + "like" => t('Like') + ], $btnType); + ?>
-
- +
+ +
+ +
+
+ +
-
-
- +
+ -
- radio("rss", "0", is_object($rssFeed) ? '1' : '0', ["id" => "disableRssFeed", "name" => "rss", "class" => "form-check-input rssSelector"]); ?> - label("disableRssFeed", t("No"), ["class" => "form-check-label"]); ?> -
+
+ radio("rss", "0", is_object($rssFeed) ? '1' : '0', ["id" => "disableRssFeed", "name" => "rss", "class" => "form-check-input rssSelector"]); ?> + label("disableRssFeed", t("No"), ["class" => "form-check-label"]); ?> +
-
- radio("rss", "1", is_object($rssFeed) ? '1' : '0', ["id" => "enableRssFeed", "name" => "rss", "class" => "form-check-input rssSelector"]); ?> - label("enableRssFeed", t("Yes"), ["class" => "form-check-label"]); ?> -
+
+ radio("rss", "1", is_object($rssFeed) ? '1' : '0', ["id" => "enableRssFeed", "name" => "rss", "class" => "form-check-input rssSelector"]); ?> + label("enableRssFeed", t("Yes"), ["class" => "form-check-label"]); ?> +
-
> - - getFeedURL()) . '" target="_blank">' . $rssFeed->getFeedURL() . '') ?> - -
- label('num', t('RSS Feed Title')); ?> - text("rssTitle", $num, ["id" => "ccm-pagelist-rssTitle", "name" => "rssTitle"]); ?> -
+
> + + getFeedURL()) . '" target="_blank">' . $rssFeed->getFeedURL() . '') ?> + +
+ label('num', t('RSS Feed Title')); ?> + text("rssTitle", $num, ["id" => "ccm-pagelist-rssTitle", "name" => "rssTitle"]); ?> +
-
- label("rssDescription", ('RSS Feed Description')); ?> - textarea("rssDescription"); ?> -
+
+ label("rssDescription", ('RSS Feed Description')); ?> + textarea("rssDescription"); ?> +
-
- label('', t('RSS Feed Location')); ?> +
+ label('', t('RSS Feed Location')); ?> -
- - / - +
+ + / + - text("rssHandle"); ?> + text("rssHandle"); ?> +
-
- + +
-
-
- +
+ -
- radio("includeName", "0", $includeName ? '1' : '0', ["id" => "disableIncludeName", "name" => "includeName"]); ?> - label("disableIncludeName", t("No"), ["class" => "form-check-label"]); ?> -
+
+ radio("disableIncludeName", "0", $includeName ? '1' : '0', ["id" => "disableIncludeName", "name" => "includeName"]); ?> + label("disableIncludeName", t("No"), ["class" => "form-check-label"]); ?> +
-
- radio("includeName", "1", $includeName ? '1' : '0', ["id" => "enableIncludeName", "name" => "includeName"]); ?> - label("enableIncludeName", t("Yes"), ["class" => "form-check-label"]); ?> +
+ radio("enableIncludeName", "1", $includeName ? '1' : '0', ["id" => "enableIncludeName", "name" => "includeName"]); ?> + label("enableIncludeName", t("Yes"), ["class" => "form-check-label"]); ?> +
-
-
- +
+ -
- radio("includeDescription", "0", $includeDescription ? '1' : '0', ["id" => "disableIncludeDescription", "name" => "includeDescription"]); ?> - label("disableIncludeDescription", t("No"), ["class" => "form-check-label"]); ?> -
+
+ radio("includeDescription", "0", $includeDescription ? '1' : '0', ["id" => "disableIncludeDescription", "name" => "includeDescription"]); ?> + label("disableIncludeDescription", t("No"), ["class" => "form-check-label"]); ?> +
-
- radio("includeDescription", "1", $includeDescription ? '1' : '0', ["id" => "enableIncludeDescription", "name" => "includeDescription"]); ?> - label("enableIncludeDescription", t("Yes"), ["class" => "form-check-label"]); ?> -
+
+ radio("includeDescription", "1", $includeDescription ? '1' : '0', ["id" => "enableIncludeDescription", "name" => "includeDescription"]); ?> + label("enableIncludeDescription", t("Yes"), ["class" => "form-check-label"]); ?> +
-
> - -
- - make('config'); - $codeVersion = $config->get('concrete.version'); - if (version_compare($codeVersion, '9.0.0', '<')) { - ?> - - /> - - - type="text" name="truncateChars" size="3" value="" /> - - - - - +
> + + +
+ + /> - - "ccm-pagelist-truncateChars", "name" => "truncateChars", "step" => 1, "min" => 0]; - - if (!$truncateSummaries) { - $miscFields["disabled"] = "disabled"; - } - - echo $form->number("truncateChars", (int)$truncateChars, $miscFields); - ?> - + "ccm-pagelist-truncateChars", "name" => "truncateChars", "step" => 1, "min" => 0]; + if (!$truncateSummaries) { + $miscFields["disabled"] = "disabled"; + } + echo $form->number("truncateChars", (int)$truncateChars, $miscFields); + } else { + ?> + + type="text" name="truncateChars" size="3" value="" /> + + + - +
- +
label('', t('Include Public Page Date')); ?> - +
radio("includeDate", "0", $includeDate ? '1' : '0', ["id" => "disableIncludeDate", "name" => "includeDate"]); ?> label("disableIncludeDate", t("No"), ["class" => "form-check-label"]); ?>
- +
radio("includeDate", "1", $includeDate ? '1' : '0', ["id" => "enableIncludeDate", "name" => "includeDate"]); ?> label("enableIncludeDate", t("Yes"), ["class" => "form-check-label"]); ?>
- +
- +
- +
radio("displayThumbnail", "0", $displayThumbnail ? '1' : '0', ["id" => "disableIncludeThumbnail", "name" => "displayThumbnail"]); ?> label("disableIncludeThumbnail", t("No"), ["class" => "form-check-label"]); ?>
- +
radio("displayThumbnail", "1", $displayThumbnail ? '1' : '0', ["id" => "enableIncludeThumbnail", "name" => "displayThumbnail"]); ?> label("enableIncludeThumbnail", t("Yes"), ["class" => "form-check-label"]); ?>
- +
- +
- +
radio("useButtonForLink", "0", $useButtonForLink ? '1' : '0', ["id" => "disableUseButtonForLink", "name" => "useButtonForLink"]); ?> label("disableUseButtonForLink", t("No"), ["class" => "form-check-label"]); ?>
- +
radio("useButtonForLink", "1", $useButtonForLink ? '1' : '0', ["id" => "enableUseButtonForLink", "name" => "useButtonForLink"]); ?> label("enableUseButtonForLink", t("Yes"), ["class" => "form-check-label"]); ?>
- +
>
label('buttonLinkText', t('Link Text')); ?> @@ -637,39 +671,34 @@
- +
label('pageListTitle', t('Title of Page List')); ?> - - make('config'); - $codeVersion = $config->get('concrete.version'); - if (version_compare($codeVersion, '9.0.0', '>')) { - ?> -
- text("pageListTitle", $pageListTitle); ?> - select('titleFormat', \Concrete\Core\Block\BlockController::$btTitleFormats, $titleFormat, array('style' => 'width:105px;flex-grow:0;', 'class' => 'form-select')); ?> -
- text("pageListTitle", $pageListTitle); - } - ?> - + +
+ text("pageListTitle", $pageListTitle); ?> + select('titleFormat', \Concrete\Core\Block\BlockController::$btTitleFormats, $titleFormat ?? null, array('style' => 'width:105px;flex-grow:0;', 'class' => 'form-select')); ?> +
+ text("pageListTitle", $pageListTitle); + } + ?>
- label("noResultsMessage", ('Message to Display When No Pages Listed.')); ?> + label("noResultsMessage", t('Message to Display When No Pages Listed')); ?> textarea("noResultsMessage", $noResultsMessage); ?>
- +
-
@@ -679,8 +708,8 @@
+ + + From 44d595b5b0ed7497d22c43bc31e366bd59c855e6 Mon Sep 17 00:00:00 2001 From: Md Biplob Hossain Date: Fri, 16 Feb 2024 17:21:06 +0900 Subject: [PATCH 3/7] Remove redundant values --- single_pages/dashboard/ratings/view.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/single_pages/dashboard/ratings/view.php b/single_pages/dashboard/ratings/view.php index 252caa0..a761f4a 100644 --- a/single_pages/dashboard/ratings/view.php +++ b/single_pages/dashboard/ratings/view.php @@ -19,7 +19,7 @@ /*right: 35px;*/ } div#ccm-dashboard-content-inner{ - padding-top: 0px !important; + padding-top: 0 !important; } .ccm-header-search-form-input{ display: inline-block; @@ -27,8 +27,8 @@ ul.ccm-header-search-navigation { list-style: none; text-align: right; - padding: 4px 0px 0px 0px; - margin:0px 0px 0px 0px + padding: 4px 0 0 0; + margin:0 0 0 0 } Date: Fri, 16 Feb 2024 17:27:29 +0900 Subject: [PATCH 4/7] Fix undefined variables --- blocks/c5j_rating_btn/view.php | 6 ++++++ blocks/c5j_rating_page_list/view.php | 20 ++++++++++++++++++++ single_pages/dashboard/ratings/view.php | 2 ++ 3 files changed, 28 insertions(+) diff --git a/blocks/c5j_rating_btn/view.php b/blocks/c5j_rating_btn/view.php index 048a629..232e1c2 100644 --- a/blocks/c5j_rating_btn/view.php +++ b/blocks/c5j_rating_btn/view.php @@ -7,6 +7,12 @@ use Concrete\Core\Support\Facade\Facade; use Concrete\Core\Support\Facade\Url; use Concrete\Core\Page\Page; + +/** @var \Concrete\Core\View\View $view */ + +$bID = $bID ?? 0; +$displayRatings = $displayRatings ?? false; + $app = Facade::getFacadeApplication(); $btnType = $btnType ?? 'clap'; $cID = Page::getCurrentPage()->getCollectionID(); diff --git a/blocks/c5j_rating_page_list/view.php b/blocks/c5j_rating_page_list/view.php index 838299d..16bcb3f 100644 --- a/blocks/c5j_rating_page_list/view.php +++ b/blocks/c5j_rating_page_list/view.php @@ -2,6 +2,10 @@ defined('C5_EXECUTE') or die('Access Denied.'); use Concrete\Core\Page\Page; +/** @var \Concrete\Package\C5jRatings\Block\C5jRatingPageList\Controller $controller */ +/** @var \Concrete\Core\View\View $view */ + +$bID = $bID ?? 0; $c = Page::getCurrentPage(); $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); /** @var \Concrete\Core\Utility\Service\Text $th */ @@ -10,6 +14,22 @@ $dh = $app->make('helper/date'); $pages = $pages ?? []; $showPagination = $showPagination ?? []; +$pagination = $pagination ?? ''; +$noResultsMessage = $noResultsMessage ?? ''; +$titleFormat = $titleFormat ?? 'h3'; +$displayThumbnail = $displayThumbnail ?? false; +$truncateSummaries = $truncateSummaries ?? false; +$truncateChars = $truncateChars ?? 300; +$includeName = $includeName ?? true; +$includeDate = $includeDate ?? true; +$includeDescription = $includeDescription ?? true; +$useButtonForLink = $useButtonForLink ?? false; +$buttonLinkText = $buttonLinkText ?? t('Read More'); +$includeEntryText = false; +$btnType = $btnType ?? 'clap'; +$displayRatings = $displayRatings ?? false; +$ratings = $ratings ?? []; + if (is_object($c) && $c->isEditMode() && $controller->isBlockEmpty()) { ?> diff --git a/single_pages/dashboard/ratings/view.php b/single_pages/dashboard/ratings/view.php index a761f4a..829adaa 100644 --- a/single_pages/dashboard/ratings/view.php +++ b/single_pages/dashboard/ratings/view.php @@ -2,6 +2,7 @@ defined('C5_EXECUTE') or die('Access Denied.'); use Concrete\Core\User\UserInfoRepository; +/** @var \Concrete\Core\View\View $view */ $app = \Concrete\Core\Support\Facade\Application::getFacadeApplication(); /* @var Concrete\Core\Form\Service\Form $form */ $form = $app->make('helper/form'); @@ -11,6 +12,7 @@ $dh = $app->make('helper/date'); /** @var string $rated_date */ $rated_date = $rated_date ?? null; +$query = $query ?? ''; ?>