Проверяет по кукам, авторизован ли юзер
Полезна для приложений VK в iframe
@param int $app_id
@return object
162404
static public function isAuth($app_id) {

		$session = array();
		$member = false;
		$valid_keys = array('expire', 'mid', 'secret', 'sid', 'sig');
		$app_cookie = $_COOKIE['vk_app_' . $app_id];
		if( $app_cookie ) {
			$session_data = explode('&', $app_cookie, 10);
			foreach( $session_data as $pair ) {
				list($key, $value) = explode('=', $pair, 2);
				if( empty($key) || empty($value) || !in_array($key, $valid_keys) ) {
					continue;
				}
				$session[$key] = $value;
			}
			foreach( $valid_keys as $key ) {
				if( !isset($session[$key]) ) {
					return $member;
				}
			}
			ksort($session);

			$sign = '';
			foreach( $session as $key => $value ) {
				if( $key != 'sig' ) {
					$sign .= ($key . '=' . $value);
				}
			}
			$sign .= $app_id;
			$sign = md5($sign);
			if( $session['sig'] == $sign && $session['expire'] > time() ) {
				$member = array(
					'id'     => intval($session['mid']),
					'secret' => $session['secret'],
					'sid'    => $session['sid']
				);
			}
		}

		return (object)array(
			'member'  => $member,
			'session' => $session
		);
	}
1146274
public static function getAppIdByApiKey($api_key)
    {
        if (empty($api_key)) {
            return null;
        }
        $cacheKey = 'apikey2appid:' . $api_key;
        try {
            return \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () use ($api_key){
                return App::whereApiKey($api_key)->firstOrFail()->id;
            });
        } catch (ModelNotFoundException $ex) {
            return null;
        }
    }
1262033
public function getSLOurl($application_index = null)
    {
        $url = null;
        $idpData = $this->_settings->getIdPData();
        if (isset($idpData['singleLogoutService']) && isset($idpData['singleLogoutService'][$application_index]) && isset($idpData['singleLogoutService'][$application_index]['url'])) {
            $url = $idpData['singleLogoutService'][$application_index]['url'];
        }
        return $url;
    }
