获取标签列表
@return bool|mixed
@throws \yii\web\HttpException
357633
public function getTagList()
    {
        $result = $this->httpGet(self::WECHAT_TAG_LIST_GET_PREFIX, [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errmsg']) && $result['errmsg'] == 'ok' ? $result['taglist'] : false;
    }
50452
public function actionCallEdit()
    {
        $component = $this->_component;

        if (\Yii::$app->request->get('attributes') && !$settings = \skeeks\cms\models\CmsComponentSettings::findByComponent($component)->one()) {
            $attributes = \Yii::$app->request->get('attributes');
            $component->setAttributes($attributes);
        } else {
            $component->overridePath = [Component::OVERRIDE_DEFAULT];
            $component->refresh();
        }

        if (!\Yii::$app->request->get('callableId')) {
            return $this->redirect(\yii\helpers\Url::to('index') . "?" . http_build_query(\Yii::$app->request->get()));
        }


        return $this->render($this->action->id, [
            'component' => $component,
            'callableId' => \Yii::$app->request->get('callableId'),
        ]);
    }
530127
public function run()
    {
        $url = Yii::$app->request->getUrl();

        $out = '';
        switch ($this->what) {
            case 'forum':
                $out .= Yii::t('podium/view', 'Browsing this forum') . ': ';
                break;
            case 'topic':
                $out .= Yii::t('podium/view', 'Reading this thread') . ': ';
                break;
            case 'unread':
                $out .= Yii::t('podium/view', 'Browsing unread threads') . ': ';
                break;
            case 'members':
                $out .= Yii::t('podium/view', 'Browsing the members') . ': ';
                break;
        }

        $out .= $this->getNamedUsersList($url);

        $anonymous = $this->getAnonymousUsers($url);
        if ($anonymous) {
            $out .= Html::button(
                Yii::t('podium/view', '{n, plural, =1{# anonymous user} other{# anonymous users}}', [
                    'n' => $anonymous
                ]),
                ['class' => 'btn btn-xs btn-default disabled']
            ) . ' ';
        }
        $guests = $this->getGuestUsers($url);
        if ($guests) {
            $out .= Html::button(
                Yii::t('podium/view', '{n, plural, =1{# guest} other{# guests}}', [
                    'n' => $guests
                ]),
                ['class' => 'btn btn-xs btn-default disabled']
            );
        }

        return $out;
    }
562064
public function getWechat()
    {
        if ($this->_wechat === null) {
            $wid = Yii::$app->session->get(self::SESSION_MANAGE_WECHAT_KEY);
            if (!$wid || ($wechat = Wechat::findOne($wid)) === null) {
                return false;
            }
            $this->setWechat($wechat);
        }
        return $this->_wechat;
    }
1200896
public function getUser()
    {
        if ($this->_user === false) {
            $this->_user = \Yii::$app->user->identity;
        }

        return $this->_user;
    }
1005402
public function actionUpdate()
    {
        $model = $this->findModel();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            \Yii::$app->getSession()->setFlash('success', $this->getFlashMsg('success'));
            return $this->redirect(ArrayHelper::merge(['view'], $model->getPrimaryKey(true)));
        } else {
            if ($model->hasErrors()) {
                \Yii::$app->getSession()->setFlash('error', $this->getFlashMsg('error'));
            }
            return $this->render($this->viewID, [
                'model' => $model,
            ]);
        }
    }
317782
public function actionLogin()
    {
        if (!\Yii::$app->user->isGuest) {
            \Yii::$app->getResponse()->redirect(Url::to([\Yii::$app->getHomeUrl()]));
        }

        /** @var LoginForm $model */
        $model = \Yii::createObject(LoginForm::className());
        $event = $this->getFormEvent($model);

        $this->performAjaxValidation($model);
        $this->trigger(self::EVENT_BEFORE_LOGIN, $event);

        if ($model->load(\Yii::$app->getRequest()->post()) && $model->login()) {
            $this->trigger(self::EVENT_AFTER_LOGIN, $event);

            //Checking return url
            if (!empty($model->returnUrl)) {
                $host = \Yii::$app->request->hostInfo;
                $returnUrlHost = substr($model->returnUrl, 0, strlen($host));
                if ($returnUrlHost == $host) {
                    $returnUrl = $model->returnUrl;
                }
                else {
                    $returnUrl = \Yii::$app->user->returnUrl;
                }
            }
            else {
                $returnUrl = Url::to([\Yii::$app->user->returnUrl]);
            }

            \Yii::$app->user->setReturnUrl($returnUrl);

            return \Yii::$app->getResponse()->redirect($returnUrl);
        }

        return $this->render('login', [
            'model'  => $model,
            'module' => $this->module,
        ]);
    }
1287627
public function run()
    {

        $model = $this->model;

        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post()) && isset($_POST['ajax'])) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return \yii\widgets\ActiveForm::validate($model);
        }

        if ($model->load(Yii::$app->request->post())) {
            if ($model->save()) {

                if ($this->isSaveAndNew) {
                    Yii::$app->response->format = Response::FORMAT_JSON;
                    return [
                        'message' => 'saveAndNew',
                        'saveAndNewUrl' => $this->saveAndNewUrl,
                    ];
                }

                Yii::$app->getSession()->setFlash('success', $this->successMsg);
                Yii::$app->response->format = Response::FORMAT_JSON;
                return [
                    'message' => 'success',
                    'success' => true,
                ];
            }

            Yii::$app->getSession()->setFlash('error', $this->errorMsg);
            Yii::$app->response->format = Response::FORMAT_JSON;
            return [
                'message' => 'error',
                'success' => false,
                'error' => Json::encode($model->getErrors()),
            ];
        }

        return $this->controller->renderAjax($this->view, array_merge([
            'model' => $model,
        ], $this->params));
    }
