Skip to content

Commit

Permalink
Fixing some code-rot in thumbs element, hadn't been updated to identify
Browse files Browse the repository at this point in the history
list rows using getRenderContext(), also tidying up and safe-ing some
queries.
  • Loading branch information
cheesegrits committed Aug 7, 2012
1 parent 2516e31 commit 3a1dd51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/fabrik_element/thumbs/list-thumbs-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions plugins/fabrik_element/thumbs/list-thumbs.js
Expand Up @@ -15,14 +15,13 @@ var FbThumbsList = new Class({

initialize: function (id, options) {
this.setOptions(options);
//this.spinner = Fabrik.loader.getSpinner();
this.col = $$('.' + id);
this.origThumbUp = {};
this.origThumbDown = {};
this.col.each(function (tr) {
var row = tr.getParent('.fabrik_row');
if (row) {
var rowid = row.id.replace('list_' + this.options.listid + '_row_', '');
var rowid = row.id.replace('list_' + this.options.renderContext + '_row_', '');
var thumbup = tr.getElements('.thumbup');
var thumbdown = tr.getElements('.thumbdown');
thumbup.each(function (thumbup) {
Expand Down Expand Up @@ -67,7 +66,7 @@ var FbThumbsList = new Class({

doAjax: function (e, thumb) {
var row = e.getParent('.fabrik_row');
var rowid = row.id.replace('list_' + this.options.listid + '_row_', '');
var rowid = row.id.replace('list_' + this.options.renderContext + '_row_', '');
var count_thumb = document.id('count_thumb' + thumb + rowid);
Fabrik.loader.start(count_thumb);
this.thumb = thumb;
Expand All @@ -93,7 +92,6 @@ var FbThumbsList = new Class({
var count_thumbdown = document.id('count_thumbdown' + rowid);
var thumbup = row.getElements('.thumbup');
var thumbdown = row.getElements('.thumbdown');
this.spinner.dispose();
Fabrik.loader.stop(count_thumb);
//r = r.split(this.options.splitter2);
r = JSON.decode(r);
Expand Down
23 changes: 17 additions & 6 deletions plugins/fabrik_element/thumbs/thumbs.php
Expand Up @@ -311,12 +311,22 @@ private function doThumb($listid, $formid, $row_id, $thumb)
$userid = $db->quote($hash);
}
$elementid = $this->getElement()->id;
$db
->setQuery(
"INSERT INTO #__{package}_thumbs (user_id, listid, formid, row_id, thumb, date_created, element_id)
values ($userid, $listid, $formid, $row_id, " . $db->quote($thumb)
. ", $strDate, $elementid)
ON DUPLICATE KEY UPDATE date_created = $strDate, thumb = " . $db->quote($thumb));
$db->setQuery(
"INSERT INTO #__{package}_thumbs
(user_id, listid, formid, row_id, thumb, date_created, element_id)
values (
" . $db->Quote($userid) . ",

This comment has been minimized.

Copy link
@pollen8

pollen8 Aug 7, 2012

Member

why quote integer values? Also should be quote() and not Quote()
plus whilst you're here the query should be done using the query builder ($query = $db->getQuery(true)

This comment has been minimized.

Copy link
@cheesegrits

cheesegrits Aug 8, 2012

Author Member

'cos some of them are coming direct from request vars, and as far as I know quoting integers won't hurt anything, so best to err on the safe side. http://xkcd.com/327/

And yeah, I know I should replace it with the New Query Builder, but I was in a hurry just trying to get something working. I'll rework the queries next time I'm in the code, and you are back from competing in the Mens Javelain Catching event at the Olympics, so I have a little more time. :)

This comment has been minimized.

Copy link
@pollen8

pollen8 Aug 8, 2012

Member

i'd case then to integers though :)

" . $db->Quote($listid) . ",
" . $db->Quote($formid) . ",
" . $db->Quote($row_id) . ",
" . $db->quote($thumb) . ",
" . $db->Quote($strDate) . ",
" . $db->Quote($elementid) . "
)
ON DUPLICATE KEY UPDATE
date_created = " . $db->Quote($strDate) . ",
thumb = " . $db->quote($thumb)
);
$db->query();
if ($db->getErrorNum())
{
Expand Down Expand Up @@ -439,6 +449,7 @@ function elementListJavascript()
$opts->elid = $this->getElement()->id;
$opts->myThumbs = $listMyThumbs;
$opts->userid = "$userid";
$opts->renderContext = $this->getListModel()->getRenderContext();
$opts = json_encode($opts);
return "new FbThumbsList('$id', $opts);\n";
}
Expand Down

0 comments on commit 3a1dd51

Please sign in to comment.