获取原图路径
@return string
@throws \yii\base\Exception
769002
public function getOriginalImage()
    {
        if ($this->_originalImage == null) {
            $this->_originalImage = Yii::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $this->getUser()->id . '_avatar.jpg';
        }
        return $this->_originalImage;
    }
1049456
public function init() {
        //close csrf
        Yii::$app->request->enableCsrfValidation = false;
        //默认设置

       // $this->php_path =  dirname(__FILE__) . '/';
        $this->php_path =  $_SERVER['DOCUMENT_ROOT'] . '/';
        $this->php_url =  '/';
//根目录路径，可以指定绝对路径，比如 /var/www/attached/
        $this->root_path = $this->php_path . 'upload/';
//根目录URL，可以指定绝对路径，比如 http://www.yoursite.com/attached/
        $this->root_url = $this->php_url . 'upload/';
//图片扩展名
//            $ext_arr = ['gif', 'jpg', 'jpeg', 'png', 'bmp'],
//文件保存目录路径
        $this->save_path = $this->php_path . 'upload/';
//文件保存目录URL
        $this->save_url = $this->php_url . 'upload/';
//定义允许上传的文件扩展名
//            $ext_arr = array(
//                'image' => array('gif', 'jpg', 'jpeg', 'png', 'bmp'),
//                'flash' => array('swf', 'flv'),
//                'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'),
//                'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'),
//            ),
//最大文件大小
        $this->max_size = 1000000;
        $this->save_path = realpath($this->save_path) . '/';

        //load config file

        parent::init();
    }
527602
public function formatter()
	{
		if (!isset($this->formatter))
			$this->formatter = \Yii::$app->getFormatter();

		return $this->formatter;
	}
337851
protected function renderWidget()
    {
        $contents = [];

        // get formatted date value
        if ($this->hasModel()) {
            $value = Html::getAttributeValue($this->model, $this->attribute);
        } else {
            $value = $this->value;
        }
        if ($value !== null && $value !== '') {
            // format value according to dateFormat
            try {
                $value = Yii::$app->formatter->asDate($value, $this->dateFormat);
            } catch(InvalidParamException $e) {
                // ignore exception and keep original value if it is not a valid date
            }
        }
        $options = $this->options;
        $options['value'] = $value;

        if ($this->inline === false) {
            // render a text input
            if ($this->hasModel()) {
                $contents[] = Html::activeTextInput($this->model, $this->attribute, $options);
            } else {
                $contents[] = Html::textInput($this->name, $value, $options);
            }
        } else {
            // render an inline date picker with hidden input
            if ($this->hasModel()) {
                $contents[] = Html::activeHiddenInput($this->model, $this->attribute, $options);
            } else {
                $contents[] = Html::hiddenInput($this->name, $value, $options);
            }
            $this->clientOptions['defaultDate'] = $value;
            $this->clientOptions['altField'] = '#' . $this->options['id'];
            $contents[] = Html::tag('div', null, $this->containerOptions);
        }

        return implode("\n", $contents);
    }
507262
public function getVerifyCode()
    {
        $session = Yii::$app->getSession();
        $session->open();
        $name = $this->getSessionKey();
        return $session[$name];
    }
