show all mods on homepage

This commit is contained in:
Brett O'Donnell 2018-04-12 18:22:18 +09:30
parent 9e98ddc2f0
commit ebb5245fde
12 changed files with 170 additions and 154 deletions

View File

@ -3,7 +3,7 @@ use yii\helpers\ArrayHelper;
$config = [ $config = [
'id' => 'minetest-bower', 'id' => 'minetest-bower',
'name' => 'Minetest Bower', 'name' => 'Minetest Mods',
'basePath' => dirname(__DIR__), 'basePath' => dirname(__DIR__),
'vendorPath' => '@app/../vendor', 'vendorPath' => '@app/../vendor',
'runtimePath' => '@app/../runtime', 'runtimePath' => '@app/../runtime',

View File

@ -27,34 +27,34 @@ class ModController extends Controller
* Browse Package models. * Browse Package models.
* @return mixed * @return mixed
*/ */
public function actionIndex() //public function actionIndex()
{ //{
$searchModel = new PackageSearch(); // $searchModel = new PackageSearch();
$dataProvider = $searchModel->search(['PackageSearch' => Yii::$app->request->queryParams]); // $dataProvider = $searchModel->search(['PackageSearch' => Yii::$app->request->queryParams]);
//
return $this->render('index', [ // return $this->render('index', [
'searchModel' => $searchModel, // 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, // 'dataProvider' => $dataProvider,
]); // ]);
} //}
/** /**
* Redirects to a random mod. * Redirects to a random mod.
* @return mixed * @return mixed
*/ */
public function actionRandom() //public function actionRandom()
{ //{
$driver = Package::getDb()->driverName; // $driver = Package::getDb()->driverName;
if ($driver == 'mysql') { // if ($driver == 'mysql') {
$rand = new Expression('RAND()'); // $rand = new Expression('RAND()');
} elseif ($driver == 'pgsql') { // } elseif ($driver == 'pgsql') {
$rand = new Expression('RANDOM()'); // $rand = new Expression('RANDOM()');
} else { // } else {
return $this->redirect(['index']); // return $this->redirect(['index']);
} // }
$model = Package::find()->orderBy($rand)->one(); // $model = Package::find()->orderBy($rand)->one();
return $this->redirect(['view', 'name' => $model->name]); // return $this->redirect(['view', 'name' => $model->name]);
} //}
/** /**
* Displays a single Package model. * Displays a single Package model.
@ -176,28 +176,28 @@ class ModController extends Controller
* Renders a tag cloud of popular keywords * Renders a tag cloud of popular keywords
* @return mixed * @return mixed
*/ */
public function actionCloud() //public function actionCloud()
{ //{
$keywords = Yii::$app->cache->get('mod.cloud.keywords'); // $keywords = Yii::$app->cache->get('mod.cloud.keywords');
if (!$keywords) { // if (!$keywords) {
$keywords = []; // $keywords = [];
$packages = Package::find()->where(['is not', 'keywords', null])->all(); // $packages = Package::find()->where(['is not', 'keywords', null])->all();
foreach ($packages as $package) { // foreach ($packages as $package) {
foreach (explode(',', $package->keywords) as $keyword) { // foreach (explode(',', $package->keywords) as $keyword) {
if (!isset($keywords[$keyword])) { // if (!isset($keywords[$keyword])) {
$keywords[$keyword] = [ // $keywords[$keyword] = [
'text' => $keyword, // 'text' => $keyword,
'weight' => 0, // 'weight' => 0,
'link' => Url::to(['/mod/index', 'search' => $keyword]), // 'link' => Url::to(['/mod/index', 'search' => $keyword]),
]; // ];
} // }
$keywords[$keyword]['weight']++; // $keywords[$keyword]['weight']++;
} // }
} // }
Yii::$app->cache->set('mod.cloud.keywords', $keywords, 60 * 60); // Yii::$app->cache->set('mod.cloud.keywords', $keywords, 60 * 60);
} // }
return $this->render('cloud', ['keywords' => $keywords]); // return $this->render('cloud', ['keywords' => $keywords]);
} //}
/** /**
* Finds the Package model based on its primary key value. * Finds the Package model based on its primary key value.

View File

@ -12,6 +12,67 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<h2>Using Bower to Manage Mods and Dependencies</h2>
<p>If you are familiar with CLI, you can use Minetest Bower to install Minetest mods and dependency mods quickly
and easily under Linux, Windows, and Mac OS X. Minetest Bower needs primarily two software packages named
NodeJS and Git, which are easy to install.</p>
<div class="row">
<div class="col-lg-6">
<h3>Install Bower</h3>
<p>Bower is a command line utility. It requires <a href="http://nodejs.org/">NodeJS and npm</a> and
<a href="http://git-scm.com/">Git</a>.</p>
<pre class="prettyprint lang-bash">$ npm install -g bower</pre>
<p>Create a
<code>.bowerrc</code> file in your home directory or minetest folder with the following contents.
</p>
<pre class="prettyprint lang-js">{
"registry": "https://minetest-bower.herokuapp.com/",
"directory" : "mods"
}</pre>
<p><?= Html::a('Installation Guide &raquo;', ['/docs/install'], ['class' => 'btn btn-sm btn-default']); ?></p>
</div>
<div class="col-lg-6">
<h3>Install Mods</h3>
<p>Install mods and their dependencies with <code>bower install</code>.</p>
<pre class="prettyprint lang-bash">$ bower install &lt;mod&gt;</pre>
<h3>Search Mods</h3>
<p>Find mods that you can install with
<code>bower search</code> or <?= Html::a('browse the repository', ['/mod/index']) ?>.</p>
<pre class="prettyprint lang-bash">$ bower search &lt;keyword&gt;
# for example
$ bower search rainbow</pre>
<h3>Register Mods</h3>
<p>Register mods with
<code>bower register</code> or <?= Html::a('submit a mod online', ['/mod/create']) ?>.</p>
<pre class="prettyprint lang-bash">$ bower register &lt;my_mod_name&gt; &lt;git_endpoint&gt;
# for example
$ bower register rainbows https://github.com/user/rainbows.git</pre>
<p>Optionally, to add more information about your mod such as description, screenshots, authors and
licence, you can submit a JSON file along with your mod. To do so add a
<code>bower.json</code> file to to your mod's git repository. For the format to be
used, <?= Html::a('click here', ['/docs/bower-format']); ?>.
</p>
</div>
</div>
<h2>Other Documentation</h2>
<?= Nav::widget([ <?= Nav::widget([
'items' => [ 'items' => [
['label' => 'Installation', 'url' => ['/docs/install']], ['label' => 'Installation', 'url' => ['/docs/install']],

View File

@ -27,7 +27,7 @@ AppAsset::register($this);
<?php <?php
NavBar::begin([ NavBar::begin([
'brandLabel' => 'Minetest Bower', 'brandLabel' => 'Minetest Mods',
'brandUrl' => Yii::$app->homeUrl, 'brandUrl' => Yii::$app->homeUrl,
'options' => [ 'options' => [
'class' => 'navbar-default navbar-fixed-top', 'class' => 'navbar-default navbar-fixed-top',
@ -37,9 +37,9 @@ echo '<a class="hidden-xs" href="https://github.com/cornernote/minetest-bower"><
echo Nav::widget([ echo Nav::widget([
'options' => ['class' => 'navbar-nav'], 'options' => ['class' => 'navbar-nav'],
'items' => [ 'items' => [
['label' => 'Browse', 'url' => ['/mod/index'], 'active' => (Yii::$app->controller->id == 'mod' && !in_array(Yii::$app->controller->action->id, ['create', 'cloud']))], //['label' => 'Browse', 'url' => ['/mod/index'], 'active' => (Yii::$app->controller->id == 'mod' && !in_array(Yii::$app->controller->action->id, ['create', 'cloud']))],
['label' => 'Random', 'url' => ['/mod/random']], //['label' => 'Random', 'url' => ['/mod/random']],
['label' => 'Cloud', 'url' => ['/mod/cloud']], //['label' => 'Cloud', 'url' => ['/mod/cloud']],
['label' => 'Submit', 'url' => ['/mod/create']], ['label' => 'Submit', 'url' => ['/mod/create']],
['label' => 'Docs', 'url' => ['/docs/index'], 'active' => Yii::$app->controller->id == 'docs'], ['label' => 'Docs', 'url' => ['/docs/index'], 'active' => Yii::$app->controller->id == 'docs'],
], ],

View File

@ -10,7 +10,7 @@ use yii\widgets\DetailView;
/* @var $model app\models\Package */ /* @var $model app\models\Package */
$this->title = $model->name . ' bower.json'; $this->title = $model->name . ' bower.json';
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]];
$this->params['breadcrumbs'][] = 'bower.json'; $this->params['breadcrumbs'][] = 'bower.json';
?> ?>

