Beispiel #1
1
 public function upload($article_id)
 {
     $accessToken = Yii::$app->params['accessToken'];
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     if ($this->validate()) {
         $image_name = Yii::$app->security->generateRandomString();
         $this->file->saveAs('uploads/' . $image_name . '.' . $this->file->extension);
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $f = fopen("{$file_name}", "rb");
         $result = $dbxClient->uploadFile("/{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image = new Image();
         $image->image_name = $image_name . '.' . $this->file->extension;
         $image->image_article = $article_id;
         $image->image_src_big = $src;
         //small
         $file_name = 'uploads/' . $image_name . '.' . $this->file->extension;
         $resizedFile = 'uploads/small_' . $image_name . '.' . $this->file->extension;
         smart_resize_image($file_name, null, 0, 100, true, $resizedFile, false, false, 100);
         $f = fopen("{$resizedFile}", "rb");
         $result = $dbxClient->uploadFile("/small_" . "{$image_name}" . '.' . $this->file->extension, dbx\WriteMode::add(), $f);
         fclose($f);
         $src = $dbxClient->createShareableLink($result['path']);
         $src[strlen($src) - 1] = '1';
         $image->image_src_small = $src;
         $image->save();
         unlink($file_name);
         unlink($resizedFile);
         return true;
     } else {
         return false;
     }
 }
Beispiel #2
0
 public function linkAccountGet()
 {
     #finishes authentication with access code and user id
     list($accessToken, $userId) = $this->getWebAuth()->finish($_GET);
     #generates a client object which we can grab information with by calling getAccountInfo()
     $client = new dbx\Client($accessToken, "PHP");
     $accountInfo = $client->getAccountInfo();
     #input access information to mysql table.
     $table = Api::updateOrCreate(['user_id' => Auth::id(), 'service' => 1, 'service_email' => $accountInfo['email'], 'service_id' => $userId], ['service_accessToken' => $accessToken]);
     $table->save();
     $updatetable = new apiController();
     $updatetable->updateAccounts();
     return redirect('/');
 }
Beispiel #3
0
 public function dropboxSuccess()
 {
     session_start();
     $appInfo = dbx\AppInfo::loadFromJsonFile(__DIR__ . "\\app-info.json");
     $csrfTokenStore = new dbx\ArrayEntryStore($_SESSION, 'dropbox-auth-csrf-token');
     $webAuth = new dbx\WebAuth($appInfo, "PHP-Example/1.0", 'http://localhost:8080/CloudSync/public/FacebookModel.php', $csrfTokenStore);
     list($accessToken, $dropboxUserId) = $webAuth->finish($_GET);
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     // Saving Access Token and usernifno to dropbox table
     $dropboxObject = new Dropbox();
     $dropboxObject->userId = Auth::id();
     $dropboxObject->username = $accountInfo["display_name"];
     $dropboxObject->accessToken = $accessToken;
     $dropboxObject->uId = $accountInfo["uid"];
     $dropboxObject->save();
     $folderMetadata = $dbxClient->getMetadataWithChildren("/");
     return view('pages.dropbox')->with('dropboxData', $folderMetadata);
 }
 /**
  * Upload file to dropbox
  * @param  init $comment_id
  * @param  init $project_id
  * @param  array $commentdata
  * @return void
  */
 function upload_file_dropbox($post_id = 0, $attachment_id)
 {
     require_once MDROP_PATH . '/lib/dropbox/autoload.php';
     $accesstoken = mdrop_get_token(get_current_user_id());
     //'v1FIiYf35K4AAAAAAAADPLhrp-T8miNShTgeuJ5zrDmyb39gf411tgDJx22_ILSK'; //$this->dropbox_accesstoken;
     $dbxClient = new dbx\Client($accesstoken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     $post = get_post($post_id);
     $files = get_attached_file($attachment_id);
     $file_name = basename(get_attached_file($attachment_id));
     $drop_path = '/EmailAttachment/' . $post->post_title . '/' . $file_name;
     $shareableLink = $dbxClient->createShareableLink($drop_path);
     if (!empty($shareableLink)) {
         return;
     }
     $f = fopen($files, "rb");
     $uploaded_file = $dbxClient->uploadFile($drop_path, dbx\WriteMode::add(), $f);
     fclose($f);
     $dropbox_file_path = $uploaded_file['path'];
     $shareableLink = $dbxClient->createShareableLink($drop_path);
     $this->update_dropbox_shareablelink($attachment_id, $shareableLink);
     $this->update_dropbox_filepath($attachment_id, $dropbox_file_path);
 }
Beispiel #5
0
   </tbody>
</table>
    <body>
<!--side bar navigation-->
<div id="page-sidebar">
<div>
<a id="linkaccount" href = "linkaccount.php">Link Account</a>
<a id="logout" href = "logout.php">Log Out</a>
</div>
<div id="accountInfo">
<?php 
#grabs quota from each account and shows you how much space you have used so far
$accounts = query("SELECT * FROM dropbox_accounts WHERE id = ?", $_SESSION["id"]);
foreach ($accounts as $account) {
    $client = new dbx\Client($account["dropbox_accessToken"], "PHP");
    $userData = $client->getAccountInfo();
    $email = $account["dropbox_email"];
    $normalbytes = $userData['quota_info']['normal'];
    $quotabytes = $userData['quota_info']['quota'];
    #format_bytes is in config.php converts bytes to more readable format.
    print "<br><a class=\"emaillink\" href=\"index.php?{$email}&/\">" . $email . '</a>:' . '</br>' . format_bytes($normalbytes) . ' out of ' . format_bytes($quotabytes) . '</br>';
}
?>
</div>
<!--example from plupload, filelist will show if you dont have flash, or HTML5-->
<div id="filelist">Your browser doesn't have Flash, Silverlight or HTML5 support.</div>
<br />
<!--clicking on of these will trigger actions in the script below-->
<div id="container">
    <a id="pickfiles" href="javascript:;">[Select files]</a> 
    <a id="uploadfiles" href="javascript:;">[Upload files]</a>
 protected function legacy()
 {
     echo "dropbox test";
     /** @var \Shockwavedesign\Mail\Dropbox\Model\Dropbox\User $dropboxUser */
     $dropboxUser = $this->scopeConfig->getDropboxUser();
     $key = $this->config->getValue('system/smtp/dropbox_key', ScopeInterface::SCOPE_STORE);
     $secret = $this->config->getValue('system/smtp/dropbox_secret', ScopeInterface::SCOPE_STORE);
     $accessToken = $dropboxUser->getAccessToken();
     $path = $this->config->getValue('system/smtp/dropbox_host_temp_folder_path', ScopeInterface::SCOPE_STORE);
     $appInfo = dbx\AppInfo::loadFromJson(array('key' => $key, 'secret' => $secret));
     //$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
     //$authorizeUrl = $webAuth->start();
     //echo "1. Go to: " . $authorizeUrl . "\n";
     //echo "2. Click \"Allow\" (you might have to log in first).\n";
     //echo "3. Copy the authorization code.\n";
     //$authCode = "WDUOKE3OsNIAAAAAAAATNEuROlA8b_uXFy0zJ6Rb_XM";
     //list($accessToken, $dropboxUserId) = $webAuth->finish($authCode);
     //print "DropboxUserId: " . $dropboxUserId . "Access Token: " . $accessToken . "\n";
     $dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
     $accountInfo = $dbxClient->getAccountInfo();
     print_r($accountInfo);
     /*
     $f = fopen($path . "test.txt", "rb");
     $result = $dbxClient->uploadFile("/test.txt", dbx\WriteMode::add(), $f);
     fclose($f);
     print_r($result);
     */
     $folderMetadata = $dbxClient->getMetadataWithChildren("/");
     print_r($folderMetadata);
     $f = fopen($path . "test.txt", "w+b");
     $fileMetadata = $dbxClient->getFile("/test.txt", $f);
     fclose($f);
     print_r($fileMetadata);
 }
Beispiel #7
0
<?php

# Include the Dropbox SDK libraries
require_once "../components/lib/Dropbox/autoload.php";
use Dropbox as dbx;
$accessToken = "lDdQ_znbyQAAAAAAAAAADJ22hHnEgTDhHf6KtzH359oJUEQQ2qTc_TtEF8_ILBry";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();
echo "<pre>";
print_r($accountInfo);
/*$file_name = "Marian3.png";

$f = fopen("$file_name", "rb");
$result = $dbxClient->uploadFile("/$file_name", dbx\WriteMode::add(), $f);
fclose($f);
print_r($result);

$src = $dbxClient->createShareableLink($result['path']);
$src[strlen($src) - 1] = '1';
echo $src;
echo '<img src='."$src".' height="300px">'.'<br>';*/
/*$files = $dbxClient->getMetadataWithChildren("/")['contents'];
//print_r($files);
for($i = 0; $i < count($files); $i++)
	if (strpos($files[$i]['mime_type'], "image") !== false){
		$src = $dbxClient->createShareableLink($files[$i]['path']);
		$src[strlen($src) - 1] = '1';
		
		echo '<img src='."$src".' height="300px">'.'<br>';
	}*/
/*$f = fopen("$file_name", "w+b");
 public function authorizeReturn()
 {
     /*try
     		{
     			list($accessToken, $userId, $urlState) = getWebAuth()->finish($_GET);
     		}
     		catch (dbx\WebAuthException_BadRequest $ex) {
     				 error_log("/dropbox-auth-finish: bad request: " . $ex->getMessage());
     				 // Respond with an HTTP 400 and display error page...
     		}
     		catch (dbx\WebAuthException_BadState $ex) {
     		 		// Auth session expired.  Restart the auth process.
     		 		header('Location: /dropbox-auth-start');
     		}
     		catch (dbx\WebAuthException_Csrf $ex) {
     		 error_log("/dropbox-auth-finish: CSRF mismatch: " . $ex->getMessage());
     		 // Respond with HTTP 403 and display error page...
     		}
     		catch (dbx\WebAuthException_NotApproved $ex) {
     		 error_log("/dropbox-auth-finish: not approved: " . $ex->getMessage());
     		}
     		catch (dbx\WebAuthException_Provider $ex) {
     		 error_log("/dropbox-auth-finish: error redirect from Dropbox: " . $ex->getMessage());
     		}
     		catch (dbx\Exception $ex) {
     		 error_log("/dropbox-auth-finish: error communicating with Dropbox API: " . $ex->getMessage());
     	 }*/
     //echo "<pre>" . var_dump(Session::all());
     list($accessToken, $userId, $urlState) = $this->getWebAuth()->finish(Input::all());
     #echo "Access token: " . $accessToken;
     Session::put("dropbox-token", $accessToken);
     $dbxClient = new dbx\Client($accessToken, $this->_appName);
     $accountInfo = $dbxClient->getAccountInfo();
     Session::put("dropbox-name", $accountInfo["display_name"]);
     /*$dbxClient = new dbx\Client($accessToken, $this->_appName);
     		$accountInfo = $dbxClient->getAccountInfo();
     
     		print_r($accountInfo);
     
     		$f = fopen("/laravelhurrdurr/public/robots.txt", "rb");
     		$result = $dbxClient->uploadFile("/laravelhurrdurr/public/robots.txt", dbx\WriteMode::add(), $f);
     		fclose($f);
     		print_r($result);*/
     return Redirect::to("dropbox-dashboard");
     #return View::make("dropbox", [ "message" => "Access token: " . Session::get("dropbox-token")]);
 }
Beispiel #9
0
 //	var_dump($accessTokenDatabase);
 $appInfo = dbx\AppInfo::loadFromJsonFile($appInfoFile);
 $clientIdentifier = "sass-app/1.0";
 $webAuth = new dbx\WebAuthNoRedirect($appInfo, $clientIdentifier, "en");
 if ($accessTokenDatabase !== NULL) {
     try {
         $dbxClientDB = new dbx\Client($accessTokenDatabase, "PHP-Example/1.0");
         $accountInfoDatabase = $dbxClientDB->getAccountInfo();
     } catch (Exception $e) {
         $errors[] = "Could not access Dropbox account database. Maybe user has revoked access?";
     }
 }
 if ($accessTokenExcel !== NULL) {
     try {
         $dbxClientExcel = new dbx\Client($accessTokenExcel, "PHP-Example/1.0");
         $accountInfoExcel = $dbxClientExcel->getAccountInfo();
     } catch (Exception $e) {
         $errors[] = "Could not access Dropbox account excel. Maybe user has revoked access?";
     }
 }
 if (isBtnRqstDropboxConnectionPrsd()) {
     $authCode = $_POST['dropbox-key-token-db'];
     if (empty($authCode)) {
         throw new Exception("Key token is required.");
     }
     list($accessTokenDatabase, $userId) = $webAuth->finish($authCode);
     DropboxCon::insertAccessToken($accessTokenDatabase, $user->getId(), DropboxCon::SERVICE_APP_DATABASE_BACKUP);
     header('Location: ' . BASE_URL . "cloud/success");
     exit;
 } else {
     if (isBtnRqstDropboxConnectExcelKeyPrsd()) {
$report_to_email = '0';
$email_from = '*****@*****.**';
$email_reply_to = $email_from;
$email_to = $email_from;
$email_title = "REPORT: dropbox-sync: ";
###############################################################################
# modules
###############################################################################
require_once __DIR__ . '/../lib/Dropbox/autoload.php';
use Dropbox as dbx;
$client = new dbx\Client($accessToken, $clientIdentifier, $userLocale);
###############################################################################
# program
###############################################################################
// collect accountinfo to be used for human quota calculations
$account_info = $client->getAccountInfo();
$quota_shared = bytes_to_human($account_info['quota_info']['shared']);
$quota = bytes_to_human($account_info['quota_info']['quota']);
$quota_used = bytes_to_human($account_info['quota_info']['normal']);
$quota_left = $account_info['quota_info']['quota'] - $account_info['quota_info']['normal'];
$quota_left = bytes_to_human($quota_left);
$delta_page = array();
// get_previous_cursor
if ($use_cursor == 1) {
    $cursor = get_previous_cursor($cursor_file);
    $delta_page['cursor'] = $cursor;
} else {
    //$cursor = $cursor;
    $delta_page['cursor'] = $cursor;
}
// getDelta collets data per page
# Include the Dropbox SDK libraries
require_once ROOT_PATH . "plugins/dropbox-sdk/lib/Dropbox/autoload.php";
include_once ROOT_PATH . 'plugins/mysqldump-php-1.4.1/src/Ifsnop/Mysqldump/Mysqldump.php';
use Dropbox as dbx;
try {
    date_default_timezone_set('Europe/Athens');
    // run script only during working hours
    if (!App::isWorkingDateTimeOn()) {
        exit;
    }
    $filePath = ROOT_PATH . 'storage/excel/';
    $curTerms = TermFetcher::retrieveCurrTerm();
    foreach ($curTerms as $curTerm) {
        $curTermId = $curTerm[TermFetcher::DB_COLUMN_ID];
        $curTermName = $curTerm[TermFetcher::DB_COLUMN_NAME];
        $curTermStartDateTime = new DateTime($curTerm[TermFetcher::DB_COLUMN_START_DATE]);
        $curTermYear = $curTermStartDateTime->format('Y');
        $fullPathFile = Excel::saveAppointments($curTermId);
        $fileName = pathinfo($fullPathFile)['filename'] . "." . pathinfo($fullPathFile)['extension'];
        $accessToken = DropboxFetcher::retrieveAccessToken(DropboxCon::SERVICE_APP_EXCEL_BACKUP)[DropboxFetcher::DB_COLUMN_ACCESS_TOKEN];
        $dbxClient = new dbx\Client($accessToken, App::getVersion());
        $adminAccountInfo = $dbxClient->getAccountInfo();
        $f = fopen($fullPathFile, "rb");
        $result = $dbxClient->uploadFile("/storage/excel/{$curTermYear}/{$fileName}", dbx\WriteMode::force(), $f);
        fclose($f);
    }
    exit;
} catch (\Exception $e) {
    App::storeError($e);
    exit;
}
Beispiel #12
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Dropbox\Client as DropboxClient;
$token = 'KBX87Dt80DcAAAAAAAAAGAsOTb0KrkX1mXvPyoi6k8L1q0cbSnM2oBS-SrUAI19-';
$app = 'Getup.io/1.0';
$dropbox = new DropboxClient($token, $app);
var_dump($dropbox->getAccountInfo());
$metadata = $dropbox->getMetadataWithChildren('/consultaleiloes/uploads');
if (isset($metadata['contents']) && is_array($metadata['contents'])) {
    $contents = $metadata['contents'];
    $files = array_filter($contents, function ($file) {
        return $file['is_dir'] != 1;
    });
    $files = array_map(function ($file) {
        return $file['path'];
    }, $files);
    var_dump($files);
}