/** * Processes the google callback from oauth authorize requests * * @return void **/ public function googledriveAuthorizeTask() { $pparams = \Plugin::params('filesystem', 'google'); $app_id = \Session::get('googledrive.app_id', false); $app_secret = \Session::get('googledrive.app_secret', false); $new_connection = Session::get('googledrive.connection_to_set_up', false); $info = ['key' => isset($app_key) ? $app_key : $pparams->get('app_key'), 'secret' => isset($app_secret) ? $app_secret : $pparams->get('app_secret')]; $client = new \Google_Client(); $client->setClientId($app_id); $client->setClientSecret($app_secret); $client->addScope(\Google_Service_Drive::DRIVE); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $redirectUri = trim(Request::root(), '/') . '/developer/callback/googledriveAuthorize'; $client->setRedirectUri($redirectUri); $code = Request::get('code', false); if ($code) { $client->fetchAccessTokenWithAuthCode($code); $accessToken = $client->getAccessToken(); } else { throw new \Exception("No state found", 400); } //if this is a new connection, we can save the token on the server to ensure that it is used next time if ($new_connection) { require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'orm' . DS . 'connection.php'; $connection = \Components\Projects\Models\Orm\Connection::oneOrFail($new_connection); $connection_params = json_decode($connection->get('params')); $connection_params->app_token = $accessToken; $connection->set('params', json_encode($connection_params)); $connection->save(); } // Redirect to the local endpoint App::redirect(base64_decode(\Session::get('googledrive.state'))); }
/** * Constructs a new connections object * * @param object $plugin the plugin that spawned this object * @param string $option the option being used * @param int $connection the connection id * @return void **/ public function __construct($plugin, $option, $connection = null) { $this->plugin = $plugin; $this->_option = $option; if (isset($connection) && $connection > 0) { $this->connection = Connection::oneOrFail($connection); } }
/** * Browser within publications (Curation) * * @return string */ protected function _select() { // Incoming $props = Request::getVar('p', ''); $ajax = Request::getInt('ajax', 0); $pid = Request::getInt('pid', 0); $vid = Request::getInt('vid', 0); $filter = urldecode(Request::getVar('filter', '')); $directory = urldecode(Request::getVar('directory', '')); // Parse props for curation $parts = explode('-', $props); $block = isset($parts[0]) && in_array($parts[0], array('content', 'extras')) ? $parts[0] : 'content'; $step = isset($parts[1]) && is_numeric($parts[1]) && $parts[1] > 0 ? $parts[1] : 1; $element = isset($parts[2]) && is_numeric($parts[2]) && $parts[2] > 0 ? $parts[2] : 1; // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'selector')); $view->publication = new \Components\Publications\Models\Publication($pid, NULL, $vid); // On error if (!$view->publication->exists()) { // Output error $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'error')); $view->title = ''; $view->option = $this->_option; $view->setError(Lang::txt('PLG_PROJECTS_FILES_SELECTOR_ERROR_NO_PUBID')); return $view->loadTemplate(); } $view->publication->attachments(); // Get curation model $view->publication->setCuration(); // Make sure block exists, else use default $view->publication->_curationModel->setBlock($block, $step); // Get file list $view->items = NULL; if ($this->model->get('id')) { // Set params $params = array('sortby' => 'localpath', 'showFullMetadata' => false, 'subdir' => $directory); // Retrieve items if (($cid = Request::getInt('cid')) && $cid > 0) { // Get directory that we're interested in $con = Connection::oneOrFail($cid); $dir = \Hubzero\Filesystem\Entity::fromPath($directory != '.' ? $directory : '', $con->adapter()); $view->items = $dir->listContents(); } else { $view->items = $this->repo->filelist($params); } $view->directory = $directory; // Get directories $params = array('subdir' => NULL, 'sortby' => 'localpath', 'showFullMetadata' => false, 'dirsOnly' => true); $view->folders = $this->repo->filelist($params); } $view->option = $this->model->isProvisioned() ? 'com_publications' : $this->_option; $view->database = $this->_database; $view->model = $this->model; $view->repo = $this->repo; $view->uid = $this->_uid; $view->ajax = $ajax; $view->task = $this->_task; $view->element = $element; $view->block = $block; $view->step = $step; $view->props = $props; $view->filter = $filter; $view->sizelimit = $this->params->get('maxUpload', '104857600'); $view->showCons = $this->params->get('default_action', 'browse') == 'connections' ? true : false; // Get messages and errors $view->msg = $this->_msg; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Save incoming file selection * * @return boolean */ public function save($element, $elementId, $pub, $blockParams, $toAttach = array()) { // Incoming selections if (empty($toAttach)) { $selections = Request::getVar('selecteditems', ''); $toAttach = explode(',', $selections); } // Get configs $configs = $this->getConfigs($element, $elementId, $pub, $blockParams); // Cannot make changes if ($configs->freeze) { return false; } // Nothing to change if (empty($toAttach)) { return false; } // Git helper include_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'githelper.php'; $this->_git = new \Components\Projects\Helpers\Git($configs->path); // Counter $i = 0; $a = 0; // Attach/refresh each selected item foreach ($toAttach as $identifier) { if (!trim($identifier)) { continue; } $identifier = urldecode($identifier); // Catch items coming in from connections if (preg_match('/^([0-9]*):\\/\\//', $identifier, $matches)) { if (isset($matches[1])) { require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'orm' . DS . 'connection.php'; // Grab the connection id $connection = $matches[1]; // Reset identifier $identifier = str_replace($matches[0], '', $identifier); $connection = Connection::oneOrFail($connection); // Create file objects $conFile = Entity::fromPath($identifier, $connection->adapter()); if (!$conFile->isLocal()) { // Create a temp file and write to it $tempFile = Manager::getTempPath($conFile->getName()); Manager::copy($conFile, $tempFile); } else { $tempFile = $conFile; } // Insert the file into the repo $result = $pub->_project->repo()->insert(['subdir' => $conFile->getParent(), 'dataPath' => $tempFile->getAbsolutePath(), 'update' => false]); if (!$conFile->isLocal()) { $tempFile->delete(); } } } $a++; $ordering = $i + 1; if ($this->addAttachment($identifier, $pub, $configs, User::get('id'), $elementId, $element, $ordering)) { $i++; } } // Success if ($i > 0 && $i == $a) { Event::trigger('filesystem.onAfterSaveFileAttachments', [$pub, $configs, $elementId, $element]); $message = $this->get('_message') ? $this->get('_message') : Lang::txt('Selection successfully saved'); $this->set('_message', $message); } return true; }
/** * Execute a request * * @return void */ public function execute() { $this->registerTask('files', 'list'); $this->registerTask('update', 'save'); $this->registerTask('insert', 'save'); $this->_task = Request::getWord('task', 'list'); // Load component language file Lang::load('com_projects') || Lang::load('com_projects', PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site'); // Incoming $id = Request::getVar('id', ''); $this->model = new Project($id); // Project did not load? if (!$this->model->exists()) { throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_CANNOT_LOAD'), 404); } $contentTasks = array('insert', 'update', 'delete', 'move', 'rename', 'makedirectory'); //tasks specific to adapters $connectionTasks = array('upload', 'download', 'getmetadata', 'setmetadata'); // Check authorization if (in_array($this->_task, $contentTasks) && !$this->model->access('content') || in_array($this->_task, $connectionTasks) && !$this->model->access('content') || !$this->model->access('member')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 401); } //connection ID $this->cid = Request::getVar('cid', ''); if (in_array($this->_task, $connectionTasks) && !$this->cid) { throw new Exception("This action is only supported by connection adapters", 401); } //if task involves connections, get the ORM Project object //if there is a connection id, get an ORM Connection object as well if ($this->cid || $this->_task == 'connections') { $this->ormproj = \Components\Projects\Models\Orm\Project::oneOrFail($id); if ($this->cid) { $this->ormconn = \Components\Projects\Models\Orm\Connection::oneOrFail($this->cid); } } // Check for local repo if no connection has been specified if (!$this->cid && !$this->model->repo()->exists()) { throw new Exception(Lang::txt('COM_PROJECTS_FILES_ERROR_NO_LOCAL_REPO'), 404); } parent::execute(); }
* * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * */ // No direct access defined('_HZEXEC_') or die; $connection = \Components\Projects\Models\Orm\Connection::oneOrFail(Request::getInt('cid')); ?> <?php if (!isset($this->noUl) || !$this->noUl) { ?> <ul class="file-selector" id="file-selector"> <?php } ?> <?php if (count($this->items) > 0) { ?> <?php $a = 1;