public function open($savePath, $sessionName) { $this->name = $sessionName; if (isset($_SERVER['SERVER_SOFTWARE']) && strstr(strtolower($_SERVER['SERVER_SOFTWARE']), 'engine')) { require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; $this->savePath = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/sessions'; } else { $this->savePath = $savePath; if (!is_dir($this->savePath)) { mkdir($this->savePath, 0777); } } return true; }
function doResumableUpload(Google_Client $client) { // Drive service $driveService = new Google_Service_Drive($client); $gs_basepath = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName(); $fileName = UPLOAD_FILENAME; // 82.52MB file $fileToUploadPath = $gs_basepath . "/{$fileName}"; $uploadFilesize = filesize($fileToUploadPath); $options = array('gs' => array('enable_cache' => false, 'acl' => 'public-read')); $ctx = stream_context_create($options); if (($handle = fopen($fileToUploadPath, 'r', false, $ctx)) === false) { throw new Exception('fopen failed.'); } $mimeType = CloudStorageTools::getContentType($handle); // prepare a drive file $file = new Google_Service_Drive_DriveFile(); $file->setTitle($fileName); $file->setMimeType($mimeType); $file->setFileSize($uploadFilesize); // You can also set the parent folder: // @see https://developers.google.com/drive/v2/reference/files/insert $chunkSizeBytes = 256 * 1024 * 4 * 1; // upload in multiples of 256K (1M * n) // Call the API with the media upload, defer so it doesn't immediately return. $client->setDefer(true); $request = $driveService->files->insert($file); // Create a media file upload to represent our upload process. $media = new Google_Http_MediaFileUpload($client, $request, $mimeType, null, true, $chunkSizeBytes); // set the media filesize to the actual filesize. $media->setFileSize($uploadFilesize); // Upload the various chunks. $status will be false until the process is complete. $status = false; while (!$status && !feof($handle)) { $chunk = readChunk($handle, $chunkSizeBytes); $status = $media->nextChunk($chunk); } fclose($handle); // Reset to the client to execute requests immediately in the future. $client->setDefer(false); var_dump($status); }
public static function set_default_bucket() { $current = get_option('appengine_uploads_bucket', false); if (!empty($current)) { return; } $default = CloudStorageTools::getDefaultGoogleStorageBucketName(); update_option('appengine_uploads_bucket', $default); }
$session_path = __DIR__ . '/../../media/sessions'; if (isset($_SERVER['SERVER_SOFTWARE']) && strstr(strtolower($_SERVER['SERVER_SOFTWARE']), 'engine')) { require_once 'google/appengine/api/users/User.php'; require_once 'google/appengine/api/users/UserService.php'; require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; $mail = UserService::getCurrentUser()->getNickname(); $session_token = md5($mail); $user = new userModel(); $u = $user->find_one_by_email(strtolower($mail)); if (isset($u['id'])) { Bootstrap::$main->session('user', $u); Bootstrap::$main->user = $u; Bootstrap::$main->session('time_delta', $u['delta']); echo '<h1><a href="/admin/">' . $u['firstname'] . ' ' . $u['lastname'] . '</a></h1>'; } $session_path = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/sessions'; } else { echo "<h1>Witaj</h1>"; @mkdir($session_path, 0755); } $session_file = "{$session_path}/{$session_token}.sess"; $session = file_exists($session_file) ? unserialize(file_get_contents($session_file)) : []; $user = new userModel(); $users = $user->count(); $event = new eventModel(); $events = $event->count(['active' => 1, 'd_event_start' => ['>', Bootstrap::$main->now]]); $guest = new guestModel(); $guests = $guest->join('event', 'events', 'id')->sum('persons', ['active' => 1, 'd_event_start' => ['>', Bootstrap::$main->now], 'd_payment' => ['>', 0], 'd_cancel' => null]); echo '<div class="menu"><ul>'; if (!isset($menu)) { $menu = '';
public function testGetDefaultBucketNameNotSet() { $req = new \google\appengine\files\GetDefaultGsBucketNameRequest(); $resp = new \google\appengine\files\GetDefaultGsBucketNameResponse(); $this->apiProxyMock->expectCall("file", "GetDefaultGsBucketName", $req, $resp); $bucket = CloudStorageTools::getDefaultGoogleStorageBucketName(); $this->assertEquals($bucket, ""); $this->apiProxyMock->verify(); }
private function getAllowedBuckets() { static $allowed_buckets = null; if (!$allowed_buckets) { $allowed_buckets = explode(',', GAE_INCLUDE_GS_BUCKETS); $allowed_buckets = array_map('trim', $allowed_buckets); $allowed_buckets = array_filter($allowed_buckets); if (ini_get('google_app_engine.gcs_default_keyword')) { $allowed_buckets = array_map(function ($path) { $parts = explode('/', $path); if ($parts[0] == CloudStorageTools::GS_DEFAULT_BUCKET_KEYWORD) { $parts[0] = CloudStorageTools::getDefaultGoogleStorageBucketName(); } return implode('/', $parts); }, $allowed_buckets); } } return $allowed_buckets; }
public static function log($app, $data = null) { if (Bootstrap::$main->appengine) { require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; } $root = Bootstrap::$main->appengine ? 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/' : __DIR__ . '/../../../media/'; $file = $root . 'log/' . $app . '/' . date('Y') . '/' . sprintf('%02d', date('m')) . '/' . sprintf('%02d', date('d')); $d = date('Y-m-d H:i:s'); $f = 0; while (file_exists("{$file}/{$d}:{$f}.txt")) { $f++; } $file = "{$file}/{$d}:{$f}.txt"; $header = date('Y-m-d H:i:s'); if (isset($_SERVER['REMOTE_ADDR'])) { $header .= ", IP:" . $_SERVER['REMOTE_ADDR']; } if (isset(Bootstrap::$main->user['email'])) { $header .= ", email: " . Bootstrap::$main->user['email']; } $header .= "\n"; self::save(substr($file, strlen($root)), $header . print_r($data, 1) . "\n\n"); }
<?php use google\appengine\api\cloud_storage\CloudStorageTools; require_once "c_transactions.php"; $db = new db_transactions(); // SQL statements $sql_demographics = "INSERT INTO demographics (study_id, abs_date, facility_id, anc_id, psc_id, visit_count, " . "anc_visit_date, birth_date, residence, parity, gravida, gestational_period, lmp, edd," . " marital_status, hiv_status, initial_hiv_status, hiv_retest, woman_haart, haart_regimen, " . "counselling, hiv_status_partner, return_date, user_initial) "; $sql_infant_registration = "INSERT INTO infant_registration(hei_id, d_study_id, birth_date, birth_weight, " . "sex, delivery_place, arv_prophylaxis, arv_pro_other, enrol_date, enrol_age, user_initial) "; $sql_adherence = "INSERT INTO adherence(a_study_id, visit_date, haart_start_date, haart_regimen, art_effect, " . "self_art_adherence, self_ctx_adherence, cd4_taken, cd4_count, cd4_date, vl_taken, viral_load, " . "viral_date, who_stage, user_initial, next_visit_date) "; $sql_variables = "INSERT INTO variables(v_study_id, visit_date, weight, height, hb_taken, hemoglobin, " . "hemoglobin_date, tb_status, preg_status, edd, fp_status, fp_method, disclosure, patner_tested, " . "user_initial, next_visit_date) "; $sql_retention = "INSERT INTO retention (r_study_id, hiv_visit, next_visit, user_initial) "; $sql_infant_diagnosis = "INSERT INTO infant_diagnosis(i_hei_id, visit_date, weight, height, " . "tb_contact, tb_ass_outcome, inf_milestones, imm_history, next_appointment, first_sample_collection, first_results_collected," . "first_results, second_sample_collection, second_results_collected, second_results, third_sample_collection, " . " third_results_collected, third_results, forth_sample_collection, forth_results_collected, forth_results," . "fifth_sample_collection, fifth_results_collected, fifth_results, sixth_sample_collection, sixth_results_collected," . "sixth_results, hei_outcome, exit_date, feeding_6wks, feeding_10wks, " . "feeding_14wks, feeding_9mths, feeding_12mths, feeding_15mths, feeding_18mths, " . "user_initial) "; $bucket = CloudStorageTools::getDefaultGoogleStorageBucketName(); $root_path = 'gs://motivatestudy/'; $public_urls = []; foreach ($_FILES['userfile']['name'] as $idx => $name) { $ext = strtolower(end(explode('.', $_FILES['userfile']['name']))); if ($_FILES['userfile']['type'][$idx] === 'text/csv') { echo "IT IS CSV"; //$im = imagecreatefromjpeg($_FILES['userfile']['tmp_name'][$idx]); //imagefilter($im, IMG_FILTER_GRAYSCALE); //$grayscale = $root_path . 'gray/' . $name; //imagejpeg($im, $grayscale); $original = $root_path . 'csv/' . $name; move_uploaded_file($_FILES['userfile']['tmp_name'][$idx], $original); echo nl2br($original . 'idx ' . $idx); /* === */ if ($csvfile = fopen("gs://motivatestudy/csv/variables.csv", 'r') !== FALSE) { echo nl2br("FILE READ SUCCSSFULY"); echo nl2br($_FILES['userfile']['tmp_name']); if ($_REQUEST['form'] == "demographics") {
} if (isset($_SERVER['HTTP_HOST'])) { echo '<h1>'; } if ($migration->getCurrentVersion() == $version) { echo 'Database at version ' . $version . PHP_EOL; } else { $migration->migrate($version); echo 'Migrated succesfully to version ' . $migration->getCurrentVersion() . PHP_EOL; } if (isset($_SERVER['HTTP_HOST'])) { echo '</h1>'; } if (isset($_SERVER['SERVER_SOFTWARE']) && strstr(strtolower($_SERVER['SERVER_SOFTWARE']), 'engine')) { require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; $path = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/sql'; if (file_exists($path)) { foreach (scandir($path) as $file) { $f = $path . '/' . $file; echo 'Execute ' . $file . PHP_EOL; $conn->execute(file_get_contents($f)); } } } if (isset($_REQUEST['sql']) && (!isset($google_user) || $google_user->getNickname() == '*****@*****.**')) { $r = $conn->execute($_REQUEST['sql']); print_r($r); } $conn->close(); } catch (Exception $e) { die($e->getMessage());
public function testGetDefaultBucketNameNotSet() { $this->expectGetDefaultBucketName(""); $this->expectApcFetch('__DEFAULT_GCS_BUCKET_NAME__', false, false); $bucket = CloudStorageTools::getDefaultGoogleStorageBucketName(); $this->assertEquals($bucket, ""); $this->apiProxyMock->verify(); }
public function delete() { $this->requiresLogin(); $user = Bootstrap::$main->user; $id = 0 + $this->id; $data = false; if ($id) { $data = $this->image()->get($id); } if (!$data) { $this->error(18); } if ($data['user'] != $user['id']) { $this->error(19); } if ($this->_appengine) { $file = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/' . $data['src']; CloudStorageTools::deleteImageServingUrl($file); } else { $file = $this->_media_dir . '/' . $data['src']; $ext = @end(explode('.', $file)); @unlink(preg_replace("/\\.{$ext}\$/", '-t.' . $ext, $file)); @unlink(preg_replace("/\\.{$ext}\$/", '-s.' . $ext, $file)); } @unlink($file); $this->image()->remove($data['id']); return $this->status(); }
<?php require_once __DIR__ . '/vendor/autoload.php'; use google\appengine\api\cloud_storage\CloudStorageTools; define('SLACK_URL', 'YOUR-TEAM.slack.com'); define('SLACK_TOKEN', 'YOUR-ACCESS-TOKEN'); // https://api.slack.com/web define('GOOGLE_MAPS_API_KEY', 'YOUR-GOOGLE-MAPS-KEY'); // https://developers.google.com/maps/documentation/javascript/get-api-key define('GOOGLE_ANALYTICS_TRACKING_ID', 'YOUR-GOOGLE-ANALYTICS-TRACKING-ID'); // https://support.google.com/analytics/answer/1008080?hl=en define('MARKERS_JS', 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/markers.js'); $smarty = new Smarty(); $smarty->setCompileDir('gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/templates_c'); $smarty->setTemplateDir(__DIR__); function smarty() { global $smarty; return $smarty; }
<?php require_once __DIR__ . '/../base.php'; use google\appengine\api\cloud_storage\CloudStorageTools; $base = __DIR__ . '/../../../media/log'; if (Bootstrap::$main->appengine) { require_once 'google/appengine/api/cloud_storage/CloudStorageTools.php'; $base = 'gs://' . CloudStorageTools::getDefaultGoogleStorageBucketName() . '/log'; } $ts = time() - 24 * 3600; $year = date('Y', $ts); $month = date('m', $ts); $day = date('d', $ts); foreach (scandir($base) as $component) { echo "Starting {$component}<br/>"; if ($component[0] == '.') { continue; } if (substr($component, -1) == '/') { $component = substr($component, 0, strlen($component) - 1); } $dir = "{$base}/{$component}/{$year}/{$month}/{$day}"; echo " Scaning dir {$dir}<br/>"; if (!file_exists($dir)) { echo " does not exist<br/>"; continue; } $log = ''; foreach (scandir($dir) as $f) { if ($f[0] == '.') { continue;