/** * Disconnect user from service * * @param string $service Service name (google or dropbox) * * @return JSON string or false */ public function disconnectMember($service, $uid = 0, $remoteid = 0) { if (!$uid) { return false; } $objO = $this->model->table('Owner'); $objO->loadOwner($this->model->get('id'), $uid); $creator = $uid == $this->model->get('owned_by_user') ? 1 : 0; // Get connection email & name $email = $this->getStoredParam($service . '_email', $uid); $name = $this->getStoredParam($service . '_name', $uid); // Remove token $objO->saveParam($this->model->get('id'), $uid, $param = $service . '_token', ''); // Remove time $objO->saveParam($this->model->get('id'), $uid, $param = $service . '_token_created', ''); // Remove email $objO->saveParam($this->model->get('id'), $uid, $param = $service . '_email', ''); // Remove name $objO->saveParam($this->model->get('id'), $uid, $param = $service . '_name', ''); // Remove user id $objO->saveParam($this->model->get('id'), $uid, $param = $service . '_userid', ''); if (!$email || !$name || !$remoteid) { return; } // Get api $apiService = $this->getAPI($service, $this->model->owner('id')); if (!$apiService) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_API_UNAVAILABLE')); return false; } // Remove permission if ($service == 'google' && !$creator) { Google::clearPermissions($apiService, array($name => $email), $remoteid); } }
// No direct access defined('_HZEXEC_') or die; if ($this->getError()) { echo '<p class="error">' . $this->getError() . '</p>'; return; } $name = $this->file->get('name'); // Is this a duplicate remote? if ($this->file->get('remote') && $this->file->get('name') != $this->file->get('remoteTitle')) { $append = \Components\Projects\Helpers\Html::getAppendedNumber($this->file->get('name')); if ($append > 0) { $name = \Components\Projects\Helpers\Html::fixFileName($this->file->get('remoteTitle'), ' (' . $append . ')', $this->file->get('ext')); } } // Do not display Google native extension $native = \Components\Projects\Helpers\Google::getGoogleNativeExts(); if (in_array($this->file->get('ext'), $native)) { $name = preg_replace("/." . $this->file->get('ext') . "\\z/", "", $name); } ?> <h4><img src="<?php echo $this->file->getIcon(); ?> " alt="<?php echo $this->file->get('ext'); ?> " /> <?php echo $name; ?> </h4> <ul class="filedata">
/** * Send file back or from to remote service for remote editing * Local repo only * * @return void redirect */ protected function _share() { // Check permission if (!$this->model->access('content')) { App::abort(403, Lang::txt('ALERTNOTAUTH')); } // Incoming $converted = Request::getInt('converted', 0); $service = Request::getVar('service', 'google'); $sync = false; $shared = 0; // Get stored remote connections $remotes = $this->_getRemoteConnections(false); // Params for repo call $params = array('subdir' => $this->subdir, 'remoteConnections' => $remotes); // Combine file and folder data $items = $this->_sortIncoming(); if (empty($items)) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_SHARE')); } else { // Sharing for a single file $type = key($items[0]); $item = $items[0][$type]; // Build metadata object $file = $this->repo->getMetadata($item, $type, $params); } // Build return url $url = $this->model->link('files'); $url .= $this->repo->isLocal() ? '' : '&repo=' . $this->repo->get('name'); $url .= $this->subdir ? '&subdir=' . urlencode($this->subdir) : ''; // Check user is connected if (!empty($this->_remoteService)) { $connected = $this->_connect->getStoredParam($this->_remoteService . '_token', $this->_uid); if (!$connected) { // Redirect to connect screen \Notify::message(Lang::txt('PLG_PROJECTS_FILES_REMOTE_PLEASE_CONNECT'), 'success', 'projects'); App::redirect(Route::url($this->model->link('files') . '&action=connect')); } } else { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_REMOTE_NOT_ENABLED')); } // Confirmation screen if ($this->_task == 'share') { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'share')); $view->option = $this->_option; $view->model = $this->model; $view->repo = $this->repo; $view->uid = $this->_uid; $view->subdir = $this->subdir; $view->path = $this->_path; if ($this->getError()) { $view->setError($this->getError()); } else { $view->file = !empty($file) ? $file : NULL; $view->connect = $this->_connect; $view->service = $this->_remoteService; } return $view->loadTemplate(); } // On error if ($this->getError()) { // Output error $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'error')); $view->title = ''; $view->option = $this->_option; $view->setError($this->getError()); return $view->loadTemplate(); } // Send file for remote editing on Google if ($this->_task == 'shareit') { // Get convertable formats $formats = \Components\Projects\Helpers\Google::getGoogleConversionExts(); // Import remote file if ($file->get('converted')) { // Load remote resource $resource = $this->_connect->loadRemoteResource($service, $this->_uid, $file->get('remoteId')); if (!$resource) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SHARING_NO_REMOTE')); } else { // Incoming $importExt = Request::getVar('format', 'pdf', 'post'); // Remove Google native extension from title $title = $file->get('name'); if (in_array($file->get('ext'), array('gdoc', 'gsheet', 'gslides', 'gdraw'))) { $title = preg_replace("/." . $file->get('ext') . "\\z/", "", $file->get('name')); } // Do we have extention in name already? - take it out $n_parts = explode('.', $title); $n_ext = count($n_parts) > 1 ? array_pop($n_parts) : ''; $title = implode($n_parts); $title .= '.' . $importExt; $newpath = $this->subdir ? $this->subdir . DS . $title : $title; $file->set('localPath', $newpath); $file->set('name', $title); $file->set('fullPath', $this->_path . DS . $newpath); // Replacing file? $exists = file_exists($file->get('fullPath')) ? 1 : 0; // Download remote file if ($this->_connect->importFile($this->_remoteService, $this->_uid, $resource, $file->get('localPath'), $this->repo->get('path'), $importExt)) { // Checkin into repo $params['file'] = $file; $this->repo->call('checkin', $params); // Remove remote resource $deleted = $this->_connect->deleteRemoteItem($this->model->get('id'), $service, $this->_uid, $file->get('remoteId'), false); // Create remote file for imported file $created = NULL; if (!$exists) { $created = $this->_connect->addRemoteFile($this->model->get('id'), $this->_remoteService, $this->_uid, $file); } // Update connection record $this->_connect->savePairing($this->model->get('id'), $this->_remoteService, $created, $file->get('localPath'), $file->get('recordId'), $file->get('originalPath'), $file->get('originalFormat'), $file->get('remoteId')); } // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_UNSHARE_SUCCESS') . ' ' . $title, 'success', 'projects'); // Force sync $sync = true; } } else { // Check that local file exists if (!$this->repo->fileExists($file->get('localPath'))) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SHARING_LOCAL_FILE_MISSING')); } else { // LaTeX? $tex = Components\Projects\Helpers\Compiler::isTexFile($file->get('name'), $file->getMimeType()); // Check format if (!in_array($file->get('ext'), $formats) && !$tex) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_SHARING_NOT_CONVERTABLE')); } if (!$this->getError()) { if ($tex) { // LaTeX? Convert to text file first $file->set('mimeType', 'text/plain'); } if ($file->get('ext') == 'wmf') { // WMF files need this mime type specified for conversion to Google drawing $file->set('mimeType', 'application/x-msmetafile'); } if ($file->get('ext') == 'ppt' || $file->get('ext') == 'pps' || $file->get('ext') == 'pptx') { $file->set('mimeType', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'); } // Convert file $added = $this->_connect->addRemoteFile($this->model->get('id'), $this->_remoteService, $this->_uid, $file, $file->get('remoteParent'), true); if ($added) { // Remove original local file $params['file'] = $file; $this->repo->deleteItem($params); // Remove original remote file $deleted = $this->_connect->deleteRemoteItem($this->model->get('id'), $this->_remoteService, $this->_uid, $file->get('remoteId'), false); $file->clear('mimeType'); $file->setMimeType(); // Update connection record $this->_connect->savePairing($this->model->get('id'), $this->_remoteService, $added, '', $file->get('recordId'), $file->get('originalPath'), $file->get('mimeType'), $file->get('remoteId')); // Output message \Notify::message(Lang::txt('PLG_PROJECTS_FILES_SHARE_SUCCESS'), 'success', 'projects'); // Force sync $sync = true; } else { // Something went wrong $this->setError(Lang::txt('PLG_PROJECTS_FILES_SHARE_ERROR_NO_CONVERT')); if ($this->_connect->getError()) { $this->setError($this->_connect->getError()); } } } } } } // Pass success or error message if ($this->getError()) { \Notify::message($this->getError(), 'error', 'projects'); } // Force sync if ($sync && $this->repo->isLocal()) { $this->model->saveParam('google_sync_queue', 1); } // Redirect to file list App::redirect(Route::url($url)); }
echo $remoteControl ? 'send_to_local' : 'send_to_remote'; ?> "><span> </span></span></p> <ul class="sample"> <?php // Display list item with file data $this->view('default', 'selected')->set('skip', false)->set('file', $this->file)->set('action', 'share')->set('multi', 'multi')->display(); ?> </ul> <?php if ($remoteControl) { $ext = $this->file->get('ext'); if ($this->file->get('originalPath')) { $ext = \Components\Projects\Helpers\Google::getImportExt($this->file->get('originalPath')); } $formats = \Components\Projects\Helpers\Google::getGoogleConversionFormat($this->file->get('mimeType'), false, false, true, $ext); $first = isset($formats[$ext]) ? 0 : 1; if (!empty($formats)) { ?> <h4><?php echo Lang::txt('PLG_PROJECTS_FILES_SHARING_CHOOSE_CONVERSION_FORMAT'); ?> </h4> <div class="sharing-option-extra"> <?php $i = 0; foreach ($formats as $key => $value) { ?> <label <?php if ($ext == $key) { echo 'class="original-format"';