Verlinkung für Top-Modul eingebaut

This commit is contained in:
Carsten Götzinger 2017-03-31 10:41:53 +02:00
parent 8ca4aad975
commit fb9540fe2e
6 changed files with 142 additions and 19 deletions

View File

@ -35,7 +35,7 @@ namespace cgoIT\rateit;
*/ */
class RateItTopRatingsModule extends RateItFrontend class RateItTopRatingsModule extends RateItFrontend
{ {
//protected $intStars = 5; private static $arrUrlCache = array();
/** /**
* Initialize the controller * Initialize the controller
@ -123,6 +123,8 @@ class RateItTopRatingsModule extends RateItFrontend
$return->rateit_class = 'rateItRating'; $return->rateit_class = 'rateItRating';
$return->url = $this->getUrl($result);
// Beschriftung ermitteln // Beschriftung ermitteln
$rating = array(); $rating = array();
$rating['totalRatings'] = $result['most']; $rating['totalRatings'] = $result['most'];
@ -137,6 +139,103 @@ class RateItTopRatingsModule extends RateItFrontend
$this->Template->arrRatings = $objReturn; $this->Template->arrRatings = $objReturn;
} }
private function getUrl($rating) {
if ($rating['typ'] === 'page') {
return \PageModel::findById($rating['rkey'])->getAbsoluteUrl();
}
if ($rating['typ'] === 'article') {
$objArticle = \ArticleModel::findPublishedById($rating['rkey']);
if (!is_null($objArticle)) {
return \PageModel::findById($objArticle->pid)->getAbsoluteUrl().'#'.$objArticle->alias;
}
}
if ($rating['typ'] === 'news') {
$objNews = \NewsModel::findById($rating['rkey']);
$objArticle = \NewsModel::findPublishedByPid($objNews->pid);
// Internal link
if ($objArticle->source != 'external') {
return $this->generateNewsUrl($objNews);
}
// Encode e-mail addresses
if (substr($objArticle->url, 0, 7) == 'mailto:') {
$strArticleUrl = \StringUtil::encodeEmail($objArticle->url);
}
// Ampersand URIs
else {
$strArticleUrl = ampersand($objArticle->url);
}
/** @var \PageModel $objPage */
global $objPage;
// External link
return $strArticleUrl;
}
return false;
}
private function generateNewsUrl($objItem) {
$strCacheKey = 'id_' . $objItem->id;
// Load the URL from cache
if (isset(self::$arrUrlCache[$strCacheKey])) {
return self::$arrUrlCache[$strCacheKey];
}
// Initialize the cache
self::$arrUrlCache[$strCacheKey] = null;
switch ($objItem->source) {
// Link to an external page
case 'external' :
if (substr($objItem->url, 0, 7) == 'mailto:') {
self::$arrUrlCache[$strCacheKey] = \StringUtil::encodeEmail($objItem->url);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($objItem->url);
}
break;
// Link to an internal page
case 'internal' :
if (($objTarget = $objItem->getRelated('jumpTo')) !== null) {
/** @var \PageModel $objTarget */
self::$arrUrlCache[$strCacheKey] = ampersand($objTarget->getFrontendUrl());
}
break;
// Link to an article
case 'article' :
if (($objArticle = \ArticleModel::findByPk($objItem->articleId, array(
'eager' => true
))) !== null && ($objPid = $objArticle->getRelated('pid')) !== null) {
/** @var \PageModel $objPid */
self::$arrUrlCache[$strCacheKey] = ampersand($objPid->getFrontendUrl('/articles/' . ((! \Config::get('disableAlias') && $objArticle->alias != '') ? $objArticle->alias : $objArticle->id)));
}
break;
}
// Link to the default page
if (self::$arrUrlCache[$strCacheKey] === null) {
$objPage = \PageModel::findWithDetails($objItem->getRelated('pid')->jumpTo);
if ($objPage === null) {
self::$arrUrlCache[$strCacheKey] = ampersand(\Environment::get('request'), true);
} else {
self::$arrUrlCache[$strCacheKey] = ampersand($objPage->getFrontendUrl(((\Config::get('useAutoItem') && ! \Config::get('disableAlias')) ? '/' : '/items/') . ((! \Config::get('disableAlias') && $objItem->alias != '') ? $objItem->alias : $objItem->id)));
}
// Add the current archive parameter (news archive)
if ($blnAddArchive && \Input::get('month') != '') {
self::$arrUrlCache[$strCacheKey] .= (\Config::get('disableAlias') ? '&' : '?') . 'month=' . \Input::get('month');
}
}
return self::$arrUrlCache[$strCacheKey];
}
} }
?> ?>

