├── .gitattributes ├── assets ├── images │ ├── Map.PNG │ ├── blogs1.jpg │ ├── login.PNG │ ├── logo.jpg │ ├── logo.png │ ├── pic-1.png │ ├── pic-2.png │ ├── pic-3.png │ ├── pour.jpg │ ├── blogs2.avif │ ├── blogs3.webp │ ├── carbon.webp │ ├── favicon.ico │ ├── gallery1.jpg │ ├── gallery2.jpg │ ├── gallery3.jpg │ ├── gallery4.jpg │ ├── gallery5.jpg │ ├── gallery6.jpg │ ├── hero-img.png │ ├── logo-min.png │ ├── about-img.png │ ├── cart-item-1.png │ ├── cart-item-2.png │ ├── cart-item-3.png │ ├── cart-item-4.png │ ├── cart-item-5.png │ ├── cart-item-6.png │ ├── cart-item-7.png │ ├── cart-item-8.png │ ├── cart-item-9.png │ ├── coffeemaker.jpg │ ├── favicon_io.zip │ ├── hero-img1.png │ ├── pure-logo.png │ ├── quote-img.png │ ├── HifiWireframe.png │ ├── LofiWireframe.png │ ├── cart-item-10.png │ ├── cart-item-11.png │ ├── cart-item-12.png │ └── BrewVoyage Home Page.PNG ├── css │ ├── login.css │ └── convo.css └── js │ ├── responses.js │ ├── convo.js │ └── script.js ├── DATABASE ├── google-api-php-client-main.zip ├── google-api-php-client-main │ ├── src │ │ ├── Service │ │ │ ├── README.md │ │ │ └── Exception.php │ │ ├── Exception.php │ │ ├── Task │ │ │ ├── Exception.php │ │ │ ├── Retryable.php │ │ │ ├── Composer.php │ │ │ └── Runner.php │ │ ├── AuthHandler │ │ │ ├── Guzzle7AuthHandler.php │ │ │ ├── AuthHandlerFactory.php │ │ │ ├── Guzzle5AuthHandler.php │ │ │ └── Guzzle6AuthHandler.php │ │ ├── Service.php │ │ ├── AccessToken │ │ │ ├── Revoke.php │ │ │ └── Verify.php │ │ ├── Collection.php │ │ ├── aliases.php │ │ └── Http │ │ │ ├── REST.php │ │ │ └── Batch.php │ ├── SECURITY.md │ ├── composer.json │ ├── CHANGELOG.md │ └── LICENSE └── kapetann.sql ├── users ├── auth_session.php ├── logout.php ├── db.php ├── cart.php ├── set_session.php ├── add_to_database.php ├── registration.php └── login.php ├── google-client ├── src │ ├── Service │ │ ├── README.md │ │ └── Exception.php │ ├── Exception.php │ ├── Task │ │ ├── Exception.php │ │ ├── Retryable.php │ │ ├── Composer.php │ │ └── Runner.php │ ├── AuthHandler │ │ ├── Guzzle7AuthHandler.php │ │ ├── AuthHandlerFactory.php │ │ ├── Guzzle5AuthHandler.php │ │ └── Guzzle6AuthHandler.php │ ├── Service.php │ ├── AccessToken │ │ ├── Revoke.php │ │ └── Verify.php │ ├── Collection.php │ ├── aliases.php │ └── Http │ │ ├── REST.php │ │ ├── Batch.php │ │ └── MediaFileUpload.php ├── SECURITY.md ├── composer.json ├── CHANGELOG.md └── LICENSE └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /assets/images/Map.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/Map.PNG -------------------------------------------------------------------------------- /assets/images/blogs1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/blogs1.jpg -------------------------------------------------------------------------------- /assets/images/login.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/login.PNG -------------------------------------------------------------------------------- /assets/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/logo.jpg -------------------------------------------------------------------------------- /assets/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/logo.png -------------------------------------------------------------------------------- /assets/images/pic-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/pic-1.png -------------------------------------------------------------------------------- /assets/images/pic-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/pic-2.png -------------------------------------------------------------------------------- /assets/images/pic-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/pic-3.png -------------------------------------------------------------------------------- /assets/images/pour.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/pour.jpg -------------------------------------------------------------------------------- /assets/images/blogs2.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/blogs2.avif -------------------------------------------------------------------------------- /assets/images/blogs3.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/blogs3.webp -------------------------------------------------------------------------------- /assets/images/carbon.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/carbon.webp -------------------------------------------------------------------------------- /assets/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/favicon.ico -------------------------------------------------------------------------------- /assets/images/gallery1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery1.jpg -------------------------------------------------------------------------------- /assets/images/gallery2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery2.jpg -------------------------------------------------------------------------------- /assets/images/gallery3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery3.jpg -------------------------------------------------------------------------------- /assets/images/gallery4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery4.jpg -------------------------------------------------------------------------------- /assets/images/gallery5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery5.jpg -------------------------------------------------------------------------------- /assets/images/gallery6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/gallery6.jpg -------------------------------------------------------------------------------- /assets/images/hero-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/hero-img.png -------------------------------------------------------------------------------- /assets/images/logo-min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/logo-min.png -------------------------------------------------------------------------------- /assets/images/about-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/about-img.png -------------------------------------------------------------------------------- /assets/images/cart-item-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-1.png -------------------------------------------------------------------------------- /assets/images/cart-item-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-2.png -------------------------------------------------------------------------------- /assets/images/cart-item-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-3.png -------------------------------------------------------------------------------- /assets/images/cart-item-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-4.png -------------------------------------------------------------------------------- /assets/images/cart-item-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-5.png -------------------------------------------------------------------------------- /assets/images/cart-item-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-6.png -------------------------------------------------------------------------------- /assets/images/cart-item-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-7.png -------------------------------------------------------------------------------- /assets/images/cart-item-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-8.png -------------------------------------------------------------------------------- /assets/images/cart-item-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-9.png -------------------------------------------------------------------------------- /assets/images/coffeemaker.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/coffeemaker.jpg -------------------------------------------------------------------------------- /assets/images/favicon_io.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/favicon_io.zip -------------------------------------------------------------------------------- /assets/images/hero-img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/hero-img1.png -------------------------------------------------------------------------------- /assets/images/pure-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/pure-logo.png -------------------------------------------------------------------------------- /assets/images/quote-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/quote-img.png -------------------------------------------------------------------------------- /assets/images/HifiWireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/HifiWireframe.png -------------------------------------------------------------------------------- /assets/images/LofiWireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/LofiWireframe.png -------------------------------------------------------------------------------- /assets/images/cart-item-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-10.png -------------------------------------------------------------------------------- /assets/images/cart-item-11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-11.png -------------------------------------------------------------------------------- /assets/images/cart-item-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/cart-item-12.png -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/DATABASE/google-api-php-client-main.zip -------------------------------------------------------------------------------- /assets/images/BrewVoyage Home Page.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/itzzmerov/coffee-shop-website/HEAD/assets/images/BrewVoyage Home Page.PNG -------------------------------------------------------------------------------- /users/auth_session.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /users/logout.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /users/db.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /google-client/src/Service/README.md: -------------------------------------------------------------------------------- 1 | # Google API Client Services 2 | 3 | Google API Client Service classes have been moved to the 4 | [google-api-php-client-services](https://github.com/google/google-api-php-client-services) 5 | repository. 6 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Service/README.md: -------------------------------------------------------------------------------- 1 | # Google API Client Services 2 | 3 | Google API Client Service classes have been moved to the 4 | [google-api-php-client-services](https://github.com/google/google-api-php-client-services) 5 | repository. 6 | -------------------------------------------------------------------------------- /google-client/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). 4 | 5 | The Google Security Team will respond within 5 working days of your report on g.co/vulnz. 6 | 7 | We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. 8 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). 4 | 5 | The Google Security Team will respond within 5 working days of your report on g.co/vulnz. 6 | 7 | We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. 8 | -------------------------------------------------------------------------------- /users/cart.php: -------------------------------------------------------------------------------- 1 | query($sql); 18 | } 19 | 20 | // Close connection 21 | $conn->close(); 22 | ?> -------------------------------------------------------------------------------- /google-client/src/Exception.php: -------------------------------------------------------------------------------- 1 | '838321752460-6ah497tdpkbekj7lfj5so48suaqhu1e7.apps.googleusercontent.com']); 9 | $payload = $client->verifyIdToken($id_token); 10 | if ($payload) { 11 | $email = $payload['email']; 12 | $username = $payload['name']; 13 | 14 | // Check if the user exists in the database 15 | $query = "SELECT * FROM `users` WHERE email='$email'"; 16 | $result = mysqli_query($con, $query); 17 | $rows = mysqli_num_rows($result); 18 | if ($rows == 0) { 19 | // Insert the user into the database 20 | $query = "INSERT INTO `users` (username, email) VALUES ('$username', '$email')"; 21 | mysqli_query($con, $query); 22 | } 23 | 24 | // Set the user session 25 | $_SESSION['username'] = $username; 26 | 27 | echo 'success'; 28 | } else { 29 | echo 'error'; 30 | } 31 | ?> -------------------------------------------------------------------------------- /users/add_to_database.php: -------------------------------------------------------------------------------- 1 | query($sql1); 12 | while($row = $result->fetch_assoc()) { 13 | $id = $row['id']; 14 | } 15 | 16 | // Insert order details into database 17 | $date = date('Y-m-d'); 18 | foreach ($orderDetails as $order) { 19 | $title = $order['title']; 20 | $price = $order['price']; 21 | $quantity = $order['quantity']; 22 | $subtotalAmount = $order['subtotal_amount']; 23 | $invoiceNumber = $order['invoice_number']; 24 | $sql = "INSERT INTO orders (price, title, quantity, subtotal_amount, date, invoice_number, user_id) VALUES ('$price', '$title', '$quantity', '$subtotalAmount', '$date', '$invoiceNumber', '$id')"; 25 | if ($con->query($sql) !== TRUE) { 26 | echo "Error: " . $sql . "
" . $con->error; 27 | } 28 | } 29 | 30 | // Close database connection 31 | $con->close(); 32 | ?> -------------------------------------------------------------------------------- /assets/css/login.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #3e4144; 3 | } 4 | .form { 5 | margin: 50px auto; 6 | width: 300px; 7 | padding: 30px 25px; 8 | background: white; 9 | } 10 | h1.login-title { 11 | color: #666; 12 | margin: 0px auto 25px; 13 | font-size: 25px; 14 | font-weight: 300; 15 | text-align: center; 16 | } 17 | .login-input { 18 | font-size: 15px; 19 | border: 1px solid #ccc; 20 | padding: 10px; 21 | margin-bottom: 25px; 22 | height: 25px; 23 | width: calc(100% - 23px); 24 | } 25 | .login-input:focus { 26 | border-color:#6e8095; 27 | outline: none; 28 | } 29 | .login-button { 30 | color: #fff; 31 | background: #9F5C44; 32 | border: 0; 33 | outline: 0; 34 | width: 100%; 35 | height: 50px; 36 | font-size: 16px; 37 | text-align: center; 38 | cursor: pointer; 39 | } 40 | 41 | .login-button:hover { 42 | background-color: #64342C; 43 | letter-spacing: .2rem; 44 | } 45 | 46 | .link { 47 | color: #666; 48 | font-size: 15px; 49 | text-align: center; 50 | margin-bottom: 0px; 51 | } 52 | .link a { 53 | color: #666; 54 | } 55 | h3 { 56 | font-weight: normal; 57 | text-align: center; 58 | } 59 | 60 | img { 61 | max-width: 100px; 62 | max-height: 100px; 63 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KapeTann Coffee Shop Website 2 | 3 | > Welcome to **KapeTann**, a coffee lover's paradise! 4 | > 5 | >Discover a world of exquisite flavors as you embark on a flavorful journey with us. 6 | > 7 | > We source the finest coffee beans from around the globe, carefully roasting and brewing them to perfection. 8 | > 9 | > From our proprietary signature drink to unique concoctions like Lavender Lattes and Maple Bacon Cold Brews, our menu is a treasure trove of specialty beverages that will delight your taste buds. 10 | > 11 | > Join us at KapeTann, where every cup tells a story, and experience the joy of exceptional coffee. 12 | 13 | > WireFrame (High Fidelity): *[KapeTann Coffee Shop Website Wireframe](https://www.figma.com/file/77vsdTFufqsMQj03VRtIGc/KapeTann-High-Fidelity?t=LsyLSC9FSRG4u7TC-1)* 14 | 15 | > WireFrame (Low Fidelity): *[KapeTann Coffee Shop Website Wireframe](https://www.figma.com/file/NDQNu5CHehVBkNVGnLvztt/KapeTann-Low-Fidelity?t=LsyLSC9FSRG4u7TC-1)* 16 | 17 | > Website Link: *[KapeTann Coffee Shop Website](https://kapetanncoffeeshop.infinityfreeapp.com/)* 18 | 19 | [![kapeTann Login Page](/assets/images/login.PNG)](https://kapetanncoffeeshop.infinityfreeapp.com/) 20 | 21 | [![kapeTann Home Page](/assets/images/BrewVoyage%20Home%20Page.PNG)](https://kapetanncoffeeshop.infinityfreeapp.com/) 22 | -------------------------------------------------------------------------------- /google-client/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google/apiclient", 3 | "type": "library", 4 | "description": "Client library for Google APIs", 5 | "keywords": ["google"], 6 | "homepage": "http://developers.google.com/api-client-library/php", 7 | "license": "Apache-2.0", 8 | "require": { 9 | "php": "^5.6|^7.0|^8.0", 10 | "google/auth": "^1.10", 11 | "google/apiclient-services": "~0.200", 12 | "firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0", 13 | "monolog/monolog": "^1.17||^2.0||^3.0", 14 | "phpseclib/phpseclib": "~2.0||^3.0.2", 15 | "guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0", 16 | "guzzlehttp/psr7": "^1.8.4||^2.2.1" 17 | }, 18 | "require-dev": { 19 | "squizlabs/php_codesniffer": "^3.0", 20 | "symfony/dom-crawler": "~2.1", 21 | "symfony/css-selector": "~2.1", 22 | "cache/filesystem-adapter": "^0.3.2|^1.1", 23 | "phpcompatibility/php-compatibility": "^9.2", 24 | "composer/composer": "^1.10.22", 25 | "yoast/phpunit-polyfills": "^1.0", 26 | "phpspec/prophecy-phpunit": "^1.1||^2.0", 27 | "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" 28 | }, 29 | "suggest": { 30 | "cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Google\\": "src/" 35 | }, 36 | "files": [ 37 | "src/aliases.php" 38 | ], 39 | "classmap": [ 40 | "src/aliases.php" 41 | ] 42 | }, 43 | "extra": { 44 | "branch-alias": { 45 | "dev-main": "2.x-dev" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google/apiclient", 3 | "type": "library", 4 | "description": "Client library for Google APIs", 5 | "keywords": ["google"], 6 | "homepage": "http://developers.google.com/api-client-library/php", 7 | "license": "Apache-2.0", 8 | "require": { 9 | "php": "^5.6|^7.0|^8.0", 10 | "google/auth": "^1.10", 11 | "google/apiclient-services": "~0.200", 12 | "firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0", 13 | "monolog/monolog": "^1.17||^2.0||^3.0", 14 | "phpseclib/phpseclib": "~2.0||^3.0.2", 15 | "guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0", 16 | "guzzlehttp/psr7": "^1.8.4||^2.2.1" 17 | }, 18 | "require-dev": { 19 | "squizlabs/php_codesniffer": "^3.0", 20 | "symfony/dom-crawler": "~2.1", 21 | "symfony/css-selector": "~2.1", 22 | "cache/filesystem-adapter": "^0.3.2|^1.1", 23 | "phpcompatibility/php-compatibility": "^9.2", 24 | "composer/composer": "^1.10.22", 25 | "yoast/phpunit-polyfills": "^1.0", 26 | "phpspec/prophecy-phpunit": "^1.1||^2.0", 27 | "phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0" 28 | }, 29 | "suggest": { 30 | "cache/filesystem-adapter": "For caching certs and tokens (using Google\\Client::setCache)" 31 | }, 32 | "autoload": { 33 | "psr-4": { 34 | "Google\\": "src/" 35 | }, 36 | "files": [ 37 | "src/aliases.php" 38 | ], 39 | "classmap": [ 40 | "src/aliases.php" 41 | ] 42 | }, 43 | "extra": { 44 | "branch-alias": { 45 | "dev-main": "2.x-dev" 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /google-client/src/AuthHandler/AuthHandlerFactory.php: -------------------------------------------------------------------------------- 1 | client = $clientOrConfig; 38 | } elseif (is_array($clientOrConfig)) { 39 | $this->client = new Client($clientOrConfig ?: []); 40 | } else { 41 | $errorMessage = 'constructor must be array or instance of Google\Client'; 42 | if (class_exists('TypeError')) { 43 | throw new TypeError($errorMessage); 44 | } 45 | trigger_error($errorMessage, E_USER_ERROR); 46 | } 47 | } 48 | 49 | /** 50 | * Return the associated Google\Client class. 51 | * @return \Google\Client 52 | */ 53 | public function getClient() 54 | { 55 | return $this->client; 56 | } 57 | 58 | /** 59 | * Create a new HTTP Batch handler for this service 60 | * 61 | * @return Batch 62 | */ 63 | public function createBatch() 64 | { 65 | return new Batch( 66 | $this->client, 67 | false, 68 | $this->rootUrl, 69 | $this->batchPath 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Service.php: -------------------------------------------------------------------------------- 1 | client = $clientOrConfig; 38 | } elseif (is_array($clientOrConfig)) { 39 | $this->client = new Client($clientOrConfig ?: []); 40 | } else { 41 | $errorMessage = 'constructor must be array or instance of Google\Client'; 42 | if (class_exists('TypeError')) { 43 | throw new TypeError($errorMessage); 44 | } 45 | trigger_error($errorMessage, E_USER_ERROR); 46 | } 47 | } 48 | 49 | /** 50 | * Return the associated Google\Client class. 51 | * @return \Google\Client 52 | */ 53 | public function getClient() 54 | { 55 | return $this->client; 56 | } 57 | 58 | /** 59 | * Create a new HTTP Batch handler for this service 60 | * 61 | * @return Batch 62 | */ 63 | public function createBatch() 64 | { 65 | return new Batch( 66 | $this->client, 67 | false, 68 | $this->rootUrl, 69 | $this->batchPath 70 | ); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /google-client/src/Service/Exception.php: -------------------------------------------------------------------------------- 1 | >|null $errors List of errors returned in an HTTP 37 | * response or null. Defaults to []. 38 | */ 39 | public function __construct( 40 | $message, 41 | $code = 0, 42 | Exception $previous = null, 43 | $errors = [] 44 | ) { 45 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) { 46 | parent::__construct($message, $code, $previous); 47 | } else { 48 | parent::__construct($message, $code); 49 | } 50 | 51 | $this->errors = $errors; 52 | } 53 | 54 | /** 55 | * An example of the possible errors returned. 56 | * 57 | * [ 58 | * { 59 | * "domain": "global", 60 | * "reason": "authError", 61 | * "message": "Invalid Credentials", 62 | * "locationType": "header", 63 | * "location": "Authorization", 64 | * } 65 | * ] 66 | * 67 | * @return array>|null List of errors returned in an HTTP response or null. 68 | */ 69 | public function getErrors() 70 | { 71 | return $this->errors; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Service/Exception.php: -------------------------------------------------------------------------------- 1 | >|null $errors List of errors returned in an HTTP 37 | * response or null. Defaults to []. 38 | */ 39 | public function __construct( 40 | $message, 41 | $code = 0, 42 | Exception $previous = null, 43 | $errors = [] 44 | ) { 45 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) { 46 | parent::__construct($message, $code, $previous); 47 | } else { 48 | parent::__construct($message, $code); 49 | } 50 | 51 | $this->errors = $errors; 52 | } 53 | 54 | /** 55 | * An example of the possible errors returned. 56 | * 57 | * [ 58 | * { 59 | * "domain": "global", 60 | * "reason": "authError", 61 | * "message": "Invalid Credentials", 62 | * "locationType": "header", 63 | * "location": "Authorization", 64 | * } 65 | * ] 66 | * 67 | * @return array>|null List of errors returned in an HTTP response or null. 68 | */ 69 | public function getErrors() 70 | { 71 | return $this->errors; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /assets/js/responses.js: -------------------------------------------------------------------------------- 1 | function getBotResponse(input) { 2 | // Simple responses 3 | if (input == "hello") { 4 | return "Hello there! What can I do for you?"; 5 | } else if (input == "hi") { 6 | return "Hi there! What can I do for you?"; 7 | } else if (input == "commands") { 8 | return "Keywords/Commands:

menu - it will show our menu.
about - it will show the 'about us'.
contact- it will show 'contact info'.
commands - it will show 'keyword'.
how to order - it will show the instruction.
location - it will show our address."; 9 | } else if (input == "menu") { 10 | return "Here's our menu:

Americano - Hot Espresso (12 OZ) - ₱45.00
Caffe Latte - Steamed Milk (12 OZ) - ₱65.00
Salted Caramel Espresso (12 OZ) - ₱75.00
Cafe Mocha Espresso (12 OZ) - ₱75.00
Spanish Latte Espresso (12 OZ) - ₱75.00 "; 11 | } else if (input == "about") { 12 | return "Hi there!

KapeTann Brewed Coffee is a coffee shop and retailer in Zambales, Philippines."; 13 | } else if (input == "contact") { 14 | return "Here's our contact information:

Email: abfiguerrez18@gmail.com
Phone Number: 0917 134 1422
Messenger: @kapetanncoffee
Address: Laoag, San Marcelino, Zambales "; 15 | } else if (input == "how to order") { 16 | return "Hi There!

To order, you can go to our Menu section and click the button of your choice.

I hope you understand. Thank you so much!"; 17 | } else if (input == "location") { 18 | return "Here's our address: San Marcelino, Zambales 2207 Olongapo, Philippines"; 19 | 20 | /* 21 | } else if (input == "hi") { 22 | return "Hi there! What can I do for you?"; 23 | } else if (input == "hi") { 24 | return "Hi there! What can I do for you?"; 25 | } else if (input == "hi") { 26 | return "Hi there! What can I do for you?"; 27 | } else if (input == "hi") { 28 | return "Hi there! What can I do for you?"; 29 | } else if (input == "hi") { 30 | return "Hi there! What can I do for you?"; 31 | } else if (input == "hi") { 32 | return "Hi there! What can I do for you?"; 33 | } else if (input == "hi") { 34 | return "Hi there! What can I do for you?"; 35 | */ 36 | 37 | } else { 38 | return "Try asking something else!"; 39 | } 40 | } -------------------------------------------------------------------------------- /google-client/src/AccessToken/Revoke.php: -------------------------------------------------------------------------------- 1 | http = $http; 45 | } 46 | 47 | /** 48 | * Revoke an OAuth2 access token or refresh token. This method will revoke the current access 49 | * token, if a token isn't provided. 50 | * 51 | * @param string|array $token The token (access token or a refresh token) that should be revoked. 52 | * @return boolean Returns True if the revocation was successful, otherwise False. 53 | */ 54 | public function revokeToken($token) 55 | { 56 | if (is_array($token)) { 57 | if (isset($token['refresh_token'])) { 58 | $token = $token['refresh_token']; 59 | } else { 60 | $token = $token['access_token']; 61 | } 62 | } 63 | 64 | $body = Psr7\Utils::streamFor(http_build_query(['token' => $token])); 65 | $request = new Request( 66 | 'POST', 67 | Client::OAUTH2_REVOKE_URI, 68 | [ 69 | 'Cache-Control' => 'no-store', 70 | 'Content-Type' => 'application/x-www-form-urlencoded', 71 | ], 72 | $body 73 | ); 74 | 75 | $httpHandler = HttpHandlerFactory::build($this->http); 76 | 77 | $response = $httpHandler($request); 78 | 79 | return $response->getStatusCode() == 200; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/AccessToken/Revoke.php: -------------------------------------------------------------------------------- 1 | http = $http; 45 | } 46 | 47 | /** 48 | * Revoke an OAuth2 access token or refresh token. This method will revoke the current access 49 | * token, if a token isn't provided. 50 | * 51 | * @param string|array $token The token (access token or a refresh token) that should be revoked. 52 | * @return boolean Returns True if the revocation was successful, otherwise False. 53 | */ 54 | public function revokeToken($token) 55 | { 56 | if (is_array($token)) { 57 | if (isset($token['refresh_token'])) { 58 | $token = $token['refresh_token']; 59 | } else { 60 | $token = $token['access_token']; 61 | } 62 | } 63 | 64 | $body = Psr7\Utils::streamFor(http_build_query(['token' => $token])); 65 | $request = new Request( 66 | 'POST', 67 | Client::OAUTH2_REVOKE_URI, 68 | [ 69 | 'Cache-Control' => 'no-store', 70 | 'Content-Type' => 'application/x-www-form-urlencoded', 71 | ], 72 | $body 73 | ); 74 | 75 | $httpHandler = HttpHandlerFactory::build($this->http); 76 | 77 | $response = $httpHandler($request); 78 | 79 | return $response->getStatusCode() == 200; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /users/registration.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | KapeTann | Registration Form 7 | 8 | 9 | 10 | 11 | 31 | alert('You are registered successfully.'); 32 | window.location.href = 'login.php'; 33 | "; 34 | } else { 35 | echo "
36 |

Required fields are missing.


37 | 38 |
"; 39 | } 40 | } else { 41 | ?> 42 |
43 |
44 | 45 |
46 |
47 |

Registration

48 | 49 | 50 | 51 | 52 | 53 | 54 |
55 | 58 | 59 | -------------------------------------------------------------------------------- /assets/js/convo.js: -------------------------------------------------------------------------------- 1 | // Collapsible 2 | var coll = document.getElementsByClassName("collapsible"); 3 | 4 | for (let i = 0; i < coll.length; i++) { 5 | coll[i].addEventListener("click", function () { 6 | this.classList.toggle("active"); 7 | 8 | var content = this.nextElementSibling; 9 | 10 | if (content.style.maxHeight) { 11 | content.style.maxHeight = null; 12 | } else { 13 | content.style.maxHeight = content.scrollHeight + "px"; 14 | } 15 | 16 | }); 17 | } 18 | 19 | function getTime() { 20 | let today = new Date(); 21 | hours = today.getHours(); 22 | minutes = today.getMinutes(); 23 | 24 | if (hours < 10) { 25 | hours = "0" + hours; 26 | } 27 | 28 | if (minutes < 10) { 29 | minutes = "0" + minutes; 30 | } 31 | 32 | let time = hours + ":" + minutes; 33 | return time; 34 | } 35 | 36 | // Gets the first message 37 | function firstBotMessage() { 38 | let firstMessage = "Keywords/Commands:

menu - it will show our menu.
about - it will show the 'about us'.
contact- it will show 'contact info'.
commands - it will show 'keyword'.
how to order - it will show the instruction.
location - it will show our address." 39 | document.getElementById("botStarterMessage").innerHTML = '

' + firstMessage + '

'; 40 | 41 | let time = getTime(); 42 | 43 | $("#chat-timestamp").append(time); 44 | document.getElementById("userInput").scrollIntoView(false); 45 | } 46 | 47 | firstBotMessage(); 48 | 49 | // Retrieves the response 50 | function getHardResponse(userText) { 51 | let botResponse = getBotResponse(userText); 52 | let botHtml = '

' + botResponse + '

'; 53 | $("#chatbox").append(botHtml); 54 | 55 | document.getElementById("chat-bar-bottom").scrollIntoView(true); 56 | } 57 | 58 | //Gets the text text from the input box and processes it 59 | function getResponse() { 60 | let userText = $("#textInput").val().toLowerCase(); 61 | 62 | if (userText == "") { 63 | alert('Please enter something!'); 64 | return; 65 | } 66 | 67 | let userHtml = '

' + userText + '

'; 68 | 69 | $("#textInput").val(""); 70 | $("#chatbox").append(userHtml); 71 | document.getElementById("chat-bar-bottom").scrollIntoView(true); 72 | 73 | setTimeout(() => { 74 | getHardResponse(userText); 75 | }, 1000) 76 | 77 | } 78 | 79 | // Handles sending text via button clicks 80 | function buttonSendText(sampleText) { 81 | let userHtml = '

' + sampleText + '

'; 82 | 83 | $("#textInput").val(""); 84 | $("#chatbox").append(userHtml); 85 | document.getElementById("chat-bar-bottom").scrollIntoView(true); 86 | 87 | //Uncomment this if you want the bot to respond to this buttonSendText event 88 | // setTimeout(() => { 89 | // getHardResponse(sampleText); 90 | // }, 1000) 91 | } 92 | 93 | function sendButton() { 94 | getResponse(); 95 | } 96 | 97 | function heartButton() { 98 | buttonSendText("Heart clicked!") 99 | } 100 | 101 | // Press enter to send a message 102 | $("#textInput").keypress(function (e) { 103 | if (e.which == 13) { 104 | getResponse(); 105 | } 106 | }); -------------------------------------------------------------------------------- /google-client/src/AuthHandler/Guzzle5AuthHandler.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 26 | $this->cacheConfig = $cacheConfig; 27 | } 28 | 29 | public function attachCredentials( 30 | ClientInterface $http, 31 | CredentialsLoader $credentials, 32 | callable $tokenCallback = null 33 | ) { 34 | // use the provided cache 35 | if ($this->cache) { 36 | $credentials = new FetchAuthTokenCache( 37 | $credentials, 38 | $this->cacheConfig, 39 | $this->cache 40 | ); 41 | } 42 | 43 | return $this->attachCredentialsCache($http, $credentials, $tokenCallback); 44 | } 45 | 46 | public function attachCredentialsCache( 47 | ClientInterface $http, 48 | FetchAuthTokenCache $credentials, 49 | callable $tokenCallback = null 50 | ) { 51 | // if we end up needing to make an HTTP request to retrieve credentials, we 52 | // can use our existing one, but we need to throw exceptions so the error 53 | // bubbles up. 54 | $authHttp = $this->createAuthHttp($http); 55 | $authHttpHandler = HttpHandlerFactory::build($authHttp); 56 | $subscriber = new AuthTokenSubscriber( 57 | $credentials, 58 | $authHttpHandler, 59 | $tokenCallback 60 | ); 61 | 62 | $http->setDefaultOption('auth', 'google_auth'); 63 | $http->getEmitter()->attach($subscriber); 64 | 65 | return $http; 66 | } 67 | 68 | public function attachToken(ClientInterface $http, array $token, array $scopes) 69 | { 70 | $tokenFunc = function ($scopes) use ($token) { 71 | return $token['access_token']; 72 | }; 73 | 74 | $subscriber = new ScopedAccessTokenSubscriber( 75 | $tokenFunc, 76 | $scopes, 77 | $this->cacheConfig, 78 | $this->cache 79 | ); 80 | 81 | $http->setDefaultOption('auth', 'scoped'); 82 | $http->getEmitter()->attach($subscriber); 83 | 84 | return $http; 85 | } 86 | 87 | public function attachKey(ClientInterface $http, $key) 88 | { 89 | $subscriber = new SimpleSubscriber(['key' => $key]); 90 | 91 | $http->setDefaultOption('auth', 'simple'); 92 | $http->getEmitter()->attach($subscriber); 93 | 94 | return $http; 95 | } 96 | 97 | private function createAuthHttp(ClientInterface $http) 98 | { 99 | return new Client([ 100 | 'base_url' => $http->getBaseUrl(), 101 | 'defaults' => [ 102 | 'exceptions' => true, 103 | 'verify' => $http->getDefaultOption('verify'), 104 | 'proxy' => $http->getDefaultOption('proxy'), 105 | ] 106 | ]); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/AuthHandler/Guzzle5AuthHandler.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 26 | $this->cacheConfig = $cacheConfig; 27 | } 28 | 29 | public function attachCredentials( 30 | ClientInterface $http, 31 | CredentialsLoader $credentials, 32 | callable $tokenCallback = null 33 | ) { 34 | // use the provided cache 35 | if ($this->cache) { 36 | $credentials = new FetchAuthTokenCache( 37 | $credentials, 38 | $this->cacheConfig, 39 | $this->cache 40 | ); 41 | } 42 | 43 | return $this->attachCredentialsCache($http, $credentials, $tokenCallback); 44 | } 45 | 46 | public function attachCredentialsCache( 47 | ClientInterface $http, 48 | FetchAuthTokenCache $credentials, 49 | callable $tokenCallback = null 50 | ) { 51 | // if we end up needing to make an HTTP request to retrieve credentials, we 52 | // can use our existing one, but we need to throw exceptions so the error 53 | // bubbles up. 54 | $authHttp = $this->createAuthHttp($http); 55 | $authHttpHandler = HttpHandlerFactory::build($authHttp); 56 | $subscriber = new AuthTokenSubscriber( 57 | $credentials, 58 | $authHttpHandler, 59 | $tokenCallback 60 | ); 61 | 62 | $http->setDefaultOption('auth', 'google_auth'); 63 | $http->getEmitter()->attach($subscriber); 64 | 65 | return $http; 66 | } 67 | 68 | public function attachToken(ClientInterface $http, array $token, array $scopes) 69 | { 70 | $tokenFunc = function ($scopes) use ($token) { 71 | return $token['access_token']; 72 | }; 73 | 74 | $subscriber = new ScopedAccessTokenSubscriber( 75 | $tokenFunc, 76 | $scopes, 77 | $this->cacheConfig, 78 | $this->cache 79 | ); 80 | 81 | $http->setDefaultOption('auth', 'scoped'); 82 | $http->getEmitter()->attach($subscriber); 83 | 84 | return $http; 85 | } 86 | 87 | public function attachKey(ClientInterface $http, $key) 88 | { 89 | $subscriber = new SimpleSubscriber(['key' => $key]); 90 | 91 | $http->setDefaultOption('auth', 'simple'); 92 | $http->getEmitter()->attach($subscriber); 93 | 94 | return $http; 95 | } 96 | 97 | private function createAuthHttp(ClientInterface $http) 98 | { 99 | return new Client([ 100 | 'base_url' => $http->getBaseUrl(), 101 | 'defaults' => [ 102 | 'exceptions' => true, 103 | 'verify' => $http->getDefaultOption('verify'), 104 | 'proxy' => $http->getDefaultOption('proxy'), 105 | ] 106 | ]); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /google-client/src/Collection.php: -------------------------------------------------------------------------------- 1 | {$this->collection_key}) 20 | && is_array($this->{$this->collection_key}) 21 | ) { 22 | reset($this->{$this->collection_key}); 23 | } 24 | } 25 | 26 | /** @return mixed */ 27 | #[\ReturnTypeWillChange] 28 | public function current() 29 | { 30 | $this->coerceType($this->key()); 31 | if (is_array($this->{$this->collection_key})) { 32 | return current($this->{$this->collection_key}); 33 | } 34 | } 35 | 36 | /** @return mixed */ 37 | #[\ReturnTypeWillChange] 38 | public function key() 39 | { 40 | if ( 41 | isset($this->{$this->collection_key}) 42 | && is_array($this->{$this->collection_key}) 43 | ) { 44 | return key($this->{$this->collection_key}); 45 | } 46 | } 47 | 48 | /** @return mixed */ 49 | #[\ReturnTypeWillChange] 50 | public function next() 51 | { 52 | return next($this->{$this->collection_key}); 53 | } 54 | 55 | /** @return bool */ 56 | #[\ReturnTypeWillChange] 57 | public function valid() 58 | { 59 | $key = $this->key(); 60 | return $key !== null && $key !== false; 61 | } 62 | 63 | /** @return int */ 64 | #[\ReturnTypeWillChange] 65 | public function count() 66 | { 67 | if (!isset($this->{$this->collection_key})) { 68 | return 0; 69 | } 70 | return count($this->{$this->collection_key}); 71 | } 72 | 73 | /** @return bool */ 74 | #[\ReturnTypeWillChange] 75 | public function offsetExists($offset) 76 | { 77 | if (!is_numeric($offset)) { 78 | return parent::offsetExists($offset); 79 | } 80 | return isset($this->{$this->collection_key}[$offset]); 81 | } 82 | 83 | /** @return mixed */ 84 | public function offsetGet($offset) 85 | { 86 | if (!is_numeric($offset)) { 87 | return parent::offsetGet($offset); 88 | } 89 | $this->coerceType($offset); 90 | return $this->{$this->collection_key}[$offset]; 91 | } 92 | 93 | /** @return void */ 94 | #[\ReturnTypeWillChange] 95 | public function offsetSet($offset, $value) 96 | { 97 | if (!is_numeric($offset)) { 98 | parent::offsetSet($offset, $value); 99 | } 100 | $this->{$this->collection_key}[$offset] = $value; 101 | } 102 | 103 | /** @return void */ 104 | #[\ReturnTypeWillChange] 105 | public function offsetUnset($offset) 106 | { 107 | if (!is_numeric($offset)) { 108 | parent::offsetUnset($offset); 109 | } 110 | unset($this->{$this->collection_key}[$offset]); 111 | } 112 | 113 | private function coerceType($offset) 114 | { 115 | $keyType = $this->keyType($this->collection_key); 116 | if ($keyType && !is_object($this->{$this->collection_key}[$offset])) { 117 | $this->{$this->collection_key}[$offset] = 118 | new $keyType($this->{$this->collection_key}[$offset]); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Collection.php: -------------------------------------------------------------------------------- 1 | {$this->collection_key}) 20 | && is_array($this->{$this->collection_key}) 21 | ) { 22 | reset($this->{$this->collection_key}); 23 | } 24 | } 25 | 26 | /** @return mixed */ 27 | #[\ReturnTypeWillChange] 28 | public function current() 29 | { 30 | $this->coerceType($this->key()); 31 | if (is_array($this->{$this->collection_key})) { 32 | return current($this->{$this->collection_key}); 33 | } 34 | } 35 | 36 | /** @return mixed */ 37 | #[\ReturnTypeWillChange] 38 | public function key() 39 | { 40 | if ( 41 | isset($this->{$this->collection_key}) 42 | && is_array($this->{$this->collection_key}) 43 | ) { 44 | return key($this->{$this->collection_key}); 45 | } 46 | } 47 | 48 | /** @return mixed */ 49 | #[\ReturnTypeWillChange] 50 | public function next() 51 | { 52 | return next($this->{$this->collection_key}); 53 | } 54 | 55 | /** @return bool */ 56 | #[\ReturnTypeWillChange] 57 | public function valid() 58 | { 59 | $key = $this->key(); 60 | return $key !== null && $key !== false; 61 | } 62 | 63 | /** @return int */ 64 | #[\ReturnTypeWillChange] 65 | public function count() 66 | { 67 | if (!isset($this->{$this->collection_key})) { 68 | return 0; 69 | } 70 | return count($this->{$this->collection_key}); 71 | } 72 | 73 | /** @return bool */ 74 | #[\ReturnTypeWillChange] 75 | public function offsetExists($offset) 76 | { 77 | if (!is_numeric($offset)) { 78 | return parent::offsetExists($offset); 79 | } 80 | return isset($this->{$this->collection_key}[$offset]); 81 | } 82 | 83 | /** @return mixed */ 84 | public function offsetGet($offset) 85 | { 86 | if (!is_numeric($offset)) { 87 | return parent::offsetGet($offset); 88 | } 89 | $this->coerceType($offset); 90 | return $this->{$this->collection_key}[$offset]; 91 | } 92 | 93 | /** @return void */ 94 | #[\ReturnTypeWillChange] 95 | public function offsetSet($offset, $value) 96 | { 97 | if (!is_numeric($offset)) { 98 | parent::offsetSet($offset, $value); 99 | } 100 | $this->{$this->collection_key}[$offset] = $value; 101 | } 102 | 103 | /** @return void */ 104 | #[\ReturnTypeWillChange] 105 | public function offsetUnset($offset) 106 | { 107 | if (!is_numeric($offset)) { 108 | parent::offsetUnset($offset); 109 | } 110 | unset($this->{$this->collection_key}[$offset]); 111 | } 112 | 113 | private function coerceType($offset) 114 | { 115 | $keyType = $this->keyType($this->collection_key); 116 | if ($keyType && !is_object($this->{$this->collection_key}[$offset])) { 117 | $this->{$this->collection_key}[$offset] = 118 | new $keyType($this->{$this->collection_key}[$offset]); 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /google-client/src/AuthHandler/Guzzle6AuthHandler.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 26 | $this->cacheConfig = $cacheConfig; 27 | } 28 | 29 | public function attachCredentials( 30 | ClientInterface $http, 31 | CredentialsLoader $credentials, 32 | callable $tokenCallback = null 33 | ) { 34 | // use the provided cache 35 | if ($this->cache) { 36 | $credentials = new FetchAuthTokenCache( 37 | $credentials, 38 | $this->cacheConfig, 39 | $this->cache 40 | ); 41 | } 42 | 43 | return $this->attachCredentialsCache($http, $credentials, $tokenCallback); 44 | } 45 | 46 | public function attachCredentialsCache( 47 | ClientInterface $http, 48 | FetchAuthTokenCache $credentials, 49 | callable $tokenCallback = null 50 | ) { 51 | // if we end up needing to make an HTTP request to retrieve credentials, we 52 | // can use our existing one, but we need to throw exceptions so the error 53 | // bubbles up. 54 | $authHttp = $this->createAuthHttp($http); 55 | $authHttpHandler = HttpHandlerFactory::build($authHttp); 56 | $middleware = new AuthTokenMiddleware( 57 | $credentials, 58 | $authHttpHandler, 59 | $tokenCallback 60 | ); 61 | 62 | $config = $http->getConfig(); 63 | $config['handler']->remove('google_auth'); 64 | $config['handler']->push($middleware, 'google_auth'); 65 | $config['auth'] = 'google_auth'; 66 | $http = new Client($config); 67 | 68 | return $http; 69 | } 70 | 71 | public function attachToken(ClientInterface $http, array $token, array $scopes) 72 | { 73 | $tokenFunc = function ($scopes) use ($token) { 74 | return $token['access_token']; 75 | }; 76 | 77 | $middleware = new ScopedAccessTokenMiddleware( 78 | $tokenFunc, 79 | $scopes, 80 | $this->cacheConfig, 81 | $this->cache 82 | ); 83 | 84 | $config = $http->getConfig(); 85 | $config['handler']->remove('google_auth'); 86 | $config['handler']->push($middleware, 'google_auth'); 87 | $config['auth'] = 'scoped'; 88 | $http = new Client($config); 89 | 90 | return $http; 91 | } 92 | 93 | public function attachKey(ClientInterface $http, $key) 94 | { 95 | $middleware = new SimpleMiddleware(['key' => $key]); 96 | 97 | $config = $http->getConfig(); 98 | $config['handler']->remove('google_auth'); 99 | $config['handler']->push($middleware, 'google_auth'); 100 | $config['auth'] = 'simple'; 101 | $http = new Client($config); 102 | 103 | return $http; 104 | } 105 | 106 | private function createAuthHttp(ClientInterface $http) 107 | { 108 | return new Client(['http_errors' => true] + $http->getConfig()); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/AuthHandler/Guzzle6AuthHandler.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 26 | $this->cacheConfig = $cacheConfig; 27 | } 28 | 29 | public function attachCredentials( 30 | ClientInterface $http, 31 | CredentialsLoader $credentials, 32 | callable $tokenCallback = null 33 | ) { 34 | // use the provided cache 35 | if ($this->cache) { 36 | $credentials = new FetchAuthTokenCache( 37 | $credentials, 38 | $this->cacheConfig, 39 | $this->cache 40 | ); 41 | } 42 | 43 | return $this->attachCredentialsCache($http, $credentials, $tokenCallback); 44 | } 45 | 46 | public function attachCredentialsCache( 47 | ClientInterface $http, 48 | FetchAuthTokenCache $credentials, 49 | callable $tokenCallback = null 50 | ) { 51 | // if we end up needing to make an HTTP request to retrieve credentials, we 52 | // can use our existing one, but we need to throw exceptions so the error 53 | // bubbles up. 54 | $authHttp = $this->createAuthHttp($http); 55 | $authHttpHandler = HttpHandlerFactory::build($authHttp); 56 | $middleware = new AuthTokenMiddleware( 57 | $credentials, 58 | $authHttpHandler, 59 | $tokenCallback 60 | ); 61 | 62 | $config = $http->getConfig(); 63 | $config['handler']->remove('google_auth'); 64 | $config['handler']->push($middleware, 'google_auth'); 65 | $config['auth'] = 'google_auth'; 66 | $http = new Client($config); 67 | 68 | return $http; 69 | } 70 | 71 | public function attachToken(ClientInterface $http, array $token, array $scopes) 72 | { 73 | $tokenFunc = function ($scopes) use ($token) { 74 | return $token['access_token']; 75 | }; 76 | 77 | $middleware = new ScopedAccessTokenMiddleware( 78 | $tokenFunc, 79 | $scopes, 80 | $this->cacheConfig, 81 | $this->cache 82 | ); 83 | 84 | $config = $http->getConfig(); 85 | $config['handler']->remove('google_auth'); 86 | $config['handler']->push($middleware, 'google_auth'); 87 | $config['auth'] = 'scoped'; 88 | $http = new Client($config); 89 | 90 | return $http; 91 | } 92 | 93 | public function attachKey(ClientInterface $http, $key) 94 | { 95 | $middleware = new SimpleMiddleware(['key' => $key]); 96 | 97 | $config = $http->getConfig(); 98 | $config['handler']->remove('google_auth'); 99 | $config['handler']->push($middleware, 'google_auth'); 100 | $config['auth'] = 'simple'; 101 | $http = new Client($config); 102 | 103 | return $http; 104 | } 105 | 106 | private function createAuthHttp(ClientInterface $http) 107 | { 108 | return new Client(['http_errors' => true] + $http->getConfig()); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /google-client/src/aliases.php: -------------------------------------------------------------------------------- 1 | 'Google_Client', 11 | 'Google\\Service' => 'Google_Service', 12 | 'Google\\AccessToken\\Revoke' => 'Google_AccessToken_Revoke', 13 | 'Google\\AccessToken\\Verify' => 'Google_AccessToken_Verify', 14 | 'Google\\Model' => 'Google_Model', 15 | 'Google\\Utils\\UriTemplate' => 'Google_Utils_UriTemplate', 16 | 'Google\\AuthHandler\\Guzzle6AuthHandler' => 'Google_AuthHandler_Guzzle6AuthHandler', 17 | 'Google\\AuthHandler\\Guzzle7AuthHandler' => 'Google_AuthHandler_Guzzle7AuthHandler', 18 | 'Google\\AuthHandler\\Guzzle5AuthHandler' => 'Google_AuthHandler_Guzzle5AuthHandler', 19 | 'Google\\AuthHandler\\AuthHandlerFactory' => 'Google_AuthHandler_AuthHandlerFactory', 20 | 'Google\\Http\\Batch' => 'Google_Http_Batch', 21 | 'Google\\Http\\MediaFileUpload' => 'Google_Http_MediaFileUpload', 22 | 'Google\\Http\\REST' => 'Google_Http_REST', 23 | 'Google\\Task\\Retryable' => 'Google_Task_Retryable', 24 | 'Google\\Task\\Exception' => 'Google_Task_Exception', 25 | 'Google\\Task\\Runner' => 'Google_Task_Runner', 26 | 'Google\\Collection' => 'Google_Collection', 27 | 'Google\\Service\\Exception' => 'Google_Service_Exception', 28 | 'Google\\Service\\Resource' => 'Google_Service_Resource', 29 | 'Google\\Exception' => 'Google_Exception', 30 | ]; 31 | 32 | foreach ($classMap as $class => $alias) { 33 | class_alias($class, $alias); 34 | } 35 | 36 | /** 37 | * This class needs to be defined explicitly as scripts must be recognized by 38 | * the autoloader. 39 | */ 40 | class Google_Task_Composer extends \Google\Task\Composer 41 | { 42 | } 43 | 44 | /** @phpstan-ignore-next-line */ 45 | if (\false) { 46 | class Google_AccessToken_Revoke extends \Google\AccessToken\Revoke 47 | { 48 | } 49 | class Google_AccessToken_Verify extends \Google\AccessToken\Verify 50 | { 51 | } 52 | class Google_AuthHandler_AuthHandlerFactory extends \Google\AuthHandler\AuthHandlerFactory 53 | { 54 | } 55 | class Google_AuthHandler_Guzzle5AuthHandler extends \Google\AuthHandler\Guzzle5AuthHandler 56 | { 57 | } 58 | class Google_AuthHandler_Guzzle6AuthHandler extends \Google\AuthHandler\Guzzle6AuthHandler 59 | { 60 | } 61 | class Google_AuthHandler_Guzzle7AuthHandler extends \Google\AuthHandler\Guzzle7AuthHandler 62 | { 63 | } 64 | class Google_Client extends \Google\Client 65 | { 66 | } 67 | class Google_Collection extends \Google\Collection 68 | { 69 | } 70 | class Google_Exception extends \Google\Exception 71 | { 72 | } 73 | class Google_Http_Batch extends \Google\Http\Batch 74 | { 75 | } 76 | class Google_Http_MediaFileUpload extends \Google\Http\MediaFileUpload 77 | { 78 | } 79 | class Google_Http_REST extends \Google\Http\REST 80 | { 81 | } 82 | class Google_Model extends \Google\Model 83 | { 84 | } 85 | class Google_Service extends \Google\Service 86 | { 87 | } 88 | class Google_Service_Exception extends \Google\Service\Exception 89 | { 90 | } 91 | class Google_Service_Resource extends \Google\Service\Resource 92 | { 93 | } 94 | class Google_Task_Exception extends \Google\Task\Exception 95 | { 96 | } 97 | interface Google_Task_Retryable extends \Google\Task\Retryable 98 | { 99 | } 100 | class Google_Task_Runner extends \Google\Task\Runner 101 | { 102 | } 103 | class Google_Utils_UriTemplate extends \Google\Utils\UriTemplate 104 | { 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/aliases.php: -------------------------------------------------------------------------------- 1 | 'Google_Client', 11 | 'Google\\Service' => 'Google_Service', 12 | 'Google\\AccessToken\\Revoke' => 'Google_AccessToken_Revoke', 13 | 'Google\\AccessToken\\Verify' => 'Google_AccessToken_Verify', 14 | 'Google\\Model' => 'Google_Model', 15 | 'Google\\Utils\\UriTemplate' => 'Google_Utils_UriTemplate', 16 | 'Google\\AuthHandler\\Guzzle6AuthHandler' => 'Google_AuthHandler_Guzzle6AuthHandler', 17 | 'Google\\AuthHandler\\Guzzle7AuthHandler' => 'Google_AuthHandler_Guzzle7AuthHandler', 18 | 'Google\\AuthHandler\\Guzzle5AuthHandler' => 'Google_AuthHandler_Guzzle5AuthHandler', 19 | 'Google\\AuthHandler\\AuthHandlerFactory' => 'Google_AuthHandler_AuthHandlerFactory', 20 | 'Google\\Http\\Batch' => 'Google_Http_Batch', 21 | 'Google\\Http\\MediaFileUpload' => 'Google_Http_MediaFileUpload', 22 | 'Google\\Http\\REST' => 'Google_Http_REST', 23 | 'Google\\Task\\Retryable' => 'Google_Task_Retryable', 24 | 'Google\\Task\\Exception' => 'Google_Task_Exception', 25 | 'Google\\Task\\Runner' => 'Google_Task_Runner', 26 | 'Google\\Collection' => 'Google_Collection', 27 | 'Google\\Service\\Exception' => 'Google_Service_Exception', 28 | 'Google\\Service\\Resource' => 'Google_Service_Resource', 29 | 'Google\\Exception' => 'Google_Exception', 30 | ]; 31 | 32 | foreach ($classMap as $class => $alias) { 33 | class_alias($class, $alias); 34 | } 35 | 36 | /** 37 | * This class needs to be defined explicitly as scripts must be recognized by 38 | * the autoloader. 39 | */ 40 | class Google_Task_Composer extends \Google\Task\Composer 41 | { 42 | } 43 | 44 | /** @phpstan-ignore-next-line */ 45 | if (\false) { 46 | class Google_AccessToken_Revoke extends \Google\AccessToken\Revoke 47 | { 48 | } 49 | class Google_AccessToken_Verify extends \Google\AccessToken\Verify 50 | { 51 | } 52 | class Google_AuthHandler_AuthHandlerFactory extends \Google\AuthHandler\AuthHandlerFactory 53 | { 54 | } 55 | class Google_AuthHandler_Guzzle5AuthHandler extends \Google\AuthHandler\Guzzle5AuthHandler 56 | { 57 | } 58 | class Google_AuthHandler_Guzzle6AuthHandler extends \Google\AuthHandler\Guzzle6AuthHandler 59 | { 60 | } 61 | class Google_AuthHandler_Guzzle7AuthHandler extends \Google\AuthHandler\Guzzle7AuthHandler 62 | { 63 | } 64 | class Google_Client extends \Google\Client 65 | { 66 | } 67 | class Google_Collection extends \Google\Collection 68 | { 69 | } 70 | class Google_Exception extends \Google\Exception 71 | { 72 | } 73 | class Google_Http_Batch extends \Google\Http\Batch 74 | { 75 | } 76 | class Google_Http_MediaFileUpload extends \Google\Http\MediaFileUpload 77 | { 78 | } 79 | class Google_Http_REST extends \Google\Http\REST 80 | { 81 | } 82 | class Google_Model extends \Google\Model 83 | { 84 | } 85 | class Google_Service extends \Google\Service 86 | { 87 | } 88 | class Google_Service_Exception extends \Google\Service\Exception 89 | { 90 | } 91 | class Google_Service_Resource extends \Google\Service\Resource 92 | { 93 | } 94 | class Google_Task_Exception extends \Google\Task\Exception 95 | { 96 | } 97 | interface Google_Task_Retryable extends \Google\Task\Retryable 98 | { 99 | } 100 | class Google_Task_Runner extends \Google\Task\Runner 101 | { 102 | } 103 | class Google_Utils_UriTemplate extends \Google\Utils\UriTemplate 104 | { 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /DATABASE/kapetann.sql: -------------------------------------------------------------------------------- 1 | -- phpMyAdmin SQL Dump 2 | -- version 5.2.0 3 | -- https://www.phpmyadmin.net/ 4 | -- 5 | -- Host: 127.0.0.1 6 | -- Generation Time: Apr 21, 2023 at 08:02 AM 7 | -- Server version: 10.4.25-MariaDB 8 | -- PHP Version: 8.1.10 9 | 10 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 11 | START TRANSACTION; 12 | SET time_zone = "+00:00"; 13 | 14 | 15 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 16 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 17 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 18 | /*!40101 SET NAMES utf8mb4 */; 19 | 20 | -- 21 | -- Database: `kapetann` 22 | -- 23 | 24 | -- -------------------------------------------------------- 25 | 26 | -- 27 | -- Table structure for table `orders` 28 | -- 29 | 30 | CREATE TABLE `orders` ( 31 | `id` int(11) NOT NULL, 32 | `price` decimal(10,2) NOT NULL, 33 | `title` varchar(100) NOT NULL, 34 | `quantity` int(11) NOT NULL, 35 | `subtotal_amount` decimal(10,2) NOT NULL, 36 | `date` date NOT NULL, 37 | `invoice_number` varchar(100) NOT NULL, 38 | `user_id` int(11) NOT NULL 39 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 40 | 41 | -- 42 | -- Dumping data for table `orders` 43 | -- 44 | 45 | INSERT INTO `orders` (`id`, `price`, `title`, `quantity`, `subtotal_amount`, `date`, `invoice_number`, `user_id`) VALUES 46 | (1, '40.00', 'COLOMBIAN SUPREMO CUP (12 OZ)', 1, '40.00', '2023-04-21', 'INV-760084', 0), 47 | (2, '45.00', 'AMERICANO - HOT ESPRESSO (12 OZ)', 1, '45.00', '2023-04-21', 'INV-760084', 0), 48 | (3, '40.00', 'COLOMBIAN SUPREMO CUP (12 OZ)', 1, '40.00', '2023-04-21', 'INV-174394', 2), 49 | (4, '50.00', 'NITRO COLD BREW W/ STRAW (12 OZ)', 1, '50.00', '2023-04-21', 'INV-741371', 2), 50 | (5, '45.00', 'AMERICANO - HOT ESPRESSO (12 OZ)', 1, '45.00', '2023-04-21', 'INV-982020', 2), 51 | (6, '40.00', 'COLOMBIAN SUPREMO CUP (12 OZ)', 1, '40.00', '2023-04-21', 'INV-144116', 2); 52 | 53 | -- -------------------------------------------------------- 54 | 55 | -- 56 | -- Table structure for table `users` 57 | -- 58 | 59 | CREATE TABLE `users` ( 60 | `id` int(11) NOT NULL, 61 | `name` varchar(100) NOT NULL, 62 | `username` varchar(50) NOT NULL, 63 | `email` varchar(100) NOT NULL, 64 | `password` varchar(50) NOT NULL, 65 | `create_datetime` datetime NOT NULL 66 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; 67 | 68 | -- 69 | -- Dumping data for table `users` 70 | -- 71 | 72 | INSERT INTO `users` (`id`, `name`, `username`, `email`, `password`, `create_datetime`) VALUES 73 | (1, 'John Rovie', 'RovicBalingbing', 'balingbing.johnrovie20@gmail.com', '850f5f5611e06993cc07363c98c560d0', '2023-04-18 08:59:41'), 74 | (2, 'admin', 'admin', 'admin@gmail.com', '21232f297a57a5a743894a0e4a801fc3', '2023-04-18 11:00:40'), 75 | (3, 'sample', 'sample', 'sample', '5e8ff9bf55ba3508199d22e984129be6', '2023-04-18 11:03:23'), 76 | (4, 'Rovic', 'Rovic', 'Rovic@gmail.com', '6bafff124175b93f6358d465c5a654d9', '2023-04-19 12:14:34'); 77 | 78 | -- 79 | -- Indexes for dumped tables 80 | -- 81 | 82 | -- 83 | -- Indexes for table `orders` 84 | -- 85 | ALTER TABLE `orders` 86 | ADD PRIMARY KEY (`id`); 87 | 88 | -- 89 | -- Indexes for table `users` 90 | -- 91 | ALTER TABLE `users` 92 | ADD PRIMARY KEY (`id`); 93 | 94 | -- 95 | -- AUTO_INCREMENT for dumped tables 96 | -- 97 | 98 | -- 99 | -- AUTO_INCREMENT for table `orders` 100 | -- 101 | ALTER TABLE `orders` 102 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; 103 | 104 | -- 105 | -- AUTO_INCREMENT for table `users` 106 | -- 107 | ALTER TABLE `users` 108 | MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; 109 | COMMIT; 110 | 111 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 112 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 113 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 114 | -------------------------------------------------------------------------------- /assets/css/convo.css: -------------------------------------------------------------------------------- 1 | .chat-bar-collapsible { 2 | position: fixed; 3 | bottom: 0; 4 | right: 50px; 5 | box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); 6 | } 7 | 8 | .collapsible { 9 | background-color: #392414; 10 | color: white; 11 | cursor: pointer; 12 | padding: 18px; 13 | width: 350px; 14 | text-align: left; 15 | outline: none; 16 | font-size: 18px; 17 | border-radius: 10px 10px 0px 0px; 18 | border: 1px solid white; 19 | border-bottom: none; 20 | } 21 | 22 | .chat-bar-collapsible .content { 23 | max-height: 0; 24 | overflow: hidden; 25 | transition: max-height 0.2s ease-out; 26 | background-color: #f1f1f1; 27 | } 28 | 29 | .full-chat-block { 30 | width: 350px; 31 | background: white; 32 | text-align: center; 33 | overflow: auto; 34 | scrollbar-width: none; 35 | height: max-content; 36 | transition: max-height 0.2s ease-out; 37 | } 38 | 39 | .outer-container { 40 | min-height: 500px; 41 | bottom: 0%; 42 | position: relative; 43 | } 44 | 45 | .chat-container { 46 | max-height: 500px; 47 | width: 100%; 48 | position: absolute; 49 | bottom: 0; 50 | left: 0; 51 | scroll-behavior: smooth; 52 | hyphens: auto; 53 | } 54 | 55 | .chat-container::-webkit-scrollbar { 56 | display: none; 57 | } 58 | 59 | .chat-bar-input-block { 60 | display: flex; 61 | float: left; 62 | box-sizing: border-box; 63 | justify-content: space-between; 64 | width: 100%; 65 | align-items: center; 66 | background-color: rgb(235, 235, 235); 67 | border-radius: 10px 10px 0px 0px; 68 | padding: 10px 0px 10px 10px; 69 | margin-top: 20px; 70 | } 71 | 72 | .chat-bar-icons { 73 | display: flex; 74 | justify-content: space-evenly; 75 | box-sizing: border-box; 76 | width: 50%; 77 | float: right; 78 | font-size: 20px; 79 | } 80 | 81 | #chat-icon:hover { 82 | opacity: .7; 83 | } 84 | 85 | /* Chat bubbles */ 86 | 87 | #userInput { 88 | width: 75%; 89 | } 90 | 91 | .input-box { 92 | float: left; 93 | border: none; 94 | box-sizing: border-box; 95 | width: 100%; 96 | border-radius: 10px; 97 | padding: 10px; 98 | font-size: 16px; 99 | color: #000; 100 | background-color: white; 101 | outline: none 102 | } 103 | 104 | .userText { 105 | color: white; 106 | font-family: Helvetica; 107 | font-size: 14px; 108 | font-weight: normal; 109 | text-align: right; 110 | clear: both; 111 | margin: 10px; 112 | } 113 | 114 | .userText span { 115 | line-height: 1.5em; 116 | display: inline-block; 117 | background: #5ca6fa; 118 | padding: 10px; 119 | border-radius: 8px; 120 | border-bottom-right-radius: 2px; 121 | max-width: 80%; 122 | margin-right: 10px; 123 | animation: floatup .5s forwards 124 | } 125 | 126 | .botText { 127 | color: #000; 128 | font-family: Helvetica; 129 | font-weight: normal; 130 | font-size: 14px; 131 | text-align: left; 132 | } 133 | 134 | .botText span { 135 | line-height: 1.5em; 136 | display: inline-block; 137 | background: #e0e0e0; 138 | padding: 10px; 139 | border-radius: 8px; 140 | border-bottom-left-radius: 2px; 141 | max-width: 80%; 142 | margin-left: 10px; 143 | animation: floatup .5s forwards 144 | } 145 | 146 | @keyframes floatup { 147 | from { 148 | transform: translateY(14px); 149 | opacity: .0; 150 | } 151 | to { 152 | transform: translateY(0px); 153 | opacity: 1; 154 | } 155 | } 156 | 157 | @media screen and (max-width:600px) { 158 | .full-chat-block { 159 | width: 100%; 160 | border-radius: 0px; 161 | } 162 | .chat-bar-collapsible { 163 | position: fixed; 164 | bottom: 0; 165 | right: 0; 166 | width: 100%; 167 | } 168 | .collapsible { 169 | width: 100%; 170 | border: 0px; 171 | border-top: 3px solid white; 172 | border-radius: 0px; 173 | } 174 | } -------------------------------------------------------------------------------- /google-client/src/Task/Composer.php: -------------------------------------------------------------------------------- 1 | getComposer(); 36 | $extra = $composer->getPackage()->getExtra(); 37 | $servicesToKeep = isset($extra['google/apiclient-services']) 38 | ? $extra['google/apiclient-services'] 39 | : []; 40 | if ($servicesToKeep) { 41 | $vendorDir = $composer->getConfig()->get('vendor-dir'); 42 | $serviceDir = sprintf( 43 | '%s/google/apiclient-services/src/Google/Service', 44 | $vendorDir 45 | ); 46 | if (!is_dir($serviceDir)) { 47 | // path for google/apiclient-services >= 0.200.0 48 | $serviceDir = sprintf( 49 | '%s/google/apiclient-services/src', 50 | $vendorDir 51 | ); 52 | } 53 | self::verifyServicesToKeep($serviceDir, $servicesToKeep); 54 | $finder = self::getServicesToRemove($serviceDir, $servicesToKeep); 55 | $filesystem = $filesystem ?: new Filesystem(); 56 | if (0 !== $count = count($finder)) { 57 | $event->getIO()->write( 58 | sprintf('Removing %s google services', $count) 59 | ); 60 | foreach ($finder as $file) { 61 | $realpath = $file->getRealPath(); 62 | $filesystem->remove($realpath); 63 | $filesystem->remove($realpath . '.php'); 64 | } 65 | } 66 | } 67 | } 68 | 69 | /** 70 | * @throws InvalidArgumentException when the service doesn't exist 71 | */ 72 | private static function verifyServicesToKeep( 73 | $serviceDir, 74 | array $servicesToKeep 75 | ) { 76 | $finder = (new Finder()) 77 | ->directories() 78 | ->depth('== 0'); 79 | 80 | foreach ($servicesToKeep as $service) { 81 | if (!preg_match('/^[a-zA-Z0-9]*$/', $service)) { 82 | throw new InvalidArgumentException( 83 | sprintf( 84 | 'Invalid Google service name "%s"', 85 | $service 86 | ) 87 | ); 88 | } 89 | try { 90 | $finder->in($serviceDir . '/' . $service); 91 | } catch (InvalidArgumentException $e) { 92 | throw new InvalidArgumentException( 93 | sprintf( 94 | 'Google service "%s" does not exist or was removed previously', 95 | $service 96 | ) 97 | ); 98 | } 99 | } 100 | } 101 | 102 | private static function getServicesToRemove( 103 | $serviceDir, 104 | array $servicesToKeep 105 | ) { 106 | // find all files in the current directory 107 | return (new Finder()) 108 | ->directories() 109 | ->depth('== 0') 110 | ->in($serviceDir) 111 | ->exclude($servicesToKeep); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Task/Composer.php: -------------------------------------------------------------------------------- 1 | getComposer(); 36 | $extra = $composer->getPackage()->getExtra(); 37 | $servicesToKeep = isset($extra['google/apiclient-services']) 38 | ? $extra['google/apiclient-services'] 39 | : []; 40 | if ($servicesToKeep) { 41 | $vendorDir = $composer->getConfig()->get('vendor-dir'); 42 | $serviceDir = sprintf( 43 | '%s/google/apiclient-services/src/Google/Service', 44 | $vendorDir 45 | ); 46 | if (!is_dir($serviceDir)) { 47 | // path for google/apiclient-services >= 0.200.0 48 | $serviceDir = sprintf( 49 | '%s/google/apiclient-services/src', 50 | $vendorDir 51 | ); 52 | } 53 | self::verifyServicesToKeep($serviceDir, $servicesToKeep); 54 | $finder = self::getServicesToRemove($serviceDir, $servicesToKeep); 55 | $filesystem = $filesystem ?: new Filesystem(); 56 | if (0 !== $count = count($finder)) { 57 | $event->getIO()->write( 58 | sprintf('Removing %s google services', $count) 59 | ); 60 | foreach ($finder as $file) { 61 | $realpath = $file->getRealPath(); 62 | $filesystem->remove($realpath); 63 | $filesystem->remove($realpath . '.php'); 64 | } 65 | } 66 | } 67 | } 68 | 69 | /** 70 | * @throws InvalidArgumentException when the service doesn't exist 71 | */ 72 | private static function verifyServicesToKeep( 73 | $serviceDir, 74 | array $servicesToKeep 75 | ) { 76 | $finder = (new Finder()) 77 | ->directories() 78 | ->depth('== 0'); 79 | 80 | foreach ($servicesToKeep as $service) { 81 | if (!preg_match('/^[a-zA-Z0-9]*$/', $service)) { 82 | throw new InvalidArgumentException( 83 | sprintf( 84 | 'Invalid Google service name "%s"', 85 | $service 86 | ) 87 | ); 88 | } 89 | try { 90 | $finder->in($serviceDir . '/' . $service); 91 | } catch (InvalidArgumentException $e) { 92 | throw new InvalidArgumentException( 93 | sprintf( 94 | 'Google service "%s" does not exist or was removed previously', 95 | $service 96 | ) 97 | ); 98 | } 99 | } 100 | } 101 | 102 | private static function getServicesToRemove( 103 | $serviceDir, 104 | array $servicesToKeep 105 | ) { 106 | // find all files in the current directory 107 | return (new Finder()) 108 | ->directories() 109 | ->depth('== 0') 110 | ->in($serviceDir) 111 | ->exclude($servicesToKeep); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /users/login.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | KapeTann | Login Form 7 | 8 | 9 | 10 | 11 | 12 | 32 |

Incorrect Username/password.


33 | 34 | "; 35 | } 36 | } else { 37 | ?> 38 |
39 |
40 | 41 |
42 |
43 |

Login

44 | 45 | 46 | 47 | 48 |
49 | 50 |
56 |
57 | 58 | 67 |
68 | 71 | 72 | 73 | 74 | 75 | 95 | 96 | -------------------------------------------------------------------------------- /google-client/src/Http/REST.php: -------------------------------------------------------------------------------- 1 | |false|null $expectedClass 42 | * @param array $config 43 | * @param array $retryMap 44 | * @return mixed|T|null 45 | * @throws \Google\Service\Exception on server side error (ie: not authenticated, 46 | * invalid or malformed post body, invalid url) 47 | */ 48 | public static function execute( 49 | ClientInterface $client, 50 | RequestInterface $request, 51 | $expectedClass = null, 52 | $config = [], 53 | $retryMap = null 54 | ) { 55 | $runner = new Runner( 56 | $config, 57 | sprintf('%s %s', $request->getMethod(), (string) $request->getUri()), 58 | [get_class(), 'doExecute'], 59 | [$client, $request, $expectedClass] 60 | ); 61 | 62 | if (null !== $retryMap) { 63 | $runner->setRetryMap($retryMap); 64 | } 65 | 66 | return $runner->run(); 67 | } 68 | 69 | /** 70 | * Executes a Psr\Http\Message\RequestInterface 71 | * 72 | * @template T 73 | * @param ClientInterface $client 74 | * @param RequestInterface $request 75 | * @param class-string|false|null $expectedClass 76 | * @return mixed|T|null 77 | * @throws \Google\Service\Exception on server side error (ie: not authenticated, 78 | * invalid or malformed post body, invalid url) 79 | */ 80 | public static function doExecute(ClientInterface $client, RequestInterface $request, $expectedClass = null) 81 | { 82 | try { 83 | $httpHandler = HttpHandlerFactory::build($client); 84 | $response = $httpHandler($request); 85 | } catch (RequestException $e) { 86 | // if Guzzle throws an exception, catch it and handle the response 87 | if (!$e->hasResponse()) { 88 | throw $e; 89 | } 90 | 91 | $response = $e->getResponse(); 92 | // specific checking for Guzzle 5: convert to PSR7 response 93 | if ( 94 | interface_exists('\GuzzleHttp\Message\ResponseInterface') 95 | && $response instanceof \GuzzleHttp\Message\ResponseInterface 96 | ) { 97 | $response = new Response( 98 | $response->getStatusCode(), 99 | $response->getHeaders() ?: [], 100 | $response->getBody(), 101 | $response->getProtocolVersion(), 102 | $response->getReasonPhrase() 103 | ); 104 | } 105 | } 106 | 107 | return self::decodeHttpResponse($response, $request, $expectedClass); 108 | } 109 | 110 | /** 111 | * Decode an HTTP Response. 112 | * @static 113 | * 114 | * @template T 115 | * @param RequestInterface $response The http response to be decoded. 116 | * @param ResponseInterface $response 117 | * @param class-string|false|null $expectedClass 118 | * @return mixed|T|null 119 | * @throws \Google\Service\Exception 120 | */ 121 | public static function decodeHttpResponse( 122 | ResponseInterface $response, 123 | RequestInterface $request = null, 124 | $expectedClass = null 125 | ) { 126 | $code = $response->getStatusCode(); 127 | 128 | // retry strategy 129 | if (intVal($code) >= 400) { 130 | // if we errored out, it should be safe to grab the response body 131 | $body = (string) $response->getBody(); 132 | 133 | // Check if we received errors, and add those to the Exception for convenience 134 | throw new GoogleServiceException($body, $code, null, self::getResponseErrors($body)); 135 | } 136 | 137 | // Ensure we only pull the entire body into memory if the request is not 138 | // of media type 139 | $body = self::decodeBody($response, $request); 140 | 141 | if ($expectedClass = self::determineExpectedClass($expectedClass, $request)) { 142 | $json = json_decode($body, true); 143 | 144 | return new $expectedClass($json); 145 | } 146 | 147 | return $response; 148 | } 149 | 150 | private static function decodeBody(ResponseInterface $response, RequestInterface $request = null) 151 | { 152 | if (self::isAltMedia($request)) { 153 | // don't decode the body, it's probably a really long string 154 | return ''; 155 | } 156 | 157 | return (string) $response->getBody(); 158 | } 159 | 160 | private static function determineExpectedClass($expectedClass, RequestInterface $request = null) 161 | { 162 | // "false" is used to explicitly prevent an expected class from being returned 163 | if (false === $expectedClass) { 164 | return null; 165 | } 166 | 167 | // if we don't have a request, we just use what's passed in 168 | if (null === $request) { 169 | return $expectedClass; 170 | } 171 | 172 | // return what we have in the request header if one was not supplied 173 | return $expectedClass ?: $request->getHeaderLine('X-Php-Expected-Class'); 174 | } 175 | 176 | private static function getResponseErrors($body) 177 | { 178 | $json = json_decode($body, true); 179 | 180 | if (isset($json['error']['errors'])) { 181 | return $json['error']['errors']; 182 | } 183 | 184 | return null; 185 | } 186 | 187 | private static function isAltMedia(RequestInterface $request = null) 188 | { 189 | if ($request && $qs = $request->getUri()->getQuery()) { 190 | parse_str($qs, $query); 191 | if (isset($query['alt']) && $query['alt'] == 'media') { 192 | return true; 193 | } 194 | } 195 | 196 | return false; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Http/REST.php: -------------------------------------------------------------------------------- 1 | |false|null $expectedClass 42 | * @param array $config 43 | * @param array $retryMap 44 | * @return mixed|T|null 45 | * @throws \Google\Service\Exception on server side error (ie: not authenticated, 46 | * invalid or malformed post body, invalid url) 47 | */ 48 | public static function execute( 49 | ClientInterface $client, 50 | RequestInterface $request, 51 | $expectedClass = null, 52 | $config = [], 53 | $retryMap = null 54 | ) { 55 | $runner = new Runner( 56 | $config, 57 | sprintf('%s %s', $request->getMethod(), (string) $request->getUri()), 58 | [get_class(), 'doExecute'], 59 | [$client, $request, $expectedClass] 60 | ); 61 | 62 | if (null !== $retryMap) { 63 | $runner->setRetryMap($retryMap); 64 | } 65 | 66 | return $runner->run(); 67 | } 68 | 69 | /** 70 | * Executes a Psr\Http\Message\RequestInterface 71 | * 72 | * @template T 73 | * @param ClientInterface $client 74 | * @param RequestInterface $request 75 | * @param class-string|false|null $expectedClass 76 | * @return mixed|T|null 77 | * @throws \Google\Service\Exception on server side error (ie: not authenticated, 78 | * invalid or malformed post body, invalid url) 79 | */ 80 | public static function doExecute(ClientInterface $client, RequestInterface $request, $expectedClass = null) 81 | { 82 | try { 83 | $httpHandler = HttpHandlerFactory::build($client); 84 | $response = $httpHandler($request); 85 | } catch (RequestException $e) { 86 | // if Guzzle throws an exception, catch it and handle the response 87 | if (!$e->hasResponse()) { 88 | throw $e; 89 | } 90 | 91 | $response = $e->getResponse(); 92 | // specific checking for Guzzle 5: convert to PSR7 response 93 | if ( 94 | interface_exists('\GuzzleHttp\Message\ResponseInterface') 95 | && $response instanceof \GuzzleHttp\Message\ResponseInterface 96 | ) { 97 | $response = new Response( 98 | $response->getStatusCode(), 99 | $response->getHeaders() ?: [], 100 | $response->getBody(), 101 | $response->getProtocolVersion(), 102 | $response->getReasonPhrase() 103 | ); 104 | } 105 | } 106 | 107 | return self::decodeHttpResponse($response, $request, $expectedClass); 108 | } 109 | 110 | /** 111 | * Decode an HTTP Response. 112 | * @static 113 | * 114 | * @template T 115 | * @param RequestInterface $response The http response to be decoded. 116 | * @param ResponseInterface $response 117 | * @param class-string|false|null $expectedClass 118 | * @return mixed|T|null 119 | * @throws \Google\Service\Exception 120 | */ 121 | public static function decodeHttpResponse( 122 | ResponseInterface $response, 123 | RequestInterface $request = null, 124 | $expectedClass = null 125 | ) { 126 | $code = $response->getStatusCode(); 127 | 128 | // retry strategy 129 | if (intVal($code) >= 400) { 130 | // if we errored out, it should be safe to grab the response body 131 | $body = (string) $response->getBody(); 132 | 133 | // Check if we received errors, and add those to the Exception for convenience 134 | throw new GoogleServiceException($body, $code, null, self::getResponseErrors($body)); 135 | } 136 | 137 | // Ensure we only pull the entire body into memory if the request is not 138 | // of media type 139 | $body = self::decodeBody($response, $request); 140 | 141 | if ($expectedClass = self::determineExpectedClass($expectedClass, $request)) { 142 | $json = json_decode($body, true); 143 | 144 | return new $expectedClass($json); 145 | } 146 | 147 | return $response; 148 | } 149 | 150 | private static function decodeBody(ResponseInterface $response, RequestInterface $request = null) 151 | { 152 | if (self::isAltMedia($request)) { 153 | // don't decode the body, it's probably a really long string 154 | return ''; 155 | } 156 | 157 | return (string) $response->getBody(); 158 | } 159 | 160 | private static function determineExpectedClass($expectedClass, RequestInterface $request = null) 161 | { 162 | // "false" is used to explicitly prevent an expected class from being returned 163 | if (false === $expectedClass) { 164 | return null; 165 | } 166 | 167 | // if we don't have a request, we just use what's passed in 168 | if (null === $request) { 169 | return $expectedClass; 170 | } 171 | 172 | // return what we have in the request header if one was not supplied 173 | return $expectedClass ?: $request->getHeaderLine('X-Php-Expected-Class'); 174 | } 175 | 176 | private static function getResponseErrors($body) 177 | { 178 | $json = json_decode($body, true); 179 | 180 | if (isset($json['error']['errors'])) { 181 | return $json['error']['errors']; 182 | } 183 | 184 | return null; 185 | } 186 | 187 | private static function isAltMedia(RequestInterface $request = null) 188 | { 189 | if ($request && $qs = $request->getUri()->getQuery()) { 190 | parse_str($qs, $query); 191 | if (isset($query['alt']) && $query['alt'] == 'media') { 192 | return true; 193 | } 194 | } 195 | 196 | return false; 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /assets/js/script.js: -------------------------------------------------------------------------------- 1 | // Show Navbar when small screen || Close Cart Items & Search Textbox 2 | let navbar = document.querySelector('.navbar'); 3 | 4 | document.querySelector('#menu-btn').onclick = () => { 5 | navbar.classList.toggle('active'); 6 | cartItem.classList.remove('active'); 7 | searchForm.classList.remove('active'); 8 | } 9 | 10 | // Show Cart Items || Close Navbar & Search Textbox 11 | let cartItem = document.querySelector('.cart'); 12 | 13 | document.querySelector('#cart-btn').onclick = () => { 14 | cartItem.classList.toggle('active'); 15 | navbar.classList.remove('active'); 16 | searchForm.classList.remove('active'); 17 | } 18 | 19 | // Show Search Textbox || Close Navbar & Cart Items 20 | let searchForm = document.querySelector('.search-form'); 21 | 22 | document.querySelector('#search-btn').onclick = () => { 23 | searchForm.classList.toggle('active'); 24 | navbar.classList.remove('active'); 25 | cartItem.classList.remove('active'); 26 | } 27 | 28 | // Remove Active Icons on Scroll and Close it 29 | window.onscroll = () => { 30 | navbar.classList.remove('active'); 31 | cartItem.classList.remove('active'); 32 | searchForm.classList.remove('active'); 33 | } 34 | 35 | // Script for making icon as button 36 | document.getElementById('paper-plane-icon').addEventListener('click', function() { 37 | // Add your desired action here, e.g. submit form, trigger AJAX request, etc. 38 | alert('Paper airplane clicked!'); 39 | }); 40 | 41 | 42 | //Cart Working JS 43 | if (document.readyState == 'loading') { 44 | document.addEventListener("DOMContentLoaded", ready); 45 | } else { 46 | ready(); 47 | } 48 | 49 | // FUNCTIONS FOR CART 50 | function ready() { 51 | //Remove Items from Cart 52 | var removeCartButtons = document.getElementsByClassName('cart-remove'); 53 | console.log(removeCartButtons); 54 | for (var i = 0; i < removeCartButtons.length; i++){ 55 | var button = removeCartButtons[i]; 56 | button.addEventListener('click', removeCartItem); 57 | } 58 | 59 | // When quantity changes 60 | var quantityInputs = document.getElementsByClassName("cart-quantity"); 61 | for (var i = 0; i < quantityInputs.length; i++){ 62 | var input = quantityInputs[i]; 63 | input.addEventListener("change", quantityChanged); 64 | } 65 | 66 | // Add to Cart 67 | var addCart = document.getElementsByClassName('add-cart'); 68 | for (var i = 0; i < addCart.length; i++){ 69 | var button = addCart[i]; 70 | button.addEventListener("click", addCartClicked); 71 | } 72 | 73 | // Buy Button Works 74 | document.getElementsByClassName("btn-buy")[0].addEventListener("click", buyButtonClicked); 75 | } 76 | 77 | // Function for "Buy Button Works" 78 | function buyButtonClicked() { 79 | alert('Your order is placed! Thank you for buying and enjoy your coffee!'); 80 | var cartContent = document.getElementsByClassName("cart-content")[0]; 81 | var cartBoxes = cartContent.getElementsByClassName("cart-box"); 82 | var orderDetails = []; 83 | 84 | // Generate invoice number 85 | var invoiceNumber = generateInvoiceNumber(); 86 | 87 | // Loop through all cart boxes to get details 88 | for (var i = 0; i < cartBoxes.length; i++) { 89 | var cartBox = cartBoxes[i]; 90 | var title = cartBox.getElementsByClassName("cart-product-title")[0].innerText; 91 | var price = cartBox.getElementsByClassName("cart-price")[0].innerText; 92 | var quantity = cartBox.getElementsByClassName("cart-quantity")[0].value; 93 | var priceValue = parseFloat(price.replace('₱', '').replace(',', '')); 94 | var subtotalAmount = priceValue * quantity; 95 | orderDetails.push({ title: title, price: priceValue, quantity: quantity, subtotal_amount: subtotalAmount, invoice_number: invoiceNumber }); 96 | } 97 | 98 | //Send data to server using AJAX 99 | var xhr = new XMLHttpRequest(); 100 | xhr.open("POST", "add_to_database.php", true); 101 | xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); 102 | xhr.onreadystatechange = function() { 103 | if (xhr.readyState === 4 && xhr.status === 200) { 104 | console.log(xhr.responseText); 105 | } 106 | }; 107 | xhr.send(JSON.stringify(orderDetails)); 108 | cartItem.classList.remove('active'); 109 | 110 | // Clear cart after sending data to server 111 | while (cartContent.hasChildNodes()) { 112 | cartContent.removeChild(cartContent.firstChild); 113 | } 114 | updateTotal(); 115 | } 116 | 117 | // Function to generate invoice number 118 | function generateInvoiceNumber() { 119 | // Implement your logic to generate an invoice number here 120 | return "INV-" + Math.floor(Math.random() * 1000000); 121 | } 122 | 123 | // Function for "Remove Items from Cart" 124 | function removeCartItem(event) { 125 | var buttonClicked = event.target; 126 | buttonClicked.parentElement.remove(); 127 | updateTotal(); 128 | } 129 | 130 | // Function for "When quantity changes" 131 | function quantityChanged(event) { 132 | var input = event.target; 133 | if (isNaN(input.value) || input.value <= 0) { 134 | input.value = 1; 135 | } 136 | updateTotal(); 137 | } 138 | 139 | //Add to Cart 140 | function addCartClicked(event) { 141 | var button = event.target; 142 | var shopProducts = button.parentElement; 143 | var title = shopProducts.getElementsByClassName("product-title")[0].innerText; 144 | var price = shopProducts.getElementsByClassName("price")[0].innerText; 145 | var productImg = shopProducts.getElementsByClassName("product-img")[0].src; 146 | addProductToCart(title, price, productImg); 147 | updateTotal(); 148 | } 149 | 150 | function addProductToCart(title, price, productImg) { 151 | var cartShopBox = document.createElement("div"); 152 | cartShopBox.classList.add("cart-box"); 153 | var cartItems = document.getElementsByClassName("cart-content")[0]; 154 | var cartItemsNames = cartItems.getElementsByClassName("cart-product-title"); 155 | for (var i = 0; i < cartItemsNames.length; i++) { 156 | if (cartItemsNames[i].innerText == title) { 157 | alert("You have already added this item to cart!") 158 | return; 159 | } 160 | } 161 | var cartBoxContent = ` 162 | 163 |
164 |
${title}
165 |
${price}
166 | 167 |
168 | 169 | `; 170 | cartShopBox.innerHTML = cartBoxContent; 171 | cartItems.append(cartShopBox); 172 | cartShopBox 173 | .getElementsByClassName("cart-remove")[0] 174 | .addEventListener('click', removeCartItem); 175 | cartShopBox 176 | .getElementsByClassName("cart-quantity")[0] 177 | .addEventListener('change', quantityChanged); 178 | 179 | } 180 | 181 | // Update Total 182 | function updateTotal() { 183 | var cartContent = document.getElementsByClassName("cart-content")[0]; 184 | var cartBoxes = cartContent.getElementsByClassName("cart-box"); 185 | var total = 0; 186 | for (var i = 0; i < cartBoxes.length; i++) { 187 | var cartBox = cartBoxes[i]; 188 | var priceElement = cartBox.getElementsByClassName("cart-price")[0]; 189 | var quantityElement = cartBox.getElementsByClassName("cart-quantity")[0]; 190 | var price = parseFloat(priceElement.innerText.replace("₱", "")); 191 | var quantity = quantityElement.value; 192 | total = total + (price * quantity); 193 | } 194 | total = Math.round(total * 100) / 100; 195 | 196 | document.getElementsByClassName("total-price")[0].innerText = "₱" + total; 197 | } -------------------------------------------------------------------------------- /google-client/src/Http/Batch.php: -------------------------------------------------------------------------------- 1 | client = $client; 64 | $this->boundary = $boundary ?: mt_rand(); 65 | $this->rootUrl = rtrim($rootUrl ?: $this->client->getConfig('base_path'), '/'); 66 | $this->batchPath = $batchPath ?: self::BATCH_PATH; 67 | } 68 | 69 | public function add(RequestInterface $request, $key = false) 70 | { 71 | if (false == $key) { 72 | $key = mt_rand(); 73 | } 74 | 75 | $this->requests[$key] = $request; 76 | } 77 | 78 | public function execute() 79 | { 80 | $body = ''; 81 | $classes = []; 82 | $batchHttpTemplate = <<requests as $key => $request) { 97 | $firstLine = sprintf( 98 | '%s %s HTTP/%s', 99 | $request->getMethod(), 100 | $request->getRequestTarget(), 101 | $request->getProtocolVersion() 102 | ); 103 | 104 | $content = (string) $request->getBody(); 105 | 106 | $headers = ''; 107 | foreach ($request->getHeaders() as $name => $values) { 108 | $headers .= sprintf("%s:%s\r\n", $name, implode(', ', $values)); 109 | } 110 | 111 | $body .= sprintf( 112 | $batchHttpTemplate, 113 | $this->boundary, 114 | $key, 115 | $firstLine, 116 | $headers, 117 | $content ? "\n" . $content : '' 118 | ); 119 | 120 | $classes['response-' . $key] = $request->getHeaderLine('X-Php-Expected-Class'); 121 | } 122 | 123 | $body .= "--{$this->boundary}--"; 124 | $body = trim($body); 125 | $url = $this->rootUrl . '/' . $this->batchPath; 126 | $headers = [ 127 | 'Content-Type' => sprintf('multipart/mixed; boundary=%s', $this->boundary), 128 | 'Content-Length' => (string) strlen($body), 129 | ]; 130 | 131 | $request = new Request( 132 | 'POST', 133 | $url, 134 | $headers, 135 | $body 136 | ); 137 | 138 | $response = $this->client->execute($request); 139 | 140 | return $this->parseResponse($response, $classes); 141 | } 142 | 143 | public function parseResponse(ResponseInterface $response, $classes = []) 144 | { 145 | $contentType = $response->getHeaderLine('content-type'); 146 | $contentType = explode(';', $contentType); 147 | $boundary = false; 148 | foreach ($contentType as $part) { 149 | $part = explode('=', $part, 2); 150 | if (isset($part[0]) && 'boundary' == trim($part[0])) { 151 | $boundary = $part[1]; 152 | } 153 | } 154 | 155 | $body = (string) $response->getBody(); 156 | if (!empty($body)) { 157 | $body = str_replace("--$boundary--", "--$boundary", $body); 158 | $parts = explode("--$boundary", $body); 159 | $responses = []; 160 | $requests = array_values($this->requests); 161 | 162 | foreach ($parts as $i => $part) { 163 | $part = trim($part); 164 | if (!empty($part)) { 165 | list($rawHeaders, $part) = explode("\r\n\r\n", $part, 2); 166 | $headers = $this->parseRawHeaders($rawHeaders); 167 | 168 | $status = substr($part, 0, strpos($part, "\n")); 169 | $status = explode(" ", $status); 170 | $status = $status[1]; 171 | 172 | list($partHeaders, $partBody) = $this->parseHttpResponse($part, 0); 173 | $response = new Response( 174 | (int) $status, 175 | $partHeaders, 176 | Psr7\Utils::streamFor($partBody) 177 | ); 178 | 179 | // Need content id. 180 | $key = $headers['content-id']; 181 | 182 | try { 183 | $response = REST::decodeHttpResponse($response, $requests[$i-1]); 184 | } catch (GoogleServiceException $e) { 185 | // Store the exception as the response, so successful responses 186 | // can be processed. 187 | $response = $e; 188 | } 189 | 190 | $responses[$key] = $response; 191 | } 192 | } 193 | 194 | return $responses; 195 | } 196 | 197 | return null; 198 | } 199 | 200 | private function parseRawHeaders($rawHeaders) 201 | { 202 | $headers = []; 203 | $responseHeaderLines = explode("\r\n", $rawHeaders); 204 | foreach ($responseHeaderLines as $headerLine) { 205 | if ($headerLine && strpos($headerLine, ':') !== false) { 206 | list($header, $value) = explode(': ', $headerLine, 2); 207 | $header = strtolower($header); 208 | if (isset($headers[$header])) { 209 | $headers[$header] = array_merge((array)$headers[$header], (array)$value); 210 | } else { 211 | $headers[$header] = $value; 212 | } 213 | } 214 | } 215 | return $headers; 216 | } 217 | 218 | /** 219 | * Used by the IO lib and also the batch processing. 220 | * 221 | * @param string $respData 222 | * @param int $headerSize 223 | * @return array 224 | */ 225 | private function parseHttpResponse($respData, $headerSize) 226 | { 227 | // check proxy header 228 | foreach (self::$CONNECTION_ESTABLISHED_HEADERS as $established_header) { 229 | if (stripos($respData, $established_header) !== false) { 230 | // existed, remove it 231 | $respData = str_ireplace($established_header, '', $respData); 232 | // Subtract the proxy header size unless the cURL bug prior to 7.30.0 233 | // is present which prevented the proxy header size from being taken into 234 | // account. 235 | // @TODO look into this 236 | // if (!$this->needsQuirk()) { 237 | // $headerSize -= strlen($established_header); 238 | // } 239 | break; 240 | } 241 | } 242 | 243 | if ($headerSize) { 244 | $responseBody = substr($respData, $headerSize); 245 | $responseHeaders = substr($respData, 0, $headerSize); 246 | } else { 247 | $responseSegments = explode("\r\n\r\n", $respData, 2); 248 | $responseHeaders = $responseSegments[0]; 249 | $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : null; 250 | } 251 | 252 | $responseHeaders = $this->parseRawHeaders($responseHeaders); 253 | 254 | return [$responseHeaders, $responseBody]; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Http/Batch.php: -------------------------------------------------------------------------------- 1 | client = $client; 64 | $this->boundary = $boundary ?: mt_rand(); 65 | $this->rootUrl = rtrim($rootUrl ?: $this->client->getConfig('base_path'), '/'); 66 | $this->batchPath = $batchPath ?: self::BATCH_PATH; 67 | } 68 | 69 | public function add(RequestInterface $request, $key = false) 70 | { 71 | if (false == $key) { 72 | $key = mt_rand(); 73 | } 74 | 75 | $this->requests[$key] = $request; 76 | } 77 | 78 | public function execute() 79 | { 80 | $body = ''; 81 | $classes = []; 82 | $batchHttpTemplate = <<requests as $key => $request) { 97 | $firstLine = sprintf( 98 | '%s %s HTTP/%s', 99 | $request->getMethod(), 100 | $request->getRequestTarget(), 101 | $request->getProtocolVersion() 102 | ); 103 | 104 | $content = (string) $request->getBody(); 105 | 106 | $headers = ''; 107 | foreach ($request->getHeaders() as $name => $values) { 108 | $headers .= sprintf("%s:%s\r\n", $name, implode(', ', $values)); 109 | } 110 | 111 | $body .= sprintf( 112 | $batchHttpTemplate, 113 | $this->boundary, 114 | $key, 115 | $firstLine, 116 | $headers, 117 | $content ? "\n" . $content : '' 118 | ); 119 | 120 | $classes['response-' . $key] = $request->getHeaderLine('X-Php-Expected-Class'); 121 | } 122 | 123 | $body .= "--{$this->boundary}--"; 124 | $body = trim($body); 125 | $url = $this->rootUrl . '/' . $this->batchPath; 126 | $headers = [ 127 | 'Content-Type' => sprintf('multipart/mixed; boundary=%s', $this->boundary), 128 | 'Content-Length' => (string) strlen($body), 129 | ]; 130 | 131 | $request = new Request( 132 | 'POST', 133 | $url, 134 | $headers, 135 | $body 136 | ); 137 | 138 | $response = $this->client->execute($request); 139 | 140 | return $this->parseResponse($response, $classes); 141 | } 142 | 143 | public function parseResponse(ResponseInterface $response, $classes = []) 144 | { 145 | $contentType = $response->getHeaderLine('content-type'); 146 | $contentType = explode(';', $contentType); 147 | $boundary = false; 148 | foreach ($contentType as $part) { 149 | $part = explode('=', $part, 2); 150 | if (isset($part[0]) && 'boundary' == trim($part[0])) { 151 | $boundary = $part[1]; 152 | } 153 | } 154 | 155 | $body = (string) $response->getBody(); 156 | if (!empty($body)) { 157 | $body = str_replace("--$boundary--", "--$boundary", $body); 158 | $parts = explode("--$boundary", $body); 159 | $responses = []; 160 | $requests = array_values($this->requests); 161 | 162 | foreach ($parts as $i => $part) { 163 | $part = trim($part); 164 | if (!empty($part)) { 165 | list($rawHeaders, $part) = explode("\r\n\r\n", $part, 2); 166 | $headers = $this->parseRawHeaders($rawHeaders); 167 | 168 | $status = substr($part, 0, strpos($part, "\n")); 169 | $status = explode(" ", $status); 170 | $status = $status[1]; 171 | 172 | list($partHeaders, $partBody) = $this->parseHttpResponse($part, 0); 173 | $response = new Response( 174 | (int) $status, 175 | $partHeaders, 176 | Psr7\Utils::streamFor($partBody) 177 | ); 178 | 179 | // Need content id. 180 | $key = $headers['content-id']; 181 | 182 | try { 183 | $response = REST::decodeHttpResponse($response, $requests[$i-1]); 184 | } catch (GoogleServiceException $e) { 185 | // Store the exception as the response, so successful responses 186 | // can be processed. 187 | $response = $e; 188 | } 189 | 190 | $responses[$key] = $response; 191 | } 192 | } 193 | 194 | return $responses; 195 | } 196 | 197 | return null; 198 | } 199 | 200 | private function parseRawHeaders($rawHeaders) 201 | { 202 | $headers = []; 203 | $responseHeaderLines = explode("\r\n", $rawHeaders); 204 | foreach ($responseHeaderLines as $headerLine) { 205 | if ($headerLine && strpos($headerLine, ':') !== false) { 206 | list($header, $value) = explode(': ', $headerLine, 2); 207 | $header = strtolower($header); 208 | if (isset($headers[$header])) { 209 | $headers[$header] = array_merge((array)$headers[$header], (array)$value); 210 | } else { 211 | $headers[$header] = $value; 212 | } 213 | } 214 | } 215 | return $headers; 216 | } 217 | 218 | /** 219 | * Used by the IO lib and also the batch processing. 220 | * 221 | * @param string $respData 222 | * @param int $headerSize 223 | * @return array 224 | */ 225 | private function parseHttpResponse($respData, $headerSize) 226 | { 227 | // check proxy header 228 | foreach (self::$CONNECTION_ESTABLISHED_HEADERS as $established_header) { 229 | if (stripos($respData, $established_header) !== false) { 230 | // existed, remove it 231 | $respData = str_ireplace($established_header, '', $respData); 232 | // Subtract the proxy header size unless the cURL bug prior to 7.30.0 233 | // is present which prevented the proxy header size from being taken into 234 | // account. 235 | // @TODO look into this 236 | // if (!$this->needsQuirk()) { 237 | // $headerSize -= strlen($established_header); 238 | // } 239 | break; 240 | } 241 | } 242 | 243 | if ($headerSize) { 244 | $responseBody = substr($respData, $headerSize); 245 | $responseHeaders = substr($respData, 0, $headerSize); 246 | } else { 247 | $responseSegments = explode("\r\n\r\n", $respData, 2); 248 | $responseHeaders = $responseSegments[0]; 249 | $responseBody = isset($responseSegments[1]) ? $responseSegments[1] : null; 250 | } 251 | 252 | $responseHeaders = $this->parseRawHeaders($responseHeaders); 253 | 254 | return [$responseHeaders, $responseBody]; 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /google-client/src/Task/Runner.php: -------------------------------------------------------------------------------- 1 | self::TASK_RETRY_ALWAYS, 81 | '503' => self::TASK_RETRY_ALWAYS, 82 | 'rateLimitExceeded' => self::TASK_RETRY_ALWAYS, 83 | 'userRateLimitExceeded' => self::TASK_RETRY_ALWAYS, 84 | 6 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_RESOLVE_HOST 85 | 7 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_CONNECT 86 | 28 => self::TASK_RETRY_ALWAYS, // CURLE_OPERATION_TIMEOUTED 87 | 35 => self::TASK_RETRY_ALWAYS, // CURLE_SSL_CONNECT_ERROR 88 | 52 => self::TASK_RETRY_ALWAYS, // CURLE_GOT_NOTHING 89 | 'lighthouseError' => self::TASK_RETRY_NEVER 90 | ]; 91 | 92 | /** 93 | * Creates a new task runner with exponential backoff support. 94 | * 95 | * @param array $config The task runner config 96 | * @param string $name The name of the current task (used for logging) 97 | * @param callable $action The task to run and possibly retry 98 | * @param array $arguments The task arguments 99 | * @throws \Google\Task\Exception when misconfigured 100 | */ 101 | // @phpstan-ignore-next-line 102 | public function __construct( 103 | $config, 104 | $name, 105 | $action, 106 | array $arguments = [] 107 | ) { 108 | if (isset($config['initial_delay'])) { 109 | if ($config['initial_delay'] < 0) { 110 | throw new GoogleTaskException( 111 | 'Task configuration `initial_delay` must not be negative.' 112 | ); 113 | } 114 | 115 | $this->delay = $config['initial_delay']; 116 | } 117 | 118 | if (isset($config['max_delay'])) { 119 | if ($config['max_delay'] <= 0) { 120 | throw new GoogleTaskException( 121 | 'Task configuration `max_delay` must be greater than 0.' 122 | ); 123 | } 124 | 125 | $this->maxDelay = $config['max_delay']; 126 | } 127 | 128 | if (isset($config['factor'])) { 129 | if ($config['factor'] <= 0) { 130 | throw new GoogleTaskException( 131 | 'Task configuration `factor` must be greater than 0.' 132 | ); 133 | } 134 | 135 | $this->factor = $config['factor']; 136 | } 137 | 138 | if (isset($config['jitter'])) { 139 | if ($config['jitter'] <= 0) { 140 | throw new GoogleTaskException( 141 | 'Task configuration `jitter` must be greater than 0.' 142 | ); 143 | } 144 | 145 | $this->jitter = $config['jitter']; 146 | } 147 | 148 | if (isset($config['retries'])) { 149 | if ($config['retries'] < 0) { 150 | throw new GoogleTaskException( 151 | 'Task configuration `retries` must not be negative.' 152 | ); 153 | } 154 | $this->maxAttempts += $config['retries']; 155 | } 156 | 157 | if (!is_callable($action)) { 158 | throw new GoogleTaskException( 159 | 'Task argument `$action` must be a valid callable.' 160 | ); 161 | } 162 | 163 | $this->action = $action; 164 | $this->arguments = $arguments; 165 | } 166 | 167 | /** 168 | * Checks if a retry can be attempted. 169 | * 170 | * @return boolean 171 | */ 172 | public function canAttempt() 173 | { 174 | return $this->attempts < $this->maxAttempts; 175 | } 176 | 177 | /** 178 | * Runs the task and (if applicable) automatically retries when errors occur. 179 | * 180 | * @return mixed 181 | * @throws \Google\Service\Exception on failure when no retries are available. 182 | */ 183 | public function run() 184 | { 185 | while ($this->attempt()) { 186 | try { 187 | return call_user_func_array($this->action, $this->arguments); 188 | } catch (GoogleServiceException $exception) { 189 | $allowedRetries = $this->allowedRetries( 190 | $exception->getCode(), 191 | $exception->getErrors() 192 | ); 193 | 194 | if (!$this->canAttempt() || !$allowedRetries) { 195 | throw $exception; 196 | } 197 | 198 | if ($allowedRetries > 0) { 199 | $this->maxAttempts = min( 200 | $this->maxAttempts, 201 | $this->attempts + $allowedRetries 202 | ); 203 | } 204 | } 205 | } 206 | } 207 | 208 | /** 209 | * Runs a task once, if possible. This is useful for bypassing the `run()` 210 | * loop. 211 | * 212 | * NOTE: If this is not the first attempt, this function will sleep in 213 | * accordance to the backoff configurations before running the task. 214 | * 215 | * @return boolean 216 | */ 217 | public function attempt() 218 | { 219 | if (!$this->canAttempt()) { 220 | return false; 221 | } 222 | 223 | if ($this->attempts > 0) { 224 | $this->backOff(); 225 | } 226 | 227 | $this->attempts++; 228 | 229 | return true; 230 | } 231 | 232 | /** 233 | * Sleeps in accordance to the backoff configurations. 234 | */ 235 | private function backOff() 236 | { 237 | $delay = $this->getDelay(); 238 | 239 | usleep((int) ($delay * 1000000)); 240 | } 241 | 242 | /** 243 | * Gets the delay (in seconds) for the current backoff period. 244 | * 245 | * @return int 246 | */ 247 | private function getDelay() 248 | { 249 | $jitter = $this->getJitter(); 250 | $factor = $this->attempts > 1 ? $this->factor + $jitter : 1 + abs($jitter); 251 | 252 | return $this->delay = min($this->maxDelay, $this->delay * $factor); 253 | } 254 | 255 | /** 256 | * Gets the current jitter (random number between -$this->jitter and 257 | * $this->jitter). 258 | * 259 | * @return float 260 | */ 261 | private function getJitter() 262 | { 263 | return $this->jitter * 2 * mt_rand() / mt_getrandmax() - $this->jitter; 264 | } 265 | 266 | /** 267 | * Gets the number of times the associated task can be retried. 268 | * 269 | * NOTE: -1 is returned if the task can be retried indefinitely 270 | * 271 | * @return integer 272 | */ 273 | public function allowedRetries($code, $errors = []) 274 | { 275 | if (isset($this->retryMap[$code])) { 276 | return $this->retryMap[$code]; 277 | } 278 | 279 | if ( 280 | !empty($errors) && 281 | isset($errors[0]['reason'], $this->retryMap[$errors[0]['reason']]) 282 | ) { 283 | return $this->retryMap[$errors[0]['reason']]; 284 | } 285 | 286 | return 0; 287 | } 288 | 289 | public function setRetryMap($retryMap) 290 | { 291 | $this->retryMap = $retryMap; 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/Task/Runner.php: -------------------------------------------------------------------------------- 1 | self::TASK_RETRY_ALWAYS, 81 | '503' => self::TASK_RETRY_ALWAYS, 82 | 'rateLimitExceeded' => self::TASK_RETRY_ALWAYS, 83 | 'userRateLimitExceeded' => self::TASK_RETRY_ALWAYS, 84 | 6 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_RESOLVE_HOST 85 | 7 => self::TASK_RETRY_ALWAYS, // CURLE_COULDNT_CONNECT 86 | 28 => self::TASK_RETRY_ALWAYS, // CURLE_OPERATION_TIMEOUTED 87 | 35 => self::TASK_RETRY_ALWAYS, // CURLE_SSL_CONNECT_ERROR 88 | 52 => self::TASK_RETRY_ALWAYS, // CURLE_GOT_NOTHING 89 | 'lighthouseError' => self::TASK_RETRY_NEVER 90 | ]; 91 | 92 | /** 93 | * Creates a new task runner with exponential backoff support. 94 | * 95 | * @param array $config The task runner config 96 | * @param string $name The name of the current task (used for logging) 97 | * @param callable $action The task to run and possibly retry 98 | * @param array $arguments The task arguments 99 | * @throws \Google\Task\Exception when misconfigured 100 | */ 101 | // @phpstan-ignore-next-line 102 | public function __construct( 103 | $config, 104 | $name, 105 | $action, 106 | array $arguments = [] 107 | ) { 108 | if (isset($config['initial_delay'])) { 109 | if ($config['initial_delay'] < 0) { 110 | throw new GoogleTaskException( 111 | 'Task configuration `initial_delay` must not be negative.' 112 | ); 113 | } 114 | 115 | $this->delay = $config['initial_delay']; 116 | } 117 | 118 | if (isset($config['max_delay'])) { 119 | if ($config['max_delay'] <= 0) { 120 | throw new GoogleTaskException( 121 | 'Task configuration `max_delay` must be greater than 0.' 122 | ); 123 | } 124 | 125 | $this->maxDelay = $config['max_delay']; 126 | } 127 | 128 | if (isset($config['factor'])) { 129 | if ($config['factor'] <= 0) { 130 | throw new GoogleTaskException( 131 | 'Task configuration `factor` must be greater than 0.' 132 | ); 133 | } 134 | 135 | $this->factor = $config['factor']; 136 | } 137 | 138 | if (isset($config['jitter'])) { 139 | if ($config['jitter'] <= 0) { 140 | throw new GoogleTaskException( 141 | 'Task configuration `jitter` must be greater than 0.' 142 | ); 143 | } 144 | 145 | $this->jitter = $config['jitter']; 146 | } 147 | 148 | if (isset($config['retries'])) { 149 | if ($config['retries'] < 0) { 150 | throw new GoogleTaskException( 151 | 'Task configuration `retries` must not be negative.' 152 | ); 153 | } 154 | $this->maxAttempts += $config['retries']; 155 | } 156 | 157 | if (!is_callable($action)) { 158 | throw new GoogleTaskException( 159 | 'Task argument `$action` must be a valid callable.' 160 | ); 161 | } 162 | 163 | $this->action = $action; 164 | $this->arguments = $arguments; 165 | } 166 | 167 | /** 168 | * Checks if a retry can be attempted. 169 | * 170 | * @return boolean 171 | */ 172 | public function canAttempt() 173 | { 174 | return $this->attempts < $this->maxAttempts; 175 | } 176 | 177 | /** 178 | * Runs the task and (if applicable) automatically retries when errors occur. 179 | * 180 | * @return mixed 181 | * @throws \Google\Service\Exception on failure when no retries are available. 182 | */ 183 | public function run() 184 | { 185 | while ($this->attempt()) { 186 | try { 187 | return call_user_func_array($this->action, $this->arguments); 188 | } catch (GoogleServiceException $exception) { 189 | $allowedRetries = $this->allowedRetries( 190 | $exception->getCode(), 191 | $exception->getErrors() 192 | ); 193 | 194 | if (!$this->canAttempt() || !$allowedRetries) { 195 | throw $exception; 196 | } 197 | 198 | if ($allowedRetries > 0) { 199 | $this->maxAttempts = min( 200 | $this->maxAttempts, 201 | $this->attempts + $allowedRetries 202 | ); 203 | } 204 | } 205 | } 206 | } 207 | 208 | /** 209 | * Runs a task once, if possible. This is useful for bypassing the `run()` 210 | * loop. 211 | * 212 | * NOTE: If this is not the first attempt, this function will sleep in 213 | * accordance to the backoff configurations before running the task. 214 | * 215 | * @return boolean 216 | */ 217 | public function attempt() 218 | { 219 | if (!$this->canAttempt()) { 220 | return false; 221 | } 222 | 223 | if ($this->attempts > 0) { 224 | $this->backOff(); 225 | } 226 | 227 | $this->attempts++; 228 | 229 | return true; 230 | } 231 | 232 | /** 233 | * Sleeps in accordance to the backoff configurations. 234 | */ 235 | private function backOff() 236 | { 237 | $delay = $this->getDelay(); 238 | 239 | usleep((int) ($delay * 1000000)); 240 | } 241 | 242 | /** 243 | * Gets the delay (in seconds) for the current backoff period. 244 | * 245 | * @return int 246 | */ 247 | private function getDelay() 248 | { 249 | $jitter = $this->getJitter(); 250 | $factor = $this->attempts > 1 ? $this->factor + $jitter : 1 + abs($jitter); 251 | 252 | return $this->delay = min($this->maxDelay, $this->delay * $factor); 253 | } 254 | 255 | /** 256 | * Gets the current jitter (random number between -$this->jitter and 257 | * $this->jitter). 258 | * 259 | * @return float 260 | */ 261 | private function getJitter() 262 | { 263 | return $this->jitter * 2 * mt_rand() / mt_getrandmax() - $this->jitter; 264 | } 265 | 266 | /** 267 | * Gets the number of times the associated task can be retried. 268 | * 269 | * NOTE: -1 is returned if the task can be retried indefinitely 270 | * 271 | * @return integer 272 | */ 273 | public function allowedRetries($code, $errors = []) 274 | { 275 | if (isset($this->retryMap[$code])) { 276 | return $this->retryMap[$code]; 277 | } 278 | 279 | if ( 280 | !empty($errors) && 281 | isset($errors[0]['reason'], $this->retryMap[$errors[0]['reason']]) 282 | ) { 283 | return $this->retryMap[$errors[0]['reason']]; 284 | } 285 | 286 | return 0; 287 | } 288 | 289 | public function setRetryMap($retryMap) 290 | { 291 | $this->retryMap = $retryMap; 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /google-client/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | -------------------------------------------------------------------------------- /google-client/src/AccessToken/Verify.php: -------------------------------------------------------------------------------- 1 | http = $http; 81 | $this->cache = $cache; 82 | $this->jwt = $jwt ?: $this->getJwtService(); 83 | } 84 | 85 | /** 86 | * Verifies an id token and returns the authenticated apiLoginTicket. 87 | * Throws an exception if the id token is not valid. 88 | * The audience parameter can be used to control which id tokens are 89 | * accepted. By default, the id token must have been issued to this OAuth2 client. 90 | * 91 | * @param string $idToken the ID token in JWT format 92 | * @param string $audience Optional. The audience to verify against JWt "aud" 93 | * @return array|false the token payload, if successful 94 | */ 95 | public function verifyIdToken($idToken, $audience = null) 96 | { 97 | if (empty($idToken)) { 98 | throw new LogicException('id_token cannot be null'); 99 | } 100 | 101 | // set phpseclib constants if applicable 102 | $this->setPhpsecConstants(); 103 | 104 | // Check signature 105 | $certs = $this->getFederatedSignOnCerts(); 106 | foreach ($certs as $cert) { 107 | try { 108 | $args = [$idToken]; 109 | $publicKey = $this->getPublicKey($cert); 110 | if (class_exists(Key::class)) { 111 | $args[] = new Key($publicKey, 'RS256'); 112 | } else { 113 | $args[] = $publicKey; 114 | $args[] = ['RS256']; 115 | } 116 | $payload = \call_user_func_array([$this->jwt, 'decode'], $args); 117 | 118 | if (property_exists($payload, 'aud')) { 119 | if ($audience && $payload->aud != $audience) { 120 | return false; 121 | } 122 | } 123 | 124 | // support HTTP and HTTPS issuers 125 | // @see https://developers.google.com/identity/sign-in/web/backend-auth 126 | $issuers = [self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS]; 127 | if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) { 128 | return false; 129 | } 130 | 131 | return (array) $payload; 132 | } catch (ExpiredException $e) { // @phpstan-ignore-line 133 | return false; 134 | } catch (ExpiredExceptionV3 $e) { 135 | return false; 136 | } catch (SignatureInvalidException $e) { 137 | // continue 138 | } catch (DomainException $e) { 139 | // continue 140 | } 141 | } 142 | 143 | return false; 144 | } 145 | 146 | private function getCache() 147 | { 148 | return $this->cache; 149 | } 150 | 151 | /** 152 | * Retrieve and cache a certificates file. 153 | * 154 | * @param string $url location 155 | * @throws \Google\Exception 156 | * @return array certificates 157 | */ 158 | private function retrieveCertsFromLocation($url) 159 | { 160 | // If we're retrieving a local file, just grab it. 161 | if (0 !== strpos($url, 'http')) { 162 | if (!$file = file_get_contents($url)) { 163 | throw new GoogleException( 164 | "Failed to retrieve verification certificates: '" . 165 | $url . "'." 166 | ); 167 | } 168 | 169 | return json_decode($file, true); 170 | } 171 | 172 | // @phpstan-ignore-next-line 173 | $response = $this->http->get($url); 174 | 175 | if ($response->getStatusCode() == 200) { 176 | return json_decode((string) $response->getBody(), true); 177 | } 178 | throw new GoogleException( 179 | sprintf( 180 | 'Failed to retrieve verification certificates: "%s".', 181 | $response->getBody()->getContents() 182 | ), 183 | $response->getStatusCode() 184 | ); 185 | } 186 | 187 | // Gets federated sign-on certificates to use for verifying identity tokens. 188 | // Returns certs as array structure, where keys are key ids, and values 189 | // are PEM encoded certificates. 190 | private function getFederatedSignOnCerts() 191 | { 192 | $certs = null; 193 | if ($cache = $this->getCache()) { 194 | $cacheItem = $cache->getItem('federated_signon_certs_v3'); 195 | $certs = $cacheItem->get(); 196 | } 197 | 198 | 199 | if (!$certs) { 200 | $certs = $this->retrieveCertsFromLocation( 201 | self::FEDERATED_SIGNON_CERT_URL 202 | ); 203 | 204 | if ($cache) { 205 | $cacheItem->expiresAt(new DateTime('+1 hour')); 206 | $cacheItem->set($certs); 207 | $cache->save($cacheItem); 208 | } 209 | } 210 | 211 | if (!isset($certs['keys'])) { 212 | throw new InvalidArgumentException( 213 | 'federated sign-on certs expects "keys" to be set' 214 | ); 215 | } 216 | 217 | return $certs['keys']; 218 | } 219 | 220 | private function getJwtService() 221 | { 222 | $jwtClass = 'JWT'; 223 | if (class_exists('\Firebase\JWT\JWT')) { 224 | $jwtClass = 'Firebase\JWT\JWT'; 225 | } 226 | 227 | if (property_exists($jwtClass, 'leeway') && $jwtClass::$leeway < 1) { 228 | // Ensures JWT leeway is at least 1 229 | // @see https://github.com/google/google-api-php-client/issues/827 230 | $jwtClass::$leeway = 1; 231 | } 232 | 233 | // @phpstan-ignore-next-line 234 | return new $jwtClass(); 235 | } 236 | 237 | private function getPublicKey($cert) 238 | { 239 | $bigIntClass = $this->getBigIntClass(); 240 | $modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256); 241 | $exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256); 242 | $component = ['n' => $modulus, 'e' => $exponent]; 243 | 244 | if (class_exists('phpseclib3\Crypt\RSA\PublicKey')) { 245 | /** @var PublicKey $loader */ 246 | $loader = PublicKeyLoader::load($component); 247 | 248 | return $loader->toString('PKCS8'); 249 | } 250 | 251 | $rsaClass = $this->getRsaClass(); 252 | $rsa = new $rsaClass(); 253 | $rsa->loadKey($component); 254 | 255 | return $rsa->getPublicKey(); 256 | } 257 | 258 | private function getRsaClass() 259 | { 260 | if (class_exists('phpseclib3\Crypt\RSA')) { 261 | return 'phpseclib3\Crypt\RSA'; 262 | } 263 | 264 | if (class_exists('phpseclib\Crypt\RSA')) { 265 | return 'phpseclib\Crypt\RSA'; 266 | } 267 | 268 | return 'Crypt_RSA'; 269 | } 270 | 271 | private function getBigIntClass() 272 | { 273 | if (class_exists('phpseclib3\Math\BigInteger')) { 274 | return 'phpseclib3\Math\BigInteger'; 275 | } 276 | 277 | if (class_exists('phpseclib\Math\BigInteger')) { 278 | return 'phpseclib\Math\BigInteger'; 279 | } 280 | 281 | return 'Math_BigInteger'; 282 | } 283 | 284 | private function getOpenSslConstant() 285 | { 286 | if (class_exists('phpseclib3\Crypt\AES')) { 287 | return 'phpseclib3\Crypt\AES::ENGINE_OPENSSL'; 288 | } 289 | 290 | if (class_exists('phpseclib\Crypt\RSA')) { 291 | return 'phpseclib\Crypt\RSA::MODE_OPENSSL'; 292 | } 293 | 294 | if (class_exists('Crypt_RSA')) { 295 | return 'CRYPT_RSA_MODE_OPENSSL'; 296 | } 297 | 298 | throw new Exception('Cannot find RSA class'); 299 | } 300 | 301 | /** 302 | * phpseclib calls "phpinfo" by default, which requires special 303 | * whitelisting in the AppEngine VM environment. This function 304 | * sets constants to bypass the need for phpseclib to check phpinfo 305 | * 306 | * @see phpseclib/Math/BigInteger 307 | * @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85 308 | */ 309 | private function setPhpsecConstants() 310 | { 311 | if (filter_var(getenv('GAE_VM'), FILTER_VALIDATE_BOOLEAN)) { 312 | if (!defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { 313 | define('MATH_BIGINTEGER_OPENSSL_ENABLED', true); 314 | } 315 | if (!defined('CRYPT_RSA_MODE')) { 316 | define('CRYPT_RSA_MODE', constant($this->getOpenSslConstant())); 317 | } 318 | } 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /DATABASE/google-api-php-client-main/src/AccessToken/Verify.php: -------------------------------------------------------------------------------- 1 | http = $http; 81 | $this->cache = $cache; 82 | $this->jwt = $jwt ?: $this->getJwtService(); 83 | } 84 | 85 | /** 86 | * Verifies an id token and returns the authenticated apiLoginTicket. 87 | * Throws an exception if the id token is not valid. 88 | * The audience parameter can be used to control which id tokens are 89 | * accepted. By default, the id token must have been issued to this OAuth2 client. 90 | * 91 | * @param string $idToken the ID token in JWT format 92 | * @param string $audience Optional. The audience to verify against JWt "aud" 93 | * @return array|false the token payload, if successful 94 | */ 95 | public function verifyIdToken($idToken, $audience = null) 96 | { 97 | if (empty($idToken)) { 98 | throw new LogicException('id_token cannot be null'); 99 | } 100 | 101 | // set phpseclib constants if applicable 102 | $this->setPhpsecConstants(); 103 | 104 | // Check signature 105 | $certs = $this->getFederatedSignOnCerts(); 106 | foreach ($certs as $cert) { 107 | try { 108 | $args = [$idToken]; 109 | $publicKey = $this->getPublicKey($cert); 110 | if (class_exists(Key::class)) { 111 | $args[] = new Key($publicKey, 'RS256'); 112 | } else { 113 | $args[] = $publicKey; 114 | $args[] = ['RS256']; 115 | } 116 | $payload = \call_user_func_array([$this->jwt, 'decode'], $args); 117 | 118 | if (property_exists($payload, 'aud')) { 119 | if ($audience && $payload->aud != $audience) { 120 | return false; 121 | } 122 | } 123 | 124 | // support HTTP and HTTPS issuers 125 | // @see https://developers.google.com/identity/sign-in/web/backend-auth 126 | $issuers = [self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS]; 127 | if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) { 128 | return false; 129 | } 130 | 131 | return (array) $payload; 132 | } catch (ExpiredException $e) { // @phpstan-ignore-line 133 | return false; 134 | } catch (ExpiredExceptionV3 $e) { 135 | return false; 136 | } catch (SignatureInvalidException $e) { 137 | // continue 138 | } catch (DomainException $e) { 139 | // continue 140 | } 141 | } 142 | 143 | return false; 144 | } 145 | 146 | private function getCache() 147 | { 148 | return $this->cache; 149 | } 150 | 151 | /** 152 | * Retrieve and cache a certificates file. 153 | * 154 | * @param string $url location 155 | * @throws \Google\Exception 156 | * @return array certificates 157 | */ 158 | private function retrieveCertsFromLocation($url) 159 | { 160 | // If we're retrieving a local file, just grab it. 161 | if (0 !== strpos($url, 'http')) { 162 | if (!$file = file_get_contents($url)) { 163 | throw new GoogleException( 164 | "Failed to retrieve verification certificates: '" . 165 | $url . "'." 166 | ); 167 | } 168 | 169 | return json_decode($file, true); 170 | } 171 | 172 | // @phpstan-ignore-next-line 173 | $response = $this->http->get($url); 174 | 175 | if ($response->getStatusCode() == 200) { 176 | return json_decode((string) $response->getBody(), true); 177 | } 178 | throw new GoogleException( 179 | sprintf( 180 | 'Failed to retrieve verification certificates: "%s".', 181 | $response->getBody()->getContents() 182 | ), 183 | $response->getStatusCode() 184 | ); 185 | } 186 | 187 | // Gets federated sign-on certificates to use for verifying identity tokens. 188 | // Returns certs as array structure, where keys are key ids, and values 189 | // are PEM encoded certificates. 190 | private function getFederatedSignOnCerts() 191 | { 192 | $certs = null; 193 | if ($cache = $this->getCache()) { 194 | $cacheItem = $cache->getItem('federated_signon_certs_v3'); 195 | $certs = $cacheItem->get(); 196 | } 197 | 198 | 199 | if (!$certs) { 200 | $certs = $this->retrieveCertsFromLocation( 201 | self::FEDERATED_SIGNON_CERT_URL 202 | ); 203 | 204 | if ($cache) { 205 | $cacheItem->expiresAt(new DateTime('+1 hour')); 206 | $cacheItem->set($certs); 207 | $cache->save($cacheItem); 208 | } 209 | } 210 | 211 | if (!isset($certs['keys'])) { 212 | throw new InvalidArgumentException( 213 | 'federated sign-on certs expects "keys" to be set' 214 | ); 215 | } 216 | 217 | return $certs['keys']; 218 | } 219 | 220 | private function getJwtService() 221 | { 222 | $jwtClass = 'JWT'; 223 | if (class_exists('\Firebase\JWT\JWT')) { 224 | $jwtClass = 'Firebase\JWT\JWT'; 225 | } 226 | 227 | if (property_exists($jwtClass, 'leeway') && $jwtClass::$leeway < 1) { 228 | // Ensures JWT leeway is at least 1 229 | // @see https://github.com/google/google-api-php-client/issues/827 230 | $jwtClass::$leeway = 1; 231 | } 232 | 233 | // @phpstan-ignore-next-line 234 | return new $jwtClass(); 235 | } 236 | 237 | private function getPublicKey($cert) 238 | { 239 | $bigIntClass = $this->getBigIntClass(); 240 | $modulus = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['n']), 256); 241 | $exponent = new $bigIntClass($this->jwt->urlsafeB64Decode($cert['e']), 256); 242 | $component = ['n' => $modulus, 'e' => $exponent]; 243 | 244 | if (class_exists('phpseclib3\Crypt\RSA\PublicKey')) { 245 | /** @var PublicKey $loader */ 246 | $loader = PublicKeyLoader::load($component); 247 | 248 | return $loader->toString('PKCS8'); 249 | } 250 | 251 | $rsaClass = $this->getRsaClass(); 252 | $rsa = new $rsaClass(); 253 | $rsa->loadKey($component); 254 | 255 | return $rsa->getPublicKey(); 256 | } 257 | 258 | private function getRsaClass() 259 | { 260 | if (class_exists('phpseclib3\Crypt\RSA')) { 261 | return 'phpseclib3\Crypt\RSA'; 262 | } 263 | 264 | if (class_exists('phpseclib\Crypt\RSA')) { 265 | return 'phpseclib\Crypt\RSA'; 266 | } 267 | 268 | return 'Crypt_RSA'; 269 | } 270 | 271 | private function getBigIntClass() 272 | { 273 | if (class_exists('phpseclib3\Math\BigInteger')) { 274 | return 'phpseclib3\Math\BigInteger'; 275 | } 276 | 277 | if (class_exists('phpseclib\Math\BigInteger')) { 278 | return 'phpseclib\Math\BigInteger'; 279 | } 280 | 281 | return 'Math_BigInteger'; 282 | } 283 | 284 | private function getOpenSslConstant() 285 | { 286 | if (class_exists('phpseclib3\Crypt\AES')) { 287 | return 'phpseclib3\Crypt\AES::ENGINE_OPENSSL'; 288 | } 289 | 290 | if (class_exists('phpseclib\Crypt\RSA')) { 291 | return 'phpseclib\Crypt\RSA::MODE_OPENSSL'; 292 | } 293 | 294 | if (class_exists('Crypt_RSA')) { 295 | return 'CRYPT_RSA_MODE_OPENSSL'; 296 | } 297 | 298 | throw new Exception('Cannot find RSA class'); 299 | } 300 | 301 | /** 302 | * phpseclib calls "phpinfo" by default, which requires special 303 | * whitelisting in the AppEngine VM environment. This function 304 | * sets constants to bypass the need for phpseclib to check phpinfo 305 | * 306 | * @see phpseclib/Math/BigInteger 307 | * @see https://github.com/GoogleCloudPlatform/getting-started-php/issues/85 308 | */ 309 | private function setPhpsecConstants() 310 | { 311 | if (filter_var(getenv('GAE_VM'), FILTER_VALIDATE_BOOLEAN)) { 312 | if (!defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { 313 | define('MATH_BIGINTEGER_OPENSSL_ENABLED', true); 314 | } 315 | if (!defined('CRYPT_RSA_MODE')) { 316 | define('CRYPT_RSA_MODE', constant($this->getOpenSslConstant())); 317 | } 318 | } 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /google-client/src/Http/MediaFileUpload.php: -------------------------------------------------------------------------------- 1 | client = $client; 91 | $this->request = $request; 92 | $this->mimeType = $mimeType; 93 | $this->data = $data; 94 | $this->resumable = $resumable; 95 | $this->chunkSize = $chunkSize; 96 | $this->progress = 0; 97 | 98 | $this->process(); 99 | } 100 | 101 | /** 102 | * Set the size of the file that is being uploaded. 103 | * @param int $size - int file size in bytes 104 | */ 105 | public function setFileSize($size) 106 | { 107 | $this->size = $size; 108 | } 109 | 110 | /** 111 | * Return the progress on the upload 112 | * @return int progress in bytes uploaded. 113 | */ 114 | public function getProgress() 115 | { 116 | return $this->progress; 117 | } 118 | 119 | /** 120 | * Send the next part of the file to upload. 121 | * @param string|bool $chunk Optional. The next set of bytes to send. If false will 122 | * use $data passed at construct time. 123 | */ 124 | public function nextChunk($chunk = false) 125 | { 126 | $resumeUri = $this->getResumeUri(); 127 | 128 | if (false == $chunk) { 129 | $chunk = substr($this->data, $this->progress, $this->chunkSize); 130 | } 131 | 132 | $lastBytePos = $this->progress + strlen($chunk) - 1; 133 | $headers = [ 134 | 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", 135 | 'content-length' => (string) strlen($chunk), 136 | 'expect' => '', 137 | ]; 138 | 139 | $request = new Request( 140 | 'PUT', 141 | $resumeUri, 142 | $headers, 143 | Psr7\Utils::streamFor($chunk) 144 | ); 145 | 146 | return $this->makePutRequest($request); 147 | } 148 | 149 | /** 150 | * Return the HTTP result code from the last call made. 151 | * @return int code 152 | */ 153 | public function getHttpResultCode() 154 | { 155 | return $this->httpResultCode; 156 | } 157 | 158 | /** 159 | * Sends a PUT-Request to google drive and parses the response, 160 | * setting the appropiate variables from the response() 161 | * 162 | * @param RequestInterface $request the Request which will be send 163 | * 164 | * @return false|mixed false when the upload is unfinished or the decoded http response 165 | * 166 | */ 167 | private function makePutRequest(RequestInterface $request) 168 | { 169 | $response = $this->client->execute($request); 170 | $this->httpResultCode = $response->getStatusCode(); 171 | 172 | if (308 == $this->httpResultCode) { 173 | // Track the amount uploaded. 174 | $range = $response->getHeaderLine('range'); 175 | if ($range) { 176 | $range_array = explode('-', $range); 177 | $this->progress = ((int) $range_array[1]) + 1; 178 | } 179 | 180 | // Allow for changing upload URLs. 181 | $location = $response->getHeaderLine('location'); 182 | if ($location) { 183 | $this->resumeUri = $location; 184 | } 185 | 186 | // No problems, but upload not complete. 187 | return false; 188 | } 189 | 190 | return REST::decodeHttpResponse($response, $this->request); 191 | } 192 | 193 | /** 194 | * Resume a previously unfinished upload 195 | * @param string $resumeUri the resume-URI of the unfinished, resumable upload. 196 | */ 197 | public function resume($resumeUri) 198 | { 199 | $this->resumeUri = $resumeUri; 200 | $headers = [ 201 | 'content-range' => "bytes */$this->size", 202 | 'content-length' => '0', 203 | ]; 204 | $httpRequest = new Request( 205 | 'PUT', 206 | $this->resumeUri, 207 | $headers 208 | ); 209 | return $this->makePutRequest($httpRequest); 210 | } 211 | 212 | /** 213 | * @return RequestInterface 214 | * @visible for testing 215 | */ 216 | private function process() 217 | { 218 | $this->transformToUploadUrl(); 219 | $request = $this->request; 220 | 221 | $postBody = ''; 222 | $contentType = false; 223 | 224 | $meta = json_decode((string) $request->getBody(), true); 225 | 226 | $uploadType = $this->getUploadType($meta); 227 | $request = $request->withUri( 228 | Uri::withQueryValue($request->getUri(), 'uploadType', $uploadType) 229 | ); 230 | 231 | $mimeType = $this->mimeType ?: $request->getHeaderLine('content-type'); 232 | 233 | if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) { 234 | $contentType = $mimeType; 235 | $postBody = is_string($meta) ? $meta : json_encode($meta); 236 | } elseif (self::UPLOAD_MEDIA_TYPE == $uploadType) { 237 | $contentType = $mimeType; 238 | $postBody = $this->data; 239 | } elseif (self::UPLOAD_MULTIPART_TYPE == $uploadType) { 240 | // This is a multipart/related upload. 241 | $boundary = $this->boundary ?: mt_rand(); 242 | $boundary = str_replace('"', '', $boundary); 243 | $contentType = 'multipart/related; boundary=' . $boundary; 244 | $related = "--$boundary\r\n"; 245 | $related .= "Content-Type: application/json; charset=UTF-8\r\n"; 246 | $related .= "\r\n" . json_encode($meta) . "\r\n"; 247 | $related .= "--$boundary\r\n"; 248 | $related .= "Content-Type: $mimeType\r\n"; 249 | $related .= "Content-Transfer-Encoding: base64\r\n"; 250 | $related .= "\r\n" . base64_encode($this->data) . "\r\n"; 251 | $related .= "--$boundary--"; 252 | $postBody = $related; 253 | } 254 | 255 | $request = $request->withBody(Psr7\Utils::streamFor($postBody)); 256 | 257 | if ($contentType) { 258 | $request = $request->withHeader('content-type', $contentType); 259 | } 260 | 261 | return $this->request = $request; 262 | } 263 | 264 | /** 265 | * Valid upload types: 266 | * - resumable (UPLOAD_RESUMABLE_TYPE) 267 | * - media (UPLOAD_MEDIA_TYPE) 268 | * - multipart (UPLOAD_MULTIPART_TYPE) 269 | * @param string|false $meta 270 | * @return string 271 | * @visible for testing 272 | */ 273 | public function getUploadType($meta) 274 | { 275 | if ($this->resumable) { 276 | return self::UPLOAD_RESUMABLE_TYPE; 277 | } 278 | 279 | if (false == $meta && $this->data) { 280 | return self::UPLOAD_MEDIA_TYPE; 281 | } 282 | 283 | return self::UPLOAD_MULTIPART_TYPE; 284 | } 285 | 286 | public function getResumeUri() 287 | { 288 | if (null === $this->resumeUri) { 289 | $this->resumeUri = $this->fetchResumeUri(); 290 | } 291 | 292 | return $this->resumeUri; 293 | } 294 | 295 | private function fetchResumeUri() 296 | { 297 | $body = $this->request->getBody(); 298 | $headers = [ 299 | 'content-type' => 'application/json; charset=UTF-8', 300 | 'content-length' => $body->getSize(), 301 | 'x-upload-content-type' => $this->mimeType, 302 | 'x-upload-content-length' => $this->size, 303 | 'expect' => '', 304 | ]; 305 | foreach ($headers as $key => $value) { 306 | $this->request = $this->request->withHeader($key, $value); 307 | } 308 | 309 | $response = $this->client->execute($this->request, false); 310 | $location = $response->getHeaderLine('location'); 311 | $code = $response->getStatusCode(); 312 | 313 | if (200 == $code && true == $location) { 314 | return $location; 315 | } 316 | 317 | $message = $code; 318 | $body = json_decode((string) $this->request->getBody(), true); 319 | if (isset($body['error']['errors'])) { 320 | $message .= ': '; 321 | foreach ($body['error']['errors'] as $error) { 322 | $message .= "{$error['domain']}, {$error['message']};"; 323 | } 324 | $message = rtrim($message, ';'); 325 | } 326 | 327 | $error = "Failed to start the resumable upload (HTTP {$message})"; 328 | $this->client->getLogger()->error($error); 329 | 330 | throw new GoogleException($error); 331 | } 332 | 333 | private function transformToUploadUrl() 334 | { 335 | $parts = parse_url((string) $this->request->getUri()); 336 | if (!isset($parts['path'])) { 337 | $parts['path'] = ''; 338 | } 339 | $parts['path'] = '/upload' . $parts['path']; 340 | $uri = Uri::fromParts($parts); 341 | $this->request = $this->request->withUri($uri); 342 | } 343 | 344 | public function setChunkSize($chunkSize) 345 | { 346 | $this->chunkSize = $chunkSize; 347 | } 348 | 349 | public function getRequest() 350 | { 351 | return $this->request; 352 | } 353 | } 354 | --------------------------------------------------------------------------------