コード例 #1
0
ファイル: DropboxLib.php プロジェクト: yslbc/twcompany
 public function putStream($stream, $target)
 {
     $storage = new \Dropbox\OAuth\Storage\ArrayStorage();
     $config = new StdClass();
     $config->oauth_token = getenv('DROPBOX_ACCESS_KEY');
     $config->oauth_token_secret = getenv('DROPBOX_ACCESS_SECRET');
     $storage->set($config, 'access_token');
     $OAuth = new \Dropbox\OAuth\Consumer\Curl(getenv('DROPBOX_KEY'), getenv('DROPBOX_SECRET'), $storage, $callback);
     $dropbox = new \Dropbox\API($OAuth);
     $result = $dropbox->putStream($stream, $target);
 }
コード例 #2
0
ファイル: dropbox.php プロジェクト: rjz/getsimple-cloudbackup
 /**
  *	Run the backup
  */
 public function backup($files)
 {
     $dropbox = new \Dropbox\API($this->_getOAuth());
     $fail = false;
     foreach ($files as $src => $filename) {
         $result = $dropbox->putFile($src, $filename);
         if ($result['code'] != 200) {
             $fail = true;
             break;
         }
     }
     return !$fail;
 }
コード例 #3
0
ファイル: dropbox.php プロジェクト: cuongnd/etravelservice
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return \EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     //-- Require the Dropbox bootstrap
     require JPATH_COMPONENT . '/helpers/Dropbox/bootstrap.php';
     $protocol = false == empty($_SERVER['HTTPS']) ? 'https' : 'http';
     $callback = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     try {
         //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
         $encrypter = new \Dropbox\OAuth\Storage\Encrypter('12312323423435456654457545646542');
         $storage = new \Dropbox\OAuth\Storage\Session($encrypter);
         $OAuth = new \Dropbox\OAuth\Consumer\Curl($this->dboxKey, $this->dboxSecret, $storage, $callback);
         $dropbox = new \Dropbox\API($OAuth);
         //$accountInfo = $dropbox->accountInfo();
         //$logger->log('Dropbox account info:'.print_r($accountInfo, 1));
         $files = $ziper->getCreatedFiles();
         /* @var EcrProjectZiperCreatedfile $file */
         foreach ($files as $i => $file) {
             $logger->log(sprintf('Uploading %s to Dropbox...', $file->name));
             $response = $dropbox->putFile($file->path);
             if ('200' !== $response['code']) {
                 $logger->log(print_r($response, 1));
                 $this->abort('Failed to upload the file to Dropbox', $ziper);
             }
             $response = $dropbox->shares($file->name);
             if ('200' !== $response['code']) {
                 $this->abort('Can not get the Dropbox share link', $ziper);
                 $logger->log(print_r($response['code'], 1));
             }
             $link = $response['body']->url;
             $ziper->setAlternateDownloadLink($i, $link);
             $logger->log('Copy the Link: ' . $link, '', JLog::WARNING);
         }
         $logger->log('Dropbox script executed succesfully.');
     } catch (Dropbox\Exception $e) {
         $this->abort(sprintf('Dropbox: %s', $e->getMessage()), $ziper);
     } catch (Exception $e) {
         $this->abort(sprintf('Dropbox action: %s', $e->getMessage()), $ziper);
     }
     return $this;
 }
コード例 #4
0
ファイル: stuffer.php プロジェクト: cuongnd/etravelservice
 public function checkDropBox()
 {
     require JPATH_COMPONENT . '/helpers/Dropbox/bootstrap.php';
     $input = JFactory::getApplication()->input;
     $key = $input->get('key');
     $secret = $input->get('seqret');
     $protocol = !empty($_SERVER['HTTPS']) ? 'https' : 'http';
     $callback = $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
     $encrypter = new \Dropbox\OAuth\Storage\Encrypter('12312323423435456654457545646542');
     $storage = new \Dropbox\OAuth\Storage\Session($encrypter);
     $OAuth = new \Dropbox\OAuth\Consumer\Curl($key, $secret, $storage, $callback);
     $dropbox = new \Dropbox\API($OAuth);
     $accountInfo = $dropbox->accountInfo();
     if ($accountInfo && '200' == $accountInfo['code']) {
         EcrHtml::message('Welcome to Dropbox.');
         if (ECR_DEBUG) {
             var_dump($accountInfo);
         }
     } else {
         EcrHtml::message('Something went wrong...');
         var_dump($accountInfo);
     }
     parent::display();
 }
コード例 #5
0
ファイル: dropbox.php プロジェクト: betsyzhang/chyrp
 static function admin_manage_dropbox($admin)
 {
     if (!Visitor::current()->group->can("add_post", "add_draft")) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to create posts."));
     }
     if (empty($_POST)) {
         return $admin->display("manage_dropbox");
     }
     $config = Config::current();
     if (!isset($config->module_dropbox["oauth_token"])) {
         Flash::notice(__("You need to authorize Dropbox first.", "dropbox"), "/admin/?action=dropbox_settings");
     }
     $data = json_decode(file_get_contents("http://chyrp.net/api/1/dropboxsync.php?keys"), true);
     $app_key = $data["key"];
     $app_secret = $data["secret"];
     $storage = new \Dropbox\OAuth\Storage\Session();
     $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage);
     $dropbox = new \Dropbox\API($OAuth);
     $delta = $dropbox->delta();
     $delta = $delta["body"];
     if ($delta->cursor != $config->module_dropbox["cursor"]) {
         if (count($delta->entries) > 0) {
             foreach ($delta->entries as $entry) {
                 $tmpfname = tempnam("/tmp", "md");
                 $file = $dropbox->getFile(ltrim($entry[0], "/"), $tmpfname);
                 $post = new FrontMatter($file["name"]);
                 $date = explode(".", ltrim($entry[0], "/"));
                 $values = array("title" => $post->fetch("title"), "body" => $post->fetch("content"));
                 # Set defaults
                 fallback($clean, oneof($post->fetch("slug"), strtolower(str_replace(" ", "-", $post->fetch("title")))));
                 fallback($url, Post::check_url($clean));
                 fallback($pinned, oneof($post->fetch("pinned"), 0));
                 fallback($status, oneof($post->fetch("status"), "public"));
                 fallback($date, oneof(datetime($post->fetch("date")), datetime($date[0])));
                 $post = Post::add($values, $clean, $url, "text", 1, $pinned, $status, datetime($post->fetch("date")), datetime($post->fetch("date")), false);
             }
         }
         $set = array($config->set("module_dropbox", array("oauth_token_secret" => $config->module_dropbox['oauth_token_secret'], "oauth_token" => $config->module_dropbox['oauth_token'], "uid" => $config->module_dropbox['uid'], "cursor" => $delta->cursor)));
         if (!in_array(false, $set)) {
             Flash::notice(__("Post imported successfully.", "dropbox"), "/admin/?action=manage_posts");
         }
     }
 }