Skip to content
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

[Draft] Release 1.1.0 #38

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
### Fixed
- PHP 7.1 & 8.2 compatibility issue

## [1.1.0-rc1] - 2024-02-16
### Fixed
- Concrete CMS version 9.x compatibility

## [1.0.1] - 2023-03-24

- Fix php8 compatible issue due to core bug
Expand Down
6 changes: 6 additions & 0 deletions blocks/c5j_rating_btn/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions blocks/c5j_rating_page_list/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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', '', '!=');

Expand Down
459 changes: 248 additions & 211 deletions blocks/c5j_rating_page_list/page_list_form.php

Large diffs are not rendered by default.

46 changes: 36 additions & 10 deletions blocks/c5j_rating_page_list/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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()) {
?>
Expand Down Expand Up @@ -205,16 +225,22 @@ class="<?php echo h($buttonClasses) ?>"><?php echo h($buttonLinkText) ?></a>
} ?>
<script>
$(document).ready(function () {
let getUrl = "<?= URL::to($view->action('get_ratings')) ?>";
let params = {
token: "<?= $app->make('token')->generate('rating') ?>",
uID: getUserID(),
};

$('input[name^="pageIDs"]').each(function() {
params['cID'] = this.value;
getRatings(getUrl, params);
});
function setRate() {
const cIDs = [];
$('input[name^="pageIDs"]').each( function() {
cIDs.push(this.value);
});
if (cIDs.length > 0) {
const url = "<?= URL::to($view->action('get_ratings')) ?>";
const params = {
token: "<?= $app->make('token')->generate('rating') ?>",
uID: getUserID(),
cID: cIDs
};
updateRatings(url, params);
}
}
setRate();
});

function getUserID() {
Expand Down
2 changes: 1 addition & 1 deletion controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Controller extends Package
/**
* @var string package version
*/
protected $pkgVersion = '1.0.2';
protected $pkgVersion = '1.1.0-rc1';

protected $pkgAutoloaderRegistries = [
'src' => '\C5jRatings',
Expand Down
6 changes: 6 additions & 0 deletions js/c5j_ratings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ function updateRatings(url, params) {
type: 'post',
data: params,
success: function(data) {
if (Array.isArray(params['cID'])) {
data.forEach(function (item) {
updateRatingButtons(item);
});
return;
}
updateRatingButtons(data);
}
});
Expand Down
8 changes: 5 additions & 3 deletions single_pages/dashboard/ratings/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -11,6 +12,7 @@
$dh = $app->make('helper/date');
/** @var string $rated_date */
$rated_date = $rated_date ?? null;
$query = $query ?? '';
?>
<style>
.ratings-header-menu{
Expand All @@ -19,16 +21,16 @@
/*right: 35px;*/
}
div#ccm-dashboard-content-inner{
padding-top: 0px !important;
padding-top: 0 !important;
}
.ccm-header-search-form-input{
display: inline-block;
}
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
}
</style>
<?php
Expand Down
21 changes: 14 additions & 7 deletions src/Traits/RatingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,13 +36,20 @@ 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)) {
$cID = (int) $this->post('cID');
if ($this->validateToken('rating', $this->post('token'), $uID)) {
$ratings = [];
$cID = $this->post('cID');
if (is_array($cID)) {
foreach ($cID as $id) {
$ratings[] = $this->getRatings((int)$id, $uID);
}
} else {
$ratings = $this->getRatings((int)$cID, $uID);
}

return JsonResponse::create($this->getRatings($cID, $uID));
return JsonResponse::create($ratings);
}

return JsonResponse::create($this->token->getErrorMessage());
return JsonResponse::create($this->token->getErrorMessage());
}

public function generate($action = '', $time = null, $uID = 0): string
Expand All @@ -64,7 +71,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) {
Expand Down