diff --git a/composer.json b/composer.json index f3f2b31..0b7b778 100644 --- a/composer.json +++ b/composer.json @@ -14,19 +14,18 @@ ], "support": { "email": "info@cgo-it.de", - "issues": "https://bitbucket.org/cgo-it/contao-rate-it/issues?status=new&status=open", + "issues": "https://git.cgo-it.de/contao/rate-it/issues", "forum": "https://community.contao.org/de/showthread.php?38471-Rate-It", - "source": "https://bitbucket.org/cgo-it/contao-rate-it/src" + "source": "https://git.cgo-it.de/contao/rate-it/tree/master" }, "require":{ "php":">=5.3", "contao/core":">=3.0", "contao-community-alliance/composer-plugin": "~2.0", - "leounglaub/contao-simple-ajax":"3.2.x-dev", "cgo-it/xls_export":"3.0.0" }, "replace": { - "cgo-it/rate-it": "<3.4.3" + "cgo-it/rate-it": "<3.5.4" }, "conflict": { "contao/core": "2.11.*" diff --git a/config/config.php b/config/config.php index 919096b..a6cb5fb 100644 --- a/config/config.php +++ b/config/config.php @@ -34,7 +34,7 @@ use cgoIT\rateit\RateItBackend; * Hooks */ $GLOBALS['TL_HOOKS']['generatePage'][] = array('rateit\\RateItPage', 'generatePage'); -$GLOBALS['TL_HOOKS']['simpleAjax'][] = array('rateit\\RateIt', 'doVote'); +$GLOBALS['TL_HOOKS']['rateitAjax'][] = array('rateit\\RateIt', 'doVote'); $GLOBALS['TL_HOOKS']['parseArticles'][] = array('rateit\\RateItNews', 'parseArticle'); $GLOBALS['TL_HOOKS']['getContentElement'][] = array('rateit\\RateItFaq', 'getContentElementRateIt'); $GLOBALS['TL_HOOKS']['parseTemplate'][] = array('rateit\\RateItArticle', 'parseTemplateRateIt'); diff --git a/public/js/rateit-uncompressed.js b/public/js/rateit-uncompressed.js index 0c5d6fa..2613927 100644 --- a/public/js/rateit-uncompressed.js +++ b/public/js/rateit-uncompressed.js @@ -271,7 +271,7 @@ function doRateIt() { }); window.addEvent('domready', function(e) { - RateItRating = new RateItRatings({url:'SimpleAjax.php?do=rateit'}); + RateItRating = new RateItRatings({url:'system/modules/rateit/public/php/rateit-ajax.php?do=rateit'}); }); } else if (window.jQuery) { // the rateit plugin as an Object @@ -579,7 +579,7 @@ function doRateIt() { async: false, cache: true }); - RateItRating = Object.create(RateItRatings).initialize({url:'SimpleAjax.php?do=rateit'}); + RateItRating = Object.create(RateItRatings).initialize({url:'system/modules/rateit/public/php/rateit-ajax.php?do=rateit'}); }); var jEscape = function(jquery) { diff --git a/public/js/rateit.js b/public/js/rateit.js index 40b6c25..8231abe 100644 --- a/public/js/rateit.js +++ b/public/js/rateit.js @@ -9,7 +9,7 @@ var votePercent=this.getVotePercent(el.newFill);if(this.options.url!=null){new R el.textEl.set('text',text);if(typeof($('.mbrateItRating'))!='undefined'&&el.id.indexOf('mb')==0){var mbid=el.getAttribute('id');mbid=mbid.replace('mb','');if(typeof(arrRatings)=='object'){for(var ri=0;ri100){el.newFill=this.getFillPercent(100);} -el.selected.setStyle('width',el.newFill);},getStarPercent:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(stars!=null){var score=stars[3].toFloat();var scale=stars[4].toFloat();var percent=(score/scale)*100;return percent;}else{return 0;}},getFillPercent:function(starPercent){return(starPercent/100)*(this.options.starwidth*this.options.max);},getVotePercent:function(actVote){var starsWidth=this.options.starwidth*this.options.max;var percent=(actVote/starsWidth*100).round(2);return percent;},getRatableId:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[1]:'';},getRatableType:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[2]:'';},getRatableMaxValue:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[4].toInt():0;},setBackgroundPosition:function(el,pos){el.setStyle('background-position','0% '+pos+'px');},getBackgroundImagePath:function(el){return el.getStyle('background-image');},getBackgroundImage:function(el){var reg_imgFile=/url\s*\(["']?(.*)["']?\)/i;var dummy=document.createElement('img');var string=this.getBackgroundImagePath(el);string=string.match(reg_imgFile)[1];string=string.replace('\"','');dummy.src=string;return dummy;}});window.addEvent('domready',function(e){RateItRating=new RateItRatings({url:'SimpleAjax.php?do=rateit'});});}else if(window.jQuery){(function(){RateItRatings={options:{step:0.1,readonly:false,resetable:false},initialize:function(options){if(typeof options=='object'&&typeof options['url']!='undefined') +el.selected.setStyle('width',el.newFill);},getStarPercent:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(stars!=null){var score=stars[3].toFloat();var scale=stars[4].toFloat();var percent=(score/scale)*100;return percent;}else{return 0;}},getFillPercent:function(starPercent){return(starPercent/100)*(this.options.starwidth*this.options.max);},getVotePercent:function(actVote){var starsWidth=this.options.starwidth*this.options.max;var percent=(actVote/starsWidth*100).round(2);return percent;},getRatableId:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[1]:'';},getRatableType:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[2]:'';},getRatableMaxValue:function(id){var stars=id.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return stars!=null?stars[4].toInt():0;},setBackgroundPosition:function(el,pos){el.setStyle('background-position','0% '+pos+'px');},getBackgroundImagePath:function(el){return el.getStyle('background-image');},getBackgroundImage:function(el){var reg_imgFile=/url\s*\(["']?(.*)["']?\)/i;var dummy=document.createElement('img');var string=this.getBackgroundImagePath(el);string=string.match(reg_imgFile)[1];string=string.replace('\"','');dummy.src=string;return dummy;}});window.addEvent('domready',function(e){RateItRating=new RateItRatings({url:'system/modules/rateit/public/php/rateit-ajax.php?do=rateit'});});}else if(window.jQuery){(function(){RateItRatings={options:{step:0.1,readonly:false,resetable:false},initialize:function(options){if(typeof options=='object'&&typeof options['url']!='undefined') this.options.url=options['url'];var self=this;jQuery('.rateItRating').each(function(i,element){self.initMe(element);});return this;},initMe:function(element){var self=this;if(!Browser.Engine.trident4){var el=jQuery(element);el.data('id',el.attr('id'));el.data('rateable',el.attr('rel')=='not-rateable'?false:true);el.data('wrapper',el.find('.wrapper'));el.data('textEl',el.find('.ratingText'));el.data('selected',el.find('.rateItRating-selected'));el.data('hover',el.find('.rateItRating-hover'));jQuery.when(self.getBackgroundImage(el.data('wrapper'))).done(function(backgroundImageSize){self.options.starwidth=backgroundImageSize[0];self.options.starheight=backgroundImageSize[1]/3;});if(self.options.starwidth===undefined||self.options.starwidth<16){self.options.starwidth=16;} if(self.options.starheight===undefined||self.options.starheight<16){self.options.starheight=16;} self.setBackgroundPosition(el.data('selected'),-1*self.options.starheight);self.setBackgroundPosition(el.data('hover'),-1*2*self.options.starheight);el.data('starPercent',self.getStarPercent(el.data('id')));el.data('ratableId',self.getRatableId(el.data('id')));el.data('ratableType',self.getRatableType(el.data('id')));self.options.max=self.getRatableMaxValue(el.data('id'));el.data('selected').css('height',self.options.starheight);el.data('hover').css('height',self.options.starheight);el.data('wrapper').css('width',self.options.starwidth*self.options.max);el.data('wrapper').css('height',self.options.starheight);self.fillVote(el.data('starPercent'),el);el.data('currentFill',self.getFillPercent(el.data('starPercent')));if(el.data('rateable')){el.data('wrapper').mouseenter(function(event){el.data('selected').hide(500,"easeInOutQuad");el.data('hover').show();el.data('wrapper').mousemove({'el':el,'self':self},self.mouseCrap);});el.data('wrapper').mouseleave(function(event){el.data('wrapper').unbind('mousemove');el.data('hover').hide();el.data('selected').show();el.data('selected').animate({width:el.data('currentFill')},500);});el.data('wrapper').click(function(event){el.data('currentFill',el.data('newFill'));el.data('wrapper').unbind();el.data('oldTxt',el.data('textEl').text());el.data('textEl').html('          ');el.data('textEl').addClass('loading');if(typeof(jQuery('.mbrateItRating'))!='undefined'&&el.data('id').indexOf('mb')==0){var mbid=el.data('id');mbid=mbid.replace('mb','');if(typeof(arrRatings)=='object'){for(var ri=0;ri').attr('src',string).load(function(){backgroundImageSize.push(this.width);backgroundImageSize.push(this.height);dfd.resolve(backgroundImageSize);});return dfd.promise();},updateText:function(el,text){error=text.split('ERROR:')[1];el.data('textEl').removeClass('loading');if(error){this.RateItRating.showError(el,error);return false;} el.data('textEl').text(text);if(typeof(jQuery('.mbrateItRating'))!='undefined'&&el.data('id').indexOf('mb')==0){var mbid=el.attr('id');mbid=mbid.replace('mb','');if(typeof(arrRatings)=='object'){for(var ri=0;ri. + * + * PHP version 5 + * @copyright Leo Unglaub 2012 + * @author Leo Unglaub + * @package simple_ajax + * @license LGPL + */ + + +// simple trick for Contao < 2.10 +$arrPost = $_POST; +unset($_POST); + + +// inizialize the contao framework +define('TL_MODE', 'FE'); +require('../../../../initialize.php'); + + +// write the post data back into the array +$_POST = $arrPost; + + +/** + * Class RateitAjax + * Contain methods to catch ajax requests and send responses back to the client. + * + * Description + * ``````````` + * + * The usage of the RateitAjax extensions is very easy. The extension provides + * the hook $GLOBALS['TL_HOOKS']['rateitAjax'] for extension developers. You + * simply have to register your class/method and the extension will call + * your class if there is an incomming ajax request. + * + * You simply have to deside if it's an ajax request for your module and return + * the data you want. + * + * There are a few thinks you should know about the extension: + * * YOU have the full controll over the response. That also means + * that you have to set the correct header. + * * YOU have to terminate the request after you have send the response. + * * If the ajax request is not for your method you simply have nothing to + * * return. + * + * + * Usage + * ````` + * // config.php + * $GLOBALS['TL_HOOKS']['rateitAjax'][] = array('MyClass', 'myMethod'); + * + * // MyClass.php + * class MyClass extends System + * { + * public function myMethod() + * { + * if ($this->Input->get('acid') == 'myrequest') + * { + * $arrReturn = array('foo', 'bar', 'foobar'); + * + * header('Content-Type: application/json'); + * echo json_encode($arrReturn); + * exit; + * } + * } + * } + */ +class RateitAjax extends Controller +{ + /** + * Call the parent constructor. + * + * !!! DON'T REMOVE THIS !!! + * + * If you remove this you get the following error message: + * Fatal error: Call to protected System::__construct() from invalid + * context + * + * @param void + * @return void + */ + public function __construct() + { + parent::__construct(); + } + + + /** + * Get the ajax request and call all hooks + * + * @param void + * @return void + */ + public function run() + { + // check if a hook is registered + if (is_array($GLOBALS['TL_HOOKS']['rateitAjax']) && count($GLOBALS['TL_HOOKS']['rateitAjax']) > 0) + { + // execute every registered callback + foreach ($GLOBALS['TL_HOOKS']['rateitAjax'] as $callback) + { + $this->import($callback[0]); + $this->{$callback[0]}->{$callback[1]}(); + } + } + + // if there is no other output, we generate a 412 error response + header('HTTP/1.1 412 Precondition Failed'); + die('Rateit Ajax: Invalid AJAX call.'); + } +} + + +// create a rateit-ajax instance and run it +$objRateitAjax = new RateitAjax(); +$objRateitAjax->run(); + +?>