Browse Source

Initialer Commit in GIT

dev-contao3 3.3.0
oetzi 8 years ago
parent
commit
dd1558b954
  1. 113
      classes/DcaHelper.php
  2. 274
      classes/RateItArticle.php
  3. 110
      classes/RateItBackend.php
  4. 801
      classes/RateItBackendModule.php
  5. 51
      classes/RateItCE.php
  6. 159
      classes/RateItFaq.php
  7. 157
      classes/RateItFrontend.php
  8. 116
      classes/RateItHybrid.php
  9. 51
      classes/RateItModule.php
  10. 85
      classes/RateItNews.php
  11. 110
      classes/RateItPage.php
  12. 96
      classes/RateItRating.php
  13. 142
      classes/RateItTopRatingsModule.php
  14. 1721
      classes/extern/simple_html_dom.php
  15. 7
      config/autoload.ini
  16. 73
      config/autoload.php
  17. 65
      config/config.php
  18. 88
      config/runonce.php
  19. 116
      dca/tl_article.php
  20. 212
      dca/tl_content.php
  21. 89
      dca/tl_faq.php
  22. 140
      dca/tl_module.php
  23. 89
      dca/tl_news.php
  24. 82
      dca/tl_page.php
  25. 69
      dca/tl_rateit_items.php
  26. 72
      dca/tl_rateit_ratings.php
  27. 133
      dca/tl_settings.php
  28. 56
      languages/de/default.php
  29. 34
      languages/de/modules.php
  30. 85
      languages/de/rateit_backend.php
  31. 40
      languages/de/tl_article.php
  32. 41
      languages/de/tl_content.php
  33. 38
      languages/de/tl_faq.php
  34. 56
      languages/de/tl_module.php
  35. 40
      languages/de/tl_news.php
  36. 36
      languages/de/tl_page.php
  37. 64
      languages/de/tl_settings.php
  38. 56
      languages/en/default.php
  39. 34
      languages/en/modules.php
  40. 85
      languages/en/rateit_backend.php
  41. 41
      languages/en/tl_article.php
  42. 41
      languages/en/tl_content.php
  43. 40
      languages/en/tl_faq.php
  44. 56
      languages/en/tl_module.php
  45. 40
      languages/en/tl_news.php
  46. 36
      languages/en/tl_page.php
  47. 64
      languages/en/tl_settings.php
  48. 7
      public/.htaccess
  49. 135
      public/css/backend.css
  50. 11
      public/css/heart.css
  51. 65
      public/css/rateit.css
  52. 11
      public/css/star.css
  53. BIN
      public/images/ajax-loading.gif
  54. BIN
      public/images/article.gif
  55. BIN
      public/images/exportEXCEL.gif
  56. BIN
      public/images/heart.gif
  57. BIN
      public/images/icon.png
  58. BIN
      public/images/info.gif
  59. BIN
      public/images/page.gif
  60. BIN
      public/images/star.gif
  61. 22
      public/js/RateItBackend.js
  62. 114
      public/js/helper.js
  63. 2240
      public/js/jquery-ui-effects.custom.js
  64. 6
      public/js/jquery-ui-effects.custom.min.js
  65. 1127
      public/js/jquery/colorbox/colorbox-rateit.js
  66. 7
      public/js/jquery/colorbox/colorbox-rateit.min.js
  67. 1025
      public/js/mootools/mediabox/mediabox-rateit-uncompressed.js
  68. 1
      public/js/mootools/mediabox/mediabox-rateit.js
  69. 75
      public/js/onReadyRateIt-uncompressed.js
  70. 1
      public/js/onReadyRateIt.js
  71. 591
      public/js/rateit-uncompressed.js
  72. 1
      public/js/rateit.js
  73. 164
      public/php/rateit.php
  74. 70
      templates/article_rateit_default.html5
  75. 71
      templates/article_rateit_default.xhtml
  76. 86
      templates/article_rateit_default_microdata.html5
  77. 87
      templates/article_rateit_default_microdata.xhtml
  78. 48
      templates/gallery_rateit_default.html5
  79. 50
      templates/gallery_rateit_default.xhtml
  80. 27
      templates/j_colorbox_rateit.html5
  81. 26
      templates/j_colorbox_rateit.xhtml
  82. 48
      templates/mod_article_list_rateit.html5
  83. 46
      templates/mod_article_list_rateit.xhtml
  84. 64
      templates/mod_article_rateit_default_microdata_teaser.html5
  85. 64
      templates/mod_article_rateit_default_microdata_teaser.xhtml
  86. 48
      templates/mod_article_rateit_default_teaser.html5
  87. 48
      templates/mod_article_rateit_default_teaser.xhtml
  88. 25
      templates/mod_rateit_top_ratings.html5
  89. 25
      templates/mod_rateit_top_ratings.xhtml
  90. 32
      templates/moo_mediabox_rateit.html5
  91. 33
      templates/moo_mediabox_rateit.xhtml
  92. 90
      templates/news_full_rateit.html5
  93. 90
      templates/news_full_rateit.xhtml
  94. 99
      templates/news_full_rateit_microdata.html5
  95. 99
      templates/news_full_rateit_microdata.xhtml
  96. 69
      templates/news_latest_rateit.html5
  97. 69
      templates/news_latest_rateit.xhtml
  98. 77
      templates/news_latest_rateit_microdata.html5
  99. 77
      templates/news_latest_rateit_microdata.xhtml
  100. 55
      templates/news_short_rateit.html5
  101. Some files were not shown because too many files have changed in this diff Show More

113
classes/DcaHelper.php

