Пример #1
0
 /**
  * Start a editing session or return an existing one
  * @param string $uid of the user starting a session
  * @param \OCA\Documents\File $file - file object
  * @return array
  * @throws \Exception
  */
 public static function start($uid, $file)
 {
     // Create a directory to store genesis
     $genesis = new Genesis($file);
     list($ownerView, $path) = $file->getOwnerViewAndPath();
     $oldSession = new Db_Session();
     $oldSession->loadBy('file_id', $file->getFileId());
     //If there is no existing session we need to start a new one
     if (!$oldSession->hasData()) {
         $newSession = new Db_Session(array($genesis->getPath(), $genesis->getHash(), $file->getOwner(), $file->getFileId()));
         if (!$newSession->insert()) {
             throw new \Exception('Failed to add session into database');
         }
     }
     $sessionData = $oldSession->loadBy('file_id', $file->getFileId())->getData();
     $memberColor = Helper::getMemberColor($uid);
     $member = new Db_Member(array($sessionData['es_id'], $uid, $memberColor, time(), intval($file->isPublicShare()), $file->getToken()));
     if ($member->insert()) {
         // Do we have OC_Avatar in out disposal?
         if (!class_exists('\\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true) {
             $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
         } else {
             $imageUrl = $uid;
         }
         $displayName = $file->isPublicShare() ? $uid . ' ' . Db_Member::getGuestPostfix() : \OCP\User::getDisplayName($uid);
         $sessionData['member_id'] = (string) $member->getLastInsertId();
         $op = new Db_Op();
         $op->addMember($sessionData['es_id'], $sessionData['member_id'], $displayName, $memberColor, $imageUrl);
     } else {
         throw new \Exception('Failed to add member into database');
     }
     $sessionData['title'] = basename($path);
     $sessionData['permissions'] = $ownerView->getFilePermissions($path);
     return $sessionData;
 }
Пример #2
0
 /**
  * Start a editing session or return an existing one
  * @param string $uid of the user starting a session
  * @param \OCA\Documents\File $file - file object
  * @return array
  * @throws \Exception
  */
 public static function start($uid, File $file)
 {
     list($ownerView, $path) = $file->getOwnerViewAndPath();
     // Create a directory to store genesis
     $genesis = new Genesis($ownerView, $path, $file->getOwner());
     $oldSession = new Db_Session();
     $oldSession->loadBy('file_id', $file->getFileId());
     //If there is no existing session we need to start a new one
     if (!$oldSession->hasData()) {
         $newSession = new Db_Session(array($genesis->getPath(), $genesis->getHash(), $file->getOwner(), $file->getFileId()));
         if (!$newSession->insert()) {
             throw new \Exception('Failed to add session into database');
         }
     }
     $session = $oldSession->loadBy('file_id', $file->getFileId())->getData();
     $memberColor = Helper::getRandomColor();
     $member = new Db_Member(array($session['es_id'], $uid, $memberColor, time()));
     if ($member->insert()) {
         // Do we have OC_Avatar in out disposal?
         if (!class_exists('\\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true) {
             //$x['avatar_url'] = \OCP\Util::linkToRoute('documents_user_avatar');
             $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
         } else {
             // https://github.com/owncloud/documents/issues/51
             // Temporary stub
             $imageUrl = $uid;
             /*
             				$avatar = new \OC_Avatar($uid);
             				$image = $avatar->get(64);
             					// User has an avatar 
             				if ($image instanceof \OC_Image) {
             					$imageUrl = \OC_Helper::linkToRoute(
             							'core_avatar_get',
             							array( 'user' => $uid, 'size' => 64)
             					) . '?requesttoken=' . \OC::$session->get('requesttoken');
             				} else {
             					//shortcircuit if it's not an image
             					$imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==';
             				}
             */
         }
         $session['member_id'] = (string) $member->getLastInsertId();
         $op = new Db_Op();
         $op->addMember($session['es_id'], $session['member_id'], \OCP\User::getDisplayName($uid), $memberColor, $imageUrl);
     } else {
         throw new \Exception('Failed to add member into database');
     }
     $session['permissions'] = $ownerView->getFilePermissions($path);
     return $session;
 }
Пример #3
0
<?php

/**
 * ownCloud - Documents App
 *
 * @author Victor Dubiniuk
 * @copyright 2013 Victor Dubiniuk victor.dubiniuk@gmail.com
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 */
namespace OCA\Documents;

\OCP\JSON::checkLoggedIn();
$path = Helper::getArrayValueByKey($_GET, 'path');
if (!empty($path)) {
    if (\OC\Files\Filesystem::getMimeType($path) !== Filter_Office::NATIVE_MIMETYPE) {
        $fileInfo = \OC\Files\Filesystem::getFileInfo($path);
        $file = new File($fileInfo->getId());
        $genesis = new Genesis($file);
        $fullPath = $genesis->getPath();
    } else {
        $fullPath = '/files' . $path;
    }
    $download = new Download(\OCP\User::getUser(), $fullPath);
    $download->sendResponse();
}
exit;
Пример #4
0
        // Remove domain from uploads
        update_option('upload_path', null);
        $old_url = site_url();
        $new_url = ($_SERVER['SERVER_PORT'] === '443' ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];
        // Ensure internal WordPress functions map correctly to new url (but don't want to persist in the DB)
        add_filter('option_home', function ($value) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $value);
        });
        add_filter('option_siteurl', function ($value) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $value);
        });
        add_filter('option_upload_path', function ($value) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $value);
        });
        add_filter('option_upload_url_path', function ($value) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $value);
        });
        add_filter('wp_get_attachment_url', function ($value) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $value);
        });
        // Override URLs in output with local environment URL
        ob_start(function ($output) use($old_url, $new_url) {
            return str_replace($old_url, $new_url, $output);
        });
        register_shutdown_function(function () {
            @ob_end_flush();
        });
    }
}
Genesis::initEnv();