1281062
public function init ()
		{
			$access = ( !is_null(Yii::$app->getModule('users')) and Yii::$app->getModule('users')->useAccessControl );
			$rules = [
				[
					'allow'       => true,
					'actions'     => [ 'index' ],
					'controllers' => [ 'site' ],
					'roles'       => [ '?', '@' ]
				],
				[
					'allow'        => true,
					'actions'      => [ 'auth', 'login' ],
					'controllers'  => [ 'user' ],
					'roles'        => [ '?' ],
					'denyCallback' => function ($rule, $action) { Yii::$app->notification->error(Yii::tr('You are already logged in.')); },
				],
				[
					'allow'         => true,
					'actions'       => [],
					'controllers'   => [],
					'roles'         => [ '@' ],
					'matchCallback' => function ($rule, $action)
					{

						if (!Yii::$app->user->identity->active)
						{
							Yii::$app->notification->errorToSession(Yii::tr('Your account is not approved yet.', [], 'user'));
							$action->controller->redirect(Url::toRoute([ '/site/index' ]));
						}

						return true;
					}
				],
			];

			if ($access)
				foreach (Yii::$app->getModule('users')->allowedUnauthorizedRoutes as $url)
				{
					$url = explode('/', trim($url, '/'));
					array_push($rules, [
						'allow'       => true,
						'actions'     => [ array_pop($url) ],
						'controllers' => [ array_shift($url) ],
						'roles'       => [ '?', '@' ]
					]);
				}

			if ($access or count($this->rules) == 0)
				foreach ($rules as $rule)
				{
					if (is_array($rule))
					{
						array_push($this->rules, Yii::createObject(array_merge($this->ruleConfig, $rule)));
					}
				}
			parent::init();
		}