@ -0,0 +1,113 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
/**
* Class DcaHelper
*/
class DcaHelper extends \Backend
{
/**
* Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Return all navigation templates as array
* @param DataContainer
* @return array
*/
public function getRateItTemplates(\DataContainer $dc)
{
$intPid = $dc->activeRecord->pid;
if ($this->Input->get('act') == 'overrideAll')
{
$intPid = $this->Input->get('id');
}
return $this->getTemplateGroup('rateit_', $intPid);
}
/**
* Anlegen eines Datensatzes in der Tabelle tl_rateit_items, falls dieser noch nicht exisitiert.
* @param mixed
* @param object
* @return string
*/
public function insertOrUpdateRatingKey(\DC_Table $dc, $type, $ratingTitle) {
if ($dc->activeRecord->rateit_active || $dc->activeRecord->addRating) {
$actRecord = $this->Database->prepare("SELECT * FROM tl_rateit_items WHERE rkey=? and typ=?")
->execute($dc->activeRecord->id, $type)
->fetchAssoc();
if (!is_array($actRecord)) {
$arrSet = array('rkey' => $dc->activeRecord->id,
'tstamp' => time(),
'typ' => $type,
'createdat' => time(),
'title'=> $ratingTitle,
'active' => '1'
);
$insertRecord = $this->Database->prepare("INSERT INTO tl_rateit_items %s")
->set($arrSet)
->execute()
->insertId;
} else {
$this->Database->prepare("UPDATE tl_rateit_items SET active='1', title=? WHERE rkey=? and typ=?")
->execute($ratingTitle, $dc->activeRecord->id, $type)
->updatedId;
}
} else {
$this->Database->prepare("UPDATE tl_rateit_items SET active='' WHERE rkey=? and typ=?")
->execute($dc->activeRecord->id, $typ)
->updatedId;
}
return true;
}
/**
* Löschen eines Datensatzes aus der Tabelle tl_rateit_items.
* @param mixed
* @param object
* @return string
*/
public function deleteRatingKey(\DC_Table $dc, $type)
{
$this->Database->prepare("DELETE FROM tl_rateit_items WHERE rkey=? and typ=?")
->execute($dc->activeRecord->id, $type);
return true;
}
}
?>

274
classes/RateItArticle.php

@ -0,0 +1,274 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
class RateItArticle extends RateItFrontend {
/**
* Initialize the controller
*/
public function __construct() {
parent::__construct();
}
public function parseTemplateRateIt($objTemplate) {
if ($objTemplate->type == 'article') {
$objTemplate = $this->doArticle($objTemplate);
} else if ($objTemplate->type == 'articleList') {
$objTemplate = $this->doArticleList($objTemplate);
} else if ($objTemplate->type == 'gallery') {
$objTemplate = $this->doGallery($objTemplate);
}
return $objTemplate;
}
private function doArticle($objTemplate) {
$arrArticle = $this->Database->prepare('SELECT * FROM tl_article WHERE ID=?')
->limit(1)
->execute($objTemplate->id)
->fetchAssoc();
if ($arrArticle['addRating']) {
if ($objTemplate->multiMode && $objTemplate->showTeaser) {
$objTemplate->setName('mod_'.$arrArticle['rateit_template'].'_teaser');
} else {
$objTemplate->setName($arrArticle['rateit_template']);
}
$ratingId = $arrArticle['id'];
$rating = $this->loadRating($ratingId, 'article');
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
$percent = round($rating['rating'], 0)."%";
$objTemplate->descriptionId = 'rateItRating-'.$ratingId.'-description';
$objTemplate->description = $this->getStarMessage($rating);
$objTemplate->rateItID = 'rateItRating-'.$ratingId.'-article-'.$stars.'_'.$this->intStars;
$objTemplate->rateit_class = 'rateItRating';
$objTemplate->itemreviewed = $rating['title'];
$objTemplate->actRating = $this->percentToStars($rating['rating']);
$objTemplate->maxRating = $this->intStars;
$objTemplate->votes = $rating[totalRatings];
if ($this->strTextPosition == "before") {
$objTemplate->showBefore = true;
}
else if ($this->strTextPosition == "after") {
$objTemplate->showAfter = true;
}
if ($arrArticle['rateit_position'] == 'before') {
$objTemplate->rateit_rating_before = true;
} else if ($arrArticle['rateit_position'] == 'after') {
$objTemplate->rateit_rating_after = true;
}
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/onReadyRateIt.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/rateit.js|static';
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/rateit.css||static';
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
case 'hearts' :
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
break;
default:
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
}
}
return $objTemplate;
}
private function doArticleList($objTemplate) {
if ($objTemplate->rateit_active) {
$bolTemplateFixed = false;
$arrArticles = array();
foreach ($objTemplate->articles as $article) {
$arrArticle = $this->Database->prepare('SELECT * FROM tl_article WHERE ID=?')
->limit(1)
->execute($article['articleId'])
->fetchAssoc();
if ($arrArticle['addRating']) {
if (!$bolTemplateFixed) {
$objTemplate->setName($objTemplate->getName().'_rateit');
$bolTemplateFixed = true;
}
$ratingId = $arrArticle['id'];
$rating = $this->loadRating($ratingId, 'article');
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
$percent = round($rating['rating'], 0)."%";
$article['descriptionId'] = 'rateItRating-'.$ratingId.'-description';
$article['description'] = $this->getStarMessage($rating);
$article['rateItID'] = 'rateItRating-'.$ratingId.'-article-'.$stars.'_'.$this->intStars;
$article['rateit_class'] = 'rateItRating';
$article['itemreviewed'] = $rating['title'];
$article['actRating'] = $this->percentToStars($rating['rating']);
$article['maxRating'] = $this->intStars;
$article['votes'] = $rating[totalRatings];
if ($this->strTextPosition == "before") {
$article['showBefore'] = true;
}
else if ($this->strTextPosition == "after") {
$article['showAfter'] = true;
}
if ($arrArticle['rateit_position'] == 'before') {
$article['rateit_rating_before'] = true;
} else if ($arrArticle['rateit_position'] == 'after') {
$article['rateit_rating_after'] = true;
}
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/onReadyRateIt.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/rateit.js|static';
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/rateit.css||static';
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
case 'hearts' :
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
break;
default:
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
}
}
$arrArticles[] = $article;
}
$objTemplate->articles = $arrArticles;
}
return $objTemplate;
}
private function doGallery($objTemplate) {
$arrGallery = $this->Database->prepare('SELECT * FROM tl_content WHERE ID=?')
->limit(1)
->execute($objTemplate->id)
->fetchAssoc();
if ($arrGallery['rateit_active']) {
$arrRating = array();
if (version_compare(VERSION, '3.2', '>=')) {
$objFiles = \FilesModel::findMultipleByUuids(deserialize($arrGallery['multiSRC']));
} else {
$objFiles = \FilesModel::findMultipleByIds(deserialize($arrGallery['multiSRC']));
}
if ($objFiles !== null) {
// Get all images
while ($objFiles->next()) {
// Continue if the files has been processed or does not exist
if (isset($arrRating[$objFiles->path]) || !file_exists(TL_ROOT . '/' . $objFiles->path)) {
continue;
}
// Single files
if ($objFiles->type == 'file') {
$objFile = new \File($objFiles->path, true);
if (!$objFile->isGdImage) {
continue;
}
$this->addRatingForImage($arrRating, $arrGallery['id'], $objFile->id, $objFile->path);
}
// Folders
else {
if (version_compare(VERSION, '3.2', '>=')) {
$objSubfiles = \FilesModel::findByPid($objFiles->uuid);
} else {
$objSubfiles = \FilesModel::findByPid($objFiles->id);
}
if ($objSubfiles === null) {
continue;
}
while ($objSubfiles->next()) {
// Skip subfolders
if ($objSubfiles->type == 'folder') {
continue;
}
$objFile = new \File($objSubfiles->path, true);
if (!$objFile->isGdImage) {
continue;
}
$this->addRatingForImage($arrRating, $arrGallery['id'], $objSubfiles->id, $objSubfiles->path);
}
}
}
}
$objTemplate->arrRating = $arrRating;
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/onReadyRateIt.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/rateit.js|static';
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/rateit.css||static';
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
case 'hearts' :
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
break;
default:
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
}
}
return $objTemplate;
}
private function addRatingForImage(&$arrRating, $galleryId, $picId, $picPath) {
$ratingId = $galleryId.'|'.$picId;
$rating = $this->loadRating($ratingId, 'galpic');
$stars = !$rating ? 0 : $this->percentToStars($rating['rating']);
$percent = round($rating['rating'], 0)."%";
$arrRating[$picPath] = array();
$arrRating[$picPath]['descriptionId'] = 'rateItRating-'.$ratingId.'-description';
$arrRating[$picPath]['description'] = $this->getStarMessage($rating);
$arrRating[$picPath]['rateItID'] = 'rateItRating-'.$ratingId.'-galpic-'.$stars.'_'.$this->intStars;
$arrRating[$picPath]['rateit_class'] = 'rateItRating';
$arrRating[$picPath]['itemreviewed'] = $rating['title'];
$arrRating[$picPath]['actRating'] = $this->percentToStars($rating['rating']);
$arrRating[$picPath]['maxRating'] = $this->intStars;
$arrRating[$picPath]['votes'] = $rating[totalRatings];
if ($this->strTextPosition == "before") {
$arrRating[$picPath]['showBefore'] = true;
}
else if ($this->strTextPosition == "after") {
$arrRating[$picPath]['showAfter'] = true;
}
}
}
?>

