diff --git a/classes/DcaHelper.php b/classes/DcaHelper.php index 830303c..ea4964b 100644 --- a/classes/DcaHelper.php +++ b/classes/DcaHelper.php @@ -90,7 +90,7 @@ class DcaHelper extends \Backend } } else { $this->Database->prepare("UPDATE tl_rateit_items SET active='' WHERE rkey=? and typ=?") - ->execute($dc->activeRecord->id, $typ) + ->execute($dc->activeRecord->id, $type) ->updatedId; } diff --git a/classes/RateItBackendModule.php b/classes/RateItBackendModule.php index 578a865..acfb5f8 100644 --- a/classes/RateItBackendModule.php +++ b/classes/RateItBackendModule.php @@ -634,8 +634,8 @@ class rateitBackendModule extends \BackendModule $cntSql = str_replace('%s', $where, $cntSql); $count = $this->Database->prepare($cntSql) - ->execute() - ->fetchRow(); + ->execute() + ->fetchRow(); $arrRatingItems = $this->Database->prepare($sql) ->execute() diff --git a/public/js/rateit-uncompressed.js b/public/js/rateit-uncompressed.js index 8f20353..8fc3360 100644 --- a/public/js/rateit-uncompressed.js +++ b/public/js/rateit-uncompressed.js @@ -312,9 +312,10 @@ function doRateIt() { el.data('selected', el.find('.rateItRating-selected')); el.data('hover', el.find('.rateItRating-hover')); - var backgroundImage = self.getBackgroundImage(el.data('wrapper')); - self.options.starwidth = backgroundImage.width; - self.options.starheight = backgroundImage.height / 3; // da immer drei Sterne "übereinander" gebraucht werden + jQuery.when(self.getBackgroundImage(el.data('wrapper'))).done(function(backgroundImageSize) { + self.options.starwidth = backgroundImageSize[0]; + self.options.starheight = backgroundImageSize[1] / 3; // da immer drei Sterne "übereinander" gebraucht werden + }); if (self.options.starwidth === undefined || self.options.starwidth < 16) { self.options.starwidth = 16; } @@ -498,13 +499,21 @@ function doRateIt() { }, getBackgroundImage: function(el) { + var dfd = jQuery.Deferred(); + var backgroundImageSize = new Array(); 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; + + jQuery('') + .attr('src', string) + .load(function() { + backgroundImageSize.push(this.width); + backgroundImageSize.push(this.height); + dfd.resolve(backgroundImageSize); + }); + return dfd.promise(); }, updateText: function(el, text) { diff --git a/public/js/rateit.js b/public/js/rateit.js index 6486824..6c7a6f4 100644 --- a/public/js/rateit.js +++ b/public/js/rateit.js @@ -1 +1,24 @@ -function doRateIt(){if(window.MooTools){var e=new Class({Implements:Options,options:{step:.1,readonly:false,resetable:false},initialize:function(e){this.setOptions(e);$$(".rateItRating").each(function(e){this.initMe(e)}.bind(this))},initMe:function(e){if(!Browser.ie||Browser.version>6){e.id=e.getAttribute("id");e.rateable=e.getAttribute("rel")=="not-rateable"?false:true;e.wrapper=e.getElement(".wrapper");e.textEl=e.getElement(".ratingText");e.selected=e.wrapper.getElement(".rateItRating-selected");e.hover=e.wrapper.getElement(".rateItRating-hover");e.widthFx=new Fx.Tween(e.selected,{property:"width",link:"chain"});var t=this.getBackgroundImage(e.wrapper);this.options.starwidth=t.width;this.options.starheight=t.height/3;if(this.options.starwidth===undefined||this.options.starwidth<16){this.options.starwidth=16}if(this.options.starheight===undefined||this.options.starheight<16){this.options.starheight=16}this.setBackgroundPosition(e.selected,-1*this.options.starheight);this.setBackgroundPosition(e.hover,-1*2*this.options.starheight);e.starPercent=this.getStarPercent(e.id);e.ratableId=this.getRatableId(e.id);e.ratableType=this.getRatableType(e.id);this.options.max=this.getRatableMaxValue(e.id);e.selected.setStyle("height",this.options.starheight);e.hover.setStyle("height",this.options.starheight);e.wrapper.setStyle("width",this.options.starwidth*this.options.max);e.wrapper.setStyle("height",this.options.starheight);this.fillVote(e.starPercent,e);e.currentFill=this.getFillPercent(e.starPercent);if(e.rateable){e.mouseCrap=function(t){var n=t.event.layerX;if(!n){n=t.event.offsetX}var r=this.getVotePercent(n);var i=Math.ceil(r/100*this.options.max);var s=i*this.options.starwidth;if(e.hover.getStyle("width").toInt()!=s){e.selected.setStyle("display","none");e.hover.setStyle("width",Math.min(s,this.options.starwidth*this.options.max));e.hover.setStyle("display","block")}var o=i/this.options.max*100;this.fillVote(o,e)}.bind(this);e.wrapper.addEvent("mouseenter",function(t){e.wrapper.addEvent("mousemove",e.mouseCrap)});e.wrapper.addEvent("mouseleave",function(t){e.removeEvent("mousemove");e.hover.setStyle("width",0);e.hover.setStyle("display","none");e.selected.setStyle("display","block");e.widthFx.start(e.currentFill)});e.wrapper.addEvent("click",function(t){e.currentFill=e.newFill;e.wrapper.removeEvents();e.textEl.oldTxt=e.textEl.get("text");e.textEl.set("html","          ");e.textEl.addClass("loading");if(typeof $(".mbrateItRating")!="undefined"&&e.id.indexOf("mb")==0){var n=e.id;n=n.replace("mb","");if(typeof arrRatings=="object"){for(var r=0;r100){t.newFill=this.getFillPercent(100)}t.selected.setStyle("width",t.newFill)},getStarPercent:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(t!=null){var n=t[3].toFloat();var r=t[4].toFloat();var i=n/r*100;return i}else{return 0}},getFillPercent:function(e){return e/100*this.options.starwidth*this.options.max},getVotePercent:function(e){var t=this.options.starwidth*this.options.max;var n=(e/t*100).round(2);return n},getRatableId:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?t[1]:""},getRatableType:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?t[2]:""},getRatableMaxValue:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?t[4].toInt():0},setBackgroundPosition:function(e,t){e.setStyle("background-position","0% "+t+"px")},getBackgroundImagePath:function(e){return e.getStyle("background-image")},getBackgroundImage:function(e){var t=/url\s*\(["']?(.*)["']?\)/i;var n=document.createElement("img");var r=this.getBackgroundImagePath(e);r=r.match(t)[1];r=r.replace('"',"");n.src=r;return n}});window.addEvent("domready",function(t){RateItRating=new e({url:"SimpleAjax.php"})})}else if(window.jQuery){(function(){e={options:{step:.1,readonly:false,resetable:false},initialize:function(e){if(typeof e=="object"&&typeof e["url"]!="undefined")this.options.url=e["url"];var t=this;jQuery(".rateItRating").each(function(e,n){t.initMe(n)});return this},initMe:function(e){var n=this;if(!Browser.Engine.trident4){var r=jQuery(e);r.data("id",r.attr("id"));r.data("rateable",r.attr("rel")=="not-rateable"?false:true);r.data("wrapper",r.find(".wrapper"));r.data("textEl",r.find(".ratingText"));r.data("selected",r.find(".rateItRating-selected"));r.data("hover",r.find(".rateItRating-hover"));var i=n.getBackgroundImage(r.data("wrapper"));n.options.starwidth=i.width;n.options.starheight=i.height/3;if(n.options.starwidth===undefined||n.options.starwidth<16){n.options.starwidth=16}if(n.options.starheight===undefined||n.options.starheight<16){n.options.starheight=16}n.setBackgroundPosition(r.data("selected"),-1*n.options.starheight);n.setBackgroundPosition(r.data("hover"),-1*2*n.options.starheight);r.data("starPercent",n.getStarPercent(r.data("id")));r.data("ratableId",n.getRatableId(r.data("id")));r.data("ratableType",n.getRatableType(r.data("id")));n.options.max=n.getRatableMaxValue(r.data("id"));r.data("selected").css("height",n.options.starheight);r.data("hover").css("height",n.options.starheight);r.data("wrapper").css("width",n.options.starwidth*n.options.max);r.data("wrapper").css("height",n.options.starheight);n.fillVote(r.data("starPercent"),r);r.data("currentFill",n.getFillPercent(r.data("starPercent")));if(r.data("rateable")){r.data("wrapper").mouseenter(function(e){r.data("selected").hide(500,"easeInOutQuad");r.data("hover").show();r.data("wrapper").mousemove({el:r,self:n},n.mouseCrap)});r.data("wrapper").mouseleave(function(e){r.data("wrapper").unbind("mousemove");r.data("hover").hide();r.data("selected").show();r.data("selected").animate({width:r.data("currentFill")},500)});r.data("wrapper").click(function(e){r.data("currentFill",r.data("newFill"));r.data("wrapper").unbind();r.data("oldTxt",r.data("textEl").text());r.data("textEl").html("          ");r.data("textEl").addClass("loading");if(typeof jQuery(".mbrateItRating")!="undefined"&&r.data("id").indexOf("mb")==0){var i=r.data("id");i=i.replace("mb","");if(typeof arrRatings=="object"){for(var s=0;s100){t.data("newFill",this.getFillPercent(100))}t.data("selected").css("width",t.data("newFill"))},mouseCrap:function(e){var t=e.data["el"];var n=e.data["self"];var r=e.originalEvent.layerX;if(!r){r=e.originalEvent.offsetX}var i=n.getVotePercent(r);var s=Math.ceil(i/100*n.options.max);var o=s*n.options.starwidth;if(parseInt(t.data("hover").css("width"))!=o){t.data("selected").css("display","none");t.data("hover").css("width",Math.min(o,n.options.starwidth*n.options.max));t.data("hover").css("display","block")}var u=s/n.options.max*100;n.fillVote(u,t)},getStarPercent:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);if(t!=null){var n=parseFloat(t[3]);var r=parseFloat(t[4]);var i=n/r*100;return i}else{return 0}},getFillPercent:function(e){return e/100*this.options.starwidth*this.options.max},getVotePercent:function(e){var t=this.options.starwidth*this.options.max;var n=(e/t*100).toFixed(2);return n},getRatableId:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?t[1]:""},getRatableType:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?t[2]:""},getRatableMaxValue:function(e){var t=e.match(/(\d*\|?\d*)-(page|article|ce|module|news|faq|galpic|news4ward)-(\d*\.?\d+)_(\d*\.?\d+)$/);return t!=null?parseInt(t[4]):0},setBackgroundPosition:function(e,t){e.css("background-position","0% "+t+"px")},getBackgroundImagePath:function(e){return e.css("background-image")},getBackgroundImage:function(e){var t=/url\s*\(["']?(.*)["']?\)/i;var n=document.createElement("img");var r=this.getBackgroundImagePath(e);r=r.match(t)[1];r=r.replace('"',"");n.src=r;return n},updateText:function(e,n){error=n.split("ERROR:")[1];e.data("textEl").removeClass("loading");if(error){this.RateItRating.showError(e,error);return false}e.data("textEl").text(n);if(typeof jQuery(".mbrateItRating")!="undefined"&&e.data("id").indexOf("mb")==0){var r=e.attr("id");r=r.replace("mb","");if(typeof arrRatings=="object"){for(var i=0;i6){el.id=el.getAttribute('id');el.rateable=el.getAttribute('rel')=='not-rateable'?false:true;el.wrapper=el.getElement('.wrapper');el.textEl=el.getElement('.ratingText');el.selected=el.wrapper.getElement('.rateItRating-selected');el.hover=el.wrapper.getElement('.rateItRating-hover');el.widthFx=new Fx.Tween(el.selected,{property:'width',link:'chain'});var backgroundImage=this.getBackgroundImage(el.wrapper);this.options.starwidth=backgroundImage.width;this.options.starheight=backgroundImage.height/3;if(this.options.starwidth===undefined||this.options.starwidth<16){this.options.starwidth=16;} +if(this.options.starheight===undefined||this.options.starheight<16){this.options.starheight=16;} +this.setBackgroundPosition(el.selected,-1*this.options.starheight);this.setBackgroundPosition(el.hover,-1*2*this.options.starheight);el.starPercent=this.getStarPercent(el.id);el.ratableId=this.getRatableId(el.id);el.ratableType=this.getRatableType(el.id);this.options.max=this.getRatableMaxValue(el.id);el.selected.setStyle('height',this.options.starheight);el.hover.setStyle('height',this.options.starheight);el.wrapper.setStyle('width',this.options.starwidth*this.options.max);el.wrapper.setStyle('height',this.options.starheight);this.fillVote(el.starPercent,el);el.currentFill=this.getFillPercent(el.starPercent);if(el.rateable){el.mouseCrap=function(e){var fill=e.event.layerX;if(!fill){fill=e.event.offsetX;} +var fillPercent=this.getVotePercent(fill);var nextStep=Math.ceil((fillPercent/100)*this.options.max);var w=nextStep*this.options.starwidth;if(el.hover.getStyle('width').toInt()!=w){el.selected.setStyle('display','none');el.hover.setStyle('width',Math.min(w,this.options.starwidth*this.options.max));el.hover.setStyle('display','block');} +var newFill=nextStep/this.options.max*100;this.fillVote(newFill,el);}.bind(this);el.wrapper.addEvent('mouseenter',function(e){el.wrapper.addEvent('mousemove',el.mouseCrap);});el.wrapper.addEvent('mouseleave',function(e){el.removeEvent('mousemove');el.hover.setStyle('width',0);el.hover.setStyle('display','none');el.selected.setStyle('display','block');el.widthFx.start(el.currentFill);});el.wrapper.addEvent('click',function(e){el.currentFill=el.newFill;el.wrapper.removeEvents();el.textEl.oldTxt=el.textEl.get('text');el.textEl.set('html','          ');el.textEl.addClass('loading');if(typeof($('.mbrateItRating'))!='undefined'&&el.id.indexOf('mb')==0){var mbid=el.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'});});}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;ri100){el.data('newFill',this.getFillPercent(100));} +el.data('selected').css('width',el.data('newFill'));},mouseCrap:function(event){var el=event.data['el'];var self=event.data['self'];var fill=event.originalEvent.layerX;if(!fill){fill=event.originalEvent.offsetX;} +var fillPercent=self.getVotePercent(fill);var nextStep=Math.ceil((fillPercent/100)*self.options.max);var w=nextStep*self.options.starwidth;if(parseInt(el.data('hover').css('width'))!=w){el.data('selected').css('display','none');el.data('hover').css('width',Math.min(w,self.options.starwidth*self.options.max));el.data('hover').css('display','block');} +var newFill=nextStep/self.options.max*100;self.fillVote(newFill,el);},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=parseFloat(stars[3]);var scale=parseFloat(stars[4]);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).toFixed(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?parseInt(stars[4]):0;},setBackgroundPosition:function(el,pos){el.css('background-position','0% '+pos+'px');},getBackgroundImagePath:function(el){return el.css("background-image");},getBackgroundImage:function(el){var dfd=jQuery.Deferred();var backgroundImageSize=new Array();var reg_imgFile=/url\s*\(["']?(.*)["']?\)/i;var string=this.getBackgroundImagePath(el);string=string.match(reg_imgFile)[1];string=string.replace('\"','');jQuery('').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;ricount(); // Die with an error if the insert fails (duplicate IP or duplicate member id for a vote). - if (((!$this->allowDuplicates && $countIp == 0) || $this->allowDuplicates) || - ((!$this->allowDuplicatesForMembers && (isset($countUser) ? $countUser == 0 : false)) || ($this->allowDuplicatesForMembers && isset($userId)))) { + if ((!$this->allowDuplicatesForMembers && (isset($countUser) ? $countUser == 0 : false)) || ($this->allowDuplicatesForMembers && isset($userId))) { + // Insert the data. + $arrSet = array('pid' => $ratableKeyId['id'], + 'tstamp' => time(), + 'ip_address' => $ip, + 'memberid' => isset($userId) ? $userId : null, + 'rating' => $rating, + 'createdat'=> time() + ); + $this->Database->prepare('INSERT INTO tl_rateit_ratings %s') + ->set($arrSet) + ->execute(); + } elseif (!isset($countUser) && ((!$this->allowDuplicates && $countIp == 0) || $this->allowDuplicates)) { // Insert the data. $arrSet = array('pid' => $ratableKeyId['id'], 'tstamp' => time(), @@ -147,7 +158,7 @@ class RateIt extends \Frontend { ->set($arrSet) ->execute(); } else { - header(RETURN_AJAX_HEADER); + header(RETURN_AJAX_HEADER); echo $GLOBALS['TL_LANG']['rateit']['error']['duplicate_vote']; exit; }