コード例 #1
0
ファイル: Module.php プロジェクト: simplator/articles
 public function init()
 {
     if (\Yii::$app instanceof \yii\console\Application) {
         $this->controllerNamespace = 'simplator\\articles\\commands';
     }
     parent::init();
     if (!count($this->_plugins)) {
         $this->setPlugins([]);
     }
     if (!strlen($this->title)) {
         $this->title = Module::t('articles', 'Articles');
     }
     //articlesAsset::register($view)->addLanguage($this->language, 'fileinput_locale_');
     $this->breadcrumbs = [];
     // custom initialization code goes here
 }
コード例 #2
0
 /**
  * 
  * @param type $manager
  * @param type $request
  * @return boolean
  */
 public function parseRequest($manager, $request)
 {
     $path = $request->getPathInfo();
     $roots = Module::getRoots();
     foreach ($roots as $n => $v) {
         if (substr($path, 0, strlen($n)) == $n) {
             goto root_found;
         }
     }
     return false;
     root_found:
     $q = explode('?', $request->url, 2);
     if (isset($q[1])) {
         parse_str($q[1], $params);
     } else {
         $params = [];
     }
     $action = 'view';
     if (isset($params['action'])) {
         $action = $params['action'];
         unset($params['action']);
     }
     if (!preg_match($this->preg, $path, $matches)) {
         return false;
     }
     if (substr($path, -1) == '/') {
         $path = substr($path, 0, strlen($path) - 1);
     }
     $result = \Yii::$app->db->createCommand("SELECT id, path FROM {{%articles_category}} WHERE path=\"{$path}\" OR  path=\"{$path}/\"")->queryOne();
     if ($result) {
         $params['id'] = $result['id'];
         return [$this->moduleId . '/front/category', $params];
     }
     $result = \Yii::$app->db->createCommand("SELECT id, path FROM {{%articles_article}} WHERE path=\"{$path}\"")->queryOne();
     if ($result) {
         $params['id'] = $result['id'];
         return [$this->moduleId . '/front/article', $params];
     }
     return false;
 }
コード例 #3
0
ファイル: create.php プロジェクト: simplator/articles
<?php

