Exemple #1
0
/**
 *  Returns an SQL search statement
 *
 * The whereclause should NOT start with WHERE
 * The whereclause should contain the output of may_read_SQL and
 * can also be used for sorting
 */
function search($db, $tableinfo, $fields, &$fieldvalues, $whereclause = false, $wcappend = true)
{
    global $db_type;
    $columnvalues = $fieldvalues;
    /* It seems we getter better performance by only asking for id
       keep this code here to revert to in case of side-effetcs
    
       // change fields into a SQL string that works with multiple tables
       $fieldsarray=explode(',',$fields);
       foreach ($fieldsarray as $field) 
          $fieldsSQLstring.=$tableinfo->realname.".$field AS $field, ";
       $fieldsSQLstring=substr($fieldsSQLstring,0,-2);
       // SELECT part
       //$query[0]="SELECT $fieldsSQLstring "; //FROM ".$tableinfo->realname." WHERE ";
    */
    // SELECT part
    $query[0] = "SELECT {$tableinfo->realname}.id ";
    // FROM part
    if ($db_type == 'mysql') {
        $query[1] = 'FROM ' . $tableinfo->realname . ' ';
    } else {
        // non sql databases use tempb table to determine whether user may read a record. Newer Postgres database need tempb in the SQL statement
        $query[1] = 'FROM tempb, ' . $tableinfo->realname . ' ';
    }
    // WHERE part
    $query[2] = 'WHERE ';
    // flag telling whether WHERE field already contains a statement
    $query[5] = false;
    $column = strtok($fields, ',');
    while ($column) {
        if ($query[5]) {
            $query = searchhelp($db, $tableinfo, $column, $columnvalues, $query, $wcappend, "AND");
        } else {
            $query = searchhelp($db, $tableinfo, $column, $columnvalues, $query, $wcappend, $and);
        }
        $column = strtok(',');
    }
    /*
     * Ugly hack needed here.  Go through the sort string (in whereclause)
     * and if there is there an assist tabel in there, we need to make a left join
     * There must be a nicer way to figure this all out.
     */
    if ($whereclause) {
        // figure out if there assist tables in the ORDER By part
        $words = preg_split('/ /', $whereclause);
        $counter = 0;
        foreach ($words as $word) {
            $parts = explode('_', $word);
            // Second part of the if is for the old style naming of assist tables...
            if (substr($parts[1], -3) == 'ass' || substr($parts[0], 0, 3) == 'ass') {
                // found assist table so add LEFT JOIN
                $dotparts = explode('.', $word);
                $query[1] .= 'LEFT JOIN ' . $dotparts[0] . " ON {$dotparts[0]}.id={$tableinfo->realname}.{$dotparts['1']} ";
                // we'll also need to clean up the order by string
                $direction = 'asc';
                for ($j = 1; $j < 4; $j++) {
                    if (substr($words[$counter + $j], 0, 3) == 'asc') {
                        $direction = 'asc';
                        break;
                    } elseif (substr($words[$counter + $j], 0, 4) == 'desc') {
                        $direction = 'desc';
                        break;
                    }
                }
                $newwhereclause .= $dotparts[0] . '.sortkey ' . $direction . ', ' . $dotparts[0] . '.type ';
                // the last asc/desc will be added in the next loop (below)
            } else {
                $newwhereclause .= $word . ' ';
            }
            $counter++;
        }
        $whereclause = $newwhereclause;
        if ($query[5]) {
            $query[2] .= "AND {$whereclause}";
        } else {
            $query[2] .= $whereclause;
        }
    }
    if (function_exists('plugin_search')) {
        $query[0] = plugin_search($query[0], $columnvalues, $query[1]);
    }
    $result = $query[0] . $query[1] . $query[2];
    //echo "$result.<br>";
    return $result;
}
Exemple #2
0
                if (isset($settings['screenshot']) && $settings['screenshot'] == 'enabled') {
                    // Only with screenshot
                    $solr_params['fq']['screenshot'] = 'screenshots_i:1';
                }
                break;
        }
    }
}
// Support for ?owner={username} query parameter
$owner = get_user_by_username(get_input('owner'));
if ($owner) {
    $solr_params['fq']['owner'] = 'owner_guid:' . $owner->guid;
}
// Get objects
elgg_set_context('search');
$result = plugin_search(null, null, array(), $solr_params);
$list = elgg_view_entity_list($result['entities'], array('limit' => $limit, 'offset' => $offset, 'count' => $result['count']));
elgg_set_context('plugins');
$title = elgg_echo('plugins:search:title');
// Add sidebar filter
$sidebar = elgg_view('plugins/filters', array('categories' => $CONFIG->plugincats, 'versions' => $CONFIG->elgg_versions, 'licences' => $CONFIG->gpllicenses, 'current_values' => $filters, 'settings' => $settings));
// Add info block on search results to the main area
if ($result['count']) {
    $first_index = $offset + 1;
    $last_index = min(array($offset + $limit, $result['count']));
    $heading = elgg_view_title(sprintf(elgg_echo('plugins:search:results'), $result['count'], $first_index, $last_index));
} else {
    $heading = elgg_view_title(elgg_echo('plugins:search:noresults'));
    $main = elgg_echo('plugins:search:noresults:info');
}
// Add the list of plugins to the main area