frontend/modules/download/controllers/FileController.php
/**
     * Renders the index view for the module
     * @return string
     */
Renders the index view for the module
@return string
Renders the index view for the module @return string
public function actionIndex()
    {
        $model = new DynamicModel(['share_hash']);
        $model->addRule(['share_hash'], 'required');
        $model->addRule(['share_hash'], 'string', ['length' => 32]);
        $data[$model->formName()] = Yii::$app->request->get();
        if ($model->load($data) && $model->validate()) {
            $share = UserFiles::find()
                ->where(['share_hash' => $model->share_hash])
                ->andWhere("(share_lifetime > :share_lifetime) OR (share_lifetime IS NULL)", ['share_lifetime'  => date(SQL_DATE_FORMAT)])
                ->andWhere("last_event_type <> :last_event_type", ['last_event_type' => UserFileEvents::TYPE_DELETE])
                ->limit(1)
                ->one();
            if ($share) {
                if ($share->share_is_locked) {
                    return "404 Share is locked";
                }
                $eventWithUuid = UserFileEvents::find()
                    ->select([
                        'event_id',
                        'event_uuid',
                    ])
                    ->where(['file_id' => $share->file_id])
                    ->andWhere('event_type NOT IN (:event_delete)', ['event_delete' => UserFileEvents::TYPE_DELETE])
                    ->orderBy(['event_id' => SORT_DESC])
                    ->limit(1)
                    ->one();
                if ($eventWithUuid) {
                    $nodes = UserNode::find()
                        ->where([
                            'user_id' => $share->user_id,
                        ])
                        ->andWhere('node_status != :node_status', ['node_status' => UserNode::STATUS_DELETED])
                        ->asArray()
                        ->all();
                    $servers['stun'] = Servers::find()
                        ->asArray()
                        ->where([
                            'server_type' => Servers::SERVER_TYPE_STUN,
                            'server_status' => Servers::SERVER_ACTIVE_YES
                        ])->limit(1)->all();
                    if (!isset($servers['stun'][0])) {
                        return "404 STUN-Server Not Found";
                    }
                    $servers['sign'] = Servers::find()
                        ->asArray()
                        ->where([
                            'server_type' => Servers::SERVER_TYPE_SIGN,
                            'server_status' => Servers::SERVER_ACTIVE_YES
                        ])->limit(1)->all();
                    if (!isset($servers['sign'][0])) {
                        return "404 SIGN-Server Not Found";
                    }
                    $servers['proxy'] = Servers::find()
                        ->asArray()
                        ->where([
                            'server_type' => Servers::SERVER_TYPE_PROXY,
                            'server_status' => Servers::SERVER_ACTIVE_YES
                        ])->limit(1)->all();
                    if (!isset($servers['proxy'][0])) {
                        return "404 PROXY-NODE-Server Not Found";
                    }
                    if (mb_strrpos($servers['proxy'][0]['server_url'], '/') == mb_strlen($servers['proxy'][0]['server_url']) - 1) {
                        $servers['proxy'][0]['server_url'] = mb_substr($servers['proxy'][0]['server_url'], 0, mb_strlen($servers['proxy'][0]['server_url']) - 1);
                    }
                    return $this->render('index', [
                        'share' => $share,
                        'eventWithUuid' => $eventWithUuid,
                        'servers' => $servers,
                        'nodes' => $nodes
                    ]);
                }
            }
        }
        return "404 Share Not Found";
    }
