show all mods on homepage

master
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 = [
'id' => 'minetest-bower',
'name' => 'Minetest Bower',
'name' => 'Minetest Mods',
'basePath' => dirname(__DIR__),
'vendorPath' => '@app/../vendor',
'runtimePath' => '@app/../runtime',

View File

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

View File

@ -27,7 +27,7 @@ AppAsset::register($this);
<?php
NavBar::begin([
'brandLabel' => 'Minetest Bower',
'brandLabel' => 'Minetest Mods',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'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([
'options' => ['class' => 'navbar-nav'],
'items' => [
['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' => 'Cloud', 'url' => ['/mod/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' => 'Cloud', 'url' => ['/mod/cloud']],
['label' => 'Submit', 'url' => ['/mod/create']],
['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 */
$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'][] = 'bower.json';
?>

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ use yii\widgets\DetailView;
/* @var $model app\models\Package */
$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'][] = 'README.md';
?>

View File

@ -10,7 +10,7 @@ use yii\widgets\DetailView;
/* @var $model app\models\Package */
$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'][] = 'Screenshots';
?>

View File

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

View File

@ -11,7 +11,7 @@ use yii\db\Expression;
use yii\helpers\Html;
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';
?>
@ -19,102 +19,57 @@ $this->params['jumbotron'] = '/site/_index-jumbotron';
<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 '<h2>Search Mods</h2>';
//echo $this->render('/mod/_search', ['model' => new PackageSearch()]);
?>
<?php echo $this->render('/mod/_search', ['model' => new PackageSearch()]); ?>
<h2>Browse Mods</h2>
<div class="row">
<?php
$searchModel = new PackageSearch();
$query = Package::find();
$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>
<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>
<?php
echo '<h2>Mod List</h2>';
$items = [];
foreach (\app\models\Package::find()->orderBy(['name' => SORT_ASC])->all() as $package) {
$items[] = Html::a($package->name, ['mod/view', 'name' => $package->name]);
}
echo Html::ul($items, [
'encode' => false,
'class' => 'list-inline',
]);
//echo '<div class="row">';
//$searchModel = new PackageSearch();
//$query = Package::find();
//$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,
//]);
//echo '</div>';
?>
</div>
</div>