View File

@ -14,18 +14,19 @@
], ],
"support": { "support": {
"email": "info@cgo-it.de", "email": "info@cgo-it.de",
"issues": "https://git.cgo-it.de/contao/rate-it/issues", "issues": "https://bitbucket.org/cgo-it/contao-rate-it/issues?status=new&status=open",
"forum": "https://community.contao.org/de/showthread.php?38471-Rate-It", "forum": "https://community.contao.org/de/showthread.php?38471-Rate-It",
"source": "https://git.cgo-it.de/contao/rate-it/tree/master" "source": "https://bitbucket.org/cgo-it/contao-rate-it/src"
}, },
"require":{ "require":{
"php":">=5.3", "php":">=5.3",
"contao/core":">=3.0", "contao/core":">=3.0",
"contao-community-alliance/composer-plugin": "~2.0", "contao-community-alliance/composer-plugin": "~2.0",
"leounglaub/contao-simple-ajax":"3.2.x-dev",
"cgo-it/xls_export":"3.0.0" "cgo-it/xls_export":"3.0.0"
}, },
"replace": { "replace": {
"cgo-it/rate-it": "<3.5.4" "cgo-it/rate-it": "<3.4.3"
}, },
"conflict": { "conflict": {
"contao/core": "2.11.*" "contao/core": "2.11.*"

View File

@ -15,6 +15,15 @@
height: 16px; height: 16px;
} }
.ce_rateit_top_ratings .rateItContainer {
display: inline-block;
width: 100%;
}
.ce_rateit_top_ratings .rateItTitle {
float: left;
}
.rateItRating[rel="not-rateable"] { .rateItRating[rel="not-rateable"] {
float: right; float: right;
} }

View File