110
classes/RateItBackend.php

@ -0,0 +1,110 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
class RateItBackend
{
const path = 'system/modules/rateit/';
/**
* Get a css file.
* @param string $file The basename if the file (without extension).
* @return string The file path.
*/
public static function css($file)
{
return self::path.'public/css/'. $file.'.css';
} // file
/**
* Get a js file.
* @param string $file The basename if the file (without extension).
* @return string The file path.
*/
public static function js($file)
{
return self::path.'public/js/'. $file.'.js';
} // file
/**
* Get image url from the theme.
* @param string $file The basename if the image (without extension).
* @return string The image path.
*/
public static function image($file)
{
$url = self::path.'public/images/';
if (is_file(TL_ROOT.'/'.$url.$file.'.png')) return $url.$file.'.png';
if (is_file(TL_ROOT.'/'.$url.$file.'.gif')) return $url.$file.'.gif';
return $url.'default.png';
} // image
/**
* Create a 'img' tag from theme icons.
* @param string $file The basename if the image (without extension).
* @param string $alt The 'alt' text.
* @param string $attributes Additional tag attributes.
* @return string The html code.
*/
public static function createImage($file, $alt='', $attributes='')
{
if ($alt=='') $alt = 'icon';
$img = self::image($file);
$size = getimagesize(TL_ROOT.'/'.$img);
return '<img'.((substr($img, -4) == '.png') ? ' class="pngfix"' : '').' src="'.$img.'" '.$size[3].' alt="'.specialchars($alt).'"'.(($attributes != '') ? ' '.$attributes : '').'>';
} // createImage
/**
* Create a list button (link button)
* @param string $file The basename if the image (without extension).
* @param string $link The URL of the link to create.
* @param string $text The alt/title text.
* @param string $confirm Optional confirmation text before redirecting to the link.
* @param boolean $popup Open the target in a new window.
* @return string The html code.
*/
public function createListButton($file, $link, $text, $confirm='', $popup=false)
{
$target = $popup ? ' target="_blank"' : '';
$onclick = ($confirm!='') ? ' onclick="if(!confirm(\''.$confirm.'\'))return false"' : '';
return '<a href="'.$link.'" title="'.$text.'"'.$target.$onclick.'>'.$this->createImage($file,$text).'</a>';
} // createListButton
public function createMainButton($file, $link, $text, $confirm='')
{
$onclick = ($confirm=='')
? ''
: ' onclick="if(!confirm(\''.$confirm.'\'))return false"';
return '<a href="'.$link.'" title="'.$text.'"'.$onclick.'>'.$this->createImage($file,$text).' '.$text.'</a>';
} // createMainButton
} // class RateItBackend
?>

801
classes/RateItBackendModule.php

