Your IP : 216.73.216.79


Current Path : /var/www/html/brspace/frontend/controllers/
Upload File :
Current File : /var/www/html/brspace/frontend/controllers/ArticleEditorController.php

<?php

namespace frontend\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\web\Controller;
use kartik\mpdf\Pdf;
use backend\modules\contentArticle\models\ContentArticle;
use backend\modules\contentArticle\models\ContentArticleTranslation;
use yii\web\UploadedFile;


/**
 * Site controller
 */
class ArticleEditorController extends Controller {

    /**
     * {@inheritDoc}
     * @see \yii\web\Controller::beforeAction()
     */
    public function beforeAction($action) {
        //         $this->layout = 'main_default';
        // TODO Auto-generated method stub
        return parent::beforeAction($action);
    }

    /**
     * @inheritdoc
     */

    public function behaviors() {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'only' => ['logout', 'signup', 'error', 'stub'],
                'rules' => [
                    [
                        'actions' => ['signup', 'error', 'stub'],
                        'allow' => true,
                        'roles' => ['?'],
                    ],
                    [
                        'actions' => ['logout', 'error'],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::className(),
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    public function actions() {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],
        ];
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionSave($article_translation_id) {

        $arttr = ContentArticleTranslation::findOne($article_translation_id);
        $arttr->article_translation_content = $_POST['content'];

        if (!$arttr->save()) {
            return $this->asJson([
                'success' => false,
                'error' => json_encode($arttr->errors)
            ]);
        }

        return $this->asJson([
            'success' => true
        ]);
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionSavePublication($article_translation_id) {

        $arttr = ContentArticleTranslation::findOne($article_translation_id);
        $arttr->article_translation_content = $_POST['content'];

        if (!$arttr->save()) {
            return $this->asJson([
                'success' => false,
                'error' => json_encode($arttr->errors)
            ]);
        }

        return $this->asJson([
            'success' => true
        ]);
    }

    /**
     * Displays homepage.
     *
     * @return mixed
     */
    public function actionSaveImages() {

        $instance = UploadedFile::getInstanceByName('image');

        $url_upload = '/uploads/article-editor-' . time() . '.' . $instance->extension;
        $file = $_SERVER['DOCUMENT_ROOT'] . $url_upload;

        if ($instance->saveAs($file, true)) {
            list($width, $height) = getimagesize($file);
            
            return $this->asJson([
                'success' => true,
                'url' => $url_upload,
                'size' => [
                    'w' => $width,
                    'h' => $height,
                ]
            ]);
        }
    
        return $this->asJson([
            'success' => false,
            'error' => 'error saving image'
        ]);
    }

}