⌈⌋ branch:  freshcode


Check-in [6915580706]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
SHA1:69155807066359806ed73aa4a351bcfa14109683
Date: 2014-08-04 15:58:06
User: mario
Comment:Allow search to look for multiple licenses.
Tags And Properties
  • branch=trunk inherited from [82405bb421]
  • sym-trunk inherited from [82405bb421]
Context
2014-08-04
15:59
[7fd519934c] Added img alt= Unicode glyphs for homepage/download (user: mario, tags: trunk)
15:58
[6915580706] Allow search to look for multiple licenses. (user: mario, tags: trunk)
15:56
[91d97fca70] Removed manual curl() loading. (user: mario, tags: trunk)
Changes

Changes to aux.php.

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
 * Output a list of select <option>s
 *
 * - Either accepts a option,value,field list.
 * - Or an associative array.
 *
 */
function form_select_options($names, $value, $r="") {

    // Transform comma-separated string into array
    $map = is_string($names) ? array_combine($names = str_getcsv($names), $names) : $names;
    
    // Add currently active value if missing
    if ($value and !isset($map[$value])) {
        $map[$value] = $map[$value];
    }
    
    // Output <option> fields
    foreach ($map as $id=>$title) {
        // optgroup
        if (is_array($title)) {







|





|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
 * Output a list of select <option>s
 *
 * - Either accepts a option,value,field list.
 * - Or an associative array.
 *
 */
function form_select_options($names, $value=NULL, $r="") {

    // Transform comma-separated string into array
    $map = is_string($names) ? array_combine($names = str_getcsv($names), $names) : $names;
    
    // Add currently active value if missing
    if ($value and !isset($map[$value]) and $value !== NULL) {
        $map[$value] = $map[$value];
    }
    
    // Output <option> fields
    foreach ($map as $id=>$title) {
        // optgroup
        if (is_array($title)) {

Changes to gimmicks.js.

105
106
107
108
109
110
111
112
113

114

115
116
117
118
119
120
121
    
    // Copying some form fields from /submit to /drchangelog
    $(".action.drchangelog").click(function() {
        $(this).attr("href", "/drchangelog?autoupdate_module=" + $("form[method='POST']").serialize());
        // and let default action proceed
    });

    // Copying some form fields from /submit to /drchangelog
    $("#search_q a").click(function() {

        $(this).attr("href", "/search?q=" + $("#search_q input[name=q]").val());

        // and let default action proceed
    });



    /**
     * Forum actions.







|

>
|
>







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
    
    // Copying some form fields from /submit to /drchangelog
    $(".action.drchangelog").click(function() {
        $(this).attr("href", "/drchangelog?autoupdate_module=" + $("form[method='POST']").serialize());
        // and let default action proceed
    });

    // Append search field in #tools bar
    $("#search_q a").click(function() {
        if (var q = $("#search_q input[name=q]").val()) {
            $(this).attr("href", "/search?q=" + q);
        }
        // and let default action proceed
    });



    /**
     * Forum actions.

Changes to page_search.php.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Actual search request
else {

    // Wrap search params into arrays
    $tags = array_filter(array_merge($_GET->array->words["tags"], $_GET->words->p_csv["tag"]));
    $trove = $_GET->array->words["trove"] and $trove = [$trove, count($trove)];
    $user = $_GET->words["user"] and $user = ["$user%"];
    $license = $_GET->words["license"] and $license = [$license];
    $search = $_GET->text["q"] and $search = ["%$search%"];

    // Run SQL
#   db()->test = 1;
    $result = db("
        SELECT release.name AS name, title, SUBSTR(description,1,500) AS description,
               version, image, homepage, download, submitter, submitter_image,
................................................................................
        HAVING 1=1
               :*  :*  :*  :*  :*
      ORDER BY t_published DESC, t_changed DESC
         LIMIT 100 ",
            // expr :* placeholders only interpolate when inner array contains params
            [" AND description LIKE ? ",  $search],
            [" AND submitter LIKE ? ", $user],
            [" AND license = ? ",   $license],
            [" AND name IN (SELECT name FROM tags WHERE tag IN (??)) ", $tags],
            [" AND name IN (SELECT name FROM tags WHERE tag IN (??)
               GROUP BY name HAVING COUNT(tag) = 1*?) ", $trove]
    );










|







 







|







31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
..
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Actual search request
else {

    // Wrap search params into arrays
    $tags = array_filter(array_merge($_GET->array->words["tags"], $_GET->words->p_csv["tag"]));
    $trove = $_GET->array->words["trove"] and $trove = [$trove, count($trove)];
    $user = $_GET->words["user"] and $user = ["$user%"];
    $license = $_GET->array->words["license"] and $license = array_filter($license);
    $search = $_GET->text["q"] and $search = ["%$search%"];

    // Run SQL
#   db()->test = 1;
    $result = db("
        SELECT release.name AS name, title, SUBSTR(description,1,500) AS description,
               version, image, homepage, download, submitter, submitter_image,
................................................................................
        HAVING 1=1
               :*  :*  :*  :*  :*
      ORDER BY t_published DESC, t_changed DESC
         LIMIT 100 ",
            // expr :* placeholders only interpolate when inner array contains params
            [" AND description LIKE ? ",  $search],
            [" AND submitter LIKE ? ", $user],
            [" AND license IN (??) ",   $license],
            [" AND name IN (SELECT name FROM tags WHERE tag IN (??)) ", $tags],
            [" AND name IN (SELECT name FROM tags WHERE tag IN (??)
               GROUP BY name HAVING COUNT(tag) = 1*?) ", $trove]
    );



Changes to template/search_form.php.

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

23
24
25
26
27

28
29
30
31
32
33
34

35
36
37
38
39
40
41
 * title: Search from
 * description: Show simple search <form>
 *
 *
 */

$select = "form_select_options";
$licenses = array_merge(array(""=>"*Any*"), tags::$licenses);

?>

<h3>Search projects</h3>

<form action="/search" method=GET enctype="application/x-www-form-urlencode" accept-encoding=UTF-8>

    <label>
        Description
        <input name=q type=text size=50>

    </label>

    <label>
        Tags
        <input name=tag type=text size=50>

    </label>

    <label>
        License
        <select name=license>
            <?php print form_select_options($licenses, ""); ?>
        </select>

    </label>
    
    <label> 
       <input type=submit title=Search>
    </label>
    
</form>







|









|
>





>



|
|
|

>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 * title: Search from
 * description: Show simple search <form>
 *
 *
 */

$select = "form_select_options";
$licenses = array_slice(tags::$licenses, 1);

?>

<h3>Search projects</h3>

<form action="/search" method=GET enctype="application/x-www-form-urlencode" accept-encoding=UTF-8>

    <label>
        Description
        <input name=q type=text size=50 style=height:24pt>
        <small>Search in project titles and descriptions.</small>
    </label>

    <label>
        Tags
        <input name=tag type=text size=50>
        <small>Comma-separated list of tags you want to include.</small>
    </label>

    <label>
        Licenses<br>
        <select name="license[]" multiple size=3>
            <?php print form_select_options($licenses, NULL); ?>
        </select>
        <small>Constrain results to a specific libre / open source / free software licenses.</small>
    </label>
    
    <label> 
       <input type=submit title=Search>
    </label>
    
</form>