@ -0,0 +1,801 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
class rateitBackendModule extends \BackendModule
{
protected $strTemplate;
protected $actions = array();
protected $rateit;
protected $tl_root;
protected $tl_files;
protected $languages;
private $compiler;
private $action = '';
private $parameter = '';
private $arrExportHeader;
private $arrExportHeaderDetails;
/**
* Anzahl der Herzen/Sterne
* @var int
*/
protected $intStars = 5;
protected $label;
protected $labels;
/**
* Initialize the controller
*/
public function __construct($objElement=array()) {
parent::__construct($objElement);
$this->label = $GLOBALS['TL_CONFIG']['rating_type'] == 'hearts' ? $GLOBALS['TL_LANG']['rateit']['heart'] : $GLOBALS['TL_LANG']['rateit']['star'];
$this->labels = $GLOBALS['TL_CONFIG']['rating_type'] == 'hearts' ? $GLOBALS['TL_LANG']['rateit']['hearts'] : $GLOBALS['TL_LANG']['rateit']['stars'];
$this->actions = array(
// act[0] strTemplate compiler
array('', 'rateitbe_ratinglist', 'listRatings' ),
array('reset_ratings', '', 'resetRatings' ),
array('view', 'rateitbe_ratingview', 'viewRating' ),
array('export', '', 'exportRatings' ),
array('exportDetails', '', 'exportRatingDetails' ),
);
$this->loadLanguageFile('rateit_backend');
$this->arrExportHeader = &$GLOBALS['TL_LANG']['tl_rateit']['xls_headers'];
$this->arrExportHeaderDetails = &$GLOBALS['TL_LANG']['tl_rateit']['xls_headers_detail'];
}
/**
* Generate module:
* - Display a wildcard in the back end
* - Select the template and compiler in the front end
* @return string
*/
public function generate()
{
$this->rateit = new \stdClass();
$rateit = &$this->rateit;
$rateit->username = $this->BackendUser->username;
$rateit->isadmin = $this->BackendUser->isAdmin;
$this->strTemplate = $this->actions[0][1];
$this->compiler = $this->actions[0][2];
$act = \Input::get('act');
if (!$act) $act = \Input::post('act');
foreach ($this->actions as $action) {
if ($act == $action[0]) {
$this->parameter = $act;
$this->action = $action[0];
$this->strTemplate = $action[1];
$this->compiler = $action[2];
break;
}
}
$stars = intval($GLOBALS['TL_CONFIG']['rating_count']);
if ($stars > 0) {
$this->intStars = $stars;
}
return str_replace(array('{{', '}}'), array('[{]', '[}]'), parent::generate());
} // generate
/**
* Compile module: common initializations and forwarding to distinct function compiler
*/
protected function compile()
{
// hide module?
$compiler = $this->compiler;
if ($compiler=='hide') return;
// load other helpers
$this->tl_root = str_replace("\\",'/',TL_ROOT).'/';
$this->tl_files = str_replace("\\",'/',$GLOBALS['TL_CONFIG']['uploadPath']).'/';
$this->Template->rateit = $this->rateit;
// complete rateit initialization
$rateit = &$this->rateit;
$rateit->f_link = $this->createUrl(array($this->action => $this->parameter));
$rateit->f_action = $this->compiler;
$rateit->f_mode = $this->action;
$rateit->theme = new RateItBackend();
$rateit->backLink = $this->getReferer(true);
$rateit->homeLink = $this->createUrl();
// execute compiler
$this->$compiler($this->parameter);
} // compile
/**
* List the ratings
*/
protected function listRatings()
{
$rateit = &$this->Template->rateit;
$rateit->f_page = 0;
// returning from submit?
if ($this->filterPost('rateit_action') == $rateit->f_action) {
// get url parameters
$rateit->f_typ = trim(\Input::post('rateit_typ'));
$rateit->f_active = trim(\Input::post('rateit_active'));
$rateit->f_order = trim(\Input::post('rateit_order'));
$rateit->f_page = trim(\Input::post('rateit_page'));
$rateit->f_find = trim(\Input::post('rateit_find'));
$this->Session->set(
'rateit_settings',
array(
'rateit_typ' => $rateit->f_typ,
'rateit_order' => $rateit->f_order,
'rateit_page' => $rateit->f_page,
'rateit_find' => $rateit->f_find
)
);
} else {
$stg = $this->Session->get('rateit_settings');
if (is_array($stg)) {
$rateit->f_typ = trim($stg['rateit_typ']);
$rateit->f_active = trim($stg['rateit_active']);
$rateit->f_order = trim($stg['rateit_order']);
$rateit->f_page = trim($stg['rateit_page']);
$rateit->f_find = trim($stg['rateit_find']);
} // if
} // if
if ($rateit->f_order=='') $rateit->f_order = 'rating';
//if (!isset($rateit->f_active)) $rateit->f_active = '-1';
if (isset($GLOBALS['TL_CONFIG']['rating_listsize']))
$perpage = (int)trim($GLOBALS['TL_CONFIG']['rating_listsize']);
if (!isset($perpage) || $perpage < 0) $perpage = 10;
if ($rateit->f_page>=0 && $perpage>0) {
$options['first'] = $rateit->f_page * $perpage;
$options['limit'] = $perpage;
} // if
if ($rateit->f_typ != '') $options['typ'] = $rateit->f_typ;
if ($rateit->f_active != '') $options['active'] = $rateit->f_active == '0' ? '' : $rateit->f_active;
if ($rateit->f_find != '') $options['find'] = $rateit->f_find;
switch ($rateit->f_order) {
case 'title' : $options['order'] = 'title'; break;
case 'typ' : $options['order'] = 'typ'; break;
case 'createdat' : $options['order'] = 'createdat'; break;
default : $options['order'] = 'rating desc';
} // switch
$rateit->exportLink = $this->createUrl(array('act' => 'export'));
// query extensions
$rateit->ratingitems = $this->getRatingItems($options);
if ($rateit->f_page>=0 && $perpage>0 && count($rateit->ratingitems)==0) {
$rateit->f_page = 0;
$options['first'] = 0;
$rateit->ratingitems = $this->getRatingItems($options);
} // if
// add view links
foreach ($rateit->ratingitems as &$ext) {
$ext->viewLink = $this->createUrl(array('act' => 'view', 'rkey' => $ext->rkey, 'typ' => $ext->typ));
$totrecs = $ext->totcount;
} // foreach
// create pages list
$rateit->pages = array();
if ($perpage > 0) {
$first = 1;
while ($totrecs > 0) {
$cnt = $totrecs > $perpage ? $perpage : $totrecs;
$rateit->pages[] = $first . ' - ' . ($first+$cnt-1);
$first += $cnt;
$totrecs -= $cnt;
} // while
} // if
} // listRatings
/**
* Export all ratings as MS-Excel-File
*/
protected function exportRatings()
{
$this->import('String');
$rateit = &$this->Template->rateit;
$options['order'] = 'rating desc';
// query ratings
$rateit->ratingitems = $this->getRatingItems($options, true);
$xls = new \xlsexport();
$strXlsSheet = $GLOBALS['TL_LANG']['tl_rateit']['xls_sheetname_ratings'];
$xls->addworksheet($strXlsSheet);
$intRowCounter = -1;
$intColCounter = 0;
$intRowCounter++;
// Header setzen
foreach(array_values($this->arrExportHeader) as $header) {
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $header, "fontweight" => XLSFONT_BOLD, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
$xls->setcolwidth($strXlsSheet, $intColCounter, 0x1aff);
$intColCounter++;
}
$intRowCounter++;
// Werte setzen
foreach($rateit->ratingitems as $item) {
$arrItem = (array)$item;
$intColCounter = 0;
foreach(array_keys($this->arrExportHeader) as $key) {
$strVal = $arrItem[$key];
$strVal = $this->String->decodeEntities($strVal);
$strVal = preg_replace(array('/<br.*\/*>/si'), array("\n"), $strVal);
$strVal = $this->convertEncoding($strVal, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252');
$cellType = CELL_STRING;
switch ($key) {
case 'typ' :
$strVal = $GLOBALS['TL_LANG']['tl_rateit_type_options'][$strVal];
break;
case 'createdat' :
$strVal = $strVal ? date($GLOBALS['TL_CONFIG']['datimFormat'], $strVal) : '';
break;
case 'active' :
$strVal = $strVal == '1' ? 'Ja' : 'Nein';
break;
case 'rating' :
if (!isset($strVal) || empty($strVal)) {
$strVal = '0';
}
$cellType = CELL_FLOAT;
break;
case 'stars' :
case 'percent' :
case 'totalRatings' :
case 'rkey' :
$cellType = CELL_FLOAT;
break;
}
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $strVal, "type" => $cellType, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
$intColCounter++;
}
$intRowCounter++;
}
$xls->sendfile("export_rateit_" . date("Ymd_His") . ".xls");
exit;
} // exportRatings
/**
* Detailed view of one rating.
* @param string
*/
protected function viewRating()
{
$rateit = &$this->Template->rateit;
$rateit->f_page = 0;
// returning from submit?
if ($this->filterPost('rateit_action') == $rateit->f_action) {
// get url parameters
$rateit->f_page = trim(\Input::post('rateit_details_page'));
$this->Session->set(
'rateit_settings',
array(
'rateit_details_page' => $rateit->f_page
)
);
} else {
$stg = $this->Session->get('rateit_settings');
if (is_array($stg)) {
$rateit->f_page = trim($stg['rateit_details_page']);
} // if
} // if
$rkey = \Input::get('rkey');
if (strstr($rkey, '|')) {
$arrRkey = explode('|', $rkey);
foreach ($arrRkey as $key) {
if (!is_numeric($key)) {
$this->redirect($rateit->homeLink);
exit;
}
$id = $rkey;
}
} else {
if (is_numeric($rkey)) {
$id = $rkey;
} else {
$this->redirect($rateit->homeLink);
exit;
}
}
$typ = \Input::get('typ');
// compose base options
$options = array(
'rkey' => $rkey,
'typ' => $typ
);
$this->rateit->f_link = $this->createUrl(array('act' => 'view', 'rkey' => $rkey, 'typ' => $typ));
if (isset($GLOBALS['TL_CONFIG']['rating_listsize']))
$perpage = (int)trim($GLOBALS['TL_CONFIG']['rating_listsize']);
if (!isset($perpage) || $perpage < 0) $perpage = 10;
if ($rateit->f_page>=0 && $perpage>0) {
$options['first'] = $rateit->f_page * $perpage;
$options['limit'] = $perpage;
} // if
$rateit->ratingitems = $this->getRatingItems($options, true);
if (count($rateit->ratingitems)<1) $this->redirect($rateit->homeLink);
$ext = &$rateit->ratingitems[0];
$ext->ratings = $this->getRatings($ext, $options);
if ($rateit->f_page>=0 && $perpage>0 && count($ext->ratings)==0) {
$rateit->f_page = 0;
$options['first'] = 0;
$rateit->ratings = $this->getRatings($ext, $options);
} // if
if (count($ext->ratings) > 0) {
$totrecs = $ext->ratings[0]->totcount;
} else {
$totrecs = 0;
}
// create pages list
$rateit->pages = array();
if ($perpage > 0) {
$first = 1;
while ($totrecs > 0) {
$cnt = $totrecs > $perpage ? $perpage : $totrecs;
$rateit->pages[] = $first . ' - ' . ($first+$cnt-1);
$first += $cnt;
$totrecs -= $cnt;
} // while
} // if
$rateit->exportLink = $this->createUrl(array('act' => 'exportDetails', 'rkey' => $rkey, 'typ' => $typ));
$ext->statistics = $this->getRatingStatistics($ext->item_id);
$ext->ratingsChartData = $this->getRatingsChartData($ext->statistics);
$ext->monthsChartData = $this->getMonthsChartData($ext->item_id);
} // viewRating
protected function resetRatings()
{
$rateit = &$this->Template->rateit;
// nothing checked?
$ids0 = \Input::post('selectedids');
if (!is_array($ids0)) {
$this->redirect($rep->homeLink); return;
}
foreach ($ids0 as $id) {
list($rkey, $typ) = explode('__', $id);
$pid = $this->Database->prepare('SELECT id FROM tl_rateit_items WHERE rkey=? and typ=?')
->execute($rkey, $typ)
->fetchRow();
$this->Database->prepare('DELETE FROM tl_rateit_ratings WHERE pid=?')
->execute($pid[0]);
}
$this->redirect($rateit->homeLink);
} // resetRatings
/**
* Export the details of one rating as MS-Excel-File
*/
protected function exportRatingDetails()
{
$rkey = \Input::get('rkey');
if (!is_numeric($rkey))
$this->redirect($rateit->backLink);
$typ = \Input::get('typ');
$this->rateit->backLink = $this->createUrl(array('act' => 'view', 'rkey' => $rkey, 'typ' => $typ));
// compose base options
$options = array(
'rkey' => $rkey,
'typ' => $typ
);
$this->import('String');
$rateit = &$this->Template->rateit;
// query ratings
$rateit->ratingitems = $this->getRatingItems($options);
if (count($rateit->ratingitems)<1) $this->redirect($rateit->backLink);
$ext = &$rateit->ratingitems[0];
$ext->ratings = $this->getRatings($ext);
$ext->statistics = $this->getRatingStatistics($ext->item_id);
$xls = new \xlsexport();
$strXlsSheet = $GLOBALS['TL_LANG']['tl_rateit']['xls_sheetname_rating'];
$xls->addworksheet($strXlsSheet);
$intRowCounter = -1;
$intColCounter = 0;
$intRowCounter++;
// Header setzen
foreach(array_values($this->arrExportHeaderDetails) as $header) {
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $header, "fontweight" => XLSFONT_BOLD, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
$xls->setcolwidth($strXlsSheet, $intColCounter, 0x1aff);
$intColCounter++;
}
$intRowCounter++;
// Werte setzen
foreach($ext->ratings as $item) {
$arrItem = (array)$item;
$intColCounter = 0;
foreach(array_keys($this->arrExportHeaderDetails) as $key) {
$strVal = $arrItem[$key];
$strVal = $this->String->decodeEntities($strVal);
$strVal = preg_replace(array('/<br.*\/*>/si'), array("\n"), $strVal);
$strVal = $this->convertEncoding($strVal, $GLOBALS['TL_CONFIG']['characterSet'], 'CP1252');
$cellType = CELL_STRING;
switch ($key) {
case 'createdat' :
$strVal = $strVal ? date($GLOBALS['TL_CONFIG']['datimFormat'], $strVal) : '';
break;
case 'rating' :
if (!isset($strVal) || empty($strVal)) {
$strVal = '0';
}
$cellType = CELL_FLOAT;
break;
case 'stars' :
case 'percent' :
case 'totalRatings' :
case 'rkey' :
$cellType = CELL_FLOAT;
break;
}
$xls->setcell(array("sheetname" => $strXlsSheet,"row" => $intRowCounter, "col" => $intColCounter, "data" => $strVal, "type" => $cellType, "vallign" => XLSXF_VALLIGN_TOP, "fontfamily" => XLSFONT_FAMILY_NORMAL));
$intColCounter++;
}
$intRowCounter++;
}
$xls->sendfile("export_rateit_" . date("Ymd_His") . ".xls");
exit;
} // exportRatingDetails
/**
* Create url for hyperlink to the current page.
* @param array $aParams Assiciative array with key/value pairs as parameters.
* @return string The create link.
*/
protected function createUrl($aParams = null)
{
return $this->createPageUrl(\Input::get('do'), $aParams);
} // createUrl
/**
* Create url for hyperlink to an arbitrary page.
* @param string $aPage The page ID.
* @param array $aParams Assiciative array with key/value pairs as parameters.
* @return string The create link.
*/
protected function createPageUrl($aPage, $aParams = null)
{
$url = \Environment::get('script') . '?do='.$aPage;
if (is_array($aParams)) {
foreach ($aParams as $key => $val)
if ($val!='')
$url .= '&amp;'.$key .'='.$val;
}
return $url;
} // createPageUrl
/**
* Get post parameter and filter value.
* @param string $aKey The post key. When filtering html, remove all attribs and
* keep the plain tags.
* @param string $aMode '': no filtering
* 'nohtml': strip all html
* 'text': Keep tags p br ul li em
* @return string The filtered input.
*/
protected function filterPost($aKey, $aMode = '')
{
$v = trim(\Input::postRaw($aKey));
if ($v == '' || $aMode=='') return $v;
switch ($aMode) {
case 'nohtml':
$v = strip_tags($v);
break;
case 'text':
$v = strip_tags($v, rateit_TEXTTAGS);
break;
} // switch
$v = preg_replace('/<(\w+) .*>/U', '<$1>', $v);
return $v;
} // filterPost
protected function getRatingItems($aOptions, $noLimit=false) {
$sql = "SELECT i.id as item_id,
i.rkey AS rkey,
i.title as title,
i.typ as typ,
i.createdat as createdat,
i.active as active,
IFNULL(AVG(r.rating),0) AS rating,
COUNT( r.rating ) AS totalRatings
FROM tl_rateit_items i
LEFT OUTER JOIN tl_rateit_ratings r
ON (i.id = r.pid)
%w
GROUP BY rkey, title, item_id, typ, createdat, active
%o
%l";
$cntSql = "SELECT COUNT(*) FROM tl_rateit_items i %s";
$where = '';
$firstWhere = true;
$limit = '';
$order = '';
foreach ($aOptions as $k=>$v) {
if ($k == 'find') {
if (!$firstWhere) {
$where .= " AND";
}
$where .= " title like '%$v%'";
$firstWhere = false;
}
else if ($k != 'order' && $k != 'limit' && $k != 'first') {
if (!$firstWhere) {
$where .= " AND";
}
$where .= " $k='$v'";
$firstWhere = false;
} else {
if ($k == 'limit' && !$noLimit) {
$cntRows = $v;
} else if ($k == 'first' && !$noLimit) {
$first = $v;
}
}
}
if (isset($cntRows) && isset($first)) {
$limit = "LIMIT $first, $cntRows";
}
if (strlen($where) > 0) {
$where = "WHERE ".$where;
}
if (isset($aOptions['order']) && !empty($aOptions['order']))
$order = "ORDER BY ".$aOptions['order'];
$sql = str_replace('%o', $order, $sql);
$sql = str_replace('%w', $where, $sql);
$sql = str_replace('%l', $limit, $sql);
$cntSql = str_replace('%s', $where, $cntSql);
$count = $this->Database->prepare($cntSql)
->execute()
->fetchRow();
$arrRatingItems = $this->Database->prepare($sql)
->execute()
->fetchAllAssoc();
$arrReturn = array();
foreach ($arrRatingItems as $rating) {
if ($rating['active'] != '1') $rating['active'] = '0';
$rating['percent'] = $rating['rating'];
$rating['rating'] = $this->percentToStars($rating['percent']);
$rating['stars'] = $this->intStars;
$rating['totcount'] = $count[0];
$arrReturn[] = (object) $rating;
}
return $arrReturn;
} // getRatingItems
protected function getRatings($ext, $options = array()) {
// Gesamtanzahl (für Paging wichtig) ermitteln
$cntSql = "SELECT COUNT(*) FROM tl_rateit_ratings r WHERE r.pid=$ext->item_id";
$count = $this->Database->prepare($cntSql)
->execute()
->fetchRow();
foreach ($options as $k=>$v) {
if ($k == 'limit') {
$cntRows = $v;
} else if ($k == 'first') {
$first = $v;
}
}
if (isset($cntRows) && isset($first)) {
$limit = "LIMIT $first, $cntRows";
}
$sql = "SELECT id AS rating_id, ip_address AS ip, memberid, rating, createdat
FROM tl_rateit_ratings r
WHERE r.pid=$ext->item_id
ORDER BY createdat DESC
%l";
$sql = str_replace('%l', $limit, $sql);
$arrRatings = $this->Database->prepare($sql)
->execute()
->fetchAllAssoc();
$arrReturn = array();
foreach ($arrRatings as $rating) {
$rating['percent'] = $rating['rating'];
$rating['rating'] = $this->percentToStars($rating['percent']);
$rating['stars'] = $this->intStars;
$rating['totcount'] = $count[0];
if ($rating['memberid'] != null) {
$member = $this->Database->prepare("SELECT firstname, lastname FROM tl_member WHERE id=?")
->limit(1)
->execute($rating['memberid'])
->fetchAssoc();
$rating['member'] = $member['firstname']." ".$member['lastname'];
}
$arrReturn[] = (object) $rating;
}
return $arrReturn;
} // getRatings
protected function getRatingStatistics($item_id) {
$sql = "SELECT rating, count(*) as count
FROM tl_rateit_ratings r
WHERE r.pid=$item_id
GROUP BY rating
ORDER BY rating";
$arrRatingStatistics = $this->Database->prepare($sql)
->execute()
->fetchAllAssoc();
$arrReturn = array();
foreach ($arrRatingStatistics as $rating) {
$rating['percent'] = $rating['rating'];
$rating['rating'] = $this->percentToStars($rating['percent']);
$arrReturn[$rating['percent']] = (object) $rating;
}
return $arrReturn;
} // getRatings
protected function getRatingsChartData($statistics) {
$arr = array();
$arr['cols'] = array();
$arr['rows'] = array();
// Spalten anlegen
$arr['cols'][] = array('id'=>'rating', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['rating_chart_legend'][2], 'type'=>'string');
$arr['cols'][] = array('id'=>'count', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['rating_chart_legend'][3], 'type'=>'number');
// Zeilen anlegen
foreach($statistics as $obj) {
$arr['rows'][] = array('c'=>array(array('v'=>$obj->rating.' '.($obj->rating == 1 ? $this->label : $this->labels)), array('v'=>(int)$obj->count, 'f'=>$obj->count.' '.$GLOBALS['TL_LANG']['tl_rateit']['vote'][$obj->count == 1 ? 0 : 1])));
}
return json_encode($arr);
}
protected function getMonthsChartData($item_id) {
$sql = "SELECT count(*) AS anzahl, avg(rating) AS bewertung, month(date(FROM_UNIXTIME(createdat))) AS monat, year(date(FROM_UNIXTIME(createdat))) AS jahr
FROM tl_rateit_ratings r
WHERE r.pid=$item_id
GROUP BY monat, jahr
ORDER BY jahr DESC , monat DESC
LIMIT 0 , 12";
$arrResult = $this->Database->prepare($sql)
->execute()
->fetchAllAssoc();
$arrResult = array_reverse($arrResult);
$this->loadLanguageFile('default');
$arr = array();
$arr['cols'] = array();
$arr['rows'] = array();
// Spalten anlegen
$arr['cols'][] = array('id'=>'month', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][3], 'type'=>'string');
$arr['cols'][] = array('id'=>'count', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][4], 'type'=>'number');
$arr['cols'][] = array('id'=>'avg', 'label'=>$GLOBALS['TL_LANG']['tl_rateit']['month_chart_legend'][2], 'type'=>'number');
// Zeilen anlegen
foreach($arrResult as $result) {
$month = $GLOBALS['TL_LANG']['MONTHS'][$result['monat']-1].' '.$result['jahr'];
$avgValue = round((float)(($result['bewertung']*$this->intStars)/100), 1);
$arr['rows'][] = array('c'=>array(array('v'=>$month),
array('v'=>(int)$result['anzahl']),
array('v'=>$avgValue)));
}
return json_encode($arr);
}
protected function percentToStars($percent) {
$modifier = 100 / $this->intStars;
return round($percent / $modifier, 1);
}
/**
* Convert encoding
* @return String
* @param $strString String to convert
* @param $from charset to convert from
* @param $to charset to convert to
*/
public function convertEncoding($strString, $from, $to) {
if (USE_MBSTRING) {
@mb_substitute_character('none');
return @mb_convert_encoding($strString, $to, $from);
}
elseif (function_exists('iconv')) {
if (strlen($iconv = @iconv($from, $to . '//IGNORE', $strString))) {
return $iconv;
}
else {
return @iconv($from, $to, $strString);
}
}
return $strString;
}
} // class rateitBackendModule