350134
public function actionSave()
    {
        $link_id = \Yii::$app->request->post('link_id');
        $menu_id = \Yii::$app->request->post('menu_id');
        $url_id = \Yii::$app->request->post('url_id');
        $status = \Yii::$app->request->post('status');

        if (!DpAdminMenuUrl::getByUrlId($url_id)) {
            return $this->renderError('菜单URL不存在！');
        }
        $saveData = [
            'menu_id' => $menu_id,
            'url_id' => $url_id,
            'status' => $status,
        ];
        if ($link_id) {
            $obj = DpAdminMenuUrlRelation::find()
                ->findByLinkId($link_id)
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminMenuUrlRelation();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
405787
public function needCache(){
		// disabled from configs
		if($this->disabled){
			return false;
		}

		// is post request
		if(Yii::$app->request->isPost){
			return false;
		}

		// has request parameter `disallowHtmlCache`
		if(Yii::$app->request->get('disallowHtmlCache')){
			return false;
		}

		// checking for excluded actions
		$excluded_actions = isset($this->excluded_actions[$this->_controller->id]) ? $this->excluded_actions[$this->_controller->id] : array();
		if($excluded_actions && in_array($this->_action->id, $excluded_actions)){
			return false;
		}

		// Checking for excluded params
		$excluded_params = isset($this->excluded_params[$this->_controller->id]) ? $this->excluded_params[$this->_controller->id] : array();

		foreach($excluded_params as $param => $value){
			if(is_numeric($param)){
				$param = $value;
				$value = null;
			}
			elseif(!is_array($value)){
				$value = array($value);
			}

			if(!isset($this->_controller->{$param})){
				continue;
			}

			if(is_null($value) && $this->_controller->{$param}){
				return false;
			}
			elseif(!is_null($value) && in_array($this->_controller->{$param}, $value)){
				return false;
			}
		}

		return true;
	}
925181
public function upload()
    {
        if (!$this->validate()) {
            return false;
        }

        try {
            $save_path = Yii::getAlias($this->_uploadDir);
            FileHelper::createDirectory($save_path);

            $image = $this->image->baseName . '.' . $this->image->extension;

            if (!$this->image->saveAs(FileHelper::normalizePath($save_path . '/' . $image))) {
                return false;
            }

            $this->path = Yii::getAlias($save_path . '/' . $image);
            $this->url = Yii::getAlias($this->_viewPath . '/' . $image);

            return true;

        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }

        return false;
    }
511134
public function actionCreate()
    {
        $model = Yii::createObject($this->getModelClass());

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            \Yii::$app->getSession()->setFlash('success', $this->getFlashMsg('success'));
            return $this->redirect(ArrayHelper::merge(['view'], $model->getPrimaryKey(true)));
        } else {
            if ($model->hasErrors()) {
                \Yii::$app->getSession()->setFlash('error', $this->getFlashMsg('error'));
            }
            return $this->render($this->viewID, [
                'model' => $model,
            ]);
        }
    }
1117635
public function actionIndex()
    {
        /** @var SearchForm $model */
        $model = $this->module->createFormModel('SearchForm');
        if (isset($_REQUEST['SearchForm'])) {
            $model->attributes = $_REQUEST['SearchForm'];
            $model->validate();
            $errors = $model->getErrors();
            $model->setAttributes(array_fill_keys(array_keys($errors), null));
        }

        if (Yii::$app->response->format === Response::FORMAT_JSON) {
            $serializer = new Serializer;
            return $serializer->serialize($model->getIdentity()->getDataProvider($model));
        }

        return $this->render('index', ['model' => $model]);
    }
198788
public function actionSave()
    {
        $user_id = \Yii::$app->request->post('user_id');
        $menu_ids = \Yii::$app->request->post('menu_ids');
        $username = \Yii::$app->request->post('username');
        $nickname = \Yii::$app->request->post('nickname');
        $source_password = \Yii::$app->request->post('source_password');
        $group_ids = (array)\Yii::$app->request->post('group_ids');
        $is_group_access = \Yii::$app->request->post('is_group_access');
        $is_user_access = \Yii::$app->request->post('is_user_access');
        $is_system = \Yii::$app->request->post('is_system');
        $note = \Yii::$app->request->post('note');
        $status = \Yii::$app->request->post('status');

        $groupIdsStr = '';
        if ($group_ids) {
            $groupIdsStr = join(',', array_filter($group_ids, function ($groupId) {
                return DpAdminGroup::getByGroupId($groupId);
            }));
        }

        $saveData = [
            'username' => $username,
            'nickname' => $nickname,
            'source_password' => $source_password,
            'group_ids' => $groupIdsStr,
            'is_group_access' => $is_group_access,
            'is_user_access' => $is_user_access,
            'is_system' => $is_system,
            'note' => $note,
            'status' => $status,
        ];
        if ($user_id) {
            $obj = DpAdminUser::find()
                ->where([
                    'user_id' => $user_id
                ])
                ->one();
            if (!$obj) {
                return $this->renderError('保存失败，记录不存在！');
            }
        } else {
            $obj = new DpAdminUser();
        }
        $obj->setAttributes($saveData);
        if (!$obj->save()) {
            foreach ($obj->getErrors() as $error) {
                foreach ($error as $message) {
                    return [
                        'success' => false,
                        'msg' => $message,
                    ];
                }
            }
        }
        // 用户关联的菜单权限更新
        DpAdminUserMenuRelation::deleteByUserId($obj->user_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 DpAdminUserMenuRelation();
                    $linkObj->setAttributes([
                        'user_id' => $obj->user_id,
                        'menu_id' => $menuId,
                    ]);
                    $linkObj->save();
                }
            }
        }

        return $this->renderSuccess('保存成功');
    }
696865
public function run()
    {
        $action = Yii::$app->getRequest()->get('action', null);
        switch ($action) {
            case 'config':
                $result = Json::encode($this->config());
                break;
            /* 上传图片 */
            case 'uploadimage':
                /* 上传涂鸦 */
            case 'uploadscrawl':
                /* 上传视频 */
            case 'uploadvideo':
                /* 上传文件 */
            case 'uploadfile':
                $result = $this->fileUpload();
                break;
            /* 抓取远程文件 */
            case 'catchimage':
                $result = $this->saveRemote();
                break;
            default:
                $result = Json::encode(array('state' => '请求地址出错'));
                break;
        }
        /* 输出结果 */
        $callback = Yii::$app->getRequest()->get('callback', null);
        if ($callback) {
            if (preg_match("/^[\w_]+$/", $callback)) {
                $result = htmlspecialchars($callback) . '(' . $result . ')';
            } else {
                $result = Json::encode(array('state' => 'callback参数不合法'));
            }
        }
        return $result;
    }
520630
public function login()
    {
        if ($this->validate()) {
            $user = User::findByEmail($this->email);
            Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0);
            return true;
        } else {
            return false;
        }
    }