932498
public function actionAdopt()
    {
        $answerId = Yii::$app->request->post('answerId');
        $answer = $this->findModel($answerId);
        if (Yii::$app->user->id !== $answer->question->user_id) {
            Yii::$app->session->setFlash('danger', Yii::t('question', 'You can not take your own answer.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        }

        $transaction = Yii::$app->db->beginTransaction();
        try {
            $answer->adopted_at = time();
            $answer->save();
            $answer->question->status = Question::STATUS_END;
            $answer->question->save(false);

            if (isset(Yii::$app->user->identity->extend->adoptions)) {
                Yii::$app->user->identity->extend->updateCounters(['adoptions' => 1]);
            }
            if (function_exists('credit')) {
                /*悬赏处理*/
                if ($answer->question->price > 0) {
                    credit($answer->user_id, 'answer_adopted', $answer->question->price, $answer->question->id, $answer->question->title);
                }
            }

            $transaction->commit();
            Yii::$app->session->setFlash('success', Yii::t('question', 'Answer to adopt success.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        } catch (\Exception $e) {
            Yii::$app->session->setFlash('danger', Yii::t('question', 'Adopte failed. Please try again later.'));
            return $this->redirect(['/question/question/view', 'id' => $answer->question_id]);
        }
    }
1206189
public static function convertExceptionToString($exception)
    {
        if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
            $message = "{$exception->getName()}: {$exception->getMessage()}";
        } elseif (YII_DEBUG) {
            if ($exception instanceof Exception) {
                $message = "Exception ({$exception->getName()})";
            } elseif ($exception instanceof ErrorException) {
                $message = "{$exception->getName()}";
            } else {
                $message = 'Exception';
            }
            $message .= " '" . get_class($exception) . "' with message '{$exception->getMessage()}' \n\nin "
                . $exception->getFile() . ':' . $exception->getLine() . "\n\n"
                . "Stack trace:\n" . $exception->getTraceAsString();
        } else {
            $message = 'Error: ' . $exception->getMessage();
        }
        return $message;
    }
533206
public function callback() {
        $xml = app('request')->input();
        if (empty($xml)) {
            throw new Exception(
                __('xml error')
            );
        }
        /**
         * 禁止引用外部xml实体
         */
        $disableLibxmlEntityLoader = libxml_disable_entity_loader(true);
        $args = Xml::specialDecode($xml);
        libxml_disable_entity_loader($disableLibxmlEntityLoader);
        Factory::log()
            ->info('WECHAT PAY CALLBACK: '.app('request')->input());
        if (!is_array($args)) {
            throw new Exception(
                __('xml error')
            );
        }
        if ($args['return_code'] != 'SUCCESS') {
            throw new Exception($args['return_msg']);
        }
        if (!$this->verify($args)) {
            throw new Exception(
                __('verify sign error')
            );
        }
        return $args;
    }
1250522
public function actionSave()
    {
        $url_id = \Yii::$app->request->post('url_id');
        $menu_id = \Yii::$app->request->post('menu_id');
        $name = \Yii::$app->request->post('name');
        $alias = \Yii::$app->request->post('alias');
        $route = \Yii::$app->request->post('route');
        $method = \Yii::$app->request->post('method');
        $host = \Yii::$app->request->post('host');
        $enable_rule = \Yii::$app->request->post('enable_rule');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        if (!$alias) {
            // 自动生成别名
            if (strpos($route, '/') === 0) {
                $tempRoute = substr($route, 1, strlen($route));
            } else {
                $tempRoute = $route;
            }
            $alias = join('.', StringHelper::explode($tempRoute, '/', true, true));
        }
        $methodStr = '';
        if (is_array($method)) {
            $method = array_filter($method, function ($value) {
                return in_array($value, ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS']);
            });
            $methodStr = join(',', $method);
        }
        $saveData = [
            'name' => $name,
            'alias' => $alias,
            'route' => $route,
            'method' => $methodStr,
            'host' => $host,
            'enable_rule' => $enable_rule,
            'note' => $note,
            'status' => $status,
        ];
        $obj = null;
        if ($url_id) {
            $obj = DpAdminMenuUrl::find()
                ->findByUrlId($url_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            if ($alias) {
                $obj = DpAdminMenuUrl::find()
                    ->findByAlias($alias)
                    ->one();
            }
            if (!$obj) {
                $obj = new DpAdminMenuUrl();
            }
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        if ($menu_id) {
            if (!DpAdminMenu::getByMenuId($menu_id)) {
                return $this->renderError('菜单不存在');
            } else {
                $linkObj = new DpAdminMenuUrlRelation();
                $linkObj->setAttributes([
                    'menu_id' => $menu_id,
                    'url_id' => $obj->url_id,
                    'status' => DpAdminMenuUrlRelation::STATUS_ACTIVE,
                ]);
                if (!$linkObj->save()) {
                    foreach ($obj->getErrors() as $error) {
                        foreach ($error as $message) {
                            return [
                                'success' => false,
                                'msg' => $message,
                            ];
                        }
                    }
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
773556
public function upBase64()
    {
        $base64Data = Yii::$app->request->post($this->fileField);
        $img = base64_decode($base64Data);
        $this->oriName = $this->config['oriName'];
        $this->fileSize = strlen($img);
        $this->fileType = $this->getExtension();
        $this->fullName = $this->getFullName();
        $this->filePath = $this->getFilePath();
        $this->fileName = $this->getFileName();
        $dirName = dirname($this->filePath);

        if (!is_dir($dirName)) {//递归创建保存目录
            FileHelper::createDirectory($dirName, $this->dirMode, true);
        }
        //检查文件大小是否超出限制
        if (!$this->checkSize()) {
            $this->stateInfo = Yii::t('attachment', 'The file size exceeds the site limit.');
            return false;
        }

        //移动文件
        if (!(file_put_contents($this->filePath, $img) && file_exists($this->filePath))) { //移动失败
            $this->stateInfo = Yii::t('attachment', 'An error occurred while saving the file.');
            return false;
        } else { //移动成功
            $this->saveModel();
            $this->stateInfo = 'SUCCESS';
            return true;
        }
    }
426051
public function getCharset()
    {
        return (isset(Yii::$app->charset) ? Yii::$app->charset : null) ?: mb_internal_encoding();
    }
1079356
public function getToken(): string
    {
        if (\Yii::$app->session->get('auth_token')) { // берем из куки
            $token = $this->__userAccessTokenClass::findOne(['access_token' => \Yii::$app->session->get('auth_token')]);
            return $token->access_token;
        }
        return '';
    }
1326516
public function actionSave()
    {
        $group_id = \Yii::$app->request->post('group_id');
        $menu_ids = \Yii::$app->request->post('menu_ids');
        $name = \Yii::$app->request->post('name');
        $is_system = \Yii::$app->request->post('is_system');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        $saveData = [
            'name' => $name,
            'is_system' => $is_system,
            'note' => $note,
            'status' => $status,
        ];
        if ($group_id) {
            $obj = DpAdminGroup::find()
                ->findByGroupId($group_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminGroup();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        // 用户组关联的菜单权限更新
        DpAdminGroupMenuRelation::deleteByGroupId($obj->group_id);
        if ($menu_ids) {
            $menuIdArr = array_filter(StringHelper::explode($menu_ids, ',', true, true), function ($menuId) {
                return DpAdminMenu::getByMenuId($menuId);
            });
            if ($menuIdArr) {
                foreach ($menuIdArr as $menuId) {
                    $linkObj = new DpAdminGroupMenuRelation();
                    $linkObj->setAttributes([
                        'group_id' => $obj->group_id,
                        'menu_id' => $menuId,
                    ]);
                    $linkObj->save();
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
957717
public function actionView()
    {
        $model = $this->model;
        $id = $model->name;
        $model = $this->findModel($id);
        $authManager = Yii::$app->getAuthManager();
        $avaliable = $assigned = [
            'Roles' => [],
            'Permission' => [],
            'Routes' => [],
        ];
        $children = array_keys($authManager->getChildren($id));
        $children[] = $id;
        foreach ($authManager->getRoles() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }
            $avaliable['Roles'][$name] = $name . ' — ' . $role->description;
        }
        foreach ($authManager->getPermissions() as $name => $role) {
            if (in_array($name, $children)) {
                continue;
            }

            if (isset($name[0])) {
                $avaliable[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $role->description;
            }
        }
        foreach ($authManager->getChildren($id) as $name => $child) {
            if ($child->type == Item::TYPE_ROLE) {
                $assigned['Roles'][$name] = $name . ' — ' . $child->description;
            } else {
                if (isset($name[0])) {
                    $assigned[$name[0] === '/' ? 'Routes' : 'Permission'][$name] = $name . ' — ' . $child->description;
                } else {
                    $assigned['Permission'][$name] = $name . ' — ' . $child->description;
                }
            }
        }
        $avaliable = array_filter($avaliable);
        $assigned = array_filter($assigned);
        return $this->render('view', ['model' => $model, 'avaliable' => $avaliable, 'assigned' => $assigned]);
    }
936295
public function getCommandLine()
    {
        if (\Yii::$app === null || !$this->getIsConsoleRequest()) {
            return null;
        }

        $params = [];
        if (isset($_SERVER['argv'])) {
            $params = $_SERVER['argv'];
        }
        return implode(' ', $params);
    }
784371
public function actionIndex()
    {
        $request = \Yii::$app->request;
        if ($request->getIsOptions()) {
            return $this->ResponseOptions($this->verbs()['index']);
        }
        try{
            return Menu::getPageMenus(Yii::$app->request->queryParams);

        }catch(Exception $e)
        {
            throw new Exception($e);
        }



    }
669089
public function actionRss()
    {
        $xml['channel']['title'] = yii::$app->feehi->website_title;
        $xml['channel']['description'] = yii::$app->feehi->seo_description;
        $xml['channel']['lin'] = yii::$app->getUrlManager()->getHostInfo();
        $xml['channel']['generator'] = yii::$app->getUrlManager()->getHostInfo();
        $models = Article::find()->limit(10)->where(['status'=>Article::ARTICLE_PUBLISHED, 'type'=>Article::ARTICLE])->orderBy('id desc')->all();
        foreach ($models as $model){
            $xml['channel']['item'][] = [
                'title' => $model->title,
                'link' => Url::to(['article/view', 'id'=>$model->id]),
                'pubData' => date('Y-m-d H:i:s', $model->created_at),
                'source' => yii::$app->feehi->website_title,
                'author' => $model->author_name,
                'description' => $model->summary,
            ];
        }
        yii::configure(yii::$app->getResponse(), [
            'formatters' => [
                Response::FORMAT_XML => [
                    'class' => XmlResponseFormatter::className(),
                    'rootTag' => 'rss',
                    'version' => '1.0',
                    'encoding' => 'utf-8'
                ]
            ]
        ]);
        yii::$app->getResponse()->format = Response::FORMAT_XML;
        return $xml;
    }