当前位置: 首页>>代码示例>>PHP>>正文


PHP elFinder::getConnectorUrl方法代码示例

本文整理汇总了PHP中elFinder::getConnectorUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP elFinder::getConnectorUrl方法的具体用法?PHP elFinder::getConnectorUrl怎么用?PHP elFinder::getConnectorUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在elFinder的用法示例。


在下文中一共展示了elFinder::getConnectorUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: netmountPrepare

 /**
  * Prepare
  * Call from elFinder::netmout() before volume->mount().
  *
  * @return array
  *
  * @author Naoki Sawada
  * @author Raja Sharma updating for GoogleDrive
  **/
 public function netmountPrepare($options)
 {
     if (empty($options['client_id']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTID')) {
         $options['client_id'] = ELFINDER_GOOGLEDRIVE_CLIENTID;
     }
     if (empty($options['client_secret']) && defined('ELFINDER_GOOGLEDRIVE_CLIENTSECRET')) {
         $options['client_secret'] = ELFINDER_GOOGLEDRIVE_CLIENTSECRET;
     }
     if (empty($options['googleApiClient']) && defined('ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT')) {
         $options['googleApiClient'] = ELFINDER_GOOGLEDRIVE_GOOGLEAPICLIENT;
         include_once $options['googleApiClient'];
     }
     if (!isset($options['pass'])) {
         $options['pass'] = '';
     }
     try {
         $client = new \Google_Client();
         $client->setClientId($options['client_id']);
         $client->setClientSecret($options['client_secret']);
         if ($options['pass'] === 'reauth') {
             $options['pass'] = '';
             $this->session->set('GoogleDriveAuthParams', [])->set('GoogleDriveTokens', []);
         } elseif ($options['pass'] === 'googledrive') {
             $options['pass'] = '';
         }
         $options = array_merge($this->session->get('GoogleDriveAuthParams', []), $options);
         if (!isset($options['access_token'])) {
             $options['access_token'] = $this->session->get('GoogleDriveTokens', []);
             $this->session->remove('GoogleDriveTokens');
         }
         $aToken = $options['access_token'];
         $rootObj = $service = null;
         if ($aToken) {
             try {
                 $client->setAccessToken($aToken);
                 if ($client->isAccessTokenExpired()) {
                     $aToken = array_merge($aToken, $client->fetchAccessTokenWithRefreshToken());
                     $client->setAccessToken($aToken);
                 }
                 $service = new \Google_Service_Drive($client);
                 $rootObj = $service->files->get('root');
                 $options['access_token'] = $aToken;
                 $this->session->set('GoogleDriveAuthParams', $options);
             } catch (Exception $e) {
                 $aToken = [];
                 $options['access_token'] = [];
                 if ($options['user'] !== 'init') {
                     $this->session->set('GoogleDriveAuthParams', $options);
                     return ['exit' => true, 'error' => elFinder::ERROR_REAUTH_REQUIRE];
                 }
             }
         }
         if ($options['user'] === 'init') {
             if (empty($options['url'])) {
                 $options['url'] = elFinder::getConnectorUrl();
             }
             $callback = $options['url'] . '?cmd=netmount&protocol=googledrive&host=1';
             $client->setRedirectUri($callback);
             if (!$aToken && empty($_GET['code'])) {
                 $client->setScopes([Google_Service_Drive::DRIVE]);
                 if (!empty($options['offline'])) {
                     $client->setApprovalPrompt('force');
                     $client->setAccessType('offline');
                 }
                 $url = $client->createAuthUrl();
                 $html = '<input id="elf-volumedriver-googledrive-host-btn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="{msg:btnApprove}" type="button" onclick="window.open(\'' . $url . '\')">';
                 $html .= '<script>
                     $("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "googledrive", mode: "makebtn"});
                 </script>';
                 if (empty($options['pass']) && $options['host'] !== '1') {
                     $options['pass'] = 'return';
                     $this->session->set('GoogleDriveAuthParams', $options);
                     return ['exit' => true, 'body' => $html];
                 } else {
                     $out = ['node' => $options['id'], 'json' => '{"protocol": "googledrive", "mode": "makebtn", "body" : "' . str_replace($html, '"', '\\"') . '", "error" : "' . elFinder::ERROR_ACCESS_DENIED . '"}', 'bind' => 'netmount'];
                     return ['exit' => 'callback', 'out' => $out];
                 }
             } else {
                 if (!empty($_GET['code'])) {
                     $aToken = $client->fetchAccessTokenWithAuthCode($_GET['code']);
                     $options['access_token'] = $aToken;
                     $this->session->set('GoogleDriveTokens', $aToken)->set('GoogleDriveAuthParams', $options);
                     $out = ['node' => $options['id'], 'json' => '{"protocol": "googledrive", "mode": "done", "reset": 1}', 'bind' => 'netmount'];
                     return ['exit' => 'callback', 'out' => $out];
                 }
                 $folders = [];
                 foreach ($service->files->listFiles(['pageSize' => 1000, 'q' => 'trashed = false and mimeType = "application/vnd.google-apps.folder"']) as $f) {
                     $folders[$f->getId()] = $f->getName();
                 }
                 natcasesort($folders);
                 $folders = ['root' => $rootObj->getName()] + $folders;
//.........这里部分代码省略.........
开发者ID:studio-42,项目名称:elfinder,代码行数:101,代码来源:elFinderVolumeGoogleDrive.class.php

示例2: netmountPrepare

    /**
     * Prepare
     * Call from elFinder::netmout() before volume->mount()
     *
     * @param $options
     * @return Array
     * @author Naoki Sawada
     */
    public function netmountPrepare($options)
    {
        if (empty($options['consumerKey']) && defined('ELFINDER_DROPBOX_CONSUMERKEY')) {
            $options['consumerKey'] = ELFINDER_DROPBOX_CONSUMERKEY;
        }
        if (empty($options['consumerSecret']) && defined('ELFINDER_DROPBOX_CONSUMERSECRET')) {
            $options['consumerSecret'] = ELFINDER_DROPBOX_CONSUMERSECRET;
        }
        if ($options['user'] === 'init') {
            if (!$this->dropbox_phpFound || empty($options['consumerKey']) || empty($options['consumerSecret']) || !class_exists('PDO', false)) {
                return array('exit' => true, 'body' => '{msg:errNetMountNoDriver}');
            }
            if (defined('ELFINDER_DROPBOX_USE_CURL_PUT')) {
                $this->oauth = new Dropbox_OAuth_Curl($options['consumerKey'], $options['consumerSecret']);
            } else {
                if (class_exists('OAuth', false)) {
                    $this->oauth = new Dropbox_OAuth_PHP($options['consumerKey'], $options['consumerSecret']);
                } else {
                    if (!class_exists('HTTP_OAuth_Consumer')) {
                        // We're going to try to load in manually
                        include 'HTTP/OAuth/Consumer.php';
                    }
                    if (class_exists('HTTP_OAuth_Consumer', false)) {
                        $this->oauth = new Dropbox_OAuth_PEAR($options['consumerKey'], $options['consumerSecret']);
                    }
                }
            }
            if (!$this->oauth) {
                return array('exit' => true, 'body' => '{msg:errNetMountNoDriver}');
            }
            if ($options['pass'] === 'init') {
                $html = '';
                if ($sessionToken = $this->session->get('DropboxTokens')) {
                    // token check
                    try {
                        list(, $accessToken, $accessTokenSecret) = $sessionToken;
                        $this->oauth->setToken($accessToken, $accessTokenSecret);
                        $this->dropbox = new Dropbox_API($this->oauth, $this->options['root']);
                        $this->dropbox->getAccountInfo();
                        $script = '<script>
							$("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "dropbox", mode: "done"});
						</script>';
                        $html = $script;
                    } catch (Dropbox_Exception $e) {
                        $this->session->remove('DropboxTokens');
                    }
                }
                if (!$html) {
                    // get customdata
                    $cdata = '';
                    $innerKeys = array('cmd', 'host', 'options', 'pass', 'protocol', 'user');
                    $this->ARGS = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
                    foreach ($this->ARGS as $k => $v) {
                        if (!in_array($k, $innerKeys)) {
                            $cdata .= '&' . $k . '=' . rawurlencode($v);
                        }
                    }
                    if (strpos($options['url'], 'http') !== 0) {
                        $options['url'] = elFinder::getConnectorUrl();
                    }
                    $callback = $options['url'] . '?cmd=netmount&protocol=dropbox&host=dropbox.com&user=init&pass=return&node=' . $options['id'] . $cdata;
                    try {
                        $tokens = $this->oauth->getRequestToken();
                        $url = $this->oauth->getAuthorizeUrl(rawurlencode($callback));
                    } catch (Dropbox_Exception $e) {
                        return array('exit' => true, 'body' => '{msg:errAccess}');
                    }
                    $this->session->set('DropboxAuthTokens', $tokens);
                    $html = '<input id="elf-volumedriver-dropbox-host-btn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="{msg:btnApprove}" type="button" onclick="window.open(\'' . $url . '\')">';
                    $html .= '<script>
						$("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "dropbox", mode: "makebtn"});
					</script>';
                }
                return array('exit' => true, 'body' => $html);
            } else {
                $this->oauth->setToken($this->session->get('DropboxAuthTokens'));
                $this->session->remove('DropboxAuthTokens');
                $tokens = $this->oauth->getAccessToken();
                $this->session->set('DropboxTokens', array($_GET['uid'], $tokens['token'], $tokens['token_secret']));
                $out = array('node' => $_GET['node'], 'json' => '{"protocol": "dropbox", "mode": "done"}', 'bind' => 'netmount');
                return array('exit' => 'callback', 'out' => $out);
            }
        }
        if ($sessionToken = $this->session->get('DropboxTokens')) {
            list($options['dropboxUid'], $options['accessToken'], $options['accessTokenSecret']) = $sessionToken;
        }
        unset($options['user'], $options['pass']);
        return $options;
    }
开发者ID:studio-42,项目名称:elfinder,代码行数:97,代码来源:elFinderVolumeDropbox.class.php

示例3: netmountPrepare

    /**
     * Prepare
     * Call from elFinder::netmout() before volume->mount().
     *
     * @return array
     *
     * @author Naoki Sawada
     * @author Raja Sharma updating for Box
     **/
    public function netmountPrepare($options)
    {
        if (empty($options['client_id']) && defined('ELFINDER_BOX_CLIENTID')) {
            $options['client_id'] = ELFINDER_BOX_CLIENTID;
        }
        if (empty($options['client_secret']) && defined('ELFINDER_BOX_CLIENTSECRET')) {
            $options['client_secret'] = ELFINDER_BOX_CLIENTSECRET;
        }
        if (isset($options['pass']) && $options['pass'] === 'reauth') {
            $options['user'] = 'init';
            $options['pass'] = '';
            $this->session->remove('BoxTokens');
        }
        if (isset($options['id'])) {
            $this->session->set('nodeId', $options['id']);
        } elseif ($_id = $this->session->get('nodeId')) {
            $options['id'] = $_id;
            $this->session->set('nodeId', $_id);
        }
        try {
            if (empty($options['client_id']) || empty($options['client_secret'])) {
                return array('exit' => true, 'body' => '{msg:errNetMountNoDriver}');
            }
            if (isset($_GET['code'])) {
                try {
                    // Obtain the token using the code received by the Box.com API
                    $this->session->set('BoxTokens', $this->_bd_obtainAccessToken($options['client_id'], $options['client_secret'], $_GET['code']));
                    $out = array('node' => $options['id'], 'json' => '{"protocol": "box", "mode": "done", "reset": 1}', 'bind' => 'netmount');
                    return array('exit' => 'callback', 'out' => $out);
                } catch (Exception $e) {
                    $out = array('node' => $options['id'], 'json' => json_encode(array('error' => $e->getMessage())));
                    return array('exit' => 'callback', 'out' => $out);
                }
            } elseif (!empty($_GET['error'])) {
                $out = array('node' => $options['id'], 'json' => json_encode(array('error' => elFinder::ERROR_ACCESS_DENIED)));
                return array('exit' => 'callback', 'out' => $out);
            }
            if ($options['user'] === 'init') {
                $this->token = $this->session->get('BoxTokens');
                if ($this->token) {
                    try {
                        $this->_bd_refreshToken();
                    } catch (Exception $e) {
                        $this->setError($e->getMessage());
                        $this->token = null;
                        $this->session->remove('BoxTokens');
                    }
                }
                if (empty($this->token)) {
                    $result = null;
                } else {
                    $result = $this->_bd_query('0', $fetch_self = false, $recursive = false);
                }
                if (!$result) {
                    $cdata = '';
                    $innerKeys = array('cmd', 'host', 'options', 'pass', 'protocol', 'user');
                    $this->ARGS = $_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : $_GET;
                    foreach ($this->ARGS as $k => $v) {
                        if (!in_array($k, $innerKeys)) {
                            $cdata .= '&' . $k . '=' . rawurlencode($v);
                        }
                    }
                    if (empty($options['url'])) {
                        $options['url'] = elFinder::getConnectorUrl();
                    }
                    $callback = $options['url'] . '?cmd=netmount&protocol=box&host=box.com&user=init&pass=return&node=' . $options['id'] . $cdata;
                    try {
                        $this->session->set('BoxTokens', (object) array('token' => null));
                        $url = self::AUTH_URL . '?' . http_build_query(array('response_type' => 'code', 'client_id' => $options['client_id'], 'redirect_uri' => elFinder::getConnectorUrl() . '?cmd=netmount&protocol=box&host=1'));
                        $url .= '&oauth_callback=' . rawurlencode($callback);
                    } catch (Exception $e) {
                        return array('exit' => true, 'body' => '{msg:errAccess}');
                    }
                    $html = '<input id="elf-volumedriver-box-host-btn" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" value="{msg:btnApprove}" type="button" onclick="window.open(\'' . $url . '\')">';
                    $html .= '<script>
							$("#' . $options['id'] . '").elfinder("instance").trigger("netmount", {protocol: "box", mode: "makebtn"});
						</script>';
                    return array('exit' => true, 'body' => $html);
                } else {
                    $folders = [];
                    foreach ($result as $res) {
                        if ($res->type == 'folder') {
                            $folders[$res->id . ' '] = $res->name;
                        }
                    }
                    natcasesort($folders);
                    $folders = ['root' => 'My Box'] + $folders;
                    $folders = json_encode($folders);
                    $expires = empty($this->token->data->refresh_token) ? (int) $this->token->expires : 0;
                    $json = '{"protocol": "box", "mode": "done", "folders": ' . $folders . ', "expires": ' . $expires . '}';
                    $html = 'Box.com';
//.........这里部分代码省略.........
开发者ID:studio-42,项目名称:elfinder,代码行数:101,代码来源:elFinderVolumeBox.class.php


注:本文中的elFinder::getConnectorUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。