View File

@ -8,7 +8,7 @@ use yii\helpers\Html;
$this->title = 'Keyword Cloud'; $this->title = 'Keyword Cloud';
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="mod-cloud"> <div class="mod-cloud">

View File

@ -7,7 +7,7 @@ use yii\helpers\Html;
/* @var $model app\models\Package */ /* @var $model app\models\Package */
$this->title = 'Submit a Mod'; $this->title = 'Submit a Mod';
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="mod-create"> <div class="mod-create">

View File

@ -4,8 +4,6 @@ use yii\helpers\Html;
use yii\widgets\ListView; use yii\widgets\ListView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel app\models\search\PackageSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Mods'; $this->title = 'Mods';
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
@ -13,9 +11,10 @@ $this->params['breadcrumbs'][] = $this->title;
<div class="mod-index"> <div class="mod-index">
<h1><?= Html::encode($this->title) ?></h1> <h1><?= Html::encode($this->title) ?></h1>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<?= ListView::widget([ <?php
echo $this->render('_search', ['model' => $searchModel]);
echo ListView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'], 'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) { 'itemView' => function ($model, $key, $index, $widget) {
@ -27,6 +26,7 @@ $this->params['breadcrumbs'][] = $this->title;
'nextPageLabel' => 'Next <i class="glyphicon glyphicon-chevron-right"></i>', 'nextPageLabel' => 'Next <i class="glyphicon glyphicon-chevron-right"></i>',
'prevPageLabel' => '<i class="glyphicon glyphicon-chevron-left"></i> Prev', 'prevPageLabel' => '<i class="glyphicon glyphicon-chevron-left"></i> Prev',
], ],
]) ?> ]);
?>
</div> </div>

