Skip to content

Commit

Permalink
fixed: decoding ' to apostrophe in filter list data
Browse files Browse the repository at this point in the history
  • Loading branch information
pollen8 committed Nov 26, 2013
1 parent 6e1ecd8 commit 730dd75
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion components/com_fabrik/models/element.php
Expand Up @@ -2864,10 +2864,12 @@ public function getFilter($counter = 0, $normal = true)
$listModel = $this->getListModel();
$formModel = $listModel->getFormModel();
$dbElName = $this->getFullName(false, false, false);

if (!$formModel->hasElement($dbElName))
{
return '';
}

$table = $listModel->getTable();
$element = $this->getElement();
$elName = $this->getFullName(false, true, false);
Expand All @@ -2882,13 +2884,16 @@ public function getFilter($counter = 0, $normal = true)
{
$rows = $this->filterValueList($normal);
$this->unmergeFilterSplits($rows);

if (!in_array($element->filter_type, array('checkbox', 'multiselect')))
{
array_unshift($rows, JHTML::_('select.option', '', $this->filterSelectLabel()));
}
}

$size = (int) $this->getParams()->get('filter_length', 20);
$class = $this->filterClass();

switch ($element->filter_type)
{
case 'range':
Expand Down Expand Up @@ -2933,7 +2938,9 @@ public function getFilter($counter = 0, $normal = true)
$return = array_merge($return, $autoComplete);
break;
}

$return[] = $normal ? $this->getFilterHiddenFields($counter, $elName) : $this->getAdvancedFilterHiddenFields();

return implode("\n", $return);
}

Expand Down Expand Up @@ -3110,21 +3117,26 @@ protected function unmergeFilterSplits(&$rows)
)
*/
$allvalues = array();

foreach ($rows as $row)
{
$allvalues[] = $row->value;
}

$c = count($rows) - 1;

for ($j = $c; $j >= 0; $j--)
{
$vals = FabrikWorker::JSONtoData($rows[$j]->value, true);
$txt = FabrikWorker::JSONtoData($rows[$j]->text, true);

if (is_array($vals))
{
for ($i = 0; $i < count($vals); $i++)
{
$vals2 = FabrikWorker::JSONtoData($vals[$i], true);
$txt2 = FabrikWorker::JSONtoData(JArrayHelper::getValue($txt, $i), true);

for ($jj = 0; $jj < count($vals2); $jj++)
{
if (!in_array($vals2[$jj], $allvalues))
Expand All @@ -3134,12 +3146,14 @@ protected function unmergeFilterSplits(&$rows)
}
}
}

if (FabrikWorker::isJSON($rows[$j]->value))
{
// $$$ rob 01/10/2012 - if not unset then you could get json values in standard dd filter (checkbox)
unset($rows[$j]);
}
}

if (count($vals) > 1)
{
unset($rows[$j]);
Expand Down Expand Up @@ -3322,6 +3336,7 @@ protected function getFilterBuildMethod()
public function filterValueList($normal, $tableName = '', $label = '', $id = '', $incjoin = true)
{
$filter_build = $this->getFilterBuildMethod();

if ($filter_build == 2 && $this->hasSubElements)
{
return $this->filterValueList_All($normal, $tableName, $label, $id, $incjoin);
Expand Down Expand Up @@ -3369,6 +3384,7 @@ protected function filterValueList_Exact($normal, $tableName = '', $label = '',
$elName = $this->getFullName(false, true, false);
$params = $this->getParams();
$elName2 = $this->getFullName(false, false, false);

if (!$this->isJoin())
{
$ids = $listModel->getColumnData($elName2);
Expand All @@ -3386,6 +3402,7 @@ protected function filterValueList_Exact($normal, $tableName = '', $label = '',
}
}
}

$incjoin = $this->isJoin() ? false : $incjoin;
/**
* filter the drop downs lists if the table_view_own_details option is on
Expand All @@ -3412,21 +3429,26 @@ protected function filterValueList_Exact($normal, $tableName = '', $label = '',
}
}
}

$elName = FabrikString::safeColName($elName);

if ($label == '')
{
$label = $this->isJoin() ? $this->getElement()->name : $elName;
}

if ($id == '')
{
$id = $this->isJoin() ? 'id' : $elName;
}

if ($this->encryptMe())
{
$secret = JFactory::getConfig()->getValue('secret');
$label = 'AES_DECRYPT(' . $label . ', ' . $fabrikDb->quote($secret) . ')';
$id = 'AES_DECRYPT(' . $id . ', ' . $fabrikDb->quote($secret) . ')';
}

$origTable = $tableName == '' ? $origTable : $tableName;
/**
* $$$ rob - 2nd sql was blowing up for me on my test table - why did we change to it?
Expand All @@ -3443,30 +3465,40 @@ protected function filterValueList_Exact($normal, $tableName = '', $label = '',
$sql = 'SELECT DISTINCT(' . $label . ') AS ' . $fabrikDb->quoteName('text') . ', ' . $id . ' AS ' . $fabrikDb->quoteName('value')
. ' FROM ' . $fabrikDb->quoteName($fromTable) . ' ' . $joinStr . "\n";
}

if (!$this->isJoin())
{
$sql .= 'WHERE ' . $id . ' IN (\'' . implode("','", $ids) . '\')';
}

// Apply element where/order by statements to the filter (e.g. dbjoins 'Joins where and/or order by statement')
$elementWhere = $this->_buildQueryWhere(array(), true, null, array('mode' => 'filter'));

if (JString::stristr($sql, 'WHERE ') && JString::stristr($elementWhere, 'WHERE '))
{
// $$$ hugh - only replace the WHERE with AND if it's the first word, so we don't munge sub-queries
// $elementWhere = JString::str_ireplace('WHERE ', 'AND ', $elementWhere);
$elementWhere = preg_replace("#^(\s*)(WHERE)(.*)#i", "$1AND$3", $elementWhere);

}

$sql .= ' ' . $elementWhere;
$sql .= "\n" . $groupBy;
$sql = $listModel->pluginQuery($sql);
$fabrikDb->setQuery($sql, 0, $fbConfig->get('filter_list_max', 100));
FabrikHelperHTML::debug($fabrikDb->getQuery(), 'element filterValueList_Exact:');
$rows = $fabrikDb->loadObjectList();

if ($fabrikDb->getErrorNum() != 0)
{
JError::raiseNotice(500, 'filter query error: ' . $this->getElement()->name . ' ' . $fabrikDb->getErrorMsg());
}

// Convert "&#039;" to "'". see http://fabrikar.com/forums/index.php?threads/wrong-decode-in-dd-filter-on-a-joined-elt.36711/
foreach ($rows as &$row)
{
$row->text = html_entity_decode($row->text, ENT_QUOTES);
}

return $rows;

}
Expand Down Expand Up @@ -3537,10 +3569,12 @@ protected function filterValueList_All($normal, $tableName = '', $label = '', $i
$vals = $this->getSubOptionValues();
$labels = $this->getSubOptionLabels();
$return = array();

for ($i = 0; $i < count($vals); $i++)
{
$return[] = JHTML::_('select.option', $vals[$i], $labels[$i]);
}

return $return;
}

Expand Down

0 comments on commit 730dd75

Please sign in to comment.