소스 검색

Merge pull request #282 from Piralein/license

Add a license select filter and remove the link filter
Emi 2 년 전
부모
커밋
70b8381112
7개의 변경된 파일46개의 추가작업 그리고 27개의 파일을 삭제
  1. 1 0
      API.md
  2. 20 0
      src/constants.php
  3. 2 2
      src/queries.php
  4. 6 0
      src/routes/asset.php
  5. 1 21
      templates/_asset_fields.phtml
  6. 1 1
      templates/asset.phtml
  7. 15 3
      templates/assets.phtml

+ 1 - 0
API.md

@@ -133,6 +133,7 @@ Get a list of categories (needed for filtering assets) and potentially a login U
 &support=(official|community|testing)
 &filter=(search text)
 &user=(submitter username)
+&cost=(license)
 &godot_version=(major).(minor).(patch)
 &max_results=(number 1…500)
 &page=(number, pages to skip) OR &offset=(number, rows to skip)

+ 20 - 0
src/constants.php

@@ -71,5 +71,25 @@ return $constants = [
         '4.0',
         'unknown',
         'custom_build',
+    ],
+    'licenses' => [
+        'MIT' => 'MIT',
+        'MPL-2.0' => 'MPL-2.0',
+        'GPLv3' => 'GPL v3',
+        'GPLv2' => 'GPL v2',
+        'LGPLv3' => 'LGPL v3',
+        'LGPLv2.1' => 'LGPL v2.1',
+        'LGPLv2' => 'LGPL v2',
+        'AGPLv3' => 'AGPL v3',
+        'Apache-2.0' => 'Apache 2.0',
+        'CC0' => 'CC0 1.0 Universal',
+        'CC-BY-4.0' => 'CC BY 4.0 International',
+        'CC-BY-3.0' => 'CC BY 3.0 Unported',
+        'CC-BY-SA-4.0' => 'CC BY-SA 4.0 International',
+        'CC-BY-SA-3.0' => 'CC BY-SA 3.0 Unported',
+        'BSD-2-Clause' => 'BSD 2-clause License',
+        'BSD-3-Clause' => 'BSD 3-clause License',
+        'BSL-1.0' => 'Boost Software License',
+        'Unlicense' => 'The Unlicense License'
     ]
 ];

+ 2 - 2
src/queries.php