@ -1 +1 @@
.rateItRating{position:relative;display:inline-block}.mbrateItRating{position:relative;opacity:1}.mbrateItRating .wrapper,.rateItRating .wrapper{cursor:pointer;position:relative;diplay:inline-block;height:16px}.rateItRating[rel=not-rateable]{float:right}.rateItRating[rel=not-rateable] .wrapper{cursor:default}div.mod_rateit_top_ratings ul{padding:0}div.mod_rateit_top_ratings li{list-style-type:none}div.mod_rateit_top_ratings div.rateItTitle{display:inline-block;max-width:40%;min-height:30px}div.mbrateItRating div.rateItRating-hover,div.mbrateItRating div.rateItRating-selected,div.rateItRating div.rateItRating-hover,div.rateItRating div.rateItRating-selected{position:absolute}.rateItRating .ratingText{color:#000}.mbrateItRating .mbratingText{display:inline-block;color:#ccc}.ratingText.ratingError{color:red}.mbrateItRating .mbratingText.loading,.rateItRating .ratingText.loading{background:url("../images/ajax-loading.gif") no-repeat}span.rating-microdata{display:none} .rateItRating{position:relative;display:inline-block}.mbrateItRating{position:relative;opacity:1}.mbrateItRating .wrapper,.rateItRating .wrapper{cursor:pointer;position:relative;diplay:inline-block;height:16px}.ce_rateit_top_ratings .rateItContainer{display:inline-block;width:100%;}.ce_rateit_top_ratings .rateItTitle{float: left;}.rateItRating[rel=not-rateable]{float:right}.rateItRating[rel=not-rateable] .wrapper{cursor:default}div.mod_rateit_top_ratings ul{padding:0}div.mod_rateit_top_ratings li{list-style-type:none}div.mod_rateit_top_ratings div.rateItTitle{display:inline-block;max-width:40%;min-height:30px}div.mbrateItRating div.rateItRating-hover,div.mbrateItRating div.rateItRating-selected,div.rateItRating div.rateItRating-hover,div.rateItRating div.rateItRating-selected{position:absolute}.rateItRating .ratingText{color:#000}.mbrateItRating .mbratingText{display:inline-block;color:#ccc}.ratingText.ratingError{color:red}.mbrateItRating .mbratingText.loading,.rateItRating .ratingText.loading{background:url("../images/ajax-loading.gif") no-repeat}span.rating-microdata{display:none}

View File

@ -1,21 +1,29 @@
<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>> <div class="<?= $this->class ?> block"<?= $this->cssID ?><?php if ($this->style): ?> style="<?= $this->style ?>"<?php endif; ?>>
<?php if ($this->headline): ?> <?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>> <<?= $this->hl ?>><?= $this->headline ?></<?= $this->hl ?>>
<?php endif; ?> <?php endif; ?>
<ul> <ul>
<?php foreach ($this->arrRatings as $rating): ?> <?php foreach ($this->arrRatings as $rating): ?>
<li> <li>
<!-- indexer::stop --> <!-- indexer::stop -->
<div class="rateItTitle"><?php echo $rating->title; ?></div> <div class="rateItContainer">
<div id="<?php echo $rating->rateItID; ?>" class="<?php echo $rating->rateit_class; ?>" rel="<?php echo $rating->rel; ?>"> <div class="rateItTitle">
<?php if ($rating->url): ?>
<a href="<?= $rating->url ?>"><?= $rating->title ?></a>
<?php else: ?>
<?= $rating->title ?>
<?php endif; ?>
</div>
<div id="<?= $rating->rateItID ?>" class="<?= $rating->rateit_class ?>" rel="<?= $rating->rel ?>">
<div class="wrapper"> <div class="wrapper">
<div class="rateItRating-selected" style="display: block;"></div> <div class="rateItRating-selected" style="display: block;"></div>
<div class="rateItRating-hover"></div> <div class="rateItRating-hover"></div>
</div> </div>
<div id="<?php echo $rating->descriptionId; ?>" class="ratingText"><?php echo $rating->description; ?></div> <div id="<?= $rating->descriptionId ?>" class="ratingText"><?= $rating->description ?></div>
</div>
</div> </div>
<!-- indexer::continue --> <!-- indexer::continue -->
</li> </li>

View File

@ -1,21 +1,27 @@
<div class="<?php echo $this->class; ?> block"<?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>> <div class="<?= $this->class; ?> block"<?= $this->cssID; ?><?php if ($this->style): ?> style="<?= $this->style; ?>"<?php endif; ?>>
<?php if ($this->headline): ?> <?php if ($this->headline): ?>
<<?php echo $this->hl; ?>><?php echo $this->headline; ?></<?php echo $this->hl; ?>> <<?= $this->hl ?>><?= $this->headline; ?></<?= $this->hl; ?>>
<?php endif; ?> <?php endif; ?>
<ul> <ul>
<?php foreach ($this->arrRatings as $rating): ?> <?php foreach ($this->arrRatings as $rating): ?>
<li> <li>
<!-- indexer::stop --> <!-- indexer::stop -->
<div class="rateItTitle"><?php echo $rating->title; ?></div> <div class="rateItTitle">
<div id="<?php echo $rating->rateItID; ?>" class="<?php echo $rating->rateit_class; ?>" rel="<?php echo $rating->rel; ?>"> <?php if ($rating->url): ?>
<a href="<?= $rating->url ?>"><?= $rating->title ?></a>
<?php else: ?>
<?= $rating->title ?>
<?php endif; ?>
</div>
<div id="<?= $rating->rateItID ?>" class="<?= $rating->rateit_class ?>" rel="<?= $rating->rel ?>">
<div class="wrapper"> <div class="wrapper">
<div class="rateItRating-selected" style="display: block;"></div> <div class="rateItRating-selected" style="display: block;"></div>
<div class="rateItRating-hover"></div> <div class="rateItRating-hover"></div>
</div> </div>
<div id="<?php echo $rating->descriptionId; ?>" class="ratingText"><?php echo $rating->description; ?></div> <div id="<?= $rating->descriptionId ?>" class="ratingText"><?= $rating->description ?></div>
</div> </div>
<!-- indexer::continue --> <!-- indexer::continue -->
</li> </li>