frontend/controllers/DownloadController.php
/**
     * Renders unrestrained link block
     *
     * @return link
     */
Renders unrestrained link block
@return link
Renders unrestrained link block @return link
public function actionUnrestrainLink()
    {
        $link = Yii::$app->request->post('link', null);
        $password = Yii::$app->request->post('password', null);
        $user = Yii::$app->user->identity;
        Yii::$app->response->format = 'json';
        $service = Service::get();
        if ($service != null) {
            $client = $service->getClient();
            $resp = $client->createLink($link, $user->id, $password);
            if ($resp->isSuccess()) {
                $linkData = [
                    'user_id' => $user->id,
                    'download_link' => $resp->body->downloadLink,
                    'stream_link' => $resp->body->streamLink,
                    'content_name' => $resp->body->contentName,
                    'content_size' => $resp->body->contentSize,
                ];
                $unrestrainedLink = new UnrestrainedLink();
                $unrestrainedLink->setScenario(UnrestrainedLink::SCENARIO_CREATE);
                $unrestrainedLink->load($linkData, '');
                if ($unrestrainedLink->save()) {
                    $success = true;
                } else {
                    $success = false;
                }
            } else {
                $success = false;
            }
            if ($success) {
                return [
                    'success' => true,
                    'linkHtml' => $this->renderAjax('_unrestrainedLink', ['unrestrainedLink' => $unrestrainedLink])
                ];
            } else {
                return [
                    'success' => false,
                    'linkHtml' => $this->renderAjax('_invalidLink', ['link' => $link, 'error' => 'Failed to unrestrain link.'])
                ];
            }
        } else {
            return [
                'success' => false,
                'linksListHtml' => $this->renderAjax('_linksList', [
                    'error' => true,
                    'message' => 'No active services found. Please, try again later.'
                ])
            ];
        }
    }
public function actionUnrestrainLink ( ) { $ link = Yii :: $ app -> request -> post ( 'link' , null ) ; $ password = Yii :: $ app -> request -> post ( 'password' , null ) ; $ user = Yii :: $ app -> user -> identity ; Yii :: $ app -> response -> format = 'json' ; $ service = Service :: get ( ) ; if ( $ service != null ) { $ client = $ service -> getClient ( ) ; $ resp = $ client -> createLink ( $ link , $ user -> id , $ password ) ; if ( $ resp -> isSuccess ( ) ) { $ linkData = [ 'user_id' => $ user -> id , 'download_link' => $ resp -> body -> downloadLink , 'stream_link' => $ resp -> body -> streamLink , 'content_name' => $ resp -> body -> contentName , 'content_size' => $ resp -> body -> contentSize , ] ; $ unrestrainedLink = new UnrestrainedLink ( ) ; $ unrestrainedLink -> setScenario ( UnrestrainedLink :: SCENARIO_CREATE ) ; $ unrestrainedLink -> load ( $ linkData , '' ) ; if ( $ unrestrainedLink -> save ( ) ) { $ success = true ; } else { $ success = false ; } } else { $ success = false ; } if ( $ success ) { return [ 'success' => true , 'linkHtml' => $ this -> renderAjax ( '_unrestrainedLink' , [ 'unrestrainedLink' => $ unrestrainedLink ] ) ] ; } else { return [ 'success' => false , 'linkHtml' => $ this -> renderAjax ( '_invalidLink' , [ 'link' => $ link , 'error' => 'Failed to unrestrain link.' ] ) ] ; } } else { return [ 'success' => false , 'linksListHtml' => $ this -> renderAjax ( '_linksList' , [ 'error' => true , 'message' => 'No active services found. Please, try again later.' ] ) ] ; } }
Renders unrestrained link block
 @return link
Renders unrestrained link block @return link