@@ -29,7 +29,7 @@ return [
             LEFT JOIN `as_categories` USING (category_id)
 
             WHERE searchable = TRUE AND category_id LIKE :category AND category_type LIKE :category_type
-            AND support_level RLIKE :support_levels_regex AND username LIKE :username
+            AND support_level RLIKE :support_levels_regex AND username LIKE :username AND cost LIKE :cost
             AND godot_version <= :max_godot_version AND godot_version >= :min_godot_version
             AND (
                 title LIKE :filter
@@ -63,7 +63,7 @@ return [
             LEFT JOIN `as_users` USING (user_id)
             LEFT JOIN `as_categories` USING (category_id)
             WHERE searchable = TRUE AND category_id LIKE :category AND category_type LIKE :category_type
-            AND support_level RLIKE :support_levels_regex AND username LIKE :username
+            AND support_level RLIKE :support_levels_regex AND username LIKE :username AND cost LIKE :cost
             AND godot_version <= :max_godot_version AND godot_version >= :min_godot_version
             AND (
                 title LIKE :filter

+ 6 - 0
src/routes/asset.php

@@ -8,6 +8,7 @@ $app->get('/asset', function ($request, $response, $args) {
     $category = '%';
     $filter = '%';
     $username = '%';
+    $cost = '%';
     $order_column = 'modify_date';
     $support_levels = [];
     $page_size = 40;
@@ -50,6 +51,9 @@ $app->get('/asset', function ($request, $response, $args) {
     if (isset($params['user'])) {
         $username = $params['user'];
     }
+    if (isset($params['cost']) && $params['cost'] != "") {
+        $cost = $params['cost'];
+    }
     if (isset($params['max_results'])) {
         $page_size = min(abs((int) $params['max_results']), $max_page_size);
     }
@@ -107,6 +111,7 @@ $app->get('/asset', function ($request, $response, $args) {
     $query->bindValue(':support_levels_regex', $support_levels);
     $query->bindValue(':filter', $filter);
     $query->bindValue(':username', $username);
+    $query->bindValue(':cost', $cost);
     $query->bindValue(':order', $order_column);
     $query->bindValue(':order_direction', $order_direction);
     $query->bindValue(':page_size', $page_size, PDO::PARAM_INT);
@@ -126,6 +131,7 @@ $app->get('/asset', function ($request, $response, $args) {
     $query_count->bindValue(':support_levels_regex', $support_levels);
     $query_count->bindValue(':filter', $filter);
     $query_count->bindValue(':username', $username);
+    $query_count->bindValue(':cost', $cost);
     $query_count->execute();
 
     $error = $this->utils->errorResponseIfQueryBad(false, $response, $query_count);

+ 1 - 21
templates/_asset_fields.phtml

@@ -60,32 +60,12 @@ $_asset_values = array_merge([
     <label class="col-md-4 control-label required_mark" for="license">License</label>
     <div class="col-md-5">
         <select id="license" name="cost" class="form-control" required="">
-            <?php $licenses = [
-                'MIT' => 'MIT',
-                'MPL-2.0' => 'MPL-2.0',
-                'GPLv3' => 'GPL v3',
-                'GPLv2' => 'GPL v2',
-                'LGPLv3' => 'LGPL v3',
-                'LGPLv2.1' => 'LGPL v2.1',
-                'LGPLv2' => 'LGPL v2',
-                'AGPLv3' => 'AGPL v3',
-                'Apache-2.0' => 'Apache 2.0',
-                'CC0' => 'CC0 1.0 Universal',
-                'CC-BY-4.0' => 'CC BY 4.0 International',
-                'CC-BY-3.0' => 'CC BY 3.0 Unported',
-                'CC-BY-SA-4.0' => 'CC BY-SA 4.0 International',
-                'CC-BY-SA-3.0' => 'CC BY-SA 3.0 Unported',
-                'BSD-2-Clause' => 'BSD 2-clause License',
-                'BSD-3-Clause' => 'BSD 3-clause License',
-                'BSL-1.0' => 'Boost Software License',
-                'Unlicense' => 'The Unlicense License'
-            ] ?>
             <?php if(!$_asset_values['cost']) { ?>
                 <option value="" selected="">
                     Select...
                 </option>
             <?php } ?>
-            <?php foreach($licenses as $id => $name) { ?>
+            <?php foreach($constants['licenses'] as $id => $name) { ?>
                 <option value="<?php echo raw($id) ?>" <?php if($id == $_asset_values['cost']) echo 'selected=""'; ?>>
                     <?php echo esc($name) ?>
                 </option>

+ 1 - 1
templates/asset.phtml

@@ -25,7 +25,7 @@
 
         <p class="text-muted">
             Submitted by user <a href="<?php echo raw($basepath) ?>/asset?user=<?php echo esc($data['author']) ?>" title="Search assets by '<?php echo esc($data['author']) ?>'"><?php echo esc($data['author']) ?></a>;
-            <a href="<?php echo raw($basepath) ?>/asset?filter=<?php echo esc($data['cost']) ?>" title="Search assets with filter '<?php echo esc($data['cost']) ?>'"><?php echo esc($data['cost']) ?></a>;
+            <?php echo esc($data['cost']) ?>;
             <?php echo esc(explode(" ", $data['modify_date'])[0]) ?>
         </p>
         <p>

+ 15 - 3
templates/assets.phtml

@@ -52,6 +52,20 @@
                     <?php } ?>
                 </select>
             </div>
+            <div class="form-group">
+                <label for="license">License</label>
+                <select id="license" name="cost" class="form-control">
+                    <option value="">
+                        Any
+                    </option>
+
+                    <?php foreach($constants['licenses'] as $id => $license) { ?>
+                        <option value="<?php echo url($id) ?>" <?php if(isset($params['cost']) && $id == $params['cost']) echo 'selected=""'; ?>>
+                            <?php echo esc($license) ?>
+                        </option>
+                    <?php } ?>
+                </select>
+            </div>
             <div class="form-group">
                 <label for="sort">Order by</label>
                 <select id="sort" name="sort" class="form-control">
@@ -112,9 +126,7 @@
 
                             <p class="text-muted">
                                 Submitted by user <a href="?user=<?php echo esc($asset['author']) ?>" title="Search assets by '<?php echo esc($asset['author']) ?>'"><?php echo esc($asset['author']) ?></a>;
-                                <a href="?<?php echo esc(http_build_query([
-                                    'filter' => $asset['cost'] // isset($params['filter']) ? $params['filter'] . ' ' . $asset['cost'] : $asset['cost']
-                                ] + $params)) ?>" title="Search assets with filter '<?php echo esc($asset['cost']) ?>'"><?php echo esc($asset['cost']) ?></a>;
+                                <?php echo esc($asset['cost']) ?>;
                                 <span class="nowrap"><?php echo esc(explode(" ", $asset['modify_date'])[0]) ?></span>
                             </p>
                         </div>