51
classes/RateItCE.php

@ -0,0 +1,51 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
/**
* Class RateItCE
*/
class RateItCE extends RateItHybrid
{
/**
* Initialize the controller
*/
public function __construct($objElement) {
parent::__construct($objElement);
}
protected function getType() {
return 'ce';
}
}
?>

159
classes/RateItFaq.php

@ -0,0 +1,159 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
class RateItFaq extends RateItFrontend {
/**
* Initialize the controller
*/
public function __construct() {
parent::__construct();
}
public function getContentElementRateIt($objRow, $strBuffer) {
if ($objRow->type == 'module') {
$objModule = $this->Database->prepare("SELECT * FROM tl_module WHERE id=? AND type IN ('faqpage', 'faqreader')")
->limit(1)
->execute($objRow->module);
if ($objModule->numRows == 1) {
$this->faq_categories = deserialize($objModule->faq_categories);
if ($objModule->type == 'faqreader') {
$strBuffer = $this->generateForFaqReader($objModule, $strBuffer);
} else {
$strBuffer = $this->generateForFaqPage($objModule, $strBuffer);
}
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/onReadyRateIt.js|static';
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/rateit/public/js/rateit.js|static';
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/rateit.css||static';
switch ($GLOBALS['TL_CONFIG']['rating_type']) {
case 'hearts' :
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/heart.css||static';
break;
default:
$GLOBALS['TL_CSS'][] = 'system/modules/rateit/public/css/star.css||static';
}
}
}
return $strBuffer;
}
private function generateForFaqPage($objModule, $strBuffer) {
$objFaq = $this->Database
->execute("SELECT *, author AS authorId, (SELECT headline FROM tl_faq_category WHERE tl_faq_category.id=tl_faq.pid) AS category, (SELECT name FROM tl_user WHERE tl_user.id=tl_faq.author) AS author FROM tl_faq WHERE pid IN(" . implode(',', array_map('intval', $this->faq_categories)) . ")" . (!BE_USER_LOGGED_IN ? " AND published=1" : ""));
if ($objFaq->numRows < 1) {
return $strBuffer;
}
$htmlBuffer = new \simple_html_dom();
$htmlBuffer->load($strBuffer);
$arrFaqs = $objFaq->fetchAllAssoc();
foreach ($arrFaqs as $arrFaq) {
$rating = $this->generateSingle($arrFaq, $strBuffer);
$h3 = $htmlBuffer->find('#'.$arrFaq['alias']);
if (is_array($h3) && count($h3) == 1) {
$section = $h3[0]->parent();
if ($arrFaq['rateit_position'] == 'before') {
$section->innertext = $rating.$section->innertext;
} else if ($arrFaq['rateit_position'] == 'after') {
$section->innertext = $section->innertext.$rating;
}
}
}
$strBuffer = $htmlBuffer->save();
// Aufräumen
$htmlBuffer->clear();
unset($htmlBuffer);
return $strBuffer;
}
private function generateForFaqReader($objModule, $strBuffer) {
// Set the item from the auto_item parameter
if ($GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item'])) {
$this->Input->setGet('items', $this->Input->get('auto_item'));
}
// Do not index or cache the page if no FAQ has been specified
if (!$this->Input->get('items')) {
return $strBuffer;
}
$objFaq = $this->Database->prepare("SELECT *, author AS authorId, (SELECT title FROM tl_faq_category WHERE tl_faq_category.id=tl_faq.pid) AS category, (SELECT name FROM tl_user WHERE tl_user.id=tl_faq.author) AS author FROM tl_faq WHERE pid IN(" . implode(',', array_map('intval', $this->faq_categories)) . ") AND (id=? OR alias=?)" . (!BE_USER_LOGGED_IN ? " AND published=1" : ""))
->limit(1)
->execute((is_numeric($this->Input->get('items')) ? $this->Input->get('items') : 0), $this->Input->get('items'));
if ($objFaq->numRows == 1) {
$arrFaq = $objFaq->fetchAssoc();
$rating = $this->generateSingle($arrFaq, $strBuffer);
}
if ($arrFaq['rateit_position'] == 'before') {
$strBuffer = $rating.$strBuffer;
} else if ($arrFaq['rateit_position'] == 'after') {
$strBuffer = $strBuffer.$rating;
}
return $strBuffer;
}
private function generateSingle($arrFaq, $strBuffer) {
$rating = '';
if ($arrFaq['addRating']) {
$actRecord = $this->Database->prepare("SELECT * FROM tl_rateit_items WHERE rkey=? and typ='faq'")
->execute($arrFaq['id'])
->fetchAssoc();
if ($actRecord['active']) {
$this->import('rateit\\RateItRating', 'RateItRating');
$this->RateItRating->rkey = $arrFaq['id'];
$this->RateItRating->ratingType = 'faq';
$this->RateItRating->generate();
$rating = $this->RateItRating->output();
}
}
return $rating;
}
}
?>