use yii\helpers\Html;
use simplator\articles\Module;
/* @var $this yii\web\View */
/* @var $model simplator\articles\models\Category */
$this->title = Module::t('articles', 'Create category');
$this->params['breadcrumbs'][] = ['label' => Module::t('articles', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-create">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
echo $this->render('_form', ['model' => $model]);
?>

</div>
コード例 #4
0
ファイル: view.php プロジェクト: simplator/articles
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-view">

    <h1><?php 
echo $this->title;
?>
</h1>
	<?php 
echo Html::a(Module::t('articles', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-success']);
?>
    
	<h1>Categories</h1>
	<?php 
echo Html::a(Module::t('articles', 'Create category'), ['category/create', 'p' => $model->id], ['class' => 'btn btn-success']);
?>
    <?php 
echo SortableListView::widget(['dataProvider' => $categories, 'itemView' => '_view', 'clientOptions' => ['placeholder' => "ui-state-highlight"]]);
?>
   
    <h1>Articles</h1>
	<?php 
echo Html::a(Module::t('articles', 'Create article'), ['article/create', 'p' => $model->id], ['class' => 'btn btn-success']);
?>
    <?php 
echo SortableListView::widget(['dataProvider' => $articles, 'itemView' => '../article/_view', 'clientOptions' => ['placeholder' => "ui-state-highlight"]]);
?>
   

</div>
コード例 #5
0
ファイル: update.php プロジェクト: simplator/articles
<?php

use yii\helpers\Html;
use simplator\articles\Module;
/* @var $this yii\web\View */
/* @var $model simplator\articles\models\Category */
$this->title = Module::t('articles', 'Update category') . ': ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => Module::t('articles', 'Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = Module::t('articles', 'Update');
?>
<div class="category-update">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
echo $this->render('_form', ['model' => $model]);
?>

</div>
コード例 #6
0
 /**
  * Updates an existing Category model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Module::checkPathes();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
コード例 #7
0
ファイル: update.php プロジェクト: simplator/articles
        $url = Url::to(['update', 'id' => $article->id]);
        $msg = Module::t('articles', 'Загружена текущая опубликованная версия, но есть более поздняя версия');
        $this->registerJs("var n = noty({type: 'information', text: '{$msg}', timeout: 15000});", 5);
    } else {
        if ($rev->id == $article->lastVersion->id) {
            $url = Url::to(['update', 'id' => $article->id, 'rev' => 'current']);
            $msg = Module::t('articles', 'Загружена последняя версия. Она имеет отличия от текущей опубликованной');
            $this->registerJs("var n = noty({type: 'information', text: '{$msg}', timeout: 15000});", 5);
        } else {
            if ($rev->role == Revision::ROLE_ARCHIVE) {
                $msg = Module::t('articles', 'Загружена архивная версия');
                $this->registerJs("var n = noty({type: 'information', text: '{$msg}', timeout: 15000});", 5);
            }
        }
    }
}
?>
<div class="article-update">

    <h1><?php 
echo Module::t('articles', 'Update article');
?>
</h1>

    <?php 
echo $this->render('_form', ['rev' => $rev]);
?>

	
</div>
コード例 #8
0
 public function actionIndex()
 {
     Module::checkPathes();
     return $this->render('index');
 }
コード例 #9
0
ファイル: Category.php プロジェクト: simplator/articles
 /**
  * Generate full path for category
  * @param string $attribute
  * @param array $params
  */
 public function genPath($attribute = 'path', $params = [])
 {
     $this->path = Module::createPath($this);
 }
コード例 #10
0
 public function actionRevrestore($id, $rev)
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $rev = Revision::findOne($rev);
     if (!$rev || $rev->articleid != intval($id)) {
         throw new NotFoundHttpException(\Yii::t('yii', 'Page not found.'));
     }
     if (!\Yii::$app->user->can('articles.article.update', ['model' => $rev->article])) {
         $this->accessDenied();
     }
     $this->checkLock($rev->article);
     if ($rev->role != Revision::ROLE_DELETED) {
         return ['error' => Module::t('article', 'Version not deleted')];
     }
     $rev->role = Revision::ROLE_SAVE;
     if ($rev->delete()) {
         return ['success' => Module::t('articles', 'Version restored')];
     } else {
         return ['error' => 'Error restore'];
     }
 }
コード例 #11
0
ファイル: revisions.php プロジェクト: simplator/articles
echo GridView::widget(['dataProvider' => $revisions, 'formatter' => ['class' => 'yii\\i18n\\Formatter', 'nullDisplay' => ''], 'columns' => ['id', ['class' => LinkColumn::className(), 'attribute' => 'roleText', 'url' => ['update'], 'params' => ['id' => 'articleid', 'rev' => 'id']], 'updated_at:datetime', ['attribute' => 'published_at', 'format' => 'datetime'], ['class' => LinkColumn::className(), 'attribute' => 'author.username', 'url' => ['/user/profile/show'], 'params' => ['id' => 'authorid']], ['label' => Module::t('articles', 'Diff'), 'format' => 'raw', 'value' => function ($data) {
    $r = Html::tag('b', intval($data->diff['c']), ['style' => 'color: black']) . ' ';
    $r .= Html::tag('b', '=' . intval($data->diff['=']), ['style' => 'color: black']) . ' ';
    $r .= Html::tag('b', '~' . intval($data->diff['~']), ['style' => 'color: blue']) . ' ';
    $r .= Html::tag('b', '+' . intval($data->diff['+']), ['style' => 'color: green']) . ' ';
    $r .= Html::tag('b', '-' . intval($data->diff['-']), ['style' => 'color: red']);
    $tt = Module::t('articles', 'Total words') . ': ' . intval($data->diff['c']) . "\n";
    $tt .= Module::t('articles', 'Unchanged') . ': ' . intval($data->diff['=']) . "\n";
    $tt .= Module::t('articles', 'Replaced') . ': ' . intval($data->diff['~']) . "\n";
    $tt .= Module::t('articles', 'Added') . ': ' . intval($data->diff['+']) . "\n";
    $tt .= Module::t('articles', 'Removed') . ': ' . intval($data->diff['-']);
    return Html::tag('span', $r, ['class' => 'diff', 'title' => $tt]);
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {diff} {update} {delete}', 'buttons' => ['view' => function ($url, $model) {
    return \yii\helpers\Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, ['title' => Module::t('articles', 'Preview'), 'target' => '_blank']);
}, 'diff' => function ($url, $model) {
    return \yii\helpers\Html::a('<span class="glyphicon glyphicon-duplicate"></span>', $url, ['title' => Module::t('articles', 'Compare'), 'target' => '_blank']);
}, 'delete' => function ($url, $model) {
    return \yii\helpers\Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => Yii::t('yii', 'Delete'), 'data-revdel' => '0']);
}], 'urlCreator' => function ($action, $model, $key, $index) {
    switch ($action) {
        case 'update':
            return Url::to(['update', 'id' => $model->articleid, 'rev' => $model->id]);
        case 'delete':
            return Url::to(['revdel', 'id' => $model->articleid, 'rev' => $model->id]);
        case 'view':
        default:
            return Url::to(['preview', 'id' => $model->articleid, 'rev' => $model->id]);
    }
}]]]);
?>
コード例 #12
0
ファイル: _form.php プロジェクト: simplator/articles
echo $form->field($model, 'parentid')->dropDownList(ArrayHelper::merge([0 => Module::t('articles', '- New root -')], $model->allparents));
?>

    <?php 
echo $form->field($model, 'title')->textInput(['maxlength' => 256]);
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => 128]);
?>

    <?php 
echo $form->field($model, 'thumbnailid')->textInput();
?>

	<?php 
echo $form->errorSummary($model);
?>
	
    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Module::t('articles', 'Create') : Module::t('articles', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
コード例 #13
0
ファイル: index.php プロジェクト: simplator/articles
<?php

use yii\helpers\Html;
use simplator\articles\Module;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Module::t('articles', 'Categories');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">

    <p>
        <?php 
echo Html::a(Module::t('articles', 'Create root'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo yii\widgets\ListView::widget(['dataProvider' => $categories, 'itemView' => '_rootview']);
?>

</div>
コード例 #14
0
ファイル: Revision.php プロジェクト: simplator/articles
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['id' => Module::t('articles', 'ID'), 'articleid' => Module::t('articles', 'Articleid'), 'title' => Module::t('articles', 'Title'), 'snippet' => Module::t('articles', 'Snippet'), 'status' => Module::t('articles', 'Status'), 'content' => Module::t('articles', 'Content'), 'diff' => Module::t('articles', 'Diff'), 'tags' => Module::t('articles', 'Tags'), 'thumbnailid' => Module::t('articles', 'Thumbnail'), 'authorid' => Module::t('articles', 'Authorid'), 'role' => Module::t('articles', 'Role'), 'roleText' => Module::t('articles', 'Role'), 'updated_at' => Module::t('articles', 'Updated at'), 'published_at' => Module::t('articles', 'Published at'), 'revisions' => Module::t('articles', 'Revisions'), 'options' => Module::t('articles', 'Options')];
 }