public function actionIndex ( ) { $ model = new DynamicModel ( [ 'share_hash' ] ) ; $ model -> addRule ( [ 'share_hash' ] , 'required' ) ; $ model -> addRule ( [ 'share_hash' ] , 'string' , [ 'length' => 32 ] ) ; $ data [ $ model -> formName ( ) ] = Yii :: $ app -> request -> get ( ) ; if ( $ model -> load ( $ data ) && $ model -> validate ( ) ) { $ share = UserFiles :: find ( ) -> where ( [ 'share_hash' => $ model -> share_hash ] ) -> andWhere ( " (share_lifetime > :share_lifetime) OR (share_lifetime IS NULL) " , [ 'share_lifetime' => date ( SQL_DATE_FORMAT ) ] ) -> andWhere ( " last_event_type <> :last_event_type " , [ 'last_event_type' => UserFileEvents :: TYPE_DELETE ] ) -> limit ( 1 ) -> one ( ) ; if ( $ share ) { if ( $ share -> share_is_locked ) { return " 404 Share is locked " ; } $ eventWithUuid = UserFileEvents :: find ( ) -> select ( [ 'event_id' , 'event_uuid' , ] ) -> where ( [ 'file_id' => $ share -> file_id ] ) -> andWhere ( 'event_type NOT IN (:event_delete)' , [ 'event_delete' => UserFileEvents :: TYPE_DELETE ] ) -> orderBy ( [ 'event_id' => SORT_DESC ] ) -> limit ( 1 ) -> one ( ) ; if ( $ eventWithUuid ) { $ nodes = UserNode :: find ( ) -> where ( [ 'user_id' => $ share -> user_id , ] ) -> andWhere ( 'node_status != :node_status' , [ 'node_status' => UserNode :: STATUS_DELETED ] ) -> asArray ( ) -> all ( ) ; $ servers [ 'stun' ] = Servers :: find ( ) -> asArray ( ) -> where ( [ 'server_type' => Servers :: SERVER_TYPE_STUN , 'server_status' => Servers :: SERVER_ACTIVE_YES ] ) -> limit ( 1 ) -> all ( ) ; if ( ! isset ( $ servers [ 'stun' ] [ 0 ] ) ) { return " 404 STUN-Server Not Found " ; } $ servers [ 'sign' ] = Servers :: find ( ) -> asArray ( ) -> where ( [ 'server_type' => Servers :: SERVER_TYPE_SIGN , 'server_status' => Servers :: SERVER_ACTIVE_YES ] ) -> limit ( 1 ) -> all ( ) ; if ( ! isset ( $ servers [ 'sign' ] [ 0 ] ) ) { return " 404 SIGN-Server Not Found " ; } $ servers [ 'proxy' ] = Servers :: find ( ) -> asArray ( ) -> where ( [ 'server_type' => Servers :: SERVER_TYPE_PROXY , 'server_status' => Servers :: SERVER_ACTIVE_YES ] ) -> limit ( 1 ) -> all ( ) ; if ( ! isset ( $ servers [ 'proxy' ] [ 0 ] ) ) { return " 404 PROXY-NODE-Server Not Found " ; } if ( mb_strrpos ( $ servers [ 'proxy' ] [ 0 ] [ 'server_url' ] , '/' ) == mb_strlen ( $ servers [ 'proxy' ] [ 0 ] [ 'server_url' ] ) - 1 ) { $ servers [ 'proxy' ] [ 0 ] [ 'server_url' ] = mb_substr ( $ servers [ 'proxy' ] [ 0 ] [ 'server_url' ] , 0 , mb_strlen ( $ servers [ 'proxy' ] [ 0 ] [ 'server_url' ] ) - 1 ) ; } return $ this -> render ( 'index' , [ 'share' => $ share , 'eventWithUuid' => $ eventWithUuid , 'servers' => $ servers , 'nodes' => $ nodes ] ) ; } } } return " 404 Share Not Found " ; }
Renders the index view for the module
 @return string
Renders the index view for the module @return string
/** @var \common\models\UserFiles $share */ //var_dump($_GET); exit; //->asArray() /*
                ->andWhere("(share_lifetime > :share_lifetime) OR ((share_lifetime IS NULL) AND (share_ttl_info != :TTL_IMMEDIATELY_DOWNLOADED))", [
                    'share_lifetime'             => date(SQL_DATE_FORMAT),
                    'TTL_IMMEDIATELY_DOWNLOADED' => UserFiles::TTL_IMMEDIATELY_DOWNLOADED,
                ])
                */ //var_dump($share); exit; /** @var \common\models\UserFileEvents $eventWithUuid */ //'node_online' => UserNode::ONLINE_ON, //var_dump($nodes); //$this->layout = "download"; //var_dump($model->getErrors());