示例#1
0
 /**
  * Add remote file
  *
  * @param	   integer	$projectid	Project ID
  * @param	   string	$service	Service name (google or dropbox)
  * @param	   integer	$uid		User ID
  * @param	   object	$file		Models\File
  * @param	   boolean	$convert	Convert for remote editing? (Google only)
  *
  * @return	   array
  */
 public function addRemoteFile($projectid = NULL, $service = 'google', $uid = 0, $file = NULL, $parentId = 0, $convert = false)
 {
     // Get api
     $apiService = $this->getAPI($service, $uid);
     if (!$apiService) {
         $this->setError(Lang::txt('PLG_PROJECTS_FILES_SYNC_API_UNAVAILABLE'));
         return false;
     }
     $newItemId = 0;
     // Parse incoming
     if ($file instanceof \Components\Projects\Models\File) {
         $title = $file->get('name');
         $localPath = $file->get('fullPath');
         $fpath = $file->get('localPath');
         $mimeType = $file->getMimeType();
         $md5 = $file->getMd5Hash();
         $parentId = $parentId ? $parentId : $file->get('remoteParent');
     } else {
         $title = $file['title'];
         $localPath = $file['fullPath'];
         $fpath = $file['local_path'];
         $mimeType = $file['mimeType'];
         $md5 = $file['md5'];
     }
     if (!$parentId) {
         return false;
     }
     // Collector for created item metadata
     $metadata = array();
     // Perform request
     if ($service == 'google') {
         $newItemId = Google::insertFile($apiService, $this->_client[$service], $title, $localPath, $mimeType, $parentId, $metadata, $convert);
     }
     // Error!
     if (!$newItemId) {
         return NULL;
     }
     $remote_md5 = isset($metadata) && isset($metadata['md5Checksum']) ? $metadata['md5Checksum'] : NULL;
     $remote_modified = isset($metadata) && isset($metadata['modifiedDate']) ? gmdate('Y-m-d H:i:s', strtotime($metadata['modifiedDate'])) : NULL;
     $remote_format = isset($metadata) && isset($metadata['mimeType']) ? $metadata['mimeType'] : NULL;
     $converted = isset($metadata) && preg_match("/google-apps/", $remote_format) && !preg_match("/.folder/", $remote_format) ? 1 : 0;
     if ($convert == true && !$converted) {
         // Retreat
         Google::deleteItem($apiService, $newItemId, true);
         return false;
     }
     if ($converted) {
         $g_ext = Google::getGoogleConversionFormat($metadata['mimeType'], false, true);
         $dir = dirname($fpath) != '.' ? dirname($fpath) : '';
         $name = basename($fpath);
         // Get file extention
         $parts = explode('.', $name);
         $ext = count($parts) > 1 ? array_pop($parts) : '';
         if ($g_ext && $ext != $g_ext) {
             $fpath = $dir ? $dir . DS : '';
             $fpath .= $name . '.' . $g_ext;
         }
     }
     // Update connection record
     $objRFile = new \Components\Projects\Tables\RemoteFile($this->_db);
     $update = $objRFile->updateRecord($projectid, $service, $newItemId, $fpath, 'file', $this->_uid, $parentId, $title, $remote_md5, $md5, $converted, $remote_format, $mimeType, $remote_modified);
     return $newItemId;
 }
示例#2
0
    echo $remoteControl ? 'send_to_local' : 'send_to_remote';
    ?>
"><span>&nbsp;</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"';