View File

@ -10,7 +10,7 @@ use yii\widgets\DetailView;
/* @var $model app\models\Package */ /* @var $model app\models\Package */
$this->title = $model->name . ' README.md'; $this->title = $model->name . ' README.md';
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]];
$this->params['breadcrumbs'][] = 'README.md'; $this->params['breadcrumbs'][] = 'README.md';
?> ?>

View File

@ -10,7 +10,7 @@ use yii\widgets\DetailView;
/* @var $model app\models\Package */ /* @var $model app\models\Package */
$this->title = $model->name . ' Screenshots'; $this->title = $model->name . ' Screenshots';
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'name' => $model->name]];
$this->params['breadcrumbs'][] = 'Screenshots'; $this->params['breadcrumbs'][] = 'Screenshots';
?> ?>

View File

@ -7,7 +7,7 @@ use yii\helpers\Html;
/* @var $model app\models\Package */ /* @var $model app\models\Package */
$this->title = $model->name; $this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']]; //$this->params['breadcrumbs'][] = ['label' => 'Mods', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="mod-view"> <div class="mod-view">

View File

@ -11,7 +11,7 @@ use yii\db\Expression;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ListView; use yii\widgets\ListView;
$this->title = 'Minetest Bower: Mods, Texture Packs and Subgames'; $this->title = 'Minetest Mods: The Minetest mod repository.';
$this->params['jumbotron'] = '/site/_index-jumbotron'; $this->params['jumbotron'] = '/site/_index-jumbotron';
?> ?>
@ -19,102 +19,57 @@ $this->params['jumbotron'] = '/site/_index-jumbotron';
<div class="body-content"> <div class="body-content">
<h2>About Minetest Bower</h2> <h2>About Minetest Mods</h2>
<p>Minetest Bower is a Minetest mod repository. The repository is unmoderated. Anybody may submit mods using one of several different approaches. Different versions by different people of similar mods are permitted but each version must have different names.</p> <p>Minetest Mods is a Minetest mod repository. The repository is unmoderated, anybody may <?=Html::a('submit a mod',['mod/create'])?>.
Different versions by different people of similar mods are permitted but
each version must have different names.</p>
<p>If you'd like to run a Minetest Bower mirror, this is encouraged and simple to set up. Simply copy the <?= Html::a('this JSON file', ['/package/index']) ?> to your website and update it periodically.</p> <p>If you'd like to run a Minetest Mods mirror, this is encouraged and simple to set up. Simply copy
the <?= Html::a('this JSON file', ['package/index']) ?> to your website and update it periodically.</p>
<h2>Search Mods</h2>
<?php echo $this->render('/mod/_search', ['model' => new PackageSearch()]); ?>
<h2>Browse Mods</h2>
<div class="row">
<?php <?php
$searchModel = new PackageSearch(); //echo '<h2>Search Mods</h2>';
$query = Package::find(); //echo $this->render('/mod/_search', ['model' => new PackageSearch()]);
$driver = Package::getDb()->driverName;
if ($driver == 'mysql') {
$rand = new Expression('RAND()');
} elseif ($driver == 'pgsql') {
$rand = new Expression('RANDOM()');
}
if (isset($rand)) {
$query->orderBy($rand);
}
$query->limit(4);
$pagination = new Pagination(['totalCount' => 4]);
$pagination->pageSize = 4;
$pagination->pageSizeLimit = [4];
echo ListView::widget([
'layout' => '{items}',
'dataProvider' => new ArrayDataProvider(['allModels' => $query->all()]),
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return $this->render('_mod-view', ['model' => $model]);
},
'pager' => $pagination,
]);
?> ?>
</div>
<h2>Using Bower to Manage Mods and Dependencies</h2> <?php
echo '<h2>Mod List</h2>';
<p>If you are familiar with CLI, you can use Minetest Bower to install Minetest mods and dependency mods quickly and easily under Linux, Windows, and Mac OS X. Minetest Bower needs primarily two software packages named NodeJS and Git, which are easy to install.</p> $items = [];
foreach (\app\models\Package::find()->orderBy(['name' => SORT_ASC])->all() as $package) {
<div class="row"> $items[] = Html::a($package->name, ['mod/view', 'name' => $package->name]);
<div class="col-lg-6"> }
echo Html::ul($items, [
<h3>Install Bower</h3> 'encode' => false,
'class' => 'list-inline',
<p>Bower is a command line utility. It requires <a href="http://nodejs.org/">NodeJS and npm</a> and ]);
<a href="http://git-scm.com/">Git</a>.</p> //echo '<div class="row">';
<pre class="prettyprint lang-bash">$ npm install -g bower</pre> //$searchModel = new PackageSearch();
//$query = Package::find();
<p>Create a //$driver = Package::getDb()->driverName;
<code>.bowerrc</code> file in your home directory or minetest folder with the following contents. //if ($driver == 'mysql') {
</p> // $rand = new Expression('RAND()');
<pre class="prettyprint lang-js">{ //} elseif ($driver == 'pgsql') {
"registry": "https://minetest-bower.herokuapp.com/", // $rand = new Expression('RANDOM()');
"directory" : "mods" //}
}</pre> //if (isset($rand)) {
<p><?= Html::a('Installation Guide &raquo;', ['/docs/install'], ['class' => 'btn btn-sm btn-default']); ?></p> // $query->orderBy($rand);
//}
</div> //$query->limit(4);
<div class="col-lg-6"> //$pagination = new Pagination(['totalCount' => 4]);
//$pagination->pageSize = 4;
<h3>Install Mods</h3> //$pagination->pageSizeLimit = [4];
//echo ListView::widget([
<p>Install mods and their dependencies with <code>bower install</code>.</p> // 'layout' => '{items}',
<pre class="prettyprint lang-bash">$ bower install &lt;mod&gt;</pre> // 'dataProvider' => new ArrayDataProvider(['allModels' => $query->all()]),
// 'itemOptions' => ['class' => 'item'],
<h3>Search Mods</h3> // 'itemView' => function ($model, $key, $index, $widget) {
// return $this->render('_mod-view', ['model' => $model]);
<p>Find mods that you can install with // },
<code>bower search</code> or <?= Html::a('browse the repository', ['/mod/index']) ?>.</p> // 'pager' => $pagination,
<pre class="prettyprint lang-bash">$ bower search &lt;keyword&gt; //]);
//echo '</div>';
# for example ?>
$ bower search rainbow</pre>
<h3>Register Mods</h3>
<p>Register mods with
<code>bower register</code> or <?= Html::a('submit a mod online', ['/mod/create']) ?>.</p>
<pre class="prettyprint lang-bash">$ bower register &lt;my_mod_name&gt; &lt;git_endpoint&gt;
# for example
$ bower register rainbows https://github.com/user/rainbows.git</pre>
<p>Optionally, to add more information about your mod such as description, screenshots, authors and licence, you can submit a JSON file along with your mod. To do so add a
<code>bower.json</code> file to to your mod's git repository. For the format to be used, <?= Html::a('click here', ['/docs/bower-format']); ?>.
</p>
</div>
</div>
</div> </div>
</div> </div>