157
classes/RateItFrontend.php

@ -0,0 +1,157 @@
<?php
/**
* Contao Open Source CMS
* Copyright (C) 2005-2011 Leo Feyer
*
* Formerly known as TYPOlight Open Source CMS.
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, please visit the Free
* Software Foundation website at <http://www.gnu.org/licenses/>.
*
* PHP version 5
* @copyright cgo IT, 2013
* @author Carsten Götzinger (info@cgo-it.de)
* @package rateit
* @license GNU/LGPL
* @filesource
*/
namespace cgoIT\rateit;
/**
* Class RateItFrontend
*/
class RateItFrontend extends \Hybrid
{
/**
* Primary key
* @var string
*/
protected $strPk = 'id';
/**
* Typ
* @var string
*/
protected $strType = 'hearts';
/**
* Template
* @var string
*/
protected $strTemplate = 'rateit_default';
/**
* Anzahl der Herzen/Sterne
* @var int
*/
protected $intStars = 5;
/**
* Textposition
* @var string
*/
protected $strTextPosition = 'after';
/**
* Initialize the controller
*/
public function __construct($objElement=array()) {
if (!empty($objElement)) {
if ($objElement instanceof \Model) {
$this->strTable = $objElement->getTable();
}
elseif ($objElement instanceof \Model\Collection) {
$this->strTable = $objElement->current()->getTable();
}
$this->strKey = $this->strPk;
}
$stars = intval($GLOBALS['TL_CONFIG']['rating_count']);
if ($stars > 0) {
$this->intStars = $stars;
}
parent::__construct($objElement);
}
/**
* Display a wildcard in the back end
* @return string
*/
public function generate() {
return parent::generate();
$this->loadLanguageFile('default');
$this->strType = $GLOBALS['TL_CONFIG']['rating_type'];
</