1019359
public static final function create(App $app): ?Service
    {
        $request = $app->request();
        $response = $app->response();
        $requestUri = $request->uri();
        $requestMethod = $request->method();

        // detect service name if provided
        $service = null;
        $serviceName = strtolower($requestUri->segment(1, ''));
        $serviceNameAlias = '';
        $serviceMethod = null;
        $serviceMethodFilter = null;
        $serviceMethodArguments = null;
        $serviceAliases = $app->configValue('service.aliases');

        // main
        if ($serviceName == '') {
            $serviceName = Service::SERVICE_MAIN;
        }
        // aliases
        elseif (isset($serviceAliases[$serviceName][0])) {
            $serviceNameAlias = $serviceName;
            // 0 => name, methods => ...
            $serviceName = $serviceAliases[$serviceNameAlias][0];
            // 0 => name, method => ... if given for one invoke direction
            $serviceMethod = $serviceAliases[$serviceNameAlias]['method'] ?? null;
            // 0 => name, method => ..., methodFilter => ... if given for one invoke direction filter
            $serviceMethodFilter = $serviceAliases[$serviceNameAlias]['methodFilter'] ?? null;
        }
        // regexp routes
        else if (isset($serviceAliases['~~'])) {
            $uriPath = $requestUri->getPath();
            foreach ((array) $serviceAliases['~~'] as $route) {
                // these are required
                if (empty($route['method']) || empty($route['pattern'])) {
                    throw new ServiceException("Both 'method' and 'pattern' are required for RegExp aliases");
                }

                if (preg_match($route['pattern'], $uriPath, $match)) {
                    $serviceName = $route[0];
                    $serviceMethod = $route['method'];
                    $serviceMethodFilter = $route['methodFilter'] ?? null;
                    $serviceMethodArguments = array_slice($match, 1);
                    break;
                }
            }
        }

        $serviceName = self::toServiceName($serviceName);
        $serviceFile = self::toServiceFile($serviceName);
        $serviceClass = self::toServiceClass($serviceName);

        // set service as FailService
        if (!self::isServiceExists($serviceFile, $serviceClass)) {
            set_global('app.service.fail', [
                'code' => 404,
                'text' => sprintf('Service not found [%s]', $serviceName),
            ]);

            // set response status
            $response->setStatus(404);

            $serviceName   = Service::SERVICE_FAIL . Service::SERVICE_NAME_SUFFIX;
            $serviceMethod = Service::METHOD_MAIN;
            $serviceFile   = self::toServiceFile($serviceName);
            $serviceClass  = self::toServiceClass($serviceName);
        }

        $service = new $serviceClass($app, $serviceName, $serviceMethod);

        // detect and set service method
        if (!$service->isFailService()) {
            if ($serviceMethod != '') { // pass
                // @note: method could be checked in main() [if $useMainOnly=true in service]
                // @note: this will override $useMainOnly option in service
            } elseif ($service->usesMainOnly()) {
                // main only
                $serviceMethod = Service::METHOD_MAIN;
            } elseif ($service->isSite()) {
                // from segment
                if ($serviceMethod == '') {
                    $serviceMethod = strtolower($requestUri->segment(2, ''));
                }

                // alias
                if (isset($serviceAliases[$serviceNameAlias]['methods'][$serviceMethod])) {
                    $serviceMethod = self::toServiceMethod($serviceAliases[$serviceNameAlias]['methods'][$serviceMethod]);
                } elseif ($serviceMethod == '' || $serviceMethod == Service::METHOD_MAIN) {
                    // main
                    $serviceMethod = Service::METHOD_MAIN;
                } else {
                    $serviceMethod = self::toServiceMethod($serviceMethod);
                }
            } elseif ($service->isRest()) {
                // from request method
                $serviceMethod = strtolower($requestMethod->getName());
            }

            // check method
            if (!self::isServiceMethodExists($service, $serviceMethod)) {
                // check fallback method
                if (self::isServiceFallMethodExists($service)) {
                    $serviceMethod = Service::METHOD_FALL;
                } else {
                    set_global('app.service.fail', [
                        'code' => 404,
                        'text' => sprintf('Service method not found [%s::%s()]', $serviceName, $serviceMethod)
                    ]);

                    // set response status
                    $response->setStatus(404);

                    // override
                    $serviceName   = Service::SERVICE_FAIL . Service::SERVICE_NAME_SUFFIX;
                    $serviceMethod = Service::METHOD_MAIN;
                    $serviceFile   = self::toServiceFile($serviceName);
                    $serviceClass  = self::toServiceClass($serviceName);

                    // re-create service as FailService
                    $service = new $serviceClass($app, $serviceName, $serviceMethod);
                }
            }

            $service->setMethod($serviceMethod);

            // set service method arguments
            if (self::isServiceMethodExists($service, $serviceMethod)) {
                $serviceMethodArguments = isset($serviceMethodArguments) ? $serviceMethodArguments
                    : $requestUri->segmentArguments($service->isSite() ? 2 : 1);

                $ref = new \ReflectionMethod($serviceClass, $serviceMethod);
                foreach ($ref->getParameters() as $i => $param) {
                    if (!isset($serviceMethodArguments[$i])) {
                        $serviceMethodArguments[$i] = $param->isDefaultValueAvailable()
                            ? $param->getDefaultValue() : null;
                    }
                }

                $service->setMethodArguments($serviceMethod, $serviceMethodArguments);

                // method filter
                if ($serviceMethodFilter != null) {
                    $serviceMethodFilter->call($service);
                }
            }
        }

        return $service;
    }
254551
public static function getMenu($appid, $pid = 0) {
		$button = static::find()->where(['appid' => $appid, 'conditional' => 0, 'pid' => $pid])->select('id, type, name, key, url, media_id')->orderby('list_order, created_at')->asArray()->all();

		foreach($button as $index => $_button) {
			$button[$index]['sub_button'] = static::getMenu($appid, $_button['id']);
			unset($_button['id']);
		}

		return $button;
	}
540321
public function get($appId, $optParams = array()) {
      $params = array('appId' => $appId);
      $params = array_merge($params, $optParams);
      $data = $this->__call('get', array($params));
      if ($this->useObjects()) {
        return new App($data);
      } else {
        return $data;
      }
    }
1289703
public function setMini($appid, $page, $url) {
        $this->setType(self::MINI_PROGRAM);
        $this->appid = $appid;
        $this->pagepath = $page;
        $this->url = $url;
        return $this;
    }
189119
public static function getOpenid($app_id, $app_secret, $code)
    {
        $url = WxpubOAuth::_createOauthUrlForOpenid($app_id, $app_secret, $code);
        $res = self::_getRequest($url);
        $data = json_decode($res, true);

        return $data['openid'];
    }
969858
private function addApp ()
		{
			$appNew = new Apiapp();
			if (Yii::$app->request->post('method') == 'apiapp')
			{
				$post = Yii::$app->request->post();

				if ($post[ 'id' ])
					$appNew = Apiapp::findOne($post[ 'id' ]);

				$appNew->setAttributes([ 'name' => $post[ 'name' ] ]);
				$appNew->token = StringHelper::random(16);
				if ($appNew->validate())
				{
					$appNew->save();
					if (!$post[ 'id' ])
						Yii::$app->session->set('viewID', $appNew->id);
					$url = Yii::$app->request->referrer . '#' . $appNew->name;
					$appNew->setAttributes([ 'name' => '', 'token' => '' ]);
					LogManager::info(Yii::tr('User {user} has created API application {name}.', [ 'user' => Html::a(Yii::$app->user->identity->name, Url::toRoute([ 'user/view', 'id' => Yii::$app->user->id ])), 'name' => $post[ 'name' ] ]));

					Yii::$app->response->redirect($url);
					Yii::$app->end();
				}
			}

			return $appNew;
		}
563157
private function executeInstall($app_name = null)
    {
        if ($app_name == null) {
            $app_name = $this->getAppName();
        }
        $apache = new ApacheProcess();
        $apache->a2enconf($app_name);
        return $apache->reload();
    }
124930
public function actionCreate($module=NULL,$id=NULL){
    $model = new Entity;

    if ($model->load(Yii::$app->request->post()) && $model->save()) 
    {
      if (\Yii::$app->request->isAjax) 
      {
        header('Content-type: application/json');
        echo Json::encode(['status'=>'DONE','model'=>$model]);
        exit();
      }
      else
      {
        return $this->redirect(['view', 'id' => $model->id]);
      }
    } 
    else 
    {
      if(!is_null($module) && !is_null($id))
      {
        $model->mod_table = $module;
        $model->mod_id = $id;  
      }
      return $this->renderAjax('@frenzelgmbh/cmentity/widgets/views/iviews/_form', [
          'model' => $model,
      ]);
    }
  }
124006
private static function _createOauthUrlForOpenid($app_id, $app_secret, $code)
    {
        $urlObj = array();
        $urlObj['appid'] = $app_id;
        $urlObj['secret'] = $app_secret;
        $urlObj['code'] = $code;
        $urlObj['grant_type'] = 'authorization_code';
        $queryStr = http_build_query($urlObj);

        return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $queryStr;
    }
64690
public static function getClassForKey($key, App $app)
    {
        $className = '\\app\\statistics\\metrics\\'.Inflector::get()->camelize($key).'Metric';

        if (class_exists($className)) {
            return new $className($app);
        }

        return false;
    }
347270
public static function getAppId()
    {
        global $objPage;

        if (TL_MODE == 'FE' && $objPage)
        {
            return PageModel::findById($objPage->rootId)->fb_app_id ?: Config::get('fb_app_id');
        }

        return Config::get('fb_app_id');
    }
628173
public function doUpdate( App $app ) {
		if ( ! $app->rewrite_rules ) {
			return FALSE;
		}

		$update = function() use ( $app ) {
            global $wp_rewrite;
            foreach ( $app->rewrite_rules as $regexp => $matches ) {
                $i = (int) ArrayHelper::remove( $matches, 'matches_position', 1);
                $query_string = ArrayHelper::remove( $matches, 'query_string', 'index.php?');
                $priority = ArrayHelper::remove( $matches, 'priority', 'top');
                if ( ! in_array( $priority, ['top', 'bottom'] ) ) {
                    $priority = 'top';
                }

                add_filter('query_vars', function( $vars ) use ( $matches ) {
                    return array_merge( $vars, array_keys( $matches ) );
                } );

                $_regexp = [ $regexp ];
                $_query = [];
                foreach ( $matches as $name => $match ) {
                    $_regexp[] = $match;
                    $_query[] = $name . '=$matches[' . $i . ']';
                    $i++;
                }

                $regexp = join("/", $_regexp ) . '/?$';
                $query  = $query_string . join("&", $_query );

                add_rewrite_rule( $regexp, $query, $priority );
            }
            $wp_rewrite->flush_rules();
        };

		add_action('init', $update );
	}
801006
public function setAppId($appId = null)
    {
        return $this->set($this->appIdColumn, $appId ?: wei()->app->getId());
    }
887619
public static function setApiKeyToAppId($api_key, $app_id)
    {
        $cacheKey = 'apikey2appid:' . $api_key;
        \Cache::put($cacheKey, $app_id, \Config::get('df.default_cache_ttl'));
    }